@yopdev/dev-server 1.8.0-alpha.1 → 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.
Files changed (40) hide show
  1. package/dist/src/assert.js +1 -2
  2. package/dist/src/cloudformation-event-proxy.d.ts +13 -0
  3. package/dist/src/cloudformation-event-proxy.js +25 -0
  4. package/dist/src/cloudformation-lambda-http-proxy.d.ts +16 -0
  5. package/dist/src/cloudformation-lambda-http-proxy.js +45 -0
  6. package/dist/src/cloudformation.d.ts +28 -0
  7. package/dist/src/cloudformation.js +46 -0
  8. package/dist/src/container.js +23 -70
  9. package/dist/src/deferred.js +28 -89
  10. package/dist/src/dev-server.js +47 -51
  11. package/dist/src/dynamodb.js +25 -74
  12. package/dist/src/event-proxy.d.ts +3 -1
  13. package/dist/src/event-proxy.js +52 -108
  14. package/dist/src/factories.js +11 -64
  15. package/dist/src/http-server.js +23 -25
  16. package/dist/src/index.d.ts +5 -4
  17. package/dist/src/index.js +8 -46
  18. package/dist/src/internal-queue.d.ts +5 -2
  19. package/dist/src/internal-queue.js +44 -99
  20. package/dist/src/lambda-http-proxy.d.ts +13 -5
  21. package/dist/src/lambda-http-proxy.js +33 -78
  22. package/dist/src/localstack.js +37 -79
  23. package/dist/src/mappers.d.ts +3 -2
  24. package/dist/src/mappers.js +29 -26
  25. package/dist/src/pre-traffic-hooks.d.ts +2 -11
  26. package/dist/src/pre-traffic-hooks.js +11 -56
  27. package/dist/src/responses.d.ts +3 -2
  28. package/dist/src/responses.js +4 -1
  29. package/dist/src/s3.d.ts +2 -2
  30. package/dist/src/s3.js +15 -64
  31. package/dist/src/scheduled-tasks.js +11 -56
  32. package/dist/src/services.d.ts +4 -2
  33. package/dist/src/services.js +13 -53
  34. package/dist/src/sns-http-proxy.js +41 -59
  35. package/dist/src/sns.js +29 -79
  36. package/dist/src/sqs.d.ts +3 -1
  37. package/dist/src/sqs.js +27 -65
  38. package/dist/src/stoppable.js +11 -50
  39. package/dist/src/tunnel.js +41 -68
  40. package/package.json +5 -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
- var logging_1 = require("@yopdev/logging");
41
- var services_1 = require("./services");
42
- var newPreTrafficHooks = function (name, hooks, callback) { return new services_1.Service(new PreTrafficHooks(name, hooks), callback); };
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
- var PreTrafficHooks = /** @class */ (function () {
45
- function PreTrafficHooks(name, hooks) {
46
- var _this = this;
8
+ class PreTrafficHooks {
9
+ constructor(name, hooks) {
47
10
  this.name = name;
48
11
  this.hooks = hooks;
49
- this.start = function () { return __awaiter(_this, void 0, void 0, function () {
50
- var _this = this;
51
- return __generator(this, function (_a) {
52
- return [2 /*return*/, Promise
53
- .all(this.hooks())
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
- return PreTrafficHooks;
64
- }());
19
+ }
@@ -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: string): void;
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;
@@ -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
- 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) {
package/dist/src/s3.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { S3Client } from '@aws-sdk/client-s3';
1
+ import { CORSConfiguration, S3Client } from '@aws-sdk/client-s3';
2
2
  import { AwsConfig } from './config';
3
3
  export declare class S3 {
4
4
  readonly client: S3Client;
5
5
  constructor(aws: AwsConfig);
6
- createBucket: (name: string) => Promise<import("@aws-sdk/client-s3").CreateBucketCommandOutput>;
6
+ createBucket: (name: string, cors?: CORSConfiguration) => Promise<import("@aws-sdk/client-s3").PutBucketCorsCommandOutput>;
7
7
  }
package/dist/src/s3.js CHANGED
@@ -1,69 +1,20 @@
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
- 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
2
  Object.defineProperty(exports, "__esModule", { value: true });
50
3
  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) { return __awaiter(_this, void 0, void 0, function () {
58
- return __generator(this, function (_a) {
59
- return [2 /*return*/, this.client.send(new client_s3_1.CreateBucketCommand({
60
- Bucket: name,
61
- }))
62
- .tap(function () { return LOGGER.debug('bucket %s created', name); })];
63
- });
64
- }); };
65
- this.client = new client_s3_1.S3Client(__assign({ forcePathStyle: true }, aws));
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 });
66
18
  }
67
- return S3;
68
- }());
19
+ }
69
20
  exports.S3 = S3;
@@ -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
- var logging_1 = require("@yopdev/logging");
41
- var timers_1 = require("timers");
42
- var services_1 = require("./services");
43
- var newScheduledTasks = function (name, schedules) { return new services_1.Service(new ScheduledTasks(name, schedules)); };
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
- var ScheduledTasks = /** @class */ (function () {
46
- function ScheduledTasks(name, schedules) {
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 = function () { return __awaiter(_this, void 0, void 0, function () {
52
- var _this = this;
53
- return __generator(this, function (_a) {
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 undefined; })];
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
- return ScheduledTasks;
65
- }());
20
+ }
@@ -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
- start: (config: DevServerConfig) => Promise<I>;
4
+ }
5
+ export interface Startable<T> {
6
+ start(config: DevServerConfig): Promise<T>;
5
7
  }
6
8
  export interface Stoppable {
7
9
  stop(): Promise<void>;
@@ -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
- var logging_1 = require("@yopdev/logging");
41
- var Service = /** @class */ (function () {
42
- function Service(service, callback) {
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 = function () { return Promise.resolve(_this.LOGGER.debug('no callback')); };
46
- this.callbackOrDefault = function (instance) { return __awaiter(_this, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
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("SERVICE[".concat(this.name, "]"));
51
- this.start = function (config) { return service.start(config)
52
- .then(function (started) { return _this
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(function () { return _this.LOGGER.info('started'); })
55
- .then(function () { return started; }); }); };
56
- this.stop = function () { return service
15
+ .then(() => this.LOGGER.info('started'))
16
+ .then(() => started));
17
+ this.stop = () => service
57
18
  .stop()
58
- .then(function () { return _this.LOGGER.info('stopped'); }); };
19
+ .then(() => this.LOGGER.info('stopped'));
59
20
  }
60
- return Service;
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
- var logging_1 = require("@yopdev/logging");
16
- var http_server_1 = require("./http-server");
17
- var responses_1 = require("./responses");
18
- var services_1 = require("./services");
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, config.topic), callback); };
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
- var SnsHttpProxy = /** @class */ (function () {
23
- function SnsHttpProxy(name, settings, method, subject, topic) {
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 = function (config) { return Promise.resolve(_this.server)
31
- .then(function (server) { return server.start(); })
32
- .tap(function () {
33
- var _a;
34
- _this.config = {
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(function (endpoint) { return endpoint; }); };
40
- this.stop = function () { return _this.onlyWhenStarted(_this.server).stop()
41
- .then(function () { return _this.LOGGER.debug('stopped'); }); };
42
- this.handler = function (method, subject) {
43
- return function (request, body, response) {
44
- return Promise.resolve(((0, assert_1.assertNotUndefined)(_this.config)))
45
- .then(function (config) {
46
- return config.sns
47
- .publish({ arn: config.topic }, _this.extractMessage(method, request, body), subject, _this.extractMessageAttributes(request))
48
- .then(function () { return (0, responses_1.writeResponse)(response, 200, ''); })
49
- .catch(function (e) {
50
- _this.LOGGER.error(e, 'request failed to execute');
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 _this.extractQueryString(request) || '';
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 = function (server) { return (0, assert_1.assertNotUndefined)(server, 'not started'); };
67
- this.extractQueryString = function (request) { var _a, _b; return (_a = request.url) === null || _a === void 0 ? void 0 : _a.substring(((_b = request.url) === null || _b === void 0 ? void 0 : _b.indexOf('?')) + 1); };
68
- this.extractMessageAttributes = function (request) {
69
- var initialValue = {};
70
- return Object.keys(request.headers).reduce(function (obj, item) {
71
- var _a;
72
- return __assign(__assign({}, obj), (_a = {}, _a[item] = {
73
- DataType: 'String',
74
- StringValue: request.headers[item],
75
- }, _a));
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("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');
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
- return SnsHttpProxy;
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
- var client_sns_1 = require("@aws-sdk/client-sns");
41
- var assert_1 = require("./assert");
42
- var logging_1 = require("@yopdev/logging");
43
- var LOGGER = logging_1.LoggerFactory.create('SNS');
44
- var Sns = /** @class */ (function () {
45
- function Sns(aws) {
46
- var _this = this;
47
- this.createTopic = function (topic) { return __awaiter(_this, void 0, void 0, function () {
48
- return __generator(this, function (_a) {
49
- return [2 /*return*/, this.client
50
- .send(new client_sns_1.CreateTopicCommand({
51
- Name: topic,
52
- }))
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); })];
55
- });
56
- }); };
57
- this.createSubscription = function (topic, queue) { return __awaiter(_this, void 0, void 0, function () {
58
- return __generator(this, function (_a) {
59
- return [2 /*return*/, this.client
60
- .send(new client_sns_1.SubscribeCommand({
61
- TopicArn: topic.arn,
62
- Protocol: 'sqs',
63
- Endpoint: queue.arn,
64
- }))
65
- .then(function () { return LOGGER.debug('subscription %s->%s created', topic.arn, queue.arn); })];
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
- return Sns;
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
- 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;