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,175 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { FluidapiCore } from "../core.js";
|
|
7
|
+
import { encodeBodyForm } from "../lib/encodings.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { pathToFunc } from "../lib/url.js";
|
|
13
|
+
import { FluidapiError } from "../models/errors/fluidapi-error.js";
|
|
14
|
+
import {
|
|
15
|
+
ConnectionError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
RequestAbortedError,
|
|
18
|
+
RequestTimeoutError,
|
|
19
|
+
UnexpectedClientError,
|
|
20
|
+
} from "../models/errors/http-client-errors.js";
|
|
21
|
+
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/response-validation-error.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
|
|
24
|
+
import * as models from "../models/index.js";
|
|
25
|
+
import * as operations from "../models/operations/index.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { Result } from "../types/fp.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Issue Fluid-signed M2M token
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Validates client credentials against the Authorization Server and then
|
|
34
|
+
* generates a JWT signed by Fluid.
|
|
35
|
+
*
|
|
36
|
+
* This endpoint coexists with `/oauth2/token`.
|
|
37
|
+
* Use `/oauth2/token` when you want the standard Hydra-backed token flow.
|
|
38
|
+
* Use `/oauth2/token-fluid` when you need a Fluid-signed JWT carrying
|
|
39
|
+
* `workspace_id`, `tenant_id`, `client_id`, and `credential_type` claims for M2M calls.
|
|
40
|
+
*/
|
|
41
|
+
export function tokensIssueFluidToken(
|
|
42
|
+
client: FluidapiCore,
|
|
43
|
+
request: models.IssueTokenRequest,
|
|
44
|
+
options?: RequestOptions,
|
|
45
|
+
): APIPromise<
|
|
46
|
+
Result<
|
|
47
|
+
operations.IssueFluidTokenResponse,
|
|
48
|
+
| errors.ErrorResponse
|
|
49
|
+
| FluidapiError
|
|
50
|
+
| ResponseValidationError
|
|
51
|
+
| ConnectionError
|
|
52
|
+
| RequestAbortedError
|
|
53
|
+
| RequestTimeoutError
|
|
54
|
+
| InvalidRequestError
|
|
55
|
+
| UnexpectedClientError
|
|
56
|
+
| SDKValidationError
|
|
57
|
+
>
|
|
58
|
+
> {
|
|
59
|
+
return new APIPromise($do(
|
|
60
|
+
client,
|
|
61
|
+
request,
|
|
62
|
+
options,
|
|
63
|
+
));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async function $do(
|
|
67
|
+
client: FluidapiCore,
|
|
68
|
+
request: models.IssueTokenRequest,
|
|
69
|
+
options?: RequestOptions,
|
|
70
|
+
): Promise<
|
|
71
|
+
[
|
|
72
|
+
Result<
|
|
73
|
+
operations.IssueFluidTokenResponse,
|
|
74
|
+
| errors.ErrorResponse
|
|
75
|
+
| FluidapiError
|
|
76
|
+
| ResponseValidationError
|
|
77
|
+
| ConnectionError
|
|
78
|
+
| RequestAbortedError
|
|
79
|
+
| RequestTimeoutError
|
|
80
|
+
| InvalidRequestError
|
|
81
|
+
| UnexpectedClientError
|
|
82
|
+
| SDKValidationError
|
|
83
|
+
>,
|
|
84
|
+
APICall,
|
|
85
|
+
]
|
|
86
|
+
> {
|
|
87
|
+
const parsed = safeParse(
|
|
88
|
+
request,
|
|
89
|
+
(value) => z.parse(models.IssueTokenRequest$outboundSchema, value),
|
|
90
|
+
"Input validation failed",
|
|
91
|
+
);
|
|
92
|
+
if (!parsed.ok) {
|
|
93
|
+
return [parsed, { status: "invalid" }];
|
|
94
|
+
}
|
|
95
|
+
const payload = parsed.value;
|
|
96
|
+
|
|
97
|
+
const body = Object.entries(payload || {}).map(([k, v]) => {
|
|
98
|
+
return encodeBodyForm(k, v, { charEncoding: "percent" });
|
|
99
|
+
}).join("&");
|
|
100
|
+
|
|
101
|
+
const path = pathToFunc("/oauth2/token-fluid")();
|
|
102
|
+
|
|
103
|
+
const headers = new Headers(compactMap({
|
|
104
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
105
|
+
Accept: "application/json",
|
|
106
|
+
}));
|
|
107
|
+
|
|
108
|
+
const context = {
|
|
109
|
+
options: client._options,
|
|
110
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
111
|
+
operationID: "issueFluidToken",
|
|
112
|
+
oAuth2Scopes: null,
|
|
113
|
+
|
|
114
|
+
resolvedSecurity: null,
|
|
115
|
+
|
|
116
|
+
securitySource: null,
|
|
117
|
+
retryConfig: options?.retries
|
|
118
|
+
|| client._options.retryConfig
|
|
119
|
+
|| { strategy: "none" },
|
|
120
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const requestRes = client._createRequest(context, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
baseURL: options?.serverURL,
|
|
126
|
+
path: path,
|
|
127
|
+
headers: headers,
|
|
128
|
+
body: body,
|
|
129
|
+
userAgent: client._options.userAgent,
|
|
130
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
131
|
+
}, options);
|
|
132
|
+
if (!requestRes.ok) {
|
|
133
|
+
return [requestRes, { status: "invalid" }];
|
|
134
|
+
}
|
|
135
|
+
const req = requestRes.value;
|
|
136
|
+
|
|
137
|
+
const doResult = await client._do(req, {
|
|
138
|
+
context,
|
|
139
|
+
errorCodes: ["400", "401", "4XX", "502", "5XX"],
|
|
140
|
+
retryConfig: context.retryConfig,
|
|
141
|
+
retryCodes: context.retryCodes,
|
|
142
|
+
});
|
|
143
|
+
if (!doResult.ok) {
|
|
144
|
+
return [doResult, { status: "request-error", request: req }];
|
|
145
|
+
}
|
|
146
|
+
const response = doResult.value;
|
|
147
|
+
|
|
148
|
+
const responseFields = {
|
|
149
|
+
HttpMeta: { Response: response, Request: req },
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const [result] = await M.match<
|
|
153
|
+
operations.IssueFluidTokenResponse,
|
|
154
|
+
| errors.ErrorResponse
|
|
155
|
+
| FluidapiError
|
|
156
|
+
| ResponseValidationError
|
|
157
|
+
| ConnectionError
|
|
158
|
+
| RequestAbortedError
|
|
159
|
+
| RequestTimeoutError
|
|
160
|
+
| InvalidRequestError
|
|
161
|
+
| UnexpectedClientError
|
|
162
|
+
| SDKValidationError
|
|
163
|
+
>(
|
|
164
|
+
M.json(200, operations.IssueFluidTokenResponse$inboundSchema),
|
|
165
|
+
M.jsonErr([400, 401], errors.ErrorResponse$inboundSchema),
|
|
166
|
+
M.jsonErr(502, errors.ErrorResponse$inboundSchema),
|
|
167
|
+
M.fail("4XX"),
|
|
168
|
+
M.fail("5XX"),
|
|
169
|
+
)(response, req, { extraFields: responseFields });
|
|
170
|
+
if (!result.ok) {
|
|
171
|
+
return [result, { status: "complete", request: req, response }];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return [result, { status: "complete", request: req, response }];
|
|
175
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { FluidapiCore } from "../core.js";
|
|
7
|
+
import { encodeBodyForm } from "../lib/encodings.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { pathToFunc } from "../lib/url.js";
|
|
13
|
+
import { FluidapiError } from "../models/errors/fluidapi-error.js";
|
|
14
|
+
import {
|
|
15
|
+
ConnectionError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
RequestAbortedError,
|
|
18
|
+
RequestTimeoutError,
|
|
19
|
+
UnexpectedClientError,
|
|
20
|
+
} from "../models/errors/http-client-errors.js";
|
|
21
|
+
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/response-validation-error.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
|
|
24
|
+
import * as models from "../models/index.js";
|
|
25
|
+
import * as operations from "../models/operations/index.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { Result } from "../types/fp.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Issue access token (client_credentials)
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Standard OAuth2 token endpoint. Performs a `client_credentials` grant
|
|
34
|
+
* against the Authorization Server and returns the access token (JWT).
|
|
35
|
+
*
|
|
36
|
+
* The OAuth2 client must be registered first via
|
|
37
|
+
* `POST /v1/tenants/{tenant_id}/credentials`.
|
|
38
|
+
*
|
|
39
|
+
* ### Scope reduction
|
|
40
|
+
*
|
|
41
|
+
* By default the token is issued with all scopes configured for the tenant.
|
|
42
|
+
* You can request a subset by passing `scope` in the form body.
|
|
43
|
+
* Requesting a scope not in the tenant's allowlist returns `400 invalid_scope`.
|
|
44
|
+
*
|
|
45
|
+
* **Available scopes:** `fluid:api`
|
|
46
|
+
*/
|
|
47
|
+
export function tokensIssueToken(
|
|
48
|
+
client: FluidapiCore,
|
|
49
|
+
request: models.IssueTokenRequest,
|
|
50
|
+
options?: RequestOptions,
|
|
51
|
+
): APIPromise<
|
|
52
|
+
Result<
|
|
53
|
+
operations.IssueTokenResponse,
|
|
54
|
+
| errors.ErrorResponse
|
|
55
|
+
| FluidapiError
|
|
56
|
+
| ResponseValidationError
|
|
57
|
+
| ConnectionError
|
|
58
|
+
| RequestAbortedError
|
|
59
|
+
| RequestTimeoutError
|
|
60
|
+
| InvalidRequestError
|
|
61
|
+
| UnexpectedClientError
|
|
62
|
+
| SDKValidationError
|
|
63
|
+
>
|
|
64
|
+
> {
|
|
65
|
+
return new APIPromise($do(
|
|
66
|
+
client,
|
|
67
|
+
request,
|
|
68
|
+
options,
|
|
69
|
+
));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function $do(
|
|
73
|
+
client: FluidapiCore,
|
|
74
|
+
request: models.IssueTokenRequest,
|
|
75
|
+
options?: RequestOptions,
|
|
76
|
+
): Promise<
|
|
77
|
+
[
|
|
78
|
+
Result<
|
|
79
|
+
operations.IssueTokenResponse,
|
|
80
|
+
| errors.ErrorResponse
|
|
81
|
+
| FluidapiError
|
|
82
|
+
| ResponseValidationError
|
|
83
|
+
| ConnectionError
|
|
84
|
+
| RequestAbortedError
|
|
85
|
+
| RequestTimeoutError
|
|
86
|
+
| InvalidRequestError
|
|
87
|
+
| UnexpectedClientError
|
|
88
|
+
| SDKValidationError
|
|
89
|
+
>,
|
|
90
|
+
APICall,
|
|
91
|
+
]
|
|
92
|
+
> {
|
|
93
|
+
const parsed = safeParse(
|
|
94
|
+
request,
|
|
95
|
+
(value) => z.parse(models.IssueTokenRequest$outboundSchema, value),
|
|
96
|
+
"Input validation failed",
|
|
97
|
+
);
|
|
98
|
+
if (!parsed.ok) {
|
|
99
|
+
return [parsed, { status: "invalid" }];
|
|
100
|
+
}
|
|
101
|
+
const payload = parsed.value;
|
|
102
|
+
|
|
103
|
+
const body = Object.entries(payload || {}).map(([k, v]) => {
|
|
104
|
+
return encodeBodyForm(k, v, { charEncoding: "percent" });
|
|
105
|
+
}).join("&");
|
|
106
|
+
|
|
107
|
+
const path = pathToFunc("/oauth2/token")();
|
|
108
|
+
|
|
109
|
+
const headers = new Headers(compactMap({
|
|
110
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
111
|
+
Accept: "application/json",
|
|
112
|
+
}));
|
|
113
|
+
|
|
114
|
+
const context = {
|
|
115
|
+
options: client._options,
|
|
116
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
117
|
+
operationID: "issueToken",
|
|
118
|
+
oAuth2Scopes: null,
|
|
119
|
+
|
|
120
|
+
resolvedSecurity: null,
|
|
121
|
+
|
|
122
|
+
securitySource: null,
|
|
123
|
+
retryConfig: options?.retries
|
|
124
|
+
|| client._options.retryConfig
|
|
125
|
+
|| { strategy: "none" },
|
|
126
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const requestRes = client._createRequest(context, {
|
|
130
|
+
method: "POST",
|
|
131
|
+
baseURL: options?.serverURL,
|
|
132
|
+
path: path,
|
|
133
|
+
headers: headers,
|
|
134
|
+
body: body,
|
|
135
|
+
userAgent: client._options.userAgent,
|
|
136
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
137
|
+
}, options);
|
|
138
|
+
if (!requestRes.ok) {
|
|
139
|
+
return [requestRes, { status: "invalid" }];
|
|
140
|
+
}
|
|
141
|
+
const req = requestRes.value;
|
|
142
|
+
|
|
143
|
+
const doResult = await client._do(req, {
|
|
144
|
+
context,
|
|
145
|
+
errorCodes: ["400", "401", "4XX", "502", "5XX"],
|
|
146
|
+
retryConfig: context.retryConfig,
|
|
147
|
+
retryCodes: context.retryCodes,
|
|
148
|
+
});
|
|
149
|
+
if (!doResult.ok) {
|
|
150
|
+
return [doResult, { status: "request-error", request: req }];
|
|
151
|
+
}
|
|
152
|
+
const response = doResult.value;
|
|
153
|
+
|
|
154
|
+
const responseFields = {
|
|
155
|
+
HttpMeta: { Response: response, Request: req },
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const [result] = await M.match<
|
|
159
|
+
operations.IssueTokenResponse,
|
|
160
|
+
| errors.ErrorResponse
|
|
161
|
+
| FluidapiError
|
|
162
|
+
| ResponseValidationError
|
|
163
|
+
| ConnectionError
|
|
164
|
+
| RequestAbortedError
|
|
165
|
+
| RequestTimeoutError
|
|
166
|
+
| InvalidRequestError
|
|
167
|
+
| UnexpectedClientError
|
|
168
|
+
| SDKValidationError
|
|
169
|
+
>(
|
|
170
|
+
M.json(200, operations.IssueTokenResponse$inboundSchema),
|
|
171
|
+
M.jsonErr([400, 401], errors.ErrorResponse$inboundSchema),
|
|
172
|
+
M.jsonErr(502, errors.ErrorResponse$inboundSchema),
|
|
173
|
+
M.fail("4XX"),
|
|
174
|
+
M.fail("5XX"),
|
|
175
|
+
)(response, req, { extraFields: responseFields });
|
|
176
|
+
if (!result.ok) {
|
|
177
|
+
return [result, { status: "complete", request: req, response }];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return [result, { status: "complete", request: req, response }];
|
|
181
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import * as z from "zod/v4-mini";
|
|
6
|
+
import { FluidapiCore } from "../core.js";
|
|
7
|
+
import { encodeJSON } from "../lib/encodings.js";
|
|
8
|
+
import * as M from "../lib/matchers.js";
|
|
9
|
+
import { compactMap } from "../lib/primitives.js";
|
|
10
|
+
import { safeParse } from "../lib/schemas.js";
|
|
11
|
+
import { RequestOptions } from "../lib/sdks.js";
|
|
12
|
+
import { pathToFunc } from "../lib/url.js";
|
|
13
|
+
import { FluidapiError } from "../models/errors/fluidapi-error.js";
|
|
14
|
+
import {
|
|
15
|
+
ConnectionError,
|
|
16
|
+
InvalidRequestError,
|
|
17
|
+
RequestAbortedError,
|
|
18
|
+
RequestTimeoutError,
|
|
19
|
+
UnexpectedClientError,
|
|
20
|
+
} from "../models/errors/http-client-errors.js";
|
|
21
|
+
import * as errors from "../models/errors/index.js";
|
|
22
|
+
import { ResponseValidationError } from "../models/errors/response-validation-error.js";
|
|
23
|
+
import { SDKValidationError } from "../models/errors/sdk-validation-error.js";
|
|
24
|
+
import * as models from "../models/index.js";
|
|
25
|
+
import * as operations from "../models/operations/index.js";
|
|
26
|
+
import { APICall, APIPromise } from "../types/async.js";
|
|
27
|
+
import { Result } from "../types/fp.js";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Issue end-user token
|
|
31
|
+
*
|
|
32
|
+
* @remarks
|
|
33
|
+
* Issues a JWT for an end user (workspace user or customer user).
|
|
34
|
+
*
|
|
35
|
+
* Supported authentication modes:
|
|
36
|
+
* - `Authorization: Bearer <m2m_token>` — preferred. The token must be a
|
|
37
|
+
* Fluid-signed M2M JWT with `scope` including `fluid:api`.
|
|
38
|
+
* Canonical first-access provisioning via external lookup/create is only
|
|
39
|
+
* available in this mode.
|
|
40
|
+
* - HTTP Basic Auth with `client_id` + `client_secret`.
|
|
41
|
+
* In this mode the service does not perform canonical lookup/create.
|
|
42
|
+
*
|
|
43
|
+
* If `customer_external_id` is present, the JWT is issued with `scope: customer`.
|
|
44
|
+
* Otherwise it is issued with `scope: workspace`.
|
|
45
|
+
*
|
|
46
|
+
* When canonical first-access provisioning is enabled, `email` is required
|
|
47
|
+
* so the service can lookup or create the canonical user before issuing the token.
|
|
48
|
+
*
|
|
49
|
+
* When canonical provisioning is disabled by server configuration, the
|
|
50
|
+
* service may materialize local IAM context by assuming `external_id` is
|
|
51
|
+
* already the canonical `user_id`.
|
|
52
|
+
*/
|
|
53
|
+
export function tokensIssueUserToken(
|
|
54
|
+
client: FluidapiCore,
|
|
55
|
+
request: models.UserTokenRequest,
|
|
56
|
+
options?: RequestOptions,
|
|
57
|
+
): APIPromise<
|
|
58
|
+
Result<
|
|
59
|
+
operations.IssueUserTokenResponse,
|
|
60
|
+
| errors.ErrorResponse
|
|
61
|
+
| FluidapiError
|
|
62
|
+
| ResponseValidationError
|
|
63
|
+
| ConnectionError
|
|
64
|
+
| RequestAbortedError
|
|
65
|
+
| RequestTimeoutError
|
|
66
|
+
| InvalidRequestError
|
|
67
|
+
| UnexpectedClientError
|
|
68
|
+
| SDKValidationError
|
|
69
|
+
>
|
|
70
|
+
> {
|
|
71
|
+
return new APIPromise($do(
|
|
72
|
+
client,
|
|
73
|
+
request,
|
|
74
|
+
options,
|
|
75
|
+
));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function $do(
|
|
79
|
+
client: FluidapiCore,
|
|
80
|
+
request: models.UserTokenRequest,
|
|
81
|
+
options?: RequestOptions,
|
|
82
|
+
): Promise<
|
|
83
|
+
[
|
|
84
|
+
Result<
|
|
85
|
+
operations.IssueUserTokenResponse,
|
|
86
|
+
| errors.ErrorResponse
|
|
87
|
+
| FluidapiError
|
|
88
|
+
| ResponseValidationError
|
|
89
|
+
| ConnectionError
|
|
90
|
+
| RequestAbortedError
|
|
91
|
+
| RequestTimeoutError
|
|
92
|
+
| InvalidRequestError
|
|
93
|
+
| UnexpectedClientError
|
|
94
|
+
| SDKValidationError
|
|
95
|
+
>,
|
|
96
|
+
APICall,
|
|
97
|
+
]
|
|
98
|
+
> {
|
|
99
|
+
const parsed = safeParse(
|
|
100
|
+
request,
|
|
101
|
+
(value) => z.parse(models.UserTokenRequest$outboundSchema, value),
|
|
102
|
+
"Input validation failed",
|
|
103
|
+
);
|
|
104
|
+
if (!parsed.ok) {
|
|
105
|
+
return [parsed, { status: "invalid" }];
|
|
106
|
+
}
|
|
107
|
+
const payload = parsed.value;
|
|
108
|
+
const body = encodeJSON("body", payload, { explode: true });
|
|
109
|
+
|
|
110
|
+
const path = pathToFunc("/users/token")();
|
|
111
|
+
|
|
112
|
+
const headers = new Headers(compactMap({
|
|
113
|
+
"Content-Type": "application/json",
|
|
114
|
+
Accept: "application/json",
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
const context = {
|
|
118
|
+
options: client._options,
|
|
119
|
+
baseURL: options?.serverURL ?? client._baseURL ?? "",
|
|
120
|
+
operationID: "issueUserToken",
|
|
121
|
+
oAuth2Scopes: null,
|
|
122
|
+
|
|
123
|
+
resolvedSecurity: null,
|
|
124
|
+
|
|
125
|
+
securitySource: null,
|
|
126
|
+
retryConfig: options?.retries
|
|
127
|
+
|| client._options.retryConfig
|
|
128
|
+
|| { strategy: "none" },
|
|
129
|
+
retryCodes: options?.retryCodes || ["429", "500", "502", "503", "504"],
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const requestRes = client._createRequest(context, {
|
|
133
|
+
method: "POST",
|
|
134
|
+
baseURL: options?.serverURL,
|
|
135
|
+
path: path,
|
|
136
|
+
headers: headers,
|
|
137
|
+
body: body,
|
|
138
|
+
userAgent: client._options.userAgent,
|
|
139
|
+
timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1,
|
|
140
|
+
}, options);
|
|
141
|
+
if (!requestRes.ok) {
|
|
142
|
+
return [requestRes, { status: "invalid" }];
|
|
143
|
+
}
|
|
144
|
+
const req = requestRes.value;
|
|
145
|
+
|
|
146
|
+
const doResult = await client._do(req, {
|
|
147
|
+
context,
|
|
148
|
+
errorCodes: ["400", "401", "403", "404", "409", "4XX", "502", "5XX"],
|
|
149
|
+
retryConfig: context.retryConfig,
|
|
150
|
+
retryCodes: context.retryCodes,
|
|
151
|
+
});
|
|
152
|
+
if (!doResult.ok) {
|
|
153
|
+
return [doResult, { status: "request-error", request: req }];
|
|
154
|
+
}
|
|
155
|
+
const response = doResult.value;
|
|
156
|
+
|
|
157
|
+
const responseFields = {
|
|
158
|
+
HttpMeta: { Response: response, Request: req },
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const [result] = await M.match<
|
|
162
|
+
operations.IssueUserTokenResponse,
|
|
163
|
+
| errors.ErrorResponse
|
|
164
|
+
| FluidapiError
|
|
165
|
+
| ResponseValidationError
|
|
166
|
+
| ConnectionError
|
|
167
|
+
| RequestAbortedError
|
|
168
|
+
| RequestTimeoutError
|
|
169
|
+
| InvalidRequestError
|
|
170
|
+
| UnexpectedClientError
|
|
171
|
+
| SDKValidationError
|
|
172
|
+
>(
|
|
173
|
+
M.json(200, operations.IssueUserTokenResponse$inboundSchema),
|
|
174
|
+
M.jsonErr([400, 401, 403, 404, 409], errors.ErrorResponse$inboundSchema),
|
|
175
|
+
M.jsonErr(502, errors.ErrorResponse$inboundSchema),
|
|
176
|
+
M.fail("4XX"),
|
|
177
|
+
M.fail("5XX"),
|
|
178
|
+
)(response, req, { extraFields: responseFields });
|
|
179
|
+
if (!result.ok) {
|
|
180
|
+
return [result, { status: "complete", request: req, response }];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return [result, { status: "complete", request: req, response }];
|
|
184
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { SDKOptions } from "../lib/config.js";
|
|
6
|
+
import { RequestInput } from "../lib/http.js";
|
|
7
|
+
import {
|
|
8
|
+
AfterErrorContext,
|
|
9
|
+
AfterErrorHook,
|
|
10
|
+
AfterSuccessContext,
|
|
11
|
+
AfterSuccessHook,
|
|
12
|
+
BeforeCreateRequestContext,
|
|
13
|
+
BeforeCreateRequestHook,
|
|
14
|
+
BeforeRequestContext,
|
|
15
|
+
BeforeRequestHook,
|
|
16
|
+
Hook,
|
|
17
|
+
Hooks,
|
|
18
|
+
SDKInitHook,
|
|
19
|
+
} from "./types.js";
|
|
20
|
+
|
|
21
|
+
import { initHooks } from "./registration.js";
|
|
22
|
+
|
|
23
|
+
export class SDKHooks implements Hooks {
|
|
24
|
+
sdkInitHooks: SDKInitHook[] = [];
|
|
25
|
+
beforeCreateRequestHooks: BeforeCreateRequestHook[] = [];
|
|
26
|
+
beforeRequestHooks: BeforeRequestHook[] = [];
|
|
27
|
+
afterSuccessHooks: AfterSuccessHook[] = [];
|
|
28
|
+
afterErrorHooks: AfterErrorHook[] = [];
|
|
29
|
+
|
|
30
|
+
constructor() {
|
|
31
|
+
const presetHooks: Array<Hook> = [];
|
|
32
|
+
|
|
33
|
+
for (const hook of presetHooks) {
|
|
34
|
+
if ("sdkInit" in hook) {
|
|
35
|
+
this.registerSDKInitHook(hook);
|
|
36
|
+
}
|
|
37
|
+
if ("beforeCreateRequest" in hook) {
|
|
38
|
+
this.registerBeforeCreateRequestHook(hook);
|
|
39
|
+
}
|
|
40
|
+
if ("beforeRequest" in hook) {
|
|
41
|
+
this.registerBeforeRequestHook(hook);
|
|
42
|
+
}
|
|
43
|
+
if ("afterSuccess" in hook) {
|
|
44
|
+
this.registerAfterSuccessHook(hook);
|
|
45
|
+
}
|
|
46
|
+
if ("afterError" in hook) {
|
|
47
|
+
this.registerAfterErrorHook(hook);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
initHooks(this);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
registerSDKInitHook(hook: SDKInitHook) {
|
|
54
|
+
this.sdkInitHooks.push(hook);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
registerBeforeCreateRequestHook(hook: BeforeCreateRequestHook) {
|
|
58
|
+
this.beforeCreateRequestHooks.push(hook);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
registerBeforeRequestHook(hook: BeforeRequestHook) {
|
|
62
|
+
this.beforeRequestHooks.push(hook);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
registerAfterSuccessHook(hook: AfterSuccessHook) {
|
|
66
|
+
this.afterSuccessHooks.push(hook);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
registerAfterErrorHook(hook: AfterErrorHook) {
|
|
70
|
+
this.afterErrorHooks.push(hook);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
sdkInit(opts: SDKOptions): SDKOptions {
|
|
74
|
+
return this.sdkInitHooks.reduce((opts, hook) => hook.sdkInit(opts), opts);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
beforeCreateRequest(
|
|
78
|
+
hookCtx: BeforeCreateRequestContext,
|
|
79
|
+
input: RequestInput,
|
|
80
|
+
): RequestInput {
|
|
81
|
+
let inp = input;
|
|
82
|
+
|
|
83
|
+
for (const hook of this.beforeCreateRequestHooks) {
|
|
84
|
+
inp = hook.beforeCreateRequest(hookCtx, inp);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return inp;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async beforeRequest(
|
|
91
|
+
hookCtx: BeforeRequestContext,
|
|
92
|
+
request: Request,
|
|
93
|
+
): Promise<Request> {
|
|
94
|
+
let req = request;
|
|
95
|
+
|
|
96
|
+
for (const hook of this.beforeRequestHooks) {
|
|
97
|
+
req = await hook.beforeRequest(hookCtx, req);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return req;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async afterSuccess(
|
|
104
|
+
hookCtx: AfterSuccessContext,
|
|
105
|
+
response: Response,
|
|
106
|
+
): Promise<Response> {
|
|
107
|
+
let res = response;
|
|
108
|
+
|
|
109
|
+
for (const hook of this.afterSuccessHooks) {
|
|
110
|
+
res = await hook.afterSuccess(hookCtx, res);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return res;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async afterError(
|
|
117
|
+
hookCtx: AfterErrorContext,
|
|
118
|
+
response: Response | null,
|
|
119
|
+
error: unknown,
|
|
120
|
+
): Promise<{ response: Response | null; error: unknown }> {
|
|
121
|
+
let res = response;
|
|
122
|
+
let err = error;
|
|
123
|
+
|
|
124
|
+
for (const hook of this.afterErrorHooks) {
|
|
125
|
+
const result = await hook.afterError(hookCtx, res, err);
|
|
126
|
+
res = result.response;
|
|
127
|
+
err = result.error;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return { response: res, error: err };
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Hooks } from "./types.js";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* This file is only ever generated once on the first generation and then is free to be modified.
|
|
5
|
+
* Any hooks you wish to add should be registered in the initHooks function. Feel free to define them
|
|
6
|
+
* in this file or in separate files in the hooks folder.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
// @ts-expect-error remove this line when you add your first hook and hooks is used
|
|
10
|
+
export function initHooks(hooks: Hooks) {
|
|
11
|
+
// Add hooks by calling hooks.register{ClientInit/BeforeCreateRequest/BeforeRequest/AfterSuccess/AfterError}Hook
|
|
12
|
+
// with an instance of a hook that implements that specific Hook interface
|
|
13
|
+
// Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
14
|
+
}
|