@quatronic/sdk 0.9.0-test.0c53b6d → 0.9.0-test.3ef1bcc
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 +6 -0
- package/dist/chunk-7XIDABOQ.js +83 -0
- package/dist/chunk-7XIDABOQ.js.map +1 -0
- package/dist/{chunk-YFZB5EW6.js → chunk-P5GBQVO7.js} +2 -2
- package/dist/{chunk-IFESUTF2.js → chunk-VQKYPW5V.js} +7 -3
- package/dist/chunk-VQKYPW5V.js.map +1 -0
- package/dist/{chunk-POZI4OKJ.js → chunk-WOFBDOMY.js} +2 -2
- package/dist/{chunk-TPBRMW5N.js → chunk-YCKDMG4B.js} +30 -1
- package/dist/chunk-YCKDMG4B.js.map +1 -0
- package/dist/chunk-YXIYI7R2.js +23 -0
- package/dist/chunk-YXIYI7R2.js.map +1 -0
- package/dist/cli/skills-postinstall.js +12 -5
- package/dist/cli/skills.js +10 -4
- package/dist/context-B_u-vpkw.d.ts +111 -0
- package/dist/eslint/index.d.ts +11 -1
- package/dist/eslint/index.js +123 -4
- package/dist/eslint/index.js.map +1 -1
- package/dist/expo/auth/index.d.ts +8 -0
- package/dist/expo/auth/index.js +177 -0
- package/dist/expo/auth/index.js.map +1 -0
- package/dist/expo/config/index.d.ts +16 -0
- package/dist/expo/config/index.js +17 -0
- package/dist/expo/config/index.js.map +1 -0
- package/dist/expo/log/index.d.ts +9 -0
- package/dist/expo/log/index.js +16 -0
- package/dist/expo/log/index.js.map +1 -0
- package/dist/expo/query/index.d.ts +15 -0
- package/dist/expo/query/index.js +52 -0
- package/dist/expo/query/index.js.map +1 -0
- package/dist/expo/sentry/index.d.ts +29 -0
- package/dist/expo/sentry/index.js +93 -0
- package/dist/expo/sentry/index.js.map +1 -0
- package/dist/expo/testing/index.d.ts +32 -0
- package/dist/expo/testing/index.js +57 -0
- package/dist/expo/testing/index.js.map +1 -0
- package/dist/next/auth/index.d.ts +50 -0
- package/dist/next/auth/index.js +504 -101
- package/dist/next/auth/index.js.map +1 -1
- package/dist/next/boot/index.js +3 -3
- package/dist/next/db/index.js +1 -1
- package/dist/next/sentry/client.js +3 -3
- package/dist/next/sentry/client.js.map +1 -1
- package/dist/next/sentry/index.js +1 -1
- package/dist/next/sentry/register.js +3 -3
- package/dist/node/sentry/index.js +1 -1
- package/dist/node/sentry/register.js +2 -2
- package/package.json +75 -2
- package/skills/catalog.json +3 -0
- package/skills/qore-add-api-route/SKILL.md +1 -1
- package/skills/qore-add-feature/SKILL.md +1 -1
- package/skills/qore-add-page/SKILL.md +1 -1
- package/skills/qore-debug-issue/SKILL.md +10 -0
- package/skills/qore-mobile-add-screen/SKILL.md +58 -0
- package/skills/qore-mobile-call-server/SKILL.md +74 -0
- package/skills/qore-mobile-run-on-device/SKILL.md +41 -0
- package/skills/qore-observability/SKILL.md +17 -0
- package/skills/qore-secure-io/SKILL.md +15 -0
- package/skills/qore-ship-checklist/SKILL.md +10 -0
- package/skills/qore-translate-strings/SKILL.md +10 -0
- package/skills/qore-use-design-system/SKILL.md +1 -1
- package/skills/qore-use-permissions/SKILL.md +10 -0
- package/dist/chunk-IFESUTF2.js.map +0 -1
- package/dist/chunk-TPBRMW5N.js.map +0 -1
- /package/dist/{chunk-YFZB5EW6.js.map → chunk-P5GBQVO7.js.map} +0 -0
- /package/dist/{chunk-POZI4OKJ.js.map → chunk-WOFBDOMY.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/expo/core/pkce.ts","../../../src/expo/core/url.ts","../../../src/expo/auth/client.ts","../../../src/expo/auth/native.ts","../../../src/expo/auth/index.ts"],"sourcesContent":["const ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\"\n\n/** base64url without padding; no dependency on a global `btoa`. */\nexport function base64url(bytes: Uint8Array): string {\n let out = \"\"\n let i = 0\n for (; i + 2 < bytes.length; i += 3) {\n const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8) | bytes[i + 2]!\n out += ALPHABET[(n >> 18) & 63]! + ALPHABET[(n >> 12) & 63]! + ALPHABET[(n >> 6) & 63]! + ALPHABET[n & 63]!\n }\n const rest = bytes.length - i\n if (rest === 1) {\n const n = bytes[i]! << 16\n out += ALPHABET[(n >> 18) & 63]! + ALPHABET[(n >> 12) & 63]!\n } else if (rest === 2) {\n const n = (bytes[i]! << 16) | (bytes[i + 1]! << 8)\n out += ALPHABET[(n >> 18) & 63]! + ALPHABET[(n >> 12) & 63]! + ALPHABET[(n >> 6) & 63]!\n }\n return out\n}\n\n/** Standard base64 (as a SHA-256 digest comes back) to base64url without padding. */\nexport function base64ToUrl(b64: string): string {\n return b64.replace(/\\+/g, \"-\").replace(/\\//g, \"_\").replace(/=+$/, \"\")\n}\n\nexport interface PkceCrypto {\n randomBytes(n: number): Uint8Array\n sha256Base64(input: string): Promise<string>\n}\n\n/** A 43-character verifier and its S256 challenge (RFC 7636). */\nexport async function createPkce(crypto: PkceCrypto): Promise<{ verifier: string; challenge: string }> {\n const verifier = base64url(crypto.randomBytes(32))\n const challenge = base64ToUrl(await crypto.sha256Base64(verifier))\n return { verifier, challenge }\n}\n","// URL helpers that do not rely on React Native's partial `URL` polyfill.\n\n/** The first value of query parameter `name` in `url`, decoded; null when absent. */\nexport function queryParam(url: string, name: string): string | null {\n const query = url.split(\"#\", 1)[0]!.split(\"?\")[1]\n if (!query) return null\n for (const pair of query.split(\"&\")) {\n const i = pair.indexOf(\"=\")\n const key = i < 0 ? pair : pair.slice(0, i)\n if (safeDecode(key) !== name) continue\n return i < 0 ? \"\" : safeDecode(pair.slice(i + 1).replace(/\\+/g, \" \"))\n }\n return null\n}\n\nfunction safeDecode(s: string): string {\n try {\n return decodeURIComponent(s)\n } catch {\n return s\n }\n}\n\n/** `serverUrl` without trailing slashes. */\nexport function normalizeOrigin(serverUrl: string): string {\n return serverUrl.replace(/\\/+$/, \"\")\n}\n","// The device half of mobile sign-in. The server half is\n// `createAuthRouteHandlers({ mobile })` in `@quatronic/sdk/next/auth`; change\n// both together. This file imports no React Native module: `native.ts` builds\n// the platform from the real peers, tests hand in a fake one.\nimport { ApiError, Unauthenticated } from \"../core/errors\"\nimport { createPkce, type PkceCrypto } from \"../core/pkce\"\nimport { normalizeOrigin, queryParam } from \"../core/url\"\n\n/** Where the session token lives: the platform keystore, never AsyncStorage. */\nexport const TOKEN_KEY = \"qore.session\"\n\nexport interface AuthPlatform extends PkceCrypto {\n store: {\n get(key: string): Promise<string | null>\n set(key: string, value: string): Promise<void>\n delete(key: string): Promise<void>\n }\n /** The app's own return URL: `exp://…/--/auth/return` in Expo Go, `<scheme>://auth/return` in a build. */\n returnUrl(): string\n /** Opens the system browser on `url` and resolves with the URL it was sent back to, or null when the user closed it. */\n openAuthSession(url: string, returnUrl: string): Promise<string | null>\n openBrowser(url: string): Promise<void>\n fetch: typeof fetch\n}\n\n/** What `/api/auth/me` answers to a bearer caller. */\nexport interface Me {\n sub: string\n email: string | null\n name: string | null\n organizationAlias: string | null\n roles: string[]\n permissions: string[]\n}\n\n/** Why a login did not produce a session. The server sends all but `cancelled` and `failed` itself. */\nexport type LoginFailure = \"cancelled\" | \"expired\" | \"no_app_access\" | \"identity_mismatch\" | \"failed\"\n\nexport type LoginResult = { ok: true } | { ok: false; reason: LoginFailure; detail?: string }\n\nconst SERVER_REASONS: ReadonlySet<string> = new Set([\"cancelled\", \"expired\", \"no_app_access\", \"identity_mismatch\", \"failed\"])\n\nexport interface MobileAuthOptions {\n /** The app's own Next server, e.g. `https://shop.acme.qore.app`. The device talks to nothing else. */\n serverUrl: string\n /** Sent as `X-Qore-App-Version` on every request, so server logs say which build called. */\n appVersion?: string\n}\n\nexport interface MobileAuth {\n login(locale: string): Promise<LoginResult>\n logout(): Promise<void>\n /** Fetch a route of the app's own server (`/api/...`) with the session token. Throws `Unauthenticated` on 401 (the token is cleared), `ApiError` on any other error status. */\n apiFetch<T>(path: string, init?: RequestInit): Promise<T>\n /** Keycloak's \"forgot password\" page in the system browser. Keycloak mails the link; nothing comes back to the app. */\n openPasswordReset(locale: string): Promise<void>\n /** Whether a token is stored. Says nothing about whether the server still accepts it. */\n hasSession(): Promise<boolean>\n readonly serverUrl: string\n}\n\nexport function createMobileAuthWith(platform: AuthPlatform, opts: MobileAuthOptions): MobileAuth {\n const origin = normalizeOrigin(opts.serverUrl)\n const versionHeader = opts.appVersion ? { \"x-qore-app-version\": opts.appVersion } : undefined\n\n function headers(init?: HeadersInit, token?: string): Headers {\n const h = new Headers(init)\n if (versionHeader) h.set(\"x-qore-app-version\", versionHeader[\"x-qore-app-version\"])\n if (token) h.set(\"authorization\", `Bearer ${token}`)\n return h\n }\n\n async function apiFetch<T>(path: string, init: RequestInit = {}): Promise<T> {\n // A relative path only: the token is for the app's own server and nobody else.\n if (!path.startsWith(\"/\") || path.startsWith(\"//\")) throw new Error(`apiFetch takes a path on the app's own server, got \"${path}\"`)\n const token = await platform.store.get(TOKEN_KEY)\n if (!token) throw new Unauthenticated()\n const res = await platform.fetch(`${origin}${path}`, { ...init, headers: headers(init.headers, token) })\n if (res.status === 401) {\n await platform.store.delete(TOKEN_KEY)\n throw new Unauthenticated()\n }\n if (!res.ok) {\n const body = (await res.json().catch(() => null)) as { error?: unknown } | null\n throw new ApiError(res.status, typeof body?.error === \"string\" ? body.error : null)\n }\n if (res.status === 204) return undefined as T\n return (await res.json()) as T\n }\n\n async function login(locale: string): Promise<LoginResult> {\n const { verifier, challenge } = await createPkce(platform)\n const returnUrl = platform.returnUrl()\n const url =\n `${origin}/api/auth/mobile/login?challenge=${encodeURIComponent(challenge)}` +\n `&redirect=${encodeURIComponent(returnUrl)}&locale=${encodeURIComponent(locale)}`\n const back = await platform.openAuthSession(url, returnUrl)\n if (back === null) return { ok: false, reason: \"cancelled\" }\n\n const error = queryParam(back, \"error\")\n if (error !== null) return { ok: false, reason: SERVER_REASONS.has(error) ? (error as LoginFailure) : \"failed\", detail: error }\n const code = queryParam(back, \"code\")\n if (!code) return { ok: false, reason: \"failed\", detail: \"no_code\" }\n\n let res: Response\n try {\n res = await platform.fetch(`${origin}/api/auth/mobile/redeem`, {\n method: \"POST\",\n headers: headers({ \"content-type\": \"application/json\" }),\n body: JSON.stringify({ code, verifier }),\n })\n } catch {\n return { ok: false, reason: \"failed\", detail: \"network\" }\n }\n const body = (await res.json().catch(() => null)) as { token?: unknown; error?: unknown } | null\n if (!res.ok || typeof body?.token !== \"string\") {\n const detail = typeof body?.error === \"string\" ? body.error : `http_${res.status}`\n // The code lives a minute; a slow redeem is an expired login, not a broken one.\n return { ok: false, reason: detail === \"invalid_grant\" ? \"expired\" : \"failed\", detail }\n }\n await platform.store.set(TOKEN_KEY, body.token)\n return { ok: true }\n }\n\n async function logout(): Promise<void> {\n const token = await platform.store.get(TOKEN_KEY)\n await platform.store.delete(TOKEN_KEY)\n if (!token) return\n // Best effort: the local token is already gone, which is what signs the device out.\n await platform.fetch(`${origin}/api/auth/mobile/logout`, { method: \"POST\", headers: headers(undefined, token) }).catch(() => undefined)\n }\n\n async function openPasswordReset(locale: string): Promise<void> {\n await platform.openBrowser(`${origin}/api/auth/mobile/reset-password?locale=${encodeURIComponent(locale)}`)\n }\n\n return {\n login,\n logout,\n apiFetch,\n openPasswordReset,\n hasSession: async () => (await platform.store.get(TOKEN_KEY)) !== null,\n serverUrl: origin,\n }\n}\n","// The only file of `expo/auth` that imports React Native peers.\nimport * as Crypto from \"expo-crypto\"\nimport * as Linking from \"expo-linking\"\nimport * as SecureStore from \"expo-secure-store\"\nimport * as WebBrowser from \"expo-web-browser\"\nimport type { AuthPlatform } from \"./client\"\n\nexport const nativeAuthPlatform: AuthPlatform = {\n randomBytes: (n) => Crypto.getRandomBytes(n),\n sha256Base64: (input) =>\n Crypto.digestStringAsync(Crypto.CryptoDigestAlgorithm.SHA256, input, { encoding: Crypto.CryptoEncoding.BASE64 }),\n store: {\n get: (key) => SecureStore.getItemAsync(key),\n set: (key, value) => SecureStore.setItemAsync(key, value),\n delete: (key) => SecureStore.deleteItemAsync(key),\n },\n returnUrl: () => Linking.createURL(\"auth/return\"),\n openAuthSession: async (url, returnUrl) => {\n const result = await WebBrowser.openAuthSessionAsync(url, returnUrl)\n return result.type === \"success\" ? result.url : null\n },\n openBrowser: async (url) => {\n await WebBrowser.openBrowserAsync(url)\n },\n fetch: (input, init) => fetch(input, init),\n}\n","// @quatronic/sdk/expo/auth — sign-in for a Qore mobile app (React Native / Expo).\n// Runs on the device. Its server counterpart is `@quatronic/sdk/next/auth`\n// with `mobile` set; see docs/surfaces.md. Never import this from `src/`.\nimport { createMobileAuthWith, type MobileAuth, type MobileAuthOptions } from \"./client\"\nimport { nativeAuthPlatform } from \"./native\"\n\n/** The device auth client for the app's own server. Create it once, at module scope. */\nexport function createMobileAuth(opts: MobileAuthOptions): MobileAuth {\n return createMobileAuthWith(nativeAuthPlatform, opts)\n}\n\nexport { ApiError, Unauthenticated } from \"../core/errors\"\nexport type { LoginFailure, LoginResult, Me, MobileAuth, MobileAuthOptions } from \"./client\"\nexport { Can, QoreAuthProvider, useAuth, useCan, useMe } from \"./context\"\nexport type { AuthContextValue, AuthStatus, QoreAuthProviderProps, SignedOutNotice } from \"./context\"\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAM,WAAW;AAGV,SAAS,UAAU,OAA2B;AACnD,MAAI,MAAM;AACV,MAAI,IAAI;AACR,SAAO,IAAI,IAAI,MAAM,QAAQ,KAAK,GAAG;AACnC,UAAM,IAAK,MAAM,CAAC,KAAM,KAAO,MAAM,IAAI,CAAC,KAAM,IAAK,MAAM,IAAI,CAAC;AAChE,WAAO,SAAU,KAAK,KAAM,EAAE,IAAK,SAAU,KAAK,KAAM,EAAE,IAAK,SAAU,KAAK,IAAK,EAAE,IAAK,SAAS,IAAI,EAAE;AAAA,EAC3G;AACA,QAAM,OAAO,MAAM,SAAS;AAC5B,MAAI,SAAS,GAAG;AACd,UAAM,IAAI,MAAM,CAAC,KAAM;AACvB,WAAO,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AS,iBAAiB,MAAqC;AACpE,SAAO,qBAAqB,oBAAoB,IAAI;AACtD;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface MobileConfigInput {
|
|
2
|
+
/** `EXPO_PUBLIC_SERVER_URL`: the app's own server. */
|
|
3
|
+
serverUrl: string;
|
|
4
|
+
/** `EXPO_PUBLIC_SENTRY_DSN`; empty turns Sentry off. */
|
|
5
|
+
sentryDsn: string;
|
|
6
|
+
/** `EXPO_PUBLIC_QORE_ENV`. */
|
|
7
|
+
qoreEnv: string;
|
|
8
|
+
}
|
|
9
|
+
interface ConfigProblem {
|
|
10
|
+
key: string;
|
|
11
|
+
problem: string;
|
|
12
|
+
}
|
|
13
|
+
/** Empty when the build can run. */
|
|
14
|
+
declare function checkConfig(c: MobileConfigInput): ConfigProblem[];
|
|
15
|
+
|
|
16
|
+
export { type ConfigProblem, type MobileConfigInput, checkConfig };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/expo/config/index.ts
|
|
2
|
+
function checkConfig(c) {
|
|
3
|
+
const problems = [];
|
|
4
|
+
if (!isOrigin(c.serverUrl)) problems.push({ key: "EXPO_PUBLIC_SERVER_URL", problem: "must be an https:// origin" });
|
|
5
|
+
if (c.sentryDsn && !/^https:\/\/\S+$/i.test(c.sentryDsn))
|
|
6
|
+
problems.push({ key: "EXPO_PUBLIC_SENTRY_DSN", problem: "must be an https:// DSN, or empty to turn Sentry off" });
|
|
7
|
+
if (!/^[a-z][a-z0-9-]*$/.test(c.qoreEnv))
|
|
8
|
+
problems.push({ key: "EXPO_PUBLIC_QORE_ENV", problem: "must be an environment name such as staging" });
|
|
9
|
+
return problems;
|
|
10
|
+
}
|
|
11
|
+
function isOrigin(raw) {
|
|
12
|
+
return /^https:\/\/[a-z0-9.-]+(?::\d{1,5})?\/*$/i.test(raw);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
checkConfig
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/expo/config/index.ts"],"sourcesContent":["// @quatronic/sdk/expo/config — checks the mobile app's public config. The web\n// app refuses to boot on a bad env; a phone shows the problems on screen,\n// since nobody reads its log. Pure: no React Native import.\n\nexport interface MobileConfigInput {\n /** `EXPO_PUBLIC_SERVER_URL`: the app's own server. */\n serverUrl: string\n /** `EXPO_PUBLIC_SENTRY_DSN`; empty turns Sentry off. */\n sentryDsn: string\n /** `EXPO_PUBLIC_QORE_ENV`. */\n qoreEnv: string\n}\n\nexport interface ConfigProblem {\n key: string\n problem: string\n}\n\n/** Empty when the build can run. */\nexport function checkConfig(c: MobileConfigInput): ConfigProblem[] {\n const problems: ConfigProblem[] = []\n if (!isOrigin(c.serverUrl)) problems.push({ key: \"EXPO_PUBLIC_SERVER_URL\", problem: \"must be an https:// origin\" })\n if (c.sentryDsn && !/^https:\\/\\/\\S+$/i.test(c.sentryDsn))\n problems.push({ key: \"EXPO_PUBLIC_SENTRY_DSN\", problem: \"must be an https:// DSN, or empty to turn Sentry off\" })\n if (!/^[a-z][a-z0-9-]*$/.test(c.qoreEnv))\n problems.push({ key: \"EXPO_PUBLIC_QORE_ENV\", problem: \"must be an environment name such as staging\" })\n return problems\n}\n\n// A regex, not `new URL`: React Native's URL polyfill is partial.\nfunction isOrigin(raw: string): boolean {\n return /^https:\\/\\/[a-z0-9.-]+(?::\\d{1,5})?\\/*$/i.test(raw)\n}\n"],"mappings":";AAmBO,SAAS,YAAY,GAAuC;AACjE,QAAM,WAA4B,CAAC;AACnC,MAAI,CAAC,SAAS,EAAE,SAAS,EAAG,UAAS,KAAK,EAAE,KAAK,0BAA0B,SAAS,6BAA6B,CAAC;AAClH,MAAI,EAAE,aAAa,CAAC,mBAAmB,KAAK,EAAE,SAAS;AACrD,aAAS,KAAK,EAAE,KAAK,0BAA0B,SAAS,uDAAuD,CAAC;AAClH,MAAI,CAAC,oBAAoB,KAAK,EAAE,OAAO;AACrC,aAAS,KAAK,EAAE,KAAK,wBAAwB,SAAS,8CAA8C,CAAC;AACvG,SAAO;AACT;AAGA,SAAS,SAAS,KAAsB;AACtC,SAAO,2CAA2C,KAAK,GAAG;AAC5D;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type LogAttributes = Record<string, string | number | boolean>;
|
|
2
|
+
declare const log: {
|
|
3
|
+
debug: (message: string, attrs?: LogAttributes) => void;
|
|
4
|
+
info: (message: string, attrs?: LogAttributes) => void;
|
|
5
|
+
warn: (message: string, attrs?: LogAttributes) => void;
|
|
6
|
+
error: (message: string, attrs?: LogAttributes) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { type LogAttributes, log };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/expo/log/index.ts
|
|
2
|
+
import * as Sentry from "@sentry/react-native";
|
|
3
|
+
function emit(level, message, attrs) {
|
|
4
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) console.log(`[${level}] ${message}`, attrs ?? "");
|
|
5
|
+
Sentry.logger[level](message, attrs);
|
|
6
|
+
}
|
|
7
|
+
var log = {
|
|
8
|
+
debug: (message, attrs) => emit("debug", message, attrs),
|
|
9
|
+
info: (message, attrs) => emit("info", message, attrs),
|
|
10
|
+
warn: (message, attrs) => emit("warn", message, attrs),
|
|
11
|
+
error: (message, attrs) => emit("error", message, attrs)
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
log
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/expo/log/index.ts"],"sourcesContent":["// @quatronic/sdk/expo/log — the mobile app's logger. Lines go to Sentry Logs\n// (tag app=mobile); in development they are printed too. Attributes are\n// filterable values: no names or addresses (they are scrubbed anyway).\n// The server's counterpart is the `Sentry.logger` the Next app already uses.\nimport * as Sentry from \"@sentry/react-native\"\n\nexport type LogAttributes = Record<string, string | number | boolean>\ntype Level = \"debug\" | \"info\" | \"warn\" | \"error\"\n\nfunction emit(level: Level, message: string, attrs?: LogAttributes): void {\n if (typeof __DEV__ !== \"undefined\" && __DEV__) console.log(`[${level}] ${message}`, attrs ?? \"\")\n Sentry.logger[level](message, attrs)\n}\n\nexport const log = {\n debug: (message: string, attrs?: LogAttributes) => emit(\"debug\", message, attrs),\n info: (message: string, attrs?: LogAttributes) => emit(\"info\", message, attrs),\n warn: (message: string, attrs?: LogAttributes) => emit(\"warn\", message, attrs),\n error: (message: string, attrs?: LogAttributes) => emit(\"error\", message, attrs),\n}\n"],"mappings":";AAIA,YAAY,YAAY;AAKxB,SAAS,KAAK,OAAc,SAAiB,OAA6B;AACxE,MAAI,OAAO,YAAY,eAAe,QAAS,SAAQ,IAAI,IAAI,KAAK,KAAK,OAAO,IAAI,SAAS,EAAE;AAC/F,EAAO,cAAO,KAAK,EAAE,SAAS,KAAK;AACrC;AAEO,IAAM,MAAM;AAAA,EACjB,OAAO,CAAC,SAAiB,UAA0B,KAAK,SAAS,SAAS,KAAK;AAAA,EAC/E,MAAM,CAAC,SAAiB,UAA0B,KAAK,QAAQ,SAAS,KAAK;AAAA,EAC7E,MAAM,CAAC,SAAiB,UAA0B,KAAK,QAAQ,SAAS,KAAK;AAAA,EAC7E,OAAO,CAAC,SAAiB,UAA0B,KAAK,SAAS,SAAS,KAAK;AACjF;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
|
|
3
|
+
/** Retrying cannot fix a missing session or a request the server refused. */
|
|
4
|
+
declare function shouldRetry(failureCount: number, error: unknown): boolean;
|
|
5
|
+
interface QueryClientOptions {
|
|
6
|
+
/** Runs when any query or mutation finds the session gone. Wire it to `useAuth().expire`. */
|
|
7
|
+
onUnauthenticated: () => void;
|
|
8
|
+
/** How long a result counts as fresh. Default 30 s. */
|
|
9
|
+
staleTime?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** The app's query client. Create it once, inside the auth provider, so `onUnauthenticated` can reach `expire`. */
|
|
13
|
+
declare function createQueryClient(opts: QueryClientOptions): QueryClient;
|
|
14
|
+
|
|
15
|
+
export { type QueryClientOptions, createQueryClient, shouldRetry };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiError,
|
|
3
|
+
Unauthenticated
|
|
4
|
+
} from "../../chunk-YXIYI7R2.js";
|
|
5
|
+
|
|
6
|
+
// src/expo/query/index.ts
|
|
7
|
+
import NetInfo from "@react-native-community/netinfo";
|
|
8
|
+
import { focusManager, onlineManager } from "@tanstack/react-query";
|
|
9
|
+
import { AppState, Platform } from "react-native";
|
|
10
|
+
|
|
11
|
+
// src/expo/query/core.ts
|
|
12
|
+
import { QueryCache, QueryClient } from "@tanstack/react-query";
|
|
13
|
+
function shouldRetry(failureCount, error) {
|
|
14
|
+
if (error instanceof Unauthenticated) return false;
|
|
15
|
+
if (error instanceof ApiError && error.status < 500) return false;
|
|
16
|
+
return failureCount < 2;
|
|
17
|
+
}
|
|
18
|
+
function createQueryClientCore({ onUnauthenticated, staleTime = 3e4 }) {
|
|
19
|
+
const onError = (error) => {
|
|
20
|
+
if (error instanceof Unauthenticated) onUnauthenticated();
|
|
21
|
+
};
|
|
22
|
+
return new QueryClient({
|
|
23
|
+
queryCache: new QueryCache({ onError }),
|
|
24
|
+
defaultOptions: {
|
|
25
|
+
queries: { retry: shouldRetry, staleTime },
|
|
26
|
+
// A mutation is not repeated behind the user's back.
|
|
27
|
+
mutations: { retry: false, onError }
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/expo/query/index.ts
|
|
33
|
+
var wired = false;
|
|
34
|
+
function wireDeviceEvents() {
|
|
35
|
+
if (wired) return;
|
|
36
|
+
wired = true;
|
|
37
|
+
onlineManager.setEventListener((setOnline) => NetInfo.addEventListener((state) => setOnline(state.isConnected !== false)));
|
|
38
|
+
focusManager.setEventListener((setFocused) => {
|
|
39
|
+
if (Platform.OS === "web") return void 0;
|
|
40
|
+
const sub = AppState.addEventListener("change", (s) => setFocused(s === "active"));
|
|
41
|
+
return () => sub.remove();
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function createQueryClient(opts) {
|
|
45
|
+
wireDeviceEvents();
|
|
46
|
+
return createQueryClientCore(opts);
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
createQueryClient,
|
|
50
|
+
shouldRetry
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/expo/query/index.ts","../../../src/expo/query/core.ts"],"sourcesContent":["// @quatronic/sdk/expo/query — TanStack Query set up for a phone. Runs on the\n// device; the web app has its own client. See docs/surfaces.md.\nimport NetInfo from \"@react-native-community/netinfo\"\nimport { focusManager, onlineManager, type QueryClient } from \"@tanstack/react-query\"\nimport { AppState, Platform } from \"react-native\"\nimport { createQueryClientCore, type QueryClientOptions } from \"./core\"\n\nlet wired = false\n\n/** Queries pause offline and resume on reconnect; \"window focus\" is the app returning to the foreground. Installed once per process. */\nfunction wireDeviceEvents(): void {\n if (wired) return\n wired = true\n onlineManager.setEventListener((setOnline) => NetInfo.addEventListener((state) => setOnline(state.isConnected !== false)))\n focusManager.setEventListener((setFocused) => {\n if (Platform.OS === \"web\") return undefined\n const sub = AppState.addEventListener(\"change\", (s) => setFocused(s === \"active\"))\n return () => sub.remove()\n })\n}\n\n/** The app's query client. Create it once, inside the auth provider, so `onUnauthenticated` can reach `expire`. */\nexport function createQueryClient(opts: QueryClientOptions): QueryClient {\n wireDeviceEvents()\n return createQueryClientCore(opts)\n}\n\nexport { shouldRetry } from \"./core\"\nexport type { QueryClientOptions } from \"./core\"\n","// Pure half of `expo/query`: no React Native import, so it is unit-tested in Node.\nimport { QueryCache, QueryClient } from \"@tanstack/react-query\"\nimport { ApiError, Unauthenticated } from \"../core/errors\"\n\n/** Retrying cannot fix a missing session or a request the server refused. */\nexport function shouldRetry(failureCount: number, error: unknown): boolean {\n if (error instanceof Unauthenticated) return false\n if (error instanceof ApiError && error.status < 500) return false\n return failureCount < 2\n}\n\nexport interface QueryClientOptions {\n /** Runs when any query or mutation finds the session gone. Wire it to `useAuth().expire`. */\n onUnauthenticated: () => void\n /** How long a result counts as fresh. Default 30 s. */\n staleTime?: number\n}\n\nexport function createQueryClientCore({ onUnauthenticated, staleTime = 30_000 }: QueryClientOptions): QueryClient {\n const onError = (error: unknown) => {\n if (error instanceof Unauthenticated) onUnauthenticated()\n }\n return new QueryClient({\n queryCache: new QueryCache({ onError }),\n defaultOptions: {\n queries: { retry: shouldRetry, staleTime },\n // A mutation is not repeated behind the user's back.\n mutations: { retry: false, onError },\n },\n })\n}\n"],"mappings":";;;;;;AAEA,OAAO,aAAa;AACpB,SAAS,cAAc,qBAAuC;AAC9D,SAAS,UAAU,gBAAgB;;;ACHnC,SAAS,YAAY,mBAAmB;AAIjC,SAAS,YAAY,cAAsB,OAAyB;AACzE,MAAI,iBAAiB,gBAAiB,QAAO;AAC7C,MAAI,iBAAiB,YAAY,MAAM,SAAS,IAAK,QAAO;AAC5D,SAAO,eAAe;AACxB;AASO,SAAS,sBAAsB,EAAE,mBAAmB,YAAY,IAAO,GAAoC;AAChH,QAAM,UAAU,CAAC,UAAmB;AAClC,QAAI,iBAAiB,gBAAiB,mBAAkB;AAAA,EAC1D;AACA,SAAO,IAAI,YAAY;AAAA,IACrB,YAAY,IAAI,WAAW,EAAE,QAAQ,CAAC;AAAA,IACtC,gBAAgB;AAAA,MACd,SAAS,EAAE,OAAO,aAAa,UAAU;AAAA;AAAA,MAEzC,WAAW,EAAE,OAAO,OAAO,QAAQ;AAAA,IACrC;AAAA,EACF,CAAC;AACH;;;ADvBA,IAAI,QAAQ;AAGZ,SAAS,mBAAyB;AAChC,MAAI,MAAO;AACX,UAAQ;AACR,gBAAc,iBAAiB,CAAC,cAAc,QAAQ,iBAAiB,CAAC,UAAU,UAAU,MAAM,gBAAgB,KAAK,CAAC,CAAC;AACzH,eAAa,iBAAiB,CAAC,eAAe;AAC5C,QAAI,SAAS,OAAO,MAAO,QAAO;AAClC,UAAM,MAAM,SAAS,iBAAiB,UAAU,CAAC,MAAM,WAAW,MAAM,QAAQ,CAAC;AACjF,WAAO,MAAM,IAAI,OAAO;AAAA,EAC1B,CAAC;AACH;AAGO,SAAS,kBAAkB,MAAuC;AACvE,mBAAiB;AACjB,SAAO,sBAAsB,IAAI;AACnC;","names":[]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
|
|
3
|
+
interface MobileSentryConfig {
|
|
4
|
+
/** The module's Sentry DSN (public by design). Empty turns Sentry off. */
|
|
5
|
+
dsn: string;
|
|
6
|
+
/** The Qore environment name, the same as the server's `QORE_ENV`, so phone and server filter together. */
|
|
7
|
+
environment: string;
|
|
8
|
+
/** The app's own server. Trace headers go there and nowhere else. */
|
|
9
|
+
serverUrl: string;
|
|
10
|
+
/** Defaults to `<slug>@<version>+<build>` from the app config. */
|
|
11
|
+
release?: string;
|
|
12
|
+
}
|
|
13
|
+
/** `<slug>@<version>+<build>`; the build is left off when unknown (Expo Go). */
|
|
14
|
+
declare function releaseName(slug: string | undefined, version: string | undefined, build: string | null | undefined): string;
|
|
15
|
+
|
|
16
|
+
/** Call once, at the top of the root layout module, before anything renders. No DSN, no Sentry. */
|
|
17
|
+
declare function qoreSentryInit(cfg: MobileSentryConfig): void;
|
|
18
|
+
/** On sign-in and sign-out: the Keycloak subject only, as on the server. Pass it to `QoreAuthProvider`'s `onUserChange`. */
|
|
19
|
+
declare function setTelemetryUser(sub: string | null): void;
|
|
20
|
+
/**
|
|
21
|
+
* In the root layout, with Expo Router's `useNavigationContainerRef()`: one
|
|
22
|
+
* transaction per screen, tab switches included, which the screen's API calls
|
|
23
|
+
* hang under.
|
|
24
|
+
*/
|
|
25
|
+
declare function useNavigationTelemetry(navigationRef: unknown): void;
|
|
26
|
+
/** Wrap the root layout's default export: catches render errors and adds touch breadcrumbs. */
|
|
27
|
+
declare function wrap<P extends object>(component: ComponentType<P>): ComponentType<P>;
|
|
28
|
+
|
|
29
|
+
export { type MobileSentryConfig, qoreSentryInit, releaseName, setTelemetryUser, useNavigationTelemetry, wrap };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SECRET_PARAMS,
|
|
3
|
+
scrubEvent,
|
|
4
|
+
scrubLog,
|
|
5
|
+
scrubSpan
|
|
6
|
+
} from "../../chunk-VQKYPW5V.js";
|
|
7
|
+
|
|
8
|
+
// src/expo/sentry/index.ts
|
|
9
|
+
import * as Sentry from "@sentry/react-native";
|
|
10
|
+
import Constants from "expo-constants";
|
|
11
|
+
import { useEffect } from "react";
|
|
12
|
+
|
|
13
|
+
// src/expo/sentry/options.ts
|
|
14
|
+
var APP_TAG = { app: "mobile" };
|
|
15
|
+
var tagLog = (l) => {
|
|
16
|
+
const scrubbed = scrubLog(l);
|
|
17
|
+
scrubbed.attributes = { ...scrubbed.attributes, ...APP_TAG };
|
|
18
|
+
return scrubbed;
|
|
19
|
+
};
|
|
20
|
+
var tagSpan = (s) => {
|
|
21
|
+
const scrubbed = scrubSpan(s);
|
|
22
|
+
scrubbed.data = { ...scrubbed.data, ...APP_TAG };
|
|
23
|
+
return scrubbed;
|
|
24
|
+
};
|
|
25
|
+
var escapeRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
26
|
+
function releaseName(slug, version, build) {
|
|
27
|
+
return `${slug || "app"}@${version || "0.0.0"}${build ? `+${build}` : ""}`;
|
|
28
|
+
}
|
|
29
|
+
function buildMobileOptions(cfg) {
|
|
30
|
+
const production = cfg.environment === "production";
|
|
31
|
+
const origin = cfg.serverUrl.replace(/\/+$/, "");
|
|
32
|
+
return {
|
|
33
|
+
dsn: cfg.dsn,
|
|
34
|
+
environment: cfg.environment,
|
|
35
|
+
release: cfg.release,
|
|
36
|
+
// Who it was is the Keycloak subject (setTelemetryUser), never a name or address.
|
|
37
|
+
sendDefaultPii: false,
|
|
38
|
+
dataCollection: { urlQueryParams: { deny: [...SECRET_PARAMS] } },
|
|
39
|
+
// The origin plus a path boundary, so `https://app.example` does not match `https://app.example.evil`.
|
|
40
|
+
tracePropagationTargets: [new RegExp(`^${escapeRe(origin)}(?:[/?#]|$)`)],
|
|
41
|
+
tracesSampleRate: production ? 0.1 : 1,
|
|
42
|
+
enableLogs: true,
|
|
43
|
+
// Logs are what the app says through `log`, not whatever reaches console.
|
|
44
|
+
enableAutoConsoleLogs: false,
|
|
45
|
+
replaysSessionSampleRate: production ? 0.1 : 1,
|
|
46
|
+
replaysOnErrorSampleRate: 1,
|
|
47
|
+
initialScope: { tags: { ...APP_TAG } },
|
|
48
|
+
beforeSend: scrubEvent,
|
|
49
|
+
beforeSendTransaction: scrubEvent,
|
|
50
|
+
beforeSendLog: tagLog,
|
|
51
|
+
beforeSendSpan: tagSpan
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
var NAVIGATION_OPTIONS = {
|
|
55
|
+
ignoreEmptyBackNavigationTransactions: false,
|
|
56
|
+
// `(tabs)/explore`, not `explore`: the route file, so two screens with one name stay apart.
|
|
57
|
+
useFullPathsForNavigationRoutes: true,
|
|
58
|
+
enableTimeToInitialDisplay: true
|
|
59
|
+
};
|
|
60
|
+
var REPLAY_OPTIONS = { maskAllText: true, maskAllImages: true, maskAllVectors: true };
|
|
61
|
+
|
|
62
|
+
// src/expo/sentry/index.ts
|
|
63
|
+
var navigation = Sentry.reactNavigationIntegration({ ...NAVIGATION_OPTIONS });
|
|
64
|
+
var enabled = false;
|
|
65
|
+
function qoreSentryInit(cfg) {
|
|
66
|
+
if (!cfg.dsn || enabled) return;
|
|
67
|
+
enabled = true;
|
|
68
|
+
const release = cfg.release ?? releaseName(Constants.expoConfig?.slug, Constants.expoConfig?.version, Constants.nativeBuildVersion);
|
|
69
|
+
Sentry.init({
|
|
70
|
+
...buildMobileOptions({ ...cfg, release }),
|
|
71
|
+
// Replay is native only: Expo Go skips it, a development or store build records.
|
|
72
|
+
integrations: [navigation, Sentry.mobileReplayIntegration({ ...REPLAY_OPTIONS })]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function setTelemetryUser(sub) {
|
|
76
|
+
if (enabled) Sentry.setUser(sub ? { id: sub } : null);
|
|
77
|
+
}
|
|
78
|
+
function useNavigationTelemetry(navigationRef) {
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (enabled && navigationRef) navigation.registerNavigationContainer(navigationRef);
|
|
81
|
+
}, [navigationRef]);
|
|
82
|
+
}
|
|
83
|
+
function wrap2(component) {
|
|
84
|
+
return Sentry.wrap(component);
|
|
85
|
+
}
|
|
86
|
+
export {
|
|
87
|
+
qoreSentryInit,
|
|
88
|
+
releaseName,
|
|
89
|
+
setTelemetryUser,
|
|
90
|
+
useNavigationTelemetry,
|
|
91
|
+
wrap2 as wrap
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/expo/sentry/index.ts","../../../src/expo/sentry/options.ts"],"sourcesContent":["// @quatronic/sdk/expo/sentry — errors, traces, logs and masked Replay for a\n// Qore mobile app, into the module's Sentry project with tag app=mobile.\n// Runs on the device; the web counterpart is `@quatronic/sdk/next/sentry`.\nimport * as Sentry from \"@sentry/react-native\"\nimport Constants from \"expo-constants\"\nimport { useEffect, type ComponentType } from \"react\"\nimport { buildMobileOptions, NAVIGATION_OPTIONS, releaseName, REPLAY_OPTIONS, type MobileSentryConfig } from \"./options\"\n\n// Created at import, as Sentry requires, and registered by useNavigationTelemetry.\n// Sentry's expoRouterIntegration looks for a module Expo Router 58 no longer\n// ships and then does nothing, so the container is registered by hand.\nconst navigation = Sentry.reactNavigationIntegration({ ...NAVIGATION_OPTIONS })\nlet enabled = false\n\n/** Call once, at the top of the root layout module, before anything renders. No DSN, no Sentry. */\nexport function qoreSentryInit(cfg: MobileSentryConfig): void {\n if (!cfg.dsn || enabled) return\n enabled = true\n const release = cfg.release ?? releaseName(Constants.expoConfig?.slug, Constants.expoConfig?.version, Constants.nativeBuildVersion)\n Sentry.init({\n ...buildMobileOptions({ ...cfg, release }),\n // Replay is native only: Expo Go skips it, a development or store build records.\n integrations: [navigation, Sentry.mobileReplayIntegration({ ...REPLAY_OPTIONS })],\n })\n}\n\n/** On sign-in and sign-out: the Keycloak subject only, as on the server. Pass it to `QoreAuthProvider`'s `onUserChange`. */\nexport function setTelemetryUser(sub: string | null): void {\n if (enabled) Sentry.setUser(sub ? { id: sub } : null)\n}\n\n/**\n * In the root layout, with Expo Router's `useNavigationContainerRef()`: one\n * transaction per screen, tab switches included, which the screen's API calls\n * hang under.\n */\nexport function useNavigationTelemetry(navigationRef: unknown): void {\n useEffect(() => {\n if (enabled && navigationRef) navigation.registerNavigationContainer(navigationRef)\n }, [navigationRef])\n}\n\n/** Wrap the root layout's default export: catches render errors and adds touch breadcrumbs. */\nexport function wrap<P extends object>(component: ComponentType<P>): ComponentType<P> {\n return Sentry.wrap(component)\n}\n\nexport { releaseName } from \"./options\"\nexport type { MobileSentryConfig } from \"./options\"\n","// Pure half of `expo/sentry`: the init options, unit-tested in Node.\nimport { SECRET_PARAMS, scrubEvent, scrubLog, scrubSpan } from \"../../sentry-core/scrub\"\n\nexport interface MobileSentryConfig {\n /** The module's Sentry DSN (public by design). Empty turns Sentry off. */\n dsn: string\n /** The Qore environment name, the same as the server's `QORE_ENV`, so phone and server filter together. */\n environment: string\n /** The app's own server. Trace headers go there and nowhere else. */\n serverUrl: string\n /** Defaults to `<slug>@<version>+<build>` from the app config. */\n release?: string\n}\n\n/** Tells phone events from server ones in the shared project. */\nconst APP_TAG = { app: \"mobile\" } as const\n\n// The scope's tags reach errors and transactions only: Sentry Logs and child\n// spans never see them, so those carry the tag as an attribute.\nconst tagLog = <L extends Parameters<typeof scrubLog>[0]>(l: L): L => {\n const scrubbed = scrubLog(l)\n scrubbed.attributes = { ...scrubbed.attributes, ...APP_TAG }\n return scrubbed\n}\nconst tagSpan = <S extends Parameters<typeof scrubSpan>[0]>(s: S): S => {\n const scrubbed = scrubSpan(s)\n scrubbed.data = { ...scrubbed.data, ...APP_TAG }\n return scrubbed\n}\n\nconst escapeRe = (s: string) => s.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")\n\n/** `<slug>@<version>+<build>`; the build is left off when unknown (Expo Go). */\nexport function releaseName(slug: string | undefined, version: string | undefined, build: string | null | undefined): string {\n return `${slug || \"app\"}@${version || \"0.0.0\"}${build ? `+${build}` : \"\"}`\n}\n\n/**\n * Everything `Sentry.init` gets except the integrations, which need the\n * native module. Scrubbing is the server's (`sentry-core/scrub`), so the\n * phone and the server redact the same things.\n */\nexport function buildMobileOptions(cfg: MobileSentryConfig & { release: string }) {\n const production = cfg.environment === \"production\"\n const origin = cfg.serverUrl.replace(/\\/+$/, \"\")\n return {\n dsn: cfg.dsn,\n environment: cfg.environment,\n release: cfg.release,\n // Who it was is the Keycloak subject (setTelemetryUser), never a name or address.\n sendDefaultPii: false,\n dataCollection: { urlQueryParams: { deny: [...SECRET_PARAMS] } },\n // The origin plus a path boundary, so `https://app.example` does not match `https://app.example.evil`.\n tracePropagationTargets: [new RegExp(`^${escapeRe(origin)}(?:[/?#]|$)`)],\n tracesSampleRate: production ? 0.1 : 1,\n enableLogs: true,\n // Logs are what the app says through `log`, not whatever reaches console.\n enableAutoConsoleLogs: false,\n replaysSessionSampleRate: production ? 0.1 : 1,\n replaysOnErrorSampleRate: 1,\n initialScope: { tags: { ...APP_TAG } },\n beforeSend: scrubEvent,\n beforeSendTransaction: scrubEvent,\n beforeSendLog: tagLog,\n beforeSendSpan: tagSpan,\n }\n}\n\n/**\n * The navigation integration's options. With Sentry's default\n * (`ignoreEmptyBackNavigationTransactions: true`) a navigation to a route it\n * has seen before is dropped when nothing hangs under it — which is exactly a\n * switch back to a tab that is already mounted, so tab switches never showed up.\n */\nexport const NAVIGATION_OPTIONS = {\n ignoreEmptyBackNavigationTransactions: false,\n // `(tabs)/explore`, not `explore`: the route file, so two screens with one name stay apart.\n useFullPathsForNavigationRoutes: true,\n enableTimeToInitialDisplay: true,\n} as const\n\n/** Session Replay records shapes only: every text, image and vector is masked on the phone. Never unmask by default. */\nexport const REPLAY_OPTIONS = { maskAllText: true, maskAllImages: true, maskAllVectors: true } as const\n"],"mappings":";;;;;;;;AAGA,YAAY,YAAY;AACxB,OAAO,eAAe;AACtB,SAAS,iBAAqC;;;ACU9C,IAAM,UAAU,EAAE,KAAK,SAAS;AAIhC,IAAM,SAAS,CAA2C,MAAY;AACpE,QAAM,WAAW,SAAS,CAAC;AAC3B,WAAS,aAAa,EAAE,GAAG,SAAS,YAAY,GAAG,QAAQ;AAC3D,SAAO;AACT;AACA,IAAM,UAAU,CAA4C,MAAY;AACtE,QAAM,WAAW,UAAU,CAAC;AAC5B,WAAS,OAAO,EAAE,GAAG,SAAS,MAAM,GAAG,QAAQ;AAC/C,SAAO;AACT;AAEA,IAAM,WAAW,CAAC,MAAc,EAAE,QAAQ,uBAAuB,MAAM;AAGhE,SAAS,YAAY,MAA0B,SAA6B,OAA0C;AAC3H,SAAO,GAAG,QAAQ,KAAK,IAAI,WAAW,OAAO,GAAG,QAAQ,IAAI,KAAK,KAAK,EAAE;AAC1E;AAOO,SAAS,mBAAmB,KAA+C;AAChF,QAAM,aAAa,IAAI,gBAAgB;AACvC,QAAM,SAAS,IAAI,UAAU,QAAQ,QAAQ,EAAE;AAC/C,SAAO;AAAA,IACL,KAAK,IAAI;AAAA,IACT,aAAa,IAAI;AAAA,IACjB,SAAS,IAAI;AAAA;AAAA,IAEb,gBAAgB;AAAA,IAChB,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,CAAC,GAAG,aAAa,EAAE,EAAE;AAAA;AAAA,IAE/D,yBAAyB,CAAC,IAAI,OAAO,IAAI,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from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { c as AuthStatus, a as MobileAuth, e as Me } from '../../context-B_u-vpkw.js';
|
|
5
|
+
export { A as ApiError, U as Unauthenticated } from '../../context-B_u-vpkw.js';
|
|
6
|
+
|
|
7
|
+
type Route = unknown;
|
|
8
|
+
/**
|
|
9
|
+
* A `MobileAuth` whose `apiFetch` answers from `routes`: path → body, or a
|
|
10
|
+
* function of the request init. A missing route throws `ApiError(404)`; an
|
|
11
|
+
* `Error` value is thrown as is (use `new Unauthenticated()` for a 401).
|
|
12
|
+
*/
|
|
13
|
+
declare function mockApiFetch(routes?: Record<string, Route>): MobileAuth;
|
|
14
|
+
/** A signed-in user with no roles; override what the test needs. */
|
|
15
|
+
declare const testUser: (over?: Partial<Me>) => Me;
|
|
16
|
+
interface MockAuthProviderProps {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
/** Default: signed in as `testUser()`. */
|
|
19
|
+
status?: AuthStatus;
|
|
20
|
+
auth?: MobileAuth;
|
|
21
|
+
signIn?: (locale: string) => Promise<void>;
|
|
22
|
+
signOut?: () => Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
declare function MockAuthProvider({ children, status, auth, signIn, signOut }: MockAuthProviderProps): react.JSX.Element;
|
|
25
|
+
/** A query client for one test: no retries, nothing kept between tests. */
|
|
26
|
+
declare function createTestQueryClient(): QueryClient;
|
|
27
|
+
/** `MockAuthProvider` inside a fresh `QueryClientProvider`. */
|
|
28
|
+
declare function TestProviders({ children, client, ...auth }: MockAuthProviderProps & {
|
|
29
|
+
client?: QueryClient;
|
|
30
|
+
}): react.JSX.Element;
|
|
31
|
+
|
|
32
|
+
export { AuthStatus, Me, MobileAuth, MockAuthProvider, type MockAuthProviderProps, TestProviders, createTestQueryClient, mockApiFetch, testUser };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AuthContextProvider
|
|
3
|
+
} from "../../chunk-7XIDABOQ.js";
|
|
4
|
+
import {
|
|
5
|
+
ApiError,
|
|
6
|
+
Unauthenticated
|
|
7
|
+
} from "../../chunk-YXIYI7R2.js";
|
|
8
|
+
|
|
9
|
+
// src/expo/testing/index.tsx
|
|
10
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
11
|
+
import { jsx } from "react/jsx-runtime";
|
|
12
|
+
function mockApiFetch(routes = {}) {
|
|
13
|
+
return {
|
|
14
|
+
serverUrl: "https://app.test",
|
|
15
|
+
login: async () => ({ ok: true }),
|
|
16
|
+
logout: async () => void 0,
|
|
17
|
+
openPasswordReset: async () => void 0,
|
|
18
|
+
hasSession: async () => true,
|
|
19
|
+
apiFetch: async (path, init) => {
|
|
20
|
+
if (!(path in routes)) throw new ApiError(404, "not_found");
|
|
21
|
+
const route = routes[path];
|
|
22
|
+
const value = typeof route === "function" ? route(init) : route;
|
|
23
|
+
if (value instanceof Error) throw value;
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var testUser = (over = {}) => ({
|
|
29
|
+
sub: "user-1",
|
|
30
|
+
email: null,
|
|
31
|
+
name: "Test User",
|
|
32
|
+
organizationAlias: "acme",
|
|
33
|
+
roles: [],
|
|
34
|
+
permissions: [],
|
|
35
|
+
...over
|
|
36
|
+
});
|
|
37
|
+
var noop = async () => void 0;
|
|
38
|
+
function MockAuthProvider({ children, status = { state: "signedIn", me: testUser() }, auth, signIn, signOut }) {
|
|
39
|
+
const value = { status, auth: auth ?? mockApiFetch(), signIn: signIn ?? noop, signOut: signOut ?? noop, refresh: noop, expire: () => void 0 };
|
|
40
|
+
return /* @__PURE__ */ jsx(AuthContextProvider, { value, children });
|
|
41
|
+
}
|
|
42
|
+
function createTestQueryClient() {
|
|
43
|
+
return new QueryClient({ defaultOptions: { queries: { retry: false, gcTime: 0 }, mutations: { retry: false } } });
|
|
44
|
+
}
|
|
45
|
+
function TestProviders({ children, client, ...auth }) {
|
|
46
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, { client: client ?? createTestQueryClient(), children: /* @__PURE__ */ jsx(MockAuthProvider, { ...auth, children }) });
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
ApiError,
|
|
50
|
+
MockAuthProvider,
|
|
51
|
+
TestProviders,
|
|
52
|
+
Unauthenticated,
|
|
53
|
+
createTestQueryClient,
|
|
54
|
+
mockApiFetch,
|
|
55
|
+
testUser
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -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 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;AAsDxC;AAzCF,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,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":[]}
|
|
@@ -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>;
|