@jdcpuwiz/zoo-kit 1.3.0 → 1.5.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 +27 -0
- package/dist/cjs/devices.d.ts +20 -1
- package/dist/cjs/devices.js +24 -2
- package/dist/cjs/generated/contract.d.ts +1 -1
- package/dist/cjs/generated/contract.js +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/people.d.ts +15 -0
- package/dist/cjs/people.js +25 -0
- package/dist/cjs/whoami.d.ts +6 -0
- package/dist/cjs/whoami.js +4 -0
- package/dist/devices.d.ts +20 -1
- package/dist/devices.js +24 -2
- package/dist/generated/contract.d.ts +1 -1
- package/dist/generated/contract.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/people.d.ts +15 -0
- package/dist/people.js +25 -0
- package/dist/whoami.d.ts +6 -0
- package/dist/whoami.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -178,6 +178,20 @@ Answers are cached 5 min and served stale ≤15 min while the directory is down.
|
|
|
178
178
|
`People` itself is unchanged; the extra member lives on `PeopleClient`, so a
|
|
179
179
|
hand-rolled `People` stub still type-checks.
|
|
180
180
|
|
|
181
|
+
### people.signature (1.4.0, additive — BP#130 S8a)
|
|
182
|
+
|
|
183
|
+
A person's one signature, set on their zoo-people profile (draw, type or
|
|
184
|
+
upload; a PNG with a transparent background):
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
const s = await people.signature("shad"); // {status: ok|none|unavailable|unconfigured, png, sha256, error?}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`GET /api/v1/people/{slug}/signature` on the same `ZOO_PEOPLE_URLS` with the
|
|
191
|
+
same token. zoo-people admits it on its OWN caller list (`SIGNATURE_CALLERS`,
|
|
192
|
+
default `timesheet`, `zoo-studio`); any other key gets 401. Never cached, never
|
|
193
|
+
throws.
|
|
194
|
+
|
|
181
195
|
## devices (1.3.0, additive — BP#129 P10c)
|
|
182
196
|
|
|
183
197
|
One device pairing for the fleet: zoo-people owns every paired phone; an app
|
|
@@ -221,6 +235,19 @@ export const POST = devices.revokeHandler();
|
|
|
221
235
|
| zoo-people refuses THIS app's key | treated as an outage (warned once), never as the phone's 401 |
|
|
222
236
|
| `app` set and the answer is another app's device | 401 |
|
|
223
237
|
|
|
238
|
+
### One pairing per device (1.5.0, additive — BP#149 P2)
|
|
239
|
+
|
|
240
|
+
zoo-people (≥0.23.0) also issues ONE `zd_` key per physical device; Wiz switches
|
|
241
|
+
apps on per device. The same `resolve` call takes it. New on `identity.device`:
|
|
242
|
+
`physicalDeviceId` (null for a legacy per-app key), `deviceName` (the physical
|
|
243
|
+
device's name) and `role` (the role/profile on this app's grant; = `appRole`).
|
|
244
|
+
`device.id` is the grant id, which is what zoo-people's revoke push carries.
|
|
245
|
+
|
|
246
|
+
| Situation | Answer |
|
|
247
|
+
|---|---|
|
|
248
|
+
| live `zd_` key, this app NOT switched on | **403** `reason:"not granted"` + `notGranted:{app, appLabel, deviceName}` — the phone KEEPS its key and shows "Ask Wiz to turn on <appLabel>"; never cached, so a grant takes effect on the next call. `requirePerson` throws `ZooKitAuthError(403)`. |
|
|
249
|
+
| any 401 from zoo-people | re-resolved ONCE before it is final (a grant or pairing written a moment ago never costs the phone its key) |
|
|
250
|
+
|
|
224
251
|
Keys live in memory only as sha256 hashes; `redeem` goes to the primary URL
|
|
225
252
|
only (a timed-out redeem may have landed) and primes the cache with the new
|
|
226
253
|
device. `selfRevoke(key)` forwards a phone's own Unpair. `ZooKitAuthError.status`
|
package/dist/cjs/devices.d.ts
CHANGED
|
@@ -27,9 +27,16 @@ export interface DevicePerson {
|
|
|
27
27
|
enabled: boolean;
|
|
28
28
|
}
|
|
29
29
|
export interface DeviceInfo {
|
|
30
|
+
/** The app's handle for this device: the legacy per-app Device id, or the DeviceGrant id for a `zd_` key. Revoke pushes carry this. */
|
|
30
31
|
id: string;
|
|
31
32
|
name: string;
|
|
32
33
|
appRole: string | null;
|
|
34
|
+
/** BP#149: the physical device (one pairing per phone/TV). Null for a legacy per-app key. */
|
|
35
|
+
physicalDeviceId: string | null;
|
|
36
|
+
/** BP#149: the physical device's name ("Shad's iPhone"); the per-app name for a legacy key. */
|
|
37
|
+
deviceName: string;
|
|
38
|
+
/** BP#149: the role/profile Wiz set on this app's grant (= appRole). */
|
|
39
|
+
role: string | null;
|
|
33
40
|
}
|
|
34
41
|
export interface DeviceIdentity {
|
|
35
42
|
kind: "person";
|
|
@@ -42,14 +49,26 @@ export interface DeviceIdentity {
|
|
|
42
49
|
}
|
|
43
50
|
/** fresh = zoo-people just said so; cached = inside the 60 s; stale = last-known-good during an outage. */
|
|
44
51
|
export type DeviceStatus = "fresh" | "cached" | "stale";
|
|
52
|
+
/**
|
|
53
|
+
* A refusal. 401 = the key is unknown or revoked (the phone may forget it).
|
|
54
|
+
* 403 = BP#149 "not granted": a live one-pairing (`zd_`) key whose device does
|
|
55
|
+
* not have THIS app switched on — the phone must KEEP its key and show
|
|
56
|
+
* "Ask Wiz to turn on <appLabel>"; once Wiz grants it the next call is admitted
|
|
57
|
+
* with no re-pair. 503 = zoo-people unreachable and the key not cached.
|
|
58
|
+
*/
|
|
45
59
|
export type DeviceVerdict = {
|
|
46
60
|
ok: true;
|
|
47
61
|
identity: DeviceIdentity;
|
|
48
62
|
status: DeviceStatus;
|
|
49
63
|
} | {
|
|
50
64
|
ok: false;
|
|
51
|
-
status: 401 | 503;
|
|
65
|
+
status: 401 | 403 | 503;
|
|
52
66
|
reason: string;
|
|
67
|
+
notGranted?: {
|
|
68
|
+
app: string;
|
|
69
|
+
appLabel: string;
|
|
70
|
+
deviceName: string;
|
|
71
|
+
};
|
|
53
72
|
};
|
|
54
73
|
export interface RedeemOptions {
|
|
55
74
|
deviceName?: string;
|
package/dist/cjs/devices.js
CHANGED
|
@@ -98,13 +98,21 @@ function toIdentity(raw) {
|
|
|
98
98
|
const person = toPersonPart(r.person);
|
|
99
99
|
if (!person || !str(r.deviceId) || !str(r.app))
|
|
100
100
|
return null;
|
|
101
|
+
const appRole = typeof r.appRole === "string" ? r.appRole : null;
|
|
101
102
|
return {
|
|
102
103
|
kind: "person",
|
|
103
104
|
via: "device",
|
|
104
105
|
slug: person.slug,
|
|
105
106
|
personId: person.id,
|
|
106
107
|
app: str(r.app),
|
|
107
|
-
device: {
|
|
108
|
+
device: {
|
|
109
|
+
id: str(r.deviceId),
|
|
110
|
+
name: str(r.name),
|
|
111
|
+
appRole,
|
|
112
|
+
physicalDeviceId: str(r.physicalDeviceId) || null,
|
|
113
|
+
deviceName: str(r.deviceName) || str(r.name),
|
|
114
|
+
role: appRole,
|
|
115
|
+
},
|
|
108
116
|
person,
|
|
109
117
|
};
|
|
110
118
|
}
|
|
@@ -172,7 +180,7 @@ function createDevices(options = {}) {
|
|
|
172
180
|
return { kind: "failed", error: out.error };
|
|
173
181
|
return { kind: "response", status: out.res.status, json: await (0, http_js_1.readJson)(out.res) };
|
|
174
182
|
}
|
|
175
|
-
async function lookup(key, h, prev) {
|
|
183
|
+
async function lookup(key, h, prev, retried = false) {
|
|
176
184
|
const outage = (why) => {
|
|
177
185
|
if (prev && now() - prev.at < o.staleMs && !revoked(prev.identity.device.id)) {
|
|
178
186
|
return { ok: true, identity: prev.identity, status: "stale" };
|
|
@@ -203,7 +211,21 @@ function createDevices(options = {}) {
|
|
|
203
211
|
return { ok: true, identity, status: "fresh" };
|
|
204
212
|
}
|
|
205
213
|
if (res.status === 401 && err === "unknown-or-revoked") {
|
|
214
|
+
// BP#149: re-resolve ONCE before a 401 is final — a grant switched on (or
|
|
215
|
+
// a fresh pairing written) a moment ago must not cost the phone its key.
|
|
216
|
+
if (!retried)
|
|
217
|
+
return lookup(key, h, prev, true);
|
|
206
218
|
cache.delete(h);
|
|
219
|
+
const j = (res.json ?? {});
|
|
220
|
+
if (str(j.reason) === "not-granted") {
|
|
221
|
+
const app = str(j.app) || options.app || "";
|
|
222
|
+
return {
|
|
223
|
+
ok: false,
|
|
224
|
+
status: 403,
|
|
225
|
+
reason: "not granted",
|
|
226
|
+
notGranted: { app, appLabel: str(j.appLabel) || app, deviceName: str(j.deviceName) },
|
|
227
|
+
};
|
|
228
|
+
}
|
|
207
229
|
return refuse(401, "unknown or revoked device");
|
|
208
230
|
}
|
|
209
231
|
// Any other answer (our own app key refused, a 4xx we don't know) is OUR
|
|
@@ -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.
|
|
2
|
+
export declare const KIT_VERSION = "1.5.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.
|
|
7
|
+
exports.KIT_VERSION = "1.5.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"];
|
package/dist/cjs/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 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";
|
|
15
|
+
export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type Contact, type Contacts, type ContactsResult, type ContactsStatus, type People, type PeopleClient, type SignatureResult, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
|
|
16
16
|
export { DEVICES_DEFAULTS, DEVICES_PATHS, DEVICE_REVOKE_PATH, createDevices, devices, type DeviceIdentity, type DeviceInfo, type DevicePerson, type DeviceStatus, type DeviceVerdict, type Devices, type DevicesOptions, type RedeemOptions, type RedeemResult, } from "./devices.js";
|
|
17
17
|
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";
|
|
18
18
|
export { ZooKitConfigError, bearerOf, callApp, checkApp, safeEqual, type AppIdentity, type AppVerdict, type CallAppOptions, type HeaderBag, type RequestLike, } from "./keys.js";
|
package/dist/cjs/people.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare const PEOPLE_PATHS: {
|
|
|
39
39
|
readonly list: "/api/v1/people";
|
|
40
40
|
readonly whoamiResolve: "/api/v1/whoami-resolve";
|
|
41
41
|
readonly contactsSearch: "/api/v1/contacts/search";
|
|
42
|
+
readonly signature: (slug: string) => string;
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
45
|
* A card from the directory's Contacts book (v1.2, additive — BP#127 P9c).
|
|
@@ -91,7 +92,21 @@ export interface People {
|
|
|
91
92
|
export type PeopleClient = People & {
|
|
92
93
|
/** Search Wiz's own Contacts book through the directory. */
|
|
93
94
|
contacts: Contacts;
|
|
95
|
+
/**
|
|
96
|
+
* A person's signature PNG (transparent background) — v1.4, additive, BP#130 S8a.
|
|
97
|
+
* zoo-people admits it on its OWN caller list (`SIGNATURE_CALLERS`: timesheet,
|
|
98
|
+
* zoo-studio). Never throws; never cached (a person can redraw it any time).
|
|
99
|
+
*/
|
|
100
|
+
signature(slug: string): Promise<SignatureResult>;
|
|
94
101
|
};
|
|
102
|
+
/** `status`: ok = png set; none = that person has no signature (or no such person). */
|
|
103
|
+
export interface SignatureResult {
|
|
104
|
+
status: "ok" | "none" | "unavailable" | "unconfigured";
|
|
105
|
+
png: Uint8Array | null;
|
|
106
|
+
/** Hex sha256 of `png`, as zoo-people reports it (ETag). */
|
|
107
|
+
sha256: string | null;
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
95
110
|
/** A people client with its own cache. Most apps use the shared {@link people}. */
|
|
96
111
|
export declare function createPeople(options?: PeopleOptions): PeopleClient;
|
|
97
112
|
/** The process-wide people client. */
|
package/dist/cjs/people.js
CHANGED
|
@@ -38,6 +38,7 @@ exports.PEOPLE_PATHS = {
|
|
|
38
38
|
list: "/api/v1/people",
|
|
39
39
|
whoamiResolve: "/api/v1/whoami-resolve",
|
|
40
40
|
contactsSearch: "/api/v1/contacts/search",
|
|
41
|
+
signature: (slug) => `/api/v1/people/${encodeURIComponent(slug)}/signature`,
|
|
41
42
|
};
|
|
42
43
|
function toContact(raw) {
|
|
43
44
|
if (!raw || typeof raw !== "object")
|
|
@@ -213,6 +214,30 @@ function createPeople(options = {}) {
|
|
|
213
214
|
return r.contacts.find((c) => c.emails.includes(e)) ?? null;
|
|
214
215
|
},
|
|
215
216
|
},
|
|
217
|
+
async signature(slug) {
|
|
218
|
+
const sl = (slug ?? "").trim().toLowerCase();
|
|
219
|
+
if (!sl)
|
|
220
|
+
return { status: "none", png: null, sha256: null };
|
|
221
|
+
const c = config();
|
|
222
|
+
if (c.missing.length) {
|
|
223
|
+
(0, env_js_1.warnOnce)("people-unconfigured", `people is unavailable: ${c.missing.join(", ")} not set`);
|
|
224
|
+
return { status: "unconfigured", png: null, sha256: null, error: `not configured: ${c.missing.join(", ")} not set` };
|
|
225
|
+
}
|
|
226
|
+
const outcome = await (0, http_js_1.failoverFetch)(c.urls, exports.PEOPLE_PATHS.signature(sl), { method: "GET", headers: { Authorization: `Bearer ${c.token}`, Accept: "image/png" } }, o);
|
|
227
|
+
if (outcome.kind === "failed")
|
|
228
|
+
return { status: "unavailable", png: null, sha256: null, error: outcome.error };
|
|
229
|
+
const { res } = outcome;
|
|
230
|
+
if (res.status === 404)
|
|
231
|
+
return { status: "none", png: null, sha256: null };
|
|
232
|
+
if (!res.ok || !(res.headers.get("content-type") ?? "").startsWith("image/png")) {
|
|
233
|
+
if (!res.ok)
|
|
234
|
+
(0, env_js_1.warnOnce)(`people-signature-${res.status}`, `the people directory refused a signature read (${res.status}) — is this app in zoo-people's SIGNATURE_CALLERS?`);
|
|
235
|
+
return { status: "unavailable", png: null, sha256: null, error: `HTTP ${res.status}` };
|
|
236
|
+
}
|
|
237
|
+
const png = new Uint8Array(await res.arrayBuffer());
|
|
238
|
+
const sha = res.headers.get("x-signature-sha256") ?? ((res.headers.get("etag") ?? "").replace(/"/g, "") || null);
|
|
239
|
+
return { status: "ok", png, sha256: sha };
|
|
240
|
+
},
|
|
216
241
|
clear() {
|
|
217
242
|
listCache = null;
|
|
218
243
|
users.clear();
|
package/dist/cjs/whoami.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface Anonymous {
|
|
|
19
19
|
reason?: string;
|
|
20
20
|
/** True when the answer is "could not check" (zoo-people down) rather than "no" — requirePerson answers 503. */
|
|
21
21
|
unavailable?: boolean;
|
|
22
|
+
/** BP#149: a live one-pairing key whose device doesn't have this app switched on (keep the key; ask Wiz). */
|
|
23
|
+
notGranted?: {
|
|
24
|
+
app: string;
|
|
25
|
+
appLabel: string;
|
|
26
|
+
deviceName: string;
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
export type Identity = PersonIdentity | AppIdentity | Anonymous;
|
|
24
30
|
export interface AuthentikOptions {
|
package/dist/cjs/whoami.js
CHANGED
|
@@ -124,6 +124,8 @@ async function whoami(req, opts = {}) {
|
|
|
124
124
|
}
|
|
125
125
|
if (v.status === 503)
|
|
126
126
|
return { kind: "anonymous", reason: v.reason, unavailable: true };
|
|
127
|
+
if (v.status === 403)
|
|
128
|
+
return { kind: "anonymous", reason: v.reason, notGranted: v.notGranted };
|
|
127
129
|
if (!opts.resolveDeviceKey)
|
|
128
130
|
return { kind: "anonymous", reason: v.reason };
|
|
129
131
|
}
|
|
@@ -201,6 +203,8 @@ async function requirePerson(req, opts = {}) {
|
|
|
201
203
|
return who;
|
|
202
204
|
if (who.kind === "anonymous" && who.unavailable)
|
|
203
205
|
throw new ZooKitAuthError(503, who.reason ?? "");
|
|
206
|
+
if (who.kind === "anonymous" && who.notGranted)
|
|
207
|
+
throw new ZooKitAuthError(403, "not granted");
|
|
204
208
|
throw new ZooKitAuthError(401, who.kind === "anonymous" ? (who.reason ?? "") : "an app key is not a person");
|
|
205
209
|
}
|
|
206
210
|
/**
|
package/dist/devices.d.ts
CHANGED
|
@@ -27,9 +27,16 @@ export interface DevicePerson {
|
|
|
27
27
|
enabled: boolean;
|
|
28
28
|
}
|
|
29
29
|
export interface DeviceInfo {
|
|
30
|
+
/** The app's handle for this device: the legacy per-app Device id, or the DeviceGrant id for a `zd_` key. Revoke pushes carry this. */
|
|
30
31
|
id: string;
|
|
31
32
|
name: string;
|
|
32
33
|
appRole: string | null;
|
|
34
|
+
/** BP#149: the physical device (one pairing per phone/TV). Null for a legacy per-app key. */
|
|
35
|
+
physicalDeviceId: string | null;
|
|
36
|
+
/** BP#149: the physical device's name ("Shad's iPhone"); the per-app name for a legacy key. */
|
|
37
|
+
deviceName: string;
|
|
38
|
+
/** BP#149: the role/profile Wiz set on this app's grant (= appRole). */
|
|
39
|
+
role: string | null;
|
|
33
40
|
}
|
|
34
41
|
export interface DeviceIdentity {
|
|
35
42
|
kind: "person";
|
|
@@ -42,14 +49,26 @@ export interface DeviceIdentity {
|
|
|
42
49
|
}
|
|
43
50
|
/** fresh = zoo-people just said so; cached = inside the 60 s; stale = last-known-good during an outage. */
|
|
44
51
|
export type DeviceStatus = "fresh" | "cached" | "stale";
|
|
52
|
+
/**
|
|
53
|
+
* A refusal. 401 = the key is unknown or revoked (the phone may forget it).
|
|
54
|
+
* 403 = BP#149 "not granted": a live one-pairing (`zd_`) key whose device does
|
|
55
|
+
* not have THIS app switched on — the phone must KEEP its key and show
|
|
56
|
+
* "Ask Wiz to turn on <appLabel>"; once Wiz grants it the next call is admitted
|
|
57
|
+
* with no re-pair. 503 = zoo-people unreachable and the key not cached.
|
|
58
|
+
*/
|
|
45
59
|
export type DeviceVerdict = {
|
|
46
60
|
ok: true;
|
|
47
61
|
identity: DeviceIdentity;
|
|
48
62
|
status: DeviceStatus;
|
|
49
63
|
} | {
|
|
50
64
|
ok: false;
|
|
51
|
-
status: 401 | 503;
|
|
65
|
+
status: 401 | 403 | 503;
|
|
52
66
|
reason: string;
|
|
67
|
+
notGranted?: {
|
|
68
|
+
app: string;
|
|
69
|
+
appLabel: string;
|
|
70
|
+
deviceName: string;
|
|
71
|
+
};
|
|
53
72
|
};
|
|
54
73
|
export interface RedeemOptions {
|
|
55
74
|
deviceName?: string;
|
package/dist/devices.js
CHANGED
|
@@ -94,13 +94,21 @@ function toIdentity(raw) {
|
|
|
94
94
|
const person = toPersonPart(r.person);
|
|
95
95
|
if (!person || !str(r.deviceId) || !str(r.app))
|
|
96
96
|
return null;
|
|
97
|
+
const appRole = typeof r.appRole === "string" ? r.appRole : null;
|
|
97
98
|
return {
|
|
98
99
|
kind: "person",
|
|
99
100
|
via: "device",
|
|
100
101
|
slug: person.slug,
|
|
101
102
|
personId: person.id,
|
|
102
103
|
app: str(r.app),
|
|
103
|
-
device: {
|
|
104
|
+
device: {
|
|
105
|
+
id: str(r.deviceId),
|
|
106
|
+
name: str(r.name),
|
|
107
|
+
appRole,
|
|
108
|
+
physicalDeviceId: str(r.physicalDeviceId) || null,
|
|
109
|
+
deviceName: str(r.deviceName) || str(r.name),
|
|
110
|
+
role: appRole,
|
|
111
|
+
},
|
|
104
112
|
person,
|
|
105
113
|
};
|
|
106
114
|
}
|
|
@@ -168,7 +176,7 @@ export function createDevices(options = {}) {
|
|
|
168
176
|
return { kind: "failed", error: out.error };
|
|
169
177
|
return { kind: "response", status: out.res.status, json: await readJson(out.res) };
|
|
170
178
|
}
|
|
171
|
-
async function lookup(key, h, prev) {
|
|
179
|
+
async function lookup(key, h, prev, retried = false) {
|
|
172
180
|
const outage = (why) => {
|
|
173
181
|
if (prev && now() - prev.at < o.staleMs && !revoked(prev.identity.device.id)) {
|
|
174
182
|
return { ok: true, identity: prev.identity, status: "stale" };
|
|
@@ -199,7 +207,21 @@ export function createDevices(options = {}) {
|
|
|
199
207
|
return { ok: true, identity, status: "fresh" };
|
|
200
208
|
}
|
|
201
209
|
if (res.status === 401 && err === "unknown-or-revoked") {
|
|
210
|
+
// BP#149: re-resolve ONCE before a 401 is final — a grant switched on (or
|
|
211
|
+
// a fresh pairing written) a moment ago must not cost the phone its key.
|
|
212
|
+
if (!retried)
|
|
213
|
+
return lookup(key, h, prev, true);
|
|
202
214
|
cache.delete(h);
|
|
215
|
+
const j = (res.json ?? {});
|
|
216
|
+
if (str(j.reason) === "not-granted") {
|
|
217
|
+
const app = str(j.app) || options.app || "";
|
|
218
|
+
return {
|
|
219
|
+
ok: false,
|
|
220
|
+
status: 403,
|
|
221
|
+
reason: "not granted",
|
|
222
|
+
notGranted: { app, appLabel: str(j.appLabel) || app, deviceName: str(j.deviceName) },
|
|
223
|
+
};
|
|
224
|
+
}
|
|
203
225
|
return refuse(401, "unknown or revoked device");
|
|
204
226
|
}
|
|
205
227
|
// Any other answer (our own app key refused, a 4xx we don't know) is OUR
|
|
@@ -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.
|
|
2
|
+
export declare const KIT_VERSION = "1.5.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.
|
|
4
|
+
export const KIT_VERSION = "1.5.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 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";
|
|
15
|
+
export { PEOPLE_DEFAULTS, PEOPLE_PATHS, createPeople, people, toPerson, type Contact, type Contacts, type ContactsResult, type ContactsStatus, type People, type PeopleClient, type SignatureResult, type PeopleList, type PeopleOptions, type PeopleStatus, type Person, type ResolveStatus, type ResolvedUsername, } from "./people.js";
|
|
16
16
|
export { DEVICES_DEFAULTS, DEVICES_PATHS, DEVICE_REVOKE_PATH, createDevices, devices, type DeviceIdentity, type DeviceInfo, type DevicePerson, type DeviceStatus, type DeviceVerdict, type Devices, type DevicesOptions, type RedeemOptions, type RedeemResult, } from "./devices.js";
|
|
17
17
|
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";
|
|
18
18
|
export { ZooKitConfigError, bearerOf, callApp, checkApp, safeEqual, type AppIdentity, type AppVerdict, type CallAppOptions, type HeaderBag, type RequestLike, } from "./keys.js";
|
package/dist/people.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export declare const PEOPLE_PATHS: {
|
|
|
39
39
|
readonly list: "/api/v1/people";
|
|
40
40
|
readonly whoamiResolve: "/api/v1/whoami-resolve";
|
|
41
41
|
readonly contactsSearch: "/api/v1/contacts/search";
|
|
42
|
+
readonly signature: (slug: string) => string;
|
|
42
43
|
};
|
|
43
44
|
/**
|
|
44
45
|
* A card from the directory's Contacts book (v1.2, additive — BP#127 P9c).
|
|
@@ -91,7 +92,21 @@ export interface People {
|
|
|
91
92
|
export type PeopleClient = People & {
|
|
92
93
|
/** Search Wiz's own Contacts book through the directory. */
|
|
93
94
|
contacts: Contacts;
|
|
95
|
+
/**
|
|
96
|
+
* A person's signature PNG (transparent background) — v1.4, additive, BP#130 S8a.
|
|
97
|
+
* zoo-people admits it on its OWN caller list (`SIGNATURE_CALLERS`: timesheet,
|
|
98
|
+
* zoo-studio). Never throws; never cached (a person can redraw it any time).
|
|
99
|
+
*/
|
|
100
|
+
signature(slug: string): Promise<SignatureResult>;
|
|
94
101
|
};
|
|
102
|
+
/** `status`: ok = png set; none = that person has no signature (or no such person). */
|
|
103
|
+
export interface SignatureResult {
|
|
104
|
+
status: "ok" | "none" | "unavailable" | "unconfigured";
|
|
105
|
+
png: Uint8Array | null;
|
|
106
|
+
/** Hex sha256 of `png`, as zoo-people reports it (ETag). */
|
|
107
|
+
sha256: string | null;
|
|
108
|
+
error?: string;
|
|
109
|
+
}
|
|
95
110
|
/** A people client with its own cache. Most apps use the shared {@link people}. */
|
|
96
111
|
export declare function createPeople(options?: PeopleOptions): PeopleClient;
|
|
97
112
|
/** The process-wide people client. */
|
package/dist/people.js
CHANGED
|
@@ -33,6 +33,7 @@ export const PEOPLE_PATHS = {
|
|
|
33
33
|
list: "/api/v1/people",
|
|
34
34
|
whoamiResolve: "/api/v1/whoami-resolve",
|
|
35
35
|
contactsSearch: "/api/v1/contacts/search",
|
|
36
|
+
signature: (slug) => `/api/v1/people/${encodeURIComponent(slug)}/signature`,
|
|
36
37
|
};
|
|
37
38
|
function toContact(raw) {
|
|
38
39
|
if (!raw || typeof raw !== "object")
|
|
@@ -208,6 +209,30 @@ export function createPeople(options = {}) {
|
|
|
208
209
|
return r.contacts.find((c) => c.emails.includes(e)) ?? null;
|
|
209
210
|
},
|
|
210
211
|
},
|
|
212
|
+
async signature(slug) {
|
|
213
|
+
const sl = (slug ?? "").trim().toLowerCase();
|
|
214
|
+
if (!sl)
|
|
215
|
+
return { status: "none", png: null, sha256: null };
|
|
216
|
+
const c = config();
|
|
217
|
+
if (c.missing.length) {
|
|
218
|
+
warnOnce("people-unconfigured", `people is unavailable: ${c.missing.join(", ")} not set`);
|
|
219
|
+
return { status: "unconfigured", png: null, sha256: null, error: `not configured: ${c.missing.join(", ")} not set` };
|
|
220
|
+
}
|
|
221
|
+
const outcome = await failoverFetch(c.urls, PEOPLE_PATHS.signature(sl), { method: "GET", headers: { Authorization: `Bearer ${c.token}`, Accept: "image/png" } }, o);
|
|
222
|
+
if (outcome.kind === "failed")
|
|
223
|
+
return { status: "unavailable", png: null, sha256: null, error: outcome.error };
|
|
224
|
+
const { res } = outcome;
|
|
225
|
+
if (res.status === 404)
|
|
226
|
+
return { status: "none", png: null, sha256: null };
|
|
227
|
+
if (!res.ok || !(res.headers.get("content-type") ?? "").startsWith("image/png")) {
|
|
228
|
+
if (!res.ok)
|
|
229
|
+
warnOnce(`people-signature-${res.status}`, `the people directory refused a signature read (${res.status}) — is this app in zoo-people's SIGNATURE_CALLERS?`);
|
|
230
|
+
return { status: "unavailable", png: null, sha256: null, error: `HTTP ${res.status}` };
|
|
231
|
+
}
|
|
232
|
+
const png = new Uint8Array(await res.arrayBuffer());
|
|
233
|
+
const sha = res.headers.get("x-signature-sha256") ?? ((res.headers.get("etag") ?? "").replace(/"/g, "") || null);
|
|
234
|
+
return { status: "ok", png, sha256: sha };
|
|
235
|
+
},
|
|
211
236
|
clear() {
|
|
212
237
|
listCache = null;
|
|
213
238
|
users.clear();
|
package/dist/whoami.d.ts
CHANGED
|
@@ -19,6 +19,12 @@ export interface Anonymous {
|
|
|
19
19
|
reason?: string;
|
|
20
20
|
/** True when the answer is "could not check" (zoo-people down) rather than "no" — requirePerson answers 503. */
|
|
21
21
|
unavailable?: boolean;
|
|
22
|
+
/** BP#149: a live one-pairing key whose device doesn't have this app switched on (keep the key; ask Wiz). */
|
|
23
|
+
notGranted?: {
|
|
24
|
+
app: string;
|
|
25
|
+
appLabel: string;
|
|
26
|
+
deviceName: string;
|
|
27
|
+
};
|
|
22
28
|
}
|
|
23
29
|
export type Identity = PersonIdentity | AppIdentity | Anonymous;
|
|
24
30
|
export interface AuthentikOptions {
|
package/dist/whoami.js
CHANGED
|
@@ -115,6 +115,8 @@ export async function whoami(req, opts = {}) {
|
|
|
115
115
|
}
|
|
116
116
|
if (v.status === 503)
|
|
117
117
|
return { kind: "anonymous", reason: v.reason, unavailable: true };
|
|
118
|
+
if (v.status === 403)
|
|
119
|
+
return { kind: "anonymous", reason: v.reason, notGranted: v.notGranted };
|
|
118
120
|
if (!opts.resolveDeviceKey)
|
|
119
121
|
return { kind: "anonymous", reason: v.reason };
|
|
120
122
|
}
|
|
@@ -191,6 +193,8 @@ export async function requirePerson(req, opts = {}) {
|
|
|
191
193
|
return who;
|
|
192
194
|
if (who.kind === "anonymous" && who.unavailable)
|
|
193
195
|
throw new ZooKitAuthError(503, who.reason ?? "");
|
|
196
|
+
if (who.kind === "anonymous" && who.notGranted)
|
|
197
|
+
throw new ZooKitAuthError(403, "not granted");
|
|
194
198
|
throw new ZooKitAuthError(401, who.kind === "anonymous" ? (who.reason ?? "") : "an app key is not a person");
|
|
195
199
|
}
|
|
196
200
|
/**
|
package/package.json
CHANGED