@sellout/service 0.0.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 (67) hide show
  1. package/.dist/BaseService.d.ts +22 -0
  2. package/.dist/BaseService.js +77 -0
  3. package/.dist/BaseService.js.map +1 -0
  4. package/.dist/ConsoleLogManager.d.ts +9 -0
  5. package/.dist/ConsoleLogManager.js +18 -0
  6. package/.dist/ConsoleLogManager.js.map +1 -0
  7. package/.dist/MongoConnectionManager.d.ts +9 -0
  8. package/.dist/MongoConnectionManager.js +52 -0
  9. package/.dist/MongoConnectionManager.js.map +1 -0
  10. package/.dist/NatsConnectionManager.d.ts +115 -0
  11. package/.dist/NatsConnectionManager.js +215 -0
  12. package/.dist/NatsConnectionManager.js.map +1 -0
  13. package/.dist/PbAsyncMessageHandler.d.ts +15 -0
  14. package/.dist/PbAsyncMessageHandler.js +26 -0
  15. package/.dist/PbAsyncMessageHandler.js.map +1 -0
  16. package/.dist/PbBroadcastProxy.d.ts +25 -0
  17. package/.dist/PbBroadcastProxy.js +41 -0
  18. package/.dist/PbBroadcastProxy.js.map +1 -0
  19. package/.dist/PbMessageHandler.d.ts +26 -0
  20. package/.dist/PbMessageHandler.js +46 -0
  21. package/.dist/PbMessageHandler.js.map +1 -0
  22. package/.dist/PbServiceProxy.d.ts +38 -0
  23. package/.dist/PbServiceProxy.js +64 -0
  24. package/.dist/PbServiceProxy.js.map +1 -0
  25. package/.dist/Segment.d.ts +12 -0
  26. package/.dist/Segment.js +34 -0
  27. package/.dist/Segment.js.map +1 -0
  28. package/.dist/Tracer.d.ts +22 -0
  29. package/.dist/Tracer.js +49 -0
  30. package/.dist/Tracer.js.map +1 -0
  31. package/.dist/TracerExpress.d.ts +1 -0
  32. package/.dist/TracerExpress.js +42 -0
  33. package/.dist/TracerExpress.js.map +1 -0
  34. package/.dist/build/tsconfig.json +32 -0
  35. package/.dist/build/tslint.json +17 -0
  36. package/.dist/env.d.ts +5 -0
  37. package/.dist/env.js +8 -0
  38. package/.dist/env.js.map +1 -0
  39. package/.dist/interfaces.d.ts +31 -0
  40. package/.dist/interfaces.js +3 -0
  41. package/.dist/interfaces.js.map +1 -0
  42. package/.dist/joiToErrors.d.ts +3 -0
  43. package/.dist/joiToErrors.js +43 -0
  44. package/.dist/joiToErrors.js.map +1 -0
  45. package/.dist/schemas.d.ts +0 -0
  46. package/.dist/schemas.js +1 -0
  47. package/.dist/schemas.js.map +1 -0
  48. package/package.json +34 -0
  49. package/src/BaseService.ts +98 -0
  50. package/src/ConsoleLogManager.ts +23 -0
  51. package/src/MongoConnectionManager.ts +49 -0
  52. package/src/NatsConnectionManager.ts +268 -0
  53. package/src/PbAsyncMessageHandler.ts +28 -0
  54. package/src/PbBroadcastProxy.ts +41 -0
  55. package/src/PbMessageHandler.ts +49 -0
  56. package/src/PbServiceProxy.ts +66 -0
  57. package/src/Segment.ts +35 -0
  58. package/src/Tracer.ts +55 -0
  59. package/src/TracerExpress.ts +36 -0
  60. package/src/build/tsconfig.json +32 -0
  61. package/src/build/tslint.json +17 -0
  62. package/src/env.ts +5 -0
  63. package/src/interfaces.ts +47 -0
  64. package/src/joiToErrors.ts +48 -0
  65. package/src/schemas.ts +0 -0
  66. package/tsconfig.json +28 -0
  67. package/tslint.json +21 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PbBroadcastProxy.js","sourceRoot":"","sources":["../src/PbBroadcastProxy.ts"],"names":[],"mappings":";;AAAA,uEAAgE;AAEhE,qDAAkD;AAElD,MAAqB,gBAAiB,SAAQ,+BAAmC;IAC/E,YAAY,IAAwB;QAClC,KAAK,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAO3B;;;;;;;WAOG;QACO,gBAAW,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;YACxD,MAAK,CAAC,qDAAqD,CAAC,CAAC;QAC/D,CAAC,CAAA;QAED;;;;;;;WAOG;QACO,qBAAgB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;YAC7D,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;aAC7D;YAAC,OAAO,CAAC,EAAE;gBACV,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aACnB;QACH,CAAC,CAAA;IAhCD,CAAC;IAEM,QAAQ,CAAC,GAAG,GAAG,yBAAS,CAAC,SAAS;QACvC,OAAO,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;CA6BF;AApCD,mCAoCC"}
@@ -0,0 +1,26 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Provides a wrapper around Protobuf messages. Incoming buffers are decoded, the
4
+ * handler method is called using staticly-compiled Protobuf definitions, and returned
5
+ * reponse objects are encoded and marshalled into Buffer.
6
+ */
7
+ export declare class PbMessageHandler {
8
+ method: any;
9
+ requestCls: any;
10
+ responseCls: any;
11
+ /**
12
+ * @constructor
13
+ * @param method - Message handler method to be invoked
14
+ * @param requestCls - Request class provided by Protobuf
15
+ * @param responseCls - Response class provided by Protobuf
16
+ */
17
+ constructor(method: any, requestCls: any, responseCls: any);
18
+ /**
19
+ * Invoke registered message handler.
20
+ *
21
+ * @param {Buffer} req - Incoming request
22
+ * @returns {Promise<Buffer>} - Promise for buffer containing encoded response object
23
+ */
24
+ process(req: Buffer): Promise<Buffer>;
25
+ }
26
+ export default PbMessageHandler;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Provides a wrapper around Protobuf messages. Incoming buffers are decoded, the
5
+ * handler method is called using staticly-compiled Protobuf definitions, and returned
6
+ * reponse objects are encoded and marshalled into Buffer.
7
+ */
8
+ class PbMessageHandler {
9
+ /**
10
+ * @constructor
11
+ * @param method - Message handler method to be invoked
12
+ * @param requestCls - Request class provided by Protobuf
13
+ * @param responseCls - Response class provided by Protobuf
14
+ */
15
+ constructor(method, requestCls, responseCls) {
16
+ this.method = method;
17
+ this.requestCls = requestCls;
18
+ this.responseCls = responseCls;
19
+ }
20
+ /**
21
+ * Invoke registered message handler.
22
+ *
23
+ * @param {Buffer} req - Incoming request
24
+ * @returns {Promise<Buffer>} - Promise for buffer containing encoded response object
25
+ */
26
+ process(req) {
27
+ return new Promise((resolve, reject) => {
28
+ const decoded = this.requestCls.decode(req);
29
+ // Pass plain JS object. I think this is a good idea?
30
+ // Idk about the performance but we'll see :)
31
+ // TODO: enable defaults when decoding messages
32
+ const reqObj = this.requestCls.toObject(decoded);
33
+ this.method(reqObj).then((respObj) => {
34
+ const respEncoded = this.responseCls.encode(respObj).finish();
35
+ resolve(respEncoded);
36
+ })
37
+ .catch((e) => {
38
+ console.log(`Error processing message for method = ${this.method}`);
39
+ reject(e);
40
+ });
41
+ });
42
+ }
43
+ }
44
+ exports.PbMessageHandler = PbMessageHandler;
45
+ exports.default = PbMessageHandler;
46
+ //# sourceMappingURL=PbMessageHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PbMessageHandler.js","sourceRoot":"","sources":["../src/PbMessageHandler.ts"],"names":[],"mappings":";;AAAA;;;;GAIG;AACH,MAAa,gBAAgB;IAM3B;;;;;OAKG;IACH,YAAY,MAAM,EAAE,UAAU,EAAE,WAAW;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACI,OAAO,CAAC,GAAW;QACxB,OAAO,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7C,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YAC5C,sDAAsD;YACtD,6CAA6C;YAC5C,+CAA+C;YAChD,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACjD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;gBACnC,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC9D,OAAO,CAAC,WAAW,CAAC,CAAC;YACvB,CAAC,CAAC;iBACC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBACX,OAAO,CAAC,GAAG,CAAC,yCAAyC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;gBACpE,MAAM,CAAC,CAAC,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAzCD,4CAyCC;AAED,kBAAe,gBAAgB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { IConnectionManager } from "./interfaces";
2
+ /**
3
+ * Provides a client proxy that wraps a Service definition generated by staticly compiled Protobuf definition.
4
+ */
5
+ export declare class PbServiceProxy<T> {
6
+ protected conn: IConnectionManager;
7
+ protected serviceName: string;
8
+ /**
9
+ * @coonstructor
10
+ * @param conn - Connection manager to handle outbound requests
11
+ * @param serviceName
12
+ */
13
+ constructor(conn: IConnectionManager, serviceName: string);
14
+ /**
15
+ *
16
+ * @param svc Create and activate an instance of a service
17
+ */
18
+ activate(svc: any, async?: any): T;
19
+ /**
20
+ * Provides handler logic for RPC sender. Note: use of arrow function
21
+ * required to maintain instance context.
22
+ *
23
+ * @param method
24
+ * @param requestData
25
+ * @param callback
26
+ */
27
+ protected sendRpcImpl: (method: any, requestData: any, callback: any) => void;
28
+ /**
29
+ * Provides handler logic for RPC sender. Note: use of arrow function
30
+ * required to maintain instance context.
31
+ *
32
+ * @param method
33
+ * @param requestData
34
+ * @param callback
35
+ */
36
+ protected sendRpcImplAsync: (method: any, requestData: any, callback: any) => void;
37
+ }
38
+ export default PbServiceProxy;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Provides a client proxy that wraps a Service definition generated by staticly compiled Protobuf definition.
5
+ */
6
+ class PbServiceProxy {
7
+ /**
8
+ * @coonstructor
9
+ * @param conn - Connection manager to handle outbound requests
10
+ * @param serviceName
11
+ */
12
+ constructor(conn, serviceName) {
13
+ /**
14
+ * Provides handler logic for RPC sender. Note: use of arrow function
15
+ * required to maintain instance context.
16
+ *
17
+ * @param method
18
+ * @param requestData
19
+ * @param callback
20
+ */
21
+ this.sendRpcImpl = (method, requestData, callback) => {
22
+ try {
23
+ this.conn.send(this.serviceName, method.name, requestData, callback);
24
+ }
25
+ catch (e) {
26
+ callback(e, null);
27
+ }
28
+ };
29
+ /**
30
+ * Provides handler logic for RPC sender. Note: use of arrow function
31
+ * required to maintain instance context.
32
+ *
33
+ * @param method
34
+ * @param requestData
35
+ * @param callback
36
+ */
37
+ this.sendRpcImplAsync = (method, requestData, callback) => {
38
+ try {
39
+ this.conn.sendAsync(this.serviceName, method.name, requestData, callback);
40
+ }
41
+ catch (e) {
42
+ callback(e, null);
43
+ }
44
+ };
45
+ this.conn = conn;
46
+ this.serviceName = serviceName;
47
+ }
48
+ /**
49
+ *
50
+ * @param svc Create and activate an instance of a service
51
+ */
52
+ activate(svc, async) {
53
+ if (async === true) {
54
+ return svc.create(this.sendRpcImplAsync);
55
+ }
56
+ else {
57
+ // tslint:disable-line
58
+ return svc.create(this.sendRpcImpl);
59
+ }
60
+ }
61
+ }
62
+ exports.PbServiceProxy = PbServiceProxy;
63
+ exports.default = PbServiceProxy;
64
+ //# sourceMappingURL=PbServiceProxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PbServiceProxy.js","sourceRoot":"","sources":["../src/PbServiceProxy.ts"],"names":[],"mappings":";;AAEA;;GAEG;AACH,MAAa,cAAc;IAIzB;;;;OAIG;IACH,YAAmB,IAAwB,EAAE,WAAmB;QAkBhE;;;;;;;WAOG;QACO,gBAAW,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;YACxD,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;aACtE;YAAC,OAAO,CAAC,EAAE;gBACV,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aACnB;QACH,CAAC,CAAC;QAEF;;;;;;;WAOG;QACO,qBAAgB,GAAG,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;YAC7D,IAAI;gBACF,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;aAC3E;YAAC,OAAO,CAAC,EAAE;gBACV,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;aACnB;QACH,CAAC,CAAC;QA/CA,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,GAAG,EAAE,KAAM;QACzB,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;SAC1C;aAAM;YACL,sBAAsB;YACtB,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SACrC;IACH,CAAC;CAiCF;AA1DD,wCA0DC;AAED,kBAAe,cAAc,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { ILogManager } from "./interfaces";
2
+ /**
3
+ * Segment class to allow for
4
+ * tracking only in production
5
+ */
6
+ export default class Segment {
7
+ private segment;
8
+ private logger;
9
+ constructor(SEGMENT_IO_WRITE_KEY: string | undefined, logger: ILogManager);
10
+ track(params: any): void;
11
+ identify(params: any): void;
12
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Analytics = require('analytics-node');
4
+ /**
5
+ * Segment class to allow for
6
+ * tracking only in production
7
+ */
8
+ class Segment {
9
+ constructor(SEGMENT_IO_WRITE_KEY, logger) {
10
+ this.segment = null;
11
+ this.logger = logger;
12
+ if (SEGMENT_IO_WRITE_KEY) {
13
+ this.logger.info("Segment - Initializing...");
14
+ this.segment = new Analytics(SEGMENT_IO_WRITE_KEY);
15
+ }
16
+ else {
17
+ this.logger.warn("Segment - No write key supplied, skipping initialization...");
18
+ }
19
+ }
20
+ track(params) {
21
+ if (this.segment) {
22
+ this.logger.info(`Segment - Tracking event ${params.event}.`);
23
+ this.segment.track(params);
24
+ }
25
+ }
26
+ identify(params) {
27
+ if (this.segment) {
28
+ this.logger.info(`Segment - Identified user.`);
29
+ this.segment.identify(params);
30
+ }
31
+ }
32
+ }
33
+ exports.default = Segment;
34
+ //# sourceMappingURL=Segment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Segment.js","sourceRoot":"","sources":["../src/Segment.ts"],"names":[],"mappings":";;AAEA,MAAM,SAAS,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAE5C;;;GAGG;AACH,MAAqB,OAAO;IAG1B,YAAY,oBAAwC,EAAE,MAAmB;QACvE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAG,oBAAoB,EAAE;YACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC;YAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAAC;SACpD;aAAM;YACL,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,6DAA6D,CAAC,CAAC;SACjF;IACH,CAAC;IACD,KAAK,CAAC,MAAM;QACV,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC;YAC9D,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;SAC5B;IACH,CAAC;IACD,QAAQ,CAAC,MAAM;QACb,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;YAC/C,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAC/B;IACH,CAAC;CACF;AA1BD,0BA0BC"}
@@ -0,0 +1,22 @@
1
+ import { Span, SpanContext } from 'jaeger-client';
2
+ export default class Tracer {
3
+ serviceName: string;
4
+ logger: any;
5
+ tracer: any;
6
+ constructor(serviceName: string, logger?: any, verbose?: boolean);
7
+ config(verbose: boolean): {
8
+ serviceName: string;
9
+ sampler: {
10
+ type: string;
11
+ param: number;
12
+ };
13
+ reporter: {
14
+ agentHost: string | undefined;
15
+ logSpans: boolean;
16
+ };
17
+ };
18
+ options(): {
19
+ logger: any;
20
+ };
21
+ startSpan(name: string, parentSpan?: (Span | SpanContext | string)): any;
22
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jaeger_client_1 = require("jaeger-client");
4
+ const JAEGER_AGENT_HOST = process.env.JAEGER_AGENT_HOST;
5
+ console.log(`Jaeger Agent Host: ${JAEGER_AGENT_HOST}`);
6
+ class Tracer {
7
+ constructor(serviceName, logger = console, verbose = true) {
8
+ this.serviceName = serviceName;
9
+ this.logger = logger ? logger : console;
10
+ this.tracer = jaeger_client_1.initTracer(this.config(verbose), this.options());
11
+ }
12
+ config(verbose) {
13
+ return {
14
+ serviceName: this.serviceName,
15
+ sampler: {
16
+ type: "const",
17
+ param: 1
18
+ },
19
+ reporter: {
20
+ // agentHost: 'jaeger-agent',
21
+ agentHost: JAEGER_AGENT_HOST,
22
+ // agentHost: 'foobar',
23
+ // collectorEndpoint: "http://localhost:14268/api/traces",
24
+ logSpans: verbose
25
+ }
26
+ };
27
+ }
28
+ options() {
29
+ const options = {
30
+ logger: this.logger,
31
+ };
32
+ return options;
33
+ }
34
+ startSpan(name, parentSpan) {
35
+ let childOf;
36
+ if (typeof parentSpan === 'string') {
37
+ childOf = jaeger_client_1.SpanContext.fromString(parentSpan);
38
+ }
39
+ else if (parentSpan instanceof jaeger_client_1.Span) {
40
+ childOf = parentSpan.context();
41
+ }
42
+ else if (parentSpan instanceof jaeger_client_1.SpanContext) {
43
+ childOf = parentSpan;
44
+ }
45
+ return this.tracer.startSpan(name, { childOf });
46
+ }
47
+ }
48
+ exports.default = Tracer;
49
+ //# sourceMappingURL=Tracer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tracer.js","sourceRoot":"","sources":["../src/Tracer.ts"],"names":[],"mappings":";;AAAA,iDAA8D;AAC9D,MAAM,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAExD,OAAO,CAAC,GAAG,CAAC,sBAAsB,iBAAiB,EAAE,CAAC,CAAC;AAEvD,MAAqB,MAAM;IAMzB,YAAY,WAAmB,EAAE,SAAc,OAAO,EAAE,UAAmB,IAAI;QAC7E,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,0BAAU,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CAAC,OAAgB;QACrB,OAAO;YACL,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,OAAO,EAAE;gBACP,IAAI,EAAE,OAAO;gBACb,KAAK,EAAE,CAAC;aACT;YACD,QAAQ,EAAE;gBACR,6BAA6B;gBAC7B,SAAS,EAAE,iBAAiB;gBAC5B,uBAAuB;gBACvB,0DAA0D;gBAC1D,QAAQ,EAAE,OAAO;aAClB;SACF,CAAC;IACJ,CAAC;IAED,OAAO;QACL,MAAM,OAAO,GAAG;YACd,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;QAEF,OAAO,OAAO,CAAC;IACjB,CAAC;IAED,SAAS,CAAC,IAAY,EAAE,UAA0C;QAChE,IAAI,OAAO,CAAC;QAEZ,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,OAAO,GAAG,2BAAW,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;SAC9C;aAAM,IAAI,UAAU,YAAY,oBAAI,EAAE;YACrC,OAAO,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC;SAChC;aAAM,IAAI,UAAU,YAAY,2BAAW,EAAE;YAC5C,OAAO,GAAG,UAAU,CAAC;SACtB;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;CACF;AAjDD,yBAiDC"}
@@ -0,0 +1 @@
1
+ export declare const tracerExpress: (serviceName: string) => (req: any, res: any, next: any) => Promise<void>;
@@ -0,0 +1,42 @@
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 Tracer_1 = require("./Tracer");
13
+ const url = require("url");
14
+ const traceHTTP = (req, res, tracer) => {
15
+ const pathname = url.parse(req.url).pathname;
16
+ const span = tracer.startSpan(pathname);
17
+ span.logEvent('request_recieved');
18
+ span.setTag('span.kind', 'server');
19
+ span.setTag('http.method', req.method);
20
+ span.setTag('http.url', req.url);
21
+ res.setHeader('uver-trace-id', span.context().toString());
22
+ req.span = span;
23
+ req.tracer = tracer;
24
+ const finish = () => {
25
+ span.logEvent('request_finished');
26
+ span.setTag('http.status_code', res.statusCode);
27
+ if (res.statusCode >= 500) {
28
+ span.setTag('error', true);
29
+ span.setTag('sampling.priority', 1);
30
+ }
31
+ span.finish();
32
+ };
33
+ res.on("finish", finish);
34
+ };
35
+ exports.tracerExpress = (serviceName) => {
36
+ const tracer = new Tracer_1.default(serviceName);
37
+ return (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
38
+ traceHTTP(req, res, tracer);
39
+ next();
40
+ });
41
+ };
42
+ //# sourceMappingURL=TracerExpress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TracerExpress.js","sourceRoot":"","sources":["../src/TracerExpress.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,qCAA8B;AAC9B,2BAA2B;AAE3B,MAAM,SAAS,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAQ,EAAE;IAC3C,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,SAAS,CAAS,QAAQ,CAAC,CAAC;IAChD,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAEjC,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IAE1D,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC;IAChB,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IAEpB,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CAAC;QAClC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QAChD,IAAG,GAAG,CAAC,UAAU,IAAI,GAAG,EAAE;YACxB,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC;SACrC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC,CAAC;IAEF,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEW,QAAA,aAAa,GAAG,CAAC,WAAmB,EAAE,EAAE;IACnD,MAAM,MAAM,GAAG,IAAI,gBAAM,CAAC,WAAW,CAAC,CAAC;IACvC,OAAO,CAAO,GAAG,EAAE,GAAG,EAAE,IAAI,EAAiB,EAAE;QAC7C,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;QAC5B,IAAI,EAAE,CAAC;IACT,CAAC,CAAA,CAAA;AACH,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ {
2
+ "compileOnSave": true,
3
+ "compilerOptions": {
4
+ "inlineSourceMap": true,
5
+ "baseUrl": ".",
6
+ "moduleResolution": "node",
7
+ "target": "es6",
8
+ "esModuleInterop": true,
9
+ "lib": ["es6", "dom", "esnext.asynciterable"],
10
+ "module": "commonjs",
11
+ "outDir": "./.dist/",
12
+ "declaration": true,
13
+ // "sourceMap": true,
14
+ // "strictNullChecks": true,
15
+ "noUnusedLocals": true,
16
+ "paths": {},
17
+ "types": [
18
+ "node",
19
+ "long",
20
+ "mocha"
21
+ ]
22
+ },
23
+ "include": [
24
+ "src/**/*.ts",
25
+ "src/templates",
26
+ ],
27
+ "exclude": [
28
+ "node_modules",
29
+ "test/*",
30
+ "dist/*"
31
+ ]
32
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "extends": "tslint-config-airbnb",
3
+ "rules": {
4
+ "quotemark": [
5
+ true,
6
+ "single"
7
+ ],
8
+ "import-name": false,
9
+ "variable-name": false,
10
+ "max-line-length": false,
11
+ "no-console": false,
12
+ "ban": false
13
+ },
14
+ "jsRules": {
15
+ "max-line-length": false
16
+ }
17
+ }
package/.dist/env.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export declare const DISABLE_PROMETHEUS: string | boolean;
2
+ export declare const LOAD_TEST_ENABLED: boolean;
3
+ export declare const SEGMENT_IO_WRITE_KEY: string | undefined;
4
+ export declare const SENTRY_DSN: string | undefined;
5
+ export declare const NODE_ENV: string;
package/.dist/env.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DISABLE_PROMETHEUS = process.env.DISABLE_PROMETHEUS || false;
4
+ exports.LOAD_TEST_ENABLED = process.env.LOAD_TEST_ENABLED === '1';
5
+ exports.SEGMENT_IO_WRITE_KEY = process.env.SEGMENT_IO_WRITE_KEY;
6
+ exports.SENTRY_DSN = process.env.SENTRY_DSN;
7
+ exports.NODE_ENV = process.env.NODE_ENV || 'development';
8
+ //# sourceMappingURL=env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":";;AAAa,QAAA,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,KAAK,CAAC;AAC7D,QAAA,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG,CAAC;AAC1D,QAAA,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC;AACxD,QAAA,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;AACpC,QAAA,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,aAAa,CAAC"}
@@ -0,0 +1,31 @@
1
+ /// <reference types="node" />
2
+ export interface ISubscriptionRoutes {
3
+ [routeName: string]: IMessageHandler;
4
+ }
5
+ export interface IConnectionManager {
6
+ connect(): any;
7
+ close(): any;
8
+ on(event: string, cb: (...args: any[]) => void): any;
9
+ send(serviceId: string, method: string, req: Buffer, cb: (error: any, reply: any) => void, timeout?: number): any;
10
+ sendAsync(serviceId: string, method: string, req: Buffer, cb: (error: any, reply: any) => void, timeout?: number): any;
11
+ sendBroadcast(messageId: string, req: Buffer, cb: (error: any, reply: any) => void): any;
12
+ subscribe(serviceId: string, queue: string, routes: ISubscriptionRoutes): any;
13
+ subscribeBroadcast(serviceId: string, routes: ISubscriptionRoutes): any;
14
+ }
15
+ export interface ILogManager {
16
+ info(msg: string, ...params: string[]): void;
17
+ warn(msg: string, ...params: string[]): void;
18
+ error(msg: string, ...params: string[]): void;
19
+ }
20
+ export interface ILogManagerOpts {
21
+ serviceName: string;
22
+ }
23
+ export interface IMessageHandler {
24
+ process(req: Buffer): Promise<Buffer>;
25
+ }
26
+ export interface IServiceOpts {
27
+ serviceName: string;
28
+ connectionMgr: IConnectionManager;
29
+ logManager: ILogManager;
30
+ storageManager?: any;
31
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ declare const joiToErrors: (joiErrors: any, errorClass: any) => any;
2
+ export declare const joiToErrorMessages: (joiErrors: any, errorClass: any) => any;
3
+ export default joiToErrors;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Converts Joi error objects to a { key, message } type object (pb.Error, Object, etc.)
5
+ */
6
+ const joiToErrors = (joiErrors, errorClass) => {
7
+ const errors = joiErrors.details.map(detail => {
8
+ const key = detail.path[0];
9
+ const type = detail.type;
10
+ // Note, these messages eventually need to be symbolic, and also localized / translated.
11
+ // Right now, we're mainly using the English strings returned by the Joi validators.
12
+ const defaultMessage = detail.message;
13
+ const message = publicErrorMessage(key, type, defaultMessage);
14
+ return new errorClass({ key, message });
15
+ }, {});
16
+ return errors;
17
+ };
18
+ /*
19
+ * Override default Joi messages, which aren't always safe to show to our users.
20
+ */
21
+ const publicErrorMessage = (key, type, defaultMessage) => {
22
+ let message = defaultMessage;
23
+ switch (type) {
24
+ case "string.regex.base": {
25
+ // regex errors echo back the value, which is dangerous for passwords
26
+ message = `"${key}" does not meet the requirements`;
27
+ }
28
+ }
29
+ return message;
30
+ };
31
+ /*
32
+ * Function used for more detailed key info and custom error messages
33
+ */
34
+ exports.joiToErrorMessages = (joiErrors, errorClass) => {
35
+ const errors = joiErrors.details.map(detail => {
36
+ const key = detail.context.label;
37
+ const message = detail.message;
38
+ return new errorClass({ key, message });
39
+ }, {});
40
+ return errors;
41
+ };
42
+ exports.default = joiToErrors;
43
+ //# sourceMappingURL=joiToErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joiToErrors.js","sourceRoot":"","sources":["../src/joiToErrors.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,MAAM,WAAW,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE;IAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAEzB,wFAAwF;QACxF,oFAAoF;QACpF,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC;QACtC,MAAM,OAAO,GAAG,kBAAkB,CAAC,GAAG,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC;QAE9D,OAAO,IAAI,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE,EAAE;IACvD,IAAI,OAAO,GAAG,cAAc,CAAC;IAE7B,QAAQ,IAAI,EAAE;QACZ,KAAK,mBAAmB,CAAC,CAAC;YACxB,qEAAqE;YACrE,OAAO,GAAG,IAAI,GAAG,kCAAkC,CAAC;SACrD;KACF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC;AAEF;;GAEG;AACU,QAAA,kBAAkB,GAAG,CAAC,SAAS,EAAE,UAAU,EAAE,EAAE;IAC1D,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;QACjC,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,OAAO,IAAI,UAAU,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,kBAAe,WAAW,CAAC"}
File without changes
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../src/schemas.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@sellout/service",
3
+ "version": "0.0.1",
4
+ "description": "Sellout.io base service",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "tsc --project . && cp -r src/build .dist",
8
+ "start": "nodemon --watch src -e json,js,ts -x \"npm run build\""
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "www.github.com/sellout-tickets/sellout/common/service"
13
+ },
14
+ "author": "samheutmaker@gmail.com",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@sellout/models": "^0.0.1",
18
+ "@sellout/utils": "^0.0.1",
19
+ "@sentry/node": "^5.14.2",
20
+ "analytics-node": "^3.4.0-beta.1",
21
+ "express": "^4.17.1",
22
+ "jaeger-client": "^3.17.2",
23
+ "nats": "^1.3.0",
24
+ "prom-client": "^12.0.0",
25
+ "url": "^0.11.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/long": "^4.0.1",
29
+ "@types/node": "^13.9.1",
30
+ "nodemon": "^2.0.2",
31
+ "typescript": "^3.8.3"
32
+ },
33
+ "gitHead": "5f577126fcc59699bc5447b62f0ee56aa4b9759b"
34
+ }