SimpleNS LogoDocs

API Reference

Complete API reference for @simplens/sdk interfaces, schemas, and utilities.


Overview

This page provides a quick reference for all exports from @simplens/sdk.

import {
  // Interfaces (types only)
  type SimpleNSProvider,
  type ProviderManifest,
  type ProviderConfig,
  type RateLimitConfig,
  type DeliveryResult,
  type BaseNotification,
  
  // Schemas
  baseNotificationSchema,
  baseRecipientSchema,
  emailRecipientSchema,
  smsRecipientSchema,
  whatsappRecipientSchema,
  pushRecipientSchema,
  emailContentSchema,
  smsContentSchema,
  whatsappContentSchema,
  createNotificationSchema,
  
  // Utilities
  replaceVariables,
  isHtmlContent,
  truncate,
  sleep,
  retryWithBackoff,
  
  // Re-exported
  z,  // Zod
} from '@simplens/sdk';

Interfaces

SimpleNSProvider<T>

The main contract all providers must implement.

MemberTypeDescription
manifestProviderManifestProvider metadata (readonly)
getNotificationSchema()() => z.ZodSchema<T>Returns notification validation schema
getRecipientSchema()() => z.ZodObjectReturns recipient fields schema
getContentSchema()() => z.ZodObjectReturns content fields schema
getRateLimitConfig()() => RateLimitConfigReturns rate limit settings
initialize(config)(ProviderConfig) => Promise<void>Setup credentials
healthCheck()() => Promise<boolean>Verify connectivity
send(notification)(T) => Promise<DeliveryResult>Deliver notification
shutdown()() => Promise<void>Cleanup resources

View full documentation →


ProviderManifest

Provider metadata for registration and display.

FieldTypeRequiredDescription
namestringPackage name (e.g., @simplens/twilio)
versionstringSemantic version
channelstringChannel type: email, sms, push, whatsapp, chat
displayNamestringHuman-readable name
descriptionstringProvider description
authorstringMaintainer name
homepagestringDocumentation URL
requiredCredentialsstring[]Required credential keys
optionalConfigstring[]Optional config keys

View full documentation →


ProviderConfig

Configuration passed to initialize().

FieldTypeDescription
idstringUnique provider instance ID
credentialsRecord<string, string>API keys, tokens
optionsRecord<string, unknown>?Optional settings

RateLimitConfig

Token bucket rate limiting configuration.

FieldTypeDescription
maxTokensnumberMaximum burst capacity
refillRatenumberTokens per second

DeliveryResult

Return type from send().

FieldTypeDescription
successbooleanWhether delivery succeeded
messageIdstring?Provider's message ID
providerResponseunknown?Raw API response
errorobject?Error details (if failed)
error.codestringError code
error.messagestringHuman-readable message
error.retryablebooleanWhether to retry

BaseNotification

Common fields in all notifications.

FieldTypeDescription
notification_idstringMongoDB ObjectId
request_idstringUUID v4 identifier
client_idstringUUID v4 client ID
channelstringChannel name
providerstring?Provider override
recipientRecord<string, unknown>Recipient data
contentRecord<string, unknown>Message content
variablesRecord<string, string>?Template variables
webhook_urlstringCallback URL
retry_countnumberCurrent retry count
created_atDateCreation timestamp

Schemas

Base Schemas

SchemaDescription
baseNotificationSchemaCommon notification fields
baseRecipientSchemaBase recipient with user_id

Recipient Schemas

SchemaExtendsAdditional Fields
emailRecipientSchemabaseRecipientSchemaemail
smsRecipientSchemabaseRecipientSchemaphone
whatsappRecipientSchemabaseRecipientSchemaphone
pushRecipientSchemabaseRecipientSchemadevice_token

Content Schemas

SchemaFieldsNotes
emailContentSchemasubject?, html?, text?Requires html or text
smsContentSchemamessageMax 1600 characters
whatsappContentSchemamessage-

Schema Factory

createNotificationSchema(channelName, recipientSchema, contentSchema)

Creates a complete notification schema combining base fields with channel-specific schemas.

View full documentation →


Utilities

FunctionSignatureDescription
replaceVariables(template: string, variables: Record<string, string>) => stringReplace {{var}} placeholders
isHtmlContent(content: string) => booleanCheck for HTML tags
truncate(str: string, maxLength: number, suffix?: string) => stringTruncate with suffix
sleep(ms: number) => Promise<void>Async delay
retryWithBackoff<T>(fn: () => Promise<T>, maxRetries?: number, baseDelayMs?: number) => Promise<T>Exponential backoff retry

View full documentation →


Quick Import Examples

import {
  SimpleNSProvider,
  ProviderManifest,
  ProviderConfig,
  DeliveryResult,
  RateLimitConfig,
  createNotificationSchema,
  emailRecipientSchema,
  emailContentSchema,
  replaceVariables,
  z,
} from '@simplens/sdk';

const schema = createNotificationSchema('email', emailRecipientSchema, emailContentSchema);
type EmailNotification = z.infer<typeof schema>;

class EmailProvider implements SimpleNSProvider<EmailNotification> {
  // ...implementation
}
import {
  SimpleNSProvider,
  ProviderManifest,
  DeliveryResult,
  createNotificationSchema,
  smsRecipientSchema,
  smsContentSchema,
  truncate,
  z,
} from '@simplens/sdk';

const schema = createNotificationSchema('sms', smsRecipientSchema, smsContentSchema);
type SMSNotification = z.infer<typeof schema>;

class SMSProvider implements SimpleNSProvider<SMSNotification> {
  // ...implementation
}
import {
  SimpleNSProvider,
  ProviderManifest,
  DeliveryResult,
  createNotificationSchema,
  baseRecipientSchema,
  z,
} from '@simplens/sdk';

// Custom recipient
const myRecipientSchema = baseRecipientSchema.extend({
  channel_id: z.string(),
});

// Custom content
const myContentSchema = z.object({
  text: z.string(),
  blocks: z.array(z.unknown()).optional(),
});

const schema = createNotificationSchema('chat', myRecipientSchema, myContentSchema);
type MyNotification = z.infer<typeof schema>;

class MyProvider implements SimpleNSProvider<MyNotification> {
  // ...implementation
}

On this page