@specdest/devkit 0.4.19 → 0.4.20
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 +105 -28
- package/dist/npm/cli.js +16 -26
- package/dist/npm/index.js +4 -1
- package/dist/npm/native/specdest-darwin-arm64 +0 -0
- package/dist/npm/native/specdest-darwin-x64 +0 -0
- package/dist/npm/native/specdest-linux-arm64 +0 -0
- package/dist/npm/native/specdest-linux-x64 +0 -0
- package/package.json +8 -5
- package/dist/npm/automation-policy.d.ts +0 -2
- package/dist/npm/automation-policy.js +0 -30
- package/dist/npm/canonical-project-operations.d.ts +0 -5
- package/dist/npm/canonical-project-operations.js +0 -5
- package/dist/npm/canonical-project.d.ts +0 -21
- package/dist/npm/canonical-project.js +0 -115
- package/dist/npm/catalog-snapshot.d.ts +0 -53
- package/dist/npm/catalog-snapshot.js +0 -35
- package/dist/npm/client-only-boundary.d.ts +0 -1
- package/dist/npm/client-only-boundary.js +0 -29
- package/dist/npm/commands.d.ts +0 -16
- package/dist/npm/commands.js +0 -194
- package/dist/npm/git-catalog.d.ts +0 -40
- package/dist/npm/git-catalog.js +0 -222
- package/dist/npm/github-doppler-secrets.d.ts +0 -8
- package/dist/npm/github-doppler-secrets.js +0 -156
- package/dist/npm/host-automation.d.ts +0 -9
- package/dist/npm/host-automation.js +0 -87
- package/dist/npm/installer-primitives.d.ts +0 -3
- package/dist/npm/installer-primitives.js +0 -50
- package/dist/npm/predefined-packages/abac.d.ts +0 -2
- package/dist/npm/predefined-packages/abac.js +0 -45
- package/dist/npm/predefined-packages/admin-ui-templates/AdminAccessAssignments.tsx.template +0 -67
- package/dist/npm/predefined-packages/admin-ui-templates/AdminConfirmDialog.tsx.template +0 -46
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDataTable.tsx.template +0 -49
- package/dist/npm/predefined-packages/admin-ui-templates/AdminDetailLayout.tsx.template +0 -15
- package/dist/npm/predefined-packages/admin-ui-templates/AdminEmptyState.tsx.template +0 -17
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFilterBar.tsx.template +0 -16
- package/dist/npm/predefined-packages/admin-ui-templates/AdminFormLayout.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminMembershipManager.tsx.template +0 -56
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPage.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPageHeader.tsx.template +0 -19
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPagination.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminPermissionMatrix.tsx.template +0 -54
- package/dist/npm/predefined-packages/admin-ui-templates/AdminRoleManager.tsx.template +0 -81
- package/dist/npm/predefined-packages/admin-ui-templates/AdminShell.tsx.template +0 -20
- package/dist/npm/predefined-packages/admin-ui-templates/AdminSidebar.tsx.template +0 -18
- package/dist/npm/predefined-packages/admin-ui-templates/AdminStatCard.tsx.template +0 -22
- package/dist/npm/predefined-packages/admin-ui.d.ts +0 -2
- package/dist/npm/predefined-packages/admin-ui.js +0 -83
- package/dist/npm/predefined-packages/auth-templates/README.md.template +0 -9
- package/dist/npm/predefined-packages/auth-templates/convex.ts.template +0 -18
- package/dist/npm/predefined-packages/auth-templates/identity.ts.template +0 -2
- package/dist/npm/predefined-packages/auth-templates/supabase.ts.template +0 -36
- package/dist/npm/predefined-packages/auth.d.ts +0 -2
- package/dist/npm/predefined-packages/auth.js +0 -36
- package/dist/npm/predefined-packages/convex.d.ts +0 -2
- package/dist/npm/predefined-packages/convex.js +0 -53
- package/dist/npm/predefined-packages/expo.d.ts +0 -2
- package/dist/npm/predefined-packages/expo.js +0 -88
- package/dist/npm/predefined-packages/firebase-hosting.d.ts +0 -2
- package/dist/npm/predefined-packages/firebase-hosting.js +0 -24
- package/dist/npm/predefined-packages/health.d.ts +0 -10
- package/dist/npm/predefined-packages/health.js +0 -52
- package/dist/npm/predefined-packages/husky.d.ts +0 -2
- package/dist/npm/predefined-packages/husky.js +0 -57
- package/dist/npm/predefined-packages/index.d.ts +0 -12
- package/dist/npm/predefined-packages/index.js +0 -97
- package/dist/npm/predefined-packages/install.d.ts +0 -19
- package/dist/npm/predefined-packages/install.js +0 -86
- package/dist/npm/predefined-packages/local-logging.d.ts +0 -2
- package/dist/npm/predefined-packages/local-logging.js +0 -17
- package/dist/npm/predefined-packages/logging.d.ts +0 -2
- package/dist/npm/predefined-packages/logging.js +0 -21
- package/dist/npm/predefined-packages/multi-tenancy.d.ts +0 -2
- package/dist/npm/predefined-packages/multi-tenancy.js +0 -37
- package/dist/npm/predefined-packages/nps.d.ts +0 -2
- package/dist/npm/predefined-packages/nps.js +0 -32
- package/dist/npm/predefined-packages/oxfmt.d.ts +0 -2
- package/dist/npm/predefined-packages/oxfmt.js +0 -22
- package/dist/npm/predefined-packages/oxlint.d.ts +0 -2
- package/dist/npm/predefined-packages/oxlint.js +0 -35
- package/dist/npm/predefined-packages/package-json.d.ts +0 -3
- package/dist/npm/predefined-packages/package-json.js +0 -61
- package/dist/npm/predefined-packages/payments.d.ts +0 -2
- package/dist/npm/predefined-packages/payments.js +0 -31
- package/dist/npm/predefined-packages/playwright.d.ts +0 -2
- package/dist/npm/predefined-packages/playwright.js +0 -35
- package/dist/npm/predefined-packages/project-signals.d.ts +0 -4
- package/dist/npm/predefined-packages/project-signals.js +0 -39
- package/dist/npm/predefined-packages/registry.d.ts +0 -3
- package/dist/npm/predefined-packages/registry.js +0 -65
- package/dist/npm/predefined-packages/resolver.d.ts +0 -8
- package/dist/npm/predefined-packages/resolver.js +0 -35
- package/dist/npm/predefined-packages/security-templates/README.md.template +0 -15
- package/dist/npm/predefined-packages/security-templates/convex-authorization.ts.template +0 -109
- package/dist/npm/predefined-packages/security-templates/permissions.ts.template +0 -40
- package/dist/npm/predefined-packages/security-templates/supabase-admin-rpc.sql.template +0 -54
- package/dist/npm/predefined-packages/security-templates/supabase-authorization.sql.template +0 -138
- package/dist/npm/predefined-packages/security-templates/supabase-posts-example.sql.template +0 -39
- package/dist/npm/predefined-packages/sentry.d.ts +0 -2
- package/dist/npm/predefined-packages/sentry.js +0 -29
- package/dist/npm/predefined-packages/shadcn.d.ts +0 -2
- package/dist/npm/predefined-packages/shadcn.js +0 -23
- package/dist/npm/predefined-packages/storybook.d.ts +0 -2
- package/dist/npm/predefined-packages/storybook.js +0 -25
- package/dist/npm/predefined-packages/stryker.d.ts +0 -2
- package/dist/npm/predefined-packages/stryker.js +0 -48
- package/dist/npm/predefined-packages/supabase.d.ts +0 -2
- package/dist/npm/predefined-packages/supabase.js +0 -355
- package/dist/npm/predefined-packages/tailwind.d.ts +0 -2
- package/dist/npm/predefined-packages/tailwind.js +0 -18
- package/dist/npm/predefined-packages/tanstack-form.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-form.js +0 -19
- package/dist/npm/predefined-packages/tanstack-query.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-query.js +0 -15
- package/dist/npm/predefined-packages/tanstack-router.d.ts +0 -2
- package/dist/npm/predefined-packages/tanstack-router.js +0 -18
- package/dist/npm/predefined-packages/tenant-templates/README.md.template +0 -11
- package/dist/npm/predefined-packages/tenant-templates/tenant-context.ts.template +0 -22
- package/dist/npm/predefined-packages/types.d.ts +0 -38
- package/dist/npm/predefined-packages/types.js +0 -1
- package/dist/npm/predefined-packages/vite.d.ts +0 -2
- package/dist/npm/predefined-packages/vite.js +0 -127
- package/dist/npm/predefined-packages/vitest.d.ts +0 -2
- package/dist/npm/predefined-packages/vitest.js +0 -20
- package/dist/npm/predefined-packages/zod.d.ts +0 -2
- package/dist/npm/predefined-packages/zod.js +0 -18
- package/dist/npm/project-check.d.ts +0 -37
- package/dist/npm/project-check.js +0 -231
- package/dist/npm/project-context.d.ts +0 -52
- package/dist/npm/project-context.js +0 -211
- package/dist/npm/project-install-guard.d.ts +0 -2
- package/dist/npm/project-install-guard.js +0 -51
- package/dist/npm/project-rules.d.ts +0 -25
- package/dist/npm/project-rules.js +0 -106
- package/dist/npm/project-runtime.d.ts +0 -21
- package/dist/npm/project-runtime.js +0 -41
- package/dist/npm/project-status.d.ts +0 -32
- package/dist/npm/project-status.js +0 -70
- package/dist/npm/project-sync.d.ts +0 -7
- package/dist/npm/project-sync.js +0 -143
- package/dist/npm/remote-installer.d.ts +0 -35
- package/dist/npm/remote-installer.js +0 -351
- package/dist/npm/rule-id-migrations.d.ts +0 -6
- package/dist/npm/rule-id-migrations.js +0 -19
- package/dist/npm/slack.d.ts +0 -16
- package/dist/npm/slack.js +0 -135
- package/dist/npm/snapshot/config.d.ts +0 -10
- package/dist/npm/snapshot/config.js +0 -24
- package/dist/npm/snapshot/policy.d.ts +0 -1
- package/dist/npm/snapshot/policy.js +0 -64
- package/dist/npm/snapshot/restore.d.ts +0 -10
- package/dist/npm/snapshot/restore.js +0 -19
- package/dist/npm/snapshot/sql.d.ts +0 -2
- package/dist/npm/snapshot/sql.js +0 -113
- package/dist/npm/snapshot/storage.d.ts +0 -8
- package/dist/npm/snapshot/storage.js +0 -70
- package/dist/npm/snapshot/verify.d.ts +0 -11
- package/dist/npm/snapshot/verify.js +0 -13
- package/dist/npm/snapshot-cli.d.ts +0 -6
- package/dist/npm/snapshot-cli.js +0 -45
- package/dist/npm/state.d.ts +0 -14
- package/dist/npm/state.js +0 -269
- package/dist/npm/supabase-local.d.ts +0 -2
- package/dist/npm/supabase-local.js +0 -63
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { abacRecipe } from "./abac.js";
|
|
2
|
-
import { adminUiRecipe } from "./admin-ui.js";
|
|
3
|
-
import { authRecipe } from "./auth.js";
|
|
4
|
-
import { convexRecipe } from "./convex.js";
|
|
5
|
-
import { expoRecipe } from "./expo.js";
|
|
6
|
-
import { loggingRecipe } from "./logging.js";
|
|
7
|
-
import { multiTenancyRecipe } from "./multi-tenancy.js";
|
|
8
|
-
import { paymentsRecipe } from "./payments.js";
|
|
9
|
-
import { sentryRecipe } from "./sentry.js";
|
|
10
|
-
import { shadcnRecipe } from "./shadcn.js";
|
|
11
|
-
import { supabaseRecipe } from "./supabase.js";
|
|
12
|
-
import { tanstackRouterRecipe } from "./tanstack-router.js";
|
|
13
|
-
import { viteRecipe } from "./vite.js";
|
|
14
|
-
import { firebaseHostingRecipe } from "./firebase-hosting.js";
|
|
15
|
-
import { localLoggingRecipe } from "./local-logging.js";
|
|
16
|
-
import { playwrightRecipe } from "./playwright.js";
|
|
17
|
-
import { storybookRecipe } from "./storybook.js";
|
|
18
|
-
import { tanstackFormRecipe } from "./tanstack-form.js";
|
|
19
|
-
import { tanstackQueryRecipe } from "./tanstack-query.js";
|
|
20
|
-
import { vitestRecipe } from "./vitest.js";
|
|
21
|
-
import { zodRecipe } from "./zod.js";
|
|
22
|
-
import { huskyRecipe } from "./husky.js";
|
|
23
|
-
import { npsRecipe } from "./nps.js";
|
|
24
|
-
import { oxfmtRecipe } from "./oxfmt.js";
|
|
25
|
-
import { oxlintRecipe } from "./oxlint.js";
|
|
26
|
-
import { strykerRecipe } from "./stryker.js";
|
|
27
|
-
import { tailwindRecipe } from "./tailwind.js";
|
|
28
|
-
const RECIPES = new Map([
|
|
29
|
-
[viteRecipe.id, viteRecipe],
|
|
30
|
-
[expoRecipe.id, expoRecipe],
|
|
31
|
-
[supabaseRecipe.id, supabaseRecipe],
|
|
32
|
-
[convexRecipe.id, convexRecipe],
|
|
33
|
-
[authRecipe.id, authRecipe],
|
|
34
|
-
[multiTenancyRecipe.id, multiTenancyRecipe],
|
|
35
|
-
[abacRecipe.id, abacRecipe],
|
|
36
|
-
[adminUiRecipe.id, adminUiRecipe],
|
|
37
|
-
[sentryRecipe.id, sentryRecipe],
|
|
38
|
-
[loggingRecipe.id, loggingRecipe],
|
|
39
|
-
[paymentsRecipe.id, paymentsRecipe],
|
|
40
|
-
[shadcnRecipe.id, shadcnRecipe],
|
|
41
|
-
[tanstackRouterRecipe.id, tanstackRouterRecipe],
|
|
42
|
-
[tanstackQueryRecipe.id, tanstackQueryRecipe],
|
|
43
|
-
[tanstackFormRecipe.id, tanstackFormRecipe],
|
|
44
|
-
[storybookRecipe.id, storybookRecipe],
|
|
45
|
-
[playwrightRecipe.id, playwrightRecipe],
|
|
46
|
-
[vitestRecipe.id, vitestRecipe],
|
|
47
|
-
[localLoggingRecipe.id, localLoggingRecipe],
|
|
48
|
-
[firebaseHostingRecipe.id, firebaseHostingRecipe],
|
|
49
|
-
[zodRecipe.id, zodRecipe],
|
|
50
|
-
[tailwindRecipe.id, tailwindRecipe],
|
|
51
|
-
[huskyRecipe.id, huskyRecipe],
|
|
52
|
-
[npsRecipe.id, npsRecipe],
|
|
53
|
-
[oxlintRecipe.id, oxlintRecipe],
|
|
54
|
-
[oxfmtRecipe.id, oxfmtRecipe],
|
|
55
|
-
[strykerRecipe.id, strykerRecipe],
|
|
56
|
-
]);
|
|
57
|
-
export function getPackageRecipe(id) {
|
|
58
|
-
const recipe = RECIPES.get(id);
|
|
59
|
-
if (!recipe)
|
|
60
|
-
throw new Error(`Unknown predefined package: ${id}`);
|
|
61
|
-
return recipe;
|
|
62
|
-
}
|
|
63
|
-
export function listPackageRecipes() {
|
|
64
|
-
return [...RECIPES.values()];
|
|
65
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { PackageRecipe, PackageResolution } from './types.ts';
|
|
2
|
-
export type PackageResolutionContext = {
|
|
3
|
-
registeredPackageIds: Iterable<string>;
|
|
4
|
-
presentPackageIds?: Iterable<string>;
|
|
5
|
-
knownRecipes?: Iterable<PackageRecipe>;
|
|
6
|
-
};
|
|
7
|
-
export declare function resolvePackageAddition(recipe: PackageRecipe, context: PackageResolutionContext): PackageResolution;
|
|
8
|
-
export declare function installedPackageIds(state: any): string[];
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export function resolvePackageAddition(recipe, context) {
|
|
2
|
-
const registered = new Set(context.registeredPackageIds);
|
|
3
|
-
const present = new Set(context.presentPackageIds ?? context.registeredPackageIds);
|
|
4
|
-
const knownRecipes = [...(context.knownRecipes ?? [])];
|
|
5
|
-
const missing = (recipe.requires ?? []).filter((id) => !registered.has(id));
|
|
6
|
-
if (missing.length) {
|
|
7
|
-
throw new Error(recipe.id + ' requires package' + (missing.length === 1 ? '' : 's') + ': ' + missing.join(', '));
|
|
8
|
-
}
|
|
9
|
-
const available = new Set([...registered, ...present]);
|
|
10
|
-
const directConflicts = (recipe.conflicts ?? []).filter((id) => available.has(id));
|
|
11
|
-
const reverseConflicts = knownRecipes
|
|
12
|
-
.filter((candidate) => available.has(candidate.id) && (candidate.conflicts ?? []).includes(recipe.id))
|
|
13
|
-
.map((candidate) => candidate.id);
|
|
14
|
-
const conflicts = [...new Set([...directConflicts, ...reverseConflicts])].sort();
|
|
15
|
-
if (conflicts.length) {
|
|
16
|
-
throw new Error(recipe.id + ' conflicts with present package' + (conflicts.length === 1 ? '' : 's') + ': ' + conflicts.join(', '));
|
|
17
|
-
}
|
|
18
|
-
const variantEnvironment = new Set([...available, recipe.id]);
|
|
19
|
-
const variants = recipe.variants ?? [];
|
|
20
|
-
if (!variants.length)
|
|
21
|
-
return { variant: null };
|
|
22
|
-
const matches = variants.filter((variant) => variant.when.every((id) => variantEnvironment.has(id)));
|
|
23
|
-
if (matches.length === 0)
|
|
24
|
-
throw new Error(recipe.id + ' has no compatible variant for the present packages');
|
|
25
|
-
if (matches.length > 1) {
|
|
26
|
-
throw new Error(recipe.id + ' has multiple compatible variants: ' + matches.map((item) => item.id).join(', '));
|
|
27
|
-
}
|
|
28
|
-
return { variant: matches[0].id };
|
|
29
|
-
}
|
|
30
|
-
export function installedPackageIds(state) {
|
|
31
|
-
return Object.entries(state?.installed ?? {})
|
|
32
|
-
.filter(([, value]) => value?.kind === 'package')
|
|
33
|
-
.map(([id]) => id)
|
|
34
|
-
.sort();
|
|
35
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
# Authorization integration checklist
|
|
2
|
-
|
|
3
|
-
These are project-owned **reference templates, NOT an activated security implementation**.
|
|
4
|
-
Do not deploy application features until enforcement is mapped and tested.
|
|
5
|
-
|
|
6
|
-
1. Authenticate via the existing Supabase Auth or configured Convex-compatible provider. Verify the identity server-side. Do not trust client-supplied role/tenant/owner fields.
|
|
7
|
-
2. Persist roles, group memberships, tenant memberships and assignments in trusted backend storage. Restrict all writes to privileged server operations; administrative mutations must authorize the acting administrator.
|
|
8
|
-
3. Supabase: inspect `supabase-posts-example.sql` for complete SELECT/INSERT/UPDATE/DELETE and trigger wiring; adapt `supabase-authorization.sql` to existing declarative schema and real table identifiers. Enforce SELECT/INSERT/UPDATE/DELETE and attach the included tenant/owner immutability trigger to each real resource table. Validate external provider subject-to-UUID mapping. Apply and test RLS; do not use frontend checks in place of RLS.
|
|
9
|
-
4. For limited Supabase user-role assignment, review `supabase-admin-rpc.sql`. It checks the real caller and rejects role grants outside their permissions; it is not a general-purpose admin API.
|
|
10
|
-
5. Convex: adapt `convex/authorization.ts` to the actual schema and load actor/roles/assignments/resource from server-owned tables. Call `authorizedMutation` for writes, `authorizedRows` for list queries, and `authorizedRoleAssignment` for tenant user-to-role changes (using trusted role/member loaders); `authorize` protects individual reads. Never invoke loaders with client-supplied owner IDs, roles or grants. Individual resource reads/writes deny missing resources. Only create checks accept `requireResource: false`; `authorizedMutation` additionally requires `newResource` with the authenticated owner and requested tenant. Persist precisely these server-validated scope fields; never trust client-provided ownership. Lists must filter server-loaded rows *before pagination*.
|
|
11
|
-
6. Test anonymous, missing grants, any/own grants, ownership transfers, cross-tenant access, revoked roles and unauthorized administrative edits.
|
|
12
|
-
|
|
13
|
-
Permission semantics: `feature:action` with `any` or `own` scope. `own` requires a resource loaded from the backend and an exact trusted owner match. Global grants do not authorize tenant resources. Missing identity or membership denies.
|
|
14
|
-
|
|
15
|
-
Security note: Convex mutation loaders and writes must execute in the same Convex transaction. Do not call an external service or an action to perform the write after authorization. Role creation, permission editing, user invitations, and group membership changes require independently authorized server mutations.
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/** Server-side authorization for Convex queries and mutations.
|
|
2
|
-
* Call these helpers only from server functions. Loaders must read trusted DB records.
|
|
3
|
-
*/
|
|
4
|
-
import { canAccess, type Actor, type Assignment, type Resource, type Role } from '../src/lib/permissions.ts';
|
|
5
|
-
|
|
6
|
-
type Context = { auth: { getUserIdentity(): Promise<{ subject: string } | null> } };
|
|
7
|
-
type PolicyLoaders = {
|
|
8
|
-
ctx: Context;
|
|
9
|
-
loadActor: (subject: string) => Promise<Actor | null>;
|
|
10
|
-
loadRoles: () => Promise<readonly Role[]>;
|
|
11
|
-
loadAssignments: () => Promise<readonly Assignment[]>;
|
|
12
|
-
};
|
|
13
|
-
type Operation = { feature: string; action: string; tenantId: string | null };
|
|
14
|
-
type VerifiedPolicy = { actor: Actor; roles: readonly Role[]; assignments: readonly Assignment[] };
|
|
15
|
-
|
|
16
|
-
async function verifiedPolicy(input: PolicyLoaders): Promise<VerifiedPolicy> {
|
|
17
|
-
const identity = await input.ctx.auth.getUserIdentity();
|
|
18
|
-
if (!identity?.subject) throw new Error('Unauthorized');
|
|
19
|
-
const actor = await input.loadActor(identity.subject);
|
|
20
|
-
if (!actor || actor.id !== identity.subject) throw new Error('Forbidden');
|
|
21
|
-
const [roles, assignments] = await Promise.all([input.loadRoles(), input.loadAssignments()]);
|
|
22
|
-
return { actor, roles, assignments };
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** Resource reads and writes fail closed when the stored resource does not exist.
|
|
26
|
-
* `requireResource: false` is only valid for a create or collection-level check.
|
|
27
|
-
*/
|
|
28
|
-
export async function authorize(input: PolicyLoaders & Operation & {
|
|
29
|
-
loadResource: () => Promise<Resource | null>;
|
|
30
|
-
requireResource?: boolean;
|
|
31
|
-
}): Promise<void> {
|
|
32
|
-
const { actor, roles, assignments } = await verifiedPolicy(input);
|
|
33
|
-
if (input.requireResource === false && input.action !== 'create') throw new Error('Forbidden');
|
|
34
|
-
const resource = await input.loadResource();
|
|
35
|
-
if (input.requireResource !== false && !resource) throw new Error('Forbidden');
|
|
36
|
-
if (!canAccess({ actor, roles, assignments, resource, feature: input.feature, action: input.action, tenantId: input.tenantId })) {
|
|
37
|
-
throw new Error('Forbidden');
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Use inside a Convex mutation. Authorization and write share its transaction.
|
|
42
|
-
* `loadResource` must look up the real document and return its stored owner/tenant.
|
|
43
|
-
*/
|
|
44
|
-
export async function authorizedMutation<T>(input: Parameters<typeof authorize>[0] & {
|
|
45
|
-
/** For create, supply the server-validated resource scope to be persisted. */
|
|
46
|
-
newResource?: Resource;
|
|
47
|
-
write: () => Promise<T>;
|
|
48
|
-
}): Promise<T> {
|
|
49
|
-
if (input.action === 'read') throw new Error('Forbidden');
|
|
50
|
-
if (input.action === 'create') {
|
|
51
|
-
if (input.requireResource !== false || !input.newResource ||
|
|
52
|
-
input.newResource.tenantId !== input.tenantId) throw new Error('Forbidden');
|
|
53
|
-
const identity = await input.ctx.auth.getUserIdentity();
|
|
54
|
-
if (!identity?.subject || input.newResource.ownerId !== identity.subject) throw new Error('Forbidden');
|
|
55
|
-
} else if (input.requireResource === false) {
|
|
56
|
-
throw new Error('Forbidden');
|
|
57
|
-
}
|
|
58
|
-
await authorize(input);
|
|
59
|
-
return await input.write();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Collection reads: verify the caller once and filter each server-loaded row.
|
|
63
|
-
* Never expose an unfiltered result or accept client-supplied rows/ownership.
|
|
64
|
-
* Fetch an authorized result set before applying any public pagination.
|
|
65
|
-
*/
|
|
66
|
-
export async function authorizedRows<T extends Resource>(input: PolicyLoaders & Operation & {
|
|
67
|
-
loadRows: () => Promise<readonly T[]>;
|
|
68
|
-
}): Promise<T[]> {
|
|
69
|
-
const { actor, roles, assignments } = await verifiedPolicy(input);
|
|
70
|
-
if (input.action !== 'read') throw new Error('Forbidden');
|
|
71
|
-
const rows = await input.loadRows();
|
|
72
|
-
return rows.filter((resource) => canAccess({
|
|
73
|
-
actor, roles, assignments, resource,
|
|
74
|
-
feature: input.feature, action: input.action, tenantId: input.tenantId,
|
|
75
|
-
}));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Assign an existing tenant role from a Convex mutation.
|
|
79
|
-
* The role, target membership and acting administrator are loaded from trusted
|
|
80
|
-
* database records. Requiring `any` for every delegated grant prevents an
|
|
81
|
-
* administrator with only `edit:own` from granting `edit:any` or `edit:own`.
|
|
82
|
-
* Do NOT pass client-authored grant definitions or role objects to loaders.
|
|
83
|
-
*/
|
|
84
|
-
export async function authorizedRoleAssignment<T>(input: PolicyLoaders & {
|
|
85
|
-
tenantId: string;
|
|
86
|
-
roleId: string;
|
|
87
|
-
targetUserId: string;
|
|
88
|
-
loadTargetRole: () => Promise<(Role & { tenantId: string }) | null>;
|
|
89
|
-
hasTargetMembership: () => Promise<boolean>;
|
|
90
|
-
writeAssignment: () => Promise<T>;
|
|
91
|
-
}): Promise<T> {
|
|
92
|
-
const { actor, roles, assignments } = await verifiedPolicy(input);
|
|
93
|
-
const canManage = canAccess({
|
|
94
|
-
actor, roles, assignments, tenantId: input.tenantId, resource: null,
|
|
95
|
-
feature: 'access', action: 'manage',
|
|
96
|
-
});
|
|
97
|
-
if (!canManage || !input.targetUserId || !input.roleId) throw new Error('Forbidden');
|
|
98
|
-
const [role, isMember] = await Promise.all([input.loadTargetRole(), input.hasTargetMembership()]);
|
|
99
|
-
if (!isMember || !role || role.id !== input.roleId || role.tenantId !== input.tenantId) {
|
|
100
|
-
throw new Error('Forbidden');
|
|
101
|
-
}
|
|
102
|
-
for (const grant of role.grants) {
|
|
103
|
-
if (!canAccess({
|
|
104
|
-
actor, roles, assignments, resource: null, tenantId: input.tenantId,
|
|
105
|
-
feature: grant.resource, action: grant.action,
|
|
106
|
-
})) throw new Error('Forbidden');
|
|
107
|
-
}
|
|
108
|
-
return await input.writeAssignment();
|
|
109
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/** Shared policy semantics. UI checks are advisory: enforce again at the data boundary. */
|
|
2
|
-
export type Permission = `${string}:${string}`;
|
|
3
|
-
export type Grant = { resource: string; action: string; scope: 'any' | 'own' };
|
|
4
|
-
export type Role = { id: string; grants: readonly Grant[] };
|
|
5
|
-
export type Membership = { tenantId: string; roleIds: readonly string[]; groupIds: readonly string[] };
|
|
6
|
-
export type Actor = { id: string; globalRoleIds: readonly string[]; memberships: readonly Membership[] };
|
|
7
|
-
export type Resource = { ownerId: string; tenantId: string | null };
|
|
8
|
-
export type Assignment = { roleId: string; userId?: string; groupId?: string; tenantId: string | null };
|
|
9
|
-
|
|
10
|
-
/** All inputs MUST be loaded on the server from trusted identity + database records. */
|
|
11
|
-
export function canAccess(input: {
|
|
12
|
-
actor: Actor | null;
|
|
13
|
-
resource: Resource | null;
|
|
14
|
-
action: string;
|
|
15
|
-
feature: string;
|
|
16
|
-
tenantId: string | null;
|
|
17
|
-
roles: readonly Role[];
|
|
18
|
-
assignments: readonly Assignment[];
|
|
19
|
-
}): boolean {
|
|
20
|
-
const { actor, resource, action, feature, tenantId, roles, assignments } = input;
|
|
21
|
-
if (!actor || !actor.id || !feature || !action) return false;
|
|
22
|
-
if (resource && resource.tenantId !== tenantId) return false;
|
|
23
|
-
const membership = tenantId === null ? null : actor.memberships.find((m) => m.tenantId === tenantId);
|
|
24
|
-
if (tenantId !== null && !membership) return false;
|
|
25
|
-
const applicable = new Set<string>();
|
|
26
|
-
for (const assignment of assignments) {
|
|
27
|
-
if (assignment.tenantId !== tenantId) continue;
|
|
28
|
-
const validSubject = Boolean(assignment.userId) !== Boolean(assignment.groupId);
|
|
29
|
-
if (validSubject && (assignment.userId === actor.id || (membership && assignment.groupId && membership.groupIds.includes(assignment.groupId)))) {
|
|
30
|
-
applicable.add(assignment.roleId);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Global roles never implicitly authorize tenant resources.
|
|
34
|
-
for (const roleId of tenantId === null ? actor.globalRoleIds : membership?.roleIds ?? []) applicable.add(roleId);
|
|
35
|
-
const grants = roles.filter((role) => applicable.has(role.id)).flatMap((role) => role.grants);
|
|
36
|
-
return grants.some((grant) =>
|
|
37
|
-
grant.resource === feature && grant.action === action &&
|
|
38
|
-
(grant.scope === 'any' || (resource !== null && resource.ownerId === actor.id))
|
|
39
|
-
);
|
|
40
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
-- OPTIONAL PRIVILEGED OPERATIONS: review and apply after supabase-authorization.sql.
|
|
2
|
-
-- Unlike client writes to authorization tables, these narrowly scoped RPCs
|
|
3
|
-
-- authenticate via auth.uid(), require access:manage (any scope), and prevent
|
|
4
|
-
-- assigning permissions the administrator does not already hold (any scope).
|
|
5
|
-
-- New tenants/roles/grants must be provisioned by a separately audited server
|
|
6
|
-
-- workflow; do not expose service-role credentials to any client.
|
|
7
|
-
create or replace function app_authz.assign_tenant_role(
|
|
8
|
-
p_tenant uuid, p_user uuid, p_role uuid
|
|
9
|
-
) returns void language plpgsql security definer set search_path = '' as $$
|
|
10
|
-
begin
|
|
11
|
-
if not app_authz.allowed(p_tenant, 'access', 'manage', null) then
|
|
12
|
-
raise exception 'Forbidden' using errcode = '42501';
|
|
13
|
-
end if;
|
|
14
|
-
if not exists (
|
|
15
|
-
select 1 from app_authz.roles r
|
|
16
|
-
where r.id = p_role and r.tenant_id = p_tenant
|
|
17
|
-
) or not exists (
|
|
18
|
-
select 1 from app_authz.tenant_memberships m
|
|
19
|
-
where m.tenant_id = p_tenant and m.user_id = p_user
|
|
20
|
-
) then
|
|
21
|
-
raise exception 'Invalid tenant, role or member' using errcode = '42501';
|
|
22
|
-
end if;
|
|
23
|
-
if exists (
|
|
24
|
-
select 1 from app_authz.role_permissions rp
|
|
25
|
-
where rp.role_id = p_role
|
|
26
|
-
and not app_authz.allowed(p_tenant, rp.feature, rp.action, null)
|
|
27
|
-
) then
|
|
28
|
-
raise exception 'Cannot delegate permissions not held by administrator'
|
|
29
|
-
using errcode = '42501';
|
|
30
|
-
end if;
|
|
31
|
-
insert into app_authz.user_roles (user_id, tenant_id, role_id)
|
|
32
|
-
values (p_user, p_tenant, p_role)
|
|
33
|
-
on conflict do nothing;
|
|
34
|
-
end;
|
|
35
|
-
$$;
|
|
36
|
-
|
|
37
|
-
create or replace function app_authz.revoke_tenant_role(
|
|
38
|
-
p_tenant uuid, p_user uuid, p_role uuid
|
|
39
|
-
) returns void language plpgsql security definer set search_path = '' as $$
|
|
40
|
-
begin
|
|
41
|
-
if not app_authz.allowed(p_tenant, 'access', 'manage', null) then
|
|
42
|
-
raise exception 'Forbidden' using errcode = '42501';
|
|
43
|
-
end if;
|
|
44
|
-
delete from app_authz.user_roles
|
|
45
|
-
where tenant_id = p_tenant and user_id = p_user and role_id = p_role;
|
|
46
|
-
end;
|
|
47
|
-
$$;
|
|
48
|
-
revoke all on function app_authz.assign_tenant_role(uuid, uuid, uuid) from public;
|
|
49
|
-
revoke all on function app_authz.revoke_tenant_role(uuid, uuid, uuid) from public;
|
|
50
|
-
grant execute on function app_authz.assign_tenant_role(uuid, uuid, uuid) to authenticated;
|
|
51
|
-
grant execute on function app_authz.revoke_tenant_role(uuid, uuid, uuid) to authenticated;
|
|
52
|
-
-- Audit execution, tenant membership revocation, grant revocation and races
|
|
53
|
-
-- before enabling these RPCs in production. Additional operations (e.g. group
|
|
54
|
-
-- assignments, user invitations, grant editing) need separately reviewed APIs.
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
-- REFERENCE ONLY: adapt and review before adding to a real Supabase declarative schema.
|
|
2
|
-
-- Identity model: auth.uid() is a verified Supabase Auth UUID, never client-provided.
|
|
3
|
-
-- External OIDC subjects require a trusted mapping to auth.users IDs.
|
|
4
|
-
-- Tenant scope is mandatory in this example. Single-tenant/global policies differ.
|
|
5
|
-
create schema if not exists app_authz;
|
|
6
|
-
|
|
7
|
-
create table if not exists app_authz.tenants (
|
|
8
|
-
id uuid primary key default gen_random_uuid(),
|
|
9
|
-
name text not null
|
|
10
|
-
);
|
|
11
|
-
create table if not exists app_authz.tenant_memberships (
|
|
12
|
-
tenant_id uuid not null references app_authz.tenants(id),
|
|
13
|
-
user_id uuid not null references auth.users(id),
|
|
14
|
-
primary key (tenant_id, user_id)
|
|
15
|
-
);
|
|
16
|
-
create table if not exists app_authz.roles (
|
|
17
|
-
id uuid primary key default gen_random_uuid(),
|
|
18
|
-
tenant_id uuid references app_authz.tenants(id),
|
|
19
|
-
name text not null,
|
|
20
|
-
unique (id, tenant_id)
|
|
21
|
-
);
|
|
22
|
-
create table if not exists app_authz.role_permissions (
|
|
23
|
-
role_id uuid not null references app_authz.roles(id) on delete cascade,
|
|
24
|
-
feature text not null,
|
|
25
|
-
action text not null,
|
|
26
|
-
scope text not null check (scope in ('any','own')),
|
|
27
|
-
primary key (role_id, feature, action, scope)
|
|
28
|
-
);
|
|
29
|
-
create table if not exists app_authz.user_roles (
|
|
30
|
-
user_id uuid not null references auth.users(id),
|
|
31
|
-
tenant_id uuid not null references app_authz.tenants(id),
|
|
32
|
-
role_id uuid not null,
|
|
33
|
-
primary key (user_id, tenant_id, role_id),
|
|
34
|
-
foreign key (tenant_id, user_id) references app_authz.tenant_memberships(tenant_id, user_id),
|
|
35
|
-
foreign key (role_id, tenant_id) references app_authz.roles(id, tenant_id)
|
|
36
|
-
);
|
|
37
|
-
create table if not exists app_authz.groups (
|
|
38
|
-
id uuid primary key default gen_random_uuid(),
|
|
39
|
-
tenant_id uuid not null references app_authz.tenants(id),
|
|
40
|
-
name text not null,
|
|
41
|
-
unique (id, tenant_id)
|
|
42
|
-
);
|
|
43
|
-
create table if not exists app_authz.group_memberships (
|
|
44
|
-
group_id uuid not null,
|
|
45
|
-
tenant_id uuid not null,
|
|
46
|
-
user_id uuid not null references auth.users(id),
|
|
47
|
-
primary key (group_id, user_id),
|
|
48
|
-
foreign key (group_id, tenant_id) references app_authz.groups(id, tenant_id),
|
|
49
|
-
foreign key (tenant_id, user_id) references app_authz.tenant_memberships(tenant_id, user_id)
|
|
50
|
-
);
|
|
51
|
-
create table if not exists app_authz.group_roles (
|
|
52
|
-
group_id uuid not null,
|
|
53
|
-
tenant_id uuid not null,
|
|
54
|
-
role_id uuid not null,
|
|
55
|
-
primary key (group_id, role_id),
|
|
56
|
-
foreign key (group_id, tenant_id) references app_authz.groups(id, tenant_id),
|
|
57
|
-
foreign key (role_id, tenant_id) references app_authz.roles(id, tenant_id)
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
-- Deny unprivileged access even if a schema/table is exposed through PostgREST.
|
|
61
|
-
-- Provision tenant/role/group records only through a trusted, admin-authorized backend.
|
|
62
|
-
alter table app_authz.tenants enable row level security;
|
|
63
|
-
alter table app_authz.tenant_memberships enable row level security;
|
|
64
|
-
alter table app_authz.roles enable row level security;
|
|
65
|
-
alter table app_authz.role_permissions enable row level security;
|
|
66
|
-
alter table app_authz.user_roles enable row level security;
|
|
67
|
-
alter table app_authz.groups enable row level security;
|
|
68
|
-
alter table app_authz.group_memberships enable row level security;
|
|
69
|
-
alter table app_authz.group_roles enable row level security;
|
|
70
|
-
revoke all on schema app_authz from public, anon, authenticated;
|
|
71
|
-
revoke all on all tables in schema app_authz from public, anon, authenticated;
|
|
72
|
-
|
|
73
|
-
-- SECURITY DEFINER reads only database-owned memberships and assignments.
|
|
74
|
-
-- The function owner must be trusted and migrations must control these tables.
|
|
75
|
-
create or replace function app_authz.allowed(p_tenant uuid, p_feature text, p_action text,
|
|
76
|
-
p_owner uuid default null)
|
|
77
|
-
returns boolean language sql stable security definer
|
|
78
|
-
set search_path = '' as $$
|
|
79
|
-
select auth.uid() is not null and p_tenant is not null and exists (
|
|
80
|
-
select 1 from app_authz.tenant_memberships m
|
|
81
|
-
join app_authz.role_permissions rp on true
|
|
82
|
-
join app_authz.roles r on r.id = rp.role_id and r.tenant_id = p_tenant
|
|
83
|
-
where m.user_id = auth.uid() and m.tenant_id = p_tenant
|
|
84
|
-
and rp.feature = p_feature and rp.action = p_action
|
|
85
|
-
and (rp.scope = 'any' or (p_owner is not null and p_owner = auth.uid()))
|
|
86
|
-
and (
|
|
87
|
-
exists (
|
|
88
|
-
select 1 from app_authz.user_roles ur
|
|
89
|
-
where ur.user_id = m.user_id and ur.tenant_id = m.tenant_id and ur.role_id = r.id
|
|
90
|
-
)
|
|
91
|
-
or exists (
|
|
92
|
-
select 1 from app_authz.group_memberships gm
|
|
93
|
-
join app_authz.group_roles gr on gr.group_id = gm.group_id and gr.tenant_id = gm.tenant_id
|
|
94
|
-
where gm.user_id = m.user_id and gm.tenant_id = m.tenant_id and gr.role_id = r.id
|
|
95
|
-
)
|
|
96
|
-
)
|
|
97
|
-
);
|
|
98
|
-
$$;
|
|
99
|
-
revoke all on function app_authz.allowed(uuid,text,text,uuid) from public;
|
|
100
|
-
grant usage on schema app_authz to authenticated;
|
|
101
|
-
grant execute on function app_authz.allowed(uuid,text,text,uuid) to authenticated;
|
|
102
|
-
|
|
103
|
-
-- Attach this immutable-scope trigger to each tenant-owned resource table.
|
|
104
|
-
-- Supply exact tenant and owner column names as trigger arguments.
|
|
105
|
-
create or replace function app_authz.prevent_scope_reassignment()
|
|
106
|
-
returns trigger language plpgsql set search_path = '' as $$
|
|
107
|
-
begin
|
|
108
|
-
if tg_nargs <> 2 then
|
|
109
|
-
raise exception 'Expected tenant and owner column names';
|
|
110
|
-
end if;
|
|
111
|
-
if (to_jsonb(new) ->> tg_argv[0]) is distinct from (to_jsonb(old) ->> tg_argv[0])
|
|
112
|
-
or (to_jsonb(new) ->> tg_argv[1]) is distinct from (to_jsonb(old) ->> tg_argv[1]) then
|
|
113
|
-
raise exception 'Tenant or ownership reassignment is not permitted';
|
|
114
|
-
end if;
|
|
115
|
-
return new;
|
|
116
|
-
end;
|
|
117
|
-
$$;
|
|
118
|
-
revoke all on function app_authz.prevent_scope_reassignment() from public;
|
|
119
|
-
|
|
120
|
-
-- Example for a real application table app.posts(tenant_id uuid, owner_id uuid, ...).
|
|
121
|
-
-- Keep this as a recipe reference, not an automatically deployed policy.
|
|
122
|
-
-- ALTER TABLE app.posts ENABLE ROW LEVEL SECURITY;
|
|
123
|
-
-- CREATE POLICY posts_read ON app.posts FOR SELECT TO authenticated
|
|
124
|
-
-- USING (app_authz.allowed(tenant_id, 'post', 'read', owner_id));
|
|
125
|
-
-- CREATE POLICY posts_insert ON app.posts FOR INSERT TO authenticated
|
|
126
|
-
-- WITH CHECK (owner_id = auth.uid() AND
|
|
127
|
-
-- app_authz.allowed(tenant_id, 'post', 'create', owner_id));
|
|
128
|
-
-- CREATE POLICY posts_update ON app.posts FOR UPDATE TO authenticated
|
|
129
|
-
-- USING (app_authz.allowed(tenant_id, 'post', 'edit', owner_id))
|
|
130
|
-
-- WITH CHECK (app_authz.allowed(tenant_id, 'post', 'edit', owner_id));
|
|
131
|
-
-- CREATE POLICY posts_delete ON app.posts FOR DELETE TO authenticated
|
|
132
|
-
-- USING (app_authz.allowed(tenant_id, 'post', 'delete', owner_id));
|
|
133
|
-
-- CREATE TRIGGER posts_protect_scope BEFORE UPDATE ON app.posts
|
|
134
|
-
-- FOR EACH ROW EXECUTE FUNCTION app_authz.prevent_scope_reassignment('tenant_id', 'owner_id');
|
|
135
|
-
-- UPDATE requires this trigger: RLS WITH CHECK does not enforce immutability.
|
|
136
|
-
-- Composite foreign keys bind tenant roles, group assignments, and memberships
|
|
137
|
-
-- to the same tenant. Global roles require a separate deliberate policy.
|
|
138
|
-
-- Audit all privileged writes, RLS, revocation, and cross-tenant scenarios.
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
-- RUNNABLE INTEGRATION EXAMPLE, not automatically installed as a migration.
|
|
2
|
-
-- Requires supabase-authorization.sql to be reviewed/applied first.
|
|
3
|
-
-- This demonstration table is separate from application tables: never run it
|
|
4
|
-
-- as a substitute for policies on real business resources.
|
|
5
|
-
create table if not exists public.authorization_example_posts (
|
|
6
|
-
id uuid primary key default gen_random_uuid(),
|
|
7
|
-
tenant_id uuid not null references app_authz.tenants(id),
|
|
8
|
-
owner_id uuid not null references auth.users(id),
|
|
9
|
-
body text not null
|
|
10
|
-
);
|
|
11
|
-
alter table public.authorization_example_posts enable row level security;
|
|
12
|
-
revoke all on public.authorization_example_posts from public, anon;
|
|
13
|
-
grant select, insert, update, delete on public.authorization_example_posts to authenticated;
|
|
14
|
-
|
|
15
|
-
create policy authorization_example_posts_select on public.authorization_example_posts
|
|
16
|
-
for select to authenticated using (
|
|
17
|
-
app_authz.allowed(tenant_id, 'post', 'read', owner_id)
|
|
18
|
-
);
|
|
19
|
-
create policy authorization_example_posts_insert on public.authorization_example_posts
|
|
20
|
-
for insert to authenticated with check (
|
|
21
|
-
owner_id = (select auth.uid())
|
|
22
|
-
and app_authz.allowed(tenant_id, 'post', 'create', owner_id)
|
|
23
|
-
);
|
|
24
|
-
create policy authorization_example_posts_update on public.authorization_example_posts
|
|
25
|
-
for update to authenticated using (
|
|
26
|
-
app_authz.allowed(tenant_id, 'post', 'edit', owner_id)
|
|
27
|
-
) with check (
|
|
28
|
-
app_authz.allowed(tenant_id, 'post', 'edit', owner_id)
|
|
29
|
-
);
|
|
30
|
-
create policy authorization_example_posts_delete on public.authorization_example_posts
|
|
31
|
-
for delete to authenticated using (
|
|
32
|
-
app_authz.allowed(tenant_id, 'post', 'delete', owner_id)
|
|
33
|
-
);
|
|
34
|
-
|
|
35
|
-
create trigger authorization_example_posts_protect_scope
|
|
36
|
-
before update on public.authorization_example_posts
|
|
37
|
-
for each row execute function app_authz.prevent_scope_reassignment('tenant_id', 'owner_id');
|
|
38
|
-
-- Required: test authenticated Supabase client reads/writes with identities in
|
|
39
|
-
-- separate tenants and verify denied reads, updates and changed owner/tenant.
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { detectDependency } from "./package-json.js";
|
|
2
|
-
export const sentryRecipe = {
|
|
3
|
-
id: 'sentry',
|
|
4
|
-
recipeVersion: '1.0.0',
|
|
5
|
-
role: 'integration',
|
|
6
|
-
variants: [
|
|
7
|
-
{ id: 'vite', when: ['vite'] },
|
|
8
|
-
{ id: 'expo', when: ['expo'] },
|
|
9
|
-
],
|
|
10
|
-
async detect(projectRoot) {
|
|
11
|
-
const expo = await detectDependency(projectRoot, 'expo', 'Expo');
|
|
12
|
-
return expo.present
|
|
13
|
-
? await detectDependency(projectRoot, '@sentry/react-native', '@sentry/react-native')
|
|
14
|
-
: await detectDependency(projectRoot, '@sentry/react', '@sentry/react');
|
|
15
|
-
},
|
|
16
|
-
async apply(projectRoot, detection, resolution) {
|
|
17
|
-
if (!detection.present) {
|
|
18
|
-
throw new Error('Sentry is not installed; creating a Sentry integration is not supported by `add sentry` yet.');
|
|
19
|
-
}
|
|
20
|
-
const expected = resolution.variant === 'expo' ? '@sentry/react-native' : '@sentry/react';
|
|
21
|
-
const expectedDetection = await detectDependency(projectRoot, expected, expected);
|
|
22
|
-
if (!expectedDetection.present) {
|
|
23
|
-
throw new Error(`Sentry ${resolution.variant ?? 'project'} variant requires ${expected}`);
|
|
24
|
-
}
|
|
25
|
-
if (!detection.compatible)
|
|
26
|
-
throw new Error(detection.reason ?? 'Existing Sentry integration is not compatible.');
|
|
27
|
-
return { source: 'adopted' };
|
|
28
|
-
},
|
|
29
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { detectAnyDependency } from "./package-json.js";
|
|
2
|
-
import { pathExists } from "./project-signals.js";
|
|
3
|
-
export const shadcnRecipe = {
|
|
4
|
-
id: 'shadcn',
|
|
5
|
-
recipeVersion: '1.0.2',
|
|
6
|
-
role: 'integration',
|
|
7
|
-
requires: ['tailwind'],
|
|
8
|
-
async detect(projectRoot) {
|
|
9
|
-
if (!(await pathExists(projectRoot, 'components.json'))) {
|
|
10
|
-
return { present: false, compatible: false, detectedVersion: null, reason: 'components.json was not found' };
|
|
11
|
-
}
|
|
12
|
-
const dependency = await detectAnyDependency(projectRoot, ['shadcn', '@shadcn/react'], 'shadcn');
|
|
13
|
-
return { present: true, compatible: true, detectedVersion: dependency.present ? dependency.detectedVersion : null };
|
|
14
|
-
},
|
|
15
|
-
async apply(_projectRoot, detection, _resolution) {
|
|
16
|
-
if (!detection.present) {
|
|
17
|
-
throw new Error('Shadcn is not configured; creating Shadcn configuration is not supported by `add shadcn` yet.');
|
|
18
|
-
}
|
|
19
|
-
if (!detection.compatible)
|
|
20
|
-
throw new Error(detection.reason ?? 'Existing Shadcn integration is not compatible.');
|
|
21
|
-
return { source: 'adopted' };
|
|
22
|
-
},
|
|
23
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { detectAnyDependency, detectDependency } from "./package-json.js";
|
|
2
|
-
export const storybookRecipe = {
|
|
3
|
-
id: 'storybook',
|
|
4
|
-
recipeVersion: '1.0.0',
|
|
5
|
-
role: 'integration',
|
|
6
|
-
variants: [
|
|
7
|
-
{ id: 'vite', when: ['vite'] },
|
|
8
|
-
{ id: 'expo', when: ['expo'] },
|
|
9
|
-
],
|
|
10
|
-
async detect(projectRoot) {
|
|
11
|
-
const expo = await detectDependency(projectRoot, 'expo', 'Expo');
|
|
12
|
-
return expo.present
|
|
13
|
-
? await detectDependency(projectRoot, '@storybook/react-native', '@storybook/react-native')
|
|
14
|
-
: await detectAnyDependency(projectRoot, ['@storybook/react-vite', 'storybook'], 'Storybook');
|
|
15
|
-
},
|
|
16
|
-
async apply(projectRoot, detection, resolution) {
|
|
17
|
-
if (!detection.present)
|
|
18
|
-
throw new Error('Storybook is not installed; creating Storybook configuration is not supported by `add storybook` yet.');
|
|
19
|
-
const expected = resolution.variant === 'expo' ? ['@storybook/react-native'] : ['@storybook/react-vite', 'storybook'];
|
|
20
|
-
const compatible = await detectAnyDependency(projectRoot, expected, 'compatible Storybook renderer');
|
|
21
|
-
if (!compatible.present)
|
|
22
|
-
throw new Error(`Storybook ${resolution.variant ?? 'project'} variant is not configured with a compatible renderer`);
|
|
23
|
-
return { source: 'adopted' };
|
|
24
|
-
},
|
|
25
|
-
};
|