import {z} from 'zod' export type PageSize = number; export type PageCursor = string; export type GetApiTrustCentersSlugIdViewersArgs = {slugId: string, pageSize?: PageSize | undefined, pageCursor?: PageCursor | undefined, includeRemoved?: boolean | undefined}; export type GetApiTrustCentersSlugIdViewersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const viewerAccessLevel = z.enum(["FULL_ACCESS", "PARTIAL_ACCESS"]); export const viewerNdaProvider = z.enum(["DOCUSIGN", "ONE_CLICK", "SFDC_BYPASS", "HUBSPOT_BYPASS", "IRONCLAD_BYPASS"]); export const externalService = z.enum(["SALESFORCE", "HUBSPOT", "IRONCLAD"]); export const customerTrustUser = z.object({id: z.string(), organizationId: z.string(), email: z.string(), givenName: z.string().nullable(), familyName: z.string().nullable()}); export const trustCenterViewer = z.object({id: z.string(), email: z.string(), name: z.string().nullable(), companyName: z.string().nullable(), resourceIds: z.array(z.string()).nullable(), accessLevel: viewerAccessLevel, ndaInfo: z.object({docuSign: z.object({envelopeId: z.string(), accountId: z.string(), accountBaseUrl: z.string()}).nullable(), oneClick: z.object({ndaUploadedDocumentId: z.string().nullable(), name: z.string(), date: z.string()}).nullable(), provider: viewerNdaProvider, satisfiedDate: z.string().nullable()}).nullable(), externalServiceAssociations: z.array(z.object({objectType: z.string(), id: z.string(), service: externalService})).nullable(), creationDate: z.string(), updatedDate: z.string(), expirationDate: z.string().nullable(), addedByUser: customerTrustUser.nullable(), customerTrustAccountId: z.string().nullable()}); export const pageInfo = z.object({endCursor: z.string().nullable(), hasNextPage: z.boolean(), hasPreviousPage: z.boolean(), startCursor: z.string().nullable()}); export const paginatedResponseTrustCenterViewer = z.object({results: z.object({data: z.array(trustCenterViewer), 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 Trust Center viewers * * GET /trust-centers/{slugId}/viewers */ export const getApiTrustCentersSlugIdViewers = async (args: GetApiTrustCentersSlugIdViewersArgs, options?: GetApiTrustCentersSlugIdViewersOptions) => { 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.includeRemoved != null) query.append("includeRemoved", String(args.includeRemoved)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/trust-centers/${encodeURIComponent(String(args.slugId))}/viewers${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(paginatedResponseTrustCenterViewer, await res.json()) };