statelyai 0.4.0 → 0.4.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
@@ -52,6 +52,8 @@ Preview what `push` would do without updating Studio or local files:
52
52
  statelyai push --dry-run
53
53
  ```
54
54
 
55
+ If a saved `// @statelyai id=...` points to a deleted or inaccessible remote machine, `push` will prompt to relink the file as a new remote machine and replace the local id.
56
+
55
57
  6. Pull remote changes back into linked local files:
56
58
 
57
59
  ```bash
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { u as run } from "./cli-DvtWVXpM.mjs";
2
+ import { u as run } from "./cli-DkWxDq0T.mjs";
3
3
 
4
4
  //#region src/bin.ts
5
5
  run();
@@ -12,7 +12,7 @@ import * as crypto from "node:crypto";
12
12
  import * as http from "node:http";
13
13
  import * as https from "node:https";
14
14
  import os from "node:os";
15
- import { createStatelyClient, getStatelyPragma } from "@statelyai/sdk";
15
+ import { StudioApiError, createStatelyClient, getStatelyPragma } from "@statelyai/sdk";
16
16
  import { planSync, pullSync, pushLocalMachineLinks } from "@statelyai/sdk/sync";
17
17
 
18
18
  //#region src/cliHost.ts
@@ -1321,6 +1321,13 @@ function buildMachineEditorUrl(studioUrl, projectId, machineId) {
1321
1321
  url.searchParams.set("machineId", machineId);
1322
1322
  return url.toString();
1323
1323
  }
1324
+ function isRelinkableLinkedMachineError(error) {
1325
+ return error instanceof StudioApiError && (error.status === 403 || error.status === 404);
1326
+ }
1327
+ async function fileHasLinkedMachineId(filePath) {
1328
+ const contents = await fsPromises.readFile(filePath, "utf8");
1329
+ return Boolean(getStatelyPragma(contents, filePath)?.id);
1330
+ }
1324
1331
  async function fileExists(filePath) {
1325
1332
  try {
1326
1333
  await fsPromises.access(filePath);
@@ -1740,14 +1747,38 @@ var PushCommand = class PushCommand extends Command {
1740
1747
  skipped.push(`${file.relativePath}: unsupported format ${file.source.format}`);
1741
1748
  continue;
1742
1749
  }
1743
- const result = await pushLocalMachineLinks({
1744
- source: file.filePath,
1745
- apiKey: resolvedApiKey.apiKey,
1746
- baseUrl: flags["base-url"] ?? config.studioUrl,
1747
- client,
1748
- project: { projectId: config.projectId },
1749
- xstateVersion: Math.max(5, file.source.xstateVersion ?? config.defaultXStateVersion)
1750
- });
1750
+ let result;
1751
+ try {
1752
+ result = await pushLocalMachineLinks({
1753
+ source: file.filePath,
1754
+ apiKey: resolvedApiKey.apiKey,
1755
+ baseUrl: flags["base-url"] ?? config.studioUrl,
1756
+ client,
1757
+ project: { projectId: config.projectId },
1758
+ xstateVersion: Math.max(5, file.source.xstateVersion ?? config.defaultXStateVersion)
1759
+ });
1760
+ } catch (error) {
1761
+ if (isRelinkableLinkedMachineError(error) && await fileHasLinkedMachineId(file.filePath)) {
1762
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
1763
+ skipped.push(`${file.relativePath}: linked remote machine is missing or inaccessible. Re-run interactively to relink it as a new machine.`);
1764
+ continue;
1765
+ }
1766
+ if (!await promptYesNo(`Linked remote machine for ${file.relativePath} is missing or inaccessible. Push it as a new machine and replace the local @statelyai id?`, true)) {
1767
+ skipped.push(`${file.relativePath}: linked remote machine is missing or inaccessible.`);
1768
+ continue;
1769
+ }
1770
+ this.log(`Relinking ${file.relativePath} as a new remote machine...`);
1771
+ result = await pushLocalMachineLinks({
1772
+ source: file.filePath,
1773
+ apiKey: resolvedApiKey.apiKey,
1774
+ baseUrl: flags["base-url"] ?? config.studioUrl,
1775
+ client,
1776
+ project: { projectId: config.projectId },
1777
+ xstateVersion: Math.max(5, file.source.xstateVersion ?? config.defaultXStateVersion),
1778
+ relink: true
1779
+ });
1780
+ } else throw error;
1781
+ }
1751
1782
  if (result.created.length > 0) linked.push(`${file.relativePath}: ${result.created.map(({ machineIndex, machine }) => `${machine.id} [${machineIndex}] ${buildMachineEditorUrl(config.studioUrl, config.projectId, machine.id)}`).join(", ")}`);
1752
1783
  if (result.updated.length > 0) refreshed.push(`${file.relativePath}: ${result.updated.map(({ machineIndex, machine }) => `${machine.id} [${machineIndex}] ${buildMachineEditorUrl(config.studioUrl, config.projectId, machine.id)}`).join(", ")}`);
1753
1784
  for (const entry of result.skipped) skipped.push(`${file.relativePath} [${entry.machineIndex}]: ${entry.reason}`);
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { a as getEnvApiKey, c as isFileGitDirty, d as scanProjectSources, f as createStatelyProjectConfig, i as formatPlanSummary, l as resolveApiKey, n as classifyPushCandidates, o as inferInitProjectName, r as discoverLinkedPullTargets, s as initProject, t as COMMANDS, u as run } from "./cli-DvtWVXpM.mjs";
1
+ import { a as getEnvApiKey, c as isFileGitDirty, d as scanProjectSources, f as createStatelyProjectConfig, i as formatPlanSummary, l as resolveApiKey, n as classifyPushCandidates, o as inferInitProjectName, r as discoverLinkedPullTargets, s as initProject, t as COMMANDS, u as run } from "./cli-DkWxDq0T.mjs";
2
2
 
3
3
  export { COMMANDS, classifyPushCandidates, createStatelyProjectConfig, discoverLinkedPullTargets, formatPlanSummary, getEnvApiKey, inferInitProjectName, initProject, isFileGitDirty, resolveApiKey, run, scanProjectSources };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statelyai",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Command-line tools for Stately",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@oclif/core": "^4.10.3",
24
- "@statelyai/sdk": "0.9.0"
24
+ "@statelyai/sdk": "0.9.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "tsdown": "0.21.0-beta.2",