fluidapi 0.0.3
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/FUNCTIONS.md +85 -0
- package/README.md +429 -0
- package/RUNTIMES.md +48 -0
- package/esm/core.d.ts +10 -0
- package/esm/core.d.ts.map +1 -0
- package/esm/core.js +13 -0
- package/esm/core.js.map +1 -0
- package/esm/funcs/metadata-get-jwks.d.ts +18 -0
- package/esm/funcs/metadata-get-jwks.d.ts.map +1 -0
- package/esm/funcs/metadata-get-jwks.js +67 -0
- package/esm/funcs/metadata-get-jwks.js.map +1 -0
- package/esm/funcs/metadata-health-check.d.ts +15 -0
- package/esm/funcs/metadata-health-check.d.ts.map +1 -0
- package/esm/funcs/metadata-health-check.js +64 -0
- package/esm/funcs/metadata-health-check.js.map +1 -0
- package/esm/funcs/tokens-issue-fluid-token.d.ts +25 -0
- package/esm/funcs/tokens-issue-fluid-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-fluid-token.js +87 -0
- package/esm/funcs/tokens-issue-fluid-token.js.map +1 -0
- package/esm/funcs/tokens-issue-token.d.ts +31 -0
- package/esm/funcs/tokens-issue-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-token.js +93 -0
- package/esm/funcs/tokens-issue-token.js.map +1 -0
- package/esm/funcs/tokens-issue-user-token.d.ts +37 -0
- package/esm/funcs/tokens-issue-user-token.d.ts.map +1 -0
- package/esm/funcs/tokens-issue-user-token.js +97 -0
- package/esm/funcs/tokens-issue-user-token.js.map +1 -0
- package/esm/hooks/hooks.d.ts +25 -0
- package/esm/hooks/hooks.d.ts.map +1 -0
- package/esm/hooks/hooks.js +82 -0
- package/esm/hooks/hooks.js.map +1 -0
- package/esm/hooks/index.d.ts +3 -0
- package/esm/hooks/index.d.ts.map +1 -0
- package/esm/hooks/index.js +6 -0
- package/esm/hooks/index.js.map +1 -0
- package/esm/hooks/registration.d.ts +3 -0
- package/esm/hooks/registration.d.ts.map +1 -0
- package/esm/hooks/registration.js +12 -0
- package/esm/hooks/registration.js.map +1 -0
- package/esm/hooks/types.d.ts +76 -0
- package/esm/hooks/types.d.ts.map +1 -0
- package/esm/hooks/types.js +5 -0
- package/esm/hooks/types.js.map +1 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +8 -0
- package/esm/index.js.map +1 -0
- package/esm/lib/base64.d.ts +10 -0
- package/esm/lib/base64.d.ts.map +1 -0
- package/esm/lib/base64.js +31 -0
- package/esm/lib/base64.js.map +1 -0
- package/esm/lib/config.d.ts +57 -0
- package/esm/lib/config.d.ts.map +1 -0
- package/esm/lib/config.js +50 -0
- package/esm/lib/config.js.map +1 -0
- package/esm/lib/dlv.d.ts +14 -0
- package/esm/lib/dlv.d.ts.map +1 -0
- package/esm/lib/dlv.js +46 -0
- package/esm/lib/dlv.js.map +1 -0
- package/esm/lib/encodings.d.ts +53 -0
- package/esm/lib/encodings.d.ts.map +1 -0
- package/esm/lib/encodings.js +370 -0
- package/esm/lib/encodings.js.map +1 -0
- package/esm/lib/env.d.ts +14 -0
- package/esm/lib/env.d.ts.map +1 -0
- package/esm/lib/env.js +43 -0
- package/esm/lib/env.js.map +1 -0
- package/esm/lib/files.d.ts +13 -0
- package/esm/lib/files.d.ts.map +1 -0
- package/esm/lib/files.js +73 -0
- package/esm/lib/files.js.map +1 -0
- package/esm/lib/http.d.ts +67 -0
- package/esm/lib/http.d.ts.map +1 -0
- package/esm/lib/http.js +209 -0
- package/esm/lib/http.js.map +1 -0
- package/esm/lib/is-plain-object.d.ts +2 -0
- package/esm/lib/is-plain-object.d.ts.map +1 -0
- package/esm/lib/is-plain-object.js +38 -0
- package/esm/lib/is-plain-object.js.map +1 -0
- package/esm/lib/logger.d.ts +6 -0
- package/esm/lib/logger.d.ts.map +1 -0
- package/esm/lib/logger.js +5 -0
- package/esm/lib/logger.js.map +1 -0
- package/esm/lib/matchers.d.ts +59 -0
- package/esm/lib/matchers.d.ts.map +1 -0
- package/esm/lib/matchers.js +202 -0
- package/esm/lib/matchers.js.map +1 -0
- package/esm/lib/primitives.d.ts +26 -0
- package/esm/lib/primitives.d.ts.map +1 -0
- package/esm/lib/primitives.js +103 -0
- package/esm/lib/primitives.js.map +1 -0
- package/esm/lib/retries.d.ts +38 -0
- package/esm/lib/retries.d.ts.map +1 -0
- package/esm/lib/retries.js +150 -0
- package/esm/lib/retries.js.map +1 -0
- package/esm/lib/schemas.d.ts +21 -0
- package/esm/lib/schemas.d.ts.map +1 -0
- package/esm/lib/schemas.js +57 -0
- package/esm/lib/schemas.js.map +1 -0
- package/esm/lib/sdks.d.ts +63 -0
- package/esm/lib/sdks.d.ts.map +1 -0
- package/esm/lib/sdks.js +258 -0
- package/esm/lib/sdks.js.map +1 -0
- package/esm/lib/security.d.ts +80 -0
- package/esm/lib/security.d.ts.map +1 -0
- package/esm/lib/security.js +122 -0
- package/esm/lib/security.js.map +1 -0
- package/esm/lib/url.d.ts +5 -0
- package/esm/lib/url.d.ts.map +1 -0
- package/esm/lib/url.js +22 -0
- package/esm/lib/url.js.map +1 -0
- package/esm/models/error-response.d.ts +17 -0
- package/esm/models/error-response.d.ts.map +1 -0
- package/esm/models/error-response.js +15 -0
- package/esm/models/error-response.js.map +1 -0
- package/esm/models/errors/error-response.d.ts +21 -0
- package/esm/models/errors/error-response.d.ts.map +1 -0
- package/esm/models/errors/error-response.js +37 -0
- package/esm/models/errors/error-response.js.map +1 -0
- package/esm/models/errors/fluidapi-default-error.d.ts +10 -0
- package/esm/models/errors/fluidapi-default-error.d.ts.map +1 -0
- package/esm/models/errors/fluidapi-default-error.js +30 -0
- package/esm/models/errors/fluidapi-default-error.js.map +1 -0
- package/esm/models/errors/fluidapi-error.d.ts +19 -0
- package/esm/models/errors/fluidapi-error.d.ts.map +1 -0
- package/esm/models/errors/fluidapi-error.js +26 -0
- package/esm/models/errors/fluidapi-error.js.map +1 -0
- package/esm/models/errors/http-client-errors.d.ts +44 -0
- package/esm/models/errors/http-client-errors.d.ts.map +1 -0
- package/esm/models/errors/http-client-errors.js +56 -0
- package/esm/models/errors/http-client-errors.js.map +1 -0
- package/esm/models/errors/index.d.ts +7 -0
- package/esm/models/errors/index.d.ts.map +1 -0
- package/esm/models/errors/index.js +10 -0
- package/esm/models/errors/index.js.map +1 -0
- package/esm/models/errors/response-validation-error.d.ts +26 -0
- package/esm/models/errors/response-validation-error.d.ts.map +1 -0
- package/esm/models/errors/response-validation-error.js +37 -0
- package/esm/models/errors/response-validation-error.js.map +1 -0
- package/esm/models/errors/sdk-validation-error.d.ts +21 -0
- package/esm/models/errors/sdk-validation-error.d.ts.map +1 -0
- package/esm/models/errors/sdk-validation-error.js +52 -0
- package/esm/models/errors/sdk-validation-error.js.map +1 -0
- package/esm/models/health-response.d.ts +10 -0
- package/esm/models/health-response.d.ts.map +1 -0
- package/esm/models/health-response.js +14 -0
- package/esm/models/health-response.js.map +1 -0
- package/esm/models/index.d.ts +8 -0
- package/esm/models/index.d.ts.map +1 -0
- package/esm/models/index.js +11 -0
- package/esm/models/index.js.map +1 -0
- package/esm/models/issue-token-request.d.ts +31 -0
- package/esm/models/issue-token-request.d.ts.map +1 -0
- package/esm/models/issue-token-request.js +27 -0
- package/esm/models/issue-token-request.js.map +1 -0
- package/esm/models/jwk-set.d.ts +21 -0
- package/esm/models/jwk-set.d.ts.map +1 -0
- package/esm/models/jwk-set.js +26 -0
- package/esm/models/jwk-set.js.map +1 -0
- package/esm/models/operations/index.d.ts +4 -0
- package/esm/models/operations/index.d.ts.map +1 -0
- package/esm/models/operations/index.js +7 -0
- package/esm/models/operations/index.js.map +1 -0
- package/esm/models/operations/issue-fluid-token.d.ts +15 -0
- package/esm/models/operations/issue-fluid-token.d.ts.map +1 -0
- package/esm/models/operations/issue-fluid-token.js +16 -0
- package/esm/models/operations/issue-fluid-token.js.map +1 -0
- package/esm/models/operations/issue-token.d.ts +15 -0
- package/esm/models/operations/issue-token.d.ts.map +1 -0
- package/esm/models/operations/issue-token.js +16 -0
- package/esm/models/operations/issue-token.js.map +1 -0
- package/esm/models/operations/issue-user-token.d.ts +15 -0
- package/esm/models/operations/issue-user-token.d.ts.map +1 -0
- package/esm/models/operations/issue-user-token.js +16 -0
- package/esm/models/operations/issue-user-token.js.map +1 -0
- package/esm/models/token-data.d.ts +29 -0
- package/esm/models/token-data.d.ts.map +1 -0
- package/esm/models/token-data.js +30 -0
- package/esm/models/token-data.js.map +1 -0
- package/esm/models/user-token-data.d.ts +12 -0
- package/esm/models/user-token-data.d.ts.map +1 -0
- package/esm/models/user-token-data.js +23 -0
- package/esm/models/user-token-data.js.map +1 -0
- package/esm/models/user-token-request.d.ts +25 -0
- package/esm/models/user-token-request.d.ts.map +1 -0
- package/esm/models/user-token-request.js +26 -0
- package/esm/models/user-token-request.js.map +1 -0
- package/esm/sdk/index.d.ts +2 -0
- package/esm/sdk/index.d.ts.map +1 -0
- package/esm/sdk/index.js +5 -0
- package/esm/sdk/index.js.map +1 -0
- package/esm/sdk/metadata.d.ts +16 -0
- package/esm/sdk/metadata.d.ts.map +1 -0
- package/esm/sdk/metadata.js +25 -0
- package/esm/sdk/metadata.js.map +1 -0
- package/esm/sdk/sdk.d.ts +10 -0
- package/esm/sdk/sdk.d.ts.map +1 -0
- package/esm/sdk/sdk.js +17 -0
- package/esm/sdk/sdk.js.map +1 -0
- package/esm/sdk/tokens.d.ts +63 -0
- package/esm/sdk/tokens.d.ts.map +1 -0
- package/esm/sdk/tokens.js +74 -0
- package/esm/sdk/tokens.js.map +1 -0
- package/esm/types/async.d.ts +23 -0
- package/esm/types/async.d.ts.map +1 -0
- package/esm/types/async.js +28 -0
- package/esm/types/async.js.map +1 -0
- package/esm/types/blobs.d.ts +4 -0
- package/esm/types/blobs.d.ts.map +1 -0
- package/esm/types/blobs.js +25 -0
- package/esm/types/blobs.js.map +1 -0
- package/esm/types/const-date-time.d.ts +3 -0
- package/esm/types/const-date-time.d.ts.map +1 -0
- package/esm/types/const-date-time.js +10 -0
- package/esm/types/const-date-time.js.map +1 -0
- package/esm/types/default-to-zero-value.d.ts +12 -0
- package/esm/types/default-to-zero-value.d.ts.map +1 -0
- package/esm/types/default-to-zero-value.js +31 -0
- package/esm/types/default-to-zero-value.js.map +1 -0
- package/esm/types/enums.d.ts +9 -0
- package/esm/types/enums.d.ts.map +1 -0
- package/esm/types/enums.js +27 -0
- package/esm/types/enums.js.map +1 -0
- package/esm/types/fp.d.ts +31 -0
- package/esm/types/fp.d.ts.map +1 -0
- package/esm/types/fp.js +31 -0
- package/esm/types/fp.js.map +1 -0
- package/esm/types/index.d.ts +10 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +10 -0
- package/esm/types/index.js.map +1 -0
- package/esm/types/operations.d.ts +27 -0
- package/esm/types/operations.d.ts.map +1 -0
- package/esm/types/operations.js +77 -0
- package/esm/types/operations.js.map +1 -0
- package/esm/types/primitives.d.ts +11 -0
- package/esm/types/primitives.d.ts.map +1 -0
- package/esm/types/primitives.js +132 -0
- package/esm/types/primitives.js.map +1 -0
- package/esm/types/rfcdate.d.ts +21 -0
- package/esm/types/rfcdate.d.ts.map +1 -0
- package/esm/types/rfcdate.js +43 -0
- package/esm/types/rfcdate.js.map +1 -0
- package/esm/types/smart-union.d.ts +7 -0
- package/esm/types/smart-union.d.ts.map +1 -0
- package/esm/types/smart-union.js +117 -0
- package/esm/types/smart-union.js.map +1 -0
- package/esm/types/streams.d.ts +2 -0
- package/esm/types/streams.d.ts.map +1 -0
- package/esm/types/streams.js +15 -0
- package/esm/types/streams.js.map +1 -0
- package/esm/types/unrecognized.d.ts +16 -0
- package/esm/types/unrecognized.d.ts.map +1 -0
- package/esm/types/unrecognized.js +31 -0
- package/esm/types/unrecognized.js.map +1 -0
- package/examples/metadataHealthCheck.example.ts +24 -0
- package/jsr.json +27 -0
- package/package.json +62 -0
- package/src/core.ts +13 -0
- package/src/funcs/metadata-get-jwks.ts +145 -0
- package/src/funcs/metadata-health-check.ts +142 -0
- package/src/funcs/tokens-issue-fluid-token.ts +175 -0
- package/src/funcs/tokens-issue-token.ts +181 -0
- package/src/funcs/tokens-issue-user-token.ts +184 -0
- package/src/hooks/hooks.ts +132 -0
- package/src/hooks/index.ts +6 -0
- package/src/hooks/registration.ts +14 -0
- package/src/hooks/types.ts +107 -0
- package/src/index.ts +9 -0
- package/src/lib/base64.ts +39 -0
- package/src/lib/config.ts +94 -0
- package/src/lib/dlv.ts +53 -0
- package/src/lib/encodings.ts +501 -0
- package/src/lib/env.ts +53 -0
- package/src/lib/files.ts +82 -0
- package/src/lib/http.ts +323 -0
- package/src/lib/is-plain-object.ts +43 -0
- package/src/lib/logger.ts +9 -0
- package/src/lib/matchers.ts +353 -0
- package/src/lib/primitives.ts +150 -0
- package/src/lib/retries.ts +218 -0
- package/src/lib/schemas.ts +94 -0
- package/src/lib/sdks.ts +406 -0
- package/src/lib/security.ts +236 -0
- package/src/lib/url.ts +33 -0
- package/src/models/error-response.ts +36 -0
- package/src/models/errors/error-response.ts +56 -0
- package/src/models/errors/fluidapi-default-error.ts +40 -0
- package/src/models/errors/fluidapi-error.ts +35 -0
- package/src/models/errors/http-client-errors.ts +62 -0
- package/src/models/errors/index.ts +10 -0
- package/src/models/errors/response-validation-error.ts +50 -0
- package/src/models/errors/sdk-validation-error.ts +54 -0
- package/src/models/health-response.ts +31 -0
- package/src/models/index.ts +11 -0
- package/src/models/issue-token-request.ts +66 -0
- package/src/models/jwk-set.ts +57 -0
- package/src/models/operations/index.ts +7 -0
- package/src/models/operations/issue-fluid-token.ts +37 -0
- package/src/models/operations/issue-token.ts +37 -0
- package/src/models/operations/issue-user-token.ts +37 -0
- package/src/models/token-data.ts +65 -0
- package/src/models/user-token-data.ts +45 -0
- package/src/models/user-token-request.ts +60 -0
- package/src/sdk/index.ts +5 -0
- package/src/sdk/metadata.ts +38 -0
- package/src/sdk/sdk.ts +19 -0
- package/src/sdk/tokens.ts +100 -0
- package/src/types/async.ts +68 -0
- package/src/types/blobs.ts +33 -0
- package/src/types/const-date-time.ts +15 -0
- package/src/types/default-to-zero-value.ts +33 -0
- package/src/types/enums.ts +45 -0
- package/src/types/fp.ts +50 -0
- package/src/types/index.ts +13 -0
- package/src/types/operations.ts +105 -0
- package/src/types/primitives.ts +168 -0
- package/src/types/rfcdate.ts +54 -0
- package/src/types/smart-union.ts +153 -0
- package/src/types/streams.ts +21 -0
- package/src/types/unrecognized.ts +35 -0
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { bytesToBase64 } from "./base64.js";
|
|
6
|
+
import { isPlainObject } from "./is-plain-object.js";
|
|
7
|
+
|
|
8
|
+
export class EncodingError extends Error {
|
|
9
|
+
constructor(message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "EncodingError";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function encodeMatrix(
|
|
16
|
+
key: string,
|
|
17
|
+
value: unknown,
|
|
18
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
19
|
+
): string | undefined {
|
|
20
|
+
let out = "";
|
|
21
|
+
const pairs: [string, unknown][] = options?.explode
|
|
22
|
+
? explode(key, value)
|
|
23
|
+
: [[key, value]];
|
|
24
|
+
|
|
25
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const encodeString = (v: string) => {
|
|
30
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
31
|
+
};
|
|
32
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
33
|
+
|
|
34
|
+
pairs.forEach(([pk, pv]) => {
|
|
35
|
+
let tmp = "";
|
|
36
|
+
let encValue: string | null | undefined = null;
|
|
37
|
+
|
|
38
|
+
if (pv == null) {
|
|
39
|
+
return;
|
|
40
|
+
} else if (Array.isArray(pv)) {
|
|
41
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(",");
|
|
42
|
+
} else if (isPlainObject(pv)) {
|
|
43
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
44
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
45
|
+
});
|
|
46
|
+
encValue = mapped?.join("").slice(1);
|
|
47
|
+
} else {
|
|
48
|
+
encValue = `${encodeValue(pv)}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (encValue == null) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const keyPrefix = encodeString(pk);
|
|
56
|
+
tmp = `${keyPrefix}=${encValue}`;
|
|
57
|
+
// trim trailing '=' if value was empty
|
|
58
|
+
if (tmp === `${keyPrefix}=`) {
|
|
59
|
+
tmp = tmp.slice(0, -1);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// If we end up with the nothing then skip forward
|
|
63
|
+
if (!tmp) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
out += `;${tmp}`;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function encodeLabel(
|
|
74
|
+
key: string,
|
|
75
|
+
value: unknown,
|
|
76
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
77
|
+
): string | undefined {
|
|
78
|
+
let out = "";
|
|
79
|
+
const pairs: [string, unknown][] = options?.explode
|
|
80
|
+
? explode(key, value)
|
|
81
|
+
: [[key, value]];
|
|
82
|
+
|
|
83
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const encodeString = (v: string) => {
|
|
88
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
89
|
+
};
|
|
90
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
91
|
+
|
|
92
|
+
pairs.forEach(([pk, pv]) => {
|
|
93
|
+
let encValue: string | null | undefined = "";
|
|
94
|
+
|
|
95
|
+
if (pv == null) {
|
|
96
|
+
return;
|
|
97
|
+
} else if (Array.isArray(pv)) {
|
|
98
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(".");
|
|
99
|
+
} else if (isPlainObject(pv)) {
|
|
100
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
101
|
+
return `.${encodeString(k)}.${encodeValue(v)}`;
|
|
102
|
+
});
|
|
103
|
+
encValue = mapped?.join("").slice(1);
|
|
104
|
+
} else {
|
|
105
|
+
const k = options?.explode && isPlainObject(value)
|
|
106
|
+
? `${encodeString(pk)}=`
|
|
107
|
+
: "";
|
|
108
|
+
encValue = `${k}${encodeValue(pv)}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
out += encValue == null ? "" : `.${encValue}`;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type FormEncoder = (
|
|
118
|
+
key: string,
|
|
119
|
+
value: unknown,
|
|
120
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
121
|
+
) => string | undefined;
|
|
122
|
+
|
|
123
|
+
function formEncoder(sep: string): FormEncoder {
|
|
124
|
+
return (
|
|
125
|
+
key: string,
|
|
126
|
+
value: unknown,
|
|
127
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
128
|
+
) => {
|
|
129
|
+
let out = "";
|
|
130
|
+
const pairs: [string, unknown][] = options?.explode
|
|
131
|
+
? explode(key, value)
|
|
132
|
+
: [[key, value]];
|
|
133
|
+
|
|
134
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const encodeString = (v: string) => {
|
|
139
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
143
|
+
|
|
144
|
+
const encodedSep = encodeString(sep);
|
|
145
|
+
|
|
146
|
+
pairs.forEach(([pk, pv]) => {
|
|
147
|
+
let tmp = "";
|
|
148
|
+
let encValue: string | null | undefined = null;
|
|
149
|
+
|
|
150
|
+
if (pv == null) {
|
|
151
|
+
return;
|
|
152
|
+
} else if (Array.isArray(pv)) {
|
|
153
|
+
encValue = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(encodedSep);
|
|
154
|
+
} else if (isPlainObject(pv)) {
|
|
155
|
+
encValue = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
156
|
+
return `${encodeString(k)}${encodedSep}${encodeValue(v)}`;
|
|
157
|
+
})?.join(encodedSep);
|
|
158
|
+
} else {
|
|
159
|
+
encValue = `${encodeValue(pv)}`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (encValue == null) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
tmp = `${encodeString(pk)}=${encValue}`;
|
|
167
|
+
|
|
168
|
+
// If we end up with the nothing then skip forward
|
|
169
|
+
if (!tmp || tmp === "=") {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
out += `&${tmp}`;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
return out.slice(1);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export const encodeForm = formEncoder(",");
|
|
181
|
+
export const encodeSpaceDelimited = formEncoder(" ");
|
|
182
|
+
export const encodePipeDelimited = formEncoder("|");
|
|
183
|
+
|
|
184
|
+
export function encodeBodyForm(
|
|
185
|
+
key: string,
|
|
186
|
+
value: unknown,
|
|
187
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
188
|
+
): string {
|
|
189
|
+
let out = "";
|
|
190
|
+
const pairs: [string, unknown][] = options?.explode
|
|
191
|
+
? explode(key, value)
|
|
192
|
+
: [[key, value]];
|
|
193
|
+
|
|
194
|
+
const encodeString = (v: string) => {
|
|
195
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
199
|
+
|
|
200
|
+
pairs.forEach(([pk, pv]) => {
|
|
201
|
+
let tmp = "";
|
|
202
|
+
let encValue = "";
|
|
203
|
+
|
|
204
|
+
if (pv == null) {
|
|
205
|
+
return;
|
|
206
|
+
} else if (Array.isArray(pv)) {
|
|
207
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
208
|
+
} else if (isPlainObject(pv)) {
|
|
209
|
+
encValue = JSON.stringify(pv, jsonReplacer);
|
|
210
|
+
} else {
|
|
211
|
+
encValue = `${encodeValue(pv)}`;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
tmp = `${encodeString(pk)}=${encValue}`;
|
|
215
|
+
|
|
216
|
+
// If we end up with the nothing then skip forward
|
|
217
|
+
if (!tmp || tmp === "=") {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
out += `&${tmp}`;
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
return out.slice(1);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function encodeDeepObject(
|
|
228
|
+
key: string,
|
|
229
|
+
value: unknown,
|
|
230
|
+
options?: { charEncoding?: "percent" | "none" },
|
|
231
|
+
): string | undefined {
|
|
232
|
+
if (value == null) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (!isPlainObject(value)) {
|
|
237
|
+
throw new EncodingError(
|
|
238
|
+
`Value of parameter '${key}' which uses deepObject encoding must be an object or null`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return encodeDeepObjectObject(key, value, options);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function encodeDeepObjectObject(
|
|
246
|
+
key: string,
|
|
247
|
+
value: unknown,
|
|
248
|
+
options?: { charEncoding?: "percent" | "none" },
|
|
249
|
+
): string | undefined {
|
|
250
|
+
if (value == null) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
let out = "";
|
|
255
|
+
|
|
256
|
+
const encodeString = (v: string) => {
|
|
257
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
if (!isPlainObject(value)) {
|
|
261
|
+
throw new EncodingError(`Expected parameter '${key}' to be an object.`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
Object.entries(value).forEach(([ck, cv]) => {
|
|
265
|
+
if (cv == null) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const pk = `${key}[${ck}]`;
|
|
270
|
+
|
|
271
|
+
if (isPlainObject(cv)) {
|
|
272
|
+
const objOut = encodeDeepObjectObject(pk, cv, options);
|
|
273
|
+
|
|
274
|
+
out += objOut == null ? "" : `&${objOut}`;
|
|
275
|
+
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const pairs: unknown[] = Array.isArray(cv) ? cv : [cv];
|
|
280
|
+
const encoded = mapDefined(pairs, (v) => {
|
|
281
|
+
return `${encodeString(pk)}=${encodeString(serializeValue(v))}`;
|
|
282
|
+
})?.join("&");
|
|
283
|
+
|
|
284
|
+
out += encoded == null ? "" : `&${encoded}`;
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
return out.slice(1);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function encodeJSON(
|
|
291
|
+
key: string,
|
|
292
|
+
value: unknown,
|
|
293
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
294
|
+
): string | undefined {
|
|
295
|
+
if (typeof value === "undefined") {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const encodeString = (v: string) => {
|
|
300
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const encVal = encodeString(JSON.stringify(value, jsonReplacer));
|
|
304
|
+
|
|
305
|
+
return options?.explode ? encVal : `${encodeString(key)}=${encVal}`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export const encodeSimple = (
|
|
309
|
+
key: string,
|
|
310
|
+
value: unknown,
|
|
311
|
+
options?: { explode?: boolean; charEncoding?: "percent" | "none" },
|
|
312
|
+
): string | undefined => {
|
|
313
|
+
let out = "";
|
|
314
|
+
const pairs: [string, unknown][] = options?.explode
|
|
315
|
+
? explode(key, value)
|
|
316
|
+
: [[key, value]];
|
|
317
|
+
|
|
318
|
+
if (pairs.every(([_, v]) => v == null)) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const encodeString = (v: string) => {
|
|
323
|
+
return options?.charEncoding === "percent" ? encodeURIComponent(v) : v;
|
|
324
|
+
};
|
|
325
|
+
const encodeValue = (v: unknown) => encodeString(serializeValue(v));
|
|
326
|
+
|
|
327
|
+
pairs.forEach(([pk, pv]) => {
|
|
328
|
+
let tmp: string | null | undefined = "";
|
|
329
|
+
|
|
330
|
+
if (pv == null) {
|
|
331
|
+
return;
|
|
332
|
+
} else if (Array.isArray(pv)) {
|
|
333
|
+
tmp = mapDefined(pv, (v) => `${encodeValue(v)}`)?.join(",");
|
|
334
|
+
} else if (isPlainObject(pv)) {
|
|
335
|
+
const mapped = mapDefinedEntries(Object.entries(pv), ([k, v]) => {
|
|
336
|
+
return `,${encodeString(k)},${encodeValue(v)}`;
|
|
337
|
+
});
|
|
338
|
+
tmp = mapped?.join("").slice(1);
|
|
339
|
+
} else {
|
|
340
|
+
const k = options?.explode && isPlainObject(value) ? `${pk}=` : "";
|
|
341
|
+
tmp = `${k}${encodeValue(pv)}`;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
out += tmp ? `,${tmp}` : "";
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
return out.slice(1);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
function explode(key: string, value: unknown): [string, unknown][] {
|
|
351
|
+
if (Array.isArray(value)) {
|
|
352
|
+
return value.map((v) => [key, v]);
|
|
353
|
+
} else if (isPlainObject(value)) {
|
|
354
|
+
const o = value ?? {};
|
|
355
|
+
return Object.entries(o).map(([k, v]) => [k, v]);
|
|
356
|
+
} else {
|
|
357
|
+
return [[key, value]];
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function serializeValue(value: unknown): string {
|
|
362
|
+
if (value == null) {
|
|
363
|
+
return "";
|
|
364
|
+
} else if (value instanceof Date) {
|
|
365
|
+
return value.toISOString();
|
|
366
|
+
} else if (value instanceof Uint8Array) {
|
|
367
|
+
return bytesToBase64(value);
|
|
368
|
+
} else if (typeof value === "object") {
|
|
369
|
+
return JSON.stringify(value, jsonReplacer);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return `${value}`;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function jsonReplacer(_: string, value: unknown): unknown {
|
|
376
|
+
if (value instanceof Uint8Array) {
|
|
377
|
+
return bytesToBase64(value);
|
|
378
|
+
} else {
|
|
379
|
+
return value;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function mapDefined<T, R>(inp: T[], mapper: (v: T) => R): R[] | null {
|
|
384
|
+
const res = inp.reduce<R[]>((acc, v) => {
|
|
385
|
+
if (v == null) {
|
|
386
|
+
return acc;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const m = mapper(v);
|
|
390
|
+
if (m == null) {
|
|
391
|
+
return acc;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
acc.push(m);
|
|
395
|
+
|
|
396
|
+
return acc;
|
|
397
|
+
}, []);
|
|
398
|
+
|
|
399
|
+
return res.length ? res : null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function mapDefinedEntries<K, V, R>(
|
|
403
|
+
inp: Iterable<[K, V]>,
|
|
404
|
+
mapper: (v: [K, V]) => R,
|
|
405
|
+
): R[] | null {
|
|
406
|
+
const acc: R[] = [];
|
|
407
|
+
for (const [k, v] of inp) {
|
|
408
|
+
if (v == null) {
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const m = mapper([k, v]);
|
|
413
|
+
if (m == null) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
acc.push(m);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
return acc.length ? acc : null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
export function queryJoin(...args: (string | undefined)[]): string {
|
|
424
|
+
return args.filter(Boolean).join("&");
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
type QueryEncoderOptions = {
|
|
428
|
+
explode?: boolean;
|
|
429
|
+
charEncoding?: "percent" | "none";
|
|
430
|
+
allowEmptyValue?: string[];
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
type QueryEncoder = (
|
|
434
|
+
key: string,
|
|
435
|
+
value: unknown,
|
|
436
|
+
options?: QueryEncoderOptions,
|
|
437
|
+
) => string | undefined;
|
|
438
|
+
|
|
439
|
+
type BulkQueryEncoder = (
|
|
440
|
+
values: Record<string, unknown>,
|
|
441
|
+
options?: QueryEncoderOptions,
|
|
442
|
+
) => string;
|
|
443
|
+
|
|
444
|
+
export function queryEncoder(f: QueryEncoder): BulkQueryEncoder {
|
|
445
|
+
const bulkEncode = function(
|
|
446
|
+
values: Record<string, unknown>,
|
|
447
|
+
options?: QueryEncoderOptions,
|
|
448
|
+
): string {
|
|
449
|
+
const opts: QueryEncoderOptions = {
|
|
450
|
+
...options,
|
|
451
|
+
explode: options?.explode ?? true,
|
|
452
|
+
charEncoding: options?.charEncoding ?? "percent",
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
const allowEmptySet = new Set(options?.allowEmptyValue ?? []);
|
|
456
|
+
|
|
457
|
+
const encoded = Object.entries(values).map(([key, value]) => {
|
|
458
|
+
if (allowEmptySet.has(key)) {
|
|
459
|
+
if (
|
|
460
|
+
value === undefined
|
|
461
|
+
|| value === null
|
|
462
|
+
|| value === ""
|
|
463
|
+
|| (Array.isArray(value) && value.length === 0)
|
|
464
|
+
) {
|
|
465
|
+
return `${encodeURIComponent(key)}=`;
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return f(key, value, opts);
|
|
469
|
+
});
|
|
470
|
+
return queryJoin(...encoded);
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
return bulkEncode;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export const encodeJSONQuery = queryEncoder(encodeJSON);
|
|
477
|
+
export const encodeFormQuery = queryEncoder(encodeForm);
|
|
478
|
+
export const encodeSpaceDelimitedQuery = queryEncoder(encodeSpaceDelimited);
|
|
479
|
+
export const encodePipeDelimitedQuery = queryEncoder(encodePipeDelimited);
|
|
480
|
+
export const encodeDeepObjectQuery = queryEncoder(encodeDeepObject);
|
|
481
|
+
|
|
482
|
+
export function appendForm(
|
|
483
|
+
fd: FormData,
|
|
484
|
+
key: string,
|
|
485
|
+
value: unknown,
|
|
486
|
+
fileName?: string,
|
|
487
|
+
): void {
|
|
488
|
+
if (value == null) {
|
|
489
|
+
return;
|
|
490
|
+
} else if (value instanceof Blob && fileName) {
|
|
491
|
+
fd.append(key, value, fileName);
|
|
492
|
+
} else if (value instanceof Blob) {
|
|
493
|
+
fd.append(key, value);
|
|
494
|
+
} else if (Array.isArray(value)) {
|
|
495
|
+
value.forEach((v) => {
|
|
496
|
+
appendForm(fd, key, v);
|
|
497
|
+
});
|
|
498
|
+
} else {
|
|
499
|
+
fd.append(key, String(value));
|
|
500
|
+
}
|
|
501
|
+
}
|
package/src/lib/env.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { dlv } from "./dlv.js";
|
|
7
|
+
|
|
8
|
+
export interface Env {
|
|
9
|
+
FLUIDAPI_DEBUG?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const envSchema: z.ZodMiniType<Env, unknown> = z.object({
|
|
13
|
+
FLUIDAPI_DEBUG: z.optional(z.coerce.boolean()),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checks for the existence of the Deno global object to determine the environment.
|
|
18
|
+
* @returns {boolean} True if the runtime is Deno, false otherwise.
|
|
19
|
+
*/
|
|
20
|
+
function isDeno() {
|
|
21
|
+
if ("Deno" in globalThis) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let envMemo: Env | undefined = undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Reads and validates environment variables.
|
|
31
|
+
*/
|
|
32
|
+
export function env(): Env {
|
|
33
|
+
if (envMemo) {
|
|
34
|
+
return envMemo;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let envObject: Record<string, unknown> = {};
|
|
38
|
+
if (isDeno()) {
|
|
39
|
+
envObject = (globalThis as any).Deno?.env?.toObject?.() ?? {};
|
|
40
|
+
} else {
|
|
41
|
+
envObject = dlv(globalThis, "process.env") ?? {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
envMemo = envSchema.parse(envObject);
|
|
45
|
+
return envMemo;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Clears the cached env object. Useful for testing with a fresh environment.
|
|
50
|
+
*/
|
|
51
|
+
export function resetEnv() {
|
|
52
|
+
envMemo = undefined;
|
|
53
|
+
}
|
package/src/lib/files.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Consumes a stream and returns a concatenated array buffer. Useful in
|
|
7
|
+
* situations where we need to read the whole file because it forms part of a
|
|
8
|
+
* larger payload containing other fields, and we can't modify the underlying
|
|
9
|
+
* request structure.
|
|
10
|
+
*/
|
|
11
|
+
export async function readableStreamToArrayBuffer(
|
|
12
|
+
readable: ReadableStream<Uint8Array>,
|
|
13
|
+
): Promise<ArrayBuffer> {
|
|
14
|
+
const reader = readable.getReader();
|
|
15
|
+
const chunks: Uint8Array[] = [];
|
|
16
|
+
|
|
17
|
+
let totalLength = 0;
|
|
18
|
+
let done = false;
|
|
19
|
+
|
|
20
|
+
while (!done) {
|
|
21
|
+
const { value, done: doneReading } = await reader.read();
|
|
22
|
+
|
|
23
|
+
if (doneReading) {
|
|
24
|
+
done = true;
|
|
25
|
+
} else {
|
|
26
|
+
chunks.push(value);
|
|
27
|
+
totalLength += value.length;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const concatenatedChunks = new Uint8Array(totalLength);
|
|
32
|
+
let offset = 0;
|
|
33
|
+
|
|
34
|
+
for (const chunk of chunks) {
|
|
35
|
+
concatenatedChunks.set(chunk, offset);
|
|
36
|
+
offset += chunk.length;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return concatenatedChunks.buffer as ArrayBuffer;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Determines the MIME content type based on a file's extension.
|
|
44
|
+
* Returns null if the extension is not recognized.
|
|
45
|
+
*/
|
|
46
|
+
export function getContentTypeFromFileName(fileName: string): string | null {
|
|
47
|
+
if (!fileName) return null;
|
|
48
|
+
|
|
49
|
+
const ext = fileName.toLowerCase().split(".").pop();
|
|
50
|
+
if (!ext) return null;
|
|
51
|
+
|
|
52
|
+
const mimeTypes: Record<string, string> = {
|
|
53
|
+
json: "application/json",
|
|
54
|
+
xml: "application/xml",
|
|
55
|
+
html: "text/html",
|
|
56
|
+
htm: "text/html",
|
|
57
|
+
txt: "text/plain",
|
|
58
|
+
csv: "text/csv",
|
|
59
|
+
pdf: "application/pdf",
|
|
60
|
+
png: "image/png",
|
|
61
|
+
jpg: "image/jpeg",
|
|
62
|
+
jpeg: "image/jpeg",
|
|
63
|
+
gif: "image/gif",
|
|
64
|
+
svg: "image/svg+xml",
|
|
65
|
+
js: "application/javascript",
|
|
66
|
+
css: "text/css",
|
|
67
|
+
zip: "application/zip",
|
|
68
|
+
tar: "application/x-tar",
|
|
69
|
+
gz: "application/gzip",
|
|
70
|
+
mp4: "video/mp4",
|
|
71
|
+
mp3: "audio/mpeg",
|
|
72
|
+
wav: "audio/wav",
|
|
73
|
+
webp: "image/webp",
|
|
74
|
+
ico: "image/x-icon",
|
|
75
|
+
woff: "font/woff",
|
|
76
|
+
woff2: "font/woff2",
|
|
77
|
+
ttf: "font/ttf",
|
|
78
|
+
otf: "font/otf",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return mimeTypes[ext] || null;
|
|
82
|
+
}
|