/* * 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 { ClosedEnum } from "../../types/enums.js"; import { Result as SafeParseResult } from "../../types/fp.js"; import { Authentication, Authentication$inboundSchema, } from "../components/authentication.js"; import { HTTPMetadata, HTTPMetadata$inboundSchema, } from "../components/httpmetadata.js"; import { SDKValidationError } from "../errors/sdkvalidationerror.js"; /** * Determines the date-based API version associated with your API call. If none is provided, your application's [minimum API version](https://docs.gusto.com/embedded-payroll/docs/api-versioning#minimum-api-version) is used. */ export const HeaderXGustoAPIVersion = { TwoThousandAndTwentyFiveMinus06Minus15: "2025-06-15", } as const; /** * Determines the date-based API version associated with your API call. If none is provided, your application's [minimum API version](https://docs.gusto.com/embedded-payroll/docs/api-versioning#minimum-api-version) is used. */ export type HeaderXGustoAPIVersion = ClosedEnum; export type SystemAccessTokenRequest = { /** * Your client ID */ clientId: string; /** * Your client secret */ clientSecret: string; /** * Set system_access to create a system access token, refresh_token to refresh an existing token */ grantType: "system_access"; }; export type RefreshTokenRequest = { /** * Your client ID */ clientId: string; /** * Your client secret */ clientSecret: string; /** * Set system_access to create a system access token, refresh_token to refresh an existing token */ grantType: "refresh_token"; refreshToken: string; /** * The redirect URI you set up via the Developer Portal */ redirectUri?: string | undefined; }; export type OauthAccessTokenRequestBody = | RefreshTokenRequest | SystemAccessTokenRequest; export type OauthAccessTokenRequest = { /** * Determines the date-based API version associated with your API call. If none is provided, your application's [minimum API version](https://docs.gusto.com/embedded-payroll/docs/api-versioning#minimum-api-version) is used. */ xGustoAPIVersion?: HeaderXGustoAPIVersion | undefined; requestBody: RefreshTokenRequest | SystemAccessTokenRequest; }; export type OauthAccessTokenResponse = { httpMeta: HTTPMetadata; /** * Success */ authentication?: Authentication | undefined; }; /** @internal */ export const HeaderXGustoAPIVersion$outboundSchema: z.ZodNativeEnum< typeof HeaderXGustoAPIVersion > = z.nativeEnum(HeaderXGustoAPIVersion); /** @internal */ export type SystemAccessTokenRequest$Outbound = { client_id: string; client_secret: string; grant_type: "system_access"; }; /** @internal */ export const SystemAccessTokenRequest$outboundSchema: z.ZodType< SystemAccessTokenRequest$Outbound, z.ZodTypeDef, SystemAccessTokenRequest > = z.object({ clientId: z.string(), clientSecret: z.string(), grantType: z.literal("system_access"), }).transform((v) => { return remap$(v, { clientId: "client_id", clientSecret: "client_secret", grantType: "grant_type", }); }); export function systemAccessTokenRequestToJSON( systemAccessTokenRequest: SystemAccessTokenRequest, ): string { return JSON.stringify( SystemAccessTokenRequest$outboundSchema.parse(systemAccessTokenRequest), ); } /** @internal */ export type RefreshTokenRequest$Outbound = { client_id: string; client_secret: string; grant_type: "refresh_token"; refresh_token: string; redirect_uri?: string | undefined; }; /** @internal */ export const RefreshTokenRequest$outboundSchema: z.ZodType< RefreshTokenRequest$Outbound, z.ZodTypeDef, RefreshTokenRequest > = z.object({ clientId: z.string(), clientSecret: z.string(), grantType: z.literal("refresh_token"), refreshToken: z.string(), redirectUri: z.string().optional(), }).transform((v) => { return remap$(v, { clientId: "client_id", clientSecret: "client_secret", grantType: "grant_type", refreshToken: "refresh_token", redirectUri: "redirect_uri", }); }); export function refreshTokenRequestToJSON( refreshTokenRequest: RefreshTokenRequest, ): string { return JSON.stringify( RefreshTokenRequest$outboundSchema.parse(refreshTokenRequest), ); } /** @internal */ export type OauthAccessTokenRequestBody$Outbound = | RefreshTokenRequest$Outbound | SystemAccessTokenRequest$Outbound; /** @internal */ export const OauthAccessTokenRequestBody$outboundSchema: z.ZodType< OauthAccessTokenRequestBody$Outbound, z.ZodTypeDef, OauthAccessTokenRequestBody > = z.union([ z.lazy(() => RefreshTokenRequest$outboundSchema), z.lazy(() => SystemAccessTokenRequest$outboundSchema), ]); export function oauthAccessTokenRequestBodyToJSON( oauthAccessTokenRequestBody: OauthAccessTokenRequestBody, ): string { return JSON.stringify( OauthAccessTokenRequestBody$outboundSchema.parse( oauthAccessTokenRequestBody, ), ); } /** @internal */ export type OauthAccessTokenRequest$Outbound = { "X-Gusto-API-Version": string; RequestBody: RefreshTokenRequest$Outbound | SystemAccessTokenRequest$Outbound; }; /** @internal */ export const OauthAccessTokenRequest$outboundSchema: z.ZodType< OauthAccessTokenRequest$Outbound, z.ZodTypeDef, OauthAccessTokenRequest > = z.object({ xGustoAPIVersion: HeaderXGustoAPIVersion$outboundSchema.default("2025-06-15"), requestBody: z.union([ z.lazy(() => RefreshTokenRequest$outboundSchema), z.lazy(() => SystemAccessTokenRequest$outboundSchema), ]), }).transform((v) => { return remap$(v, { xGustoAPIVersion: "X-Gusto-API-Version", requestBody: "RequestBody", }); }); export function oauthAccessTokenRequestToJSON( oauthAccessTokenRequest: OauthAccessTokenRequest, ): string { return JSON.stringify( OauthAccessTokenRequest$outboundSchema.parse(oauthAccessTokenRequest), ); } /** @internal */ export const OauthAccessTokenResponse$inboundSchema: z.ZodType< OauthAccessTokenResponse, z.ZodTypeDef, unknown > = z.object({ HttpMeta: HTTPMetadata$inboundSchema, Authentication: Authentication$inboundSchema.optional(), }).transform((v) => { return remap$(v, { "HttpMeta": "httpMeta", "Authentication": "authentication", }); }); export function oauthAccessTokenResponseFromJSON( jsonString: string, ): SafeParseResult { return safeParse( jsonString, (x) => OauthAccessTokenResponse$inboundSchema.parse(JSON.parse(x)), `Failed to parse 'OauthAccessTokenResponse' from JSON`, ); }