import {z} from 'zod' export type ActionId = number; export type Created = number; export type Updated = number; export type Language = string; export type From = string; export type FromId = number; export type ReplyTo = string; export type ReplyToId = number | null; export type Preprocessor = 'premailer'; export type Recipient = string; export type Subject = string; export type Cc = string; export type Bcc = string; export type FakeBcc = boolean; export type PreheaderText = string; export type BodyAmp = string; export type UpdateHeaders = Array<{name?: string | undefined, value?: string | undefined}>; export type UpdateTransactionalActionObject = {id?: ActionId | undefined, name?: string | undefined, created?: Created | undefined, updated?: Updated | undefined, body?: string | undefined, language?: Language | undefined, type?: ('email' | 'push') | undefined, from?: From | undefined, from_id?: FromId | undefined, reply_to?: ReplyTo | undefined, reply_to_id?: ReplyToId | undefined, preprocessor?: Preprocessor | undefined, recipient?: Recipient | undefined, subject?: Subject | undefined, cc?: Cc | undefined, bcc?: Bcc | undefined, fake_bcc?: FakeBcc | undefined, preheader_text?: PreheaderText | undefined, body_amp?: BodyAmp | undefined, headers?: UpdateHeaders | undefined}; export type UpdateApiV1TransactionalTransactionalIdLanguageLanguageArgs = {body: UpdateTransactionalActionObject}; export type UpdateApiV1TransactionalTransactionalIdLanguageLanguageOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const actionId = z.number().int(); export const created = z.number().int(); export const updated = z.number().int(); export const language = z.string(); export const from = z.string(); export const fromId = z.number().int(); export const replyTo = z.string(); export const replyToId = z.number().int().nullable(); export const preprocessor = z.literal("premailer"); export const recipient = z.string(); export const subject = z.string(); export const cc = z.string(); export const bcc = z.string(); export const fakeBcc = z.boolean(); export const preheaderText = z.string(); export const bodyAmp = z.string(); export const headers = z.string(); export const getTransactionalActionObject = z.object({id: actionId.optional(), name: z.string().optional(), created: created.optional(), updated: updated.optional(), body: z.string().optional(), language: language.optional(), type: z.enum(["email", "push"]).optional(), from: from.optional(), from_id: fromId.optional(), reply_to: replyTo.optional(), reply_to_id: replyToId.optional(), preprocessor: preprocessor.optional(), recipient: recipient.optional(), subject: subject.optional(), cc: cc.optional(), bcc: bcc.optional(), fake_bcc: fakeBcc.optional(), preheader_text: preheaderText.optional(), body_amp: bodyAmp.optional(), headers: headers.optional()}); export const updateApiV1TransactionalTransactionalIdLanguageLanguageResponse = z.object({content: z.array(getTransactionalActionObject).optional()}); 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 a translation of a transactional message * * PUT /v1/transactional/{transactional_id}/language/{language} */ export const updateApiV1TransactionalTransactionalIdLanguageLanguage = async (args: UpdateApiV1TransactionalTransactionalIdLanguageLanguageArgs, options?: UpdateApiV1TransactionalTransactionalIdLanguageLanguageOptions) => { const {baseUrl = "https://track.customer.io", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/transactional/${encodeURIComponent(String(args.transactional_id))}/language/${encodeURIComponent(String(args.language))}${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(updateApiV1TransactionalTransactionalIdLanguageLanguageResponse, await res.json()) };