@statelyai/sdk 0.23.1 → 0.24.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 CHANGED
@@ -45,6 +45,10 @@ embed.init({
45
45
  });
46
46
  ```
47
47
 
48
+ The embed `apiKey` is sent to the iframe over `postMessage` after the editor
49
+ handshake; it is not included in the iframe URL. Call `embed.setApiKey(token)`
50
+ when the host refreshes the access token.
51
+
48
52
  Use `viewMode: 'list'` on `createStatelyEmbed` to add `?view=list` to the
49
53
  iframe URL, or subscribe to `viewModeChanged` when the user switches views.
50
54
 
@@ -108,7 +112,7 @@ Key capabilities:
108
112
  - **Reference documents** supplied as ordered, read-only Markdown, code, or text
109
113
  - **Comments** via Liveblocks integration (optional)
110
114
  - **Asset uploads** with built-in S3 and Supabase adapters, or bring your own upload handler
111
- - **Runtime settings** - toggle color mode, grid, snap lines, autolayout, and view mode on the fly
115
+ - **Runtime settings** - toggle color mode, grid, snap lines, and view mode on the fly
112
116
 
113
117
  ### Resource API client
114
118
 
package/dist/embed.d.mts CHANGED
@@ -71,6 +71,7 @@ type EmbedFormatDefinition = {
71
71
  };
72
72
  interface StatelyEmbedOptions extends Partial<MachineInitOptions> {
73
73
  baseUrl: string;
74
+ /** Access token sent to the iframe over the embed protocol. */
74
75
  apiKey?: string;
75
76
  /** Initial canvas view. Also reflected in the iframe URL as `?view=`. */
76
77
  viewMode?: 'graph' | 'list';
@@ -115,6 +116,8 @@ interface StatelyEmbed {
115
116
  attach(iframe: HTMLIFrameElement): void;
116
117
  /** Create an iframe and mount it into a container element. */
117
118
  mount(container: HTMLElement): HTMLIFrameElement;
119
+ /** Update the access token used by the iframe. */
120
+ setApiKey(apiKey: string): void;
118
121
  /** Send init message (queued if iframe not ready yet). */
119
122
  init(options: InitOptions): void;
120
123
  /** Update the machine (shorthand for update message). */
package/dist/embed.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-DX-_ZovM.mjs";
1
+ import { a as createEventRegistry, o as createPendingExportManager, r as createPostMessageTransport, s as toInitMessage, t as SDK_VERSION } from "./version-DALql3iM.mjs";
2
2
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
3
3
 
4
4
  //#region src/embed.ts
@@ -25,10 +25,13 @@ function assertExtensionCall(value) {
25
25
  if ((value.method === "export" || value.method === "validate") && !isEmbedGraph(payload.graph)) throw new Error("Invalid extension graph payload.");
26
26
  if (value.method === "validate" && payload.revision !== void 0 && typeof payload.revision !== "number") throw new Error("Invalid extension revision payload.");
27
27
  }
28
+ function normalizeApiKey(apiKey) {
29
+ return apiKey?.trim() || void 0;
30
+ }
28
31
  function buildEmbedUrl(options) {
29
32
  const base = options.baseUrl.replace(/\/+$/, "") + "/embed";
30
33
  const url = new URL(base);
31
- if (options.apiKey) url.searchParams.set("api_key", options.apiKey);
34
+ if (normalizeApiKey(options.apiKey)) url.searchParams.set("auth", "message");
32
35
  if (options.viewMode) url.searchParams.set("view", options.viewMode);
33
36
  return url.toString();
34
37
  }
@@ -113,6 +116,7 @@ function createStatelyEmbed(options) {
113
116
  let ownedIframe = false;
114
117
  let destroyed = false;
115
118
  let editorProtocolCompatible;
119
+ let apiKey = normalizeApiKey(options.apiKey);
116
120
  const pendingMessages = [];
117
121
  const events = createEventRegistry();
118
122
  const profiles = new Map((options.profiles ?? []).map((profile) => [profile.profile, profile]));
@@ -141,6 +145,12 @@ function createStatelyEmbed(options) {
141
145
  transport.send(msg);
142
146
  }
143
147
  }
148
+ function sendApiKey() {
149
+ if (apiKey) send({
150
+ type: "@statelyai.setApiKey",
151
+ apiKey
152
+ });
153
+ }
144
154
  function formatContext(profile) {
145
155
  const namespace = profile.namespace ?? /^(@[^/]+)\//.exec(profile.profile)?.[1];
146
156
  if (!namespace) throw new Error(`Profile ${profile.profile} has no namespace.`);
@@ -231,6 +241,7 @@ function createStatelyEmbed(options) {
231
241
  }
232
242
  });
233
243
  } else editorProtocolCompatible = true;
244
+ sendApiKey();
234
245
  flush();
235
246
  if (uploadAsset) send({
236
247
  type: "@statelyai.uploadCapabilities",
@@ -411,6 +422,10 @@ function createStatelyEmbed(options) {
411
422
  setupTransport(el);
412
423
  return el;
413
424
  },
425
+ setApiKey(nextApiKey) {
426
+ apiKey = normalizeApiKey(nextApiKey);
427
+ sendApiKey();
428
+ },
414
429
  init(opts) {
415
430
  send(toInitMessage("machine" in opts ? {
416
431
  ...opts,
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import "./openapi-BTDjYWXd.mjs";
2
2
  import { EMBED_DOCUMENT_LANGUAGES, EMBED_DOCUMENT_LIMITS, INSPECTION_PROTOCOL_VERSION, INSPECTION_ROOM_QUERY_PARAM, createInspectionActorId, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
3
- import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-DX-_ZovM.mjs";
3
+ import { i as createWebSocketTransport, r as createPostMessageTransport } from "./version-DALql3iM.mjs";
4
4
  import { t as EDITOR_PROTOCOL_VERSION } from "./editorHostProtocol-Bko7wge8.mjs";
5
5
  import { createStatelyEmbed } from "./embed.mjs";
6
6
  import { i as fetchEditorSyncAccess, r as createRemoteEditorSyncBackend, t as EditorHostSession } from "./editorHostSession-BwS-EiBJ.mjs";
7
7
  import { n as StudioApiError, r as createStatelyClient, t as DEFAULT_STATELY_BASE_URL } from "./studio-iNSHtNmP.mjs";
8
8
  import { a as RawCode, c as eventsSchemaToTSType, d as jsonSchemaToTSType, l as graphToMachineConfig, m as serializeJS, n as getStatelyPragma, o as contextSchemaToTSType, p as raw, r as upsertStatelyPragma, t as findStatelyPragmaAttachments, u as graphToXStateTS } from "./statelyPragma-0djA1cnm.mjs";
9
9
  import { createS3AssetUploadAdapter, createSupabaseAssetUploadAdapter } from "./assetStorage.mjs";
10
- import { n as createStatelyInspector, t as createInspector } from "./inspect-CWFYJT9G.mjs";
10
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-j1T7sM6_.mjs";
11
11
  import { createAuthorizationHeader, getCredentialToken } from "./auth.mjs";
12
12
  import { buildAuthorizeUrl, createPkcePair, discoverAuthorizationServer, discoverProtectedResource, exchangeCodeForToken, refreshToken, registerOAuthClient } from "./oauth.mjs";
13
13
  import { StatelyApiError, createStatelyApiClient, createStatelyApiUrl } from "./api.mjs";
@@ -1,5 +1,5 @@
1
1
  import { INSPECTION_PROTOCOL_VERSION, createInspectionRoomUrls, getInspectionRoomId } from "./protocol.mjs";
2
- import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-DX-_ZovM.mjs";
2
+ import { a as createEventRegistry, i as createWebSocketTransport, n as inspectionRuntime, o as createPendingExportManager, t as SDK_VERSION } from "./version-DALql3iM.mjs";
3
3
 
4
4
  //#region src/openBrowser.ts
5
5
  async function openBrowser(url) {
package/dist/inspect.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./version-DX-_ZovM.mjs";
2
- import { n as createStatelyInspector, t as createInspector } from "./inspect-CWFYJT9G.mjs";
1
+ import "./version-DALql3iM.mjs";
2
+ import { n as createStatelyInspector, t as createInspector } from "./inspect-j1T7sM6_.mjs";
3
3
 
4
4
  export { createInspector, createStatelyInspector };
@@ -65,12 +65,10 @@ interface ProjectWorkspaceCapabilities {
65
65
  deleteMachine?: ProjectWorkspaceAction;
66
66
  setRootMachine?: ProjectWorkspaceAction;
67
67
  }
68
- /** Serializable workspace tree rendered by project-mode embeds. */
69
- interface ProjectWorkspaceConfig {
70
- /** Visible projects; pass one entry when embedding a single project. */
71
- projects: ProjectWorkspaceProject[];
68
+ interface ProjectWorkspaceConfigBase {
72
69
  defaultProjectId?: string;
73
- backAction?: ProjectWorkspaceAction;
70
+ /** Optional navigation action shown above the workspace. Set to null to hide it. */
71
+ backAction?: ProjectWorkspaceAction | null;
74
72
  userAvatarUrl?: string;
75
73
  machineSelectionDisabled?: boolean;
76
74
  /** Optional host-backed operations for the built-in workspace controls. */
@@ -81,6 +79,14 @@ interface ProjectWorkspaceConfig {
81
79
  projectActions?: Record<string, ProjectWorkspaceAction[]>;
82
80
  machineActions?: Record<string, ProjectWorkspaceAction[]>;
83
81
  }
82
+ /** Serializable workspace tree rendered by project-mode embeds. */
83
+ type ProjectWorkspaceConfig = (ProjectWorkspaceConfigBase & {
84
+ /** Single-project mode: hides project CRUD and flattens its machines. */project: ProjectWorkspaceProject;
85
+ projects?: never;
86
+ }) | (ProjectWorkspaceConfigBase & {
87
+ /** Multi-project mode: renders a collapsible project tree. */projects: ProjectWorkspaceProject[];
88
+ project?: never;
89
+ });
84
90
  declare const EMBED_DOCUMENT_LANGUAGES: readonly ["markdown", "typescript", "javascript", "json", "xml", "mermaid", "text"];
85
91
  type EmbedDocumentLanguage = (typeof EMBED_DOCUMENT_LANGUAGES)[number];
86
92
  declare const EMBED_DOCUMENT_LIMITS: {
@@ -278,7 +284,7 @@ interface MachineInitOptions {
278
284
  * - `enabled` — whether to show the pill at all. Defaults to `false`.
279
285
  * - `mode` — `'structural'` (default) only triggers on graph-structural
280
286
  * changes (state/transition/action/invoke/schema edits). Pure visual
281
- * changes like drag-to-position, color, and autolayout are ignored.
287
+ * changes like drag-to-position, color, and layout are ignored.
282
288
  * `'all'` triggers on any graph change.
283
289
  */
284
290
  unsavedIndicator?: {
@@ -333,7 +333,7 @@ function createWebSocketTransport(options) {
333
333
 
334
334
  //#endregion
335
335
  //#region src/version.ts
336
- const SDK_VERSION = "0.23.1";
336
+ const SDK_VERSION = "0.24.0";
337
337
  function inspectionRuntime() {
338
338
  if (typeof window !== "undefined") return "browser";
339
339
  if (typeof process !== "undefined" && process.versions?.node) return "node";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/sdk",
3
- "version": "0.23.1",
3
+ "version": "0.24.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "stately-sdk": "./dist/bin.mjs"
@@ -93,8 +93,8 @@
93
93
  "jsdom": "^27.4.0",
94
94
  "tsdown": "0.21.0-beta.2",
95
95
  "vitest": "^3.2.4",
96
- "@statelyai/api-contract": "0.3.8",
97
- "@statelyai/graph-tools": "0.2.2"
96
+ "@statelyai/graph-tools": "0.2.2",
97
+ "@statelyai/api-contract": "0.3.8"
98
98
  },
99
99
  "engines": {
100
100
  "node": ">=22.4"