@omnitron-dev/titan-notifications 0.1.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.
Files changed (150) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -0
  3. package/dist/channel/channel-registry.d.ts +40 -0
  4. package/dist/channel/channel-registry.d.ts.map +1 -0
  5. package/dist/channel/channel-registry.js +157 -0
  6. package/dist/channel/channel-registry.js.map +1 -0
  7. package/dist/channel/channel.interface.d.ts +77 -0
  8. package/dist/channel/channel.interface.d.ts.map +1 -0
  9. package/dist/channel/channel.interface.js +9 -0
  10. package/dist/channel/channel.interface.js.map +1 -0
  11. package/dist/channel/channels/email.channel.d.ts +43 -0
  12. package/dist/channel/channels/email.channel.d.ts.map +1 -0
  13. package/dist/channel/channels/email.channel.js +211 -0
  14. package/dist/channel/channels/email.channel.js.map +1 -0
  15. package/dist/channel/channels/inapp.channel.d.ts +41 -0
  16. package/dist/channel/channels/inapp.channel.d.ts.map +1 -0
  17. package/dist/channel/channels/inapp.channel.js +308 -0
  18. package/dist/channel/channels/inapp.channel.js.map +1 -0
  19. package/dist/channel/channels/index.d.ts +11 -0
  20. package/dist/channel/channels/index.d.ts.map +1 -0
  21. package/dist/channel/channels/index.js +6 -0
  22. package/dist/channel/channels/index.js.map +1 -0
  23. package/dist/channel/channels/push.channel.d.ts +51 -0
  24. package/dist/channel/channels/push.channel.d.ts.map +1 -0
  25. package/dist/channel/channels/push.channel.js +179 -0
  26. package/dist/channel/channels/push.channel.js.map +1 -0
  27. package/dist/channel/channels/sms.channel.d.ts +45 -0
  28. package/dist/channel/channels/sms.channel.d.ts.map +1 -0
  29. package/dist/channel/channels/sms.channel.js +170 -0
  30. package/dist/channel/channels/sms.channel.js.map +1 -0
  31. package/dist/channel/channels/webhook.channel.d.ts +39 -0
  32. package/dist/channel/channels/webhook.channel.d.ts.map +1 -0
  33. package/dist/channel/channels/webhook.channel.js +217 -0
  34. package/dist/channel/channels/webhook.channel.js.map +1 -0
  35. package/dist/channel/index.d.ts +5 -0
  36. package/dist/channel/index.d.ts.map +1 -0
  37. package/dist/channel/index.js +4 -0
  38. package/dist/channel/index.js.map +1 -0
  39. package/dist/index.d.ts +35 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +17 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/notifications.decorators.d.ts +14 -0
  44. package/dist/notifications.decorators.d.ts.map +1 -0
  45. package/dist/notifications.decorators.js +24 -0
  46. package/dist/notifications.decorators.js.map +1 -0
  47. package/dist/notifications.events.d.ts +83 -0
  48. package/dist/notifications.events.d.ts.map +1 -0
  49. package/dist/notifications.events.js +118 -0
  50. package/dist/notifications.events.js.map +1 -0
  51. package/dist/notifications.health.d.ts +16 -0
  52. package/dist/notifications.health.d.ts.map +1 -0
  53. package/dist/notifications.health.js +63 -0
  54. package/dist/notifications.health.js.map +1 -0
  55. package/dist/notifications.module.d.ts +27 -0
  56. package/dist/notifications.module.d.ts.map +1 -0
  57. package/dist/notifications.module.js +533 -0
  58. package/dist/notifications.module.js.map +1 -0
  59. package/dist/notifications.service.d.ts +43 -0
  60. package/dist/notifications.service.d.ts.map +1 -0
  61. package/dist/notifications.service.js +394 -0
  62. package/dist/notifications.service.js.map +1 -0
  63. package/dist/notifications.tokens.d.ts +31 -0
  64. package/dist/notifications.tokens.d.ts.map +1 -0
  65. package/dist/notifications.tokens.js +14 -0
  66. package/dist/notifications.tokens.js.map +1 -0
  67. package/dist/notifications.types.d.ts +234 -0
  68. package/dist/notifications.types.d.ts.map +1 -0
  69. package/dist/notifications.types.js +2 -0
  70. package/dist/notifications.types.js.map +1 -0
  71. package/dist/publisher.d.ts +35 -0
  72. package/dist/publisher.d.ts.map +1 -0
  73. package/dist/publisher.js +18 -0
  74. package/dist/publisher.js.map +1 -0
  75. package/dist/redis-preference-store.d.ts +68 -0
  76. package/dist/redis-preference-store.d.ts.map +1 -0
  77. package/dist/redis-preference-store.js +291 -0
  78. package/dist/redis-preference-store.js.map +1 -0
  79. package/dist/redis-rate-limiter.d.ts +67 -0
  80. package/dist/redis-rate-limiter.d.ts.map +1 -0
  81. package/dist/redis-rate-limiter.js +270 -0
  82. package/dist/redis-rate-limiter.js.map +1 -0
  83. package/dist/rotif/dlq-manager.d.ts +53 -0
  84. package/dist/rotif/dlq-manager.d.ts.map +1 -0
  85. package/dist/rotif/dlq-manager.js +249 -0
  86. package/dist/rotif/dlq-manager.js.map +1 -0
  87. package/dist/rotif/index.d.ts +7 -0
  88. package/dist/rotif/index.d.ts.map +1 -0
  89. package/dist/rotif/index.js +7 -0
  90. package/dist/rotif/index.js.map +1 -0
  91. package/dist/rotif/middleware.d.ts +22 -0
  92. package/dist/rotif/middleware.d.ts.map +1 -0
  93. package/dist/rotif/middleware.js +39 -0
  94. package/dist/rotif/middleware.js.map +1 -0
  95. package/dist/rotif/rotif.d.ts +88 -0
  96. package/dist/rotif/rotif.d.ts.map +1 -0
  97. package/dist/rotif/rotif.js +948 -0
  98. package/dist/rotif/rotif.js.map +1 -0
  99. package/dist/rotif/stats.d.ts +12 -0
  100. package/dist/rotif/stats.d.ts.map +1 -0
  101. package/dist/rotif/stats.js +27 -0
  102. package/dist/rotif/stats.js.map +1 -0
  103. package/dist/rotif/types.d.ts +92 -0
  104. package/dist/rotif/types.d.ts.map +1 -0
  105. package/dist/rotif/types.js +2 -0
  106. package/dist/rotif/types.js.map +1 -0
  107. package/dist/rotif/utils.d.ts +40 -0
  108. package/dist/rotif/utils.d.ts.map +1 -0
  109. package/dist/rotif/utils.js +156 -0
  110. package/dist/rotif/utils.js.map +1 -0
  111. package/dist/template-engine.d.ts +97 -0
  112. package/dist/template-engine.d.ts.map +1 -0
  113. package/dist/template-engine.js +290 -0
  114. package/dist/template-engine.js.map +1 -0
  115. package/dist/transport/index.d.ts +4 -0
  116. package/dist/transport/index.d.ts.map +1 -0
  117. package/dist/transport/index.js +3 -0
  118. package/dist/transport/index.js.map +1 -0
  119. package/dist/transport/rotif.transport.d.ts +29 -0
  120. package/dist/transport/rotif.transport.d.ts.map +1 -0
  121. package/dist/transport/rotif.transport.js +301 -0
  122. package/dist/transport/rotif.transport.js.map +1 -0
  123. package/dist/transport/transport.interface.d.ts +130 -0
  124. package/dist/transport/transport.interface.d.ts.map +1 -0
  125. package/dist/transport/transport.interface.js +8 -0
  126. package/dist/transport/transport.interface.js.map +1 -0
  127. package/dist/worker/index.d.ts +4 -0
  128. package/dist/worker/index.d.ts.map +1 -0
  129. package/dist/worker/index.js +3 -0
  130. package/dist/worker/index.js.map +1 -0
  131. package/dist/worker/notification-worker.d.ts +41 -0
  132. package/dist/worker/notification-worker.d.ts.map +1 -0
  133. package/dist/worker/notification-worker.js +229 -0
  134. package/dist/worker/notification-worker.js.map +1 -0
  135. package/dist/worker/worker.interfaces.d.ts +41 -0
  136. package/dist/worker/worker.interfaces.d.ts.map +1 -0
  137. package/dist/worker/worker.interfaces.js +2 -0
  138. package/dist/worker/worker.interfaces.js.map +1 -0
  139. package/dist/worker/worker.tokens.d.ts +6 -0
  140. package/dist/worker/worker.tokens.d.ts.map +1 -0
  141. package/dist/worker/worker.tokens.js +5 -0
  142. package/dist/worker/worker.tokens.js.map +1 -0
  143. package/lua/rotif/ack-message.lua +19 -0
  144. package/lua/rotif/move-scheduled-messages.lua +38 -0
  145. package/lua/rotif/move-to-dlq.lua +41 -0
  146. package/lua/rotif/publish-message.lua +89 -0
  147. package/lua/rotif/requeue-from-dlq.lua +40 -0
  148. package/lua/rotif/retry-message.lua +49 -0
  149. package/lua/rotif/safe-unsubscribe.lua +8 -0
  150. package/package.json +67 -0
@@ -0,0 +1,41 @@
1
+ -- KEYS[1]: Stream key
2
+ -- KEYS[2]: DLQ Stream key (rotif:dlq)
3
+ -- ARGV[1]: Consumer Group
4
+ -- ARGV[2]: Message ID
5
+ -- ARGV[3]: Channel
6
+ -- ARGV[4]: Payload JSON
7
+ -- ARGV[5]: Error message
8
+ -- ARGV[6]: Original timestamp
9
+ -- ARGV[7]: Attempt count
10
+ -- ARGV[8]: exactlyOnce (optional)
11
+ -- ARGV[9]: dedupTTL (optional)
12
+
13
+ local streamKey = KEYS[1]
14
+ local dlqKey = KEYS[2]
15
+
16
+ local consumerGroup = ARGV[1]
17
+ local messageId = ARGV[2]
18
+ local channel = ARGV[3]
19
+ local payload = ARGV[4]
20
+ local errorMessage = ARGV[5]
21
+ local originalTimestamp = ARGV[6]
22
+ local attemptCount = ARGV[7]
23
+ local exactlyOnce = ARGV[8] or "false"
24
+ local dedupTTL = ARGV[9] or "3600"
25
+
26
+ -- Acknowledge the original message
27
+ redis.call("XACK", streamKey, consumerGroup, messageId)
28
+
29
+ -- Move message to DLQ with all fields
30
+ redis.call("XADD", dlqKey, "*",
31
+ "channel", channel,
32
+ "payload", payload,
33
+ "error", errorMessage,
34
+ "timestamp", originalTimestamp,
35
+ "attempt", attemptCount,
36
+ "streamKey", streamKey,
37
+ "exactlyOnce", exactlyOnce,
38
+ "dedupTTL", dedupTTL
39
+ )
40
+
41
+ return "MOVED_TO_DLQ"
@@ -0,0 +1,89 @@
1
+ -- KEYS[1]: Stream key
2
+ -- KEYS[2]: Sorted Set key for delayed messages
3
+ -- ARGV[1]: payload
4
+ -- ARGV[2]: Timestamp
5
+ -- ARGV[3]: Channel name
6
+ -- ARGV[4]: Attempt count
7
+ -- ARGV[5]: Delivery type ("normal" или "delayed")
8
+ -- ARGV[6]: Delay timestamp (если delayed) или "0"
9
+ -- ARGV[7]: Max stream length (или "0" если нет ограничения)
10
+ -- ARGV[8]: Min stream ID (или "" если нет ограничения)
11
+ -- ARGV[9]: Deduplication key ("" если не используется)
12
+ -- ARGV[10]: Deduplication TTL (seconds, "0" если не используется)
13
+ -- ARGV[11]: Message ID (для надёжного удаления)
14
+ -- ARGV[12]: Exactly once (true/false)
15
+ -- ARGV[13]: Pattern (for deduplication key consistency)
16
+
17
+ local streamKey = KEYS[1]
18
+ local delayedSetKey = KEYS[2]
19
+ local payload = ARGV[1]
20
+ local timestamp = ARGV[2]
21
+ local channel = ARGV[3]
22
+ local attempt = ARGV[4]
23
+ local deliveryType = ARGV[5]
24
+ local delayTimestamp = tonumber(ARGV[6])
25
+ local maxStreamLength = tonumber(ARGV[7])
26
+ local minStreamId = ARGV[8]
27
+ local dedupKey = ARGV[9]
28
+ local dedupTTL = tonumber(ARGV[10])
29
+ local messageUUID = ARGV[11]
30
+ local exactlyOnce = ARGV[12]
31
+ local pattern = ARGV[13]
32
+
33
+ -- Input validation
34
+ if not channel or channel == "" then
35
+ return redis.error_reply("Channel is required")
36
+ end
37
+ if not payload then
38
+ return redis.error_reply("Payload is required")
39
+ end
40
+
41
+ if dedupKey ~= "" and redis.call("EXISTS", dedupKey) == 1 then
42
+ return "DUPLICATE"
43
+ end
44
+
45
+ redis.call('ZADD', 'rotif:channels', 0, channel)
46
+
47
+ if deliveryType == "delayed" then
48
+ local delayedMessage = cjson.encode({
49
+ streamKey = streamKey,
50
+ channel = channel,
51
+ payload = payload,
52
+ timestamp = timestamp,
53
+ attempt = attempt,
54
+ exactlyOnce = exactlyOnce,
55
+ dedupTTL = ARGV[10],
56
+ pattern = pattern
57
+ })
58
+
59
+ redis.call("ZADD", delayedSetKey, delayTimestamp, messageUUID)
60
+ redis.call("SET", "rotif:delayed:" .. messageUUID, delayedMessage)
61
+
62
+ if dedupKey ~= "" and dedupTTL > 0 then
63
+ redis.call("SET", dedupKey, "1", "EX", dedupTTL)
64
+ end
65
+
66
+ return "SCHEDULED"
67
+ else
68
+ local id = redis.call("XADD", streamKey, "*",
69
+ "channel", channel,
70
+ "payload", payload,
71
+ "timestamp", timestamp,
72
+ "attempt", attempt,
73
+ "exactlyOnce", exactlyOnce,
74
+ "dedupTTL", ARGV[10],
75
+ "pattern", pattern
76
+ )
77
+
78
+ if maxStreamLength > 0 then
79
+ redis.call("XTRIM", streamKey, "MAXLEN", "~", maxStreamLength)
80
+ elseif minStreamId ~= "" then
81
+ redis.call("XTRIM", streamKey, "MINID", "~", minStreamId)
82
+ end
83
+
84
+ if dedupKey ~= "" and dedupTTL > 0 then
85
+ redis.call("SET", dedupKey, "1", "EX", dedupTTL)
86
+ end
87
+
88
+ return id
89
+ end
@@ -0,0 +1,40 @@
1
+ -- KEYS[1]: DLQ stream key (rotif:dlq)
2
+ -- ARGV[1]: Maximum number of messages to requeue
3
+
4
+ local dlqKey = KEYS[1]
5
+ local count = tonumber(ARGV[1])
6
+
7
+ local entries = redis.call('XRANGE', dlqKey, '-', '+', 'COUNT', count)
8
+ local requeued = 0
9
+
10
+ for _, entry in ipairs(entries) do
11
+ local id = entry[1]
12
+ local fields = entry[2]
13
+
14
+ local channel, payload, timestamp, streamKey
15
+ for i = 1, #fields, 2 do
16
+ if fields[i] == 'channel' then
17
+ channel = fields[i+1]
18
+ elseif fields[i] == 'payload' then
19
+ payload = fields[i+1]
20
+ elseif fields[i] == 'timestamp' then
21
+ timestamp = fields[i+1]
22
+ elseif fields[i] == 'streamKey' then
23
+ streamKey = fields[i+1]
24
+ end
25
+ end
26
+
27
+ if channel and payload and streamKey and streamKey ~= "" then
28
+ redis.call('XADD', streamKey, '*',
29
+ 'channel', channel,
30
+ 'payload', payload,
31
+ 'timestamp', timestamp or tostring(redis.call('TIME')[1] * 1000),
32
+ 'attempt', '1'
33
+ )
34
+
35
+ redis.call('XDEL', dlqKey, id)
36
+ requeued = requeued + 1
37
+ end
38
+ end
39
+
40
+ return requeued
@@ -0,0 +1,49 @@
1
+ -- KEYS[1]: Current stream key (to ACK from)
2
+ -- KEYS[2]: Sorted Set key for delayed messages
3
+ -- ARGV[1]: Consumer Group
4
+ -- ARGV[2]: Message ID to ACK
5
+ -- ARGV[3]: Channel name
6
+ -- ARGV[4]: Payload
7
+ -- ARGV[5]: Original Timestamp
8
+ -- ARGV[6]: Next Attempt (number)
9
+ -- ARGV[7]: Delay timestamp (retry delay)
10
+ -- ARGV[8]: New Message UUID
11
+ -- ARGV[9]: exactlyOnce flag
12
+ -- ARGV[10]: dedupTTL
13
+ -- ARGV[11]: Retry stream key (where retry will be sent)
14
+ -- ARGV[12]: Pattern (for deduplication consistency)
15
+
16
+ local currentStreamKey = KEYS[1]
17
+ local delayedSetKey = KEYS[2]
18
+
19
+ local consumerGroup = ARGV[1]
20
+ local messageId = ARGV[2]
21
+ local channel = ARGV[3]
22
+ local payload = ARGV[4]
23
+ local originalTimestamp = ARGV[5]
24
+ local attempt = ARGV[6]
25
+ local delayTimestamp = tonumber(ARGV[7])
26
+ local messageUUID = ARGV[8]
27
+ local exactlyOnce = ARGV[9]
28
+ local dedupTTL = ARGV[10]
29
+ local retryStreamKey = ARGV[11]
30
+ local pattern = ARGV[12]
31
+
32
+ redis.call("ZADD", delayedSetKey, delayTimestamp, messageUUID)
33
+
34
+ local delayedMessage = cjson.encode({
35
+ streamKey = retryStreamKey,
36
+ channel = channel,
37
+ payload = payload,
38
+ timestamp = originalTimestamp,
39
+ attempt = attempt,
40
+ exactlyOnce = exactlyOnce,
41
+ dedupTTL = dedupTTL,
42
+ pattern = pattern
43
+ })
44
+
45
+ redis.call("SET", "rotif:delayed:" .. messageUUID, delayedMessage)
46
+
47
+ redis.call("XACK", currentStreamKey, consumerGroup, messageId)
48
+
49
+ return "RETRIED"
@@ -0,0 +1,8 @@
1
+ -- KEYS[1]: patterns ZSET key
2
+ -- ARGV[1]: pattern
3
+ local count = redis.call("ZINCRBY", KEYS[1], -1, ARGV[1])
4
+ if tonumber(count) <= 0 then
5
+ redis.call("ZREM", KEYS[1], ARGV[1])
6
+ return 0
7
+ end
8
+ return count
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@omnitron-dev/titan-notifications",
3
+ "version": "0.1.1",
4
+ "description": "Notifications module for Titan framework with multi-channel delivery, Rotif messaging, and DLQ",
5
+ "author": "LuxQuant",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./rotif": {
16
+ "types": "./dist/rotif/index.d.ts",
17
+ "default": "./dist/rotif/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "lua"
23
+ ],
24
+ "dependencies": {
25
+ "handlebars": "^4.7.8",
26
+ "ioredis": "^5.8.2",
27
+ "minimatch": "^10.1.1",
28
+ "msgpackr": "^1.11.5",
29
+ "@omnitron-dev/common": "0.1.1",
30
+ "@omnitron-dev/eventemitter": "0.1.1"
31
+ },
32
+ "peerDependencies": {
33
+ "nodemailer": ">=6.0.0",
34
+ "twilio": ">=4.0.0",
35
+ "firebase-admin": ">=12.0.0",
36
+ "amqplib": ">=0.10.0",
37
+ "@omnitron-dev/titan": "0.1.1",
38
+ "@omnitron-dev/titan-events": "0.1.1",
39
+ "@omnitron-dev/titan-redis": "0.1.1"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "nodemailer": {
43
+ "optional": true
44
+ },
45
+ "twilio": {
46
+ "optional": true
47
+ },
48
+ "firebase-admin": {
49
+ "optional": true
50
+ },
51
+ "amqplib": {
52
+ "optional": true
53
+ }
54
+ },
55
+ "devDependencies": {
56
+ "@types/node": "25.0.3",
57
+ "reflect-metadata": "^0.2.2",
58
+ "typescript": "^5.9.3",
59
+ "vitest": "^4.1.0"
60
+ },
61
+ "scripts": {
62
+ "build": "rm -rf dist node_modules/.tmp && tsc -p ./tsconfig.json",
63
+ "test": "vitest run",
64
+ "clean": "rm -rf dist",
65
+ "typecheck": "tsc --noEmit"
66
+ }
67
+ }