@viceme-ai/sdk 0.2.0 → 0.3.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 (44) hide show
  1. package/README.md +49 -45
  2. package/dist/chunks/client-DKsaEtwq.js +941 -0
  3. package/dist/chunks/client-DKsaEtwq.js.map +1 -0
  4. package/dist/chunks/version-C3KVoLNb.js +51 -0
  5. package/dist/chunks/version-C3KVoLNb.js.map +1 -0
  6. package/dist/core/build-endpoints.d.ts +4 -1
  7. package/dist/core/build-endpoints.d.ts.map +1 -1
  8. package/dist/core/capabilities.d.ts +79 -0
  9. package/dist/core/capabilities.d.ts.map +1 -0
  10. package/dist/core/client.d.ts +34 -8
  11. package/dist/core/client.d.ts.map +1 -1
  12. package/dist/core/config.d.ts +14 -4
  13. package/dist/core/config.d.ts.map +1 -1
  14. package/dist/core/errors.d.ts +1 -1
  15. package/dist/core/errors.d.ts.map +1 -1
  16. package/dist/core/lifecycle.d.ts +4 -2
  17. package/dist/core/lifecycle.d.ts.map +1 -1
  18. package/dist/core/presentation.d.ts +24 -0
  19. package/dist/core/presentation.d.ts.map +1 -0
  20. package/dist/danmaku.js +44 -48
  21. package/dist/danmaku.js.map +1 -1
  22. package/dist/generated/public-contract.d.ts +617 -13
  23. package/dist/generated/public-contract.d.ts.map +1 -1
  24. package/dist/index.d.ts +8 -4
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +112 -95
  27. package/dist/index.js.map +1 -1
  28. package/dist/manifest.json +30 -18
  29. package/dist/session/session.d.ts +67 -0
  30. package/dist/session/session.d.ts.map +1 -0
  31. package/dist/testing/test-adapter.d.ts +59 -0
  32. package/dist/testing/test-adapter.d.ts.map +1 -0
  33. package/dist/testing.d.ts +9 -0
  34. package/dist/testing.d.ts.map +1 -0
  35. package/dist/testing.js +75 -0
  36. package/dist/testing.js.map +1 -0
  37. package/dist/transport/transport.d.ts +44 -0
  38. package/dist/transport/transport.d.ts.map +1 -0
  39. package/dist/version.d.ts +1 -1
  40. package/dist/viceme.min.js +232 -1
  41. package/dist/viceme.min.js.map +1 -1
  42. package/package.json +6 -2
  43. package/dist/chunks/version-BbUa2jZV.js +0 -38
  44. package/dist/chunks/version-BbUa2jZV.js.map +0 -1
package/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # @viceme-ai/sdk
2
2
 
3
- PUBLIC-only ViceMe browser SDK for the Shop-hosted danmaku overlay.
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.
4
6
 
5
7
  ## Install
6
8
 
@@ -8,61 +10,63 @@ PUBLIC-only ViceMe browser SDK for the Shop-hosted danmaku overlay.
8
10
  pnpm add @viceme-ai/sdk
9
11
  ```
10
12
 
11
- ## Static HTML
12
-
13
- ```html
14
- <script
15
- defer
16
- src="https://viceme.cn/viceme-sdk/v1/viceme.min.js"
17
- data-viceme-work="wrk_public_xxx"
18
- data-viceme-region="cn"
19
- data-viceme-features="danmaku"
20
- data-viceme-target="body"
21
- data-viceme-theme="auto"
22
- ></script>
23
- ```
24
-
25
- The feature declaration must be exactly `danmaku`.
26
-
27
- 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.
31
-
32
- With CSP, allow the exact regional Shop origin in `script-src`, `connect-src`,
33
- and `frame-src`, and keep `object-src 'none'`. A nonce with `'strict-dynamic'`
34
- may authorize dynamic scripts, but `connect-src` and `frame-src` still need the
35
- exact origin. Do not use `*` or a ViceMe subdomain wildcard.
36
-
37
- ## ESM
13
+ ## Usage
38
14
 
39
15
  ```ts
40
16
  import { createViceMe } from '@viceme-ai/sdk';
41
- import { mountDanmaku } from '@viceme-ai/sdk/danmaku';
42
17
 
43
18
  const client = createViceMe({ workKey: 'wrk_public_xxx', region: 'cn' });
44
19
  await client.ready();
45
20
 
46
- const mounted = await mountDanmaku(client, {
47
- target: document.body,
48
- theme: 'auto',
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');
25
+
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();
50
35
 
51
- mounted.destroy();
52
36
  client.destroy();
53
37
  ```
54
38
 
55
- Run those cleanup calls from the owning component's unmount path or another
56
- explicit lifecycle boundary, not from `pagehide` (which also covers bfcache).
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.
57
52
 
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
60
- internal SDK to read and create anonymous messages through
61
- `/v1/danmaku/messages`.
53
+ Static HTML sites can use the CDN auto-loader instead see the
54
+ [repository README](https://github.com/ViceMe-AI/sdk).
62
55
 
63
- There is no public SDK Session, Bearer token, auth, follow, access, purchase,
64
- or checkout surface, and no `@viceme-ai/sdk/testing` subpath.
56
+ ## Testing your integration
57
+
58
+ ```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();
69
+ ```
65
70
 
66
- The danmaku mount hashes the canonical page URL locally, combines it with a 10%
67
- scroll bucket, and sends only the opaque anchor to the hosted iframe. Destroying
68
- the mount removes its nodes, listeners, debounce timer, and location poll.
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.