@yopdev/dev-server 1.4.0-alpha.0 → 1.4.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.
|
@@ -2,6 +2,7 @@ import { SQSEvent } from 'aws-lambda';
|
|
|
2
2
|
import { Service } from './services';
|
|
3
3
|
export declare const newEventsProxy: (name: string, config: {
|
|
4
4
|
handlers: EventHandler[];
|
|
5
|
+
topic?: string;
|
|
5
6
|
}) => Service<any>;
|
|
6
7
|
export type EventHandler = {
|
|
7
8
|
handler: (event: SQSEvent) => Promise<unknown>;
|
package/dist/src/event-proxy.js
CHANGED
|
@@ -43,20 +43,22 @@ var logging_1 = require("@yopdev/logging");
|
|
|
43
43
|
var stoppable_1 = require("./stoppable");
|
|
44
44
|
var assert_1 = require("./assert");
|
|
45
45
|
var services_1 = require("./services");
|
|
46
|
-
var newEventsProxy = function (name, config) { return new services_1.Service(new EventsProxy(name, config.handlers)); };
|
|
46
|
+
var newEventsProxy = function (name, config) { return new services_1.Service(new EventsProxy(name, config.handlers, config.topic)); };
|
|
47
47
|
exports.newEventsProxy = newEventsProxy;
|
|
48
48
|
var EventsProxy = /** @class */ (function () {
|
|
49
|
-
function EventsProxy(name, handlers) {
|
|
49
|
+
function EventsProxy(name, handlers, topic) {
|
|
50
50
|
var _this = this;
|
|
51
51
|
this.name = name;
|
|
52
52
|
this.handlers = handlers;
|
|
53
|
+
this.topic = topic;
|
|
53
54
|
this.pollingFrequency = 1;
|
|
54
55
|
this.stopped = true;
|
|
55
56
|
this.queueName = function () { return "EventProxyQueue".concat(Buffer.from(_this.name).toString('hex').substring(0, 64)); };
|
|
56
57
|
this.start = function (config) { return __awaiter(_this, void 0, void 0, function () {
|
|
57
58
|
var _this = this;
|
|
58
|
-
|
|
59
|
-
|
|
59
|
+
var _a;
|
|
60
|
+
return __generator(this, function (_b) {
|
|
61
|
+
return [2 /*return*/, this.queueConnectedToTopic(config.sns, (_a = this.topic) !== null && _a !== void 0 ? _a : config.eventsProxy.topic.arn, config.sqs, this.queueName())
|
|
60
62
|
.then(function (url) { return _this.startEventsConsumer(config.sqs.client, url); })
|
|
61
63
|
.then(function () { return _this.stopped = false; })
|
|
62
64
|
.then(function () { return undefined; })];
|
|
@@ -5,17 +5,19 @@ import { DevServerConfig } from "./config";
|
|
|
5
5
|
export declare const newSnsHttpProxy: (name: string, config: {
|
|
6
6
|
settings: HttpSettings;
|
|
7
7
|
method: string;
|
|
8
|
-
subject
|
|
8
|
+
subject?: string;
|
|
9
|
+
topic?: string;
|
|
9
10
|
}, callback?: Callback<string>) => Service<string>;
|
|
10
11
|
export declare class SnsHttpProxy implements Lifecycle<string> {
|
|
11
12
|
readonly name: string;
|
|
12
13
|
private readonly settings;
|
|
13
14
|
private readonly method;
|
|
14
15
|
private readonly subject?;
|
|
16
|
+
private readonly topic?;
|
|
15
17
|
private LOGGER;
|
|
16
18
|
private server;
|
|
17
19
|
private config;
|
|
18
|
-
constructor(name: string, settings: HttpSettings, method: string, subject?: string);
|
|
20
|
+
constructor(name: string, settings: HttpSettings, method: string, subject?: string, topic?: string);
|
|
19
21
|
start: (config: DevServerConfig) => Promise<string>;
|
|
20
22
|
stop: () => Promise<void>;
|
|
21
23
|
handler: (method: string, subject?: string) => (request: IncomingMessage, body: string, response: ServerResponse) => Promise<void>;
|
|
@@ -17,20 +17,22 @@ var http_server_1 = require("./http-server");
|
|
|
17
17
|
var responses_1 = require("./responses");
|
|
18
18
|
var services_1 = require("./services");
|
|
19
19
|
var assert_1 = require("./assert");
|
|
20
|
-
var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject), callback); };
|
|
20
|
+
var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject, config.topic), callback); };
|
|
21
21
|
exports.newSnsHttpProxy = newSnsHttpProxy;
|
|
22
22
|
var SnsHttpProxy = /** @class */ (function () {
|
|
23
|
-
function SnsHttpProxy(name, settings, method, subject) {
|
|
23
|
+
function SnsHttpProxy(name, settings, method, subject, topic) {
|
|
24
24
|
var _this = this;
|
|
25
25
|
this.name = name;
|
|
26
26
|
this.settings = settings;
|
|
27
27
|
this.method = method;
|
|
28
28
|
this.subject = subject;
|
|
29
|
+
this.topic = topic;
|
|
29
30
|
this.start = function (config) { return Promise.resolve(_this.server)
|
|
30
31
|
.then(function (server) { return server.start(); })
|
|
31
32
|
.then(function (endpoint) {
|
|
33
|
+
var _a;
|
|
32
34
|
_this.config = {
|
|
33
|
-
topic: config.eventsProxy.topic,
|
|
35
|
+
topic: (_a = _this.topic) !== null && _a !== void 0 ? _a : config.eventsProxy.topic.arn,
|
|
34
36
|
sns: config.sns
|
|
35
37
|
};
|
|
36
38
|
return endpoint;
|
|
@@ -43,7 +45,7 @@ var SnsHttpProxy = /** @class */ (function () {
|
|
|
43
45
|
return Promise.resolve(((0, assert_1.assertNotUndefined)(_this.config)))
|
|
44
46
|
.then(function (config) {
|
|
45
47
|
return config.sns
|
|
46
|
-
.publish(config.topic, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
|
|
48
|
+
.publish({ arn: config.topic }, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
|
|
47
49
|
.then(function () { return (0, responses_1.writeResponse)(response, 200, ''); })
|
|
48
50
|
.catch(function (e) {
|
|
49
51
|
_this.LOGGER.error(e, 'request failed to execute');
|