@sellout/service 0.0.384 → 1.0.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.
Files changed (68) hide show
  1. package/{src/BaseService.ts → BaseService.ts} +7 -18
  2. package/{src/NatsConnectionManager.ts → NatsConnectionManager.ts} +3 -1
  3. package/{src/PbAsyncMessageHandler.ts → PbAsyncMessageHandler.ts} +1 -2
  4. package/{src/PbBroadcastProxy.ts → PbBroadcastProxy.ts} +4 -2
  5. package/{src/Tracer.ts → Tracer.ts} +2 -7
  6. package/{src/env.ts → env.ts} +2 -0
  7. package/interfaces.ts +100 -0
  8. package/package.json +3 -23
  9. package/{.dist/build → service-build}/tsconfig.json +0 -1
  10. package/.dist/BaseService.d.ts +0 -27
  11. package/.dist/BaseService.js +0 -95
  12. package/.dist/BaseService.js.map +0 -1
  13. package/.dist/ConsoleLogManager.d.ts +0 -9
  14. package/.dist/ConsoleLogManager.js +0 -18
  15. package/.dist/ConsoleLogManager.js.map +0 -1
  16. package/.dist/MongoConnectionManager.d.ts +0 -9
  17. package/.dist/MongoConnectionManager.js +0 -52
  18. package/.dist/MongoConnectionManager.js.map +0 -1
  19. package/.dist/NatsConnectionManager.d.ts +0 -117
  20. package/.dist/NatsConnectionManager.js +0 -215
  21. package/.dist/NatsConnectionManager.js.map +0 -1
  22. package/.dist/PbAsyncMessageHandler.d.ts +0 -15
  23. package/.dist/PbAsyncMessageHandler.js +0 -27
  24. package/.dist/PbAsyncMessageHandler.js.map +0 -1
  25. package/.dist/PbBroadcastProxy.d.ts +0 -25
  26. package/.dist/PbBroadcastProxy.js +0 -41
  27. package/.dist/PbBroadcastProxy.js.map +0 -1
  28. package/.dist/PbMessageHandler.d.ts +0 -27
  29. package/.dist/PbMessageHandler.js +0 -47
  30. package/.dist/PbMessageHandler.js.map +0 -1
  31. package/.dist/PbServiceProxy.d.ts +0 -38
  32. package/.dist/PbServiceProxy.js +0 -65
  33. package/.dist/PbServiceProxy.js.map +0 -1
  34. package/.dist/Segment.d.ts +0 -12
  35. package/.dist/Segment.js +0 -34
  36. package/.dist/Segment.js.map +0 -1
  37. package/.dist/Tracer.d.ts +0 -22
  38. package/.dist/Tracer.js +0 -55
  39. package/.dist/Tracer.js.map +0 -1
  40. package/.dist/TracerExpress.d.ts +0 -1
  41. package/.dist/TracerExpress.js +0 -44
  42. package/.dist/TracerExpress.js.map +0 -1
  43. package/.dist/env.d.ts +0 -5
  44. package/.dist/env.js +0 -9
  45. package/.dist/env.js.map +0 -1
  46. package/.dist/interfaces.d.ts +0 -32
  47. package/.dist/interfaces.js +0 -3
  48. package/.dist/interfaces.js.map +0 -1
  49. package/.dist/joiToErrors.d.ts +0 -3
  50. package/.dist/joiToErrors.js +0 -45
  51. package/.dist/joiToErrors.js.map +0 -1
  52. package/.dist/schemas.d.ts +0 -0
  53. package/.dist/schemas.js +0 -1
  54. package/.dist/schemas.js.map +0 -1
  55. package/src/MongoConnectionManager.ts +0 -50
  56. package/src/build/tsconfig.json +0 -33
  57. package/src/build/tslint.json +0 -17
  58. package/src/interfaces.ts +0 -47
  59. package/tsconfig.json +0 -29
  60. package/tslint.json +0 -21
  61. /package/{src/ConsoleLogManager.ts → ConsoleLogManager.ts} +0 -0
  62. /package/{src/PbMessageHandler.ts → PbMessageHandler.ts} +0 -0
  63. /package/{src/PbServiceProxy.ts → PbServiceProxy.ts} +0 -0
  64. /package/{src/Segment.ts → Segment.ts} +0 -0
  65. /package/{src/TracerExpress.ts → TracerExpress.ts} +0 -0
  66. /package/{src/joiToErrors.ts → joiToErrors.ts} +0 -0
  67. /package/{src/schemas.ts → schemas.ts} +0 -0
  68. /package/{.dist/build → service-build}/tslint.json +0 -0
@@ -9,7 +9,6 @@ import {
9
9
  } from "./env";
10
10
  import * as Sentry from "@sentry/node";
11
11
  import Segment from "./Segment";
12
- import * as pb from '@sellout/models/.dist/sellout-proto';
13
12
 
14
13
  /**
15
14
  * Provides the abstract class for all service implementations.
@@ -22,7 +21,6 @@ class BaseService {
22
21
  public storage;
23
22
  public segment: Segment;
24
23
  public collectDefaultMetrics;
25
- public ready: any
26
24
 
27
25
  constructor(opts: IServiceOpts) {
28
26
  this.opts = opts;
@@ -46,11 +44,10 @@ class BaseService {
46
44
  }
47
45
 
48
46
  // Enable/Disable Prometheus
49
- if (!DISABLE_PROMETHEUS) {
47
+ if(!DISABLE_PROMETHEUS) {
50
48
  // set up Prometheus client metrics gathering
51
49
  const collectDefaultMetrics = Prometheus.collectDefaultMetrics;
52
- // collectDefaultMetrics({ timeout: 5000 });
53
- collectDefaultMetrics();
50
+ collectDefaultMetrics({ timeout: 5000 });
54
51
 
55
52
  // initialize Express app
56
53
  const app = express();
@@ -59,11 +56,11 @@ class BaseService {
59
56
  // Metrics endpoint
60
57
  app.get('/metrics', (req, res) => {
61
58
  res.set('Content-Type', Prometheus.register.contentType)
62
- res.send(Prometheus.register.metrics())
59
+ res.end(Prometheus.register.metrics())
63
60
  });
64
61
 
65
- app.get('/readiness', async (req, res) => {
66
- if (await this.isReady()) {
62
+ app.get('/readiness', (req, res) => {
63
+ if (this.isReady()) {
67
64
  res.status(200).send('OK');
68
65
  } else {
69
66
  res.status(500).send('Not ready');
@@ -81,16 +78,8 @@ class BaseService {
81
78
  }
82
79
 
83
80
  // override to have derived classes declare non-readiness to k8s
84
-
85
- // public async isReady() : Promise<boolean> {
86
- // return true;
87
- // }
88
-
89
- public async isReady(): Promise<{ statusCode: pb.StatusCode; isReady: boolean }> {
90
- return {
91
- statusCode: pb.StatusCode.OK, // Indicates successful readiness
92
- isReady: true, // Confirms that the service is operational
93
- };
81
+ public isReady() : boolean {
82
+ return true;
94
83
  }
95
84
 
96
85
  /**
@@ -4,6 +4,8 @@ import { IConnectionManager, ILogManager, ISubscriptionRoutes } from './interfac
4
4
 
5
5
  const BROADCAST_PREFIX = 'BROADCAST'; /* Prefix for broadcast messages */
6
6
 
7
+ /* tslint:disable: max-classes-per-file */
8
+
7
9
  /**
8
10
  * Exposes connection operations for NATS.
9
11
  */
@@ -49,7 +51,7 @@ class NatsConnectionManager implements IConnectionManager {
49
51
  *
50
52
  * @param {boolean} verbose - Log all events if true
51
53
  */
52
- constructor(natsServers: string[], logger: ILogManager, verbose = false, defaultRequestTimeout = 120000) {
54
+ constructor(natsServers: string[], logger: ILogManager, verbose = false, defaultRequestTimeout = 60000) {
53
55
  this.logger = logger;
54
56
  this.natsServers = natsServers;
55
57
  this.verbose = verbose;
@@ -1,6 +1,5 @@
1
- import * as pb from "@sellout/models/.dist/sellout-proto";
2
1
  import { PbMessageHandler } from './PbMessageHandler';
3
-
2
+ import * as pb from './../dist/sellout-proto';
4
3
 
5
4
  /* Message handler wrapper method for unidirectional calls */
6
5
  function invokeWithEmptyResponse(method) {
@@ -1,8 +1,8 @@
1
- import { Broadcast } from "@sellout/models/.dist/sellout-proto";
2
1
  import { IConnectionManager } from './interfaces';
3
2
  import { PbServiceProxy } from './PbServiceProxy';
3
+ import { Broadcast } from "./../dist/sellout-proto";
4
4
 
5
- export default class PbBroadcastProxy extends PbServiceProxy<Broadcast.Publisher> {
5
+ export class PbBroadcastProxy extends PbServiceProxy<Broadcast.Publisher> {
6
6
  constructor(conn: IConnectionManager) {
7
7
  super(conn, 'BROADCAST');
8
8
  }
@@ -39,3 +39,5 @@ export default class PbBroadcastProxy extends PbServiceProxy<Broadcast.Publisher
39
39
  }
40
40
  }
41
41
  }
42
+
43
+ export default PbBroadcastProxy;
@@ -1,7 +1,7 @@
1
1
  import { initTracer, Span, SpanContext } from 'jaeger-client';
2
2
  const JAEGER_AGENT_HOST = process.env.JAEGER_AGENT_HOST;
3
3
 
4
- // console.log(`Jaeger Agent Host: ${JAEGER_AGENT_HOST}`);
4
+ console.log(`Jaeger Agent Host: ${JAEGER_AGENT_HOST}`);
5
5
 
6
6
  export default class Tracer {
7
7
 
@@ -12,12 +12,7 @@ export default class Tracer {
12
12
  constructor(serviceName: string, logger: any = console, verbose: boolean = true) {
13
13
  this.serviceName = serviceName;
14
14
  this.logger = logger ? logger : console;
15
- try {
16
- this.tracer = initTracer(this.config(verbose), this.options());
17
- } catch (error) {
18
- console.log(error, 'err', this.tracer)
19
- this.tracer = null
20
- }
15
+ this.tracer = initTracer(this.config(verbose), this.options());
21
16
  }
22
17
 
23
18
  config(verbose: boolean) {
@@ -1,5 +1,7 @@
1
1
  export const DISABLE_PROMETHEUS = process.env.DISABLE_PROMETHEUS || false;
2
+ export const GOOGLE_TIMEZONE_API_KEY = process.env.GOOGLE_TIMEZONE_API_KEY;
2
3
  export const LOAD_TEST_ENABLED = process.env.LOAD_TEST_ENABLED === '1';
3
4
  export const SEGMENT_IO_WRITE_KEY = process.env.SEGMENT_IO_WRITE_KEY;
5
+ export const IP_STACK_API_KEY = process.env.IP_STACK_API_KEY;
4
6
  export const SENTRY_DSN = process.env.SENTRY_DSN;
5
7
  export const NODE_ENV = process.env.NODE_ENV || 'development';
package/interfaces.ts ADDED
@@ -0,0 +1,100 @@
1
+ export interface ISubscriptionRoutes {
2
+ [routeName: string]: IMessageHandler;
3
+ }
4
+
5
+ export interface IConnectionManager {
6
+ connect();
7
+ close();
8
+ on(event: string, cb: (...args: any[]) => void);
9
+ send(
10
+ serviceId: string,
11
+ method: string,
12
+ req: Buffer,
13
+ cb: (error, reply) => void,
14
+ timeout?: number
15
+ );
16
+ sendAsync(
17
+ serviceId: string,
18
+ method: string,
19
+ req: Buffer,
20
+ cb: (error, reply) => void,
21
+ timeout?: number
22
+ );
23
+ sendBroadcast(messageId: string, req: Buffer, cb: (error, reply) => void);
24
+ subscribe(serviceId: string, queue: string, routes: ISubscriptionRoutes);
25
+ subscribeBroadcast(serviceId: string, routes: ISubscriptionRoutes);
26
+ }
27
+
28
+ export interface ILogManager {
29
+ info(msg: string, ...params: string[]): void;
30
+ warn(msg: string, ...params: string[]): void;
31
+ error(msg: string, ...params: string[]): void;
32
+ }
33
+
34
+ export interface ILogManagerOpts {
35
+ serviceName: string;
36
+ }
37
+
38
+ export interface IMessageHandler {
39
+ process(req: Buffer): Promise<Buffer>;
40
+ }
41
+
42
+ export interface IServiceOpts {
43
+ serviceName: string;
44
+ connectionMgr: IConnectionManager;
45
+ logManager: ILogManager;
46
+ storageManager?: any;
47
+ }
48
+
49
+ export interface IPagination {
50
+ pageSize: number;
51
+ pageNumber: number;
52
+ }
53
+
54
+ export interface IAddress {
55
+ address1?: string;
56
+ address2?: string;
57
+ city?: string;
58
+ state?: string;
59
+ zip?: string;
60
+ country?: string;
61
+ phone?: string;
62
+ lat?: number;
63
+ lng?: number;
64
+ placeId?: string;
65
+ timezone?: string;
66
+ }
67
+
68
+ export interface IMetrics {
69
+ _id?: string;
70
+ orgId: string;
71
+ createdAt: number;
72
+ // Value
73
+ lifeTimeValue?: number;
74
+ yearToDateValue?: number;
75
+ lifeTimeValueRefunded?: number;
76
+ yearToDateValueRefunded?: number;
77
+ lifeTimeValueComped?: number;
78
+ yearToDateValueComped?: number;
79
+ // Tickets
80
+ lifeTimeTicketsPurchased?: number;
81
+ yearToDateTicketsPurchased?: number;
82
+ lifeTimeTicketsRefunded?: number;
83
+ yearToDateTicketsRefunded?: number;
84
+ lifeTimeTicketsComped?: number;
85
+ yearToDateTicketsComped?: number;
86
+ // Upgrades
87
+ lifeTimeUpgradesPurchased?: number;
88
+ yearToDateUpgradesPurchased?: number;
89
+ lifeTimeUpgradesRefunded?: number;
90
+ yearToDateUpgradesRefunded?: number;
91
+ lifeTimeUpgradesComped?: number;
92
+ yearToDateUpgradesComped?: number;
93
+ // Orders
94
+ lifeTimeOrdersPurchased?: number;
95
+ yearToDateOrdersPurchased?: number;
96
+ lifeTimeOrdersRefunded?: number;
97
+ yearToDateOrdersRefunded?: number;
98
+ lifeTimeOrdersComped?: number;
99
+ yearToDateOrdersComped?: number;
100
+ }
package/package.json CHANGED
@@ -1,35 +1,15 @@
1
1
  {
2
2
  "name": "@sellout/service",
3
- "version": "0.0.384",
3
+ "version": "1.0.0",
4
4
  "description": "Sellout.io base service",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "prepare": "npm run build",
8
- "build": "tsc --project . && cp -r src/build .dist",
9
- "start": "nodemon --watch src -e json,js,ts -x \"npm run build\""
7
+ "test": "echo \"Error: no test specified\" && exit 1"
10
8
  },
11
9
  "repository": {
12
10
  "type": "git",
13
11
  "url": "www.github.com/sellout-tickets/sellout/common/service"
14
12
  },
15
13
  "author": "samheutmaker@gmail.com",
16
- "license": "MIT",
17
- "dependencies": {
18
- "@sellout/models": "^0.0.384",
19
- "@sellout/utils": "^0.0.384",
20
- "@sentry/node": "^5.30.0",
21
- "analytics-node": "^3.5.0",
22
- "express": "^4.18.2",
23
- "jaeger-client": "^3.19.0",
24
- "nats": "^1.4.12",
25
- "prom-client": "^14.2.0",
26
- "url": "^0.11.0"
27
- },
28
- "devDependencies": {
29
- "@types/long": "^4.0.2",
30
- "@types/node": "^20.11.19",
31
- "nodemon": "^2.0.22",
32
- "typescript": "^4.4.2"
33
- },
34
- "gitHead": "1cbafa1999f5f1f90bf6c4fa934d2b6e0278a3de"
14
+ "license": "MIT"
35
15
  }
@@ -10,7 +10,6 @@
10
10
  "module": "commonjs",
11
11
  "outDir": "./.dist/",
12
12
  "declaration": true,
13
- "jsx": "react",
14
13
  // "sourceMap": true,
15
14
  // "strictNullChecks": true,
16
15
  "noUnusedLocals": true,
@@ -1,27 +0,0 @@
1
- import { IConnectionManager, ILogManager, IServiceOpts } from "./interfaces";
2
- import Segment from "./Segment";
3
- import * as pb from '@sellout/models/.dist/sellout-proto';
4
- /**
5
- * Provides the abstract class for all service implementations.
6
- */
7
- declare class BaseService {
8
- opts: IServiceOpts;
9
- serviceName: string;
10
- connectionMgr: IConnectionManager;
11
- logger: ILogManager;
12
- storage: any;
13
- segment: Segment;
14
- collectDefaultMetrics: any;
15
- ready: any;
16
- constructor(opts: IServiceOpts);
17
- isReady(): Promise<{
18
- statusCode: pb.StatusCode;
19
- isReady: boolean;
20
- }>;
21
- /**
22
- * Register message listeners here.
23
- */
24
- register(): void;
25
- run(): void;
26
- }
27
- export default BaseService;
@@ -1,95 +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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const Prometheus = require("prom-client");
13
- const express = require("express");
14
- const env_1 = require("./env");
15
- const Sentry = require("@sentry/node");
16
- const Segment_1 = require("./Segment");
17
- const pb = require("@sellout/models/.dist/sellout-proto");
18
- /**
19
- * Provides the abstract class for all service implementations.
20
- */
21
- class BaseService {
22
- constructor(opts) {
23
- this.opts = opts;
24
- this.connectionMgr = this.opts.connectionMgr;
25
- this.logger = this.opts.logManager;
26
- this.serviceName = this.opts.serviceName;
27
- this.storage = this.opts.storageManager;
28
- this.segment = new Segment_1.default(env_1.SEGMENT_IO_WRITE_KEY, this.logger);
29
- /**
30
- * Initialize Sentry
31
- */
32
- if (env_1.SENTRY_DSN) {
33
- this.logger.info("Sentry - Initializing with environment ${NODE_ENV}...");
34
- Sentry.init({
35
- dsn: env_1.SENTRY_DSN,
36
- environment: env_1.NODE_ENV,
37
- });
38
- }
39
- else {
40
- this.logger.warn("Sentry - No DSN supplied, skipping initialization...");
41
- }
42
- // Enable/Disable Prometheus
43
- if (!env_1.DISABLE_PROMETHEUS) {
44
- // set up Prometheus client metrics gathering
45
- const collectDefaultMetrics = Prometheus.collectDefaultMetrics;
46
- // collectDefaultMetrics({ timeout: 5000 });
47
- collectDefaultMetrics();
48
- // initialize Express app
49
- const app = express();
50
- const metricsPort = 5499; // todo: parameterize this
51
- // Metrics endpoint
52
- app.get('/metrics', (req, res) => {
53
- res.set('Content-Type', Prometheus.register.contentType);
54
- res.send(Prometheus.register.metrics());
55
- });
56
- app.get('/readiness', (req, res) => __awaiter(this, void 0, void 0, function* () {
57
- if (yield this.isReady()) {
58
- res.status(200).send('OK');
59
- }
60
- else {
61
- res.status(500).send('Not ready');
62
- }
63
- }));
64
- // as long as the event loop is running this should run
65
- app.get('/liveness', (req, res) => {
66
- res.status(200).send('OK');
67
- });
68
- // listen for metrics requests
69
- app.listen(metricsPort, () => this.logger.info(`Service '${this.serviceName}' listening for metrics requests on port ${metricsPort}.`));
70
- }
71
- }
72
- // override to have derived classes declare non-readiness to k8s
73
- // public async isReady() : Promise<boolean> {
74
- // return true;
75
- // }
76
- isReady() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- return {
79
- statusCode: pb.StatusCode.OK,
80
- isReady: true, // Confirms that the service is operational
81
- };
82
- });
83
- }
84
- /**
85
- * Register message listeners here.
86
- */
87
- register() {
88
- throw new Error("Not Implemented: register method in Service class.");
89
- }
90
- run() {
91
- throw new Error("Not Implemented: run method in Service class.");
92
- }
93
- }
94
- exports.default = BaseService;
95
- //# sourceMappingURL=BaseService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BaseService.js","sourceRoot":"","sources":["../src/BaseService.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,0CAA0C;AAC1C,mCAAmC;AACnC,+BAKe;AACf,uCAAuC;AACvC,uCAAgC;AAChC,0DAA0D;AAE1D;;GAEG;AACH,MAAM,WAAW;IAUf,YAAY,IAAkB;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;QAC7C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;QACzC,IAA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AC,GAAG,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;iBACnC;YACH,CAAC,CAAA,CAAC,CAAC;YAEH,uDAAuD;YACvD,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;gBAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC,CAAC,CAAC;YAEH,8BAA8B;YAC9B,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,WAAW,4CAA4C,WAAW,GAAG,CAAC,CAAC,CAAC;SACzI;IACH,CAAC;IAED,gEAAgE;IAEhE,8CAA8C;IAC9C,iBAAiB;IACjB,IAAI;IAES,OAAO;;YAClB,OAAO;gBACL,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE;gBAC5B,OAAO,EAAE,IAAI,EAAE,2CAA2C;aAC3D,CAAC;QACJ,CAAC;KAAA;IAED;;OAEG;IACI,QAAQ;QACb,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAEM,GAAG;QACR,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;CACF;AAED,kBAAe,WAAW,CAAC"}
@@ -1,9 +0,0 @@
1
- import { ILogManager, ILogManagerOpts } from "./interfaces";
2
- declare class ConsoleLogManager implements ILogManager {
3
- opts: ILogManagerOpts;
4
- constructor(opts: ILogManagerOpts);
5
- info(msg: string, ...params: string[]): void;
6
- warn(msg: string, ...params: string[]): void;
7
- error(msg: string, ...params: string[]): void;
8
- }
9
- export default ConsoleLogManager;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class ConsoleLogManager {
4
- constructor(opts) {
5
- this.opts = opts;
6
- }
7
- info(msg, ...params) {
8
- console.info(msg, ...params);
9
- }
10
- warn(msg, ...params) {
11
- console.warn(msg, ...params);
12
- }
13
- error(msg, ...params) {
14
- console.error(msg, ...params);
15
- }
16
- }
17
- exports.default = ConsoleLogManager;
18
- //# sourceMappingURL=ConsoleLogManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConsoleLogManager.js","sourceRoot":"","sources":["../src/ConsoleLogManager.ts"],"names":[],"mappings":";;AAEA,MAAM,iBAAiB;IAGrB,YAAY,IAAqB;QAC/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAEM,IAAI,CAAC,GAAW,EAAE,GAAG,MAAgB;QAC1C,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,IAAI,CAAC,GAAW,EAAE,GAAG,MAAgB;QAC1C,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAC/B,CAAC;IAEM,KAAK,CAAC,GAAW,EAAE,GAAG,MAAgB;QAC3C,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,CAAC;IAChC,CAAC;CACF;AAED,kBAAe,iBAAiB,CAAC"}
@@ -1,9 +0,0 @@
1
- export default class MongoConnectionManager {
2
- connected: boolean;
3
- mongoConnectionString: string;
4
- isReplicaSet: boolean;
5
- private mongoose;
6
- private mongoConnectionStringInternal;
7
- constructor(mongoose: any, mongoConnectionString: string, username?: string, password?: string);
8
- connect(): Promise<void>;
9
- }
@@ -1,52 +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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const wait_1 = require("@sellout/utils/.dist/wait");
13
- class MongoConnectionManager {
14
- constructor(mongoose, mongoConnectionString, username = '', password = '') {
15
- const parsed = new URL(mongoConnectionString);
16
- parsed.username = username;
17
- parsed.password = password;
18
- parsed.pathname = '/admin';
19
- this.connected = false;
20
- this.mongoConnectionStringInternal = parsed.toString();
21
- this.isReplicaSet = parsed.protocol === 'mongodb+srv:';
22
- // redact username/password from publicly available connection string
23
- parsed.username = '__user__';
24
- parsed.password = '__pass__';
25
- this.mongoConnectionString = parsed.toString();
26
- this.mongoose = mongoose;
27
- }
28
- connect() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- while (!this.connected) {
31
- console.log('Attempting to connect to Mongo...');
32
- this.mongoose.connect(this.mongoConnectionStringInternal, {
33
- ssl: false,
34
- useUnifiedTopology: true,
35
- useNewUrlParser: true,
36
- })
37
- .then(() => {
38
- this.connected = true;
39
- console.log(`Connected to MongoDB: ${this.mongoConnectionString}`);
40
- })
41
- .catch((e) => {
42
- console.error(`There was an error connecting to MongoDB: ${this.mongoConnectionString}`);
43
- console.error(e);
44
- });
45
- // wait five seconds before trying again
46
- yield (0, wait_1.default)(5000);
47
- }
48
- });
49
- }
50
- }
51
- exports.default = MongoConnectionManager;
52
- //# sourceMappingURL=MongoConnectionManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MongoConnectionManager.js","sourceRoot":"","sources":["../src/MongoConnectionManager.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAA6C;AAE7C,MAAqB,sBAAsB;IAOzC,YAAY,QAAa,EAAE,qBAA6B,EAAE,WAAmB,EAAE,EAAE,WAAmB,EAAE;QACpG,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAE9C,MAAM,CAAC,QAAQ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AA;CACF;AA9CD,yCA8CC"}
@@ -1,117 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- import { IConnectionManager, ILogManager, ISubscriptionRoutes } from './interfaces';
5
- /**
6
- * Exposes connection operations for NATS.
7
- */
8
- declare class NatsConnectionManager implements IConnectionManager {
9
- /**
10
- * Exception representing an error that occurred during invocation of
11
- * a message handler.
12
- *
13
- */
14
- static MESSAGE_HANDLER_ERROR: {
15
- new (errors: any, messageSubject: string): {
16
- errors: any;
17
- name: string;
18
- message: string;
19
- stack?: string | undefined;
20
- };
21
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
22
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
23
- stackTraceLimit: number;
24
- };
25
- /**
26
- * Exception caused by request timeout.
27
- */
28
- static TIMEOUT_ERROR: {
29
- new (errors: any): {
30
- errors: any;
31
- name: string;
32
- message: string;
33
- stack?: string | undefined;
34
- };
35
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
36
- prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
37
- stackTraceLimit: number;
38
- };
39
- natsServers: string[];
40
- private verbose;
41
- private defaultRequestTimeout;
42
- private conn;
43
- private logPrefix;
44
- private logger;
45
- /**
46
- * Manages connections to NATS servers.
47
- * @constructor
48
- *
49
- * @param {boolean} verbose - Log all events if true
50
- */
51
- constructor(natsServers: string[], logger: ILogManager, verbose?: boolean, defaultRequestTimeout?: number);
52
- /**
53
- * Connect to one of the specified servers.
54
- *
55
- * @param {string[]} servers - Array of server URLs for NATS (server is randomly chosen)
56
- */
57
- connect(waitForConnect?: boolean): void;
58
- /**
59
- * Close active connections.
60
- */
61
- close(): void;
62
- /**
63
- * Expose event system of Nats client.
64
- *
65
- * @param event
66
- * @callback cb
67
- */
68
- on(event: string, cb: (...args: any[]) => void): void;
69
- /**
70
- * Subscribes a service listener to its methods within a NATS queue.
71
- *
72
- * IMPORTANT: Ensure service message handlers are defined via arrow functions
73
- * to ensure instance variables of the class are accessible within
74
- * the scope of the handlers.
75
- *
76
- * @param service - Service Id of listener
77
- * @param @optional {string} - Optional name of queue to subscribe
78
- * @param {SubscriptionRoutes} routes - Mapping of method Ids to handlers
79
- */
80
- subscribe(serviceId: string, queue: string, routes: ISubscriptionRoutes): void;
81
- subscribeBroadcast(serviceId: string, routes: ISubscriptionRoutes): void;
82
- subscribeTopic(topicQualifier: string, queue: string | undefined, routes: ISubscriptionRoutes): void;
83
- /**
84
- * Publish request for service.
85
- *
86
- * @param {string} serviceId - Service Id of receipient
87
- * @param {string} method - Id of method to call
88
- * @param {Buffer} req - Request buffer
89
- * @callback cb - Reply callback
90
- * @param { number} [timeout] - Register a default timeout for requests
91
- */
92
- send: (serviceId: string, method: string, req: Buffer, cb: (error: any, reply: any) => void, timeout?: number) => void;
93
- /**
94
- * Publish a broadcast message
95
- */
96
- sendBroadcast: (messageId: string, req: Buffer, cb: (error: any, reply: any) => void) => void;
97
- /**
98
- * Publish asynchronous request for service.
99
- *
100
- * @param {string} serviceId - Service Id of receipient
101
- * @param {string} method - Id of method to call
102
- * @param {Buffer} req - Request buffer
103
- * @callback cb - Reply callback
104
- */
105
- sendAsync: (serviceId: string, method: string, req: Buffer, cb: (error: any, reply: any) => void) => void;
106
- /**
107
- * Register for logged connection events
108
- */
109
- private enableLogging;
110
- /**
111
- * Log a message
112
- *
113
- * @param msg
114
- */
115
- private logMessage;
116
- }
117
- export default NatsConnectionManager;