@nathapp/nestjs-notification 1.0.0-rc.5 → 1.0.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 (102) hide show
  1. package/README.md +3 -3
  2. package/dist/email/constant.js +1 -0
  3. package/dist/email/constant.js.map +1 -0
  4. package/dist/email/email-provider.factory.js +1 -0
  5. package/dist/email/email-provider.factory.js.map +1 -0
  6. package/dist/email/email.interface.js +1 -0
  7. package/dist/email/email.interface.js.map +1 -0
  8. package/dist/email/email.module.d.ts +3 -0
  9. package/dist/email/email.module.js +20 -5
  10. package/dist/email/email.module.js.map +1 -0
  11. package/dist/email/email.provider.d.ts +2 -0
  12. package/dist/email/email.provider.js +29 -7
  13. package/dist/email/email.provider.js.map +1 -0
  14. package/dist/email/email.service.d.ts +1 -1
  15. package/dist/email/email.service.js +3 -2
  16. package/dist/email/email.service.js.map +1 -0
  17. package/dist/email/index.d.ts +2 -2
  18. package/dist/email/index.js +3 -1
  19. package/dist/email/index.js.map +1 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +2 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/interface/index.d.ts +4 -2
  24. package/dist/interface/index.js +1 -0
  25. package/dist/interface/index.js.map +1 -0
  26. package/dist/interface/message.interface.d.ts +13 -0
  27. package/dist/interface/message.interface.js +1 -0
  28. package/dist/interface/message.interface.js.map +1 -0
  29. package/dist/interface/payload.inteface.d.ts +22 -0
  30. package/dist/interface/payload.inteface.js +3 -0
  31. package/dist/interface/payload.inteface.js.map +1 -0
  32. package/dist/interface/result.interface.d.ts +5 -0
  33. package/dist/interface/result.interface.js +1 -0
  34. package/dist/interface/result.interface.js.map +1 -0
  35. package/dist/notification/constant.js +1 -0
  36. package/dist/notification/constant.js.map +1 -0
  37. package/dist/notification/index.d.ts +2 -2
  38. package/dist/notification/index.js +1 -0
  39. package/dist/notification/index.js.map +1 -0
  40. package/dist/notification/notification.module.d.ts +28 -5
  41. package/dist/notification/notification.module.js +149 -10
  42. package/dist/notification/notification.module.js.map +1 -0
  43. package/dist/notification/notification.service.d.ts +14 -3
  44. package/dist/notification/notification.service.js +135 -10
  45. package/dist/notification/notification.service.js.map +1 -0
  46. package/dist/push-notification/constant.d.ts +1 -0
  47. package/dist/push-notification/constant.js +5 -0
  48. package/dist/push-notification/constant.js.map +1 -0
  49. package/dist/push-notification/fcm-push-notification.provider.d.ts +13 -0
  50. package/dist/push-notification/fcm-push-notification.provider.js +78 -0
  51. package/dist/push-notification/fcm-push-notification.provider.js.map +1 -0
  52. package/dist/push-notification/firebase.interface.d.ts +144 -0
  53. package/dist/push-notification/firebase.interface.js +3 -0
  54. package/dist/push-notification/firebase.interface.js.map +1 -0
  55. package/dist/push-notification/index.d.ts +11 -0
  56. package/dist/push-notification/index.js +24 -0
  57. package/dist/push-notification/index.js.map +1 -0
  58. package/dist/push-notification/push-notification-module.interface.d.ts +33 -0
  59. package/dist/push-notification/push-notification-module.interface.js +4 -0
  60. package/dist/push-notification/push-notification-module.interface.js.map +1 -0
  61. package/dist/push-notification/push-notification-provider-module.factory.d.ts +5 -0
  62. package/dist/push-notification/push-notification-provider-module.factory.js +13 -0
  63. package/dist/push-notification/push-notification-provider-module.factory.js.map +1 -0
  64. package/dist/push-notification/push-notification-provider.factory.d.ts +5 -0
  65. package/dist/push-notification/push-notification-provider.factory.js +16 -0
  66. package/dist/push-notification/push-notification-provider.factory.js.map +1 -0
  67. package/dist/push-notification/push-notification-provider.manager.d.ts +13 -0
  68. package/dist/push-notification/push-notification-provider.manager.js +38 -0
  69. package/dist/push-notification/push-notification-provider.manager.js.map +1 -0
  70. package/dist/push-notification/push-notification.interface.d.ts +16 -0
  71. package/dist/push-notification/push-notification.interface.js +11 -0
  72. package/dist/push-notification/push-notification.interface.js.map +1 -0
  73. package/dist/push-notification/push-notification.module.d.ts +15 -0
  74. package/dist/push-notification/push-notification.module.js +189 -0
  75. package/dist/push-notification/push-notification.module.js.map +1 -0
  76. package/dist/push-notification/push-notification.provider.d.ts +12 -0
  77. package/dist/push-notification/push-notification.provider.js +7 -0
  78. package/dist/push-notification/push-notification.provider.js.map +1 -0
  79. package/dist/push-notification/push-notification.service.d.ts +15 -0
  80. package/dist/push-notification/push-notification.service.js +66 -0
  81. package/dist/push-notification/push-notification.service.js.map +1 -0
  82. package/dist/push-notification/user-token.store.d.ts +19 -0
  83. package/dist/push-notification/user-token.store.js +44 -0
  84. package/dist/push-notification/user-token.store.js.map +1 -0
  85. package/dist/sms/index.js +1 -0
  86. package/dist/sms/index.js.map +1 -0
  87. package/dist/sms/sms.service.js +1 -0
  88. package/dist/sms/sms.service.js.map +1 -0
  89. package/dist/template/constant.js +1 -0
  90. package/dist/template/constant.js.map +1 -0
  91. package/dist/template/fake-template.loader.d.ts +3 -0
  92. package/dist/template/fake-template.loader.js +15 -1
  93. package/dist/template/fake-template.loader.js.map +1 -0
  94. package/dist/template/index.d.ts +2 -2
  95. package/dist/template/index.js +3 -1
  96. package/dist/template/index.js.map +1 -0
  97. package/dist/template/template.loader.js +3 -2
  98. package/dist/template/template.loader.js.map +1 -0
  99. package/dist/template/template.service.js +3 -2
  100. package/dist/template/template.service.js.map +1 -0
  101. package/package.json +13 -22
  102. package/.eslintrc.js +0 -24
@@ -14,29 +14,45 @@ const constant_1 = require("./constant");
14
14
  const template_1 = require("../template");
15
15
  const template_service_1 = require("../template/template.service");
16
16
  const notification_service_1 = require("./notification.service");
17
+ const push_notification_1 = require("../push-notification");
18
+ const defaultOptions = {
19
+ templateService: template_service_1.TemplateService,
20
+ templateLoader: template_1.FakeTemplateLoader,
21
+ notificationService: notification_service_1.NotificationService,
22
+ };
17
23
  let NotificationModule = NotificationModule_1 = class NotificationModule {
18
24
  static forRoot(options) {
19
25
  options = this.santitizeOptions(options);
20
26
  const modules = [];
21
- const { emailOptions } = options;
27
+ const { emailOptions, pushNotificationOptions } = options;
22
28
  if (emailOptions) {
23
- modules.push(email_1.EmailModule.forRoot(emailOptions));
29
+ if (this.isEmailModuleAsyncOption(emailOptions)) {
30
+ modules.push(email_1.EmailModule.forRootAsync(emailOptions));
31
+ }
32
+ else {
33
+ modules.push(email_1.EmailModule.forRoot(emailOptions));
34
+ }
35
+ }
36
+ if (pushNotificationOptions) {
37
+ if (this.isPushNotificationModuleAsyncOption(pushNotificationOptions)) {
38
+ modules.push(push_notification_1.PushNotificationModule.registerAsync(pushNotificationOptions));
39
+ }
40
+ else {
41
+ modules.push(push_notification_1.PushNotificationModule.register(pushNotificationOptions));
42
+ }
24
43
  }
25
44
  const moduleOptions = {
26
45
  provide: constant_1.NOTIFICATION_OPTIONS,
27
46
  useValue: options,
28
47
  };
29
- const templateLoader = {
30
- provide: template_1.TEMPLATE_LOADER,
31
- useClass: options.templateLoader || template_1.FakeTemplateLoader,
32
- };
48
+ const templateLoader = this.createTemplateLoader(options);
33
49
  const templateService = {
34
50
  provide: template_service_1.TemplateService,
35
- useClass: template_service_1.TemplateService
51
+ useClass: options.templateService || template_service_1.TemplateService
36
52
  };
37
53
  const notificationService = {
38
54
  provide: notification_service_1.NotificationService,
39
- useClass: notification_service_1.NotificationService,
55
+ useClass: options.notificationService || notification_service_1.NotificationService,
40
56
  };
41
57
  return {
42
58
  module: NotificationModule_1,
@@ -45,9 +61,128 @@ let NotificationModule = NotificationModule_1 = class NotificationModule {
45
61
  exports: [...modules, constant_1.NOTIFICATION_OPTIONS, template_1.TEMPLATE_LOADER, templateService, notificationService],
46
62
  };
47
63
  }
64
+ static forRootAsync(options) {
65
+ options = this.santitizeOptions(options);
66
+ const importedModules = options.imports || [];
67
+ const { emailOptions, pushNotificationOptions } = options;
68
+ if (emailOptions) {
69
+ if (this.isEmailModuleAsyncOption(emailOptions)) {
70
+ importedModules.push(email_1.EmailModule.forRootAsync(emailOptions));
71
+ }
72
+ else {
73
+ importedModules.push(email_1.EmailModule.forRoot(emailOptions));
74
+ }
75
+ }
76
+ if (pushNotificationOptions) {
77
+ if (this.isPushNotificationModuleAsyncOption(pushNotificationOptions)) {
78
+ importedModules.push(push_notification_1.PushNotificationModule.registerAsync(pushNotificationOptions));
79
+ }
80
+ else {
81
+ importedModules.push(push_notification_1.PushNotificationModule.register(pushNotificationOptions));
82
+ }
83
+ }
84
+ const moduleOptions = {
85
+ provide: constant_1.NOTIFICATION_OPTIONS,
86
+ useValue: options,
87
+ };
88
+ const templateLoader = this.createTemplateLoader(options);
89
+ const templateService = this.createTemplateService(options);
90
+ const notificationService = this.createNotificationService(options);
91
+ return {
92
+ module: NotificationModule_1,
93
+ imports: [...importedModules,],
94
+ providers: [moduleOptions, templateLoader, templateService, notificationService],
95
+ exports: [...importedModules, constant_1.NOTIFICATION_OPTIONS, template_1.TEMPLATE_LOADER, templateService, notificationService],
96
+ };
97
+ }
98
+ static createTemplateLoader(options) {
99
+ const providerOptions = options.templateLoader;
100
+ if (!isProviderAsyncOptions(providerOptions)) {
101
+ return {
102
+ provide: template_1.TEMPLATE_LOADER,
103
+ useClass: providerOptions || template_1.FakeTemplateLoader,
104
+ };
105
+ }
106
+ if (providerOptions.useFactory) {
107
+ return {
108
+ provide: template_1.TEMPLATE_LOADER,
109
+ useFactory(...args) {
110
+ return providerOptions.useFactory(...args);
111
+ },
112
+ inject: providerOptions.inject || [],
113
+ };
114
+ }
115
+ return {
116
+ provide: template_1.TEMPLATE_LOADER,
117
+ useFactory(loader) {
118
+ return loader;
119
+ },
120
+ inject: [providerOptions.useClass || providerOptions.useExisting],
121
+ };
122
+ }
123
+ static createTemplateService(options) {
124
+ const providerOptions = options.templateService;
125
+ if (!isProviderAsyncOptions(providerOptions)) {
126
+ return {
127
+ provide: template_service_1.TemplateService,
128
+ useClass: providerOptions || template_service_1.TemplateService,
129
+ };
130
+ }
131
+ if (providerOptions.useFactory) {
132
+ return {
133
+ provide: template_service_1.TemplateService,
134
+ useFactory(...args) {
135
+ return providerOptions.useFactory(...args);
136
+ },
137
+ inject: providerOptions.inject || [],
138
+ };
139
+ }
140
+ return {
141
+ provide: template_service_1.TemplateService,
142
+ useFactory(service) {
143
+ return service;
144
+ },
145
+ inject: [providerOptions.useClass || providerOptions.useExisting],
146
+ };
147
+ }
148
+ static createNotificationService(options) {
149
+ const providerOptions = options.notificationService;
150
+ if (!isProviderAsyncOptions(providerOptions)) {
151
+ return {
152
+ provide: notification_service_1.NotificationService,
153
+ useClass: providerOptions || notification_service_1.NotificationService,
154
+ };
155
+ }
156
+ if (providerOptions.useFactory) {
157
+ return {
158
+ provide: notification_service_1.NotificationService,
159
+ useFactory(...args) {
160
+ return providerOptions.useFactory(...args);
161
+ },
162
+ inject: providerOptions.inject || [],
163
+ };
164
+ }
165
+ return {
166
+ provide: notification_service_1.NotificationService,
167
+ useFactory(service) {
168
+ return service;
169
+ },
170
+ inject: [providerOptions.useClass || providerOptions.useExisting],
171
+ };
172
+ }
48
173
  static santitizeOptions(options) {
174
+ options = { ...defaultOptions, ...options };
49
175
  return options;
50
176
  }
177
+ static isEmailModuleAsyncOption(options) {
178
+ return 'useExisting' in options || 'useClass' in options || 'useFactory' in options || 'inject' in options;
179
+ }
180
+ static isPushNotificationModuleAsyncOption(options) {
181
+ if (options.providers.length > 0) {
182
+ const provider = options.providers[0];
183
+ return 'useExisting' in provider || 'useClass' in provider || 'useFactory' in provider || 'inject' in provider;
184
+ }
185
+ }
51
186
  static createAsyncOptionsProviders(options) {
52
187
  if (options.useExisting || options.useFactory) {
53
188
  return [this.createAsyncOptionsProvider(options)];
@@ -77,7 +212,11 @@ let NotificationModule = NotificationModule_1 = class NotificationModule {
77
212
  };
78
213
  }
79
214
  };
80
- NotificationModule = NotificationModule_1 = __decorate([
215
+ exports.NotificationModule = NotificationModule;
216
+ exports.NotificationModule = NotificationModule = NotificationModule_1 = __decorate([
81
217
  (0, common_1.Module)({})
82
218
  ], NotificationModule);
83
- exports.NotificationModule = NotificationModule;
219
+ const isProviderAsyncOptions = (options) => {
220
+ return 'useExisting' in options || 'useClass' in options || 'useFactory' in options;
221
+ };
222
+ //# sourceMappingURL=notification.module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.module.js","sourceRoot":"","sources":["../../lib/notification/notification.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAQwB;AACxB,oCAAoF;AACpF,yCAAkD;AAClD,0CAAkF;AAClF,mEAA+D;AAC/D,iEAA6D;AAC7D,4DAAiI;AAEjI,MAAM,cAAc,GAAwE;IAC1F,eAAe,EAAE,kCAAe;IAChC,cAAc,EAAE,6BAAkB;IAClC,mBAAmB,EAAE,0CAAmB;CACzC,CAAC;AAMK,IAAM,kBAAkB,0BAAxB,MAAM,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CAAC,OAAkC;QAC/C,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;QAEzC,MAAM,OAAO,GAAG,EAAE,CAAC;QACnB,MAAM,EAAE,YAAY,EAAE,uBAAuB,EAAE,GAAG,OAAO,CAAC;QAE1D,IAAI,YAAY,EAAE,CAAC;YACjB,IAAI,IAAI,CAAC,wBAAwB,CAAC,YAAY,CAAC,EAAE,CAAC;gBAChD,OAAO,CAAC,IAAI,CAAC,mBAAW,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC,CAAA;YACtD,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,mBAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QAED,IAAI,uBAAuB,EAAE,CAAC;YAC5B,IAAI,IAAI,CAAC,mCAAmC,CAAC,uBAAuB,CAAC,EAAE,CAAC;gBACtE,OAAO,CAAC,IAAI,CAAC,0CAAsB,CAAC,aAAa,CAAC,uBAAuB,CAAC,CAAC,CAAA;YAC7E,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,0CAAsB,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC;YACzE,CAAC;QACH,CAAC;QAED,MAAM,aAAa,GAAkB;YACnC,OAAO,EAA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CAAC,OAAO,CAAC,CAAC,CAAC;QACpD,CAAC;QAGD,OAAO;YACL,IAAI,CAAC,0BAA0B,CAAC,OAAO,CAAC;YACxC;gBACE,OAAO,EAAE,OAAO,CAAC,QAAQ;gBACzB,QAAQ,EAAE,OAAO,CAAC,QAAQ;aAC3B;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,0BAA0B,CACvC,OAAuC;QAEvC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO;gBACL,OAAO,EAAE,+BAAoB;gBAC7B,UAAU,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,EAAE;oBAC5B,OAAO,IAAI,CAAC,gBAAgB,CAC1B,CAAC,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,CAAQ,CAC3C,CAAC;gBACJ,CAAC;gBACD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;aAC7B,CAAC;QACJ,CAAC;QACD,OAAO;YACL,OAAO,EAAE,+BAAoB;YAC7B,UAAU,EAAE,KAAK,EAAE,cAAgD,EAAE,EAAE,CACrE,IAAI,CAAC,gBAAgB,CAAC,CAAC,MAAM,cAAc,CAAC,aAAa,EAAE,CAAQ,CAAC;YACtE,MAAM,EAAE,CAAC,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;SAClD,CAAC;IACJ,CAAC;CACF,CAAA;AA9OY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,kBAAkB,CA8O9B;AAoCD,MAAM,sBAAsB,GAAG,CAAC,OAAY,EAAmC,EAAE;IAC/E,OAAO,aAAa,IAAI,OAAO,IAAI,UAAU,IAAI,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC;AACtF,CAAC,CAAA"}
@@ -1,10 +1,21 @@
1
1
  import { ResolveOption, TemplateLoader } from "../template";
2
2
  import { EmailService } from "../email";
3
- import { SendResult } from "../interface/result.interface";
3
+ import { BatchSendResult, SendResult, EmailAttachment, EmailMessage, PushMessage, PushMessageOnly, EmailNotificationPayload, PushNotificationPayload } from "../interface";
4
+ import { DeviceToken, PushNotificationService } from "../push-notification";
4
5
  export declare class NotificationService {
5
6
  private readonly templateLoader;
6
7
  private readonly emailService;
8
+ private readonly pushNotificationService;
7
9
  private readonly logger;
8
- constructor(templateLoader: TemplateLoader, emailService: EmailService);
9
- sendEmail(templateCode: string, email: string, resolveOption: ResolveOption): Promise<SendResult>;
10
+ constructor(templateLoader: TemplateLoader, emailService: EmailService, pushNotificationService: PushNotificationService);
11
+ sendEmailRaw(message: EmailMessage): Promise<SendResult>;
12
+ sendEmail(payload: EmailNotificationPayload): Promise<SendResult>;
13
+ sendEmail(templateCode: string, email: string, resolveOption: ResolveOption, attachments: EmailAttachment[]): Promise<SendResult>;
14
+ sendPushNotificationRaw(message: PushMessage): Promise<SendResult>;
15
+ sendPushNotification(payload: PushNotificationPayload): Promise<SendResult>;
16
+ sendPushNotification(templateCode: string, token: string | number | DeviceToken, resolveOption: ResolveOption): Promise<SendResult>;
17
+ sendPushNotificationMulticastRaw(tokens: DeviceToken[], message: PushMessageOnly): Promise<BatchSendResult>;
18
+ sendPushNotificationMulticast(templateCode: string, tokens: DeviceToken[], resolveOption: ResolveOption): Promise<BatchSendResult>;
19
+ protected isEmailPayload(value: any): value is EmailNotificationPayload;
20
+ protected isPushNotificationPayload(value: any): value is PushNotificationPayload;
10
21
  }
@@ -11,39 +11,164 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
+ var NotificationService_1;
14
15
  Object.defineProperty(exports, "__esModule", { value: true });
15
16
  exports.NotificationService = void 0;
16
17
  const common_1 = require("@nestjs/common");
17
18
  const template_1 = require("../template");
18
19
  const email_1 = require("../email");
19
- let NotificationService = class NotificationService {
20
- constructor(templateLoader, emailService) {
20
+ const push_notification_1 = require("../push-notification");
21
+ let NotificationService = NotificationService_1 = class NotificationService {
22
+ constructor(templateLoader, emailService, pushNotificationService) {
21
23
  this.templateLoader = templateLoader;
22
24
  this.emailService = emailService;
23
- this.logger = new common_1.Logger(NotificationService.name);
25
+ this.pushNotificationService = pushNotificationService;
26
+ this.logger = new common_1.Logger(NotificationService_1.name);
27
+ const services = [];
28
+ services.push(templateLoader.constructor.name);
29
+ if (emailService)
30
+ services.push(emailService.constructor.name);
31
+ if (pushNotificationService)
32
+ services.push(pushNotificationService.constructor.name);
33
+ this.logger.log(`NotificationService initialized with ${services.join(', ')} services`);
24
34
  }
25
- async sendEmail(templateCode, email, resolveOption) {
35
+ async sendEmailRaw(message) {
26
36
  if (!this.emailService) {
27
- this.logger.error("Email Service is load configure..please configure the email option");
37
+ this.logger.error("Email Service is not configure..please configure the email option");
38
+ return {
39
+ success: false,
40
+ message: "Email Service is not configure"
41
+ };
42
+ }
43
+ return this.emailService.send(message);
44
+ }
45
+ async sendEmail(templateCodeOrPayload, email, resolveOption, attachments) {
46
+ let resolvedTemplateCode = '';
47
+ let resolvedEmail = '';
48
+ let resolvedResolveOption = {};
49
+ let resolvedAttachments = [];
50
+ if (this.isEmailPayload(templateCodeOrPayload)) {
51
+ resolvedTemplateCode = templateCodeOrPayload.templateCode;
52
+ resolvedEmail = templateCodeOrPayload.email;
53
+ resolvedResolveOption = templateCodeOrPayload.options || {};
54
+ resolvedAttachments = templateCodeOrPayload.attachments;
55
+ }
56
+ else {
57
+ resolvedTemplateCode = templateCodeOrPayload || '';
58
+ resolvedEmail = email || '';
59
+ resolvedResolveOption = resolveOption || {};
60
+ resolvedAttachments = attachments || [];
61
+ }
62
+ const templateMessage = await this.templateLoader.resolve(resolvedTemplateCode, resolvedResolveOption);
63
+ if (!templateMessage) {
64
+ this.logger.error(`Template ${resolvedTemplateCode} resolve failure. Please make sure the template has set`);
65
+ return {
66
+ success: false,
67
+ message: `Template ${resolvedTemplateCode} resolve failure. Please make sure the template has set`
68
+ };
69
+ }
70
+ return this.sendEmailRaw({
71
+ recipient: resolvedEmail,
72
+ subject: templateMessage.subject || "",
73
+ message: templateMessage.content,
74
+ attachments: resolvedAttachments,
75
+ });
76
+ }
77
+ async sendPushNotificationRaw(message) {
78
+ if (!this.pushNotificationService) {
79
+ this.logger.error("Push Notification Service is not configure..please configure the pushNotification option");
80
+ return {
81
+ success: false,
82
+ message: "Push Notification Service is not configure..please configure the pushNotification option"
83
+ };
84
+ }
85
+ return this.pushNotificationService.send(message);
86
+ }
87
+ async sendPushNotification(templateCodeOrPayload, token, resolveOption) {
88
+ let resolvedTemplateCode = '';
89
+ let resolvedToken;
90
+ let resolvedDeviceToken;
91
+ let resolvedResolveOption = {};
92
+ if (this.isPushNotificationPayload(templateCodeOrPayload)) {
93
+ resolvedTemplateCode = templateCodeOrPayload.templateCode;
94
+ resolvedResolveOption = templateCodeOrPayload.options || {};
95
+ resolvedToken = templateCodeOrPayload.userId || templateCodeOrPayload.deviceToken;
96
+ }
97
+ else {
98
+ resolvedTemplateCode = templateCodeOrPayload || '';
99
+ resolvedResolveOption = resolveOption || {};
100
+ resolvedToken = token;
101
+ }
102
+ if (!resolvedToken) {
103
+ this.logger.error(`Token is required to send push notification`);
104
+ return {
105
+ success: false,
106
+ message: `Token is required to send push notification`
107
+ };
108
+ }
109
+ if (typeof resolvedToken === 'string' || typeof resolvedToken === 'number') {
110
+ resolvedDeviceToken = await this.pushNotificationService.getUserDeviceToken(resolvedToken);
111
+ if (!resolvedDeviceToken) {
112
+ this.logger.error(`Device Token not found for user ${resolvedToken}`);
113
+ return {
114
+ success: false,
115
+ message: `Device Token not found for user ${resolvedToken}`
116
+ };
117
+ }
118
+ }
119
+ else {
120
+ resolvedDeviceToken = resolvedToken;
121
+ }
122
+ const templateMessage = await this.templateLoader.resolve(resolvedTemplateCode, resolveOption);
123
+ if (!templateMessage) {
124
+ this.logger.error(`Template ${resolvedTemplateCode} resolve failure. Please make sure the template has set`);
125
+ return {
126
+ success: false,
127
+ message: `Template ${resolvedTemplateCode} resolve failure. Please make sure the template has set`
128
+ };
129
+ }
130
+ return this.sendPushNotificationRaw({
131
+ recipient: resolvedDeviceToken.data,
132
+ paltform: resolvedDeviceToken.type,
133
+ subject: templateMessage.subject || "",
134
+ message: templateMessage.content,
135
+ });
136
+ }
137
+ async sendPushNotificationMulticastRaw(tokens, message) {
138
+ if (!this.pushNotificationService) {
139
+ this.logger.error("PushNotification Service is not configure..please configure the pushNotification option");
28
140
  return null;
29
141
  }
142
+ return this.pushNotificationService.sendMulticast(tokens, message);
143
+ }
144
+ async sendPushNotificationMulticast(templateCode, tokens, resolveOption) {
30
145
  const templateMessage = await this.templateLoader.resolve(templateCode, resolveOption);
31
146
  if (!templateMessage) {
32
147
  this.logger.error(`Template ${templateCode} Load Failed. Please make sure the template has set`);
33
148
  return null;
34
149
  }
35
- return this.emailService.send({
36
- recipient: email,
150
+ return this.sendPushNotificationMulticastRaw(tokens, {
37
151
  subject: templateMessage.subject || "",
38
152
  message: templateMessage.content,
39
153
  });
40
154
  }
155
+ isEmailPayload(value) {
156
+ return typeof value === 'object' && 'templateCode' in value && 'email' in value;
157
+ }
158
+ ;
159
+ isPushNotificationPayload(value) {
160
+ return typeof value === 'object' && 'templateCode' in value && ('userId' in value || 'deviceToken' in value);
161
+ }
41
162
  };
42
- NotificationService = __decorate([
163
+ exports.NotificationService = NotificationService;
164
+ exports.NotificationService = NotificationService = NotificationService_1 = __decorate([
43
165
  __param(0, (0, common_1.Inject)(template_1.TEMPLATE_LOADER)),
44
166
  __param(1, (0, common_1.Optional)()),
45
167
  __param(1, (0, common_1.Inject)(email_1.EmailService)),
168
+ __param(2, (0, common_1.Optional)()),
169
+ __param(2, (0, common_1.Inject)(push_notification_1.PushNotificationService)),
46
170
  __metadata("design:paramtypes", [template_1.TemplateLoader,
47
- email_1.EmailService])
171
+ email_1.EmailService,
172
+ push_notification_1.PushNotificationService])
48
173
  ], NotificationService);
49
- exports.NotificationService = NotificationService;
174
+ //# sourceMappingURL=notification.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"notification.service.js","sourceRoot":"","sources":["../../lib/notification/notification.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA0D;AAC1D,0CAA6E;AAC7E,oCAAwC;AAExC,4DAA4E;AAE5E,IAAa,mBAAmB,2BAAhC,MAAa,mBAAmB;IAG9B,YAAqC,cAA+C,EAChD,YAA2C,EAChC,uBAAiE;QAF1D,mBAAc,GAAd,cAAc,CAAgB;QAC/B,iBAAY,GAAZ,YAAY,CAAc;QACf,4BAAuB,GAAvB,uBAAuB,CAAyB;QAH/F,WAAM,GAAG,IAAI,eAAM,CAAC,qBAAmB,CAAC,IAAI,CAAC,CAAC;QAK3D,MAAM,QAAQ,GAAG,EAAE,CAAC;QACpB,QAAQ,CAAC,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAG,YAAY;YAAE,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAC9D,IAAG,uBAAuB;YAAE,QAAQ,CAAC,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAEpF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,wCAAwC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAC3F,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,OAAqB;QACtC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAA;YAEtF,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,gCAAgC;aAC1C,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IAGD,KAAK,CAAC,SAAS,CAAC,qBAAyD,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AAC,OAAO,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;QACvF,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,YAAY,qDAAqD,CAAC,CAAA;YAChG,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,gCAAgC,CAAC,MAAM,EAAE;YACnD,OAAO,EAAE,eAAe,CAAC,OAAO,IAAI,EAAE;YACtC,OAAO,EAAE,eAAe,CAAC,OAAO;SACjC,CAAC,CAAA;IACJ,CAAC;IAES,cAAc,CAAC,KAAU;QACjC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,CAAC;IAClF,CAAC;IAAA,CAAC;IAEQ,yBAAyB,CAAC,KAAU;QAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,cAAc,IAAI,KAAK,IAAI,CAAC,QAAQ,IAAI,KAAK,IAAI,aAAa,IAAI,KAAK,CAAC,CAAC;IAC/G,CAAC;CAEF,CAAA;AAhKY,kDAAmB;8BAAnB,mBAAmB;IAGjB,WAAA,IAAA,eAAM,EAAC,0BAAe,CAAC,CAAA;IACjC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,oBAAY,CAAC,CAAA;IAChC,WAAA,IAAA,iBAAQ,GAAE,CAAA;IAAE,WAAA,IAAA,eAAM,EAAC,2CAAuB,CAAC,CAAA;qCAFwB,yBAAc;QACjB,oBAAY;QACU,2CAAuB;GALrG,mBAAmB,CAgK/B"}
@@ -0,0 +1 @@
1
+ export declare const PUSH_NOTIFICATION_PROVIDERS = "PUSH_NOTIFICATION_PROVIDERS";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PUSH_NOTIFICATION_PROVIDERS = void 0;
4
+ exports.PUSH_NOTIFICATION_PROVIDERS = 'PUSH_NOTIFICATION_PROVIDERS';
5
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","sourceRoot":"","sources":["../../lib/push-notification/constant.ts"],"names":[],"mappings":";;;AAAa,QAAA,2BAA2B,GAAG,6BAA6B,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { FCMPushNotificationOption, PushNotificationPlatform } from "./push-notification.interface";
2
+ import { PushNotificationProvider } from "./push-notification.provider";
3
+ import { PushMessage, SendResult, PushMessageOnly, BatchSendResult } from "../interface";
4
+ export declare class FCMPushNotificationProvider extends PushNotificationProvider {
5
+ private readonly option;
6
+ private readonly client;
7
+ constructor(option: FCMPushNotificationOption);
8
+ get type(): PushNotificationPlatform;
9
+ send(message: PushMessage): Promise<SendResult>;
10
+ sendMulticast(tokens: string[], message: PushMessageOnly): Promise<BatchSendResult>;
11
+ private generateMessage;
12
+ private getFirebaseMessage;
13
+ }
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FCMPushNotificationProvider = void 0;
4
+ const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
5
+ const push_notification_provider_1 = require("./push-notification.provider");
6
+ const common_1 = require("@nathapp/common");
7
+ class FCMPushNotificationProvider extends push_notification_provider_1.PushNotificationProvider {
8
+ constructor(option) {
9
+ super();
10
+ const Firebase = (0, load_package_util_1.loadPackage)('firebase-admin', FCMPushNotificationProvider.name, () => require('firebase-admin'));
11
+ this.option = option;
12
+ this.client = Firebase.initializeApp({
13
+ credential: Firebase.credential.cert(JSON.parse(option.serviceAccount)),
14
+ databaseURL: option.databaseUrl,
15
+ });
16
+ }
17
+ get type() {
18
+ return "firebase";
19
+ }
20
+ async send(message) {
21
+ const firebaseMessage = this.generateMessage(message);
22
+ const messageId = await this.client.messaging().send(firebaseMessage);
23
+ return {
24
+ success: !(0, common_1.isUndefinedOrNullOrEmpty)(messageId),
25
+ requestId: messageId,
26
+ };
27
+ }
28
+ async sendMulticast(tokens, message) {
29
+ const multicastMessage = this.getFirebaseMessage(tokens, message);
30
+ const batchResponse = await this.client.messaging().sendEachForMulticast(multicastMessage);
31
+ return {
32
+ results: batchResponse.responses.map(response => {
33
+ var _a;
34
+ return {
35
+ success: response.success,
36
+ requestId: response.messageId,
37
+ message: (_a = response.error) === null || _a === void 0 ? void 0 : _a.message,
38
+ extra: response.error
39
+ };
40
+ }),
41
+ successCount: batchResponse.successCount,
42
+ failureCount: batchResponse.failureCount,
43
+ };
44
+ }
45
+ generateMessage(pushMessage) {
46
+ return this.getFirebaseMessage(pushMessage.recipient, pushMessage);
47
+ }
48
+ getFirebaseMessage(token, pushMessage) {
49
+ const partialMessage = {
50
+ notification: {
51
+ title: pushMessage.subject,
52
+ body: pushMessage.message,
53
+ },
54
+ data: pushMessage.data,
55
+ apns: {
56
+ payload: {
57
+ aps: {
58
+ mutableContent: true,
59
+ contentAvailable: true,
60
+ apnsPushType: "background"
61
+ }
62
+ }
63
+ },
64
+ };
65
+ if (Array.isArray(token)) {
66
+ return {
67
+ ...partialMessage,
68
+ tokens: token
69
+ };
70
+ }
71
+ return {
72
+ ...partialMessage,
73
+ token: token
74
+ };
75
+ }
76
+ }
77
+ exports.FCMPushNotificationProvider = FCMPushNotificationProvider;
78
+ //# sourceMappingURL=fcm-push-notification.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fcm-push-notification.provider.js","sourceRoot":"","sources":["../../lib/push-notification/fcm-push-notification.provider.ts"],"names":[],"mappings":";;;AAEA,8EAAqE;AACrE,6EAAwE;AAExE,4CAA2D;AAK3D,MAAa,2BAA4B,SAAQ,qDAAwB;IAGvE,YAAY,MAAiC;QAC3C,KAAK,EAAE,CAAC;QACR,MAAM,QAAQ,GAAG,IAAA,+BAAW,EAAC,gBAAgB,EAAE,2BAA2B,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAClH,IAAI,CAAC,MA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