@izara_project/izara-core-generate-service-code 1.0.98 → 1.0.100

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 (70) hide show
  1. package/package.json +1 -1
  2. package/src/compile/compileProject.js +16 -5
  3. package/src/compile/flowValidator.js +47 -8
  4. package/src/compile/loadSchemas.js +18 -7
  5. package/src/compile/schemaValidatorSetup.js +16 -0
  6. package/src/emit/application/coreFunction/emitCoreFunctionArtifacts.js +123 -109
  7. package/src/emit/application/coreFunction/templates/InitialSetupConfig.ejs +8 -4
  8. package/src/emit/application/coreFunction/templates/InitialSetupRunner.ejs +2 -2
  9. package/src/emit/application/crud/templates/CreateComplete_Main.ejs +2 -0
  10. package/src/emit/application/crud/templates/CreateEndpoint_Main.ejs +4 -4
  11. package/src/emit/application/crud/templates/CreateLogicalLib.ejs +74 -15
  12. package/src/emit/application/crud/templates/DeleteComplete_Main.ejs +2 -0
  13. package/src/emit/application/crud/templates/DeleteEndpoint_Main.ejs +4 -4
  14. package/src/emit/application/crud/templates/FlowEndpoint_HdrWbs.ejs +7 -5
  15. package/src/emit/application/crud/templates/UpdateComplete_Main.ejs +2 -0
  16. package/src/emit/application/crud/templates/UpdateEndpoint_Main.ejs +4 -4
  17. package/src/emit/application/custom/customFlowPaths.js +13 -16
  18. package/src/emit/application/custom/customFlowS3.js +277 -66
  19. package/src/emit/application/custom/customFlows.js +131 -0
  20. package/src/emit/application/custom/emitCustomFlowApplicationArtifacts.js +3 -1
  21. package/src/emit/application/custom/templates/FlowEndpoint_Main.ejs +2 -2
  22. package/src/emit/application/custom/templates/s3/ConfirmAfterUpload_HdrSqs.ejs +110 -0
  23. package/src/emit/application/custom/templates/s3/ConfirmAfterUpload_Main.ejs +89 -0
  24. package/src/emit/application/custom/templates/s3/ConfirmComplete_HdrSqs.ejs +110 -0
  25. package/src/emit/application/custom/templates/s3/ConfirmComplete_Main.ejs +89 -0
  26. package/src/emit/application/custom/templates/s3/CreateObject_HdrWbs.ejs +2 -1
  27. package/src/emit/application/custom/templates/s3/CreateObject_Main.ejs +4 -0
  28. package/src/emit/application/custom/templates/s3/CreatePreSignUrl_HdrSqs.ejs +42 -0
  29. package/src/emit/application/custom/templates/s3/CreatePreSignUrl_Main.ejs +23 -0
  30. package/src/emit/application/custom/templates/s3/ProcessS3File_Main.ejs +135 -27
  31. package/src/emit/application/custom/templates/s3/Start_Main.ejs +197 -0
  32. package/src/emit/application/rbac/emitDynamicRbacFlowSchemas.js +8 -1
  33. package/src/emit/application/rbac/emitRbacApplicationArtifacts.js +107 -25
  34. package/src/emit/application/rbac/templates/ReservedDynamicUsage_Main.ejs +29 -9
  35. package/src/emit/application/rbac/templates/ReservedUsageTtlExpired_HdrDss.ejs +176 -0
  36. package/src/emit/application/rbac/templates/UserRbacFlow_Main.ejs +4 -3
  37. package/src/emit/application/system/templates/Register_HdrWbs.ejs +2 -1
  38. package/src/emit/infrastructure/functions/functionYamlArtifact.js +31 -8
  39. package/src/emit/infrastructure/functions/templates/DssFunction_Yaml.ejs +21 -0
  40. package/src/emit/infrastructure/functions/templates/S3Function_Yaml.ejs +2 -3
  41. package/src/emit/infrastructure/resources/iamResourceArtifacts.js +67 -5
  42. package/src/emit/infrastructure/resources/resourceState.js +15 -5
  43. package/src/emit/infrastructure/resources/s3ResourceArtifacts.js +19 -3
  44. package/src/emit/infrastructure/resources/templates/GeneratedLambdaRoleServiceConfig.ejs +5 -3
  45. package/src/emit/infrastructure/resources/templates/S3Bucket_Yaml.ejs +1 -1
  46. package/src/emit/infrastructure/resources/templates/SystemDynamoDB_Yaml.ejs +2 -2
  47. package/src/emit/schemas/attributeTree/emitAttributeTreeSchemas.js +62 -1
  48. package/src/emit/schemas/error/emitErrorSchemas.js +120 -10
  49. package/src/emit/schemas/error/templates/errorConsts.ejs +12 -0
  50. package/src/generate.js +32 -34
  51. package/src/output/mergeHooks.js +105 -5
  52. package/src/plan/domainRegistry.js +0 -10
  53. package/task.md +40 -96
  54. package/test/integration/graphDrivenFlowSchema.test.js +58 -0
  55. package/test/integration/publicApi.test.js +33 -24
  56. package/test/unit/application/createTargetRoleHandler.test.js +101 -9
  57. package/test/unit/application/crudApplicationArtifacts.test.js +4 -0
  58. package/test/unit/application/customFlowApplicationArtifacts.test.js +6 -6
  59. package/test/unit/application/customFlowS3.test.js +730 -0
  60. package/test/unit/infrastructure/functionYamlArtifact.test.js +6 -4
  61. package/test/unit/infrastructure/resourceArtifacts.test.js +103 -0
  62. package/test/unit/output/mergeHooks.test.js +137 -0
  63. package/test/unit/schemas/attributeTreeSchemas.test.js +32 -3
  64. package/test/unit/schemas/attributeTreeSingleService.test.js +175 -0
  65. package/test/unit/schemas/dynamicRbacFlowSchemas.test.js +8 -6
  66. package/test/unit/schemas/dynamicRelationshipFlowSchemas.test.js +51 -0
  67. package/test/unit/schemas/errorSchemas.test.js +84 -5
  68. package/test/unit/templates/hookTagsValidation.test.js +83 -0
  69. package/src/emit/schemas/attributeTree/emitAttributeTreeTargetValueStandard.js +0 -132
  70. package/test/unit/schemas/attributeTreeDirectives.test.js +0 -177
@@ -170,13 +170,20 @@ export async function resolveAndGenerateIdentifiers(
170
170
  objectSchemas
171
171
  );
172
172
 
173
- foundErrors.push(
174
- ...(await createNodeLib.validateRequiredOnCreateLinks(
175
- _izContext,
176
- objType,
177
- requestParams.relationships
178
- ))
179
- );
173
+ try {
174
+ foundErrors.push(
175
+ ...(await createNodeLib.validateRequiredOnCreateLinks(
176
+ _izContext,
177
+ objType,
178
+ requestParams.relationships
179
+ ))
180
+ );
181
+ } catch (err) {
182
+ _izContext.logger.warn(
183
+ `[${process.env.iz_serviceTag}:<%- flowTag %>] validateRequiredOnCreateLinks warning:`,
184
+ err.message
185
+ );
186
+ }
180
187
  _izContext.logger.debug(
181
188
  `[${process.env.iz_serviceTag}:<%- flowTag %>] foundErrors:`,
182
189
  foundErrors
@@ -499,6 +506,24 @@ const ROOT_RBAC_OBJECT_TYPES = new Set([
499
506
  <%_ } _%>
500
507
  ]);
501
508
 
509
+ <%_
510
+ const objectQuotaServiceTags = {};
511
+ for (const obj of objects || []) {
512
+ if (obj?.objectType) {
513
+ let serviceTag = null;
514
+ if (obj.belongTo) {
515
+ if (Array.isArray(obj.belongTo)) {
516
+ serviceTag = obj.belongTo[0]?.serviceTag || null;
517
+ } else if (obj.belongTo.serviceTag) {
518
+ serviceTag = obj.belongTo.serviceTag;
519
+ }
520
+ }
521
+ objectQuotaServiceTags[obj.objectType] = serviceTag;
522
+ }
523
+ }
524
+ _%>
525
+ const OBJECT_QUOTA_SERVICE_TAGS = <%- JSON.stringify(objectQuotaServiceTags) %>;
526
+
502
527
  /**
503
528
  * Auto-provisions owner TargetRole for Root RBAC object after Graph and DynamoDB write
504
529
  * @param {Object} _izContext - Izara context object
@@ -772,6 +797,30 @@ export function resolveQuotaDeductionKeys(
772
797
  passBackProperties?.rbacType ||
773
798
  callingFlowConfig?.rbacType;
774
799
 
800
+ const objType =
801
+ returnValue?.requestParams?.objType ||
802
+ requestParams?.objType ||
803
+ passBackProperties?.objType;
804
+ let objectType = null;
805
+ if (typeof objType === 'string') {
806
+ objectType = objType;
807
+ } else if (objType && objType.objectType) {
808
+ objectType = objType.objectType;
809
+ }
810
+
811
+ let quotaServiceTag =
812
+ requestParams?.passBackProperties?.quotaServiceTag ||
813
+ passBackProperties?.passBackProperties?.quotaServiceTag ||
814
+ passBackProperties?.quotaServiceTag ||
815
+ callingFlowConfig?.quotaServiceTag;
816
+
817
+ if (!quotaServiceTag && objectType && OBJECT_QUOTA_SERVICE_TAGS[objectType]) {
818
+ quotaServiceTag = OBJECT_QUOTA_SERVICE_TAGS[objectType];
819
+ }
820
+ if (!quotaServiceTag) {
821
+ quotaServiceTag = process.env.iz_serviceTag;
822
+ }
823
+
775
824
  return {
776
825
  limitTag,
777
826
  flowTypeConcat,
@@ -780,7 +829,8 @@ export function resolveQuotaDeductionKeys(
780
829
  runningTotalReservedId,
781
830
  identifiersConcat,
782
831
  targetIdentifiers,
783
- rbacType
832
+ rbacType,
833
+ quotaServiceTag
784
834
  };
785
835
  }
786
836
 
@@ -808,10 +858,15 @@ export async function forwardToQuotaConfirmation(
808
858
  targetFunction = 'ConfirmUsageHdrInv';
809
859
  }
810
860
 
861
+ let quotaServiceTag = quotaKeys.quotaServiceTag;
862
+ if (!quotaServiceTag) {
863
+ quotaServiceTag = process.env.iz_serviceTag;
864
+ }
865
+
811
866
  const functionName = await lambdaSharedLib.lambdaFunctionName(
812
867
  _izContext,
813
868
  targetFunction,
814
- 'Rbac'
869
+ quotaServiceTag
815
870
  );
816
871
 
817
872
  const forwardMessage = {
@@ -820,11 +875,15 @@ export async function forwardToQuotaConfirmation(
820
875
  callingFlowConfig
821
876
  };
822
877
 
823
- _izContext.logger.debug('[CreateLogicalLib] invoking RBAC quota sync', {
824
- targetFunction,
825
- functionName,
826
- forwardMessage
827
- });
878
+ _izContext.logger.debug(
879
+ `[CreateLogicalLib] invoking ${quotaServiceTag} quota sync`,
880
+ {
881
+ targetFunction,
882
+ functionName,
883
+ quotaServiceTag,
884
+ forwardMessage
885
+ }
886
+ );
828
887
 
829
888
  try {
830
889
  quotaResult = await lambda.invokeSync(
@@ -842,7 +901,7 @@ export async function forwardToQuotaConfirmation(
842
901
  const cancelFunctionName = await lambdaSharedLib.lambdaFunctionName(
843
902
  _izContext,
844
903
  'CancelUsageHdrInv',
845
- 'Rbac'
904
+ quotaServiceTag
846
905
  );
847
906
  await lambda.invokeSync(
848
907
  _izContext,
@@ -145,6 +145,8 @@ export default async function DeleteComplete(
145
145
  }
146
146
  const callingFlowConfig =
147
147
  result?.additionalAttributes?.callingFlowConfig ||
148
+ requestParams?.passBackProperties?.parentPassBackProperties ||
149
+ passBackProperties?.passBackProperties?.parentPassBackProperties ||
148
150
  passBackProperties;
149
151
  const actionData = {
150
152
  objType: returnValue.requestParams.objType,
@@ -144,9 +144,9 @@ export default async function <%- flowTag %>(
144
144
  const { checkRbacPermission } =
145
145
  await import('@izara_project/izara-authorization');
146
146
 
147
- //(<rbacParameterGroups_<%- flowTag %>)
147
+ //(<rbacParameterGroups_<%- flowTag %>>)
148
148
  const parameterGroups = {};
149
- //(</rbacParameterGroups_<%- flowTag %>)
149
+ //(</rbacParameterGroups_<%- flowTag %>>)
150
150
 
151
151
  const resultPermissionCheck = await checkRbacPermission(
152
152
  _izContext,
@@ -181,8 +181,8 @@ export default async function <%- flowTag %>(
181
181
  );
182
182
  }
183
183
 
184
- //(<rbacPublish_<%- flowTag %>)
185
- //(</rbacPublish_<%- flowTag %>)
184
+ //(<rbacPublish_<%- flowTag %>>)
185
+ //(</rbacPublish_<%- flowTag %>>)
186
186
  }
187
187
  <%_ } _%>
188
188
 
@@ -89,10 +89,10 @@ export const main = middleware.wrap(async (event, context) => {
89
89
  flowSchema.statusType === 'triggerCache'
90
90
  ) {
91
91
  const taskKey = `${createFlowTypeConcat(event._izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${identifiers}`;
92
- event._izContext.logger.debug('[FlowEndpoint_HdrWbs] registering WebSocketTask with ttl', {
92
+ event._izContext.logger.debug('[FlowEndpoint_HdrWbs] registering WebSocketTask with expirationTime', {
93
93
  taskKey,
94
94
  connectionId,
95
- ttl: 600
95
+ expirationTime: Math.floor(Date.now() / 1000) + 7200
96
96
  });
97
97
  await dynamodbSharedLib.putItem(
98
98
  event._izContext,
@@ -103,14 +103,15 @@ export const main = middleware.wrap(async (event, context) => {
103
103
  {
104
104
  taskKey,
105
105
  connectionId: connectionId,
106
- ttl: 600
106
+ expirationTime: Math.floor(Date.now() / 1000) + 7200
107
107
  }
108
108
  );
109
109
  } else if (flowSchema.statusType === 'none') {
110
110
  const taskKey = `${createFlowTypeConcat(event._izContext, { flowTag: '<%- flowTag %>', serviceTag: process.env.iz_serviceTag })}${correlationId}`;
111
111
  event._izContext.logger.debug('[FlowEndpoint_HdrWbs] registering WebSocketTask for status none', {
112
112
  taskKey,
113
- connectionId
113
+ connectionId,
114
+ expirationTime: Math.floor(Date.now() / 1000) + 7200
114
115
  });
115
116
  await dynamodbSharedLib.putItem(
116
117
  event._izContext,
@@ -120,7 +121,8 @@ export const main = middleware.wrap(async (event, context) => {
120
121
  ),
121
122
  {
122
123
  taskKey,
123
- connectionId: connectionId
124
+ connectionId: connectionId,
125
+ expirationTime: Math.floor(Date.now() / 1000) + 7200
124
126
  }
125
127
  );
126
128
  }
@@ -145,6 +145,8 @@ export default async function UpdateComplete(
145
145
  }
146
146
  const callingFlowConfig =
147
147
  result?.additionalAttributes?.callingFlowConfig ||
148
+ requestParams?.passBackProperties?.parentPassBackProperties ||
149
+ passBackProperties?.passBackProperties?.parentPassBackProperties ||
148
150
  passBackProperties;
149
151
 
150
152
  const actionData = {
@@ -156,9 +156,9 @@ export default async function <%- flowTag %>(
156
156
  const { checkRbacPermission } =
157
157
  await import('@izara_project/izara-authorization');
158
158
 
159
- //(<rbacParameterGroups_<%- flowTag %>)
159
+ //(<rbacParameterGroups_<%- flowTag %>>)
160
160
  const parameterGroups = {};
161
- //(</rbacParameterGroups_<%- flowTag %>)
161
+ //(</rbacParameterGroups_<%- flowTag %>>)
162
162
 
163
163
  const resultPermissionCheck = await checkRbacPermission(
164
164
  _izContext,
@@ -193,8 +193,8 @@ export default async function <%- flowTag %>(
193
193
  );
194
194
  }
195
195
 
196
- //(<rbacPublish_<%- flowTag %>)
197
- //(</rbacPublish_<%- flowTag %>)
196
+ //(<rbacPublish_<%- flowTag %>>)
197
+ //(</rbacPublish_<%- flowTag %>>)
198
198
  }
199
199
  <%_ } _%>
200
200
 
@@ -4,7 +4,8 @@ import {
4
4
  generatedDsqFlows,
5
5
  generatedOwnTopicFlows,
6
6
  supportedCustomFlows,
7
- upperFirst
7
+ upperFirst,
8
+ resolveS3Parts
8
9
  } from './customFlows.js';
9
10
 
10
11
  export const YAML_PATH = 'app/sls_yaml/generatedCode/source/flow-schema.yml';
@@ -70,23 +71,19 @@ export function flowPaths(flow, objects = []) {
70
71
  paths.push(...ownTopicRootPaths(flow, objects));
71
72
  }
72
73
  if (flow.event.includes('s3')) {
73
- const s3Actions = [
74
- 'ConfirmAfterUpload',
75
- 'CreateObject',
76
- 'CreatePreSignUrl',
77
- 'ProcessAfterUpload',
78
- 'ReservedLimit'
79
- ];
80
- for (const action of s3Actions) {
81
- let handler = 'HdrSqs';
82
- if (action === 'CreateObject') {
83
- handler = 'HdrWbs';
84
- } else if (action === 'ProcessAfterUpload') {
85
- handler = 'HdrS3';
74
+ const parts = resolveS3Parts(flow);
75
+ for (const { action, handler } of parts) {
76
+ let isStart = false;
77
+ if (typeof action === 'string' && action.toLowerCase() === 'start') {
78
+ isStart = true;
79
+ }
80
+ let baseName = `${tag}${action}`;
81
+ if (isStart) {
82
+ baseName = tag;
86
83
  }
87
84
  paths.push(
88
- `${source}/${tag}${action}_Main.js`,
89
- `${source}/${tag}${action}_${handler}.js`
85
+ `${source}/${baseName}_Main.js`,
86
+ `${source}/${baseName}_${handler}.js`
90
87
  );
91
88
  }
92
89
  }