import {z} from 'zod' export type Authv2RoleTypes = 'ROLE_TYPES_SUPPLIER_REPORT_VIEW' | 'ROLE_TYPES_SUPPLIER_FULL' | 'ROLE_TYPES_RETAILER_REPORT_VIEW' | 'ROLE_TYPES_RETAILER_FULL'; export type V2InviteEmailLanguageCode = 'EN_US' | 'CS_CZ' | 'FR_FR' | 'HU_HU' | 'IT_IT' | 'JA_JP' | 'KO_KR' | 'PT_BR' | 'SK_SK' | 'ES_ES'; export type V2InviteTeam = {managerTeamId?: string | undefined, roleIds: Array, teamId: string, emailToInvite: string, inviteUrl?: string | undefined, languageCode?: V2InviteEmailLanguageCode | undefined}; export type V2BulkInviteUsersRequest = {inviteUsers: Array}; export type CreateApiV2TeamsBulkInviteUserArgs = {body: V2BulkInviteUsersRequest}; export type CreateApiV2TeamsBulkInviteUserOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v1BulkOperationStatus = z.enum(["BULK_OPERATION_SUBMITTED", "BULK_OPERATION_IN_PROGRESS", "BULK_OPERATION_COMPLETED", "BULK_OPERATION_FAILED"]); export const v2BulkInviteUsersResponse = z.object({bulkId: z.string().optional(), status: v1BulkOperationStatus.optional(), message: 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 }; /** * Invite users to teams in bulk * * POST /v2/teams/bulk/invite-user */ export const createApiV2TeamsBulkInviteUser = async (args: CreateApiV2TeamsBulkInviteUserArgs, options?: CreateApiV2TeamsBulkInviteUserOptions) => { const {baseUrl = "https://auth..citrusad.com", 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(/\/+$/, '')}/v2/teams/bulk/invite-user${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(v2BulkInviteUsersResponse, await res.json()) };