snapback4-expo 0.4.28 → 0.4.29

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 CHANGED
@@ -106,3 +106,13 @@ recorded simulator, with project and device leases held through cleanup.
106
106
  For durable offline media, use the local client's `uploadAndPlace` or `useUpload`
107
107
  (re-exported here). `saveAsset(client, id, name?)` presents the iOS save/share sheet
108
108
  from authorized or retained bytes. See [the shared upload contract](../snapback4/OFFLINE-UPLOADS.md).
109
+
110
+ ### Persist account sessions
111
+
112
+ Install with `npx expo install expo-secure-store`, import `* as SecureStore` from
113
+ `expo-secure-store`, then import `secureStoreSessionStore` from `snapback4-expo`.
114
+ Pass `sessionStore: secureStoreSessionStore(SecureStore)` to `createApp`.
115
+ The adapter encodes complete UTF-16 keys injectively; distinct backend and
116
+ read/full session keys stay distinct. Storage failures propagate. This adds no
117
+ Swift code. Rebuild the app after installing SecureStore; see
118
+ [Expo SecureStore](https://docs.expo.dev/versions/latest/sdk/securestore/).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "snapback4-expo",
3
- "version": "0.4.28",
3
+ "version": "0.4.29",
4
4
  "type": "module",
5
5
  "description": "Snapback 4's native module for Expo: the device in Rust (the partition in its own SQLite, the stream applied, the outbox kept, queries and predictions answered) behind one JSON call, and the opener `snapback4/native` takes.",
6
6
  "main": "src/index.ts",
package/src/index.ts CHANGED
@@ -72,3 +72,5 @@ export function saveAsset(client: Pick<Client, "asset">, id: string, name?: stri
72
72
  }
73
73
  export { uploadAndPlace, type UploadIntent, type UploadAndPlaceOptions } from "snapback4/local";
74
74
  export { useUpload } from "snapback4/react";
75
+
76
+ export { secureStoreSessionStore, type SecureStoreLike } from "./session-store";
@@ -0,0 +1,19 @@
1
+ import type { SessionStore } from "snapback4/auth";
2
+
3
+ /** Pass the expo-secure-store module; no native module is loaded by this adapter. */
4
+ export interface SecureStoreLike {
5
+ getItemAsync(key: string): Promise<string | null>;
6
+ setItemAsync(key: string, value: string): Promise<void>;
7
+ deleteItemAsync(key: string): Promise<void>;
8
+ }
9
+
10
+ // Fixed-width UTF-16 units preserve every JS key, including lone surrogates.
11
+ // @ref LLP 3000.013#6.9 — backend and read/full session keys must never collide.
12
+ export function secureStoreSessionStore(secureStore: SecureStoreLike): SessionStore {
13
+ const key = (value: string) => "snapback4.session." + Array.from({ length: value.length }, (_, i) => value.charCodeAt(i).toString(16).padStart(4, "0")).join("");
14
+ return {
15
+ get: value => secureStore.getItemAsync(key(value)),
16
+ set: (value, session) => secureStore.setItemAsync(key(value), session),
17
+ delete: value => secureStore.deleteItemAsync(key(value)),
18
+ };
19
+ }