@izara_project/izara-core-generate-service-code 1.0.67 → 1.0.69

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 (128) hide show
  1. package/.prettierrc +11 -0
  2. package/package.json +16 -12
  3. package/scripts/format-ejs.js +104 -0
  4. package/src/compile/compileProject.js +40 -9
  5. package/src/compile/loadSchemas.js +120 -11
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +188 -41
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +34 -18
  8. package/src/emit/crud/generateCrudApplicationArtifacts.js +14 -6
  9. package/src/emit/crud/generateDynamicCrudFlowSchemas.js +4 -1
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +296 -105
  11. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +222 -144
  12. package/src/emit/crud/templates/FlowEndpointBeforeLogical_Main.ejs +22 -6
  13. package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +134 -43
  14. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +51 -31
  15. package/src/emit/crud/templates/FlowHandler_HdrApi.ejs +53 -45
  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 +402 -249
  22. package/src/emit/custom/customFlows.js +68 -28
  23. package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +520 -123
  24. package/src/emit/custom/generateCustomFlowApplicationArtifacts.js +28 -8
  25. package/src/emit/custom/templates/FlowEndpoint_Main.ejs +48 -36
  26. package/src/emit/custom/templates/FlowStep_Main.ejs +7 -9
  27. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +59 -54
  28. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +33 -23
  29. package/src/emit/custom/templates/s3/CreateObject_HdrWbs.ejs +30 -23
  30. package/src/emit/custom/templates/s3/CreateObject_Main.ejs +56 -39
  31. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +56 -51
  32. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +112 -75
  33. package/src/emit/custom/templates/s3/FlowHandler_HdrS3.ejs +14 -9
  34. package/src/emit/custom/templates/s3/ProcessS3File_Main.ejs +11 -8
  35. package/src/emit/custom/templates/s3/ReservedLimit_HdrSqs.ejs +65 -56
  36. package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +74 -52
  37. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +58 -14
  38. package/src/emit/custom/templates/triggerCache/CheckTriggerCache_Main.ejs +12 -17
  39. package/src/emit/custom/templates/triggerCache/TriggerCacheComplete_Main.ejs +20 -13
  40. package/src/emit/custom/templates/triggerCache/TriggerCache_Main.ejs +4 -1
  41. package/src/emit/function/functionYamlArtifact.js +272 -79
  42. package/src/emit/function/templates/ApiFunction_Yaml.ejs +7 -0
  43. package/src/emit/function/templates/EventBridgeFunction_Yaml.ejs +6 -0
  44. package/src/emit/function/templates/InvFunction_Yaml.ejs +5 -0
  45. package/src/emit/function/templates/S3Function_Yaml.ejs +16 -0
  46. package/src/emit/function/templates/SqsFunction_Yaml.ejs +10 -0
  47. package/src/emit/function/templates/WbsFunction_Yaml.ejs +10 -0
  48. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +40 -29
  49. package/src/emit/rbac/emitRbacApplicationArtifacts.js +171 -72
  50. package/src/emit/rbac/generateCreateTargetRoleHandler.js +6 -4
  51. package/src/emit/rbac/generateDynamicRbacFlowSchemas.js +8 -2
  52. package/src/emit/rbac/rbacFlowTag.js +3 -1
  53. package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +41 -18
  54. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +23 -3
  55. package/src/emit/rbac/templates/ListRbac_HdrApi.ejs +27 -5
  56. package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +41 -8
  57. package/src/emit/rbac/templates/ListRbac_Main.ejs +26 -6
  58. package/src/emit/rbac/templates/RbacMutation_Main.ejs +23 -3
  59. package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +46 -0
  60. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +152 -33
  61. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +24 -4
  62. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +26 -11
  63. package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +179 -37
  64. package/src/emit/relationship/generateDynamicRelationshipFlowSchemas.js +8 -2
  65. package/src/emit/relationship/generateRelationshipApplicationArtifacts.js +15 -6
  66. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +64 -37
  67. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +258 -142
  68. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +68 -43
  69. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +315 -171
  70. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +67 -41
  71. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +226 -115
  72. package/src/emit/relationship/templates/FlowHandler_HdrApi.ejs +41 -33
  73. package/src/emit/relationship/templates/FlowHandler_HdrDsq.ejs +15 -11
  74. package/src/emit/relationship/templates/FlowHandler_HdrInv.ejs +28 -26
  75. package/src/emit/relationship/templates/FlowHandler_HdrSqs.ejs +15 -11
  76. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +46 -26
  77. package/src/emit/relationship/templates/GetRelationship_Main.ejs +233 -126
  78. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +72 -44
  79. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +266 -150
  80. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +74 -45
  81. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +285 -152
  82. package/src/emit/resource/emitResourceArtifacts.js +274 -105
  83. package/src/emit/resource/generateResourceArtifacts.js +15 -6
  84. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +139 -0
  85. package/src/emit/resource/templates/S3Bucket_Yaml.ejs +19 -0
  86. package/src/emit/resource/templates/S3Subscription_Yaml.ejs +7 -0
  87. package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +7 -0
  88. package/src/emit/system/emitSystemWebSocketArtifacts.js +61 -165
  89. package/src/emit/system/templates/WebSocketComplete_HdrSqs.ejs +32 -0
  90. package/src/emit/system/templates/WebSocketComplete_Main.ejs +46 -0
  91. package/src/emit/system/templates/WebSocketComplete_Yaml.ejs +19 -0
  92. package/src/emit/system/templates/WebSocketConnect.ejs +25 -0
  93. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +11 -0
  94. package/src/generate.js +141 -34
  95. package/src/generateIntTest.js +76 -28
  96. package/src/generateResourceIntTest.js +35 -12
  97. package/src/generateResources/IntTest/generateResources/generateResources.js +5 -2
  98. package/src/generateResources/IntTest/generateResources/templateResources.ejs +18 -30
  99. package/src/generateResources/IntTest/generateTests/events/events.js +1 -1
  100. package/src/generateResources/IntTest/generateTests/events/templateEvents.ejs +13 -10
  101. package/src/generateResources/IntTest/generateTests/generateTemplate.js +2 -2
  102. package/src/generateResources/IntTest/generateTests/pathIntTest/pathIntTest.js +2 -1
  103. package/src/generateResources/IntTest/generateTests/pathIntTest/template.ejs +1 -3
  104. package/src/generateResources/IntTest/generateTests/tests/templateTests.ejs +1 -1
  105. package/src/generateResources/IntTest/generateTests/tests/tests.js +7 -3
  106. package/src/generateResources/IntTest/libs/{libs.js → IntTestGenerateLib.js} +34 -23
  107. package/src/generateResources/IntTest/upload/uploadIntTest.js +33 -19
  108. package/src/intTestGeneratorShared.js +15 -10
  109. package/src/output/commitArtifacts.js +99 -39
  110. package/src/output/mergeHooks.js +24 -10
  111. package/src/output/validateArtifacts.js +37 -27
  112. package/src/plan/buildGenerationPlan.js +24 -13
  113. package/test/core.test.js +116 -49
  114. package/test/createTargetRoleHandler.test.js +63 -14
  115. package/test/crudApplicationArtifacts.test.js +128 -23
  116. package/test/customFlowApplicationArtifacts.test.js +391 -84
  117. package/test/dynamicCrudFlowSchemas.test.js +74 -26
  118. package/test/dynamicRbacFlowSchemas.test.js +63 -20
  119. package/test/dynamicRelationshipFlowSchemas.test.js +65 -18
  120. package/test/functionYamlArtifact.test.js +67 -10
  121. package/test/intTestApi.test.js +9 -10
  122. package/test/publicApi.test.js +184 -44
  123. package/test/relationshipApplicationArtifacts.test.js +90 -19
  124. package/test/resourceArtifacts.test.js +183 -33
  125. package/docs/test.png +0 -0
  126. package/src/emit/rbac/templates/UserRbacFlow_HdrInv.ejs +0 -10
  127. package/src/emit/relationship/dynamicRelationshipFlowSchemaTemplate.js +0 -11
  128. /package/docs/{test.mmd → TriggeredCacheFlow.mmd} +0 -0
@@ -16,8 +16,6 @@ along with this program. If not, see
16
16
  <http: //www.gnu.org/licenses />.
17
17
  */
18
18
 
19
-
20
-
21
19
  import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
22
20
  import { consts } from '@izara_project/izara-middleware';
23
21
 
@@ -53,79 +51,98 @@ const { TOPIC_NAME_GENERATE_CODE } = schemaConsts;
53
51
  export default async function createObject(
54
52
  _izContext,
55
53
  requestParams,
56
- callingFlowConfig = {},
54
+ callingFlowConfig = {}
57
55
  //(<additionalParams>)
58
56
  //(</additionalParams>)
59
57
  ) {
60
-
61
58
  try {
62
- _izContext.logger.debug("WebSocketInvoke _izContext", _izContext)
63
- _izContext.logger.debug("WebSocketInvoke requestParams", requestParams)
64
- _izContext.logger.debug("WebSocketInvoke callingFlowConfig", callingFlowConfig)
59
+ _izContext.logger.debug('WebSocketInvoke _izContext', _izContext);
60
+ _izContext.logger.debug('WebSocketInvoke requestParams', requestParams);
61
+ _izContext.logger.debug(
62
+ 'WebSocketInvoke callingFlowConfig',
63
+ callingFlowConfig
64
+ );
65
65
 
66
- let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
66
+ let connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID);
67
67
 
68
- let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
69
- flowTag: "<%- flowTag %>",
70
- serviceTag: process.env.iz_serviceTag
71
- })
68
+ let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
69
+ _izContext,
70
+ {
71
+ flowTag: '<%- flowTag %>',
72
+ serviceTag: process.env.iz_serviceTag
73
+ }
74
+ );
72
75
 
73
- _izContext.logger.debug("getFlowSchema", flowSchema)
76
+ _izContext.logger.debug('getFlowSchema', flowSchema);
74
77
 
75
- let getUserFromTableUserUploadRecord = await dynamodbSharedLib.getItem(_izContext,
76
- await dynamodbSharedLib.tableName(_izContext, "UserUploadRecords"),
78
+ let getUserFromTableUserUploadRecord = await dynamodbSharedLib.getItem(
79
+ _izContext,
80
+ await dynamodbSharedLib.tableName(_izContext, 'UserUploadRecords'),
77
81
  {
78
82
  connectionId: connectionId
79
83
  }
80
- )
84
+ );
81
85
 
82
- const { userId, submittedByUserId } = getUserFromTableUserUploadRecord
83
- _izContext.correlationIds.set(consts.BASE_USER_ID, userId)
84
- _izContext.correlationIds.set(consts.TARGET_ID, submittedByUserId)
86
+ const { userId, submittedByUserId } = getUserFromTableUserUploadRecord;
87
+ _izContext.correlationIds.set(consts.BASE_USER_ID, userId);
88
+ _izContext.correlationIds.set(consts.TARGET_ID, submittedByUserId);
85
89
 
86
90
  if (!flowSchema) {
87
- throw new NoRetryError(`flowTag not found ${requestParams.action}`)
91
+ throw new NoRetryError(`flowTag not found ${requestParams.action}`);
88
92
  }
89
93
 
90
94
  // get objectType
91
- let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(_izContext, flowSchema.objType)
92
- _izContext.logger.debug("objectSchema in flowSchema mainFunction", objectSchema)
95
+ let objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
96
+ _izContext,
97
+ flowSchema.objType
98
+ );
99
+ _izContext.logger.debug(
100
+ 'objectSchema in flowSchema mainFunction',
101
+ objectSchema
102
+ );
93
103
 
94
104
  if (!objectSchema) {
95
- throw new NoRetryError(`${flowSchema.objType.objectType} not found`)
105
+ throw new NoRetryError(`${flowSchema.objType.objectType} not found`);
96
106
  }
97
107
 
98
108
  //(<beforeCreateHook>)
99
109
  //(</beforeCreateHook>)
100
110
  // create message Object to create Endpoint
101
111
  let messageObject = {
102
- objectType: "<%- objectType %>",
112
+ objectType: '<%- objectType %>',
103
113
  fieldNames: {
104
114
  //(<fieldNamesHook>)
105
115
  //(</fieldNamesHook>)
106
116
  }
107
- }
117
+ };
108
118
  // create callingFlow
109
- messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
110
- messageObject,
111
- callingFlowSharedLib.addParentCallingFlowConfig(
112
- callingFlowConfig,
113
- callingFlowSharedLib.createCallingFlowConfig(
114
- await lambdaSharedLib.lambdaFunctionName(_izContext, TOPIC_NAME_GENERATE_CODE.createNodeComplete), {}
119
+ messageObject =
120
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
121
+ messageObject,
122
+ callingFlowSharedLib.addParentCallingFlowConfig(
123
+ callingFlowConfig,
124
+ callingFlowSharedLib.createCallingFlowConfig(
125
+ await lambdaSharedLib.lambdaFunctionName(
126
+ _izContext,
127
+ TOPIC_NAME_GENERATE_CODE.createNodeComplete
128
+ ),
129
+ {}
130
+ )
115
131
  )
116
- )
117
- )
132
+ );
118
133
 
119
134
  // send message to Create endpoint
120
135
  let sendMessageToCreateEndpoint = {
121
136
  Message: JSON.stringify(messageObject),
122
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Create_In")
123
- }
124
- _izContext.logger.debug("sendMessageToCreateEndpoint", sendMessageToCreateEndpoint);
137
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Create_In')
138
+ };
139
+ _izContext.logger.debug(
140
+ 'sendMessageToCreateEndpoint',
141
+ sendMessageToCreateEndpoint
142
+ );
125
143
  await sns.publishAsync(_izContext, sendMessageToCreateEndpoint);
126
-
127
144
  } catch (err) {
128
- _izContext.logger.error('error WebSocketInvoke: ', err)
129
- throw (err)
145
+ _izContext.logger.error('error WebSocketInvoke: ', err);
146
+ throw err;
130
147
  }
131
148
  }
@@ -15,9 +15,7 @@ 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 } from "@izara_project/izara-middleware";
18
+ import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
21
19
  import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
22
20
  import Logger from '@izara_project/izara-core-library-logger';
23
21
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
@@ -29,18 +27,14 @@ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
29
27
 
30
28
  // set schema for record.body.Message
31
29
  let perRecordsValidatorSchema = {
32
- type: "object",
33
- required: [
34
- 'returnMessage',
35
- 'errorsFound',
36
- 'passStatus'
37
- ],
30
+ type: 'object',
31
+ required: ['returnMessage', 'errorsFound', 'passStatus'],
38
32
  properties: {
39
33
  returnMessage: {
40
- type: "object"
34
+ type: 'object'
41
35
  },
42
36
  errorsFound: {
43
- type: "array"
37
+ type: 'array'
44
38
  },
45
39
  passStatus: {
46
40
  type: 'boolean'
@@ -62,62 +56,73 @@ let perRecordsValidatorSchema = {
62
56
  // }
63
57
  // };
64
58
 
65
- perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema)
59
+ perRecordsValidatorSchema =
60
+ callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(
61
+ perRecordsValidatorSchema
62
+ );
66
63
 
67
64
  export const main = middleware.wrap(async (event, context) => {
68
-
69
65
  try {
70
-
71
66
  let recordPromises = [];
72
67
 
73
68
  // loop each record and send to mainFunction
74
- await Promise.all(event.Records.map(async record => { // promise.all for map() function
75
-
76
- let passOnProperties = []
77
- record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
78
-
79
- // validate message (and MessageAttributes)
80
- await recordHandlerSharedLib.validateRecord(
81
- record, // one record will send to mainFunction
82
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
83
- perRecordsValidatorSchema, // schema for record.Message
84
- // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
85
- );
86
-
87
- // add argument (to invoke lambda) to passOnProperties[]
88
- passOnProperties.push(record.body.Message.returnMessage)
89
- passOnProperties.push(record.body.Message.errorsFound)
90
- passOnProperties.push(record.body.Message.passStatus)
91
- //(<additionalProperties>)
92
- //(</additionalProperties>)
93
- passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message))
94
- record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
95
-
96
- // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
97
- let recordPromise = recordHandlerSharedLib.recordHandler(
98
- record, // one record will send to mainFunction
99
- <%= functionName %>, // mainFunction that need to invoke.
100
- "<%= functionName %><%= handlerType %>", // queue name that need to retry or send to dlq
101
- passOnProperties, // all parameters that mainFunction needed.
102
- );
103
- record._izContext.logger.debug('after recordPromise in handler');
104
- recordPromises.push(recordPromise); // push promise to recordPromises
105
- }))
69
+ await Promise.all(
70
+ event.Records.map(async (record) => {
71
+ // promise.all for map() function
72
+
73
+ let passOnProperties = [];
74
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
75
+
76
+ // validate message (and MessageAttributes)
77
+ await recordHandlerSharedLib.validateRecord(
78
+ record, // one record will send to mainFunction
79
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
80
+ perRecordsValidatorSchema // schema for record.Message
81
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
82
+ );
83
+
84
+ // add argument (to invoke lambda) to passOnProperties[]
85
+ passOnProperties.push(record.body.Message.returnMessage);
86
+ passOnProperties.push(record.body.Message.errorsFound);
87
+ passOnProperties.push(record.body.Message.passStatus);
88
+ //(<additionalProperties>)
89
+ //(</additionalProperties>)
90
+ passOnProperties.push(
91
+ callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
92
+ record.body.Message
93
+ )
94
+ );
95
+ record._izContext.logger.debug(
96
+ 'passOnProperties in handler',
97
+ passOnProperties
98
+ );
99
+
100
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
101
+ let recordPromise = recordHandlerSharedLib.recordHandler(
102
+ record, // one record will send to mainFunction
103
+ <%= functionName %>, // mainFunction that need to invoke.
104
+ '<%= functionName %><%= handlerType %>', // queue name that need to retry or send to dlq
105
+ passOnProperties // all parameters that mainFunction needed.
106
+ );
107
+ record._izContext.logger.debug('after recordPromise in handler');
108
+ recordPromises.push(recordPromise); // push promise to recordPromises
109
+ })
110
+ );
106
111
 
107
112
  Logger.debug('before Promise.all(recordPromises) in handler');
108
113
  try {
109
114
  // --- main await all promises
110
115
  await Promise.all(recordPromises); // await all promises
111
116
 
112
- return event.Records // return all for local test
113
-
117
+ return event.Records; // return all for local test
114
118
  } catch {
115
- Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
119
+ Logger.debug(
120
+ 'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
121
+ );
116
122
  }
117
123
  Logger.debug('after Promise.all(recordPromises) in handler');
118
-
119
124
  } catch (err) {
120
125
  Logger.error('Unhandled Error, <%= functionName %><%= handlerType %>: ', err);
121
- throw (err);
126
+ throw err;
122
127
  }
123
128
  });
@@ -15,25 +15,32 @@ 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
18
  import snsSharedLib from '@izara_project/izara-core-library-sns';
21
19
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
22
20
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
23
21
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
24
22
 
25
- import { lambda, sns } from '@izara_project/izara-core-library-external-request'
23
+ import {
24
+ lambda,
25
+ sns
26
+ } from '@izara_project/izara-core-library-external-request';
26
27
 
27
28
  import { S3Client } from '@aws-sdk/client-s3';
28
29
  import { createPresignedPost } from '@aws-sdk/s3-presigned-post';
29
30
  const client = new S3Client({ region: process.env.AWS_REGION });
30
31
  import { consts } from '@izara_project/izara-middleware';
31
32
 
32
- import { postToConnection, getNestObject } from '../../../libs/source/GenerateCodeLibs.js'
33
+ import {
34
+ postToConnection,
35
+ getNestObject
36
+ } from '../../../libs/source/GenerateCodeLibs.js';
33
37
  import { consts as coreConsts } from '@izara_project/izara-core-library-core';
34
- import { consts as schemaConsts, utils } from "@izara_project/izara-core-library-service-schemas"
38
+ import {
39
+ consts as schemaConsts,
40
+ utils
41
+ } from '@izara_project/izara-core-library-service-schemas';
35
42
  const { EXTERNAL_SERVICE_NAME } = schemaConsts;
36
- const { createFlowTypeConcat } = utils
43
+ const { createFlowTypeConcat } = utils;
37
44
  //(<optionalRequired>)
38
45
  //(</optionalRequired>)
39
46
 
@@ -51,7 +58,7 @@ const { createFlowTypeConcat } = utils
51
58
  * @returns {object} returnResponse
52
59
  */
53
60
 
54
- export default async function createPreSignUrl (
61
+ export default async function createPreSignUrl(
55
62
  _izContext,
56
63
  returnMessage,
57
64
  errorsFound,
@@ -59,10 +66,8 @@ export default async function createPreSignUrl (
59
66
  //(<additionalProperties>)
60
67
  //(</additionalProperties>)
61
68
  passBackProperties = {}
62
- ) {
63
-
69
+ ) {
64
70
  try {
65
-
66
71
  _izContext.logger.debug('----- createPreSignUrl event params -----', {
67
72
  returnMessage: returnMessage,
68
73
  errorsFound: errorsFound,
@@ -70,46 +75,54 @@ export default async function createPreSignUrl (
70
75
  passBackProperties: passBackProperties
71
76
  });
72
77
 
73
- const servicePendingId = passBackProperties.passBackProperties.identifier.servicePendingId; // importBatchId
74
- const reservedDataId = passBackProperties.passBackProperties.identifier.reservedDataId;
75
- const objType = passBackProperties.passBackProperties.objType
78
+ const servicePendingId =
79
+ passBackProperties.passBackProperties.identifier.servicePendingId; // importBatchId
80
+ const reservedDataId =
81
+ passBackProperties.passBackProperties.identifier.reservedDataId;
82
+ const objType = passBackProperties.passBackProperties.objType;
76
83
 
77
- const correlationId = _izContext.correlationIds.get(consts.X_CORRELATION_ID)
78
- const connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID)
84
+ const correlationId = _izContext.correlationIds.get(
85
+ consts.X_CORRELATION_ID
86
+ );
87
+ const connectionId = _izContext.correlationIds.get(consts.CONNECTION_ID);
79
88
 
80
- let getResult = await lambda.invokeSync(_izContext,
81
- await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv"),
89
+ let getResult = await lambda.invokeSync(
90
+ _izContext,
91
+ await lambdaSharedLib.lambdaFunctionName(_izContext, 'GetHdrInv'),
82
92
  {
83
- objectType: objType.objectType,
93
+ objectType: objType.objectType
84
94
  //(<identifiersForGetData>)
85
95
  //(</identifiersForGetData>)
86
96
  }
87
- )
88
- _izContext.logger.debug("getResult", getResult);
97
+ );
98
+ _izContext.logger.debug('getResult', getResult);
89
99
 
90
100
  //(<afterGetResult>)
91
101
  //(</afterGetResult>)
92
102
 
93
- let uniqueIdentify = getNestObject(
94
- _izContext,
95
- returnMessage,
96
- ['limitFound', 'runningTotal', 'uniqueIdentify', 'usedTimestampId']
97
- );
98
- _izContext.logger.debug("uniqueIdentify", uniqueIdentify);
103
+ let uniqueIdentify = getNestObject(_izContext, returnMessage, [
104
+ 'limitFound',
105
+ 'runningTotal',
106
+ 'uniqueIdentify',
107
+ 'usedTimestampId'
108
+ ]);
109
+ _izContext.logger.debug('uniqueIdentify', uniqueIdentify);
99
110
 
100
- await dynamodbSharedLib.putItem(_izContext,
101
- await dynamodbSharedLib.tableName(_izContext, "ReservedDataMain"),
111
+ await dynamodbSharedLib.putItem(
112
+ _izContext,
113
+ await dynamodbSharedLib.tableName(_izContext, 'ReservedDataMain'),
102
114
  //(<createReservedDataMain>)
103
115
  {}
104
116
  //(</createReservedDataMain>)
105
117
  );
106
118
 
107
- if (passStatus === false) { // if passStatus false post message to client
119
+ if (passStatus === false) {
120
+ // if passStatus false post message to client
108
121
  // use correlationId to get connectionId and use connectionId to post message to client
109
122
 
110
- _izContext.logger.debug("reserved has reach limit");
123
+ _izContext.logger.debug('reserved has reach limit');
111
124
 
112
- errorsFound.push("reserved has reach limit")
125
+ errorsFound.push('reserved has reach limit');
113
126
  // update status
114
127
  let updateStatusField = {
115
128
  objInstanceFull: {
@@ -123,13 +136,16 @@ export default async function createPreSignUrl (
123
136
  }
124
137
  },
125
138
  objectType: objType.objectType
126
- }
139
+ };
127
140
 
128
141
  let sendMessageToUpdateEndpoint = {
129
142
  Message: JSON.stringify(updateStatusField),
130
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, `Update_In`)
131
- }
132
- _izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
143
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, `Update_In`)
144
+ };
145
+ _izContext.logger.debug(
146
+ 'sendMessageToUpdateEndpoint',
147
+ sendMessageToUpdateEndpoint
148
+ );
133
149
 
134
150
  // cancel reserved
135
151
 
@@ -141,38 +157,49 @@ export default async function createPreSignUrl (
141
157
 
142
158
  let sendMessageToCancelReserved = {
143
159
  Message: JSON.stringify(cancelReservedMsg),
144
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'CancelUsage_In', EXTERNAL_SERVICE_NAME.accountLimits)
160
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
161
+ _izContext,
162
+ 'CancelUsage_In',
163
+ EXTERNAL_SERVICE_NAME.accountLimits
164
+ )
145
165
  };
146
166
 
147
- _izContext.logger.debug("sendMessageToCancelReserved", sendMessageToCancelReserved);
167
+ _izContext.logger.debug(
168
+ 'sendMessageToCancelReserved',
169
+ sendMessageToCancelReserved
170
+ );
148
171
  await sns.publishAsync(_izContext, sendMessageToCancelReserved);
149
172
 
150
- await postToConnection({ message: "reserved has reach limit" }, connectionId)
173
+ await postToConnection(
174
+ { message: 'reserved has reach limit' },
175
+ connectionId
176
+ );
151
177
 
152
178
  //(<createIdentifiersForDeleteTask>)
153
- let identifiers
179
+ let identifiers;
154
180
  //(</createIdentifiersForDeleteTask>)
155
181
  // after post message delete websocket task
156
- await dynamodbSharedLib.deleteItem(_izContext,
157
- await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
182
+ await dynamodbSharedLib.deleteItem(
183
+ _izContext,
184
+ await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
158
185
  {
159
- taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
186
+ taskKey: `${createFlowTypeConcat(_izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
160
187
  connectionId: connectionId
161
188
  }
162
- )
189
+ );
163
190
 
164
191
  //(<afterCancelReservedLimit>)
165
192
  //(</afterCancelReservedLimit>)
166
193
 
167
- return "reserved not pass"
194
+ return 'reserved not pass';
168
195
  }
169
196
 
170
197
  //(<createKeyForUploadFile>)
171
- const Key = `${fileName}.${importType}`
198
+ const Key = `${fileName}.${importType}`;
172
199
  //(</createKeyForUploadFile>)
173
200
 
174
- const maximumSize = getResult.fields.fileSize * 1048576 // convert to byte unit for restrict
175
- _izContext.logger.debug("maximumSize", maximumSize);
201
+ const maximumSize = getResult.fields.fileSize * 1048576; // convert to byte unit for restrict
202
+ _izContext.logger.debug('maximumSize', maximumSize);
176
203
 
177
204
  // create PresignUrl
178
205
  let createPreSignUrlParam = {
@@ -180,9 +207,9 @@ export default async function createPreSignUrl (
180
207
  Key: Key,
181
208
  Conditions: [
182
209
  //(<conditionCreateUrlLink>)
183
- ["content-length-range", 0, maximumSize],
184
- ["starts-with", "$Content-Type", "file/csv"],
185
- ["eq", "$x-amz-meta-importBatchId", importBatchId]
210
+ ['content-length-range', 0, maximumSize],
211
+ ['starts-with', '$Content-Type', 'file/csv'],
212
+ ['eq', '$x-amz-meta-importBatchId', importBatchId]
186
213
  //(</conditionCreateUrlLink>)
187
214
  ],
188
215
  Fields: {},
@@ -197,11 +224,11 @@ export default async function createPreSignUrl (
197
224
  uploadUrl.fields['Content-Type'] = `file/${importType}`;
198
225
  //(</modifyUploadLinkField>)
199
226
 
200
- _izContext.logger.debug('uploadUrlLimitSize: ', uploadUrl) // return as object type = {url, fields}
227
+ _izContext.logger.debug('uploadUrlLimitSize: ', uploadUrl); // return as object type = {url, fields}
201
228
 
202
229
  // update to waiting to upload
203
230
  //(<checkStatusField>)
204
- if (status === "processing") {
231
+ if (status === 'processing') {
205
232
  //(</checkStatusField>)
206
233
  let messageObject = {
207
234
  objInstanceFull: {
@@ -210,52 +237,62 @@ export default async function createPreSignUrl (
210
237
  //(</identifiersForUpdateTable>)
211
238
  },
212
239
  fields: {
213
- importBatchStatus: "waitingToUpload",
214
- expiryTimestamp: (getResult.fields.startTime + (createPreSignUrlParam.Expires * 1000))
240
+ importBatchStatus: 'waitingToUpload',
241
+ expiryTimestamp:
242
+ getResult.fields.startTime + createPreSignUrlParam.Expires * 1000
215
243
  }
216
244
  },
217
245
  objectType: objType.objectType
218
- }
246
+ };
219
247
 
220
- messageObject = callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
221
- messageObject,
222
- callingFlowSharedLib.addParentCallingFlowConfig(
223
- returnMessage, // resive parent callingFlowConfig.
224
- callingFlowSharedLib.createCallingFlowConfig( // calling flow own service
225
- await lambdaSharedLib.lambdaFunctionName(_izContext, `WebSocketComplete`), {}
248
+ messageObject =
249
+ callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
250
+ messageObject,
251
+ callingFlowSharedLib.addParentCallingFlowConfig(
252
+ returnMessage, // resive parent callingFlowConfig.
253
+ callingFlowSharedLib.createCallingFlowConfig(
254
+ // calling flow own service
255
+ await lambdaSharedLib.lambdaFunctionName(
256
+ _izContext,
257
+ `WebSocketComplete`
258
+ ),
259
+ {}
260
+ )
226
261
  )
227
- )
228
- );
262
+ );
229
263
 
230
- _izContext.logger.debug("after add callingFlow", messageObject)
264
+ _izContext.logger.debug('after add callingFlow', messageObject);
231
265
 
232
266
  let sendMessageToUpdateEndpoint = {
233
267
  Message: JSON.stringify(messageObject),
234
- TopicArn: await snsSharedLib.snsTopicArnByFlowSchema(_izContext, "Update_In")
235
- }
236
- _izContext.logger.debug("sendMessageToUpdateEndpoint", sendMessageToUpdateEndpoint);
268
+ TopicArn: snsSharedLib.snsTopicArnByFlowSchema(_izContext, 'Update_In')
269
+ };
270
+ _izContext.logger.debug(
271
+ 'sendMessageToUpdateEndpoint',
272
+ sendMessageToUpdateEndpoint
273
+ );
237
274
  await sns.publishAsync(_izContext, sendMessageToUpdateEndpoint);
238
275
 
239
276
  //(<createIdentifierFlow>)
240
- let identifiers
277
+ let identifiers;
241
278
  //(</createIdentifierFlow>)
242
- await dynamodbSharedLib.updateItem(_izContext,
243
- await dynamodbSharedLib.tableName(_izContext, "WebSocketTask"),
279
+ await dynamodbSharedLib.updateItem(
280
+ _izContext,
281
+ await dynamodbSharedLib.tableName(_izContext, 'WebSocketTask'),
244
282
  {
245
- taskKey: `${createFlowTypeConcat(_izContext, { flowTag: "<%- flowTag %>", serviceTag: process.env.iz_serviceTag })}${identifiers}`,
283
+ taskKey: `${createFlowTypeConcat(_izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`,
246
284
  connectionId: connectionId
247
285
  },
248
286
  {
249
287
  uploadUrl: uploadUrl
250
288
  }
251
- )
289
+ );
252
290
  }
253
291
 
254
292
  //(<mainFunctionHookCode>)
255
293
  //(</mainFunctionHookCode>)
256
-
257
294
  } catch (err) {
258
- _izContext.logger.error('error createPreSignUrl: ', err)
259
- throw (err)
295
+ _izContext.logger.error('error createPreSignUrl: ', err);
296
+ throw err;
260
297
  }
261
298
  }