@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.
- package/dist/src/assert.js +1 -2
- package/dist/src/cloudformation-event-proxy.d.ts +13 -0
- package/dist/src/cloudformation-event-proxy.js +24 -0
- package/dist/src/cloudformation-lambda-http-proxy.d.ts +12 -0
- package/dist/src/cloudformation-lambda-http-proxy.js +42 -0
- package/dist/src/cloudformation.d.ts +28 -0
- package/dist/src/cloudformation.js +47 -0
- package/dist/src/container.js +23 -70
- package/dist/src/deferred.js +28 -89
- package/dist/src/dev-server.js +47 -51
- package/dist/src/dynamodb.js +25 -74
- package/dist/src/event-proxy.js +51 -108
- package/dist/src/factories.js +11 -64
- package/dist/src/http-server.js +23 -25
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +7 -46
- package/dist/src/internal-queue.js +42 -100
- package/dist/src/lambda-http-proxy.d.ts +1 -2
- package/dist/src/lambda-http-proxy.js +28 -93
- package/dist/src/localstack.js +37 -79
- package/dist/src/mappers.js +6 -6
- package/dist/src/pre-traffic-hooks.js +11 -55
- package/dist/src/responses.js +2 -2
- package/dist/src/s3.js +15 -69
- package/dist/src/scheduled-tasks.js +11 -56
- package/dist/src/services.d.ts +4 -2
- package/dist/src/services.js +13 -53
- package/dist/src/sns-http-proxy.js +41 -59
- package/dist/src/sns.js +29 -79
- package/dist/src/sqs.js +27 -74
- package/dist/src/stoppable.js +11 -50
- package/dist/src/tunnel.js +20 -70
- package/package.json +4 -1
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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 =
|
|
59
|
-
this.create =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
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
|
-
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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 =
|
|
59
|
-
this.stop =
|
|
60
|
-
this.handler =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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(
|
|
38
|
+
this.LOGGER = logging_1.LoggerFactory.create(`HTTP->LAMBDA[${this.name}]`);
|
|
103
39
|
this.LOGGER.info('registered %i routes', routes.length);
|
|
104
40
|
}
|
|
105
|
-
|
|
106
|
-
}());
|
|
41
|
+
}
|
package/dist/src/localstack.js
CHANGED
|
@@ -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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
38
|
+
const ready = withLocalState
|
|
80
39
|
.withExposedPorts(concreteConfig.exposedPort)
|
|
81
40
|
.withNetwork(network)
|
|
82
41
|
.withNetworkAliases(NETWORK_ALIAS);
|
|
83
|
-
this._start =
|
|
42
|
+
this._start = () => ready
|
|
84
43
|
.start()
|
|
85
|
-
.then(
|
|
86
|
-
.then(
|
|
44
|
+
.then((container) => this.started = container)
|
|
45
|
+
.then((container) => `${PROTOCOL}://${container.getHost()}:${container.getMappedPort(SERVICES_PORT)}`);
|
|
87
46
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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:
|
|
53
|
+
localStackDockerImage: config?.localStackDockerImage || DEFAULT_DOCKER_IMAGE,
|
|
95
54
|
exposedPort: exposedPort,
|
|
96
|
-
localStateBindMount: config
|
|
55
|
+
localStateBindMount: config?.localStateBindMount,
|
|
97
56
|
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
101
59
|
exports.LocalStack = LocalStack;
|
package/dist/src/mappers.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
url.searchParams.forEach(
|
|
32
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
var _this = this;
|
|
8
|
+
class PreTrafficHooks {
|
|
9
|
+
constructor(name, hooks) {
|
|
47
10
|
this.name = name;
|
|
48
11
|
this.hooks = hooks;
|
|
49
|
-
this.start =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
63
|
-
}());
|
|
19
|
+
}
|
package/dist/src/responses.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
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');
|