diff --git a/deps/aws-lambda-cpp-0.2.6.tar.gz b/deps/aws-lambda-cpp-0.2.6.tar.gz
index fe1fbae..ff1a706 100644
Binary files a/deps/aws-lambda-cpp-0.2.6.tar.gz and b/deps/aws-lambda-cpp-0.2.6.tar.gz differ
diff --git a/deps/patches/aws-lambda-cpp-macos-fixes.patch b/deps/patches/aws-lambda-cpp-macos-fixes.patch
new file mode 100644
index 0000000..2bafc27
--- /dev/null
+++ b/deps/patches/aws-lambda-cpp-macos-fixes.patch
@@ -0,0 +1,22 @@
+diff --git a/include/backward.h b/include/backward.h
+index e065783..9e369a6 100644
+--- a/include/backward.h
++++ b/include/backward.h
+@@ -43,7 +43,7 @@
+
+ // You can define one of the following (or leave it to the auto-detection):
+ //
+-# define BACKWARD_SYSTEM_LINUX
++// #define BACKWARD_SYSTEM_LINUX
+ // - specialization for linux
+ //
+ // #define BACKWARD_SYSTEM_DARWIN
+@@ -3057,7 +3057,7 @@ public:
+ if (st.size() == 0) {
+ return;
+ }
+- _symbols.reset(backtrace_symbols(st.begin(), st.size()));
++ _symbols.reset(backtrace_symbols(st.begin(), (int)st.size()));
+ }
+
+ ResolvedTrace resolve(ResolvedTrace trace)
diff --git a/lib/Common/index.d.ts b/lib/Common/index.d.ts
new file mode 100644
index 0000000..05c3d63
--- /dev/null
+++ b/lib/Common/index.d.ts
@@ -0,0 +1,62 @@
+/**
+ * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines types, enums and interfaces common to the other modules.
+ */
+///
+import { IncomingHttpHeaders } from "http";
+export interface InvocationResponse {
+ bodyJson: string;
+ headers: IncomingHttpHeaders;
+}
+export interface NativeClient {
+ initializeClient: (userAgent: string) => void;
+ done: (id: string, bodyString: string) => void;
+ error: (id: string, bodyString: string, xrayString: string) => void;
+ next: () => Promise;
+}
+export declare enum INVOKE_HEADER {
+ ClientContext = "lambda-runtime-client-context",
+ CognitoIdentity = "lambda-runtime-cognito-identity",
+ ARN = "lambda-runtime-invoked-function-arn",
+ AWSRequestId = "lambda-runtime-aws-request-id",
+ DeadlineMs = "lambda-runtime-deadline-ms",
+ XRayTrace = "lambda-runtime-trace-id"
+}
+export interface IEnvironmentData {
+ functionVersion?: string;
+ functionName?: string;
+ memoryLimitInMB?: string;
+ logGroupName?: string;
+ logStreamName?: string;
+}
+export interface IHeaderData {
+ clientContext?: string;
+ identity?: string;
+ invokedFunctionArn?: string;
+ awsRequestId?: string;
+ getRemainingTimeInMillis: () => number;
+}
+export declare type ErrorStringOrUndefined = Error | string | undefined;
+export declare type ErrorStringOrUndefinedOrNull = ErrorStringOrUndefined | null;
+/**
+ *
+ */
+export interface ICallbackContext {
+ callbackWaitsForEmptyEventLoop: boolean;
+ succeed: (result: unknown) => void;
+ fail: (err: ErrorStringOrUndefinedOrNull) => void;
+ done: (err: ErrorStringOrUndefinedOrNull, result?: unknown) => void;
+}
+export declare type CallbackFunction = (err: ErrorStringOrUndefinedOrNull, result?: unknown) => void;
+export interface IBeforeExitListener {
+ invoke: () => void;
+ reset: () => () => void;
+ set: (listener: () => void) => () => void;
+}
+export interface IErrorCallbacks {
+ uncaughtException: (err: Error) => void;
+ unhandledRejection: (err: Error) => void;
+}
+export declare type HandlerFunction = (body: unknown, data: IEnvironmentData & IHeaderData, callback: CallbackFunction) => PromiseLike | unknown;
+//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/lib/Common/index.d.ts.map b/lib/Common/index.d.ts.map
new file mode 100644
index 0000000..dbfdc20
--- /dev/null
+++ b/lib/Common/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Common/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;I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,CAAC,GAAG,EAAE,4BAA4B,EAAE,MAAM,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;CACrE;AAED,oBAAY,gBAAgB,GAAG,CAC7B,GAAG,EAAE,4BAA4B,EACjC,MAAM,CAAC,EAAE,OAAO,KACb,IAAI,CAAC;AAEV,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,MAAM,IAAI,CAAC;IACxB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;IACxC,kBAAkB,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C;AAED,oBAAY,eAAe,GAAG,CAC5B,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,gBAAgB,GAAG,WAAW,EACpC,QAAQ,EAAE,gBAAgB,KACvB,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC"}
\ No newline at end of file
diff --git a/lib/Common/index.js b/lib/Common/index.js
new file mode 100644
index 0000000..1608bba
--- /dev/null
+++ b/lib/Common/index.js
@@ -0,0 +1,18 @@
+"use strict";
+/**
+ * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines types, enums and interfaces common to the other modules.
+ */
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.INVOKE_HEADER = void 0;
+var INVOKE_HEADER;
+(function (INVOKE_HEADER) {
+ INVOKE_HEADER["ClientContext"] = "lambda-runtime-client-context";
+ INVOKE_HEADER["CognitoIdentity"] = "lambda-runtime-cognito-identity";
+ INVOKE_HEADER["ARN"] = "lambda-runtime-invoked-function-arn";
+ INVOKE_HEADER["AWSRequestId"] = "lambda-runtime-aws-request-id";
+ INVOKE_HEADER["DeadlineMs"] = "lambda-runtime-deadline-ms";
+ INVOKE_HEADER["XRayTrace"] = "lambda-runtime-trace-id";
+})(INVOKE_HEADER = exports.INVOKE_HEADER || (exports.INVOKE_HEADER = {}));
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvQ29tbW9uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7OztHQUlHOzs7QUFnQkgsSUFBWSxhQU9YO0FBUEQsV0FBWSxhQUFhO0lBQ3ZCLGdFQUErQyxDQUFBO0lBQy9DLG9FQUFtRCxDQUFBO0lBQ25ELDREQUEyQyxDQUFBO0lBQzNDLCtEQUE4QyxDQUFBO0lBQzlDLDBEQUF5QyxDQUFBO0lBQ3pDLHNEQUFxQyxDQUFBO0FBQ3ZDLENBQUMsRUFQVyxhQUFhLEdBQWIscUJBQWEsS0FBYixxQkFBYSxRQU94QiJ9
\ No newline at end of file
diff --git a/lib/Errors/XRayError.d.ts b/lib/Errors/XRayError.d.ts
new file mode 100644
index 0000000..7beb12f
--- /dev/null
+++ b/lib/Errors/XRayError.d.ts
@@ -0,0 +1,34 @@
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+/**
+ * prepare an exception blob for sending to AWS X-Ray
+ * transform an Error, or Error-like, into an exception parseable by X-Ray's service.
+ * {
+ * "name": "CustomException",
+ * "message": "Something bad happend!",
+ * "stack": [
+ * "exports.handler (/var/function/node_modules/event_invoke.js:3:502)
+ * ]
+ * }
+ * =>
+ * {
+ * "working_directory": "/var/function",
+ * "exceptions": [
+ * {
+ * "type": "CustomException",
+ * "message": "Something bad happend!",
+ * "stack": [
+ * {
+ * "path": "/var/function/event_invoke.js",
+ * "line": 502,
+ * "label": "exports.throw_custom_exception"
+ * }
+ * ]
+ * }
+ * ],
+ * "paths": [
+ * "/var/function/event_invoke.js"
+ * ]
+ * }
+ */
+export declare const toFormatted: (err: unknown) => string;
+//# sourceMappingURL=XRayError.d.ts.map
\ No newline at end of file
diff --git a/lib/Errors/XRayError.d.ts.map b/lib/Errors/XRayError.d.ts.map
new file mode 100644
index 0000000..4fb1046
--- /dev/null
+++ b/lib/Errors/XRayError.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"XRayError.d.ts","sourceRoot":"","sources":["../../src/Errors/XRayError.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAM9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,QAAS,OAAO,KAAG,MAU1C,CAAC"}
\ No newline at end of file
diff --git a/lib/Errors/XRayError.js b/lib/Errors/XRayError.js
new file mode 100644
index 0000000..c882f58
--- /dev/null
+++ b/lib/Errors/XRayError.js
@@ -0,0 +1,87 @@
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.toFormatted = void 0;
+const _1 = require(".");
+/**
+ * prepare an exception blob for sending to AWS X-Ray
+ * transform an Error, or Error-like, into an exception parseable by X-Ray's service.
+ * {
+ * "name": "CustomException",
+ * "message": "Something bad happend!",
+ * "stack": [
+ * "exports.handler (/var/function/node_modules/event_invoke.js:3:502)
+ * ]
+ * }
+ * =>
+ * {
+ * "working_directory": "/var/function",
+ * "exceptions": [
+ * {
+ * "type": "CustomException",
+ * "message": "Something bad happend!",
+ * "stack": [
+ * {
+ * "path": "/var/function/event_invoke.js",
+ * "line": 502,
+ * "label": "exports.throw_custom_exception"
+ * }
+ * ]
+ * }
+ * ],
+ * "paths": [
+ * "/var/function/event_invoke.js"
+ * ]
+ * }
+ */
+exports.toFormatted = (err) => {
+ if (!_1.isError(err)) {
+ return "";
+ }
+ try {
+ return JSON.stringify(new XRayFormattedCause(err));
+ }
+ catch (error) {
+ return "";
+ }
+};
+class XRayFormattedCause {
+ constructor(err) {
+ this.working_directory = process.cwd(); // eslint-disable-line
+ const stack = [];
+ if (err.stack) {
+ const stackLines = err.stack.split("\n");
+ stackLines.shift();
+ stackLines.forEach((stackLine) => {
+ let line = stackLine.trim().replace(/\(|\)/g, "");
+ line = line.substring(line.indexOf(" ") + 1);
+ const label = line.lastIndexOf(" ") >= 0
+ ? line.slice(0, line.lastIndexOf(" "))
+ : null;
+ const path = label == undefined || label == null || label.length === 0
+ ? line
+ : line.slice(line.lastIndexOf(" ") + 1);
+ const pathParts = path.split(":");
+ const entry = {
+ path: pathParts[0],
+ line: parseInt(pathParts[1]),
+ label: label || "anonymous",
+ };
+ stack.push(entry);
+ });
+ }
+ this.exceptions = [
+ {
+ type: err.name,
+ message: err.message,
+ stack: stack,
+ },
+ ];
+ const paths = new Set();
+ stack.forEach((entry) => {
+ paths.add(entry.path);
+ });
+ this.paths = Array.from(paths);
+ }
+}
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiWFJheUVycm9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL0Vycm9ycy9YUmF5RXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsOEVBQThFO0FBRTlFLFlBQVksQ0FBQzs7O0FBRWIsd0JBQTRCO0FBRTVCOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0E4Qkc7QUFDVSxRQUFBLFdBQVcsR0FBRyxDQUFDLEdBQVksRUFBVSxFQUFFO0lBQ2xELElBQUksQ0FBQyxVQUFPLENBQUMsR0FBRyxDQUFDLEVBQUU7UUFDakIsT0FBTyxFQUFFLENBQUM7S0FDWDtJQUVELElBQUk7UUFDRixPQUFPLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxrQkFBa0IsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO0tBQ3BEO0lBQUMsT0FBTyxLQUFLLEVBQUU7UUFDZCxPQUFPLEVBQUUsQ0FBQztL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@@ -0,0 +1,41 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Defines custom error types throwable by the runtime.
+ */
+export declare function isError(obj: any): obj is Error;
+interface RuntimeErrorResponse {
+ errorType: string;
+ errorMessage: string;
+ trace: string[];
+}
+/**
+ * Attempt to convert an object into a response object.
+ * This method accounts for failures when serializing the error object.
+ */
+export declare function toRuntimeResponse(error: unknown): RuntimeErrorResponse;
+/**
+ * Format an error with the expected properties.
+ * For compatability, the error string always starts with a tab.
+ */
+export declare const toFormatted: (error: unknown) => string;
+export declare class ExtendedError extends Error {
+ code?: number;
+ custom?: string;
+ reason?: string;
+ promise?: Promise;
+ constructor(reason?: string);
+}
+export declare class ImportModuleError extends ExtendedError {
+}
+export declare class HandlerNotFound extends ExtendedError {
+}
+export declare class MalformedHandlerName extends ExtendedError {
+}
+export declare class UserCodeSyntaxError extends ExtendedError {
+}
+export declare class UnhandledPromiseRejection extends ExtendedError {
+ constructor(reason?: string, promise?: Promise);
+}
+export {};
+//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/lib/Errors/index.d.ts.map b/lib/Errors/index.d.ts.map
new file mode 100644
index 0000000..6a3ea0f
--- /dev/null
+++ b/lib/Errors/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Errors/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAMH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,KAAK,CAU9C;AAED,UAAU,oBAAoB;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CA0BtE;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,UAAW,OAAO,KAAG,MAQ5C,CAAC;AA2BF,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEX,MAAM,CAAC,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AACvD,qBAAa,eAAgB,SAAQ,aAAa;CAAG;AACrD,qBAAa,oBAAqB,SAAQ,aAAa;CAAG;AAC1D,qBAAa,mBAAoB,SAAQ,aAAa;CAAG;AACzD,qBAAa,yBAA0B,SAAQ,aAAa;gBAC9C,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;CAKpD"}
\ No newline at end of file
diff --git a/lib/Errors/index.js b/lib/Errors/index.js
new file mode 100644
index 0000000..7f2f209
--- /dev/null
+++ b/lib/Errors/index.js
@@ -0,0 +1,129 @@
+/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
+/* eslint-disable @typescript-eslint/no-explicit-any */
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Defines custom error types throwable by the runtime.
+ */
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.UnhandledPromiseRejection = exports.UserCodeSyntaxError = exports.MalformedHandlerName = exports.HandlerNotFound = exports.ImportModuleError = exports.ExtendedError = exports.toFormatted = exports.toRuntimeResponse = exports.isError = void 0;
+const util_1 = __importDefault(require("util"));
+function isError(obj) {
+ return (obj &&
+ obj.name &&
+ obj.message &&
+ obj.stack &&
+ typeof obj.name === "string" &&
+ typeof obj.message === "string" &&
+ typeof obj.stack === "string");
+}
+exports.isError = isError;
+/**
+ * Attempt to convert an object into a response object.
+ * This method accounts for failures when serializing the error object.
+ */
+function toRuntimeResponse(error) {
+ try {
+ if (util_1.default.types.isNativeError(error) || isError(error)) {
+ if (!error.stack) {
+ throw new Error("Error stack is missing.");
+ }
+ return {
+ errorType: error.name,
+ errorMessage: error.message,
+ trace: error.stack.split("\n") || [],
+ };
+ }
+ else {
+ return {
+ errorType: typeof error,
+ errorMessage: error.toString(),
+ trace: [],
+ };
+ }
+ }
+ catch (_err) {
+ return {
+ errorType: "handled",
+ errorMessage: "callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack",
+ trace: [],
+ };
+ }
+}
+exports.toRuntimeResponse = toRuntimeResponse;
+/**
+ * Format an error with the expected properties.
+ * For compatability, the error string always starts with a tab.
+ */
+exports.toFormatted = (error) => {
+ try {
+ return ("\t" + JSON.stringify(error, (_k, v) => _withEnumerableProperties(v)));
+ }
+ catch (err) {
+ return "\t" + JSON.stringify(toRuntimeResponse(error));
+ }
+};
+/**
+ * Error name, message, code, and stack are all members of the superclass, which
+ * means they aren't enumerable and don't normally show up in JSON.stringify.
+ * This method ensures those interesting properties are available along with any
+ * user-provided enumerable properties.
+ */
+function _withEnumerableProperties(error) {
+ if (error instanceof ExtendedError) {
+ const ret = Object.assign({
+ errorType: error.name,
+ errorMessage: error.message,
+ code: error.code,
+ }, error);
+ if (typeof error.stack == "string") {
+ ret.stack = error.stack.split("\n");
+ }
+ return ret;
+ }
+ else {
+ return error;
+ }
+}
+class ExtendedError extends Error {
+ constructor(reason) {
+ super(reason); // 'Error' breaks prototype chain here
+ Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain
+ }
+}
+exports.ExtendedError = ExtendedError;
+class ImportModuleError extends ExtendedError {
+}
+exports.ImportModuleError = ImportModuleError;
+class HandlerNotFound extends ExtendedError {
+}
+exports.HandlerNotFound = HandlerNotFound;
+class MalformedHandlerName extends ExtendedError {
+}
+exports.MalformedHandlerName = MalformedHandlerName;
+class UserCodeSyntaxError extends ExtendedError {
+}
+exports.UserCodeSyntaxError = UserCodeSyntaxError;
+class UnhandledPromiseRejection extends ExtendedError {
+ constructor(reason, promise) {
+ super(reason);
+ this.reason = reason;
+ this.promise = promise;
+ }
+}
+exports.UnhandledPromiseRejection = UnhandledPromiseRejection;
+const errorClasses = [
+ ImportModuleError,
+ HandlerNotFound,
+ MalformedHandlerName,
+ UserCodeSyntaxError,
+ UnhandledPromiseRejection,
+];
+errorClasses.forEach((e) => {
+ e.prototype.name = `Runtime.${e.name}`;
+});
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvRXJyb3JzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHNFQUFzRTtBQUN0RSx1REFBdUQ7QUFDdkQ7Ozs7R0FJRztBQUVILFlBQVksQ0FBQzs7Ozs7O0FBRWIsZ0RBQXdCO0FBRXhCLFNBQWdCLE9BQU8sQ0FBQyxHQUFRO0lBQzlCLE9BQU8sQ0FDTCxHQUFHO1FBQ0gsR0FBRyxDQUFDLElBQUk7UUFDUixHQUFHLENBQUMsT0FBTztRQUNYLEdBQUcsQ0FBQyxLQUFLO1FBQ1QsT0FBTyxHQUFHLENBQUMsSUFBSSxLQUFLLFFBQVE7UUFDNUIsT0FBTyxHQUFHLENBQUMsT0FBTyxLQUFLLFFBQVE7UUFDL0IsT0FBTyxHQUFHLENBQUMsS0FBSyxLQUFLLFFBQVEsQ0FDOUIsQ0FBQztBQUNKLENBQUM7QUFWRCwwQkFVQztBQVFEOzs7R0FHRztBQUNILFNBQWdCLGlCQUFpQixDQUFDLEtBQWM7SUFDOUMsSUFBSTtRQUNGLElBQUksY0FBSSxDQUFDLEtBQUssQ0FBQyxhQUFhLENBQUMsS0FBSyxDQUFDLElBQUksT0FBTyxDQUFDLEtBQUssQ0FBQyxFQUFFO1lBQ3JELElBQUksQ0FBQyxLQUFLLENBQUMsS0FBS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FDekQsTUFBYSx5QkFBMEIsU0FBUSxhQUFhO0lBQzFELFlBQVksTUFBZSxFQUFFLE9BQXNCO1FBQ2pELEtBQUssQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUNkLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDO1FBQ3JCLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO0lBQ3pCLENBQUM7Q0FDRjtBQU5ELDhEQU1DO0FBRUQsTUFBTSxZQUFZLEdBQUc7SUFDbkIsaUJBQWlCO0lBQ2pCLGVBQWU7SUFDZixvQkFBb0I7SUFDcEIsbUJBQW1CO0lBQ25CLHlCQUF5QjtDQUMxQixDQUFDO0FBRUYsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsRUFBRSxFQUFFO0lBQ3pCLENBQUMsQ0FBQyxTQUFTLENBQUMsSUFBSSxHQUFHLFdBQVcsQ0FBQyxDQUFDLElBQUksRUFBRSxDQUFDO0FBQ3pDLENBQUMsQ0FBQyxDQUFDIn0=
\ No newline at end of file
diff --git a/lib/Runtime/BeforeExitListener.d.ts b/lib/Runtime/BeforeExitListener.d.ts
new file mode 100644
index 0000000..d015394
--- /dev/null
+++ b/lib/Runtime/BeforeExitListener.d.ts
@@ -0,0 +1,20 @@
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+import { IBeforeExitListener } from "../Common";
+declare class BeforeExitListener implements IBeforeExitListener {
+ constructor();
+ /**
+ * Call the listener function with no arguments.
+ */
+ invoke: () => void;
+ /**
+ * Reset the listener to a no-op function.
+ */
+ reset: () => (() => void);
+ /**
+ * Set the listener to the provided function.
+ */
+ set: (listener: () => void) => (() => void);
+}
+declare const beforeExitListener: BeforeExitListener;
+export default beforeExitListener;
+//# sourceMappingURL=BeforeExitListener.d.ts.map
\ No newline at end of file
diff --git a/lib/Runtime/BeforeExitListener.d.ts.map b/lib/Runtime/BeforeExitListener.d.ts.map
new file mode 100644
index 0000000..411e32b
--- /dev/null
+++ b/lib/Runtime/BeforeExitListener.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"BeforeExitListener.d.ts","sourceRoot":"","sources":["../../src/Runtime/BeforeExitListener.ts"],"names":[],"mappings":"AACA,8EAA8E;AAI9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAkBhD,cAAM,kBAAmB,YAAW,mBAAmB;;IAKrD;;OAEG;IACH,MAAM,QAAO,IAAI,CAAuC;IAExD;;OAEG;IACH,KAAK,QAAO,CAAC,MAAM,IAAI,CAAC,CAC8B;IAEtD;;OAEG;IACH,GAAG,aAAc,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CACM;CACjD;AAED,QAAA,MAAM,kBAAkB,oBAA2B,CAAC;AAEpD,eAAe,kBAAkB,CAAC"}
\ No newline at end of file
diff --git a/lib/Runtime/BeforeExitListener.js b/lib/Runtime/BeforeExitListener.js
new file mode 100644
index 0000000..75cb36c
--- /dev/null
+++ b/lib/Runtime/BeforeExitListener.js
@@ -0,0 +1,37 @@
+/* eslint-disable @typescript-eslint/no-explicit-any */
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+/**
+ * The runtime has a single beforeExit function which is stored in the global
+ * object with a symbol key.
+ * The symbol is not exported.
+ * The process.beforeExit listener is setup in index.js along with all other
+ * top-level process event listeners.
+ */
+// define a named symbol for the handler function
+const LISTENER_SYMBOL = Symbol.for("aws.lambda.beforeExit");
+const NO_OP_LISTENER = () => {
+ /* NoOp */
+};
+// export a setter
+class BeforeExitListener {
+ constructor() {
+ /**
+ * Call the listener function with no arguments.
+ */
+ this.invoke = () => global[LISTENER_SYMBOL]();
+ /**
+ * Reset the listener to a no-op function.
+ */
+ this.reset = () => (global[LISTENER_SYMBOL] = NO_OP_LISTENER);
+ /**
+ * Set the listener to the provided function.
+ */
+ this.set = (listener) => (global[LISTENER_SYMBOL] = listener);
+ this.reset();
+ }
+}
+const beforeExitListener = new BeforeExitListener();
+exports.default = beforeExitListener;
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmVmb3JlRXhpdExpc3RlbmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL1J1bnRpbWUvQmVmb3JlRXhpdExpc3RlbmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHVEQUF1RDtBQUN2RCw4RUFBOEU7QUFFOUUsWUFBWSxDQUFDOztBQUliOzs7Ozs7R0FNRztBQUVILGlEQUFpRDtBQUNqRCxNQUFNLGVBQWUsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLHVCQUF1QixDQUFDLENBQUM7QUFFNUQsTUFBTSxjQUFjLEdBQUcsR0FBRyxFQUFFO0lBQzFCLFVBQVU7QUFDWixDQUFDLENBQUM7QUFFRixrQkFBa0I7QUFDbEIsTUFBTSxrQkFBa0I7SUFDdEI7UUFJQTs7V0FFRztRQUNILFdBQU0sR0FBRyxHQUFTLEVBQUUsQ0FBRSxNQUFjLENBQUMsZUFBZSxDQUFDLEVBQUUsQ0FBQztRQUV4RDs7V0FFRztRQUNILFVBQUssR0FBRyxHQUFpQixFQUFFLENBQ3pCLENBQUUsTUFBYyxDQUFDLGVBQWUsQ0FBQyxHQUFHLGNBQWMsQ0FBQyxDQUFDO1FBRXREOztXQUVHO1FBQ0gsUUFBRyxHQUFHLENBQUMsUUFBb0IsRUFBZ0IsRUFBRSxDQUMzQyxDQUFFLE1BQWMsQ0FBQyxlQUFlLENBQUMsR0FBRyxRQUFRLENBQUMsQ0FBQztRQWxCOUMsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQ2YsQ0FBQztDQWtCRjtBQUVELE1BQU0sa0JBQWtCLEdBQUcsSUFBSSxrQkFBa0IsRUFBRSxDQUFDO0FBRXBELGtCQUFlLGtCQUFrQixDQUFDIn0=
\ No newline at end of file
diff --git a/lib/Runtime/CallbackContext.d.ts b/lib/Runtime/CallbackContext.d.ts
new file mode 100644
index 0000000..36d02a7
--- /dev/null
+++ b/lib/Runtime/CallbackContext.d.ts
@@ -0,0 +1,21 @@
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+import { ICallbackContext, CallbackFunction } from "../Common";
+import { IRuntimeClient } from "../RuntimeClient";
+/**
+ * Construct the base-context object which includes the required flags and
+ * callback methods for the Node programming model.
+ *
+ * @param client {Client}
+ * The Runtime client used to post results/errors.
+ * @param id {string}
+ * The invokeId for the current invocation.
+ * @param scheduleNext {function}
+ * A function which takes no params and immediately schedules the next
+ * iteration of the invoke loop.
+ * @returns [callback, context]
+ * The same function and context object, but wrapped such that only the
+ * first call to any function will be successful. All subsequent calls are
+ * a no-op.
+ */
+export declare const build: (client: IRuntimeClient, id: string, scheduleNext: () => void) => [CallbackFunction, ICallbackContext];
+//# sourceMappingURL=CallbackContext.d.ts.map
\ No newline at end of file
diff --git a/lib/Runtime/CallbackContext.d.ts.map b/lib/Runtime/CallbackContext.d.ts.map
new file mode 100644
index 0000000..ac4aec3
--- /dev/null
+++ b/lib/Runtime/CallbackContext.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"CallbackContext.d.ts","sourceRoot":"","sources":["../../src/Runtime/CallbackContext.ts"],"names":[],"mappings":"AACA,8EAA8E;AAK9E,OAAO,EAEL,gBAAgB,EAEhB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,WACR,cAAc,MAClB,MAAM,gBACI,MAAM,IAAI,KACvB,CAAC,gBAAgB,EAAE,gBAAgB,CAGrC,CAAC"}
\ No newline at end of file
diff --git a/lib/Runtime/CallbackContext.js b/lib/Runtime/CallbackContext.js
new file mode 100644
index 0000000..e439fa5
--- /dev/null
+++ b/lib/Runtime/CallbackContext.js
@@ -0,0 +1,157 @@
+/* eslint-disable no-console */
+/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.build = void 0;
+const BeforeExitListener_1 = __importDefault(require("./BeforeExitListener"));
+const Errors = __importStar(require("../Errors"));
+/**
+ * Construct the base-context object which includes the required flags and
+ * callback methods for the Node programming model.
+ *
+ * @param client {Client}
+ * The Runtime client used to post results/errors.
+ * @param id {string}
+ * The invokeId for the current invocation.
+ * @param scheduleNext {function}
+ * A function which takes no params and immediately schedules the next
+ * iteration of the invoke loop.
+ * @returns [callback, context]
+ * The same function and context object, but wrapped such that only the
+ * first call to any function will be successful. All subsequent calls are
+ * a no-op.
+ */
+exports.build = function (client, id, scheduleNext) {
+ const [callback, context] = _rawCallbackContext(client, id, scheduleNext);
+ return _wrappedCallbackContext(callback, context);
+};
+function _homogeneousError(err) {
+ if (err instanceof Error) {
+ return err;
+ }
+ else {
+ return new Error(err);
+ }
+}
+/**
+ * Build the callback function and the part of the context which exposes
+ * the succeed/fail/done callbacks.
+ * @param client {Client}
+ * The Runtime client used to post results/errors.
+ * @param id {string}
+ * The invokeId for the current invocation.
+ * @param scheduleNext {function}
+ * A function which takes no params and immediately schedules the next
+ * iteration of the invoke loop.
+ */
+function _rawCallbackContext(client, id, scheduleNext) {
+ const postError = (err, callback) => {
+ const homogeneousError = _homogeneousError(err);
+ console.error("Invoke Error", Errors.toFormatted(homogeneousError));
+ client.postInvocationError(err, id, callback);
+ };
+ const complete = (result, callback) => {
+ client.postInvocationResponse(result, id, callback);
+ };
+ let waitForEmptyEventLoop = true;
+ const callback = (err, result) => {
+ BeforeExitListener_1.default.reset();
+ if (err !== undefined && err !== null) {
+ postError(err, scheduleNext);
+ }
+ else {
+ complete(result, () => {
+ if (!waitForEmptyEventLoop) {
+ scheduleNext();
+ }
+ else {
+ BeforeExitListener_1.default.set(scheduleNext);
+ }
+ });
+ }
+ };
+ const done = (err, result) => {
+ BeforeExitListener_1.default.reset();
+ if (err !== undefined && err !== null) {
+ postError(err, scheduleNext);
+ }
+ else {
+ complete(result, scheduleNext);
+ }
+ };
+ const succeed = (result) => {
+ done(null, result);
+ };
+ const fail = (err) => {
+ if (err === undefined || err === null) {
+ done("handled");
+ }
+ else {
+ done(err);
+ }
+ };
+ const callbackContext = {
+ get callbackWaitsForEmptyEventLoop() {
+ return waitForEmptyEventLoop;
+ },
+ set callbackWaitsForEmptyEventLoop(value) {
+ waitForEmptyEventLoop = value;
+ },
+ succeed,
+ fail,
+ done,
+ };
+ return [callback, callbackContext];
+}
+/**
+ * Wraps the callback and context so that only the first call to any callback
+ * succeeds.
+ * @param callback {function}
+ * the node-style callback function that was previously generated but not
+ * yet wrapped.
+ * @param callbackContext {object}
+ * The previously generated callbackContext object that contains
+ * getter/setters for the contextWaitsForEmptyeventLoop flag and the
+ * succeed/fail/done functions.
+ * @return [callback, context]
+ */
+function _wrappedCallbackContext(callback, callbackContext) {
+ let finished = false;
+ // eslint-disable-next-line @typescript-eslint/ban-types
+ const onlyAllowFirstCall = function (toWrap) {
+ return function (...args) {
+ if (!finished) {
+ // eslint-disable-next-line prefer-spread
+ toWrap.apply(null, args);
+ finished = true;
+ }
+ };
+ };
+ callbackContext.succeed = onlyAllowFirstCall(callbackContext.succeed);
+ callbackContext.fail = onlyAllowFirstCall(callbackContext.fail);
+ callbackContext.done = onlyAllowFirstCall(callbackContext.done);
+ return [onlyAllowFirstCall(callback), callbackContext];
+}
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FsbGJhY2tDb250ZXh0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL1J1bnRpbWUvQ2FsbGJhY2tDb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLCtCQUErQjtBQUMvQiw4RUFBOEU7QUFFOUUsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRWIsOEVBQXNEO0FBT3RELGtEQUFvQztBQUdwQzs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7QUFDVSxRQUFBLEtBQUssR0FBRyxVQUNuQixNQUFzQixFQUN0QixFQUFVLEVBQ1YsWUFBd0I7SUFFeEIsTUFBTSxDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsR0FBRyxtQkFBbUIsQ0FBQyxNQUFNLEVBQUUsRUFBRSxFQUFFLFlBQVksQ0FBQyxDQUFDO0lBQzFFLE9BQU8sdUJBQXVCLENBQUMsUUFBUSxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3BELENBQUMsQ0FBQztBQUVGLFNBQVMsaUJBQWlCLENBQUMsR0FBMkI7SUFDcEQsSUFBSSxHQUFHLFlBQVksS0FBSyxFQUFFO1FBQ3hCLE9BQU8sR0FBRyxDQUFDO0tBQ1o7U0FBTTtRQUNMLE9BQU8sSUFBSSxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7S0FDdkI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FJO1FBQ0osSUFBSTtLQUNMLENBQUM7SUFFRixPQUFPLENBQUMsUUFBUSxFQUFFLGVBQWUsQ0FBQyxDQUFDO0FBQ3JDLENBQUM7QUFFRDs7Ozs7Ozs7Ozs7R0FXRztBQUNILFNBQVMsdUJBQXVCLENBQzlCLFFBQTBCLEVBQzFCLGVBQWlDO0lBRWpDLElBQUksUUFBUSxHQUFHLEtBQUssQ0FBQztJQUNyQix3REFBd0Q7SUFDeEQsTUFBTSxrQkFBa0IsR0FBRyxVQUFVLE1BQWdCO1FBQ25ELE9BQU8sVUFBVSxHQUFHLElBQWU7WUFDakMsSUFBSSxDQUFDLFFBQVEsRUFBRTtnQkFDYix5Q0FBeUM7Z0JBQ3pDLE1BQU0sQ0FBQyxLQUFLLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFDO2dCQUN6QixRQUFRLEdBQUcsSUFBSSxDQUFDO2FBQ2pCO1FBQ0gsQ0FBQyxDQUFDO0lBQ0osQ0FBQyxDQUFDO0lBRUYsZUFBZSxDQUFDLE9BQU8sR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEUsZUFBZSxDQUFDLElBQUksR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDaEUsZUFBZSxDQUFDLElBQUksR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFaEUsT0FBTyxDQUFDLGtCQUFrQixDQUFDLFFBQVEsQ0FBQyxFQUFFLGVBQWUsQ0FBQyxDQUFDO0FBQ3pELENBQUMifQ==
\ No newline at end of file
diff --git a/lib/Runtime/InvokeContext.d.ts b/lib/Runtime/InvokeContext.d.ts
new file mode 100644
index 0000000..8e374ce
--- /dev/null
+++ b/lib/Runtime/InvokeContext.d.ts
@@ -0,0 +1,53 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines the InvokeContext and supporting functions. The
+ * InvokeContext is responsible for pulling information from the invoke headers
+ * and for wrapping the Runtime Client object's error and response functions.
+ */
+///
+import { IncomingHttpHeaders } from "http";
+import { ICallbackContext, IHeaderData, IEnvironmentData } from "../Common";
+export default class InvokeContext {
+ headers: IncomingHttpHeaders;
+ constructor(headers: IncomingHttpHeaders);
+ private getHeaderValue;
+ /**
+ * The invokeId for this request.
+ */
+ get invokeId(): string;
+ /**
+ * The header data for this request.
+ */
+ get headerData(): IHeaderData;
+ /**
+ * Push relevant invoke data into the logging context.
+ */
+ updateLoggingContext(): void;
+ /**
+ * Attach all of the relavant environmental and invocation data to the
+ * provided object.
+ * This method can throw if the headers are malformed and cannot be parsed.
+ * @param callbackContext {Object}
+ * The callbackContext object returned by a call to buildCallbackContext().
+ * @return {Object}
+ * The user context object with all required data populated from the headers
+ * and environment variables.
+ */
+ attachEnvironmentData(callbackContext: ICallbackContext): ICallbackContext & IEnvironmentData & IHeaderData;
+ /**
+ * All parts of the user-facing context object which are provided through
+ * environment variables.
+ */
+ private _environmentalData;
+ /**
+ * All parts of the user-facing context object which are provided through
+ * request headers.
+ */
+ private _headerData;
+ /**
+ * Forward the XRay header into the environment variable.
+ */
+ private _forwardXRay;
+}
+//# sourceMappingURL=InvokeContext.d.ts.map
\ No newline at end of file
diff --git a/lib/Runtime/InvokeContext.d.ts.map b/lib/Runtime/InvokeContext.d.ts.map
new file mode 100644
index 0000000..a0e2444
--- /dev/null
+++ b/lib/Runtime/InvokeContext.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"InvokeContext.d.ts","sourceRoot":"","sources":["../../src/Runtime/InvokeContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AAKnB,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,EAAE,mBAAmB,CAAC;gBAEjB,OAAO,EAAE,mBAAmB;IAIxC,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAIrB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,WAAW,CAE5B;IAED;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;;;;;;;;OASG;IACH,qBAAqB,CACnB,eAAe,EAAE,gBAAgB,GAChC,gBAAgB,GAAG,gBAAgB,GAAG,WAAW;IASpD;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;;OAGG;IACH,OAAO,CAAC,WAAW;IAqBnB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB"}
\ No newline at end of file
diff --git a/lib/Runtime/InvokeContext.js b/lib/Runtime/InvokeContext.js
new file mode 100644
index 0000000..022d683
--- /dev/null
+++ b/lib/Runtime/InvokeContext.js
@@ -0,0 +1,140 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines the InvokeContext and supporting functions. The
+ * InvokeContext is responsible for pulling information from the invoke headers
+ * and for wrapping the Runtime Client object's error and response functions.
+ */
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const assert_1 = require("assert");
+const Common_1 = require("../Common");
+const LogPatch_1 = __importDefault(require("../utils/LogPatch"));
+const setCurrentRequestId = LogPatch_1.default.setCurrentRequestId;
+class InvokeContext {
+ constructor(headers) {
+ this.headers = _enforceLowercaseKeys(headers);
+ }
+ getHeaderValue(key) {
+ const headerVal = this.headers[key];
+ switch (typeof headerVal) {
+ case "undefined":
+ return undefined;
+ case "string":
+ return headerVal;
+ default:
+ if (headerVal.length == 0) {
+ return undefined;
+ }
+ return headerVal[0];
+ }
+ }
+ /**
+ * The invokeId for this request.
+ */
+ get invokeId() {
+ const id = this.getHeaderValue(Common_1.INVOKE_HEADER.AWSRequestId);
+ assert_1.strict.ok(id, "invocation id is missing or invalid");
+ return id;
+ }
+ /**
+ * The header data for this request.
+ */
+ get headerData() {
+ return this._headerData();
+ }
+ /**
+ * Push relevant invoke data into the logging context.
+ */
+ updateLoggingContext() {
+ setCurrentRequestId(this.invokeId);
+ }
+ /**
+ * Attach all of the relavant environmental and invocation data to the
+ * provided object.
+ * This method can throw if the headers are malformed and cannot be parsed.
+ * @param callbackContext {Object}
+ * The callbackContext object returned by a call to buildCallbackContext().
+ * @return {Object}
+ * The user context object with all required data populated from the headers
+ * and environment variables.
+ */
+ attachEnvironmentData(callbackContext) {
+ this._forwardXRay();
+ return Object.assign(callbackContext, this._environmentalData(), this._headerData());
+ }
+ /**
+ * All parts of the user-facing context object which are provided through
+ * environment variables.
+ */
+ _environmentalData() {
+ return {
+ functionVersion: process.env["AWS_LAMBDA_FUNCTION_VERSION"],
+ functionName: process.env["AWS_LAMBDA_FUNCTION_NAME"],
+ memoryLimitInMB: process.env["AWS_LAMBDA_FUNCTION_MEMORY_SIZE"],
+ logGroupName: process.env["AWS_LAMBDA_LOG_GROUP_NAME"],
+ logStreamName: process.env["AWS_LAMBDA_LOG_STREAM_NAME"],
+ };
+ }
+ /**
+ * All parts of the user-facing context object which are provided through
+ * request headers.
+ */
+ _headerData() {
+ const deadline = parseInt(this.getHeaderValue(Common_1.INVOKE_HEADER.DeadlineMs) || "");
+ return {
+ clientContext: _parseJson(this.getHeaderValue(Common_1.INVOKE_HEADER.ClientContext), "ClientContext"),
+ identity: _parseJson(this.getHeaderValue(Common_1.INVOKE_HEADER.CognitoIdentity), "CognitoIdentity"),
+ invokedFunctionArn: this.getHeaderValue(Common_1.INVOKE_HEADER.ARN),
+ awsRequestId: this.getHeaderValue(Common_1.INVOKE_HEADER.AWSRequestId),
+ getRemainingTimeInMillis: function () {
+ return deadline - Date.now();
+ },
+ };
+ }
+ /**
+ * Forward the XRay header into the environment variable.
+ */
+ _forwardXRay() {
+ if (this.getHeaderValue(Common_1.INVOKE_HEADER.XRayTrace)) {
+ process.env["_X_AMZN_TRACE_ID"] = this.getHeaderValue(Common_1.INVOKE_HEADER.XRayTrace);
+ }
+ else {
+ delete process.env["_X_AMZN_TRACE_ID"];
+ }
+ }
+}
+exports.default = InvokeContext;
+/**
+ * Parse a JSON string and throw a readable error if something fails.
+ * @param jsonString {string} - the string to attempt to parse
+ * @param name {string} - the name to use when describing the string in an error
+ * @return object - the parsed object
+ * @throws if jsonString cannot be parsed
+ */
+function _parseJson(jsonString, name) {
+ if (jsonString !== undefined) {
+ try {
+ return JSON.parse(jsonString);
+ }
+ catch (err) {
+ throw new Error(`Cannot parse ${name} as json: ${err.toString()}`);
+ }
+ }
+ else {
+ return undefined;
+ }
+}
+/**
+ * Construct a copy of an object such that all of its keys are lowercase.
+ */
+function _enforceLowercaseKeys(original) {
+ return Object.keys(original).reduce((enforced, originalKey) => {
+ enforced[originalKey.toLowerCase()] = original[originalKey];
+ return enforced;
+ }, {});
+}
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW52b2tlQ29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9SdW50aW1lL0ludm9rZUNvbnRleHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsWUFBWSxDQUFDOzs7OztBQUViLG1DQUEwQztBQUUxQyxzQ0FLbUI7QUFDbkIsaUVBQXlDO0FBRXpDLE1BQU0sbUJBQW1CLEdBQUcsa0JBQVEsQ0FBQyxtQkFBbUIsQ0FBQztBQUV6RCxNQUFxQixhQUFhO0lBR2hDLFlBQVksT0FBNEI7UUFDdEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxxQkFBcUIsQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNoRCxDQUFDO0lBRU8sY0FBYyxDQUFDLEdBQVc7U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BQyxXQUFXLENBQUMsQ0FBQztRQUM1RCxPQUFPLFFBQVEsQ0FBQztJQUNsQixDQUFDLEVBQUUsRUFBeUIsQ0FBQyxDQUFDO0FBQ2hDLENBQUMifQ==
\ No newline at end of file
diff --git a/lib/Runtime/Runtime.d.ts b/lib/Runtime/Runtime.d.ts
new file mode 100644
index 0000000..6505301
--- /dev/null
+++ b/lib/Runtime/Runtime.d.ts
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines the top-level Runtime class which controls the
+ * bootstrap's execution flow.
+ */
+import { HandlerFunction, IErrorCallbacks } from "../Common";
+import { IRuntimeClient } from "../RuntimeClient";
+export default class Runtime {
+ client: IRuntimeClient;
+ errorCallbacks: IErrorCallbacks;
+ handler: HandlerFunction;
+ constructor(client: IRuntimeClient, handler: HandlerFunction, errorCallbacks: IErrorCallbacks);
+ /**
+ * Schedule the next loop iteration to start at the beginning of the next time
+ * around the event loop.
+ */
+ scheduleIteration(): void;
+ /**
+ * Wait for the next invocation, process it, and schedule the next iteration.
+ */
+ handleOnce(): Promise;
+ /**
+ * Replace the error handler callbacks.
+ * @param {String} invokeId
+ */
+ private _setErrorCallbacks;
+ /**
+ * Setup the 'beforeExit' listener that is used if the callback is never
+ * called and the handler is not async.
+ * CallbackContext replaces the listener if a callback is invoked.
+ */
+ private _setDefaultExitListener;
+}
+//# sourceMappingURL=Runtime.d.ts.map
\ No newline at end of file
diff --git a/lib/Runtime/Runtime.d.ts.map b/lib/Runtime/Runtime.d.ts.map
new file mode 100644
index 0000000..0712b32
--- /dev/null
+++ b/lib/Runtime/Runtime.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/Runtime/Runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,cAAc,EAAE,eAAe,CAAC;IAChC,OAAO,EAAE,eAAe,CAAC;gBAGvB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,eAAe,EACxB,cAAc,EAAE,eAAe;IAOjC;;;OAGG;IACH,iBAAiB,IAAI,IAAI;IAwBzB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BjC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAOhC"}
\ No newline at end of file
diff --git a/lib/Runtime/Runtime.js b/lib/Runtime/Runtime.js
new file mode 100644
index 0000000..9556629
--- /dev/null
+++ b/lib/Runtime/Runtime.js
@@ -0,0 +1,118 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines the top-level Runtime class which controls the
+ * bootstrap's execution flow.
+ */
+"use strict";
+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
+}) : (function(o, m, k, k2) {
+ if (k2 === undefined) k2 = k;
+ o[k2] = m[k];
+}));
+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
+}) : function(o, v) {
+ o["default"] = v;
+});
+var __importStar = (this && this.__importStar) || function (mod) {
+ if (mod && mod.__esModule) return mod;
+ var result = {};
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
+ __setModuleDefault(result, mod);
+ return result;
+};
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+const BeforeExitListener_1 = __importDefault(require("./BeforeExitListener"));
+const CallbackContext = __importStar(require("./CallbackContext"));
+const InvokeContext_1 = __importDefault(require("./InvokeContext"));
+class Runtime {
+ constructor(client, handler, errorCallbacks) {
+ this.client = client;
+ this.handler = handler;
+ this.errorCallbacks = errorCallbacks;
+ }
+ /**
+ * Schedule the next loop iteration to start at the beginning of the next time
+ * around the event loop.
+ */
+ scheduleIteration() {
+ setImmediate(() => {
+ this.handleOnce().then(
+ // Success is a no-op at this level. There are 2 cases:
+ // 1 - The user used one of the callback functions which already
+ // schedules the next iteration.
+ // 2 - The next iteration is not scheduled because the
+ // waitForEmptyEventLoop was set. In this case the beforeExit
+ // handler will automatically start the next iteration.
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
+ () => { },
+ // Errors should not reach this level in typical execution. If they do
+ // it's a sign of an issue in the Client or a bug in the runtime. So
+ // dump it to the console and attempt to report it as a Runtime error.
+ (err) => {
+ // eslint-disable-next-line no-console
+ console.log(`Unexpected Top Level Error: ${err.toString()}`);
+ this.errorCallbacks.uncaughtException(err);
+ });
+ });
+ }
+ /**
+ * Wait for the next invocation, process it, and schedule the next iteration.
+ */
+ async handleOnce() {
+ const { bodyJson, headers } = await this.client.nextInvocation();
+ const invokeContext = new InvokeContext_1.default(headers);
+ invokeContext.updateLoggingContext();
+ const [callback, callbackContext] = CallbackContext.build(this.client, invokeContext.invokeId, this.scheduleIteration.bind(this));
+ try {
+ this._setErrorCallbacks(invokeContext.invokeId);
+ this._setDefaultExitListener(invokeContext.invokeId);
+ const result = this.handler(JSON.parse(bodyJson), invokeContext.attachEnvironmentData(callbackContext), callback);
+ if (_isPromise(result)) {
+ result
+ .then(callbackContext.succeed, callbackContext.fail)
+ .catch(callbackContext.fail);
+ }
+ }
+ catch (err) {
+ callback(err);
+ }
+ }
+ /**
+ * Replace the error handler callbacks.
+ * @param {String} invokeId
+ */
+ _setErrorCallbacks(invokeId) {
+ this.errorCallbacks.uncaughtException = (error) => {
+ this.client.postInvocationError(error, invokeId, () => {
+ process.exit(129);
+ });
+ };
+ this.errorCallbacks.unhandledRejection = (error) => {
+ this.client.postInvocationError(error, invokeId, () => {
+ process.exit(128);
+ });
+ };
+ }
+ /**
+ * Setup the 'beforeExit' listener that is used if the callback is never
+ * called and the handler is not async.
+ * CallbackContext replaces the listener if a callback is invoked.
+ */
+ _setDefaultExitListener(invokeId) {
+ BeforeExitListener_1.default.set(() => {
+ this.client.postInvocationResponse(null, invokeId, () => this.scheduleIteration());
+ });
+ }
+}
+exports.default = Runtime;
+function _isPromise(obj) {
+ return obj instanceof Promise;
+}
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUnVudGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9SdW50aW1lL1J1bnRpbWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7O0dBS0c7QUFFSCxZQUFZLENBQUM7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUViLDhFQUFzRDtBQUV0RCxtRUFBcUQ7QUFDckQsb0VBQTRDO0FBRzVDLE1BQXFCLE9BQU87SUFLMUIsWUFDRSxNQUFzQixFQUN0QixPQUF3QixFQUN4QixjQUErQjtRQUUvQixJQUFJLENBQUMsTUFBTSxHQUFHLE1BQU0sQ0FBQztRQUNyQixJQUFJLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQztRQUN2QixJQUFJLENBQUMsY0FBYyxHQUFHLGNBQWMsQ0FBQztJQUN2QyxDQUFDO0lBRUQ7OztPQUdHO0lBQ0gsaUJBQWlCO1FBQ2YsWUFBWSxDQUFDLEdBQUcsRUFBRTtZQUNoQixJQUFJLENBQUMsVUFBVSxFQUFFLENBQUMsSUFBSTtZQUNwQix1REFBdUQ7WUFDdkQsZ0VBQWdFO1lBQ2hFLG9DQUFvQztZQUNwQyxzREFBc0Q7WUFDdEQs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UNMLENBQUMsQ0FBQztJQUNKLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ssdUJBQXVCLENBQUMsUUFBZ0I7UUFDOUMsNEJBQWtCLENBQUMsR0FBRyxDQUFDLEdBQUcsRUFBRTtZQUMxQixJQUFJLENBQUMsTUFBTSxDQUFDLHNCQUFzQixDQUFDLElBQUksRUFBRSxRQUFRLEVBQUUsR0FBRyxFQUFFLENBQ3RELElBQUksQ0FBQyxpQkFBaUIsRUFBRSxDQUN6QixDQUFDO1FBQ0osQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDO0NBQ0Y7QUExR0QsMEJBMEdDO0FBRUQsU0FBUyxVQUFVLENBQUMsR0FBK0I7SUFDakQsT0FBTyxHQUFHLFlBQVksT0FBTyxDQUFDO0FBQ2hDLENBQUMifQ==
\ No newline at end of file
diff --git a/lib/Runtime/index.d.ts b/lib/Runtime/index.d.ts
new file mode 100644
index 0000000..caea962
--- /dev/null
+++ b/lib/Runtime/index.d.ts
@@ -0,0 +1,6 @@
+/**
+ * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ */
+import Runtime from "./Runtime";
+export default Runtime;
+//# sourceMappingURL=index.d.ts.map
\ No newline at end of file
diff --git a/lib/Runtime/index.d.ts.map b/lib/Runtime/index.d.ts.map
new file mode 100644
index 0000000..b8d8f10
--- /dev/null
+++ b/lib/Runtime/index.d.ts.map
@@ -0,0 +1 @@
+{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,eAAe,OAAO,CAAC"}
\ No newline at end of file
diff --git a/lib/Runtime/index.js b/lib/Runtime/index.js
new file mode 100644
index 0000000..6e00f32
--- /dev/null
+++ b/lib/Runtime/index.js
@@ -0,0 +1,11 @@
+"use strict";
+var __importDefault = (this && this.__importDefault) || function (mod) {
+ return (mod && mod.__esModule) ? mod : { "default": mod };
+};
+Object.defineProperty(exports, "__esModule", { value: true });
+/**
+ * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ */
+const Runtime_1 = __importDefault(require("./Runtime"));
+exports.default = Runtime_1.default;
+//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvUnVudGltZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBOztHQUVHO0FBQ0gsd0RBQWdDO0FBRWhDLGtCQUFlLGlCQUFPLENBQUMifQ==
\ No newline at end of file
diff --git a/lib/RuntimeClient/RuntimeClient.d.ts b/lib/RuntimeClient/RuntimeClient.d.ts
new file mode 100644
index 0000000..7c6820e
--- /dev/null
+++ b/lib/RuntimeClient/RuntimeClient.d.ts
@@ -0,0 +1,79 @@
+/**
+ * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * This module defines the Runtime client which is responsible for all HTTP
+ * interactions with the Runtime layer.
+ */
+///
+import { Agent, RequestOptions, IncomingMessage, ClientRequest, OutgoingHttpHeaders } from "http";
+import { URL } from "url";
+import { InvocationResponse, NativeClient } from "../Common";
+interface HttpModule {
+ Agent: typeof Agent;
+ request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
+}
+export interface IRuntimeClient {
+ nextInvocation: () => Promise;
+ postInvocationError: (error: unknown, id: string, callback: () => void) => void;
+ postInvocationResponse: (response: unknown, id: string, callback: () => void) => void;
+}
+/**
+ * Objects of this class are responsible for all interactions with the Runtime
+ * API.
+ */
+export default class RuntimeClient implements IRuntimeClient {
+ agent: Agent;
+ http: HttpModule;
+ nativeClient: NativeClient;
+ userAgent: string;
+ useAlternativeClient: boolean;
+ hostname: string;
+ port: number;
+ constructor(hostnamePort: string, httpClient?: HttpModule, nativeClient?: NativeClient);
+ /**
+ * Complete and invocation with the provided response.
+ * @param {Object} response
+ * An arbitrary object to convert to JSON and send back as as response.
+ * @param {String} id
+ * The invocation ID.
+ * @param {function()} callback
+ * The callback to run after the POST response ends
+ */
+ postInvocationResponse(response: unknown, id: string, callback: () => void): void;
+ /**
+ * Post an initialization error to the Runtime API.
+ * @param {Error} error
+ * @param {function()} callback
+ * The callback to run after the POST response ends
+ */
+ postInitError(error: unknown, callback: () => void): void;
+ /**
+ * Post an invocation error to the Runtime API
+ * @param {Error} error
+ * @param {String} id
+ * The invocation ID for the in-progress invocation.
+ * @param {function()} callback
+ * The callback to run after the POST response ends
+ */
+ postInvocationError(error: unknown, id: string, callback: () => void): void;
+ /**
+ * Get the next invocation.
+ * @return {PromiseLike.