@unisim/sdk 0.231.1 → 0.232.0

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.
@@ -0,0 +1,172 @@
1
+ 'use client';
2
+ // The account sync behind Tune this app (0.229.0), as one engine (0.232.0).
3
+ //
4
+ // One `user_app_prefs` row, one device stamp, one rule: the newer side wins.
5
+ // TuneSync.tsx runs it for the settings the SDK holds (`tune:<product>`), and
6
+ // SyncedSettingsSync.tsx runs it once per `createSyncedSettings` store
7
+ // (`tune-app:<app>`). The rules themselves are in tuneSyncCore.ts
8
+ // (`decideTuneSync`); this is the part with React and the network in it:
9
+ //
10
+ // • A change on this device is stamped at once; signed in, it is pushed a
11
+ // moment later (one write for a Reset to defaults that clears it all).
12
+ // • When a session arrives, and again on resume (throttled like the Global
13
+ // Tuning pull), the row is read and the newer side wins: the row is
14
+ // applied here, or this device's set is written to it.
15
+ // • A guest's change (made signed out) is written to the row on sign-in.
16
+ //
17
+ // ⚠️ Fire-and-forget and silent, like the Global Tuning row: offline, an RLS
18
+ // refusal or a self-hosted fork without the table cost the sync and nothing
19
+ // else. A failed write leaves this device's stamp newer than the row, so the
20
+ // next pull writes it again.
21
+ import { useEffect, useRef, useState } from 'react';
22
+ import { decideTuneSync, readTuneStamp, writeTuneStamp } from './tuneSyncCore.js';
23
+ /** At most one re-read of the row per this long, on resume. */
24
+ const RESUME_THROTTLE_MS = 30_000;
25
+ /** Changes closer together than this go up as one write. */
26
+ const PUSH_DELAY_MS = 60;
27
+ /**
28
+ * The table refuses a `data` over 8 KB (0151, `pg_column_size`). A set this
29
+ * large as JSON text is not sent: it stays on the device, stamped, as if
30
+ * offline. Tune settings are a few hundred bytes; this is a guard, not a budget.
31
+ */
32
+ export const ROW_MAX_BYTES = 8000;
33
+ /** A person, not an anonymous trial: signed in = synced. */
34
+ export function syncUserId(session) {
35
+ const user = session?.user;
36
+ return user && !user.is_anonymous ? user.id : null;
37
+ }
38
+ function fits(data) {
39
+ try {
40
+ return new TextEncoder().encode(JSON.stringify(data)).length <= ROW_MAX_BYTES;
41
+ }
42
+ catch {
43
+ return false;
44
+ }
45
+ }
46
+ /**
47
+ * Keep one channel's row and this device in step while signed in as `uid`.
48
+ * Memoise the channel: its `onChange` is re-subscribed when it changes.
49
+ */
50
+ export function useRowSync(channel, supabase, uid) {
51
+ const live = useRef({ channel, supabase, uid });
52
+ live.current = { channel, supabase, uid };
53
+ // The last row seen or sent (TuneSync carries its colour scheme on a page
54
+ // with no theme store, which has none of its own to report).
55
+ const lastRow = useRef(null);
56
+ const timer = useRef(null);
57
+ // The set this page last wrote (`uid:at`), so a pull that lands just after
58
+ // a change's own write does not send it again. A new page retries.
59
+ const sent = useRef(null);
60
+ const push = (at) => {
61
+ const { channel, supabase, uid } = live.current;
62
+ if (!uid)
63
+ return;
64
+ const data = { at, ...channel.snapshot(lastRow.current) };
65
+ if (!fits(data))
66
+ return;
67
+ lastRow.current = data;
68
+ sent.current = `${uid}:${at}`;
69
+ writeTuneStamp(channel.stampName, { at, uid });
70
+ try {
71
+ void supabase
72
+ .from('user_app_prefs')
73
+ .upsert({ user_id: uid, app: channel.rowApp, data }, { onConflict: 'user_id,app' })
74
+ .then(() => { }, () => { });
75
+ }
76
+ catch { /* see the header */ }
77
+ };
78
+ const apply = (row) => {
79
+ const { channel, uid } = live.current;
80
+ // Stamped as agreed only when all of it landed, so the next page tries again.
81
+ if (channel.apply(row) && uid)
82
+ writeTuneStamp(channel.stampName, { at: row.at, uid });
83
+ };
84
+ // ── A change on this device ────────────────────────────────────────────────
85
+ useEffect(() => channel.onChange(() => {
86
+ const { channel, uid } = live.current;
87
+ const at = Date.now();
88
+ writeTuneStamp(channel.stampName, uid ? { at, uid } : { at, guest: true });
89
+ if (!uid)
90
+ return;
91
+ if (timer.current)
92
+ clearTimeout(timer.current);
93
+ timer.current = setTimeout(() => {
94
+ timer.current = null;
95
+ push(readTuneStamp(live.current.channel.stampName)?.at ?? at);
96
+ }, PUSH_DELAY_MS);
97
+ // eslint-disable-next-line react-hooks/exhaustive-deps
98
+ }), [channel]);
99
+ // A write still waiting when the provider goes is sent now, not lost.
100
+ useEffect(() => () => {
101
+ if (!timer.current)
102
+ return;
103
+ clearTimeout(timer.current);
104
+ timer.current = null;
105
+ push(readTuneStamp(live.current.channel.stampName)?.at ?? Date.now());
106
+ // eslint-disable-next-line react-hooks/exhaustive-deps
107
+ }, []);
108
+ // ── Re-read on resume (phone apps stay resident) ───────────────────────────
109
+ const [pull, setPull] = useState(0);
110
+ useEffect(() => {
111
+ if (!uid || typeof window === 'undefined')
112
+ return;
113
+ let last = Date.now();
114
+ const again = () => {
115
+ if (Date.now() - last < RESUME_THROTTLE_MS)
116
+ return;
117
+ last = Date.now();
118
+ setPull((n) => n + 1);
119
+ };
120
+ const onVisibility = () => { if (document.visibilityState === 'visible')
121
+ again(); };
122
+ const onPageShow = (e) => { if (e.persisted)
123
+ again(); };
124
+ document.addEventListener('visibilitychange', onVisibility);
125
+ window.addEventListener('pageshow', onPageShow);
126
+ return () => {
127
+ document.removeEventListener('visibilitychange', onVisibility);
128
+ window.removeEventListener('pageshow', onPageShow);
129
+ };
130
+ }, [uid]);
131
+ // ── Sign-in (and resume): newer side wins ──────────────────────────────────
132
+ const rowApp = channel.rowApp;
133
+ useEffect(() => {
134
+ if (!uid || typeof window === 'undefined')
135
+ return;
136
+ let cancelled = false;
137
+ void (async () => {
138
+ try {
139
+ const { channel } = live.current;
140
+ const { data, error } = await supabase
141
+ .from('user_app_prefs')
142
+ .select('data')
143
+ .eq('app', rowApp)
144
+ .maybeSingle();
145
+ if (cancelled || error)
146
+ return;
147
+ const remote = channel.parse(data?.data);
148
+ if (remote)
149
+ lastRow.current = remote;
150
+ // Read now, not before the await: a change made meanwhile (the guest
151
+ // adoption on sign-in, say) is part of the answer.
152
+ const local = readTuneStamp(channel.stampName);
153
+ const action = decideTuneSync(local, remote, uid);
154
+ if (action === 'apply' && remote)
155
+ apply(remote);
156
+ else if (action === 'push' && local) {
157
+ // A change's own write still waiting on its timer will send it.
158
+ if (timer.current)
159
+ return;
160
+ if (local.guest)
161
+ push(Date.now());
162
+ else if (sent.current !== `${uid}:${local.at}`)
163
+ push(local.at);
164
+ }
165
+ }
166
+ catch { /* no sync this time — see the header */ }
167
+ })();
168
+ return () => { cancelled = true; };
169
+ // eslint-disable-next-line react-hooks/exhaustive-deps
170
+ }, [supabase, rowApp, uid, pull]);
171
+ }
172
+ //# sourceMappingURL=rowSync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rowSync.js","sourceRoot":"","sources":["../src/rowSync.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,4EAA4E;AAC5E,EAAE;AACF,6EAA6E;AAC7E,8EAA8E;AAC9E,uEAAuE;AACvE,kEAAkE;AAClE,yEAAyE;AACzE,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,6EAA6E;AAC7E,wEAAwE;AACxE,2DAA2D;AAC3D,2EAA2E;AAC3E,EAAE;AACF,6EAA6E;AAC7E,4EAA4E;AAC5E,6EAA6E;AAC7E,6BAA6B;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEnD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAEjF,+DAA+D;AAC/D,MAAM,kBAAkB,GAAG,MAAM,CAAA;AACjC,4DAA4D;AAC5D,MAAM,aAAa,GAAG,EAAE,CAAA;AACxB;;;;GAIG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAA;AAqBjC,4DAA4D;AAC5D,MAAM,UAAU,UAAU,CAAC,OAAuB;IAChD,MAAM,IAAI,GAAG,OAAO,EAAE,IAA0D,CAAA;IAChF,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AACp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AM,CAAA;gBACpC,qEAAqE;gBACrE,mDAAmD;gBACnD,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;gBAC9C,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;gBACjD,IAAI,MAAM,KAAK,OAAO,IAAI,MAAM;oBAAE,KAAK,CAAC,MAAM,CAAC,CAAA;qBAC1C,IAAI,MAAM,KAAK,MAAM,IAAI,KAAK,EAAE,CAAC;oBACpC,gEAAgE;oBAChE,IAAI,KAAK,CAAC,OAAO;wBAAE,OAAM;oBACzB,IAAI,KAAK,CAAC,KAAK;wBAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;yBAC5B,IAAI,IAAI,CAAC,OAAO,KAAK,GAAG,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;wBAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;gBAChE,CAAC;YACH,CAAC;YAAC,MAAM,CAAC,CAAC,wCAAwC,CAAC,CAAC;QACtD,CAAC,CAAC,EAAE,CAAA;QACJ,OAAO,GAAG,EAAE,GAAG,SAAS,GAAG,IAAI,CAAA,CAAC,CAAC,CAAA;QACjC,uDAAuD;IACzD,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;AACnC,CAAC"}
@@ -0,0 +1,100 @@
1
+ /** The `user_app_prefs.app` value holding one app's own synced Tune rows. */
2
+ export declare function settingsRowApp(app: string): string;
3
+ /** The name the device stamp is kept under (`unisim:tune-stamp:app:<app>`). */
4
+ export declare function settingsStampName(app: string): string;
5
+ /** A store's row: the values, as the device that last changed them had them. */
6
+ export interface SettingsRow {
7
+ at: number;
8
+ values: Record<string, unknown>;
9
+ }
10
+ /** A row's `data`, or `null` when it is not one (absent, corrupt, unstamped). */
11
+ export declare function parseSettingsRow(raw: unknown): SettingsRow | null;
12
+ export interface SyncedSettingsOptions<T> {
13
+ /**
14
+ * Where the values live on the device. Default `unisim:settings:<app>`.
15
+ * Pass an app's EXISTING key to keep reading it: `normalise` receives
16
+ * whatever is stored there, in whatever shape the old code wrote, and the
17
+ * first change rewrites it as this store's flat object. Only do that when
18
+ * nothing else reads the key (a pre-paint script, another module).
19
+ */
20
+ storageKey?: string;
21
+ /**
22
+ * Existing values from before this store, read once when `storageKey` holds
23
+ * nothing — e.g. one localStorage key per switch. The result goes through
24
+ * `normalise` and is saved under `storageKey` straight away, so nobody loses
25
+ * a setting. It is NOT a change: unstamped, it never outranks the account.
26
+ * Return `undefined` for "nothing to migrate".
27
+ */
28
+ legacy?: () => unknown;
29
+ /**
30
+ * Keys that stay on this device and never go to the account (a phone
31
+ * gesture, a choice that needs this device's own permission). A change to
32
+ * one is saved locally and not stamped.
33
+ */
34
+ deviceOnly?: readonly (keyof T & string)[];
35
+ }
36
+ export interface SyncedSettings<T extends object> {
37
+ /** Subscribe a component to the whole set. */
38
+ (): T;
39
+ /** Subscribe a component to a slice — `useSettings((s) => s.pageSize)`. */
40
+ <U>(selector: (state: T) => U): U;
41
+ /** Read outside React. */
42
+ getState(): T;
43
+ /**
44
+ * Change some values. Saved on the device at once; a real change to a
45
+ * synced key is stamped and, signed in, goes to the account. Values go
46
+ * through `normalise`, so a bad one falls back to what it would read as.
47
+ */
48
+ set(patch: Partial<T> | ((state: T) => Partial<T>)): void;
49
+ /** Zustand's name for `set`. */
50
+ setState(patch: Partial<T> | ((state: T) => Partial<T>)): void;
51
+ /**
52
+ * Every value back to its default, saved, and — when that changed anything —
53
+ * stamped and synced, so the account's other devices follow. The SDK's
54
+ * `useResetAppDefaults` (every Tune this app's Reset to defaults) calls it.
55
+ */
56
+ reset(): void;
57
+ /** Low-level change listener; returns the unsubscribe. */
58
+ subscribe(listener: () => void): () => void;
59
+ readonly app: string;
60
+ readonly storageKey: string;
61
+ /** A fresh copy of the defaults, through `normalise`. */
62
+ readonly defaults: T;
63
+ }
64
+ /** What SyncedSettingsSync needs from one store. */
65
+ export interface SyncedSettingsEntry {
66
+ app: string;
67
+ /** The synced values (no `deviceOnly` keys). */
68
+ snapshot(): Record<string, unknown>;
69
+ /** Put the account's values on this device, quietly. */
70
+ applyRemote(values: Record<string, unknown>): void;
71
+ /** This device's own real changes to synced keys. */
72
+ onChange(listener: () => void): () => void;
73
+ reset(): void;
74
+ }
75
+ /** Every synced store made on this page (one per `app`; a re-made one replaces it). */
76
+ export declare function getSyncedSettingsEntries(): SyncedSettingsEntry[];
77
+ export declare function subscribeSyncedSettingsEntries(listener: () => void): () => void;
78
+ /** Reset every synced store on this page (Reset to defaults, via useResetAppDefaults). */
79
+ export declare function resetAllSyncedSettings(): void;
80
+ /**
81
+ * Create an app's synced Tune settings. Call it ONCE, at module level, and
82
+ * export the result.
83
+ *
84
+ * - `app`: the app's product code (`config.product`), ≤ 31 characters. The
85
+ * row is `tune-app:<app>`; the device stamp `unisim:tune-stamp:app:<app>`.
86
+ * - `defaults`: every setting's default. JSON values only. ⚠️ Use `null`, not
87
+ * `undefined`, for "none": an absent key in the account's row leaves this
88
+ * device's value as it is (so an older build that doesn't know a newer
89
+ * setting can't reset it), and `undefined` doesn't survive JSON.
90
+ * - `normalise(raw, defaults)`: turn anything — the stored object (in an old
91
+ * shape too), the account's values, a patched set — into a complete, valid
92
+ * set. It must not trust `raw` (it can be `undefined`, `null`, junk) and
93
+ * must fill every key; a throw reads as the defaults.
94
+ *
95
+ * ⚠️ Never change a setting's default by accident: a device that never
96
+ * changed anything shows the defaults, and so does a Reset. Tick boxes start
97
+ * unticked (BRANDING.md); word a default-on feature as an opt-out.
98
+ */
99
+ export declare function createSyncedSettings<T extends object>(app: string, defaults: T, normalise: (raw: unknown, defaults: T) => T, options?: SyncedSettingsOptions<T>): SyncedSettings<T>;
100
+ //# sourceMappingURL=syncedSettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncedSettings.d.ts","sourceRoot":"","sources":["../src/sync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;IACH,KAAK,IAAI,IAAI,CAAA;IACb,0DAA0D;IAC1D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC3C,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,yDAAyD;IACzD,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;CACrB;AAID,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,gDAAgD;IAChD,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,wDAAwD;IACxD,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IAClD,qDAAqD;IACrD,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAA;IAC1C,KAAK,IAAI,IAAI,CAAA;CACd;AAKD,uFAAuF;AACvF,wBAAgB,wBAAwB,IAAI,mBAAmB,EAAE,CAEhE;AAED,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAG/E;AAED,0FAA0F;AAC1F,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAqBD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,CAAC,EACX,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,EAC3C,OAAO,GAAE,qBAAqB,CAAC,CAAC,CAAM,GACrC,cAAc,CAAC,CAAC,CAAC,CA8InB"}
@@ -0,0 +1,272 @@
1
+ 'use client';
2
+ // An app's own Tune this app rows, kept on the device and synced to the
3
+ // account (0.232.0) — phase 2 of James's 2026-10-30 rule: "mobile app and web
4
+ // app settings in tune this app should be saved and synced to their account …
5
+ // Global rule". Phase 1 (0.229.0, TuneSync.tsx) synced what the SDK holds;
6
+ // this is the same thing for the switches an app keeps itself. It is
7
+ // BlackBook's settingsStore (`tunedAt`) generalised; BlackBook stays on its
8
+ // own E2EE vault.
9
+ //
10
+ // // src/stores/settings.ts — once, at module level
11
+ // export const useSettings = createSyncedSettings('universal_pdf',
12
+ // { compressOnSave: false, pageSize: 'a4' },
13
+ // (raw, d) => ({ compressOnSave: raw?.compressOnSave === true, pageSize: … ?? d.pageSize }))
14
+ // // in a component
15
+ // const compress = useSettings((s) => s.compressOnSave)
16
+ // useSettings.set({ compressOnSave: true })
17
+ //
18
+ // Zustand-shaped (`useStore(selector)`, `getState`, `setState`, `subscribe`),
19
+ // on React's own `useSyncExternalStore` — the SDK takes no zustand dependency
20
+ // (see themeStore.ts). Read synchronously from localStorage at import time.
21
+ //
22
+ // THE RULES are phase 1's, run by the same engine (rowSync.ts,
23
+ // decideTuneSync): signed in = synced, signed out = this device only; one
24
+ // stamp per store and the newer set wins; first sight is unstamped, so a
25
+ // device that never changed anything (existing values migrated from before
26
+ // included) says nothing — it takes the account's set if there is one and
27
+ // writes nothing; a guest's change is saved on sign-in; another account's
28
+ // stamp on a shared device is no stamp; Reset to defaults is a change.
29
+ //
30
+ // ⚠️ WHERE IT LIVES: a SIBLING row, `app = 'tune-app:<app>'`, with
31
+ // `data = { at, values }` — not a nested key in phase 1's `tune:<product>`
32
+ // row. Every SDK from 0.229.0 to 0.231.x writes that row whole as
33
+ // `{ at, colorScheme, language, views }`, so a phone a release behind would
34
+ // wipe a nested key on its next colour-scheme change; and sharing its one
35
+ // stamp would make a look change on one device and a switch change on
36
+ // another fight, the older losing BOTH. Two rows, two stamps: the SDK's look
37
+ // and the app's switches each go newest-wins on their own and never touch
38
+ // each other. Same reasoning as phase 1's own row and "Call me"'s. No
39
+ // migration: `app` is free text (0151), and the stamp is inside `data`.
40
+ //
41
+ // Privacy: the row holds the settings' values and the stamp. Nothing else.
42
+ // Keys marked `deviceOnly` (a shake gesture, a permission-backed choice that
43
+ // needs this device's own say) stay on the device and never go up.
44
+ import { useSyncExternalStore } from 'react';
45
+ /** The `user_app_prefs.app` value holding one app's own synced Tune rows. */
46
+ export function settingsRowApp(app) {
47
+ return `tune-app:${app}`;
48
+ }
49
+ /** The name the device stamp is kept under (`unisim:tune-stamp:app:<app>`). */
50
+ export function settingsStampName(app) {
51
+ return `app:${app}`;
52
+ }
53
+ /** A row's `data`, or `null` when it is not one (absent, corrupt, unstamped). */
54
+ export function parseSettingsRow(raw) {
55
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw))
56
+ return null;
57
+ const r = raw;
58
+ if (typeof r.at !== 'number' || !Number.isFinite(r.at) || r.at <= 0)
59
+ return null;
60
+ const values = r.values;
61
+ if (!values || typeof values !== 'object' || Array.isArray(values))
62
+ return null;
63
+ return { at: r.at, values: values };
64
+ }
65
+ /** `app` is a product code or short name: ≤ 31 characters, so the row's name fits the table's 40. */
66
+ const APP_NAME = /^[A-Za-z0-9_.-]{1,31}$/;
67
+ let entries = [];
68
+ const registryListeners = new Set();
69
+ /** Every synced store made on this page (one per `app`; a re-made one replaces it). */
70
+ export function getSyncedSettingsEntries() {
71
+ return entries;
72
+ }
73
+ export function subscribeSyncedSettingsEntries(listener) {
74
+ registryListeners.add(listener);
75
+ return () => { registryListeners.delete(listener); };
76
+ }
77
+ /** Reset every synced store on this page (Reset to defaults, via useResetAppDefaults). */
78
+ export function resetAllSyncedSettings() {
79
+ for (const e of entries)
80
+ e.reset();
81
+ }
82
+ function register(entry) {
83
+ entries = [...entries.filter((e) => e.app !== entry.app), entry];
84
+ for (const l of registryListeners)
85
+ l();
86
+ }
87
+ // ── The store ────────────────────────────────────────────────────────────────
88
+ function hasDom() {
89
+ return typeof window !== 'undefined';
90
+ }
91
+ function clone(v) {
92
+ return JSON.parse(JSON.stringify(v));
93
+ }
94
+ function same(a, b) {
95
+ return JSON.stringify(a) === JSON.stringify(b);
96
+ }
97
+ /**
98
+ * Create an app's synced Tune settings. Call it ONCE, at module level, and
99
+ * export the result.
100
+ *
101
+ * - `app`: the app's product code (`config.product`), ≤ 31 characters. The
102
+ * row is `tune-app:<app>`; the device stamp `unisim:tune-stamp:app:<app>`.
103
+ * - `defaults`: every setting's default. JSON values only. ⚠️ Use `null`, not
104
+ * `undefined`, for "none": an absent key in the account's row leaves this
105
+ * device's value as it is (so an older build that doesn't know a newer
106
+ * setting can't reset it), and `undefined` doesn't survive JSON.
107
+ * - `normalise(raw, defaults)`: turn anything — the stored object (in an old
108
+ * shape too), the account's values, a patched set — into a complete, valid
109
+ * set. It must not trust `raw` (it can be `undefined`, `null`, junk) and
110
+ * must fill every key; a throw reads as the defaults.
111
+ *
112
+ * ⚠️ Never change a setting's default by accident: a device that never
113
+ * changed anything shows the defaults, and so does a Reset. Tick boxes start
114
+ * unticked (BRANDING.md); word a default-on feature as an opt-out.
115
+ */
116
+ export function createSyncedSettings(app, defaults, normalise, options = {}) {
117
+ if (!APP_NAME.test(app))
118
+ throw new Error(`createSyncedSettings: "${app}" is not a short app name (letters, digits, _ . -, ≤ 31)`);
119
+ const storageKey = options.storageKey ?? `unisim:settings:${app}`;
120
+ const deviceOnly = new Set(options.deviceOnly ?? []);
121
+ const listeners = new Set();
122
+ const changeListeners = new Set();
123
+ let quiet = 0;
124
+ const read = (raw) => {
125
+ try {
126
+ const v = normalise(raw, clone(defaults));
127
+ if (v && typeof v === 'object' && !Array.isArray(v))
128
+ return v;
129
+ }
130
+ catch { /* falls through to the defaults */ }
131
+ return clone(defaults);
132
+ };
133
+ const save = (v) => {
134
+ try {
135
+ window.localStorage.setItem(storageKey, JSON.stringify(v));
136
+ }
137
+ catch { /* storage off: held for this page */ }
138
+ };
139
+ const load = () => {
140
+ if (!hasDom())
141
+ return read(undefined);
142
+ let raw;
143
+ try {
144
+ const stored = window.localStorage.getItem(storageKey);
145
+ if (stored !== null)
146
+ raw = JSON.parse(stored);
147
+ }
148
+ catch { /* corrupt or unreadable */ }
149
+ if (raw === undefined && options.legacy) {
150
+ let old;
151
+ try {
152
+ old = options.legacy();
153
+ }
154
+ catch { /* nothing to migrate */ }
155
+ if (old !== undefined && old !== null) {
156
+ const migrated = read(old);
157
+ save(migrated);
158
+ return migrated;
159
+ }
160
+ }
161
+ return read(raw);
162
+ };
163
+ let state = load();
164
+ const emit = () => { for (const l of listeners)
165
+ l(); };
166
+ const noteChange = () => {
167
+ if (quiet > 0)
168
+ return;
169
+ for (const l of changeListeners)
170
+ l();
171
+ };
172
+ /** Commit `next`; returns which keys changed. */
173
+ const commit = (next) => {
174
+ const changed = Object.keys({ ...state, ...next }).filter((k) => !same(state[k], next[k]));
175
+ if (changed.length === 0)
176
+ return changed;
177
+ state = next;
178
+ save(state);
179
+ emit();
180
+ return changed;
181
+ };
182
+ const set = (patch) => {
183
+ const p = typeof patch === 'function' ? patch(state) : patch;
184
+ if (!p || typeof p !== 'object')
185
+ return;
186
+ const changed = commit(read({ ...state, ...p }));
187
+ if (changed.some((k) => !deviceOnly.has(k)))
188
+ noteChange();
189
+ };
190
+ const reset = () => {
191
+ const changed = commit(read(undefined));
192
+ if (changed.some((k) => !deviceOnly.has(k)))
193
+ noteChange();
194
+ };
195
+ const snapshot = () => {
196
+ const out = {};
197
+ for (const [k, v] of Object.entries(state)) {
198
+ if (!deviceOnly.has(k) && v !== undefined)
199
+ out[k] = v;
200
+ }
201
+ return out;
202
+ };
203
+ const applyRemote = (values) => {
204
+ // Only the synced keys the row has; this device keeps its device-only
205
+ // keys, and any key an older build's row doesn't know.
206
+ const incoming = {};
207
+ for (const [k, v] of Object.entries(values))
208
+ if (!deviceOnly.has(k))
209
+ incoming[k] = v;
210
+ quiet++;
211
+ try {
212
+ commit(read({ ...state, ...incoming }));
213
+ }
214
+ finally {
215
+ quiet--;
216
+ }
217
+ };
218
+ // Another tab on this device changed them.
219
+ if (hasDom()) {
220
+ try {
221
+ window.addEventListener('storage', (e) => {
222
+ if (e.key !== storageKey)
223
+ return;
224
+ let raw;
225
+ try {
226
+ raw = e.newValue === null ? undefined : JSON.parse(e.newValue);
227
+ }
228
+ catch {
229
+ return;
230
+ }
231
+ const next = read(raw);
232
+ if (same(next, state))
233
+ return;
234
+ state = next;
235
+ emit();
236
+ });
237
+ }
238
+ catch { /* no window events */ }
239
+ }
240
+ const subscribe = (l) => {
241
+ listeners.add(l);
242
+ return () => { listeners.delete(l); };
243
+ };
244
+ const getState = () => state;
245
+ function useSettings(selector) {
246
+ const s = useSyncExternalStore(subscribe, getState, getState);
247
+ return selector ? selector(s) : s;
248
+ }
249
+ const store = useSettings;
250
+ Object.defineProperties(store, {
251
+ getState: { value: getState },
252
+ set: { value: set },
253
+ setState: { value: set },
254
+ reset: { value: reset },
255
+ subscribe: { value: subscribe },
256
+ app: { value: app },
257
+ storageKey: { value: storageKey },
258
+ defaults: { get: () => read(undefined) },
259
+ });
260
+ register({
261
+ app,
262
+ snapshot,
263
+ applyRemote,
264
+ onChange: (l) => {
265
+ changeListeners.add(l);
266
+ return () => { changeListeners.delete(l); };
267
+ },
268
+ reset,
269
+ });
270
+ return store;
271
+ }
272
+ //# sourceMappingURL=syncedSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncedSettings.js","sourceRoot":"","sources":["../src/syncedSettings.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,wEAAwE;AACxE,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,qEAAqE;AACrE,4EAA4E;AAC5E,kBAAkB;AAClB,EAAE;AACF,sDAAsD;AACtD,qEAAqE;AACrE,iDAAiD;AACjD,iGAAiG;AACjG,sBAAsB;AACtB,0DAA0D;AAC1D,8CAA8C;AAC9C,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,4EAA4E;AAC5E,EAAE;AACF,+DAA+D;AAC/D,0EAA0E;AAC1E,yEAAyE;AACzE,2EAA2E;AAC3E,0EAA0E;AAC1E,0EAA0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,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;YACtB,OAAO,GAAG,EAAE,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA,CAAC,CAAC,CAAA;QAC5C,CAAC;QACD,KAAK;KACN,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unisim/sdk",
3
- "version": "0.231.1",
3
+ "version": "0.232.0",
4
4
  "description": "Shared React SDK for the Universal Suite — auth, entitlements, usage telemetry, changelog, org admin.",
5
5
  "license": "MIT",
6
6
  "author": "Universal Simulation Ltd",
@@ -129,6 +129,7 @@
129
129
  "test:tune-account": "npm run build && node tests/tune-account.browser.mjs",
130
130
  "test:guest-tuning": "npm run build && node tests/guest-tuning.browser.mjs",
131
131
  "test:tune-sync": "npm run build && node tests/tune-sync.mjs && node tests/tune-sync.browser.mjs",
132
+ "test:synced-settings": "npm run build && node tests/synced-settings.mjs && node tests/synced-settings.browser.mjs",
132
133
  "test:empty-actions": "npm run build && node tests/empty-actions.browser.mjs",
133
134
  "test:menu-row-close": "npm run build && node tests/menu-row-close.browser.mjs",
134
135
  "prepublishOnly": "npm run typecheck && npm run build",