@statelyai/sdk 0.5.0 → 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,28 +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 |
72
- | `STATELY_API_KEY` | Server-side API key for Stately data fetching |
73
- | `STATELY_API_URL` | Stately API base URL override |
74
- | `NEXT_PUBLIC_BASE_URL` | Public-facing editor URL |
58
+ | Variable | Purpose |
59
+ | --------------------------- | ----------------------------------------------------------------------- |
60
+ | `AUTH_PROVIDER` | Auth strategy used by the editor host |
61
+ | `EDITOR_SYNC_AUTH_REQUIRED` | Set to `false` to disable API-key checks for editor-sync endpoints only |
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 |
75
65
 
76
66
  For a fully self-contained deployment with no auth, omit `apiKey` in the SDK and configure the host/editor to allow unauthenticated access:
77
67
 
@@ -142,6 +132,8 @@ The SDK ships root exports for the most common entry points and helpers:
142
132
 
143
133
  ```ts
144
134
  import {
135
+ createStatelyApiClient,
136
+ createStatelyApiUrl,
145
137
  createStatelyClient,
146
138
  createStatelyEmbed,
147
139
  createStatelyInspector,
@@ -158,11 +150,17 @@ It also supports narrower subpath imports:
158
150
  import { createStatelyClient } from '@statelyai/sdk/studio';
159
151
  import { createStatelyInspector } from '@statelyai/sdk/inspect';
160
152
  import { createStatelyEmbed } from '@statelyai/sdk/embed';
153
+ import {
154
+ createStatelyApiClient,
155
+ createStatelyApiUrl,
156
+ } from '@statelyai/sdk/api';
161
157
  import { fromStudioMachine, toStudioMachine } from '@statelyai/sdk/graph';
162
- import { planSync, pullSync } from '@statelyai/sdk/sync';
158
+ import { planSync, pullSync, pushSync } from '@statelyai/sdk/sync';
163
159
  import type { GraphPatch } from '@statelyai/sdk/patchTypes';
164
160
  ```
165
161
 
162
+ The root package also exports `getStatelyPragma()`, `findStatelyPragmaAttachments()`, and `upsertStatelyPragma()` for working with canonical source annotations such as `// @statelyai id=machine-123`.
163
+
166
164
  ## Studio API Client
167
165
 
168
166
  ```ts
@@ -172,21 +170,84 @@ const studio = createStatelyClient({
172
170
  apiKey: process.env.STATELY_API_KEY,
173
171
  });
174
172
 
173
+ const createdProject = await studio.projects.create({
174
+ name: 'My project',
175
+ visibility: 'Private',
176
+ });
175
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
+ });
176
184
  const machine = await studio.machines.get('machine-id', { version: '42' });
177
185
  const extracted = await studio.code.extractMachines(sourceCode);
178
186
  ```
179
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
+
180
190
  <!-- public methods of StudioClient from src/studio.ts -->
181
191
 
182
192
  Available client methods:
183
193
 
184
- | Method | Description |
185
- | --- | --- |
186
- | `studio.auth.verify(apiKey?)` | Verify an API key against the registry API |
187
- | `studio.projects.get(projectId)` | Fetch a project and its machines |
188
- | `studio.machines.get(machineId, { version? })` | Fetch a machine, optionally pinned to a version |
189
- | `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
+ ```
190
251
 
191
252
  ## Inspector
192
253
 
@@ -210,18 +271,18 @@ actor.start();
210
271
 
211
272
  Key options:
212
273
 
213
- | Option | Description |
214
- | --- | --- |
215
- | `actor` | Root actor to adopt and inspect automatically |
216
- | `url` | Devtools relay URL. Defaults to `ws://localhost:4242` |
217
- | `autoOpen` | Whether to ask the relay to open the inspector UI |
218
- | `sessionId` | Override the relay session id |
219
- | `name` | Display name shown to the inspector |
220
- | `serializeSnapshot` | Customize snapshot serialization before sending it over the wire |
221
- | `extractMachineConfig` | Customize how machine config is derived from an actor |
222
- | `selectedActorId` | Focus a specific actor first |
223
- | `panels`, `theme`, `readOnly`, `depth` | Initial inspector UI options |
224
- | `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 |
225
286
 
226
287
  Key methods:
227
288
 
@@ -240,17 +301,17 @@ Creates an embed instance.
240
301
 
241
302
  <!-- public options of StatelyEmbedOptions from src/embed.ts -->
242
303
 
243
- | Option | Type | Description |
244
- | --- | --- | --- |
245
- | `baseUrl` | `string` | **Required.** Base URL of the Stately app |
246
- | `apiKey` | `string` | API key for hosted Stately deployments |
247
- | `origin` | `string` | Optional strict target origin for `postMessage`; defaults to permissive wildcard messaging for local/self-hosted testing |
248
- | `assets` | `AssetConfig` | Asset upload configuration |
249
- | `onReady` | `() => void` | Called when the embed is ready |
250
- | `onLoaded` | `(graph) => void` | Called when a machine is loaded |
251
- | `onChange` | `(graph, machineConfig) => void` | Called on every change |
252
- | `onSave` | `(graph, machineConfig) => void` | Called on save |
253
- | `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 |
254
315
 
255
316
  ### Embed methods
256
317
 
@@ -294,20 +355,20 @@ embed.init({
294
355
 
295
356
  `comments` accepts:
296
357
 
297
- | Field | Type | Description |
298
- | --- | --- | --- |
299
- | `roomId` | `string` | **Required.** Liveblocks room identifier |
300
- | `publicApiKey` | `string` | Liveblocks public key |
301
- | `authEndpoint` | `string` | Custom Liveblocks auth endpoint |
302
- | `baseUrl` | `string` | Custom Liveblocks base URL for self-hosting |
303
- | `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 |
304
365
 
305
366
  `unsavedIndicator` accepts:
306
367
 
307
- | Field | Type | Description |
308
- | --- | --- | --- |
309
- | `enabled` | `boolean` | Show the persistent "Save to apply" pill |
310
- | `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 |
311
372
 
312
373
  #### `embed.updateMachine(machine, format?)`
313
374
 
@@ -330,16 +391,18 @@ embed.setSettings({
330
391
 
331
392
  Available core settings:
332
393
 
333
- | Path | Type | Default |
334
- | --- | --- | --- |
335
- | `appearance.colorMode` | `'light' \| 'dark' \| 'system'` | `'dark'` |
336
- | `canvas.showGrid` | `boolean` | `true` |
337
- | `canvas.viewMode` | `'graph' \| 'list'` | `'graph'` |
338
- | `canvas.enableSnapLines` | `boolean` | `true` |
339
- | `canvas.dimUnselected` | `boolean` | `true` |
340
- | `validation.showValidations` | `boolean` | `true` |
341
- | `autolayout.autoEnabled` | `boolean` | `false` |
342
- | `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` |
343
406
 
344
407
  #### `embed.export(format, options?)`
345
408
 
@@ -348,13 +411,13 @@ Export the current machine. Returns a promise.
348
411
  ```ts
349
412
  const xstateCode = await embed.export('xstate', { version: 5 });
350
413
  const digraph = await embed.export('digraph');
351
- const rtk = await embed.export('rtk');
414
+ const redux = await embed.export('redux');
352
415
  const aslYaml = await embed.export('asl-yaml');
353
416
  ```
354
417
 
355
418
  <!-- supported export formats from ExportFormatMap in src/protocol.ts -->
356
419
 
357
- Supported formats: `xstate`, `json`, `digraph`, `mermaid`, `rtk`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
420
+ Supported formats: `xstate`, `json`, `xgraph`, `digraph`, `mermaid`, `redux`, `zustand`, `asl-json`, `asl-yaml`, `scxml`
358
421
 
359
422
  #### `embed.on(event, handler)` / `embed.off(event, handler)`
360
423
 
@@ -399,11 +462,11 @@ const embed = createStatelyEmbed({
399
462
  });
400
463
  ```
401
464
 
402
- | Option | Type | Description |
403
- | --- | --- | --- |
465
+ | Option | Type | Description |
466
+ | ----------------- | ------------------------------------------------------------------------- | ----------------------------------------------------------- |
404
467
  | `onUploadRequest` | `(file: File, context: { stateNodeId: string }) => Promise<UploadResult>` | **Required.** Called when the editor needs to upload a file |
405
- | `accept` | `string[]` | Accepted MIME types. Supports wildcards like `image/*` |
406
- | `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` |
407
470
 
408
471
  `UploadResult`:
409
472
 
@@ -445,6 +508,8 @@ const digraph = toStudioMachine(graph);
445
508
  Other exported helpers:
446
509
 
447
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
448
513
  - `serializeJS()`, `raw()`, and `RawCode` for emitting JavaScript source
449
514
  - `jsonSchemaToTSType()`, `contextSchemaToTSType()`, and `eventsSchemaToTSType()` for generating inline TypeScript types from JSON Schema
450
515
  - `GraphPatch` and `ActionLocation` types from `@statelyai/sdk/patchTypes`
@@ -488,6 +553,9 @@ Installing the package also exposes a `statelyai` binary:
488
553
  ```bash
489
554
  npx statelyai open ./checkout.machine.ts
490
555
 
556
+ statelyai init
557
+ statelyai login
558
+ statelyai auth status
491
559
  statelyai plan ./checkout.machine.ts machine-id
492
560
  statelyai diff ./checkout.machine.ts machine-id --fail-on-changes
493
561
  statelyai pull machine-id ./checkout.machine.ts
@@ -498,20 +566,26 @@ For one-off use, `npx statelyai ...` installs the small `statelyai` CLI package,
498
566
 
499
567
  Available commands:
500
568
 
501
- | Command | Description |
502
- | --- | --- |
503
- | `statelyai plan <source> <target>` | Print a semantic sync summary |
504
- | `statelyai diff <source> <target>` | Diff two locators and optionally fail on changes |
505
- | `statelyai pull <source> <target>` | Materialize a source into a local target file |
506
- | `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 |
507
579
 
508
580
  Common flags:
509
581
 
510
- - `--api-key` for remote machine resolution
582
+ - `--api-key` for remote machine resolution or editor servers that require auth
511
583
  - `--base-url` for self-hosted or non-default Stately deployments
512
584
  - `--fail-on-changes` to return a nonzero exit code when a diff is detected
513
585
 
514
- `statelyai open` also supports `--editor-url`, `--host`, `--port`, `--no-open`, and `--debug`. It watches the local file on disk, updates the visual editor after saved source changes, and writes saved visual edits back to source.
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.
515
589
 
516
590
  ## Transport Helpers
517
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 };