import {z} from 'zod' export type AssetType = 1 | 2 | 3; export type AssetStatus = 0 | 1 | 2 | 4 | 8 | 15; export type AssetSortBy = 0 | 1 | 2; export type SortOrder = 0 | 1; export type GetApiApiV1AssetsOrdersArgs = {ResellerCustomerId?: number | undefined, PublisherId?: number | undefined, ExternalOrderId?: (string | null) | undefined, ExternalOrderIds?: (Array | null) | undefined, ReservationId?: (string | null) | undefined, AssetType?: AssetType | undefined, Status?: AssetStatus | undefined, Page?: number | undefined, PageSize?: number | undefined, Search?: (string | null) | undefined, SortBy?: AssetSortBy | undefined, SortOrder?: SortOrder | undefined, InvoiceProfileId?: number | undefined}; export type GetApiApiV1AssetsOrdersOptions = {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 getApiApiV1AssetsOrdersResponse = z.array(purchaseRequestOrder); 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 /api/v1/Assets/orders */ export const getApiApiV1AssetsOrders = async (args: GetApiApiV1AssetsOrdersArgs, options: GetApiApiV1AssetsOrdersOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.ResellerCustomerId != null) query.append("ResellerCustomerId", String(args.ResellerCustomerId)) if (args.PublisherId != null) query.append("PublisherId", String(args.PublisherId)) if (args.ExternalOrderId != null) query.append("ExternalOrderId", String(args.ExternalOrderId)) for (const item of args.ExternalOrderIds ?? []) query.append("ExternalOrderIds", String(item)) if (args.ReservationId != null) query.append("ReservationId", String(args.ReservationId)) if (args.AssetType != null) query.append("AssetType", String(args.AssetType)) if (args.Status != null) query.append("Status", String(args.Status)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Search != null) query.append("Search", String(args.Search)) if (args.SortBy != null) query.append("SortBy", String(args.SortBy)) if (args.SortOrder != null) query.append("SortOrder", String(args.SortOrder)) if (args.InvoiceProfileId != null) query.append("InvoiceProfileId", String(args.InvoiceProfileId)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/Assets/orders${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(getApiApiV1AssetsOrdersResponse, await res.json()) };