import {z} from 'zod' export type DID = unknown; export type CreateApiEntitiesEntityDIDFlowCustomersArgs = {entityDID: DID, body: {customerDid: string, customerType: 'natural_person' | 'legal_person', profileData: {naturalPerson: {name: {nameIdentifier?: (Array<{primaryIdentifier: string, secondaryIdentifier?: string | undefined, naturalPersonNameIdentifierType: string}>) | undefined}, geographicAddress?: Array> | undefined, nationalIdentification?: Record | undefined, dateAndPlaceOfBirth?: Record | undefined, countryOfResidence?: string | undefined}} | {legalPerson: {name: {nameIdentifier?: Array<{legalPersonName: string, legalPersonNameIdentifierType: string}> | undefined}, nationalIdentification: {nationalIdentifier: string, nationalIdentifierType: string, countryOfIssue?: string | undefined, registrationAuthority?: string | undefined}, geographicAddress?: Array> | undefined}}, verificationStatus?: ('pending' | 'verified' | 'rejected' | 'expired') | undefined, verificationLevel?: ('basic' | 'enhanced' | 'premium') | undefined}}; export type CreateApiEntitiesEntityDIDFlowCustomersOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiEntitiesEntityDIDFlowCustomersResponse = z.object({customerDid: z.string().optional(), entityDid: z.string().optional(), customerType: z.enum(["natural_person", "legal_person"]).optional(), profileData: z.object({}).optional(), verificationStatus: z.enum(["pending", "verified", "rejected", "expired"]).optional(), verificationLevel: z.enum(["basic", "enhanced", "premium"]).optional(), verifiedAt: z.string().optional(), verificationExpiresAt: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().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 }; /** * Create a new customer for Flow workflows * * POST /entities/{entityDID}/flow/customers */ export const createApiEntitiesEntityDIDFlowCustomers = async (args: CreateApiEntitiesEntityDIDFlowCustomersArgs, options?: CreateApiEntitiesEntityDIDFlowCustomersOptions) => { const {baseUrl = "https://api.eu1.notabene.id", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/entities/${encodeURIComponent(String(args.entityDID))}/flow/customers${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(createApiEntitiesEntityDIDFlowCustomersResponse, await res.json()) };