import {z} from 'zod' export type InventoryItemUpdateSchema = {displayName?: string | undefined, description?: string | undefined, identifyingAttributes?: Record | undefined, descriptiveAttributes?: Record | undefined, labels?: Record | undefined, resourceType?: string | undefined, resourceId?: string | undefined, firstSeenAt?: Record | undefined, lastSeenAt?: Record | undefined, isArchived?: boolean | undefined, customFields?: Record | undefined}; export type UpdateApiInventoryItemIdArgs = {id: string, body: {data: InventoryItemUpdateSchema}}; export type UpdateApiInventoryItemIdOptions = {baseUrl?: string | undefined, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const inventoryItemReadSchema = z.object({_id: z.string().optional(), createdAt: z.object({}).optional(), updatedAt: z.object({}).optional(), deletedAt: z.object({}).optional(), projectId: z.string().optional(), 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().optional(), archivedAt: z.object({}).optional(), archivedByUserId: z.string().optional(), customFields: z.object({}).optional(), createdByUserId: z.string().optional(), deletedByUserId: z.string().optional()}); export const updateApiInventoryItemIdResponse = z.object({data: inventoryItemReadSchema.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 }; /** * Update Inventory Item * * PUT /inventory-item/{id} */ export const updateApiInventoryItemId = async (args: UpdateApiInventoryItemIdArgs, options?: UpdateApiInventoryItemIdOptions) => { 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))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiInventoryItemIdResponse, await res.json()) };