@izara_project/izara-market-library-service-schemas 1.0.19 → 1.0.20

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 (86) hide show
  1. package/package.json +1 -1
  2. package/src/SourceManager/src/Utils.js +33 -9
  3. package/src/TemplateManager/src/FindData/FindDataYaml/data.js +4 -1
  4. package/src/TemplateManager/src/FindData/FindDataYaml/template.ejs +1 -14
  5. package/src/TemplateManager/src/GenerateCode.js +22 -5
  6. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/data.js +22 -2
  7. package/src/TemplateManager/src/OutPerActionComplete/OutCreateComplete/functionYaml/template.ejs +1 -14
  8. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/data.js +21 -2
  9. package/src/TemplateManager/src/OutPerActionComplete/OutDeleteComplete/functionYaml/template.ejs +1 -14
  10. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/data.js +23 -3
  11. package/src/TemplateManager/src/OutPerActionComplete/OutGetComplete/functionYaml/template.ejs +1 -14
  12. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/data.js +22 -2
  13. package/src/TemplateManager/src/OutPerActionComplete/OutUpdateComplete/functionYaml/template.ejs +1 -14
  14. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/data.js +6 -6
  15. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrApi/template.ejs +1 -14
  16. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/data.js +2 -1
  17. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrDsq/template.ejs +1 -14
  18. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/data.js +1 -1
  19. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrInv/template.ejs +1 -14
  20. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/data.js +3 -1
  21. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrSqs/template.ejs +1 -14
  22. package/src/TemplateManager/src/PerActionEndpoint/FunctionYaml/HdrWbs/data.js +1 -1
  23. package/src/TemplateManager/src/PerActionEndpoint/MainFunction/Create/template.ejs +23 -3
  24. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/data.js +18 -2
  25. package/src/TemplateManager/src/ProcessLogical/ProcessLogicalYaml/template.ejs +1 -14
  26. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/data.js +20 -3
  27. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrDsq/template.ejs +1 -14
  28. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/data.js +21 -3
  29. package/src/TemplateManager/src/ProcessLogicalPagination/FunctionYaml/HdrSqs/template.ejs +1 -14
  30. package/src/TemplateManager/src/ProcessLogicalPagination/mainFunction/template.ejs +1 -1
  31. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/data.js +16 -2
  32. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrApi/template.ejs +1 -14
  33. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/data.js +17 -2
  34. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  35. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/data.js +16 -2
  36. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrInv/template.ejs +1 -14
  37. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/data.js +18 -3
  38. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  39. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/data.js +18 -3
  40. package/src/TemplateManager/src/RelationshipPerAction/CreateRelationship/createRelationshipComplete/functionYaml/template.ejs +1 -14
  41. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/data.js +15 -2
  42. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrApi/template.ejs +1 -14
  43. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/data.js +17 -2
  44. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  45. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/data.js +16 -2
  46. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrInv/template.ejs +1 -14
  47. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/data.js +18 -3
  48. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  49. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/data.js +18 -3
  50. package/src/TemplateManager/src/RelationshipPerAction/DeleteRelationship/DeleteRelationshipComplete/functionYaml/template.ejs +1 -14
  51. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/data.js +19 -4
  52. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRalationshipComplete/functionYaml/template.ejs +1 -14
  53. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/data.js +19 -2
  54. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrApi/template.ejs +1 -14
  55. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/data.js +19 -2
  56. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrDsq/template.ejs +1 -14
  57. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/data.js +20 -2
  58. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrInv/template.ejs +1 -14
  59. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/data.js +20 -2
  60. package/src/TemplateManager/src/RelationshipPerAction/UpdateRelationshipSchema/updateRelationship/functionYaml/HdrSqs/template.ejs +1 -14
  61. package/src/TemplateManager/src/Role/createSharedResource.js +270 -0
  62. package/src/TemplateManager/src/Role/sharedResourceTemplate.ejs +58 -0
  63. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrDsq/data.js +1 -1
  64. package/src/TemplateManager/src/TranslateIdReq/TranslateIds/functionYaml/HdrSqs/data.js +1 -1
  65. package/src/TemplateManager/src/externalService/LambdaRole/data.js +13 -13
  66. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/functionYaml/data.js +16 -10
  67. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/data.js +8 -5
  68. package/src/TemplateManager/src/flowSchema/UploadS3Case/createObject/handler/template.ejs +22 -9
  69. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/data.js +102 -0
  70. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/functionYaml/template.ejs +43 -0
  71. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/data.js +94 -0
  72. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateAsyncHandler.ejs +110 -0
  73. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/handler/templateSyncHandler.ejs +49 -0
  74. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/hookLogic/data.js +65 -0
  75. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/data.js +67 -0
  76. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/mainFunction/template.ejs +30 -0
  77. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/data.js +125 -0
  78. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/snsTemplate.ejs +59 -0
  79. package/src/TemplateManager/src/flowSchema/UploadS3Case/hookCode(old)/queue/sqsTemplate.ejs +43 -0
  80. package/src/TemplateManager/src/libs/Consts.js +36 -10
  81. package/src/TemplateManager/src/reStructureExample/GenerateCodeTest.js +31 -0
  82. package/src/TemplateManager/src/reStructureExample/TemplateConfig.js +11 -0
  83. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/data.js +0 -0
  84. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generateCodeShared.js +1 -0
  85. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/generatePerAction.js +5 -0
  86. package/src/TemplateManager/src/reStructureExample/TemplateData/perAction/template.ejs +0 -0
@@ -0,0 +1,270 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http://izara.io>
3
+ This program is free software: you can redistribute it and/or modify
4
+ it under the terms of the GNU Affero General Public License as
5
+ published by the Free Software Foundation, either version 3 of the
6
+ License, or (at your option) any later version.
7
+ This program is distributed in the hope that it will be useful,
8
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
9
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
+ GNU Affero General Public License for more details.
11
+ You should have received a copy of the GNU Affero General Public License
12
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
13
+ */
14
+ 'use strict';
15
+ const { SOURCE_GENERATE_IAM_ROLE, SOURCE_PATH, SAVE_FILE_NAME } = require('../libs/Consts');
16
+ const { firstLetterUpperCase: upperCase } = require("../../../MainLibs/src/Utils")
17
+ const path = require('path');
18
+
19
+ /**
20
+ * Process additional resource permissions for an object type
21
+ * @param {Array} resourcePermissions - Array of resource permissions to process
22
+ * @param {Object} targetResources - Resources object to update
23
+ */
24
+ const processResourcePermissions = (resourcePermissions, targetResources) => {
25
+ if (!Array.isArray(resourcePermissions)) return;
26
+ resourcePermissions.forEach(resourcePermission => {
27
+ if (!resourcePermission.action) return;
28
+ const [key, value] = Object.entries(resourcePermission.action)[0];
29
+ if (!targetResources[key]) {
30
+ targetResources[key] = [];
31
+ }
32
+ const actionsList = Array.isArray(value) ? value : [value];
33
+ const resourcesList = Array.isArray(resourcePermission.resource)
34
+ ? resourcePermission.resource
35
+ : [resourcePermission.resource];
36
+ // Check if entry with same actions exists
37
+ const existingEntry = targetResources[key].find(entry =>
38
+ JSON.stringify(entry.actions) === JSON.stringify(actionsList)
39
+ );
40
+ if (existingEntry) {
41
+ // Merge resources without duplicates
42
+ existingEntry.resource = [
43
+ ...new Set([...existingEntry.resource, ...resourcesList])
44
+ ];
45
+ } else {
46
+ // Add new entry
47
+ targetResources[key].push({
48
+ actions: actionsList,
49
+ resource: resourcesList
50
+ });
51
+ }
52
+ });
53
+ };
54
+ /**
55
+ * Check if an item should be skipped based on templateData content
56
+ * @param {Object} templateData - Template data to check
57
+ * @returns {Boolean} True if item should be skipped
58
+ */
59
+ const shouldSkipItem = (templateData) => {
60
+ return !templateData ||
61
+ Object.keys(templateData).length === 0 ||
62
+ !templateData.additionalResourcePermission;
63
+ };
64
+ /**
65
+ * Initialize object type structure if it doesn't exist
66
+ * @param {Object} groupedByObjectType - The grouped object
67
+ * @param {String} objectType - Object type to initialize
68
+ * @param {Array} objectTypeList - List to track object types
69
+ */
70
+ const initializeObjectType = (groupedByObjectType, objectType, objectTypeList) => {
71
+ if (!groupedByObjectType[objectType]) {
72
+ groupedByObjectType[objectType] = {
73
+ functionNames: [],
74
+ actions: [],
75
+ resources: {},
76
+ actionHandler: []
77
+ };
78
+ objectTypeList.push(objectType);
79
+ }
80
+ };
81
+ module.exports.createSharedResource = (_izContext, createSourceParams, srcPath) => {
82
+ // Initialize data structure
83
+ const groupedByObjectType = {
84
+ [SOURCE_GENERATE_IAM_ROLE.ProcessFindDataRole]: {
85
+ handlerType: [],
86
+ resources: {}
87
+ },
88
+ [SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole]: {
89
+ functionNames: [],
90
+ handlerType: [],
91
+ resources: {}
92
+ },
93
+ [SOURCE_GENERATE_IAM_ROLE.RelationshipRole]: {
94
+ handlerType: [],
95
+ resources: {}
96
+ },
97
+ [SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole]: {
98
+ handlerType: [],
99
+ resources: []
100
+ },
101
+ Other: []
102
+ };
103
+ const objectTypeList = [];
104
+ // Ensure data is defined - assuming it comes from createSourceParams
105
+ const data = createSourceParams || [];
106
+ // Process each item in data
107
+ data.map((item) => {
108
+ const templateData = item.templateData;
109
+ if (shouldSkipItem(templateData)) return;
110
+ if (templateData.objectType) {
111
+ // Handle items with objectType
112
+ initializeObjectType(groupedByObjectType, templateData.objectType, objectTypeList);
113
+ // Add function name if it doesn't exist
114
+ if (templateData.functionName &&
115
+ !groupedByObjectType[templateData.objectType].functionNames?.includes(templateData.functionName)) {
116
+ groupedByObjectType[templateData.objectType].functionNames.push(templateData.functionName);
117
+ }
118
+ // Add action if it doesn't exist
119
+ if (templateData.action !== null &&
120
+ !groupedByObjectType[templateData.objectType].actions.includes(templateData.action)) {
121
+ groupedByObjectType[templateData.objectType].actions.push(templateData.action);
122
+ }
123
+ // Process additionalResourcePermission
124
+ processResourcePermissions(
125
+ templateData.additionalResourcePermission,
126
+ groupedByObjectType[templateData.objectType].resources
127
+ );
128
+ }
129
+ else if (templateData.functionName &&
130
+ (templateData.functionName.includes('ObjectComplete') ||
131
+ templateData.functionName.includes('NodeComplete'))) {
132
+ // Handle ObjectComplete items
133
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].functionNames.push(templateData.functionName);
134
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].handlerType.push(templateData.handlerType);
135
+ processResourcePermissions(
136
+ templateData.additionalResourcePermission,
137
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.ObjectCompleteRole].resources
138
+ );
139
+ }
140
+ else if (templateData.functionName && templateData.functionName.includes([SOURCE_GENERATE_IAM_ROLE.RelationshipRole])) {
141
+ if (templateData.functionName.includes([SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole])) {
142
+ // Handle RelationshipComplete items
143
+ if (templateData.handlerType &&
144
+ !groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].handlerType.includes(templateData.handlerType)) {
145
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].handlerType.push(templateData.handlerType);
146
+ }
147
+ processResourcePermissions(
148
+ templateData.additionalResourcePermission,
149
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipCompleteRole].resources
150
+ );
151
+ } else {
152
+ // Handle regular Relationship items
153
+ if (templateData.handlerType &&
154
+ !groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].handlerType.includes(templateData.handlerType)) {
155
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].handlerType.push(templateData.handlerType);
156
+ }
157
+ processResourcePermissions(
158
+ templateData.additionalResourcePermission,
159
+ groupedByObjectType[SOURCE_GENERATE_IAM_ROLE.RelationshipRole].resources
160
+ );
161
+ }
162
+ }
163
+ else if (templateData.functionName &&
164
+ (templateData.functionName.includes('PaginateProcessLogical') ||
165
+ templateData.functionName.includes('FindData') ||
166
+ templateData.functionName.includes('ProcessLogical'))) {
167
+ // Handle ProcessFindData items
168
+ groupedByObjectType.ProcessFindData.handlerType.push(templateData.handlerType);
169
+ processResourcePermissions(
170
+ templateData.additionalResourcePermission,
171
+ groupedByObjectType.ProcessFindData.resources
172
+ );
173
+ }
174
+ else {
175
+ // Handle other items
176
+ groupedByObjectType.Other.push(item);
177
+ }
178
+ return item;
179
+ });
180
+ // Process "Other" items that might belong to existing object types
181
+ groupedByObjectType.Other = groupedByObjectType.Other.filter(item => {
182
+ const templateData = item.templateData;
183
+ if (!templateData.functionName) return true;
184
+ // Find matching objectType
185
+ const matchedObjectType = objectTypeList.find(objectType =>
186
+ templateData.functionName.toLowerCase().includes(objectType.toLowerCase()) ||
187
+ templateData.functionName.includes(objectType.charAt(0).toUpperCase() + objectType.slice(1))
188
+ );
189
+ if (matchedObjectType) {
190
+ // Move the item to the matched object type
191
+ groupedByObjectType[matchedObjectType].actionHandler.push(templateData.handlerType);
192
+ groupedByObjectType[matchedObjectType].resources = {
193
+ ...groupedByObjectType[matchedObjectType].resources,
194
+ ...templateData.additionalResourcePermission
195
+ };
196
+ return false; // Remove from Other
197
+ }
198
+ return true; // Keep in Other
199
+ });
200
+ // Prepare results
201
+
202
+
203
+ // Process and prepare data for role definitions and extract any resources
204
+ // that might be related to object types but weren't categorized properly
205
+ const roles = [];
206
+ const otherResources = []
207
+ Object.entries(groupedByObjectType).forEach(([objectType, data]) => {
208
+ if (objectType === 'Other' || !data.resources) return;
209
+ // สร้าง policy statements จาก resources
210
+ const rolePolicyStatement = [];
211
+ Object.entries(data.resources).forEach(([effect, permissionList]) => {
212
+ if (!Array.isArray(permissionList)) {
213
+ // permissionList might be in a different format
214
+ if (typeof permissionList === 'object' && !Array.isArray(permissionList)) {
215
+ // Handle non-standard format
216
+ const actions = [];
217
+ if (permissionList.action) {
218
+ const actionObj = permissionList.action;
219
+ Object.entries(actionObj).forEach(([service, actionList]) => {
220
+ const actionArray = Array.isArray(actionList) ? actionList : [actionList];
221
+ actionArray.forEach(action => actions.push(`${service}:${action}`));
222
+ });
223
+ }
224
+ rolePolicyStatement.push({
225
+ Effect: permissionList.effect || 'Allow',
226
+ Action: actions,
227
+ Resource: permissionList.resource
228
+ });
229
+ return;
230
+ }
231
+ rolePolicyStatement.push({
232
+ Effect: permissionList.effect,
233
+ Action: actions,
234
+ Resource: permission.resource
235
+ });
236
+ return;
237
+ };
238
+ permissionList.forEach(permission => {
239
+ const actions = permission.actions.map(action => `${effect}:${action}`);
240
+ rolePolicyStatement.push({
241
+ Effect: 'Allow',
242
+ Action: actions,
243
+ Resource: permission.resource
244
+ });
245
+ });
246
+ });
247
+ if (rolePolicyStatement.length > 0) {
248
+ roles.push({
249
+ roleName: upperCase(objectType),
250
+ rolePolicyStatement
251
+ });
252
+ }
253
+ });
254
+ const reformattedData = {
255
+ roles,
256
+ };
257
+ const sharedResourceTemplatePath = path.join(__dirname, './sharedResourceTemplate.ejs')
258
+
259
+ return {
260
+ templatePath: sharedResourceTemplatePath,
261
+ templateData: reformattedData,
262
+ setting: {
263
+ initialData: 'Resources:\n',
264
+ savePath: path.join(srcPath, SOURCE_PATH.appYaml),
265
+ saveFileName: SAVE_FILE_NAME.sharedResourceYaml,
266
+ fileExtension: '.yml',
267
+ isAppend: true
268
+ }
269
+ }
270
+ };
@@ -0,0 +1,58 @@
1
+ #IAM Role for Upload Schema functionality
2
+ UploadSchemaRole:
3
+ Type: AWS::IAM::Role
4
+ Properties:
5
+ RoleName: ${self:custom.iz_resourcePrefix}UploadSchemaRole
6
+ AssumeRolePolicyDocument:
7
+ Version: "2012-10-17"
8
+ Statement:
9
+ - Effect: Allow
10
+ Principal:
11
+ Service: "lambda.amazonaws.com"
12
+ Action: sts:AssumeRole
13
+ # this is the managed policy for lambda basic execution ex. logging to cloudwatch
14
+ ManagedPolicyArns:
15
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
16
+ - arn:aws:iam::${self:custom.iz_accountId}:policy/UploadSchemaSharedPolicy
17
+ Policies:
18
+ - PolicyName: ${self:custom.iz_resourcePrefix}UploadSchemaPolicy
19
+ PolicyDocument:
20
+ Version: "2012-10-17"
21
+ Statement:
22
+ - Effect: Allow
23
+ Action:
24
+ - s3:PutObject
25
+ - s3:GetObject
26
+ - s3:ListBucket
27
+ Resource:
28
+ - arn:aws:s3:::object-schema/*
29
+ - arn:aws:s3:::object-schema/perServiceSchemas/${self:custom.iz_serviceTag}/*
30
+ <% if (roles && roles.length > 0) { -%>
31
+ <% roles.forEach(function(role) { %>
32
+ <%= role.roleName %>Role:
33
+ Type: AWS::IAM::Role
34
+ Properties:
35
+ RoleName: ${self:custom.iz_resourcePrefix}<%= role.roleName %>Role
36
+ AssumeRolePolicyDocument:
37
+ Version: "2012-10-17"
38
+ Statement:
39
+ - Effect: Allow
40
+ Principal:
41
+ Service: "lambda.amazonaws.com"
42
+ Action: sts:AssumeRole
43
+ ManagedPolicyArns:
44
+ - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
45
+ Policies:
46
+ - PolicyName: ${self:custom.iz_resourcePrefix}<%= role.roleName %>Policy
47
+ PolicyDocument:
48
+ Version: "2012-10-17"
49
+ Statement:<% role.rolePolicyStatement.forEach(function(statement) { %>
50
+ - Effect: <%= statement.Effect %><%_ if (Array.isArray(statement.Action)) { %>
51
+ Action:<% statement.Action.forEach(function(action) { %>
52
+ - <%= action %><% }); %><% } else { %>Action: <%= statement.Action %><% } -%>
53
+ <% if (Array.isArray(statement.Resource)) { %>
54
+ Resource:<% statement.Resource.forEach(function(resource) { %>
55
+ - <%= resource -%><% }); %><% } else { %>
56
+ Resource: <%= statement.Resource %><% } %><% }); %>
57
+ <% }); %>
58
+ <% } %>
@@ -50,7 +50,7 @@ function createTranslateIdFunctionYamlHdrDsq(srcPath) {
50
50
  ],
51
51
  [RESOURCE_CLASSES.sns]:
52
52
  [
53
- SNS_RESOURCE.publish, SNS_RESOURCE.subscription
53
+ SNS_RESOURCE.publish, SNS_RESOURCE.subscribe
54
54
  ]
55
55
  },
56
56
  [
@@ -50,7 +50,7 @@ function createTranslateIdFunctionYmlHdrSqs(srcPath) {
50
50
  ],
51
51
  [RESOURCE_CLASSES.sns]:
52
52
  [
53
- SNS_RESOURCE.publish, SNS_RESOURCE.subscription
53
+ SNS_RESOURCE.publish, SNS_RESOURCE.subscribe
54
54
  ]
55
55
  },
56
56
  [
@@ -25,7 +25,7 @@ const { getGraphServiceNameFromGraphServerTagWithCache,
25
25
  } = require('@izara_project/izara-core-library-service-schemas/src/ServiceConfig')
26
26
 
27
27
  const { firstLetterLowerCase: lowerCase, firstLetterUpperCase: upperCase } = require("../../../../MainLibs/src/Utils")
28
- const { DEFAULT_HANDLER_PER_ACTION, createIamRole, RESOURCE_CLASSES, SOURCE_PATH, externalResourceName, externalResourceSns, getGraphServiceNameFromAllRelSchema, SAVE_FILE_NAME, LAMBDA_RESOURCE, SNS_RESOURCE, getGraphServiceNameFromObjectSchema, shortNameHandler, SHORT_FUNCTION_NAME, defaultIamRolePerAction, resourceNames } = require("../../libs/Consts");
28
+ const { DEFAULT_HANDLER_PER_ACTION, createIamRole, RESOURCE_CLASSES, SOURCE_PATH, externalResourceName, getGraphServiceNameFromAllRelSchema, SAVE_FILE_NAME, LAMBDA_RESOURCE, SNS_RESOURCE, getGraphServiceNameFromObjectSchema, shortNameHandler, SHORT_FUNCTION_NAME, defaultIamRolePerAction, resourceNames } = require("../../libs/Consts");
29
29
  // const templatePath = path.join(__dirname, "./template.ejs");
30
30
  const templatePath = path.join(__dirname, "./template.ejs");
31
31
  const { getAllLocalRelationshipSchemas } = require('@izara_project/izara-core-library-service-schemas/src/GetObjectSchema')
@@ -159,7 +159,7 @@ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, acti
159
159
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
160
160
  },
161
161
  graphServiceNames.map(graphServiceName =>
162
- externalResourceSns("InUpdateNode", graphServiceName)
162
+ externalResourceName(RESOURCE_CLASSES.sns, "InUpdateNode", graphServiceName)
163
163
  )
164
164
  )
165
165
  )
@@ -171,7 +171,7 @@ async function externalLambdaIamRoleDataPerAction(_izContext, objectSchema, acti
171
171
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
172
172
  },
173
173
  graphServiceNames.map(graphServiceName =>
174
- externalResourceSns("InCreateNodeV2", graphServiceName)
174
+ externalResourceName(RESOURCE_CLASSES.sns, "InCreateNodeV2", graphServiceName)
175
175
  )
176
176
  )
177
177
  )
@@ -215,7 +215,7 @@ async function externalLambdaIamRoleDataUpdateRelationshipSchema(_izContext, all
215
215
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
216
216
  },
217
217
  graphServiceNamesFromAllRelSchemas.map(graphServiceName =>
218
- externalResourceSns("InUpdateRelationship", graphServiceName)
218
+ externalResourceName(RESOURCE_CLASSES.sns, "InUpdateRelationship", graphServiceName)
219
219
  )
220
220
  )
221
221
  )
@@ -240,7 +240,7 @@ async function externalLambdaIamRoleDataCreateRelationshipSchema(_izContext, all
240
240
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
241
241
  },
242
242
  graphServiceNamesFromAllRelSchemas.map(graphServiceName =>
243
- externalResourceSns("InCreateRelationshipV2", graphServiceName)
243
+ externalResourceName(RESOURCE_CLASSES.sns, "InCreateRelationshipV2", graphServiceName)
244
244
  )
245
245
  )
246
246
  )
@@ -262,7 +262,7 @@ async function externalLambdaIamRoleDataDeleteRelationshipSchema(_izContext, all
262
262
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
263
263
  },
264
264
  graphServiceNamesFromAllRelSchemas.map(graphServiceName =>
265
- externalResourceSns("InDeleteRelationshipV2", graphServiceName)
265
+ externalResourceName(RESOURCE_CLASSES.sns, "InDeleteRelationshipV2", graphServiceName)
266
266
  )
267
267
  )
268
268
  )
@@ -325,7 +325,7 @@ function externalLambdaIamRoleDataGetPresignUrl(_izContext) {
325
325
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
326
326
  },
327
327
  [
328
- externalResourceSns("InReservedDynamicUsage", EXTERNAL_SERVICE_NAME.accountLimits)
328
+ externalResourceName(RESOURCE_CLASSES.sns, "InReservedDynamicUsage", EXTERNAL_SERVICE_NAME.accountLimits)
329
329
  ]
330
330
  ),
331
331
  createIamRole(
@@ -354,7 +354,7 @@ function externalLambdaIamRoleDataReservedLimitComplete(_izContext) {
354
354
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
355
355
  },
356
356
  [
357
- externalResourceSns("InCancelUsage", EXTERNAL_SERVICE_NAME.accountLimits)
357
+ externalResourceName(RESOURCE_CLASSES.sns, "InCancelUsage", EXTERNAL_SERVICE_NAME.accountLimits)
358
358
  ]
359
359
  )
360
360
  )
@@ -374,8 +374,8 @@ function externalLambdaIamRoleDataConfirmReservedAfterUpload(_izContext) {
374
374
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
375
375
  },
376
376
  [
377
- externalResourceSns("OutReservedDynamicUsageComplet", EXTERNAL_SERVICE_NAME.accountLimits),
378
- externalResourceSns("InConfirmUsage", EXTERNAL_SERVICE_NAME.accountLimits)
377
+ externalResourceName(RESOURCE_CLASSES.sns, "OutReservedDynamicUsageComplet", EXTERNAL_SERVICE_NAME.accountLimits),
378
+ externalResourceName(RESOURCE_CLASSES.sns, "InConfirmUsage", EXTERNAL_SERVICE_NAME.accountLimits)
379
379
  ]
380
380
  ),
381
381
  )
@@ -395,9 +395,9 @@ function externalLambdaIamRoleDataProcessAfterUpload(_izContext) {
395
395
  [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
396
396
  },
397
397
  [
398
- externalResourceSns("InCancelUsage", EXTERNAL_SERVICE_NAME.accountLimits),
399
- externalResourceSns("InConfirmUsage", EXTERNAL_SERVICE_NAME.accountLimits),
400
- externalResourceSns("InReservedDynamicUsage", EXTERNAL_SERVICE_NAME.accountLimits),
398
+ externalResourceName(RESOURCE_CLASSES.sns, "InCancelUsage", EXTERNAL_SERVICE_NAME.accountLimits),
399
+ externalResourceName(RESOURCE_CLASSES.sns, "InConfirmUsage", EXTERNAL_SERVICE_NAME.accountLimits),
400
+ externalResourceName(RESOURCE_CLASSES.sns, "InReservedDynamicUsage", EXTERNAL_SERVICE_NAME.accountLimits),
401
401
  ]
402
402
  )
403
403
  )
@@ -21,7 +21,7 @@ const fs = require('fs');
21
21
 
22
22
  const { FLOW_SCHEMA_HOOK_STATE } = require('@izara_project/izara-core-library-service-schemas/src/Consts')
23
23
  const { firstLetterUpperCase: upperCase } = require('../../../../../../MainLibs/src/Utils')
24
- const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler } = require("../../../../libs/Consts");
24
+ const { SOURCE_PATH, defaultIamRolePerAction, createIamRole, RESOURCE_CLASSES, SNS_RESOURCE, resourceNames, DYNAMO_RESOURCE, SAVE_FILE_NAME, FUNCTION_NAME, shortNameHandler, externalResourceYaml } = require("../../../../libs/Consts");
25
25
  const templatePath = path.join(__dirname, "template.ejs")
26
26
  const hookTemplate = path.join(__dirname, "./hookTemplate.ejs")
27
27
  /**
@@ -50,7 +50,7 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
50
50
  ]
51
51
  },
52
52
  [
53
- resourceNames(RESOURCE_CLASSES.sns, "*")
53
+ resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
54
54
  ]
55
55
  ),
56
56
  createIamRole(
@@ -81,25 +81,31 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
81
81
 
82
82
  if (flowSchema?.hook) {
83
83
  for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
84
- for (const hookFunction of hookProperties.functionList) {
85
- if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
86
- if (hookFunction?.permission) {
87
- for (const permission of hookFunction.permission) {
88
- if (hookFunction.event?.initialEvent && hookFunction.initialEvent === true)
84
+ if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
85
+ for (const hookFunction of hookProperties.functionList) {
86
+ if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
87
+ if (hookFunction?.permission) {
88
+ for (const permission of hookFunction.permission) {
89
89
  additionalResourcePermission.push(
90
90
  createIamRole(
91
91
  permission.action,
92
- permission.resource,
93
- permission.effect
92
+ permission.resource.map(resource =>
93
+ externalResourceYaml(
94
+ resource.resource,
95
+ resource.resourceName,
96
+ resource.serviceTag),
97
+ permission.effect
98
+ )
94
99
  )
95
100
  )
101
+ }
96
102
  }
97
103
  }
98
104
  }
99
105
  }
100
106
  }
101
107
  }
102
- // console.log("additionalResourcePermission in createObjectS3", additionalResourcePermission)
108
+ // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
103
109
  return {
104
110
  templatePath: templatePath,
105
111
  templateData: {
@@ -39,8 +39,9 @@ function data(_izContext, flowSchema, srcPath) {
39
39
  function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
40
40
  let functionName = upperCase(FUNCTION_NAME.createObjectS3)
41
41
  let handlerType = "HdrWbs"
42
- let hook;
42
+ let hook = false;
43
43
  let hookFunctionName;
44
+ let isAsync = false;
44
45
  if (flowSchema?.hook) {
45
46
  for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
46
47
  for (const hookFunction of hookProperties.functionList) {
@@ -48,18 +49,20 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
48
49
  if (hookFunction.event?.initialEvent && hookFunction.event.initialEvent === true) {
49
50
  hook = true
50
51
  hookFunctionName = hookFunction.name
52
+ if (hookFunction.event?.isAsync && hookFunction.event.isAsync === true) {
53
+ isAsync = true
54
+ }
51
55
  }
52
56
  }
53
57
  }
54
58
  }
55
59
  }
56
-
57
60
  return {
58
61
  templatePath: templatePath,
59
62
  templateData: {
60
- hook: hook ? hook : false,
61
- hookFunctionName: hookFunctionName ? hookFunctionName : null,
62
- // hookSourcePath: hook ? SOURCE_PATH.webSocketHook : {}
63
+ hook: hook,
64
+ hookFunctionName: hookFunctionName,
65
+ isAsync
63
66
  },
64
67
  setting: {
65
68
  savePath: path.join(srcPath, SOURCE_PATH.webSocket),
@@ -29,7 +29,7 @@ const hash = require('object-hash')
29
29
  const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
30
30
  const { postToConnection } = require("../../libs/source/ImportDataLib");
31
31
  <% if (hook) { _%>
32
- const <%- hookFunctionName %> = required("<% hookFunctionName _%>_Main ")
32
+ const <%- upperCase(hookFunctionName) %> = require("./FlowSchemaHook/HookLogicFunction/source/<%- upperCase(hookFunctionName) %>")
33
33
  <% } else { _%>
34
34
  const createObject = require('./CreateObjectS3_Main');
35
35
  <% } _%>
@@ -69,13 +69,23 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
69
69
 
70
70
  let callingFlow = eventParams?.callingFlow ? eventParams.callingFlow : {};
71
71
  <% if (hook) { _%>
72
- await <%- hookFunctionName %>.<%- hookFunctionName %>(
73
- event._izContext,
74
- eventParams,
75
- callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
76
- //(<additionalParams>)
77
- //(</additionalParams>)
78
- )
72
+ <% if (isAsync) { %>
73
+ await <%- upperCase(hookFunctionName) %>(
74
+ event._izContext,
75
+ eventParams,
76
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
77
+ //(<additionalParams>)
78
+ //(</additionalParams>)
79
+ )
80
+ <% } else { %>
81
+ <%- upperCase(hookFunctionName) %>(
82
+ event._izContext,
83
+ eventParams,
84
+ callingFlowSharedLib.addCallingFlowToPassOnProperties(callingFlow)
85
+ //(<additionalParams>)
86
+ //(</additionalParams>)
87
+ )
88
+ <% } _%>
79
89
  <% } else { _%>
80
90
  await createObject.createObject(
81
91
  event._izContext,
@@ -104,4 +114,7 @@ module.exports.main = middleware.wrap(async (event, context, callback) => {
104
114
  return (izara.response.failure(err));
105
115
  }
106
116
  });
107
- <%_ const join = require('path').join _%>
117
+ <%_ const join = require('path').join _%>
118
+ <%_ function upperCase (text) {
119
+ return text.charAt(0).toUpperCase() + text.slice(1)
120
+ } _%>