@izara_project/izara-market-library-service-schemas 1.0.1 → 1.0.2

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 (31) hide show
  1. package/index.js +25 -0
  2. package/package.json +6 -2
  3. package/src/GenerateCodeLibs/index.js +24 -0
  4. package/src/GenerateCodeLibs/src/GenerateCodeLibs.js +1373 -0
  5. package/src/MainLibs/index.js +24 -0
  6. package/src/MainLibs/src/Consts.js +0 -0
  7. package/src/MainLibs/src/Utils.js +27 -0
  8. package/src/SourceManager/index.js +23 -0
  9. package/src/SourceManager/src/CreateSource.js +182 -0
  10. package/src/SourceManager/src/Utils.js +50 -0
  11. package/src/TemplateManager/index.js +23 -0
  12. package/src/TemplateManager/src/GenerateCode.js +135 -0
  13. package/src/TemplateManager/src/MainResourcesYaml/CreateSourceData.js +76 -0
  14. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Data/MainDynamoDbYamlData.js +153 -0
  15. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.ejs +31 -0
  16. package/src/TemplateManager/src/MainResourcesYaml/TemplateAndData/DynamoDbMain/Template/DynamoDb.exampleData.js +12 -0
  17. package/src/TemplateManager/src/PerActionEndpoint/CreateSourceData.js +131 -0
  18. package/src/TemplateManager/src/PerActionEndpoint/DataPerActionEndpoint.js +0 -0
  19. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/Handler/Handler.js +0 -0
  20. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Create.js +18 -0
  21. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Delete.js +18 -0
  22. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Get.js +18 -0
  23. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplate/Update.js +18 -0
  24. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/MainFunction/MainFunctionTemplateData.js +0 -0
  25. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Data/LambdaYamlData.js +166 -0
  26. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrApi.ejs +0 -0
  27. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrDsq.ejs +0 -0
  28. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.ejs +26 -0
  29. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrInv.exampleData.js +15 -0
  30. package/src/TemplateManager/src/PerActionEndpoint/TemplateAndData/ResourceYaml/Lambda/Template/HdrSqs.ejs +0 -0
  31. package/src/TemplateManager/src/libs/Consts.js +108 -0
@@ -0,0 +1,108 @@
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
+ 'use strict';
19
+
20
+ const {
21
+ HANDLER,
22
+ ACTIONS
23
+ } = require('@izara_project/izara-core-library-service-schemas/src/Consts');
24
+
25
+
26
+ const DEFAULT_HANDLER_PER_ACTION = {
27
+ [ACTIONS.create]: [HANDLER.hdrApi, HANDLER.hdrSqs],
28
+ [ACTIONS.update]: [HANDLER.hdrApi, HANDLER.hdrSqs],
29
+ [ACTIONS.get]: [HANDLER.hdrApi, HANDLER.hdrInv],
30
+ [ACTIONS.delete]: [HANDLER.hdrApi, HANDLER.hdrSqs]
31
+ }
32
+
33
+ const RESOURCE_CLASSES = {
34
+ sqs: 'sqs',
35
+ s3: 's3',
36
+ dynamoDbTable: 'dynamodb',
37
+ sns: "SNS",
38
+ lambda: "lambda"
39
+ };
40
+
41
+
42
+ function resourceNames(resourceClass, resourceName) {
43
+ return {
44
+ [RESOURCE_CLASSES.sqs]: "arn:aws:sqs:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}" + resourceName,
45
+ [RESOURCE_CLASSES.s3]: "arn:aws:s3:::" + resourceName,
46
+ [RESOURCE_CLASSES.dynamoDbTable]: "arn:aws:dynamodb:${self:custom.iz_region}:${self:custom.iz_accountId}:table/${self:custom.iz_resourcePrefix}" + resourceName,
47
+ [RESOURCE_CLASSES.sns]: "arn:aws:sns:${self:custom.iz_region}:${self:custom.iz_accountId}:${self:custom.iz_resourcePrefix}" + resourceName,
48
+ [RESOURCE_CLASSES.lambda]: "arn:aws:lambda:${self:custom.iz_region}:${self:custom.iz_accountId}:function:" + resourceName
49
+ }[resourceClass];
50
+ }
51
+
52
+
53
+ function createIamRole(action, resource = [], effect = "Allow") {
54
+ for (const resourceAction in action) {
55
+ if (typeof (action[resourceAction]) === 'string') {
56
+ action[resourceAction] = [action[resourceAction]]
57
+ }
58
+
59
+ if (!Array.isArray(action[resourceAction])) {
60
+ throw new Error(`resourceAction:${resourceAction} should be string or array`);
61
+ }
62
+ }
63
+
64
+ return {
65
+ effect,
66
+ action,
67
+ resource
68
+ };
69
+ }
70
+
71
+
72
+ // relative with ./app/src
73
+ const SOURCE_PATH = {
74
+ appYaml: `../sls_yaml/generatedCode/source/`,
75
+ resourceYaml: `../../resource/sls_yaml/generatedCode/source/`,
76
+ lambdaPerObjectTypePath: `/generatedCode/lambdaPerObjectType/source/`,
77
+ lamdaPerCombindActionPath: `/generatedCode/lamdaPerCombindAction/source/`,
78
+ };
79
+
80
+
81
+ const DEFAULT_LAMBDA_ROLE_PER_ACTION = {
82
+ [ACTIONS.create]: {
83
+ dynamoDbPermission: 'PutItem',
84
+ httpMethod: 'put',
85
+ },
86
+ [ACTIONS.update]: {
87
+ dynamoDbPermission: 'UpdateItem',
88
+ httpMethod: 'post',
89
+ },
90
+ [ACTIONS.get]: {
91
+ dynamoDbPermission: 'GetItem',
92
+ httpMethod: 'post',
93
+ },
94
+ [ACTIONS.delete]: {
95
+ dynamoDbPermission: 'DeleteItem',
96
+ httpMethod: 'delete',
97
+ }
98
+ }
99
+
100
+ module.exports = {
101
+ ACTIONS,
102
+ DEFAULT_HANDLER_PER_ACTION,
103
+ RESOURCE_CLASSES,
104
+ resourceNames,
105
+ createIamRole,
106
+ SOURCE_PATH,
107
+ DEFAULT_LAMBDA_ROLE_PER_ACTION
108
+ }