import {z} from 'zod' export type APIClientID = string; export type APISecret = string; export type UserToken = string; export type NewUserID = string; export type CreditEmploymentGetRequest = {client_id?: APIClientID | undefined, secret?: APISecret | undefined, user_token?: UserToken | undefined, user_id?: NewUserID | undefined}; export type CreateApiCreditEmploymentGetArgs = {body: CreditEmploymentGetRequest}; export type CreateApiCreditEmploymentGetOptions = {baseUrl?: string | undefined, clientId?: string | undefined, secret?: string | undefined, plaidVersion?: string | undefined, fetch?: typeof fetch | undefined}; export const itemId = z.string(); export const creditEmploymentVerificationStatus = z.string().nullable(); export const creditEmployerVerification = z.object({name: z.string().nullable()}).and(z.record(z.string(), z.unknown())); export const creditPlatformIds = z.object({employee_id: z.string().nullable(), payroll_id: z.string().nullable(), position_id: z.string().nullable()}).and(z.record(z.string(), z.unknown())); export const creditEmploymentEmployeeType = z.string().nullable(); export const creditEmploymentVerification = z.object({account_id: z.string().nullable(), status: creditEmploymentVerificationStatus, start_date: z.string().nullable(), end_date: z.string().nullable(), employer: creditEmployerVerification, title: z.string().nullable(), platform_ids: creditPlatformIds, employee_type: creditEmploymentEmployeeType, last_paystub_date: z.string().nullable()}).and(z.record(z.string(), z.unknown())); export const creditEmploymentItem = z.object({item_id: itemId, employments: z.array(creditEmploymentVerification), employment_report_token: z.string().optional()}).and(z.record(z.string(), z.unknown())); export const requestID = z.string(); export const creditEmploymentGetResponse = z.object({items: z.array(creditEmploymentItem), request_id: requestID}).and(z.record(z.string(), z.unknown())); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Retrieve a summary of an individual's employment information * * POST /credit/employment/get */ export const createApiCreditEmploymentGet = async (args: CreateApiCreditEmploymentGetArgs, options?: CreateApiCreditEmploymentGetOptions) => { const {baseUrl = "https://production.plaid.com", fetch: fetchFn = fetch, clientId, secret, plaidVersion} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (clientId !== undefined) headers.set("PLAID-CLIENT-ID", clientId) if (secret !== undefined) headers.set("PLAID-SECRET", secret) if (plaidVersion !== undefined) headers.set("Plaid-Version", plaidVersion) const url = `${baseUrl.replace(/\/+$/, '')}/credit/employment/get${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(creditEmploymentGetResponse, await res.json()) };