@izara_project/izara-core-generate-service-code 1.0.70 → 1.0.72
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 +3 -3
- package/src/compile/loadSchemas.js +69 -1
- package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +171 -44
- package/src/emit/coreFunction/templates/GenerateSeedDataDynamo_HdrInv.ejs +4 -1
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphData_HdrInv.ejs +4 -1
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_HdrInv.ejs +4 -1
- package/src/emit/coreFunction/templates/GenerateSeedDataGraphSchema_Main.ejs +10 -2
- package/src/emit/coreFunction/templates/GeneratedGraphNodeSchemas.ejs +17 -17
- package/src/emit/coreFunction/templates/GeneratedGraphRelSchemas.ejs +6 -6
- package/src/emit/coreFunction/templates/GeneratedTableConfigs.ejs +12 -12
- package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +195 -58
- package/src/emit/coreFunction/templates/InitialSetupRunner.ejs +175 -0
- package/src/emit/coreFunction/templates/InitialSetupRunner_initialSetup.ejs +9 -0
- package/src/emit/coreFunction/templates/InitialSetupRunner_seedDynamo.ejs +22 -0
- package/src/emit/coreFunction/templates/InitialSetupRunner_seedGraph.ejs +8 -0
- package/src/emit/coreFunction/templates/InitialSetupRunner_seedRemove.ejs +5 -0
- package/src/emit/coreFunction/templates/InitialSetupRunner_uploadSchema.ejs +33 -0
- package/src/emit/coreFunction/templates/InitialSetup_Main.ejs +9 -11
- package/src/emit/coreFunction/templates/UploadSchema_HdrInv.ejs +1 -3
- package/src/emit/coreFunction/templates/UploadSchema_Main.ejs +1 -1
- package/src/emit/crud/templates/CreateEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/FlowMain_Wbs.ejs +1 -2
- package/src/emit/crud/templates/GetEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/GetRangeEndpoint_Main.ejs +1 -1
- package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +1 -1
- package/src/emit/custom/emitCustomFlowApplicationArtifacts.js +4 -1
- package/src/emit/custom/templates/FlowEndpoint_Main.ejs +2 -2
- package/src/emit/custom/templates/FlowStep_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/CreateObject_Main.ejs +1 -1
- package/src/emit/custom/templates/s3/ReservedLimit_Main.ejs +1 -1
- package/src/emit/custom/templates/triggerCache/CheckTriggerCache_HdrSqs.ejs +2 -2
- package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/CreateRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/GetRelationship_Main.ejs +53 -32
- package/src/emit/relationship/templates/MoveRelationship_Main.ejs +1 -1
- package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +1 -1
- package/src/emit/resource/emitResourceArtifacts.js +65 -21
- package/src/emit/resource/templates/DynamoDBTable_Yaml.ejs +18 -18
- package/src/emit/resource/templates/FlowOut_Yaml.ejs +5 -5
- package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +9 -10
- package/src/emit/resource/templates/ResourceBeforeLogicalYaml.ejs +44 -44
- package/src/emit/resource/templates/ResourceSqsYaml.ejs +36 -36
- package/src/emit/resource/templates/ResourceYaml.ejs +48 -48
- package/src/emit/resource/templates/S3Bucket_Yaml.ejs +0 -1
- package/src/emit/resource/templates/S3Subscription_Yaml.ejs +6 -6
- package/src/emit/resource/templates/SharedResource_Yaml.ejs +4 -4
- package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +115 -115
- package/src/emit/resource/templates/WebSocketSubscription_Yaml.ejs +6 -6
- package/src/emit/shared/templates/FindData_HdrSqs.ejs +1 -1
- package/src/emit/shared/templates/FlowHandler_HdrApi.ejs +3 -1
- package/src/emit/shared/templates/FlowHandler_HdrDsq.ejs +5 -2
- package/src/emit/shared/templates/FlowHandler_HdrInv.ejs +3 -1
- package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +5 -2
- package/src/emit/shared/templates/PaginateProcessLogical_HdrDsq.ejs +1 -1
- package/src/emit/shared/templates/PaginateProcessLogical_HdrSqs.ejs +1 -1
- package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +2 -2
- package/src/emit/shared/templates/ProcessLogical_HdrSqs.ejs +1 -1
- package/src/generate.js +26 -5
- package/src/output/mergeHooks.js +13 -13
- package/src/output/validateArtifacts.js +10 -1
- package/test/publicApi.test.js +2 -2
- package/test/resourceArtifacts.test.js +8 -18
- package/docs/TriggeredCache Flow.drawio +0 -193
- package/docs/TriggeredCacheFlow.mmd +0 -47
|
@@ -15,13 +15,12 @@ You should have received a copy of the GNU Affero General Public License
|
|
|
15
15
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
// Auto-generated configurations
|
|
18
19
|
import Logger from '@izara_project/izara-core-library-logger';
|
|
19
|
-
import
|
|
20
|
+
import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
|
|
21
|
+
import snsSharedLib from '@izara_project/izara-core-library-sns';
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
import { prodTableConfigs, testTableConfigs } from './generated/GeneratedTableConfigs.js';
|
|
23
|
-
import { generatedGraphNodeSchemas } from './generated/GeneratedGraphNodeSchemas.js';
|
|
24
|
-
import { generatedGraphRelationshipSchemas } from './generated/GeneratedGraphRelSchemas.js';
|
|
23
|
+
const _izContext = { logger: Logger };
|
|
25
24
|
|
|
26
25
|
// ============================================================
|
|
27
26
|
// External Service Config
|
|
@@ -33,76 +32,214 @@ const externalServices = {
|
|
|
33
32
|
};
|
|
34
33
|
// <#/InitialSetupConfig_ExternalServices#>
|
|
35
34
|
|
|
36
|
-
// ============================================================
|
|
37
|
-
// Paths
|
|
38
|
-
// ============================================================
|
|
39
|
-
// <#InitialSetupConfig_Paths#>
|
|
40
|
-
const paths = {
|
|
41
|
-
seedGraphFilepath: './__test__/graph_seed_data/',
|
|
42
|
-
seedDataFilepath: './__test__/dynamodb_seed_data/default/',
|
|
43
|
-
seedUserFilepath: './__test__/userAccounts.json',
|
|
44
|
-
userId: ''
|
|
45
|
-
};
|
|
46
|
-
// <#/InitialSetupConfig_Paths#>
|
|
47
|
-
|
|
48
35
|
// ============================================================
|
|
49
36
|
// Table Configs (generated + manual merge)
|
|
50
37
|
// ============================================================
|
|
38
|
+
<%
|
|
39
|
+
const dynamoTableNames = new Set();
|
|
40
|
+
(objects || []).forEach(obj => {
|
|
41
|
+
if (obj && obj.storageResources) {
|
|
42
|
+
Object.values(obj.storageResources).forEach(res => {
|
|
43
|
+
if (res && res.tableName && (res.storageType === 'dynamo' || res.storageType === 'dynamoDB' || !res.storageType)) {
|
|
44
|
+
dynamoTableNames.add(res.tableName);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
-%>
|
|
51
50
|
const tableConfigs = {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
51
|
+
prod: {
|
|
52
|
+
Config: {},
|
|
53
|
+
<% dynamoTableNames.forEach(tableName => { -%>
|
|
54
|
+
<%= tableName %>: {}
|
|
55
|
+
<% }); -%>
|
|
56
|
+
// <#InitialSetupConfig_ExtraProdTableConfigs#>
|
|
57
|
+
// <#/InitialSetupConfig_ExtraProdTableConfigs#>
|
|
58
|
+
},
|
|
59
|
+
test: {
|
|
60
|
+
Config: {
|
|
61
|
+
clearDataWhenRefresh: true,
|
|
62
|
+
rawSource: false
|
|
63
|
+
},
|
|
64
|
+
<% dynamoTableNames.forEach(tableName => { -%>
|
|
65
|
+
<%= tableName %>: {
|
|
66
|
+
clearDataWhenRefresh: true
|
|
67
|
+
}
|
|
68
|
+
<% }); -%>
|
|
69
|
+
// <#InitialSetupConfig_ExtraTestTableConfigs#>
|
|
70
|
+
// <#/InitialSetupConfig_ExtraTestTableConfigs#>
|
|
71
|
+
}
|
|
61
72
|
};
|
|
62
73
|
|
|
63
74
|
// ============================================================
|
|
64
|
-
//
|
|
75
|
+
// SNS Subscriptions Config
|
|
65
76
|
// ============================================================
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
77
|
+
<%
|
|
78
|
+
const relSubs = [];
|
|
79
|
+
(relationshipGraphServiceTags || []).forEach(function(tag) {
|
|
80
|
+
relSubs.push({ serviceTag: tag, topicName: 'UpdateRelationship_Out', sqsEndpoint: 'UpdateRelationshipCompleteHdrSqs' });
|
|
81
|
+
relSubs.push({ serviceTag: tag, topicName: 'CreateRelationship_Out', sqsEndpoint: 'CreateRelationshipCompleteHdrSqs' });
|
|
82
|
+
relSubs.push({ serviceTag: tag, topicName: 'DeleteRelationship_Out', sqsEndpoint: 'DeleteRelationshipCompleteHdrSqs' });
|
|
83
|
+
relSubs.push({ serviceTag: tag, topicName: 'ChangeRelationshipType_Out', sqsEndpoint: 'ChangeRelationshipCompleteHdrSqs' });
|
|
84
|
+
relSubs.push({ serviceTag: tag, topicName: 'MoveRelationship_Out', sqsEndpoint: 'MoveRelationshipCompleteHdrSqs' });
|
|
85
|
+
});
|
|
73
86
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
87
|
+
const nodeSubs = [];
|
|
88
|
+
(objectGraphServiceTags || []).forEach(function(tag) {
|
|
89
|
+
nodeSubs.push({ serviceTag: tag, topicName: 'UpdateNode_Out', sqsEndpoint: 'UpdateCompleteHdrSqs' });
|
|
90
|
+
nodeSubs.push({ serviceTag: tag, topicName: 'CreateNode_Out', sqsEndpoint: 'CreateCompleteHdrSqs' });
|
|
91
|
+
});
|
|
92
|
+
-%>
|
|
93
|
+
const snsTopicSubscriptions = [
|
|
94
|
+
<% if (relSubs.length > 0) { -%>
|
|
95
|
+
// ------------------------------------------------------------
|
|
96
|
+
// Relationship Subscriptions
|
|
97
|
+
// ------------------------------------------------------------
|
|
98
|
+
<% relSubs.forEach(function(sub, idx) { -%>
|
|
99
|
+
{
|
|
100
|
+
serviceTag: '<%= sub.serviceTag %>',
|
|
101
|
+
topicName: '<%= sub.topicName %>',
|
|
102
|
+
sqsEndpoint: '<%= sub.sqsEndpoint %>'
|
|
103
|
+
},
|
|
104
|
+
<% }); -%>
|
|
105
|
+
<% } -%>
|
|
106
|
+
<% if (nodeSubs.length > 0) { -%>
|
|
107
|
+
|
|
108
|
+
// ------------------------------------------------------------
|
|
109
|
+
// Node Subscriptions
|
|
110
|
+
// ------------------------------------------------------------
|
|
111
|
+
<% nodeSubs.forEach(function(sub, idx) { -%>
|
|
112
|
+
{
|
|
113
|
+
serviceTag: '<%= sub.serviceTag %>',
|
|
114
|
+
topicName: '<%= sub.topicName %>',
|
|
115
|
+
sqsEndpoint: '<%= sub.sqsEndpoint %>'
|
|
116
|
+
},
|
|
117
|
+
<% }); -%>
|
|
118
|
+
<% } -%>
|
|
119
|
+
|
|
120
|
+
//(<additionalSubscription>)
|
|
121
|
+
//(</additionalSubscription>)
|
|
122
|
+
];
|
|
84
123
|
|
|
85
124
|
// ============================================================
|
|
86
|
-
//
|
|
125
|
+
// Lambda Role Configs
|
|
87
126
|
// ============================================================
|
|
88
|
-
function
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
127
|
+
function roleConfigs() {
|
|
128
|
+
const externalLambdaRole = [
|
|
129
|
+
<% if (crud && objectGraphServiceTags && objectGraphServiceTags.length > 0) { -%>
|
|
130
|
+
{
|
|
131
|
+
roleName: 'FlowObjects',
|
|
132
|
+
statement: [
|
|
133
|
+
<% objectGraphServiceTags.forEach(function(tag, idx) { -%>
|
|
134
|
+
{
|
|
135
|
+
Sid: 'FlowObjectsInvokeGetNode<%= tag %>',
|
|
136
|
+
Effect: 'Allow',
|
|
137
|
+
Action: ['lambda:InvokeFunction'],
|
|
138
|
+
Resource: [
|
|
139
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetNodeHdrInv', '<%= tag %>')}`
|
|
140
|
+
]
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
Sid: 'FlowObjectsPublishNodeTopics<%= tag %>',
|
|
145
|
+
Effect: 'Allow',
|
|
146
|
+
Action: ['sns:Publish'],
|
|
147
|
+
Resource: [
|
|
148
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'UpdateNode_In', '<%= tag %>')}`,
|
|
149
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'CreateNode_In', '<%= tag %>')}`
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
<% }); -%>
|
|
153
|
+
//(<createFlowObjectsRole>)
|
|
154
|
+
//(</createFlowObjectsRole>)
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
{
|
|
159
|
+
roleName: 'ProcFindData',
|
|
160
|
+
statement: [
|
|
161
|
+
<% objectGraphServiceTags.forEach(function(tag, idx) { -%>
|
|
162
|
+
{
|
|
163
|
+
Sid: 'ProcFindDataInvokeGetNode<%= tag %>',
|
|
164
|
+
Effect: 'Allow',
|
|
165
|
+
Action: ['lambda:InvokeFunction'],
|
|
166
|
+
Resource: [
|
|
167
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetNodeHdrInv', '<%= tag %>')}`
|
|
168
|
+
]
|
|
169
|
+
}
|
|
170
|
+
<% }); -%>
|
|
171
|
+
//(<createProcFindDataRole>)
|
|
172
|
+
//(</createProcFindDataRole>)
|
|
173
|
+
]
|
|
174
|
+
},
|
|
175
|
+
<% } -%>
|
|
176
|
+
|
|
177
|
+
<% if (hasRelationships && relationshipGraphServiceTags && relationshipGraphServiceTags.length > 0) { -%>
|
|
178
|
+
{
|
|
179
|
+
roleName: 'FlowRelationship',
|
|
180
|
+
statement: [
|
|
181
|
+
<% relationshipGraphServiceTags.forEach(function(tag, idx) { -%>
|
|
182
|
+
{
|
|
183
|
+
Sid: 'FlowRelationshipInvokeGetRelationship<%= tag %>',
|
|
184
|
+
Effect: 'Allow',
|
|
185
|
+
Action: ['lambda:InvokeFunction'],
|
|
186
|
+
Resource: [
|
|
187
|
+
`arn:aws:lambda:${process.env.iz_region}:${process.env.iz_accountId}:function:${lambdaSharedLib.lambdaFunctionName(_izContext, 'GetRelationshipHdrInv', '<%= tag %>')}`
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
|
|
191
|
+
{
|
|
192
|
+
Sid: 'FlowRelationshipPublishRelationshipTopics<%= tag %>',
|
|
193
|
+
Effect: 'Allow',
|
|
194
|
+
Action: ['sns:Publish'],
|
|
195
|
+
Resource: [
|
|
196
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'CreateRelationship_In', '<%= tag %>')}`,
|
|
197
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'UpdateRelationship_In', '<%= tag %>')}`,
|
|
198
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'DeleteRelationship_In', '<%= tag %>')}`,
|
|
199
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ChangeRelationship_In', '<%= tag %>')}`,
|
|
200
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'MoveRelationship_In', '<%= tag %>')}`
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
<% }); -%>
|
|
204
|
+
//(<createFlowRelationshipRole>)
|
|
205
|
+
//(</createFlowRelationshipRole>)
|
|
206
|
+
]
|
|
207
|
+
}
|
|
208
|
+
<% } -%>
|
|
209
|
+
<% s3Flows.forEach(function(flow) { -%> {
|
|
210
|
+
roleName: '<%= flow.roleName %>',
|
|
211
|
+
statement: [
|
|
212
|
+
{
|
|
213
|
+
Sid: '<%= flow.roleName %>RoleTest0',
|
|
214
|
+
Effect: 'Allow',
|
|
215
|
+
Action: ['sns:Publish'],
|
|
216
|
+
Resource: [
|
|
217
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ReservedDynamicUsage_In', 'AccountLimits')}`
|
|
218
|
+
]
|
|
219
|
+
},
|
|
93
220
|
|
|
94
|
-
|
|
95
|
-
|
|
221
|
+
{
|
|
222
|
+
Sid: '<%= flow.roleName %>RoleTest1',
|
|
223
|
+
Effect: 'Allow',
|
|
224
|
+
Action: ['sns:Publish'],
|
|
225
|
+
Resource: [
|
|
226
|
+
`arn:aws:sns:${process.env.iz_region}:${process.env.iz_accountId}:${snsSharedLib.snsTopicNameByFlowSchema(_izContext, 'ConfirmDynamicAfterUpload_In', 'AccountLimits')}`
|
|
227
|
+
]
|
|
228
|
+
}
|
|
229
|
+
//(<create<%= flow.roleName %>Role>)
|
|
230
|
+
//(</create<%= flow.roleName %>Role>)
|
|
231
|
+
]
|
|
232
|
+
} <% }); %>
|
|
233
|
+
//(<additionalRole>)
|
|
234
|
+
//(</additionalRole>)
|
|
235
|
+
];
|
|
96
236
|
|
|
97
|
-
return
|
|
237
|
+
return externalLambdaRole;
|
|
98
238
|
}
|
|
99
239
|
|
|
100
240
|
export default {
|
|
101
241
|
externalServices,
|
|
102
|
-
paths,
|
|
103
242
|
tableConfigs,
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
graphRelationshipSchemas,
|
|
107
|
-
graphVersionedDataSchemas
|
|
243
|
+
roleConfigs,
|
|
244
|
+
snsTopicSubscriptions
|
|
108
245
|
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI runner for InitialSetup commands.
|
|
3
|
+
* Usage: node app/initial_setup/generatedCode/source/runner.js <command> [dataSet]
|
|
4
|
+
*
|
|
5
|
+
* Commands:
|
|
6
|
+
* initialSetup:prod - Generate IAM roles + SNS subscriptions (prod)
|
|
7
|
+
* initialSetup:test - Generate IAM roles + SNS subscriptions (test)
|
|
8
|
+
* seedDynamo:prod - Generate seed data for prod env (DynamoDB) [optional dataset]
|
|
9
|
+
* seedDynamo:test - Generate seed data for test env (DynamoDB) [optional dataset]
|
|
10
|
+
* seedRemove:prod - Remove seed data from prod env (DynamoDB)
|
|
11
|
+
* seedRemove:test - Remove seed data from test env (DynamoDB)
|
|
12
|
+
* seedGraph:test - Generate seed data for graph
|
|
13
|
+
* uploadSchema - Upload object schema
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import yaml from 'yaml';
|
|
18
|
+
import { join } from 'path';
|
|
19
|
+
|
|
20
|
+
// 1. Parse serverless config and set environment variables
|
|
21
|
+
const configPath = join(process.cwd(), '..', 'config', 'serverless.config.yml');
|
|
22
|
+
if (fs.existsSync(configPath)) {
|
|
23
|
+
const serverlessConfig = yaml.parse(fs.readFileSync(configPath, 'utf8'));
|
|
24
|
+
const izConfig = serverlessConfig.main_config || {};
|
|
25
|
+
process.env.iz_stage = izConfig.iz_stage || process.env.iz_stage;
|
|
26
|
+
process.env.iz_region = izConfig.iz_region || process.env.iz_region;
|
|
27
|
+
process.env.iz_accountId = izConfig.iz_accountId || process.env.iz_accountId;
|
|
28
|
+
process.env.iz_serviceTag =
|
|
29
|
+
izConfig.iz_serviceTag || process.env.iz_serviceTag;
|
|
30
|
+
process.env.iz_resourcePrefix =
|
|
31
|
+
izConfig.iz_resourcePrefix ||
|
|
32
|
+
process.env.iz_resourcePrefix ||
|
|
33
|
+
`${process.env.iz_serviceTag}${process.env.iz_stage}`;
|
|
34
|
+
process.env.AWS_REGION = process.env.iz_region;
|
|
35
|
+
} else {
|
|
36
|
+
console.warn(
|
|
37
|
+
`[WARN] Config not found at ${configPath}. Using existing process.env variables.`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 2. Dynamic import to ensure SDKs use the injected process.env
|
|
42
|
+
const { default: initialSetupSharedLib } =
|
|
43
|
+
await import('@izara_project/izara-core-library-initial-setup');
|
|
44
|
+
const { default: config } = await import('./InitialSetupConfig.js');
|
|
45
|
+
const { default: CorrelationIds } =
|
|
46
|
+
await import('@izara_project/izara-core-library-correlation-ids');
|
|
47
|
+
const { default: Logger } =
|
|
48
|
+
await import('@izara_project/izara-core-library-logger');
|
|
49
|
+
const { consts } = await import('@izara_project/izara-core-library-core');
|
|
50
|
+
|
|
51
|
+
function _createContext() {
|
|
52
|
+
const _izContext = { CorrelationIds, Logger };
|
|
53
|
+
_izContext.correlationIds = new CorrelationIds();
|
|
54
|
+
_izContext.correlationIds.set(
|
|
55
|
+
consts.BASE_USER_ID,
|
|
56
|
+
process.env.iz_userId || ''
|
|
57
|
+
);
|
|
58
|
+
_izContext.correlationIds.set(
|
|
59
|
+
consts.RESOURCE_USE_USER_ID,
|
|
60
|
+
process.env.iz_userId || ''
|
|
61
|
+
);
|
|
62
|
+
_izContext.logger = Logger;
|
|
63
|
+
return _izContext;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const commands = {
|
|
67
|
+
'initialSetup:prod': async (_izContext) => {
|
|
68
|
+
const { default: fn } = await import('./commands/initialSetup.js');
|
|
69
|
+
await fn('Prod', _izContext, initialSetupSharedLib, config);
|
|
70
|
+
},
|
|
71
|
+
'initialSetup:test': async (_izContext) => {
|
|
72
|
+
const { default: fn } = await import('./commands/initialSetup.js');
|
|
73
|
+
await fn('Test', _izContext, initialSetupSharedLib, config);
|
|
74
|
+
},
|
|
75
|
+
'seedDynamo:prod': async (_izContext, dataSet) => {
|
|
76
|
+
const { default: fn } = await import('./commands/seedDynamo.js');
|
|
77
|
+
await fn('prod', dataSet, _izContext, initialSetupSharedLib, config);
|
|
78
|
+
},
|
|
79
|
+
'seedDynamo:test': async (_izContext, dataSet) => {
|
|
80
|
+
const { default: fn } = await import('./commands/seedDynamo.js');
|
|
81
|
+
await fn('test', dataSet, _izContext, initialSetupSharedLib, config);
|
|
82
|
+
},
|
|
83
|
+
'seedRemove:prod': async (_izContext) => {
|
|
84
|
+
const { default: fn } = await import('./commands/seedRemove.js');
|
|
85
|
+
await fn('prod', _izContext, initialSetupSharedLib, config);
|
|
86
|
+
},
|
|
87
|
+
'seedRemove:test': async (_izContext) => {
|
|
88
|
+
const { default: fn } = await import('./commands/seedRemove.js');
|
|
89
|
+
await fn('test', _izContext, initialSetupSharedLib, config);
|
|
90
|
+
},
|
|
91
|
+
'seedGraph:test': async (_izContext) => {
|
|
92
|
+
const { default: fn } = await import('./commands/seedGraph.js');
|
|
93
|
+
await fn(_izContext, initialSetupSharedLib, config);
|
|
94
|
+
},
|
|
95
|
+
uploadSchema: async (_izContext) => {
|
|
96
|
+
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
97
|
+
await fn(_izContext);
|
|
98
|
+
},
|
|
99
|
+
'uploadSchema:test': async (_izContext) => {
|
|
100
|
+
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
101
|
+
await fn(_izContext);
|
|
102
|
+
},
|
|
103
|
+
'uploadSchema:prod': async (_izContext) => {
|
|
104
|
+
const { default: fn } = await import('./commands/uploadSchema.js');
|
|
105
|
+
await fn(_izContext);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// --- Main ---
|
|
110
|
+
const command = process.argv[2];
|
|
111
|
+
const dataSet = process.argv[3];
|
|
112
|
+
|
|
113
|
+
function showHelp() {
|
|
114
|
+
console.log(`\nUsage: node runner.js <command> [dataSet]\n`);
|
|
115
|
+
console.log(`Available Commands:`);
|
|
116
|
+
console.log(
|
|
117
|
+
` initialSetup:prod Generate IAM roles & SNS subscriptions for production`
|
|
118
|
+
);
|
|
119
|
+
console.log(
|
|
120
|
+
` initialSetup:test Generate IAM roles & SNS subscriptions for testing`
|
|
121
|
+
);
|
|
122
|
+
console.log(
|
|
123
|
+
` seedDynamo:prod Seed DynamoDB for production [optional dataset subfolder]`
|
|
124
|
+
);
|
|
125
|
+
console.log(
|
|
126
|
+
` seedDynamo:test Seed DynamoDB for testing [optional dataset subfolder]`
|
|
127
|
+
);
|
|
128
|
+
console.log(
|
|
129
|
+
` seedRemove:prod Remove seed data from production DynamoDB tables`
|
|
130
|
+
);
|
|
131
|
+
console.log(
|
|
132
|
+
` seedRemove:test Remove seed data from testing DynamoDB tables`
|
|
133
|
+
);
|
|
134
|
+
console.log(` seedGraph:test Seed Graph data`);
|
|
135
|
+
console.log(` uploadSchema Upload object schema\n`);
|
|
136
|
+
console.log(`Examples:`);
|
|
137
|
+
console.log(` node runner.js seedDynamo:test`);
|
|
138
|
+
console.log(` node runner.js seedDynamo:test flow-a`);
|
|
139
|
+
console.log(` npm run seedDynamo:test -- flow-a\n`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (
|
|
143
|
+
!command ||
|
|
144
|
+
command === '--help' ||
|
|
145
|
+
command === '-h' ||
|
|
146
|
+
!commands[command]
|
|
147
|
+
) {
|
|
148
|
+
showHelp();
|
|
149
|
+
if (command === '--help' || command === '-h') {
|
|
150
|
+
process.exit(0);
|
|
151
|
+
} else {
|
|
152
|
+
process.exit(1);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const _izContext = _createContext();
|
|
157
|
+
|
|
158
|
+
let dataSetSuffix = '';
|
|
159
|
+
if (dataSet) {
|
|
160
|
+
dataSetSuffix = `:${dataSet}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
await commands[command](_izContext, dataSet);
|
|
165
|
+
console.log(
|
|
166
|
+
`\n✅ [${command}${dataSetSuffix}] completed successfully`
|
|
167
|
+
);
|
|
168
|
+
process.exit(0);
|
|
169
|
+
} catch (err) {
|
|
170
|
+
console.error(
|
|
171
|
+
`\n❌ [${command}${dataSetSuffix}] failed:`,
|
|
172
|
+
err
|
|
173
|
+
);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export default async function initialSetup(env, _izContext, lib, config) {
|
|
2
|
+
console.log(`======== GeneratingIAMRoles ${env} ========`);
|
|
3
|
+
await lib.generateIamRoleExternalService(config.roleConfigs());
|
|
4
|
+
console.log('-------- Finish GeneratingIAMRoles --------');
|
|
5
|
+
|
|
6
|
+
console.log(`======== Setup ${env}: SNS Subscriptions ========`);
|
|
7
|
+
await lib.generateTopicSubscriptions(config.snsTopicSubscriptions);
|
|
8
|
+
console.log('-------- Finish generate subscribe --------');
|
|
9
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default async function seedDynamo(
|
|
2
|
+
env,
|
|
3
|
+
dataSet,
|
|
4
|
+
_izContext,
|
|
5
|
+
lib,
|
|
6
|
+
config
|
|
7
|
+
) {
|
|
8
|
+
let label = env;
|
|
9
|
+
if (dataSet) {
|
|
10
|
+
label = `${env} (${dataSet})`;
|
|
11
|
+
}
|
|
12
|
+
console.log(`======== GeneratingSeedDataDynamo ${label} ========`);
|
|
13
|
+
await lib.generateSeedDataByEnv(
|
|
14
|
+
_izContext,
|
|
15
|
+
env,
|
|
16
|
+
dataSet,
|
|
17
|
+
config.tableConfigs,
|
|
18
|
+
'./initial_setup/generatedCode/data/dynamo',
|
|
19
|
+
{} // bucketS3
|
|
20
|
+
);
|
|
21
|
+
console.log('-------- Finish GenerateSeedDataDynamo --------');
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default async function seedGraph(_izContext, lib, config) {
|
|
2
|
+
console.log('======== GeneratingSeedDataGraph ========');
|
|
3
|
+
await lib.generateSeedDataGraphHandler(
|
|
4
|
+
_izContext,
|
|
5
|
+
'./initial_setup/generatedCode/data/graph'
|
|
6
|
+
);
|
|
7
|
+
console.log('-------- Finish GeneratingSeedDataGraph --------');
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { uploadObjSchema } from '@izara_project/izara-core-library-service-schemas';
|
|
2
|
+
|
|
3
|
+
const SERVICE_TAG = {
|
|
4
|
+
TRANSLATIONS: 'Translations',
|
|
5
|
+
GRAPH_HANDLER: 'GraphHandler',
|
|
6
|
+
TRANSLATE_IDS: 'TranslateIds',
|
|
7
|
+
USER_ACCOUNT: 'UserAccount',
|
|
8
|
+
MEDIA: 'Media'
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const ignoreExternalServices = {
|
|
12
|
+
[SERVICE_TAG.TRANSLATIONS]: false,
|
|
13
|
+
[SERVICE_TAG.GRAPH_HANDLER]: false,
|
|
14
|
+
[SERVICE_TAG.USER_ACCOUNT]: false,
|
|
15
|
+
[SERVICE_TAG.TRANSLATE_IDS]: false,
|
|
16
|
+
[SERVICE_TAG.MEDIA]: false
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default async function uploadSchema(_izContext) {
|
|
20
|
+
console.log('======== UploadSchema ========');
|
|
21
|
+
try {
|
|
22
|
+
_izContext.logger.debug('uploadSchema _izContext: ', _izContext);
|
|
23
|
+
|
|
24
|
+
await uploadObjSchema.uploadObjectSchemaByUseCase(_izContext, {
|
|
25
|
+
ignoreExternalServices: ignoreExternalServices
|
|
26
|
+
});
|
|
27
|
+
console.log('-------- Finish UploadSchema --------');
|
|
28
|
+
return 'upload successfully';
|
|
29
|
+
} catch (err) {
|
|
30
|
+
_izContext.logger.error('error LambdaFunction: ', err);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -9,27 +9,25 @@ const initialSetup = async (event, context, izContext) => {
|
|
|
9
9
|
logger: Logger
|
|
10
10
|
};
|
|
11
11
|
try {
|
|
12
|
-
|
|
12
|
+
console.log('======== InitialSetup start ========');
|
|
13
13
|
|
|
14
14
|
// ====== Generate IAM Role of function ======
|
|
15
15
|
await initialSetupSharedLib.generateIamRoleExternalService(
|
|
16
|
-
|
|
17
|
-
await config.roleConfigs() // If implemented in config
|
|
16
|
+
config.roleConfigs() // If implemented in config
|
|
18
17
|
);
|
|
19
|
-
|
|
18
|
+
console.log('-------- Finish generate role IAM --------');
|
|
20
19
|
|
|
21
20
|
// ====== Generate Seed Data ======
|
|
22
21
|
// await initialSetupSharedLib.generateSeedData(_izContext, config);
|
|
23
|
-
//
|
|
22
|
+
// console.log('------ Finish InitialSetup generateSeedData ------');
|
|
24
23
|
|
|
25
24
|
// ====== Generate Subscriptions of SNS topic ======
|
|
26
25
|
await initialSetupSharedLib.generateTopicSubscriptions(
|
|
27
|
-
_izContext,
|
|
28
26
|
config.snsTopicSubscriptions // If implemented in config
|
|
29
27
|
);
|
|
30
|
-
|
|
28
|
+
console.log('-------- Finish generate subscribe --------');
|
|
31
29
|
|
|
32
|
-
<% if (hasGenerateGraph) { -%>
|
|
30
|
+
<% if (hasGenerateGraph) { -%>
|
|
33
31
|
// ====== Generate Schema for graphDb ======
|
|
34
32
|
// await initialSetupSharedLib.generateSchema(_izContext, config.graphNodeSchemas(), 'node');
|
|
35
33
|
// await initialSetupSharedLib.generateSchema(_izContext, config.graphRelationshipSchemas(), 'relationship');
|
|
@@ -38,12 +36,12 @@ const initialSetup = async (event, context, izContext) => {
|
|
|
38
36
|
// await initialSetupSharedLib.generateSchema(_izContext, versionedDataNodeSchemas, 'node');
|
|
39
37
|
// await initialSetupSharedLib.generateSchema(_izContext, versionedDataRelationshipSchemas, 'relationship');
|
|
40
38
|
|
|
41
|
-
//
|
|
42
|
-
<% } -%>
|
|
39
|
+
// console.log('-------- Finished generate main schema --------');
|
|
40
|
+
<% } -%>
|
|
43
41
|
|
|
44
42
|
return 'InitialSetup Complete';
|
|
45
43
|
} catch (err) {
|
|
46
|
-
|
|
44
|
+
console.error('Error InitialSetup (prod)', err);
|
|
47
45
|
throw err;
|
|
48
46
|
}
|
|
49
47
|
};
|
|
@@ -25,9 +25,7 @@ const main = middleware.wrap(async (event, context, callback) => {
|
|
|
25
25
|
|
|
26
26
|
try {
|
|
27
27
|
// invoke LambdaFunction
|
|
28
|
-
return await uploadSchema.uploadSchema(
|
|
29
|
-
event._izContext
|
|
30
|
-
);
|
|
28
|
+
return await uploadSchema.uploadSchema(event._izContext);
|
|
31
29
|
} catch (err) {
|
|
32
30
|
event._izContext.logger.error('Error, LambdaFunctionHdrInv: ', err);
|
|
33
31
|
throw err;
|
|
@@ -31,6 +31,7 @@ const { postToConnection } = webSocket;
|
|
|
31
31
|
|
|
32
32
|
//(<optionalRequire>)
|
|
33
33
|
//(</optionalRequire>)
|
|
34
|
+
|
|
34
35
|
/**
|
|
35
36
|
*
|
|
36
37
|
*
|
|
@@ -42,10 +43,8 @@ const { postToConnection } = webSocket;
|
|
|
42
43
|
* @param {Object} requestParams.identifiers - identifiers for get data
|
|
43
44
|
* @param {Object} requestParams.additionalRequest - additionalRequest
|
|
44
45
|
*
|
|
45
|
-
*
|
|
46
46
|
* @returns {object} description of return value
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
48
|
export default async function <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>(
|
|
50
49
|
_izContext,
|
|
51
50
|
requestParams,
|
|
@@ -58,7 +58,7 @@ import { sns } from '@izara_project/izara-core-library-external-request';
|
|
|
58
58
|
export default async function <%- flowTag %>(
|
|
59
59
|
_izContext,
|
|
60
60
|
requestParams,
|
|
61
|
-
callingFlowConfig = {}
|
|
61
|
+
callingFlowConfig = {}
|
|
62
62
|
//(<additionalParams>)
|
|
63
63
|
//(</additionalParams>)
|
|
64
64
|
) {
|