@shuffl/sdk 0.4.0 → 0.5.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.
package/README.md CHANGED
@@ -10,7 +10,7 @@ The package is ESM-only and ships its own types. It installs `@shuffl/api-contra
10
10
 
11
11
  Create an API key in **Settings → API keys**. The key is bound to one team and the issuing user's current permissions, and expires within 30 days. There is one kind of API key: the same key works for the SDK, CLI, HTTP API and, when it carries the `mcp.knowledge` permission, the MCP server.
12
12
 
13
- Choose exact endpoint permissions such as `users.list` and `units.save`, grouped by resource and Read/Write. Discover them with `shuffl.permissions.list()`. A write grant does not imply reads or sibling operations. See [endpoint permissions and delegation](https://shuffl-rebuild.vercel.app/docs/api-permissions).
13
+ Choose exact endpoint permissions such as `users.list` and `groups.save`, grouped by resource and Read/Write. Discover them with `shuffl.permissions.list()`. A write grant does not imply reads or sibling operations. See [endpoint permissions and delegation](https://shuffl-rebuild.vercel.app/docs/api-permissions).
14
14
 
15
15
  ```ts
16
16
  import { createShuffl } from '@shuffl/sdk';
@@ -45,15 +45,42 @@ createShuffl({ baseUrl, token: async () => credentialStore.read() });
45
45
 
46
46
  Use `ORPCError.code` for errors (`UNAUTHORIZED`, `FORBIDDEN`, `BAD_REQUEST`, `NOT_FOUND`, `CONFLICT`, and others). Calls accept oRPC's second options argument, including an abort signal. HTTPS is required except on loopback; redirects are refused to avoid forwarding credentials to another origin. The public API currently allows same-origin browser calls and server/CLI clients; cross-origin browser CORS is not enabled.
47
47
 
48
+ ## Webhooks
49
+
50
+ Shuffl can call your HTTPS endpoint when something happens in a workspace (#643). Add an endpoint in Settings → Webhooks or with `webhooks.create`, keep the `whsec_…` signing secret it returns, and check every delivery against it before you trust it. Pass the raw body, before any JSON parsing:
51
+
52
+ ```ts
53
+ import { verifyWebhook, WebhookVerificationError } from '@shuffl/sdk';
54
+
55
+ export async function POST(request: Request) {
56
+ const body = await request.text();
57
+ try {
58
+ const event = await verifyWebhook({
59
+ body,
60
+ headers: request.headers,
61
+ secret: process.env.SHUFFL_WEBHOOK_SECRET!,
62
+ });
63
+ if (event.type === 'knowledge.document.published')
64
+ console.log(event.data.document_id);
65
+ return new Response(null, { status: 204 });
66
+ } catch (error) {
67
+ if (error instanceof WebhookVerificationError)
68
+ return new Response('Bad signature', { status: 400 });
69
+ throw error;
70
+ }
71
+ }
72
+ ```
73
+
74
+ Deliveries follow [Standard Webhooks](https://www.standardwebhooks.com/), so their libraries for other languages work too. `event.id` stays the same across retries and resends; use it to drop duplicates. Payloads carry ids, statuses and counts only; read anything more through the API. `webhookEventCatalog` lists every event type with its group and the fields its `data` may carry. While a secret is rolled, pass both secrets as an array.
75
+
48
76
  ## Management commands
49
77
 
50
78
  ```ts
51
- const saved = await shuffl.units.save({
52
- id: crypto.randomUUID(), kind: 'team', name: 'Mentors',
53
- expectedRevision: 0, requestKey: 'create-mentors-2026-09',
79
+ const saved = await shuffl.groups.save({
80
+ kind: 'list', name: 'Mentors', requestKey: 'create-mentors-2026-09',
54
81
  });
55
82
  const receipt = await shuffl.commands.get({ id: saved.receipt.id });
56
- const teams = await shuffl.units.list({}); // Same persisted teams the web app reads.
83
+ const groups = await shuffl.groups.list({}); // Same groups the web app reads.
57
84
  ```
58
85
 
59
86
  Management writes return `{receipt, result}`. A duplicate request returns the same receipt with `result: null`; it never replays an action or a private result. Reusing a key with changed input fails. Read the resource after replay and reconcile an `unknown` receipt before issuing a new command. Sensitive actions require `confirm` equal to the method name (for example `knowledge.sources.publish`). Initial program/run methods retain the shapes described above.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { ShufflContract } from '@shuffl/api-contracts';
3
3
  import { type ShufflCompanyContract } from '@shuffl/api-contracts/company';
4
4
  export { ORPCError } from '@orpc/client';
5
5
  export type { CompanyPermission, Permission, PermissionDefinition, Scope, } from '@shuffl/api-contracts';
6
+ export { isWebhookEventType, signWebhook, verifyWebhook, type WebhookActor, type WebhookEvent, type WebhookEventData, type WebhookEventGroup, type WebhookEventType, WebhookVerificationError, webhookApiVersion, webhookEventCatalog, webhookEventGroups, webhookEventTypes, } from '@shuffl/api-contracts/webhooks';
6
7
  export type ShufflClient = ContractRouterClient<ShufflContract>;
7
8
  /** The company API (#1692), for a company key (shuffl_company_). */
8
9
  export type ShufflCompanyClient = ContractRouterClient<ShufflCompanyContract>;
package/dist/index.js CHANGED
@@ -3,6 +3,8 @@ import { RPCLink } from '@orpc/client/fetch';
3
3
  import { isContractProcedure } from '@orpc/contract';
4
4
  import { companyContract, } from '@shuffl/api-contracts/company';
5
5
  export { ORPCError } from '@orpc/client';
6
+ // #643: check and type the webhooks Shuffl sends.
7
+ export { isWebhookEventType, signWebhook, verifyWebhook, WebhookVerificationError, webhookApiVersion, webhookEventCatalog, webhookEventGroups, webhookEventTypes, } from '@shuffl/api-contracts/webhooks';
6
8
  function origin(baseUrl) {
7
9
  const base = new URL(baseUrl);
8
10
  if (base.username ||
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "dependencies": {
3
3
  "@orpc/client": "1.15.3",
4
4
  "@orpc/contract": "1.15.3",
5
- "@shuffl/api-contracts": "0.4.0"
5
+ "@shuffl/api-contracts": "0.5.1"
6
6
  },
7
7
  "description": "TypeScript client for the Shuffl API: people, teams, knowledge, programs and management commands.",
8
8
  "engines": {
@@ -34,5 +34,5 @@
34
34
  "sideEffects": false,
35
35
  "type": "module",
36
36
  "types": "./dist/index.d.ts",
37
- "version": "0.4.0"
37
+ "version": "0.5.1"
38
38
  }