import {z} from 'zod' export type GetApiV1betaLicensesArgs = {limit?: number | undefined, offset?: number | undefined, 'order_by.id'?: string | undefined, 'order_by.key_id'?: string | undefined, 'order_by.title'?: string | undefined, 'order_by.product'?: string | undefined, 'order_by.status'?: string | undefined, 'order_by.key_number'?: string | undefined, 'order_by.expiration_date'?: string | undefined, product?: string | undefined, key_number?: string | undefined, title_pattern?: string | undefined, key_number_pattern?: string | undefined, parent_key_id?: number | undefined, status?: string | undefined}; export type GetApiV1betaLicensesOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const licenseLicenseWithPriceVersion = z.object({activation_code: z.string().optional(), billing_type: z.string().optional(), comment: z.string().optional(), contract: z.string().optional(), expiration_date: z.string().optional(), id: z.number().int().optional(), items: z.array(z.string()).optional(), key_id: z.number().int().optional(), key_number: z.string().optional(), order_date: z.string().optional(), parent_key_id: z.number().int().optional(), period: z.number().int().optional(), product: z.string().optional(), sku_values: z.record(z.string(), z.boolean()).optional(), status: z.string().optional(), title: z.string().optional()}); export const licenseListLicensesWithPriceVersionResponseData = z.object({results: z.array(licenseLicenseWithPriceVersion).optional(), total: z.number().int().optional()}); export const errorWarning = z.object({code: z.number().int().optional(), data: z.string().optional(), desc: z.string().optional()}); export const licenseListLicensesWithPriceVersionResponse = z.object({code: z.number().int().optional(), data: licenseListLicensesWithPriceVersionResponseData.optional(), desc: z.string().optional(), maintenance: z.boolean().optional(), warnings: z.array(errorWarning).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 }; /** * List licenses with price version * * GET /v1beta/licenses */ export const getApiV1betaLicenses = async (args: GetApiV1betaLicensesArgs, options?: GetApiV1betaLicensesOptions) => { const {baseUrl = "https://api.openprovider.eu", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['order_by.id'] != null) query.append("order_by.id", String(args['order_by.id'])) if (args['order_by.key_id'] != null) query.append("order_by.key_id", String(args['order_by.key_id'])) if (args['order_by.title'] != null) query.append("order_by.title", String(args['order_by.title'])) if (args['order_by.product'] != null) query.append("order_by.product", String(args['order_by.product'])) if (args['order_by.status'] != null) query.append("order_by.status", String(args['order_by.status'])) if (args['order_by.key_number'] != null) query.append("order_by.key_number", String(args['order_by.key_number'])) if (args['order_by.expiration_date'] != null) query.append("order_by.expiration_date", String(args['order_by.expiration_date'])) if (args.product != null) query.append("product", String(args.product)) if (args.key_number != null) query.append("key_number", String(args.key_number)) if (args.title_pattern != null) query.append("title_pattern", String(args.title_pattern)) if (args.key_number_pattern != null) query.append("key_number_pattern", String(args.key_number_pattern)) if (args.parent_key_id != null) query.append("parent_key_id", String(args.parent_key_id)) if (args.status != null) query.append("status", String(args.status)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/v1beta/licenses${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(licenseListLicensesWithPriceVersionResponse, await res.json()) };