claudia-api-builder
Advanced tools
Comparing version 1.3.1 to 1.4.0
{ | ||
"name": "claudia-api-builder", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Simplify AWS ApiGateway handling", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,3 +0,3 @@ | ||
/*global module */ | ||
module.exports = function ApiBuilder() { | ||
/*global module, require */ | ||
module.exports = function ApiBuilder(components) { | ||
'use strict'; | ||
@@ -10,2 +10,4 @@ var self = this, | ||
customCorsHeaders, | ||
unsupportedEventCallback, | ||
prompter = (components && components.prompter) || require('../ask'), | ||
isApiResponse = function (obj) { | ||
@@ -88,2 +90,5 @@ return obj && (typeof obj === 'object') && (Object.getPrototypeOf(obj) === self.ApiResponse.prototype); | ||
}; | ||
self.unsupportedEvent = function (callback) { | ||
unsupportedEventCallback = callback; | ||
}; | ||
self.router = function (event, context) { | ||
@@ -117,3 +122,7 @@ var handler, result, path; | ||
} else { | ||
context.done('event must contain context.path and context.method'); | ||
if (unsupportedEventCallback) { | ||
unsupportedEventCallback.apply(this, arguments); | ||
} else { | ||
context.done('event must contain context.path and context.method'); | ||
} | ||
} | ||
@@ -133,2 +142,32 @@ }; | ||
}; | ||
self.addPostDeployConfig = function (stageVarName, prompt, configOption) { | ||
self.addPostDeployStep(stageVarName, function (options, lambdaDetails, utils) { | ||
var configureDeployment = function (varValue) { | ||
var result = { | ||
restApiId: lambdaDetails.apiId, | ||
stageName: lambdaDetails.alias, | ||
variables: { } | ||
}; | ||
result.variables[stageVarName] = varValue; | ||
return result; | ||
}, | ||
deployStageVar = function (deployment) { | ||
return utils.apiGatewayPromise.createDeploymentPromise(deployment).then(function () { | ||
return deployment.variables[stageVarName]; | ||
}); | ||
}, | ||
getVariable = function () { | ||
if (typeof options[configOption] === 'string') { | ||
return utils.Promise.resolve(options[configOption]); | ||
} else { | ||
return prompter(prompt, utils.Promise); | ||
} | ||
}; | ||
if (options[configOption]) { | ||
return getVariable() | ||
.then(configureDeployment) | ||
.then(deployStageVar); | ||
} | ||
}); | ||
}; | ||
self.postDeploy = function (options, lambdaDetails, utils) { | ||
@@ -135,0 +174,0 @@ var steps = Object.keys(postDeploySteps), |
10452
7
206