@izara_project/izara-core-generate-service-code 1.0.28 → 1.0.30

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 (29) hide show
  1. package/package.json +2 -2
  2. package/src/generateCode/generateFlowSchema/event/lambdaSyncApiComponent/handler/template.ejs +4 -4
  3. package/src/generateCode/generateFlowSchema/event/s3Component/upload/processFile/handler/handlerS3/template.ejs +4 -4
  4. package/src/generateCode/generateInitialSetup/GenerateCodeExternalService.js +0 -1
  5. package/src/generateCode/generateInitialSetup/externalServiceComponent/index.js +9 -3
  6. package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/data.js +90 -0
  7. package/src/generateCode/generateInitialSetup/externalServiceComponent/tableNameConfig/template.ejs +43 -0
  8. package/src/generateCode/generateSchema/GenerateCodeSchema.js +13 -4
  9. package/src/generateCode/generateSchema/actionEndpointCompleteComponent/update/mainFunction/template.ejs +4 -4
  10. package/src/generateCode/generateSchema/actionEndpointComponent/yaml/data.js +3 -3
  11. package/src/generateCode/{generateTranslation/generateTranslation.js → generateSchema/generateTextTag/index.js} +10 -7
  12. package/src/generateCode/{generateTranslation/translations → generateSchema/generateTextTag/systemText}/data.js +46 -11
  13. package/src/generateCode/generateSchema/rbac/dynamoDb/data.js +112 -0
  14. package/src/generateCode/generateSchema/rbac/index.js +74 -0
  15. package/src/generateCode/generateSchema/rbac/lambda/authApi/data.js +69 -0
  16. package/src/generateCode/generateSchema/rbac/lambda/authApi/templateInv.ejs +52 -0
  17. package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/data.js +70 -0
  18. package/src/generateCode/generateSchema/rbac/lambda/authInv/handler/templateInv.ejs +52 -0
  19. package/src/generateCode/generateSchema/rbac/lambda/authInv/mainFunction/data.js +82 -0
  20. package/src/generateCode/generateSchema/rbac/lambda/authInv/mainFunction/template.ejs +42 -0
  21. package/src/generateCode/generateSchema/rbac/lambda/yaml/data.js +128 -0
  22. package/src/generateCode/generateSchema/rbac/lambda/yaml/template.ejs +6 -0
  23. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/mainFunction/template.ejs +36 -12
  24. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/mainFunction/template.ejs +10 -0
  25. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/mainFunction/template.ejs +6 -6
  26. package/src/generateCode.js +5 -12
  27. package/src/libs/Consts.js +10 -4
  28. package/src/libs/Libs.js +7 -1
  29. /package/src/generateCode/{generateTranslation/translations → generateSchema/generateTextTag/systemText}/template.ejs +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.28",
3
+ "version": "1.0.30",
4
4
  "description": "Code for locally generating per service files",
5
5
  "author": "Sven Mason <thebarbariansven@gmail.com>",
6
6
  "license": "AGPL-3.0-or-later",
@@ -27,7 +27,7 @@
27
27
  "@izara_project/izara-core-library-core": "^1.0.31",
28
28
  "@izara_project/izara-core-library-logger": "^1.0.8",
29
29
  "@izara_project/izara-core-library-s3": "^1.0.5",
30
- "@izara_project/izara-core-library-service-schemas": "^1.0.127",
30
+ "@izara_project/izara-core-library-service-schemas": "^1.0.133",
31
31
  "@izara_project/izara-shared-core": "^1.0.9",
32
32
  "ejs": "^5.0.1",
33
33
  "js-beautify": "^1.15.4",
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  const RBAC_TARGET_ID = process.env.iz_rbacTargetIdUser // iz_rbacTargetIdUser | iz_rbacDeliveryMethodId
19
19
 
20
- import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
20
+ import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
21
21
  import Logger from '@izara_project/izara-core-library-logger';
22
22
  import callingFlowSharedLib from '@izara_project/izara-core-library-calling-flow';
23
23
 
@@ -71,14 +71,14 @@ export const main = middleware.wrap(async (event, context, callback) => {
71
71
 
72
72
  // return error to client
73
73
  if (lambdaFunctionResponse instanceof Error) {
74
- return (izara.response.failure(lambdaFunctionResponse));
74
+ return (response.failure(lambdaFunctionResponse));
75
75
  }
76
76
 
77
77
  // return success to client
78
- return (izara.response.success(lambdaFunctionResponse));
78
+ return (response.success(lambdaFunctionResponse));
79
79
 
80
80
  } catch (err) {
81
81
  event._izContext.logger.error('Error, LambdaFunctionHdrApi: ', err);
82
- return (izara.response.failure(err));
82
+ return (response.failure(err));
83
83
  }
84
84
  });
@@ -16,7 +16,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
  */
17
17
 
18
18
 
19
- import { middlewareHandler as middleware } from "@izara_project/izara-middleware";
19
+ import { middlewareHandler as middleware, response } from "@izara_project/izara-middleware";
20
20
  import Logger from '@izara_project/izara-core-library-logger';
21
21
  import recordHandlerS3SharedLib from '@izara_project/izara-core-library-record-handler';
22
22
 
@@ -38,13 +38,13 @@ export const main = middleware.wrap(async (event, context) => {
38
38
  );
39
39
 
40
40
  if (processImageResponse instanceof Error) {
41
- return (izara.response.failure(processImageResponse));
41
+ return (response.failure(processImageResponse));
42
42
  };
43
43
 
44
- return (izara.response.success(processImageResponse));
44
+ return (response.success(processImageResponse));
45
45
 
46
46
  } catch (err) {
47
47
  event._izContext.logger.error('Error, processAfterUploadHdrS3: ', err);
48
- return (izara.response.failure(err));
48
+ return (response.failure(err));
49
49
  }
50
50
  });
@@ -33,7 +33,6 @@ async function generateTemplateExternalResourceDataFromCustomData(
33
33
  allObjSchemas,
34
34
  allRelationshipSchemas,
35
35
  allFlowSchemas,
36
- settings
37
36
  )
38
37
  ]);
39
38
 
@@ -17,7 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
 
18
18
  import createExternalLambdaRole from './lambdaRole/data.js';
19
19
  import createExternalSnsSubscriptions from './snsTopicSubscriptions/data.js';
20
-
20
+ import createTableNameConfig from './tableNameConfig/data.js';
21
21
  /**
22
22
  * Generates code with templates for different actions
23
23
  * @param {Object} _izContext - Context object
@@ -29,7 +29,7 @@ async function generateCodeWithTemplate(
29
29
  rootServicePath,
30
30
  allObjSchemas,
31
31
  allObjectRelationships,
32
- allLocalFlowSchemas
32
+ allLocalFlowSchemas,
33
33
  ) {
34
34
  try {
35
35
  const createSourceParams = [];
@@ -51,7 +51,13 @@ async function generateCodeWithTemplate(
51
51
  rootServicePath
52
52
  );
53
53
 
54
- createSourceParams.push(createFunctionIamRole, createSnsSubscription);
54
+ const createTableName = createTableNameConfig(_izContext,
55
+ allObjSchemas,
56
+ allObjectRelationships,
57
+ rootServicePath
58
+ )
59
+
60
+ createSourceParams.push(createFunctionIamRole, createSnsSubscription, createTableName);
55
61
 
56
62
  return createSourceParams;
57
63
  } catch (error) {
@@ -0,0 +1,90 @@
1
+ /*
2
+ Copyright (C) 2020 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 path from 'path';
19
+ import { fileURLToPath } from 'url';
20
+ import consts from '#libs/Consts.js';
21
+ import libs from '#libs/Libs.js';
22
+ import utils from '#libs/Utils.js';
23
+
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = path.dirname(__filename);
26
+
27
+ const {
28
+ STORAGE_TYPES,
29
+ SOURCE_PATH,
30
+ SAVE_FILE_NAME
31
+ } = consts;
32
+
33
+ const { createDynamoDbComponentByLinks } = libs;
34
+
35
+ const templatePath = path.join(__dirname, 'template.ejs');
36
+
37
+ /**
38
+ * Creates external SNS subscription configuration
39
+ * @param {Object} _izContext - Context object
40
+ * @param {Array} allObjSchemas - All object schemas
41
+ * @param {Array} allRelSchemas - All relationship schemas
42
+ * @param {Array} allLocalFlowSchemas - All local flow schemas
43
+ * @param {string} rootSchemasPath
44
+ * @returns {Promise<Object>} SNS subscription template config
45
+ */
46
+ function createTableNameConfig(
47
+ _izContext,
48
+ allObjSchemas,
49
+ allRelationshipSchemas,
50
+ appPath
51
+ ) {
52
+
53
+ const tableNames = [];
54
+
55
+ if (allObjSchemas.some(objSchema => objSchema.addOnDataStructure?.some(addOn => addOn.type === 'rbac'))) {
56
+ tableNames.push("Permission", "RolePermissions", "Roles", "UserRoles")
57
+ };
58
+
59
+ for (const objSchema of allObjSchemas) {
60
+ for (const storageResource of Object.values(objSchema.storageResources)) {
61
+ if (storageResource.storageType === STORAGE_TYPES.dynamoDB) {
62
+ tableNames.push(storageResource.tableName)
63
+ }
64
+ }
65
+ };
66
+
67
+ for (const relSchema of allRelationshipSchemas) {
68
+ const relData = Object.values(relSchema);
69
+ for (const storageResource of Object.values(relData[0].storageResources)) {
70
+ if (storageResource.storagetype === STORAGE_TYPES.dynamoDB) {
71
+ const { resourceNameFrom, resourceNameTo } = createDynamoDbComponentByLinks(relData.links, Object.keys(relSchema)[0])
72
+ tableNames.push(resourceNameFrom, resourceNameTo)
73
+ }
74
+ }
75
+ }
76
+
77
+ // console.log("tableNames", tableNames)
78
+ return {
79
+ templatePath,
80
+ templateData: { tableNames },
81
+ setting: {
82
+ savePath: path.join(appPath, SOURCE_PATH.externalService),
83
+ saveFileName: SAVE_FILE_NAME.tableName,
84
+ fileExtension: '.js',
85
+ isAppend: true
86
+ }
87
+ };
88
+ }
89
+
90
+ export default createTableNameConfig;
@@ -0,0 +1,43 @@
1
+ /*
2
+ Copyright (C) 2020 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
+ /*
19
+ Copyright (C) 2020 Sven Mason <http://izara.io>
20
+
21
+ This program is free software: you can redistribute it and/or modify
22
+ it under the terms of the GNU Affero General Public License as
23
+ published by the Free Software Foundation, either version 3 of the
24
+ License, or (at your option) any later version.
25
+
26
+ This program is distributed in the hope that it will be useful,
27
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ GNU Affero General Public License for more details.
30
+
31
+ You should have received a copy of the GNU Affero General Public License
32
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
33
+ */
34
+
35
+ const generatedTableNameConfig = [
36
+ <% tableNames.forEach(tableName => { %>
37
+ {<%- tableName %>: {},},
38
+ <% }) %>
39
+ ]
40
+
41
+ export {
42
+ generatedTableNameConfig
43
+ }
@@ -5,6 +5,8 @@ import relationshipPerActionComponent from './relationshipPerActionComponent/ind
5
5
  import processLogicalComponent from './processLogicalComponent/index.js';
6
6
  import processLogicalPaginateComponent from './processLogicalPaginationComponent/index.js';
7
7
  import findDataComponent from './findDataComponent/index.js';
8
+ import systemTextTagComponent from './generateTextTag/index.js';
9
+ import rbacComponent from './rbac/index.js'
8
10
 
9
11
  /**
10
12
  * Generates code from templates based on object schemas
@@ -21,6 +23,7 @@ async function generateTemplateDataFromSchema(
21
23
  allObjSchemas,
22
24
  allRelationshipSchemas,
23
25
  allLocalFlowSchemas,
26
+ localNotificationSystem,
24
27
  settings
25
28
  ) {
26
29
  try {
@@ -50,7 +53,9 @@ async function generateTemplateDataFromSchema(
50
53
  relationshipParams,
51
54
  processLogicalParams,
52
55
  processLogicalPaginateParams,
53
- findDataParams
56
+ findDataParams,
57
+ systemTextParams,
58
+ rbacParams,
54
59
  ] = await Promise.all([
55
60
  endpointComponent(
56
61
  _izContext,
@@ -79,11 +84,13 @@ async function generateTemplateDataFromSchema(
79
84
  appPath,
80
85
  allObjSchemas.records
81
86
  ),
82
- findDataComponent(_izContext, appPath, allObjSchemas, settings)
87
+ findDataComponent(_izContext, appPath, allObjSchemas, settings),
88
+ systemTextTagComponent(_izContext, appPath, allObjSchemas, allRelationshipSchemas, allLocalFlowSchemas, localNotificationSystem),
89
+ rbacComponent(_izContext, appPath, allObjSchemas, settings)
83
90
  ]);
84
91
 
85
92
  console.info(
86
- `[Schema] components generated endpoint=${endpointParams.length} endpointComplete=${endpointCompleteParams.length} resourceYaml=${resourceYamlParams.length} relationship=${relationshipParams.length} processLogical=${processLogicalParams.length} processLogicalPaginate=${processLogicalPaginateParams.length} findData=${findDataParams.length}`
93
+ `[Schema] components generated endpoint=${endpointParams.length} \nendpointComplete=${endpointCompleteParams.length} \nresourceYaml=${resourceYamlParams.length} \nrelationship=${relationshipParams.length} \nprocessLogical=${processLogicalParams.length} \nprocessLogicalPaginate=${processLogicalPaginateParams.length} \nfindData=${findDataParams.length} \nsystemText=${systemTextParams.length} \nrbac=${rbacParams.length}`
87
94
  );
88
95
 
89
96
  const allCreateSourceParams = [
@@ -93,7 +100,9 @@ async function generateTemplateDataFromSchema(
93
100
  ...relationshipParams,
94
101
  ...processLogicalParams,
95
102
  ...processLogicalPaginateParams,
96
- ...findDataParams
103
+ ...findDataParams,
104
+ ...systemTextParams,
105
+ ...rbacParams
97
106
  ];
98
107
 
99
108
  const uniqueSortedTargetFiles = Array.from(
@@ -25,10 +25,10 @@ import {
25
25
  consts,
26
26
  } from '@izara_project/izara-core-library-service-schemas';
27
27
 
28
- const { TOPIC_NAME_GENERATE_CODE } = consts;
29
- const PREFIX = {
30
- updateNode: 'updateNode',
31
- };
28
+ const { TOPIC_NAME_GENERATE_CODE, PREFIX } = consts;
29
+ // const PREFIX = {
30
+ // updateNode: 'updateNode',
31
+ // };
32
32
 
33
33
  //(<optionalRequire>)
34
34
  //(</optionalRequire>)
@@ -253,9 +253,9 @@ async function data(
253
253
  const resourceApis =
254
254
  handler === HANDLER.hdrApi
255
255
  ? allObjSchemas.map(objectSchema => ({
256
- event: lowerCase(objectSchema.objectType),
257
- method: HTTP_METHOD[action]
258
- }))
256
+ event: lowerCase(objectSchema.objectType),
257
+ method: HTTP_METHOD[action]
258
+ }))
259
259
  : [];
260
260
 
261
261
  // ── External topic SNS permissions (create only) ──────────────────────────
@@ -19,23 +19,26 @@ import { join } from 'path';
19
19
 
20
20
  import libs from '#libs/Utils.js';
21
21
 
22
- const { checkValidTableYaml } = libs;
23
- import createSourceTranslations from './translations/data.js';
22
+ import createSourceSystemText from './systemText/data.js';
24
23
 
25
- async function translationComponent(
24
+ async function systemTextComponent(
26
25
  _izContext,
27
26
  appPath,
28
27
  allObjSchemas,
29
- allFlowSchemas
28
+ allRelationshipSchemas,
29
+ allFlowSchemas,
30
+ notificationSchemas
30
31
  ) {
31
32
  try {
32
33
  const objSchemaPath = join(appPath, '/src/schemas');
33
34
 
34
35
  const createSources = [];
35
- const translationComponent = await createSourceTranslations(
36
+ const translationComponent = await createSourceSystemText(
36
37
  _izContext,
37
- allObjSchemas,
38
+ allObjSchemas.records,
39
+ allRelationshipSchemas,
38
40
  allFlowSchemas,
41
+ notificationSchemas,
39
42
  objSchemaPath
40
43
  );
41
44
 
@@ -52,4 +55,4 @@ async function translationComponent(
52
55
  }
53
56
  }
54
57
 
55
- export default translationComponent;
58
+ export default systemTextComponent;
@@ -40,47 +40,82 @@ import { utils as coreUtils } from '@izara_project/izara-core-library-service-sc
40
40
  *
41
41
  * @return {{ templatePath, templateData, setting } }
42
42
  */
43
- function createSourceTranslations(
43
+ function createSourceSystemText(
44
44
  _izContext,
45
45
  allObjectSchema,
46
+ allRelSchema,
46
47
  allFlowSchemas,
48
+ notificationSchemas,
47
49
  schemaPath
48
50
  ) {
49
51
  const createSourceArray = [];
50
52
  // console.log("params objSchema", JSON.stringify(allObjectSchema, null, 2));
51
- for (const objectSchema of allObjectSchema.records) {
52
- for (const fieldName of Object.keys(objectSchema.fieldNames)) {
53
+ for (const objectSchema of allObjectSchema) {
54
+ const fieldNames = [...Object.keys(objectSchema.fieldNames)];
55
+ if (objectSchema.hasOwnProperty("addOnDataStructure")) {
56
+ for (const addOn of objectSchema.addOnDataStructure) {
57
+ if (addOn.type === "versionedData") {
58
+ fieldNames.push(...Object.keys(addOn.fieldNames))
59
+ }
60
+ }
61
+ };
62
+
63
+ for (const fieldName of fieldNames) {
53
64
  const objType = {
54
65
  objectType: objectSchema.objectType,
55
66
  serviceTag: getLocalConfig('iz_serviceTag')
56
67
  };
57
- const translationTextObjSchemas = {
68
+ const systemTextObjectSchemas = {
58
69
  nameSpace: `${coreUtils.createObjTypeConcat(_izContext, objType)}_description`, // for each objectType
59
70
  systemTextTag: `${fieldName}_${coreUtils.createObjTypeConcat(_izContext, objType)}` // for each fieldName
60
71
  };
61
- createSourceArray.push(translationTextObjSchemas);
72
+ createSourceArray.push(systemTextObjectSchemas);
62
73
  }
63
74
  }
64
75
 
65
- for (const flowSchema of allFlowSchemas.records) {
76
+ for (const flowSchema of allFlowSchemas) {
66
77
  const flowType = {
67
78
  flowTag: flowSchema.flowTag,
68
79
  serviceTag: getLocalConfig('iz_serviceTag')
69
80
  };
70
- const translationTextFlowSchemas = {
81
+ const systemTextFlowSchemas = {
71
82
  nameSpace: `${coreUtils.createFlowTypeConcat(_izContext, flowType)}`, // for each flowType
72
83
  systemTextTag: `errors_${coreUtils.createFlowTypeConcat(_izContext, flowType)}`
73
84
  };
74
- createSourceArray.push(translationTextFlowSchemas);
85
+ createSourceArray.push(systemTextFlowSchemas);
75
86
  }
76
87
 
88
+ for (const relSchema of allRelSchema) {
89
+ const relTag = Object.keys(relSchema)[0]
90
+ const relType = {
91
+ serviceTag: getLocalConfig('iz_serviceTag'),
92
+ relationshipTag: relTag
93
+ };
94
+
95
+ for (const fieldName of Object.keys(relSchema[relTag].fieldNames)) {
96
+ const systemTextRelSchemas = {
97
+ nameSpace: `${coreUtils.createRelTypeConcat(_izContext, relType)}_description`,
98
+ systemTextTag: `${fieldName}_${coreUtils.createRelTypeConcat(_izContext, relType)}`
99
+ }
100
+ createSourceArray.push(systemTextRelSchemas);
101
+ }
102
+ }
103
+ console.log("notificationSchemas", notificationSchemas);
104
+ for (const notification of notificationSchemas) {
105
+ const notificationSystemText = {
106
+ nameSpace: `sysNotification_${notification.notificationGrouping}`,
107
+ systemTextTag: notification.notificationTag
108
+ }
109
+ createSourceArray.push(notificationSystemText)
110
+ }
111
+ // console.log("schemaPath", schemaPath)
77
112
  // console.log("createSourceArray", createSourceArray)
78
113
  return {
79
114
  templatePath: templatePath,
80
115
  templateData: { datas: createSourceArray },
81
116
  setting: {
82
- savePath: path.join(schemaPath, SOURCE_PATH.translationSchema),
83
- saveFileName: SAVE_FILE_NAME.translationSchema,
117
+ savePath: path.join(schemaPath, SOURCE_PATH.systemTextSchema),
118
+ saveFileName: SAVE_FILE_NAME.systemTextSchema,
84
119
  fileExtension: '.js',
85
120
  isAppend: true,
86
121
  generateHookFile: false
@@ -88,4 +123,4 @@ function createSourceTranslations(
88
123
  };
89
124
  }
90
125
 
91
- export default createSourceTranslations;
126
+ export default createSourceSystemText;
@@ -0,0 +1,112 @@
1
+ /*
2
+ Copyright (C) 2020 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 path from 'path';
19
+ import { fileURLToPath } from 'url';
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ import consts from '#libs/Consts.js';
24
+ const { SOURCE_PATH, SAVE_FILE_NAME } = consts;
25
+ const templatePath = path.join(__dirname, '../../../resourceYamlComponent/dynamodb/template.ejs');
26
+
27
+ /**
28
+ * create param of crateSouce for FindData And processLogical
29
+ *
30
+ * @param {Object} _izContext
31
+ * @param {String} srcPath
32
+ * @returns {Object[]}
33
+ */
34
+ const createAwaitingMultipleStepDynamoDbData = (_izContext, srcPath) => {
35
+ let resultsForCreateSource = [];
36
+ const defaultDynamoDataLists = [];
37
+
38
+ defaultDynamoDataLists.push(
39
+ {
40
+ tableName: 'Permission',
41
+ resourceName: 'Permission',
42
+ attributes: [
43
+ {
44
+ keyType: 'partitionKey',
45
+ AttributeName: 'targetObjTypeConcat',
46
+ AttributeType: 'S'
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ tableName: 'RolePermissions',
52
+ resourceName: 'RolePermissions',
53
+ attributes: [
54
+ {
55
+ keyType: 'partitionKey',
56
+ AttributeName: 'roleIdKey',
57
+ AttributeType: 'S'
58
+ },
59
+ {
60
+ keyType: 'sortKey',
61
+ AttributeName: 'service_resource_action',
62
+ AttributeType: 'S'
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ tableName: 'Roles',
68
+ resourceName: 'Roles',
69
+ attributes: [
70
+ {
71
+ keyType: 'partitionKey',
72
+ AttributeName: 'roleIdKey',
73
+ AttributeType: 'S'
74
+ }
75
+ ]
76
+ },
77
+ {
78
+ tableName: 'UserRoles',
79
+ resourceName: 'UserRoles',
80
+ attributes: [
81
+ {
82
+ keyType: 'partitionKey',
83
+ AttributeName: 'userId',
84
+ AttributeType: 'S'
85
+ },
86
+ {
87
+ keyType: 'sortKey',
88
+ AttributeName: 'roleIdKey',
89
+ AttributeType: 'S'
90
+ }
91
+ ]
92
+ }
93
+ );
94
+
95
+ for (let defaultlDynamoData of defaultDynamoDataLists) {
96
+ resultsForCreateSource.push({
97
+ templatePath: templatePath,
98
+ templateData: defaultlDynamoData,
99
+ setting: {
100
+ initialData: 'Resources:\n',
101
+ savePath: path.join(srcPath, SOURCE_PATH.resourceYaml),
102
+ saveFileName: SAVE_FILE_NAME.dynamoDbYaml,
103
+ fileExtension: '.yml',
104
+ isAppend: true
105
+ }
106
+ });
107
+ };
108
+
109
+ return resultsForCreateSource;
110
+ };
111
+
112
+ export default createAwaitingMultipleStepDynamoDbData;
@@ -0,0 +1,74 @@
1
+ /*
2
+ Copyright (C) 2020 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 required modules
19
+ import { join } from 'path';
20
+ import { getObjectSchema } from '@izara_project/izara-core-library-service-schemas';
21
+ const { getAllLocalObjectSchemasWithHierarchy } = getObjectSchema;
22
+
23
+ // lambda
24
+ import authInvHandler from './lambda/authInv/handler/data.js'
25
+ import authInvMain from './lambda/authInv/mainFunction/data.js'
26
+
27
+ // auth for api
28
+ import authApi from './lambda/authApi/data.js'
29
+ // yaml
30
+ import authYaml from './lambda/yaml/data.js';
31
+ // dynamo
32
+ import dynamo from './dynamoDb/data.js';
33
+
34
+ /**
35
+ * Generates code with templates for different actions
36
+ * @param {Object} _izContext - Context object
37
+ * @param {string} appPath - Path to the schema
38
+ * @returns {Array} Array of generated code parameters
39
+ */
40
+ async function generateCodeWithTemplate(
41
+ _izContext,
42
+ appPath,
43
+ allObjSchemas,
44
+ ) {
45
+ try {
46
+ const createSourceParams = [];
47
+ if (allObjSchemas.records.some(objectSchema => objectSchema.addOnDataStructure?.some(addOn => addOn.type === 'rbac'))) {
48
+ const handlerInvComponent = authInvHandler(_izContext, appPath);
49
+ const mainFunctionInvComponent = authInvMain(_izContext, appPath);
50
+ const authApiComponent = authApi(_izContext, appPath);
51
+ const yamlInvComponent = await authYaml(_izContext, appPath);
52
+ const dynamoRbacPermission = dynamo(_izContext, appPath);
53
+
54
+
55
+ createSourceParams.push(
56
+ mainFunctionInvComponent,
57
+ handlerInvComponent,
58
+ authApiComponent,
59
+ ...yamlInvComponent,
60
+ ...dynamoRbacPermission
61
+ );
62
+
63
+ }
64
+
65
+
66
+
67
+ return createSourceParams;
68
+ } catch (error) {
69
+ _izContext.logger.error('Error generating code with template:', error);
70
+ return [];
71
+ }
72
+ }
73
+
74
+ export default generateCodeWithTemplate;