import {z} from 'zod' export type ServiceChannelServicesMessagingAssetsWarrantyProvider = {Type?: ('Fixed' | 'PrimaryRanked' | 'FixedRanked') | undefined, Value?: number | undefined, ProviderName?: string | undefined}; export type ServiceChannelServicesMessagingAssetsWarrantyExpiration = {Type?: ('FromPurchaseDate' | 'FromInstallDate') | undefined, Period?: number | undefined}; export type ServiceChannelServicesMessagingAssetsWarrantyInfo = {NTE?: number | undefined, Priority?: string | undefined, PriorityId?: number | undefined, Category?: string | undefined, CategoryId?: number | undefined, Provider?: ServiceChannelServicesMessagingAssetsWarrantyProvider | undefined, Expiration?: ServiceChannelServicesMessagingAssetsWarrantyExpiration | undefined}; export type SystemObject = Record; export type ServiceChannelServicesMessagingEquipmentsEquipmentAttributeDescription = {EquipmentAttributeId?: number | undefined, EquipmentTypeAttributeId?: number | undefined, ValueType?: number | undefined, EquipmentId?: number | undefined, Value?: SystemObject | undefined, ValueText?: string | undefined, SelectedOptionsText?: string | undefined, Visible?: boolean | undefined, Editable?: boolean | undefined, Required?: boolean | undefined, Name?: string | undefined, Custom?: boolean | undefined}; export type ServiceChannelServicesMessagingAssetsAddUpdateAssetRequest = {OriginalTagId?: string | undefined, NewTagId: string, LocationNoteHeaderName?: string | undefined, LocationNoteHeaderValue: string, BrandId: number, BrandName: string, AssetTypeId: number, ApplyEmptyFields?: boolean | undefined, Warranty?: ServiceChannelServicesMessagingAssetsWarrantyInfo | undefined, CustomAttributes?: Array | undefined, ModelNo?: string | undefined, SerialNo?: string | undefined, Area?: string | undefined, WorkOrderArea?: string | undefined, InstallDateStr?: string | undefined, PurchaseDateStr?: string | undefined, ManufacturedDateStr?: string | undefined, EnergyEfficiency?: string | undefined, Capacity?: string | undefined, Description?: string | undefined, AssetTag?: string | undefined, LeaseDate?: string | undefined, UsesRefrigerant?: number | undefined, TradeId?: number | undefined, LifeExpectancy?: number | undefined, LeasePeriod?: number | undefined, Condition?: number | undefined, ParentId?: number | undefined, Currency?: number | undefined, OriginalValue?: number | undefined, ClearAssetTag?: boolean | undefined, IsInspection?: boolean | undefined, ApplyCustom?: boolean | undefined, HasLeakDetector?: boolean | undefined, Active?: boolean | undefined, IsLeased?: boolean | undefined, HasComponents?: boolean | undefined, HasCircuits?: boolean | undefined, IsCarbReporting?: boolean | undefined, AssetUpdatesStatus?: string | undefined, ProcessDuplicatedAssetTag?: boolean | undefined}; export type CreateApiAssetsAddUpdateAssetArgs = {body: ServiceChannelServicesMessagingAssetsAddUpdateAssetRequest}; export type CreateApiAssetsAddUpdateAssetOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const systemObject = z.object({}); 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 }; /** * Add Update Asset * * POST /assets/AddUpdateAsset */ export const createApiAssetsAddUpdateAsset = async (args: CreateApiAssetsAddUpdateAssetArgs, options?: CreateApiAssetsAddUpdateAssetOptions) => { const {baseUrl = "https://sb2api.servicechannel.com/v3", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/assets/AddUpdateAsset${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(systemObject, await res.json()) };