@usestatemachines/sdk 0.1.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.
Files changed (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +311 -0
  3. package/agents/SKILL.md +90 -0
  4. package/agents/index.d.ts +13 -0
  5. package/agents/index.js +22 -0
  6. package/agents/llms.txt +93 -0
  7. package/agents/prompt.md +49 -0
  8. package/esm/core.d.ts +9 -0
  9. package/esm/core.js +12 -0
  10. package/esm/extensions/client.d.ts +81 -0
  11. package/esm/extensions/client.js +213 -0
  12. package/esm/extensions/connection.d.ts +42 -0
  13. package/esm/extensions/connection.js +133 -0
  14. package/esm/extensions/errors.d.ts +52 -0
  15. package/esm/extensions/errors.js +129 -0
  16. package/esm/extensions/index.d.ts +11 -0
  17. package/esm/extensions/index.js +7 -0
  18. package/esm/extensions/signal.d.ts +14 -0
  19. package/esm/extensions/signal.js +29 -0
  20. package/esm/extensions/wait.d.ts +19 -0
  21. package/esm/extensions/wait.js +102 -0
  22. package/esm/funcs/catalog-get.d.ts +11 -0
  23. package/esm/funcs/catalog-get.js +76 -0
  24. package/esm/funcs/catalog-release.d.ts +11 -0
  25. package/esm/funcs/catalog-release.js +92 -0
  26. package/esm/funcs/credential-get.d.ts +11 -0
  27. package/esm/funcs/credential-get.js +76 -0
  28. package/esm/funcs/environments-create.d.ts +11 -0
  29. package/esm/funcs/environments-create.js +94 -0
  30. package/esm/funcs/environments-events.d.ts +12 -0
  31. package/esm/funcs/environments-events.js +98 -0
  32. package/esm/funcs/environments-get-connection.d.ts +11 -0
  33. package/esm/funcs/environments-get-connection.js +96 -0
  34. package/esm/funcs/environments-get.d.ts +11 -0
  35. package/esm/funcs/environments-get.js +92 -0
  36. package/esm/funcs/environments-list.d.ts +11 -0
  37. package/esm/funcs/environments-list.js +100 -0
  38. package/esm/funcs/environments-reveal.d.ts +11 -0
  39. package/esm/funcs/environments-reveal.js +97 -0
  40. package/esm/funcs/environments-stop.d.ts +11 -0
  41. package/esm/funcs/environments-stop.js +92 -0
  42. package/esm/funcs/workspaces-events.d.ts +12 -0
  43. package/esm/funcs/workspaces-events.js +98 -0
  44. package/esm/funcs/workspaces-get.d.ts +11 -0
  45. package/esm/funcs/workspaces-get.js +92 -0
  46. package/esm/funcs/workspaces-list.d.ts +11 -0
  47. package/esm/funcs/workspaces-list.js +90 -0
  48. package/esm/hooks/hooks.d.ts +24 -0
  49. package/esm/hooks/hooks.js +79 -0
  50. package/esm/hooks/index.d.ts +2 -0
  51. package/esm/hooks/index.js +5 -0
  52. package/esm/hooks/types.d.ts +76 -0
  53. package/esm/hooks/types.js +4 -0
  54. package/esm/index.d.ts +5 -0
  55. package/esm/index.js +7 -0
  56. package/esm/lib/base64.d.ts +9 -0
  57. package/esm/lib/base64.js +30 -0
  58. package/esm/lib/config.d.ts +37 -0
  59. package/esm/lib/config.js +30 -0
  60. package/esm/lib/encodings.d.ts +54 -0
  61. package/esm/lib/encodings.js +406 -0
  62. package/esm/lib/files.d.ts +25 -0
  63. package/esm/lib/files.js +90 -0
  64. package/esm/lib/http.d.ts +66 -0
  65. package/esm/lib/http.js +208 -0
  66. package/esm/lib/logger.d.ts +5 -0
  67. package/esm/lib/logger.js +4 -0
  68. package/esm/lib/matchers.d.ts +58 -0
  69. package/esm/lib/matchers.js +201 -0
  70. package/esm/lib/primitives.d.ts +26 -0
  71. package/esm/lib/primitives.js +119 -0
  72. package/esm/lib/retries.d.ts +37 -0
  73. package/esm/lib/retries.js +156 -0
  74. package/esm/lib/schemas.d.ts +20 -0
  75. package/esm/lib/schemas.js +56 -0
  76. package/esm/lib/sdks.d.ts +62 -0
  77. package/esm/lib/sdks.js +289 -0
  78. package/esm/lib/security.d.ts +83 -0
  79. package/esm/lib/security.js +145 -0
  80. package/esm/lib/url.d.ts +4 -0
  81. package/esm/lib/url.js +23 -0
  82. package/esm/models/actor.d.ts +12 -0
  83. package/esm/models/actor.js +16 -0
  84. package/esm/models/api-profile.d.ts +17 -0
  85. package/esm/models/api-profile.js +22 -0
  86. package/esm/models/app.d.ts +14 -0
  87. package/esm/models/app.js +18 -0
  88. package/esm/models/catalog.d.ts +12 -0
  89. package/esm/models/catalog.js +15 -0
  90. package/esm/models/connection-secret.d.ts +14 -0
  91. package/esm/models/connection-secret.js +18 -0
  92. package/esm/models/connection.d.ts +26 -0
  93. package/esm/models/connection.js +30 -0
  94. package/esm/models/create-environment-input.d.ts +35 -0
  95. package/esm/models/create-environment-input.js +23 -0
  96. package/esm/models/credential-kind.d.ts +9 -0
  97. package/esm/models/credential-kind.js +10 -0
  98. package/esm/models/credential.d.ts +48 -0
  99. package/esm/models/credential.js +44 -0
  100. package/esm/models/environment-app.d.ts +42 -0
  101. package/esm/models/environment-app.js +44 -0
  102. package/esm/models/environment-lifetime.d.ts +10 -0
  103. package/esm/models/environment-lifetime.js +14 -0
  104. package/esm/models/environment.d.ts +47 -0
  105. package/esm/models/environment.js +48 -0
  106. package/esm/models/error-response.d.ts +45 -0
  107. package/esm/models/error-response.js +47 -0
  108. package/esm/models/errors/error-response.d.ts +18 -0
  109. package/esm/models/errors/error-response.js +32 -0
  110. package/esm/models/errors/http-client-errors.d.ts +43 -0
  111. package/esm/models/errors/http-client-errors.js +55 -0
  112. package/esm/models/errors/index.d.ts +6 -0
  113. package/esm/models/errors/index.js +9 -0
  114. package/esm/models/errors/response-validation-error.d.ts +25 -0
  115. package/esm/models/errors/response-validation-error.js +36 -0
  116. package/esm/models/errors/sdk-validation-error.d.ts +20 -0
  117. package/esm/models/errors/sdk-validation-error.js +51 -0
  118. package/esm/models/errors/state-machines-http-error.d.ts +18 -0
  119. package/esm/models/errors/state-machines-http-error.js +25 -0
  120. package/esm/models/errors/unexpected-response-error.d.ts +9 -0
  121. package/esm/models/errors/unexpected-response-error.js +29 -0
  122. package/esm/models/event-page.d.ts +11 -0
  123. package/esm/models/event-page.js +16 -0
  124. package/esm/models/event.d.ts +20 -0
  125. package/esm/models/event.js +22 -0
  126. package/esm/models/index.d.ts +19 -0
  127. package/esm/models/index.js +22 -0
  128. package/esm/models/operations/create-environments.d.ts +27 -0
  129. package/esm/models/operations/create-environments.js +27 -0
  130. package/esm/models/operations/get-catalog.d.ts +13 -0
  131. package/esm/models/operations/get-catalog.js +13 -0
  132. package/esm/models/operations/get-connection.d.ts +25 -0
  133. package/esm/models/operations/get-connection.js +21 -0
  134. package/esm/models/operations/get-credential.d.ts +13 -0
  135. package/esm/models/operations/get-credential.js +13 -0
  136. package/esm/models/operations/get-environment.d.ts +23 -0
  137. package/esm/models/operations/get-environment.js +20 -0
  138. package/esm/models/operations/get-release.d.ts +23 -0
  139. package/esm/models/operations/get-release.js +20 -0
  140. package/esm/models/operations/get-workspace.d.ts +23 -0
  141. package/esm/models/operations/get-workspace.js +20 -0
  142. package/esm/models/operations/index.d.ts +13 -0
  143. package/esm/models/operations/index.js +16 -0
  144. package/esm/models/operations/list-environment-events.d.ts +15 -0
  145. package/esm/models/operations/list-environment-events.js +13 -0
  146. package/esm/models/operations/list-environments.d.ts +49 -0
  147. package/esm/models/operations/list-environments.js +40 -0
  148. package/esm/models/operations/list-workspace-events.d.ts +15 -0
  149. package/esm/models/operations/list-workspace-events.js +13 -0
  150. package/esm/models/operations/list-workspaces.d.ts +32 -0
  151. package/esm/models/operations/list-workspaces.js +27 -0
  152. package/esm/models/operations/reveal-connection.d.ts +37 -0
  153. package/esm/models/operations/reveal-connection.js +29 -0
  154. package/esm/models/operations/stop-environment.d.ts +23 -0
  155. package/esm/models/operations/stop-environment.js +20 -0
  156. package/esm/models/release-actor.d.ts +11 -0
  157. package/esm/models/release-actor.js +15 -0
  158. package/esm/models/release.d.ts +26 -0
  159. package/esm/models/release.js +29 -0
  160. package/esm/models/security.d.ts +11 -0
  161. package/esm/models/security.js +11 -0
  162. package/esm/models/workspace.d.ts +16 -0
  163. package/esm/models/workspace.js +21 -0
  164. package/esm/sdk/catalog.d.ts +6 -0
  165. package/esm/sdk/catalog.js +15 -0
  166. package/esm/sdk/credential.d.ts +5 -0
  167. package/esm/sdk/credential.js +11 -0
  168. package/esm/sdk/environments.d.ts +12 -0
  169. package/esm/sdk/environments.js +35 -0
  170. package/esm/sdk/index.d.ts +1 -0
  171. package/esm/sdk/index.js +4 -0
  172. package/esm/sdk/sdk.d.ts +15 -0
  173. package/esm/sdk/sdk.js +26 -0
  174. package/esm/sdk/workspaces.d.ts +8 -0
  175. package/esm/sdk/workspaces.js +19 -0
  176. package/esm/types/async.d.ts +22 -0
  177. package/esm/types/async.js +27 -0
  178. package/esm/types/blobs.d.ts +3 -0
  179. package/esm/types/blobs.js +24 -0
  180. package/esm/types/const-date-time.d.ts +2 -0
  181. package/esm/types/const-date-time.js +9 -0
  182. package/esm/types/default-to-zero-value.d.ts +11 -0
  183. package/esm/types/default-to-zero-value.js +30 -0
  184. package/esm/types/enums.d.ts +8 -0
  185. package/esm/types/enums.js +26 -0
  186. package/esm/types/fp.d.ts +30 -0
  187. package/esm/types/fp.js +30 -0
  188. package/esm/types/index.d.ts +9 -0
  189. package/esm/types/index.js +9 -0
  190. package/esm/types/operations.d.ts +26 -0
  191. package/esm/types/operations.js +76 -0
  192. package/esm/types/primitives.d.ts +8 -0
  193. package/esm/types/primitives.js +108 -0
  194. package/esm/types/rfcdate.d.ts +20 -0
  195. package/esm/types/rfcdate.js +42 -0
  196. package/esm/types/smart-union.d.ts +6 -0
  197. package/esm/types/smart-union.js +116 -0
  198. package/esm/types/streams.d.ts +1 -0
  199. package/esm/types/streams.js +14 -0
  200. package/esm/types/unrecognized.d.ts +15 -0
  201. package/esm/types/unrecognized.js +30 -0
  202. package/openapi.json +2853 -0
  203. package/package.json +50 -0
@@ -0,0 +1,129 @@
1
+ import { ErrorResponse } from '../models/errors/error-response.js';
2
+ import { ConnectionError, RequestTimeoutError, } from '../models/errors/http-client-errors.js';
3
+ import { ResponseValidationError } from '../models/errors/response-validation-error.js';
4
+ import { StateMachinesHTTPError } from '../models/errors/state-machines-http-error.js';
5
+ /**
6
+ * Any failed API call: an error response, an invalid response, or no response at
7
+ * all (`status` null). The message never includes a response body.
8
+ */
9
+ export class StateMachinesError extends Error {
10
+ name = 'StateMachinesError';
11
+ status;
12
+ code;
13
+ requestId;
14
+ fields;
15
+ /** Milliseconds the server asked the client to wait. */
16
+ retryAfter;
17
+ /** Transient: a 502, 503 or 504, or the request never got a response. */
18
+ retryable;
19
+ /** Set on `environments.create` failures; replay the create with it to recover. */
20
+ idempotencyKey;
21
+ /** Wraps any thrown value. Wrapping a `StateMachinesError` copies it, keeping its cause. */
22
+ constructor(error, extra = {}) {
23
+ const details = error instanceof StateMachinesError ? error : describe(error);
24
+ super(details.message, details.cause === undefined ? undefined : { cause: details.cause });
25
+ this.status = details.status;
26
+ this.code = details.code;
27
+ this.requestId = details.requestId;
28
+ this.fields = details.fields;
29
+ this.retryAfter = details.retryAfter;
30
+ this.retryable = details.retryable;
31
+ const idempotencyKey = extra.idempotencyKey ?? details.idempotencyKey;
32
+ if (idempotencyKey !== undefined) {
33
+ this.idempotencyKey = idempotencyKey;
34
+ }
35
+ }
36
+ }
37
+ export function toStateMachinesError(error) {
38
+ return error instanceof StateMachinesError
39
+ ? error
40
+ : new StateMachinesError(error);
41
+ }
42
+ // Matches the generated retry codes (.speakeasy/overlay.yaml): Cloudflare answers 502 and 504
43
+ // when the API origin is unreachable, and the API answers 503 when it is saturated.
44
+ const retryableStatuses = new Set([502, 503, 504]);
45
+ function describe(error) {
46
+ const empty = {
47
+ status: null,
48
+ code: null,
49
+ requestId: null,
50
+ fields: null,
51
+ retryAfter: null,
52
+ retryable: false,
53
+ };
54
+ if (error instanceof StateMachinesHTTPError) {
55
+ return describeResponse(error);
56
+ }
57
+ if (error instanceof SyntaxError) {
58
+ // A malformed JSON body; V8 quotes the body in the parser's message.
59
+ return { ...empty, message: 'Invalid response from the State API.' };
60
+ }
61
+ if (error instanceof Error) {
62
+ // A `TimeoutError` DOMException is an attempt timeout that fired while the body was read.
63
+ const retryable = error instanceof ConnectionError ||
64
+ error instanceof RequestTimeoutError ||
65
+ error.name === 'TimeoutError';
66
+ return { ...empty, message: error.message, cause: error, retryable };
67
+ }
68
+ return { ...empty, message: String(error), cause: error };
69
+ }
70
+ function describeResponse(error) {
71
+ const status = error.statusCode;
72
+ const body = error instanceof ErrorResponse ? error.error : undefined;
73
+ const success = status >= 200 && status < 300;
74
+ let message = `HTTP ${status} from the State API`;
75
+ if (success || error instanceof ResponseValidationError) {
76
+ message = `Invalid response from the State API (HTTP ${status})`;
77
+ }
78
+ else if (body?.message) {
79
+ message = body.message;
80
+ }
81
+ return {
82
+ message,
83
+ // No cause: generated HTTP errors hold the request (with the API key) and the raw body.
84
+ status,
85
+ code: body?.code ?? null,
86
+ requestId: body?.requestId ?? error.headers.get('x-request-id'),
87
+ fields: body?.fields ?? null,
88
+ retryAfter: retryAfter(error.headers),
89
+ retryable: retryableStatuses.has(status),
90
+ };
91
+ }
92
+ function retryAfter(headers) {
93
+ const value = headers.get('retry-after')?.trim();
94
+ if (!value) {
95
+ return null;
96
+ }
97
+ const seconds = Number(value);
98
+ if (Number.isFinite(seconds)) {
99
+ return Math.max(0, seconds * 1000);
100
+ }
101
+ const date = Date.parse(value);
102
+ return Number.isNaN(date) ? null : Math.max(0, date - Date.now());
103
+ }
104
+ export class EnvironmentFailedError extends Error {
105
+ environment;
106
+ name = 'EnvironmentFailedError';
107
+ constructor(environment) {
108
+ super(`Environment ${environment.id} is ${environment.status} (${environment.stopReason ?? 'no stop reason'}).`);
109
+ this.environment = environment;
110
+ }
111
+ }
112
+ export class DisposalIncompleteError extends Error {
113
+ environment;
114
+ name = 'DisposalIncompleteError';
115
+ constructor(environment) {
116
+ super(`Environment ${environment.id} ended, but not every sandbox was confirmed disposed.`);
117
+ this.environment = environment;
118
+ }
119
+ }
120
+ export class TimeoutError extends Error {
121
+ timeoutMs;
122
+ environment;
123
+ name = 'TimeoutError';
124
+ constructor(timeoutMs, environment) {
125
+ super(`Timed out after ${timeoutMs} ms.`);
126
+ this.timeoutMs = timeoutMs;
127
+ this.environment = environment;
128
+ }
129
+ }
@@ -0,0 +1,11 @@
1
+ export type { Fetcher, HTTPClientOptions } from '../lib/http.js';
2
+ export { HTTPClient } from '../lib/http.js';
3
+ export { ConnectionError, ErrorResponse, HTTPClientError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, ResponseValidationError, SDKValidationError, StateMachinesHTTPError, UnexpectedClientError, UnexpectedResponseError, } from '../models/errors/index.js';
4
+ export type { ApiProfile, App, Catalog, Connection as ConnectionDetails, ConnectionSecret, CreateEnvironmentInput, Credential, Environment, EnvironmentApp, Event, EventPage, Release, ReleaseActor, Workspace, } from '../models/index.js';
5
+ export { Code as ErrorCode, Disposal, EnvironmentStatus, StopReason, } from '../models/index.js';
6
+ export { Status as EnvironmentListStatus } from '../models/operations/list-environments.js';
7
+ export type { CallOptions, ConnectOptions, CreateOptions, ListEnvironmentsQuery, Page, StateMachinesOptions, } from './client.js';
8
+ export { StateMachines } from './client.js';
9
+ export { Connection, formatActorHeader } from './connection.js';
10
+ export { DisposalIncompleteError, EnvironmentFailedError, StateMachinesError, TimeoutError, } from './errors.js';
11
+ export type { WaitOptions } from './wait.js';
@@ -0,0 +1,7 @@
1
+ export { HTTPClient } from '../lib/http.js';
2
+ export { ConnectionError, ErrorResponse, HTTPClientError, InvalidRequestError, RequestAbortedError, RequestTimeoutError, ResponseValidationError, SDKValidationError, StateMachinesHTTPError, UnexpectedClientError, UnexpectedResponseError, } from '../models/errors/index.js';
3
+ export { Code as ErrorCode, Disposal, EnvironmentStatus, StopReason, } from '../models/index.js';
4
+ export { Status as EnvironmentListStatus } from '../models/operations/list-environments.js';
5
+ export { StateMachines } from './client.js';
6
+ export { Connection, formatActorHeader } from './connection.js';
7
+ export { DisposalIncompleteError, EnvironmentFailedError, StateMachinesError, TimeoutError, } from './errors.js';
@@ -0,0 +1,14 @@
1
+ /** A signal that aborts on the parent's abort, after `timeoutMs`, or on `close()`. */
2
+ export interface LinkedSignal {
3
+ readonly signal: AbortSignal;
4
+ /** Releases the timer and the parent listener without aborting. */
5
+ dispose(): void;
6
+ /** Aborts the signal, so anything linked to it releases its resources too. */
7
+ close(): void;
8
+ }
9
+ /**
10
+ * Links with an explicit controller instead of `AbortSignal.any`, which never fired
11
+ * on Node 20.20 in our probes. The timer and the listener hold the controller, so
12
+ * the abort reaches in-flight requests.
13
+ */
14
+ export declare function linkSignal(parent: AbortSignal | undefined, timeoutMs?: number): LinkedSignal;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Links with an explicit controller instead of `AbortSignal.any`, which never fired
3
+ * on Node 20.20 in our probes. The timer and the listener hold the controller, so
4
+ * the abort reaches in-flight requests.
5
+ */
6
+ export function linkSignal(parent, timeoutMs) {
7
+ const controller = new AbortController();
8
+ const timer = timeoutMs === undefined
9
+ ? undefined
10
+ : setTimeout(() => controller.abort(new DOMException(`Timed out after ${timeoutMs} ms.`, 'TimeoutError')), timeoutMs);
11
+ const onAbort = () => controller.abort(parent?.reason);
12
+ const dispose = () => {
13
+ clearTimeout(timer);
14
+ parent?.removeEventListener('abort', onAbort);
15
+ };
16
+ timer?.unref?.();
17
+ controller.signal.addEventListener('abort', dispose, { once: true });
18
+ if (parent?.aborted) {
19
+ onAbort();
20
+ }
21
+ else {
22
+ parent?.addEventListener('abort', onAbort, { once: true });
23
+ }
24
+ return {
25
+ signal: controller.signal,
26
+ dispose,
27
+ close: () => controller.abort(new DOMException('The call settled.', 'AbortError')),
28
+ };
29
+ }
@@ -0,0 +1,19 @@
1
+ import type { Environment } from '../models/environment.js';
2
+ export interface WaitOptions {
3
+ /** Overall deadline for the wait. Defaults to 10 minutes. */
4
+ timeoutMs?: number;
5
+ /** Aborting rejects the wait with `signal.reason`. */
6
+ signal?: AbortSignal;
7
+ }
8
+ type Read = (signal: AbortSignal) => Promise<Environment>;
9
+ type Decide = (environment: Environment) => boolean;
10
+ /**
11
+ * Reads until `done` returns true. `done` throws to end the wait with a failure.
12
+ * Transient read failures are retried with backoff until the deadline.
13
+ */
14
+ export declare function poll(read: Read, done: Decide, options?: WaitOptions): Promise<Environment>;
15
+ /** Resolves on `running`. Never stops the environment. */
16
+ export declare function ready(environment: Environment): boolean;
17
+ /** Resolves once the environment ended and every app's sandbox is confirmed disposed. */
18
+ export declare function disposed(environment: Environment): boolean;
19
+ export {};
@@ -0,0 +1,102 @@
1
+ import { DisposalIncompleteError, EnvironmentFailedError, TimeoutError, toStateMachinesError, } from './errors.js';
2
+ import { linkSignal } from './signal.js';
3
+ const defaultTimeoutMs = 600000;
4
+ const readTimeoutMs = 30000;
5
+ /**
6
+ * Reads until `done` returns true. `done` throws to end the wait with a failure.
7
+ * Transient read failures are retried with backoff until the deadline.
8
+ */
9
+ export async function poll(read, done, options = {}) {
10
+ const { signal } = options;
11
+ const timeoutMs = options.timeoutMs ?? defaultTimeoutMs;
12
+ if (!(timeoutMs >= 0)) {
13
+ throw new RangeError(`timeoutMs must be a non-negative number, got ${timeoutMs}.`);
14
+ }
15
+ const deadline = Date.now() + timeoutMs;
16
+ let last = null;
17
+ for (let attempt = 0;; attempt += 1) {
18
+ signal?.throwIfAborted();
19
+ const remaining = deadline - Date.now();
20
+ if (remaining <= 0) {
21
+ throw new TimeoutError(timeoutMs, last);
22
+ }
23
+ let waitMs = backoff(attempt);
24
+ let environment = null;
25
+ const link = linkSignal(signal, Math.min(readTimeoutMs, remaining));
26
+ try {
27
+ environment = await read(link.signal);
28
+ last = environment;
29
+ }
30
+ catch (error) {
31
+ // Classify by signal state: a stalled body read surfaces as an arbitrary error.
32
+ signal?.throwIfAborted();
33
+ if (Date.now() >= deadline) {
34
+ throw new TimeoutError(timeoutMs, last);
35
+ }
36
+ if (!link.signal.aborted) {
37
+ const failure = toStateMachinesError(error);
38
+ if (!failure.retryable) {
39
+ throw failure;
40
+ }
41
+ waitMs = Math.max(waitMs, failure.retryAfter ?? 0);
42
+ }
43
+ }
44
+ finally {
45
+ link.dispose();
46
+ }
47
+ // A read can settle after an abort or past the deadline; neither may resolve the wait.
48
+ signal?.throwIfAborted();
49
+ if (Date.now() >= deadline) {
50
+ throw new TimeoutError(timeoutMs, last);
51
+ }
52
+ if (environment && done(environment)) {
53
+ return environment;
54
+ }
55
+ await sleep(Math.min(waitMs, deadline - Date.now()), signal);
56
+ }
57
+ }
58
+ /** Resolves on `running`. Never stops the environment. */
59
+ export function ready(environment) {
60
+ switch (environment.status) {
61
+ case 'running':
62
+ return true;
63
+ case 'failed':
64
+ case 'stopping':
65
+ case 'stopped':
66
+ throw new EnvironmentFailedError(environment);
67
+ default:
68
+ return false;
69
+ }
70
+ }
71
+ /** Resolves once the environment ended and every app's sandbox is confirmed disposed. */
72
+ export function disposed(environment) {
73
+ if (environment.status !== 'stopped' && environment.status !== 'failed') {
74
+ return false;
75
+ }
76
+ const unconfirmed = environment.apps.some(({ disposal }) => disposal === 'failed' || disposal === 'unknown');
77
+ if (unconfirmed) {
78
+ throw new DisposalIncompleteError(environment);
79
+ }
80
+ return environment.apps.every((app) => app.disposal === 'complete');
81
+ }
82
+ /** 1 s × 1.5ⁿ, capped at 5 s, with ±20% jitter. */
83
+ function backoff(attempt) {
84
+ return Math.min(5000, 1000 * 1.5 ** attempt) * (0.8 + Math.random() * 0.4);
85
+ }
86
+ function sleep(ms, signal) {
87
+ return new Promise((resolve, reject) => {
88
+ if (signal?.aborted) {
89
+ reject(signal.reason);
90
+ return;
91
+ }
92
+ const onAbort = () => {
93
+ clearTimeout(timer);
94
+ reject(signal?.reason);
95
+ };
96
+ const timer = setTimeout(() => {
97
+ signal?.removeEventListener('abort', onAbort);
98
+ resolve();
99
+ }, ms);
100
+ signal?.addEventListener('abort', onAbort, { once: true });
101
+ });
102
+ }
@@ -0,0 +1,11 @@
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 catalogGet(client: StateMachinesCore, options?: RequestOptions): APIPromise<Result<operations.GetCatalogResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -0,0 +1,76 @@
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 catalogGet(client, options) {
13
+ return new APIPromise($do(client, options));
14
+ }
15
+ async function $do(client, options) {
16
+ const path = pathToFunc("/v1/catalog")();
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: "getCatalog",
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.GetCatalogResponse$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
+ }
@@ -0,0 +1,11 @@
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 catalogRelease(client: StateMachinesCore, request: operations.GetReleaseRequest, options?: RequestOptions): APIPromise<Result<operations.GetReleaseResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
3
+ */
4
+ import * as z from "zod/v4-mini";
5
+ import { 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 catalogRelease(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.GetReleaseRequest$outboundSchema, value), "Input validation failed");
20
+ if (!parsed.ok) {
21
+ return [parsed, { status: "invalid" }];
22
+ }
23
+ const payload = parsed.value;
24
+ const body = null;
25
+ const pathParams = {
26
+ releaseId: encodeSimple("releaseId", payload.releaseId, {
27
+ explode: false,
28
+ charEncoding: "percent",
29
+ }),
30
+ };
31
+ const path = pathToFunc("/v1/catalog/releases/{releaseId}")(pathParams);
32
+ const headers = new Headers(compactMap({
33
+ Accept: "application/json",
34
+ }));
35
+ const secConfig = await extractSecurity(client._options.apiKey);
36
+ const securityInput = secConfig == null ? {} : { apiKey: secConfig };
37
+ const requestSecurity = resolveGlobalSecurity(securityInput);
38
+ const context = {
39
+ options: client._options,
40
+ baseURL: options?.serverURL ?? client._baseURL ?? "",
41
+ operationID: "getRelease",
42
+ oAuth2Scopes: null,
43
+ resolvedSecurity: requestSecurity,
44
+ securitySource: client._options.apiKey,
45
+ retryConfig: options?.retries
46
+ || client._options.retryConfig
47
+ || {
48
+ strategy: "backoff",
49
+ backoff: {
50
+ initialInterval: 1000,
51
+ maxInterval: 5000,
52
+ exponent: 1.5,
53
+ maxElapsedTime: 600000,
54
+ },
55
+ retryConnectionErrors: true,
56
+ }
57
+ || { strategy: "none" },
58
+ retryCodes: options?.retryCodes || ["502", "503", "504"],
59
+ };
60
+ const requestRes = client._createRequest(context, {
61
+ security: requestSecurity,
62
+ method: "GET",
63
+ baseURL: options?.serverURL,
64
+ path: path,
65
+ headers: headers,
66
+ body: body,
67
+ userAgent: client._options.userAgent,
68
+ timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
69
+ }, options);
70
+ if (!requestRes.ok) {
71
+ return [requestRes, { status: "invalid" }];
72
+ }
73
+ const req = requestRes.value;
74
+ const doResult = await client._do(req, {
75
+ context,
76
+ isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
77
+ retryConfig: context.retryConfig,
78
+ retryCodes: context.retryCodes,
79
+ });
80
+ if (!doResult.ok) {
81
+ return [doResult, { status: "request-error", request: req }];
82
+ }
83
+ const response = doResult.value;
84
+ const responseFields = {
85
+ HttpMeta: { Response: response, Request: req },
86
+ };
87
+ const [result] = await M.match(M.json(200, operations.GetReleaseResponse$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 });
88
+ if (!result.ok) {
89
+ return [result, { status: "complete", request: req, response }];
90
+ }
91
+ return [result, { status: "complete", request: req, response }];
92
+ }
@@ -0,0 +1,11 @@
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 credentialGet(client: StateMachinesCore, options?: RequestOptions): APIPromise<Result<operations.GetCredentialResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
@@ -0,0 +1,76 @@
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
+ }
@@ -0,0 +1,11 @@
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 environmentsCreate(client: StateMachinesCore, request: operations.CreateEnvironmentsRequest, options?: RequestOptions): APIPromise<Result<operations.CreateEnvironmentsResponse, errors.ErrorResponse | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;