@viceme-ai/sdk 0.2.0 → 0.4.0
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/README.md +46 -17
- package/dist/browser-events.d.ts +49 -0
- package/dist/browser-events.d.ts.map +1 -0
- package/dist/capability-mount.d.ts +15 -0
- package/dist/capability-mount.d.ts.map +1 -0
- package/dist/chunks/client-Cbldd7F2.js +949 -0
- package/dist/chunks/client-Cbldd7F2.js.map +1 -0
- package/dist/chunks/{version-BbUa2jZV.js → errors-B-Qv_azy.js} +27 -17
- package/dist/chunks/errors-B-Qv_azy.js.map +1 -0
- package/dist/chunks/version-C8DeBm39.js +6 -0
- package/dist/chunks/version-C8DeBm39.js.map +1 -0
- package/dist/core/build-endpoints.d.ts +5 -0
- package/dist/core/build-endpoints.d.ts.map +1 -1
- package/dist/core/capabilities.d.ts +79 -0
- package/dist/core/capabilities.d.ts.map +1 -0
- package/dist/core/client.d.ts +36 -8
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/config.d.ts +14 -4
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/errors.d.ts +1 -1
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/presentation.d.ts +29 -0
- package/dist/core/presentation.d.ts.map +1 -0
- package/dist/danmaku/index.d.ts +1 -0
- package/dist/danmaku/index.d.ts.map +1 -1
- package/dist/danmaku/mount.d.ts +1 -1
- package/dist/danmaku/mount.d.ts.map +1 -1
- package/dist/danmaku.js +127 -125
- package/dist/danmaku.js.map +1 -1
- package/dist/generated/public-contract.d.ts +291 -43
- package/dist/generated/public-contract.d.ts.map +1 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +114 -95
- package/dist/index.js.map +1 -1
- package/dist/loader/attributes.d.ts +3 -2
- package/dist/loader/attributes.d.ts.map +1 -1
- package/dist/loader/auto-loader.d.ts +1 -1
- package/dist/loader/auto-loader.d.ts.map +1 -1
- package/dist/loader/events.d.ts +1 -44
- package/dist/loader/events.d.ts.map +1 -1
- package/dist/loader/registry.d.ts +2 -1
- package/dist/loader/registry.d.ts.map +1 -1
- package/dist/manifest.json +44 -19
- package/dist/session/session.d.ts +68 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/testing/test-adapter.d.ts +59 -0
- package/dist/testing/test-adapter.d.ts.map +1 -0
- package/dist/testing.d.ts +9 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +76 -0
- package/dist/testing.js.map +1 -0
- package/dist/tip/index.d.ts +22 -0
- package/dist/tip/index.d.ts.map +1 -0
- package/dist/tip/mount.d.ts +5 -0
- package/dist/tip/mount.d.ts.map +1 -0
- package/dist/tip.js +137 -0
- package/dist/tip.js.map +1 -0
- package/dist/transport/transport.d.ts +46 -0
- package/dist/transport/transport.d.ts.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/viceme.min.js +212 -1
- package/dist/viceme.min.js.map +1 -1
- package/package.json +10 -2
- package/dist/chunks/version-BbUa2jZV.js.map +0 -1
- package/dist/loader/mount-handle.d.ts +0 -25
- package/dist/loader/mount-handle.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAClG,YAAY,EACV,eAAe,EACf,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,GACxB,MAAM,2BAA2B,CAAC"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { a as s } from "./chunks/errors-B-Qv_azy.js";
|
|
2
|
+
import { i as w, a as u, V as d } from "./chunks/client-Cbldd7F2.js";
|
|
3
|
+
function g(e) {
|
|
4
|
+
const i = [], o = [...e.sessionFailures ?? []], a = e.latencyMs ?? 0;
|
|
5
|
+
return {
|
|
6
|
+
requests: i,
|
|
7
|
+
async request(t) {
|
|
8
|
+
if (t.signal?.aborted)
|
|
9
|
+
throw new DOMException("Aborted", "AbortError");
|
|
10
|
+
if (i.push(t), await new Promise((r, n) => {
|
|
11
|
+
const c = t.signal, l = setTimeout(() => r(), a);
|
|
12
|
+
c?.addEventListener(
|
|
13
|
+
"abort",
|
|
14
|
+
() => {
|
|
15
|
+
clearTimeout(l), n(new DOMException("Aborted", "AbortError"));
|
|
16
|
+
},
|
|
17
|
+
{ once: !0 }
|
|
18
|
+
);
|
|
19
|
+
}), t.path === "/v1/public/work-sdk/sessions" && t.method === "POST") {
|
|
20
|
+
const r = o.shift();
|
|
21
|
+
if (r) {
|
|
22
|
+
if (r instanceof Error) throw r;
|
|
23
|
+
return {
|
|
24
|
+
status: r.status,
|
|
25
|
+
body: {
|
|
26
|
+
error: { code: r.code, message: r.message ?? "Simulated failure." }
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
status: 201,
|
|
32
|
+
body: {
|
|
33
|
+
workKey: e.work.key,
|
|
34
|
+
capabilities: [...e.work.capabilities],
|
|
35
|
+
...e.work.token !== void 0 ? { token: e.work.token } : {},
|
|
36
|
+
...e.work.expiresAt !== void 0 ? { expiresAt: new Date(e.work.expiresAt).toISOString() } : {}
|
|
37
|
+
},
|
|
38
|
+
requestId: `test-${i.length}`
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
status: 404,
|
|
43
|
+
body: { error: { code: "CONFIG_INVALID", message: `No fixture for ${t.path}.` } }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function m(e) {
|
|
49
|
+
if (!w(e.workKey))
|
|
50
|
+
throw s('Test client requires a valid workKey ("wrk_…").');
|
|
51
|
+
if (!u(e.region))
|
|
52
|
+
throw s('Test client requires region "cn" or "global".');
|
|
53
|
+
if (typeof e.transport?.request != "function")
|
|
54
|
+
throw s("Test client requires a transport with a request() method.");
|
|
55
|
+
return new d({
|
|
56
|
+
config: {
|
|
57
|
+
workKey: e.workKey,
|
|
58
|
+
region: e.region,
|
|
59
|
+
signal: e.signal
|
|
60
|
+
},
|
|
61
|
+
transport: e.transport,
|
|
62
|
+
presenter: e.presenter,
|
|
63
|
+
...e.now !== void 0 ? { now: e.now } : {}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const y = {
|
|
67
|
+
key: "wrk_test",
|
|
68
|
+
capabilities: ["fixture"],
|
|
69
|
+
token: "test-session-token"
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
y as FIXTURE_WORK,
|
|
73
|
+
g as createMemoryTransport,
|
|
74
|
+
m as createTestViceMe
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sources":["../src/testing/test-adapter.ts"],"sourcesContent":["/**\n * `@viceme-ai/sdk/testing` — explicit test adapter.\n *\n * Deterministic fixture helpers for SDK consumers and capability authors.\n * This code must never be imported from production core, loader, or capability\n * bundles; it is excluded from them at build time and only exported via the\n * `./testing` subpath.\n *\n * The test client runs the exact same config, lifecycle, error, and contract\n * validation as production `createViceMe()` — it is not a bypass mock.\n */\n\nimport { configInvalid } from '../core/errors.ts';\nimport { isValidWorkKey, isValidRegion } from '../core/config.ts';\nimport { ViceMeClientImpl } from '../core/client.ts';\nimport type { ViceMeClient } from '../core/client.ts';\nimport type { ViceMeRegion } from '../core/config.ts';\nimport type { AccessPresenter } from '../core/presentation.ts';\nimport type { Transport, TransportRequest, TransportResponse } from '../transport/transport.ts';\n\nexport interface MemoryTransportWorkFixture {\n key: string;\n capabilities: string[];\n token?: string;\n expiresAt?: number;\n}\n\nexport interface MemoryTransportOptions {\n /** Work descriptor served for `POST /v1/public/work-sdk/sessions`. */\n work: MemoryTransportWorkFixture;\n /** Artificial response latency in milliseconds (default 0). */\n latencyMs?: number;\n /**\n * Queue of failures thrown before the fixture response is served; each\n * entry is consumed by one session request. Use for retry/timeout tests.\n */\n sessionFailures?: Array<Error | { status: number; code: string; message?: string }>;\n}\n\nexport interface MemoryTransport extends Transport {\n /** Every request seen so far, for assertions. */\n readonly requests: TransportRequest[];\n}\n\nexport function createMemoryTransport(options: MemoryTransportOptions): MemoryTransport {\n const requests: TransportRequest[] = [];\n const failures = [...(options.sessionFailures ?? [])];\n const latencyMs = options.latencyMs ?? 0;\n\n return {\n requests,\n async request(request: TransportRequest): Promise<TransportResponse> {\n // A pre-aborted signal never counts as an issued request.\n if (request.signal?.aborted) {\n throw new DOMException('Aborted', 'AbortError');\n }\n requests.push(request);\n await new Promise<void>((resolve, reject) => {\n const signal = request.signal;\n const timer = setTimeout(() => resolve(), latencyMs);\n signal?.addEventListener(\n 'abort',\n () => {\n clearTimeout(timer);\n reject(new DOMException('Aborted', 'AbortError'));\n },\n { once: true },\n );\n });\n if (request.path === '/v1/public/work-sdk/sessions' && request.method === 'POST') {\n const failure = failures.shift();\n if (failure) {\n if (failure instanceof Error) throw failure;\n return {\n status: failure.status,\n body: {\n error: { code: failure.code, message: failure.message ?? 'Simulated failure.' },\n },\n };\n }\n return {\n status: 201,\n body: {\n workKey: options.work.key,\n capabilities: [...options.work.capabilities],\n ...(options.work.token !== undefined ? { token: options.work.token } : {}),\n ...(options.work.expiresAt !== undefined\n ? { expiresAt: new Date(options.work.expiresAt).toISOString() }\n : {}),\n },\n requestId: `test-${requests.length}`,\n };\n }\n return {\n status: 404,\n body: { error: { code: 'CONFIG_INVALID', message: `No fixture for ${request.path}.` } },\n };\n },\n };\n}\n\nexport interface CreateTestViceMeOptions {\n workKey: string;\n region: ViceMeRegion;\n /** Mock transport serving the fixture contract. */\n transport: Transport;\n signal?: AbortSignal;\n presenter?: AccessPresenter;\n /** Stable virtual clock for deterministic time-based assertions. */\n now?: () => number;\n}\n\n/**\n * Create a client backed by an injected transport. Runs identical validation\n * and lifecycle logic to `createViceMe()`.\n */\nexport function createTestViceMe(options: CreateTestViceMeOptions): ViceMeClient {\n if (!isValidWorkKey(options.workKey)) {\n throw configInvalid('Test client requires a valid workKey (\"wrk_…\").');\n }\n if (!isValidRegion(options.region)) {\n throw configInvalid('Test client requires region \"cn\" or \"global\".');\n }\n if (typeof options.transport?.request !== 'function') {\n throw configInvalid('Test client requires a transport with a request() method.');\n }\n return new ViceMeClientImpl({\n config: {\n workKey: options.workKey,\n region: options.region,\n signal: options.signal,\n },\n transport: options.transport,\n presenter: options.presenter,\n ...(options.now !== undefined ? { now: options.now } : {}),\n });\n}\n\n/** Standard fixture work used across repo tests and examples. */\nexport const FIXTURE_WORK: MemoryTransportWorkFixture = {\n key: 'wrk_test',\n capabilities: ['fixture'],\n token: 'test-session-token',\n};\n"],"names":["createMemoryTransport","options","requests","failures","latencyMs","request","resolve","reject","signal","timer","failure","createTestViceMe","isValidWorkKey","configInvalid","isValidRegion","ViceMeClientImpl","FIXTURE_WORK"],"mappings":";;AA4CO,SAASA,EAAsBC,GAAkD;AACtF,QAAMC,IAA+B,CAAA,GAC/BC,IAAW,CAAC,GAAIF,EAAQ,mBAAmB,CAAA,CAAG,GAC9CG,IAAYH,EAAQ,aAAa;AAEvC,SAAO;AAAA,IACL,UAAAC;AAAA,IACA,MAAM,QAAQG,GAAuD;AAEnE,UAAIA,EAAQ,QAAQ;AAClB,cAAM,IAAI,aAAa,WAAW,YAAY;AAehD,UAbAH,EAAS,KAAKG,CAAO,GACrB,MAAM,IAAI,QAAc,CAACC,GAASC,MAAW;AAC3C,cAAMC,IAASH,EAAQ,QACjBI,IAAQ,WAAW,MAAMH,EAAA,GAAWF,CAAS;AACnD,QAAAI,GAAQ;AAAA,UACN;AAAA,UACA,MAAM;AACJ,yBAAaC,CAAK,GAClBF,EAAO,IAAI,aAAa,WAAW,YAAY,CAAC;AAAA,UAClD;AAAA,UACA,EAAE,MAAM,GAAA;AAAA,QAAK;AAAA,MAEjB,CAAC,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;AAAA,IAAA;AAAA,IAElB,WAAWA,EAAQ;AAAA,IACnB,WAAWA,EAAQ;AAAA,IACnB,GAAIA,EAAQ,QAAQ,SAAY,EAAE,KAAKA,EAAQ,QAAQ,CAAA;AAAA,EAAC,CACzD;AACH;AAGO,MAAMe,IAA2C;AAAA,EACtD,KAAK;AAAA,EACL,cAAc,CAAC,SAAS;AAAA,EACxB,OAAO;AACT;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
2
|
+
export interface TipMountOptions {
|
|
3
|
+
target: Element;
|
|
4
|
+
theme: 'light' | 'dark' | 'auto';
|
|
5
|
+
signal?: AbortSignal;
|
|
6
|
+
}
|
|
7
|
+
export interface TipMountHandle {
|
|
8
|
+
readonly capability: 'tip';
|
|
9
|
+
destroy(): void;
|
|
10
|
+
}
|
|
11
|
+
export interface TipWidgetCloseDetail {
|
|
12
|
+
workId: string;
|
|
13
|
+
}
|
|
14
|
+
export interface TipPaidDetail {
|
|
15
|
+
workId: string;
|
|
16
|
+
orderNo: string;
|
|
17
|
+
status: 'PAID';
|
|
18
|
+
amountCents: number;
|
|
19
|
+
}
|
|
20
|
+
/** Explicit ESM/npm entry point; the CDN loader calls the same mount function. */
|
|
21
|
+
export declare function mountTip(client: ViceMeClient, options: TipMountOptions): Promise<TipMountHandle>;
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tip/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC;IAC3B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAID,kFAAkF;AAClF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAgChG"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
2
|
+
import type { CapabilityMountHandle, CapabilityMountOptions } from '../capability-mount.ts';
|
|
3
|
+
export declare const FRAME_READY_TIMEOUT_MS = 8000;
|
|
4
|
+
export declare function mount(client: ViceMeClient, options: CapabilityMountOptions): Promise<CapabilityMountHandle>;
|
|
5
|
+
//# sourceMappingURL=mount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../src/tip/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAItD,OAAO,KAAK,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAS5F,eAAO,MAAM,sBAAsB,OAAQ,CAAC;AAM5C,wBAAsB,KAAK,CACzB,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,qBAAqB,CAAC,CAsLhC"}
|
package/dist/tip.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { c as p, V as b, B as N } from "./chunks/errors-B-Qv_azy.js";
|
|
2
|
+
const M = /* @__PURE__ */ new Map([
|
|
3
|
+
["viceme:ready", /* @__PURE__ */ new Set(["clientKey", "workKey", "capabilities", "version"])],
|
|
4
|
+
["viceme:capability-ready", /* @__PURE__ */ new Set(["clientKey", "instanceKey", "capability", "version"])],
|
|
5
|
+
[
|
|
6
|
+
"viceme:error",
|
|
7
|
+
/* @__PURE__ */ new Set(["clientKey", "instanceKey", "capability", "code", "retryable", "requestId"])
|
|
8
|
+
],
|
|
9
|
+
["viceme:destroyed", /* @__PURE__ */ new Set(["clientKey", "instanceKey", "capability"])],
|
|
10
|
+
["viceme:widget-close", /* @__PURE__ */ new Set(["workId"])],
|
|
11
|
+
["viceme:tip-paid", /* @__PURE__ */ new Set(["workId", "orderNo", "status", "amountCents"])]
|
|
12
|
+
]);
|
|
13
|
+
function D(i, t) {
|
|
14
|
+
const a = M.get(i), n = {};
|
|
15
|
+
for (const [s, o] of Object.entries(t))
|
|
16
|
+
a.has(s) && o !== void 0 && (n[s] = o);
|
|
17
|
+
return n;
|
|
18
|
+
}
|
|
19
|
+
function k(i, t, a) {
|
|
20
|
+
const n = new CustomEvent(t, {
|
|
21
|
+
detail: D(t, a),
|
|
22
|
+
bubbles: !0,
|
|
23
|
+
composed: !0,
|
|
24
|
+
cancelable: !1
|
|
25
|
+
});
|
|
26
|
+
i.dispatchEvent(n);
|
|
27
|
+
}
|
|
28
|
+
const R = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, S = /^VT\d{14}[0-9a-f]{12}$/, C = 100, O = 2e4, K = 2048, P = 8e3;
|
|
29
|
+
function x(i) {
|
|
30
|
+
return typeof i == "object" && i !== null;
|
|
31
|
+
}
|
|
32
|
+
async function U(i, t) {
|
|
33
|
+
if (t.signal?.aborted) throw p();
|
|
34
|
+
if (await i.ready(), t.signal?.aborted) throw p();
|
|
35
|
+
if (!i.hasCapability("tip"))
|
|
36
|
+
throw new b({
|
|
37
|
+
code: "CAPABILITY_DISABLED",
|
|
38
|
+
message: "Tip is not available in this SDK build.",
|
|
39
|
+
retryable: !1,
|
|
40
|
+
capability: "tip"
|
|
41
|
+
});
|
|
42
|
+
const a = t.target.ownerDocument, n = a.defaultView;
|
|
43
|
+
if (!n)
|
|
44
|
+
throw new b({
|
|
45
|
+
code: "CONFIG_INVALID",
|
|
46
|
+
message: "Tip requires a browser document.",
|
|
47
|
+
retryable: !1,
|
|
48
|
+
capability: "tip"
|
|
49
|
+
});
|
|
50
|
+
const s = N[i.region], o = t.theme === "auto" ? n.matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
51
|
+
let l = t.theme === "auto" ? o?.matches ? "dark" : "light" : t.theme, y = !1, m, u;
|
|
52
|
+
const c = a.createElement("div");
|
|
53
|
+
c.dataset.vicemeTip = "mounted", c.style.all = "initial", c.style.display = "block", c.style.width = "100%", c.style.maxWidth = "100%", c.style.contain = "layout style";
|
|
54
|
+
const L = c.attachShadow({ mode: "open" }), r = a.createElement("iframe"), h = new URL(`/widget/tip/${encodeURIComponent(i.workKey)}`, s);
|
|
55
|
+
h.searchParams.set("appearance", l), r.title = "ViceMe Tip", r.src = h.toString(), r.loading = "eager", r.referrerPolicy = "strict-origin", r.setAttribute(
|
|
56
|
+
"sandbox",
|
|
57
|
+
"allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts"
|
|
58
|
+
), r.setAttribute("allow", "payment"), r.style.boxSizing = "border-box", r.style.display = "block", r.style.width = "100%", r.style.height = "0px", r.style.margin = "0", r.style.border = "0", r.style.background = "transparent", r.style.colorScheme = l, r.style.pointerEvents = "none", L.append(r);
|
|
59
|
+
let v, I;
|
|
60
|
+
const _ = new Promise((d, e) => {
|
|
61
|
+
v = d, I = e, m = n.setTimeout(() => {
|
|
62
|
+
e(
|
|
63
|
+
new b({
|
|
64
|
+
code: "INTERNAL_ERROR",
|
|
65
|
+
message: "Hosted Tip widget did not become ready in time.",
|
|
66
|
+
retryable: !0,
|
|
67
|
+
capability: "tip"
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
}, P);
|
|
71
|
+
}), E = (d) => {
|
|
72
|
+
if (d.origin !== s || d.source !== r.contentWindow) return;
|
|
73
|
+
const e = d.data;
|
|
74
|
+
if (!(!x(e) || typeof e.type != "string")) {
|
|
75
|
+
if (e.type === "viceme:widget-resize") {
|
|
76
|
+
if (typeof e.workId != "string" || !R.test(e.workId) || typeof e.height != "number" || !Number.isInteger(e.height) || e.height < 1 || e.height > K || u !== void 0 && e.workId !== u)
|
|
77
|
+
return;
|
|
78
|
+
r.style.height = `${e.height}px`, u === void 0 && (u = e.workId, r.style.pointerEvents = "auto", m !== void 0 && (n.clearTimeout(m), m = void 0), v?.());
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (!(typeof e.workId != "string" || e.workId !== u)) {
|
|
82
|
+
if (e.type === "viceme:widget-close") {
|
|
83
|
+
k(t.target, "viceme:widget-close", { workId: e.workId });
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
e.type === "viceme:tip-paid" && typeof e.orderNo == "string" && S.test(e.orderNo) && e.status === "PAID" && typeof e.amountCents == "number" && Number.isInteger(e.amountCents) && e.amountCents >= C && e.amountCents <= O && k(t.target, "viceme:tip-paid", {
|
|
87
|
+
workId: e.workId,
|
|
88
|
+
orderNo: e.orderNo,
|
|
89
|
+
status: "PAID",
|
|
90
|
+
amountCents: e.amountCents
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, g = (d) => {
|
|
95
|
+
l = d.matches ? "dark" : "light", r.style.colorScheme = l, r.contentWindow?.postMessage(
|
|
96
|
+
{ type: "viceme:widget-appearance", appearance: l },
|
|
97
|
+
s
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
let w;
|
|
101
|
+
const T = () => {
|
|
102
|
+
I?.(p()), f();
|
|
103
|
+
}, f = () => {
|
|
104
|
+
y || (y = !0, m !== void 0 && n.clearTimeout(m), n.removeEventListener("message", E), w?.(), t.signal?.removeEventListener("abort", T), c.remove());
|
|
105
|
+
};
|
|
106
|
+
try {
|
|
107
|
+
if (n.addEventListener("message", E), o && (typeof o.addEventListener == "function" ? (o.addEventListener("change", g), w = () => o.removeEventListener("change", g)) : (o.addListener(g), w = () => o.removeListener(g))), t.signal?.addEventListener("abort", T, { once: !0 }), t.signal?.aborted) throw p();
|
|
108
|
+
t.target.appendChild(c), await _;
|
|
109
|
+
} catch (d) {
|
|
110
|
+
throw f(), d;
|
|
111
|
+
}
|
|
112
|
+
return { capability: "tip", destroy: f };
|
|
113
|
+
}
|
|
114
|
+
const A = /* @__PURE__ */ new WeakMap();
|
|
115
|
+
function V(i, t) {
|
|
116
|
+
let a = A.get(i);
|
|
117
|
+
a || (a = /* @__PURE__ */ new WeakMap(), A.set(i, a));
|
|
118
|
+
const n = a.get(t.target);
|
|
119
|
+
if (n) return n;
|
|
120
|
+
const s = U(i, t).then((o) => {
|
|
121
|
+
let l = !1;
|
|
122
|
+
const y = {
|
|
123
|
+
capability: "tip",
|
|
124
|
+
destroy() {
|
|
125
|
+
l || (l = !0, t.signal?.removeEventListener("abort", y.destroy), a.get(t.target) === s && a.delete(t.target), o.destroy());
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return t.signal?.addEventListener("abort", y.destroy, { once: !0 }), t.signal?.aborted && y.destroy(), y;
|
|
129
|
+
}).catch((o) => {
|
|
130
|
+
throw a.get(t.target) === s && a.delete(t.target), o;
|
|
131
|
+
});
|
|
132
|
+
return a.set(t.target, s), s;
|
|
133
|
+
}
|
|
134
|
+
export {
|
|
135
|
+
V as mountTip
|
|
136
|
+
};
|
|
137
|
+
//# sourceMappingURL=tip.js.map
|
package/dist/tip.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tip.js","sources":["../src/browser-events.ts","../src/tip/mount.ts","../src/tip/index.ts"],"sourcesContent":["/** Stable, allowlisted `viceme:*` DOM events shared by hosted capabilities. */\n\nimport type { ViceMeErrorCode } from './core/errors.ts';\n\nexport interface VicemeReadyDetail {\n clientKey: string;\n workKey: string;\n capabilities: string[];\n version: string;\n}\n\nexport interface VicemeCapabilityReadyDetail {\n clientKey: string;\n instanceKey: string;\n capability: string;\n version: string;\n}\n\nexport interface VicemeErrorDetail {\n clientKey?: string;\n instanceKey?: string;\n capability?: string;\n code: ViceMeErrorCode;\n retryable: boolean;\n requestId?: string;\n}\n\nexport interface VicemeDestroyedDetail {\n clientKey: string;\n instanceKey: string;\n capability: string;\n}\n\nexport interface VicemeWidgetCloseDetail {\n workId: string;\n}\n\nexport interface VicemeTipPaidDetail {\n workId: string;\n orderNo: string;\n status: 'PAID';\n amountCents: number;\n}\n\nexport type VicemeEventType =\n | 'viceme:ready'\n | 'viceme:capability-ready'\n | 'viceme:error'\n | 'viceme:destroyed'\n | 'viceme:widget-close'\n | 'viceme:tip-paid';\n\nexport type VicemeEventDetailMap = {\n 'viceme:ready': VicemeReadyDetail;\n 'viceme:capability-ready': VicemeCapabilityReadyDetail;\n 'viceme:error': VicemeErrorDetail;\n 'viceme:destroyed': VicemeDestroyedDetail;\n 'viceme:widget-close': VicemeWidgetCloseDetail;\n 'viceme:tip-paid': VicemeTipPaidDetail;\n};\n\nconst ALLOWED_KEYS: ReadonlyMap<VicemeEventType, ReadonlySet<string>> = new Map([\n ['viceme:ready', new Set(['clientKey', 'workKey', 'capabilities', 'version'])],\n ['viceme:capability-ready', new Set(['clientKey', 'instanceKey', 'capability', 'version'])],\n [\n 'viceme:error',\n new Set(['clientKey', 'instanceKey', 'capability', 'code', 'retryable', 'requestId']),\n ],\n ['viceme:destroyed', new Set(['clientKey', 'instanceKey', 'capability'])],\n ['viceme:widget-close', new Set(['workId'])],\n ['viceme:tip-paid', new Set(['workId', 'orderNo', 'status', 'amountCents'])],\n]);\n\n/** Strip anything outside the documented allowlist before dispatch. */\nexport function sanitizeDetail(\n type: VicemeEventType,\n detail: VicemeEventDetailMap[VicemeEventType],\n): VicemeEventDetailMap[VicemeEventType] {\n const allowed = ALLOWED_KEYS.get(type)!;\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(detail)) {\n if (allowed.has(key) && value !== undefined) result[key] = value;\n }\n return result as unknown as VicemeEventDetailMap[VicemeEventType];\n}\n\nexport function dispatchViceMeEvent<K extends VicemeEventType>(\n target: EventTarget,\n type: K,\n detail: VicemeEventDetailMap[K],\n): void {\n const event = new CustomEvent(type, {\n detail: sanitizeDetail(type, detail),\n bubbles: true,\n composed: true,\n cancelable: false,\n });\n target.dispatchEvent(event);\n}\n","import type { ViceMeClient } from '../core/client.ts';\nimport { BUILD_WIDGET_ORIGINS } from '../core/build-endpoints.ts';\nimport { clientDestroyed, ViceMeError } from '../core/errors.ts';\nimport { dispatchViceMeEvent } from '../browser-events.ts';\nimport type { CapabilityMountHandle, CapabilityMountOptions } from '../capability-mount.ts';\n\ntype WidgetAppearance = 'light' | 'dark';\n\nconst UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;\nconst TIP_ORDER_NO_PATTERN = /^VT\\d{14}[0-9a-f]{12}$/;\nconst TIP_AMOUNT_MIN = 100;\nconst TIP_AMOUNT_MAX = 20_000;\nconst WIDGET_HEIGHT_MAX = 2_048;\nexport const FRAME_READY_TIMEOUT_MS = 8_000;\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nexport async function mount(\n client: ViceMeClient,\n options: CapabilityMountOptions,\n): Promise<CapabilityMountHandle> {\n if (options.signal?.aborted) throw clientDestroyed();\n await client.ready();\n if (options.signal?.aborted) throw clientDestroyed();\n if (!client.hasCapability('tip')) {\n throw new ViceMeError({\n code: 'CAPABILITY_DISABLED',\n message: 'Tip is not available in this SDK build.',\n retryable: false,\n capability: 'tip',\n });\n }\n\n const documentObject = options.target.ownerDocument;\n const windowObject = documentObject.defaultView;\n if (!windowObject) {\n throw new ViceMeError({\n code: 'CONFIG_INVALID',\n message: 'Tip requires a browser document.',\n retryable: false,\n capability: 'tip',\n });\n }\n\n const widgetOrigin = BUILD_WIDGET_ORIGINS[client.region];\n const mediaQuery =\n options.theme === 'auto' ? windowObject.matchMedia('(prefers-color-scheme: dark)') : undefined;\n let appearance: WidgetAppearance =\n options.theme === 'auto' ? (mediaQuery?.matches ? 'dark' : 'light') : options.theme;\n let destroyed = false;\n let readyTimer: number | undefined;\n let boundWorkId: string | undefined;\n\n const portal = documentObject.createElement('div');\n portal.dataset.vicemeTip = 'mounted';\n portal.style.all = 'initial';\n portal.style.display = 'block';\n portal.style.width = '100%';\n portal.style.maxWidth = '100%';\n portal.style.contain = 'layout style';\n\n const shadow = portal.attachShadow({ mode: 'open' });\n const frame = documentObject.createElement('iframe');\n const frameUrl = new URL(`/widget/tip/${encodeURIComponent(client.workKey)}`, widgetOrigin);\n frameUrl.searchParams.set('appearance', appearance);\n frame.title = 'ViceMe Tip';\n frame.src = frameUrl.toString();\n frame.loading = 'eager';\n frame.referrerPolicy = 'strict-origin';\n frame.setAttribute(\n 'sandbox',\n 'allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts',\n );\n frame.setAttribute('allow', 'payment');\n frame.style.boxSizing = 'border-box';\n frame.style.display = 'block';\n frame.style.width = '100%';\n frame.style.height = '0px';\n frame.style.margin = '0';\n frame.style.border = '0';\n frame.style.background = 'transparent';\n frame.style.colorScheme = appearance;\n frame.style.pointerEvents = 'none';\n shadow.append(frame);\n\n let resolveReady: (() => void) | undefined;\n let rejectReady: ((error: ViceMeError) => void) | undefined;\n const readiness = new Promise<void>((resolve, reject) => {\n resolveReady = resolve;\n rejectReady = reject;\n readyTimer = windowObject.setTimeout(() => {\n reject(\n new ViceMeError({\n code: 'INTERNAL_ERROR',\n message: 'Hosted Tip widget did not become ready in time.',\n retryable: true,\n capability: 'tip',\n }),\n );\n }, FRAME_READY_TIMEOUT_MS);\n });\n\n const onMessage = (event: MessageEvent<unknown>): void => {\n if (event.origin !== widgetOrigin || event.source !== frame.contentWindow) return;\n const message = event.data;\n if (!isRecord(message) || typeof message.type !== 'string') return;\n\n if (message.type === 'viceme:widget-resize') {\n if (\n typeof message.workId !== 'string' ||\n !UUID_PATTERN.test(message.workId) ||\n typeof message.height !== 'number' ||\n !Number.isInteger(message.height) ||\n message.height < 1 ||\n message.height > WIDGET_HEIGHT_MAX ||\n (boundWorkId !== undefined && message.workId !== boundWorkId)\n ) {\n return;\n }\n frame.style.height = `${message.height}px`;\n if (boundWorkId === undefined) {\n boundWorkId = message.workId;\n frame.style.pointerEvents = 'auto';\n if (readyTimer !== undefined) {\n windowObject.clearTimeout(readyTimer);\n readyTimer = undefined;\n }\n resolveReady?.();\n }\n return;\n }\n\n if (typeof message.workId !== 'string' || message.workId !== boundWorkId) return;\n if (message.type === 'viceme:widget-close') {\n dispatchViceMeEvent(options.target, 'viceme:widget-close', { workId: message.workId });\n return;\n }\n if (\n message.type === 'viceme:tip-paid' &&\n typeof message.orderNo === 'string' &&\n TIP_ORDER_NO_PATTERN.test(message.orderNo) &&\n message.status === 'PAID' &&\n typeof message.amountCents === 'number' &&\n Number.isInteger(message.amountCents) &&\n message.amountCents >= TIP_AMOUNT_MIN &&\n message.amountCents <= TIP_AMOUNT_MAX\n ) {\n dispatchViceMeEvent(options.target, 'viceme:tip-paid', {\n workId: message.workId,\n orderNo: message.orderNo,\n status: 'PAID',\n amountCents: message.amountCents,\n });\n }\n };\n\n const onAppearanceChange = (event: MediaQueryListEvent): void => {\n appearance = event.matches ? 'dark' : 'light';\n frame.style.colorScheme = appearance;\n frame.contentWindow?.postMessage(\n { type: 'viceme:widget-appearance', appearance },\n widgetOrigin,\n );\n };\n\n let removeAppearanceListener: (() => void) | undefined;\n const onAbort = (): void => {\n rejectReady?.(clientDestroyed());\n cleanup();\n };\n const cleanup = (): void => {\n if (destroyed) return;\n destroyed = true;\n if (readyTimer !== undefined) windowObject.clearTimeout(readyTimer);\n windowObject.removeEventListener('message', onMessage);\n removeAppearanceListener?.();\n options.signal?.removeEventListener('abort', onAbort);\n portal.remove();\n };\n\n try {\n windowObject.addEventListener('message', onMessage);\n if (mediaQuery) {\n if (typeof mediaQuery.addEventListener === 'function') {\n mediaQuery.addEventListener('change', onAppearanceChange);\n removeAppearanceListener = () =>\n mediaQuery.removeEventListener('change', onAppearanceChange);\n } else {\n mediaQuery.addListener(onAppearanceChange);\n removeAppearanceListener = () => mediaQuery.removeListener(onAppearanceChange);\n }\n }\n options.signal?.addEventListener('abort', onAbort, { once: true });\n if (options.signal?.aborted) throw clientDestroyed();\n options.target.appendChild(portal);\n await readiness;\n } catch (error) {\n cleanup();\n throw error;\n }\n\n return { capability: 'tip', destroy: cleanup };\n}\n","import type { ViceMeClient } from '../core/client.ts';\nimport { mount } from './mount.ts';\n\nexport interface TipMountOptions {\n target: Element;\n theme: 'light' | 'dark' | 'auto';\n signal?: AbortSignal;\n}\n\nexport interface TipMountHandle {\n readonly capability: 'tip';\n destroy(): void;\n}\n\nexport interface TipWidgetCloseDetail {\n workId: string;\n}\n\nexport interface TipPaidDetail {\n workId: string;\n orderNo: string;\n status: 'PAID';\n amountCents: number;\n}\n\nconst mounts = new WeakMap<ViceMeClient, WeakMap<Element, Promise<TipMountHandle>>>();\n\n/** Explicit ESM/npm entry point; the CDN loader calls the same mount function. */\nexport function mountTip(client: ViceMeClient, options: TipMountOptions): Promise<TipMountHandle> {\n let byTarget = mounts.get(client);\n if (!byTarget) {\n byTarget = new WeakMap();\n mounts.set(client, byTarget);\n }\n const existing = byTarget.get(options.target);\n if (existing) return existing;\n\n const pending: Promise<TipMountHandle> = mount(client, options)\n .then((raw) => {\n let destroyed = false;\n const handle: TipMountHandle = {\n capability: 'tip' as const,\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n options.signal?.removeEventListener('abort', handle.destroy);\n if (byTarget.get(options.target) === pending) byTarget.delete(options.target);\n raw.destroy();\n },\n };\n options.signal?.addEventListener('abort', handle.destroy, { once: true });\n if (options.signal?.aborted) handle.destroy();\n return handle;\n })\n .catch((error: unknown) => {\n if (byTarget.get(options.target) === pending) byTarget.delete(options.target);\n throw error;\n });\n byTarget.set(options.target, pending);\n return pending;\n}\n"],"names":["ALLOWED_KEYS","sanitizeDetail","type","detail","allowed","result","key","value","dispatchViceMeEvent","target","event","UUID_PATTERN","TIP_ORDER_NO_PATTERN","TIP_AMOUNT_MIN","TIP_AMOUNT_MAX","WIDGET_HEIGHT_MAX","FRAME_READY_TIMEOUT_MS","isRecord","mount","client","options","clientDestroyed","ViceMeError","documentObject","windowObject","widgetOrigin","BUILD_WIDGET_ORIGINS","mediaQuery","appearance","destroyed","readyTimer","boundWorkId","portal","shadow","frame","frameUrl","resolveReady","rejectReady","readiness","resolve","reject","onMessage","message","onAppearanceChange","removeAppearanceListener","onAbort","cleanup","error","mounts","mountTip","byTarget","existing","pending","raw","handle"],"mappings":";AA6DA,MAAMA,wBAAsE,IAAI;AAAA,EAC9E,CAAC,gBAAgB,oBAAI,IAAI,CAAC,aAAa,WAAW,gBAAgB,SAAS,CAAC,CAAC;AAAA,EAC7E,CAAC,2BAA2B,oBAAI,IAAI,CAAC,aAAa,eAAe,cAAc,SAAS,CAAC,CAAC;AAAA,EAC1F;AAAA,IACE;AAAA,IACA,oBAAI,IAAI,CAAC,aAAa,eAAe,cAAc,QAAQ,aAAa,WAAW,CAAC;AAAA,EAAA;AAAA,EAEtF,CAAC,oBAAoB,oBAAI,IAAI,CAAC,aAAa,eAAe,YAAY,CAAC,CAAC;AAAA,EACxE,CAAC,uBAAuB,oBAAI,IAAI,CAAC,QAAQ,CAAC,CAAC;AAAA,EAC3C,CAAC,mBAAmB,oBAAI,IAAI,CAAC,UAAU,WAAW,UAAU,aAAa,CAAC,CAAC;AAC7E,CAAC;AAGM,SAASC,EACdC,GACAC,GACuC;AACvC,QAAMC,IAAUJ,EAAa,IAAIE,CAAI,GAC/BG,IAAkC,CAAA;AACxC,aAAW,CAACC,GAAKC,CAAK,KAAK,OAAO,QAAQJ,CAAM;AAC9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AMyB,IAAyB;AAAA,MAC7B,YAAY;AAAA,MACZ,UAAgB;AACd,QAAIzB,MACJA,IAAY,IACZT,EAAQ,QAAQ,oBAAoB,SAASkC,EAAO,OAAO,GACvDJ,EAAS,IAAI9B,EAAQ,MAAM,MAAMgC,KAASF,EAAS,OAAO9B,EAAQ,MAAM,GAC5EiC,EAAI,QAAA;AAAA,MACN;AAAA,IAAA;AAEF,WAAAjC,EAAQ,QAAQ,iBAAiB,SAASkC,EAAO,SAAS,EAAE,MAAM,IAAM,GACpElC,EAAQ,QAAQ,WAASkC,EAAO,QAAA,GAC7BA;AAAA,EACT,CAAC,EACA,MAAM,CAACP,MAAmB;AACzB,UAAIG,EAAS,IAAI9B,EAAQ,MAAM,MAAMgC,KAASF,EAAS,OAAO9B,EAAQ,MAAM,GACtE2B;AAAA,EACR,CAAC;AACH,SAAAG,EAAS,IAAI9B,EAAQ,QAAQgC,CAAO,GAC7BA;AACT;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP transport for the public API.
|
|
3
|
+
*
|
|
4
|
+
* Responsibilities: request execution with timeout, abort, client request ids,
|
|
5
|
+
* and normalization of every failure into the public `ViceMeError` model.
|
|
6
|
+
* Capabilities and the loader never build their own `fetch` calls — they go
|
|
7
|
+
* through a Transport so tests can swap in `createMemoryTransport`.
|
|
8
|
+
*/
|
|
9
|
+
export interface TransportRequest {
|
|
10
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
11
|
+
/** Absolute path under the public API base. */
|
|
12
|
+
path: string;
|
|
13
|
+
/** JSON-serializable request body. */
|
|
14
|
+
body?: unknown;
|
|
15
|
+
/** Work-session token. It is never persisted by the transport. */
|
|
16
|
+
authorization?: string;
|
|
17
|
+
/** Optional memory-only signed-in widget token. */
|
|
18
|
+
userAuthorization?: string;
|
|
19
|
+
signal?: AbortSignal;
|
|
20
|
+
/** Per-request timeout; defaults to the transport default. */
|
|
21
|
+
timeoutMs?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface TransportResponse {
|
|
24
|
+
status: number;
|
|
25
|
+
body?: unknown;
|
|
26
|
+
/** Echoed server request id, when provided. */
|
|
27
|
+
requestId?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface Transport {
|
|
30
|
+
request(request: TransportRequest): Promise<TransportResponse>;
|
|
31
|
+
}
|
|
32
|
+
export interface FetchTransportOptions {
|
|
33
|
+
apiBaseUrl: string;
|
|
34
|
+
/** Injectable for tests; defaults to global `fetch`. */
|
|
35
|
+
fetchImpl?: typeof fetch;
|
|
36
|
+
defaultTimeoutMs?: number;
|
|
37
|
+
/** Injectable id generator (default: `crypto.randomUUID`). */
|
|
38
|
+
generateRequestId?: () => string;
|
|
39
|
+
}
|
|
40
|
+
export declare class FetchTransport implements Transport {
|
|
41
|
+
#private;
|
|
42
|
+
constructor(options: FetchTransportOptions);
|
|
43
|
+
request(request: TransportRequest): Promise<TransportResponse>;
|
|
44
|
+
}
|
|
45
|
+
export declare function createFetchTransport(options: FetchTransportOptions): Transport;
|
|
46
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/transport/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;IAC1C,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,kEAAkE;IAClE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mDAAmD;IACnD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAChE;AAED,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,wDAAwD;IACxD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,MAAM,MAAM,CAAC;CAClC;AAqED,qBAAa,cAAe,YAAW,SAAS;;gBAMlC,OAAO,EAAE,qBAAqB;IAOpC,OAAO,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CA0GrE;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,SAAS,CAE9E"}
|
package/dist/version.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Kept in sync with `packages/sdk/package.json#version`; a unit test enforces
|
|
5
5
|
* the match so the loader, release manifest, and npm metadata can never drift.
|
|
6
6
|
*/
|
|
7
|
-
export declare const SDK_VERSION = "0.
|
|
7
|
+
export declare const SDK_VERSION = "0.4.0";
|
|
8
8
|
/** Public API major carried by this build (loader namespace `v1`). */
|
|
9
9
|
export declare const API_MAJOR = 1;
|
|
10
10
|
//# sourceMappingURL=version.d.ts.map
|