@statelyai/sdk 0.5.1 → 0.6.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
@@ -27,10 +27,9 @@ npm install @statelyai/sdk
27
27
  The embed supports three common deployment models:
28
28
 
29
29
  - Hosted Stately: pass an API key to `createStatelyEmbed()`
30
- - Same-origin deployments: rely on the host application's session/cookie auth
31
30
  - Self-hosted deployments: configure auth in the editor server and omit `apiKey` when no token is required
32
31
 
33
- ### With Stately (default)
32
+ ### Hosted Stately
34
33
 
35
34
  An API key is required. To get one:
36
35
 
@@ -50,29 +49,19 @@ const embed = createStatelyEmbed({
50
49
  });
51
50
  ```
52
51
 
53
- ### Same-origin embed (cookie auth)
54
-
55
- When the embed host and the editor share a domain, you can omit `apiKey` and rely on the host application's auth/session layer:
56
-
57
- ```ts
58
- const embed = createStatelyEmbed({
59
- baseUrl: process.env.NEXT_PUBLIC_BETA_EDITOR_URL ?? window.location.origin,
60
- });
61
- ```
62
-
63
52
  ### Self-hosting
64
53
 
65
54
  When self-hosting the editor, authentication is enforced by the editor server, not by this npm package.
66
55
 
67
56
  The common environment variables are:
68
57
 
69
- | Variable | Purpose |
70
- | --- | --- |
71
- | `AUTH_PROVIDER` | Auth strategy used by the editor host |
58
+ | Variable | Purpose |
59
+ | --------------------------- | ----------------------------------------------------------------------- |
60
+ | `AUTH_PROVIDER` | Auth strategy used by the editor host |
72
61
  | `EDITOR_SYNC_AUTH_REQUIRED` | Set to `false` to disable API-key checks for editor-sync endpoints only |
73
- | `STATELY_API_KEY` | Server-side API key for Stately data fetching |
74
- | `STATELY_API_URL` | Stately API base URL override |
75
- | `NEXT_PUBLIC_BASE_URL` | Public-facing editor URL |
62
+ | `STATELY_API_KEY` | Server-side API key for Stately data fetching |
63
+ | `STATELY_API_URL` | Stately API base URL override |
64
+ | `NEXT_PUBLIC_BASE_URL` | Public-facing editor URL |
76
65
 
77
66
  For a fully self-contained deployment with no auth, omit `apiKey` in the SDK and configure the host/editor to allow unauthenticated access:
78
67
 
@@ -143,6 +132,8 @@ The SDK ships root exports for the most common entry points and helpers:
143
132
 
144
133
  ```ts
145
134
  import {
135
+ createStatelyApiClient,
136
+ createStatelyApiUrl,
146
137
  createStatelyClient,
147
138
  createStatelyEmbed,
148
139
  createStatelyInspector,
@@ -159,11 +150,17 @@ It also supports narrower subpath imports:
159
150
  import { createStatelyClient } from '@statelyai/sdk/studio';
160
151
  import { createStatelyInspector } from '@statelyai/sdk/inspect';
161
152
  import { createStatelyEmbed } from '@statelyai/sdk/embed';
153
+ import {
154
+ createStatelyApiClient,
155
+ createStatelyApiUrl,
156
+ } from '@statelyai/sdk/api';
162
157
  import { fromStudioMachine, toStudioMachine } from '@statelyai/sdk/graph';
163
- import { planSync, pullSync } from '@statelyai/sdk/sync';
158
+ import { planSync, pullSync, pushSync } from '@statelyai/sdk/sync';
164
159
  import type { GraphPatch } from '@statelyai/sdk/patchTypes';
165
160
  ```
166
161
 
162
+ The root package also exports `getStatelyPragma()`, `findStatelyPragmaAttachments()`, and `upsertStatelyPragma()` for working with canonical source annotations such as `// @statelyai id=machine-123`.
163
+
167
164
  ## Studio API Client
168
165
 
169
166
  ```ts
@@ -173,21 +170,84 @@ const studio = createStatelyClient({
173
170
  apiKey: process.env.STATELY_API_KEY,
174
171
  });
175
172
 
173
+ const createdProject = await studio.projects.create({
174
+ name: 'My project',
175
+ visibility: 'Private',
176
+ });
176
177
  const project = await studio.projects.get('project-id');
178
+ const projects = await studio.projects.list();
179
+ const createdMachine = await studio.machines.create({
180
+ projectVersionId: createdProject.projectVersionId!,
181
+ definition: digraphDefinition,
182
+ xstateVersion: 5,
183
+ });
177
184
  const machine = await studio.machines.get('machine-id', { version: '42' });
178
185
  const extracted = await studio.code.extractMachines(sourceCode);
179
186
  ```
180
187
 
188
+ `studio.projects.list(...)`, `studio.projects.create(...)`, and `studio.machines.create(...)` use the documented Studio REST API. `studio.projects.ensure(...)` is a client-side helper that uses the documented list/create endpoints to reuse an existing connected project when the repo metadata matches.
189
+
181
190
  <!-- public methods of StudioClient from src/studio.ts -->
182
191
 
183
192
  Available client methods:
184
193
 
185
- | Method | Description |
186
- | --- | --- |
187
- | `studio.auth.verify(apiKey?)` | Verify an API key against the registry API |
188
- | `studio.projects.get(projectId)` | Fetch a project and its machines |
189
- | `studio.machines.get(machineId, { version? })` | Fetch a machine, optionally pinned to a version |
190
- | `studio.code.extractMachines(code, { apiKey? })` | Extract machine configs from source text |
194
+ | Method | Description |
195
+ | ----------------------------------------------------------------------- | ------------------------------------------------------------------------ |
196
+ | `studio.auth.verify(apiKey?)` | Verify an API key against the registry API |
197
+ | `studio.projects.list()` | List accessible projects, including connected repo metadata when present |
198
+ | `studio.projects.create({ name, visibility, description?, keywords? })` | Create a new project through the published REST API |
199
+ | `studio.projects.ensure({ name, visibility, repo?, ... })` | Reuse an existing connected project or create one through the REST API |
200
+ | `studio.projects.get(projectId)` | Fetch a project and its machines |
201
+ | `studio.machines.create({ projectVersionId, ... })` | Create a machine through the published REST API |
202
+ | `studio.machines.createMany({ projectVersionId, ... })` | Compatibility wrapper around `create()` that returns a one-item array |
203
+ | `studio.machines.get(machineId, { version? })` | Fetch a machine, optionally pinned to a version |
204
+ | `studio.code.extractMachines(code, { apiKey? })` | Extract machine configs from source text |
205
+
206
+ ## Sync Helpers
207
+
208
+ `pushSync()` complements `planSync()` and `pullSync()` for local-to-Studio flows. It resolves a local source file, ensures there is a target project, creates the remote machine, and writes `// @statelyai id=...` back into XState source files.
209
+
210
+ ```ts
211
+ import { pushSync } from '@statelyai/sdk/sync';
212
+
213
+ const result = await pushSync({
214
+ source: './src/machines/toggle.ts',
215
+ apiKey: process.env.STATELY_API_KEY,
216
+ project: {
217
+ visibility: 'Private',
218
+ repo: {
219
+ url: 'https://github.com/statelyai/viz',
220
+ owner: 'statelyai',
221
+ repo: 'viz',
222
+ branch: 'main',
223
+ treeSha: 'abc123',
224
+ },
225
+ },
226
+ });
227
+ ```
228
+
229
+ Projects can also check in a `statelyai.json` file to describe which local sources belong to a Studio project. The published schema lives at `@statelyai/sdk/statelyai.schema.json` and the canonical schema id is `https://stately.ai/schemas/statelyai.json`.
230
+
231
+ ```json
232
+ {
233
+ "$schema": "https://stately.ai/schemas/statelyai.json",
234
+ "version": "1.0.0",
235
+ "projectId": "project_123",
236
+ "studioUrl": "https://stately.ai",
237
+ "defaultXStateVersion": 5,
238
+ "sources": [
239
+ {
240
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
241
+ "exclude": ["**/*.test.ts", "**/dist/**"],
242
+ "format": "xstate"
243
+ },
244
+ {
245
+ "include": ["docs/**/*.mmd"],
246
+ "format": "mermaid"
247
+ }
248
+ ]
249
+ }
250
+ ```
191
251
 
192
252
  ## Inspector
193
253
 
@@ -211,18 +271,18 @@ actor.start();
211
271
 
212
272
  Key options:
213
273
 
214
- | Option | Description |
215
- | --- | --- |
216
- | `actor` | Root actor to adopt and inspect automatically |
217
- | `url` | Devtools relay URL. Defaults to `ws://localhost:4242` |
218
- | `autoOpen` | Whether to ask the relay to open the inspector UI |
219
- | `sessionId` | Override the relay session id |
220
- | `name` | Display name shown to the inspector |
221
- | `serializeSnapshot` | Customize snapshot serialization before sending it over the wire |
222
- | `extractMachineConfig` | Customize how machine config is derived from an actor |
223
- | `selectedActorId` | Focus a specific actor first |
224
- | `panels`, `theme`, `readOnly`, `depth` | Initial inspector UI options |
225
- | `transport` | Inject an existing transport instead of opening a new WebSocket |
274
+ | Option | Description |
275
+ | -------------------------------------- | ---------------------------------------------------------------- |
276
+ | `actor` | Root actor to adopt and inspect automatically |
277
+ | `url` | Devtools relay URL. Defaults to `ws://localhost:4242` |
278
+ | `autoOpen` | Whether to ask the relay to open the inspector UI |
279
+ | `sessionId` | Override the relay session id |
280
+ | `name` | Display name shown to the inspector |
281
+ | `serializeSnapshot` | Customize snapshot serialization before sending it over the wire |
282
+ | `extractMachineConfig` | Customize how machine config is derived from an actor |
283
+ | `selectedActorId` | Focus a specific actor first |
284
+ | `panels`, `theme`, `readOnly`, `depth` | Initial inspector UI options |
285
+ | `transport` | Inject an existing transport instead of opening a new WebSocket |
226
286
 
227
287
  Key methods:
228
288
 
@@ -241,17 +301,17 @@ Creates an embed instance.
241
301
 
242
302
  <!-- public options of StatelyEmbedOptions from src/embed.ts -->
243
303
 
244
- | Option | Type | Description |
245
- | --- | --- | --- |
246
- | `baseUrl` | `string` | **Required.** Base URL of the Stately app |
247
- | `apiKey` | `string` | API key for hosted Stately deployments |
248
- | `origin` | `string` | Optional strict target origin for `postMessage`; defaults to permissive wildcard messaging for local/self-hosted testing |
249
- | `assets` | `AssetConfig` | Asset upload configuration |
250
- | `onReady` | `() => void` | Called when the embed is ready |
251
- | `onLoaded` | `(graph) => void` | Called when a machine is loaded |
252
- | `onChange` | `(graph, machineConfig) => void` | Called on every change |
253
- | `onSave` | `(graph, machineConfig) => void` | Called on save |
254
- | `onError` | `({ code, message }) => void` | Called when the embed reports an error |
304
+ | Option | Type | Description |
305
+ | ---------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
306
+ | `baseUrl` | `string` | **Required.** Base URL of the Stately app |
307
+ | `apiKey` | `string` | API key for hosted Stately deployments |
308
+ | `origin` | `string` | Optional strict target origin for `postMessage`; defaults to permissive wildcard messaging for local/self-hosted testing |
309
+ | `assets` | `AssetConfig` | Asset upload configuration |
310
+ | `onReady` | `() => void` | Called when the embed is ready |
311
+ | `onLoaded` | `(graph) => void` | Called when a machine is loaded |
312
+ | `onChange` | `(graph, machineConfig) => void` | Called on every change |
313
+ | `onSave` | `(graph, machineConfig) => void` | Called on save |
314
+ | `onError` | `({ code, message }) => void` | Called when the embed reports an error |
255
315
 
256
316
  ### Embed methods
257
317
 
@@ -295,20 +355,20 @@ embed.init({
295
355
 
296
356
  `comments` accepts:
297
357
 
298
- | Field | Type | Description |
299
- | --- | --- | --- |
300
- | `roomId` | `string` | **Required.** Liveblocks room identifier |
301
- | `publicApiKey` | `string` | Liveblocks public key |
302
- | `authEndpoint` | `string` | Custom Liveblocks auth endpoint |
303
- | `baseUrl` | `string` | Custom Liveblocks base URL for self-hosting |
304
- | `userId` | `string \| null` | Optional user identity metadata |
358
+ | Field | Type | Description |
359
+ | -------------- | ---------------- | ------------------------------------------- |
360
+ | `roomId` | `string` | **Required.** Liveblocks room identifier |
361
+ | `publicApiKey` | `string` | Liveblocks public key |
362
+ | `authEndpoint` | `string` | Custom Liveblocks auth endpoint |
363
+ | `baseUrl` | `string` | Custom Liveblocks base URL for self-hosting |
364
+ | `userId` | `string \| null` | Optional user identity metadata |
305
365
 
306
366
  `unsavedIndicator` accepts:
307
367
 
308
- | Field | Type | Description |
309
- | --- | --- | --- |
310
- | `enabled` | `boolean` | Show the persistent "Save to apply" pill |
311
- | `mode` | `'structural' \| 'all'` | Track only structural graph edits or all edits |
368
+ | Field | Type | Description |
369
+ | --------- | ----------------------- | ---------------------------------------------- |
370
+ | `enabled` | `boolean` | Show the persistent "Save to apply" pill |
371
+ | `mode` | `'structural' \| 'all'` | Track only structural graph edits or all edits |
312
372
 
313
373
  #### `embed.updateMachine(machine, format?)`
314
374
 
@@ -331,16 +391,18 @@ embed.setSettings({
331
391
 
332
392
  Available core settings:
333
393
 
334
- | Path | Type | Default |
335
- | --- | --- | --- |
336
- | `appearance.colorMode` | `'light' \| 'dark' \| 'system'` | `'dark'` |
337
- | `canvas.showGrid` | `boolean` | `true` |
338
- | `canvas.viewMode` | `'graph' \| 'list'` | `'graph'` |
339
- | `canvas.enableSnapLines` | `boolean` | `true` |
340
- | `canvas.dimUnselected` | `boolean` | `true` |
341
- | `validation.showValidations` | `boolean` | `true` |
342
- | `autolayout.autoEnabled` | `boolean` | `false` |
343
- | `developer.devMode` | `boolean` | `false` |
394
+ <!-- core setting paths from ../../src/settings.ts -->
395
+
396
+ | Path | Type | Default |
397
+ | ---------------------------- | ------------------------------- | --------- |
398
+ | `appearance.colorMode` | `'light' \| 'dark' \| 'system'` | `'dark'` |
399
+ | `canvas.showGrid` | `boolean` | `true` |
400
+ | `canvas.viewMode` | `'graph' \| 'list'` | `'graph'` |
401
+ | `canvas.enableSnapLines` | `boolean` | `true` |
402
+ | `canvas.dimUnselected` | `boolean` | `true` |
403
+ | `validation.showValidations` | `boolean` | `true` |
404
+ | `layout.autolayout` | `boolean` | `false` |
405
+ | `developer.devMode` | `boolean` | `false` |
344
406
 
345
407
  #### `embed.export(format, options?)`
346
408
 
@@ -349,13 +411,13 @@ Export the current machine. Returns a promise.
349
411
  ```ts
350
412
  const xstateCode = await embed.export('xstate', { version: 5 });
351
413
  const digraph = await embed.export('digraph');
352
- const rtk = await embed.export('rtk');
414
+ const redux = await embed.export('redux');
353
415
  const aslYaml = await embed.export('asl-yaml');
354
416
  ```
355
417
 
356
418
  <!-- supported export formats from ExportFormatMap in src/protocol.ts -->
357
419
 
358
- Supported formats: `xstate`, `json`, `xgraph`, `digraph`, `mermaid`, `rtk`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
420
+ Supported formats: `xstate`, `json`, `xgraph`, `digraph`, `mermaid`, `redux`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
359
421
 
360
422
  #### `embed.on(event, handler)` / `embed.off(event, handler)`
361
423
 
@@ -400,11 +462,11 @@ const embed = createStatelyEmbed({
400
462
  });
401
463
  ```
402
464
 
403
- | Option | Type | Description |
404
- | --- | --- | --- |
465
+ | Option | Type | Description |
466
+ | ----------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------- |
405
467
  | `onUploadRequest` | `(file: File, context: { stateNodeId: string }) => Promise<UploadResult>` | **Required.** Called when the editor needs to upload a file |
406
- | `accept` | `string[]` | Accepted MIME types. Supports wildcards like `image/*` |
407
- | `maxFileSize` | `number` | Max file size in bytes. Defaults to `10_485_760` |
468
+ | `accept` | `string[]` | Accepted MIME types. Supports wildcards like `image/*` |
469
+ | `maxFileSize` | `number` | Max file size in bytes. Defaults to `10_485_760` |
408
470
 
409
471
  `UploadResult`:
410
472
 
@@ -446,6 +508,8 @@ const digraph = toStudioMachine(graph);
446
508
  Other exported helpers:
447
509
 
448
510
  - `studioMachineConverter` for reusable format conversion
511
+ - `createStatelyApiUrl()` and `createStatelyApiClient()` for building and
512
+ calling self-hosted Viz API routes from a shared API base URL
449
513
  - `serializeJS()`, `raw()`, and `RawCode` for emitting JavaScript source
450
514
  - `jsonSchemaToTSType()`, `contextSchemaToTSType()`, and `eventsSchemaToTSType()` for generating inline TypeScript types from JSON Schema
451
515
  - `GraphPatch` and `ActionLocation` types from `@statelyai/sdk/patchTypes`
@@ -489,6 +553,9 @@ Installing the package also exposes a `statelyai` binary:
489
553
  ```bash
490
554
  npx statelyai open ./checkout.machine.ts
491
555
 
556
+ statelyai init
557
+ statelyai login
558
+ statelyai auth status
492
559
  statelyai plan ./checkout.machine.ts machine-id
493
560
  statelyai diff ./checkout.machine.ts machine-id --fail-on-changes
494
561
  statelyai pull machine-id ./checkout.machine.ts
@@ -499,12 +566,16 @@ For one-off use, `npx statelyai ...` installs the small `statelyai` CLI package,
499
566
 
500
567
  Available commands:
501
568
 
502
- | Command | Description |
503
- | --- | --- |
504
- | `statelyai plan <source> <target>` | Print a semantic sync summary |
505
- | `statelyai diff <source> <target>` | Diff two locators and optionally fail on changes |
506
- | `statelyai pull <source> <target>` | Materialize a source into a local target file |
507
- | `statelyai open <file>` | Open a local file in a browser-backed visual editor session |
569
+ | Command | Description |
570
+ | ---------------------------------- | --------------------------------------------------------------------------- |
571
+ | `statelyai init` | Create or reuse a Studio project for the current directory and write `statelyai.json` |
572
+ | `statelyai login` | Store an API key for future CLI use |
573
+ | `statelyai logout` | Remove a stored API key |
574
+ | `statelyai auth status` | Show whether the CLI would use an environment variable or stored credential |
575
+ | `statelyai plan <source> <target>` | Print a semantic sync summary |
576
+ | `statelyai diff <source> <target>` | Diff two locators and optionally fail on changes |
577
+ | `statelyai pull <source> <target>` | Materialize a source into a local target file |
578
+ | `statelyai open <file>` | Open a local file in a browser-backed visual editor session |
508
579
 
509
580
  Common flags:
510
581
 
@@ -512,7 +583,9 @@ Common flags:
512
583
  - `--base-url` for self-hosted or non-default Stately deployments
513
584
  - `--fail-on-changes` to return a nonzero exit code when a diff is detected
514
585
 
515
- `statelyai open` also supports `--api-key`, `--editor-url`, `--host`, `--port`, `--no-open`, and `--debug`. It watches the local file on disk and sends source snapshots to `/api/editor-sync/*` endpoints, which return the text replacements to apply locally. Pass `--api-key` or set `STATELY_API_KEY` when the editor server requires auth. Self-hosted servers can disable editor-sync API-key checks with `EDITOR_SYNC_AUTH_REQUIRED=false`. The private source reconciliation engine is not bundled into the published CLI.
586
+ The CLI resolves credentials in this order: `--api-key`, then `STATELY_API_KEY`/`NEXT_PUBLIC_STATELY_API_KEY`, then the key stored by `statelyai login`. `login` stores the key in the OS credential store when available, with a private file fallback.
587
+
588
+ `statelyai open` also supports `--api-key`, `--editor-url`, `--host`, `--port`, `--no-open`, and `--debug`. It watches the local file on disk and sends source snapshots to `/api/editor-sync/*` endpoints, which return the text replacements to apply locally. When the source file contains `// @statelyai id=...` and an API key is available, the editor session also reuses the referenced remote machine layout while continuing to treat the local source as the semantic source of truth. Pass `--api-key`, set `STATELY_API_KEY`, or run `statelyai login` when the editor server requires auth. Self-hosted servers can disable editor-sync API-key checks with `EDITOR_SYNC_AUTH_REQUIRED=false`. The private source reconciliation engine is not bundled into the published CLI.
516
589
 
517
590
  ## Transport Helpers
518
591
 
package/dist/api.d.mts ADDED
@@ -0,0 +1,20 @@
1
+ //#region src/api.d.ts
2
+ interface StatelyApiUrlOptions {
3
+ baseUrl?: string | null;
4
+ }
5
+ interface StatelyApiClientOptions extends StatelyApiUrlOptions {
6
+ fetch?: typeof fetch;
7
+ }
8
+ declare class StatelyApiError extends Error {
9
+ readonly status: number;
10
+ readonly data: unknown;
11
+ constructor(message: string, status: number, data: unknown);
12
+ }
13
+ declare function createStatelyApiUrl(path: string, options?: StatelyApiUrlOptions): string;
14
+ declare function createStatelyApiClient(options?: StatelyApiClientOptions): {
15
+ url(path: string): string;
16
+ request: <T>(path: string, init?: RequestInit) => Promise<T>;
17
+ post<T>(path: string, body: unknown, init?: RequestInit): Promise<T>;
18
+ };
19
+ //#endregion
20
+ export { StatelyApiClientOptions, StatelyApiError, StatelyApiUrlOptions, createStatelyApiClient, createStatelyApiUrl };
package/dist/api.mjs ADDED
@@ -0,0 +1,56 @@
1
+ //#region src/api.ts
2
+ var StatelyApiError = class extends Error {
3
+ status;
4
+ data;
5
+ constructor(message, status, data) {
6
+ super(message);
7
+ this.name = "StatelyApiError";
8
+ this.status = status;
9
+ this.data = data;
10
+ }
11
+ };
12
+ function getFetch(fetchImpl) {
13
+ const resolvedFetch = fetchImpl ?? globalThis.fetch;
14
+ if (!resolvedFetch) throw new Error("No fetch implementation available. Pass one via createStatelyApiClient({ fetch }).");
15
+ return resolvedFetch;
16
+ }
17
+ function getErrorMessage(data, status) {
18
+ if (typeof data === "object" && data !== null && "error" in data && typeof data.error === "string") return data.error;
19
+ return `HTTP ${status}`;
20
+ }
21
+ async function parseJson(response) {
22
+ if (!response.headers.get("content-type")?.includes("application/json")) return null;
23
+ return response.json().catch(() => null);
24
+ }
25
+ function createStatelyApiUrl(path, options) {
26
+ return `${(options?.baseUrl ?? "/api").replace(/\/+$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
27
+ }
28
+ function createStatelyApiClient(options = {}) {
29
+ const fetchImpl = getFetch(options.fetch);
30
+ async function request(path, init) {
31
+ const response = await fetchImpl(createStatelyApiUrl(path, options), init);
32
+ const data = await parseJson(response);
33
+ if (!response.ok) throw new StatelyApiError(getErrorMessage(data, response.status), response.status, data);
34
+ return data;
35
+ }
36
+ return {
37
+ url(path) {
38
+ return createStatelyApiUrl(path, options);
39
+ },
40
+ request,
41
+ post(path, body, init) {
42
+ return request(path, {
43
+ ...init,
44
+ method: init?.method ?? "POST",
45
+ headers: {
46
+ "content-type": "application/json",
47
+ ...init?.headers
48
+ },
49
+ body: JSON.stringify(body)
50
+ });
51
+ }
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ export { StatelyApiError, createStatelyApiClient, createStatelyApiUrl };
package/dist/cli.d.mts CHANGED
@@ -1,9 +1,60 @@
1
- import "./graph-BfezxFKJ.mjs";
1
+ import { ConnectedRepo, CreateProjectInput, ProjectData, StudioClient } from "./studio.mjs";
2
+ import "./graph-CB-ALrdk.mjs";
2
3
  import { SyncPlan } from "./sync.mjs";
3
4
  import { Command } from "@oclif/core";
4
5
  import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
5
6
 
6
7
  //#region src/cli.d.ts
8
+ interface StatelySourceConfig {
9
+ include: string[];
10
+ exclude?: string[];
11
+ format: 'xstate' | 'redux' | 'zustand' | 'xgraph' | 'digraph' | 'mermaid' | 'scxml' | 'json' | 'asl-json' | 'asl-yaml' | 'auto';
12
+ xstateVersion?: number;
13
+ }
14
+ interface StatelyProjectConfig {
15
+ $schema: string;
16
+ version: string;
17
+ projectId: string;
18
+ studioUrl: string;
19
+ defaultXStateVersion: number;
20
+ sources: StatelySourceConfig[];
21
+ }
22
+ interface InitProjectOptions {
23
+ apiKey: string;
24
+ baseUrl?: string;
25
+ cwd?: string;
26
+ client?: StudioClient;
27
+ configPath?: string;
28
+ defaultXStateVersion?: number;
29
+ force?: boolean;
30
+ project?: Partial<CreateProjectInput>;
31
+ }
32
+ interface InitProjectResult {
33
+ config: StatelyProjectConfig;
34
+ configPath: string;
35
+ project: ProjectData;
36
+ }
37
+ declare function createStatelyProjectConfig(options: {
38
+ projectId: string;
39
+ studioUrl: string;
40
+ defaultXStateVersion?: number;
41
+ }): StatelyProjectConfig;
42
+ type ApiKeyResolution = {
43
+ apiKey: string;
44
+ detail: string;
45
+ source: 'env' | 'flag' | 'stored';
46
+ } | {
47
+ apiKey?: undefined;
48
+ detail?: undefined;
49
+ source: 'missing';
50
+ };
51
+ declare function getEnvApiKey(): {
52
+ apiKey: string;
53
+ variable: 'NEXT_PUBLIC_STATELY_API_KEY' | 'STATELY_API_KEY';
54
+ } | undefined;
55
+ declare function resolveApiKey(explicitApiKey?: string): Promise<ApiKeyResolution>;
56
+ declare function inferInitProjectName(cwd: string, repo?: ConnectedRepo): string;
57
+ declare function initProject(options: InitProjectOptions): Promise<InitProjectResult>;
7
58
  declare function formatPlanSummary(plan: SyncPlan): string;
8
59
  declare abstract class BaseSyncCommand extends Command {
9
60
  static enableJsonFlag: boolean;
@@ -71,12 +122,59 @@ declare class OpenCommand extends Command {
71
122
  };
72
123
  run(): Promise<void>;
73
124
  }
125
+ declare class InitCommand extends Command {
126
+ static enableJsonFlag: boolean;
127
+ static summary: string;
128
+ static description: string;
129
+ static flags: {
130
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
131
+ 'api-key': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
132
+ 'base-url': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
133
+ name: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
134
+ visibility: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
135
+ force: _oclif_core_interfaces0.BooleanFlag<boolean>;
136
+ };
137
+ run(): Promise<void>;
138
+ }
139
+ declare class LoginCommand extends Command {
140
+ static enableJsonFlag: boolean;
141
+ static summary: string;
142
+ static description: string;
143
+ static flags: {
144
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
145
+ 'api-key': _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
146
+ stdin: _oclif_core_interfaces0.BooleanFlag<boolean>;
147
+ };
148
+ run(): Promise<void>;
149
+ }
150
+ declare class LogoutCommand extends Command {
151
+ static enableJsonFlag: boolean;
152
+ static summary: string;
153
+ static description: string;
154
+ static flags: {
155
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
156
+ };
157
+ run(): Promise<void>;
158
+ }
159
+ declare class AuthStatusCommand extends Command {
160
+ static enableJsonFlag: boolean;
161
+ static summary: string;
162
+ static description: string;
163
+ static flags: {
164
+ help: _oclif_core_interfaces0.BooleanFlag<void>;
165
+ };
166
+ run(): Promise<void>;
167
+ }
74
168
  declare const COMMANDS: {
75
169
  plan: typeof PlanCommand;
76
170
  diff: typeof DiffCommand;
77
171
  pull: typeof PullCommand;
78
172
  open: typeof OpenCommand;
173
+ init: typeof InitCommand;
174
+ login: typeof LoginCommand;
175
+ logout: typeof LogoutCommand;
176
+ 'auth:status': typeof AuthStatusCommand;
79
177
  };
80
178
  declare function run(argv?: string[], entryUrl?: string): Promise<void>;
81
179
  //#endregion
82
- export { COMMANDS, formatPlanSummary, run };
180
+ export { ApiKeyResolution, COMMANDS, InitProjectOptions, InitProjectResult, StatelyProjectConfig, StatelySourceConfig, createStatelyProjectConfig, formatPlanSummary, getEnvApiKey, inferInitProjectName, initProject, resolveApiKey, run };