@izara_project/izara-market-library-service-schemas 1.0.66 → 1.0.68

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 (42) hide show
  1. package/package.json +3 -3
  2. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +13 -1
  3. package/src/MainLibs/src/Consts.js +34 -1
  4. package/src/MainLibs/src/GenerateCodeUtils.js +6 -6
  5. package/src/reStructure/GenerateCode.js +2 -1
  6. package/src/reStructure/TemplateData/EndpointPerService/generateTemplateData.js +1 -1
  7. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +35 -8
  8. package/src/reStructure/TemplateData/EndpointPerService/yaml/data.js +49 -5
  9. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +8 -0
  10. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +14 -0
  11. package/src/reStructure/TemplateData/findData/findDataYaml/data.js +2 -2
  12. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +2 -2
  13. package/src/reStructure/TemplateData/flowSchema/flowStep/functionYaml/data.js +3 -3
  14. package/src/reStructure/TemplateData/flowSchema/flowStep/handler/data.js +1 -1
  15. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/data.js +4 -2
  16. package/src/reStructure/TemplateData/flowSchema/flowStep/sns-in/template.ejs +9 -9
  17. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +24 -24
  18. package/src/reStructure/TemplateData/generateRole/data.js +38 -24
  19. package/src/reStructure/TemplateData/generateRole/template.ejs +5 -7
  20. package/src/reStructure/TemplateData/processLogical/yaml/data.js +3 -3
  21. package/src/reStructure/TemplateData/processLogicalPagination/yaml/dsq/data.js +1 -1
  22. package/src/reStructure/TemplateData/processLogicalPagination/yaml/sqs/data.js +1 -1
  23. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/functionYaml/data.js +29 -25
  24. package/src/reStructure/TemplateData/relationshipPerAction/changeRelationship/action/mainFunction/template.ejs +4 -4
  25. package/src/reStructure/TemplateData/relationshipPerAction/create/action/functionYaml/data.js +37 -29
  26. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/functionYaml/data.js +1 -4
  27. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/functionYaml/data.js +37 -29
  28. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/functionYaml/data.js +1 -4
  29. package/src/reStructure/TemplateData/relationshipPerAction/get/action/functionYaml/data.js +37 -29
  30. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/functionYaml/data.js +1 -4
  31. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/functionYaml/data.js +36 -50
  32. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/apiTemplate.ejs +15 -30
  33. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/dsqTemplate.ejs +15 -30
  34. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/invTemplate.ejs +15 -30
  35. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/handler/templateByHandler/sqsTemplate.ejs +15 -30
  36. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/action/mainFunction/template.ejs +2 -2
  37. package/src/reStructure/TemplateData/relationshipPerAction/moveRelationship/complete/functionYaml/data.js +1 -4
  38. package/src/reStructure/TemplateData/relationshipPerAction/update/action/functionYaml/data.js +30 -27
  39. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/functionYaml/data.js +1 -4
  40. package/src/reStructure/TemplateData/resourceYaml/dynamodb/mainResourcePerObjectSchemaData.js +8 -7
  41. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +36 -30
  42. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-market-library-service-schemas",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "Schemas for Izara Market project",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,11 +24,11 @@
24
24
  "@izara_project/izara-core-library-core": "^1.0.20",
25
25
  "@izara_project/izara-core-library-external-request": "^1.0.20",
26
26
  "@izara_project/izara-core-library-logger": "^1.0.7",
27
- "@izara_project/izara-core-library-service-schemas": "^1.0.90",
27
+ "@izara_project/izara-core-library-service-schemas": "^1.0.95",
28
28
  "@izara_project/izara-core-library-sns": "^1.0.6",
29
29
  "@izara_project/izara-core-library-sqs": "^1.0.4",
30
30
  "@izara_project/izara-shared": "^1.0.126",
31
- "@izara_project/izara-shared-service-schemas": "^1.0.29",
31
+ "@izara_project/izara-shared-service-schemas": "^1.0.31",
32
32
  "@izara_project/izara-shared-core": "^1.0.2",
33
33
  "ejs": "^3.1.10",
34
34
  "js-beautify": "^1.15.4",
@@ -889,7 +889,19 @@ async function createDataDetailsLib(_izContext, objectSchemas, settings = { buck
889
889
  });
890
890
  };
891
891
  };
892
- };
892
+ } else if (storageResources[eachStorageResourceTag].storageType === consts.STORAGE_TYPES.externalTopic) {
893
+ let topicName = storageResources[eachStorageResourceTag].serviceTag + storageResources[eachStorageResourceTag].stage + storageResources[eachStorageResourceTag].topicName
894
+ Object.assign(createDataDetails, {
895
+ [topicName]: {
896
+ storageType: consts.STORAGE_TYPES.externalTopic,
897
+ fieldNames: [keyFieldName],
898
+ accountId: storageResources[eachStorageResourceTag].accountId,
899
+ region: storageResources[eachStorageResourceTag].region,
900
+ serviceTag: storageResources[eachStorageResourceTag].serviceTag,
901
+ stage: storageResources[eachStorageResourceTag].stage
902
+ }
903
+ });
904
+ }
893
905
  };
894
906
  }; // end loop storageResourceTags
895
907
  }; // end loop
@@ -575,6 +575,38 @@ const FLOW_SCHEMA_EVENT_TYPE = {
575
575
  eventBridge: "eventBridge",
576
576
  }
577
577
 
578
+ async function getExternalTopicComponentFromAllObjectSchemas(_izContext, allObjSchemas) {
579
+ const externalTopicComponentSet = new Set();
580
+ for (const objectSchema of allObjSchemas) {
581
+ for (let storageResource of Object.values(objectSchema.storageResources)) {
582
+
583
+ if (storageResource.storageType === STORAGE_TYPES.externalTopic) {
584
+ let uniqueTag = hash({
585
+ accountId: storageResource.accountId,
586
+ region: storageResource.region,
587
+ serviceTag: storageResource.serviceTag,
588
+ stage: storageResource.stage
589
+ })
590
+
591
+ if (!externalTopicComponentSet.has(uniqueTag)) {
592
+ externalTopicComponentSet.add(
593
+ {
594
+ [uniqueTag]: {
595
+ accountId: storageResource.accountId,
596
+ region: storageResource.region,
597
+ serviceTag: storageResource.serviceTag,
598
+ stage: storageResource.stage
599
+ }
600
+ }
601
+ )
602
+ }
603
+ }
604
+ }
605
+ }
606
+ let externalTopicComponents = [...externalTopicComponentSet]
607
+ return externalTopicComponents
608
+ };
609
+
578
610
  module.exports = {
579
611
  STORAGE_TYPES,
580
612
  ACTIONS,
@@ -610,5 +642,6 @@ module.exports = {
610
642
  checkDynamoTypeRelationship,
611
643
  createDynamoDbComponentByLinks,
612
644
  getStorageResourceFromObjectSchemas,
613
- FLOW_SCHEMA_EVENT_TYPE
645
+ FLOW_SCHEMA_EVENT_TYPE,
646
+ getExternalTopicComponentFromAllObjectSchemas
614
647
  }
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
  'use strict';
19
19
 
20
20
  const hash = require('@izara_project/izara-shared-core').objectHash;
21
-
21
+ const { firstLetterUpperCase: upperCase } = require('./Utils')
22
22
 
23
23
  function checkValidTableYaml(_izContext, currentTableSetting, existsTableSetting) {
24
24
  // console.log("checkValidTableYaml", JSON.stringify(currentTableSetting, null, 2), JSON.stringify(existsTableSetting, null, 2))
@@ -31,14 +31,14 @@ function checkValidTableYaml(_izContext, currentTableSetting, existsTableSetting
31
31
 
32
32
  for (let i = 0, length = currentTableSetting.length; i < length; i++) {
33
33
  let dynamoDbYamlSetting = currentTableSetting[i];
34
- console.log("dynamoDbYamlSetting", dynamoDbYamlSetting)
35
- if (existsTableSetting.hasOwnProperty(dynamoDbYamlSetting.templateData.tableName)) {
34
+ // console.log("dynamoDbYamlSetting", dynamoDbYamlSetting)
35
+ if (existsTableSetting.hasOwnProperty(upperCase(dynamoDbYamlSetting.templateData.tableName))) {
36
36
 
37
37
  // exists table
38
- if (hash(existsTableSetting[dynamoDbYamlSetting.templateData.tableName]) === hash(dynamoDbYamlSetting.templateData.attributes.sort())) {
38
+ if (hash(existsTableSetting[upperCase(dynamoDbYamlSetting.templateData.tableName)]) === hash(dynamoDbYamlSetting.templateData.attributes.sort())) {
39
39
  continue;
40
40
  } else {
41
- throw Error(`tableName:${dynamoDbYamlSetting.templateData.tableName} have duplicate setting but not have same setting`)
41
+ throw Error(`tableName:${upperCase(dynamoDbYamlSetting.templateData.tableName)} have duplicate setting but not have same setting`)
42
42
  }
43
43
 
44
44
  } else {
@@ -48,7 +48,7 @@ function checkValidTableYaml(_izContext, currentTableSetting, existsTableSetting
48
48
  Object.assign(
49
49
  existsTableSetting,
50
50
  {
51
- [dynamoDbYamlSetting.templateData.tableName]: dynamoDbYamlSetting.templateData.attributes.sort()
51
+ [upperCase(dynamoDbYamlSetting.templateData.tableName)]: dynamoDbYamlSetting.templateData.attributes.sort()
52
52
  }
53
53
  );
54
54
  }
@@ -84,7 +84,8 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath, settings = {}
84
84
  const functionNameConfigs = functionNameConfigYamlData(_izContext, allCreateSource, saveFilePath);
85
85
  allCreateSource.push(...functionNameConfigs);
86
86
 
87
- const generateRoleData = generateRole(_izContext, allCreateSource, saveFilePath);
87
+ let filterAllCreateSource = allCreateSource.filter((createSource) => createSource.templateData.hasOwnProperty("additionalResourcePermission") && createSource.templateData.hasOwnProperty("roleName"))
88
+ const generateRoleData = generateRole(_izContext, filterAllCreateSource, saveFilePath);
88
89
  allCreateSource.push(...generateRoleData);
89
90
 
90
91
  // ** create Generate-Shared-resource
@@ -60,7 +60,7 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
60
60
  try {
61
61
  const saveFilePath = join(objSchemaPath, `../`);
62
62
  const allObjSchemas = await getAllLocalObjectSchemasWithHierarchy(_izContext, objSchemaPath);
63
-
63
+ console.log("allObjSchemas: ", allObjSchemas.records)
64
64
  const createSourceParams = [];
65
65
 
66
66
  for (const objectSchema of allObjSchemas.records) {
@@ -67,7 +67,8 @@ const PREFIX = {
67
67
  ONE: "one",
68
68
  MANY: "many",
69
69
  CREATE_OBJECT_ASYNC: "createObjectAsync",
70
- CREATE_OBJECT_ASYNC_COMPLETE: "createObjectAsyncComplete"
70
+ CREATE_OBJECT_ASYNC_COMPLETE: "createObjectAsyncComplete",
71
+ CREATE_OBJECT_EXTERNAL_TOPIC: "createObjectExternalTopic"
71
72
  }
72
73
  //-----------------------------------------------------------------------------------------------------------
73
74
 
@@ -204,10 +205,10 @@ module.exports.createMain = async (
204
205
  }
205
206
  } else if (objectSchemas.fieldNames[identifier.fieldName].hasOwnProperty("optionalOnCreate")) {
206
207
  if ((objectSchemas.fieldNames[identifier.fieldName].optionalOnCreate == true)) {
208
+ //(<createOptionalOnCreateIdentifiers>)
209
+ let optionalOnCreateIdentifiers
210
+ //(</createOptionalOnCreateIdentifiers>)
207
211
  Object.assign(
208
- //(<createOptionalOnCreateIdentifiers>)
209
- let optionalOnCreateIdentifiers
210
- //(</createOptionalOnCreateIdentifiers>)
211
212
  requestParams.fieldNames, {
212
213
  [identifier.fieldName]: hash(optionalOnCreateIdentifiers)
213
214
  }
@@ -295,8 +296,9 @@ module.exports.createMain = async (
295
296
 
296
297
  let listOfObjectForCreates = [];
297
298
 
298
- let objInstanceFullForDynamoDb = lodash.cloneDeep(objInstanceFull)
299
- let objInstanceFullForGraph = lodash.cloneDeep(objInstanceFull)
299
+ let objInstanceFullForDynamoDb = lodash.cloneDeep(objInstanceFull);
300
+ let objInstanceFullForGraph = lodash.cloneDeep(objInstanceFull);
301
+ let objInstanceFullForExternalTopic = lodash.cloneDeep(objInstanceFull);
300
302
 
301
303
  if (errorsFound.length == 0) {
302
304
  //(<validateBeforeCreate>)
@@ -312,8 +314,9 @@ module.exports.createMain = async (
312
314
  if (parentObject) {
313
315
  if (createDataDetail.tableName.includes(firstLetterUpperCase(`${parentObject.objectType}Records`))) {
314
316
  Object.assign(
315
- objInstanceFullForDynamoDb.fields,
316
- { [`${parentObject.objectType}HandlerServiceTag`]: process.env.iz_serviceTag })
317
+ objInstanceFullForDynamoDb.fields, {
318
+ [`${parentObject.objectType}HandlerServiceTag`]: process.env.iz_serviceTag
319
+ })
317
320
  }
318
321
  }
319
322
 
@@ -375,6 +378,30 @@ module.exports.createMain = async (
375
378
 
376
379
  _izContext.logger.debug("FIRST", listOfObjectForCreates)
377
380
 
381
+ } else if (createDataDetail.storageType === consts.STORAGE_TYPES.externalTopic) {
382
+ _izContext.logger.debug("::::::externalTopic::::::", { storageTag, createDataDetail });
383
+ //(<beforeSendMessageToExternalTopic>)
384
+ //(</beforeSendMessageToExternalTopic>)
385
+ Object.assign(objInstanceFullForExternalTopic.fields, createObjInstanceFullFieldsByStorageTag(_izContext, storageTag, createDataDetail))
386
+ _izContext.logger.debug("objInstanceFull before send to external topic", objInstanceFullForExternalTopic)
387
+
388
+ allAwaitingStepsId.push(await asyncFlowSharedLib.createAwaitingStepId(
389
+ (hash({
390
+ objType: objType,
391
+ graphServerTag: storageTag,
392
+ identifiers: objInstanceFullForGraph.identifiers,
393
+ callingFlowProperties: callingFlowConfig.callingFlowProperties || {}
394
+ })),
395
+ PREFIX.CREATE_OBJECT_EXTERNAL_TOPIC
396
+ ));
397
+
398
+ let sendToCreateExternalTopic = {
399
+ Message: JSON.stringify(objInstanceFullForExternalTopic),
400
+ TopicArn: `arn:aws:sns:${createDataDetail.region}:${createDataDetail.accountId}:${createDataDetail.serviceTag}_${createDataDetail.stage}_Create_In`
401
+ };
402
+ _izContext.logger.debug("Request params before send to create endpoint:", sendToCreateExternalTopic);
403
+
404
+ await sns.publishAsync(_izContext, sendToCreateExternalTopic)
378
405
  }
379
406
  };
380
407
  _izContext.logger.debug("[1]listOfObjectForCreates:::", listOfObjectForCreates);
@@ -22,6 +22,7 @@ const fs = require('fs');
22
22
  const yaml = require('yaml');
23
23
 
24
24
  const { ACTIONS, HANDLER, STORAGE_TYPES } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
25
+ const hash = require('@izara_project/izara-shared-core').objectHash
25
26
  const {
26
27
  DEFAULT_HANDLER_PER_ACTION,
27
28
  createIamRole,
@@ -82,7 +83,7 @@ async function createParamForCreateSource(_izContext, allObjSchemas, action, han
82
83
  [RESOURCE_CLASSES.dynamoDbTable]: Object.values(DYNAMO_RESOURCE),
83
84
  },
84
85
  storageResourceAllLocalObjectSchemas.resourceDynamoTableName.map(tableName =>
85
- resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
86
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(tableName))
86
87
  )
87
88
  )
88
89
  )
@@ -143,19 +144,44 @@ async function createParamForCreateSource(_izContext, allObjSchemas, action, han
143
144
  const config = yaml.parse(serverlessConfig);
144
145
  const ownServiceTag = config.main_config.iz_serviceTag;
145
146
  let parentTables = [];
147
+ let externalTopicComponents = [];
146
148
  // create lambdaRole for parent dynamo table if able
147
149
  for (const objectSchema of allObjSchemas.records) {
148
- if (objectSchema.hasOwnProperty("extendObjType")) {
149
- for (const storageResource of Object.values(objectSchema.storageResources)) {
150
- if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
150
+ for (const storageResource of Object.values(objectSchema.storageResources)) {
151
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
152
+ if (objectSchema.hasOwnProperty("extendObjType")) {
151
153
  if (storageResource.serviceTag && storageResource.serviceTag !== ownServiceTag) {
152
- parentTables.push({ tableName: storageResource.tableName, serviceTag: storageResource.serviceTag })
154
+ parentTables.push({ tableName: upperCase(storageResource.tableName), serviceTag: upperCase(storageResource.serviceTag) })
153
155
  }
154
156
  }
155
157
  }
158
+
159
+ if (storageResource.storageType === STORAGE_TYPES.externalTopic) {
160
+ let uniqueTag = hash({
161
+ accountId: storageResource.accountId,
162
+ region: storageResource.region,
163
+ serviceTag: storageResource.serviceTag,
164
+ stage: storageResource.stage
165
+ })
166
+
167
+ if (!externalTopicComponents.includes(uniqueTag)) {
168
+ externalTopicComponents.push(
169
+ {
170
+ [uniqueTag]: {
171
+ accountId: storageResource.accountId,
172
+ region: storageResource.region,
173
+ serviceTag: storageResource.serviceTag,
174
+ stage: storageResource.stage
175
+ }
176
+ }
177
+ )
178
+ }
179
+ }
156
180
  }
157
181
  }
158
182
 
183
+
184
+
159
185
  if (parentTables.length > 0) {
160
186
  additionalResourcePermission.push(
161
187
  createIamRole(
@@ -179,6 +205,24 @@ async function createParamForCreateSource(_izContext, allObjSchemas, action, han
179
205
  }
180
206
  }
181
207
 
208
+ if (externalTopicComponents.length > 0) {
209
+ if (action === ACTIONS.create) {
210
+ externalTopicComponents.map(component => {
211
+ for (const [_, compo] of Object.entries(component)) {
212
+ additionalResourcePermission.push(createIamRole(
213
+ {
214
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
215
+ },
216
+ [
217
+ `arn:aws:sns:${compo.region}:${compo.accountId}:${compo.serviceTag}_${compo.stage}_Create_In`
218
+ ]
219
+ ))
220
+ }
221
+ }
222
+ )
223
+ }
224
+ }
225
+
182
226
  return {
183
227
  templatePath: templatePath,
184
228
  templateData: {
@@ -204,6 +204,14 @@ async function externalLambdaIamRoleRelationships(_izContext, allRelSchemas) {
204
204
  graphServiceNamesFromAllRelSchemas.map(graphServiceName =>
205
205
  externalResourceName(RESOURCE_CLASSES.sns, "ChangeRelationshipType_In", graphServiceName)
206
206
  )
207
+ ),
208
+ createIamRole(
209
+ {
210
+ [RESOURCE_CLASSES.sns]: [SNS_RESOURCE.publish]
211
+ },
212
+ graphServiceNamesFromAllRelSchemas.map(graphServiceName =>
213
+ externalResourceName(RESOURCE_CLASSES.sns, "MoveRelationship_In", graphServiceName)
214
+ )
207
215
  )
208
216
  )
209
217
  }
@@ -167,6 +167,17 @@ async function snsSubscriptionDeleteRelationshipComplete(_izContext, allRelSchem
167
167
  }
168
168
  }
169
169
 
170
+ async function snsSubscriptionDeleteRelationshipComplete(_izContext, allRelSchemas) {
171
+ let serviceTag = await getGraphServiceNameFromAllRelSchema(_izContext, allRelSchemas)
172
+
173
+ return {
174
+ serviceTag: serviceTag,
175
+ topicName: TOPIC_NAME_GRAPH_HANDLER.outMoveRelationship,
176
+ sqsEndpoint: TOPIC_NAME_GENERATE_CODE.moveRelationshipComplete
177
+ }
178
+ }
179
+
180
+
170
181
  function snsSubscriptionReservedLimitCompleteForReservedDynamicUsage(_izContext) {
171
182
  let serviceTag = [EXTERNAL_SERVICE_NAME.accountLimits]
172
183
  return {
@@ -186,4 +197,7 @@ function snsSubscriptionConfirmReserved(_izContext) {
186
197
  }
187
198
  }
188
199
 
200
+ async function snsSubScriptionFromExternalTopic(_izContext, allObjectSchemas) {
201
+
202
+ }
189
203
  module.exports = createExternalSnsSubscriptions;
@@ -25,7 +25,7 @@ const { HANDLER, STORAGE_TYPES, ACTIONS } = require('@izara_project/izara-core-l
25
25
  const {
26
26
  firstLetterLowerCase: lowerCase,
27
27
  firstLetterUpperCase: upperCase,
28
- } = require("../../../../MainLibs/index.js").utils;
28
+ } = require("../../../../MainLibs/src/Utils");
29
29
  const {
30
30
  createIamRole,
31
31
  resourceNames,
@@ -65,7 +65,7 @@ async function data(_izContext, objectSchemas, srcPath, settings) {
65
65
  for (let storageResource of Object.values(objectSchema.storageResources)) {
66
66
  if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
67
67
  // add IamRole for dynamodb depend on tableName in storageResources of objectSchema
68
- tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, storageResource.tableName));
68
+ tableForGetItem.push(resourceNames(RESOURCE_CLASSES.dynamoDbTable, upperCase(storageResource.tableName)));
69
69
 
70
70
  } else if (storageResource.storageType === STORAGE_TYPES.graph) {
71
71
  // find graph serviceName from graphServerTag or *GetNodeHdrInv ?
@@ -21,7 +21,7 @@ const path = require("path")
21
21
 
22
22
  const templatePath = path.join(__dirname, '../../resourceYaml/dynamodb/template.ejs')
23
23
  const { SOURCE_PATH, SAVE_FILE_NAME, defaultIamRolePerAction, createIamRole, DYNAMO_RESOURCE, resourceNames, RESOURCE_CLASSES, FUNCTION_NAME, SOURCE_GENERATE_IAM_ROLE } = require('../../../../MainLibs/src/Consts.js')
24
-
24
+ const { firstLetterUpperCase: upperCase } = require('../../../../MainLibs/src/Utils.js')
25
25
  /**
26
26
  * create param of crateSouce for FindData And processLogical
27
27
  *
@@ -84,7 +84,7 @@ const createAwaitingMultipleStepDynamoDbData = (_izContext, flowSchema, allLocal
84
84
  templatePath,
85
85
  templateData: {
86
86
  tableName,
87
- resourceName: tableName,
87
+ resourceName: upperCase(tableName),
88
88
  attributes,
89
89
  },
90
90
  setting: {
@@ -77,7 +77,7 @@ function data(_izContext, flowSchema, srcPath) {
77
77
  function createSourceParams(_izContext, flowTag, flowStep, srcPath) {
78
78
  let functionName = upperCase(flowStep);
79
79
  let handlerType = upperCase(HANDLER.hdrSqs);
80
- let topicIn = upperCase(flowStep);
80
+ let topicIn = `${upperCase(flowTag)}_${upperCase(flowStep)}`;
81
81
  let additionalResourcePermission = defaultIamRolePerAction();
82
82
  additionalResourcePermission.push(
83
83
  createIamRole(
@@ -95,8 +95,8 @@ function createSourceParams(_izContext, flowTag, flowStep, srcPath) {
95
95
  [RESOURCE_CLASSES.sqs]: [SQS_RESOURCE.sendMessage, SQS_RESOURCE.receiveMessage, SQS_RESOURCE.deleteMessage, SQS_RESOURCE.getQueueAttributes, SQS_RESOURCE.deleteMessageBatch, SQS_RESOURCE.getQueueUrl]
96
96
  },
97
97
  [
98
- resourceNames(RESOURCE_CLASSES.sqs, upperCase(flowStep) + upperCase(handlerType)),
99
- resourceNames(RESOURCE_CLASSES.sqs, upperCase(flowStep) + upperCase(handlerType) + "DLQ")
98
+ resourceNames(RESOURCE_CLASSES.sqs, `${upperCase(flowTag)}_${upperCase(flowStep)}` + upperCase(handlerType)),
99
+ resourceNames(RESOURCE_CLASSES.sqs, `${upperCase(flowTag)}_${upperCase(flowStep)}` + upperCase(handlerType) + "DLQ")
100
100
  ]
101
101
  )
102
102
  )
@@ -62,7 +62,7 @@ function data(_izContext, flowSchema, srcPath) {
62
62
  function createParamsForCreateSource(_izContext, flowTag, flowStep, srcPath) {
63
63
  let functionName = upperCase(flowStep)
64
64
  let handlerType = upperCase(HANDLER.hdrSqs)
65
- let queueName = upperCase(flowStep) + handlerType
65
+ let queueName = `${upperCase(flowTag)}_${upperCase(flowStep)}` + handlerType
66
66
  return {
67
67
  templatePath: templatePath,
68
68
  templateData: {
@@ -55,7 +55,8 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
55
55
  for (let i = 2; i < flowSteps.length; i++) {
56
56
  generatedSnsTopicInForFlowSchema.add(
57
57
  {
58
- queueName: upperCase(flowSteps[i])
58
+ queueName: `${upperCase(flowSchema.flowTag)}_${upperCase(flowSteps[i])}`,
59
+ resourceName: upperCase(flowSchema.flowTag) + upperCase(flowSteps[i])
59
60
  }
60
61
  )
61
62
  }
@@ -67,7 +68,8 @@ function createDataForDefaultSnsInSqs(_izContext, flowSchema, srcPath) {
67
68
  for (let i = 2; i < flowSteps.length; i++) {
68
69
  generatedSnsTopicInForFlowSchema.add(
69
70
  {
70
- queueName: upperCase(flowSteps[i])
71
+ queueName: `${upperCase(flowSchema.flowTag)}_${upperCase(flowSteps[i])}`,
72
+ resourceName: upperCase(flowSchema.flowTag) + upperCase(flowSteps[i])
71
73
  }
72
74
  )
73
75
  }
@@ -1,19 +1,19 @@
1
1
  ##===== [Create topic in]
2
- In<%- queueName %>:
2
+ In<%- resourceName %>:
3
3
  Type: AWS::SNS::Topic
4
4
  Properties:
5
5
  DisplayName: "SNS Message in"
6
6
  TopicName: ${self:custom.iz_serviceTag}_${self:custom.iz_stage}_<%- queueName %>
7
7
  ##===== SNS Subscription
8
8
  ##===== [Topic In]
9
- SubscriptionIn<%- queueName %>:
9
+ SubscriptionIn<%- resourceName %>:
10
10
  Type: AWS::SNS::Subscription
11
11
  Properties:
12
- TopicArn: !Ref In<%- queueName %>
12
+ TopicArn: !Ref In<%- resourceName %>
13
13
  Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs"
14
14
  Protocol: "sqs"
15
15
  ##===== [Queue]
16
- <%- queueName %>HdrSqs:
16
+ <%- resourceName %>HdrSqs:
17
17
  Type: "AWS::SQS::Queue"
18
18
  Properties:
19
19
  QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
@@ -21,17 +21,17 @@
21
21
  deadLetterTargetArn:
22
22
  # !GetAtt
23
23
  Fn::GetAtt:
24
- - <%- queueName %>HdrSqsDLQ
24
+ - <%- resourceName %>HdrSqsDLQ
25
25
  - Arn
26
26
  maxReceiveCount: 3
27
27
  VisibilityTimeout: 120
28
28
  ##==== [QueueDLQ]
29
- <%- queueName %>HdrSqsDLQ:
29
+ <%- resourceName %>HdrSqsDLQ:
30
30
  Type: AWS::SQS::Queue
31
31
  Properties:
32
32
  QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
33
33
  ##==== [QueuePolicy]
34
- <%- queueName %>HdrSqsPolicy:
34
+ <%- resourceName %>HdrSqsPolicy:
35
35
  Type: AWS::SQS::QueuePolicy
36
36
  Properties:
37
37
  PolicyDocument:
@@ -43,11 +43,11 @@
43
43
  Resource:
44
44
  # !GetAtt
45
45
  Fn::GetAtt:
46
- - <%- queueName %>HdrSqs
46
+ - <%- resourceName %>HdrSqs
47
47
  - Arn
48
48
  Action: "SQS:SendMessage"
49
49
  Queues:
50
- - Ref: <%- queueName %>HdrSqs
50
+ - Ref: <%- resourceName %>HdrSqs
51
51
  #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
52
52
  #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
53
53
 
@@ -386,30 +386,30 @@ async function generateCodeWithTemplate(_izContext, objSchemaPath) {
386
386
  }
387
387
 
388
388
  // statusType enum [storedCache, statusField]
389
- if (flowSchema.statusType === "storedCache") {
390
- const flowSchemaDynamoDb = createAwaitingMultipleStepDynamoDbData(_izContext, flowSchema, allLocalObjectSchemas, saveFilePath)
391
- console.log("generated code storedCache flowSchema")
392
- createSourceParams.push(...flowSchemaDynamoDb);
393
- } else if (flowSchema.statusType === "statusField") {
394
- // wait
395
-
396
-
397
- // if (flowSchema.statusType === "statusField") {
398
- // const createRecordCompleteFunctionYaml = createCreateObjectCompleteFuntionYaml(_izContext, flowSchema, saveFilePath);
399
- // const createRecordCompleteHandler = createCreateObjectCompleteHandler(_izContext, flowSchema, saveFilePath);
400
- // const createRecordCompleteMainFunction = createCreateObjectCompleteMainFunction(_izContext, flowSchema, saveFilePath);
401
- // const createRecordCompleteQueue = createCreateObjectCompleteQueue(_izContext, flowSchema, saveFilePath);
402
-
403
- // const recordCompleteResources = [
404
- // ...createRecordCompleteFunctionYaml,
405
- // ...createRecordCompleteHandler,
406
- // ...createRecordCompleteMainFunction,
407
- // ...createRecordCompleteQueue
408
- // ];
409
- // console.log("generated Code createRecordComplete")
410
- // createSourceParams.push(...recordCompleteResources);
411
- // }
412
- }
389
+ // if (flowSchema.statusType === "storedCache") {
390
+ // const flowSchemaDynamoDb = createAwaitingMultipleStepDynamoDbData(_izContext, flowSchema, allLocalObjectSchemas, saveFilePath)
391
+ // console.log("generated code storedCache flowSchema")
392
+ // createSourceParams.push(...flowSchemaDynamoDb);
393
+ // } else if (flowSchema.statusType === "statusField") {
394
+ // wait
395
+
396
+
397
+ // if (flowSchema.statusType === "statusField") {
398
+ // const createRecordCompleteFunctionYaml = createCreateObjectCompleteFuntionYaml(_izContext, flowSchema, saveFilePath);
399
+ // const createRecordCompleteHandler = createCreateObjectCompleteHandler(_izContext, flowSchema, saveFilePath);
400
+ // const createRecordCompleteMainFunction = createCreateObjectCompleteMainFunction(_izContext, flowSchema, saveFilePath);
401
+ // const createRecordCompleteQueue = createCreateObjectCompleteQueue(_izContext, flowSchema, saveFilePath);
402
+
403
+ // const recordCompleteResources = [
404
+ // ...createRecordCompleteFunctionYaml,
405
+ // ...createRecordCompleteHandler,
406
+ // ...createRecordCompleteMainFunction,
407
+ // ...createRecordCompleteQueue
408
+ // ];
409
+ // console.log("generated Code createRecordComplete")
410
+ // createSourceParams.push(...recordCompleteResources);
411
+ // }
412
+ // }
413
413
  const flowSchemaFlowStepYml = createFlowSchemaFlowStepFunctionYaml(_izContext, flowSchema, saveFilePath);
414
414
  const flowSchemaFlowStepHandler = createFlowSchemaFlowStepHandler(_izContext, flowSchema, saveFilePath);
415
415
  const flowSchemaFlowStepMainFunction = createFlowSchemaFlowStepMainFunction(_izContext, flowSchema, saveFilePath);
@@ -21,36 +21,50 @@ const templatePath = path.join(__dirname, "./template.ejs")
21
21
 
22
22
  function generateRole(_izContext, createSourceParams, srcPath) {
23
23
  // console.log("createSourceParams", createSourceParams);
24
- let reformCreateSourceParams = {};
25
- let createSourceRole = [];
24
+ let createSourceRole = new Set();
25
+ const reformCreateSourceParams = {};
26
+
26
27
  for (const createSource of createSourceParams) {
27
- const { roleName, additionalResourcePermission } = createSource.templateData
28
- if (additionalResourcePermission && roleName) {
29
- if (!reformCreateSourceParams[roleName]) {
30
- reformCreateSourceParams[roleName] = {
31
- resourcePermissions: [...additionalResourcePermission]
32
- };
33
- } else {
34
- let resourcePermission = reformCreateSourceParams[roleName].resourcePermissions
35
- let mergeResource = [...resourcePermission, ...additionalResourcePermission]
28
+ const { roleName, additionalResourcePermission } = createSource.templateData;
36
29
 
37
- const seen = new Set();
38
- const unique = [];
30
+ if (!roleName || !additionalResourcePermission) continue;
39
31
 
40
- for (const permission of mergeResource) {
41
- const key = JSON.stringify(permission);
42
- if (!seen.has(key)) {
43
- seen.add(key);
44
- unique.push(permission);
45
- }
46
- }
47
- reformCreateSourceParams[roleName].resourcePermissions = unique;
32
+ if (!reformCreateSourceParams[roleName]) {
33
+ reformCreateSourceParams[roleName] = { resourcePermissions: [] };
34
+ }
35
+
36
+ const rolePermissions = reformCreateSourceParams[roleName].resourcePermissions;
37
+
38
+ for (const newPerm of additionalResourcePermission) {
39
+ const normalizedActions = Object.entries(newPerm.action)
40
+ .flatMap(([service, actions]) => actions.map(action => `${service}:${action}`))
41
+ .sort();
42
+
43
+ const effect = newPerm.effect;
44
+ const resources = [...new Set(newPerm.resource)];
45
+
46
+ const existing = rolePermissions.find(
47
+ permission =>
48
+ permission.effect === effect &&
49
+ JSON.stringify([...permission.action].sort()) === JSON.stringify(normalizedActions)
50
+ );
51
+
52
+ if (existing) {
53
+ // Merge resources (deduplicate with Set)
54
+ existing.resource = Array.from(new Set([...existing.resource, ...resources]));
55
+ } else {
56
+ // Push new permission
57
+ rolePermissions.push({
58
+ effect: effect,
59
+ action: normalizedActions,
60
+ resource: resources
61
+ });
48
62
  }
49
63
  }
50
64
  }
65
+ // console.log({ reformCreateSourceParams: JSON.stringify(reformCreateSourceParams, null, 2) })
51
66
  for (const [roleName, roleData] of Object.entries(reformCreateSourceParams)) {
52
-
53
- createSourceRole.push(
67
+ createSourceRole.add(
54
68
  {
55
69
  templatePath: templatePath,
56
70
  templateData: { roleName, roleData },
@@ -71,4 +85,4 @@ function generateRole(_izContext, createSourceParams, srcPath) {
71
85
 
72
86
  module.exports = {
73
87
  generateRole
74
- }
88
+ }