serverless-api-gateway-caching
Advanced tools
Comparing version 1.7.1-rc1 to 1.7.1
@@ -0,0 +0,0 @@ { |
{ | ||
"name": "serverless-api-gateway-caching", | ||
"version": "1.7.1-rc1", | ||
"version": "1.7.1", | ||
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", | ||
@@ -22,3 +22,4 @@ "main": "src/apiGatewayCachingPlugin.js", | ||
"lodash.get": "^4.4.2", | ||
"lodash.isempty": "^4.4.0" | ||
"lodash.isempty": "^4.4.0", | ||
"lodash.split": "^4.4.0" | ||
}, | ||
@@ -37,5 +38,4 @@ "bugs": { | ||
"mocha-junit-reporter": "^1.18.0", | ||
"proxyquire": "^2.1.0", | ||
"lodash.split": "^4.4.0" | ||
"proxyquire": "^2.1.0" | ||
} | ||
} |
@@ -249,3 +249,3 @@ # serverless-api-gateway-caching | ||
functions: | ||
# Cache responses for POST requests based on a part of the request body | ||
# Cache responses for POST requests based on the whole request body | ||
cats-graphql: | ||
@@ -252,0 +252,0 @@ handler: graphql/handler.handle |
@@ -111,5 +111,2 @@ 'use strict'; | ||
enabled: { type: 'boolean' }, | ||
apiGatewayIsShared: { type: 'boolean' }, | ||
basePath: { type: 'string' }, | ||
restApiId: { type: 'string' }, | ||
clusterSize: { type: 'string' }, | ||
@@ -116,0 +113,0 @@ ttlInSeconds: { type: 'number' }, |
@@ -25,23 +25,2 @@ const get = require('lodash.get'); | ||
const getApiGatewayResourceNameFor = (path, httpMethod) => { | ||
const pathElements = path.split('/'); | ||
pathElements.push(httpMethod.toLowerCase()); | ||
let gatewayResourceName = pathElements | ||
.map(element => { | ||
element = element.toLowerCase(); | ||
element = element.replaceAll('+', ''); | ||
element = element.replaceAll('_', ''); | ||
element = element.replaceAll('.', ''); | ||
element = element.replaceAll('-', 'Dash'); | ||
if (element.startsWith('{')) { | ||
element = element.substring(element.indexOf('{') + 1, element.indexOf('}')) + "Var"; | ||
} | ||
//capitalize first letter | ||
return element.charAt(0).toUpperCase() + element.slice(1); | ||
}).reduce((a, b) => a + b); | ||
gatewayResourceName = "ApiGatewayMethod" + gatewayResourceName; | ||
return gatewayResourceName; | ||
} | ||
class PerKeyInvalidationSettings { | ||
@@ -82,4 +61,2 @@ constructor(cachingSettings) { | ||
this.gatewayResourceName = getApiGatewayResourceNameFor(this.path, this.method); | ||
let { basePath } = globalSettings; | ||
@@ -86,0 +63,0 @@ if (basePath) { |
@@ -0,1 +1,3 @@ | ||
const split = require('lodash.split'); | ||
const getResourcesByName = (name, serverless) => { | ||
@@ -10,2 +12,23 @@ let resourceKeys = Object.keys(serverless.service.provider.compiledCloudFormationTemplate.Resources); | ||
const getApiGatewayMethodNameFor = (path, httpMethod) => { | ||
const pathElements = split(path, '/'); | ||
pathElements.push(httpMethod.toLowerCase()); | ||
let gatewayResourceName = pathElements | ||
.map(element => { | ||
element = element.toLowerCase(); | ||
element = element.replaceAll('+', ''); | ||
element = element.replaceAll('_', ''); | ||
element = element.replaceAll('.', ''); | ||
element = element.replaceAll('-', 'Dash'); | ||
if (element.startsWith('{')) { | ||
element = element.substring(element.indexOf('{') + 1, element.indexOf('}')) + "Var"; | ||
} | ||
//capitalize first letter | ||
return element.charAt(0).toUpperCase() + element.slice(1); | ||
}).reduce((a, b) => a + b); | ||
gatewayResourceName = "ApiGatewayMethod" + gatewayResourceName; | ||
return gatewayResourceName; | ||
} | ||
const addPathParametersCacheConfig = (settings, serverless) => { | ||
@@ -16,5 +39,6 @@ for (let endpointSettings of settings.endpointSettings) { | ||
} | ||
const method = getResourcesByName(endpointSettings.gatewayResourceName, serverless); | ||
const resourceName = getApiGatewayMethodNameFor(endpointSettings.path, endpointSettings.method); | ||
const method = getResourcesByName(resourceName, serverless); | ||
if (!method) { | ||
serverless.cli.log(`[serverless-api-gateway-caching] The method ${endpointSettings.gatewayResourceName} couldn't be found in the | ||
serverless.cli.log(`[serverless-api-gateway-caching] The method ${resourceName} couldn't be found in the | ||
compiled CloudFormation template. Caching settings will not be updated for this endpoint.`); | ||
@@ -55,3 +79,3 @@ continue; | ||
} | ||
method.Properties.Integration.CacheNamespace = `${endpointSettings.gatewayResourceName}CacheNS`; | ||
method.Properties.Integration.CacheNamespace = `${resourceName}CacheNS`; | ||
} | ||
@@ -61,3 +85,4 @@ } | ||
module.exports = { | ||
addPathParametersCacheConfig: addPathParametersCacheConfig | ||
addPathParametersCacheConfig: addPathParametersCacheConfig, | ||
getApiGatewayMethodNameFor: getApiGatewayMethodNameFor | ||
} |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ const isEmpty = require('lodash.isempty'); |
@@ -0,0 +0,0 @@ module.exports = { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5
1
38416
3
589
+ Addedlodash.split@^4.4.0
+ Addedlodash.split@4.4.2(transitive)