@statelyai/sdk 0.11.0 → 0.12.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
@@ -28,11 +28,35 @@ embed.init({
28
28
  });
29
29
  ```
30
30
 
31
+ Restrict an embed by passing a resolved access policy:
32
+
33
+ ```ts
34
+ embed.init({
35
+ machine: myMachineConfig,
36
+ mode: 'viewing',
37
+ readOnly: true,
38
+ capabilities: {
39
+ edit: false,
40
+ export: false,
41
+ ai: false,
42
+ simulate: false,
43
+ navigateHierarchy: false,
44
+ maxDepth: 1,
45
+ panels: ['structure', 'details', 'validations'],
46
+ },
47
+ });
48
+
49
+ embed.on('capabilityDenied', (event) => {
50
+ console.warn(event.message);
51
+ });
52
+ ```
53
+
31
54
  Key capabilities:
32
55
 
33
56
  - **Mount or attach** to any container element or existing iframe
34
57
  - **Two-way sync** - push machine configs in, get changes and saves back via event callbacks
35
58
  - **Export** to multiple formats: XState v5, XState JSON, Mermaid, Redux, Zustand, ASL, SCXML, and more
59
+ - **Access policies** for read-only, no-export, no-AI, shallow-viewer embeds
36
60
  - **Comments** via Liveblocks integration (optional)
37
61
  - **Asset uploads** with built-in S3 and Supabase adapters, or bring your own upload handler
38
62
  - **Runtime settings** - toggle color mode, grid, snap lines, autolayout, and view mode on the fly
@@ -69,7 +93,10 @@ Programmatic access to Stately Studio for managing projects and machines, extrac
69
93
  import { createStatelyClient } from '@statelyai/sdk';
70
94
 
71
95
  const studio = createStatelyClient({
72
- apiKey: process.env.STATELY_API_KEY,
96
+ credential: {
97
+ type: 'oauth',
98
+ accessToken: process.env.STATELY_ACCESS_TOKEN!,
99
+ },
73
100
  });
74
101
 
75
102
  const projects = await studio.projects.list();
@@ -77,6 +104,10 @@ const machine = await studio.machines.get('machine-id');
77
104
  const extracted = await studio.code.extractMachines(sourceCode);
78
105
  ```
79
106
 
107
+ Legacy `apiKey` is still accepted as an alias for
108
+ `credential: { type: 'api_key', token }`. Use `authMode: 'none'` only for
109
+ self-hosted deployments that intentionally accept unauthenticated calls.
110
+
80
111
  ### Inspector
81
112
 
82
113
  Stream live actor-system state to the Stately inspector over WebSockets, with support for automatic XState actor adoption and manual actor registration.
@@ -0,0 +1,15 @@
1
+ //#region src/auth.d.ts
2
+ type StatelyCredential = {
3
+ type: 'api_key';
4
+ token: string;
5
+ } | {
6
+ type: 'oauth';
7
+ accessToken: string;
8
+ refreshToken?: string;
9
+ expiresAt?: number;
10
+ };
11
+ type StatelyAuthMode = 'auto' | 'none' | 'bearer';
12
+ declare function getCredentialToken(credential: StatelyCredential | string | null | undefined): string | undefined;
13
+ declare function createAuthorizationHeader(credential: StatelyCredential | string): string;
14
+ //#endregion
15
+ export { getCredentialToken as i, StatelyCredential as n, createAuthorizationHeader as r, StatelyAuthMode as t };
@@ -0,0 +1,2 @@
1
+ import { i as getCredentialToken, n as StatelyCredential, r as createAuthorizationHeader, t as StatelyAuthMode } from "./auth-DO1-eQcU.mjs";
2
+ export { StatelyAuthMode, StatelyCredential, createAuthorizationHeader, getCredentialToken };
package/dist/auth.mjs ADDED
@@ -0,0 +1,11 @@
1
+ //#region src/auth.ts
2
+ function getCredentialToken(credential) {
3
+ if (!credential) return;
4
+ return typeof credential === "string" ? credential : credential.type === "oauth" ? credential.accessToken : credential.token;
5
+ }
6
+ function createAuthorizationHeader(credential) {
7
+ return `Bearer ${getCredentialToken(credential)}`;
8
+ }
9
+
10
+ //#endregion
11
+ export { createAuthorizationHeader, getCredentialToken };