import { z } from 'zod'; /** * Zod schema for the Notification model. * Defines the structure and validation rules for this data type. * This is the shape used in application code - what developers interact with. */ export const notification = z.lazy(() => { return z.object({ actionUrl: z.string().max(2048).optional().nullable(), archivedAt: z.string().optional().nullable(), category: z.string().max(100).optional().nullable(), content: z.string().max(10485760).optional().nullable(), createdAt: z.string(), customAttributes: z.any().optional().nullable(), discardedAt: z.string().optional().nullable(), id: z.string(), readAt: z.string().optional().nullable(), seenAt: z.string().optional().nullable(), sentAt: z.string().optional().nullable(), title: z.string(), topic: z.string().max(100).optional().nullable(), updatedAt: z.string(), userId: z.string(), }); }); /** * * @typedef {Notification} notification * @property {string} - The link associated with the notification. * @property {string} - The timestamp when the notification was archived. * @property {string} - The category grouping for the notification. * @property {string} - The body content of the notification. * @property {string} - The timestamp when the notification was created. * @property {any} - The custom data stored with the notification. * @property {string} - The timestamp when the notification was discarded. * @property {string} - The unique identifier for the notification. * @property {string} - The timestamp when the notification was marked as read. * @property {string} - The timestamp when the notification was seen. * @property {string} - The timestamp when the notification was sent. * @property {string} - The title that is displayed to recipients. * @property {string} - The topic for additional classification. * @property {string} - The timestamp when the notification was last updated. * @property {string} - The user that should receive the notification. */ export type Notification = z.infer; /** * Zod schema for mapping API responses to the Notification application shape. * Handles any property name transformations from the API schema. * If property names match the API schema exactly, this is identical to the application shape. */ export const notificationResponse = z.lazy(() => { return z .object({ action_url: z.string().max(2048).optional().nullable(), archived_at: z.string().optional().nullable(), category: z.string().max(100).optional().nullable(), content: z.string().max(10485760).optional().nullable(), created_at: z.string(), custom_attributes: z.any().optional().nullable(), discarded_at: z.string().optional().nullable(), id: z.string(), read_at: z.string().optional().nullable(), seen_at: z.string().optional().nullable(), sent_at: z.string().optional().nullable(), title: z.string(), topic: z.string().max(100).optional().nullable(), updated_at: z.string(), user_id: z.string(), }) .transform((data) => ({ actionUrl: data['action_url'], archivedAt: data['archived_at'], category: data['category'], content: data['content'], createdAt: data['created_at'], customAttributes: data['custom_attributes'], discardedAt: data['discarded_at'], id: data['id'], readAt: data['read_at'], seenAt: data['seen_at'], sentAt: data['sent_at'], title: data['title'], topic: data['topic'], updatedAt: data['updated_at'], userId: data['user_id'], })); }); /** * Zod schema for mapping the Notification application shape to API requests. * Handles any property name transformations required by the API schema. * If property names match the API schema exactly, this is identical to the application shape. */ export const notificationRequest = z.lazy(() => { return z .object({ actionUrl: z.string().max(2048).optional().nullable(), archivedAt: z.string().optional().nullable(), category: z.string().max(100).optional().nullable(), content: z.string().max(10485760).optional().nullable(), createdAt: z.string(), customAttributes: z.any().optional().nullable(), discardedAt: z.string().optional().nullable(), id: z.string(), readAt: z.string().optional().nullable(), seenAt: z.string().optional().nullable(), sentAt: z.string().optional().nullable(), title: z.string(), topic: z.string().max(100).optional().nullable(), updatedAt: z.string(), userId: z.string(), }) .transform((data) => ({ action_url: data['actionUrl'], archived_at: data['archivedAt'], category: data['category'], content: data['content'], created_at: data['createdAt'], custom_attributes: data['customAttributes'], discarded_at: data['discardedAt'], id: data['id'], read_at: data['readAt'], seen_at: data['seenAt'], sent_at: data['sentAt'], title: data['title'], topic: data['topic'], updated_at: data['updatedAt'], user_id: data['userId'], })); });