@izara_project/izara-market-library-service-schemas 1.0.35 → 1.0.36

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 (111) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +2 -1
  3. package/src/MainLibs/src/Consts.js +8 -8
  4. package/src/MainLibs/src/GenerateCodeUtils.js +2 -0
  5. package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/generateTemplateData.js +35 -20
  6. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/data.js +84 -0
  7. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/tempReferenceRelationshipSchema.ejs +9 -0
  8. package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/relationshipSchema/data.js +1 -1
  9. package/src/reStructure/SchemaConfig.js +1 -4
  10. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +701 -0
  11. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +34 -162
  12. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -0
  13. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +3 -4
  14. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +2 -0
  15. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +38 -12
  16. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +5 -2
  17. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -14
  18. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +4 -1
  19. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +68 -33
  20. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  21. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  22. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -1
  23. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +12 -4
  24. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +13 -8
  25. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +16 -13
  26. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +9 -9
  27. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +1 -1
  28. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +7 -9
  29. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/dynamoDB/register.js +82 -0
  30. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +1 -1
  31. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +34 -1
  32. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +10 -33
  33. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +5 -5
  34. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +6 -6
  35. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +26 -4
  36. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +5 -5
  37. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +7 -8
  38. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +118 -16
  39. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +83 -44
  40. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +4 -5
  41. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -7
  42. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +2 -3
  43. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +2 -4
  44. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +31 -3
  45. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +4 -4
  46. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +7 -8
  47. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +13 -13
  48. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +4 -4
  49. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +44 -69
  50. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +4 -6
  51. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +2 -2
  52. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +2 -9
  53. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +40 -87
  54. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +5 -4
  55. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +2 -10
  56. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +17 -3
  57. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +2 -2
  58. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +6 -2
  59. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +49 -84
  60. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +55 -10
  61. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -1
  62. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +2 -2
  63. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +1 -1
  64. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +20 -7
  65. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +24 -33
  66. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +20 -5
  67. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +1 -3
  68. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +2 -2
  69. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +5 -5
  70. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/data.js +5 -3
  71. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +7 -5
  72. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +6 -3
  73. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -2
  74. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/data.js +2 -2
  75. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +3 -3
  76. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +8 -3
  77. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +17 -11
  78. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +14 -8
  79. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +4 -1
  80. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +50 -42
  81. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +3 -2
  82. package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +3 -0
  83. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +9 -8
  84. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +5 -1
  85. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +2 -1
  86. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +1 -0
  87. package/src/reStructure/TemplateData/{propertyNodeSchema → propertyValueSchema}/generateTemplateData.js +4 -4
  88. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +131 -0
  89. package/src/reStructure/TemplateData/{propertyNodeSchema/relationshipPropertyNodeSchema → propertyValueSchema/relationshipPropertyValueSchema}/data.js +32 -55
  90. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/tempRelationship.ejs +13 -0
  91. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/templateRelationshipPropertyValueSchema.ejs +7 -0
  92. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +2 -1
  93. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +2 -1
  94. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +2 -1
  95. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/handler/sqs/template.ejs +5 -5
  96. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -4
  97. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -1
  98. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +4 -4
  99. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +4 -3
  100. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +2 -1
  101. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +2 -1
  102. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -3
  103. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +61 -0
  104. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +13 -4
  105. package/src/reStructure/TemplateData/propertyNodeSchema/objectPropertyNodeSchema/data.js +0 -151
  106. package/src/reStructure/TemplateData/propertyNodeSchema/relationshipPropertyNodeSchema/templateRelationshipPropertyNodeSchema.ejs +0 -7
  107. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/attributeLinkTemplate.ejs +0 -0
  108. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/data.js +0 -0
  109. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/mainAttributeTree/request.json +0 -0
  110. /package/src/{reStructure/TemplateData → TemplateManager/src}/attributeTreeSchema/relationshipSchema/template.ejs +0 -0
  111. /package/src/reStructure/TemplateData/{propertyNodeSchema/objectPropertyNodeSchema/templateObjectPropertyNodeSchema.ejs → propertyValueSchema/objectPropertyValueSchema/templateObjectPropertyValueSchema.ejs} +0 -0
@@ -33,7 +33,7 @@ const sns = externalRequest.sns
33
33
  const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
34
34
  const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
35
35
  const { v4: uuidv4 } = require('uuid')
36
- const coreConsts = require("@izara_project/izara-core-library-core/src/Consts");
36
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
37
37
  const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
38
38
  /**
39
39
  *
@@ -68,7 +68,7 @@ module.exports.<%- functionMain%> = async (
68
68
  // receive flowTag and identifiers
69
69
  let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
70
70
  flowTag: requestParams.flowTag,
71
- serviceTag: requestParams.serviceTag,
71
+ serviceTag: process.env.iz_serviceTag,
72
72
  })
73
73
 
74
74
  _izContext.logger.debug("flowSchema", flowSchema)
@@ -76,13 +76,80 @@ module.exports.<%- functionMain%> = async (
76
76
  throw new NoRetryError(`flowTag not found ${requestParams.flowTag}`)
77
77
  }
78
78
 
79
+ // get data from dynamoDB of objectType of flowSchema
80
+ const getStoredCache = async (objectType) => {
81
+ const objectSchema = await getObjectSchema.getObjSchemaS3WithCache(
82
+ _izContext,
83
+ {
84
+ objectType: objectType,
85
+ serviceTag: process.env.iz_serviceTag,
86
+ })
87
+
88
+ _izContext.logger.debug("==> objectSchema", objectSchema)
89
+
90
+ // this returns the table name of the first storage resource with storageType "dynamoDB"
91
+ const tableName = Object.values(objectSchema.storageResources).find(
92
+ (storageResource) => storageResource.storageType === "dynamoDB"
93
+ )?.tableName
94
+ _izContext.logger.debug("==> tableName", tableName)
95
+
96
+ // const identifierPK = objectSchema[identifierPK].find(
97
+ // (identifier) => identifier.type === "partitionKey"
98
+ // )?.fieldName
99
+
100
+ // const identifierSK = objectSchema[identifierSK].find(
101
+ // (identifier) => identifier.type === "sortKey"
102
+ // )?.fieldName
103
+
104
+ let identifierPK = null
105
+ let identifierSK = null
106
+ objectSchema.identifiers.map((identifier) => {
107
+ if (identifier.type === "partitionKey") {
108
+ identifierPK = identifier.fieldName
109
+ } else if (identifier.type === "sortKey") {
110
+ identifierSK = identifier.fieldName
111
+ }
112
+ })
113
+
114
+ _izContext.logger.debug("==> identifierPK", identifierPK)
115
+ _izContext.logger.debug("==> identifierSK", identifierSK)
116
+
117
+ const payloadGetStoredCache = {
118
+ [identifierPK]: requestParams.identifiers[identifierPK],
119
+ }
120
+ if (identifierSK) {
121
+ payloadGetStoredCache[identifierSK] = requestParams.identifiers[identifierSK]
122
+ }
123
+
124
+ _izContext.logger.debug("==> payloadGetStoredCache", payloadGetStoredCache)
125
+
126
+ // const getStoredCache = await dynamodbSharedLib.getItem(
127
+ // _izContext,
128
+ // await dynamodbSharedLib.tableName(_izContext, tableName),
129
+ // payloadGetStoredCache
130
+ // )
131
+
132
+ const getStoredCache = await dynamodbSharedLib.query(
133
+ _izContext,
134
+ await dynamodbSharedLib.tableName(_izContext, tableName),
135
+ payloadGetStoredCache
136
+ )
137
+ _izContext.logger.debug("==> getStoredCache:::", getStoredCache)
138
+ return ({
139
+ data: getStoredCache.Items[0],
140
+ identifierPK: identifierPK,
141
+ })
142
+ }
143
+
144
+ // Initialize storedCacheData variable that will be used in multiple switch cases
145
+ let storedCacheData = null;
79
146
  switch (flowSchema.statusType) {
80
147
  case "statusField":
81
- let payload = {
148
+ const payload = {
82
149
  identifiers: requestParams.identifiers,
83
150
  objectType: flowSchema.objType.objectType
84
151
  }
85
- let result = await externalRequest.lambda.invokeSync(
152
+ const result = await externalRequest.lambda.invokeSync(
86
153
  _izContext,
87
154
  await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv", flowSchema.objType.serviceTag),
88
155
  payload
@@ -91,23 +158,58 @@ module.exports.<%- functionMain%> = async (
91
158
  throw new NoRetryError(`statusField not found ${requestParams.identifiers}`)
92
159
  }
93
160
  return result
94
- case "storedCache":
161
+
162
+
163
+ case "storedCache":
95
164
  // if statusType=storedCache then query storedCache > post message to client -> remove connectionId if status = error || complete
96
- const getStoredCache = await dynamodbSharedLib.getItem(
97
- _izContext,
98
- await dynamodbSharedLib.tableName(_izContext, flowSchema.flowTag + "Main"),
99
- {
100
- taskKey: requestParams.identifiers,
101
- connectionId: requestParams.connectionId
165
+
166
+ storedCacheData = await getStoredCache(flowSchema.objType.objectType)
167
+ _izContext.logger.debug("==> storedCacheData", storedCacheData)
168
+
169
+ if (!storedCacheData) {
170
+ throw new NoRetryError(`storedCache not found ${requestParams.identifiers} ${requestParams.sortKey}`)
171
+ }
172
+ let payloadPostMessage = {
173
+ identifierTask: requestParams.identifiers[storedCacheData.identifierPK],
174
+ connectionId: _izContext.correlationIds.get(consts.CONNECTION_ID),
175
+ flowType: {
176
+ flowTag: flowSchema.flowTag,
177
+ serviceTag: process.env.iz_serviceTag,
102
178
  }
103
- )
104
- if (!getStoredCache) {
105
- throw new NoRetryError(`storedCache not found ${requestParams.identifiers}`)
106
179
  }
107
- return getStoredCache
180
+
181
+ _izContext.logger.debug('==> payloadPostMessage', payloadPostMessage)
182
+ if (storedCacheData.data.cacheStatus !== "error" && storedCacheData.data.cacheStatus != "complete") {
183
+ await dynamodbSharedLib.putItem(
184
+ _izContext,
185
+ await dynamodbSharedLib.tableName(_izContext, "FlowTagRegisterRecords"),
186
+ payloadPostMessage
187
+ )
188
+
189
+ return payloadPostMessage;
190
+ } else {
191
+ await dynamodbSharedLib.deleteItem(
192
+ _izContext,
193
+ await dynamodbSharedLib.tableName(_izContext, "FlowTagRegisterRecords"),
194
+ {
195
+ identifierTask: requestParams.identifiers[storedCacheData.identifierPK],
196
+ connectionId: _izContext.correlationIds.get(consts.CONNECTION_ID)
197
+ }
198
+ )
199
+ }
200
+
201
+ return storedCacheData;
202
+
108
203
  case "none":
109
204
  // if statusType=none -> post message to client ---- not remove connectionId when post message, can remove connectionId when cannot use connectionId only(user disconnect)
110
- break
205
+ storedCacheData = await getStoredCache(flowSchema.objType.objectType)
206
+
207
+ _izContext.logger.debug("==> objectSchema", storedCacheData)
208
+ if (!storedCacheData) {
209
+ throw new NoRetryError(`none not found ${requestParams.identifiers}`)
210
+ }
211
+ return storedCacheData
212
+
111
213
  default:
112
214
  throw new NoRetryError(`statusType not found ${flowSchema.statusType}`)
113
215
  }
@@ -19,18 +19,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19
19
 
20
20
  const path = require("path")
21
21
 
22
-
23
- // const {
24
- // HANDLER,
25
- // STORAGE_TYPES
26
- // } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
27
-
28
- const STORAGE_TYPES = {
29
- dynamoDB: "dynamoDB",
30
- graph: "graph"
31
- }
32
22
  const templatePath = path.join(__dirname, '../../resourceYaml/dynamodb/template.ejs')
33
- const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../MainLibs/src/Consts.js')
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')
34
24
 
35
25
  /**
36
26
  * create param of crateSouce for FindData And processLogical
@@ -39,43 +29,92 @@ const { SOURCE_PATH, SAVE_FILE_NAME } = require('../../../../MainLibs/src/Consts
39
29
  * @param {String} srcPath
40
30
  * @returns {Object[]}
41
31
  */
42
- const createAwaitingMultipleStepDynamoDbData = (_izContext, flowSchema, srcPath) => {
32
+ const createAwaitingMultipleStepDynamoDbData = (_izContext, flowSchema, allLocalObjectSchemas, srcPath) => {
33
+ if (!flowSchema.event.includes("ownTopic")) {
34
+ return [];
35
+ }
43
36
 
44
- let resultsForCreateSource = [];
45
- const defaultDynamoDataLists = [];
37
+ const objectSchema = allLocalObjectSchemas.records.find(schema =>
38
+ schema.objectType === flowSchema.objType.objectType);
46
39
 
47
- if (flowSchema.statusType === "storedCache") {
48
- defaultDynamoDataLists.push(
49
- {
50
- tableName: flowSchema.flowTag + "Main",
51
- resourceName: flowSchema.flowTag + "Main",
52
- attributes: [
53
- {
54
- keyType: "partitionKey",
55
- AttributeName: flowSchema.flowTag + "Id",
56
- AttributeType: "S"
57
- }
58
- ]
59
- }
60
- )
40
+ if (!objectSchema) {
41
+ return [];
42
+ }
43
+
44
+ if (!objectSchema.storageResources) {
45
+ return [];
46
+ }
47
+
48
+ // ex.
49
+ // storageResources: {
50
+ // cacheTable: {
51
+ // storageType: "dynamoDB",
52
+ // tableName: "TranslateIdsCacheMain"
53
+ // }
54
+ // }
55
+
56
+ // Check if there's exactly one DynamoDB storage resource
57
+ const dynamoDbEntries = Object.entries(objectSchema.storageResources)
58
+ .filter(([_, value]) => value.storageType === "dynamoDB");
59
+
60
+ console.debug(`DynamoDB entries: ${JSON.stringify(dynamoDbEntries)}`);
61
+
62
+ if (dynamoDbEntries.length !== 1) {
63
+ console.warn(`Object schema ${objectSchema.objectType} for ${flowSchema.flowTag} needs to have exactly one DynamoDB storage resource.`);
64
+ return []; // Either no DynamoDB storage or more than one found
61
65
  }
62
66
 
63
- for (let defaultDynamoData of defaultDynamoDataLists) {
64
- resultsForCreateSource.push({
65
- templatePath: templatePath,
66
- templateData: defaultDynamoData,
67
- setting: {
68
- initialData: 'Resources:\n',
69
- savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
70
- saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
71
- fileExtension: '.yml',
72
- isAppend: true
73
- }
74
- });
67
+ const storageResourceEntry = dynamoDbEntries[0];
68
+
69
+ if (!storageResourceEntry) {
70
+ return [];
75
71
  }
76
- // console.log("resultsForCreateSource default dynamo", resultsForCreateSource)
77
72
 
78
- return resultsForCreateSource;
79
- }
73
+ const [_, storageResource] = storageResourceEntry;
74
+ const tableName = storageResource.tableName;
75
+
76
+ const attributes = objectSchema.identifiers
77
+ .map(identifier => ({
78
+ keyType: identifier.type,
79
+ AttributeName: identifier.fieldName,
80
+ AttributeType: "S"
81
+ }));
82
+
83
+ let additionalResourcePermission = defaultIamRolePerAction();
84
+ additionalResourcePermission.push(
85
+ createIamRole(
86
+ {
87
+ [RESOURCE_CLASSES.dynamoDbTable]: [
88
+ DYNAMO_RESOURCE.putItem,
89
+ DYNAMO_RESOURCE.getItem,
90
+ DYNAMO_RESOURCE.query,
91
+ DYNAMO_RESOURCE.deleteItem,
92
+ DYNAMO_RESOURCE.updateItem
93
+ ]
94
+ },
95
+ [
96
+ resourceNames(RESOURCE_CLASSES.dynamoDbTable, tableName)
97
+ ]
98
+ )
99
+ );
100
+
101
+ return [{
102
+ templatePath,
103
+ templateData: {
104
+ tableName,
105
+ resourceName: tableName,
106
+ attributes,
107
+ additionalResourcePermission,
108
+ roleName: SOURCE_GENERATE_IAM_ROLE.RegisterRole,
109
+ },
110
+ setting: {
111
+ initialData: 'Resources:\n',
112
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
113
+ saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
114
+ fileExtension: '.yml',
115
+ isAppend: true
116
+ }
117
+ }];
118
+ };
80
119
 
81
- module.exports = createAwaitingMultipleStepDynamoDbData
120
+ module.exports = createAwaitingMultipleStepDynamoDbData;
@@ -32,6 +32,7 @@ const {
32
32
  FUNCTION_NAME,
33
33
  SAVE_FILE_NAME,
34
34
  SOURCE_GENERATE_IAM_ROLE,
35
+ HANDLER,
35
36
  } = require("../../../../../MainLibs/src/Consts");
36
37
 
37
38
  /**
@@ -45,17 +46,15 @@ const {
45
46
  */
46
47
 
47
48
  function data(_izContext, flowSchema, srcPath) {
48
- const flowStepSplitKey = Object.keys(flowSchema.flowSteps)[0].split("_");
49
+ const flowStepSplitKeyOut = Object.keys(flowSchema.flowSteps)[1].split("_");
49
50
  // console.log({ flowStepSplitKey })
50
- let queueName = flowStepSplitKey[3] + 'Out';
51
- let queueNameSubscription = flowStepSplitKey[3];
52
-
51
+ let queueName = upperCase(flowSchema.flowTag) + "ExternalTopicOut" + upperCase(HANDLER.hdrSqs)
53
52
  return [{
54
53
  templatePath,
55
54
  templateData: {
56
55
  queueName: upperCase(queueName),
57
- queueNameSubscription: upperCase(queueNameSubscription),
58
56
  roleName: SOURCE_GENERATE_IAM_ROLE.ExternalTopicRole,
57
+ firstLetterUpperCase: upperCase
59
58
  },
60
59
  setting: {
61
60
  initialData: "Resource\n",
@@ -1,10 +1,4 @@
1
- ##===== SNS Subscription
2
- SubscriptionOut<%- queueNameSubscription %>:
3
- Type: AWS::SNS::Subscription
4
- Properties:
5
- TopicArn: !Ref Out<%- queueNameSubscription %>
6
- Endpoint: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- queueNameSubscription %>Out"
7
- Protocol: "sqs"
1
+ ##===== ExternalTopic
8
2
  ##===== [Queue]
9
3
  <%- queueName %>:
10
4
  Type: "AWS::SQS::Queue"
@@ -33,7 +33,7 @@ const {
33
33
  SOURCE_GENERATE_IAM_ROLE
34
34
  } = require("../../../../../MainLibs/src/Consts");
35
35
 
36
- const templatePath = path.join(__dirname, "../../../../TemplateData/resourceYaml/sns-out/template.ejs");
36
+ const templatePath = path.join(__dirname, "./template.ejs");
37
37
  // /ResourceYaml/sns-out/template.ejs
38
38
  // /OutPerActionComplete/OutUpdateComplete/sns-out/data.js
39
39
 
@@ -52,8 +52,7 @@ function data(_izContext, flowSchema, srcPath) {
52
52
  }
53
53
 
54
54
  function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
55
- const flowStepSplitKey = Object.keys(flowSchema.flowSteps)[1].split('_');
56
- const queueName = flowStepSplitKey[3]
55
+ const queueName = upperCase(flowSchema.flowTag)
57
56
  return [
58
57
  {
59
58
  templatePath: templatePath,
@@ -3,8 +3,6 @@
3
3
  Type: AWS::SNS::Topic
4
4
  Properties:
5
5
  DisplayName: "SNS Message out"
6
- TopicName: ${self:custom.iz_serviceTag}_${self:custom.iz_stage}_<%- firstLetterUpperCase(queueName) %>_Out
6
+ TopicName: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(queueName) %>
7
7
 
8
- <%_ function firstLetterUpperCase(text) {
9
- return text.charAt(0).toUpperCase() + text.slice(1)
10
- } _%>
8
+ <%_ function firstLetterUpperCase(text) { return text.charAt(0).toUpperCase() + text.slice(1) } _%>
@@ -33,7 +33,8 @@ const {
33
33
  FUNCTION_NAME,
34
34
  shortNameHandler,
35
35
  externalResourceYaml,
36
- SOURCE_GENERATE_IAM_ROLE
36
+ SOURCE_GENERATE_IAM_ROLE,
37
+ SQS_RESOURCE
37
38
  } = require("../../../../../../MainLibs/src/Consts");
38
39
 
39
40
  const templatePath = path.join(__dirname, "template.ejs");
@@ -55,13 +56,40 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
55
56
  let externalTopicName = FUNCTION_NAME.flowSchemaExternalTopic + 'Out';
56
57
  let functionConfig = "ExtTopicOut" + upperCase(shortNameHandler(handlerType));
57
58
  let additionalResourcePermission = defaultIamRolePerAction();
59
+ let flowStepInSplitKey = Object.keys(flowSchema.flowSteps)[0].split("_");
58
60
  // const action = flowSchema.flowTag || 'defaultAction'; // Using flowTag as the action name
59
61
  // const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(action) + upperCase(handler));
60
-
62
+ additionalResourcePermission.push(
63
+ createIamRole(
64
+ {
65
+ [RESOURCE_CLASSES.sqs]: [
66
+ SQS_RESOURCE.getQueueAttributes,
67
+ SQS_RESOURCE.receiveMessage,
68
+ SQS_RESOURCE.deleteMessage,
69
+ ]
70
+ },
71
+ [
72
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType),
73
+ resourceNames(RESOURCE_CLASSES.sqs, functionName + handlerType + "DLQ"),
74
+ // resourceNames(RESOURCE_CLASSES.sqs, functionName + "Out"),
75
+ // resourceNames(RESOURCE_CLASSES.sqs, functionName + "OutDLQ"),
76
+ ]
77
+ ),
78
+ // createIamRole(
79
+ // {
80
+ // [RESOURCE_CLASSES.sns]: [
81
+ // SNS_RESOURCE.publish,
82
+ // ]
83
+ // },
84
+ // [
85
+ // resourceNames(RESOURCE_CLASSES.sns, flowStepInSplitKey[2] + flowStepInSplitKey[3]),
86
+ // ]
87
+ // )
88
+ );
61
89
  return {
62
90
  templatePath: templatePath,
63
91
  templateData: {
64
- resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaExternalTopic, flowSchema.flowTag, "source/"),
92
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchema, flowSchema.flowTag, "source/"),
65
93
  functionName,
66
94
  handlerType,
67
95
  functionNameConfig: functionConfig,
@@ -1,14 +1,14 @@
1
1
  <%_ const join = require('path').join _%>
2
2
  <%- firstLetterUpperCase(functionNameConfig) %>:
3
- handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`) %>
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}Out_${firstLetterUpperCase(handlerType)}.main`) %>
4
4
  name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
5
5
  events:
6
6
  - sqs:
7
- arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %>
7
+ arn: arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) + firstLetterUpperCase(handlerType) %>
8
8
  batchSize: 10
9
9
  role: <%- firstLetterUpperCase(roleName) _%>Role
10
- #<#<%_ functionName _%><%_ handlerType _%>IamRole#>
11
- #<#/<%_ functionName _%><%_ handlerType _%>IamRole#>
10
+ #<#<%- functionName %><%- handlerType %>IamRole#>
11
+ #<#/<%- functionName %><%- handlerType %>IamRole#>
12
12
  <%_ function firstLetterUpperCase(text){
13
13
  return text.charAt(0).toUpperCase() + text.slice(1)
14
14
  } _%>
@@ -41,22 +41,21 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
41
41
  _izContext.logger.error(`flowStepInSplitKey.length < 4: ${flowStepInSplitKey.length} ${flowSchema.flowTag}`);
42
42
  return null;
43
43
  }
44
- const ExternalTopicName = FUNCTION_NAME.flowSchemaExternalTopic + 'Out';
45
- let queueName = (flowStepInSplitKey[2]) + (flowStepInSplitKey[3]) + 'Out';
46
- let functionName = upperCase(FUNCTION_NAME.flowSchemaExternalTopic)
44
+ let functionName = upperCase(flowSchema.flowTag) + "ExternalTopicOut"
47
45
  let handlerType = upperCase(HANDLER.hdrSqs);
48
46
  return {
49
47
  templatePath: templatePath,
50
48
  templateData: {
51
- queueName,
52
- fileName: ExternalTopicName + 'Out_Main',
53
- functionMain: ExternalTopicName + 'Out',
49
+ queueName: functionName + handlerType,
50
+ fileName: functionName + '_Main',
51
+ functionMain: functionName + 'Main',
54
52
  handler: HANDLER.hdrSqs,
55
53
  firstLetterUpperCase: upperCase,
54
+ functionName
56
55
  },
57
56
  setting: {
58
- savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag, 'source/'),
59
- saveFileName: `${functionName}Out_${handlerType}`,
57
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, flowSchema.flowTag, 'source/'),
58
+ saveFileName: `${functionName}_${handlerType}`,
60
59
  fileExtension: ".js",
61
60
  isAppend: false
62
61
  }
@@ -29,7 +29,7 @@ const { <%- functionMain %> } =require('./<%- firstLetterUpperCase(fileName) %>.
29
29
  // validate event properties in body.Message of sqs event
30
30
  middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
31
31
  // set schema for record.body.Message
32
- // const perRecordsValidatorSchema = {
32
+ const perRecordsValidatorSchema = {}
33
33
  // type: "object",
34
34
  // required: ['param1', 'param2', 'param3', 'param4',],
35
35
  // properties: {
@@ -63,18 +63,18 @@ middlewareHandler.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema(
63
63
  // };
64
64
 
65
65
  // set schema for record.body.MessageAttributes
66
- const messageAttributeValidatorSchema = {
67
- type: "object",
68
- required: ['msgAtrrParam1', 'msgAtrrParam2'],
69
- properties: {
70
- msgAtrrParam1: {
71
- type: "string"
72
- },
73
- msgAtrrParam2: {
74
- type: "object"
75
- }
76
- }
77
- };
66
+ // const messageAttributeValidatorSchema = {
67
+ // type: "object",
68
+ // required: ['msgAtrrParam1', 'msgAtrrParam2'],
69
+ // properties: {
70
+ // msgAtrrParam1: {
71
+ // type: "string"
72
+ // },
73
+ // msgAtrrParam2: {
74
+ // type: "object"
75
+ // }
76
+ // }
77
+ // };
78
78
 
79
79
  module.exports.main = middlewareHandler.wrap(async (event, context, callback) => {
80
80
 
@@ -38,7 +38,7 @@ function data(_izContext, flowSchema, srcPath) {
38
38
  }
39
39
 
40
40
  function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
41
- let functionName = upperCase(FUNCTION_NAME.flowSchemaExternalTopic)
41
+ let functionName = upperCase(flowSchema.flowTag) + "ExternalTopicOut";
42
42
  let snsTopicIn = Object.keys(flowSchema.flowSteps)
43
43
  let snsTopicInWithoutUnderscore = snsTopicIn[0].replace(/_/g, '')
44
44
  let handlerType = upperCase(HANDLER.hdrSqs);
@@ -48,11 +48,11 @@ function createParamsForCreateSource(_izContext, flowSchema, srcPath) {
48
48
  templatePath: templatePath,
49
49
  templateData: {
50
50
  snsTopicIn: snsTopicInWithoutUnderscore,
51
- externalTopicOutMain: FUNCTION_NAME.flowSchemaExternalTopic + 'Out',
51
+ externalTopicOutMain: functionName,
52
52
  },
53
53
  setting: {
54
- savePath: path.join(srcPath, SOURCE_PATH.flowSchemaExternalTopic, flowSchema.flowTag, 'source/'),
55
- saveFileName: `${functionName}Out_Main`,
54
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchema, flowSchema.flowTag, 'source/'),
55
+ saveFileName: `${functionName}_Main`,
56
56
  fileExtension: ".js",
57
57
  isAppend: false
58
58
  }