nesthub 1.0.0

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 (143) hide show
  1. package/README.md +108 -0
  2. package/dist/cache/README.md +91 -0
  3. package/dist/cache/index.d.ts +10 -0
  4. package/dist/cache/index.js +75 -0
  5. package/dist/cache/index.js.map +1 -0
  6. package/dist/cache/index.spec.d.ts +1 -0
  7. package/dist/cache/index.spec.js +61 -0
  8. package/dist/cache/index.spec.js.map +1 -0
  9. package/dist/excel/README.md +132 -0
  10. package/dist/excel/excel.module.d.ts +2 -0
  11. package/dist/excel/excel.module.js +21 -0
  12. package/dist/excel/excel.module.js.map +1 -0
  13. package/dist/excel/excel.service.d.ts +23 -0
  14. package/dist/excel/excel.service.js +124 -0
  15. package/dist/excel/excel.service.js.map +1 -0
  16. package/dist/excel/index.d.ts +2 -0
  17. package/dist/excel/index.js +8 -0
  18. package/dist/excel/index.js.map +1 -0
  19. package/dist/excel/interfaces.d.ts +19 -0
  20. package/dist/excel/interfaces.js +3 -0
  21. package/dist/excel/interfaces.js.map +1 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +5 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/index.spec.d.ts +1 -0
  26. package/dist/index.spec.js +11 -0
  27. package/dist/index.spec.js.map +1 -0
  28. package/dist/notification/README.md +237 -0
  29. package/dist/notification/channels/channel.interface.d.ts +10 -0
  30. package/dist/notification/channels/channel.interface.js +3 -0
  31. package/dist/notification/channels/channel.interface.js.map +1 -0
  32. package/dist/notification/channels/email.channel.d.ts +11 -0
  33. package/dist/notification/channels/email.channel.js +58 -0
  34. package/dist/notification/channels/email.channel.js.map +1 -0
  35. package/dist/notification/channels/firebase.channel.d.ts +11 -0
  36. package/dist/notification/channels/firebase.channel.js +69 -0
  37. package/dist/notification/channels/firebase.channel.js.map +1 -0
  38. package/dist/notification/channels/index.d.ts +5 -0
  39. package/dist/notification/channels/index.js +12 -0
  40. package/dist/notification/channels/index.js.map +1 -0
  41. package/dist/notification/channels/sms.channel.d.ts +8 -0
  42. package/dist/notification/channels/sms.channel.js +90 -0
  43. package/dist/notification/channels/sms.channel.js.map +1 -0
  44. package/dist/notification/channels/telegram.channel.d.ts +10 -0
  45. package/dist/notification/channels/telegram.channel.js +59 -0
  46. package/dist/notification/channels/telegram.channel.js.map +1 -0
  47. package/dist/notification/email/index.d.ts +62 -0
  48. package/dist/notification/email/index.js +253 -0
  49. package/dist/notification/email/index.js.map +1 -0
  50. package/dist/notification/email/index.spec.d.ts +1 -0
  51. package/dist/notification/email/index.spec.js +121 -0
  52. package/dist/notification/email/index.spec.js.map +1 -0
  53. package/dist/notification/entities/notification-log.entity.d.ts +15 -0
  54. package/dist/notification/entities/notification-log.entity.js +82 -0
  55. package/dist/notification/entities/notification-log.entity.js.map +1 -0
  56. package/dist/notification/firebase/index.d.ts +52 -0
  57. package/dist/notification/firebase/index.js +261 -0
  58. package/dist/notification/firebase/index.js.map +1 -0
  59. package/dist/notification/firebase/index.spec.d.ts +1 -0
  60. package/dist/notification/firebase/index.spec.js +114 -0
  61. package/dist/notification/firebase/index.spec.js.map +1 -0
  62. package/dist/notification/index.d.ts +12 -0
  63. package/dist/notification/index.js +26 -0
  64. package/dist/notification/index.js.map +1 -0
  65. package/dist/notification/index.spec.d.ts +1 -0
  66. package/dist/notification/index.spec.js +336 -0
  67. package/dist/notification/index.spec.js.map +1 -0
  68. package/dist/notification/interfaces.d.ts +98 -0
  69. package/dist/notification/interfaces.js +3 -0
  70. package/dist/notification/interfaces.js.map +1 -0
  71. package/dist/notification/notification.constants.d.ts +4 -0
  72. package/dist/notification/notification.constants.js +8 -0
  73. package/dist/notification/notification.constants.js.map +1 -0
  74. package/dist/notification/notification.module.d.ts +10 -0
  75. package/dist/notification/notification.module.js +160 -0
  76. package/dist/notification/notification.module.js.map +1 -0
  77. package/dist/notification/notification.service.d.ts +14 -0
  78. package/dist/notification/notification.service.js +184 -0
  79. package/dist/notification/notification.service.js.map +1 -0
  80. package/dist/notification/queue/index.d.ts +2 -0
  81. package/dist/notification/queue/index.js +6 -0
  82. package/dist/notification/queue/index.js.map +1 -0
  83. package/dist/notification/queue/notification-queue.service.d.ts +31 -0
  84. package/dist/notification/queue/notification-queue.service.js +134 -0
  85. package/dist/notification/queue/notification-queue.service.js.map +1 -0
  86. package/dist/notification/services/index.d.ts +1 -0
  87. package/dist/notification/services/index.js +6 -0
  88. package/dist/notification/services/index.js.map +1 -0
  89. package/dist/notification/services/template.service.d.ts +13 -0
  90. package/dist/notification/services/template.service.js +75 -0
  91. package/dist/notification/services/template.service.js.map +1 -0
  92. package/dist/notification/shared.d.ts +48 -0
  93. package/dist/notification/shared.js +95 -0
  94. package/dist/notification/shared.js.map +1 -0
  95. package/dist/notification/sms/index.d.ts +52 -0
  96. package/dist/notification/sms/index.js +234 -0
  97. package/dist/notification/sms/index.js.map +1 -0
  98. package/dist/notification/sms/index.spec.d.ts +1 -0
  99. package/dist/notification/sms/index.spec.js +123 -0
  100. package/dist/notification/sms/index.spec.js.map +1 -0
  101. package/dist/notification/telegram/index.d.ts +50 -0
  102. package/dist/notification/telegram/index.js +248 -0
  103. package/dist/notification/telegram/index.js.map +1 -0
  104. package/dist/notification/telegram/index.spec.d.ts +1 -0
  105. package/dist/notification/telegram/index.spec.js +108 -0
  106. package/dist/notification/telegram/index.spec.js.map +1 -0
  107. package/dist/notification/typeorm-storage.d.ts +28 -0
  108. package/dist/notification/typeorm-storage.js +56 -0
  109. package/dist/notification/typeorm-storage.js.map +1 -0
  110. package/dist/notification/unified.d.ts +47 -0
  111. package/dist/notification/unified.js +207 -0
  112. package/dist/notification/unified.js.map +1 -0
  113. package/dist/queue/README.md +82 -0
  114. package/dist/queue/index.d.ts +14 -0
  115. package/dist/queue/index.js +17 -0
  116. package/dist/queue/index.js.map +1 -0
  117. package/dist/queue/index.spec.d.ts +1 -0
  118. package/dist/queue/index.spec.js +76 -0
  119. package/dist/queue/index.spec.js.map +1 -0
  120. package/dist/tsconfig.build.tsbuildinfo +1 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -0
  122. package/dist/typeorm/README.md +197 -0
  123. package/dist/typeorm/crud-controller.d.ts +4 -0
  124. package/dist/typeorm/crud-controller.js +81 -0
  125. package/dist/typeorm/crud-controller.js.map +1 -0
  126. package/dist/typeorm/crud-service.d.ts +6 -0
  127. package/dist/typeorm/crud-service.js +53 -0
  128. package/dist/typeorm/crud-service.js.map +1 -0
  129. package/dist/typeorm/crud.interface.d.ts +9 -0
  130. package/dist/typeorm/crud.interface.js +3 -0
  131. package/dist/typeorm/crud.interface.js.map +1 -0
  132. package/dist/typeorm/index.d.ts +23 -0
  133. package/dist/typeorm/index.js +66 -0
  134. package/dist/typeorm/index.js.map +1 -0
  135. package/dist/typeorm/index.spec.d.ts +1 -0
  136. package/dist/typeorm/index.spec.js +109 -0
  137. package/dist/typeorm/index.spec.js.map +1 -0
  138. package/package.json +229 -0
  139. package/src/cache/README.md +91 -0
  140. package/src/excel/README.md +132 -0
  141. package/src/notification/README.md +237 -0
  142. package/src/queue/README.md +82 -0
  143. package/src/typeorm/README.md +197 -0
@@ -0,0 +1,248 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var TelegramModule_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.TelegramModule = exports.TELEGRAM_SERVICE = void 0;
17
+ const common_1 = require("@nestjs/common");
18
+ const shared_1 = require("../shared");
19
+ const typeorm_storage_1 = require("../typeorm-storage");
20
+ exports.TELEGRAM_SERVICE = 'TELEGRAM_SERVICE';
21
+ const TELEGRAM_API = 'https://api.telegram.org/bot';
22
+ let TelegramServiceImpl = class TelegramServiceImpl {
23
+ options;
24
+ injectedStorage;
25
+ templateService = new shared_1.TemplateService();
26
+ queueClient;
27
+ workerClient;
28
+ storage;
29
+ apiBase;
30
+ constructor(options, injectedStorage) {
31
+ this.options = options;
32
+ this.injectedStorage = injectedStorage;
33
+ this.storage =
34
+ injectedStorage ??
35
+ options.storage?.provider ??
36
+ new shared_1.ConsoleNotificationStorage();
37
+ this.apiBase = `${TELEGRAM_API}${options.botToken}`;
38
+ }
39
+ async onModuleInit() {
40
+ const { templates, queue } = this.options;
41
+ if (templates?.dir)
42
+ await this.templateService.loadFromDir(templates.dir);
43
+ if (templates?.templates)
44
+ this.templateService.loadFromRecord(templates.templates);
45
+ if (queue?.useQueue && queue?.connection?.url) {
46
+ try {
47
+ const bullmqModule = (await (0, shared_1.dynamicImport)('bullmq'));
48
+ const queueName = queue.prefix ?? 'telegram-notifications';
49
+ this.queueClient = new bullmqModule.Queue(queueName, {
50
+ connection: { url: queue.connection.url },
51
+ defaultJobOptions: queue.defaultJobOptions,
52
+ });
53
+ if (queue.worker !== false) {
54
+ this.workerClient = new bullmqModule.Worker(queueName, async (job) => this.processQueuedJob(job), {
55
+ connection: { url: queue.connection.url },
56
+ concurrency: queue.concurrency ?? 1,
57
+ });
58
+ }
59
+ }
60
+ catch {
61
+ console.warn('[TelegramModule] bullmq not installed. Queue mode disabled.');
62
+ }
63
+ }
64
+ }
65
+ async onModuleDestroy() {
66
+ await this.workerClient?.close();
67
+ await this.queueClient?.close();
68
+ }
69
+ async sendTelegram(options) {
70
+ if ((options.mode ?? 'direct') === 'queue' && this.queueClient) {
71
+ return this.enqueue(options);
72
+ }
73
+ return this.sendNow(options);
74
+ }
75
+ async cancelJob(dedupId) {
76
+ if (!this.queueClient)
77
+ return;
78
+ const record = await this.storage.findByDedupId(dedupId);
79
+ if (!record || record.status !== 'pending')
80
+ return;
81
+ try {
82
+ await this.queueClient.remove(record.id);
83
+ }
84
+ catch {
85
+ }
86
+ await this.storage.update(record.id, { status: 'cancelled' });
87
+ }
88
+ async processQueuedJob(job) {
89
+ const { data } = job;
90
+ if (data.expiresAt && new Date(data.expiresAt) < new Date()) {
91
+ await this.storage.update(job.id, {
92
+ status: 'expired',
93
+ error: 'Expired before processing',
94
+ });
95
+ return;
96
+ }
97
+ if (data.dedupId) {
98
+ const record = await this.storage.findByDedupId(data.dedupId);
99
+ if (record &&
100
+ (record.status === 'cancelled' || record.status === 'expired'))
101
+ return;
102
+ }
103
+ const result = await this.sendNow(data);
104
+ await this.storage.update(job.id, {
105
+ status: result.success ? 'sent' : 'failed',
106
+ messageId: result.messageId,
107
+ error: result.error,
108
+ sentAt: new Date().toISOString(),
109
+ });
110
+ }
111
+ async sendNow(options) {
112
+ try {
113
+ const { chatId, text, parseMode, disableWebPagePreview, disableNotification, replyToMessageId, template, context = {}, locale, } = options;
114
+ const resolvedLocale = locale ?? this.options.defaultLocale ?? 'en';
115
+ const ctx = { ...context, locale: resolvedLocale };
116
+ let resolvedText = text;
117
+ if (template) {
118
+ const tmplName = this.templateService.resolveName(template, resolvedLocale);
119
+ if (!resolvedText) {
120
+ resolvedText =
121
+ this.templateService.render(tmplName, ctx) ||
122
+ this.templateService.render(`body:${tmplName}`, ctx);
123
+ }
124
+ }
125
+ if (!resolvedText) {
126
+ return { success: false, error: 'No content to send' };
127
+ }
128
+ const payload = {
129
+ chat_id: chatId,
130
+ text: resolvedText,
131
+ };
132
+ if (parseMode)
133
+ payload.parse_mode = parseMode;
134
+ if (disableWebPagePreview)
135
+ payload.disable_web_page_preview = true;
136
+ if (disableNotification)
137
+ payload.disable_notification = true;
138
+ if (replyToMessageId)
139
+ payload.reply_to_message_id = replyToMessageId;
140
+ const response = await fetch(`${this.apiBase}/sendMessage`, {
141
+ method: 'POST',
142
+ headers: { 'Content-Type': 'application/json' },
143
+ body: JSON.stringify(payload),
144
+ });
145
+ if (!response.ok) {
146
+ const errorText = await response.text();
147
+ return {
148
+ success: false,
149
+ error: `Telegram API error ${response.status}: ${errorText}`,
150
+ };
151
+ }
152
+ const data = (await response.json());
153
+ if (!data.ok) {
154
+ return { success: false, error: 'Telegram API returned ok: false' };
155
+ }
156
+ return {
157
+ success: true,
158
+ messageId: String(data.result?.message_id ?? ''),
159
+ };
160
+ }
161
+ catch (error) {
162
+ const message = error instanceof Error ? error.message : 'Unknown error';
163
+ return { success: false, error: message };
164
+ }
165
+ }
166
+ async enqueue(options) {
167
+ try {
168
+ const jobOpts = {};
169
+ if (options.dedupId)
170
+ jobOpts.deduplication = { id: options.dedupId };
171
+ const job = await this.queueClient.add('send-telegram', options, jobOpts);
172
+ await this.storage.save({
173
+ id: job.id ?? '',
174
+ to: String(options.chatId),
175
+ template: options.template,
176
+ channel: 'telegram',
177
+ status: 'pending',
178
+ expiresAt: options.expiresAt
179
+ ? new Date(options.expiresAt).toISOString()
180
+ : undefined,
181
+ dedupId: options.dedupId,
182
+ createdAt: new Date().toISOString(),
183
+ });
184
+ return { success: true, messageId: job.id, jobId: job.id };
185
+ }
186
+ catch (error) {
187
+ const message = error instanceof Error ? error.message : 'Unknown error';
188
+ return { success: false, error: message };
189
+ }
190
+ }
191
+ };
192
+ TelegramServiceImpl = __decorate([
193
+ (0, common_1.Injectable)(),
194
+ __param(0, (0, common_1.Inject)('TELEGRAM_MODULE_OPTIONS')),
195
+ __param(1, (0, common_1.Optional)()),
196
+ __param(1, (0, common_1.Inject)(shared_1.NOTIFICATION_STORAGE)),
197
+ __metadata("design:paramtypes", [Object, Object])
198
+ ], TelegramServiceImpl);
199
+ let TelegramModule = TelegramModule_1 = class TelegramModule {
200
+ static forRoot(options) {
201
+ const providers = [
202
+ { provide: 'TELEGRAM_MODULE_OPTIONS', useValue: options },
203
+ { provide: exports.TELEGRAM_SERVICE, useClass: TelegramServiceImpl },
204
+ ];
205
+ const imports = [];
206
+ if (options.storage?.typeorm) {
207
+ try {
208
+ const { TypeOrmModule, getRepositoryToken } = (0, typeorm_storage_1.getTypeOrmHelpers)();
209
+ const entity = (0, typeorm_storage_1.getOrCreateEntity)();
210
+ imports.push(TypeOrmModule.forFeature([entity]));
211
+ providers.push({
212
+ provide: shared_1.NOTIFICATION_STORAGE,
213
+ useFactory: (repo) => new typeorm_storage_1.TypeOrmNotificationStorage(repo),
214
+ inject: [getRepositoryToken(entity)],
215
+ });
216
+ }
217
+ catch {
218
+ throw new Error('TelegramModule: @nestjs/typeorm and typeorm must be installed when storage.typeorm is true');
219
+ }
220
+ }
221
+ return {
222
+ module: TelegramModule_1,
223
+ imports,
224
+ providers,
225
+ exports: [exports.TELEGRAM_SERVICE],
226
+ };
227
+ }
228
+ static forRootAsync(options) {
229
+ return {
230
+ module: TelegramModule_1,
231
+ providers: [
232
+ {
233
+ provide: 'TELEGRAM_MODULE_OPTIONS',
234
+ useFactory: options.useFactory,
235
+ inject: options.inject ?? [],
236
+ },
237
+ { provide: exports.TELEGRAM_SERVICE, useClass: TelegramServiceImpl },
238
+ ],
239
+ exports: [exports.TELEGRAM_SERVICE],
240
+ };
241
+ }
242
+ };
243
+ exports.TelegramModule = TelegramModule;
244
+ exports.TelegramModule = TelegramModule = TelegramModule_1 = __decorate([
245
+ (0, common_1.Global)(),
246
+ (0, common_1.Module)({})
247
+ ], TelegramModule);
248
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/notification/telegram/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAMA,2CAQwB;AAOxB,sCAKmB;AACnB,wDAK4B;AAEf,QAAA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E;iBAC7B;gBACD,EAAE,OAAO,EAAE,wBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE;aAC7D;YACD,OAAO,EAAE,CAAC,wBAAgB,CAAC;SAC5B,CAAC;IACJ,CAAC;CACF,CAAA;AArDY,wCAAc;yBAAd,cAAc;IAF1B,IAAA,eAAM,GAAE;IACR,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,cAAc,CAqD1B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ let nextJobId = 1;
4
+ jest.mock('bullmq', () => ({
5
+ Queue: jest.fn().mockImplementation(() => ({
6
+ add: jest
7
+ .fn()
8
+ .mockImplementation(() => Promise.resolve({ id: `tg-job-${nextJobId++}` })),
9
+ remove: jest.fn().mockResolvedValue(undefined),
10
+ close: jest.fn().mockResolvedValue(undefined),
11
+ })),
12
+ Worker: jest.fn().mockImplementation(() => ({
13
+ close: jest.fn().mockResolvedValue(undefined),
14
+ })),
15
+ }));
16
+ const testing_1 = require("@nestjs/testing");
17
+ const index_1 = require("./index");
18
+ describe('@vn.chemgio/nestjs-utilities/notification/telegram', () => {
19
+ let service;
20
+ let module;
21
+ afterEach(async () => {
22
+ if (module)
23
+ await module.close();
24
+ });
25
+ it('should return no-content error', async () => {
26
+ module = await testing_1.Test.createTestingModule({
27
+ imports: [index_1.TelegramModule.forRoot({ botToken: 'test-token' })],
28
+ }).compile();
29
+ await module.init();
30
+ service = module.get(index_1.TELEGRAM_SERVICE);
31
+ const result = await service.sendTelegram({ chatId: 12345 });
32
+ expect(result.success).toBe(false);
33
+ expect(result.error).toBe('No content to send');
34
+ });
35
+ it('should render handlebars template for body', async () => {
36
+ module = await testing_1.Test.createTestingModule({
37
+ imports: [
38
+ index_1.TelegramModule.forRoot({
39
+ botToken: 'test-token',
40
+ templates: {
41
+ templates: {
42
+ alert: { body: 'Alert: {{message}}' },
43
+ },
44
+ },
45
+ }),
46
+ ],
47
+ }).compile();
48
+ await module.init();
49
+ service = module.get(index_1.TELEGRAM_SERVICE);
50
+ try {
51
+ await service.sendTelegram({
52
+ chatId: 12345,
53
+ template: 'alert',
54
+ context: { message: 'Server down' },
55
+ });
56
+ }
57
+ catch {
58
+ }
59
+ });
60
+ it('should queue message and save pending record', async () => {
61
+ module = await testing_1.Test.createTestingModule({
62
+ imports: [
63
+ index_1.TelegramModule.forRoot({
64
+ botToken: 'test-token',
65
+ queue: {
66
+ useQueue: true,
67
+ connection: { url: 'redis://localhost:6379' },
68
+ worker: false,
69
+ },
70
+ }),
71
+ ],
72
+ }).compile();
73
+ await module.init();
74
+ service = module.get(index_1.TELEGRAM_SERVICE);
75
+ const result = await service.sendTelegram({
76
+ chatId: 12345,
77
+ text: 'Queued TG',
78
+ mode: 'queue',
79
+ });
80
+ expect(result.success).toBe(true);
81
+ expect(result.jobId).toMatch(/^tg-job-/);
82
+ });
83
+ it('should cancel a pending job by dedupId', async () => {
84
+ module = await testing_1.Test.createTestingModule({
85
+ imports: [
86
+ index_1.TelegramModule.forRoot({
87
+ botToken: 'test-token',
88
+ queue: {
89
+ useQueue: true,
90
+ connection: { url: 'redis://localhost:6379' },
91
+ worker: false,
92
+ },
93
+ }),
94
+ ],
95
+ }).compile();
96
+ await module.init();
97
+ service = module.get(index_1.TELEGRAM_SERVICE);
98
+ const sendResult = await service.sendTelegram({
99
+ chatId: 12345,
100
+ text: 'Cancel test',
101
+ mode: 'queue',
102
+ dedupId: 'tg-cancel-test',
103
+ });
104
+ expect(sendResult.success).toBe(true);
105
+ await service.cancelJob('tg-cancel-test');
106
+ });
107
+ });
108
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../../../src/notification/telegram/index.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,SAAS,GAAG,CAAC,CAAC;AAClB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EA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AS,CAAC,gBAAgB,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,28 @@
1
+ import type { DynamicModule } from '@nestjs/common';
2
+ import type { NotificationStorage, NotificationRecord } from './shared';
3
+ export type Repo = {
4
+ save(record: NotificationRecord): Promise<NotificationRecord>;
5
+ update(id: string, updates: Partial<NotificationRecord>): Promise<unknown>;
6
+ findOne(opts: {
7
+ where: Record<string, unknown>;
8
+ }): Promise<NotificationRecord | null>;
9
+ };
10
+ export declare class TypeOrmNotificationStorage implements NotificationStorage {
11
+ private readonly repo;
12
+ constructor(repo: Repo);
13
+ save(record: NotificationRecord): Promise<void>;
14
+ update(recordId: string, updates: Partial<NotificationRecord>): Promise<void>;
15
+ findByDedupId(dedupId: string): Promise<NotificationRecord | null>;
16
+ }
17
+ type EntitySchemaInstance = {
18
+ name: string;
19
+ options: Record<string, unknown>;
20
+ };
21
+ export declare function getOrCreateEntity(): EntitySchemaInstance;
22
+ export declare function getTypeOrmHelpers(): {
23
+ TypeOrmModule: {
24
+ forFeature: (entities: unknown[]) => DynamicModule;
25
+ };
26
+ getRepositoryToken: (entity: unknown) => string;
27
+ };
28
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeOrmNotificationStorage = void 0;
4
+ exports.getOrCreateEntity = getOrCreateEntity;
5
+ exports.getTypeOrmHelpers = getTypeOrmHelpers;
6
+ class TypeOrmNotificationStorage {
7
+ repo;
8
+ constructor(repo) {
9
+ this.repo = repo;
10
+ }
11
+ async save(record) {
12
+ await this.repo.save(record);
13
+ }
14
+ async update(recordId, updates) {
15
+ await this.repo.update(recordId, updates);
16
+ }
17
+ async findByDedupId(dedupId) {
18
+ return this.repo.findOne({ where: { dedupId } });
19
+ }
20
+ }
21
+ exports.TypeOrmNotificationStorage = TypeOrmNotificationStorage;
22
+ let _entity = null;
23
+ function getOrCreateEntity() {
24
+ if (_entity)
25
+ return _entity;
26
+ const typeorm = eval('require')('typeorm');
27
+ _entity = new typeorm.EntitySchema({
28
+ name: 'NotificationLog',
29
+ tableName: 'notification_logs',
30
+ columns: {
31
+ id: { primary: true, type: String },
32
+ to: { type: String },
33
+ subject: { type: String, nullable: true },
34
+ body: { type: String, nullable: true },
35
+ template: { type: String, nullable: true },
36
+ channel: { type: String, nullable: true },
37
+ status: { type: String },
38
+ messageId: { type: String, nullable: true },
39
+ error: { type: 'text', nullable: true },
40
+ expiresAt: { type: String, nullable: true },
41
+ dedupId: { type: String, nullable: true },
42
+ createdAt: { type: String },
43
+ sentAt: { type: String, nullable: true },
44
+ },
45
+ indices: [
46
+ { columns: ['dedupId'] },
47
+ { columns: ['status'] },
48
+ { columns: ['channel', 'status'] },
49
+ ],
50
+ });
51
+ return _entity;
52
+ }
53
+ function getTypeOrmHelpers() {
54
+ return eval('require')('@nestjs/typeorm');
55
+ }
56
+ //# sourceMappingURL=typeorm-storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeorm-storage.js","sourceRoot":"","sources":["../../src/notification/typeorm-storage.ts"],"names":[],"mappings":";;;AAqCA,8CA+BC;AAGD,8CAQC;AApED,MAAa,0BAA0B;IACR;IAA7B,YAA6B,IAAU;QAAV,SAAI,GAAJ,IAAI,CAAM;IAAG,CAAC;IAE3C,KAAK,CAAC,IAAI,CAAC,MAA0B;QACnC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,MAAM,CACV,QAAgB,EAChB,OAAoC;QAEpC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAe;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;IACnD,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EAAE,OAAO,EAAE,CAAC,SAAS,CAAC,EAAE;YACxB,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC,EAAE;YACvB,EAAE,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;SACnC;KACF,CAAC,CAAC;IACH,OAAO,OAAO,CAAC;AACjB,CAAC;AAGD,SAAgB,iBAAiB;IAI/B,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,iBAAiB,CAGvC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { DynamicModule, InjectionToken, OptionalFactoryDependency } from '@nestjs/common';
2
+ import type { SendResult, NotificationStorage, NotificationTemplate } from './shared';
3
+ import type { SendEmailOptions, EmailModuleOptions } from './email';
4
+ import type { SendSmsOptions, SmsModuleOptions } from './sms';
5
+ import type { SendPushOptions, FirebaseModuleOptions } from './firebase';
6
+ import type { SendTelegramOptions } from './telegram';
7
+ export declare const NOTIFICATION_SERVICE = "NOTIFICATION_SERVICE";
8
+ export interface INotificationService {
9
+ sendEmail(options: SendEmailOptions): Promise<SendResult>;
10
+ sendSms(options: SendSmsOptions): Promise<SendResult>;
11
+ sendPush(options: SendPushOptions): Promise<SendResult>;
12
+ sendTelegram(options: SendTelegramOptions): Promise<SendResult>;
13
+ cancelJob(dedupId: string): Promise<void>;
14
+ }
15
+ export interface NotificationModuleOptions {
16
+ defaultFrom?: string;
17
+ defaultLocale?: string;
18
+ sendgrid?: EmailModuleOptions['sendgrid'];
19
+ twilio?: SmsModuleOptions['twilio'];
20
+ firebase?: FirebaseModuleOptions['firebase'];
21
+ botToken?: string;
22
+ queue?: {
23
+ useQueue?: boolean;
24
+ connection?: {
25
+ url: string;
26
+ };
27
+ prefix?: string;
28
+ defaultJobOptions?: Record<string, unknown>;
29
+ worker?: boolean;
30
+ concurrency?: number;
31
+ };
32
+ templates?: {
33
+ dir?: string;
34
+ templates?: Record<string, NotificationTemplate>;
35
+ };
36
+ storage?: {
37
+ provider?: NotificationStorage;
38
+ typeorm?: boolean;
39
+ };
40
+ }
41
+ export declare class NotificationModule {
42
+ static forRoot(options?: NotificationModuleOptions): DynamicModule;
43
+ static forRootAsync(options: {
44
+ useFactory: (...args: unknown[]) => NotificationModuleOptions | Promise<NotificationModuleOptions>;
45
+ inject?: (InjectionToken | OptionalFactoryDependency)[];
46
+ }): DynamicModule;
47
+ }