@jini-ai/devops 0.5.3 → 0.5.5

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.
@@ -7,6 +7,8 @@ export declare function createSourceControlProviderKit(required: {
7
7
  describeTransportError(required: {
8
8
  error: unknown;
9
9
  }): DescribedTransportError;
10
+ }, optional?: {
11
+ fetchRedirectPolicy?: "guard" | "caller";
10
12
  }): SourceControlProviderKit;
11
13
  /** Adapt a host-selected native/guarded fetch without choosing a global transport. */
12
14
  export declare function createSourceControlFetchAdapter(required: {
@@ -1,9 +1,9 @@
1
1
  import { assertNotRedirected, redirectGuardInit } from '../core/redirect-guard.js';
2
2
  import { DeployError } from '../core/deploy-types.js';
3
3
  /** Build a kit without globals or a silently missing guarded HTTP client. */
4
- export function createSourceControlProviderKit(required) {
4
+ export function createSourceControlProviderKit(required, optional = {}) {
5
5
  return {
6
- fetch: ({ url, init }) => required.fetch({ url }, { init: redirectGuardInit({ init }) }),
6
+ fetch: ({ url, init }) => required.fetch({ url }, { init: optional.fetchRedirectPolicy === "caller" ? init : redirectGuardInit({ init }) }),
7
7
  redirectGuardInit: ({ init }) => redirectGuardInit({ init }),
8
8
  assertNotRedirected: ({ response, hostName }) => assertNotRedirected({ resp: response, providerLabel: hostName }),
9
9
  isRedirectRefusal: ({ error }) => error instanceof DeployError,
@@ -1,4 +1,4 @@
1
- import type { DescriptorExtensionReader, LoadedSourceControlProvider, ProviderCatalogPort, SourceControlProvider, SourceControlProviderDescriptor, SourceControlProviderKit, SourceControlProviderRegistry } from './contracts.js';
1
+ import type { SourceControlProviderOperations, DescriptorExtensionReader, ProviderCatalogPort, SourceControlProvider, SourceControlProviderDescriptor, SourceControlProviderKit, SourceControlProviderRegistry } from './contracts.js';
2
2
  type ParseResult = {
3
3
  ok: true;
4
4
  descriptors: SourceControlProviderDescriptor[];
@@ -6,11 +6,23 @@ type ParseResult = {
6
6
  ok: false;
7
7
  reason: string;
8
8
  };
9
+ export interface DescriptorPathPolicy {
10
+ /** Trusted catalogs may defer module containment to their own fail-closed import gate. */
11
+ modulePath?(required: {
12
+ path: string;
13
+ }): boolean;
14
+ folderPath?(required: {
15
+ path: string;
16
+ }): boolean;
17
+ }
9
18
  /** Parse generic host facts; the caller validates credential/i18n extensions. Unknown keys are ignored. */
10
19
  export declare function parseSourceControlProvidersFile(required: {
11
20
  raw: string;
12
21
  readExtensions: DescriptorExtensionReader;
13
- }): ParseResult;
22
+ }, optional?: DescriptorPathPolicy): ParseResult;
23
+ export declare function sourceControlProviderModuleError({ value }: {
24
+ value: unknown;
25
+ }, _optional?: {}): string | null;
14
26
  /** Fresh instance-local registry; only the catalog can grant the ability to import trusted modules. */
15
27
  export declare function loadSourceControlProviderRegistry(required: {
16
28
  workspaceId: string;
@@ -22,10 +34,45 @@ export declare function loadSourceControlProviderRegistry(required: {
22
34
  }): string;
23
35
  }): Promise<SourceControlProviderRegistry>;
24
36
  /** Build operations and host facts without allowing module operations to overwrite declared facts. */
25
- export declare function buildLoadedSourceControlProvider(required: {
26
- loaded: LoadedSourceControlProvider;
27
- kit: SourceControlProviderKit;
28
- }): SourceControlProvider;
37
+ export interface SharedLoadedProvider<Kit, Operations> {
38
+ readonly descriptor: SourceControlProviderDescriptor;
39
+ readonly module: {
40
+ create(required: {
41
+ kit: Kit;
42
+ }): Operations;
43
+ validateTarget?: (required: {
44
+ owner: string;
45
+ repo: string;
46
+ }) => string | null;
47
+ };
48
+ }
49
+ export declare function buildLoadedSourceControlProvider<Kit, Operations>(required: {
50
+ loaded: SharedLoadedProvider<Kit, Operations>;
51
+ kit: Kit;
52
+ }, _optional?: {}): Operations & import('./contracts.js').SourceControlHostFacts & {
53
+ validateTarget?: (required: {
54
+ owner: string;
55
+ repo: string;
56
+ }) => string | null;
57
+ };
58
+ export interface SharedProviderRegistry<Kit, Operations> {
59
+ list(required: Record<string, never>): readonly SharedLoadedProvider<Kit, Operations>[];
60
+ get(required: {
61
+ providerId: string;
62
+ }): SharedLoadedProvider<Kit, Operations> | undefined;
63
+ readonly refusals: readonly string[];
64
+ }
65
+ export interface SharedBuildProviderArgs<Kit = SourceControlProviderKit, Operations = SourceControlProviderOperations, Registry extends SharedProviderRegistry<Kit, Operations> = SharedProviderRegistry<Kit, Operations>> {
66
+ workspaceId: string;
67
+ kit: Kit;
68
+ load(required: {
69
+ workspaceId: string;
70
+ }): Promise<Registry>;
71
+ noProviderMessage(required: {
72
+ registry: Registry;
73
+ providerId?: string;
74
+ }): string;
75
+ }
29
76
  export type BuildSourceControlProviderResult = {
30
77
  ok: true;
31
78
  provider: SourceControlProvider;
@@ -47,7 +94,28 @@ export interface BuildProviderArgs {
47
94
  }): string;
48
95
  }
49
96
  /** Operator navigation/copy is supplied by the host, with no descriptor or product defaults. */
50
- export declare function buildSourceControlProvider(required: BuildProviderArgs): Promise<BuildSourceControlProviderResult>;
97
+ export declare function buildSourceControlProvider<Kit = SourceControlProviderKit, Operations = SourceControlProviderOperations, Registry extends SharedProviderRegistry<Kit, Operations> = SharedProviderRegistry<Kit, Operations>>(required: Omit<SharedBuildProviderArgs<Kit, Operations, Registry>, "noProviderMessage"> & {
98
+ providerId: string;
99
+ noProviderMessage(required: {
100
+ registry: Registry;
101
+ providerId: string;
102
+ }): string;
103
+ }, _optional?: {}): Promise<{
104
+ ok: false;
105
+ message: string;
106
+ refusals: readonly string[];
107
+ provider?: never;
108
+ } | {
109
+ ok: true;
110
+ provider: Operations & import("./contracts.js").SourceControlHostFacts & {
111
+ validateTarget?: (required: {
112
+ owner: string;
113
+ repo: string;
114
+ }) => string | null;
115
+ };
116
+ message?: never;
117
+ refusals?: never;
118
+ }>;
51
119
  export interface BuildProvidersArgs {
52
120
  workspaceId: string;
53
121
  kit: SourceControlProviderKit;
@@ -59,15 +127,37 @@ export interface BuildProvidersArgs {
59
127
  }): string;
60
128
  }
61
129
  /** Build every enabled provider over the same guarded kit, in catalog order. */
62
- export declare function buildSourceControlProviders(required: BuildProvidersArgs): Promise<{
63
- providers: readonly SourceControlProvider[];
130
+ export declare function buildSourceControlProviders<Kit = SourceControlProviderKit, Operations = SourceControlProviderOperations, Registry extends SharedProviderRegistry<Kit, Operations> = SharedProviderRegistry<Kit, Operations>>(required: SharedBuildProviderArgs<Kit, Operations, Registry>, _optional?: {}): Promise<{
131
+ providers: (Operations & import("./contracts.js").SourceControlHostFacts & {
132
+ validateTarget?: (required: {
133
+ owner: string;
134
+ repo: string;
135
+ }) => string | null;
136
+ })[];
64
137
  refusals: readonly string[];
65
138
  noProviderMessage: string;
66
139
  }>;
67
140
  /** Build and select a provider for one custom credential's API origin. */
68
- export declare function buildSourceControlProviderForApi(required: BuildProvidersArgs & {
141
+ export declare function buildSourceControlProviderForApi<Kit = SourceControlProviderKit, Operations = SourceControlProviderOperations, Registry extends SharedProviderRegistry<Kit, Operations> = SharedProviderRegistry<Kit, Operations>>(required: SharedBuildProviderArgs<Kit, Operations, Registry> & {
69
142
  baseUrl: string;
70
- }): Promise<BuildSourceControlProviderResult>;
143
+ }, optional?: {
144
+ missingProviderMessage?: (required: {
145
+ origin: string | undefined;
146
+ baseUrl: string;
147
+ }) => string;
148
+ }): Promise<{
149
+ ok: true;
150
+ provider: Operations & import("./contracts.js").SourceControlHostFacts & {
151
+ validateTarget?: (required: {
152
+ owner: string;
153
+ repo: string;
154
+ }) => string | null;
155
+ };
156
+ } | {
157
+ refusals: readonly string[];
158
+ ok: false;
159
+ message: string;
160
+ }>;
71
161
  /** Find the folder or ancestor that has provider-defined reserved semantics, ignoring case. */
72
162
  export declare function findReservedPath(required: {
73
163
  folder: string;
@@ -85,13 +175,20 @@ export declare function originOf(required: {
85
175
  url: string;
86
176
  }): string | undefined;
87
177
  /** Exact API-origin match first; a sole provider may serve a self-hosted origin. */
88
- export declare function pickSourceControlProviderForApi(required: {
89
- providers: readonly SourceControlProvider[];
178
+ export declare function pickSourceControlProviderForApi<Provider extends {
179
+ apiOrigin: string;
180
+ }>(required: {
181
+ providers: readonly Provider[];
90
182
  baseUrl: string;
91
183
  noProviderMessage: string;
184
+ }, optional?: {
185
+ missingProviderMessage?: (required: {
186
+ origin: string | undefined;
187
+ baseUrl: string;
188
+ }) => string;
92
189
  }): {
93
190
  ok: true;
94
- provider: SourceControlProvider;
191
+ provider: Provider;
95
192
  } | {
96
193
  ok: false;
97
194
  message: string;
@@ -2,6 +2,7 @@ function object(value) { return value !== null && typeof value === 'object' && !
2
2
  function relativeModule(value) {
3
3
  return typeof value === 'string' && value.endsWith('.mjs') && !/[\\\x00-\x1f\x7f:]/.test(value) && value.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..');
4
4
  }
5
+ /** True for `https://host[:port]` exactly — what `new URL(x).origin` gives back. @complexity O(1). */
5
6
  function httpsOrigin(value) {
6
7
  if (typeof value !== 'string')
7
8
  return false;
@@ -13,10 +14,10 @@ function httpsOrigin(value) {
13
14
  return false;
14
15
  }
15
16
  }
16
- function pathList(value) {
17
- return Array.isArray(value) && value.length <= 20 && value.every(entry => typeof entry === 'string' && entry.length <= 200 && !/[\\\x00-\x1f\x7f:]/.test(entry) && entry.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..'));
17
+ function pathList(value, policy = {}) {
18
+ return Array.isArray(value) && value.length <= 20 && value.every(entry => typeof entry === 'string' && entry.length <= 200 && (policy.folderPath ? policy.folderPath({ path: entry }) : !/[\\\x00-\x1f\x7f:]/.test(entry) && entry.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..')));
18
19
  }
19
- function parseDescriptor(entry, at, readExtensions) {
20
+ function parseDescriptor(entry, at, readExtensions, policy) {
20
21
  if (!object(entry))
21
22
  return `${at} must be an object`;
22
23
  const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths, module } = entry;
@@ -28,19 +29,19 @@ function parseDescriptor(entry, at, readExtensions) {
28
29
  return `${at}.apiOrigin must be an https origin with no path`;
29
30
  if (maxFileBytes !== undefined && (typeof maxFileBytes !== 'number' || !Number.isSafeInteger(maxFileBytes) || maxFileBytes <= 0))
30
31
  return `${at}.maxFileBytes must be a positive integer`;
31
- if (reservedPaths !== undefined && !pathList(reservedPaths))
32
+ if (reservedPaths !== undefined && !pathList(reservedPaths, policy))
32
33
  return `${at}.reservedPaths must be a list of at most 20 relative folder paths`;
33
- if (workflowPaths !== undefined && !pathList(workflowPaths))
34
+ if (workflowPaths !== undefined && !pathList(workflowPaths, policy))
34
35
  return `${at}.workflowPaths must be a list of at most 20 relative folder paths`;
35
- if (!relativeModule(module))
36
+ if (!(typeof module === "string" && module.endsWith(".mjs") && (policy.modulePath ? policy.modulePath({ path: module }) : relativeModule(module))))
36
37
  return `${at}.module must be a relative path ending in .mjs`;
37
38
  const extras = readExtensions({ entry, at });
38
39
  if (!extras.ok)
39
40
  return extras.reason;
40
- return { ...extras.extensions, id, label, apiOrigin, module, ...(typeof maxFileBytes === 'number' ? { maxFileBytes } : {}), ...(pathList(reservedPaths) ? { reservedPaths } : {}), ...(pathList(workflowPaths) ? { workflowPaths } : {}) };
41
+ return { ...extras.extensions, id, label, apiOrigin, module, ...(typeof maxFileBytes === 'number' ? { maxFileBytes } : {}), ...(pathList(reservedPaths, policy) ? { reservedPaths } : {}), ...(pathList(workflowPaths, policy) ? { workflowPaths } : {}) };
41
42
  }
42
43
  /** Parse generic host facts; the caller validates credential/i18n extensions. Unknown keys are ignored. */
43
- export function parseSourceControlProvidersFile(required) {
44
+ export function parseSourceControlProvidersFile(required, optional = {}) {
44
45
  let value;
45
46
  try {
46
47
  value = JSON.parse(required.raw);
@@ -54,7 +55,7 @@ export function parseSourceControlProvidersFile(required) {
54
55
  return { ok: false, reason: 'providers must be an array' };
55
56
  const descriptors = [];
56
57
  for (const [index, entry] of value.providers.entries()) {
57
- const descriptor = parseDescriptor(entry, `providers[${index}]`, required.readExtensions);
58
+ const descriptor = parseDescriptor(entry, `providers[${index}]`, required.readExtensions, optional);
58
59
  if (typeof descriptor === 'string')
59
60
  return { ok: false, reason: descriptor };
60
61
  if (descriptors.some(prior => prior.id === descriptor.id))
@@ -63,7 +64,7 @@ export function parseSourceControlProvidersFile(required) {
63
64
  }
64
65
  return { ok: true, descriptors };
65
66
  }
66
- function moduleError(value) {
67
+ export function sourceControlProviderModuleError({ value }, _optional = {}) {
67
68
  if (!object(value) || typeof value.create !== 'function')
68
69
  return 'its module has no create() function';
69
70
  if (value.validateTarget !== undefined && typeof value.validateTarget !== 'function')
@@ -102,7 +103,7 @@ export async function loadSourceControlProviderRegistry(required) {
102
103
  for (const descriptor of parsed.descriptors) {
103
104
  try {
104
105
  const candidate = await item.importModule({ relativePath: descriptor.module });
105
- const reason = moduleError(candidate);
106
+ const reason = sourceControlProviderModuleError({ value: candidate });
106
107
  if (reason) {
107
108
  refusals.push(`${item.pluginId}/${descriptor.id}: ${reason}`);
108
109
  continue;
@@ -117,15 +118,14 @@ export async function loadSourceControlProviderRegistry(required) {
117
118
  const frozen = Object.freeze(providers.slice());
118
119
  return { list: () => frozen, get: ({ providerId }) => frozen.find(provider => provider.descriptor.id === providerId), refusals: Object.freeze(refusals.slice()), switchedOff };
119
120
  }
120
- /** Build operations and host facts without allowing module operations to overwrite declared facts. */
121
- export function buildLoadedSourceControlProvider(required) {
121
+ export function buildLoadedSourceControlProvider(required, _optional = {}) {
122
122
  const { loaded, kit } = required;
123
123
  const { id, label, apiOrigin, maxFileBytes, reservedPaths, workflowPaths } = loaded.descriptor;
124
124
  return { ...loaded.module.create({ kit }), ...(loaded.module.validateTarget ? { validateTarget: loaded.module.validateTarget } : {}), id, label, apiOrigin,
125
125
  ...(maxFileBytes !== undefined ? { maxFileBytes } : {}), ...(reservedPaths !== undefined ? { reservedPaths } : {}), ...(workflowPaths !== undefined ? { workflowPaths } : {}) };
126
126
  }
127
127
  /** Operator navigation/copy is supplied by the host, with no descriptor or product defaults. */
128
- export async function buildSourceControlProvider(required) {
128
+ export async function buildSourceControlProvider(required, _optional = {}) {
129
129
  const registry = await required.load({ workspaceId: required.workspaceId });
130
130
  const loaded = registry.get({ providerId: required.providerId });
131
131
  if (!loaded)
@@ -133,14 +133,14 @@ export async function buildSourceControlProvider(required) {
133
133
  return { ok: true, provider: buildLoadedSourceControlProvider({ loaded, kit: required.kit }) };
134
134
  }
135
135
  /** Build every enabled provider over the same guarded kit, in catalog order. */
136
- export async function buildSourceControlProviders(required) {
136
+ export async function buildSourceControlProviders(required, _optional = {}) {
137
137
  const registry = await required.load({ workspaceId: required.workspaceId });
138
138
  return { providers: registry.list({}).map(loaded => buildLoadedSourceControlProvider({ loaded, kit: required.kit })), refusals: registry.refusals, noProviderMessage: required.noProviderMessage({ registry }) };
139
139
  }
140
140
  /** Build and select a provider for one custom credential's API origin. */
141
- export async function buildSourceControlProviderForApi(required) {
141
+ export async function buildSourceControlProviderForApi(required, optional = {}) {
142
142
  const built = await buildSourceControlProviders(required);
143
- const picked = pickSourceControlProviderForApi({ providers: built.providers, baseUrl: required.baseUrl, noProviderMessage: built.noProviderMessage });
143
+ const picked = pickSourceControlProviderForApi({ providers: built.providers, baseUrl: required.baseUrl, noProviderMessage: built.noProviderMessage }, optional);
144
144
  if (picked.ok)
145
145
  return picked;
146
146
  return { ...picked, refusals: built.refusals };
@@ -164,11 +164,11 @@ export function originOf(required) {
164
164
  }
165
165
  }
166
166
  /** Exact API-origin match first; a sole provider may serve a self-hosted origin. */
167
- export function pickSourceControlProviderForApi(required) {
167
+ export function pickSourceControlProviderForApi(required, optional = {}) {
168
168
  const origin = originOf({ url: required.baseUrl });
169
169
  const match = required.providers.find(provider => originOf({ url: provider.apiOrigin }) === origin) ?? (required.providers.length === 1 ? required.providers[0] : undefined);
170
170
  if (match)
171
171
  return { ok: true, provider: match };
172
- return { ok: false, message: required.providers.length === 0 ? required.noProviderMessage : `No enabled provider supplies source control for ${origin ?? required.baseUrl}.` };
172
+ return { ok: false, message: required.providers.length === 0 ? required.noProviderMessage : (optional.missingProviderMessage?.({ origin, baseUrl: required.baseUrl }) ?? `No enabled provider supplies source control for ${origin ?? required.baseUrl}.`) };
173
173
  }
174
174
  //# sourceMappingURL=registry.js.map
@@ -1,3 +1,5 @@
1
+ /** Owner and repo, whatever the host: one URL path segment each, so never empty, never `.`/`..`,
2
+ * never a slash, whitespace or control character. */
1
3
  const GENERIC_SEGMENT_PATTERN = /^[^\s/\\\x00-\x1f\x7f]{1,100}$/;
2
4
  const BRANCH_PATTERN = /^[A-Za-z0-9._/-]{1,250}$/;
3
5
  function isGenericSegment(value) {
@@ -79,6 +79,12 @@ export interface FailedAsset {
79
79
  url: string;
80
80
  reason: string;
81
81
  }
82
+ export interface DroppedReference {
83
+ page: string;
84
+ url: string;
85
+ attribute: string;
86
+ reason: 'not-exported' | 'needs-server';
87
+ }
82
88
  export interface ExportReport {
83
89
  outputDir: string;
84
90
  routes: {
@@ -91,6 +97,9 @@ export interface ExportReport {
91
97
  };
92
98
  skippedManifestEntries: ManifestSkip[];
93
99
  unreferencedThemeFiles: string[];
100
+ /** Site-relative references missing from written HTML's output, deduped per page + URL (ignoring
101
+ * queries/fragments and the export base path). At most 200 entries; a full list may be truncated at that cap. */
102
+ droppedReferences: DroppedReference[];
94
103
  basePath?: string;
95
104
  basePathRewriteWarning?: string;
96
105
  }
@@ -130,6 +139,12 @@ export interface ExportSiteArgs {
130
139
  describeError(required: {
131
140
  error: unknown;
132
141
  }): string;
142
+ /** Further routes a written page links to (e.g. see-more batch URLs), exported in turn and
143
+ * themselves scanned, so a chain of batches is followed to its end. Given the raw, pre-rewrite html. */
144
+ discoverRoutes?(required: {
145
+ path: string;
146
+ html: string;
147
+ }): readonly ManifestRoute[];
133
148
  }
134
149
  export interface ExportSiteOptions {
135
150
  clean?: boolean;
@@ -1,5 +1,5 @@
1
1
  import { ExportPathError } from "./contracts.js";
2
- import { extractAssetUrls, extractCssUrls, normalizeBasePath, outputFileForUrl, redirectOutcomeFor, renderRedirectStub, rewriteRouteBodyForBasePath, safeRelativeOutputFile } from './transforms.js';
2
+ import { extractAssetUrls, extractHtmlReferences, extractCssUrls, normalizeBasePath, outputFileForUrl, redirectOutcomeFor, renderRedirectStub, rewriteRouteBodyForBasePath, safeRelativeOutputFile } from './transforms.js';
3
3
  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).";
4
4
  async function request(ctx, url) {
5
5
  // Redirects are observed, never followed off the caller's app, for routes and assets alike.
@@ -39,10 +39,17 @@ async function writeRoute(ctx, route) {
39
39
  await ctx.args.writer.write({ outputDir: ctx.args.outputDir, outputFile, data: body });
40
40
  return { route: { path: route.path, kind: route.kind, outputFile, data: body, contentType }, ...(rawBody !== undefined && route.kind !== 'not-found' ? { crawlHtml: rawBody } : {}) };
41
41
  }
42
+ /** Most routes `discoverRoutes` may add to one export; the rest are reported as skipped. */
43
+ const MAX_DISCOVERED_ROUTES = 2000;
42
44
  async function writeRoutes(ctx, routes) {
43
- const succeeded = [], failed = [];
45
+ const succeeded = [], failed = [], skipped = [];
44
46
  const assets = new Set();
45
- for (const route of routes) {
47
+ // A queue, not a loop over the manifest: discovered routes are appended and scanned in turn.
48
+ const queue = [...routes];
49
+ const queued = new Set(routes.map(route => route.path));
50
+ let discovered = 0;
51
+ for (let index = 0; index < queue.length; index++) {
52
+ const route = queue[index];
46
53
  try {
47
54
  const outcome = await writeRoute(ctx, route);
48
55
  if ('reason' in outcome) {
@@ -50,15 +57,27 @@ async function writeRoutes(ctx, routes) {
50
57
  continue;
51
58
  }
52
59
  succeeded.push(outcome.route);
53
- if (outcome.crawlHtml !== undefined)
54
- for (const url of extractAssetUrls({ html: outcome.crawlHtml, prefixes: ctx.args.assetUrlPrefixes }))
55
- assets.add(url);
60
+ if (outcome.crawlHtml === undefined)
61
+ continue;
62
+ for (const url of extractAssetUrls({ html: outcome.crawlHtml, prefixes: ctx.args.assetUrlPrefixes }))
63
+ assets.add(url);
64
+ for (const next of ctx.args.discoverRoutes?.({ path: route.path, html: outcome.crawlHtml }) ?? []) {
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
+ }
56
75
  }
57
76
  catch (error) {
58
77
  failed.push({ path: route.path, kind: route.kind, reason: failureReason(ctx, route.path, error) });
59
78
  }
60
79
  }
61
- return { succeeded, failed, assets };
80
+ return { succeeded, failed, assets, skipped };
62
81
  }
63
82
  async function writeAssets(ctx, initial) {
64
83
  const succeeded = [], failed = [];
@@ -108,6 +127,60 @@ async function unreferenced(ctx, manifest, assets) {
108
127
  }
109
128
  return [...await ctx.args.assetSource.listThemeFiles({ theme })].filter(file => !accounted.has(file)).sort();
110
129
  }
130
+ /** Compare written HTML with this run's outputs only; no requests or filesystem reads.
131
+ * At most 200 drops are retained. O(output count + scanned HTML bytes) time; output paths plus
132
+ * at most 200 dedupe keys are retained. Forms take precedence over links to the same URL.
133
+ */
134
+ function droppedReferences(required) {
135
+ const origin = required.baseUrl;
136
+ const normalize = (url) => new URL(url, origin).pathname.replace(/\/+$/, '') || '/';
137
+ const written = new Set();
138
+ for (const item of [...required.routes, ...required.assets]) {
139
+ const file = '/' + item.outputFile;
140
+ written.add(normalize(file));
141
+ if (file.endsWith('/index.html'))
142
+ written.add(normalize(file.slice(0, -10)));
143
+ }
144
+ for (const route of required.routes)
145
+ if (route.kind !== 'not-found')
146
+ written.add(normalize(route.path));
147
+ for (const asset of required.assets)
148
+ written.add(normalize(asset.url));
149
+ 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;
153
+ for (const reference of extractHtmlReferences({ html: route.data })) {
154
+ const value = reference.url.trim();
155
+ if (((!value || value.startsWith('?')) && reference.attribute !== 'action') || value.startsWith('#'))
156
+ continue;
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 });
180
+ }
181
+ }
182
+ return [...dropped.values()];
183
+ }
111
184
  /** Drive the caller's actual app, retaining exact written bytes and reporting each failed item.
112
185
  * Startup/output/inventory errors throw; an opened app always closes. No singleton state is used.
113
186
  */
@@ -126,7 +199,8 @@ export async function exportSite(required, optional = {}) {
126
199
  const ctx = { args: required, baseUrl: origin.origin, basePath, timeoutMs };
127
200
  const routes = await writeRoutes(ctx, manifest.routes);
128
201
  const assets = await writeAssets(ctx, [...routes.assets]);
129
- return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: manifest.skipped,
202
+ return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: [...manifest.skipped, ...routes.skipped],
203
+ droppedReferences: droppedReferences({ routes: routes.succeeded, assets: assets.succeeded, basePath, baseUrl: ctx.baseUrl }),
130
204
  unreferencedThemeFiles: await unreferenced(ctx, manifest, assets.succeeded), ...(basePath ? { basePath, basePathRewriteWarning: BASE_PATH_REWRITE_WARNING } : {}) };
131
205
  }
132
206
  finally {
@@ -28,7 +28,14 @@ export declare function renderRedirectStub(required: {
28
28
  }, optional?: {
29
29
  basePath?: string;
30
30
  }): string;
31
- /** Quoted href/src/srcset scan, preserving data-URL commas and ignoring external references. */
31
+ /** HTML URL attributes; form actions are diagnostic references, never crawled as assets. */
32
+ export declare function extractHtmlReferences(required: {
33
+ html: string;
34
+ }, _optional?: Record<string, never>): Generator<{
35
+ url: string;
36
+ attribute: string;
37
+ }>;
38
+ /** Shared href/src/srcset/poster scan, preserving data-URL commas and ignoring external references. */
32
39
  export declare function extractAssetUrls(required: {
33
40
  html: string;
34
41
  prefixes: readonly string[];
@@ -1,4 +1,8 @@
1
1
  import { ExportPathError } from './contracts.js';
2
+ // Crawling and rewriting must recognize the same URL attributes.
3
+ const HTML_URL_ATTRIBUTES = ['href', 'src', 'srcset', 'poster'];
4
+ const HTML_URL_REWRITE = new RegExp(`\\b(${HTML_URL_ATTRIBUTES.join('|')})=(["'])([^"']*)\\2`, 'g');
5
+ const HTML_URL_SCAN = new RegExp(`\\b(${HTML_URL_ATTRIBUTES.join('|')})=(["'])([^"']+)\\2`, 'g');
2
6
  function escapeHtml(value) { return value.replace(/[&<>"']/g, char => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' })[char]); }
3
7
  function safeHref(value) {
4
8
  const href = value.trim();
@@ -55,10 +59,25 @@ function srcsetRanges(value) {
55
59
  }
56
60
  return ranges;
57
61
  }
62
+ /** A route path naming a `.json` file (e.g. a see-more JSON batch): written as that file, not `<path>/index.html`. */
63
+ function isJsonRoute(path) {
64
+ return /\.json$/i.test(path.split(/[?#]/)[0]);
65
+ }
66
+ /** JSON's link fields (`href`/`url`/`src` string values) get the base path, as HTML attributes do; a body that is not JSON is left as is. */
67
+ function rewriteJson(body, basePath) {
68
+ let parsed;
69
+ try {
70
+ parsed = JSON.parse(body);
71
+ }
72
+ catch {
73
+ return body;
74
+ }
75
+ return JSON.stringify(parsed, (key, value) => (typeof value === 'string' && (key === 'href' || key === 'url' || key === 'src') ? prefix(value, basePath) : value));
76
+ }
58
77
  function rewriteHtml(html, basePath) {
59
78
  if (!basePath)
60
79
  return html;
61
- return html.replace(/\b(href|src|srcset)=(["'])([^"']*)\2/g, (_match, attr, quote, value) => {
80
+ return html.replace(HTML_URL_REWRITE, (_match, attr, quote, value) => {
62
81
  if (attr !== 'srcset')
63
82
  return `${attr}=${quote}${prefix(value, basePath)}${quote}`;
64
83
  for (const { start, end } of srcsetRanges(value).reverse())
@@ -75,6 +94,8 @@ export function rewriteRouteBodyForBasePath(required) {
75
94
  return body.replace(/<loc>([^<]*)<\/loc>/g, (_match, value) => `<loc>${prefix(value, basePath)}</loc>`);
76
95
  if (path === '/robots.txt')
77
96
  return body.replace(/^Sitemap: (.*)$/gm, (_match, value) => `Sitemap: ${prefix(value.trim(), basePath)}`);
97
+ if (isJsonRoute(path))
98
+ return rewriteJson(body, basePath);
78
99
  return rewriteHtml(body, basePath);
79
100
  }
80
101
  /** Live Location wins; a manifest target is a fallback only for a genuine 3xx. */
@@ -92,16 +113,35 @@ export function renderRedirectStub(required, optional = {}) {
92
113
  const safeTarget = escapeHtml(safeHref(location));
93
114
  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
115
  }
95
- /** Quoted href/src/srcset scan, preserving data-URL commas and ignoring external references. */
116
+ /** HTML URL attributes; form actions are diagnostic references, never crawled as assets. */
117
+ export function* extractHtmlReferences(required, _optional = {}) {
118
+ const references = [...required.html.matchAll(HTML_URL_SCAN)]
119
+ .filter(match => required.html[match.index - 1] !== '-')
120
+ .map(match => ({ index: match.index, attribute: match[1], value: match[3] }));
121
+ for (const match of required.html.matchAll(/<form\b[^>]*?\baction=(["'])([^"']*)\1/g)) {
122
+ references.push({ index: match.index, attribute: 'action', value: match[2] });
123
+ }
124
+ for (const { attribute, value } of references.sort((a, b) => a.index - b.index)) {
125
+ const values = attribute === 'srcset' ? srcsetRanges(value).map(({ start, end }) => value.slice(start, end)) : [value];
126
+ for (const url of values)
127
+ yield { url, attribute };
128
+ }
129
+ }
130
+ /** Shared href/src/srcset/poster scan, preserving data-URL commas and ignoring external references. */
96
131
  export function extractAssetUrls(required) {
97
132
  const found = new Set();
98
- for (const match of required.html.matchAll(/\b(href|src|srcset)=(["'])([^"']+)\2/g)) {
133
+ for (const match of required.html.matchAll(HTML_URL_SCAN)) {
99
134
  const value = match[3];
100
135
  const values = match[1] === 'srcset' ? srcsetRanges(value).map(({ start, end }) => value.slice(start, end)) : [value];
101
136
  for (const url of values)
102
137
  if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
103
138
  found.add(url.split('#')[0]);
104
139
  }
140
+ // 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)) {
142
+ if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
143
+ found.add(url.split('#')[0]);
144
+ }
105
145
  return [...found];
106
146
  }
107
147
  /** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
@@ -148,7 +188,7 @@ export function outputFileForUrl(required, optional = {}) {
148
188
  const relative = decoded.replace(/^\//, '').replace(/\/+$/, '');
149
189
  if (relative)
150
190
  safeRelativeOutputFile({ value: relative });
151
- const output = optional.contentRoute ? (relative ? relative + '/index.html' : 'index.html') : relative;
191
+ const output = optional.contentRoute && !isJsonRoute(relative) ? (relative ? relative + '/index.html' : 'index.html') : relative;
152
192
  return safeRelativeOutputFile({ value: output });
153
193
  }
154
194
  //# sourceMappingURL=transforms.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jini-ai/devops",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
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": {
@@ -27,6 +27,11 @@
27
27
  "./local-dev": "node",
28
28
  "./deploy/node": "node",
29
29
  "./static-export/failure-summary": "universal"
30
+ },
31
+ "isolation": {
32
+ "shared": [
33
+ "src/core/export-failure-summary.ts"
34
+ ]
30
35
  }
31
36
  },
32
37
  "type": "module",
@@ -124,16 +129,16 @@
124
129
  "devDependencies": {
125
130
  "@vitest/coverage-v8": "^2.1.9",
126
131
  "undici": "^7.25.0",
127
- "@jini-ai/platform": "^0.5.2",
128
- "@jini-ai/daemon": "0.5.4",
129
- "@jini-ai/core": "^0.4.2"
132
+ "@jini-ai/daemon": "0.6.8",
133
+ "@jini-ai/platform": "^0.5.9",
134
+ "@jini-ai/core": "^0.4.7"
130
135
  },
131
136
  "dependencies": {
132
- "@jini-ai/core": "^0.4.2"
137
+ "@jini-ai/core": "^0.4.7"
133
138
  },
134
139
  "peerDependencies": {
135
140
  "typescript": "^5.6.0",
136
- "@jini-ai/platform": "^0.5.1",
141
+ "@jini-ai/platform": "^0.5.3",
137
142
  "undici": "^7.25.0"
138
143
  },
139
144
  "peerDependenciesMeta": {