import {z} from 'zod' export type GetApiV1ProjectsProjectIdKakaotalkSendersPlusFriendIdTemplatesTemplateCodeActivitiesArgs = {projectId: string, plusFriendId: string, templateCode: string, pageSize?: number | undefined, pageToken?: string | undefined}; export type GetApiV1ProjectsProjectIdKakaotalkSendersPlusFriendIdTemplatesTemplateCodeActivitiesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, BearerAuth?: string | undefined, OAuth2Production?: string | undefined, fetch?: typeof fetch | undefined}; export const kakaotalkTemplateNotificationTypeEnum = z.enum(["COMMENT_ADDED", "CREATED", "DRAFT", "EDITED", "IN_PROGRESS", "REJECTED"]); export const kakaotalkTemplateNotificationDto = z.object({type: kakaotalkTemplateNotificationTypeEnum, created: z.string().optional(), author: z.string().optional(), comment: z.string().optional()}); export const kakaotalkTemplateNotificationListDto = z.object({totalSize: z.number(), pageSize: z.number(), previousPageToken: z.string().optional(), nextPageToken: z.string().optional(), notifications: z.array(kakaotalkTemplateNotificationDto)}); 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 }; /** * Lists activities on project template * * GET /v1/projects/{projectId}/kakaotalk/senders/{plusFriendId}/templates/{templateCode}/activities */ export const getApiV1ProjectsProjectIdKakaotalkSendersPlusFriendIdTemplatesTemplateCodeActivities = async (args: GetApiV1ProjectsProjectIdKakaotalkSendersPlusFriendIdTemplatesTemplateCodeActivitiesArgs, options?: GetApiV1ProjectsProjectIdKakaotalkSendersPlusFriendIdTemplatesTemplateCodeActivitiesOptions) => { const {baseUrl = "https://provisioning.api.sinch.com", fetch: fetchFn = fetch, BasicAuth, BearerAuth, OAuth2Production} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) if (OAuth2Production !== undefined) headers.set('authorization', `Bearer ${OAuth2Production}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectId))}/kakaotalk/senders/${encodeURIComponent(String(args.plusFriendId))}/templates/${encodeURIComponent(String(args.templateCode))}/activities${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(kakaotalkTemplateNotificationListDto, await res.json()) };