@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.
Files changed (67) hide show
  1. package/README.md +46 -17
  2. package/dist/browser-events.d.ts +49 -0
  3. package/dist/browser-events.d.ts.map +1 -0
  4. package/dist/capability-mount.d.ts +15 -0
  5. package/dist/capability-mount.d.ts.map +1 -0
  6. package/dist/chunks/client-Cbldd7F2.js +949 -0
  7. package/dist/chunks/client-Cbldd7F2.js.map +1 -0
  8. package/dist/chunks/{version-BbUa2jZV.js → errors-B-Qv_azy.js} +27 -17
  9. package/dist/chunks/errors-B-Qv_azy.js.map +1 -0
  10. package/dist/chunks/version-C8DeBm39.js +6 -0
  11. package/dist/chunks/version-C8DeBm39.js.map +1 -0
  12. package/dist/core/build-endpoints.d.ts +5 -0
  13. package/dist/core/build-endpoints.d.ts.map +1 -1
  14. package/dist/core/capabilities.d.ts +79 -0
  15. package/dist/core/capabilities.d.ts.map +1 -0
  16. package/dist/core/client.d.ts +36 -8
  17. package/dist/core/client.d.ts.map +1 -1
  18. package/dist/core/config.d.ts +14 -4
  19. package/dist/core/config.d.ts.map +1 -1
  20. package/dist/core/errors.d.ts +1 -1
  21. package/dist/core/errors.d.ts.map +1 -1
  22. package/dist/core/presentation.d.ts +29 -0
  23. package/dist/core/presentation.d.ts.map +1 -0
  24. package/dist/danmaku/index.d.ts +1 -0
  25. package/dist/danmaku/index.d.ts.map +1 -1
  26. package/dist/danmaku/mount.d.ts +1 -1
  27. package/dist/danmaku/mount.d.ts.map +1 -1
  28. package/dist/danmaku.js +127 -125
  29. package/dist/danmaku.js.map +1 -1
  30. package/dist/generated/public-contract.d.ts +291 -43
  31. package/dist/generated/public-contract.d.ts.map +1 -1
  32. package/dist/index.d.ts +9 -4
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +114 -95
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader/attributes.d.ts +3 -2
  37. package/dist/loader/attributes.d.ts.map +1 -1
  38. package/dist/loader/auto-loader.d.ts +1 -1
  39. package/dist/loader/auto-loader.d.ts.map +1 -1
  40. package/dist/loader/events.d.ts +1 -44
  41. package/dist/loader/events.d.ts.map +1 -1
  42. package/dist/loader/registry.d.ts +2 -1
  43. package/dist/loader/registry.d.ts.map +1 -1
  44. package/dist/manifest.json +44 -19
  45. package/dist/session/session.d.ts +68 -0
  46. package/dist/session/session.d.ts.map +1 -0
  47. package/dist/testing/test-adapter.d.ts +59 -0
  48. package/dist/testing/test-adapter.d.ts.map +1 -0
  49. package/dist/testing.d.ts +9 -0
  50. package/dist/testing.d.ts.map +1 -0
  51. package/dist/testing.js +76 -0
  52. package/dist/testing.js.map +1 -0
  53. package/dist/tip/index.d.ts +22 -0
  54. package/dist/tip/index.d.ts.map +1 -0
  55. package/dist/tip/mount.d.ts +5 -0
  56. package/dist/tip/mount.d.ts.map +1 -0
  57. package/dist/tip.js +137 -0
  58. package/dist/tip.js.map +1 -0
  59. package/dist/transport/transport.d.ts +46 -0
  60. package/dist/transport/transport.d.ts.map +1 -0
  61. package/dist/version.d.ts +1 -1
  62. package/dist/viceme.min.js +212 -1
  63. package/dist/viceme.min.js.map +1 -1
  64. package/package.json +10 -2
  65. package/dist/chunks/version-BbUa2jZV.js.map +0 -1
  66. package/dist/loader/mount-handle.d.ts +0 -25
  67. package/dist/loader/mount-handle.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @viceme-ai/sdk
2
2
 
3
- PUBLIC-only ViceMe browser SDK for the Shop-hosted danmaku overlay.
3
+ ViceMe browser SDK for Shop-hosted engagement and origin-bound Website Work access.
4
4
 
5
5
  ## Install
6
6
 
@@ -11,23 +11,26 @@ pnpm add @viceme-ai/sdk
11
11
  ## Static HTML
12
12
 
13
13
  ```html
14
+ <div id="viceme-engagement"></div>
14
15
  <script
15
16
  defer
16
17
  src="https://viceme.cn/viceme-sdk/v1/viceme.min.js"
17
18
  data-viceme-work="wrk_public_xxx"
18
19
  data-viceme-region="cn"
19
- data-viceme-features="danmaku"
20
- data-viceme-target="body"
20
+ data-viceme-features="danmaku,tip"
21
+ data-viceme-target="#viceme-engagement"
21
22
  data-viceme-theme="auto"
22
23
  ></script>
23
24
  ```
24
25
 
25
- The feature declaration must be exactly `danmaku`.
26
+ The feature declaration accepts `danmaku`, `tip`, or both without whitespace or
27
+ duplicates.
26
28
 
27
29
  The `viceme.cn/viceme-sdk/v1/*` Shop proxy directly exposes one configured
28
- exact release, including the loader, manifest, danmaku entry, and hashed
29
- chunks. It is distinct from the direct S3 `v1/viceme.min.js` alias, whose fixed
30
- bootstrap reads `-/aliases/v1` before loading an exact-version directory.
30
+ exact release, including the loader, manifest, danmaku and Tip entries, and
31
+ hashed chunks. It is distinct from the direct S3 `v1/viceme.min.js` alias,
32
+ whose fixed bootstrap reads `-/aliases/v1` before loading an exact-version
33
+ directory.
31
34
 
32
35
  With CSP, allow the exact regional Shop origin in `script-src`, `connect-src`,
33
36
  and `frame-src`, and keep `object-src 'none'`. A nonce with `'strict-dynamic'`
@@ -39,30 +42,56 @@ exact origin. Do not use `*` or a ViceMe subdomain wildcard.
39
42
  ```ts
40
43
  import { createViceMe } from '@viceme-ai/sdk';
41
44
  import { mountDanmaku } from '@viceme-ai/sdk/danmaku';
45
+ import { mountTip } from '@viceme-ai/sdk/tip';
42
46
 
43
47
  const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
44
48
  await client.ready();
45
49
 
46
- const mounted = await mountDanmaku(client, {
47
- target: document.body,
48
- theme: 'auto',
49
- });
50
+ const target = document.querySelector('#viceme-engagement');
51
+ if (!target) throw new Error('ViceMe target missing');
50
52
 
51
- mounted.destroy();
53
+ const results = await Promise.allSettled([
54
+ mountDanmaku(client, { target, theme: 'auto' }),
55
+ mountTip(client, { target, theme: 'auto' }),
56
+ ]);
57
+ const mounted = results.flatMap((result) => (result.status === 'fulfilled' ? [result.value] : []));
58
+
59
+ mounted.forEach((handle) => handle.destroy());
52
60
  client.destroy();
53
61
  ```
54
62
 
55
63
  Run those cleanup calls from the owning component's unmount path or another
56
64
  explicit lifecycle boundary, not from `pagehide` (which also covers bfcache).
57
65
 
58
- `createViceMe` is purely local and never contacts Shop. A live client reports
59
- only the `danmaku` capability. The hosted `/embed/danmaku` iframe uses Shop's
66
+ `createViceMe` and `ready()` are purely local and never contact Shop. A live client reports
67
+ build support for `danmaku` and `tip`; Shop remains authoritative for whether a
68
+ Work enables either capability. The hosted `/embed/danmaku` iframe uses Shop's
60
69
  internal SDK to read and create anonymous messages through
61
- `/v1/danmaku/messages`.
70
+ `/v1/danmaku/messages`. The `/widget/tip/<workKey>` iframe handles login and
71
+ payment only after its exact parent Origin is registered.
72
+
73
+ Access operations establish a short-lived, memory-only Work session on first
74
+ use. They expose `client.auth`, `client.access`, and `client.checkout`; login,
75
+ explicit follow, and hosted checkout remain ViceMe-owned UI. The host never
76
+ receives a general ViceMe session or payment credential. There is no public
77
+ `@viceme-ai/sdk/testing` subpath.
78
+
79
+ ```ts
80
+ const decisions = await client.access.checkMany(['members', 'pro-tools']);
81
+ if (!decisions['pro-tools']?.allowed) {
82
+ await client.access.require('pro-tools');
83
+ }
84
+ ```
62
85
 
63
- There is no public SDK Session, Bearer token, auth, follow, access, purchase,
64
- or checkout surface, and no `@viceme-ai/sdk/testing` subpath.
86
+ The Tip subpath exports `TipPaidDetail` and `TipWidgetCloseDetail` for the
87
+ sanitized `viceme:tip-paid` and `viceme:widget-close` `CustomEvent` details.
65
88
 
66
89
  The danmaku mount hashes the canonical page URL locally, combines it with a 10%
67
90
  scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
68
91
  the mount removes its nodes, listeners, debounce timer, and location poll.
92
+
93
+ The Tip mount sends no amount, provider, token, or application ID. It enables
94
+ interaction only after a trusted resize handshake. Shop resets its hosted
95
+ payment surface on Escape before sending close; the SDK forwards sanitized
96
+ close and paid notifications, and removes its iframe, timer, media listener,
97
+ and message listener on destroy.
@@ -0,0 +1,49 @@
1
+ /** Stable, allowlisted `viceme:*` DOM events shared by hosted capabilities. */
2
+ import type { ViceMeErrorCode } from './core/errors.ts';
3
+ export interface VicemeReadyDetail {
4
+ clientKey: string;
5
+ workKey: string;
6
+ capabilities: string[];
7
+ version: string;
8
+ }
9
+ export interface VicemeCapabilityReadyDetail {
10
+ clientKey: string;
11
+ instanceKey: string;
12
+ capability: string;
13
+ version: string;
14
+ }
15
+ export interface VicemeErrorDetail {
16
+ clientKey?: string;
17
+ instanceKey?: string;
18
+ capability?: string;
19
+ code: ViceMeErrorCode;
20
+ retryable: boolean;
21
+ requestId?: string;
22
+ }
23
+ export interface VicemeDestroyedDetail {
24
+ clientKey: string;
25
+ instanceKey: string;
26
+ capability: string;
27
+ }
28
+ export interface VicemeWidgetCloseDetail {
29
+ workId: string;
30
+ }
31
+ export interface VicemeTipPaidDetail {
32
+ workId: string;
33
+ orderNo: string;
34
+ status: 'PAID';
35
+ amountCents: number;
36
+ }
37
+ export type VicemeEventType = 'viceme:ready' | 'viceme:capability-ready' | 'viceme:error' | 'viceme:destroyed' | 'viceme:widget-close' | 'viceme:tip-paid';
38
+ export type VicemeEventDetailMap = {
39
+ 'viceme:ready': VicemeReadyDetail;
40
+ 'viceme:capability-ready': VicemeCapabilityReadyDetail;
41
+ 'viceme:error': VicemeErrorDetail;
42
+ 'viceme:destroyed': VicemeDestroyedDetail;
43
+ 'viceme:widget-close': VicemeWidgetCloseDetail;
44
+ 'viceme:tip-paid': VicemeTipPaidDetail;
45
+ };
46
+ /** Strip anything outside the documented allowlist before dispatch. */
47
+ export declare function sanitizeDetail(type: VicemeEventType, detail: VicemeEventDetailMap[VicemeEventType]): VicemeEventDetailMap[VicemeEventType];
48
+ export declare function dispatchViceMeEvent<K extends VicemeEventType>(target: EventTarget, type: K, detail: VicemeEventDetailMap[K]): void;
49
+ //# sourceMappingURL=browser-events.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-events.d.ts","sour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C;IAClC,kBAAkB,EAAE,qBAAqB,CAAC;IAC1C,qBAAqB,EAAE,uBAAuB,CAAC;IAC/C,iBAAiB,EAAE,mBAAmB,CAAC;CACxC,CAAC;AAcF,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,15 @@
1
+ import type { ViceMeClient } from './core/client.ts';
2
+ export interface CapabilityMountOptions {
3
+ /** Mount host element; the capability owns its Shadow DOM subtree. */
4
+ target: Element;
5
+ theme: 'light' | 'dark' | 'auto';
6
+ /** Abort a mount that has not completed and destroy it after completion. */
7
+ signal?: AbortSignal;
8
+ }
9
+ /** A capability's own lifecycle handle; the loader assigns public identity. */
10
+ export interface CapabilityMountHandle {
11
+ readonly capability: string;
12
+ destroy(): void;
13
+ }
14
+ export type CapabilityMountFunction = (client: ViceMeClient, options: CapabilityMountOptions) => Promise<CapabilityMountHandle>;
15
+ //# sourceMappingURL=capability-mount.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-mount.d.ts","sourceRoot":"","sources":["../src/capability-mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC,sEAAsE;IACtE,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACjC,4EAA4E;IAC5E,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,+EAA+E;AAC/E,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,OAAO,IAAI,IAAI,CAAC;CACjB;AAED,MAAM,MAAM,uBAAuB,GAAG,CACpC,MAAM,EAAE,YAAY,EACpB,OAAO,EAAE,sBAAsB,KAC5B,OAAO,CAAC,qBAAqB,CAAC,CAAC"}