@yopdev/dev-server 1.4.0-alpha.0 → 1.4.0

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.
@@ -36,33 +36,51 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.newLambdaHttpProxy = void 0;
39
+ exports.newLambdaHttpProxy = exports.UNAUTHORIZED = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var http_server_1 = require("./http-server");
42
42
  var mappers_1 = require("./mappers");
43
43
  var responses_1 = require("./responses");
44
44
  var services_1 = require("./services");
45
- var newLambdaHttpProxy = function (name, config, callback) { return new services_1.Service(new LambdaHttpProxy(name, config.settings, config.routes), callback); };
45
+ 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
+ };
46
50
  exports.newLambdaHttpProxy = newLambdaHttpProxy;
47
51
  var LambdaHttpProxy = /** @class */ (function () {
48
- function LambdaHttpProxy(name, settings, routes) {
52
+ function LambdaHttpProxy(name, settings, routes, mapper, defaultAuthorizer) {
49
53
  var _this = this;
50
54
  this.name = name;
51
55
  this.routes = routes;
56
+ this.mapper = mapper;
57
+ this.defaultAuthorizer = defaultAuthorizer;
52
58
  this.start = function () { return _this.server.start(); };
53
- this.stop = function () { return _this.server.stop()
54
- .then(function () { return _this.LOGGER.info('stopped'); }); };
55
- this.handler = function (lambdaHandler) {
59
+ this.stop = function () { return _this.server.stop(); };
60
+ this.handler = function (authorizer, lambdaHandler) {
56
61
  return function (request, body, response) {
57
- return lambdaHandler((0, mappers_1.mapToLambdaEvent)(request, body))
58
- .then(function (lambda) {
59
- var _a, _b, _c, _d, _e, _f;
60
- 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);
61
- })
62
- .catch(function (e) {
63
- _this.LOGGER.error(e, 'request failed to execute');
64
- (0, responses_1.internalServerError)(response, e.body);
65
- });
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
+ }); });
66
84
  };
67
85
  };
68
86
  this.fallback = function (request, _, response) { return __awaiter(_this, void 0, void 0, function () {
@@ -76,12 +94,13 @@ var LambdaHttpProxy = /** @class */ (function () {
76
94
  var _a;
77
95
  return ((_a = _this.routes.filter(function (r) { return request.method.match(r.method); })
78
96
  .filter(function (r) { return request.url.match(r.path); })
79
- .sort(function (r1, r2) { return r2.path.source.length - r1.path.source.length; })
80
- .map(function (r) { return _this.handler(r.handler); })
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); })
81
99
  .find(function () { return true; })) !== null && _a !== void 0 ? _a : _this.fallback)(request, body, response);
82
100
  };
83
101
  this.server = new http_server_1.HttpServer(name, settings, this.resolveRoute);
84
102
  this.LOGGER = logging_1.LoggerFactory.create("HTTP->LAMBDA[".concat(this.name, "]"));
103
+ this.LOGGER.info('registered %i routes', routes.length);
85
104
  }
86
105
  return LambdaHttpProxy;
87
106
  }());
@@ -57,12 +57,13 @@ var LocalStack = /** @class */ (function () {
57
57
  accessKeyId: 'dummy',
58
58
  secretAccessKey: 'dummy'
59
59
  }
60
- }); })];
60
+ }); })
61
+ .tap(function () { return LOGGER.debug('started'); })];
61
62
  });
62
63
  }); };
63
64
  this.stop = function () { return Promise.resolve(_this.started)
64
65
  .then(function (container) { return container ? container.stop().then(function () { return 'stopped'; }) : 'not started'; })
65
- .then(function (status) { return LOGGER.info(status); }); };
66
+ .then(function (status) { return LOGGER.debug(status); }); };
66
67
  var concreteConfig = this.configOrDefaults(config);
67
68
  var container = new testcontainers_1.GenericContainer(concreteConfig.localStackDockerImage);
68
69
  var localStatePath = concreteConfig.localStateBindMount;
@@ -83,7 +84,6 @@ var LocalStack = /** @class */ (function () {
83
84
  .start()
84
85
  .then(function (container) { return _this.started = container; })
85
86
  .then(function (container) { return "".concat(PROTOCOL, "://").concat(container.getHost(), ":").concat(container.getMappedPort(SERVICES_PORT)); }); };
86
- LOGGER.debug('initialized');
87
87
  }
88
88
  LocalStack.prototype.configOrDefaults = function (config) {
89
89
  var selectedServicesPort = config === null || config === void 0 ? void 0 : config.boundServicesPort;
@@ -3,4 +3,4 @@ import { Message } from "@aws-sdk/client-sqs";
3
3
  import { APIGatewayProxyEvent, SQSRecord } from "aws-lambda";
4
4
  import { IncomingMessage } from "http";
5
5
  export declare const mapToLambdaSqsRecord: (message: Message) => SQSRecord;
6
- export declare function mapToLambdaEvent(req: IncomingMessage, requestBody: string): APIGatewayProxyEvent;
6
+ export declare function mapToLambdaEvent(req: IncomingMessage, requestBody: string): Promise<APIGatewayProxyEvent>;
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mapToLambdaEvent = exports.mapToLambdaSqsRecord = void 0;
4
- var logging_1 = require("@yopdev/logging");
5
4
  var url_1 = require("url");
6
- var LOGGER = logging_1.LoggerFactory.create('MAPPERS');
7
5
  var mapToLambdaSqsRecord = function (message) {
8
6
  if (!message.Body)
9
- throw new Error("message Body must be present: ".concat(message.Body));
7
+ throw new Error('message Body must be present');
10
8
  return {
11
9
  messageId: 'N/A',
12
10
  receiptHandle: 'N/A',
@@ -28,16 +26,17 @@ exports.mapToLambdaSqsRecord = mapToLambdaSqsRecord;
28
26
  function mapToLambdaEvent(req, requestBody) {
29
27
  if (!req.url || !req.method)
30
28
  throw new Error('url and method are required');
31
- var url = new url_1.URL(decodeURIComponent(req.url), "http://".concat(req.headers.host));
29
+ var url = new url_1.URL(req.url, "http://".concat(req.headers.host));
32
30
  var qsp = {};
33
- url.searchParams.forEach(function (v, k) { return (qsp[k] = v); });
34
- var claims = extractClaims(req);
31
+ url.searchParams.forEach(function (v, k) { return (qsp[k] = decodeURIComponent(v)); });
35
32
  var headers = {};
36
33
  if (req.headers['content-type'])
37
- headers['Content-Type'] = req.headers['content-type'];
34
+ headers['content-type'] = req.headers['content-type'];
38
35
  if (req.headers['accept'])
39
- headers['Accept'] = req.headers['accept'];
40
- return {
36
+ headers['accept'] = req.headers['accept'];
37
+ if (req.headers['authorization'])
38
+ headers['authorization'] = req.headers['authorization'];
39
+ return Promise.resolve({
41
40
  httpMethod: req.method,
42
41
  body: requestBody,
43
42
  headers: headers,
@@ -52,7 +51,7 @@ function mapToLambdaEvent(req, requestBody) {
52
51
  requestContext: {
53
52
  accountId: '',
54
53
  apiId: '',
55
- authorizer: { claims: claims },
54
+ authorizer: undefined,
56
55
  httpMethod: '',
57
56
  identity: {
58
57
  accessKey: '',
@@ -85,17 +84,6 @@ function mapToLambdaEvent(req, requestBody) {
85
84
  resourcePath: '',
86
85
  stage: '',
87
86
  },
88
- };
87
+ });
89
88
  }
90
89
  exports.mapToLambdaEvent = mapToLambdaEvent;
91
- function extractClaims(req) {
92
- var _a;
93
- var jwt = (_a = req.headers['authorization']) === null || _a === void 0 ? void 0 : _a.replace('Bearer ', '');
94
- try {
95
- return jwt ? JSON.parse(atob(jwt.split('.')[1])) : null;
96
- }
97
- catch (e) {
98
- LOGGER.warn('Invalid token, claims could not be extracted: %O', jwt);
99
- return undefined;
100
- }
101
- }
@@ -1,11 +1,2 @@
1
- import { Lifecycle, Service, Callback } from './services';
2
- export declare const newPreTrafficHooks: (name: string, hooks: () => Promise<void>[], callback?: Callback<PreTrafficHooks>) => Service<PreTrafficHooks>;
3
- declare class PreTrafficHooks implements Lifecycle<PreTrafficHooks> {
4
- readonly name: string;
5
- private readonly hooks;
6
- private LOGGER;
7
- constructor(name: string, hooks: () => Promise<void>[]);
8
- start: () => Promise<this>;
9
- stop: () => Promise<void>;
10
- }
11
- export {};
1
+ import { Service } from './services';
2
+ export declare const newPreTrafficHooks: (name: string, hooks: () => Promise<void>[]) => Service<any>;
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.newPreTrafficHooks = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var services_1 = require("./services");
42
- var newPreTrafficHooks = function (name, hooks, callback) { return new services_1.Service(new PreTrafficHooks(name, hooks), callback); };
42
+ var newPreTrafficHooks = function (name, hooks) { return new services_1.Service(new PreTrafficHooks(name, hooks)); };
43
43
  exports.newPreTrafficHooks = newPreTrafficHooks;
44
44
  var PreTrafficHooks = /** @class */ (function () {
45
45
  function PreTrafficHooks(name, hooks) {
@@ -47,22 +47,17 @@ var PreTrafficHooks = /** @class */ (function () {
47
47
  this.name = name;
48
48
  this.hooks = hooks;
49
49
  this.start = function () { return __awaiter(_this, void 0, void 0, function () {
50
- var _this = this;
51
50
  return __generator(this, function (_a) {
52
51
  return [2 /*return*/, Promise
53
52
  .all(this.hooks())
54
- .then(function () { return _this.LOGGER.info('started'); })
55
- .then(function () { return _this; })];
56
- });
57
- }); };
58
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () {
59
- var _this = this;
60
- return __generator(this, function (_a) {
61
- return [2 /*return*/, Promise.resolve()
62
- .then(function () { return _this.LOGGER.info('stopped'); })];
53
+ .then(function () { return undefined; })];
63
54
  });
64
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
+ }); }); };
65
59
  this.LOGGER = logging_1.LoggerFactory.create("PRETRAFFIC[".concat(name, "]"));
60
+ this.LOGGER.info('%i hooks registered', hooks.length);
66
61
  }
67
62
  return PreTrafficHooks;
68
63
  }());
@@ -1,4 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import { ServerResponse } from 'http';
3
- export declare function internalServerError(res: ServerResponse, body: string): void;
3
+ export declare function internalServerError(res: ServerResponse, body: any): void;
4
4
  export declare function writeResponse(res: ServerResponse, statusCode: number, body: string, contentType?: string, location?: string): void;
@@ -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
+ var logging_1 = require("@yopdev/logging");
5
+ var LOG = logging_1.LoggerFactory.create('RESPONSES');
4
6
  function internalServerError(res, body) {
5
- return writeResponse(res, 500, body);
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) {
@@ -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,74 @@
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
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.S3 = void 0;
51
+ var client_s3_1 = require("@aws-sdk/client-s3");
52
+ var logging_1 = require("@yopdev/logging");
53
+ var LOGGER = logging_1.LoggerFactory.create('S3');
54
+ var S3 = /** @class */ (function () {
55
+ function S3(aws) {
56
+ var _this = this;
57
+ this.createBucket = function (name, cors) { return __awaiter(_this, void 0, void 0, function () {
58
+ var _this = this;
59
+ return __generator(this, function (_a) {
60
+ return [2 /*return*/, this.client.send(new client_s3_1.CreateBucketCommand({
61
+ Bucket: name,
62
+ }))
63
+ .then(function () { return cors && _this.client.send(new client_s3_1.PutBucketCorsCommand({
64
+ Bucket: name,
65
+ CORSConfiguration: cors
66
+ })); })
67
+ .tap(function () { return LOGGER.debug('bucket %s created', name); })];
68
+ });
69
+ }); };
70
+ this.client = new client_s3_1.S3Client(__assign({ forcePathStyle: true }, aws));
71
+ }
72
+ return S3;
73
+ }());
74
+ exports.S3 = S3;
@@ -1,17 +1,6 @@
1
- /// <reference types="node" />
2
- import { Lifecycle, Service, Callback } from './services';
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 {};
@@ -40,7 +40,7 @@ exports.newScheduledTasks = void 0;
40
40
  var logging_1 = require("@yopdev/logging");
41
41
  var timers_1 = require("timers");
42
42
  var services_1 = require("./services");
43
- var newScheduledTasks = function (name, schedules, callback) { return new services_1.Service(new ScheduledTasks(name, schedules), callback); };
43
+ var newScheduledTasks = function (name, schedules) { return new services_1.Service(new ScheduledTasks(name, schedules)); };
44
44
  exports.newScheduledTasks = newScheduledTasks;
45
45
  var ScheduledTasks = /** @class */ (function () {
46
46
  function ScheduledTasks(name, schedules) {
@@ -52,18 +52,14 @@ var ScheduledTasks = /** @class */ (function () {
52
52
  var _this = this;
53
53
  return __generator(this, function (_a) {
54
54
  return [2 /*return*/, Promise.resolve(this.schedules.forEach(function (schedule) { return _this.intervals.push(setInterval(schedule.task, schedule.frequency * 1000)); }))
55
- .then(function () { return _this.LOGGER.info('started'); })
56
- .then(function () { return _this; })];
57
- });
58
- }); };
59
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () {
60
- var _this = this;
61
- return __generator(this, function (_a) {
62
- return [2 /*return*/, Promise.resolve(this.intervals.forEach(function (interval) { return (0, timers_1.clearInterval)(interval); }))
63
- .then(function () { return _this.LOGGER.info('stopped'); })];
55
+ .then(function () { return undefined; })];
64
56
  });
65
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
+ }); }); };
66
61
  this.LOGGER = logging_1.LoggerFactory.create("SCHEDULER[".concat(name, "]"));
62
+ this.LOGGER.info('registered %i scheduled tasks', schedules.length);
67
63
  }
68
64
  return ScheduledTasks;
69
65
  }());
@@ -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: string | undefined;
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,33 +17,34 @@ 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
- .then(function (endpoint) {
32
+ .tap(function () {
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
- return endpoint;
37
38
  })
38
39
  .then(function (endpoint) { return endpoint; }); };
39
40
  this.stop = function () { return _this.onlyWhenStarted(_this.server).stop()
40
- .then(function () { return _this.LOGGER.info('stopped'); }); };
41
+ .then(function () { return _this.LOGGER.debug('stopped'); }); };
41
42
  this.handler = function (method, subject) {
42
43
  return function (request, body, response) {
43
44
  return Promise.resolve(((0, assert_1.assertNotUndefined)(_this.config)))
44
45
  .then(function (config) {
45
46
  return config.sns
46
- .publish(config.topic, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
47
+ .publish({ arn: config.topic }, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
47
48
  .then(function () { return (0, responses_1.writeResponse)(response, 200, ''); })
48
49
  .catch(function (e) {
49
50
  _this.LOGGER.error(e, 'request failed to execute');
@@ -76,6 +77,7 @@ var SnsHttpProxy = /** @class */ (function () {
76
77
  };
77
78
  this.server = new http_server_1.HttpServer(this.name, this.settings, this.handler(this.method, this.subject));
78
79
  this.LOGGER = logging_1.LoggerFactory.create("HTTP->SNS[".concat(name, "]"));
80
+ this.LOGGER.info('forwarding %s %s events to %s', subject ? "events with ".concat(subject, " subject") : 'all', method, topic !== null && topic !== void 0 ? topic : 'the event bus');
79
81
  }
80
82
  return SnsHttpProxy;
81
83
  }());
package/dist/src/sns.js CHANGED
@@ -50,7 +50,8 @@ var Sns = /** @class */ (function () {
50
50
  .send(new client_sns_1.CreateTopicCommand({
51
51
  Name: topic,
52
52
  }))
53
- .then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })];
53
+ .then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })
54
+ .tap(function (arn) { return LOGGER.debug('topic %o created', arn); })];
54
55
  });
55
56
  }); };
56
57
  this.createSubscription = function (topic, queue) { return __awaiter(_this, void 0, void 0, function () {
@@ -61,7 +62,7 @@ var Sns = /** @class */ (function () {
61
62
  Protocol: 'sqs',
62
63
  Endpoint: queue.arn,
63
64
  }))
64
- .then(function () { return LOGGER.debug('connected %s to %s', topic.arn, queue.arn); })];
65
+ .then(function () { return LOGGER.debug('subscription %s->%s created', topic.arn, queue.arn); })];
65
66
  });
66
67
  }); };
67
68
  this.publish = function (topic, body, subject, attributes) { return __awaiter(_this, void 0, void 0, function () {
@@ -73,12 +74,11 @@ var Sns = /** @class */ (function () {
73
74
  MessageAttributes: attributes,
74
75
  Subject: subject,
75
76
  }))
76
- .then(function () { return LOGGER.debug('published with subject %s to %s', subject, topic.arn); })
77
+ .then(function () { return LOGGER.trace('published %s[%s]', topic.arn, subject); })
77
78
  .then()];
78
79
  });
79
80
  }); };
80
81
  this.client = new client_sns_1.SNSClient(aws);
81
- LOGGER.debug('initialized');
82
82
  }
83
83
  return Sns;
84
84
  }());
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
- createNamedQueue: (name: string) => Promise<Queue>;
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;
package/dist/src/sqs.js CHANGED
@@ -45,12 +45,21 @@ var LOGGER = logging_1.LoggerFactory.create('SQS');
45
45
  var Sqs = /** @class */ (function () {
46
46
  function Sqs(config) {
47
47
  var _this = this;
48
- this.createNamedQueue = function (name) { return __awaiter(_this, void 0, void 0, function () {
48
+ this.createStandardQueue = function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
49
+ return [2 /*return*/, this.createNamedQueue(name, false)];
50
+ }); }); };
51
+ this.createFifoQueue = function (name) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
52
+ return [2 /*return*/, this.createNamedQueue(name, true)];
53
+ }); }); };
54
+ this.createNamedQueue = function (name, fifo) { return __awaiter(_this, void 0, void 0, function () {
49
55
  var _this = this;
50
56
  return __generator(this, function (_a) {
51
57
  return [2 /*return*/, this.client
52
58
  .send(new client_sqs_1.CreateQueueCommand({
53
- QueueName: name,
59
+ QueueName: fifo ? "".concat(name, ".fifo") : name,
60
+ Attributes: {
61
+ FifoQueue: fifo ? 'true' : 'false',
62
+ }
54
63
  }))
55
64
  .then(function (create) { return _this.client
56
65
  .send(new client_sqs_1.GetQueueAttributesCommand({
@@ -60,11 +69,11 @@ var Sqs = /** @class */ (function () {
60
69
  .then(function (attributes) { return ({
61
70
  url: (0, assert_1.assertNotUndefined)(create.QueueUrl),
62
71
  arn: (0, assert_1.assertNotUndefined)(attributes.Attributes)[QUEUE_NAME_ATTRIBUTE_NAME],
63
- }); }); })];
72
+ }); }); })
73
+ .tap(function (queue) { return LOGGER.debug('created %s', queue.arn); })];
64
74
  });
65
75
  }); };
66
76
  this.client = new client_sqs_1.SQSClient(config);
67
- LOGGER.debug('initialized');
68
77
  }
69
78
  return Sqs;
70
79
  }());
@@ -1,2 +1,2 @@
1
1
  import { Consumer } from "sqs-consumer";
2
- export declare const stopConsumer: (target: Consumer, queueWaitTimeSecs: number) => Promise<void>;
2
+ export declare const stopConsumer: (queueWaitTimeSecs: number, target?: Consumer) => Promise<void>;
@@ -37,12 +37,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.stopConsumer = void 0;
40
- var stopConsumer = function (target, queueWaitTimeSecs) { return __awaiter(void 0, void 0, void 0, function () {
40
+ var stopConsumer = function (queueWaitTimeSecs, target) { return __awaiter(void 0, void 0, void 0, function () {
41
41
  return __generator(this, function (_a) {
42
- target.stop();
43
- return [2 /*return*/, new Promise(function (resolve) {
44
- setTimeout(resolve, queueWaitTimeSecs * 1000 + 1);
45
- })];
42
+ if (target) {
43
+ target.stop();
44
+ return [2 /*return*/, new Promise(function (resolve) {
45
+ setTimeout(resolve, queueWaitTimeSecs * 1000 + 1);
46
+ })];
47
+ }
48
+ else {
49
+ return [2 /*return*/, Promise.resolve()];
50
+ }
51
+ return [2 /*return*/];
46
52
  });
47
53
  }); };
48
54
  exports.stopConsumer = stopConsumer;
@@ -0,0 +1,10 @@
1
+ import { Service } from './services';
2
+ export declare const terminate: () => Promise<void>;
3
+ export declare const newTunnel: (config: {
4
+ name: string;
5
+ port: number;
6
+ fixed?: {
7
+ name: string;
8
+ token: string;
9
+ };
10
+ }) => Service<string>;