bespoken-tools
Advanced tools
Comparing version 0.9.2 to 0.9.3
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
var logging_helper_1 = require("../lib/core/logging-helper"); | ||
var lambda_config_1 = require("../lib/client/lambda-config"); | ||
var lambda_deploy_1 = require("../lib/client/lambda-deploy"); | ||
var lambda_aws_1 = require("../lib/client/lambda-aws"); | ||
var fs = require("fs"); | ||
var path = require("path"); | ||
var defaultLambdaRoleName = "lambda-bst-execution"; | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
const logging_helper_1 = require("../lib/core/logging-helper"); | ||
const lambda_config_1 = require("../lib/client/lambda-config"); | ||
const lambda_deploy_1 = require("../lib/client/lambda-deploy"); | ||
const lambda_aws_1 = require("../lib/client/lambda-aws"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const defaultLambdaRoleName = "lambda-bst-execution"; | ||
global_1.Global.initializeCLI(); | ||
@@ -23,3 +23,3 @@ program | ||
} | ||
var isDir = fs.lstatSync(lambdaFolder).isDirectory(); | ||
let isDir = fs.lstatSync(lambdaFolder).isDirectory(); | ||
if (!isDir) { | ||
@@ -31,3 +31,3 @@ console.error(lambdaFolder + " is not a folder! You need to specify the project folder!"); | ||
} | ||
var lambdaConfig = lambda_config_1.LambdaConfig.create(); | ||
let lambdaConfig = lambda_config_1.LambdaConfig.create(); | ||
try { | ||
@@ -50,8 +50,8 @@ lambdaConfig.initialize(); | ||
} | ||
var deployer = lambda_deploy_1.LambdaDeploy.create(lambdaFolder, lambdaConfig); | ||
var roleHelper = lambda_aws_1.LambdaAws.create(lambdaConfig); | ||
let deployer = lambda_deploy_1.LambdaDeploy.create(lambdaFolder, lambdaConfig); | ||
let roleHelper = lambda_aws_1.LambdaAws.create(lambdaConfig); | ||
if (lambdaConfig.AWS_ROLE && lambdaConfig.AWS_ROLE !== defaultLambdaRoleName) { | ||
var getRolePromise = roleHelper.getRole(lambdaConfig.AWS_ROLE); | ||
let getRolePromise = roleHelper.getRole(lambdaConfig.AWS_ROLE); | ||
getRolePromise | ||
.then(function (arn) { | ||
.then((arn) => { | ||
if (arn) { | ||
@@ -69,3 +69,3 @@ console.log("Re-using existing lambda role."); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
console.error("Error looking up AWS role: " + err); | ||
@@ -75,9 +75,9 @@ }); | ||
else { | ||
var getRolePromise = roleHelper.getRole(defaultLambdaRoleName); | ||
var reuse_1 = false; | ||
let getRolePromise = roleHelper.getRole(defaultLambdaRoleName); | ||
let reuse = false; | ||
getRolePromise | ||
.then(function (arn) { | ||
.then((arn) => { | ||
if (arn) { | ||
console.log("Re-using existing BST lambda role."); | ||
reuse_1 = true; | ||
reuse = true; | ||
return arn; | ||
@@ -91,3 +91,3 @@ } | ||
}) | ||
.then(function (arn) { | ||
.then((arn) => { | ||
lambdaConfig.AWS_ROLE = defaultLambdaRoleName; | ||
@@ -97,3 +97,3 @@ lambdaConfig.AWS_ROLE_ARN = arn; | ||
global_1.Global.config().save(); | ||
if (reuse_1) { | ||
if (reuse) { | ||
deployer.deploy(); | ||
@@ -103,3 +103,3 @@ } | ||
console.log("Waiting for AWS to propagate the changes"); | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
deployer.deploy(); | ||
@@ -109,3 +109,3 @@ }, 3000); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
console.error("Error creating AWS role: " + err); | ||
@@ -112,0 +112,0 @@ }); |
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
var bst_alexa_1 = require("../lib/client/bst-alexa"); | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
const bst_alexa_1 = require("../lib/client/bst-alexa"); | ||
global_1.Global.initializeCLI(); | ||
@@ -16,6 +16,6 @@ program.version(global_1.Global.version()); | ||
.action(function () { | ||
var intentName = program.args[0]; | ||
var slots = {}; | ||
for (var i = 1; i < program.args.length; i++) { | ||
var slotArg = program.args[i]; | ||
let intentName = program.args[0]; | ||
let slots = {}; | ||
for (let i = 1; i < program.args.length; i++) { | ||
let slotArg = program.args[i]; | ||
if (typeof slotArg !== "string") { | ||
@@ -30,13 +30,13 @@ continue; | ||
} | ||
var slotName = slotArg.split("=")[0]; | ||
var slotValue = slotArg.split("=")[1]; | ||
let slotName = slotArg.split("=")[0]; | ||
let slotValue = slotArg.split("=")[1]; | ||
slots[slotName] = slotValue; | ||
} | ||
var options = program; | ||
var url = options.url; | ||
var intentSchemaPath = options.intents; | ||
var samplesPath = options.samples; | ||
var applicationID = options.appId; | ||
let options = program; | ||
let url = options.url; | ||
let intentSchemaPath = options.intents; | ||
let samplesPath = options.samples; | ||
let applicationID = options.appId; | ||
if (options.url === undefined) { | ||
var proxyProcess = global_1.Global.running(); | ||
let proxyProcess = global_1.Global.running(); | ||
if (proxyProcess === null) { | ||
@@ -53,3 +53,3 @@ console.log("No URL specified and no proxy is currently running"); | ||
} | ||
var speaker = new bst_alexa_1.BSTAlexa(url, intentSchemaPath, samplesPath, applicationID); | ||
let speaker = new bst_alexa_1.BSTAlexa(url, intentSchemaPath, samplesPath, applicationID); | ||
speaker.start(function (error) { | ||
@@ -62,3 +62,3 @@ if (error !== undefined) { | ||
speaker.intended(intentName, slots, function (error, response, request) { | ||
var jsonPretty = JSON.stringify(response, null, 4); | ||
let jsonPretty = JSON.stringify(response, null, 4); | ||
console.log("Intended: " + intentName); | ||
@@ -65,0 +65,0 @@ console.log(""); |
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
var logging_helper_1 = require("../lib/core/logging-helper"); | ||
var bst_proxy_1 = require("../lib/client/bst-proxy"); | ||
var url_mangler_1 = require("../lib/client/url-mangler"); | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
const logging_helper_1 = require("../lib/core/logging-helper"); | ||
const bst_proxy_1 = require("../lib/client/bst-proxy"); | ||
const url_mangler_1 = require("../lib/client/url-mangler"); | ||
global_1.Global.initializeCLI(); | ||
var handleOptions = function (proxy, options) { | ||
let handleOptions = function (proxy, options) { | ||
if (options.bstHost !== undefined) { | ||
@@ -29,3 +29,3 @@ proxy.bespokenServer(options.bstHost, options.bstPort); | ||
console.log(""); | ||
var proxy = bst_proxy_1.BSTProxy.http(port); | ||
let proxy = bst_proxy_1.BSTProxy.http(port); | ||
handleOptions(proxy, options); | ||
@@ -44,3 +44,3 @@ proxy.start(); | ||
console.log(""); | ||
var proxy = bst_proxy_1.BSTProxy.lambda(lambdaFile); | ||
let proxy = bst_proxy_1.BSTProxy.lambda(lambdaFile); | ||
handleOptions(proxy, options); | ||
@@ -72,3 +72,3 @@ proxy.start(); | ||
.action(function (url) { | ||
var bstURL = bst_proxy_1.BSTProxy.urlgen(url); | ||
let bstURL = bst_proxy_1.BSTProxy.urlgen(url); | ||
console.log("Enter this URL on the Configuration tab of your skill:"); | ||
@@ -75,0 +75,0 @@ console.log(); |
"use strict"; | ||
var bespoke_server_1 = require("../lib/server/bespoke-server"); | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
const bespoke_server_1 = require("../lib/server/bespoke-server"); | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
program.version(global_1.Global.version()); | ||
@@ -10,5 +10,5 @@ program | ||
.action(function (nodeID, port, options) { | ||
var webhookPort = parseInt(process.argv[3]); | ||
var serverPort = parseInt(process.argv[4]); | ||
var bespokeServer = new bespoke_server_1.BespokeServer(webhookPort, serverPort); | ||
let webhookPort = parseInt(process.argv[3]); | ||
let serverPort = parseInt(process.argv[4]); | ||
let bespokeServer = new bespoke_server_1.BespokeServer(webhookPort, serverPort); | ||
bespokeServer.start(); | ||
@@ -15,0 +15,0 @@ }); |
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
global_1.Global.initializeCLI(); | ||
@@ -6,0 +6,0 @@ program.version(global_1.Global.version()); |
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
var bst_alexa_1 = require("../lib/client/bst-alexa"); | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
const bst_alexa_1 = require("../lib/client/bst-alexa"); | ||
global_1.Global.initializeCLI(); | ||
@@ -16,5 +16,5 @@ program.version(global_1.Global.version()); | ||
.action(function () { | ||
var utterance = ""; | ||
for (var i = 0; i < program.args.length; i++) { | ||
var arg = program.args[i]; | ||
let utterance = ""; | ||
for (let i = 0; i < program.args.length; i++) { | ||
let arg = program.args[i]; | ||
if (typeof arg !== "string") { | ||
@@ -28,9 +28,9 @@ break; | ||
} | ||
var options = program; | ||
var url = options.url; | ||
var intentSchemaPath = options.intents; | ||
var samplesPath = options.samples; | ||
var applicationID = options.appId; | ||
let options = program; | ||
let url = options.url; | ||
let intentSchemaPath = options.intents; | ||
let samplesPath = options.samples; | ||
let applicationID = options.appId; | ||
if (options.url === undefined) { | ||
var proxyProcess = global_1.Global.running(); | ||
let proxyProcess = global_1.Global.running(); | ||
if (proxyProcess === null) { | ||
@@ -48,3 +48,3 @@ console.error("No URL specified and no proxy is currently running"); | ||
} | ||
var speaker = new bst_alexa_1.BSTAlexa(url, intentSchemaPath, samplesPath, applicationID); | ||
let speaker = new bst_alexa_1.BSTAlexa(url, intentSchemaPath, samplesPath, applicationID); | ||
speaker.start(function (error) { | ||
@@ -56,3 +56,3 @@ if (error !== undefined) { | ||
speaker.spoken(utterance, function (error, response, request) { | ||
var jsonPretty = JSON.stringify(response, null, 4); | ||
let jsonPretty = JSON.stringify(response, null, 4); | ||
console.log("Spoke: " + utterance); | ||
@@ -59,0 +59,0 @@ console.log(""); |
#!/usr/bin/env node | ||
"use strict"; | ||
var program = require("commander"); | ||
var global_1 = require("../lib/core/global"); | ||
var logging_helper_1 = require("../lib/core/logging-helper"); | ||
var Logger = "BST"; | ||
const program = require("commander"); | ||
const global_1 = require("../lib/core/global"); | ||
const logging_helper_1 = require("../lib/core/logging-helper"); | ||
let Logger = "BST"; | ||
global_1.Global.initializeCLI(); | ||
console.log("BST: v" + global_1.Global.version() + " Node: " + process.version); | ||
console.log(""); | ||
var nodeMajorVersion = parseInt(process.version.substr(1, 2)); | ||
let nodeMajorVersion = parseInt(process.version.substr(1, 2)); | ||
if (nodeMajorVersion < 4) { | ||
@@ -12,0 +12,0 @@ logging_helper_1.LoggingHelper.error(Logger, "!!!!Node version must be >= 4!!!!"); |
"use strict"; | ||
var alexa_session_1 = require("./alexa-session"); | ||
var uuid = require("node-uuid"); | ||
var AlexaContext = (function () { | ||
function AlexaContext(_skillURL, _interactionModel, _audioPlayer, _applicationID) { | ||
const alexa_session_1 = require("./alexa-session"); | ||
const uuid = require("node-uuid"); | ||
class AlexaContext { | ||
constructor(_skillURL, _interactionModel, _audioPlayer, _applicationID) { | ||
this._skillURL = _skillURL; | ||
@@ -11,3 +11,3 @@ this._interactionModel = _interactionModel; | ||
} | ||
AlexaContext.prototype.applicationID = function () { | ||
applicationID() { | ||
if (this._applicationID === undefined || this._applicationID === null) { | ||
@@ -17,10 +17,10 @@ this._applicationID = "amzn1.echo-sdk-ams.app." + uuid.v4(); | ||
return this._applicationID; | ||
}; | ||
AlexaContext.prototype.skillURL = function () { | ||
} | ||
skillURL() { | ||
return this._skillURL; | ||
}; | ||
AlexaContext.prototype.interactionModel = function () { | ||
} | ||
interactionModel() { | ||
return this._interactionModel; | ||
}; | ||
AlexaContext.prototype.userID = function () { | ||
} | ||
userID() { | ||
if (this._userID === undefined || this._userID === null) { | ||
@@ -30,24 +30,23 @@ this._userID = "amzn1.ask.account." + uuid.v4(); | ||
return this._userID; | ||
}; | ||
AlexaContext.prototype.audioPlayer = function () { | ||
} | ||
audioPlayer() { | ||
return this._audioPlayer; | ||
}; | ||
AlexaContext.prototype.audioPlayerEnabled = function () { | ||
} | ||
audioPlayerEnabled() { | ||
return this._audioPlayer !== null; | ||
}; | ||
AlexaContext.prototype.newSession = function () { | ||
} | ||
newSession() { | ||
this._session = new alexa_session_1.AlexaSession(); | ||
}; | ||
AlexaContext.prototype.session = function () { | ||
} | ||
session() { | ||
return this._session; | ||
}; | ||
AlexaContext.prototype.endSession = function () { | ||
} | ||
endSession() { | ||
this._session = null; | ||
}; | ||
AlexaContext.prototype.activeSession = function () { | ||
} | ||
activeSession() { | ||
return this._session !== null; | ||
}; | ||
return AlexaContext; | ||
}()); | ||
} | ||
} | ||
exports.AlexaContext = AlexaContext; | ||
//# sourceMappingURL=alexa-context.js.map |
"use strict"; | ||
var uuid = require("node-uuid"); | ||
var AlexaSession = (function () { | ||
function AlexaSession() { | ||
const uuid = require("node-uuid"); | ||
class AlexaSession { | ||
constructor() { | ||
this._id = "SessionID." + uuid.v4(); | ||
@@ -9,22 +9,21 @@ this._new = true; | ||
} | ||
AlexaSession.prototype.attributes = function () { | ||
attributes() { | ||
return this._attributes; | ||
}; | ||
AlexaSession.prototype.updateAttributes = function (sessionAttributes) { | ||
} | ||
updateAttributes(sessionAttributes) { | ||
if (sessionAttributes !== undefined && sessionAttributes !== null) { | ||
this._attributes = sessionAttributes; | ||
} | ||
}; | ||
AlexaSession.prototype.id = function () { | ||
} | ||
id() { | ||
return this._id; | ||
}; | ||
AlexaSession.prototype.isNew = function () { | ||
} | ||
isNew() { | ||
return this._new; | ||
}; | ||
AlexaSession.prototype.used = function () { | ||
} | ||
used() { | ||
this._new = false; | ||
}; | ||
return AlexaSession; | ||
}()); | ||
} | ||
} | ||
exports.AlexaSession = AlexaSession; | ||
//# sourceMappingURL=alexa-session.js.map |
"use strict"; | ||
var audio_player_1 = require("./audio-player"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var service_request_1 = require("./service-request"); | ||
var request = require("request"); | ||
var alexa_context_1 = require("./alexa-context"); | ||
var events_1 = require("events"); | ||
var Logger = "ALEXA"; | ||
const audio_player_1 = require("./audio-player"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const service_request_1 = require("./service-request"); | ||
const request = require("request"); | ||
const alexa_context_1 = require("./alexa-context"); | ||
const events_1 = require("events"); | ||
const Logger = "ALEXA"; | ||
(function (AlexaEvent) { | ||
@@ -15,4 +15,4 @@ AlexaEvent[AlexaEvent["SessionEnded"] = 0] = "SessionEnded"; | ||
var AlexaEvent = exports.AlexaEvent; | ||
var Alexa = (function () { | ||
function Alexa() { | ||
class Alexa { | ||
constructor() { | ||
this._actionQueue = new ActionQueue(); | ||
@@ -24,4 +24,4 @@ this._context = null; | ||
} | ||
Alexa.prototype.startSession = function (skillURL, model, audioEnabled, applicationID) { | ||
var audioPlayer = null; | ||
startSession(skillURL, model, audioEnabled, applicationID) { | ||
let audioPlayer = null; | ||
if (audioEnabled) { | ||
@@ -33,13 +33,13 @@ audioPlayer = new audio_player_1.AudioPlayer(this); | ||
return this; | ||
}; | ||
Alexa.prototype.context = function () { | ||
} | ||
context() { | ||
return this._context; | ||
}; | ||
Alexa.prototype.interactionModel = function () { | ||
} | ||
interactionModel() { | ||
return this.context().interactionModel(); | ||
}; | ||
Alexa.prototype.spoken = function (utterance, callback) { | ||
var intent = this.interactionModel().sampleUtterances.intentForUtterance(utterance); | ||
} | ||
spoken(utterance, callback) { | ||
let intent = this.interactionModel().sampleUtterances.intentForUtterance(utterance); | ||
if (intent === null) { | ||
var defaultUtterance = this.interactionModel().sampleUtterances.defaultUtterance(); | ||
let defaultUtterance = this.interactionModel().sampleUtterances.defaultUtterance(); | ||
intent = this.interactionModel().sampleUtterances.intentForUtterance(defaultUtterance); | ||
@@ -49,22 +49,22 @@ logging_helper_1.LoggingHelper.warn(Logger, "No intentName matches utterance: " + utterance + ". Using fallback utterance: " + intent.utterance); | ||
this.callSkillWithIntent(intent.intentName, intent.toJSON(), callback); | ||
}; | ||
Alexa.prototype.launched = function (callback) { | ||
var serviceRequest = new service_request_1.ServiceRequest(this._context); | ||
} | ||
launched(callback) { | ||
let serviceRequest = new service_request_1.ServiceRequest(this._context); | ||
serviceRequest.launchRequest(); | ||
this.callSkill(serviceRequest, callback); | ||
}; | ||
Alexa.prototype.sessionEnded = function (sessionEndedReason, errorData, callback) { | ||
} | ||
sessionEnded(sessionEndedReason, errorData, callback) { | ||
if (sessionEndedReason === service_request_1.SessionEndedReason.ERROR) { | ||
logging_helper_1.LoggingHelper.error(Logger, "SessionEndedRequest:\n" + JSON.stringify(errorData, null, 2)); | ||
} | ||
var serviceRequest = new service_request_1.ServiceRequest(this._context); | ||
let serviceRequest = new service_request_1.ServiceRequest(this._context); | ||
serviceRequest.sessionEndedRequest(sessionEndedReason, errorData); | ||
this.callSkill(serviceRequest, callback); | ||
this.context().endSession(); | ||
}; | ||
Alexa.prototype.intended = function (intentName, slots, callback) { | ||
} | ||
intended(intentName, slots, callback) { | ||
this.callSkillWithIntent(intentName, slots, callback); | ||
}; | ||
Alexa.prototype.callSkillWithIntent = function (intentName, slots, callback) { | ||
var self = this; | ||
} | ||
callSkillWithIntent(intentName, slots, callback) { | ||
let self = this; | ||
try { | ||
@@ -75,6 +75,5 @@ if (this._context.audioPlayerEnabled() && this._context.audioPlayer().isPlaying()) { | ||
console.log("Intent: " + intentName + " Session: " + this._session); | ||
var serviceRequest = new service_request_1.ServiceRequest(this._context).intentRequest(intentName); | ||
let serviceRequest = new service_request_1.ServiceRequest(this._context).intentRequest(intentName); | ||
if (slots !== undefined && slots !== null) { | ||
for (var _i = 0, _a = Object.keys(slots); _i < _a.length; _i++) { | ||
var slotName = _a[_i]; | ||
for (let slotName of Object.keys(slots)) { | ||
serviceRequest.withSlot(slotName, slots[slotName]); | ||
@@ -97,20 +96,20 @@ } | ||
} | ||
}; | ||
Alexa.prototype.callSkill = function (serviceRequest, callback) { | ||
var self = this; | ||
} | ||
callSkill(serviceRequest, callback) { | ||
let self = this; | ||
this.sequence(function (done) { | ||
self.callSkillImpl(serviceRequest, callback, done); | ||
}); | ||
}; | ||
Alexa.prototype.sequence = function (action) { | ||
} | ||
sequence(action) { | ||
this._actionQueue.enqueue(action); | ||
}; | ||
Alexa.prototype.callSkillImpl = function (serviceRequest, callback, done) { | ||
var self = this; | ||
} | ||
callSkillImpl(serviceRequest, callback, done) { | ||
let self = this; | ||
if (serviceRequest.requiresSession() && !this.context().activeSession()) { | ||
this.context().newSession(); | ||
} | ||
var requestJSON = serviceRequest.toJSON(); | ||
let requestJSON = serviceRequest.toJSON(); | ||
logging_helper_1.LoggingHelper.info(Logger, "CALLING: " + requestJSON.request.type); | ||
var responseHandler = function (error, response, body) { | ||
let responseHandler = function (error, response, body) { | ||
if (self.context().activeSession()) { | ||
@@ -148,26 +147,25 @@ self.context().session().used(); | ||
}, responseHandler); | ||
}; | ||
Alexa.prototype.post = function (options, responseHandler) { | ||
} | ||
post(options, responseHandler) { | ||
request.post(options, responseHandler); | ||
}; | ||
Alexa.prototype.on = function (event, callback) { | ||
} | ||
on(event, callback) { | ||
this._emitter.on(AlexaEvent[event], callback); | ||
}; | ||
Alexa.prototype.once = function (event, callback) { | ||
} | ||
once(event, callback) { | ||
this._emitter.once(AlexaEvent[event], callback); | ||
}; | ||
Alexa.prototype.stop = function (onStop) { | ||
} | ||
stop(onStop) { | ||
this._actionQueue.stop(function () { | ||
onStop(); | ||
}); | ||
}; | ||
return Alexa; | ||
}()); | ||
} | ||
} | ||
exports.Alexa = Alexa; | ||
var ActionQueue = (function () { | ||
function ActionQueue() { | ||
class ActionQueue { | ||
constructor() { | ||
this._queue = []; | ||
this._stop = false; | ||
} | ||
ActionQueue.prototype.enqueue = function (action) { | ||
enqueue(action) { | ||
this._queue.push(action); | ||
@@ -177,12 +175,12 @@ if (this._queue.length === 1) { | ||
} | ||
}; | ||
ActionQueue.prototype.processing = function () { | ||
} | ||
processing() { | ||
return (this._queue.length > 0); | ||
}; | ||
ActionQueue.prototype.next = function () { | ||
var self = this; | ||
} | ||
next() { | ||
let self = this; | ||
if (this._queue.length === 0) { | ||
return; | ||
} | ||
var action = this._queue[0]; | ||
let action = this._queue[0]; | ||
action(function () { | ||
@@ -197,4 +195,4 @@ self._queue = self._queue.slice(1); | ||
}); | ||
}; | ||
ActionQueue.prototype.stop = function (onStop) { | ||
} | ||
stop(onStop) { | ||
this._stop = true; | ||
@@ -207,6 +205,5 @@ if (this.processing()) { | ||
} | ||
}; | ||
return ActionQueue; | ||
}()); | ||
} | ||
} | ||
exports.ActionQueue = ActionQueue; | ||
//# sourceMappingURL=alexa.js.map |
"use strict"; | ||
var AudioItem = (function () { | ||
function AudioItem(_json) { | ||
class AudioItem { | ||
constructor(_json) { | ||
this._json = _json; | ||
@@ -11,10 +11,9 @@ this.stream = new AudioItemStream(); | ||
} | ||
AudioItem.prototype.clone = function () { | ||
clone() { | ||
return new AudioItem(this); | ||
}; | ||
return AudioItem; | ||
}()); | ||
} | ||
} | ||
exports.AudioItem = AudioItem; | ||
var AudioItemStream = (function () { | ||
function AudioItemStream() { | ||
class AudioItemStream { | ||
constructor() { | ||
this.url = null; | ||
@@ -24,5 +23,4 @@ this.token = null; | ||
} | ||
return AudioItemStream; | ||
}()); | ||
} | ||
exports.AudioItemStream = AudioItemStream; | ||
//# sourceMappingURL=audio-item.js.map |
"use strict"; | ||
var service_request_1 = require("./service-request"); | ||
var events_1 = require("events"); | ||
var audio_item_1 = require("./audio-item"); | ||
const service_request_1 = require("./service-request"); | ||
const events_1 = require("events"); | ||
const audio_item_1 = require("./audio-item"); | ||
(function (AudioPlayerActivity) { | ||
@@ -14,4 +14,4 @@ AudioPlayerActivity[AudioPlayerActivity["BUFFER_UNDERRUN"] = 0] = "BUFFER_UNDERRUN"; | ||
var AudioPlayerActivity = exports.AudioPlayerActivity; | ||
var AudioPlayer = (function () { | ||
function AudioPlayer(alexa) { | ||
class AudioPlayer { | ||
constructor(alexa) { | ||
this.alexa = alexa; | ||
@@ -26,3 +26,3 @@ this._emitter = null; | ||
} | ||
AudioPlayer.prototype.enqueue = function (audioItem, playBehavior) { | ||
enqueue(audioItem, playBehavior) { | ||
if (playBehavior === AudioPlayer.PlayBehaviorEnqueue) { | ||
@@ -45,7 +45,7 @@ this._queue.push(audioItem); | ||
} | ||
}; | ||
AudioPlayer.prototype.activity = function () { | ||
} | ||
activity() { | ||
return this._activity; | ||
}; | ||
AudioPlayer.prototype.playNext = function () { | ||
} | ||
playNext() { | ||
if (this._queue.length === 0) { | ||
@@ -64,45 +64,45 @@ return; | ||
} | ||
}; | ||
AudioPlayer.prototype.suspend = function () { | ||
} | ||
suspend() { | ||
this._suspended = true; | ||
this.playbackStopped(); | ||
}; | ||
AudioPlayer.prototype.suspended = function () { | ||
} | ||
suspended() { | ||
return this._suspended; | ||
}; | ||
AudioPlayer.prototype.playbackOffset = function (offset) { | ||
} | ||
playbackOffset(offset) { | ||
if (this.isPlaying()) { | ||
this.playing().stream.offsetInMilliseconds = offset; | ||
} | ||
}; | ||
AudioPlayer.prototype.on = function (audioPlayerRequest, listener) { | ||
} | ||
on(audioPlayerRequest, listener) { | ||
this._emitter.on(audioPlayerRequest, listener); | ||
}; | ||
AudioPlayer.prototype.once = function (audioPlayerRequest, listener) { | ||
} | ||
once(audioPlayerRequest, listener) { | ||
this._emitter.once(audioPlayerRequest, listener); | ||
}; | ||
AudioPlayer.prototype.resume = function () { | ||
} | ||
resume() { | ||
this._suspended = false; | ||
this.playbackStarted(); | ||
}; | ||
AudioPlayer.prototype.playbackNearlyFinished = function (callback) { | ||
} | ||
playbackNearlyFinished(callback) { | ||
this.audioPlayerRequest(service_request_1.RequestType.AudioPlayerPlaybackNearlyFinished, callback); | ||
}; | ||
AudioPlayer.prototype.playbackFinished = function (callback) { | ||
} | ||
playbackFinished(callback) { | ||
this._activity = AudioPlayerActivity.FINISHED; | ||
this.audioPlayerRequest(service_request_1.RequestType.AudioPlayerPlaybackFinished, callback); | ||
this.playNext(); | ||
}; | ||
AudioPlayer.prototype.playbackStarted = function (callback) { | ||
} | ||
playbackStarted(callback) { | ||
this._activity = AudioPlayerActivity.PLAYING; | ||
this.audioPlayerRequest(service_request_1.RequestType.AudioPlayerPlaybackStarted, callback); | ||
}; | ||
AudioPlayer.prototype.playbackStopped = function (callback) { | ||
} | ||
playbackStopped(callback) { | ||
this._activity = AudioPlayerActivity.STOPPED; | ||
this.audioPlayerRequest(service_request_1.RequestType.AudioPlayerPlaybackStopped, callback); | ||
}; | ||
AudioPlayer.prototype.audioPlayerRequest = function (requestType, callback) { | ||
var self = this; | ||
var nowPlaying = this.playing(); | ||
var serviceRequest = new service_request_1.ServiceRequest(this.alexa.context()); | ||
} | ||
audioPlayerRequest(requestType, callback) { | ||
const self = this; | ||
const nowPlaying = this.playing(); | ||
const serviceRequest = new service_request_1.ServiceRequest(this.alexa.context()); | ||
serviceRequest.audioPlayerRequest(requestType, nowPlaying.stream.token, nowPlaying.stream.offsetInMilliseconds); | ||
@@ -115,13 +115,12 @@ this.alexa.callSkill(serviceRequest, function (error, response, request) { | ||
}); | ||
}; | ||
AudioPlayer.prototype.directivesReceived = function (directives) { | ||
for (var _i = 0, directives_1 = directives; _i < directives_1.length; _i++) { | ||
var directive = directives_1[_i]; | ||
} | ||
directivesReceived(directives) { | ||
for (let directive of directives) { | ||
this.handleDirective(directive); | ||
} | ||
}; | ||
AudioPlayer.prototype.handleDirective = function (directive) { | ||
} | ||
handleDirective(directive) { | ||
if (directive.type === AudioPlayer.DirectivePlay) { | ||
var audioItem = new audio_item_1.AudioItem(directive.audioItem); | ||
var playBehavior = directive.playBehavior; | ||
let audioItem = new audio_item_1.AudioItem(directive.audioItem); | ||
let playBehavior = directive.playBehavior; | ||
this.enqueue(audioItem, playBehavior); | ||
@@ -137,23 +136,22 @@ } | ||
} | ||
}; | ||
AudioPlayer.prototype.isPlaying = function () { | ||
} | ||
isPlaying() { | ||
return (this._activity === AudioPlayerActivity.PLAYING); | ||
}; | ||
AudioPlayer.prototype.dequeue = function () { | ||
var audioItem = this._queue[0]; | ||
} | ||
dequeue() { | ||
const audioItem = this._queue[0]; | ||
this._queue = this._queue.slice(1); | ||
return audioItem; | ||
}; | ||
AudioPlayer.prototype.playing = function () { | ||
} | ||
playing() { | ||
return this._playing; | ||
}; | ||
AudioPlayer.DirectivePlay = "AudioPlayer.Play"; | ||
AudioPlayer.DirectiveStop = "AudioPlayer.Stop"; | ||
AudioPlayer.DirectiveClearQueue = "AudioPlayer.ClearQueue"; | ||
AudioPlayer.PlayBehaviorReplaceAll = "REPLACE_ALL"; | ||
AudioPlayer.PlayBehaviorEnqueue = "ENQUEUE"; | ||
AudioPlayer.PlayBehaviorReplaceEnqueued = "REPLACE_ENQUEUED"; | ||
return AudioPlayer; | ||
}()); | ||
} | ||
} | ||
AudioPlayer.DirectivePlay = "AudioPlayer.Play"; | ||
AudioPlayer.DirectiveStop = "AudioPlayer.Stop"; | ||
AudioPlayer.DirectiveClearQueue = "AudioPlayer.ClearQueue"; | ||
AudioPlayer.PlayBehaviorReplaceAll = "REPLACE_ALL"; | ||
AudioPlayer.PlayBehaviorEnqueue = "ENQUEUE"; | ||
AudioPlayer.PlayBehaviorReplaceEnqueued = "REPLACE_ENQUEUED"; | ||
exports.AudioPlayer = AudioPlayer; | ||
//# sourceMappingURL=audio-player.js.map |
"use strict"; | ||
var file_util_1 = require("../core/file-util"); | ||
var IntentSchema = (function () { | ||
function IntentSchema(schemaJSON) { | ||
const file_util_1 = require("../core/file-util"); | ||
class IntentSchema { | ||
constructor(schemaJSON) { | ||
this.schemaJSON = schemaJSON; | ||
} | ||
IntentSchema.fromFile = function (file, callback) { | ||
static fromFile(file, callback) { | ||
file_util_1.FileUtil.readFile(file, function (data) { | ||
if (data !== null) { | ||
var json = null; | ||
let json = null; | ||
try { | ||
json = JSON.parse(data.toString()); | ||
var schema = new IntentSchema(json); | ||
let schema = new IntentSchema(json); | ||
callback(schema); | ||
@@ -21,18 +21,16 @@ } | ||
else { | ||
var error_1 = "File not found: " + file; | ||
callback(null, error_1); | ||
let error = "File not found: " + file; | ||
callback(null, error); | ||
} | ||
}); | ||
}; | ||
IntentSchema.fromJSON = function (schemaJSON) { | ||
} | ||
static fromJSON(schemaJSON) { | ||
return new IntentSchema(schemaJSON); | ||
}; | ||
IntentSchema.prototype.intents = function () { | ||
var intentArray = []; | ||
for (var _i = 0, _a = this.schemaJSON.intents; _i < _a.length; _i++) { | ||
var intentJSON = _a[_i]; | ||
var intent = new Intent(intentJSON.intent); | ||
} | ||
intents() { | ||
let intentArray = []; | ||
for (let intentJSON of this.schemaJSON.intents) { | ||
let intent = new Intent(intentJSON.intent); | ||
if (intentJSON.slots !== undefined && intentJSON.slots !== null) { | ||
for (var _b = 0, _c = intentJSON.slots; _b < _c.length; _b++) { | ||
var slotJSON = _c[_b]; | ||
for (let slotJSON of intentJSON.slots) { | ||
intent.addSlot(new IntentSlot(slotJSON.name, slotJSON.type)); | ||
@@ -44,7 +42,6 @@ } | ||
return intentArray; | ||
}; | ||
IntentSchema.prototype.intent = function (intentString) { | ||
var intent = null; | ||
for (var _i = 0, _a = this.intents(); _i < _a.length; _i++) { | ||
var o = _a[_i]; | ||
} | ||
intent(intentString) { | ||
let intent = null; | ||
for (let o of this.intents()) { | ||
if (o.name === intentString) { | ||
@@ -56,11 +53,10 @@ intent = o; | ||
return intent; | ||
}; | ||
IntentSchema.prototype.hasIntent = function (intentString) { | ||
} | ||
hasIntent(intentString) { | ||
return this.intent(intentString) !== null; | ||
}; | ||
return IntentSchema; | ||
}()); | ||
} | ||
} | ||
exports.IntentSchema = IntentSchema; | ||
var Intent = (function () { | ||
function Intent(name) { | ||
class Intent { | ||
constructor(name) { | ||
this.name = name; | ||
@@ -73,3 +69,3 @@ this.builtin = false; | ||
} | ||
Intent.prototype.addSlot = function (slot) { | ||
addSlot(slot) { | ||
if (this.slots === null) { | ||
@@ -79,14 +75,12 @@ this.slots = []; | ||
this.slots.push(slot); | ||
}; | ||
return Intent; | ||
}()); | ||
} | ||
} | ||
exports.Intent = Intent; | ||
var IntentSlot = (function () { | ||
function IntentSlot(name, type) { | ||
class IntentSlot { | ||
constructor(name, type) { | ||
this.name = name; | ||
this.type = type; | ||
} | ||
return IntentSlot; | ||
}()); | ||
} | ||
exports.IntentSlot = IntentSlot; | ||
//# sourceMappingURL=intent-schema.js.map |
"use strict"; | ||
var intent_schema_1 = require("./intent-schema"); | ||
var sample_utterances_1 = require("./sample-utterances"); | ||
var InteractionModel = (function () { | ||
function InteractionModel(intentSchema, sampleUtterances) { | ||
const intent_schema_1 = require("./intent-schema"); | ||
const sample_utterances_1 = require("./sample-utterances"); | ||
class InteractionModel { | ||
constructor(intentSchema, sampleUtterances) { | ||
this.intentSchema = intentSchema; | ||
this.sampleUtterances = sampleUtterances; | ||
} | ||
InteractionModel.fromFiles = function (intentSchemaFile, sampleUtterancesFile, callback) { | ||
var callbackCount = 0; | ||
var callbackError = null; | ||
var intentSchema = null; | ||
var sampleUtterances = null; | ||
var done = function (schema, utterances, error) { | ||
static fromFiles(intentSchemaFile, sampleUtterancesFile, callback) { | ||
let callbackCount = 0; | ||
let callbackError = null; | ||
let intentSchema = null; | ||
let sampleUtterances = null; | ||
let done = function (schema, utterances, error) { | ||
callbackCount++; | ||
@@ -50,12 +50,11 @@ if (schema !== undefined && schema !== null) { | ||
}); | ||
}; | ||
InteractionModel.prototype.intentForUtterance = function (utterance) { | ||
} | ||
intentForUtterance(utterance) { | ||
return this.sampleUtterances.intentForUtterance(utterance); | ||
}; | ||
InteractionModel.prototype.hasIntent = function (intent) { | ||
} | ||
hasIntent(intent) { | ||
return this.intentSchema.hasIntent(intent); | ||
}; | ||
return InteractionModel; | ||
}()); | ||
} | ||
} | ||
exports.InteractionModel = InteractionModel; | ||
//# sourceMappingURL=interaction-model.js.map |
"use strict"; | ||
var file_util_1 = require("../core/file-util"); | ||
var SampleUtterances = (function () { | ||
function SampleUtterances() { | ||
const file_util_1 = require("../core/file-util"); | ||
class SampleUtterances { | ||
constructor() { | ||
this.samples = {}; | ||
} | ||
SampleUtterances.fromFile = function (file, callback) { | ||
static fromFile(file, callback) { | ||
file_util_1.FileUtil.readFile(file, function (data) { | ||
if (data !== null) { | ||
var sampleUtterances = new SampleUtterances(); | ||
let sampleUtterances = new SampleUtterances(); | ||
try { | ||
@@ -20,27 +20,24 @@ sampleUtterances.parseFlatFile(data.toString()); | ||
else { | ||
var error_1 = "File not found: " + file; | ||
callback(null, error_1); | ||
let error = "File not found: " + file; | ||
callback(null, error); | ||
} | ||
}); | ||
}; | ||
SampleUtterances.fromJSON = function (sampleUtterancesJSON) { | ||
var sampleUtterances = new SampleUtterances(); | ||
for (var _i = 0, _a = Object.keys(sampleUtterancesJSON); _i < _a.length; _i++) { | ||
var intent = _a[_i]; | ||
} | ||
static fromJSON(sampleUtterancesJSON) { | ||
let sampleUtterances = new SampleUtterances(); | ||
for (let intent of Object.keys(sampleUtterancesJSON)) { | ||
sampleUtterances.samples[intent] = sampleUtterancesJSON[intent]; | ||
} | ||
return sampleUtterances; | ||
}; | ||
SampleUtterances.prototype.defaultUtterance = function () { | ||
var firstIntent = Object.keys(this.samples)[0]; | ||
} | ||
defaultUtterance() { | ||
let firstIntent = Object.keys(this.samples)[0]; | ||
return this.samples[firstIntent][0]; | ||
}; | ||
SampleUtterances.prototype.intentForUtterance = function (phraseString) { | ||
var phrase = new Phrase(phraseString); | ||
var matchedIntent = null; | ||
for (var _i = 0, _a = Object.keys(this.samples); _i < _a.length; _i++) { | ||
var intent = _a[_i]; | ||
var samples = this.samples[intent]; | ||
for (var _b = 0, samples_1 = samples; _b < samples_1.length; _b++) { | ||
var sample = samples_1[_b]; | ||
} | ||
intentForUtterance(phraseString) { | ||
let phrase = new Phrase(phraseString); | ||
let matchedIntent = null; | ||
for (let intent of Object.keys(this.samples)) { | ||
let samples = this.samples[intent]; | ||
for (let sample of samples) { | ||
if (phrase.matchesUtterance(sample)) { | ||
@@ -56,20 +53,19 @@ matchedIntent = new UtteredIntent(intent, phraseString, new Phrase(sample)); | ||
return matchedIntent; | ||
}; | ||
SampleUtterances.prototype.hasIntent = function (intent) { | ||
} | ||
hasIntent(intent) { | ||
return intent in this.samples; | ||
}; | ||
SampleUtterances.prototype.parseFlatFile = function (fileData) { | ||
var lines = fileData.split("\n"); | ||
for (var _i = 0, lines_1 = lines; _i < lines_1.length; _i++) { | ||
var line = lines_1[_i]; | ||
} | ||
parseFlatFile(fileData) { | ||
let lines = fileData.split("\n"); | ||
for (let line of lines) { | ||
if (line.trim().length === 0) { | ||
continue; | ||
} | ||
var index = line.indexOf(" "); | ||
let index = line.indexOf(" "); | ||
if (index === -1) { | ||
throw Error("Invalid sample utterance: " + line); | ||
} | ||
var intent = line.substr(0, index); | ||
var sample = line.substr(index).trim(); | ||
var intentSamples = []; | ||
let intent = line.substr(0, index); | ||
let sample = line.substr(index).trim(); | ||
let intentSamples = []; | ||
if (intent in this.samples) { | ||
@@ -83,8 +79,7 @@ intentSamples = this.samples[intent]; | ||
} | ||
}; | ||
return SampleUtterances; | ||
}()); | ||
} | ||
} | ||
exports.SampleUtterances = SampleUtterances; | ||
var Phrase = (function () { | ||
function Phrase(phrase) { | ||
class Phrase { | ||
constructor(phrase) { | ||
this.phrase = phrase; | ||
@@ -95,11 +90,11 @@ this.slots = []; | ||
} | ||
Phrase.prototype.normalizeSlots = function (utterance) { | ||
var slotlessUtterance = ""; | ||
var index = 0; | ||
var done = false; | ||
normalizeSlots(utterance) { | ||
let slotlessUtterance = ""; | ||
let index = 0; | ||
let done = false; | ||
while (!done) { | ||
var startSlotIndex = utterance.indexOf("{", index); | ||
let startSlotIndex = utterance.indexOf("{", index); | ||
if (startSlotIndex !== -1) { | ||
var endSlotIndex = utterance.indexOf("}", startSlotIndex); | ||
var slotValue = utterance.substr(startSlotIndex + 1, endSlotIndex - (startSlotIndex + 1)); | ||
let endSlotIndex = utterance.indexOf("}", startSlotIndex); | ||
let slotValue = utterance.substr(startSlotIndex + 1, endSlotIndex - (startSlotIndex + 1)); | ||
this.slots.push(slotValue); | ||
@@ -115,14 +110,13 @@ slotlessUtterance += utterance.substr(index, startSlotIndex - index + 1) + "}"; | ||
this.normalizedPhrase = slotlessUtterance; | ||
}; | ||
Phrase.prototype.matchesUtterance = function (otherPhraseString) { | ||
} | ||
matchesUtterance(otherPhraseString) { | ||
return this.matches(new Phrase(otherPhraseString)); | ||
}; | ||
Phrase.prototype.matches = function (otherPhrase) { | ||
} | ||
matches(otherPhrase) { | ||
return this.normalizedPhrase.toLowerCase() === otherPhrase.normalizedPhrase.toLowerCase(); | ||
}; | ||
return Phrase; | ||
}()); | ||
} | ||
} | ||
exports.Phrase = Phrase; | ||
var UtteredIntent = (function () { | ||
function UtteredIntent(intentName, utterance, matchedPhrase) { | ||
class UtteredIntent { | ||
constructor(intentName, utterance, matchedPhrase) { | ||
this.intentName = intentName; | ||
@@ -132,21 +126,20 @@ this.utterance = utterance; | ||
} | ||
UtteredIntent.prototype.slotCount = function () { | ||
slotCount() { | ||
return this.matchedPhrase.slots.length; | ||
}; | ||
UtteredIntent.prototype.slotName = function (index) { | ||
} | ||
slotName(index) { | ||
return this.matchedPhrase.slots[index]; | ||
}; | ||
UtteredIntent.prototype.slotValue = function (index) { | ||
} | ||
slotValue(index) { | ||
return new Phrase(this.utterance).slots[index]; | ||
}; | ||
UtteredIntent.prototype.toJSON = function () { | ||
var json = {}; | ||
for (var i = 0; i < this.slotCount(); i++) { | ||
} | ||
toJSON() { | ||
let json = {}; | ||
for (let i = 0; i < this.slotCount(); i++) { | ||
json[this.slotName(i)] = this.slotValue(i); | ||
} | ||
return json; | ||
}; | ||
return UtteredIntent; | ||
}()); | ||
} | ||
} | ||
exports.UtteredIntent = UtteredIntent; | ||
//# sourceMappingURL=sample-utterances.js.map |
"use strict"; | ||
var audio_player_1 = require("./audio-player"); | ||
var uuid = require("node-uuid"); | ||
var RequestType = (function () { | ||
function RequestType() { | ||
} | ||
RequestType.IntentRequest = "IntentRequest"; | ||
RequestType.LaunchRequest = "LaunchRequest"; | ||
RequestType.SessionEndedRequest = "SessionEndedRequest"; | ||
RequestType.AudioPlayerPlaybackFinished = "AudioPlayer.PlaybackFinished"; | ||
RequestType.AudioPlayerPlaybackNearlyFinished = "AudioPlayer.PlaybackNearlyFinished"; | ||
RequestType.AudioPlayerPlaybackStarted = "AudioPlayer.PlaybackStarted"; | ||
RequestType.AudioPlayerPlaybackStopped = "AudioPlayer.PlaybackStopped"; | ||
return RequestType; | ||
}()); | ||
const audio_player_1 = require("./audio-player"); | ||
const uuid = require("node-uuid"); | ||
class RequestType { | ||
} | ||
RequestType.IntentRequest = "IntentRequest"; | ||
RequestType.LaunchRequest = "LaunchRequest"; | ||
RequestType.SessionEndedRequest = "SessionEndedRequest"; | ||
RequestType.AudioPlayerPlaybackFinished = "AudioPlayer.PlaybackFinished"; | ||
RequestType.AudioPlayerPlaybackNearlyFinished = "AudioPlayer.PlaybackNearlyFinished"; | ||
RequestType.AudioPlayerPlaybackStarted = "AudioPlayer.PlaybackStarted"; | ||
RequestType.AudioPlayerPlaybackStopped = "AudioPlayer.PlaybackStopped"; | ||
exports.RequestType = RequestType; | ||
@@ -23,9 +20,9 @@ (function (SessionEndedReason) { | ||
var SessionEndedReason = exports.SessionEndedReason; | ||
var ServiceRequest = (function () { | ||
function ServiceRequest(context) { | ||
class ServiceRequest { | ||
constructor(context) { | ||
this.context = context; | ||
this.requestJSON = null; | ||
} | ||
ServiceRequest.prototype.intentRequest = function (intentName) { | ||
var isBuiltin = intentName.startsWith("AMAZON"); | ||
intentRequest(intentName) { | ||
let isBuiltin = intentName.startsWith("AMAZON"); | ||
if (!isBuiltin) { | ||
@@ -41,7 +38,6 @@ if (!this.context.interactionModel().hasIntent(intentName)) { | ||
if (!isBuiltin) { | ||
var intent = this.context.interactionModel().intentSchema.intent(intentName); | ||
let intent = this.context.interactionModel().intentSchema.intent(intentName); | ||
if (intent.slots !== null && intent.slots.length > 0) { | ||
this.requestJSON.request.intent.slots = {}; | ||
for (var _i = 0, _a = intent.slots; _i < _a.length; _i++) { | ||
var slot = _a[_i]; | ||
for (let slot of intent.slots) { | ||
this.requestJSON.request.intent.slots[slot.name] = { | ||
@@ -54,4 +50,4 @@ name: slot.name | ||
return this; | ||
}; | ||
ServiceRequest.prototype.audioPlayerRequest = function (requestType, token, offsetInMilliseconds) { | ||
} | ||
audioPlayerRequest(requestType, token, offsetInMilliseconds) { | ||
this.requestJSON = this.baseRequest(requestType); | ||
@@ -61,8 +57,8 @@ this.requestJSON.request.token = token; | ||
return this; | ||
}; | ||
ServiceRequest.prototype.launchRequest = function () { | ||
} | ||
launchRequest() { | ||
this.requestJSON = this.baseRequest(RequestType.LaunchRequest); | ||
return this; | ||
}; | ||
ServiceRequest.prototype.sessionEndedRequest = function (reason, errorData) { | ||
} | ||
sessionEndedRequest(reason, errorData) { | ||
this.requestJSON = this.baseRequest(RequestType.SessionEndedRequest); | ||
@@ -74,4 +70,4 @@ this.requestJSON.request.reason = SessionEndedReason[reason]; | ||
return this; | ||
}; | ||
ServiceRequest.prototype.withSlot = function (slotName, slotValue) { | ||
} | ||
withSlot(slotName, slotValue) { | ||
if (this.requestJSON.request.type !== "IntentRequest") { | ||
@@ -82,5 +78,5 @@ throw Error("Adding slot to non-intentName request - not allowed!"); | ||
return this; | ||
}; | ||
ServiceRequest.prototype.requiresSession = function () { | ||
var requireSession = false; | ||
} | ||
requiresSession() { | ||
let requireSession = false; | ||
if (this.requestType === RequestType.LaunchRequest || this.requestType === RequestType.IntentRequest) { | ||
@@ -90,9 +86,9 @@ requireSession = true; | ||
return requireSession; | ||
}; | ||
ServiceRequest.prototype.baseRequest = function (requestType) { | ||
} | ||
baseRequest(requestType) { | ||
this.requestType = requestType; | ||
var applicationID = this.context.applicationID(); | ||
var requestID = ServiceRequest.requestID(); | ||
var userID = this.context.userID(); | ||
var timestamp = ServiceRequest.timestamp(); | ||
const applicationID = this.context.applicationID(); | ||
const requestID = ServiceRequest.requestID(); | ||
const userID = this.context.userID(); | ||
const timestamp = ServiceRequest.timestamp(); | ||
return { | ||
@@ -122,12 +118,12 @@ request: { | ||
}; | ||
}; | ||
ServiceRequest.timestamp = function () { | ||
var timestamp = new Date().toISOString(); | ||
} | ||
static timestamp() { | ||
let timestamp = new Date().toISOString(); | ||
return timestamp.substring(0, 19) + "Z"; | ||
}; | ||
ServiceRequest.requestID = function () { | ||
} | ||
static requestID() { | ||
return "amzn1.echo-api.request." + uuid.v4(); | ||
}; | ||
ServiceRequest.prototype.includeSession = function () { | ||
var include = false; | ||
} | ||
includeSession() { | ||
let include = false; | ||
if (this.requestType === RequestType.IntentRequest || | ||
@@ -139,11 +135,11 @@ this.requestType === RequestType.LaunchRequest || | ||
return include; | ||
}; | ||
ServiceRequest.prototype.toJSON = function () { | ||
var applicationID = this.context.applicationID(); | ||
var userID = this.context.userID(); | ||
} | ||
toJSON() { | ||
const applicationID = this.context.applicationID(); | ||
const userID = this.context.userID(); | ||
if (this.includeSession() && this.context.activeSession()) { | ||
var session = this.context.session(); | ||
var newSession = session.isNew(); | ||
var sessionID = session.id(); | ||
var attributes = session.attributes(); | ||
const session = this.context.session(); | ||
let newSession = session.isNew(); | ||
let sessionID = session.id(); | ||
let attributes = session.attributes(); | ||
this.requestJSON.session = { | ||
@@ -167,3 +163,3 @@ sessionId: sessionID, | ||
if (this.context.audioPlayerEnabled()) { | ||
var activity = audio_player_1.AudioPlayerActivity[this.context.audioPlayer().activity()]; | ||
const activity = audio_player_1.AudioPlayerActivity[this.context.audioPlayer().activity()]; | ||
this.requestJSON.context.AudioPlayer = { | ||
@@ -173,3 +169,3 @@ playerActivity: activity | ||
if (this.context.audioPlayer().activity() !== audio_player_1.AudioPlayerActivity.IDLE) { | ||
var playing = this.context.audioPlayer().playing(); | ||
const playing = this.context.audioPlayer().playing(); | ||
this.requestJSON.context.AudioPlayer.token = playing.stream.token; | ||
@@ -181,6 +177,5 @@ this.requestJSON.context.AudioPlayer.offsetInMilliseconds = playing.stream.offsetInMilliseconds; | ||
return this.requestJSON; | ||
}; | ||
return ServiceRequest; | ||
}()); | ||
} | ||
} | ||
exports.ServiceRequest = ServiceRequest; | ||
//# sourceMappingURL=service-request.js.map |
"use strict"; | ||
var global_1 = require("../core/global"); | ||
var socket_handler_1 = require("../core/socket-handler"); | ||
var webhook_request_1 = require("../core/webhook-request"); | ||
var tcp_client_1 = require("./tcp-client"); | ||
var global_2 = require("../core/global"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var keep_alive_1 = require("./keep-alive"); | ||
var string_util_1 = require("../core/string-util"); | ||
var http_buffer_1 = require("../core/http-buffer"); | ||
var Logger = "BST-CLIENT"; | ||
var BespokeClient = (function () { | ||
function BespokeClient(nodeID, host, port, targetPort) { | ||
const global_1 = require("../core/global"); | ||
const socket_handler_1 = require("../core/socket-handler"); | ||
const webhook_request_1 = require("../core/webhook-request"); | ||
const tcp_client_1 = require("./tcp-client"); | ||
const global_2 = require("../core/global"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const keep_alive_1 = require("./keep-alive"); | ||
const string_util_1 = require("../core/string-util"); | ||
const http_buffer_1 = require("../core/http-buffer"); | ||
const Logger = "BST-CLIENT"; | ||
class BespokeClient { | ||
constructor(nodeID, host, port, targetPort) { | ||
this.nodeID = nodeID; | ||
@@ -21,4 +21,4 @@ this.host = host; | ||
} | ||
BespokeClient.prototype.connect = function (onConnect) { | ||
var self = this; | ||
connect(onConnect) { | ||
let self = this; | ||
if (onConnect !== undefined && onConnect !== null) { | ||
@@ -48,12 +48,12 @@ this.onConnect = onConnect; | ||
}); | ||
}; | ||
BespokeClient.prototype.newKeepAlive = function (handler) { | ||
} | ||
newKeepAlive(handler) { | ||
return new keep_alive_1.KeepAlive(handler); | ||
}; | ||
BespokeClient.prototype.onWebhookReceived = function (request) { | ||
var self = this; | ||
} | ||
onWebhookReceived(request) { | ||
let self = this; | ||
logging_helper_1.LoggingHelper.info(Logger, "RequestReceived: " + request.toString() + " ID: " + request.id()); | ||
logging_helper_1.LoggingHelper.verbose(Logger, "Payload:\n" + string_util_1.StringUtil.prettyPrintJSON(request.body)); | ||
var tcpClient = new tcp_client_1.TCPClient(request.id() + ""); | ||
var httpBuffer = new http_buffer_1.HTTPBuffer(); | ||
let tcpClient = new tcp_client_1.TCPClient(request.id() + ""); | ||
let httpBuffer = new http_buffer_1.HTTPBuffer(); | ||
tcpClient.transmit("localhost", self.targetPort, request.toTCP(), function (data, error, message) { | ||
@@ -64,3 +64,3 @@ if (data != null) { | ||
logging_helper_1.LoggingHelper.info(Logger, "ResponseReceived ID: " + request.id()); | ||
var payload = null; | ||
let payload = null; | ||
if (httpBuffer.isJSON()) { | ||
@@ -85,4 +85,4 @@ payload = string_util_1.StringUtil.prettyPrintJSON(httpBuffer.body().toString()); | ||
}); | ||
}; | ||
BespokeClient.prototype.connected = function (error) { | ||
} | ||
connected(error) { | ||
if (error !== undefined && error !== null) { | ||
@@ -97,4 +97,4 @@ logging_helper_1.LoggingHelper.error(Logger, "Unable to connect to: " + this.host + ":" + this.port); | ||
logging_helper_1.LoggingHelper.info(Logger, "Connected - " + this.host + ":" + this.port); | ||
var messageJSON = { "id": this.nodeID }; | ||
var message = JSON.stringify(messageJSON); | ||
let messageJSON = { "id": this.nodeID }; | ||
let message = JSON.stringify(messageJSON); | ||
this.socketHandler.send(message); | ||
@@ -105,4 +105,4 @@ if (this.onConnect !== undefined && this.onConnect !== null) { | ||
} | ||
}; | ||
BespokeClient.prototype.messageReceived = function (message, messageID) { | ||
} | ||
messageReceived(message, messageID) { | ||
if (message.indexOf("ACK") !== -1) { | ||
@@ -116,4 +116,4 @@ } | ||
} | ||
}; | ||
BespokeClient.prototype.shutdown = function (callback) { | ||
} | ||
shutdown(callback) { | ||
logging_helper_1.LoggingHelper.info(Logger, "Shutting down proxy"); | ||
@@ -126,6 +126,5 @@ this.shuttingDown = true; | ||
} | ||
}; | ||
return BespokeClient; | ||
}()); | ||
} | ||
} | ||
exports.BespokeClient = BespokeClient; | ||
//# sourceMappingURL=bespoke-client.js.map |
"use strict"; | ||
var interaction_model_1 = require("../alexa/interaction-model"); | ||
var alexa_1 = require("../alexa/alexa"); | ||
var global_1 = require("../core/global"); | ||
var service_request_1 = require("../alexa/service-request"); | ||
var BSTAlexaEvents = (function () { | ||
function BSTAlexaEvents() { | ||
} | ||
BSTAlexaEvents.AudioPlayerPlaybackFinished = "AudioPlayer.PlaybackFinished"; | ||
BSTAlexaEvents.AudioPlayerPlaybackNearlyFinished = "AudioPlayer.PlaybackNearlyFinished"; | ||
BSTAlexaEvents.AudioPlayerPlaybackStarted = "AudioPlayer.PlaybackStarted"; | ||
BSTAlexaEvents.AudioPlayerPlaybackStopped = "AudioPlayer.PlaybackStopped"; | ||
BSTAlexaEvents.Response = "response"; | ||
return BSTAlexaEvents; | ||
}()); | ||
const interaction_model_1 = require("../alexa/interaction-model"); | ||
const alexa_1 = require("../alexa/alexa"); | ||
const global_1 = require("../core/global"); | ||
const service_request_1 = require("../alexa/service-request"); | ||
class BSTAlexaEvents { | ||
} | ||
BSTAlexaEvents.AudioPlayerPlaybackFinished = "AudioPlayer.PlaybackFinished"; | ||
BSTAlexaEvents.AudioPlayerPlaybackNearlyFinished = "AudioPlayer.PlaybackNearlyFinished"; | ||
BSTAlexaEvents.AudioPlayerPlaybackStarted = "AudioPlayer.PlaybackStarted"; | ||
BSTAlexaEvents.AudioPlayerPlaybackStopped = "AudioPlayer.PlaybackStopped"; | ||
BSTAlexaEvents.Response = "response"; | ||
exports.BSTAlexaEvents = BSTAlexaEvents; | ||
var BSTAlexa = (function () { | ||
function BSTAlexa(skillURL, intentSchemaFile, sampleUtterancesFile, applicationID) { | ||
class BSTAlexa { | ||
constructor(skillURL, intentSchemaFile, sampleUtterancesFile, applicationID) { | ||
this.skillURL = skillURL; | ||
@@ -35,4 +32,4 @@ this.intentSchemaFile = intentSchemaFile; | ||
} | ||
BSTAlexa.prototype.start = function (ready) { | ||
var self = this; | ||
start(ready) { | ||
let self = this; | ||
interaction_model_1.InteractionModel.fromFiles(this.intentSchemaFile, this.sampleUtterancesFile, function (model, error) { | ||
@@ -47,4 +44,4 @@ if (error !== undefined && error !== null) { | ||
}); | ||
}; | ||
BSTAlexa.prototype.on = function (eventType, callback) { | ||
} | ||
on(eventType, callback) { | ||
if (eventType.startsWith("AudioPlayer")) { | ||
@@ -65,4 +62,4 @@ if (!BSTAlexa.validateAudioEventType(eventType)) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.once = function (eventType, callback) { | ||
} | ||
once(eventType, callback) { | ||
if (eventType.startsWith("AudioPlayer")) { | ||
@@ -83,4 +80,4 @@ if (!BSTAlexa.validateAudioEventType(eventType)) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.spoken = function (phrase, callback) { | ||
} | ||
spoken(phrase, callback) { | ||
this._alexa.spoken(phrase, function (error, response, request) { | ||
@@ -92,4 +89,4 @@ if (callback !== undefined && callback !== null) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.intended = function (intentName, slots, callback) { | ||
} | ||
intended(intentName, slots, callback) { | ||
this._alexa.intended(intentName, slots, function (error, response, request) { | ||
@@ -101,13 +98,13 @@ if (callback !== undefined && callback !== null) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.launched = function (callback) { | ||
} | ||
launched(callback) { | ||
this._alexa.launched(callback); | ||
return this; | ||
}; | ||
BSTAlexa.prototype.sessionEnded = function (sessionEndedReason, callback) { | ||
var sessionEndedEnum = service_request_1.SessionEndedReason[sessionEndedReason]; | ||
} | ||
sessionEnded(sessionEndedReason, callback) { | ||
const sessionEndedEnum = service_request_1.SessionEndedReason[sessionEndedReason]; | ||
this._alexa.sessionEnded(sessionEndedEnum, null, callback); | ||
return this; | ||
}; | ||
BSTAlexa.prototype.playbackFinished = function (callback) { | ||
} | ||
playbackFinished(callback) { | ||
if (this._alexa.context().audioPlayerEnabled()) { | ||
@@ -119,4 +116,4 @@ if (this._alexa.context().audioPlayer().isPlaying()) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.playbackNearlyFinished = function (callback) { | ||
} | ||
playbackNearlyFinished(callback) { | ||
if (this._alexa.context().audioPlayerEnabled()) { | ||
@@ -128,4 +125,4 @@ if (this._alexa.context().audioPlayer().isPlaying()) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.playbackStopped = function (callback) { | ||
} | ||
playbackStopped(callback) { | ||
if (this._alexa.context().audioPlayerEnabled()) { | ||
@@ -137,14 +134,13 @@ if (this._alexa.context().audioPlayer().isPlaying()) { | ||
return this; | ||
}; | ||
BSTAlexa.prototype.playbackOffset = function (offsetInMilliseconds) { | ||
} | ||
playbackOffset(offsetInMilliseconds) { | ||
this._alexa.context().audioPlayer().playbackOffset(offsetInMilliseconds); | ||
return this; | ||
}; | ||
BSTAlexa.prototype.stop = function (onStop) { | ||
} | ||
stop(onStop) { | ||
this._alexa.stop(onStop); | ||
}; | ||
BSTAlexa.validateAudioEventType = function (eventType) { | ||
var match = false; | ||
for (var _i = 0, _a = BSTAlexa.AudioPlayerEvents; _i < _a.length; _i++) { | ||
var e = _a[_i]; | ||
} | ||
static validateAudioEventType(eventType) { | ||
let match = false; | ||
for (let e of BSTAlexa.AudioPlayerEvents) { | ||
if (eventType === e) { | ||
@@ -156,12 +152,11 @@ match = true; | ||
return match; | ||
}; | ||
BSTAlexa.AudioPlayerEvents = [BSTAlexaEvents.AudioPlayerPlaybackFinished, | ||
BSTAlexaEvents.AudioPlayerPlaybackNearlyFinished, | ||
BSTAlexaEvents.AudioPlayerPlaybackStarted, | ||
BSTAlexaEvents.AudioPlayerPlaybackStopped]; | ||
BSTAlexa.DefaultIntentSchemaLocation = "speechAssets/IntentSchema.json"; | ||
BSTAlexa.DefaultSampleUtterancesLocation = "speechAssets/SampleUtterances.txt"; | ||
return BSTAlexa; | ||
}()); | ||
} | ||
} | ||
BSTAlexa.AudioPlayerEvents = [BSTAlexaEvents.AudioPlayerPlaybackFinished, | ||
BSTAlexaEvents.AudioPlayerPlaybackNearlyFinished, | ||
BSTAlexaEvents.AudioPlayerPlaybackStarted, | ||
BSTAlexaEvents.AudioPlayerPlaybackStopped]; | ||
BSTAlexa.DefaultIntentSchemaLocation = "speechAssets/IntentSchema.json"; | ||
BSTAlexa.DefaultSampleUtterancesLocation = "speechAssets/SampleUtterances.txt"; | ||
exports.BSTAlexa = BSTAlexa; | ||
//# sourceMappingURL=bst-alexa.js.map |
"use strict"; | ||
var fs = require("fs"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var lambda_config_1 = require("./lambda-config"); | ||
var uuid = require("node-uuid"); | ||
var Logger = "CONFIG"; | ||
var BSTDirectoryName = ".bst"; | ||
var BSTConfig = (function () { | ||
function BSTConfig() { | ||
const fs = require("fs"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const lambda_config_1 = require("./lambda-config"); | ||
let uuid = require("node-uuid"); | ||
const Logger = "CONFIG"; | ||
const BSTDirectoryName = ".bst"; | ||
class BSTConfig { | ||
constructor() { | ||
this.configuration = null; | ||
this.process = null; | ||
} | ||
BSTConfig.load = function () { | ||
static load() { | ||
BSTConfig.bootstrapIfNeeded(); | ||
var data = fs.readFileSync(BSTConfig.configPath()); | ||
var config = JSON.parse(data.toString()); | ||
var bstConfig = new BSTConfig(); | ||
let data = fs.readFileSync(BSTConfig.configPath()); | ||
let config = JSON.parse(data.toString()); | ||
let bstConfig = new BSTConfig(); | ||
bstConfig.loadFromJSON(config); | ||
return bstConfig; | ||
}; | ||
BSTConfig.prototype.save = function () { | ||
} | ||
save() { | ||
BSTConfig.saveConfig(this.configuration); | ||
}; | ||
BSTConfig.prototype.nodeID = function () { | ||
} | ||
nodeID() { | ||
return this.configuration.nodeID; | ||
}; | ||
BSTConfig.prototype.applicationID = function () { | ||
} | ||
applicationID() { | ||
return this.configuration.applicationID; | ||
}; | ||
BSTConfig.prototype.updateApplicationID = function (applicationID) { | ||
} | ||
updateApplicationID(applicationID) { | ||
this.configuration.applicationID = applicationID; | ||
this.commit(); | ||
}; | ||
BSTConfig.prototype.commit = function () { | ||
var configBuffer = new Buffer(JSON.stringify(this.configuration, null, 4) + "\n"); | ||
} | ||
commit() { | ||
let configBuffer = new Buffer(JSON.stringify(this.configuration, null, 4) + "\n"); | ||
fs.writeFileSync(BSTConfig.configPath(), configBuffer); | ||
}; | ||
BSTConfig.prototype.loadFromJSON = function (config) { | ||
} | ||
loadFromJSON(config) { | ||
this.configuration = config; | ||
}; | ||
BSTConfig.configDirectory = function () { | ||
} | ||
static configDirectory() { | ||
return getUserHome() + "/" + BSTDirectoryName; | ||
}; | ||
BSTConfig.configPath = function () { | ||
} | ||
static configPath() { | ||
return BSTConfig.configDirectory() + "/config"; | ||
}; | ||
BSTConfig.bootstrapIfNeeded = function () { | ||
var directory = BSTConfig.configDirectory(); | ||
} | ||
static bootstrapIfNeeded() { | ||
let directory = BSTConfig.configDirectory(); | ||
if (!fs.existsSync(directory)) { | ||
@@ -54,13 +54,13 @@ fs.mkdirSync(directory); | ||
logging_helper_1.LoggingHelper.info(Logger, "No configuration. Creating one: " + BSTConfig.configPath()); | ||
var configJSON = BSTConfig.createConfig(); | ||
let configJSON = BSTConfig.createConfig(); | ||
BSTConfig.saveConfig(configJSON); | ||
} | ||
}; | ||
BSTConfig.saveConfig = function (config) { | ||
var configBuffer = new Buffer(JSON.stringify(config, null, 4) + "\n"); | ||
} | ||
static saveConfig(config) { | ||
let configBuffer = new Buffer(JSON.stringify(config, null, 4) + "\n"); | ||
fs.writeFileSync(BSTConfig.configPath(), configBuffer); | ||
}; | ||
BSTConfig.createConfig = function () { | ||
var nodeID = uuid.v4(); | ||
var lambdaConfig = lambda_config_1.LambdaConfig.defaultConfig().lambdaDeploy; | ||
} | ||
static createConfig() { | ||
let nodeID = uuid.v4(); | ||
let lambdaConfig = lambda_config_1.LambdaConfig.defaultConfig().lambdaDeploy; | ||
return { | ||
@@ -70,14 +70,13 @@ "nodeID": nodeID, | ||
}; | ||
}; | ||
return BSTConfig; | ||
}()); | ||
} | ||
} | ||
exports.BSTConfig = BSTConfig; | ||
var BSTProcess = (function () { | ||
function BSTProcess() { | ||
class BSTProcess { | ||
constructor() { | ||
} | ||
BSTProcess.running = function () { | ||
var process = null; | ||
static running() { | ||
let process = null; | ||
if (fs.existsSync(BSTProcess.processPath())) { | ||
var data = fs.readFileSync(BSTProcess.processPath()); | ||
var json = JSON.parse(data.toString()); | ||
let data = fs.readFileSync(BSTProcess.processPath()); | ||
let json = JSON.parse(data.toString()); | ||
if (BSTProcess.isRunning(json.pid)) { | ||
@@ -89,4 +88,4 @@ process = new BSTProcess(); | ||
return process; | ||
}; | ||
BSTProcess.isRunning = function (pid) { | ||
} | ||
static isRunning(pid) { | ||
try { | ||
@@ -99,17 +98,17 @@ process.kill(pid, 0); | ||
} | ||
}; | ||
BSTProcess.processPath = function () { | ||
} | ||
static processPath() { | ||
return getUserHome() + "/" + BSTDirectoryName + "/process"; | ||
}; | ||
BSTProcess.run = function (port, proxyType, pid) { | ||
var process = new BSTProcess(); | ||
} | ||
static run(port, proxyType, pid) { | ||
let process = new BSTProcess(); | ||
process.port = port; | ||
process.proxyType = proxyType; | ||
process.pid = pid; | ||
var json = process.json(); | ||
var jsonBuffer = new Buffer(JSON.stringify(json, undefined, 4) + "\n"); | ||
let json = process.json(); | ||
let jsonBuffer = new Buffer(JSON.stringify(json, undefined, 4) + "\n"); | ||
fs.writeFileSync(BSTProcess.processPath(), jsonBuffer); | ||
return process; | ||
}; | ||
BSTProcess.prototype.kill = function () { | ||
} | ||
kill() { | ||
try { | ||
@@ -123,9 +122,9 @@ process.kill(this.pid, "SIGKILL"); | ||
} | ||
}; | ||
BSTProcess.prototype.loadJSON = function (json) { | ||
} | ||
loadJSON(json) { | ||
this.port = json.port; | ||
this.proxyType = json.proxyType; | ||
this.pid = json.pid; | ||
}; | ||
BSTProcess.prototype.json = function () { | ||
} | ||
json() { | ||
return { | ||
@@ -136,5 +135,4 @@ "port": this.port, | ||
}; | ||
}; | ||
return BSTProcess; | ||
}()); | ||
} | ||
} | ||
exports.BSTProcess = BSTProcess; | ||
@@ -141,0 +139,0 @@ function getUserHome() { |
"use strict"; | ||
var file_util_1 = require("../core/file-util"); | ||
var path = require("path"); | ||
var http = require("http"); | ||
var AWS = require("aws-sdk"); | ||
var BSTEncode = (function () { | ||
function BSTEncode(awsConfiguration) { | ||
const file_util_1 = require("../core/file-util"); | ||
const path = require("path"); | ||
const http = require("http"); | ||
const AWS = require("aws-sdk"); | ||
class BSTEncode { | ||
constructor(awsConfiguration) { | ||
this._awsConfiguration = awsConfiguration; | ||
@@ -14,10 +14,10 @@ if (awsConfiguration.accessKeyId === undefined) { | ||
} | ||
BSTEncode.prototype.encodeFileAndPublish = function (filePath, callback) { | ||
encodeFileAndPublish(filePath, callback) { | ||
this.encodeURLAndPublishAs(filePath, null, callback); | ||
}; | ||
BSTEncode.prototype.encodeFileAndPublishAs = function (filePath, outputKey, callback) { | ||
var self = this; | ||
} | ||
encodeFileAndPublishAs(filePath, outputKey, callback) { | ||
const self = this; | ||
file_util_1.FileUtil.readFile(filePath, function (data) { | ||
var fp = path.parse(filePath); | ||
var filename = fp.name + fp.ext; | ||
const fp = path.parse(filePath); | ||
const filename = fp.name + fp.ext; | ||
self.uploadFile(self._awsConfiguration.bucket, filename, data, function (url) { | ||
@@ -29,17 +29,17 @@ self.callEncode(url, null, function (error, encodedURL) { | ||
}); | ||
}; | ||
BSTEncode.prototype.encodeURLAndPublish = function (sourceURL, callback) { | ||
} | ||
encodeURLAndPublish(sourceURL, callback) { | ||
this.encodeURLAndPublishAs(sourceURL, null, callback); | ||
}; | ||
BSTEncode.prototype.encodeURLAndPublishAs = function (sourceURL, outputKey, callback) { | ||
var self = this; | ||
} | ||
encodeURLAndPublishAs(sourceURL, outputKey, callback) { | ||
const self = this; | ||
self.callEncode(sourceURL, outputKey, function (error, encodedURL) { | ||
callback(error, encodedURL); | ||
}); | ||
}; | ||
BSTEncode.prototype.uploadFile = function (bucket, name, data, callback) { | ||
} | ||
uploadFile(bucket, name, data, callback) { | ||
if (this._awsConfiguration === undefined) { | ||
throw new Error("No AWS Configuration parameters defined"); | ||
} | ||
var config = { | ||
const config = { | ||
credentials: { | ||
@@ -50,10 +50,10 @@ accessKeyId: this._awsConfiguration.accessKeyId, | ||
}; | ||
var s3 = new AWS.S3(config); | ||
var params = { Bucket: bucket, Key: name, Body: data, ACL: "public-read" }; | ||
const s3 = new AWS.S3(config); | ||
const params = { Bucket: bucket, Key: name, Body: data, ACL: "public-read" }; | ||
s3.putObject(params, function () { | ||
callback(BSTEncode.urlForS3(bucket, name)); | ||
}); | ||
}; | ||
BSTEncode.prototype.callEncode = function (sourceURL, bucketKey, callback) { | ||
var self = this; | ||
} | ||
callEncode(sourceURL, bucketKey, callback) { | ||
const self = this; | ||
if (bucketKey === null) { | ||
@@ -64,6 +64,6 @@ bucketKey = sourceURL.substring(sourceURL.lastIndexOf("/") + 1); | ||
} | ||
var basename = bucketKey.substring(0, bucketKey.indexOf(".")); | ||
const basename = bucketKey.substring(0, bucketKey.indexOf(".")); | ||
bucketKey = basename + "-encoded.mp3"; | ||
} | ||
var options = { | ||
const options = { | ||
host: BSTEncode.EncoderHost, | ||
@@ -80,4 +80,4 @@ path: BSTEncode.EncoderPath, | ||
}; | ||
var responseData = ""; | ||
var request = http.request(options, function (response) { | ||
let responseData = ""; | ||
const request = http.request(options, function (response) { | ||
if (response.statusCode !== 200) { | ||
@@ -91,3 +91,3 @@ callback(new Error(response.statusMessage), null); | ||
response.on("end", function () { | ||
var officialURL = BSTEncode.urlForS3(self.bucket(), bucketKey); | ||
const officialURL = BSTEncode.urlForS3(self.bucket(), bucketKey); | ||
callback(null, officialURL); | ||
@@ -98,14 +98,13 @@ }); | ||
request.end(); | ||
}; | ||
BSTEncode.prototype.bucket = function () { | ||
} | ||
bucket() { | ||
return this._awsConfiguration.bucket; | ||
}; | ||
BSTEncode.urlForS3 = function (bucket, key) { | ||
} | ||
static urlForS3(bucket, key) { | ||
return "https://s3.amazonaws.com/" + bucket + "/" + key; | ||
}; | ||
BSTEncode.EncoderHost = "elb-ecs-bespokenencoder-dev-299768275.us-east-1.elb.amazonaws.com"; | ||
BSTEncode.EncoderPath = "/encode"; | ||
return BSTEncode; | ||
}()); | ||
} | ||
} | ||
BSTEncode.EncoderHost = "elb-ecs-bespokenencoder-dev-299768275.us-east-1.elb.amazonaws.com"; | ||
BSTEncode.EncoderPath = "/encode"; | ||
exports.BSTEncode = BSTEncode; | ||
//# sourceMappingURL=bst-encode.js.map |
"use strict"; | ||
var bespoke_client_1 = require("./bespoke-client"); | ||
var lambda_server_1 = require("./lambda-server"); | ||
var url_mangler_1 = require("./url-mangler"); | ||
var bst_config_1 = require("./bst-config"); | ||
var global_1 = require("../core/global"); | ||
const bespoke_client_1 = require("./bespoke-client"); | ||
const lambda_server_1 = require("./lambda-server"); | ||
const url_mangler_1 = require("./url-mangler"); | ||
const bst_config_1 = require("./bst-config"); | ||
const global_1 = require("../core/global"); | ||
(function (ProxyType) { | ||
@@ -12,5 +12,5 @@ ProxyType[ProxyType["HTTP"] = 0] = "HTTP"; | ||
var ProxyType = exports.ProxyType; | ||
var DefaultLambdaPort = 10000; | ||
var BSTProxy = (function () { | ||
function BSTProxy(proxyType) { | ||
const DefaultLambdaPort = 10000; | ||
class BSTProxy { | ||
constructor(proxyType) { | ||
this.proxyType = proxyType; | ||
@@ -22,30 +22,30 @@ this.bespokenClient = null; | ||
} | ||
BSTProxy.http = function (targetPort) { | ||
var tool = new BSTProxy(ProxyType.HTTP); | ||
static http(targetPort) { | ||
let tool = new BSTProxy(ProxyType.HTTP); | ||
tool.httpPort = targetPort; | ||
return tool; | ||
}; | ||
BSTProxy.lambda = function (lambdaFile) { | ||
var tool = new BSTProxy(ProxyType.LAMBDA); | ||
} | ||
static lambda(lambdaFile) { | ||
let tool = new BSTProxy(ProxyType.LAMBDA); | ||
tool.lambdaFile = lambdaFile; | ||
tool.httpPort = DefaultLambdaPort; | ||
return tool; | ||
}; | ||
BSTProxy.urlgen = function (url) { | ||
} | ||
static urlgen(url) { | ||
return url_mangler_1.URLMangler.mangle(url, global_1.Global.config().nodeID()); | ||
}; | ||
BSTProxy.prototype.bespokenServer = function (host, port) { | ||
} | ||
bespokenServer(host, port) { | ||
this.bespokenHost = host; | ||
this.bespokenPort = port; | ||
return this; | ||
}; | ||
BSTProxy.prototype.lambdaPort = function (port) { | ||
} | ||
lambdaPort(port) { | ||
this.httpPort = port; | ||
return this; | ||
}; | ||
BSTProxy.prototype.start = function (onStarted) { | ||
} | ||
start(onStarted) { | ||
bst_config_1.BSTProcess.run(this.httpPort, this.proxyType, process.pid); | ||
this.bespokenClient = new bespoke_client_1.BespokeClient(global_1.Global.config().nodeID(), this.bespokenHost, this.bespokenPort, this.httpPort); | ||
var callbackCountDown = 1; | ||
var callback = function () { | ||
let callbackCountDown = 1; | ||
const callback = function () { | ||
callbackCountDown--; | ||
@@ -63,4 +63,4 @@ if (callbackCountDown === 0 && onStarted !== undefined) { | ||
} | ||
}; | ||
BSTProxy.prototype.stop = function (onStopped) { | ||
} | ||
stop(onStopped) { | ||
if (this.bespokenClient !== null) { | ||
@@ -77,6 +77,5 @@ this.bespokenClient.shutdown(); | ||
} | ||
}; | ||
return BSTProxy; | ||
}()); | ||
} | ||
} | ||
exports.BSTProxy = BSTProxy; | ||
//# sourceMappingURL=bst-proxy.js.map |
"use strict"; | ||
var global_1 = require("../core/global"); | ||
var KeepAlivePeriod = 30000; | ||
var KeepAliveWindowPeriod = 300000; | ||
var KeepAliveWarningThreshold = 5; | ||
var KeepAlive = (function () { | ||
function KeepAlive(socket) { | ||
const global_1 = require("../core/global"); | ||
const KeepAlivePeriod = 30000; | ||
const KeepAliveWindowPeriod = 300000; | ||
const KeepAliveWarningThreshold = 5; | ||
class KeepAlive { | ||
constructor(socket) { | ||
this.socket = socket; | ||
@@ -15,12 +15,12 @@ this.pingPeriod = KeepAlivePeriod; | ||
} | ||
KeepAlive.prototype.start = function (onFailureCallback) { | ||
start(onFailureCallback) { | ||
this.onFailureCallback = onFailureCallback; | ||
this.reset(); | ||
this.keepAlive(); | ||
}; | ||
KeepAlive.prototype.reset = function () { | ||
} | ||
reset() { | ||
this.startedTimestamp = new Date().getTime(); | ||
}; | ||
KeepAlive.prototype.keepAlive = function () { | ||
var self = this; | ||
} | ||
keepAlive() { | ||
let self = this; | ||
if ((new Date().getTime() - this.startedTimestamp) > this.windowPeriod) { | ||
@@ -37,9 +37,8 @@ this.keepAliveArray = this.keepAlivesInPeriod(this.windowPeriod); | ||
}, this.pingPeriod); | ||
}; | ||
KeepAlive.prototype.keepAlivesInPeriod = function (periodInMilliseconds) { | ||
var newArray = []; | ||
var rightNow = new Date().getTime(); | ||
for (var _i = 0, _a = this.keepAliveArray; _i < _a.length; _i++) { | ||
var timestamp = _a[_i]; | ||
var secondsPassed = rightNow - timestamp; | ||
} | ||
keepAlivesInPeriod(periodInMilliseconds) { | ||
let newArray = []; | ||
let rightNow = new Date().getTime(); | ||
for (let timestamp of this.keepAliveArray) { | ||
let secondsPassed = rightNow - timestamp; | ||
if (secondsPassed < periodInMilliseconds) { | ||
@@ -50,14 +49,13 @@ newArray.push(timestamp); | ||
return newArray; | ||
}; | ||
KeepAlive.prototype.received = function () { | ||
} | ||
received() { | ||
this.keepAliveArray.push(new Date().getTime()); | ||
}; | ||
KeepAlive.prototype.stop = function () { | ||
} | ||
stop() { | ||
if (this.timeout !== null) { | ||
clearTimeout(this.timeout); | ||
} | ||
}; | ||
return KeepAlive; | ||
}()); | ||
} | ||
} | ||
exports.KeepAlive = KeepAlive; | ||
//# sourceMappingURL=keep-alive.js.map |
"use strict"; | ||
var aws = require("aws-sdk"); | ||
var LambdaAws = (function () { | ||
function LambdaAws() { | ||
const aws = require("aws-sdk"); | ||
class LambdaAws { | ||
constructor() { | ||
this.iam = null; | ||
@@ -9,6 +9,6 @@ this.lambda = null; | ||
} | ||
LambdaAws.create = function (lambdaConfig) { | ||
var instance = new LambdaAws(); | ||
static create(lambdaConfig) { | ||
let instance = new LambdaAws(); | ||
instance.lambdaConfig = lambdaConfig; | ||
var aws_security = { | ||
let aws_security = { | ||
accessKeyId: lambdaConfig.AWS_ACCESS_KEY_ID, | ||
@@ -26,8 +26,7 @@ secretAccessKey: lambdaConfig.AWS_SECRET_ACCESS_KEY, | ||
return instance; | ||
}; | ||
LambdaAws.prototype.createRole = function (roleName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var roleRrn = null; | ||
var assumeRolePolicy = { | ||
} | ||
createRole(roleName) { | ||
return new Promise((resolve, reject) => { | ||
let roleRrn = null; | ||
let assumeRolePolicy = { | ||
Version: "2012-10-17", | ||
@@ -45,29 +44,28 @@ Statement: [ | ||
}; | ||
var createParams = { | ||
let createParams = { | ||
AssumeRolePolicyDocument: JSON.stringify(assumeRolePolicy, null, 2), | ||
RoleName: roleName | ||
}; | ||
var createPromise = _this.iam.createRole(createParams).promise(); | ||
let createPromise = this.iam.createRole(createParams).promise(); | ||
createPromise | ||
.then(function (data) { | ||
.then((data) => { | ||
roleRrn = data.Role.Arn; | ||
return _this.putRolePolicy(roleName); | ||
return this.putRolePolicy(roleName); | ||
}) | ||
.then(function (data) { | ||
.then((data) => { | ||
resolve(roleRrn); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
}; | ||
LambdaAws.prototype.getRole = function (roleName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var getRolePromise = _this.iam.getRole({ "RoleName": roleName }).promise(); | ||
} | ||
getRole(roleName) { | ||
return new Promise((resolve, reject) => { | ||
let getRolePromise = this.iam.getRole({ "RoleName": roleName }).promise(); | ||
getRolePromise | ||
.then(function (data) { | ||
.then((data) => { | ||
resolve(data.Role.Arn); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
if (err.code === "NoSuchEntity") { | ||
@@ -81,14 +79,13 @@ resolve(null); | ||
}); | ||
}; | ||
LambdaAws.prototype.deleteRole = function (roleName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.deleteRolePolicy(roleName) | ||
.then(function (data) { | ||
return _this.iam.deleteRole({ "RoleName": roleName }).promise(); | ||
} | ||
deleteRole(roleName) { | ||
return new Promise((resolve, reject) => { | ||
this.deleteRolePolicy(roleName) | ||
.then((data) => { | ||
return this.iam.deleteRole({ "RoleName": roleName }).promise(); | ||
}) | ||
.then(function (data) { | ||
.then((data) => { | ||
resolve(null); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
if (err.code === "NoSuchEntity") { | ||
@@ -102,12 +99,11 @@ resolve(null); | ||
}); | ||
}; | ||
LambdaAws.prototype.deleteRolePolicy = function (roleName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var policyName = roleName + "-access"; | ||
_this.iam.deleteRolePolicy({ "PolicyName": policyName, "RoleName": roleName }).promise() | ||
.then(function (data) { | ||
} | ||
deleteRolePolicy(roleName) { | ||
return new Promise((resolve, reject) => { | ||
let policyName = roleName + "-access"; | ||
this.iam.deleteRolePolicy({ "PolicyName": policyName, "RoleName": roleName }).promise() | ||
.then((data) => { | ||
resolve(data); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
if (err.code === "NoSuchEntity") { | ||
@@ -121,7 +117,6 @@ resolve(err.code); | ||
}); | ||
}; | ||
LambdaAws.prototype.putRolePolicy = function (roleName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var rolePolicy = { | ||
} | ||
putRolePolicy(roleName) { | ||
return new Promise((resolve, reject) => { | ||
let rolePolicy = { | ||
Version: "2012-10-17", | ||
@@ -165,3 +160,3 @@ Statement: [ | ||
}; | ||
var putRolePolicyParams = { | ||
let putRolePolicyParams = { | ||
PolicyDocument: JSON.stringify(rolePolicy, null, 2), | ||
@@ -171,16 +166,15 @@ PolicyName: roleName + "-access", | ||
}; | ||
var putRolePromise = _this.iam.putRolePolicy(putRolePolicyParams).promise(); | ||
let putRolePromise = this.iam.putRolePolicy(putRolePolicyParams).promise(); | ||
putRolePromise | ||
.then(function (data) { | ||
.then((data) => { | ||
resolve(data); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
}; | ||
LambdaAws.prototype.invokeLambda = function (functionName, payload) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
var params = { | ||
} | ||
invokeLambda(functionName, payload) { | ||
return new Promise((resolve, reject) => { | ||
let params = { | ||
FunctionName: functionName, | ||
@@ -191,20 +185,19 @@ InvocationType: "RequestResponse", | ||
}; | ||
var invokePromise = _this.lambda.invoke(params).promise(); | ||
let invokePromise = this.lambda.invoke(params).promise(); | ||
invokePromise | ||
.then(function (data) { | ||
.then((data) => { | ||
resolve(data); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
}; | ||
LambdaAws.prototype.deleteFunction = function (functionName) { | ||
var _this = this; | ||
return new Promise(function (resolve, reject) { | ||
_this.lambda.deleteFunction({ "FunctionName": functionName }).promise() | ||
.then(function (data) { | ||
} | ||
deleteFunction(functionName) { | ||
return new Promise((resolve, reject) => { | ||
this.lambda.deleteFunction({ "FunctionName": functionName }).promise() | ||
.then((data) => { | ||
resolve(data); | ||
}) | ||
.catch(function (err) { | ||
.catch((err) => { | ||
if (err.code === "NoSuchEntity") { | ||
@@ -218,6 +211,5 @@ resolve(err.code); | ||
}); | ||
}; | ||
return LambdaAws; | ||
}()); | ||
} | ||
} | ||
exports.LambdaAws = LambdaAws; | ||
//# sourceMappingURL=lambda-aws.js.map |
"use strict"; | ||
var global_1 = require("../core/global"); | ||
var PropertiesReader = require("properties-reader"); | ||
var LambdaConfig = (function () { | ||
function LambdaConfig() { | ||
const global_1 = require("../core/global"); | ||
let PropertiesReader = require("properties-reader"); | ||
class LambdaConfig { | ||
static create() { | ||
let instance = new LambdaConfig(); | ||
return instance; | ||
} | ||
LambdaConfig.create = function () { | ||
var instance = new LambdaConfig(); | ||
return instance; | ||
}; | ||
LambdaConfig.defaultConfig = function () { | ||
static defaultConfig() { | ||
return { | ||
@@ -25,5 +23,5 @@ "lambdaDeploy": { | ||
}; | ||
}; | ||
LambdaConfig.prototype.initialize = function () { | ||
var awsConfig = null; | ||
} | ||
initialize() { | ||
let awsConfig = null; | ||
if (!global_1.Global.config().configuration.lambdaDeploy) { | ||
@@ -33,5 +31,5 @@ global_1.Global.config().configuration.lambdaDeploy = LambdaConfig.defaultConfig().lambdaDeploy; | ||
} | ||
var bstConfig = global_1.Global.config().configuration.lambdaDeploy; | ||
let bstConfig = global_1.Global.config().configuration.lambdaDeploy; | ||
try { | ||
var home = process.env[(process.platform === "win32") ? "USERPROFILE" : "HOME"]; | ||
let home = process.env[(process.platform === "win32") ? "USERPROFILE" : "HOME"]; | ||
awsConfig = PropertiesReader(home + "/.aws/config").append(home + "/.aws/credentials"); | ||
@@ -68,8 +66,7 @@ } | ||
this.EXCLUDE_GLOBS = bstConfig.excludeGlobs || ""; | ||
}; | ||
LambdaConfig.prototype.validate = function () { | ||
}; | ||
return LambdaConfig; | ||
}()); | ||
} | ||
validate() { | ||
} | ||
} | ||
exports.LambdaConfig = LambdaConfig; | ||
//# sourceMappingURL=lambda-config.js.map |
"use strict"; | ||
var fs = require("fs"); | ||
var os = require("os"); | ||
var path = require("path"); | ||
var async = require("async"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var aws = require("aws-sdk"); | ||
var exec = require("child_process").exec; | ||
var logger = "LambdaDeploy"; | ||
var LambdaDeploy = (function () { | ||
function LambdaDeploy() { | ||
const fs = require("fs"); | ||
const os = require("os"); | ||
const path = require("path"); | ||
const async = require("async"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const aws = require("aws-sdk"); | ||
const exec = require("child_process").exec; | ||
let logger = "LambdaDeploy"; | ||
class LambdaDeploy { | ||
constructor() { | ||
this.codeDirectory = function () { | ||
var epoch_time = +new Date(); | ||
let epoch_time = +new Date(); | ||
return os.tmpdir() + "/" + this.lambdaConfig.AWS_FUNCTION_NAME + "-" + epoch_time; | ||
}; | ||
this.nativeZipFiles = function (codeDirectory, callback) { | ||
var ms_since_epoch = new Date().getTime(); | ||
var filename = this.lambdaConfig.AWS_FUNCTION_NAME + "-" + ms_since_epoch + ".zip"; | ||
var zipfile = path.join(os.tmpdir(), filename); | ||
var cmd = "zip -r " + zipfile + " ."; | ||
let ms_since_epoch = new Date().getTime(); | ||
let filename = this.lambdaConfig.AWS_FUNCTION_NAME + "-" + ms_since_epoch + ".zip"; | ||
let zipfile = path.join(os.tmpdir(), filename); | ||
let cmd = "zip -r " + zipfile + " ."; | ||
exec(cmd, { | ||
@@ -28,3 +28,3 @@ cwd: codeDirectory, | ||
} | ||
var data = fs.readFileSync(zipfile); | ||
let data = fs.readFileSync(zipfile); | ||
callback(null, data); | ||
@@ -38,11 +38,11 @@ }); | ||
} | ||
LambdaDeploy.create = function (lambdaFolder, lambdaConfig) { | ||
var instance = new LambdaDeploy(); | ||
static create(lambdaFolder, lambdaConfig) { | ||
let instance = new LambdaDeploy(); | ||
instance.lambdaConfig = lambdaConfig; | ||
instance.lambdaFolder = lambdaFolder; | ||
return instance; | ||
}; | ||
LambdaDeploy.prototype.deploy = function (callback) { | ||
var self = this; | ||
var regions = this.lambdaConfig.AWS_REGION.split(","); | ||
} | ||
deploy(callback) { | ||
let self = this; | ||
let regions = this.lambdaConfig.AWS_REGION.split(","); | ||
this.archive(function (err, buffer) { | ||
@@ -53,3 +53,3 @@ if (err) { | ||
logging_helper_1.LoggingHelper.verbose(logger, "Reading zip file to memory"); | ||
var params = self.params(buffer); | ||
let params = self.params(buffer); | ||
async.map(regions, cb, function (err, results) { | ||
@@ -62,3 +62,3 @@ if (err) { | ||
console.log("Enter this ARN(s) on the Configuration tab of your skill:"); | ||
results.map(function (result) { | ||
results.map((result) => { | ||
console.log(); | ||
@@ -76,3 +76,3 @@ console.log("\t" + result.FunctionArn); | ||
self.logParams(params); | ||
var aws_security = { | ||
let aws_security = { | ||
accessKeyId: self.lambdaConfig.AWS_ACCESS_KEY_ID, | ||
@@ -83,3 +83,3 @@ secretAccessKey: self.lambdaConfig.AWS_SECRET_ACCESS_KEY, | ||
aws.config.update(aws_security); | ||
var lambda = new aws.Lambda({ | ||
let lambda = new aws.Lambda({ | ||
apiVersion: "2015-03-31" | ||
@@ -97,11 +97,11 @@ }); | ||
}); | ||
}; | ||
} | ||
; | ||
LambdaDeploy.prototype.logParams = function (params) { | ||
var buff = params.Code.ZipFile; | ||
logParams(params) { | ||
let buff = params.Code.ZipFile; | ||
params.Code.ZipFile = "<" + buff.length + " bytes>"; | ||
logging_helper_1.LoggingHelper.verbose(logger, JSON.stringify(params, null, 2)); | ||
params.Code.ZipFile = buff; | ||
}; | ||
LambdaDeploy.prototype.uploadExisting = function (lambda, params, callback) { | ||
} | ||
uploadExisting(lambda, params, callback) { | ||
return lambda.updateFunctionCode({ | ||
@@ -128,4 +128,4 @@ "FunctionName": params.FunctionName, | ||
}); | ||
}; | ||
LambdaDeploy.prototype.uploadNew = function (lambda, params, callback) { | ||
} | ||
uploadNew(lambda, params, callback) { | ||
return lambda.createFunction(params, function (err, functionData) { | ||
@@ -139,3 +139,3 @@ if (!err) { | ||
console.log("Waiting for AWS to propagate the changes"); | ||
setTimeout(function () { | ||
setTimeout(() => { | ||
return lambda.addPermission({ | ||
@@ -154,5 +154,5 @@ "FunctionName": params.FunctionName, | ||
}); | ||
}; | ||
LambdaDeploy.prototype.params = function (buffer) { | ||
var params = { | ||
} | ||
params(buffer) { | ||
let params = { | ||
FunctionName: this.lambdaConfig.AWS_FUNCTION_NAME, | ||
@@ -181,11 +181,11 @@ Code: { | ||
return params; | ||
}; | ||
} | ||
; | ||
LambdaDeploy.prototype.archive = function (callback) { | ||
archive(callback) { | ||
return this.lambdaConfig.PREBUILT_DIRECTORY | ||
? this.archivePrebuilt(callback) : this.buildAndArchive(callback); | ||
}; | ||
LambdaDeploy.prototype.buildAndArchive = function (callback) { | ||
var self = this; | ||
var codeDirectory = this.codeDirectory(); | ||
} | ||
buildAndArchive(callback) { | ||
let self = this; | ||
let codeDirectory = this.codeDirectory(); | ||
this.cleanDirectory(codeDirectory, function (err) { | ||
@@ -220,7 +220,7 @@ if (err) { | ||
}); | ||
}; | ||
LambdaDeploy.prototype.postInstallScript = function (codeDirectory, callback) { | ||
} | ||
postInstallScript(codeDirectory, callback) { | ||
callback(null); | ||
}; | ||
LambdaDeploy.prototype.npmInstall = function (codeDirectory, callback) { | ||
} | ||
npmInstall(codeDirectory, callback) { | ||
exec("npm -s install --production --prefix " + codeDirectory, function (err) { | ||
@@ -232,13 +232,13 @@ if (err) { | ||
}); | ||
}; | ||
LambdaDeploy.prototype.archivePrebuilt = function (callback) { | ||
} | ||
archivePrebuilt(callback) { | ||
callback(null); | ||
}; | ||
LambdaDeploy.prototype.copyFiles = function (src, dest, excludeNodeModules, callback) { | ||
var excludes = [".git*", "*.swp", ".editorconfig", "deploy.env", "*.log", "build/", ".DS_Store"]; | ||
var excludeGlobs = []; | ||
} | ||
copyFiles(src, dest, excludeNodeModules, callback) { | ||
let excludes = [".git*", "*.swp", ".editorconfig", "deploy.env", "*.log", "build/", ".DS_Store"]; | ||
let excludeGlobs = []; | ||
if (this.lambdaConfig.EXCLUDE_GLOBS) { | ||
excludeGlobs = this.lambdaConfig.EXCLUDE_GLOBS.split(" "); | ||
} | ||
var excludeArgs = excludeGlobs | ||
let excludeArgs = excludeGlobs | ||
.concat(excludes) | ||
@@ -253,3 +253,3 @@ .concat(excludeNodeModules ? ["node_modules"] : []) | ||
} | ||
var cmd = "rsync -rL " + excludeArgs + " " + src.trim() + "/ " + dest; | ||
let cmd = "rsync -rL " + excludeArgs + " " + src.trim() + "/ " + dest; | ||
exec(cmd, function (err, stdout, stderr) { | ||
@@ -262,4 +262,4 @@ if (err) { | ||
}); | ||
}; | ||
LambdaDeploy.prototype.cleanDirectory = function (codeDirectory, callback) { | ||
} | ||
cleanDirectory(codeDirectory, callback) { | ||
exec("rm -rf " + codeDirectory, function (err) { | ||
@@ -276,7 +276,6 @@ if (err) { | ||
}); | ||
}; | ||
} | ||
; | ||
return LambdaDeploy; | ||
}()); | ||
} | ||
exports.LambdaDeploy = LambdaDeploy; | ||
//# sourceMappingURL=lambda-deploy.js.map |
"use strict"; | ||
var fs = require("fs"); | ||
var http = require("http"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var node_util_1 = require("../core/node-util"); | ||
var Logger = "BST-LAMBDA"; | ||
var LambdaServer = (function () { | ||
function LambdaServer(file, port, verbose) { | ||
const fs = require("fs"); | ||
const http = require("http"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const node_util_1 = require("../core/node-util"); | ||
let Logger = "BST-LAMBDA"; | ||
class LambdaServer { | ||
constructor(file, port, verbose) { | ||
this.file = file; | ||
@@ -19,7 +19,7 @@ this.port = port; | ||
} | ||
LambdaServer.prototype.start = function (callback) { | ||
var self = this; | ||
var watchOptions = { "persistent": false, "recursive": true }; | ||
start(callback) { | ||
let self = this; | ||
let watchOptions = { "persistent": false, "recursive": true }; | ||
this.watcher = fs.watch(process.cwd(), watchOptions, function (event, filename) { | ||
var exclude = false; | ||
let exclude = false; | ||
if (filename.indexOf("node_modules") !== -1) { | ||
@@ -46,3 +46,3 @@ exclude = true; | ||
self.requests.push(request); | ||
var requestBody = ""; | ||
let requestBody = ""; | ||
request.on("data", function (chunk) { | ||
@@ -66,8 +66,7 @@ requestBody += chunk.toString(); | ||
}); | ||
}; | ||
LambdaServer.prototype.stop = function (onStop) { | ||
} | ||
stop(onStop) { | ||
this.watcher.close(); | ||
var request = null; | ||
for (var _i = 0, _a = this.requests; _i < _a.length; _i++) { | ||
request = _a[_i]; | ||
let request = null; | ||
for (request of this.requests) { | ||
try { | ||
@@ -84,5 +83,5 @@ request.socket.end(); | ||
}); | ||
}; | ||
LambdaServer.prototype.invoke = function (request, body, response) { | ||
var path = this.file; | ||
} | ||
invoke(request, body, response) { | ||
let path = this.file; | ||
if (!path.startsWith("/")) { | ||
@@ -96,5 +95,5 @@ path = [process.cwd(), this.file].join("/"); | ||
} | ||
var context = new LambdaContext(request, response, this.verbose); | ||
const context = new LambdaContext(request, response, this.verbose); | ||
try { | ||
var bodyJSON = JSON.parse(body); | ||
const bodyJSON = JSON.parse(body); | ||
if (this.verbose) { | ||
@@ -111,8 +110,7 @@ console.log("Request:"); | ||
} | ||
}; | ||
return LambdaServer; | ||
}()); | ||
} | ||
} | ||
exports.LambdaServer = LambdaServer; | ||
var LambdaContext = (function () { | ||
function LambdaContext(request, response, verbose) { | ||
class LambdaContext { | ||
constructor(request, response, verbose) { | ||
this.request = request; | ||
@@ -132,15 +130,15 @@ this.response = response; | ||
} | ||
LambdaContext.prototype.fail = function (error) { | ||
fail(error) { | ||
this.done(error, null); | ||
}; | ||
LambdaContext.prototype.succeed = function (body) { | ||
} | ||
succeed(body) { | ||
this.done(null, body); | ||
}; | ||
LambdaContext.prototype.getRemainingTimeMillis = function () { | ||
} | ||
getRemainingTimeMillis() { | ||
return -1; | ||
}; | ||
LambdaContext.prototype.done = function (error, body) { | ||
var statusCode = 200; | ||
var contentType = "application/json"; | ||
var bodyString = null; | ||
} | ||
done(error, body) { | ||
let statusCode = 200; | ||
let contentType = "application/json"; | ||
let bodyString = null; | ||
if (error === null) { | ||
@@ -162,5 +160,4 @@ bodyString = JSON.stringify(body); | ||
this.response.end(new Buffer(bodyString)); | ||
}; | ||
return LambdaContext; | ||
}()); | ||
} | ||
} | ||
//# sourceMappingURL=lambda-server.js.map |
"use strict"; | ||
var net = require("net"); | ||
var global_1 = require("../core/global"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var Logger = "TCP-CLIENT"; | ||
var TCPClient = (function () { | ||
function TCPClient(id) { | ||
const net = require("net"); | ||
const global_1 = require("../core/global"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
let Logger = "TCP-CLIENT"; | ||
class TCPClient { | ||
constructor(id) { | ||
this.id = id; | ||
} | ||
TCPClient.prototype.transmit = function (host, port, data, callback) { | ||
var self = this; | ||
var client = new net.Socket(); | ||
transmit(host, port, data, callback) { | ||
let self = this; | ||
let client = new net.Socket(); | ||
logging_helper_1.LoggingHelper.info(Logger, "Forwarding " + host + ":" + port); | ||
@@ -35,8 +35,7 @@ client.on("error", function (e) { | ||
}); | ||
}; | ||
TCPClient.prototype.close = function () { | ||
}; | ||
return TCPClient; | ||
}()); | ||
} | ||
close() { | ||
} | ||
} | ||
exports.TCPClient = TCPClient; | ||
//# sourceMappingURL=tcp-client.js.map |
"use strict"; | ||
var url = require("url"); | ||
var global_1 = require("../core/global"); | ||
var URLMangler = (function () { | ||
function URLMangler() { | ||
const url = require("url"); | ||
const global_1 = require("../core/global"); | ||
class URLMangler { | ||
static mangle(urlString, nodeID) { | ||
let urlValue = url.parse(urlString, true, false); | ||
return URLMangler.mangleJustPath(urlValue.path, nodeID); | ||
} | ||
URLMangler.mangle = function (urlString, nodeID) { | ||
var urlValue = url.parse(urlString, true, false); | ||
return URLMangler.mangleJustPath(urlValue.path, nodeID); | ||
}; | ||
URLMangler.mangleJustPath = function (path, nodeID) { | ||
var newUrl = "https://"; | ||
static mangleJustPath(path, nodeID) { | ||
let newUrl = "https://"; | ||
newUrl += global_1.Global.BespokeServerHost; | ||
@@ -23,12 +21,11 @@ newUrl += path; | ||
return newUrl; | ||
}; | ||
URLMangler.mangleNoPath = function (nodeID) { | ||
var newUrl = "https://"; | ||
} | ||
static mangleNoPath(nodeID) { | ||
let newUrl = "https://"; | ||
newUrl += global_1.Global.BespokeServerHost; | ||
newUrl += "?node-id=" + nodeID; | ||
return newUrl; | ||
}; | ||
return URLMangler; | ||
}()); | ||
} | ||
} | ||
exports.URLMangler = URLMangler; | ||
//# sourceMappingURL=url-mangler.js.map |
"use strict"; | ||
var string_util_1 = require("./string-util"); | ||
var BufferUtil = (function () { | ||
function BufferUtil() { | ||
const string_util_1 = require("./string-util"); | ||
class BufferUtil { | ||
static prettyPrint(buffer) { | ||
let s = buffer.toString(); | ||
return string_util_1.StringUtil.prettyPrint(s); | ||
} | ||
BufferUtil.prettyPrint = function (buffer) { | ||
var s = buffer.toString(); | ||
return string_util_1.StringUtil.prettyPrint(s); | ||
}; | ||
BufferUtil.fromString = function (s) { | ||
static fromString(s) { | ||
return new Buffer(s); | ||
}; | ||
BufferUtil.scan = function (body, sequence) { | ||
var index = -1; | ||
for (var i = 0; i < body.length; i++) { | ||
var val = body[i]; | ||
} | ||
static scan(body, sequence) { | ||
let index = -1; | ||
for (let i = 0; i < body.length; i++) { | ||
let val = body[i]; | ||
if (val === sequence[0]) { | ||
var match_1 = true; | ||
for (var ii = 1; ii < sequence.length; ii++) { | ||
var bodyIndex = i + ii; | ||
let match = true; | ||
for (let ii = 1; ii < sequence.length; ii++) { | ||
let bodyIndex = i + ii; | ||
if (bodyIndex >= body.length) { | ||
match_1 = false; | ||
match = false; | ||
break; | ||
@@ -27,7 +25,7 @@ } | ||
if (val !== sequence[ii]) { | ||
match_1 = false; | ||
match = false; | ||
break; | ||
} | ||
} | ||
if (match_1) { | ||
if (match) { | ||
index = i; | ||
@@ -39,6 +37,5 @@ break; | ||
return index; | ||
}; | ||
return BufferUtil; | ||
}()); | ||
} | ||
} | ||
exports.BufferUtil = BufferUtil; | ||
//# sourceMappingURL=buffer-util.js.map |
"use strict"; | ||
var fs = require("fs"); | ||
var FileUtil = (function () { | ||
function FileUtil() { | ||
} | ||
FileUtil.copyFile = function (source, target, callback) { | ||
var cbCalled = false; | ||
var readStream = fs.createReadStream(source); | ||
const fs = require("fs"); | ||
class FileUtil { | ||
static copyFile(source, target, callback) { | ||
let cbCalled = false; | ||
let readStream = fs.createReadStream(source); | ||
readStream.on("error", function (error) { | ||
done(error); | ||
}); | ||
var writeStream = fs.createWriteStream(target); | ||
let writeStream = fs.createWriteStream(target); | ||
writeStream.on("error", function (error) { | ||
@@ -28,4 +26,4 @@ done(error); | ||
} | ||
}; | ||
FileUtil.readFile = function (source, callback) { | ||
} | ||
static readFile(source, callback) { | ||
fs.readFile(source, null, function (error, data) { | ||
@@ -39,6 +37,5 @@ if (error !== null) { | ||
}); | ||
}; | ||
return FileUtil; | ||
}()); | ||
} | ||
} | ||
exports.FileUtil = FileUtil; | ||
//# sourceMappingURL=file-util.js.map |
"use strict"; | ||
var logging_helper_1 = require("./logging-helper"); | ||
var bst_config_1 = require("../client/bst-config"); | ||
var bst_config_2 = require("../client/bst-config"); | ||
var chalk = require("chalk"); | ||
var Global = (function () { | ||
function Global() { | ||
} | ||
Global.initializeCLI = function () { | ||
var originalError = console.error; | ||
const logging_helper_1 = require("./logging-helper"); | ||
const bst_config_1 = require("../client/bst-config"); | ||
const bst_config_2 = require("../client/bst-config"); | ||
const chalk = require("chalk"); | ||
class Global { | ||
static initializeCLI() { | ||
let originalError = console.error; | ||
console.error = function (message) { | ||
@@ -21,7 +19,7 @@ if (message !== undefined) { | ||
Global._configuration = bst_config_1.BSTConfig.load(); | ||
}; | ||
Global.cli = function () { | ||
} | ||
static cli() { | ||
return Global._cli; | ||
}; | ||
Global.config = function () { | ||
} | ||
static config() { | ||
if (Global._configuration === null) { | ||
@@ -32,7 +30,7 @@ Global.initialize(false); | ||
return Global._configuration; | ||
}; | ||
Global.running = function () { | ||
} | ||
static running() { | ||
return bst_config_2.BSTProcess.running(); | ||
}; | ||
Global.initialize = function (cli) { | ||
} | ||
static initialize(cli) { | ||
if (cli !== undefined && cli !== null) { | ||
@@ -42,15 +40,14 @@ Global._cli = cli; | ||
logging_helper_1.LoggingHelper.initialize(cli); | ||
}; | ||
Global.version = function () { | ||
var packageInfo = require("../../package.json"); | ||
} | ||
static version() { | ||
let packageInfo = require("../../package.json"); | ||
return packageInfo.version; | ||
}; | ||
Global.MessageDelimiter = "4772616365"; | ||
Global.MessageIDLength = 13; | ||
Global.KeepAliveMessage = "KEEPALIVE"; | ||
Global.BespokeServerHost = "proxy.bespoken.tools"; | ||
Global._configuration = null; | ||
Global._cli = false; | ||
return Global; | ||
}()); | ||
} | ||
} | ||
Global.MessageDelimiter = "4772616365"; | ||
Global.MessageIDLength = 13; | ||
Global.KeepAliveMessage = "KEEPALIVE"; | ||
Global.BespokeServerHost = "proxy.bespoken.tools"; | ||
Global._configuration = null; | ||
Global._cli = false; | ||
exports.Global = Global; | ||
@@ -57,0 +54,0 @@ (function (NetworkErrorType) { |
"use strict"; | ||
var buffer_util_1 = require("./buffer-util"); | ||
var HTTPBuffer = (function () { | ||
function HTTPBuffer() { | ||
const buffer_util_1 = require("./buffer-util"); | ||
class HTTPBuffer { | ||
constructor() { | ||
this._rawContent = buffer_util_1.BufferUtil.fromString(""); | ||
this._complete = false; | ||
} | ||
HTTPBuffer.prototype.append = function (data) { | ||
append(data) { | ||
this._rawContent = Buffer.concat([this._rawContent, data]); | ||
if (this._headers === undefined) { | ||
var endIndex = buffer_util_1.BufferUtil.scan(this._rawContent, [13, 10, 13, 10]); | ||
let endIndex = buffer_util_1.BufferUtil.scan(this._rawContent, [13, 10, 13, 10]); | ||
if (endIndex !== -1) { | ||
var headerBuffer = this._rawContent.slice(0, endIndex); | ||
let headerBuffer = this._rawContent.slice(0, endIndex); | ||
this.parseHeaders(headerBuffer.toString()); | ||
if (endIndex + 4 < this._rawContent.length) { | ||
var bodyPart = this._rawContent.slice((endIndex + 4)); | ||
let bodyPart = this._rawContent.slice((endIndex + 4)); | ||
this.appendBody(bodyPart); | ||
@@ -24,9 +24,9 @@ } | ||
} | ||
}; | ||
HTTPBuffer.prototype.complete = function () { | ||
} | ||
complete() { | ||
if (!this._complete) { | ||
if (this._headers !== undefined) { | ||
var chunked = this.hasHeader("Transfer-Encoding") && this.header("Transfer-Encoding").toLowerCase() === "chunked"; | ||
let chunked = this.hasHeader("Transfer-Encoding") && this.header("Transfer-Encoding").toLowerCase() === "chunked"; | ||
if (chunked && this._rawBody !== undefined) { | ||
var chunks = this.parseChunks(); | ||
let chunks = this.parseChunks(); | ||
if (chunks !== null && chunks.length > 0 && chunks[chunks.length - 1].lastChunk()) { | ||
@@ -38,7 +38,7 @@ this._chunks = chunks; | ||
else if (this._rawBody !== undefined) { | ||
var length_1 = this._rawBody.length; | ||
let length = this._rawBody.length; | ||
if (this.hasHeader("Content-Length")) { | ||
length_1 = parseInt(this.header("Content-Length")); | ||
length = parseInt(this.header("Content-Length")); | ||
} | ||
this._complete = this._rawBody.length === length_1; | ||
this._complete = this._rawBody.length === length; | ||
} | ||
@@ -48,5 +48,5 @@ } | ||
return this._complete; | ||
}; | ||
HTTPBuffer.prototype.header = function (headerKey) { | ||
var value = null; | ||
} | ||
header(headerKey) { | ||
let value = null; | ||
if (this._headers !== undefined && this.hasHeader(headerKey)) { | ||
@@ -56,17 +56,17 @@ value = this._headers[headerKey]; | ||
return value; | ||
}; | ||
HTTPBuffer.prototype.hasHeader = function (headerKey) { | ||
} | ||
hasHeader(headerKey) { | ||
return headerKey in this._headers; | ||
}; | ||
HTTPBuffer.prototype.method = function () { | ||
} | ||
method() { | ||
return this._method; | ||
}; | ||
HTTPBuffer.prototype.uri = function () { | ||
} | ||
uri() { | ||
return this._uri; | ||
}; | ||
HTTPBuffer.prototype.statusCode = function () { | ||
} | ||
statusCode() { | ||
return this._statusCode; | ||
}; | ||
HTTPBuffer.prototype.chunked = function () { | ||
var chunked = false; | ||
} | ||
chunked() { | ||
let chunked = false; | ||
if (this.complete()) { | ||
@@ -78,16 +78,15 @@ if (this._chunks !== undefined) { | ||
return chunked; | ||
}; | ||
HTTPBuffer.prototype.raw = function () { | ||
} | ||
raw() { | ||
return this._rawContent; | ||
}; | ||
HTTPBuffer.prototype.isJSON = function () { | ||
} | ||
isJSON() { | ||
return this.hasHeader("Content-Type") && this.header("Content-Type") === "application/json"; | ||
}; | ||
HTTPBuffer.prototype.body = function () { | ||
var body; | ||
} | ||
body() { | ||
let body; | ||
if (this.complete()) { | ||
body = buffer_util_1.BufferUtil.fromString(""); | ||
if (this.chunked()) { | ||
for (var _i = 0, _a = this._chunks; _i < _a.length; _i++) { | ||
var chunk = _a[_i]; | ||
for (let chunk of this._chunks) { | ||
body = Buffer.concat([body, chunk.body]); | ||
@@ -101,5 +100,5 @@ } | ||
return body; | ||
}; | ||
HTTPBuffer.prototype.bodyAsJSON = function () { | ||
var json; | ||
} | ||
bodyAsJSON() { | ||
let json; | ||
if (this.body() !== undefined) { | ||
@@ -109,8 +108,8 @@ json = JSON.parse(this.body().toString()); | ||
return json; | ||
}; | ||
HTTPBuffer.prototype.parseChunks = function () { | ||
var chunks = []; | ||
var body = this._rawBody; | ||
} | ||
parseChunks() { | ||
let chunks = []; | ||
let body = this._rawBody; | ||
while (true) { | ||
var chunk = HTTPChunk.parse(body); | ||
let chunk = HTTPChunk.parse(body); | ||
if (chunk !== null) { | ||
@@ -128,4 +127,4 @@ chunks.push(chunk); | ||
return chunks; | ||
}; | ||
HTTPBuffer.prototype.appendBody = function (bodyPart) { | ||
} | ||
appendBody(bodyPart) { | ||
if (this._rawBody === undefined) { | ||
@@ -135,9 +134,9 @@ this._rawBody = buffer_util_1.BufferUtil.fromString(""); | ||
this._rawBody = Buffer.concat([this._rawBody, bodyPart]); | ||
}; | ||
HTTPBuffer.prototype.parseHeaders = function (headersString) { | ||
} | ||
parseHeaders(headersString) { | ||
this._headers = {}; | ||
var lines = headersString.split("\n"); | ||
let lines = headersString.split("\n"); | ||
if (lines[0].startsWith("HTTP")) { | ||
this._statusLine = lines[0]; | ||
var statusLineParts = this._statusLine.split(" "); | ||
let statusLineParts = this._statusLine.split(" "); | ||
this._statusCode = parseInt(statusLineParts[1]); | ||
@@ -147,55 +146,54 @@ } | ||
this._requestLine = lines[0]; | ||
var requestLineParts = this._requestLine.split(" "); | ||
let requestLineParts = this._requestLine.split(" "); | ||
this._method = requestLineParts[0]; | ||
this._uri = requestLineParts[1]; | ||
} | ||
for (var i = 1; i < lines.length; i++) { | ||
var headerLine = lines[i]; | ||
var headerParts = headerLine.split(":"); | ||
var key = headerParts[0]; | ||
for (let i = 1; i < lines.length; i++) { | ||
let headerLine = lines[i]; | ||
let headerParts = headerLine.split(":"); | ||
let key = headerParts[0]; | ||
this._headers[key] = headerParts[1].trim(); | ||
} | ||
}; | ||
return HTTPBuffer; | ||
}()); | ||
} | ||
} | ||
exports.HTTPBuffer = HTTPBuffer; | ||
var HTTPChunk = (function () { | ||
function HTTPChunk(body, lengthString) { | ||
class HTTPChunk { | ||
constructor(body, lengthString) { | ||
this.body = body; | ||
this.lengthString = lengthString; | ||
} | ||
HTTPChunk.prototype.length = function () { | ||
length() { | ||
return parseInt(this.lengthString, 16); | ||
}; | ||
HTTPChunk.prototype.headerLength = function () { | ||
} | ||
headerLength() { | ||
return (this.lengthString).length + 2; | ||
}; | ||
HTTPChunk.prototype.lengthWithHeaderAndTrailer = function () { | ||
} | ||
lengthWithHeaderAndTrailer() { | ||
return this.length() + this.headerLength() + 2; | ||
}; | ||
HTTPChunk.prototype.lastChunk = function () { | ||
} | ||
lastChunk() { | ||
return (this.length() === 0); | ||
}; | ||
HTTPChunk.parse = function (httpBody) { | ||
var chunkLengthString = HTTPChunk.parseLength(httpBody); | ||
} | ||
static parse(httpBody) { | ||
let chunkLengthString = HTTPChunk.parseLength(httpBody); | ||
if (chunkLengthString === null) { | ||
return null; | ||
} | ||
var chunkLength = parseInt(chunkLengthString, 16); | ||
var chunkStartIndex = chunkLengthString.length + 2; | ||
var endIndex = chunkStartIndex + chunkLength; | ||
let chunkLength = parseInt(chunkLengthString, 16); | ||
let chunkStartIndex = chunkLengthString.length + 2; | ||
let endIndex = chunkStartIndex + chunkLength; | ||
if (httpBody.length < endIndex) { | ||
return null; | ||
} | ||
var chunkBody = httpBody.slice(chunkStartIndex, chunkStartIndex + chunkLength); | ||
let chunkBody = httpBody.slice(chunkStartIndex, chunkStartIndex + chunkLength); | ||
return new HTTPChunk(chunkBody, chunkLengthString); | ||
}; | ||
HTTPChunk.parseLength = function (httpBody) { | ||
var index = buffer_util_1.BufferUtil.scan(httpBody, [13, 10]); | ||
} | ||
static parseLength(httpBody) { | ||
let index = buffer_util_1.BufferUtil.scan(httpBody, [13, 10]); | ||
if (index === -1) { | ||
return null; | ||
} | ||
var chunkLengthString = ""; | ||
for (var i = 0; i < index; i++) { | ||
var char = String.fromCharCode(httpBody[i]); | ||
let chunkLengthString = ""; | ||
for (let i = 0; i < index; i++) { | ||
let char = String.fromCharCode(httpBody[i]); | ||
if (isNaN(parseInt(char, 16))) { | ||
@@ -207,6 +205,5 @@ throw new RangeError("Invalid character found in chunk length - something went wrong! " + char); | ||
return chunkLengthString; | ||
}; | ||
return HTTPChunk; | ||
}()); | ||
} | ||
} | ||
exports.HTTPChunk = HTTPChunk; | ||
//# sourceMappingURL=http-buffer.js.map |
"use strict"; | ||
var http = require("http"); | ||
var buffer_util_1 = require("./buffer-util"); | ||
var HTTPClient = (function () { | ||
function HTTPClient() { | ||
} | ||
HTTPClient.prototype.post = function (host, port, path, data, callback) { | ||
var post_options = { | ||
const http = require("http"); | ||
const buffer_util_1 = require("./buffer-util"); | ||
class HTTPClient { | ||
post(host, port, path, data, callback) { | ||
let post_options = { | ||
agent: false, | ||
@@ -19,4 +17,4 @@ host: host, | ||
}; | ||
var responseData = new Buffer(""); | ||
var post_req = http.request(post_options, function (response) { | ||
let responseData = new Buffer(""); | ||
let post_req = http.request(post_options, function (response) { | ||
response.on("data", function (chunk) { | ||
@@ -38,5 +36,5 @@ responseData = Buffer.concat([responseData, chunk]); | ||
post_req.end(); | ||
}; | ||
HTTPClient.prototype.get = function (host, port, path, callback) { | ||
var options = { | ||
} | ||
get(host, port, path, callback) { | ||
let options = { | ||
host: host, | ||
@@ -47,4 +45,4 @@ port: port, | ||
}; | ||
var responseData = new Buffer(""); | ||
var request = http.request(options, function (response) { | ||
let responseData = new Buffer(""); | ||
let request = http.request(options, function (response) { | ||
response.on("data", function (chunk) { | ||
@@ -60,6 +58,5 @@ responseData = Buffer.concat([responseData, chunk]); | ||
request.end(); | ||
}; | ||
return HTTPClient; | ||
}()); | ||
} | ||
} | ||
exports.HTTPClient = HTTPClient; | ||
//# sourceMappingURL=http-client.js.map |
"use strict"; | ||
var HTTPHelper = (function () { | ||
function HTTPHelper() { | ||
} | ||
HTTPHelper.format = function (statusCode, body) { | ||
var statusMessage = "OK"; | ||
class HTTPHelper { | ||
static format(statusCode, body) { | ||
let statusMessage = "OK"; | ||
if (statusCode === 400) { | ||
@@ -13,15 +11,14 @@ statusMessage = "Bad Request"; | ||
} | ||
var responseString = "HTTP/1.0 " + statusCode + " " + statusMessage + "\r\n"; | ||
let responseString = "HTTP/1.0 " + statusCode + " " + statusMessage + "\r\n"; | ||
responseString += "Content-Length: " + body.length + "\r\n\r\n"; | ||
responseString += body; | ||
return responseString; | ||
}; | ||
HTTPHelper.respond = function (socket, statusCode, body) { | ||
var s = HTTPHelper.format(statusCode, body); | ||
} | ||
static respond(socket, statusCode, body) { | ||
let s = HTTPHelper.format(statusCode, body); | ||
socket.write(s); | ||
socket.end(); | ||
}; | ||
return HTTPHelper; | ||
}()); | ||
} | ||
} | ||
exports.HTTPHelper = HTTPHelper; | ||
//# sourceMappingURL=http-helper.js.map |
"use strict"; | ||
var winston = require("winston"); | ||
var string_util_1 = require("./string-util"); | ||
var LoggingHelper = (function () { | ||
function LoggingHelper() { | ||
} | ||
LoggingHelper.setVerbose = function (enableVerbose) { | ||
const winston = require("winston"); | ||
const string_util_1 = require("./string-util"); | ||
class LoggingHelper { | ||
static setVerbose(enableVerbose) { | ||
LoggingHelper.verboseEnabled = enableVerbose; | ||
@@ -15,20 +13,20 @@ if (LoggingHelper.verboseEnabled) { | ||
} | ||
}; | ||
LoggingHelper.debug = function (logger, message) { | ||
} | ||
static debug(logger, message) { | ||
LoggingHelper.log("debug", logger, message); | ||
}; | ||
LoggingHelper.verbose = function (logger, message) { | ||
} | ||
static verbose(logger, message) { | ||
LoggingHelper.log("verbose", logger, message); | ||
}; | ||
LoggingHelper.info = function (logger, message) { | ||
} | ||
static info(logger, message) { | ||
LoggingHelper.log("info", logger, message); | ||
}; | ||
LoggingHelper.warn = function (logger, message) { | ||
} | ||
static warn(logger, message) { | ||
LoggingHelper.log("warn", logger, message); | ||
}; | ||
LoggingHelper.error = function (logger, message) { | ||
} | ||
static error(logger, message) { | ||
LoggingHelper.log("error", logger, message); | ||
}; | ||
LoggingHelper.log = function (level, logger, message) { | ||
var loggerString = string_util_1.StringUtil.rpad(logger, " ", 10).substr(0, 10); | ||
} | ||
static log(level, logger, message) { | ||
let loggerString = string_util_1.StringUtil.rpad(logger, " ", 10).substr(0, 10); | ||
if (LoggingHelper.cli) { | ||
@@ -40,4 +38,4 @@ winston.log(level, message); | ||
} | ||
}; | ||
LoggingHelper.initialize = function (cli) { | ||
} | ||
static initialize(cli) { | ||
LoggingHelper.cli = cli; | ||
@@ -57,4 +55,4 @@ winston.clear(); | ||
} | ||
}; | ||
LoggingHelper.formatter = function (options) { | ||
} | ||
static formatter(options) { | ||
return new Date().toISOString() + " " | ||
@@ -65,5 +63,5 @@ + options.level.toUpperCase() + " " | ||
+ JSON.stringify(options.meta) : ""); | ||
}; | ||
LoggingHelper.cliFormatter = function (options) { | ||
var level = options.level.toUpperCase(); | ||
} | ||
static cliFormatter(options) { | ||
let level = options.level.toUpperCase(); | ||
if (level === "VERBOSE") { | ||
@@ -77,9 +75,8 @@ level = "VERB"; | ||
+ JSON.stringify(options.meta) : ""); | ||
}; | ||
LoggingHelper.cli = false; | ||
LoggingHelper.verboseEnabled = false; | ||
LoggingHelper.logger = null; | ||
return LoggingHelper; | ||
}()); | ||
} | ||
} | ||
LoggingHelper.cli = false; | ||
LoggingHelper.verboseEnabled = false; | ||
LoggingHelper.logger = null; | ||
exports.LoggingHelper = LoggingHelper; | ||
//# sourceMappingURL=logging-helper.js.map |
"use strict"; | ||
var NodeUtil = (function () { | ||
function NodeUtil() { | ||
} | ||
NodeUtil.load = function (file) { | ||
class NodeUtil { | ||
static load(file) { | ||
NodeUtil.resetCache(); | ||
return require(file); | ||
}; | ||
NodeUtil.run = function (file) { | ||
} | ||
static run(file) { | ||
NodeUtil.requireClean(file); | ||
}; | ||
NodeUtil.requireClean = function (file) { | ||
} | ||
static requireClean(file) { | ||
delete require.cache[require.resolve(file)]; | ||
return require(file); | ||
}; | ||
NodeUtil.resetCache = function () { | ||
var directory = process.cwd(); | ||
for (var _i = 0, _a = Object.keys(require.cache); _i < _a.length; _i++) { | ||
var file = _a[_i]; | ||
} | ||
static resetCache() { | ||
let directory = process.cwd(); | ||
for (let file of Object.keys(require.cache)) { | ||
if (file.startsWith(directory) | ||
@@ -25,6 +22,5 @@ && file.indexOf("node_modules") === -1) { | ||
} | ||
}; | ||
return NodeUtil; | ||
}()); | ||
} | ||
} | ||
exports.NodeUtil = NodeUtil; | ||
//# sourceMappingURL=node-util.js.map |
"use strict"; | ||
var global_1 = require("./global"); | ||
var string_util_1 = require("./string-util"); | ||
var logging_helper_1 = require("./logging-helper"); | ||
var net = require("net"); | ||
var Logger = "SOCKET"; | ||
var SocketHandler = (function () { | ||
function SocketHandler(socket, onMessage) { | ||
const global_1 = require("./global"); | ||
const string_util_1 = require("./string-util"); | ||
const logging_helper_1 = require("./logging-helper"); | ||
const net = require("net"); | ||
let Logger = "SOCKET"; | ||
class SocketHandler { | ||
constructor(socket, onMessage) { | ||
this.socket = socket; | ||
@@ -14,3 +14,3 @@ this.onMessage = onMessage; | ||
this.connected = true; | ||
var self = this; | ||
let self = this; | ||
this.onDataCallback = function (data) { | ||
@@ -36,5 +36,5 @@ self.handleData(data.toString()); | ||
} | ||
SocketHandler.connect = function (host, port, onConnect, onMessage) { | ||
var socket = new net.Socket(); | ||
var handler = new SocketHandler(socket, onMessage); | ||
static connect(host, port, onConnect, onMessage) { | ||
let socket = new net.Socket(); | ||
let handler = new SocketHandler(socket, onMessage); | ||
handler.connected = false; | ||
@@ -51,17 +51,17 @@ socket.connect(port, host, function () { | ||
return handler; | ||
}; | ||
SocketHandler.prototype.handleData = function (dataString) { | ||
} | ||
handleData(dataString) { | ||
if (dataString !== null) { | ||
this.buffer += dataString; | ||
} | ||
var delimiterIndex = this.buffer.indexOf(global_1.Global.MessageDelimiter); | ||
let delimiterIndex = this.buffer.indexOf(global_1.Global.MessageDelimiter); | ||
if (delimiterIndex > -1) { | ||
var messageIDIndex = delimiterIndex - global_1.Global.MessageIDLength; | ||
var badMessage = false; | ||
let messageIDIndex = delimiterIndex - global_1.Global.MessageIDLength; | ||
let badMessage = false; | ||
if (messageIDIndex < 0) { | ||
badMessage = true; | ||
} | ||
var message = this.buffer.substring(0, messageIDIndex); | ||
var messageIDString = this.buffer.substring(delimiterIndex - global_1.Global.MessageIDLength, delimiterIndex); | ||
var messageID = parseInt(messageIDString); | ||
let message = this.buffer.substring(0, messageIDIndex); | ||
let messageIDString = this.buffer.substring(delimiterIndex - global_1.Global.MessageIDLength, delimiterIndex); | ||
let messageID = parseInt(messageIDString); | ||
if (isNaN(messageID) || (messageID + "").length < 13) { | ||
@@ -82,4 +82,4 @@ badMessage = true; | ||
} | ||
}; | ||
SocketHandler.prototype.send = function (message, messageID) { | ||
} | ||
send(message, messageID) { | ||
if (this.socket === null) { | ||
@@ -95,7 +95,7 @@ logging_helper_1.LoggingHelper.warn(Logger, "Writing message to closed socket: " + messageID); | ||
this.socket.write(message, null); | ||
}; | ||
SocketHandler.prototype.remoteAddress = function () { | ||
} | ||
remoteAddress() { | ||
return this.socket.remoteAddress; | ||
}; | ||
SocketHandler.prototype.remoteEndPoint = function () { | ||
} | ||
remoteEndPoint() { | ||
if (this.socket === null) { | ||
@@ -105,4 +105,4 @@ return ""; | ||
return this.socket.remoteAddress + ":" + this.socket.remotePort; | ||
}; | ||
SocketHandler.prototype.disconnect = function () { | ||
} | ||
disconnect() { | ||
if (this.isOpen()) { | ||
@@ -112,9 +112,8 @@ this.socket.end(); | ||
} | ||
}; | ||
SocketHandler.prototype.isOpen = function () { | ||
} | ||
isOpen() { | ||
return this.socket != null; | ||
}; | ||
return SocketHandler; | ||
}()); | ||
} | ||
} | ||
exports.SocketHandler = SocketHandler; | ||
//# sourceMappingURL=socket-handler.js.map |
"use strict"; | ||
var StringUtil = (function () { | ||
function StringUtil() { | ||
} | ||
StringUtil.replaceAll = function (s, val, newVal) { | ||
class StringUtil { | ||
static replaceAll(s, val, newVal) { | ||
while (s.indexOf(val) !== -1) { | ||
@@ -10,9 +8,9 @@ s = s.replace(val, newVal); | ||
return s; | ||
}; | ||
StringUtil.prettyPrint = function (bufferString) { | ||
var s = StringUtil.replaceAll(bufferString, "\r\n", "\\n"); | ||
} | ||
static prettyPrint(bufferString) { | ||
let s = StringUtil.replaceAll(bufferString, "\r\n", "\\n"); | ||
s = StringUtil.replaceAll(s, "\n", "\\n"); | ||
return s; | ||
}; | ||
StringUtil.prettyPrintJSON = function (jsonString) { | ||
} | ||
static prettyPrintJSON(jsonString) { | ||
try { | ||
@@ -24,5 +22,5 @@ return JSON.stringify(JSON.parse(jsonString), null, 2); | ||
} | ||
}; | ||
StringUtil.rpad = function (s, padString, length) { | ||
var str = s; | ||
} | ||
static rpad(s, padString, length) { | ||
let str = s; | ||
while (str.length < length) | ||
@@ -34,7 +32,6 @@ str = str + padString; | ||
return str; | ||
}; | ||
StringUtil.isIn = function (input, values) { | ||
var match = false; | ||
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { | ||
var s = values_1[_i]; | ||
} | ||
static isIn(input, values) { | ||
let match = false; | ||
for (let s of values) { | ||
if (input === s) { | ||
@@ -46,6 +43,5 @@ match = true; | ||
return match; | ||
}; | ||
return StringUtil; | ||
}()); | ||
} | ||
} | ||
exports.StringUtil = StringUtil; | ||
//# sourceMappingURL=string-util.js.map |
"use strict"; | ||
var querystring = require("querystring"); | ||
var buffer_util_1 = require("./buffer-util"); | ||
var WebhookRequest = (function () { | ||
function WebhookRequest(sourceSocket) { | ||
const querystring = require("querystring"); | ||
const buffer_util_1 = require("./buffer-util"); | ||
class WebhookRequest { | ||
constructor(sourceSocket) { | ||
this.sourceSocket = sourceSocket; | ||
@@ -15,18 +15,18 @@ this.queryParameters = {}; | ||
} | ||
WebhookRequest.fromString = function (sourceSocket, payload, id) { | ||
var webhookRequest = new WebhookRequest(sourceSocket); | ||
static fromString(sourceSocket, payload, id) { | ||
let webhookRequest = new WebhookRequest(sourceSocket); | ||
webhookRequest.append(buffer_util_1.BufferUtil.fromString(payload)); | ||
webhookRequest.requestID = id; | ||
return webhookRequest; | ||
}; | ||
WebhookRequest.prototype.append = function (data) { | ||
} | ||
append(data) { | ||
this.rawContents = Buffer.concat([this.rawContents, data]); | ||
if (this.headers == null) { | ||
this.headers = {}; | ||
var contentsString = this.rawContents.toString(); | ||
var endIndex = contentsString.indexOf("\r\n\r\n"); | ||
let contentsString = this.rawContents.toString(); | ||
let endIndex = contentsString.indexOf("\r\n\r\n"); | ||
if (endIndex !== -1) { | ||
this.parseHeaders(contentsString.substr(0, endIndex)); | ||
if (endIndex + 4 < contentsString.length) { | ||
var bodyPart = contentsString.substr((endIndex + 4)); | ||
let bodyPart = contentsString.substr((endIndex + 4)); | ||
this.appendBody(bodyPart); | ||
@@ -39,7 +39,7 @@ } | ||
} | ||
}; | ||
WebhookRequest.prototype.appendBody = function (bodyPart) { | ||
} | ||
appendBody(bodyPart) { | ||
this.body += bodyPart; | ||
}; | ||
WebhookRequest.prototype.done = function () { | ||
} | ||
done() { | ||
if (this.method === "GET") { | ||
@@ -49,33 +49,33 @@ return true; | ||
return (this.body.length === this.contentLength()); | ||
}; | ||
WebhookRequest.prototype.contentLength = function () { | ||
var contentLength = -1; | ||
} | ||
contentLength() { | ||
let contentLength = -1; | ||
if (this.headers != null) { | ||
var contentLengthString = this.headers["content-length"]; | ||
let contentLengthString = this.headers["content-length"]; | ||
contentLength = parseInt(contentLengthString); | ||
} | ||
return contentLength; | ||
}; | ||
WebhookRequest.prototype.isPing = function () { | ||
} | ||
isPing() { | ||
return (this.uri.indexOf("/ping") !== -1); | ||
}; | ||
WebhookRequest.prototype.parseHeaders = function (headersString) { | ||
var lines = headersString.split("\n"); | ||
var requestLine = lines[0]; | ||
var requestLineParts = requestLine.split(" "); | ||
} | ||
parseHeaders(headersString) { | ||
let lines = headersString.split("\n"); | ||
let requestLine = lines[0]; | ||
let requestLineParts = requestLine.split(" "); | ||
this.method = requestLineParts[0]; | ||
this.uri = requestLineParts[1]; | ||
if (this.uri.indexOf("?") >= 0) { | ||
var qs = this.uri.replace(/^.*\?/, ""); | ||
const qs = this.uri.replace(/^.*\?/, ""); | ||
this.queryParameters = querystring.parse(qs); | ||
} | ||
for (var i = 1; i < lines.length; i++) { | ||
var headerLine = lines[i]; | ||
var headerParts = headerLine.split(":"); | ||
var key = headerParts[0].toLowerCase(); | ||
for (let i = 1; i < lines.length; i++) { | ||
let headerLine = lines[i]; | ||
let headerParts = headerLine.split(":"); | ||
let key = headerParts[0].toLowerCase(); | ||
this.headers[key] = headerParts[1].trim(); | ||
} | ||
}; | ||
WebhookRequest.prototype.nodeID = function () { | ||
var nodeValue = null; | ||
} | ||
nodeID() { | ||
let nodeValue = null; | ||
if ("node-id" in this.queryParameters) { | ||
@@ -85,15 +85,14 @@ nodeValue = this.queryParameters["node-id"]; | ||
return nodeValue; | ||
}; | ||
WebhookRequest.prototype.toTCP = function () { | ||
} | ||
toTCP() { | ||
return this.rawContents.toString(); | ||
}; | ||
WebhookRequest.prototype.toString = function () { | ||
} | ||
toString() { | ||
return this.method + " " + this.uri; | ||
}; | ||
WebhookRequest.prototype.id = function () { | ||
} | ||
id() { | ||
return this.requestID; | ||
}; | ||
return WebhookRequest; | ||
}()); | ||
} | ||
} | ||
exports.WebhookRequest = WebhookRequest; | ||
//# sourceMappingURL=webhook-request.js.map |
"use strict"; | ||
var http = require("http"); | ||
var util = require("util"); | ||
var uuid = require("node-uuid"); | ||
var LoglessContext = (function () { | ||
function LoglessContext(_source) { | ||
const http = require("http"); | ||
const util = require("util"); | ||
const uuid = require("node-uuid"); | ||
class LoglessContext { | ||
constructor(_source) { | ||
this._source = _source; | ||
@@ -11,4 +11,4 @@ this._queue = []; | ||
} | ||
LoglessContext.prototype.onLambdaEvent = function (event, context, wrappedCallback) { | ||
var self = this; | ||
onLambdaEvent(event, context, wrappedCallback) { | ||
const self = this; | ||
if (context.awsRequestId !== undefined && context.awsRequestId !== null) { | ||
@@ -20,3 +20,3 @@ this._transactionID = context.awsRequestId; | ||
} | ||
var done = context.done; | ||
const done = context.done; | ||
context.done = function (error, result) { | ||
@@ -28,3 +28,3 @@ self.captureResponse(error, result); | ||
}; | ||
var fail = context.fail; | ||
const fail = context.fail; | ||
context.fail = function (error) { | ||
@@ -36,3 +36,3 @@ self.captureResponse(error, null); | ||
}; | ||
var succeed = context.succeed; | ||
const succeed = context.succeed; | ||
context.succeed = function (result) { | ||
@@ -53,7 +53,7 @@ self.captureResponse(null, result); | ||
} | ||
}; | ||
LoglessContext.prototype.callback = function () { | ||
} | ||
callback() { | ||
return this._callback; | ||
}; | ||
LoglessContext.prototype.log = function (type, data, params, tags) { | ||
} | ||
log(type, data, params, tags) { | ||
if (data instanceof Error) { | ||
@@ -63,7 +63,6 @@ this.logError(type, data, tags); | ||
else if (typeof data === "string") { | ||
var dataString = data; | ||
let dataString = data; | ||
if (params !== undefined && params !== null) { | ||
var allParams = [data]; | ||
for (var _i = 0, params_1 = params; _i < params_1.length; _i++) { | ||
var param = params_1[_i]; | ||
let allParams = [data]; | ||
for (let param of params) { | ||
allParams.push(param); | ||
@@ -78,5 +77,5 @@ } | ||
} | ||
}; | ||
LoglessContext.prototype.logError = function (type, error, tags) { | ||
var message = error.name + ": " + error.message; | ||
} | ||
logError(type, error, tags) { | ||
let message = error.name + ": " + error.message; | ||
if (error.code !== undefined) { | ||
@@ -89,4 +88,4 @@ message += " code: " + error.code; | ||
this._queue.push(new Log(type, message, error.stack, tags)); | ||
}; | ||
LoglessContext.prototype.captureResponse = function (error, result) { | ||
} | ||
captureResponse(error, result) { | ||
if (error !== undefined && error !== null) { | ||
@@ -98,8 +97,8 @@ this.log(LogType.ERROR, error, null, ["response"]); | ||
} | ||
}; | ||
LoglessContext.prototype.transactionID = function () { | ||
} | ||
transactionID() { | ||
return this._transactionID; | ||
}; | ||
LoglessContext.prototype.flush = function (flushed) { | ||
var logBatch = { | ||
} | ||
flush(flushed) { | ||
const logBatch = { | ||
source: this._source, | ||
@@ -109,7 +108,6 @@ transaction_id: this.transactionID(), | ||
}; | ||
for (var _i = 0, _a = this._queue; _i < _a.length; _i++) { | ||
var log = _a[_i]; | ||
var timestamp = log.timestampAsISOString(); | ||
var payload = log.data; | ||
var logJSON = { | ||
for (let log of this._queue) { | ||
const timestamp = log.timestampAsISOString(); | ||
let payload = log.data; | ||
const logJSON = { | ||
payload: payload, | ||
@@ -127,5 +125,5 @@ log_type: LogType[log.type], | ||
} | ||
var dataAsString = JSON.stringify(logBatch); | ||
var dataLength = Buffer.byteLength(dataAsString); | ||
var options = { | ||
const dataAsString = JSON.stringify(logBatch); | ||
const dataLength = Buffer.byteLength(dataAsString); | ||
const options = { | ||
host: "logless-server-049ff85c.4a0ac639.svc.dockerapp.io", | ||
@@ -141,3 +139,3 @@ port: 3000, | ||
}; | ||
var httpRequest = this.httpRequest(options, function (response) { | ||
const httpRequest = this.httpRequest(options, function (response) { | ||
}); | ||
@@ -153,11 +151,10 @@ httpRequest.setNoDelay(true); | ||
this._queue = []; | ||
}; | ||
LoglessContext.prototype.completed = function () { | ||
} | ||
completed() { | ||
return this._completed; | ||
}; | ||
LoglessContext.prototype.httpRequest = function (options, callback) { | ||
} | ||
httpRequest(options, callback) { | ||
return http.request(options, callback); | ||
}; | ||
return LoglessContext; | ||
}()); | ||
} | ||
} | ||
exports.LoglessContext = LoglessContext; | ||
@@ -172,4 +169,4 @@ (function (LogType) { | ||
var LogType = exports.LogType; | ||
var Log = (function () { | ||
function Log(type, data, stack, tags) { | ||
class Log { | ||
constructor(type, data, stack, tags) { | ||
this.type = type; | ||
@@ -181,8 +178,7 @@ this.data = data; | ||
} | ||
Log.prototype.timestampAsISOString = function () { | ||
timestampAsISOString() { | ||
return this._timestamp.toISOString(); | ||
}; | ||
return Log; | ||
}()); | ||
} | ||
} | ||
exports.Log = Log; | ||
//# sourceMappingURL=logless-context.js.map |
"use strict"; | ||
var logless_context_1 = require("../logless/logless-context"); | ||
var Logless = (function () { | ||
function Logless() { | ||
} | ||
Logless.capture = function (source, handler) { | ||
const logless_context_1 = require("../logless/logless-context"); | ||
class Logless { | ||
static capture(source, handler) { | ||
if (handler === undefined || handler === null) { | ||
@@ -12,6 +10,6 @@ throw new Error("Handler is null or undefined! This must be passed."); | ||
Logless.initialize(); | ||
var logger = Logless.newContext(); | ||
const logger = Logless.newContext(); | ||
return new LambdaWrapper(logger, handler).lambdaFunction(); | ||
}; | ||
Logless.initialize = function () { | ||
} | ||
static initialize() { | ||
if (Logless._initialized) { | ||
@@ -30,13 +28,14 @@ return; | ||
}); | ||
}; | ||
Logless.wrapCall = function (console, name, type) { | ||
var originalCall = console[name]; | ||
var newCall = function (data, params) { | ||
} | ||
static wrapCall(console, name, type) { | ||
let originalCall = console[name]; | ||
let newCall = function (data, params) { | ||
if (!Logless._context.completed()) { | ||
Logless._context.log(type, data, params); | ||
} | ||
var allParams = [data]; | ||
for (var _i = 0, params_1 = params; _i < params_1.length; _i++) { | ||
var param = params_1[_i]; | ||
allParams.push(param); | ||
let allParams = [data]; | ||
if (params !== undefined && params !== null) { | ||
for (let param of params) { | ||
allParams.push(param); | ||
} | ||
} | ||
@@ -46,17 +45,16 @@ originalCall.apply(this, allParams); | ||
console[name] = newCall; | ||
}; | ||
Logless.newContext = function () { | ||
} | ||
static newContext() { | ||
Logless._context = new logless_context_1.LoglessContext(Logless._source); | ||
return Logless._context; | ||
}; | ||
Logless._initialized = false; | ||
return Logless; | ||
}()); | ||
} | ||
} | ||
Logless._initialized = false; | ||
exports.Logless = Logless; | ||
var LambdaWrapper = (function () { | ||
function LambdaWrapper(logger, wrappedLambda) { | ||
class LambdaWrapper { | ||
constructor(logger, wrappedLambda) { | ||
this.logger = logger; | ||
this.wrappedLambda = wrappedLambda; | ||
} | ||
LambdaWrapper.prototype.handle = function (event, context, callback) { | ||
handle(event, context, callback) { | ||
this.logger.onLambdaEvent(event, context, callback); | ||
@@ -70,11 +68,10 @@ try { | ||
} | ||
}; | ||
LambdaWrapper.prototype.lambdaFunction = function () { | ||
var lambda = this.handle.bind(this); | ||
} | ||
lambdaFunction() { | ||
let lambda = this.handle.bind(this); | ||
lambda.logger = this.logger; | ||
return lambda; | ||
}; | ||
return LambdaWrapper; | ||
}()); | ||
} | ||
} | ||
exports.LambdaWrapper = LambdaWrapper; | ||
//# sourceMappingURL=logless.js.map |
@@ -59,4 +59,6 @@ import {LogType, LoglessContext} from "../logless/logless-context"; | ||
let allParams = [data]; | ||
for (let param of params) { | ||
allParams.push(param); | ||
if (params !== undefined && params !== null) { | ||
for (let param of params) { | ||
allParams.push(param); | ||
} | ||
} | ||
@@ -63,0 +65,0 @@ originalCall.apply(this, allParams); |
"use strict"; | ||
var node_manager_1 = require("./node-manager"); | ||
var webhook_manager_1 = require("./webhook-manager"); | ||
var http_helper_1 = require("../core/http-helper"); | ||
var global_1 = require("../core/global"); | ||
var statistics_1 = require("./statistics"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var Logger = "BSPKD"; | ||
var BespokeServer = (function () { | ||
function BespokeServer(webhookPort, nodePort) { | ||
const node_manager_1 = require("./node-manager"); | ||
const webhook_manager_1 = require("./webhook-manager"); | ||
const http_helper_1 = require("../core/http-helper"); | ||
const global_1 = require("../core/global"); | ||
const statistics_1 = require("./statistics"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const Logger = "BSPKD"; | ||
class BespokeServer { | ||
constructor(webhookPort, nodePort) { | ||
this.webhookPort = webhookPort; | ||
this.nodePort = nodePort; | ||
} | ||
BespokeServer.prototype.start = function (started) { | ||
var self = this; | ||
start(started) { | ||
let self = this; | ||
console.error("AWS_KEY: " + process.env["AWS_ACCESS_KEY_ID"]); | ||
var count = 0; | ||
var callbackCounter = function () { | ||
let count = 0; | ||
let callbackCounter = function () { | ||
count++; | ||
@@ -40,3 +40,3 @@ if (count === 2) { | ||
else { | ||
var node = self.nodeManager.node(webhookRequest.nodeID()); | ||
let node = self.nodeManager.node(webhookRequest.nodeID()); | ||
if (node == null) { | ||
@@ -55,6 +55,6 @@ logging_helper_1.LoggingHelper.error(Logger, "Node is not active: " + webhookRequest.nodeID()); | ||
}; | ||
}; | ||
BespokeServer.prototype.stop = function (callback) { | ||
var count = 0; | ||
var callbackFunction = function () { | ||
} | ||
stop(callback) { | ||
let count = 0; | ||
let callbackFunction = function () { | ||
count++; | ||
@@ -67,6 +67,5 @@ if (count === 2) { | ||
this.webhookManager.stop(callbackFunction); | ||
}; | ||
return BespokeServer; | ||
}()); | ||
} | ||
} | ||
exports.BespokeServer = BespokeServer; | ||
//# sourceMappingURL=bespoke-server.js.map |
"use strict"; | ||
var net = require("net"); | ||
var node_1 = require("./node"); | ||
var socket_handler_1 = require("../core/socket-handler"); | ||
var global_1 = require("../core/global"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var statistics_1 = require("./statistics"); | ||
var Logger = "NODEMGR"; | ||
var NodeManager = (function () { | ||
function NodeManager(port) { | ||
const net = require("net"); | ||
const node_1 = require("./node"); | ||
const socket_handler_1 = require("../core/socket-handler"); | ||
const global_1 = require("../core/global"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const statistics_1 = require("./statistics"); | ||
let Logger = "NODEMGR"; | ||
class NodeManager { | ||
constructor(port) { | ||
this.port = port; | ||
@@ -17,13 +17,13 @@ this.host = "0.0.0.0"; | ||
} | ||
NodeManager.prototype.node = function (nodeID) { | ||
node(nodeID) { | ||
return this.nodes[nodeID]; | ||
}; | ||
NodeManager.prototype.start = function (callback) { | ||
var self = this; | ||
} | ||
start(callback) { | ||
let self = this; | ||
this.server = net.createServer(function (socket) { | ||
var initialConnection = true; | ||
var node = null; | ||
var socketHandler = new socket_handler_1.SocketHandler(socket, function (message, messageID) { | ||
let initialConnection = true; | ||
let node = null; | ||
let socketHandler = new socket_handler_1.SocketHandler(socket, function (message, messageID) { | ||
if (initialConnection) { | ||
var connectData = null; | ||
let connectData = null; | ||
try { | ||
@@ -70,10 +70,9 @@ connectData = JSON.parse(message); | ||
logging_helper_1.LoggingHelper.info(Logger, "Listening on " + this.host + ":" + this.port); | ||
}; | ||
NodeManager.onKeepAliveReceived = function (node) { | ||
} | ||
static onKeepAliveReceived(node) { | ||
node.socketHandler.send(global_1.Global.KeepAliveMessage); | ||
}; | ||
NodeManager.prototype.stop = function (callback) { | ||
for (var _i = 0, _a = Object.keys(this.nodes); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var node = this.node(key); | ||
} | ||
stop(callback) { | ||
for (let key of Object.keys(this.nodes)) { | ||
let node = this.node(key); | ||
node.socketHandler.disconnect(); | ||
@@ -91,6 +90,5 @@ logging_helper_1.LoggingHelper.info(Logger, "NODE CLOSING: " + node.id); | ||
}); | ||
}; | ||
return NodeManager; | ||
}()); | ||
} | ||
} | ||
exports.NodeManager = NodeManager; | ||
//# sourceMappingURL=node-manager.js.map |
"use strict"; | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var Logger = "NODE"; | ||
var Node = (function () { | ||
function Node(id, socketHandler) { | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
const Logger = "NODE"; | ||
class Node { | ||
constructor(id, socketHandler) { | ||
this.id = id; | ||
@@ -10,14 +10,14 @@ this.socketHandler = socketHandler; | ||
} | ||
Node.prototype.forward = function (request) { | ||
forward(request) { | ||
console.log("NODE " + this.id + " MSG-ID: " + request.id() + " Forwarding"); | ||
this.requests[request.id()] = request; | ||
this.socketHandler.send(request.toTCP(), request.id()); | ||
}; | ||
Node.prototype.handlingRequest = function () { | ||
} | ||
handlingRequest() { | ||
return (Object.keys(this.requests).length > 0); | ||
}; | ||
Node.prototype.onReply = function (message, messageID) { | ||
var self = this; | ||
} | ||
onReply(message, messageID) { | ||
let self = this; | ||
console.log("NODE " + this.id + " MSG-ID: " + messageID + " ReplyReceived"); | ||
var request = this.requests[messageID]; | ||
let request = this.requests[messageID]; | ||
if (request === null) { | ||
@@ -31,6 +31,5 @@ logging_helper_1.LoggingHelper.info(Logger, "No matching messageID for reply: " + messageID); | ||
} | ||
}; | ||
return Node; | ||
}()); | ||
} | ||
} | ||
exports.Node = Node; | ||
//# sourceMappingURL=node.js.map |
"use strict"; | ||
var AWS = require("aws-sdk"); | ||
var Statistics = (function () { | ||
function Statistics() { | ||
const AWS = require("aws-sdk"); | ||
class Statistics { | ||
constructor() { | ||
this._dynamoClient = null; | ||
this._docClient = null; | ||
} | ||
Statistics.instance = function () { | ||
static instance() { | ||
return Statistics.Singleton; | ||
}; | ||
Statistics.prototype.dynamoClient = function () { | ||
} | ||
dynamoClient() { | ||
this.configure(); | ||
@@ -17,4 +17,4 @@ if (this._dynamoClient === null) { | ||
return this._dynamoClient; | ||
}; | ||
Statistics.prototype.docClient = function () { | ||
} | ||
docClient() { | ||
this.configure(); | ||
@@ -29,11 +29,11 @@ if (this._docClient === null) { | ||
return this._docClient; | ||
}; | ||
Statistics.prototype.configure = function () { | ||
} | ||
configure() { | ||
AWS.config.update({ | ||
region: "us-east-1" | ||
}); | ||
}; | ||
Statistics.prototype.deleteTable = function (deleted) { | ||
var dynamoClient = this.dynamoClient(); | ||
var dynamoParams = { | ||
} | ||
deleteTable(deleted) { | ||
const dynamoClient = this.dynamoClient(); | ||
const dynamoParams = { | ||
TableName: Statistics.Table | ||
@@ -44,6 +44,6 @@ }; | ||
}); | ||
}; | ||
Statistics.prototype.createTable = function (created) { | ||
var dynamoClient = this.dynamoClient(); | ||
var dynamoParams = { | ||
} | ||
createTable(created) { | ||
const dynamoClient = this.dynamoClient(); | ||
const dynamoParams = { | ||
TableName: Statistics.Table, | ||
@@ -66,9 +66,9 @@ KeySchema: [ | ||
}); | ||
}; | ||
Statistics.prototype.record = function (nodeID, accessType, confirmation) { | ||
} | ||
record(nodeID, accessType, confirmation) { | ||
console.time("Statistics.record"); | ||
var self = this; | ||
var timestamp = new Date().toISOString(); | ||
var docClient = this.docClient(); | ||
var dynamoParams = { | ||
const self = this; | ||
const timestamp = new Date().toISOString(); | ||
const docClient = this.docClient(); | ||
const dynamoParams = { | ||
TableName: Statistics.Table, | ||
@@ -97,7 +97,6 @@ Item: { | ||
console.timeEnd("Statistics.record"); | ||
}; | ||
Statistics.Table = "bst-stats"; | ||
Statistics.Singleton = new Statistics(); | ||
return Statistics; | ||
}()); | ||
} | ||
} | ||
Statistics.Table = "bst-stats"; | ||
Statistics.Singleton = new Statistics(); | ||
exports.Statistics = Statistics; | ||
@@ -104,0 +103,0 @@ (function (AccessType) { |
"use strict"; | ||
var webhook_request_1 = require("../core/webhook-request"); | ||
var net = require("net"); | ||
var logging_helper_1 = require("../core/logging-helper"); | ||
var Logger = "WEBHOOK"; | ||
var WebhookManager = (function () { | ||
function WebhookManager(port) { | ||
const webhook_request_1 = require("../core/webhook-request"); | ||
const net = require("net"); | ||
const logging_helper_1 = require("../core/logging-helper"); | ||
let Logger = "WEBHOOK"; | ||
class WebhookManager { | ||
constructor(port) { | ||
this.port = port; | ||
@@ -13,12 +13,12 @@ this.socketMap = {}; | ||
} | ||
WebhookManager.prototype.start = function (started) { | ||
var self = this; | ||
var socketIndex = 0; | ||
start(started) { | ||
let self = this; | ||
let socketIndex = 0; | ||
this.server = net.createServer(function (socket) { | ||
var webhookRequest = new webhook_request_1.WebhookRequest(socket); | ||
let webhookRequest = new webhook_request_1.WebhookRequest(socket); | ||
socketIndex++; | ||
var socketKey = socketIndex; | ||
let socketKey = socketIndex; | ||
self.socketMap[socketIndex] = socket; | ||
socket.on("data", function (data) { | ||
var dataString = data.toString(); | ||
let dataString = data.toString(); | ||
if (dataString.length > 4 && dataString.substr(0, 3) !== "GET") { | ||
@@ -43,7 +43,7 @@ logging_helper_1.LoggingHelper.info(Logger, "Webhook From " + socket.remoteAddress + ":" + socket.remotePort); | ||
logging_helper_1.LoggingHelper.info(Logger, "Listening on " + this.host + ":" + this.port); | ||
}; | ||
WebhookManager.prototype.stop = function (callback) { | ||
var self = this; | ||
for (var key in self.socketMap) { | ||
var socket = self.socketMap[key]; | ||
} | ||
stop(callback) { | ||
let self = this; | ||
for (let key in self.socketMap) { | ||
let socket = self.socketMap[key]; | ||
socket.end(); | ||
@@ -56,6 +56,5 @@ } | ||
}); | ||
}; | ||
return WebhookManager; | ||
}()); | ||
} | ||
} | ||
exports.WebhookManager = WebhookManager; | ||
//# sourceMappingURL=webhook-manager.js.map |
@@ -5,3 +5,3 @@ { | ||
"private": false, | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"bin": { | ||
@@ -39,3 +39,3 @@ "bst": "./bin/bst.js", | ||
"engines": { | ||
"node": "4.4.7" | ||
"node": "4.3.2" | ||
}, | ||
@@ -42,0 +42,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4600458
14825