@izara_project/izara-market-library-service-schemas 1.0.14 → 1.0.16

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 (67) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +3 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +122 -98
  4. package/src/MainLibs/src/Utils.js +10 -9
  5. package/src/TemplateManager/src/FindData/GetByStorage/getByGraph.ejs +2 -1
  6. package/src/TemplateManager/src/GenerateCode.js +55 -12
  7. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +86 -0
  8. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +33 -0
  9. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/data.js +59 -0
  10. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/handler/template.ejs +129 -0
  11. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/data.js +53 -0
  12. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/mainFunction/template.ejs +130 -0
  13. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sns-out/data.js +62 -0
  14. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/data.js +58 -0
  15. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/sqs-in-sns/template.ejs +47 -0
  16. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +15 -7
  17. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +14 -6
  18. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +14 -4
  19. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +14 -4
  20. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +171 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/request.json +19 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/template.ejs +29 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/data.js +60 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/webSocketConnect/template.ejs +10 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/template.ejs +15 -12
  26. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/template.ejs +14 -13
  27. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/data.js +76 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocket/template.ejs +141 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/data.js +56 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/Handler/WebSocketConnect/template.ejs +55 -0
  31. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +40 -36
  32. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Delete/template.ejs +0 -1
  33. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +54 -22
  34. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Update/template.ejs +23 -27
  35. package/src/TemplateManager/src/ProcessLogical/mainFunction/template.ejs +2 -2
  36. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  37. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrApi/template.ejs +2 -1
  38. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrDsq/template.ejs +1 -5
  39. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/perAction/HdrSqs/template.ejs +1 -5
  40. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/mainFunction/template.ejs +11 -7
  41. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  42. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrApi/template.ejs +5 -4
  43. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/perAction/HdrInv/template.ejs +3 -2
  44. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/mainFunction/template.ejs +16 -13
  45. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +9 -6
  46. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +4 -0
  47. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +8 -5
  48. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +1 -1
  49. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +10 -8
  50. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +1 -1
  51. package/src/TemplateManager/src/ResourceYaml/dynamodb/{awaitingMultipleStepData.js → defaultDynamoDbTable.js} +39 -3
  52. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +6 -3
  53. package/src/TemplateManager/src/externalService/FunctionNameConfig/data.js +1 -1
  54. package/src/TemplateManager/src/externalService/LambdaRole/data.js +5 -10
  55. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +14 -0
  56. package/src/TemplateManager/src/flowTag/resources/dynamoDb/data.js +65 -0
  57. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/data.js +56 -0
  58. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/functionYaml/template.ejs +10 -0
  59. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/data.js +55 -0
  60. package/src/TemplateManager/src/flowTag/webSocket/webSocketConnect/handler/template.ejs +63 -0
  61. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/data.js +75 -0
  62. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/functionYaml/template.ejs +33 -0
  63. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/data.js +57 -0
  64. package/src/TemplateManager/src/flowTag/webSocket/websocketHandler/lambda/template.ejs +131 -0
  65. package/src/TemplateManager/src/libs/Consts.js +7 -2
  66. package/src/TemplateManager/src/libs/GenerateCodeUtils.js +3 -1
  67. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +0 -99
@@ -0,0 +1,86 @@
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, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
+ const { getGraphServiceNameFromGraphServerTagWithCache, getServiceNameWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
24
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../../MainLibs/src/Utils")
25
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, getGraphServiceNameFromAllRelSchema, FUNCTION_NAME, SAVE_FILE_NAME, getGraphServiceNameFromObjectSchema, defaultIamRolePerAction, SQS_RESOURCE, SNS_RESOURCE, DYNAMO_RESOURCE, awaitingMultipleStepsRole, SHORT_FUNCTION_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, './template.ejs');
28
+
29
+ function data(_izContext, srcPath) {
30
+ return [createFunctionYamlOutUpdateComplete(_izContext, srcPath)]
31
+ }
32
+
33
+ function createFunctionYamlOutUpdateComplete(_izContext, srcPath) {
34
+ let functionName = upperCase(FUNCTION_NAME.getNodeComplete)
35
+ let functionNameConfig = upperCase(SHORT_FUNCTION_NAME.getNodeComplete)
36
+ let additionalResourcePermission = defaultIamRolePerAction();
37
+ let handlerType = upperCase(HANDLER.hdrSqs)
38
+
39
+ additionalResourcePermission.push(
40
+ createIamRole(
41
+ {
42
+ [RESOURCE_CLASSES.sqs]: [
43
+ SQS_RESOURCE.deleteMessage,
44
+ SQS_RESOURCE.deleteMessageBatch,
45
+ SQS_RESOURCE.getQueueAttributes,
46
+ SQS_RESOURCE.getQueueUrl,
47
+ SQS_RESOURCE.receiveMessage,
48
+ SQS_RESOURCE.sendMessage
49
+ ],
50
+ [RESOURCE_CLASSES.sns]: [
51
+ SNS_RESOURCE.publish,
52
+ SNS_RESOURCE.subscription
53
+ ]
54
+ },
55
+ [
56
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName)),
57
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + "DLQ"),
58
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName)),
59
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName)),
60
+ ]
61
+ )
62
+ )
63
+
64
+ additionalResourcePermission.push(awaitingMultipleStepsRole())
65
+
66
+
67
+ return {
68
+ templatePath: templatePath,
69
+ templateData: {
70
+ functionName,
71
+ handlerType,
72
+ additionalResourcePermission,
73
+ resourceLocation: SOURCE_PATH.resourceLocationOutPerActionComplete,
74
+ functionNameConfig
75
+ },
76
+ setting: {
77
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
78
+ saveFileName: SAVE_FILE_NAME.functionPerActionYaml,
79
+ fileExtension: '.yml',
80
+ isAppend: true
81
+ }
82
+
83
+ }
84
+ }
85
+
86
+ module.exports = data
@@ -0,0 +1,33 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
5
+ events:
6
+ - sqs:
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
8
+ batchSize: 10
9
+ filterPatterns: #**** need to update serverless framwork upper v.2.69.1
10
+ - body: {"MessageAttributes":{"callingFlow":{"Value":["${self:custom.iz_resourcePrefix}<%-firstLetterUpperCase(functionName) %>"]}}} # functionName of callingFlow
11
+ - body: {"MessageAttributes":{"callingFlow":{"Value":[{"exists":false}]}}}
12
+ iamRoleStatements:
13
+ <%_ additionalResourcePermission.forEach(resourcePermission => { _%>
14
+ - Effect: <%- resourcePermission.effect %>
15
+ Action:
16
+ <%_ Object.keys(resourcePermission.action).forEach(resourcePerAction => { _%>
17
+ <%_ resourcePermission.action[resourcePerAction].forEach(permission => { _%>
18
+ - <%- resourcePerAction %>:<%- permission %>
19
+ <%_}) _%>
20
+ <%_ }) _%>
21
+ Resource:
22
+ <%_ resourcePermission.resource.forEach(resource => { _%>
23
+ - <%- resource %>
24
+ <%_ }) _%>
25
+ <%_}) _%>
26
+ #<#<%- functionName %><%- handlerType %>IamRole#>
27
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
28
+ <%_ function firstLetterUpperCase(text){
29
+ return text.charAt(0).toUpperCase() + text.slice(1)
30
+ } _%>
31
+ <%_ function firstLetterLowerCase(str) {
32
+ return str.charAt(0).toLowerCase() + str.slice(1)
33
+ } _%>
@@ -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.getNodeComplete;
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.outPerActionComplete),
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 [createMainFunctionUpdateComplete(_izContext, srcPath)]
38
+ }
39
+
40
+ function createMainFunctionUpdateComplete(_izContext, srcPath) {
41
+ return {
42
+ templatePath: templatePath,
43
+ templateData: {},
44
+ setting: {
45
+ savePath: path.join(srcPath, SOURCE_PATH.outPerActionComplete),
46
+ saveFileName: `${upperCase(FUNCTION_NAME.getNodeComplete)}_Main`,
47
+ fileExtension: ".js",
48
+ isAppend: false
49
+ }
50
+ }
51
+ }
52
+
53
+ module.exports = data
@@ -0,0 +1,130 @@
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 hash = require("object-hash");
20
+
21
+ const izaraShared = require('@izara_project/izara-shared');
22
+ const callingFlowSharedLib = izaraShared.callingFlowSharedLib;
23
+ const configSharedLib = izaraShared.configSharedLib;
24
+ const snsSharedLib = izaraShared.snsSharedLib;
25
+ const asyncFlowSharedLib = izaraShared.asyncFlowSharedLib;
26
+ const dynamodbSharedLib = izaraShared.dynamodbSharedLib;
27
+
28
+ const sns = require("@izara_project/izara-core-library-external-request").sns;
29
+ const NoRetryError = require("@izara_project/izara-core-library-core/src/NoRetryError");
30
+
31
+ const { explodedObjectTypeId, explodedRelationshipTypeId, createLinkTypeId } = require('@izara_project/izara-core-library-service-schemas/src/Utils');
32
+
33
+ const {
34
+ TOPIC_NAME_GENERATE_CODE,
35
+ TOPIC_NAME_GRAPH_HANDLER,
36
+ PREFIX
37
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
38
+
39
+ module.exports.updateNodeComplete = async (
40
+ _izContext,
41
+ returnValue,
42
+ status,
43
+ errorsFound,
44
+ passBackProperties = {}
45
+ ) => {
46
+ try {
47
+ _izContext.logger.debug("Function:updateNodeComplete", {
48
+ _izContext: _izContext,
49
+ returnValue: returnValue,
50
+ status: status,
51
+ errorsFound: errorsFound,
52
+ passBackProperties: passBackProperties
53
+ });
54
+
55
+ // start create AwaitingStepId
56
+ let awaitingStepId = asyncFlowSharedLib.createAwaitingStepId(
57
+ hash({
58
+ objectType: returnValue.objType.objectType,
59
+ serviceTag: returnValue.objType.serviceTag,
60
+ identifiers: returnValue.objInstanceFull.identifiers,
61
+ fields: returnValue.objInstanceFull.fields
62
+ }),
63
+ PREFIX.updateNode
64
+ )
65
+
66
+ let updateNodePendingObjects = await dynamodbSharedLib.query(
67
+ _izContext,
68
+ await dynamodbSharedLib.tableName(_izContext, "AwaitingMultipleSteps"),
69
+ {
70
+ awaitingStepId: awaitingStepId
71
+ }
72
+ );
73
+ _izContext.logger.debug("updateNodePendingObjects", updateNodePendingObjects);
74
+
75
+ await Promise.all(
76
+ updateNodePendingObjects.Items.map(async ({ pendingStepId }) => {
77
+ if (await asyncFlowSharedLib.checkAllAwaitingStepsFinished(
78
+ _izContext,
79
+ pendingStepId,
80
+ awaitingStepId
81
+ )) {
82
+ _izContext.logger.debug("finished all awaitingStep");
83
+
84
+ let updateCompleteMsg = {
85
+ objType: {
86
+ objectType: returnValue.objType.objectType,
87
+ serviceTag: returnValue.objType.serviceTag
88
+ },
89
+ objInstance: {
90
+ identifiers: returnValue.objInstanceFull.identifiers,
91
+ fields: returnValue.objInstanceFull.fields
92
+ },
93
+ status: status,
94
+ errorsFound: errorsFound
95
+ };
96
+
97
+ updateCompleteMsg = callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(passBackProperties, updateCompleteMsg);
98
+ _izContext.logger.debug("after addCallingFlow to SnsResponseMessageObject", updateCompleteMsg);
99
+
100
+ let messageAttributes = callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(passBackProperties, {});
101
+ _izContext.logger.debug("after addCallingFlow to SnsResponseMessageAttributes", updateCompleteMsg);
102
+
103
+ let sendMessageToOutUpdateNodeComplete = {
104
+ Message: JSON.stringify(updateCompleteMsg),
105
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, messageAttributes),
106
+ TopicArn: await snsSharedLib.snsTopicArn(_izContext, TOPIC_NAME_GENERATE_CODE.outUpdateNodeComplete)
107
+ };
108
+ _izContext.logger.debug("Send Message to OutUpdateNodeComplete::", sendMessageToOutUpdateNodeComplete);
109
+ await sns.publishAsync(_izContext, sendMessageToOutUpdateNodeComplete)
110
+
111
+ await asyncFlowSharedLib.removeAwaitingMultipleStep(
112
+ _izContext,
113
+ awaitingStepId,
114
+ pendingStepId
115
+ );
116
+ }
117
+ })
118
+ )
119
+
120
+ return {
121
+ objType: returnValue.objType,
122
+ objInstanceFull: returnValue.objInstanceFull,
123
+ errorsFound: errorsFound
124
+ }
125
+
126
+ } catch (err) {
127
+ _izContext.logger.error("error UpdateNodeComplete : ", err)
128
+ throw (err)
129
+ }
130
+ }
@@ -0,0 +1,62 @@
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, SAVE_FILE_NAME, FUNCTION_NAME } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "../../../ResourceYaml/sns-out/template.ejs")
28
+ // /ResourceYaml/sns-out/template.ejs
29
+ // /OutPerActionComplete/OutUpdateComplete/sns-out/data.js
30
+ /**
31
+ * create data for dynamoDbYaml tempalte from objectSchema
32
+ * return array of dynamoDb data
33
+ * because one objectSchema can create multiple dynamoDb table
34
+ *
35
+ * @param {Object} _izContext
36
+ * @param {String} saveFilePath
37
+ * @returns {Object[]} - data of multiple dynamoDb template
38
+ */
39
+
40
+ function data(_izContext, srcPath) {
41
+ const createSourceParams = createParamsForCreateSource(_izContext, srcPath)
42
+ return [createSourceParams]
43
+ }
44
+
45
+ function createParamsForCreateSource(_izContext, srcPath) {
46
+ let queueName = FUNCTION_NAME.getNodeComplete
47
+ return {
48
+ templatePath: templatePath,
49
+ templateData: {
50
+ queueName: upperCase(queueName)
51
+ },
52
+ setting: {
53
+ initialData: 'Resources:\n',
54
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
55
+ saveFileName: SAVE_FILE_NAME.snsOutYaml,
56
+ fileExtension: '.yml',
57
+ isAppend: true
58
+ }
59
+ }
60
+ }
61
+
62
+ module.exports = data
@@ -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 createGetNodeCompleteQueues = [
38
+ {
39
+ queueName: upperCase(FUNCTION_NAME.getNodeComplete)
40
+ }
41
+ ]
42
+ for (let getNodeCompleteQueue of createGetNodeCompleteQueues) {
43
+ createUpdateNodeCompleteQueues.push({
44
+ templatePath: templatePath,
45
+ templateData: getNodeCompleteQueue,
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
+