import {z} from 'zod' export type InventoryItemSelectSchema = {_id?: boolean | undefined, createdAt?: boolean | undefined, updatedAt?: boolean | undefined, deletedAt?: boolean | undefined, projectId?: boolean | undefined, entityType?: boolean | undefined, entityKey?: boolean | undefined, displayName?: boolean | undefined, source?: boolean | undefined, description?: boolean | undefined, identifyingAttributes?: boolean | undefined, descriptiveAttributes?: boolean | undefined, labels?: boolean | undefined, resourceType?: boolean | undefined, resourceId?: boolean | undefined, firstSeenAt?: boolean | undefined, lastSeenAt?: boolean | undefined, inventoryStatus?: boolean | undefined, isArchived?: boolean | undefined, archivedAt?: boolean | undefined, archivedByUserId?: boolean | undefined, customFields?: boolean | undefined, createdByUserId?: boolean | undefined, deletedByUserId?: boolean | undefined}; export type CreateApiInventoryItemIdGetItemArgs = {id: string, body: {select?: InventoryItemSelectSchema | undefined}}; export type CreateApiInventoryItemIdGetItemOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const inventoryItem = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), version: z.number().optional(), projectId: z.string(), entityType: z.enum(["service", "service.instance", "host", "container", "process", "k8s.cluster", "k8s.namespace", "k8s.node", "k8s.pod", "k8s.deployment", "proxmox.cluster", "openstack.cloud", "proxmox.node", "openstack.hypervisor", "proxmox.guest", "openstack.instance", "ceph.cluster", "storage.array", "vmware.vcenter", "vmware.cluster", "vmware.host", "vmware.vm", "vmware.datastore", "docker.swarm.cluster", "docker.swarm.node", "docker.swarm.service", "docker.swarm.task", "telemetry.sdk", "database", "remote.service", "database.server", "message.queue", "openstack.resource", "network.device", "cloud.resource", "serverless.function", "rum.application", "iot.device", "docker.host", "podman.host", "external.service", "external.database", "appliance"]), entityKey: z.string(), displayName: z.string().optional(), source: z.enum(["discovered", "inventory", "manual"]), description: z.string().optional(), identifyingAttributes: z.object({}).optional(), descriptiveAttributes: z.object({}).optional(), labels: z.object({}).optional(), resourceType: z.string().optional(), resourceId: z.string().optional(), firstSeenAt: z.object({}).optional(), lastSeenAt: z.object({}).optional(), inventoryStatus: z.enum(["live", "recent", "stale", "never", "not-tracked"]).optional(), isArchived: z.boolean(), archivedAt: z.object({}).optional(), archivedByUserId: z.string().optional(), customFields: z.object({}).optional(), createdByUserId: z.string().optional(), deletedByUserId: z.string().optional()}); export const createApiInventoryItemIdGetItemResponse = z.object({data: inventoryItem.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 Inventory Item * * POST /inventory-item/{id}/get-item */ export const createApiInventoryItemIdGetItem = async (args: CreateApiInventoryItemIdGetItemArgs, options?: CreateApiInventoryItemIdGetItemOptions) => { const {baseUrl = "https://oneuptime.com/api", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set("APIKey", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/inventory-item/${encodeURIComponent(String(args.id))}/get-item${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(createApiInventoryItemIdGetItemResponse, await res.json()) };