@viceme-ai/sdk 0.3.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 (64) hide show
  1. package/README.md +70 -45
  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-DKsaEtwq.js → client-Cbldd7F2.js} +321 -313
  7. package/dist/chunks/client-Cbldd7F2.js.map +1 -0
  8. package/dist/chunks/{version-C3KVoLNb.js → errors-B-Qv_azy.js} +4 -7
  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 +2 -0
  13. package/dist/core/build-endpoints.d.ts.map +1 -1
  14. package/dist/core/capabilities.d.ts +2 -2
  15. package/dist/core/capabilities.d.ts.map +1 -1
  16. package/dist/core/client.d.ts +4 -2
  17. package/dist/core/client.d.ts.map +1 -1
  18. package/dist/core/lifecycle.d.ts +2 -4
  19. package/dist/core/lifecycle.d.ts.map +1 -1
  20. package/dist/core/presentation.d.ts +7 -2
  21. package/dist/core/presentation.d.ts.map +1 -1
  22. package/dist/danmaku/index.d.ts +1 -0
  23. package/dist/danmaku/index.d.ts.map +1 -1
  24. package/dist/danmaku/mount.d.ts +1 -1
  25. package/dist/danmaku/mount.d.ts.map +1 -1
  26. package/dist/danmaku.js +127 -121
  27. package/dist/danmaku.js.map +1 -1
  28. package/dist/generated/public-contract.d.ts +54 -410
  29. package/dist/generated/public-contract.d.ts.map +1 -1
  30. package/dist/index.d.ts +2 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +23 -21
  33. package/dist/index.js.map +1 -1
  34. package/dist/loader/attributes.d.ts +3 -2
  35. package/dist/loader/attributes.d.ts.map +1 -1
  36. package/dist/loader/auto-loader.d.ts +1 -1
  37. package/dist/loader/auto-loader.d.ts.map +1 -1
  38. package/dist/loader/events.d.ts +1 -44
  39. package/dist/loader/events.d.ts.map +1 -1
  40. package/dist/loader/registry.d.ts +2 -1
  41. package/dist/loader/registry.d.ts.map +1 -1
  42. package/dist/manifest.json +41 -28
  43. package/dist/session/session.d.ts +7 -6
  44. package/dist/session/session.d.ts.map +1 -1
  45. package/dist/testing/test-adapter.d.ts +1 -1
  46. package/dist/testing/test-adapter.d.ts.map +1 -1
  47. package/dist/testing.js +7 -6
  48. package/dist/testing.js.map +1 -1
  49. package/dist/tip/index.d.ts +22 -0
  50. package/dist/tip/index.d.ts.map +1 -0
  51. package/dist/tip/mount.d.ts +5 -0
  52. package/dist/tip/mount.d.ts.map +1 -0
  53. package/dist/tip.js +137 -0
  54. package/dist/tip.js.map +1 -0
  55. package/dist/transport/transport.d.ts +3 -1
  56. package/dist/transport/transport.d.ts.map +1 -1
  57. package/dist/version.d.ts +1 -1
  58. package/dist/viceme.min.js +2 -22
  59. package/dist/viceme.min.js.map +1 -1
  60. package/package.json +6 -2
  61. package/dist/chunks/client-DKsaEtwq.js.map +0 -1
  62. package/dist/chunks/version-C3KVoLNb.js.map +0 -1
  63. package/dist/loader/mount-handle.d.ts +0 -25
  64. package/dist/loader/mount-handle.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # @viceme-ai/sdk
2
2
 
3
- Public ViceMe browser SDK: headless core, public session, and capability
4
- subpaths for static HTML, browser-native ESM, React/Next.js, and
5
- Agent-generated sites.
3
+ ViceMe browser SDK for Shop-hosted engagement and origin-bound Website Work access.
6
4
 
7
5
  ## Install
8
6
 
@@ -10,63 +8,90 @@ Agent-generated sites.
10
8
  pnpm add @viceme-ai/sdk
11
9
  ```
12
10
 
13
- ## Usage
11
+ ## Static HTML
12
+
13
+ ```html
14
+ <div id="viceme-engagement"></div>
15
+ <script
16
+ defer
17
+ src="https://viceme.cn/viceme-sdk/v1/viceme.min.js"
18
+ data-viceme-work="wrk_public_xxx"
19
+ data-viceme-region="cn"
20
+ data-viceme-features="danmaku,tip"
21
+ data-viceme-target="#viceme-engagement"
22
+ data-viceme-theme="auto"
23
+ ></script>
24
+ ```
25
+
26
+ The feature declaration accepts `danmaku`, `tip`, or both without whitespace or
27
+ duplicates.
28
+
29
+ The `viceme.cn/viceme-sdk/v1/*` Shop proxy directly exposes one configured
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.
34
+
35
+ With CSP, allow the exact regional Shop origin in `script-src`, `connect-src`,
36
+ and `frame-src`, and keep `object-src 'none'`. A nonce with `'strict-dynamic'`
37
+ may authorize dynamic scripts, but `connect-src` and `frame-src` still need the
38
+ exact origin. Do not use `*` or a ViceMe subdomain wildcard.
39
+
40
+ ## ESM
14
41
 
15
42
  ```ts
16
43
  import { createViceMe } from '@viceme-ai/sdk';
44
+ import { mountDanmaku } from '@viceme-ai/sdk/danmaku';
45
+ import { mountTip } from '@viceme-ai/sdk/tip';
17
46
 
18
47
  const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
19
48
  await client.ready();
20
49
 
21
- // Use server-authoritative titles and prices in the host site's existing
22
- // Button/Card components. This does not open or customize ViceMe checkout.
23
- const features = await client.access.getFeatures();
24
- const emperor = features.find((feature) => feature.featureKey === 'emperor');
50
+ const target = document.querySelector('#viceme-engagement');
51
+ if (!target) throw new Error('ViceMe target missing');
25
52
 
26
- const access = await client.access.checkMany(['dingdong', 'emperor']);
27
- if (access.dingdong.allowed) enableDingdong();
28
- if (access.emperor.allowed) enableEmperor();
29
-
30
- // Call from a user gesture. A denied decision opens the ViceMe
31
- // bottom-sheet/in-page Web Component. Creator details and recent work covers appear
32
- // above one authorization action; accepted authorization automatically follows.
33
- const decision = await client.access.require('emperor');
34
- if (decision.allowed) enableEmperor();
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] : []));
35
58
 
59
+ mounted.forEach((handle) => handle.destroy());
36
60
  client.destroy();
37
61
  ```
38
62
 
39
- When adding a host-side locked state or purchase entry, preserve the site's
40
- existing component library, design tokens, responsive behavior, and feedback
41
- patterns. Keep the original business action unchanged and call it only after
42
- `access.require()` returns an allowed decision. Never hard-code a price from
43
- local configuration; `getFeatures()` returns the current display price. The
44
- ViceMe-owned authorization and checkout layer remains isolated and unchanged.
45
-
46
- The SDK registers and mounts `<viceme-access-layer>` with isolated ViceMe-owned
47
- styles. Authorization and checkout remain inside its iframe area and complete through
48
- an origin- and channel-validated message; no browser popup, page navigation,
49
- `confirm`, or `alert` is used. Custom site presenters and style inference are
50
- not part of the current public contract. WeChat opens directly inside the frame,
51
- and the checkout frame keeps a stable height while its content loads.
63
+ Run those cleanup calls from the owning component's unmount path or another
64
+ explicit lifecycle boundary, not from `pagehide` (which also covers bfcache).
52
65
 
53
- Static HTML sites can use the CDN auto-loader instead see the
54
- [repository README](https://github.com/ViceMe-AI/sdk).
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
69
+ internal SDK to read and create anonymous messages through
70
+ `/v1/danmaku/messages`. The `/widget/tip/<workKey>` iframe handles login and
71
+ payment only after its exact parent Origin is registered.
55
72
 
56
- ## Testing your integration
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.
57
78
 
58
79
  ```ts
59
- import { createTestViceMe, createMemoryTransport } from '@viceme-ai/sdk/testing';
60
-
61
- const client = createTestViceMe({
62
- workKey: 'wrk_test',
63
- region: 'cn',
64
- transport: createMemoryTransport({
65
- work: { key: 'wrk_test', capabilities: ['fixture'] },
66
- }),
67
- });
68
- await client.ready();
80
+ const decisions = await client.access.checkMany(['members', 'pro-tools']);
81
+ if (!decisions['pro-tools']?.allowed) {
82
+ await client.access.require('pro-tools');
83
+ }
69
84
  ```
70
85
 
71
- Consumers branch on stable `ViceMeError.code` values only never on error
72
- messages. Work-session tokens and work-scoped users remain in memory only.
86
+ The Tip subpath exports `TipPaidDetail` and `TipWidgetCloseDetail` for the
87
+ sanitized `viceme:tip-paid` and `viceme:widget-close` `CustomEvent` details.
88
+
89
+ The danmaku mount hashes the canonical page URL locally, combines it with a 10%
90
+ scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
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","sourceRoot":"","sources":["../src/browser-events.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAE/E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,C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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"}