@izara_project/izara-market-library-service-schemas 1.0.34 → 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 (135) hide show
  1. package/package.json +1 -1
  2. package/src/GenerateCodeLibs/src/Consts.js +2 -1
  3. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +7 -6
  4. package/src/MainLibs/src/Consts.js +47 -14
  5. package/src/MainLibs/src/GenerateCodeUtils.js +2 -0
  6. package/src/TemplateManager/src/attributeTree/relationshipSchema/data.js +1 -1
  7. package/src/TemplateManager/src/attributeTreeSchema/generateTemplateData.js +103 -0
  8. package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/attributeLinkTemplate.ejs +3 -7
  9. package/src/TemplateManager/src/attributeTreeSchema/mainAttributeTree/data.js +134 -0
  10. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/data.js +84 -0
  11. package/src/TemplateManager/src/attributeTreeSchema/referenceRelationshipSchema/tempReferenceRelationshipSchema.ejs +9 -0
  12. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/data.js +172 -0
  13. package/src/TemplateManager/src/attributeTreeSchema/relationshipSchema/template.ejs +7 -0
  14. package/src/reStructure/GenerateCode.js +1 -0
  15. package/src/reStructure/SchemaConfig.js +1 -3
  16. package/src/reStructure/TemplateData/EndpointPerService/handler/api/template.ejs +2 -2
  17. package/src/reStructure/TemplateData/EndpointPerService/handler/inv/template.ejs +2 -2
  18. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/backupTemplate.ejs +701 -0
  19. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/create/template.ejs +34 -159
  20. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/delete/template.ejs +2 -0
  21. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/get/template.ejs +3 -4
  22. package/src/reStructure/TemplateData/EndpointPerService/mainFunction/update/template.ejs +2 -0
  23. package/src/reStructure/TemplateData/externalService/lambdaRole/data.js +38 -12
  24. package/src/reStructure/TemplateData/externalService/lambdaRole/template.ejs +5 -2
  25. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/data.js +22 -14
  26. package/src/reStructure/TemplateData/externalService/snsTopicSubscriptions/template.ejs +4 -1
  27. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/data.js +123 -0
  28. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/functionYaml/template.ejs +20 -0
  29. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/data.js +57 -0
  30. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/handler/template.ejs +85 -0
  31. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/data.js +68 -0
  32. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/mainFunction/template.ejs +131 -0
  33. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/data.js +77 -0
  34. package/src/reStructure/TemplateData/flowSchema/CreateRecordComplete/queue/template.ejs +49 -0
  35. package/src/reStructure/TemplateData/flowSchema/components/upload/createObject/handler/template.ejs +1 -1
  36. package/src/reStructure/TemplateData/flowSchema/components/upload/createObjectComplete/mainFunction/template.ejs +1 -1
  37. package/src/reStructure/TemplateData/flowSchema/components/upload/preSignUrl/createPresignUrl/mainFunction/template.ejs +1 -1
  38. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/data.js +12 -4
  39. package/src/reStructure/TemplateData/flowSchema/components/upload/relate/libs/template.ejs +13 -8
  40. package/src/reStructure/TemplateData/flowSchema/components/websocket/connect/handler/template.ejs +4 -4
  41. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/data.js +141 -0
  42. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/functionYaml/template.ejs +20 -0
  43. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/data.js +55 -0
  44. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/handler/template.ejs +83 -0
  45. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/data.js +55 -0
  46. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/complete/mainFunction/template.ejs +131 -0
  47. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/dynamoDB/register.js +82 -0
  48. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/data.js +64 -0
  49. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/sns-in/template.ejs +45 -0
  50. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/statusFieldTemplate.ejs +19 -6
  51. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/storedCacheTemplate.ejs +9 -15
  52. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/data.js +76 -0
  53. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/subscriptionOutAll/template.ejs +13 -0
  54. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/data.js +164 -0
  55. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/functionYaml/template.ejs +18 -0
  56. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/data.js +64 -0
  57. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/handler/template.ejs +88 -0
  58. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/data.js +55 -0
  59. package/src/reStructure/TemplateData/flowSchema/createRecordByStatusType/wbs/mainFunction/template.ejs +222 -0
  60. package/src/reStructure/TemplateData/flowSchema/dynamoDb/data.js +83 -44
  61. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/data.js +26 -59
  62. package/src/reStructure/TemplateData/flowSchema/eventBridge/functionYaml/template.ejs +3 -3
  63. package/src/reStructure/TemplateData/flowSchema/eventBridge/handler/inv/data.js +8 -8
  64. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/data.js +11 -9
  65. package/src/reStructure/TemplateData/flowSchema/eventBridge/mainFunction/template.ejs +3 -3
  66. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/data.js +5 -9
  67. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-in-sqs/template.ejs +1 -7
  68. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/data.js +2 -3
  69. package/src/reStructure/TemplateData/flowSchema/externalTopic/sns-out/template.ejs +2 -4
  70. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/data.js +37 -11
  71. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/functionYaml/template.ejs +4 -4
  72. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/data.js +8 -9
  73. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/handler/template.ejs +13 -13
  74. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/data.js +4 -4
  75. package/src/reStructure/TemplateData/flowSchema/externalTopic/sqs/mainFunction/template.ejs +44 -69
  76. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/data.js +7 -44
  77. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/functionYaml/template.ejs +3 -3
  78. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/data.js +3 -10
  79. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/handler/template.ejs +40 -86
  80. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/data.js +11 -4
  81. package/src/reStructure/TemplateData/flowSchema/externalTopic/websocket/mainFunction/template.ejs +11 -8
  82. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/data.js +17 -3
  83. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/functionYaml/template.ejs +2 -2
  84. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/data.js +8 -2
  85. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComplete/mainFunction/template.ejs +49 -84
  86. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/data.js +55 -10
  87. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/functionYaml/template.ejs +1 -1
  88. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/data.js +2 -2
  89. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/handler/template.ejs +1 -1
  90. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/data.js +27 -8
  91. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/EndpointComponent/mainFunction/template.ejs +50 -20
  92. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/data.js +20 -5
  93. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/functionYaml/template.ejs +1 -1
  94. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/data.js +2 -2
  95. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/handler/template.ejs +5 -5
  96. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/data.js +5 -3
  97. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaCompleteComponent/mainFunction/template.ejs +7 -5
  98. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/data.js +6 -3
  99. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/functionYaml/template.ejs +0 -2
  100. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/data.js +2 -2
  101. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/handler/template.ejs +3 -3
  102. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/data.js +9 -9
  103. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/FlowSchemaComponent/mainFunction/template.ejs +17 -39
  104. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-in/data.js +14 -8
  105. package/src/reStructure/TemplateData/flowSchema/flowSchemaOwnTopic/sns-out/data.js +4 -1
  106. package/src/reStructure/TemplateData/flowSchema/generateTemplateData.js +90 -21
  107. package/src/reStructure/TemplateData/generateRole/createSharedResource.js +22 -1
  108. package/src/reStructure/TemplateData/generateRole/sharedResourceTemplate.ejs +3 -0
  109. package/src/reStructure/TemplateData/perActionComplete/create/mainFunction/template.ejs +9 -8
  110. package/src/reStructure/TemplateData/perActionComplete/delete/mainFunction/template.ejs +5 -1
  111. package/src/reStructure/TemplateData/perActionComplete/get/mainFunction/template.ejs +2 -1
  112. package/src/reStructure/TemplateData/processLogical/mainFunction/template.ejs +1 -0
  113. package/src/reStructure/TemplateData/propertyValueSchema/generateTemplateData.js +66 -0
  114. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/data.js +131 -0
  115. package/src/reStructure/TemplateData/propertyValueSchema/objectPropertyValueSchema/templateObjectPropertyValueSchema.ejs +16 -0
  116. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/data.js +156 -0
  117. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/tempRelationship.ejs +13 -0
  118. package/src/reStructure/TemplateData/propertyValueSchema/relationshipPropertyValueSchema/templateRelationshipPropertyValueSchema.ejs +7 -0
  119. package/src/reStructure/TemplateData/relationshipPerAction/create/action/mainFunction/template.ejs +2 -1
  120. package/src/reStructure/TemplateData/relationshipPerAction/create/complete/mainFunction/template.ejs +2 -1
  121. package/src/reStructure/TemplateData/relationshipPerAction/delete/action/mainFunction/template.ejs +2 -1
  122. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/handler/sqs/template.ejs +5 -5
  123. package/src/reStructure/TemplateData/relationshipPerAction/delete/complete/mainFunction/template.ejs +5 -4
  124. package/src/reStructure/TemplateData/relationshipPerAction/get/action/mainFunction/template.ejs +2 -1
  125. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/handler/sqs/template.ejs +4 -4
  126. package/src/reStructure/TemplateData/relationshipPerAction/get/complete/mainFunction/template.ejs +4 -3
  127. package/src/reStructure/TemplateData/relationshipPerAction/update/action/mainFunction/template.ejs +2 -1
  128. package/src/reStructure/TemplateData/relationshipPerAction/update/complete/mainFunction/template.ejs +2 -1
  129. package/src/reStructure/TemplateData/resourceYaml/dynamodb/template.ejs +1 -3
  130. package/src/reStructure/TemplateData/resourceYaml/filterGenerateResource/data.js +61 -0
  131. package/src/reStructure/TemplateData/resourceYaml/generateTemplateData.js +13 -4
  132. package/src/reStructure/libs/ValidateAddOnDataStructure.js +62 -0
  133. package/src/reStructure/TemplateData/attributeTreeSchema/generateTemplateData.js +0 -104
  134. package/src/reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema/data.js +0 -188
  135. /package/src/{reStructure/TemplateData/attributeTreeSchema/mainAttributeTreeSchema → TemplateManager/src/attributeTreeSchema/mainAttributeTree}/request.json +0 -0
@@ -0,0 +1,222 @@
1
+ /*
2
+ Copyright (C) 2020 Sven Mason <http: //izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see
16
+ <http: //www.gnu.org/licenses />.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ const hash = require("object-hash");
22
+ const { getObjectSchema } = require('@izara_project/izara-core-library-service-schemas');
23
+
24
+ const dynamodbSharedLib = require('@izara_project/izara-core-library-dynamodb');
25
+ const snsSharedLib = require('@izara_project/izara-core-library-sns');
26
+ const asyncFlowSharedLib = require('@izara_project/izara-core-library-asynchronous-flow');
27
+ const callingFlowSharedLib = require('@izara_project/izara-core-library-calling-flow');
28
+ const lambdaSharedLib = require('@izara_project/izara-core-library-lambda');
29
+
30
+ const externalRequest = require('@izara_project/izara-core-library-external-request');
31
+ const sns = externalRequest.sns
32
+
33
+ const utils = require('@izara_project/izara-market-library-service-schemas/src/MainLibs/src/Utils')
34
+ const NoRetryError = require('@izara_project/izara-core-library-core').NoRetryError
35
+ const { v4: uuidv4 } = require('uuid')
36
+ const consts = require('@izara_project/izara-middleware/src/MiddlewareCore/Consts')
37
+ const { TOPIC_NAME_GENERATE_CODE } = require('@izara_project/izara-market-library-service-schemas/src/GenerateCodeLibs/src/Consts')
38
+ /**
39
+ *
40
+ *
41
+ * description of function.
42
+ * @param {Object} _izContext
43
+ * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
44
+ * @param {Logger} _izContext.logger - property of _izContext
45
+ * @param {Object} requestParams - request params
46
+ * @param {Object} requestParams.identifiers - identifiers for get data
47
+ * @param {Object} requestParams.additionalRequest - additionalRequest
48
+ *
49
+ *
50
+ * @returns {object} description of return value
51
+ */
52
+
53
+ module.exports.<%- functionMain%> = async (
54
+ _izContext,
55
+ requestParams,
56
+ callingFlowConfig = {},
57
+ //(<additionalParams>)
58
+ //(</additionalParams>)
59
+ ) => {
60
+ try {
61
+ //param {
62
+ // "action":register
63
+ // flowTag:"xxx"
64
+ // identifierTask:"xxxx",
65
+ // ...something
66
+ //}
67
+
68
+ // receive flowTag and identifiers
69
+ let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(_izContext, {
70
+ flowTag: requestParams.flowTag,
71
+ serviceTag: process.env.iz_serviceTag,
72
+ })
73
+
74
+ _izContext.logger.debug("flowSchema", flowSchema)
75
+ if (!flowSchema) {
76
+ throw new NoRetryError(`flowTag not found ${requestParams.flowTag}`)
77
+ }
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;
146
+ switch (flowSchema.statusType) {
147
+ case "statusField":
148
+ const payload = {
149
+ identifiers: requestParams.identifiers,
150
+ objectType: flowSchema.objType.objectType
151
+ }
152
+ const result = await externalRequest.lambda.invokeSync(
153
+ _izContext,
154
+ await lambdaSharedLib.lambdaFunctionName(_izContext, "GetHdrInv", flowSchema.objType.serviceTag),
155
+ payload
156
+ )
157
+ if (!result) {
158
+ throw new NoRetryError(`statusField not found ${requestParams.identifiers}`)
159
+ }
160
+ return result
161
+
162
+
163
+ case "storedCache":
164
+ // if statusType=storedCache then query storedCache > post message to client -> remove connectionId if status = error || complete
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,
178
+ }
179
+ }
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
+
203
+ case "none":
204
+ // if statusType=none -> post message to client ---- not remove connectionId when post message, can remove connectionId when cannot use connectionId only(user disconnect)
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
+
213
+ default:
214
+ throw new NoRetryError(`statusType not found ${flowSchema.statusType}`)
215
+ }
216
+
217
+ // post result to connectionId
218
+ } catch (err) {
219
+ _izContext.logger.error('error WebSocketInvoke: ', err)
220
+ throw (err)
221
+ }
222
+ }
@@ -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;
@@ -51,9 +51,9 @@ function data(_izContext, flowSchema, srcPath) {
51
51
  }
52
52
 
53
53
  function createSourceParams(_izContext, flowSchema, srcPath) {
54
- const functionName = upperCase(flowSchema.flowTag);
55
- const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
56
- const functionNameConfig = upperCase(flowSchema.flowTag) + SOURCE_GENERATE_IAM_ROLE.EventBridge;
54
+ const functionName = upperCase(FUNCTION_NAME.flowSchemaEventBridge);
55
+ // const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
56
+ const functionNameConfig = upperCase(SOURCE_GENERATE_IAM_ROLE.EventBridge);
57
57
  const handlerType = HANDLER.hdrInv;
58
58
  const schedules = flowSchema.schedules;
59
59
 
@@ -85,25 +85,28 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
85
85
 
86
86
  // Validate rate format for each schedule
87
87
  for (const schedule of schedules) {
88
- const rate = schedule.rate;
89
- if (rate.startsWith('rate')) {
90
- // Validate rate expression format: rate(value unit)
91
- if (!/^rate\(\d+\s+(minute|minutes|hour|hours|day|days)\)$/.test(rate)) {
92
- console.error(`Invalid rate format: ${rate}. Should be like 'rate(5 minutes)' or 'rate(1 day)'`);
93
- return;
94
- }
95
- } else if (rate.startsWith('cron')) {
96
- // Extract the cron components for more detailed validation
97
- const cronMatch = rate.match(/^cron\((.*)\)$/);
98
- if (!cronMatch) {
99
- console.error(`Invalid cron format: ${rate}. Should be like 'cron(0 10 * * ? *)'`);
100
- return;
101
- }
88
+ if (Array.isArray(schedule.rate) && schedule.rate.length <= 1) {
89
+ const rate = schedule.rate[0];
90
+
91
+ if (rate.startsWith('rate')) {
92
+ // Validate rate expression format: rate(value unit)
93
+ if (!/^rate\(\d+\s+(minute|minutes|hour|hours|day|days)\)$/.test(rate)) {
94
+ console.error(`Invalid rate format: ${rate}. Should be like 'rate(5 minutes)' or 'rate(1 day)'`);
95
+ return;
96
+ }
97
+ } else if (rate.startsWith('cron')) {
98
+ // Extract the cron components for more detailed validation
99
+ const cronMatch = rate.match(/^cron\((.*)\)$/);
100
+ if (!cronMatch) {
101
+ console.error(`Invalid cron format: ${rate}. Should be like 'cron(0 10 * * ? *)'`);
102
+ return;
103
+ }
102
104
 
103
- const cronParts = cronMatch[1].split(/\s+/);
104
- if (cronParts.length !== 6) {
105
- console.error(`Invalid cron expression: ${rate}. Must contain 6 components: minutes hours day-of-month month day-of-week year`);
106
- return;
105
+ const cronParts = cronMatch[1].split(/\s+/);
106
+ if (cronParts.length !== 6) {
107
+ console.error(`Invalid cron expression: ${rate}. Must contain 6 components: minutes hours day-of-month month day-of-week year`);
108
+ return;
109
+ }
107
110
  }
108
111
 
109
112
  } else {
@@ -115,16 +118,6 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
115
118
 
116
119
  let additionalResourcePermission = defaultIamRolePerAction();
117
120
  additionalResourcePermission.push(
118
- createIamRole(
119
- {
120
- [RESOURCE_CLASSES.sns]: [
121
- SNS_RESOURCE.publish
122
- ]
123
- },
124
- [
125
- resourceNames(RESOURCE_CLASSES.sns, "InImportBatchMainCreate")
126
- ]
127
- ),
128
121
  createIamRole(
129
122
  {
130
123
  [RESOURCE_CLASSES.dynamoDbTable]: [
@@ -151,39 +144,13 @@ function createSourceParams(_izContext, flowSchema, srcPath) {
151
144
  )
152
145
  )
153
146
 
154
- if (flowSchema?.hook) {
155
- for (const [hookName, hookProperties] of Object.entries(flowSchema.hook)) {
156
- if (hookName === FLOW_SCHEMA_HOOK_STATE.beforeCreate) {
157
- for (const hookFunction of hookProperties.functionList) {
158
- if ((hookFunction.event.hasOwnProperty("initialEvent") && (hookFunction.event.initialEvent === true))) {
159
- if (hookFunction?.permission) {
160
- for (const permission of hookFunction.permission) {
161
- additionalResourcePermission.push(
162
- createIamRole(
163
- permission.action,
164
- permission.resource.map(resource =>
165
- externalResourceYaml(
166
- resource.resource,
167
- resource.resourceName,
168
- resource.serviceTag),
169
- permission.effect
170
- )
171
- )
172
- )
173
- }
174
- }
175
- }
176
- }
177
- }
178
- }
179
- }
180
147
  // console.log("additionalResourcePermission in createObjectS3", JSON.stringify(additionalResourcePermission))
181
148
  return {
182
149
  templatePath: templatePath,
183
150
  templateData: {
184
- resourceLocation: SOURCE_PATH.resourceLocationFlowSchemaEventBridge,
151
+ resourceLocation: path.join(SOURCE_PATH.resourceLocationFlowSchemaEventBridge, flowSchema.flowTag, "source/"),
185
152
  functionName,
186
- action,
153
+ // action,
187
154
  functionNameConfig: functionNameConfig,
188
155
  additionalResourcePermission,
189
156
  roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
@@ -1,6 +1,6 @@
1
1
  <%_ const join = require('path').join; _%>
2
2
  <%- firstLetterUpperCase(functionNameConfig) %>:
3
- handler: <%- join(resourceLocation, `${functionName}${action}_${firstLetterUpperCase(handlerType)}.main`)%>
3
+ handler: <%- join(resourceLocation, `${functionName}_${firstLetterUpperCase(handlerType)}.main`)%>
4
4
  name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionNameConfig) %>
5
5
  events:
6
6
  <%_ schedules.forEach((schedule) => { _%>
@@ -11,8 +11,8 @@
11
11
  input: <%- JSON.stringify(schedule.input) %>
12
12
  <%_ }) _%>
13
13
  role: <%- roleName %>Role
14
- #<#<%- functionName %><%- action %>IamRole#>
15
- #<#/<%- functionName %><%- action %>IamRole#>
14
+ #<#<%- functionName %>IamRole#>
15
+ #<#/<%- functionName %>IamRole#>
16
16
  <%_ function firstLetterUpperCase(text){
17
17
  return text.charAt(0).toUpperCase() + text.slice(1)
18
18
  } _%>
@@ -51,22 +51,22 @@ const templatePath = path.join(__dirname, "./template.ejs")
51
51
  function data(_izContext, flowSchema, srcPath) {
52
52
  const handler = HANDLER.hdrInv;
53
53
  const flowTag = flowSchema.flowTag;
54
- const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
55
- const functionName = flowTag + action;
56
- const fileName = `${upperCase(flowTag)}${upperCase(action)}_${upperCase(handler)}`;
54
+ // const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
55
+ const functionName = "EventBridge" + upperCase(handler);
56
+ // const fileName = `${upperCase(flowTag)}${upperCase(action)}_${upperCase(handler)}`;
57
57
  return [{
58
58
  templatePath: templatePath,
59
59
  templateData: {
60
60
  functionName: functionName,
61
61
  flowTag: flowTag,
62
- action: action,
62
+ // action: action,
63
63
  handler,
64
- roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
65
- firstLetterUpperCase: upperCase,
64
+ // roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
65
+ // firstLetterUpperCase: upperCase,
66
66
  },
67
67
  setting: {
68
- savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
69
- saveFileName: fileName,
68
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge, flowSchema.flowTag, "source/"),
69
+ saveFileName: `EventBridge_${upperCase(handler)}`,
70
70
  fileExtension: '.js',
71
71
  isAppend: false
72
72
  }
@@ -32,7 +32,9 @@ const {
32
32
  consts: {
33
33
  DEFAULT_HANDLER_PER_ACTION,
34
34
  SOURCE_PATH,
35
- SOURCE_GENERATE_IAM_ROLE
35
+ SOURCE_GENERATE_IAM_ROLE,
36
+ SAVE_FILE_NAME,
37
+ FUNCTION_NAME
36
38
  }
37
39
  } = require("../../../../../MainLibs");
38
40
 
@@ -46,23 +48,23 @@ const templatePath = path.join(__dirname, "./template.ejs")
46
48
  * @return {{ templatePath, templateData, setting } }
47
49
  */
48
50
  function data(_izContext, flowSchema, srcPath) {
49
- const handler = HANDLER.hdrInv;
51
+ // const handler = HANDLER.hdrInv;
50
52
  const flowTag = flowSchema.flowTag;
51
- const functionName = flowTag + upperCase(handler);
52
- const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
53
- const fileName = `${upperCase(flowTag)}${upperCase(action)}_Main`;
53
+ // const functionName = "EventBridge" + upperCase(handler);
54
+ // const action = SOURCE_GENERATE_IAM_ROLE.EventBridge;
55
+ // const fileName = `${upperCase(flowTag)}${upperCase(action)}_Main`;
54
56
  return [{
55
57
  templatePath: templatePath,
56
58
  templateData: {
57
- functionName: functionName,
59
+ functionName: "EventBridge",
58
60
  flowTag: flowTag,
59
61
  roleName: SOURCE_GENERATE_IAM_ROLE.EventBridge,
60
- action: action,
62
+ // action: action,
61
63
  firstLetterUpperCase: upperCase,
62
64
  },
63
65
  setting: {
64
- savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge),
65
- saveFileName: fileName,
66
+ savePath: path.join(srcPath, SOURCE_PATH.flowSchemaEventBridge, flowSchema.flowTag, "source/"),
67
+ saveFileName: "EventBridge_Main",
66
68
  fileExtension: '.js',
67
69
  isAppend: false
68
70
  }
@@ -78,9 +78,9 @@ module.exports.<%- functionName %>Main = async (
78
78
  _izContext.logger.debug('<%- functionName %> requestParams: ', requestParams);
79
79
  _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
80
80
 
81
- //(<additionalParams>)
82
- //(</additionalParams>)
83
-
81
+ //(<eventBridgeHook>)
82
+ //(</eventBridgeHook>)
83
+
84
84
  } catch (err) {
85
85
  _izContext.logger.error('error <%- firstLetterUpperCase(functionName) %>Main: ', err)
86
86
  throw (err)
@@ -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,20 +46,15 @@ const {
45
46
  */
46
47
 
47
48
  function data(_izContext, flowSchema, srcPath) {
48
- const flowStepSplitKey = Object.keys(flowSchema.flowSteps)[0].split("_");
49
- let queueName;
50
- let queueNameSubscription;
51
- if (Object.keys(flowSchema.flowSteps).length > 3) {
52
- queueName = flowStepSplitKey[3] + 'Out';
53
- queueNameSubscription = flowStepSplitKey[3]
54
- }
55
-
49
+ const flowStepSplitKeyOut = Object.keys(flowSchema.flowSteps)[1].split("_");
50
+ // console.log({ flowStepSplitKey })
51
+ let queueName = upperCase(flowSchema.flowTag) + "ExternalTopicOut" + upperCase(HANDLER.hdrSqs)
56
52
  return [{
57
53
  templatePath,
58
54
  templateData: {
59
55
  queueName: upperCase(queueName),
60
- queueNameSubscription: upperCase(queueNameSubscription),
61
56
  roleName: SOURCE_GENERATE_IAM_ROLE.ExternalTopicRole,
57
+ firstLetterUpperCase: upperCase
62
58
  },
63
59
  setting: {
64
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) } _%>