@jini-ai/devops 0.5.5 → 0.5.6
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 +6 -0
- package/dist/agent-jobs/jobs.js +33 -26
- package/dist/agent-jobs/node.d.ts +14 -0
- package/dist/agent-jobs/node.js +8 -3
- package/dist/checks/coverage/diff.js +21 -10
- package/dist/checks/coverage/disk.js +20 -13
- package/dist/checks/coverage/integrity.js +44 -39
- package/dist/checks/hardwiring-node.js +89 -73
- package/dist/checks/hardwiring.d.ts +5 -0
- package/dist/checks/hardwiring.js +75 -48
- package/dist/checks/node.js +6 -1
- package/dist/checks/published-types/index.js +30 -15
- package/dist/core/artifact-store.d.ts +35 -0
- package/dist/core/artifact-store.js +2 -0
- package/dist/deploy/host-kit.d.ts +3 -0
- package/dist/deploy/index.d.ts +1 -0
- package/dist/deploy/node.d.ts +10 -0
- package/dist/deploy/node.js +11 -3
- package/dist/deploy/reachability.d.ts +2 -2
- package/dist/deploy/reachability.js +164 -117
- package/dist/dns/approval.d.ts +61 -0
- package/dist/dns/approval.js +48 -0
- package/dist/dns/contract.d.ts +206 -0
- package/dist/dns/contract.js +30 -0
- package/dist/dns/delegation.d.ts +36 -0
- package/dist/dns/delegation.js +44 -0
- package/dist/dns/index.d.ts +15 -0
- package/dist/dns/index.js +15 -0
- package/dist/dns/manual.d.ts +28 -0
- package/dist/dns/manual.js +140 -0
- package/dist/dns/node/index.d.ts +8 -0
- package/dist/dns/node/index.js +8 -0
- package/dist/dns/node/resolver.d.ts +35 -0
- package/dist/dns/node/resolver.js +155 -0
- package/dist/dns/node/udp.d.ts +27 -0
- package/dist/dns/node/udp.js +39 -0
- package/dist/dns/node/wire.d.ts +36 -0
- package/dist/dns/node/wire.js +90 -0
- package/dist/dns/plan.d.ts +34 -0
- package/dist/dns/plan.js +242 -0
- package/dist/dns/records.d.ts +67 -0
- package/dist/dns/records.js +144 -0
- package/dist/dns/registry.d.ts +26 -0
- package/dist/dns/registry.js +59 -0
- package/dist/dns/spf.d.ts +23 -0
- package/dist/dns/spf.js +35 -0
- package/dist/dns/verify.d.ts +61 -0
- package/dist/dns/verify.js +109 -0
- package/dist/local-dev/index.js +36 -20
- package/dist/packaging/electron/archive.d.ts +7 -4
- package/dist/packaging/electron/archive.js +32 -25
- package/dist/packaging/electron/imports.d.ts +1 -1
- package/dist/packaging/electron/imports.js +39 -23
- package/dist/packaging/electron/staging.js +68 -47
- package/dist/source-control/commit.js +36 -18
- package/dist/source-control/registry.js +95 -59
- package/dist/static-export/node-adapters.js +26 -17
- package/dist/static-export/runner.js +185 -103
- package/dist/static-export/transforms.js +26 -23
- package/package.json +18 -6
|
@@ -5,6 +5,24 @@ import { createServer } from 'node:http';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { ExportPathError } from './contracts.js';
|
|
7
7
|
import { safeRelativeOutputFile } from './transforms.js';
|
|
8
|
+
/** Create one directory level; an existing entry is left for the caller's lstat check. */
|
|
9
|
+
async function makeDirectory(directory) {
|
|
10
|
+
try {
|
|
11
|
+
await mkdir(directory);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
if (error.code !== 'EEXIST')
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** True only for macOS's own /tmp or /var symlink into /private. */
|
|
19
|
+
async function isSystemTempAlias(current, info) {
|
|
20
|
+
// macOS exposes its system temporary roots through these fixed OS aliases. Arbitrary
|
|
21
|
+
// symlinks still fail closed; rejecting /var would reject Node's own tmpdir() output.
|
|
22
|
+
if (process.platform !== 'darwin' || (current !== '/tmp' && current !== '/var') || !info.isSymbolicLink())
|
|
23
|
+
return false;
|
|
24
|
+
return await realpath(current) === '/private' + current;
|
|
25
|
+
}
|
|
8
26
|
/** Require regular directories at every ancestor. Hosts must use canonical absolute storage paths.
|
|
9
27
|
* The storage hierarchy must be caller-owned; cross-process hostile ancestor swaps require host isolation.
|
|
10
28
|
*/
|
|
@@ -12,25 +30,16 @@ async function ensureDirectory({ directory, label }, optional = {}) {
|
|
|
12
30
|
if (!path.isAbsolute(directory))
|
|
13
31
|
throw new ExportPathError(`${label} path must be absolute.`);
|
|
14
32
|
const resolved = path.resolve(directory);
|
|
15
|
-
const
|
|
16
|
-
let current =
|
|
17
|
-
for (const segment of
|
|
33
|
+
const { root } = path.parse(resolved);
|
|
34
|
+
let current = root;
|
|
35
|
+
for (const segment of resolved.slice(root.length).split(path.sep).filter(Boolean)) {
|
|
18
36
|
current = path.join(current, segment);
|
|
19
|
-
if (optional.create)
|
|
20
|
-
|
|
21
|
-
await mkdir(current);
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
if (error.code !== 'EEXIST')
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
37
|
+
if (optional.create)
|
|
38
|
+
await makeDirectory(current);
|
|
28
39
|
const info = await lstat(current);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
&& info.isSymbolicLink() && await realpath(current) === '/private' + current;
|
|
33
|
-
if (!systemAlias && (!info.isDirectory() || info.isSymbolicLink()))
|
|
40
|
+
if (await isSystemTempAlias(current, info))
|
|
41
|
+
continue;
|
|
42
|
+
if (!info.isDirectory() || info.isSymbolicLink())
|
|
34
43
|
throw new ExportPathError(`${label} path must be a regular directory.`);
|
|
35
44
|
}
|
|
36
45
|
}
|
|
@@ -10,46 +10,75 @@ function failureReason(ctx, url, error) {
|
|
|
10
10
|
return `GET ${ctx.baseUrl}${url} timed out after ${ctx.timeoutMs}ms`;
|
|
11
11
|
return `GET ${ctx.baseUrl}${url} failed: ${ctx.args.describeError({ error })}`;
|
|
12
12
|
}
|
|
13
|
+
async function redirectBody(required) {
|
|
14
|
+
const { ctx, route, response } = required;
|
|
15
|
+
const decision = redirectOutcomeFor({ status: response.status, locationHeader: response.headers.get('location') }, route.redirectTarget !== undefined ? { manifestTarget: route.redirectTarget } : {});
|
|
16
|
+
if (decision.kind === 'failed')
|
|
17
|
+
return { reason: decision.reason };
|
|
18
|
+
const body = ctx.args.security.transformHtml({ html: renderRedirectStub({ location: decision.location }, { basePath: ctx.basePath }) });
|
|
19
|
+
await response.body?.cancel();
|
|
20
|
+
return { body, contentType: 'text/html; charset=utf-8' };
|
|
21
|
+
}
|
|
22
|
+
/** The error-page probe accepts what the host's policy accepts; every other content route needs a 200. */
|
|
23
|
+
function statusAccepted(required) {
|
|
24
|
+
const { ctx, route, status } = required;
|
|
25
|
+
return route.kind === 'not-found' ? ctx.args.errorPage.acceptStatus({ status }) : status === 200;
|
|
26
|
+
}
|
|
27
|
+
function statusRejection(required) {
|
|
28
|
+
const { ctx, route, status } = required;
|
|
29
|
+
if (route.kind !== 'not-found')
|
|
30
|
+
return `expected 200, got ${status}`;
|
|
31
|
+
return ctx.args.errorPage.rejectionReason?.({ status }) ?? `expected an accepted response for the error-page probe, got ${status}`;
|
|
32
|
+
}
|
|
33
|
+
async function contentBody(required) {
|
|
34
|
+
const { ctx, route, response } = required;
|
|
35
|
+
const contentType = response.headers.get('content-type');
|
|
36
|
+
if (!statusAccepted({ ctx, route, status: response.status })) {
|
|
37
|
+
await response.body?.cancel();
|
|
38
|
+
return { reason: statusRejection({ ctx, route, status: response.status }) };
|
|
39
|
+
}
|
|
40
|
+
const rawBody = await response.text();
|
|
41
|
+
let body = rewriteRouteBodyForBasePath({ path: route.path, body: rawBody, basePath: ctx.basePath });
|
|
42
|
+
if (route.kind === 'not-found' || /^text\/html\b/i.test(contentType ?? ''))
|
|
43
|
+
body = ctx.args.security.transformHtml({ html: body });
|
|
44
|
+
// The error page is written but never crawled for assets or further routes.
|
|
45
|
+
return { body, contentType, ...(route.kind !== 'not-found' ? { crawlHtml: rawBody } : {}) };
|
|
46
|
+
}
|
|
13
47
|
async function writeRoute(ctx, route) {
|
|
14
48
|
// Validate the request path even when the error-page policy supplies a different artifact path.
|
|
15
49
|
const regularOutput = outputFileForUrl({ url: route.path }, { contentRoute: route.kind !== 'well-known' });
|
|
16
50
|
const outputFile = route.kind === 'not-found' ? safeRelativeOutputFile({ value: ctx.args.errorPage.outputFile }) : regularOutput;
|
|
17
51
|
const response = await request(ctx, route.path);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (decision.kind === 'failed')
|
|
24
|
-
return { reason: decision.reason };
|
|
25
|
-
body = ctx.args.security.transformHtml({ html: renderRedirectStub({ location: decision.location }, { basePath: ctx.basePath }) });
|
|
26
|
-
contentType = 'text/html; charset=utf-8';
|
|
27
|
-
await response.body?.cancel();
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
if (route.kind === 'not-found' ? !ctx.args.errorPage.acceptStatus({ status: response.status }) : response.status !== 200) {
|
|
31
|
-
await response.body?.cancel();
|
|
32
|
-
return { reason: route.kind === 'not-found' ? (ctx.args.errorPage.rejectionReason?.({ status: response.status }) ?? `expected an accepted response for the error-page probe, got ${response.status}`) : `expected 200, got ${response.status}` };
|
|
33
|
-
}
|
|
34
|
-
rawBody = await response.text();
|
|
35
|
-
body = rewriteRouteBodyForBasePath({ path: route.path, body: rawBody, basePath: ctx.basePath });
|
|
36
|
-
if (route.kind === 'not-found' || /^text\/html\b/i.test(contentType ?? ''))
|
|
37
|
-
body = ctx.args.security.transformHtml({ html: body });
|
|
38
|
-
}
|
|
39
|
-
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data: body });
|
|
40
|
-
return { route: { path: route.path, kind: route.kind, outputFile, data: body, contentType }, ...(rawBody !== undefined && route.kind !== 'not-found' ? { crawlHtml: rawBody } : {}) };
|
|
52
|
+
const outcome = route.kind === 'redirect' ? await redirectBody({ ctx, route, response }) : await contentBody({ ctx, route, response });
|
|
53
|
+
if ('reason' in outcome)
|
|
54
|
+
return outcome;
|
|
55
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data: outcome.body });
|
|
56
|
+
return { route: { path: route.path, kind: route.kind, outputFile, data: outcome.body, contentType: outcome.contentType }, ...(outcome.crawlHtml !== undefined ? { crawlHtml: outcome.crawlHtml } : {}) };
|
|
41
57
|
}
|
|
42
58
|
/** Most routes `discoverRoutes` may add to one export; the rest are reported as skipped. */
|
|
43
59
|
const MAX_DISCOVERED_ROUTES = 2000;
|
|
60
|
+
/** Append newly discovered routes once each, up to the cap; the rest are reported as skipped. */
|
|
61
|
+
function enqueueDiscovered(required) {
|
|
62
|
+
const { state } = required;
|
|
63
|
+
for (const next of required.routes) {
|
|
64
|
+
if (state.queued.has(next.path))
|
|
65
|
+
continue;
|
|
66
|
+
state.queued.add(next.path);
|
|
67
|
+
if (state.discovered >= MAX_DISCOVERED_ROUTES) {
|
|
68
|
+
state.skipped.push({ reason: 'discovered-route-cap', detail: `${next.path} (over ${MAX_DISCOVERED_ROUTES} discovered routes)` });
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
state.discovered += 1;
|
|
72
|
+
state.queue.push(next);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
44
75
|
async function writeRoutes(ctx, routes) {
|
|
45
|
-
const succeeded = [], failed = []
|
|
76
|
+
const succeeded = [], failed = [];
|
|
46
77
|
const assets = new Set();
|
|
47
78
|
// A queue, not a loop over the manifest: discovered routes are appended and scanned in turn.
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
for (let index = 0; index < queue.length; index++) {
|
|
52
|
-
const route = queue[index];
|
|
79
|
+
const state = { queue: [...routes], queued: new Set(routes.map(route => route.path)), discovered: 0, skipped: [] };
|
|
80
|
+
for (let index = 0; index < state.queue.length; index++) {
|
|
81
|
+
const route = state.queue[index];
|
|
53
82
|
try {
|
|
54
83
|
const outcome = await writeRoute(ctx, route);
|
|
55
84
|
if ('reason' in outcome) {
|
|
@@ -57,27 +86,42 @@ async function writeRoutes(ctx, routes) {
|
|
|
57
86
|
continue;
|
|
58
87
|
}
|
|
59
88
|
succeeded.push(outcome.route);
|
|
60
|
-
|
|
89
|
+
const html = outcome.crawlHtml;
|
|
90
|
+
if (html === undefined)
|
|
61
91
|
continue;
|
|
62
|
-
for (const url of extractAssetUrls({ html
|
|
92
|
+
for (const url of extractAssetUrls({ html, prefixes: ctx.args.assetUrlPrefixes }))
|
|
63
93
|
assets.add(url);
|
|
64
|
-
|
|
65
|
-
if (queued.has(next.path))
|
|
66
|
-
continue;
|
|
67
|
-
queued.add(next.path);
|
|
68
|
-
if (discovered >= MAX_DISCOVERED_ROUTES) {
|
|
69
|
-
skipped.push({ reason: 'discovered-route-cap', detail: `${next.path} (over ${MAX_DISCOVERED_ROUTES} discovered routes)` });
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
discovered += 1;
|
|
73
|
-
queue.push(next);
|
|
74
|
-
}
|
|
94
|
+
enqueueDiscovered({ state, routes: ctx.args.discoverRoutes?.({ path: route.path, html }) ?? [] });
|
|
75
95
|
}
|
|
76
96
|
catch (error) {
|
|
77
97
|
failed.push({ path: route.path, kind: route.kind, reason: failureReason(ctx, route.path, error) });
|
|
78
98
|
}
|
|
79
99
|
}
|
|
80
|
-
return { succeeded, failed, assets, skipped };
|
|
100
|
+
return { succeeded, failed, assets, skipped: state.skipped };
|
|
101
|
+
}
|
|
102
|
+
async function fetchAsset(required) {
|
|
103
|
+
const { ctx, url } = required;
|
|
104
|
+
const outputFile = outputFileForUrl({ url });
|
|
105
|
+
const response = await request(ctx, url);
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
await response.body?.cancel();
|
|
108
|
+
return { reason: `GET ${url} -> ${response.status}` };
|
|
109
|
+
}
|
|
110
|
+
const data = Buffer.from(await response.arrayBuffer());
|
|
111
|
+
const contentType = response.headers.get('content-type');
|
|
112
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data });
|
|
113
|
+
return { url, outputFile, data, contentType };
|
|
114
|
+
}
|
|
115
|
+
/** Only a stylesheet reached from HTML is scanned: one CSS hop, never recursive. */
|
|
116
|
+
function stylesheetChildren(required) {
|
|
117
|
+
const { ctx, asset } = required;
|
|
118
|
+
if (!required.crawlCss || !asset.url.split('?')[0].endsWith('.css'))
|
|
119
|
+
return [];
|
|
120
|
+
return extractCssUrls({ css: asset.data.toString('utf8'), cssUrl: asset.url, prefixes: ctx.args.assetUrlPrefixes });
|
|
121
|
+
}
|
|
122
|
+
function assetFailureReason(required) {
|
|
123
|
+
const { ctx, url, error } = required;
|
|
124
|
+
return error instanceof ExportPathError && ctx.args.assetPathFailureReason !== undefined ? ctx.args.assetPathFailureReason : failureReason(ctx, url, error);
|
|
81
125
|
}
|
|
82
126
|
async function writeAssets(ctx, initial) {
|
|
83
127
|
const succeeded = [], failed = [];
|
|
@@ -89,24 +133,17 @@ async function writeAssets(ctx, initial) {
|
|
|
89
133
|
continue;
|
|
90
134
|
seen.add(url);
|
|
91
135
|
try {
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
await response.body?.cancel();
|
|
96
|
-
failed.push({ url, reason: `GET ${url} -> ${response.status}` });
|
|
136
|
+
const outcome = await fetchAsset({ ctx, url });
|
|
137
|
+
if ('reason' in outcome) {
|
|
138
|
+
failed.push({ url, reason: outcome.reason });
|
|
97
139
|
continue;
|
|
98
140
|
}
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
succeeded.push({ url, outputFile, data, contentType });
|
|
103
|
-
if (crawlCss && url.split('?')[0].endsWith('.css')) {
|
|
104
|
-
for (const child of extractCssUrls({ css: data.toString('utf8'), cssUrl: url, prefixes: ctx.args.assetUrlPrefixes }))
|
|
105
|
-
queue.push({ url: child, crawlCss: false });
|
|
106
|
-
}
|
|
141
|
+
succeeded.push(outcome);
|
|
142
|
+
for (const child of stylesheetChildren({ ctx, asset: outcome, crawlCss }))
|
|
143
|
+
queue.push({ url: child, crawlCss: false });
|
|
107
144
|
}
|
|
108
145
|
catch (error) {
|
|
109
|
-
failed.push({ url, reason:
|
|
146
|
+
failed.push({ url, reason: assetFailureReason({ ctx, url, error }) });
|
|
110
147
|
}
|
|
111
148
|
}
|
|
112
149
|
return { succeeded, failed };
|
|
@@ -127,76 +164,121 @@ async function unreferenced(ctx, manifest, assets) {
|
|
|
127
164
|
}
|
|
128
165
|
return [...await ctx.args.assetSource.listThemeFiles({ theme })].filter(file => !accounted.has(file)).sort();
|
|
129
166
|
}
|
|
130
|
-
/**
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
167
|
+
/** Most dropped references retained per export. */
|
|
168
|
+
const MAX_DROPPED_REFERENCES = 200;
|
|
169
|
+
/** Site path normalization shared by written outputs and references: no trailing slashes, root as '/'. */
|
|
170
|
+
function pathNormalizer(required) {
|
|
171
|
+
return url => new URL(url, required.origin).pathname.replace(/\/+$/, '') || '/';
|
|
172
|
+
}
|
|
173
|
+
/** Every path this run wrote: artifact paths (and index.html directory aliases), route paths except the error-page probe, and asset URLs. */
|
|
174
|
+
function writtenPaths(required) {
|
|
175
|
+
const { routes, assets, normalize } = required;
|
|
137
176
|
const written = new Set();
|
|
138
|
-
for (const item of [...
|
|
177
|
+
for (const item of [...routes, ...assets]) {
|
|
139
178
|
const file = '/' + item.outputFile;
|
|
140
179
|
written.add(normalize(file));
|
|
141
180
|
if (file.endsWith('/index.html'))
|
|
142
181
|
written.add(normalize(file.slice(0, -10)));
|
|
143
182
|
}
|
|
144
|
-
for (const route of
|
|
183
|
+
for (const route of routes)
|
|
145
184
|
if (route.kind !== 'not-found')
|
|
146
185
|
written.add(normalize(route.path));
|
|
147
|
-
for (const asset of
|
|
186
|
+
for (const asset of assets)
|
|
148
187
|
written.add(normalize(asset.url));
|
|
188
|
+
return written;
|
|
189
|
+
}
|
|
190
|
+
function isHtmlRoute(route) {
|
|
191
|
+
return /^text\/html\b/i.test(route.contentType ?? '') || route.outputFile.endsWith('.html');
|
|
192
|
+
}
|
|
193
|
+
/** Fragments are always skipped; empty and query-only values are skipped unless they are form actions (which post to the page itself). */
|
|
194
|
+
function isSkippedReference(required) {
|
|
195
|
+
const { value, attribute } = required;
|
|
196
|
+
return ((!value || value.startsWith('?')) && attribute !== 'action') || value.startsWith('#');
|
|
197
|
+
}
|
|
198
|
+
/** The same-origin site path a reference names, base path stripped; undefined when unparseable or off-site. */
|
|
199
|
+
function referencedPath(required) {
|
|
200
|
+
const { scan, value, page } = required;
|
|
201
|
+
let url;
|
|
202
|
+
try {
|
|
203
|
+
url = new URL(value, scan.origin + scan.basePath + page);
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
if (url.origin !== scan.origin)
|
|
209
|
+
return undefined;
|
|
210
|
+
let pathname = url.pathname;
|
|
211
|
+
if (scan.basePath && (pathname === scan.basePath || pathname.startsWith(scan.basePath + '/')))
|
|
212
|
+
pathname = pathname.slice(scan.basePath.length) || '/';
|
|
213
|
+
return scan.normalize(pathname);
|
|
214
|
+
}
|
|
215
|
+
/** A reference this export cannot serve: a form action (needs a server) or a link to a path nothing wrote. */
|
|
216
|
+
function droppedReference(required) {
|
|
217
|
+
const { scan, page, reference } = required;
|
|
218
|
+
const value = reference.url.trim();
|
|
219
|
+
if (isSkippedReference({ value, attribute: reference.attribute }))
|
|
220
|
+
return undefined;
|
|
221
|
+
const url = referencedPath({ scan, value, page });
|
|
222
|
+
if (url === undefined)
|
|
223
|
+
return undefined;
|
|
224
|
+
const reason = reference.attribute === 'action' ? 'needs-server' : 'not-exported';
|
|
225
|
+
if (reason === 'not-exported' && scan.written.has(url))
|
|
226
|
+
return undefined;
|
|
227
|
+
return { page, url, attribute: reference.attribute, reason };
|
|
228
|
+
}
|
|
229
|
+
/** Dedupe per page + URL; a form replaces an earlier link to the same URL, and new keys stop at the cap. */
|
|
230
|
+
function recordDrop(required) {
|
|
231
|
+
const { dropped, drop } = required;
|
|
232
|
+
const key = drop.page + '\n' + drop.url;
|
|
233
|
+
if (dropped.has(key)) {
|
|
234
|
+
if (drop.reason === 'needs-server')
|
|
235
|
+
dropped.set(key, drop);
|
|
236
|
+
}
|
|
237
|
+
else if (dropped.size < MAX_DROPPED_REFERENCES)
|
|
238
|
+
dropped.set(key, drop);
|
|
239
|
+
}
|
|
240
|
+
/** Compare written HTML with this run's outputs only; no requests or filesystem reads.
|
|
241
|
+
* At most 200 drops are retained. O(output count + scanned HTML bytes) time; output paths plus
|
|
242
|
+
* at most 200 dedupe keys are retained. Forms take precedence over links to the same URL.
|
|
243
|
+
*/
|
|
244
|
+
function droppedReferences(required) {
|
|
245
|
+
const origin = required.baseUrl;
|
|
246
|
+
const normalize = pathNormalizer({ origin });
|
|
247
|
+
const scan = { origin, basePath: required.basePath, normalize, written: writtenPaths({ routes: required.routes, assets: required.assets, normalize }) };
|
|
149
248
|
const dropped = new Map();
|
|
150
|
-
for (const route of required.routes) {
|
|
151
|
-
if (!/^text\/html\b/i.test(route.contentType ?? '') && !route.outputFile.endsWith('.html'))
|
|
152
|
-
continue;
|
|
249
|
+
for (const route of required.routes.filter(isHtmlRoute)) {
|
|
153
250
|
for (const reference of extractHtmlReferences({ html: route.data })) {
|
|
154
|
-
const
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
let url;
|
|
158
|
-
try {
|
|
159
|
-
url = new URL(value, origin + required.basePath + route.path);
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
continue;
|
|
163
|
-
}
|
|
164
|
-
if (url.origin !== origin)
|
|
165
|
-
continue;
|
|
166
|
-
let pathname = url.pathname;
|
|
167
|
-
if (required.basePath && (pathname === required.basePath || pathname.startsWith(required.basePath + '/')))
|
|
168
|
-
pathname = pathname.slice(required.basePath.length) || '/';
|
|
169
|
-
pathname = normalize(pathname);
|
|
170
|
-
const reason = reference.attribute === 'action' ? 'needs-server' : 'not-exported';
|
|
171
|
-
if (reason === 'not-exported' && written.has(pathname))
|
|
172
|
-
continue;
|
|
173
|
-
const key = route.path + '\n' + pathname;
|
|
174
|
-
if (dropped.has(key)) {
|
|
175
|
-
if (reason === 'needs-server')
|
|
176
|
-
dropped.set(key, { page: route.path, url: pathname, attribute: reference.attribute, reason });
|
|
177
|
-
}
|
|
178
|
-
else if (dropped.size < 200)
|
|
179
|
-
dropped.set(key, { page: route.path, url: pathname, attribute: reference.attribute, reason });
|
|
251
|
+
const drop = droppedReference({ scan, page: route.path, reference });
|
|
252
|
+
if (drop)
|
|
253
|
+
recordDrop({ dropped, drop });
|
|
180
254
|
}
|
|
181
255
|
}
|
|
182
256
|
return [...dropped.values()];
|
|
183
257
|
}
|
|
258
|
+
/** The app session's origin. Anything but a bare http(s) origin without credentials is refused. */
|
|
259
|
+
function sessionOrigin(required) {
|
|
260
|
+
const origin = new URL(required.baseUrl);
|
|
261
|
+
if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash)
|
|
262
|
+
throw new Error('App session baseUrl must be an HTTP origin without credentials.');
|
|
263
|
+
return origin.origin;
|
|
264
|
+
}
|
|
265
|
+
function fetchTimeout(required) {
|
|
266
|
+
const timeoutMs = required.fetchTimeoutMs ?? 30_000;
|
|
267
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
268
|
+
throw new RangeError('fetchTimeoutMs must be a positive integer');
|
|
269
|
+
return timeoutMs;
|
|
270
|
+
}
|
|
184
271
|
/** Drive the caller's actual app, retaining exact written bytes and reporting each failed item.
|
|
185
272
|
* Startup/output/inventory errors throw; an opened app always closes. No singleton state is used.
|
|
186
273
|
*/
|
|
187
274
|
export async function exportSite(required, optional = {}) {
|
|
188
275
|
const basePath = normalizeBasePath({ raw: optional.basePath ?? '' });
|
|
189
|
-
const timeoutMs = optional.fetchTimeoutMs
|
|
190
|
-
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
191
|
-
throw new RangeError('fetchTimeoutMs must be a positive integer');
|
|
276
|
+
const timeoutMs = fetchTimeout({ fetchTimeoutMs: optional.fetchTimeoutMs });
|
|
192
277
|
await required.writer.prepare({ outputDir: required.outputDir }, { clean: optional.clean ?? false });
|
|
193
278
|
const manifest = await required.manifest.build({});
|
|
194
279
|
const session = await required.app.open({});
|
|
195
280
|
try {
|
|
196
|
-
const
|
|
197
|
-
if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash)
|
|
198
|
-
throw new Error('App session baseUrl must be an HTTP origin without credentials.');
|
|
199
|
-
const ctx = { args: required, baseUrl: origin.origin, basePath, timeoutMs };
|
|
281
|
+
const ctx = { args: required, baseUrl: sessionOrigin({ baseUrl: session.baseUrl }), basePath, timeoutMs };
|
|
200
282
|
const routes = await writeRoutes(ctx, manifest.routes);
|
|
201
283
|
const assets = await writeAssets(ctx, [...routes.assets]);
|
|
202
284
|
return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: [...manifest.skipped, ...routes.skipped],
|
|
@@ -9,6 +9,7 @@ function safeHref(value) {
|
|
|
9
9
|
if (href.startsWith('#') || /^https?:\/\//i.test(href) || /^mailto:/i.test(href))
|
|
10
10
|
return href;
|
|
11
11
|
if (href.startsWith('/')) {
|
|
12
|
+
// eslint-disable-next-line sonarjs/no-clear-text-protocols -- Reserved .invalid sentinel used only for local URL resolution/origin comparison; never fetched.
|
|
12
13
|
try {
|
|
13
14
|
if (new URL(href, 'http://export-safehref.invalid/').origin === 'http://export-safehref.invalid')
|
|
14
15
|
return href;
|
|
@@ -38,27 +39,33 @@ function prefix(value, basePath) {
|
|
|
38
39
|
return value;
|
|
39
40
|
return basePath + value;
|
|
40
41
|
}
|
|
42
|
+
/** First index at or after `index` whose character fails `test` (or the end of `value`). */
|
|
43
|
+
function skipWhile(value, index, test) {
|
|
44
|
+
while (index < value.length && test(value[index]))
|
|
45
|
+
index++;
|
|
46
|
+
return index;
|
|
47
|
+
}
|
|
41
48
|
function srcsetRanges(value) {
|
|
42
49
|
const ranges = [];
|
|
43
50
|
let index = 0;
|
|
44
51
|
while (index < value.length) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const start = index;
|
|
48
|
-
while (index < value.length && !/\s/.test(value[index]))
|
|
49
|
-
index++;
|
|
52
|
+
const start = skipWhile(value, index, char => /[\s,]/.test(char));
|
|
53
|
+
index = skipWhile(value, start, char => !/\s/.test(char));
|
|
50
54
|
let end = index;
|
|
51
55
|
while (end > start && value[end - 1] === ',')
|
|
52
56
|
end--;
|
|
53
57
|
if (end > start)
|
|
54
58
|
ranges.push({ start, end });
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
index++;
|
|
59
|
+
// A URL ending in commas ends its candidate; otherwise skip its descriptor up to the next comma.
|
|
60
|
+
if (end === index)
|
|
61
|
+
index = skipWhile(value, index, char => char !== ',');
|
|
59
62
|
}
|
|
60
63
|
return ranges;
|
|
61
64
|
}
|
|
65
|
+
/** One attribute's URL values: each srcset candidate URL, or the whole value for any other attribute. */
|
|
66
|
+
function attributeUrls(attribute, value) {
|
|
67
|
+
return attribute === 'srcset' ? srcsetRanges(value).map(({ start, end }) => value.slice(start, end)) : [value];
|
|
68
|
+
}
|
|
62
69
|
/** A route path naming a `.json` file (e.g. a see-more JSON batch): written as that file, not `<path>/index.html`. */
|
|
63
70
|
function isJsonRoute(path) {
|
|
64
71
|
return /\.json$/i.test(path.split(/[?#]/)[0]);
|
|
@@ -75,8 +82,6 @@ function rewriteJson(body, basePath) {
|
|
|
75
82
|
return JSON.stringify(parsed, (key, value) => (typeof value === 'string' && (key === 'href' || key === 'url' || key === 'src') ? prefix(value, basePath) : value));
|
|
76
83
|
}
|
|
77
84
|
function rewriteHtml(html, basePath) {
|
|
78
|
-
if (!basePath)
|
|
79
|
-
return html;
|
|
80
85
|
return html.replace(HTML_URL_REWRITE, (_match, attr, quote, value) => {
|
|
81
86
|
if (attr !== 'srcset')
|
|
82
87
|
return `${attr}=${quote}${prefix(value, basePath)}${quote}`;
|
|
@@ -122,26 +127,22 @@ export function* extractHtmlReferences(required, _optional = {}) {
|
|
|
122
127
|
references.push({ index: match.index, attribute: 'action', value: match[2] });
|
|
123
128
|
}
|
|
124
129
|
for (const { attribute, value } of references.sort((a, b) => a.index - b.index)) {
|
|
125
|
-
const
|
|
126
|
-
for (const url of values)
|
|
130
|
+
for (const url of attributeUrls(attribute, value))
|
|
127
131
|
yield { url, attribute };
|
|
128
132
|
}
|
|
129
133
|
}
|
|
130
134
|
/** Shared href/src/srcset/poster scan, preserving data-URL commas and ignoring external references. */
|
|
131
135
|
export function extractAssetUrls(required) {
|
|
132
|
-
const
|
|
133
|
-
for (const match of required.html.matchAll(HTML_URL_SCAN))
|
|
134
|
-
|
|
135
|
-
const values = match[1] === 'srcset' ? srcsetRanges(value).map(({ start, end }) => value.slice(start, end)) : [value];
|
|
136
|
-
for (const url of values)
|
|
137
|
-
if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
|
|
138
|
-
found.add(url.split('#')[0]);
|
|
139
|
-
}
|
|
136
|
+
const candidates = [];
|
|
137
|
+
for (const match of required.html.matchAll(HTML_URL_SCAN))
|
|
138
|
+
candidates.push(...attributeUrls(match[1], match[3]));
|
|
140
139
|
// JSON link fields too (a see-more JSON batch's covers), as `rewriteJson` prefixes them.
|
|
141
|
-
for (const [, url = ''] of required.html.matchAll(/"(?:href|src|url)"\s*:\s*"([^"\\]+)"/g))
|
|
140
|
+
for (const [, url = ''] of required.html.matchAll(/"(?:href|src|url)"\s*:\s*"([^"\\]+)"/g))
|
|
141
|
+
candidates.push(url);
|
|
142
|
+
const found = new Set();
|
|
143
|
+
for (const url of candidates)
|
|
142
144
|
if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
|
|
143
145
|
found.add(url.split('#')[0]);
|
|
144
|
-
}
|
|
145
146
|
return [...found];
|
|
146
147
|
}
|
|
147
148
|
/** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
|
|
@@ -152,12 +153,14 @@ export function extractCssUrls(required) {
|
|
|
152
153
|
if (!ref || ref.startsWith('data:'))
|
|
153
154
|
continue;
|
|
154
155
|
let resolved;
|
|
156
|
+
// eslint-disable-next-line sonarjs/no-clear-text-protocols -- Reserved .invalid sentinel used only for local URL resolution/origin comparison; never fetched.
|
|
155
157
|
try {
|
|
156
158
|
resolved = new URL(ref, 'http://export-local.invalid' + required.cssUrl);
|
|
157
159
|
}
|
|
158
160
|
catch {
|
|
159
161
|
continue;
|
|
160
162
|
}
|
|
163
|
+
// eslint-disable-next-line sonarjs/no-clear-text-protocols -- Reserved .invalid sentinel used only for local URL resolution/origin comparison; never fetched.
|
|
161
164
|
if (resolved.origin !== 'http://export-local.invalid')
|
|
162
165
|
continue;
|
|
163
166
|
if (required.prefixes.some(prefix => resolved.pathname.startsWith(prefix)))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/devops",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "DevOps capabilities for deployment, source control, and CI/CD, exposed through independent subpaths.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -26,7 +26,9 @@
|
|
|
26
26
|
"./checks/node": "node",
|
|
27
27
|
"./local-dev": "node",
|
|
28
28
|
"./deploy/node": "node",
|
|
29
|
-
"./static-export/failure-summary": "universal"
|
|
29
|
+
"./static-export/failure-summary": "universal",
|
|
30
|
+
"./dns": "node",
|
|
31
|
+
"./dns/node": "node"
|
|
30
32
|
},
|
|
31
33
|
"isolation": {
|
|
32
34
|
"shared": [
|
|
@@ -108,6 +110,16 @@
|
|
|
108
110
|
"types": "./dist/core/export-failure-summary.d.ts",
|
|
109
111
|
"import": "./dist/core/export-failure-summary.js",
|
|
110
112
|
"default": "./dist/core/export-failure-summary.js"
|
|
113
|
+
},
|
|
114
|
+
"./dns": {
|
|
115
|
+
"types": "./dist/dns/index.d.ts",
|
|
116
|
+
"import": "./dist/dns/index.js",
|
|
117
|
+
"default": "./dist/dns/index.js"
|
|
118
|
+
},
|
|
119
|
+
"./dns/node": {
|
|
120
|
+
"types": "./dist/dns/node/index.d.ts",
|
|
121
|
+
"import": "./dist/dns/node/index.js",
|
|
122
|
+
"default": "./dist/dns/node/index.js"
|
|
111
123
|
}
|
|
112
124
|
},
|
|
113
125
|
"files": [
|
|
@@ -129,12 +141,12 @@
|
|
|
129
141
|
"devDependencies": {
|
|
130
142
|
"@vitest/coverage-v8": "^2.1.9",
|
|
131
143
|
"undici": "^7.25.0",
|
|
132
|
-
"@jini-ai/
|
|
133
|
-
"@jini-ai/platform": "^0.5.
|
|
134
|
-
"@jini-ai/
|
|
144
|
+
"@jini-ai/core": "^0.4.9",
|
|
145
|
+
"@jini-ai/platform": "^0.5.10",
|
|
146
|
+
"@jini-ai/daemon": "0.6.9"
|
|
135
147
|
},
|
|
136
148
|
"dependencies": {
|
|
137
|
-
"@jini-ai/core": "^0.4.
|
|
149
|
+
"@jini-ai/core": "^0.4.9"
|
|
138
150
|
},
|
|
139
151
|
"peerDependencies": {
|
|
140
152
|
"typescript": "^5.6.0",
|