import {z} from 'zod' export type GetApiTeamMessagingV1ChatsChatIdNotesArgs = {chatId: string, creationTimeTo?: string | undefined, creationTimeFrom?: string | undefined, creatorId?: string | undefined, status?: ('Active' | 'Draft') | undefined, pageToken?: string | undefined, recordCount?: number | undefined}; export type GetApiTeamMessagingV1ChatsChatIdNotesOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const tMCreatorInfo = z.object({id: z.string().optional()}); export const lastModifiedByInfo = z.object({id: z.string().optional()}); export const lockedByInfo = z.object({id: z.string().optional()}); export const tMNoteInfo = z.object({id: z.string().optional(), title: z.string().optional(), chatIds: z.array(z.string()).optional(), preview: z.string().optional(), creator: tMCreatorInfo.optional(), lastModifiedBy: lastModifiedByInfo.optional(), lockedBy: lockedByInfo.optional(), status: z.enum(["Active", "Draft"]).optional(), creationTime: z.string().optional(), lastModifiedTime: z.string().optional(), type: z.literal("Note").optional()}); export const tMNavigationInfo = z.object({prevPageToken: z.string().optional(), nextPageToken: z.string().optional()}); export const tMNoteList = z.object({records: z.array(tMNoteInfo).optional(), navigation: tMNavigationInfo.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 }; /** * List Notes * * GET /team-messaging/v1/chats/{chatId}/notes */ export const getApiTeamMessagingV1ChatsChatIdNotes = async (args: GetApiTeamMessagingV1ChatsChatIdNotesArgs, options?: GetApiTeamMessagingV1ChatsChatIdNotesOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.creationTimeTo != null) query.append("creationTimeTo", String(args.creationTimeTo)) if (args.creationTimeFrom != null) query.append("creationTimeFrom", String(args.creationTimeFrom)) if (args.creatorId != null) query.append("creatorId", String(args.creatorId)) if (args.status != null) query.append("status", String(args.status)) if (args.pageToken != null) query.append("pageToken", String(args.pageToken)) if (args.recordCount != null) query.append("recordCount", String(args.recordCount)) if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/team-messaging/v1/chats/${encodeURIComponent(String(args.chatId))}/notes${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(tMNoteList, await res.json()) };