@izara_project/izara-market-library-service-schemas 1.0.3 → 1.0.4

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 (75) hide show
  1. package/package.json +5 -5
  2. package/src/GenerateCodeLibs/src/Consts.js +40 -0
  3. package/src/TemplateManager/src/FunctionYaml/HdrApi/data.js +4 -4
  4. package/src/TemplateManager/src/FunctionYaml/HdrDsq/data.js +7 -5
  5. package/src/TemplateManager/src/FunctionYaml/HdrInv/data.js +3 -3
  6. package/src/TemplateManager/src/FunctionYaml/HdrSqs/data.js +11 -13
  7. package/src/TemplateManager/src/FunctionYaml/HdrSqs/template.ejs +1 -1
  8. package/src/TemplateManager/src/GenerateCode.js +117 -29
  9. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrDsq/data.js +1 -1
  10. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrInv/data.js +1 -1
  11. package/src/TemplateManager/src/PerActionEndpoint/Handler/HdrSqs/data.js +1 -1
  12. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/data.js +1 -1
  13. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Get/template.ejs +1 -1
  14. package/src/TemplateManager/src/ResourceYaml/dynamodb/awaitingMultipleStepData.js +98 -0
  15. package/src/TemplateManager/src/ResourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +7 -7
  16. package/src/TemplateManager/src/ResourceYaml/dynamodb/processLogicalAndFindData.js +4 -3
  17. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/defaultSnsInSqsForFindDataAndProcessLogical.js +4 -4
  18. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/snsAndSqsPerActiondata.js +4 -4
  19. package/src/TemplateManager/src/ResourceYaml/sns-in-sqs/sqsTemplate.ejs +1 -0
  20. package/src/TemplateManager/src/ResourceYaml/sns-out/data.js +89 -0
  21. package/src/TemplateManager/src/ResourceYaml/sns-out/request.json +3 -0
  22. package/src/TemplateManager/src/ResourceYaml/sns-out/template.ejs +10 -0
  23. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +151 -0
  24. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/request.json +3 -0
  25. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +33 -0
  26. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/data.js +76 -0
  27. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/request.json +0 -0
  28. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/handler/HdrSqs/template.ejs +127 -0
  29. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/data.js +55 -0
  30. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/request.json +1 -0
  31. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/mainFunction/template.ejs +140 -0
  32. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/data.js +75 -0
  33. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/request.json +3 -0
  34. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-in-sqs/template.ejs +45 -0
  35. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/data.js +70 -0
  36. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRalationshipComplete/sns-out/request.json +3 -0
  37. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +127 -0
  38. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/request.json +0 -0
  39. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +33 -0
  40. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +148 -0
  41. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/request.json +0 -0
  42. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +125 -0
  43. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/request.json +0 -0
  44. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +148 -0
  45. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/request.json +0 -0
  46. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/data.js +80 -0
  47. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/request.json +1 -0
  48. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/mainFunction/template.ejs +324 -0
  49. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/data.js +72 -0
  50. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/request.json +7 -0
  51. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrApi/template.ejs +120 -0
  52. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/data.js +73 -0
  53. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/request.json +7 -0
  54. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrDsq/template.ejs +167 -0
  55. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/data.js +73 -0
  56. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/request.json +5 -0
  57. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrInv/template.ejs +126 -0
  58. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/data.js +73 -0
  59. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/request.json +7 -0
  60. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/HdrSqs/template.ejs +146 -0
  61. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/perAction/request.json +31 -0
  62. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/data.js +91 -0
  63. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-in-sqs/request.json +3 -0
  64. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/data.js +70 -0
  65. package/src/TemplateManager/src/UpdateRelationshipSchema/updateRelationship/sns-out/request.json +3 -0
  66. package/src/TemplateManager/src/externalService/LambdaRole/data.js +56 -10
  67. package/src/TemplateManager/src/externalService/LambdaRole/template.ejs +6 -2
  68. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/data.js +67 -2
  69. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/request.json +12 -0
  70. package/src/TemplateManager/src/externalService/SnsTopicSubscriotions/template.ejs +10 -14
  71. package/src/TemplateManager/src/libs/Consts.js +16 -25
  72. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +0 -76
  73. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +0 -155
  74. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +0 -31
  75. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +0 -12
@@ -0,0 +1,73 @@
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 } = 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
+
41
+ function createParamForCreateSource(srcPath) {
42
+ let functionName = "updateRelationship";
43
+ return {
44
+ templatePath: templatePath,
45
+ templateData: {
46
+ functionName,
47
+ queueName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrSqs)
48
+ },
49
+ setting: {
50
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
51
+ saveFileName: upperCase(functionName) + "_" + upperCase(HANDLER.hdrSqs),
52
+ fileExtension: '.js',
53
+ isAppend: false
54
+ }
55
+ }
56
+ }
57
+
58
+
59
+ // [
60
+ // {
61
+ // templatePath: '/home/toughnut/BasProgram/empty-service-template/app/node_modules/@izara_project/izara-market-library-service-schemas/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs',
62
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
63
+ // setting: {
64
+ // savePath: '/generatedCode/source/',
65
+ // saveFileName: 'ObjectTypeGet',
66
+ // fileExtension: '.js',
67
+ // isAppend: false
68
+ // }
69
+ // }
70
+ // ]
71
+
72
+
73
+ module.exports = data;
@@ -0,0 +1,7 @@
1
+ {
2
+ "objectType": "objectType",
3
+ "action": "get",
4
+ "mainFunction": "xxx",
5
+ "mainFunctionFile": "directoryOfMainFunction",
6
+ "isCreateMainByDev": "boolean"
7
+ }
@@ -0,0 +1,146 @@
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 izara = require("@izara_project/izara-middleware");
20
+ const middleware = izara.middlewareHandler;
21
+ const callingFlowSharedLib = require('@izara_project/izara-shared/src/CallingFlowSharedLib')
22
+ const {
23
+ validateSchemaMiddleware
24
+ } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/GenerateCodeLibs');
25
+ const Logger = require('@izara_project/izara-core-library-logger');
26
+ const recordHandlerSharedLib = require('@izara_project/izara-shared').recordHandlerSharedLib
27
+
28
+ const updateRelationship = require('./UpdateRelationship_Main');
29
+
30
+ middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
31
+
32
+ // validate event params in middleware before into function
33
+ let validatorSchema = {
34
+ type: "object",
35
+ required: ["objects", "relId", "relType", "relationshipProperties"],
36
+ properties: {
37
+ objects: {
38
+ type: "array",
39
+ minItems: 2,
40
+ maxItems: 2,
41
+ items: {
42
+ type: 'object',
43
+ required: ["objType", "identifiers"],
44
+ properties: {
45
+ objType: {
46
+ type: "object",
47
+ required: ["serviceTag", "objectType"],
48
+ properties: {
49
+ serviceTag: izara.validatorSchema.stringNotEmpty(),
50
+ objectType: izara.validatorSchema.stringNotEmpty()
51
+ }
52
+ },
53
+ identifiers: {
54
+ type: "object",
55
+ minProperties: 1
56
+ }
57
+ }
58
+ }
59
+ },
60
+ relType: {
61
+ type: "object",
62
+ required: ["relationshipTag", "serviceTag"],
63
+ properties: {
64
+ relationshipTag: izara.validatorSchema.stringNotEmpty(),
65
+ serviceTag: {
66
+ type: 'string',
67
+ pattern: "^[a-zA-Z0-9_-]+$",
68
+ enum: [process.env.iz_serviceTag]
69
+ },
70
+ }
71
+ },
72
+ relId: izara.validatorSchema.stringNotEmpty(),
73
+ relationshipProperties: {
74
+ type: 'object',
75
+ minProperties: 1,
76
+ },
77
+ }
78
+ };
79
+
80
+ //(<globalVarible>
81
+ //</globalVarible>)
82
+
83
+ // validate event params in middleware before into main function
84
+ validatorSchema = callingFlowSharedLib.addOptionalCallingFlowToValidatorSchema(validatorSchema);
85
+ // if need to validate authorizer or additional params , add code to hook tag below
86
+
87
+ //(<afterValidateWith>)
88
+ //(</afterValidateWith>)
89
+
90
+ module.exports.main = middleware.wrap(async (event, context, callback) => {
91
+
92
+ try {
93
+
94
+ let recordPromises = []; // final return
95
+
96
+ // loop each record and send to mainFunction
97
+ await Promise.all(event.Records.map(async record => { // promise.all for map() function
98
+
99
+ let passOnProperties = []
100
+
101
+ // --- validate message (and MessageAttributes)
102
+ await recordHandlerSharedLib.validateRecord(
103
+ record, // one record will send to mainFunction
104
+ "<%- queueName %>", // queue name that need to retry or send to dlq
105
+ validatorSchema, // schema for record.Message
106
+ // messageAttributeValidatorSchema // ----- for msgAttr default is null -> do not send this parameter if not want to validate msgAtt
107
+ );
108
+
109
+ // add argument (to invoke lambda) to passOnProperties[]
110
+ passOnProperties.push(record.body.Message)
111
+ passOnProperties.push(callingFlowSharedLib.addCallingFlowToPassOnProperties(record.body.Message));
112
+ //(<afterPutParamIntoMainFunction>)
113
+ //(</afterPutParamIntoMainFunction>)
114
+
115
+ record._izContext.logger.debug('passOnProperties in handler', passOnProperties);
116
+
117
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
118
+ let recordPromise = recordHandlerSharedLib.recordHandler(
119
+ record, // one record will send to mainFunction
120
+ <%- functionName %>.<%- functionName %>, // mainFunction that need to invoke.
121
+ "<%- queueName %>", // queue name that need to retry or send to dlq
122
+ passOnProperties, // all parameters that mainFunction needed.
123
+ );
124
+ record._izContext.logger.debug('after recordPromise in handler');
125
+ recordPromises.push(recordPromise); // push promise to recordPromises
126
+ })) //end record
127
+
128
+ Logger.debug('before Promise.all(recordPromises) in handler');
129
+ try {
130
+ await Promise.all(recordPromises); // await all promises
131
+ return event.Records // return all for local test
132
+ } catch {
133
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
134
+ }
135
+ Logger.debug('after Promise.all(recordPromises) in handler');
136
+ } catch (err) {
137
+ Logger.error('Unhandled Error, updateRelationshipHdrDsq:', err);
138
+ throw (err);
139
+ }
140
+ });
141
+ <%_ function firstLetterUpperCase(text) {
142
+ return text.charAt(0).toUpperCase() + text.slice(1)
143
+ } _%>
144
+ <%_ function firstLetterLowerCase(str) {
145
+ return str.charAt(0).toLowerCase() + str.slice(1)
146
+ } _%>
@@ -0,0 +1,31 @@
1
+ {
2
+ "objects": [
3
+ {
4
+ "objType": {
5
+ "objectType": "Sunny",
6
+ "serviceTag": "GenerateCodeTemplateBas"
7
+ },
8
+ "identifiers": {
9
+ "personId": "Node1"
10
+ }
11
+ },
12
+ {
13
+ "objType": {
14
+ "objectType": "Weather",
15
+ "serviceTag": "GenerateCodeTemplateBas"
16
+ },
17
+ "identifiers": {
18
+ "personId": "Node2"
19
+ }
20
+ }
21
+ ],
22
+ "relType": {
23
+ "relationshipTag": "RelTag",
24
+ "serviceTag": "GenerateCodeTemplateBas"
25
+ },
26
+ "relId": "aa-bb-cc",
27
+ "relationshipProperties": {
28
+ "name": "bas007"
29
+ },
30
+ "callingFlow": "basCallingFlow"
31
+ }
@@ -0,0 +1,91 @@
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
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
35
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
36
+ const snsTemplatePath = path.join(__dirname, "../../../ResourceYaml/sns-in-sqs/snsTemplate.ejs")
37
+ const sqsTemplatePath = path.join(__dirname, "../../../ResourceYaml/sns-in-sqs/sqsTemplate.ejs")
38
+
39
+ /**
40
+ * create data for dynamoDbYaml tempalte from objectSchema
41
+ * return array of dynamoDb data
42
+ * because one objectSchema can create multiple dynamoDb table
43
+ *
44
+ * @param {Object} _izContext
45
+ * @param {String} saveFilePath
46
+ * @returns {Object[]} - data of multiple dynamoDb template
47
+ */
48
+
49
+ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
50
+ let resultsForCreateDefaultSnsInSqs = [];
51
+ const defaultSnsInSqsDataList = [
52
+ {
53
+ "queueName": "UpdateRelationship"
54
+ },
55
+ {
56
+ "queueName": "UpdateRelationshipHdrDsq"
57
+ }
58
+ ]
59
+
60
+ for (let defaultSnsInSqsData of defaultSnsInSqsDataList) {
61
+ if (defaultSnsInSqsData.queueName.includes("HdrDsq")) {
62
+ resultsForCreateDefaultSnsInSqs.push({
63
+ templatePath: sqsTemplatePath,
64
+ templateData: defaultSnsInSqsData,
65
+ setting: {
66
+ initialData: "Resources:\n",
67
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
68
+ saveFileName: 'generated-sns-in-sqs',
69
+ fileExtension: '.yml',
70
+ isAppend: true
71
+ }
72
+ })
73
+ } else {
74
+ resultsForCreateDefaultSnsInSqs.push({
75
+ templatePath: snsTemplatePath,
76
+ templateData: defaultSnsInSqsData,
77
+ setting: {
78
+ initialData: "Resources:\n",
79
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
80
+ saveFileName: "generated-sns-in-sqs",
81
+ fileExtension: ".yml",
82
+ isAppend: true
83
+ }
84
+ })
85
+ }
86
+ }
87
+ // console.log("resultsForCreateDefaultSnsInSqs", resultsForCreateDefaultSnsInSqs);
88
+ return resultsForCreateDefaultSnsInSqs;
89
+ }
90
+
91
+ module.exports = createDataForDefaultSnsInSqs;
@@ -0,0 +1,70 @@
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
+
22
+
23
+ // const {
24
+ // HANDLER,
25
+ // STORAGE_TYPES
26
+ // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
+
28
+
29
+ const STORAGE_TYPES = {
30
+ dynamoDB: "dynamoDB",
31
+ graph: "graph"
32
+ }
33
+
34
+ const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase, firstLetterUpperCase } = require("../../../../../MainLibs/src/Utils")
35
+ const { DEFAULT_HANDLER_PER_ACTION, SOURCE_PATH } = require("../../../libs/Consts");
36
+ const templatePath = path.join(__dirname, '../../../ResourceYaml/sns-out/template.ejs')
37
+
38
+ /**
39
+ * create data for dynamoDbYaml tempalte from objectSchema
40
+ * return array of dynamoDb data
41
+ * because one objectSchema can create multiple dynamoDb table
42
+ *
43
+ * @param {Object} _izContext
44
+ * @param {String} saveFilePath
45
+ * @returns {Object[]} - data of multiple dynamoDb template
46
+ */
47
+
48
+ function createDefaultSnsOut(_izContext, srcPath) {
49
+ const createSourceParams = createParamsForCreateSource(_izContext, srcPath)
50
+ return [createSourceParams]
51
+ }
52
+
53
+ function createParamsForCreateSource(_izContext, srcPath) {
54
+ let queueName = "updateRelationshipSchema"
55
+ return {
56
+ templatePath: templatePath,
57
+ templateData: {
58
+ queueName
59
+ },
60
+ setting: {
61
+ initialData: 'Resources:\n',
62
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
63
+ saveFileName: "generated-sns-out",
64
+ fileExtension: '.yml',
65
+ isAppend: true
66
+ }
67
+ }
68
+ }
69
+
70
+ module.exports = createDefaultSnsOut
@@ -23,12 +23,11 @@ const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-l
23
23
  const { getGraphServiceNameFromGraphServerTagWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
24
24
 
25
25
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
26
- const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, } = require("../../libs/Consts");
26
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName, externalResourceSns, } = require("../../libs/Consts");
27
27
  const templatePath = path.join(__dirname, "./template.ejs");
28
28
 
29
29
 
30
-
31
- async function dataForGenerateLambdaRole(_izContext, allObjSchemas, srcPath) {
30
+ async function dataForGenerateLambdaRole(_izContext, allObjSchemas, allRelSchemas, srcPath) {
32
31
  const externalLambdaIamRoleArray = [];
33
32
  for (const objectSchema of allObjSchemas) {
34
33
 
@@ -47,19 +46,30 @@ async function dataForGenerateLambdaRole(_izContext, allObjSchemas, srcPath) {
47
46
  }
48
47
  }
49
48
  }
49
+
50
+ }
51
+
52
+
53
+ // updateRelationship external lambda role
54
+ for (const handler of Object.values(HANDLER)) {
55
+ if (handler !== HANDLER.hdrApi) {
56
+ const externalLambdaIamRoleUpdateRelationship = await externalLambdaIamRoleDataUpdateRelationshipSchema(_izContext, allRelSchemas, handler)
57
+ externalLambdaIamRoleUpdateRelationship && externalLambdaIamRoleArray.push(externalLambdaIamRoleUpdateRelationship)
58
+ }
50
59
  }
51
60
 
61
+
52
62
  // findData external lambda role
53
63
 
54
64
  // processLogical
55
65
 
56
- // updateRelationship external lambda role
66
+
57
67
  // updateRelationshipComplete external lambda role
58
68
 
59
69
  // ... another external lambda role data
60
70
 
61
71
 
62
- console.log("createSourceArrayIamRole", (externalLambdaIamRoleArray))
72
+ console.log("createSourceArrayIamRole", JSON.stringify(externalLambdaIamRoleArray))
63
73
  // return externalLambdaIamRoleArray
64
74
 
65
75
  return {
@@ -67,14 +77,14 @@ async function dataForGenerateLambdaRole(_izContext, allObjSchemas, srcPath) {
67
77
  templateData: { datas: externalLambdaIamRoleArray },
68
78
  setting: {
69
79
  savePath: path.join(srcPath, SOURCE_PATH.externalService),
70
- saveFileName: "generatedServiceConfig",
71
- fileExtension: '.js',
80
+ saveFileName: "generatedLambdaRoleServiceConfig",
81
+ fileExtension: ".js",
72
82
  isAppend: false
73
83
  }
74
84
  }
75
85
  }
76
- async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler) {
77
86
 
87
+ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, action, handler) {
78
88
  const objectType = objectSchema.objectType;
79
89
  const additionalResourcePermission = [];
80
90
  // let functionNameArray = [];
@@ -117,8 +127,8 @@ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, acti
117
127
  // throw Error("invalid action")
118
128
  }
119
129
 
120
- console.log("additionalResourcePermission:", (additionalResourcePermission))
121
-
130
+ // console.log("additionalResourcePermissionExtraLambdaRole:", JSON.stringify(additionalResourcePermission))
131
+ console.log("additionalResourcePermissionInExternalRolePerAction", JSON.stringify(additionalResourcePermission))
122
132
  return {
123
133
  functionName: functionName,
124
134
  action: action,
@@ -127,6 +137,42 @@ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, acti
127
137
  }
128
138
 
129
139
 
140
+
141
+ async function externalLambdaIamRoleDataUpdateRelationshipSchema(_izContext, allRelSchemas, handler) {
142
+ const functionName = "UpdateRelationship" + upperCase(handler);
143
+ const additionalResourcePermission = [];
144
+ const graphServiceNames = [];
145
+ for (const allRelSchema of Object.values(allRelSchemas)) {
146
+ for (const relationship of Object.values(allRelSchema)) {
147
+ for (const storageResource of Object.values(relationship.storageResources)) {
148
+ if (storageResource.storageType === STORAGE_TYPES.graph) {
149
+ let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
150
+ if (!graphServiceNames.includes(getGraphServiceTag)) {
151
+ graphServiceNames.push(getGraphServiceTag)
152
+ }
153
+ }
154
+ }
155
+ }
156
+ }
157
+ console.log("graphServiceNames", graphServiceNames)
158
+ additionalResourcePermission.push(
159
+ createIamRole(
160
+ {
161
+ [RESOURCE_CLASSES.sns]: ["Publish"]
162
+ },
163
+ graphServiceNames.map(graphServiceName =>
164
+ externalResourceSns("InUpdateRelationship", graphServiceName)
165
+ )
166
+ )
167
+ )
168
+
169
+ console.log("additionalResourcePermissionInexternalLambdaIamRoleDataUpdateRelationshipSchema", JSON.stringify(additionalResourcePermission))
170
+ return {
171
+ functionName,
172
+ additionalResourcePermission
173
+ }
174
+ }
175
+
130
176
  module.exports = dataForGenerateLambdaRole;
131
177
 
132
178
 
@@ -24,8 +24,10 @@ const lambdaSharedLib = izaraShared.lambdaSharedLib
24
24
  const snsSharedLib = izaraShared.snsSharedLib
25
25
  const initialSetupConfig = require('../../config/Config') // config external serviceName
26
26
  const basicNodeSchemaLib = require('@izara_project/izara-attribute-tree').basicNodeSchemaLib
27
+ const _izContext = {logger : Logger}
27
28
 
28
- module.exports.generatedLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
29
+ module.exports.generatedLambdaRole = async () => {
30
+ let externalLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %>
29
31
  {
30
32
  functionName: "<%- data.functionName %>",
31
33
  statement: [
@@ -49,4 +51,6 @@ module.exports.generatedLambdaRole = [ <%_ datas.forEach((data,dataIndex) => { %
49
51
  }
50
52
  ]
51
53
  }, <%_ }) -%>
52
- ]
54
+ ]
55
+ return externalLambdaRole
56
+ }
@@ -20,12 +20,77 @@ const path = require('path');
20
20
  const fs = require('fs');
21
21
 
22
22
  const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
-
23
+ const { getGraphServiceNameFromGraphServerTagWithCache, getServiceNameWithCache } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
24
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 } = require("../../libs/Consts");
25
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, resourceNames, RESOURCE_CLASSES, DEFAULT_LAMBDA_ROLE_PER_ACTION, SOURCE_PATH, externalResourceName } = require("../../libs/Consts");
26
26
 
27
27
  const templatePath = path.join(__dirname, "./template.ejs");
28
28
 
29
+ async function getGraphServiceTagFromRelSchema(_izContext, allRelSchemas) {
30
+ let graphServiceNames = [];
31
+ // for (const allRelSchema of Object.values(allRelSchemas)) {
32
+ // for (const relationship of Object.values(allRelSchema)) {
33
+ // for (const storageResource of Object.values(relationship.storageResources)) {
34
+ // if (storageResource.storageType === STORAGE_TYPES.graph) {
35
+ // let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
36
+ // if (!graphServiceNames.includes(getGraphServiceTag)) {
37
+ // graphServiceNames.push(getGraphServiceTag);
38
+ // }
39
+ // }
40
+ // }
41
+ // }
42
+ // }
43
+
44
+
45
+ await Promise.all(allRelSchemas.map(async relSchema => {
46
+ let relTag = Object.keys(relSchema)[0];
47
+ let relSchemaData = relSchema[relTag];
48
+
49
+ await Promise.all(Object.values(relSchemaData.storageResources).map(async storageResource => {
50
+ if (storageResource.storageType === STORAGE_TYPES.graph) {
51
+ let getGraphServiceTag = await getGraphServiceNameFromGraphServerTagWithCache(_izContext, storageResource.graphServerTag)
52
+ graphServiceNames.push(getGraphServiceTag);
53
+ }
54
+ }))
55
+ }));
56
+
57
+ return [...new Set(graphServiceNames)];
58
+ }
59
+
60
+
61
+
62
+ async function createExternalSnsSubscriptions(_izContext, allRelSchemas, srcPath) {
63
+ const snsServiceConfigArray = [];
64
+ const snsServiceConfigUpdateRelationshipComplete = await snsSubScriptionUpdateRelationship(_izContext, allRelSchemas)
65
+ snsServiceConfigUpdateRelationshipComplete && snsServiceConfigArray.push(snsServiceConfigUpdateRelationshipComplete)
66
+
67
+
68
+ return {
69
+ templatePath: templatePath,
70
+ templateData: { datas: snsServiceConfigArray },
71
+ setting: {
72
+ savePath: path.join(srcPath, SOURCE_PATH.externalService),
73
+ saveFileName: "generatedSnsServiceConfig",
74
+ fileExtension: ".js",
75
+ isAppend: false
76
+ }
77
+ }
78
+ }
79
+ // update Relationship
80
+ async function snsSubScriptionUpdateRelationship(_izContext, allRelSchemas) {
81
+ let serviceNames = await getGraphServiceTagFromRelSchema(_izContext, allRelSchemas)
82
+
83
+ return {
84
+ serviceNames: serviceNames,
85
+ topicName: "OutUpdateRelationship",
86
+ sqsEndpoint: "OutUpdateRelationshipComplete"
87
+ }
88
+ }
89
+
90
+
91
+ // create Relationship
92
+
29
93
 
94
+ module.exports = createExternalSnsSubscriptions
30
95
 
31
96
  // not done yet wait for comfirmation
@@ -0,0 +1,12 @@
1
+ [
2
+ {
3
+ "serviceName": "externalService",
4
+ "topicName": "sns of external service",
5
+ "sqsEndpoint": "sqs inside this service"
6
+ },
7
+ {
8
+ "serviceName": [],
9
+ "topicName": [],
10
+ "sqsEndpoint": []
11
+ }
12
+ ]