|
| 1 | +/* |
| 2 | + * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. |
| 3 | + */ |
| 4 | + |
| 5 | +import { NovuCore } from "../core.js"; |
| 6 | +import { encodeSimple } from "../lib/encodings.js"; |
| 7 | +import * as M from "../lib/matchers.js"; |
| 8 | +import { compactMap } from "../lib/primitives.js"; |
| 9 | +import { safeParse } from "../lib/schemas.js"; |
| 10 | +import { RequestOptions } from "../lib/sdks.js"; |
| 11 | +import { extractSecurity, resolveGlobalSecurity } from "../lib/security.js"; |
| 12 | +import { pathToFunc } from "../lib/url.js"; |
| 13 | +import { |
| 14 | + ConnectionError, |
| 15 | + InvalidRequestError, |
| 16 | + RequestAbortedError, |
| 17 | + RequestTimeoutError, |
| 18 | + UnexpectedClientError, |
| 19 | +} from "../models/errors/httpclienterrors.js"; |
| 20 | +import * as errors from "../models/errors/index.js"; |
| 21 | +import { SDKError } from "../models/errors/sdkerror.js"; |
| 22 | +import { SDKValidationError } from "../models/errors/sdkvalidationerror.js"; |
| 23 | +import * as operations from "../models/operations/index.js"; |
| 24 | +import { Result } from "../types/fp.js"; |
| 25 | + |
| 26 | +export async function generateRandomNumber( |
| 27 | + client: NovuCore, |
| 28 | + idempotencyKey?: string | undefined, |
| 29 | + options?: RequestOptions, |
| 30 | +): Promise< |
| 31 | + Result< |
| 32 | + operations.HealthControllerGenerateRandomNumberResponse, |
| 33 | + | errors.ErrorDto |
| 34 | + | errors.ErrorDto |
| 35 | + | errors.ValidationErrorDto |
| 36 | + | errors.ErrorDto |
| 37 | + | SDKError |
| 38 | + | SDKValidationError |
| 39 | + | UnexpectedClientError |
| 40 | + | InvalidRequestError |
| 41 | + | RequestAbortedError |
| 42 | + | RequestTimeoutError |
| 43 | + | ConnectionError |
| 44 | + > |
| 45 | +> { |
| 46 | + const input: operations.HealthControllerGenerateRandomNumberRequest = { |
| 47 | + idempotencyKey: idempotencyKey, |
| 48 | + }; |
| 49 | + |
| 50 | + const parsed = safeParse( |
| 51 | + input, |
| 52 | + (value) => |
| 53 | + operations.HealthControllerGenerateRandomNumberRequest$outboundSchema |
| 54 | + .parse(value), |
| 55 | + "Input validation failed", |
| 56 | + ); |
| 57 | + if (!parsed.ok) { |
| 58 | + return parsed; |
| 59 | + } |
| 60 | + const payload = parsed.value; |
| 61 | + const body = null; |
| 62 | + |
| 63 | + const path = pathToFunc("/v1/health-check/test-idempotency")(); |
| 64 | + |
| 65 | + const headers = new Headers(compactMap({ |
| 66 | + Accept: "application/json", |
| 67 | + "idempotency-key": encodeSimple( |
| 68 | + "idempotency-key", |
| 69 | + payload["idempotency-key"], |
| 70 | + { explode: false, charEncoding: "none" }, |
| 71 | + ), |
| 72 | + })); |
| 73 | + |
| 74 | + const secConfig = await extractSecurity(client._options.apiKey); |
| 75 | + const securityInput = secConfig == null ? {} : { apiKey: secConfig }; |
| 76 | + const requestSecurity = resolveGlobalSecurity(securityInput); |
| 77 | + |
| 78 | + const context = { |
| 79 | + operationID: "HealthController_generateRandomNumber", |
| 80 | + oAuth2Scopes: [], |
| 81 | + |
| 82 | + resolvedSecurity: requestSecurity, |
| 83 | + |
| 84 | + securitySource: client._options.apiKey, |
| 85 | + retryConfig: options?.retries |
| 86 | + || client._options.retryConfig |
| 87 | + || { |
| 88 | + strategy: "backoff", |
| 89 | + backoff: { |
| 90 | + initialInterval: 1000, |
| 91 | + maxInterval: 30000, |
| 92 | + exponent: 1.5, |
| 93 | + maxElapsedTime: 3600000, |
| 94 | + }, |
| 95 | + retryConnectionErrors: true, |
| 96 | + } |
| 97 | + || { strategy: "none" }, |
| 98 | + retryCodes: options?.retryCodes || ["408", "409", "429", "5XX"], |
| 99 | + }; |
| 100 | + |
| 101 | + const requestRes = client._createRequest(context, { |
| 102 | + security: requestSecurity, |
| 103 | + method: "GET", |
| 104 | + baseURL: options?.serverURL, |
| 105 | + path: path, |
| 106 | + headers: headers, |
| 107 | + body: body, |
| 108 | + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, |
| 109 | + }, options); |
| 110 | + if (!requestRes.ok) { |
| 111 | + return requestRes; |
| 112 | + } |
| 113 | + const req = requestRes.value; |
| 114 | + |
| 115 | + const doResult = await client._do(req, { |
| 116 | + context, |
| 117 | + errorCodes: [ |
| 118 | + "400", |
| 119 | + "401", |
| 120 | + "403", |
| 121 | + "404", |
| 122 | + "405", |
| 123 | + "409", |
| 124 | + "413", |
| 125 | + "414", |
| 126 | + "415", |
| 127 | + "422", |
| 128 | + "429", |
| 129 | + "4XX", |
| 130 | + "500", |
| 131 | + "503", |
| 132 | + "5XX", |
| 133 | + ], |
| 134 | + retryConfig: context.retryConfig, |
| 135 | + retryCodes: context.retryCodes, |
| 136 | + }); |
| 137 | + if (!doResult.ok) { |
| 138 | + return doResult; |
| 139 | + } |
| 140 | + const response = doResult.value; |
| 141 | + |
| 142 | + const responseFields = { |
| 143 | + HttpMeta: { Response: response, Request: req }, |
| 144 | + }; |
| 145 | + |
| 146 | + const [result] = await M.match< |
| 147 | + operations.HealthControllerGenerateRandomNumberResponse, |
| 148 | + | errors.ErrorDto |
| 149 | + | errors.ErrorDto |
| 150 | + | errors.ValidationErrorDto |
| 151 | + | errors.ErrorDto |
| 152 | + | SDKError |
| 153 | + | SDKValidationError |
| 154 | + | UnexpectedClientError |
| 155 | + | InvalidRequestError |
| 156 | + | RequestAbortedError |
| 157 | + | RequestTimeoutError |
| 158 | + | ConnectionError |
| 159 | + >( |
| 160 | + M.json( |
| 161 | + 201, |
| 162 | + operations.HealthControllerGenerateRandomNumberResponse$inboundSchema, |
| 163 | + { hdrs: true, key: "Result" }, |
| 164 | + ), |
| 165 | + M.jsonErr( |
| 166 | + [400, 401, 403, 404, 405, 409, 413, 415], |
| 167 | + errors.ErrorDto$inboundSchema, |
| 168 | + { hdrs: true }, |
| 169 | + ), |
| 170 | + M.jsonErr(414, errors.ErrorDto$inboundSchema), |
| 171 | + M.jsonErr(422, errors.ValidationErrorDto$inboundSchema, { hdrs: true }), |
| 172 | + M.fail(429), |
| 173 | + M.jsonErr(500, errors.ErrorDto$inboundSchema, { hdrs: true }), |
| 174 | + M.fail(503), |
| 175 | + M.fail("4XX"), |
| 176 | + M.fail("5XX"), |
| 177 | + )(response, { extraFields: responseFields }); |
| 178 | + if (!result.ok) { |
| 179 | + return result; |
| 180 | + } |
| 181 | + |
| 182 | + return result; |
| 183 | +} |
0 commit comments