@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
package/dist/index.js
CHANGED
|
@@ -1,111 +1,130 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { V as n } from "./chunks/errors-B-Qv_azy.js";
|
|
2
|
+
import { i as L } from "./chunks/errors-B-Qv_azy.js";
|
|
3
|
+
import { v as A, V as b, r as h } from "./chunks/client-Cbldd7F2.js";
|
|
4
|
+
import { A as S, S as V } from "./chunks/version-C8DeBm39.js";
|
|
5
|
+
const m = 1e4, p = /* @__PURE__ */ new Map([
|
|
6
|
+
[400, "CONFIG_INVALID"],
|
|
7
|
+
[401, "SESSION_EXPIRED"],
|
|
8
|
+
[403, "CAPABILITY_DISABLED"],
|
|
9
|
+
[404, "WORK_NOT_FOUND"],
|
|
10
|
+
[409, "CONFIG_INVALID"],
|
|
11
|
+
[422, "CONFIG_INVALID"],
|
|
12
|
+
[429, "RATE_LIMITED"]
|
|
13
|
+
]), T = /* @__PURE__ */ new Set([
|
|
14
|
+
"CONFIG_INVALID",
|
|
15
|
+
"WORK_NOT_FOUND",
|
|
16
|
+
"CAPABILITY_DISABLED",
|
|
17
|
+
"SESSION_EXPIRED",
|
|
18
|
+
"AUTH_REQUIRED",
|
|
19
|
+
"AUTH_CANCELLED",
|
|
20
|
+
"RETURN_URL_NOT_ALLOWED",
|
|
21
|
+
"RATE_LIMITED",
|
|
22
|
+
"NETWORK_TIMEOUT",
|
|
23
|
+
"CHECKOUT_UNAVAILABLE",
|
|
24
|
+
"INTERNAL_ERROR"
|
|
25
|
+
]);
|
|
26
|
+
function O(s) {
|
|
27
|
+
if (typeof s != "object" || s === null) return {};
|
|
28
|
+
const e = s, t = typeof e.error == "object" && e.error !== null ? e.error : e, r = {};
|
|
29
|
+
return typeof t.code == "string" && T.has(t.code) && (r.code = t.code), typeof t.message == "string" && (r.message = t.message.slice(0, 200)), typeof t.retryable == "boolean" && (r.retryable = t.retryable), typeof t.requestId == "string" && (r.requestId = t.requestId), r;
|
|
6
30
|
}
|
|
7
|
-
function
|
|
8
|
-
return typeof
|
|
31
|
+
function _() {
|
|
32
|
+
return typeof crypto < "u" && typeof crypto.randomUUID == "function" ? crypto.randomUUID() : `req-${Math.random().toString(36).slice(2)}`;
|
|
9
33
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (!c(e.workKey))
|
|
18
|
-
throw i('Configuration field "workKey" must be a public work key ("wrk_…").');
|
|
19
|
-
if (!l(e.region))
|
|
20
|
-
throw i('Configuration field "region" must be "cn" or "global".');
|
|
21
|
-
return {
|
|
22
|
-
workKey: e.workKey,
|
|
23
|
-
region: e.region
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
const h = {
|
|
27
|
-
CREATED: ["READY", "DESTROYED"],
|
|
28
|
-
READY: ["DEGRADED", "DESTROYED"],
|
|
29
|
-
DEGRADED: ["DESTROYED"],
|
|
30
|
-
DESTROYED: []
|
|
31
|
-
};
|
|
32
|
-
class E {
|
|
33
|
-
#e = "CREATED";
|
|
34
|
-
#t = /* @__PURE__ */ new Set();
|
|
35
|
-
get state() {
|
|
36
|
-
return this.#e;
|
|
37
|
-
}
|
|
38
|
-
get destroyed() {
|
|
39
|
-
return this.#e === "DESTROYED";
|
|
34
|
+
class R {
|
|
35
|
+
#e;
|
|
36
|
+
#t;
|
|
37
|
+
#r;
|
|
38
|
+
#o;
|
|
39
|
+
constructor(e) {
|
|
40
|
+
this.#e = e.apiBaseUrl.replace(/\/+$/, ""), this.#t = e.fetchImpl ?? globalThis.fetch.bind(globalThis), this.#r = e.defaultTimeoutMs ?? m, this.#o = e.generateRequestId ?? _;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
if (e
|
|
43
|
-
|
|
42
|
+
async request(e) {
|
|
43
|
+
if (e.signal?.aborted)
|
|
44
|
+
throw this.#s(e.signal);
|
|
45
|
+
const t = e.timeoutMs ?? this.#r, r = new AbortController();
|
|
46
|
+
let c = !1;
|
|
47
|
+
const E = setTimeout(() => {
|
|
48
|
+
c = !0, r.abort(new I());
|
|
49
|
+
}, t), d = () => r.abort(new I(!1));
|
|
50
|
+
e.signal?.addEventListener("abort", d, { once: !0 });
|
|
51
|
+
const l = this.#o();
|
|
52
|
+
try {
|
|
53
|
+
const o = await this.#t(`${this.#e}${e.path}`, {
|
|
54
|
+
method: e.method,
|
|
55
|
+
// Public API is CORS-only; credentials must stay off so Shop session
|
|
56
|
+
// cookies can never attach to public SDK requests.
|
|
57
|
+
credentials: "omit",
|
|
58
|
+
mode: "cors",
|
|
59
|
+
headers: {
|
|
60
|
+
"content-type": "application/json",
|
|
61
|
+
"x-client-request-id": l,
|
|
62
|
+
...e.authorization !== void 0 ? { authorization: `Bearer ${e.authorization}` } : {},
|
|
63
|
+
...e.userAuthorization !== void 0 ? { "x-viceme-user-token": e.userAuthorization } : {}
|
|
64
|
+
},
|
|
65
|
+
body: e.body !== void 0 ? JSON.stringify(e.body) : void 0,
|
|
66
|
+
signal: r.signal
|
|
67
|
+
});
|
|
68
|
+
let a;
|
|
69
|
+
try {
|
|
70
|
+
a = await o.json();
|
|
71
|
+
} catch (i) {
|
|
72
|
+
if (e.signal?.aborted || c)
|
|
73
|
+
throw i;
|
|
74
|
+
a = void 0;
|
|
75
|
+
}
|
|
76
|
+
const u = o.headers.get("x-request-id") ?? void 0;
|
|
77
|
+
if (!o.ok) {
|
|
78
|
+
const i = O(a), f = i.code ?? p.get(o.status) ?? "INTERNAL_ERROR";
|
|
44
79
|
throw new n({
|
|
45
|
-
code:
|
|
46
|
-
message:
|
|
47
|
-
retryable:
|
|
80
|
+
code: f,
|
|
81
|
+
message: i.message ?? "Public API request failed.",
|
|
82
|
+
retryable: i.retryable,
|
|
83
|
+
requestId: i.requestId ?? u
|
|
48
84
|
});
|
|
49
|
-
|
|
50
|
-
|
|
85
|
+
}
|
|
86
|
+
return { status: o.status, body: a, requestId: u };
|
|
87
|
+
} catch (o) {
|
|
88
|
+
throw e.signal?.aborted ? this.#s(e.signal) : c ? new n({
|
|
89
|
+
code: "NETWORK_TIMEOUT",
|
|
90
|
+
message: "Public API request timed out.",
|
|
91
|
+
retryable: !0,
|
|
92
|
+
requestId: l
|
|
93
|
+
}) : o instanceof n ? o : o instanceof DOMException && o.name === "AbortError" ? new DOMException("ViceMe request aborted by caller.", "AbortError") : new n({
|
|
94
|
+
code: "INTERNAL_ERROR",
|
|
95
|
+
message: "Public API request failed.",
|
|
96
|
+
retryable: !0,
|
|
97
|
+
requestId: l
|
|
98
|
+
});
|
|
99
|
+
} finally {
|
|
100
|
+
clearTimeout(E), e.signal?.removeEventListener("abort", d);
|
|
51
101
|
}
|
|
52
102
|
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
subscribe(e) {
|
|
58
|
-
return this.#t.add(e), () => {
|
|
59
|
-
this.#t.delete(e);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
clearListeners() {
|
|
63
|
-
this.#t.clear();
|
|
103
|
+
/** Caller-abort error that preserves the caller's own abort reason. */
|
|
104
|
+
#s(e) {
|
|
105
|
+
return e.reason instanceof Error ? e.reason : new DOMException("ViceMe request aborted by caller.", "AbortError");
|
|
64
106
|
}
|
|
65
107
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.#t = e;
|
|
73
|
-
}
|
|
74
|
-
get workKey() {
|
|
75
|
-
return this.#t.workKey;
|
|
76
|
-
}
|
|
77
|
-
get region() {
|
|
78
|
-
return this.#t.region;
|
|
79
|
-
}
|
|
80
|
-
get state() {
|
|
81
|
-
return this.#e.state;
|
|
82
|
-
}
|
|
83
|
-
ready() {
|
|
84
|
-
return this.#e.destroyed ? Promise.reject(o()) : (this.#i || (this.#e.transition("READY"), this.#i = Promise.resolve()), this.#i);
|
|
85
|
-
}
|
|
86
|
-
hasCapability(e) {
|
|
87
|
-
return !this.#e.destroyed && e === "danmaku";
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Internal: mark one capability unavailable without taking down the client
|
|
91
|
-
* (loader uses this when a feature chunk fails after the core is READY).
|
|
92
|
-
*/
|
|
93
|
-
[D]() {
|
|
94
|
-
this.#e.state === "READY" && this.#e.transition("DEGRADED");
|
|
95
|
-
}
|
|
96
|
-
destroy() {
|
|
97
|
-
this.#e.destroyed || (this.#e.transition("DESTROYED"), this.#e.clearListeners(), this.#i = void 0);
|
|
108
|
+
function N(s) {
|
|
109
|
+
return new R(s);
|
|
110
|
+
}
|
|
111
|
+
class I extends DOMException {
|
|
112
|
+
constructor(e = !0) {
|
|
113
|
+
super(e ? "ViceMe request timed out." : "ViceMe request aborted.", "AbortError");
|
|
98
114
|
}
|
|
99
115
|
}
|
|
100
|
-
function
|
|
101
|
-
const e =
|
|
102
|
-
|
|
116
|
+
function D(s) {
|
|
117
|
+
const e = A(s), t = h(e.region), r = N({
|
|
118
|
+
apiBaseUrl: t
|
|
119
|
+
});
|
|
120
|
+
return new b({ config: e, transport: r });
|
|
103
121
|
}
|
|
104
122
|
export {
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
S as API_MAJOR,
|
|
124
|
+
V as SDK_VERSION,
|
|
107
125
|
n as ViceMeError,
|
|
108
|
-
|
|
109
|
-
|
|
126
|
+
D as createViceMe,
|
|
127
|
+
L as isViceMeError,
|
|
128
|
+
h as resolveApiBaseUrl
|
|
110
129
|
};
|
|
111
130
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/core/config.ts","../src/core/lifecycle.ts","../src/core/client.ts","../src/index.ts"],"sourcesContent":["/**\n * Public client configuration.\n *\n * Production `createViceMe()` accepts exactly `workKey` and `region`.\n * Endpoints, credentials, access policy, and provider state are not client\n * configuration: the hosted Shop runtime owns those concerns.\n */\n\nimport { configInvalid } from './errors.ts';\nexport type ViceMeRegion = 'cn' | 'global';\n\nexport interface ViceMeConfig {\n /** Public opaque work key (`wrk_…`). Locates a Work; it is not a secret. */\n workKey: string;\n /** Selects the hosted Shop region. */\n region: ViceMeRegion;\n}\n\nconst REGIONS: ReadonlySet<string> = new Set(['cn', 'global']);\n\nexport function isValidWorkKey(value: unknown): value is string {\n return typeof value === 'string' && /^wrk_[A-Za-z0-9_-]{4,124}$/.test(value);\n}\n\nexport function isValidRegion(value: unknown): value is ViceMeRegion {\n return typeof value === 'string' && REGIONS.has(value);\n}\n\n/**\n * Validate unknown input as a public client config. Throws a CONFIG_INVALID\n * ViceMeError that never echoes values back beyond the offending field name.\n */\nexport function validatePublicConfig(input: unknown): ViceMeConfig {\n if (typeof input !== 'object' || input === null) {\n throw configInvalid('createViceMe expects a configuration object.');\n }\n const raw = input as Record<string, unknown>;\n\n const known = new Set(['workKey', 'region']);\n for (const key of Object.keys(raw)) {\n if (!known.has(key)) {\n throw configInvalid(`Unknown configuration field \"${key}\".`);\n }\n }\n if (!isValidWorkKey(raw.workKey)) {\n throw configInvalid('Configuration field \"workKey\" must be a public work key (\"wrk_…\").');\n }\n if (!isValidRegion(raw.region)) {\n throw configInvalid('Configuration field \"region\" must be \"cn\" or \"global\".');\n }\n return {\n workKey: raw.workKey,\n region: raw.region,\n };\n}\n","/**\n * Client lifecycle state machine.\n *\n * ```text\n * CREATED -> READY -> DESTROYED\n * READY -> DEGRADED (single capability unavailable; host page keeps working)\n * ```\n *\n * State is exposed read-only; consumers can never assign it directly.\n */\n\nimport { ViceMeError, clientDestroyed } from './errors.ts';\n\nexport type ViceMeClientState = 'CREATED' | 'READY' | 'DEGRADED' | 'DESTROYED';\n\nconst ALLOWED_TRANSITIONS: Readonly<Record<ViceMeClientState, readonly ViceMeClientState[]>> = {\n CREATED: ['READY', 'DESTROYED'],\n READY: ['DEGRADED', 'DESTROYED'],\n DEGRADED: ['DESTROYED'],\n DESTROYED: [],\n};\n\nexport type LifecycleListener = (state: ViceMeClientState) => void;\n\nexport class Lifecycle {\n #state: ViceMeClientState = 'CREATED';\n #listeners = new Set<LifecycleListener>();\n\n get state(): ViceMeClientState {\n return this.#state;\n }\n\n get destroyed(): boolean {\n return this.#state === 'DESTROYED';\n }\n\n transition(next: ViceMeClientState): void {\n if (next === this.#state) return;\n if (!ALLOWED_TRANSITIONS[this.#state]!.includes(next)) {\n throw new ViceMeError({\n code: 'INTERNAL_ERROR',\n message: `Illegal lifecycle transition ${this.#state} -> ${next}.`,\n retryable: false,\n });\n }\n this.#state = next;\n for (const listener of this.#listeners) listener(next);\n }\n\n /** Any operation on a destroyed client must fail closed with this guard. */\n assertAlive(): void {\n if (this.destroyed) throw clientDestroyed();\n }\n\n subscribe(listener: LifecycleListener): () => void {\n this.#listeners.add(listener);\n return () => {\n this.#listeners.delete(listener);\n };\n }\n\n clearListeners(): void {\n this.#listeners.clear();\n }\n}\n","/**\n * Local ViceMe client for the public hosted danmaku capability.\n *\n * Initialization performs no network request. The static loader owns release\n * manifest/chunk loading, while the hosted iframe owns Shop API calls.\n */\n\nimport { clientDestroyed } from './errors.ts';\nimport { Lifecycle, type ViceMeClientState } from './lifecycle.ts';\nimport type { ViceMeConfig, ViceMeRegion } from './config.ts';\n\nconst MARK_DEGRADED = Symbol('ViceMeClient.markDegraded');\n\ninterface DegradableViceMeClient {\n [MARK_DEGRADED](): void;\n}\n\nexport interface ViceMeClient {\n readonly workKey: string;\n readonly region: ViceMeRegion;\n readonly state: ViceMeClientState;\n ready(): Promise<void>;\n hasCapability(name: string): boolean;\n destroy(): void;\n}\n\nexport interface ViceMeMountedInstance {\n readonly instanceKey: string;\n readonly capability: string;\n destroy(): void;\n}\n\n/** Internal loader hook; not part of the client object's string-keyed surface. */\nexport function markClientDegraded(client: ViceMeClient): void {\n if (MARK_DEGRADED in client) {\n (client as ViceMeClient & DegradableViceMeClient)[MARK_DEGRADED]();\n }\n}\n\nexport class ViceMeClientImpl implements ViceMeClient {\n readonly #lifecycle = new Lifecycle();\n readonly #config: ViceMeConfig;\n #readyPromise: Promise<void> | undefined;\n\n constructor(config: ViceMeConfig) {\n this.#config = config;\n }\n\n get workKey(): string {\n return this.#config.workKey;\n }\n\n get region(): ViceMeRegion {\n return this.#config.region;\n }\n\n get state(): ViceMeClientState {\n return this.#lifecycle.state;\n }\n\n ready(): Promise<void> {\n if (this.#lifecycle.destroyed) return Promise.reject(clientDestroyed());\n if (!this.#readyPromise) {\n this.#lifecycle.transition('READY');\n this.#readyPromise = Promise.resolve();\n }\n return this.#readyPromise;\n }\n\n hasCapability(name: string): boolean {\n return !this.#lifecycle.destroyed && name === 'danmaku';\n }\n\n /**\n * Internal: mark one capability unavailable without taking down the client\n * (loader uses this when a feature chunk fails after the core is READY).\n */\n [MARK_DEGRADED](): void {\n if (this.#lifecycle.state === 'READY') this.#lifecycle.transition('DEGRADED');\n }\n\n destroy(): void {\n if (this.#lifecycle.destroyed) return;\n this.#lifecycle.transition('DESTROYED');\n this.#lifecycle.clearListeners();\n this.#readyPromise = undefined;\n }\n}\n","/**\n * `@viceme-ai/sdk` public entry.\n *\n * Production consumers get a local public-danmaku client plus public types.\n */\n\nimport { 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 };\nexport type {\n ViceMeClient,\n ViceMeMountedInstance,\n ViceMeConfig,\n ViceMeRegion,\n ViceMeClientState,\n ViceMeErrorCode,\n};\n\n/**\n * Create a local public-danmaku 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 return new ViceMeClientImpl(validated);\n}\n"],"names":["REGIONS","isValidWorkKey","value","isValidRegion","validatePublicConfig","input","configInvalid","raw","known","key","ALLOWED_TRANSITIONS","Lifecycle","#state","#listeners","next","ViceMeError","listener","clientDestroyed","MARK_DEGRADED","ViceMeClientImpl","#lifecycle","#config","#readyPromise","config","name","createViceMe","validated"],"mappings":";;AAkBA,MAAMA,IAA+B,oBAAI,IAAI,CAAC,MAAM,QAAQ,CAAC;AAEtD,SAASC,EAAeC,GAAiC;AAC9D,SAAO,OAAOA,KAAU,YAAY,6BAA6B,KAAKA,CAAK;AAC7E;AAEO,SAASC,EAAcD,GAAuC;AACnE,SAAO,OAAOA,KAAU,YAAYF,EAAQ,IAAIE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|
|
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' | 'PUT' | 'DELETE';\n /** Absolute path under the public API base. */\n path: string;\n /** JSON-serializable request body. */\n body?: unknown;\n /** Work-session token. It is never persisted by the transport. */\n authorization?: string;\n /** Optional memory-only signed-in widget token. */\n userAuthorization?: string;\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, 'CAPABILITY_DISABLED'],\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 'CAPABILITY_DISABLED',\n 'SESSION_EXPIRED',\n 'AUTH_REQUIRED',\n 'AUTH_CANCELLED',\n 'RETURN_URL_NOT_ALLOWED',\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 raw = body as Record<string, unknown>;\n const candidate =\n typeof raw.error === 'object' && raw.error !== null\n ? (raw.error as Record<string, unknown>)\n : raw;\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 ...(request.authorization !== undefined\n ? { authorization: `Bearer ${request.authorization}` }\n : {}),\n ...(request.userAuthorization !== undefined\n ? { 'x-viceme-user-token': request.userAuthorization }\n : {}),\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 `createViceMe` plus public types. Test injection\n * lives under `@viceme-ai/sdk/testing`.\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 type {\n AccessCapability,\n AccessDecision,\n AccessFeaturePresentation,\n AccessPolicyType,\n AccessReason,\n AuthCapability,\n AuthState,\n CheckoutCapability,\n CheckoutOptions,\n CheckoutResult,\n} from './core/capabilities.ts';\nimport type { WorkUser } from './session/session.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 AccessCapability,\n AccessDecision,\n AccessFeaturePresentation,\n AccessPolicyType,\n AccessReason,\n AuthCapability,\n AuthState,\n CheckoutCapability,\n CheckoutOptions,\n CheckoutResult,\n WorkUser,\n};\n\n/**\n * Create a ViceMe client for one Work. Hosted capabilities initialize locally;\n * website access establishes a short-lived Work session only when used.\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 apiBaseUrl = resolveApiBaseUrl(validated.region);\n const transport = createFetchTransport({\n apiBaseUrl,\n });\n return new ViceMeClientImpl({ config: validated, transport });\n}\n"],"names":["DEFAULT_TIMEOUT_MS","STATUS_CODE_MAP","KNOWN_CODES","parseErrorBody","body","raw","candidate","result","defaultRequestId","FetchTransport","#apiBaseUrl","#fetchImpl","#defaultTimeoutMs","#generateRequestId","options","request","#callerAbortError","timeoutMs","controller","timedOut","timer","TimeoutAbort","onOuterAbort","requestId","response","error","serverRequestId","parsed","code","ViceMeError","cause","signal","createFetchTransport","createViceMe","config","validated","validatePublicConfig","apiBaseUrl","resolveApiBaseUrl","transport","ViceMeClientImpl"],"mappings":";;;;AA8CA,MAAMA,IAAqB,KAErBC,wBAA4D,IAAI;AAAA,EACpE,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,iBAAiB;AAAA,EACvB,CAAC,KAAK,qBAAqB;AAAA,EAC3B,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,gBAAgB;AAAA,EACtB,CAAC,KAAK,cAAc;AACtB,CAAC,GAEKC,wBAAuC,IAAI;AAAA,EA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9
9
|
import type { ViceMeRegion } from '../core/config.ts';
|
|
10
10
|
export type ViceMeTheme = 'light' | 'dark' | 'auto';
|
|
11
|
+
export type LoaderFeature = 'danmaku' | 'tip';
|
|
11
12
|
export interface LoaderAttributes {
|
|
12
13
|
workKey: string;
|
|
13
14
|
region: ViceMeRegion;
|
|
14
|
-
/**
|
|
15
|
-
features:
|
|
15
|
+
/** Hosted capabilities mounted by this loader invocation. */
|
|
16
|
+
features: LoaderFeature[];
|
|
16
17
|
/** CSS selector; required whenever features are declared. */
|
|
17
18
|
target?: string;
|
|
18
19
|
theme: ViceMeTheme;
|
|
@@ -1 +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;
|
|
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;AACpD,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,KAAK,CAAC;AAE9C,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,6DAA6D;IAC7D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,WAAW,CAAC;CACpB;AAeD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAiExE"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* 4. Read `manifest.json` from the loader's own directory (exact release
|
|
13
13
|
* version; URLs are never assembled from page parameters).
|
|
14
14
|
* 5. Create the local client embedded in this loader, then load the
|
|
15
|
-
* same-version
|
|
15
|
+
* requested same-version capability chunks declared by the manifest.
|
|
16
16
|
* 6. Mount; handles land in an internal registry.
|
|
17
17
|
* 7. Re-running the same instance key returns the original handle — no
|
|
18
18
|
* duplicate clients, subscriptions, or DOM.
|
|
@@ -1 +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,EAEL,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC3B,MAAM,mBAAmB,CAAC;AAI3B,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;AAED,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;
|
|
1
|
+
{"version":3,"file":"auto-loader.d.ts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
|
|
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;
|
|
1
|
+
export { dispatchViceMeEvent, sanitizeDetail, type VicemeCapabilityReadyDetail, type VicemeDestroyedDetail, type VicemeErrorDetail, type VicemeEventDetailMap, type VicemeEventType, type VicemeReadyDetail, type VicemeTipPaidDetail, type VicemeWidgetCloseDetail, } from '../browser-events.ts';
|
|
45
2
|
//# sourceMappingURL=events.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/loader/events.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/loader/events.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,uBAAuB,GAC7B,MAAM,sBAAsB,CAAC"}
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* `ViceMeMountedInstance` and owns destroy/event deduplication.
|
|
13
13
|
*/
|
|
14
14
|
import type { ViceMeClient } from '../core/client.ts';
|
|
15
|
-
import type { CapabilityMountHandle } from '
|
|
15
|
+
import type { CapabilityMountHandle } from '../capability-mount.ts';
|
|
16
16
|
export interface RegisteredClient {
|
|
17
17
|
clientKey: string;
|
|
18
18
|
client: ViceMeClient;
|
|
19
19
|
ready: Promise<void>;
|
|
20
|
+
pendingMounts: Set<AbortController>;
|
|
20
21
|
}
|
|
21
22
|
export interface RegisteredInstance {
|
|
22
23
|
instanceKey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/loader/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,YAAY,E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EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,qBAAqB,GACzB,kBAAkB;IAwBrB,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAQnE,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,kBAAkB,EAAE;CAG5D"}
|
package/dist/manifest.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.4.0",
|
|
3
3
|
"apiMajor": 1,
|
|
4
4
|
"loader": "viceme.min.js",
|
|
5
5
|
"features": {
|
|
6
|
-
"danmaku": "danmaku.js"
|
|
6
|
+
"danmaku": "danmaku.js",
|
|
7
|
+
"tip": "tip.js"
|
|
7
8
|
},
|
|
8
9
|
"files": {
|
|
9
10
|
"bootstrap.min.js": {
|
|
@@ -12,29 +13,53 @@
|
|
|
12
13
|
"bytes": 964,
|
|
13
14
|
"gzipBytes": 597
|
|
14
15
|
},
|
|
15
|
-
"chunks/
|
|
16
|
-
"sha256": "
|
|
17
|
-
"sri": "sha384-
|
|
18
|
-
"bytes":
|
|
19
|
-
"gzipBytes":
|
|
16
|
+
"chunks/client-Cbldd7F2.js": {
|
|
17
|
+
"sha256": "d3cc3bb1af3d1a932d4a90e03bb9bb87fcc7feccae41e8d847c2aaf554dde5e3",
|
|
18
|
+
"sri": "sha384-3KcJOxpIpTef28FKFuVc94xQnYXf8dMmnlOxp2RU7GJgUT0gfZyHEVp5RPIO2N1I",
|
|
19
|
+
"bytes": 31162,
|
|
20
|
+
"gzipBytes": 8991
|
|
21
|
+
},
|
|
22
|
+
"chunks/errors-B-Qv_azy.js": {
|
|
23
|
+
"sha256": "e8663d662b0a3d483cb46498bd30a8b910658ca4ae707dbd6c0955930bcaef99",
|
|
24
|
+
"sri": "sha384-aD5pgOhBsOrYVQhKM02ig6c9J/Rrw/t0+ZJ5FVamOnI+xuoBx7OhDCqR/FLFNfhN",
|
|
25
|
+
"bytes": 1215,
|
|
26
|
+
"gzipBytes": 616
|
|
27
|
+
},
|
|
28
|
+
"chunks/version-C8DeBm39.js": {
|
|
29
|
+
"sha256": "0c3445a6c890c11d734e4a0eecfd3b68d777f2f830188fffe4087d5f54791d55",
|
|
30
|
+
"sri": "sha384-MWCW0IJOfoua7WCu/Am8r6cCVgwPorO8likP6tc35DDUMjgn/lJkF7lyPHvF5DGU",
|
|
31
|
+
"bytes": 102,
|
|
32
|
+
"gzipBytes": 119
|
|
20
33
|
},
|
|
21
34
|
"danmaku.js": {
|
|
22
|
-
"sha256": "
|
|
23
|
-
"sri": "sha384-
|
|
24
|
-
"bytes":
|
|
25
|
-
"gzipBytes":
|
|
35
|
+
"sha256": "fddd863f1dca4cc8884bbf6a034dfdfe1cce5f5dc7b85a42776d2297512cb2a7",
|
|
36
|
+
"sri": "sha384-i2JXE00Si/MITDDy2WES5iy+65Ny7eoKNStNK65T7yvY6YC8Bkbe+WQ79aFSB+R+",
|
|
37
|
+
"bytes": 9380,
|
|
38
|
+
"gzipBytes": 3312
|
|
26
39
|
},
|
|
27
40
|
"index.js": {
|
|
28
|
-
"sha256": "
|
|
29
|
-
"sri": "sha384-
|
|
30
|
-
"bytes":
|
|
31
|
-
"gzipBytes":
|
|
41
|
+
"sha256": "559fb02f5353e4f5ff25caaff745e5dfd4fd5788a84992867996fb5f02b76b94",
|
|
42
|
+
"sri": "sha384-WJYmAkUGfbGZlZM9iW8KhMnBdrfXAia4HUz3Vf9PaUO9AoFPSHrYT1izflCjnpTG",
|
|
43
|
+
"bytes": 4472,
|
|
44
|
+
"gzipBytes": 1843
|
|
45
|
+
},
|
|
46
|
+
"testing.js": {
|
|
47
|
+
"sha256": "4917da4fd09a0ed34886c0831d1f59e129504b3c7d0fb70a104fdadcdc4e05c4",
|
|
48
|
+
"sri": "sha384-rTEGIbt82W3dv1pBBPj65IokdBGxXjXU8MR3RgELWDxtB2karLqr0+o8jlY5u60u",
|
|
49
|
+
"bytes": 2286,
|
|
50
|
+
"gzipBytes": 1030
|
|
51
|
+
},
|
|
52
|
+
"tip.js": {
|
|
53
|
+
"sha256": "0f2a15e6640d94a81fd0ea1376bdd3b67d4a765a546f8511635521f4a20bd95f",
|
|
54
|
+
"sri": "sha384-K8pK7stoxs7viZBclXhBEBWbMmddisbHZSQLrkisVhDb0ZlvW7Wy1kRagRR7HCQu",
|
|
55
|
+
"bytes": 5962,
|
|
56
|
+
"gzipBytes": 2290
|
|
32
57
|
},
|
|
33
58
|
"viceme.min.js": {
|
|
34
|
-
"sha256": "
|
|
35
|
-
"sri": "sha384-
|
|
36
|
-
"bytes":
|
|
37
|
-
"gzipBytes":
|
|
59
|
+
"sha256": "c05d6cccf5e98f56941d507409c092e00bf628c2f04810efc3a09a9e389354cf",
|
|
60
|
+
"sri": "sha384-BE8bq1YYCmrB+6OxIcHINjsXvGBqqPzn4WxlTE90u8i69tjg6sZ5t8oVldPRmaTj",
|
|
61
|
+
"bytes": 37200,
|
|
62
|
+
"gzipBytes": 11548
|
|
38
63
|
}
|
|
39
64
|
}
|
|
40
65
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public visitor session.
|
|
3
|
+
*
|
|
4
|
+
* ```text
|
|
5
|
+
* SDK + workKey + Origin -> POST /v1/public/work-sdk/sessions
|
|
6
|
+
* -> short-lived capability token -> public capability calls
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* The token lives in memory only (never localStorage/cookies), is bound to the
|
|
10
|
+
* Work, Origin, capability set, and expiry by the server, and is dropped on
|
|
11
|
+
* `destroy()`. `workKey` locates the Work — it is never an authorization
|
|
12
|
+
* credential.
|
|
13
|
+
*/
|
|
14
|
+
import type { Transport, TransportRequest, TransportResponse } from '../transport/transport.ts';
|
|
15
|
+
export interface CreateWorkSessionRequestDto {
|
|
16
|
+
workKey: string;
|
|
17
|
+
}
|
|
18
|
+
export interface WorkDescriptor {
|
|
19
|
+
key: string;
|
|
20
|
+
/** Capability names enabled for this work. */
|
|
21
|
+
capabilities: string[];
|
|
22
|
+
}
|
|
23
|
+
export interface WorkSessionSnapshot {
|
|
24
|
+
work: WorkDescriptor;
|
|
25
|
+
/** Opaque short-lived capability token; memory-only. */
|
|
26
|
+
token?: string;
|
|
27
|
+
/** Epoch milliseconds when the token expires, when provided by the server. */
|
|
28
|
+
expiresAt?: number;
|
|
29
|
+
user?: WorkUser;
|
|
30
|
+
userToken?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface WorkUser {
|
|
33
|
+
subject: string;
|
|
34
|
+
nickname: string | null;
|
|
35
|
+
avatarUrl: string | null;
|
|
36
|
+
}
|
|
37
|
+
export interface SessionManagerOptions {
|
|
38
|
+
workKey: string;
|
|
39
|
+
transport: Transport;
|
|
40
|
+
signal?: AbortSignal;
|
|
41
|
+
timeoutMs?: number;
|
|
42
|
+
/** Injectable clock for tests. */
|
|
43
|
+
now?: () => number;
|
|
44
|
+
}
|
|
45
|
+
export declare class SessionManager {
|
|
46
|
+
#private;
|
|
47
|
+
constructor(options: SessionManagerOptions);
|
|
48
|
+
get snapshot(): WorkSessionSnapshot | undefined;
|
|
49
|
+
/**
|
|
50
|
+
* Establish (or return the established) public session.
|
|
51
|
+
*
|
|
52
|
+
* A cached snapshot is reused only while it is unexpired; an expired
|
|
53
|
+
* snapshot is dropped and re-authenticated. Concurrent callers share one
|
|
54
|
+
* in-flight request (single flight).
|
|
55
|
+
*/
|
|
56
|
+
establish(): Promise<WorkSessionSnapshot>;
|
|
57
|
+
request(request: Omit<TransportRequest, 'authorization' | 'userAuthorization' | 'signal'>): Promise<TransportResponse>;
|
|
58
|
+
authenticate(input: {
|
|
59
|
+
userToken: string;
|
|
60
|
+
user: WorkUser;
|
|
61
|
+
}): void;
|
|
62
|
+
signOut(): Promise<void>;
|
|
63
|
+
/** Drop the token; next `establish()` re-authenticates. */
|
|
64
|
+
invalidate(): void;
|
|
65
|
+
/** Hard cleanup: forget the token and pending work. */
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAChG,MAAM,WAAW,2BAA2B;IAC1C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,cAAc,CAAC;IACrB,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8EAA8E;IAC9E,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AA4CD,qBAAa,cAAc;;gBAMb,OAAO,EAAE,qBAAqB;IAK1C,IAAI,QAAQ,IAAI,mBAAmB,GAAG,SAAS,CAE9C;IAQD;;;;;;OAMG;IACH,SAAS,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAwBnC,OAAO,CACX,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,eAAe,GAAG,mBAAmB,GAAG,QAAQ,CAAC,GAChF,OAAO,CAAC,iBAAiB,CAAC;IAwB7B,YAAY,CAAC,KAAK,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,IAAI;IAS1D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAK9B,2DAA2D;IAC3D,UAAU,IAAI,IAAI;IAIlB,uDAAuD;IACvD,OAAO,IAAI,IAAI;CAIhB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@viceme-ai/sdk/testing` — explicit test adapter.
|
|
3
|
+
*
|
|
4
|
+
* Deterministic fixture helpers for SDK consumers and capability authors.
|
|
5
|
+
* This code must never be imported from production core, loader, or capability
|
|
6
|
+
* bundles; it is excluded from them at build time and only exported via the
|
|
7
|
+
* `./testing` subpath.
|
|
8
|
+
*
|
|
9
|
+
* The test client runs the exact same config, lifecycle, error, and contract
|
|
10
|
+
* validation as production `createViceMe()` — it is not a bypass mock.
|
|
11
|
+
*/
|
|
12
|
+
import type { ViceMeClient } from '../core/client.ts';
|
|
13
|
+
import type { ViceMeRegion } from '../core/config.ts';
|
|
14
|
+
import type { AccessPresenter } from '../core/presentation.ts';
|
|
15
|
+
import type { Transport, TransportRequest } from '../transport/transport.ts';
|
|
16
|
+
export interface MemoryTransportWorkFixture {
|
|
17
|
+
key: string;
|
|
18
|
+
capabilities: string[];
|
|
19
|
+
token?: string;
|
|
20
|
+
expiresAt?: number;
|
|
21
|
+
}
|
|
22
|
+
export interface MemoryTransportOptions {
|
|
23
|
+
/** Work descriptor served for `POST /v1/public/work-sdk/sessions`. */
|
|
24
|
+
work: MemoryTransportWorkFixture;
|
|
25
|
+
/** Artificial response latency in milliseconds (default 0). */
|
|
26
|
+
latencyMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Queue of failures thrown before the fixture response is served; each
|
|
29
|
+
* entry is consumed by one session request. Use for retry/timeout tests.
|
|
30
|
+
*/
|
|
31
|
+
sessionFailures?: Array<Error | {
|
|
32
|
+
status: number;
|
|
33
|
+
code: string;
|
|
34
|
+
message?: string;
|
|
35
|
+
}>;
|
|
36
|
+
}
|
|
37
|
+
export interface MemoryTransport extends Transport {
|
|
38
|
+
/** Every request seen so far, for assertions. */
|
|
39
|
+
readonly requests: TransportRequest[];
|
|
40
|
+
}
|
|
41
|
+
export declare function createMemoryTransport(options: MemoryTransportOptions): MemoryTransport;
|
|
42
|
+
export interface CreateTestViceMeOptions {
|
|
43
|
+
workKey: string;
|
|
44
|
+
region: ViceMeRegion;
|
|
45
|
+
/** Mock transport serving the fixture contract. */
|
|
46
|
+
transport: Transport;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
presenter?: AccessPresenter;
|
|
49
|
+
/** Stable virtual clock for deterministic time-based assertions. */
|
|
50
|
+
now?: () => number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a client backed by an injected transport. Runs identical validation
|
|
54
|
+
* and lifecycle logic to `createViceMe()`.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createTestViceMe(options: CreateTestViceMeOptions): ViceMeClient;
|
|
57
|
+
/** Standard fixture work used across repo tests and examples. */
|
|
58
|
+
export declare const FIXTURE_WORK: MemoryTransportWorkFixture;
|
|
59
|
+
//# sourceMappingURL=test-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-adapter.d.ts","sourceRoot":"","sources":["../../src/testing/test-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAA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the deterministic mock transport and test client so the emitted
|
|
5
|
+
* declaration lands at `dist/testing.d.ts`, matching the package exports map.
|
|
6
|
+
*/
|
|
7
|
+
export { createTestViceMe, createMemoryTransport, FIXTURE_WORK } from './testing/test-adapter.ts';
|
|
8
|
+
export type { MemoryTransport, MemoryTransportOptions, MemoryTransportWorkFixture, CreateTestViceMeOptions, } from './testing/test-adapter.ts';
|
|
9
|
+
//# sourceMappingURL=testing.d.ts.map
|