The SDK provides pre-built Zod schemas that you can use directly or extend for your custom provider. Zod is re-exported from the SDK, so you don't need to install it separately.
import { z, emailRecipientSchema, createNotificationSchema } from '@simplens/sdk';
Email message content with HTML/text body options.
const emailContentSchema = z.object({ subject: z.string().optional(), html: z.string().optional(), text: z.string().optional(),}).refine( data => data.html || data.text, { message: 'Either html or text content is required' });
At least one of html or text must be provided. The schema uses a Zod refinement to enforce this.
Field
Type
Description
subject
string?
Email subject line
html
string?
HTML body content
text
string?
Plain text body content
Example:
{ "subject": "Welcome to SimpleNS", "html": "<h1>Hello!</h1><p>Welcome to our platform.</p>"}
Combines base schemas with channel-specific recipient and content schemas.
function createNotificationSchema< R extends z.ZodObject<Record<string, z.ZodTypeAny>>, C extends z.ZodObject<Record<string, z.ZodTypeAny>>>( channelName: string, recipientSchema: R, contentSchema: C)
Parameters:
Parameter
Type
Description
channelName
string
Channel identifier (e.g., 'email')
recipientSchema
ZodObject
Recipient fields schema
contentSchema
ZodObject
Content fields schema
Example:
import { createNotificationSchema, emailRecipientSchema, emailContentSchema, z } from '@simplens/sdk';// Create the complete schemaconst emailNotificationSchema = createNotificationSchema( 'email', emailRecipientSchema, emailContentSchema);// Infer the TypeScript typetype EmailNotification = z.infer<typeof emailNotificationSchema>;
Use Zod's z.infer<> to get TypeScript types from your schemas:
import { emailNotificationSchema } from './my-schemas';import { z } from '@simplens/sdk';// Get the typetype EmailNotification = z.infer<typeof emailNotificationSchema>;// Now you have full type safetyfunction processNotification(notification: EmailNotification) { console.log(notification.recipient.email); // ✓ Type-safe console.log(notification.content.html); // ✓ Type-safe}