rez_core 2.2.203 → 2.2.204
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/package.json
CHANGED
|
@@ -23,9 +23,16 @@ export class WrapperService {
|
|
|
23
23
|
*/
|
|
24
24
|
async sendMailWrapper(payload: any, loggedInUser: any) {
|
|
25
25
|
try {
|
|
26
|
+
this.logger.log(
|
|
27
|
+
`sendMailWrapper called. User: ${JSON.stringify(loggedInUser)}, Payload: ${JSON.stringify(payload)}`,
|
|
28
|
+
);
|
|
29
|
+
|
|
26
30
|
const { level_id, level_type, organization_id } = loggedInUser;
|
|
27
31
|
|
|
28
32
|
// 1. Check for config at user’s level
|
|
33
|
+
this.logger.debug(
|
|
34
|
+
`Fetching configs for level_id=${level_id}, level_type=${level_type}`,
|
|
35
|
+
);
|
|
29
36
|
const configs = await this.datasource.query(
|
|
30
37
|
`SELECT *
|
|
31
38
|
FROM cr_communication_hub
|
|
@@ -34,24 +41,35 @@ export class WrapperService {
|
|
|
34
41
|
AND communication_config_type = 'EMAIL'`,
|
|
35
42
|
[level_id, level_type],
|
|
36
43
|
);
|
|
44
|
+
this.logger.debug(`Configs found: ${JSON.stringify(configs)}`);
|
|
37
45
|
|
|
38
46
|
let templateCode: string | undefined;
|
|
39
47
|
|
|
40
48
|
if (payload.templateCode) {
|
|
41
|
-
|
|
49
|
+
this.logger.debug(
|
|
50
|
+
`Looking up templateCode=${payload.templateCode} for current level`,
|
|
51
|
+
);
|
|
42
52
|
const template = await this.datasource.query(
|
|
43
53
|
`SELECT rich_text FROM cr_wf_comm_template WHERE code = ? AND level_id = ? AND level_type = ? LIMIT 1`,
|
|
44
54
|
[payload.templateCode, level_id, level_type],
|
|
45
55
|
);
|
|
56
|
+
this.logger.debug(
|
|
57
|
+
`Template lookup result: ${JSON.stringify(template)}`,
|
|
58
|
+
);
|
|
46
59
|
|
|
47
60
|
if (template && template.length > 0) {
|
|
48
|
-
templateCode = template[0]
|
|
61
|
+
templateCode = template[0]?.rich_text;
|
|
49
62
|
} else {
|
|
50
|
-
|
|
63
|
+
this.logger.warn(
|
|
64
|
+
`Template not found at user level. Falling back to ORG-level template`,
|
|
65
|
+
);
|
|
51
66
|
const fallbackTemplate = await this.datasource.query(
|
|
52
67
|
`SELECT code FROM cr_wf_comm_template WHERE code = ? AND level_id = ? AND level_type = 'ORG' LIMIT 1`,
|
|
53
68
|
[payload.templateCode, organization_id],
|
|
54
69
|
);
|
|
70
|
+
this.logger.debug(
|
|
71
|
+
`Fallback template lookup: ${JSON.stringify(fallbackTemplate)}`,
|
|
72
|
+
);
|
|
55
73
|
|
|
56
74
|
if (!fallbackTemplate || fallbackTemplate.length === 0) {
|
|
57
75
|
throw new Error(
|
|
@@ -66,6 +84,7 @@ export class WrapperService {
|
|
|
66
84
|
let payloadSendMail: GenericMessageDto;
|
|
67
85
|
|
|
68
86
|
if (configs && configs.length > 0) {
|
|
87
|
+
this.logger.debug(`Using user-level configs`);
|
|
69
88
|
payloadSendMail = {
|
|
70
89
|
levelId: level_id,
|
|
71
90
|
levelType: level_type,
|
|
@@ -81,13 +100,18 @@ export class WrapperService {
|
|
|
81
100
|
variables: payload.variables,
|
|
82
101
|
};
|
|
83
102
|
} else {
|
|
84
|
-
|
|
103
|
+
this.logger.warn(
|
|
104
|
+
`No user-level configs found. Falling back to ORG-level`,
|
|
105
|
+
);
|
|
85
106
|
const fallbackConfigs = await this.datasource.query(
|
|
86
107
|
`SELECT *
|
|
87
108
|
FROM cr_communication_hub
|
|
88
109
|
WHERE level_type = 'ORG'
|
|
89
110
|
AND communication_config_type = 'EMAIL'`,
|
|
90
111
|
);
|
|
112
|
+
this.logger.debug(
|
|
113
|
+
`ORG-level configs: ${JSON.stringify(fallbackConfigs)}`,
|
|
114
|
+
);
|
|
91
115
|
|
|
92
116
|
if (!fallbackConfigs || fallbackConfigs.length === 0) {
|
|
93
117
|
throw new Error('No active email communication config found');
|
|
@@ -102,23 +126,30 @@ export class WrapperService {
|
|
|
102
126
|
type: 'EMAIL',
|
|
103
127
|
cc: payload.cc,
|
|
104
128
|
bcc: payload.bcc,
|
|
105
|
-
html: payload.
|
|
129
|
+
html: payload.message,
|
|
106
130
|
attachments: payload.attachments,
|
|
107
131
|
templateId: payload.templateId,
|
|
108
132
|
variables: payload.variables,
|
|
109
133
|
};
|
|
110
134
|
}
|
|
111
135
|
|
|
112
|
-
|
|
136
|
+
this.logger.debug(
|
|
137
|
+
`Final payload for CommunicationService: ${JSON.stringify(payloadSendMail)}`,
|
|
138
|
+
);
|
|
139
|
+
|
|
113
140
|
const result =
|
|
114
141
|
await this.communicationService.sendGenericMessage(payloadSendMail);
|
|
115
142
|
|
|
143
|
+
this.logger.log(
|
|
144
|
+
`sendMailWrapper SUCCESS. Result: ${JSON.stringify(result)}`,
|
|
145
|
+
);
|
|
146
|
+
|
|
116
147
|
return {
|
|
117
148
|
success: true,
|
|
118
149
|
data: result,
|
|
119
150
|
};
|
|
120
151
|
} catch (error: any) {
|
|
121
|
-
this.logger.error(
|
|
152
|
+
this.logger.error(`sendMailWrapper ERROR: ${error.message}`, error.stack);
|
|
122
153
|
return {
|
|
123
154
|
success: false,
|
|
124
155
|
error: error.message,
|
|
@@ -127,42 +158,52 @@ export class WrapperService {
|
|
|
127
158
|
}
|
|
128
159
|
|
|
129
160
|
/**
|
|
130
|
-
* Wrapper for scheduling meeting
|
|
131
|
-
* or fallback to sending ICS as email attachment
|
|
161
|
+
* Wrapper for scheduling meeting
|
|
132
162
|
*/
|
|
133
163
|
async scheduleMeetingWrapper(payload: any, loggedInUser: any) {
|
|
134
164
|
try {
|
|
135
165
|
this.logger.log(
|
|
136
|
-
`scheduleMeetingWrapper called by user
|
|
166
|
+
`scheduleMeetingWrapper called by user=${loggedInUser?.id || 'unknown'} Payload=${JSON.stringify(payload)}`,
|
|
137
167
|
);
|
|
138
168
|
|
|
139
169
|
const { level_id, level_type } = loggedInUser;
|
|
140
170
|
|
|
141
171
|
// 1. Try user-level config
|
|
172
|
+
this.logger.debug(
|
|
173
|
+
`Fetching user-level config for scheduling. level_id=${level_id}, level_type=${level_type}`,
|
|
174
|
+
);
|
|
142
175
|
const userConfigs = await this.datasource.query(
|
|
143
176
|
`SELECT *
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
FROM cr_communication_hub
|
|
178
|
+
WHERE level_id = ?
|
|
179
|
+
AND level_type = ?
|
|
180
|
+
AND communication_config_type = 'EMAIL'
|
|
181
|
+
AND service = 'API'`,
|
|
149
182
|
[level_id, level_type],
|
|
150
183
|
);
|
|
184
|
+
this.logger.debug(`User configs found: ${JSON.stringify(userConfigs)}`);
|
|
151
185
|
|
|
152
186
|
if (userConfigs && userConfigs.length > 0) {
|
|
153
187
|
const provider = userConfigs[0]?.provider;
|
|
154
188
|
const configId = userConfigs[0]?.config_id;
|
|
189
|
+
this.logger.debug(
|
|
190
|
+
`User config provider=${provider}, configId=${configId}`,
|
|
191
|
+
);
|
|
155
192
|
|
|
156
193
|
if (provider === 'gmail') {
|
|
157
|
-
|
|
194
|
+
this.logger.log(`Using Google Calendar for scheduling`);
|
|
158
195
|
const creds = await this.getConfigCred(configId);
|
|
196
|
+
this.logger.debug(`Google creds: ${JSON.stringify(creds)}`);
|
|
159
197
|
if (creds) {
|
|
160
198
|
const result = await this.googleService.createEvent(creds, payload);
|
|
199
|
+
this.logger.log(
|
|
200
|
+
`Google Calendar createEvent SUCCESS: ${JSON.stringify(result)}`,
|
|
201
|
+
);
|
|
161
202
|
return { success: true, data: result };
|
|
162
203
|
}
|
|
163
204
|
}
|
|
164
205
|
|
|
165
|
-
|
|
206
|
+
this.logger.log(`Non-Gmail provider detected. Falling back to ICS`);
|
|
166
207
|
const result = await this.sendIcsFallback(
|
|
167
208
|
payload,
|
|
168
209
|
level_id,
|
|
@@ -172,38 +213,55 @@ export class WrapperService {
|
|
|
172
213
|
}
|
|
173
214
|
|
|
174
215
|
// 2. Fallback to ORG-level config
|
|
216
|
+
this.logger.warn(
|
|
217
|
+
`No user-level config found. Checking ORG-level configs...`,
|
|
218
|
+
);
|
|
175
219
|
const orgConfigs = await this.datasource.query(
|
|
176
220
|
`SELECT *
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
221
|
+
FROM cr_communication_hub
|
|
222
|
+
WHERE level_type = 'ORG'
|
|
223
|
+
AND level_id = 1
|
|
224
|
+
AND communication_config_type = 'EMAIL'
|
|
225
|
+
AND service = 'API'`,
|
|
182
226
|
);
|
|
227
|
+
this.logger.debug(`ORG configs found: ${JSON.stringify(orgConfigs)}`);
|
|
183
228
|
|
|
184
229
|
if (orgConfigs && orgConfigs.length > 0) {
|
|
185
230
|
const provider = orgConfigs[0].provider;
|
|
186
231
|
const configId = orgConfigs[0].config_id;
|
|
232
|
+
this.logger.debug(
|
|
233
|
+
`ORG config provider=${provider}, configId=${configId}`,
|
|
234
|
+
);
|
|
187
235
|
|
|
188
236
|
if (provider === 'gmail') {
|
|
189
|
-
|
|
237
|
+
this.logger.log(`Using ORG Google Calendar for scheduling`);
|
|
190
238
|
const creds = await this.getConfigCred(configId);
|
|
239
|
+
this.logger.debug(`ORG Google creds: ${JSON.stringify(creds)}`);
|
|
191
240
|
if (creds) {
|
|
192
241
|
const result = await this.googleService.createEvent(creds, payload);
|
|
242
|
+
this.logger.log(
|
|
243
|
+
`ORG Google Calendar createEvent SUCCESS: ${JSON.stringify(result)}`,
|
|
244
|
+
);
|
|
193
245
|
return { success: true, data: result };
|
|
194
246
|
}
|
|
195
247
|
}
|
|
196
248
|
|
|
197
|
-
|
|
249
|
+
this.logger.log(`ORG Non-Gmail provider. Falling back to ICS`);
|
|
198
250
|
const result = await this.sendIcsFallback(payload, 1, 'ORG');
|
|
199
251
|
return { success: true, data: result };
|
|
200
252
|
}
|
|
201
253
|
|
|
202
|
-
// 3. Absolute fallback
|
|
254
|
+
// 3. Absolute fallback
|
|
255
|
+
this.logger.error(
|
|
256
|
+
`No configs found anywhere. Defaulting to ORG ICS fallback`,
|
|
257
|
+
);
|
|
203
258
|
const result = await this.sendIcsFallback(payload, 1, 'ORG');
|
|
204
259
|
return { success: true, data: result };
|
|
205
260
|
} catch (error: any) {
|
|
206
|
-
this.logger.error(
|
|
261
|
+
this.logger.error(
|
|
262
|
+
`scheduleMeetingWrapper ERROR: ${error.message}`,
|
|
263
|
+
error.stack,
|
|
264
|
+
);
|
|
207
265
|
return { success: false, error: error.message };
|
|
208
266
|
}
|
|
209
267
|
}
|
|
@@ -212,12 +270,14 @@ export class WrapperService {
|
|
|
212
270
|
* Fetch credentials JSON by config ID
|
|
213
271
|
*/
|
|
214
272
|
private async getConfigCred(configId: number) {
|
|
273
|
+
this.logger.debug(`Fetching config JSON for configId=${configId}`);
|
|
215
274
|
const configRes = await this.datasource.query(
|
|
216
275
|
`SELECT config_json
|
|
217
276
|
FROM cr_communication_config
|
|
218
277
|
WHERE id = ?`,
|
|
219
278
|
[configId],
|
|
220
279
|
);
|
|
280
|
+
this.logger.debug(`Config fetch result: ${JSON.stringify(configRes)}`);
|
|
221
281
|
return configRes?.[0]?.config_json || null;
|
|
222
282
|
}
|
|
223
283
|
|
|
@@ -229,7 +289,11 @@ export class WrapperService {
|
|
|
229
289
|
levelId: number,
|
|
230
290
|
levelType: string,
|
|
231
291
|
) {
|
|
292
|
+
this.logger.log(
|
|
293
|
+
`Generating ICS file for fallback. Payload: ${JSON.stringify(payload)}`,
|
|
294
|
+
);
|
|
232
295
|
const base64String = await this.icsService.generateIcs(payload);
|
|
296
|
+
this.logger.debug(`ICS generated (base64 length: ${base64String?.length})`);
|
|
233
297
|
|
|
234
298
|
const payloadSendMail: GenericMessageDto = {
|
|
235
299
|
levelId,
|
|
@@ -253,6 +317,12 @@ export class WrapperService {
|
|
|
253
317
|
variables: payload.variables,
|
|
254
318
|
};
|
|
255
319
|
|
|
256
|
-
|
|
320
|
+
this.logger.debug(
|
|
321
|
+
`Final payload for ICS send: ${JSON.stringify(payloadSendMail)}`,
|
|
322
|
+
);
|
|
323
|
+
const result =
|
|
324
|
+
await this.communicationService.sendGenericMessage(payloadSendMail);
|
|
325
|
+
this.logger.log(`ICS fallback mail send result: ${JSON.stringify(result)}`);
|
|
326
|
+
return result;
|
|
257
327
|
}
|
|
258
328
|
}
|