@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.
- package/LICENSE +21 -0
- package/README.md +311 -0
- package/agents/SKILL.md +90 -0
- package/agents/index.d.ts +13 -0
- package/agents/index.js +22 -0
- package/agents/llms.txt +93 -0
- package/agents/prompt.md +49 -0
- package/esm/core.d.ts +9 -0
- package/esm/core.js +12 -0
- package/esm/extensions/client.d.ts +81 -0
- package/esm/extensions/client.js +213 -0
- package/esm/extensions/connection.d.ts +42 -0
- package/esm/extensions/connection.js +133 -0
- package/esm/extensions/errors.d.ts +52 -0
- package/esm/extensions/errors.js +129 -0
- package/esm/extensions/index.d.ts +11 -0
- package/esm/extensions/index.js +7 -0
- package/esm/extensions/signal.d.ts +14 -0
- package/esm/extensions/signal.js +29 -0
- package/esm/extensions/wait.d.ts +19 -0
- package/esm/extensions/wait.js +102 -0
- package/esm/funcs/catalog-get.d.ts +11 -0
- package/esm/funcs/catalog-get.js +76 -0
- package/esm/funcs/catalog-release.d.ts +11 -0
- package/esm/funcs/catalog-release.js +92 -0
- package/esm/funcs/credential-get.d.ts +11 -0
- package/esm/funcs/credential-get.js +76 -0
- package/esm/funcs/environments-create.d.ts +11 -0
- package/esm/funcs/environments-create.js +94 -0
- package/esm/funcs/environments-events.d.ts +12 -0
- package/esm/funcs/environments-events.js +98 -0
- package/esm/funcs/environments-get-connection.d.ts +11 -0
- package/esm/funcs/environments-get-connection.js +96 -0
- package/esm/funcs/environments-get.d.ts +11 -0
- package/esm/funcs/environments-get.js +92 -0
- package/esm/funcs/environments-list.d.ts +11 -0
- package/esm/funcs/environments-list.js +100 -0
- package/esm/funcs/environments-reveal.d.ts +11 -0
- package/esm/funcs/environments-reveal.js +97 -0
- package/esm/funcs/environments-stop.d.ts +11 -0
- package/esm/funcs/environments-stop.js +92 -0
- package/esm/funcs/workspaces-events.d.ts +12 -0
- package/esm/funcs/workspaces-events.js +98 -0
- package/esm/funcs/workspaces-get.d.ts +11 -0
- package/esm/funcs/workspaces-get.js +92 -0
- package/esm/funcs/workspaces-list.d.ts +11 -0
- package/esm/funcs/workspaces-list.js +90 -0
- package/esm/hooks/hooks.d.ts +24 -0
- package/esm/hooks/hooks.js +79 -0
- package/esm/hooks/index.d.ts +2 -0
- package/esm/hooks/index.js +5 -0
- package/esm/hooks/types.d.ts +76 -0
- package/esm/hooks/types.js +4 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +7 -0
- package/esm/lib/base64.d.ts +9 -0
- package/esm/lib/base64.js +30 -0
- package/esm/lib/config.d.ts +37 -0
- package/esm/lib/config.js +30 -0
- package/esm/lib/encodings.d.ts +54 -0
- package/esm/lib/encodings.js +406 -0
- package/esm/lib/files.d.ts +25 -0
- package/esm/lib/files.js +90 -0
- package/esm/lib/http.d.ts +66 -0
- package/esm/lib/http.js +208 -0
- package/esm/lib/logger.d.ts +5 -0
- package/esm/lib/logger.js +4 -0
- package/esm/lib/matchers.d.ts +58 -0
- package/esm/lib/matchers.js +201 -0
- package/esm/lib/primitives.d.ts +26 -0
- package/esm/lib/primitives.js +119 -0
- package/esm/lib/retries.d.ts +37 -0
- package/esm/lib/retries.js +156 -0
- package/esm/lib/schemas.d.ts +20 -0
- package/esm/lib/schemas.js +56 -0
- package/esm/lib/sdks.d.ts +62 -0
- package/esm/lib/sdks.js +289 -0
- package/esm/lib/security.d.ts +83 -0
- package/esm/lib/security.js +145 -0
- package/esm/lib/url.d.ts +4 -0
- package/esm/lib/url.js +23 -0
- package/esm/models/actor.d.ts +12 -0
- package/esm/models/actor.js +16 -0
- package/esm/models/api-profile.d.ts +17 -0
- package/esm/models/api-profile.js +22 -0
- package/esm/models/app.d.ts +14 -0
- package/esm/models/app.js +18 -0
- package/esm/models/catalog.d.ts +12 -0
- package/esm/models/catalog.js +15 -0
- package/esm/models/connection-secret.d.ts +14 -0
- package/esm/models/connection-secret.js +18 -0
- package/esm/models/connection.d.ts +26 -0
- package/esm/models/connection.js +30 -0
- package/esm/models/create-environment-input.d.ts +35 -0
- package/esm/models/create-environment-input.js +23 -0
- package/esm/models/credential-kind.d.ts +9 -0
- package/esm/models/credential-kind.js +10 -0
- package/esm/models/credential.d.ts +48 -0
- package/esm/models/credential.js +44 -0
- package/esm/models/environment-app.d.ts +42 -0
- package/esm/models/environment-app.js +44 -0
- package/esm/models/environment-lifetime.d.ts +10 -0
- package/esm/models/environment-lifetime.js +14 -0
- package/esm/models/environment.d.ts +47 -0
- package/esm/models/environment.js +48 -0
- package/esm/models/error-response.d.ts +45 -0
- package/esm/models/error-response.js +47 -0
- package/esm/models/errors/error-response.d.ts +18 -0
- package/esm/models/errors/error-response.js +32 -0
- package/esm/models/errors/http-client-errors.d.ts +43 -0
- package/esm/models/errors/http-client-errors.js +55 -0
- package/esm/models/errors/index.d.ts +6 -0
- package/esm/models/errors/index.js +9 -0
- package/esm/models/errors/response-validation-error.d.ts +25 -0
- package/esm/models/errors/response-validation-error.js +36 -0
- package/esm/models/errors/sdk-validation-error.d.ts +20 -0
- package/esm/models/errors/sdk-validation-error.js +51 -0
- package/esm/models/errors/state-machines-http-error.d.ts +18 -0
- package/esm/models/errors/state-machines-http-error.js +25 -0
- package/esm/models/errors/unexpected-response-error.d.ts +9 -0
- package/esm/models/errors/unexpected-response-error.js +29 -0
- package/esm/models/event-page.d.ts +11 -0
- package/esm/models/event-page.js +16 -0
- package/esm/models/event.d.ts +20 -0
- package/esm/models/event.js +22 -0
- package/esm/models/index.d.ts +19 -0
- package/esm/models/index.js +22 -0
- package/esm/models/operations/create-environments.d.ts +27 -0
- package/esm/models/operations/create-environments.js +27 -0
- package/esm/models/operations/get-catalog.d.ts +13 -0
- package/esm/models/operations/get-catalog.js +13 -0
- package/esm/models/operations/get-connection.d.ts +25 -0
- package/esm/models/operations/get-connection.js +21 -0
- package/esm/models/operations/get-credential.d.ts +13 -0
- package/esm/models/operations/get-credential.js +13 -0
- package/esm/models/operations/get-environment.d.ts +23 -0
- package/esm/models/operations/get-environment.js +20 -0
- package/esm/models/operations/get-release.d.ts +23 -0
- package/esm/models/operations/get-release.js +20 -0
- package/esm/models/operations/get-workspace.d.ts +23 -0
- package/esm/models/operations/get-workspace.js +20 -0
- package/esm/models/operations/index.d.ts +13 -0
- package/esm/models/operations/index.js +16 -0
- package/esm/models/operations/list-environment-events.d.ts +15 -0
- package/esm/models/operations/list-environment-events.js +13 -0
- package/esm/models/operations/list-environments.d.ts +49 -0
- package/esm/models/operations/list-environments.js +40 -0
- package/esm/models/operations/list-workspace-events.d.ts +15 -0
- package/esm/models/operations/list-workspace-events.js +13 -0
- package/esm/models/operations/list-workspaces.d.ts +32 -0
- package/esm/models/operations/list-workspaces.js +27 -0
- package/esm/models/operations/reveal-connection.d.ts +37 -0
- package/esm/models/operations/reveal-connection.js +29 -0
- package/esm/models/operations/stop-environment.d.ts +23 -0
- package/esm/models/operations/stop-environment.js +20 -0
- package/esm/models/release-actor.d.ts +11 -0
- package/esm/models/release-actor.js +15 -0
- package/esm/models/release.d.ts +26 -0
- package/esm/models/release.js +29 -0
- package/esm/models/security.d.ts +11 -0
- package/esm/models/security.js +11 -0
- package/esm/models/workspace.d.ts +16 -0
- package/esm/models/workspace.js +21 -0
- package/esm/sdk/catalog.d.ts +6 -0
- package/esm/sdk/catalog.js +15 -0
- package/esm/sdk/credential.d.ts +5 -0
- package/esm/sdk/credential.js +11 -0
- package/esm/sdk/environments.d.ts +12 -0
- package/esm/sdk/environments.js +35 -0
- package/esm/sdk/index.d.ts +1 -0
- package/esm/sdk/index.js +4 -0
- package/esm/sdk/sdk.d.ts +15 -0
- package/esm/sdk/sdk.js +26 -0
- package/esm/sdk/workspaces.d.ts +8 -0
- package/esm/sdk/workspaces.js +19 -0
- package/esm/types/async.d.ts +22 -0
- package/esm/types/async.js +27 -0
- package/esm/types/blobs.d.ts +3 -0
- package/esm/types/blobs.js +24 -0
- package/esm/types/const-date-time.d.ts +2 -0
- package/esm/types/const-date-time.js +9 -0
- package/esm/types/default-to-zero-value.d.ts +11 -0
- package/esm/types/default-to-zero-value.js +30 -0
- package/esm/types/enums.d.ts +8 -0
- package/esm/types/enums.js +26 -0
- package/esm/types/fp.d.ts +30 -0
- package/esm/types/fp.js +30 -0
- package/esm/types/index.d.ts +9 -0
- package/esm/types/index.js +9 -0
- package/esm/types/operations.d.ts +26 -0
- package/esm/types/operations.js +76 -0
- package/esm/types/primitives.d.ts +8 -0
- package/esm/types/primitives.js +108 -0
- package/esm/types/rfcdate.d.ts +20 -0
- package/esm/types/rfcdate.js +42 -0
- package/esm/types/smart-union.d.ts +6 -0
- package/esm/types/smart-union.js +116 -0
- package/esm/types/streams.d.ts +1 -0
- package/esm/types/streams.js +14 -0
- package/esm/types/unrecognized.d.ts +15 -0
- package/esm/types/unrecognized.js +30 -0
- package/openapi.json +2853 -0
- package/package.json +50 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import * as z from "zod/v4-mini";
|
|
5
|
+
export function bytesToBase64(u8arr) {
|
|
6
|
+
return btoa(String.fromCodePoint(...u8arr));
|
|
7
|
+
}
|
|
8
|
+
export function bytesFromBase64(encoded) {
|
|
9
|
+
return Uint8Array.from(atob(encoded), (c) => c.charCodeAt(0));
|
|
10
|
+
}
|
|
11
|
+
export function stringToBytes(str) {
|
|
12
|
+
return new TextEncoder().encode(str);
|
|
13
|
+
}
|
|
14
|
+
export function stringFromBytes(u8arr) {
|
|
15
|
+
return new TextDecoder().decode(u8arr);
|
|
16
|
+
}
|
|
17
|
+
export function stringToBase64(str) {
|
|
18
|
+
return bytesToBase64(stringToBytes(str));
|
|
19
|
+
}
|
|
20
|
+
export function stringFromBase64(b64str) {
|
|
21
|
+
return stringFromBytes(bytesFromBase64(b64str));
|
|
22
|
+
}
|
|
23
|
+
export const zodOutbound = z.union([
|
|
24
|
+
z.custom(x => x instanceof Uint8Array),
|
|
25
|
+
z.pipe(z.string(), z.transform(stringToBytes)),
|
|
26
|
+
]);
|
|
27
|
+
export const zodInbound = z.union([
|
|
28
|
+
z.custom(x => x instanceof Uint8Array),
|
|
29
|
+
z.pipe(z.string(), z.transform(bytesFromBase64)),
|
|
30
|
+
]);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HTTPClient } from "./http.js";
|
|
2
|
+
import { Logger } from "./logger.js";
|
|
3
|
+
import { RetryConfig } from "./retries.js";
|
|
4
|
+
/**
|
|
5
|
+
* Contains the list of servers available to the SDK
|
|
6
|
+
*/
|
|
7
|
+
export declare const ServerList: readonly ["https://state-api.usestatemachines.workers.dev"];
|
|
8
|
+
export type SDKOptions = {
|
|
9
|
+
apiKey?: string | (() => Promise<string>) | undefined;
|
|
10
|
+
httpClient?: HTTPClient;
|
|
11
|
+
/**
|
|
12
|
+
* Allows overriding the default server used by the SDK
|
|
13
|
+
*/
|
|
14
|
+
serverIdx?: number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Allows overriding the default server URL used by the SDK
|
|
17
|
+
*/
|
|
18
|
+
serverURL?: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Allows overriding the default user agent used by the SDK
|
|
21
|
+
*/
|
|
22
|
+
userAgent?: string | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Allows overriding the default retry config used by the SDK
|
|
25
|
+
*/
|
|
26
|
+
retryConfig?: RetryConfig;
|
|
27
|
+
timeoutMs?: number;
|
|
28
|
+
debugLogger?: Logger;
|
|
29
|
+
};
|
|
30
|
+
export declare function serverURLFromOptions(options: SDKOptions): URL | null;
|
|
31
|
+
export declare const SDK_METADATA: {
|
|
32
|
+
readonly language: "typescript";
|
|
33
|
+
readonly openapiDocVersion: "1.0.0";
|
|
34
|
+
readonly sdkVersion: "0.1.1";
|
|
35
|
+
readonly genVersion: "2.941.0";
|
|
36
|
+
readonly userAgent: "speakeasy-sdk/typescript 0.1.1 2.941.0 1.0.0 @usestatemachines/sdk";
|
|
37
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import { pathToFunc } from "./url.js";
|
|
5
|
+
/**
|
|
6
|
+
* Contains the list of servers available to the SDK
|
|
7
|
+
*/
|
|
8
|
+
export const ServerList = [
|
|
9
|
+
"https://state-api.usestatemachines.workers.dev",
|
|
10
|
+
];
|
|
11
|
+
export function serverURLFromOptions(options) {
|
|
12
|
+
let serverURL = options.serverURL;
|
|
13
|
+
const params = {};
|
|
14
|
+
if (!serverURL) {
|
|
15
|
+
const serverIdx = options.serverIdx ?? 0;
|
|
16
|
+
if (serverIdx < 0 || serverIdx >= ServerList.length) {
|
|
17
|
+
throw new Error(`Invalid server index ${serverIdx}`);
|
|
18
|
+
}
|
|
19
|
+
serverURL = ServerList[serverIdx] || "";
|
|
20
|
+
}
|
|
21
|
+
const u = pathToFunc(serverURL)(params);
|
|
22
|
+
return new URL(u);
|
|
23
|
+
}
|
|
24
|
+
export const SDK_METADATA = {
|
|
25
|
+
language: "typescript",
|
|
26
|
+
openapiDocVersion: "1.0.0",
|
|
27
|
+
sdkVersion: "0.1.1",
|
|
28
|
+
genVersion: "2.941.0",
|
|
29
|
+
userAgent: "speakeasy-sdk/typescript 0.1.1 2.941.0 1.0.0 @usestatemachines/sdk",
|
|
30
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export declare class EncodingError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export type CharEncoding = "percent" | "percentExceptReserved" | "none";
|
|
5
|
+
export declare function encodeMatrix(key: string, value: unknown, options?: {
|
|
6
|
+
explode?: boolean;
|
|
7
|
+
charEncoding?: CharEncoding;
|
|
8
|
+
}): string | undefined;
|
|
9
|
+
export declare function encodeLabel(key: string, value: unknown, options?: {
|
|
10
|
+
explode?: boolean;
|
|
11
|
+
charEncoding?: CharEncoding;
|
|
12
|
+
}): string | undefined;
|
|
13
|
+
type FormEncoder = (key: string, value: unknown, options?: {
|
|
14
|
+
explode?: boolean;
|
|
15
|
+
charEncoding?: CharEncoding;
|
|
16
|
+
}) => string | undefined;
|
|
17
|
+
export declare const encodeForm: FormEncoder;
|
|
18
|
+
export declare const encodeSpaceDelimited: FormEncoder;
|
|
19
|
+
export declare const encodePipeDelimited: FormEncoder;
|
|
20
|
+
export declare function encodeBodyForm(key: string, value: unknown, options?: {
|
|
21
|
+
explode?: boolean;
|
|
22
|
+
charEncoding?: CharEncoding;
|
|
23
|
+
}): string;
|
|
24
|
+
export declare function encodeDeepObject(key: string, value: unknown, options?: {
|
|
25
|
+
charEncoding?: CharEncoding;
|
|
26
|
+
}): string | undefined;
|
|
27
|
+
export declare function encodeDeepObjectObject(key: string, value: unknown, options?: {
|
|
28
|
+
charEncoding?: CharEncoding;
|
|
29
|
+
}): string | undefined;
|
|
30
|
+
export declare function encodeJSON(key: string, value: unknown, options?: {
|
|
31
|
+
explode?: boolean;
|
|
32
|
+
charEncoding?: CharEncoding;
|
|
33
|
+
}): string | undefined;
|
|
34
|
+
export declare const encodeSimple: (key: string, value: unknown, options?: {
|
|
35
|
+
explode?: boolean;
|
|
36
|
+
charEncoding?: CharEncoding;
|
|
37
|
+
} | undefined) => string | undefined;
|
|
38
|
+
export declare function queryJoin(...args: (string | undefined)[]): string;
|
|
39
|
+
type QueryEncoderOptions = {
|
|
40
|
+
explode?: boolean;
|
|
41
|
+
charEncoding?: CharEncoding;
|
|
42
|
+
allowEmptyValue?: string[];
|
|
43
|
+
};
|
|
44
|
+
type QueryEncoder = (key: string, value: unknown, options?: QueryEncoderOptions) => string | undefined;
|
|
45
|
+
type BulkQueryEncoder = (values: Record<string, unknown>, options?: QueryEncoderOptions) => string;
|
|
46
|
+
export declare function queryEncoder(f: QueryEncoder): BulkQueryEncoder;
|
|
47
|
+
export declare const encodeJSONQuery: BulkQueryEncoder;
|
|
48
|
+
export declare const encodeFormQuery: BulkQueryEncoder;
|
|
49
|
+
export declare const encodeSpaceDelimitedQuery: BulkQueryEncoder;
|
|
50
|
+
export declare const encodePipeDelimitedQuery: BulkQueryEncoder;
|
|
51
|
+
export declare const encodeDeepObjectQuery: BulkQueryEncoder;
|
|
52
|
+
export declare function appendForm(fd: FormData, key: string, value: unknown, fileName?: string): void;
|
|
53
|
+
export declare function normalizeBlob(value: Pick<Blob, "arrayBuffer" | "type">): Promise<Blob>;
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
import { bytesToBase64 } from "./base64.js";
|
|
5
|
+
import { isPlainObject } from "./primitives.js";
|
|
6
|
+
export class EncodingError extends Error {
|
|
7
|
+
constructor(message) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "EncodingError";
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
const reservedEscapes = /%(2[346bcf]|3[abdf]|40|5[bd])/gi;
|
|
13
|
+
function encodeKeyChars(v, charEncoding) {
|
|
14
|
+
return encodeChars(v, charEncoding === "percentExceptReserved" ? "percent" : charEncoding);
|
|
15
|
+
}
|
|
16
|
+
function encodeChars(v, charEncoding) {
|
|
17
|
+
switch (charEncoding) {
|
|
18
|
+
case "percent":
|
|
19
|
+
return encodeURIComponent(v);
|
|
20
|
+
case "percentExceptReserved":
|
|
21
|
+
return encodeURIComponent(v).replace(reservedEscapes, (m) => decodeURIComponent(m));
|
|
22
|
+
default:
|
|
23
|
+
return v;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function encodeMatrix(key, value, options) {
|
|
27
|
+
let out = "";
|
|
28
|
+
const pairs = options?.explode
|
|
29
|
+
? explode(key, value)
|
|
30
|
+
: [[key, value]];
|
|
31
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const encodeString = (v) => {
|
|
35
|
+
return encodeChars(v, options?.charEncoding);
|
|
36
|
+
};
|
|
37
|
+
const encodeValue = (v) => encodeString(serializeValue(v));
|
|
38
|
+
pairs.forEach(([pk, pv]) => {
|
|
39
|
+
let tmp = "";
|
|
40
|
+
let encValue = null;
|
|
41
|
+
if (pv == null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
else if (Array.isArray(pv)) {
|
|
45
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(",");
|
|
46
|
+
}
|
|
47
|
+
else if (isPlainObject(pv)) {
|
|
48
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
49
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
50
|
+
});
|
|
51
|
+
encValue = mapped?.join("").slice(1);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
encValue = `${encodeValue(pv)}`;
|
|
55
|
+
}
|
|
56
|
+
if (encValue == null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const keyPrefix = encodeKeyChars(pk, options?.charEncoding);
|
|
60
|
+
tmp = `${keyPrefix}=${encValue}`;
|
|
61
|
+
// trim trailing '=' if value was empty
|
|
62
|
+
if (tmp === `${keyPrefix}=`) {
|
|
63
|
+
tmp = tmp.slice(0, -1);
|
|
64
|
+
}
|
|
65
|
+
// If we end up with the nothing then skip forward
|
|
66
|
+
if (!tmp) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
out += `;${tmp}`;
|
|
70
|
+
});
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
export function encodeLabel(key, value, options) {
|
|
74
|
+
let out = "";
|
|
75
|
+
const pairs = options?.explode
|
|
76
|
+
? explode(key, value)
|
|
77
|
+
: [[key, value]];
|
|
78
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const encodeString = (v) => {
|
|
82
|
+
return encodeChars(v, options?.charEncoding);
|
|
83
|
+
};
|
|
84
|
+
const encodeValue = (v) => encodeString(serializeValue(v));
|
|
85
|
+
pairs.forEach(([pk, pv]) => {
|
|
86
|
+
let encValue = "";
|
|
87
|
+
if (pv == null) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
else if (Array.isArray(pv)) {
|
|
91
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(".");
|
|
92
|
+
}
|
|
93
|
+
else if (isPlainObject(pv)) {
|
|
94
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
95
|
+
return `.${encodeString(k)}.${encodeValue(v)}`;
|
|
96
|
+
});
|
|
97
|
+
encValue = mapped?.join("").slice(1);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const k = options?.explode && isPlainObject(value)
|
|
101
|
+
? `${encodeKeyChars(pk, options?.charEncoding)}=`
|
|
102
|
+
: "";
|
|
103
|
+
encValue = `${k}${encodeValue(pv)}`;
|
|
104
|
+
}
|
|
105
|
+
out += encValue == null ? "" : `.${encValue}`;
|
|
106
|
+
});
|
|
107
|
+
return out;
|
|
108
|
+
}
|
|
109
|
+
function formEncoder(sep) {
|
|
110
|
+
return (key, value, options) => {
|
|
111
|
+
let out = "";
|
|
112
|
+
const pairs = options?.explode
|
|
113
|
+
? explode(key, value)
|
|
114
|
+
: [[key, value]];
|
|
115
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
const encodeString = (v) => {
|
|
119
|
+
return encodeChars(v, options?.charEncoding);
|
|
120
|
+
};
|
|
121
|
+
const encodeValue = (v) => encodeString(serializeValue(v));
|
|
122
|
+
const encodedSep = encodeString(sep);
|
|
123
|
+
pairs.forEach(([pk, pv]) => {
|
|
124
|
+
let tmp = "";
|
|
125
|
+
let encValue = null;
|
|
126
|
+
if (pv == null) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
else if (Array.isArray(pv)) {
|
|
130
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(encodedSep);
|
|
131
|
+
}
|
|
132
|
+
else if (isPlainObject(pv)) {
|
|
133
|
+
encValue = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
134
|
+
return `${encodeString(k)}${encodedSep}${encodeValue(v)}`;
|
|
135
|
+
})?.join(encodedSep);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
encValue = `${encodeValue(pv)}`;
|
|
139
|
+
}
|
|
140
|
+
if (encValue == null) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
tmp = `${encodeKeyChars(pk, options?.charEncoding)}=${encValue}`;
|
|
144
|
+
// If we end up with the nothing then skip forward
|
|
145
|
+
if (!tmp || tmp === "=") {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
out += `&${tmp}`;
|
|
149
|
+
});
|
|
150
|
+
return out.slice(1);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
export const encodeForm = formEncoder(",");
|
|
154
|
+
export const encodeSpaceDelimited = formEncoder(" ");
|
|
155
|
+
export const encodePipeDelimited = formEncoder("|");
|
|
156
|
+
export function encodeBodyForm(key, value, options) {
|
|
157
|
+
let out = "";
|
|
158
|
+
const pairs = options?.explode
|
|
159
|
+
? explode(key, value)
|
|
160
|
+
: [[key, value]];
|
|
161
|
+
const encodeString = (v) => {
|
|
162
|
+
return encodeChars(v, options?.charEncoding);
|
|
163
|
+
};
|
|
164
|
+
const encodeValue = (v) => encodeString(serializeValue(v));
|
|
165
|
+
pairs.forEach(([pk, pv]) => {
|
|
166
|
+
let tmp = "";
|
|
167
|
+
let encValue = "";
|
|
168
|
+
if (pv == null) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
else if (Array.isArray(pv)) {
|
|
172
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
173
|
+
}
|
|
174
|
+
else if (isPlainObject(pv)) {
|
|
175
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
encValue = `${encodeValue(pv)}`;
|
|
179
|
+
}
|
|
180
|
+
tmp = `${encodeKeyChars(pk, options?.charEncoding)}=${encValue}`;
|
|
181
|
+
// If we end up with the nothing then skip forward
|
|
182
|
+
if (!tmp || tmp === "=") {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
out += `&${tmp}`;
|
|
186
|
+
});
|
|
187
|
+
return out.slice(1);
|
|
188
|
+
}
|
|
189
|
+
export function encodeDeepObject(key, value, options) {
|
|
190
|
+
if (value == null) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (!isPlainObject(value)) {
|
|
194
|
+
throw new EncodingError(`Value of parameter '${key}' which uses deepObject encoding must be an object or null`);
|
|
195
|
+
}
|
|
196
|
+
return encodeDeepObjectObject(key, value, options);
|
|
197
|
+
}
|
|
198
|
+
export function encodeDeepObjectObject(key, value, options) {
|
|
199
|
+
if (value == null) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
let out = "";
|
|
203
|
+
const encodeString = (v) => {
|
|
204
|
+
return encodeChars(v, options?.charEncoding);
|
|
205
|
+
};
|
|
206
|
+
if (!isPlainObject(value)) {
|
|
207
|
+
throw new EncodingError(`Expected parameter '${key}' to be an object.`);
|
|
208
|
+
}
|
|
209
|
+
Object.entries(value).forEach(([ck, cv]) => {
|
|
210
|
+
if (cv == null) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const pk = `${key}[${ck}]`;
|
|
214
|
+
if (isPlainObject(cv)) {
|
|
215
|
+
const objOut = encodeDeepObjectObject(pk, cv, options);
|
|
216
|
+
out += objOut == null ? "" : `&${objOut}`;
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const pairs = Array.isArray(cv) ? cv : [cv];
|
|
220
|
+
const encoded = mapDefined(pairs, (v) => {
|
|
221
|
+
return `${encodeKeyChars(pk, options?.charEncoding)}=${encodeString(serializeValue(v))}`;
|
|
222
|
+
})?.join("&");
|
|
223
|
+
out += encoded == null ? "" : `&${encoded}`;
|
|
224
|
+
});
|
|
225
|
+
return out.slice(1);
|
|
226
|
+
}
|
|
227
|
+
export function encodeJSON(key, value, options) {
|
|
228
|
+
if (typeof value === "undefined") {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const encodeString = (v) => {
|
|
232
|
+
return encodeChars(v, options?.charEncoding);
|
|
233
|
+
};
|
|
234
|
+
const encVal = encodeString(JSON.stringify(value, jsonReplacer));
|
|
235
|
+
return options?.explode
|
|
236
|
+
? encVal
|
|
237
|
+
: `${encodeKeyChars(key, options?.charEncoding)}=${encVal}`;
|
|
238
|
+
}
|
|
239
|
+
export const encodeSimple = (key, value, options) => {
|
|
240
|
+
let out = "";
|
|
241
|
+
const pairs = options?.explode
|
|
242
|
+
? explode(key, value)
|
|
243
|
+
: [[key, value]];
|
|
244
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const encodeString = (v) => {
|
|
248
|
+
return encodeChars(v, options?.charEncoding);
|
|
249
|
+
};
|
|
250
|
+
const encodeValue = (v) => encodeString(serializeValue(v));
|
|
251
|
+
pairs.forEach(([pk, pv]) => {
|
|
252
|
+
let tmp = "";
|
|
253
|
+
if (pv == null) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
else if (Array.isArray(pv)) {
|
|
257
|
+
tmp = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(",");
|
|
258
|
+
}
|
|
259
|
+
else if (isPlainObject(pv)) {
|
|
260
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
261
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
262
|
+
});
|
|
263
|
+
tmp = mapped?.join("").slice(1);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
const k = options?.explode && isPlainObject(value) ? `${pk}=` : "";
|
|
267
|
+
tmp = `${k}${encodeValue(pv)}`;
|
|
268
|
+
}
|
|
269
|
+
out += tmp ? `,${tmp}` : "";
|
|
270
|
+
});
|
|
271
|
+
return out.slice(1);
|
|
272
|
+
};
|
|
273
|
+
function explode(key, value) {
|
|
274
|
+
if (Array.isArray(value)) {
|
|
275
|
+
return value.map((v) => [key, v]);
|
|
276
|
+
}
|
|
277
|
+
else if (isPlainObject(value)) {
|
|
278
|
+
const o = value ?? {};
|
|
279
|
+
return Object.entries(o).map(([k, v]) => [k, v]);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
return [[key, value]];
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function serializeValue(value) {
|
|
286
|
+
if (value == null) {
|
|
287
|
+
return "";
|
|
288
|
+
}
|
|
289
|
+
else if (value instanceof Date) {
|
|
290
|
+
return value.toISOString();
|
|
291
|
+
}
|
|
292
|
+
else if (value instanceof Uint8Array) {
|
|
293
|
+
return bytesToBase64(value);
|
|
294
|
+
}
|
|
295
|
+
else if (typeof value === "object") {
|
|
296
|
+
return JSON.stringify(value, jsonReplacer);
|
|
297
|
+
}
|
|
298
|
+
return `${value}`;
|
|
299
|
+
}
|
|
300
|
+
function jsonReplacer(_, value) {
|
|
301
|
+
if (value instanceof Uint8Array) {
|
|
302
|
+
return bytesToBase64(value);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
return value;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function mapDefined(inp, mapper) {
|
|
309
|
+
const res = inp.reduce((acc, v) => {
|
|
310
|
+
if (v == null) {
|
|
311
|
+
return acc;
|
|
312
|
+
}
|
|
313
|
+
const m = mapper(v);
|
|
314
|
+
if (m == null) {
|
|
315
|
+
return acc;
|
|
316
|
+
}
|
|
317
|
+
acc.push(m);
|
|
318
|
+
return acc;
|
|
319
|
+
}, []);
|
|
320
|
+
return res.length ? res : null;
|
|
321
|
+
}
|
|
322
|
+
function mapDefinedEntries(inp, mapper) {
|
|
323
|
+
const acc = [];
|
|
324
|
+
for (const [k, v] of inp) {
|
|
325
|
+
if (v == null) {
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
const m = mapper([k, v]);
|
|
329
|
+
if (m == null) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
acc.push(m);
|
|
333
|
+
}
|
|
334
|
+
return acc.length ? acc : null;
|
|
335
|
+
}
|
|
336
|
+
export function queryJoin(...args) {
|
|
337
|
+
return args.filter(Boolean).join("&");
|
|
338
|
+
}
|
|
339
|
+
export function queryEncoder(f) {
|
|
340
|
+
const bulkEncode = function (values, options) {
|
|
341
|
+
const opts = {
|
|
342
|
+
...options,
|
|
343
|
+
explode: options?.explode ?? true,
|
|
344
|
+
charEncoding: options?.charEncoding ?? "percent",
|
|
345
|
+
};
|
|
346
|
+
const allowEmptySet = new Set(options?.allowEmptyValue ?? []);
|
|
347
|
+
const encoded = Object.entries(values).map(([key, value]) => {
|
|
348
|
+
if (allowEmptySet.has(key)) {
|
|
349
|
+
if (value === undefined
|
|
350
|
+
|| value === null
|
|
351
|
+
|| value === ""
|
|
352
|
+
|| (Array.isArray(value) && value.length === 0)) {
|
|
353
|
+
return `${encodeURIComponent(key)}=`;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return f(key, value, opts);
|
|
357
|
+
});
|
|
358
|
+
return queryJoin(...encoded);
|
|
359
|
+
};
|
|
360
|
+
return bulkEncode;
|
|
361
|
+
}
|
|
362
|
+
export const encodeJSONQuery = queryEncoder(encodeJSON);
|
|
363
|
+
export const encodeFormQuery = queryEncoder(encodeForm);
|
|
364
|
+
export const encodeSpaceDelimitedQuery = queryEncoder(encodeSpaceDelimited);
|
|
365
|
+
export const encodePipeDelimitedQuery = queryEncoder(encodePipeDelimited);
|
|
366
|
+
export const encodeDeepObjectQuery = queryEncoder(encodeDeepObject);
|
|
367
|
+
function isBlobLike(val) {
|
|
368
|
+
if (val instanceof Blob) {
|
|
369
|
+
return true;
|
|
370
|
+
}
|
|
371
|
+
if (typeof val !== "object" || val == null || !(Symbol.toStringTag in val)) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
const tag = val[Symbol.toStringTag];
|
|
375
|
+
if (tag !== "Blob" && tag !== "File") {
|
|
376
|
+
return false;
|
|
377
|
+
}
|
|
378
|
+
return "stream" in val && typeof val.stream === "function";
|
|
379
|
+
}
|
|
380
|
+
export function appendForm(fd, key, value, fileName) {
|
|
381
|
+
if (value == null) {
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
else if (isBlobLike(value)) {
|
|
385
|
+
if (fileName) {
|
|
386
|
+
fd.append(key, value, fileName);
|
|
387
|
+
}
|
|
388
|
+
else {
|
|
389
|
+
fd.append(key, value);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
else if (Array.isArray(value)) {
|
|
393
|
+
value.forEach((v) => {
|
|
394
|
+
appendForm(fd, key, v);
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
fd.append(key, String(value));
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
export async function normalizeBlob(value) {
|
|
402
|
+
if (value instanceof Blob) {
|
|
403
|
+
return value;
|
|
404
|
+
}
|
|
405
|
+
return new Blob([await value.arrayBuffer()], { type: value.type });
|
|
406
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consumes a stream and returns a concatenated array buffer. Useful in
|
|
3
|
+
* situations where we need to read the whole file because it forms part of a
|
|
4
|
+
* larger payload containing other fields, and we can't modify the underlying
|
|
5
|
+
* request structure.
|
|
6
|
+
*/
|
|
7
|
+
export declare function readableStreamToArrayBuffer(readable: ReadableStream<Uint8Array>): Promise<ArrayBuffer>;
|
|
8
|
+
/**
|
|
9
|
+
* Determines the MIME content type based on a file's extension.
|
|
10
|
+
* Returns null if the extension is not recognized.
|
|
11
|
+
*/
|
|
12
|
+
export declare function getContentTypeFromFileName(fileName: string): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Blob from file content with the given MIME type.
|
|
15
|
+
*
|
|
16
|
+
* Node.js Buffers are Uint8Array subclasses that may share a pooled
|
|
17
|
+
* ArrayBuffer (byteOffset > 0, byteLength < buffer.byteLength). Passing
|
|
18
|
+
* such a Buffer directly to `new Blob([buf])` can include the entire
|
|
19
|
+
* underlying pool on some runtimes, producing a Blob with extra bytes
|
|
20
|
+
* that corrupts multipart uploads.
|
|
21
|
+
*
|
|
22
|
+
* Copying into a standalone Uint8Array ensures the Blob receives only the
|
|
23
|
+
* intended bytes regardless of runtime behaviour.
|
|
24
|
+
*/
|
|
25
|
+
export declare function bytesToBlob(content: Uint8Array<ArrayBufferLike> | ArrayBuffer | Blob | string, contentType: string): Blob;
|
package/esm/lib/files.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Consumes a stream and returns a concatenated array buffer. Useful in
|
|
6
|
+
* situations where we need to read the whole file because it forms part of a
|
|
7
|
+
* larger payload containing other fields, and we can't modify the underlying
|
|
8
|
+
* request structure.
|
|
9
|
+
*/
|
|
10
|
+
export async function readableStreamToArrayBuffer(readable) {
|
|
11
|
+
const reader = readable.getReader();
|
|
12
|
+
const chunks = [];
|
|
13
|
+
let totalLength = 0;
|
|
14
|
+
let done = false;
|
|
15
|
+
while (!done) {
|
|
16
|
+
const { value, done: doneReading } = await reader.read();
|
|
17
|
+
if (doneReading) {
|
|
18
|
+
done = true;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
chunks.push(value);
|
|
22
|
+
totalLength += value.length;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const concatenatedChunks = new Uint8Array(totalLength);
|
|
26
|
+
let offset = 0;
|
|
27
|
+
for (const chunk of chunks) {
|
|
28
|
+
concatenatedChunks.set(chunk, offset);
|
|
29
|
+
offset += chunk.length;
|
|
30
|
+
}
|
|
31
|
+
return concatenatedChunks.buffer;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Determines the MIME content type based on a file's extension.
|
|
35
|
+
* Returns null if the extension is not recognized.
|
|
36
|
+
*/
|
|
37
|
+
export function getContentTypeFromFileName(fileName) {
|
|
38
|
+
if (!fileName)
|
|
39
|
+
return null;
|
|
40
|
+
const ext = fileName.toLowerCase().split(".").pop();
|
|
41
|
+
if (!ext)
|
|
42
|
+
return null;
|
|
43
|
+
const mimeTypes = {
|
|
44
|
+
json: "application/json",
|
|
45
|
+
xml: "application/xml",
|
|
46
|
+
html: "text/html",
|
|
47
|
+
htm: "text/html",
|
|
48
|
+
txt: "text/plain",
|
|
49
|
+
csv: "text/csv",
|
|
50
|
+
pdf: "application/pdf",
|
|
51
|
+
png: "image/png",
|
|
52
|
+
jpg: "image/jpeg",
|
|
53
|
+
jpeg: "image/jpeg",
|
|
54
|
+
gif: "image/gif",
|
|
55
|
+
svg: "image/svg+xml",
|
|
56
|
+
js: "application/javascript",
|
|
57
|
+
css: "text/css",
|
|
58
|
+
zip: "application/zip",
|
|
59
|
+
tar: "application/x-tar",
|
|
60
|
+
gz: "application/gzip",
|
|
61
|
+
mp4: "video/mp4",
|
|
62
|
+
mp3: "audio/mpeg",
|
|
63
|
+
wav: "audio/wav",
|
|
64
|
+
webp: "image/webp",
|
|
65
|
+
ico: "image/x-icon",
|
|
66
|
+
woff: "font/woff",
|
|
67
|
+
woff2: "font/woff2",
|
|
68
|
+
ttf: "font/ttf",
|
|
69
|
+
otf: "font/otf",
|
|
70
|
+
};
|
|
71
|
+
return mimeTypes[ext] || null;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a Blob from file content with the given MIME type.
|
|
75
|
+
*
|
|
76
|
+
* Node.js Buffers are Uint8Array subclasses that may share a pooled
|
|
77
|
+
* ArrayBuffer (byteOffset > 0, byteLength < buffer.byteLength). Passing
|
|
78
|
+
* such a Buffer directly to `new Blob([buf])` can include the entire
|
|
79
|
+
* underlying pool on some runtimes, producing a Blob with extra bytes
|
|
80
|
+
* that corrupts multipart uploads.
|
|
81
|
+
*
|
|
82
|
+
* Copying into a standalone Uint8Array ensures the Blob receives only the
|
|
83
|
+
* intended bytes regardless of runtime behaviour.
|
|
84
|
+
*/
|
|
85
|
+
export function bytesToBlob(content, contentType) {
|
|
86
|
+
if (content instanceof Uint8Array) {
|
|
87
|
+
return new Blob([new Uint8Array(content)], { type: contentType });
|
|
88
|
+
}
|
|
89
|
+
return new Blob([content], { type: contentType });
|
|
90
|
+
}
|