import {z} from 'zod' export type GetApiV2PartitionPartitionIdDataHistoryArgs = {endDate?: string | undefined, firstResultIndex?: number | undefined, maxResult?: number | undefined, partitionId: string, startDate?: string | undefined, tag?: Array | undefined}; export type GetApiV2PartitionPartitionIdDataHistoryOptions = {baseUrl?: string | undefined, XAuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const partitionDataHistoryX = z.object({partitionId: z.string().optional(), id: z.string().optional(), type: z.enum(["PARTITION", "PLATFORM_USER", "PLATFORM_USER_GROUP", "CALLING_PLAN", "INBOUND_RATE_PLAN", "LOCAL_CALLING_PLANS", "TN_INVENTORY", "PARTITION_SETTINGS", "FEATURE_TOGGLES", "IP_WHITELIST", "DIAL_PLAN_RULE", "ROUTE_PLAN"]).optional(), createdDate: z.string().optional(), userId: z.string().optional(), userName: z.string().optional(), userType: z.enum(["AccountUser", "EndUser", "ManagementUser", "AlianzaUser", "BusinessLines"]).optional(), searchTags: z.array(z.string()).optional(), actionType: z.string().optional(), relatedDataId: z.string().optional(), relatedDataType: z.string().optional(), relatedDataDisplayName: z.string().optional(), oldValue: z.string().optional(), newValue: z.string().optional()}); export const partitionDataHistorySearchResponseX = z.object({totalRecords: z.number().int().optional(), results: z.array(partitionDataHistoryX).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 partition data history * * GET /v2/partition/{partitionId}/data-history */ export const getApiV2PartitionPartitionIdDataHistory = async (args: GetApiV2PartitionPartitionIdDataHistoryArgs, options?: GetApiV2PartitionPartitionIdDataHistoryOptions) => { 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.endDate != null) query.append("endDate", String(args.endDate)) if (args.firstResultIndex != null) query.append("firstResultIndex", String(args.firstResultIndex)) if (args.maxResult != null) query.append("maxResult", String(args.maxResult)) if (args.startDate != null) query.append("startDate", String(args.startDate)) for (const item of args.tag ?? []) query.append("tag", String(item)) if (XAuthToken !== undefined) headers.set("X-AUTH-TOKEN", XAuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/v2/partition/${encodeURIComponent(String(args.partitionId))}/data-history${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(partitionDataHistorySearchResponseX, await res.json()) };