Skip to content

Commit e7b06bc

Browse files
committed
fix(spec): push device contract review should-fixes
- RegisterDeviceRequestSchema.vendor and INotificationService.registerDevice now say the same thing: web has no default vendor, a web registration names apns or fcm, and one without vendor is refused. - unregisterDevice states its mechanism: a device the user does not hold throws an error whose code is NOT_FOUND, which the route answers as 404. - A comment says why the push secretReference is stricter than the house credentialRef: the two push secrets are recognisable by shape (PEM block, JSON document), a bearer token or API key is not. - One platform list for the registration and the stored device, in an internal module no barrel re-exports, so no new public name. - UserDeviceSchema describes say when lastSeenAt and invalidatedAt are absent. - The changeset names LocaleSchema for the registration's locale. Claude-Session: https://claude.ai/code/session_01ADHkmT6K7dHh79Lej3sWr5 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 833e9bd commit e7b06bc

10 files changed

Lines changed: 65 additions & 17 deletions

File tree

‎.changeset/29067-push-device-registry-spec.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Metadata-protocol: added
99

1010
Nothing here is served or read yet. Every new or touched schema carries a `[PLANNED — not yet served]` or `[PLANNED — not yet read]` marker in its description, and no route row is added: the device routes land in `DEFAULT_NOTIFICATION_ROUTES` together with their handlers, so the catalog never advertises a route that answers 404. Nothing a client or an operator writes today is refused.
1111

12-
- **`RegisterDeviceRequestSchema`** gains three optional members: `vendor` (`apns` | `fcm`; absent, the server derives it from `platform`, `ios` → `apns` and `android` → `fcm`, and a `web` registration names its vendor), `appId` and `locale`. `token`, `platform`, `deviceId` and `name` are unchanged, so every body a client sent before still parses as it did. The describes now say that re-registering a `deviceId` refreshes that device, and that a request without one gets a server-minted id the client keeps. A `vendor` outside `apns` / `fcm` is refused; since the member is new, no body sent before carries one. `RegisterDeviceResponseSchema` and `UnregisterDevice*` keep their members and gain only their description.
12+
- **`RegisterDeviceRequestSchema`** gains three optional members: `vendor` (`apns` | `fcm`; absent, the server derives it from `platform`, `ios` → `apns` and `android` → `fcm`, and a `web` registration names `apns` or `fcm`), `appId` and `locale` (a BCP 47 tag, the house `LocaleSchema`). `token`, `platform`, `deviceId` and `name` are unchanged, so every body a client sent before still parses as it did. The describes now say that re-registering a `deviceId` refreshes that device, and that a request without one gets a server-minted id the client keeps. A `vendor` outside `apns` / `fcm` is refused; since the member is new, no body sent before carries one. `RegisterDeviceResponseSchema` and `UnregisterDevice*` keep their members and gain only their description.
1313
- **`UserDeviceSchema`** (new, `system/push-device.zod.ts`) is the stored device: `deviceId`, `userId`, `vendor`, `token`, `platform`, `enabled`, and optional `appId`, `locale`, `name`, `invalidatedAt` and `lastSeenAt`. A device belongs to its user alone (no organization member), a token has one live owner (a second user's registration takes it over), and a token the vendor reports dead keeps its row with `enabled: false` and `invalidatedAt`.
1414
- **`INotificationService`** gains four optional members: `registerDevice(userId, request)`, `unregisterDevice(userId, deviceId)`, `listDevices(userId)` and `invalidateDeviceToken(token)`. Their docs state the semantics an implementation owes. Absence means the capability is unavailable, so every existing implementation stays valid.
1515
- **`PushDeliveryDataSchema`** (new, `api/push-delivery.zod.ts`) is the data a push carries to the shell: `notificationId` and an optional `route`. `PushRouteSchema` admits only a same-server relative path (one leading `/`; no scheme, host, backslash, whitespace or control character). The route is derived, never authored: it is the notification's existing `actionUrl` when that passes the schema, and absent otherwise. No `notify` key is added.

‎content/docs/references/api/protocol.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ The authoring surface of a metadata write. Closed: `copilot` is an AI assistant'
27712771
| **platform** | `Enum<'ios' \| 'android' \| 'web'>` | ✅ | Device platform |
27722772
| **deviceId** | `string` | optional | Client-held device id, stable per app install. Re-registering the same deviceId refreshes that device; absent, the server mints one and answers it, and the client keeps it for later registrations and unregister |
27732773
| **name** | `string` | optional | Device friendly name |
2774-
| **vendor** | `Enum<'apns' \| 'fcm'>` | optional | Push vendor the token belongs to: apns or fcm. Absent, the server derives it from platform: ios means apns, android means fcm; web has no core vendor, so a web registration names fcm or is refused |
2774+
| **vendor** | `Enum<'apns' \| 'fcm'>` | optional | Push vendor the token belongs to: apns or fcm. Absent, the server derives it from platform: ios means apns, android means fcm. web has no default vendor: a web registration names apns or fcm, and one without vendor is refused |
27752775
| **appId** | `string` | optional | App the token was issued to: the iOS bundle ID or the Android application ID |
27762776
| **locale** | `string` | optional | Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in |
27772777

‎content/docs/references/system/push-device.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const result = UserDeviceSchema.parse(data);
7575
| **locale** | `string` | optional | Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in |
7676
| **name** | `string` | optional | Device friendly name, as the registration named it |
7777
| **enabled** | `boolean` | ✅ | False once the vendor reported the token dead; nothing is delivered to a disabled device |
78-
| **invalidatedAt** | `string` | optional | When the vendor reported the token dead; absent while the device is enabled |
79-
| **lastSeenAt** | `string` | optional | When the device last registered or refreshed |
78+
| **invalidatedAt** | `string` | optional | When the vendor reported the token dead. Present exactly while enabled is false: absent on an enabled device, and cleared by the registration that re-enables it |
79+
| **lastSeenAt** | `string` | optional | When the device last registered or refreshed. Every registration and refresh sets it, so it is absent only on a row no registration wrote; listDevices answers such a device last |
8080

8181

8282
---

‎packages/spec/src/api/protocol.zod.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { ObjectPermissionSchema, EffectiveObjectPermissionSchema, FieldPermissio
3030
import { ActionDescriptorSchema } from '../automation/node-executor.zod';
3131
import { ServedTranslationDataSchema, LocaleSchema } from '../system/translation.zod';
3232
import { PushVendorSchema } from '../system/push-config.zod';
33+
import { PUSH_DEVICE_PLATFORMS } from '../system/push-device-platform';
3334
// #5950 / #5882 — the ADR-0010 read-side protection envelope both metadata-item
3435
// responses publish. Same three vocabularies the resolver filters against, so a
3536
// value this spec cannot name is a value the resolver would have dropped.
@@ -3534,15 +3535,15 @@ export const GetPresenceResponseSchema = lazySchema(() => z.object({
35343535
// to DEFAULT_NOTIFICATION_ROUTES and flips that table's catalog pin.
35353536
export const RegisterDeviceRequestSchema = lazySchema(() => z.object({
35363537
token: z.string().describe('Device push notification token'),
3537-
platform: z.enum(['ios', 'android', 'web']).describe('Device platform'),
3538+
platform: z.enum(PUSH_DEVICE_PLATFORMS).describe('Device platform'),
35383539
deviceId: z.string().optional().describe(
35393540
'Client-held device id, stable per app install. Re-registering the same deviceId refreshes that device; '
35403541
+ 'absent, the server mints one and answers it, and the client keeps it for later registrations and unregister',
35413542
),
35423543
name: z.string().optional().describe('Device friendly name'),
35433544
vendor: PushVendorSchema.optional().describe(
35443545
'Push vendor the token belongs to: apns or fcm. Absent, the server derives it from platform: ios means apns, '
3545-
+ 'android means fcm; web has no core vendor, so a web registration names fcm or is refused',
3546+
+ 'android means fcm. web has no default vendor: a web registration names apns or fcm, and one without vendor is refused',
35463547
),
35473548
appId: z.string().optional().describe('App the token was issued to: the iOS bundle ID or the Android application ID'),
35483549
locale: LocaleSchema.optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),

‎packages/spec/src/api/register-device-request.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ describe('RegisterDeviceRequestSchema (push device registry)', () => {
5252
expect('vendor' in parsed).toBe(false);
5353
});
5454

55+
// web has no default vendor, and the schema does not tie a vendor to a
56+
// platform: a web registration names either one. Refusing a web body WITHOUT
57+
// vendor is the route's (the server device-registry slice), not this schema's.
58+
it.each(['apns', 'fcm'] as const)('admits a web registration naming vendor %s', (vendor) => {
59+
const body = { token: 't', platform: 'web', vendor } as const;
60+
expect(RegisterDeviceRequestSchema.parse(body)).toEqual(body);
61+
});
62+
5563
it.each(['hms', 'xiaomi', 'web_push', 'APNS', ''])('refuses vendor %j (core delivers through apns / fcm only)', (vendor) => {
5664
const parsed = RegisterDeviceRequestSchema.safeParse({ token: 't', platform: 'android', vendor });
5765
expect(parsed.success).toBe(false);

‎packages/spec/src/contracts/notification-service.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ export interface INotificationService {
245245
* user, and the other user's device stops receiving it. A push meant
246246
* for the previous owner never reaches the phone's new user.
247247
* - An absent `request.vendor` is derived from `request.platform`
248-
* (`ios` → `apns`, `android` → `fcm`). A `web` registration names its
249-
* vendor; without one there is nothing to derive, and it is refused as
250-
* a validation error, never stored with a guessed vendor.
248+
* (`ios` → `apns`, `android` → `fcm`). `web` has no default vendor: a
249+
* `web` registration names `apns` or `fcm`, and one without `vendor` is
250+
* refused as a validation error, never stored with a guessed vendor.
251251
*
252252
* @param userId - The signed-in user, from the session; never a body member
253253
* @param request - The registration body
@@ -257,18 +257,21 @@ export interface INotificationService {
257257
/**
258258
* Unregister one of this user's devices (sign-out, account switch).
259259
*
260-
* A `deviceId` this user does not hold — unknown, or another user's —
261-
* answers not found (`NOT_FOUND`, 404 at the device route), never a
262-
* success and never a distinct "forbidden": a caller cannot learn that a
263-
* device id exists for somebody else, and cannot remove it.
260+
* Resolves `{ success: true }` once the device is removed. A `deviceId`
261+
* this user does not hold — unknown, or another user's — never resolves:
262+
* the call throws an error whose `code` is `NOT_FOUND`, which the device
263+
* route answers as 404. It is never a distinct "forbidden", so a caller
264+
* cannot learn that a device id exists for somebody else, and cannot
265+
* remove it.
264266
*
265267
* @param userId - The signed-in user, from the session
266268
* @param deviceId - The id {@link registerDevice} answered
267269
*/
268270
unregisterDevice?(userId: string, deviceId: string): Promise<UnregisterDeviceResponse>;
269271

270272
/**
271-
* List this user's devices, newest `lastSeenAt` first.
273+
* List this user's devices, newest `lastSeenAt` first; a device with no
274+
* `lastSeenAt` comes last.
272275
*
273276
* Disabled devices (a token the vendor reported dead) are listed too,
274277
* with `enabled: false` and their `invalidatedAt`, so a settings screen

‎packages/spec/src/system/push-config.zod.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ export type PushVendor = z.input<typeof PushVendorSchema>;
6060
* be written without them (a PEM block, a JSON document) and a reference
6161
* never needs them.
6262
*/
63+
// Stricter than the house `credentialRef` (`z.string().min(1)`,
64+
// shared/connector-auth.zod.ts) on purpose. A bearer token or an API key looks
65+
// like a name, so a connector's reference cannot tell a pasted secret from a
66+
// reference and checks only that one is there. The two push secrets can be
67+
// told apart: a .p8 key is a PEM block and a service-account file is a JSON
68+
// document, and every name the house writes (an environment-variable name in
69+
// the open tier) has neither whitespace nor braces. If a secrets layer ever
70+
// names a secret with either, this widens to the house shape.
6371
function secretReference(secret: string) {
6472
return z.string()
6573
.min(1)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The device platforms a push device registration names: `ios`, `android`
5+
* and `web`.
6+
*
7+
* One list for the two schemas that carry it, the registration body
8+
* (`RegisterDeviceRequestSchema.platform`, `api/protocol.zod.ts`) and the
9+
* stored device (`UserDeviceSchema.platform`, `system/push-device.zod.ts`), so
10+
* a stored device never names a platform its registration would refuse.
11+
*
12+
* Internal to the package: no barrel re-exports this module, so it adds no
13+
* public name. Each schema builds its own `z.enum` from it and describes it.
14+
*/
15+
export const PUSH_DEVICE_PLATFORMS = ['ios', 'android', 'web'] as const;

‎packages/spec/src/system/push-device.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import { describe, it, expect } from 'vitest';
99
import { UserDeviceSchema } from './push-device.zod';
10+
import { RegisterDeviceRequestSchema } from '../api/protocol.zod';
1011

1112
const DEVICE = {
1213
deviceId: 'install-1',
@@ -62,6 +63,11 @@ describe('UserDeviceSchema', () => {
6263
expect(parsed.error?.issues[0]?.path).toEqual(['invalidatedAt']);
6364
});
6465

66+
it('names the same platforms its registration does', () => {
67+
expect(UserDeviceSchema.shape.platform.options).toEqual(RegisterDeviceRequestSchema.shape.platform.options);
68+
expect(UserDeviceSchema.shape.platform.options).toEqual(['ios', 'android', 'web']);
69+
});
70+
6571
it('has no organization member: a device belongs to its user alone', () => {
6672
expect(Object.keys(UserDeviceSchema.shape)).not.toContain('organizationId');
6773
});

‎packages/spec/src/system/push-device.zod.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from 'zod';
44
import { lazySchema } from '../shared/lazy-schema';
55
import { PushVendorSchema } from './push-config.zod';
66
import { LocaleSchema } from './translation.zod';
7+
import { PUSH_DEVICE_PLATFORMS } from './push-device-platform';
78

89
/**
910
* Push Device Protocol — the stored device shape of the push device registry
@@ -51,13 +52,19 @@ export const UserDeviceSchema = lazySchema(() => z.object({
5152
userId: z.string().min(1).describe('The user the device belongs to: the session user who registered it. No organization member'),
5253
vendor: PushVendorSchema.describe('Push vendor the token belongs to: the registration\'s vendor, or the one derived from platform'),
5354
token: z.string().min(1).describe('Vendor push token. Held by one live device at a time: a second user\'s registration moves it'),
54-
platform: z.enum(['ios', 'android', 'web']).describe('Device platform, as the registration named it'),
55+
platform: z.enum(PUSH_DEVICE_PLATFORMS).describe('Device platform, as the registration named it'),
5556
appId: z.string().optional().describe('App the token was issued to: the iOS bundle ID or the Android application ID'),
5657
locale: LocaleSchema.optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),
5758
name: z.string().optional().describe('Device friendly name, as the registration named it'),
5859
enabled: z.boolean().describe('False once the vendor reported the token dead; nothing is delivered to a disabled device'),
59-
invalidatedAt: z.string().datetime().optional().describe('When the vendor reported the token dead; absent while the device is enabled'),
60-
lastSeenAt: z.string().datetime().optional().describe('When the device last registered or refreshed'),
60+
invalidatedAt: z.string().datetime().optional().describe(
61+
'When the vendor reported the token dead. Present exactly while enabled is false: absent on an enabled device, '
62+
+ 'and cleared by the registration that re-enables it',
63+
),
64+
lastSeenAt: z.string().datetime().optional().describe(
65+
'When the device last registered or refreshed. Every registration and refresh sets it, so it is absent only on a '
66+
+ 'row no registration wrote; listDevices answers such a device last',
67+
),
6168
}).describe(
6269
'[PLANNED — not yet served] A push device of one user: one row per app install. No table stores it yet; '
6370
+ 'the device registry lands with the push channel',

0 commit comments

Comments
 (0)