@izara_project/izara-core-generate-service-code 1.0.66 → 1.0.68

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 (90) hide show
  1. package/.prettierrc +11 -0
  2. package/docs/TriggeredCache Flow.drawio +193 -0
  3. package/docs/TriggeredCacheFlow.mmd +47 -0
  4. package/package.json +16 -12
  5. package/scripts/format-ejs.js +105 -0
  6. package/src/compile/compileProject.js +16 -1
  7. package/src/compile/loadSchemas.js +108 -1
  8. package/src/emit/crud/emitCrudApplicationArtifacts.js +9 -5
  9. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +1 -2
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +300 -109
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +221 -143
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +150 -38
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +57 -31
  16. package/src/emit/crud/templates/FlowHandler_HdrInv.ejs +28 -26
  17. package/src/emit/crud/templates/FlowHandler_HdrSqs.ejs +15 -11
  18. package/src/emit/crud/templates/FlowMain_Wbs.ejs +53 -38
  19. package/src/emit/crud/templates/GetEndpoint_Main.ejs +6 -3
  20. package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +2 -2
  21. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +407 -252
  22. package/src/emit/custom/customFlows.js +112 -31
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +89 -77
  24. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +49 -37
  25. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  26. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  27. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  28. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  29. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  30. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  32. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +12 -7
  33. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  34. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +64 -55
  35. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  36. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  38. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  39. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  40. package/src/emit/function/functionYamlArtifact.js +46 -12
  41. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +28 -15
  42. package/src/emit/rbac/emitRbacApplicationArtifacts.js +179 -66
  43. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  44. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  45. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  46. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  47. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  48. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  49. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  50. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  51. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  52. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -2
  53. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +6 -5
  54. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  55. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +260 -144
  56. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  57. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  58. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  59. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  60. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  61. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  62. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  63. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  64. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  65. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  66. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  67. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  68. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  69. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  70. package/src/emit/resource/emitResourceArtifacts.js +499 -108
  71. package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
  72. package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
  73. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +138 -0
  74. package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
  75. package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
  76. package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
  77. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  78. package/src/emit/resource/templates/SharedResource_Yaml.ejs +11 -11
  79. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +105 -105
  80. package/src/emit/system/emitSystemWebSocketArtifacts.js +2 -1
  81. package/src/generate.js +8 -4
  82. package/test/createTargetRoleHandler.test.js +63 -14
  83. package/test/crudApplicationArtifacts.test.js +1 -1
  84. package/test/customFlowApplicationArtifacts.test.js +71 -43
  85. package/test/dynamicCrudFlowSchemas.test.js +6 -6
  86. package/test/dynamicRbacFlowSchemas.test.js +8 -12
  87. package/test/dynamicRelationshipFlowSchemas.test.js +3 -3
  88. package/test/publicApi.test.js +11 -13
  89. package/test/resourceArtifacts.test.js +13 -3
  90. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
@@ -6,70 +6,182 @@ import { sns } from '@izara_project/izara-core-library-external-request';
6
6
  import { consts } from '@izara_project/izara-core-library-service-schemas';
7
7
  import { NoRetryError } from '@izara_project/izara-core-library-core';
8
8
 
9
- const { TOPIC_NAME_GENERATE_CODE } = consts;
9
+ const { TOPIC_NAME_GENERATE_CODE, PREFIX: _constPrefix } = consts;
10
+ <%_ if (action === 'Update') { _%>
11
+ const PREFIX = { ASYNC: _constPrefix.updateNode };
12
+ <%_ } else { _%>
10
13
  const PREFIX = { ASYNC: '<%- action %>AsyncEndpoint' };
14
+ <%_ } _%>
11
15
 
12
16
  function empty(value) {
13
- return value == null || (typeof value === 'object' && Object.keys(value).length === 0);
17
+ return (
18
+ value == null ||
19
+ (typeof value === 'object' && Object.keys(value).length === 0)
20
+ );
14
21
  }
15
22
 
16
23
  function validateInput(returnValue, status, graphServiceTag, errorsFound) {
17
- if (!returnValue?.queryResult) errorsFound.push('message is not have property queryResult, should be not happen');
18
- if (!returnValue?.requestParams?.objType) errorsFound.push('message is not have property objType, should be not happen');
19
- if (!returnValue?.requestParams?.objInstanceFull) errorsFound.push('message is not have property objInstance, should be not objInstance');
20
- if (status === 'error' && errorsFound.length === 0) errorsFound.push('[invalid]status is error not have errorsFound form graphService');
21
- if (status === 'complete' && errorsFound.length > 0) errorsFound.push('[Invalid] status is complete should be not have errorsFound');
22
- if (graphServiceTag == null) errorsFound.push('[Invalid] graphServerTag is not empty string');
24
+ if (!returnValue?.queryResult)
25
+ errorsFound.push(
26
+ 'message is not have property queryResult, should be not happen'
27
+ );
28
+ if (!returnValue?.requestParams?.objType)
29
+ errorsFound.push(
30
+ 'message is not have property objType, should be not happen'
31
+ );
32
+ if (!returnValue?.requestParams?.objInstanceFull)
33
+ errorsFound.push(
34
+ 'message is not have property objInstance, should be not objInstance'
35
+ );
36
+ if (status === 'error' && errorsFound.length === 0)
37
+ errorsFound.push(
38
+ '[invalid]status is error not have errorsFound form graphService'
39
+ );
40
+ if (status === 'complete' && errorsFound.length > 0)
41
+ errorsFound.push(
42
+ '[Invalid] status is complete should be not have errorsFound'
43
+ );
44
+ if (graphServiceTag == null)
45
+ errorsFound.push('[Invalid] graphServerTag is not empty string');
23
46
  }
24
47
 
25
- export default async function <%- action %>Complete(_izContext, requestParams, passBackProperties) {
48
+ export default async function <%- action %>Complete(
49
+ _izContext,
50
+ requestParams,
51
+ passBackProperties
52
+ ) {
26
53
  try {
27
- const { returnValue, status, errorsFound = [], graphServiceTag, parentFlowId } = requestParams;
28
- if (empty(returnValue?.requestParams)) throw new NoRetryError('message not an object');
54
+ _izContext.logger.debug('[<%- action %>Complete] started', {
55
+ requestParams
56
+ });
57
+ const {
58
+ returnValue,
59
+ status,
60
+ errorsFound = [],
61
+ graphServiceTag,
62
+ parentFlowId
63
+ } = requestParams;
64
+ if (empty(returnValue?.requestParams))
65
+ throw new NoRetryError('message not an object');
29
66
  validateInput(returnValue, status, graphServiceTag, errorsFound);
30
67
  if (errorsFound.length > 0) errorsFound.push(errorsFound.join(','));
31
68
 
32
- const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(parentFlowId, PREFIX.ASYNC);
33
- const pending = await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(_izContext, awaitingStepId);
34
- const result = await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
35
- _izContext, pending.pendingStepId, awaitingStepId, errorsFound
69
+ const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
70
+ parentFlowId,
71
+ PREFIX.ASYNC
72
+ );
73
+ const pending =
74
+ await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
75
+ _izContext,
76
+ awaitingStepId
77
+ );
78
+ _izContext.logger.debug('[<%- action %>Complete] awaiting step', {
79
+ awaitingStepId,
80
+ pending
81
+ });
82
+ if (!pending) {
83
+ _izContext.logger.warn(
84
+ `No pending step found for awaitingStepId: ${awaitingStepId}`
85
+ );
86
+ return { returnValue, status, errorsFound };
87
+ }
88
+ const result =
89
+ await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
90
+ _izContext,
91
+ pending.pendingStepId,
92
+ awaitingStepId,
93
+ errorsFound
94
+ );
95
+ _izContext.logger.debug(
96
+ '[<%- action %>Complete] all awaiting steps result',
97
+ {
98
+ isComplete: result.isComplete,
99
+ awaitingStepId,
100
+ pendingStepId: pending.pendingStepId
101
+ }
36
102
  );
37
103
 
38
104
  if (result.isComplete) {
39
- const node = returnValue.queryResult.return<%- action %>Node ?? {};
40
- const existsNode = node.existsNode && Object.keys(node.existsNode).length
41
- ? { objType: returnValue.requestParams.objType, objInstanceFull: node.existsNode.objInstanceFull }
42
- : null;
105
+ const nodeResultKey = `return<%- action %>dNode`;
106
+ const fallbackNodeResultKey = `return<%- action %>Node`;
107
+ const nodeResult =
108
+ returnValue.queryResult[nodeResultKey] ??
109
+ returnValue.queryResult[fallbackNodeResultKey] ??
110
+ {};
111
+ const node = nodeResult[`<%- action.toLowerCase() %>NodeResult`] ?? nodeResult;
112
+ const existsNode =
113
+ node.existsNode && Object.keys(node.existsNode).length
114
+ ? {
115
+ objType: returnValue.requestParams.objType,
116
+ objInstanceFull: node.existsNode.objInstanceFull
117
+ }
118
+ : null;
43
119
  if (status === 'complete') {
44
- await Promise.all((pending.listOfRecords ?? []).flatMap(records => Object.values(records).map(async record =>
45
- dynamodbSharedLib.putItem(_izContext, await dynamodbSharedLib.tableName(_izContext, record.tableName, record.serviceTag), {
46
- ...record.objInstanceFull.identifiers,
47
- ...record.objInstanceFull.fields
48
- })
49
- )));
120
+ await Promise.all(
121
+ (pending.listOfRecords ?? []).flatMap((records) =>
122
+ Object.values(records).map(async (record) =>
123
+ dynamodbSharedLib.putItem(
124
+ _izContext,
125
+ await dynamodbSharedLib.tableName(
126
+ _izContext,
127
+ record.tableName,
128
+ record.serviceTag
129
+ ),
130
+ {
131
+ ...record.objInstanceFull.identifiers,
132
+ ...record.objInstanceFull.fields
133
+ }
134
+ )
135
+ )
136
+ )
137
+ );
50
138
  }
51
- const message = callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(passBackProperties, {
52
- objType: returnValue.requestParams.objType,
53
- objInstanceFull: node.objInstanceFull,
54
- relationships: node.relationships,
55
- parentFlowId: returnValue.parentFlowId,
56
- existsNode,
57
- status,
58
- errorsFound
139
+ const message =
140
+ callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
141
+ passBackProperties,
142
+ {
143
+ objType: returnValue.requestParams.objType,
144
+ objInstanceFull: node.objInstanceFull,
145
+ relationships: node.relationships,
146
+ parentFlowId: returnValue.parentFlowId,
147
+ existsNode,
148
+ status,
149
+ errorsFound
150
+ }
151
+ );
152
+ const messageAttributes =
153
+ callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
154
+ passBackProperties,
155
+ {}
156
+ );
157
+ const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
158
+ _izContext,
159
+ TOPIC_NAME_GENERATE_CODE.out<%- action %>NodeComplete
160
+ );
161
+ _izContext.logger.debug('[<%- action %>Complete] publishing to SNS', {
162
+ TopicArn: topicArn,
163
+ message
59
164
  });
60
- const messageAttributes = callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(passBackProperties, {});
61
165
  await sns.publishAsync(_izContext, {
62
166
  Message: JSON.stringify(message),
63
- MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
64
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, TOPIC_NAME_GENERATE_CODE.out<%- action %>NodeComplete)
167
+ MessageAttributes: sns.createStringMessageAttributes(
168
+ _izContext,
169
+ messageAttributes
170
+ ),
171
+ TopicArn: topicArn
65
172
  });
66
173
  //(<afterSendMessage>)
67
174
  //(</afterSendMessage>)
68
175
  }
69
- await asyncFlowSharedLib.removeAwaitingMultipleStep(_izContext, awaitingStepId, pending.pendingStepId, errorsFound);
176
+ await asyncFlowSharedLib.removeAwaitingMultipleStep(
177
+ _izContext,
178
+ awaitingStepId,
179
+ pending.pendingStepId,
180
+ errorsFound
181
+ );
70
182
  return { returnValue, status, errorsFound };
71
183
  } catch (error) {
72
- _izContext.logger.error('<%- action %>Complete error:', error);
184
+ _izContext.logger.error('[<%- action %>Complete] error:', error);
73
185
  throw error;
74
186
  }
75
187
  }
@@ -15,13 +15,19 @@ You should have received a copy of the GNU Affero General Public License
15
15
  along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
-
19
-
20
- import { middlewareHandler as middleware, validatorSchema, consts, response } from "@izara_project/izara-middleware";
18
+ import {
19
+ middlewareHandler as middleware,
20
+ validatorSchema,
21
+ consts,
22
+ response
23
+ } from '@izara_project/izara-middleware';
21
24
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
22
25
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
26
  import { objectHash as hash } from '@izara_project/izara-shared-core';
24
- import { utils, getObjectSchema } from "@izara_project/izara-core-library-service-schemas";
27
+ import {
28
+ utils,
29
+ getObjectSchema
30
+ } from '@izara_project/izara-core-library-service-schemas';
25
31
  const { createFlowTypeConcat } = utils;
26
32
 
27
33
  import { webSocket } from '@izara_project/izara-core-library-external-request';
@@ -29,68 +35,83 @@ const { postToConnection } = webSocket;
29
35
 
30
36
  import <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> from './<%- typeof mainFileName !== 'undefined' ? mainFileName : `${upperCaseFlowTag}_Main` %>.js';
31
37
 
32
- export const main = middleware.wrap(async (event, context) => {
38
+ //(<optionalRequire>)
39
+ //(</optionalRequire>)
33
40
 
41
+ export const main = middleware.wrap(async (event, context) => {
34
42
  event._izContext.logger.debug('Event:', event);
35
43
 
36
44
  try {
37
45
  if (event.requestContext) {
38
46
  const route = event.requestContext.routeKey;
39
47
  const connectionId = event.requestContext.connectionId;
40
- let correlationId = event._izContext.correlationIds.get(consts.X_CORRELATION_ID)
48
+ let correlationId = event._izContext.correlationIds.get(
49
+ consts.X_CORRELATION_ID
50
+ );
41
51
 
42
52
  switch (route) {
43
-
44
53
  case '$default':
45
54
  console.log('Received unknown route:', route);
46
- break
55
+ break;
47
56
  case '<%- flowTag %>':
48
- console.log("event in route webSocket", event);
49
- let eventParams = JSON.parse(event.body)
57
+ console.log('event in route webSocket', event);
58
+ let eventParams = JSON.parse(event.body);
50
59
 
51
60
  //(<createIdentifiersFlow>)
52
- let identifiers = ""
61
+ let identifiers = '';
53
62
  //(</createIdentifiersFlow>)
54
63
 
55
64
  let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
56
65
  event._izContext,
57
66
  {
58
- flowTag: "<%- flowTag %>",
67
+ flowTag: '<%- flowTag %>',
59
68
  serviceTag: process.env.iz_serviceTag
60
69
  }
61
- )
70
+ );
62
71
 
63
- if (flowSchema.statusType === "statusField" || flowSchema.statusType === "storedCache" || flowSchema.statusType === "triggerCache") {
64
- await dynamodbSharedLib.putItem(event._izContext,
65
- await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
72
+ if (
73
+ flowSchema.statusType === 'statusField' ||
74
+ flowSchema.statusType === 'storedCache' ||
75
+ flowSchema.statusType === 'triggerCache'
76
+ ) {
77
+ await dynamodbSharedLib.putItem(
78
+ event._izContext,
79
+ await dynamodbSharedLib.tableName(
80
+ event._izContext,
81
+ 'WebSocketTask'
82
+ ),
66
83
  {
67
- taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
84
+ taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
68
85
  connectionId: connectionId,
69
86
  ttl: 600
70
87
  }
71
- )
72
-
73
- } else if (flowSchema.statusType === "none") {
88
+ );
89
+ } else if (flowSchema.statusType === 'none') {
74
90
  await dynamodbSharedLib.putItem(
75
91
  event._izContext,
76
- await dynamodbSharedLib.tableName(event._izContext, "WebSocketTask"),
92
+ await dynamodbSharedLib.tableName(
93
+ event._izContext,
94
+ 'WebSocketTask'
95
+ ),
77
96
  {
78
- taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${correlationId}`,
79
- connectionId: connectionId,
97
+ taskKey: `${createFlowTypeConcat(event._izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${correlationId}`,
98
+ connectionId: connectionId
80
99
  }
81
- )
100
+ );
82
101
  }
83
102
 
84
- let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
103
+ let callingFlow = eventParams?.callingFlow
104
+ ? eventParams.callingFlow
105
+ : {};
85
106
  await <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>(
86
107
  event._izContext,
87
108
  eventParams,
88
109
  //(<additionalParams>)
89
110
  //(</additionalParams>)
90
111
  callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
91
- )
112
+ );
92
113
 
93
- break
114
+ break;
94
115
  }
95
116
  } else {
96
117
  const connId = event.connId;
@@ -98,13 +119,12 @@ export const main = middleware.wrap(async (event, context) => {
98
119
  await postToConnection({ message: event.message }, connId);
99
120
  }
100
121
 
101
- return (response.webSocketSuccess());
102
-
122
+ return response.webSocketSuccess();
103
123
  } catch (err) {
104
- const connId = event.requestContext.connectionId
124
+ const connId = event.requestContext.connectionId;
105
125
  event._izContext.logger.error('Error, WebSocket: ', err);
106
126
  // await sendErrorMessage({ message: err.message }, connId);
107
127
  await postToConnection({ message: err.message }, connId);
108
- return (response.failure(err));
128
+ return response.failure(err);
109
129
  }
110
130
  });
@@ -1,20 +1,23 @@
1
- import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
1
+ import {
2
+ middlewareHandler as middleware,
3
+ response
4
+ } from '@izara_project/izara-middleware';
2
5
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
3
6
 
4
7
  import <%= functionName %> from './<%= mainFileName %>.js';
5
8
 
6
9
  const validatorSchema = {
7
- //(<validatorSchema>)
8
- <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
9
- type: 'object',
10
- properties: {
10
+ //(<validatorSchema>)
11
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
12
+ type: 'object',
13
+ properties: {
11
14
  <% startConfig.properties.forEach(prop => { -%>
12
- <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' },
15
+ <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }
13
16
  <% }) -%>
14
- },
15
- required: [ <%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
16
- <% } -%>
17
- //(</validatorSchema>)
17
+ },
18
+ required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
19
+ <% } -%>
20
+ //(</validatorSchema>)
18
21
  };
19
22
 
20
23
  middleware.setValidatorSchema(validatorSchema, { noAuthorizer: true });
@@ -24,28 +27,51 @@ middleware.setValidatorSchema(validatorSchema, { noAuthorizer: true });
24
27
  * Triggered by: API Gateway
25
28
  */
26
29
  export const main = middleware.wrap(async (event, context) => {
27
- event._izContext?.logger?.debug(`[${context.awsRequestId}] Received API request in <%= flowStepName %>`);
28
-
29
- try {
30
- const passOnProperties = [
31
- event.body,
32
- //(<additionalParams>)
33
- //(</additionalParams>)
34
- callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
35
- ];
36
-
37
- const lambdaFunctionResponse = await <%= functionName %>(
38
- event._izContext,
39
- ...passOnProperties
40
- );
41
-
42
- if (lambdaFunctionResponse instanceof Error) {
43
- return response.failure(lambdaFunctionResponse);
30
+ event._izContext?.logger?.debug(
31
+ `[${context.awsRequestId}] Received API request in <%= flowStepName %>`
32
+ );
33
+
34
+ try {
35
+ let objectType;
36
+ if (event.routeKey) {
37
+ const path = event.routeKey.split(' ')[1];
38
+ if (path) {
39
+ const segments = path.split('/');
40
+ const serviceName = process.env.iz_serviceName;
41
+ const serviceIndex = segments.indexOf(serviceName);
42
+ if (serviceIndex !== -1 && segments.length > serviceIndex + 1) {
43
+ objectType = segments[serviceIndex + 1];
44
44
  }
45
+ }
46
+ }
45
47
 
46
- return response.success(lambdaFunctionResponse);
47
- } catch (err) {
48
- event._izContext?.logger?.error('Unhandled Error in <%= flowStepName %> API:', err);
49
- return response.failure(err);
48
+ if (objectType) {
49
+ event.body = event.body || {};
50
+ event.body.objectType = objectType;
50
51
  }
52
+
53
+ const passOnProperties = [
54
+ event.body,
55
+ //(<additionalParams>)
56
+ //(</additionalParams>)
57
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
58
+ ];
59
+
60
+ const lambdaFunctionResponse = await <%= functionName %>(
61
+ event._izContext,
62
+ ...passOnProperties
63
+ );
64
+
65
+ if (lambdaFunctionResponse instanceof Error) {
66
+ return response.failure(lambdaFunctionResponse);
67
+ }
68
+
69
+ return response.success(lambdaFunctionResponse);
70
+ } catch (err) {
71
+ event._izContext?.logger?.error(
72
+ 'Unhandled Error in <%= flowStepName %> API:',
73
+ err
74
+ );
75
+ return response.failure(err);
76
+ }
51
77
  });
@@ -1,20 +1,20 @@
1
- import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
1
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
2
2
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
3
3
 
4
4
  import <%= functionName %> from './<%= mainFileName %>.js';
5
5
 
6
6
  const validatorSchema = {
7
- //(<validatorSchema>)
8
- <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
9
- type: 'object',
10
- properties: {
7
+ //(<validatorSchema>)
8
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
9
+ type: 'object',
10
+ properties: {
11
11
  <% startConfig.properties.forEach(prop => { -%>
12
- <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' },
12
+ <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }
13
13
  <% }) -%>
14
- },
15
- required: [ <%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %> ]
16
- <% } -%>
17
- //(</validatorSchema>)
14
+ },
15
+ required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
16
+ <% } -%>
17
+ //(</validatorSchema>)
18
18
  };
19
19
 
20
20
  middleware.setValidatorSchema(validatorSchema);
@@ -24,22 +24,24 @@ middleware.setValidatorSchema(validatorSchema);
24
24
  * Triggered by: Lambda Invocation
25
25
  */
26
26
  export const main = middleware.wrap(async (event, context) => {
27
- event._izContext?.logger?.debug(`[${context.awsRequestId}] Received Invocation in <%= flowStepName %>`);
27
+ event._izContext?.logger?.debug(
28
+ `[${context.awsRequestId}] Received Invocation in <%= flowStepName %>`
29
+ );
28
30
 
29
- try {
30
- const passOnProperties = [
31
- event,
32
- //(<additionalParams>)
33
- //(</additionalParams>)
34
- callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
35
- ];
31
+ try {
32
+ const passOnProperties = [
33
+ event,
34
+ //(<additionalParams>)
35
+ //(</additionalParams>)
36
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(event)
37
+ ];
36
38
 
37
- return await <%= functionName %>(
38
- event._izContext,
39
- ...passOnProperties
40
- );
41
- } catch (err) {
42
- event._izContext?.logger?.error('Unhandled Error in <%= flowStepName %> Invocation:', err);
43
- throw err;
44
- }
39
+ return await <%= functionName %>(event._izContext, ...passOnProperties);
40
+ } catch (err) {
41
+ event._izContext?.logger?.error(
42
+ 'Unhandled Error in <%= flowStepName %> Invocation:',
43
+ err
44
+ );
45
+ throw err;
46
+ }
45
47
  });
@@ -24,13 +24,16 @@ import <%= functionName %> from './<%= mainFileName %>.js';
24
24
  // validate event properties in body.Message of sqs event
25
25
  let perRecordsValidatorSchema = {
26
26
  //(<validatorSchema>)
27
- <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
27
+ <% if (typeof startConfig !== 'undefined' && startConfig !== null && startConfig.properties && startConfig.properties.length > 0) { -%>
28
28
  type: 'object',
29
29
  properties: {
30
- <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: { type: '<%- prop.type || 'string' %>' }<%= index < startConfig.properties.length - 1 ? ',' : '' %>
31
- <% }) %> },
30
+ <% startConfig.properties.forEach((prop, index) => { %> <%- prop.propertyName %>: {
31
+ type: '<%- prop.type || 'string' %>'
32
+ } /*__EJS_COMMA_6__*/
33
+ <% }) %>
34
+ },
32
35
  required: [<%- startConfig.properties.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
33
- <% } -%>
36
+ <% } -%>
34
37
  //(</validatorSchema>)
35
38
  };
36
39
 
@@ -38,15 +41,16 @@ let perRecordsValidatorSchema = {
38
41
  let messageAttributeValidatorSchema = {
39
42
  type: 'object',
40
43
  properties: {
41
- <% startConfig.messageAttributes.forEach((prop, index) => { %> '<%- prop.propertyName %>': {
44
+ <% startConfig.messageAttributes.forEach((prop, index) => { %> <%- prop.propertyName %>: {
42
45
  type: 'object',
43
46
  properties: {
44
47
  Type: { type: 'string' },
45
48
  Value: { type: '<%- prop.type || 'string' %>' }
46
49
  },
47
50
  required: ['Type', 'Value']
48
- }<%= index < startConfig.messageAttributes.length - 1 ? ',' : '' %>
49
- <% }) %> },
51
+ } /*__EJS_COMMA_14__*/
52
+ <% }) %>
53
+ },
50
54
  required: [<%- startConfig.messageAttributes.filter(p => p.required !== false).map(p => `'${p.propertyName}'`).join(', ') %>]
51
55
  };
52
56
  <% } else { -%>
@@ -60,7 +64,7 @@ export const main = middleware.wrap(async (event, context) => {
60
64
 
61
65
  // loop each record and send to mainFunction
62
66
  await Promise.all(
63
- event.Records.map(async record => {
67
+ event.Records.map(async (record) => {
64
68
  // promise.all for map() function
65
69
 
66
70
  let passOnProperties = [];
@@ -76,19 +80,19 @@ export const main = middleware.wrap(async (event, context) => {
76
80
 
77
81
  // add argument (to invoke lambda) to passOnProperties[]
78
82
  passOnProperties.push(record.body.Message);
79
- <% if (typeof usePassBack === 'undefined' ? functionName.endsWith('Complete') : usePassBack) { %>
83
+ <% if (typeof usePassBack === 'undefined' ? functionName.endsWith('Complete') : usePassBack) { %>
80
84
  passOnProperties.push(
81
85
  callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
82
86
  record.body.Message
83
87
  )
84
88
  );
85
- <% } else { %>
89
+ <% } else { %>
86
90
  passOnProperties.push(
87
91
  callingFlowSharedLib.addCallingFlowToPassOnProperties(
88
92
  record.body.Message
89
93
  )
90
94
  );
91
- <% } %>
95
+ <% } %>
92
96
  //(<additionalParams>)
93
97
  //(</additionalParams>)
94
98
  record._izContext.logger.debug(