@izara_project/izara-market-library-service-schemas 1.0.6 → 1.0.7

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 (20) hide show
  1. package/package.json +1 -1
  2. package/src/TemplateManager/src/FindData/mainFunction/template.ejs +3 -0
  3. package/src/TemplateManager/src/GenerateCode.js +20 -14
  4. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +1 -1
  5. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/data.js +59 -0
  6. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/handler/template.ejs +129 -0
  7. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/data.js +53 -0
  8. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/mainFunction/template.ejs +172 -0
  9. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/data.js +58 -0
  10. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-in-sqs/template.ejs +47 -0
  11. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/data.js +62 -0
  12. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/sns-out/template.ejs +10 -0
  13. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +2 -3
  14. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +4 -2
  15. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrApi/data.js +1 -2
  16. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +3 -3
  17. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +171 -177
  18. package/src/TemplateManager/src/ProcessLogical/mainFunction/template.ejs +9 -1
  19. package/src/TemplateManager/src/externalService/LambdaRole/data.js +3 -6
  20. package/src/TemplateManager/src/libs/Consts.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,6 +26,9 @@ const serviceSchemas = require('@izara_project/izara-core-library-service-schema
26
26
  const serviceConfig = serviceSchemas.serviceConfig;
27
27
  const identifierObj = serviceSchemas.identifiersObject
28
28
 
29
+ //(<additionalModule>)
30
+ //(</additionalModule>)
31
+
29
32
  /**
30
33
  * triggered from searchResult for each requiredData field per one identifiers
31
34
  * @param {Object} _izContext
@@ -44,10 +44,10 @@ const mainFunctionUpdateData = require('./PerActionEndpoint/MainFunction/Update/
44
44
  const mainFunctionCreateData = require('./PerActionEndpoint/MainFunction/Create/data');
45
45
 
46
46
  // create function.yaml
47
- const functionGetYamlDataHdrInv = require('./PerActionEndpoint/FunctionYaml/HdrInv/data');
48
- const functionGetYamlDataHdrApi = require('./PerActionEndpoint/FunctionYaml/HdrApi/data');
49
- const functionGetYamlDataHdrSqs = require('./PerActionEndpoint/FunctionYaml/HdrSqs/data');
50
- const functionGetYamlDataHdrDsq = require('./PerActionEndpoint/FunctionYaml/HdrDsq/data');
47
+ const functionYamlDataHdrInv = require('./PerActionEndpoint/FunctionYaml/HdrInv/data');
48
+ const functionYamlDataHdrApi = require('./PerActionEndpoint/FunctionYaml/HdrApi/data');
49
+ const functionYamlDataHdrSqs = require('./PerActionEndpoint/FunctionYaml/HdrSqs/data');
50
+ const functionYamlDataHdrDsq = require('./PerActionEndpoint/FunctionYaml/HdrDsq/data');
51
51
 
52
52
  // out updateNode Complete
53
53
  const functionYamlOutUpdateComplete = require('./OutPerActionComplete/OutUpdateComplete/functionYaml/data');
@@ -58,7 +58,10 @@ const outUpdateCompleteSnsOut = require('./OutPerActionComplete/OutUpdateComplet
58
58
 
59
59
  // out CreateNode Complete
60
60
  const functionYamlOutCreateComplete = require('./OutPerActionComplete/OutCreateComplete/functionYaml/data');
61
-
61
+ const snsInSqsCreateObjectComplete = require('./OutPerActionComplete/OutCreateComplete/sns-in-sqs/data');
62
+ const snsOutCreateObjectComplete = require('./OutPerActionComplete/OutCreateComplete/sns-out/data')
63
+ const createObjectCompleteHandler = require('./OutPerActionComplete/OutCreateComplete/handler/data');
64
+ const createObjectCompleteMainFunction = require('./OutPerActionComplete/OutCreateComplete/mainFunction/data');
62
65
 
63
66
  // create Main resource
64
67
  const createSourceDataDynamoDB = require('./ResourceYaml/dynamodb/mainResourcePerObjectSchemaData');
@@ -245,13 +248,13 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
245
248
 
246
249
  const createMainFunction = [...createMainFunctionGet, ...createMainFunctionUpdate, ...createMainFunctionCreate]
247
250
  // generate functionYaml File
248
- const createFunctionGetYamlHdrInv = functionGetYamlDataHdrInv(_izContext, objectSchema, saveFilePath);
249
- const createFunctionGetYamlHdrApi = functionGetYamlDataHdrApi(_izContext, objectSchema, saveFilePath);
250
- const createFunctionGetYamlHdrSqs = functionGetYamlDataHdrSqs(_izContext, objectSchema, saveFilePath);
251
- const createFunctionGetYamlHdrDsq = functionGetYamlDataHdrDsq(_izContext, objectSchema, saveFilePath);
251
+ const createFunctionYamlHdrInv = functionYamlDataHdrInv(_izContext, objectSchema, saveFilePath);
252
+ const createFunctionYamlHdrApi = functionYamlDataHdrApi(_izContext, objectSchema, saveFilePath);
253
+ const createFunctionYamlHdrSqs = functionYamlDataHdrSqs(_izContext, objectSchema, saveFilePath);
254
+ const createFunctionYamlHdrDsq = functionYamlDataHdrDsq(_izContext, objectSchema, saveFilePath);
252
255
 
253
256
  // wrapMain Function
254
- const createFunctionYaml = [...createFunctionGetYamlHdrApi, ...createFunctionGetYamlHdrDsq, ...createFunctionGetYamlHdrInv, ...createFunctionGetYamlHdrSqs];
257
+ const createFunctionYaml = [...createFunctionYamlHdrApi, ...createFunctionYamlHdrDsq, ...createFunctionYamlHdrInv, ...createFunctionYamlHdrSqs];
255
258
 
256
259
  // generate Resource ..via dynamoDb sns-in-sqs sns-put
257
260
  const createResourceDynamo = createSourceDataDynamoDB(_izContext, objectSchema, saveFilePath);
@@ -286,10 +289,13 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
286
289
  const createOutUpdateComplete = [...createFunctionYamlOutUpdateNodeComplete, ...createOutUpdateCompleteHandler, ...createOutUpdateCompleteMainFunction, ...createOutUpdateCompleteSnsInSqs, ...createOutUpdateCompleteSnsOut]
287
290
 
288
291
  // create CreateNodeComplete
289
- const createFunctionYamlOutCreateNodeComplete = functionYamlOutCreateComplete(_izContext, saveFilePath);
290
-
292
+ const createFunctionYamlCreateObjectComplete = functionYamlOutCreateComplete(_izContext, saveFilePath);
293
+ const createSnsInSqsCreateObjectComplete = snsInSqsCreateObjectComplete(_izContext, saveFilePath)
294
+ const createSnsOutCreateObjectComplete = snsOutCreateObjectComplete(_izContext, saveFilePath);
295
+ const createHandlerCreateObjectComplete = createObjectCompleteHandler(_izContext, saveFilePath);
296
+ const createMainFunctionCreateObjectComplete = createObjectCompleteMainFunction(_izContext, saveFilePath)
291
297
 
292
- const createCreateNodeComplete = [...createFunctionYamlOutCreateNodeComplete]
298
+ const createCreateNodeComplete = [...createFunctionYamlCreateObjectComplete, ...createSnsInSqsCreateObjectComplete, ...createSnsOutCreateObjectComplete, ...createHandlerCreateObjectComplete, ...createMainFunctionCreateObjectComplete]
293
299
 
294
300
  // create default data resource such as findData ProcessLogical and awaitingMultipleStep
295
301
  const createResourceFindDataAndProcessLogical = createDefaultSourceDataDynamoDB(_izContext, saveFilePath);
@@ -411,7 +417,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
411
417
  createSnsSubscription,
412
418
  createFunctionIamRole,
413
419
  ...createOutUpdateComplete,
414
- // ...createCreateNodeComplete,
420
+ ...createCreateNodeComplete,
415
421
  ...findDataResource,
416
422
  ...processLogicalResource,
417
423
  ...processLogicalPaginateResource
@@ -31,7 +31,7 @@ function data(_izContext, srcPath) {
31
31
  }
32
32
 
33
33
  function createFunctionYamlOutUpdateComplete(_izContext, srcPath) {
34
- let functionName = upperCase(FUNCTION_NAME.createNodeComplete)
34
+ let functionName = upperCase(FUNCTION_NAME.createObjectComplete)
35
35
  let additionalResourcePermission = defaultIamRolePerAction();
36
36
  let awaitingTables = ["AwaitingMultipleSteps", "AwaitingMultipleStepByPending"]
37
37
  let handlerType = upperCase(HANDLER.hdrSqs)
@@ -0,0 +1,59 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+ function data(_izContext, srcPath) {
36
+ const createSourceParams = createParamForCreateSource(srcPath)
37
+ return [createSourceParams];
38
+ }
39
+
40
+ function createParamForCreateSource(srcPath) {
41
+ const functionName = FUNCTION_NAME.createObjectComplete;
42
+
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName: upperCase(functionName),
48
+ functionName
49
+ },
50
+ setting: {
51
+ savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
52
+ saveFileName: `${upperCase(functionName)}_${upperCase(HANDLER.hdrSqs)}`,
53
+ fileExtension: ".js",
54
+ isAppend: false
55
+ }
56
+ }
57
+ }
58
+
59
+ module.exports = data
@@ -0,0 +1,129 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ // const AWS = require('aws-sdk');
21
+ // const sqs = new AWS.SQS({ apiVersion: '2012-11-05' });
22
+
23
+ const izara = require("@izara_project/izara-middleware");
24
+ const middleware = izara.middlewareHandler;
25
+ const izaraShared = require('@izara_project/izara-shared');
26
+ const recordHandlerSharedLib = izaraShared.recordHandlerSharedLib
27
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
28
+
29
+ const <%- functionName %> = require('./<%- firstLetterUpperCase(functionName) %>_Main');
30
+ const Logger = require('@izara_project/izara-core-library-logger');
31
+ // validate event properties in body.Message of sqs event
32
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
33
+ // set schema for record.body.Message
34
+ let perRecordsValidatorSchema = {
35
+ type: "object",
36
+ required: [
37
+ 'returnValue',
38
+ 'status',
39
+ 'errorFounds'
40
+ ],
41
+ properties: {
42
+ returnValue: {
43
+ type: 'object',
44
+ },
45
+ status: {
46
+ type: 'string',
47
+ },
48
+ errorFounds: {
49
+ type: 'array',
50
+ default: []
51
+ }
52
+ }
53
+ };
54
+
55
+ // set schema for record.body.MessageAttributes
56
+ // const messageAttributeValidatorSchema = {
57
+ // type: "object",
58
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
59
+ // properties: {
60
+ // msgAtrrParam1: {
61
+ // type: "string"
62
+ // },
63
+ // msgAtrrParam2: {
64
+ // type: "object"
65
+ // }
66
+ // }
67
+ // };
68
+
69
+ perRecordsValidatorSchema = callingFlowSharedLib.addOptionalPassBackPropertiesToValidatorSchema(perRecordsValidatorSchema); // is Ok passBackProperties
70
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
71
+
72
+ try {
73
+
74
+ let recordPromises = [];
75
+
76
+ // loop each record and send to mainFunction
77
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
78
+
79
+ let passOnProperties = []
80
+ record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
81
+
82
+ //validate message (and MessageAttributes)
83
+ await recordHandlerSharedLib.validateRecord(
84
+ record, // one record will send to mainFunction
85
+ "<%- firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
86
+ perRecordsValidatorSchema, // schema for record.Message
87
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
88
+ );
89
+
90
+ // add argument (to invoke lambda) to passOnProperties[]
91
+ passOnProperties.push(record.body.Message.returnValue)
92
+ passOnProperties.push(record.body.Message.status)
93
+ passOnProperties.push(record.body.Message.errorFounds)
94
+ passOnProperties.push(callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(record.body.Message)) // is Ok PassBackProperties
95
+ // passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message)) // is Ok callinfFlow
96
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
97
+
98
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
99
+ let recordPromise = recordHandlerSharedLib.recordHandler(
100
+ record, // one record will send to mainFunction
101
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
102
+ "<%- firstLetterUpperCase(queueName) %>", // queue name that need to retry or send to dlq
103
+ passOnProperties, // all parameters that mainFunction needed.
104
+ );
105
+ record._izContext.logger.debug('after recordPromise in handler');
106
+ recordPromises.push(recordPromise); // push promise to recordPromises
107
+ }))
108
+
109
+ Logger.debug('before Promise.all(recordPromises) in handler');
110
+ try {
111
+ // --- main await all promises
112
+ await Promise.all(recordPromises); // await all promises
113
+
114
+ return event.Records // return all for local testing
115
+
116
+ } catch {
117
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
118
+ }
119
+ Logger.debug('after Promise.all(recordPromises) in handler');
120
+
121
+ } catch (err) {
122
+ Logger.error('Unhandled Error, updateNodeCompleteHdrSqs: ', err);
123
+ throw (err);
124
+ }
125
+ });
126
+
127
+ <%_ function firstLetterUpperCase(text){
128
+ return text.charAt(0).toUpperCase()+ text.slice(1)
129
+ } _%>
@@ -0,0 +1,53 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+ const path = require('path');
20
+ const fs = require('fs');
21
+
22
+ const { ACTIONS, HANDLER } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH, FUNCTION_NAME, SAVE_FILE_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ /**
30
+ * receive objectSchema
31
+ * create data for hdrInv template
32
+ *
33
+ * @return {{ templatePath, templateData, setting } }
34
+ */
35
+
36
+ function data(_izContext, srcPath) {
37
+ return [createMainFunctionCreateComplete(_izContext, srcPath)]
38
+ }
39
+
40
+ function createMainFunctionCreateComplete(_izContext, srcPath) {
41
+ return {
42
+ templatePath: templatePath,
43
+ templateData: {},
44
+ setting: {
45
+ savePath: path.join(srcPath, SOURCE_PATH.lambdaPerAction),
46
+ saveFileName: `${upperCase(FUNCTION_NAME.createObjectComplete)}_Main`,
47
+ fileExtension: ".js",
48
+ isAppend: false
49
+ }
50
+ }
51
+ }
52
+
53
+ module.exports = data
@@ -0,0 +1,172 @@
1
+ /*
2
+ Copyright (C) 2021 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ 'use strict';
18
+ const asyncFlowSharedLib = require('@izara_project/izara-shared/src/AsyncFlowSharedLib');
19
+ const dynamodbSharedLib = require('@izara_project/izara-shared/src/DynamodbSharedLib');
20
+ const snsSharedLib = require('@izara_project/izara-shared/src/SnsSharedLib');
21
+ const sns = require('@izara_project/izara-core-library-external-request/src/resources/Sns');
22
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib');
23
+ const _ = require('lodash');
24
+ const hash = require("object-hash")
25
+
26
+
27
+ const PREFIX = {
28
+ CREATE_OBJECT_ASYNC: "createObjectAsync",
29
+ CREATE_OBJECT_ASYNC_COMPLETE: "createObjectAsyncComplete"
30
+ }
31
+
32
+ /**
33
+ *
34
+ * @param {*} _izContext
35
+ * @param {*} returnValue
36
+ * @param {*} status
37
+ * @param {*} errorsFounds
38
+ * @param {*} graphServiceTag
39
+ * @param {*} passBackProperties
40
+ * @param {*} callingFlowConfig
41
+ returnValue = {
42
+ queryResult: returnCreateNode,
43
+ objType,
44
+ objInstance,
45
+ relationships,
46
+ settings
47
+ }
48
+ */
49
+ module.exports.createObjectComplete = async (
50
+ _izContext,
51
+ returnValue,
52
+ status,
53
+ errorsFound,
54
+ graphServiceTag,
55
+ passBackProperties,
56
+ callingFlowConfig
57
+ ) => {
58
+ try {
59
+ _izContext.logger.debug("function createObjectComplete:", {
60
+ returnValue,
61
+ status,
62
+ errorsFound,
63
+ graphServiceTag,
64
+ passBackProperties,
65
+ callingFlowConfig
66
+ });
67
+
68
+ let errorFounds = [];
69
+
70
+ if (_.isEmpty(returnValue)) {
71
+ _izContext.logger.debug("message callingFlowProperties is empty");
72
+ throw new NoRetryError("message not an object")
73
+ };
74
+ // validate.
75
+ if (!returnValue.hasOwnProperty("queryResult")) {
76
+ errorFounds.push("message is not have property queryResult, should be not happen");
77
+ };
78
+ if (!returnValue.hasOwnProperty("objType")) {
79
+ errorFounds.push("message is not have property objType, should be not happen");
80
+ };
81
+ if (!returnValue.hasOwnProperty("objInstance")) {
82
+ errorFounds.push("message is not have property objInstance, should be not objInstance");
83
+ };
84
+
85
+ if (status == "error" && errorsFound.length > 0) {
86
+ errorFounds.push(errorsFound);
87
+ } else if (status == "error" && errorsFound.length == 0) {
88
+ errorFounds.push("[invalid]statur is error not have errorfound form graphService");
89
+
90
+ };
91
+ if (status === "complete" && errorsFound.length > 0) {
92
+ errorFounds.push("[Invalid] status is commplete should be not have errorsFound");
93
+ };
94
+ if (graphServiceTag == "") {
95
+ errorFounds.push("[Invalid] graphServiceTag is not empty string");
96
+ };
97
+
98
+ if (errorsFound.length > 0) {
99
+ _izContext.logger.debug("Have error form grapService:", errorsFound);
100
+ errorFounds = errorFounds.concat(errorsFound);
101
+ };
102
+
103
+ // check and remove awaitngStep finish.
104
+ let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId((hash(
105
+ {
106
+ objType: returnValue.objType,
107
+ graphServerTag: graphServiceTag,
108
+ identifiers: returnValue.objInstance.identifiers
109
+ }
110
+ )),
111
+ PREFIX.CREATE_OBJECT_ASYNC
112
+ )
113
+ _izContext.logger.debug("awaitingStepId:", awaitingStepId);
114
+
115
+ let recordAwaitingSteps = await dynamodbSharedLib.query(
116
+ _izContext,
117
+ await dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
118
+ {
119
+ awaitingStepId: awaitingStepId
120
+ }
121
+ );
122
+ _izContext.logger.debug("record awaitingSteps::", recordAwaitingSteps);
123
+
124
+ nextAwaitingAteps:
125
+ for (let listRecordAwaitingStep of recordAwaitingSteps.Items) {
126
+
127
+ _izContext.logger.debug("iterate RecordAwaitingStep:", listRecordAwaitingStep);
128
+
129
+
130
+ if (!await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
131
+ _izContext,
132
+ listRecordAwaitingStep.pendingStepId,
133
+ awaitingStepId
134
+ )) {
135
+ _izContext.logger.debug("!Waiting record form other graph::")
136
+ // **** add step of remove awaitingMultiplestep!! ??
137
+ continue nextAwaitingAteps
138
+ };
139
+
140
+ await asyncFlowSharedLib.removeAwaitingMultipleStep(
141
+ _izContext,
142
+ awaitingStepId,
143
+ listRecordAwaitingStep.pendingStepId,
144
+ );
145
+ _izContext.logger.debug("Remove awaitingStep finish")
146
+ };
147
+
148
+ // seagame: problem about lambdaComplete is will missing errorsFound from request if have 2 request
149
+ // one send with errorsFound and one send without errorsFound
150
+ // this scenario can complete with or without errorsFound
151
+ let messageObject = {
152
+ objType: returnValue.objType,
153
+ identifierId: returnValue.objInstance.identifiers,
154
+ errorFounds: errorFounds
155
+ };
156
+
157
+ messageObject = callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(passBackProperties, messageObject)
158
+ let messageAttributes = callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(passBackProperties, {})
159
+
160
+ let sendMessageOutCreateObjectComplete = {
161
+ Message: JSON.stringify(messageObject),
162
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
163
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, "OutCreateObjectComplete")
164
+ };
165
+ _izContext.logger.debug("Send message to OutCreateObjectComplete :::>", sendMessageOutCreateObjectComplete)
166
+ await sns.publishAsync(_izContext, sendMessageOutCreateObjectComplete);
167
+
168
+
169
+ } catch (err) {
170
+ throw (err)
171
+ }
172
+ }
@@ -0,0 +1,58 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ 'use strict';
19
+
20
+ const path = require("path")
21
+ const templatePath = path.join(__dirname, './template.ejs');
22
+ const { SOURCE_PATH, FUNCTION_NAME, SAVE_FILE_NAME } = require('../../../libs/Consts');
23
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
24
+
25
+ /**
26
+ * create data for dynamoDbYaml tempalte from objectSchema
27
+ * return array of dynamoDb data
28
+ * because one objectSchema can create multiple dynamoDb table
29
+ *
30
+ * @param {Object} _izContext
31
+ * @param {String} saveFilePath
32
+ * @returns {Object[]} - data of multiple dynamoDb template
33
+ */
34
+
35
+ function data(_izContext, srcPath) {
36
+ let createUpdateNodeCompleteQueues = [];
37
+ const createCreateUpdatenodeCompleteQueueNames = [
38
+ {
39
+ queueName: upperCase(FUNCTION_NAME.createObjectComplete)
40
+ }
41
+ ]
42
+ for (let createUpdateNodeCompleteQueueName of createCreateUpdatenodeCompleteQueueNames) {
43
+ createUpdateNodeCompleteQueues.push({
44
+ templatePath: templatePath,
45
+ templateData: createUpdateNodeCompleteQueueName,
46
+ setting: {
47
+ initialData: "Resource\n",
48
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
49
+ saveFileName: SAVE_FILE_NAME.snsInSqsYaml,
50
+ fileExtension: ".yml",
51
+ isAppend: true
52
+ }
53
+ })
54
+ }
55
+ return createUpdateNodeCompleteQueues
56
+ }
57
+
58
+ module.exports = data
@@ -0,0 +1,47 @@
1
+ ##===== [Queue]
2
+ <%- queueName %>:
3
+ Type: "AWS::SQS::Queue"
4
+ Properties:
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
+ RedrivePolicy:
7
+ deadLetterTargetArn:
8
+ # !GetAtt
9
+ Fn::GetAtt:
10
+ - <%- queueName %>DLQ
11
+ - Arn
12
+ maxReceiveCount: 3
13
+ VisibilityTimeout: 120
14
+ ##==== [QueueDLQ]
15
+ <%- queueName %>DLQ:
16
+ Type: AWS::SQS::Queue
17
+ Properties:
18
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
19
+ ##==== [QueuePolicy]
20
+ <%- queueName %>Policy:
21
+ Type: AWS::SQS::QueuePolicy
22
+ Properties:
23
+ PolicyDocument:
24
+ Version: "2012-10-17"
25
+ Statement:
26
+ - Sid: "allow-sns-messages"
27
+ Effect: Allow
28
+ Principal: "*"
29
+ Resource:
30
+ # !GetAtt
31
+ Fn::GetAtt:
32
+ - <%- queueName %>
33
+ - Arn
34
+ Action: "SQS:SendMessage"
35
+ Queues:
36
+ - Ref: <%- queueName %>
37
+ #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
38
+ #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
39
+
40
+
41
+ <%_ function firstLetterUpperCase(text){
42
+ return text.charAt(0).toUpperCase() + text.slice(1)
43
+ } _%>
44
+ <%_ function firstLetterLowerCase(str) {
45
+ return str.charAt(0).toLowerCase() + str.slice(1)
46
+ } _%>
47
+