create-signet-app 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/base/api/api/app.ts +15 -1
  2. package/base/api/api/env.ts +4 -0
  3. package/base/api/api/services.ts +55 -1
  4. package/base/web/src/routes/_app.tsx +6 -3
  5. package/package.json +3 -2
  6. package/parts/auth/api/api/routes/auth.ts +31 -8
  7. package/parts/mobile/api/api/routes/mobile.ts +71 -0
  8. package/parts/mobile/api/test/mobile.test.ts +104 -0
  9. package/parts/mobile/part.ts +11 -0
  10. package/parts/pwa/web/public/icon-192.png +0 -0
  11. package/parts/pwa/web/public/icon-512.png +0 -0
  12. package/parts/pwa/web/public/icon-maskable-512.png +0 -0
  13. package/parts/pwa/web/public/manifest.webmanifest +11 -1
  14. package/parts/pwa/web/public/sw.js +8 -1
  15. package/src/compose.ts +15 -4
  16. package/src/index.ts +53 -13
  17. package/src/mobile.ts +58 -0
  18. package/src/picker.ts +21 -8
  19. package/template-mobile/README.md +139 -0
  20. package/template-mobile/_github/workflows/ci.yml +38 -0
  21. package/template-mobile/_gitignore +1 -0
  22. package/template-mobile/mobile/_gitignore +16 -0
  23. package/template-mobile/mobile/app.config.ts +77 -0
  24. package/template-mobile/mobile/assets/adaptive-icon.png +0 -0
  25. package/template-mobile/mobile/assets/icon.png +0 -0
  26. package/template-mobile/mobile/assets/notification-icon.png +0 -0
  27. package/template-mobile/mobile/assets/splash-icon.png +0 -0
  28. package/template-mobile/mobile/babel.config.js +4 -0
  29. package/template-mobile/mobile/biome.json +8 -0
  30. package/template-mobile/mobile/eas.json +27 -0
  31. package/template-mobile/mobile/expo-env.d.ts +1 -0
  32. package/template-mobile/mobile/jest.config.js +9 -0
  33. package/template-mobile/mobile/jest.setup.js +32 -0
  34. package/template-mobile/mobile/src/__tests__/auth-gate.test.tsx +40 -0
  35. package/template-mobile/mobile/src/__tests__/sign-in.test.tsx +41 -0
  36. package/template-mobile/mobile/src/app/(app)/_layout.tsx +48 -0
  37. package/template-mobile/mobile/src/app/(app)/devices/[id].tsx +62 -0
  38. package/template-mobile/mobile/src/app/(app)/devices/_layout.tsx +19 -0
  39. package/template-mobile/mobile/src/app/(app)/devices/index.tsx +40 -0
  40. package/template-mobile/mobile/src/app/(app)/index.tsx +69 -0
  41. package/template-mobile/mobile/src/app/(app)/settings.tsx +116 -0
  42. package/template-mobile/mobile/src/app/(auth)/_layout.tsx +19 -0
  43. package/template-mobile/mobile/src/app/(auth)/sign-in.tsx +49 -0
  44. package/template-mobile/mobile/src/app/(auth)/verify.tsx +62 -0
  45. package/template-mobile/mobile/src/app/_layout.tsx +95 -0
  46. package/template-mobile/mobile/src/components/ui.tsx +230 -0
  47. package/template-mobile/mobile/src/lib/analytics.ts +20 -0
  48. package/template-mobile/mobile/src/lib/api.ts +49 -0
  49. package/template-mobile/mobile/src/lib/auth.ts +43 -0
  50. package/template-mobile/mobile/src/lib/config.ts +14 -0
  51. package/template-mobile/mobile/src/lib/devices.ts +18 -0
  52. package/template-mobile/mobile/src/lib/outbox.ts +84 -0
  53. package/template-mobile/mobile/src/lib/polyfills.ts +6 -0
  54. package/template-mobile/mobile/src/lib/push.ts +97 -0
  55. package/template-mobile/mobile/src/lib/session.ts +39 -0
  56. package/template-mobile/mobile/src/lib/storage.ts +17 -0
  57. package/template-mobile/mobile/src/lib/theme.tsx +64 -0
  58. package/template-mobile/mobile/tsconfig.json +11 -0
package/src/index.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import { existsSync } from "node:fs"
14
- import { cp, mkdir, readdir, readFile, rename, writeFile } from "node:fs/promises"
14
+ import { cp, mkdir, readdir, readFile, rename, rm, writeFile } from "node:fs/promises"
15
15
  import { basename, join, resolve } from "node:path"
16
16
  import {
17
17
  cancel,
@@ -38,6 +38,7 @@ import {
38
38
  type StarterName,
39
39
  } from "./compose.js"
40
40
  import { appId, DESKTOP_PKG } from "./desktop.js"
41
+ import { MOBILE_PKG, MOBILE_PMS } from "./mobile.js"
41
42
  import {
42
43
  answer,
43
44
  choose,
@@ -54,6 +55,7 @@ import {
54
55
  THEME_LABELS,
55
56
  ticked,
56
57
  WHAT,
58
+ type What,
57
59
  } from "./picker.js"
58
60
 
59
61
  const THEMES = ["editorial", "cinematic", "finance"] as const
@@ -453,6 +455,8 @@ Composed apps (a web app and its API from parts; any of these flags):
453
455
  ${STARTER_NAMES.map((s) => ` ${s.padEnd(14)}${STARTERS[s].description}`).join("\n")}
454
456
  --with <parts> comma-separated parts to add; the parts they need come too
455
457
  --without <parts> parts to leave out (alone: the full starter without them)
458
+ mobile is an Expo app (iOS, Android) in mobile/ and its API
459
+ in server/; --with and --without change the API's parts
456
460
  --ui the web half only; it calls an API elsewhere (VITE_API_URL)
457
461
  --api the API half only (Hono on Bun, SQLite)
458
462
  neither: both halves
@@ -487,6 +491,7 @@ Examples:
487
491
  bun create-signet-app my-app --with payments,notifications
488
492
  bun create-signet-app my-app --without admin,privacy
489
493
  bun create-signet-app my-api --api --with orgs
494
+ bun create-signet-app my-app --starter mobile
490
495
  bun create-signet-app my-cli --platform cli
491
496
  npm create signet-app my-app -- --starter full --pm npm
492
497
  bun create-signet-app my-app --describe "a team inbox with settings and pricing"
@@ -592,6 +597,7 @@ async function substitute(dir: string, vars: Record<string, string>) {
592
597
  await substitute(full, vars)
593
598
  continue
594
599
  }
600
+ if (entry.name.endsWith(".png")) continue // binary: utf8 would corrupt it
595
601
  let text = await readFile(full, "utf8")
596
602
  let changed = false
597
603
  for (const [k, v] of Object.entries(vars)) {
@@ -636,14 +642,15 @@ async function askName(): Promise<string> {
636
642
  */
637
643
  async function askWhat(themeGiven?: Theme, mcpGiven?: boolean) {
638
644
  const what = ask(
639
- await select<Platform>({
645
+ await select<What>({
640
646
  message: "What are you building?",
641
647
  initialValue: "web",
642
648
  options: WHAT,
643
649
  }),
644
650
  )
645
651
  let choice = choose(what)
646
- let ticks: PartName[] = []
652
+ // The mobile starter's API parts, for the summary.
653
+ let ticks: PartName[] = what === "mobile" ? ticked("mobile") : []
647
654
  if (what === "web" || what === "api") {
648
655
  const mix = ask(
649
656
  await select<Mix>({ message: "Start from", initialValue: "basics", options: mixRows(what) }),
@@ -713,9 +720,14 @@ async function pickParts(c: ComposeFlags, mcpFlag: boolean | undefined) {
713
720
  const flagged = c.ui || c.api || c.with.length > 0 || c.without.length > 0
714
721
  const starter =
715
722
  c.starter ?? (!flagged || (!c.with.length && c.without.length) ? "full" : undefined)
716
- const apiStarter = starter !== undefined && "surface" in STARTERS[starter]
723
+ const surface =
724
+ starter !== undefined && "surface" in STARTERS[starter] && STARTERS[starter].surface
725
+ const apiStarter = surface === "api"
726
+ const mobile = surface === "mobile"
717
727
  if (apiStarter && c.ui) throw new Error(`--starter ${starter} is the API only: drop --ui.`)
718
- const web = !c.api && !apiStarter
728
+ if (mobile && (c.ui || c.api))
729
+ throw new Error("--starter mobile makes the app and its API (in server/): drop --ui and --api.")
730
+ const web = !c.api && !apiStarter && !mobile
719
731
  const api = !c.ui
720
732
  // A UI-only app takes the starter's parts that have a web half.
721
733
  const base = starter ? STARTERS[starter].parts.filter((p) => api || !PARTS[p].apiOnly) : []
@@ -730,7 +742,7 @@ async function pickParts(c: ComposeFlags, mcpFlag: boolean | undefined) {
730
742
  if (PARTS[p].apiOnly && !api) throw new Error(`${p} needs the API: drop --ui, or ${p}.`)
731
743
  if (PARTS[p].webOnly && !web) throw new Error(`${p} is web only: drop --api, or ${p}.`)
732
744
  }
733
- return { parts, added, web, api, starter }
745
+ return { parts, added, web, api, starter, mobile }
734
746
  }
735
747
 
736
748
  function composedMessage(
@@ -828,10 +840,22 @@ async function main() {
828
840
  const mcp = composed
829
841
  ? composed.parts.includes("mcp")
830
842
  : template === "api" && (flags.mcp ?? (await askMcp()))
843
+ const mobile = composed?.mobile ?? false
844
+ if (mobile && !(MOBILE_PMS as readonly string[]).includes(pm))
845
+ throw new Error(`--starter mobile is set up for --pm ${MOBILE_PMS.join(" or ")}.`)
831
846
  await mkdir(dest, { recursive: true })
832
847
  const runtime = (parsed.targetGiven ?? "bun") as Runtime
833
- const made = composed ? await compose(dest, { ...composed, runtime }, BASE) : undefined
848
+ // The mobile starter: the API half in server/, the Expo app in mobile/.
849
+ const apiDir = mobile ? join(dest, "server") : dest
850
+ const made = composed ? await compose(apiDir, { ...composed, runtime }, BASE) : undefined
834
851
  if (!composed) await copyPlatform(template as Platform, dest, target, mcp)
852
+ if (mobile) {
853
+ await cp(resolve(import.meta.dirname, "../template-mobile"), dest, { recursive: true })
854
+ await rename(join(apiDir, "_gitignore"), join(apiDir, ".gitignore"))
855
+ await rename(join(dest, "mobile/_gitignore"), join(dest, "mobile/.gitignore"))
856
+ // One workflow at the root checks both projects.
857
+ await rm(join(apiDir, "_github"), { recursive: true })
858
+ }
835
859
 
836
860
  // npm strips a file literally named .gitignore from published packages, so
837
861
  // the template ships it as _gitignore and it is renamed on scaffold.
@@ -867,7 +891,7 @@ async function main() {
867
891
  if (made?.env.length)
868
892
  // The API's secrets for this machine, fresh per app; gitignored. Bun loads
869
893
  // it on its own. Production sets these on the host instead.
870
- await writeFile(join(dest, ".env"), made.env.join("\n"))
894
+ await writeFile(join(apiDir, ".env"), made.env.join("\n"))
871
895
 
872
896
  // signet-mcp's index reads the scripts below from this source by their
873
897
  // shape: the api object first, the web object as the next literal.
@@ -913,7 +937,7 @@ async function main() {
913
937
  ? JSON.parse(JSON.stringify(CLI_PKG).replaceAll("__APP_NAME__", appName))
914
938
  : pkg
915
939
  const out = {
916
- name: appName,
940
+ name: mobile ? `${appName}-server` : appName,
917
941
  private: true,
918
942
  version: "0.1.0",
919
943
  type: "module",
@@ -926,10 +950,15 @@ async function main() {
926
950
  if (pm === "yarn" && out.dependencies?.["@dapplelight/signet-ui"])
927
951
  out.dependencies = sortDeps({ ...UI_PEERS, ...out.dependencies })
928
952
  await writeFile(
929
- join(dest, "package.json"),
953
+ join(apiDir, "package.json"),
930
954
  `${JSON.stringify(out, null, 2)}
931
955
  `,
932
956
  )
957
+ if (mobile)
958
+ await writeFile(
959
+ join(dest, "mobile/package.json"),
960
+ `${JSON.stringify({ name: `${appName}-mobile`, private: true, version: "0.1.0", ...MOBILE_PKG }, null, 2)}\n`,
961
+ )
933
962
 
934
963
  const { install, run } = PM[pm]
935
964
  if (described && parsed.describe) {
@@ -979,9 +1008,20 @@ async function main() {
979
1008
  Needs Rust and Tauri's system dependencies. README.md covers sign-in (register
980
1009
  the client on signet-server) and the identifier in src-tauri/tauri.conf.json.
981
1010
  `
982
- : composed
983
- ? composedMessage(appName, theme, steps, composed)
984
- : `
1011
+ : mobile && composed
1012
+ ? `
1013
+ Created ${appName}: an Expo app in mobile/ and its API in server/.
1014
+ Parts (server): ${composed.parts.join(", ")}.
1015
+
1016
+ cd ${name}/server && ${install} && ${run} dev
1017
+ cd ${name}/mobile && ${install} && ${run} start (in a second terminal)
1018
+
1019
+ Sign in with any phone number; in development the code is printed in the
1020
+ server's terminal. README.md covers phones on your network, builds and push.
1021
+ `
1022
+ : composed
1023
+ ? composedMessage(appName, theme, steps, composed)
1024
+ : `
985
1025
  Created ${appName} with the ${theme} theme.
986
1026
 
987
1027
  ${steps}
package/src/mobile.ts ADDED
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The mobile starter: an Expo app in mobile/ (template-mobile) beside its API
3
+ * in server/ (the composed API half, as `--api` makes it). Two projects, not
4
+ * one: Metro and React Native's toolchain (jest-expo, TypeScript 6) and the
5
+ * Bun API (bun test, TypeScript 7) each keep their own dependencies.
6
+ */
7
+
8
+ /** Expo SDK 58's versions, as `npx expo install` picks them (expo's bundledNativeModules.json). */
9
+ export const MOBILE_PKG = {
10
+ main: "expo-router/entry",
11
+ scripts: {
12
+ start: "expo start",
13
+ android: "expo start --android",
14
+ ios: "expo start --ios",
15
+ lint: "biome check .",
16
+ format: "biome check --write .",
17
+ typecheck: "tsc --noEmit",
18
+ test: "jest",
19
+ },
20
+ dependencies: {
21
+ "@dapplelight/signet-lib": "^0.4.2",
22
+ "@dapplelight/signet-tokens": "^0.4.0",
23
+ "@expo/vector-icons": "^15.0.2",
24
+ "@tanstack/react-query": "^5.108.0",
25
+ expo: "~58.0.26",
26
+ "expo-constants": "~58.0.16",
27
+ "expo-crypto": "~58.0.8",
28
+ "expo-dev-client": "~58.0.21",
29
+ "expo-linking": "~58.0.17",
30
+ "expo-network": "~58.0.5",
31
+ "expo-notifications": "~58.1.9",
32
+ "expo-router": "~58.0.32",
33
+ "expo-secure-store": "~58.0.3",
34
+ "expo-splash-screen": "~58.0.14",
35
+ "expo-sqlite": "~58.0.18",
36
+ "expo-status-bar": "~58.0.5",
37
+ "expo-system-ui": "~58.0.7",
38
+ "expo-updates": "~58.0.22",
39
+ react: "19.3.0",
40
+ "react-native": "0.88.1",
41
+ "react-native-safe-area-context": "~5.11.1",
42
+ "react-native-screens": "~4.30.1",
43
+ },
44
+ devDependencies: {
45
+ "@biomejs/biome": "^2.5.14",
46
+ "@dapplelight/signet-config": "^0.2.2",
47
+ "@react-native/jest-preset": "~0.88.1",
48
+ "@testing-library/react-native": "^14.1.0",
49
+ "@types/react": "~19.3.0",
50
+ jest: "^30.5.2",
51
+ "jest-expo": "~58.0.15",
52
+ "test-renderer": "^1.3.1",
53
+ typescript: "~6.0.3",
54
+ },
55
+ }
56
+
57
+ /** Package managers the mobile starter is set up for; Expo needs a plain node_modules. */
58
+ export const MOBILE_PMS = ["bun", "npm"] as const
package/src/picker.ts CHANGED
@@ -12,6 +12,7 @@ import { resolve } from "node:path"
12
12
  import {
13
13
  PART_NAMES,
14
14
  PARTS,
15
+ type Part,
15
16
  type PartName,
16
17
  resolveParts,
17
18
  STARTERS,
@@ -21,9 +22,13 @@ import {
21
22
  export const PLATFORMS = ["web", "api", "cli", "extension", "desktop"] as const
22
23
  export type Platform = (typeof PLATFORMS)[number]
23
24
 
24
- export const WHAT: { value: Platform; label: string }[] = [
25
+ /** Step 1's answers: a platform, or the mobile starter (an Expo app and its API). */
26
+ export type What = Platform | "mobile"
27
+
28
+ export const WHAT: { value: What; label: string }[] = [
25
29
  { value: "web", label: "Web app — a site people open in a browser" },
26
30
  { value: "api", label: "API only — a server other apps talk to" },
31
+ { value: "mobile", label: "Mobile app — iOS and Android, with its API" },
27
32
  { value: "cli", label: "Command-line tool — runs in a terminal" },
28
33
  { value: "extension", label: "Browser extension — a Chrome add-on" },
29
34
  { value: "desktop", label: "Desktop app — Mac, Windows and Linux" },
@@ -33,12 +38,16 @@ export const WHAT: { value: Platform; label: string }[] = [
33
38
  export type Mix = "basics" | StarterName
34
39
 
35
40
  const STARTER_NAMES = Object.keys(STARTERS) as StarterName[]
36
- const apiStarter = (s: StarterName) => "surface" in STARTERS[s]
41
+ const surfaceOf = (s: StarterName) =>
42
+ (STARTERS[s] as { surface?: "api" | "mobile" }).surface ?? "both"
43
+ const apiStarter = (s: StarterName) => surfaceOf(s) === "api"
37
44
 
38
- /** The starters offered on a path: the API ones for api, the rest for web; full on both, last. */
45
+ /** The starters offered on a path: the API ones for api, web + API ones for web; full on both, last. */
39
46
  function startersFor(what: "web" | "api"): StarterName[] {
40
47
  const ends: StarterName[] = what === "web" ? ["blank", "full"] : ["full"]
41
- const rest = STARTER_NAMES.filter((s) => !ends.includes(s) && (what === "api") === apiStarter(s))
48
+ const rest = STARTER_NAMES.filter(
49
+ (s) => !ends.includes(s) && surfaceOf(s) === (what === "api" ? "api" : "both"),
50
+ )
42
51
  return [...rest, ...ends]
43
52
  }
44
53
 
@@ -71,6 +80,7 @@ const PART_LABELS: Record<Exclude<PartName, "mcp">, string> = {
71
80
  workflows: "Approvals — multi-step jobs people sign off",
72
81
  dashboard: "Dashboard — sidebar, stats, a chart, a table",
73
82
  pwa: "Installable — works offline",
83
+ mobile: "Mobile API — token sign-in, push tokens",
74
84
  }
75
85
  const partLabel = (p: PartName) => PART_LABELS[p as Exclude<PartName, "mcp">]
76
86
 
@@ -106,7 +116,8 @@ const same = (a: readonly string[], b: readonly string[]) =>
106
116
  * `--with`, plus `--api` on the API path. Nothing ticked from the basics, or
107
117
  * nothing that matches a starter, is the platform alone.
108
118
  */
109
- export function choose(what: Platform, mix: Mix = "basics", ticks: PartName[] = []): Choice {
119
+ export function choose(what: What, mix: Mix = "basics", ticks: PartName[] = []): Choice {
120
+ if (what === "mobile") return { template: "full", starter: "mobile" }
110
121
  if (what !== "web" && what !== "api") return { template: what }
111
122
  if (mix === "basics" && !ticks.length) return { template: what }
112
123
  const api = what === "api" ? ({ api: true } as const) : {}
@@ -114,7 +125,9 @@ export function choose(what: Platform, mix: Mix = "basics", ticks: PartName[] =
114
125
  const starter = order.find((s) => same(installed(STARTERS[s].parts), installed(ticks)))
115
126
  if (starter) return { template: "full", starter, ...(apiStarter(starter) ? {} : api) }
116
127
  if (!ticks.length) return { template: what }
117
- return { template: "full", with: ticks, ...api }
128
+ // Needs are implied by what needs them, so the command leaves them out.
129
+ const needed = new Set(ticks.flatMap((p) => (PARTS[p] as Part).needs ?? []))
130
+ return { template: "full", with: ticks.filter((p) => !needed.has(p)), ...api }
118
131
  }
119
132
 
120
133
  /** The one-line command that scaffolds the same app, so the picker teaches the flags. */
@@ -139,7 +152,7 @@ export function command(
139
152
 
140
153
  /** The summary shown before creating: what, which mix, the parts installed (needs too), theme, MCP. */
141
154
  export function summary(
142
- what: Platform,
155
+ what: What,
143
156
  c: Choice,
144
157
  ticks: PartName[],
145
158
  theme?: string,
@@ -178,7 +191,7 @@ export async function answer<T>(
178
191
 
179
192
  /** MCP applies where there is an API; the theme where there is a web UI. */
180
193
  export const hasApi = (c: Choice) => c.template === "api" || c.template === "full"
181
- export const hasUi = (what: Platform) => what !== "api" && what !== "cli"
194
+ export const hasUi = (what: What) => what !== "api" && what !== "cli"
182
195
 
183
196
  /** Why a typed project name can't be used, or undefined; empty is the default, my-app. */
184
197
  export function nameError(typed: string | undefined, cwd: string): string | undefined {
@@ -0,0 +1,139 @@
1
+ # __APP_NAME__
2
+
3
+ An iOS and Android app on [Expo](https://expo.dev) and its API, on Signet.
4
+
5
+ ```
6
+ mobile/ the Expo app: Expo Router, phone sign-in, tabs, push, offline writes
7
+ server/ the API: Hono on Bun with SQLite (its own README covers the API)
8
+ ```
9
+
10
+ Two projects, each with its own `package.json`: React Native's toolchain and
11
+ the API's never share a dependency tree.
12
+
13
+ ## Run it
14
+
15
+ In one terminal, the API (port 3000):
16
+
17
+ ```sh
18
+ cd server
19
+ __PM_INSTALL__
20
+ __PM_RUN__ dev
21
+ ```
22
+
23
+ In another, the app:
24
+
25
+ ```sh
26
+ cd mobile
27
+ __PM_INSTALL__
28
+ __PM_RUN__ start
29
+ ```
30
+
31
+ Press `i` for the iOS simulator or `a` for the Android emulator. Sign in with
32
+ any phone number: in development no text is sent, and the code is printed in
33
+ the API's terminal.
34
+
35
+ The app reaches the API at `EXPO_PUBLIC_API_URL`, `http://localhost:3000` by
36
+ default, which works on the iOS simulator. Elsewhere, point it at your machine:
37
+
38
+ ```sh
39
+ EXPO_PUBLIC_API_URL=http://10.0.2.2:3000 __PM_RUN__ start # Android emulator
40
+ EXPO_PUBLIC_API_URL=http://192.168.1.20:3000 __PM_RUN__ start # a phone on your Wi-Fi
41
+ ```
42
+
43
+ Expo Go runs everything here except push notifications, which need a
44
+ development build (below).
45
+
46
+ ## What is in the app
47
+
48
+ - **Sign-in**: phone, then the code (`src/app/(auth)`). The API answers
49
+ `POST /api/auth/verify?client_id=mobile` with a token pair instead of a cookie;
50
+ the tokens live in the Keychain / Keystore (`expo-secure-store`) through
51
+ `@dapplelight/signet-lib/session`, which refreshes the access token before it
52
+ expires.
53
+ - **The auth gate** (`src/app/_layout.tsx`): signed in shows the tabs, signed out
54
+ shows sign-in. A 401 that a refresh cannot fix clears the session, and the
55
+ gate flips. Sign-out revokes the session on the API, drops the push token, and
56
+ forgets cached data and queued writes.
57
+ - **Tabs** (`src/app/(app)`): Home (your name, saved offline if need be),
58
+ Devices (the sample list and detail: where you are signed in, pull to refresh,
59
+ loading, empty and error states, sign a device out) and Settings (theme,
60
+ light or dark, notifications, sign out, the app's version).
61
+ - **Offline writes** (`src/lib/outbox.ts`): a write that cannot reach the API is
62
+ queued (`@dapplelight/signet-lib/offline`) and sent when the network returns.
63
+ Send each write with the `Idempotency-Key` it carries, so a retry is harmless.
64
+ - **Theme**: every colour and size comes from `@dapplelight/signet-tokens/native`.
65
+ Light and dark follow the phone unless Settings overrides it. The default
66
+ theme is in `src/lib/theme.tsx`.
67
+ - **Errors**: `ErrorBoundary` in `src/app/_layout.tsx` catches a screen that
68
+ throws; API refusals show the server's message, everything else Signet's copy.
69
+
70
+ ## Environment
71
+
72
+ The app reads these at build time (`app.config.ts`); put them in `mobile/.env`
73
+ for local runs, or in an EAS environment for builds.
74
+
75
+ | Variable | What |
76
+ |---|---|
77
+ | `EXPO_PUBLIC_API_URL` | The API's origin. Default `http://localhost:3000`. |
78
+ | `EXPO_PUBLIC_ANALYTICS_URL` | Where screen-view events are posted in batches. Unset: none are sent. |
79
+ | `EAS_PROJECT_ID` | Your Expo project, after `eas init`. Push tokens and updates need it. |
80
+ | `APP_LINK_DOMAIN` | Your site's domain, for universal links / app links. |
81
+
82
+ The API's are in `server/.env` (written with fresh secrets) and
83
+ `server/api/env.ts`. `EXPO_ACCESS_TOKEN` is the one the app adds.
84
+
85
+ ## Deep links
86
+
87
+ The scheme is `__APP_ID__`: `__APP_ID__://devices` opens the Devices tab. To
88
+ open https links in the app, set `APP_LINK_DOMAIN` and serve the
89
+ `apple-app-site-association` and `assetlinks.json` files from that domain (see
90
+ Expo's "Universal links" and "Android App Links" guides).
91
+
92
+ ## Builds (EAS)
93
+
94
+ ```sh
95
+ __PM_X__ eas-cli login
96
+ __PM_X__ eas-cli init # creates the project; put its id in EAS_PROJECT_ID
97
+ __PM_X__ eas-cli build --profile development --platform ios # or android
98
+ ```
99
+
100
+ `eas.json` has three profiles: `development` (a development build with the dev
101
+ client, for push and native debugging), `preview` (an internal build to share)
102
+ and `production` (store builds, version numbers kept by EAS). Change the
103
+ placeholder `com.example.__APP_ID__` identifier in `app.config.ts`, and the
104
+ icon and splash in `assets/`, before the first store build.
105
+
106
+ Updates: `expo-updates` checks for an update on launch. Publish one with
107
+ `__PM_X__ eas-cli update --channel production`; it reaches builds of the same app
108
+ version (`runtimeVersion` follows the version in `app.config.ts`).
109
+
110
+ ## Push notifications
111
+
112
+ 1. Make a development build (above); Expo Go cannot receive them.
113
+ 2. Set `EAS_PROJECT_ID`. On Android, add your Firebase project's credentials
114
+ with `eas credentials`; on iOS, EAS creates the push key when you build.
115
+ 3. In the app: Settings, Turn on notifications. The app sends its Expo push
116
+ token to `POST /api/mobile/push/token`.
117
+ 4. Settings, Send a test notification: the API sends one through Expo's push
118
+ service; tapping it opens Devices.
119
+
120
+ The API sends with `expoPushSender` from `@dapplelight/signet-server/notify/channels`
121
+ (`server/api/services.ts`). With the notifications part, any template with a
122
+ `push` variant reaches the phone. Turn on push security in your Expo project
123
+ and set `EXPO_ACCESS_TOKEN` on the API before you ship. A notification's `url`
124
+ must be one of the screens listed in `src/lib/push.ts` to be opened.
125
+
126
+ ## Analytics
127
+
128
+ Every screen sends a `screen_view` event (`src/lib/analytics.ts`) when
129
+ `EXPO_PUBLIC_ANALYTICS_URL` is set. The API has no ingest route yet: add one
130
+ with `@dapplelight/signet-server/analytics`, or point the URL at your own.
131
+
132
+ ## Checks
133
+
134
+ ```sh
135
+ cd mobile && __PM_RUN__ lint && __PM_RUN__ typecheck && __PM_RUN__ test
136
+ cd server && __PM_RUN__ lint && __PM_RUN__ typecheck && __PM_RUN__ test
137
+ ```
138
+
139
+ CI (`.github/workflows/ci.yml`) runs both.
@@ -0,0 +1,38 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ server:
13
+ runs-on: ubuntu-latest
14
+ defaults:
15
+ run:
16
+ working-directory: server
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+ - uses: oven-sh/setup-bun@v2
20
+ # Commit bun.lock: --frozen-lockfile fails the build if it is missing or stale.
21
+ - run: bun install --frozen-lockfile
22
+ - run: bun run lint
23
+ - run: bun run typecheck
24
+ - run: bun run test
25
+
26
+ mobile:
27
+ runs-on: ubuntu-latest
28
+ defaults:
29
+ run:
30
+ working-directory: mobile
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ - uses: oven-sh/setup-bun@v2
34
+ # Commit bun.lock: --frozen-lockfile fails the build if it is missing or stale.
35
+ - run: bun install --frozen-lockfile
36
+ - run: bun run lint
37
+ - run: bun run typecheck
38
+ - run: bun run test
@@ -0,0 +1 @@
1
+ .DS_Store
@@ -0,0 +1,16 @@
1
+ node_modules
2
+ .expo
3
+ dist
4
+ web-build
5
+ ios
6
+ android
7
+ *.jks
8
+ *.p8
9
+ *.p12
10
+ *.key
11
+ *.mobileprovision
12
+ *.orig.*
13
+ .env
14
+ .env.local
15
+ coverage
16
+ .DS_Store
@@ -0,0 +1,77 @@
1
+ import type { ConfigContext, ExpoConfig } from "expo/config"
2
+
3
+ // Set after `eas init` (README, "Builds"): push tokens and over-the-air updates need it.
4
+ const projectId = process.env.EAS_PROJECT_ID
5
+ // Your site's domain, e.g. "app.example.com", once it serves the iOS and Android
6
+ // association files: then https links to it open the app (universal / app links).
7
+ const linkDomain = process.env.APP_LINK_DOMAIN
8
+ // Grey of the placeholder icon; change it with the icon.
9
+ const brand = "#4b5563"
10
+
11
+ export default ({ config }: ConfigContext): ExpoConfig => ({
12
+ ...config,
13
+ name: "__APP_NAME__",
14
+ slug: "__APP_NAME__",
15
+ version: "0.1.0",
16
+ orientation: "portrait",
17
+ icon: "./assets/icon.png",
18
+ // Deep links: __APP_ID__://devices opens the Devices tab.
19
+ scheme: "__APP_ID__",
20
+ userInterfaceStyle: "automatic",
21
+ ios: {
22
+ // A placeholder: use your own reverse domain before the first store build.
23
+ bundleIdentifier: "com.example.__APP_ID__",
24
+ supportsTablet: true,
25
+ ...(linkDomain ? { associatedDomains: [`applinks:${linkDomain}`] } : {}),
26
+ },
27
+ android: {
28
+ package: "com.example.__APP_ID__",
29
+ adaptiveIcon: { foregroundImage: "./assets/adaptive-icon.png", backgroundColor: brand },
30
+ ...(linkDomain
31
+ ? {
32
+ intentFilters: [
33
+ {
34
+ action: "VIEW",
35
+ autoVerify: true,
36
+ data: [{ scheme: "https", host: linkDomain }],
37
+ category: ["BROWSABLE", "DEFAULT"],
38
+ },
39
+ ],
40
+ }
41
+ : {}),
42
+ },
43
+ plugins: [
44
+ "expo-router",
45
+ [
46
+ "expo-splash-screen",
47
+ {
48
+ image: "./assets/splash-icon.png",
49
+ imageWidth: 160,
50
+ backgroundColor: "#ffffff",
51
+ dark: { backgroundColor: "#111111" },
52
+ },
53
+ ],
54
+ "expo-secure-store",
55
+ "expo-sqlite",
56
+ ["expo-notifications", { icon: "./assets/notification-icon.png", color: brand }],
57
+ ],
58
+ experiments: { typedRoutes: true },
59
+ // An update only reaches builds of the same app version.
60
+ runtimeVersion: { policy: "appVersion" },
61
+ ...(projectId
62
+ ? {
63
+ updates: {
64
+ url: `https://u.expo.dev/${projectId}`,
65
+ checkAutomatically: "ON_LOAD",
66
+ fallbackToCacheTimeout: 0,
67
+ },
68
+ }
69
+ : {}),
70
+ extra: {
71
+ // The API the app talks to. Android's emulator reaches your machine at 10.0.2.2.
72
+ apiUrl: process.env.EXPO_PUBLIC_API_URL ?? "http://localhost:3000",
73
+ // Where screen-view events go; unset, none are sent (README, "Analytics").
74
+ analyticsUrl: process.env.EXPO_PUBLIC_ANALYTICS_URL,
75
+ ...(projectId ? { eas: { projectId } } : {}),
76
+ },
77
+ })
@@ -0,0 +1,4 @@
1
+ module.exports = (api) => {
2
+ api.cache(true)
3
+ return { presets: ["babel-preset-expo"] }
4
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3
+ "extends": ["@dapplelight/signet-config/biome"],
4
+ "files": {
5
+ "ignoreUnknown": true,
6
+ "includes": ["**", "!.expo", "!ios", "!android", "!coverage", "!**/*.md"]
7
+ }
8
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "cli": {
3
+ "version": ">= 16.0.0",
4
+ "appVersionSource": "remote"
5
+ },
6
+ "build": {
7
+ "development": {
8
+ "developmentClient": true,
9
+ "distribution": "internal",
10
+ "channel": "development"
11
+ },
12
+ "preview": {
13
+ "distribution": "internal",
14
+ "channel": "preview",
15
+ "android": {
16
+ "buildType": "apk"
17
+ }
18
+ },
19
+ "production": {
20
+ "channel": "production",
21
+ "autoIncrement": true
22
+ }
23
+ },
24
+ "submit": {
25
+ "production": {}
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="expo/types" />
@@ -0,0 +1,9 @@
1
+ const [modules, ...rest] = require("jest-expo/jest-preset").transformIgnorePatterns
2
+
3
+ module.exports = {
4
+ preset: "jest-expo",
5
+ setupFiles: ["<rootDir>/jest.setup.js"],
6
+ moduleNameMapper: { "^@/(.*)$": "<rootDir>/src/$1" },
7
+ // jest-expo's list, plus Signet's packages: they ship ES modules.
8
+ transformIgnorePatterns: [modules.replace("(?!(", "(?!(@dapplelight|"), ...rest],
9
+ }