@rei-standard/amsg-server 1.2.0 → 2.0.0-pre1

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.
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Shared SQL schema constants
3
+ * ReiStandard SDK v2.0.0-pre1
4
+ */
5
+
6
+ const TABLE_SQL = `
7
+ CREATE TABLE IF NOT EXISTS scheduled_messages (
8
+ id SERIAL PRIMARY KEY,
9
+ user_id VARCHAR(255) NOT NULL,
10
+ uuid VARCHAR(36),
11
+ encrypted_payload TEXT NOT NULL,
12
+ message_type VARCHAR(50) NOT NULL CHECK (message_type IN ('fixed', 'prompted', 'auto', 'instant')),
13
+ next_send_at TIMESTAMP WITH TIME ZONE NOT NULL,
14
+ status VARCHAR(50) NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'sent', 'failed')),
15
+ retry_count INTEGER DEFAULT 0,
16
+ created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
17
+ updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
18
+ )
19
+ `;
20
+
21
+ const INDEXES = [
22
+ {
23
+ name: 'idx_pending_tasks_optimized',
24
+ sql: `CREATE INDEX IF NOT EXISTS idx_pending_tasks_optimized
25
+ ON scheduled_messages (status, next_send_at, id, retry_count)
26
+ WHERE status = 'pending'`,
27
+ description: 'Main query index (Cron Job finds pending tasks)'
28
+ },
29
+ {
30
+ name: 'idx_cleanup_completed',
31
+ sql: `CREATE INDEX IF NOT EXISTS idx_cleanup_completed
32
+ ON scheduled_messages (status, updated_at)
33
+ WHERE status IN ('sent', 'failed')`,
34
+ description: 'Cleanup query index'
35
+ },
36
+ {
37
+ name: 'idx_failed_retry',
38
+ sql: `CREATE INDEX IF NOT EXISTS idx_failed_retry
39
+ ON scheduled_messages (status, retry_count, next_send_at)
40
+ WHERE status = 'failed' AND retry_count < 3`,
41
+ description: 'Failed retry index'
42
+ },
43
+ {
44
+ name: 'idx_user_id',
45
+ sql: `CREATE INDEX IF NOT EXISTS idx_user_id
46
+ ON scheduled_messages (user_id)`,
47
+ description: 'User task query index'
48
+ },
49
+ {
50
+ name: 'uidx_uuid',
51
+ sql: `CREATE UNIQUE INDEX IF NOT EXISTS uidx_uuid
52
+ ON scheduled_messages (uuid)
53
+ WHERE uuid IS NOT NULL`,
54
+ description: 'UUID uniqueness guard',
55
+ critical: true
56
+ }
57
+ ];
58
+
59
+ const VERIFY_TABLE_SQL = `
60
+ SELECT table_name
61
+ FROM information_schema.tables
62
+ WHERE table_schema = 'public'
63
+ AND table_name = 'scheduled_messages'
64
+ `;
65
+
66
+ const COLUMNS_SQL = `
67
+ SELECT column_name, data_type, is_nullable
68
+ FROM information_schema.columns
69
+ WHERE table_schema = 'public'
70
+ AND table_name = 'scheduled_messages'
71
+ ORDER BY ordinal_position
72
+ `;
73
+
74
+ export { COLUMNS_SQL as C, INDEXES as I, TABLE_SQL as T, VERIFY_TABLE_SQL as V };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rei-standard/amsg-server",
3
- "version": "1.2.0",
3
+ "version": "2.0.0-pre1",
4
4
  "description": "ReiStandard Active Messaging server SDK with pluggable database adapters",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,7 +33,8 @@
33
33
  "node": ">=20"
34
34
  },
35
35
  "dependencies": {
36
- "web-push": "^3.6.7"
36
+ "web-push": "^3.6.7",
37
+ "@netlify/blobs": "^8.1.0"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@neondatabase/serverless": ">=0.9.0",