@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.
@@ -18,6 +18,25 @@ interface ValidationIssue {
18
18
  level: "info" | "warning" | "error";
19
19
  message: string;
20
20
  }
21
+ interface EditorCapabilities {
22
+ edit?: boolean;
23
+ export?: boolean;
24
+ ai?: boolean;
25
+ simulate?: boolean;
26
+ inspect?: boolean;
27
+ navigateHierarchy?: boolean;
28
+ maxDepth?: number;
29
+ panels?: string[];
30
+ commands?: string[];
31
+ }
32
+ type CapabilityDeniedCapability = "edit" | "export" | "ai" | "simulate" | "inspect" | "navigateHierarchy" | "panel" | "mode";
33
+ interface CapabilityDeniedEvent {
34
+ capability: CapabilityDeniedCapability;
35
+ action: "openPanel" | "openDialog" | "editSource" | "navigateHierarchy" | "setMode" | "simulationStart" | "inspectStart" | "retrieve";
36
+ requested?: string;
37
+ message: string;
38
+ dedupeKey: string;
39
+ }
21
40
  interface SourceRange {
22
41
  startLine: number;
23
42
  startChar: number;
@@ -142,6 +161,7 @@ interface EmbedEventMap {
142
161
  code: string;
143
162
  message: string;
144
163
  };
164
+ capabilityDenied: CapabilityDeniedEvent;
145
165
  snapshot: {
146
166
  snapshot: unknown;
147
167
  event: unknown | null;
@@ -159,6 +179,7 @@ interface MachineInitOptions {
159
179
  theme?: "light" | "dark";
160
180
  readOnly?: boolean;
161
181
  depth?: number;
182
+ capabilities?: EditorCapabilities;
162
183
  panels?: {
163
184
  leftPanels?: string[];
164
185
  rightPanels?: string[];
@@ -191,6 +212,7 @@ interface ProjectInitOptions {
191
212
  theme?: "light" | "dark";
192
213
  readOnly?: boolean;
193
214
  depth?: number;
215
+ capabilities?: EditorCapabilities;
194
216
  panels?: {
195
217
  leftPanels?: string[];
196
218
  rightPanels?: string[];
@@ -212,6 +234,7 @@ interface InitMessage {
212
234
  theme?: "light" | "dark";
213
235
  readOnly?: boolean;
214
236
  depth?: number;
237
+ capabilities?: EditorCapabilities;
215
238
  leftPanels?: string[];
216
239
  rightPanels?: string[];
217
240
  activePanels?: string[];
@@ -234,6 +257,7 @@ interface ProjectInitMessage {
234
257
  theme?: "light" | "dark";
235
258
  readOnly?: boolean;
236
259
  depth?: number;
260
+ capabilities?: EditorCapabilities;
237
261
  leftPanels?: string[];
238
262
  rightPanels?: string[];
239
263
  activePanels?: string[];
@@ -317,6 +341,7 @@ interface SystemInitMessage {
317
341
  theme?: "light" | "dark";
318
342
  readOnly?: boolean;
319
343
  depth?: number;
344
+ capabilities?: EditorCapabilities;
320
345
  leftPanels?: string[];
321
346
  rightPanels?: string[];
322
347
  activePanels?: string[];
@@ -387,6 +412,9 @@ interface ErrorMessage {
387
412
  message: string;
388
413
  requestId?: string;
389
414
  }
415
+ interface CapabilityDeniedMessage extends CapabilityDeniedEvent {
416
+ type: "@statelyai.capabilityDenied";
417
+ }
390
418
  /** File metadata sent from viz to SDK when a file needs uploading. */
391
419
  interface UploadFileInfo {
392
420
  /** Original filename (e.g. "screenshot.png") */
@@ -430,7 +458,7 @@ interface UploadResponseMessage {
430
458
  /** All messages a client (embed/inspector) can send to the viz. */
431
459
  type ClientMessage = InitMessage | ProjectInitMessage | ProjectUpdateMessage | ProjectSelectMachineMessage | UpdateMessage | SetModeMessage | SetThemeMessage | SetSettingsMessage | RetrieveMessage | ToastMessage | InspectSnapshotMessage | SystemInitMessage | SystemActorRegisteredMessage | SystemActorSnapshotMessage | SystemActorStoppedMessage | UploadCapabilitiesMessage | UploadResponseMessage | ErrorMessage;
432
460
  /** All messages the viz can send back to a client. */
433
- type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | UploadRequestMessage;
461
+ type VizMessage = ReadyMessage | LoadedMessage | ChangeMessage | SaveMessage | ProjectMachineSelectedMessage | RetrievedMessage | ErrorMessage | CapabilityDeniedMessage | UploadRequestMessage;
434
462
  interface RegisterMessage {
435
463
  type: "@statelyai.register";
436
464
  role: "client" | "viz";
@@ -478,4 +506,4 @@ type SessionMessage = RegisterMessage | RegisteredMessage | RequestOpenMessage |
478
506
  type ProtocolMessage = ClientMessage | VizMessage | SessionMessage;
479
507
  declare const PREFIX = "@statelyai.";
480
508
  //#endregion
481
- export { ActorSystemEntry, AddSessionMessage, ChangeMessage, ClientMessage, CommentsConfig, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ErrorMessage, ExportCallOptions, ExportFormat, ExportFormatMap, InitMessage, InitOptions, InspectSnapshotMessage, LoadedMessage, MachineInitOptions, MachineSourceLocations, PREFIX, ProjectEmbedMachine, ProjectInitMessage, ProjectInitOptions, ProjectMachineSelectedMessage, ProjectSelectMachineMessage, ProjectUpdateMessage, ProtocolMessage, ReadyMessage, RegisterMessage, RegisteredMessage, RequestOpenMessage, RetrieveMessage, RetrievedMessage, SaveMessage, SessionAddedMessage, SessionMessage, SetModeMessage, SetSettingsMessage, SetThemeMessage, SourceLocation, SourceRange, StateSourceLocation, SystemActorRegisteredMessage, SystemActorSnapshotMessage, SystemActorStoppedMessage, SystemInitMessage, ToastMessage, UpdateMessage, UploadCapabilitiesMessage, UploadFileInfo, UploadRequestMessage, UploadResponseMessage, UploadResult, ValidationIssue, VizMessage };
509
+ export { ActorSystemEntry, AddSessionMessage, CapabilityDeniedCapability, CapabilityDeniedEvent, CapabilityDeniedMessage, ChangeMessage, ClientMessage, CommentsConfig, EditorCapabilities, EmbedEventHandler, EmbedEventMap, EmbedEventName, EmbedMode, ErrorMessage, ExportCallOptions, ExportFormat, ExportFormatMap, InitMessage, InitOptions, InspectSnapshotMessage, LoadedMessage, MachineInitOptions, MachineSourceLocations, PREFIX, ProjectEmbedMachine, ProjectInitMessage, ProjectInitOptions, ProjectMachineSelectedMessage, ProjectSelectMachineMessage, ProjectUpdateMessage, ProtocolMessage, ReadyMessage, RegisterMessage, RegisteredMessage, RequestOpenMessage, RetrieveMessage, RetrievedMessage, SaveMessage, SessionAddedMessage, SessionMessage, SetModeMessage, SetSettingsMessage, SetThemeMessage, SourceLocation, SourceRange, StateSourceLocation, SystemActorRegisteredMessage, SystemActorSnapshotMessage, SystemActorStoppedMessage, SystemInitMessage, ToastMessage, UpdateMessage, UploadCapabilitiesMessage, UploadFileInfo, UploadRequestMessage, UploadResponseMessage, UploadResult, ValidationIssue, VizMessage };
package/dist/studio.d.mts CHANGED
@@ -1,7 +1,12 @@
1
+ import { n as StatelyCredential, t as StatelyAuthMode } from "./auth-DO1-eQcU.mjs";
2
+
1
3
  //#region src/studio.d.ts
2
4
  interface StudioClientOptions {
3
5
  baseUrl?: string;
6
+ credential?: StatelyCredential;
7
+ /** @deprecated Use credential: { type: 'api_key', token }. */
4
8
  apiKey?: string;
9
+ authMode?: StatelyAuthMode;
5
10
  fetch?: typeof fetch;
6
11
  }
7
12
  interface VerifyApiKeyResponse {
@@ -93,7 +98,7 @@ declare class StudioApiError extends Error {
93
98
  }
94
99
  interface StudioClient {
95
100
  auth: {
96
- verify(apiKey?: string): Promise<VerifyApiKeyResponse>;
101
+ verify(credential?: StatelyCredential | string): Promise<VerifyApiKeyResponse>;
97
102
  };
98
103
  projects: {
99
104
  list(): Promise<ProjectData[]>;
@@ -109,7 +114,9 @@ interface StudioClient {
109
114
  };
110
115
  code: {
111
116
  extractMachines(code: string, options?: {
117
+ credential?: StatelyCredential | null; /** @deprecated Use credential. */
112
118
  apiKey?: string | null;
119
+ authMode?: StatelyAuthMode;
113
120
  }): Promise<ExtractMachinesResponse>;
114
121
  };
115
122
  }
package/dist/studio.mjs CHANGED
@@ -1,3 +1,5 @@
1
+ import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
2
+
1
3
  //#region src/studio.ts
2
4
  var StudioApiError = class extends Error {
3
5
  status;
@@ -79,10 +81,19 @@ function connectedReposMatch(left, right) {
79
81
  function createStatelyClient(options = {}) {
80
82
  const baseUrl = options.baseUrl ?? "https://stately.ai";
81
83
  const fetchImpl = getFetch(options.fetch);
82
- async function request(path, init = {}, apiKeyOverride) {
84
+ const defaultCredential = options.credential ?? (options.apiKey ? {
85
+ type: "api_key",
86
+ token: options.apiKey
87
+ } : void 0);
88
+ const defaultAuthMode = options.authMode ?? "auto";
89
+ async function request(path, init = {}, credentialOverride, authModeOverride) {
83
90
  const headers = new Headers(init.headers);
84
- const apiKey = apiKeyOverride ?? options.apiKey;
85
- if (apiKey) headers.set("Authorization", `Bearer ${apiKey}`);
91
+ const authMode = authModeOverride ?? defaultAuthMode;
92
+ const credential = credentialOverride ?? defaultCredential;
93
+ if (authMode !== "none") {
94
+ if (!getCredentialToken(credential) || !credential) throw new StudioApiError("No Stately credential configured. Pass createStatelyClient({ credential }) or set authMode: \"none\" for no-auth self-hosted deployments.", 401);
95
+ headers.set("Authorization", createAuthorizationHeader(credential));
96
+ }
86
97
  const response = await fetchImpl(joinApiUrl(baseUrl, path), {
87
98
  ...init,
88
99
  headers
@@ -92,8 +103,8 @@ function createStatelyClient(options = {}) {
92
103
  return unwrapResponseData(data);
93
104
  }
94
105
  return {
95
- auth: { verify(apiKey) {
96
- return request("/verify", { method: "GET" }, apiKey);
106
+ auth: { verify(credential) {
107
+ return request("/verify", { method: "GET" }, credential);
97
108
  } },
98
109
  projects: {
99
110
  list() {
@@ -143,12 +154,15 @@ function createStatelyClient(options = {}) {
143
154
  }
144
155
  },
145
156
  code: { extractMachines(code, extractOptions = {}) {
146
- const apiKey = extractOptions.apiKey ?? options.apiKey ?? "anonymous";
157
+ const credential = extractOptions.credential ?? (extractOptions.apiKey ? {
158
+ type: "api_key",
159
+ token: extractOptions.apiKey
160
+ } : void 0);
147
161
  return request("/code", {
148
162
  method: "POST",
149
163
  headers: { "Content-Type": "application/json" },
150
164
  body: JSON.stringify({ code })
151
- }, apiKey);
165
+ }, credential, extractOptions.authMode);
152
166
  } }
153
167
  };
154
168
  }
package/dist/sync.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { b as DigraphConfig, i as StatelyGraph } from "./graph-GeuH-mFK.mjs";
1
+ import { b as DigraphConfig, i as StatelyGraph } from "./graph-Bm4_GZX_.mjs";
2
2
  import { CreateProjectInput, ProjectData, StudioClient, StudioMachineRecord, XStateVersion } from "./studio.mjs";
3
3
  import { GraphDiff } from "@statelyai/graph";
4
4