@fintalk.ai/lambda-handlers 1.0.4 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -20
- package/lib/errors/bad-request-error.d.ts +1 -1
- package/lib/errors/bad-request-error.js +3 -2
- package/lib/errors/bad-request-error.js.map +1 -1
- package/lib/errors/conflict-error.d.ts +1 -1
- package/lib/errors/conflict-error.js +4 -2
- package/lib/errors/conflict-error.js.map +1 -1
- package/lib/errors/fintalk-error.d.ts +11 -6
- package/lib/errors/fintalk-error.js +3 -2
- package/lib/errors/fintalk-error.js.map +1 -1
- package/lib/errors/forbidden-error.d.ts +1 -1
- package/lib/errors/forbidden-error.js +4 -2
- package/lib/errors/forbidden-error.js.map +1 -1
- package/lib/errors/gone-error.d.ts +1 -1
- package/lib/errors/gone-error.js +4 -2
- package/lib/errors/gone-error.js.map +1 -1
- package/lib/errors/internal-server-error.d.ts +1 -1
- package/lib/errors/internal-server-error.js +4 -2
- package/lib/errors/internal-server-error.js.map +1 -1
- package/lib/errors/not-acceptable-error.d.ts +1 -1
- package/lib/errors/not-acceptable-error.js +4 -2
- package/lib/errors/not-acceptable-error.js.map +1 -1
- package/lib/errors/not-found-error.d.ts +1 -1
- package/lib/errors/not-found-error.js +4 -2
- package/lib/errors/not-found-error.js.map +1 -1
- package/lib/errors/payment-required-error.d.ts +1 -1
- package/lib/errors/payment-required-error.js +4 -2
- package/lib/errors/payment-required-error.js.map +1 -1
- package/lib/errors/precondition-failed-error.d.ts +1 -1
- package/lib/errors/precondition-failed-error.js +4 -2
- package/lib/errors/precondition-failed-error.js.map +1 -1
- package/lib/errors/service-unavailable-error.d.ts +1 -1
- package/lib/errors/service-unavailable-error.js +4 -2
- package/lib/errors/service-unavailable-error.js.map +1 -1
- package/lib/errors/teapot-error.d.ts +1 -1
- package/lib/errors/teapot-error.js +4 -2
- package/lib/errors/teapot-error.js.map +1 -1
- package/lib/errors/too-many-requests-error.d.ts +1 -1
- package/lib/errors/too-many-requests-error.js +4 -2
- package/lib/errors/too-many-requests-error.js.map +1 -1
- package/lib/errors/unauthorized-error.d.ts +1 -1
- package/lib/errors/unauthorized-error.js +4 -2
- package/lib/errors/unauthorized-error.js.map +1 -1
- package/lib/errors/unprocessable-entity-error.d.ts +1 -1
- package/lib/errors/unprocessable-entity-error.js +4 -3
- package/lib/errors/unprocessable-entity-error.js.map +1 -1
- package/lib/errors/websocket-error.d.ts +40 -0
- package/lib/errors/websocket-error.js +54 -0
- package/lib/errors/websocket-error.js.map +1 -0
- package/lib/handlers/api-proxy.js +150 -56
- package/lib/handlers/api-proxy.js.map +1 -1
- package/lib/handlers/api.d.ts +5 -1
- package/lib/handlers/api.js +130 -38
- package/lib/handlers/api.js.map +1 -1
- package/lib/handlers/authorizer.d.ts +7 -0
- package/lib/handlers/authorizer.js +181 -0
- package/lib/handlers/authorizer.js.map +1 -0
- package/lib/handlers/cloudwatch.d.ts +7 -0
- package/lib/handlers/cloudwatch.js +143 -0
- package/lib/handlers/cloudwatch.js.map +1 -0
- package/lib/handlers/invoke.d.ts +7 -1
- package/lib/handlers/invoke.js +101 -26
- package/lib/handlers/invoke.js.map +1 -1
- package/lib/handlers/kinesis.d.ts +13 -0
- package/lib/handlers/kinesis.js +193 -0
- package/lib/handlers/kinesis.js.map +1 -0
- package/lib/handlers/lambda-proxy/index.d.ts +8 -0
- package/lib/handlers/lambda-proxy/index.js +182 -0
- package/lib/handlers/lambda-proxy/index.js.map +1 -0
- package/lib/handlers/lambda-proxy/validate-event-data.d.ts +3 -0
- package/lib/handlers/lambda-proxy/validate-event-data.js +26 -0
- package/lib/handlers/lambda-proxy/validate-event-data.js.map +1 -0
- package/lib/handlers/sqs-v2.d.ts +5 -3
- package/lib/handlers/sqs-v2.js +109 -22
- package/lib/handlers/sqs-v2.js.map +1 -1
- package/lib/handlers/sqs.d.ts +11 -2
- package/lib/handlers/sqs.js +118 -16
- package/lib/handlers/sqs.js.map +1 -1
- package/lib/index.d.ts +4 -0
- package/lib/index.js +9 -1
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +8 -2
- package/lib/utils/check-envs.d.ts +3 -0
- package/lib/utils/check-envs.js +14 -0
- package/lib/utils/check-envs.js.map +1 -0
- package/lib/utils/convert-query-string.d.ts +3 -0
- package/lib/utils/convert-query-string.js +18 -0
- package/lib/utils/convert-query-string.js.map +1 -0
- package/lib/utils/extract-queue-name.d.ts +2 -0
- package/lib/utils/extract-queue-name.js +9 -0
- package/lib/utils/extract-queue-name.js.map +1 -0
- package/lib/utils/find-path.d.ts +2 -0
- package/lib/utils/find-path.js +14 -0
- package/lib/utils/find-path.js.map +1 -0
- package/lib/utils/kinesis-parse.d.ts +2 -0
- package/lib/utils/kinesis-parse.js +14 -0
- package/lib/utils/kinesis-parse.js.map +1 -0
- package/lib/utils/lower-case-headers.d.ts +2 -2
- package/lib/utils/lower-case-headers.js.map +1 -1
- package/lib/utils/parse-authorizer-request.d.ts +4 -0
- package/lib/utils/parse-authorizer-request.js +32 -0
- package/lib/utils/parse-authorizer-request.js.map +1 -0
- package/lib/utils/parse-path-params.d.ts +2 -0
- package/lib/utils/parse-path-params.js +14 -0
- package/lib/utils/parse-path-params.js.map +1 -0
- package/lib/utils/parse-request.d.ts +0 -1
- package/lib/utils/parse-request.js +3 -12
- package/lib/utils/parse-request.js.map +1 -1
- package/lib/utils/provider-flush.d.ts +4 -0
- package/lib/utils/provider-flush.js +81 -0
- package/lib/utils/provider-flush.js.map +1 -0
- package/lib/utils/sleep.d.ts +2 -0
- package/lib/utils/sleep.js +7 -0
- package/lib/utils/sleep.js.map +1 -0
- package/package.json +26 -34
|
@@ -21,10 +21,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
21
21
|
var fintalk_error_1 = __importDefault(require("./fintalk-error"));
|
|
22
22
|
var UnprocessableEntityError = (function (_super) {
|
|
23
23
|
__extends(UnprocessableEntityError, _super);
|
|
24
|
-
function UnprocessableEntityError(message, details) {
|
|
24
|
+
function UnprocessableEntityError(message, details, user_error_code) {
|
|
25
25
|
if (message === void 0) { message = 'Unprocessable Entity'; }
|
|
26
|
-
if (details === void 0) { details =
|
|
27
|
-
|
|
26
|
+
if (details === void 0) { details = []; }
|
|
27
|
+
if (user_error_code === void 0) { user_error_code = ''; }
|
|
28
|
+
var _this = _super.call(this, message, 422, details, user_error_code) || this;
|
|
28
29
|
Object.setPrototypeOf(_this, UnprocessableEntityError.prototype);
|
|
29
30
|
return _this;
|
|
30
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unprocessable-entity-error.js","sourceRoot":"","sources":["../../src/errors/unprocessable-entity-error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kEAA0C;AAE1C;IAAsD,4CAAY;IAChE,kCACE,OAAwC,EACxC,
|
|
1
|
+
{"version":3,"file":"unprocessable-entity-error.js","sourceRoot":"","sources":["../../src/errors/unprocessable-entity-error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,kEAA0C;AAE1C;IAAsD,4CAAY;IAChE,kCACE,OAAwC,EACxC,OAAmB,EACnB,eAA4B;QAF5B,wBAAA,EAAA,gCAAwC;QACxC,wBAAA,EAAA,YAAmB;QACnB,gCAAA,EAAA,oBAA4B;QAH9B,YAKE,kBAAM,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,CAAC,SAE9C;QADC,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAA;;IACjE,CAAC;IACH,+BAAC;AAAD,CAAC,AATD,CAAsD,uBAAY,GASjE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default class WebsocketError extends Error {
|
|
2
|
+
isTreated: boolean;
|
|
3
|
+
code: number;
|
|
4
|
+
details?: any;
|
|
5
|
+
constructor(message: string, code?: number, details?: any);
|
|
6
|
+
getDetails(): {
|
|
7
|
+
details?: undefined;
|
|
8
|
+
} | {
|
|
9
|
+
details: any;
|
|
10
|
+
};
|
|
11
|
+
toObject(): {
|
|
12
|
+
error: boolean;
|
|
13
|
+
status: number;
|
|
14
|
+
body: {
|
|
15
|
+
details?: undefined;
|
|
16
|
+
code: number;
|
|
17
|
+
message: string;
|
|
18
|
+
} | {
|
|
19
|
+
details: any;
|
|
20
|
+
code: number;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
details?: undefined;
|
|
24
|
+
name: string;
|
|
25
|
+
} | {
|
|
26
|
+
error: boolean;
|
|
27
|
+
status: number;
|
|
28
|
+
body: {
|
|
29
|
+
details?: undefined;
|
|
30
|
+
code: number;
|
|
31
|
+
message: string;
|
|
32
|
+
} | {
|
|
33
|
+
details: any;
|
|
34
|
+
code: number;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
details: any;
|
|
38
|
+
name: string;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
var WebsocketError = (function (_super) {
|
|
30
|
+
__extends(WebsocketError, _super);
|
|
31
|
+
function WebsocketError(message, code, details) {
|
|
32
|
+
var _this = _super.call(this, message) || this;
|
|
33
|
+
_this.isTreated = true;
|
|
34
|
+
_this.message = message;
|
|
35
|
+
_this.code = code || 400;
|
|
36
|
+
_this.details = details;
|
|
37
|
+
Object.setPrototypeOf(_this, WebsocketError.prototype);
|
|
38
|
+
return _this;
|
|
39
|
+
}
|
|
40
|
+
WebsocketError.prototype.getDetails = function () {
|
|
41
|
+
if (!this.details) {
|
|
42
|
+
return {};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
details: this.details,
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
WebsocketError.prototype.toObject = function () {
|
|
49
|
+
return __assign(__assign({ name: this.message }, this.getDetails()), { error: true, status: this.code, body: __assign({ code: this.code, message: this.message }, this.getDetails()) });
|
|
50
|
+
};
|
|
51
|
+
return WebsocketError;
|
|
52
|
+
}(Error));
|
|
53
|
+
exports.default = WebsocketError;
|
|
54
|
+
//# sourceMappingURL=websocket-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket-error.js","sourceRoot":"","sources":["../../src/errors/websocket-error.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;IAA4C,kCAAK;IAK/C,wBAAa,OAAe,EAAE,IAAa,EAAE,OAAa;QAA1D,YACE,kBAAM,OAAO,CAAC,SAQf;QANC,KAAI,CAAC,SAAS,GAAG,IAAI,CAAA;QACrB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,KAAI,CAAC,IAAI,GAAG,IAAI,IAAI,GAAG,CAAA;QACvB,KAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QAEtB,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;;IACvD,CAAC;IAED,mCAAU,GAAV;QACE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YACjB,OAAO,EAAE,CAAA;SACV;QAED,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAA;IACH,CAAC;IAED,iCAAQ,GAAR;QACE,2BACE,IAAI,EAAE,IAAI,CAAC,OAAO,IACf,IAAI,CAAC,UAAU,EAAE,KACpB,KAAK,EAAE,IAAI,EACX,MAAM,EAAE,IAAI,CAAC,IAAI,EACjB,IAAI,aACF,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,OAAO,EAAE,IAAI,CAAC,OAAO,IAClB,IAAI,CAAC,UAAU,EAAE,KAEvB;IACH,CAAC;IACH,qBAAC;AAAD,CAAC,AAvCD,CAA4C,KAAK,GAuChD"}
|
|
@@ -51,12 +51,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.LambdaApiProxyHandler = void 0;
|
|
54
|
+
var api_1 = require("@opentelemetry/api");
|
|
55
|
+
var core_1 = require("@opentelemetry/core");
|
|
56
|
+
var semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
57
|
+
var otlp_1 = require("@stone-ton/otlp");
|
|
54
58
|
var fintalk_logger_1 = __importDefault(require("fintalk-logger"));
|
|
55
59
|
var node_match_path_1 = require("node-match-path");
|
|
56
60
|
var constants_1 = require("../constants");
|
|
57
61
|
var not_found_error_1 = __importDefault(require("../errors/not-found-error"));
|
|
62
|
+
var check_envs_1 = __importDefault(require("../utils/check-envs"));
|
|
58
63
|
var compare_ignore_case_1 = __importDefault(require("../utils/compare-ignore-case"));
|
|
64
|
+
var convert_query_string_1 = __importDefault(require("../utils/convert-query-string"));
|
|
59
65
|
var parse_request_1 = __importDefault(require("../utils/parse-request"));
|
|
66
|
+
var provider_flush_1 = __importDefault(require("../utils/provider-flush"));
|
|
60
67
|
var LambdaApiProxyHandler = (function () {
|
|
61
68
|
function LambdaApiProxyHandler(options) {
|
|
62
69
|
this.routes = [];
|
|
@@ -97,63 +104,150 @@ var LambdaApiProxyHandler = (function () {
|
|
|
97
104
|
});
|
|
98
105
|
};
|
|
99
106
|
LambdaApiProxyHandler.prototype.handler = function (event, context) {
|
|
100
|
-
var _a;
|
|
101
107
|
return __awaiter(this, void 0, void 0, function () {
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
108
|
+
var activeContext;
|
|
109
|
+
var _this = this;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
(0, check_envs_1.default)(fintalk_logger_1.default);
|
|
112
|
+
activeContext = api_1.propagation.extract(api_1.context.active(), {
|
|
113
|
+
traceparent: event.headers.traceparent,
|
|
114
|
+
});
|
|
115
|
+
return [2, otlp_1.tracer.startActiveSpan('handler', {
|
|
116
|
+
kind: api_1.SpanKind.SERVER,
|
|
117
|
+
startTime: (0, core_1.hrTime)(),
|
|
118
|
+
}, activeContext, function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
119
|
+
var remainingTimeInMillis, timeout, spanContext, request, method, route, _a, response, error_1;
|
|
120
|
+
var _b;
|
|
121
|
+
var _c, _d, _e, _f, _g, _h, _j;
|
|
122
|
+
return __generator(this, function (_k) {
|
|
123
|
+
switch (_k.label) {
|
|
124
|
+
case 0:
|
|
125
|
+
remainingTimeInMillis = context.getRemainingTimeInMillis();
|
|
126
|
+
timeout = setTimeout(function () {
|
|
127
|
+
span.setStatus({
|
|
128
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
129
|
+
message: 'Detected an impending timeout',
|
|
130
|
+
});
|
|
131
|
+
span.end((0, core_1.hrTime)());
|
|
132
|
+
(0, provider_flush_1.default)(otlp_1.tracerProvider);
|
|
133
|
+
}, remainingTimeInMillis - 100);
|
|
134
|
+
_k.label = 1;
|
|
135
|
+
case 1:
|
|
136
|
+
_k.trys.push([1, 5, 6, 8]);
|
|
137
|
+
spanContext = span.spanContext();
|
|
138
|
+
fintalk_logger_1.default.setCustomArgs({
|
|
139
|
+
dd: {
|
|
140
|
+
trace_id: spanContext.traceId,
|
|
141
|
+
span_id: spanContext.spanId,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
request = (0, parse_request_1.default)(event, context);
|
|
145
|
+
span.setAttributes((_b = {},
|
|
146
|
+
_b[semantic_conventions_1.SemanticResourceAttributes.CLOUD_REGION] = process.env.AWS_REGION,
|
|
147
|
+
_b[semantic_conventions_1.SemanticResourceAttributes.CLOUD_PLATFORM] = semantic_conventions_1.CloudPlatformValues.AWS_LAMBDA,
|
|
148
|
+
_b['faas.version'] = process.env.AWS_EXECUTION_ENV,
|
|
149
|
+
_b[semantic_conventions_1.SemanticAttributes.FAAS_EXECUTION] = request.id,
|
|
150
|
+
_b[semantic_conventions_1.SemanticResourceAttributes.FAAS_MAX_MEMORY] = process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
|
|
151
|
+
_b[semantic_conventions_1.SemanticResourceAttributes.FAAS_NAME] = context.functionName,
|
|
152
|
+
_b[semantic_conventions_1.SemanticResourceAttributes.FAAS_ID] = context.invokedFunctionArn,
|
|
153
|
+
_b[semantic_conventions_1.SemanticAttributes.FAAS_TRIGGER] = semantic_conventions_1.FaasTriggerValues.HTTP,
|
|
154
|
+
_b['client.address'] = request.ip,
|
|
155
|
+
_b['server.address'] = event.requestContext.domainName,
|
|
156
|
+
_b['server.port'] = '443',
|
|
157
|
+
_b['http.request.method'] = request.method,
|
|
158
|
+
_b['url.path'] = request.path,
|
|
159
|
+
_b['url.query'] = (0, convert_query_string_1.default)(request.multiValueQuery),
|
|
160
|
+
_b['url.scheme'] = 'https',
|
|
161
|
+
_b['user_agent.original'] = request.userAgent,
|
|
162
|
+
_b));
|
|
163
|
+
method = event.httpMethod.toUpperCase();
|
|
164
|
+
if (method === 'OPTIONS') {
|
|
165
|
+
return [2, this.corsObject(event, constants_1.defaultHeaders)];
|
|
166
|
+
}
|
|
167
|
+
route = this.findRoute(event);
|
|
168
|
+
if (!route) {
|
|
169
|
+
fintalk_logger_1.default.warn({
|
|
170
|
+
message: 'Route not found',
|
|
171
|
+
path: event.path,
|
|
172
|
+
method: method,
|
|
173
|
+
});
|
|
174
|
+
throw new not_found_error_1.default();
|
|
175
|
+
}
|
|
176
|
+
span.setAttribute('http.route', route.path);
|
|
177
|
+
request = (0, parse_request_1.default)(event, context, route.path);
|
|
178
|
+
if (!route.auth) return [3, 3];
|
|
179
|
+
_a = request;
|
|
180
|
+
return [4, route.auth(request)];
|
|
181
|
+
case 2:
|
|
182
|
+
_a.auth = _k.sent();
|
|
183
|
+
_k.label = 3;
|
|
184
|
+
case 3:
|
|
185
|
+
span.setAttributes({
|
|
186
|
+
user_id: (_c = request.user) === null || _c === void 0 ? void 0 : _c.id,
|
|
187
|
+
email: (_d = request.user) === null || _d === void 0 ? void 0 : _d.email,
|
|
188
|
+
});
|
|
189
|
+
if (process.env.OTLP_LAMBDA_DEBUG === 'true') {
|
|
190
|
+
span.setAttributes({
|
|
191
|
+
'http.request.body': JSON.stringify(request.body),
|
|
192
|
+
'http.request.headers': JSON.stringify(request.headers),
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return [4, route.run(request, context)];
|
|
196
|
+
case 4:
|
|
197
|
+
response = _k.sent();
|
|
198
|
+
span.setAttribute('http.response.status_code', (_f = (_e = response.statusCode) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '200');
|
|
199
|
+
if (process.env.OTLP_LAMBDA_DEBUG === 'true') {
|
|
200
|
+
span.setAttributes({
|
|
201
|
+
'http.response.body': JSON.stringify(response.body),
|
|
202
|
+
'http.response.headers': JSON.stringify(response.headers),
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
206
|
+
return [2, {
|
|
207
|
+
headers: __assign(__assign({}, constants_1.defaultHeaders), response.headers),
|
|
208
|
+
multiValueHeaders: response.multiValueHeaders,
|
|
209
|
+
statusCode: (_g = response.statusCode) !== null && _g !== void 0 ? _g : 200,
|
|
210
|
+
body: JSON.stringify(response.body),
|
|
211
|
+
}];
|
|
212
|
+
case 5:
|
|
213
|
+
error_1 = _k.sent();
|
|
214
|
+
span.setAttributes({
|
|
215
|
+
'exception.message': error_1.message,
|
|
216
|
+
'exception.stacktrace': error_1.trace,
|
|
217
|
+
'http.response.status_code': (_j = (_h = error_1.code) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : '500',
|
|
218
|
+
});
|
|
219
|
+
span.setStatus({
|
|
220
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
221
|
+
message: error_1.message,
|
|
222
|
+
});
|
|
223
|
+
if (error_1.isTreated) {
|
|
224
|
+
return [2, {
|
|
225
|
+
headers: constants_1.defaultHeaders,
|
|
226
|
+
statusCode: error_1.code,
|
|
227
|
+
body: JSON.stringify(error_1.toObject()),
|
|
228
|
+
}];
|
|
229
|
+
}
|
|
230
|
+
fintalk_logger_1.default.error(error_1);
|
|
231
|
+
return [2, {
|
|
232
|
+
headers: constants_1.defaultHeaders,
|
|
233
|
+
statusCode: 500,
|
|
234
|
+
body: JSON.stringify({
|
|
235
|
+
error: {
|
|
236
|
+
message: 'Internal Server Error',
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
}];
|
|
240
|
+
case 6:
|
|
241
|
+
clearTimeout(timeout);
|
|
242
|
+
span.end((0, core_1.hrTime)());
|
|
243
|
+
return [4, (0, provider_flush_1.default)(otlp_1.tracerProvider)];
|
|
244
|
+
case 7:
|
|
245
|
+
_k.sent();
|
|
246
|
+
return [7];
|
|
247
|
+
case 8: return [2];
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}); })];
|
|
157
251
|
});
|
|
158
252
|
});
|
|
159
253
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-proxy.js","sourceRoot":"","sources":["../../src/handlers/api-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"api-proxy.js","sourceRoot":"","sources":["../../src/handlers/api-proxy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0CAK2B;AAC3B,4CAA4C;AAC5C,4EAK4C;AAC5C,wCAAwD;AAMxD,kEAAmC;AACnC,mDAAuC;AAEvC,0CAA6C;AAC7C,8EAAqD;AAKrD,mEAA2C;AAC3C,qFAA4D;AAC5D,uFA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AA;oCACrB,IAAI,CAAC,GAAG,CAAC,IAAA,aAAM,GAAE,CAAC,CAAA;oCAElB,WAAM,IAAA,wBAAa,EAAC,qBAAc,CAAC,EAAA;;oCAAnC,SAAmC,CAAA;;;;;yBAEtC,CACF,EAAA;;;KACF;IACH,4BAAC;AAAD,CAAC,AA1ND,IA0NC;AA1NY,sDAAqB"}
|
package/lib/handlers/api.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';
|
|
2
2
|
import { Controller } from '../models';
|
|
3
|
+
export interface Options {
|
|
4
|
+
path?: string;
|
|
5
|
+
}
|
|
3
6
|
export declare class LambdaApiHandler {
|
|
4
7
|
readonly controller: Controller;
|
|
5
|
-
|
|
8
|
+
readonly options: Options;
|
|
9
|
+
constructor(controller: Controller, options?: Options);
|
|
6
10
|
handler(event: APIGatewayProxyEvent, context: Context): Promise<APIGatewayProxyResult>;
|
|
7
11
|
}
|
package/lib/handlers/api.js
CHANGED
|
@@ -51,52 +51,144 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
51
51
|
};
|
|
52
52
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
53
|
exports.LambdaApiHandler = void 0;
|
|
54
|
+
var api_1 = require("@opentelemetry/api");
|
|
55
|
+
var core_1 = require("@opentelemetry/core");
|
|
56
|
+
var semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
57
|
+
var otlp_1 = require("@stone-ton/otlp");
|
|
54
58
|
var fintalk_logger_1 = __importDefault(require("fintalk-logger"));
|
|
55
59
|
var constants_1 = require("../constants");
|
|
60
|
+
var check_envs_1 = __importDefault(require("../utils/check-envs"));
|
|
61
|
+
var convert_query_string_1 = __importDefault(require("../utils/convert-query-string"));
|
|
56
62
|
var parse_request_1 = __importDefault(require("../utils/parse-request"));
|
|
63
|
+
var provider_flush_1 = __importDefault(require("../utils/provider-flush"));
|
|
57
64
|
var LambdaApiHandler = (function () {
|
|
58
|
-
function LambdaApiHandler(controller) {
|
|
65
|
+
function LambdaApiHandler(controller, options) {
|
|
66
|
+
if (options === void 0) { options = {}; }
|
|
59
67
|
this.controller = controller;
|
|
68
|
+
this.options = options;
|
|
60
69
|
}
|
|
61
70
|
LambdaApiHandler.prototype.handler = function (event, context) {
|
|
62
|
-
var _a;
|
|
63
71
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
72
|
+
var activeContext;
|
|
73
|
+
var _this = this;
|
|
74
|
+
return __generator(this, function (_a) {
|
|
75
|
+
(0, check_envs_1.default)(fintalk_logger_1.default);
|
|
76
|
+
activeContext = api_1.propagation.extract(api_1.context.active(), {
|
|
77
|
+
traceparent: event.headers.traceparent,
|
|
78
|
+
});
|
|
79
|
+
return [2, otlp_1.tracer.startActiveSpan('handler', {
|
|
80
|
+
kind: api_1.SpanKind.SERVER,
|
|
81
|
+
startTime: (0, core_1.hrTime)(),
|
|
82
|
+
}, activeContext, function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
+
var remainingTimeInMillis, timeout, spanContext, request, response, error_1;
|
|
84
|
+
var _a;
|
|
85
|
+
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
86
|
+
return __generator(this, function (_k) {
|
|
87
|
+
switch (_k.label) {
|
|
88
|
+
case 0:
|
|
89
|
+
remainingTimeInMillis = context.getRemainingTimeInMillis();
|
|
90
|
+
timeout = setTimeout(function () {
|
|
91
|
+
span.setStatus({
|
|
92
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
93
|
+
message: 'Detected an impending timeout',
|
|
94
|
+
});
|
|
95
|
+
span.end((0, core_1.hrTime)());
|
|
96
|
+
(0, provider_flush_1.default)(otlp_1.tracerProvider);
|
|
97
|
+
}, remainingTimeInMillis - 100);
|
|
98
|
+
_k.label = 1;
|
|
99
|
+
case 1:
|
|
100
|
+
_k.trys.push([1, 3, 4, 6]);
|
|
101
|
+
spanContext = span.spanContext();
|
|
102
|
+
fintalk_logger_1.default.setCustomArgs({
|
|
103
|
+
dd: {
|
|
104
|
+
trace_id: spanContext.traceId,
|
|
105
|
+
span_id: spanContext.spanId,
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
request = (0, parse_request_1.default)(event, context);
|
|
109
|
+
span.setAttributes((_a = {},
|
|
110
|
+
_a[semantic_conventions_1.SemanticResourceAttributes.CLOUD_REGION] = process.env.AWS_REGION,
|
|
111
|
+
_a[semantic_conventions_1.SemanticResourceAttributes.CLOUD_PLATFORM] = semantic_conventions_1.CloudPlatformValues.AWS_LAMBDA,
|
|
112
|
+
_a['faas.version'] = process.env.AWS_EXECUTION_ENV,
|
|
113
|
+
_a[semantic_conventions_1.SemanticAttributes.FAAS_EXECUTION] = request.id,
|
|
114
|
+
_a[semantic_conventions_1.SemanticResourceAttributes.FAAS_MAX_MEMORY] = process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE,
|
|
115
|
+
_a[semantic_conventions_1.SemanticResourceAttributes.FAAS_NAME] = context.functionName,
|
|
116
|
+
_a[semantic_conventions_1.SemanticResourceAttributes.FAAS_ID] = context.invokedFunctionArn,
|
|
117
|
+
_a[semantic_conventions_1.SemanticAttributes.FAAS_TRIGGER] = semantic_conventions_1.FaasTriggerValues.HTTP,
|
|
118
|
+
_a['client.address'] = request.ip,
|
|
119
|
+
_a['http.route'] = (_b = this.options.path) !== null && _b !== void 0 ? _b : request.path,
|
|
120
|
+
_a['server.address'] = event.requestContext.domainName,
|
|
121
|
+
_a['server.port'] = '443',
|
|
122
|
+
_a['http.request.method'] = request.method,
|
|
123
|
+
_a['url.path'] = request.path,
|
|
124
|
+
_a['url.query'] = (0, convert_query_string_1.default)(request.multiValueQuery),
|
|
125
|
+
_a['url.scheme'] = 'https',
|
|
126
|
+
_a['user_agent.original'] = request.userAgent,
|
|
127
|
+
_a.user_id = (_c = request.user) === null || _c === void 0 ? void 0 : _c.id,
|
|
128
|
+
_a.email = (_d = request.user) === null || _d === void 0 ? void 0 : _d.email,
|
|
129
|
+
_a));
|
|
130
|
+
if (process.env.OTLP_LAMBDA_DEBUG === 'true') {
|
|
131
|
+
span.setAttributes({
|
|
132
|
+
'http.request.body': JSON.stringify(request.body),
|
|
133
|
+
'http.request.headers': JSON.stringify(request.headers),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return [4, this.controller(request, context)];
|
|
137
|
+
case 2:
|
|
138
|
+
response = _k.sent();
|
|
139
|
+
span.setAttribute('http.response.status_code', (_f = (_e = response.statusCode) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : '200');
|
|
140
|
+
if (process.env.OTLP_LAMBDA_DEBUG === 'true') {
|
|
141
|
+
span.setAttributes({
|
|
142
|
+
'http.response.body': JSON.stringify(response.body),
|
|
143
|
+
'http.response.headers': JSON.stringify(response.headers),
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
147
|
+
return [2, {
|
|
148
|
+
headers: __assign(__assign({}, constants_1.defaultHeaders), response.headers),
|
|
149
|
+
multiValueHeaders: response.multiValueHeaders,
|
|
150
|
+
statusCode: (_g = response.statusCode) !== null && _g !== void 0 ? _g : 200,
|
|
151
|
+
body: JSON.stringify(response.body),
|
|
152
|
+
}];
|
|
153
|
+
case 3:
|
|
154
|
+
error_1 = _k.sent();
|
|
155
|
+
span.setAttributes({
|
|
156
|
+
'exception.message': error_1.message,
|
|
157
|
+
'exception.stacktrace': error_1.trace,
|
|
158
|
+
'http.response.status_code': (_j = (_h = error_1.code) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : '500',
|
|
159
|
+
});
|
|
160
|
+
span.setStatus({
|
|
161
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
162
|
+
message: error_1.message,
|
|
163
|
+
});
|
|
164
|
+
if (error_1.isTreated) {
|
|
165
|
+
return [2, {
|
|
166
|
+
headers: constants_1.defaultHeaders,
|
|
167
|
+
statusCode: error_1.code,
|
|
168
|
+
body: JSON.stringify(error_1.toObject()),
|
|
169
|
+
}];
|
|
170
|
+
}
|
|
171
|
+
fintalk_logger_1.default.error(error_1);
|
|
172
|
+
return [2, {
|
|
173
|
+
headers: constants_1.defaultHeaders,
|
|
174
|
+
statusCode: 500,
|
|
175
|
+
body: JSON.stringify({
|
|
176
|
+
error: {
|
|
177
|
+
message: 'Internal Server Error',
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
}];
|
|
181
|
+
case 4:
|
|
182
|
+
clearTimeout(timeout);
|
|
183
|
+
span.end((0, core_1.hrTime)());
|
|
184
|
+
return [4, (0, provider_flush_1.default)(otlp_1.tracerProvider)];
|
|
185
|
+
case 5:
|
|
186
|
+
_k.sent();
|
|
187
|
+
return [7];
|
|
188
|
+
case 6: return [2];
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}); })];
|
|
100
192
|
});
|
|
101
193
|
});
|
|
102
194
|
};
|
package/lib/handlers/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/handlers/api.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3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CAClC,sBAAsB,EAAE,OAAK,CAAC,KAAK;wCACnC,2BAA2B,EAAE,MAAA,MAAA,OAAK,CAAC,IAAI,0CAAE,QAAQ,EAAE,mCAAI,KAAK;qCAC7D,CAAC,CAAA;oCACF,IAAI,CAAC,SAAS,CAAC;wCACb,IAAI,EAAE,oBAAc,CAAC,KAAK;wCAC1B,OAAO,EAAE,OAAK,CAAC,OAAO;qCACvB,CAAC,CAAA;oCAEF,IAAI,OAAK,CAAC,SAAS,EAAE;wCACnB,WAAO;gDACL,OAAO,EAAE,0BAAc;gDACvB,UAAU,EAAE,OAAK,CAAC,IAAI;gDACtB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAK,CAAC,QAAQ,EAAE,CAAC;6CACvC,EAAA;qCACF;oCAED,wBAAM,CAAC,KAAK,CAAC,OAAK,CAAC,CAAA;oCACnB,WAAO;4CACL,OAAO,EAAE,0BAAc;4CACvB,UAAU,EAAE,GAAG;4CACf,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gDACnB,KAAK,EAAE;oDACL,OAAO,EAAE,uBAAuB;iDACjC;6CACF,CAAC;yCACH,EAAA;;oCAED,YAAY,CAAC,OAAO,CAAC,CAAA;oCACrB,IAAI,CAAC,GAAG,CAAC,IAAA,aAAM,GAAE,CAAC,CAAA;oCAElB,WAAM,IAAA,wBAAa,EAAC,qBAAc,CAAC,EAAA;;oCAAnC,SAAmC,CAAA;;;;;yBAEtC,CACF,EAAA;;;KACF;IACH,uBAAC;AAAD,CAAC,AAjJD,IAiJC;AAjJY,4CAAgB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { APIGatewayIAMAuthorizerResult, APIGatewayRequestAuthorizerEvent, Context } from 'aws-lambda';
|
|
2
|
+
import { AuthorizerHandler } from '../models';
|
|
3
|
+
export declare class LambdaAuthorizerHandler {
|
|
4
|
+
readonly authHanlder: AuthorizerHandler;
|
|
5
|
+
constructor(handler: AuthorizerHandler);
|
|
6
|
+
handler(event: APIGatewayRequestAuthorizerEvent, context: Context): Promise<APIGatewayIAMAuthorizerResult>;
|
|
7
|
+
}
|