@viceme-ai/sdk 0.4.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +116 -17
  2. package/dist/browser-events.d.ts +5 -2
  3. package/dist/browser-events.d.ts.map +1 -1
  4. package/dist/chunks/build-endpoints-NrDmg6jf.js +12 -0
  5. package/dist/chunks/build-endpoints-NrDmg6jf.js.map +1 -0
  6. package/dist/chunks/{client-Cbldd7F2.js → client-DEg6YouY.js} +350 -272
  7. package/dist/chunks/client-DEg6YouY.js.map +1 -0
  8. package/dist/chunks/{errors-B-Qv_azy.js → errors-C7DfLKcF.js} +14 -22
  9. package/dist/chunks/errors-C7DfLKcF.js.map +1 -0
  10. package/dist/chunks/validation-patAYhXC.js +43 -0
  11. package/dist/chunks/validation-patAYhXC.js.map +1 -0
  12. package/dist/chunks/version-BJiUVcir.js +6 -0
  13. package/dist/chunks/{version-C8DeBm39.js.map → version-BJiUVcir.js.map} +1 -1
  14. package/dist/core/capabilities.d.ts +3 -0
  15. package/dist/core/capabilities.d.ts.map +1 -1
  16. package/dist/core/client.d.ts.map +1 -1
  17. package/dist/core/config.d.ts +1 -1
  18. package/dist/core/config.d.ts.map +1 -1
  19. package/dist/core/errors.d.ts +1 -1
  20. package/dist/core/errors.d.ts.map +1 -1
  21. package/dist/core/presentation.d.ts +2 -0
  22. package/dist/core/presentation.d.ts.map +1 -1
  23. package/dist/danmaku.js +5 -4
  24. package/dist/danmaku.js.map +1 -1
  25. package/dist/generated/public-contract.d.ts +108 -1
  26. package/dist/generated/public-contract.d.ts.map +1 -1
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +4 -4
  29. package/dist/index.js.map +1 -1
  30. package/dist/loader/auto-loader.d.ts.map +1 -1
  31. package/dist/manifest.json +50 -38
  32. package/dist/session/session.d.ts.map +1 -1
  33. package/dist/testing.js +14 -14
  34. package/dist/testing.js.map +1 -1
  35. package/dist/tip/headless.d.ts +4 -0
  36. package/dist/tip/headless.d.ts.map +1 -0
  37. package/dist/tip/index.d.ts +47 -2
  38. package/dist/tip/index.d.ts.map +1 -1
  39. package/dist/tip/mount.d.ts.map +1 -1
  40. package/dist/tip/testing.d.ts +9 -0
  41. package/dist/tip/testing.d.ts.map +1 -0
  42. package/dist/tip/testing.js +43 -0
  43. package/dist/tip/testing.js.map +1 -0
  44. package/dist/tip/validation.d.ts +7 -0
  45. package/dist/tip/validation.d.ts.map +1 -0
  46. package/dist/tip.js +419 -84
  47. package/dist/tip.js.map +1 -1
  48. package/dist/version.d.ts +1 -1
  49. package/dist/viceme.min.js +5 -2
  50. package/dist/viceme.min.js.map +1 -1
  51. package/package.json +7 -6
  52. package/dist/bootstrap.min.js +0 -2
  53. package/dist/bootstrap.min.js.map +0 -1
  54. package/dist/chunks/client-Cbldd7F2.js.map +0 -1
  55. package/dist/chunks/errors-B-Qv_azy.js.map +0 -1
  56. package/dist/chunks/version-C8DeBm39.js +0 -6
  57. package/dist/loader/bootstrap.d.ts +0 -1
  58. package/dist/loader/bootstrap.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # @viceme-ai/sdk
2
2
 
3
- ViceMe browser SDK for Shop-hosted engagement and origin-bound Website Work access.
3
+ ViceMe browser SDK for Shop-hosted engagement and Website Work access.
4
+
5
+ The release PR atomically owns the package version, runtime manifest, and
6
+ changelog update. During the current preview stage, publication does not
7
+ require a repository license file. The root `LICENSE-PENDING.md` records the
8
+ deferred decision without blocking release; licensing will be finalized
9
+ separately.
4
10
 
5
11
  ## Install
6
12
 
@@ -14,8 +20,8 @@ pnpm add @viceme-ai/sdk
14
20
  <div id="viceme-engagement"></div>
15
21
  <script
16
22
  defer
17
- src="https://viceme.cn/viceme-sdk/v1/viceme.min.js"
18
- data-viceme-work="wrk_public_xxx"
23
+ src="https://s3.viceme.cn/viceme-sdk/0.5.0/viceme.min.js"
24
+ data-viceme-work="wrk_live_demo"
19
25
  data-viceme-region="cn"
20
26
  data-viceme-features="danmaku,tip"
21
27
  data-viceme-target="#viceme-engagement"
@@ -26,16 +32,16 @@ pnpm add @viceme-ai/sdk
26
32
  The feature declaration accepts `danmaku`, `tip`, or both without whitespace or
27
33
  duplicates.
28
34
 
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.
35
+ Static CDN entry points always use an immutable exact-version directory. The CN
36
+ host is `s3.viceme.cn`; GLOBAL uses `s3.viceme.ai`. The `0.5.0` URL above is the
37
+ current source target and is unavailable until that exact release is published
38
+ and verified.
34
39
 
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.
40
+ With CSP, allow the exact regional S3 origin in `script-src` and `connect-src`,
41
+ the exact regional Shop origin in `frame-src`, and keep `object-src 'none'`. A
42
+ nonce with `'strict-dynamic'` may authorize dynamic scripts, but the other
43
+ directives still need exact origins. Do not use `*` or a ViceMe subdomain
44
+ wildcard.
39
45
 
40
46
  ## ESM
41
47
 
@@ -44,7 +50,7 @@ import { createViceMe } from '@viceme-ai/sdk';
44
50
  import { mountDanmaku } from '@viceme-ai/sdk/danmaku';
45
51
  import { mountTip } from '@viceme-ai/sdk/tip';
46
52
 
47
- const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
53
+ const client = createViceMe({ workKey: 'wrk_live_demo', region: 'cn' });
48
54
  await client.ready();
49
55
 
50
56
  const target = document.querySelector('#viceme-engagement');
@@ -67,14 +73,35 @@ explicit lifecycle boundary, not from `pagehide` (which also covers bfcache).
67
73
  build support for `danmaku` and `tip`; Shop remains authoritative for whether a
68
74
  Work enables either capability. The hosted `/embed/danmaku` iframe uses Shop's
69
75
  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.
76
+ `/v1/danmaku/messages`. The `/widget/tip/<workKey>` iframe owns confirmation,
77
+ payment, risk, and result authority. Visitors do not sign in to ViceMe and are
78
+ anonymous to the creator; the observed parent Origin is attribution rather than
79
+ an authorization gate.
80
+
81
+ Pass a selected public pair value: `keys.test` is `wrk_test_...` and `keys.live`
82
+ is `wrk_live_...`. Other Work key shapes are rejected locally.
72
83
 
73
84
  Access operations establish a short-lived, memory-only Work session on first
74
85
  use. They expose `client.auth`, `client.access`, and `client.checkout`; login,
75
86
  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.
87
+ receives a general ViceMe session or payment credential. Tests can inject a
88
+ deterministic transport and presenter through `@viceme-ai/sdk/testing`.
89
+ Calling `client.destroy()` cancels in-flight access requests, closes the active
90
+ SDK-owned sign-in or checkout layer, and rejects the interrupted call with
91
+ `CLIENT_DESTROYED`; late responses cannot restore the in-memory Work token.
92
+
93
+ The current Website Access release accepts any valid HTTP(S) host Origin and
94
+ does not require DNS TXT verification. Session tokens remain bound to the
95
+ Origin observed when they were issued, but that Origin is not compared with a
96
+ registered allowlist. The hosted checkout iframe likewise has no parent-Origin
97
+ `frame-ancestors` restriction; its signed launch context, expiry, official
98
+ Shop URL, and server-authoritative entitlement checks remain enforced.
99
+
100
+ Website access login renders the work-bound WeChat QR code directly in the SDK
101
+ layer. Paid access keeps desktop QR payment and WeChat JSAPI in that layer;
102
+ mobile H5/WAP payment may open a provider page or app. The original page polls
103
+ the server-authoritative access decision and closes the layer after entitlement
104
+ is active. This behavior does not change the separate Tip Widget flow.
78
105
 
79
106
  ```ts
80
107
  const decisions = await client.access.checkMany(['members', 'pro-tools']);
@@ -85,6 +112,8 @@ if (!decisions['pro-tools']?.allowed) {
85
112
 
86
113
  The Tip subpath exports `TipPaidDetail` and `TipWidgetCloseDetail` for the
87
114
  sanitized `viceme:tip-paid` and `viceme:widget-close` `CustomEvent` details.
115
+ `TipPaidDetail` contains only `status`, trusted `work.id/title`, amount, and CNY;
116
+ it contains no key, provider, order number, token, or transaction identifier.
88
117
 
89
118
  The danmaku mount hashes the canonical page URL locally, combines it with a 10%
90
119
  scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
@@ -95,3 +124,73 @@ interaction only after a trusted resize handshake. Shop resets its hosted
95
124
  payment surface on Escape before sending close; the SDK forwards sanitized
96
125
  close and paid notifications, and removes its iframe, timer, media listener,
97
126
  and message listener on destroy.
127
+
128
+ ## Headless Tip
129
+
130
+ This additive API targets `0.5.0`. Do not expect `createTip` or
131
+ `@viceme-ai/sdk/tip/testing` from the immutable npm `0.4.0` package.
132
+
133
+ ```ts
134
+ import { createViceMe } from '@viceme-ai/sdk';
135
+ import { createTip } from '@viceme-ai/sdk/tip';
136
+
137
+ const client = createViceMe({ workKey: 'wrk_live_demo', region: 'cn' });
138
+ const tip = createTip(client);
139
+ const config = await tip.getConfig();
140
+
141
+ button.addEventListener('click', async () => {
142
+ const result = await tip.open({
143
+ amountCents: config.amount.minCents,
144
+ provider: config.providers[0],
145
+ locale: 'zh-CN',
146
+ appearance: 'auto',
147
+ });
148
+ console.log(result.status);
149
+ });
150
+
151
+ function destroyTip() {
152
+ tip.destroy();
153
+ client.destroy();
154
+ }
155
+ ```
156
+
157
+ Call `destroyTip()` from the owning component or route cleanup. Do not bind it
158
+ to `pagehide`, because that event also fires when a page enters the bfcache.
159
+
160
+ `getConfig()` strictly parses the credential-free regional
161
+ `GET /v1/work-sdk/<encoded-workKey>/tip-config` response. Call `open()` directly
162
+ from user activation so it can create its secure full-screen frame in the same
163
+ call stack. Only `PAID`, `CANCELLED`, and `UNKNOWN` cross back; no order number,
164
+ token, payment action, or transaction ID is exposed. `scene`, `metadata`, and
165
+ `testMode` are rejected or absent from the API.
166
+
167
+ The config `environment` remains server-authoritative. The SDK checks only that
168
+ `wrk_test_...` is paired with `SANDBOX` and `wrk_live_...` with `PRODUCTION`, and
169
+ rejects inconsistent responses.
170
+
171
+ The first Tip release is CN/CNY only. `region: 'global'` fails locally with
172
+ `CAPABILITY_DISABLED` without a config request or iframe. Anonymous Tip does not
173
+ use the legacy WeChat JSAPI user/OpenID path.
174
+
175
+ `TIP_CONFIG_INVALID` is a non-retryable Shop/SDK contract mismatch and should be
176
+ reported rather than retried. `TIP_OPEN_IN_PROGRESS` means the existing call
177
+ must settle first. `TIP_READY_TIMEOUT` is retryable after the failed call has
178
+ cleaned itself up. On every component or route unmount, call `tip.destroy()`
179
+ before `client.destroy()` so an in-flight flow settles as `UNKNOWN` and leaves
180
+ no portal or message listener behind.
181
+
182
+ Immutable exact-version CDN ESM exports the same implementation from
183
+ `<origin>/viceme-sdk/<version>/index.js` and `tip.js` without adding a `window`
184
+ global.
185
+
186
+ Use the scoped fake in components and Storybook:
187
+
188
+ ```ts
189
+ import { createTestTip } from '@viceme-ai/sdk/tip/testing';
190
+
191
+ const paid = createTestTip({ config, outcome: 'PAID' });
192
+ const failed = createTestTip({ config, outcome: new Error('fixture failure') });
193
+ ```
194
+
195
+ The config may also be an `Error`. `SANDBOX` is always supplied by server config
196
+ for a test Work, never by a production SDK switch.
@@ -29,10 +29,13 @@ export interface VicemeWidgetCloseDetail {
29
29
  workId: string;
30
30
  }
31
31
  export interface VicemeTipPaidDetail {
32
- workId: string;
33
- orderNo: string;
34
32
  status: 'PAID';
33
+ work: {
34
+ id: string;
35
+ title: string;
36
+ };
35
37
  amountCents: number;
38
+ currency: 'CNY';
36
39
  }
37
40
  export type VicemeEventType = 'viceme:ready' | 'viceme:capability-ready' | 'viceme:error' | 'viceme:destroyed' | 'viceme:widget-close' | 'viceme:tip-paid';
38
41
  export type VicemeEventDetailMap = {
@@ -1 +1 @@
1
- {"version":3,"file":"browser-events.d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AM,CAAC;CACpB;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC;CACjB;AAED,MAAM,MAAM,eAAe,GACvB,cAAc,GACd,yBAAyB,GACzB,cAAc,GACd,kBAAkB,GAClB,qBAAqB,GACrB,iBAAiB,CAAC;AAEtB,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,EAAE,iBAAiB,CAAC;IAClC,yBAAyB,EAAE,2BAA2B,CAAC;IACvD,cAAc,EAAE,iBAAiB,CAAC;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,CAgBvC;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,12 @@
1
+ const t = {
2
+ cn: "https://api.viceme.cn",
3
+ global: "https://api.viceme.ai"
4
+ }, c = {
5
+ cn: "https://viceme.cn",
6
+ global: "https://viceme.ai"
7
+ };
8
+ export {
9
+ c as B,
10
+ t as a
11
+ };
12
+ //# sourceMappingURL=build-endpoints-NrDmg6jf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-endpoints-NrDmg6jf.js","sources":["../../src/core/build-endpoints.ts"],"sourcesContent":["declare const __VICEME_BUILD_CN_API_BASE_URL__: string | undefined;\ndeclare const __VICEME_BUILD_GLOBAL_API_BASE_URL__: string | undefined;\ndeclare const __VICEME_BUILD_CN_WIDGET_ORIGIN__: string | undefined;\ndeclare const __VICEME_BUILD_GLOBAL_WIDGET_ORIGIN__: string | undefined;\n\n/** Public Shop API origins baked into immutable release artifacts. */\nexport const BUILD_API_BASE_URLS = {\n cn:\n typeof __VICEME_BUILD_CN_API_BASE_URL__ === 'string'\n ? __VICEME_BUILD_CN_API_BASE_URL__\n : 'https://api.viceme.cn',\n global:\n typeof __VICEME_BUILD_GLOBAL_API_BASE_URL__ === 'string'\n ? __VICEME_BUILD_GLOBAL_API_BASE_URL__\n : 'https://api.viceme.ai',\n} as const;\n\n/** Hosted Shop origins baked into immutable release artifacts. */\nexport const BUILD_WIDGET_ORIGINS = {\n cn:\n typeof __VICEME_BUILD_CN_WIDGET_ORIGIN__ === 'string'\n ? __VICEME_BUILD_CN_WIDGET_ORIGIN__\n : 'https://viceme.cn',\n global:\n typeof __VICEME_BUILD_GLOBAL_WIDGET_ORIGIN__ === 'string'\n ? __VICEME_BUILD_GLOBAL_WIDGET_ORIGIN__\n : 'https://viceme.ai',\n} as const;\n"],"names":["BUILD_API_BASE_URLS","BUILD_WIDGET_ORIGINS"],"mappings":"AAMO,MAAMA,IAAsB;AAAA,EACjC,IAEM;AAAA,EAEN,QAEM;AAER,GAGaC,IAAuB;AAAA,EAClC,IAEM;AAAA,EAEN,QAEM;AAER;"}