import {z} from 'zod' export type TimeIntervalNoTz = {start: string, end: string}; export type WeekSchedule = {monday?: Array | undefined, tuesday?: Array | undefined, wednesday?: Array | undefined, thursday?: Array | undefined, friday?: Array | undefined, saturday?: Array | undefined, sunday?: Array | undefined, tz?: string | undefined}; export type TargetInputPhoneNumber = {value: string, operating_hours?: (WeekSchedule | null) | undefined}; export type PatientInput = {first_name?: (string | null) | undefined, last_name?: (string | null) | undefined, date_of_birth?: (string | null) | undefined, phone_number?: (string | null) | undefined, external_id?: (string | null) | undefined, mrn?: (string | null) | undefined, extra_data?: ({[key: string]: unknown} | null) | undefined}; export type PreCallEhrIds = {patient_id: string}; export type TargetInput = {id?: string | undefined, external_id?: (string | null) | undefined, phone_number: string | TargetInputPhoneNumber | null, fallback_phone_number?: (string | TargetInputPhoneNumber | null) | undefined, input_data?: {[key: string]: unknown} | undefined, patient?: (PatientInput | null) | undefined, pre_call_ehr_ids?: (PreCallEhrIds | null) | undefined}; export type AddTargetsRequest = {targets?: (Array | null) | undefined, launch?: boolean | undefined, call_immediately?: boolean | undefined, allow_duplicates?: boolean | undefined, strict?: boolean | undefined}; export type CreateApiApiV1CampaignsCampaignIdTargetsArgs = {campaign_id: string, body: AddTargetsRequest}; export type CreateApiApiV1CampaignsCampaignIdTargetsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiApiV1CampaignsCampaignIdTargetsResponse = z.unknown(); 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 Targets * * POST /api/v1/campaigns/{campaign_id}/targets */ export const createApiApiV1CampaignsCampaignIdTargets = async (args: CreateApiApiV1CampaignsCampaignIdTargetsArgs, options: CreateApiApiV1CampaignsCampaignIdTargetsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/campaigns/${encodeURIComponent(String(args.campaign_id))}/targets${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(createApiApiV1CampaignsCampaignIdTargetsResponse, await res.json()) };