import {z} from 'zod' export type GetTermsOfServiceDocumentRequest = {language: string, termsOfServiceDocumentFormat?: string | undefined, type: 'adyenAccount' | 'adyenCapital' | 'adyenCapitalCashAdvance' | 'adyenCard' | 'adyenChargeCard' | 'adyenForPlatformsAdvanced' | 'adyenForPlatformsManage' | 'adyenFranchisee' | 'adyenIssuing' | 'adyenPccr' | 'directDebit' | 'kycOnInvite'}; export type CreateApiLegalEntitiesIdTermsOfServiceArgs = {id: string, body: GetTermsOfServiceDocumentRequest}; export type CreateApiLegalEntitiesIdTermsOfServiceOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getTermsOfServiceDocumentResponse = z.object({document: z.string().optional(), id: z.string().optional(), language: z.string().optional(), termsOfServiceDocumentFormat: z.string().optional(), termsOfServiceDocumentId: z.string().optional(), type: z.enum(["adyenAccount", "adyenCapital", "adyenCapitalCashAdvance", "adyenCard", "adyenChargeCard", "adyenForPlatformsAdvanced", "adyenForPlatformsManage", "adyenFranchisee", "adyenIssuing", "adyenPccr", "directDebit", "kycOnInvite"]).optional()}); 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 }; /** * Get Terms of Service document * * POST /legalEntities/{id}/termsOfService * * Also accepts auth: ApiKeyAuth */ export const createApiLegalEntitiesIdTermsOfService = async (args: CreateApiLegalEntitiesIdTermsOfServiceArgs, options?: CreateApiLegalEntitiesIdTermsOfServiceOptions) => { const {baseUrl = "https://kyc-test.adyen.com/lem/v1", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/legalEntities/${encodeURIComponent(String(args.id))}/termsOfService${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(getTermsOfServiceDocumentResponse, await res.json()) };