@jini-ai/devops 0.3.3 → 0.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 +120 -0
- package/README.md +65 -5
- package/dist/agent-jobs/entry.d.ts +4 -0
- package/dist/agent-jobs/entry.js +4 -0
- package/dist/agent-jobs/jobs.d.ts +25 -0
- package/dist/agent-jobs/jobs.js +115 -0
- package/dist/agent-jobs/node.d.ts +12 -0
- package/dist/agent-jobs/node.js +53 -0
- package/dist/agent-jobs/ports.d.ts +69 -0
- package/dist/agent-jobs/ports.js +2 -0
- package/dist/checks/coverage/diff.d.ts +57 -0
- package/dist/checks/coverage/diff.js +48 -0
- package/dist/checks/coverage/disk.d.ts +65 -0
- package/dist/checks/coverage/disk.js +136 -0
- package/dist/checks/coverage/floors.d.ts +31 -0
- package/dist/checks/coverage/floors.js +24 -0
- package/dist/checks/coverage/index.d.ts +7 -0
- package/dist/checks/coverage/index.js +6 -0
- package/dist/checks/coverage/integrity.d.ts +79 -0
- package/dist/checks/coverage/integrity.js +140 -0
- package/dist/checks/coverage/lcov.d.ts +65 -0
- package/dist/checks/coverage/lcov.js +64 -0
- package/dist/checks/node.d.ts +19 -0
- package/dist/checks/node.js +40 -0
- package/dist/checks/ports.d.ts +67 -0
- package/dist/checks/ports.js +2 -0
- package/dist/checks/published-types/index.d.ts +77 -0
- package/dist/checks/published-types/index.js +186 -0
- package/dist/deploy/host-kit.d.ts +27 -10
- package/dist/deploy/index.d.ts +0 -4
- package/dist/deploy/index.js +0 -4
- package/dist/deploy/naming.d.ts +9 -6
- package/dist/deploy/naming.js +5 -7
- package/dist/deploy/node.d.ts +18 -0
- package/dist/deploy/node.js +57 -0
- package/dist/deploy/reachability.d.ts +47 -18
- package/dist/deploy/reachability.js +77 -71
- package/dist/deploy/redirect-guard.d.ts +15 -11
- package/dist/deploy/redirect-guard.js +11 -12
- package/dist/deploy/tokens.d.ts +17 -14
- package/dist/deploy/tokens.js +16 -16
- package/dist/deploy/tool.d.ts +12 -8
- package/dist/deploy/tool.js +9 -10
- package/dist/deploy/types.d.ts +27 -15
- package/dist/deploy/types.js +3 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/local-dev/index.d.ts +34 -0
- package/dist/local-dev/index.js +37 -0
- package/dist/packaging/electron/archive.d.ts +41 -0
- package/dist/packaging/electron/archive.js +77 -0
- package/dist/packaging/electron/asar-adapter.d.ts +13 -0
- package/dist/packaging/electron/asar-adapter.js +5 -0
- package/dist/packaging/electron/entry.d.ts +9 -0
- package/dist/packaging/electron/entry.js +9 -0
- package/dist/packaging/electron/imports.d.ts +13 -0
- package/dist/packaging/electron/imports.js +44 -0
- package/dist/packaging/electron/node.d.ts +8 -0
- package/dist/packaging/electron/node.js +51 -0
- package/dist/packaging/electron/policies.d.ts +64 -0
- package/dist/packaging/electron/policies.js +63 -0
- package/dist/packaging/electron/ports.d.ts +113 -0
- package/dist/packaging/electron/ports.js +2 -0
- package/dist/packaging/electron/stability.d.ts +9 -0
- package/dist/packaging/electron/stability.js +12 -0
- package/dist/packaging/electron/staging.d.ts +108 -0
- package/dist/packaging/electron/staging.js +249 -0
- package/dist/packaging/electron/typescript.d.ts +7 -0
- package/dist/packaging/electron/typescript.js +18 -0
- package/dist/source-control/commit.d.ts +11 -0
- package/dist/source-control/commit.js +71 -0
- package/dist/source-control/contracts.d.ts +327 -0
- package/dist/source-control/contracts.js +2 -0
- package/dist/source-control/entry.d.ts +6 -0
- package/dist/source-control/entry.js +6 -0
- package/dist/source-control/kit.d.ts +15 -0
- package/dist/source-control/kit.js +17 -0
- package/dist/source-control/registry.d.ts +100 -0
- package/dist/source-control/registry.js +174 -0
- package/dist/source-control/repository-target.d.ts +13 -0
- package/dist/source-control/repository-target.js +28 -0
- package/dist/static-export/contracts.d.ts +138 -0
- package/dist/static-export/contracts.js +5 -0
- package/dist/static-export/entry.d.ts +6 -0
- package/dist/static-export/entry.js +6 -0
- package/dist/static-export/failure-summary.d.ts +12 -0
- package/dist/static-export/failure-summary.js +12 -0
- package/dist/static-export/fetch-adapter.d.ts +6 -0
- package/dist/static-export/fetch-adapter.js +5 -0
- package/dist/static-export/node-adapters.d.ts +11 -0
- package/dist/static-export/node-adapters.js +111 -0
- package/dist/static-export/runner.d.ts +6 -0
- package/dist/static-export/runner.js +135 -0
- package/dist/static-export/transforms.d.ts +53 -0
- package/dist/static-export/transforms.js +154 -0
- package/package.json +82 -5
- package/dist/deploy/cloudflare-pages.d.ts +0 -105
- package/dist/deploy/cloudflare-pages.js +0 -943
- package/dist/deploy/github-pages.d.ts +0 -62
- package/dist/deploy/github-pages.js +0 -373
- package/dist/deploy/netlify.d.ts +0 -40
- package/dist/deploy/netlify.js +0 -299
- package/dist/deploy/vercel.d.ts +0 -56
- package/dist/deploy/vercel.js +0 -258
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { extractAssetUrls, extractCssUrls, normalizeBasePath, outputFileForUrl, redirectOutcomeFor, renderRedirectStub, rewriteRouteBodyForBasePath, safeRelativeOutputFile } from './transforms.js';
|
|
2
|
+
const BASE_PATH_REWRITE_WARNING = "base-path rewriting is a best-effort TEXT rewrite over already-rendered responses — it cannot rewrite a path a theme's own JavaScript constructs at runtime from a string (same category of gap as the unreferenced-theme-file warning, just invisible to this rewrite instead of to the asset crawl).";
|
|
3
|
+
async function request(ctx, url) {
|
|
4
|
+
// Redirects are observed, never followed off the caller's app, for routes and assets alike.
|
|
5
|
+
return ctx.args.fetch({ url: ctx.baseUrl + url }, { init: { redirect: 'manual', headers: new Headers(ctx.args.requestHeaders), signal: AbortSignal.timeout(ctx.timeoutMs) } });
|
|
6
|
+
}
|
|
7
|
+
function failureReason(ctx, url, error) {
|
|
8
|
+
if (error instanceof Error && (error.name === 'AbortError' || error.name === 'TimeoutError'))
|
|
9
|
+
return `GET ${ctx.baseUrl}${url} timed out after ${ctx.timeoutMs}ms`;
|
|
10
|
+
return `GET ${ctx.baseUrl}${url} failed: ${ctx.args.describeError({ error })}`;
|
|
11
|
+
}
|
|
12
|
+
async function writeRoute(ctx, route) {
|
|
13
|
+
// Validate the request path even when the error-page policy supplies a different artifact path.
|
|
14
|
+
const regularOutput = outputFileForUrl({ url: route.path }, { contentRoute: route.kind !== 'well-known' });
|
|
15
|
+
const outputFile = route.kind === 'not-found' ? safeRelativeOutputFile({ value: ctx.args.errorPage.outputFile }) : regularOutput;
|
|
16
|
+
const response = await request(ctx, route.path);
|
|
17
|
+
let body;
|
|
18
|
+
let rawBody;
|
|
19
|
+
let contentType = response.headers.get('content-type');
|
|
20
|
+
if (route.kind === 'redirect') {
|
|
21
|
+
const decision = redirectOutcomeFor({ status: response.status, locationHeader: response.headers.get('location') }, { ...(route.redirectTarget !== undefined ? { manifestTarget: route.redirectTarget } : {}) });
|
|
22
|
+
if (decision.kind === 'failed')
|
|
23
|
+
return { reason: decision.reason };
|
|
24
|
+
body = ctx.args.security.transformHtml({ html: renderRedirectStub({ location: decision.location }, { basePath: ctx.basePath }) });
|
|
25
|
+
contentType = 'text/html; charset=utf-8';
|
|
26
|
+
await response.body?.cancel();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (route.kind === 'not-found' ? !ctx.args.errorPage.acceptStatus({ status: response.status }) : response.status !== 200) {
|
|
30
|
+
await response.body?.cancel();
|
|
31
|
+
return { reason: route.kind === 'not-found' ? `expected an accepted response for the error-page probe, got ${response.status}` : `expected 200, got ${response.status}` };
|
|
32
|
+
}
|
|
33
|
+
rawBody = await response.text();
|
|
34
|
+
body = rewriteRouteBodyForBasePath({ path: route.path, body: rawBody, basePath: ctx.basePath });
|
|
35
|
+
if (route.kind === 'not-found' || /^text\/html\b/i.test(contentType ?? ''))
|
|
36
|
+
body = ctx.args.security.transformHtml({ html: body });
|
|
37
|
+
}
|
|
38
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data: body });
|
|
39
|
+
return { route: { path: route.path, kind: route.kind, outputFile, data: body, contentType }, ...(rawBody !== undefined && route.kind !== 'not-found' ? { crawlHtml: rawBody } : {}) };
|
|
40
|
+
}
|
|
41
|
+
async function writeRoutes(ctx, routes) {
|
|
42
|
+
const succeeded = [], failed = [];
|
|
43
|
+
const assets = new Set();
|
|
44
|
+
for (const route of routes) {
|
|
45
|
+
try {
|
|
46
|
+
const outcome = await writeRoute(ctx, route);
|
|
47
|
+
if ('reason' in outcome) {
|
|
48
|
+
failed.push({ path: route.path, kind: route.kind, reason: outcome.reason });
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
succeeded.push(outcome.route);
|
|
52
|
+
if (outcome.crawlHtml !== undefined)
|
|
53
|
+
for (const url of extractAssetUrls({ html: outcome.crawlHtml, prefixes: ctx.args.assetUrlPrefixes }))
|
|
54
|
+
assets.add(url);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
failed.push({ path: route.path, kind: route.kind, reason: failureReason(ctx, route.path, error) });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { succeeded, failed, assets };
|
|
61
|
+
}
|
|
62
|
+
async function writeAssets(ctx, initial) {
|
|
63
|
+
const succeeded = [], failed = [];
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const queue = initial.map(url => ({ url, crawlCss: true }));
|
|
66
|
+
for (let index = 0; index < queue.length; index++) {
|
|
67
|
+
const { url, crawlCss } = queue[index];
|
|
68
|
+
if (seen.has(url))
|
|
69
|
+
continue;
|
|
70
|
+
seen.add(url);
|
|
71
|
+
try {
|
|
72
|
+
const outputFile = outputFileForUrl({ url });
|
|
73
|
+
const response = await request(ctx, url);
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
await response.body?.cancel();
|
|
76
|
+
failed.push({ url, reason: `GET ${url} -> ${response.status}` });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const data = Buffer.from(await response.arrayBuffer());
|
|
80
|
+
const contentType = response.headers.get('content-type');
|
|
81
|
+
await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data });
|
|
82
|
+
succeeded.push({ url, outputFile, data, contentType });
|
|
83
|
+
if (crawlCss && url.split('?')[0].endsWith('.css')) {
|
|
84
|
+
for (const child of extractCssUrls({ css: data.toString('utf8'), cssUrl: url, prefixes: ctx.args.assetUrlPrefixes }))
|
|
85
|
+
queue.push({ url: child, crawlCss: false });
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
failed.push({ url, reason: failureReason(ctx, url, error) });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return { succeeded, failed };
|
|
93
|
+
}
|
|
94
|
+
async function unreferenced(ctx, manifest, assets) {
|
|
95
|
+
if (!manifest.activeTheme)
|
|
96
|
+
return [];
|
|
97
|
+
const theme = manifest.activeTheme;
|
|
98
|
+
const layout = ctx.args.themeLayout.resolve({ theme });
|
|
99
|
+
const accounted = new Set([`${layout.pagesDir}/index.html`, `${layout.pagesDir}/404.html`]);
|
|
100
|
+
for (const route of manifest.routes)
|
|
101
|
+
if (route.kind === 'theme-page')
|
|
102
|
+
accounted.add(`${layout.pagesDir}/${route.label}.html`);
|
|
103
|
+
for (const asset of assets) {
|
|
104
|
+
const pathname = decodeURIComponent(asset.url.split(/[?#]/)[0]);
|
|
105
|
+
if (pathname.startsWith(layout.assetUrlPrefix))
|
|
106
|
+
accounted.add(pathname.slice(layout.assetUrlPrefix.length));
|
|
107
|
+
}
|
|
108
|
+
return [...await ctx.args.assetSource.listThemeFiles({ theme })].filter(file => !accounted.has(file)).sort();
|
|
109
|
+
}
|
|
110
|
+
/** Drive the caller's actual app, retaining exact written bytes and reporting each failed item.
|
|
111
|
+
* Startup/output/inventory errors throw; an opened app always closes. No singleton state is used.
|
|
112
|
+
*/
|
|
113
|
+
export async function exportSite(required, optional = {}) {
|
|
114
|
+
const basePath = normalizeBasePath({ raw: optional.basePath ?? '' });
|
|
115
|
+
const timeoutMs = optional.fetchTimeoutMs ?? 30_000;
|
|
116
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
117
|
+
throw new RangeError('fetchTimeoutMs must be a positive integer');
|
|
118
|
+
await required.writer.prepare({ outputDir: required.outputDir }, { clean: optional.clean ?? false });
|
|
119
|
+
const manifest = await required.manifest.build({});
|
|
120
|
+
const session = await required.app.open({});
|
|
121
|
+
try {
|
|
122
|
+
const origin = new URL(session.baseUrl);
|
|
123
|
+
if (!['http:', 'https:'].includes(origin.protocol) || origin.username || origin.password || origin.pathname !== '/' || origin.search || origin.hash)
|
|
124
|
+
throw new Error('App session baseUrl must be an HTTP origin without credentials.');
|
|
125
|
+
const ctx = { args: required, baseUrl: origin.origin, basePath, timeoutMs };
|
|
126
|
+
const routes = await writeRoutes(ctx, manifest.routes);
|
|
127
|
+
const assets = await writeAssets(ctx, [...routes.assets]);
|
|
128
|
+
return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: manifest.skipped,
|
|
129
|
+
unreferencedThemeFiles: await unreferenced(ctx, manifest, assets.succeeded), ...(basePath ? { basePath, basePathRewriteWarning: BASE_PATH_REWRITE_WARNING } : {}) };
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
await session.close({});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** Normalize the optional output URL prefix; no product layout is implied. */
|
|
2
|
+
export declare function normalizeBasePath(required: {
|
|
3
|
+
raw: string;
|
|
4
|
+
}): string;
|
|
5
|
+
/** Same bounded text transforms as the exporter origin; crawl the raw body before applying these. */
|
|
6
|
+
export declare function rewriteRouteBodyForBasePath(required: {
|
|
7
|
+
path: string;
|
|
8
|
+
body: string;
|
|
9
|
+
basePath: string;
|
|
10
|
+
}): string;
|
|
11
|
+
type RedirectDecision = {
|
|
12
|
+
kind: 'failed';
|
|
13
|
+
reason: string;
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'redirect-to';
|
|
16
|
+
location: string;
|
|
17
|
+
};
|
|
18
|
+
/** Live Location wins; a manifest target is a fallback only for a genuine 3xx. */
|
|
19
|
+
export declare function redirectOutcomeFor(required: {
|
|
20
|
+
status: number;
|
|
21
|
+
locationHeader: string | null;
|
|
22
|
+
}, optional?: {
|
|
23
|
+
manifestTarget?: string;
|
|
24
|
+
}): RedirectDecision;
|
|
25
|
+
/** Scheme-check before escaping all three URL sinks. Unsafe destinations degrade to '#'. */
|
|
26
|
+
export declare function renderRedirectStub(required: {
|
|
27
|
+
location: string;
|
|
28
|
+
}, optional?: {
|
|
29
|
+
basePath?: string;
|
|
30
|
+
}): string;
|
|
31
|
+
/** Quoted href/src/srcset scan, preserving data-URL commas and ignoring external references. */
|
|
32
|
+
export declare function extractAssetUrls(required: {
|
|
33
|
+
html: string;
|
|
34
|
+
prefixes: readonly string[];
|
|
35
|
+
}): string[];
|
|
36
|
+
/** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
|
|
37
|
+
export declare function extractCssUrls(required: {
|
|
38
|
+
css: string;
|
|
39
|
+
cssUrl: string;
|
|
40
|
+
prefixes: readonly string[];
|
|
41
|
+
}): string[];
|
|
42
|
+
/** Reject path escapes and separators before HTTP or writing; returns forward-slash relative output. */
|
|
43
|
+
export declare function safeRelativeOutputFile(required: {
|
|
44
|
+
value: string;
|
|
45
|
+
}): string;
|
|
46
|
+
/** URL request path to portable artifact path, with decoded traversal refusal. */
|
|
47
|
+
export declare function outputFileForUrl(required: {
|
|
48
|
+
url: string;
|
|
49
|
+
}, optional?: {
|
|
50
|
+
contentRoute?: boolean;
|
|
51
|
+
}): string;
|
|
52
|
+
export {};
|
|
53
|
+
//# sourceMappingURL=transforms.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { ExportPathError } from './contracts.js';
|
|
2
|
+
function escapeHtml(value) { return value.replace(/[&<>"']/g, char => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[char]); }
|
|
3
|
+
function safeHref(value) {
|
|
4
|
+
const href = value.trim();
|
|
5
|
+
if (href.startsWith('#') || /^https?:\/\//i.test(href) || /^mailto:/i.test(href))
|
|
6
|
+
return href;
|
|
7
|
+
if (href.startsWith('/')) {
|
|
8
|
+
try {
|
|
9
|
+
if (new URL(href, 'http://export-safehref.invalid/').origin === 'http://export-safehref.invalid')
|
|
10
|
+
return href;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return '#';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return '#';
|
|
17
|
+
}
|
|
18
|
+
/** Normalize the optional output URL prefix; no product layout is implied. */
|
|
19
|
+
export function normalizeBasePath(required) {
|
|
20
|
+
const trimmed = required.raw.trim().replace(/\/+$/, '');
|
|
21
|
+
if (trimmed === '' || trimmed === '/')
|
|
22
|
+
return '';
|
|
23
|
+
if (/[\\\x00-\x20\x7f?#"'<>]/.test(trimmed) || trimmed.startsWith('//'))
|
|
24
|
+
throw new ExportPathError('Invalid export base path.');
|
|
25
|
+
const normalized = trimmed.startsWith('/') ? trimmed : '/' + trimmed;
|
|
26
|
+
if (normalized.split('/').slice(1).some(segment => !segment || segment === '.' || segment === '..'))
|
|
27
|
+
throw new ExportPathError('Invalid export base path.');
|
|
28
|
+
return normalized;
|
|
29
|
+
}
|
|
30
|
+
function prefix(value, basePath) {
|
|
31
|
+
if (!basePath || !value.startsWith('/') || value.startsWith('//'))
|
|
32
|
+
return value;
|
|
33
|
+
if (value === basePath || value.startsWith(basePath + '/'))
|
|
34
|
+
return value;
|
|
35
|
+
return basePath + value;
|
|
36
|
+
}
|
|
37
|
+
function srcsetRanges(value) {
|
|
38
|
+
const ranges = [];
|
|
39
|
+
let index = 0;
|
|
40
|
+
while (index < value.length) {
|
|
41
|
+
while (index < value.length && /[\s,]/.test(value[index]))
|
|
42
|
+
index++;
|
|
43
|
+
const start = index;
|
|
44
|
+
while (index < value.length && !/\s/.test(value[index]))
|
|
45
|
+
index++;
|
|
46
|
+
let end = index;
|
|
47
|
+
while (end > start && value[end - 1] === ',')
|
|
48
|
+
end--;
|
|
49
|
+
if (end > start)
|
|
50
|
+
ranges.push({ start, end });
|
|
51
|
+
if (end < index)
|
|
52
|
+
continue;
|
|
53
|
+
while (index < value.length && value[index] !== ',')
|
|
54
|
+
index++;
|
|
55
|
+
}
|
|
56
|
+
return ranges;
|
|
57
|
+
}
|
|
58
|
+
function rewriteHtml(html, basePath) {
|
|
59
|
+
if (!basePath)
|
|
60
|
+
return html;
|
|
61
|
+
return html.replace(/\b(href|src|srcset)=(["'])([^"']*)\2/g, (_match, attr, quote, value) => {
|
|
62
|
+
if (attr !== 'srcset')
|
|
63
|
+
return `${attr}=${quote}${prefix(value, basePath)}${quote}`;
|
|
64
|
+
for (const { start, end } of srcsetRanges(value).reverse())
|
|
65
|
+
value = value.slice(0, start) + prefix(value.slice(start, end), basePath) + value.slice(end);
|
|
66
|
+
return `${attr}=${quote}${value}${quote}`;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/** Same bounded text transforms as the exporter origin; crawl the raw body before applying these. */
|
|
70
|
+
export function rewriteRouteBodyForBasePath(required) {
|
|
71
|
+
const { path, body, basePath } = required;
|
|
72
|
+
if (!basePath || path === '/feed.xml')
|
|
73
|
+
return body;
|
|
74
|
+
if (path === '/sitemap.xml')
|
|
75
|
+
return body.replace(/<loc>([^<]*)<\/loc>/g, (_match, value) => `<loc>${prefix(value, basePath)}</loc>`);
|
|
76
|
+
if (path === '/robots.txt')
|
|
77
|
+
return body.replace(/^Sitemap: (.*)$/gm, (_match, value) => `Sitemap: ${prefix(value.trim(), basePath)}`);
|
|
78
|
+
return rewriteHtml(body, basePath);
|
|
79
|
+
}
|
|
80
|
+
/** Live Location wins; a manifest target is a fallback only for a genuine 3xx. */
|
|
81
|
+
export function redirectOutcomeFor(required, optional = {}) {
|
|
82
|
+
if (required.status < 300 || required.status >= 400)
|
|
83
|
+
return { kind: 'failed', reason: `expected a 3xx redirect response, got ${required.status}` };
|
|
84
|
+
const location = required.locationHeader ?? optional.manifestTarget;
|
|
85
|
+
if (!location)
|
|
86
|
+
return { kind: 'failed', reason: 'redirect response carried no Location header' };
|
|
87
|
+
return { kind: 'redirect-to', location };
|
|
88
|
+
}
|
|
89
|
+
/** Scheme-check before escaping all three URL sinks. Unsafe destinations degrade to '#'. */
|
|
90
|
+
export function renderRedirectStub(required, optional = {}) {
|
|
91
|
+
const location = prefix(required.location, optional.basePath ?? '');
|
|
92
|
+
const safeTarget = escapeHtml(safeHref(location));
|
|
93
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="refresh" content="0; url=${safeTarget}"><link rel="canonical" href="${safeTarget}"><title>Redirecting…</title></head><body>Redirecting to <a href="${safeTarget}">${escapeHtml(location)}</a>.</body></html>\n`;
|
|
94
|
+
}
|
|
95
|
+
/** Quoted href/src/srcset scan, preserving data-URL commas and ignoring external references. */
|
|
96
|
+
export function extractAssetUrls(required) {
|
|
97
|
+
const found = new Set();
|
|
98
|
+
for (const match of required.html.matchAll(/\b(href|src|srcset)=(["'])([^"']+)\2/g)) {
|
|
99
|
+
const value = match[3];
|
|
100
|
+
const values = match[1] === 'srcset' ? srcsetRanges(value).map(({ start, end }) => value.slice(start, end)) : [value];
|
|
101
|
+
for (const url of values)
|
|
102
|
+
if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
|
|
103
|
+
found.add(url.split('#')[0]);
|
|
104
|
+
}
|
|
105
|
+
return [...found];
|
|
106
|
+
}
|
|
107
|
+
/** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
|
|
108
|
+
export function extractCssUrls(required) {
|
|
109
|
+
const found = new Set();
|
|
110
|
+
for (const match of required.css.matchAll(/url\(\s*(['"]?)([^'")]+)\1\s*\)/g)) {
|
|
111
|
+
const ref = match[2].trim();
|
|
112
|
+
if (!ref || ref.startsWith('data:'))
|
|
113
|
+
continue;
|
|
114
|
+
let resolved;
|
|
115
|
+
try {
|
|
116
|
+
resolved = new URL(ref, 'http://export-local.invalid' + required.cssUrl);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (resolved.origin !== 'http://export-local.invalid')
|
|
122
|
+
continue;
|
|
123
|
+
if (required.prefixes.some(prefix => resolved.pathname.startsWith(prefix)))
|
|
124
|
+
found.add(resolved.pathname);
|
|
125
|
+
}
|
|
126
|
+
return [...found];
|
|
127
|
+
}
|
|
128
|
+
/** Reject path escapes and separators before HTTP or writing; returns forward-slash relative output. */
|
|
129
|
+
export function safeRelativeOutputFile(required) {
|
|
130
|
+
const { value } = required;
|
|
131
|
+
if (!value || /[\\\x00-\x1f\x7f:]/.test(value) || value.startsWith('/'))
|
|
132
|
+
throw new ExportPathError('Output path resolved outside the output directory — refused');
|
|
133
|
+
if (value.split('/').some(segment => !segment || segment === '.' || segment === '..'))
|
|
134
|
+
throw new ExportPathError('Output path resolved outside the output directory — refused');
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
/** URL request path to portable artifact path, with decoded traversal refusal. */
|
|
138
|
+
export function outputFileForUrl(required, optional = {}) {
|
|
139
|
+
if (!required.url.startsWith('/') || required.url.startsWith('//') || /[\\\x00-\x1f\x7f]/.test(required.url))
|
|
140
|
+
throw new ExportPathError('URL resolved outside the output directory — refused');
|
|
141
|
+
let decoded;
|
|
142
|
+
try {
|
|
143
|
+
decoded = decodeURIComponent(required.url.split(/[?#]/)[0]);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
throw new ExportPathError('Invalid URL encoding — refused');
|
|
147
|
+
}
|
|
148
|
+
const relative = decoded.replace(/^\//, '').replace(/\/+$/, '');
|
|
149
|
+
if (relative)
|
|
150
|
+
safeRelativeOutputFile({ value: relative });
|
|
151
|
+
const output = optional.contentRoute ? (relative ? relative + '/index.html' : 'index.html') : relative;
|
|
152
|
+
return safeRelativeOutputFile({ value: output });
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=transforms.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jini-ai/devops",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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": {
|
|
@@ -14,7 +14,18 @@
|
|
|
14
14
|
"runtime": "node",
|
|
15
15
|
"entries": {
|
|
16
16
|
".": "node",
|
|
17
|
-
"./
|
|
17
|
+
"./source-control": "node",
|
|
18
|
+
"./static-export": "node",
|
|
19
|
+
"./static-export/node": "node",
|
|
20
|
+
"./packaging/electron": "node",
|
|
21
|
+
"./packaging/electron/typescript": "node",
|
|
22
|
+
"./agent-jobs": "node",
|
|
23
|
+
"./deploy": "node",
|
|
24
|
+
"./checks/published-types": "node",
|
|
25
|
+
"./checks/coverage": "node",
|
|
26
|
+
"./checks/node": "node",
|
|
27
|
+
"./local-dev": "node",
|
|
28
|
+
"./deploy/node": "node"
|
|
18
29
|
}
|
|
19
30
|
},
|
|
20
31
|
"type": "module",
|
|
@@ -22,6 +33,36 @@
|
|
|
22
33
|
"main": "./dist/index.js",
|
|
23
34
|
"types": "./dist/index.d.ts",
|
|
24
35
|
"exports": {
|
|
36
|
+
"./source-control": {
|
|
37
|
+
"types": "./dist/source-control/entry.d.ts",
|
|
38
|
+
"import": "./dist/source-control/entry.js",
|
|
39
|
+
"default": "./dist/source-control/entry.js"
|
|
40
|
+
},
|
|
41
|
+
"./static-export": {
|
|
42
|
+
"types": "./dist/static-export/entry.d.ts",
|
|
43
|
+
"import": "./dist/static-export/entry.js",
|
|
44
|
+
"default": "./dist/static-export/entry.js"
|
|
45
|
+
},
|
|
46
|
+
"./static-export/node": {
|
|
47
|
+
"types": "./dist/static-export/node-adapters.d.ts",
|
|
48
|
+
"import": "./dist/static-export/node-adapters.js",
|
|
49
|
+
"default": "./dist/static-export/node-adapters.js"
|
|
50
|
+
},
|
|
51
|
+
"./packaging/electron": {
|
|
52
|
+
"types": "./dist/packaging/electron/entry.d.ts",
|
|
53
|
+
"import": "./dist/packaging/electron/entry.js",
|
|
54
|
+
"default": "./dist/packaging/electron/entry.js"
|
|
55
|
+
},
|
|
56
|
+
"./packaging/electron/typescript": {
|
|
57
|
+
"types": "./dist/packaging/electron/typescript.d.ts",
|
|
58
|
+
"import": "./dist/packaging/electron/typescript.js",
|
|
59
|
+
"default": "./dist/packaging/electron/typescript.js"
|
|
60
|
+
},
|
|
61
|
+
"./agent-jobs": {
|
|
62
|
+
"types": "./dist/agent-jobs/entry.d.ts",
|
|
63
|
+
"import": "./dist/agent-jobs/entry.js",
|
|
64
|
+
"default": "./dist/agent-jobs/entry.js"
|
|
65
|
+
},
|
|
25
66
|
".": {
|
|
26
67
|
"types": "./dist/index.d.ts",
|
|
27
68
|
"import": "./dist/index.js",
|
|
@@ -31,10 +72,38 @@
|
|
|
31
72
|
"types": "./dist/deploy/index.d.ts",
|
|
32
73
|
"import": "./dist/deploy/index.js",
|
|
33
74
|
"default": "./dist/deploy/index.js"
|
|
75
|
+
},
|
|
76
|
+
"./checks/published-types": {
|
|
77
|
+
"types": "./dist/checks/published-types/index.d.ts",
|
|
78
|
+
"import": "./dist/checks/published-types/index.js",
|
|
79
|
+
"default": "./dist/checks/published-types/index.js"
|
|
80
|
+
},
|
|
81
|
+
"./checks/coverage": {
|
|
82
|
+
"types": "./dist/checks/coverage/index.d.ts",
|
|
83
|
+
"import": "./dist/checks/coverage/index.js",
|
|
84
|
+
"default": "./dist/checks/coverage/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./checks/node": {
|
|
87
|
+
"types": "./dist/checks/node.d.ts",
|
|
88
|
+
"import": "./dist/checks/node.js",
|
|
89
|
+
"default": "./dist/checks/node.js"
|
|
90
|
+
},
|
|
91
|
+
"./local-dev": {
|
|
92
|
+
"types": "./dist/local-dev/index.d.ts",
|
|
93
|
+
"import": "./dist/local-dev/index.js",
|
|
94
|
+
"default": "./dist/local-dev/index.js"
|
|
95
|
+
},
|
|
96
|
+
"./deploy/node": {
|
|
97
|
+
"types": "./dist/deploy/node.d.ts",
|
|
98
|
+
"import": "./dist/deploy/node.js",
|
|
99
|
+
"default": "./dist/deploy/node.js"
|
|
34
100
|
}
|
|
35
101
|
},
|
|
36
102
|
"files": [
|
|
37
103
|
"dist",
|
|
104
|
+
"README.md",
|
|
105
|
+
"CHANGELOG.md",
|
|
106
|
+
"LICENSE",
|
|
38
107
|
"!dist/**/*.test.js",
|
|
39
108
|
"!dist/**/*.test.d.ts",
|
|
40
109
|
"!dist/**/*.test.js.map",
|
|
@@ -48,12 +117,20 @@
|
|
|
48
117
|
},
|
|
49
118
|
"dependencies": {
|
|
50
119
|
"undici": "^7.25.0",
|
|
51
|
-
"@jini-ai/core": "0.
|
|
52
|
-
"@jini-ai/platform": "0.
|
|
120
|
+
"@jini-ai/core": "0.4.0",
|
|
121
|
+
"@jini-ai/platform": "0.5.0"
|
|
53
122
|
},
|
|
54
123
|
"devDependencies": {
|
|
55
124
|
"@vitest/coverage-v8": "^2.1.9",
|
|
56
|
-
"@jini-ai/daemon": "0.
|
|
125
|
+
"@jini-ai/daemon": "0.5.0"
|
|
126
|
+
},
|
|
127
|
+
"peerDependencies": {
|
|
128
|
+
"typescript": "^5.6.0"
|
|
129
|
+
},
|
|
130
|
+
"peerDependenciesMeta": {
|
|
131
|
+
"typescript": {
|
|
132
|
+
"optional": true
|
|
133
|
+
}
|
|
57
134
|
},
|
|
58
135
|
"scripts": {
|
|
59
136
|
"build": "tsc -p tsconfig.json",
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { type DeployFile, type DeployPublishInput, type DeployPublishResult, type DeployTarget, type DeploymentUrlCheck, type JsonObject } from './types.js';
|
|
2
|
-
export declare const CLOUDFLARE_PAGES_TARGET_ID = "cloudflare-pages";
|
|
3
|
-
export declare const CLOUDFLARE_PAGES_ASSET_UPLOAD_MAX_FILES = 100;
|
|
4
|
-
export declare const CLOUDFLARE_PAGES_ASSET_UPLOAD_MAX_BODY_BYTES: number;
|
|
5
|
-
export declare const CLOUDFLARE_PAGES_ASSET_MAX_BYTES: number;
|
|
6
|
-
/** Auth/scoping config a caller supplies when constructing a `CloudflarePagesDeployTarget`. */
|
|
7
|
-
export interface CloudflarePagesDeployConfig {
|
|
8
|
-
token: string;
|
|
9
|
-
accountId: string;
|
|
10
|
-
}
|
|
11
|
-
/** A caller-selected Cloudflare zone + subdomain prefix to bind as a custom domain. */
|
|
12
|
-
export interface CloudflarePagesCustomDomainSelection {
|
|
13
|
-
zoneId: string;
|
|
14
|
-
zoneName: string;
|
|
15
|
-
domainPrefix: string;
|
|
16
|
-
}
|
|
17
|
-
/** Opaque bookkeeping from a prior publish's custom-domain setup, fed back in to make DNS-record reuse idempotent. */
|
|
18
|
-
export interface CloudflarePagesPriorCustomDomainMetadata {
|
|
19
|
-
dnsRecordId?: string;
|
|
20
|
-
marker?: string;
|
|
21
|
-
}
|
|
22
|
-
/** Optional `DeployPublishInput.metadata` keys this target reads; everything else is ignored. */
|
|
23
|
-
export interface CloudflarePagesPublishMetadata extends JsonObject {
|
|
24
|
-
customDomain?: CloudflarePagesCustomDomainSelection;
|
|
25
|
-
priorCustomDomain?: CloudflarePagesPriorCustomDomainMetadata;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Deterministic content hash used purely as Cloudflare Pages' per-asset
|
|
29
|
-
* dedup key (the direct-upload protocol needs a stable 32-hex-char key per
|
|
30
|
-
* file, not a specific algorithm). Swapped from the OD origin's
|
|
31
|
-
* `blake3-wasm` to Node's built-in `crypto` so this package carries no
|
|
32
|
-
* native/WASM dependency — see `source-map.md`.
|
|
33
|
-
*/
|
|
34
|
-
export declare function cloudflarePagesAssetHash(file: Pick<DeployFile, 'file' | 'data'>): string;
|
|
35
|
-
/**
|
|
36
|
-
* Splits a file set into upload batches that respect Cloudflare Pages'
|
|
37
|
-
* per-request file-count and body-size limits.
|
|
38
|
-
*
|
|
39
|
-
* @param files - Files with their pre-computed content hash.
|
|
40
|
-
* @param limits - Overridable file-count/byte-size caps (default to the
|
|
41
|
-
* Cloudflare Pages direct-upload limits).
|
|
42
|
-
* @returns An array of batches; each batch's estimated encoded size stays
|
|
43
|
-
* under `maxBytes` and its length under `maxFiles` (a single
|
|
44
|
-
* larger-than-cap file still gets its own batch rather than being dropped).
|
|
45
|
-
* @complexity O(n) in the number of files.
|
|
46
|
-
* @overallScore 100/100
|
|
47
|
-
*/
|
|
48
|
-
export declare function chunkCloudflarePagesAssetUploads(files: {
|
|
49
|
-
hash: string;
|
|
50
|
-
data: Buffer | Uint8Array | string;
|
|
51
|
-
contentType?: string;
|
|
52
|
-
}[], { maxFiles, maxBytes }?: {
|
|
53
|
-
maxFiles?: number | undefined;
|
|
54
|
-
maxBytes?: number | undefined;
|
|
55
|
-
}): (typeof files)[number][][];
|
|
56
|
-
/** Lists active, fully-onboarded zones on the account — used to populate a custom-domain selection UI. */
|
|
57
|
-
export declare function listCloudflarePagesZones(config: CloudflarePagesDeployConfig): Promise<{
|
|
58
|
-
zones: {
|
|
59
|
-
id: string;
|
|
60
|
-
name: string;
|
|
61
|
-
status: string | undefined;
|
|
62
|
-
type: string | undefined;
|
|
63
|
-
}[];
|
|
64
|
-
}>;
|
|
65
|
-
/**
|
|
66
|
-
* `DeployTarget` adapter for Cloudflare Pages' direct-upload API: ensures a
|
|
67
|
-
* Pages project exists, uploads the file set as content-addressed assets,
|
|
68
|
-
* creates a deployment, waits for the `pages.dev` URL to be reachable, and
|
|
69
|
-
* (optionally, when `input.metadata.customDomain` is supplied) binds a
|
|
70
|
-
* custom domain via a managed CNAME + Pages domain record.
|
|
71
|
-
*
|
|
72
|
-
* Genericized from the origin product's daemon deploy module's
|
|
73
|
-
* `deployToCloudflarePages` family: the origin's persisted local config file
|
|
74
|
-
* and product-specific project naming are gone — the caller supplies
|
|
75
|
-
* `{ token, accountId }` directly and a stable `projectName` label.
|
|
76
|
-
*/
|
|
77
|
-
export declare class CloudflarePagesDeployTarget implements DeployTarget {
|
|
78
|
-
private readonly config;
|
|
79
|
-
readonly id = "cloudflare-pages";
|
|
80
|
-
constructor(config: CloudflarePagesDeployConfig);
|
|
81
|
-
/**
|
|
82
|
-
* Publishes `input.files` to Cloudflare Pages and waits for the resulting
|
|
83
|
-
* `pages.dev` URL to be reachable, optionally binding a custom domain.
|
|
84
|
-
*
|
|
85
|
-
* @param input - File set, a caller-chosen project name label, and
|
|
86
|
-
* optional `metadata.customDomain`/`metadata.priorCustomDomain`.
|
|
87
|
-
* @returns The published deployment's URL/status, with any custom-domain
|
|
88
|
-
* outcome folded into `providerMetadata`.
|
|
89
|
-
* @throws {DeployError} If `token`/`accountId` are missing, the derived
|
|
90
|
-
* project name is empty, or any Cloudflare API call fails.
|
|
91
|
-
* @complexity O(files) to hash/chunk the asset set, plus a bounded
|
|
92
|
-
* reachability wait; DNS/domain setup is O(1) additional round-trips.
|
|
93
|
-
* @overallScore 95/100
|
|
94
|
-
* @tradeoffs Custom-domain setup errors are captured into the returned
|
|
95
|
-
* `providerMetadata` rather than thrown, matching the OD origin's
|
|
96
|
-
* behavior of always returning the base pages.dev result even if the
|
|
97
|
-
* custom domain step fails partway — flagged since a caller that only
|
|
98
|
-
* checks `status`/`throws` could miss a degraded custom-domain state
|
|
99
|
-
* without also inspecting `providerMetadata`.
|
|
100
|
-
*/
|
|
101
|
-
publish(input: DeployPublishInput): Promise<DeployPublishResult>;
|
|
102
|
-
/** Probes `url` with the shared reachability checker (no Cloudflare-specific auth-wall detection is needed). */
|
|
103
|
-
checkReachability(url: string): Promise<DeploymentUrlCheck>;
|
|
104
|
-
}
|
|
105
|
-
//# sourceMappingURL=cloudflare-pages.d.ts.map
|