@izara_project/izara-core-generate-service-code 1.0.89 → 1.0.91

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 (56) hide show
  1. package/package.json +1 -1
  2. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +2 -2
  3. package/src/emit/crud/templates/CreateAfterHookCallback_Main.ejs +6 -6
  4. package/src/emit/crud/templates/CreateBeforeHookCallback_Main.ejs +3 -3
  5. package/src/emit/crud/templates/CreateComplete_Main.ejs +153 -28
  6. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +18 -18
  7. package/src/emit/crud/templates/CreateLogicalLib.ejs +83 -54
  8. package/src/emit/crud/templates/CreateNodeCallback_Main.ejs +32 -25
  9. package/src/emit/crud/templates/DeleteAfterHookCallback_Main.ejs +5 -5
  10. package/src/emit/crud/templates/DeleteBeforeHookCallback_Main.ejs +3 -3
  11. package/src/emit/crud/templates/DeleteComplete_Main.ejs +23 -23
  12. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +15 -15
  13. package/src/emit/crud/templates/DeleteLogicalLib.ejs +20 -22
  14. package/src/emit/crud/templates/FlowEndpointRbacCallback_Main.ejs +3 -3
  15. package/src/emit/crud/templates/UpdateAfterHookCallback_Main.ejs +5 -5
  16. package/src/emit/crud/templates/UpdateBeforeHookCallback_Main.ejs +3 -3
  17. package/src/emit/crud/templates/UpdateComplete_Main.ejs +22 -22
  18. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +15 -15
  19. package/src/emit/crud/templates/UpdateLogicalLib.ejs +33 -36
  20. package/src/emit/custom/templates/FlowEndpointRbacCallback_Main.ejs +7 -7
  21. package/src/emit/custom/templates/s3/ConfirmReserved_HdrSqs.ejs +3 -3
  22. package/src/emit/custom/templates/s3/ConfirmReserved_Main.ejs +3 -3
  23. package/src/emit/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +3 -3
  24. package/src/emit/custom/templates/s3/CreatePreSignUrl_Main.ejs +4 -4
  25. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +26 -6
  26. package/src/emit/rbac/emitRbacApplicationArtifacts.js +40 -13
  27. package/src/emit/rbac/templates/UserRbacFlow_Main.ejs +33 -20
  28. package/src/emit/relationship/emitDynamicRelationshipFlowSchemas.js +1 -1
  29. package/src/emit/relationship/templates/ChangeRelationshipComplete_HdrSqs.ejs +2 -2
  30. package/src/emit/relationship/templates/ChangeRelationshipComplete_Main.ejs +6 -6
  31. package/src/emit/relationship/templates/ChangeRelationship_Main.ejs +17 -17
  32. package/src/emit/relationship/templates/CreateRelationshipComplete_HdrSqs.ejs +2 -2
  33. package/src/emit/relationship/templates/CreateRelationshipComplete_Main.ejs +6 -6
  34. package/src/emit/relationship/templates/CreateRelationship_Main.ejs +14 -14
  35. package/src/emit/relationship/templates/DeleteRelationshipComplete_HdrSqs.ejs +2 -2
  36. package/src/emit/relationship/templates/DeleteRelationshipComplete_Main.ejs +6 -6
  37. package/src/emit/relationship/templates/DeleteRelationship_Main.ejs +10 -10
  38. package/src/emit/relationship/templates/GetRelationshipComplete_HdrSqs.ejs +2 -2
  39. package/src/emit/relationship/templates/GetRelationshipComplete_Main.ejs +5 -5
  40. package/src/emit/relationship/templates/GetRelationship_Main.ejs +9 -9
  41. package/src/emit/relationship/templates/MoveRelationshipComplete_HdrSqs.ejs +2 -2
  42. package/src/emit/relationship/templates/MoveRelationshipComplete_Main.ejs +6 -6
  43. package/src/emit/relationship/templates/MoveRelationship_Main.ejs +15 -15
  44. package/src/emit/relationship/templates/UpdateRelationshipComplete_HdrSqs.ejs +2 -2
  45. package/src/emit/relationship/templates/UpdateRelationshipComplete_Main.ejs +6 -6
  46. package/src/emit/relationship/templates/UpdateRelationship_Main.ejs +11 -11
  47. package/src/emit/resource/emitResourceArtifacts.js +48 -18
  48. package/src/emit/shared/templates/FindData_Main.ejs +19 -19
  49. package/src/emit/shared/templates/PaginateProcessLogical_Main.ejs +3 -3
  50. package/src/emit/shared/templates/ProcessLogical_Main.ejs +15 -15
  51. package/test/createTargetRoleHandler.test.js +70 -9
  52. package/test/crudApplicationArtifacts.test.js +98 -3
  53. package/test/dynamicCrudFlowSchemas.test.js +2 -2
  54. package/test/dynamicRbacFlowSchemas.test.js +32 -4
  55. package/test/relationshipApplicationArtifacts.test.js +1 -1
  56. package/test/resourceArtifacts.test.js +42 -0
@@ -67,10 +67,10 @@ const PREFIX = {
67
67
  * Loads ObjectSchema and resolves submittedByUserId and targetIdentifiers
68
68
  * @param {Object} _izContext - Izara context object
69
69
  * @param {Object} requestParams - Incoming request parameters
70
- * @param {Array<string>} errorsFound - Array to collect validation errors
70
+ * @param {Array<string>} foundErrors - Array to collect validation errors
71
71
  * @returns {Promise<{ objType: string, objectSchema: Object }>}
72
72
  */
73
- export async function resolveSchemaAndIdentity(_izContext, requestParams, errorsFound) {
73
+ export async function resolveSchemaAndIdentity(_izContext, requestParams, foundErrors) {
74
74
  const objType = createObjType(requestParams.objectType);
75
75
  const objectSchema = await getObjectSchema.getObjSchemaS3WithHierarchy(
76
76
  _izContext,
@@ -89,19 +89,19 @@ export async function resolveSchemaAndIdentity(_izContext, requestParams, errors
89
89
 
90
90
  targetIdentifiers = requestParams.targetIdentifiers;
91
91
 
92
- if (!targetIdentifiers && submittedByUserId) {
92
+ if (
93
+ !targetIdentifiers &&
94
+ objectSchema.belongTo?.objectType === 'user' &&
95
+ submittedByUserId
96
+ ) {
93
97
  targetIdentifiers = { submittedByUserId };
94
98
  }
95
99
 
96
- if (!submittedByUserId) errorsFound.push('Not have submittedByUserId');
100
+ if (!submittedByUserId) foundErrors.push('Not have submittedByUserId');
97
101
  if (objectSchema.hasOwnProperty('belongTo') && !targetIdentifiers)
98
- errorsFound.push('not have targetIdentifiers');
102
+ foundErrors.push('not have targetIdentifiers');
99
103
 
100
104
  if (targetIdentifiers) {
101
- if (!targetIdentifiers.submittedByUserId && submittedByUserId) {
102
- targetIdentifiers.submittedByUserId = submittedByUserId;
103
- }
104
-
105
105
  // if (Array.isArray(objectSchema.identifiers)) {
106
106
  // for (const identifier of objectSchema.identifiers) {
107
107
  // if (identifier.fieldName) {
@@ -126,7 +126,7 @@ export async function resolveSchemaAndIdentity(_izContext, requestParams, errors
126
126
  }
127
127
 
128
128
  if (requestParams.rbacTargetIdentifiers === undefined && targetIdentifiers) {
129
- requestParams.rbacTargetIdentifiers = targetIdentifiers;
129
+ requestParams.rbacTargetIdentifiers = { ...targetIdentifiers };
130
130
  }
131
131
 
132
132
  _izContext.logger.debug(`[${process.env.iz_serviceTag}:<%- flowTag %>] Identity & Target Context Resolved:`, {
@@ -148,14 +148,14 @@ export async function resolveSchemaAndIdentity(_izContext, requestParams, errors
148
148
  * @param {Object} _izContext - Izara context object
149
149
  * @param {Object} requestParams - Request parameters
150
150
  * @param {Object} objectSchema - Base object schema
151
- * @param {Array<string>} errorsFound - Error list
151
+ * @param {Array<string>} foundErrors - Error list
152
152
  * @returns {Promise<{ objectSchemas: Object }>}
153
153
  */
154
154
  export async function resolveAndGenerateIdentifiers(
155
155
  _izContext,
156
156
  requestParams,
157
157
  objectSchema,
158
- errorsFound
158
+ foundErrors
159
159
  ) {
160
160
  const objType = createObjType(requestParams.objectType);
161
161
  const targetIdentifiers = requestParams.targetIdentifiers;
@@ -170,7 +170,7 @@ export async function resolveAndGenerateIdentifiers(
170
170
  objectSchemas
171
171
  );
172
172
 
173
- errorsFound.push(
173
+ foundErrors.push(
174
174
  ...(await createNodeLib.validateRequiredOnCreateLinks(
175
175
  _izContext,
176
176
  objType,
@@ -178,8 +178,8 @@ export async function resolveAndGenerateIdentifiers(
178
178
  ))
179
179
  );
180
180
  _izContext.logger.debug(
181
- `[${process.env.iz_serviceTag}:<%- flowTag %>] errorsFound:`,
182
- errorsFound
181
+ `[${process.env.iz_serviceTag}:<%- flowTag %>] foundErrors:`,
182
+ foundErrors
183
183
  );
184
184
 
185
185
  // ── Resolve fromRequiredOnCreate fields ──────────────────────────────────
@@ -235,7 +235,7 @@ export async function resolveAndGenerateIdentifiers(
235
235
  optionalOnCreateIdentifiers
236
236
  );
237
237
  if (errors?.length > 0) {
238
- errorsFound.push(...errors);
238
+ foundErrors.push(...errors);
239
239
  }
240
240
  } else if (identifiers?.length > 1) {
241
241
  for (const identifier of identifiers) {
@@ -247,7 +247,7 @@ export async function resolveAndGenerateIdentifiers(
247
247
  optionalOnCreateIdentifiers
248
248
  );
249
249
  if (errors?.length > 0) {
250
- errorsFound.push(...errors);
250
+ foundErrors.push(...errors);
251
251
  }
252
252
  }
253
253
  }
@@ -260,13 +260,13 @@ export async function resolveAndGenerateIdentifiers(
260
260
  * @param {Object} _izContext - Izara context object
261
261
  * @param {Object} requestParams - Incoming request parameters
262
262
  * @param {Object} objectSchemas - Combined object schema
263
- * @param {Array<string>} errorsFound - Array to collect validation errors
263
+ * @param {Array<string>} foundErrors - Array to collect validation errors
264
264
  */
265
265
  export function validateFieldNames(
266
266
  _izContext,
267
267
  requestParams,
268
268
  objectSchemas,
269
- errorsFound
269
+ foundErrors
270
270
  ) {
271
271
  const listOfRequiredOnCreate = [];
272
272
  const listOfOptionalOnCreate = [];
@@ -290,12 +290,12 @@ export function validateFieldNames(
290
290
  !listOfRequiredOnCreate.includes(fieldName) &&
291
291
  !listOfOptionalOnCreate.includes(fieldName)
292
292
  ) {
293
- errorsFound.push('[invalid] over fieldNames create object');
293
+ foundErrors.push('[invalid] over fieldNames create object');
294
294
  }
295
- if (errorsFound.length > 0) {
295
+ if (foundErrors.length > 0) {
296
296
  _izContext.logger.debug(
297
297
  `[${process.env.iz_serviceTag}:<%- flowTag %>] HaveError:`,
298
- errorsFound
298
+ foundErrors
299
299
  );
300
300
  break;
301
301
  }
@@ -331,7 +331,7 @@ export async function collectRbacAwaitingResults(_izContext, requestParams) {
331
331
  _izContext,
332
332
  rbacPendingStepId,
333
333
  currentAwaitingStepId,
334
- requestParams.errorsFound,
334
+ requestParams.foundErrors,
335
335
  {
336
336
  returnValue: requestParams.returnValue,
337
337
  rbacType
@@ -348,7 +348,7 @@ export async function collectRbacAwaitingResults(_izContext, requestParams) {
348
348
  const {
349
349
  isComplete,
350
350
  collectedReturnValueByAwaitingStepId,
351
- collectedErrors: errorsFound = [],
351
+ collectedErrors: foundErrors = [],
352
352
  additionalAttributes
353
353
  } = rbacAwaitingStepsResult;
354
354
 
@@ -389,7 +389,7 @@ export async function collectRbacAwaitingResults(_izContext, requestParams) {
389
389
  isComplete: true,
390
390
  rbacResults,
391
391
  originalRequestParams,
392
- collectedErrors: errorsFound
392
+ collectedErrors: foundErrors
393
393
  };
394
394
  }
395
395
 
@@ -399,11 +399,11 @@ export async function collectRbacAwaitingResults(_izContext, requestParams) {
399
399
  * @param {Object} options - Validation options
400
400
  * @returns {Promise<{ hasError: boolean, errorResult?: Object, rbacCallbackResults: Object }>}
401
401
  */
402
- export async function assertRbacPermission(_izContext, { rbacResults, originalRequestParams, errorsFound }) {
402
+ export async function assertRbacPermission(_izContext, { rbacResults, originalRequestParams, foundErrors }) {
403
403
  const rbacCallbackResults = {};
404
404
  const hasError = Object.entries(rbacResults).some(([type, result]) => {
405
405
  if (result && result.error) {
406
- errorsFound.push(result.error);
406
+ foundErrors.push(result.error);
407
407
  return true;
408
408
  }
409
409
  rbacCallbackResults[type] = result;
@@ -415,7 +415,7 @@ export async function assertRbacPermission(_izContext, { rbacResults, originalRe
415
415
  );
416
416
 
417
417
  if (!isAllowed) {
418
- errorsFound.push('Permission denied');
418
+ foundErrors.push('Permission denied');
419
419
  }
420
420
 
421
421
  _izContext.logger.debug(
@@ -423,13 +423,13 @@ export async function assertRbacPermission(_izContext, { rbacResults, originalRe
423
423
  {
424
424
  rbacCallbackResults,
425
425
  isAllowed,
426
- errorsFound
426
+ foundErrors
427
427
  }
428
428
  );
429
429
 
430
- if (hasError || errorsFound.length > 0) {
430
+ if (hasError || foundErrors.length > 0) {
431
431
  const errorResult = {
432
- errorsFound,
432
+ foundErrors,
433
433
  status: 'rejected',
434
434
  requestParams: originalRequestParams
435
435
  };
@@ -487,14 +487,43 @@ export async function saveDynamoDbRecords(_izContext, listOfRecords) {
487
487
  );
488
488
  }
489
489
 
490
+ <%_
491
+ const rootRbacObjects = (objects || []).filter(obj => {
492
+ const hasSelfRbac = Array.isArray(obj?.addOnDataStructure) && obj.addOnDataStructure.some(addOn => addOn?.type === 'rbac');
493
+ return hasSelfRbac && !obj?.belongTo && obj?.objectType !== 'user' && obj?.generatedBy !== 'systemNoUser';
494
+ });
495
+ _%>
496
+ const ROOT_RBAC_OBJECT_TYPES = new Set([
497
+ <%_ for (const obj of rootRbacObjects) { _%>
498
+ '<%- obj.objectType %>',
499
+ <%_ } _%>
500
+ ]);
501
+
490
502
  /**
491
503
  * Auto-provisions owner TargetRole for Root RBAC object after Graph and DynamoDB write
492
504
  * @param {Object} _izContext - Izara context object
493
505
  * @param {Object} options - Target node and submitter details
494
506
  * @returns {Promise<void>}
495
507
  */
496
- export async function autoProvisionOwnerTargetRole(_izContext, { node, submittedByUserId }) {
508
+ export async function autoProvisionOwnerTargetRole(_izContext, { node, submittedByUserId, objType }) {
497
509
  try {
510
+ let objectType = null;
511
+ if (typeof objType === 'string') {
512
+ objectType = objType;
513
+ } else if (objType && objType.objectType) {
514
+ objectType = objType.objectType;
515
+ } else if (typeof node?.objType === 'string') {
516
+ objectType = node.objType;
517
+ } else if (node?.objType?.objectType) {
518
+ objectType = node.objType.objectType;
519
+ } else if (node?.objectType) {
520
+ objectType = node.objectType;
521
+ }
522
+
523
+ if (!objectType || !ROOT_RBAC_OBJECT_TYPES.has(objectType)) {
524
+ return;
525
+ }
526
+
498
527
  if (!submittedByUserId || !node?.objInstanceFull?.identifiers) {
499
528
  return;
500
529
  }
@@ -766,7 +795,7 @@ export async function forwardToQuotaConfirmation(
766
795
  _izContext,
767
796
  {
768
797
  status,
769
- errorsFound = [],
798
+ foundErrors = [],
770
799
  quotaKeys,
771
800
  actionData,
772
801
  callingFlowConfig
@@ -775,7 +804,7 @@ export async function forwardToQuotaConfirmation(
775
804
  let quotaResult = null;
776
805
  if (quotaKeys && (quotaKeys.limitTag || quotaKeys.flowTypeConcat)) {
777
806
  let targetFunction = 'CancelUsageHdrInv';
778
- if (status === 'complete' && errorsFound.length === 0) {
807
+ if (status === 'complete' && foundErrors.length === 0) {
779
808
  targetFunction = 'ConfirmUsageHdrInv';
780
809
  }
781
810
 
@@ -827,10 +856,10 @@ export async function forwardToQuotaConfirmation(
827
856
  );
828
857
  }
829
858
  }
830
- errorsFound.push(err.message || 'Quota confirmation failed');
859
+ foundErrors.push(err.message || 'Quota confirmation failed');
831
860
  if (actionData) {
832
861
  actionData.status = 'error';
833
- actionData.errorsFound = errorsFound;
862
+ actionData.foundErrors = foundErrors;
834
863
  }
835
864
  }
836
865
  }
@@ -1258,10 +1287,10 @@ export async function handleCreateError(
1258
1287
  objInstanceFull,
1259
1288
  requestParams,
1260
1289
  callingFlowConfig,
1261
- errorsFound
1290
+ foundErrors
1262
1291
  }
1263
1292
  ) {
1264
- _izContext.logger.debug(`[${process.env.iz_serviceTag}:<%- flowTag %>LogicalLib] errorsFound:`, errorsFound);
1293
+ _izContext.logger.debug(`[${process.env.iz_serviceTag}:<%- flowTag %>LogicalLib] foundErrors:`, foundErrors);
1265
1294
 
1266
1295
  await asyncFlowSharedLib.clearAllAwaitingSteps(
1267
1296
  _izContext,
@@ -1274,7 +1303,7 @@ export async function handleCreateError(
1274
1303
  const messageObject =
1275
1304
  callingFlowSharedLib.addPassBackPropertiesToSnsResponseMessageObject(
1276
1305
  callingFlowConfig,
1277
- { objType, identifiers: null, errorsFound }
1306
+ { objType, identifiers: null, foundErrors }
1278
1307
  );
1279
1308
 
1280
1309
  await sns.publishAsync(_izContext, {
@@ -1298,7 +1327,7 @@ export async function handleCreateError(
1298
1327
  relationships: requestParams.relationships || [],
1299
1328
  targetIdentifiers: requestParams.targetIdentifiers,
1300
1329
  status: 'error',
1301
- errorsFound
1330
+ foundErrors
1302
1331
  };
1303
1332
  }
1304
1333
 
@@ -1356,15 +1385,15 @@ export async function handleDynamoDbOnlyComplete(
1356
1385
  * @param {Object} _izContext - Context object with logger
1357
1386
  * @param {Object} requestParams - Request parameters { fieldNames, relationships[] }
1358
1387
  * @param {Object} callingFlowConfig - Calling flow configuration
1359
- * @param {Array<string>} errorsFound - Array of preceding errors
1388
+ * @param {Array<string>} foundErrors - Array of preceding errors
1360
1389
  * @param {Object} phaseResults - Results from preceding phases
1361
- * @returns {Promise<Object>} Result with objType, objInstanceFull, relationships, status, errorsFound
1390
+ * @returns {Promise<Object>} Result with objType, objInstanceFull, relationships, status, foundErrors
1362
1391
  */
1363
1392
  export async function <%- flowTag %>LogicalLib(
1364
1393
  _izContext,
1365
1394
  requestParams,
1366
1395
  callingFlowConfig = {},
1367
- errorsFound = [],
1396
+ foundErrors = [],
1368
1397
  phaseResults = {}
1369
1398
  ) {
1370
1399
  try {
@@ -1411,7 +1440,7 @@ export async function <%- flowTag %>LogicalLib(
1411
1440
  const listOfRecords = [];
1412
1441
 
1413
1442
  // 3. Process storage resources
1414
- if (errorsFound.length === 0) {
1443
+ if (foundErrors.length === 0) {
1415
1444
  //(<validateBeforeCreate>)
1416
1445
  //(</validateBeforeCreate>)
1417
1446
 
@@ -1534,12 +1563,12 @@ export async function <%- flowTag %>LogicalLib(
1534
1563
  callingFlowConfig
1535
1564
  }
1536
1565
  );
1537
- if (hookResult?.errorsFound?.length > 0 || hookResult?.status === 'error') {
1538
- errorsFound.push(...(hookResult.errorsFound || ['Hook <%= hook.flowTag %> failed']));
1566
+ if (hookResult?.foundErrors?.length > 0 || hookResult?.status === 'error') {
1567
+ foundErrors.push(...(hookResult.foundErrors || ['Hook <%= hook.flowTag %> failed']));
1539
1568
  }
1540
1569
  } catch (hookErr) {
1541
1570
  _izContext.logger.error('[<%- flowTag %>LogicalLib] Sync hook <%= hook.flowTag %> error:', hookErr);
1542
- errorsFound.push(hookErr.message || 'Hook <%= hook.flowTag %> failed');
1571
+ foundErrors.push(hookErr.message || 'Hook <%= hook.flowTag %> failed');
1543
1572
  }
1544
1573
  <%_ if (hook.targetObjectTypes && hook.targetObjectTypes.length > 0) { _%>
1545
1574
  }
@@ -1586,7 +1615,7 @@ export async function <%- flowTag %>LogicalLib(
1586
1615
  relationships: requestParams.relationships || [],
1587
1616
  targetIdentifiers: requestParams.targetIdentifiers,
1588
1617
  status: 'complete',
1589
- errorsFound
1618
+ foundErrors
1590
1619
  }
1591
1620
  }
1592
1621
  )
@@ -1716,7 +1745,7 @@ export async function <%- flowTag %>LogicalLib(
1716
1745
  // 5. Dispatch to Graph Service
1717
1746
  for (const objectCreate of listOfObjectForCreates) {
1718
1747
  for (const [graphServiceName, objectForCreate] of Object.entries(objectCreate)) {
1719
- if (!objectForCreate.allStorageTagComplete && errorsFound.length === 0) {
1748
+ if (!objectForCreate.allStorageTagComplete && foundErrors.length === 0) {
1720
1749
  //(<beforeSendMessageToGraph>)
1721
1750
  //(</beforeSendMessageToGraph>)
1722
1751
 
@@ -1739,21 +1768,21 @@ export async function <%- flowTag %>LogicalLib(
1739
1768
  relationships: requestParams.relationships || [],
1740
1769
  targetIdentifiers: requestParams.targetIdentifiers,
1741
1770
  status: 'complete',
1742
- errorsFound
1771
+ foundErrors
1743
1772
  };
1744
1773
  }
1745
1774
  }
1746
- if (errorsFound.length > 0) break;
1775
+ if (foundErrors.length > 0) break;
1747
1776
  }
1748
1777
 
1749
1778
  // 6. Handle Errors
1750
- if (errorsFound.length > 0) {
1779
+ if (foundErrors.length > 0) {
1751
1780
  return await handleCreateError(_izContext, {
1752
1781
  objType,
1753
1782
  objInstanceFull,
1754
1783
  requestParams,
1755
1784
  callingFlowConfig,
1756
- errorsFound
1785
+ foundErrors
1757
1786
  });
1758
1787
  }
1759
1788
 
@@ -1777,7 +1806,7 @@ export async function <%- flowTag %>LogicalLib(
1777
1806
  relationships: requestParams.relationships || [],
1778
1807
  targetIdentifiers: requestParams.targetIdentifiers,
1779
1808
  status: 'complete',
1780
- errorsFound
1809
+ foundErrors
1781
1810
  };
1782
1811
  } catch (err) {
1783
1812
  _izContext.logger.error(`[${process.env.iz_serviceTag}:<%- flowTag %>LogicalLib] error:`, err);
@@ -46,29 +46,29 @@ function empty(value) {
46
46
  );
47
47
  }
48
48
 
49
- function validateInput(returnValue, status, graphServiceTag, errorsFound) {
49
+ function validateInput(returnValue, status, graphServiceTag, foundErrors) {
50
50
  if (!returnValue?.queryResult)
51
- errorsFound.push(
51
+ foundErrors.push(
52
52
  'message is not have property queryResult, should be not happen'
53
53
  );
54
54
  if (!returnValue?.requestParams?.objType)
55
- errorsFound.push(
55
+ foundErrors.push(
56
56
  'message is not have property objType, should be not happen'
57
57
  );
58
58
  if (!returnValue?.requestParams?.objInstanceFull)
59
- errorsFound.push(
59
+ foundErrors.push(
60
60
  'message is not have property objInstance, should be not objInstance'
61
61
  );
62
- if (status === 'error' && errorsFound.length === 0)
63
- errorsFound.push(
64
- '[invalid]status is error not have errorsFound form graphService'
62
+ if (status === 'error' && foundErrors.length === 0)
63
+ foundErrors.push(
64
+ '[invalid]status is error not have foundErrors form graphService'
65
65
  );
66
- if (status === 'complete' && errorsFound.length > 0)
67
- errorsFound.push(
68
- '[Invalid] status is complete should be not have errorsFound'
66
+ if (status === 'complete' && foundErrors.length > 0)
67
+ foundErrors.push(
68
+ '[Invalid] status is complete should be not have foundErrors'
69
69
  );
70
70
  if (graphServiceTag == null)
71
- errorsFound.push('[Invalid] graphServerTag is not empty string');
71
+ foundErrors.push('[Invalid] graphServerTag is not empty string');
72
72
  }
73
73
 
74
74
  /**
@@ -93,14 +93,14 @@ export default async function CreateNodeCallbackMain(
93
93
  const {
94
94
  returnValue,
95
95
  status,
96
- errorsFound = [],
96
+ foundErrors = [],
97
97
  graphServiceTag,
98
98
  parentFlowId
99
99
  } = requestParams;
100
100
  if (empty(returnValue?.requestParams))
101
101
  throw new NoRetryError('message not an object');
102
- validateInput(returnValue, status, graphServiceTag, errorsFound);
103
- if (errorsFound.length > 0) errorsFound.push(errorsFound.join(','));
102
+ validateInput(returnValue, status, graphServiceTag, foundErrors);
103
+ if (foundErrors.length > 0) foundErrors.push(foundErrors.join(','));
104
104
 
105
105
  const awaitingStepId = await asyncFlowSharedLib.createAwaitingStepId(
106
106
  parentFlowId,
@@ -119,14 +119,14 @@ export default async function CreateNodeCallbackMain(
119
119
  _izContext.logger.warn(
120
120
  `No pending step found for awaitingStepId: ${awaitingStepId}`
121
121
  );
122
- return { returnValue, status, errorsFound };
122
+ return { returnValue, status, foundErrors };
123
123
  }
124
124
  const result =
125
125
  await asyncFlowSharedLib.checkAllAwaitingStepsFinishedWithReturnParams(
126
126
  _izContext,
127
127
  pending.pendingStepId,
128
128
  awaitingStepId,
129
- errorsFound
129
+ foundErrors
130
130
  );
131
131
  _izContext.logger.debug(
132
132
  '[CreateNodeCallback] all awaiting steps result',
@@ -154,7 +154,7 @@ export default async function CreateNodeCallbackMain(
154
154
  : null;
155
155
 
156
156
  // ── Step 1: Persist DynamoDB records ──────────────────────────────────
157
- if (status === 'complete' && errorsFound.length === 0) {
157
+ if (status === 'complete' && foundErrors.length === 0) {
158
158
  const listOfRecords = result?.additionalAttributes?.listOfRecords ?? [];
159
159
  await saveDynamoDbRecords(_izContext, listOfRecords);
160
160
 
@@ -167,10 +167,17 @@ export default async function CreateNodeCallbackMain(
167
167
  _izContext.correlationIds?.get(coreConsts.SUBMITTED_BY_USER_ID) ||
168
168
  _izContext.correlationIds?.get('submittedByUserId');
169
169
 
170
+ <%_ const rootRbacObjs = (objects || []).filter(obj => {
171
+ const hasSelfRbac = Array.isArray(obj?.addOnDataStructure) && obj.addOnDataStructure.some(addOn => addOn?.type === 'rbac');
172
+ return hasSelfRbac && !obj?.belongTo && obj?.objectType !== 'user' && obj?.generatedBy !== 'systemNoUser';
173
+ }); _%>
174
+ <%_ if (rootRbacObjs.length > 0) { _%>
170
175
  await autoProvisionOwnerTargetRole(_izContext, {
171
176
  node,
172
- submittedByUserId
177
+ submittedByUserId,
178
+ objType: returnValue?.requestParams?.objType
173
179
  });
180
+ <%_ } _%>
174
181
 
175
182
  <%_ if (plan?.hasAfterHookSync) { _%>
176
183
  // ── Synchronous After Hooks ──
@@ -201,12 +208,12 @@ export default async function CreateNodeCallbackMain(
201
208
  callingFlowConfig
202
209
  }
203
210
  );
204
- if (hookResult?.errorsFound?.length > 0 || hookResult?.status === 'error') {
205
- errorsFound.push(...(hookResult.errorsFound || ['Hook <%= hook.flowTag %> failed']));
211
+ if (hookResult?.foundErrors?.length > 0 || hookResult?.status === 'error') {
212
+ foundErrors.push(...(hookResult.foundErrors || ['Hook <%= hook.flowTag %> failed']));
206
213
  }
207
214
  } catch (hookErr) {
208
215
  _izContext.logger.error('[CreateNodeCallback] Sync hook <%= hook.flowTag %> error:', hookErr);
209
- errorsFound.push(hookErr.message || 'Hook <%= hook.flowTag %> failed');
216
+ foundErrors.push(hookErr.message || 'Hook <%= hook.flowTag %> failed');
210
217
  }
211
218
  <%_ if (hook.targetObjectTypes && hook.targetObjectTypes.length > 0) { _%>
212
219
  }
@@ -228,7 +235,7 @@ export default async function CreateNodeCallbackMain(
228
235
  parentFlowId: parentFlowId || returnValue?.parentFlowId,
229
236
  existsNode,
230
237
  status,
231
- errorsFound
238
+ foundErrors
232
239
  };
233
240
 
234
241
  // ── Step 3: Resolve Quota deduction keys and forward confirmation ─────
@@ -289,7 +296,7 @@ export default async function CreateNodeCallbackMain(
289
296
  <%_ } else { _%>
290
297
  await forwardToQuotaConfirmation(_izContext, {
291
298
  status,
292
- errorsFound,
299
+ foundErrors,
293
300
  quotaKeys,
294
301
  actionData,
295
302
  callingFlowConfig
@@ -301,9 +308,9 @@ export default async function CreateNodeCallbackMain(
301
308
  _izContext,
302
309
  awaitingStepId,
303
310
  pending.pendingStepId,
304
- errorsFound
311
+ foundErrors
305
312
  );
306
- return { returnValue, status, errorsFound };
313
+ return { returnValue, status, foundErrors };
307
314
  } catch (error) {
308
315
  _izContext.logger.error('[CreateNodeCallback] error:', error);
309
316
  throw error;
@@ -48,12 +48,12 @@ export default async function DeleteAfterHookCallbackMain(
48
48
 
49
49
  const {
50
50
  status,
51
- errorsFound = [],
51
+ foundErrors = [],
52
52
  returnValue,
53
53
  parentFlowId
54
54
  } = requestParams;
55
55
 
56
- const mergedErrors = Array.isArray(errorsFound) ? [...errorsFound] : [];
56
+ const mergedErrors = Array.isArray(foundErrors) ? [...foundErrors] : [];
57
57
  if (status === 'error' && mergedErrors.length === 0) {
58
58
  mergedErrors.push('AfterHook execution reported error');
59
59
  }
@@ -73,7 +73,7 @@ export default async function DeleteAfterHookCallbackMain(
73
73
  targetIdentifiers: requestParams?.targetIdentifiers,
74
74
  parentFlowId: parentFlowId || returnValue?.parentFlowId,
75
75
  status: mergedErrors.length > 0 ? 'error' : 'complete',
76
- errorsFound: mergedErrors
76
+ foundErrors: mergedErrors
77
77
  };
78
78
 
79
79
  const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
@@ -87,7 +87,7 @@ export default async function DeleteAfterHookCallbackMain(
87
87
  {
88
88
  ...actionData,
89
89
  status: mergedErrors.length > 0 ? 'error' : 'complete',
90
- errorsFound: mergedErrors
90
+ foundErrors: mergedErrors
91
91
  }
92
92
  );
93
93
 
@@ -109,7 +109,7 @@ export default async function DeleteAfterHookCallbackMain(
109
109
  return {
110
110
  returnValue,
111
111
  status: mergedErrors.length > 0 ? 'error' : 'complete',
112
- errorsFound: mergedErrors
112
+ foundErrors: mergedErrors
113
113
  };
114
114
  } catch (error) {
115
115
  _izContext.logger.error('[DeleteAfterHookCallback] error:', error);
@@ -45,12 +45,12 @@ export default async function <%- upperCaseFlowTag %>BeforeHookCallbackMain(
45
45
 
46
46
  const {
47
47
  status,
48
- errorsFound = [],
48
+ foundErrors = [],
49
49
  returnValue,
50
50
  parentFlowId
51
51
  } = requestParams;
52
52
 
53
- const mergedErrors = Array.isArray(errorsFound) ? [...errorsFound] : [];
53
+ const mergedErrors = Array.isArray(foundErrors) ? [...foundErrors] : [];
54
54
  if (status === 'error' && mergedErrors.length === 0) {
55
55
  mergedErrors.push('BeforeHook execution reported error');
56
56
  }
@@ -76,7 +76,7 @@ export default async function <%- upperCaseFlowTag %>BeforeHookCallbackMain(
76
76
  identifiers: originalRequestParams?.identifiers || {},
77
77
  targetIdentifiers: originalRequestParams?.targetIdentifiers,
78
78
  callingFlowConfig,
79
- errorsFound: mergedErrors
79
+ foundErrors: mergedErrors
80
80
  });
81
81
  }
82
82