@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
@@ -81,22 +81,23 @@ module.exports.createDefaultSourceDataDynamoDB = (_izContext, srcPath) => {
81
81
  }
82
82
  ];
83
83
 
84
- console.log("defaultlDynamoDataList: ", (defaultDynamoDataList));
84
+ // console.log("defaultlDynamoDataList: ", (defaultDynamoDataList));
85
85
 
86
86
  for (let defaultlDynamoData of defaultDynamoDataList) {
87
87
  resultsForCreateSource.push({
88
88
  templatePath: templatePath,
89
89
  templateData: defaultlDynamoData,
90
90
  setting: {
91
+ initialData: 'Resources:\n',
91
92
  savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
92
- saveFileName: 'dynamoDB-table',
93
+ saveFileName: 'generated-dynamoDB-table',
93
94
  fileExtension: '.yml',
94
95
  isAppend: true
95
96
  }
96
97
  });
97
98
  }
98
99
 
99
- console.log("resultForCreateDefaultDynamoDb: ", (resultsForCreateSource));
100
+ // console.log("resultForCreateDefaultDynamoDb: ", (resultsForCreateSource));
100
101
 
101
102
  return resultsForCreateSource;
102
103
  }
@@ -59,22 +59,22 @@ function createDataForDefaultSnsInSqs(_izContext, srcPath) {
59
59
  }
60
60
  ]
61
61
 
62
- console.log("defaultSnsInSqsDataList", defaultSnsInSqsDataList);
62
+ // console.log("defaultSnsInSqsDataList", defaultSnsInSqsDataList);
63
63
 
64
64
  for (let defaultSnsInSqsData of defaultSnsInSqsDataList) {
65
65
  resultsForCreateDefaultSnsInSqs.push({
66
66
  templatePath,
67
67
  templateData: defaultSnsInSqsData,
68
68
  setting: {
69
- // initialData: "",
69
+ initialData: "Resources:\n",
70
70
  savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
71
- saveFileName: "sns-in-sqs",
71
+ saveFileName: "generated-sns-in-sqs",
72
72
  fileExtension: ".yml",
73
73
  isAppend: true
74
74
  }
75
75
  })
76
76
  }
77
- console.log("resultsForCreateDefaultSnsInSqs", resultsForCreateDefaultSnsInSqs);
77
+ // console.log("resultsForCreateDefaultSnsInSqs", resultsForCreateDefaultSnsInSqs);
78
78
  return resultsForCreateDefaultSnsInSqs;
79
79
  }
80
80
 
@@ -60,7 +60,7 @@ function dataForCreateSnsAndSqsQueueFromObjectSchema(_izContext, objectSchema, s
60
60
  }
61
61
  }
62
62
  }
63
- console.log("snsAndSqsQueueArray", (snsAndSqsDataArray))
63
+ // console.log("snsAndSqsQueueArray", (snsAndSqsDataArray))
64
64
  return snsAndSqsDataArray
65
65
  }
66
66
 
@@ -81,9 +81,9 @@ function createQueueNameForSnsAndSqsQueue(_izContext, objectSchema, action, hand
81
81
  module.exports.createSourceSnsAndSqs = (_izContext, objectSchema, srcPath) => {
82
82
  let resultsForCreateSnsAndSqsSource = [];
83
83
  let setting = {
84
- initialData:'Resources:\n',
84
+ initialData: 'Resources:\n',
85
85
  savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
86
- saveFileName: 'sns-in-sqs',
86
+ saveFileName: 'generated-sns-in-sqs',
87
87
  fileExtension: '.yml',
88
88
  isAppend: true
89
89
  }
@@ -103,6 +103,6 @@ module.exports.createSourceSnsAndSqs = (_izContext, objectSchema, srcPath) => {
103
103
  })
104
104
  }
105
105
  }
106
- console.log("resultsForCreateSnsAndSqsSource", resultsForCreateSnsAndSqsSource);
106
+ // console.log("resultsForCreateSnsAndSqsSource", resultsForCreateSnsAndSqsSource);
107
107
  return resultsForCreateSnsAndSqsSource
108
108
  }
@@ -1,3 +1,4 @@
1
+ #------- queue ---------
1
2
  <%- queueName %>:
2
3
  Type: "AWS::SQS::Queue"
3
4
  Properties:
@@ -0,0 +1,89 @@
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 createDataForCreateSourceSnsOut(_izContext, objectSchema, srcPath) {
36
+ const createSourceArray = [];
37
+ for (const action of Object.values(ACTIONS)) {
38
+ if (objectSchema.overWriteHandlers[action]) {
39
+ for (const handler of objectSchema.overWriteHandlers[action]) {
40
+ const snsOut = {
41
+ queueName: createQueueName(_izContext, objectSchema, action, handler, srcPath)
42
+ }
43
+ snsOut.queueName && createSourceArray.push(snsOut)
44
+ }
45
+ } else {
46
+ for (const handler of DEFAULT_HANDLER_PER_ACTION[action]) {
47
+ const snsOut = {
48
+ queueName: createQueueName(_izContext, objectSchema, action, handler, srcPath)
49
+ }
50
+ snsOut.queueName && createSourceArray.push(snsOut)
51
+ }
52
+ }
53
+ }
54
+ console.log("createSourceArrayInCreateSourceSnsOut", createSourceArray)
55
+ return createSourceArray;
56
+ }
57
+
58
+ function createQueueName(_izContext, objectSchema, action, handler) {
59
+ let objectType = objectSchema.objectType
60
+ let queueName = upperCase(objectType) + upperCase(action) + upperCase(handler)
61
+ if (queueName.includes("HdrSqs")) {
62
+ queueName = upperCase(objectType) + upperCase(action)
63
+ } else
64
+ return
65
+ return queueName
66
+ }
67
+ function createSourceSnsOut(_izContext, objectSchema, srcPath) {
68
+ let resultsForCreateSnsOut = [];
69
+ const snsOutDataList = createDataForCreateSourceSnsOut(_izContext, objectSchema, srcPath);
70
+ for (let snsOutData of snsOutDataList) {
71
+ resultsForCreateSnsOut.push(
72
+ {
73
+ templatePath: templatePath,
74
+ templateData: snsOutData,
75
+ setting: {
76
+ initialData: 'Resources:\n',
77
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
78
+ saveFileName: 'generated-sns-out',
79
+ fileExtension: '.yml',
80
+ isAppend: true
81
+ }
82
+ }
83
+ )
84
+ }
85
+ return resultsForCreateSnsOut
86
+ }
87
+
88
+
89
+ module.exports = createSourceSnsOut
@@ -0,0 +1,3 @@
1
+ {
2
+ "queueName": "string"
3
+ }
@@ -0,0 +1,10 @@
1
+ ##--------- [Create Topic Out]
2
+ Out<%- firstLetterUpperCase(queueName) %>:
3
+ Type: AWS::SNS::Topic
4
+ Properties:
5
+ DisplayName: "SNS Message out"
6
+ TopicName: ${self:custom.iz_resourcePrefix}Out<%- firstLetterUpperCase(queueName) %>
7
+
8
+ <%_ function firstLetterUpperCase(text) {
9
+ return text.charAt(0).toUpperCase() + text.slice(1)
10
+ } _%>
@@ -0,0 +1,151 @@
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
+
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, SQS_RESOURCE, SOURCE_PATH } = require("../../../libs/Consts");
26
+
27
+ const templatePath = path.join(__dirname, "./template.ejs")
28
+
29
+ function defaultIamRolePerAction() {
30
+
31
+ let defaultIamRole = [];
32
+
33
+
34
+ defaultIamRole.push(
35
+ createIamRole(
36
+ {
37
+ [RESOURCE_CLASSES.s3]: ["GetObject", "GetObjectVersion"],
38
+ },
39
+ [
40
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/perServiceSchemas/*"),
41
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/ServiceNameConfig.json"),
42
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema/serviceConfig/GraphServerTags.json"),
43
+ ]
44
+ )
45
+ );
46
+
47
+ defaultIamRole.push(
48
+ createIamRole(
49
+ { [RESOURCE_CLASSES.s3]: ["ListBucket"] },
50
+ [
51
+ resourceNames(RESOURCE_CLASSES.s3, "object-schema"),
52
+ ]
53
+ )
54
+ );
55
+
56
+ return defaultIamRole
57
+ }
58
+
59
+ /**
60
+ * receive objectSchema
61
+ * create data for updateRelationshipSchema
62
+ *
63
+ * @param {Object} objectSchema
64
+ * @return {{ templatePath, templateData, setting } }
65
+ */
66
+
67
+ function data(_izContext, srcPath) {
68
+ let createSourceArray = [];
69
+ const createSourceParam = createParamForCreateSource(srcPath);
70
+ createSourceArray.push(createSourceParam);
71
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
72
+ return createSourceArray
73
+ }
74
+
75
+
76
+ function createParamForCreateSource(srcPath) {
77
+ let awaitingTable = ["AwaitingMultipleSteps", "AwaitingMultipleStepByPending"]
78
+ let handlerType = 'HdrSqs';
79
+ let functionName = 'updateRelationshipComplete'
80
+ let additionalResourcePermission = defaultIamRolePerAction();
81
+
82
+ additionalResourcePermission.push(
83
+ // createIamRole(
84
+ // { [RESOURCE_CLASSES.lambda]: ["InvokeFunction"] },
85
+ // [resourceNames(RESOURCE_CLASSES.lambda, "*GetNodeHdrInv")]),
86
+ createIamRole(
87
+ {
88
+ [RESOURCE_CLASSES.sqs]: [
89
+ SQS_RESOURCE.deleteMessage,
90
+ SQS_RESOURCE.getQueueAttributes,
91
+ SQS_RESOURCE.receiveMessage,
92
+ SQS_RESOURCE.sendMessage,
93
+ SQS_RESOURCE.deleteMessageBatch,
94
+ SQS_RESOURCE.getQueueUrl,
95
+ ],
96
+ [RESOURCE_CLASSES.sns]: [
97
+ "Publish", "Subscribe"
98
+ ]
99
+ },
100
+ [
101
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs)),
102
+ resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(HANDLER.hdrSqs) + "DLQ"),
103
+ resourceNames(RESOURCE_CLASSES.sns, "In" + upperCase(functionName)),
104
+ resourceNames(RESOURCE_CLASSES.sns, "Out" + upperCase(functionName))
105
+ ],
106
+ ))
107
+ additionalResourcePermission.push(
108
+ createIamRole(
109
+ {
110
+ [RESOURCE_CLASSES.dynamoDbTable]: ["UpdateItem", "Query", "DeleteItem"]
111
+ },
112
+ awaitingTable.map(tableName =>
113
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
114
+ )
115
+ )
116
+ )
117
+ return {
118
+ templatePath: templatePath,
119
+ templateData: {
120
+ functionName,
121
+ handlerType,
122
+ additionalResourcePermission,
123
+ resourceLocation: SOURCE_PATH.resourceLocationUpdateRelationshipSchema
124
+ },
125
+ setting: {
126
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
127
+ saveFileName: 'updateRelationshipSchema',
128
+ fileExtension: '.yml',
129
+ isAppend: true
130
+ }
131
+
132
+ }
133
+ }
134
+
135
+
136
+
137
+ // [
138
+ // {
139
+ // 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',
140
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
141
+ // setting: {
142
+ // savePath: '/generatedCode/source/',
143
+ // saveFileName: 'ObjectTypeGet',
144
+ // fileExtension: '.js',
145
+ // isAppend: false
146
+ // }
147
+ // }
148
+ // ]
149
+
150
+
151
+ module.exports = data;
@@ -0,0 +1,33 @@
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionName) %>:
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,76 @@
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
+ const functionName = "updateRelationshipComplete";
43
+ const mainFunction = "updateRelationshipSchemaComplete"
44
+ return {
45
+ templatePath: templatePath,
46
+ templateData: {
47
+ functionName: upperCase(functionName),
48
+ mainFunction: upperCase(mainFunction),
49
+ queueName: upperCase(functionName) + "HdrSqs",
50
+ isCreateMainFunction: false
51
+ },
52
+ setting: {
53
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
54
+ saveFileName: `${upperCase(functionName)}_HdrSqs`,
55
+ fileExtension: '.js',
56
+ isAppend: false
57
+ }
58
+ }
59
+ }
60
+
61
+
62
+ // [
63
+ // {
64
+ // 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',
65
+ // templateData: { tableName: 'ObjectTypeSingle', attributes: [Array] },
66
+ // setting: {
67
+ // savePath: '/generatedCode/source/',
68
+ // saveFileName: 'ObjectTypeGet',
69
+ // fileExtension: '.js',
70
+ // isAppend: false
71
+ // }
72
+ // }
73
+ // ]
74
+
75
+
76
+ module.exports = data;
@@ -0,0 +1,127 @@
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 updateRelationshipComplete = require('./UpdateRelationshipComplete_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
+ 'errorsFound'
40
+ ],
41
+ properties: {
42
+ returnValue: {//validate from authorizer
43
+ type: 'object',
44
+ },
45
+ status: {
46
+ type: 'string',
47
+ },
48
+ errorsFound: {
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
+ "UpdateRelationshipComplete", // 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.errorsFound)
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
+ //(<afterSendParamToMainFunction>)
98
+ //(</afterSendParamToMainFunction>)
99
+
100
+ // call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
101
+ let recordPromise = recordHandlerSharedLib.recordHandler(
102
+ record, // one record will send to mainFunction
103
+ updateRelationshipComplete.updateRelationshipComplete, // mainFunction that need to invoke.
104
+ "UpdateRelationshipComplete", // queue name that need to retry or send to dlq
105
+ passOnProperties, // all parameters that mainFunction needed.
106
+ );
107
+ record._izContext.logger.debug('after recordPromise in handler');
108
+ recordPromises.push(recordPromise); // push promise to recordPromises
109
+ }))
110
+
111
+ Logger.debug('before Promise.all(recordPromises) in handler');
112
+ try {
113
+ // --- main await all promises
114
+ await Promise.all(recordPromises); // await all promises
115
+
116
+ return event.Records // return all for local testing
117
+
118
+ } catch {
119
+ Logger.debug('Promise.all(recordPromises) in handler threw error (at least one record did no resolve)');
120
+ }
121
+ Logger.debug('after Promise.all(recordPromises) in handler');
122
+
123
+ } catch (err) {
124
+ Logger.error('Unhandled Error, UpdateRelationshipCompleteHdrSqs: ', err);
125
+ throw (err);
126
+ }
127
+ });
@@ -0,0 +1,55 @@
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
+ return {
43
+ templatePath: templatePath,
44
+ templateData: {
45
+ },
46
+ setting: {
47
+ savePath: path.join(srcPath, SOURCE_PATH.updateRelationshipSchema),
48
+ saveFileName: `UpdateRelationshipComplete_Main`,
49
+ fileExtension: '.js',
50
+ isAppend: false
51
+ }
52
+ }
53
+ }
54
+
55
+ module.exports = data;