@izara_project/izara-core-generate-service-code 1.0.74 → 1.0.76
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.
- package/package.json +1 -1
- package/src/compile/loadSchemas.js +36 -30
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +2 -4
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +12 -2
- package/src/emit/coreFunction/templates/InitialSetupRunner.ejs +5 -3
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +13 -6
- package/src/emit/coreFunction/templates/InitialSetup_HdrInv.ejs +1 -1
- package/src/emit/crud/emitCrudApplicationArtifacts.js +2 -2
- package/src/emit/crud/emitDynamicCrudFlowSchemas.js +43 -2
- package/src/emit/crud/templates/CreateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/CreateComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/DeleteComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/DeleteComplete_Main.ejs +188 -0
- package/src/emit/crud/templates/FlowEndpointComplete_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateComplete_HdrSqs.ejs +99 -0
- package/src/emit/crud/templates/UpdateComplete_Main.ejs +188 -0
- package/src/emit/custom/customFlows.js +15 -1
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +2 -0
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +1 -1
- package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +20 -5
- package/src/emit/rbac/emitRbacApplicationArtifacts.js +58 -43
- package/src/emit/rbac/templates/CreateTargetRole_HdrSqs.ejs +68 -20
- package/src/emit/rbac/templates/ListRbac_HdrSqs.ejs +69 -20
- package/src/emit/rbac/templates/UserRbacFlow_HdrSqs.ejs +69 -20
- package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +21 -1
- package/src/emit/relationship/emitRelationshipApplicationArtifacts.js +1 -1
- package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +91 -87
- package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +90 -86
- package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +85 -81
- package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +2 -0
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +2 -20
- package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +93 -89
- package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +99 -0
- package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +85 -81
- package/src/emit/resource/emitResourceArtifacts.js +36 -2
- package/src/emit/shared/templates/FindData_Main.ejs +1 -1
- package/src/emit/system/emitSystemWebSocketArtifacts.js +54 -2
- package/src/emit/system/templates/RegisterComplete_HdrSqs.ejs +64 -0
- package/src/emit/system/templates/RegisterComplete_Main.ejs +154 -0
- package/src/emit/system/templates/RegisterComplete_Yaml.ejs +17 -0
- package/src/emit/system/templates/RegisterWbs_Yaml.ejs +7 -0
- package/src/emit/system/templates/Register_HdrWbs.ejs +56 -0
- package/src/emit/system/templates/Register_Main.ejs +148 -0
- package/src/output/mergeHooks.js +4 -3
- package/test/customFlowApplicationArtifacts.test.js +16 -5
- package/test/publicApi.test.js +21 -0
- package/test/relationshipApplicationArtifacts.test.js +1 -1
- package/test/resourceArtifacts.test.js +20 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@izara_project/izara-core-generate-service-code",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.76",
|
|
4
4
|
"description": "Code for locally generating per service files",
|
|
5
5
|
"homepage": "https://bitbucket.org/izara-core-support-services/izara-core-support-services-generate-service-code#readme",
|
|
6
6
|
"repository": {
|
|
@@ -159,41 +159,47 @@ export async function resolveExtendedObjectSchemas(
|
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
/*
|
|
163
162
|
if (
|
|
164
163
|
currentSchema.hasOwnProperty('belongTo') &&
|
|
165
|
-
currentSchema.belongTo
|
|
166
|
-
currentSchema.belongTo.serviceTag &&
|
|
167
|
-
currentSchema.belongTo.objectType
|
|
164
|
+
currentSchema.belongTo
|
|
168
165
|
) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
166
|
+
const belongToTarget = Array.isArray(currentSchema.belongTo)
|
|
167
|
+
? currentSchema.belongTo[0]
|
|
168
|
+
: currentSchema.belongTo;
|
|
169
|
+
|
|
170
|
+
if (
|
|
171
|
+
belongToTarget &&
|
|
172
|
+
belongToTarget.serviceTag &&
|
|
173
|
+
belongToTarget.objectType
|
|
174
|
+
) {
|
|
175
|
+
try {
|
|
176
|
+
Logger.debug(
|
|
177
|
+
`[DEBUG] [resolveExtendedObjectSchemas] Fetching belongTo schema for objectType=${currentSchema.objectType}`,
|
|
178
|
+
{ belongTo: belongToTarget }
|
|
179
|
+
);
|
|
180
|
+
const belongToObjType = {
|
|
181
|
+
serviceTag: belongToTarget.serviceTag,
|
|
182
|
+
objectType: belongToTarget.objectType
|
|
183
|
+
};
|
|
184
|
+
const belongToSchema = await getObjectSchema.getObjSchemaS3(
|
|
185
|
+
{ logger: Logger },
|
|
186
|
+
belongToObjType,
|
|
187
|
+
false,
|
|
188
|
+
bucketName
|
|
189
|
+
);
|
|
190
|
+
currentSchema.belongToSchema = belongToSchema;
|
|
191
|
+
Logger.debug(
|
|
192
|
+
`[DEBUG] [resolveExtendedObjectSchemas] Successfully fetched belongTo schema for objectType=${currentSchema.objectType}`,
|
|
193
|
+
{ belongToObjectType: belongToSchema?.objectType }
|
|
194
|
+
);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
Logger.warn(
|
|
197
|
+
`[WARN] [resolveExtendedObjectSchemas] Failed to fetch belongTo schema for objectType=${currentSchema.objectType}`,
|
|
198
|
+
{ error }
|
|
199
|
+
);
|
|
200
|
+
}
|
|
194
201
|
}
|
|
195
202
|
}
|
|
196
|
-
*/
|
|
197
203
|
|
|
198
204
|
resolvedSchemas.push(currentSchema);
|
|
199
205
|
}
|
|
@@ -210,13 +210,11 @@ export async function emitCoreFunctionArtifacts({ project, objects = [], relatio
|
|
|
210
210
|
},
|
|
211
211
|
{
|
|
212
212
|
path: `${SRC_ROOT}/InitialSetupConfig.js`,
|
|
213
|
-
content: initialSetupConfig
|
|
214
|
-
writeWhenFileExist: false
|
|
213
|
+
content: initialSetupConfig
|
|
215
214
|
},
|
|
216
215
|
{
|
|
217
216
|
path: `${INITIAL_SETUP_ROOT}/InitialSetupConfig.js`,
|
|
218
|
-
content: initialSetupConfig
|
|
219
|
-
writeWhenFileExist: false // Don't overwrite the file that dev modifies
|
|
217
|
+
content: initialSetupConfig
|
|
220
218
|
},
|
|
221
219
|
{
|
|
222
220
|
path: `${INITIAL_SETUP_ROOT}/runner.js`,
|
|
@@ -49,21 +49,31 @@ const externalServices = {
|
|
|
49
49
|
-%>
|
|
50
50
|
const tableConfigs = {
|
|
51
51
|
prod: {
|
|
52
|
-
Config: {
|
|
52
|
+
Config: {
|
|
53
|
+
// <#InitialSetupConfig_Prod_Config_TableConfig#>
|
|
54
|
+
// <#/InitialSetupConfig_Prod_Config_TableConfig#>
|
|
55
|
+
},
|
|
53
56
|
<% dynamoTableNames.forEach(tableName => { -%>
|
|
54
|
-
<%= tableName %>: {
|
|
57
|
+
<%= tableName %>: {
|
|
58
|
+
// <#InitialSetupConfig_Prod_<%= tableName %>_TableConfig#>
|
|
59
|
+
// <#/InitialSetupConfig_Prod_<%= tableName %>_TableConfig#>
|
|
60
|
+
},
|
|
55
61
|
<% }); -%>
|
|
56
62
|
// <#InitialSetupConfig_ExtraProdTableConfigs#>
|
|
57
63
|
// <#/InitialSetupConfig_ExtraProdTableConfigs#>
|
|
58
64
|
},
|
|
59
65
|
test: {
|
|
60
66
|
Config: {
|
|
67
|
+
// <#InitialSetupConfig_Test_Config_TableConfig#>
|
|
61
68
|
clearDataWhenRefresh: true,
|
|
62
69
|
rawSource: false
|
|
70
|
+
// <#/InitialSetupConfig_Test_Config_TableConfig#>
|
|
63
71
|
},
|
|
64
72
|
<% dynamoTableNames.forEach(tableName => { -%>
|
|
65
73
|
<%= tableName %>: {
|
|
74
|
+
// <#InitialSetupConfig_Test_<%= tableName %>_TableConfig#>
|
|
66
75
|
clearDataWhenRefresh: true
|
|
76
|
+
// <#/InitialSetupConfig_Test_<%= tableName %>_TableConfig#>
|
|
67
77
|
},
|
|
68
78
|
<% }); -%>
|
|
69
79
|
// <#InitialSetupConfig_ExtraTestTableConfigs#>
|
|
@@ -40,6 +40,8 @@ if (fs.existsSync(configPath)) {
|
|
|
40
40
|
);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
process.env.LOG_LEVEL = process.env.LOG_LEVEL || 'INFO';
|
|
44
|
+
|
|
43
45
|
// 2. Dynamic import to ensure SDKs use the injected process.env
|
|
44
46
|
const { default: initialSetupSharedLib } =
|
|
45
47
|
await import('@izara_project/izara-core-library-initial-setup');
|
|
@@ -96,15 +98,15 @@ const commands = {
|
|
|
96
98
|
},
|
|
97
99
|
uploadSchema: async (_izContext) => {
|
|
98
100
|
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
99
|
-
await fn(_izContext);
|
|
101
|
+
await fn(_izContext, initialSetupSharedLib);
|
|
100
102
|
},
|
|
101
103
|
'uploadSchema:test': async (_izContext) => {
|
|
102
104
|
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
103
|
-
await fn(_izContext);
|
|
105
|
+
await fn(_izContext, initialSetupSharedLib);
|
|
104
106
|
},
|
|
105
107
|
'uploadSchema:prod': async (_izContext) => {
|
|
106
108
|
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
107
|
-
await fn(_izContext);
|
|
109
|
+
await fn(_izContext, initialSetupSharedLib);
|
|
108
110
|
}
|
|
109
111
|
};
|
|
110
112
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import initialSetupLib from '@izara_project/izara-core-library-initial-setup';
|
|
2
2
|
|
|
3
3
|
const SERVICE_TAG = {
|
|
4
4
|
TRANSLATIONS: 'Translations',
|
|
@@ -18,18 +18,25 @@ const ignoreExternalServices = {
|
|
|
18
18
|
};
|
|
19
19
|
//(</ignoreExternalServices>)
|
|
20
20
|
|
|
21
|
-
export default async function uploadSchema(_izContext) {
|
|
21
|
+
export default async function uploadSchema(_izContext, initialSetupSharedLib = initialSetupLib) {
|
|
22
22
|
console.log('======== UploadSchema ========');
|
|
23
23
|
try {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
await uploadObjSchema.uploadObjectSchemaByUseCase(_izContext, {
|
|
24
|
+
const libToUse = initialSetupSharedLib || initialSetupLib;
|
|
25
|
+
await libToUse.uploadObjectSchema(_izContext, {
|
|
27
26
|
ignoreExternalServices: ignoreExternalServices
|
|
28
27
|
});
|
|
29
28
|
console.log('-------- Finish UploadSchema --------');
|
|
30
29
|
return 'upload successfully';
|
|
31
30
|
} catch (err) {
|
|
32
|
-
|
|
31
|
+
let errorDetails = err.message || String(err);
|
|
32
|
+
if (errorDetails.includes('errorMessage:')) {
|
|
33
|
+
const match = errorDetails.match(/functionName:\s*([^,]+),errorMessage:(.*)/);
|
|
34
|
+
if (match) {
|
|
35
|
+
errorDetails = `Lambda [${match[1].trim()}] failed: ${match[2].trim()}`;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_izContext.logger.error(`[uploadSchema] ❌ ${errorDetails}`);
|
|
33
39
|
throw err;
|
|
34
40
|
}
|
|
35
41
|
}
|
|
42
|
+
|
|
@@ -234,11 +234,11 @@ async function emitAction(action, objects, flows, serviceTag) {
|
|
|
234
234
|
artifacts.push(
|
|
235
235
|
{
|
|
236
236
|
path: `${source}/${complete}_Main.js`,
|
|
237
|
-
content: await render(
|
|
237
|
+
content: await render(`${action}Complete_Main.ejs`, { action })
|
|
238
238
|
},
|
|
239
239
|
{
|
|
240
240
|
path: `${source}/${complete}_HdrSqs.js`,
|
|
241
|
-
content: await
|
|
241
|
+
content: await render(`${action}Complete_HdrSqs.ejs`, {
|
|
242
242
|
...shared,
|
|
243
243
|
mainFileName: `${complete}_Main`,
|
|
244
244
|
functionName: complete,
|
|
@@ -23,7 +23,10 @@ export function emitDynamicCrudFlowSchemas({ objects, flows = [] }) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
return ACTIONS.map((action, index) => {
|
|
26
|
-
const flow = _createDynamicFlow(
|
|
26
|
+
const flow = _createDynamicFlow(
|
|
27
|
+
action,
|
|
28
|
+
_hasBeforeLogicalStep(flows, action)
|
|
29
|
+
);
|
|
27
30
|
return {
|
|
28
31
|
path: dynamicCrudFlowSchemaPaths[index],
|
|
29
32
|
content: renderDynamicCrudFlowSchema(action, flow)
|
|
@@ -36,6 +39,23 @@ function _createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
36
39
|
const flowSteps = [
|
|
37
40
|
{
|
|
38
41
|
stepName: 'start',
|
|
42
|
+
...(hasBeforeLogicalStep
|
|
43
|
+
? {
|
|
44
|
+
nextSteps: [
|
|
45
|
+
{
|
|
46
|
+
stepName: 'BeforeLogical'
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
: outputTopic
|
|
51
|
+
? {
|
|
52
|
+
nextSteps: [
|
|
53
|
+
{
|
|
54
|
+
stepName: 'Complete'
|
|
55
|
+
}
|
|
56
|
+
]
|
|
57
|
+
}
|
|
58
|
+
: {}),
|
|
39
59
|
properties: [],
|
|
40
60
|
messageAttributes: MESSAGE_ATTRIBUTES,
|
|
41
61
|
...(outputTopic
|
|
@@ -53,6 +73,16 @@ function _createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
53
73
|
flowSteps.push({
|
|
54
74
|
stepName: 'BeforeLogical',
|
|
55
75
|
event: ['extTopic'],
|
|
76
|
+
previousSteps: [
|
|
77
|
+
{
|
|
78
|
+
stepName: 'start'
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
nextSteps: [
|
|
82
|
+
{
|
|
83
|
+
stepName: 'Complete'
|
|
84
|
+
}
|
|
85
|
+
],
|
|
56
86
|
properties: [],
|
|
57
87
|
messageAttributes: MESSAGE_ATTRIBUTES
|
|
58
88
|
});
|
|
@@ -62,7 +92,18 @@ function _createDynamicFlow(action, hasBeforeLogicalStep) {
|
|
|
62
92
|
flowSteps.push({
|
|
63
93
|
stepName: 'Complete',
|
|
64
94
|
event: ['extTopic'],
|
|
65
|
-
|
|
95
|
+
previousSteps: [
|
|
96
|
+
{
|
|
97
|
+
stepName: hasBeforeLogicalStep ? 'BeforeLogical' : 'start'
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
properties: [
|
|
101
|
+
'returnValue',
|
|
102
|
+
'parentFlowId',
|
|
103
|
+
'status',
|
|
104
|
+
'errorsFound',
|
|
105
|
+
'graphServiceTag'
|
|
106
|
+
],
|
|
66
107
|
messageAttributes: MESSAGE_ATTRIBUTES
|
|
67
108
|
});
|
|
68
109
|
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import CreateComplete from './CreateComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'CreateCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
CreateComplete, // mainFunction that need to invoke.
|
|
80
|
+
'CreateCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, CreateComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
|
|
2
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
3
|
+
import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
|
|
4
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
5
|
+
import { sns } from '@izara_project/izara-core-library-external-request';
|
|
6
|
+
import { consts } from '@izara_project/izara-core-library-service-schemas';
|
|
7
|
+
import { NoRetryError } from '@izara_project/izara-core-library-core';
|
|
8
|
+
|
|
9
|
+
//(<optionalRequire>)
|
|
10
|
+
//(</optionalRequire>)
|
|
11
|
+
|
|
12
|
+
const { TOPIC_NAME_GENERATE_CODE } = consts;
|
|
13
|
+
const PREFIX = { ASYNC: 'CreateAsyncEndpoint' };
|
|
14
|
+
|
|
15
|
+
function empty(value) {
|
|
16
|
+
return (
|
|
17
|
+
value == null ||
|
|
18
|
+
(typeof value === 'object' && Object.keys(value).length === 0)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function validateInput(returnValue, status, graphServiceTag, errorsFound) {
|
|
23
|
+
if (!returnValue?.queryResult)
|
|
24
|
+
errorsFound.push(
|
|
25
|
+
'message is not have property queryResult, should be not happen'
|
|
26
|
+
);
|
|
27
|
+
if (!returnValue?.requestParams?.objType)
|
|
28
|
+
errorsFound.push(
|
|
29
|
+
'message is not have property objType, should be not happen'
|
|
30
|
+
);
|
|
31
|
+
if (!returnValue?.requestParams?.objInstanceFull)
|
|
32
|
+
errorsFound.push(
|
|
33
|
+
'message is not have property objInstance, should be not objInstance'
|
|
34
|
+
);
|
|
35
|
+
if (status === 'error' && errorsFound.length === 0)
|
|
36
|
+
errorsFound.push(
|
|
37
|
+
'[invalid]status is error not have errorsFound form graphService'
|
|
38
|
+
);
|
|
39
|
+
if (status === 'complete' && errorsFound.length > 0)
|
|
40
|
+
errorsFound.push(
|
|
41
|
+
'[Invalid] status is complete should be not have errorsFound'
|
|
42
|
+
);
|
|
43
|
+
if (graphServiceTag == null)
|
|
44
|
+
errorsFound.push('[Invalid] graphServerTag is not empty string');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export default async function CreateComplete(
|
|
48
|
+
_izContext,
|
|
49
|
+
requestParams,
|
|
50
|
+
passBackProperties
|
|
51
|
+
//(<additionalParams>)
|
|
52
|
+
//(</additionalParams>)
|
|
53
|
+
) {
|
|
54
|
+
try {
|
|
55
|
+
_izContext.logger.debug('[CreateComplete] started', {
|
|
56
|
+
requestParams
|
|
57
|
+
});
|
|
58
|
+
const {
|
|
59
|
+
returnValue,
|
|
60
|
+
status,
|
|
61
|
+
errorsFound = [],
|
|
62
|
+
graphServiceTag,
|
|
63
|
+
parentFlowId
|
|
64
|
+
} = requestParams;
|
|
65
|
+
if (empty(returnValue?.requestParams))
|
|
66
|
+
throw new NoRetryError('message not an object');
|
|
67
|
+
validateInput(returnValue, status, graphServiceTag, errorsFound);
|
|
68
|
+
if (errorsFound.length > 0) errorsFound.push(errorsFound.join(','));
|
|
69
|
+
|
|
70
|
+
const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
|
|
71
|
+
parentFlowId,
|
|
72
|
+
PREFIX.ASYNC
|
|
73
|
+
);
|
|
74
|
+
const pending =
|
|
75
|
+
await asyncFlowSharedLib.findPendingStepAwaitingMultipleSteps(
|
|
76
|
+
_izContext,
|
|
77
|
+
awaitingStepId
|
|
78
|
+
);
|
|
79
|
+
_izContext.logger.debug('[CreateComplete] awaiting step', {
|
|
80
|
+
awaitingStepId,
|
|
81
|
+
pending
|
|
82
|
+
});
|
|
83
|
+
if (!pending) {
|
|
84
|
+
_izContext.logger.warn(
|
|
85
|
+
`No pending step found for awaitingStepId: ${awaitingStepId}`
|
|
86
|
+
);
|
|
87
|
+
return { returnValue, status, errorsFound };
|
|
88
|
+
}
|
|
89
|
+
const result =
|
|
90
|
+
await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
|
|
91
|
+
_izContext,
|
|
92
|
+
pending.pendingStepId,
|
|
93
|
+
awaitingStepId,
|
|
94
|
+
errorsFound
|
|
95
|
+
);
|
|
96
|
+
_izContext.logger.debug(
|
|
97
|
+
'[CreateComplete] all awaiting steps result',
|
|
98
|
+
{
|
|
99
|
+
isComplete: result.isComplete,
|
|
100
|
+
awaitingStepId,
|
|
101
|
+
pendingStepId: pending.pendingStepId
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
if (result.isComplete) {
|
|
106
|
+
const nodeResultKey = `returnCreatedNode`;
|
|
107
|
+
const fallbackNodeResultKey = `returnCreateNode`;
|
|
108
|
+
const nodeResult =
|
|
109
|
+
returnValue.queryResult[nodeResultKey] ??
|
|
110
|
+
returnValue.queryResult[fallbackNodeResultKey] ??
|
|
111
|
+
{};
|
|
112
|
+
const node = nodeResult.createNodeResult ?? nodeResult;
|
|
113
|
+
const existsNode =
|
|
114
|
+
node.existsNode && Object.keys(node.existsNode).length
|
|
115
|
+
? {
|
|
116
|
+
objType: returnValue.requestParams.objType,
|
|
117
|
+
objInstanceFull: node.existsNode.objInstanceFull
|
|
118
|
+
}
|
|
119
|
+
: null;
|
|
120
|
+
if (status === 'complete') {
|
|
121
|
+
await Promise.all(
|
|
122
|
+
(pending.listOfRecords ?? []).flatMap((records) =>
|
|
123
|
+
Object.values(records).map(async (record) =>
|
|
124
|
+
dynamodbSharedLib.putItem(
|
|
125
|
+
_izContext,
|
|
126
|
+
await dynamodbSharedLib.tableName(
|
|
127
|
+
_izContext,
|
|
128
|
+
record.tableName,
|
|
129
|
+
record.serviceTag
|
|
130
|
+
),
|
|
131
|
+
{
|
|
132
|
+
...record.objInstanceFull.identifiers,
|
|
133
|
+
...record.objInstanceFull.fields
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
const message =
|
|
141
|
+
callingFlowSharedLib.addParentPassBackPropertiesToSnsResponseMessageObject(
|
|
142
|
+
passBackProperties,
|
|
143
|
+
{
|
|
144
|
+
objType: returnValue.requestParams.objType,
|
|
145
|
+
objInstanceFull: node.objInstanceFull,
|
|
146
|
+
relationships: node.relationships,
|
|
147
|
+
parentFlowId: parentFlowId || returnValue?.parentFlowId,
|
|
148
|
+
existsNode,
|
|
149
|
+
status,
|
|
150
|
+
errorsFound
|
|
151
|
+
}
|
|
152
|
+
);
|
|
153
|
+
const messageAttributes =
|
|
154
|
+
callingFlowSharedLib.addParentPassBackCallingFlowToSnsResponseMessageAttributes(
|
|
155
|
+
passBackProperties,
|
|
156
|
+
{}
|
|
157
|
+
);
|
|
158
|
+
const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
|
|
159
|
+
_izContext,
|
|
160
|
+
TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete
|
|
161
|
+
);
|
|
162
|
+
_izContext.logger.debug('[CreateComplete] publishing to SNS', {
|
|
163
|
+
TopicArn: topicArn,
|
|
164
|
+
message
|
|
165
|
+
});
|
|
166
|
+
await sns.publishAsync(_izContext, {
|
|
167
|
+
Message: JSON.stringify(message),
|
|
168
|
+
MessageAttributes: sns.createStringMessageAttributes(
|
|
169
|
+
_izContext,
|
|
170
|
+
messageAttributes
|
|
171
|
+
),
|
|
172
|
+
TopicArn: topicArn
|
|
173
|
+
});
|
|
174
|
+
//(<afterSendMessage>)
|
|
175
|
+
//(</afterSendMessage>)
|
|
176
|
+
}
|
|
177
|
+
await asyncFlowSharedLib.removeAwaitingMultipleStep(
|
|
178
|
+
_izContext,
|
|
179
|
+
awaitingStepId,
|
|
180
|
+
pending.pendingStepId,
|
|
181
|
+
errorsFound
|
|
182
|
+
);
|
|
183
|
+
return { returnValue, status, errorsFound };
|
|
184
|
+
} catch (error) {
|
|
185
|
+
_izContext.logger.error('[CreateComplete] error:', error);
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { middlewareHandler as middleware } from '@izara_project/izara-middleware';
|
|
2
|
+
import { recordHandlerSharedLib } from '@izara_project/izara-core-library-record-handler';
|
|
3
|
+
import Logger from '@izara_project/izara-core-library-logger';
|
|
4
|
+
import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
|
|
5
|
+
import DeleteComplete from './DeleteComplete_Main.js';
|
|
6
|
+
|
|
7
|
+
//(<optionalRequire>)
|
|
8
|
+
//(</optionalRequire>)
|
|
9
|
+
|
|
10
|
+
// validate event properties in body.Message of sqs event
|
|
11
|
+
let perRecordsValidatorSchema = {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
returnValue: {
|
|
15
|
+
type: 'object'
|
|
16
|
+
},
|
|
17
|
+
parentFlowId: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: 'string'
|
|
22
|
+
},
|
|
23
|
+
errorsFound: {
|
|
24
|
+
type: 'array'
|
|
25
|
+
},
|
|
26
|
+
graphServiceTag: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
required: [
|
|
31
|
+
'returnValue',
|
|
32
|
+
'parentFlowId',
|
|
33
|
+
'status',
|
|
34
|
+
'errorsFound',
|
|
35
|
+
'graphServiceTag'
|
|
36
|
+
]
|
|
37
|
+
//(<validatorSchema>)
|
|
38
|
+
//(</validatorSchema>)
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
let messageAttributeValidatorSchema = null;
|
|
42
|
+
middleware.setValidatorSchema(recordHandlerSharedLib.baseValidatorSchema());
|
|
43
|
+
|
|
44
|
+
export const main = middleware.wrap(async (event, context) => {
|
|
45
|
+
try {
|
|
46
|
+
let recordPromises = [];
|
|
47
|
+
|
|
48
|
+
// loop each record and send to mainFunction
|
|
49
|
+
await Promise.all(
|
|
50
|
+
event.Records.map(async (record) => {
|
|
51
|
+
let passOnProperties = [];
|
|
52
|
+
record._izContext.logger.debug('record ReceiveMsgOutHdrSqs', record);
|
|
53
|
+
|
|
54
|
+
//validate message (and MessageAttributes)
|
|
55
|
+
await recordHandlerSharedLib.validateRecord(
|
|
56
|
+
record, // one record will send to mainFunction
|
|
57
|
+
'DeleteCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
58
|
+
perRecordsValidatorSchema, // schema for record.Message
|
|
59
|
+
messageAttributeValidatorSchema
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// add argument (to invoke lambda) to passOnProperties[]
|
|
63
|
+
passOnProperties.push(record.body.Message);
|
|
64
|
+
passOnProperties.push(
|
|
65
|
+
callingFlowSharedLib.addPassBackPropertiesToPassOnProperties(
|
|
66
|
+
record.body.Message
|
|
67
|
+
)
|
|
68
|
+
);
|
|
69
|
+
//(<additionalParams>)
|
|
70
|
+
//(</additionalParams>)
|
|
71
|
+
record._izContext.logger.debug(
|
|
72
|
+
'passOnProperties in handler',
|
|
73
|
+
passOnProperties
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
// call recordHandlerSharedLib.recordHandler with 3 parameters and return promise(resolve)
|
|
77
|
+
let recordPromise = recordHandlerSharedLib.recordHandler(
|
|
78
|
+
record, // one record will send to mainFunction
|
|
79
|
+
DeleteComplete, // mainFunction that need to invoke.
|
|
80
|
+
'DeleteCompleteHdrSqs', // queue name that need to retry or send to dlq
|
|
81
|
+
passOnProperties // all parameters that mainFunction needed.
|
|
82
|
+
);
|
|
83
|
+
record._izContext.logger.debug('after recordPromise in handler');
|
|
84
|
+
recordPromises.push(recordPromise); // push promise to recordPromises
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
try {
|
|
88
|
+
await Promise.all(recordPromises);
|
|
89
|
+
return event.Records;
|
|
90
|
+
} catch {
|
|
91
|
+
Logger.debug(
|
|
92
|
+
'Promise.all(recordPromises) in handler threw error (at least one record did no resolve)'
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} catch (error) {
|
|
96
|
+
Logger.error('Unhandled Error, DeleteComplete_HdrSqs: ', error);
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
});
|