@contentgrowth/content-emailing 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentgrowth/content-emailing",
3
- "version": "0.6.1",
3
+ "version": "0.7.1",
4
4
  "type": "module",
5
5
  "description": "Unified email delivery and template management system with UI components",
6
6
  "main": "./dist/index.js",
package/schema.sql CHANGED
@@ -61,3 +61,35 @@ CREATE INDEX IF NOT EXISTS idx_system_email_preferences_unsub_token ON system_em
61
61
  CREATE INDEX IF NOT EXISTS idx_system_email_sends_user ON system_email_sends(user_id);
62
62
  CREATE INDEX IF NOT EXISTS idx_system_email_sends_period ON system_email_sends(email_kind, period_key);
63
63
  CREATE INDEX IF NOT EXISTS idx_system_email_events_send ON system_email_events(send_id);
64
+
65
+ -- =========================================================
66
+ -- Email Logs: Comprehensive tracking of all email sends
67
+ -- =========================================================
68
+ -- Use this table to track every email sent, with status,
69
+ -- provider info, and error handling. Supports batch emails via batch_id.
70
+
71
+ CREATE TABLE IF NOT EXISTS system_email_logs (
72
+ id TEXT PRIMARY KEY DEFAULT (lower(hex(randomblob(16)))),
73
+ batch_id TEXT, -- Groups multiple recipients in same send
74
+ recipient_email TEXT NOT NULL, -- Email address sent to
75
+ recipient_user_id TEXT, -- User ID if known (NULL for invitations)
76
+ template_id TEXT NOT NULL, -- e.g., 'tmpl_verify_email', 'direct'
77
+ subject TEXT, -- Rendered subject line
78
+ status TEXT NOT NULL DEFAULT 'pending', -- 'pending', 'sent', 'failed', 'bounced', 'complained'
79
+ provider TEXT, -- 'resend', 'sendgrid', 'mailchannels', etc.
80
+ provider_message_id TEXT, -- ID from email provider for tracking/webhooks
81
+ error_message TEXT, -- Failure reason if status = 'failed'
82
+ error_code TEXT, -- Provider error code if available
83
+ metadata TEXT, -- JSON for extra context (org name, etc.)
84
+ created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
85
+ sent_at INTEGER -- When successfully delivered to provider
86
+ );
87
+
88
+ -- Email logs indexes for common queries
89
+ CREATE INDEX IF NOT EXISTS idx_email_logs_recipient ON system_email_logs(recipient_email);
90
+ CREATE INDEX IF NOT EXISTS idx_email_logs_user ON system_email_logs(recipient_user_id);
91
+ CREATE INDEX IF NOT EXISTS idx_email_logs_template ON system_email_logs(template_id);
92
+ CREATE INDEX IF NOT EXISTS idx_email_logs_status ON system_email_logs(status);
93
+ CREATE INDEX IF NOT EXISTS idx_email_logs_batch ON system_email_logs(batch_id);
94
+ CREATE INDEX IF NOT EXISTS idx_email_logs_created ON system_email_logs(created_at DESC);
95
+ CREATE INDEX IF NOT EXISTS idx_email_logs_provider_msg ON system_email_logs(provider_message_id);