@izara_project/izara-core-generate-service-code 1.0.84 → 1.0.86

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 (46) hide show
  1. package/package.json +1 -1
  2. package/src/compile/compileProject.js +1 -2
  3. package/src/compile/loadSchemas.js +29 -17
  4. package/src/emit/coreFunction/emitCoreFunctionArtifacts.js +6 -0
  5. package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +26 -6
  6. package/src/emit/crud/crudActionPlan.js +3 -1
  7. package/src/emit/crud/emitCrudApplicationArtifacts.js +47 -8
  8. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +136 -25
  9. package/src/emit/crud/templates/CreateConfirmComplete_Main.ejs +54 -0
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +248 -181
  11. package/src/emit/crud/templates/CreateLogicalLib.ejs +1155 -293
  12. package/src/emit/crud/templates/CreateNodeCallback_Main.ejs +221 -0
  13. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +36 -4
  14. package/src/emit/crud/templates/FlowEndpointRbacCallback_Main.ejs +20 -120
  15. package/src/emit/crud/templates/FlowEndpoint_HdrWbs.ejs +76 -14
  16. package/src/emit/crud/templates/FlowMain_Wbs.ejs +31 -35
  17. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +35 -3
  18. package/src/emit/crud/templates/UpdateLogicalLib.ejs +754 -353
  19. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +5 -2
  20. package/src/emit/rbac/emitRbacApplicationArtifacts.js +102 -6
  21. package/src/emit/rbac/templates/CancelUsage_Main.ejs +82 -22
  22. package/src/emit/rbac/templates/ConfirmUsage_Main.ejs +130 -14
  23. package/src/emit/rbac/templates/CreateTargetRole_Main.ejs +61 -12
  24. package/src/emit/rbac/templates/DeleteTargetRole_Main.ejs +96 -0
  25. package/src/emit/rbac/templates/GetMyPermissions_Main.ejs +106 -0
  26. package/src/emit/rbac/templates/GetTargetRole_Main.ejs +62 -0
  27. package/src/emit/rbac/templates/ReservedDynamicUsage_Main.ejs +30 -11
  28. package/src/emit/rbac/templates/UpdateTargetRole_Main.ejs +107 -0
  29. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +40 -15
  30. package/src/emit/rbac/templates/UserRoleMutation_Main.ejs +22 -7
  31. package/src/emit/resource/emitResourceArtifacts.js +52 -2
  32. package/src/emit/resource/templates/GeneratedLambdaRoleServiceConfig.ejs +6 -2
  33. package/src/emit/resource/templates/SystemDynamoDB_Yaml.ejs +2 -0
  34. package/src/emit/shared/templates/FlowHandler_HdrSqs.ejs +1 -1
  35. package/src/emit/system/templates/WebSocketConnect_Yaml.ejs +0 -1
  36. package/src/emit/systemText/emitSystemTextSchemas.js +5 -2
  37. package/src/generate.js +18 -12
  38. package/src/generateResources/IntTest/generateResources/generateResources.js +1 -1
  39. package/src/generateResources/IntTest/generateTests/generateTemplate.js +1 -1
  40. package/src/generateResources/IntTest/upload/uploadIntTest.js +8 -2
  41. package/test/createTargetRoleHandler.test.js +42 -1
  42. package/test/crudApplicationArtifacts.test.js +53 -0
  43. package/test/dynamicCrudFlowSchemas.test.js +16 -2
  44. package/test/dynamicRbacFlowSchemas.test.js +5 -2
  45. package/test/publicApi.test.js +18 -14
  46. package/test/resourceArtifacts.test.js +24 -0
@@ -33,34 +33,27 @@ const { postToConnection } = webSocket;
33
33
  //(</optionalRequire>)
34
34
 
35
35
  /**
36
- *
37
- *
38
- * description of function.
36
+ * WebSocket handler entry for <%- upperCaseFlowTag %> Flow
39
37
  * @param {Object} _izContext
40
- * @param {CorrelationIds} _izContext.correlationIds - property of _izContext
41
- * @param {Logger} _izContext.logger - property of _izContext
42
- * @param {Object} requestParams - request params
43
- * @param {Object} requestParams.identifiers - identifiers for get data
44
- * @param {Object} requestParams.additionalRequest - additionalRequest
45
- *
46
- * @returns {object} description of return value
38
+ * @param {CorrelationIds} _izContext.correlationIds - Context correlation IDs
39
+ * @param {Logger} _izContext.logger - Context logger
40
+ * @param {Object} requestParams - Request parameters
41
+ * @param {Object} callingFlowConfig - Calling flow configuration
42
+ * @returns {Promise<void>}
47
43
  */
48
44
  export default async function <%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>(
49
45
  _izContext,
50
46
  requestParams,
51
- //(<additionalParams>)
52
- //(</additionalParams>)
53
- callingFlowConfig = {}
47
+ callingFlowConfig
54
48
  ) {
55
49
  try {
56
- _izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> _izContext', _izContext);
57
- _izContext.logger.debug('<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> requestParams', requestParams);
58
50
  _izContext.logger.debug(
59
- '<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %> callingFlowConfig',
51
+ `[${process.env.iz_serviceTag}:<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>Wbs] started`,
52
+ requestParams,
60
53
  callingFlowConfig
61
54
  );
62
55
 
63
- let flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
56
+ const flowSchema = await getObjectSchema.getFlowSchemaS3WithCache(
64
57
  _izContext,
65
58
  {
66
59
  flowTag: '<%- flowTag %>',
@@ -70,6 +63,23 @@ export default async function <%- typeof functionName !== 'undefined' ? function
70
63
 
71
64
  _izContext.logger.debug('flowSchema', flowSchema);
72
65
 
66
+ const connectionId = _izContext.correlationIds?.get(coreConsts.CONNECTION_ID);
67
+
68
+ if (!flowSchema) {
69
+ if (connectionId) {
70
+ await postToConnection(
71
+ _izContext,
72
+ {
73
+ message: {
74
+ error: `flowTag not found ${requestParams.action}`
75
+ }
76
+ },
77
+ connectionId
78
+ );
79
+ }
80
+ throw new NoRetryError(`flowTag not found ${requestParams.action}`);
81
+ }
82
+
73
83
  if (
74
84
  flowSchema.initiateBy === 'user' ||
75
85
  flowSchema.initiateBy === 'systemWithUser'
@@ -77,24 +87,9 @@ export default async function <%- typeof functionName !== 'undefined' ? function
77
87
  _izContext.correlationIds.set(coreConsts.USER_AGENT, 'webSocket');
78
88
  }
79
89
 
80
- let connectionId = _izContext.correlationIds.get(coreConsts.CONNECTION_ID);
81
-
82
- if (!flowSchema) {
83
- await postToConnection(
84
- _izContext,
85
- {
86
- message: {
87
- error: `flowTag not found ${requestParams.action}`
88
- }
89
- },
90
- connectionId
91
- );
92
- throw new NoRetryError(`flowTag not found ${requestParams.action}`);
93
- }
94
-
95
90
  let messageObject = requestParams;
96
91
 
97
- // create callingFlow
92
+ // Attach calling flow configuration pointing to WebSocketCompleteHdrSqs
98
93
  messageObject =
99
94
  callingFlowSharedLib.addCallingFlowToSnsRequestMessageObject(
100
95
  messageObject,
@@ -110,17 +105,18 @@ export default async function <%- typeof functionName !== 'undefined' ? function
110
105
  )
111
106
  );
112
107
 
113
- let sendMessageToEndpoint = {
108
+ const sendMessageToEndpoint = {
114
109
  Message: JSON.stringify(messageObject),
115
110
  TopicArn: snsSharedLib.snsTopicArnByFlowSchema(
116
111
  _izContext,
117
112
  '<%- upperCaseFlowTag %>_In'
118
113
  )
119
114
  };
115
+
120
116
  _izContext.logger.debug('sendMessageToEndpoint', sendMessageToEndpoint);
121
117
  await sns.publishAsync(_izContext, sendMessageToEndpoint);
122
118
  } catch (err) {
123
- _izContext.logger.error(`[${process.env.iz_serviceTag}:<%- typeof functionName !== undefined ? functionName : upperCaseFlowTag %>Wbs] error:`, err);
119
+ _izContext.logger.error(`[${process.env.iz_serviceTag}:<%- typeof functionName !== 'undefined' ? functionName : upperCaseFlowTag %>Wbs] error:`, err);
124
120
  throw err;
125
121
  }
126
122
  }
@@ -99,6 +99,7 @@ export default async function <%- flowTag %>(
99
99
  _izContext.correlationIds?.get(coreConsts.SUBMITTED_BY_USER_ID);
100
100
 
101
101
  targetIdentifiers = requestParams.targetIdentifiers;
102
+ delete requestParams.targetIdentifiers;
102
103
 
103
104
  if (!targetIdentifiers && objectSchema.belongTo?.objectType === 'user' && submittedByUserId) {
104
105
  targetIdentifiers = { submittedByUserId };
@@ -113,12 +114,11 @@ export default async function <%- flowTag %>(
113
114
  if (!targetIdentifiers.submittedByUserId && submittedByUserId) {
114
115
  targetIdentifiers.submittedByUserId = submittedByUserId;
115
116
  }
116
- requestParams.targetIdentifiers = targetIdentifiers;
117
117
  }
118
118
 
119
119
  _izContext.logger.debug(`[${process.env.iz_serviceTag}:<%- flowTag %>] Identity & Target Context Resolved:`, {
120
120
  submittedByUserId: requestParams.submittedByUserId,
121
- targetIdentifiers: requestParams.targetIdentifiers,
121
+ targetIdentifiers,
122
122
  belongTo: objectSchema.belongTo,
123
123
  generatedBy: objectSchema.generatedBy
124
124
  });
@@ -129,7 +129,38 @@ export default async function <%- flowTag %>(
129
129
  }
130
130
 
131
131
  // ── Build identifiers used by asynchronous processing ────────────────────
132
- const identifiers = requestParams.objInstanceFull.identifiers;
132
+ const identifiers = requestParams.objInstanceFull?.identifiers;
133
+
134
+ if (!objectSchema.hasOwnProperty('belongTo')) {
135
+ if (!targetIdentifiers && identifiers) {
136
+ targetIdentifiers = { ...identifiers };
137
+ } else if (targetIdentifiers && identifiers) {
138
+ for (const [key, value] of Object.entries(identifiers)) {
139
+ if (targetIdentifiers[key] === undefined && value !== undefined) {
140
+ targetIdentifiers[key] = value;
141
+ }
142
+ }
143
+ }
144
+ if (targetIdentifiers) {
145
+ if (!targetIdentifiers.submittedByUserId && submittedByUserId) {
146
+ targetIdentifiers.submittedByUserId = submittedByUserId;
147
+ }
148
+ }
149
+ }
150
+
151
+ if (targetIdentifiers && identifiers) {
152
+ for (const [key, value] of Object.entries(identifiers)) {
153
+ if (
154
+ targetIdentifiers[key] !== undefined &&
155
+ value !== undefined &&
156
+ targetIdentifiers[key] !== value
157
+ ) {
158
+ errorsFound.push(
159
+ `targetIdentifiers.${key} must match objInstanceFull.identifiers.${key}`
160
+ );
161
+ }
162
+ }
163
+ }
133
164
 
134
165
  //(<validateBeforeUpdate>)
135
166
  //(</validateBeforeUpdate>)
@@ -182,6 +213,7 @@ export default async function <%- flowTag %>(
182
213
  },
183
214
  parameterGroups,
184
215
  {
216
+ targetIdentifiers,
185
217
  rbacObjType: {
186
218
  serviceTag: <%- rbacServiceTags.length === 1 ? rbacServiceTags[0] : `{ ${Object.entries(rbacServiceTagMap).map(([k, v]) => `'${k}': ${v}`).join(', ')} }[requestParams.objectType] || process.env.iz_serviceTag` %>
187
219
  },