@neta-art/cohub 8.0.0 → 8.1.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.
- package/README.md +3 -3
- package/dist/chunks/http.d.ts +68 -9
- package/dist/chunks/http.js +67 -1
- package/dist/chunks/transport.js +2 -1
- package/dist/chunks/websocket.d.ts +14 -6
- package/dist/http.d.ts +3 -3
- package/dist/http.js +2 -2
- package/dist/index.d.ts +43 -14
- package/dist/index.js +387 -95
- package/docs/work-runtime-guide.md +17 -17
- package/package.json +1 -1
|
@@ -62,8 +62,8 @@ Four runtime-only APIs form the foundation; everything else is standard SDK:
|
|
|
62
62
|
|---|---|---|
|
|
63
63
|
| `client.context()` | Asks the host for the Work's identity | `{ work, space, viewer?, permissions }` or `null` |
|
|
64
64
|
| `client.auth.request({ scopes, reason })` | Requests viewer authorization and caches a scoped token; Cohub may silently approve the publisher's own workspace preview or background | `true` / `false` |
|
|
65
|
-
| `client.
|
|
66
|
-
| `client.
|
|
65
|
+
| `client.app.commerce.*` | Entitlement checks, credit consumption, purchases | (see Commerce section) |
|
|
66
|
+
| `client.app.realtime.*` | Temporary rooms, events, presence, and membership | (see Realtime rooms section) |
|
|
67
67
|
|
|
68
68
|
> **Runtime-only constraint.** These APIs only work inside a **published**
|
|
69
69
|
> Work. Outside that context (a static asset URL, a local `file://` preview,
|
|
@@ -235,10 +235,10 @@ from viewer authorization checked against the requested Space or Session.
|
|
|
235
235
|
| List viewer's spaces | `client.spaces.list()` | `user.space.list` | viewer |
|
|
236
236
|
| List viewer's sessions | `client.user.listSessions()` | `user.session.list` | viewer |
|
|
237
237
|
| Read viewer's activity | `client.user.getActivity()` | `user.usage.read` | viewer |
|
|
238
|
-
| Commerce: entitlements | `client.
|
|
239
|
-
| Commerce: consume credits | `client.
|
|
240
|
-
| Commerce: purchase | `client.
|
|
241
|
-
| Realtime rooms | `client.
|
|
238
|
+
| Commerce: entitlements | `client.app.commerce.getEntitlements()` | *(runtime only, no scope)* | — |
|
|
239
|
+
| Commerce: consume credits | `client.app.commerce.consumeCredits()` | *(runtime only, no scope)* | — |
|
|
240
|
+
| Commerce: purchase | `client.app.commerce.purchase()` | *(runtime only, no scope)* | — |
|
|
241
|
+
| Realtime rooms | `client.app.realtime.createRoom()` / `joinRoom()` | *(runtime only, no scope)* | — |
|
|
242
242
|
|
|
243
243
|
### Minimal scope sets for common Work types
|
|
244
244
|
|
|
@@ -649,29 +649,29 @@ in a published Work.
|
|
|
649
649
|
|
|
650
650
|
```js
|
|
651
651
|
// Check entitlements and credit balance in one call
|
|
652
|
-
const { entitlements, credits } = await client.
|
|
652
|
+
const { entitlements, credits } = await client.app.commerce.getEntitlements();
|
|
653
653
|
|
|
654
654
|
// Feature unlock: purchase if not entitled
|
|
655
655
|
const unlocked = entitlements.some(e => e.benefitKey === "space_pro" && e.enabled);
|
|
656
656
|
if (!unlocked) {
|
|
657
|
-
await client.
|
|
657
|
+
await client.app.commerce.purchase({ productKey: "pro_unlock" });
|
|
658
658
|
// purchase() redirects to checkout; after return, re-check entitlements
|
|
659
659
|
}
|
|
660
660
|
|
|
661
661
|
// Credit consumption for a metered action
|
|
662
|
-
const result = await client.
|
|
662
|
+
const result = await client.app.commerce.consumeCredits({
|
|
663
663
|
amount: 10,
|
|
664
664
|
operationId: crypto.randomUUID(), // idempotency key
|
|
665
665
|
reason: "Export high-res image",
|
|
666
666
|
});
|
|
667
667
|
if (result.status === "insufficient") {
|
|
668
|
-
await client.
|
|
668
|
+
await client.app.commerce.purchase({ productKey: "credit_pack" });
|
|
669
669
|
}
|
|
670
670
|
|
|
671
671
|
// After checkout return, query the order
|
|
672
|
-
const checkoutState = await client.
|
|
672
|
+
const checkoutState = await client.app.commerce.getCheckoutState();
|
|
673
673
|
if (checkoutState.orderId) {
|
|
674
|
-
const { order } = await client.
|
|
674
|
+
const { order } = await client.app.commerce.getOrder(checkoutState.orderId);
|
|
675
675
|
}
|
|
676
676
|
```
|
|
677
677
|
|
|
@@ -686,7 +686,7 @@ additional consent dialog. The CLI and ordinary server auth cannot create or
|
|
|
686
686
|
join these rooms.
|
|
687
687
|
|
|
688
688
|
```js
|
|
689
|
-
const room = await client.
|
|
689
|
+
const room = await client.app.realtime.createRoom({
|
|
690
690
|
code: "TEAM-ALPHA", // optional; generated when omitted
|
|
691
691
|
maxParticipants: 64,
|
|
692
692
|
expiresInSeconds: 2 * 60 * 60,
|
|
@@ -709,7 +709,7 @@ await room.leave();
|
|
|
709
709
|
```
|
|
710
710
|
|
|
711
711
|
Join an existing room with
|
|
712
|
-
`client.
|
|
712
|
+
`client.app.realtime.joinRoom({ code: "TEAM-ALPHA" })`. Codes are scoped to
|
|
713
713
|
one Work and are identifiers, not credentials; the runtime session and a
|
|
714
714
|
short-lived admission ticket provide authorization.
|
|
715
715
|
|
|
@@ -776,7 +776,7 @@ letting an application group connections without seeing the account ID.
|
|
|
776
776
|
Set `seatPerUser: true` when each viewer should occupy at most one seat:
|
|
777
777
|
|
|
778
778
|
```js
|
|
779
|
-
const room = await client.
|
|
779
|
+
const room = await client.app.realtime.createRoom({
|
|
780
780
|
maxParticipants: 2,
|
|
781
781
|
seatPerUser: true,
|
|
782
782
|
});
|
|
@@ -797,7 +797,7 @@ acknowledgement immediately:
|
|
|
797
797
|
```js
|
|
798
798
|
let activeCommandId = null;
|
|
799
799
|
|
|
800
|
-
client.
|
|
800
|
+
client.app.surface.handle("image.open", async (input, { commandId }) => {
|
|
801
801
|
if (!commandId) throw new Error("image.open must be called by a UI command");
|
|
802
802
|
activeCommandId = commandId;
|
|
803
803
|
openImageStudio(input);
|
|
@@ -817,7 +817,7 @@ async function useImage(result) {
|
|
|
817
817
|
|
|
818
818
|
The Work should persist the command id alongside its local/server-backed draft
|
|
819
819
|
so a reload can restore the pending interaction. A Work session may only report a command that targets that same Work. Existing
|
|
820
|
-
`client.
|
|
820
|
+
`client.app.surface.handle(method, handler)` usage remains unchanged.
|
|
821
821
|
|
|
822
822
|
---
|
|
823
823
|
|