@izara_project/izara-core-generate-service-code 1.0.74 → 1.0.75

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 (41) hide show
  1. package/package.json +1 -1
  2. package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
  3. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
  4. package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
  5. package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
  6. package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
  7. package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
  8. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
  9. package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
  10. package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
  11. package/src/emit/custom/customFlows.js +15 -1
  12. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +2 -0
  13. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
  14. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
  15. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
  16. package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
  17. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +91 -87
  18. package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
  19. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +90 -86
  20. package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
  21. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +85 -81
  22. package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
  23. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +2 -0
  24. package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
  25. package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
  26. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +93 -89
  27. package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
  28. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +85 -81
  29. package/src/emit/resource/emitResourceArtifacts.js +23 -0
  30. package/src/emit/shared/templates/FindData_Main.ejs +1 -1
  31. package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
  32. package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
  33. package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
  34. package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
  35. package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
  36. package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
  37. package/src/emit/system/templates/Register_Main.ejs +148 -0
  38. package/test/customFlowApplicationArtifacts.test.js +16 -5
  39. package/test/publicApi.test.js +21 -0
  40. package/test/relationshipApplicationArtifacts.test.js +1 -1
  41. package/test/resourceArtifacts.test.js +20 -0
@@ -0,0 +1,99 @@
1
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
2
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
3
+ import Logger from '@izara_project/izara-core-library-logger';
4
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
5
+ import UpdateRelationshipComplete from './UpdateRelationshipComplete_Main.js';
6
+
7
+ //(<optionalRequire>)
8
+ //(</optionalRequire>)
9
+
10
+ // validate event properties in body.Message of sqs event
11
+ let perRecordsValidatorSchema = {
12
+ type: 'object',
13
+ properties: {
14
+ returnValue: {
15
+ type: 'object'
16
+ },
17
+ parentFlowId: {
18
+ type: 'string'
19
+ },
20
+ status: {
21
+ type: 'string'
22
+ },
23
+ errorsFound: {
24
+ type: 'array'
25
+ },
26
+ graphServiceTag: {
27
+ type: 'string'
28
+ }
29
+ },
30
+ required: [
31
+ 'returnValue',
32
+ 'parentFlowId',
33
+ 'status',
34
+ 'errorsFound',
35
+ 'graphServiceTag'
36
+ ]
37
+ //(<validatorSchema>)
38
+ //(</validatorSchema>)
39
+ };
40
+
41
+ let messageAttributeValidatorSchema = null;
42
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
43
+
44
+ export const main = middleware.wrap(async (event, context) => {
45
+ try {
46
+ let recordPromises = [];
47
+
48
+ // loop each record and send to mainFunction
49
+ await Promise.all(
50
+ event.Records.map(async (record) => {
51
+ let passOnProperties = [];
52
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
53
+
54
+ //validate message (and MessageAttributes)
55
+ await recordHandlerSharedLib.validateRecord(
56
+ record, // one record will send to mainFunction
57
+ 'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
58
+ perRecordsValidatorSchema, // schema for record.Message
59
+ messageAttributeValidatorSchema
60
+ );
61
+
62
+ // add argument (to invoke lambda) to passOnProperties[]
63
+ passOnProperties.push(record.body.Message);
64
+ passOnProperties.push(
65
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
66
+ record.body.Message
67
+ )
68
+ );
69
+ //(<additionalParams>)
70
+ //(</additionalParams>)
71
+ record._izContext.logger.debug(
72
+ 'passOnProperties in handler',
73
+ passOnProperties
74
+ );
75
+
76
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
77
+ let recordPromise = recordHandlerSharedLib.recordHandler(
78
+ record, // one record will send to mainFunction
79
+ UpdateRelationshipComplete, // mainFunction that need to invoke.
80
+ 'UpdateRelationshipCompleteHdrSqs', // queue name that need to retry or send to dlq
81
+ passOnProperties // all parameters that mainFunction needed.
82
+ );
83
+ record._izContext.logger.debug('after recordPromise in handler');
84
+ recordPromises.push(recordPromise); // push promise to recordPromises
85
+ })
86
+ );
87
+ try {
88
+ await Promise.all(recordPromises);
89
+ return event.Records;
90
+ } catch {
91
+ Logger.debug(
92
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
93
+ );
94
+ }
95
+ } catch (error) {
96
+ Logger.error('Unhandled Error, UpdateRelationshipComplete_HdrSqs: ', error);
97
+ throw error;
98
+ }
99
+ });
@@ -19,7 +19,7 @@ import { objectHash as hash } from '@izara_project/izara-shared-core';
19
19
 
20
20
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
21
21
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
- import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
+
23
23
  import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
24
24
 
25
25
  import { sns } from '@izara_project/izara-core-library-external-request';
@@ -43,6 +43,7 @@ export default async function updateRelationshipComplete(
43
43
  try {
44
44
  const {
45
45
  returnValue,
46
+ parentFlowId,
46
47
  status,
47
48
  errorsFound,
48
49
  graphServiceTag
@@ -50,6 +51,7 @@ export default async function updateRelationshipComplete(
50
51
 
51
52
  _izContext.logger.debug('Function:updateRelationshipComplete', {
52
53
  returnValue: returnValue,
54
+ parentFlowId: parentFlowId,
53
55
  status: status,
54
56
  errorsFound: errorsFound,
55
57
  graphServiceTag: graphServiceTag,
@@ -57,94 +59,96 @@ export default async function updateRelationshipComplete(
57
59
  // callingFlowConfig: callingFlowConfig
58
60
  });
59
61
 
60
- let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
61
- returnValue.parentFlowId, // hash id
62
+ const awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
63
+ parentFlowId || returnValue?.parentFlowId, // hash id
62
64
  PREFIX.updateRel // prefix, use constant further
63
65
  );
64
66
 
65
- let updateRelPendingObjects = await dynamodbSharedLib.query(
66
- _izContext,
67
- await dynamodbSharedLib.tableName(_izContext, 'AwaitingMultipleSteps'),
67
+ const pending =
68
+ await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
69
+ _izContext,
70
+ awaitingStepId
71
+ );
72
+ _izContext.logger.debug('[UpdateRelationshipComplete] awaiting step', {
73
+ awaitingStepId,
74
+ pending
75
+ });
76
+
77
+ if (!pending) {
78
+ _izContext.logger.warn(
79
+ `No pending step found for awaitingStepId: ${awaitingStepId}`
80
+ );
81
+ return { returnValue, status, errorsFound };
82
+ }
83
+
84
+ const result =
85
+ await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
86
+ _izContext,
87
+ pending.pendingStepId,
88
+ awaitingStepId,
89
+ errorsFound
90
+ );
91
+ _izContext.logger.debug(
92
+ '[UpdateRelationshipComplete] all awaiting steps result',
68
93
  {
69
- awaitingStepId: awaitingStepId
94
+ isComplete: result.isComplete,
95
+ awaitingStepId,
96
+ pendingStepId: pending.pendingStepId
70
97
  }
71
98
  );
72
- _izContext.logger.debug(
73
- 'record of updateRelPendingObjects ::',
74
- updateRelPendingObjects
75
- );
76
99
 
77
- await Promise.all(
78
- updateRelPendingObjects.Items.map(async ({ pendingStepId }) => {
79
- if (
80
- await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
81
- _izContext,
82
- pendingStepId, // task waiting
83
- awaitingStepId,
84
- errorsFound
85
- )
86
- ) {
87
- _izContext.logger.debug('finished all awaitingStep');
88
-
89
- let updateCompleteMsg = {
90
- relId: returnValue.requestParams.relId,
91
- relType: returnValue.requestParams.relType,
92
- status: status,
93
- errorsFound: errorsFound
94
- //(<inUpdateCompleteMsg>)
95
- //(</inUpdateCompleteMsg>)
96
- };
97
-
98
- updateCompleteMsg =
99
- callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
100
- passBackProperties,
101
- updateCompleteMsg
102
- );
103
- _izContext.logger.debug(
104
- 'After addCallingFlowToSnsResponseMessageObject',
105
- updateCompleteMsg
106
- );
107
-
108
- let messageAttributes =
109
- callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
110
- passBackProperties,
111
- {}
112
- );
113
- _izContext.logger.debug(
114
- 'After addCallingFlowToSnsResponseMessageAttributes',
115
- updateCompleteMsg
116
- );
117
-
118
- let sendMessageToOutUpdateRelationshipComplete = {
119
- Message: JSON.stringify(updateCompleteMsg),
120
- MessageAttributes: sns.createStringMessageAttributes(
121
- _izContext,
122
- messageAttributes
123
- ),
124
- TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
125
- _izContext,
126
- TOPIC_NAME_GENERATE_CODE.outUpdateRelComplete
127
- )
128
- };
129
- _izContext.logger.debug(
130
- 'Send message to OutUpdateRelationshipComplete :::>',
131
- sendMessageToOutUpdateRelationshipComplete
132
- );
133
- await sns.publishAsync(
134
- _izContext,
135
- sendMessageToOutUpdateRelationshipComplete
136
- );
137
- } // check pendingStepId finished
138
-
139
- // remove awaitingMultipleStep after finished
140
- await asyncFlowSharedLib.removeAwaitingMultipleStep(
141
- _izContext,
142
- awaitingStepId,
143
- pendingStepId,
144
- errorsFound
100
+ if (result.isComplete) {
101
+ _izContext.logger.debug('finished all awaitingStep');
102
+
103
+ let updateCompleteMsg = {
104
+ relId: returnValue.requestParams.relId,
105
+ relType: returnValue.requestParams.relType,
106
+ status: status,
107
+ errorsFound: errorsFound
108
+ //(<inUpdateCompleteMsg>)
109
+ //(</inUpdateCompleteMsg>)
110
+ };
111
+
112
+ updateCompleteMsg =
113
+ callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
114
+ passBackProperties,
115
+ updateCompleteMsg
145
116
  );
146
- }) // end per pendingStep
147
- );
117
+ _izContext.logger.debug(
118
+ 'After addCallingFlowToSnsResponseMessageObject',
119
+ updateCompleteMsg
120
+ );
121
+
122
+ let messageAttributes =
123
+ callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
124
+ passBackProperties,
125
+ {}
126
+ );
127
+ _izContext.logger.debug(
128
+ 'After addCallingFlowToSnsResponseMessageAttributes',
129
+ updateCompleteMsg
130
+ );
131
+
132
+ let sendMessageToOutUpdateRelationshipComplete = {
133
+ Message: JSON.stringify(updateCompleteMsg),
134
+ MessageAttributes: sns.createStringMessageAttributes(
135
+ _izContext,
136
+ messageAttributes
137
+ ),
138
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
139
+ _izContext,
140
+ TOPIC_NAME_GENERATE_CODE.outUpdateRelComplete
141
+ )
142
+ };
143
+ _izContext.logger.debug(
144
+ 'Send message to OutUpdateRelationshipComplete :::>',
145
+ sendMessageToOutUpdateRelationshipComplete
146
+ );
147
+ await sns.publishAsync(
148
+ _izContext,
149
+ sendMessageToOutUpdateRelationshipComplete
150
+ );
151
+ } // check isComplete finished
148
152
 
149
153
  return {
150
154
  returnValue,
@@ -5,6 +5,7 @@ import {
5
5
  customFlowRoleName,
6
6
  flowDsqSteps,
7
7
  flowExtTopicSteps,
8
+ generatedDsqFlows,
8
9
  generatedOwnTopicFlows,
9
10
  supportedCustomFlows
10
11
  } from '../custom/customFlows.js';
@@ -74,6 +75,12 @@ const SQS_CONSUMER_ACTIONS = [
74
75
  'sqs:GetQueueAttributes',
75
76
  'sqs:ReceiveMessage'
76
77
  ];
78
+ const SQS_DLQ_ACTIONS = [
79
+ 'sqs:DeleteMessage',
80
+ 'sqs:GetQueueAttributes',
81
+ 'sqs:ReceiveMessage',
82
+ 'sqs:SendMessage'
83
+ ];
77
84
 
78
85
  export async function emitResourceArtifacts({
79
86
  objects,
@@ -219,6 +226,9 @@ function createResourceState({ objects, relationships, flows }) {
219
226
  ...generatedOwnTopicFlows(flows).map((flow) =>
220
227
  customFlowRoleName(flow.flowTag)
221
228
  ),
229
+ ...generatedDsqFlows(flows).map((flow) =>
230
+ customFlowRoleName(flow.flowTag)
231
+ ),
222
232
  ...flowExtTopicSteps(flows).map(({ flow }) =>
223
233
  customFlowRoleName(flow.flowTag)
224
234
  ),
@@ -497,6 +507,11 @@ function roleStatements(state, roleName) {
497
507
  SQS_CONSUMER_ACTIONS,
498
508
  queueArns(roleQueueNames(state, roleName))
499
509
  );
510
+ addStatement(
511
+ statements,
512
+ SQS_DLQ_ACTIONS,
513
+ queueArns(roleDlqQueueNames(state, roleName))
514
+ );
500
515
  addStatement(
501
516
  statements,
502
517
  ['sns:Publish'],
@@ -649,6 +664,14 @@ function roleQueueNames(state, roleName) {
649
664
  return queueList;
650
665
  }
651
666
 
667
+ function roleDlqQueueNames(state, roleName) {
668
+ const queues = roleQueueNames(state, roleName);
669
+ if (!Array.isArray(queues) || queues.length === 0) {
670
+ return [];
671
+ }
672
+ return queues.map((q) => (q.endsWith('DLQ') ? q : `${q}DLQ`));
673
+ }
674
+
652
675
  function roleTopicNames(state, roleName) {
653
676
  if (roleName === 'ProcFindDataRole') return [];
654
677
  if (roleName === 'FlowObjectsRole')
@@ -94,7 +94,7 @@ export default async function findData(
94
94
  fieldName,
95
95
  objType,
96
96
  identifiers,
97
- null,
97
+ "",
98
98
  overWriteCache,
99
99
  callingFlow,
100
100
  'error'
@@ -3,6 +3,8 @@ import ejsLib from 'ejs';
3
3
 
4
4
  const TEMPLATE_URL = new URL('./templates/', import.meta.url);
5
5
  const SOURCE = 'app/src/generatedCode/SystemFlowSchemas/WebSocketMain/source';
6
+ const REGISTER_SOURCE =
7
+ 'app/src/generatedCode/SystemFlowSchemas/Register/source';
6
8
 
7
9
  async function _renderSystemTemplate(templateName, data = {}) {
8
10
  const templatePath = new URL(templateName, TEMPLATE_URL);
@@ -27,12 +29,32 @@ export async function emitSystemWebSocketArtifacts(
27
29
  const webSocketCompleteHdrSqsContent = await _renderSystemTemplate(
28
30
  'WebSocketComplete_HdrSqs.ejs'
29
31
  );
32
+ const registerMainContent = await _renderSystemTemplate('Register_Main.ejs');
33
+ const registerHdrWbsContent = await _renderSystemTemplate(
34
+ 'Register_HdrWbs.ejs'
35
+ );
36
+ const registerCompleteMainContent = await _renderSystemTemplate(
37
+ 'RegisterComplete_Main.ejs'
38
+ );
39
+ const registerCompleteHdrSqsContent = await _renderSystemTemplate(
40
+ 'RegisterComplete_HdrSqs.ejs',
41
+ { queueName: 'RegisterComplete' }
42
+ );
43
+ const registerCompleteHdrDsqContent = await _renderSystemTemplate(
44
+ 'RegisterComplete_HdrSqs.ejs',
45
+ { queueName: 'RegisterCompleteDLQ' }
46
+ );
47
+
30
48
  const webSocketConnectYaml = await _renderSystemTemplate(
31
49
  'WebSocketConnect_Yaml.ejs'
32
50
  );
33
51
  const webSocketCompleteYaml = await _renderSystemTemplate(
34
52
  'WebSocketComplete_Yaml.ejs'
35
53
  );
54
+ const registerWbsYaml = await _renderSystemTemplate('RegisterWbs_Yaml.ejs');
55
+ const registerCompleteYaml = await _renderSystemTemplate(
56
+ 'RegisterComplete_Yaml.ejs'
57
+ );
36
58
 
37
59
  return {
38
60
  artifacts: [
@@ -47,9 +69,34 @@ export async function emitSystemWebSocketArtifacts(
47
69
  {
48
70
  path: `${SOURCE}/WebSocketComplete_HdrSqs.js`,
49
71
  content: webSocketCompleteHdrSqsContent
72
+ },
73
+ {
74
+ path: `${REGISTER_SOURCE}/Register_Main.js`,
75
+ content: registerMainContent
76
+ },
77
+ {
78
+ path: `${REGISTER_SOURCE}/Register_HdrWbs.js`,
79
+ content: registerHdrWbsContent
80
+ },
81
+ {
82
+ path: `${REGISTER_SOURCE}/RegisterComplete_Main.js`,
83
+ content: registerCompleteMainContent
84
+ },
85
+ {
86
+ path: `${REGISTER_SOURCE}/RegisterComplete_HdrSqs.js`,
87
+ content: registerCompleteHdrSqsContent
88
+ },
89
+ {
90
+ path: `${REGISTER_SOURCE}/RegisterComplete_HdrDsq.js`,
91
+ content: registerCompleteHdrDsqContent
50
92
  }
51
93
  ],
52
- functions: [webSocketConnectYaml, webSocketCompleteYaml]
94
+ functions: [
95
+ webSocketConnectYaml,
96
+ webSocketCompleteYaml,
97
+ registerWbsYaml,
98
+ registerCompleteYaml
99
+ ]
53
100
  };
54
101
  }
55
102
 
@@ -57,7 +104,12 @@ export function systemWebSocketManagedPaths() {
57
104
  return [
58
105
  `${SOURCE}/WebSocketConnect.js`,
59
106
  `${SOURCE}/WebSocketComplete_Main.js`,
60
- `${SOURCE}/WebSocketComplete_HdrSqs.js`
107
+ `${SOURCE}/WebSocketComplete_HdrSqs.js`,
108
+ `${REGISTER_SOURCE}/Register_Main.js`,
109
+ `${REGISTER_SOURCE}/Register_HdrWbs.js`,
110
+ `${REGISTER_SOURCE}/RegisterComplete_Main.js`,
111
+ `${REGISTER_SOURCE}/RegisterComplete_HdrSqs.js`,
112
+ `${REGISTER_SOURCE}/RegisterComplete_HdrDsq.js`
61
113
  ];
62
114
  }
63
115
 
@@ -0,0 +1,64 @@
1
+ import { middlewareHandler } from '@izara_project/izara-middleware';
2
+ import Logger from '@izara_project/izara-core-library-logger';
3
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
4
+ import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
5
+ import registerCompleteMain from './RegisterComplete_Main.js';
6
+
7
+ middlewareHandler.setValidatorSchema(
8
+ recordHandlerSharedLib.baseValidatorSchema()
9
+ );
10
+ let perRecordsValidatorSchema = {};
11
+
12
+ export const main = middlewareHandler.wrap(async (event, context) => {
13
+ try {
14
+ let recordPromises = [];
15
+
16
+ await Promise.all(
17
+ event.Records.map(async (record) => {
18
+ let passOnProperties = [];
19
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
20
+
21
+ await recordHandlerSharedLib.validateRecord(
22
+ record,
23
+ '<%= queueName %>',
24
+ perRecordsValidatorSchema
25
+ );
26
+
27
+ passOnProperties.push(record.body.TopicArn);
28
+ passOnProperties.push(record.body.Message);
29
+ passOnProperties.push(
30
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(
31
+ record.body.Message
32
+ )
33
+ );
34
+ record._izContext.logger.debug(
35
+ 'passOnProperties in handler',
36
+ passOnProperties
37
+ );
38
+
39
+ let recordPromise = recordHandlerSharedLib.recordHandler(
40
+ record,
41
+ registerCompleteMain,
42
+ '<%= queueName %>',
43
+ passOnProperties
44
+ );
45
+ record._izContext.logger.debug('after recordPromise in handler');
46
+ recordPromises.push(recordPromise);
47
+ })
48
+ );
49
+
50
+ Logger.debug('before Promise.all(recordPromises) in handler');
51
+ try {
52
+ await Promise.all(recordPromises);
53
+ return event.Records;
54
+ } catch {
55
+ Logger.debug(
56
+ 'Promise.all(recordPromises) in handler threw error (at least one record did not resolve)'
57
+ );
58
+ }
59
+ Logger.debug('after Promise.all(recordPromises) in handler');
60
+ } catch (err) {
61
+ Logger.error('Unhandled Error, RegisterComplete: ', err);
62
+ throw err;
63
+ }
64
+ });
@@ -0,0 +1,154 @@
1
+ import { NoRetryError } from '@izara_project/izara-core-library-core';
2
+ import { objectHash as hash } from '@izara_project/izara-shared-core';
3
+ import { getObjectSchema, identifiersObject } from '@izara_project/izara-core-library-service-schemas';
4
+ import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
5
+ import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
6
+ import { lambda, webSocket } from '@izara_project/izara-core-library-external-request';
7
+ const { postToConnection } = webSocket;
8
+
9
+ /**
10
+ * Register complete main handler
11
+ * @param {Object} _izContext
12
+ * @param {string} topicArn
13
+ * @param {Object} requestParams
14
+ * @param {Object} callingFlowConfig
15
+ */
16
+ export default async function registerCompleteMain(
17
+ _izContext,
18
+ topicArn,
19
+ requestParams,
20
+ callingFlowConfig = {}
21
+ ) {
22
+ try {
23
+ _izContext.logger.debug('WebSocketInvoke _izContext', _izContext);
24
+ _izContext.logger.debug('WebSocketInvoke requestParams', requestParams);
25
+ _izContext.logger.debug('WebSocketInvoke callingFlowConfig', callingFlowConfig);
26
+
27
+ if (!topicArn) {
28
+ throw new NoRetryError('invalid not have topicArn to get flowSchema');
29
+ }
30
+
31
+ let topicName = topicArn.split(':')[5].split('_');
32
+ let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
33
+ flowTag: topicName[2],
34
+ serviceTag: topicName[0]
35
+ });
36
+
37
+ if (!flowSchema) {
38
+ throw new NoRetryError('not have flowSchema in S3');
39
+ }
40
+
41
+ let identifiersTask = '';
42
+
43
+ if (!requestParams.identifiersTask && flowSchema.objType) {
44
+ identifiersTask = await identifiersObject.identifiersConcatFromIdentifiers(
45
+ _izContext,
46
+ flowSchema.objType,
47
+ requestParams
48
+ );
49
+ _izContext.logger.debug('identifiersTask from request params', identifiersTask);
50
+
51
+ Object.assign(requestParams, {
52
+ identifiersTask: identifiersTask
53
+ });
54
+ }
55
+
56
+ if (!requestParams.identifiersTask) {
57
+ _izContext.logger.warn('invalid identifiersTask');
58
+ return 'invalid identifiersTask';
59
+ }
60
+
61
+ const getResult = async (objType) => {
62
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
63
+ _izContext,
64
+ {
65
+ objectType: objType.objectType,
66
+ serviceTag: objType.serviceTag
67
+ }
68
+ );
69
+
70
+ _izContext.logger.debug('==> objectSchema', objectSchema);
71
+
72
+ let tasks = await dynamodbSharedLib.query(
73
+ _izContext,
74
+ await dynamodbSharedLib.tableName(_izContext, 'RegisterRecords'),
75
+ {
76
+ identifiersTask: identifiersTask
77
+ }
78
+ );
79
+
80
+ if (tasks.Items && tasks.Items.length > 0) {
81
+ const result = await lambda.invokeSync(
82
+ _izContext,
83
+ await lambdaSharedLib.lambdaFunctionName(_izContext, 'GetHdrInv'),
84
+ {
85
+ identifiers: await identifiersObject.identifiersFromIdentifiersConcat(
86
+ _izContext,
87
+ objType,
88
+ requestParams.identifiersTask
89
+ ),
90
+ objectType: objType.objectType
91
+ }
92
+ );
93
+ await Promise.all(
94
+ tasks.Items.map(async (task) => {
95
+ if (!result) {
96
+ await postToConnection({ message: 'not have record' }, task.connectionId);
97
+ } else {
98
+ await postToConnection({ message: result }, task.connectionId);
99
+ }
100
+ })
101
+ );
102
+ }
103
+ };
104
+
105
+ switch (flowSchema.statusType) {
106
+ case 'statusField':
107
+ await getResult(flowSchema.objType);
108
+ break;
109
+ case 'storedCache':
110
+ await getResult(flowSchema.objType);
111
+ break;
112
+ case 'triggerCache':
113
+ await getResult(flowSchema.objType);
114
+ break;
115
+ case 'none': {
116
+ let identifier = {};
117
+ if (
118
+ requestParams.hasOwnProperty('identifiersField') &&
119
+ Array.isArray(requestParams.identifiersField)
120
+ ) {
121
+ for (const fieldNames of requestParams.identifiersField) {
122
+ Object.assign(identifier, {
123
+ [fieldNames]: requestParams[fieldNames]
124
+ });
125
+ }
126
+ } else {
127
+ identifier = requestParams;
128
+ }
129
+
130
+ let tasks = await dynamodbSharedLib.query(
131
+ _izContext,
132
+ await dynamodbSharedLib.tableName(_izContext, 'RegisterRecords'),
133
+ {
134
+ identifiersTask: hash(identifier)
135
+ }
136
+ );
137
+
138
+ if (tasks.Items && tasks.Items.length > 0) {
139
+ await Promise.all(
140
+ tasks.Items.map(async (task) => {
141
+ await postToConnection({ message: task }, task.connectionId);
142
+ })
143
+ );
144
+ }
145
+ break;
146
+ }
147
+ default:
148
+ throw new NoRetryError(`statusType not found ${flowSchema.statusType}`);
149
+ }
150
+ } catch (err) {
151
+ _izContext.logger.error('error WebSocketInvoke: ', err);
152
+ throw err;
153
+ }
154
+ }
@@ -0,0 +1,17 @@
1
+ RegisterCompleteHdrSqs:
2
+ handler: src/generatedCode/SystemFlowSchemas/Register/source/RegisterComplete_HdrSqs.main
3
+ name: ${self:custom.iz_resourcePrefix}RegisterCompleteHdrSqs
4
+ role: RegisterRole
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}RegisterComplete
8
+ batchSize: 10
9
+
10
+ RegisterCompleteDsq:
11
+ handler: src/generatedCode/SystemFlowSchemas/Register/source/RegisterComplete_HdrDsq.main
12
+ name: ${self:custom.iz_resourcePrefix}RegisterCompleteDsq
13
+ role: RegisterRole
14
+ events:
15
+ - sqs:
16
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}RegisterCompleteDLQ
17
+ batchSize: 10