@jdcpuwiz/zoo-kit 1.0.1 → 1.1.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 +48 -3
- package/dist/cjs/categories.d.ts +31 -0
- package/dist/cjs/categories.js +47 -0
- package/dist/cjs/env.d.ts +62 -0
- package/dist/cjs/env.js +105 -0
- package/dist/cjs/generated/categories.d.ts +85 -0
- package/dist/cjs/generated/categories.js +10 -0
- package/dist/cjs/generated/contract.d.ts +7 -0
- package/dist/cjs/generated/contract.js +12 -0
- package/dist/cjs/generated/notifier.d.ts +230 -0
- package/dist/cjs/generated/notifier.js +5 -0
- package/dist/cjs/generated/people.d.ts +261 -0
- package/dist/cjs/generated/people.js +5 -0
- package/dist/cjs/health.d.ts +46 -0
- package/dist/cjs/health.js +132 -0
- package/dist/cjs/http.d.ts +51 -0
- package/dist/cjs/http.js +108 -0
- package/dist/cjs/index.d.ts +20 -0
- package/dist/cjs/index.js +62 -0
- package/dist/cjs/keys.d.ts +51 -0
- package/dist/cjs/keys.js +106 -0
- package/dist/cjs/notify.d.ts +79 -0
- package/dist/cjs/notify.js +131 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/people.d.ts +61 -0
- package/dist/cjs/people.js +170 -0
- package/dist/cjs/whoami.d.ts +86 -0
- package/dist/cjs/whoami.js +197 -0
- package/dist/generated/contract.d.ts +1 -1
- package/dist/generated/contract.js +1 -1
- package/dist/health.js +20 -5
- package/dist/notify.d.ts +5 -1
- package/dist/notify.js +13 -7
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ directory, authentik); this package is a **thin, pinned client** of their
|
|
|
8
8
|
versioned v1 contract (`contracts/v1` in the zoo-kit repo). Types are
|
|
9
9
|
generated from those OpenAPI files, never restated by hand.
|
|
10
10
|
|
|
11
|
-
- **Server-only.** Node ≥ 20, ESM + `.d.ts`. Next.js route handlers,
|
|
11
|
+
- **Server-only.** Node ≥ 20, ESM and CommonJS builds + `.d.ts`. Next.js route handlers,
|
|
12
12
|
Hono / Express / Fastify and Bun all import it. It imports `node:crypto`,
|
|
13
13
|
so a browser bundle fails at build time; it does *not* import Next's
|
|
14
14
|
`server-only` marker (that would break every non-Next runtime).
|
|
@@ -22,7 +22,7 @@ generated from those OpenAPI files, never restated by hand.
|
|
|
22
22
|
## Install
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
npm install --save-exact @jdcpuwiz/zoo-kit@1.
|
|
25
|
+
npm install --save-exact @jdcpuwiz/zoo-kit@1.1.0
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Pin the exact version (no caret) — rollback is one revert of that line. v1.x
|
|
@@ -80,6 +80,12 @@ if (!r.ok) console.log("push not sent:", r.error); // never throws
|
|
|
80
80
|
- Result: `{ ok: true, id, queued, deduped, status, url }` or
|
|
81
81
|
`{ ok: false, error, status, skipped?, attempts }`. `{ dryRun: true }` builds
|
|
82
82
|
the request and sends nothing.
|
|
83
|
+
- **Settings that don't live in env:** an app that keeps its hub URL and key
|
|
84
|
+
somewhere else, such as an encrypted settings table, passes them per call:
|
|
85
|
+
`notify(input, { urls: [hubUrl], key: hubKey })`. Each overrides its env
|
|
86
|
+
value independently, and an empty value (`[]`, `""`) means not set, so env
|
|
87
|
+
applies. The key goes in the Bearer header and is never logged or returned.
|
|
88
|
+
`notifyConfigured()` reports env only.
|
|
83
89
|
- **No `notify.batch`.** v1 has no batch route, so a client batch would be N
|
|
84
90
|
calls with invented partial-failure semantics; `Promise.all(items.map(notify))`
|
|
85
91
|
is exactly as good and says what it does.
|
|
@@ -183,6 +189,43 @@ working directory's `package.json`; `sha` is the option, else `GIT_SHA`, else
|
|
|
183
189
|
`null`. Each check gets a timeout (default 3 s). The route answers 200 even
|
|
184
190
|
when `ok` is false (zoo-vet reads `ok`); opt into `failStatus: 503`.
|
|
185
191
|
|
|
192
|
+
**Error text is generic, and there is no option to expose it.** Health routes
|
|
193
|
+
are open on the LAN and a raw error can name a database host and port (a Prisma
|
|
194
|
+
one does).
|
|
195
|
+
|
|
196
|
+
| The check | `checks.<name>` in the body | App log |
|
|
197
|
+
|---|---|---|
|
|
198
|
+
| throws | `error: "check failed"` | `[zoo-kit] health check "<name>" failed: <real message>`, one `console.warn` per failure |
|
|
199
|
+
| outlives its timeout | `error: "timed out after N ms"` (kit-made) | nothing |
|
|
200
|
+
| returns `false` | `ok: false` | nothing |
|
|
201
|
+
| returns `{ ok, detail }` | `detail` as written, so never put a raw error in it | nothing |
|
|
202
|
+
|
|
203
|
+
If the handler itself fails, the body has `checks.kit.error: "health failed"` and
|
|
204
|
+
the real message goes to the log.
|
|
205
|
+
|
|
206
|
+
## CommonJS
|
|
207
|
+
|
|
208
|
+
The package ships both builds, and `exports` picks one: `import` gets `dist/`,
|
|
209
|
+
`require` gets `dist/cjs/`. A CommonJS backend (`module: commonjs`, Node 20) just
|
|
210
|
+
writes `require("@jdcpuwiz/zoo-kit")` or a TypeScript `import` and needs no
|
|
211
|
+
workaround.
|
|
212
|
+
|
|
213
|
+
Use one build per process. Each has its own module state (the once-only warnings,
|
|
214
|
+
the people cache) and its own `ZooKitAuthError` class, so an `instanceof` across
|
|
215
|
+
the two builds is false.
|
|
216
|
+
|
|
217
|
+
## Upgrading to 1.1.0
|
|
218
|
+
|
|
219
|
+
No code change is needed: the health body and every function signature keep their
|
|
220
|
+
shape. Two things behave differently:
|
|
221
|
+
|
|
222
|
+
- **A test asserting a check's thrown text must now expect `check failed`**. That
|
|
223
|
+
covers an app's own wrapper too: a check that does
|
|
224
|
+
`throw new Error("database unreachable")` now answers `check failed`, and the
|
|
225
|
+
sentence goes to the log. To show your own text in the body, return
|
|
226
|
+
`{ ok: false, detail: "database unreachable" }` instead.
|
|
227
|
+
- **A test pinning `kit` to a version string** needs the new version, as on every bump.
|
|
228
|
+
|
|
186
229
|
## App keys
|
|
187
230
|
|
|
188
231
|
```ts
|
|
@@ -212,7 +255,7 @@ checkConfig(["DATABASE_URL", "ZOO_NOTIFIER_KEY"]); // { ok: false, missing: ["ZO
|
|
|
212
255
|
|
|
213
256
|
## Adopting in an app
|
|
214
257
|
|
|
215
|
-
1. `npm install --save-exact @jdcpuwiz/zoo-kit@1.
|
|
258
|
+
1. `npm install --save-exact @jdcpuwiz/zoo-kit@1.1.0`.
|
|
216
259
|
2. **notify:** delete `lib/notify-client.ts`; `import { notify } from "@jdcpuwiz/zoo-kit"`.
|
|
217
260
|
Callers that did `if (await notify(...))` now read `.ok`. Category strings
|
|
218
261
|
from settings go through `toCategory()`. Env names are unchanged.
|
|
@@ -236,4 +279,6 @@ npm run typecheck
|
|
|
236
279
|
npm test
|
|
237
280
|
npm run build
|
|
238
281
|
npm pack --dry-run # dist/, README.md, LICENSE, package.json only
|
|
282
|
+
npm run test:tarball # pack, install in a temp dir: require, import, tsc
|
|
283
|
+
node scripts/tarball-test.mjs @jdcpuwiz/zoo-kit@X.Y.Z # the same three checks on a published version
|
|
239
284
|
```
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type CategoryAlias, type NotifyCategory } from "./generated/categories.js";
|
|
2
|
+
export { CATEGORIES, CATEGORY_ALIASES, CATEGORY_SLUGS } from "./generated/categories.js";
|
|
3
|
+
export type { CategoryAlias, NotifyCategory } from "./generated/categories.js";
|
|
4
|
+
declare const customBrand: unique symbol;
|
|
5
|
+
/**
|
|
6
|
+
* A category the hub holds as a Category ROW but which is not published in
|
|
7
|
+
* categories.v1.json (created on the hub's /categories page). Only reachable
|
|
8
|
+
* through {@link customCategory} / {@link toCategory}, so a typo in code is a
|
|
9
|
+
* type error rather than a 400 at 3am.
|
|
10
|
+
*/
|
|
11
|
+
export type CustomCategory = string & {
|
|
12
|
+
readonly [customBrand]: true;
|
|
13
|
+
};
|
|
14
|
+
/** Anything `notify({ category })` accepts. */
|
|
15
|
+
export type CategoryInput = NotifyCategory | CategoryAlias | CustomCategory;
|
|
16
|
+
export declare function isCanonicalCategory(s: string): s is NotifyCategory;
|
|
17
|
+
export declare function isCategoryAlias(s: string): s is CategoryAlias;
|
|
18
|
+
/** Alias -> its canonical slug; a canonical slug -> itself; anything else unchanged. */
|
|
19
|
+
export declare function canonicalCategory(s: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Mark a hub-only category as usable. Throws TypeError when the string cannot
|
|
22
|
+
* be a slug at all — this is a programming error at the call site, not a
|
|
23
|
+
* delivery failure.
|
|
24
|
+
*/
|
|
25
|
+
export declare function customCategory(slug: string): CustomCategory;
|
|
26
|
+
/**
|
|
27
|
+
* For a category that comes from runtime config (a settings row, an env var):
|
|
28
|
+
* returns it typed, or null when it cannot be a slug. Whether the HUB holds a
|
|
29
|
+
* non-canonical one is only knowable by asking it — notify() reports its 400.
|
|
30
|
+
*/
|
|
31
|
+
export declare function toCategory(s: string | null | undefined): CategoryInput | null;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CATEGORY_SLUGS = exports.CATEGORY_ALIASES = exports.CATEGORIES = void 0;
|
|
4
|
+
exports.isCanonicalCategory = isCanonicalCategory;
|
|
5
|
+
exports.isCategoryAlias = isCategoryAlias;
|
|
6
|
+
exports.canonicalCategory = canonicalCategory;
|
|
7
|
+
exports.customCategory = customCategory;
|
|
8
|
+
exports.toCategory = toCategory;
|
|
9
|
+
const categories_js_1 = require("./generated/categories.js");
|
|
10
|
+
const contract_js_1 = require("./generated/contract.js");
|
|
11
|
+
var categories_js_2 = require("./generated/categories.js");
|
|
12
|
+
Object.defineProperty(exports, "CATEGORIES", { enumerable: true, get: function () { return categories_js_2.CATEGORIES; } });
|
|
13
|
+
Object.defineProperty(exports, "CATEGORY_ALIASES", { enumerable: true, get: function () { return categories_js_2.CATEGORY_ALIASES; } });
|
|
14
|
+
Object.defineProperty(exports, "CATEGORY_SLUGS", { enumerable: true, get: function () { return categories_js_2.CATEGORY_SLUGS; } });
|
|
15
|
+
const SLUG_RE = new RegExp(contract_js_1.SLUG_PATTERN);
|
|
16
|
+
const CANON = new Set(categories_js_1.CATEGORY_SLUGS);
|
|
17
|
+
function isCanonicalCategory(s) {
|
|
18
|
+
return CANON.has(s);
|
|
19
|
+
}
|
|
20
|
+
function isCategoryAlias(s) {
|
|
21
|
+
return Object.prototype.hasOwnProperty.call(categories_js_1.CATEGORY_ALIASES, s);
|
|
22
|
+
}
|
|
23
|
+
/** Alias -> its canonical slug; a canonical slug -> itself; anything else unchanged. */
|
|
24
|
+
function canonicalCategory(s) {
|
|
25
|
+
return isCategoryAlias(s) ? categories_js_1.CATEGORY_ALIASES[s] : s;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Mark a hub-only category as usable. Throws TypeError when the string cannot
|
|
29
|
+
* be a slug at all — this is a programming error at the call site, not a
|
|
30
|
+
* delivery failure.
|
|
31
|
+
*/
|
|
32
|
+
function customCategory(slug) {
|
|
33
|
+
if (!SLUG_RE.test(slug))
|
|
34
|
+
throw new TypeError(`not a category slug: ${JSON.stringify(slug)}`);
|
|
35
|
+
return slug;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* For a category that comes from runtime config (a settings row, an env var):
|
|
39
|
+
* returns it typed, or null when it cannot be a slug. Whether the HUB holds a
|
|
40
|
+
* non-canonical one is only knowable by asking it — notify() reports its 400.
|
|
41
|
+
*/
|
|
42
|
+
function toCategory(s) {
|
|
43
|
+
const v = (s ?? "").trim();
|
|
44
|
+
if (!v || !SLUG_RE.test(v))
|
|
45
|
+
return null;
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every environment variable the kit reads, by NAME. Values live in ZooVault
|
|
3
|
+
* and each app's .env — never in this package (it is public on npm), so there
|
|
4
|
+
* is no default host, IP or key anywhere in the kit.
|
|
5
|
+
*
|
|
6
|
+
* Read at CALL time, never at import: an app (or a test) that sets an env var
|
|
7
|
+
* after importing the kit must be honoured.
|
|
8
|
+
*/
|
|
9
|
+
/** Static names. Per-app names are built by {@link appKeyEnv} and friends. */
|
|
10
|
+
export declare const ENV: {
|
|
11
|
+
/** Comma-separated hub base URLs, primary first. */
|
|
12
|
+
readonly NOTIFIER_URLS: "ZOO_NOTIFIER_URLS";
|
|
13
|
+
/** Legacy single hub URL — read only when ZOO_NOTIFIER_URLS is unset. */
|
|
14
|
+
readonly NOTIFIER_URL: "ZOO_NOTIFIER_URL";
|
|
15
|
+
/** This app's per-source key on the hub. */
|
|
16
|
+
readonly NOTIFIER_KEY: "ZOO_NOTIFIER_KEY";
|
|
17
|
+
/** Comma-separated people-directory base URLs, primary first. */
|
|
18
|
+
readonly PEOPLE_URLS: "ZOO_PEOPLE_URLS";
|
|
19
|
+
/** This app's consumer token on the people directory. */
|
|
20
|
+
readonly PEOPLE_TOKEN: "ZOO_PEOPLE_TOKEN";
|
|
21
|
+
/** The consumer name the directory has declared for this app. */
|
|
22
|
+
readonly PEOPLE_CONSUMER: "ZOO_PEOPLE_CONSUMER";
|
|
23
|
+
/** Comma-separated public host(s) the authentik edge serves this app on. */
|
|
24
|
+
readonly PUBLIC_HOSTS: "ZOO_KIT_PUBLIC_HOSTS";
|
|
25
|
+
/** Legacy single public host — read only when ZOO_KIT_PUBLIC_HOSTS is unset. */
|
|
26
|
+
readonly PUBLIC_HOST: "PUBLIC_HOST";
|
|
27
|
+
/** The X-Zoo-Gate secret Traefik stamps behind authentik. */
|
|
28
|
+
readonly GATE_SECRET: "ZOO_KIT_GATE_SECRET";
|
|
29
|
+
/** Legacy name of the same secret — read only when ZOO_KIT_GATE_SECRET is unset. */
|
|
30
|
+
readonly AUTH_GATE_SECRET: "AUTH_GATE_SECRET";
|
|
31
|
+
/** Dev-box identity short-circuit; honoured only with `allowDevUser`. */
|
|
32
|
+
readonly DEV_USER: "DEV_USER";
|
|
33
|
+
/** App version fallback for the health handler. */
|
|
34
|
+
readonly APP_VERSION: "APP_VERSION";
|
|
35
|
+
/** Build commit for the health handler. */
|
|
36
|
+
readonly GIT_SHA: "GIT_SHA";
|
|
37
|
+
};
|
|
38
|
+
/** `zoo-vet` -> `ZOO_VET`. */
|
|
39
|
+
export declare function envSuffix(app: string): string;
|
|
40
|
+
/** Inbound: the key caller `app` presents to US. */
|
|
41
|
+
export declare const appKeyEnv: (app: string) => string;
|
|
42
|
+
/** Outbound: base URLs of `app`. */
|
|
43
|
+
export declare const appUrlsEnv: (app: string) => string;
|
|
44
|
+
/** Outbound: the key WE present to `app`. */
|
|
45
|
+
export declare const appKeyForEnv: (app: string) => string;
|
|
46
|
+
export declare function str(name: string): string;
|
|
47
|
+
/** A comma-separated list, trimmed, blanks dropped, trailing slashes removed. */
|
|
48
|
+
export declare function list(name: string): string[];
|
|
49
|
+
/** The first non-empty list among `names`, in order. */
|
|
50
|
+
export declare function firstList(...names: string[]): string[];
|
|
51
|
+
export declare function firstStr(...names: string[]): string;
|
|
52
|
+
/** One warning per process per key — a misconfigured app must not spam its log. */
|
|
53
|
+
export declare function warnOnce(key: string, msg: string): void;
|
|
54
|
+
/** Test hook. */
|
|
55
|
+
export declare function _resetWarnings(): void;
|
|
56
|
+
export interface ConfigReport {
|
|
57
|
+
ok: boolean;
|
|
58
|
+
/** Env var NAMES that are unset or blank. Never values. */
|
|
59
|
+
missing: string[];
|
|
60
|
+
}
|
|
61
|
+
/** Which of `required` are unset or blank — names only, for `checks.config`. */
|
|
62
|
+
export declare function checkConfig(required: string[]): ConfigReport;
|
package/dist/cjs/env.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Every environment variable the kit reads, by NAME. Values live in ZooVault
|
|
4
|
+
* and each app's .env — never in this package (it is public on npm), so there
|
|
5
|
+
* is no default host, IP or key anywhere in the kit.
|
|
6
|
+
*
|
|
7
|
+
* Read at CALL time, never at import: an app (or a test) that sets an env var
|
|
8
|
+
* after importing the kit must be honoured.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.appKeyForEnv = exports.appUrlsEnv = exports.appKeyEnv = exports.ENV = void 0;
|
|
12
|
+
exports.envSuffix = envSuffix;
|
|
13
|
+
exports.str = str;
|
|
14
|
+
exports.list = list;
|
|
15
|
+
exports.firstList = firstList;
|
|
16
|
+
exports.firstStr = firstStr;
|
|
17
|
+
exports.warnOnce = warnOnce;
|
|
18
|
+
exports._resetWarnings = _resetWarnings;
|
|
19
|
+
exports.checkConfig = checkConfig;
|
|
20
|
+
/** Static names. Per-app names are built by {@link appKeyEnv} and friends. */
|
|
21
|
+
exports.ENV = {
|
|
22
|
+
/** Comma-separated hub base URLs, primary first. */
|
|
23
|
+
NOTIFIER_URLS: "ZOO_NOTIFIER_URLS",
|
|
24
|
+
/** Legacy single hub URL — read only when ZOO_NOTIFIER_URLS is unset. */
|
|
25
|
+
NOTIFIER_URL: "ZOO_NOTIFIER_URL",
|
|
26
|
+
/** This app's per-source key on the hub. */
|
|
27
|
+
NOTIFIER_KEY: "ZOO_NOTIFIER_KEY",
|
|
28
|
+
/** Comma-separated people-directory base URLs, primary first. */
|
|
29
|
+
PEOPLE_URLS: "ZOO_PEOPLE_URLS",
|
|
30
|
+
/** This app's consumer token on the people directory. */
|
|
31
|
+
PEOPLE_TOKEN: "ZOO_PEOPLE_TOKEN",
|
|
32
|
+
/** The consumer name the directory has declared for this app. */
|
|
33
|
+
PEOPLE_CONSUMER: "ZOO_PEOPLE_CONSUMER",
|
|
34
|
+
/** Comma-separated public host(s) the authentik edge serves this app on. */
|
|
35
|
+
PUBLIC_HOSTS: "ZOO_KIT_PUBLIC_HOSTS",
|
|
36
|
+
/** Legacy single public host — read only when ZOO_KIT_PUBLIC_HOSTS is unset. */
|
|
37
|
+
PUBLIC_HOST: "PUBLIC_HOST",
|
|
38
|
+
/** The X-Zoo-Gate secret Traefik stamps behind authentik. */
|
|
39
|
+
GATE_SECRET: "ZOO_KIT_GATE_SECRET",
|
|
40
|
+
/** Legacy name of the same secret — read only when ZOO_KIT_GATE_SECRET is unset. */
|
|
41
|
+
AUTH_GATE_SECRET: "AUTH_GATE_SECRET",
|
|
42
|
+
/** Dev-box identity short-circuit; honoured only with `allowDevUser`. */
|
|
43
|
+
DEV_USER: "DEV_USER",
|
|
44
|
+
/** App version fallback for the health handler. */
|
|
45
|
+
APP_VERSION: "APP_VERSION",
|
|
46
|
+
/** Build commit for the health handler. */
|
|
47
|
+
GIT_SHA: "GIT_SHA",
|
|
48
|
+
};
|
|
49
|
+
/** `zoo-vet` -> `ZOO_VET`. */
|
|
50
|
+
function envSuffix(app) {
|
|
51
|
+
return app.trim().toUpperCase().replace(/[^A-Z0-9]+/g, "_");
|
|
52
|
+
}
|
|
53
|
+
/** Inbound: the key caller `app` presents to US. */
|
|
54
|
+
const appKeyEnv = (app) => `ZOO_KIT_APP_KEY_${envSuffix(app)}`;
|
|
55
|
+
exports.appKeyEnv = appKeyEnv;
|
|
56
|
+
/** Outbound: base URLs of `app`. */
|
|
57
|
+
const appUrlsEnv = (app) => `ZOO_KIT_APP_URLS_${envSuffix(app)}`;
|
|
58
|
+
exports.appUrlsEnv = appUrlsEnv;
|
|
59
|
+
/** Outbound: the key WE present to `app`. */
|
|
60
|
+
const appKeyForEnv = (app) => `ZOO_KIT_APP_KEY_FOR_${envSuffix(app)}`;
|
|
61
|
+
exports.appKeyForEnv = appKeyForEnv;
|
|
62
|
+
function str(name) {
|
|
63
|
+
return (process.env[name] ?? "").trim();
|
|
64
|
+
}
|
|
65
|
+
/** A comma-separated list, trimmed, blanks dropped, trailing slashes removed. */
|
|
66
|
+
function list(name) {
|
|
67
|
+
return str(name)
|
|
68
|
+
.split(",")
|
|
69
|
+
.map((s) => s.trim().replace(/\/+$/, ""))
|
|
70
|
+
.filter(Boolean);
|
|
71
|
+
}
|
|
72
|
+
/** The first non-empty list among `names`, in order. */
|
|
73
|
+
function firstList(...names) {
|
|
74
|
+
for (const n of names) {
|
|
75
|
+
const l = list(n);
|
|
76
|
+
if (l.length)
|
|
77
|
+
return l;
|
|
78
|
+
}
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
function firstStr(...names) {
|
|
82
|
+
for (const n of names) {
|
|
83
|
+
const v = str(n);
|
|
84
|
+
if (v)
|
|
85
|
+
return v;
|
|
86
|
+
}
|
|
87
|
+
return "";
|
|
88
|
+
}
|
|
89
|
+
const warned = new Set();
|
|
90
|
+
/** One warning per process per key — a misconfigured app must not spam its log. */
|
|
91
|
+
function warnOnce(key, msg) {
|
|
92
|
+
if (warned.has(key))
|
|
93
|
+
return;
|
|
94
|
+
warned.add(key);
|
|
95
|
+
console.warn(`[zoo-kit] ${msg}`);
|
|
96
|
+
}
|
|
97
|
+
/** Test hook. */
|
|
98
|
+
function _resetWarnings() {
|
|
99
|
+
warned.clear();
|
|
100
|
+
}
|
|
101
|
+
/** Which of `required` are unset or blank — names only, for `checks.config`. */
|
|
102
|
+
function checkConfig(required) {
|
|
103
|
+
const missing = required.filter((n) => !str(n));
|
|
104
|
+
return { ok: missing.length === 0, missing };
|
|
105
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Canonical category slugs (contracts/v1/categories.v1.json). */
|
|
2
|
+
export declare const CATEGORY_SLUGS: readonly ["backups", "bat-signal", "calendar", "cameras", "chores", "deploys", "financial", "general", "home", "infra", "location", "mail", "questions", "security", "siri", "summons", "test", "todos", "zoo-news"];
|
|
3
|
+
export type NotifyCategory = (typeof CATEGORY_SLUGS)[number];
|
|
4
|
+
/** alias -> canonical slug. The hub accepts an alias as sent. */
|
|
5
|
+
export declare const CATEGORY_ALIASES: {
|
|
6
|
+
readonly infrastructure: "infra";
|
|
7
|
+
};
|
|
8
|
+
export type CategoryAlias = keyof typeof CATEGORY_ALIASES;
|
|
9
|
+
export declare const CATEGORIES: readonly [{
|
|
10
|
+
readonly slug: "backups";
|
|
11
|
+
readonly name: "Backups";
|
|
12
|
+
readonly aliases: readonly [];
|
|
13
|
+
}, {
|
|
14
|
+
readonly slug: "bat-signal";
|
|
15
|
+
readonly name: "Bat Signal";
|
|
16
|
+
readonly aliases: readonly [];
|
|
17
|
+
}, {
|
|
18
|
+
readonly slug: "calendar";
|
|
19
|
+
readonly name: "Calendar";
|
|
20
|
+
readonly aliases: readonly [];
|
|
21
|
+
}, {
|
|
22
|
+
readonly slug: "cameras";
|
|
23
|
+
readonly name: "Cameras";
|
|
24
|
+
readonly aliases: readonly [];
|
|
25
|
+
}, {
|
|
26
|
+
readonly slug: "chores";
|
|
27
|
+
readonly name: "Chores";
|
|
28
|
+
readonly aliases: readonly [];
|
|
29
|
+
}, {
|
|
30
|
+
readonly slug: "deploys";
|
|
31
|
+
readonly name: "Deploys";
|
|
32
|
+
readonly aliases: readonly [];
|
|
33
|
+
}, {
|
|
34
|
+
readonly slug: "financial";
|
|
35
|
+
readonly name: "Financial";
|
|
36
|
+
readonly aliases: readonly [];
|
|
37
|
+
}, {
|
|
38
|
+
readonly slug: "general";
|
|
39
|
+
readonly name: "General";
|
|
40
|
+
readonly aliases: readonly [];
|
|
41
|
+
}, {
|
|
42
|
+
readonly slug: "home";
|
|
43
|
+
readonly name: "Home";
|
|
44
|
+
readonly aliases: readonly [];
|
|
45
|
+
}, {
|
|
46
|
+
readonly slug: "infra";
|
|
47
|
+
readonly name: "Infra";
|
|
48
|
+
readonly aliases: readonly ["infrastructure"];
|
|
49
|
+
}, {
|
|
50
|
+
readonly slug: "location";
|
|
51
|
+
readonly name: "Location";
|
|
52
|
+
readonly aliases: readonly [];
|
|
53
|
+
}, {
|
|
54
|
+
readonly slug: "mail";
|
|
55
|
+
readonly name: "Mail";
|
|
56
|
+
readonly aliases: readonly [];
|
|
57
|
+
}, {
|
|
58
|
+
readonly slug: "questions";
|
|
59
|
+
readonly name: "Questions";
|
|
60
|
+
readonly aliases: readonly [];
|
|
61
|
+
}, {
|
|
62
|
+
readonly slug: "security";
|
|
63
|
+
readonly name: "Security";
|
|
64
|
+
readonly aliases: readonly [];
|
|
65
|
+
}, {
|
|
66
|
+
readonly slug: "siri";
|
|
67
|
+
readonly name: "Siri";
|
|
68
|
+
readonly aliases: readonly [];
|
|
69
|
+
}, {
|
|
70
|
+
readonly slug: "summons";
|
|
71
|
+
readonly name: "Summons";
|
|
72
|
+
readonly aliases: readonly [];
|
|
73
|
+
}, {
|
|
74
|
+
readonly slug: "test";
|
|
75
|
+
readonly name: "Test";
|
|
76
|
+
readonly aliases: readonly [];
|
|
77
|
+
}, {
|
|
78
|
+
readonly slug: "todos";
|
|
79
|
+
readonly name: "Todos";
|
|
80
|
+
readonly aliases: readonly [];
|
|
81
|
+
}, {
|
|
82
|
+
readonly slug: "zoo-news";
|
|
83
|
+
readonly name: "Zoo News";
|
|
84
|
+
readonly aliases: readonly [];
|
|
85
|
+
}];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GENERATED by packages/zoo-kit/scripts/generate.mjs from contracts/v1/categories.v1.json.
|
|
3
|
+
// Do not edit — change the contract and run `npm run gen`.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.CATEGORIES = exports.CATEGORY_ALIASES = exports.CATEGORY_SLUGS = void 0;
|
|
6
|
+
/** Canonical category slugs (contracts/v1/categories.v1.json). */
|
|
7
|
+
exports.CATEGORY_SLUGS = ["backups", "bat-signal", "calendar", "cameras", "chores", "deploys", "financial", "general", "home", "infra", "location", "mail", "questions", "security", "siri", "summons", "test", "todos", "zoo-news"];
|
|
8
|
+
/** alias -> canonical slug. The hub accepts an alias as sent. */
|
|
9
|
+
exports.CATEGORY_ALIASES = { "infrastructure": "infra" };
|
|
10
|
+
exports.CATEGORIES = [{ "slug": "backups", "name": "Backups", "aliases": [] }, { "slug": "bat-signal", "name": "Bat Signal", "aliases": [] }, { "slug": "calendar", "name": "Calendar", "aliases": [] }, { "slug": "cameras", "name": "Cameras", "aliases": [] }, { "slug": "chores", "name": "Chores", "aliases": [] }, { "slug": "deploys", "name": "Deploys", "aliases": [] }, { "slug": "financial", "name": "Financial", "aliases": [] }, { "slug": "general", "name": "General", "aliases": [] }, { "slug": "home", "name": "Home", "aliases": [] }, { "slug": "infra", "name": "Infra", "aliases": ["infrastructure"] }, { "slug": "location", "name": "Location", "aliases": [] }, { "slug": "mail", "name": "Mail", "aliases": [] }, { "slug": "questions", "name": "Questions", "aliases": [] }, { "slug": "security", "name": "Security", "aliases": [] }, { "slug": "siri", "name": "Siri", "aliases": [] }, { "slug": "summons", "name": "Summons", "aliases": [] }, { "slug": "test", "name": "Test", "aliases": [] }, { "slug": "todos", "name": "Todos", "aliases": [] }, { "slug": "zoo-news", "name": "Zoo News", "aliases": [] }];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** The kit's own version — reported as `kit` by the health handler. */
|
|
2
|
+
export declare const KIT_VERSION = "1.1.0";
|
|
3
|
+
/** The exact keys a v1 Person may carry; anything else is dropped. */
|
|
4
|
+
export declare const PERSON_KEYS: readonly ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
|
|
5
|
+
export declare const NOTIFY_PRIORITIES: readonly ["passive", "active", "time-sensitive", "critical"];
|
|
6
|
+
/** The Slug pattern a category must match. */
|
|
7
|
+
export declare const SLUG_PATTERN = "^[a-z0-9][a-z0-9-]{0,39}$";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// GENERATED by packages/zoo-kit/scripts/generate.mjs from contracts/v1/*.v1.yaml + packages/zoo-kit/package.json.
|
|
3
|
+
// Do not edit — change the contract and run `npm run gen`.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.SLUG_PATTERN = exports.NOTIFY_PRIORITIES = exports.PERSON_KEYS = exports.KIT_VERSION = void 0;
|
|
6
|
+
/** The kit's own version — reported as `kit` by the health handler. */
|
|
7
|
+
exports.KIT_VERSION = "1.1.0";
|
|
8
|
+
/** The exact keys a v1 Person may carry; anything else is dropped. */
|
|
9
|
+
exports.PERSON_KEYS = ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
|
|
10
|
+
exports.NOTIFY_PRIORITIES = ["passive", "active", "time-sensitive", "critical"];
|
|
11
|
+
/** The Slug pattern a category must match. */
|
|
12
|
+
exports.SLUG_PATTERN = "^[a-z0-9][a-z0-9-]{0,39}$";
|