@agimon-ai/po-remote 0.0.0-alpha.198 → 0.0.0-alpha.199
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/index.cjs +178 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +136 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +179 -4
- package/dist/index.mjs.map +1 -1
- package/dist/po-runtime-identity.json +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -2929,6 +2929,62 @@ function parseNativePushRegistration(value, platform) {
|
|
|
2929
2929
|
function sameNativePushRegistration(a, b) {
|
|
2930
2930
|
return a.platform === b.platform && a.token === b.token && a.hostRef === b.hostRef && (a.platform !== "ios" || b.platform === "ios" && a.environment === b.environment);
|
|
2931
2931
|
}
|
|
2932
|
+
/** Strict allowlist shared by sealed enrollment and disk restore. No arbitrary widget props survive. */
|
|
2933
|
+
function parseLiveActivityRegistration(value) {
|
|
2934
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2935
|
+
const body = value;
|
|
2936
|
+
const keys = [
|
|
2937
|
+
"platform",
|
|
2938
|
+
"activityId",
|
|
2939
|
+
"sessionId",
|
|
2940
|
+
"token",
|
|
2941
|
+
"environment",
|
|
2942
|
+
"startedAt",
|
|
2943
|
+
"expiresAt",
|
|
2944
|
+
"presentation"
|
|
2945
|
+
];
|
|
2946
|
+
if (Object.keys(body).some((key) => !keys.includes(key)) || body.platform !== "ios" || typeof body.activityId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(body.activityId) || typeof body.sessionId !== "string" || !/^[A-Za-z0-9_-]{1,128}$/u.test(body.sessionId) || typeof body.token !== "string" || body.token.length > MAX_TOKEN_LENGTH || !APNS_TOKEN.test(body.token) || !["development", "production"].includes(body.environment) || !Number.isSafeInteger(body.startedAt) || !Number.isSafeInteger(body.expiresAt) || body.startedAt < 0 || body.expiresAt <= body.startedAt || body.expiresAt - body.startedAt > _agimon_ai_po_core_remoteContract.LIVE_ACTIVITY_MAX_LIFETIME_MS) return void 0;
|
|
2947
|
+
const p = body.presentation;
|
|
2948
|
+
if (!p || typeof p !== "object" || Array.isArray(p) || JSON.stringify(p).length > 3e3 || Object.keys(p).some((key) => ![
|
|
2949
|
+
"nameFallback",
|
|
2950
|
+
"initials",
|
|
2951
|
+
"avatar",
|
|
2952
|
+
"labels",
|
|
2953
|
+
"approvalLabel",
|
|
2954
|
+
"themes",
|
|
2955
|
+
"spacing"
|
|
2956
|
+
].includes(key))) return void 0;
|
|
2957
|
+
const text = (v, max) => typeof v === "string" && v.length <= max && !/[\u0000-\u001f\u007f]/u.test(v);
|
|
2958
|
+
if (p.nameFallback !== void 0 && !text(p.nameFallback, 160) || !text(p.initials, 8) || !text(p.approvalLabel, 160) || p.avatar !== void 0 && (typeof p.avatar !== "string" || p.avatar.length > 512 || !/^file:\/\/\/(?:private\/)?var\/mobile\/Containers\/Shared\/AppGroup\/[A-Fa-f0-9-]{36}\/po-session-avatars\/[A-Za-z0-9_-]+\.(png|jpeg|webp)$/u.test(p.avatar) || p.avatar.split("/").includes("..")) || !(typeof p.spacing === "number" && Number.isFinite(p.spacing) && p.spacing > 0 && p.spacing <= 64)) return void 0;
|
|
2959
|
+
const statuses = [
|
|
2960
|
+
"working",
|
|
2961
|
+
"question",
|
|
2962
|
+
"approval",
|
|
2963
|
+
"finished",
|
|
2964
|
+
"stale",
|
|
2965
|
+
"unavailable"
|
|
2966
|
+
];
|
|
2967
|
+
if (!p.labels || Object.keys(p.labels).length !== statuses.length || !statuses.every((key) => text(p.labels[key], 160))) return void 0;
|
|
2968
|
+
if (!p.themes || Object.keys(p.themes).length !== 2) return void 0;
|
|
2969
|
+
for (const scheme of ["light", "dark"]) {
|
|
2970
|
+
const colors = p.themes[scheme];
|
|
2971
|
+
if (!colors || Object.keys(colors).length !== 6 || ![
|
|
2972
|
+
"hi",
|
|
2973
|
+
"dim",
|
|
2974
|
+
"panel",
|
|
2975
|
+
"green",
|
|
2976
|
+
"magenta",
|
|
2977
|
+
"tint"
|
|
2978
|
+
].every((key) => {
|
|
2979
|
+
const color = colors[key];
|
|
2980
|
+
return typeof color === "string" && /^#[a-fA-F0-9]{6}(?:[a-fA-F0-9]{2})?$/u.test(color);
|
|
2981
|
+
})) return void 0;
|
|
2982
|
+
}
|
|
2983
|
+
return structuredClone({
|
|
2984
|
+
...body,
|
|
2985
|
+
token: body.token.toLowerCase()
|
|
2986
|
+
});
|
|
2987
|
+
}
|
|
2932
2988
|
//#endregion
|
|
2933
2989
|
//#region src/services/pairingFlow/index.ts
|
|
2934
2990
|
/** Failed claims allowed per source inside one window before the endpoint starts refusing. */
|
|
@@ -3225,7 +3281,7 @@ function isLooseMode(mode) {
|
|
|
3225
3281
|
function isTrustedDeviceRecord(value) {
|
|
3226
3282
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
3227
3283
|
const record = value;
|
|
3228
|
-
return typeof record.id === "string" && STORED_ID.test(record.id) && typeof record.identityPublicKey === "string" && STORED_KEY.test(record.identityPublicKey) && typeof record.stepUpPublicKey === "string" && STORED_KEY.test(record.stepUpPublicKey) && record.identityPublicKey !== record.stepUpPublicKey && typeof record.label === "string" && record.label.length <= MAX_STORED_LABEL && typeof record.platform === "string" && TRUSTED_DEVICE_PLATFORMS.has(record.platform) && Number.isFinite(record.createdAt) && Number.isFinite(record.lastSeenAt) && (record.nativePushEnrollment === void 0 || isPrincipal(record.nativePushEnrollment) && "generation" in record.nativePushEnrollment && Number.isSafeInteger(record.nativePushEnrollment.generation) && Number(record.nativePushEnrollment.generation) > 0) && (record.person === void 0 && record.accountDeviceKeyId === void 0 || isPrincipal(record.person) && typeof record.accountDeviceKeyId === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(record.accountDeviceKeyId));
|
|
3284
|
+
return typeof record.id === "string" && STORED_ID.test(record.id) && typeof record.identityPublicKey === "string" && STORED_KEY.test(record.identityPublicKey) && typeof record.stepUpPublicKey === "string" && STORED_KEY.test(record.stepUpPublicKey) && record.identityPublicKey !== record.stepUpPublicKey && typeof record.label === "string" && record.label.length <= MAX_STORED_LABEL && typeof record.platform === "string" && TRUSTED_DEVICE_PLATFORMS.has(record.platform) && Number.isFinite(record.createdAt) && Number.isFinite(record.lastSeenAt) && (record.liveActivityEnrollment === void 0 || isPrincipal(record.liveActivityEnrollment) && "generation" in record.liveActivityEnrollment && Number.isSafeInteger(record.liveActivityEnrollment.generation) && Number(record.liveActivityEnrollment.generation) > 0) && (record.nativePushEnrollment === void 0 || isPrincipal(record.nativePushEnrollment) && "generation" in record.nativePushEnrollment && Number.isSafeInteger(record.nativePushEnrollment.generation) && Number(record.nativePushEnrollment.generation) > 0) && (record.person === void 0 && record.accountDeviceKeyId === void 0 || isPrincipal(record.person) && typeof record.accountDeviceKeyId === "string" && /^[A-Za-z0-9_-]{1,128}$/.test(record.accountDeviceKeyId));
|
|
3229
3285
|
}
|
|
3230
3286
|
function parseSettingsFile(raw, settingsPath, notice) {
|
|
3231
3287
|
let parsed;
|
|
@@ -3281,6 +3337,7 @@ function parseTrustedDevicesFile(raw, trustedDevicesPath, notice) {
|
|
|
3281
3337
|
break;
|
|
3282
3338
|
}
|
|
3283
3339
|
const nativePush = parseNativePushRegistration(entry.nativePush, entry.platform);
|
|
3340
|
+
const liveActivity = entry.platform === "ios" ? parseLiveActivityRegistration(entry.liveActivity) : void 0;
|
|
3284
3341
|
loaded.push({
|
|
3285
3342
|
id: entry.id,
|
|
3286
3343
|
identityPublicKey: entry.identityPublicKey,
|
|
@@ -3289,6 +3346,8 @@ function parseTrustedDevicesFile(raw, trustedDevicesPath, notice) {
|
|
|
3289
3346
|
platform: entry.platform,
|
|
3290
3347
|
createdAt: entry.createdAt,
|
|
3291
3348
|
lastSeenAt: entry.lastSeenAt,
|
|
3349
|
+
...liveActivity === void 0 ? {} : { liveActivity },
|
|
3350
|
+
...entry.liveActivityEnrollment === void 0 ? {} : { liveActivityEnrollment: { ...entry.liveActivityEnrollment } },
|
|
3292
3351
|
...nativePush === void 0 ? {} : { nativePush },
|
|
3293
3352
|
...entry.nativePushEnrollment === void 0 ? {} : { nativePushEnrollment: { ...entry.nativePushEnrollment } },
|
|
3294
3353
|
...entry.person === void 0 ? {} : {
|
|
@@ -4404,6 +4463,78 @@ function createRemoteAccess(options) {
|
|
|
4404
4463
|
const { nativePush: _previous, ...next } = record;
|
|
4405
4464
|
return options.store.saveTrustedDevice(next);
|
|
4406
4465
|
},
|
|
4466
|
+
setLiveActivityRegistration(sessionDeviceId, body) {
|
|
4467
|
+
devices.sweep();
|
|
4468
|
+
const trust = devices.trustOf(sessionDeviceId);
|
|
4469
|
+
if (status !== "on" || trust?.kind !== "device-key") return {
|
|
4470
|
+
ok: false,
|
|
4471
|
+
reason: "forbidden"
|
|
4472
|
+
};
|
|
4473
|
+
const record = options.store.trustedDevices().find((held) => held.id === trust.trustedDeviceId);
|
|
4474
|
+
if (!record || record.platform !== "ios") return {
|
|
4475
|
+
ok: false,
|
|
4476
|
+
reason: "forbidden"
|
|
4477
|
+
};
|
|
4478
|
+
const registration = parseLiveActivityRegistration(body);
|
|
4479
|
+
if (!registration || registration.startedAt > now() || registration.expiresAt <= now() || record.liveActivity?.activityId === registration.activityId && record.liveActivity.startedAt !== registration.startedAt) return {
|
|
4480
|
+
ok: false,
|
|
4481
|
+
reason: "invalid"
|
|
4482
|
+
};
|
|
4483
|
+
if (!options.liveActivityReaches?.(record.id, registration.sessionId)) return {
|
|
4484
|
+
ok: false,
|
|
4485
|
+
reason: "forbidden"
|
|
4486
|
+
};
|
|
4487
|
+
const hub = options.store.hubTrust?.read();
|
|
4488
|
+
const binding = hub?.owner && {
|
|
4489
|
+
...hub.owner,
|
|
4490
|
+
generation: hub.enrollmentGeneration ?? 1
|
|
4491
|
+
};
|
|
4492
|
+
if (hub && nativePushEnrollmentRemoved({
|
|
4493
|
+
...record,
|
|
4494
|
+
nativePushEnrollment: binding
|
|
4495
|
+
}, hub)) return {
|
|
4496
|
+
ok: false,
|
|
4497
|
+
reason: "forbidden"
|
|
4498
|
+
};
|
|
4499
|
+
if (!options.store.saveTrustedDevice({
|
|
4500
|
+
...record,
|
|
4501
|
+
liveActivity: registration,
|
|
4502
|
+
liveActivityEnrollment: binding
|
|
4503
|
+
})) return {
|
|
4504
|
+
ok: false,
|
|
4505
|
+
reason: "persistence"
|
|
4506
|
+
};
|
|
4507
|
+
return {
|
|
4508
|
+
ok: true,
|
|
4509
|
+
notificationId: record.id,
|
|
4510
|
+
registration
|
|
4511
|
+
};
|
|
4512
|
+
},
|
|
4513
|
+
listLiveActivityRegistrations(listOptions) {
|
|
4514
|
+
return options.store.trustedDevices().flatMap((record) => {
|
|
4515
|
+
const registration = parseLiveActivityRegistration(record.liveActivity);
|
|
4516
|
+
const hub = options.store.hubTrust?.read();
|
|
4517
|
+
if (record.platform !== "ios" || !registration) return [];
|
|
4518
|
+
if (!listOptions?.includeExpired && registration.expiresAt <= now() || registration.startedAt > now() || hub && nativePushEnrollmentRemoved({
|
|
4519
|
+
...record,
|
|
4520
|
+
nativePushEnrollment: record.liveActivityEnrollment
|
|
4521
|
+
}, hub)) {
|
|
4522
|
+
const { liveActivity: _activity, liveActivityEnrollment: _binding, ...base } = record;
|
|
4523
|
+
options.store.saveTrustedDevice(base);
|
|
4524
|
+
return [];
|
|
4525
|
+
}
|
|
4526
|
+
return [{
|
|
4527
|
+
notificationId: record.id,
|
|
4528
|
+
registration
|
|
4529
|
+
}];
|
|
4530
|
+
});
|
|
4531
|
+
},
|
|
4532
|
+
clearLiveActivityRegistration(notificationId, activityId, expectedToken) {
|
|
4533
|
+
const record = options.store.trustedDevices().find((held) => held.id === notificationId);
|
|
4534
|
+
if (!record?.liveActivity || record.liveActivity.activityId !== activityId || record.liveActivity.token !== expectedToken) return false;
|
|
4535
|
+
const { liveActivity: _activity, liveActivityEnrollment: _binding, ...base } = record;
|
|
4536
|
+
return options.store.saveTrustedDevice(base);
|
|
4537
|
+
},
|
|
4407
4538
|
beginDeviceAuth(input) {
|
|
4408
4539
|
if (!isOpaqueId(input.trustedDeviceId) || !isDeviceNonce(input.nonce)) return {
|
|
4409
4540
|
ok: false,
|
|
@@ -4526,6 +4657,14 @@ function createRemoteAccess(options) {
|
|
|
4526
4657
|
},
|
|
4527
4658
|
channelFor: (deviceId, scope) => channels.get(channelKey(deviceId, scope)),
|
|
4528
4659
|
revokeDevice(id) {
|
|
4660
|
+
const trust = devices.trustOf(id);
|
|
4661
|
+
if (trust?.kind === "device-key") {
|
|
4662
|
+
const held = options.store.trustedDevices().find((row) => row.id === trust.trustedDeviceId);
|
|
4663
|
+
if (held?.liveActivity) {
|
|
4664
|
+
const { liveActivity: _activity, liveActivityEnrollment: _binding, ...base } = held;
|
|
4665
|
+
if (!options.store.saveTrustedDevice(base)) return false;
|
|
4666
|
+
}
|
|
4667
|
+
}
|
|
4529
4668
|
const revoked = devices.revoke(id);
|
|
4530
4669
|
if (revoked) publish();
|
|
4531
4670
|
return revoked;
|
|
@@ -4660,8 +4799,18 @@ function createRemoteAccessStore(options = {}) {
|
|
|
4660
4799
|
if (!writeJson(hubTrustPath, state)) return false;
|
|
4661
4800
|
hubTrust = structuredClone(state);
|
|
4662
4801
|
const next = trusted.map((record) => {
|
|
4663
|
-
|
|
4664
|
-
|
|
4802
|
+
let held = record;
|
|
4803
|
+
if (record.nativePush && nativePushEnrollmentRemoved(record, state)) {
|
|
4804
|
+
const { nativePush: _push, nativePushEnrollment: _binding, ...base } = held;
|
|
4805
|
+
held = base;
|
|
4806
|
+
}
|
|
4807
|
+
if (record.liveActivity && nativePushEnrollmentRemoved({
|
|
4808
|
+
...record,
|
|
4809
|
+
nativePushEnrollment: record.liveActivityEnrollment
|
|
4810
|
+
}, state)) {
|
|
4811
|
+
const { liveActivity: _activity, liveActivityEnrollment: _binding, ...base } = held;
|
|
4812
|
+
held = base;
|
|
4813
|
+
}
|
|
4665
4814
|
return held;
|
|
4666
4815
|
});
|
|
4667
4816
|
if (next.every((record, index) => record === trusted[index])) return true;
|
|
@@ -5082,6 +5231,30 @@ function registerRemoteRoutes(app, options) {
|
|
|
5082
5231
|
if (outcome.reason === "unavailable") return context.json({ error: "Remote access is unavailable." }, CONFLICT);
|
|
5083
5232
|
return context.json({ error: "The device keys or proofs were not valid." }, BAD_REQUEST);
|
|
5084
5233
|
});
|
|
5234
|
+
app.post(_agimon_ai_po_core_remoteContract.LIVE_ACTIVITY_ROUTE, limitedJsonBody(NATIVE_PUSH_BODY_BYTES), async (context) => {
|
|
5235
|
+
const deviceId = sealedDeviceOf(context);
|
|
5236
|
+
if (!deviceId) return context.json({ error: "A sealed trusted device is required." }, FORBIDDEN);
|
|
5237
|
+
const outcome = remote.setLiveActivityRegistration(deviceId, await readJson(context));
|
|
5238
|
+
if (outcome.ok) {
|
|
5239
|
+
try {
|
|
5240
|
+
options.onLiveActivityEnrolled?.(structuredClone(outcome));
|
|
5241
|
+
} catch {
|
|
5242
|
+
return context.json({ error: "Activity saved, immediate refresh unavailable." }, SERVICE_UNAVAILABLE);
|
|
5243
|
+
}
|
|
5244
|
+
return context.json({ enrolled: true });
|
|
5245
|
+
}
|
|
5246
|
+
return context.json({ error: "Activity enrollment refused." }, outcome.reason === "persistence" ? SERVICE_UNAVAILABLE : outcome.reason === "forbidden" ? FORBIDDEN : BAD_REQUEST);
|
|
5247
|
+
});
|
|
5248
|
+
app.delete(_agimon_ai_po_core_remoteContract.LIVE_ACTIVITY_ROUTE, limitedJsonBody(NATIVE_PUSH_BODY_BYTES), async (context) => {
|
|
5249
|
+
const deviceId = sealedDeviceOf(context);
|
|
5250
|
+
if (!deviceId || !remote.isDeviceAuthorized(deviceId)) return context.json({ error: "A sealed trusted device is required." }, FORBIDDEN);
|
|
5251
|
+
const id = remote.trustedDeviceOf(deviceId);
|
|
5252
|
+
if (!id) return context.json({ error: "A trusted native session is required." }, FORBIDDEN);
|
|
5253
|
+
const body = await readJson(context);
|
|
5254
|
+
if (!body || Object.keys(body).length !== 2 || typeof body.activityId !== "string" || typeof body.token !== "string" || body.activityId.length > 128 || body.token.length > 4096) return context.json({ error: "Activity identity and expected token required." }, BAD_REQUEST);
|
|
5255
|
+
const removed = remote.clearLiveActivityRegistration(id, body.activityId, body.token);
|
|
5256
|
+
return context.json({ removed });
|
|
5257
|
+
});
|
|
5085
5258
|
app.post(_agimon_ai_po_core_remoteContract.NATIVE_PUSH_ROUTE, limitedJsonBody(NATIVE_PUSH_BODY_BYTES), async (context) => {
|
|
5086
5259
|
const sessionDeviceId = sealedDeviceOf(context);
|
|
5087
5260
|
if (sessionDeviceId === void 0) return context.json({ error: "Native push requires a sealed trusted device session." }, FORBIDDEN);
|
|
@@ -6377,6 +6550,7 @@ function createRemoteRuntime(options) {
|
|
|
6377
6550
|
};
|
|
6378
6551
|
const createAccess = (transport) => createRemoteAccess({
|
|
6379
6552
|
store,
|
|
6553
|
+
liveActivityReaches: options.liveActivityReaches,
|
|
6380
6554
|
broadcastLocal: () => options.onStateChanged?.(),
|
|
6381
6555
|
broadcastAll: () => {
|
|
6382
6556
|
options.onStateChanged?.();
|
|
@@ -6678,6 +6852,7 @@ function createRemoteRuntime(options) {
|
|
|
6678
6852
|
unlinkAccount: federation?.unlinkAccount,
|
|
6679
6853
|
bindAccountDevice: federation?.bindAccountDevice,
|
|
6680
6854
|
remote,
|
|
6855
|
+
onLiveActivityEnrolled: options.onLiveActivityEnrolled,
|
|
6681
6856
|
disableAll: () => remote.disableAll(),
|
|
6682
6857
|
current: () => remote.current(),
|
|
6683
6858
|
listenerOf: (context) => context.env.listener
|