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

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 (32) hide show
  1. package/package.json +1 -1
  2. package/src/compile/flowValidator.js +25 -0
  3. package/src/compile/loadSchemas.js +199 -10
  4. package/src/emit/coreFunction/templates/InitialSetupConfig.ejs +3 -7
  5. package/src/emit/crud/crudActionPlan.js +105 -6
  6. package/src/emit/crud/emitCrudApplicationArtifacts.js +63 -3
  7. package/src/emit/crud/emitDynamicCrudFlowSchemas.js +15 -32
  8. package/src/emit/crud/templates/CreateAfterHookCallback_Main.ejs +121 -0
  9. package/src/emit/crud/templates/CreateBeforeHookCallback_Main.ejs +108 -0
  10. package/src/emit/crud/templates/CreateEndpoint_Main.ejs +140 -340
  11. package/src/emit/crud/templates/CreateLogicalLib.ejs +338 -82
  12. package/src/emit/crud/templates/CreateNodeCallback_Main.ejs +90 -0
  13. package/src/emit/crud/templates/DeleteAfterHookCallback_Main.ejs +118 -0
  14. package/src/emit/crud/templates/DeleteBeforeHookCallback_Main.ejs +99 -0
  15. package/src/emit/crud/templates/DeleteComplete_Main.ejs +124 -10
  16. package/src/emit/crud/templates/DeleteEndpoint_Main.ejs +151 -179
  17. package/src/emit/crud/templates/DeleteLogicalLib.ejs +244 -27
  18. package/src/emit/crud/templates/UpdateAfterHookCallback_Main.ejs +120 -0
  19. package/src/emit/crud/templates/UpdateBeforeHookCallback_Main.ejs +112 -0
  20. package/src/emit/crud/templates/UpdateComplete_Main.ejs +104 -10
  21. package/src/emit/crud/templates/UpdateEndpoint_Main.ejs +166 -185
  22. package/src/emit/crud/templates/UpdateLogicalLib.ejs +123 -3
  23. package/src/emit/custom/customFlows.js +3 -1
  24. package/src/emit/rbac/emitDynamicRbacFlowSchemas.js +8 -2
  25. package/src/emit/rbac/templates/CancelUsage_Main.ejs +34 -14
  26. package/src/emit/rbac/templates/ConfirmUsage_Main.ejs +34 -14
  27. package/src/emit/resource/emitResourceArtifacts.js +119 -59
  28. package/test/crudApplicationArtifacts.test.js +876 -0
  29. package/test/dynamicCrudFlowSchemas.test.js +10 -5
  30. package/test/dynamicRbacFlowSchemas.test.js +24 -2
  31. package/test/graphDrivenFlowSchema.test.js +36 -0
  32. package/test/resourceArtifacts.test.js +271 -12
@@ -0,0 +1,121 @@
1
+ /*
2
+ Copyright (C) 2026 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import asyncFlowSharedLib from '@izara_project/izara-core-library-asynchronous-flow';
19
+ import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
20
+ import snsSharedLib from '@izara_project/izara-core-library-sns';
21
+ import { sns } from '@izara_project/izara-core-library-external-request';
22
+ import { consts } from '@izara_project/izara-core-library-service-schemas';
23
+ import { forwardToQuotaConfirmation } from './CreateLogicalLib.js';
24
+
25
+ //(<optionalRequire>)
26
+ //(</optionalRequire>)
27
+
28
+ const { TOPIC_NAME_GENERATE_CODE } = consts;
29
+
30
+ /**
31
+ * Handles callback after async AfterHook completion
32
+ * @param {Object} _izContext - Izara context object
33
+ * @param {Object} requestParams - Callback request parameters
34
+ * @param {Object} passBackProperties - Pass-back properties
35
+ * @returns {Promise<Object>} Result object
36
+ */
37
+ export default async function CreateAfterHookCallbackMain(
38
+ _izContext,
39
+ requestParams,
40
+ passBackProperties
41
+ //(<additionalParams>)
42
+ //(</additionalParams>)
43
+ ) {
44
+ try {
45
+ _izContext.logger.debug('[CreateAfterHookCallback] started', {
46
+ requestParams,
47
+ passBackProperties
48
+ });
49
+
50
+ const {
51
+ status,
52
+ errorsFound = [],
53
+ returnValue,
54
+ parentFlowId
55
+ } = requestParams;
56
+
57
+ const mergedErrors = Array.isArray(errorsFound) ? [...errorsFound] : [];
58
+ if (status === 'error' && mergedErrors.length === 0) {
59
+ mergedErrors.push('AfterHook execution reported error');
60
+ }
61
+
62
+ const callingFlowConfig =
63
+ passBackProperties?.callingFlowConfig ||
64
+ requestParams?.passBackProperties?.callingFlowConfig ||
65
+ passBackProperties;
66
+
67
+ const quotaKeys =
68
+ passBackProperties?.quotaKeys ||
69
+ requestParams?.passBackProperties?.quotaKeys;
70
+
71
+ const actionData =
72
+ passBackProperties?.actionData ||
73
+ requestParams?.passBackProperties?.actionData ||
74
+ {
75
+ objType: returnValue?.objType || requestParams?.objType,
76
+ objInstanceFull: returnValue?.objInstanceFull || requestParams?.objInstanceFull,
77
+ relationships: returnValue?.relationships || requestParams?.relationships || [],
78
+ targetIdentifiers: requestParams?.targetIdentifiers,
79
+ parentFlowId: parentFlowId || returnValue?.parentFlowId,
80
+ status: mergedErrors.length > 0 ? 'error' : 'complete',
81
+ errorsFound: mergedErrors
82
+ };
83
+
84
+ if (quotaKeys) {
85
+ await forwardToQuotaConfirmation(_izContext, {
86
+ status: mergedErrors.length > 0 ? 'error' : 'complete',
87
+ errorsFound: mergedErrors,
88
+ quotaKeys,
89
+ actionData,
90
+ callingFlowConfig
91
+ });
92
+ } else {
93
+ const topicArn = snsSharedLib.snsTopicArnByFlowSchema(
94
+ _izContext,
95
+ TOPIC_NAME_GENERATE_CODE.outCreateNodeComplete
96
+ );
97
+ const completionPayload = {
98
+ ...actionData,
99
+ status: mergedErrors.length > 0 ? 'error' : 'complete',
100
+ errorsFound: mergedErrors
101
+ };
102
+ await sns.publishAsync(_izContext, {
103
+ TopicArn: topicArn,
104
+ Message: JSON.stringify(completionPayload),
105
+ MessageAttributes: sns.createStringMessageAttributes(_izContext, {})
106
+ });
107
+ }
108
+
109
+ //(<afterProcessCallback>)
110
+ //(</afterProcessCallback>)
111
+
112
+ return {
113
+ returnValue,
114
+ status: mergedErrors.length > 0 ? 'error' : 'complete',
115
+ errorsFound: mergedErrors
116
+ };
117
+ } catch (error) {
118
+ _izContext.logger.error('[CreateAfterHookCallback] error:', error);
119
+ throw error;
120
+ }
121
+ }
@@ -0,0 +1,108 @@
1
+ /*
2
+ Copyright (C) 2026 Sven Mason <http://izara.io>
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Affero General Public License as
6
+ published by the Free Software Foundation, either version 3 of the
7
+ License, or (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Affero General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Affero General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+
18
+ import {
19
+ <%- flowTag %>LogicalLib,
20
+ handleCreateError
21
+ } from './<%- upperCaseFlowTag %>LogicalLib.js';
22
+
23
+ //(<optionalRequire>)
24
+ //(</optionalRequire>)
25
+
26
+ /**
27
+ * Handles callback after async BeforeHook completion
28
+ * @param {Object} _izContext - Izara context object
29
+ * @param {Object} requestParams - Callback request parameters
30
+ * @param {Object} passBackProperties - Pass-back properties
31
+ * @returns {Promise<Object>} Result object
32
+ */
33
+ export default async function <%- upperCaseFlowTag %>BeforeHookCallbackMain(
34
+ _izContext,
35
+ requestParams,
36
+ passBackProperties
37
+ //(<additionalParams>)
38
+ //(</additionalParams>)
39
+ ) {
40
+ try {
41
+ _izContext.logger.debug('[<%- upperCaseFlowTag %>BeforeHookCallback] started', {
42
+ requestParams,
43
+ passBackProperties
44
+ });
45
+
46
+ const {
47
+ status,
48
+ errorsFound = [],
49
+ returnValue,
50
+ parentFlowId
51
+ } = requestParams;
52
+
53
+ const mergedErrors = Array.isArray(errorsFound) ? [...errorsFound] : [];
54
+ if (status === 'error' && mergedErrors.length === 0) {
55
+ mergedErrors.push('BeforeHook execution reported error');
56
+ }
57
+
58
+ const callingFlowConfig =
59
+ passBackProperties?.callingFlowConfig ||
60
+ requestParams?.passBackProperties?.callingFlowConfig ||
61
+ {};
62
+
63
+ const originalRequestParams =
64
+ passBackProperties?.originalRequestParams ||
65
+ requestParams?.passBackProperties?.originalRequestParams ||
66
+ passBackProperties?.requestParams ||
67
+ passBackProperties;
68
+
69
+ if (mergedErrors.length > 0) {
70
+ _izContext.logger.warn(
71
+ '[<%- upperCaseFlowTag %>BeforeHookCallback] BeforeHook reported errors:',
72
+ mergedErrors
73
+ );
74
+ return await handleCreateError(_izContext, {
75
+ objType: originalRequestParams?.objType,
76
+ objInstanceFull: {
77
+ identifiers:
78
+ originalRequestParams?.identifiers ||
79
+ originalRequestParams?.targetIdentifiers ||
80
+ {},
81
+ fields: originalRequestParams?.fieldNames || {}
82
+ },
83
+ requestParams: originalRequestParams || {},
84
+ callingFlowConfig,
85
+ errorsFound: mergedErrors
86
+ });
87
+ }
88
+
89
+ if (returnValue?.fieldNames && originalRequestParams?.fieldNames) {
90
+ Object.assign(originalRequestParams.fieldNames, returnValue.fieldNames);
91
+ }
92
+ if (returnValue?.relationships && originalRequestParams) {
93
+ originalRequestParams.relationships = returnValue.relationships;
94
+ }
95
+
96
+ //(<beforeLogicalExecution>)
97
+ //(</beforeLogicalExecution>)
98
+
99
+ return await <%- flowTag %>LogicalLib(
100
+ _izContext,
101
+ originalRequestParams,
102
+ callingFlowConfig
103
+ );
104
+ } catch (error) {
105
+ _izContext.logger.error('[<%- upperCaseFlowTag %>BeforeHookCallback] error:', error);
106
+ throw error;
107
+ }
108
+ }