@yopdev/dev-server 1.4.0 → 1.4.4

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.
@@ -1,113 +1,55 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.newInternalQueue = void 0;
40
- var logging_1 = require("@yopdev/logging");
41
- var sqs_consumer_1 = require("sqs-consumer");
42
- var stoppable_1 = require("./stoppable");
43
- var mappers_1 = require("./mappers");
44
- var services_1 = require("./services");
45
- var newInternalQueue = function (name, config, callback) {
46
- var _a;
47
- return new services_1.Service(new InternalQueue(name, config.visibility, config.handler, function (sqs) { return config.fifo ? sqs.createFifoQueue : sqs.createStandardQueue; }, (_a = config.mapper) !== null && _a !== void 0 ? _a : mappers_1.mapToLambdaSqsRecord), callback);
48
- };
4
+ const logging_1 = require("@yopdev/logging");
5
+ const sqs_consumer_1 = require("sqs-consumer");
6
+ const stoppable_1 = require("./stoppable");
7
+ const mappers_1 = require("./mappers");
8
+ const services_1 = require("./services");
9
+ const newInternalQueue = (name, config, callback) => new services_1.Service(new InternalQueue(name, config.visibility, config.handler, (sqs) => config.fifo ? sqs.createFifoQueue : sqs.createStandardQueue, config.mapper ?? mappers_1.mapToLambdaSqsRecord), callback);
49
10
  exports.newInternalQueue = newInternalQueue;
50
- var InternalQueue = /** @class */ (function () {
51
- function InternalQueue(name, visibility, handler, creator, mapper) {
52
- var _this = this;
11
+ class InternalQueue {
12
+ constructor(name, visibility, handler, creator, mapper) {
53
13
  this.name = name;
54
14
  this.visibility = visibility;
55
15
  this.handler = handler;
56
16
  this.creator = creator;
57
17
  this.mapper = mapper;
58
- this.start = function (config) { return _this.create(config.sqs); };
59
- this.create = function (sqs) { return __awaiter(_this, void 0, void 0, function () {
60
- var _this = this;
61
- return __generator(this, function (_a) {
62
- return [2 /*return*/, this.createQueue(sqs, this.name)
63
- .then(function (queue) { return _this
64
- .createConsumer(sqs.client, _this.name, queue.url, _this.handler(queue), _this.visibility)
65
- .then(function () { return queue.url; }); })];
18
+ this.start = (config) => this.create(config.sqs);
19
+ this.create = async (sqs) => this.createQueue(sqs, this.name)
20
+ .then((queue) => this
21
+ .createConsumer(sqs.client, this.name, queue.url, this.handler(queue), this.visibility)
22
+ .then(() => queue.url));
23
+ this.createConsumer = async (sqs, name, url, handler, visibility) => Promise.resolve(sqs_consumer_1.Consumer.create({
24
+ queueUrl: url,
25
+ waitTimeSeconds: visibility,
26
+ sqs: sqs,
27
+ handleMessage: async (message) => handler({ Records: [this.mapper(message)] }),
28
+ }))
29
+ .then((consumer) => {
30
+ consumer.on('error', (err) => {
31
+ this.LOGGER.error(err, 'failed to handle message');
66
32
  });
67
- }); };
68
- this.createConsumer = function (sqs, name, url, handler, visibility) { return __awaiter(_this, void 0, void 0, function () {
69
- var _this = this;
70
- return __generator(this, function (_a) {
71
- return [2 /*return*/, Promise.resolve(sqs_consumer_1.Consumer.create({
72
- queueUrl: url,
73
- waitTimeSeconds: visibility,
74
- sqs: sqs,
75
- handleMessage: function (message) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
76
- return [2 /*return*/, handler({ Records: [this.mapper(message)] })];
77
- }); }); },
78
- }))
79
- .then(function (consumer) {
80
- consumer.on('error', function (err) {
81
- _this.LOGGER.error(err, 'failed to handle message');
82
- });
83
- consumer.on('processing_error', function (err) {
84
- _this.LOGGER.error(err, 'failed to process message');
85
- });
86
- consumer.start();
87
- _this.LOGGER.info('consumer for %s initialized', name);
88
- _this.state = {
89
- consumer: consumer,
90
- visibility: visibility,
91
- };
92
- })
93
- .then(function () { return _this.LOGGER.info('started'); })
94
- .then(function () { return _this; })];
33
+ consumer.on('processing_error', (err) => {
34
+ this.LOGGER.error(err, 'failed to process message');
95
35
  });
96
- }); };
97
- this.stop = function () { return (0, stoppable_1.stopConsumer)(_this.state.visibility, _this.state.consumer); };
98
- this.LOGGER = logging_1.LoggerFactory.create("INTERNALQUEUE[".concat(name, "]"));
36
+ consumer.start();
37
+ this.LOGGER.info('consumer for %s initialized', name);
38
+ this.state = {
39
+ consumer: consumer,
40
+ visibility: visibility,
41
+ };
42
+ })
43
+ .then(() => this.LOGGER.info('started'))
44
+ .then(() => this);
45
+ this.stop = () => (0, stoppable_1.stopConsumer)(this.state.visibility, this.state.consumer);
46
+ this.LOGGER = logging_1.LoggerFactory.create(`INTERNALQUEUE[${name}]`);
99
47
  }
100
- InternalQueue.prototype.createQueue = function (sqs, name) {
101
- return __awaiter(this, void 0, void 0, function () {
102
- var _this = this;
103
- return __generator(this, function (_a) {
104
- return [2 /*return*/, this.creator(sqs)(name) //
105
- .then(function (queue) {
106
- _this.LOGGER.info('created: %s', queue.url);
107
- return queue;
108
- })];
109
- });
48
+ async createQueue(sqs, name) {
49
+ return this.creator(sqs)(name) //
50
+ .then((queue) => {
51
+ this.LOGGER.info('created: %s', queue.url);
52
+ return queue;
110
53
  });
111
- };
112
- return InternalQueue;
113
- }());
54
+ }
55
+ }
@@ -16,5 +16,4 @@ export type Route = {
16
16
  authorizer?: Authorizer;
17
17
  handler: (event: APIGatewayProxyEvent) => Promise<APIGatewayProxyResult>;
18
18
  };
19
- type Authorizer = (authorization: string) => Promise<APIGatewayEventDefaultAuthorizerContext | undefined>;
20
- export {};
19
+ export type Authorizer = (authorization: string) => Promise<APIGatewayEventDefaultAuthorizerContext | undefined>;
@@ -1,106 +1,41 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.newLambdaHttpProxy = exports.UNAUTHORIZED = void 0;
40
- var logging_1 = require("@yopdev/logging");
41
- var http_server_1 = require("./http-server");
42
- var mappers_1 = require("./mappers");
43
- var responses_1 = require("./responses");
44
- var services_1 = require("./services");
4
+ const logging_1 = require("@yopdev/logging");
5
+ const http_server_1 = require("./http-server");
6
+ const mappers_1 = require("./mappers");
7
+ const responses_1 = require("./responses");
8
+ const services_1 = require("./services");
45
9
  exports.UNAUTHORIZED = new Error('UNAUTHORIZED');
46
- var newLambdaHttpProxy = function (name, config, callback) {
47
- var _a, _b;
48
- return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.routes, (_a = config.mapper) !== null && _a !== void 0 ? _a : mappers_1.mapToLambdaEvent, (_b = config.authorizer) !== null && _b !== void 0 ? _b : (function () { return Promise.resolve(undefined); })), callback);
49
- };
10
+ const newLambdaHttpProxy = (name, config, callback) => new services_1.Service(new LambdaHttpProxy(name, config.settings, config.routes, config.mapper ?? mappers_1.mapToLambdaEvent, config.authorizer ?? (() => Promise.resolve(undefined))), callback);
50
11
  exports.newLambdaHttpProxy = newLambdaHttpProxy;
51
- var LambdaHttpProxy = /** @class */ (function () {
52
- function LambdaHttpProxy(name, settings, routes, mapper, defaultAuthorizer) {
53
- var _this = this;
12
+ class LambdaHttpProxy {
13
+ constructor(name, settings, routes, mapper, defaultAuthorizer) {
54
14
  this.name = name;
55
15
  this.routes = routes;
56
16
  this.mapper = mapper;
57
17
  this.defaultAuthorizer = defaultAuthorizer;
58
- this.start = function () { return _this.server.start(); };
59
- this.stop = function () { return _this.server.stop(); };
60
- this.handler = function (authorizer, lambdaHandler) {
61
- return function (request, body, response) {
62
- return _this.mapper(request, body)
63
- .then(function (proxyEvent) { return __awaiter(_this, void 0, void 0, function () {
64
- var _this = this;
65
- return __generator(this, function (_a) {
66
- return [2 /*return*/, authorizer(proxyEvent.headers['authorization'])
67
- .then(function (context) { return __awaiter(_this, void 0, void 0, function () {
68
- var _this = this;
69
- return __generator(this, function (_a) {
70
- proxyEvent.requestContext.authorizer = context;
71
- return [2 /*return*/, lambdaHandler(proxyEvent)
72
- .then(function (lambda) {
73
- var _a, _b, _c, _d, _e, _f;
74
- return (0, responses_1.writeResponse)(response, lambda.statusCode, lambda.body, (_c = (_b = (_a = lambda.headers) === null || _a === void 0 ? void 0 : _a['content-type']) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : undefined, (_f = (_e = (_d = lambda.headers) === null || _d === void 0 ? void 0 : _d['location']) === null || _e === void 0 ? void 0 : _e.toString()) !== null && _f !== void 0 ? _f : undefined);
75
- })
76
- .catch(function (e) {
77
- _this.LOGGER.error(e, 'request failed to execute');
78
- (0, responses_1.internalServerError)(response, e.body);
79
- })];
80
- });
81
- }); }, function (e) { return e === exports.UNAUTHORIZED ? (0, responses_1.writeResponse)(response, 401, '') : (0, responses_1.internalServerError)(response, e); })];
82
- });
83
- }); });
84
- };
85
- };
86
- this.fallback = function (request, _, response) { return __awaiter(_this, void 0, void 0, function () {
87
- return __generator(this, function (_a) {
88
- return [2 /*return*/, Promise.resolve(this.LOGGER.warn('FALLBACK')).then(function () {
89
- return (0, responses_1.writeResponse)(response, 404, "no route found to handle ".concat(request.method, " to ").concat(request.url));
90
- })];
18
+ this.start = () => this.server.start();
19
+ this.stop = () => this.server.stop();
20
+ this.handler = (authorizer, lambdaHandler) => (request, body, response) => this.mapper(request, body)
21
+ .then(async (proxyEvent) => authorizer(proxyEvent.headers['authorization'])
22
+ .then(async (context) => {
23
+ proxyEvent.requestContext.authorizer = context;
24
+ return lambdaHandler(proxyEvent)
25
+ .then((lambda) => (0, responses_1.writeResponse)(response, lambda.statusCode, lambda.body, lambda.headers?.['content-type']?.toString() ?? undefined, lambda.headers?.['location']?.toString() ?? undefined))
26
+ .catch((e) => {
27
+ this.LOGGER.error(e, 'request failed to execute');
28
+ (0, responses_1.internalServerError)(response, e.body);
91
29
  });
92
- }); };
93
- this.resolveRoute = function (request, body, response) {
94
- var _a;
95
- return ((_a = _this.routes.filter(function (r) { return request.method.match(r.method); })
96
- .filter(function (r) { return request.url.match(r.path); })
97
- .sort(function (r1, r2) { return r2.weight - r1.weight; })
98
- .map(function (r) { var _a; return _this.handler((_a = r.authorizer) !== null && _a !== void 0 ? _a : _this.defaultAuthorizer, r.handler); })
99
- .find(function () { return true; })) !== null && _a !== void 0 ? _a : _this.fallback)(request, body, response);
100
- };
30
+ }, (e) => e === exports.UNAUTHORIZED ? (0, responses_1.writeResponse)(response, 401, '') : (0, responses_1.internalServerError)(response, e)));
31
+ this.fallback = async (request, _, response) => Promise.resolve(this.LOGGER.warn('FALLBACK')).then(() => (0, responses_1.writeResponse)(response, 404, `no route found to handle ${request.method} to ${request.url}`));
32
+ this.resolveRoute = (request, body, response) => (this.routes.filter((r) => request.method.match(r.method))
33
+ .filter((r) => request.url.match(r.path))
34
+ .sort((r1, r2) => r2.weight - r1.weight)
35
+ .map((r) => this.handler(r.authorizer ?? this.defaultAuthorizer, r.handler))
36
+ .find(() => true) ?? this.fallback)(request, body, response);
101
37
  this.server = new http_server_1.HttpServer(name, settings, this.resolveRoute);
102
- this.LOGGER = logging_1.LoggerFactory.create("HTTP->LAMBDA[".concat(this.name, "]"));
38
+ this.LOGGER = logging_1.LoggerFactory.create(`HTTP->LAMBDA[${this.name}]`);
103
39
  this.LOGGER.info('registered %i routes', routes.length);
104
40
  }
105
- return LambdaHttpProxy;
106
- }());
41
+ }
@@ -1,73 +1,32 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.LocalStack = void 0;
40
- var logging_1 = require("@yopdev/logging");
41
- var testcontainers_1 = require("testcontainers");
42
- var LOGGER = logging_1.LoggerFactory.create('LOCALSTACK');
43
- var SERVICES_PORT = 4566;
44
- var NETWORK_ALIAS = 'localstack';
45
- var PROTOCOL = 'http';
46
- var DEFAULT_DOCKER_IMAGE = 'localstack/localstack:stable';
47
- var LocalStack = /** @class */ (function () {
48
- function LocalStack(network, config) {
49
- var _this = this;
50
- this.start = function () { return __awaiter(_this, void 0, void 0, function () {
51
- return __generator(this, function (_a) {
52
- return [2 /*return*/, this._start()
53
- .then(function (endpoint) { return ({
54
- region: 'us-east-1',
55
- endpoint: endpoint,
56
- credentials: {
57
- accessKeyId: 'dummy',
58
- secretAccessKey: 'dummy'
59
- }
60
- }); })
61
- .tap(function () { return LOGGER.debug('started'); })];
62
- });
63
- }); };
64
- this.stop = function () { return Promise.resolve(_this.started)
65
- .then(function (container) { return container ? container.stop().then(function () { return 'stopped'; }) : 'not started'; })
66
- .then(function (status) { return LOGGER.debug(status); }); };
67
- var concreteConfig = this.configOrDefaults(config);
68
- var container = new testcontainers_1.GenericContainer(concreteConfig.localStackDockerImage);
69
- var localStatePath = concreteConfig.localStateBindMount;
70
- var withLocalState = localStatePath !== undefined ?
4
+ const logging_1 = require("@yopdev/logging");
5
+ const testcontainers_1 = require("testcontainers");
6
+ const LOGGER = logging_1.LoggerFactory.create('LOCALSTACK');
7
+ const SERVICES_PORT = 4566;
8
+ const NETWORK_ALIAS = 'localstack';
9
+ const PROTOCOL = 'http';
10
+ const DEFAULT_DOCKER_IMAGE = 'localstack/localstack:stable';
11
+ class LocalStack {
12
+ constructor(network, config) {
13
+ this.start = async () => this._start()
14
+ .then((endpoint) => ({
15
+ region: 'us-east-1',
16
+ endpoint: endpoint,
17
+ credentials: {
18
+ accessKeyId: 'dummy',
19
+ secretAccessKey: 'dummy'
20
+ }
21
+ }))
22
+ .tap(() => LOGGER.debug('started'));
23
+ this.stop = () => Promise.resolve(this.started)
24
+ .then((container) => container ? container.stop().then(() => 'stopped') : 'not started')
25
+ .then((status) => LOGGER.debug(status));
26
+ const concreteConfig = this.configOrDefaults(config);
27
+ const container = new testcontainers_1.GenericContainer(concreteConfig.localStackDockerImage);
28
+ const localStatePath = concreteConfig.localStateBindMount;
29
+ const withLocalState = localStatePath !== undefined ?
71
30
  container
72
31
  .withEnvironment({ PERSISTENCE: '1' })
73
32
  .withBindMounts([{
@@ -76,26 +35,25 @@ var LocalStack = /** @class */ (function () {
76
35
  mode: 'rw',
77
36
  }])
78
37
  : container;
79
- var ready = withLocalState
38
+ const ready = withLocalState
80
39
  .withExposedPorts(concreteConfig.exposedPort)
81
40
  .withNetwork(network)
82
41
  .withNetworkAliases(NETWORK_ALIAS);
83
- this._start = function () { return ready
42
+ this._start = () => ready
84
43
  .start()
85
- .then(function (container) { return _this.started = container; })
86
- .then(function (container) { return "".concat(PROTOCOL, "://").concat(container.getHost(), ":").concat(container.getMappedPort(SERVICES_PORT)); }); };
44
+ .then((container) => this.started = container)
45
+ .then((container) => `${PROTOCOL}://${container.getHost()}:${container.getMappedPort(SERVICES_PORT)}`);
87
46
  }
88
- LocalStack.prototype.configOrDefaults = function (config) {
89
- var selectedServicesPort = config === null || config === void 0 ? void 0 : config.boundServicesPort;
90
- var exposedPort = selectedServicesPort !== undefined ?
47
+ configOrDefaults(config) {
48
+ const selectedServicesPort = config?.boundServicesPort;
49
+ const exposedPort = selectedServicesPort !== undefined ?
91
50
  { container: SERVICES_PORT, host: selectedServicesPort } :
92
51
  SERVICES_PORT;
93
52
  return {
94
- localStackDockerImage: (config === null || config === void 0 ? void 0 : config.localStackDockerImage) || DEFAULT_DOCKER_IMAGE,
53
+ localStackDockerImage: config?.localStackDockerImage || DEFAULT_DOCKER_IMAGE,
95
54
  exposedPort: exposedPort,
96
- localStateBindMount: config === null || config === void 0 ? void 0 : config.localStateBindMount,
55
+ localStateBindMount: config?.localStateBindMount,
97
56
  };
98
- };
99
- return LocalStack;
100
- }());
57
+ }
58
+ }
101
59
  exports.LocalStack = LocalStack;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapToLambdaEvent = exports.mapToLambdaSqsRecord = void 0;
4
- var url_1 = require("url");
5
- var mapToLambdaSqsRecord = function (message) {
4
+ const url_1 = require("url");
5
+ const mapToLambdaSqsRecord = (message) => {
6
6
  if (!message.Body)
7
7
  throw new Error('message Body must be present');
8
8
  return {
@@ -26,10 +26,10 @@ exports.mapToLambdaSqsRecord = mapToLambdaSqsRecord;
26
26
  function mapToLambdaEvent(req, requestBody) {
27
27
  if (!req.url || !req.method)
28
28
  throw new Error('url and method are required');
29
- var url = new url_1.URL(req.url, "http://".concat(req.headers.host));
30
- var qsp = {};
31
- url.searchParams.forEach(function (v, k) { return (qsp[k] = decodeURIComponent(v)); });
32
- var headers = {};
29
+ const url = new url_1.URL(req.url, `http://${req.headers.host}`);
30
+ const qsp = {};
31
+ url.searchParams.forEach((v, k) => (qsp[k] = decodeURIComponent(v)));
32
+ const headers = {};
33
33
  if (req.headers['content-type'])
34
34
  headers['content-type'] = req.headers['content-type'];
35
35
  if (req.headers['accept'])
@@ -1,63 +1,19 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.newPreTrafficHooks = void 0;
40
- var logging_1 = require("@yopdev/logging");
41
- var services_1 = require("./services");
42
- var newPreTrafficHooks = function (name, hooks) { return new services_1.Service(new PreTrafficHooks(name, hooks)); };
4
+ const logging_1 = require("@yopdev/logging");
5
+ const services_1 = require("./services");
6
+ const newPreTrafficHooks = (name, hooks) => new services_1.Service(new PreTrafficHooks(name, hooks));
43
7
  exports.newPreTrafficHooks = newPreTrafficHooks;
44
- var PreTrafficHooks = /** @class */ (function () {
45
- function PreTrafficHooks(name, hooks) {
46
- var _this = this;
8
+ class PreTrafficHooks {
9
+ constructor(name, hooks) {
47
10
  this.name = name;
48
11
  this.hooks = hooks;
49
- this.start = function () { return __awaiter(_this, void 0, void 0, function () {
50
- return __generator(this, function (_a) {
51
- return [2 /*return*/, Promise
52
- .all(this.hooks())
53
- .then(function () { return undefined; })];
54
- });
55
- }); };
56
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
57
- return [2 /*return*/, Promise.resolve()];
58
- }); }); };
59
- this.LOGGER = logging_1.LoggerFactory.create("PRETRAFFIC[".concat(name, "]"));
12
+ this.start = async () => Promise
13
+ .all(this.hooks())
14
+ .then(() => undefined);
15
+ this.stop = async () => Promise.resolve();
16
+ this.LOGGER = logging_1.LoggerFactory.create(`PRETRAFFIC[${name}]`);
60
17
  this.LOGGER.info('%i hooks registered', hooks.length);
61
18
  }
62
- return PreTrafficHooks;
63
- }());
19
+ }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeResponse = exports.internalServerError = void 0;
4
- var logging_1 = require("@yopdev/logging");
5
- var LOG = logging_1.LoggerFactory.create('RESPONSES');
4
+ const logging_1 = require("@yopdev/logging");
5
+ const LOG = logging_1.LoggerFactory.create('RESPONSES');
6
6
  function internalServerError(res, body) {
7
7
  LOG.error(body, 'internal server error handled');
8
8
  return writeResponse(res, 500, 'internal server error. check system logs');