@yopdev/dev-server 1.7.0-alpha.0 → 2.0.0-alpha.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/dist/src/assert.js +1 -2
- package/dist/src/cloudformation-event-proxy.d.ts +13 -0
- package/dist/src/cloudformation-event-proxy.js +25 -0
- package/dist/src/cloudformation-lambda-http-proxy.d.ts +16 -0
- package/dist/src/cloudformation-lambda-http-proxy.js +45 -0
- package/dist/src/cloudformation.d.ts +28 -0
- package/dist/src/cloudformation.js +46 -0
- package/dist/src/config.d.ts +2 -0
- package/dist/src/container.js +23 -70
- package/dist/src/deferred.js +28 -89
- package/dist/src/dev-server.js +47 -49
- package/dist/src/dynamodb.js +25 -74
- package/dist/src/event-proxy.d.ts +3 -1
- package/dist/src/event-proxy.js +52 -108
- package/dist/src/factories.js +11 -64
- package/dist/src/http-server.js +23 -25
- package/dist/src/index.d.ts +5 -4
- package/dist/src/index.js +8 -46
- package/dist/src/internal-queue.d.ts +5 -2
- package/dist/src/internal-queue.js +44 -99
- package/dist/src/lambda-http-proxy.d.ts +13 -5
- package/dist/src/lambda-http-proxy.js +33 -78
- package/dist/src/localstack.js +37 -79
- package/dist/src/mappers.d.ts +3 -2
- package/dist/src/mappers.js +29 -26
- package/dist/src/pre-traffic-hooks.d.ts +2 -11
- package/dist/src/pre-traffic-hooks.js +11 -56
- package/dist/src/responses.d.ts +3 -2
- package/dist/src/responses.js +4 -1
- package/dist/src/s3.d.ts +7 -0
- package/dist/src/s3.js +20 -0
- package/dist/src/scheduled-tasks.d.ts +2 -13
- 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.d.ts +3 -1
- package/dist/src/sqs.js +27 -65
- package/dist/src/stoppable.js +11 -50
- package/dist/src/tunnel.js +41 -68
- package/package.json +6 -1
|
@@ -1,64 +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
|
-
.then(function () { return _this; })];
|
|
55
|
-
});
|
|
56
|
-
}); };
|
|
57
|
-
this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
58
|
-
return [2 /*return*/, Promise.resolve()];
|
|
59
|
-
}); }); };
|
|
60
|
-
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}]`);
|
|
61
17
|
this.LOGGER.info('%i hooks registered', hooks.length);
|
|
62
18
|
}
|
|
63
|
-
|
|
64
|
-
}());
|
|
19
|
+
}
|
package/dist/src/responses.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { ServerResponse } from 'http';
|
|
3
|
-
export declare function internalServerError(res: ServerResponse, body:
|
|
4
|
-
export declare function writeResponse(res: ServerResponse, statusCode: number, body: string, contentType?: string, location?: string): void;
|
|
4
|
+
export declare function internalServerError(res: ServerResponse, body: any): void;
|
|
5
|
+
export declare function writeResponse(res: ServerResponse, statusCode: number, body: string | Buffer, contentType?: string, location?: string): void;
|
package/dist/src/responses.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.writeResponse = exports.internalServerError = void 0;
|
|
4
|
+
const logging_1 = require("@yopdev/logging");
|
|
5
|
+
const LOG = logging_1.LoggerFactory.create('RESPONSES');
|
|
4
6
|
function internalServerError(res, body) {
|
|
5
|
-
|
|
7
|
+
LOG.error(body, 'internal server error handled');
|
|
8
|
+
return writeResponse(res, 500, 'internal server error. check system logs');
|
|
6
9
|
}
|
|
7
10
|
exports.internalServerError = internalServerError;
|
|
8
11
|
function writeResponse(res, statusCode, body, contentType, location) {
|
package/dist/src/s3.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CORSConfiguration, S3Client } from '@aws-sdk/client-s3';
|
|
2
|
+
import { AwsConfig } from './config';
|
|
3
|
+
export declare class S3 {
|
|
4
|
+
readonly client: S3Client;
|
|
5
|
+
constructor(aws: AwsConfig);
|
|
6
|
+
createBucket: (name: string, cors?: CORSConfiguration) => Promise<import("@aws-sdk/client-s3").PutBucketCorsCommandOutput>;
|
|
7
|
+
}
|
package/dist/src/s3.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.S3 = void 0;
|
|
4
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
|
+
const logging_1 = require("@yopdev/logging");
|
|
6
|
+
const LOGGER = logging_1.LoggerFactory.create('S3');
|
|
7
|
+
class S3 {
|
|
8
|
+
constructor(aws) {
|
|
9
|
+
this.createBucket = async (name, cors) => this.client.send(new client_s3_1.CreateBucketCommand({
|
|
10
|
+
Bucket: name,
|
|
11
|
+
}))
|
|
12
|
+
.then(() => cors && this.client.send(new client_s3_1.PutBucketCorsCommand({
|
|
13
|
+
Bucket: name,
|
|
14
|
+
CORSConfiguration: cors
|
|
15
|
+
})))
|
|
16
|
+
.tap(() => LOGGER.debug('bucket %s created', name));
|
|
17
|
+
this.client = new client_s3_1.S3Client({ forcePathStyle: true, ...aws });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.S3 = S3;
|
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const newScheduledTasks: (name: string, schedules: Rate[], callback?: Callback<ScheduledTasks>) => Service<ScheduledTasks>;
|
|
4
|
-
declare class ScheduledTasks implements Lifecycle<ScheduledTasks> {
|
|
5
|
-
readonly name: string;
|
|
6
|
-
private readonly schedules;
|
|
7
|
-
private LOGGER;
|
|
8
|
-
constructor(name: string, schedules: Rate[]);
|
|
9
|
-
intervals: NodeJS.Timeout[];
|
|
10
|
-
start: () => Promise<this>;
|
|
11
|
-
stop: () => Promise<void>;
|
|
12
|
-
}
|
|
1
|
+
import { Service } from './services';
|
|
2
|
+
export declare const newScheduledTasks: (name: string, schedules: Rate[]) => Service<any>;
|
|
13
3
|
export type Rate = {
|
|
14
4
|
frequency: number;
|
|
15
5
|
task: () => Promise<unknown>;
|
|
16
6
|
};
|
|
17
|
-
export {};
|
|
@@ -1,65 +1,20 @@
|
|
|
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.newScheduledTasks = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
4
|
+
const logging_1 = require("@yopdev/logging");
|
|
5
|
+
const timers_1 = require("timers");
|
|
6
|
+
const services_1 = require("./services");
|
|
7
|
+
const newScheduledTasks = (name, schedules) => new services_1.Service(new ScheduledTasks(name, schedules));
|
|
44
8
|
exports.newScheduledTasks = newScheduledTasks;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var _this = this;
|
|
9
|
+
class ScheduledTasks {
|
|
10
|
+
constructor(name, schedules) {
|
|
48
11
|
this.name = name;
|
|
49
12
|
this.schedules = schedules;
|
|
50
13
|
this.intervals = [];
|
|
51
|
-
this.start =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
.then(function () { return _this; })];
|
|
56
|
-
});
|
|
57
|
-
}); };
|
|
58
|
-
this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
59
|
-
return [2 /*return*/, Promise.resolve(this.intervals.forEach(function (interval) { return (0, timers_1.clearInterval)(interval); }))];
|
|
60
|
-
}); }); };
|
|
61
|
-
this.LOGGER = logging_1.LoggerFactory.create("SCHEDULER[".concat(name, "]"));
|
|
14
|
+
this.start = async () => Promise.resolve(this.schedules.forEach((schedule) => this.intervals.push(setInterval(schedule.task, schedule.frequency * 1000))))
|
|
15
|
+
.then(() => undefined);
|
|
16
|
+
this.stop = async () => Promise.resolve(this.intervals.forEach((interval) => (0, timers_1.clearInterval)(interval)));
|
|
17
|
+
this.LOGGER = logging_1.LoggerFactory.create(`SCHEDULER[${name}]`);
|
|
62
18
|
this.LOGGER.info('registered %i scheduled tasks', schedules.length);
|
|
63
19
|
}
|
|
64
|
-
|
|
65
|
-
}());
|
|
20
|
+
}
|
package/dist/src/services.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DevServerConfig } from "./config";
|
|
2
|
-
export interface Lifecycle<I> extends Stoppable {
|
|
2
|
+
export interface Lifecycle<I> extends Startable<I>, Stoppable {
|
|
3
3
|
name: string;
|
|
4
|
-
|
|
4
|
+
}
|
|
5
|
+
export interface Startable<T> {
|
|
6
|
+
start(config: DevServerConfig): Promise<T>;
|
|
5
7
|
}
|
|
6
8
|
export interface Stoppable {
|
|
7
9
|
stop(): Promise<void>;
|
package/dist/src/services.js
CHANGED
|
@@ -1,62 +1,22 @@
|
|
|
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.Service = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var _this = this;
|
|
4
|
+
const logging_1 = require("@yopdev/logging");
|
|
5
|
+
class Service {
|
|
6
|
+
constructor(service, callback) {
|
|
44
7
|
this.callback = callback;
|
|
45
|
-
this.DEFAULT_CALLBACK =
|
|
46
|
-
this.callbackOrDefault =
|
|
47
|
-
return [2 /*return*/, ((_a = this.callback) !== null && _a !== void 0 ? _a : this.DEFAULT_CALLBACK)(instance)];
|
|
48
|
-
}); }); };
|
|
8
|
+
this.DEFAULT_CALLBACK = () => Promise.resolve(this.LOGGER.debug('no callback'));
|
|
9
|
+
this.callbackOrDefault = async (instance) => (this.callback ?? this.DEFAULT_CALLBACK)(instance);
|
|
49
10
|
this.name = service.name;
|
|
50
|
-
this.LOGGER = logging_1.LoggerFactory.create(
|
|
51
|
-
this.start =
|
|
52
|
-
.then(
|
|
11
|
+
this.LOGGER = logging_1.LoggerFactory.create(`SERVICE[${this.name}]`);
|
|
12
|
+
this.start = (config) => service.start(config)
|
|
13
|
+
.then((started) => this
|
|
53
14
|
.callbackOrDefault(started)
|
|
54
|
-
.then(
|
|
55
|
-
.then(
|
|
56
|
-
this.stop =
|
|
15
|
+
.then(() => this.LOGGER.info('started'))
|
|
16
|
+
.then(() => started));
|
|
17
|
+
this.stop = () => service
|
|
57
18
|
.stop()
|
|
58
|
-
.then(
|
|
19
|
+
.then(() => this.LOGGER.info('stopped'));
|
|
59
20
|
}
|
|
60
|
-
|
|
61
|
-
}());
|
|
21
|
+
}
|
|
62
22
|
exports.Service = Service;
|
|
@@ -1,84 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.SnsHttpProxy = exports.newSnsHttpProxy = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
const logging_1 = require("@yopdev/logging");
|
|
5
|
+
const http_server_1 = require("./http-server");
|
|
6
|
+
const responses_1 = require("./responses");
|
|
7
|
+
const services_1 = require("./services");
|
|
8
|
+
const assert_1 = require("./assert");
|
|
9
|
+
const newSnsHttpProxy = (name, config, callback) => new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject, config.topic), callback);
|
|
21
10
|
exports.newSnsHttpProxy = newSnsHttpProxy;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var _this = this;
|
|
11
|
+
class SnsHttpProxy {
|
|
12
|
+
constructor(name, settings, method, subject, topic) {
|
|
25
13
|
this.name = name;
|
|
26
14
|
this.settings = settings;
|
|
27
15
|
this.method = method;
|
|
28
16
|
this.subject = subject;
|
|
29
17
|
this.topic = topic;
|
|
30
|
-
this.start =
|
|
31
|
-
.then(
|
|
32
|
-
.tap(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
topic: (_a = _this.topic) !== null && _a !== void 0 ? _a : config.eventsProxy.topic.arn,
|
|
18
|
+
this.start = (config) => Promise.resolve(this.server)
|
|
19
|
+
.then(server => server.start())
|
|
20
|
+
.tap(() => {
|
|
21
|
+
this.config = {
|
|
22
|
+
topic: this.topic ?? config.eventsProxy.topic.arn,
|
|
36
23
|
sns: config.sns
|
|
37
24
|
};
|
|
38
25
|
})
|
|
39
|
-
.then(
|
|
40
|
-
this.stop =
|
|
41
|
-
.then(
|
|
42
|
-
this.handler =
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, responses_1.internalServerError)(response, e.body);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
this.extractMessage = function (method, request, body) {
|
|
26
|
+
.then((endpoint) => endpoint);
|
|
27
|
+
this.stop = () => this.onlyWhenStarted(this.server).stop()
|
|
28
|
+
.then(() => this.LOGGER.debug('stopped'));
|
|
29
|
+
this.handler = (method, subject) => (request, body, response) => Promise.resolve(((0, assert_1.assertNotUndefined)(this.config)))
|
|
30
|
+
.then((config) => config.sns
|
|
31
|
+
.publish({ arn: config.topic }, this.extractMessage(method, request, body), subject, this.extractMessageAttributes(request))
|
|
32
|
+
.then(() => (0, responses_1.writeResponse)(response, 200, ''))
|
|
33
|
+
.catch((e) => {
|
|
34
|
+
this.LOGGER.error(e, 'request failed to execute');
|
|
35
|
+
(0, responses_1.internalServerError)(response, e.body);
|
|
36
|
+
}));
|
|
37
|
+
this.extractMessage = (method, request, body) => {
|
|
57
38
|
switch (method) {
|
|
58
39
|
case 'GET':
|
|
59
|
-
return
|
|
40
|
+
return this.extractQueryString(request) || '';
|
|
60
41
|
case 'POST':
|
|
61
42
|
return body;
|
|
62
43
|
default:
|
|
63
44
|
throw new Error();
|
|
64
45
|
}
|
|
65
46
|
};
|
|
66
|
-
this.onlyWhenStarted =
|
|
67
|
-
this.extractQueryString =
|
|
68
|
-
this.extractMessageAttributes =
|
|
69
|
-
|
|
70
|
-
return Object.keys(request.headers).reduce(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
47
|
+
this.onlyWhenStarted = (server) => (0, assert_1.assertNotUndefined)(server, 'not started');
|
|
48
|
+
this.extractQueryString = (request) => request.url?.substring(request.url?.indexOf('?') + 1);
|
|
49
|
+
this.extractMessageAttributes = (request) => {
|
|
50
|
+
const initialValue = {};
|
|
51
|
+
return Object.keys(request.headers).reduce((obj, item) => {
|
|
52
|
+
return {
|
|
53
|
+
...obj,
|
|
54
|
+
[item]: {
|
|
55
|
+
DataType: 'String',
|
|
56
|
+
StringValue: request.headers[item],
|
|
57
|
+
},
|
|
58
|
+
};
|
|
76
59
|
}, initialValue);
|
|
77
60
|
};
|
|
78
61
|
this.server = new http_server_1.HttpServer(this.name, this.settings, this.handler(this.method, this.subject));
|
|
79
|
-
this.LOGGER = logging_1.LoggerFactory.create(
|
|
80
|
-
this.LOGGER.info('forwarding %s %s events to %s', subject ?
|
|
62
|
+
this.LOGGER = logging_1.LoggerFactory.create(`HTTP->SNS[${name}]`);
|
|
63
|
+
this.LOGGER.info('forwarding %s %s events to %s', subject ? `events with ${subject} subject` : 'all', method, topic ?? 'the event bus');
|
|
81
64
|
}
|
|
82
|
-
|
|
83
|
-
}());
|
|
65
|
+
}
|
|
84
66
|
exports.SnsHttpProxy = SnsHttpProxy;
|
package/dist/src/sns.js
CHANGED
|
@@ -1,85 +1,35 @@
|
|
|
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.Sns = 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
|
-
|
|
67
|
-
|
|
68
|
-
this.publish = function (topic, body, subject, attributes) { return __awaiter(_this, void 0, void 0, function () {
|
|
69
|
-
return __generator(this, function (_a) {
|
|
70
|
-
return [2 /*return*/, this.client
|
|
71
|
-
.send(new client_sns_1.PublishCommand({
|
|
72
|
-
TopicArn: topic.arn,
|
|
73
|
-
Message: body,
|
|
74
|
-
MessageAttributes: attributes,
|
|
75
|
-
Subject: subject,
|
|
76
|
-
}))
|
|
77
|
-
.then(function () { return LOGGER.trace('published %s[%s]', topic.arn, subject); })
|
|
78
|
-
.then()];
|
|
79
|
-
});
|
|
80
|
-
}); };
|
|
4
|
+
const client_sns_1 = require("@aws-sdk/client-sns");
|
|
5
|
+
const assert_1 = require("./assert");
|
|
6
|
+
const logging_1 = require("@yopdev/logging");
|
|
7
|
+
const LOGGER = logging_1.LoggerFactory.create('SNS');
|
|
8
|
+
class Sns {
|
|
9
|
+
constructor(aws) {
|
|
10
|
+
this.createTopic = async (topic) => this.client
|
|
11
|
+
.send(new client_sns_1.CreateTopicCommand({
|
|
12
|
+
Name: topic,
|
|
13
|
+
}))
|
|
14
|
+
.then((o) => (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'))
|
|
15
|
+
.tap((arn) => LOGGER.debug('topic %o created', arn));
|
|
16
|
+
this.createSubscription = async (topic, queue) => this.client
|
|
17
|
+
.send(new client_sns_1.SubscribeCommand({
|
|
18
|
+
TopicArn: topic.arn,
|
|
19
|
+
Protocol: 'sqs',
|
|
20
|
+
Endpoint: queue.arn,
|
|
21
|
+
}))
|
|
22
|
+
.then(() => LOGGER.debug('subscription %s->%s created', topic.arn, queue.arn));
|
|
23
|
+
this.publish = async (topic, body, subject, attributes) => this.client
|
|
24
|
+
.send(new client_sns_1.PublishCommand({
|
|
25
|
+
TopicArn: topic.arn,
|
|
26
|
+
Message: body,
|
|
27
|
+
MessageAttributes: attributes,
|
|
28
|
+
Subject: subject,
|
|
29
|
+
}))
|
|
30
|
+
.then(() => LOGGER.trace('published %s[%s]', topic.arn, subject))
|
|
31
|
+
.then();
|
|
81
32
|
this.client = new client_sns_1.SNSClient(aws);
|
|
82
33
|
}
|
|
83
|
-
|
|
84
|
-
}());
|
|
34
|
+
}
|
|
85
35
|
exports.Sns = Sns;
|
package/dist/src/sqs.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import { AwsConfig } from "./config";
|
|
|
3
3
|
export declare class Sqs {
|
|
4
4
|
readonly client: SQSClient;
|
|
5
5
|
constructor(config: AwsConfig);
|
|
6
|
-
|
|
6
|
+
createStandardQueue: (name: string) => Promise<Queue>;
|
|
7
|
+
createFifoQueue: (name: string) => Promise<Queue>;
|
|
8
|
+
private createNamedQueue;
|
|
7
9
|
}
|
|
8
10
|
export type Queue = {
|
|
9
11
|
arn: string;
|