import {z} from 'zod' export type IProductAccess = {can3pl?: boolean | undefined, canOrderManager?: boolean | undefined, canWarehouseManagerClassicAdmin?: boolean | undefined, canWarehouseManagerUnlimitedAdmin?: boolean | undefined, canWarehouseManagerCustomerPortal?: boolean | undefined, canWarehouseManagerIntegrations?: boolean | undefined, canWarehouseManagerMobile?: boolean | undefined, canWarehouseManagerAccountManager?: boolean | undefined, canIntegrationManager?: boolean | undefined, canBilling?: boolean | undefined, canNetworkManager?: boolean | undefined, canSignUp?: boolean | undefined, canManagementConsole?: boolean | undefined, canAdmin?: boolean | undefined, canFM?: boolean | undefined, canSmartScan?: boolean | undefined, canAccountingIntegration?: boolean | undefined, canBusinessAnalytics?: boolean | undefined, canAI?: boolean | undefined}; export type BulkUpdateUsersWhere = {orgKey?: (string | null) | undefined, extensivId?: (string | null) | undefined, isC2?: (boolean | null) | undefined, roleIds?: (Array) | undefined, productAccess?: IProductAccess | undefined}; export type BulkUpdateUsersUpdate = {roleId?: string | undefined, productAccess?: IProductAccess | undefined, externalRoleIds?: ({can3pl?: Array | undefined, canOrderManager?: Array | undefined, canWarehouseManagerClassicAdmin?: Array | undefined, canWarehouseManagerUnlimitedAdmin?: Array | undefined, canWarehouseManagerCustomerPortal?: Array | undefined, canWarehouseManagerIntegrations?: Array | undefined, canWarehouseManagerMobile?: Array | undefined, canWarehouseManagerAccountManager?: Array | undefined, canIntegrationManager?: Array | undefined, canBilling?: Array | undefined, canNetworkManager?: Array | undefined, canSignUp?: Array | undefined, canManagementConsole?: Array | undefined, canAdmin?: Array | undefined, canFM?: Array | undefined, canSmartScan?: Array | undefined, canAccountingIntegration?: Array | undefined, canBusinessAnalytics?: Array | undefined, canAI?: Array | undefined} | null) | undefined}; export type BulkUpdateUsersRequest = {where: BulkUpdateUsersWhere, update: BulkUpdateUsersUpdate, dryRun?: boolean | undefined}; export type CreateApiUsersUpdateWhereArgs = {body: BulkUpdateUsersRequest}; export type CreateApiUsersUpdateWhereOptions = {baseUrl?: string | undefined, cognitoJwtAuthorizer?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiUsersUpdateWhereResponse = z.object({data: z.array(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 }; /** * bulkUpdateUsers * * POST /users/update-where */ export const createApiUsersUpdateWhere = async (args: CreateApiUsersUpdateWhereArgs, options?: CreateApiUsersUpdateWhereOptions) => { const {baseUrl = "https://api-hub.extensiv.com", fetch: fetchFn = fetch, cognitoJwtAuthorizer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (cognitoJwtAuthorizer !== undefined) headers.set('authorization', `Bearer ${cognitoJwtAuthorizer}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/update-where${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(createApiUsersUpdateWhereResponse, await res.json()) };