Skip to content

Commit 833e9bd

Browse files
committed
fix(spec): push device locale members take the house LocaleSchema
RegisterDeviceRequestSchema.locale and UserDeviceSchema.locale were a bare string their describes called BCP 47; a device saved as a non-tag spelling would be rendered in a locale no bundle answers. Both now take LocaleSchema (system/translation.zod.ts), with refusal tests for non-tag spellings. Claude-Session: https://claude.ai/code/session_01ADHkmT6K7dHh79Lej3sWr5 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 73fabdf commit 833e9bd

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
import { RealtimePresenceSchema, TransportProtocol } from './realtime.zod';
2929
import { ObjectPermissionSchema, EffectiveObjectPermissionSchema, FieldPermissionSchema } from '../security/permission.zod';
3030
import { ActionDescriptorSchema } from '../automation/node-executor.zod';
31-
import { ServedTranslationDataSchema } from '../system/translation.zod';
31+
import { ServedTranslationDataSchema, LocaleSchema } from '../system/translation.zod';
3232
import { PushVendorSchema } from '../system/push-config.zod';
3333
// #5950 / #5882 — the ADR-0010 read-side protection envelope both metadata-item
3434
// responses publish. Same three vocabularies the resolver filters against, so a
@@ -3545,7 +3545,7 @@ export const RegisterDeviceRequestSchema = lazySchema(() => z.object({
35453545
+ 'android means fcm; web has no core vendor, so a web registration names fcm or is refused',
35463546
),
35473547
appId: z.string().optional().describe('App the token was issued to: the iOS bundle ID or the Android application ID'),
3548-
locale: z.string().optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),
3548+
locale: LocaleSchema.optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),
35493549
}).describe(
35503550
'[PLANNED — not yet served] Register or refresh a push device for the signed-in user. No route serves it yet; '
35513551
+ 'the device routes land together with their handlers',

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ describe('RegisterDeviceRequestSchema (push device registry)', () => {
5959
expect(parsed.error?.issues[0]?.code).toBe('invalid_value');
6060
});
6161

62+
// The locale a push is rendered in must be a tag a translation bundle can
63+
// answer: the house LocaleSchema, the shape every other locale key takes.
64+
it.each(['zh_CN', 'Chinese', 'zh-CN ', ''])('refuses locale %j (not a BCP-47 language tag)', (locale) => {
65+
const parsed = RegisterDeviceRequestSchema.safeParse({ token: 't', platform: 'ios', locale });
66+
expect(parsed.success).toBe(false);
67+
expect(parsed.error?.issues[0]?.path).toEqual(['locale']);
68+
expect(parsed.error?.issues[0]?.code).toBe('invalid_format');
69+
});
70+
71+
it.each(['en', 'zh-CN', 'zh-Hans-CN', 'es-419'])('accepts locale %j', (locale) => {
72+
expect(RegisterDeviceRequestSchema.safeParse({ token: 't', platform: 'ios', locale }).success).toBe(true);
73+
});
74+
6275
it('keeps the response and unregister shapes as they were', () => {
6376
expect(RegisterDeviceResponseSchema.parse({ deviceId: 'install-1', success: true }))
6477
.toEqual({ deviceId: 'install-1', success: true });

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ describe('UserDeviceSchema', () => {
4949
expect(parsed.error?.issues[0]?.path).toEqual(['vendor']);
5050
});
5151

52+
it.each(['zh_CN', 'Chinese', 'zh-CN '])('refuses locale %j (not a BCP-47 language tag)', (locale) => {
53+
const parsed = UserDeviceSchema.safeParse({ ...DEVICE, locale });
54+
expect(parsed.success).toBe(false);
55+
expect(parsed.error?.issues[0]?.path).toEqual(['locale']);
56+
expect(parsed.error?.issues[0]?.code).toBe('invalid_format');
57+
});
58+
5259
it('refuses an invalidation time that is not an ISO-8601 instant', () => {
5360
const parsed = UserDeviceSchema.safeParse({ ...DEVICE, enabled: false, invalidatedAt: 'yesterday' });
5461
expect(parsed.success).toBe(false);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { z } from 'zod';
44
import { lazySchema } from '../shared/lazy-schema';
55
import { PushVendorSchema } from './push-config.zod';
6+
import { LocaleSchema } from './translation.zod';
67

78
/**
89
* Push Device Protocol — the stored device shape of the push device registry
@@ -52,7 +53,7 @@ export const UserDeviceSchema = lazySchema(() => z.object({
5253
token: z.string().min(1).describe('Vendor push token. Held by one live device at a time: a second user\'s registration moves it'),
5354
platform: z.enum(['ios', 'android', 'web']).describe('Device platform, as the registration named it'),
5455
appId: z.string().optional().describe('App the token was issued to: the iOS bundle ID or the Android application ID'),
55-
locale: z.string().optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),
56+
locale: LocaleSchema.optional().describe('Device locale (BCP 47, for example zh-CN) that pushes to this device are rendered in'),
5657
name: z.string().optional().describe('Device friendly name, as the registration named it'),
5758
enabled: z.boolean().describe('False once the vendor reported the token dead; nothing is delivered to a disabled device'),
5859
invalidatedAt: z.string().datetime().optional().describe('When the vendor reported the token dead; absent while the device is enabled'),

0 commit comments

Comments
 (0)