Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge b6e851f into 938649b
Browse files Browse the repository at this point in the history
  • Loading branch information
jperata committed Nov 23, 2017
2 parents 938649b + b6e851f commit 65aac19
Show file tree
Hide file tree
Showing 9 changed files with 939 additions and 913 deletions.
28 changes: 13 additions & 15 deletions bin/bst-intend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as program from "commander";
import {Global} from "../lib/core/global";
import {BSTVirtualAlexa} from "../lib/client/bst-virtual-alexa";
import * as chalk from "chalk";

program.version(Global.version());

Expand Down Expand Up @@ -85,29 +86,26 @@ program
}

speaker.intended(intentName, slots, function(error: any, response: any, request: any) {
console.log("Intended: " + intentName);
console.log("");
if (request) {
console.log("Request:");
console.log(chalk.blue(JSON.stringify(request, null, 4)));
console.log("");
}

if (error) {
console.log("Intended: " + intentName);
if (request) {
console.log("Request:");
console.log(JSON.stringify(request, null, 4));
console.log("");
}
console.log("Error: " + error.message);
console.log(chalk.red("Error: " + error.message));
return;
}
const jsonPretty = JSON.stringify(response, null, 4);
console.log("Intended: " + intentName);
console.log("");
console.log("Request:");
console.log(JSON.stringify(request, null, 4));
console.log("");
console.log("Response:");
console.log(jsonPretty);
console.log(chalk.cyan(jsonPretty));
console.log("");
});
} catch (e) {
console.error("Error with intent:");
console.error(e.message);
console.error(chalk.red("Error with intent:"));
console.error(chalk.red(e.message));
console.error();
}
});
Expand Down
7 changes: 4 additions & 3 deletions bin/bst-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as program from "commander";
import {Global} from "../lib/core/global";
import {BSTVirtualAlexa} from "../lib/client/bst-virtual-alexa";
import * as chalk from "chalk";

program.version(Global.version());

Expand Down Expand Up @@ -58,16 +59,16 @@ program

speaker.launched(function (errorInLaunch: any, response: any, request: any) {
if (errorInLaunch) {
console.log("Error: " + errorInLaunch);
console.error(chalk.red("Error: " + errorInLaunch));
return;
}

const jsonPretty = JSON.stringify(response, null, 4);
console.log("Request:");
console.log(JSON.stringify(request, null, 4));
console.log(chalk.blue(JSON.stringify(request, null, 4)));
console.log("");
console.log("Response:");
console.log(jsonPretty);
console.log(chalk.cyan(jsonPretty));
console.log("");
});
});
Expand Down
19 changes: 10 additions & 9 deletions bin/bst-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Global} from "../lib/core/global";
import {LoggingHelper} from "../lib/core/logging-helper";
import {BSTProxy} from "../lib/client/bst-proxy";
import {URLMangler} from "../lib/client/url-mangler";
import * as chalk from "chalk";

let handleOptions = function(proxy: BSTProxy, options: any) {
if (options.bstHost) {
Expand Down Expand Up @@ -40,16 +41,16 @@ program
console.log("You are in secure mode, requests must include the bespoken-key in the query or the headers");
console.log("");
console.log("Your public URL for accessing your local service with bespoken-key in the query:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("");
} else {
console.log("Your public URL for accessing your local service:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID())));
console.log("");
}

console.log("Your URL for viewing requests/responses sent to your service:");
console.log(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("Copy and paste this to your browser to view your transaction history and summary data.");
console.log("");

Expand All @@ -71,16 +72,16 @@ program
console.log("You are in secure mode, requests must include the bespoken-key in the query or the headers");
console.log("");
console.log("Your public URL for accessing your local service with bespoken-key in the query:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("");
} else {
console.log("Your public URL for accessing your local service:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID())));
console.log("");
}

console.log("Your URL for viewing requests/responses sent to your service:");
console.log(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("Copy and paste this to your browser to view your transaction history and summary data.");
console.log("");
let proxy: BSTProxy = BSTProxy.lambda(lambdaFile, functionName);
Expand All @@ -101,16 +102,16 @@ program
console.log("You are in secure mode, requests must include the bespoken-key in the query or the headers");
console.log("");
console.log("Your URL for Fulfillment configuration with bespoken-key in the query:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("");
} else {
console.log("Your URL for Fulfillment configuration:");
console.log(URLMangler.manglePipeToPath(Global.config().sourceID()));
console.log(chalk.blue(URLMangler.manglePipeToPath(Global.config().sourceID())));
console.log("");
}

console.log("Your URL for viewing your function data:");
console.log(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey()));
console.log(chalk.blue(URLMangler.mangleNoPath(Global.config().sourceID(), Global.config().secretKey())));
console.log("Copy and paste this to your browser to view your transaction history and summary data.");
console.log("");

Expand Down
25 changes: 11 additions & 14 deletions bin/bst-utter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import * as program from "commander";
import {Global} from "../lib/core/global";
import {BSTVirtualAlexa} from "../lib/client/bst-virtual-alexa";
import * as chalk from "chalk";

program.version(Global.version());

Expand Down Expand Up @@ -78,25 +79,21 @@ program
}

speaker.spoken(utterance, function(error: any, response: any, request: any) {
if (error) {
console.log("Spoke: " + utterance);
console.log("Spoke: " + utterance);
console.log("");
if (request) {
console.log("Request:");
console.log(chalk.blue(JSON.stringify(request, null, 4)));
console.log("");
if (request) {
console.log("Request:");
console.log(JSON.stringify(request, null, 4));
console.log("");
}
console.log("Error: " + error.message);
}

if (error) {
console.log(chalk.red("Error: " + error.message));
return;
}
const jsonPretty = JSON.stringify(response, null, 4);
console.log("Spoke: " + utterance);
console.log("");
console.log("Request:");
console.log(JSON.stringify(request, null, 4));
console.log("");
console.log("Response:");
console.log(jsonPretty);
console.log(chalk.cyan(jsonPretty));
console.log("");
});
});
Expand Down
13 changes: 10 additions & 3 deletions lib/client/bespoke-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {LoggingHelper} from "../core/logging-helper";
import {KeepAlive} from "./keep-alive";
import {StringUtil} from "../core/string-util";
import {HTTPBuffer} from "../core/http-buffer";
import * as chalk from "chalk";

const Logger = "BST-CLIENT";

Expand Down Expand Up @@ -95,7 +96,7 @@ export class BespokeClient {

// Print out the contents of the request body to the console
LoggingHelper.info(Logger, "RequestReceived: " + request.toString() + " ID: " + request.id());
LoggingHelper.verbose(Logger, "Payload:\n" + StringUtil.prettyPrintJSON(request.body));
LoggingHelper.verbose(Logger, "Payload:\n" + chalk.blue(StringUtil.prettyPrintJSON(request.body)));

const tcpClient = new TCPClient(request.id() + "");
const httpBuffer = new HTTPBuffer();
Expand All @@ -114,12 +115,18 @@ export class BespokeClient {
} else {
payload = httpBuffer.body().toString();
}
LoggingHelper.verbose(Logger, "Payload:\n" + payload);

// Errors managed by us
if (payload.indexOf("Unhandle exception") !== -1 || payload.indexOf("Error: ") !== -1) {
LoggingHelper.verbose(Logger, "Payload:\n" + chalk.red(payload));
} else {
LoggingHelper.verbose(Logger, "Payload:\n" + chalk.cyan(payload));
}
self.socketHandler.send(httpBuffer.raw().toString(), request.id());
}
} else if (error !== null && error !== undefined) {
if (error === NetworkErrorType.CONNECTION_REFUSED) {
LoggingHelper.error(Logger, "CLIENT Connection Refused, Port " + self.targetPort + ". Is your server running?");
LoggingHelper.error(Logger, chalk.red("CLIENT Connection Refused, Port " + self.targetPort + ". Is your server running?"));
}

const errorMessage = "BST Proxy - Local Forwarding Error\n" + message;
Expand Down
8 changes: 3 additions & 5 deletions lib/client/lambda-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {ServerResponse} from "http";
import {Server} from "http";
import {LoggingHelper} from "../core/logging-helper";
import {ModuleManager} from "./module-manager";
import * as chalk from "chalk";

let Logger = "BST-LAMBDA";

Expand Down Expand Up @@ -37,6 +38,7 @@ export class LambdaServer {
let self = this;

this.moduleManager = new ModuleManager(process.cwd());

this.moduleManager.start();

this.server = http.createServer();
Expand Down Expand Up @@ -133,11 +135,7 @@ export class LambdaServer {
context.done(error, result);
});
} catch (e) {
if (e.stack) {
console.error(e.stack);
} else {
console.error(e);
}
console.error(chalk.red(e.toString()));
context.fail(e);
}
}
Expand Down

0 comments on commit 65aac19

Please sign in to comment.