rez_core 2.2.159 → 2.2.162

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 (33) hide show
  1. package/dist/module/communication/service/communication.service.js +32 -12
  2. package/dist/module/communication/service/communication.service.js.map +1 -1
  3. package/dist/module/communication/strategies/communication.strategy.d.ts +1 -0
  4. package/dist/module/communication/strategies/gmail.strategy.js +20 -1
  5. package/dist/module/communication/strategies/gmail.strategy.js.map +1 -1
  6. package/dist/module/workflow/controller/comm-template.controller.d.ts +1 -0
  7. package/dist/module/workflow/controller/workflow-meta.controller.d.ts +1 -1
  8. package/dist/module/workflow/controller/workflow-meta.controller.js +6 -4
  9. package/dist/module/workflow/controller/workflow-meta.controller.js.map +1 -1
  10. package/dist/module/workflow/entity/action.entity.d.ts +1 -0
  11. package/dist/module/workflow/entity/action.entity.js +4 -0
  12. package/dist/module/workflow/entity/action.entity.js.map +1 -1
  13. package/dist/module/workflow/repository/comm-template.repository.js +1 -1
  14. package/dist/module/workflow/repository/comm-template.repository.js.map +1 -1
  15. package/dist/module/workflow/service/comm-template.service.d.ts +1 -0
  16. package/dist/module/workflow/service/comm-template.service.js +1 -0
  17. package/dist/module/workflow/service/comm-template.service.js.map +1 -1
  18. package/dist/module/workflow/service/task.service.js +1 -0
  19. package/dist/module/workflow/service/task.service.js.map +1 -1
  20. package/dist/module/workflow/service/workflow-meta.service.d.ts +1 -1
  21. package/dist/module/workflow/service/workflow-meta.service.js +9 -9
  22. package/dist/module/workflow/service/workflow-meta.service.js.map +1 -1
  23. package/dist/tsconfig.build.tsbuildinfo +1 -1
  24. package/package.json +1 -1
  25. package/src/module/communication/service/communication.service.ts +42 -12
  26. package/src/module/communication/strategies/communication.strategy.ts +1 -0
  27. package/src/module/communication/strategies/gmail.strategy.ts +28 -1
  28. package/src/module/workflow/controller/workflow-meta.controller.ts +4 -0
  29. package/src/module/workflow/entity/action.entity.ts +3 -0
  30. package/src/module/workflow/repository/comm-template.repository.ts +1 -1
  31. package/src/module/workflow/service/comm-template.service.ts +1 -0
  32. package/src/module/workflow/service/task.service.ts +1 -0
  33. package/src/module/workflow/service/workflow-meta.service.ts +14 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez_core",
3
- "version": "2.2.159",
3
+ "version": "2.2.162",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -148,16 +148,18 @@ export class CommunicationService {
148
148
  .createQueryBuilder('hub')
149
149
  .leftJoin('communication_config', 'config', 'config.id = hub.config_id')
150
150
  .select([
151
- 'hub.id',
152
- 'hub.status',
153
- 'hub.config_id',
154
- 'hub.communication_config_type',
155
- 'hub.service',
156
- 'hub.provider',
157
- 'hub.priority',
158
- 'hub.is_default',
159
- 'hub.created_at',
160
- 'hub.updated_at',
151
+ 'hub.id as hub_id',
152
+ 'hub.level_id as hub_level_id',
153
+ 'hub.level_type as hub_level_type',
154
+ 'hub.status as hub_status',
155
+ 'hub.config_id as hub_config_id',
156
+ 'hub.communication_config_type as hub_communication_config_type',
157
+ 'hub.service as hub_service',
158
+ 'hub.provider as hub_provider',
159
+ 'hub.priority as hub_priority',
160
+ 'hub.is_default as hub_is_default',
161
+ 'hub.created_at as hub_created_at',
162
+ 'hub.updated_at as hub_updated_at',
161
163
  'config.id as config_id',
162
164
  'config.config_json as config_json',
163
165
  'config.created_at as config_created_at',
@@ -217,7 +219,32 @@ export class CommunicationService {
217
219
  hub.provider,
218
220
  );
219
221
 
220
- return strategy.sendMessage(to, message, hub.config.config_json);
222
+ const result = await strategy.sendMessage(to, message, hub.config.config_json);
223
+
224
+ // If token was refreshed, update it in the database
225
+ if (result.refreshedToken && result.success) {
226
+ try {
227
+ const currentConfig = hub.config.config_json as any;
228
+ const updatedConfig = {
229
+ ...currentConfig,
230
+ accessToken: result.refreshedToken,
231
+ };
232
+
233
+ await this.configRepository.update(hub.config.id, {
234
+ config_json: updatedConfig,
235
+ } as any);
236
+
237
+ this.logger.log(
238
+ `Updated access token for ${hub.provider}/${hub.service} configuration`,
239
+ );
240
+ } catch (error) {
241
+ this.logger.warn(
242
+ `Failed to update refreshed token in database: ${error.message}`,
243
+ );
244
+ }
245
+ }
246
+
247
+ return result;
221
248
  }
222
249
 
223
250
  async createCommunicationConfig(
@@ -338,8 +365,11 @@ export class CommunicationService {
338
365
  );
339
366
 
340
367
  if (!hubs.length) {
368
+ this.logger.warn(
369
+ `No communication hubs found for ${levelType} ${levelId}. Please configure communication providers using the createCommunicationConfig method.`
370
+ );
341
371
  throw new Error(
342
- `No active ${communicationType} configuration found for ${levelType} ${levelId}`,
372
+ `No active ${communicationType} configuration found for ${levelType} ${levelId}. Please configure a communication provider first.`,
343
373
  );
344
374
  }
345
375
 
@@ -14,6 +14,7 @@ export interface CommunicationResult {
14
14
  service: string;
15
15
  error?: string;
16
16
  timestamp: Date;
17
+ refreshedToken?: string;
17
18
  }
18
19
 
19
20
  export interface MessageTemplate {
@@ -16,12 +16,31 @@ export class GmailStrategy implements CommunicationStrategy {
16
16
  const { clientId, clientSecret, refreshToken, accessToken, email } =
17
17
  config;
18
18
 
19
- const oauth2Client = new google.auth.OAuth2(clientId, clientSecret);
19
+ // For backward compatibility, only validate essential fields for sending
20
+ if (!refreshToken || !email) {
21
+ throw new Error('Missing required Gmail credentials: refreshToken and email are required');
22
+ }
23
+
24
+ // Create a minimal OAuth2 client just for token management
25
+ const oauth2Client = new google.auth.OAuth2();
26
+
20
27
  oauth2Client.setCredentials({
21
28
  refresh_token: refreshToken,
22
29
  access_token: accessToken,
23
30
  });
24
31
 
32
+ // Try to get a valid access token (will auto-refresh if needed)
33
+ try {
34
+ const { token } = await oauth2Client.getAccessToken();
35
+ // If we got a new token, update the config
36
+ if (token && token !== accessToken) {
37
+ config.accessToken = token;
38
+ }
39
+ } catch (tokenError) {
40
+ console.log('Token refresh error:', tokenError.message);
41
+ // If refresh fails, continue with existing token and let Gmail API handle it
42
+ }
43
+
25
44
  const gmail = google.gmail({ version: 'v1', auth: oauth2Client });
26
45
 
27
46
  const subject = config.subject || 'Notification';
@@ -53,8 +72,16 @@ export class GmailStrategy implements CommunicationStrategy {
53
72
  service: 'API',
54
73
  messageId: result.data.id || undefined,
55
74
  timestamp: new Date(),
75
+ refreshedToken: config.accessToken !== accessToken ? config.accessToken : undefined,
56
76
  };
57
77
  } catch (error) {
78
+ console.log('Gmail strategy error:', error.message);
79
+ console.log('Config validation:', JSON.stringify({
80
+ hasRefreshToken: !!config.refreshToken,
81
+ hasAccessToken: !!config.accessToken,
82
+ hasEmail: !!config.email
83
+ }));
84
+
58
85
  return {
59
86
  success: false,
60
87
  provider: 'gmail',
@@ -64,6 +64,8 @@ export class WorkflowMetaController {
64
64
  async moveToNextStage(
65
65
  @Body('entityType') mapped_entity_type: string,
66
66
  @Body('entityId') mapped_entity_id: number,
67
+ @Body('reason_code') reason_code: string,
68
+ @Body('remark') remark: string,
67
69
  @Req() req: Request & { user: any },
68
70
  ): Promise<string> {
69
71
  const loggedInUser = req.user.userData;
@@ -71,6 +73,8 @@ export class WorkflowMetaController {
71
73
  mapped_entity_type,
72
74
  Number(mapped_entity_id),
73
75
  loggedInUser,
76
+ reason_code,
77
+ remark,
74
78
  );
75
79
  }
76
80
  }
@@ -35,4 +35,7 @@ export class ActionEntity extends BaseEntity {
35
35
 
36
36
  @Column({ type: 'varchar', nullable: true })
37
37
  assignment_type: string;
38
+
39
+ @Column({ type: 'boolean', nullable: true })
40
+ is_template: boolean;
38
41
  }
@@ -19,7 +19,7 @@ export class CommTemplateRepository {
19
19
  async getAllCommTemplate(entity_type: string, loggedInUser) {
20
20
  const { organization_id } = loggedInUser;
21
21
  return this.commTemplateRepository.find({
22
- select: ['name', 'code'],
22
+ select: ['name', 'code', 'mode'],
23
23
  where: {
24
24
  mapped_entity_type: entity_type,
25
25
  organization_id: organization_id,
@@ -88,6 +88,7 @@ export class CommTemplateService extends EntityServiceImpl {
88
88
  const response = commTemplateData.map((item) => ({
89
89
  value: item.code,
90
90
  label: item.name,
91
+ mode: item.mode,
91
92
  }));
92
93
 
93
94
  return response;
@@ -435,6 +435,7 @@ export class TaskService extends EntityServiceImpl {
435
435
  stage_group_id: entity.stage_group_id,
436
436
  } as any;
437
437
 
438
+ console.log(notePayload);
438
439
  return await super.createEntity(notePayload, loggedInUser);
439
440
  }
440
441
  }
@@ -114,6 +114,8 @@ export class WorkflowMetaService extends EntityServiceImpl {
114
114
  mapped_entity_type: string,
115
115
  mapped_entity_id: number,
116
116
  loggedInUser: UserData,
117
+ reason_code?: string,
118
+ remark?: string,
117
119
  ): Promise<string> {
118
120
  const now = new Date();
119
121
  let currentStage = await this.getCurrentStage(
@@ -153,19 +155,6 @@ export class WorkflowMetaService extends EntityServiceImpl {
153
155
  mapped_entity_id,
154
156
  mapped_entity_type,
155
157
  );
156
-
157
- await this.taskService.createSystemNote(
158
- {
159
- reason_code: firstStage.reason_code,
160
- remark: firstStage.remark,
161
- mapped_entity_id,
162
- stage_id: firstStage.id,
163
- action_id: firstStage.id,
164
- stage_group_id: stageGroup.id,
165
- },
166
- loggedInUser,
167
- );
168
-
169
158
  return `Initialized workflow with first stage (Stage ID: ${firstStage.id}).`;
170
159
  }
171
160
 
@@ -255,6 +244,18 @@ export class WorkflowMetaService extends EntityServiceImpl {
255
244
  currentStage.is_current = 'N';
256
245
  await this.stageMovementRepo.save(currentStage);
257
246
 
247
+ await this.taskService.createSystemNote(
248
+ {
249
+ reason_code: reason_code || '',
250
+ remark: remark || '',
251
+ mapped_entity_id,
252
+ stage_id: currentStage.stage_id,
253
+ action_id: currentStage.action_id,
254
+ stage_group_id: currentStage.stage_group_id,
255
+ },
256
+ loggedInUser,
257
+ );
258
+
258
259
  return 'Workflow completed. No next stage available.';
259
260
  }
260
261