@quatronic/sdk 0.10.1 → 0.11.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.
Files changed (71) hide show
  1. package/README.md +6 -0
  2. package/dist/chunk-JM5LHJUJ.js +32 -0
  3. package/dist/chunk-JM5LHJUJ.js.map +1 -0
  4. package/dist/{chunk-YFZB5EW6.js → chunk-P5GBQVO7.js} +2 -2
  5. package/dist/{chunk-IFESUTF2.js → chunk-VQKYPW5V.js} +7 -3
  6. package/dist/chunk-VQKYPW5V.js.map +1 -0
  7. package/dist/{chunk-POZI4OKJ.js → chunk-WOFBDOMY.js} +2 -2
  8. package/dist/{chunk-TPBRMW5N.js → chunk-YCKDMG4B.js} +30 -1
  9. package/dist/chunk-YCKDMG4B.js.map +1 -0
  10. package/dist/chunk-YJZZURE4.js +83 -0
  11. package/dist/chunk-YJZZURE4.js.map +1 -0
  12. package/dist/cli/skills-postinstall.js +12 -5
  13. package/dist/cli/skills.js +10 -4
  14. package/dist/context-CWvUIBHJ.d.ts +196 -0
  15. package/dist/eslint/index.d.ts +11 -1
  16. package/dist/eslint/index.js +123 -4
  17. package/dist/eslint/index.js.map +1 -1
  18. package/dist/expo/auth/index.d.ts +14 -0
  19. package/dist/expo/auth/index.js +324 -0
  20. package/dist/expo/auth/index.js.map +1 -0
  21. package/dist/expo/config/index.d.ts +38 -0
  22. package/dist/expo/config/index.js +35 -0
  23. package/dist/expo/config/index.js.map +1 -0
  24. package/dist/expo/log/index.d.ts +9 -0
  25. package/dist/expo/log/index.js +16 -0
  26. package/dist/expo/log/index.js.map +1 -0
  27. package/dist/expo/query/index.d.ts +41 -0
  28. package/dist/expo/query/index.js +98 -0
  29. package/dist/expo/query/index.js.map +1 -0
  30. package/dist/expo/sentry/index.d.ts +33 -0
  31. package/dist/expo/sentry/index.js +121 -0
  32. package/dist/expo/sentry/index.js.map +1 -0
  33. package/dist/expo/testing/index.d.ts +32 -0
  34. package/dist/expo/testing/index.js +58 -0
  35. package/dist/expo/testing/index.js.map +1 -0
  36. package/dist/expo/updates/index.d.ts +51 -0
  37. package/dist/expo/updates/index.js +163 -0
  38. package/dist/expo/updates/index.js.map +1 -0
  39. package/dist/next/auth/index.d.ts +50 -0
  40. package/dist/next/auth/index.js +523 -101
  41. package/dist/next/auth/index.js.map +1 -1
  42. package/dist/next/boot/index.js +3 -3
  43. package/dist/next/db/index.js +1 -1
  44. package/dist/next/security/index.d.ts +24 -1
  45. package/dist/next/security/index.js +29 -0
  46. package/dist/next/security/index.js.map +1 -1
  47. package/dist/next/sentry/client.js +3 -3
  48. package/dist/next/sentry/client.js.map +1 -1
  49. package/dist/next/sentry/index.js +1 -1
  50. package/dist/next/sentry/register.js +3 -3
  51. package/dist/node/sentry/index.js +1 -1
  52. package/dist/node/sentry/register.js +2 -2
  53. package/package.json +85 -2
  54. package/skills/catalog.json +3 -0
  55. package/skills/qore-add-api-route/SKILL.md +1 -1
  56. package/skills/qore-add-feature/SKILL.md +1 -1
  57. package/skills/qore-add-page/SKILL.md +1 -1
  58. package/skills/qore-debug-issue/SKILL.md +10 -0
  59. package/skills/qore-mobile-add-screen/SKILL.md +64 -0
  60. package/skills/qore-mobile-call-server/SKILL.md +75 -0
  61. package/skills/qore-mobile-run-on-device/SKILL.md +44 -0
  62. package/skills/qore-observability/SKILL.md +17 -0
  63. package/skills/qore-secure-io/SKILL.md +15 -0
  64. package/skills/qore-ship-checklist/SKILL.md +10 -0
  65. package/skills/qore-translate-strings/SKILL.md +10 -0
  66. package/skills/qore-use-design-system/SKILL.md +1 -1
  67. package/skills/qore-use-permissions/SKILL.md +10 -0
  68. package/dist/chunk-IFESUTF2.js.map +0 -1
  69. package/dist/chunk-TPBRMW5N.js.map +0 -1
  70. /package/dist/{chunk-YFZB5EW6.js.map → chunk-P5GBQVO7.js.map} +0 -0
  71. /package/dist/{chunk-POZI4OKJ.js.map → chunk-WOFBDOMY.js.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/expo/testing/index.tsx"],"sourcesContent":["// @quatronic/sdk/expo/testing — for the mobile app's component tests (jest).\n// Provides the same auth context as `QoreAuthProvider`, with a fixed status.\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\"\nimport type { ReactNode } from \"react\"\nimport type { Me, MobileAuth } from \"../auth/client\"\nimport { AuthContextProvider, type AuthStatus } from \"../auth/context\"\nimport { ApiError } from \"../core/errors\"\n\ntype Route = unknown\n\n/**\n * A `MobileAuth` whose `apiFetch` answers from `routes`: path → body, or a\n * function of the request init. A missing route throws `ApiError(404)`; an\n * `Error` value is thrown as is (use `new Unauthenticated()` for a 401).\n */\nexport function mockApiFetch(routes: Record<string, Route> = {}): MobileAuth {\n return {\n serverUrl: \"https://app.test\",\n login: async () => ({ ok: true }),\n logout: async () => undefined,\n openPasswordReset: async () => undefined,\n hasSession: async () => true,\n checkApiLevel: async () => ({ state: \"ok\" }),\n apiFetch: async <T,>(path: string, init?: RequestInit): Promise<T> => {\n if (!(path in routes)) throw new ApiError(404, \"not_found\")\n const route = routes[path]\n const value = typeof route === \"function\" ? (route as (i: RequestInit | undefined) => unknown)(init) : route\n if (value instanceof Error) throw value\n return value as T\n },\n }\n}\n\n/** A signed-in user with no roles; override what the test needs. */\nexport const testUser = (over: Partial<Me> = {}): Me => ({\n sub: \"user-1\",\n email: null,\n name: \"Test User\",\n organizationAlias: \"acme\",\n roles: [],\n permissions: [],\n ...over,\n})\n\nexport interface MockAuthProviderProps {\n children: ReactNode\n /** Default: signed in as `testUser()`. */\n status?: AuthStatus\n auth?: MobileAuth\n signIn?: (locale: string) => Promise<void>\n signOut?: () => Promise<void>\n}\n\nconst noop = async () => undefined\n\nexport function MockAuthProvider({ children, status = { state: \"signedIn\", me: testUser() }, auth, signIn, signOut }: MockAuthProviderProps) {\n const value = { status, auth: auth ?? mockApiFetch(), signIn: signIn ?? noop, signOut: signOut ?? noop, refresh: noop, expire: () => undefined }\n return <AuthContextProvider value={value}>{children}</AuthContextProvider>\n}\n\n/** A query client for one test: no retries, nothing kept between tests. */\nexport function createTestQueryClient(): QueryClient {\n return new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0 }, mutations: { retry: false } } })\n}\n\n/** `MockAuthProvider` inside a fresh `QueryClientProvider`. */\nexport function TestProviders({ children, client, ...auth }: MockAuthProviderProps & { client?: QueryClient }) {\n return (\n <QueryClientProvider client={client ?? createTestQueryClient()}>\n <MockAuthProvider {...auth}>{children}</MockAuthProvider>\n </QueryClientProvider>\n )\n}\n\nexport { ApiError, Unauthenticated } from \"../core/errors\"\nexport type { AuthStatus } from \"../auth/context\"\nexport type { Me, MobileAuth } from \"../auth/client\"\n"],"mappings":";;;;;;;;;AAEA,SAAS,aAAa,2BAA2B;AAuDxC;AA1CF,SAAS,aAAa,SAAgC,CAAC,GAAe;AAC3E,SAAO;AAAA,IACL,WAAW;AAAA,IACX,OAAO,aAAa,EAAE,IAAI,KAAK;AAAA,IAC/B,QAAQ,YAAY;AAAA,IACpB,mBAAmB,YAAY;AAAA,IAC/B,YAAY,YAAY;AAAA,IACxB,eAAe,aAAa,EAAE,OAAO,KAAK;AAAA,IAC1C,UAAU,OAAW,MAAc,SAAmC;AACpE,UAAI,EAAE,QAAQ,QAAS,OAAM,IAAI,SAAS,KAAK,WAAW;AAC1D,YAAM,QAAQ,OAAO,IAAI;AACzB,YAAM,QAAQ,OAAO,UAAU,aAAc,MAAkD,IAAI,IAAI;AACvG,UAAI,iBAAiB,MAAO,OAAM;AAClC,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAGO,IAAM,WAAW,CAAC,OAAoB,CAAC,OAAW;AAAA,EACvD,KAAK;AAAA,EACL,OAAO;AAAA,EACP,MAAM;AAAA,EACN,mBAAmB;AAAA,EACnB,OAAO,CAAC;AAAA,EACR,aAAa,CAAC;AAAA,EACd,GAAG;AACL;AAWA,IAAM,OAAO,YAAY;AAElB,SAAS,iBAAiB,EAAE,UAAU,SAAS,EAAE,OAAO,YAAY,IAAI,SAAS,EAAE,GAAG,MAAM,QAAQ,QAAQ,GAA0B;AAC3I,QAAM,QAAQ,EAAE,QAAQ,MAAM,QAAQ,aAAa,GAAG,QAAQ,UAAU,MAAM,SAAS,WAAW,MAAM,SAAS,MAAM,QAAQ,MAAM,OAAU;AAC/I,SAAO,oBAAC,uBAAoB,OAAe,UAAS;AACtD;AAGO,SAAS,wBAAqC;AACnD,SAAO,IAAI,YAAY,EAAE,gBAAgB,EAAE,SAAS,EAAE,OAAO,OAAO,QAAQ,EAAE,GAAG,WAAW,EAAE,OAAO,MAAM,EAAE,EAAE,CAAC;AAClH;AAGO,SAAS,cAAc,EAAE,UAAU,QAAQ,GAAG,KAAK,GAAqD;AAC7G,SACE,oBAAC,uBAAoB,QAAQ,UAAU,sBAAsB,GAC3D,8BAAC,oBAAkB,GAAG,MAAO,UAAS,GACxC;AAEJ;","names":[]}
@@ -0,0 +1,51 @@
1
+ interface UpdateTimings {
2
+ /** How long the splash may wait for an update that is already downloading, in ms. Default 3000. */
3
+ startupWindowMs?: number;
4
+ /** At most one foreground check per this many ms. Expo rate-limits frequent polling. Default 30 min. */
5
+ checkEveryMs?: number;
6
+ /** An away of at least this many ms lets a downloaded update restart the app on return. Default 15 min. */
7
+ resumeAfterMs?: number;
8
+ }
9
+ declare const DEFAULT_TIMINGS: Required<UpdateTimings>;
10
+
11
+ type UpdateEvent = "ota.checked" | "ota.downloaded" | "ota.reloading" | "ota.failed";
12
+ interface OtaUpdateOptions extends UpdateTimings {
13
+ /** Every check, download, restart and failure, for the app's log. Failures never throw. */
14
+ onEvent?: (event: UpdateEvent, detail: Record<string, string>) => void;
15
+ }
16
+ interface OtaUpdates {
17
+ /** Keep the splash up: an update is downloading during the startup window. Pass to the splash's `ready`. */
18
+ holdSplash: boolean;
19
+ }
20
+ /**
21
+ * On a screen whose state must survive: an unsaved form, an upload in progress.
22
+ * While `active`, coming back to the app never restarts it for an update; the
23
+ * update waits for the next long absence or the next cold start.
24
+ */
25
+ declare function useHoldUpdates(active: boolean): void;
26
+
27
+ interface ReloadScreen {
28
+ /** The splash's background colour, so the restart looks like the splash. */
29
+ backgroundColor?: string;
30
+ /** The splash mark: `require("../../assets/images/splash-icon.png")`. */
31
+ image?: number | string;
32
+ imageResizeMode?: "contain" | "cover" | "center" | "stretch";
33
+ spinner?: {
34
+ enabled?: boolean;
35
+ color?: string;
36
+ size?: "small" | "medium" | "large";
37
+ };
38
+ fade?: boolean;
39
+ }
40
+ interface AppUpdateOptions extends OtaUpdateOptions {
41
+ reloadScreen?: ReloadScreen;
42
+ }
43
+ /**
44
+ * Once, in the root layout. Checks when the app returns to the foreground (at
45
+ * most every 30 min), restarts into a downloaded update behind the splash at
46
+ * launch or on return after 15 min away, and otherwise leaves it for the next
47
+ * cold start. Pass `holdSplash` into the splash's `ready` condition.
48
+ */
49
+ declare function useOtaUpdates(options?: AppUpdateOptions): OtaUpdates;
50
+
51
+ export { type AppUpdateOptions, DEFAULT_TIMINGS, type OtaUpdateOptions, type OtaUpdates, type ReloadScreen, type UpdateEvent, type UpdateTimings, useHoldUpdates, useOtaUpdates };
@@ -0,0 +1,163 @@
1
+ // src/expo/updates/index.ts
2
+ import * as Updates from "expo-updates";
3
+ import { AppState } from "react-native";
4
+ import { useMemo } from "react";
5
+
6
+ // src/expo/updates/hook.ts
7
+ import { useCallback, useEffect, useRef, useState } from "react";
8
+
9
+ // src/expo/updates/core.ts
10
+ var DEFAULT_TIMINGS = {
11
+ startupWindowMs: 3e3,
12
+ checkEveryMs: 30 * 6e4,
13
+ resumeAfterMs: 15 * 6e4
14
+ };
15
+ function resolveTimings(t = {}) {
16
+ return {
17
+ startupWindowMs: t.startupWindowMs ?? DEFAULT_TIMINGS.startupWindowMs,
18
+ checkEveryMs: t.checkEveryMs ?? DEFAULT_TIMINGS.checkEveryMs,
19
+ resumeAfterMs: t.resumeAfterMs ?? DEFAULT_TIMINGS.resumeAfterMs
20
+ };
21
+ }
22
+ function inStartupWindow(s, t) {
23
+ return s.now - s.launchedAt < t.startupWindowMs;
24
+ }
25
+ function shouldHoldSplash(s, t) {
26
+ return inStartupWindow(s, t) && (s.downloading || s.pending);
27
+ }
28
+ function shouldReloadAtStartup(s, t) {
29
+ return inStartupWindow(s, t) && s.pending;
30
+ }
31
+ function onResume(s, t) {
32
+ const away = s.backgroundedAt === null ? 0 : s.now - s.backgroundedAt;
33
+ if (s.pending && away >= t.resumeAfterMs && s.holds === 0) return "reload";
34
+ if (s.now - s.lastCheckAt >= t.checkEveryMs) return "check";
35
+ return "none";
36
+ }
37
+
38
+ // src/expo/updates/hook.ts
39
+ var holds = 0;
40
+ function useHoldUpdates(active) {
41
+ useEffect(() => {
42
+ if (!active) return;
43
+ holds += 1;
44
+ return () => {
45
+ holds -= 1;
46
+ };
47
+ }, [active]);
48
+ }
49
+ function message(e) {
50
+ return e instanceof Error ? e.message : String(e);
51
+ }
52
+ function useOtaUpdatesWith(platform, options = {}) {
53
+ const { downloading, pending } = platform.useStatus();
54
+ const [launchedAt] = useState(() => Date.now());
55
+ const [timings] = useState(() => resolveTimings(options));
56
+ const [, setWindowClosed] = useState(false);
57
+ const [startupReloadFailed, setStartupReloadFailed] = useState(false);
58
+ const onEventRef = useRef(options.onEvent);
59
+ onEventRef.current = options.onEvent;
60
+ const pendingRef = useRef(pending);
61
+ pendingRef.current = pending;
62
+ const reloading = useRef(false);
63
+ const emit = useCallback((event, detail = {}) => {
64
+ try {
65
+ onEventRef.current?.(event, detail);
66
+ } catch {
67
+ }
68
+ }, []);
69
+ const reload = useCallback(
70
+ async (reason) => {
71
+ if (reloading.current) return;
72
+ reloading.current = true;
73
+ emit("ota.reloading", { reason });
74
+ try {
75
+ await platform.reload();
76
+ } catch (e) {
77
+ reloading.current = false;
78
+ if (reason === "startup") setStartupReloadFailed(true);
79
+ emit("ota.failed", { step: "reload", reason, message: message(e) });
80
+ }
81
+ },
82
+ [platform, emit]
83
+ );
84
+ useEffect(() => {
85
+ if (!platform.enabled) return;
86
+ const id = setTimeout(() => setWindowClosed(true), timings.startupWindowMs);
87
+ return () => clearTimeout(id);
88
+ }, [platform, timings]);
89
+ useEffect(() => {
90
+ if (!platform.enabled) return;
91
+ if (shouldReloadAtStartup({ now: Date.now(), launchedAt, downloading, pending }, timings)) void reload("startup");
92
+ }, [platform, pending, downloading, launchedAt, timings, reload]);
93
+ useEffect(() => {
94
+ if (!platform.enabled) return;
95
+ let backgroundedAt = null;
96
+ let lastCheckAt = launchedAt;
97
+ return platform.onAppStateChange((state) => {
98
+ if (state === "background") {
99
+ backgroundedAt = Date.now();
100
+ return;
101
+ }
102
+ if (state !== "active") return;
103
+ const now = Date.now();
104
+ const action = onResume({ now, backgroundedAt, lastCheckAt, pending: pendingRef.current, holds }, timings);
105
+ backgroundedAt = null;
106
+ if (action === "reload") {
107
+ void reload("resume");
108
+ } else if (action === "check") {
109
+ lastCheckAt = now;
110
+ void (async () => {
111
+ try {
112
+ const downloaded = await platform.checkAndFetch();
113
+ emit(downloaded ? "ota.downloaded" : "ota.checked");
114
+ } catch (e) {
115
+ emit("ota.failed", { step: "check", message: message(e) });
116
+ }
117
+ })();
118
+ }
119
+ });
120
+ }, [platform, launchedAt, timings, reload, emit]);
121
+ const holdSplash = platform.enabled && !startupReloadFailed && shouldHoldSplash({ now: Date.now(), launchedAt, downloading, pending }, timings);
122
+ return { holdSplash };
123
+ }
124
+
125
+ // src/expo/updates/index.ts
126
+ var ENABLED = Updates.isEnabled && !__DEV__;
127
+ function useStatus() {
128
+ const { isDownloading, isUpdatePending } = Updates.useUpdates();
129
+ return { downloading: isDownloading, pending: isUpdatePending };
130
+ }
131
+ function useNoStatus() {
132
+ return { downloading: false, pending: false };
133
+ }
134
+ function useOtaUpdates(options = {}) {
135
+ const { reloadScreen } = options;
136
+ const platform = useMemo(
137
+ () => ({
138
+ enabled: ENABLED,
139
+ // Chosen once per process, so the hook order never changes between renders.
140
+ useStatus: ENABLED ? useStatus : useNoStatus,
141
+ onAppStateChange: (listener) => {
142
+ const sub = AppState.addEventListener("change", listener);
143
+ return () => sub.remove();
144
+ },
145
+ checkAndFetch: async () => {
146
+ const check = await Updates.checkForUpdateAsync();
147
+ if (!check.isAvailable) return false;
148
+ const fetched = await Updates.fetchUpdateAsync();
149
+ return fetched.isNew;
150
+ },
151
+ reload: () => Updates.reloadAsync(reloadScreen ? { reloadScreenOptions: reloadScreen } : void 0)
152
+ }),
153
+ // The reload screen is a constant in the app; a new object per render must not resubscribe.
154
+ []
155
+ );
156
+ return useOtaUpdatesWith(platform, options);
157
+ }
158
+ export {
159
+ DEFAULT_TIMINGS,
160
+ useHoldUpdates,
161
+ useOtaUpdates
162
+ };
163
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/expo/updates/index.ts","../../../src/expo/updates/hook.ts","../../../src/expo/updates/core.ts"],"sourcesContent":["// @quatronic/sdk/expo/updates — apply over-the-air updates sooner without\n// interrupting anyone. Runs on the device. The rules are in ./core.ts.\n//\n// Nothing here changes native config, so adopting it changes no fingerprint: it\n// reaches an installed app as an OTA update itself.\nimport * as Updates from \"expo-updates\"\nimport { AppState } from \"react-native\"\nimport { useMemo } from \"react\"\nimport { useOtaUpdatesWith, type OtaUpdateOptions, type OtaUpdates, type UpdatesPlatform } from \"./hook\"\n\nexport interface ReloadScreen {\n /** The splash's background colour, so the restart looks like the splash. */\n backgroundColor?: string\n /** The splash mark: `require(\"../../assets/images/splash-icon.png\")`. */\n image?: number | string\n imageResizeMode?: \"contain\" | \"cover\" | \"center\" | \"stretch\"\n spinner?: { enabled?: boolean; color?: string; size?: \"small\" | \"medium\" | \"large\" }\n fade?: boolean\n}\n\nexport interface AppUpdateOptions extends OtaUpdateOptions {\n reloadScreen?: ReloadScreen\n}\n\nconst ENABLED = Updates.isEnabled && !__DEV__\n\nfunction useStatus() {\n const { isDownloading, isUpdatePending } = Updates.useUpdates()\n return { downloading: isDownloading, pending: isUpdatePending }\n}\n\nfunction useNoStatus() {\n return { downloading: false, pending: false }\n}\n\n/**\n * Once, in the root layout. Checks when the app returns to the foreground (at\n * most every 30 min), restarts into a downloaded update behind the splash at\n * launch or on return after 15 min away, and otherwise leaves it for the next\n * cold start. Pass `holdSplash` into the splash's `ready` condition.\n */\nexport function useOtaUpdates(options: AppUpdateOptions = {}): OtaUpdates {\n const { reloadScreen } = options\n const platform = useMemo<UpdatesPlatform>(\n () => ({\n enabled: ENABLED,\n // Chosen once per process, so the hook order never changes between renders.\n useStatus: ENABLED ? useStatus : useNoStatus,\n onAppStateChange: (listener) => {\n const sub = AppState.addEventListener(\"change\", listener)\n return () => sub.remove()\n },\n checkAndFetch: async () => {\n const check = await Updates.checkForUpdateAsync()\n if (!check.isAvailable) return false\n const fetched = await Updates.fetchUpdateAsync()\n return fetched.isNew\n },\n reload: () => Updates.reloadAsync(reloadScreen ? { reloadScreenOptions: reloadScreen } : undefined),\n }),\n // The reload screen is a constant in the app; a new object per render must not resubscribe.\n [],\n )\n return useOtaUpdatesWith(platform, options)\n}\n\nexport { useHoldUpdates } from \"./hook\"\nexport { DEFAULT_TIMINGS } from \"./core\"\nexport type { UpdateTimings } from \"./core\"\nexport type { OtaUpdateOptions, OtaUpdates, UpdateEvent } from \"./hook\"\n","// The React side of OTA updates, written against a small platform adapter so it\n// is tested in Node. `index.ts` supplies the real adapter (expo-updates + AppState).\nimport { useCallback, useEffect, useRef, useState } from \"react\"\nimport { onResume, resolveTimings, shouldHoldSplash, shouldReloadAtStartup, type UpdateTimings } from \"./core\"\n\nexport type UpdateEvent = \"ota.checked\" | \"ota.downloaded\" | \"ota.reloading\" | \"ota.failed\"\n\nexport interface OtaUpdateOptions extends UpdateTimings {\n /** Every check, download, restart and failure, for the app's log. Failures never throw. */\n onEvent?: (event: UpdateEvent, detail: Record<string, string>) => void\n}\n\nexport interface OtaUpdates {\n /** Keep the splash up: an update is downloading during the startup window. Pass to the splash's `ready`. */\n holdSplash: boolean\n}\n\nexport interface UpdatesPlatform {\n /** False in Expo Go, a dev client, or a build without `updates.url`: then nothing happens. */\n enabled: boolean\n /** A hook: what expo-updates is doing right now. */\n useStatus(): { downloading: boolean; pending: boolean }\n /** AppState changes; returns the unsubscribe. */\n onAppStateChange(listener: (state: string) => void): () => void\n /** Check, and download if there is something new. True when an update was downloaded. */\n checkAndFetch(): Promise<boolean>\n /** Restart into the downloaded update. */\n reload(): Promise<void>\n}\n\n// Screens holding off a restart. One process, one counter: a hold is not tied to a provider.\nlet holds = 0\n\n/** For tests only. */\nexport function _holdCount(): number {\n return holds\n}\n\n/**\n * On a screen whose state must survive: an unsaved form, an upload in progress.\n * While `active`, coming back to the app never restarts it for an update; the\n * update waits for the next long absence or the next cold start.\n */\nexport function useHoldUpdates(active: boolean): void {\n useEffect(() => {\n if (!active) return\n holds += 1\n return () => {\n holds -= 1\n }\n }, [active])\n}\n\nfunction message(e: unknown): string {\n return e instanceof Error ? e.message : String(e)\n}\n\nexport function useOtaUpdatesWith(platform: UpdatesPlatform, options: OtaUpdateOptions = {}): OtaUpdates {\n const { downloading, pending } = platform.useStatus()\n const [launchedAt] = useState(() => Date.now())\n const [timings] = useState(() => resolveTimings(options))\n // Re-render once when the startup window closes, so the splash is released.\n const [, setWindowClosed] = useState(false)\n const [startupReloadFailed, setStartupReloadFailed] = useState(false)\n\n const onEventRef = useRef(options.onEvent)\n onEventRef.current = options.onEvent\n const pendingRef = useRef(pending)\n pendingRef.current = pending\n const reloading = useRef(false)\n\n const emit = useCallback((event: UpdateEvent, detail: Record<string, string> = {}) => {\n try {\n onEventRef.current?.(event, detail)\n } catch {\n // A broken logger must not break updates.\n }\n }, [])\n\n const reload = useCallback(\n async (reason: \"startup\" | \"resume\") => {\n if (reloading.current) return\n reloading.current = true\n emit(\"ota.reloading\", { reason })\n try {\n await platform.reload()\n } catch (e) {\n reloading.current = false\n if (reason === \"startup\") setStartupReloadFailed(true)\n emit(\"ota.failed\", { step: \"reload\", reason, message: message(e) })\n }\n },\n [platform, emit],\n )\n\n useEffect(() => {\n if (!platform.enabled) return\n const id = setTimeout(() => setWindowClosed(true), timings.startupWindowMs)\n return () => clearTimeout(id)\n }, [platform, timings])\n\n useEffect(() => {\n if (!platform.enabled) return\n if (shouldReloadAtStartup({ now: Date.now(), launchedAt, downloading, pending }, timings)) void reload(\"startup\")\n }, [platform, pending, downloading, launchedAt, timings, reload])\n\n useEffect(() => {\n if (!platform.enabled) return\n let backgroundedAt: number | null = null\n // The launch itself checked (expo-updates' ON_LOAD), so the first foreground check waits a full interval.\n let lastCheckAt = launchedAt\n return platform.onAppStateChange((state) => {\n if (state === \"background\") {\n backgroundedAt = Date.now()\n return\n }\n if (state !== \"active\") return\n const now = Date.now()\n const action = onResume({ now, backgroundedAt, lastCheckAt, pending: pendingRef.current, holds }, timings)\n backgroundedAt = null\n if (action === \"reload\") {\n void reload(\"resume\")\n } else if (action === \"check\") {\n // Throttle on the attempt, not the success, so a failing check is not retried on every resume.\n lastCheckAt = now\n void (async () => {\n try {\n const downloaded = await platform.checkAndFetch()\n emit(downloaded ? \"ota.downloaded\" : \"ota.checked\")\n } catch (e) {\n emit(\"ota.failed\", { step: \"check\", message: message(e) })\n }\n })()\n }\n })\n }, [platform, launchedAt, timings, reload, emit])\n\n const holdSplash =\n platform.enabled && !startupReloadFailed && shouldHoldSplash({ now: Date.now(), launchedAt, downloading, pending }, timings)\n return { holdSplash }\n}\n","// When a Qore mobile app checks for and applies an over-the-air update. Pure:\n// no React, no React Native, no expo-updates, so every rule is unit-tested in Node.\n//\n// expo-updates on its own checks at launch and applies on the next cold start.\n// iOS keeps an app suspended for days, so that can take a week. Two moments are\n// added where a restart costs the user nothing:\n// - startup: an update that finishes downloading while the splash is still up\n// is applied behind it, in the same launch;\n// - resume: an update that is already downloaded is applied when the user comes\n// back after a long absence, unless a screen holds it off.\n\nexport interface UpdateTimings {\n /** How long the splash may wait for an update that is already downloading, in ms. Default 3000. */\n startupWindowMs?: number\n /** At most one foreground check per this many ms. Expo rate-limits frequent polling. Default 30 min. */\n checkEveryMs?: number\n /** An away of at least this many ms lets a downloaded update restart the app on return. Default 15 min. */\n resumeAfterMs?: number\n}\n\nexport const DEFAULT_TIMINGS: Required<UpdateTimings> = {\n startupWindowMs: 3_000,\n checkEveryMs: 30 * 60_000,\n resumeAfterMs: 15 * 60_000,\n}\n\nexport function resolveTimings(t: UpdateTimings = {}): Required<UpdateTimings> {\n return {\n startupWindowMs: t.startupWindowMs ?? DEFAULT_TIMINGS.startupWindowMs,\n checkEveryMs: t.checkEveryMs ?? DEFAULT_TIMINGS.checkEveryMs,\n resumeAfterMs: t.resumeAfterMs ?? DEFAULT_TIMINGS.resumeAfterMs,\n }\n}\n\nexport interface StartupState {\n now: number\n launchedAt: number\n /** expo-updates is downloading an update it found. A check that finds nothing never holds the splash. */\n downloading: boolean\n /** A downloaded update is waiting to be applied. */\n pending: boolean\n}\n\n/** Inside the startup window: until it closes, the splash may still cover a restart. */\nexport function inStartupWindow(s: Pick<StartupState, \"now\" | \"launchedAt\">, t: Required<UpdateTimings>): boolean {\n return s.now - s.launchedAt < t.startupWindowMs\n}\n\n/**\n * Keep the splash up: an update is downloading or ready, and the window is open.\n * A slow check with nothing to download never delays the app.\n */\nexport function shouldHoldSplash(s: StartupState, t: Required<UpdateTimings>): boolean {\n return inStartupWindow(s, t) && (s.downloading || s.pending)\n}\n\n/** Restart into the update now, behind the splash. After the window the user may be using the app, so it waits. */\nexport function shouldReloadAtStartup(s: StartupState, t: Required<UpdateTimings>): boolean {\n return inStartupWindow(s, t) && s.pending\n}\n\nexport interface ResumeState {\n now: number\n /** When the app went to the background; null if it never did. */\n backgroundedAt: number | null\n lastCheckAt: number\n pending: boolean\n /** Screens that asked not to be restarted (unsaved form, upload in progress). */\n holds: number\n}\n\nexport type ResumeAction = \"reload\" | \"check\" | \"none\"\n\n/** What to do when the app returns to the foreground. */\nexport function onResume(s: ResumeState, t: Required<UpdateTimings>): ResumeAction {\n const away = s.backgroundedAt === null ? 0 : s.now - s.backgroundedAt\n if (s.pending && away >= t.resumeAfter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;AAChE;AAEA,SAAS,cAAc;AACrB,SAAO,EAAE,aAAa,OAAO,SAAS,MAAM;AAC9C;AAQO,SAAS,cAAc,UAA4B,CAAC,GAAe;AACxE,QAAM,EAAE,aAAa,IAAI;AACzB,QAAM,WAAW;AAAA,IACf,OAAO;AAAA,MACL,SAAS;AAAA;AAAA,MAET,WAAW,UAAU,YAAY;AAAA,MACjC,kBAAkB,CAAC,aAAa;AAC9B,cAAM,MAAM,SAAS,iBAAiB,UAAU,QAAQ;AACxD,eAAO,MAAM,IAAI,OAAO;AAAA,MAC1B;AAAA,MACA,eAAe,YAAY;AACzB,cAAM,QAAQ,MAAc,4BAAoB;AAChD,YAAI,CAAC,MAAM,YAAa,QAAO;AAC/B,cAAM,UAAU,MAAc,yBAAiB;AAC/C,eAAO,QAAQ;AAAA,MACjB;AAAA,MACA,QAAQ,MAAc,oBAAY,eAAe,EAAE,qBAAqB,aAAa,IAAI,MAAS;AAAA,IACpG;AAAA;AAAA,IAEA,CAAC;AAAA,EACH;AACA,SAAO,kBAAkB,UAAU,OAAO;AAC5C;","names":[]}
@@ -43,6 +43,34 @@ type NextAuthOptions = {
43
43
  sessionIdleTimeoutSec?: number;
44
44
  /** Hard ceiling no activity can extend. Default 12h. */
45
45
  sessionAbsoluteMaxSec?: number;
46
+ /** Turns on sign-in for the app's own Expo app (`@quatronic/sdk/expo/auth`).
47
+ * Absent: every `/api/auth/mobile/*` route answers 404 and no bearer token
48
+ * is accepted anywhere. See `MobileAuthOptions`. */
49
+ mobile?: MobileAuthOptions;
50
+ };
51
+ /** Server half of mobile sign-in. The phone opens `/api/auth/mobile/login` in
52
+ * an in-app browser with its PKCE challenge; the callback sends a one-shot
53
+ * code back to the app's URL scheme; the app redeems it at
54
+ * `/api/auth/mobile/redeem` for a session token it sends as
55
+ * `Authorization: Bearer` from then on. `requireAuth`, `getAccessToken` and
56
+ * `/api/auth/me` accept that header, so the app's own API routes serve the
57
+ * phone unchanged. */
58
+ type MobileAuthOptions = {
59
+ /** The app's URL schemes, e.g. `["acme-orders", "acme-orders-stag"]`. A login
60
+ * may only return to `<scheme>://auth/return`. */
61
+ schemes: readonly string[];
62
+ /** Also accept `exp://…/--/auth/return` (Expo Go during development). Never
63
+ * in production: any Expo Go project could then receive a code. */
64
+ allowExpoGo?: boolean;
65
+ /** Mobile session dies after this long without use. Default 30 days. */
66
+ sessionIdleTimeoutSec?: number;
67
+ /** Hard ceiling for a mobile session. Default 90 days. */
68
+ sessionAbsoluteMaxSec?: number;
69
+ /** Ask Keycloak for `offline_access` on a mobile login, so the refresh token
70
+ * outlives the realm's SSO session (the 30/90-day bounds above then hold).
71
+ * The app's Keycloak client must list `offline_access` as an optional
72
+ * scope, or every mobile login fails with `invalid_scope`. Default false. */
73
+ offlineAccess?: boolean;
46
74
  };
47
75
 
48
76
  type AuthRouteHandlers = {
@@ -94,6 +122,11 @@ declare function createKcClient(cfg: KcConfig): {
94
122
  prompt?: string;
95
123
  maxAge?: number;
96
124
  idTokenHint?: string;
125
+ /** Added to the configured scope for this one request, e.g. a mobile
126
+ * login's `offline_access`. The client must allow each one in Keycloak. */
127
+ extraScopes?: readonly string[];
128
+ /** Language for Keycloak's own pages (OIDC `ui_locales`). */
129
+ uiLocales?: string;
97
130
  }) => string;
98
131
  buildEndSessionUrl: (args: {
99
132
  postLogoutRedirectUri: string;
@@ -125,7 +158,10 @@ type CreateSessionInput = {
125
158
  refreshToken: string;
126
159
  refreshExpiresAt: Date;
127
160
  pendingIdentityConfirm?: boolean;
161
+ /** "web" (cookie, the default) or "mobile" (bearer token held by a phone). */
162
+ kind?: SessionKind;
128
163
  };
164
+ type SessionKind = "web" | "mobile";
129
165
  type Session = {
130
166
  id: string;
131
167
  userSub: string;
@@ -139,6 +175,9 @@ type Session = {
139
175
  refreshExpiresAt: Date;
140
176
  createdAt: Date;
141
177
  updatedAt: Date;
178
+ /** Always set on a row read from the store; absent only on hand-built
179
+ * values, where it reads as "web" — so a bearer check fails closed. */
180
+ kind?: SessionKind;
142
181
  };
143
182
  type RotateInput = {
144
183
  accessToken: string;
@@ -199,6 +238,12 @@ declare function requireAuth(opts: {
199
238
  * would silently become the session's real lifetime. */
200
239
  idleTimeoutSec?: number;
201
240
  absoluteMaxSec?: number;
241
+ /** Set when the server enabled mobile sign-in: an `Authorization: Bearer`
242
+ * session token is accepted when there is no cookie, with these bounds. */
243
+ mobile?: {
244
+ idleTimeoutSec: number;
245
+ absoluteMaxSec: number;
246
+ };
202
247
  }): () => Promise<AuthUser>;
203
248
 
204
249
  declare function requireAuthFor(opts: NextAuthOptions): Promise<() => Promise<AuthUser>>;
@@ -216,6 +261,11 @@ type GetAccessTokenDeps = {
216
261
  * would silently become the session's real lifetime. */
217
262
  idleTimeoutSec?: number;
218
263
  absoluteMaxSec?: number;
264
+ /** Set when the server enabled mobile sign-in; see `requireAuth`. */
265
+ mobile?: {
266
+ idleTimeoutSec: number;
267
+ absoluteMaxSec: number;
268
+ };
219
269
  };
220
270
  declare function getAccessToken(opts: GetAccessTokenDeps): () => Promise<string | null>;
221
271
  declare function requireAccessToken(opts: GetAccessTokenDeps): () => Promise<string>;