@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/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@usestatemachines/sdk",
3
- "version": "0.4.0",
4
- "description": "TypeScript SDK for State environments",
3
+ "version": "0.6.0",
4
+ "description": "TypeScript SDK for State Machines environments",
5
5
  "license": "MIT",
6
6
  "homepage": "https://usestatemachines.com",
7
- "author": "State",
7
+ "author": "State Machines",
8
8
  "type": "module",
9
9
  "sideEffects": false,
10
10
  "engines": {
@@ -29,7 +29,18 @@
29
29
  "openapi.json",
30
30
  "README.md"
31
31
  ],
32
+ "scripts": {
33
+ "build": "node scripts/clean.mjs && tsgo",
34
+ "prepare": "pnpm build",
35
+ "typecheck": "tsgo -p tsconfig.check.json",
36
+ "lint": "biome ci . && pnpm agents:check && node scripts/source-stamp.mjs --check && node scripts/published-contract.mjs",
37
+ "generate": "speakeasy run -y --skip-versioning --skip-upload-spec --skip-compile && node scripts/source-stamp.mjs --write",
38
+ "test": "vitest run",
39
+ "agents:build": "node scripts/build-agents.mjs",
40
+ "agents:check": "node scripts/build-agents.mjs --check"
41
+ },
32
42
  "dependencies": {
43
+ "yaml": "^2.9.1",
33
44
  "zod": "^3.25.65 || ^4.0.0"
34
45
  },
35
46
  "devDependencies": {
@@ -37,14 +48,5 @@
37
48
  "@types/node": "24.13.4",
38
49
  "@typescript/native-preview": "7.0.0-dev.20260302.1",
39
50
  "vitest": "5.0.1"
40
- },
41
- "scripts": {
42
- "build": "tsgo",
43
- "typecheck": "tsgo -p tsconfig.check.json",
44
- "lint": "biome ci . && pnpm agents:check && node scripts/source-stamp.mjs --check",
45
- "generate": "speakeasy run -y --skip-versioning --skip-upload-spec --skip-compile && node scripts/source-stamp.mjs --write",
46
- "test": "vitest run",
47
- "agents:build": "node scripts/build-agents.mjs",
48
- "agents:check": "node scripts/build-agents.mjs --check"
49
51
  }
50
- }
52
+ }
@@ -1,18 +0,0 @@
1
- import type { CreateEnvironmentInput, CreateEnvironmentInputApp } from '../models/create-environment-input.js';
2
- /** A string is shorthand for `{ key: <the string>, appId: <the string> }`. */
3
- export type AppInput = string | CreateEnvironmentInputApp;
4
- type Common = Omit<CreateEnvironmentInput, 'apps' | 'snapshotId' | 'snapshotAppInstanceKeys'>;
5
- export interface EnvironmentInput extends Common {
6
- /** 1 to 10 apps with unique keys. */
7
- apps: AppInput[];
8
- }
9
- /** Starts from a snapshot: each app keeps the key it had when captured. */
10
- export interface SnapshotEnvironmentInput extends Common {
11
- snapshotId: string;
12
- /** Keys of the snapshot's app instances to restore. Defaults to all. */
13
- snapshotAppInstanceKeys?: string[];
14
- }
15
- export declare function expandApps(input: EnvironmentInput): CreateEnvironmentInput;
16
- export type EnvironmentSource = EnvironmentInput | SnapshotEnvironmentInput | CreateEnvironmentInput;
17
- export declare function expandSource(input: EnvironmentSource): CreateEnvironmentInput;
18
- export {};
@@ -1,39 +0,0 @@
1
- const APP_KEY = /^[a-z][a-z0-9-]{0,39}$/;
2
- export function expandApps(input) {
3
- if (input.apps.length === 0) {
4
- throw new TypeError('Pass at least one app.');
5
- }
6
- const apps = input.apps.map((app) => {
7
- if (typeof app !== 'string') {
8
- return app;
9
- }
10
- if (!APP_KEY.test(app)) {
11
- throw new TypeError(`"${app}" can't be used as an app key; pass { key, appId } instead.`);
12
- }
13
- return { key: app, appId: app };
14
- });
15
- const keys = new Set();
16
- for (const { key } of apps) {
17
- if (keys.has(key)) {
18
- throw new TypeError(`App key "${key}" is used twice.`);
19
- }
20
- keys.add(key);
21
- }
22
- return { ...input, apps };
23
- }
24
- export function expandSource(input) {
25
- const { apps, ...rest } = input;
26
- if (rest.snapshotId === undefined) {
27
- if (rest.snapshotAppInstanceKeys !== undefined) {
28
- throw new TypeError('Pass snapshotAppInstanceKeys with snapshotId.');
29
- }
30
- if (apps === undefined) {
31
- throw new TypeError('Pass apps or snapshotId.');
32
- }
33
- return expandApps({ ...rest, apps });
34
- }
35
- if (apps !== undefined) {
36
- throw new TypeError('Pass apps or snapshotId, not both.');
37
- }
38
- return rest;
39
- }
@@ -1,42 +0,0 @@
1
- import type { Fetcher } from '../lib/http.js';
2
- import type { ApiProfile } from '../models/api-profile.js';
3
- import type { ConnectionSecret } from '../models/connection-secret.js';
4
- /**
5
- * The HTTP header an app's API expects for its actor token, or `null` when the token goes in
6
- * the request body instead: for `SOAP SessionHeader`, as the envelope's `SessionHeader/sessionId`.
7
- */
8
- export declare function formatActorHeader(actorHeader: string, token: string): {
9
- name: string;
10
- value: string;
11
- } | null;
12
- /** A live app connection. `fetch` only reaches paths under `baseUrl`. */
13
- export declare class Connection {
14
- #private;
15
- readonly baseUrl: string;
16
- readonly environmentId: string;
17
- readonly appKey: string;
18
- readonly actorId: string;
19
- readonly api: ApiProfile;
20
- readonly expiresAt: Date;
21
- constructor(baseUrl: string, api: ApiProfile, secret: ConnectionSecret, fetch?: Fetcher);
22
- /**
23
- * The headers the gateway and the app need, for clients that can't use `fetch`. For an API
24
- * whose actor token goes in the request body, such as SOAP, only the environment token.
25
- */
26
- headers(): Record<string, string>;
27
- /**
28
- * The live actor token, for APIs that take it in the request body: for a SOAP API, put it in
29
- * the envelope's `SessionHeader/sessionId`. Treat it as a secret.
30
- */
31
- actorToken(): string;
32
- /** Sends one request to the app. Never retries, never follows redirects, never adds the API key. */
33
- fetch(path: string, init?: RequestInit): Promise<Response>;
34
- toJSON(): {
35
- baseUrl: string;
36
- environmentId: string;
37
- appKey: string;
38
- actorId: string;
39
- api: ApiProfile;
40
- expiresAt: Date;
41
- };
42
- }
@@ -1,133 +0,0 @@
1
- const HTTP_TOKEN = /^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/;
2
- // Salesforce's SOAP API takes the actor token in the envelope, not an HTTP header.
3
- const SOAP_SESSION_HEADER = 'SOAP SessionHeader';
4
- // Visible ASCII only: `Headers` would otherwise echo a bad value, token included, in its error.
5
- const TOKEN_VALUE = /^[\x21-\x7e]+$/;
6
- // Checked on the path part only (C7). Covers protocol-relative starts, backslashes, control
7
- // characters and encoded dots, slashes and backslashes, including double encoding.
8
- const UNSAFE_PATH = /^\/\/|\\|%(?:25)*(?:2e|2f|5c)|\p{Cc}/iu;
9
- const OUTSIDE = 'Connection.fetch only reaches paths under the connection baseUrl.';
10
- /**
11
- * The HTTP header an app's API expects for its actor token, or `null` when the token goes in
12
- * the request body instead: for `SOAP SessionHeader`, as the envelope's `SessionHeader/sessionId`.
13
- */
14
- export function formatActorHeader(actorHeader, token) {
15
- if (actorHeader === SOAP_SESSION_HEADER) {
16
- return null;
17
- }
18
- if (!HTTP_TOKEN.test(actorHeader) ||
19
- actorHeader.toLowerCase().startsWith('x-state-')) {
20
- throw new TypeError('The API profile names an invalid actor header.');
21
- }
22
- return actorHeader.toLowerCase() === 'authorization'
23
- ? { name: 'Authorization', value: `Bearer ${token}` }
24
- : { name: actorHeader, value: token };
25
- }
26
- /** A live app connection. `fetch` only reaches paths under `baseUrl`. */
27
- export class Connection {
28
- baseUrl;
29
- environmentId;
30
- appKey;
31
- actorId;
32
- api;
33
- expiresAt;
34
- #base;
35
- #environmentToken;
36
- #actorToken;
37
- #actor;
38
- #fetch;
39
- constructor(baseUrl, api, secret, fetch) {
40
- const base = URL.canParse(baseUrl) ? new URL(baseUrl) : null;
41
- if (!base ||
42
- !/^https?:$/.test(base.protocol) ||
43
- base.username ||
44
- base.password ||
45
- base.search ||
46
- base.hash) {
47
- throw new TypeError('The connection baseUrl is not a plain http(s) URL.');
48
- }
49
- if (!TOKEN_VALUE.test(secret.environmentToken) ||
50
- !TOKEN_VALUE.test(secret.actorToken)) {
51
- throw new TypeError('The connection tokens are malformed.');
52
- }
53
- if (!base.pathname.endsWith('/')) {
54
- base.pathname += '/';
55
- }
56
- this.#base = base;
57
- this.#environmentToken = secret.environmentToken;
58
- this.#actorToken = secret.actorToken;
59
- this.#actor = formatActorHeader(api.actorHeader, secret.actorToken);
60
- this.#fetch = fetch;
61
- this.baseUrl = base.href;
62
- this.environmentId = secret.environmentId;
63
- this.appKey = secret.appKey;
64
- this.actorId = secret.actorId;
65
- this.api = api;
66
- this.expiresAt = secret.expiresAt;
67
- }
68
- /**
69
- * The headers the gateway and the app need, for clients that can't use `fetch`. For an API
70
- * whose actor token goes in the request body, such as SOAP, only the environment token.
71
- */
72
- headers() {
73
- return {
74
- 'X-State-Environment-Token': this.#environmentToken,
75
- ...(this.#actor ? { [this.#actor.name]: this.#actor.value } : {}),
76
- };
77
- }
78
- /**
79
- * The live actor token, for APIs that take it in the request body: for a SOAP API, put it in
80
- * the envelope's `SessionHeader/sessionId`. Treat it as a secret.
81
- */
82
- actorToken() {
83
- return this.#actorToken;
84
- }
85
- /** Sends one request to the app. Never retries, never follows redirects, never adds the API key. */
86
- async fetch(path, init = {}) {
87
- const url = this.#resolve(path);
88
- const headers = new Headers(init.headers);
89
- for (const name of headers.keys()) {
90
- if (name.startsWith('x-state-')) {
91
- throw new TypeError(`Header ${name} is reserved for State.`);
92
- }
93
- }
94
- // Ours go last so a caller header of the same name can't replace them.
95
- for (const [name, value] of Object.entries(this.headers())) {
96
- headers.set(name, value);
97
- }
98
- const request = new Request(url, { ...init, headers, redirect: 'manual' });
99
- // Called on `globalThis` at use time: a stored unbound `fetch` throws "Illegal invocation" in Workers.
100
- return this.#fetch ? this.#fetch(request) : globalThis.fetch(request);
101
- }
102
- toJSON() {
103
- return {
104
- baseUrl: this.baseUrl,
105
- environmentId: this.environmentId,
106
- appKey: this.appKey,
107
- actorId: this.actorId,
108
- api: this.api,
109
- expiresAt: this.expiresAt,
110
- };
111
- }
112
- #resolve(path) {
113
- const pathPart = path.split(/[?#]/, 1)[0] ?? '';
114
- if (UNSAFE_PATH.test(pathPart)) {
115
- throw new TypeError(OUTSIDE);
116
- }
117
- // A leading `/` means the root of the connection, not of the gateway.
118
- const relative = path.startsWith('/') ? `.${path}` : path;
119
- // `URL` errors carry the input, query included, so they are replaced rather than rethrown.
120
- const url = URL.canParse(relative, this.#base)
121
- ? new URL(relative, this.#base)
122
- : null;
123
- if (!url ||
124
- url.origin !== this.#base.origin ||
125
- url.username ||
126
- url.password ||
127
- !url.pathname.startsWith(this.#base.pathname) ||
128
- UNSAFE_PATH.test(url.pathname)) {
129
- throw new TypeError(OUTSIDE);
130
- }
131
- return url;
132
- }
133
- }
@@ -1,46 +0,0 @@
1
- import type { Environment } from '../models/environment.js';
2
- import type { EnvironmentSnapshot } from '../models/environment-snapshot.js';
3
- import type { ReleaseActor } from '../models/release-actor.js';
4
- import type { CallOptions, CaptureInput, CaptureOptions, ConnectOptions, StateMachines } from './client.js';
5
- import type { Connection } from './connection.js';
6
- import type { WaitOptions } from './wait.js';
7
- /** A started environment. It remains the handle after `suspend()` and `stop()`. */
8
- export declare class RunningEnvironment {
9
- #private;
10
- readonly id: string;
11
- /** The record when `start()` resolved. Use `sm.environments.get(id)` for fresh state. */
12
- readonly environment: Environment;
13
- constructor(sm: StateMachines, environment: Environment);
14
- /**
15
- * actorId defaults to the actor of the environment's declared default connection, or
16
- * else the app's first actor (for Salesforce, the administrator). Pick another from
17
- * actors() to act with that user's permissions.
18
- */
19
- connect(appKey: string, options?: ConnectOptions): Promise<Connection>;
20
- /** The app's users, in the release's order. */
21
- actors(appKey: string, options?: CallOptions): Promise<ReleaseActor[]>;
22
- /** Captures a snapshot in the environment's own workspace and waits until it's `ready`. */
23
- snapshot(input?: CaptureInput, options?: CaptureOptions): Promise<EnvironmentSnapshot>;
24
- /**
25
- * Ends the sandboxes and keeps the data for `resume()`. Doesn't wait: use
26
- * `waitUntilSuspended()` before resuming.
27
- */
28
- suspend(options?: CallOptions): Promise<Environment>;
29
- /** Resolves when the environment is suspended and can resume. */
30
- waitUntilSuspended(options?: WaitOptions): Promise<Environment>;
31
- /** Runs a suspended environment again on its data. Use `waitUntilReady()` before connecting. */
32
- resume(options?: CallOptions): Promise<Environment>;
33
- /** Resolves when the environment is running again. */
34
- waitUntilReady(options?: WaitOptions): Promise<Environment>;
35
- /**
36
- * Ends the environment and discards its data. Safe to call twice. Doesn't wait for
37
- * disposal: use `waitUntilStopped()`.
38
- */
39
- stop(options?: CallOptions): Promise<Environment>;
40
- /** Resolves when the environment ended and every sandbox is confirmed disposed. */
41
- waitUntilStopped(options?: WaitOptions): Promise<Environment>;
42
- toJSON(): {
43
- id: string;
44
- environment: Environment;
45
- };
46
- }
@@ -1,66 +0,0 @@
1
- /** A started environment. It remains the handle after `suspend()` and `stop()`. */
2
- export class RunningEnvironment {
3
- id;
4
- /** The record when `start()` resolved. Use `sm.environments.get(id)` for fresh state. */
5
- environment;
6
- #environments;
7
- #snapshots;
8
- constructor(sm, environment) {
9
- this.id = environment.id;
10
- this.environment = environment;
11
- this.#environments = sm.environments;
12
- this.#snapshots = sm.snapshots;
13
- }
14
- /**
15
- * actorId defaults to the actor of the environment's declared default connection, or
16
- * else the app's first actor (for Salesforce, the administrator). Pick another from
17
- * actors() to act with that user's permissions.
18
- */
19
- connect(appKey, options) {
20
- return this.#environments.connect(this.id, appKey, options);
21
- }
22
- /** The app's users, in the release's order. */
23
- actors(appKey, options) {
24
- return this.#environments.actors(this.id, appKey, options);
25
- }
26
- /** Captures a snapshot in the environment's own workspace and waits until it's `ready`. */
27
- snapshot(input, options = {}) {
28
- return this.#snapshots.capture(this.id, input, {
29
- ...options,
30
- workspaceId: options.workspaceId ?? this.environment.workspaceId,
31
- });
32
- }
33
- /**
34
- * Ends the sandboxes and keeps the data for `resume()`. Doesn't wait: use
35
- * `waitUntilSuspended()` before resuming.
36
- */
37
- suspend(options) {
38
- return this.#environments.suspend(this.id, options);
39
- }
40
- /** Resolves when the environment is suspended and can resume. */
41
- waitUntilSuspended(options) {
42
- return this.#environments.waitUntilSuspended(this.id, options);
43
- }
44
- /** Runs a suspended environment again on its data. Use `waitUntilReady()` before connecting. */
45
- resume(options) {
46
- return this.#environments.resume(this.id, options);
47
- }
48
- /** Resolves when the environment is running again. */
49
- waitUntilReady(options) {
50
- return this.#environments.waitUntilReady(this.id, options);
51
- }
52
- /**
53
- * Ends the environment and discards its data. Safe to call twice. Doesn't wait for
54
- * disposal: use `waitUntilStopped()`.
55
- */
56
- stop(options) {
57
- return this.#environments.stop(this.id, options);
58
- }
59
- /** Resolves when the environment ended and every sandbox is confirmed disposed. */
60
- waitUntilStopped(options) {
61
- return this.#environments.waitUntilStopped(this.id, options);
62
- }
63
- toJSON() {
64
- return { id: this.id, environment: this.environment };
65
- }
66
- }
@@ -1,11 +0,0 @@
1
- import { StateMachinesCore } from "../core.js";
2
- import { RequestOptions } from "../lib/sdks.js";
3
- import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/http-client-errors.js";
4
- import * as errors from "../models/errors/index.js";
5
- import { ResponseValidationError } from "../models/errors/response-validation-error.js";
6
- import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
7
- import { StateMachinesHTTPError } from "../models/errors/state-machines-http-error.js";
8
- import * as operations from "../models/operations/index.js";
9
- import { APIPromise } from "../types/async.js";
10
- import { Result } from "../types/fp.js";
11
- export declare function createEnvironmentDefinition(client: StateMachinesCore, request: operations.CreateEnvironmentDefinitionRequest, options?: RequestOptions): APIPromise<Result<operations.CreateEnvironmentDefinitionResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -1,94 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
- import * as z from "zod/v4-mini";
5
- import { encodeJSON, encodeSimple } from "../lib/encodings.js";
6
- import { matchStatusCode } from "../lib/http.js";
7
- import * as M from "../lib/matchers.js";
8
- import { compactMap } from "../lib/primitives.js";
9
- import { safeParse } from "../lib/schemas.js";
10
- import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
11
- import { pathToFunc } from "../lib/url.js";
12
- import * as errors from "../models/errors/index.js";
13
- import * as operations from "../models/operations/index.js";
14
- import { APIPromise } from "../types/async.js";
15
- export function createEnvironmentDefinition(client, request, options) {
16
- return new APIPromise($do(client, request, options));
17
- }
18
- async function $do(client, request, options) {
19
- const parsed = safeParse(request, (value) => z.parse(operations.CreateEnvironmentDefinitionRequest$outboundSchema, value), "Input validation failed");
20
- if (!parsed.ok) {
21
- return [parsed, { status: "invalid" }];
22
- }
23
- const payload = parsed.value;
24
- const body = encodeJSON("body", payload.body, { explode: true });
25
- const pathParams = {
26
- workspaceId: encodeSimple("workspaceId", payload.workspaceId, {
27
- explode: false,
28
- charEncoding: "percent",
29
- }),
30
- };
31
- const path = pathToFunc("/v1/workspaces/{workspaceId}/environment-definitions")(pathParams);
32
- const headers = new Headers(compactMap({
33
- "Content-Type": "application/json",
34
- Accept: "application/json",
35
- "idempotency-key": encodeSimple("idempotency-key", payload["idempotency-key"], { explode: false, charEncoding: "none" }),
36
- }));
37
- const secConfig = await extractSecurity(client._options.apiKey);
38
- const securityInput = secConfig == null ? {} : { apiKey: secConfig };
39
- const requestSecurity = resolveGlobalSecurity(securityInput);
40
- const context = {
41
- options: client._options,
42
- baseURL: options?.serverURL ?? client._baseURL ?? "",
43
- operationID: "createEnvironmentDefinition",
44
- oAuth2Scopes: null,
45
- resolvedSecurity: requestSecurity,
46
- securitySource: client._options.apiKey,
47
- retryConfig: options?.retries
48
- || client._options.retryConfig
49
- || {
50
- strategy: "backoff",
51
- backoff: {
52
- initialInterval: 1000,
53
- maxInterval: 5000,
54
- exponent: 1.5,
55
- maxElapsedTime: 600000,
56
- },
57
- retryConnectionErrors: true,
58
- }
59
- || { strategy: "none" },
60
- retryCodes: options?.retryCodes || ["502", "503", "504"],
61
- };
62
- const requestRes = client._createRequest(context, {
63
- security: requestSecurity,
64
- method: "POST",
65
- baseURL: options?.serverURL,
66
- path: path,
67
- headers: headers,
68
- body: body,
69
- userAgent: client._options.userAgent,
70
- timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
71
- }, options);
72
- if (!requestRes.ok) {
73
- return [requestRes, { status: "invalid" }];
74
- }
75
- const req = requestRes.value;
76
- const doResult = await client._do(req, {
77
- context,
78
- isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
79
- retryConfig: context.retryConfig,
80
- retryCodes: context.retryCodes,
81
- });
82
- if (!doResult.ok) {
83
- return [doResult, { status: "request-error", request: req }];
84
- }
85
- const response = doResult.value;
86
- const responseFields = {
87
- HttpMeta: { Response: response, Request: req },
88
- };
89
- const [result] = await M.match(M.json(202, operations.CreateEnvironmentDefinitionResponse$inboundSchema), M.jsonErr([400, 401, 403, 404, 409, 413, 422, 429], errors.ErrorResponse$inboundSchema), M.jsonErr([500, 503], errors.ErrorResponse$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
90
- if (!result.ok) {
91
- return [result, { status: "complete", request: req, response }];
92
- }
93
- return [result, { status: "complete", request: req, response }];
94
- }
@@ -1,76 +0,0 @@
1
- /*
2
- * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
- */
4
- import { matchStatusCode } from "../lib/http.js";
5
- import * as M from "../lib/matchers.js";
6
- import { compactMap } from "../lib/primitives.js";
7
- import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js";
8
- import { pathToFunc } from "../lib/url.js";
9
- import * as errors from "../models/errors/index.js";
10
- import * as operations from "../models/operations/index.js";
11
- import { APIPromise } from "../types/async.js";
12
- export function credentialGet(client, options) {
13
- return new APIPromise($do(client, options));
14
- }
15
- async function $do(client, options) {
16
- const path = pathToFunc("/v1/credential")();
17
- const headers = new Headers(compactMap({
18
- Accept: "application/json",
19
- }));
20
- const secConfig = await extractSecurity(client._options.apiKey);
21
- const securityInput = secConfig == null ? {} : { apiKey: secConfig };
22
- const requestSecurity = resolveGlobalSecurity(securityInput);
23
- const context = {
24
- options: client._options,
25
- baseURL: options?.serverURL ?? client._baseURL ?? "",
26
- operationID: "getCredential",
27
- oAuth2Scopes: null,
28
- resolvedSecurity: requestSecurity,
29
- securitySource: client._options.apiKey,
30
- retryConfig: options?.retries
31
- || client._options.retryConfig
32
- || {
33
- strategy: "backoff",
34
- backoff: {
35
- initialInterval: 1000,
36
- maxInterval: 5000,
37
- exponent: 1.5,
38
- maxElapsedTime: 600000,
39
- },
40
- retryConnectionErrors: true,
41
- }
42
- || { strategy: "none" },
43
- retryCodes: options?.retryCodes || ["502", "503", "504"],
44
- };
45
- const requestRes = client._createRequest(context, {
46
- security: requestSecurity,
47
- method: "GET",
48
- baseURL: options?.serverURL,
49
- path: path,
50
- headers: headers,
51
- userAgent: client._options.userAgent,
52
- timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
53
- }, options);
54
- if (!requestRes.ok) {
55
- return [requestRes, { status: "invalid" }];
56
- }
57
- const req = requestRes.value;
58
- const doResult = await client._do(req, {
59
- context,
60
- isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
61
- retryConfig: context.retryConfig,
62
- retryCodes: context.retryCodes,
63
- });
64
- if (!doResult.ok) {
65
- return [doResult, { status: "request-error", request: req }];
66
- }
67
- const response = doResult.value;
68
- const responseFields = {
69
- HttpMeta: { Response: response, Request: req },
70
- };
71
- const [result] = await M.match(M.json(200, operations.GetCredentialResponse$inboundSchema), M.jsonErr([400, 401, 403, 404, 409, 413, 422, 429], errors.ErrorResponse$inboundSchema), M.jsonErr([500, 503], errors.ErrorResponse$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
72
- if (!result.ok) {
73
- return [result, { status: "complete", request: req, response }];
74
- }
75
- return [result, { status: "complete", request: req, response }];
76
- }
@@ -1,11 +0,0 @@
1
- import { StateMachinesCore } from "../core.js";
2
- import { RequestOptions } from "../lib/sdks.js";
3
- import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/http-client-errors.js";
4
- import * as errors from "../models/errors/index.js";
5
- import { ResponseValidationError } from "../models/errors/response-validation-error.js";
6
- import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
7
- import { StateMachinesHTTPError } from "../models/errors/state-machines-http-error.js";
8
- import * as operations from "../models/operations/index.js";
9
- import { APIPromise } from "../types/async.js";
10
- import { Result } from "../types/fp.js";
11
- export declare function environmentsReveal(client: StateMachinesCore, request: operations.RevealConnectionRequest, options?: RequestOptions): APIPromise<Result<operations.RevealConnectionResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -1,11 +0,0 @@
1
- import { StateMachinesCore } from "../core.js";
2
- import { RequestOptions } from "../lib/sdks.js";
3
- import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/http-client-errors.js";
4
- import * as errors from "../models/errors/index.js";
5
- import { ResponseValidationError } from "../models/errors/response-validation-error.js";
6
- import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
7
- import { StateMachinesHTTPError } from "../models/errors/state-machines-http-error.js";
8
- import * as operations from "../models/operations/index.js";
9
- import { APIPromise } from "../types/async.js";
10
- import { Result } from "../types/fp.js";
11
- export declare function environmentsSuspend(client: StateMachinesCore, request: operations.SuspendEnvironmentRequest, options?: RequestOptions): APIPromise<Result<operations.SuspendEnvironmentResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -1,11 +0,0 @@
1
- import { StateMachinesCore } from "../core.js";
2
- import { RequestOptions } from "../lib/sdks.js";
3
- import { ConnectionError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, UnexpectedClientError } from "../models/errors/http-client-errors.js";
4
- import * as errors from "../models/errors/index.js";
5
- import { ResponseValidationError } from "../models/errors/response-validation-error.js";
6
- import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
7
- import { StateMachinesHTTPError } from "../models/errors/state-machines-http-error.js";
8
- import * as operations from "../models/operations/index.js";
9
- import { APIPromise } from "../types/async.js";
10
- import { Result } from "../types/fp.js";
11
- export declare function getEnvironmentExchange(client: StateMachinesCore, request: operations.GetEnvironmentExchangeRequest, options?: RequestOptions): APIPromise<Result<operations.GetEnvironmentExchangeResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;