@starci/eslint-canon-be 3.6.8 → 3.7.1
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/CHANGELOG.md +16 -0
- package/dist/app-composition.d.ts +1 -1
- package/dist/app-composition.js +18 -5
- package/dist/auth-passport.d.ts +14 -0
- package/dist/auth-passport.js +106 -0
- package/dist/index.js +4 -0
- package/dist/jwt-alg.js +1 -1
- package/dist/lib/hfs-view.d.ts +9 -0
- package/dist/module-layering.js +17 -4
- package/dist/no-raw-sql.d.ts +9 -0
- package/dist/no-raw-sql.js +78 -0
- package/package.json +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +44 -24
- package/runtime/knowledge/hfs/fe-stack.yaml +4 -11
- package/runtime/knowledge/hfs/rules.yaml +179 -157
- package/runtime/knowledge/hfs/slots.yaml +185 -172
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +1 -1
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +53 -0
- package/runtime/scripts/hfs/architecture/{supabase-be.mjs → identity.mjs} +45 -15
- package/runtime/scripts/hfs/architecture/index.mjs +2 -3
- package/runtime/scripts/hfs/architecture/{supabase-ast.mjs → jwt-ast.mjs} +2 -103
- package/runtime/scripts/hfs/architecture/owners.mjs +11 -0
- package/runtime/scripts/hfs/architecture/register-once.mjs +1 -1
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +29 -4
- package/runtime/scripts/hfs/architecture/server-action.mjs +3 -4
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +1 -1
- package/runtime/scripts/hfs/architecture/{supabase-keys.mjs → sql-keys.mjs} +1 -1
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +25 -27
- package/runtime/scripts/hfs/architecture/tiers.mjs +14 -3
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +7 -3
- package/runtime/scripts/hfs/declaration-shape.mjs +15 -18
- package/runtime/scripts/hfs/manifest-shape.mjs +9 -5
- package/runtime/scripts/hfs/rule-params-shape.mjs +4 -1
- package/runtime/scripts/hfs/rules/database-constants.mjs +8 -10
- package/runtime/scripts/hfs/rules/database-migrations.mjs +3 -3
- package/runtime/scripts/hfs/slot-app-view.mjs +1 -1
- package/runtime/scripts/hfs/slots.mjs +8 -2
- package/runtime/scripts/lib/secret-patterns.mjs +2 -2
- package/runtime/scripts/hfs/architecture/supabase-tables.mjs +0 -50
- package/runtime/scripts/hfs/architecture/supabase.mjs +0 -226
|
@@ -154,7 +154,7 @@ function readCall(env, call, managers) {
|
|
|
154
154
|
function ownedRead(env, statement) {
|
|
155
155
|
const { ts } = env;
|
|
156
156
|
const call = statementCall(ts, statement);
|
|
157
|
-
if (!call || !ts.isCallExpression(call) || !imported(env, call.expression, '
|
|
157
|
+
if (!call || !ts.isCallExpression(call) || !imported(env, call.expression, 'requireOwnedEntity', '@modules/platform/database') || call.arguments.length !== 5) return false;
|
|
158
158
|
if (!call.arguments.slice(0, 4).every(argument => mapping(env, argument))) return false;
|
|
159
159
|
const callback = unwrap(ts, call.arguments[4]);
|
|
160
160
|
if (!ts.isArrowFunction(callback) || callback.parameters.length || !ts.isBlock(callback.body) || callback.body.statements.length !== 1) return false;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { braceVariants, globExpression } from '../../lib/glob.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The entity registry (persistence.md BE-PERSISTENCE-3): the one file whose slot plays `role: entity-registry`
|
|
5
|
+
* (`be.platform.database.entities`, lite's `src/modules/platform/database/entities.ts`). It lists every capability's `<c>Entities`
|
|
6
|
+
* array as `PRIMARY_ENTITIES`, so it is the one platform file that imports domain and platform capability barrels, and only for
|
|
7
|
+
* that name; and it is imported by deep path only from the files its slot's `importedBy` names (app composition and the test world).
|
|
8
|
+
* The tier matrix (tiers.mjs), the public-entry check (owners.mjs) and the lint rule `import-owner-entry` read it here.
|
|
9
|
+
*/
|
|
10
|
+
export const ENTITY_REGISTRY_ROLE = 'entity-registry';
|
|
11
|
+
|
|
12
|
+
/** The tiers whose capabilities contribute an entity list to the registry. */
|
|
13
|
+
const CONTRIBUTING_TIERS = new Set(['domain', 'platform']);
|
|
14
|
+
|
|
15
|
+
/** The entity list a capability exports: `<c>Entities`, `<c>` its folder name in camelCase. */
|
|
16
|
+
export const entityListName = capability => `${capability.replace(/-([a-z0-9])/g, (_, next) => next.toUpperCase())}Entities`;
|
|
17
|
+
|
|
18
|
+
/** The slot of `file` (side-relative or absolute) when it plays the entity-registry role, else null. */
|
|
19
|
+
export function registrySlot(resolver, file) {
|
|
20
|
+
const slot = resolver?.slotOf?.(file);
|
|
21
|
+
return slot?.role === ENTITY_REGISTRY_ROLE ? slot : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Whether `file` is one of the importers the registry slot admits by deep path (`importedBy`, side-relative patterns); an app-wide
|
|
26
|
+
* resolver answers for a side-prefixed path (`be/apps/...`), which is read without its side folder.
|
|
27
|
+
*/
|
|
28
|
+
export function registryImporter(resolver, slot, file) {
|
|
29
|
+
const side = resolver?.sideOf?.(file);
|
|
30
|
+
const rel = side ? file.slice(side.length + 1) : file;
|
|
31
|
+
return (slot.importedBy ?? []).some(pattern => braceVariants(pattern).some(variant => globExpression(variant).test(rel)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The names an import declaration binds by name; null for a default, namespace or side-effect import and for any re-export. */
|
|
35
|
+
function namedImports(declaration) {
|
|
36
|
+
const clause = declaration?.importClause;
|
|
37
|
+
if (!clause || clause.name || !Array.isArray(clause.namedBindings?.elements) || !clause.namedBindings.elements.length) return null;
|
|
38
|
+
return clause.namedBindings.elements.map(element => (element.propertyName ?? element.name).text);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Whether an owner-graph edge (side-relative `from` and `to`, `edge.declaration` the TypeScript statement) is the registry naming a
|
|
43
|
+
* capability's entity list: it leaves the registry, imports the public entry (`index.ts`) of a domain or platform capability, and
|
|
44
|
+
* binds that capability's `<c>Entities` and nothing else.
|
|
45
|
+
*/
|
|
46
|
+
export function registryListImport(resolver, edge) {
|
|
47
|
+
if (!registrySlot(resolver, edge.from)) return false;
|
|
48
|
+
const owner = resolver.ownerOf(edge.to);
|
|
49
|
+
if (!owner || !CONTRIBUTING_TIERS.has(resolver.slot(owner.slot)?.tier) || edge.to !== `${owner.root}/index.ts`) return false;
|
|
50
|
+
const names = namedImports(edge.edge?.declaration ?? edge.declaration);
|
|
51
|
+
const listName = entityListName(owner.root.split('/').at(-1));
|
|
52
|
+
return names !== null && names.every(name => name === listName);
|
|
53
|
+
}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// identity.mjs - the back-end identity machine. Under lite the one token verifier is be.integrations.passport: jose's jwtVerify
|
|
2
|
+
// there checks the app's OWN key set (createLocalJWKSet over the keys it signs with, never createRemoteJWKSet), pins issuer,
|
|
3
|
+
// audience and algorithms, and no file decodes a token unverified or reads authorization claims from a request body (R329).
|
|
4
|
+
// In both editions every jwtVerify call holds the JWT policy (R260, jwtPolicyProblems).
|
|
3
5
|
import path from 'node:path';
|
|
4
6
|
import { machineKit } from './machine-ast.mjs';
|
|
5
|
-
import { importedFrom, reportAt, unwrap } from './
|
|
7
|
+
import { importedFrom, jwtPolicyProblems, reportAt, unwrap } from './jwt-ast.mjs';
|
|
6
8
|
import { accessName } from '../../lib/ts-ast.mjs';
|
|
7
9
|
|
|
8
|
-
const
|
|
9
|
-
const BE_JWT_VERIFIED = '
|
|
10
|
+
const PASSPORT_SLOT = 'be.integrations.passport';
|
|
11
|
+
const BE_JWT_VERIFIED = 'BE_AUTH_JWT_OWN_JWKS';
|
|
12
|
+
|
|
13
|
+
/** The rule ids the back-end identity machine reports. */
|
|
14
|
+
export const IDENTITY_RULE_IDS = Object.freeze(['BE_AUTH_JWT_OWN_JWKS', 'BE_JWT_ALG_PINNED']);
|
|
10
15
|
const JWT_MODULES = new Set(['jose', 'jsonwebtoken', 'jwt-decode']);
|
|
11
16
|
const CLAIM_NAMES = new Set(['role', 'roles', 'membership', 'memberships']);
|
|
12
17
|
|
|
@@ -33,7 +38,7 @@ const staticStrings = (kit, checker, node) => {
|
|
|
33
38
|
|
|
34
39
|
const jwksArgument = (kit, checker, node) => {
|
|
35
40
|
const current = unwrap(kit.ts, node);
|
|
36
|
-
if (kit.ts.isCallExpression(current)) return importedFrom(kit, checker, current.expression, new Set(['jose']), new Set(['
|
|
41
|
+
if (kit.ts.isCallExpression(current)) return importedFrom(kit, checker, current.expression, new Set(['jose']), new Set(['createLocalJWKSet']));
|
|
37
42
|
if (!kit.ts.isIdentifier(current)) return false;
|
|
38
43
|
return kit.declarationsOf(checker, current).some((declaration) => kit.ts.isVariableDeclaration(declaration) && declaration.initializer
|
|
39
44
|
&& jwksArgument(kit, checker, declaration.initializer));
|
|
@@ -69,8 +74,8 @@ const fromRequestBody = (kit, checker, node, seen = new Set()) => {
|
|
|
69
74
|
|
|
70
75
|
function verifyJwtCall(kit, checker, file, node, counters, violations) {
|
|
71
76
|
counters.verifyCalls += 1;
|
|
72
|
-
if (file.slot !==
|
|
73
|
-
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `jwtVerify is called outside ${
|
|
77
|
+
if (file.slot !== PASSPORT_SLOT) {
|
|
78
|
+
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `jwtVerify is called outside ${PASSPORT_SLOT}; the integration is the one token verifier.`);
|
|
74
79
|
return true;
|
|
75
80
|
}
|
|
76
81
|
const options = objectLiteral(kit, checker, node.arguments[2]);
|
|
@@ -82,10 +87,10 @@ function verifyJwtCall(kit, checker, file, node, counters, violations) {
|
|
|
82
87
|
const issuer = property('issuer');
|
|
83
88
|
const audience = values('audience');
|
|
84
89
|
const algorithms = values('algorithms');
|
|
85
|
-
const good = jwksArgument(kit, checker, node.arguments[1]) && issuer != null && audience
|
|
90
|
+
const good = jwksArgument(kit, checker, node.arguments[1]) && issuer != null && audience !== null && audience.length > 0
|
|
86
91
|
&& algorithms !== null && algorithms.length > 0;
|
|
87
92
|
if (!good) {
|
|
88
|
-
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, '
|
|
93
|
+
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, 'jwtVerify must check the app\'s own key set (createLocalJWKSet(...) over the keys integrations/passport signs with) and pin issuer, audience and a non-empty algorithms list; jwtVerify then enforces signature and exp.');
|
|
89
94
|
} else counters.verifiedCalls += 1;
|
|
90
95
|
return false;
|
|
91
96
|
}
|
|
@@ -93,7 +98,7 @@ function verifyJwtCall(kit, checker, file, node, counters, violations) {
|
|
|
93
98
|
function inspectJwtCall(kit, checker, file, node, counters, violations) {
|
|
94
99
|
const binding = importedCall(kit, checker, node);
|
|
95
100
|
if (binding && JWT_MODULES.has(binding.module) && ['decode', 'decodeJwt', 'jwtDecode'].includes(binding.name)) {
|
|
96
|
-
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${binding.module}.${binding.name} decodes a token without proving its signature;
|
|
101
|
+
reportAt(violations, kit, BE_JWT_VERIFIED, file, node, `${binding.module}.${binding.name} decodes a token without proving its signature; verify it through integrations/passport.`, { module: binding.module, method: binding.name });
|
|
97
102
|
}
|
|
98
103
|
if (binding?.module === 'jose' && binding.name === 'jwtVerify') return verifyJwtCall(kit, checker, file, node, counters, violations);
|
|
99
104
|
return false;
|
|
@@ -118,10 +123,10 @@ function inspectBackendNode(kit, checker, file, node, counters, violations) {
|
|
|
118
123
|
if (!handled) inspectRequestClaims(kit, file, node, checker, violations);
|
|
119
124
|
}
|
|
120
125
|
|
|
121
|
-
|
|
126
|
+
function checkOwnJwks(input) {
|
|
122
127
|
const kit = machineKit(input);
|
|
123
128
|
const violations = [];
|
|
124
|
-
const integrations = [...input.graph.files.values()].filter((file) => file.slot ===
|
|
129
|
+
const integrations = [...input.graph.files.values()].filter((file) => file.slot === PASSPORT_SLOT);
|
|
125
130
|
if (!integrations.length) return { violations, coverage: { status: 'not-applicable', integrationFiles: 0, verifiedCalls: 0 } };
|
|
126
131
|
const counters = { verifyCalls: 0, verifiedCalls: 0 };
|
|
127
132
|
for (const file of input.graph.files.values()) {
|
|
@@ -129,8 +134,33 @@ export function checkBackendJwt(input) {
|
|
|
129
134
|
kit.walk(file.sourceFile, node => inspectBackendNode(kit, checker, file, node, counters, violations));
|
|
130
135
|
}
|
|
131
136
|
if (counters.verifyCalls === 0) {
|
|
132
|
-
const anchor = integrations.find((file) => path.posix.basename(file.rel).endsWith('.
|
|
133
|
-
reportAt(violations, kit, BE_JWT_VERIFIED, anchor, anchor.sourceFile, `${
|
|
137
|
+
const anchor = integrations.find((file) => path.posix.basename(file.rel).endsWith('.tokens.ts')) ?? integrations[0];
|
|
138
|
+
reportAt(violations, kit, BE_JWT_VERIFIED, anchor, anchor.sourceFile, `${PASSPORT_SLOT} has no jose.jwtVerify call backed by createLocalJWKSet over the app's own keys.`);
|
|
134
139
|
}
|
|
135
140
|
return { violations, coverage: { status: 'checked', integrationFiles: integrations.length, verifyCalls: counters.verifyCalls, verifiedCalls: counters.verifiedCalls } };
|
|
136
141
|
}
|
|
142
|
+
|
|
143
|
+
/** R260 BE_JWT_ALG_PINNED: every jose jwtVerify call pins a literal secure algorithm list, a configured issuer and the authenticated role. */
|
|
144
|
+
export function checkJwtPolicy(input) {
|
|
145
|
+
const kit = machineKit(input);
|
|
146
|
+
const violations = [];
|
|
147
|
+
let verifyCalls = 0;
|
|
148
|
+
for (const file of input.graph.files.values()) {
|
|
149
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
150
|
+
kit.walk(file.sourceFile, node => {
|
|
151
|
+
if (!kit.ts.isCallExpression(node) || !kit.isImportOf(checker, node.expression, 'jwtVerify', 'jose')) return;
|
|
152
|
+
verifyCalls += 1;
|
|
153
|
+
const problems = jwtPolicyProblems(kit.ts, checker, node);
|
|
154
|
+
if (problems.length) reportAt(violations, kit, 'BE_JWT_ALG_PINNED', file, node, problems.join(' '));
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return { violations, coverage: { status: 'checked', verifyCalls } };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** The back-end identity machine: the own-JWKS law where the passport integration exists (lite), the JWT policy everywhere. */
|
|
161
|
+
export function checkBackendIdentity(input) {
|
|
162
|
+
const slot = input.graph.resolver.slot(PASSPORT_SLOT);
|
|
163
|
+
const own = slot && input.graph.resolver.slotEnabled(slot) ? checkOwnJwks(input) : { violations: [], coverage: { status: 'not-applicable', reason: 'no passport integration slot (full edition)' } };
|
|
164
|
+
const policy = checkJwtPolicy(input);
|
|
165
|
+
return { violations: [...own.violations, ...policy.violations], coverage: { status: 'checked', ownJwks: own.coverage, jwtPolicy: policy.coverage } };
|
|
166
|
+
}
|
|
@@ -48,7 +48,7 @@ import { checkPackageShape, PACKAGE_SHAPE_RULE_IDS } from './package-shape.mjs';
|
|
|
48
48
|
import { checkFeSlotAllows, FE_SLOT_ALLOWS_RULE_IDS } from './fe-slot-allows.mjs';
|
|
49
49
|
import { checkI18nKeys, I18N_KEYS_RULE_IDS } from './i18n-keys.mjs';
|
|
50
50
|
import { checkDocLanguage, DOC_LANGUAGE_RULE_IDS } from './doc-language.mjs';
|
|
51
|
-
import {
|
|
51
|
+
import { checkBackendIdentity, IDENTITY_RULE_IDS } from './identity.mjs';
|
|
52
52
|
import { checkServerActions, SERVER_ACTION_RULE_IDS } from './server-action.mjs';
|
|
53
53
|
import { LINT_CODES, onLintSurface } from './surface.mjs';
|
|
54
54
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
@@ -86,7 +86,7 @@ const BACKEND_MACHINE = {
|
|
|
86
86
|
backgroundUnowned: [checkBackgroundUnowned, BACKGROUND_UNOWNED_RULE_IDS],
|
|
87
87
|
testWorldFiles: [checkTestWorldFiles, TEST_WORLD_FILES_RULE_IDS],
|
|
88
88
|
contractFixtureGuard: [checkContractFixtureGuard, CONTRACT_FIXTURE_GUARD_RULE_IDS],
|
|
89
|
-
|
|
89
|
+
identity: [checkBackendIdentity, IDENTITY_RULE_IDS],
|
|
90
90
|
};
|
|
91
91
|
|
|
92
92
|
// The frontend repository machine (R21, R50, R54, R55, R56, R63, R94, R106): same shape, run for a front-end repository only.
|
|
@@ -99,7 +99,6 @@ const FRONTEND_MACHINE = {
|
|
|
99
99
|
crossAppDuplicate: [checkCrossAppDuplicate, CROSS_APP_DUPLICATE_RULE_IDS],
|
|
100
100
|
feSlotAllows: [checkFeSlotAllows, FE_SLOT_ALLOWS_RULE_IDS],
|
|
101
101
|
i18nKeys: [checkI18nKeys, I18N_KEYS_RULE_IDS],
|
|
102
|
-
supabaseFrontend: [checkFrontendSupabase, FRONTEND_SUPABASE_RULE_IDS],
|
|
103
102
|
serverActions: [checkServerActions, SERVER_ACTION_RULE_IDS],
|
|
104
103
|
};
|
|
105
104
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
1
|
+
// jwt-ast.mjs - shared TypeScript-symbol and expression helpers of the identity checks (token verification and the principal).
|
|
2
|
+
// Recognition follows imported declarations and inferred types, never local spelling alone.
|
|
3
3
|
import { unwrapExpression } from '../../lib/ts-analysis.mjs';
|
|
4
4
|
import { accessName as memberName, hasAnyFlag } from '../../lib/ts-ast.mjs';
|
|
5
5
|
export { accessName as memberName } from '../../lib/ts-ast.mjs';
|
|
6
6
|
|
|
7
|
-
export const SUPABASE_MODULES = Object.freeze({ has: name => typeof name === 'string' && name.startsWith('@supabase/') });
|
|
8
|
-
|
|
9
7
|
export const moduleNameOf = (ts, node) => {
|
|
10
8
|
if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && ts.isStringLiteralLike(node.moduleSpecifier)) return node.moduleSpecifier.text;
|
|
11
9
|
if (!ts.isCallExpression(node)) return null;
|
|
@@ -19,39 +17,8 @@ export const importedFrom = (kit, checker, node, modules, names = null) => {
|
|
|
19
17
|
return Boolean(binding && modules.has(binding.module) && (names === null || names.has(binding.name)));
|
|
20
18
|
};
|
|
21
19
|
|
|
22
|
-
const declarationFromSupabase = (declaration) => /(?:^|\/)node_modules\/@supabase\/[^/]+(?:\/|$)/u
|
|
23
|
-
.test(String(declaration?.getSourceFile?.().fileName ?? '').replaceAll('\\', '/'));
|
|
24
|
-
|
|
25
|
-
const typeFromSupabase = (checker, node) => {
|
|
26
|
-
let type;
|
|
27
|
-
try { type = checker.getTypeAtLocation(node); } catch { return false; }
|
|
28
|
-
const queue = [type];
|
|
29
|
-
const seen = new Set();
|
|
30
|
-
while (queue.length) {
|
|
31
|
-
const item = queue.shift();
|
|
32
|
-
if (!item || seen.has(item)) continue;
|
|
33
|
-
seen.add(item);
|
|
34
|
-
if ([item.symbol, item.aliasSymbol].some((symbol) => symbol?.declarations?.some(declarationFromSupabase))) return true;
|
|
35
|
-
if (item.types) queue.push(...item.types);
|
|
36
|
-
if (item.target && item.target !== item) queue.push(item.target);
|
|
37
|
-
}
|
|
38
|
-
return false;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const signatureFromSupabase = (checker, call) => {
|
|
42
|
-
try { return declarationFromSupabase(checker.getResolvedSignature(call)?.declaration); } catch { return false; }
|
|
43
|
-
};
|
|
44
|
-
|
|
45
20
|
export const unwrap = (ts, node) => unwrapExpression(ts, node, { awaitExpressions: true, satisfiesExpressions: false });
|
|
46
21
|
|
|
47
|
-
const isSupabaseValue = (kit, checker, node) => {
|
|
48
|
-
const current = unwrap(kit.ts, node);
|
|
49
|
-
if (!current) return false;
|
|
50
|
-
if (importedFrom(kit, checker, current, SUPABASE_MODULES)) return true;
|
|
51
|
-
if (kit.ts.isCallExpression(current) && signatureFromSupabase(checker, current)) return true;
|
|
52
|
-
return typeFromSupabase(checker, current);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
22
|
export const callName = (ts, call) => ts.isCallExpression(call) ? memberName(ts, call.expression) : null;
|
|
56
23
|
|
|
57
24
|
export const chainParts = (ts, expression) => {
|
|
@@ -73,74 +40,6 @@ export const chainParts = (ts, expression) => {
|
|
|
73
40
|
return names;
|
|
74
41
|
};
|
|
75
42
|
|
|
76
|
-
export const isSupabaseCall = (kit, checker, node) => kit.ts.isCallExpression(node)
|
|
77
|
-
&& (signatureFromSupabase(checker, node) || isSupabaseValue(kit, checker,
|
|
78
|
-
kit.ts.isPropertyAccessExpression(node.expression) || kit.ts.isElementAccessExpression(node.expression) ? node.expression.expression : node.expression));
|
|
79
|
-
|
|
80
|
-
const authStorageValue = (kit, checker, expression, seen = new Set()) => {
|
|
81
|
-
const current = unwrap(kit.ts, expression);
|
|
82
|
-
if (!current || seen.has(current)) return false;
|
|
83
|
-
seen.add(current);
|
|
84
|
-
if (['auth', 'storage'].includes(memberName(kit.ts, current)) && isSupabaseValue(kit, checker, current.expression)) return true;
|
|
85
|
-
if (checker.getTypeAtLocation(current).symbol?.declarations?.some(declaration =>
|
|
86
|
-
/\/node_modules\/@supabase\/(?:storage-js|auth-js)\//u.test(String(declaration.getSourceFile().fileName).replaceAll('\\', '/')))) return true;
|
|
87
|
-
if (!kit.ts.isIdentifier(current)) return false;
|
|
88
|
-
return kit.declarationsOf(checker, current).some(declaration =>
|
|
89
|
-
(kit.ts.isVariableDeclaration(declaration) || kit.ts.isPropertyDeclaration(declaration)) && declaration.initializer
|
|
90
|
-
&& authStorageValue(kit, checker, declaration.initializer, seen));
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const chainAccesses = (ts, node) => {
|
|
94
|
-
const accesses = [];
|
|
95
|
-
let current = unwrap(ts, node);
|
|
96
|
-
while (current) {
|
|
97
|
-
if (ts.isCallExpression(current)) current = unwrap(ts, current.expression);
|
|
98
|
-
else if (ts.isPropertyAccessExpression(current) || ts.isElementAccessExpression(current)) {
|
|
99
|
-
accesses.unshift(current);
|
|
100
|
-
current = unwrap(ts, current.expression);
|
|
101
|
-
} else break;
|
|
102
|
-
}
|
|
103
|
-
return accesses;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
/** The first forbidden SDK access in a call chain, anchored once even when more methods follow it. */
|
|
107
|
-
export const supabaseDataAccess = (kit, checker, node, members, { storageAllowed = false } = {}) => {
|
|
108
|
-
for (const access of chainAccesses(kit.ts, node)) {
|
|
109
|
-
const name = memberName(kit.ts, access);
|
|
110
|
-
if (storageAllowed && (name === 'storage' || name === 'auth')) return null;
|
|
111
|
-
if (members.has(name) && isSupabaseValue(kit, checker, access.expression)) {
|
|
112
|
-
if (storageAllowed && authStorageValue(kit, checker, access.expression)) return null;
|
|
113
|
-
return { name, node: access };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export const isDatabaseType = (ts, node) => {
|
|
120
|
-
if (!node) return false;
|
|
121
|
-
if (ts.isTypeReferenceNode(node)) {
|
|
122
|
-
const name = ts.isIdentifier(node.typeName) ? node.typeName.text : node.typeName.right.text;
|
|
123
|
-
return name === 'Database';
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const supabaseClientType = (kit, checker, node) => {
|
|
129
|
-
if (!node || !kit.ts.isTypeReferenceNode(node)) return false;
|
|
130
|
-
const name = kit.ts.isIdentifier(node.typeName) ? node.typeName : null;
|
|
131
|
-
return Boolean(name && importedFrom(kit, checker, name, SUPABASE_MODULES, new Set(['SupabaseClient'])));
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
export const contextTypesClient = (kit, checker, call) => {
|
|
135
|
-
let parent = call.parent;
|
|
136
|
-
while (parent && (kit.ts.isParenthesizedExpression(parent) || kit.ts.isAsExpression(parent))) {
|
|
137
|
-
if (kit.ts.isAsExpression(parent) && supabaseClientType(kit, checker, parent.type) && isDatabaseType(kit.ts, parent.type.typeArguments?.[0])) return true;
|
|
138
|
-
parent = parent.parent;
|
|
139
|
-
}
|
|
140
|
-
return kit.ts.isVariableDeclaration(parent) && supabaseClientType(kit, checker, parent.type)
|
|
141
|
-
&& isDatabaseType(kit.ts, parent.type.typeArguments?.[0]);
|
|
142
|
-
};
|
|
143
|
-
|
|
144
43
|
export const reportAt = (violations, kit, ruleId, file, node, message, extra = {}) => {
|
|
145
44
|
violations.push({ ruleId, ...kit.at(file.rel, file.sourceFile, node), message, ...extra });
|
|
146
45
|
};
|
|
@@ -4,6 +4,7 @@ import { relativePath, workspaceExportSources } from './typescript.mjs';
|
|
|
4
4
|
import { sourceLocation } from '../../lib/ts-ast.mjs';
|
|
5
5
|
import { globExpression } from '../../lib/glob.mjs';
|
|
6
6
|
import { posixPath } from '../../lib/path-key.mjs';
|
|
7
|
+
import { registryImporter, registrySlot } from './entity-registry.mjs';
|
|
7
8
|
|
|
8
9
|
function absolute(root, relative) {
|
|
9
10
|
return canonical(path.resolve(root, ...relative.split('/')));
|
|
@@ -68,6 +69,15 @@ function arrangesSchema(config, from, to) {
|
|
|
68
69
|
&& resolver.classifyPath(relativePath(config.root, to)).slot === 'be.persistence';
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The entity registry (slot role entity-registry, entity-registry.mjs) is imported by deep path, and only from the files its slot's
|
|
74
|
+
* `importedBy` names: app composition and the test world. Any other importer goes through the owner's entry, which never exports it.
|
|
75
|
+
*/
|
|
76
|
+
function importsRegistry(config, from, to) {
|
|
77
|
+
const slot = registrySlot(config.hfs, relativePath(config.root, to));
|
|
78
|
+
return slot !== null && registryImporter(config.hfs, slot, relativePath(config.root, from));
|
|
79
|
+
}
|
|
80
|
+
|
|
71
81
|
function publicEntryViolations(config, context, owners, sourceFiles) {
|
|
72
82
|
const violations = [];
|
|
73
83
|
for (const owner of owners) {
|
|
@@ -104,6 +114,7 @@ function ownerImportViolations(config, context, owners) {
|
|
|
104
114
|
const bypass = privateOwnerChain(context, owners, edge);
|
|
105
115
|
if (!bypass) continue;
|
|
106
116
|
if (arrangesSchema(config, from, bypass.chain.at(-1))) continue;
|
|
117
|
+
if (bypass.chain.length === 2 && importsRegistry(config, from, bypass.chain.at(-1))) continue;
|
|
107
118
|
violations.push({
|
|
108
119
|
ruleId: 'ARCH_OWNER_EXPORT_BYPASS',
|
|
109
120
|
path: relativePath(config.root, from),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { isComposeGroup, machineKit } from './machine-ast.mjs';
|
|
3
|
-
import { callName } from './
|
|
3
|
+
import { callName } from './jwt-ast.mjs';
|
|
4
4
|
import { isTestWorldSlot } from '../test-world-slot.mjs';
|
|
5
5
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
6
6
|
|
|
@@ -20,6 +20,11 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
20
20
|
* (`<c>` the camelCase capability name), and no other name coming from `persistence/`;
|
|
21
21
|
* - a migration file is `<epochMs13>-<kebab-name>.ts`, holds a class `<Pascal><epochMs13>` and a `name` property equal to
|
|
22
22
|
* that class name, and has no unit spec beside it.
|
|
23
|
+
*
|
|
24
|
+
* Lite (persistence.md BE-PERSISTENCE-3, ruling lite-persistence-typeorm-entities) has entities and no be migration: the
|
|
25
|
+
* capability's `persistence/entities/index.ts` declares `<c>Entities`, its `index.ts` exports that one persistence name, and
|
|
26
|
+
* `platform/database/entities.ts` names it in `PRIMARY_ENTITIES`, the one list the app composition registers; there is a
|
|
27
|
+
* single primary connection, so the per-connection checks do not apply.
|
|
23
28
|
*/
|
|
24
29
|
export const SCHEMA_OWNER_RULE_IDS = ['BE_SCHEMA_OWNER'];
|
|
25
30
|
|
|
@@ -27,6 +32,8 @@ const RULE = 'BE_SCHEMA_OWNER';
|
|
|
27
32
|
const PERSISTENCE_SLOT = 'be.persistence';
|
|
28
33
|
const SCHEMA_FOLDERS = new Set(['entities', 'migrations']);
|
|
29
34
|
const MIGRATION_FILE = /^(\d{13})-([a-z0-9]+(?:-[a-z0-9]+)*)\.ts$/u;
|
|
35
|
+
/** The lite entity list every capability's `<c>Entities` is named in (BE-PERSISTENCE-3). */
|
|
36
|
+
const LITE_ENTITY_LIST = `${DATABASE_DIR}/entities.ts`;
|
|
30
37
|
const camel = name => { const text = pascal(name); return text[0].toLowerCase() + text.slice(1); };
|
|
31
38
|
|
|
32
39
|
function noteSchemaOwner(found, persistence, kind) {
|
|
@@ -127,6 +134,22 @@ function reportRegistrationSites(registered, connections, resolver, report) {
|
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
|
|
137
|
+
/** The identifiers a file of the graph declares or names, for the lite list checks. */
|
|
138
|
+
function identifiersOf(ts, file) {
|
|
139
|
+
const names = new Set();
|
|
140
|
+
const visit = node => { if (ts.isIdentifier(node)) names.add(node.text); ts.forEachChild(node, visit); };
|
|
141
|
+
if (file) visit(file.sourceFile);
|
|
142
|
+
return names;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function reportLiteEntityArrays(key, kinds, graph, ts, plain) {
|
|
146
|
+
const wanted = `${camel(kinds.name)}Entities`;
|
|
147
|
+
const listFile = `${key}/persistence/entities/index.ts`;
|
|
148
|
+
const declared = new Set((graph.files.get(listFile)?.sourceFile.statements.filter(ts.isVariableStatement).flatMap(statement => statement.declarationList.declarations) ?? []).map(item => item.name.text));
|
|
149
|
+
if (!declared.has(wanted)) plain(listFile, `${listFile} must export ${wanted}, the entities of the ${kinds.name} capability, the one file that lists them.`, { capability: kinds.name });
|
|
150
|
+
if (!identifiersOf(ts, graph.files.get(LITE_ENTITY_LIST)).has(wanted)) plain(LITE_ENTITY_LIST, `The ${kinds.name} capability has entities but ${LITE_ENTITY_LIST} does not name ${wanted} in PRIMARY_ENTITIES; list it there by name, the one list the app composition registers.`, { capability: kinds.name });
|
|
151
|
+
}
|
|
152
|
+
|
|
130
153
|
function reportDeclaredPersistenceArrays(key, kinds, registered, graph, ts, plain) {
|
|
131
154
|
if (!registered.get(key)?.connections.size) plain(`${key}/persistence/connection.ts`, `The ${kinds.name} capability has entities or migrations but no app registers them; add ${camel(kinds.name)}Entities and ${camel(kinds.name)}Migrations to a connection of DatabaseModule.register and of the cli app.`, { capability: kinds.name });
|
|
132
155
|
const connectionFile = graph.files.get(`${key}/persistence/connection.ts`);
|
|
@@ -160,6 +183,7 @@ function reportFoundCapability(input, kit, key, kinds, view) {
|
|
|
160
183
|
const { registered, connections, plain, report } = view;
|
|
161
184
|
const { graph } = input;
|
|
162
185
|
const { resolver } = kit;
|
|
186
|
+
if (view.lite) { reportLiteEntityArrays(key, kinds, graph, kit.ts, plain); return; }
|
|
163
187
|
reportDeclaredPersistenceArrays(key, kinds, registered, graph, kit.ts, plain);
|
|
164
188
|
const only = registered.get(key)?.connections;
|
|
165
189
|
if (!only || only.size < 1) return;
|
|
@@ -170,7 +194,7 @@ function reportFoundCapability(input, kit, key, kinds, view) {
|
|
|
170
194
|
}
|
|
171
195
|
|
|
172
196
|
function reportFoundCapabilities(input, kit, found, registered, connections, plain, report) {
|
|
173
|
-
const view = { registered, connections, plain, report };
|
|
197
|
+
const view = { registered, connections, plain, report, lite: kit.resolver.repo?.edition === 'lite' };
|
|
174
198
|
for (const [key, kinds] of found) reportFoundCapability(input, kit, key, kinds, view);
|
|
175
199
|
}
|
|
176
200
|
|
|
@@ -178,7 +202,7 @@ function reportPersistenceExport(capabilityRoot, index, statement, element, want
|
|
|
178
202
|
const from = statement.moduleSpecifier?.text;
|
|
179
203
|
const inPersistence = from?.startsWith('.') && path.posix.join(capabilityRoot, from).split('/').includes('persistence');
|
|
180
204
|
if (inPersistence && !Object.values(wanted).includes(element.name.text)) {
|
|
181
|
-
report(index, element, `${element.name.text} is exported from persistence/; the persistence of a capability is exposed only as ${wanted.
|
|
205
|
+
report(index, element, `${element.name.text} is exported from persistence/; the persistence of a capability is exposed only as ${Object.values(wanted).join(' and ')}.`, { name: element.name.text });
|
|
182
206
|
}
|
|
183
207
|
}
|
|
184
208
|
|
|
@@ -204,10 +228,11 @@ function reportCapabilityIndex(input, kit, capabilityRoot, kinds, report) {
|
|
|
204
228
|
const { graph } = input;
|
|
205
229
|
const index = graph.files.get(`${capabilityRoot}/index.ts`);
|
|
206
230
|
if (!index) return;
|
|
207
|
-
const
|
|
231
|
+
const lite = kit.resolver.repo?.edition === 'lite';
|
|
232
|
+
const wanted = lite ? { Entities: `${camel(kinds.name)}Entities` } : { Entities: `${camel(kinds.name)}Entities`, Migrations: `${camel(kinds.name)}Migrations` };
|
|
208
233
|
const exported = collectIndexExports(kit, capabilityRoot, index, wanted, report);
|
|
209
234
|
for (const [kind, has] of [['Entities', kinds.entities], ['Migrations', kinds.migrations]]) {
|
|
210
|
-
if (has && !exported.has(wanted[kind])) report(index, index.sourceFile, `${capabilityRoot}/index.ts must export ${wanted[kind]}, the ${kind.toLowerCase()} of the capability; apps concatenate them per connection into DatabaseModule.register.`, { capability: kinds.name, expected: wanted[kind] });
|
|
235
|
+
if (has && wanted[kind] && !exported.has(wanted[kind])) report(index, index.sourceFile, `${capabilityRoot}/index.ts must export ${wanted[kind]}, the ${kind.toLowerCase()} of the capability; apps concatenate them per connection into DatabaseModule.register.`, { capability: kinds.name, expected: wanted[kind] });
|
|
211
236
|
}
|
|
212
237
|
}
|
|
213
238
|
|
|
@@ -7,7 +7,7 @@ import { sourceLocation } from '../../lib/ts-ast.mjs';
|
|
|
7
7
|
* - FE_SERVER_ACTION_FORBIDDEN: a `"use server"` directive anywhere in a front-end source file, in the file's directive prologue
|
|
8
8
|
* (a Server Action module) or in the prologue of any function body (an inline Server Action), apps and packages alike;
|
|
9
9
|
* - FE_ROUTE_HANDLER_FORBIDDEN: a route handler (`route.ts`, `route.js` and their module variants) under `apps/<app>/src/app/` other than the
|
|
10
|
-
* liveness probe `health/live/route.ts
|
|
10
|
+
* liveness probe `health/live/route.ts`.
|
|
11
11
|
*
|
|
12
12
|
* The check is provider-independent: it runs for every front-end repository.
|
|
13
13
|
*/
|
|
@@ -15,7 +15,6 @@ export const SERVER_ACTION_RULE_IDS = Object.freeze(['FE_SERVER_ACTION_FORBIDDEN
|
|
|
15
15
|
|
|
16
16
|
const SERVER_ACTION = 'FE_SERVER_ACTION_FORBIDDEN';
|
|
17
17
|
const ROUTE_HANDLER = 'FE_ROUTE_HANDLER_FORBIDDEN';
|
|
18
|
-
const CALLBACK_SLOT = 'fe.route.callback';
|
|
19
18
|
const ROUTE_FILE = /^apps\/([^/]+)\/src\/app\/(?:.+\/)?route\.[cm]?[jt]s$/u;
|
|
20
19
|
|
|
21
20
|
/** The statement nodes of a directive prologue: the leading string-literal expression statements. */
|
|
@@ -57,10 +56,10 @@ function serverActionViolations(ts, file) {
|
|
|
57
56
|
function routeHandlerViolation(file) {
|
|
58
57
|
const match = ROUTE_FILE.exec(file.rel);
|
|
59
58
|
if (!match) return null;
|
|
60
|
-
if (file.rel === `apps/${match[1]}/src/app/health/live/route.ts`
|
|
59
|
+
if (file.rel === `apps/${match[1]}/src/app/health/live/route.ts`) return null;
|
|
61
60
|
return {
|
|
62
61
|
ruleId: ROUTE_HANDLER, path: file.rel, line: 1, column: 1,
|
|
63
|
-
message: `${file.rel} is a front-end route handler outside health/live/route.ts
|
|
62
|
+
message: `${file.rel} is a front-end route handler outside health/live/route.ts: the front end serves no API. Webhooks, cron, public APIs and third-party callbacks belong to be features; the browser reaches the back end through modules/api.`,
|
|
64
63
|
};
|
|
65
64
|
}
|
|
66
65
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// side-boundary.mjs - what counts as an import that leaves a side of an app (ARCH_INTERNAL_IMPORT_OUTSIDE).
|
|
2
2
|
// A side (be/ or fe/) imports nothing of the app outside itself: the root holds no source and the other side is another program; a
|
|
3
3
|
// declared read of the OTHER side (be/contracts/) is codegen input, never an import. A declared read of a tree the APP ROOT owns
|
|
4
|
-
// (
|
|
4
|
+
// (db/types/, sides.<side>.reads of the slot manifest) is the one thing both sides do import: the generated database types.
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { isInside, slash } from './config.mjs';
|
|
7
7
|
|
|
@@ -248,7 +248,7 @@ function activeMigrations(root) {
|
|
|
248
248
|
* Public-table key sets proven by ordered, tracked active migrations. Direct event triggers taint later DDL proof.
|
|
249
249
|
* Opaque bodies discard current facts; persistent schema machinery hidden inside them is outside static authority.
|
|
250
250
|
*/
|
|
251
|
-
export function
|
|
251
|
+
export function sqlUniqueSetsOf(appRoot) {
|
|
252
252
|
const root = path.resolve(appRoot);
|
|
253
253
|
const files = activeMigrations(root);
|
|
254
254
|
const state = { tables: new Map(), safe: new Set(), schema: 'public', tainted: false };
|