import {z} from 'zod' export type PurchaseRequestOrderError = {orderGroupId?: (string | null) | undefined, code?: number | undefined, description?: (string | null) | undefined}; export type BillingCycleType = 0 | 1 | 2 | 3 | 4 | 5 | 6; export type AssetType = 1 | 2 | 3; export type AssetScope = 1 | 2 | 3; export type ResellerSalesPricePriceType = 1 | 2 | 3 | 4; export type AssetTags = {assetId?: number | undefined, costCenter?: (string | null) | undefined, department?: (string | null) | undefined, project?: (string | null) | undefined, custom?: (string | null) | undefined, owner?: (string | null) | undefined}; export type PurchaseRequestOrderLineError = {reasonCode?: (string | null) | undefined, description?: (string | null) | undefined, properties?: ({[key: string]: string} | null) | undefined}; export type PurchaseRequestOrderLine = {productId?: (string | null) | undefined, subscriptionId?: (number | null) | undefined, armRegionName?: (string | null) | undefined, skuId?: (string | null) | undefined, productVariantId?: (number | null) | undefined, quantity?: number | undefined, billingCycle?: BillingCycleType | undefined, provisioningContext?: ({[key: string]: string} | null) | undefined, type?: AssetType | undefined, requiresInventoryCheck?: boolean | undefined, catalogItemId?: (string | null) | undefined, termDuration?: (string | null) | undefined, scope?: AssetScope | undefined, resellerPriceType?: ResellerSalesPricePriceType | undefined, resellerPriceTypeValue?: (number | null) | undefined, isTrial?: boolean | undefined, name?: (string | null) | undefined, attestationAccepted?: (boolean | null) | undefined, tags?: AssetTags | undefined, errors?: (Array | null) | undefined, customTermEndDate?: (string | null) | undefined}; export type PurchaseRequestOrder = {externalOrderId?: (string | null) | undefined, countryCode?: (string | null) | undefined, resellerCustomerId?: number | undefined, adminAccount?: (string | null) | undefined, notificationEmail?: (string | null) | undefined, invoiceProfileId?: (number | null) | undefined, scheduledPurchaseDate?: (string | null) | undefined, errors?: (Array | null) | undefined, orderLines?: (Array | null) | undefined}; export type CreateApiApiV1PurchaseRequestVerifyArgs = {body: PurchaseRequestOrder}; export type CreateApiApiV1PurchaseRequestVerifyOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const purchaseRequestOrderError = z.object({orderGroupId: z.string().nullable().optional(), code: z.number().int().optional(), description: z.string().nullable().optional()}); export const billingCycleType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]); export const assetType = z.union([z.literal(1), z.literal(2), z.literal(3)]); export const assetScope = z.union([z.literal(1), z.literal(2), z.literal(3)]); export const resellerSalesPricePriceType = z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]); export const assetTags = z.object({assetId: z.number().int().optional(), costCenter: z.string().nullable().optional(), department: z.string().nullable().optional(), project: z.string().nullable().optional(), custom: z.string().nullable().optional(), owner: z.string().nullable().optional()}); export const purchaseRequestOrderLineError = z.object({reasonCode: z.string().nullable().optional(), description: z.string().nullable().optional(), properties: z.record(z.string(), z.string()).nullable().optional()}); export const purchaseRequestOrderLine = z.object({productId: z.string().nullable().optional(), subscriptionId: z.number().int().nullable().optional(), armRegionName: z.string().nullable().optional(), skuId: z.string().nullable().optional(), productVariantId: z.number().int().nullable().optional(), quantity: z.number().int().optional(), billingCycle: billingCycleType.optional(), provisioningContext: z.record(z.string(), z.string()).nullable().optional(), type: assetType.optional(), requiresInventoryCheck: z.boolean().optional(), catalogItemId: z.string().nullable().optional(), termDuration: z.string().nullable().optional(), scope: assetScope.optional(), resellerPriceType: resellerSalesPricePriceType.optional(), resellerPriceTypeValue: z.number().nullable().optional(), isTrial: z.boolean().optional(), name: z.string().nullable().optional(), attestationAccepted: z.boolean().nullable().optional(), tags: assetTags.optional(), errors: z.array(purchaseRequestOrderLineError).nullable().optional(), customTermEndDate: z.string().nullable().optional()}); export const purchaseRequestOrder = z.object({externalOrderId: z.string().nullable().optional(), countryCode: z.string().nullable().optional(), resellerCustomerId: z.number().int().optional(), adminAccount: z.string().nullable().optional(), notificationEmail: z.string().nullable().optional(), invoiceProfileId: z.number().int().nullable().optional(), scheduledPurchaseDate: z.string().nullable().optional(), errors: z.array(purchaseRequestOrderError).nullable().optional(), orderLines: z.array(purchaseRequestOrderLine).nullable().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 }; /** * POST /api/v1/PurchaseRequest/verify */ export const createApiApiV1PurchaseRequestVerify = async (args: CreateApiApiV1PurchaseRequestVerifyArgs, options: CreateApiApiV1PurchaseRequestVerifyOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/PurchaseRequest/verify${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(purchaseRequestOrder, await res.json()) };