@jini-ai/devops 0.5.3 → 0.5.4

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) {
@@ -130,6 +130,12 @@ export interface ExportSiteArgs {
130
130
  describeError(required: {
131
131
  error: unknown;
132
132
  }): string;
133
+ /** Further routes a written page links to (e.g. see-more batch URLs), exported in turn and
134
+ * themselves scanned, so a chain of batches is followed to its end. Given the raw, pre-rewrite html. */
135
+ discoverRoutes?(required: {
136
+ path: string;
137
+ html: string;
138
+ }): readonly ManifestRoute[];
133
139
  }
134
140
  export interface ExportSiteOptions {
135
141
  clean?: boolean;
@@ -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 = [];
@@ -126,7 +145,7 @@ export async function exportSite(required, optional = {}) {
126
145
  const ctx = { args: required, baseUrl: origin.origin, basePath, timeoutMs };
127
146
  const routes = await writeRoutes(ctx, manifest.routes);
128
147
  const assets = await writeAssets(ctx, [...routes.assets]);
129
- return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: manifest.skipped,
148
+ return { outputDir: required.outputDir, routes: { succeeded: routes.succeeded, failed: routes.failed }, assets, skippedManifestEntries: [...manifest.skipped, ...routes.skipped],
130
149
  unreferencedThemeFiles: await unreferenced(ctx, manifest, assets.succeeded), ...(basePath ? { basePath, basePathRewriteWarning: BASE_PATH_REWRITE_WARNING } : {}) };
131
150
  }
132
151
  finally {
@@ -55,6 +55,21 @@ function srcsetRanges(value) {
55
55
  }
56
56
  return ranges;
57
57
  }
58
+ /** A route path naming a `.json` file (e.g. a see-more JSON batch): written as that file, not `<path>/index.html`. */
59
+ function isJsonRoute(path) {
60
+ return /\.json$/i.test(path.split(/[?#]/)[0]);
61
+ }
62
+ /** 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. */
63
+ function rewriteJson(body, basePath) {
64
+ let parsed;
65
+ try {
66
+ parsed = JSON.parse(body);
67
+ }
68
+ catch {
69
+ return body;
70
+ }
71
+ return JSON.stringify(parsed, (key, value) => (typeof value === 'string' && (key === 'href' || key === 'url' || key === 'src') ? prefix(value, basePath) : value));
72
+ }
58
73
  function rewriteHtml(html, basePath) {
59
74
  if (!basePath)
60
75
  return html;
@@ -75,6 +90,8 @@ export function rewriteRouteBodyForBasePath(required) {
75
90
  return body.replace(/<loc>([^<]*)<\/loc>/g, (_match, value) => `<loc>${prefix(value, basePath)}</loc>`);
76
91
  if (path === '/robots.txt')
77
92
  return body.replace(/^Sitemap: (.*)$/gm, (_match, value) => `Sitemap: ${prefix(value.trim(), basePath)}`);
93
+ if (isJsonRoute(path))
94
+ return rewriteJson(body, basePath);
78
95
  return rewriteHtml(body, basePath);
79
96
  }
80
97
  /** Live Location wins; a manifest target is a fallback only for a genuine 3xx. */
@@ -102,6 +119,11 @@ export function extractAssetUrls(required) {
102
119
  if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
103
120
  found.add(url.split('#')[0]);
104
121
  }
122
+ // JSON link fields too (a see-more JSON batch's covers), as `rewriteJson` prefixes them.
123
+ for (const [, url = ''] of required.html.matchAll(/"(?:href|src|url)"\s*:\s*"([^"\\]+)"/g)) {
124
+ if (!url.startsWith('//') && required.prefixes.some(prefix => url.startsWith(prefix)))
125
+ found.add(url.split('#')[0]);
126
+ }
105
127
  return [...found];
106
128
  }
107
129
  /** A single CSS hop, resolved against the stylesheet URL and restricted to the same synthetic origin. */
@@ -148,7 +170,7 @@ export function outputFileForUrl(required, optional = {}) {
148
170
  const relative = decoded.replace(/^\//, '').replace(/\/+$/, '');
149
171
  if (relative)
150
172
  safeRelativeOutputFile({ value: relative });
151
- const output = optional.contentRoute ? (relative ? relative + '/index.html' : 'index.html') : relative;
173
+ const output = optional.contentRoute && !isJsonRoute(relative) ? (relative ? relative + '/index.html' : 'index.html') : relative;
152
174
  return safeRelativeOutputFile({ value: output });
153
175
  }
154
176
  //# 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.4",
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": {
@@ -124,16 +124,16 @@
124
124
  "devDependencies": {
125
125
  "@vitest/coverage-v8": "^2.1.9",
126
126
  "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"
127
+ "@jini-ai/daemon": "0.6.1",
128
+ "@jini-ai/platform": "^0.5.3",
129
+ "@jini-ai/core": "^0.4.3"
130
130
  },
131
131
  "dependencies": {
132
- "@jini-ai/core": "^0.4.2"
132
+ "@jini-ai/core": "^0.4.3"
133
133
  },
134
134
  "peerDependencies": {
135
135
  "typescript": "^5.6.0",
136
- "@jini-ai/platform": "^0.5.1",
136
+ "@jini-ai/platform": "^0.5.3",
137
137
  "undici": "^7.25.0"
138
138
  },
139
139
  "peerDependenciesMeta": {