@jdcpuwiz/zoo-kit 1.0.0 → 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/dist/notify.js CHANGED
@@ -9,6 +9,10 @@
9
9
  * list, logs one line and resolves `{ ok: false, error }`.
10
10
  *
11
11
  * Missing config is one logged warning and a no-op — never a guessed host.
12
+ *
13
+ * An app that keeps its hub settings somewhere other than env (an encrypted
14
+ * settings table) passes `{ urls, key }` per call; the key is sent as the Bearer
15
+ * header and nowhere else, so it never reaches a result or a log line.
12
16
  */
13
17
  import { createHash, randomUUID } from "node:crypto";
14
18
  import { ENV, firstList, str, warnOnce } from "./env.js";
@@ -43,9 +47,10 @@ export function dedupeKey(kind, ...parts) {
43
47
  return key;
44
48
  return `${kind.toLowerCase()}:sha256-${createHash("sha256").update(key).digest("hex").slice(0, 48)}`;
45
49
  }
46
- function config() {
47
- const urls = firstList(ENV.NOTIFIER_URLS, ENV.NOTIFIER_URL);
48
- const key = str(ENV.NOTIFIER_KEY);
50
+ function config(override = {}) {
51
+ const urlsOverride = (override.urls ?? []).map((u) => u.trim().replace(/\/+$/, "")).filter(Boolean);
52
+ const urls = urlsOverride.length ? urlsOverride : firstList(ENV.NOTIFIER_URLS, ENV.NOTIFIER_URL);
53
+ const key = override.key?.trim() || str(ENV.NOTIFIER_KEY);
49
54
  const missing = [];
50
55
  if (!urls.length)
51
56
  missing.push(ENV.NOTIFIER_URLS);
@@ -53,7 +58,7 @@ function config() {
53
58
  missing.push(ENV.NOTIFIER_KEY);
54
59
  return { urls, key, missing };
55
60
  }
56
- /** Is notify configured? Names only. */
61
+ /** Is notify configured through the env? Names only; per-call overrides are not counted. */
57
62
  export function notifyConfigured() {
58
63
  const { missing } = config();
59
64
  return { ok: missing.length === 0, missing };
@@ -70,7 +75,8 @@ function failed(error, extra = {}) {
70
75
  */
71
76
  export async function notify(input, opts = {}) {
72
77
  try {
73
- const { urls, key, missing } = config();
78
+ const { urls: urlsOverride, key: keyOverride, dryRun, ...failover } = opts;
79
+ const { urls, key, missing } = config({ urls: urlsOverride, key: keyOverride });
74
80
  if (missing.length) {
75
81
  warnOnce("notify-unconfigured", `notify is a no-op: ${missing.join(", ")} not set`);
76
82
  return failed(`not configured: ${missing.join(", ")} not set`, { skipped: "unconfigured" });
@@ -84,14 +90,14 @@ export async function notify(input, opts = {}) {
84
90
  const body = stripUndefined({ ...input });
85
91
  if (!body.dedupeKey)
86
92
  body.dedupeKey = dedupeKey("kit-once", randomUUID());
87
- if (opts.dryRun) {
93
+ if (dryRun) {
88
94
  return { ok: true, dryRun: true, queued: false, deduped: false, urls, path: NOTIFY_PATH, body };
89
95
  }
90
96
  const outcome = await failoverFetch(urls, NOTIFY_PATH, {
91
97
  method: "POST",
92
98
  headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
93
99
  body: JSON.stringify(body),
94
- }, { ...NOTIFY_DEFAULTS, ...stripUndefined(opts) });
100
+ }, { ...NOTIFY_DEFAULTS, ...stripUndefined(failover) });
95
101
  if (outcome.kind === "failed") {
96
102
  console.warn(`[zoo-kit] notify failed after ${outcome.attempts.length} attempt(s): ${outcome.error}`);
97
103
  return failed(outcome.error, { status: outcome.status, attempts: outcome.attempts });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdcpuwiz/zoo-kit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Thin, pinned server-side client for the homelab's shared services: notify, whoami, people, health, app keys.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -12,14 +12,21 @@
12
12
  "types": "./dist/index.d.ts",
13
13
  "exports": {
14
14
  ".": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.js"
15
+ "import": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ },
19
+ "require": {
20
+ "types": "./dist/cjs/index.d.ts",
21
+ "default": "./dist/cjs/index.js"
22
+ }
17
23
  },
18
24
  "./package.json": "./package.json"
19
25
  },
20
26
  "files": [
21
27
  "dist/**/*.js",
22
28
  "dist/**/*.d.ts",
29
+ "dist/cjs/package.json",
23
30
  "README.md",
24
31
  "LICENSE"
25
32
  ],
@@ -36,8 +43,9 @@
36
43
  "gen:check": "node scripts/generate.mjs --check",
37
44
  "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p tsconfig.test.json",
38
45
  "test": "npm run gen:check && vitest run",
39
- "build": "npm run gen:check && rm -rf dist && tsc -p tsconfig.build.json",
46
+ "build": "npm run gen:check && rm -rf dist && tsc -p tsconfig.build.json && tsc -p tsconfig.cjs.json && node scripts/write-cjs-package.mjs",
40
47
  "prepack": "npm run build",
48
+ "test:tarball": "node scripts/tarball-test.mjs",
41
49
  "smoke:live": "npm run build && node scripts/live-smoke.mjs"
42
50
  },
43
51
  "devDependencies": {