@usestatemachines/sdk 0.4.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.
Files changed (270) hide show
  1. package/README.md +177 -470
  2. package/agents/SKILL.md +38 -47
  3. package/agents/index.js +7 -7
  4. package/agents/llms.txt +49 -45
  5. package/agents/prompt.md +11 -11
  6. package/esm/extensions/client.d.ts +105 -116
  7. package/esm/extensions/client.js +162 -309
  8. package/esm/extensions/credentials.d.ts +13 -0
  9. package/esm/extensions/credentials.js +73 -0
  10. package/esm/extensions/environment.d.ts +25 -0
  11. package/esm/extensions/environment.js +1 -0
  12. package/esm/extensions/errors.d.ts +42 -75
  13. package/esm/extensions/errors.js +125 -110
  14. package/esm/extensions/index.d.ts +6 -11
  15. package/esm/extensions/index.js +2 -7
  16. package/esm/extensions/wait.d.ts +17 -18
  17. package/esm/extensions/wait.js +60 -56
  18. package/esm/extensions/yaml.d.ts +6 -0
  19. package/esm/extensions/yaml.js +137 -0
  20. package/esm/funcs/{catalog-release.d.ts → apps-list.d.ts} +1 -1
  21. package/esm/funcs/apps-list.js +91 -0
  22. package/esm/funcs/{credential-get.d.ts → apps-versions.d.ts} +1 -1
  23. package/esm/funcs/{workspaces-events.js → apps-versions.js} +6 -7
  24. package/esm/funcs/{environments-get-connection.d.ts → audit-events-list.d.ts} +1 -1
  25. package/esm/funcs/audit-events-list.js +93 -0
  26. package/esm/funcs/{workspaces-events.d.ts → environments-connect.d.ts} +1 -1
  27. package/esm/funcs/{environments-reveal.js → environments-connect.js} +7 -6
  28. package/esm/funcs/environments-create.d.ts +2 -1
  29. package/esm/funcs/environments-create.js +5 -10
  30. package/esm/funcs/{environments-events.d.ts → environments-delete.d.ts} +1 -1
  31. package/esm/funcs/{environments-stop.js → environments-delete.js} +8 -6
  32. package/esm/funcs/environments-get.d.ts +2 -1
  33. package/esm/funcs/environments-get.js +2 -1
  34. package/esm/funcs/environments-list.d.ts +1 -1
  35. package/esm/funcs/environments-list.js +11 -16
  36. package/esm/funcs/environments-pause.d.ts +12 -0
  37. package/esm/funcs/{environments-suspend.js → environments-pause.js} +7 -5
  38. package/esm/funcs/environments-resume.d.ts +2 -1
  39. package/esm/funcs/environments-resume.js +3 -1
  40. package/esm/funcs/environments-update.d.ts +12 -0
  41. package/esm/funcs/{get-environment-position.js → environments-update.js} +10 -8
  42. package/esm/funcs/me.d.ts +11 -0
  43. package/esm/funcs/{catalog-get.js → me.js} +5 -5
  44. package/esm/funcs/{catalog-get.d.ts → requests-body.d.ts} +1 -1
  45. package/esm/funcs/{environments-get-connection.js → requests-body.js} +8 -8
  46. package/esm/funcs/requests-get.d.ts +12 -0
  47. package/esm/funcs/{catalog-release.js → requests-get.js} +7 -6
  48. package/esm/funcs/{environments-stop.d.ts → requests-list.d.ts} +1 -1
  49. package/esm/funcs/{list-environment-history.js → requests-list.js} +15 -12
  50. package/esm/funcs/requests-stats.d.ts +12 -0
  51. package/esm/funcs/{environments-events.js → requests-stats.js} +15 -14
  52. package/esm/funcs/snapshots-create.d.ts +12 -0
  53. package/esm/funcs/{snapshots-capture.js → snapshots-create.js} +6 -11
  54. package/esm/funcs/snapshots-delete.d.ts +2 -1
  55. package/esm/funcs/snapshots-delete.js +2 -1
  56. package/esm/funcs/snapshots-get.d.ts +2 -1
  57. package/esm/funcs/snapshots-get.js +2 -1
  58. package/esm/funcs/snapshots-list.d.ts +1 -1
  59. package/esm/funcs/snapshots-list.js +9 -13
  60. package/esm/funcs/snapshots-update.d.ts +2 -1
  61. package/esm/funcs/snapshots-update.js +2 -1
  62. package/esm/funcs/workspaces-get.d.ts +2 -1
  63. package/esm/funcs/workspaces-get.js +2 -1
  64. package/esm/funcs/workspaces-list.d.ts +1 -1
  65. package/esm/funcs/workspaces-list.js +3 -1
  66. package/esm/lib/config.d.ts +3 -3
  67. package/esm/lib/config.js +3 -3
  68. package/esm/models/actor.d.ts +2 -3
  69. package/esm/models/actor.js +2 -3
  70. package/esm/models/{api-profile.d.ts → api.d.ts} +4 -4
  71. package/esm/models/{api-profile.js → api.js} +4 -5
  72. package/esm/models/app.d.ts +9 -1
  73. package/esm/models/app.js +7 -1
  74. package/esm/models/{event.d.ts → audit-event.d.ts} +6 -6
  75. package/esm/models/{event.js → audit-event.js} +7 -6
  76. package/esm/models/body-preview.d.ts +31 -0
  77. package/esm/models/body-preview.js +34 -0
  78. package/esm/models/create-environment.d.ts +51 -0
  79. package/esm/models/create-environment.js +35 -0
  80. package/esm/models/credentials.d.ts +31 -0
  81. package/esm/models/credentials.js +31 -0
  82. package/esm/models/environment-failure.d.ts +22 -0
  83. package/esm/models/environment-failure.js +25 -0
  84. package/esm/models/environment-status.d.ts +14 -0
  85. package/esm/models/environment-status.js +15 -0
  86. package/esm/models/environment.d.ts +27 -27
  87. package/esm/models/environment.js +28 -27
  88. package/esm/models/error.d.ts +38 -0
  89. package/esm/models/error.js +39 -0
  90. package/esm/models/errors/{error-response.d.ts → error.d.ts} +5 -5
  91. package/esm/models/errors/{error-response.js → error.js} +4 -4
  92. package/esm/models/errors/index.d.ts +1 -1
  93. package/esm/models/errors/index.js +1 -1
  94. package/esm/models/index.d.ts +17 -22
  95. package/esm/models/index.js +17 -22
  96. package/esm/models/me.d.ts +66 -0
  97. package/esm/models/me.js +75 -0
  98. package/esm/models/operations/create-credentials.d.ts +25 -0
  99. package/esm/models/operations/create-credentials.js +20 -0
  100. package/esm/models/operations/create-environment.d.ts +14 -0
  101. package/esm/models/operations/create-environment.js +18 -0
  102. package/esm/models/operations/create-snapshot.d.ts +25 -0
  103. package/esm/models/operations/create-snapshot.js +25 -0
  104. package/esm/models/operations/delete-environment.d.ts +13 -0
  105. package/esm/models/operations/delete-environment.js +17 -0
  106. package/esm/models/operations/delete-snapshot.d.ts +0 -12
  107. package/esm/models/operations/delete-snapshot.js +0 -9
  108. package/esm/models/operations/get-environment.d.ts +0 -12
  109. package/esm/models/operations/get-environment.js +0 -9
  110. package/esm/models/operations/get-request-body.d.ts +21 -0
  111. package/esm/models/operations/get-request-body.js +18 -0
  112. package/esm/models/operations/get-request-stats.d.ts +51 -0
  113. package/esm/models/operations/get-request-stats.js +40 -0
  114. package/esm/models/operations/get-request.d.ts +11 -0
  115. package/esm/models/operations/get-request.js +11 -0
  116. package/esm/models/operations/get-snapshot.d.ts +0 -12
  117. package/esm/models/operations/get-snapshot.js +0 -9
  118. package/esm/models/operations/get-workspace.d.ts +0 -12
  119. package/esm/models/operations/get-workspace.js +0 -9
  120. package/esm/models/operations/index.d.ts +13 -15
  121. package/esm/models/operations/index.js +13 -15
  122. package/esm/models/operations/list-apps.d.ts +26 -0
  123. package/esm/models/operations/list-apps.js +23 -0
  124. package/esm/models/operations/list-audit-events.d.ts +30 -0
  125. package/esm/models/operations/list-audit-events.js +25 -0
  126. package/esm/models/operations/list-environments.d.ts +6 -21
  127. package/esm/models/operations/list-environments.js +3 -16
  128. package/esm/models/operations/list-requests.d.ts +68 -0
  129. package/esm/models/operations/list-requests.js +53 -0
  130. package/esm/models/operations/list-snapshots.d.ts +8 -6
  131. package/esm/models/operations/list-snapshots.js +4 -3
  132. package/esm/models/operations/list-versions.d.ts +28 -0
  133. package/esm/models/operations/list-versions.js +24 -0
  134. package/esm/models/operations/list-workspaces.d.ts +8 -4
  135. package/esm/models/operations/list-workspaces.js +7 -4
  136. package/esm/models/operations/pause-environment.d.ts +13 -0
  137. package/esm/models/operations/pause-environment.js +17 -0
  138. package/esm/models/operations/resume-environment.d.ts +2 -12
  139. package/esm/models/operations/resume-environment.js +8 -11
  140. package/esm/models/operations/update-environment.d.ts +29 -0
  141. package/esm/models/operations/update-environment.js +20 -0
  142. package/esm/models/operations/update-snapshot.d.ts +0 -14
  143. package/esm/models/operations/update-snapshot.js +0 -10
  144. package/esm/models/permission.d.ts +17 -0
  145. package/esm/models/permission.js +18 -0
  146. package/esm/models/principal.d.ts +20 -0
  147. package/esm/models/principal.js +24 -0
  148. package/esm/models/request-detail.d.ts +39 -0
  149. package/esm/models/request-detail.js +38 -0
  150. package/esm/models/request-stats.d.ts +26 -0
  151. package/esm/models/request-stats.js +31 -0
  152. package/esm/models/request.d.ts +30 -0
  153. package/esm/models/request.js +34 -0
  154. package/esm/models/snapshot-status.d.ts +13 -0
  155. package/esm/models/snapshot-status.js +14 -0
  156. package/esm/models/snapshot.d.ts +47 -0
  157. package/esm/models/snapshot.js +54 -0
  158. package/esm/models/version.d.ts +27 -0
  159. package/esm/models/version.js +31 -0
  160. package/esm/models/workspace.d.ts +2 -4
  161. package/esm/models/workspace.js +2 -4
  162. package/esm/sdk/apps.d.ts +6 -0
  163. package/esm/sdk/apps.js +15 -0
  164. package/esm/sdk/audit-events.d.ts +5 -0
  165. package/esm/sdk/audit-events.js +11 -0
  166. package/esm/sdk/environments.d.ts +8 -9
  167. package/esm/sdk/environments.js +19 -23
  168. package/esm/sdk/requests.d.ts +9 -0
  169. package/esm/sdk/requests.js +23 -0
  170. package/esm/sdk/sdk.d.ts +11 -11
  171. package/esm/sdk/sdk.js +16 -23
  172. package/esm/sdk/snapshots.d.ts +6 -5
  173. package/esm/sdk/snapshots.js +7 -7
  174. package/esm/sdk/workspaces.d.ts +1 -2
  175. package/esm/sdk/workspaces.js +0 -4
  176. package/esm/types/smart-union.js +1 -2
  177. package/openapi.json +1630 -2380
  178. package/package.json +15 -13
  179. package/esm/extensions/apps.d.ts +0 -18
  180. package/esm/extensions/apps.js +0 -39
  181. package/esm/extensions/connection.d.ts +0 -42
  182. package/esm/extensions/connection.js +0 -133
  183. package/esm/extensions/running-environment.d.ts +0 -46
  184. package/esm/extensions/running-environment.js +0 -66
  185. package/esm/funcs/create-environment-definition.d.ts +0 -11
  186. package/esm/funcs/create-environment-definition.js +0 -94
  187. package/esm/funcs/credential-get.js +0 -76
  188. package/esm/funcs/environments-reveal.d.ts +0 -11
  189. package/esm/funcs/environments-suspend.d.ts +0 -11
  190. package/esm/funcs/get-environment-exchange.d.ts +0 -11
  191. package/esm/funcs/get-environment-exchange.js +0 -96
  192. package/esm/funcs/get-environment-position.d.ts +0 -11
  193. package/esm/funcs/list-environment-history.d.ts +0 -11
  194. package/esm/funcs/snapshots-capture.d.ts +0 -11
  195. package/esm/models/app-instance-snapshot.d.ts +0 -15
  196. package/esm/models/app-instance-snapshot.js +0 -19
  197. package/esm/models/catalog.d.ts +0 -12
  198. package/esm/models/catalog.js +0 -15
  199. package/esm/models/connection-secret.d.ts +0 -30
  200. package/esm/models/connection-secret.js +0 -31
  201. package/esm/models/connection.d.ts +0 -40
  202. package/esm/models/connection.js +0 -44
  203. package/esm/models/create-environment-input.d.ts +0 -39
  204. package/esm/models/create-environment-input.js +0 -25
  205. package/esm/models/credential-kind.d.ts +0 -9
  206. package/esm/models/credential-kind.js +0 -10
  207. package/esm/models/credential.d.ts +0 -48
  208. package/esm/models/credential.js +0 -44
  209. package/esm/models/environment-app.d.ts +0 -53
  210. package/esm/models/environment-app.js +0 -57
  211. package/esm/models/environment-exchange.d.ts +0 -116
  212. package/esm/models/environment-exchange.js +0 -126
  213. package/esm/models/environment-lifetime.d.ts +0 -10
  214. package/esm/models/environment-lifetime.js +0 -14
  215. package/esm/models/environment-position.d.ts +0 -25
  216. package/esm/models/environment-position.js +0 -32
  217. package/esm/models/environment-snapshot.d.ts +0 -40
  218. package/esm/models/environment-snapshot.js +0 -42
  219. package/esm/models/error-response.d.ts +0 -58
  220. package/esm/models/error-response.js +0 -60
  221. package/esm/models/event-page.d.ts +0 -11
  222. package/esm/models/event-page.js +0 -16
  223. package/esm/models/history-body.d.ts +0 -28
  224. package/esm/models/history-body.js +0 -33
  225. package/esm/models/history-cause.d.ts +0 -48
  226. package/esm/models/history-cause.js +0 -63
  227. package/esm/models/history-position.d.ts +0 -11
  228. package/esm/models/history-position.js +0 -15
  229. package/esm/models/history-transaction.d.ts +0 -16
  230. package/esm/models/history-transaction.js +0 -20
  231. package/esm/models/operations/capture-snapshot.d.ts +0 -41
  232. package/esm/models/operations/capture-snapshot.js +0 -36
  233. package/esm/models/operations/create-environment-definition.d.ts +0 -225
  234. package/esm/models/operations/create-environment-definition.js +0 -149
  235. package/esm/models/operations/create-environments.d.ts +0 -27
  236. package/esm/models/operations/create-environments.js +0 -27
  237. package/esm/models/operations/get-catalog.d.ts +0 -13
  238. package/esm/models/operations/get-catalog.js +0 -13
  239. package/esm/models/operations/get-connection.d.ts +0 -25
  240. package/esm/models/operations/get-connection.js +0 -21
  241. package/esm/models/operations/get-credential.d.ts +0 -13
  242. package/esm/models/operations/get-credential.js +0 -13
  243. package/esm/models/operations/get-environment-exchange.d.ts +0 -25
  244. package/esm/models/operations/get-environment-exchange.js +0 -21
  245. package/esm/models/operations/get-environment-position.d.ts +0 -23
  246. package/esm/models/operations/get-environment-position.js +0 -20
  247. package/esm/models/operations/get-release.d.ts +0 -23
  248. package/esm/models/operations/get-release.js +0 -20
  249. package/esm/models/operations/list-environment-events.d.ts +0 -15
  250. package/esm/models/operations/list-environment-events.js +0 -13
  251. package/esm/models/operations/list-environment-history.d.ts +0 -28
  252. package/esm/models/operations/list-environment-history.js +0 -24
  253. package/esm/models/operations/list-workspace-events.d.ts +0 -15
  254. package/esm/models/operations/list-workspace-events.js +0 -13
  255. package/esm/models/operations/reveal-connection.d.ts +0 -59
  256. package/esm/models/operations/reveal-connection.js +0 -55
  257. package/esm/models/operations/stop-environment.d.ts +0 -23
  258. package/esm/models/operations/stop-environment.js +0 -20
  259. package/esm/models/operations/suspend-environment.d.ts +0 -23
  260. package/esm/models/operations/suspend-environment.js +0 -20
  261. package/esm/models/release-actor.d.ts +0 -11
  262. package/esm/models/release-actor.js +0 -15
  263. package/esm/models/release.d.ts +0 -37
  264. package/esm/models/release.js +0 -39
  265. package/esm/sdk/catalog.d.ts +0 -6
  266. package/esm/sdk/catalog.js +0 -15
  267. package/esm/sdk/credential.d.ts +0 -5
  268. package/esm/sdk/credential.js +0 -11
  269. package/esm/types/discriminated-union.d.ts +0 -24
  270. package/esm/types/discriminated-union.js +0 -60
package/agents/prompt.md CHANGED
@@ -1,26 +1,26 @@
1
1
  Set up State Machines so this project can run code against a disposable replica of a SaaS app, such as Salesforce. Follow these steps in order.
2
2
 
3
- 1. Install the SDK: `npm install @usestatemachines/sdk`. It is ESM only and runs on Node.js 20.20 or later and on Cloudflare Workers, not in browsers.
4
- 2. Check that `STATE_API_KEY` is set without printing it: `test -n "$STATE_API_KEY"`. If it is missing, stop and ask me to set it; the SDK doesn't read `.env` files. In Cloudflare Workers, pass the key as `new StateMachines({ apiKey })`.
5
- 3. Save this quickstart unchanged as `state-quickstart.mts` and run `npx tsx state-quickstart.mts` to confirm the setup. It prints `200` and the org's limits:
3
+ 1. Install the SDK: `npm install @usestatemachines/sdk`. It is ESM only and runs on Node.js, at the versions in its `engines` field, and on Cloudflare Workers, not in browsers.
4
+ 2. Check that `STATEMACHINES_API_KEY` is set without printing it: `test -n "$STATEMACHINES_API_KEY"`. If it is missing, stop and ask me to set it; the SDK doesn't read `.env` files. In Cloudflare Workers, pass the key as `new StateMachines({ apiKey })`.
5
+ 3. Save this quickstart unchanged as `state-quickstart.mts` and run `npx tsx state-quickstart.mts` to confirm the setup. It prints `200` and the Salesforce org's limits:
6
6
 
7
7
  ```ts
8
8
  import { StateMachines } from '@usestatemachines/sdk';
9
9
 
10
- const sm = new StateMachines(); // reads STATE_API_KEY
11
- const env = await sm.environments.start({ apps: ['salesforce'] });
10
+ const sm = new StateMachines(); // reads STATEMACHINES_API_KEY
11
+ const env = await sm.environments.create({ apps: ['salesforce'] });
12
12
 
13
13
  try {
14
- const salesforce = await env.connect('salesforce', { apiId: 'rest' });
14
+ const salesforce = await env.connect('salesforce');
15
15
  const res = await salesforce.fetch('/services/data/v67.0/limits');
16
16
  console.log(res.status, await res.json());
17
17
  } finally {
18
- await env.stop();
18
+ await env.delete();
19
19
  }
20
20
  ```
21
21
 
22
- 4. Adapt it to my task. Log `await sm.catalog.get()` to find each app's ID and the actors and API profiles its release offers; don't guess IDs. Start only the apps the task needs; a string such as `'salesforce'` means `{ key: 'salesforce', appId: 'salesforce' }`. Salesforce always needs an `apiId`. `connect()` acts as the declared default connection's actor, or else the app's first actor, the administrator; to act as a specific user, pass an `actorId` from `await env.actors('salesforce')`. To reuse seeded data, `await env.snapshot()` once, then `sm.environments.start({ snapshotId })`.
23
- 5. Always call `env.stop()` in a `finally`; it ends the environment and discards its data. In CI, then await `env.waitUntilStopped()` so the run fails if cleanup isn't confirmed. If `start()` fails after creating the environment, it stops it; an `EnvironmentFailedError` or `TimeoutError` carries `err.environmentId` and `err.stopped`. If the create itself fails, call `sm.environments.start(input, { idempotencyKey: err.idempotencyKey })` with the same `input`; never retry without the key, which can start a second environment.
24
- 6. Never print, log or commit keys or tokens, including `connection.headers()` and `connection.actorToken()`, which return live tokens.
22
+ 4. Adapt it to my task. Log `await sm.apps.list()` to find each app's ID, and `await sm.apps.versions(appId)` for the actors and APIs of its versions; don't guess IDs. Create only the apps the task needs; a string such as `'salesforce'` names the app and also becomes its name in the environment. `connect()` acts as the app's default actor, the Salesforce administrator; to act as another user, pass an `actorId` from the version's `actors`. To reuse seeded data, create a snapshot once with `await env.snapshots.create()`, then `sm.environments.create({ snapshotId })`.
23
+ 5. Always call `env.delete()` in a `finally`; it deletes the environment and its data. If the start fails, the server deletes the environment itself and `create` throws `EnvironmentFailedError`. Pass your own `idempotencyKey` to `create`; if it throws with no response, call it again with the same input and key.
24
+ 6. Never print, log or commit keys or tokens, including `credentials.token` and `credentials.headers`.
25
25
 
26
- Read more: `node_modules/@usestatemachines/sdk/README.md`, https://state-web.usestatemachines.workers.dev/llms.txt and https://www.npmjs.com/package/@usestatemachines/sdk
26
+ Read more: `node_modules/@usestatemachines/sdk/README.md`, https://app.usestatemachines.com/llms.txt and https://www.npmjs.com/package/@usestatemachines/sdk
@@ -1,149 +1,138 @@
1
- import { type Fetcher, HTTPClient } from '../lib/http.js';
2
- import type { Catalog } from '../models/catalog.js';
3
- import type { Connection as ConnectionDetails } from '../models/connection.js';
4
- import type { ConnectionSecret } from '../models/connection-secret.js';
5
- import type { Credential } from '../models/credential.js';
6
- import type { Environment } from '../models/environment.js';
7
- import type { EnvironmentSnapshot } from '../models/environment-snapshot.js';
8
- import type { EventPage } from '../models/event-page.js';
9
- import type { CaptureSnapshotRequestBody } from '../models/operations/capture-snapshot.js';
1
+ import type { App } from '../models/app.js';
2
+ import type { AuditEvent } from '../models/audit-event.js';
3
+ import type { CreateEnvironment } from '../models/create-environment.js';
4
+ import type { Me } from '../models/me.js';
5
+ import type { GetRequestStatsRequest } from '../models/operations/get-request-stats.js';
6
+ import type { ListAuditEventsRequest } from '../models/operations/list-audit-events.js';
10
7
  import type { ListEnvironmentsRequest } from '../models/operations/list-environments.js';
8
+ import type { ListRequestsRequest } from '../models/operations/list-requests.js';
11
9
  import type { ListSnapshotsRequest } from '../models/operations/list-snapshots.js';
12
10
  import type { ListWorkspacesRequest } from '../models/operations/list-workspaces.js';
13
- import type { UpdateSnapshotRequestBody } from '../models/operations/update-snapshot.js';
14
- import type { Release } from '../models/release.js';
15
- import type { ReleaseActor } from '../models/release-actor.js';
11
+ import type { UpdateEnvironmentRequestBody } from '../models/operations/update-environment.js';
12
+ import type { RequestT as Request } from '../models/request.js';
13
+ import type { RequestDetail } from '../models/request-detail.js';
14
+ import type { RequestStats } from '../models/request-stats.js';
15
+ import type { Snapshot } from '../models/snapshot.js';
16
+ import type { Version } from '../models/version.js';
16
17
  import type { Workspace } from '../models/workspace.js';
17
- import { type EnvironmentSource } from './apps.js';
18
- import { Connection } from './connection.js';
19
- import { RunningEnvironment } from './running-environment.js';
20
- import { type WaitOptions } from './wait.js';
18
+ import { type Credentials } from './credentials.js';
19
+ import type { Environment } from './environment.js';
20
+ import { type KnownEnvironmentStatus, type KnownSnapshotStatus, type WaitOptions } from './wait.js';
21
21
  export interface StateMachinesOptions {
22
- /** Workspace API key. Defaults to `STATE_API_KEY` where a `process` exists. */
22
+ /** An API key or a member's access token. Defaults to `STATEMACHINES_API_KEY` where a `process` exists. */
23
23
  apiKey?: string;
24
- serverURL?: string;
25
- /** Used when a call omits `workspaceId`; otherwise read from the API key. */
24
+ /** Defaults to `https://api.usestatemachines.com`. */
25
+ baseUrl?: string;
26
+ /** The workspace for calls that name none. Member tokens need it; an API key has its own. */
26
27
  workspaceId?: string;
27
- fetch?: Fetcher;
28
- /** Copied, never modified. Can't be combined with `fetch`. */
29
- httpClient?: HTTPClient;
30
- /** Timeout for each attempt of a request; retries get a fresh one. */
31
- timeoutMs?: number;
28
+ fetch?: typeof fetch;
29
+ /** Timeout of each HTTP attempt; a retry gets a fresh one. Defaults to 60 seconds. */
30
+ attemptTimeoutMs?: number;
32
31
  }
33
- export interface CallOptions {
32
+ export interface SignalOptions {
34
33
  signal?: AbortSignal;
35
34
  }
36
- export interface CreateOptions extends CallOptions {
35
+ export interface CreateEnvironmentOptions extends SignalOptions {
36
+ /** Wait until the environment is `running`. Defaults to true. */
37
+ wait?: boolean;
38
+ /** Deadline for the wait. Defaults to 10 minutes. */
39
+ timeoutMs?: number;
40
+ /** A replay with the same key and input returns the same environment. Defaults to a new UUID. */
37
41
  idempotencyKey?: string;
38
- workspaceId?: string;
39
42
  }
40
- export type ListEnvironmentsQuery = Omit<ListEnvironmentsRequest, 'workspaceId'> & {
41
- workspaceId?: string;
42
- };
43
+ export interface ResumeOptions extends SignalOptions {
44
+ /** Wait until the environment is `running`. Defaults to true. */
45
+ wait?: boolean;
46
+ /** Deadline for the wait. Defaults to 10 minutes. */
47
+ timeoutMs?: number;
48
+ }
49
+ export type CreateSnapshotOptions = CreateEnvironmentOptions;
50
+ export interface ConnectOptions {
51
+ /** Defaults to the app's default actor (for Salesforce, the administrator). */
52
+ actorId?: string;
53
+ }
43
54
  export interface Page<T> {
44
55
  data: T[];
45
56
  nextCursor: string | null;
46
57
  }
47
- export interface StartOptions extends CreateOptions {
48
- /** Deadline for the whole wait for readiness. Defaults to 10 minutes. */
49
- readyTimeoutMs?: number;
50
- }
51
- export type CaptureInput = Omit<CaptureSnapshotRequestBody, 'environmentId'>;
52
- /** `readyTimeoutMs` bounds the wait for `ready`, as in `start()`. */
53
- export type CaptureOptions = StartOptions;
54
- export type ListSnapshotsQuery = Omit<ListSnapshotsRequest, 'workspaceId'> & {
55
- workspaceId?: string;
58
+ export type PageQuery = {
59
+ limit?: number;
60
+ cursor?: string;
56
61
  };
57
- export interface ConnectOptions extends CallOptions {
58
- /** Defaults to the actor of the environment's declared default connection, else the app's first actor. */
59
- actorId?: string;
60
- /** Required when the app has more than one API, as Salesforce does. */
61
- apiId?: string;
62
- }
62
+ export type ListEnvironmentsQuery = ListEnvironmentsRequest;
63
+ export type ListSnapshotsQuery = ListSnapshotsRequest;
64
+ export type ListAuditEventsQuery = ListAuditEventsRequest;
65
+ export type ListWorkspacesQuery = ListWorkspacesRequest;
66
+ export type ListRequestsQuery = ListRequestsRequest;
67
+ export type RequestStatsQuery = GetRequestStatsRequest;
63
68
  export declare class StateMachines {
64
69
  #private;
65
70
  constructor(options?: StateMachinesOptions);
66
- readonly credential: {
67
- get: (options?: CallOptions | undefined) => Promise<Credential>;
68
- };
69
- readonly catalog: {
70
- get: (options?: CallOptions | undefined) => Promise<Catalog>;
71
- release: (releaseId: string, options?: CallOptions | undefined) => Promise<Release>;
71
+ /** The caller: its principal, organization, workspace, permissions and limits. */
72
+ me(): Promise<Me>;
73
+ readonly apps: {
74
+ list: (query?: PageQuery) => Promise<Page<App>>;
75
+ /** Published versions, including retired ones. */
76
+ versions: (appId: string, query?: PageQuery) => Promise<Page<Version>>;
72
77
  };
73
78
  readonly workspaces: {
74
- list: (query?: ListWorkspacesRequest, options?: CallOptions | undefined) => Promise<Workspace[]>;
75
- get: (workspaceId: string, options?: CallOptions | undefined) => Promise<Workspace>;
76
- events: (workspaceId: string, query?: {
77
- limit?: number;
78
- cursor?: string;
79
- }, options?: CallOptions | undefined) => Promise<EventPage>;
79
+ list: (query?: ListWorkspacesRequest) => Promise<Page<Workspace>>;
80
+ get: (workspaceId: string) => Promise<Workspace>;
80
81
  };
81
82
  readonly environments: {
82
- list: (query?: ListEnvironmentsQuery, options?: CallOptions | undefined) => Promise<Page<Environment>>;
83
- get: (environmentId: string, options?: CallOptions | undefined) => Promise<Environment>;
84
- /**
85
- * Creates an environment and waits until it's running. If the wait fails, stops the
86
- * environment (unless the caller passed its own `idempotencyKey`), then rethrows the
87
- * error with `environmentId`, `stopped` and `stopError`.
88
- */
89
- start: (input: EnvironmentSource, options?: StartOptions) => Promise<RunningEnvironment>;
90
- /**
91
- * A string app is shorthand for `{ key: <the string>, appId: <the string> }`. Every
92
- * failure carries the `idempotencyKey`; replaying the create with it is safe.
93
- */
94
- create: (input: EnvironmentSource, options?: CreateOptions) => Promise<Environment>;
95
- /** Ends the environment and discards its data. Safe to repeat. */
96
- stop: (environmentId: string, options?: CallOptions | undefined) => Promise<Environment>;
83
+ /** Creates an environment and, unless `wait` is false, waits until it is `running`. */
84
+ create: (input: CreateEnvironment, options?: CreateEnvironmentOptions) => Promise<Environment>;
85
+ /** Newest first. Leaves deleted environments out unless `status` asks for them. */
86
+ list: (query?: ListEnvironmentsRequest) => Promise<Page<Environment>>;
87
+ get: (environmentId: string) => Promise<Environment>;
88
+ /** `labels` replaces the whole map. */
89
+ update: (environmentId: string, body: UpdateEnvironmentRequestBody) => Promise<Environment>;
90
+ /** Takes effect when the API answers: the gateway refuses calls from then on. */
91
+ pause: (environmentId: string, options?: SignalOptions) => Promise<Environment>;
92
+ /** Resumes a paused or failed environment and, unless `wait` is false, waits until it is `running`. */
93
+ resume: (environmentId: string, options?: ResumeOptions) => Promise<Environment>;
94
+ /** Deletes the environment and its data. Safe to repeat. */
95
+ delete: (environmentId: string, options?: SignalOptions) => Promise<Environment>;
97
96
  /**
98
- * Suspends a running environment: its sandboxes end and its data stays for `resume`.
99
- * Its lifetime is paused meanwhile. Use `stop` to end it.
97
+ * Resolves when the environment has `status`. Throws once it cannot get there without
98
+ * another call: `EnvironmentFailedError` if it failed, else `UnexpectedStatusError`.
100
99
  */
101
- suspend: (environmentId: string, options?: CallOptions | undefined) => Promise<Environment>;
102
- /** Queues a suspended environment to run again on the data it was suspended with. */
103
- resume: (environmentId: string, options?: CallOptions | undefined) => Promise<Environment>;
104
- events: (environmentId: string, query?: {
105
- limit?: number;
106
- cursor?: string;
107
- }, options?: CallOptions | undefined) => Promise<EventPage>;
108
- /** The app's users, in the release's order. */
109
- actors: (environmentId: string, appKey: string, options?: CallOptions | undefined) => Promise<ReleaseActor[]>;
110
- getConnection: (environmentId: string, appKey: string, options?: CallOptions | undefined) => Promise<ConnectionDetails>;
111
- reveal: (environmentId: string, appKey: string, actorId: string, options?: CallOptions | undefined) => Promise<ConnectionSecret>;
112
- /** Resolves when the environment is running. Never suspends or stops it. */
113
- waitUntilReady: (environmentId: string, options?: WaitOptions | undefined) => Promise<Environment>;
114
- /** Resolves when the environment is suspended and can resume. */
115
- waitUntilSuspended: (environmentId: string, options?: WaitOptions | undefined) => Promise<Environment>;
116
- /** Resolves when the environment ended and every sandbox is confirmed disposed. */
117
- waitUntilStopped: (environmentId: string, options?: WaitOptions | undefined) => Promise<Environment>;
118
- /**
119
- * actorId defaults to the actor of the environment's declared default connection, or
120
- * else the app's first actor (for Salesforce, the administrator). Pick another from
121
- * actors() to act with that user's permissions.
122
- */
123
- connect: (environmentId: string, appKey: string, options?: ConnectOptions) => Promise<Connection>;
100
+ wait: (environmentId: string, options: WaitOptions<KnownEnvironmentStatus>) => Promise<Environment>;
101
+ /** Credentials for one app of the environment. */
102
+ connect: (environmentId: string, app: string, options?: ConnectOptions) => Promise<Credentials>;
124
103
  };
125
104
  readonly snapshots: {
126
- /** Returns the API's answer at once: it may still be `capturing`. */
127
- create: (environmentId: string, input?: CaptureInput, options?: CreateOptions) => Promise<EnvironmentSnapshot>;
128
- /**
129
- * Creates a snapshot and waits until it's `ready`. Needs `snapshots:create` and
130
- * `snapshots:read`. A failed or timed-out snapshot is never deleted: the error
131
- * carries `snapshotId` and `idempotencyKey`.
132
- */
133
- capture: (environmentId: string, input?: CaptureInput, options?: StartOptions) => Promise<EnvironmentSnapshot>;
134
- /** Resolves when the snapshot is `ready`. Never deletes it. */
135
- waitUntilReady: (snapshotId: string, options?: WaitOptions | undefined) => Promise<EnvironmentSnapshot>;
136
- /** Deleted snapshots too, with `deletedAt` set. */
137
- get: (snapshotId: string, options?: CallOptions | undefined) => Promise<EnvironmentSnapshot>;
138
- /** Newest first. Deleted snapshots are left out. */
139
- list: (query?: ListSnapshotsQuery, options?: CallOptions | undefined) => Promise<Page<EnvironmentSnapshot>>;
105
+ /** Creates a snapshot of a running environment and, unless `wait` is false, waits until it is `ready`. */
106
+ create: (input: {
107
+ environmentId: string;
108
+ name?: string | null;
109
+ }, options?: CreateEnvironmentOptions) => Promise<Snapshot>;
110
+ /** Newest first. Leaves deleted snapshots out unless `status` asks for them. */
111
+ list: (query?: ListSnapshotsRequest) => Promise<Page<Snapshot>>;
112
+ get: (snapshotId: string) => Promise<Snapshot>;
113
+ /** `null` clears the name. */
114
+ update: (snapshotId: string, body: {
115
+ name: string | null;
116
+ }) => Promise<Snapshot>;
117
+ /** A `saving` snapshot cannot be deleted. Safe to repeat. */
118
+ delete: (snapshotId: string) => Promise<Snapshot>;
140
119
  /**
141
- * `null` clears the name. A stale `expectedVersion`, or a deleted snapshot, is a 409
142
- * `version-conflict`; so is a retry of a rename whose first answer was lost.
120
+ * Resolves when the snapshot has `status`. Throws once it cannot get there without
121
+ * another call: `SnapshotFailedError` if it failed, else `UnexpectedStatusError`.
143
122
  */
144
- rename: (snapshotId: string, body: UpdateSnapshotRequestBody, options?: CallOptions | undefined) => Promise<EnvironmentSnapshot>;
145
- /** Marks the snapshot deleted and returns it; safe to repeat. A capturing snapshot is a 409 `not-ready`. */
146
- delete: (snapshotId: string, options?: CallOptions | undefined) => Promise<EnvironmentSnapshot>;
123
+ wait: (snapshotId: string, options: WaitOptions<KnownSnapshotStatus>) => Promise<Snapshot>;
124
+ };
125
+ readonly requests: {
126
+ /** Calls the gateway recorded for one environment, newest first. Recording is best effort. */
127
+ list: (query: ListRequestsRequest) => Promise<Page<Request>>;
128
+ get: (requestId: string) => Promise<RequestDetail>;
129
+ stats: (query: GetRequestStatsRequest) => Promise<RequestStats>;
130
+ /** The recorded body, in full. */
131
+ body: (requestId: string, direction: "request" | "response") => Promise<Uint8Array<ArrayBufferLike>>;
132
+ };
133
+ readonly auditEvents: {
134
+ /** Newest first. An API key that names no filter gets its own workspace. */
135
+ list: (query?: ListAuditEventsRequest) => Promise<Page<AuditEvent>>;
147
136
  };
148
137
  }
149
138
  /**