import {z} from 'zod' export type CreateApiV1InvitesWarmedArgs = {body: {light?: boolean | undefined, users: Array<{sumsub_sharetoken?: string | undefined, role?: string | undefined, details: {email: string, firstname?: string | undefined, lastname?: string | undefined, middlename?: string | undefined, dob?: string | undefined, tin?: string | undefined, external_reference_id?: string | undefined, sumsub_id?: string | undefined, registrationType?: string | undefined}, address?: ({country?: string | undefined, city?: string | undefined, state?: string | undefined, address_line1?: string | undefined, address_line2?: string | undefined, zip?: string | undefined, timezone?: string | undefined}) | undefined, companyData?: ({name?: string | undefined, phone?: string | undefined, tax_id?: string | undefined}) | undefined}>, company_riseid?: string | undefined, company_id?: (string | number) | undefined, role?: string | undefined}}; export type CreateApiV1InvitesWarmedOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV1InvitesWarmedResponse = z.object({data: z.object({failed: z.array(z.object({invite: z.string(), error: z.string()})), countAdded: z.number(), invited: z.array(z.string())})}); 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 }; /** * Send warmed invites (V1 Legacy) * * POST /v1/invites/warmed */ export const createApiV1InvitesWarmed = async (args: CreateApiV1InvitesWarmedArgs, options?: CreateApiV1InvitesWarmedOptions) => { const {baseUrl = "https://b2b-api.dev-riseworks.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v1/invites/warmed${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(createApiV1InvitesWarmedResponse, await res.json()) };