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 GetApiApiV1AssetsArgs = {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 GetApiApiV1AssetsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const objectReference = z.object({id: z.number().int().optional(), name: z.string().nullable().optional()}); export const assetStatus = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(8), z.literal(15)]); export const assetScope = z.union([z.literal(1), z.literal(2), z.literal(3)]); export const assetType = z.union([z.literal(1), z.literal(2), z.literal(3)]); 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 subscriptionLite = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), publisherSubscriptionId: z.string().nullable().optional(), resellerCustomerName: z.string().nullable().optional()}); 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 assetExtended = z.object({invoiceProfile: objectReference.optional(), id: z.number().int().optional(), status: assetStatus.optional(), externalOrderId: z.string().nullable().optional(), quantity: z.number().int().optional(), externalProductId: z.string().nullable().optional(), externalSkuId: z.string().nullable().optional(), name: z.string().nullable().optional(), startDate: z.string().optional(), expirationDate: z.string().nullable().optional(), resellerCustomerId: z.number().int().optional(), scope: assetScope.optional(), assetType: assetType.optional(), billingCycle: billingCycleType.optional(), publisherId: z.number().int().optional(), programId: z.number().int().optional(), reservationId: z.string().nullable().optional(), reservationUsedInSubscriptionId: z.number().int().nullable().optional(), reservationUsedInSubscription: subscriptionLite.optional(), purchaseCurrency: z.string().nullable().optional(), purchasePrice: z.number().optional(), salesCurrency: z.string().nullable().optional(), salesPrice: z.number().optional(), createdDate: z.string().optional(), modifiedDate: z.string().optional(), changedBy: z.string().nullable().optional(), reservedInstanceArtifactResourceId: z.string().nullable().optional(), purchaseDate: z.string().nullable().optional(), tags: assetTags.optional(), autoRenewEnabled: z.boolean().nullable().optional(), productVariantId: z.number().int().nullable().optional()}); export const getApiApiV1AssetsResponse = z.array(assetExtended); 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 */ export const getApiApiV1Assets = async (args: GetApiApiV1AssetsArgs, options: GetApiApiV1AssetsOptions) => { 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${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(getApiApiV1AssetsResponse, await res.json()) };