@yopdev/dev-server 1.3.0-alpha.0 → 1.3.0-alpha.3

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.
@@ -21,4 +21,9 @@ export type DevServerConfig = {
21
21
  sqs: Sqs;
22
22
  sns: Sns;
23
23
  dynamo: DynamoDb;
24
+ eventsProxy: {
25
+ topic: {
26
+ arn: string;
27
+ };
28
+ };
24
29
  };
@@ -4,6 +4,7 @@ export declare class DevServer implements Lifecycle<DevServer> {
4
4
  readonly name: string;
5
5
  private readonly service;
6
6
  private readonly config?;
7
+ private readonly eventProxyTopic;
7
8
  private LOGGER;
8
9
  private localStack;
9
10
  constructor(name: string, service: Service<any>, config?: Config);
@@ -23,13 +23,22 @@ var DevServer = /** @class */ (function () {
23
23
  aws: config,
24
24
  network: infra.network
25
25
  }); }); })
26
- .then(function (infra) { return ({
26
+ .then(function (infra) { return Promise
27
+ .resolve(new sns_1.Sns(infra.aws))
28
+ .then(function (sns) { return sns
29
+ .createTopic(_this.eventProxyTopic)
30
+ .then(function (eventProxyTopicArn) { return ({
27
31
  raw: infra.aws,
28
32
  network: infra.network,
29
33
  sqs: new sqs_1.Sqs(infra.aws),
30
34
  sns: new sns_1.Sns(infra.aws),
31
35
  dynamo: new dynamodb_1.DynamoDb(infra.aws),
32
- }); })
36
+ eventsProxy: {
37
+ topic: {
38
+ arn: eventProxyTopicArn
39
+ }
40
+ },
41
+ }); }); }); })
33
42
  .then(function (config) { _this.LOGGER.debug('starting. config is %o', config); return config; })
34
43
  .then(function (aws) { return _this.service.start(aws); })
35
44
  .then(function () { return _this.LOGGER.info('started'); })
@@ -39,6 +48,8 @@ var DevServer = /** @class */ (function () {
39
48
  .then(function () { var _a; return (_a = _this.localStack) === null || _a === void 0 ? void 0 : _a.stop(); })
40
49
  .then(function () { return _this.LOGGER.info('stopped'); }); };
41
50
  this.LOGGER = logging_1.LoggerFactory.create("DEVSERVER[".concat(name, "]"));
51
+ var encodedName = Buffer.from(name).toString('hex').substring(0, 64);
52
+ this.eventProxyTopic = "EventProxyTopic".concat(encodedName);
42
53
  }
43
54
  return DevServer;
44
55
  }());
@@ -3,19 +3,16 @@ import { Lifecycle, Service, Callback } from './services';
3
3
  import { DevServerConfig } from './config';
4
4
  export declare const newEventsProxy: (name: string, config: {
5
5
  handlers: EventHandler[];
6
- topic?: string;
7
- queue?: string;
8
6
  }, callback?: Callback<EventsProxy>) => Service<EventsProxy>;
9
7
  declare class EventsProxy implements Lifecycle<EventsProxy> {
10
8
  readonly name: string;
11
- readonly handlers: EventHandler[];
9
+ private readonly handlers;
12
10
  private LOGGER;
13
11
  private consumer;
14
12
  private readonly pollingFrequency;
15
- private readonly topic;
16
13
  private readonly queue;
17
14
  private stopped;
18
- constructor(name: string, handlers: EventHandler[], topic?: string, queue?: string);
15
+ constructor(name: string, handlers: EventHandler[]);
19
16
  start: (config: DevServerConfig) => Promise<this>;
20
17
  private queueConnectedToTopic;
21
18
  private startEventsConsumer;
@@ -46,7 +46,7 @@ var services_1 = require("./services");
46
46
  var newEventsProxy = function (name, config, callback) { return new services_1.Service(new EventsProxy(name, config.handlers), callback); };
47
47
  exports.newEventsProxy = newEventsProxy;
48
48
  var EventsProxy = /** @class */ (function () {
49
- function EventsProxy(name, handlers, topic, queue) {
49
+ function EventsProxy(name, handlers) {
50
50
  var _this = this;
51
51
  this.name = name;
52
52
  this.handlers = handlers;
@@ -55,21 +55,18 @@ var EventsProxy = /** @class */ (function () {
55
55
  this.start = function (config) { return __awaiter(_this, void 0, void 0, function () {
56
56
  var _this = this;
57
57
  return __generator(this, function (_a) {
58
- return [2 /*return*/, this.queueConnectedToTopic(config.sns, this.topic, config.sqs, this.queue)
58
+ return [2 /*return*/, this.queueConnectedToTopic(config.sns, config.eventsProxy.topic.arn, config.sqs, this.queue)
59
59
  .then(function (url) { return _this.startEventsConsumer(config.sqs.client, url); })
60
- .then(function (url) { return _this.LOGGER.debug('initialized: %s', url); })
61
60
  .then(function () { return _this.stopped = false; })
62
61
  .then(function () { return _this; })];
63
62
  });
64
63
  }); };
65
64
  this.queueConnectedToTopic = function (sns, topic, sqs, queue) { return __awaiter(_this, void 0, void 0, function () {
66
65
  return __generator(this, function (_a) {
67
- return [2 /*return*/, Promise.all([
68
- sns.createTopic(topic), sqs.createNamedQueue(queue)
69
- ])
70
- .then(function (values) { return sns
71
- .createSubscription({ arn: values[0] }, { arn: values[1].arn })
72
- .then(function () { return values[1].url; }); })];
66
+ return [2 /*return*/, sqs.createNamedQueue(queue)
67
+ .then(function (queue) { return sns
68
+ .createSubscription({ arn: topic }, { arn: queue.arn })
69
+ .then(function () { return queue[1].url; }); })];
73
70
  });
74
71
  }); };
75
72
  this.startEventsConsumer = function (sqs, url) { return __awaiter(_this, void 0, void 0, function () {
@@ -125,9 +122,7 @@ var EventsProxy = /** @class */ (function () {
125
122
  }); };
126
123
  this.LOGGER = logging_1.LoggerFactory.create("SNS->SQS[".concat(name, "]"));
127
124
  var encodedName = Buffer.from(name).toString('hex').substring(0, 64);
128
- this.topic = topic !== null && topic !== void 0 ? topic : "EventProxyTopic".concat(encodedName);
129
- this.queue = queue !== null && queue !== void 0 ? queue : "EventProxyQueue".concat(encodedName);
130
- this.LOGGER.info('proxying events from %s to %s', this.topic, this.queue);
125
+ this.queue = "EventProxyQueue".concat(encodedName);
131
126
  }
132
127
  return EventsProxy;
133
128
  }());
@@ -5,23 +5,17 @@ import { DevServerConfig } from "./config";
5
5
  export declare const newSnsHttpProxy: (name: string, config: {
6
6
  settings: HttpSettings;
7
7
  method: string;
8
- topic: {
9
- arn: string;
10
- };
11
8
  subject: string | undefined;
12
9
  }, callback?: Callback<string>) => Service<string>;
13
10
  export declare class SnsHttpProxy implements Lifecycle<string> {
14
11
  readonly name: string;
15
12
  private readonly settings;
16
13
  private readonly method;
17
- private readonly topic;
18
14
  private readonly subject?;
19
15
  private LOGGER;
20
- private readonly server;
16
+ private server;
21
17
  private config;
22
- constructor(name: string, settings: HttpSettings, method: string, topic: {
23
- arn: string;
24
- }, subject?: string);
18
+ constructor(name: string, settings: HttpSettings, method: string, subject?: string);
25
19
  start: (config: DevServerConfig) => Promise<string>;
26
20
  stop: () => Promise<void>;
27
21
  handler: (method: string, subject?: string) => (request: IncomingMessage, body: string, response: ServerResponse) => Promise<void>;
@@ -17,21 +17,20 @@ 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.topic, config.subject), callback); };
20
+ var newSnsHttpProxy = function (name, config, callback) { return new services_1.Service(new SnsHttpProxy(name, config.settings, config.method, config.subject), callback); };
21
21
  exports.newSnsHttpProxy = newSnsHttpProxy;
22
22
  var SnsHttpProxy = /** @class */ (function () {
23
- function SnsHttpProxy(name, settings, method, topic, subject) {
23
+ function SnsHttpProxy(name, settings, method, subject) {
24
24
  var _this = this;
25
25
  this.name = name;
26
26
  this.settings = settings;
27
27
  this.method = method;
28
- this.topic = topic;
29
28
  this.subject = subject;
30
29
  this.start = function (config) { return Promise.resolve(_this.server)
31
30
  .then(function (server) { return server.start(); })
32
31
  .then(function (endpoint) {
33
32
  _this.config = {
34
- topic: _this.topic.arn,
33
+ topic: config.eventsProxy.topic,
35
34
  sns: config.sns
36
35
  };
37
36
  return endpoint;
@@ -44,7 +43,7 @@ var SnsHttpProxy = /** @class */ (function () {
44
43
  return Promise.resolve(((0, assert_1.assertNotUndefined)(_this.config)))
45
44
  .then(function (config) {
46
45
  return config.sns
47
- .publish({ arn: config.topic }, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
46
+ .publish(config.topic, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
48
47
  .then(function () { return (0, responses_1.writeResponse)(response, 200, ''); })
49
48
  .catch(function (e) {
50
49
  _this.LOGGER.error(e, 'request failed to execute');
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.3.0-alpha.0",
3
+ "version": "1.3.0-alpha.3",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
+ "pretest": "npm run compile",
6
7
  "test": "jest",
7
8
  "clean": "rm -rf dist",
8
9
  "predistclean": "npm run clean",