import {z} from 'zod' export type GetApiV1TransactionalTransactionalIdLanguageLanguageOptions = {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 getApiV1TransactionalTransactionalIdLanguageLanguageResponse = 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 }; /** * Get a translation of a transactional message * * GET /v1/transactional/{transactional_id}/language/{language} */ export const getApiV1TransactionalTransactionalIdLanguageLanguage = async (options?: GetApiV1TransactionalTransactionalIdLanguageLanguageOptions) => { const {baseUrl = "https://track.customer.io", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1TransactionalTransactionalIdLanguageLanguageResponse, await res.json()) };