import {z} from 'zod' export type GetApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdArgs = {accountId: string, batchId: string}; export type GetApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdOptions = {baseUrl: string, XAPIKey?: string | undefined, fetch?: typeof fetch | undefined}; export const getBatchStatus = z.object({batchId: z.string().optional(), hasErrors: z.boolean().optional(), operation: z.enum(["create", "update"]).optional(), status: z.enum(["processing", "completed"]).optional(), successLicenses: z.array(z.object({domain: z.string().optional(), getLicenseURL: z.string().optional(), licenseId: z.string().optional()})).optional(), failedLicenses: z.array(z.object({domain: z.string().optional(), message: z.string().optional()})).optional(), total: z.number().int().optional(), totalFailures: z.number().int().optional(), totalSuccesses: z.number().int().optional()}); export const getApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdResponse = z.object({success: z.boolean().optional(), data: getBatchStatus.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 }; /** * Get batch operation status * * GET /accounts/{accountId}/access-widget-licenses/batch/{batchId} */ export const getApiAccountsAccountIdAccessWidgetLicensesBatchBatchId = async (args: GetApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdArgs, options: GetApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, XAPIKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.batchId != null) query.append("batchId", String(args.batchId)) if (XAPIKey !== undefined) headers.set("X-API-Key", XAPIKey) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.accountId))}/access-widget-licenses/batch/${encodeURIComponent(String(args.batchId))}${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(getApiAccountsAccountIdAccessWidgetLicensesBatchBatchIdResponse, await res.json()) };