@sixbell-telco/sdk-tools 0.0.0-stage → 0.1.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 +32 -0
- package/README.md +277 -2
- package/data/security-floors.json +47 -0
- package/package.json +43 -4
- package/recipes/README.md +53 -0
- package/recipes/crud-list.md +21 -0
- package/recipes/custom-component.md +35 -0
- package/recipes/detail-page.md +19 -0
- package/recipes/form-dialog.md +17 -0
- package/recipes/parts/crud-list/i18n.json +83 -0
- package/recipes/parts/crud-list/src/app/features/__name__/__name__.routes.ts.tpl +30 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.html.tpl +102 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.spec.ts.tpl +101 -0
- package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.ts.tpl +143 -0
- package/recipes/parts/detail-page/i18n.json +32 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.html.tpl +35 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.spec.ts.tpl +58 -0
- package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.ts.tpl +68 -0
- package/recipes/parts/entity/i18n.json +5 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.model.ts.tpl +9 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.spec.ts.tpl +29 -0
- package/recipes/parts/entity/src/app/features/__name__/__name__.service.ts.tpl +33 -0
- package/recipes/parts/form-dialog/i18n.json +35 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.html.tpl +33 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.spec.ts.tpl +69 -0
- package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.ts.tpl +73 -0
- package/src/add/add.mjs +251 -0
- package/src/check/config.mjs +112 -0
- package/src/check/exceptions.mjs +103 -0
- package/src/check/federation.mjs +224 -0
- package/src/check/finding.mjs +23 -0
- package/src/check/harness.mjs +146 -0
- package/src/check/i18n.mjs +218 -0
- package/src/check/integration.mjs +566 -0
- package/src/check/security.mjs +165 -0
- package/src/check/steps.mjs +37 -0
- package/src/check/styles.mjs +347 -0
- package/src/check/wiring.mjs +198 -0
- package/src/check.mjs +333 -0
- package/src/cli.mjs +551 -0
- package/src/docs/docs.mjs +154 -0
- package/src/doctor/doctor.mjs +492 -0
- package/src/format.mjs +102 -0
- package/src/info/info.mjs +149 -0
- package/src/init/init.mjs +490 -0
- package/src/init/merge.mjs +191 -0
- package/src/init/template.mjs +292 -0
- package/src/mcp/catalog.mjs +248 -0
- package/src/mcp/glossary.mjs +75 -0
- package/src/mcp/manifest.mjs +53 -0
- package/src/mcp/recipes.mjs +198 -0
- package/src/mcp/server.mjs +249 -0
- package/src/mcp/upgrade-guide.mjs +116 -0
- package/src/mcp/usage.mjs +48 -0
- package/src/project/project.mjs +220 -0
- package/src/types.d.ts +448 -0
- package/src/upgrade/lockstep.mjs +153 -0
- package/src/upgrade/upgrade.mjs +623 -0
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `sdk-tools check --integration --root <dir>`: the cross-repo wiring between a host, its children
|
|
3
|
+
* and the integration (deploy) repos under one directory, with the mfe-tools ids MFE_INT_001..010
|
|
4
|
+
* and MFE_INT_ASSET_001..004. File-based only: no network, no browser, no git.
|
|
5
|
+
*
|
|
6
|
+
* Repos are found by walking `<dir>`: an Angular app is read with the shared project reader (its
|
|
7
|
+
* role says host or child), an integration repo is a folder with `web/` and a compose file (or a
|
|
8
|
+
* served `web/federation`, `web/translation` or `web/themes`), a database repo is a `database`,
|
|
9
|
+
* `db` or `*-db` folder. An integration or database repo belongs to the apps under its parent
|
|
10
|
+
* folder (productos/irp/web/integration serves productos/irp/web/frontend/...).
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readdirSync, realpathSync, statSync } from 'node:fs';
|
|
13
|
+
import { basename, dirname, join, relative, sep } from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { readJson, readProject, readText, walk } from '../project/project.mjs';
|
|
16
|
+
import { applyExceptions } from './exceptions.mjs';
|
|
17
|
+
import { finding, position } from './finding.mjs';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @typedef {import('../types.js').Finding} Finding
|
|
21
|
+
* @typedef {import('../types.js').ExceptedFinding} ExceptedFinding
|
|
22
|
+
* @typedef {import('../types.js').CheckResult} CheckResult
|
|
23
|
+
* @typedef {import('../types.js').ProjectInfo} ProjectInfo
|
|
24
|
+
* @typedef {{ root: string, rel: string }} Repo
|
|
25
|
+
* @typedef {Repo & { project: ProjectInfo }} AppRepo
|
|
26
|
+
* @typedef {{ apps: AppRepo[], integrations: Repo[], databases: Repo[] }} Repos
|
|
27
|
+
* @typedef {{ remote: string, module: string, file: string, line: number, column: number }} RemoteLoad
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const HOST_MANIFEST = 'src/assets/federation/federation.manifest.json';
|
|
31
|
+
const CHILD_CONFIG = 'src/assets/configuration/mfe_config.json';
|
|
32
|
+
const INTEGRATION_MANIFEST = 'web/federation/federation.manifest.json';
|
|
33
|
+
const INTEGRATION_TRANSLATION = 'web/translation/translation.json';
|
|
34
|
+
const TRANSLATION_FILES = [INTEGRATION_TRANSLATION, 'config/translation/translation.json'];
|
|
35
|
+
const THEMES = 'web/themes/themes.json';
|
|
36
|
+
const COMPOSE_FILES = ['docker-compose.yml', 'docker-compose.yaml', 'compose.yml', 'compose.yaml'];
|
|
37
|
+
const PROXY_FILES = ['proxy-config.json.example', 'proxy-config.json'];
|
|
38
|
+
const SERVED = new Set(['federation', 'translation', 'themes', 'config']);
|
|
39
|
+
const SKIPPED = new Set(['node_modules', 'dist', 'coverage', 'build', 'target', 'tmp', 'log', 'logs']);
|
|
40
|
+
const MAX_DEPTH = 6;
|
|
41
|
+
const BANNER_NAMES = new Set([
|
|
42
|
+
'banner',
|
|
43
|
+
'cherry-banner',
|
|
44
|
+
'green-banner',
|
|
45
|
+
'ground-banner',
|
|
46
|
+
'network-banner',
|
|
47
|
+
'pastel-banner',
|
|
48
|
+
'purple-network',
|
|
49
|
+
'red-network-banner',
|
|
50
|
+
'valentine-banner',
|
|
51
|
+
]);
|
|
52
|
+
const BANNER_TONE_HINT =
|
|
53
|
+
'st-page-banner reads the catalog tone to pick the title color; without it a dark banner can get a dark title. Declare tone { light, dark } ("light" or "dark") on every banner asset.';
|
|
54
|
+
|
|
55
|
+
/** @param {string} path */
|
|
56
|
+
const isDir = (path) => {
|
|
57
|
+
try {
|
|
58
|
+
return statSync(path).isDirectory();
|
|
59
|
+
} catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** @param {string} dir */
|
|
65
|
+
const isApp = (dir) => ['angular.json', 'federation.config.js', 'mfe-foundation.config.json'].some((file) => existsSync(join(dir, file)));
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* An integration repo serves the web apps from `web/`: the host's federation, translation, themes
|
|
69
|
+
* or config folders, or a remote's `web/mfe-*` folder (a plain static site under web/ is not one).
|
|
70
|
+
* @param {string} dir
|
|
71
|
+
*/
|
|
72
|
+
const isIntegration = (dir) =>
|
|
73
|
+
readdirSafe(join(dir, 'web')).some((name) => (SERVED.has(name) || name.startsWith('mfe-')) && isDir(join(dir, 'web', name)));
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* A database repo: a `database`, `db` or `*-db` folder that holds SQL scripts.
|
|
77
|
+
* @param {string} dir
|
|
78
|
+
*/
|
|
79
|
+
const isDatabase = (dir) => /^(?:database|db)$|-db$/.test(basename(dir)) && walk(dir, '.', (file) => file.endsWith('.sql')).length > 0;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The repos under `root`. A found repo is not searched further.
|
|
83
|
+
* @param {string} root
|
|
84
|
+
* @returns {Repos}
|
|
85
|
+
*/
|
|
86
|
+
function findRepos(root) {
|
|
87
|
+
/** @type {Repos} */
|
|
88
|
+
const repos = { apps: [], integrations: [], databases: [] };
|
|
89
|
+
/** @type {Set<string>} */
|
|
90
|
+
const seen = new Set();
|
|
91
|
+
/**
|
|
92
|
+
* @param {string} dir
|
|
93
|
+
* @param {number} depth
|
|
94
|
+
*/
|
|
95
|
+
const visit = (dir, depth) => {
|
|
96
|
+
let real;
|
|
97
|
+
try {
|
|
98
|
+
real = realpathSync(dir);
|
|
99
|
+
} catch {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (seen.has(real)) return;
|
|
103
|
+
seen.add(real);
|
|
104
|
+
const rel = relative(root, dir).split(sep).join('/') || '.';
|
|
105
|
+
if (isApp(dir)) {
|
|
106
|
+
const project = readProject(dir);
|
|
107
|
+
if (project.role) repos.apps.push({ root: dir, rel, project });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (isIntegration(dir)) return void repos.integrations.push({ root: dir, rel });
|
|
111
|
+
if (depth > 0 && isDatabase(dir)) return void repos.databases.push({ root: dir, rel });
|
|
112
|
+
if (depth >= MAX_DEPTH) return;
|
|
113
|
+
let names;
|
|
114
|
+
try {
|
|
115
|
+
names = readdirSync(dir).sort();
|
|
116
|
+
} catch {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
for (const name of names) {
|
|
120
|
+
if (name.startsWith('.') || SKIPPED.has(name)) continue;
|
|
121
|
+
const path = join(dir, name);
|
|
122
|
+
if (isDir(path)) visit(path, depth + 1);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
visit(root, 0);
|
|
126
|
+
return repos;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* True when `repo` (an integration or database repo) belongs to `app`: the app sits under the
|
|
131
|
+
* repo's parent folder. A repo at the root itself belongs to nothing found beside it.
|
|
132
|
+
* @param {Repo} repo
|
|
133
|
+
* @param {Repo} app
|
|
134
|
+
*/
|
|
135
|
+
const belongsTo = (repo, app) => repo.rel !== '.' && app.root.startsWith(dirname(repo.root) + sep);
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* `loadRemoteModule('name', './Module')` and `loadRemoteModule({ remoteName, exposedModule })`
|
|
139
|
+
* calls in the app's TypeScript (specs left out).
|
|
140
|
+
* @param {string} root
|
|
141
|
+
* @returns {RemoteLoad[]}
|
|
142
|
+
*/
|
|
143
|
+
function remoteLoads(root) {
|
|
144
|
+
/** @type {RemoteLoad[]} */
|
|
145
|
+
const loads = [];
|
|
146
|
+
for (const file of walk(root, 'src', (path) => path.endsWith('.ts') && !path.endsWith('.spec.ts'))) {
|
|
147
|
+
const text = readText(root, file) ?? '';
|
|
148
|
+
if (!text.includes('loadRemoteModule')) continue;
|
|
149
|
+
for (const match of text.matchAll(/loadRemoteModule\(\s*(?:['"`]([^'"`]+)['"`]\s*,\s*['"`]([^'"`]+)['"`]|\{([^}]*)\})/g)) {
|
|
150
|
+
const remote = match[1] ?? /remoteName\s*:\s*['"`]([^'"`]+)['"`]/.exec(match[3] ?? '')?.[1];
|
|
151
|
+
const module = match[2] ?? /exposedModule\s*:\s*['"`]([^'"`]+)['"`]/.exec(match[3] ?? '')?.[1];
|
|
152
|
+
if (remote && module) loads.push({ remote, module, file, ...position(text, match.index) });
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return loads;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The first path segment of a relative remoteEntry URL (`/mfe-audit/remoteEntry.json` → mfe-audit),
|
|
160
|
+
* or null for an absolute URL.
|
|
161
|
+
* @param {unknown} url
|
|
162
|
+
*/
|
|
163
|
+
const urlSegment = (url) => (typeof url === 'string' && url.startsWith('/') ? (url.split('/')[1] ?? null) : null);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {string} rule
|
|
167
|
+
* @param {Repo} repo
|
|
168
|
+
* @param {string} file
|
|
169
|
+
* @param {string} message
|
|
170
|
+
* @param {{ severity?: Finding['severity'], line?: number, column?: number }} [at]
|
|
171
|
+
* @returns {Finding}
|
|
172
|
+
*/
|
|
173
|
+
const repoFinding = (rule, repo, file, message, at) => ({ ...finding(rule, file, message, at), id: rule, repo: repo.rel });
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The child that serves remote `name` (remoteEntry `url`): its federation name is the manifest key
|
|
177
|
+
* or the URL folder, or its integration repo serves that folder (web/<folder>).
|
|
178
|
+
* @param {AppRepo[]} children
|
|
179
|
+
* @param {Repo[]} integrations
|
|
180
|
+
* @param {string} name
|
|
181
|
+
* @param {unknown} url
|
|
182
|
+
*/
|
|
183
|
+
function resolveChild(children, integrations, name, url) {
|
|
184
|
+
const segment = urlSegment(url);
|
|
185
|
+
const byName = children.find((child) => child.project.federation?.name === name || (segment && child.project.federation?.name === segment));
|
|
186
|
+
if (byName) return byName;
|
|
187
|
+
return children.find((child) =>
|
|
188
|
+
integrations.some((repo) => belongsTo(repo, child) && [name, segment].some((folder) => folder && isDir(join(repo.root, 'web', folder)))),
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* JSON with comments and trailing commas (Angular reads proxy configs this way), or null.
|
|
194
|
+
* @param {string} text
|
|
195
|
+
* @returns {any}
|
|
196
|
+
*/
|
|
197
|
+
export function parseJsonc(text) {
|
|
198
|
+
let out = '';
|
|
199
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
200
|
+
const char = text[index];
|
|
201
|
+
if (char === '"') {
|
|
202
|
+
const end = /"(?:[^"\\\n]|\\.)*"/y;
|
|
203
|
+
end.lastIndex = index;
|
|
204
|
+
const string = end.exec(text)?.[0] ?? char;
|
|
205
|
+
out += string;
|
|
206
|
+
index += string.length - 1;
|
|
207
|
+
} else if (char === '/' && text[index + 1] === '/') index = (text.indexOf('\n', index) + 1 || text.length) - 1;
|
|
208
|
+
else if (char === '/' && text[index + 1] === '*') {
|
|
209
|
+
const end = text.indexOf('*/', index + 2);
|
|
210
|
+
index = (end === -1 ? text.length : end + 2) - 1;
|
|
211
|
+
} else out += char;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
return JSON.parse(out.replace(/,(\s*[}\]])/g, '$1'));
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The proxy file the host's developers use: the tracked example when there is one (proxy-config.json
|
|
222
|
+
* itself is usually gitignored), else proxy-config.json.
|
|
223
|
+
* @param {string} root
|
|
224
|
+
*/
|
|
225
|
+
const proxyFile = (root) => PROXY_FILES.find((file) => existsSync(join(root, file))) ?? null;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @param {AppRepo} host
|
|
229
|
+
* @param {Repos} repos
|
|
230
|
+
* @returns {Finding[]}
|
|
231
|
+
*/
|
|
232
|
+
function hostFindings(host, repos) {
|
|
233
|
+
/** @type {Finding[]} */
|
|
234
|
+
const findings = [];
|
|
235
|
+
const children = repos.apps.filter((app) => app.project.role === 'child');
|
|
236
|
+
const manifest = readJson(host.root, HOST_MANIFEST);
|
|
237
|
+
const remotes = manifest && typeof manifest === 'object' && !Array.isArray(manifest) ? /** @type {Record<string, unknown>} */ (manifest) : null;
|
|
238
|
+
const loads = remoteLoads(host.root);
|
|
239
|
+
const loaded = [...new Set(loads.map((load) => load.remote))];
|
|
240
|
+
|
|
241
|
+
if (!remotes)
|
|
242
|
+
findings.push(
|
|
243
|
+
repoFinding(
|
|
244
|
+
'MFE_INT_001',
|
|
245
|
+
host,
|
|
246
|
+
HOST_MANIFEST,
|
|
247
|
+
'The host federation manifest is missing or not a JSON object of remote name to remoteEntry URL.',
|
|
248
|
+
),
|
|
249
|
+
);
|
|
250
|
+
else
|
|
251
|
+
for (const remote of loaded) {
|
|
252
|
+
if (Object.hasOwn(remotes, remote)) continue;
|
|
253
|
+
const load = /** @type {RemoteLoad} */ (loads.find((item) => item.remote === remote));
|
|
254
|
+
findings.push(
|
|
255
|
+
repoFinding(
|
|
256
|
+
'MFE_INT_001',
|
|
257
|
+
host,
|
|
258
|
+
load.file,
|
|
259
|
+
`loadRemoteModule('${remote}', ...) has no entry in ${HOST_MANIFEST}: add "${remote}": "/${remote}/remoteEntry.json".`,
|
|
260
|
+
load,
|
|
261
|
+
),
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (!existsSync(join(host.root, 'src/app/app.routes.ts')))
|
|
266
|
+
findings.push(repoFinding('MFE_INT_002', host, 'src/app/app.routes.ts', 'Host app routes are missing: they mount the child remotes.'));
|
|
267
|
+
for (const remote of Object.keys(remotes ?? {}).filter((name) => !loaded.includes(name)))
|
|
268
|
+
findings.push(
|
|
269
|
+
repoFinding('MFE_INT_002', host, HOST_MANIFEST, `The manifest lists remote "${remote}" but no loadRemoteModule call mounts it.`, {
|
|
270
|
+
severity: 'warn',
|
|
271
|
+
}),
|
|
272
|
+
);
|
|
273
|
+
for (const load of loads) {
|
|
274
|
+
const child = resolveChild(children, repos.integrations, load.remote, remotes?.[load.remote]);
|
|
275
|
+
const exposes = child?.project.federation?.exposes;
|
|
276
|
+
if (!child || !exposes || Object.hasOwn(exposes, load.module)) continue;
|
|
277
|
+
findings.push(
|
|
278
|
+
repoFinding(
|
|
279
|
+
'MFE_INT_002',
|
|
280
|
+
host,
|
|
281
|
+
load.file,
|
|
282
|
+
`Remote "${load.remote}" (${child.rel}) does not expose ${load.module}; it exposes ${Object.keys(exposes).join(', ') || 'nothing'}.`,
|
|
283
|
+
load,
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const proxy = proxyFile(host.root);
|
|
289
|
+
if (!proxy)
|
|
290
|
+
findings.push(repoFinding('MFE_INT_003', host, PROXY_FILES[0], 'Host proxy config (proxy-config.json.example or proxy-config.json) is missing.'));
|
|
291
|
+
else {
|
|
292
|
+
const routes = parseJsonc(readText(host.root, proxy) ?? '');
|
|
293
|
+
const segments = new Set(Object.keys(routes && typeof routes === 'object' ? routes : {}).map((key) => key.split('/')[1]));
|
|
294
|
+
if (!routes || typeof routes !== 'object') findings.push(repoFinding('MFE_INT_003', host, proxy, 'The host proxy config is not valid JSON.'));
|
|
295
|
+
else
|
|
296
|
+
for (const [remote, url] of Object.entries(remotes ?? {})) {
|
|
297
|
+
const segment = urlSegment(url);
|
|
298
|
+
if (segment && !segments.has(segment))
|
|
299
|
+
findings.push(
|
|
300
|
+
repoFinding('MFE_INT_003', host, proxy, `No proxy entry for remote "${remote}" (/${segment}/**): ng serve cannot load ${String(url)}.`),
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
for (const integration of repos.integrations.filter((repo) => belongsTo(repo, host))) {
|
|
306
|
+
const served = readJson(integration.root, INTEGRATION_MANIFEST);
|
|
307
|
+
if (!served || typeof served !== 'object')
|
|
308
|
+
findings.push(
|
|
309
|
+
repoFinding(
|
|
310
|
+
'MFE_INT_006',
|
|
311
|
+
integration,
|
|
312
|
+
INTEGRATION_MANIFEST,
|
|
313
|
+
`The integration federation manifest served to ${host.rel} is missing or not valid JSON.`,
|
|
314
|
+
),
|
|
315
|
+
);
|
|
316
|
+
else
|
|
317
|
+
for (const remote of loaded.filter((name) => !Object.hasOwn(served, name)))
|
|
318
|
+
findings.push(
|
|
319
|
+
repoFinding(
|
|
320
|
+
'MFE_INT_006',
|
|
321
|
+
integration,
|
|
322
|
+
INTEGRATION_MANIFEST,
|
|
323
|
+
`Remote "${remote}", mounted by ${host.rel}, is not in the served federation manifest.`,
|
|
324
|
+
),
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
const translation = readJson(integration.root, INTEGRATION_TRANSLATION);
|
|
328
|
+
if (!translation) {
|
|
329
|
+
findings.push(
|
|
330
|
+
repoFinding(
|
|
331
|
+
'MFE_INT_007',
|
|
332
|
+
integration,
|
|
333
|
+
INTEGRATION_TRANSLATION,
|
|
334
|
+
`The integration translation config served to ${host.rel} is missing or not valid JSON.`,
|
|
335
|
+
),
|
|
336
|
+
);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
/** @type {string[]} */
|
|
340
|
+
const paths = Array.isArray(translation.translationPaths) ? translation.translationPaths.map(String) : [];
|
|
341
|
+
if (!paths.some((path) => /i18n\/permissions/.test(path))) continue;
|
|
342
|
+
const languages = readdirSafe(join(host.root, 'src/assets/i18n'))
|
|
343
|
+
.filter((name) => /^[a-z]{2}(?:-[A-Za-z]+)?\.json$/.test(name))
|
|
344
|
+
.map((name) => name.slice(0, -'.json'.length));
|
|
345
|
+
const missing = languages.filter((language) => !existsSync(join(host.root, 'src/assets/i18n/permissions', `${language}.json`)));
|
|
346
|
+
if (missing.length)
|
|
347
|
+
findings.push(
|
|
348
|
+
repoFinding(
|
|
349
|
+
'MFE_INT_008',
|
|
350
|
+
host,
|
|
351
|
+
'src/assets/i18n/permissions',
|
|
352
|
+
`${integration.rel}/${INTEGRATION_TRANSLATION} loads permission translations, but the host has none for ${missing.join(', ')}.`,
|
|
353
|
+
),
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
return findings;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** @param {string} dir */
|
|
360
|
+
function readdirSafe(dir) {
|
|
361
|
+
try {
|
|
362
|
+
return readdirSync(dir).sort();
|
|
363
|
+
} catch {
|
|
364
|
+
return [];
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* @param {AppRepo} child
|
|
370
|
+
* @returns {Finding[]}
|
|
371
|
+
*/
|
|
372
|
+
function childFindings(child) {
|
|
373
|
+
/** @type {Finding[]} */
|
|
374
|
+
const findings = [];
|
|
375
|
+
const federation = child.project.federation;
|
|
376
|
+
if (!federation?.name || !Object.keys(federation.exposes).length)
|
|
377
|
+
findings.push(
|
|
378
|
+
repoFinding(
|
|
379
|
+
'MFE_INT_004',
|
|
380
|
+
child,
|
|
381
|
+
'federation.config.js',
|
|
382
|
+
'A child needs federation.config.js with a name and the modules it exposes to the host.',
|
|
383
|
+
),
|
|
384
|
+
);
|
|
385
|
+
if (!existsSync(join(child.root, CHILD_CONFIG)))
|
|
386
|
+
findings.push(repoFinding('MFE_INT_005', child, CHILD_CONFIG, 'Child runtime config is missing: the host reads it when it mounts the remote.'));
|
|
387
|
+
return findings;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* True when the database repo holds an access-control or data seed (`access-control/data.sql` or
|
|
392
|
+
* any `data.sql`).
|
|
393
|
+
* @param {string} root
|
|
394
|
+
*/
|
|
395
|
+
const hasSeed = (root) => walk(root, '.', (file) => file === 'data.sql' || file.endsWith('/data.sql')).length > 0;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* @param {Repo} database
|
|
399
|
+
* @param {Repos} repos
|
|
400
|
+
* @returns {Finding[]}
|
|
401
|
+
*/
|
|
402
|
+
function databaseFindings(database, repos) {
|
|
403
|
+
const owners = repos.apps.filter((app) => belongsTo(database, app));
|
|
404
|
+
if (!owners.length || hasSeed(database.root)) return [];
|
|
405
|
+
if (owners.some((app) => app.project.role === 'host'))
|
|
406
|
+
return [
|
|
407
|
+
repoFinding(
|
|
408
|
+
'MFE_INT_009',
|
|
409
|
+
database,
|
|
410
|
+
'access-control/data.sql',
|
|
411
|
+
'The host database repo has no permission or menu seed (access-control/data.sql or data.sql).',
|
|
412
|
+
),
|
|
413
|
+
];
|
|
414
|
+
return [
|
|
415
|
+
repoFinding(
|
|
416
|
+
'MFE_INT_010',
|
|
417
|
+
database,
|
|
418
|
+
'access-control/data.sql',
|
|
419
|
+
'The child database repo has no data scripts (access-control/data.sql or data.sql).',
|
|
420
|
+
),
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* @param {unknown} catalog
|
|
426
|
+
* @returns {string[]}
|
|
427
|
+
*/
|
|
428
|
+
function bannersWithoutTone(catalog) {
|
|
429
|
+
const assets = /** @type {{ assets?: unknown }} */ (catalog ?? {}).assets;
|
|
430
|
+
/** @param {unknown} value */
|
|
431
|
+
const isTone = (value) => value === 'light' || value === 'dark';
|
|
432
|
+
return (Array.isArray(assets) ? assets : [])
|
|
433
|
+
.filter((asset) => {
|
|
434
|
+
const name = String(asset?.name ?? '');
|
|
435
|
+
return BANNER_NAMES.has(name) || /banner/i.test(name) || /\/banners?\//i.test(`${asset?.light ?? ''} ${asset?.dark ?? ''}`);
|
|
436
|
+
})
|
|
437
|
+
.filter((asset) => !isTone(asset?.tone?.light) || !isTone(asset?.tone?.dark))
|
|
438
|
+
.map((asset) => String(asset?.name ?? '(unnamed)'));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* @param {Repo} integration
|
|
443
|
+
* @returns {Finding[]}
|
|
444
|
+
*/
|
|
445
|
+
function assetFindings(integration) {
|
|
446
|
+
/** @type {Finding[]} */
|
|
447
|
+
const findings = [];
|
|
448
|
+
for (const file of TRANSLATION_FILES) {
|
|
449
|
+
const text = readText(integration.root, file);
|
|
450
|
+
if (text?.includes('/assets/themes/i18n') && !text.includes('/assets/themes/assets/i18n'))
|
|
451
|
+
findings.push(
|
|
452
|
+
repoFinding(
|
|
453
|
+
'MFE_INT_ASSET_001',
|
|
454
|
+
integration,
|
|
455
|
+
file,
|
|
456
|
+
'Integration translation paths must use /assets/themes/assets/i18n, not /assets/themes/i18n.',
|
|
457
|
+
),
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
const themesText = readText(integration.root, THEMES);
|
|
462
|
+
if (themesText === null) return findings;
|
|
463
|
+
/** @type {unknown} */
|
|
464
|
+
let themesJson;
|
|
465
|
+
try {
|
|
466
|
+
themesJson = JSON.parse(themesText);
|
|
467
|
+
} catch {
|
|
468
|
+
return [...findings, repoFinding('MFE_INT_ASSET_002', integration, THEMES, 'themes.json is not valid JSON.')];
|
|
469
|
+
}
|
|
470
|
+
const listed = /** @type {{ themes?: unknown }} */ (themesJson ?? {}).themes;
|
|
471
|
+
const themes = (Array.isArray(listed) ? listed : []).filter((entry) => typeof entry === 'string' && !entry.startsWith('http'));
|
|
472
|
+
const composes = COMPOSE_FILES.map((file) => ({ file, text: readText(integration.root, file) })).filter((compose) => compose.text !== null);
|
|
473
|
+
// Mounting web/themes whole serves the catalog too.
|
|
474
|
+
/** @param {string} text */
|
|
475
|
+
const mountsThemes = (text) => /web\/themes\/?["':\s]/.test(text);
|
|
476
|
+
// A compose file that mounts neither web/themes nor its catalog leaves the catalog to the host image.
|
|
477
|
+
const servesCatalog = !composes.length || composes.some(({ text }) => mountsThemes(String(text)) || /web\/themes\/catalog/.test(String(text)));
|
|
478
|
+
for (const entry of servesCatalog ? themes : []) {
|
|
479
|
+
const catalogName = entry.replace(/^.*\/catalog\//, '').replace(/^\//, '');
|
|
480
|
+
const catalogFile = `web/themes/catalog/${catalogName}`;
|
|
481
|
+
const catalogText = readText(integration.root, catalogFile);
|
|
482
|
+
if (catalogText === null) {
|
|
483
|
+
findings.push(repoFinding('MFE_INT_ASSET_002', integration, THEMES, `Referenced theme catalog "${entry}" is missing at ${catalogFile}.`));
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
let catalog;
|
|
487
|
+
try {
|
|
488
|
+
catalog = JSON.parse(catalogText);
|
|
489
|
+
} catch {
|
|
490
|
+
findings.push(repoFinding('MFE_INT_ASSET_002', integration, catalogFile, `Referenced theme catalog "${entry}" is not valid JSON.`));
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const missingTone = bannersWithoutTone(catalog);
|
|
494
|
+
if (missingTone.length)
|
|
495
|
+
findings.push(
|
|
496
|
+
repoFinding(
|
|
497
|
+
'MFE_INT_ASSET_004',
|
|
498
|
+
integration,
|
|
499
|
+
catalogFile,
|
|
500
|
+
`Served catalog has banner assets without tone: ${missingTone.join(', ')}. ${BANNER_TONE_HINT}`,
|
|
501
|
+
),
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const referencesCatalog = themes.some((entry) => entry.includes('/catalog/'));
|
|
506
|
+
for (const { file, text } of composes) {
|
|
507
|
+
const content = String(text);
|
|
508
|
+
if (referencesCatalog && /web\/themes\/assets/.test(content) && !/web\/themes\/catalog/.test(content) && !mountsThemes(content))
|
|
509
|
+
findings.push(
|
|
510
|
+
repoFinding(
|
|
511
|
+
'MFE_INT_ASSET_003',
|
|
512
|
+
integration,
|
|
513
|
+
file,
|
|
514
|
+
'Compose mounts web/themes/assets but not web/themes/catalog while themes.json references catalog files.',
|
|
515
|
+
{
|
|
516
|
+
severity: 'warn',
|
|
517
|
+
},
|
|
518
|
+
),
|
|
519
|
+
);
|
|
520
|
+
}
|
|
521
|
+
return findings;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Every integration finding under `root`, unfiltered by exceptions.
|
|
526
|
+
* @param {string} root
|
|
527
|
+
* @returns {Finding[]}
|
|
528
|
+
*/
|
|
529
|
+
export function integrationFindings(root) {
|
|
530
|
+
const repos = findRepos(root);
|
|
531
|
+
return [
|
|
532
|
+
...repos.apps.flatMap((app) => (app.project.role === 'host' ? hostFindings(app, repos) : childFindings(app))),
|
|
533
|
+
...repos.databases.flatMap((database) => databaseFindings(database, repos)),
|
|
534
|
+
...repos.integrations.flatMap(assetFindings),
|
|
535
|
+
];
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* `check --integration`: the findings under `root`, each repo's `sdk-tools.exceptions.json`
|
|
540
|
+
* applied to its own findings.
|
|
541
|
+
* @param {{ root: string, today?: string }} options
|
|
542
|
+
* @returns {CheckResult}
|
|
543
|
+
*/
|
|
544
|
+
export function checkIntegration({ root, today }) {
|
|
545
|
+
/** @type {Map<string, Finding[]>} */
|
|
546
|
+
const byRepo = new Map();
|
|
547
|
+
for (const item of integrationFindings(root)) {
|
|
548
|
+
const repo = item.repo ?? '.';
|
|
549
|
+
byRepo.set(repo, [...(byRepo.get(repo) ?? []), item]);
|
|
550
|
+
}
|
|
551
|
+
/** @type {Finding[]} */
|
|
552
|
+
const kept = [];
|
|
553
|
+
/** @type {ExceptedFinding[]} */
|
|
554
|
+
const excepted = [];
|
|
555
|
+
for (const [repo, list] of byRepo) {
|
|
556
|
+
const applied = applyExceptions(join(root, repo), list, today);
|
|
557
|
+
kept.push(...applied.findings.map((item) => ({ ...item, id: item.id ?? null, repo })));
|
|
558
|
+
excepted.push(...applied.excepted);
|
|
559
|
+
}
|
|
560
|
+
kept.sort((a, b) => (a.repo ?? '').localeCompare(b.repo ?? '') || a.file.localeCompare(b.file) || a.line - b.line || a.rule.localeCompare(b.rule));
|
|
561
|
+
return {
|
|
562
|
+
findings: kept,
|
|
563
|
+
counts: { errors: kept.filter((f) => f.severity === 'error').length, warnings: kept.filter((f) => f.severity === 'warn').length },
|
|
564
|
+
excepted,
|
|
565
|
+
};
|
|
566
|
+
}
|