@usestatemachines/sdk 0.8.1 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/esm/extensions/ui.d.ts +59 -0
- package/esm/extensions/ui.js +153 -0
- package/esm/funcs/launch-ui-session.d.ts +15 -0
- package/esm/funcs/launch-ui-session.js +101 -0
- package/esm/funcs/list-snapshot-creators.d.ts +11 -0
- package/esm/funcs/list-snapshot-creators.js +90 -0
- package/esm/funcs/revoke-ui-session.d.ts +15 -0
- package/esm/funcs/revoke-ui-session.js +104 -0
- package/esm/funcs/snapshots-list.js +3 -0
- package/esm/lib/config.d.ts +2 -2
- package/esm/lib/config.js +2 -2
- package/esm/models/browser-capability.d.ts +12 -0
- package/esm/models/browser-capability.js +16 -0
- package/esm/models/environment.d.ts +8 -0
- package/esm/models/environment.js +9 -0
- package/esm/models/error.d.ts +1 -0
- package/esm/models/error.js +1 -0
- package/esm/models/index.d.ts +5 -0
- package/esm/models/index.js +5 -0
- package/esm/models/launch-ui-session.d.ts +26 -0
- package/esm/models/launch-ui-session.js +16 -0
- package/esm/models/operations/index.d.ts +3 -0
- package/esm/models/operations/index.js +3 -0
- package/esm/models/operations/launch-ui-session.d.ts +16 -0
- package/esm/models/operations/launch-ui-session.js +14 -0
- package/esm/models/operations/list-snapshot-creators.d.ts +23 -0
- package/esm/models/operations/list-snapshot-creators.js +20 -0
- package/esm/models/operations/list-snapshots.d.ts +6 -0
- package/esm/models/operations/list-snapshots.js +3 -0
- package/esm/models/operations/revoke-ui-session.d.ts +15 -0
- package/esm/models/operations/revoke-ui-session.js +13 -0
- package/esm/models/service.d.ts +2 -0
- package/esm/models/service.js +2 -0
- package/esm/models/ui-session-launch.d.ts +21 -0
- package/esm/models/ui-session-launch.js +25 -0
- package/esm/models/ui-session-mode.d.ts +11 -0
- package/esm/models/ui-session-mode.js +12 -0
- package/esm/models/ui-session-revocation.d.ts +12 -0
- package/esm/models/ui-session-revocation.js +16 -0
- package/esm/sdk/sdk.d.ts +10 -0
- package/esm/sdk/sdk.js +18 -0
- package/openapi.json +738 -78
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -146,6 +146,22 @@ actors. A new environment runs each app's default version.
|
|
|
146
146
|
Environments created with `tokenInUrl: true` carry the environment token in each service's `url`
|
|
147
147
|
instead of in its `headers`.
|
|
148
148
|
|
|
149
|
+
## Browser UI sessions
|
|
150
|
+
|
|
151
|
+
`@usestatemachines/sdk/ui` is the only part of the SDK for a browser. It holds no client and no
|
|
152
|
+
credential. Your server launches a UI session with the API key, then gives the launch only to
|
|
153
|
+
the browser of the user it is for. In that browser, `submitLaunch(launch, target)` posts the
|
|
154
|
+
launch's one-use grant into `target`: an iframe for an `embedded` launch, or a window for a
|
|
155
|
+
`page` launch. Open the window in the click handler, such as with
|
|
156
|
+
`window.open('about:blank', name)`, so the browser does not block it.
|
|
157
|
+
|
|
158
|
+
`listenToSession(launch, iframe, onMessage, { signal })` calls `onMessage` with `ready`,
|
|
159
|
+
`failure` and `logout`. It passes only messages from the session's origin, from that iframe and
|
|
160
|
+
for that session. A browser can block the session's cookie in a frame, and a blocked frame looks
|
|
161
|
+
loaded to your page. So wait for `ready` with a timeout, and on `failure` or the timeout, offer
|
|
162
|
+
a `page` launch. The page that posts the grant must send its `Origin`, so do not serve it with
|
|
163
|
+
`Referrer-Policy: no-referrer`.
|
|
164
|
+
|
|
149
165
|
## Snapshots
|
|
150
166
|
|
|
151
167
|
```ts
|
|
@@ -251,7 +267,8 @@ to })` counts them. Recording is best effort.
|
|
|
251
267
|
|
|
252
268
|
- **Node.js**, at the versions that `engines` in `package.json` allows. ESM only.
|
|
253
269
|
- **Cloudflare Workers.** Pass `apiKey` explicitly.
|
|
254
|
-
- **Not browsers.** Never ship an API key to a browser.
|
|
270
|
+
- **Not browsers.** Never ship an API key to a browser. Only `@usestatemachines/sdk/ui` runs
|
|
271
|
+
in a browser.
|
|
255
272
|
|
|
256
273
|
TypeScript consumers need `lib: ["DOM"]` or `@types/node`, for the `fetch`, `Request` and
|
|
257
274
|
`Response` types. While the version is `0.x`, a minor version may include breaking changes. Enums
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser helpers for a UI session that a trusted server launched. This
|
|
3
|
+
* module imports nothing: it holds no management client, API key or token,
|
|
4
|
+
* so a browser bundle that imports it holds none either.
|
|
5
|
+
*/
|
|
6
|
+
/** The fields of a launch that a browser needs. A launch from the API has them all. */
|
|
7
|
+
export interface UiLaunch {
|
|
8
|
+
readonly sessionId: string;
|
|
9
|
+
/** `embedded` posts into an iframe; `page` posts into a window of its own. */
|
|
10
|
+
readonly mode: 'embedded' | 'page';
|
|
11
|
+
/** The session's own origin. */
|
|
12
|
+
readonly origin: string;
|
|
13
|
+
/** Where the browser posts the grant. It is on `origin`. */
|
|
14
|
+
readonly exchangeUrl: string;
|
|
15
|
+
/** One use. Post it once, from the origin the launch named. */
|
|
16
|
+
readonly grant: string;
|
|
17
|
+
}
|
|
18
|
+
/** A message that an embedded session posts to the page that frames it. */
|
|
19
|
+
export type UiSessionMessage = {
|
|
20
|
+
readonly event: 'ready';
|
|
21
|
+
readonly sessionId: string;
|
|
22
|
+
} | {
|
|
23
|
+
readonly event: 'logout';
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly event: 'failure';
|
|
27
|
+
/** Null when the session failed before it knew its ID, such as when the browser blocked its cookie. */
|
|
28
|
+
readonly sessionId: string | null;
|
|
29
|
+
/** A short code, such as `ui_access_required`, or null. */
|
|
30
|
+
readonly reason: string | null;
|
|
31
|
+
};
|
|
32
|
+
export interface ListenOptions {
|
|
33
|
+
/** Removes the listener when it aborts. */
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Posts the launch's grant to its exchange URL, targeted at `target`: an
|
|
38
|
+
* iframe for an `embedded` launch, or a window for a `page` launch. Open the
|
|
39
|
+
* window in the click handler, such as with `window.open('about:blank',
|
|
40
|
+
* name)`, so the browser does not block it. The session then loads in
|
|
41
|
+
* `target`, and a window loses its `opener`. A launch posts once; a second
|
|
42
|
+
* post of the same grant is refused.
|
|
43
|
+
*
|
|
44
|
+
* The posting page must send its `Origin`, so its `Referrer-Policy` must not
|
|
45
|
+
* be `no-referrer`.
|
|
46
|
+
*/
|
|
47
|
+
export declare function submitLaunch(launch: UiLaunch, target: HTMLIFrameElement | Window): void;
|
|
48
|
+
/**
|
|
49
|
+
* The session message in `data`, or null when `data` is not exactly one of
|
|
50
|
+
* the messages for `sessionId`. A failure may carry a null session ID.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parseSessionMessage(data: unknown, sessionId: string): UiSessionMessage | null;
|
|
53
|
+
/**
|
|
54
|
+
* Calls `onMessage` with each message that the session in `source` posts:
|
|
55
|
+
* only from the launch's exact origin, only from `source`'s window, and only
|
|
56
|
+
* for the launch's session. Every other message is ignored. Answers the
|
|
57
|
+
* function that removes the listener.
|
|
58
|
+
*/
|
|
59
|
+
export declare function listenToSession(launch: Pick<UiLaunch, 'sessionId' | 'origin'>, source: HTMLIFrameElement | Window, onMessage: (message: UiSessionMessage) => void, options?: ListenOptions): () => void;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser helpers for a UI session that a trusted server launched. This
|
|
3
|
+
* module imports nothing: it holds no management client, API key or token,
|
|
4
|
+
* so a browser bundle that imports it holds none either.
|
|
5
|
+
*/
|
|
6
|
+
const MESSAGE_TYPE = 'state-ui';
|
|
7
|
+
const EVENTS = new Set(['ready', 'logout', 'failure']);
|
|
8
|
+
const REASON = /^[a-z][a-z0-9_]{0,63}$/;
|
|
9
|
+
function isFrame(target) {
|
|
10
|
+
return typeof target.tagName === 'string';
|
|
11
|
+
}
|
|
12
|
+
function sessionOrigin(launch) {
|
|
13
|
+
const origin = URL.canParse(launch.origin) ? new URL(launch.origin) : null;
|
|
14
|
+
const exchange = URL.canParse(launch.exchangeUrl)
|
|
15
|
+
? new URL(launch.exchangeUrl)
|
|
16
|
+
: null;
|
|
17
|
+
if (!origin ||
|
|
18
|
+
!exchange ||
|
|
19
|
+
origin.protocol !== 'https:' ||
|
|
20
|
+
origin.origin !== launch.origin ||
|
|
21
|
+
exchange.origin !== launch.origin) {
|
|
22
|
+
throw new TypeError('The launch must name an HTTPS session origin and an exchange URL on it.');
|
|
23
|
+
}
|
|
24
|
+
return launch.origin;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Posts the launch's grant to its exchange URL, targeted at `target`: an
|
|
28
|
+
* iframe for an `embedded` launch, or a window for a `page` launch. Open the
|
|
29
|
+
* window in the click handler, such as with `window.open('about:blank',
|
|
30
|
+
* name)`, so the browser does not block it. The session then loads in
|
|
31
|
+
* `target`, and a window loses its `opener`. A launch posts once; a second
|
|
32
|
+
* post of the same grant is refused.
|
|
33
|
+
*
|
|
34
|
+
* The posting page must send its `Origin`, so its `Referrer-Policy` must not
|
|
35
|
+
* be `no-referrer`.
|
|
36
|
+
*/
|
|
37
|
+
export function submitLaunch(launch, target) {
|
|
38
|
+
sessionOrigin(launch);
|
|
39
|
+
const frame = isFrame(target);
|
|
40
|
+
if (frame !== (launch.mode === 'embedded')) {
|
|
41
|
+
throw new TypeError(launch.mode === 'embedded'
|
|
42
|
+
? 'Post an embedded launch into an iframe.'
|
|
43
|
+
: 'Post a page launch into a window.');
|
|
44
|
+
}
|
|
45
|
+
if (!target.name) {
|
|
46
|
+
const name = `state-ui-${launch.sessionId}`;
|
|
47
|
+
target.name = name;
|
|
48
|
+
if (frame) {
|
|
49
|
+
// Chromium and WebKit keep the name an iframe's frame had when it was
|
|
50
|
+
// attached, so a later name attribute alone sends the form to a new
|
|
51
|
+
// window. Name the frame's window too.
|
|
52
|
+
try {
|
|
53
|
+
target.contentWindow.name = name;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
throw new TypeError('Name the iframe before you attach it, or let the page reach its frame.');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const document = frame ? target.ownerDocument : globalThis.document;
|
|
61
|
+
const form = document.createElement('form');
|
|
62
|
+
form.method = 'post';
|
|
63
|
+
form.action = launch.exchangeUrl;
|
|
64
|
+
form.target = target.name;
|
|
65
|
+
form.hidden = true;
|
|
66
|
+
const grant = document.createElement('input');
|
|
67
|
+
grant.type = 'hidden';
|
|
68
|
+
grant.name = 'grant';
|
|
69
|
+
grant.value = launch.grant;
|
|
70
|
+
form.append(grant);
|
|
71
|
+
document.body.append(form);
|
|
72
|
+
try {
|
|
73
|
+
form.submit();
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
form.remove();
|
|
77
|
+
}
|
|
78
|
+
if (!frame) {
|
|
79
|
+
// The session page gets no handle on this page. Clearing it before the
|
|
80
|
+
// submit makes WebKit open another window instead.
|
|
81
|
+
target.opener = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function hasExactKeys(value, keys) {
|
|
85
|
+
const own = Object.keys(value);
|
|
86
|
+
return (own.length === keys.length && keys.every((key) => Object.hasOwn(value, key)));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The session message in `data`, or null when `data` is not exactly one of
|
|
90
|
+
* the messages for `sessionId`. A failure may carry a null session ID.
|
|
91
|
+
*/
|
|
92
|
+
export function parseSessionMessage(data, sessionId) {
|
|
93
|
+
if (typeof data !== 'object' || data === null || Array.isArray(data)) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const fields = data;
|
|
97
|
+
const { type, event, reason, sessionId: id } = fields;
|
|
98
|
+
if (type !== MESSAGE_TYPE || !EVENTS.has(event)) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
if (event === 'failure') {
|
|
102
|
+
if (!(hasExactKeys(fields, ['type', 'event', 'sessionId']) ||
|
|
103
|
+
hasExactKeys(fields, ['type', 'event', 'sessionId', 'reason'])) ||
|
|
104
|
+
(id !== sessionId && id !== null) ||
|
|
105
|
+
(reason !== undefined &&
|
|
106
|
+
!(typeof reason === 'string' && REASON.test(reason)))) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
event,
|
|
111
|
+
sessionId: id,
|
|
112
|
+
reason: typeof reason === 'string' ? reason : null,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return hasExactKeys(fields, ['type', 'event', 'sessionId']) &&
|
|
116
|
+
id === sessionId
|
|
117
|
+
? { event: event, sessionId }
|
|
118
|
+
: null;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Calls `onMessage` with each message that the session in `source` posts:
|
|
122
|
+
* only from the launch's exact origin, only from `source`'s window, and only
|
|
123
|
+
* for the launch's session. Every other message is ignored. Answers the
|
|
124
|
+
* function that removes the listener.
|
|
125
|
+
*/
|
|
126
|
+
export function listenToSession(launch, source, onMessage, options = {}) {
|
|
127
|
+
const launcher = isFrame(source)
|
|
128
|
+
? source.ownerDocument.defaultView
|
|
129
|
+
: globalThis.window;
|
|
130
|
+
if (!launcher) {
|
|
131
|
+
throw new TypeError('The iframe is not in a window.');
|
|
132
|
+
}
|
|
133
|
+
const listener = (event) => {
|
|
134
|
+
const from = isFrame(source) ? source.contentWindow : source;
|
|
135
|
+
if (event.origin !== launch.origin || !from || event.source !== from) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const message = parseSessionMessage(event.data, launch.sessionId);
|
|
139
|
+
if (message) {
|
|
140
|
+
onMessage(message);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const remove = () => {
|
|
144
|
+
launcher.removeEventListener('message', listener);
|
|
145
|
+
options.signal?.removeEventListener('abort', remove);
|
|
146
|
+
};
|
|
147
|
+
if (options.signal?.aborted) {
|
|
148
|
+
return remove;
|
|
149
|
+
}
|
|
150
|
+
launcher.addEventListener('message', listener);
|
|
151
|
+
options.signal?.addEventListener('abort', remove, { once: true });
|
|
152
|
+
return remove;
|
|
153
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 models from "../models/index.js";
|
|
9
|
+
import * as operations from "../models/operations/index.js";
|
|
10
|
+
import { APIPromise } from "../types/async.js";
|
|
11
|
+
import { Result } from "../types/fp.js";
|
|
12
|
+
/**
|
|
13
|
+
* Launches a browser session of one actor in an app's UI. The answer holds a one-use grant and no reusable credential. Return it only to the browser of the user it is for, which posts the grant to `exchangeUrl` from `launcherOrigin`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function launchUiSession(client: StateMachinesCore, request: operations.LaunchUiSessionRequest, options?: RequestOptions): APIPromise<Result<models.UiSessionLaunch, errors.ErrorT | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
|
|
@@ -0,0 +1,101 @@
|
|
|
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 models from "../models/index.js";
|
|
14
|
+
import * as operations from "../models/operations/index.js";
|
|
15
|
+
import { APIPromise } from "../types/async.js";
|
|
16
|
+
/**
|
|
17
|
+
* Launches a browser session of one actor in an app's UI. The answer holds a one-use grant and no reusable credential. Return it only to the browser of the user it is for, which posts the grant to `exchangeUrl` from `launcherOrigin`.
|
|
18
|
+
*/
|
|
19
|
+
export function launchUiSession(client, request, options) {
|
|
20
|
+
return new APIPromise($do(client, request, options));
|
|
21
|
+
}
|
|
22
|
+
async function $do(client, request, options) {
|
|
23
|
+
const parsed = safeParse(request, (value) => z.parse(operations.LaunchUiSessionRequest$outboundSchema, value), "Input validation failed");
|
|
24
|
+
if (!parsed.ok) {
|
|
25
|
+
return [parsed, { status: "invalid" }];
|
|
26
|
+
}
|
|
27
|
+
const payload = parsed.value;
|
|
28
|
+
const body = encodeJSON("body", payload.body, { explode: true });
|
|
29
|
+
const pathParams = {
|
|
30
|
+
appName: encodeSimple("appName", payload.appName, {
|
|
31
|
+
explode: false,
|
|
32
|
+
charEncoding: "percent",
|
|
33
|
+
}),
|
|
34
|
+
environmentId: encodeSimple("environmentId", payload.environmentId, {
|
|
35
|
+
explode: false,
|
|
36
|
+
charEncoding: "percent",
|
|
37
|
+
}),
|
|
38
|
+
};
|
|
39
|
+
const path = pathToFunc("/v1/environments/{environmentId}/apps/{appName}/ui-sessions")(pathParams);
|
|
40
|
+
const headers = new Headers(compactMap({
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
Accept: "application/json",
|
|
43
|
+
}));
|
|
44
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
45
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
46
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
47
|
+
const context = {
|
|
48
|
+
options: client._options,
|
|
49
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
50
|
+
operationID: "launchUiSession",
|
|
51
|
+
oAuth2Scopes: null,
|
|
52
|
+
resolvedSecurity: requestSecurity,
|
|
53
|
+
securitySource: client._options.apiKey,
|
|
54
|
+
retryConfig: options?.retries
|
|
55
|
+
|| client._options.retryConfig
|
|
56
|
+
|| {
|
|
57
|
+
strategy: "backoff",
|
|
58
|
+
backoff: {
|
|
59
|
+
initialInterval: 1000,
|
|
60
|
+
maxInterval: 5000,
|
|
61
|
+
exponent: 1.5,
|
|
62
|
+
maxElapsedTime: 600000,
|
|
63
|
+
},
|
|
64
|
+
retryConnectionErrors: true,
|
|
65
|
+
}
|
|
66
|
+
|| { strategy: "none" },
|
|
67
|
+
retryCodes: options?.retryCodes || ["502", "503", "504"],
|
|
68
|
+
};
|
|
69
|
+
const requestRes = client._createRequest(context, {
|
|
70
|
+
security: requestSecurity,
|
|
71
|
+
method: "POST",
|
|
72
|
+
baseURL: options?.serverURL,
|
|
73
|
+
path: path,
|
|
74
|
+
headers: headers,
|
|
75
|
+
body: body,
|
|
76
|
+
userAgent: client._options.userAgent,
|
|
77
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
78
|
+
}, options);
|
|
79
|
+
if (!requestRes.ok) {
|
|
80
|
+
return [requestRes, { status: "invalid" }];
|
|
81
|
+
}
|
|
82
|
+
const req = requestRes.value;
|
|
83
|
+
const doResult = await client._do(req, {
|
|
84
|
+
context,
|
|
85
|
+
isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
|
|
86
|
+
retryConfig: context.retryConfig,
|
|
87
|
+
retryCodes: context.retryCodes,
|
|
88
|
+
});
|
|
89
|
+
if (!doResult.ok) {
|
|
90
|
+
return [doResult, { status: "request-error", request: req }];
|
|
91
|
+
}
|
|
92
|
+
const response = doResult.value;
|
|
93
|
+
const responseFields = {
|
|
94
|
+
HttpMeta: { Response: response, Request: req },
|
|
95
|
+
};
|
|
96
|
+
const [result] = await M.match(M.json(201, models.UiSessionLaunch$inboundSchema), M.jsonErr([400, 401, 403, 404, 409, 413, 422, 429], errors.ErrorT$inboundSchema), M.jsonErr([500, 503], errors.ErrorT$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
|
|
97
|
+
if (!result.ok) {
|
|
98
|
+
return [result, { status: "complete", request: req, response }];
|
|
99
|
+
}
|
|
100
|
+
return [result, { status: "complete", request: req, response }];
|
|
101
|
+
}
|
|
@@ -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 listSnapshotCreators(client: StateMachinesCore, request?: operations.ListSnapshotCreatorsRequest | undefined, options?: RequestOptions): APIPromise<Result<operations.ListSnapshotCreatorsResponse, errors.ErrorT | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4-mini";
|
|
5
|
+
import { encodeFormQuery } 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 listSnapshotCreators(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(z.optional(operations.ListSnapshotCreatorsRequest$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 path = pathToFunc("/v1/snapshots/creators")();
|
|
26
|
+
const query = encodeFormQuery({
|
|
27
|
+
"workspaceId": payload?.workspaceId,
|
|
28
|
+
});
|
|
29
|
+
const headers = new Headers(compactMap({
|
|
30
|
+
Accept: "application/json",
|
|
31
|
+
}));
|
|
32
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
33
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
34
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
35
|
+
const context = {
|
|
36
|
+
options: client._options,
|
|
37
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
38
|
+
operationID: "listSnapshotCreators",
|
|
39
|
+
oAuth2Scopes: null,
|
|
40
|
+
resolvedSecurity: requestSecurity,
|
|
41
|
+
securitySource: client._options.apiKey,
|
|
42
|
+
retryConfig: options?.retries
|
|
43
|
+
|| client._options.retryConfig
|
|
44
|
+
|| {
|
|
45
|
+
strategy: "backoff",
|
|
46
|
+
backoff: {
|
|
47
|
+
initialInterval: 1000,
|
|
48
|
+
maxInterval: 5000,
|
|
49
|
+
exponent: 1.5,
|
|
50
|
+
maxElapsedTime: 600000,
|
|
51
|
+
},
|
|
52
|
+
retryConnectionErrors: true,
|
|
53
|
+
}
|
|
54
|
+
|| { strategy: "none" },
|
|
55
|
+
retryCodes: options?.retryCodes || ["502", "503", "504"],
|
|
56
|
+
};
|
|
57
|
+
const requestRes = client._createRequest(context, {
|
|
58
|
+
security: requestSecurity,
|
|
59
|
+
method: "GET",
|
|
60
|
+
baseURL: options?.serverURL,
|
|
61
|
+
path: path,
|
|
62
|
+
headers: headers,
|
|
63
|
+
query: query,
|
|
64
|
+
body: body,
|
|
65
|
+
userAgent: client._options.userAgent,
|
|
66
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
67
|
+
}, options);
|
|
68
|
+
if (!requestRes.ok) {
|
|
69
|
+
return [requestRes, { status: "invalid" }];
|
|
70
|
+
}
|
|
71
|
+
const req = requestRes.value;
|
|
72
|
+
const doResult = await client._do(req, {
|
|
73
|
+
context,
|
|
74
|
+
isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
|
|
75
|
+
retryConfig: context.retryConfig,
|
|
76
|
+
retryCodes: context.retryCodes,
|
|
77
|
+
});
|
|
78
|
+
if (!doResult.ok) {
|
|
79
|
+
return [doResult, { status: "request-error", request: req }];
|
|
80
|
+
}
|
|
81
|
+
const response = doResult.value;
|
|
82
|
+
const responseFields = {
|
|
83
|
+
HttpMeta: { Response: response, Request: req },
|
|
84
|
+
};
|
|
85
|
+
const [result] = await M.match(M.json(200, operations.ListSnapshotCreatorsResponse$inboundSchema), M.jsonErr([400, 401, 403, 404, 409, 413, 422, 429], errors.ErrorT$inboundSchema), M.jsonErr([500, 503], errors.ErrorT$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
|
|
86
|
+
if (!result.ok) {
|
|
87
|
+
return [result, { status: "complete", request: req, response }];
|
|
88
|
+
}
|
|
89
|
+
return [result, { status: "complete", request: req, response }];
|
|
90
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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 models from "../models/index.js";
|
|
9
|
+
import * as operations from "../models/operations/index.js";
|
|
10
|
+
import { APIPromise } from "../types/async.js";
|
|
11
|
+
import { Result } from "../types/fp.js";
|
|
12
|
+
/**
|
|
13
|
+
* Revokes a browser session that the caller's own credential launched. Revoking again answers the same result. Another credential's session is not found.
|
|
14
|
+
*/
|
|
15
|
+
export declare function revokeUiSession(client: StateMachinesCore, request: operations.RevokeUiSessionRequest, options?: RequestOptions): APIPromise<Result<models.UiSessionRevocation, errors.ErrorT | StateMachinesHTTPError | ResponseValidationError | ConnectionError | RequestAbortedError | RequestTimeoutError | InvalidRequestError | UnexpectedClientError | SDKValidationError>>;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 models from "../models/index.js";
|
|
14
|
+
import * as operations from "../models/operations/index.js";
|
|
15
|
+
import { APIPromise } from "../types/async.js";
|
|
16
|
+
/**
|
|
17
|
+
* Revokes a browser session that the caller's own credential launched. Revoking again answers the same result. Another credential's session is not found.
|
|
18
|
+
*/
|
|
19
|
+
export function revokeUiSession(client, request, options) {
|
|
20
|
+
return new APIPromise($do(client, request, options));
|
|
21
|
+
}
|
|
22
|
+
async function $do(client, request, options) {
|
|
23
|
+
const parsed = safeParse(request, (value) => z.parse(operations.RevokeUiSessionRequest$outboundSchema, value), "Input validation failed");
|
|
24
|
+
if (!parsed.ok) {
|
|
25
|
+
return [parsed, { status: "invalid" }];
|
|
26
|
+
}
|
|
27
|
+
const payload = parsed.value;
|
|
28
|
+
const body = null;
|
|
29
|
+
const pathParams = {
|
|
30
|
+
appName: encodeSimple("appName", payload.appName, {
|
|
31
|
+
explode: false,
|
|
32
|
+
charEncoding: "percent",
|
|
33
|
+
}),
|
|
34
|
+
environmentId: encodeSimple("environmentId", payload.environmentId, {
|
|
35
|
+
explode: false,
|
|
36
|
+
charEncoding: "percent",
|
|
37
|
+
}),
|
|
38
|
+
sessionId: encodeSimple("sessionId", payload.sessionId, {
|
|
39
|
+
explode: false,
|
|
40
|
+
charEncoding: "percent",
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
const path = pathToFunc("/v1/environments/{environmentId}/apps/{appName}/ui-sessions/{sessionId}")(pathParams);
|
|
44
|
+
const headers = new Headers(compactMap({
|
|
45
|
+
Accept: "application/json",
|
|
46
|
+
}));
|
|
47
|
+
const secConfig = await extractSecurity(client._options.apiKey);
|
|
48
|
+
const securityInput = secConfig == null ? {} : { apiKey: secConfig };
|
|
49
|
+
const requestSecurity = resolveGlobalSecurity(securityInput);
|
|
50
|
+
const context = {
|
|
51
|
+
options: client._options,
|
|
52
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
53
|
+
operationID: "revokeUiSession",
|
|
54
|
+
oAuth2Scopes: null,
|
|
55
|
+
resolvedSecurity: requestSecurity,
|
|
56
|
+
securitySource: client._options.apiKey,
|
|
57
|
+
retryConfig: options?.retries
|
|
58
|
+
|| client._options.retryConfig
|
|
59
|
+
|| {
|
|
60
|
+
strategy: "backoff",
|
|
61
|
+
backoff: {
|
|
62
|
+
initialInterval: 1000,
|
|
63
|
+
maxInterval: 5000,
|
|
64
|
+
exponent: 1.5,
|
|
65
|
+
maxElapsedTime: 600000,
|
|
66
|
+
},
|
|
67
|
+
retryConnectionErrors: true,
|
|
68
|
+
}
|
|
69
|
+
|| { strategy: "none" },
|
|
70
|
+
retryCodes: options?.retryCodes || ["502", "503", "504"],
|
|
71
|
+
};
|
|
72
|
+
const requestRes = client._createRequest(context, {
|
|
73
|
+
security: requestSecurity,
|
|
74
|
+
method: "DELETE",
|
|
75
|
+
baseURL: options?.serverURL,
|
|
76
|
+
path: path,
|
|
77
|
+
headers: headers,
|
|
78
|
+
body: body,
|
|
79
|
+
userAgent: client._options.userAgent,
|
|
80
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
81
|
+
}, options);
|
|
82
|
+
if (!requestRes.ok) {
|
|
83
|
+
return [requestRes, { status: "invalid" }];
|
|
84
|
+
}
|
|
85
|
+
const req = requestRes.value;
|
|
86
|
+
const doResult = await client._do(req, {
|
|
87
|
+
context,
|
|
88
|
+
isErrorStatusCode: (statusCode) => matchStatusCode({ status: statusCode }, ["4XX", "5XX"]),
|
|
89
|
+
retryConfig: context.retryConfig,
|
|
90
|
+
retryCodes: context.retryCodes,
|
|
91
|
+
});
|
|
92
|
+
if (!doResult.ok) {
|
|
93
|
+
return [doResult, { status: "request-error", request: req }];
|
|
94
|
+
}
|
|
95
|
+
const response = doResult.value;
|
|
96
|
+
const responseFields = {
|
|
97
|
+
HttpMeta: { Response: response, Request: req },
|
|
98
|
+
};
|
|
99
|
+
const [result] = await M.match(M.json(200, models.UiSessionRevocation$inboundSchema), M.jsonErr([400, 401, 403, 404, 409, 413, 422, 429], errors.ErrorT$inboundSchema), M.jsonErr([500, 503], errors.ErrorT$inboundSchema), M.fail("4XX"), M.fail("5XX"))(response, req, { extraFields: responseFields });
|
|
100
|
+
if (!result.ok) {
|
|
101
|
+
return [result, { status: "complete", request: req, response }];
|
|
102
|
+
}
|
|
103
|
+
return [result, { status: "complete", request: req, response }];
|
|
104
|
+
}
|
|
@@ -24,9 +24,12 @@ async function $do(client, request, options) {
|
|
|
24
24
|
const body = null;
|
|
25
25
|
const path = pathToFunc("/v1/snapshots")();
|
|
26
26
|
const query = encodeFormQuery({
|
|
27
|
+
"appId": payload?.appId,
|
|
28
|
+
"createdBy": payload?.createdBy,
|
|
27
29
|
"cursor": payload?.cursor,
|
|
28
30
|
"environmentId": payload?.environmentId,
|
|
29
31
|
"limit": payload?.limit,
|
|
32
|
+
"search": payload?.search,
|
|
30
33
|
"status": payload?.status,
|
|
31
34
|
"workspaceId": payload?.workspaceId,
|
|
32
35
|
});
|
package/esm/lib/config.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
|
31
31
|
export declare const SDK_METADATA: {
|
|
32
32
|
readonly language: "typescript";
|
|
33
33
|
readonly openapiDocVersion: "1.0.0";
|
|
34
|
-
readonly sdkVersion: "0.
|
|
34
|
+
readonly sdkVersion: "0.9.0";
|
|
35
35
|
readonly genVersion: "2.941.0";
|
|
36
|
-
readonly userAgent: "speakeasy-sdk/typescript 0.
|
|
36
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.9.0 2.941.0 1.0.0 @usestatemachines/sdk";
|
|
37
37
|
};
|
package/esm/lib/config.js
CHANGED
|
@@ -24,7 +24,7 @@ export function serverURLFromOptions(options) {
|
|
|
24
24
|
export const SDK_METADATA = {
|
|
25
25
|
language: "typescript",
|
|
26
26
|
openapiDocVersion: "1.0.0",
|
|
27
|
-
sdkVersion: "0.
|
|
27
|
+
sdkVersion: "0.9.0",
|
|
28
28
|
genVersion: "2.941.0",
|
|
29
|
-
userAgent: "speakeasy-sdk/typescript 0.
|
|
29
|
+
userAgent: "speakeasy-sdk/typescript 0.9.0 2.941.0 1.0.0 @usestatemachines/sdk",
|
|
30
30
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as z from "zod/v4-mini";
|
|
2
|
+
import { Result as SafeParseResult } from "../types/fp.js";
|
|
3
|
+
import { SDKValidationError } from "./errors/sdk-validation-error.js";
|
|
4
|
+
export type BrowserCapability = {
|
|
5
|
+
acceptsClients: Array<string>;
|
|
6
|
+
contract: string;
|
|
7
|
+
documents: Array<string>;
|
|
8
|
+
entry: string;
|
|
9
|
+
};
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare const BrowserCapability$inboundSchema: z.ZodMiniType<BrowserCapability, unknown>;
|
|
12
|
+
export declare function browserCapabilityFromJSON(jsonString: string): SafeParseResult<BrowserCapability, SDKValidationError>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4-mini";
|
|
5
|
+
import { safeParse } from "../lib/schemas.js";
|
|
6
|
+
import * as types from "../types/primitives.js";
|
|
7
|
+
/** @internal */
|
|
8
|
+
export const BrowserCapability$inboundSchema = z.object({
|
|
9
|
+
acceptsClients: z.array(types.string()),
|
|
10
|
+
contract: types.string(),
|
|
11
|
+
documents: z.array(types.string()),
|
|
12
|
+
entry: types.string(),
|
|
13
|
+
});
|
|
14
|
+
export function browserCapabilityFromJSON(jsonString) {
|
|
15
|
+
return safeParse(jsonString, (x) => BrowserCapability$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'BrowserCapability' from JSON`);
|
|
16
|
+
}
|