/* * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. */ import * as z from "zod/v3"; import { remap as remap$ } from "../../lib/primitives.js"; import { collectExtraKeys as collectExtraKeys$, lazySchema as lazySchema$, safeParse, } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import * as types from "../../types/primitives.js"; import { smartUnion } from "../../types/smartUnion.js"; import { ApideckError } from "./apideckerror.js"; import { SDKValidationError } from "./sdkvalidationerror.js"; /** * HTTP request details */ export type RequestT = {}; /** * HTTP response details */ export type ResponseT = {}; /** * Debug information including request/response details and OAuth timing metadata */ export type Debug = { /** * HTTP request details */ request?: RequestT | undefined; /** * HTTP response details */ response?: ResponseT | undefined; /** * Error message from downstream provider or network layer */ message?: string | undefined; /** * Error code (e.g., ETIMEDOUT, ECONNREFUSED) */ code?: string | undefined; /** * Unix timestamp (milliseconds) when credentials will be deleted if not refreshed. Only present for non-recoverable errors (401, 400). Credentials are preserved indefinitely for recoverable/network errors. */ credentialsExpireAtMs?: number | undefined; /** * Unix timestamp (milliseconds) when token refresh retry is allowed after cooldown period expires. */ retryAfterMs?: number | undefined; /** * Milliseconds remaining in cooldown period before retry is allowed. */ cooldownRemainingMs?: number | undefined; }; export type Two = { /** * Error type identifier */ type?: string | undefined; /** * Detailed error message */ message?: string | undefined; /** * Debug information including request/response details and OAuth timing metadata */ debug?: Debug | undefined; additionalProperties?: { [k: string]: any } | undefined; }; /** * Contains parameter or domain specific information related to the error and why it occurred. */ export type UnauthorizedResponseDetail = string | Two; /** * Unauthorized */ export type UnauthorizedResponseData = { /** * HTTP status code */ statusCode?: number | undefined; /** * Contains an explanation of the status_code as defined in HTTP/1.1 standard (RFC 7231) */ error?: string | undefined; /** * The type of error returned */ typeName?: string | undefined; /** * A human-readable message providing more details about the error. */ message?: string | undefined; /** * Contains parameter or domain specific information related to the error and why it occurred. */ detail?: string | Two | undefined; /** * Link to documentation of error type */ ref?: string | undefined; }; /** * Unauthorized */ export class UnauthorizedResponse extends ApideckError { /** * HTTP status code */ statusCode?: number | undefined; /** * Contains an explanation of the status_code as defined in HTTP/1.1 standard (RFC 7231) */ error?: string | undefined; /** * The type of error returned */ typeName?: string | undefined; /** * Contains parameter or domain specific information related to the error and why it occurred. */ detail?: string | Two | undefined; /** * Link to documentation of error type */ ref?: string | undefined; /** The original data that was passed to this error instance. */ data$: UnauthorizedResponseData; constructor( err: UnauthorizedResponseData, httpMeta: { response: Response; request: Request; body: string }, ) { const message = err.message || `API error occurred: ${JSON.stringify(err)}`; super(message, httpMeta); this.data$ = err; if (err.statusCode != null) this.statusCode = err.statusCode; if (err.error != null) this.error = err.error; if (err.typeName != null) this.typeName = err.typeName; if (err.detail != null) this.detail = err.detail; if (err.ref != null) this.ref = err.ref; this.name = "UnauthorizedResponse"; } } /** @internal */ export const RequestT$inboundSchema: z.ZodType< RequestT, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({})); export function requestFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => RequestT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'RequestT' from JSON`, ); } /** @internal */ export const ResponseT$inboundSchema: z.ZodType< ResponseT, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({})); export function responseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => ResponseT$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'ResponseT' from JSON`, ); } /** @internal */ export const Debug$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => z.object({ request: types.optional(z.lazy(() => RequestT$inboundSchema)), response: types.optional(z.lazy(() => ResponseT$inboundSchema)), message: types.optional(types.string()), code: types.optional(types.string()), credentials_expire_at_ms: types.optional(types.number()), retry_after_ms: types.optional(types.number()), cooldown_remaining_ms: types.optional(types.number()), }).transform((v) => { return remap$(v, { "credentials_expire_at_ms": "credentialsExpireAtMs", "retry_after_ms": "retryAfterMs", "cooldown_remaining_ms": "cooldownRemainingMs", }); }) ); export function debugFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Debug$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Debug' from JSON`, ); } /** @internal */ export const Two$inboundSchema: z.ZodType = /* @__PURE__ */ lazySchema$(() => collectExtraKeys$( z.object({ type: types.optional(types.string()), message: types.optional(types.string()), debug: types.optional(z.lazy(() => Debug$inboundSchema)), }).catchall(z.any()), "additionalProperties", true, ) ); export function twoFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => Two$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'Two' from JSON`, ); } /** @internal */ export const UnauthorizedResponseDetail$inboundSchema: z.ZodType< UnauthorizedResponseDetail, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => smartUnion([types.string(), z.lazy(() => Two$inboundSchema)]) ); export function unauthorizedResponseDetailFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => UnauthorizedResponseDetail$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'UnauthorizedResponseDetail' from JSON`, ); } /** @internal */ export const UnauthorizedResponse$inboundSchema: z.ZodType< UnauthorizedResponse, z.ZodTypeDef, unknown > = /* @__PURE__ */ lazySchema$(() => z.object({ status_code: types.optional(types.number()), error: types.optional(types.string()), type_name: types.optional(types.string()), message: types.optional(types.string()), detail: types.optional( smartUnion([types.string(), z.lazy(() => Two$inboundSchema)]), ), ref: types.optional(types.string()), request$: z.instanceof(Request), response$: z.instanceof(Response), body$: z.string(), }) .transform((v) => { const remapped = remap$(v, { "status_code": "statusCode", "type_name": "typeName", }); return new UnauthorizedResponse(remapped, { request: v.request$, response: v.response$, body: v.body$, }); }) );