@marktiderman/genesis-cli 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -3
- package/dist/cli.js +4602 -1549
- package/dist/cli.js.map +1 -1
- package/dist/{config-Ci-_Ue-1.d.ts → config-CrZbM3jD.d.ts} +73 -4
- package/dist/doctor.d.ts +31 -4
- package/dist/doctor.js +976 -30
- package/dist/doctor.js.map +1 -1
- package/dist/expo.d.ts +91 -8
- package/dist/expo.js +207 -14
- package/dist/expo.js.map +1 -1
- package/dist/genesis-catalog.json +502 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +987 -38
- package/dist/index.js.map +1 -1
- package/dist/scaffolder.d.ts +1 -1
- package/dist/scaffolder.js +9 -6
- package/dist/scaffolder.js.map +1 -1
- package/dist/starter/.eas/scripts/rollout-health.mjs +85 -0
- package/dist/starter/.eas/workflows/deploy-production.yml +149 -0
- package/dist/starter/.eas/workflows/e2e.yml +77 -0
- package/dist/starter/.eas/workflows/pr-preview.yml +117 -0
- package/dist/starter/.eas/workflows/rollout.yml +120 -0
- package/dist/starter/.env.example +11 -0
- package/dist/starter/.fingerprintignore +7 -0
- package/dist/starter/.maestro/README.md +38 -0
- package/dist/starter/.maestro/config.yaml +5 -0
- package/dist/starter/.maestro/flows/deep-link.yaml +22 -0
- package/dist/starter/.maestro/flows/launch.yaml +17 -0
- package/dist/starter/.maestro/flows/settings-version.yaml +28 -0
- package/dist/starter/.maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/starter/.maestro/subflows/sign-in.yaml +20 -0
- package/dist/starter/README.md +314 -0
- package/dist/starter/__tests__/app-config.test.ts +51 -0
- package/dist/starter/__tests__/check-in-photos.test.ts +57 -0
- package/dist/starter/__tests__/components/css-stub.js +2 -0
- package/dist/starter/__tests__/components/fake-supabase.ts +136 -0
- package/dist/starter/__tests__/components/links.test.ts +25 -0
- package/dist/starter/__tests__/components/render-app.ts +22 -0
- package/dist/starter/__tests__/components/reports.ts +10 -0
- package/dist/starter/__tests__/components/resolver.js +12 -0
- package/dist/starter/__tests__/components/root-layout.test.tsx +55 -0
- package/dist/starter/__tests__/components/session-storage.test.tsx +81 -0
- package/dist/starter/__tests__/components/settings.test.tsx +134 -0
- package/dist/starter/__tests__/components/setup.ts +69 -0
- package/dist/starter/__tests__/components/sign-in.test.tsx +90 -0
- package/dist/starter/__tests__/components/tabs-feature-off.test.tsx +19 -0
- package/dist/starter/__tests__/components/tabs.test.tsx +43 -0
- package/dist/starter/__tests__/components/tabs.ts +12 -0
- package/dist/starter/__tests__/entry.test.ts +28 -0
- package/dist/starter/__tests__/inline-copy.ts +59 -0
- package/dist/starter/__tests__/starter.test.ts +319 -0
- package/dist/starter/_gitignore +13 -0
- package/dist/starter/app.config.ts +44 -0
- package/dist/starter/babel.config.js +9 -0
- package/dist/starter/eas.json +47 -0
- package/dist/starter/eslint.config.js +5 -0
- package/dist/starter/genesis.config.json +12 -0
- package/dist/starter/global.css +3 -0
- package/dist/starter/index.ts +14 -0
- package/dist/starter/jest.config.js +36 -0
- package/dist/starter/metro.config.js +38 -0
- package/dist/starter/package.json +93 -0
- package/dist/starter/pnpm-workspace.yaml +73 -0
- package/dist/starter/src/app/(app)/(home)/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/(home)/check-in.tsx +41 -0
- package/dist/starter/src/app/(app)/(home)/index.tsx +34 -0
- package/dist/starter/src/app/(app)/_layout.tsx +27 -0
- package/dist/starter/src/app/(app)/notifications/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/notifications/index.tsx +36 -0
- package/dist/starter/src/app/(app)/settings/_layout.tsx +6 -0
- package/dist/starter/src/app/(app)/settings/index.tsx +96 -0
- package/dist/starter/src/app/(app)/settings/notifications.tsx +16 -0
- package/dist/starter/src/app/(app)/settings/support/[id].tsx +23 -0
- package/dist/starter/src/app/(app)/settings/support/ideas.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/index.tsx +20 -0
- package/dist/starter/src/app/(app)/settings/support/new.tsx +35 -0
- package/dist/starter/src/app/(app)/settings/support/shipped.tsx +20 -0
- package/dist/starter/src/app/+native-intent.ts +11 -0
- package/dist/starter/src/app/_layout.tsx +20 -0
- package/dist/starter/src/app/sign-in.tsx +69 -0
- package/dist/starter/src/copy.ts +118 -0
- package/dist/starter/src/forms/check-in.json +121 -0
- package/dist/starter/src/lib/account.ts +42 -0
- package/dist/starter/src/lib/app.ts +52 -0
- package/dist/starter/src/lib/auth.ts +80 -0
- package/dist/starter/src/lib/check-in-photos.ts +66 -0
- package/dist/starter/src/lib/check-in.ts +85 -0
- package/dist/starter/src/lib/define-starter.ts +148 -0
- package/dist/starter/src/lib/devtools-overlay.ts +34 -0
- package/dist/starter/src/lib/devtools.ts +23 -0
- package/dist/starter/src/lib/env.ts +33 -0
- package/dist/starter/src/lib/google-signin.ts +23 -0
- package/dist/starter/src/lib/links.ts +40 -0
- package/dist/starter/src/lib/native-modules.ts +27 -0
- package/dist/starter/src/lib/notifications.ts +15 -0
- package/dist/starter/src/lib/observability.ts +45 -0
- package/dist/starter/src/lib/push.ts +49 -0
- package/dist/starter/src/lib/supabase.ts +65 -0
- package/dist/starter/src/lib/support.ts +44 -0
- package/dist/starter/src/lib/updates.ts +61 -0
- package/dist/starter/starter.config.ts +37 -0
- package/dist/starter/supabase/config.toml +26 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/apple.ts +237 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/handler.ts +227 -0
- package/dist/starter/supabase/functions/genesis-apple-revoke/index.ts +55 -0
- package/dist/starter/supabase/functions/genesis-push-send/expo.ts +117 -0
- package/dist/starter/supabase/functions/genesis-push-send/handler.ts +462 -0
- package/dist/starter/supabase/functions/genesis-push-send/index.ts +54 -0
- package/dist/starter/supabase/migrations/20261024000000_genesis_account_deletion.sql +133 -0
- package/dist/starter/supabase/migrations/20261024000100_genesis_app_release_policy.sql +82 -0
- package/dist/starter/supabase/migrations/20261024000200_genesis_apple_token_revocation.sql +205 -0
- package/dist/starter/supabase/migrations/20261024000400_genesis_push.sql +524 -0
- package/dist/starter/supabase/migrations/20261024000600_genesis_support.sql +846 -0
- package/dist/starter/supabase/tests/database/genesis_account_deletion.test.sql +138 -0
- package/dist/starter/supabase/tests/database/genesis_app_release_policy.test.sql +148 -0
- package/dist/starter/supabase/tests/database/genesis_apple_token_revocation.test.sql +230 -0
- package/dist/starter/supabase/tests/database/genesis_push.test.sql +407 -0
- package/dist/starter/supabase/tests/database/genesis_support.test.sql +552 -0
- package/dist/starter/tailwind.config.mjs +15 -0
- package/dist/starter/tsconfig.json +14 -0
- package/dist/starter/vitest.config.mts +7 -0
- package/dist/templates/ci/app-ci.yml +17 -0
- package/dist/templates/ci/genesis-upgrade.yml +21 -0
- package/dist/templates/ci/supabase-ci.yml +20 -0
- package/dist/templates/eas/eas.json +47 -0
- package/dist/templates/eas/scripts/rollout-health.mjs +85 -0
- package/dist/templates/eas/workflows/deploy-production.yml +149 -0
- package/dist/templates/eas/workflows/e2e.yml +77 -0
- package/dist/templates/eas/workflows/pr-preview.yml +117 -0
- package/dist/templates/eas/workflows/rollout.yml +120 -0
- package/dist/templates/maestro/config.yaml +5 -0
- package/dist/templates/maestro/flows/deep-link.yaml +22 -0
- package/dist/templates/maestro/flows/launch.yaml +17 -0
- package/dist/templates/maestro/flows/settings-version.yaml +28 -0
- package/dist/templates/maestro/flows/sign-in-screen.yaml +17 -0
- package/dist/templates/maestro/subflows/sign-in.yaml +20 -0
- package/dist/vite.js +975 -29
- package/dist/vite.js.map +1 -1
- package/package.json +4 -4
package/dist/doctor.js
CHANGED
|
@@ -51,6 +51,54 @@ var GenesisConfigError = class extends Error {
|
|
|
51
51
|
var DoctorConfigError = class extends GenesisConfigError {
|
|
52
52
|
name = "DoctorConfigError";
|
|
53
53
|
};
|
|
54
|
+
var PRIVACY_DATA_TYPES = {
|
|
55
|
+
name: "NSPrivacyCollectedDataTypeName",
|
|
56
|
+
"email address": "NSPrivacyCollectedDataTypeEmailAddress",
|
|
57
|
+
"phone number": "NSPrivacyCollectedDataTypePhoneNumber",
|
|
58
|
+
"physical address": "NSPrivacyCollectedDataTypePhysicalAddress",
|
|
59
|
+
"other user contact info": "NSPrivacyCollectedDataTypeOtherUserContactInfo",
|
|
60
|
+
health: "NSPrivacyCollectedDataTypeHealth",
|
|
61
|
+
fitness: "NSPrivacyCollectedDataTypeFitness",
|
|
62
|
+
"payment info": "NSPrivacyCollectedDataTypePaymentInfo",
|
|
63
|
+
"credit info": "NSPrivacyCollectedDataTypeCreditInfo",
|
|
64
|
+
"other financial info": "NSPrivacyCollectedDataTypeOtherFinancialInfo",
|
|
65
|
+
"precise location": "NSPrivacyCollectedDataTypePreciseLocation",
|
|
66
|
+
"coarse location": "NSPrivacyCollectedDataTypeCoarseLocation",
|
|
67
|
+
"sensitive info": "NSPrivacyCollectedDataTypeSensitiveInfo",
|
|
68
|
+
contacts: "NSPrivacyCollectedDataTypeContacts",
|
|
69
|
+
"emails or text messages": "NSPrivacyCollectedDataTypeEmailsOrTextMessages",
|
|
70
|
+
"photos or videos": "NSPrivacyCollectedDataTypePhotosorVideos",
|
|
71
|
+
"audio data": "NSPrivacyCollectedDataTypeAudioData",
|
|
72
|
+
"gameplay content": "NSPrivacyCollectedDataTypeGameplayContent",
|
|
73
|
+
"customer support": "NSPrivacyCollectedDataTypeCustomerSupport",
|
|
74
|
+
"other user content": "NSPrivacyCollectedDataTypeOtherUserContent",
|
|
75
|
+
"browsing history": "NSPrivacyCollectedDataTypeBrowsingHistory",
|
|
76
|
+
"search history": "NSPrivacyCollectedDataTypeSearchHistory",
|
|
77
|
+
"user id": "NSPrivacyCollectedDataTypeUserID",
|
|
78
|
+
"device id": "NSPrivacyCollectedDataTypeDeviceID",
|
|
79
|
+
"purchase history": "NSPrivacyCollectedDataTypePurchaseHistory",
|
|
80
|
+
"product interaction": "NSPrivacyCollectedDataTypeProductInteraction",
|
|
81
|
+
"advertising data": "NSPrivacyCollectedDataTypeAdvertisingData",
|
|
82
|
+
"other usage data": "NSPrivacyCollectedDataTypeOtherUsageData",
|
|
83
|
+
"crash data": "NSPrivacyCollectedDataTypeCrashData",
|
|
84
|
+
"performance data": "NSPrivacyCollectedDataTypePerformanceData",
|
|
85
|
+
"other diagnostic data": "NSPrivacyCollectedDataTypeOtherDiagnosticData",
|
|
86
|
+
"environment scanning": "NSPrivacyCollectedDataTypeEnvironmentScanning",
|
|
87
|
+
hands: "NSPrivacyCollectedDataTypeHands",
|
|
88
|
+
head: "NSPrivacyCollectedDataTypeHead",
|
|
89
|
+
"other data types": "NSPrivacyCollectedDataTypeOtherDataTypes"
|
|
90
|
+
};
|
|
91
|
+
function privacyDataType(type) {
|
|
92
|
+
return PRIVACY_DATA_TYPES[type.toLowerCase()];
|
|
93
|
+
}
|
|
94
|
+
var PRIVACY_PURPOSES = {
|
|
95
|
+
"app functionality": "NSPrivacyCollectedDataTypePurposeAppFunctionality",
|
|
96
|
+
analytics: "NSPrivacyCollectedDataTypePurposeAnalytics",
|
|
97
|
+
"product personalization": "NSPrivacyCollectedDataTypePurposeProductPersonalization",
|
|
98
|
+
"developer advertising": "NSPrivacyCollectedDataTypePurposeDeveloperAdvertising",
|
|
99
|
+
"third-party advertising": "NSPrivacyCollectedDataTypePurposeThirdPartyAdvertising",
|
|
100
|
+
other: "NSPrivacyCollectedDataTypePurposeOther"
|
|
101
|
+
};
|
|
54
102
|
var STRING_LISTS = ["src", "extensions", "ignore", "tokenFiles", "ignoreTokenPrefixes", "localPrimitiveDirs", "build"];
|
|
55
103
|
var STRINGS = ["uiPackage", "rulesDoc"];
|
|
56
104
|
var KNOWN = /* @__PURE__ */ new Set([
|
|
@@ -63,11 +111,26 @@ var KNOWN = /* @__PURE__ */ new Set([
|
|
|
63
111
|
"allow",
|
|
64
112
|
"patterns",
|
|
65
113
|
"plugins",
|
|
114
|
+
"packs",
|
|
115
|
+
"native",
|
|
116
|
+
"supabase",
|
|
66
117
|
"$schema",
|
|
67
118
|
"$comment"
|
|
68
119
|
]);
|
|
69
120
|
var LEVELS = /* @__PURE__ */ new Set(["error", "warn", "off"]);
|
|
70
121
|
var PATTERN_KEYS = /* @__PURE__ */ new Set(["id", "level", "files", "exclude", "forbid", "require", "path", "message"]);
|
|
122
|
+
var PACKS = /* @__PURE__ */ new Set(["native", "supabase"]);
|
|
123
|
+
var PACK_KEYS = {
|
|
124
|
+
native: { routerRoot: "path" },
|
|
125
|
+
supabase: { migrations: "path", base: "string", exposedSchemas: "list", since: "string" }
|
|
126
|
+
};
|
|
127
|
+
function appPath(v, where, fail) {
|
|
128
|
+
if (typeof v !== "string" || !v.trim()) return fail(`${where} must be a non-empty path`);
|
|
129
|
+
if (path3.isAbsolute(v) || /^[A-Za-z]:[\\/]/.test(v)) fail(`${where} must be relative to the app, not absolute ("${v}")`);
|
|
130
|
+
const norm = path3.posix.normalize(v.replace(/\\/g, "/")).replace(/\/+$/, "");
|
|
131
|
+
if (norm === "." || norm === ".." || norm.startsWith("../")) fail(`${where} must be a folder inside the app ("${v}")`);
|
|
132
|
+
return norm;
|
|
133
|
+
}
|
|
71
134
|
function loadConfig(root, configPath) {
|
|
72
135
|
if (configPath) {
|
|
73
136
|
const file = path3.resolve(root, configPath);
|
|
@@ -100,8 +163,48 @@ function readGenesisConfig(root) {
|
|
|
100
163
|
if (!existsSync(file)) return null;
|
|
101
164
|
const raw = readJson(file);
|
|
102
165
|
if (!isObject(raw)) throw new GenesisConfigError(`${file}: the config must be a JSON object`);
|
|
103
|
-
const
|
|
104
|
-
|
|
166
|
+
const out = { raw };
|
|
167
|
+
if (raw.links !== void 0) out.links = validateLinks(raw.links, file);
|
|
168
|
+
if (raw.privacy !== void 0) out.privacy = validatePrivacy(raw.privacy, file);
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
var PRIVACY_KEYS = /* @__PURE__ */ new Set(["blocks", "collects", "tracking"]);
|
|
172
|
+
var DATA_USE_KEYS = /* @__PURE__ */ new Set(["type", "purposes", "linked", "tracking"]);
|
|
173
|
+
function validatePrivacy(raw, source = "config") {
|
|
174
|
+
const fail = (msg) => {
|
|
175
|
+
throw new GenesisConfigError(`${source}: ${msg}`);
|
|
176
|
+
};
|
|
177
|
+
if (!isObject(raw)) fail(`"privacy" must be an object`);
|
|
178
|
+
const c = raw;
|
|
179
|
+
for (const key of Object.keys(c)) if (!PRIVACY_KEYS.has(key)) fail(`privacy: unknown setting "${key}"`);
|
|
180
|
+
const out = {};
|
|
181
|
+
if (c.blocks !== void 0) {
|
|
182
|
+
if (!isStringList(c.blocks)) fail(`privacy.blocks must be a list of block ids`);
|
|
183
|
+
out.blocks = [...new Set(c.blocks)];
|
|
184
|
+
}
|
|
185
|
+
if (c.tracking !== void 0) {
|
|
186
|
+
if (typeof c.tracking !== "boolean") fail(`privacy.tracking must be true or false`);
|
|
187
|
+
out.tracking = c.tracking;
|
|
188
|
+
}
|
|
189
|
+
if (c.collects !== void 0) {
|
|
190
|
+
if (!Array.isArray(c.collects)) fail(`privacy.collects must be a list`);
|
|
191
|
+
out.collects = c.collects.map((entry, i) => {
|
|
192
|
+
const where = `privacy.collects[${i}]`;
|
|
193
|
+
if (!isObject(entry)) return fail(`${where} must be an object`);
|
|
194
|
+
for (const key of Object.keys(entry)) if (!DATA_USE_KEYS.has(key)) fail(`${where}: unknown setting "${key}"`);
|
|
195
|
+
if (typeof entry.type !== "string" || !privacyDataType(entry.type)) {
|
|
196
|
+
fail(`${where}.type "${String(entry.type)}" is not one of ${Object.keys(PRIVACY_DATA_TYPES).join(", ")}`);
|
|
197
|
+
}
|
|
198
|
+
if (!isStringList(entry.purposes) || entry.purposes.length === 0) fail(`${where}.purposes must be a non-empty list`);
|
|
199
|
+
for (const p of entry.purposes) {
|
|
200
|
+
if (!(p in PRIVACY_PURPOSES)) fail(`${where}.purposes: "${p}" is not one of ${Object.keys(PRIVACY_PURPOSES).join(", ")}`);
|
|
201
|
+
}
|
|
202
|
+
if (typeof entry.linked !== "boolean") fail(`${where}.linked must be true or false`);
|
|
203
|
+
if (typeof entry.tracking !== "boolean") fail(`${where}.tracking must be true or false`);
|
|
204
|
+
return { type: entry.type, purposes: [...new Set(entry.purposes)], linked: entry.linked, tracking: entry.tracking };
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
return out;
|
|
105
208
|
}
|
|
106
209
|
var LINK_KEYS = /* @__PURE__ */ new Set(["hosts", "paths", "webcredentials"]);
|
|
107
210
|
var HOST = /^(?=.{1,253}$)(\*\.)?([a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/;
|
|
@@ -191,6 +294,27 @@ function validateConfig(raw, source = "config") {
|
|
|
191
294
|
}
|
|
192
295
|
});
|
|
193
296
|
}
|
|
297
|
+
if (c.packs !== void 0) {
|
|
298
|
+
if (!isStringList(c.packs)) fail(`"packs" must be a list, e.g. ["native", "supabase"]`);
|
|
299
|
+
for (const p of c.packs) if (!PACKS.has(p)) fail(`packs: unknown pack "${p}" (known: ${[...PACKS].join(", ")})`);
|
|
300
|
+
if (new Set(c.packs).size !== c.packs.length) fail(`packs: lists a pack twice`);
|
|
301
|
+
}
|
|
302
|
+
for (const [pack, keys] of Object.entries(PACK_KEYS)) {
|
|
303
|
+
const block = c[pack];
|
|
304
|
+
if (block === void 0) continue;
|
|
305
|
+
if (!isObject(block)) fail(`"${pack}" must be an object`);
|
|
306
|
+
if (!(c.packs ?? []).includes(pack)) fail(`"${pack}" settings are set but the ${pack} pack is not in "packs"`);
|
|
307
|
+
for (const [k, v] of Object.entries(block)) {
|
|
308
|
+
const want = keys[k];
|
|
309
|
+
if (!want) fail(`${pack}: unknown setting "${k}"`);
|
|
310
|
+
if (want === "string" && typeof v !== "string") fail(`${pack}.${k} must be a string`);
|
|
311
|
+
if (want === "list" && !isStringList(v)) fail(`${pack}.${k} must be a list of strings`);
|
|
312
|
+
if (want === "string" && !v.trim()) fail(`${pack}.${k} must not be empty`);
|
|
313
|
+
if (want === "path") block[k] = appPath(v, `${pack}.${k}`, fail);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const supa = c.supabase;
|
|
317
|
+
if (Array.isArray(supa?.exposedSchemas)) supa.exposedSchemas = supa.exposedSchemas.map((s) => s.toLowerCase());
|
|
194
318
|
if (c.plugins !== void 0) {
|
|
195
319
|
const ok = Array.isArray(c.plugins) && c.plugins.every((p) => typeof p === "string" || Array.isArray(p) && p.length === 2 && typeof p[0] === "string");
|
|
196
320
|
if (!ok) fail(`"plugins" must be a list of module paths or [path, options] pairs`);
|
|
@@ -236,9 +360,10 @@ function globToRegExp(glob) {
|
|
|
236
360
|
}
|
|
237
361
|
function globMatcher(globs) {
|
|
238
362
|
const res = (globs ?? []).filter((g) => g.trim()).map(globToRegExp);
|
|
239
|
-
return (
|
|
363
|
+
return (path13) => res.some((re) => re.test(path13));
|
|
240
364
|
}
|
|
241
365
|
var DEFAULT_UI_PACKAGE = "@marktiderman/genesis-ui";
|
|
366
|
+
var NATIVE_UI_PACKAGE = "@marktiderman/genesis-ui-native";
|
|
242
367
|
var DESIGN_SYSTEM_PACKAGE = "@marktiderman/genesis-design-system";
|
|
243
368
|
var TAGS = ["button", "input", "textarea", "select", "label", "table", "dialog", "progress", "details", "summary"];
|
|
244
369
|
var TAG_ALIASES = { hr: "Separator" };
|
|
@@ -283,10 +408,39 @@ function findPackageDir(from, name) {
|
|
|
283
408
|
dir = parent;
|
|
284
409
|
}
|
|
285
410
|
}
|
|
411
|
+
function uiPackageFor(config) {
|
|
412
|
+
return config.uiPackage ?? (config.packs?.includes("native") ? NATIVE_UI_PACKAGE : DEFAULT_UI_PACKAGE);
|
|
413
|
+
}
|
|
286
414
|
function loadGenesis(root, config) {
|
|
287
|
-
const uiPackage = config
|
|
415
|
+
const uiPackage = uiPackageFor(config);
|
|
416
|
+
const pkg = readPackageExports(root, uiPackage);
|
|
417
|
+
if (!pkg) throw new DoctorConfigError(`${uiPackage} is not installed here. Install it, or set doctor.uiPackage.`);
|
|
418
|
+
const { dir: uiDir, exports: exportNames, values, components } = pkg;
|
|
419
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
420
|
+
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
421
|
+
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
422
|
+
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
423
|
+
const rawTags = /* @__PURE__ */ new Map();
|
|
424
|
+
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
425
|
+
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
426
|
+
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
427
|
+
if (comp === false) rawTags.delete(tag);
|
|
428
|
+
else rawTags.set(tag, comp);
|
|
429
|
+
}
|
|
430
|
+
return {
|
|
431
|
+
uiPackage,
|
|
432
|
+
uiVersion: pkg.version,
|
|
433
|
+
exports: exportNames,
|
|
434
|
+
values,
|
|
435
|
+
components,
|
|
436
|
+
tokens,
|
|
437
|
+
rawTags,
|
|
438
|
+
palette: loadPalette(root)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
function readPackageExports(root, uiPackage) {
|
|
288
442
|
const uiDir = findPackageDir(root, uiPackage);
|
|
289
|
-
if (!uiDir)
|
|
443
|
+
if (!uiDir) return null;
|
|
290
444
|
const uiPkg = JSON.parse(readFileSync(path3.join(uiDir, "package.json"), "utf8"));
|
|
291
445
|
const typeEntries = /* @__PURE__ */ new Set();
|
|
292
446
|
const mainTypes = uiPkg.types ?? uiPkg.typings ?? exportTypes(uiPkg.exports?.["."] ?? uiPkg.exports);
|
|
@@ -327,27 +481,7 @@ function loadGenesis(root, config) {
|
|
|
327
481
|
const isTypeOnly = (n) => typeDecls.has(n) && !valueDecls.has(n);
|
|
328
482
|
const values = new Set([...exportNames].filter((n) => !isTypeOnly(n)));
|
|
329
483
|
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();
|
|
330
|
-
|
|
331
|
-
const themeFiles = resolveThemeFiles(root, config, uiDir);
|
|
332
|
-
for (const file of themeFiles) for (const t of declaredTokens(readFileSync(file, "utf8"))) tokens.add(t);
|
|
333
|
-
const byLower = new Map(components.map((c) => [c.toLowerCase(), c]));
|
|
334
|
-
const rawTags = /* @__PURE__ */ new Map();
|
|
335
|
-
for (const tag of TAGS) if (byLower.has(tag)) rawTags.set(tag, byLower.get(tag));
|
|
336
|
-
for (const [tag, comp] of Object.entries(TAG_ALIASES)) if (values.has(comp)) rawTags.set(tag, comp);
|
|
337
|
-
for (const [tag, comp] of Object.entries(config.rawTags ?? {})) {
|
|
338
|
-
if (comp === false) rawTags.delete(tag);
|
|
339
|
-
else rawTags.set(tag, comp);
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
uiPackage,
|
|
343
|
-
uiVersion: String(uiPkg.version ?? "unknown"),
|
|
344
|
-
exports: exportNames,
|
|
345
|
-
values,
|
|
346
|
-
components,
|
|
347
|
-
tokens,
|
|
348
|
-
rawTags,
|
|
349
|
-
palette: loadPalette(root)
|
|
350
|
-
};
|
|
484
|
+
return { dir: uiDir, version: String(uiPkg.version ?? "unknown"), exports: exportNames, values, components };
|
|
351
485
|
}
|
|
352
486
|
function parseExportNames(dts) {
|
|
353
487
|
const names = [];
|
|
@@ -600,6 +734,7 @@ function findColorFunctions(line) {
|
|
|
600
734
|
|
|
601
735
|
// src/doctor/scan.ts
|
|
602
736
|
var DEFAULT_SRC = ["src"];
|
|
737
|
+
var DEFAULT_NATIVE_SRC = ["app", "src", "components"];
|
|
603
738
|
var DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".css"];
|
|
604
739
|
var DEFAULT_IGNORE = [
|
|
605
740
|
"**/*.d.ts",
|
|
@@ -637,7 +772,7 @@ function scanFiles(root, config) {
|
|
|
637
772
|
}
|
|
638
773
|
}
|
|
639
774
|
};
|
|
640
|
-
for (const src of config.src ?? DEFAULT_SRC) {
|
|
775
|
+
for (const src of config.src ?? (config.packs?.includes("native") ? DEFAULT_NATIVE_SRC : DEFAULT_SRC)) {
|
|
641
776
|
const abs = path3.resolve(root, src);
|
|
642
777
|
if (!existsSync(abs)) continue;
|
|
643
778
|
if (statSync(abs).isDirectory()) walk(abs);
|
|
@@ -793,7 +928,18 @@ var BUILTIN_RULES = [
|
|
|
793
928
|
"raw-color",
|
|
794
929
|
"undefined-token",
|
|
795
930
|
"shadowed-export",
|
|
796
|
-
"version-skew"
|
|
931
|
+
"version-skew",
|
|
932
|
+
// native pack
|
|
933
|
+
"native-raw-primitive",
|
|
934
|
+
"native-literal-color",
|
|
935
|
+
"native-custom-header",
|
|
936
|
+
"native-screen-layout",
|
|
937
|
+
"store-readiness",
|
|
938
|
+
// supabase pack
|
|
939
|
+
"migration-grants",
|
|
940
|
+
"migration-rls",
|
|
941
|
+
"migration-definer-search-path",
|
|
942
|
+
"migration-edited"
|
|
797
943
|
];
|
|
798
944
|
var DEFAULT_LOCAL_PRIMITIVE_DIRS = ["src/components/ui"];
|
|
799
945
|
var STARTER_LEFTOVERS = ["components.json", "src/lib/utils.ts"];
|
|
@@ -869,7 +1015,10 @@ function checkColors(ctx) {
|
|
|
869
1015
|
`(?<![\\w-])(?:${COLOR_UTILITIES})-(?:${ctx.genesis.palette.join("|")})(?:-\\d{2,3})?(?:\\/\\d{1,3})?(?![\\w-])`,
|
|
870
1016
|
"g"
|
|
871
1017
|
);
|
|
1018
|
+
const native = ctx.config.packs?.includes("native") ?? false;
|
|
1019
|
+
const themeRoles = ctx.genesis.values.has("useThemeRoles") ? "a theme role (useThemeRoles())" : "a theme role";
|
|
872
1020
|
for (const file of ctx.files) {
|
|
1021
|
+
const nativeCode = native && SCRIPT_EXTS.has(file.ext);
|
|
873
1022
|
file.code.split("\n").forEach((text, i) => {
|
|
874
1023
|
const line = i + 1;
|
|
875
1024
|
for (const m of text.matchAll(palette)) {
|
|
@@ -883,6 +1032,16 @@ function checkColors(ctx) {
|
|
|
883
1032
|
for (const hit of [...findHexLiterals(text), ...findColorFunctions(text)]) {
|
|
884
1033
|
const at = hit.column - 1;
|
|
885
1034
|
if (arbitrary.some(([a, b]) => at >= a && at < b)) continue;
|
|
1035
|
+
if (nativeCode) {
|
|
1036
|
+
ctx.report({
|
|
1037
|
+
rule: "native-literal-color",
|
|
1038
|
+
file: file.path,
|
|
1039
|
+
line,
|
|
1040
|
+
subject: hit.literal,
|
|
1041
|
+
message: `hardcodes the color ${hit.literal}; use ${themeRoles}, a token className (bg-primary, text-muted-foreground) or PlatformColor(...)`
|
|
1042
|
+
});
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
886
1045
|
ctx.report({ rule: "raw-color", file: file.path, line, subject: hit.literal, message: `hardcodes the color ${hit.literal}; color values come from Genesis tokens` });
|
|
887
1046
|
}
|
|
888
1047
|
});
|
|
@@ -939,6 +1098,791 @@ function unusedComponents(ctx) {
|
|
|
939
1098
|
}
|
|
940
1099
|
return ctx.genesis.components.filter((c) => !used.has(c));
|
|
941
1100
|
}
|
|
1101
|
+
|
|
1102
|
+
// ../../scripts/lib/native-primitives.mjs
|
|
1103
|
+
var NATIVE_WRAPPED_PRIMITIVES = Object.freeze({
|
|
1104
|
+
Modal: Object.freeze(["NativeDialog", "NativeSheet", "NativeDrawer"]),
|
|
1105
|
+
ActivityIndicator: Object.freeze(["NativeSkeleton", "NativeProgress"])
|
|
1106
|
+
});
|
|
1107
|
+
function wrappedPrimitivesIn(namedImports) {
|
|
1108
|
+
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));
|
|
1109
|
+
}
|
|
1110
|
+
var api = (category, ...reasons) => ({
|
|
1111
|
+
NSPrivacyAccessedAPIType: `NSPrivacyAccessedAPICategory${category}`,
|
|
1112
|
+
NSPrivacyAccessedAPITypeReasons: reasons
|
|
1113
|
+
});
|
|
1114
|
+
var PRIVACY_APIS = {
|
|
1115
|
+
"react-native": [api("FileTimestamp", "C617.1"), api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1")],
|
|
1116
|
+
expo: [api("FileTimestamp", "0A2A.1", "3B52.1"), api("DiskSpace", "E174.1", "85F4.1"), api("UserDefaults", "CA92.1")],
|
|
1117
|
+
"expo-updates": [api("UserDefaults", "CA92.1")],
|
|
1118
|
+
"expo-application": [api("FileTimestamp", "C617.1")],
|
|
1119
|
+
"expo-notifications": [api("UserDefaults", "CA92.1")],
|
|
1120
|
+
"@react-native-async-storage/async-storage": [api("FileTimestamp", "C617.1")],
|
|
1121
|
+
"@sentry/react-native": [api("UserDefaults", "CA92.1"), api("SystemBootTime", "35F9.1"), api("FileTimestamp", "C617.1")]
|
|
1122
|
+
};
|
|
1123
|
+
var appFunctionality = (type, ...more) => ({
|
|
1124
|
+
type,
|
|
1125
|
+
purposes: ["app functionality", ...more],
|
|
1126
|
+
linked: true,
|
|
1127
|
+
tracking: false
|
|
1128
|
+
});
|
|
1129
|
+
({
|
|
1130
|
+
account: {
|
|
1131
|
+
collects: [appFunctionality("email address"), appFunctionality("user id"), appFunctionality("name")]
|
|
1132
|
+
},
|
|
1133
|
+
observability: {
|
|
1134
|
+
collects: [
|
|
1135
|
+
appFunctionality("crash data"),
|
|
1136
|
+
appFunctionality("performance data"),
|
|
1137
|
+
appFunctionality("other diagnostic data"),
|
|
1138
|
+
appFunctionality("user id", "analytics"),
|
|
1139
|
+
{ type: "product interaction", purposes: ["analytics"], linked: true, tracking: false }
|
|
1140
|
+
]
|
|
1141
|
+
},
|
|
1142
|
+
push: {
|
|
1143
|
+
collects: [appFunctionality("device ID")]
|
|
1144
|
+
},
|
|
1145
|
+
support: {
|
|
1146
|
+
collects: [
|
|
1147
|
+
appFunctionality("user id"),
|
|
1148
|
+
appFunctionality("customer support"),
|
|
1149
|
+
appFunctionality("other user content"),
|
|
1150
|
+
appFunctionality("photos or videos"),
|
|
1151
|
+
appFunctionality("other diagnostic data")
|
|
1152
|
+
]
|
|
1153
|
+
}
|
|
1154
|
+
});
|
|
1155
|
+
function privacyApisFor(dependencies2) {
|
|
1156
|
+
return Object.keys(PRIVACY_APIS).filter((pkg) => pkg in dependencies2).flatMap((pkg) => PRIVACY_APIS[pkg]);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
// src/doctor/native.ts
|
|
1160
|
+
var SCRIPT_EXTS2 = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx", ".mts", ".cts", ".mjs", ".cjs"]);
|
|
1161
|
+
var JSX_EXTS2 = /* @__PURE__ */ new Set([".tsx", ".jsx"]);
|
|
1162
|
+
var RESOLVE_EXTS = [".tsx", ".ts", ".jsx", ".js"];
|
|
1163
|
+
var LAYOUT_NAME = /(?:Page|Screen|ScreenContainer)$/;
|
|
1164
|
+
var NON_SCREEN_ROUTE = /(?:^|\/)(?:_layout|\+html|\+native-intent|\+middleware)\.[jt]sx?$|\+api\.[jt]sx?$/;
|
|
1165
|
+
var PART_HEADER = /(?:Section|List|Card|Dialog|Table|Group|Column|Row|Cell|Accordion|Sheet|Drawer|Modal|Popover|Menu|Panel|Form)Header$/;
|
|
1166
|
+
var HIDES_HEADER = /\bheaderShown\s*(?::|=\s*\{)\s*false\b/;
|
|
1167
|
+
function nativePackage(ctx) {
|
|
1168
|
+
const pkg = readPackageExports(ctx.root, NATIVE_UI_PACKAGE);
|
|
1169
|
+
if (!pkg) throw new DoctorConfigError(`the native pack needs ${NATIVE_UI_PACKAGE}; install it, or remove "native" from doctor.packs`);
|
|
1170
|
+
return pkg;
|
|
1171
|
+
}
|
|
1172
|
+
function nativeLayouts(pkg) {
|
|
1173
|
+
return pkg.components.filter((n) => LAYOUT_NAME.test(n));
|
|
1174
|
+
}
|
|
1175
|
+
function checkNativePack(ctx) {
|
|
1176
|
+
const pkg = nativePackage(ctx);
|
|
1177
|
+
checkRawPrimitives(ctx, pkg);
|
|
1178
|
+
checkCustomHeaders(ctx, pkg);
|
|
1179
|
+
checkScreenLayouts(ctx, pkg);
|
|
1180
|
+
checkStoreReadiness(ctx);
|
|
1181
|
+
}
|
|
1182
|
+
var RN = String.raw`["']react-native["']`;
|
|
1183
|
+
function checkRawPrimitives(ctx, pkg) {
|
|
1184
|
+
const wrapped = Object.keys(NATIVE_WRAPPED_PRIMITIVES);
|
|
1185
|
+
const named = [
|
|
1186
|
+
// import { Modal } / import RN, { Modal }; `import type { … }` doesn't match.
|
|
1187
|
+
new RegExp(String.raw`\bimport\s+(?:[\w$]+\s*,\s*)?\{([^}]*)\}\s*from\s*${RN}`, "g"),
|
|
1188
|
+
new RegExp(String.raw`\bexport\s+\{([^}]*)\}\s*from\s*${RN}`, "g"),
|
|
1189
|
+
new RegExp(String.raw`\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\(\s*${RN}\s*\)`, "g")
|
|
1190
|
+
];
|
|
1191
|
+
const namespaces = [
|
|
1192
|
+
new RegExp(String.raw`\bimport\s+\*\s+as\s+([\w$]+)\s+from\s*${RN}`, "g"),
|
|
1193
|
+
new RegExp(String.raw`\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*${RN}\s*\)`, "g")
|
|
1194
|
+
];
|
|
1195
|
+
const member = new RegExp(String.raw`\brequire\(\s*${RN}\s*\)\.(${wrapped.join("|")})\b`, "g");
|
|
1196
|
+
for (const file of ctx.files) {
|
|
1197
|
+
if (!SCRIPT_EXTS2.has(file.ext)) continue;
|
|
1198
|
+
const code = file.code;
|
|
1199
|
+
const report = (name, at) => {
|
|
1200
|
+
const use = NATIVE_WRAPPED_PRIMITIVES[name].filter((c) => pkg.values.has(c));
|
|
1201
|
+
ctx.report({
|
|
1202
|
+
rule: "native-raw-primitive",
|
|
1203
|
+
file: file.path,
|
|
1204
|
+
line: lineAt(code, at),
|
|
1205
|
+
subject: name,
|
|
1206
|
+
message: `uses ${name} from react-native, which Genesis wraps; use ${use.length ? use.join(" or ") : "the Genesis wrapper"} from ${NATIVE_UI_PACKAGE}`
|
|
1207
|
+
});
|
|
1208
|
+
};
|
|
1209
|
+
for (const re of named) {
|
|
1210
|
+
for (const m of code.matchAll(re)) {
|
|
1211
|
+
for (const name of wrappedPrimitivesIn(m[1].replace(/:/g, " as "))) report(name, m.index + m[0].indexOf(name));
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
for (const re of namespaces) {
|
|
1215
|
+
for (const m of code.matchAll(re)) {
|
|
1216
|
+
for (const use of code.matchAll(new RegExp(String.raw`\b${m[1].replace(/\$/g, "\\$")}\.(${wrapped.join("|")})\b`, "g"))) report(use[1], use.index);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
for (const m of code.matchAll(member)) report(m[1], m.index);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
function customElement(code, re, pkg) {
|
|
1223
|
+
for (const m of code.matchAll(re)) {
|
|
1224
|
+
const name = m[1];
|
|
1225
|
+
if (!pkg.values.has(name.split(".")[0]) && !PART_HEADER.test(name)) return { name, index: m.index };
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
function ownHeader(code, pkg) {
|
|
1230
|
+
const el = customElement(code, /<([A-Z][\w$]*Header)\b/g, pkg);
|
|
1231
|
+
if (el) return el;
|
|
1232
|
+
const style = /\bstyle=\{\s*styles\.header\s*\}/.exec(code);
|
|
1233
|
+
return style ? { name: "styles.header", index: style.index } : null;
|
|
1234
|
+
}
|
|
1235
|
+
function checkCustomHeaders(ctx, pkg) {
|
|
1236
|
+
const layouts = nativeLayouts(pkg);
|
|
1237
|
+
if (layouts.length === 0) return;
|
|
1238
|
+
const headerWay = pkg.values.has("ScreenContainer") ? `ScreenContainer's header props${pkg.values.has("composeHeaderOptions") ? " (composeHeaderOptions)" : ""}` : `a Genesis layout's header (${layouts.join(", ")})`;
|
|
1239
|
+
const rootDir = routerRoot(ctx);
|
|
1240
|
+
const reported = /* @__PURE__ */ new Set();
|
|
1241
|
+
const hidingLayouts = /* @__PURE__ */ new Map();
|
|
1242
|
+
for (const file of ctx.files) {
|
|
1243
|
+
if (!JSX_EXTS2.has(file.ext)) continue;
|
|
1244
|
+
const code = file.code;
|
|
1245
|
+
const hidden = HIDES_HEADER.exec(code);
|
|
1246
|
+
if (hidden && /(?:^|\/)_layout\.[jt]sx$/.test(file.path)) hidingLayouts.set(path3.posix.dirname(file.path), file.path);
|
|
1247
|
+
const own = hidden ? ownHeader(code, pkg) : null;
|
|
1248
|
+
if (hidden && own) {
|
|
1249
|
+
reported.add(file.path);
|
|
1250
|
+
ctx.report({
|
|
1251
|
+
rule: "native-custom-header",
|
|
1252
|
+
level: "warn",
|
|
1253
|
+
file: file.path,
|
|
1254
|
+
line: lineAt(code, hidden.index),
|
|
1255
|
+
subject: own.name,
|
|
1256
|
+
message: `hides the navigator header and draws its own (${own.name}); use ${headerWay} so the title, back button and large-title behavior stay native`
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
const tabBarProp = /<Tabs\b/.test(code) ? /\btabBar\s*=\s*\{/.exec(code) : null;
|
|
1260
|
+
const tabBar = tabBarProp ? { name: "tabBar prop", index: tabBarProp.index } : customElement(code, /<([A-Z][\w$]*TabBar)\b/g, pkg);
|
|
1261
|
+
if (tabBar) {
|
|
1262
|
+
ctx.report({
|
|
1263
|
+
rule: "native-custom-header",
|
|
1264
|
+
level: "warn",
|
|
1265
|
+
file: file.path,
|
|
1266
|
+
line: lineAt(code, tabBar.index),
|
|
1267
|
+
subject: tabBar.name,
|
|
1268
|
+
message: `builds a tab bar by hand (${tabBar.name}); use the router's native <Tabs> bar, themed through Genesis screenOptions`
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
}
|
|
1272
|
+
for (const file of ctx.files) {
|
|
1273
|
+
if (!JSX_EXTS2.has(file.ext) || reported.has(file.path) || !file.path.startsWith(`${rootDir}/`) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1274
|
+
const layout = hidingLayouts.get(path3.posix.dirname(file.path));
|
|
1275
|
+
const own = layout ? ownHeader(file.code, pkg) : null;
|
|
1276
|
+
if (!layout || !own) continue;
|
|
1277
|
+
ctx.report({
|
|
1278
|
+
rule: "native-custom-header",
|
|
1279
|
+
level: "warn",
|
|
1280
|
+
file: file.path,
|
|
1281
|
+
line: lineAt(file.code, own.index),
|
|
1282
|
+
subject: own.name,
|
|
1283
|
+
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`
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
function routerRoot(ctx) {
|
|
1288
|
+
if (ctx.config.native?.routerRoot) return ctx.config.native.routerRoot.replace(/\/+$/, "");
|
|
1289
|
+
return existsSync(path3.join(ctx.root, "src", "app")) ? "src/app" : "app";
|
|
1290
|
+
}
|
|
1291
|
+
function checkScreenLayouts(ctx, pkg) {
|
|
1292
|
+
const layouts = nativeLayouts(pkg);
|
|
1293
|
+
if (layouts.length === 0) return;
|
|
1294
|
+
const rootDir = routerRoot(ctx);
|
|
1295
|
+
if (!existsSync(path3.join(ctx.root, rootDir))) {
|
|
1296
|
+
ctx.report({ rule: "native-screen-layout", level: "warn", file: rootDir, message: `no Expo Router root at ${rootDir}; set doctor.native.routerRoot` });
|
|
1297
|
+
return;
|
|
1298
|
+
}
|
|
1299
|
+
const routes = ctx.files.filter((f) => f.path.startsWith(`${rootDir}/`));
|
|
1300
|
+
if (routes.length === 0) {
|
|
1301
|
+
ctx.report({
|
|
1302
|
+
rule: "native-screen-layout",
|
|
1303
|
+
level: "warn",
|
|
1304
|
+
file: rootDir,
|
|
1305
|
+
message: `no scanned file is under the router root ${rootDir}, so no screen was checked; add it to doctor.src`
|
|
1306
|
+
});
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
const renders = new RegExp(`<(?:${layouts.join("|")}|Redirect)\\b`);
|
|
1310
|
+
const byPath = new Map(ctx.files.map((f) => [f.absolutePath, f]));
|
|
1311
|
+
for (const file of routes) {
|
|
1312
|
+
if (!JSX_EXTS2.has(file.ext) || NON_SCREEN_ROUTE.test(file.path)) continue;
|
|
1313
|
+
if (!/\bexport\s+default\b/.test(file.code) || !/<[A-Za-z]/.test(file.code)) continue;
|
|
1314
|
+
if (renders.test(file.code)) continue;
|
|
1315
|
+
const viaImport = localImports(ctx.root, file).some((abs) => {
|
|
1316
|
+
const target = byPath.get(abs) ?? readSource(abs);
|
|
1317
|
+
return target !== null && renders.test(target.code);
|
|
1318
|
+
});
|
|
1319
|
+
if (viaImport) continue;
|
|
1320
|
+
ctx.report({
|
|
1321
|
+
rule: "native-screen-layout",
|
|
1322
|
+
level: "warn",
|
|
1323
|
+
file: file.path,
|
|
1324
|
+
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`
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
function localImports(root, file) {
|
|
1329
|
+
const out = [];
|
|
1330
|
+
for (const m of file.code.matchAll(/\bfrom\s*["']((?:\.{1,2}|[@~])\/[^"']+)["']/g)) {
|
|
1331
|
+
const spec = m[1];
|
|
1332
|
+
const bases = spec.startsWith(".") ? [path3.resolve(path3.dirname(file.absolutePath), spec)] : [path3.join(root, spec.slice(2)), path3.join(root, "src", spec.slice(2))];
|
|
1333
|
+
for (const base of bases) {
|
|
1334
|
+
const hit = [base, ...RESOLVE_EXTS.map((e) => base + e), ...RESOLVE_EXTS.map((e) => path3.join(base, `index${e}`))].find(
|
|
1335
|
+
(p) => SCRIPT_EXTS2.has(path3.extname(p)) && existsSync(p)
|
|
1336
|
+
);
|
|
1337
|
+
if (hit) {
|
|
1338
|
+
out.push(hit);
|
|
1339
|
+
break;
|
|
1340
|
+
}
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
return out;
|
|
1344
|
+
}
|
|
1345
|
+
function readSource(abs) {
|
|
1346
|
+
try {
|
|
1347
|
+
return { code: readFileSync(abs, "utf8") };
|
|
1348
|
+
} catch {
|
|
1349
|
+
return null;
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
var PERMISSIONS = [
|
|
1353
|
+
{ module: "expo-camera", key: "NSCameraUsageDescription", option: "cameraPermission" },
|
|
1354
|
+
{ module: "expo-image-picker", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
1355
|
+
{ module: "expo-image-picker", key: "NSCameraUsageDescription", option: "cameraPermission", maybe: "takes photos with the camera" },
|
|
1356
|
+
{ module: "expo-media-library", key: "NSPhotoLibraryUsageDescription", option: "photosPermission" },
|
|
1357
|
+
{ module: "expo-location", key: "NSLocationWhenInUseUsageDescription", option: "locationWhenInUsePermission" },
|
|
1358
|
+
{ module: "expo-av", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
|
|
1359
|
+
{ module: "expo-audio", key: "NSMicrophoneUsageDescription", option: "microphonePermission", maybe: "records audio" },
|
|
1360
|
+
{ module: "expo-contacts", key: "NSContactsUsageDescription", option: "contactsPermission" },
|
|
1361
|
+
{ module: "expo-local-authentication", key: "NSFaceIDUsageDescription", option: "faceIDPermission" }
|
|
1362
|
+
];
|
|
1363
|
+
var SOCIAL_SIGN_IN = ["@react-native-google-signin/google-signin", "react-native-fbsdk-next"];
|
|
1364
|
+
var WEAK_SOCIAL_SIGN_IN = ["expo-auth-session"];
|
|
1365
|
+
var APPLE_SIGN_IN = ["expo-apple-authentication", "@invertase/react-native-apple-authentication"];
|
|
1366
|
+
var EXPO_CONFIGS = ["app.json", "app.config.json", "app.config.ts", "app.config.js", "app.config.mjs", "app.config.cjs"];
|
|
1367
|
+
var SUPABASE_SIGN_IN = /\bsignInWith(?:OAuth|IdToken)\s*\(\s*\{\s*provider\s*:\s*["']([\w-]+)["']/g;
|
|
1368
|
+
var GENESIS_PLUGIN = "@marktiderman/genesis-cli";
|
|
1369
|
+
var GENESIS_PLUGIN_TEXT = /["']@marktiderman\/genesis-cli(?:\/expo)?["']|\bwithGenesis\s*\(/;
|
|
1370
|
+
var GENESIS_PLUGIN_IMPORT = /\bfrom\s*["']@marktiderman\/genesis-cli[^"']*["']|\b(?:require|import)\s*\(\s*["']@marktiderman\/genesis-cli[^"']*["']\s*\)/g;
|
|
1371
|
+
function readExpoConfigs(root) {
|
|
1372
|
+
const out = [];
|
|
1373
|
+
for (const name of EXPO_CONFIGS) {
|
|
1374
|
+
const abs = path3.join(root, name);
|
|
1375
|
+
if (!existsSync(abs)) continue;
|
|
1376
|
+
const text = readFileSync(abs, "utf8");
|
|
1377
|
+
let json = null;
|
|
1378
|
+
if (name.endsWith(".json")) {
|
|
1379
|
+
try {
|
|
1380
|
+
const raw = JSON.parse(text);
|
|
1381
|
+
json = raw.expo ?? raw;
|
|
1382
|
+
} catch (err) {
|
|
1383
|
+
throw new DoctorConfigError(`${name} is not valid JSON: ${err.message}`);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
out.push({ file: name, json, text });
|
|
1387
|
+
}
|
|
1388
|
+
return out;
|
|
1389
|
+
}
|
|
1390
|
+
function get(obj, keys) {
|
|
1391
|
+
let cur = obj;
|
|
1392
|
+
for (const k of keys) {
|
|
1393
|
+
if (!cur || typeof cur !== "object") return void 0;
|
|
1394
|
+
cur = cur[k];
|
|
1395
|
+
}
|
|
1396
|
+
return cur;
|
|
1397
|
+
}
|
|
1398
|
+
function pluginOptions(json, module) {
|
|
1399
|
+
const plugins = json?.plugins;
|
|
1400
|
+
if (!Array.isArray(plugins)) return null;
|
|
1401
|
+
for (const p of plugins) {
|
|
1402
|
+
if (p === module) return {};
|
|
1403
|
+
if (Array.isArray(p) && p[0] === module) return p[1] && typeof p[1] === "object" ? p[1] : {};
|
|
1404
|
+
}
|
|
1405
|
+
return null;
|
|
1406
|
+
}
|
|
1407
|
+
function dependencies(root) {
|
|
1408
|
+
const file = path3.join(root, "package.json");
|
|
1409
|
+
if (!existsSync(file)) return /* @__PURE__ */ new Set();
|
|
1410
|
+
const pkg = JSON.parse(readFileSync(file, "utf8"));
|
|
1411
|
+
return /* @__PURE__ */ new Set([...Object.keys(pkg.dependencies ?? {}), ...Object.keys(pkg.devDependencies ?? {})]);
|
|
1412
|
+
}
|
|
1413
|
+
function runtimeDependencies(root) {
|
|
1414
|
+
const file = path3.join(root, "package.json");
|
|
1415
|
+
if (!existsSync(file)) return {};
|
|
1416
|
+
return JSON.parse(readFileSync(file, "utf8")).dependencies ?? {};
|
|
1417
|
+
}
|
|
1418
|
+
function checkStoreReadiness(ctx) {
|
|
1419
|
+
const configs = readExpoConfigs(ctx.root);
|
|
1420
|
+
if (configs.length === 0) {
|
|
1421
|
+
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" });
|
|
1422
|
+
return;
|
|
1423
|
+
}
|
|
1424
|
+
const file = configs[0].file;
|
|
1425
|
+
const deps = dependencies(ctx.root);
|
|
1426
|
+
const has = (keys, word) => configs.some((c) => c.json ? get(c.json, keys) !== void 0 : new RegExp(`\\b${word}\\b`).test(c.text));
|
|
1427
|
+
const genesisPluginDoes = (option) => configs.some((c) => {
|
|
1428
|
+
if (c.json) {
|
|
1429
|
+
const options = pluginOptions(c.json, GENESIS_PLUGIN) ?? pluginOptions(c.json, `${GENESIS_PLUGIN}/expo`);
|
|
1430
|
+
return options !== null && options[option] !== false;
|
|
1431
|
+
}
|
|
1432
|
+
const listed = c.text.replace(GENESIS_PLUGIN_IMPORT, "");
|
|
1433
|
+
return GENESIS_PLUGIN_TEXT.test(listed) && !new RegExp(`\\b${option}\\s*:\\s*false\\b`).test(c.text);
|
|
1434
|
+
});
|
|
1435
|
+
const exportCompliance = has(["ios", "config", "usesNonExemptEncryption"], "usesNonExemptEncryption") || has(["ios", "infoPlist", "ITSAppUsesNonExemptEncryption"], "ITSAppUsesNonExemptEncryption") || genesisPluginDoes("exportCompliance");
|
|
1436
|
+
if (!exportCompliance) {
|
|
1437
|
+
ctx.report({
|
|
1438
|
+
rule: "store-readiness",
|
|
1439
|
+
level: "warn",
|
|
1440
|
+
file,
|
|
1441
|
+
subject: "usesNonExemptEncryption",
|
|
1442
|
+
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"
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
const social = SOCIAL_SIGN_IN.filter((d) => deps.has(d));
|
|
1446
|
+
let apple = APPLE_SIGN_IN.some((d) => deps.has(d));
|
|
1447
|
+
for (const f of ctx.files) {
|
|
1448
|
+
for (const m of f.code.matchAll(SUPABASE_SIGN_IN)) {
|
|
1449
|
+
if (m[1] === "apple") apple = true;
|
|
1450
|
+
else if (!social.includes(`Supabase ${m[1]} sign-in`)) social.push(`Supabase ${m[1]} sign-in`);
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
if (social.length > 0 && !apple) {
|
|
1454
|
+
const weak = WEAK_SOCIAL_SIGN_IN.filter((d) => deps.has(d));
|
|
1455
|
+
ctx.report({
|
|
1456
|
+
rule: "store-readiness",
|
|
1457
|
+
level: "warn",
|
|
1458
|
+
file: "package.json",
|
|
1459
|
+
subject: "sign-in-with-apple",
|
|
1460
|
+
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.`
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
const generic = /* @__PURE__ */ new Map();
|
|
1464
|
+
for (const p of PERMISSIONS) {
|
|
1465
|
+
if (!deps.has(p.module)) continue;
|
|
1466
|
+
const set = configs.some((c) => {
|
|
1467
|
+
if (!c.json) return new RegExp(`\\b(?:${p.key}|${p.option})\\b`).test(c.text);
|
|
1468
|
+
const plist = get(c.json, ["ios", "infoPlist", p.key]);
|
|
1469
|
+
const option = pluginOptions(c.json, p.module)?.[p.option];
|
|
1470
|
+
return typeof plist === "string" && plist.trim() !== "" || typeof option === "string" && option.trim() !== "" || option === false;
|
|
1471
|
+
});
|
|
1472
|
+
if (!set) generic.set(p.key, [...generic.get(p.key) ?? [], `${p.module}${p.maybe ? `, if the app ${p.maybe}` : ""}`]);
|
|
1473
|
+
}
|
|
1474
|
+
for (const [key, modules] of generic) {
|
|
1475
|
+
const opt = PERMISSIONS.find((p) => p.key === key).option;
|
|
1476
|
+
ctx.report({
|
|
1477
|
+
rule: "store-readiness",
|
|
1478
|
+
level: "warn",
|
|
1479
|
+
file,
|
|
1480
|
+
subject: key,
|
|
1481
|
+
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`
|
|
1482
|
+
});
|
|
1483
|
+
}
|
|
1484
|
+
const pluginManifest = genesisPluginDoes("privacyManifest") && privacyApisFor(runtimeDependencies(ctx.root)).length > 0;
|
|
1485
|
+
if (!has(["ios", "privacyManifests"], "privacyManifests") && !pluginManifest) {
|
|
1486
|
+
ctx.report({
|
|
1487
|
+
rule: "store-readiness",
|
|
1488
|
+
level: "warn",
|
|
1489
|
+
file,
|
|
1490
|
+
subject: "privacyManifests",
|
|
1491
|
+
message: "has no ios.privacyManifests; declare the required-reason APIs the app uses (NSPrivacyAccessedAPITypes) so uploads aren't rejected for a missing privacy manifest"
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
var DEFAULT_MIGRATIONS = "supabase/migrations";
|
|
1496
|
+
var DEFAULT_BASE = "origin/main";
|
|
1497
|
+
var DEFAULT_EXPOSED = ["public"];
|
|
1498
|
+
function sqlStatements(text) {
|
|
1499
|
+
const out = [];
|
|
1500
|
+
let buf = "";
|
|
1501
|
+
let bodies = [];
|
|
1502
|
+
let line = 1;
|
|
1503
|
+
let start = 0;
|
|
1504
|
+
const flush = () => {
|
|
1505
|
+
const sql = buf.replace(/\s+/g, " ").trim().toLowerCase();
|
|
1506
|
+
if (sql) out.push({ sql, line: start, bodies });
|
|
1507
|
+
buf = "";
|
|
1508
|
+
bodies = [];
|
|
1509
|
+
start = 0;
|
|
1510
|
+
};
|
|
1511
|
+
const put = (s) => {
|
|
1512
|
+
if (!start && /\S/.test(s)) start = line;
|
|
1513
|
+
buf += s;
|
|
1514
|
+
};
|
|
1515
|
+
let i = 0;
|
|
1516
|
+
while (i < text.length) {
|
|
1517
|
+
const ch = text[i];
|
|
1518
|
+
const two = text.slice(i, i + 2);
|
|
1519
|
+
if (ch === "\n") {
|
|
1520
|
+
buf += " ";
|
|
1521
|
+
line++;
|
|
1522
|
+
i++;
|
|
1523
|
+
} else if (two === "--") {
|
|
1524
|
+
while (i < text.length && text[i] !== "\n") i++;
|
|
1525
|
+
} else if (two === "/*") {
|
|
1526
|
+
let depth = 0;
|
|
1527
|
+
while (i < text.length) {
|
|
1528
|
+
if (text.startsWith("/*", i)) {
|
|
1529
|
+
depth++;
|
|
1530
|
+
i += 2;
|
|
1531
|
+
} else if (text.startsWith("*/", i)) {
|
|
1532
|
+
depth--;
|
|
1533
|
+
i += 2;
|
|
1534
|
+
if (depth === 0) break;
|
|
1535
|
+
} else {
|
|
1536
|
+
if (text[i] === "\n") line++;
|
|
1537
|
+
i++;
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
buf += " ";
|
|
1541
|
+
} else if (ch === "'") {
|
|
1542
|
+
const escapes = /[eE]/.test(text[i - 1] ?? "") && !/[\w$]/.test(text[i - 2] ?? "");
|
|
1543
|
+
put("'");
|
|
1544
|
+
i++;
|
|
1545
|
+
while (i < text.length) {
|
|
1546
|
+
if (escapes && text[i] === "\\") i += 2;
|
|
1547
|
+
else if (text[i] === "'" && text[i + 1] === "'") i += 2;
|
|
1548
|
+
else if (text[i] === "'") break;
|
|
1549
|
+
else {
|
|
1550
|
+
if (text[i] === "\n") line++;
|
|
1551
|
+
i++;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
put("'");
|
|
1555
|
+
i++;
|
|
1556
|
+
} else if (ch === '"') {
|
|
1557
|
+
i++;
|
|
1558
|
+
while (i < text.length && text[i] !== '"') put(text[i++]);
|
|
1559
|
+
i++;
|
|
1560
|
+
} else if (ch === "$" && !/[\w$]/.test(text[i - 1] ?? "") && /^\$(?:[A-Za-z_]\w*)?\$/.test(text.slice(i))) {
|
|
1561
|
+
const tag = /^\$(?:[A-Za-z_]\w*)?\$/.exec(text.slice(i))[0];
|
|
1562
|
+
const end = text.indexOf(tag, i + tag.length);
|
|
1563
|
+
const stop = end === -1 ? text.length : end + tag.length;
|
|
1564
|
+
bodies.push(text.slice(i + tag.length, end === -1 ? text.length : end).toLowerCase());
|
|
1565
|
+
for (let k = i; k < stop; k++) if (text[k] === "\n") line++;
|
|
1566
|
+
put(`${tag} ${tag}`);
|
|
1567
|
+
i = stop;
|
|
1568
|
+
} else if (ch === ";") {
|
|
1569
|
+
flush();
|
|
1570
|
+
i++;
|
|
1571
|
+
} else {
|
|
1572
|
+
put(ch);
|
|
1573
|
+
i++;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
flush();
|
|
1577
|
+
return out;
|
|
1578
|
+
}
|
|
1579
|
+
function qualify(name) {
|
|
1580
|
+
const n = name.trim().toLowerCase();
|
|
1581
|
+
return n.includes(".") ? n : `public.${n}`;
|
|
1582
|
+
}
|
|
1583
|
+
var schemaOf = (name) => name.split(".")[0];
|
|
1584
|
+
function parenthesized(sql, open) {
|
|
1585
|
+
let depth = 0;
|
|
1586
|
+
for (let k = open; k < sql.length; k++) {
|
|
1587
|
+
if (sql[k] === "(") depth++;
|
|
1588
|
+
else if (sql[k] === ")" && --depth === 0) return { inner: sql.slice(open + 1, k), end: k + 1 };
|
|
1589
|
+
}
|
|
1590
|
+
return { inner: sql.slice(open + 1), end: sql.length };
|
|
1591
|
+
}
|
|
1592
|
+
function stripParens(s) {
|
|
1593
|
+
let out = "";
|
|
1594
|
+
let depth = 0;
|
|
1595
|
+
for (const c of s) {
|
|
1596
|
+
if (c === "(") depth++;
|
|
1597
|
+
else if (c === ")") depth = Math.max(0, depth - 1);
|
|
1598
|
+
else if (depth === 0) out += c;
|
|
1599
|
+
}
|
|
1600
|
+
return out;
|
|
1601
|
+
}
|
|
1602
|
+
function splitTop(s) {
|
|
1603
|
+
const parts = [];
|
|
1604
|
+
let depth = 0;
|
|
1605
|
+
let cur = "";
|
|
1606
|
+
for (const c of s) {
|
|
1607
|
+
if (c === "(") depth++;
|
|
1608
|
+
if (c === ")") depth--;
|
|
1609
|
+
if (c === "," && depth === 0) {
|
|
1610
|
+
parts.push(cur);
|
|
1611
|
+
cur = "";
|
|
1612
|
+
} else cur += c;
|
|
1613
|
+
}
|
|
1614
|
+
if (cur.trim()) parts.push(cur);
|
|
1615
|
+
return parts.map((p) => p.trim()).filter(Boolean);
|
|
1616
|
+
}
|
|
1617
|
+
var TYPE_ALIASES = {
|
|
1618
|
+
int: "integer",
|
|
1619
|
+
int4: "integer",
|
|
1620
|
+
int8: "bigint",
|
|
1621
|
+
int2: "smallint",
|
|
1622
|
+
bool: "boolean",
|
|
1623
|
+
varchar: "character varying",
|
|
1624
|
+
timestamptz: "timestamp with time zone",
|
|
1625
|
+
float8: "double precision"
|
|
1626
|
+
};
|
|
1627
|
+
var MULTIWORD_TYPE = /^(?:double precision|character varying|character|bit varying|timestamp|time|interval)\b/;
|
|
1628
|
+
function argTypes(args) {
|
|
1629
|
+
const types = [];
|
|
1630
|
+
for (const raw of splitTop(args)) {
|
|
1631
|
+
let tokens = stripParens(raw.replace(/\s+(?:default\b|=).*$/, "")).trim().split(/\s+/).filter(Boolean);
|
|
1632
|
+
const mode = tokens[0];
|
|
1633
|
+
if (mode === "out") continue;
|
|
1634
|
+
if (mode === "in" || mode === "inout" || mode === "variadic") tokens = tokens.slice(1);
|
|
1635
|
+
const joined = tokens.join(" ");
|
|
1636
|
+
const type = tokens.length > 1 && !MULTIWORD_TYPE.test(joined) ? tokens.slice(1).join(" ") : joined;
|
|
1637
|
+
types.push(TYPE_ALIASES[type] ?? type);
|
|
1638
|
+
}
|
|
1639
|
+
return types;
|
|
1640
|
+
}
|
|
1641
|
+
function git(root, args) {
|
|
1642
|
+
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
1643
|
+
return r.status === 0 ? r.stdout : null;
|
|
1644
|
+
}
|
|
1645
|
+
function gitView(root, dir, base) {
|
|
1646
|
+
if (git(root, ["rev-parse", "--is-inside-work-tree"])?.trim() !== "true") return { reason: "not a git repository", repo: false };
|
|
1647
|
+
if (git(root, ["rev-parse", "--verify", "--quiet", `${base}^{commit}`]) === null) {
|
|
1648
|
+
return { reason: `the git ref ${base} isn't available (fetch it, or set doctor.supabase.base)`, repo: true };
|
|
1649
|
+
}
|
|
1650
|
+
const mergeBase = git(root, ["merge-base", "HEAD", base])?.trim();
|
|
1651
|
+
if (!mergeBase) return { reason: `HEAD has no merge base with ${base} (a shallow clone? fetch with depth 0)`, repo: true };
|
|
1652
|
+
const diff = git(root, ["diff", "--relative", "--name-status", "-M", mergeBase, "--", dir]);
|
|
1653
|
+
const untracked = git(root, ["ls-files", "--others", "--exclude-standard", "--", dir]);
|
|
1654
|
+
if (diff === null || untracked === null) return { reason: `git diff against ${base} failed`, repo: true };
|
|
1655
|
+
const sql = (p) => p !== void 0 && p.endsWith(".sql");
|
|
1656
|
+
const touched = new Set(untracked.split("\n").filter(sql));
|
|
1657
|
+
const edited = [];
|
|
1658
|
+
for (const row of diff.split("\n").filter(Boolean)) {
|
|
1659
|
+
const [status, a, b] = row.split(" ");
|
|
1660
|
+
if (status.startsWith("R")) {
|
|
1661
|
+
if (sql(b)) touched.add(b);
|
|
1662
|
+
if (sql(a)) edited.push({ file: a, status: "renamed" });
|
|
1663
|
+
continue;
|
|
1664
|
+
}
|
|
1665
|
+
if (!sql(a)) continue;
|
|
1666
|
+
if (status.startsWith("A")) touched.add(a);
|
|
1667
|
+
else if (status.startsWith("M") || status.startsWith("T")) {
|
|
1668
|
+
touched.add(a);
|
|
1669
|
+
edited.push({ file: a, status: "modified" });
|
|
1670
|
+
} else if (status.startsWith("D")) edited.push({ file: a, status: "deleted" });
|
|
1671
|
+
}
|
|
1672
|
+
return { touched, edited };
|
|
1673
|
+
}
|
|
1674
|
+
function checkSupabasePack(ctx) {
|
|
1675
|
+
const settings = ctx.config.supabase ?? {};
|
|
1676
|
+
const dir = settings.migrations ?? DEFAULT_MIGRATIONS;
|
|
1677
|
+
const abs = path3.join(ctx.root, dir);
|
|
1678
|
+
if (!existsSync(abs)) throw new DoctorConfigError(`the supabase pack reads ${dir}, which doesn't exist; set doctor.supabase.migrations`);
|
|
1679
|
+
const migrations = readdirSync(abs).filter((n) => n.endsWith(".sql")).sort().map((n) => ({ file: `${dir}/${n}`, statements: sqlStatements(readFileSync(path3.join(abs, n), "utf8")) }));
|
|
1680
|
+
const exposed = new Set((settings.exposedSchemas ?? DEFAULT_EXPOSED).map((s) => s.toLowerCase()));
|
|
1681
|
+
const base = settings.base ?? DEFAULT_BASE;
|
|
1682
|
+
const view = gitView(ctx.root, dir, base);
|
|
1683
|
+
if ("reason" in view) {
|
|
1684
|
+
if (view.repo) ctx.report({ rule: "migration-edited", level: "warn", file: dir, message: `can't check for edited migrations: ${view.reason}` });
|
|
1685
|
+
} else {
|
|
1686
|
+
for (const e of view.edited) {
|
|
1687
|
+
ctx.report({
|
|
1688
|
+
rule: "migration-edited",
|
|
1689
|
+
file: e.file,
|
|
1690
|
+
subject: e.file,
|
|
1691
|
+
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`
|
|
1692
|
+
});
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
const since = settings.since;
|
|
1696
|
+
const afterSince = (file) => since === void 0 || path3.posix.basename(file) >= since;
|
|
1697
|
+
if ("reason" in view && since === void 0) {
|
|
1698
|
+
ctx.report({
|
|
1699
|
+
rule: "migration-grants",
|
|
1700
|
+
level: "warn",
|
|
1701
|
+
file: dir,
|
|
1702
|
+
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`
|
|
1703
|
+
});
|
|
1704
|
+
} else {
|
|
1705
|
+
const isNew = (file) => afterSince(file) && ("reason" in view || view.touched.has(file));
|
|
1706
|
+
checkGrants(ctx, migrations.filter((m) => isNew(m.file)), exposed);
|
|
1707
|
+
}
|
|
1708
|
+
checkRls(ctx, migrations, exposed);
|
|
1709
|
+
checkDefinerSearchPath(ctx, migrations);
|
|
1710
|
+
}
|
|
1711
|
+
function granteesOf(s) {
|
|
1712
|
+
return s.replace(/\s+granted by .*$/, "").replace(/\s+with grant option$/, "").split(/\s*,\s*/).map((r) => r.replace(/^group\s+/, "").trim()).filter(Boolean);
|
|
1713
|
+
}
|
|
1714
|
+
function checkGrants(ctx, migrations, exposed) {
|
|
1715
|
+
const fix = "grant by name (grant execute on function schema.fn(args) to role) so an earlier revoke survives";
|
|
1716
|
+
const open = (roles) => roles.filter((r) => r === "anon" || r === "public");
|
|
1717
|
+
const blanket = (roles) => {
|
|
1718
|
+
const o = open(roles);
|
|
1719
|
+
if (o.length) return { level: "error", who: o.join(" and ") };
|
|
1720
|
+
if (roles.includes("authenticated")) return { level: "warn", who: "authenticated" };
|
|
1721
|
+
return null;
|
|
1722
|
+
};
|
|
1723
|
+
for (const { file, statements } of migrations) {
|
|
1724
|
+
for (const { sql, line } of statements) {
|
|
1725
|
+
const all = /^grant\b.*\bon all (?:functions|routines|procedures) in schema .+? to (.+)$/.exec(sql);
|
|
1726
|
+
if (all) {
|
|
1727
|
+
const hit = blanket(granteesOf(all[1]));
|
|
1728
|
+
if (hit) {
|
|
1729
|
+
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}` });
|
|
1730
|
+
}
|
|
1731
|
+
continue;
|
|
1732
|
+
}
|
|
1733
|
+
const defaults = /^alter default privileges\b.*?\bgrant\b.*\bon (?:functions|routines) to (.+)$/.exec(sql);
|
|
1734
|
+
if (defaults) {
|
|
1735
|
+
const hit = blanket(granteesOf(defaults[1]));
|
|
1736
|
+
if (hit) {
|
|
1737
|
+
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}` });
|
|
1738
|
+
}
|
|
1739
|
+
continue;
|
|
1740
|
+
}
|
|
1741
|
+
const fn = /^grant\b.*?\bon (?:function|procedure|routine)s? (.+?) to (.+)$/.exec(sql);
|
|
1742
|
+
if (fn) {
|
|
1743
|
+
const roles = open(granteesOf(fn[2]));
|
|
1744
|
+
if (!roles.length) continue;
|
|
1745
|
+
for (const name of splitTop(fn[1]).map((n) => qualify(stripParens(n)))) {
|
|
1746
|
+
if (exposed.has(schemaOf(name))) continue;
|
|
1747
|
+
ctx.report({
|
|
1748
|
+
rule: "migration-grants",
|
|
1749
|
+
file,
|
|
1750
|
+
line,
|
|
1751
|
+
subject: name,
|
|
1752
|
+
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)`
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
const schema = /^grant\b.*?\bon schema (.+?) to (.+)$/.exec(sql);
|
|
1758
|
+
if (schema) {
|
|
1759
|
+
const roles = open(granteesOf(schema[2]));
|
|
1760
|
+
if (!roles.length) continue;
|
|
1761
|
+
for (const s of schema[1].split(/\s*,\s*/).map((x) => x.trim())) {
|
|
1762
|
+
if (exposed.has(s)) continue;
|
|
1763
|
+
ctx.report({
|
|
1764
|
+
rule: "migration-grants",
|
|
1765
|
+
file,
|
|
1766
|
+
line,
|
|
1767
|
+
subject: `schema ${s}`,
|
|
1768
|
+
message: `grants schema ${s} to ${roles.join(" and ")}; a schema outside the exposed ones stays closed to anon and public`
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
function checkRls(ctx, migrations, exposed) {
|
|
1776
|
+
const tables = /* @__PURE__ */ new Map();
|
|
1777
|
+
const name = String.raw`([\w$.]+)`;
|
|
1778
|
+
const target = String.raw`^alter table (?:if exists )?(?:only )?${name}`;
|
|
1779
|
+
for (const { file, statements } of migrations) {
|
|
1780
|
+
for (const { sql, line, bodies } of statements) {
|
|
1781
|
+
if (bodies.some((b) => /\benable row level security\b/.test(b))) for (const t of tables.values()) t.rls = true;
|
|
1782
|
+
const create = new RegExp(String.raw`^create (?:(?:global |local )?(?:temp|temporary) |unlogged )?table (?:if not exists )?${name}`).exec(sql);
|
|
1783
|
+
if (create) {
|
|
1784
|
+
if (!/^create (?:global |local )?(?:temp|temporary) /.test(sql)) tables.set(qualify(create[1]), { rls: false, file, line, disabled: false });
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
const rename = new RegExp(`${target} rename to ([\\w$]+)$`).exec(sql);
|
|
1788
|
+
const move = new RegExp(`${target} set schema ([\\w$]+)$`).exec(sql);
|
|
1789
|
+
if (rename || move) {
|
|
1790
|
+
const from = qualify((rename ?? move)[1]);
|
|
1791
|
+
const to = rename ? `${schemaOf(from)}.${rename[2]}` : `${move[2]}.${from.split(".")[1]}`;
|
|
1792
|
+
const state = tables.get(from);
|
|
1793
|
+
if (state) {
|
|
1794
|
+
tables.delete(from);
|
|
1795
|
+
tables.set(to, state);
|
|
1796
|
+
}
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
const alter = new RegExp(target).exec(sql);
|
|
1800
|
+
if (alter && /\b(?:enable|disable) row level security\b/.test(sql)) {
|
|
1801
|
+
const t = qualify(alter[1]);
|
|
1802
|
+
if (/\bdisable row level security\b/.test(sql)) tables.set(t, { rls: false, file, line, disabled: true });
|
|
1803
|
+
else {
|
|
1804
|
+
const state = tables.get(t);
|
|
1805
|
+
if (state) state.rls = true;
|
|
1806
|
+
}
|
|
1807
|
+
continue;
|
|
1808
|
+
}
|
|
1809
|
+
const drop = /^drop table (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1810
|
+
if (drop) for (const n of drop[1].split(",")) tables.delete(qualify(n));
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
for (const [t, at] of tables) {
|
|
1814
|
+
if (at.rls || !exposed.has(schemaOf(t))) continue;
|
|
1815
|
+
ctx.report({
|
|
1816
|
+
rule: "migration-rls",
|
|
1817
|
+
file: at.file,
|
|
1818
|
+
line: at.line,
|
|
1819
|
+
subject: t,
|
|
1820
|
+
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`
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
function checkDefinerSearchPath(ctx, migrations) {
|
|
1825
|
+
const fns = /* @__PURE__ */ new Map();
|
|
1826
|
+
const keysFor = (sql, nameEnd, fnName) => {
|
|
1827
|
+
const rest = sql.slice(nameEnd).trimStart();
|
|
1828
|
+
if (rest.startsWith("(")) {
|
|
1829
|
+
const { inner } = parenthesized(rest, 0);
|
|
1830
|
+
return [`${fnName}(${argTypes(inner).join(",")})`];
|
|
1831
|
+
}
|
|
1832
|
+
return [...fns.keys()].filter((k) => k.startsWith(`${fnName}(`));
|
|
1833
|
+
};
|
|
1834
|
+
for (const { file, statements } of migrations) {
|
|
1835
|
+
for (const { sql, line } of statements) {
|
|
1836
|
+
const create = /^create (?:or replace )?(?:function|procedure) ([\w$.]+)\s*/.exec(sql);
|
|
1837
|
+
if (create) {
|
|
1838
|
+
const [key] = keysFor(sql, create[0].length, qualify(create[1]));
|
|
1839
|
+
fns.set(key, { definer: /\bsecurity definer\b/.test(sql), searchPath: /\bset search_path\b/.test(sql), file, line });
|
|
1840
|
+
continue;
|
|
1841
|
+
}
|
|
1842
|
+
const alter = /^alter (?:function|procedure|routine) ([\w$.]+)\s*/.exec(sql);
|
|
1843
|
+
if (alter) {
|
|
1844
|
+
const fnName = qualify(alter[1]);
|
|
1845
|
+
const keys = keysFor(sql, alter[0].length, fnName);
|
|
1846
|
+
const rename = / rename to ([\w$]+)$/.exec(sql);
|
|
1847
|
+
const move = / set schema ([\w$]+)$/.exec(sql);
|
|
1848
|
+
for (const key of keys) {
|
|
1849
|
+
const state = fns.get(key);
|
|
1850
|
+
if (rename || move) {
|
|
1851
|
+
if (!state) continue;
|
|
1852
|
+
fns.delete(key);
|
|
1853
|
+
const newName = rename ? `${schemaOf(fnName)}.${rename[1]}` : `${move[1]}.${fnName.split(".")[1]}`;
|
|
1854
|
+
fns.set(newName + key.slice(fnName.length), state);
|
|
1855
|
+
continue;
|
|
1856
|
+
}
|
|
1857
|
+
const next = state ?? { definer: false, searchPath: false, file, line };
|
|
1858
|
+
if (/\bsecurity definer\b/.test(sql)) Object.assign(next, { definer: true, file, line });
|
|
1859
|
+
if (/\bsecurity invoker\b/.test(sql)) next.definer = false;
|
|
1860
|
+
if (/\bset search_path\b/.test(sql)) next.searchPath = true;
|
|
1861
|
+
if (/\breset (?:search_path|all)\b/.test(sql)) Object.assign(next, { searchPath: false, file, line });
|
|
1862
|
+
fns.set(key, next);
|
|
1863
|
+
}
|
|
1864
|
+
continue;
|
|
1865
|
+
}
|
|
1866
|
+
const drop = /^drop (?:function|procedure|routine) (?:if exists )?(.+?)(?: cascade| restrict)?$/.exec(sql);
|
|
1867
|
+
if (drop) {
|
|
1868
|
+
for (const part of splitTop(drop[1])) {
|
|
1869
|
+
const m = /^([\w$.]+)\s*/.exec(part);
|
|
1870
|
+
if (m) for (const key of keysFor(part, m[0].length, qualify(m[1]))) fns.delete(key);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
for (const [key, at] of fns) {
|
|
1876
|
+
if (!at.definer || at.searchPath) continue;
|
|
1877
|
+
ctx.report({
|
|
1878
|
+
rule: "migration-definer-search-path",
|
|
1879
|
+
file: at.file,
|
|
1880
|
+
line: at.line,
|
|
1881
|
+
subject: key,
|
|
1882
|
+
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`
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
942
1886
|
var UMBRELLA_PACKAGE = "@marktiderman/genesis";
|
|
943
1887
|
function readReleaseManifest(root) {
|
|
944
1888
|
const dir = findPackageDir(root, UMBRELLA_PACKAGE);
|
|
@@ -986,7 +1930,9 @@ async function runDoctor(options = {}) {
|
|
|
986
1930
|
{ name: "colors", check: checkColors },
|
|
987
1931
|
{ name: "tokens", check: checkTokens },
|
|
988
1932
|
{ name: "shadowed-exports", check: checkShadowedExports },
|
|
989
|
-
{ name: "version-skew", check: checkVersionSkew }
|
|
1933
|
+
{ name: "version-skew", check: checkVersionSkew },
|
|
1934
|
+
...config.packs?.includes("native") ? [{ name: "native", check: checkNativePack }] : [],
|
|
1935
|
+
...config.packs?.includes("supabase") ? [{ name: "supabase", check: checkSupabasePack }] : []
|
|
990
1936
|
];
|
|
991
1937
|
for (const plugin of [...builtins, ...patterns ? [patterns.plugin] : [], ...plugins]) {
|
|
992
1938
|
try {
|
|
@@ -1083,6 +2029,6 @@ function genesisSummary(g) {
|
|
|
1083
2029
|
};
|
|
1084
2030
|
}
|
|
1085
2031
|
|
|
1086
|
-
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, parseExportNames, parseRulesMarkdown, readGenesisConfig, readReleaseManifest, runDoctor, toJson, validateConfig, validateLinks };
|
|
2032
|
+
export { BUILTIN_RULES, DoctorConfigError, GenesisConfigError, defineDoctorPlugin, findPackageDir, formatReport, genesisSummary, globToRegExp, loadConfig, loadGenesis, nativeLayouts, parseExportNames, parseRulesMarkdown, readGenesisConfig, readPackageExports, readReleaseManifest, runDoctor, sqlStatements, toJson, validateConfig, validateLinks };
|
|
1087
2033
|
//# sourceMappingURL=doctor.js.map
|
|
1088
2034
|
//# sourceMappingURL=doctor.js.map
|