|
| 1 | +/* |
| 2 | + * Get admin. |
| 3 | + */ |
| 4 | + |
| 5 | +import { ClientSDK, RequestOptions } from "../../lib/sdks.js"; |
| 6 | +import { |
| 7 | + encodeSimple, |
| 8 | +} from "../../lib/encodings.js"; |
| 9 | +import * as M from "../../lib/matchers.js"; |
| 10 | +import { safeParse } from "../../lib/schemas.js"; |
| 11 | +import { extractSecurity, resolveGlobalSecurity } from "../../lib/security.js"; |
| 12 | +import * as errors from "../../models/errors/index.js"; |
| 13 | +import { ResponseValidationError } from "../../models/errors/response-validation-error.js"; |
| 14 | +import { SDKValidationError } from "../../models/errors/sdk-validation-error.js"; |
| 15 | +import { |
| 16 | + ConnectionError, |
| 17 | + InvalidRequestError, |
| 18 | + RequestAbortedError, |
| 19 | + RequestTimeoutError, |
| 20 | + UnexpectedClientError, |
| 21 | +} from "../../models/errors/http-client-errors.js"; |
| 22 | +import * as operations from "../../models/operations/index.js"; |
| 23 | +import { GetAdminResponse$inboundSchema } from "../../models/operations/admins.js"; |
| 24 | +import { APICall, APIPromise } from "../../types/async.js"; |
| 25 | +import { OK, Result } from "../../types/fp.js"; |
| 26 | + |
| 27 | +export function adminsGet( |
| 28 | + client: ClientSDK, |
| 29 | + request: operations.GetAdminRequest, |
| 30 | + options?: RequestOptions, |
| 31 | +): APIPromise< |
| 32 | + Result< |
| 33 | + operations.GetAdminResponse, |
| 34 | + | errors.ErrorResponse |
| 35 | + | errors.OminityDefaultError |
| 36 | + | ResponseValidationError |
| 37 | + | ConnectionError |
| 38 | + | RequestAbortedError |
| 39 | + | RequestTimeoutError |
| 40 | + | InvalidRequestError |
| 41 | + | UnexpectedClientError |
| 42 | + | SDKValidationError |
| 43 | + > |
| 44 | +> { |
| 45 | + return new APIPromise($do( |
| 46 | + client, |
| 47 | + request, |
| 48 | + options, |
| 49 | + )); |
| 50 | +} |
| 51 | + |
| 52 | +async function $do( |
| 53 | + client: ClientSDK, |
| 54 | + request: operations.GetAdminRequest, |
| 55 | + options?: RequestOptions, |
| 56 | +): Promise< |
| 57 | + [ |
| 58 | + Result< |
| 59 | + operations.GetAdminResponse, |
| 60 | + | errors.ErrorResponse |
| 61 | + | errors.OminityDefaultError |
| 62 | + | ResponseValidationError |
| 63 | + | ConnectionError |
| 64 | + | RequestAbortedError |
| 65 | + | RequestTimeoutError |
| 66 | + | InvalidRequestError |
| 67 | + | UnexpectedClientError |
| 68 | + | SDKValidationError |
| 69 | + >, |
| 70 | + APICall, |
| 71 | + ] |
| 72 | +> { |
| 73 | + const parsed = safeParse( |
| 74 | + request, |
| 75 | + (value) => |
| 76 | + operations.GetAdminRequest$outboundSchema.parse(value), |
| 77 | + "Input validation failed", |
| 78 | + ); |
| 79 | + if (!parsed.ok) { |
| 80 | + return [parsed, { status: "invalid" }]; |
| 81 | + } |
| 82 | + const payload = parsed.value; |
| 83 | + const body = null; |
| 84 | + |
| 85 | + const path = encodeSimple( |
| 86 | + "/admins/{id}", |
| 87 | + { "id": payload.id }, |
| 88 | + { explode: false, charEncoding: "percent" }, |
| 89 | + ) || ""; |
| 90 | + |
| 91 | + const headers = new Headers({ |
| 92 | + Accept: "application/hal+json", |
| 93 | + }); |
| 94 | + |
| 95 | + const securityInput = await extractSecurity(client._options.security); |
| 96 | + const requestSecurity = resolveGlobalSecurity(securityInput); |
| 97 | + |
| 98 | + const context = { |
| 99 | + options: client._options, |
| 100 | + baseURL: options?.serverURL ?? client._baseURL ?? "", |
| 101 | + operationID: "admins.get", |
| 102 | + oAuth2Scopes: null, |
| 103 | + resolvedSecurity: requestSecurity, |
| 104 | + securitySource: client._options.security, |
| 105 | + retryConfig: options?.retries |
| 106 | + || client._options.retryConfig |
| 107 | + || { |
| 108 | + strategy: "backoff", |
| 109 | + backoff: { |
| 110 | + initialInterval: 500, |
| 111 | + maxInterval: 5000, |
| 112 | + exponent: 2, |
| 113 | + maxElapsedTime: 7500, |
| 114 | + }, |
| 115 | + retryConnectionErrors: true, |
| 116 | + } |
| 117 | + || { strategy: "none" }, |
| 118 | + retryCodes: options?.retryCodes || ["5xx"], |
| 119 | + }; |
| 120 | + |
| 121 | + const requestRes = client._createRequest(context, { |
| 122 | + security: requestSecurity, |
| 123 | + method: "GET", |
| 124 | + baseURL: options?.serverURL, |
| 125 | + path, |
| 126 | + headers, |
| 127 | + body, |
| 128 | + userAgent: client._options.userAgent, |
| 129 | + timeoutMs: options?.timeoutMs || client._options.timeoutMs || -1, |
| 130 | + }, options); |
| 131 | + if (!requestRes.ok) { |
| 132 | + return [requestRes, { status: "invalid" }]; |
| 133 | + } |
| 134 | + const req = requestRes.value; |
| 135 | + |
| 136 | + const doResult = await client._do(req, { |
| 137 | + context, |
| 138 | + errorCodes: ["400", "4XX", "5XX"], |
| 139 | + retryConfig: context.retryConfig, |
| 140 | + retryCodes: context.retryCodes, |
| 141 | + }); |
| 142 | + if (!doResult.ok) { |
| 143 | + return [doResult, { status: "request-error", request: req }]; |
| 144 | + } |
| 145 | + const response = doResult.value; |
| 146 | + |
| 147 | + const responseFields = { |
| 148 | + HttpMeta: { Response: response, Request: req }, |
| 149 | + }; |
| 150 | + |
| 151 | + const [result] = await M.match< |
| 152 | + operations.GetAdminResponse, |
| 153 | + | errors.ErrorResponse |
| 154 | + | errors.OminityDefaultError |
| 155 | + | ResponseValidationError |
| 156 | + | ConnectionError |
| 157 | + | RequestAbortedError |
| 158 | + | RequestTimeoutError |
| 159 | + | InvalidRequestError |
| 160 | + | UnexpectedClientError |
| 161 | + | SDKValidationError |
| 162 | + >( |
| 163 | + M.json(200, GetAdminResponse$inboundSchema, { |
| 164 | + ctype: "application/hal+json", |
| 165 | + }), |
| 166 | + M.jsonErr("4XX", errors.ErrorResponse$inboundSchema, { |
| 167 | + ctype: "application/hal+json", |
| 168 | + }), |
| 169 | + M.fail("5XX"), |
| 170 | + )(response, req, { extraFields: responseFields }); |
| 171 | + if (!result.ok) { |
| 172 | + return [result, { status: "complete", request: req, response }]; |
| 173 | + } |
| 174 | + |
| 175 | + return [ |
| 176 | + OK(result.value), |
| 177 | + { status: "complete", request: req, response }, |
| 178 | + ]; |
| 179 | +} |
0 commit comments