@izara_project/izara-core-generate-service-code 1.0.43 → 1.0.45

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 (46) hide show
  1. package/package.json +3 -3
  2. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/mainFunction/template.ejs +1 -1
  3. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/queueNtopic/sqsTemplate.ejs +8 -8
  4. package/src/generateCode/generateFlowStepWithPlugIn/firstFlowStep/yaml/template.ejs +13 -1
  5. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/data.js +12 -12
  6. package/src/generateCode/generateInitialSetup/externalServiceComponent/lambdaRole/template.ejs +1 -0
  7. package/src/generateCode/generateSchema/actionEndpointComponent/mainFunction/get/template.ejs +1 -1
  8. package/src/generateCode/generateSchema/findDataComponent/GetByStorage/getByGraph.ejs +1 -1
  9. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/data.js +37 -18
  10. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/template.ejs +33 -9
  11. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/data.js +26 -11
  12. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/template.ejs +33 -9
  13. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/data.js +28 -11
  14. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/template.ejs +33 -9
  15. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/data.js +26 -13
  16. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/template.ejs +27 -9
  17. package/src/generateCode/generateSchema/relationshipPerActionComponent/index.js +3 -2
  18. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/data.js +27 -11
  19. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/template.ejs +33 -9
  20. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/data.js +27 -6
  21. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/template.ejs +33 -9
  22. package/src/libs/Libs.js +13 -12
  23. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -20
  24. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -17
  25. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  26. package/src/generateCode/generateSchema/relationshipPerActionComponent/changeRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -18
  27. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -21
  28. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -17
  29. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  30. package/src/generateCode/generateSchema/relationshipPerActionComponent/create/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -17
  31. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -21
  32. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -17
  33. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  34. package/src/generateCode/generateSchema/relationshipPerActionComponent/delete/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -18
  35. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -21
  36. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -17
  37. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  38. package/src/generateCode/generateSchema/relationshipPerActionComponent/get/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -18
  39. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -20
  40. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -17
  41. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  42. package/src/generateCode/generateSchema/relationshipPerActionComponent/moveRelationship/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -17
  43. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/templateByHandler/apiTemplate.ejs +0 -20
  44. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/templateByHandler/dsqTemplate.ejs +0 -18
  45. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/templateByHandler/invTemplate.ejs +0 -13
  46. package/src/generateCode/generateSchema/relationshipPerActionComponent/update/action/functionYaml/templateByHandler/sqsTemplate.ejs +0 -17
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@izara_project/izara-core-generate-service-code",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
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",
@@ -26,8 +26,8 @@
26
26
  "dependencies": {
27
27
  "@izara_project/izara-core-library-core": "^1.0.32",
28
28
  "@izara_project/izara-core-library-logger": "^1.0.9",
29
- "@izara_project/izara-core-library-s3": "^1.0.8",
30
- "@izara_project/izara-core-library-service-schemas": "^1.0.141",
29
+ "@izara_project/izara-core-library-s3": "^1.0.9",
30
+ "@izara_project/izara-core-library-service-schemas": "^1.0.145",
31
31
  "@izara_project/izara-shared-core": "^1.0.12",
32
32
  "ejs": "^5.0.1",
33
33
  "js-beautify": "^1.15.4",
@@ -55,7 +55,7 @@ export default async function <%- functionName %>(
55
55
  _izContext.logger.debug('<%- functionName %> callingFlowConfig: ', callingFlowConfig);
56
56
 
57
57
  //(<hookCode>)
58
- //(<hookCode>)
58
+ //(</hookCode>)
59
59
 
60
60
  <% if (handleLogic === 'awaitingMultipleSteps') { %>
61
61
  <%- include(templateAwaitingStep, { childFlow, mainObjType }) %>
@@ -1,22 +1,22 @@
1
1
  #------- queue ---------
2
- <%- queueName %>HdrSqs:
2
+ <%- queueName %>:
3
3
  Type: "AWS::SQS::Queue"
4
4
  Properties:
5
- QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqs
5
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>
6
6
  RedrivePolicy:
7
7
  deadLetterTargetArn: #!GetAtt
8
8
  Fn::GetAtt:
9
- - <%- queueName %>HdrSqsDLQ
9
+ - <%- queueName %>DLQ
10
10
  - Arn
11
11
  maxReceiveCount: 3
12
12
  VisibilityTimeout: 120
13
13
 
14
- <%- queueName %>HdrSqsDLQ:
14
+ <%- queueName %>DLQ:
15
15
  Type: AWS::SQS::Queue
16
16
  Properties:
17
- QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>HdrSqsDLQ
17
+ QueueName: ${self:custom.iz_resourcePrefix}<%- queueName %>DLQ
18
18
 
19
- <%- queueName %>HdrSqsPolicy:
19
+ <%- queueName %>Policy:
20
20
  Type: AWS::SQS::QueuePolicy
21
21
  Properties:
22
22
  PolicyDocument:
@@ -27,11 +27,11 @@
27
27
  Principal: "*"
28
28
  Resource: #!GetAtt
29
29
  Fn::GetAtt:
30
- - <%- queueName %>HdrSqs
30
+ - <%- queueName %>
31
31
  - Arn
32
32
  Action: "SQS:SendMessage"
33
33
  Queues:
34
- - Ref: <%- queueName %>HdrSqs
34
+ - Ref: <%- queueName %>
35
35
  #<#<%- firstLetterUpperCase(queueName) %>QueueSetting#>
36
36
  #<#/<%- firstLetterUpperCase(queueName) %>QueueSetting#>
37
37
 
@@ -1,5 +1,5 @@
1
1
  <%- functionNameConfig %>:
2
- handler: <%- handlerPath %>
2
+ handler: <%- handlerPath %>.main
3
3
  name: ${self:custom.iz_resourcePrefix}<%- functionName %>
4
4
  role: <%- roleName %>Role
5
5
  #<#<%- hookTagSetting %>#>
@@ -9,6 +9,18 @@
9
9
  - sqs:
10
10
  arn: <%- event %>
11
11
  batchSize: 10
12
+ <%_ if (eventFlow === 'extTopic') { _%>
13
+ filterPatterns: #**** need to update serverless framework upper v.2.69.1
14
+ - body: { 'MessageAttributes': {
15
+ 'callingFlow': {
16
+ 'Value': ['${self:custom.iz_resourcePrefix}<%- functionName %>']
17
+ }
18
+ }
19
+ } # functionName of callingFlow
20
+ - body: {
21
+ 'MessageAttributes': { 'callingFlow': { 'Value': [{ 'exists': false }] } }
22
+ }
23
+ <%_ } _%>
12
24
  <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
13
25
  events:
14
26
  <%_ resourceApis.forEach(api => { _%>
@@ -85,7 +85,7 @@ async function createExternalLambdaRole(
85
85
  role(
86
86
  lam,
87
87
  LAMBDA_RESOURCE.invokeFunction,
88
- extRes(lam, 'GetNodeV2HdrInv', resourceGraphServiceTag)
88
+ extRes(lam, 'GetNodeHdrInv', resourceGraphServiceTag)
89
89
  ),
90
90
  role(
91
91
  sns,
@@ -97,16 +97,16 @@ async function createExternalLambdaRole(
97
97
  SNS_RESOURCE.publish,
98
98
  extRes(sns, 'CreateNode_In', resourceGraphServiceTag)
99
99
  ),
100
- role(
101
- lam,
102
- LAMBDA_RESOURCE.invokeFunction,
103
- extRes(lam, 'CreateNodeV2HdrInv', resourceGraphServiceTag)
104
- ),
105
- role(
106
- lam,
107
- LAMBDA_RESOURCE.invokeFunction,
108
- extRes(lam, 'UpdateNodeHdrInv', resourceGraphServiceTag)
109
- )
100
+ // role(
101
+ // lam,
102
+ // LAMBDA_RESOURCE.invokeFunction,
103
+ // extRes(lam, 'CreateNodeV2HdrInv', resourceGraphServiceTag)
104
+ // ),
105
+ // role(
106
+ // lam,
107
+ // LAMBDA_RESOURCE.invokeFunction,
108
+ // extRes(lam, 'UpdateNodeHdrInv', resourceGraphServiceTag)
109
+ // )
110
110
  ]
111
111
  });
112
112
  }
@@ -167,7 +167,7 @@ async function createExternalLambdaRole(
167
167
  role(
168
168
  lam,
169
169
  LAMBDA_RESOURCE.invokeFunction,
170
- extRes(lam, 'GetNodeV2HdrInv', processTags)
170
+ extRes(lam, 'GetNodeHdrInv', processTags)
171
171
  )
172
172
  ]
173
173
  });
@@ -19,6 +19,7 @@ import Logger from '@izara_project/izara-core-library-logger';
19
19
  import dynamodbSharedLib from '@izara_project/izara-core-library-dynamodb';
20
20
  import lambdaSharedLib from '@izara_project/izara-core-library-lambda';
21
21
  import snsSharedLib from '@izara_project/izara-core-library-sns';
22
+ import initialSetupConfig from '../../config/Config.js';
22
23
  const _izContext = { logger: Logger }
23
24
 
24
25
  export function generatedLambdaRole() {
@@ -109,7 +109,7 @@ export default async function getMain(
109
109
  //(<beforeGetGraph>)
110
110
  //(</beforeGetGraph>)
111
111
 
112
- const dataFromGraph = await graphSharedLib.getNodeV2(
112
+ const dataFromGraph = await graphSharedLib.getNode(
113
113
  _izContext,
114
114
  graphServiceName,
115
115
  objType,
@@ -6,7 +6,7 @@ const graphHandlerServiceTag = await serviceConfig.getGraphServiceTagWithCache(
6
6
  );
7
7
  _izContext.logger.debug('graphHandlerServiceTag: ', graphHandlerServiceTag)
8
8
 
9
- let getDataByGraph = await graphSharedLib.getNodeV2(
9
+ let getDataByGraph = await graphSharedLib.getNode(
10
10
  _izContext,
11
11
  graphHandlerServiceTag,
12
12
  objType,
@@ -19,7 +19,6 @@ import path from 'path';
19
19
  import { fileURLToPath } from 'url';
20
20
  const __filename = fileURLToPath(import.meta.url);
21
21
  const __dirname = path.dirname(__filename);
22
-
23
22
  import consts from '#libs/Consts.js';
24
23
  import utils from '#libs/Utils.js';
25
24
  import libs from '#libs/Libs.js';
@@ -36,7 +35,10 @@ const {
36
35
  HANDLER
37
36
  } = consts;
38
37
 
39
- const { firstLetterUpperCase: upperCase, getLocalConfig } = utils;
38
+ const { firstLetterUpperCase: upperCase,
39
+ firstLetterLowerCase: lowerCase,
40
+ getLocalConfig
41
+ } = utils;
40
42
 
41
43
  const {
42
44
  createIamRole,
@@ -48,11 +50,6 @@ const {
48
50
 
49
51
  const templatePath = path.join(__dirname, 'template.ejs');
50
52
 
51
- const apiTemplate = path.join(__dirname, 'templateByHandler/apiTemplate.ejs');
52
- const dsqTemplate = path.join(__dirname, 'templateByHandler/dsqTemplate.ejs');
53
- const invTemplate = path.join(__dirname, 'templateByHandler/invTemplate.ejs');
54
- const sqsTemplate = path.join(__dirname, 'templateByHandler/sqsTemplate.ejs');
55
-
56
53
  /**
57
54
  * receive objectSchema
58
55
  * create data for updateRelationshipSchema
@@ -61,19 +58,23 @@ const sqsTemplate = path.join(__dirname, 'templateByHandler/sqsTemplate.ejs');
61
58
  * @return {{ templatePath, templateData, setting } }
62
59
  */
63
60
 
64
- function data(_izContext, srcPath) {
61
+ function data(_izContext, allObjectRelationships, srcPath) {
65
62
  let createSourceArray = [];
66
63
  for (const handlerType of Object.values(HANDLER)) {
67
- const createSourceParam = createParamForCreateSource(handlerType, srcPath);
64
+ const createSourceParam = createParamForCreateSource(
65
+ allObjectRelationships,
66
+ handlerType,
67
+ srcPath
68
+ );
68
69
  createSourceArray.push(createSourceParam);
69
70
  }
70
- // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", JSON.stringify(createSourceArray, null, 2))
71
+ // console.log("createSourceArrayInUpdaterelationShipSchemahdrSqs", createSourceArray)
71
72
  return createSourceArray;
72
73
  }
73
74
 
74
- function createParamForCreateSource(handlerType, srcPath) {
75
- let functionName = upperCase(FUNCTION_NAME.changeRel);
76
- let additionalResourcePermission = defaultIamRolePerAction();
75
+ function createParamForCreateSource(allObjectRelationships, handlerType, srcPath) {
76
+ const functionName = upperCase(FUNCTION_NAME.changeRel);
77
+ const additionalResourcePermission = defaultIamRolePerAction();
77
78
 
78
79
  additionalResourcePermission.push(awaitingMultipleStepsRole());
79
80
 
@@ -134,6 +135,21 @@ function createParamForCreateSource(handlerType, srcPath) {
134
135
  );
135
136
  }
136
137
 
138
+ const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType));
139
+
140
+ const serviceTag = getLocalConfig('iz_serviceTag');
141
+
142
+ const resourcesApi = [];
143
+ if (handlerType === HANDLER.hdrApi) {
144
+ allObjectRelationships.map(relationshipSchema => (
145
+ resourcesApi.push({
146
+ event: lowerCase(Object.keys(relationshipSchema)[0]),
147
+ method: 'post',
148
+ action: 'change'
149
+ }))
150
+ )
151
+ }
152
+
137
153
  return {
138
154
  templatePath: templatePath,
139
155
  templateData: {
@@ -145,11 +161,14 @@ function createParamForCreateSource(handlerType, srcPath) {
145
161
  upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.changeRel)) +
146
162
  upperCase(shortNameHandler(handlerType)),
147
163
  roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole,
148
- serviceTag: getLocalConfig('iz_serviceTag'),
149
- apiTemplate,
150
- dsqTemplate,
151
- invTemplate,
152
- sqsTemplate
164
+ resourceApis: resourcesApi.map(api => ({
165
+ path: `/${serviceTag}/${api.event}/${api.action}`,
166
+ pathWithUser: `/${serviceTag}/${api.event}/${api.action}/{targetUserId}`,
167
+ method: api.method,
168
+ hookTagApp: `${upperCase(api.event)}AppLevelAuthorizer`,
169
+ hookTagUser: `${upperCase(api.event)}UserLevelAuthorizer`
170
+ })),
171
+ event
153
172
  },
154
173
  setting: {
155
174
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
@@ -1,9 +1,33 @@
1
- <% if (handlerType === "hdrApi") { %>
2
- <%- include(apiTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName, serviceTag } %>
3
- <% } else if (handlerType === "hdrDsq") { %>
4
- <%- include(dsqTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
5
- <% } else if (handlerType === "hdrInv") { %>
6
- <%- include(invTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
7
- <% } else if (handlerType === "hdrSqs") { %>
8
- <%- include(sqsTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
9
- <% } %>
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ role: <%- roleName %>Role
6
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
7
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
8
+ <%_ if (handlerType === 'hdrDsq' || handlerType === 'hdrSqs') { _%>
9
+ events:
10
+ - sqs:
11
+ arn: <%- event %>
12
+ batchSize: 10
13
+ <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
14
+ events:
15
+ <%_ resourceApis.forEach(api => { _%>
16
+ - httpApi:
17
+ path: <%- api.path %>
18
+ method: <%- api.method %>
19
+ #<#<%- api.hookTagApp %>#>
20
+ # authorizer: authorizerServiceSchema
21
+ #<#/<%- api.hookTagApp %>#>
22
+ - httpApi:
23
+ path: <%- api.pathWithUser %>
24
+ method: <%- api.method %>
25
+ #<#<%- api.hookTagUser %>#>
26
+ # authorizer: authorizerIdentifiers
27
+ #<#/<%- api.hookTagUser %>#>a
28
+ <%_ }) _%>
29
+ <%_ } _%>
30
+
31
+ <%_ function firstLetterUpperCase(text) {
32
+ return text.charAt(0).toUpperCase() + text.slice(1)
33
+ } _%>
@@ -37,7 +37,10 @@ const {
37
37
  HANDLER
38
38
  } = consts;
39
39
 
40
- const { firstLetterUpperCase: upperCase, getLocalConfig } = utils;
40
+ const { firstLetterUpperCase: upperCase,
41
+ firstLetterLowerCase: lowerCase,
42
+ getLocalConfig
43
+ } = utils;
41
44
 
42
45
  const {
43
46
  createIamRole,
@@ -51,11 +54,6 @@ const {
51
54
 
52
55
  const templatePath = path.join(__dirname, 'template.ejs');
53
56
 
54
- const apiTemplate = path.join(__dirname, 'templateByHandler/apiTemplate.ejs');
55
- const dsqTemplate = path.join(__dirname, 'templateByHandler/dsqTemplate.ejs');
56
- const invTemplate = path.join(__dirname, 'templateByHandler/invTemplate.ejs');
57
- const sqsTemplate = path.join(__dirname, 'templateByHandler/sqsTemplate.ejs');
58
-
59
57
  /**
60
58
  * receive objectSchema
61
59
  * create data for updateRelationshipSchema
@@ -175,6 +173,20 @@ function createParamForCreateSource(
175
173
  }
176
174
  }
177
175
 
176
+ const serviceTag = getLocalConfig('iz_serviceTag');
177
+
178
+ const resourcesApi = [];
179
+ if (handlerType === HANDLER.hdrApi) {
180
+ allObjectRelationships.map(relationshipSchema => (
181
+ resourcesApi.push({
182
+ event: lowerCase(Object.keys(relationshipSchema)[0]),
183
+ method: 'post',
184
+ action: 'create'
185
+ }))
186
+ )
187
+ }
188
+ const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType));
189
+
178
190
  return {
179
191
  templatePath: templatePath,
180
192
  templateData: {
@@ -186,11 +198,14 @@ function createParamForCreateSource(
186
198
  upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.createRel)) +
187
199
  upperCase(shortNameHandler(handlerType)),
188
200
  roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole,
189
- serviceTag: getLocalConfig('iz_serviceTag'),
190
- apiTemplate,
191
- dsqTemplate,
192
- invTemplate,
193
- sqsTemplate
201
+ resourceApis: resourcesApi.map(api => ({
202
+ path: `/${serviceTag}/${api.event}/${api.action}`,
203
+ pathWithUser: `/${serviceTag}/${api.event}/${api.action}/{targetUserId}`,
204
+ method: api.method,
205
+ hookTagApp: `${upperCase(api.event)}AppLevelAuthorizer`,
206
+ hookTagUser: `${upperCase(api.event)}UserLevelAuthorizer`
207
+ })),
208
+ event
194
209
  },
195
210
  setting: {
196
211
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
@@ -1,9 +1,33 @@
1
- <% if (handlerType === "hdrApi") { %>
2
- <%- include(apiTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName, serviceTag } %>
3
- <% } else if (handlerType === "hdrDsq") { %>
4
- <%- include(dsqTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
5
- <% } else if (handlerType === "hdrInv") { %>
6
- <%- include(invTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
7
- <% } else if (handlerType === "hdrSqs") { %>
8
- <%- include(sqsTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
9
- <% } %>
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ role: <%- roleName %>Role
6
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
7
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
8
+ <%_ if (handlerType === 'hdrDsq' || handlerType === 'hdrSqs') { _%>
9
+ events:
10
+ - sqs:
11
+ arn: <%- event %>
12
+ batchSize: 10
13
+ <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
14
+ events:
15
+ <%_ resourceApis.forEach(api => { _%>
16
+ - httpApi:
17
+ path: <%- api.path %>
18
+ method: <%- api.method %>
19
+ #<#<%- api.hookTagApp %>#>
20
+ # authorizer: authorizerServiceSchema
21
+ #<#/<%- api.hookTagApp %>#>
22
+ - httpApi:
23
+ path: <%- api.pathWithUser %>
24
+ method: <%- api.method %>
25
+ #<#<%- api.hookTagUser %>#>
26
+ # authorizer: authorizerIdentifiers
27
+ #<#/<%- api.hookTagUser %>#>
28
+ <%_ }) _%>
29
+ <%_ } _%>
30
+
31
+ <%_ function firstLetterUpperCase(text) {
32
+ return text.charAt(0).toUpperCase() + text.slice(1)
33
+ } _%>
@@ -37,7 +37,10 @@ const {
37
37
  HANDLER
38
38
  } = consts;
39
39
 
40
- const { firstLetterUpperCase: upperCase, getLocalConfig } = utils;
40
+ const { firstLetterUpperCase: upperCase,
41
+ firstLetterLowerCase: lowerCase,
42
+ getLocalConfig
43
+ } = utils;
41
44
 
42
45
  const {
43
46
  createIamRole,
@@ -51,11 +54,6 @@ const {
51
54
 
52
55
  const templatePath = path.join(__dirname, 'template.ejs');
53
56
 
54
- const apiTemplate = path.join(__dirname, 'templateByHandler/apiTemplate.ejs');
55
- const dsqTemplate = path.join(__dirname, 'templateByHandler/dsqTemplate.ejs');
56
- const invTemplate = path.join(__dirname, 'templateByHandler/invTemplate.ejs');
57
- const sqsTemplate = path.join(__dirname, 'templateByHandler/sqsTemplate.ejs');
58
-
59
57
  /**
60
58
  * receive objectSchema
61
59
  * create data for updateRelationshipSchema
@@ -175,6 +173,22 @@ function createParamForCreateSource(
175
173
  }
176
174
  }
177
175
 
176
+ const serviceTag = getLocalConfig('iz_serviceTag');
177
+
178
+ const resourcesApi = [];
179
+ if (handlerType === HANDLER.hdrApi) {
180
+ allObjectRelationships.map(relationshipSchema => (
181
+ resourcesApi.push({
182
+ event: lowerCase(Object.keys(relationshipSchema)[0]),
183
+ method: 'post',
184
+ action: 'delete'
185
+ }))
186
+ )
187
+ }
188
+
189
+ const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType));
190
+
191
+
178
192
  return {
179
193
  templatePath: templatePath,
180
194
  templateData: {
@@ -186,11 +200,14 @@ function createParamForCreateSource(
186
200
  upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.deleteRel)) +
187
201
  upperCase(shortNameHandler(handlerType)),
188
202
  roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole,
189
- serviceTag: getLocalConfig('iz_serviceTag'),
190
- apiTemplate,
191
- dsqTemplate,
192
- invTemplate,
193
- sqsTemplate
203
+ resourceApis: resourcesApi.map(api => ({
204
+ path: `/${serviceTag}/${api.event}/${api.action}`,
205
+ pathWithUser: `/${serviceTag}/${api.event}/${api.action}/{targetUserId}`,
206
+ method: api.method,
207
+ hookTagApp: `${upperCase(api.event)}AppLevelAuthorizer`,
208
+ hookTagUser: `${upperCase(api.event)}UserLevelAuthorizer`
209
+ })),
210
+ event
194
211
  },
195
212
  setting: {
196
213
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
@@ -1,9 +1,33 @@
1
- <% if (handlerType === "hdrApi") { %>
2
- <%- include(apiTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName, serviceTag } %>
3
- <% } else if (handlerType === "hdrDsq") { %>
4
- <%- include(dsqTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
5
- <% } else if (handlerType === "hdrInv") { %>
6
- <%- include(invTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
7
- <% } else if (handlerType === "hdrSqs") { %>
8
- <%- include(sqsTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
9
- <% } %>
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ role: <%- roleName %>Role
6
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
7
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
8
+ <%_ if (handlerType === 'hdrDsq' || handlerType === 'hdrSqs') { _%>
9
+ events:
10
+ - sqs:
11
+ arn: <%- event %>
12
+ batchSize: 10
13
+ <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
14
+ events:
15
+ <%_ resourceApis.forEach(api => { _%>
16
+ - httpApi:
17
+ path: <%- api.path %>
18
+ method: <%- api.method %>
19
+ #<#<%- api.hookTagApp %>#>
20
+ # authorizer: authorizerServiceSchema
21
+ #<#/<%- api.hookTagApp %>#>
22
+ - httpApi:
23
+ path: <%- api.pathWithUser %>
24
+ method: <%- api.method %>
25
+ #<#<%- api.hookTagUser %>#>
26
+ # authorizer: authorizerIdentifiers
27
+ #<#/<%- api.hookTagUser %>#>
28
+ <%_ }) _%>
29
+ <%_ } _%>
30
+
31
+ <%_ function firstLetterUpperCase(text) {
32
+ return text.charAt(0).toUpperCase() + text.slice(1)
33
+ } _%>
@@ -37,7 +37,10 @@ const {
37
37
  HANDLER
38
38
  } = consts;
39
39
 
40
- const { firstLetterUpperCase: upperCase, getLocalConfig } = utils;
40
+ const { firstLetterUpperCase: upperCase,
41
+ firstLetterLowerCase: lowerCase,
42
+ getLocalConfig
43
+ } = utils;
41
44
 
42
45
  const {
43
46
  createIamRole,
@@ -50,11 +53,6 @@ const {
50
53
  } = libs;
51
54
  const templatePath = path.join(__dirname, 'template.ejs');
52
55
 
53
- const apiTemplate = path.join(__dirname, 'templateByHandler/apiTemplate.ejs');
54
- const dsqTemplate = path.join(__dirname, 'templateByHandler/dsqTemplate.ejs');
55
- const invTemplate = path.join(__dirname, 'templateByHandler/invTemplate.ejs');
56
- const sqsTemplate = path.join(__dirname, 'templateByHandler/sqsTemplate.ejs');
57
-
58
56
  /**
59
57
  * receive objectSchema
60
58
  * create data for updateRelationshipSchema
@@ -82,8 +80,9 @@ function createParamForCreateSource(
82
80
  handlerType,
83
81
  srcPath
84
82
  ) {
85
- let functionName = upperCase(FUNCTION_NAME.getRel);
86
- let additionalResourcePermission = defaultIamRolePerAction();
83
+ const ownServiceTag = getLocalConfig('iz_serviceTag');
84
+ const functionName = upperCase(FUNCTION_NAME.getRel);
85
+ const additionalResourcePermission = defaultIamRolePerAction();
87
86
 
88
87
  additionalResourcePermission.push(awaitingMultipleStepsRole());
89
88
 
@@ -174,6 +173,19 @@ function createParamForCreateSource(
174
173
  }
175
174
  }
176
175
 
176
+ const resourcesApi = [];
177
+ if (handlerType === HANDLER.hdrApi) {
178
+ allObjectRelationships.map(relationshipSchema => (
179
+ resourcesApi.push({
180
+ event: lowerCase(Object.keys(relationshipSchema)[0]),
181
+ method: 'post',
182
+ action: 'get'
183
+ }))
184
+ )
185
+ }
186
+
187
+ const event = resourceNames(RESOURCE_CLASSES.sqs, upperCase(functionName) + upperCase(handlerType));
188
+
177
189
  return {
178
190
  templatePath: templatePath,
179
191
  templateData: {
@@ -185,11 +197,12 @@ function createParamForCreateSource(
185
197
  upperCase(SHORT_FUNCTION_NAME(FUNCTION_NAME.getRel)) +
186
198
  upperCase(shortNameHandler(handlerType)),
187
199
  roleName: SOURCE_GENERATE_IAM_ROLE.RelationshipRole,
188
- serviceTag: getLocalConfig('iz_serviceTag'),
189
- apiTemplate,
190
- dsqTemplate,
191
- invTemplate,
192
- sqsTemplate
200
+ resourceApis: resourcesApi.map(api => ({
201
+ path: `/${ownServiceTag}/${api.event}/${api.action}`,
202
+ method: api.method,
203
+ hookTagApp: `${upperCase(api.event)}AppLevelAuthorizer`,
204
+ })),
205
+ event
193
206
  },
194
207
  setting: {
195
208
  savePath: path.join(srcPath, SOURCE_PATH.appYaml),
@@ -1,9 +1,27 @@
1
- <% if (handlerType === "hdrApi") { %>
2
- <%- include(apiTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName, serviceTag } %>
3
- <% } else if (handlerType === "hdrDsq") { %>
4
- <%- include(dsqTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
5
- <% } else if (handlerType === "hdrInv") { %>
6
- <%- include(invTemplate), { functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
7
- <% } else if (handlerType === "hdrSqs") { %>
8
- <%- include(sqsTemplate),{ functionName, handlerType, additionalResourcePermission, resourceLocation, functionNameConfig, roleName } %>
9
- <% } %>
1
+ <%_ const join = require('path').join; _%>
2
+ <%- firstLetterUpperCase(functionNameConfig) %>:
3
+ handler: <%- join(resourceLocation, `${firstLetterUpperCase(functionName)}_${firstLetterUpperCase(handlerType)}.main`)%>
4
+ name: ${self:custom.iz_resourcePrefix}<%- firstLetterUpperCase(functionName) %><%- firstLetterUpperCase(handlerType) %>
5
+ role: <%- roleName %>Role
6
+ #<#<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
7
+ #<#/<%- functionName %><%- firstLetterUpperCase(handlerType) %>FunctionSetting#>
8
+ <%_ if (handlerType === 'hdrDsq' || handlerType === 'hdrSqs') { _%>
9
+ events:
10
+ - sqs:
11
+ arn: <%- event %>
12
+ batchSize: 10
13
+ <%_ } else if (handlerType === 'hdrApi' && resourceApis.length > 0) { _%>
14
+ events:
15
+ <%_ resourceApis.forEach(api => { _%>
16
+ - httpApi:
17
+ path: <%- api.path %>
18
+ method: <%- api.method %>
19
+ #<#<%- api.hookTagApp %>#>
20
+ # authorizer: authorizerServiceSchema
21
+ #<#/<%- api.hookTagApp %>#>
22
+ <%_ }) _%>
23
+ <%_ } _%>
24
+
25
+ <%_ function firstLetterUpperCase(text) {
26
+ return text.charAt(0).toUpperCase() + text.slice(1)
27
+ } _%>