import { BOOT_ALIAS_IDS_FLAG } from './version.js'; /** Browser-only globals dshloader relies on (typed loosely so the module compiles without DOM lib). */ type FetchImpl = (input: any, init?: any) => Promise<{ clone(): { json(): any; }; json(): any; }>; interface DshLoaderWindowLike { fetch: FetchImpl; location?: { origin?: string; }; Response?: new (body?: string, init?: { status?: number; headers?: Record; }) => any; __ModuleLoader__?: { load(handoff: { id: string; factory: (require: (spec: string) => any) => any; }): unknown; }; __DSHLOADER_VERSION__?: string; __DSHLOADER_CONFIG__?: { exposeAllNamespaces?: boolean; }; __dshNativeRequire__?: (spec: string) => any; __dshLoader__?: unknown; /** Alias ids the boot injection (src/boot-injection.ts) already registered. */ [BOOT_ALIAS_IDS_FLAG]?: string[]; } declare global { } /** The client module-system surface legacy plugins read off `window.__DSH_MODULES__`. */ interface DshModulesLike { import(specifier: string): Promise; } /** * Compatibility shim: mount `window.__DSH_MODULES__` for plugins that read the * client module system off the global. * * dsh ≤ 0.1.0-rc.7 set `globalThis.__DSH_MODULES__ = ` * during web boot; 0.1.0-rc.8+ stopped exposing it globally and instead hands * the same instance to the cordis client loader as `ctx.loader.internal`. * Plugins built against the old global (e.g. dsh-better-sidebar's lazy chunks) * break with "client module system unavailable" on the new versions. dshloader * bridges the gap so those plugins need no change across every dsh version: * when the global is missing but the cordis loader carries the module system, * mirror it back onto the global. * * Returns true when the global is present after this call (either it already * was, or we just mirrored it). */ export declare function ensureDshModulesGlobal(win: DshLoaderWindowLike, ctx: { loader?: { internal?: DshModulesLike; }; } | undefined): boolean; export declare class ModuleNotFoundError extends Error { specifier: string; constructor(specifier: string); } interface CreateClientAPIOpts { dshVersion?: string; adapterVersion?: string; moduleAliases?: Record; packageAliases?: Map | Record; requireImpl?: (spec: string) => any; fetchBridge?: { describe: () => Promise; write: (mode: string, payload: object) => Promise; }; clientCtx?: { get?: (name: string) => any; }; } /** * Build the `window.__dshLoader__` API object. */ export declare function createClientAPI(opts?: CreateClientAPIOpts): { version: string; dshVersion: string | undefined; adapterVersion: string | undefined; require(specifier: string): any; registerModuleAlias(alias: string, target: string): void; /** * Register a package-name alias for the client module loader's * require(). When a plugin's bundle calls require('@old/pkg-name'), * the loader's wrapped require remaps it to '@new/pkg-name' before * hitting the module table. This lets dsh rename client packages * across versions without forcing plugin bundles to rebuild. */ registerPackageAlias(oldName: string, newName: string): void; /** * Read a client-side cordis service by name. * Proxies to `clientCtx.get(name)` — the same ctx.get plugins use * inside their client `apply(ctx)`, but exposed through the stable * dshloader surface so plugins don't depend on the cordis context * shape directly. * * Only available when dshloader's client apply() received a ctx * (cordis client boot). Returns undefined when ctx is not wired. */ services: { get(name: string): any; }; rpc: { settings: { describe: () => Promise; update: (ns: string, section: unknown) => Promise; replace: (ns: string, section: unknown) => Promise; mutate: (ns: string, ops: unknown) => Promise; }; } | undefined; }; interface InstallClientOpts { window?: DshLoaderWindowLike; dshVersion?: string; exposeAllNamespaces?: boolean; requireImpl?: (spec: string) => any; hostBridgePrefix?: string; packageAliases?: Record; clientCtx?: { get?: (name: string) => any; }; /** * cordis effect hook (`ctx.effect`): the load wrapper and fetch * interceptor register their disposers through it so fiber unload / HMR * tears the patches down instead of leaking them. Absent in bare test * environments, where patches simply live for the process. */ effect?: (fn: () => (() => void) | void) => unknown; } /** * Install dshloader into a browser-like environment. */ export declare function installClient(opts?: InstallClientOpts): { version: string; dshVersion: string | undefined; adapterVersion: string | undefined; require(specifier: string): any; registerModuleAlias(alias: string, target: string): void; /** * Register a package-name alias for the client module loader's * require(). When a plugin's bundle calls require('@old/pkg-name'), * the loader's wrapped require remaps it to '@new/pkg-name' before * hitting the module table. This lets dsh rename client packages * across versions without forcing plugin bundles to rebuild. */ registerPackageAlias(oldName: string, newName: string): void; /** * Read a client-side cordis service by name. * Proxies to `clientCtx.get(name)` — the same ctx.get plugins use * inside their client `apply(ctx)`, but exposed through the stable * dshloader surface so plugins don't depend on the cordis context * shape directly. * * Only available when dshloader's client apply() received a ctx * (cordis client boot). Returns undefined when ctx is not wired. */ services: { get(name: string): any; }; rpc: { settings: { describe: () => Promise; update: (ns: string, section: unknown) => Promise; replace: (ns: string, section: unknown) => Promise; mutate: (ns: string, ops: unknown) => Promise; }; } | undefined; } | undefined; /** * Fetch interceptor for settings namespace whitelist bypass (fix 5, path 2). * Mirrors dsh-upstream-fixes/lib/client.js (127-223). * * - /api/settings.describe: merge non-whitelisted namespaces from the host * bridge into the official response (rpcId/official fields preserved). * - /api/settings.{update,mutate,replace}: route writes for namespaces the * official proxy does NOT expose through the host bridge, and rebuild the * response envelope as `{ type: 'server-response', rpcId, result }` so the * official client can correlate the response with the request. */ export declare function installSettingsFetchInterceptor(win: DshLoaderWindowLike, bridgePrefix?: string): () => void; export declare const name = "@dsh-plugin/dsh-loader"; export declare const inject: string[]; export declare function apply(ctx: { get?: (name: string) => any; loader?: { internal?: DshModulesLike; }; effect?: (fn: () => (() => void) | void) => unknown; }): void; export {};