MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / bootstrapLoader

Function bootstrapLoader

apps/web/src/widgets-runtime/loader.ts:24–55  ·  view source on GitHub ↗
(opts: BootstrapOptions = {})

Source from the content-addressed store, hash-verified

22}
23
24export async function bootstrapLoader(opts: BootstrapOptions = {}): Promise<void> {
25 const base = opts.baseUrl ?? '/api/widget-modules'
26 const importer = opts.importer ?? ((url: string) => import(/* @vite-ignore */ url))
27 const hostVersion = opts.hostSdkVersion ?? SDK_VERSION
28
29 const res = await fetch(base, { credentials: 'include' })
30 if (!res.ok) {
31 throw new Error(`bootstrapLoader: list failed ${res.status}`)
32 }
33 const body = (await res.json()) as { data: ListEntry[] }
34 const modules = body.data
35
36 await Promise.allSettled(
37 modules.map(async (entry) => {
38 try {
39 if (!isCompatible(hostVersion, entry.manifest.sdkVersion)) {
40 throw new Error(
41 `sdk version mismatch: host ${hostVersion} does not satisfy manifest range ${entry.manifest.sdkVersion}`
42 )
43 }
44 const url = `${base}/${entry.id}/${entryAssetPath(entry.entry_path)}`
45 const mod = await importer(url)
46 if (!mod.default || mod.default.__brand !== 'WidgetModule') {
47 throw new Error(`module ${entry.id} did not export a WidgetModule via default`)
48 }
49 registryActions.register(entry.id, mod.default, entry.manifest)
50 } catch (err) {
51 registryActions.recordLoadFailure(entry.id, err instanceof Error ? err : new Error(String(err)))
52 }
53 })
54 )
55}

Callers 2

loader.test.tsFile · 0.90
useWidgetModuleBootstrapFunction · 0.90

Calls 3

isCompatibleFunction · 0.90
fetchFunction · 0.85
entryAssetPathFunction · 0.85

Tested by

no test coverage detected