import {z} from 'zod' export type DocumentType = 'IDENTITY_CARD' | 'PASSPORT' | 'RESIDENCE_PERMIT'; export type VerificationDocumentDetailsV1IdentityDocument = {bsnDocument?: string | undefined, base64DocumentBack: string, base64DocumentFront: string, documentType: DocumentType, documentNumber: string, documentExpiryDate: string, documentNationality: string}; export type VerificationDocumentDetailsV1 = {firstNameFormal: string, initials: string, dateOfBirth: string, placeOfBirth: string, gender: 'Male' | 'Female', nationality: string, identityDocument: VerificationDocumentDetailsV1IdentityDocument, identificationBy: string, idCheckDate: string, BSN: string}; export type PaymentDetailsV1 = {IBAN: string}; export type AddressDetailsV1 = {street: string, houseNumber: string, houseNumberAddition?: string | undefined, zipCode: string, city: string, country: string}; export type WorkerDetailsV1 = {firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, emailAddress?: string | undefined, mobileNumber?: string | undefined, verificationDocumentDetails?: VerificationDocumentDetailsV1 | undefined, paymentDetails?: PaymentDetailsV1 | undefined, address?: AddressDetailsV1 | undefined}; export type WorkerCreationRequestV1 = {workerDetails?: WorkerDetailsV1 | undefined}; export type CreateApiPublicOnboardingV1CreateWorkerArgs = {body: WorkerCreationRequestV1}; export type CreateApiPublicOnboardingV1CreateWorkerOptions = {baseUrl?: string | undefined, oauth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const workerCreationResponseV1 = z.object({workerId: 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 worker * * POST /public/onboarding/v1/create-worker */ export const createApiPublicOnboardingV1CreateWorker = async (args: CreateApiPublicOnboardingV1CreateWorkerArgs, options?: CreateApiPublicOnboardingV1CreateWorkerOptions) => { const {baseUrl = "https://api.maqqie.app", fetch: fetchFn = fetch, oauth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${oauth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/public/onboarding/v1/create-worker${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(workerCreationResponseV1, await res.json()) };