import {z} from 'zod' export type ServiceChannelNotificationsObjectsUser = {Id?: number | undefined, AuthUserId?: number | undefined, UserName?: string | undefined, FullName?: string | undefined, Email?: string | undefined, LoginType?: ('Credentials' | 'Pin') | undefined, SubscriberId?: number | undefined, ProviderId?: number | undefined}; export type ServiceChannelNotificationsObjectsWorkorderStatusDescriptor = {Primary?: string | undefined, Extended?: string | undefined}; export type ServiceChannelNotificationsObjectsLocation = {StoreId?: string | undefined, Id?: number | undefined, SubscriberId?: number | undefined, ShortName?: string | undefined, FullName?: string | undefined, Address1?: string | undefined, Address2?: string | undefined, Region?: string | undefined, District?: string | undefined, City?: string | undefined, State?: string | undefined, Country?: string | undefined, StoreOpenDTO?: string | undefined, StoreCloseDTO?: string | undefined, Zip?: string | undefined, MainContact?: string | undefined, PhoneNumber?: string | undefined, FaxNumber?: string | undefined, FacilityManager?: string | undefined, Email?: string | undefined, NotesCount?: number | undefined, LocationTypeId?: number | undefined, LocationType?: string | undefined, Latitude?: number | undefined, Longitude?: number | undefined, TimeZoneId?: string | undefined, TimeZoneInfoId?: number | undefined, TimeShiftToEst?: number | undefined, RetiredAllProvidersDate?: string | undefined, RetiredLogin?: string | undefined, UpdatedUserName?: string | undefined, UpdatedDate?: string | undefined, UpdatedLocationNotesUserName?: string | undefined, UpdatedLocationNotesDate?: string | undefined}; export type ServiceChannelNotificationsObjectsCheckInOutActivity = {CheckInNotes?: {[key: string]: string} | undefined, Id?: number | undefined, SubscriberId?: number | undefined, ProviderId?: number | undefined, LocationId?: number | undefined, CheckinAction?: ('CheckIn' | 'CheckOut') | undefined, WorkOrderId?: number | undefined, Date?: string | undefined, DateDTO?: string | undefined, User?: ServiceChannelNotificationsObjectsUser | undefined, CallerId?: string | undefined, Action?: string | undefined, WorkType?: string | undefined, WorkorderStatus?: ServiceChannelNotificationsObjectsWorkorderStatusDescriptor | undefined, ProviderName?: string | undefined, Trade?: string | undefined, Category?: string | undefined, Source?: string | undefined, TradeId?: number | undefined, TechsCount?: number | undefined, Location?: ServiceChannelNotificationsObjectsLocation | undefined, ClosingAuthorizationNumber?: number | undefined, CheckinType?: ('Common' | 'Ivr' | 'Gps') | undefined}; export type ServiceChannelServicesWebApiModelsCheckInOutNotificationObject = {Object?: ServiceChannelNotificationsObjectsCheckInOutActivity | undefined, Type?: string | undefined, Action?: string | undefined, EventType?: string | undefined}; export type CreateApiScConnectorCheckInOutArgs = {body: ServiceChannelServicesWebApiModelsCheckInOutNotificationObject}; export type CreateApiScConnectorCheckInOutOptions = {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 }; /** * Called when subcontractor workorder CheckInOut * * POST /ScConnector/CheckInOut */ export const createApiScConnectorCheckInOut = async (args: CreateApiScConnectorCheckInOutArgs, options?: CreateApiScConnectorCheckInOutOptions) => { 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(/\/+$/, '')}/ScConnector/CheckInOut${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()) };