@thescaffold/ntx-apps-notification 0.0.10

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 (135) hide show
  1. package/README.md +1 -0
  2. package/api/log/dto/create-log.dto.d.ts +20 -0
  3. package/api/log/dto/create-log.dto.js +123 -0
  4. package/api/log/dto/create-log.dto.js.map +1 -0
  5. package/api/log/dto/update-log.dto.d.ts +20 -0
  6. package/api/log/dto/update-log.dto.js +126 -0
  7. package/api/log/dto/update-log.dto.js.map +1 -0
  8. package/api/log/entities/log.entity.d.ts +30 -0
  9. package/api/log/entities/log.entity.js +163 -0
  10. package/api/log/entities/log.entity.js.map +1 -0
  11. package/api/log/index.d.ts +6 -0
  12. package/api/log/index.js +23 -0
  13. package/api/log/index.js.map +1 -0
  14. package/api/log/log.controller.d.ts +34 -0
  15. package/api/log/log.controller.js +105 -0
  16. package/api/log/log.controller.js.map +1 -0
  17. package/api/log/log.module.d.ts +2 -0
  18. package/api/log/log.module.js +34 -0
  19. package/api/log/log.module.js.map +1 -0
  20. package/api/log/log.service.d.ts +22 -0
  21. package/api/log/log.service.js +65 -0
  22. package/api/log/log.service.js.map +1 -0
  23. package/api/message/dto/create-message.dto.d.ts +17 -0
  24. package/api/message/dto/create-message.dto.js +105 -0
  25. package/api/message/dto/create-message.dto.js.map +1 -0
  26. package/api/message/dto/update-message.dto.d.ts +17 -0
  27. package/api/message/dto/update-message.dto.js +108 -0
  28. package/api/message/dto/update-message.dto.js.map +1 -0
  29. package/api/message/entities/message.entity.d.ts +22 -0
  30. package/api/message/entities/message.entity.js +135 -0
  31. package/api/message/entities/message.entity.js.map +1 -0
  32. package/api/message/index.d.ts +6 -0
  33. package/api/message/index.js +23 -0
  34. package/api/message/index.js.map +1 -0
  35. package/api/message/message.controller.d.ts +24 -0
  36. package/api/message/message.controller.js +50 -0
  37. package/api/message/message.controller.js.map +1 -0
  38. package/api/message/message.module.d.ts +2 -0
  39. package/api/message/message.module.js +27 -0
  40. package/api/message/message.module.js.map +1 -0
  41. package/api/message/message.service.d.ts +22 -0
  42. package/api/message/message.service.js +65 -0
  43. package/api/message/message.service.js.map +1 -0
  44. package/api/rule/dto/create-rule.dto.d.ts +6 -0
  45. package/api/rule/dto/create-rule.dto.js +39 -0
  46. package/api/rule/dto/create-rule.dto.js.map +1 -0
  47. package/api/rule/dto/update-rule.dto.d.ts +6 -0
  48. package/api/rule/dto/update-rule.dto.js +42 -0
  49. package/api/rule/dto/update-rule.dto.js.map +1 -0
  50. package/api/rule/entities/rule.entity.d.ts +9 -0
  51. package/api/rule/entities/rule.entity.js +47 -0
  52. package/api/rule/entities/rule.entity.js.map +1 -0
  53. package/api/rule/index.d.ts +6 -0
  54. package/api/rule/index.js +23 -0
  55. package/api/rule/index.js.map +1 -0
  56. package/api/rule/rule.controller.d.ts +21 -0
  57. package/api/rule/rule.controller.js +40 -0
  58. package/api/rule/rule.controller.js.map +1 -0
  59. package/api/rule/rule.module.d.ts +2 -0
  60. package/api/rule/rule.module.js +27 -0
  61. package/api/rule/rule.module.js.map +1 -0
  62. package/api/rule/rule.service.d.ts +13 -0
  63. package/api/rule/rule.service.js +46 -0
  64. package/api/rule/rule.service.js.map +1 -0
  65. package/api/template/dto/create-template.dto.d.ts +7 -0
  66. package/api/template/dto/create-template.dto.js +46 -0
  67. package/api/template/dto/create-template.dto.js.map +1 -0
  68. package/api/template/dto/update-template.dto.d.ts +7 -0
  69. package/api/template/dto/update-template.dto.js +48 -0
  70. package/api/template/dto/update-template.dto.js.map +1 -0
  71. package/api/template/entities/template.entity.d.ts +12 -0
  72. package/api/template/entities/template.entity.js +59 -0
  73. package/api/template/entities/template.entity.js.map +1 -0
  74. package/api/template/index.d.ts +6 -0
  75. package/api/template/index.js +23 -0
  76. package/api/template/index.js.map +1 -0
  77. package/api/template/template.controller.d.ts +21 -0
  78. package/api/template/template.controller.js +40 -0
  79. package/api/template/template.controller.js.map +1 -0
  80. package/api/template/template.module.d.ts +2 -0
  81. package/api/template/template.module.js +27 -0
  82. package/api/template/template.module.js.map +1 -0
  83. package/api/template/template.service.d.ts +13 -0
  84. package/api/template/template.service.js +46 -0
  85. package/api/template/template.service.js.map +1 -0
  86. package/app.config.d.ts +2 -0
  87. package/app.config.js +16 -0
  88. package/app.config.js.map +1 -0
  89. package/app.controller.d.ts +54 -0
  90. package/app.controller.js +259 -0
  91. package/app.controller.js.map +1 -0
  92. package/app.dto.d.ts +46 -0
  93. package/app.dto.js +58 -0
  94. package/app.dto.js.map +1 -0
  95. package/app.module.d.ts +2 -0
  96. package/app.module.js +58 -0
  97. package/app.module.js.map +1 -0
  98. package/app.service.d.ts +3 -0
  99. package/app.service.js +20 -0
  100. package/app.service.js.map +1 -0
  101. package/index.d.ts +30 -0
  102. package/index.js +69 -0
  103. package/index.js.map +1 -0
  104. package/migrations/1749979429709-NotificationLogs.d.ts +5 -0
  105. package/migrations/1749979429709-NotificationLogs.js +61 -0
  106. package/migrations/1749979429709-NotificationLogs.js.map +1 -0
  107. package/migrations/1749979429775-NotificationRules.d.ts +5 -0
  108. package/migrations/1749979429775-NotificationRules.js +32 -0
  109. package/migrations/1749979429775-NotificationRules.js.map +1 -0
  110. package/migrations/1749979429841-NotificationTemplates.d.ts +5 -0
  111. package/migrations/1749979429841-NotificationTemplates.js +36 -0
  112. package/migrations/1749979429841-NotificationTemplates.js.map +1 -0
  113. package/migrations/1749979429845-NotificationMessages.d.ts +5 -0
  114. package/migrations/1749979429845-NotificationMessages.js +58 -0
  115. package/migrations/1749979429845-NotificationMessages.js.map +1 -0
  116. package/migrations/index.d.ts +2 -0
  117. package/migrations/index.js +14 -0
  118. package/migrations/index.js.map +1 -0
  119. package/package.json +18 -0
  120. package/pkg/provider/mailgun/mailgun.service.d.ts +19 -0
  121. package/pkg/provider/mailgun/mailgun.service.js +84 -0
  122. package/pkg/provider/mailgun/mailgun.service.js.map +1 -0
  123. package/pkg/provider/provider.interface.d.ts +25 -0
  124. package/pkg/provider/provider.interface.js +3 -0
  125. package/pkg/provider/provider.interface.js.map +1 -0
  126. package/pkg/provider/provider.module.d.ts +2 -0
  127. package/pkg/provider/provider.module.js +26 -0
  128. package/pkg/provider/provider.module.js.map +1 -0
  129. package/pkg/provider/provider.service.d.ts +29 -0
  130. package/pkg/provider/provider.service.js +204 -0
  131. package/pkg/provider/provider.service.js.map +1 -0
  132. package/pkg/provider/zoho/zoho.service.d.ts +20 -0
  133. package/pkg/provider/zoho/zoho.service.js +94 -0
  134. package/pkg/provider/zoho/zoho.service.js.map +1 -0
  135. package/tsconfig.lib.tsbuildinfo +1 -0
@@ -0,0 +1,204 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ProviderService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const config_1 = require("@nestjs/config");
15
+ const ntx_apps_identity_1 = require("@thescaffold/ntx-apps-identity");
16
+ const ntx_core_1 = require("@thescaffold/ntx-core");
17
+ const mustache_1 = require("mustache");
18
+ const typeorm_1 = require("typeorm");
19
+ const log_entity_1 = require("../../api/log/entities/log.entity");
20
+ const rule_entity_1 = require("../../api/rule/entities/rule.entity");
21
+ const template_entity_1 = require("../../api/template/entities/template.entity");
22
+ const app_config_1 = require("../../app.config");
23
+ const app_dto_1 = require("../../app.dto");
24
+ const mailgun_service_1 = require("./mailgun/mailgun.service");
25
+ const zoho_service_1 = require("./zoho/zoho.service");
26
+ let ProviderService = class ProviderService {
27
+ constructor(mailgunService, zohoService, configService, mediaService, dataSource, platformService, trackerService, identityAppService) {
28
+ this.mailgunService = mailgunService;
29
+ this.zohoService = zohoService;
30
+ this.configService = configService;
31
+ this.mediaService = mediaService;
32
+ this.dataSource = dataSource;
33
+ this.platformService = platformService;
34
+ this.trackerService = trackerService;
35
+ this.identityAppService = identityAppService;
36
+ this.providers = {
37
+ [app_dto_1.ProviderName.Mailgun]: mailgunService,
38
+ [app_dto_1.ProviderName.Zoho]: zohoService,
39
+ };
40
+ }
41
+ use(providerType) {
42
+ const clonedThis = (0, ntx_core_1.clone)(this);
43
+ clonedThis.provider = this.providers[providerType];
44
+ return clonedThis;
45
+ }
46
+ email(message) {
47
+ return this.provider.email(message);
48
+ }
49
+ sms(message) {
50
+ return this.provider.sms(message);
51
+ }
52
+ web(message) {
53
+ return this.provider.web(message);
54
+ }
55
+ mobile(message) {
56
+ return this.provider.mobile(message);
57
+ }
58
+ async send(log) {
59
+ var _a, _b, _c, _d;
60
+ const { userId, clientId, workspaceId, key, data } = log;
61
+ const context = await this.identityAppService.contextByUserId(userId);
62
+ if (!((_a = context === null || context === void 0 ? void 0 : context.user) === null || _a === void 0 ? void 0 : _a.ref)) {
63
+ this.sendWithoutContext(log);
64
+ this.trackerService.message('apps.common.log.error', {
65
+ context,
66
+ log,
67
+ trace: (0, ntx_core_1.stackTrace)(),
68
+ });
69
+ return;
70
+ }
71
+ const rule = await this.dataSource.getRepository(rule_entity_1.Rule).findOne({
72
+ where: [{ key }],
73
+ });
74
+ const groupName = this.configService.get('GROUP_NAME');
75
+ const template = await this.dataSource.getRepository(template_entity_1.Template).findOne({
76
+ where: [{ key, group: groupName }],
77
+ });
78
+ const { user, attributes, workspaces } = context;
79
+ const to = (_b = data === null || data === void 0 ? void 0 : data.owner) !== null && _b !== void 0 ? _b : user === null || user === void 0 ? void 0 : user.ref;
80
+ if (!to) {
81
+ return;
82
+ }
83
+ const notification = attributes === null || attributes === void 0 ? void 0 : attributes.notification;
84
+ const address = attributes === null || attributes === void 0 ? void 0 : attributes.address;
85
+ const preference = attributes === null || attributes === void 0 ? void 0 : attributes.preference;
86
+ const organization = attributes === null || attributes === void 0 ? void 0 : attributes.organization;
87
+ const { channels, subject } = log;
88
+ const provider = this.configService.get('NOTIFICATION_DEFAULT_PROVIDER');
89
+ let result = [];
90
+ for (let index = 0; index < channels.length; index++) {
91
+ const channel = channels[index];
92
+ if (!channel) {
93
+ continue;
94
+ }
95
+ const typeChannels = notification && log.type in notification
96
+ ? notification[log.type]
97
+ : (0, app_config_1.defaultMessageTypeChannels)(log.type);
98
+ if (!typeChannels.includes(channel)) {
99
+ continue;
100
+ }
101
+ let templateValue;
102
+ if ((_c = template[channel]) === null || _c === void 0 ? void 0 : _c.endsWith('.html')) {
103
+ templateValue = await this.mediaService.loadAndGet(template[channel]);
104
+ }
105
+ else if (template[channel].length) {
106
+ templateValue = template[channel];
107
+ }
108
+ if (!templateValue || !templateValue.length) {
109
+ continue;
110
+ }
111
+ const now = ntx_core_1.time.utc().now();
112
+ const message = {
113
+ to,
114
+ subject,
115
+ html: (0, mustache_1.render)(templateValue, Object.assign(Object.assign({ user: Object.assign(Object.assign({}, user), ((_d = attributes === null || attributes === void 0 ? void 0 : attributes.user) !== null && _d !== void 0 ? _d : {})), address,
116
+ preference,
117
+ organization, now: {
118
+ dateTime: now.format(ntx_core_1.FORMAT.FULL_DATE_TIME),
119
+ time: now.format(ntx_core_1.FORMAT.DATE),
120
+ date: now.format(ntx_core_1.FORMAT.FULL_TIME),
121
+ day: now.format('DD'),
122
+ month: now.format('MM'),
123
+ year: now.format('YYYY'),
124
+ } }, ntx_core_1.renderUtils), data)),
125
+ log,
126
+ };
127
+ const status = await this.use(provider)[channel](message);
128
+ result.push({ channel, status, message });
129
+ }
130
+ await this.dataSource.getRepository(log_entity_1.Log).update(log.id, {
131
+ message: result,
132
+ templateId: template === null || template === void 0 ? void 0 : template.id,
133
+ ruleId: rule === null || rule === void 0 ? void 0 : rule.id,
134
+ });
135
+ }
136
+ async sendWithoutContext(log) {
137
+ var _a;
138
+ const { key, data, clientId } = log;
139
+ const rule = await this.dataSource.getRepository(rule_entity_1.Rule).findOne({
140
+ where: [{ key }],
141
+ });
142
+ const groupName = this.configService.get('GROUP_NAME');
143
+ const template = await this.dataSource.getRepository(template_entity_1.Template).findOne({
144
+ where: [{ key, group: groupName }],
145
+ });
146
+ const to = data === null || data === void 0 ? void 0 : data.owner;
147
+ if (!to) {
148
+ return;
149
+ }
150
+ const { channels, subject } = log;
151
+ const provider = this.configService.get('NOTIFICATION_DEFAULT_PROVIDER');
152
+ let result = [];
153
+ for (let index = 0; index < channels.length; index++) {
154
+ const channel = channels[index];
155
+ if (!channel) {
156
+ continue;
157
+ }
158
+ let templateValue;
159
+ if ((_a = template[channel]) === null || _a === void 0 ? void 0 : _a.endsWith('.html')) {
160
+ templateValue = await this.mediaService.loadAndGet(template[channel]);
161
+ }
162
+ else if (template[channel].length) {
163
+ templateValue = template[channel];
164
+ }
165
+ if (!templateValue || !templateValue.length) {
166
+ continue;
167
+ }
168
+ const now = ntx_core_1.time.utc().now();
169
+ const message = {
170
+ to,
171
+ subject,
172
+ html: (0, mustache_1.render)(templateValue, Object.assign(Object.assign({ now: {
173
+ dateTime: now.format(ntx_core_1.FORMAT.FULL_DATE_TIME),
174
+ time: now.format(ntx_core_1.FORMAT.DATE),
175
+ date: now.format(ntx_core_1.FORMAT.FULL_TIME),
176
+ day: now.format('DD'),
177
+ month: now.format('MM'),
178
+ year: now.format('YYYY'),
179
+ } }, ntx_core_1.renderUtils), data)),
180
+ log,
181
+ };
182
+ const status = await this.use(provider)[channel](message);
183
+ result.push({ channel, status, message });
184
+ }
185
+ await this.dataSource.getRepository(log_entity_1.Log).update(log.id, {
186
+ message: result,
187
+ templateId: template === null || template === void 0 ? void 0 : template.id,
188
+ ruleId: rule === null || rule === void 0 ? void 0 : rule.id,
189
+ });
190
+ }
191
+ };
192
+ exports.ProviderService = ProviderService;
193
+ exports.ProviderService = ProviderService = __decorate([
194
+ (0, common_1.Injectable)(),
195
+ __metadata("design:paramtypes", [mailgun_service_1.MailgunService,
196
+ zoho_service_1.ZohoService,
197
+ config_1.ConfigService,
198
+ ntx_core_1.MediaService,
199
+ typeorm_1.DataSource,
200
+ ntx_core_1.PlatformService,
201
+ ntx_core_1.TrackerService,
202
+ ntx_apps_identity_1.AppService])
203
+ ], ProviderService);
204
+ //# sourceMappingURL=provider.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.service.js","sourceRoot":"","sources":["../../../../../libs/notification/src/pkg/provider/provider.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,sEAAkF;AAClF,oDAS+B;AAC/B,uCAAkC;AAClC,qCAAqC;AACrC,kEAAwD;AACxD,qEAA2D;AAC3D,iFAAuE;AACvE,iDAA8D;AAC9D,2CAA6C;AAC7C,+DAA2D;AAQ3D,sDAAkD;AAG3C,IAAM,eAAe,GAArB,MAAM,eAAe;IAI1B,YACmB,cAA8B,EAC9B,WAAwB,EACxB,aAA4B,EAC5B,YAA0B,EAC1B,UAAsB,EACpB,eAAgC,EAClC,cAA8B,EAC9B,kBAAsC;QAPtC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAY;QACpB,oBAAe,GAAf,eAAe,CAAiB;QAClC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,uBAAkB,GAAlB,kBAAkB,CAAoB;QAEvD,IAAI,CAAC,SAAS,GAAG;YACf,CAAC,sBAAY,CAAC,OAAO,CAAC,EAAE,cAAc;YACtC,CAAC,sBAAY,CAAC,IAAI,CAAC,EAAE,W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ConfigService } from '@nestjs/config';
2
+ import { QuickHttpService } from '@thescaffold/ntx-core';
3
+ import { DataSource } from 'typeorm';
4
+ import { EmailMessage, MobileMessage, ProviderContract, SMSMessage, WebMessage } from '../provider.interface';
5
+ export declare class ZohoService implements ProviderContract {
6
+ private readonly quickHttpService;
7
+ private readonly configService;
8
+ private readonly dataSource;
9
+ private baseurl;
10
+ private domain;
11
+ private token;
12
+ private fromEmail;
13
+ private fromName;
14
+ constructor(quickHttpService: QuickHttpService, configService: ConfigService, dataSource: DataSource);
15
+ email(message: EmailMessage): Promise<boolean>;
16
+ sms(message: SMSMessage): Promise<boolean>;
17
+ web(message: WebMessage): Promise<boolean>;
18
+ mobile(message: MobileMessage): Promise<boolean>;
19
+ render(template: string, data: any): string;
20
+ }
@@ -0,0 +1,94 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ZohoService = void 0;
13
+ const common_1 = require("@nestjs/common");
14
+ const config_1 = require("@nestjs/config");
15
+ const ntx_core_1 = require("@thescaffold/ntx-core");
16
+ const mustache_1 = require("mustache");
17
+ const typeorm_1 = require("typeorm");
18
+ const message_1 = require("../../../api/message");
19
+ const app_dto_1 = require("../../../app.dto");
20
+ let ZohoService = class ZohoService {
21
+ constructor(quickHttpService, configService, dataSource) {
22
+ this.quickHttpService = quickHttpService;
23
+ this.configService = configService;
24
+ this.dataSource = dataSource;
25
+ this.baseurl = this.configService.get('ZOHO_BASE_URL');
26
+ this.domain = this.configService.get('ZOHO_DOMAIN');
27
+ this.token = this.configService.get('ZOHO_TOKEN');
28
+ this.fromEmail = this.configService.get('ZOHO_FROM_EMAIL');
29
+ this.fromName = this.configService.get('ZOHO_FROM_NAME');
30
+ }
31
+ async email(message) {
32
+ var _a, _b;
33
+ const [status, httpStatus, title, rMessage, response] = await this.quickHttpService.external('POST', `${this.baseurl}/v1.1/email`, {
34
+ from: {
35
+ address: (_a = message.from) !== null && _a !== void 0 ? _a : this.fromEmail,
36
+ name: (_b = message.name) !== null && _b !== void 0 ? _b : this.fromName,
37
+ },
38
+ to: [
39
+ {
40
+ email_address: {
41
+ address: message.to,
42
+ },
43
+ },
44
+ ],
45
+ subject: message.subject,
46
+ htmlbody: message.html,
47
+ }, null, {
48
+ authorization: `Zoho-enczapikey ${this.token}`,
49
+ accept: 'application/json',
50
+ 'content-type': 'application/json',
51
+ });
52
+ return status == true;
53
+ }
54
+ async sms(message) {
55
+ return false;
56
+ }
57
+ async web(message) {
58
+ const log = message.log;
59
+ await this.dataSource.getRepository(message_1.Message).save({
60
+ reference: log.reference,
61
+ userId: log.userId,
62
+ clientId: log.clientId,
63
+ workspaceId: log.workspaceId,
64
+ key: log.key,
65
+ subject: log.subject,
66
+ channel: app_dto_1.MessageChannelType.Web,
67
+ data: log.data,
68
+ readAt: log.readAt,
69
+ publishAt: log.publishAt,
70
+ expireAt: log.expireAt,
71
+ type: log.type,
72
+ priority: log.priority,
73
+ theme: log.theme,
74
+ scope: log.scope,
75
+ position: log.position,
76
+ status: log.status,
77
+ });
78
+ return true;
79
+ }
80
+ async mobile(message) {
81
+ return false;
82
+ }
83
+ render(template, data) {
84
+ return (0, mustache_1.render)(template, Object.assign(Object.assign({}, data), ntx_core_1.renderUtils));
85
+ }
86
+ };
87
+ exports.ZohoService = ZohoService;
88
+ exports.ZohoService = ZohoService = __decorate([
89
+ (0, common_1.Injectable)(),
90
+ __metadata("design:paramtypes", [ntx_core_1.QuickHttpService,
91
+ config_1.ConfigService,
92
+ typeorm_1.DataSource])
93
+ ], ZohoService);
94
+ //# sourceMappingURL=zoho.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zoho.service.js","sourceRoot":"","sources":["../../../../../../libs/notification/src/pkg/provider/zoho/zoho.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,2CAA+C;AAC/C,oDAAsE;AACtE,uCAAkC;AAClC,qCAAqC;AACrC,kDAA+C;AAC/C,8CAAsD;AAU/C,IAAM,WAAW,GAAjB,MAAM,WAAW;IAOtB,YACmB,gBAAkC,EAClC,aAA4B,EAC5B,UAAsB;QAFtB,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,kBAAa,GAAb,aAAa,CAAe;QAC5B,eAAU,GAAV,UAAU,CAAY;QATjC,YAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAClD,WAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;QAC/C,UAAK,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC7C,cAAS,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACtD,aAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IAMzD,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAAqB;;QAC/B,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,CAAC,GACnD,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAClC,MAAM,EACN,GAAG,IAAI,CAAC,OAAO,aAAa,EAC5B;YACE,IAAI,EAAE;gBACJ,OAAO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