@marktiderman/genesis-native 0.10.1 → 0.12.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.
- package/README.md +11 -5
- package/dist/{block-CQz1pOnm.d.ts → block-DlGnjjps.d.ts} +1 -1
- package/dist/{blocks-dppiMmy-.d.ts → blocks-CF0agqxk.d.ts} +54 -4
- package/dist/{chunk-6BT4PTGH.js → chunk-5STOXRTS.js} +11 -4
- package/dist/chunk-5STOXRTS.js.map +1 -0
- package/dist/{chunk-65P7RU4V.js → chunk-M7S7F6L5.js} +2 -2
- package/dist/chunk-M7S7F6L5.js.map +1 -0
- package/dist/{chunk-EWHO5WQU.js → chunk-ZQVRCW5J.js} +20 -8
- package/dist/chunk-ZQVRCW5J.js.map +1 -0
- package/dist/devtools.d.ts +69 -6
- package/dist/devtools.js +48 -12
- package/dist/devtools.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -7
- package/dist/index.js.map +1 -1
- package/dist/observability.d.ts +12 -6
- package/dist/observability.js +2 -2
- package/dist/push.d.ts +3 -3
- package/dist/push.js +1 -1
- package/dist/push.js.map +1 -1
- package/dist/updates.d.ts +2 -2
- package/dist/updates.js +6 -6
- package/dist/updates.js.map +1 -1
- package/package.json +50 -8
- package/src/app.tsx +12 -6
- package/src/blocks.tsx +2 -2
- package/src/devtools/block.tsx +38 -9
- package/src/devtools/index.ts +3 -2
- package/src/devtools/settings.ts +50 -0
- package/src/devtools/slots.ts +15 -0
- package/src/observability/block.tsx +1 -1
- package/src/observability/index.ts +1 -1
- package/src/observability/scrub.ts +22 -4
- package/src/push/block.tsx +1 -1
- package/src/updates/block.tsx +7 -5
- package/src/updates/index.ts +1 -1
- package/src/updates/signature.ts +40 -2
- package/dist/chunk-65P7RU4V.js.map +0 -1
- package/dist/chunk-6BT4PTGH.js.map +0 -1
- package/dist/chunk-EWHO5WQU.js.map +0 -1
package/src/app.tsx
CHANGED
|
@@ -34,7 +34,7 @@ import { GenesisThemeProvider, useTheme } from "@marktiderman/genesis-design-sys
|
|
|
34
34
|
import { brandRoleVariables, type CanonicalBrand } from "@marktiderman/genesis-design-system";
|
|
35
35
|
import { GenesisProvider, createSupabaseProvider, type DataProvider, type SupabaseClientInput } from "@marktiderman/genesis-core/provider";
|
|
36
36
|
import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
|
|
37
|
-
import { KeyboardScrollProvider, type KeyboardScrollProps, type KeyboardToolbarProps } from "@marktiderman/genesis-ui-native/layouts";
|
|
37
|
+
import { KeyboardScrollProvider, type KeyboardScrollProps, type KeyboardStickyProps, type KeyboardToolbarProps } from "@marktiderman/genesis-ui-native/layouts";
|
|
38
38
|
import {
|
|
39
39
|
GenesisModulesProvider,
|
|
40
40
|
NativeSheetProvider,
|
|
@@ -62,7 +62,7 @@ import {
|
|
|
62
62
|
import { SessionProvider, createSessionStore, type AuthClientLike } from "./auth";
|
|
63
63
|
import { useHeldLink, type HeldLinkAuth, type LinkHold } from "./held-link";
|
|
64
64
|
import { connectQueryLifecycle, createNativeQueryClient, reportQueryErrors, type QueryLifecycleOptions, type QueryPersistence } from "./query";
|
|
65
|
-
import { resolveBlocks } from "@marktiderman/genesis-
|
|
65
|
+
import { resolveBlocks } from "@marktiderman/genesis-config/blocks";
|
|
66
66
|
import { BlocksProvider, reportToBlocks, type NativeBlock } from "./blocks";
|
|
67
67
|
import type { DevtoolsSlots } from "./devtools/slots";
|
|
68
68
|
// Types only: the block's code is in the `/updates` entry and arrives with the `updates` prop.
|
|
@@ -158,6 +158,11 @@ export interface GenesisNativeAppProps {
|
|
|
158
158
|
* (and so `keyboardProvider`); without them it is ignored.
|
|
159
159
|
*/
|
|
160
160
|
keyboardToolbar?: ComponentType<KeyboardToolbarProps>;
|
|
161
|
+
/**
|
|
162
|
+
* `KeyboardStickyView` from react-native-keyboard-controller: keeps FormPage's Save / Cancel
|
|
163
|
+
* bar above the keyboard. Needs `keyboardScroll`; without it, the bar ends the scrolling form.
|
|
164
|
+
*/
|
|
165
|
+
keyboardSticky?: ComponentType<KeyboardStickyProps>;
|
|
161
166
|
/**
|
|
162
167
|
* The optional native modules the app installed, for Genesis components to
|
|
163
168
|
* use (`GenesisModulesProvider` from `@marktiderman/genesis-ui-native`):
|
|
@@ -300,18 +305,18 @@ const MISSING_KEYBOARD_PROVIDER =
|
|
|
300
305
|
'Pass `keyboardProvider={KeyboardProvider}` from "react-native-keyboard-controller" too.';
|
|
301
306
|
|
|
302
307
|
const TOOLBAR_WITHOUT_SCROLL =
|
|
303
|
-
"GenesisNativeApp: `keyboardToolbar` was given without `keyboardScroll`, so it is ignored. " +
|
|
308
|
+
"GenesisNativeApp: `keyboardToolbar` or `keyboardSticky` was given without `keyboardScroll`, so it is ignored. " +
|
|
304
309
|
'Pass `keyboardScroll={KeyboardAwareScrollView}` and `keyboardProvider={KeyboardProvider}` from "react-native-keyboard-controller" too.';
|
|
305
310
|
|
|
306
311
|
function ThemedShell(props: GenesisNativeAppProps) {
|
|
307
|
-
const { brand, keyboardScroll, keyboardToolbar } = props;
|
|
312
|
+
const { brand, keyboardScroll, keyboardToolbar, keyboardSticky } = props;
|
|
308
313
|
// Frozen: a new component type here (an inline wrapper) would remount the shell and reset the app.
|
|
309
314
|
const [Keyboard] = useState(() => props.keyboardProvider);
|
|
310
315
|
// Frozen too: an inline object would hand every component a new module set each render.
|
|
311
316
|
const [modules] = useState(() => props.modules);
|
|
312
317
|
const [toast] = useState(() => (props.toast === null ? null : { position: "top" as const, ...props.toast }));
|
|
313
318
|
const missingProvider = Boolean(keyboardScroll) && !Keyboard;
|
|
314
|
-
const toolbarWithoutScroll = Boolean(keyboardToolbar) && !keyboardScroll;
|
|
319
|
+
const toolbarWithoutScroll = Boolean(keyboardToolbar || keyboardSticky) && !keyboardScroll;
|
|
315
320
|
useEffect(() => {
|
|
316
321
|
if (typeof __DEV__ === "undefined" || !__DEV__) return;
|
|
317
322
|
// genesis-allow-console: development-only set-up mistakes, shown as LogBox errors on purpose.
|
|
@@ -322,7 +327,7 @@ function ThemedShell(props: GenesisNativeAppProps) {
|
|
|
322
327
|
// Inside the modules: a toast animates with Reanimated and draws Liquid Glass when the app gave them.
|
|
323
328
|
if (toast) body = <NativeToastProvider {...toast}>{body}</NativeToastProvider>;
|
|
324
329
|
if (modules) body = <GenesisModulesProvider modules={modules}>{body}</GenesisModulesProvider>;
|
|
325
|
-
if (keyboardScroll) body = <KeyboardScrollProvider component={keyboardScroll} toolbar={keyboardToolbar}>{body}</KeyboardScrollProvider>;
|
|
330
|
+
if (keyboardScroll) body = <KeyboardScrollProvider component={keyboardScroll} toolbar={keyboardToolbar} sticky={keyboardSticky}>{body}</KeyboardScrollProvider>;
|
|
326
331
|
if (Keyboard) body = <Keyboard>{body}</Keyboard>;
|
|
327
332
|
if (modules?.navigation && props.navigationTheme !== false) {
|
|
328
333
|
body = (
|
|
@@ -615,6 +620,7 @@ const SLOT_NAMES: Record<keyof NativeAppSlots, true> = {
|
|
|
615
620
|
updateBanner: true,
|
|
616
621
|
whatsNew: true,
|
|
617
622
|
devtoolsFeedback: true,
|
|
623
|
+
devtoolsDiagnostics: true,
|
|
618
624
|
pushPrompt: true,
|
|
619
625
|
};
|
|
620
626
|
const NATIVE_APP_SLOT_NAMES: readonly string[] = Object.keys(SLOT_NAMES);
|
package/src/blocks.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Blocks on native: `defineBlock` declarations (from
|
|
3
|
-
* `@marktiderman/genesis-
|
|
3
|
+
* `@marktiderman/genesis-config/blocks`) with the two things only a native
|
|
4
4
|
* shell can run, boot steps behind the splash and a root around the screens.
|
|
5
5
|
* `<GenesisNativeApp blocks={[…]}>` resolves them once, runs their steps,
|
|
6
6
|
* mounts their roots, puts their slot fills under the app's own `slots`, and
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { createContext, useContext, type ComponentType, type ReactNode } from "react";
|
|
10
10
|
import type { SlotPropsFor, Slots } from "@marktiderman/genesis-core/slots";
|
|
11
|
-
import type { BlockDef, BlockSettingsRow, Contributed, ResolvedBlocks } from "@marktiderman/genesis-
|
|
11
|
+
import type { BlockDef, BlockSettingsRow, Contributed, ResolvedBlocks } from "@marktiderman/genesis-config/blocks";
|
|
12
12
|
import type { BootStep } from "./boot";
|
|
13
13
|
import type { ErrorReport } from "./errors";
|
|
14
14
|
import type { NativeAppSlots } from "./app";
|
package/src/devtools/block.tsx
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* - the server's base URL;
|
|
13
13
|
* - "Copy debug info", "Crash test", "Clear cache" and "Sign out";
|
|
14
14
|
* - the `devtoolsFeedback` slot, which the support block fills with
|
|
15
|
-
* "Send feedback"
|
|
15
|
+
* "Send feedback", and the `devtoolsDiagnostics` slot beside "Copy debug
|
|
16
|
+
* info", which it fills with "Send diagnostics" (the context dump).
|
|
16
17
|
*
|
|
17
18
|
* Keep it out of production bundles: import this entry only behind a
|
|
18
19
|
* condition Metro can fold at build time (see the README), and pass
|
|
@@ -20,12 +21,14 @@
|
|
|
20
21
|
* false the block mounts nothing and listens to nothing.
|
|
21
22
|
*/
|
|
22
23
|
import { useEffect, useMemo, useRef, useState, useSyncExternalStore, type ComponentType, type ReactNode } from "react";
|
|
24
|
+
import type { ResolvedSettings } from "@marktiderman/genesis-config/settings";
|
|
25
|
+
import { devtoolsSettingValues } from "./settings";
|
|
23
26
|
import { Alert, Modal, ScrollView, Share, View, type GestureResponderEvent } from "react-native";
|
|
24
27
|
import { useQueryClient } from "@tanstack/react-query";
|
|
25
28
|
import { renderSlot } from "@marktiderman/genesis-core/slots";
|
|
26
29
|
import { NativeButton, NativeInput, NativeText } from "@marktiderman/genesis-ui-native/components";
|
|
27
30
|
import { useThemeRoles } from "@marktiderman/genesis-ui-native/hooks";
|
|
28
|
-
import { defineBlock } from "@marktiderman/genesis-
|
|
31
|
+
import { defineBlock } from "@marktiderman/genesis-config/blocks";
|
|
29
32
|
import { useSession } from "../auth";
|
|
30
33
|
import { useBlocks, type NativeBlock, type NativeBlockRootProps } from "../blocks";
|
|
31
34
|
import { useRecentActivity, type ObservabilityBlock } from "../observability/block";
|
|
@@ -35,7 +38,7 @@ import type { ChannelSwitchResult } from "../updates/channels";
|
|
|
35
38
|
import { versionSignature, type VersionSignature } from "../updates/signature";
|
|
36
39
|
import { createHoldDetector, createShakeDetector, type AccelerometerLike } from "./gestures";
|
|
37
40
|
import { buildDebugInfo } from "./info";
|
|
38
|
-
import type { DevtoolsFeedbackProps } from "./slots";
|
|
41
|
+
import type { DevtoolsDiagnosticsProps, DevtoolsFeedbackProps } from "./slots";
|
|
39
42
|
|
|
40
43
|
/** The FeatureId of the devtools overlay. */
|
|
41
44
|
export const DEVTOOLS_BLOCK_ID = "devtools-overlay";
|
|
@@ -73,6 +76,13 @@ export interface DevtoolsOptions {
|
|
|
73
76
|
clearCache?: () => unknown;
|
|
74
77
|
/** Sign out (`supabase.auth.signOut()`). Without it, the action is hidden. */
|
|
75
78
|
signOut?: () => unknown;
|
|
79
|
+
/**
|
|
80
|
+
* Genesis settings (`resolveSettings`' result, or the values alone): `devtools.overlay` off
|
|
81
|
+
* mounts nothing (it never turns the overlay on: `enabled` does); `devtools.shakeToOpen`,
|
|
82
|
+
* `devtools.hold`, `devtools.flags` and `devtools.signOut` off take that part away. Without
|
|
83
|
+
* them, everything the options give.
|
|
84
|
+
*/
|
|
85
|
+
appSettings?: Pick<ResolvedSettings, "values"> | { readonly [key: string]: unknown } | null;
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
export interface DevtoolsState {
|
|
@@ -90,8 +100,17 @@ export interface DevtoolsBlock extends NativeBlock<typeof DEVTOOLS_BLOCK_ID> {
|
|
|
90
100
|
}
|
|
91
101
|
|
|
92
102
|
/** Build the overlay once, at module scope. @stability Beta */
|
|
93
|
-
export function createDevtools(
|
|
94
|
-
const
|
|
103
|
+
export function createDevtools(given: DevtoolsOptions): DevtoolsBlock {
|
|
104
|
+
const settings = devtoolsSettingValues(given.appSettings);
|
|
105
|
+
// The settings only take away: what they switch off is left out of the options everything reads.
|
|
106
|
+
const options: DevtoolsOptions = {
|
|
107
|
+
...given,
|
|
108
|
+
...(settings.shakeToOpen ? {} : { accelerometer: undefined }),
|
|
109
|
+
...(settings.hold ? {} : { hold: false as const }),
|
|
110
|
+
...(settings.flags ? {} : { flags: undefined }),
|
|
111
|
+
...(settings.signOut ? {} : { signOut: undefined }),
|
|
112
|
+
};
|
|
113
|
+
const enabled = given.enabled === true && settings.overlay;
|
|
95
114
|
let state: DevtoolsState = { open: false };
|
|
96
115
|
const listeners = new Set<() => void>();
|
|
97
116
|
const set = (next: DevtoolsState) => {
|
|
@@ -214,6 +233,8 @@ export function createDevtools(options: DevtoolsOptions): DevtoolsBlock {
|
|
|
214
233
|
block={block}
|
|
215
234
|
Feedback={slots?.devtoolsFeedback}
|
|
216
235
|
feedbackProps={slotProps?.devtoolsFeedback}
|
|
236
|
+
Diagnostics={slots?.devtoolsDiagnostics}
|
|
237
|
+
diagnosticsProps={slotProps?.devtoolsDiagnostics}
|
|
217
238
|
onCrash={() => {
|
|
218
239
|
set({ open: false });
|
|
219
240
|
setCrash(true);
|
|
@@ -241,6 +262,10 @@ function NoFeedback(_props: DevtoolsFeedbackProps) {
|
|
|
241
262
|
return null;
|
|
242
263
|
}
|
|
243
264
|
|
|
265
|
+
function NoDiagnostics(_props: DevtoolsDiagnosticsProps) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
|
|
244
269
|
function useSignature(options: DevtoolsOptions): VersionSignature | null {
|
|
245
270
|
const updates = options.updates;
|
|
246
271
|
const [requested, setRequested] = useState<string | null>(null);
|
|
@@ -255,8 +280,8 @@ function useSignature(options: DevtoolsOptions): VersionSignature | null {
|
|
|
255
280
|
return useMemo(() => {
|
|
256
281
|
if (!updates) return options.signature ?? null;
|
|
257
282
|
if (!requested) return updates.signature;
|
|
258
|
-
const { application, updates: modules, platform } = updates.options;
|
|
259
|
-
return versionSignature({ application, updates: modules, platform, requestedChannel: requested });
|
|
283
|
+
const { application, updates: modules, platform, buildMetadata } = updates.options;
|
|
284
|
+
return versionSignature({ application, updates: modules, platform, requestedChannel: requested, buildMetadata: buildMetadata ?? null });
|
|
260
285
|
}, [updates, requested, options.signature]);
|
|
261
286
|
}
|
|
262
287
|
|
|
@@ -276,6 +301,8 @@ interface SheetProps {
|
|
|
276
301
|
block: DevtoolsBlock;
|
|
277
302
|
Feedback: ComponentType<DevtoolsFeedbackProps> | null | undefined;
|
|
278
303
|
feedbackProps: Partial<DevtoolsFeedbackProps> | undefined;
|
|
304
|
+
Diagnostics: ComponentType<DevtoolsDiagnosticsProps> | null | undefined;
|
|
305
|
+
diagnosticsProps: Partial<DevtoolsDiagnosticsProps> | undefined;
|
|
279
306
|
onCrash: () => void;
|
|
280
307
|
}
|
|
281
308
|
|
|
@@ -304,7 +331,7 @@ function Section({ title, children }: { title: string; children: ReactNode }) {
|
|
|
304
331
|
);
|
|
305
332
|
}
|
|
306
333
|
|
|
307
|
-
function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, onCrash }: SheetProps) {
|
|
334
|
+
function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, Diagnostics, diagnosticsProps, onCrash }: SheetProps) {
|
|
308
335
|
const { options } = block;
|
|
309
336
|
const roles = useThemeRoles();
|
|
310
337
|
const { userId } = useSession();
|
|
@@ -329,7 +356,8 @@ function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, o
|
|
|
329
356
|
);
|
|
330
357
|
};
|
|
331
358
|
|
|
332
|
-
const
|
|
359
|
+
const copyText = (text: string) => (options.copy ? options.copy(text) : Share.share({ message: text }));
|
|
360
|
+
const copy = () => run("Copy debug info", () => copyText(info()));
|
|
333
361
|
const clearCache = () =>
|
|
334
362
|
run("Clear cache", async () => {
|
|
335
363
|
queryClient.clear();
|
|
@@ -458,6 +486,7 @@ function DevtoolsSheet({ visible, onDismissed, block, Feedback, feedbackProps, o
|
|
|
458
486
|
<NativeButton size="sm" variant="outline" onPress={copy} testID="genesis-devtools-copy">
|
|
459
487
|
Copy debug info
|
|
460
488
|
</NativeButton>
|
|
489
|
+
{renderSlot(NoDiagnostics, Diagnostics, { debugInfo: info(), close, copy: copyText }, diagnosticsProps)}
|
|
461
490
|
{renderSlot(NoFeedback, Feedback, { debugInfo: info(), close }, feedbackProps)}
|
|
462
491
|
<NativeButton size="sm" variant="outline" onPress={clearCache} testID="genesis-devtools-clear-cache">
|
|
463
492
|
Clear cache
|
package/src/devtools/index.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* Rung 1: `<GenesisNativeApp blocks={[devtools]}>`. Rung 2: the
|
|
14
|
-
* `devtoolsFeedback`
|
|
14
|
+
* `devtoolsFeedback` and `devtoolsDiagnostics` slots. Rung 3: `createHoldDetector`,
|
|
15
15
|
* `createShakeDetector`, `buildDebugInfo`.
|
|
16
16
|
*
|
|
17
17
|
* @stability Beta
|
|
@@ -19,4 +19,5 @@
|
|
|
19
19
|
export { createDevtools, DEVTOOLS_BLOCK_ID, type DevSettingsLike, type DevtoolsBlock, type DevtoolsOptions, type DevtoolsState } from "./block";
|
|
20
20
|
export { createHoldDetector, createShakeDetector, type AccelerometerLike, type HoldDetector, type HoldDetectorOptions, type ShakeDetector, type ShakeDetectorOptions } from "./gestures";
|
|
21
21
|
export { buildDebugInfo, type DebugInfoInput } from "./info";
|
|
22
|
-
export type { DevtoolsFeedbackProps, DevtoolsSlots } from "./slots";
|
|
22
|
+
export type { DevtoolsDiagnosticsProps, DevtoolsFeedbackProps, DevtoolsSlots } from "./slots";
|
|
23
|
+
export { DEVTOOLS_SETTING_SPECS, devtoolsSettings, devtoolsSettingValues, type DevtoolsSettingValues } from "./settings";
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The devtools overlay's settings (`devtools.*`), declared with genesis-config. The same
|
|
3
|
+
* declaration is in this package's package.json (`genesis.settings`) for the CLI's doctor; a test
|
|
4
|
+
* keeps the two the same.
|
|
5
|
+
*
|
|
6
|
+
* A setting can only take things away: `devtools.overlay` off hides the overlay, but nothing here
|
|
7
|
+
* turns it on in a production build (`createDevtools({ enabled })` stays a fact of the binary).
|
|
8
|
+
*
|
|
9
|
+
* @stability Beta
|
|
10
|
+
*/
|
|
11
|
+
import { defineSettings, settingValueProblem, type ResolvedSettings, type SettingSpec } from "@marktiderman/genesis-config/settings";
|
|
12
|
+
|
|
13
|
+
/** `devtools.*`, as declared. @stability Beta */
|
|
14
|
+
export const DEVTOOLS_SETTING_SPECS = {
|
|
15
|
+
overlay: { type: "boolean", default: true, summary: "The Development overlay in development and preview builds. Off hides it; no setting turns it on in a production build." },
|
|
16
|
+
shakeToOpen: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Shake to open the overlay (development and preview builds)." },
|
|
17
|
+
hold: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "A three-finger hold opens the overlay." },
|
|
18
|
+
flags: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Show the app's switches and flags in the overlay." },
|
|
19
|
+
signOut: { type: "boolean", default: true, requires: ["devtools.overlay"], summary: "Offer Sign out in the overlay." },
|
|
20
|
+
} as const satisfies Record<string, SettingSpec>;
|
|
21
|
+
|
|
22
|
+
/** @stability Beta */
|
|
23
|
+
export const devtoolsSettings = defineSettings("devtools", DEVTOOLS_SETTING_SPECS);
|
|
24
|
+
|
|
25
|
+
/** The devtools overlay's settings, typed. @stability Beta */
|
|
26
|
+
export interface DevtoolsSettingValues {
|
|
27
|
+
overlay: boolean;
|
|
28
|
+
shakeToOpen: boolean;
|
|
29
|
+
hold: boolean;
|
|
30
|
+
flags: boolean;
|
|
31
|
+
signOut: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The overlay's settings from `resolveSettings`' result (or the values alone, by full key). A key
|
|
36
|
+
* that's missing, or whose value doesn't fit, takes its default (every one on).
|
|
37
|
+
*
|
|
38
|
+
* @stability Beta
|
|
39
|
+
*/
|
|
40
|
+
export function devtoolsSettingValues(input?: Pick<ResolvedSettings, "values"> | { readonly [key: string]: unknown } | null): DevtoolsSettingValues {
|
|
41
|
+
const raw = (input ?? {}) as { readonly [key: string]: unknown };
|
|
42
|
+
const nested = Object.prototype.hasOwnProperty.call(raw, "values") ? raw.values : undefined;
|
|
43
|
+
const values = (typeof nested === "object" && nested !== null && !Array.isArray(nested) ? nested : raw) as { readonly [key: string]: unknown };
|
|
44
|
+
const out: Record<string, unknown> = {};
|
|
45
|
+
for (const def of Object.values(devtoolsSettings.keys)) {
|
|
46
|
+
const v = Object.prototype.hasOwnProperty.call(values, def.key) ? values[def.key] : undefined;
|
|
47
|
+
out[def.key.slice("devtools.".length)] = v !== undefined && settingValueProblem(def, v) === null ? v : def.defaults.max;
|
|
48
|
+
}
|
|
49
|
+
return out as unknown as DevtoolsSettingValues;
|
|
50
|
+
}
|
package/src/devtools/slots.ts
CHANGED
|
@@ -14,8 +14,23 @@ export interface DevtoolsFeedbackProps {
|
|
|
14
14
|
close: () => Promise<void> | void;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
/** What the `devtoolsDiagnostics` slot is given: the support block's "Send diagnostics" fills it. */
|
|
18
|
+
export interface DevtoolsDiagnosticsProps {
|
|
19
|
+
/** The overlay's debug report, as text (what "Copy debug info" copies). */
|
|
20
|
+
debugInfo: string;
|
|
21
|
+
/** Closes the overlay. */
|
|
22
|
+
close: () => Promise<void> | void;
|
|
23
|
+
/** Copies text, as the overlay's own "Copy debug info" does (the app's `copy` option, or the share sheet). */
|
|
24
|
+
copy: (text: string) => unknown;
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
// A type, not an interface, so it fits the slots contract's Record constraint.
|
|
18
28
|
export type DevtoolsSlots = {
|
|
19
29
|
/** A "send feedback" action in the devtools overlay. Default nothing; the support block fills it. */
|
|
20
30
|
devtoolsFeedback: DevtoolsFeedbackProps;
|
|
31
|
+
/**
|
|
32
|
+
* A "Send diagnostics" action beside "Copy debug info": sends the context dump and shows its
|
|
33
|
+
* short id. Default nothing; the support block fills it when it has `diagnostics`.
|
|
34
|
+
*/
|
|
35
|
+
devtoolsDiagnostics: DevtoolsDiagnosticsProps;
|
|
21
36
|
};
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* (`recent`).
|
|
28
28
|
*/
|
|
29
29
|
import { createContext, useContext, useEffect, useRef, useSyncExternalStore, type ComponentType, type ReactNode } from "react";
|
|
30
|
-
import { defineBlock } from "@marktiderman/genesis-
|
|
30
|
+
import { defineBlock } from "@marktiderman/genesis-config/blocks";
|
|
31
31
|
import { setErrorReporter } from "@marktiderman/genesis-core/errors";
|
|
32
32
|
import { useSession } from "../auth";
|
|
33
33
|
import { onBeforeReload } from "../reload";
|
|
@@ -43,4 +43,4 @@ export {
|
|
|
43
43
|
export { sentrySink, sentryRelease, signatureTags, type SentryLike, type SentrySinkOptions } from "./sentry";
|
|
44
44
|
export { defineEvents, checkEvent, type EventCheck, type EventPropSpec, type EventProps, type EventSchema, type EventValues } from "./events";
|
|
45
45
|
export { ScreenErrorScreen, createScreenErrorBoundary, type ScreenErrorProps } from "../screen-boundary";
|
|
46
|
-
export { FILTERED, isSecretKey, scrubEvent, scrubRecord, scrubString, scrubUrl, scrubValue, type ScrubbableEvent } from "./scrub";
|
|
46
|
+
export { FILTERED, isSecretKey, scrubEvent, scrubRecord, scrubString, scrubUrl, scrubValue, scrubValueStrict, type ScrubbableEvent } from "./scrub";
|
|
@@ -69,6 +69,15 @@ const PATTERNS: readonly [RegExp, string][] = [
|
|
|
69
69
|
// Phone numbers: international (`+1 555 555 0101`) and North American (`555-555-0101`).
|
|
70
70
|
[/\+\d[\d\s().-]{6,18}\d/g, "[phone]"],
|
|
71
71
|
[/\b\(?\d{3}\)?[-.\s]\d{3}[-.\s]\d{4}\b/g, "[phone]"],
|
|
72
|
+
// …national numbers in space-separated groups, which start with a trunk 0 (`020 7946 0958`), and
|
|
73
|
+
// international ones without the + (`44 20 7946 0958`: a country code, then two groups of 4).
|
|
74
|
+
// Plain counts, durations and dates (`120 340 560`, `2024 11 19`) don't have either shape.
|
|
75
|
+
[/\b0\d{2,4} \d{3,4} \d{3,4}\b/g, "[phone]"],
|
|
76
|
+
[/\b\d{2,3} \d{1,4} \d{4} \d{4}\b/g, "[phone]"],
|
|
77
|
+
// …and North American numbers with no separator (`5555550101`, `15555550101`): an area code and an
|
|
78
|
+
// exchange that start with 2-9. A whole word only, so a hex id, a longer number or an epoch
|
|
79
|
+
// time (which starts with 1) is left alone.
|
|
80
|
+
[/\b1?[2-9]\d{2}[2-9]\d{6}\b/g, "[phone]"],
|
|
72
81
|
// Long opaque hex runs: API keys, refresh tokens, DSN secrets. Linear: a run starts only after a non-hex character.
|
|
73
82
|
[/(^|[^A-Fa-f0-9])[A-Fa-f0-9]{32,}(?![A-Fa-f0-9])/g, "$1[hex]"],
|
|
74
83
|
];
|
|
@@ -96,10 +105,10 @@ const MAX_DEPTH = 8;
|
|
|
96
105
|
* `"[Truncated]"`. Errors become `{ name, message }`. Header lists
|
|
97
106
|
* (`[["authorization", "…"]]`) are treated like objects.
|
|
98
107
|
*/
|
|
99
|
-
export function scrubValue(value: unknown, key = "", depth = 0, seen: WeakSet<object> = new WeakSet()): unknown {
|
|
108
|
+
export function scrubValue(value: unknown, key = "", depth = 0, seen: WeakSet<object> = new WeakSet(), keepIds = true): unknown {
|
|
100
109
|
if (key && isSecretKey(key)) return value === undefined || value === null || value === "" ? value : FILTERED;
|
|
101
110
|
if (typeof value === "string") {
|
|
102
|
-
if (key && ID_KEY.test(key)) return value;
|
|
111
|
+
if (keepIds && key && ID_KEY.test(key)) return value;
|
|
103
112
|
return URL_KEY.test(key) ? scrubUrl(value) : scrubString(value);
|
|
104
113
|
}
|
|
105
114
|
if (value === null || typeof value !== "object") return value;
|
|
@@ -110,16 +119,25 @@ export function scrubValue(value: unknown, key = "", depth = 0, seen: WeakSet<ob
|
|
|
110
119
|
if (Array.isArray(value)) {
|
|
111
120
|
// A `[name, value]` pair (fetch's header lists): the name decides, as for an object key.
|
|
112
121
|
if (value.length === 2 && typeof value[0] === "string" && isSecretKey(value[0])) return [value[0], FILTERED];
|
|
113
|
-
return value.map((item) => scrubValue(item, "", depth + 1, seen));
|
|
122
|
+
return value.map((item) => scrubValue(item, "", depth + 1, seen, keepIds));
|
|
114
123
|
}
|
|
115
124
|
const out: Record<string, unknown> = {};
|
|
116
125
|
for (const [k, v] of Object.entries(value)) {
|
|
117
126
|
if (DROPPED_KEY.test(k)) continue;
|
|
118
|
-
out[k] = scrubValue(v, k, depth + 1, seen);
|
|
127
|
+
out[k] = scrubValue(v, k, depth + 1, seen, keepIds);
|
|
119
128
|
}
|
|
120
129
|
return out;
|
|
121
130
|
}
|
|
122
131
|
|
|
132
|
+
/**
|
|
133
|
+
* `scrubValue` without the pass for Sentry's own id fields (`release`, `environment`,
|
|
134
|
+
* `event_id`, …): for data that isn't a Sentry envelope (a support dump, an app's own
|
|
135
|
+
* object), where a key named like one can hold anything.
|
|
136
|
+
*/
|
|
137
|
+
export function scrubValueStrict(value: unknown): unknown {
|
|
138
|
+
return scrubValue(value, "", 0, new WeakSet(), false);
|
|
139
|
+
}
|
|
140
|
+
|
|
123
141
|
/** The fields of a Sentry-shaped event `scrubEvent` treats specially. Anything else is scrubbed by value. */
|
|
124
142
|
export interface ScrubbableEvent {
|
|
125
143
|
user?: { id?: unknown; [key: string]: unknown } | null;
|
package/src/push/block.tsx
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { createContext, useContext, useEffect, useRef, useSyncExternalStore, type ComponentType, type ReactNode } from "react";
|
|
24
24
|
import { View } from "react-native";
|
|
25
25
|
import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
|
|
26
|
-
import { defineBlock } from "@marktiderman/genesis-
|
|
26
|
+
import { defineBlock } from "@marktiderman/genesis-config/blocks";
|
|
27
27
|
import { useSession } from "../auth";
|
|
28
28
|
import type { NativeBlock, NativeBlockRootProps } from "../blocks";
|
|
29
29
|
import type { BootStep } from "../boot";
|
package/src/updates/block.tsx
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
import { createContext, useContext, useEffect, useMemo, useState, useSyncExternalStore, type ComponentType, type ReactNode } from "react";
|
|
22
22
|
import { View } from "react-native";
|
|
23
23
|
import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
|
|
24
|
-
import { defineBlock } from "@marktiderman/genesis-
|
|
24
|
+
import { defineBlock } from "@marktiderman/genesis-config/blocks";
|
|
25
25
|
import type { NativeBlock } from "../blocks";
|
|
26
26
|
import { createUpdateChecker, createReloadGuard, type ReloadGuard, type UpdateChecker, type UpdateCheckState } from "./checker";
|
|
27
27
|
import { createChannelSwitcher, type ChannelSwitcher } from "./channels";
|
|
@@ -37,7 +37,7 @@ import {
|
|
|
37
37
|
type UpdatePolicySource,
|
|
38
38
|
type UpdateVerdict,
|
|
39
39
|
} from "./policy";
|
|
40
|
-
import { versionSignature, type VersionSignature } from "./signature";
|
|
40
|
+
import { versionSignature, type BuildMetadata, type VersionSignature } from "./signature";
|
|
41
41
|
import { createWhatsNewStore, type WhatsNewState, type WhatsNewStore } from "./whats-new";
|
|
42
42
|
import {
|
|
43
43
|
ForceUpgradeScreen,
|
|
@@ -70,6 +70,8 @@ export interface UpdatesOptions {
|
|
|
70
70
|
application?: ApplicationLike;
|
|
71
71
|
/** `expo-updates`. Without it (or with updates off), no banner and no channel switching. */
|
|
72
72
|
updates?: UpdatesModuleLike;
|
|
73
|
+
/** The commit, OTA number and release the app stamped at publish time: shown in the signature. */
|
|
74
|
+
buildMetadata?: BuildMetadata | null;
|
|
73
75
|
/** Min versions, maintenance and notes. Without it, only `notes` and the banner. */
|
|
74
76
|
policy?: UpdatePolicySource;
|
|
75
77
|
/** AsyncStorage: the policy cache, the version whose notes were seen, the picked channel. */
|
|
@@ -176,7 +178,7 @@ export function createUpdates(options: UpdatesOptions): UpdatesBlock {
|
|
|
176
178
|
reloadScreenOptions,
|
|
177
179
|
onError,
|
|
178
180
|
});
|
|
179
|
-
const signature = versionSignature({ application, updates, platform });
|
|
181
|
+
const signature = versionSignature({ application, updates, platform, buildMetadata: options.buildMetadata ?? null });
|
|
180
182
|
|
|
181
183
|
const allNotes = (): ReleaseNote[] => [...(options.notes ?? []), ...(policy.getState().policy?.notes ?? [])];
|
|
182
184
|
const syncNotes = () => {
|
|
@@ -380,8 +382,8 @@ function useVersionSignatureOf(block: UpdatesBlock): VersionSignature {
|
|
|
380
382
|
}, [block]);
|
|
381
383
|
return useMemo(() => {
|
|
382
384
|
if (!requested) return block.signature;
|
|
383
|
-
const { application, updates, platform } = block.options;
|
|
384
|
-
return versionSignature({ application, updates, platform, requestedChannel: requested });
|
|
385
|
+
const { application, updates, platform, buildMetadata } = block.options;
|
|
386
|
+
return versionSignature({ application, updates, platform, requestedChannel: requested, buildMetadata: buildMetadata ?? null });
|
|
385
387
|
}, [block, requested]);
|
|
386
388
|
}
|
|
387
389
|
|
package/src/updates/index.ts
CHANGED
|
@@ -74,7 +74,7 @@ export {
|
|
|
74
74
|
type UpdateCheckStatus,
|
|
75
75
|
} from "./checker";
|
|
76
76
|
export { createWhatsNewStore, notesSince, type WhatsNewOptions, type WhatsNewState, type WhatsNewStore } from "./whats-new";
|
|
77
|
-
export { versionSignature, type VersionSignature, type VersionSignatureInput } from "./signature";
|
|
77
|
+
export { versionSignature, type BuildMetadata, type VersionSignature, type VersionSignatureInput } from "./signature";
|
|
78
78
|
export { createChannelSwitcher, type ChannelSwitcher, type ChannelSwitcherOptions, type ChannelSwitchResult } from "./channels";
|
|
79
79
|
export { compareVersions, isBelowMinimum, parseVersion } from "./version";
|
|
80
80
|
export type {
|
package/src/updates/signature.ts
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
* (an empty string counts as not given: expo-updates gives `""` for the
|
|
11
11
|
* runtime version in a development build); one that doesn't apply, with
|
|
12
12
|
* updates off, as `none`.
|
|
13
|
+
*
|
|
14
|
+
* With `buildMetadata` (a module the app writes at publish time: the commit,
|
|
15
|
+
* the OTA number, the release), the signature also carries `commit`,
|
|
16
|
+
* `otaNumber` and `release`, and the text names them. Without it they are
|
|
17
|
+
* null and the text is as before.
|
|
13
18
|
*/
|
|
14
19
|
import type { ApplicationLike, UpdatesModuleLike } from "./modules";
|
|
15
20
|
|
|
@@ -27,18 +32,43 @@ export interface VersionSignature {
|
|
|
27
32
|
launch: "update" | "embedded" | "off";
|
|
28
33
|
/** expo-updates fell back to the embedded code after a failed launch. */
|
|
29
34
|
emergency: boolean;
|
|
35
|
+
/** The commit the bundle was built from (`buildMetadata`), or null. Optional for signatures made by hand. */
|
|
36
|
+
commit?: string | null;
|
|
37
|
+
/** The OTA number (`buildMetadata`), or null. */
|
|
38
|
+
otaNumber?: string | null;
|
|
39
|
+
/** The release's name (`buildMetadata`), or null. */
|
|
40
|
+
release?: string | null;
|
|
30
41
|
/** One line, for an About row. */
|
|
31
42
|
short: string;
|
|
32
43
|
/** Several lines, for a support report. */
|
|
33
44
|
text: string;
|
|
34
45
|
}
|
|
35
46
|
|
|
47
|
+
/**
|
|
48
|
+
* What the app stamps into its bundle when it publishes (a generated `build-metadata.ts` or JSON):
|
|
49
|
+
* every field optional.
|
|
50
|
+
*/
|
|
51
|
+
export interface BuildMetadata {
|
|
52
|
+
/** The commit the bundle was built from, full or short. */
|
|
53
|
+
commit?: string | null;
|
|
54
|
+
commitMessage?: string | null;
|
|
55
|
+
branch?: string | null;
|
|
56
|
+
/** The over-the-air update's number on its channel. */
|
|
57
|
+
otaNumber?: string | number | null;
|
|
58
|
+
/** The release's name (a tag, a date, a version). */
|
|
59
|
+
release?: string | null;
|
|
60
|
+
/** When the release or update was published, ISO. */
|
|
61
|
+
publishedAt?: string | null;
|
|
62
|
+
}
|
|
63
|
+
|
|
36
64
|
export interface VersionSignatureInput {
|
|
37
65
|
application?: ApplicationLike;
|
|
38
66
|
updates?: UpdatesModuleLike;
|
|
39
67
|
/** `Platform.OS`. */
|
|
40
68
|
platform: string;
|
|
41
69
|
requestedChannel?: string | null;
|
|
70
|
+
/** The commit, OTA number and release the app stamped at publish time. */
|
|
71
|
+
buildMetadata?: BuildMetadata | null;
|
|
42
72
|
}
|
|
43
73
|
|
|
44
74
|
const UNKNOWN = "unknown";
|
|
@@ -46,7 +76,9 @@ const UNKNOWN = "unknown";
|
|
|
46
76
|
/** A module's value, or null when it gave none (undefined, null or an empty string). */
|
|
47
77
|
const given = (value: string | null | undefined): string | null => (typeof value === "string" && value.trim() !== "" ? value : null);
|
|
48
78
|
|
|
49
|
-
|
|
79
|
+
const metaText = (value: string | number | null | undefined): string | null => (typeof value === "number" && Number.isFinite(value) ? String(value) : given(typeof value === "string" ? value : null));
|
|
80
|
+
|
|
81
|
+
export function versionSignature({ application, updates, platform, requestedChannel = null, buildMetadata = null }: VersionSignatureInput): VersionSignature {
|
|
50
82
|
const version = given(application?.nativeApplicationVersion);
|
|
51
83
|
const build = given(application?.nativeBuildVersion);
|
|
52
84
|
const on = Boolean(updates?.isEnabled);
|
|
@@ -76,5 +108,11 @@ export function versionSignature({ application, updates, platform, requestedChan
|
|
|
76
108
|
`Update ${launch === "off" ? "updates off" : launch === "embedded" ? "embedded" : (updateId ?? UNKNOWN)}`,
|
|
77
109
|
];
|
|
78
110
|
if (emergency) lines.push(`Emergency launch: ${updates?.emergencyLaunchReason ?? UNKNOWN}`);
|
|
79
|
-
|
|
111
|
+
const commit = metaText(buildMetadata?.commit);
|
|
112
|
+
const otaNumber = metaText(buildMetadata?.otaNumber);
|
|
113
|
+
const release = metaText(buildMetadata?.release);
|
|
114
|
+
if (commit) lines.push(`Commit ${commit}`);
|
|
115
|
+
if (otaNumber) lines.push(`OTA ${otaNumber}`);
|
|
116
|
+
if (release) lines.push(`Release ${release}`);
|
|
117
|
+
return { version, build, platform, channel, requestedChannel, runtimeVersion, updateId, launch, emergency, commit, otaNumber, release, short, text: lines.join("\n") };
|
|
80
118
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/blocks.tsx"],"names":[],"mappings":";;;AA0CO,SAAS,cAAA,CAAe,MAAA,EAAgC,KAAA,EAAc,MAAA,EAA2B;AACtG,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,IAAI,CAAC,MAAM,OAAA,EAAS;AACpB,IAAA,IAAI;AACF,MAAA,KAAA,CAAM,OAAA,CAAQ,OAAO,MAAM,CAAA;AAAA,IAC7B,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF;AACF;AAEA,IAAM,aAAA,GAAgB,cAAkD,IAAI,CAAA;AAGrE,IAAM,iBAAiB,aAAA,CAAc;AAQrC,SAAS,SAAA,GAAyC;AACvD,EAAA,MAAM,MAAA,GAAS,WAAW,aAAa,CAAA;AACvC,EAAA,IAAI,CAAC,MAAA,EAAQ,MAAM,IAAI,MAAM,yDAAyD,CAAA;AACtF,EAAA,OAAO,MAAA;AACT;AAuCO,SAAS,gBAAA,CACd,QAAA,EACA,OAAA,GAAmC,EAAC,EACS;AAC7C,EAAA,MAAM,MAAA,GAAS,WAAW,aAAa,CAAA;AACvC,EAAA,MAAM,IAAA,GAAO,MAAA,EAAQ,QAAA,IAAY,EAAC;AAElC,EAAA,MAAM,YAAY,IAAA,CAAK,GAAA,CAAI,CAAC,GAAA,KAAQ,GAAA,CAAI,eAAe,CAAA;AACvD,EAAA,OAAO,kBAAA,CAAmB,QAAA,EAAU,IAAA,EAAM,SAAA,EAAW,OAAO,CAAA;AAC9D;AAGO,SAAS,kBAAA,CACd,UACA,IAAA,EACA,SAAA,GAAoD,EAAC,EACrD,OAAA,GAAmC,EAAC,EACS;AAC7C,EAAA,MAAM,GAAA,GAAmD,QAAA,CAAS,GAAA,CAAI,CAAC,OAAO,EAAE,GAAG,CAAA,EAAG,IAAA,EAAM,CAAC,GAAG,CAAA,CAAE,IAAI,GAAE,CAAE,CAAA;AAC1G,EAAA,IAAA,CAAK,OAAA,CAAQ,CAAC,GAAA,EAAK,CAAA,KAAM;AACvB,IAAA,IAAI,OAAA,GAAU,IAAI,IAAA,CAAK,CAAC,MAAM,CAAA,CAAE,EAAA,KAAO,IAAI,OAAO,CAAA;AAClD,IAAA,IAAI,CAAC,OAAA,EAAS;AACZ,MAAA,OAAA,GAAU,EAAE,EAAA,EAAI,GAAA,CAAI,OAAA,EAAS,OAAO,OAAA,CAAQ,aAAA,GAAgB,GAAA,CAAI,OAAO,CAAA,IAAK,GAAA,CAAI,OAAA,EAAS,IAAA,EAAM,EAAC,EAAE;AAClG,MAAA,GAAA,CAAI,KAAK,OAAO,CAAA;AAAA,IAClB;AACA,IAAA,MAAM,EAAE,UAAS,GAAI,OAAA;AACrB,IAAA,MAAM,OAAO,GAAA,CAAI,IAAA;AACjB,IAAA,OAAA,CAAQ,KAAK,IAAA,CAAK;AAAA,MAChB,IAAI,GAAA,CAAI,EAAA;AAAA,MACR,OAAO,GAAA,CAAI,KAAA;AAAA,MACX,QAAA,EAAU,SAAA,CAAU,CAAC,CAAA,IAAK,GAAA,CAAI,QAAA;AAAA,MAC9B,QAAQ,GAAA,CAAI,MAAA;AAAA,MACZ,GAAI,IAAA,IAAQ,QAAA,GAAW,EAAE,WAAA,EAAa,IAAA,EAAM,OAAA,EAAS,MAAM,QAAA,CAAS,IAAI,CAAA,EAAE,GAAI;AAAC,KAChF,CAAA;AAAA,EACH,CAAC,CAAA;AACD,EAAA,OAAO,GAAA;AACT","file":"chunk-65P7RU4V.js","sourcesContent":["/**\n * Blocks on native: `defineBlock` declarations (from\n * `@marktiderman/genesis-features/blocks`) with the two things only a native\n * shell can run, boot steps behind the splash and a root around the screens.\n * `<GenesisNativeApp blocks={[…]}>` resolves them once, runs their steps,\n * mounts their roots, puts their slot fills under the app's own `slots`, and\n * hands their Settings rows to `useBlockSettings`.\n */\nimport { createContext, useContext, type ComponentType, type ReactNode } from \"react\";\nimport type { SlotPropsFor, Slots } from \"@marktiderman/genesis-core/slots\";\nimport type { BlockDef, BlockSettingsRow, Contributed, ResolvedBlocks } from \"@marktiderman/genesis-features/blocks\";\nimport type { BootStep } from \"./boot\";\nimport type { ErrorReport } from \"./errors\";\nimport type { NativeAppSlots } from \"./app\";\n\n/** What a block's `Root` is given: the app's slots, with every block's fills merged under them. @stability Beta */\nexport interface NativeBlockRootProps {\n slots?: Slots<NativeAppSlots>;\n slotProps?: SlotPropsFor<NativeAppSlots>;\n children?: ReactNode;\n}\n\n/**\n * A block a native shell can run. `contributes.slots` fills `GenesisNativeApp`\n * slots by name (the app's own `slots` win).\n *\n * @stability Beta\n */\nexport interface NativeBlock<Id extends string = string> extends BlockDef<Id, ComponentType<never>> {\n /** Run behind the splash after the app's own `steps`, before the session. A step that fails fails the boot, so keep them bounded. */\n readonly bootSteps?: readonly BootStep[];\n /** Mounted around the screens, inside the shell's error boundary. The first block's root is the outermost. */\n readonly Root?: ComponentType<NativeBlockRootProps>;\n /**\n * Every error the shell catches (render, global, boot, rejection), before\n * the app's own `onError`. The observability block reports them here. A\n * throw is ignored.\n */\n readonly onError?: (error: Error, report: ErrorReport) => void;\n}\n\n/** @internal Hand an error to each block's `onError`; one that throws never stops the rest. */\nexport function reportToBlocks(blocks: readonly NativeBlock[], error: Error, report: ErrorReport): void {\n for (const block of blocks) {\n if (!block.onError) continue;\n try {\n block.onError(error, report);\n } catch {\n // A failing reporter must not take the error path down with it.\n }\n }\n}\n\nconst BlocksContext = createContext<ResolvedBlocks<NativeBlock> | null>(null);\n\n/** @internal Provided by GenesisNativeApp. */\nexport const BlocksProvider = BlocksContext.Provider;\n\n/**\n * The resolved blocks: their ids, nav entries, Settings rows, routes and the\n * rest, each tagged with its FeatureId. Throws outside `GenesisNativeApp`.\n *\n * @stability Beta\n */\nexport function useBlocks(): ResolvedBlocks<NativeBlock> {\n const blocks = useContext(BlocksContext);\n if (!blocks) throw new Error(\"useBlocks: no blocks. Render inside <GenesisNativeApp>.\");\n return blocks;\n}\n\n/** A Settings section as `SettingsPage` from `@marktiderman/genesis-ui-native` takes it. @stability Beta */\nexport interface BlockSettingsSection<R extends { id: string; title: string } = SettingsRowLike> {\n id: string;\n title?: string;\n footnote?: string;\n rows: R[];\n}\n\n/** The row fields a block can fill. @stability Beta */\nexport interface SettingsRowLike {\n id: string;\n title: string;\n subtitle?: string;\n showChevron?: boolean;\n onPress?: () => void;\n testID?: string;\n}\n\n/** @stability Beta */\nexport interface UseBlockSettingsOptions {\n /** Open a row's `href` (expo-router's `router.push`). Without it, rows with an `href` aren't pressable. */\n navigate?: (href: string) => void;\n /** Titles for sections a block names that `sections` doesn't have. Default the section id. */\n sectionTitles?: Readonly<Record<string, string>>;\n}\n\n/**\n * The app's Settings sections with every block's rows added: each row goes\n * at the end of the section its `section` names (by `order`, then block\n * order), and a section no one has yet is added after the rest.\n *\n * Calls each row's `useSubtitle` hook, so call it unconditionally at the top\n * of the Settings screen. The blocks are fixed for the life of the app, so\n * the hooks run in the same order on every render.\n *\n * @stability Beta\n */\nexport function useBlockSettings<R extends SettingsRowLike>(\n sections: readonly BlockSettingsSection<R>[],\n options: UseBlockSettingsOptions = {},\n): BlockSettingsSection<R | SettingsRowLike>[] {\n const blocks = useContext(BlocksContext);\n const rows = blocks?.settings ?? [];\n // The same hooks in the same order every render: `rows` never changes once the shell has resolved it.\n const subtitles = rows.map((row) => row.useSubtitle?.());\n return mergeBlockSettings(sections, rows, subtitles, options);\n}\n\n/** The merge `useBlockSettings` does, without hooks (subtitles already read). @stability Beta */\nexport function mergeBlockSettings<R extends SettingsRowLike>(\n sections: readonly BlockSettingsSection<R>[],\n rows: readonly Contributed<BlockSettingsRow>[],\n subtitles: readonly (string | null | undefined)[] = [],\n options: UseBlockSettingsOptions = {},\n): BlockSettingsSection<R | SettingsRowLike>[] {\n const out: BlockSettingsSection<R | SettingsRowLike>[] = sections.map((s) => ({ ...s, rows: [...s.rows] }));\n rows.forEach((row, i) => {\n let section = out.find((s) => s.id === row.section);\n if (!section) {\n section = { id: row.section, title: options.sectionTitles?.[row.section] ?? row.section, rows: [] };\n out.push(section);\n }\n const { navigate } = options;\n const href = row.href;\n section.rows.push({\n id: row.id,\n title: row.title,\n subtitle: subtitles[i] ?? row.subtitle,\n testID: row.testID,\n ...(href && navigate ? { showChevron: true, onPress: () => navigate(href) } : {}),\n });\n });\n return out;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updates/signature.ts"],"names":[],"mappings":";AA2CA,IAAM,OAAA,GAAU,SAAA;AAGhB,IAAM,KAAA,GAAQ,CAAC,KAAA,KAAqD,OAAO,KAAA,KAAU,YAAY,KAAA,CAAM,IAAA,EAAK,KAAM,EAAA,GAAK,KAAA,GAAQ,IAAA;AAExH,SAAS,iBAAiB,EAAE,WAAA,EAAa,SAAS,QAAA,EAAU,gBAAA,GAAmB,MAAK,EAA4C;AACrI,EAAA,MAAM,OAAA,GAAU,KAAA,CAAM,WAAA,EAAa,wBAAwB,CAAA;AAC3D,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,WAAA,EAAa,kBAAkB,CAAA;AACnD,EAAA,MAAM,EAAA,GAAK,OAAA,CAAQ,OAAA,EAAS,SAAS,CAAA;AACrC,EAAA,MAAM,OAAA,GAAU,EAAA,GAAK,KAAA,CAAM,OAAA,EAAS,OAAO,CAAA,GAAI,IAAA;AAC/C,EAAA,MAAM,QAAA,GAAW,EAAA,GAAK,KAAA,CAAM,OAAA,EAAS,QAAQ,CAAA,GAAI,IAAA;AACjD,EAAA,MAAM,cAAA,GAAiB,KAAA,CAAM,OAAA,EAAS,cAAc,CAAA;AACpD,EAAA,MAAM,SAAqC,CAAC,EAAA,GAAK,KAAA,GAAQ,OAAA,EAAS,mBAAmB,UAAA,GAAa,QAAA;AAClG,EAAA,MAAM,SAAA,GAAY,EAAA,IAAM,OAAA,EAAS,iBAAA,KAAsB,IAAA;AACvD,EAAA,MAAM,eAAe,gBAAA,IAAoB,OAAA;AAEzC,EAAA,MAAM,OAAO,CAAA,EAAG,OAAA,IAAW,OAAO,CAAA,EAAA,EAAK,SAAS,OAAO,CAAA,CAAA,CAAA;AACvD,EAAA,MAAM,KAAA,GAAQ,CAAC,IAAI,CAAA;AACnB,EAAA,IAAI,WAAW,KAAA,EAAO;AACpB,IAAA,KAAA,CAAM,KAAK,aAAa,CAAA;AAAA,EAC1B,CAAA,MAAO;AACL,IAAA,KAAA,CAAM,IAAA,CAAK,gBAAgB,YAAY,CAAA;AACvC,IAAA,KAAA,CAAM,IAAA,CAAK,WAAW,UAAA,GAAa,UAAA,GAAc,UAAU,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,IAAK,OAAQ,CAAA;AAAA,EACpF;AACA,EAAA,IAAI,SAAA,EAAW,KAAA,CAAM,IAAA,CAAK,kBAAkB,CAAA;AAC5C,EAAA,MAAM,KAAA,GAAQ,KAAA,CAAM,IAAA,CAAK,QAAK,CAAA;AAE9B,EAAA,MAAM,KAAA,GAAQ;AAAA,IACZ,WAAW,IAAI,CAAA,CAAA;AAAA,IACf,YAAY,QAAQ,CAAA,CAAA;AAAA,IACpB,CAAA,QAAA,EAAW,OAAA,KAAY,EAAA,GAAK,OAAA,GAAU,MAAA,CAAO,CAAA,EAAG,gBAAA,IAAoB,gBAAA,KAAqB,OAAA,GAAU,CAAA,cAAA,EAAiB,gBAAgB,CAAA,CAAA,CAAA,GAAM,EAAE,CAAA,CAAA;AAAA,IAC5I,CAAA,QAAA,EAAW,cAAA,KAAmB,EAAA,GAAK,OAAA,GAAU,MAAA,CAAO,CAAA,CAAA;AAAA,IACpD,CAAA,OAAA,EAAU,WAAW,KAAA,GAAQ,aAAA,GAAgB,WAAW,UAAA,GAAa,UAAA,GAAc,YAAY,OAAQ,CAAA;AAAA,GACzG;AACA,EAAA,IAAI,WAAW,KAAA,CAAM,IAAA,CAAK,qBAAqB,OAAA,EAAS,qBAAA,IAAyB,OAAO,CAAA,CAAE,CAAA;AAC1F,EAAA,OAAO,EAAE,OAAA,EAAS,KAAA,EAAO,QAAA,EAAU,SAAS,gBAAA,EAAkB,cAAA,EAAgB,QAAA,EAAU,MAAA,EAAQ,WAAW,KAAA,EAAO,IAAA,EAAM,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA,EAAE;AAC3I","file":"chunk-6BT4PTGH.js","sourcesContent":["/**\n * The version signature: which binary and which update this is, in one\n * line for Settings \"About\" and in a few lines for a support report.\n *\n * 1.4.0 (37) · preview · 3f2a9c1b\n * 1.4.0 (37) · production · embedded\n * 1.4.0 (37) · updates off\n *\n * A value the modules can't give is printed as `unknown`, never left out\n * (an empty string counts as not given: expo-updates gives `\"\"` for the\n * runtime version in a development build); one that doesn't apply, with\n * updates off, as `none`.\n */\nimport type { ApplicationLike, UpdatesModuleLike } from \"./modules\";\n\nexport interface VersionSignature {\n version: string | null;\n build: string | null;\n platform: string;\n /** The build's channel (expo-updates). */\n channel: string | null;\n /** A channel picked on this device (a test build switched channels); `null` when it follows the build. */\n requestedChannel: string | null;\n runtimeVersion: string | null;\n updateId: string | null;\n /** `update`: a downloaded update runs. `embedded`: the binary's own code. `off`: updates are off (development, Expo Go). */\n launch: \"update\" | \"embedded\" | \"off\";\n /** expo-updates fell back to the embedded code after a failed launch. */\n emergency: boolean;\n /** One line, for an About row. */\n short: string;\n /** Several lines, for a support report. */\n text: string;\n}\n\nexport interface VersionSignatureInput {\n application?: ApplicationLike;\n updates?: UpdatesModuleLike;\n /** `Platform.OS`. */\n platform: string;\n requestedChannel?: string | null;\n}\n\nconst UNKNOWN = \"unknown\";\n\n/** A module's value, or null when it gave none (undefined, null or an empty string). */\nconst given = (value: string | null | undefined): string | null => (typeof value === \"string\" && value.trim() !== \"\" ? value : null);\n\nexport function versionSignature({ application, updates, platform, requestedChannel = null }: VersionSignatureInput): VersionSignature {\n const version = given(application?.nativeApplicationVersion);\n const build = given(application?.nativeBuildVersion);\n const on = Boolean(updates?.isEnabled);\n const channel = on ? given(updates?.channel) : null;\n const updateId = on ? given(updates?.updateId) : null;\n const runtimeVersion = given(updates?.runtimeVersion);\n const launch: VersionSignature[\"launch\"] = !on ? \"off\" : updates?.isEmbeddedLaunch ? \"embedded\" : \"update\";\n const emergency = on && updates?.isEmergencyLaunch === true;\n const shownChannel = requestedChannel ?? channel;\n\n const head = `${version ?? UNKNOWN} (${build ?? UNKNOWN})`;\n const parts = [head];\n if (launch === \"off\") {\n parts.push(\"updates off\");\n } else {\n parts.push(shownChannel ?? \"no channel\");\n parts.push(launch === \"embedded\" ? \"embedded\" : (updateId?.slice(0, 8) ?? UNKNOWN));\n }\n if (emergency) parts.push(\"emergency launch\");\n const short = parts.join(\" · \");\n\n const lines = [\n `Version ${head}`,\n `Platform ${platform}`,\n `Channel ${channel ?? (on ? UNKNOWN : \"none\")}${requestedChannel && requestedChannel !== channel ? ` (switched to ${requestedChannel})` : \"\"}`,\n `Runtime ${runtimeVersion ?? (on ? UNKNOWN : \"none\")}`,\n `Update ${launch === \"off\" ? \"updates off\" : launch === \"embedded\" ? \"embedded\" : (updateId ?? UNKNOWN)}`,\n ];\n if (emergency) lines.push(`Emergency launch: ${updates?.emergencyLaunchReason ?? UNKNOWN}`);\n return { version, build, platform, channel, requestedChannel, runtimeVersion, updateId, launch, emergency, short, text: lines.join(\"\\n\") };\n}\n"]}
|