/* * 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 { safeParse } from "../../lib/schemas.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; import { TokenType, TokenType$inboundSchema, TokenType$outboundSchema, } from "./tokentype.js"; export type AuthToken = { /** * An [RFC 6750](https://www.rfc-editor.org/rfc/rfc6750#section-6.1) token type. */ tokenType: TokenType; /** * A value passed to the authorization server to gain access to the system. */ accessToken: string; /** * A value passed to the authorization server to obtain a new access token. */ refreshToken: string; /** * Unix timestamp indicating when this token expires. */ expiresIn: number; /** * A space-delimited list of [scopes](https://docs.moov.io/api/authentication/scopes/) that are allowed. */ scope: string; }; /** @internal */ export const AuthToken$inboundSchema: z.ZodType< AuthToken, z.ZodTypeDef, unknown > = z.object({ token_type: TokenType$inboundSchema, access_token: z.string(), refresh_token: z.string(), expires_in: z.number().int(), scope: z.string(), }).transform((v) => { return remap$(v, { "token_type": "tokenType", "access_token": "accessToken", "refresh_token": "refreshToken", "expires_in": "expiresIn", }); }); /** @internal */ export type AuthToken$Outbound = { token_type: string; access_token: string; refresh_token: string; expires_in: number; scope: string; }; /** @internal */ export const AuthToken$outboundSchema: z.ZodType< AuthToken$Outbound, z.ZodTypeDef, AuthToken > = z.object({ tokenType: TokenType$outboundSchema, accessToken: z.string(), refreshToken: z.string(), expiresIn: z.number().int(), scope: z.string(), }).transform((v) => { return remap$(v, { tokenType: "token_type", accessToken: "access_token", refreshToken: "refresh_token", expiresIn: "expires_in", }); }); export function authTokenToJSON(authToken: AuthToken): string { return JSON.stringify(AuthToken$outboundSchema.parse(authToken)); } export function authTokenFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => AuthToken$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'AuthToken' from JSON`, ); }