@starci/eslint-canon-fe 9.4.7 → 9.5.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/CHANGELOG.md +15 -0
- package/dist/fe-stack.d.ts +3 -3
- package/dist/fe-stack.js +3 -9
- package/dist/index.js +0 -2
- package/dist/lib/scope.d.ts +8 -0
- package/dist/lib/scope.js +10 -0
- package/dist/lib/why.js +2 -2
- package/dist/shape-slot.d.ts +2 -2
- package/dist/transport.d.ts +1 -1
- package/dist/transport.js +29 -7
- package/package.json +1 -1
- package/runtime/knowledge/hfs/canon-pins.yaml +54 -24
- package/runtime/knowledge/hfs/fe-stack.yaml +4 -11
- package/runtime/knowledge/hfs/slots.yaml +185 -174
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +1 -1
- 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/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/transport-owner.mjs +7 -3
- package/runtime/scripts/hfs/declaration-shape.mjs +15 -18
- package/runtime/scripts/hfs/manifest-shape.mjs +4 -4
- 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/dist/callback-shape.d.ts +0 -7
- package/dist/callback-shape.js +0 -396
- package/dist/lib/pure-owner-helper.d.ts +0 -10
- package/dist/lib/pure-owner-helper.js +0 -156
- package/runtime/scripts/hfs/architecture/supabase-tables.mjs +0 -50
- package/runtime/scripts/hfs/architecture/supabase.mjs +0 -226
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
import { machineKit } from './machine-ast.mjs';
|
|
2
|
-
import { callName, chainParts, contextTypesClient, isDatabaseType, isSupabaseCall, jwtPolicyProblems, moduleNameOf, reportAt, supabaseClientType, supabaseDataAccess, SUPABASE_MODULES } from './supabase-ast.mjs';
|
|
3
|
-
import { checkBackendJwt } from './supabase-be.mjs';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* L10-L16, the slot-driven Supabase machine. On the back end Supabase provides Auth/Storage with one owner,
|
|
7
|
-
* `be.integrations.supabase`. On the front end Supabase is auth only (owner ruling 2026-10-13): `fe.modules.auth` is the one
|
|
8
|
-
* importer of `@supabase/*` and calls only the auth API; data, storage, rpc and realtime go through the back end (modules/api).
|
|
9
|
-
* The checks below recognise provider calls and types by their imported package declarations, not by local variable or type names.
|
|
10
|
-
*/
|
|
11
|
-
export const FRONTEND_SUPABASE_RULE_IDS = Object.freeze(['FE_SUPABASE_CLIENT_OWNER', 'FE_SERVICE_ROLE_FORBIDDEN']);
|
|
12
|
-
export const BACKEND_SUPABASE_RULE_IDS = Object.freeze(['BE_SUPABASE_CLIENT_OWNER', 'BE_SUPABASE_JWT_VERIFIED', 'BE_JWT_ALG_PINNED']);
|
|
13
|
-
|
|
14
|
-
const FE_CLIENT_OWNER = 'FE_SUPABASE_CLIENT_OWNER';
|
|
15
|
-
const BE_CLIENT_OWNER = 'BE_SUPABASE_CLIENT_OWNER';
|
|
16
|
-
const FE_SERVICE_ROLE = 'FE_SERVICE_ROLE_FORBIDDEN';
|
|
17
|
-
const BE_SUPABASE_SLOT = 'be.integrations.supabase';
|
|
18
|
-
const FE_AUTH_SLOT = 'fe.modules.auth';
|
|
19
|
-
/** The front-end provider slot: enabled exactly when a connection declares provider supabase. */
|
|
20
|
-
const FE_SUPABASE_PROVIDER_SLOT = 'fe.route.callback';
|
|
21
|
-
const FE_CONFIG_SLOT = 'fe.modules.config';
|
|
22
|
-
const BE_DATA_MEMBERS = new Set(['from', 'rpc', 'schema', 'functions', 'channel', 'realtime', 'getChannels', 'removeChannel', 'removeAllChannels']);
|
|
23
|
-
/** The members of a Supabase client that read or write data, files or channels: never called from the front end. */
|
|
24
|
-
const FE_DATA_MEMBERS = new Set(['from', 'rpc', 'schema', 'storage', 'functions', 'realtime', 'channel', 'getChannels', 'removeChannel', 'removeAllChannels']);
|
|
25
|
-
const supabaseSlotEnabled = (input, slotId) => {
|
|
26
|
-
const slot = input.graph.resolver.slot(slotId);
|
|
27
|
-
return Boolean(slot && input.graph.resolver.slotEnabled(slot));
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const CLIENT_FACTORY = /^create(?:Client|ServerClient|BrowserClient)$/u;
|
|
31
|
-
|
|
32
|
-
function inspectSupabaseImport(scope, node) {
|
|
33
|
-
const { kit, file, slots, ruleId, violations, counters } = scope;
|
|
34
|
-
const moduleName = moduleNameOf(kit.ts, node);
|
|
35
|
-
if (!moduleName || !SUPABASE_MODULES.has(moduleName)) return;
|
|
36
|
-
counters.imports += 1;
|
|
37
|
-
if (!slots.has(file.slot)) reportAt(violations, kit, ruleId, file, node, `${moduleName} is imported by ${file.rel}, whose slot is ${file.slot ?? 'unowned'}; Supabase imports belong only to ${[...slots].join(' or ')}.`, { module: moduleName, slot: file.slot ?? null });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function inspectClientTypeReference(scope, node) {
|
|
41
|
-
const { kit, checker, file, ruleId, violations, counters } = scope;
|
|
42
|
-
if (!kit.ts.isTypeReferenceNode(node) || !supabaseClientType(kit, checker, node)) return;
|
|
43
|
-
counters.clients += 1;
|
|
44
|
-
if (!isDatabaseType(kit.ts, node.typeArguments?.[0])) reportAt(violations, kit, ruleId, file, node, 'SupabaseClient must carry the committed Database type as SupabaseClient<Database>.');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function inspectClientFactoryCall(scope, node) {
|
|
48
|
-
const { kit, checker, file, ruleId, violations, counters } = scope;
|
|
49
|
-
const binding = kit.importBinding(checker, node.expression);
|
|
50
|
-
if (!binding || !SUPABASE_MODULES.has(binding.module) || !CLIENT_FACTORY.test(binding.name)) return;
|
|
51
|
-
counters.clients += 1;
|
|
52
|
-
if (!isDatabaseType(kit.ts, node.typeArguments?.[0]) && !contextTypesClient(kit, checker, node)) {
|
|
53
|
-
reportAt(violations, kit, ruleId, file, node, `${binding.name} creates an untyped Supabase client; create it as ${binding.name}<Database>(...) (or give it the contextual type SupabaseClient<Database>).`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function inspectProviderCall(scope, node) {
|
|
58
|
-
const { kit, checker, file, slots, ruleId, violations, counters, reportedData } = scope;
|
|
59
|
-
const { ts } = kit;
|
|
60
|
-
const data = supabaseDataAccess(kit, checker, node, BE_DATA_MEMBERS, { storageAllowed: true });
|
|
61
|
-
if (data) {
|
|
62
|
-
if (!reportedData.has(data.node.pos)) {
|
|
63
|
-
reportedData.add(data.node.pos);
|
|
64
|
-
reportAt(violations, kit, ruleId, file, data.node, `A Supabase .${data.name} data call is made from ${file.slot ?? 'an unowned path'}; the back-end SDK is Auth/Storage only, including inside ${BE_SUPABASE_SLOT}. Data uses EntityManager as app_be.`, { member: data.name, slot: file.slot ?? null });
|
|
65
|
-
}
|
|
66
|
-
if (ts.isCallExpression(node)) counters.calls += 1;
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
if (!isSupabaseCall(kit, checker, node)) return;
|
|
70
|
-
const properties = chainParts(ts, node);
|
|
71
|
-
const method = callName(ts, node);
|
|
72
|
-
if (!properties.includes('auth') && !properties.includes('storage')) return;
|
|
73
|
-
counters.calls += 1;
|
|
74
|
-
if (!slots.has(file.slot)) reportAt(violations, kit, ruleId, file, node, `A Supabase ${method ?? 'client'} call is made from ${file.slot ?? 'an unowned path'}; database, auth and storage calls belong only to ${[...slots].join(' or ')}.`, { method, slot: file.slot ?? null });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function inspectOwnershipNode(scope, node) {
|
|
78
|
-
inspectSupabaseImport(scope, node);
|
|
79
|
-
inspectClientTypeReference(scope, node);
|
|
80
|
-
const { ts } = scope.kit;
|
|
81
|
-
if (!ts.isCallExpression(node) && !ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node)) return;
|
|
82
|
-
if (ts.isCallExpression(node)) inspectClientFactoryCall(scope, node);
|
|
83
|
-
inspectProviderCall(scope, node);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function checkClientOwnership(input, { slots, ruleId }) {
|
|
87
|
-
const kit = machineKit(input);
|
|
88
|
-
const violations = [];
|
|
89
|
-
const counters = { imports: 0, clients: 0, calls: 0 };
|
|
90
|
-
for (const file of input.graph.files.values()) {
|
|
91
|
-
const checker = kit.checkerOf(file.sourceFile);
|
|
92
|
-
const scope = { kit, checker, file, slots, ruleId, violations, counters, reportedData: new Set() };
|
|
93
|
-
kit.walk(file.sourceFile, node => inspectOwnershipNode(scope, node));
|
|
94
|
-
}
|
|
95
|
-
return { violations, coverage: { status: 'checked', ...counters, ownerSlots: [...slots] } };
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const words = text => String(text).replace(/([a-z0-9])([A-Z])/gu, '$1_$2').toUpperCase();
|
|
99
|
-
const serviceRoleText = text => /(?:^|[^A-Z0-9])SERVICE[_ -]?ROLE(?:[^A-Z0-9]|$)/iu.test(words(text));
|
|
100
|
-
const credentialEnv = name => /(?:^|_)(?:SECRET|PRIVATE|TOKEN|PASSWORD)$/u.test(name) || /(?:^|_)SERVICE_ROLE(?:_|$)/u.test(name);
|
|
101
|
-
const CORE_PUBLIC_ENV = new Set(['NEXT_PUBLIC_SUPABASE_URL', 'NEXT_PUBLIC_SUPABASE_ANON_KEY', 'NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY', 'NEXT_PUBLIC_SITE_URL']);
|
|
102
|
-
|
|
103
|
-
const envRead = (ts, node) => {
|
|
104
|
-
if (!ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node)) return null;
|
|
105
|
-
const object = node.expression;
|
|
106
|
-
const processEnv = ts.isPropertyAccessExpression(object) && ts.isIdentifier(object.expression) && object.expression.text === 'process' && object.name.text === 'env';
|
|
107
|
-
const importMetaEnv = ts.isPropertyAccessExpression(object) && object.name.text === 'env' && object.expression.kind === ts.SyntaxKind.MetaProperty;
|
|
108
|
-
if (!processEnv && !importMetaEnv) return null;
|
|
109
|
-
if (ts.isPropertyAccessExpression(node)) return node.name.text;
|
|
110
|
-
return ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : null;
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/** Reports a SERVICE_ROLE identifier or string literal: the browser and Next process never hold the service role. */
|
|
114
|
-
function inspectServiceRoleText(ts, node, report) {
|
|
115
|
-
if (ts.isIdentifier(node) && serviceRoleText(node.text)) report(node, 'A SERVICE_ROLE identifier appears in the front end; the browser and Next process never hold the Supabase service role.', node.text);
|
|
116
|
-
if (ts.isStringLiteralLike(node) && serviceRoleText(node.text)) report(node, 'A service_role string appears in the front end; the service role belongs behind the back-end guard chain.', node.text);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** Counts an environment read and reports a credential-shaped or product-specific public variable. */
|
|
120
|
-
function inspectEnvironmentRead(state, file, node, name) {
|
|
121
|
-
state.reads += 1;
|
|
122
|
-
if (credentialEnv(name)) state.report(node, `${name} is a credential-shaped environment read in the front end; no *_SECRET, *_PRIVATE, *_TOKEN, *_PASSWORD or service-role value enters fe/.`, name);
|
|
123
|
-
else if (name.startsWith('NEXT_PUBLIC_') && !CORE_PUBLIC_ENV.has(name) && file.slot !== FE_CONFIG_SLOT) {
|
|
124
|
-
state.report(node, `${name} is not a core Supabase/site public variable and is read outside ${FE_CONFIG_SLOT}; product public configuration is declared by the one config owner.`, name);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function checkFrontendSecretNames(input) {
|
|
129
|
-
const kit = machineKit(input);
|
|
130
|
-
const { ts } = kit;
|
|
131
|
-
const violations = [];
|
|
132
|
-
const state = { reads: 0, report: null };
|
|
133
|
-
for (const file of input.graph.files.values()) {
|
|
134
|
-
const seen = new Set();
|
|
135
|
-
state.report = (node, message, name) => {
|
|
136
|
-
const key = `${node.pos}:${name ?? ''}`;
|
|
137
|
-
if (seen.has(key)) return;
|
|
138
|
-
seen.add(key);
|
|
139
|
-
reportAt(violations, kit, FE_SERVICE_ROLE, file, node, message, name ? { name } : {});
|
|
140
|
-
};
|
|
141
|
-
kit.walk(file.sourceFile, node => {
|
|
142
|
-
inspectServiceRoleText(ts, node, state.report);
|
|
143
|
-
const name = envRead(ts, node);
|
|
144
|
-
if (name) inspectEnvironmentRead(state, file, node, name);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
return { violations, coverage: { status: 'checked', envReads: state.reads } };
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function inspectFrontendNode(scope, node) {
|
|
151
|
-
const { kit, checker, file, violations, counters, reportedData } = scope;
|
|
152
|
-
const { ts } = kit;
|
|
153
|
-
const moduleName = moduleNameOf(ts, node);
|
|
154
|
-
if (moduleName?.startsWith('@supabase/')) {
|
|
155
|
-
counters.imports += 1;
|
|
156
|
-
if (file.slot !== FE_AUTH_SLOT) reportAt(violations, kit, FE_CLIENT_OWNER, file, node, `${moduleName} is imported by ${file.rel}, whose slot is ${file.slot ?? 'unowned'}; on the front end Supabase is auth only and ${FE_AUTH_SLOT} (modules/auth) is its one importer.`, { module: moduleName, slot: file.slot ?? null });
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (!ts.isCallExpression(node) && !ts.isPropertyAccessExpression(node) && !ts.isElementAccessExpression(node)) return;
|
|
160
|
-
const data = supabaseDataAccess(kit, checker, node, FE_DATA_MEMBERS);
|
|
161
|
-
if (data) {
|
|
162
|
-
if (!reportedData.has(data.node.pos)) {
|
|
163
|
-
reportedData.add(data.node.pos);
|
|
164
|
-
reportAt(violations, kit, FE_CLIENT_OWNER, file, data.node, `A Supabase .${data.name} call is made from the front end; Supabase on the front end is auth only - read and write data, files and realtime through the back end (a modules/api GraphQL operation, an SWR hook, hooks/socketio).`, { member: data.name, slot: file.slot ?? null });
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (!isSupabaseCall(kit, checker, node)) return;
|
|
169
|
-
counters.calls += 1;
|
|
170
|
-
const parts = chainParts(ts, node);
|
|
171
|
-
if (file.slot !== FE_AUTH_SLOT && parts.includes('auth')) reportAt(violations, kit, FE_CLIENT_OWNER, file, node, `A Supabase auth call is made from ${file.slot ?? 'an unowned path'}; the auth client is called only inside ${FE_AUTH_SLOT}, which exports the session and the access token.`, { slot: file.slot ?? null });
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function checkFrontendClientOwner(input) {
|
|
175
|
-
const kit = machineKit(input);
|
|
176
|
-
const violations = [];
|
|
177
|
-
const counters = { imports: 0, calls: 0 };
|
|
178
|
-
for (const file of input.graph.files.values()) {
|
|
179
|
-
const scope = { kit, checker: kit.checkerOf(file.sourceFile), file, violations, counters, reportedData: new Set() };
|
|
180
|
-
kit.walk(file.sourceFile, node => inspectFrontendNode(scope, node));
|
|
181
|
-
}
|
|
182
|
-
return { violations, coverage: { status: 'checked', ...counters, ownerSlots: [FE_AUTH_SLOT] } };
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function checkFrontendSupabase(input) {
|
|
186
|
-
const owner = checkFrontendClientOwner(input);
|
|
187
|
-
if (!supabaseSlotEnabled(input, FE_SUPABASE_PROVIDER_SLOT)) return {
|
|
188
|
-
violations: owner.violations,
|
|
189
|
-
coverage: { status: owner.coverage.imports || owner.coverage.calls || owner.violations.length ? 'checked' : 'not-applicable', owner: owner.coverage, reason: 'no connection declares provider supabase; SDK ownership is still checked' },
|
|
190
|
-
};
|
|
191
|
-
const secrets = checkFrontendSecretNames(input);
|
|
192
|
-
return {
|
|
193
|
-
violations: [...owner.violations, ...secrets.violations],
|
|
194
|
-
coverage: { status: 'checked', owner: owner.coverage, secrets: secrets.coverage },
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export function checkBackendSupabase(input) {
|
|
199
|
-
const owner = checkClientOwnership(input, { slots: new Set([BE_SUPABASE_SLOT]), ruleId: BE_CLIENT_OWNER });
|
|
200
|
-
if (!supabaseSlotEnabled(input, BE_SUPABASE_SLOT)) return {
|
|
201
|
-
violations: owner.violations,
|
|
202
|
-
coverage: { status: owner.coverage.imports || owner.coverage.calls || owner.violations.length ? 'checked' : 'not-applicable', owner: owner.coverage, reason: 'the Supabase integration slot is disabled; SDK ownership is still checked' },
|
|
203
|
-
};
|
|
204
|
-
const jwt = checkBackendJwt(input);
|
|
205
|
-
const policy = checkJwtPolicy(input);
|
|
206
|
-
return {
|
|
207
|
-
violations: [...owner.violations, ...jwt.violations, ...policy.violations],
|
|
208
|
-
coverage: { status: 'checked', owner: owner.coverage, jwt: jwt.coverage, jwtPolicy: policy.coverage },
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
export function checkJwtPolicy(input) {
|
|
213
|
-
const kit = machineKit(input);
|
|
214
|
-
const violations = [];
|
|
215
|
-
let verifyCalls = 0;
|
|
216
|
-
for (const file of input.graph.files.values()) {
|
|
217
|
-
const checker = kit.checkerOf(file.sourceFile);
|
|
218
|
-
kit.walk(file.sourceFile, node => {
|
|
219
|
-
if (!kit.ts.isCallExpression(node) || !kit.isImportOf(checker, node.expression, 'jwtVerify', 'jose')) return;
|
|
220
|
-
verifyCalls += 1;
|
|
221
|
-
const problems = jwtPolicyProblems(kit.ts, checker, node);
|
|
222
|
-
if (problems.length) reportAt(violations, kit, 'BE_JWT_ALG_PINNED', file, node, problems.join(' '));
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return { violations, coverage: { status: 'checked', verifyCalls } };
|
|
226
|
-
}
|