@openstatus/health-algolia 0.1.4-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # @openstatus/health-algolia
2
+
3
+ [Algolia](https://www.algolia.com/) probe for
4
+ [`@openstatus/health`](https://jsr.io/@openstatus/health). Sends
5
+ `GET /1/isalive` to your application's DSN host with the application ID and
6
+ an API key in the Algolia headers, so it proves both that the search API
7
+ answers and that the key is valid — with `fetch` alone, on every runtime.
8
+
9
+ ```sh
10
+ deno add jsr:@openstatus/health jsr:@openstatus/health-algolia
11
+ npm install @openstatus/health @openstatus/health-algolia
12
+ ```
13
+
14
+ ```ts
15
+ import { createHealthHandler, readEnv } from "@openstatus/health";
16
+ import { algoliaProbe } from "@openstatus/health-algolia";
17
+
18
+ const appId = readEnv("ALGOLIA_APP_ID");
19
+ const apiKey = readEnv("ALGOLIA_SEARCH_KEY");
20
+
21
+ Deno.serve(
22
+ createHealthHandler({
23
+ probes: [
24
+ // the factory validates `appId` and `apiKey` at construction, so pass
25
+ // placeholders and let `skip` keep the unconfigured check from running.
26
+ algoliaProbe({
27
+ appId: appId || "unconfigured",
28
+ apiKey: apiKey || "unconfigured",
29
+ skip: () => !appId || !apiKey,
30
+ }),
31
+ ],
32
+ }),
33
+ );
34
+ ```
35
+
36
+ `appId` is the application ID and `apiKey` any key of that application —
37
+ the search-only key is enough and is the least privilege that still
38
+ authenticates. The request goes to `https://{appId}-dsn.algolia.net`, the
39
+ DSN host that fans out across the application's cluster and the same one the
40
+ search client uses; pass `baseUrl` to target a specific replica instead.
41
+ `/1/isalive` is the endpoint Algolia documents for exactly this and has no
42
+ side effects, so the probe can run on every health request. Like every
43
+ probe here, this one never reads the environment itself — pass the values
44
+ in, and use `skip` for environments where Algolia is not configured.
45
+
46
+ ```ts
47
+ algoliaProbe({
48
+ appId: appId || "unconfigured",
49
+ apiKey: apiKey || "unconfigured",
50
+ // optional overrides from the Probe contract
51
+ name: "algolia",
52
+ critical: true,
53
+ timeoutMs: 1000,
54
+ skip: () => !appId || !apiKey,
55
+ });
56
+ ```
57
+
58
+ Non-critical by default: search is usually one feature of a service rather
59
+ than its request path, so an outage degrades the report instead of taking
60
+ the service out of rotation. Set `critical: true` when requests cannot be
61
+ served without it.
62
+
63
+ ## About openstatus
64
+
65
+ [openstatus](https://www.openstatus.dev/) is the open-source uptime monitoring
66
+ and status page platform. This package is part of
67
+ [`@openstatus/health`](https://github.com/openstatusHQ/health), the `/health`
68
+ endpoints behind openstatus's own services, extracted so any JavaScript server
69
+ can expose one. Point an
70
+ [openstatus monitor](https://www.openstatus.dev/docs/reference/http-monitor)
71
+ at the endpoint and assert on `status` in the body to be alerted on
72
+ `degraded` before it becomes `unhealthy`.
73
+
74
+ Source: [github.com/openstatusHQ/health](https://github.com/openstatusHQ/health).
75
+ Issues and PRs welcome.
76
+
77
+ ## License
78
+
79
+ [MIT](https://github.com/openstatusHQ/health/blob/main/LICENSE)
@@ -0,0 +1,30 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ Object.defineProperty(exports, '__toESM', {
26
+ enumerable: true,
27
+ get: function () {
28
+ return __toESM;
29
+ }
30
+ });
package/dist/mod.cjs ADDED
@@ -0,0 +1,45 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const __openstatus_health = require_rolldown_runtime.__toESM(require("@openstatus/health"));
3
+
4
+ //#region src/mod.ts
5
+ /** Probe name when `name` is unset. */
6
+ const algoliaDefaultName = "search";
7
+ /** The DSN host for an application, used when `baseUrl` is unset. */
8
+ function algoliaDsnUrl(appId) {
9
+ return `https://${appId.toLowerCase()}-dsn.algolia.net`;
10
+ }
11
+ /** A probe that expects 2xx from `GET {baseUrl}/1/isalive` with the application headers; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey`, an `appId` that is not alphanumeric, or an invalid `baseUrl`. */
12
+ function algoliaProbe(options) {
13
+ const doFetch = options.fetch ?? globalThis.fetch;
14
+ for (const field of ["appId", "apiKey"]) {
15
+ const value = options[field];
16
+ if (typeof value !== "string" || value.length === 0) throw new __openstatus_health.ProbeConfigError("algoliaProbe", field, typeof value !== "string" ? `must be a string, got ${String(value)}` : "must not be empty");
17
+ }
18
+ if (!/^[A-Za-z0-9]+$/.test(options.appId)) throw new __openstatus_health.ProbeConfigError("algoliaProbe", "appId", `must be alphanumeric, got ${JSON.stringify(options.appId)}`);
19
+ const url = (0, __openstatus_health.probeUrl)({
20
+ probe: "algoliaProbe",
21
+ field: "baseUrl",
22
+ value: options.baseUrl ?? algoliaDsnUrl(options.appId),
23
+ path: "/1/isalive"
24
+ });
25
+ const headers = {
26
+ "x-algolia-application-id": options.appId,
27
+ "x-algolia-api-key": options.apiKey
28
+ };
29
+ return {
30
+ name: options.name ?? algoliaDefaultName,
31
+ critical: options.critical ?? false,
32
+ timeoutMs: options.timeoutMs,
33
+ skip: options.skip,
34
+ run: (signal) => (0, __openstatus_health.expectOk)(doFetch(url, {
35
+ method: "GET",
36
+ headers,
37
+ signal
38
+ }))
39
+ };
40
+ }
41
+
42
+ //#endregion
43
+ exports.algoliaDefaultName = algoliaDefaultName;
44
+ exports.algoliaDsnUrl = algoliaDsnUrl;
45
+ exports.algoliaProbe = algoliaProbe;
package/dist/mod.d.cts ADDED
@@ -0,0 +1,25 @@
1
+ import { Probe, ProbeOverrides } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** Probe name when `name` is unset. */
6
+ declare const algoliaDefaultName = "search";
7
+ /** The DSN host for an application, used when `baseUrl` is unset. */
8
+ declare function algoliaDsnUrl(appId: string): string;
9
+ /** Options for `algoliaProbe()`. */
10
+ interface AlgoliaProbeOptions extends ProbeOverrides {
11
+ /** The application ID. */
12
+ readonly appId: string;
13
+ /** Any API key of the application; a search-only key is enough. */
14
+ readonly apiKey: string;
15
+ /** API host. Default `algoliaDsnUrl(appId)`. */
16
+ readonly baseUrl?: string | URL;
17
+ /** Replacement `fetch`, for tests. */
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** A probe that expects 2xx from `GET {baseUrl}/1/isalive` with the application headers; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey`, an `appId` that is not alphanumeric, or an invalid `baseUrl`. */
21
+ declare function algoliaProbe(options: AlgoliaProbeOptions): Probe;
22
+ //# sourceMappingURL=mod.d.ts.map
23
+ //#endregion
24
+ export { AlgoliaProbeOptions, algoliaDefaultName, algoliaDsnUrl, algoliaProbe };
25
+ //# sourceMappingURL=mod.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AA0C4D,cApB/C,kBAAA,GAoB+C,QAAA;AAAK;iBAjBjD,aAAA;;UAKC,mBAAA,SAA4B;;;;;;8BAMf;;0BAEJ;;;iBAIV,YAAA,UAAsB,sBAAsB"}
package/dist/mod.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { Probe, ProbeOverrides } from "@openstatus/health";
2
+
3
+ //#region src/mod.d.ts
4
+
5
+ /** Probe name when `name` is unset. */
6
+ declare const algoliaDefaultName = "search";
7
+ /** The DSN host for an application, used when `baseUrl` is unset. */
8
+ declare function algoliaDsnUrl(appId: string): string;
9
+ /** Options for `algoliaProbe()`. */
10
+ interface AlgoliaProbeOptions extends ProbeOverrides {
11
+ /** The application ID. */
12
+ readonly appId: string;
13
+ /** Any API key of the application; a search-only key is enough. */
14
+ readonly apiKey: string;
15
+ /** API host. Default `algoliaDsnUrl(appId)`. */
16
+ readonly baseUrl?: string | URL;
17
+ /** Replacement `fetch`, for tests. */
18
+ readonly fetch?: typeof fetch;
19
+ }
20
+ /** A probe that expects 2xx from `GET {baseUrl}/1/isalive` with the application headers; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey`, an `appId` that is not alphanumeric, or an invalid `baseUrl`. */
21
+ declare function algoliaProbe(options: AlgoliaProbeOptions): Probe;
22
+ //# sourceMappingURL=mod.d.ts.map
23
+ //#endregion
24
+ export { AlgoliaProbeOptions, algoliaDefaultName, algoliaDsnUrl, algoliaProbe };
25
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;AA0C4D,cApB/C,kBAAA,GAoB+C,QAAA;AAAK;iBAjBjD,aAAA;;UAKC,mBAAA,SAA4B;;;;;;8BAMf;;0BAEJ;;;iBAIV,YAAA,UAAsB,sBAAsB"}
package/dist/mod.js ADDED
@@ -0,0 +1,43 @@
1
+ import { ProbeConfigError, expectOk, probeUrl } from "@openstatus/health";
2
+
3
+ //#region src/mod.ts
4
+ /** Probe name when `name` is unset. */
5
+ const algoliaDefaultName = "search";
6
+ /** The DSN host for an application, used when `baseUrl` is unset. */
7
+ function algoliaDsnUrl(appId) {
8
+ return `https://${appId.toLowerCase()}-dsn.algolia.net`;
9
+ }
10
+ /** A probe that expects 2xx from `GET {baseUrl}/1/isalive` with the application headers; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey`, an `appId` that is not alphanumeric, or an invalid `baseUrl`. */
11
+ function algoliaProbe(options) {
12
+ const doFetch = options.fetch ?? globalThis.fetch;
13
+ for (const field of ["appId", "apiKey"]) {
14
+ const value = options[field];
15
+ if (typeof value !== "string" || value.length === 0) throw new ProbeConfigError("algoliaProbe", field, typeof value !== "string" ? `must be a string, got ${String(value)}` : "must not be empty");
16
+ }
17
+ if (!/^[A-Za-z0-9]+$/.test(options.appId)) throw new ProbeConfigError("algoliaProbe", "appId", `must be alphanumeric, got ${JSON.stringify(options.appId)}`);
18
+ const url = probeUrl({
19
+ probe: "algoliaProbe",
20
+ field: "baseUrl",
21
+ value: options.baseUrl ?? algoliaDsnUrl(options.appId),
22
+ path: "/1/isalive"
23
+ });
24
+ const headers = {
25
+ "x-algolia-application-id": options.appId,
26
+ "x-algolia-api-key": options.apiKey
27
+ };
28
+ return {
29
+ name: options.name ?? algoliaDefaultName,
30
+ critical: options.critical ?? false,
31
+ timeoutMs: options.timeoutMs,
32
+ skip: options.skip,
33
+ run: (signal) => expectOk(doFetch(url, {
34
+ method: "GET",
35
+ headers,
36
+ signal
37
+ }))
38
+ };
39
+ }
40
+
41
+ //#endregion
42
+ export { algoliaDefaultName, algoliaDsnUrl, algoliaProbe };
43
+ //# sourceMappingURL=mod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.js","names":["appId: string","options: AlgoliaProbeOptions"],"sources":["../src/mod.ts"],"sourcesContent":["/**\n * Algolia reachability probe for `@openstatus/health`, against `/1/isalive`\n * on the application's DSN host.\n *\n * ```ts\n * import { algoliaProbe } from \"@openstatus/health-algolia\";\n *\n * const probe = algoliaProbe({ appId: env.ALGOLIA_APP_ID, apiKey: env.ALGOLIA_SEARCH_KEY });\n * ```\n *\n * @module\n */\n\nimport {\n expectOk,\n type Probe,\n ProbeConfigError,\n type ProbeOverrides,\n probeUrl,\n} from \"@openstatus/health\";\n\n/** Probe name when `name` is unset. */\nexport const algoliaDefaultName = \"search\";\n\n/** The DSN host for an application, used when `baseUrl` is unset. */\nexport function algoliaDsnUrl(appId: string): string {\n return `https://${appId.toLowerCase()}-dsn.algolia.net`;\n}\n\n/** Options for `algoliaProbe()`. */\nexport interface AlgoliaProbeOptions extends ProbeOverrides {\n /** The application ID. */\n readonly appId: string;\n /** Any API key of the application; a search-only key is enough. */\n readonly apiKey: string;\n /** API host. Default `algoliaDsnUrl(appId)`. */\n readonly baseUrl?: string | URL;\n /** Replacement `fetch`, for tests. */\n readonly fetch?: typeof fetch;\n}\n\n/** A probe that expects 2xx from `GET {baseUrl}/1/isalive` with the application headers; non-critical by default. Throws `ProbeConfigError` for an empty `apiKey`, an `appId` that is not alphanumeric, or an invalid `baseUrl`. */\nexport function algoliaProbe(options: AlgoliaProbeOptions): Probe {\n const doFetch = options.fetch ?? globalThis.fetch;\n for (const field of [\"appId\", \"apiKey\"] as const) {\n const value = options[field];\n if (typeof value !== \"string\" || value.length === 0) {\n throw new ProbeConfigError(\n \"algoliaProbe\",\n field,\n typeof value !== \"string\"\n ? `must be a string, got ${String(value)}`\n : \"must not be empty\",\n );\n }\n }\n if (!/^[A-Za-z0-9]+$/.test(options.appId)) {\n throw new ProbeConfigError(\n \"algoliaProbe\",\n \"appId\",\n `must be alphanumeric, got ${JSON.stringify(options.appId)}`,\n );\n }\n const url = probeUrl({\n probe: \"algoliaProbe\",\n field: \"baseUrl\",\n value: options.baseUrl ?? algoliaDsnUrl(options.appId),\n path: \"/1/isalive\",\n });\n const headers = {\n \"x-algolia-application-id\": options.appId,\n \"x-algolia-api-key\": options.apiKey,\n };\n return {\n name: options.name ?? algoliaDefaultName,\n critical: options.critical ?? false,\n timeoutMs: options.timeoutMs,\n skip: options.skip,\n run: (signal) => expectOk(doFetch(url, { method: \"GET\", headers, signal })),\n };\n}\n"],"mappings":";;;;AAsBA,MAAa,qBAAqB;;AAGlC,SAAgB,cAAcA,OAAuB;AACnD,SAAQ,UAAU,MAAM,aAAa,CAAC;AACvC;;AAeD,SAAgB,aAAaC,SAAqC;CAChE,MAAM,UAAU,QAAQ,SAAS,WAAW;AAC5C,MAAK,MAAM,SAAS,CAAC,SAAS,QAAS,GAAW;EAChD,MAAM,QAAQ,QAAQ;AACtB,aAAW,UAAU,YAAY,MAAM,WAAW,EAChD,OAAM,IAAI,iBACR,gBACA,cACO,UAAU,YACZ,wBAAwB,OAAO,MAAM,CAAC,IACvC;CAGT;AACD,MAAK,iBAAiB,KAAK,QAAQ,MAAM,CACvC,OAAM,IAAI,iBACR,gBACA,UACC,4BAA4B,KAAK,UAAU,QAAQ,MAAM,CAAC;CAG/D,MAAM,MAAM,SAAS;EACnB,OAAO;EACP,OAAO;EACP,OAAO,QAAQ,WAAW,cAAc,QAAQ,MAAM;EACtD,MAAM;CACP,EAAC;CACF,MAAM,UAAU;EACd,4BAA4B,QAAQ;EACpC,qBAAqB,QAAQ;CAC9B;AACD,QAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,UAAU,QAAQ,YAAY;EAC9B,WAAW,QAAQ;EACnB,MAAM,QAAQ;EACd,KAAK,CAAC,WAAW,SAAS,QAAQ,KAAK;GAAE,QAAQ;GAAO;GAAS;EAAQ,EAAC,CAAC;CAC5E;AACF"}
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@openstatus/health-algolia",
3
+ "version": "0.1.4-dev.0",
4
+ "description": "Algolia probe for @openstatus/health",
5
+ "keywords": [
6
+ "openstatus",
7
+ "health",
8
+ "healthcheck",
9
+ "algolia",
10
+ "search"
11
+ ],
12
+ "license": "MIT",
13
+ "author": {
14
+ "name": "openstatus",
15
+ "url": "https://www.openstatus.dev/"
16
+ },
17
+ "homepage": "https://github.com/openstatusHQ/health",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/openstatusHQ/health.git",
21
+ "directory": "packages/algolia/"
22
+ },
23
+ "bugs": {
24
+ "url": "https://github.com/openstatusHQ/health/issues"
25
+ },
26
+ "type": "module",
27
+ "module": "./dist/mod.js",
28
+ "main": "./dist/mod.cjs",
29
+ "types": "./dist/mod.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": {
33
+ "import": "./dist/mod.d.ts",
34
+ "require": "./dist/mod.d.cts"
35
+ },
36
+ "import": "./dist/mod.js",
37
+ "require": "./dist/mod.cjs"
38
+ },
39
+ "./package.json": "./package.json"
40
+ },
41
+ "sideEffects": false,
42
+ "files": [
43
+ "dist/"
44
+ ],
45
+ "engines": {
46
+ "node": ">=22"
47
+ },
48
+ "peerDependencies": {
49
+ "@openstatus/health": "^0.1.4-dev.0"
50
+ },
51
+ "devDependencies": {
52
+ "tsdown": "^0.12.7",
53
+ "typescript": "^5.8.3"
54
+ },
55
+ "scripts": {
56
+ "build": "tsdown",
57
+ "prepack": "tsdown",
58
+ "test": "node --experimental-transform-types --test"
59
+ }
60
+ }