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.
- package/README.md +108 -0
- package/dist/cache/README.md +91 -0
- package/dist/cache/index.d.ts +10 -0
- package/dist/cache/index.js +75 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cache/index.spec.d.ts +1 -0
- package/dist/cache/index.spec.js +61 -0
- package/dist/cache/index.spec.js.map +1 -0
- package/dist/excel/README.md +132 -0
- package/dist/excel/excel.module.d.ts +2 -0
- package/dist/excel/excel.module.js +21 -0
- package/dist/excel/excel.module.js.map +1 -0
- package/dist/excel/excel.service.d.ts +23 -0
- package/dist/excel/excel.service.js +124 -0
- package/dist/excel/excel.service.js.map +1 -0
- package/dist/excel/index.d.ts +2 -0
- package/dist/excel/index.js +8 -0
- package/dist/excel/index.js.map +1 -0
- package/dist/excel/interfaces.d.ts +19 -0
- package/dist/excel/interfaces.js +3 -0
- package/dist/excel/interfaces.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/index.spec.d.ts +1 -0
- package/dist/index.spec.js +11 -0
- package/dist/index.spec.js.map +1 -0
- package/dist/notification/README.md +237 -0
- package/dist/notification/channels/channel.interface.d.ts +10 -0
- package/dist/notification/channels/channel.interface.js +3 -0
- package/dist/notification/channels/channel.interface.js.map +1 -0
- package/dist/notification/channels/email.channel.d.ts +11 -0
- package/dist/notification/channels/email.channel.js +58 -0
- package/dist/notification/channels/email.channel.js.map +1 -0
- package/dist/notification/channels/firebase.channel.d.ts +11 -0
- package/dist/notification/channels/firebase.channel.js +69 -0
- package/dist/notification/channels/firebase.channel.js.map +1 -0
- package/dist/notification/channels/index.d.ts +5 -0
- package/dist/notification/channels/index.js +12 -0
- package/dist/notification/channels/index.js.map +1 -0
- package/dist/notification/channels/sms.channel.d.ts +8 -0
- package/dist/notification/channels/sms.channel.js +90 -0
- package/dist/notification/channels/sms.channel.js.map +1 -0
- package/dist/notification/channels/telegram.channel.d.ts +10 -0
- package/dist/notification/channels/telegram.channel.js +59 -0
- package/dist/notification/channels/telegram.channel.js.map +1 -0
- package/dist/notification/email/index.d.ts +62 -0
- package/dist/notification/email/index.js +253 -0
- package/dist/notification/email/index.js.map +1 -0
- package/dist/notification/email/index.spec.d.ts +1 -0
- package/dist/notification/email/index.spec.js +121 -0
- package/dist/notification/email/index.spec.js.map +1 -0
- package/dist/notification/entities/notification-log.entity.d.ts +15 -0
- package/dist/notification/entities/notification-log.entity.js +82 -0
- package/dist/notification/entities/notification-log.entity.js.map +1 -0
- package/dist/notification/firebase/index.d.ts +52 -0
- package/dist/notification/firebase/index.js +261 -0
- package/dist/notification/firebase/index.js.map +1 -0
- package/dist/notification/firebase/index.spec.d.ts +1 -0
- package/dist/notification/firebase/index.spec.js +114 -0
- package/dist/notification/firebase/index.spec.js.map +1 -0
- package/dist/notification/index.d.ts +12 -0
- package/dist/notification/index.js +26 -0
- package/dist/notification/index.js.map +1 -0
- package/dist/notification/index.spec.d.ts +1 -0
- package/dist/notification/index.spec.js +336 -0
- package/dist/notification/index.spec.js.map +1 -0
- package/dist/notification/interfaces.d.ts +98 -0
- package/dist/notification/interfaces.js +3 -0
- package/dist/notification/interfaces.js.map +1 -0
- package/dist/notification/notification.constants.d.ts +4 -0
- package/dist/notification/notification.constants.js +8 -0
- package/dist/notification/notification.constants.js.map +1 -0
- package/dist/notification/notification.module.d.ts +10 -0
- package/dist/notification/notification.module.js +160 -0
- package/dist/notification/notification.module.js.map +1 -0
- package/dist/notification/notification.service.d.ts +14 -0
- package/dist/notification/notification.service.js +184 -0
- package/dist/notification/notification.service.js.map +1 -0
- package/dist/notification/queue/index.d.ts +2 -0
- package/dist/notification/queue/index.js +6 -0
- package/dist/notification/queue/index.js.map +1 -0
- package/dist/notification/queue/notification-queue.service.d.ts +31 -0
- package/dist/notification/queue/notification-queue.service.js +134 -0
- package/dist/notification/queue/notification-queue.service.js.map +1 -0
- package/dist/notification/services/index.d.ts +1 -0
- package/dist/notification/services/index.js +6 -0
- package/dist/notification/services/index.js.map +1 -0
- package/dist/notification/services/template.service.d.ts +13 -0
- package/dist/notification/services/template.service.js +75 -0
- package/dist/notification/services/template.service.js.map +1 -0
- package/dist/notification/shared.d.ts +48 -0
- package/dist/notification/shared.js +95 -0
- package/dist/notification/shared.js.map +1 -0
- package/dist/notification/sms/index.d.ts +52 -0
- package/dist/notification/sms/index.js +234 -0
- package/dist/notification/sms/index.js.map +1 -0
- package/dist/notification/sms/index.spec.d.ts +1 -0
- package/dist/notification/sms/index.spec.js +123 -0
- package/dist/notification/sms/index.spec.js.map +1 -0
- package/dist/notification/telegram/index.d.ts +50 -0
- package/dist/notification/telegram/index.js +248 -0
- package/dist/notification/telegram/index.js.map +1 -0
- package/dist/notification/telegram/index.spec.d.ts +1 -0
- package/dist/notification/telegram/index.spec.js +108 -0
- package/dist/notification/telegram/index.spec.js.map +1 -0
- package/dist/notification/typeorm-storage.d.ts +28 -0
- package/dist/notification/typeorm-storage.js +56 -0
- package/dist/notification/typeorm-storage.js.map +1 -0
- package/dist/notification/unified.d.ts +47 -0
- package/dist/notification/unified.js +207 -0
- package/dist/notification/unified.js.map +1 -0
- package/dist/queue/README.md +82 -0
- package/dist/queue/index.d.ts +14 -0
- package/dist/queue/index.js +17 -0
- package/dist/queue/index.js.map +1 -0
- package/dist/queue/index.spec.d.ts +1 -0
- package/dist/queue/index.spec.js +76 -0
- package/dist/queue/index.spec.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/typeorm/README.md +197 -0
- package/dist/typeorm/crud-controller.d.ts +4 -0
- package/dist/typeorm/crud-controller.js +81 -0
- package/dist/typeorm/crud-controller.js.map +1 -0
- package/dist/typeorm/crud-service.d.ts +6 -0
- package/dist/typeorm/crud-service.js +53 -0
- package/dist/typeorm/crud-service.js.map +1 -0
- package/dist/typeorm/crud.interface.d.ts +9 -0
- package/dist/typeorm/crud.interface.js +3 -0
- package/dist/typeorm/crud.interface.js.map +1 -0
- package/dist/typeorm/index.d.ts +23 -0
- package/dist/typeorm/index.js +66 -0
- package/dist/typeorm/index.js.map +1 -0
- package/dist/typeorm/index.spec.d.ts +1 -0
- package/dist/typeorm/index.spec.js +109 -0
- package/dist/typeorm/index.spec.js.map +1 -0
- package/package.json +229 -0
- package/src/cache/README.md +91 -0
- package/src/excel/README.md +132 -0
- package/src/notification/README.md +237 -0
- package/src/queue/README.md +82 -0
- package/src/typeorm/README.md +197 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excel.service.js","sourceRoot":"","sources":["../../src/excel/excel.service.ts"],"names":[],"mappings":";;AA2HA,wCA2CC;AAED,oCAOC;AAED,4CAeC;AAhMD,qCAAmC;AAEnC,+CAA6C;AAuB7C,MAAM,QAAQ,GAAG;IACf,SAAS,EAAE,QAAQ;IACnB,aAAa,EAAE,IAAI;IACnB,UAAU,EAAE,EAAE,IAAI,EAAE,SAAkB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE;IAC9D,QAAQ,EAAE,QAAQ;IAClB,WAAW,EAAE,QAAQ;CACtB,CAAC;AAEF,SAAS,WAAW,CAClB,IAA+B,EAC/B,OAAkC;IAElC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YACxC,GAAG;YACH,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,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E,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;SAClD,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC;AAEM,KAAK,UAAU,YAAY,CAChC,IAA+B,EAC/B,QAAgB,EAChB,OAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AACpC,CAAC;AAEM,KAAK,UAAU,gBAAgB,CACpC,IAA+B,EAC/B,GAAmB,EACnB,QAAiB,EACjB,OAA4B;IAE5B,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,MAAM,IAAI,GAAG,QAAQ,IAAI,aAAa,CAAC;IACvC,GAAG,CAAC,SAAS,CACX,cAAc,EACd,mEAAmE,CACpE,CAAC;IACF,GAAG,CAAC,SAAS,CAAC,qBAAqB,EAAE,yBAAyB,IAAI,GAAG,CAAC,CAAC;IACvE,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.exportToResponse = exports.exportToFile = exports.exportToBuffer = void 0;
|
|
4
|
+
var excel_service_1 = require("./excel.service");
|
|
5
|
+
Object.defineProperty(exports, "exportToBuffer", { enumerable: true, get: function () { return excel_service_1.exportToBuffer; } });
|
|
6
|
+
Object.defineProperty(exports, "exportToFile", { enumerable: true, get: function () { return excel_service_1.exportToFile; } });
|
|
7
|
+
Object.defineProperty(exports, "exportToResponse", { enumerable: true, get: function () { return excel_service_1.exportToResponse; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/excel/index.ts"],"names":[],"mappings":";;;AAAA,iDAIyB;AAHvB,+GAAA,cAAc,OAAA;AACd,6GAAA,YAAY,OAAA;AACZ,iHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ExcelColumn {
|
|
2
|
+
key: string;
|
|
3
|
+
header?: string;
|
|
4
|
+
width?: number;
|
|
5
|
+
formatter?: (value: unknown, row: Record<string, unknown>) => unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface ExcelExportOptions {
|
|
8
|
+
sheetName?: string;
|
|
9
|
+
columns?: (string | ExcelColumn)[];
|
|
10
|
+
useAutofilter?: boolean;
|
|
11
|
+
headerFont?: {
|
|
12
|
+
name?: string;
|
|
13
|
+
size?: number;
|
|
14
|
+
bold?: boolean;
|
|
15
|
+
};
|
|
16
|
+
headerBg?: string;
|
|
17
|
+
borderColor?: string;
|
|
18
|
+
formatters?: Record<string, (value: unknown, row: Record<string, unknown>) => unknown>;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../src/excel/interfaces.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const VERSION = "2.2.0";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const index_1 = require("./index");
|
|
4
|
+
describe('@vn.chemgio/nestjs-utilities', () => {
|
|
5
|
+
describe('VERSION', () => {
|
|
6
|
+
it('should be a semver string', () => {
|
|
7
|
+
expect(index_1.VERSION).toMatch(/^\d+\.\d+\.\d+$/);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":";;AAAA,mCAAkC;AAElC,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;IAC5C,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;YACnC,MAAM,CAAC,eAAO,CAAC,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# nesthub/notification
|
|
2
|
+
|
|
3
|
+
Multi-channel notification module for NestJS with support for email, SMS, Firebase Cloud Messaging, and Telegram.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **4 channels**: Email, SMS, Firebase, Telegram
|
|
8
|
+
- **Multiple providers**: Configure many SMTP servers / SMS gateways per channel (failover chain)
|
|
9
|
+
- **Template engine**: Handlebars (`.hbs`) for dynamic content
|
|
10
|
+
- **Queue support**: Optional BullMQ integration with expiry check
|
|
11
|
+
- **Persistence**: Optional TypeORM-based notification logging (snake_case columns)
|
|
12
|
+
- **Optional dependencies**: Only install what you use
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install nesthub
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Optional channel dependencies
|
|
21
|
+
|
|
22
|
+
Only install the libraries for channels you use:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# For email (SMTP)
|
|
26
|
+
npm install nodemailer
|
|
27
|
+
|
|
28
|
+
# For SMS (choose your provider)
|
|
29
|
+
npm install twilio
|
|
30
|
+
# or
|
|
31
|
+
npm install @aws-sdk/client-sns
|
|
32
|
+
|
|
33
|
+
# For Firebase
|
|
34
|
+
npm install firebase-admin
|
|
35
|
+
|
|
36
|
+
# For templates
|
|
37
|
+
npm install handlebars
|
|
38
|
+
|
|
39
|
+
# For queue
|
|
40
|
+
npm install @nestjs/bullmq bullmq
|
|
41
|
+
|
|
42
|
+
# For persistence (TypeORM)
|
|
43
|
+
npm install @nestjs/typeorm typeorm
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { Module } from '@nestjs/common';
|
|
50
|
+
import { NotificationModule } from 'nesthub/notification';
|
|
51
|
+
|
|
52
|
+
@Module({
|
|
53
|
+
imports: [
|
|
54
|
+
NotificationModule.forRoot({
|
|
55
|
+
channels: {
|
|
56
|
+
email: {
|
|
57
|
+
smtp: { host: 'smtp.example.com', port: 587, user: 'user', pass: 'pass' },
|
|
58
|
+
defaults: { from: 'noreply@example.com' },
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
})
|
|
64
|
+
export class AppModule {}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## SMTP Configuration
|
|
68
|
+
|
|
69
|
+
Two ways to configure email:
|
|
70
|
+
|
|
71
|
+
### Explicit SMTP fields
|
|
72
|
+
```typescript
|
|
73
|
+
email: {
|
|
74
|
+
smtp: {
|
|
75
|
+
host: 'smtp.example.com',
|
|
76
|
+
port: 587,
|
|
77
|
+
secure: false, // true for port 465
|
|
78
|
+
user: 'username',
|
|
79
|
+
pass: 'password',
|
|
80
|
+
},
|
|
81
|
+
defaults: { from: 'noreply@example.com' },
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Connection string (nodemailer transport)
|
|
86
|
+
```typescript
|
|
87
|
+
email: {
|
|
88
|
+
transport: 'smtp://user:pass@smtp.example.com:587',
|
|
89
|
+
defaults: { from: 'noreply@example.com' },
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Multi-Provider Failover
|
|
94
|
+
|
|
95
|
+
Pass an array of configs per channel. On failure, the next provider is tried automatically:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
channels: {
|
|
99
|
+
email: [
|
|
100
|
+
{ smtp: { host: 'smtp1.example.com', port: 587, user: 'u1', pass: 'p1' } },
|
|
101
|
+
{ smtp: { host: 'smtp2.example.com', port: 587, user: 'u2', pass: 'p2' } },
|
|
102
|
+
],
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Usage
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
import { Injectable } from '@nestjs/common';
|
|
110
|
+
import { NotificationService } from 'nesthub/notification';
|
|
111
|
+
|
|
112
|
+
@Injectable()
|
|
113
|
+
export class UserService {
|
|
114
|
+
constructor(private readonly notification: NotificationService) {}
|
|
115
|
+
|
|
116
|
+
async welcomeUser(email: string, name: string) {
|
|
117
|
+
await this.notification.send({
|
|
118
|
+
channel: 'email',
|
|
119
|
+
to: email,
|
|
120
|
+
subject: 'Welcome!',
|
|
121
|
+
template: 'welcome',
|
|
122
|
+
context: { name },
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API
|
|
129
|
+
|
|
130
|
+
### `NotificationModule.forRoot(options)`
|
|
131
|
+
|
|
132
|
+
| Option | Type | Description |
|
|
133
|
+
|--------|------|-------------|
|
|
134
|
+
| `channels.email` | `EmailChannelConfig \| EmailChannelConfig[]` | Email channel config(s) |
|
|
135
|
+
| `channels.sms` | `SmsChannelConfig \| SmsChannelConfig[]` | SMS channel config(s) |
|
|
136
|
+
| `channels.firebase` | `FirebaseChannelConfig \| FirebaseChannelConfig[]` | Firebase channel config(s) |
|
|
137
|
+
| `channels.telegram` | `TelegramChannelConfig \| TelegramChannelConfig[]` | Telegram channel config(s) |
|
|
138
|
+
| `templates.dir` | `string` | Directory containing `.hbs` template files |
|
|
139
|
+
| `queue` | `QueueConfig` | BullMQ queue configuration |
|
|
140
|
+
| `storage.enabled` | `boolean` | Enable notification persistence |
|
|
141
|
+
|
|
142
|
+
### `NotificationModule.forRootAsync(options)`
|
|
143
|
+
|
|
144
|
+
Use with `ConfigService` to read config from environment variables:
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
NotificationModule.forRootAsync({
|
|
148
|
+
imports: [ConfigModule],
|
|
149
|
+
inject: [ConfigService],
|
|
150
|
+
useFactory: (config: ConfigService) => ({
|
|
151
|
+
channels: {
|
|
152
|
+
email: {
|
|
153
|
+
smtp: {
|
|
154
|
+
host: config.get('SMTP_HOST'),
|
|
155
|
+
port: config.get('SMTP_PORT'),
|
|
156
|
+
user: config.get('SMTP_USER'),
|
|
157
|
+
pass: config.get('SMTP_PASS'),
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
queue: {
|
|
162
|
+
enabled: true,
|
|
163
|
+
connection: { url: config.get('VALKEY_URL') ?? 'valkey://localhost:6379' },
|
|
164
|
+
},
|
|
165
|
+
templates: { dir: config.get('TEMPLATE_DIR', './templates') },
|
|
166
|
+
storage: { enabled: config.get('NOTIFICATION_STORAGE', false) },
|
|
167
|
+
}),
|
|
168
|
+
})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `NotificationService`
|
|
172
|
+
|
|
173
|
+
| Method | Description |
|
|
174
|
+
|--------|-------------|
|
|
175
|
+
| `send(input)` | Send notification immediately (tries providers in order) |
|
|
176
|
+
| `enqueue(input)` | Queue notification for async processing |
|
|
177
|
+
|
|
178
|
+
## Template Engine
|
|
179
|
+
|
|
180
|
+
Place `.hbs` files in the configured template directory:
|
|
181
|
+
|
|
182
|
+
```hbs
|
|
183
|
+
<!-- templates/welcome.hbs -->
|
|
184
|
+
<h1>Welcome, {{name}}!</h1>
|
|
185
|
+
<p>Thank you for joining us.</p>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Queue with Expiry Check
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
NotificationModule.forRoot({
|
|
192
|
+
channels: { email: { smtp: { host: '...', port: 587 } } },
|
|
193
|
+
queue: {
|
|
194
|
+
enabled: true,
|
|
195
|
+
name: 'notifications',
|
|
196
|
+
connection: { url: 'valkey://localhost:6379' },
|
|
197
|
+
defaultJobOptions: { attempts: 3 },
|
|
198
|
+
},
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Expired notifications (those with `expiresAt` in the past) are automatically skipped.
|
|
203
|
+
|
|
204
|
+
## Persistence with TypeORM
|
|
205
|
+
|
|
206
|
+
The `NotificationLog` entity uses snake_case column names.
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
import { NotificationLog, NOTIFICATION_LOG_REPOSITORY } from 'nesthub/notification';
|
|
210
|
+
import { TypeOrmModule, getRepositoryToken } from '@nestjs/typeorm';
|
|
211
|
+
|
|
212
|
+
@Module({
|
|
213
|
+
imports: [
|
|
214
|
+
TypeOrmModule.forFeature([NotificationLog]),
|
|
215
|
+
NotificationModule.forRoot({
|
|
216
|
+
channels: { email: { smtp: { host: '...', port: 587 } } },
|
|
217
|
+
storage: { enabled: true },
|
|
218
|
+
}),
|
|
219
|
+
],
|
|
220
|
+
providers: [{
|
|
221
|
+
provide: NOTIFICATION_LOG_REPOSITORY,
|
|
222
|
+
useFactory: (repo) => repo,
|
|
223
|
+
inject: [getRepositoryToken(NotificationLog)],
|
|
224
|
+
}],
|
|
225
|
+
})
|
|
226
|
+
export class AppModule {}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Column naming
|
|
230
|
+
|
|
231
|
+
| Entity property | DB column |
|
|
232
|
+
|----------------|-----------|
|
|
233
|
+
| `to` | `recipient_to` |
|
|
234
|
+
| `messageId` | `message_id` |
|
|
235
|
+
| `createdAt` | `created_at` |
|
|
236
|
+
| `updatedAt` | `updated_at` |
|
|
237
|
+
| `sentAt` | `sent_at` |
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SendNotificationInput } from '../interfaces';
|
|
2
|
+
export interface SendChannelResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
messageId?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface NotificationChannel {
|
|
8
|
+
readonly channelType: string;
|
|
9
|
+
send(input: SendNotificationInput): Promise<SendChannelResult>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"channel.interface.js","sourceRoot":"","sources":["../../../src/notification/channels/channel.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { SendNotificationInput, EmailChannelConfig } from '../interfaces';
|
|
2
|
+
import type { NotificationChannel, SendChannelResult } from './channel.interface';
|
|
3
|
+
export declare class EmailChannel implements NotificationChannel {
|
|
4
|
+
private config;
|
|
5
|
+
readonly channelType = "email";
|
|
6
|
+
private transporter;
|
|
7
|
+
private initPromise;
|
|
8
|
+
constructor(config: EmailChannelConfig);
|
|
9
|
+
private ensureTransporter;
|
|
10
|
+
send(input: SendNotificationInput): Promise<SendChannelResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailChannel = void 0;
|
|
4
|
+
function smtpToTransport(smtp) {
|
|
5
|
+
const transport = {
|
|
6
|
+
host: smtp.host,
|
|
7
|
+
port: smtp.port,
|
|
8
|
+
secure: smtp.secure ?? smtp.port === 465,
|
|
9
|
+
};
|
|
10
|
+
if (smtp.user)
|
|
11
|
+
transport.auth = { user: smtp.user, pass: smtp.pass ?? '' };
|
|
12
|
+
return transport;
|
|
13
|
+
}
|
|
14
|
+
class EmailChannel {
|
|
15
|
+
config;
|
|
16
|
+
channelType = 'email';
|
|
17
|
+
transporter;
|
|
18
|
+
initPromise = null;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
async ensureTransporter() {
|
|
23
|
+
if (this.transporter)
|
|
24
|
+
return;
|
|
25
|
+
if (this.initPromise)
|
|
26
|
+
return this.initPromise;
|
|
27
|
+
this.initPromise = (async () => {
|
|
28
|
+
const nodemailer = await import('nodemailer');
|
|
29
|
+
const transportOpts = this.config.smtp
|
|
30
|
+
? smtpToTransport(this.config.smtp)
|
|
31
|
+
: (this.config.transport ?? {});
|
|
32
|
+
this.transporter = nodemailer.default.createTransport(transportOpts, this.config.defaults);
|
|
33
|
+
})();
|
|
34
|
+
return this.initPromise;
|
|
35
|
+
}
|
|
36
|
+
async send(input) {
|
|
37
|
+
try {
|
|
38
|
+
await this.ensureTransporter();
|
|
39
|
+
const mailOptions = {
|
|
40
|
+
to: Array.isArray(input.to) ? input.to.join(', ') : input.to,
|
|
41
|
+
subject: input.subject,
|
|
42
|
+
html: input.content,
|
|
43
|
+
};
|
|
44
|
+
if (input.sender)
|
|
45
|
+
mailOptions.from = input.sender;
|
|
46
|
+
if (input.attachments?.length)
|
|
47
|
+
mailOptions.attachments = input.attachments;
|
|
48
|
+
const info = await this.transporter.sendMail(mailOptions);
|
|
49
|
+
return { success: true, messageId: info.messageId };
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
return { success: false, error: message };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.EmailChannel = EmailChannel;
|
|
58
|
+
//# sourceMappingURL=email.channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"email.channel.js","sourceRoot":"","sources":["../../../src/notification/channels/email.channel.ts"],"names":[],"mappings":";;;AAOA,SAAS,eAAe,CACtB,IAA6C;IAE7C,MAAM,SAAS,GAA4B;QACzC,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,GAAG;KACzC,CAAC;IACF,IAAI,IAAI,CAAC,IAAI;QAAE,SAAS,CAAC,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;IAC3E,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAa,YAAY;IAKH;IAJX,WAAW,GAAG,OAAO,CAAC;IACvB,WAAW,CAAM;IACjB,WAAW,GAAyB,IAAI,CAAC;IAEjD,YAAoB,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAE1C,KAAK,CAAC,iBAAiB;QAC7B,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAC7B,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAAC;QAE9C,IAAI,CAAC,WAAW,GAAG,CAAC,KAAK,IAAI,EAAE;YAC7B,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,CAAC;YAC9C,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI;gBACpC,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;gBACnC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC;YAClC,IAAI,CAAC,WAAW,GAAG,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+
import type { SendNotificationInput, FirebaseChannelConfig } from '../interfaces';
|
|
2
|
+
import type { NotificationChannel, SendChannelResult } from './channel.interface';
|
|
3
|
+
export declare class FirebaseChannel implements NotificationChannel {
|
|
4
|
+
private config;
|
|
5
|
+
readonly channelType = "firebase";
|
|
6
|
+
private initialized;
|
|
7
|
+
private initPromise;
|
|
8
|
+
constructor(config: FirebaseChannelConfig);
|
|
9
|
+
private ensureInitialized;
|
|
10
|
+
send(input: SendNotificationInput): Promise<SendChannelResult>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirebaseChannel = void 0;
|
|
4
|
+
class FirebaseChannel {
|
|
5
|
+
config;
|
|
6
|
+
channelType = 'firebase';
|
|
7
|
+
initialized = false;
|
|
8
|
+
initPromise = null;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
async ensureInitialized() {
|
|
13
|
+
if (this.initialized)
|
|
14
|
+
return;
|
|
15
|
+
if (this.initPromise)
|
|
16
|
+
return this.initPromise;
|
|
17
|
+
this.initPromise = (async () => {
|
|
18
|
+
const admin = await import('firebase-admin');
|
|
19
|
+
if (admin.apps.length === 0) {
|
|
20
|
+
const credential = this.config.serviceAccountPath
|
|
21
|
+
? admin.credential.cert(this.config.serviceAccountPath)
|
|
22
|
+
: this.config.serviceAccount
|
|
23
|
+
? admin.credential.cert(this.config.serviceAccount)
|
|
24
|
+
: undefined;
|
|
25
|
+
admin.initializeApp({
|
|
26
|
+
credential,
|
|
27
|
+
databaseURL: this.config.databaseURL,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
this.initialized = true;
|
|
31
|
+
})();
|
|
32
|
+
return this.initPromise;
|
|
33
|
+
}
|
|
34
|
+
async send(input) {
|
|
35
|
+
try {
|
|
36
|
+
await this.ensureInitialized();
|
|
37
|
+
const admin = await import('firebase-admin');
|
|
38
|
+
const to = Array.isArray(input.to) ? input.to : [input.to];
|
|
39
|
+
const tokens = to.filter(Boolean);
|
|
40
|
+
if (tokens.length === 0) {
|
|
41
|
+
return { success: false, error: 'No device tokens provided' };
|
|
42
|
+
}
|
|
43
|
+
const message = {
|
|
44
|
+
tokens,
|
|
45
|
+
notification: {
|
|
46
|
+
title: input.subject,
|
|
47
|
+
body: input.content,
|
|
48
|
+
},
|
|
49
|
+
data: input.metadata,
|
|
50
|
+
};
|
|
51
|
+
const response = await admin
|
|
52
|
+
.messaging()
|
|
53
|
+
.sendEachForMulticast(message);
|
|
54
|
+
const successCount = response.successCount;
|
|
55
|
+
const failureCount = response.failureCount;
|
|
56
|
+
return {
|
|
57
|
+
success: successCount > 0,
|
|
58
|
+
messageId: response.responses.find((r) => r.success)?.messageId,
|
|
59
|
+
error: failureCount > 0 ? `${failureCount} tokens failed` : undefined,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
64
|
+
return { success: false, error: message };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.FirebaseChannel = FirebaseChannel;
|
|
69
|
+
//# sourceMappingURL=firebase.channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebase.channel.js","sourceRoot":"","sources":["../../../src/notification/channels/firebase.channel.ts"],"names":[],"mappings":";;;AAUA,MAAa,eAAe;IAKN;IAJX,WAAW,GAAG,UAAU,CAAC;IAC1B,WAAW,GAAG,KAAK,CAAC;IACpB,WAAW,GAAyB,IAAI,CAAC;IAEjD,YAAoB,MAA6B;QAA7B,WAAM,GAAN,MAAM,CAAuB;IAAG,CAAC;IAE7C,KAAK,CAAC,iBAAiB;QAC7B,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO;QAC7B,IAAI,IAAI,CAAC,WAAW;YAAE,OAAO,IAAI,CAAC,WAAW,CAA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,EAAE,KAAK,EAAE,KAAK,EAAE,2BAA2B,EAAE,CAAC;YAChE,CAAC;YAED,MAAM,OAAO,GAA4B;gBACvC,MAAM;gBACN,YAAY,EAAE;oBACZ,KAAK,EAAE,KAAK,CAAC,OAAO;oBACpB,IAAI,EAAE,KAAK,CAAC,OAAO;iBACpB;gBACD,IAAI,EAAE,KAAK,CAAC,QAAQ;aACrB,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAO,KAAa;iBAClC,SAAS,EAAE;iBACX,oBAAoB,CAAC,OAAc,CAAC,CAAC;YACxC,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;YAC3C,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;YAE3C,OAAO;gBACL,OAAO,EAAE,YAAY,GAAG,CAAC;gBACzB,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,SAAS;gBACpE,KAAK,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,gBAAgB,CAAC,CAAC,CAAC,SAAS;aACtE,CAAC;QACJ,CAAC;QAAC,OAAO,KAAc,EAAE,CAAC;YACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;CACF;AAtED,0CAsEC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { NotificationChannel, SendChannelResult, } from './channel.interface';
|
|
2
|
+
export { EmailChannel } from './email.channel';
|
|
3
|
+
export { SmsChannel } from './sms.channel';
|
|
4
|
+
export { FirebaseChannel } from './firebase.channel';
|
|
5
|
+
export { TelegramChannel } from './telegram.channel';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelegramChannel = exports.FirebaseChannel = exports.SmsChannel = exports.EmailChannel = void 0;
|
|
4
|
+
var email_channel_1 = require("./email.channel");
|
|
5
|
+
Object.defineProperty(exports, "EmailChannel", { enumerable: true, get: function () { return email_channel_1.EmailChannel; } });
|
|
6
|
+
var sms_channel_1 = require("./sms.channel");
|
|
7
|
+
Object.defineProperty(exports, "SmsChannel", { enumerable: true, get: function () { return sms_channel_1.SmsChannel; } });
|
|
8
|
+
var firebase_channel_1 = require("./firebase.channel");
|
|
9
|
+
Object.defineProperty(exports, "FirebaseChannel", { enumerable: true, get: function () { return firebase_channel_1.FirebaseChannel; } });
|
|
10
|
+
var telegram_channel_1 = require("./telegram.channel");
|
|
11
|
+
Object.defineProperty(exports, "TelegramChannel", { enumerable: true, get: function () { return telegram_channel_1.TelegramChannel; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/notification/channels/index.ts"],"names":[],"mappings":";;;AAIA,iDAA+C;AAAtC,6GAAA,YAAY,OAAA;AACrB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AACnB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AACxB,uDAAqD;AAA5C,mHAAA,eAAe,OAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SendNotificationInput, SmsChannelConfig } from '../interfaces';
|
|
2
|
+
import type { NotificationChannel, SendChannelResult } from './channel.interface';
|
|
3
|
+
export declare class SmsChannel implements NotificationChannel {
|
|
4
|
+
private config;
|
|
5
|
+
readonly channelType = "sms";
|
|
6
|
+
constructor(config: SmsChannelConfig);
|
|
7
|
+
send(input: SendNotificationInput): Promise<SendChannelResult>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SmsChannel = void 0;
|
|
4
|
+
class SmsChannel {
|
|
5
|
+
config;
|
|
6
|
+
channelType = 'sms';
|
|
7
|
+
constructor(config) {
|
|
8
|
+
this.config = config;
|
|
9
|
+
}
|
|
10
|
+
async send(input) {
|
|
11
|
+
try {
|
|
12
|
+
const to = Array.isArray(input.to) ? input.to[0] : input.to;
|
|
13
|
+
switch (this.config.provider) {
|
|
14
|
+
case 'twilio': {
|
|
15
|
+
const twilio = await import('twilio');
|
|
16
|
+
const client = twilio.default(this.config.credentials.accountSid, this.config.credentials.authToken);
|
|
17
|
+
const result = await client.messages.create({
|
|
18
|
+
body: input.content,
|
|
19
|
+
to,
|
|
20
|
+
from: input.sender ?? this.config.from,
|
|
21
|
+
});
|
|
22
|
+
return { success: true, messageId: result.sid };
|
|
23
|
+
}
|
|
24
|
+
case 'aws-sns': {
|
|
25
|
+
const { SNSClient, PublishCommand } = await import('@aws-sdk/client-sns');
|
|
26
|
+
const client = new SNSClient({
|
|
27
|
+
region: this.config.credentials.region,
|
|
28
|
+
credentials: {
|
|
29
|
+
accessKeyId: this.config.credentials.accessKeyId,
|
|
30
|
+
secretAccessKey: this.config.credentials.secretAccessKey,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const command = new PublishCommand({
|
|
34
|
+
Message: input.content,
|
|
35
|
+
PhoneNumber: to,
|
|
36
|
+
MessageAttributes: this.config.from
|
|
37
|
+
? {
|
|
38
|
+
'AWS.SNS.SMS.SenderID': {
|
|
39
|
+
DataType: 'String',
|
|
40
|
+
StringValue: this.config.from,
|
|
41
|
+
},
|
|
42
|
+
}
|
|
43
|
+
: undefined,
|
|
44
|
+
});
|
|
45
|
+
const result = await client.send(command);
|
|
46
|
+
return { success: true, messageId: result.MessageId };
|
|
47
|
+
}
|
|
48
|
+
case 'http': {
|
|
49
|
+
const url = this.config.credentials.url;
|
|
50
|
+
if (!url)
|
|
51
|
+
return { success: false, error: 'HTTP URL not configured' };
|
|
52
|
+
const response = await fetch(url, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: {
|
|
55
|
+
'Content-Type': 'application/json',
|
|
56
|
+
Authorization: this.config.credentials.apiKey
|
|
57
|
+
? `Bearer ${this.config.credentials.apiKey}`
|
|
58
|
+
: '',
|
|
59
|
+
},
|
|
60
|
+
body: JSON.stringify({
|
|
61
|
+
to,
|
|
62
|
+
content: input.content,
|
|
63
|
+
from: input.sender ?? this.config.from,
|
|
64
|
+
...input.metadata,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
return {
|
|
69
|
+
success: false,
|
|
70
|
+
error: `HTTP ${response.status}: ${response.statusText}`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const data = await response.json();
|
|
74
|
+
return { success: true, messageId: data.id ?? data.messageId };
|
|
75
|
+
}
|
|
76
|
+
default:
|
|
77
|
+
return {
|
|
78
|
+
success: false,
|
|
79
|
+
error: 'Unsupported SMS provider',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
85
|
+
return { success: false, error: message };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.SmsChannel = SmsChannel;
|
|
90
|
+
//# sourceMappingURL=sms.channel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sms.channel.js","sourceRoot":"","sources":["../../../src/notification/channels/sms.channel.ts"],"names":[],"mappings":";;;AAOA,MAAa,UAAU;IAGD;IAFX,WAAW,GAAG,KAAK,CAAC;IAE7B,YAAoB,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;IAAG,CAAC;IAEhD,KAAK,CAAC,IAAI,CAAC,KAA4B;QACrC,IAAI,CAAC;YACH,MAAM,EAAE,GAAG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