@jdcpuwiz/zoo-kit 1.1.0 → 1.2.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 CHANGED
@@ -161,6 +161,23 @@ const me = await people.byAuthentikUsername("Shad"); // Person | null
161
161
  Person carries the contract's roster keys only (anything else in an answer is
162
162
  dropped). Archived people are in the list with `enabled: false`.
163
163
 
164
+ ### people.contacts (1.2.0, additive)
165
+
166
+ Wiz's own Contacts book (Radicale), searched through the directory — not the
167
+ family roster, so the result is a `Contact`, never a `Person`:
168
+
169
+ ```ts
170
+ const r = await people.contacts.search("pat"); // {contacts, status, error?} — never throws
171
+ const c = await people.contacts.byEmail("pat@x.test"); // exact email match or null
172
+ ```
173
+
174
+ `GET /api/v1/contacts/search?q=&limit=` on the same `ZOO_PEOPLE_URLS` with the
175
+ same token. zoo-people admits it on its OWN caller list (`CONTACTS_CALLERS`,
176
+ default `snailslap`), so a roster reader is not automatically a contacts reader.
177
+ Answers are cached 5 min and served stale ≤15 min while the directory is down.
178
+ `People` itself is unchanged; the extra member lives on `PeopleClient`, so a
179
+ hand-rolled `People` stub still type-checks.
180
+
164
181
  ## Health route
165
182
 
166
183
  ```ts
@@ -1,5 +1,5 @@
1
1
  /** The kit's own version — reported as `kit` by the health handler. */
2
- export declare const KIT_VERSION = "1.1.0";
2
+ export declare const KIT_VERSION = "1.2.0";
3
3
  /** The exact keys a v1 Person may carry; anything else is dropped. */
4
4
  export declare const PERSON_KEYS: readonly ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
5
5
  export declare const NOTIFY_PRIORITIES: readonly ["passive", "active", "time-sensitive", "critical"];
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.SLUG_PATTERN = exports.NOTIFY_PRIORITIES = exports.PERSON_KEYS = exports.KIT_VERSION = void 0;
6
6
  /** The kit's own version — reported as `kit` by the health handler. */
7
- exports.KIT_VERSION = "1.1.0";
7
+ exports.KIT_VERSION = "1.2.0";
8
8
  /** The exact keys a v1 Person may carry; anything else is dropped. */
9
9
  exports.PERSON_KEYS = ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
10
10
  exports.NOTIFY_PRIORITIES = ["passive", "active", "time-sensitive", "critical"];
@@ -12,7 +12,7 @@
12
12
  export { ENV, appKeyEnv, appKeyForEnv, appUrlsEnv, checkConfig, envSuffix, type ConfigReport } from "./env.js";
13
13
  export { CATEGORIES, CATEGORY_ALIASES, CATEGORY_SLUGS, canonicalCategory, customCategory, isCanonicalCategory, isCategoryAlias, toCategory, type CategoryAlias, type CategoryInput, type CustomCategory, type NotifyCategory, } from "./categories.js";
14
14
  export { NOTIFY_DEFAULTS, NOTIFY_PATH, dedupeKey, notify, notifyConfigured, type NotifyAction, type NotifyDryRun, type NotifyFailed, type NotifyInput, type NotifyOptions, type NotifyPriority, type NotifyResult, type NotifySent, } from "./notify.js";
15
- export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type People, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
15
+ export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type Contact, type Contacts, type ContactsResult, type ContactsStatus, type People, type PeopleClient, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
16
16
  export { ZooKitAuthError, cameThroughGate, gateSecretOk, readAuthentikUsername, requireApp, requirePerson, whoami, type Anonymous, type AuthentikOptions, type DeviceAnswer, type Identity, type PersonIdentity, type SessionAnswer, type WhoamiOptions, } from "./whoami.js";
17
17
  export { ZooKitConfigError, bearerOf, callApp, checkApp, safeEqual, type AppIdentity, type AppVerdict, type CallAppOptions, type HeaderBag, type RequestLike, } from "./keys.js";
18
18
  export { healthBody, healthHandler, type CheckFn, type CheckResult, type HealthBody, type HealthOptions } from "./health.js";
@@ -38,7 +38,35 @@ export declare const PEOPLE_DEFAULTS: {
38
38
  export declare const PEOPLE_PATHS: {
39
39
  readonly list: "/api/v1/people";
40
40
  readonly whoamiResolve: "/api/v1/whoami-resolve";
41
+ readonly contactsSearch: "/api/v1/contacts/search";
41
42
  };
43
+ /**
44
+ * A card from the directory's Contacts book (v1.2, additive — BP#127 P9c).
45
+ * Not a Person: the Contacts book is anyone Wiz keeps, not the family roster.
46
+ */
47
+ export interface Contact {
48
+ uid: string | null;
49
+ name: string;
50
+ /** Lower-cased. */
51
+ emails: string[];
52
+ phones: string[];
53
+ org: string | null;
54
+ hasPhoto: boolean;
55
+ }
56
+ export type ContactsStatus = "fresh" | "stale" | "unavailable" | "unconfigured";
57
+ export interface ContactsResult {
58
+ contacts: Contact[];
59
+ status: ContactsStatus;
60
+ error?: string;
61
+ }
62
+ export interface Contacts {
63
+ /** Ranked search (exact email first, then name prefix …). Never throws; an outage is status "unavailable". */
64
+ search(q: string, opts?: {
65
+ limit?: number;
66
+ }): Promise<ContactsResult>;
67
+ /** The contact holding exactly this email, or null. Cached like search. */
68
+ byEmail(email: string): Promise<Contact | null>;
69
+ }
42
70
  /** Keep only the contract's Person keys; null for anything that is not a usable person. */
43
71
  export declare function toPerson(raw: unknown): Person | null;
44
72
  export interface People {
@@ -55,7 +83,16 @@ export interface People {
55
83
  /** Drop every cached answer. */
56
84
  clear(): void;
57
85
  }
86
+ /**
87
+ * The client {@link createPeople} returns: People plus the Contacts book
88
+ * (v1.2, additive). Kept OUT of the People interface so an app's hand-rolled
89
+ * People stub (whoami tests) still type-checks after the bump.
90
+ */
91
+ export type PeopleClient = People & {
92
+ /** Search Wiz's own Contacts book through the directory. */
93
+ contacts: Contacts;
94
+ };
58
95
  /** A people client with its own cache. Most apps use the shared {@link people}. */
59
- export declare function createPeople(options?: PeopleOptions): People;
96
+ export declare function createPeople(options?: PeopleOptions): PeopleClient;
60
97
  /** The process-wide people client. */
61
- export declare const people: People;
98
+ export declare const people: PeopleClient;
@@ -37,7 +37,24 @@ exports.PEOPLE_DEFAULTS = {
37
37
  exports.PEOPLE_PATHS = {
38
38
  list: "/api/v1/people",
39
39
  whoamiResolve: "/api/v1/whoami-resolve",
40
+ contactsSearch: "/api/v1/contacts/search",
40
41
  };
42
+ function toContact(raw) {
43
+ if (!raw || typeof raw !== "object")
44
+ return null;
45
+ const r = raw;
46
+ if (typeof r.name !== "string" || !r.name)
47
+ return null;
48
+ const strs = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === "string") : []);
49
+ return {
50
+ uid: typeof r.uid === "string" ? r.uid : null,
51
+ name: r.name,
52
+ emails: strs(r.emails).map((e) => e.toLowerCase()),
53
+ phones: strs(r.phones),
54
+ org: typeof r.org === "string" ? r.org : null,
55
+ hasPhoto: r.hasPhoto === true,
56
+ };
57
+ }
41
58
  const KEYS = new Set(contract_js_1.PERSON_KEYS);
42
59
  /** Keep only the contract's Person keys; null for anything that is not a usable person. */
43
60
  function toPerson(raw) {
@@ -72,6 +89,7 @@ function createPeople(options = {}) {
72
89
  let listCache = null;
73
90
  let listInflight = null;
74
91
  const users = new Map();
92
+ const searches = new Map();
75
93
  async function get(path) {
76
94
  const c = config();
77
95
  if (c.missing.length) {
@@ -159,9 +177,46 @@ function createPeople(options = {}) {
159
177
  return { ok: true, detail: `stale since ${l.loadedAt?.toISOString()}: ${l.error ?? ""}`.trim() };
160
178
  throw new Error(`roster ${l.status}${l.error ? `: ${l.error}` : ""}`);
161
179
  },
180
+ contacts: {
181
+ async search(q, opts = {}) {
182
+ const needle = (q ?? "").trim().toLowerCase();
183
+ if (!needle)
184
+ return { contacts: [], status: "fresh" };
185
+ const limit = Math.max(1, Math.min(50, Math.floor(opts.limit ?? 20)));
186
+ const key = `${limit}|${needle}`;
187
+ const hit = searches.get(key);
188
+ const age = hit ? now() - hit.at : Infinity;
189
+ if (hit && age < o.ttlMs)
190
+ return hit.result;
191
+ const got = await get(`${exports.PEOPLE_PATHS.contactsSearch}?q=${encodeURIComponent(needle)}&limit=${limit}`);
192
+ if (got.kind === "ok") {
193
+ const j = got.json;
194
+ if (Array.isArray(j?.contacts)) {
195
+ const contacts = j.contacts.map(toContact).filter((c) => c !== null);
196
+ const result = { contacts, status: j?.status === "stale" ? "stale" : "fresh" };
197
+ if (searches.size > 500)
198
+ searches.clear();
199
+ searches.set(key, { result, at: now() });
200
+ return result;
201
+ }
202
+ }
203
+ const error = got.kind === "ok" ? "malformed contacts answer" : got.kind === "not-found" ? "HTTP 404" : got.error;
204
+ if (hit && age <= o.staleUsernameMs)
205
+ return { ...hit.result, status: "stale", error };
206
+ return { contacts: [], status: got.kind === "unconfigured" ? "unconfigured" : "unavailable", error };
207
+ },
208
+ async byEmail(email) {
209
+ const e = (email ?? "").trim().toLowerCase();
210
+ if (!e)
211
+ return null;
212
+ const r = await api.contacts.search(e, { limit: 5 });
213
+ return r.contacts.find((c) => c.emails.includes(e)) ?? null;
214
+ },
215
+ },
162
216
  clear() {
163
217
  listCache = null;
164
218
  users.clear();
219
+ searches.clear();
165
220
  },
166
221
  };
167
222
  return api;
@@ -1,5 +1,5 @@
1
1
  /** The kit's own version — reported as `kit` by the health handler. */
2
- export declare const KIT_VERSION = "1.1.0";
2
+ export declare const KIT_VERSION = "1.2.0";
3
3
  /** The exact keys a v1 Person may carry; anything else is dropped. */
4
4
  export declare const PERSON_KEYS: readonly ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
5
5
  export declare const NOTIFY_PRIORITIES: readonly ["passive", "active", "time-sensitive", "critical"];
@@ -1,7 +1,7 @@
1
1
  // GENERATED by packages/zoo-kit/scripts/generate.mjs from contracts/v1/*.v1.yaml + packages/zoo-kit/package.json.
2
2
  // Do not edit — change the contract and run `npm run gen`.
3
3
  /** The kit's own version — reported as `kit` by the health handler. */
4
- export const KIT_VERSION = "1.1.0";
4
+ export const KIT_VERSION = "1.2.0";
5
5
  /** The exact keys a v1 Person may carry; anything else is dropped. */
6
6
  export const PERSON_KEYS = ["authentikUsername", "dob", "enabled", "haEntityId", "headingColor", "id", "kind", "name", "photoUrl", "role", "slug", "sortOrder", "traccarDeviceId"];
7
7
  export const NOTIFY_PRIORITIES = ["passive", "active", "time-sensitive", "critical"];
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  export { ENV, appKeyEnv, appKeyForEnv, appUrlsEnv, checkConfig, envSuffix, type ConfigReport } from "./env.js";
13
13
  export { CATEGORIES, CATEGORY_ALIASES, CATEGORY_SLUGS, canonicalCategory, customCategory, isCanonicalCategory, isCategoryAlias, toCategory, type CategoryAlias, type CategoryInput, type CustomCategory, type NotifyCategory, } from "./categories.js";
14
14
  export { NOTIFY_DEFAULTS, NOTIFY_PATH, dedupeKey, notify, notifyConfigured, type NotifyAction, type NotifyDryRun, type NotifyFailed, type NotifyInput, type NotifyOptions, type NotifyPriority, type NotifyResult, type NotifySent, } from "./notify.js";
15
- export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type People, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
15
+ export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type Contact, type Contacts, type ContactsResult, type ContactsStatus, type People, type PeopleClient, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
16
16
  export { ZooKitAuthError, cameThroughGate, gateSecretOk, readAuthentikUsername, requireApp, requirePerson, whoami, type Anonymous, type AuthentikOptions, type DeviceAnswer, type Identity, type PersonIdentity, type SessionAnswer, type WhoamiOptions, } from "./whoami.js";
17
17
  export { ZooKitConfigError, bearerOf, callApp, checkApp, safeEqual, type AppIdentity, type AppVerdict, type CallAppOptions, type HeaderBag, type RequestLike, } from "./keys.js";
18
18
  export { healthBody, healthHandler, type CheckFn, type CheckResult, type HealthBody, type HealthOptions } from "./health.js";
package/dist/people.d.ts CHANGED
@@ -38,7 +38,35 @@ export declare const PEOPLE_DEFAULTS: {
38
38
  export declare const PEOPLE_PATHS: {
39
39
  readonly list: "/api/v1/people";
40
40
  readonly whoamiResolve: "/api/v1/whoami-resolve";
41
+ readonly contactsSearch: "/api/v1/contacts/search";
41
42
  };
43
+ /**
44
+ * A card from the directory's Contacts book (v1.2, additive — BP#127 P9c).
45
+ * Not a Person: the Contacts book is anyone Wiz keeps, not the family roster.
46
+ */
47
+ export interface Contact {
48
+ uid: string | null;
49
+ name: string;
50
+ /** Lower-cased. */
51
+ emails: string[];
52
+ phones: string[];
53
+ org: string | null;
54
+ hasPhoto: boolean;
55
+ }
56
+ export type ContactsStatus = "fresh" | "stale" | "unavailable" | "unconfigured";
57
+ export interface ContactsResult {
58
+ contacts: Contact[];
59
+ status: ContactsStatus;
60
+ error?: string;
61
+ }
62
+ export interface Contacts {
63
+ /** Ranked search (exact email first, then name prefix …). Never throws; an outage is status "unavailable". */
64
+ search(q: string, opts?: {
65
+ limit?: number;
66
+ }): Promise<ContactsResult>;
67
+ /** The contact holding exactly this email, or null. Cached like search. */
68
+ byEmail(email: string): Promise<Contact | null>;
69
+ }
42
70
  /** Keep only the contract's Person keys; null for anything that is not a usable person. */
43
71
  export declare function toPerson(raw: unknown): Person | null;
44
72
  export interface People {
@@ -55,7 +83,16 @@ export interface People {
55
83
  /** Drop every cached answer. */
56
84
  clear(): void;
57
85
  }
86
+ /**
87
+ * The client {@link createPeople} returns: People plus the Contacts book
88
+ * (v1.2, additive). Kept OUT of the People interface so an app's hand-rolled
89
+ * People stub (whoami tests) still type-checks after the bump.
90
+ */
91
+ export type PeopleClient = People & {
92
+ /** Search Wiz's own Contacts book through the directory. */
93
+ contacts: Contacts;
94
+ };
58
95
  /** A people client with its own cache. Most apps use the shared {@link people}. */
59
- export declare function createPeople(options?: PeopleOptions): People;
96
+ export declare function createPeople(options?: PeopleOptions): PeopleClient;
60
97
  /** The process-wide people client. */
61
- export declare const people: People;
98
+ export declare const people: PeopleClient;
package/dist/people.js CHANGED
@@ -32,7 +32,24 @@ export const PEOPLE_DEFAULTS = {
32
32
  export const PEOPLE_PATHS = {
33
33
  list: "/api/v1/people",
34
34
  whoamiResolve: "/api/v1/whoami-resolve",
35
+ contactsSearch: "/api/v1/contacts/search",
35
36
  };
37
+ function toContact(raw) {
38
+ if (!raw || typeof raw !== "object")
39
+ return null;
40
+ const r = raw;
41
+ if (typeof r.name !== "string" || !r.name)
42
+ return null;
43
+ const strs = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === "string") : []);
44
+ return {
45
+ uid: typeof r.uid === "string" ? r.uid : null,
46
+ name: r.name,
47
+ emails: strs(r.emails).map((e) => e.toLowerCase()),
48
+ phones: strs(r.phones),
49
+ org: typeof r.org === "string" ? r.org : null,
50
+ hasPhoto: r.hasPhoto === true,
51
+ };
52
+ }
36
53
  const KEYS = new Set(PERSON_KEYS);
37
54
  /** Keep only the contract's Person keys; null for anything that is not a usable person. */
38
55
  export function toPerson(raw) {
@@ -67,6 +84,7 @@ export function createPeople(options = {}) {
67
84
  let listCache = null;
68
85
  let listInflight = null;
69
86
  const users = new Map();
87
+ const searches = new Map();
70
88
  async function get(path) {
71
89
  const c = config();
72
90
  if (c.missing.length) {
@@ -154,9 +172,46 @@ export function createPeople(options = {}) {
154
172
  return { ok: true, detail: `stale since ${l.loadedAt?.toISOString()}: ${l.error ?? ""}`.trim() };
155
173
  throw new Error(`roster ${l.status}${l.error ? `: ${l.error}` : ""}`);
156
174
  },
175
+ contacts: {
176
+ async search(q, opts = {}) {
177
+ const needle = (q ?? "").trim().toLowerCase();
178
+ if (!needle)
179
+ return { contacts: [], status: "fresh" };
180
+ const limit = Math.max(1, Math.min(50, Math.floor(opts.limit ?? 20)));
181
+ const key = `${limit}|${needle}`;
182
+ const hit = searches.get(key);
183
+ const age = hit ? now() - hit.at : Infinity;
184
+ if (hit && age < o.ttlMs)
185
+ return hit.result;
186
+ const got = await get(`${PEOPLE_PATHS.contactsSearch}?q=${encodeURIComponent(needle)}&limit=${limit}`);
187
+ if (got.kind === "ok") {
188
+ const j = got.json;
189
+ if (Array.isArray(j?.contacts)) {
190
+ const contacts = j.contacts.map(toContact).filter((c) => c !== null);
191
+ const result = { contacts, status: j?.status === "stale" ? "stale" : "fresh" };
192
+ if (searches.size > 500)
193
+ searches.clear();
194
+ searches.set(key, { result, at: now() });
195
+ return result;
196
+ }
197
+ }
198
+ const error = got.kind === "ok" ? "malformed contacts answer" : got.kind === "not-found" ? "HTTP 404" : got.error;
199
+ if (hit && age <= o.staleUsernameMs)
200
+ return { ...hit.result, status: "stale", error };
201
+ return { contacts: [], status: got.kind === "unconfigured" ? "unconfigured" : "unavailable", error };
202
+ },
203
+ async byEmail(email) {
204
+ const e = (email ?? "").trim().toLowerCase();
205
+ if (!e)
206
+ return null;
207
+ const r = await api.contacts.search(e, { limit: 5 });
208
+ return r.contacts.find((c) => c.emails.includes(e)) ?? null;
209
+ },
210
+ },
157
211
  clear() {
158
212
  listCache = null;
159
213
  users.clear();
214
+ searches.clear();
160
215
  },
161
216
  };
162
217
  return api;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jdcpuwiz/zoo-kit",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",