import {z} from 'zod' export type GetApiV5PersonsPersonIdStepsArgs = {person_id: string, names?: Array | undefined, containers?: Array | undefined, campaign_ids?: Array | undefined, programs?: Array | undefined, journey_names?: Array | undefined, is_primary?: boolean | undefined, data_keys?: Array | undefined, event_ids?: Array | undefined, cause_event_ids?: Array | undefined, root_event_ids?: Array | undefined, offset?: number | undefined, limit?: number | undefined, journey_key_names?: Array | undefined, journey_key_values?: Array | undefined}; export type GetApiV5PersonsPersonIdStepsOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const zonedDateTime = z.string(); export const personStepDataResponse = z.object({name: z.string().optional(), scope: z.enum(["CLIENT", "PRIVATE", "PUBLIC"]).optional(), value: z.object({}).optional()}); export const journeyKey = z.object({name: z.string().optional(), value: z.string().optional()}); export const personStepResponse = z.object({campaign_id: z.string(), cause_event_id: z.string(), container: z.string(), created_date: zonedDateTime, data: z.record(z.string(), personStepDataResponse), event_date: zonedDateTime, event_id: z.string(), id: z.string(), is_primary: z.boolean(), journey_key: journeyKey, journey_name: z.string(), name: z.string(), program: z.string(), quality: z.enum(["HIGH", "LOW", "NONE"]), root_event_id: z.string(), scope: z.enum(["CLIENT", "PRIVATE", "PUBLIC"]), updated_date: zonedDateTime}); export const getApiV5PersonsPersonIdStepsResponse = z.array(personStepResponse); 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 }; /** * List person steps * * GET /v5/persons/{person_id}/steps * * Also accepts auth: QUERY, COOKIE */ export const getApiV5PersonsPersonIdSteps = async (args: GetApiV5PersonsPersonIdStepsArgs, options?: GetApiV5PersonsPersonIdStepsOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.names ?? []) query.append("names", String(item)) for (const item of args.containers ?? []) query.append("containers", String(item)) for (const item of args.campaign_ids ?? []) query.append("campaign_ids", String(item)) for (const item of args.programs ?? []) query.append("programs", String(item)) for (const item of args.journey_names ?? []) query.append("journey_names", String(item)) if (args.is_primary != null) query.append("is_primary", String(args.is_primary)) for (const item of args.data_keys ?? []) query.append("data_keys", String(item)) for (const item of args.event_ids ?? []) query.append("event_ids", String(item)) for (const item of args.cause_event_ids ?? []) query.append("cause_event_ids", String(item)) for (const item of args.root_event_ids ?? []) query.append("root_event_ids", String(item)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) for (const item of args.journey_key_names ?? []) query.append("journey_key_names", String(item)) for (const item of args.journey_key_values ?? []) query.append("journey_key_values", String(item)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v5/persons/${encodeURIComponent(String(args.person_id))}/steps${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV5PersonsPersonIdStepsResponse, await res.json()) };