@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.
Files changed (139) hide show
  1. package/README.md +224 -3
  2. package/dist/cli.js +4602 -1549
  3. package/dist/cli.js.map +1 -1
  4. package/dist/{config-Ci-_Ue-1.d.ts → config-CrZbM3jD.d.ts} +73 -4
  5. package/dist/doctor.d.ts +31 -4
  6. package/dist/doctor.js +976 -30
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/expo.d.ts +91 -8
  9. package/dist/expo.js +207 -14
  10. package/dist/expo.js.map +1 -1
  11. package/dist/genesis-catalog.json +502 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +987 -38
  14. package/dist/index.js.map +1 -1
  15. package/dist/scaffolder.d.ts +1 -1
  16. package/dist/scaffolder.js +9 -6
  17. package/dist/scaffolder.js.map +1 -1
  18. package/dist/starter/.eas/scripts/rollout-health.mjs +85 -0
  19. package/dist/starter/.eas/workflows/deploy-production.yml +149 -0
  20. package/dist/starter/.eas/workflows/e2e.yml +77 -0
  21. package/dist/starter/.eas/workflows/pr-preview.yml +117 -0
  22. package/dist/starter/.eas/workflows/rollout.yml +120 -0
  23. package/dist/starter/.env.example +11 -0
  24. package/dist/starter/.fingerprintignore +7 -0
  25. package/dist/starter/.maestro/README.md +38 -0
  26. package/dist/starter/.maestro/config.yaml +5 -0
  27. package/dist/starter/.maestro/flows/deep-link.yaml +22 -0
  28. package/dist/starter/.maestro/flows/launch.yaml +17 -0
  29. package/dist/starter/.maestro/flows/settings-version.yaml +28 -0
  30. package/dist/starter/.maestro/flows/sign-in-screen.yaml +17 -0
  31. package/dist/starter/.maestro/subflows/sign-in.yaml +20 -0
  32. package/dist/starter/README.md +314 -0
  33. package/dist/starter/__tests__/app-config.test.ts +51 -0
  34. package/dist/starter/__tests__/check-in-photos.test.ts +57 -0
  35. package/dist/starter/__tests__/components/css-stub.js +2 -0
  36. package/dist/starter/__tests__/components/fake-supabase.ts +136 -0
  37. package/dist/starter/__tests__/components/links.test.ts +25 -0
  38. package/dist/starter/__tests__/components/render-app.ts +22 -0
  39. package/dist/starter/__tests__/components/reports.ts +10 -0
  40. package/dist/starter/__tests__/components/resolver.js +12 -0
  41. package/dist/starter/__tests__/components/root-layout.test.tsx +55 -0
  42. package/dist/starter/__tests__/components/session-storage.test.tsx +81 -0
  43. package/dist/starter/__tests__/components/settings.test.tsx +134 -0
  44. package/dist/starter/__tests__/components/setup.ts +69 -0
  45. package/dist/starter/__tests__/components/sign-in.test.tsx +90 -0
  46. package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +19 -0
  47. package/dist/starter/__tests__/components/tabs.test.tsx +43 -0
  48. package/dist/starter/__tests__/components/tabs.ts +12 -0
  49. package/dist/starter/__tests__/entry.test.ts +28 -0
  50. package/dist/starter/__tests__/inline-copy.ts +59 -0
  51. package/dist/starter/__tests__/starter.test.ts +319 -0
  52. package/dist/starter/_gitignore +13 -0
  53. package/dist/starter/app.config.ts +44 -0
  54. package/dist/starter/babel.config.js +9 -0
  55. package/dist/starter/eas.json +47 -0
  56. package/dist/starter/eslint.config.js +5 -0
  57. package/dist/starter/genesis.config.json +12 -0
  58. package/dist/starter/global.css +3 -0
  59. package/dist/starter/index.ts +14 -0
  60. package/dist/starter/jest.config.js +36 -0
  61. package/dist/starter/metro.config.js +38 -0
  62. package/dist/starter/package.json +93 -0
  63. package/dist/starter/pnpm-workspace.yaml +73 -0
  64. package/dist/starter/src/app/(app)/(home)/_layout.tsx +6 -0
  65. package/dist/starter/src/app/(app)/(home)/check-in.tsx +41 -0
  66. package/dist/starter/src/app/(app)/(home)/index.tsx +34 -0
  67. package/dist/starter/src/app/(app)/_layout.tsx +27 -0
  68. package/dist/starter/src/app/(app)/notifications/_layout.tsx +6 -0
  69. package/dist/starter/src/app/(app)/notifications/index.tsx +36 -0
  70. package/dist/starter/src/app/(app)/settings/_layout.tsx +6 -0
  71. package/dist/starter/src/app/(app)/settings/index.tsx +96 -0
  72. package/dist/starter/src/app/(app)/settings/notifications.tsx +16 -0
  73. package/dist/starter/src/app/(app)/settings/support/[id].tsx +23 -0
  74. package/dist/starter/src/app/(app)/settings/support/ideas.tsx +20 -0
  75. package/dist/starter/src/app/(app)/settings/support/index.tsx +20 -0
  76. package/dist/starter/src/app/(app)/settings/support/new.tsx +35 -0
  77. package/dist/starter/src/app/(app)/settings/support/shipped.tsx +20 -0
  78. package/dist/starter/src/app/+native-intent.ts +11 -0
  79. package/dist/starter/src/app/_layout.tsx +20 -0
  80. package/dist/starter/src/app/sign-in.tsx +69 -0
  81. package/dist/starter/src/copy.ts +118 -0
  82. package/dist/starter/src/forms/check-in.json +121 -0
  83. package/dist/starter/src/lib/account.ts +42 -0
  84. package/dist/starter/src/lib/app.ts +52 -0
  85. package/dist/starter/src/lib/auth.ts +80 -0
  86. package/dist/starter/src/lib/check-in-photos.ts +66 -0
  87. package/dist/starter/src/lib/check-in.ts +85 -0
  88. package/dist/starter/src/lib/define-starter.ts +148 -0
  89. package/dist/starter/src/lib/devtools-overlay.ts +34 -0
  90. package/dist/starter/src/lib/devtools.ts +23 -0
  91. package/dist/starter/src/lib/env.ts +33 -0
  92. package/dist/starter/src/lib/google-signin.ts +23 -0
  93. package/dist/starter/src/lib/links.ts +40 -0
  94. package/dist/starter/src/lib/native-modules.ts +27 -0
  95. package/dist/starter/src/lib/notifications.ts +15 -0
  96. package/dist/starter/src/lib/observability.ts +45 -0
  97. package/dist/starter/src/lib/push.ts +49 -0
  98. package/dist/starter/src/lib/supabase.ts +65 -0
  99. package/dist/starter/src/lib/support.ts +44 -0
  100. package/dist/starter/src/lib/updates.ts +61 -0
  101. package/dist/starter/starter.config.ts +37 -0
  102. package/dist/starter/supabase/config.toml +26 -0
  103. package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +237 -0
  104. package/dist/starter/supabase/functions/genesis-apple-revoke/handler.ts +227 -0
  105. package/dist/starter/supabase/functions/genesis-apple-revoke/index.ts +55 -0
  106. package/dist/starter/supabase/functions/genesis-push-send/expo.ts +117 -0
  107. package/dist/starter/supabase/functions/genesis-push-send/handler.ts +462 -0
  108. package/dist/starter/supabase/functions/genesis-push-send/index.ts +54 -0
  109. package/dist/starter/supabase/migrations/20261024000000_genesis_account_deletion.sql +133 -0
  110. package/dist/starter/supabase/migrations/20261024000100_genesis_app_release_policy.sql +82 -0
  111. package/dist/starter/supabase/migrations/20261024000200_genesis_apple_token_revocation.sql +205 -0
  112. package/dist/starter/supabase/migrations/20261024000400_genesis_push.sql +524 -0
  113. package/dist/starter/supabase/migrations/20261024000600_genesis_support.sql +846 -0
  114. package/dist/starter/supabase/tests/database/genesis_account_deletion.test.sql +138 -0
  115. package/dist/starter/supabase/tests/database/genesis_app_release_policy.test.sql +148 -0
  116. package/dist/starter/supabase/tests/database/genesis_apple_token_revocation.test.sql +230 -0
  117. package/dist/starter/supabase/tests/database/genesis_push.test.sql +407 -0
  118. package/dist/starter/supabase/tests/database/genesis_support.test.sql +552 -0
  119. package/dist/starter/tailwind.config.mjs +15 -0
  120. package/dist/starter/tsconfig.json +14 -0
  121. package/dist/starter/vitest.config.mts +7 -0
  122. package/dist/templates/ci/app-ci.yml +17 -0
  123. package/dist/templates/ci/genesis-upgrade.yml +21 -0
  124. package/dist/templates/ci/supabase-ci.yml +20 -0
  125. package/dist/templates/eas/eas.json +47 -0
  126. package/dist/templates/eas/scripts/rollout-health.mjs +85 -0
  127. package/dist/templates/eas/workflows/deploy-production.yml +149 -0
  128. package/dist/templates/eas/workflows/e2e.yml +77 -0
  129. package/dist/templates/eas/workflows/pr-preview.yml +117 -0
  130. package/dist/templates/eas/workflows/rollout.yml +120 -0
  131. package/dist/templates/maestro/config.yaml +5 -0
  132. package/dist/templates/maestro/flows/deep-link.yaml +22 -0
  133. package/dist/templates/maestro/flows/launch.yaml +17 -0
  134. package/dist/templates/maestro/flows/settings-version.yaml +28 -0
  135. package/dist/templates/maestro/flows/sign-in-screen.yaml +17 -0
  136. package/dist/templates/maestro/subflows/sign-in.yaml +20 -0
  137. package/dist/vite.js +975 -29
  138. package/dist/vite.js.map +1 -1
  139. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ var NOOP_LOGGER = {
18
18
  function validateConsumerName(name) {
19
19
  if (!VALID_NAME_PATTERN.test(name)) {
20
20
  throw new Error(
21
- `Invalid consumer name "${name}". Must be lowercase letters/digits/hyphens, 2-31 chars, starting with a letter (e.g., "acme", "gamify-mobile").`
21
+ `Invalid consumer name "${name}". Must be lowercase letters/digits/hyphens, 2-31 chars, starting with a letter (e.g., "acme", "arcade-mobile").`
22
22
  );
23
23
  }
24
24
  }
@@ -101,9 +101,9 @@ async function runScaffold(opts, fs) {
101
101
  function joinPath(...parts) {
102
102
  return parts.filter(Boolean).join("/").replace(/\/+/g, "/");
103
103
  }
104
- function dirname(path10) {
105
- const idx = path10.lastIndexOf("/");
106
- return idx === -1 ? "." : path10.slice(0, idx);
104
+ function dirname(path13) {
105
+ const idx = path13.lastIndexOf("/");
106
+ return idx === -1 ? "." : path13.slice(0, idx);
107
107
  }
108
108
  function brandPackageJson(consumer, genesisVersion) {
109
109
  return JSON.stringify(
@@ -144,7 +144,7 @@ function brandSchema(consumer) {
144
144
  * Genesis primitives consume tokens from this file via the design-system
145
145
  * provider. Edit colors/spacing/typography here to retheme every screen
146
146
  * at once. Domain-specific tokens (e.g., "mood" for Acme, "rarity" for
147
- * Gamify) go under \`extensions\` \u2014 Genesis primitives don't read these,
147
+ * a game app) go under \`extensions\` \u2014 Genesis primitives don't read these,
148
148
  * but consumer composites do via \`useGenesisExtension(key)\`.
149
149
  *
150
150
  * Schema is intentionally narrow at the top level. Add categories under
@@ -235,9 +235,12 @@ export const brand: Brand = {
235
235
  }
236
236
  function tailwindConfig(consumer, native) {
237
237
  return `import type { Config } from "tailwindcss";
238
- import { genesisPreset } from "@marktiderman/genesis-design-system/presets/tailwind";${native ? `
239
- // NativeWind v4 needs its preset; Genesis's goes after it.
240
- import nativewindPreset from "nativewind/preset";` : ""}
238
+ ${native ? `// NativeWind v4 needs its preset; Genesis's goes after it. The NativeWind preset also declares
239
+ // the theme variables, which NativeWind can't import from genesis.css. genesisNativewindContent
240
+ // lists the Genesis React Native packages the app uses, wherever they are installed.
241
+ import { fileURLToPath } from "node:url";
242
+ import nativewindPreset from "nativewind/preset";
243
+ import { genesisNativewindContent, genesisNativewindPreset as genesisPreset } from "@marktiderman/genesis-design-system/presets/nativewind";` : `import { genesisPreset } from "@marktiderman/genesis-design-system/presets/tailwind";`}
241
244
  import { brand } from "@${consumer}/brand";
242
245
 
243
246
  /**
@@ -253,7 +256,7 @@ const config: Config = {
253
256
  content: [
254
257
  "./app/**/*.{ts,tsx}",
255
258
  "./components/**/*.{ts,tsx}",
256
- ${native ? ` "./node_modules/@marktiderman/genesis-ui-native/**/*.{js,ts,tsx}",
259
+ ${native ? ` ...genesisNativewindContent({ root: fileURLToPath(new URL(".", import.meta.url)) }),
257
260
  ` : ""} ],
258
261
  presets: [${native ? "nativewindPreset, " : ""}genesisPreset],
259
262
  theme: {
@@ -1000,6 +1003,54 @@ var GenesisConfigError = class extends Error {
1000
1003
  var DoctorConfigError = class extends GenesisConfigError {
1001
1004
  name = "DoctorConfigError";
1002
1005
  };
1006
+ var PRIVACY_DATA_TYPES = {
1007
+ name: "NSPrivacyCollectedDataTypeName",
1008
+ "email address": "NSPrivacyCollectedDataTypeEmailAddress",
1009
+ "phone number": "NSPrivacyCollectedDataTypePhoneNumber",
1010
+ "physical address": "NSPrivacyCollectedDataTypePhysicalAddress",
1011
+ "other user contact info": "NSPrivacyCollectedDataTypeOtherUserContactInfo",
1012
+ health: "NSPrivacyCollectedDataTypeHealth",
1013
+ fitness: "NSPrivacyCollectedDataTypeFitness",
1014
+ "payment info": "NSPrivacyCollectedDataTypePaymentInfo",
1015
+ "credit info": "NSPrivacyCollectedDataTypeCreditInfo",
1016
+ "other financial info": "NSPrivacyCollectedDataTypeOtherFinancialInfo",
1017
+ "precise location": "NSPrivacyCollectedDataTypePreciseLocation",
1018
+ "coarse location": "NSPrivacyCollectedDataTypeCoarseLocation",
1019
+ "sensitive info": "NSPrivacyCollectedDataTypeSensitiveInfo",
1020
+ contacts: "NSPrivacyCollectedDataTypeContacts",
1021
+ "emails or text messages": "NSPrivacyCollectedDataTypeEmailsOrTextMessages",
1022
+ "photos or videos": "NSPrivacyCollectedDataTypePhotosorVideos",
1023
+ "audio data": "NSPrivacyCollectedDataTypeAudioData",
1024
+ "gameplay content": "NSPrivacyCollectedDataTypeGameplayContent",
1025
+ "customer support": "NSPrivacyCollectedDataTypeCustomerSupport",
1026
+ "other user content": "NSPrivacyCollectedDataTypeOtherUserContent",
1027
+ "browsing history": "NSPrivacyCollectedDataTypeBrowsingHistory",
1028
+ "search history": "NSPrivacyCollectedDataTypeSearchHistory",
1029
+ "user id": "NSPrivacyCollectedDataTypeUserID",
1030
+ "device id": "NSPrivacyCollectedDataTypeDeviceID",
1031
+ "purchase history": "NSPrivacyCollectedDataTypePurchaseHistory",
1032
+ "product interaction": "NSPrivacyCollectedDataTypeProductInteraction",
1033
+ "advertising data": "NSPrivacyCollectedDataTypeAdvertisingData",
1034
+ "other usage data": "NSPrivacyCollectedDataTypeOtherUsageData",
1035
+ "crash data": "NSPrivacyCollectedDataTypeCrashData",
1036
+ "performance data": "NSPrivacyCollectedDataTypePerformanceData",
1037
+ "other diagnostic data": "NSPrivacyCollectedDataTypeOtherDiagnosticData",
1038
+ "environment scanning": "NSPrivacyCollectedDataTypeEnvironmentScanning",
1039
+ hands: "NSPrivacyCollectedDataTypeHands",
1040
+ head: "NSPrivacyCollectedDataTypeHead",
1041
+ "other data types": "NSPrivacyCollectedDataTypeOtherDataTypes"
1042
+ };
1043
+ function privacyDataType(type) {
1044
+ return PRIVACY_DATA_TYPES[type.toLowerCase()];
1045
+ }
1046
+ var PRIVACY_PURPOSES = {
1047
+ "app functionality": "NSPrivacyCollectedDataTypePurposeAppFunctionality",
1048
+ analytics: "NSPrivacyCollectedDataTypePurposeAnalytics",
1049
+ "product personalization": "NSPrivacyCollectedDataTypePurposeProductPersonalization",
1050
+ "developer advertising": "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising",
1051
+ "third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
1052
+ other: "NSPrivacyCollectedDataTypePurposeOther"
1053
+ };
1003
1054
  var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
1004
1055
  var STRINGS = ["uiPackage", "rulesDoc"];
1005
1056
  var KNOWN = /* @__PURE__ */ new Set([
@@ -1012,11 +1063,26 @@ var KNOWN = /* @__PURE__ */ new Set([
1012
1063
  "allow",
1013
1064
  "patterns",
1014
1065
  "plugins",
1066
+ "packs",
1067
+ "native",
1068
+ "supabase",
1015
1069
  "$schema",
1016
1070
  "$comment"
1017
1071
  ]);
1018
1072
  var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
1019
1073
  var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
1074
+ var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
1075
+ var PACK_KEYS = {
1076
+ native: { routerRoot: "path" },
1077
+ supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
1078
+ };
1079
+ function appPath(v, where, fail) {
1080
+ if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
1081
+ if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
1082
+ const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
1083
+ if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
1084
+ return norm;
1085
+ }
1020
1086
  function loadConfig(root, configPath) {
1021
1087
  if (configPath) {
1022
1088
  const file = path3.resolve(root, configPath);
@@ -1049,8 +1115,48 @@ function readGenesisConfig(root) {
1049
1115
  if (!existsSync(file)) return null;
1050
1116
  const raw = readJson(file);
1051
1117
  if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
1052
- const links = raw.links === void 0 ? void 0 : validateLinks(raw.links, file);
1053
- return links ? { raw, links } : { raw };
1118
+ const out = { raw };
1119
+ if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
1120
+ if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
1121
+ return out;
1122
+ }
1123
+ var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
1124
+ var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
1125
+ function validatePrivacy(raw, source = "config") {
1126
+ const fail = (msg) => {
1127
+ throw new GenesisConfigError(`${source}: ${msg}`);
1128
+ };
1129
+ if (!isObject(raw)) fail(`"privacy" must be an object`);
1130
+ const c = raw;
1131
+ for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
1132
+ const out = {};
1133
+ if (c.blocks !== void 0) {
1134
+ if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
1135
+ out.blocks = [...new Set(c.blocks)];
1136
+ }
1137
+ if (c.tracking !== void 0) {
1138
+ if (typeof c.tracking !== "boolean") fail(`privacy.tracking must be true or false`);
1139
+ out.tracking = c.tracking;
1140
+ }
1141
+ if (c.collects !== void 0) {
1142
+ if (!Array.isArray(c.collects)) fail(`privacy.collects must be a list`);
1143
+ out.collects = c.collects.map((entry, i) => {
1144
+ const where = `privacy.collects[${i}]`;
1145
+ if (!isObject(entry)) return fail(`${where} must be an object`);
1146
+ for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
1147
+ if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
1148
+ fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
1149
+ }
1150
+ if (!isStringList(entry.purposes) || entry.purposes.length === 0) fail(`${where}.purposes must be a non-empty list`);
1151
+ for (const p of entry.purposes) {
1152
+ if (!(p in PRIVACY_PURPOSES)) fail(`${where}.purposes: "${p}" is not one of ${Object.keys(PRIVACY_PURPOSES).join(", ")}`);
1153
+ }
1154
+ if (typeof entry.linked !== "boolean") fail(`${where}.linked must be true or false`);
1155
+ if (typeof entry.tracking !== "boolean") fail(`${where}.tracking must be true or false`);
1156
+ return { type: entry.type, purposes: [...new Set(entry.purposes)], linked: entry.linked, tracking: entry.tracking };
1157
+ });
1158
+ }
1159
+ return out;
1054
1160
  }
1055
1161
  var LINK_KEYS = /* @__PURE__ */ new Set(["hosts", "paths", "webcredentials"]);
1056
1162
  var HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
@@ -1140,6 +1246,27 @@ function validateConfig(raw, source = "config") {
1140
1246
  }
1141
1247
  });
1142
1248
  }
1249
+ if (c.packs !== void 0) {
1250
+ if (!isStringList(c.packs)) fail(`"packs" must be a list, e.g. ["native", "supabase"]`);
1251
+ for (const p of c.packs) if (!PACKS.has(p)) fail(`packs: unknown pack "${p}" (known: ${[...PACKS].join(", ")})`);
1252
+ if (new Set(c.packs).size !== c.packs.length) fail(`packs: lists a pack twice`);
1253
+ }
1254
+ for (const [pack, keys] of Object.entries(PACK_KEYS)) {
1255
+ const block = c[pack];
1256
+ if (block === void 0) continue;
1257
+ if (!isObject(block)) fail(`"${pack}" must be an object`);
1258
+ if (!(c.packs ?? []).includes(pack)) fail(`"${pack}" settings are set but the ${pack} pack is not in "packs"`);
1259
+ for (const [k, v] of Object.entries(block)) {
1260
+ const want = keys[k];
1261
+ if (!want) fail(`${pack}: unknown setting "${k}"`);
1262
+ if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
1263
+ if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
1264
+ if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
1265
+ if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
1266
+ }
1267
+ }
1268
+ const supa = c.supabase;
1269
+ if (Array.isArray(supa?.exposedSchemas)) supa.exposedSchemas = supa.exposedSchemas.map((s) => s.toLowerCase());
1143
1270
  if (c.plugins !== void 0) {
1144
1271
  const ok = Array.isArray(c.plugins) && c.plugins.every((p) => typeof p === "string" || Array.isArray(p) && p.length === 2 && typeof p[0] === "string");
1145
1272
  if (!ok) fail(`"plugins" must be a list of module paths or [path, options] pairs`);
@@ -1185,9 +1312,10 @@ function globToRegExp(glob) {
1185
1312
  }
1186
1313
  function globMatcher(globs) {
1187
1314
  const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
1188
- return (path10) => res.some((re) => re.test(path10));
1315
+ return (path13) => res.some((re) => re.test(path13));
1189
1316
  }
1190
1317
  var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
1318
+ var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
1191
1319
  var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
1192
1320
  var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
1193
1321
  var TAG_ALIASES = { hr: "Separator" };
@@ -1232,10 +1360,39 @@ function findPackageDir(from, name) {
1232
1360
  dir = parent;
1233
1361
  }
1234
1362
  }
1363
+ function uiPackageFor(config) {
1364
+ return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
1365
+ }
1235
1366
  function loadGenesis(root, config) {
1236
- const uiPackage = config.uiPackage ?? DEFAULT_UI_PACKAGE;
1367
+ const uiPackage = uiPackageFor(config);
1368
+ const pkg = readPackageExports(root, uiPackage);
1369
+ if (!pkg) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
1370
+ const { dir: uiDir, exports: exportNames, values, components } = pkg;
1371
+ const tokens = /* @__PURE__ */ new Set();
1372
+ const themeFiles = resolveThemeFiles(root, config, uiDir);
1373
+ for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
1374
+ const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
1375
+ const rawTags = /* @__PURE__ */ new Map();
1376
+ for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
1377
+ for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
1378
+ for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
1379
+ if (comp === false) rawTags.delete(tag);
1380
+ else rawTags.set(tag, comp);
1381
+ }
1382
+ return {
1383
+ uiPackage,
1384
+ uiVersion: pkg.version,
1385
+ exports: exportNames,
1386
+ values,
1387
+ components,
1388
+ tokens,
1389
+ rawTags,
1390
+ palette: loadPalette(root)
1391
+ };
1392
+ }
1393
+ function readPackageExports(root, uiPackage) {
1237
1394
  const uiDir = findPackageDir(root, uiPackage);
1238
- if (!uiDir) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
1395
+ if (!uiDir) return null;
1239
1396
  const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
1240
1397
  const typeEntries = /* @__PURE__ */ new Set();
1241
1398
  const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
@@ -1276,27 +1433,7 @@ function loadGenesis(root, config) {
1276
1433
  const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
1277
1434
  const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
1278
1435
  const components = [...values].filter((n) => /^[A-Z][A-Za-z0-9]*$/.test(n) && !(n.length > 2 && n === n.toUpperCase()) && !NON_COMPONENT_SUFFIX.test(n)).sort();
1279
- const tokens = /* @__PURE__ */ new Set();
1280
- const themeFiles = resolveThemeFiles(root, config, uiDir);
1281
- for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
1282
- const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
1283
- const rawTags = /* @__PURE__ */ new Map();
1284
- for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
1285
- for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
1286
- for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
1287
- if (comp === false) rawTags.delete(tag);
1288
- else rawTags.set(tag, comp);
1289
- }
1290
- return {
1291
- uiPackage,
1292
- uiVersion: String(uiPkg.version ?? "unknown"),
1293
- exports: exportNames,
1294
- values,
1295
- components,
1296
- tokens,
1297
- rawTags,
1298
- palette: loadPalette(root)
1299
- };
1436
+ return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
1300
1437
  }
1301
1438
  function parseExportNames(dts) {
1302
1439
  const names = [];
@@ -1549,6 +1686,7 @@ function findColorFunctions(line) {
1549
1686
 
1550
1687
  // src/doctor/scan.ts
1551
1688
  var DEFAULT_SRC = ["src"];
1689
+ var DEFAULT_NATIVE_SRC = ["app", "src", "components"];
1552
1690
  var DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".css"];
1553
1691
  var DEFAULT_IGNORE = [
1554
1692
  "**/*.d.ts",
@@ -1586,7 +1724,7 @@ function scanFiles(root, config) {
1586
1724
  }
1587
1725
  }
1588
1726
  };
1589
- for (const src of config.src ?? DEFAULT_SRC) {
1727
+ for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
1590
1728
  const abs = path3.resolve(root, src);
1591
1729
  if (!existsSync(abs)) continue;
1592
1730
  if (statSync(abs).isDirectory()) walk(abs);
@@ -1742,7 +1880,18 @@ var BUILTIN_RULES = [
1742
1880
  "raw-color",
1743
1881
  "undefined-token",
1744
1882
  "shadowed-export",
1745
- "version-skew"
1883
+ "version-skew",
1884
+ // native pack
1885
+ "native-raw-primitive",
1886
+ "native-literal-color",
1887
+ "native-custom-header",
1888
+ "native-screen-layout",
1889
+ "store-readiness",
1890
+ // supabase pack
1891
+ "migration-grants",
1892
+ "migration-rls",
1893
+ "migration-definer-search-path",
1894
+ "migration-edited"
1746
1895
  ];
1747
1896
  var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
1748
1897
  var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
@@ -1818,7 +1967,10 @@ function checkColors(ctx) {
1818
1967
  `(?<![\\w-])(?:${COLOR_UTILITIES})-(?:${ctx.genesis.palette.join("|")})(?:-\\d{2,3})?(?:\\/\\d{1,3})?(?![\\w-])`,
1819
1968
  "g"
1820
1969
  );
1970
+ const native = ctx.config.packs?.includes("native") ?? false;
1971
+ const themeRoles = ctx.genesis.values.has("useThemeRoles") ? "a theme role (useThemeRoles())" : "a theme role";
1821
1972
  for (const file of ctx.files) {
1973
+ const nativeCode = native && SCRIPT_EXTS.has(file.ext);
1822
1974
  file.code.split("\n").forEach((text, i) => {
1823
1975
  const line = i + 1;
1824
1976
  for (const m of text.matchAll(palette)) {
@@ -1832,6 +1984,16 @@ function checkColors(ctx) {
1832
1984
  for (const hit of [...findHexLiterals(text), ...findColorFunctions(text)]) {
1833
1985
  const at = hit.column - 1;
1834
1986
  if (arbitrary.some(([a, b]) => at >= a && at < b)) continue;
1987
+ if (nativeCode) {
1988
+ ctx.report({
1989
+ rule: "native-literal-color",
1990
+ file: file.path,
1991
+ line,
1992
+ subject: hit.literal,
1993
+ message: `hardcodes the color ${hit.literal}; use ${themeRoles}, a token className (bg-primary, text-muted-foreground) or PlatformColor(...)`
1994
+ });
1995
+ continue;
1996
+ }
1835
1997
  ctx.report({ rule: "raw-color", file: file.path, line, subject: hit.literal, message: `hardcodes the color ${hit.literal}; color values come from Genesis tokens` });
1836
1998
  }
1837
1999
  });
@@ -1888,6 +2050,791 @@ function unusedComponents(ctx) {
1888
2050
  }
1889
2051
  return ctx.genesis.components.filter((c) => !used.has(c));
1890
2052
  }
2053
+
2054
+ // ../../scripts/lib/native-primitives.mjs
2055
+ var NATIVE_WRAPPED_PRIMITIVES = Object.freeze({
2056
+ Modal: Object.freeze(["NativeDialog", "NativeSheet", "NativeDrawer"]),
2057
+ ActivityIndicator: Object.freeze(["NativeSkeleton", "NativeProgress"])
2058
+ });
2059
+ function wrappedPrimitivesIn(namedImports) {
2060
+ return namedImports.split(",").map((n) => n.trim()).filter((n) => n && !/^type\s/.test(n)).map((n) => n.split(/\s+as\s+/)[0].trim()).filter((n) => n && Object.hasOwn(NATIVE_WRAPPED_PRIMITIVES, n));
2061
+ }
2062
+ var api = (category, ...reasons) => ({
2063
+ NSPrivacyAccessedAPIType: `NSPrivacyAccessedAPICategory${category}`,
2064
+ NSPrivacyAccessedAPITypeReasons: reasons
2065
+ });
2066
+ var PRIVACY_APIS = {
2067
+ "react-native": [api("FileTimestamp", "C617.1"), api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1")],
2068
+ expo: [api("FileTimestamp", "0A2A.1", "3B52.1"), api("DiskSpace", "E174.1", "85F4.1"), api("UserDefaults", "CA92.1")],
2069
+ "expo-updates": [api("UserDefaults", "CA92.1")],
2070
+ "expo-application": [api("FileTimestamp", "C617.1")],
2071
+ "expo-notifications": [api("UserDefaults", "CA92.1")],
2072
+ "@react-native-async-storage/async-storage": [api("FileTimestamp", "C617.1")],
2073
+ "@sentry/react-native": [api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1"), api("FileTimestamp", "C617.1")]
2074
+ };
2075
+ var appFunctionality = (type, ...more) => ({
2076
+ type,
2077
+ purposes: ["app functionality", ...more],
2078
+ linked: true,
2079
+ tracking: false
2080
+ });
2081
+ ({
2082
+ account: {
2083
+ collects: [appFunctionality("email address"), appFunctionality("user id"), appFunctionality("name")]
2084
+ },
2085
+ observability: {
2086
+ collects: [
2087
+ appFunctionality("crash data"),
2088
+ appFunctionality("performance data"),
2089
+ appFunctionality("other diagnostic data"),
2090
+ appFunctionality("user id", "analytics"),
2091
+ { type: "product interaction", purposes: ["analytics"], linked: true, tracking: false }
2092
+ ]
2093
+ },
2094
+ push: {
2095
+ collects: [appFunctionality("device ID")]
2096
+ },
2097
+ support: {
2098
+ collects: [
2099
+ appFunctionality("user id"),
2100
+ appFunctionality("customer support"),
2101
+ appFunctionality("other user content"),
2102
+ appFunctionality("photos or videos"),
2103
+ appFunctionality("other diagnostic data")
2104
+ ]
2105
+ }
2106
+ });
2107
+ function privacyApisFor(dependencies2) {
2108
+ return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
2109
+ }
2110
+
2111
+ // src/doctor/native.ts
2112
+ var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
2113
+ var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
2114
+ var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
2115
+ var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
2116
+ var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
2117
+ var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
2118
+ var HIDES_HEADER = /\bheaderShown\s*(?::|=\s*\{)\s*false\b/;
2119
+ function nativePackage(ctx) {
2120
+ const pkg = readPackageExports(ctx.root, NATIVE_UI_PACKAGE);
2121
+ if (!pkg) throw new DoctorConfigError(`the native pack needs ${NATIVE_UI_PACKAGE}; install it, or remove "native" from doctor.packs`);
2122
+ return pkg;
2123
+ }
2124
+ function nativeLayouts(pkg) {
2125
+ return pkg.components.filter((n) => LAYOUT_NAME.test(n));
2126
+ }
2127
+ function checkNativePack(ctx) {
2128
+ const pkg = nativePackage(ctx);
2129
+ checkRawPrimitives(ctx, pkg);
2130
+ checkCustomHeaders(ctx, pkg);
2131
+ checkScreenLayouts(ctx, pkg);
2132
+ checkStoreReadiness(ctx);
2133
+ }
2134
+ var RN = String.raw`["']react-native["']`;
2135
+ function checkRawPrimitives(ctx, pkg) {
2136
+ const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
2137
+ const named = [
2138
+ // import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
2139
+ new RegExp(String.raw`\bimport\s+(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*${RN}`, "g"),
2140
+ new RegExp(String.raw`\bexport\s+\{([^}]*)\}\s*from\s*${RN}`, "g"),
2141
+ new RegExp(String.raw`\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\(\s*${RN}\s*\)`, "g")
2142
+ ];
2143
+ const namespaces = [
2144
+ new RegExp(String.raw`\bimport\s+\*\s+as\s+([\w$]+)\s+from\s*${RN}`, "g"),
2145
+ new RegExp(String.raw`\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*${RN}\s*\)`, "g")
2146
+ ];
2147
+ const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
2148
+ for (const file of ctx.files) {
2149
+ if (!SCRIPT_EXTS2.has(file.ext)) continue;
2150
+ const code = file.code;
2151
+ const report = (name, at) => {
2152
+ const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
2153
+ ctx.report({
2154
+ rule: "native-raw-primitive",
2155
+ file: file.path,
2156
+ line: lineAt(code, at),
2157
+ subject: name,
2158
+ message: `uses ${name} from react-native, which Genesis wraps; use ${use.length ? use.join(" or ") : "the Genesis wrapper"} from ${NATIVE_UI_PACKAGE}`
2159
+ });
2160
+ };
2161
+ for (const re of named) {
2162
+ for (const m of code.matchAll(re)) {
2163
+ for (const name of wrappedPrimitivesIn(m[1].replace(/:/g, " as "))) report(name, m.index + m[0].indexOf(name));
2164
+ }
2165
+ }
2166
+ for (const re of namespaces) {
2167
+ for (const m of code.matchAll(re)) {
2168
+ for (const use of code.matchAll(new RegExp(String.raw`\b${m[1].replace(/\$/g, "\\$")}\.(${wrapped.join("|")})\b`, "g"))) report(use[1], use.index);
2169
+ }
2170
+ }
2171
+ for (const m of code.matchAll(member)) report(m[1], m.index);
2172
+ }
2173
+ }
2174
+ function customElement(code, re, pkg) {
2175
+ for (const m of code.matchAll(re)) {
2176
+ const name = m[1];
2177
+ if (!pkg.values.has(name.split(".")[0]) && !PART_HEADER.test(name)) return { name, index: m.index };
2178
+ }
2179
+ return null;
2180
+ }
2181
+ function ownHeader(code, pkg) {
2182
+ const el = customElement(code, /<([A-Z][\w$]*Header)\b/g, pkg);
2183
+ if (el) return el;
2184
+ const style = /\bstyle=\{\s*styles\.header\s*\}/.exec(code);
2185
+ return style ? { name: "styles.header", index: style.index } : null;
2186
+ }
2187
+ function checkCustomHeaders(ctx, pkg) {
2188
+ const layouts = nativeLayouts(pkg);
2189
+ if (layouts.length === 0) return;
2190
+ const headerWay = pkg.values.has("ScreenContainer") ? `ScreenContainer's header props${pkg.values.has("composeHeaderOptions") ? " (composeHeaderOptions)" : ""}` : `a Genesis layout's header (${layouts.join(", ")})`;
2191
+ const rootDir = routerRoot(ctx);
2192
+ const reported = /* @__PURE__ */ new Set();
2193
+ const hidingLayouts = /* @__PURE__ */ new Map();
2194
+ for (const file of ctx.files) {
2195
+ if (!JSX_EXTS2.has(file.ext)) continue;
2196
+ const code = file.code;
2197
+ const hidden = HIDES_HEADER.exec(code);
2198
+ if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
2199
+ const own = hidden ? ownHeader(code, pkg) : null;
2200
+ if (hidden && own) {
2201
+ reported.add(file.path);
2202
+ ctx.report({
2203
+ rule: "native-custom-header",
2204
+ level: "warn",
2205
+ file: file.path,
2206
+ line: lineAt(code, hidden.index),
2207
+ subject: own.name,
2208
+ message: `hides the navigator header and draws its own (${own.name}); use ${headerWay} so the title, back button and large-title behavior stay native`
2209
+ });
2210
+ }
2211
+ const tabBarProp = /<Tabs\b/.test(code) ? /\btabBar\s*=\s*\{/.exec(code) : null;
2212
+ const tabBar = tabBarProp ? { name: "tabBar prop", index: tabBarProp.index } : customElement(code, /<([A-Z][\w$]*TabBar)\b/g, pkg);
2213
+ if (tabBar) {
2214
+ ctx.report({
2215
+ rule: "native-custom-header",
2216
+ level: "warn",
2217
+ file: file.path,
2218
+ line: lineAt(code, tabBar.index),
2219
+ subject: tabBar.name,
2220
+ message: `builds a tab bar by hand (${tabBar.name}); use the router's native <Tabs> bar, themed through Genesis screenOptions`
2221
+ });
2222
+ }
2223
+ }
2224
+ for (const file of ctx.files) {
2225
+ if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
2226
+ const layout = hidingLayouts.get(path3.posix.dirname(file.path));
2227
+ const own = layout ? ownHeader(file.code, pkg) : null;
2228
+ if (!layout || !own) continue;
2229
+ ctx.report({
2230
+ rule: "native-custom-header",
2231
+ level: "warn",
2232
+ file: file.path,
2233
+ line: lineAt(file.code, own.index),
2234
+ subject: own.name,
2235
+ message: `draws its own header (${own.name}) while ${layout} hides the navigator's; use ${headerWay} so the title, back button and large-title behavior stay native`
2236
+ });
2237
+ }
2238
+ }
2239
+ function routerRoot(ctx) {
2240
+ if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
2241
+ return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
2242
+ }
2243
+ function checkScreenLayouts(ctx, pkg) {
2244
+ const layouts = nativeLayouts(pkg);
2245
+ if (layouts.length === 0) return;
2246
+ const rootDir = routerRoot(ctx);
2247
+ if (!existsSync(path3.join(ctx.root, rootDir))) {
2248
+ ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
2249
+ return;
2250
+ }
2251
+ const routes = ctx.files.filter((f) => f.path.startsWith(`${rootDir}/`));
2252
+ if (routes.length === 0) {
2253
+ ctx.report({
2254
+ rule: "native-screen-layout",
2255
+ level: "warn",
2256
+ file: rootDir,
2257
+ message: `no scanned file is under the router root ${rootDir}, so no screen was checked; add it to doctor.src`
2258
+ });
2259
+ return;
2260
+ }
2261
+ const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
2262
+ const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
2263
+ for (const file of routes) {
2264
+ if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
2265
+ if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
2266
+ if (renders.test(file.code)) continue;
2267
+ const viaImport = localImports(ctx.root, file).some((abs) => {
2268
+ const target = byPath.get(abs) ?? readSource(abs);
2269
+ return target !== null && renders.test(target.code);
2270
+ });
2271
+ if (viaImport) continue;
2272
+ ctx.report({
2273
+ rule: "native-screen-layout",
2274
+ level: "warn",
2275
+ file: file.path,
2276
+ message: `doesn't render a Genesis screen layout (${layouts.join(", ")}); wrap the screen in one so the header, safe area and scrolling match every other screen`
2277
+ });
2278
+ }
2279
+ }
2280
+ function localImports(root, file) {
2281
+ const out = [];
2282
+ for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
2283
+ const spec = m[1];
2284
+ const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
2285
+ for (const base of bases) {
2286
+ const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
2287
+ (p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
2288
+ );
2289
+ if (hit) {
2290
+ out.push(hit);
2291
+ break;
2292
+ }
2293
+ }
2294
+ }
2295
+ return out;
2296
+ }
2297
+ function readSource(abs) {
2298
+ try {
2299
+ return { code: readFileSync(abs, "utf8") };
2300
+ } catch {
2301
+ return null;
2302
+ }
2303
+ }
2304
+ var PERMISSIONS = [
2305
+ { module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
2306
+ { module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
2307
+ { module: "expo-image-picker", key: "NSCameraUsageDescription", option: "cameraPermission", maybe: "takes photos with the camera" },
2308
+ { module: "expo-media-library", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
2309
+ { module: "expo-location", key: "NSLocationWhenInUseUsageDescription", option: "locationWhenInUsePermission" },
2310
+ { module: "expo-av", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
2311
+ { module: "expo-audio", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
2312
+ { module: "expo-contacts", key: "NSContactsUsageDescription", option: "contactsPermission" },
2313
+ { module: "expo-local-authentication", key: "NSFaceIDUsageDescription", option: "faceIDPermission" }
2314
+ ];
2315
+ var SOCIAL_SIGN_IN = ["@react-native-google-signin/google-signin", "react-native-fbsdk-next"];
2316
+ var WEAK_SOCIAL_SIGN_IN = ["expo-auth-session"];
2317
+ var APPLE_SIGN_IN = ["expo-apple-authentication", "@invertase/react-native-apple-authentication"];
2318
+ var EXPO_CONFIGS = ["app.json", "app.config.json", "app.config.ts", "app.config.js", "app.config.mjs", "app.config.cjs"];
2319
+ var SUPABASE_SIGN_IN = /\bsignInWith(?:OAuth|IdToken)\s*\(\s*\{\s*provider\s*:\s*["']([\w-]+)["']/g;
2320
+ var GENESIS_PLUGIN = "@marktiderman/genesis-cli";
2321
+ var GENESIS_PLUGIN_TEXT = /["']@marktiderman\/genesis-cli(?:\/expo)?["']|\bwithGenesis\s*\(/;
2322
+ var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\b(?:require|import)\s*\(\s*["']@marktiderman\/genesis-cli[^"']*["']\s*\)/g;
2323
+ function readExpoConfigs(root) {
2324
+ const out = [];
2325
+ for (const name of EXPO_CONFIGS) {
2326
+ const abs = path3.join(root, name);
2327
+ if (!existsSync(abs)) continue;
2328
+ const text = readFileSync(abs, "utf8");
2329
+ let json = null;
2330
+ if (name.endsWith(".json")) {
2331
+ try {
2332
+ const raw = JSON.parse(text);
2333
+ json = raw.expo ?? raw;
2334
+ } catch (err) {
2335
+ throw new DoctorConfigError(`${name} is not valid JSON: ${err.message}`);
2336
+ }
2337
+ }
2338
+ out.push({ file: name, json, text });
2339
+ }
2340
+ return out;
2341
+ }
2342
+ function get(obj, keys) {
2343
+ let cur = obj;
2344
+ for (const k of keys) {
2345
+ if (!cur || typeof cur !== "object") return void 0;
2346
+ cur = cur[k];
2347
+ }
2348
+ return cur;
2349
+ }
2350
+ function pluginOptions(json, module) {
2351
+ const plugins = json?.plugins;
2352
+ if (!Array.isArray(plugins)) return null;
2353
+ for (const p of plugins) {
2354
+ if (p === module) return {};
2355
+ if (Array.isArray(p) && p[0] === module) return p[1] && typeof p[1] === "object" ? p[1] : {};
2356
+ }
2357
+ return null;
2358
+ }
2359
+ function dependencies(root) {
2360
+ const file = path3.join(root, "package.json");
2361
+ if (!existsSync(file)) return /* @__PURE__ */ new Set();
2362
+ const pkg = JSON.parse(readFileSync(file, "utf8"));
2363
+ return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
2364
+ }
2365
+ function runtimeDependencies(root) {
2366
+ const file = path3.join(root, "package.json");
2367
+ if (!existsSync(file)) return {};
2368
+ return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
2369
+ }
2370
+ function checkStoreReadiness(ctx) {
2371
+ const configs = readExpoConfigs(ctx.root);
2372
+ if (configs.length === 0) {
2373
+ ctx.report({ rule: "store-readiness", level: "warn", file: "app.json", message: "no app.json or app.config.* found; the store checks read the Expo config" });
2374
+ return;
2375
+ }
2376
+ const file = configs[0].file;
2377
+ const deps = dependencies(ctx.root);
2378
+ const has2 = (keys, word) => configs.some((c) => c.json ? get(c.json, keys) !== void 0 : new RegExp(`\\b${word}\\b`).test(c.text));
2379
+ const genesisPluginDoes = (option) => configs.some((c) => {
2380
+ if (c.json) {
2381
+ const options = pluginOptions(c.json, GENESIS_PLUGIN) ?? pluginOptions(c.json, `${GENESIS_PLUGIN}/expo`);
2382
+ return options !== null && options[option] !== false;
2383
+ }
2384
+ const listed = c.text.replace(GENESIS_PLUGIN_IMPORT, "");
2385
+ return GENESIS_PLUGIN_TEXT.test(listed) && !new RegExp(`\\b${option}\\s*:\\s*false\\b`).test(c.text);
2386
+ });
2387
+ const exportCompliance = has2(["ios", "config", "usesNonExemptEncryption"], "usesNonExemptEncryption") || has2(["ios", "infoPlist", "ITSAppUsesNonExemptEncryption"], "ITSAppUsesNonExemptEncryption") || genesisPluginDoes("exportCompliance");
2388
+ if (!exportCompliance) {
2389
+ ctx.report({
2390
+ rule: "store-readiness",
2391
+ level: "warn",
2392
+ file,
2393
+ subject: "usesNonExemptEncryption",
2394
+ message: "sets neither ios.config.usesNonExemptEncryption nor ios.infoPlist.ITSAppUsesNonExemptEncryption; set it (false for HTTPS-only apps) so App Store Connect doesn't hold every build for the export-compliance question"
2395
+ });
2396
+ }
2397
+ const social = SOCIAL_SIGN_IN.filter((d) => deps.has(d));
2398
+ let apple = APPLE_SIGN_IN.some((d) => deps.has(d));
2399
+ for (const f of ctx.files) {
2400
+ for (const m of f.code.matchAll(SUPABASE_SIGN_IN)) {
2401
+ if (m[1] === "apple") apple = true;
2402
+ else if (!social.includes(`Supabase ${m[1]} sign-in`)) social.push(`Supabase ${m[1]} sign-in`);
2403
+ }
2404
+ }
2405
+ if (social.length > 0 && !apple) {
2406
+ const weak = WEAK_SOCIAL_SIGN_IN.filter((d) => deps.has(d));
2407
+ ctx.report({
2408
+ rule: "store-readiness",
2409
+ level: "warn",
2410
+ file: "package.json",
2411
+ subject: "sign-in-with-apple",
2412
+ message: `offers third-party sign-in (${[...social, ...weak].join(", ")}) and no Sign in with Apple. App Store guideline 4.8 asks for an equivalent login that limits data collection to name and email, lets people keep their email private and doesn't track them; Sign in with Apple (expo-apple-authentication, or Supabase's apple provider) is the usual one. If another option qualifies, allow this with the reason.`
2413
+ });
2414
+ }
2415
+ const generic = /* @__PURE__ */ new Map();
2416
+ for (const p of PERMISSIONS) {
2417
+ if (!deps.has(p.module)) continue;
2418
+ const set = configs.some((c) => {
2419
+ if (!c.json) return new RegExp(`\\b(?:${p.key}|${p.option})\\b`).test(c.text);
2420
+ const plist = get(c.json, ["ios", "infoPlist", p.key]);
2421
+ const option = pluginOptions(c.json, p.module)?.[p.option];
2422
+ return typeof plist === "string" && plist.trim() !== "" || typeof option === "string" && option.trim() !== "" || option === false;
2423
+ });
2424
+ if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
2425
+ }
2426
+ for (const [key, modules] of generic) {
2427
+ const opt = PERMISSIONS.find((p) => p.key === key).option;
2428
+ ctx.report({
2429
+ rule: "store-readiness",
2430
+ level: "warn",
2431
+ file,
2432
+ subject: key,
2433
+ message: `leaves ${key} to Expo's generic default string (${modules.join("; ")}), and App Review rejects generic purpose strings; set the plugin's ${opt} (or ios.infoPlist.${key}) to a sentence saying why the app needs it, or ${opt}: false if it doesn't`
2434
+ });
2435
+ }
2436
+ const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
2437
+ if (!has2(["ios", "privacyManifests"], "privacyManifests") && !pluginManifest) {
2438
+ ctx.report({
2439
+ rule: "store-readiness",
2440
+ level: "warn",
2441
+ file,
2442
+ subject: "privacyManifests",
2443
+ message: "has no ios.privacyManifests; declare the required-reason APIs the app uses (NSPrivacyAccessedAPITypes) so uploads aren't rejected for a missing privacy manifest"
2444
+ });
2445
+ }
2446
+ }
2447
+ var DEFAULT_MIGRATIONS = "supabase/migrations";
2448
+ var DEFAULT_BASE = "origin/main";
2449
+ var DEFAULT_EXPOSED = ["public"];
2450
+ function sqlStatements(text) {
2451
+ const out = [];
2452
+ let buf = "";
2453
+ let bodies = [];
2454
+ let line = 1;
2455
+ let start = 0;
2456
+ const flush = () => {
2457
+ const sql = buf.replace(/\s+/g, " ").trim().toLowerCase();
2458
+ if (sql) out.push({ sql, line: start, bodies });
2459
+ buf = "";
2460
+ bodies = [];
2461
+ start = 0;
2462
+ };
2463
+ const put = (s) => {
2464
+ if (!start && /\S/.test(s)) start = line;
2465
+ buf += s;
2466
+ };
2467
+ let i = 0;
2468
+ while (i < text.length) {
2469
+ const ch = text[i];
2470
+ const two = text.slice(i, i + 2);
2471
+ if (ch === "\n") {
2472
+ buf += " ";
2473
+ line++;
2474
+ i++;
2475
+ } else if (two === "--") {
2476
+ while (i < text.length && text[i] !== "\n") i++;
2477
+ } else if (two === "/*") {
2478
+ let depth = 0;
2479
+ while (i < text.length) {
2480
+ if (text.startsWith("/*", i)) {
2481
+ depth++;
2482
+ i += 2;
2483
+ } else if (text.startsWith("*/", i)) {
2484
+ depth--;
2485
+ i += 2;
2486
+ if (depth === 0) break;
2487
+ } else {
2488
+ if (text[i] === "\n") line++;
2489
+ i++;
2490
+ }
2491
+ }
2492
+ buf += " ";
2493
+ } else if (ch === "'") {
2494
+ const escapes = /[eE]/.test(text[i - 1] ?? "") && !/[\w$]/.test(text[i - 2] ?? "");
2495
+ put("'");
2496
+ i++;
2497
+ while (i < text.length) {
2498
+ if (escapes && text[i] === "\\") i += 2;
2499
+ else if (text[i] === "'" && text[i + 1] === "'") i += 2;
2500
+ else if (text[i] === "'") break;
2501
+ else {
2502
+ if (text[i] === "\n") line++;
2503
+ i++;
2504
+ }
2505
+ }
2506
+ put("'");
2507
+ i++;
2508
+ } else if (ch === '"') {
2509
+ i++;
2510
+ while (i < text.length && text[i] !== '"') put(text[i++]);
2511
+ i++;
2512
+ } else if (ch === "$" && !/[\w$]/.test(text[i - 1] ?? "") && /^\$(?:[A-Za-z_]\w*)?\$/.test(text.slice(i))) {
2513
+ const tag = /^\$(?:[A-Za-z_]\w*)?\$/.exec(text.slice(i))[0];
2514
+ const end = text.indexOf(tag, i + tag.length);
2515
+ const stop = end === -1 ? text.length : end + tag.length;
2516
+ bodies.push(text.slice(i + tag.length, end === -1 ? text.length : end).toLowerCase());
2517
+ for (let k = i; k < stop; k++) if (text[k] === "\n") line++;
2518
+ put(`${tag} ${tag}`);
2519
+ i = stop;
2520
+ } else if (ch === ";") {
2521
+ flush();
2522
+ i++;
2523
+ } else {
2524
+ put(ch);
2525
+ i++;
2526
+ }
2527
+ }
2528
+ flush();
2529
+ return out;
2530
+ }
2531
+ function qualify(name) {
2532
+ const n = name.trim().toLowerCase();
2533
+ return n.includes(".") ? n : `public.${n}`;
2534
+ }
2535
+ var schemaOf = (name) => name.split(".")[0];
2536
+ function parenthesized(sql, open) {
2537
+ let depth = 0;
2538
+ for (let k = open; k < sql.length; k++) {
2539
+ if (sql[k] === "(") depth++;
2540
+ else if (sql[k] === ")" && --depth === 0) return { inner: sql.slice(open + 1, k), end: k + 1 };
2541
+ }
2542
+ return { inner: sql.slice(open + 1), end: sql.length };
2543
+ }
2544
+ function stripParens(s) {
2545
+ let out = "";
2546
+ let depth = 0;
2547
+ for (const c of s) {
2548
+ if (c === "(") depth++;
2549
+ else if (c === ")") depth = Math.max(0, depth - 1);
2550
+ else if (depth === 0) out += c;
2551
+ }
2552
+ return out;
2553
+ }
2554
+ function splitTop(s) {
2555
+ const parts = [];
2556
+ let depth = 0;
2557
+ let cur = "";
2558
+ for (const c of s) {
2559
+ if (c === "(") depth++;
2560
+ if (c === ")") depth--;
2561
+ if (c === "," && depth === 0) {
2562
+ parts.push(cur);
2563
+ cur = "";
2564
+ } else cur += c;
2565
+ }
2566
+ if (cur.trim()) parts.push(cur);
2567
+ return parts.map((p) => p.trim()).filter(Boolean);
2568
+ }
2569
+ var TYPE_ALIASES = {
2570
+ int: "integer",
2571
+ int4: "integer",
2572
+ int8: "bigint",
2573
+ int2: "smallint",
2574
+ bool: "boolean",
2575
+ varchar: "character varying",
2576
+ timestamptz: "timestamp with time zone",
2577
+ float8: "double precision"
2578
+ };
2579
+ var MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
2580
+ function argTypes(args) {
2581
+ const types = [];
2582
+ for (const raw of splitTop(args)) {
2583
+ let tokens = stripParens(raw.replace(/\s+(?:default\b|=).*$/, "")).trim().split(/\s+/).filter(Boolean);
2584
+ const mode = tokens[0];
2585
+ if (mode === "out") continue;
2586
+ if (mode === "in" || mode === "inout" || mode === "variadic") tokens = tokens.slice(1);
2587
+ const joined = tokens.join(" ");
2588
+ const type = tokens.length > 1 && !MULTIWORD_TYPE.test(joined) ? tokens.slice(1).join(" ") : joined;
2589
+ types.push(TYPE_ALIASES[type] ?? type);
2590
+ }
2591
+ return types;
2592
+ }
2593
+ function git(root, args) {
2594
+ const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
2595
+ return r.status === 0 ? r.stdout : null;
2596
+ }
2597
+ function gitView(root, dir, base) {
2598
+ if (git(root, ["rev-parse", "--is-inside-work-tree"])?.trim() !== "true") return { reason: "not a git repository", repo: false };
2599
+ if (git(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]) === null) {
2600
+ return { reason: `the git ref ${base} isn't available (fetch it, or set doctor.supabase.base)`, repo: true };
2601
+ }
2602
+ const mergeBase = git(root, ["merge-base", "HEAD", base])?.trim();
2603
+ if (!mergeBase) return { reason: `HEAD has no merge base with ${base} (a shallow clone? fetch with depth 0)`, repo: true };
2604
+ const diff = git(root, ["diff", "--relative", "--name-status", "-M", mergeBase, "--", dir]);
2605
+ const untracked = git(root, ["ls-files", "--others", "--exclude-standard", "--", dir]);
2606
+ if (diff === null || untracked === null) return { reason: `git diff against ${base} failed`, repo: true };
2607
+ const sql = (p) => p !== void 0 && p.endsWith(".sql");
2608
+ const touched = new Set(untracked.split("\n").filter(sql));
2609
+ const edited = [];
2610
+ for (const row of diff.split("\n").filter(Boolean)) {
2611
+ const [status, a, b] = row.split(" ");
2612
+ if (status.startsWith("R")) {
2613
+ if (sql(b)) touched.add(b);
2614
+ if (sql(a)) edited.push({ file: a, status: "renamed" });
2615
+ continue;
2616
+ }
2617
+ if (!sql(a)) continue;
2618
+ if (status.startsWith("A")) touched.add(a);
2619
+ else if (status.startsWith("M") || status.startsWith("T")) {
2620
+ touched.add(a);
2621
+ edited.push({ file: a, status: "modified" });
2622
+ } else if (status.startsWith("D")) edited.push({ file: a, status: "deleted" });
2623
+ }
2624
+ return { touched, edited };
2625
+ }
2626
+ function checkSupabasePack(ctx) {
2627
+ const settings = ctx.config.supabase ?? {};
2628
+ const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
2629
+ const abs = path3.join(ctx.root, dir);
2630
+ if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
2631
+ const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
2632
+ const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
2633
+ const base = settings.base ?? DEFAULT_BASE;
2634
+ const view = gitView(ctx.root, dir, base);
2635
+ if ("reason" in view) {
2636
+ if (view.repo) ctx.report({ rule: "migration-edited", level: "warn", file: dir, message: `can't check for edited migrations: ${view.reason}` });
2637
+ } else {
2638
+ for (const e of view.edited) {
2639
+ ctx.report({
2640
+ rule: "migration-edited",
2641
+ file: e.file,
2642
+ subject: e.file,
2643
+ message: `${e.status === "modified" ? "edits" : e.status === "deleted" ? "deletes" : "renames"} a migration that already exists on ${base}, so it has been applied; put the change in a new migration instead`
2644
+ });
2645
+ }
2646
+ }
2647
+ const since = settings.since;
2648
+ const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
2649
+ if ("reason" in view && since === void 0) {
2650
+ ctx.report({
2651
+ rule: "migration-grants",
2652
+ level: "warn",
2653
+ file: dir,
2654
+ message: `skipped: can't tell new migrations from applied ones (${view.reason}); fetch the base ref (CI: fetch-depth 0) or set doctor.supabase.since`
2655
+ });
2656
+ } else {
2657
+ const isNew = (file) => afterSince(file) && ("reason" in view || view.touched.has(file));
2658
+ checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
2659
+ }
2660
+ checkRls(ctx, migrations, exposed);
2661
+ checkDefinerSearchPath(ctx, migrations);
2662
+ }
2663
+ function granteesOf(s) {
2664
+ return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
2665
+ }
2666
+ function checkGrants(ctx, migrations, exposed) {
2667
+ const fix = "grant by name (grant execute on function schema.fn(args) to role) so an earlier revoke survives";
2668
+ const open = (roles) => roles.filter((r) => r === "anon" || r === "public");
2669
+ const blanket = (roles) => {
2670
+ const o = open(roles);
2671
+ if (o.length) return { level: "error", who: o.join(" and ") };
2672
+ if (roles.includes("authenticated")) return { level: "warn", who: "authenticated" };
2673
+ return null;
2674
+ };
2675
+ for (const { file, statements } of migrations) {
2676
+ for (const { sql, line } of statements) {
2677
+ const all = /^grant\b.*\bon all (?:functions|routines|procedures) in schema .+? to (.+)$/.exec(sql);
2678
+ if (all) {
2679
+ const hit = blanket(granteesOf(all[1]));
2680
+ if (hit) {
2681
+ ctx.report({ rule: "migration-grants", level: hit.level, file, line, subject: "on all functions", message: `grants every function in a schema to ${hit.who}, which re-grants functions an earlier migration revoked; ${fix}` });
2682
+ }
2683
+ continue;
2684
+ }
2685
+ const defaults = /^alter default privileges\b.*?\bgrant\b.*\bon (?:functions|routines) to (.+)$/.exec(sql);
2686
+ if (defaults) {
2687
+ const hit = blanket(granteesOf(defaults[1]));
2688
+ if (hit) {
2689
+ ctx.report({ rule: "migration-grants", level: hit.level, file, line, subject: "alter default privileges", message: `grants default privileges on functions to ${hit.who}, so every future function is callable by them; ${fix}` });
2690
+ }
2691
+ continue;
2692
+ }
2693
+ const fn = /^grant\b.*?\bon (?:function|procedure|routine)s? (.+?) to (.+)$/.exec(sql);
2694
+ if (fn) {
2695
+ const roles = open(granteesOf(fn[2]));
2696
+ if (!roles.length) continue;
2697
+ for (const name of splitTop(fn[1]).map((n) => qualify(stripParens(n)))) {
2698
+ if (exposed.has(schemaOf(name))) continue;
2699
+ ctx.report({
2700
+ rule: "migration-grants",
2701
+ file,
2702
+ line,
2703
+ subject: name,
2704
+ message: `grants ${name} to ${roles.join(" and ")}; a function outside the exposed schemas is never callable by anon or public (grant it to authenticated, or expose a wrapper)`
2705
+ });
2706
+ }
2707
+ continue;
2708
+ }
2709
+ const schema = /^grant\b.*?\bon schema (.+?) to (.+)$/.exec(sql);
2710
+ if (schema) {
2711
+ const roles = open(granteesOf(schema[2]));
2712
+ if (!roles.length) continue;
2713
+ for (const s of schema[1].split(/\s*,\s*/).map((x) => x.trim())) {
2714
+ if (exposed.has(s)) continue;
2715
+ ctx.report({
2716
+ rule: "migration-grants",
2717
+ file,
2718
+ line,
2719
+ subject: `schema ${s}`,
2720
+ message: `grants schema ${s} to ${roles.join(" and ")}; a schema outside the exposed ones stays closed to anon and public`
2721
+ });
2722
+ }
2723
+ }
2724
+ }
2725
+ }
2726
+ }
2727
+ function checkRls(ctx, migrations, exposed) {
2728
+ const tables = /* @__PURE__ */ new Map();
2729
+ const name = String.raw`([\w$.]+)`;
2730
+ const target = String.raw`^alter table (?:if exists )?(?:only )?${name}`;
2731
+ for (const { file, statements } of migrations) {
2732
+ for (const { sql, line, bodies } of statements) {
2733
+ if (bodies.some((b) => /\benable row level security\b/.test(b))) for (const t of tables.values()) t.rls = true;
2734
+ const create = new RegExp(String.raw`^create (?:(?:global |local )?(?:temp|temporary) |unlogged )?table (?:if not exists )?${name}`).exec(sql);
2735
+ if (create) {
2736
+ if (!/^create (?:global |local )?(?:temp|temporary) /.test(sql)) tables.set(qualify(create[1]), { rls: false, file, line, disabled: false });
2737
+ continue;
2738
+ }
2739
+ const rename = new RegExp(`${target} rename to ([\\w$]+)$`).exec(sql);
2740
+ const move = new RegExp(`${target} set schema ([\\w$]+)$`).exec(sql);
2741
+ if (rename || move) {
2742
+ const from = qualify((rename ?? move)[1]);
2743
+ const to = rename ? `${schemaOf(from)}.${rename[2]}` : `${move[2]}.${from.split(".")[1]}`;
2744
+ const state = tables.get(from);
2745
+ if (state) {
2746
+ tables.delete(from);
2747
+ tables.set(to, state);
2748
+ }
2749
+ continue;
2750
+ }
2751
+ const alter = new RegExp(target).exec(sql);
2752
+ if (alter && /\b(?:enable|disable) row level security\b/.test(sql)) {
2753
+ const t = qualify(alter[1]);
2754
+ if (/\bdisable row level security\b/.test(sql)) tables.set(t, { rls: false, file, line, disabled: true });
2755
+ else {
2756
+ const state = tables.get(t);
2757
+ if (state) state.rls = true;
2758
+ }
2759
+ continue;
2760
+ }
2761
+ const drop = /^drop table (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
2762
+ if (drop) for (const n of drop[1].split(",")) tables.delete(qualify(n));
2763
+ }
2764
+ }
2765
+ for (const [t, at] of tables) {
2766
+ if (at.rls || !exposed.has(schemaOf(t))) continue;
2767
+ ctx.report({
2768
+ rule: "migration-rls",
2769
+ file: at.file,
2770
+ line: at.line,
2771
+ subject: t,
2772
+ message: at.disabled ? `disables row level security on ${t}, and no later migration turns it back on; anyone with the API key can read and write it` : `creates ${t} without enabling row level security in any migration; add "alter table ${t} enable row level security;" and its policies`
2773
+ });
2774
+ }
2775
+ }
2776
+ function checkDefinerSearchPath(ctx, migrations) {
2777
+ const fns = /* @__PURE__ */ new Map();
2778
+ const keysFor = (sql, nameEnd, fnName) => {
2779
+ const rest = sql.slice(nameEnd).trimStart();
2780
+ if (rest.startsWith("(")) {
2781
+ const { inner } = parenthesized(rest, 0);
2782
+ return [`${fnName}(${argTypes(inner).join(",")})`];
2783
+ }
2784
+ return [...fns.keys()].filter((k) => k.startsWith(`${fnName}(`));
2785
+ };
2786
+ for (const { file, statements } of migrations) {
2787
+ for (const { sql, line } of statements) {
2788
+ const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
2789
+ if (create) {
2790
+ const [key] = keysFor(sql, create[0].length, qualify(create[1]));
2791
+ fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
2792
+ continue;
2793
+ }
2794
+ const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
2795
+ if (alter) {
2796
+ const fnName = qualify(alter[1]);
2797
+ const keys = keysFor(sql, alter[0].length, fnName);
2798
+ const rename = / rename to ([\w$]+)$/.exec(sql);
2799
+ const move = / set schema ([\w$]+)$/.exec(sql);
2800
+ for (const key of keys) {
2801
+ const state = fns.get(key);
2802
+ if (rename || move) {
2803
+ if (!state) continue;
2804
+ fns.delete(key);
2805
+ const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
2806
+ fns.set(newName + key.slice(fnName.length), state);
2807
+ continue;
2808
+ }
2809
+ const next = state ?? { definer: false, searchPath: false, file, line };
2810
+ if (/\bsecurity definer\b/.test(sql)) Object.assign(next, { definer: true, file, line });
2811
+ if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
2812
+ if (/\bset search_path\b/.test(sql)) next.searchPath = true;
2813
+ if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
2814
+ fns.set(key, next);
2815
+ }
2816
+ continue;
2817
+ }
2818
+ const drop = /^drop (?:function|procedure|routine) (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
2819
+ if (drop) {
2820
+ for (const part of splitTop(drop[1])) {
2821
+ const m = /^([\w$.]+)\s*/.exec(part);
2822
+ if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
2823
+ }
2824
+ }
2825
+ }
2826
+ }
2827
+ for (const [key, at] of fns) {
2828
+ if (!at.definer || at.searchPath) continue;
2829
+ ctx.report({
2830
+ rule: "migration-definer-search-path",
2831
+ file: at.file,
2832
+ line: at.line,
2833
+ subject: key,
2834
+ message: `${key} is security definer without "set search_path"; add set search_path = '' and schema-qualify the names in its body, so a caller's objects can't stand in for yours`
2835
+ });
2836
+ }
2837
+ }
1891
2838
  var UMBRELLA_PACKAGE = "@marktiderman/genesis";
1892
2839
  function readReleaseManifest(root) {
1893
2840
  const dir = findPackageDir(root, UMBRELLA_PACKAGE);
@@ -1935,7 +2882,9 @@ async function runDoctor(options = {}) {
1935
2882
  { name: "colors", check: checkColors },
1936
2883
  { name: "tokens", check: checkTokens },
1937
2884
  { name: "shadowed-exports", check: checkShadowedExports },
1938
- { name: "version-skew", check: checkVersionSkew }
2885
+ { name: "version-skew", check: checkVersionSkew },
2886
+ ...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
2887
+ ...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
1939
2888
  ];
1940
2889
  for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
1941
2890
  try {