Skip to content

Commit a257694

Browse files
committed
chore: changeset for the native push registration
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6bhgWPe8iKWPE5j7CLjdF
1 parent 19a48b3 commit a257694

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/console': patch
3+
'@object-ui/mobile': patch
4+
'@object-ui/auth': patch
5+
---
6+
7+
feat(console,mobile,auth): the Console registers the mobile shell's push token under its own session and unregisters it on sign-out and when the shell removes the connection
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: none
11+
12+
- **`@object-ui/console`:** in the ObjectStack mobile shell, a signed-in person who has reached Home or an app is asked for push permission once per page load, after a short delay (never on a sign-in screen): the Console calls `getPushToken()` and registers the token with `POST /api/v1/notifications/devices`. A `null` answer (simulator, permission denied, no token) sends nothing. A token the shell rotates is registered again; an unchanged token for the same person is not sent twice. Another person signing in on the page registers the device for them, and the registry moves the token away from the previous person. An impersonation never registers, so the impersonated person's pushes never reach the administrator's device. The registration sends `deviceId` as the shell's `installId` when it has one, and `origin` only when the page was loaded over `http:` or `https:`. The device is unregistered (`DELETE /api/v1/notifications/devices/:deviceId`) before sign-out ends the session, and when the shell removes this connection; a shell that is neither iOS nor Android registers nothing. A browser is unchanged.
13+
- **`@object-ui/mobile`:** `ObjectStackNative` gains the optional `installId` (`string | null`), and the package exports `NATIVE_PUSH_TOKEN_CHANGED_EVENT` (`objectstack-native:pushTokenChanged`, announced as `has('pushTokenChanged')`) with its event type `NativePushTokenChangedEvent`. Both are feature-detected: a shell that predates them carries neither.
14+
- **`@object-ui/auth`:** `registerBeforeSignOut(step)` registers a step that `signOut()` awaits while the session still exists, and returns the function that removes it. The steps run together and can never hold sign-out back: a rejection is reported and dropped, and sign-out goes ahead after `BEFORE_SIGN_OUT_TIMEOUT_MS` (3 s) whether or not they have settled.

‎ui/apps/console/src/__tests__/nativePushRegistration-29042.test.tsx‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,14 @@ function answer(status: number, body: unknown) {
8686

8787
function deviceRequests(): Array<{ method: string; url: string; body: unknown }> {
8888
return fetchMock.mock.calls
89-
.map(([url, init]: [string, RequestInit | undefined]) => ({
90-
method: init?.method ?? 'GET',
91-
url: String(url),
92-
body: typeof init?.body === 'string' ? JSON.parse(init.body) : undefined,
93-
}))
89+
.map((call: unknown[]) => {
90+
const init = call[1] as RequestInit | undefined;
91+
return {
92+
method: init?.method ?? 'GET',
93+
url: String(call[0]),
94+
body: typeof init?.body === 'string' ? (JSON.parse(init.body) as unknown) : undefined,
95+
};
96+
})
9497
.filter((request) => request.url.includes(DEVICES));
9598
}
9699

@@ -311,7 +314,7 @@ describe('unregistering the device this Console registered (objectstack#29042)',
311314
await act(async () => {
312315
await unregister!();
313316
});
314-
expect(deviceRequests().at(-1)).toEqual({ method: 'DELETE', url: expect.stringContaining(`${DEVICES}/install-7`), body: undefined });
317+
expect(deviceRequests()[deviceRequests().length - 1]).toEqual({ method: 'DELETE', url: expect.stringContaining(`${DEVICES}/install-7`), body: undefined });
315318
expect(sessionStorage.getItem(NATIVE_PUSH_REGISTRATION_KEY)).toBeNull();
316319
});
317320

‎ui/apps/console/src/nativePushRegistration.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ function installIdOf(host: ObjectStackNative): string | null {
126126

127127
/** The registry's platform for this shell, or `null` for a shell that is neither iOS nor Android. */
128128
function platformOf(host: ObjectStackNative): 'ios' | 'android' | null {
129-
return host.platform === 'ios' || host.platform === 'android' ? host.platform : null;
129+
const { platform } = host;
130+
if (platform === 'ios') return 'ios';
131+
if (platform === 'android') return 'android';
132+
return null;
130133
}
131134

132135
/**

0 commit comments

Comments
 (0)