@jdcpuwiz/zoo-kit 1.4.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 +13 -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/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/whoami.d.ts +6 -0
- package/dist/whoami.js +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -235,6 +235,19 @@ export const POST = devices.revokeHandler();
|
|
|
235
235
|
| zoo-people refuses THIS app's key | treated as an outage (warned once), never as the phone's 401 |
|
|
236
236
|
| `app` set and the answer is another app's device | 401 |
|
|
237
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
|
+
|
|
238
251
|
Keys live in memory only as sha256 hashes; `redeem` goes to the primary URL
|
|
239
252
|
only (a timed-out redeem may have landed) and primes the cache with the new
|
|
240
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/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/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