import {z} from 'zod' export type RefCountry = string; export type RefStateProvince = string; export type Address = {postalCode: string, city: string, country: RefCountry, addressLineOne: string, addressLineTwo?: string | undefined, stateProvince?: RefStateProvince | undefined}; export type RefOrganizationRelationship = string; export type UserRole = 'ACCOUNT_ADMIN' | 'ACCOUNT_MANAGER' | 'EXCHANGE_READ' | 'EXCHANGE_WRITE' | 'PORTFOLIO_READ' | 'PORTFOLIO_WRITE'; export type RefAccountStatus = string; export type RefProgram = string; export type RefRegistryLinkStatus = string; export type AccountRegistryLink = {id: number, program: RefProgram, registryAccountId: string, status: RefRegistryLinkStatus, lastSyncDate?: (string | null) | undefined}; export type RefOrganizationLegalStructure = string; export type RefOrganizationType = string; export type Organization = {iamOrgId?: string | undefined, legalName: string, structure: RefOrganizationLegalStructure, type: RefOrganizationType}; export type AcxAccountServiceAttributes = {acxAccountIdentifier: string}; export type SubaccountAccountServiceAttributes = {custodianEmaAccountIdentifier: string, autoDeposit: boolean, retirementSubaccountCodes?: {[key: string]: Array} | undefined, linkedRegistryAccountIds?: {[key: string]: string} | undefined}; export type RefCustodianProgram = string; export type CustodianAccountServiceAttributes = {custodianProgramCode: RefCustodianProgram, manualReplicaMode: boolean, ledgerCode?: string | undefined, ledgerIdentifier?: string | undefined, accountHoldingsIdentifier?: string | undefined, accountHoldingsName?: string | undefined, replicaTargetSubaccountIdentifier?: string | undefined, externalTransferAutoApproval: boolean, retirementOperationsNotificationEmails?: Array | undefined}; export type AccountServiceAttributes = AcxAccountServiceAttributes | SubaccountAccountServiceAttributes | CustodianAccountServiceAttributes; export type AccountService = {id: number, status: string, type: string, attributes?: AccountServiceAttributes | undefined}; export type Account = {id: number, identifier: string, noOfUsers: number, status: RefAccountStatus, maxUsers: number, childAccounts: Array, registryLinks: Array, organization: Organization, services: Array}; export type RefUserStatus = string; export type User = {firstName: string, middleName?: string | undefined, lastName: string, email: string, jobTitle: string, telephone?: string | undefined, authSubject?: string | undefined, login?: string | undefined, address: Address, organizationRelationship?: RefOrganizationRelationship | undefined, roles?: Array | undefined, account?: Account | undefined, status?: RefUserStatus | undefined, lastLogin?: string | undefined, isAdmin?: boolean | undefined}; export type BulkCreateAccountUsersRequest = {users: Array}; export type CreateApiAccountsAccountIdentifierUsersActionBulkCreateArgs = {AccountIdentifier: string, body: BulkCreateAccountUsersRequest}; export type CreateApiAccountsAccountIdentifierUsersActionBulkCreateOptions = {baseUrl?: string | undefined, bearerToken?: string | undefined, fetch?: typeof fetch | undefined}; export const refCountry = z.string(); export const refStateProvince = z.string(); export const address = z.object({postalCode: z.string().min(1), city: z.string().min(1), country: refCountry, addressLineOne: z.string().min(1), addressLineTwo: z.string().optional(), stateProvince: refStateProvince.optional()}); export const refOrganizationRelationship = z.string(); export const userRole = z.enum(["ACCOUNT_ADMIN", "ACCOUNT_MANAGER", "EXCHANGE_READ", "EXCHANGE_WRITE", "PORTFOLIO_READ", "PORTFOLIO_WRITE"]); export const refAccountStatus = z.string(); export const refProgram = z.string(); export const refRegistryLinkStatus = z.string(); export const accountRegistryLink = z.object({id: z.number().int(), program: refProgram, registryAccountId: z.string(), status: refRegistryLinkStatus, lastSyncDate: z.string().nullable().optional()}); export const refOrganizationLegalStructure = z.string(); export const refOrganizationType = z.string(); export const organization = z.object({iamOrgId: z.string().optional(), legalName: z.string(), structure: refOrganizationLegalStructure, type: refOrganizationType}); export const acxAccountServiceAttributes = z.object({acxAccountIdentifier: z.string()}); export const subaccountAccountServiceAttributes = z.object({custodianEmaAccountIdentifier: z.string(), autoDeposit: z.boolean(), retirementSubaccountCodes: z.record(z.string(), z.array(z.string())).optional(), linkedRegistryAccountIds: z.record(z.string(), z.string()).optional()}); export const refCustodianProgram = z.string(); export const custodianAccountServiceAttributes = z.object({custodianProgramCode: refCustodianProgram, manualReplicaMode: z.boolean(), ledgerCode: z.string().optional(), ledgerIdentifier: z.string().optional(), accountHoldingsIdentifier: z.string().optional(), accountHoldingsName: z.string().optional(), replicaTargetSubaccountIdentifier: z.string().optional(), externalTransferAutoApproval: z.boolean(), retirementOperationsNotificationEmails: z.array(z.string()).optional()}); export const accountServiceAttributes = z.union([acxAccountServiceAttributes, subaccountAccountServiceAttributes, custodianAccountServiceAttributes]); export const accountService = z.object({id: z.number().int(), status: z.string(), type: z.string(), attributes: accountServiceAttributes.optional()}); export const account: z.ZodType = z.object({id: z.number().int(), identifier: z.string(), noOfUsers: z.number().int(), status: refAccountStatus, maxUsers: z.number(), childAccounts: z.array(z.lazy(() => account)), registryLinks: z.array(accountRegistryLink), organization: organization, services: z.array(accountService)}); export const refUserStatus = z.string(); export const user = z.object({firstName: z.string().min(1).max(100), middleName: z.string().max(100).optional(), lastName: z.string().min(1).max(100), email: z.string(), jobTitle: z.string(), telephone: z.string().optional(), authSubject: z.string().optional(), login: z.string().optional(), address: address, organizationRelationship: refOrganizationRelationship.optional(), roles: z.array(userRole).optional(), account: account.optional(), status: refUserStatus.optional(), lastLogin: z.string().optional(), isAdmin: z.boolean().optional()}); export const bulkCreateAccountUsersResult = z.object({index: z.number().int(), code: z.enum(["CREATED", "FAILED"]), message: z.string().optional(), user: user.optional()}); export const bulkCreateAccountUsersResponse = z.object({code: z.enum(["SUCCESS", "PARTIAL_SUCCESS", "FAILURE"]), message: z.string().optional(), results: z.array(bulkCreateAccountUsersResult)}); 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 multiple users under the specified account * * POST /accounts/{AccountIdentifier}/users/action/bulk-create */ export const createApiAccountsAccountIdentifierUsersActionBulkCreate = async (args: CreateApiAccountsAccountIdentifierUsersActionBulkCreateArgs, options?: CreateApiAccountsAccountIdentifierUsersActionBulkCreateOptions) => { const {baseUrl = "https://sandbox.preprod.connect.xpansiv.com/app/api/v1", fetch: fetchFn = fetch, bearerToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerToken !== undefined) headers.set('authorization', `Bearer ${bearerToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.AccountIdentifier))}/users/action/bulk-create${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(bulkCreateAccountUsersResponse, await res.json()) };