import {z} from 'zod' export type GetApiV2PartitionPartitionIdManagementuserSearchArgs = {descending?: boolean | undefined, firstResultIndex?: number | undefined, maxResult?: number | undefined, partitionId: string, searchString: string, sortColumn: 'firstName' | 'lastName' | 'username'}; export type GetApiV2PartitionPartitionIdManagementuserSearchOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const managementUserX = z.object({id: z.string().optional(), username: z.string().optional(), firstName: z.string().optional(), lastName: z.string().optional(), emailAddress: z.string().optional(), mustChangePassword: z.boolean().optional(), languageTag: z.enum(["en-US", "fr-CA"]).optional(), partitionId: z.string().optional(), roles: z.array(z.string()).optional(), groupIds: z.array(z.string()).optional()}); export const managementUserSearchResponseX = z.object({totalRecords: z.number().int().optional(), results: z.array(managementUserX).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 }; /** * Search for management users * * GET /v2/partition/{partitionId}/managementuser/search */ export const getApiV2PartitionPartitionIdManagementuserSearch = async (args: GetApiV2PartitionPartitionIdManagementuserSearchArgs, options?: GetApiV2PartitionPartitionIdManagementuserSearchOptions) => { const {baseUrl = "https://api.alianza.com", fetch: fetchFn = fetch, XAuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.descending != null) query.append("descending", String(args.descending)) if (args.firstResultIndex != null) query.append("firstResultIndex", String(args.firstResultIndex)) if (args.maxResult != null) query.append("maxResult", String(args.maxResult)) if (args.searchString != null) query.append("searchString", String(args.searchString)) if (args.sortColumn != null) query.append("sortColumn", String(args.sortColumn)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/managementuser/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(managementUserSearchResponseX, await res.json()) };