import {z} from 'zod' export type ServiceChannelServicesMessagingRefrigerantTrackingRefrigerantSettingsThresholdAnnouncement = {Id?: number | undefined, UpcomingChargeThreshold?: number | undefined, ApplyDateByFeature?: string | undefined, Message?: string | undefined, FeatureId?: number | undefined}; export type ServiceChannelServicesMessagingRefrigerantTrackingMaxThreshold = {Id?: number | undefined, ChargeThreshold?: number | undefined, ComercialRefTriggerRate?: number | undefined, IndustrialRefTriggerRate?: number | undefined, HVACTriggerRate?: number | undefined, OthersTriggerRate?: number | undefined, ApplyDate?: string | undefined, Announcement?: ServiceChannelServicesMessagingRefrigerantTrackingRefrigerantSettingsThresholdAnnouncement | undefined}; export type ServiceChannelServicesMessagingRefrigerantTrackingPreferencesRequest = {SubscriberId?: number | undefined, ChargeThreshold?: number | undefined, ComercialRefTriggerRate?: number | undefined, IndustrialRefTriggerRate?: number | undefined, HVACTriggerRate?: number | undefined, OthersTriggerRate?: number | undefined, CreateDate?: string | undefined, CreateDateStr?: string | undefined, UserId?: number | undefined, UserName?: string | undefined, MaxThreshold?: ServiceChannelServicesMessagingRefrigerantTrackingMaxThreshold | undefined, CalculationMethod?: string | undefined, CalculationMethods?: {[key: string]: string} | undefined, UnitsOfMeasure?: string | undefined, UnitsOfMeasures?: {[key: string]: string} | undefined, InventoryLocation?: string | undefined, InventoryLocationOptions?: {[key: string]: string} | undefined, RefrigerationPriorityName?: string | undefined, RefrigerationPriorityId?: number | undefined, RefrigerationPriorityNameOptions?: {[key: string]: string} | undefined, GenerateFollowUpWorkOrders?: {[key: string]: string} | undefined, ChargeThresholdStr?: string | undefined, RunCARBReport?: boolean | undefined, LeakInspectionNTE?: number | undefined, GenerateFollowUpWorkOrder?: string | undefined, MaxLocCount?: number | undefined, RtLimitedApplianceId?: string | undefined, RtLimitedApplianceName?: string | undefined, RefrigerantTrackingProviderId?: number | undefined, RefrigerantTrackingProviderName?: string | undefined, ODSRefrigerantTypes?: Array | undefined, GenerateLeakInspectionOption?: string | undefined, CalendarStartDate?: string | undefined, CalendarStartDateStr?: string | undefined, EnableCARBInspections?: boolean | undefined}; export type UpdateApiRefrigeranttrackingArgs = {body: ServiceChannelServicesMessagingRefrigerantTrackingPreferencesRequest}; export type UpdateApiRefrigeranttrackingOptions = {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 }; /** * Update/Insert Leak Tracking Preferences * * PUT /refrigeranttracking */ export const updateApiRefrigeranttracking = async (args: UpdateApiRefrigeranttrackingArgs, options?: UpdateApiRefrigeranttrackingOptions) => { 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(/\/+$/, '')}/refrigeranttracking${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(systemObject, await res.json()) };