histoire 1.0.0-beta.2 → 1.0.0-beta.3
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/dist/node/build/vite-config.d.ts.map +1 -1
- package/dist/node/build/vite-config.js +16 -0
- package/dist/node/collect/finalize.js +3 -2
- package/dist/node/commands/dev-child.js +26 -2
- package/dist/node/dom/collect-globals.d.ts +8 -0
- package/dist/node/dom/collect-globals.d.ts.map +1 -1
- package/dist/node/dom/collect-globals.js +20 -0
- package/dist/node/dom/env.d.ts.map +1 -1
- package/dist/node/dom/env.js +2 -1
- package/dist/node/marketplace/catalog/cache.d.ts +1 -1
- package/dist/node/marketplace/catalog/cache.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/cache.js +11 -8
- package/dist/node/marketplace/catalog/discover.d.ts +2 -0
- package/dist/node/marketplace/catalog/discover.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/fetch-json.d.ts +3 -0
- package/dist/node/marketplace/catalog/fetch-json.d.ts.map +1 -0
- package/dist/node/marketplace/catalog/fetch-json.js +37 -0
- package/dist/node/marketplace/catalog/handlers.js +2 -2
- package/dist/node/marketplace/catalog/official-feed.d.ts +50 -0
- package/dist/node/marketplace/catalog/official-feed.d.ts.map +1 -0
- package/dist/node/marketplace/catalog/official-feed.js +53 -0
- package/dist/node/marketplace/catalog/official-source.d.ts +22 -0
- package/dist/node/marketplace/catalog/official-source.d.ts.map +1 -0
- package/dist/node/marketplace/catalog/official-source.js +49 -0
- package/dist/node/marketplace/catalog/official.json +144 -10
- package/dist/node/marketplace/catalog/page-budget.d.ts +4 -0
- package/dist/node/marketplace/catalog/page-budget.d.ts.map +1 -0
- package/dist/node/marketplace/catalog/page-budget.js +30 -0
- package/dist/node/marketplace/catalog/registry.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/registry.js +3 -39
- package/dist/node/marketplace/catalog/service.d.ts +10 -5
- package/dist/node/marketplace/catalog/service.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/service.js +91 -46
- package/dist/node/marketplace/catalog/signals.d.ts +1 -1
- package/dist/node/marketplace/catalog/signals.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/signals.js +8 -3
- package/dist/node/marketplace/catalog/validation.d.ts +2 -0
- package/dist/node/marketplace/catalog/validation.d.ts.map +1 -1
- package/dist/node/marketplace/catalog/validation.js +2 -0
- package/dist/node/marketplace/changes/resolve-plugin.d.ts.map +1 -1
- package/dist/node/marketplace/changes/resolve-plugin.js +25 -5
- package/dist/node/marketplace/changes/validation.d.ts +1 -2
- package/dist/node/marketplace/changes/validation.d.ts.map +1 -1
- package/dist/node/marketplace/changes/validation.js +2 -3
- package/dist/node/marketplace/inventory/registry-versions.d.ts +21 -6
- package/dist/node/marketplace/inventory/registry-versions.d.ts.map +1 -1
- package/dist/node/marketplace/inventory/registry-versions.js +29 -10
- package/dist/node/marketplace/inventory/updates.d.ts +6 -1
- package/dist/node/marketplace/inventory/updates.d.ts.map +1 -1
- package/dist/node/marketplace/inventory/updates.js +22 -9
- package/dist/node/marketplace/jobs/execute.d.ts.map +1 -1
- package/dist/node/marketplace/jobs/execute.js +2 -3
- package/dist/node/marketplace/jobs/failure.d.ts +1 -1
- package/dist/node/marketplace/jobs/failure.d.ts.map +1 -1
- package/dist/node/marketplace/jobs/failure.js +5 -10
- package/dist/node/marketplace/migrations/details.d.ts.map +1 -1
- package/dist/node/marketplace/migrations/details.js +6 -6
- package/dist/node/marketplace/migrations/releases.d.ts.map +1 -1
- package/dist/node/marketplace/migrations/releases.js +3 -20
- package/dist/node/runtime/browser/limits.d.ts +2 -2
- package/dist/node/runtime/browser/limits.d.ts.map +1 -1
- package/dist/node/runtime/browser/limits.js +2 -2
- package/dist/node/runtime/catalog/projection.d.ts.map +1 -1
- package/dist/node/runtime/catalog/projection.js +13 -2
- package/dist/node/server/vite-servers.d.ts.map +1 -1
- package/dist/node/server/vite-servers.js +8 -3
- package/dist/node/util/has-vitest.d.ts +8 -2
- package/dist/node/util/has-vitest.d.ts.map +1 -1
- package/dist/node/util/has-vitest.js +9 -27
- package/dist/node/virtual/embed/descriptor.d.ts.map +1 -1
- package/dist/node/virtual/embed/descriptor.js +4 -1
- package/dist/node/virtual/preview-runtime/app-root.d.ts.map +1 -1
- package/dist/node/virtual/preview-runtime/app-root.js +6 -0
- package/dist/node/virtual/preview-runtime/components.d.ts.map +1 -1
- package/dist/node/virtual/preview-runtime/components.js +6 -1
- package/dist/node/virtual/preview-runtime/message-handler.d.ts.map +1 -1
- package/dist/node/virtual/preview-runtime/message-handler.js +5 -1
- package/dist/node/virtual/preview-runtime/preamble.js +1 -1
- package/dist/node/visual/spec.d.ts.map +1 -1
- package/dist/node/visual/spec.js +12 -1
- package/dist/node/vite/core-plugin.d.ts.map +1 -1
- package/dist/node/vite/core-plugin.js +3 -0
- package/dist/node/vite/dev-proxy.d.ts +7 -2
- package/dist/node/vite/dev-proxy.d.ts.map +1 -1
- package/dist/node/vite/dev-proxy.js +19 -6
- package/package.json +9 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-config.d.ts","sourceRoot":"","sources":["../../../src/node/build/vite-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,IAAI,gBAAgB,EAEjC,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"vite-config.d.ts","sourceRoot":"","sources":["../../../src/node/build/vite-config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,IAAI,gBAAgB,EAEjC,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AA0C5C;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,SAAoB,6BA0GrH"}
|
|
@@ -5,6 +5,21 @@ import { resolveEmbedConfig } from '../config/embed.js';
|
|
|
5
5
|
import { getViteConfigWithPlugins } from '../vite/index.js';
|
|
6
6
|
import { createBuildChunkOutput } from './chunks.js';
|
|
7
7
|
import { routeImportsThroughDynamicFacades } from './mock-facades.js';
|
|
8
|
+
/** Use Vue's build-time asset defaults while its collection server keeps story bindings available. */
|
|
9
|
+
function configureVueBuildAssets(plugin) {
|
|
10
|
+
const options = plugin.api?.options;
|
|
11
|
+
const configured = options?.template?.transformAssetUrls;
|
|
12
|
+
if (!options || configured === false)
|
|
13
|
+
return;
|
|
14
|
+
const assetOptions = configured && typeof configured === 'object' ? configured : {};
|
|
15
|
+
const overrides = Object.values(assetOptions).some(Array.isArray) ? { tags: assetOptions } : assetOptions;
|
|
16
|
+
options.template = {
|
|
17
|
+
...options.template,
|
|
18
|
+
// Without an explicit base, the synthetic dev server makes Vue emit
|
|
19
|
+
// unbundled URLs pointing to source files instead of build output.
|
|
20
|
+
transformAssetUrls: { base: null, includeAbsolute: true, ...overrides },
|
|
21
|
+
};
|
|
22
|
+
}
|
|
8
23
|
/**
|
|
9
24
|
* Builds the Vite config of the final bundle: the histoire app entries plus the
|
|
10
25
|
* overrides that must win over anything a user plugin sets (no externals, a
|
|
@@ -77,6 +92,7 @@ export async function createBuildViteConfig(ctx, collectServer, outputRoot = ctx
|
|
|
77
92
|
};
|
|
78
93
|
// @ts-expect-error vue plugin use function form
|
|
79
94
|
vuePlugin.configureServer(collectServer);
|
|
95
|
+
configureVueBuildAssets(vuePlugin);
|
|
80
96
|
}
|
|
81
97
|
},
|
|
82
98
|
});
|
|
@@ -12,9 +12,10 @@ export function finalizeCollectedStoryFile(storyFile, ctx, storyData = storyFile
|
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
const layoutType = storyData.layout?.type ?? ctx.config.defaultStoryProps?.layout?.type;
|
|
15
16
|
// Finalization can repeat; its own fallback must never become an author declaration.
|
|
16
|
-
storyData.layoutExplicit ??= !!
|
|
17
|
-
storyData.layout
|
|
17
|
+
storyData.layoutExplicit ??= !!layoutType;
|
|
18
|
+
storyData.layout = { ...storyData.layout, type: layoutType ?? 'single' };
|
|
18
19
|
storyFile.id = storyData.id;
|
|
19
20
|
storyFile.story = storyData;
|
|
20
21
|
storyFile.treeFile = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RESTART_SOURCE_MAX_LENGTH } from '@histoire/dev-proxy/protocol';
|
|
1
|
+
import { isBoundedFrame, RESTART_SOURCE_MAX_LENGTH } from '@histoire/dev-proxy/protocol';
|
|
2
2
|
import { installConsoleObserver } from '../runtime/terminal/console-hook.js';
|
|
3
3
|
// Credentials arrive over private IPC, never through project-visible environment.
|
|
4
4
|
delete process.env.HISTOIRE_MCP_TOKEN;
|
|
@@ -11,6 +11,8 @@ let session;
|
|
|
11
11
|
let startup;
|
|
12
12
|
let closing;
|
|
13
13
|
let stopped = false;
|
|
14
|
+
/** Settles the pending public address negotiation of the current generation. */
|
|
15
|
+
let pendingAddress;
|
|
14
16
|
/** Send observations only while owning parent remains connected. */
|
|
15
17
|
function send(message) {
|
|
16
18
|
if (!process.connected || stopped)
|
|
@@ -21,6 +23,8 @@ function send(message) {
|
|
|
21
23
|
/** Drain runtime before releasing IPC; parent bounds full winddown. */
|
|
22
24
|
function close() {
|
|
23
25
|
stopped = true;
|
|
26
|
+
pendingAddress?.reject(new Error('Histoire runtime closed'));
|
|
27
|
+
pendingAddress = undefined;
|
|
24
28
|
return closing ??= (async () => {
|
|
25
29
|
try {
|
|
26
30
|
await session?.close();
|
|
@@ -70,7 +74,18 @@ async function start(message) {
|
|
|
70
74
|
root: process.cwd(),
|
|
71
75
|
port: 0,
|
|
72
76
|
host: '127.0.0.1',
|
|
73
|
-
devProxy: {
|
|
77
|
+
devProxy: {
|
|
78
|
+
origin: message.publicOrigin,
|
|
79
|
+
generation: message.generation,
|
|
80
|
+
negotiate: address => new Promise((resolve, reject) => {
|
|
81
|
+
const frame = { type: 'address', generation: message.generation, ...address };
|
|
82
|
+
if (!isBoundedFrame(frame))
|
|
83
|
+
throw new Error('Configured server address exceeds the IPC limit');
|
|
84
|
+
if (!send(frame))
|
|
85
|
+
throw new Error('Histoire runtime closed');
|
|
86
|
+
pendingAddress = { generation: message.generation, resolve, reject };
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
74
89
|
onConfigurationInputs(files) {
|
|
75
90
|
send({ type: 'watch', generation: message.generation, inputs: encodeWatchInputs(files) });
|
|
76
91
|
},
|
|
@@ -99,6 +114,13 @@ process.on('message', (raw) => {
|
|
|
99
114
|
adapter?.receive(raw);
|
|
100
115
|
return;
|
|
101
116
|
}
|
|
117
|
+
if (raw?.type === 'address') {
|
|
118
|
+
if (pendingAddress?.generation === raw.generation) {
|
|
119
|
+
pendingAddress.resolve(raw.publicOrigin);
|
|
120
|
+
pendingAddress = undefined;
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
102
124
|
if (raw?.type === 'shutdown') {
|
|
103
125
|
void close();
|
|
104
126
|
return;
|
|
@@ -106,6 +128,8 @@ process.on('message', (raw) => {
|
|
|
106
128
|
if (raw?.type !== 'start' || startup || stopped)
|
|
107
129
|
return;
|
|
108
130
|
startup = start(raw).catch((error) => {
|
|
131
|
+
if (stopped)
|
|
132
|
+
return;
|
|
109
133
|
console.error(error);
|
|
110
134
|
send({ type: 'failed', generation: raw.generation, error: String(error instanceof Error ? error.message : error).slice(0, 4096) });
|
|
111
135
|
});
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { DOMWindow } from 'jsdom';
|
|
2
|
+
/**
|
|
3
|
+
* Supplies opaque URLs for libraries that prepare workers while being imported.
|
|
4
|
+
* Collection cannot load browser workers, so the URLs hold no blob data and
|
|
5
|
+
* revoking them needs no cleanup. Browser story runs use the real API.
|
|
6
|
+
* @param window The individual jsdom window owned by this collection pass.
|
|
7
|
+
*/
|
|
8
|
+
export declare function installCollectObjectUrls(window: DOMWindow): void;
|
|
1
9
|
/**
|
|
2
10
|
* Creates a `WebSocket` class for story collection that never connects.
|
|
3
11
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-globals.d.ts","sourceRoot":"","sources":["../../../src/node/dom/collect-globals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collect-globals.d.ts","sourceRoot":"","sources":["../../../src/node/dom/collect-globals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAStC;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,QAWzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM;cAsBjC,MAAM,GAAG,GAAG,eAAe,MAAM,GAAG,MAAM,EAAE;;;;;QAZ7D,8DAA8D;sBAChD,MAAM;;;;oBAIR,UAAU;;gBAEd,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI;mBAC5B,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI;iBACjC,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI;iBAC/B,CAAC,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC,GAAG,IAAI;QAOxC,6DAA6D;oBACjD,OAAO;QAEnB,2EAA2E;sBAC7D,MAAM,YAAY,MAAM;;;;;;;;;EAQzC;AAeD;;;GAGG;AACH,wBAAgB,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAerC"}
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
+
import { Blob as NodeBlob } from 'node:buffer';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
1
3
|
import { IDBCursor, IDBCursorWithValue, IDBDatabase, IDBFactory, IDBIndex, IDBKeyRange, IDBObjectStore, IDBOpenDBRequest, IDBRequest, IDBTransaction, IDBVersionChangeEvent } from 'fake-indexeddb';
|
|
2
4
|
/** Node's own event classes, captured before jsdom replaces the globals. */
|
|
3
5
|
const NativeEventTarget = globalThis.EventTarget;
|
|
4
6
|
const NativeEvent = globalThis.Event;
|
|
7
|
+
/**
|
|
8
|
+
* Supplies opaque URLs for libraries that prepare workers while being imported.
|
|
9
|
+
* Collection cannot load browser workers, so the URLs hold no blob data and
|
|
10
|
+
* revoking them needs no cleanup. Browser story runs use the real API.
|
|
11
|
+
* @param window The individual jsdom window owned by this collection pass.
|
|
12
|
+
*/
|
|
13
|
+
export function installCollectObjectUrls(window) {
|
|
14
|
+
const { Blob, URL, location: { origin } } = window;
|
|
15
|
+
if (typeof URL.createObjectURL === 'function')
|
|
16
|
+
return;
|
|
17
|
+
URL.createObjectURL = (blob) => {
|
|
18
|
+
if (!(blob instanceof Blob || blob instanceof NodeBlob)) {
|
|
19
|
+
throw new TypeError('URL.createObjectURL requires a Blob');
|
|
20
|
+
}
|
|
21
|
+
return `blob:${origin}/${randomUUID()}`;
|
|
22
|
+
};
|
|
23
|
+
URL.revokeObjectURL ??= () => { };
|
|
24
|
+
}
|
|
5
25
|
/**
|
|
6
26
|
* Creates a `WebSocket` class for story collection that never connects.
|
|
7
27
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/node/dom/env.ts"],"names":[],"mappings":"AAQA,4EAA4E;AAC5E,wBAAgB,YAAY;;;
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/node/dom/env.ts"],"names":[],"mappings":"AAQA,4EAA4E;AAC5E,wBAAgB,YAAY;;;EAgF3B"}
|
package/dist/node/dom/env.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSDOM, VirtualConsole, } from 'jsdom';
|
|
2
|
-
import { createCollectIndexedDb, createCollectWebSocket } from './collect-globals.js';
|
|
2
|
+
import { createCollectIndexedDb, createCollectWebSocket, installCollectObjectUrls } from './collect-globals.js';
|
|
3
3
|
import { restoreNativeEventGlobals } from './native-events.js';
|
|
4
4
|
import { populateGlobal } from './util.js';
|
|
5
5
|
/** Installs one collection window and owns its resources until teardown. */
|
|
@@ -17,6 +17,7 @@ export function createDomEnv() {
|
|
|
17
17
|
WebSocket: createCollectWebSocket(dom.window.location.href),
|
|
18
18
|
...(dom.window.indexedDB ? {} : createCollectIndexedDb()),
|
|
19
19
|
});
|
|
20
|
+
installCollectObjectUrls(dom.window);
|
|
20
21
|
const { keys, originals } = populateGlobal(globalThis, dom.window, { bindFunctions: true });
|
|
21
22
|
// Node's BroadcastChannel builds its delivery events from global constructors.
|
|
22
23
|
// Replacing them with jsdom's incompatible classes makes message delivery throw
|
|
@@ -8,7 +8,7 @@ export declare const REGISTRY_CACHE_PATH = "node_modules/.cache/histoire/marketp
|
|
|
8
8
|
/** Release generation metadata and fence already running fetches from republishing it. */
|
|
9
9
|
export declare function clearRegistryMemory(root: string): void;
|
|
10
10
|
/** Project-shared bounded metadata, with per-client identical in-flight work sharing. */
|
|
11
|
-
export declare function createRegistryCache(root: string, now?: () => number): {
|
|
11
|
+
export declare function createRegistryCache(root: string, now?: () => number, cachePath?: string): {
|
|
12
12
|
get: <T>(key: string, parse: (value: unknown) => T, fetch: () => Promise<unknown>) => Promise<CacheResult<T>>;
|
|
13
13
|
read: <T>(key: string, parse: (value: unknown) => T) => Promise<CacheResult<T> | undefined>;
|
|
14
14
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/cache.ts"],"names":[],"mappings":"AAKA,kDAAkD;AAClD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,uBAAuB,CAAC,KAAK,EAAE,CAAC,CAAA;IAChC,qEAAqE,CAAC,KAAK,EAAE,OAAO,CAAA;CACrF;AAOD,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,sDAAsD,CAAA;AAetF,0FAA0F;AAC1F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAStD;AAsBD,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,MAAiB;
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/cache.ts"],"names":[],"mappings":"AAKA,kDAAkD;AAClD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,uBAAuB,CAAC,KAAK,EAAE,CAAC,CAAA;IAChC,qEAAqE,CAAC,KAAK,EAAE,OAAO,CAAA;CACrF;AAOD,6EAA6E;AAC7E,eAAO,MAAM,mBAAmB,sDAAsD,CAAA;AAetF,0FAA0F;AAC1F,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAStD;AAsBD,yFAAyF;AACzF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,MAAiB,EAAE,SAAS,SAAsB;UAmD1F,CAAC,OAAO,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,SAAS,MAAM,OAAO,CAAC,OAAO,CAAC,KAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;WANpG,CAAC,OAAO,MAAM,SAAS,CAAC,KAAK,EAAE,OAAO,KAAK,CAAC,KAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;EA2CvG"}
|
|
@@ -39,9 +39,11 @@ function remember(store, key, entry, serialized) {
|
|
|
39
39
|
store.bytes += bytes;
|
|
40
40
|
}
|
|
41
41
|
/** Project-shared bounded metadata, with per-client identical in-flight work sharing. */
|
|
42
|
-
export function createRegistryCache(root, now = Date.now) {
|
|
42
|
+
export function createRegistryCache(root, now = Date.now, cachePath = REGISTRY_CACHE_PATH) {
|
|
43
43
|
root = resolve(root);
|
|
44
|
-
const directory = join(root,
|
|
44
|
+
const directory = join(root, cachePath);
|
|
45
|
+
/** Keep different schemas distinct even if an npm registry uses the catalog host. */
|
|
46
|
+
const memoryKey = (key) => `${cachePath}:${key}`;
|
|
45
47
|
let memory = stores.get(root);
|
|
46
48
|
if (!memory) {
|
|
47
49
|
memory = { entries: new Map(), bytes: 0, active: true };
|
|
@@ -56,18 +58,19 @@ export function createRegistryCache(root, now = Date.now) {
|
|
|
56
58
|
async function readEntry(key, parse) {
|
|
57
59
|
if (!memory.active)
|
|
58
60
|
return;
|
|
59
|
-
const
|
|
61
|
+
const id = memoryKey(key);
|
|
62
|
+
const cached = memory.entries.get(id);
|
|
60
63
|
if (cached) {
|
|
61
64
|
try {
|
|
62
65
|
if (cached.at > now())
|
|
63
66
|
throw new Error('Invalid cache time');
|
|
64
67
|
// Promote reads without resetting fetch time or serializing the payload again.
|
|
65
|
-
memory.entries.delete(
|
|
66
|
-
memory.entries.set(
|
|
68
|
+
memory.entries.delete(id);
|
|
69
|
+
memory.entries.set(id, cached);
|
|
67
70
|
return { at: cached.at, value: cached.value };
|
|
68
71
|
}
|
|
69
72
|
catch {
|
|
70
|
-
forget(memory,
|
|
73
|
+
forget(memory, id);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
try {
|
|
@@ -78,7 +81,7 @@ export function createRegistryCache(root, now = Date.now) {
|
|
|
78
81
|
if (typeof entry.at !== 'number' || !Number.isFinite(entry.at) || entry.at > now())
|
|
79
82
|
return;
|
|
80
83
|
const validated = { at: entry.at, value: parse(entry.value) };
|
|
81
|
-
remember(memory,
|
|
84
|
+
remember(memory, id, validated, JSON.stringify(validated));
|
|
82
85
|
return validated;
|
|
83
86
|
}
|
|
84
87
|
catch { /* Invalid or absent cache is a miss. */ }
|
|
@@ -107,7 +110,7 @@ export function createRegistryCache(root, now = Date.now) {
|
|
|
107
110
|
try {
|
|
108
111
|
// Serialize once for both the memory budget and atomic disk publication.
|
|
109
112
|
const serialized = JSON.stringify(entry);
|
|
110
|
-
remember(memory, key, entry, serialized);
|
|
113
|
+
remember(memory, memoryKey(key), entry, serialized);
|
|
111
114
|
if (memory.active) {
|
|
112
115
|
await mkdir(directory, { recursive: true });
|
|
113
116
|
await writeFile(temporary, serialized);
|
|
@@ -15,6 +15,7 @@ export declare function discoverCatalog(entries: PluginDetail[], project: Projec
|
|
|
15
15
|
tint: import("@histoire/shared").Tint;
|
|
16
16
|
logoUrl?: string;
|
|
17
17
|
latest: string;
|
|
18
|
+
installVersion?: string;
|
|
18
19
|
updatedAt?: string;
|
|
19
20
|
license?: string;
|
|
20
21
|
repoUrl?: string;
|
|
@@ -61,6 +62,7 @@ export declare function discoverCatalog(entries: PluginDetail[], project: Projec
|
|
|
61
62
|
tint: import("@histoire/shared").Tint;
|
|
62
63
|
logoUrl?: string;
|
|
63
64
|
latest: string;
|
|
65
|
+
installVersion?: string;
|
|
64
66
|
updatedAt?: string;
|
|
65
67
|
license?: string;
|
|
66
68
|
repoUrl?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/discover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAIlD,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC;IAO9G,IAAI
|
|
1
|
+
{"version":3,"file":"discover.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/discover.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAIlD,wFAAwF;AACxF,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC;IAO9G,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IACJ,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IACL,WAAW;;;;;EAEd"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** Read bounded streaming JSON, including chunked bodies lacking content-length. */
|
|
2
|
+
export declare function fetchMarketplaceJson(url: string, bytes: number, signal: AbortSignal, authorization?: string, source?: string): Promise<unknown>;
|
|
3
|
+
//# sourceMappingURL=fetch-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-json.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/fetch-json.ts"],"names":[],"mappings":"AAGA,oFAAoF;AACpF,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,SAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CA6BzJ"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { CatalogNotFoundError } from './errors.js';
|
|
3
|
+
/** Read bounded streaming JSON, including chunked bodies lacking content-length. */
|
|
4
|
+
export async function fetchMarketplaceJson(url, bytes, signal, authorization, source = 'Registry') {
|
|
5
|
+
const response = await fetch(url, { signal, redirect: 'error', headers: { accept: 'application/json', ...(authorization ? { authorization } : {}) } });
|
|
6
|
+
if (!response.ok) {
|
|
7
|
+
await response.body?.cancel();
|
|
8
|
+
if (response.status === 404)
|
|
9
|
+
throw new CatalogNotFoundError();
|
|
10
|
+
throw new Error(`${source} HTTP ${response.status} (${new URL(url).host})`);
|
|
11
|
+
}
|
|
12
|
+
if (Number(response.headers.get('content-length')) > bytes) {
|
|
13
|
+
await response.body?.cancel();
|
|
14
|
+
throw new Error(`${source} response too large`);
|
|
15
|
+
}
|
|
16
|
+
const reader = response.body?.getReader();
|
|
17
|
+
if (!reader)
|
|
18
|
+
throw new Error(`${source} response is empty`);
|
|
19
|
+
let size = 0;
|
|
20
|
+
const chunks = [];
|
|
21
|
+
try {
|
|
22
|
+
while (true) {
|
|
23
|
+
const { value, done } = await reader.read();
|
|
24
|
+
if (done)
|
|
25
|
+
break;
|
|
26
|
+
size += value.byteLength;
|
|
27
|
+
if (size > bytes)
|
|
28
|
+
throw new Error(`${source} response too large`);
|
|
29
|
+
chunks.push(value);
|
|
30
|
+
}
|
|
31
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await reader.cancel().catch(() => { });
|
|
35
|
+
reader.releaseLock();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { registerCorrelated } from '../channel.js';
|
|
2
2
|
import { getCatalogService } from './service.js';
|
|
3
|
-
import { catalogQuerySchema, correlationSchema, packageName, prefsSchema } from './validation.js';
|
|
3
|
+
import { catalogQuerySchema, correlationSchema, exactVersion, packageName, prefsSchema } from './validation.js';
|
|
4
4
|
/** Register private correlated reads; retired generations and closed clients cannot reply. */
|
|
5
5
|
export const registerCatalogHandlers = (ctx, channel, isActive) => {
|
|
6
6
|
const service = getCatalogService(ctx);
|
|
7
7
|
registerCorrelated(channel, 'histoire:ui:marketplace-catalog', 'histoire:ui:marketplace-catalog-result', correlationSchema.extend({ query: catalogQuerySchema }), async (request) => ({ page: await service.catalog(request.query) }), 'Could not load plugin catalog', { isActive });
|
|
8
|
-
registerCorrelated(channel, 'histoire:ui:marketplace-detail', 'histoire:ui:marketplace-detail-result', correlationSchema.extend({ id: packageName, prefs: prefsSchema }), async (request) => ({ detail: await service.detail(request.id, request.prefs) }), 'Could not load plugin catalog', { isActive });
|
|
8
|
+
registerCorrelated(channel, 'histoire:ui:marketplace-detail', 'histoire:ui:marketplace-detail-result', correlationSchema.extend({ id: packageName, prefs: prefsSchema, version: exactVersion.optional() }), async (request) => ({ detail: await service.detail(request.id, request.prefs, request.version) }), 'Could not load plugin catalog', { isActive });
|
|
9
9
|
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RegistryRelease } from './registry-entry.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
/** Versioned public catalog URL. Only test callers can substitute another origin. */
|
|
4
|
+
export declare const OFFICIAL_FEED_URL = "https://histoire.dev/marketplace/v1/official.json";
|
|
5
|
+
/** Maximum bytes for the published file and runtime response. */
|
|
6
|
+
export declare const OFFICIAL_FEED_BYTES: number;
|
|
7
|
+
/** A curated listing and its approved exact releases. */
|
|
8
|
+
export interface OfficialListing {
|
|
9
|
+
/** Release that supplies the listing metadata. */ listing: RegistryRelease;
|
|
10
|
+
/** Versions in descending semver order. */ releases: RegistryRelease[];
|
|
11
|
+
}
|
|
12
|
+
/** Disk and HTTP share one parser, retaining only metadata used by Histoire. */
|
|
13
|
+
declare const schema: z.ZodObject<{
|
|
14
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
15
|
+
packages: z.ZodArray<z.ZodObject<{
|
|
16
|
+
packument: z.ZodPipe<z.ZodObject<{
|
|
17
|
+
name: z.ZodString;
|
|
18
|
+
'dist-tags': z.ZodObject<{
|
|
19
|
+
latest: z.ZodString;
|
|
20
|
+
}, z.core.$strip>;
|
|
21
|
+
versions: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
22
|
+
time: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
23
|
+
}, z.core.$strip>, z.ZodTransform<{
|
|
24
|
+
name: string;
|
|
25
|
+
'dist-tags': {
|
|
26
|
+
latest: string;
|
|
27
|
+
};
|
|
28
|
+
time?: Record<string, string>;
|
|
29
|
+
versions: {
|
|
30
|
+
[k: string]: {};
|
|
31
|
+
};
|
|
32
|
+
}, {
|
|
33
|
+
name: string;
|
|
34
|
+
'dist-tags': {
|
|
35
|
+
latest: string;
|
|
36
|
+
};
|
|
37
|
+
versions: Record<string, unknown>;
|
|
38
|
+
time?: Record<string, string>;
|
|
39
|
+
}>>;
|
|
40
|
+
docsUrl: z.ZodOptional<z.ZodString>;
|
|
41
|
+
}, z.core.$strict>>;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
/** Cache objects serve multiple browse, detail and planning requests. */
|
|
44
|
+
type Feed = z.infer<typeof schema>;
|
|
45
|
+
/** Validate the whole snapshot before it can replace last-known-good metadata. */
|
|
46
|
+
export declare function parseOfficialFeed(input: unknown): Feed;
|
|
47
|
+
/** Return the validated projections for this snapshot. */
|
|
48
|
+
export declare function officialFeedListings(feed: Feed): ReadonlyMap<string, OfficialListing>;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=official-feed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"official-feed.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/official-feed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAE1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAOvB,qFAAqF;AACrF,eAAO,MAAM,iBAAiB,sDAAsD,CAAA;AACpF,iEAAiE;AACjE,eAAO,MAAM,mBAAmB,QAAkB,CAAA;AAElD,yDAAyD;AACzD,MAAM,WAAW,eAAe;IAC9B,kDAAkD,CAAC,OAAO,EAAE,eAAe,CAAA;IAC3E,2CAA2C,CAAC,QAAQ,EAAE,eAAe,EAAE,CAAA;CACxE;AAED,gFAAgF;AAChF,QAAA,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAMV,CAAA;AACF,yEAAyE;AACzE,KAAK,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAA;AAIlC,kFAAkF;AAClF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAuBtD;AAED,0DAA0D;AAC1D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAErF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { valid } from 'semver';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { webUrl } from '../../config/plugin-metadata.js';
|
|
4
|
+
import { officialPlugins } from './official.js';
|
|
5
|
+
import { packumentSchema, registryRelease } from './registry-entry.js';
|
|
6
|
+
import { exactVersion } from './validation.js';
|
|
7
|
+
import { compareVersions } from './version.js';
|
|
8
|
+
/** Versioned public catalog URL. Only test callers can substitute another origin. */
|
|
9
|
+
export const OFFICIAL_FEED_URL = 'https://histoire.dev/marketplace/v1/official.json';
|
|
10
|
+
/** Maximum bytes for the published file and runtime response. */
|
|
11
|
+
export const OFFICIAL_FEED_BYTES = 4 * 1024 * 1024;
|
|
12
|
+
/** Disk and HTTP share one parser, retaining only metadata used by Histoire. */
|
|
13
|
+
const schema = z.strictObject({
|
|
14
|
+
schemaVersion: z.literal(1),
|
|
15
|
+
packages: z.array(z.strictObject({
|
|
16
|
+
packument: packumentSchema,
|
|
17
|
+
docsUrl: z.string().url().max(2048).optional(),
|
|
18
|
+
})).max(100),
|
|
19
|
+
});
|
|
20
|
+
const feedListings = new WeakMap();
|
|
21
|
+
const bundledLogos = new Map(officialPlugins.map(entry => [entry.id, entry.logoUrl]));
|
|
22
|
+
/** Validate the whole snapshot before it can replace last-known-good metadata. */
|
|
23
|
+
export function parseOfficialFeed(input) {
|
|
24
|
+
const feed = schema.parse(input);
|
|
25
|
+
const listings = new Map();
|
|
26
|
+
for (const { packument, docsUrl } of feed.packages) {
|
|
27
|
+
const id = packument.name;
|
|
28
|
+
const versions = Object.keys(packument.versions);
|
|
29
|
+
if (!id.startsWith('@histoire/') || listings.has(id) || versions.length > 50 || (docsUrl && !webUrl(docsUrl)))
|
|
30
|
+
throw new Error('Invalid official plugin listing');
|
|
31
|
+
const releases = versions.sort((a, b) => compareVersions(b, a)).map((version) => {
|
|
32
|
+
const release = registryRelease(packument, version);
|
|
33
|
+
if (!release || !exactVersion.safeParse(version).success || !valid(version))
|
|
34
|
+
throw new Error(`Invalid official plugin release: ${id}@${version}`);
|
|
35
|
+
const logoUrl = bundledLogos.get(id);
|
|
36
|
+
// The package manager resolves missing published peers. A manifest requirement
|
|
37
|
+
// still expects the dependency to be present before installation.
|
|
38
|
+
const optionalPeers = Object.keys(release.detail.requires).filter(name => !Object.hasOwn(release.detail.manifest.requires ?? {}, name));
|
|
39
|
+
// Keep bundled marks and monograms. Listing the catalog never fetches a package author's logo.
|
|
40
|
+
return { ...release, optionalPeers, detail: { ...release.detail, official: true, logoUrl, docsUrl: docsUrl ?? release.detail.docsUrl } };
|
|
41
|
+
});
|
|
42
|
+
const listing = releases.find(release => release.version === packument['dist-tags'].latest && !release.deprecated);
|
|
43
|
+
if (!listing)
|
|
44
|
+
throw new Error('Missing official listing release');
|
|
45
|
+
listings.set(id, { listing, releases });
|
|
46
|
+
}
|
|
47
|
+
feedListings.set(feed, listings);
|
|
48
|
+
return feed;
|
|
49
|
+
}
|
|
50
|
+
/** Return the validated projections for this snapshot. */
|
|
51
|
+
export function officialFeedListings(feed) {
|
|
52
|
+
return feedListings.get(feed);
|
|
53
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Context } from '../../context.js';
|
|
2
|
+
import type { OfficialListing } from './official-feed.js';
|
|
3
|
+
/** Source options for tests. Project configuration only controls whether refresh runs. */
|
|
4
|
+
export interface OfficialSourceOptions {
|
|
5
|
+
/** Override the public endpoint in boundary tests. */ officialUrl?: string;
|
|
6
|
+
/** Limit the fetch deadline in boundary tests. */ officialTimeoutMs?: number;
|
|
7
|
+
/** Clock used for refresh and retry deadlines. */ now?: () => number;
|
|
8
|
+
}
|
|
9
|
+
/** Context evidence needed to apply project refresh policy. */
|
|
10
|
+
export type OfficialContext = Pick<Context, 'root'> & Partial<Pick<Context, 'mode'>> & {
|
|
11
|
+
/** Server-owned settings. */ config?: Pick<Context['config'], 'marketplace'>;
|
|
12
|
+
};
|
|
13
|
+
/** A single consistent catalog used for a read or review. */
|
|
14
|
+
export interface OfficialSnapshot {
|
|
15
|
+
/** Source freshness. */ source: 'bundled' | 'ok' | 'stale' | 'fallback';
|
|
16
|
+
/** Identifies packages curated by this source. */ listings: ReadonlyMap<string, OfficialListing>;
|
|
17
|
+
}
|
|
18
|
+
/** Share and persist validated public metadata without consulting npm configuration. */
|
|
19
|
+
export declare function createOfficialSource(ctx: OfficialContext, options: OfficialSourceOptions): (readOnly?: boolean) => Promise<OfficialSnapshot>;
|
|
20
|
+
/** Whether exact hosted releases are authoritative for this request. */
|
|
21
|
+
export declare function hasHostedSnapshot(snapshot: OfficialSnapshot): boolean;
|
|
22
|
+
//# sourceMappingURL=official-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"official-source.d.ts","sourceRoot":"","sources":["../../../../src/node/marketplace/catalog/official-source.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAMzD,0FAA0F;AAC1F,MAAM,WAAW,qBAAqB;IACpC,sDAAsD,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC3E,kDAAkD,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC7E,kDAAkD,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;CACtE;AAED,+DAA+D;AAC/D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,GAAG;IACrF,6BAA6B,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,aAAa,CAAC,CAAA;CAC9E,CAAA;AAED,6DAA6D;AAC7D,MAAM,WAAW,gBAAgB;IAC/B,wBAAwB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,GAAG,OAAO,GAAG,UAAU,CAAA;IACxE,kDAAkD,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;CAClG;AAYD,wFAAwF;AACxF,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,eAAe,EAAE,OAAO,EAAE,qBAAqB,2BAW7B,OAAO,CAAC,gBAAgB,CAAC,CAmBpF;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAErE"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { createRegistryCache } from './cache.js';
|
|
2
|
+
import { fetchMarketplaceJson } from './fetch-json.js';
|
|
3
|
+
import { OFFICIAL_FEED_BYTES, OFFICIAL_FEED_URL, officialFeedListings, parseOfficialFeed } from './official-feed.js';
|
|
4
|
+
import { officialPlugins, officialReleases } from './official.js';
|
|
5
|
+
/** Lift the bundled history into the same shape as the live source. */
|
|
6
|
+
const bundled = {
|
|
7
|
+
source: 'bundled',
|
|
8
|
+
listings: new Map(officialPlugins.filter(entry => entry.official).map((entry) => {
|
|
9
|
+
/** Bundled entries predate published peer metadata. */
|
|
10
|
+
const release = (detail) => ({ detail, version: detail.latest, optionalPeers: [], deprecated: false });
|
|
11
|
+
return [entry.id, { listing: release(entry), releases: officialReleases(entry.id).map(release) }];
|
|
12
|
+
})),
|
|
13
|
+
};
|
|
14
|
+
/** Share and persist validated public metadata without consulting npm configuration. */
|
|
15
|
+
export function createOfficialSource(ctx, options) {
|
|
16
|
+
if (ctx.mode !== 'dev' || ctx.config?.marketplace?.refreshOfficialCatalog === false) {
|
|
17
|
+
return async () => bundled;
|
|
18
|
+
}
|
|
19
|
+
const url = options.officialUrl ?? OFFICIAL_FEED_URL;
|
|
20
|
+
const now = options.now ?? Date.now;
|
|
21
|
+
const cache = createRegistryCache(ctx.root, now, 'node_modules/.cache/histoire/marketplace/official');
|
|
22
|
+
let nextRetry = 0;
|
|
23
|
+
let pending;
|
|
24
|
+
/** Read, or refresh once per cache window. Planning never touches the network or writes files. */
|
|
25
|
+
return async function officialSnapshot(readOnly = false) {
|
|
26
|
+
if (readOnly || now() < nextRetry) {
|
|
27
|
+
const saved = await cache.read(url, parseOfficialFeed);
|
|
28
|
+
return saved
|
|
29
|
+
? { source: saved.stale ? 'stale' : 'ok', listings: officialFeedListings(saved.value) }
|
|
30
|
+
: { ...bundled, source: 'fallback' };
|
|
31
|
+
}
|
|
32
|
+
pending ??= cache.get(url, parseOfficialFeed, () => fetchMarketplaceJson(url, OFFICIAL_FEED_BYTES, AbortSignal.timeout(options.officialTimeoutMs ?? 2000), undefined, 'Official catalog'))
|
|
33
|
+
.then((result) => {
|
|
34
|
+
if (result.stale)
|
|
35
|
+
nextRetry = now() + 300_000;
|
|
36
|
+
return { source: result.stale ? 'stale' : 'ok', listings: officialFeedListings(result.value) };
|
|
37
|
+
})
|
|
38
|
+
.catch(() => {
|
|
39
|
+
nextRetry = now() + 300_000;
|
|
40
|
+
return { ...bundled, source: 'fallback' };
|
|
41
|
+
})
|
|
42
|
+
.finally(() => { pending = undefined; });
|
|
43
|
+
return pending;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/** Whether exact hosted releases are authoritative for this request. */
|
|
47
|
+
export function hasHostedSnapshot(snapshot) {
|
|
48
|
+
return snapshot.source === 'ok' || snapshot.source === 'stale';
|
|
49
|
+
}
|