@yopdev/dev-server 1.3.17 → 1.4.0-alpha.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.
@@ -1,2 +1,11 @@
1
- import { Service } from './services';
2
- export declare const newPreTrafficHooks: (name: string, hooks: () => Promise<void>[]) => Service<any>;
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 {};
@@ -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) { return new services_1.Service(new PreTrafficHooks(name, hooks)); };
42
+ var newPreTrafficHooks = function (name, hooks, callback) { return new services_1.Service(new PreTrafficHooks(name, hooks), callback); };
43
43
  exports.newPreTrafficHooks = newPreTrafficHooks;
44
44
  var PreTrafficHooks = /** @class */ (function () {
45
45
  function PreTrafficHooks(name, hooks) {
@@ -47,17 +47,22 @@ 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;
50
51
  return __generator(this, function (_a) {
51
52
  return [2 /*return*/, Promise
52
53
  .all(this.hooks())
53
- .then(function () { return undefined; })];
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'); })];
54
63
  });
55
64
  }); };
56
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
57
- return [2 /*return*/, Promise.resolve()];
58
- }); }); };
59
65
  this.LOGGER = logging_1.LoggerFactory.create("PRETRAFFIC[".concat(name, "]"));
60
- this.LOGGER.info('%i hooks registered', hooks.length);
61
66
  }
62
67
  return PreTrafficHooks;
63
68
  }());
@@ -1,6 +1,17 @@
1
- import { Service } from './services';
2
- export declare const newScheduledTasks: (name: string, schedules: Rate[]) => Service<any>;
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
+ }
3
13
  export type Rate = {
4
14
  frequency: number;
5
15
  task: () => Promise<unknown>;
6
16
  };
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) { return new services_1.Service(new ScheduledTasks(name, schedules)); };
43
+ var newScheduledTasks = function (name, schedules, callback) { return new services_1.Service(new ScheduledTasks(name, schedules), callback); };
44
44
  exports.newScheduledTasks = newScheduledTasks;
45
45
  var ScheduledTasks = /** @class */ (function () {
46
46
  function ScheduledTasks(name, schedules) {
@@ -52,14 +52,18 @@ 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 undefined; })];
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'); })];
56
64
  });
57
65
  }); };
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
66
  this.LOGGER = logging_1.LoggerFactory.create("SCHEDULER[".concat(name, "]"));
62
- this.LOGGER.info('registered %i scheduled tasks', schedules.length);
63
67
  }
64
68
  return ScheduledTasks;
65
69
  }());
@@ -5,19 +5,17 @@ import { DevServerConfig } from "./config";
5
5
  export declare const newSnsHttpProxy: (name: string, config: {
6
6
  settings: HttpSettings;
7
7
  method: string;
8
- subject?: string;
9
- topic?: string;
8
+ subject: string | undefined;
10
9
  }, callback?: Callback<string>) => Service<string>;
11
10
  export declare class SnsHttpProxy implements Lifecycle<string> {
12
11
  readonly name: string;
13
12
  private readonly settings;
14
13
  private readonly method;
15
14
  private readonly subject?;
16
- private readonly topic?;
17
15
  private LOGGER;
18
16
  private server;
19
17
  private config;
20
- constructor(name: string, settings: HttpSettings, method: string, subject?: string, topic?: string);
18
+ constructor(name: string, settings: HttpSettings, method: string, subject?: string);
21
19
  start: (config: DevServerConfig) => Promise<string>;
22
20
  stop: () => Promise<void>;
23
21
  handler: (method: string, subject?: string) => (request: IncomingMessage, body: string, response: ServerResponse) => Promise<void>;
@@ -17,34 +17,33 @@ 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, config.topic), 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, subject, topic) {
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
28
  this.subject = subject;
29
- this.topic = topic;
30
29
  this.start = function (config) { return Promise.resolve(_this.server)
31
30
  .then(function (server) { return server.start(); })
32
- .tap(function () {
33
- var _a;
31
+ .then(function (endpoint) {
34
32
  _this.config = {
35
- topic: (_a = _this.topic) !== null && _a !== void 0 ? _a : config.eventsProxy.topic.arn,
33
+ topic: config.eventsProxy.topic,
36
34
  sns: config.sns
37
35
  };
36
+ return endpoint;
38
37
  })
39
38
  .then(function (endpoint) { return endpoint; }); };
40
39
  this.stop = function () { return _this.onlyWhenStarted(_this.server).stop()
41
- .then(function () { return _this.LOGGER.debug('stopped'); }); };
40
+ .then(function () { return _this.LOGGER.info('stopped'); }); };
42
41
  this.handler = function (method, subject) {
43
42
  return function (request, body, response) {
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');
@@ -77,7 +76,6 @@ var SnsHttpProxy = /** @class */ (function () {
77
76
  };
78
77
  this.server = new http_server_1.HttpServer(this.name, this.settings, this.handler(this.method, this.subject));
79
78
  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');
81
79
  }
82
80
  return SnsHttpProxy;
83
81
  }());
package/dist/src/sns.js CHANGED
@@ -50,8 +50,7 @@ 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'); })
54
- .tap(function (arn) { return LOGGER.debug('topic %o created', arn); })];
53
+ .then(function (o) { return (0, assert_1.assertNotUndefined)(o.TopicArn, 'TopicArn is not present'); })];
55
54
  });
56
55
  }); };
57
56
  this.createSubscription = function (topic, queue) { return __awaiter(_this, void 0, void 0, function () {
@@ -62,7 +61,7 @@ var Sns = /** @class */ (function () {
62
61
  Protocol: 'sqs',
63
62
  Endpoint: queue.arn,
64
63
  }))
65
- .then(function () { return LOGGER.debug('subscription %s->%s created', topic.arn, queue.arn); })];
64
+ .then(function () { return LOGGER.debug('connected %s to %s', topic.arn, queue.arn); })];
66
65
  });
67
66
  }); };
68
67
  this.publish = function (topic, body, subject, attributes) { return __awaiter(_this, void 0, void 0, function () {
@@ -74,11 +73,12 @@ var Sns = /** @class */ (function () {
74
73
  MessageAttributes: attributes,
75
74
  Subject: subject,
76
75
  }))
77
- .then(function () { return LOGGER.trace('published %s[%s]', topic.arn, subject); })
76
+ .then(function () { return LOGGER.debug('published with subject %s to %s', subject, topic.arn); })
78
77
  .then()];
79
78
  });
80
79
  }); };
81
80
  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,9 +3,7 @@ import { AwsConfig } from "./config";
3
3
  export declare class Sqs {
4
4
  readonly client: SQSClient;
5
5
  constructor(config: AwsConfig);
6
- createStandardQueue: (name: string) => Promise<Queue>;
7
- createFifoQueue: (name: string) => Promise<Queue>;
8
- private createNamedQueue;
6
+ createNamedQueue: (name: string) => Promise<Queue>;
9
7
  }
10
8
  export type Queue = {
11
9
  arn: string;
package/dist/src/sqs.js CHANGED
@@ -45,21 +45,12 @@ 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.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 () {
48
+ this.createNamedQueue = function (name) { return __awaiter(_this, void 0, void 0, function () {
55
49
  var _this = this;
56
50
  return __generator(this, function (_a) {
57
51
  return [2 /*return*/, this.client
58
52
  .send(new client_sqs_1.CreateQueueCommand({
59
- QueueName: fifo ? "".concat(name, ".fifo") : name,
60
- Attributes: {
61
- FifoQueue: fifo ? 'true' : 'false',
62
- }
53
+ QueueName: name,
63
54
  }))
64
55
  .then(function (create) { return _this.client
65
56
  .send(new client_sqs_1.GetQueueAttributesCommand({
@@ -69,11 +60,11 @@ var Sqs = /** @class */ (function () {
69
60
  .then(function (attributes) { return ({
70
61
  url: (0, assert_1.assertNotUndefined)(create.QueueUrl),
71
62
  arn: (0, assert_1.assertNotUndefined)(attributes.Attributes)[QUEUE_NAME_ATTRIBUTE_NAME],
72
- }); }); })
73
- .tap(function (queue) { return LOGGER.debug('created %s', queue.arn); })];
63
+ }); }); })];
74
64
  });
75
65
  }); };
76
66
  this.client = new client_sqs_1.SQSClient(config);
67
+ LOGGER.debug('initialized');
77
68
  }
78
69
  return Sqs;
79
70
  }());
@@ -1,2 +1,2 @@
1
1
  import { Consumer } from "sqs-consumer";
2
- export declare const stopConsumer: (queueWaitTimeSecs: number, target?: Consumer) => Promise<void>;
2
+ export declare const stopConsumer: (target: Consumer, queueWaitTimeSecs: number) => Promise<void>;
@@ -37,18 +37,12 @@ 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 (queueWaitTimeSecs, target) { return __awaiter(void 0, void 0, void 0, function () {
40
+ var stopConsumer = function (target, queueWaitTimeSecs) { return __awaiter(void 0, void 0, void 0, function () {
41
41
  return __generator(this, function (_a) {
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*/];
42
+ target.stop();
43
+ return [2 /*return*/, new Promise(function (resolve) {
44
+ setTimeout(resolve, queueWaitTimeSecs * 1000 + 1);
45
+ })];
52
46
  });
53
47
  }); };
54
48
  exports.stopConsumer = stopConsumer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yopdev/dev-server",
3
- "version": "1.3.17",
3
+ "version": "1.4.0-alpha.0",
4
4
  "scripts": {
5
5
  "compile": "tsc",
6
6
  "pretest": "npm run compile",
@@ -18,17 +18,15 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@aws-sdk/client-dynamodb": "^3.451.0",
21
- "@aws-sdk/client-s3": "^3.451.0",
22
21
  "@aws-sdk/client-sns": "^3.451.0",
23
22
  "@aws-sdk/client-sqs": "^3.451.0",
24
- "@ngrok/ngrok": "^0.9.1",
25
23
  "@yopdev/logging": "^0.0.2",
26
24
  "sqs-consumer": "^7.4.0",
27
25
  "testcontainers": "^10.2.2"
28
26
  },
29
27
  "repository": {
30
28
  "type": "git",
31
- "url": "git+https://github.com/blockademy/devserver.git"
29
+ "url": "github:blockademy/devserver"
32
30
  },
33
31
  "main": "dist/src/index.js",
34
32
  "types": "dist/src/index.d.ts",
@@ -1,18 +0,0 @@
1
- import { BindMount, Environment } from 'testcontainers/build/types';
2
- import { Callback, Service } from './services';
3
- import { PortWithOptionalBinding } from 'testcontainers/build/utils/port';
4
- import { Readable } from 'stream';
5
- import { WaitStrategy } from 'testcontainers/build/wait-strategies/wait-strategy';
6
- export declare const newContainer: (name: string, config: {
7
- image: string;
8
- networkAlias: string;
9
- environment?: Environment;
10
- bindMounts?: BindMount[];
11
- exposedPorts?: PortWithOptionalBinding[];
12
- logConsumer?: (stream: Readable) => unknown;
13
- startup?: {
14
- waitStrategy: WaitStrategy;
15
- timeout: number;
16
- };
17
- endpointBuilder?: (port: number) => string;
18
- }, callback?: Callback<string>) => Service<string>;
@@ -1,80 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.newContainer = void 0;
40
- var logging_1 = require("@yopdev/logging");
41
- var testcontainers_1 = require("testcontainers");
42
- var services_1 = require("./services");
43
- var newContainer = function (name, config, callback) {
44
- return new services_1.Service(new Container(name, config.image, config.networkAlias, config.environment, config.bindMounts, config.exposedPorts, config.logConsumer, config.startup, config.endpointBuilder), callback);
45
- };
46
- exports.newContainer = newContainer;
47
- var Container = /** @class */ (function () {
48
- function Container(name, image, networkAlias, environment, bindMounts, exposedPorts, logConsumer, startup, endpointBuilder) {
49
- var _this = this;
50
- this.name = name;
51
- this.networkAlias = networkAlias;
52
- this.start = function (config) { return __awaiter(_this, void 0, void 0, function () {
53
- var _this = this;
54
- return __generator(this, function (_a) {
55
- return [2 /*return*/, Promise.resolve(this.LOGGER.info('start'))
56
- .then(function () { return _this.container
57
- .withNetwork(config.network)
58
- .withNetworkAliases(_this.networkAlias)
59
- .start(); })
60
- .then(function (started) { return _this.started = started; })
61
- .then(function () { return _this.endpointBuilder(_this.started.getFirstMappedPort()); })
62
- .tap(function (url) { return _this.LOGGER.debug(url); })];
63
- });
64
- }); };
65
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
66
- return [2 /*return*/, this.started.stop().then(function () { return undefined; })];
67
- }); }); };
68
- this.LOGGER = logging_1.LoggerFactory.create("CONTAINER[".concat(name, "]"));
69
- var generic = new testcontainers_1.GenericContainer(image);
70
- var withEnvironment = environment ? generic.withEnvironment(environment) : generic;
71
- var withBindMounts = bindMounts ? withEnvironment.withBindMounts(bindMounts) : withEnvironment;
72
- var withExposedPorts = exposedPorts ? withBindMounts.withExposedPorts.apply(withBindMounts, exposedPorts) : withBindMounts;
73
- var withLogConsumer = logConsumer ? withExposedPorts.withLogConsumer(logConsumer) : withExposedPorts;
74
- this.container = startup ? withLogConsumer.withWaitStrategy(startup.waitStrategy).withStartupTimeout(startup.timeout) : withLogConsumer;
75
- this.networkAlias = networkAlias;
76
- this.endpointBuilder = endpointBuilder !== null && endpointBuilder !== void 0 ? endpointBuilder : (function (port) { return "http://localhost:".concat(port); });
77
- }
78
- return Container;
79
- }());
80
- ;
package/dist/src/s3.d.ts DELETED
@@ -1,7 +0,0 @@
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 DELETED
@@ -1,74 +0,0 @@
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,10 +0,0 @@
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>;
@@ -1,79 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.newTunnel = exports.terminate = void 0;
40
- var services_1 = require("./services");
41
- var logging_1 = require("@yopdev/logging");
42
- var ngrok = require("@ngrok/ngrok");
43
- var assert_1 = require("./assert");
44
- var terminate = function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
45
- return [2 /*return*/, ngrok.kill()];
46
- }); }); };
47
- exports.terminate = terminate;
48
- var newTunnel = function (config) {
49
- return new services_1.Service(new Tunnel(config.name, config.port, config.fixed));
50
- };
51
- exports.newTunnel = newTunnel;
52
- var Tunnel = /** @class */ (function () {
53
- function Tunnel(name, port, domain) {
54
- var _this = this;
55
- this.name = name;
56
- this.port = port;
57
- this.domain = domain;
58
- this.start = function () { return __awaiter(_this, void 0, void 0, function () {
59
- var _this = this;
60
- var _a, _b;
61
- return __generator(this, function (_c) {
62
- return [2 /*return*/, ngrok
63
- .forward({
64
- proto: 'http',
65
- domain: (_a = this.domain) === null || _a === void 0 ? void 0 : _a.name,
66
- addr: this.port,
67
- authtoken: (_b = this.domain) === null || _b === void 0 ? void 0 : _b.token,
68
- })
69
- .then(function (listener) { return (0, assert_1.assertNotUndefined)(listener.url()); })
70
- .tap(function (url) { return _this.logger.debug(url); })];
71
- });
72
- }); };
73
- this.stop = function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
74
- return [2 /*return*/, ngrok.disconnect()];
75
- }); }); };
76
- this.logger = logging_1.LoggerFactory.create("TUNNEL[".concat(name, "]"));
77
- }
78
- return Tunnel;
79
- }());