@marktiderman/genesis-cli 1.5.0 → 1.7.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 +224 -3
- package/dist/cli.js +4602 -1549
- package/dist/cli.js.map +1 -1
- package/dist/{config-Ci-_Ue-1.d.ts → config-CrZbM3jD.d.ts} +73 -4
- package/dist/doctor.d.ts +31 -4
- package/dist/doctor.js +976 -30
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +91 -8
- package/dist/expo.js +207 -14
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +502 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +987 -38
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.d.ts +1 -1
- package/dist/scaffolder.js +9 -6
- package/dist/scaffolder.js.map +1 -1
- package/dist/starter/.eas/scripts/rollout-health.mjs +85 -0
- package/dist/starter/.eas/workflows/deploy-production.yml +149 -0
- package/dist/starter/.eas/workflows/e2e.yml +77 -0
- package/dist/starter/.eas/workflows/pr-preview.yml +117 -0
- package/dist/starter/.eas/workflows/rollout.yml +120 -0
- package/dist/starter/.env.example +11 -0
- package/dist/starter/.fingerprintignore +7 -0
- package/dist/starter/.maestro/README.md +38 -0
- package/dist/starter/.maestro/config.yaml +5 -0
- package/dist/starter/.maestro/flows/deep-link.yaml +22 -0
- package/dist/starter/.maestro/flows/launch.yaml +17 -0
- package/dist/starter/.maestro/flows/settings-version.yaml +28 -0
- package/dist/starter/.maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/starter/.maestro/subflows/sign-in.yaml +20 -0
- package/dist/starter/README.md +314 -0
- package/dist/starter/__tests__/app-config.test.ts +51 -0
- package/dist/starter/__tests__/check-in-photos.test.ts +57 -0
- package/dist/starter/__tests__/components/css-stub.js +2 -0
- package/dist/starter/__tests__/components/fake-supabase.ts +136 -0
- package/dist/starter/__tests__/components/links.test.ts +25 -0
- package/dist/starter/__tests__/components/render-app.ts +22 -0
- package/dist/starter/__tests__/components/reports.ts +10 -0
- package/dist/starter/__tests__/components/resolver.js +12 -0
- package/dist/starter/__tests__/components/root-layout.test.tsx +55 -0
- package/dist/starter/__tests__/components/session-storage.test.tsx +81 -0
- package/dist/starter/__tests__/components/settings.test.tsx +134 -0
- package/dist/starter/__tests__/components/setup.ts +69 -0
- package/dist/starter/__tests__/components/sign-in.test.tsx +90 -0
- package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +19 -0
- package/dist/starter/__tests__/components/tabs.test.tsx +43 -0
- package/dist/starter/__tests__/components/tabs.ts +12 -0
- package/dist/starter/__tests__/entry.test.ts +28 -0
- package/dist/starter/__tests__/inline-copy.ts +59 -0
- package/dist/starter/__tests__/starter.test.ts +319 -0
- package/dist/starter/_gitignore +13 -0
- package/dist/starter/app.config.ts +44 -0
- package/dist/starter/babel.config.js +9 -0
- package/dist/starter/eas.json +47 -0
- package/dist/starter/eslint.config.js +5 -0
- package/dist/starter/genesis.config.json +12 -0
- package/dist/starter/global.css +3 -0
- package/dist/starter/index.ts +14 -0
- package/dist/starter/jest.config.js +36 -0
- package/dist/starter/metro.config.js +38 -0
- package/dist/starter/package.json +93 -0
- package/dist/starter/pnpm-workspace.yaml +73 -0
- package/dist/starter/src/app/(app)/(home)/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +41 -0
- package/dist/starter/src/app/(app)/(home)/index.tsx +34 -0
- package/dist/starter/src/app/(app)/_layout.tsx +27 -0
- package/dist/starter/src/app/(app)/notifications/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/notifications/index.tsx +36 -0
- package/dist/starter/src/app/(app)/settings/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/settings/index.tsx +96 -0
- package/dist/starter/src/app/(app)/settings/notifications.tsx +16 -0
- package/dist/starter/src/app/(app)/settings/support/[id].tsx +23 -0
- package/dist/starter/src/app/(app)/settings/support/ideas.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/index.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/new.tsx +35 -0
- package/dist/starter/src/app/(app)/settings/support/shipped.tsx +20 -0
- package/dist/starter/src/app/+native-intent.ts +11 -0
- package/dist/starter/src/app/_layout.tsx +20 -0
- package/dist/starter/src/app/sign-in.tsx +69 -0
- package/dist/starter/src/copy.ts +118 -0
- package/dist/starter/src/forms/check-in.json +121 -0
- package/dist/starter/src/lib/account.ts +42 -0
- package/dist/starter/src/lib/app.ts +52 -0
- package/dist/starter/src/lib/auth.ts +80 -0
- package/dist/starter/src/lib/check-in-photos.ts +66 -0
- package/dist/starter/src/lib/check-in.ts +85 -0
- package/dist/starter/src/lib/define-starter.ts +148 -0
- package/dist/starter/src/lib/devtools-overlay.ts +34 -0
- package/dist/starter/src/lib/devtools.ts +23 -0
- package/dist/starter/src/lib/env.ts +33 -0
- package/dist/starter/src/lib/google-signin.ts +23 -0
- package/dist/starter/src/lib/links.ts +40 -0
- package/dist/starter/src/lib/native-modules.ts +27 -0
- package/dist/starter/src/lib/notifications.ts +15 -0
- package/dist/starter/src/lib/observability.ts +45 -0
- package/dist/starter/src/lib/push.ts +49 -0
- package/dist/starter/src/lib/supabase.ts +65 -0
- package/dist/starter/src/lib/support.ts +44 -0
- package/dist/starter/src/lib/updates.ts +61 -0
- package/dist/starter/starter.config.ts +37 -0
- package/dist/starter/supabase/config.toml +26 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +237 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/handler.ts +227 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/index.ts +55 -0
- package/dist/starter/supabase/functions/genesis-push-send/expo.ts +117 -0
- package/dist/starter/supabase/functions/genesis-push-send/handler.ts +462 -0
- package/dist/starter/supabase/functions/genesis-push-send/index.ts +54 -0
- package/dist/starter/supabase/migrations/20261024000000_genesis_account_deletion.sql +133 -0
- package/dist/starter/supabase/migrations/20261024000100_genesis_app_release_policy.sql +82 -0
- package/dist/starter/supabase/migrations/20261024000200_genesis_apple_token_revocation.sql +205 -0
- package/dist/starter/supabase/migrations/20261024000400_genesis_push.sql +524 -0
- package/dist/starter/supabase/migrations/20261024000600_genesis_support.sql +846 -0
- package/dist/starter/supabase/tests/database/genesis_account_deletion.test.sql +138 -0
- package/dist/starter/supabase/tests/database/genesis_app_release_policy.test.sql +148 -0
- package/dist/starter/supabase/tests/database/genesis_apple_token_revocation.test.sql +230 -0
- package/dist/starter/supabase/tests/database/genesis_push.test.sql +407 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +552 -0
- package/dist/starter/tailwind.config.mjs +15 -0
- package/dist/starter/tsconfig.json +14 -0
- package/dist/starter/vitest.config.mts +7 -0
- package/dist/templates/ci/app-ci.yml +17 -0
- package/dist/templates/ci/genesis-upgrade.yml +21 -0
- package/dist/templates/ci/supabase-ci.yml +20 -0
- package/dist/templates/eas/eas.json +47 -0
- package/dist/templates/eas/scripts/rollout-health.mjs +85 -0
- package/dist/templates/eas/workflows/deploy-production.yml +149 -0
- package/dist/templates/eas/workflows/e2e.yml +77 -0
- package/dist/templates/eas/workflows/pr-preview.yml +117 -0
- package/dist/templates/eas/workflows/rollout.yml +120 -0
- package/dist/templates/maestro/config.yaml +5 -0
- package/dist/templates/maestro/flows/deep-link.yaml +22 -0
- package/dist/templates/maestro/flows/launch.yaml +17 -0
- package/dist/templates/maestro/flows/settings-version.yaml +28 -0
- package/dist/templates/maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/templates/maestro/subflows/sign-in.yaml +20 -0
- package/dist/vite.js +975 -29
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The observability block (`features.observability`): every error the shell
|
|
3
|
+
* catches, route breadcrumbs and timings, the signed-in user's id and the
|
|
4
|
+
* typed analytics events below, through Sentry (when `EXPO_PUBLIC_SENTRY_DSN`
|
|
5
|
+
* is set) and, in development, the console. Emails, tokens, keys and query
|
|
6
|
+
* strings are scrubbed on the phone before anything is sent.
|
|
7
|
+
*
|
|
8
|
+
* Built here, at module scope, so `Sentry.init` runs before the root layout
|
|
9
|
+
* renders: `app.ts` imports this file before anything else of the app's.
|
|
10
|
+
*/
|
|
11
|
+
import * as Sentry from "@sentry/react-native";
|
|
12
|
+
import * as Application from "expo-application";
|
|
13
|
+
import { useSegments } from "expo-router";
|
|
14
|
+
import * as Updates from "expo-updates";
|
|
15
|
+
import type { ComponentType } from "react";
|
|
16
|
+
import { Platform } from "react-native";
|
|
17
|
+
import { consoleSink, createObservability, defineEvents, sentrySink } from "@marktiderman/genesis-native/observability";
|
|
18
|
+
import { versionSignature } from "@marktiderman/genesis-native/updates";
|
|
19
|
+
import starter from "../../starter.config";
|
|
20
|
+
|
|
21
|
+
/** Every analytics event the app sends, and the props each may carry (closed lists, numbers, booleans: never free text). */
|
|
22
|
+
export const events = defineEvents({
|
|
23
|
+
"auth.signed_out": {},
|
|
24
|
+
"account.deleted": {},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const observability = starter.features.observability
|
|
28
|
+
? createObservability({
|
|
29
|
+
events,
|
|
30
|
+
useSegments,
|
|
31
|
+
sinks: [
|
|
32
|
+
__DEV__ && consoleSink(),
|
|
33
|
+
sentrySink(Sentry, {
|
|
34
|
+
dsn: process.env.EXPO_PUBLIC_SENTRY_DSN,
|
|
35
|
+
signature: versionSignature({ application: Application, updates: Updates, platform: Platform.OS }),
|
|
36
|
+
applicationId: Application.applicationId,
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
})
|
|
40
|
+
: undefined;
|
|
41
|
+
|
|
42
|
+
/** The root layout, wrapped by Sentry (touch and profiler boundaries) when the block is on. */
|
|
43
|
+
export function wrapRoot<P extends Record<string, unknown>>(root: ComponentType<P>): ComponentType<P> {
|
|
44
|
+
return observability ? observability.wrap(root) : root;
|
|
45
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The push block (`features.push`): this device's Expo push token on sign-in
|
|
3
|
+
* (once permission is granted) and off on sign-out, taps routed through the
|
|
4
|
+
* deep-link map, the badge, the soft prompt and the Notification settings
|
|
5
|
+
* screen, on Supabase's `push_devices` and `notification_preferences`
|
|
6
|
+
* (migration in `supabase/migrations`). `app.ts` passes it to GenesisNativeApp's
|
|
7
|
+
* `blocks`; it adds the Notifications row to Settings (`useBlockSettings`).
|
|
8
|
+
*
|
|
9
|
+
* The sender is the `genesis-push-send` Edge Function in `supabase/functions`;
|
|
10
|
+
* the app never sends a push itself. Without an EAS project id
|
|
11
|
+
* (`starter.config.ts` `app.easProjectId`) there is no push token: the block
|
|
12
|
+
* says so once in the console and Settings says so on screen.
|
|
13
|
+
*/
|
|
14
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
15
|
+
import * as Application from "expo-application";
|
|
16
|
+
import Constants from "expo-constants";
|
|
17
|
+
import * as Notifications from "expo-notifications";
|
|
18
|
+
import { router, type Href } from "expo-router";
|
|
19
|
+
import { AppState, Linking, Platform } from "react-native";
|
|
20
|
+
import { createPush, supabasePushBackend } from "@marktiderman/genesis-native/push";
|
|
21
|
+
import starter from "../../starter.config";
|
|
22
|
+
import { copy } from "@/copy";
|
|
23
|
+
import { linkHold, links } from "./links";
|
|
24
|
+
import { supabase } from "./supabase";
|
|
25
|
+
|
|
26
|
+
/** The kinds of notification the app sends: a switch each in Settings, an Android channel each. Add yours. */
|
|
27
|
+
export const pushCategories = [{ id: "activity", title: copy.push.activityTitle, description: copy.push.activityDescription }];
|
|
28
|
+
|
|
29
|
+
export function createStarterPush() {
|
|
30
|
+
return createPush({
|
|
31
|
+
notifications: Notifications,
|
|
32
|
+
platform: Platform.OS,
|
|
33
|
+
projectId: (Constants.expoConfig?.extra?.eas?.projectId as string | undefined) ?? Constants.easConfig?.projectId ?? null,
|
|
34
|
+
appVersion: Application.nativeApplicationVersion,
|
|
35
|
+
backend: supabasePushBackend(supabase),
|
|
36
|
+
categories: pushCategories,
|
|
37
|
+
storage: AsyncStorage,
|
|
38
|
+
appState: AppState,
|
|
39
|
+
openSettings: Linking.openSettings,
|
|
40
|
+
// With deepLinks off a tapped push opens `/`, as every other link does, and isn't held over sign-in.
|
|
41
|
+
links: starter.features.deepLinks ? links : { map: {} },
|
|
42
|
+
onOpen: (path) => router.push(path as Href),
|
|
43
|
+
hold: starter.features.deepLinks ? linkHold : undefined,
|
|
44
|
+
// Settings gets the row through useBlockSettings, in its untitled `general` section.
|
|
45
|
+
settingsRow: { title: copy.settings.notifications, section: "general", href: "/settings/notifications" },
|
|
46
|
+
statusLabels: copy.push.status,
|
|
47
|
+
onError: (error, source) => console.warn(`[push] ${source}: ${error.message}`),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app's one Supabase client: PKCE sign-in, the session in the Keychain,
|
|
3
|
+
* refreshed only while the app is in front, and wiped after a reinstall.
|
|
4
|
+
*/
|
|
5
|
+
import "react-native-url-polyfill/auto";
|
|
6
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
7
|
+
import * as ExpoCrypto from "expo-crypto";
|
|
8
|
+
import * as SecureStore from "expo-secure-store";
|
|
9
|
+
import { AppState } from "react-native";
|
|
10
|
+
import { createGenesisSupabase, type SessionStorage } from "@marktiderman/genesis-supabase";
|
|
11
|
+
import { keychainStorage, refreshWhileActive, wipeSessionOnReinstall } from "@marktiderman/genesis-supabase/native";
|
|
12
|
+
import starter from "../../starter.config";
|
|
13
|
+
import { env } from "./env";
|
|
14
|
+
|
|
15
|
+
const { features } = starter;
|
|
16
|
+
const sessionKey = `${starter.app.slug}-auth-token`;
|
|
17
|
+
const keychain = keychainStorage(SecureStore);
|
|
18
|
+
|
|
19
|
+
let wipe: Promise<unknown> | undefined;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Settles once a session left by an earlier install is gone. The first call
|
|
23
|
+
* starts the wipe; later calls share it. A failed wipe is forgotten, so the
|
|
24
|
+
* next call (the fatal screen's "Try again", or the next storage read) runs it
|
|
25
|
+
* again instead of failing for the rest of the process. The boot waits for it
|
|
26
|
+
* (`steps` in `app.ts`), so a failure shows the fatal screen.
|
|
27
|
+
*/
|
|
28
|
+
export function sessionReady(): Promise<unknown> {
|
|
29
|
+
if (!features.wipeSessionOnReinstall) return Promise.resolve(false);
|
|
30
|
+
wipe ??= wipeSessionOnReinstall({ session: keychain, sessionKey, installMarker: AsyncStorage }).catch((error: unknown) => {
|
|
31
|
+
wipe = undefined;
|
|
32
|
+
throw error;
|
|
33
|
+
});
|
|
34
|
+
return wipe;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// supabase-js reads the stored session as soon as the client is created, so
|
|
38
|
+
// every read and write waits for the wipe. The wipe itself uses `keychain`
|
|
39
|
+
// directly, never this wrapper.
|
|
40
|
+
const storage: SessionStorage = {
|
|
41
|
+
async getItem(key) {
|
|
42
|
+
await sessionReady();
|
|
43
|
+
return keychain.getItem(key);
|
|
44
|
+
},
|
|
45
|
+
async setItem(key, value) {
|
|
46
|
+
await sessionReady();
|
|
47
|
+
return keychain.setItem(key, value);
|
|
48
|
+
},
|
|
49
|
+
async removeItem(key) {
|
|
50
|
+
await sessionReady();
|
|
51
|
+
return keychain.removeItem(key);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const supabase = createGenesisSupabase({
|
|
56
|
+
url: env.supabaseUrl,
|
|
57
|
+
publishableKey: env.supabasePublishableKey,
|
|
58
|
+
storage,
|
|
59
|
+
platform: "native",
|
|
60
|
+
// Hermes has no crypto.subtle: without this, supabase-js would send PKCE challenges as "plain".
|
|
61
|
+
crypto: ExpoCrypto,
|
|
62
|
+
options: { auth: { storageKey: sessionKey } },
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (features.refreshWhileActive) refreshWhileActive(supabase, AppState);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The support block (`features.support`): "Send feedback" and "Help" in
|
|
3
|
+
* Settings, the feedback screen with a screenshot (shake the phone to capture
|
|
4
|
+
* the screen you're on and mark it up), your reports with staff replies, and
|
|
5
|
+
* the idea board with votes, on Supabase's `support_*` tables and the private
|
|
6
|
+
* `genesis-support` bucket (migration in `supabase/migrations`). `app.ts`
|
|
7
|
+
* passes it to GenesisNativeApp's `blocks`; it also fills the devtools overlay's
|
|
8
|
+
* "Send feedback" (its `devtoolsFeedback` slot).
|
|
9
|
+
*
|
|
10
|
+
* Staff: nobody is, until you add `private.genesis_support_staff(person uuid)`
|
|
11
|
+
* in a migration of your own (see the migration's header).
|
|
12
|
+
*/
|
|
13
|
+
import * as Application from "expo-application";
|
|
14
|
+
import { Accelerometer } from "expo-sensors";
|
|
15
|
+
import { router, usePathname, type Href } from "expo-router";
|
|
16
|
+
import * as Updates from "expo-updates";
|
|
17
|
+
import { Platform } from "react-native";
|
|
18
|
+
import * as ViewShot from "react-native-view-shot";
|
|
19
|
+
import { versionSignature } from "@marktiderman/genesis-native/updates";
|
|
20
|
+
import { createSupport } from "@marktiderman/genesis-support/native";
|
|
21
|
+
import starter from "../../starter.config";
|
|
22
|
+
import { copy } from "@/copy";
|
|
23
|
+
import { supabase } from "./supabase";
|
|
24
|
+
|
|
25
|
+
/** Where the support screens live: `src/app/(app)/settings/support/`. */
|
|
26
|
+
export const supportBasePath = "/settings/support";
|
|
27
|
+
|
|
28
|
+
export function createStarterSupport() {
|
|
29
|
+
return createSupport({
|
|
30
|
+
supabase,
|
|
31
|
+
navigate: (href) => router.push(href as Href),
|
|
32
|
+
platform: Platform.OS,
|
|
33
|
+
appVersion: () => versionSignature({ application: Application, updates: Updates, platform: Platform.OS }).short,
|
|
34
|
+
useCurrentRoute: usePathname,
|
|
35
|
+
viewShot: ViewShot,
|
|
36
|
+
accelerometer: Accelerometer,
|
|
37
|
+
basePath: supportBasePath,
|
|
38
|
+
copy: copy.support,
|
|
39
|
+
onError: (error, where) => console.warn(`[support] ${where}: ${error.message}`),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The support block, or `undefined` with `features.support` off. */
|
|
44
|
+
export const support = starter.features.support ? createStarterSupport() : undefined;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The updates block (`features.updates`): force upgrade and maintenance from
|
|
3
|
+
* Supabase's `app_release_policy` row (migration in `supabase/migrations`),
|
|
4
|
+
* the update banner, what's new once per version, and the version signature
|
|
5
|
+
* Settings shows. `app.ts` passes it to `GenesisNativeApp`.
|
|
6
|
+
*
|
|
7
|
+
* Channel switching (`useUpdates().channels.switchTo("pr-42")`, a pull
|
|
8
|
+
* request's preview update) is on only in development and in the
|
|
9
|
+
* development and preview variants, told apart by the bundle id
|
|
10
|
+
* `APP_VARIANT` gave the build (`.dev`, `.preview`): a fact of the binary,
|
|
11
|
+
* so a build that has switched channels can switch again, and a production
|
|
12
|
+
* build (no suffix) never can.
|
|
13
|
+
*/
|
|
14
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
15
|
+
import * as Application from "expo-application";
|
|
16
|
+
import * as Updates from "expo-updates";
|
|
17
|
+
import { AppState, Linking, Platform } from "react-native";
|
|
18
|
+
import { createUpdates, supabasePolicySource, useVersionSignature, versionSignature } from "@marktiderman/genesis-native/updates";
|
|
19
|
+
import starter from "../../starter.config";
|
|
20
|
+
import { observability } from "./observability";
|
|
21
|
+
import { supabase } from "./supabase";
|
|
22
|
+
|
|
23
|
+
/** The variants (withGenesis bundle id suffixes) that may switch to another channel's updates. */
|
|
24
|
+
const TEST_BUILD = /\.(dev|preview)$/;
|
|
25
|
+
|
|
26
|
+
export function createStarterUpdates() {
|
|
27
|
+
return createUpdates({
|
|
28
|
+
platform: Platform.OS,
|
|
29
|
+
application: Application,
|
|
30
|
+
updates: Updates,
|
|
31
|
+
policy: supabasePolicySource(supabase),
|
|
32
|
+
storage: AsyncStorage,
|
|
33
|
+
appState: AppState,
|
|
34
|
+
openURL: Linking.openURL,
|
|
35
|
+
channels: { enabled: __DEV__ || TEST_BUILD.test(Application.applicationId ?? "") },
|
|
36
|
+
// Settings > About shows the version itself (`useAppVersion`), with the block on or off.
|
|
37
|
+
versionRow: false,
|
|
38
|
+
onError: (error, source) => {
|
|
39
|
+
console.warn(`[updates] ${source}: ${error.message}`);
|
|
40
|
+
observability?.captureError(error, { source: `updates:${source}` });
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The app's one updates block (`features.updates`), shared by the shell and the devtools overlay. */
|
|
46
|
+
export const updatesBlock = starter.features.updates ? createStarterUpdates() : undefined;
|
|
47
|
+
|
|
48
|
+
function useBlockSignature(): string {
|
|
49
|
+
return useVersionSignature().short;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function useModuleSignature(): string {
|
|
53
|
+
return versionSignature({ application: Application, updates: Updates, platform: Platform.OS }).short;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The About row's line, `1.4.0 (37) · preview · 3f2a9c1b`: from the block
|
|
58
|
+
* (with a channel picked on this device) when `updates` is on, else read
|
|
59
|
+
* from the modules directly.
|
|
60
|
+
*/
|
|
61
|
+
export const useAppVersion: () => string = starter.features.updates ? useBlockSignature : useModuleSignature;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The starter's switches. Every universal feature the Genesis packages ship
|
|
3
|
+
* is on; turn one off by changing its line to `false`. See README.md.
|
|
4
|
+
*/
|
|
5
|
+
import { defineStarter } from "./src/lib/define-starter";
|
|
6
|
+
|
|
7
|
+
export default defineStarter({
|
|
8
|
+
app: {
|
|
9
|
+
name: "Genesis Starter",
|
|
10
|
+
slug: "genesis-rn-starter",
|
|
11
|
+
scheme: "genesis-starter",
|
|
12
|
+
bundleId: "com.example.genesisstarter",
|
|
13
|
+
// PLACEHOLDER: your EAS project id (a UUID), printed by `eas init`. Empty means no EAS project:
|
|
14
|
+
// the app runs, builds carry no update URL and `eas update` can't reach them.
|
|
15
|
+
easProjectId: "",
|
|
16
|
+
},
|
|
17
|
+
features: {
|
|
18
|
+
emailSignIn: true,
|
|
19
|
+
appleSignIn: true,
|
|
20
|
+
// Off: it needs Google client ids and the Universal sign-in module. README, "Google sign-in".
|
|
21
|
+
googleSignIn: false,
|
|
22
|
+
accountDeletion: true,
|
|
23
|
+
notifications: true,
|
|
24
|
+
queryPersistence: true,
|
|
25
|
+
queryLifecycle: true,
|
|
26
|
+
keyboardScroll: true,
|
|
27
|
+
deepLinks: true,
|
|
28
|
+
wipeSessionOnReinstall: true,
|
|
29
|
+
refreshWhileActive: true,
|
|
30
|
+
updates: true,
|
|
31
|
+
push: true,
|
|
32
|
+
observability: true,
|
|
33
|
+
devtools: true,
|
|
34
|
+
checkIn: true,
|
|
35
|
+
support: true,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# The local Supabase stack for the starter (`supabase start`). Settings not listed here keep the
|
|
2
|
+
# CLI's defaults. See https://supabase.com/docs/guides/local-development/cli/config
|
|
3
|
+
project_id = "genesis-rn-starter"
|
|
4
|
+
|
|
5
|
+
# Sign-up asks the person to confirm their email. The link confirms it on Supabase's side and
|
|
6
|
+
# then opens `site_url`, not the app; the app's copy says to come back and sign in. (Opening the
|
|
7
|
+
# app from the link needs `emailRedirectTo`, a redirect URL here and a screen that exchanges the
|
|
8
|
+
# code: not in the starter yet.)
|
|
9
|
+
[auth.email]
|
|
10
|
+
enable_confirmations = true
|
|
11
|
+
|
|
12
|
+
# Sign in with Apple: the bundle id (and its .dev / .preview variants) as client ids.
|
|
13
|
+
[auth.external.apple]
|
|
14
|
+
enabled = true
|
|
15
|
+
client_id = "com.example.genesisstarter,com.example.genesisstarter.dev,com.example.genesisstarter.preview"
|
|
16
|
+
secret = ""
|
|
17
|
+
|
|
18
|
+
# Keeps Apple's refresh token at sign-in and revokes it when the account is deleted. It checks
|
|
19
|
+
# the caller itself (and its revoke step runs after the login is gone), so the gateway's JWT
|
|
20
|
+
# check is off. Secrets: APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_PRIVATE_KEY, APPLE_CLIENT_IDS.
|
|
21
|
+
[functions.genesis-apple-revoke]
|
|
22
|
+
verify_jwt = false
|
|
23
|
+
|
|
24
|
+
# Checks GENESIS_PUSH_SECRET itself; never called by the app.
|
|
25
|
+
[functions.genesis-push-send]
|
|
26
|
+
verify_jwt = false
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sign in with Apple's REST API, for the genesis-apple-revoke Edge Function:
|
|
3
|
+
* the client secret (an ES256 JWT signed with your .p8 key), the
|
|
4
|
+
* authorization-code exchange (/auth/token) and revocation (/auth/revoke).
|
|
5
|
+
*
|
|
6
|
+
* Plain TypeScript over WebCrypto and fetch, with no Deno or Node APIs, so the
|
|
7
|
+
* same file runs in the Edge Function and in the package's unit tests.
|
|
8
|
+
* Nothing here logs or returns a token, a key or a client secret.
|
|
9
|
+
*
|
|
10
|
+
* Apple's docs: developer.apple.com/documentation/signinwithapplerestapi
|
|
11
|
+
* (generate-and-validate-tokens, revoke-tokens) and
|
|
12
|
+
* developer.apple.com/documentation/accountorganizationaldatasharing/creating-a-client-secret.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const APPLE_ISSUER = "https://appleid.apple.com";
|
|
16
|
+
export const APPLE_TOKEN_URL = "https://appleid.apple.com/auth/token";
|
|
17
|
+
export const APPLE_REVOKE_URL = "https://appleid.apple.com/auth/revoke";
|
|
18
|
+
|
|
19
|
+
/** Apple caps a client secret's lifetime at 15777000 seconds (six months). Each call signs a fresh one, so five minutes is plenty. */
|
|
20
|
+
export const CLIENT_SECRET_TTL_SECONDS = 300;
|
|
21
|
+
const CLIENT_SECRET_MAX_TTL_SECONDS = 15_777_000;
|
|
22
|
+
const REQUEST_TIMEOUT_MS = 10_000;
|
|
23
|
+
const CLOCK_SKEW_SECONDS = 30;
|
|
24
|
+
|
|
25
|
+
/** Apple's error codes (ErrorResponse.error). Anything else reads as "unknown". */
|
|
26
|
+
const APPLE_ERRORS = ["invalid_request", "invalid_client", "invalid_grant", "unauthorized_client", "unsupported_grant_type", "invalid_scope"] as const;
|
|
27
|
+
export type AppleErrorCode = (typeof APPLE_ERRORS)[number] | "unknown" | "network" | "bad_response";
|
|
28
|
+
|
|
29
|
+
export interface AppleConfig {
|
|
30
|
+
/** APPLE_TEAM_ID: your 10-character Team ID (the secret's `iss`). */
|
|
31
|
+
teamId: string;
|
|
32
|
+
/** APPLE_KEY_ID: the 10-character id of your Sign in with Apple key (the secret's `kid`). */
|
|
33
|
+
keyId: string;
|
|
34
|
+
/** APPLE_PRIVATE_KEY: the .p8 file's contents (PKCS#8 PEM). Escaped `\n` are accepted. */
|
|
35
|
+
privateKey: string;
|
|
36
|
+
/** APPLE_CLIENT_IDS: the bundle ids (App IDs) or Services IDs a code may be exchanged for, comma-separated. The first is the default. */
|
|
37
|
+
clientIds: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const TEN_CHARS = /^[A-Z0-9]{10}$/;
|
|
41
|
+
const CLIENT_ID = /^[A-Za-z0-9][A-Za-z0-9.-]{0,254}$/;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Reads the Apple settings from the environment. Returns the names that are
|
|
45
|
+
* missing or malformed (never their values), so the function can fail loud.
|
|
46
|
+
*/
|
|
47
|
+
export function readAppleConfig(env: (name: string) => string | undefined): { config: AppleConfig; problems?: undefined } | { config?: undefined; problems: string[] } {
|
|
48
|
+
const problems: string[] = [];
|
|
49
|
+
const teamId = (env("APPLE_TEAM_ID") ?? "").trim();
|
|
50
|
+
const keyId = (env("APPLE_KEY_ID") ?? "").trim();
|
|
51
|
+
const privateKey = normalizePem(env("APPLE_PRIVATE_KEY") ?? "");
|
|
52
|
+
const clientIds = (env("APPLE_CLIENT_IDS") ?? "")
|
|
53
|
+
.split(",")
|
|
54
|
+
.map((s) => s.trim())
|
|
55
|
+
.filter(Boolean);
|
|
56
|
+
if (!TEN_CHARS.test(teamId)) problems.push("APPLE_TEAM_ID (10 capital letters or digits)");
|
|
57
|
+
if (!TEN_CHARS.test(keyId)) problems.push("APPLE_KEY_ID (10 capital letters or digits)");
|
|
58
|
+
if (!/-----BEGIN PRIVATE KEY-----[\s\S]+-----END PRIVATE KEY-----/.test(privateKey)) problems.push("APPLE_PRIVATE_KEY (the .p8 file's PEM text)");
|
|
59
|
+
if (clientIds.length === 0 || !clientIds.every((id) => CLIENT_ID.test(id))) problems.push("APPLE_CLIENT_IDS (comma-separated bundle ids or Services IDs)");
|
|
60
|
+
return problems.length ? { problems } : { config: { teamId, keyId, privateKey, clientIds } };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Accepts a PEM pasted with real newlines, escaped `\n`, or surrounding quotes. */
|
|
64
|
+
function normalizePem(raw: string): string {
|
|
65
|
+
return raw.trim().replace(/^"|"$/g, "").replace(/\\n/g, "\n");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const encoder = new TextEncoder();
|
|
69
|
+
|
|
70
|
+
export function base64url(bytes: Uint8Array | string): string {
|
|
71
|
+
const data = typeof bytes === "string" ? encoder.encode(bytes) : bytes;
|
|
72
|
+
let binary = "";
|
|
73
|
+
for (const b of data) binary += String.fromCharCode(b);
|
|
74
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function base64urlDecode(text: string): string {
|
|
78
|
+
const b64 = text.replace(/-/g, "+").replace(/_/g, "/");
|
|
79
|
+
const binary = atob(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
|
|
80
|
+
return new TextDecoder().decode(Uint8Array.from(binary, (c) => c.charCodeAt(0)));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const keyCache = new Map<string, Promise<CryptoKey>>();
|
|
84
|
+
|
|
85
|
+
function signingKey(pem: string): Promise<CryptoKey> {
|
|
86
|
+
let key = keyCache.get(pem);
|
|
87
|
+
if (!key) {
|
|
88
|
+
const body = pem.replace(/-----(BEGIN|END) PRIVATE KEY-----/g, "").replace(/\s+/g, "");
|
|
89
|
+
const der = Uint8Array.from(atob(body), (c) => c.charCodeAt(0));
|
|
90
|
+
key = crypto.subtle.importKey("pkcs8", der, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
|
|
91
|
+
// A bad key must not stay cached as a rejected promise.
|
|
92
|
+
key.catch(() => keyCache.delete(pem));
|
|
93
|
+
keyCache.set(pem, key);
|
|
94
|
+
}
|
|
95
|
+
return key;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The `client_secret` for one client id: a JWT with header `{ alg: "ES256", kid }`
|
|
100
|
+
* and claims `{ iss: teamId, iat, exp, aud: "https://appleid.apple.com", sub: clientId }`,
|
|
101
|
+
* signed with ECDSA P-256 / SHA-256. WebCrypto returns the signature as r‖s
|
|
102
|
+
* (64 bytes), which is the JWS encoding ES256 needs.
|
|
103
|
+
*/
|
|
104
|
+
export async function appleClientSecret(config: AppleConfig, clientId: string, options: { now?: number; ttlSeconds?: number } = {}): Promise<string> {
|
|
105
|
+
// Backdated a little, so a clock slightly ahead of Apple's doesn't issue a secret "from the future".
|
|
106
|
+
const iat = Math.floor((options.now ?? Date.now()) / 1000) - CLOCK_SKEW_SECONDS;
|
|
107
|
+
const ttl = Math.min(Math.max(1, options.ttlSeconds ?? CLIENT_SECRET_TTL_SECONDS), CLIENT_SECRET_MAX_TTL_SECONDS);
|
|
108
|
+
const header = base64url(JSON.stringify({ alg: "ES256", kid: config.keyId }));
|
|
109
|
+
const payload = base64url(JSON.stringify({ iss: config.teamId, iat, exp: iat + ttl, aud: APPLE_ISSUER, sub: clientId }));
|
|
110
|
+
const input = `${header}.${payload}`;
|
|
111
|
+
const signature = await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, await signingKey(config.privateKey), encoder.encode(input));
|
|
112
|
+
return `${input}.${base64url(new Uint8Array(signature))}`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The payload of a JWT, unverified, or null if it isn't one. */
|
|
116
|
+
export function decodeJwtPayload(jwt: string): Record<string, unknown> | null {
|
|
117
|
+
const parts = jwt.split(".");
|
|
118
|
+
if (parts.length !== 3 || !parts[1]) return null;
|
|
119
|
+
try {
|
|
120
|
+
const payload: unknown = JSON.parse(base64urlDecode(parts[1]));
|
|
121
|
+
return payload && typeof payload === "object" && !Array.isArray(payload) ? (payload as Record<string, unknown>) : null;
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function appleError(res: Response): Promise<AppleErrorCode> {
|
|
128
|
+
try {
|
|
129
|
+
const body: unknown = await res.json();
|
|
130
|
+
const code = body && typeof body === "object" ? (body as { error?: unknown }).error : undefined;
|
|
131
|
+
return (APPLE_ERRORS as readonly unknown[]).includes(code) ? (code as AppleErrorCode) : "unknown";
|
|
132
|
+
} catch {
|
|
133
|
+
return "unknown";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function postForm(fetchImpl: typeof fetch, url: string, form: Record<string, string>): Promise<Response | null> {
|
|
138
|
+
try {
|
|
139
|
+
return await fetchImpl(url, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: { "content-type": "application/x-www-form-urlencoded", accept: "application/json" },
|
|
142
|
+
body: new URLSearchParams(form).toString(),
|
|
143
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
144
|
+
});
|
|
145
|
+
} catch {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type ExchangeResult =
|
|
151
|
+
| { ok: true; refreshToken: string; appleUserId: string }
|
|
152
|
+
/** `mintedRefreshToken`: Apple issued a token the checks then refused; revoke it rather than drop it. */
|
|
153
|
+
| { ok: false; error: AppleErrorCode; status?: number; mintedRefreshToken?: string };
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Exchanges a sign-in's single-use authorization code (valid for five
|
|
157
|
+
* minutes) for Apple's refresh token: `grant_type=authorization_code` with
|
|
158
|
+
* `client_id`, `client_secret` and `code`. A native sign-in sends no
|
|
159
|
+
* `redirect_uri` (Apple wants one only if the authorization request had one).
|
|
160
|
+
*
|
|
161
|
+
* Also checks the returned id token names Apple as `iss` and this client as
|
|
162
|
+
* `aud`, and returns its `sub` (the person's Apple user id) so the caller can
|
|
163
|
+
* tie the token to the right login. The id token comes straight from Apple
|
|
164
|
+
* over TLS in this response, so its claims are read without checking its
|
|
165
|
+
* signature (OpenID Connect Core 3.1.3.7).
|
|
166
|
+
*/
|
|
167
|
+
export async function exchangeAuthorizationCode(config: AppleConfig, clientId: string, code: string, fetchImpl: typeof fetch = fetch): Promise<ExchangeResult> {
|
|
168
|
+
const res = await postForm(fetchImpl, APPLE_TOKEN_URL, {
|
|
169
|
+
client_id: clientId,
|
|
170
|
+
client_secret: await appleClientSecret(config, clientId),
|
|
171
|
+
code,
|
|
172
|
+
grant_type: "authorization_code",
|
|
173
|
+
});
|
|
174
|
+
if (!res) return { ok: false, error: "network" };
|
|
175
|
+
if (!res.ok) return { ok: false, error: await appleError(res), status: res.status };
|
|
176
|
+
let body: { refresh_token?: unknown; id_token?: unknown };
|
|
177
|
+
try {
|
|
178
|
+
body = (await res.json()) as typeof body;
|
|
179
|
+
} catch {
|
|
180
|
+
return { ok: false, error: "bad_response", status: res.status };
|
|
181
|
+
}
|
|
182
|
+
const claims = typeof body.id_token === "string" ? decodeJwtPayload(body.id_token) : null;
|
|
183
|
+
const aud = claims?.aud;
|
|
184
|
+
const audOk = aud === clientId || (Array.isArray(aud) && aud.includes(clientId));
|
|
185
|
+
const minted = typeof body.refresh_token === "string" && body.refresh_token ? body.refresh_token : undefined;
|
|
186
|
+
if (!minted) return { ok: false, error: "bad_response", status: res.status };
|
|
187
|
+
if (!claims || claims.iss !== APPLE_ISSUER || !audOk || typeof claims.sub !== "string" || !claims.sub) {
|
|
188
|
+
return { ok: false, error: "bad_response", status: res.status, mintedRefreshToken: minted };
|
|
189
|
+
}
|
|
190
|
+
return { ok: true, refreshToken: minted, appleUserId: claims.sub };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Checks a refresh token is still live with this client's secret:
|
|
195
|
+
* `grant_type=refresh_token` at /auth/token (Apple returns new access and id
|
|
196
|
+
* tokens, which are dropped). This is the proof a revocation needs, because
|
|
197
|
+
* /auth/revoke answers 200 to a token it doesn't know even when the client
|
|
198
|
+
* secret is garbage: a 200 here means the secret is right and the token is
|
|
199
|
+
* live; `invalid_grant` means the token is already dead (nothing left to
|
|
200
|
+
* revoke); `invalid_client` means the secrets are wrong.
|
|
201
|
+
*/
|
|
202
|
+
export async function checkRefreshToken(config: AppleConfig, clientId: string, refreshToken: string, fetchImpl: typeof fetch = fetch): Promise<RevokeResult> {
|
|
203
|
+
const res = await postForm(fetchImpl, APPLE_TOKEN_URL, {
|
|
204
|
+
client_id: clientId,
|
|
205
|
+
client_secret: await appleClientSecret(config, clientId),
|
|
206
|
+
grant_type: "refresh_token",
|
|
207
|
+
refresh_token: refreshToken,
|
|
208
|
+
});
|
|
209
|
+
if (!res) return { ok: false, error: "network" };
|
|
210
|
+
if (res.status === 200) {
|
|
211
|
+
await res.body?.cancel().catch(() => {});
|
|
212
|
+
return { ok: true };
|
|
213
|
+
}
|
|
214
|
+
return { ok: false, error: await appleError(res), status: res.status };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export type RevokeResult = { ok: true } | { ok: false; error: AppleErrorCode; status?: number };
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Revokes a refresh token: `client_id`, `client_secret`, `token` and
|
|
221
|
+
* `token_type_hint=refresh_token`. Apple answers 200 with no body when it
|
|
222
|
+
* revoked the token, and also when the token was already invalid. It also
|
|
223
|
+
* answered 200 to an unknown token with a garbage client secret (seen
|
|
224
|
+
* 2026-10-24), so a 200 alone proves nothing: check the token with
|
|
225
|
+
* {@link checkRefreshToken} first.
|
|
226
|
+
*/
|
|
227
|
+
export async function revokeRefreshToken(config: AppleConfig, clientId: string, refreshToken: string, fetchImpl: typeof fetch = fetch): Promise<RevokeResult> {
|
|
228
|
+
const res = await postForm(fetchImpl, APPLE_REVOKE_URL, {
|
|
229
|
+
client_id: clientId,
|
|
230
|
+
client_secret: await appleClientSecret(config, clientId),
|
|
231
|
+
token: refreshToken,
|
|
232
|
+
token_type_hint: "refresh_token",
|
|
233
|
+
});
|
|
234
|
+
if (!res) return { ok: false, error: "network" };
|
|
235
|
+
if (res.status === 200) return { ok: true };
|
|
236
|
+
return { ok: false, error: await appleError(res), status: res.status };
|
|
237
|
+
}
|