@viceme-ai/sdk 0.4.0 → 0.6.1

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 (55) hide show
  1. package/README.md +105 -16
  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-w9vih8Ng.js} +267 -238
  7. package/dist/chunks/client-w9vih8Ng.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-uPTHb89K.js +6 -0
  13. package/dist/chunks/{version-C8DeBm39.js.map → version-uPTHb89K.js.map} +1 -1
  14. package/dist/core/capabilities.d.ts +2 -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.map +1 -1
  22. package/dist/danmaku.js +5 -4
  23. package/dist/danmaku.js.map +1 -1
  24. package/dist/generated/public-contract.d.ts +108 -1
  25. package/dist/generated/public-contract.d.ts.map +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +4 -4
  28. package/dist/index.js.map +1 -1
  29. package/dist/manifest.json +49 -37
  30. package/dist/testing.js +14 -14
  31. package/dist/testing.js.map +1 -1
  32. package/dist/tip/headless.d.ts +4 -0
  33. package/dist/tip/headless.d.ts.map +1 -0
  34. package/dist/tip/index.d.ts +47 -2
  35. package/dist/tip/index.d.ts.map +1 -1
  36. package/dist/tip/mount.d.ts.map +1 -1
  37. package/dist/tip/testing.d.ts +9 -0
  38. package/dist/tip/testing.d.ts.map +1 -0
  39. package/dist/tip/testing.js +43 -0
  40. package/dist/tip/testing.js.map +1 -0
  41. package/dist/tip/validation.d.ts +7 -0
  42. package/dist/tip/validation.d.ts.map +1 -0
  43. package/dist/tip.js +419 -84
  44. package/dist/tip.js.map +1 -1
  45. package/dist/version.d.ts +1 -1
  46. package/dist/viceme.min.js +5 -2
  47. package/dist/viceme.min.js.map +1 -1
  48. package/package.json +7 -6
  49. package/dist/bootstrap.min.js +0 -2
  50. package/dist/bootstrap.min.js.map +0 -1
  51. package/dist/chunks/client-Cbldd7F2.js.map +0 -1
  52. package/dist/chunks/errors-B-Qv_azy.js.map +0 -1
  53. package/dist/chunks/version-C8DeBm39.js +0 -6
  54. package/dist/loader/bootstrap.d.ts +0 -1
  55. package/dist/loader/bootstrap.d.ts.map +0 -1
package/README.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ViceMe browser SDK for Shop-hosted engagement and origin-bound Website Work access.
4
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.
10
+
5
11
  ## Install
6
12
 
7
13
  ```bash
@@ -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,25 @@ 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
+
90
+ Website access login renders the work-bound WeChat QR code directly in the SDK
91
+ layer. Paid access keeps desktop QR payment and WeChat JSAPI in that layer;
92
+ mobile H5/WAP payment may open a provider page or app. The original page polls
93
+ the server-authoritative access decision and closes the layer after entitlement
94
+ is active. This behavior does not change the separate Tip Widget flow.
78
95
 
79
96
  ```ts
80
97
  const decisions = await client.access.checkMany(['members', 'pro-tools']);
@@ -85,6 +102,8 @@ if (!decisions['pro-tools']?.allowed) {
85
102
 
86
103
  The Tip subpath exports `TipPaidDetail` and `TipWidgetCloseDetail` for the
87
104
  sanitized `viceme:tip-paid` and `viceme:widget-close` `CustomEvent` details.
105
+ `TipPaidDetail` contains only `status`, trusted `work.id/title`, amount, and CNY;
106
+ it contains no key, provider, order number, token, or transaction identifier.
88
107
 
89
108
  The danmaku mount hashes the canonical page URL locally, combines it with a 10%
90
109
  scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
@@ -95,3 +114,73 @@ interaction only after a trusted resize handshake. Shop resets its hosted
95
114
  payment surface on Escape before sending close; the SDK forwards sanitized
96
115
  close and paid notifications, and removes its iframe, timer, media listener,
97
116
  and message listener on destroy.
117
+
118
+ ## Headless Tip
119
+
120
+ This additive API targets `0.5.0`. Do not expect `createTip` or
121
+ `@viceme-ai/sdk/tip/testing` from the immutable npm `0.4.0` package.
122
+
123
+ ```ts
124
+ import { createViceMe } from '@viceme-ai/sdk';
125
+ import { createTip } from '@viceme-ai/sdk/tip';
126
+
127
+ const client = createViceMe({ workKey: 'wrk_live_demo', region: 'cn' });
128
+ const tip = createTip(client);
129
+ const config = await tip.getConfig();
130
+
131
+ button.addEventListener('click', async () => {
132
+ const result = await tip.open({
133
+ amountCents: config.amount.minCents,
134
+ provider: config.providers[0],
135
+ locale: 'zh-CN',
136
+ appearance: 'auto',
137
+ });
138
+ console.log(result.status);
139
+ });
140
+
141
+ function destroyTip() {
142
+ tip.destroy();
143
+ client.destroy();
144
+ }
145
+ ```
146
+
147
+ Call `destroyTip()` from the owning component or route cleanup. Do not bind it
148
+ to `pagehide`, because that event also fires when a page enters the bfcache.
149
+
150
+ `getConfig()` strictly parses the credential-free regional
151
+ `GET /v1/work-sdk/<encoded-workKey>/tip-config` response. Call `open()` directly
152
+ from user activation so it can create its secure full-screen frame in the same
153
+ call stack. Only `PAID`, `CANCELLED`, and `UNKNOWN` cross back; no order number,
154
+ token, payment action, or transaction ID is exposed. `scene`, `metadata`, and
155
+ `testMode` are rejected or absent from the API.
156
+
157
+ The config `environment` remains server-authoritative. The SDK checks only that
158
+ `wrk_test_...` is paired with `SANDBOX` and `wrk_live_...` with `PRODUCTION`, and
159
+ rejects inconsistent responses.
160
+
161
+ The first Tip release is CN/CNY only. `region: 'global'` fails locally with
162
+ `CAPABILITY_DISABLED` without a config request or iframe. Anonymous Tip does not
163
+ use the legacy WeChat JSAPI user/OpenID path.
164
+
165
+ `TIP_CONFIG_INVALID` is a non-retryable Shop/SDK contract mismatch and should be
166
+ reported rather than retried. `TIP_OPEN_IN_PROGRESS` means the existing call
167
+ must settle first. `TIP_READY_TIMEOUT` is retryable after the failed call has
168
+ cleaned itself up. On every component or route unmount, call `tip.destroy()`
169
+ before `client.destroy()` so an in-flight flow settles as `UNKNOWN` and leaves
170
+ no portal or message listener behind.
171
+
172
+ Immutable exact-version CDN ESM exports the same implementation from
173
+ `<origin>/viceme-sdk/<version>/index.js` and `tip.js` without adding a `window`
174
+ global.
175
+
176
+ Use the scoped fake in components and Storybook:
177
+
178
+ ```ts
179
+ import { createTestTip } from '@viceme-ai/sdk/tip/testing';
180
+
181
+ const paid = createTestTip({ config, outcome: 'PAID' });
182
+ const failed = createTestTip({ config, outcome: new Error('fixture failure') });
183
+ ```
184
+
185
+ The config may also be an `Error`. `SANDBOX` is always supplied by server config
186
+ 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.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,EA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E,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;"}