@viceme-ai/sdk 0.1.2

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.
Files changed (49) hide show
  1. package/README.md +48 -0
  2. package/dist/bootstrap.min.js +2 -0
  3. package/dist/bootstrap.min.js.map +1 -0
  4. package/dist/chunks/client-CGU3qeew.js +275 -0
  5. package/dist/chunks/client-CGU3qeew.js.map +1 -0
  6. package/dist/core/client.d.ts +55 -0
  7. package/dist/core/client.d.ts.map +1 -0
  8. package/dist/core/config.d.ts +32 -0
  9. package/dist/core/config.d.ts.map +1 -0
  10. package/dist/core/errors.d.ts +37 -0
  11. package/dist/core/errors.d.ts.map +1 -0
  12. package/dist/core/lifecycle.d.ts +25 -0
  13. package/dist/core/lifecycle.d.ts.map +1 -0
  14. package/dist/generated/public-contract.d.ts +156 -0
  15. package/dist/generated/public-contract.d.ts.map +1 -0
  16. package/dist/index.d.ts +27 -0
  17. package/dist/index.d.ts.map +1 -0
  18. package/dist/index.js +126 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/loader/attributes.d.ts +21 -0
  21. package/dist/loader/attributes.d.ts.map +1 -0
  22. package/dist/loader/auto-loader.d.ts +51 -0
  23. package/dist/loader/auto-loader.d.ts.map +1 -0
  24. package/dist/loader/bootstrap.d.ts +1 -0
  25. package/dist/loader/bootstrap.d.ts.map +1 -0
  26. package/dist/loader/events.d.ts +45 -0
  27. package/dist/loader/events.d.ts.map +1 -0
  28. package/dist/loader/main.d.ts +11 -0
  29. package/dist/loader/main.d.ts.map +1 -0
  30. package/dist/loader/mount-handle.d.ts +25 -0
  31. package/dist/loader/mount-handle.d.ts.map +1 -0
  32. package/dist/loader/registry.d.ts +42 -0
  33. package/dist/loader/registry.d.ts.map +1 -0
  34. package/dist/manifest.json +38 -0
  35. package/dist/session/session.d.ts +54 -0
  36. package/dist/session/session.d.ts.map +1 -0
  37. package/dist/testing/test-adapter.d.ts +57 -0
  38. package/dist/testing/test-adapter.d.ts.map +1 -0
  39. package/dist/testing.d.ts +9 -0
  40. package/dist/testing.d.ts.map +1 -0
  41. package/dist/testing.js +69 -0
  42. package/dist/testing.js.map +1 -0
  43. package/dist/transport/transport.d.ts +42 -0
  44. package/dist/transport/transport.d.ts.map +1 -0
  45. package/dist/version.d.ts +10 -0
  46. package/dist/version.d.ts.map +1 -0
  47. package/dist/viceme.min.js +2 -0
  48. package/dist/viceme.min.js.map +1 -0
  49. package/package.json +59 -0
@@ -0,0 +1,156 @@
1
+ /**
2
+ * GENERATED FILE — DO NOT EDIT.
3
+ *
4
+ * Generated from contracts/public-capabilities.openapi.json
5
+ * (contractVersion 0.1.0, sha256 a9c5d56d90eb2654…)
6
+ * by scripts/generate-contracts.mjs. Regenerate with `pnpm contracts:generate`.
7
+ */
8
+ /**
9
+ * This file was auto-generated by openapi-typescript.
10
+ * Do not make direct changes to the file.
11
+ */
12
+ export interface paths {
13
+ "/public/v1/work-sessions": {
14
+ parameters: {
15
+ query?: never;
16
+ header?: never;
17
+ path?: never;
18
+ cookie?: never;
19
+ };
20
+ get?: never;
21
+ put?: never;
22
+ /**
23
+ * Establish a public visitor session for a Work
24
+ * @description Binds a short-lived capability token to the Work, the caller Origin, the enabled capability set, and an expiry. The workKey locates the Work; it is never an authorization credential. CORS: exact registered origins only, credentials disabled.
25
+ */
26
+ post: operations["createWorkSession"];
27
+ delete?: never;
28
+ options?: never;
29
+ head?: never;
30
+ patch?: never;
31
+ trace?: never;
32
+ };
33
+ }
34
+ export type webhooks = Record<string, never>;
35
+ export interface components {
36
+ schemas: {
37
+ /** @description Public opaque work key. */
38
+ WorkKey: string;
39
+ /** @description Enabled capability name for the work. */
40
+ CapabilityName: string;
41
+ CreateWorkSessionRequest: {
42
+ workKey: components["schemas"]["WorkKey"];
43
+ };
44
+ WorkDescriptor: {
45
+ key: components["schemas"]["WorkKey"];
46
+ capabilities: components["schemas"]["CapabilityName"][];
47
+ } & {
48
+ [key: string]: unknown;
49
+ };
50
+ /** @description Unknown additional fields are allowed and ignored by the SDK (forward compatibility). */
51
+ WorkSession: {
52
+ work: components["schemas"]["WorkDescriptor"];
53
+ /** @description Short-lived capability token; memory-only in the SDK. */
54
+ token?: string;
55
+ /** @description Epoch milliseconds when the token expires. */
56
+ expiresAt?: number;
57
+ } & {
58
+ [key: string]: unknown;
59
+ };
60
+ ErrorBody: {
61
+ error: {
62
+ /** @enum {string} */
63
+ code: "CONFIG_INVALID" | "WORK_NOT_FOUND" | "ORIGIN_NOT_ALLOWED" | "CAPABILITY_DISABLED" | "SESSION_EXPIRED" | "RATE_LIMITED" | "NETWORK_TIMEOUT" | "CHECKOUT_UNAVAILABLE" | "INTERNAL_ERROR";
64
+ message?: string;
65
+ retryable?: boolean;
66
+ requestId?: string;
67
+ };
68
+ };
69
+ };
70
+ responses: {
71
+ /** @description Invalid configuration. */
72
+ ValidationError: {
73
+ headers: {
74
+ [name: string]: unknown;
75
+ };
76
+ content: {
77
+ "application/json": components["schemas"]["ErrorBody"];
78
+ };
79
+ };
80
+ /** @description Origin not registered for this work (fail closed). */
81
+ OriginNotAllowed: {
82
+ headers: {
83
+ [name: string]: unknown;
84
+ };
85
+ content: {
86
+ "application/json": components["schemas"]["ErrorBody"];
87
+ };
88
+ };
89
+ /** @description Unknown, private, or disabled work. */
90
+ WorkNotFound: {
91
+ headers: {
92
+ [name: string]: unknown;
93
+ };
94
+ content: {
95
+ "application/json": components["schemas"]["ErrorBody"];
96
+ };
97
+ };
98
+ /** @description Rate limit exceeded (retryable). */
99
+ RateLimited: {
100
+ headers: {
101
+ [name: string]: unknown;
102
+ };
103
+ content: {
104
+ "application/json": components["schemas"]["ErrorBody"];
105
+ };
106
+ };
107
+ /** @description Server error (retryable). */
108
+ InternalError: {
109
+ headers: {
110
+ [name: string]: unknown;
111
+ };
112
+ content: {
113
+ "application/json": components["schemas"]["ErrorBody"];
114
+ };
115
+ };
116
+ };
117
+ parameters: never;
118
+ requestBodies: never;
119
+ headers: never;
120
+ pathItems: never;
121
+ }
122
+ export type $defs = Record<string, never>;
123
+ export interface operations {
124
+ createWorkSession: {
125
+ parameters: {
126
+ query?: never;
127
+ header?: never;
128
+ path?: never;
129
+ cookie?: never;
130
+ };
131
+ requestBody: {
132
+ content: {
133
+ "application/json": components["schemas"]["CreateWorkSessionRequest"];
134
+ };
135
+ };
136
+ responses: {
137
+ /** @description Session established. */
138
+ 201: {
139
+ headers: {
140
+ /** @description Server request id for support correlation. */
141
+ "x-request-id"?: string;
142
+ [name: string]: unknown;
143
+ };
144
+ content: {
145
+ "application/json": components["schemas"]["WorkSession"];
146
+ };
147
+ };
148
+ 400: components["responses"]["ValidationError"];
149
+ 403: components["responses"]["OriginNotAllowed"];
150
+ 404: components["responses"]["WorkNotFound"];
151
+ 429: components["responses"]["RateLimited"];
152
+ "5xx": components["responses"]["InternalError"];
153
+ };
154
+ };
155
+ }
156
+ //# sourceMappingURL=public-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-contract.d.ts","sourceRoot":"","sources":["../../src/generated/public-contract.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAEH;;;GAGG;AAEH,MAAM,WAAW,KAAK;IAClB,0BAA0B,EAAE;QACxB,UAAU,EAAE;YACR,KAAK,CAAC,EAAE,KAAK,CAAC;YACd,MAAM,CAAC,EAAE,KAAK,CAAC;YACf,IAAI,CAAC,EAAE,KAAK,CAAC;YACb,MAAM,CAAC,EAAE,KAAK,CAAC;SAClB,CAAC;QACF,GAAG,CAAC,EAAE,KAAK,CAAC;QACZ,GAAG,CAAC,EAAE,KAAK,CAAC;QACZ;;;WAGG;QACH,IAAI,EAAE,UAAU,CAAC,mBAAmB,CAAC,CAAC;QACtC,MAAM,CAAC,EAAE,KAAK,CAAC;QACf,OAAO,CAAC,EAAE,KAAK,CAAC;QAChB,IAAI,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,KAAK,CAAC,EAAE,KAAK,CAAC;KACjB,CAAC;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,CAAC,CAAC;AAC1C,MAAM,WAAW,UAAU;IACvB,iBAAiB,EAAE;QACf,UAAU,EAAE;YACR,KAAK,CAAC,EAAE,KAAK,CAAC;YACd,MAAM,CAAC,EAAE,KAAK,CAAC;YACf,IAAI,CAAC,EAAE,KAAK,CAAC;YACb,MAAM,CAAC,EAAE,KAAK,CAAC;SAClB,CAAC;QACF,WAAW,EAAE;YACT,OAAO,EAAE;gBACL,kBAAkB,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,0BAA0B,CAAC,CAAC;aACzE,CAAC;SACL,CAAC;QACF,SAAS,EAAE;YACP,wCAAwC;YACxC,GAAG,EAAE;gBACD,OAAO,EAAE;oBACL,8DAA8D;oBAC9D,cAAc,CAAC,EAAE,MAAM,CAAC;oBACxB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;iBAC3B,CAAC;gBACF,OAAO,EAAE;oBACL,kBAAkB,EAAE,UAAU,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC;iBAC5D,CAAC;aACL,CAAC;YACF,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,iBAAiB,CAAC,CAAC;YAChD,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,kBAAkB,CAAC,CAAC;YACjD,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,CAAC;YAC7C,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,CAAC;YAC5C,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,eAAe,CAAC,CAAC;SACnD,CAAC;KACL,CAAC;CACL"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `@viceme-ai/sdk` public entry.
3
+ *
4
+ * Production consumers get exactly `createViceMe` plus types. Test injection
5
+ * lives under `@viceme-ai/sdk/testing`. Capability subpaths (danmaku, payment)
6
+ * are added only when the capability is real.
7
+ */
8
+ import { resolveApiBaseUrl } from './core/config.ts';
9
+ import { ViceMeError, isViceMeError, type ViceMeErrorCode } from './core/errors.ts';
10
+ import type { ViceMeClient, ViceMeMountedInstance } from './core/client.ts';
11
+ import type { ViceMeRegion, ViceMeConfig } from './core/config.ts';
12
+ import type { ViceMeClientState } from './core/lifecycle.ts';
13
+ import { SDK_VERSION, API_MAJOR } from './version.ts';
14
+ export { ViceMeError, isViceMeError, SDK_VERSION, API_MAJOR, resolveApiBaseUrl };
15
+ export type { ViceMeClient, ViceMeMountedInstance, ViceMeConfig, ViceMeRegion, ViceMeClientState, ViceMeErrorCode, };
16
+ /**
17
+ * Create a headless ViceMe client for one Work.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
22
+ * await client.ready();
23
+ * client.destroy();
24
+ * ```
25
+ */
26
+ export declare function createViceMe(config: unknown): ViceMeClient;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,iBAAiB,EAAwB,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;AACjF,YAAY,EACV,YAAY,EACZ,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,GAChB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CAM1D"}
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
1
+ import { V as i, v as b, a as O, r as p } from "./chunks/client-CGU3qeew.js";
2
+ import { A as w, S as L, i as S } from "./chunks/client-CGU3qeew.js";
3
+ const A = 1e4, h = /* @__PURE__ */ new Map([
4
+ [400, "CONFIG_INVALID"],
5
+ [401, "SESSION_EXPIRED"],
6
+ [403, "ORIGIN_NOT_ALLOWED"],
7
+ [404, "WORK_NOT_FOUND"],
8
+ [409, "CONFIG_INVALID"],
9
+ [422, "CONFIG_INVALID"],
10
+ [429, "RATE_LIMITED"]
11
+ ]), m = /* @__PURE__ */ new Set([
12
+ "CONFIG_INVALID",
13
+ "WORK_NOT_FOUND",
14
+ "ORIGIN_NOT_ALLOWED",
15
+ "CAPABILITY_DISABLED",
16
+ "SESSION_EXPIRED",
17
+ "RATE_LIMITED",
18
+ "NETWORK_TIMEOUT",
19
+ "CHECKOUT_UNAVAILABLE",
20
+ "INTERNAL_ERROR"
21
+ ]);
22
+ function T(o) {
23
+ if (typeof o != "object" || o === null) return {};
24
+ const e = o.error;
25
+ if (typeof e != "object" || e === null) return {};
26
+ const t = e, s = {};
27
+ return typeof t.code == "string" && m.has(t.code) && (s.code = t.code), typeof t.message == "string" && (s.message = t.message.slice(0, 200)), typeof t.retryable == "boolean" && (s.retryable = t.retryable), typeof t.requestId == "string" && (s.requestId = t.requestId), s;
28
+ }
29
+ function N() {
30
+ return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `req-${Math.random().toString(36).slice(2)}`;
31
+ }
32
+ class _ {
33
+ #e;
34
+ #t;
35
+ #r;
36
+ #o;
37
+ constructor(e) {
38
+ this.#e = e.apiBaseUrl.replace(/\/+$/, ""), this.#t = e.fetchImpl ?? globalThis.fetch.bind(globalThis), this.#r = e.defaultTimeoutMs ?? A, this.#o = e.generateRequestId ?? N;
39
+ }
40
+ async request(e) {
41
+ if (e.signal?.aborted)
42
+ throw this.#s(e.signal);
43
+ const t = e.timeoutMs ?? this.#r, s = new AbortController();
44
+ let c = !1;
45
+ const f = setTimeout(() => {
46
+ c = !0, s.abort(new I());
47
+ }, t), d = () => s.abort(new I(!1));
48
+ e.signal?.addEventListener("abort", d, { once: !0 });
49
+ const l = this.#o();
50
+ try {
51
+ const r = await this.#t(`${this.#e}${e.path}`, {
52
+ method: e.method,
53
+ // Public API is CORS-only; credentials must stay off so Shop session
54
+ // cookies can never attach to public SDK requests.
55
+ credentials: "omit",
56
+ mode: "cors",
57
+ headers: {
58
+ "content-type": "application/json",
59
+ "x-client-request-id": l
60
+ },
61
+ body: e.body !== void 0 ? JSON.stringify(e.body) : void 0,
62
+ signal: s.signal
63
+ });
64
+ let a;
65
+ try {
66
+ a = await r.json();
67
+ } catch (n) {
68
+ if (e.signal?.aborted || c)
69
+ throw n;
70
+ a = void 0;
71
+ }
72
+ const u = r.headers.get("x-request-id") ?? void 0;
73
+ if (!r.ok) {
74
+ const n = T(a), E = n.code ?? h.get(r.status) ?? "INTERNAL_ERROR";
75
+ throw new i({
76
+ code: E,
77
+ message: n.message ?? "Public API request failed.",
78
+ retryable: n.retryable,
79
+ requestId: n.requestId ?? u
80
+ });
81
+ }
82
+ return { status: r.status, body: a, requestId: u };
83
+ } catch (r) {
84
+ throw e.signal?.aborted ? this.#s(e.signal) : c ? new i({
85
+ code: "NETWORK_TIMEOUT",
86
+ message: "Public API request timed out.",
87
+ retryable: !0,
88
+ requestId: l
89
+ }) : r instanceof i ? r : r instanceof DOMException && r.name === "AbortError" ? new DOMException("ViceMe request aborted by caller.", "AbortError") : new i({
90
+ code: "INTERNAL_ERROR",
91
+ message: "Public API request failed.",
92
+ retryable: !0,
93
+ requestId: l
94
+ });
95
+ } finally {
96
+ clearTimeout(f), e.signal?.removeEventListener("abort", d);
97
+ }
98
+ }
99
+ /** Caller-abort error that preserves the caller's own abort reason. */
100
+ #s(e) {
101
+ return e.reason instanceof Error ? e.reason : new DOMException("ViceMe request aborted by caller.", "AbortError");
102
+ }
103
+ }
104
+ function g(o) {
105
+ return new _(o);
106
+ }
107
+ class I extends DOMException {
108
+ constructor(e = !0) {
109
+ super(e ? "ViceMe request timed out." : "ViceMe request aborted.", "AbortError");
110
+ }
111
+ }
112
+ function R(o) {
113
+ const e = b(o), t = g({
114
+ apiBaseUrl: p(e.region)
115
+ });
116
+ return new O({ config: e, transport: t });
117
+ }
118
+ export {
119
+ w as API_MAJOR,
120
+ L as SDK_VERSION,
121
+ i as ViceMeError,
122
+ R as createViceMe,
123
+ S as isViceMeError,
124
+ p as resolveApiBaseUrl
125
+ };
126
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/transport/transport.ts","../src/index.ts"],"sourcesContent":["/**\n * HTTP transport for the public API.\n *\n * Responsibilities: request execution with timeout, abort, client request ids,\n * and normalization of every failure into the public `ViceMeError` model.\n * Capabilities and the loader never build their own `fetch` calls — they go\n * through a Transport so tests can swap in `createMemoryTransport`.\n */\n\nimport { ViceMeError, type ViceMeErrorCode } from '../core/errors.ts';\n\nexport interface TransportRequest {\n method: 'GET' | 'POST';\n /** Absolute path under the public API base, e.g. `/public/v1/work-sessions`. */\n path: string;\n /** JSON-serializable request body. */\n body?: unknown;\n signal?: AbortSignal;\n /** Per-request timeout; defaults to the transport default. */\n timeoutMs?: number;\n}\n\nexport interface TransportResponse {\n status: number;\n body?: unknown;\n /** Echoed server request id, when provided. */\n requestId?: string;\n}\n\nexport interface Transport {\n request(request: TransportRequest): Promise<TransportResponse>;\n}\n\nexport interface FetchTransportOptions {\n apiBaseUrl: string;\n /** Injectable for tests; defaults to global `fetch`. */\n fetchImpl?: typeof fetch;\n defaultTimeoutMs?: number;\n /** Injectable id generator (default: `crypto.randomUUID`). */\n generateRequestId?: () => string;\n}\n\nconst DEFAULT_TIMEOUT_MS = 10_000;\n\nconst STATUS_CODE_MAP: ReadonlyMap<number, ViceMeErrorCode> = new Map([\n [400, 'CONFIG_INVALID'],\n [401, 'SESSION_EXPIRED'],\n [403, 'ORIGIN_NOT_ALLOWED'],\n [404, 'WORK_NOT_FOUND'],\n [409, 'CONFIG_INVALID'],\n [422, 'CONFIG_INVALID'],\n [429, 'RATE_LIMITED'],\n]);\n\nconst KNOWN_CODES: ReadonlySet<string> = new Set([\n 'CONFIG_INVALID',\n 'WORK_NOT_FOUND',\n 'ORIGIN_NOT_ALLOWED',\n 'CAPABILITY_DISABLED',\n 'SESSION_EXPIRED',\n 'RATE_LIMITED',\n 'NETWORK_TIMEOUT',\n 'CHECKOUT_UNAVAILABLE',\n 'INTERNAL_ERROR',\n]);\n\n/** Extract a stable error payload from a JSON error body, if well-formed. */\nfunction parseErrorBody(body: unknown): {\n code?: ViceMeErrorCode;\n message?: string;\n retryable?: boolean;\n requestId?: string;\n} {\n if (typeof body !== 'object' || body === null) return {};\n const error = (body as { error?: unknown }).error;\n if (typeof error !== 'object' || error === null) return {};\n const candidate = error as Record<string, unknown>;\n const result: {\n code?: ViceMeErrorCode;\n message?: string;\n retryable?: boolean;\n requestId?: string;\n } = {};\n if (typeof candidate.code === 'string' && KNOWN_CODES.has(candidate.code)) {\n result.code = candidate.code as ViceMeErrorCode;\n }\n if (typeof candidate.message === 'string') {\n result.message = candidate.message.slice(0, 200);\n }\n if (typeof candidate.retryable === 'boolean') {\n result.retryable = candidate.retryable;\n }\n if (typeof candidate.requestId === 'string') {\n result.requestId = candidate.requestId;\n }\n return result;\n}\n\nfunction defaultRequestId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `req-${Math.random().toString(36).slice(2)}`;\n}\n\nexport class FetchTransport implements Transport {\n readonly #apiBaseUrl: string;\n readonly #fetchImpl: typeof fetch;\n readonly #defaultTimeoutMs: number;\n readonly #generateRequestId: () => string;\n\n constructor(options: FetchTransportOptions) {\n this.#apiBaseUrl = options.apiBaseUrl.replace(/\\/+$/, '');\n this.#fetchImpl = options.fetchImpl ?? globalThis.fetch.bind(globalThis);\n this.#defaultTimeoutMs = options.defaultTimeoutMs ?? DEFAULT_TIMEOUT_MS;\n this.#generateRequestId = options.generateRequestId ?? defaultRequestId;\n }\n\n async request(request: TransportRequest): Promise<TransportResponse> {\n // A pre-aborted signal must never reach the network. Preserve the\n // caller's abort reason when one was set.\n if (request.signal?.aborted) {\n throw this.#callerAbortError(request.signal);\n }\n const timeoutMs = request.timeoutMs ?? this.#defaultTimeoutMs;\n const controller = new AbortController();\n // Engine notes: Chrome/Firefox reject fetch with the abort reason and\n // WebKit may reject with a plain error — so timeout/abort classification\n // keys off our own timer/signal state, never off the exception shape.\n let timedOut = false;\n const timer = setTimeout(() => {\n timedOut = true;\n controller.abort(new TimeoutAbort());\n }, timeoutMs);\n const onOuterAbort = () => controller.abort(new TimeoutAbort(false));\n request.signal?.addEventListener('abort', onOuterAbort, { once: true });\n\n const requestId = this.#generateRequestId();\n try {\n const response = await this.#fetchImpl(`${this.#apiBaseUrl}${request.path}`, {\n method: request.method,\n // Public API is CORS-only; credentials must stay off so Shop session\n // cookies can never attach to public SDK requests.\n credentials: 'omit',\n mode: 'cors',\n headers: {\n 'content-type': 'application/json',\n 'x-client-request-id': requestId,\n },\n body: request.body !== undefined ? JSON.stringify(request.body) : undefined,\n signal: controller.signal,\n });\n\n // Body reading stays inside the same timeout/abort lifecycle: a server\n // that returns headers and then stalls the body still hits\n // NETWORK_TIMEOUT, caller abort still cancels the read, and a late\n // body can never outlive a destroyed client/session.\n let body: unknown;\n try {\n body = await response.json();\n } catch (error) {\n // A malformed/empty body is tolerated; a cancelled read must\n // propagate so the outer handler can classify it.\n if (request.signal?.aborted || timedOut) {\n throw error;\n }\n body = undefined;\n }\n\n const serverRequestId = response.headers.get('x-request-id') ?? undefined;\n if (!response.ok) {\n const parsed = parseErrorBody(body);\n const code = parsed.code ?? STATUS_CODE_MAP.get(response.status) ?? 'INTERNAL_ERROR';\n throw new ViceMeError({\n code,\n message: parsed.message ?? 'Public API request failed.',\n retryable: parsed.retryable,\n requestId: parsed.requestId ?? serverRequestId,\n });\n }\n return { status: response.status, body, requestId: serverRequestId };\n } catch (cause) {\n if (request.signal?.aborted) {\n throw this.#callerAbortError(request.signal);\n }\n if (timedOut) {\n throw new ViceMeError({\n code: 'NETWORK_TIMEOUT',\n message: 'Public API request timed out.',\n retryable: true,\n requestId,\n });\n }\n // Non-OK statuses already carry a normalized error — pass it through.\n if (cause instanceof ViceMeError) {\n throw cause;\n }\n if (cause instanceof DOMException && cause.name === 'AbortError') {\n throw new DOMException('ViceMe request aborted by caller.', 'AbortError');\n }\n throw new ViceMeError({\n code: 'INTERNAL_ERROR',\n message: 'Public API request failed.',\n retryable: true,\n requestId,\n });\n } finally {\n clearTimeout(timer);\n request.signal?.removeEventListener('abort', onOuterAbort);\n }\n }\n\n /** Caller-abort error that preserves the caller's own abort reason. */\n #callerAbortError(signal: AbortSignal): unknown {\n return signal.reason instanceof Error\n ? signal.reason\n : new DOMException('ViceMe request aborted by caller.', 'AbortError');\n }\n}\n\nexport function createFetchTransport(options: FetchTransportOptions): Transport {\n return new FetchTransport(options);\n}\n\n/** Internal marker distinguishing timeout aborts from caller aborts. */\nclass TimeoutAbort extends DOMException {\n constructor(timedOut = true) {\n super(timedOut ? 'ViceMe request timed out.' : 'ViceMe request aborted.', 'AbortError');\n }\n}\n","/**\n * `@viceme-ai/sdk` public entry.\n *\n * Production consumers get exactly `createViceMe` plus types. Test injection\n * lives under `@viceme-ai/sdk/testing`. Capability subpaths (danmaku, payment)\n * are added only when the capability is real.\n */\n\nimport { createFetchTransport } from './transport/transport.ts';\nimport { resolveApiBaseUrl, validatePublicConfig } from './core/config.ts';\nimport { ViceMeClientImpl } from './core/client.ts';\nimport { ViceMeError, isViceMeError, type ViceMeErrorCode } from './core/errors.ts';\nimport type { ViceMeClient, ViceMeMountedInstance } from './core/client.ts';\nimport type { ViceMeRegion, ViceMeConfig } from './core/config.ts';\nimport type { ViceMeClientState } from './core/lifecycle.ts';\nimport { SDK_VERSION, API_MAJOR } from './version.ts';\n\nexport { ViceMeError, isViceMeError, SDK_VERSION, API_MAJOR, resolveApiBaseUrl };\nexport type {\n ViceMeClient,\n ViceMeMountedInstance,\n ViceMeConfig,\n ViceMeRegion,\n ViceMeClientState,\n ViceMeErrorCode,\n};\n\n/**\n * Create a headless ViceMe client for one Work.\n *\n * @example\n * ```ts\n * const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });\n * await client.ready();\n * client.destroy();\n * ```\n */\nexport function createViceMe(config: unknown): ViceMeClient {\n const validated = validatePublicConfig(config);\n const transport = createFetchTransport({\n apiBaseUrl: resolveApiBaseUrl(validated.region),\n });\n return new ViceMeClientImpl({ config: validated, transport });\n}\n"],"names":["DEFAULT_TIMEOUT_MS","STATUS_CODE_MAP","KNOWN_CODES","parseErrorBody","body","error","candidate","result","defaultRequestId","FetchTransport","#apiBaseUrl","#fetchImpl","#defaultTimeoutMs","#generateRequestId","options","request","#callerAbortError","timeoutMs","controller","timedOut","timer","TimeoutAbort","onOuterAbort","requestId","response","serverRequestId","parsed","code","ViceMeError","cause","signal","createFetchTransport","createViceMe","config","validated","validatePublicConfig","transport","resolveApiBaseUrl","ViceMeClientImpl"],"mappings":";;AA0CA,MAAMA,IAAqB,KAErBC,wBAA4D,IAAI;AAAA,EACpE,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,iBAAiB;AAAA,EACvB,CAAC,KAAK,oBAAoB;AAAA,EAC1B,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,cAAc;AACtB,CAAC,GAEKC,wBAAuC,IAAI;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;A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B,MAAM;AAAA,QACN,SAAS;AAAA,QACT,WAAW;AAAA,QACX,WAAAL;AAAA,MAAA,CACD,IAGCM,aAAiBD,IACbC,IAEJA,aAAiB,gBAAgBA,EAAM,SAAS,eAC5C,IAAI,aAAa,qCAAqC,YAAY,IAEpE,IAAID,EAAY;AAAA,QACpB,MAAM;AAAA,QACN,SAAS;AAAA,QACT,WAAW;AAAA,QACX,WAAAL;AAAA,MAAA,CACD;AAAA,IACH,UAAA;AACE,mBAAaH,CAAK,GAClBL,EAAQ,QAAQ,oBAAoB,SAASO,CAAY;AAAA,IAC3D;AAAA,EACF;AAAA;AAAA,EAGAN,GAAkBc,GAA8B;AAC9C,WAAOA,EAAO,kBAAkB,QAC5BA,EAAO,SACP,IAAI,aAAa,qCAAqC,YAAY;AAAA,EACxE;AACF;AAEO,SAASC,EAAqBjB,GAA2C;AAC9E,SAAO,IAAIL,EAAeK,CAAO;AACnC;AAGA,MAAMO,UAAqB,aAAa;AAAA,EACtC,YAAYF,IAAW,IAAM;AAC3B,UAAMA,IAAW,8BAA8B,2BAA2B,YAAY;AAAA,EACxF;AACF;AChMO,SAASa,EAAaC,GAA+B;AAC1D,QAAMC,IAAYC,EAAqBF,CAAM,GACvCG,IAAYL,EAAqB;AAAA,IACrC,YAAYM,EAAkBH,EAAU,MAAM;AAAA,EAAA,CAC/C;AACD,SAAO,IAAII,EAAiB,EAAE,QAAQJ,GAAW,WAAAE,GAAW;AAC9D;"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * `data-viceme-*` attribute parsing for the CDN auto-loader.
3
+ *
4
+ * The attribute set is fixed; unknown `data-viceme-*` attributes are rejected
5
+ * so pages can never smuggle endpoints, tokens, secrets, prices, or payment
6
+ * state through the loader. Parse failures never guess defaults for work,
7
+ * region, or target.
8
+ */
9
+ import type { ViceMeRegion } from '../core/config.ts';
10
+ export type ViceMeTheme = 'light' | 'dark' | 'auto';
11
+ export interface LoaderAttributes {
12
+ workKey: string;
13
+ region: ViceMeRegion;
14
+ /** Deduplicated feature names in declared order. */
15
+ features: string[];
16
+ /** CSS selector; required whenever features are declared. */
17
+ target?: string;
18
+ theme: ViceMeTheme;
19
+ }
20
+ export declare function parseLoaderAttributes(element: Element): LoaderAttributes;
21
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../src/loader/attributes.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,WAAW,CAAC;CACpB;AAeD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAyDxE"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * CDN auto-loader (`viceme.min.js`, IIFE).
3
+ *
4
+ * Deterministic algorithm (fixed baseline):
5
+ *
6
+ * 1. Read `document.currentScript`; when unavailable, accept exactly one
7
+ * explicit `script[data-viceme-loader]`.
8
+ * 2. Parse and validate `data-viceme-*`; build `clientKey` and per-feature
9
+ * `instanceKey`s.
10
+ * 3. Wait for DOM ready; a missing/ambiguous target emits `CONFIG_INVALID`
11
+ * and never creates phantom nodes.
12
+ * 4. Read `manifest.json` from the loader's own directory (exact release
13
+ * version; URLs are never assembled from page parameters).
14
+ * 5. Load the same-version core, then each declared feature chunk in order.
15
+ * 6. Create the client, then mount; handles land in an internal registry.
16
+ * 7. Re-running the same instance key returns the original handle — no
17
+ * duplicate sessions, subscriptions, or DOM.
18
+ * 8. A failing capability destroys only its own partial state; the rest of
19
+ * the page and other capabilities keep working.
20
+ * 9. `pagehide` never auto-destroys (bfcache); cleanup happens on explicit
21
+ * `destroy()` only.
22
+ *
23
+ * The loader never writes localStorage, cookies, global CSS, or globals other
24
+ * than the fixed `window.ViceMe.versions.vN` namespace.
25
+ */
26
+ import { type RegisteredInstance } from './registry.ts';
27
+ import type { ViceMeClient, ViceMeMountedInstance } from '../core/client.ts';
28
+ export interface ReleaseManifest {
29
+ version: string;
30
+ apiMajor: number;
31
+ loader: string;
32
+ features: Record<string, string>;
33
+ }
34
+ export interface ViceMeLoaderNamespaceV1 {
35
+ readonly version: string;
36
+ whenReady(clientKey: string): Promise<ViceMeClient>;
37
+ getInstance(instanceKey: string): ViceMeMountedInstance | undefined;
38
+ destroyInstance(instanceKey: string): void;
39
+ destroyClient(clientKey: string): void;
40
+ }
41
+ export interface ViceMeBrowserGlobal {
42
+ versions: {
43
+ [major: string]: ViceMeLoaderNamespaceV1 | undefined;
44
+ };
45
+ }
46
+ export declare function ensureNamespace(version: string): ViceMeLoaderNamespaceV1;
47
+ export declare function runAutoLoader(script: HTMLScriptElement): Promise<void>;
48
+ declare function bootstrap(): void;
49
+ export declare const __bootstrapForTests: typeof bootstrap;
50
+ export type { RegisteredInstance };
51
+ //# sourceMappingURL=auto-loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-loader.d.ts","sourceRoot":"","sources":["../../src/loader/auto-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAGH,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAIrF,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG7E,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAWD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAC;IACpE,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3C,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACxC;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE;QAER,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS,CAAC;KACtD,CAAC;CACH;AA2ED,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,uBAAuB,CA2CxE;AAuID,wBAAsB,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAkJ5E;AAkBD,iBAAS,SAAS,IAAI,IAAI,CAYzB;AAKD,eAAO,MAAM,mBAAmB,kBAAY,CAAC;AAC7C,YAAY,EAAE,kBAAkB,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../../src/loader/bootstrap.ts"],"names":[],"mappings":""}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Stable `viceme:*` DOM events.
3
+ *
4
+ * Dispatch target is the mount host element; configuration errors that happen
5
+ * before a host exists are dispatched on `document`. Event details carry an
6
+ * allowlisted field set only — never tokens, cookies, provider payloads, or
7
+ * internal stacks.
8
+ */
9
+ import type { ViceMeErrorCode } from '../core/errors.ts';
10
+ export interface VicemeReadyDetail {
11
+ clientKey: string;
12
+ workKey: string;
13
+ capabilities: string[];
14
+ version: string;
15
+ }
16
+ export interface VicemeCapabilityReadyDetail {
17
+ clientKey: string;
18
+ instanceKey: string;
19
+ capability: string;
20
+ version: string;
21
+ }
22
+ export interface VicemeErrorDetail {
23
+ clientKey?: string;
24
+ instanceKey?: string;
25
+ capability?: string;
26
+ code: ViceMeErrorCode;
27
+ retryable: boolean;
28
+ requestId?: string;
29
+ }
30
+ export interface VicemeDestroyedDetail {
31
+ clientKey: string;
32
+ instanceKey: string;
33
+ capability: string;
34
+ }
35
+ export type VicemeEventType = 'viceme:ready' | 'viceme:capability-ready' | 'viceme:error' | 'viceme:destroyed';
36
+ export type VicemeEventDetailMap = {
37
+ 'viceme:ready': VicemeReadyDetail;
38
+ 'viceme:capability-ready': VicemeCapabilityReadyDetail;
39
+ 'viceme:error': VicemeErrorDetail;
40
+ 'viceme:destroyed': VicemeDestroyedDetail;
41
+ };
42
+ /** Strip anything outside the documented allowlist before dispatch. */
43
+ export declare function sanitizeDetail(type: VicemeEventType, detail: VicemeEventDetailMap[VicemeEventType]): VicemeEventDetailMap[VicemeEventType];
44
+ export declare function dispatchViceMeEvent<K extends VicemeEventType>(target: EventTarget, type: K, detail: VicemeEventDetailMap[K]): void;
45
+ //# sourceMappingURL=events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/loader/events.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,eAAe,GACzB,cAAc,GAAG,yBAAyB,GAAG,cAAc,GAAG,kBAAkB,CAAC;AAEnF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,iBAAiB,CAAC;IAClC,yBAAyB,EAAE,2BAA2B,CAAC;IACvD,cAAc,EAAE,iBAAiB,CAAC;IAClC,kBAAkB,EAAE,qBAAqB,CAAC;CAC3C,CAAC;AAYF,uEAAuE;AACvE,wBAAgB,cAAc,CAC5B,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,oBAAoB,CAAC,eAAe,CAAC,GAC5C,oBAAoB,CAAC,eAAe,CAAC,CAOvC;AAED,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,eAAe,EAC3D,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,CAAC,EACP,MAAM,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC9B,IAAI,CAQN"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * IIFE entry for the CDN auto-loader.
3
+ *
4
+ * Side-effect only: imports the loader (which bootstraps from
5
+ * `document.currentScript`) and exports nothing, so the built
6
+ * `viceme.min.js` never leaves a global binding behind — the fixed
7
+ * `window.ViceMe.versions.v1` namespace is installed non-enumerably by the
8
+ * loader itself.
9
+ */
10
+ import './auto-loader.ts';
11
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/loader/main.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,kBAAkB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The handle a capability `mount()` returns to the loader (headless, no
3
+ * registry/identity concerns). The loader wraps it into the public
4
+ * `ViceMeMountedInstance`, which carries the registry-assigned `instanceKey`
5
+ * and owns idempotent destroy + event dispatch.
6
+ */
7
+ import type { ViceMeClient } from '../core/client.ts';
8
+ import type { ViceMeTheme } from './attributes.ts';
9
+ export interface CapabilityMountOptions {
10
+ /** Mount host element; the capability owns its Shadow DOM subtree. */
11
+ target: Element;
12
+ theme: ViceMeTheme;
13
+ }
14
+ /** A capability's own lifecycle handle — no `instanceKey`, no registry. */
15
+ export interface CapabilityMountHandle {
16
+ readonly capability: string;
17
+ /** Remove listeners, observers, timers, portals, and Shadow DOM nodes. */
18
+ destroy(): void;
19
+ }
20
+ export type CapabilityMountFunction = (client: ViceMeClient, options: CapabilityMountOptions) => Promise<CapabilityMountHandle>;
21
+ /** Convenience for ESM-direct capability entry points. */
22
+ export interface ViceMeCapabilityModule {
23
+ mount: CapabilityMountFunction;
24
+ }
25
+ //# sourceMappingURL=mount-handle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mount-handle.d.ts","sourceRoot":"","sources":["../../src/loader/mount-handle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,WAAW,CAAC;CACpB;AAED,2EAA2E;AAC3E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,0EAA0E;IAC1E,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,uBAAuB,GAAG,CACpC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,sBAAsB,KAC5B,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAEpC,0DAA0D;AAC1D,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,uBAAuB,CAAC;CAChC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Loader registry.
3
+ *
4
+ * Only the CDN loader maintains this registry (explicit `createViceMe()`
5
+ * instances never register). Core clients are shared by
6
+ * `major + region + workKey`; capability mounts are deduplicated by
7
+ * `clientKey + capability + target Element identity`.
8
+ *
9
+ * The registry itself is never exposed on `window` — only the fixed
10
+ * `ViceMe.versions.v1` diagnostics/destroy namespace is. It stores raw
11
+ * capability handles; the loader wraps them into the public
12
+ * `ViceMeMountedInstance` and owns destroy/event deduplication.
13
+ */
14
+ import type { ViceMeClient } from '../core/client.ts';
15
+ import type { CapabilityMountHandle } from './mount-handle.ts';
16
+ export interface RegisteredClient {
17
+ clientKey: string;
18
+ client: ViceMeClient;
19
+ ready: Promise<void>;
20
+ }
21
+ export interface RegisteredInstance {
22
+ instanceKey: string;
23
+ clientKey: string;
24
+ capability: string;
25
+ host: Element;
26
+ raw: CapabilityMountHandle;
27
+ destroyed: boolean;
28
+ }
29
+ export declare function clientKeyOf(majorVersion: number, region: string, workKey: string): string;
30
+ export declare class LoaderRegistry {
31
+ #private;
32
+ getClient(clientKey: string): RegisteredClient | undefined;
33
+ registerClient(entry: RegisteredClient): void;
34
+ unregisterClient(clientKey: string): void;
35
+ getInstance(instanceKey: string): RegisteredInstance | undefined;
36
+ /** Existing mount for the same client+capability+element, if any. */
37
+ findInstance(clientKey: string, capability: string, element: Element): RegisteredInstance | undefined;
38
+ registerInstance(clientKey: string, capability: string, element: Element, raw: CapabilityMountHandle): RegisteredInstance;
39
+ removeInstance(instanceKey: string): RegisteredInstance | undefined;
40
+ instancesForClient(clientKey: string): RegisteredInstance[];
41
+ }
42
+ //# sourceMappingURL=registry.d.ts.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E,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAQnE,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,EAAE;CAG5D"}
@@ -0,0 +1,38 @@
1
+ {
2
+ "version": "0.1.2",
3
+ "apiMajor": 1,
4
+ "loader": "viceme.min.js",
5
+ "features": {},
6
+ "files": {
7
+ "bootstrap.min.js": {
8
+ "sha256": "390e260c83f55a077485b14c93c6e40440d84d5419fd48e4246a3b82ef59f398",
9
+ "sri": "sha384-RC4TWyaPaXrOTKEXMGP/KrcvUkJ6JyQqtl+WcUPN1JEiNKSp4Uf4jFzY3mkpgDzt",
10
+ "bytes": 935,
11
+ "gzipBytes": 585
12
+ },
13
+ "chunks/client-CGU3qeew.js": {
14
+ "sha256": "aa0dd0d96548f5f2407eba9771bdfc9d308e18b8b82c1020317d4baf951ef75f",
15
+ "sri": "sha384-OKBbC9Ou25tdP3F7ENuDaMV43raPG5ueYAKp8EcuUf+SOaGw4DCiaxHrqP+ifUMx",
16
+ "bytes": 7537,
17
+ "gzipBytes": 2743
18
+ },
19
+ "index.js": {
20
+ "sha256": "1dbd5dd4c3cee405f09b110c5450428dfa953bff8cc0162d4c4eb04f83ee31c7",
21
+ "sri": "sha384-iPA3K29jZimRRPVxMV5Y6UIFQni3Fs0nY7mKt6PQE3BRndOwb2M0a4wOc8us+ER5",
22
+ "bytes": 4142,
23
+ "gzipBytes": 1717
24
+ },
25
+ "testing.js": {
26
+ "sha256": "488e6f414de1aa65a1217c154cdac38335544b7226994b8f0969ab061c58b758",
27
+ "sri": "sha384-PWwNV0b8O3H9U6fSzviAHZVTeEqLAAhn+0a2NzEPFuLlvD1StjVcxbBr2XYMb0WV",
28
+ "bytes": 2156,
29
+ "gzipBytes": 983
30
+ },
31
+ "viceme.min.js": {
32
+ "sha256": "ac038a50a71720e49602223d89dde0f09b51917fb013c8a59a82858fa407b51c",
33
+ "sri": "sha384-KMteTHDhwmb8Ob4OpHSUda+Cupi7ZEbQUWvtIHf+hqiMCpBkE0OCm7NhDjwEJdtP",
34
+ "bytes": 10125,
35
+ "gzipBytes": 3642
36
+ }
37
+ }
38
+ }