import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type GetApiCustomerTrustAccountsArgs = {pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, searchString?: string | undefined, isAutoApprovalEnabled?: boolean | undefined, customFieldsFilter?: string | undefined}; export type GetApiCustomerTrustAccountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const customerTrustAccountNdaStatus = z.enum(["SIGNED", "NOT_REQUIRED", "INCOMPLETE"]); export const customerTrustAccountNDADetails = z.object({ndaStatus: customerTrustAccountNdaStatus, ndaSatisfiedDate: z.string().nullable()}); export const customerTrustAccountGrantAccessOption = z.enum(["INCLUDE_EVERYTHING_REQUESTED", "INCLUDE_ONLY_CONFIGURED"]); export const customerTrustAccountAccessConfig = z.object({autoApprovalEnabled: z.boolean(), grantAccessOption: customerTrustAccountGrantAccessOption.nullable()}); export const customField = z.object({label: z.string(), value: z.union([z.string(), z.array(z.string())])}); export const tagsByCategoryOutput = z.object({categoryId: z.string(), tagIds: z.array(z.string())}); export const customerTrustAccountVantaApi = z.object({id: z.string(), name: z.string(), emailDomain: z.string(), createdDate: z.string(), updatedDate: z.string(), ndaDetails: customerTrustAccountNDADetails, accessConfig: customerTrustAccountAccessConfig.nullable(), customFields: z.array(customField), tagsByCategory: z.array(tagsByCategoryOutput)}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedResponseCustomerTrustAccountVantaApi = z.object({results: z.object({data: z.array(customerTrustAccountVantaApi), pageInfo: pageInfo})}); 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 }; /** * List customer trust accounts * * GET /customer-trust/accounts */ export const getApiCustomerTrustAccounts = async (args: GetApiCustomerTrustAccountsArgs, options?: GetApiCustomerTrustAccountsOptions) => { const {baseUrl = "https://api.vanta.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageCursor != null) query.append("pageCursor", String(args.pageCursor)) if (args.searchString != null) query.append("searchString", String(args.searchString)) if (args.isAutoApprovalEnabled != null) query.append("isAutoApprovalEnabled", String(args.isAutoApprovalEnabled)) if (args.customFieldsFilter != null) query.append("customFieldsFilter", String(args.customFieldsFilter)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/customer-trust/accounts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedResponseCustomerTrustAccountVantaApi, await res.json()) };