@routr/location 2.0.5-alpha.15 → 2.0.5-alpha.17

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.
package/dist/client.d.ts CHANGED
@@ -1,14 +1,47 @@
1
1
  import { AddRouteRequest, FindRoutesRequest, ILocationService, RemoveRoutesRequest } from "./types";
2
2
  import { Route } from "@routr/common";
3
+ /**
4
+ * Location client
5
+ */
3
6
  export default class Location implements ILocationService {
4
7
  location: any;
5
8
  config: {
6
9
  addr: string;
7
10
  };
11
+ /**
12
+ * Create a new Location client.
13
+ *
14
+ * @param {object} config - Location client config
15
+ * @param {string} config.addr - Location service address
16
+ */
8
17
  constructor(config: {
9
18
  addr: string;
10
19
  });
20
+ /**
21
+ * Add a route to the location service.
22
+ *
23
+ * @param {AddRouteRequest} request - Add route request
24
+ * @param {string} request.aor - AOR of the route
25
+ * @param {Route} request.route - Route to add
26
+ * @return {Promise<void>}
27
+ */
11
28
  addRoute(request: AddRouteRequest): Promise<void>;
29
+ /**
30
+ * Add a route to the location service.
31
+ *
32
+ * @param {FindRoutesResponse} request - Request to find routes
33
+ * @param {string} request.aor - AOR of the route
34
+ * @param {Map<string, string>} request.labels - Optional Route labels
35
+ * @param {string} request.sessionAffinityRef - Optiona session affinity ref
36
+ * @return {Promise<void>}
37
+ */
12
38
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
39
+ /**
40
+ * Add a route to the location service.
41
+ *
42
+ * @param {RemoveRoutesRequest} request - Remove routes request
43
+ * @param {string} request.aor - AOR of the route
44
+ * @return {Promise<void>}
45
+ */
13
46
  removeRoutes(request: RemoveRoutesRequest): Promise<void>;
14
47
  }
package/dist/client.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,32 +33,68 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  const common_1 = require("@routr/common");
13
- const grpc = require("@grpc/grpc-js");
14
- function container(self, request, name) {
36
+ const grpc = __importStar(require("@grpc/grpc-js"));
37
+ const container = (self, request, name) => {
15
38
  return new Promise((resolve, reject) => {
16
39
  self.location[name](request, (err, response) => {
17
40
  if ((err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE) {
18
- return reject(new common_1.ServiceUnavailableError(this.config.addr));
41
+ return reject(new common_1.ServiceUnavailableError(self.config.addr));
19
42
  }
20
43
  resolve(response);
21
44
  });
22
45
  });
23
- }
46
+ };
47
+ /**
48
+ * Location client
49
+ */
24
50
  class Location {
51
+ /**
52
+ * Create a new Location client.
53
+ *
54
+ * @param {object} config - Location client config
55
+ * @param {string} config.addr - Location service address
56
+ */
25
57
  constructor(config) {
26
58
  this.config = config;
27
- this.location = new common_1.LOCATION_OBJECT_PROTO
28
- .Location(config.addr, grpc.credentials.createInsecure());
59
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
+ this.location = new common_1.LOCATION_OBJECT_PROTO.Location(config.addr, grpc.credentials.createInsecure());
29
61
  }
62
+ /**
63
+ * Add a route to the location service.
64
+ *
65
+ * @param {AddRouteRequest} request - Add route request
66
+ * @param {string} request.aor - AOR of the route
67
+ * @param {Route} request.route - Route to add
68
+ * @return {Promise<void>}
69
+ */
30
70
  addRoute(request) {
31
71
  return container(this, request, this.addRoute.name);
32
72
  }
73
+ /**
74
+ * Add a route to the location service.
75
+ *
76
+ * @param {FindRoutesResponse} request - Request to find routes
77
+ * @param {string} request.aor - AOR of the route
78
+ * @param {Map<string, string>} request.labels - Optional Route labels
79
+ * @param {string} request.sessionAffinityRef - Optiona session affinity ref
80
+ * @return {Promise<void>}
81
+ */
33
82
  findRoutes(request) {
34
83
  var _a;
35
84
  return __awaiter(this, void 0, void 0, function* () {
36
- return ((_a = (yield container(this, request, this.findRoutes.name))) === null || _a === void 0 ? void 0 : _a.routes) || [];
85
+ return (
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ ((_a = ((yield container(this, request, this.findRoutes.name)))) === null || _a === void 0 ? void 0 : _a.routes) ||
88
+ []);
37
89
  });
38
90
  }
91
+ /**
92
+ * Add a route to the location service.
93
+ *
94
+ * @param {RemoveRoutesRequest} request - Remove routes request
95
+ * @param {string} request.aor - AOR of the route
96
+ * @return {Promise<void>}
97
+ */
39
98
  removeRoutes(request) {
40
99
  return container(this, request, this.removeRoutes.name);
41
100
  }
@@ -1,4 +1,4 @@
1
1
  import { LocationConfig } from "../types";
2
- import * as E from 'fp-ts/Either';
2
+ import * as E from "fp-ts/Either";
3
3
  import { InvalidConfiguration } from "../errors";
4
4
  export declare const getConfig: (path: string) => E.Either<InvalidConfiguration, LocationConfig>;
@@ -53,9 +53,9 @@ const E = __importStar(require("fp-ts/Either"));
53
53
  const errors_1 = require("../errors");
54
54
  const ajv = new ajv_1.default();
55
55
  const validate = ajv.compile(schema_1.schema);
56
- const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LB_ALGORITHM.ROUND_ROBIN && b.sessionAffinity);
57
- const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LB_ALGORITHM.ROUND_ROBIN
58
- && b.balancingAlgorithm !== types_1.LB_ALGORITHM.LEAST_SESSIONS);
56
+ const hasBadCombiniation = (backends) => backends.some((b) => b.balancingAlgorithm === types_1.LB_ALGORITHM.ROUND_ROBIN && b.withSessionAffinity);
57
+ const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LB_ALGORITHM.ROUND_ROBIN &&
58
+ b.balancingAlgorithm !== types_1.LB_ALGORITHM.LEAST_SESSIONS);
59
59
  const getConfig = (path) => {
60
60
  var _a, _b, _c;
61
61
  const c = JSON.parse(fs_1.default.readFileSync(path, "utf8"));
@@ -67,7 +67,8 @@ const getConfig = (path) => {
67
67
  config.backends.map((b) => {
68
68
  // Setting round-robin by default
69
69
  b.balancingAlgorithm = b.balancingAlgorithm
70
- ? b.balancingAlgorithm : types_1.LB_ALGORITHM.ROUND_ROBIN;
70
+ ? b.balancingAlgorithm
71
+ : types_1.LB_ALGORITHM.ROUND_ROBIN;
71
72
  return b;
72
73
  });
73
74
  if (hasBadCombiniation(config.backends)) {
@@ -47,18 +47,9 @@ export declare const schema: {
47
47
  balancingAlgorithm: {
48
48
  enum: string[];
49
49
  };
50
- sessionAffinity: {
50
+ withSessionAffinity: {
51
51
  description: string;
52
52
  type: string;
53
- properties: {
54
- enabled: {
55
- type: string;
56
- };
57
- ref: {
58
- type: string;
59
- };
60
- };
61
- required: string[];
62
53
  };
63
54
  };
64
55
  required: string[];
@@ -20,72 +20,63 @@ exports.schema = void 0;
20
20
  * limitations under the License.
21
21
  */
22
22
  exports.schema = {
23
- "$id": "https://json-schema.org/draft/2020-12/schema",
24
- "title": "Location Service configuration",
25
- "description": "Configuration for an instance of the Location Service",
26
- "type": "object",
27
- "properties": {
28
- "kind": {
29
- "enum": ["Location", "location"]
23
+ $id: "https://json-schema.org/draft/2020-12/schema",
24
+ title: "Location Service configuration",
25
+ description: "Configuration for an instance of the Location Service",
26
+ type: "object",
27
+ properties: {
28
+ kind: {
29
+ enum: ["Location", "location"]
30
30
  },
31
- "apiVersion": {
32
- "enum": ["v2draft1"]
31
+ apiVersion: {
32
+ enum: ["v2draft1"]
33
33
  },
34
- "metadata": {
35
- "description": "Resource metadata",
36
- "type": "object"
34
+ metadata: {
35
+ description: "Resource metadata",
36
+ type: "object"
37
37
  },
38
- "spec": {
39
- "description": "Operations spec for Location",
40
- "type": "object",
41
- "properties": {
42
- "bindAddr": {
43
- "description": "Ipv4 interface to accept request on",
44
- "type": "string"
38
+ spec: {
39
+ description: "Operations spec for Location",
40
+ type: "object",
41
+ properties: {
42
+ bindAddr: {
43
+ description: "Ipv4 interface to accept request on",
44
+ type: "string"
45
45
  },
46
- "cache": {
47
- "type": "object",
48
- "properties": {
49
- "provider": {
50
- "enum": ["memory", "redis"]
51
- },
52
- "parameters": {
53
- "type": "string"
46
+ cache: {
47
+ type: "object",
48
+ properties: {
49
+ provider: {
50
+ enum: ["memory", "redis"]
54
51
  },
52
+ parameters: {
53
+ type: "string"
54
+ }
55
55
  },
56
- "required": ["provider"]
56
+ required: ["provider"]
57
57
  },
58
- "backends": {
59
- "description": "Optional SIP backends",
60
- "type": "array",
61
- "items": {
62
- "type": "object"
58
+ backends: {
59
+ description: "Optional SIP backends",
60
+ type: "array",
61
+ items: {
62
+ type: "object"
63
63
  },
64
- "properties": {
65
- "ref": {
66
- "type": "string"
67
- },
68
- "balancingAlgorithm": {
69
- "enum": ["round-robin", "least-sessions"]
64
+ properties: {
65
+ ref: {
66
+ type: "string"
70
67
  },
71
- "sessionAffinity": {
72
- "description": "Optional session affinity",
73
- "type": "object",
74
- "properties": {
75
- "enabled": {
76
- "type": "boolean"
77
- },
78
- "ref": {
79
- "type": "string"
80
- }
81
- },
82
- "required": ["ref"]
68
+ balancingAlgorithm: {
69
+ enum: ["round-robin", "least-sessions"]
83
70
  },
71
+ withSessionAffinity: {
72
+ description: "Optional session affinity",
73
+ type: "boolean"
74
+ }
84
75
  },
85
- "required": ["ref"]
86
- },
76
+ required: ["ref"]
77
+ }
87
78
  }
88
79
  }
89
80
  },
90
- "required": ["kind", "metadata", "spec", "apiVersion"]
81
+ required: ["kind", "spec", "apiVersion"]
91
82
  };
package/dist/errors.d.ts CHANGED
@@ -1,23 +1,59 @@
1
- import grpc = require("@grpc/grpc-js");
1
+ import * as grpc from "@grpc/grpc-js";
2
2
  export declare type LocationError = UnsupportedSchema | NotRoutesFoundForAOR;
3
3
  export declare type InvalidConfiguration = BadAlgorithmAndAffinityCombination | InvalidSchemaConfiguration;
4
+ /**
5
+ * Error thrown when the location service returns an unsupported schema.
6
+ */
4
7
  export declare class UnsupportedSchema extends Error {
5
8
  code: grpc.status;
9
+ /**
10
+ * Create a new UnsupportedSchema error.
11
+ *
12
+ * @param {string} aor - The AOR that was requested
13
+ */
6
14
  constructor(aor: string);
7
15
  }
16
+ /**
17
+ * Error thrown when the location service returns no routes for the AOR.
18
+ */
8
19
  export declare class NotRoutesFoundForAOR extends Error {
9
20
  code: number;
21
+ /**
22
+ * Create a new NotRoutesFoundForAOR error.
23
+ *
24
+ * @param {string} aor - The AOR that was requested
25
+ */
10
26
  constructor(aor: string);
11
27
  }
28
+ /**
29
+ * Error thrown when the location finds a bad configuration.
30
+ */
12
31
  export declare class InvalidSchemaConfiguration extends Error {
13
32
  code: grpc.status;
33
+ /**
34
+ * Create a new InvalidSchemaConfiguration error.
35
+ *
36
+ * @param {string} msg - Message from the validation error
37
+ */
14
38
  constructor(msg: string);
15
39
  }
40
+ /**
41
+ * Error thrown when the location finds incompatible algorithm and session affinity.
42
+ */
16
43
  export declare class BadAlgorithmAndAffinityCombination extends Error {
17
44
  code: grpc.status;
45
+ /**
46
+ * Create a new BadAlgorithmAndAffinityCombination error.
47
+ */
18
48
  constructor();
19
49
  }
50
+ /**
51
+ * Error thrown when the location finds an invalid balancing algorithm.
52
+ */
20
53
  export declare class InvalidLoadBalancerAlgorithm extends Error {
21
54
  code: grpc.status;
55
+ /**
56
+ * Create a new InvalidLoadBalancerAlgorithm error.
57
+ */
22
58
  constructor();
23
59
  }
package/dist/errors.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.InvalidLoadBalancerAlgorithm = exports.BadAlgorithmAndAffinityCombination = exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
4
27
  /*
@@ -19,8 +42,16 @@ exports.InvalidLoadBalancerAlgorithm = exports.BadAlgorithmAndAffinityCombinatio
19
42
  * See the License for the specific language governing permissions and
20
43
  * limitations under the License.
21
44
  */
22
- const grpc = require("@grpc/grpc-js");
45
+ const grpc = __importStar(require("@grpc/grpc-js"));
46
+ /**
47
+ * Error thrown when the location service returns an unsupported schema.
48
+ */
23
49
  class UnsupportedSchema extends Error {
50
+ /**
51
+ * Create a new UnsupportedSchema error.
52
+ *
53
+ * @param {string} aor - The AOR that was requested
54
+ */
24
55
  constructor(aor) {
25
56
  super(`aor ${aor} has an invalid schema, only "sip:" or "backend:" are allowed`);
26
57
  this.code = grpc.status.INVALID_ARGUMENT;
@@ -29,15 +60,31 @@ class UnsupportedSchema extends Error {
29
60
  }
30
61
  }
31
62
  exports.UnsupportedSchema = UnsupportedSchema;
63
+ /**
64
+ * Error thrown when the location service returns no routes for the AOR.
65
+ */
32
66
  class NotRoutesFoundForAOR extends Error {
67
+ /**
68
+ * Create a new NotRoutesFoundForAOR error.
69
+ *
70
+ * @param {string} aor - The AOR that was requested
71
+ */
33
72
  constructor(aor) {
34
- super(`no routes found for aor ${aor}`);
73
+ super(`no routes found for aor: ${aor}`);
35
74
  this.code = grpc.status.NOT_FOUND;
36
75
  Object.setPrototypeOf(this, NotRoutesFoundForAOR.prototype);
37
76
  }
38
77
  }
39
78
  exports.NotRoutesFoundForAOR = NotRoutesFoundForAOR;
79
+ /**
80
+ * Error thrown when the location finds a bad configuration.
81
+ */
40
82
  class InvalidSchemaConfiguration extends Error {
83
+ /**
84
+ * Create a new InvalidSchemaConfiguration error.
85
+ *
86
+ * @param {string} msg - Message from the validation error
87
+ */
41
88
  constructor(msg) {
42
89
  super(msg);
43
90
  this.code = grpc.status.INVALID_ARGUMENT;
@@ -45,14 +92,26 @@ class InvalidSchemaConfiguration extends Error {
45
92
  }
46
93
  }
47
94
  exports.InvalidSchemaConfiguration = InvalidSchemaConfiguration;
95
+ /**
96
+ * Error thrown when the location finds incompatible algorithm and session affinity.
97
+ */
48
98
  class BadAlgorithmAndAffinityCombination extends Error {
99
+ /**
100
+ * Create a new BadAlgorithmAndAffinityCombination error.
101
+ */
49
102
  constructor() {
50
103
  super("session affinity can not be combined with round-robin load balancing");
51
104
  Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
52
105
  }
53
106
  }
54
107
  exports.BadAlgorithmAndAffinityCombination = BadAlgorithmAndAffinityCombination;
108
+ /**
109
+ * Error thrown when the location finds an invalid balancing algorithm.
110
+ */
55
111
  class InvalidLoadBalancerAlgorithm extends Error {
112
+ /**
113
+ * Create a new InvalidLoadBalancerAlgorithm error.
114
+ */
56
115
  constructor() {
57
116
  super("found invalid load balancing algorithm. must be round-robin or least-sessions");
58
117
  Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
package/dist/helper.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- import { Route } from "@routr/common";
2
- import { MessageRequest } from "@routr/common";
1
+ import { MessageRequest, Route } from "@routr/common";
3
2
  export declare const createRoute: (request: MessageRequest) => Route;
package/dist/helper.js CHANGED
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createRoute = void 0;
4
4
  const processor_1 = require("@routr/processor");
5
- const processor_2 = require("@routr/processor");
6
5
  // TODO: Before finalizing this, consider using the old approach of saving the rport
7
6
  // and received values (like here:
8
7
  // https://github.com/fonoster/routr/blob/59bc98af86078088aede7e658c0d82a19fa18fa4/mod/registrar/utils.js#L87)
@@ -11,15 +10,18 @@ const processor_2 = require("@routr/processor");
11
10
  // and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
12
11
  const createRoute = (request) => {
13
12
  const uri = request.message.contact.address.uri;
13
+ const sessionCount = processor_1.Extensions.getHeaderValue(request, "x-session-count")
14
+ ? parseInt(processor_1.Extensions.getHeaderValue(request, "x-session-count"))
15
+ : -1;
14
16
  return {
15
17
  edgePortRef: request.edgePortRef,
16
18
  user: uri.user,
17
19
  host: uri.host,
18
20
  port: uri.port,
19
- transport: uri.transport,
21
+ transport: uri.transportParam,
20
22
  registeredOn: Date.now(),
21
- sessionCount: processor_1.Extensions.getHeaderValue(request, "x-session-count") || -1,
22
- expires: processor_2.Target.getTargetExpires(request),
23
+ sessionCount,
24
+ expires: processor_1.Target.getTargetExpires(request),
23
25
  listeningPoint: request.listeningPoint
24
26
  };
25
27
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  import LocationClient from "./client";
2
+ import { ILocationService } from "./types";
2
3
  export * as Helper from "./helper";
3
4
  export * as Utils from "./utils";
4
- export { LocationClient };
5
+ export * from "./errors";
6
+ export { LocationClient, ILocationService };
package/dist/index.js CHANGED
@@ -22,6 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
+ };
25
28
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
30
  };
@@ -49,3 +52,4 @@ const client_1 = __importDefault(require("./client"));
49
52
  exports.LocationClient = client_1.default;
50
53
  exports.Helper = __importStar(require("./helper"));
51
54
  exports.Utils = __importStar(require("./utils"));
55
+ __exportStar(require("./errors"), exports);
@@ -1,13 +1,25 @@
1
1
  import { AddRouteRequest, Backend, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
2
2
  import { Route } from "@routr/common";
3
+ /**
4
+ * A locator store that uses the location service to find routes for AORs.
5
+ */
3
6
  export default class Location implements ILocationService {
4
7
  private store;
5
8
  private backends;
6
9
  private rrCount;
7
10
  private affinityStore;
11
+ /**
12
+ * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
13
+ *
14
+ * @param {ILocatorStore} store - The store to use for the location service
15
+ * @param {Map<string, Backend>} backends - The backends to use for the location service
16
+ */
8
17
  constructor(store: ILocatorStore, backends?: Map<string, Backend>);
18
+ /** @inheritdoc */
9
19
  addRoute(request: AddRouteRequest): Promise<void>;
20
+ /** @inheritdoc */
10
21
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
22
+ /** @inheritdoc */
11
23
  removeRoutes(request: RemoveRoutesRequest): Promise<void>;
12
24
  private next;
13
25
  private nextWithAffinity;
package/dist/location.js CHANGED
@@ -30,8 +30,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
30
30
  const errors_1 = require("./errors");
31
31
  const types_1 = require("./types");
32
32
  const utils_1 = require("./utils");
33
+ var AOR_SCHEME;
34
+ (function (AOR_SCHEME) {
35
+ AOR_SCHEME["SIP"] = "sip:";
36
+ AOR_SCHEME["BACKEND"] = "backend:";
37
+ })(AOR_SCHEME || (AOR_SCHEME = {}));
38
+ /**
39
+ * A locator store that uses the location service to find routes for AORs.
40
+ */
33
41
  class Location {
34
- // Should fail if any backend has sessionAffinity and round-robin
42
+ /**
43
+ * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
44
+ *
45
+ * @param {ILocatorStore} store - The store to use for the location service
46
+ * @param {Map<string, Backend>} backends - The backends to use for the location service
47
+ */
35
48
  constructor(store, backends = new Map()) {
36
49
  this.store = store;
37
50
  this.backends = backends;
@@ -39,55 +52,59 @@ class Location {
39
52
  this.affinityStore = new Map();
40
53
  this.backends.forEach((value, key) => this.rrCount.set(key, 0));
41
54
  }
55
+ /** @inheritdoc */
42
56
  addRoute(request) {
43
- if (!request.aor.startsWith('sip:') &&
44
- !request.aor.startsWith('backend:')) {
57
+ if (!request.aor.startsWith(AOR_SCHEME.SIP) &&
58
+ !request.aor.startsWith(AOR_SCHEME.BACKEND)) {
45
59
  throw new errors_1.UnsupportedSchema(request.aor);
46
60
  }
47
61
  return this.store.put(request.aor, request.route);
48
62
  }
63
+ /** @inheritdoc */
49
64
  findRoutes(request) {
50
65
  return __awaiter(this, void 0, void 0, function* () {
51
66
  const routes = request.labels
52
- ? (yield this.store.get(request.aor))
53
- .filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
67
+ ? (yield this.store.get(request.aor)).filter((0, utils_1.filterOnlyMatchingLabels)(request.labels))
54
68
  : (yield this.store.get(request.aor)) || [];
55
- if (request.aor.startsWith('sip:')) {
69
+ if (request.aor.startsWith(AOR_SCHEME.SIP)) {
56
70
  return routes;
57
71
  }
58
- else if (request.aor.startsWith('backend:')) {
72
+ else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
59
73
  const backend = this.backends.get(request.aor);
60
74
  if (!backend) {
61
75
  throw new errors_1.NotRoutesFoundForAOR(request.aor);
62
76
  }
63
77
  // If it has not affinity sesssion then get next
64
- return !(0, utils_1.hasAffinitySession)(backend)
65
- ? [this.next(routes, backend)]
66
- : [this.nextWithAffinity(yield routes, backend.sessionAffinity.ref)];
78
+ return backend.withSessionAffinity
79
+ ? [this.nextWithAffinity(routes, request.sessionAffinityRef)]
80
+ : [this.next(routes, backend)];
67
81
  }
68
82
  throw new errors_1.UnsupportedSchema(request.aor);
69
83
  });
70
84
  }
85
+ /** @inheritdoc */
71
86
  removeRoutes(request) {
72
87
  return this.store.delete(request.aor);
73
88
  }
89
+ // eslint-disable-next-line require-jsdoc
74
90
  next(routes, backend) {
75
91
  if (backend.balancingAlgorithm === types_1.LB_ALGORITHM.LEAST_SESSIONS) {
76
92
  return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
77
93
  }
78
94
  // Continues using round-robin
79
- const nextPosition = this.rrCount.get(`backend:${backend.ref}`);
95
+ const nextPosition = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`);
80
96
  const result = routes[nextPosition];
81
- if (nextPosition >= (routes.length - 1)) {
97
+ if (nextPosition >= routes.length - 1) {
82
98
  // Restarting round-robin counter
83
- this.rrCount.set(`backend:${backend.ref}`, 0);
99
+ this.rrCount.set(`${AOR_SCHEME.BACKEND}${backend.ref}`, 0);
84
100
  }
85
101
  else {
86
- this.rrCount.set(`backend:${backend.ref}`, nextPosition + 1);
102
+ this.rrCount.set(`${AOR_SCHEME.BACKEND}${backend.ref}`, nextPosition + 1);
87
103
  }
88
104
  return result;
89
105
  }
90
106
  // Backend with session affinity does not support round-robin
107
+ // eslint-disable-next-line require-jsdoc
91
108
  nextWithAffinity(routes, sessionAffinityRef) {
92
109
  let route = this.affinityStore.get(sessionAffinityRef);
93
110
  if (route) {
@@ -1,13 +1,26 @@
1
1
  import { Route } from "@routr/common";
2
2
  import { ILocatorStore } from "./types";
3
+ /**
4
+ * In-memory store for the locator service.
5
+ */
3
6
  export default class MemoryStore implements ILocatorStore {
4
7
  private collections;
5
8
  private cleanupCount;
6
9
  private maxCyclesBeforeCleanup;
10
+ /**
11
+ * Creates a new in-memory store.
12
+ *
13
+ * @param {number} maxCyclesBeforeCleanup - Maximum number of cycles before cleanup
14
+ */
7
15
  constructor(maxCyclesBeforeCleanup?: number);
16
+ /** @inheritdoc */
8
17
  put(key: string, route: Route): Promise<void>;
18
+ /** @inheritdoc */
9
19
  get(key: string): Promise<Route[]>;
20
+ /** @inheritdoc */
10
21
  delete(key: string): Promise<void>;
22
+ /** @inheritdoc */
11
23
  size(): number;
24
+ /** @inheritdoc */
12
25
  cleanup(): void;
13
26
  }
@@ -2,17 +2,26 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const utils_1 = require("./utils");
4
4
  const MAX_CYCLES_BEFORE_CLEANUP = 10000;
5
+ /**
6
+ * In-memory store for the locator service.
7
+ */
5
8
  class MemoryStore {
9
+ /**
10
+ * Creates a new in-memory store.
11
+ *
12
+ * @param {number} maxCyclesBeforeCleanup - Maximum number of cycles before cleanup
13
+ */
6
14
  constructor(maxCyclesBeforeCleanup = MAX_CYCLES_BEFORE_CLEANUP) {
7
15
  this.collections = new Map();
8
16
  this.maxCyclesBeforeCleanup = maxCyclesBeforeCleanup;
9
17
  }
18
+ /** @inheritdoc */
10
19
  put(key, route) {
11
- const routes = [...this.collections.get(key) || []];
20
+ const routes = [...(this.collections.get(key) || [])];
12
21
  // Avoids duplicate or expired routes
13
22
  const filteredRoutes = routes
14
23
  .filter(utils_1.expiredFilter)
15
- .filter(r => (0, utils_1.duplicateFilter)(r, route));
24
+ .filter((r) => (0, utils_1.duplicateFilter)(r, route));
16
25
  if (filteredRoutes.length > 0) {
17
26
  this.collections.set(key, [route, ...filteredRoutes]);
18
27
  }
@@ -21,6 +30,7 @@ class MemoryStore {
21
30
  }
22
31
  return;
23
32
  }
33
+ /** @inheritdoc */
24
34
  get(key) {
25
35
  // Cleanup every so often to avoid memory build up
26
36
  this.cleanupCount++;
@@ -30,13 +40,16 @@ class MemoryStore {
30
40
  }
31
41
  return Promise.resolve((this.collections.get(key) || []).filter(utils_1.expiredFilter));
32
42
  }
43
+ /** @inheritdoc */
33
44
  delete(key) {
34
45
  this.collections.delete(key);
35
46
  return;
36
47
  }
48
+ /** @inheritdoc */
37
49
  size() {
38
50
  return this.collections.size;
39
51
  }
52
+ /** @inheritdoc */
40
53
  cleanup() {
41
54
  // Remove any expired route from collection
42
55
  this.collections.forEach((routes, key) => {
@@ -1,9 +1,21 @@
1
1
  import { Route } from "@routr/common";
2
- import { ILocatorStore, RedisStoreConfig } from "./types";
2
+ import { ILocatorStore } from "./types";
3
+ import { Redis } from "@routr/common";
4
+ /**
5
+ * Redis store for the locator service.
6
+ */
3
7
  export default class RedisStore implements ILocatorStore {
4
8
  client: any;
5
- constructor(config?: RedisStoreConfig);
9
+ /**
10
+ * Creates a new redis store.
11
+ *
12
+ * @param {Redis.RedisStoreConfig} config - Optional store config
13
+ */
14
+ constructor(config?: Redis.RedisStoreConfig);
15
+ /** @inheritdoc */
6
16
  put(key: string, route: Route): Promise<void>;
17
+ /** @inheritdoc */
7
18
  get(key: string): Promise<Route[]>;
19
+ /** @inheritdoc */
8
20
  delete(key: string): Promise<void>;
9
21
  }
@@ -15,19 +15,28 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
15
15
  function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
16
16
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
17
  };
18
- var __importDefault = (this && this.__importDefault) || function (mod) {
19
- return (mod && mod.__esModule) ? mod : { "default": mod };
20
- };
21
18
  Object.defineProperty(exports, "__esModule", { value: true });
22
19
  const redis_1 = require("redis");
23
- const utils_1 = require("./utils");
24
- const logger_1 = __importDefault(require("@fonoster/logger"));
20
+ const common_1 = require("@routr/common");
21
+ const logger_1 = require("@fonoster/logger");
22
+ const logger = (0, logger_1.getLogger)({ service: "location", filePath: __filename });
23
+ /**
24
+ * Redis store for the locator service.
25
+ */
25
26
  class RedisStore {
27
+ /**
28
+ * Creates a new redis store.
29
+ *
30
+ * @param {Redis.RedisStoreConfig} config - Optional store config
31
+ */
26
32
  constructor(config) {
27
- this.client = config ? (0, redis_1.createClient)({ url: (0, utils_1.getUrlString)(config) }) : (0, redis_1.createClient)();
33
+ this.client = config
34
+ ? (0, redis_1.createClient)({ url: common_1.Redis.getRedisUrlFromConfig(config) })
35
+ : (0, redis_1.createClient)();
28
36
  this.client.connect();
29
- this.client.on('error', (err) => logger_1.default.error('redis client error: ', err));
37
+ this.client.on("error", (err) => logger.error("redis client error: ", err));
30
38
  }
39
+ /** @inheritdoc */
31
40
  put(key, route) {
32
41
  return __awaiter(this, void 0, void 0, function* () {
33
42
  // Formatted the key to ensure it is unique
@@ -37,11 +46,13 @@ class RedisStore {
37
46
  return;
38
47
  });
39
48
  }
49
+ /** @inheritdoc */
40
50
  get(key) {
41
51
  var e_1, _a;
42
52
  return __awaiter(this, void 0, void 0, function* () {
43
53
  const routes = [];
44
54
  try {
55
+ // eslint-disable-next-line no-loops/no-loops
45
56
  for (var _b = __asyncValues(yield this.client.scanIterator({
46
57
  CURSOR: 0,
47
58
  MATCH: `${key}:*`
@@ -60,10 +71,12 @@ class RedisStore {
60
71
  return routes;
61
72
  });
62
73
  }
74
+ /** @inheritdoc */
63
75
  delete(key) {
64
76
  var e_2, _a;
65
77
  return __awaiter(this, void 0, void 0, function* () {
66
78
  try {
79
+ // eslint-disable-next-line no-loops/no-loops
67
80
  for (var _b = __asyncValues(yield this.client.scanIterator({
68
81
  CURSOR: 0,
69
82
  MATCH: `${key}:*`
package/dist/runner.js CHANGED
@@ -22,14 +22,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  * See the License for the specific language governing permissions and
23
23
  * limitations under the License.
24
24
  */
25
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
25
26
  require("./tracer").init("dispatcher");
26
- const logger_1 = __importDefault(require("@fonoster/logger"));
27
27
  const service_1 = __importDefault(require("./service"));
28
28
  const get_config_1 = require("./config/get_config");
29
+ const common_1 = require("@routr/common");
30
+ const logger_1 = require("@fonoster/logger");
31
+ const logger = (0, logger_1.getLogger)({ service: "location", filePath: __filename });
32
+ common_1.Assertions.assertEnvsAreSet(["CONFIG_PATH"]);
29
33
  const result = (0, get_config_1.getConfig)(process.env.CONFIG_PATH);
30
- if (result._tag === 'Right') {
34
+ if (result._tag === "Right") {
31
35
  (0, service_1.default)(result.right);
32
36
  }
33
37
  else {
34
- logger_1.default.error(result.left);
38
+ logger.error(result.left);
35
39
  }
package/dist/service.d.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  import { LocationConfig } from "./types";
2
+ /**
3
+ * Creates a new locator service.
4
+ *
5
+ * @param {LocationConfig} config - Service configuration
6
+ */
2
7
  export default function LocationService(config: LocationConfig): void;
package/dist/service.js CHANGED
@@ -27,8 +27,14 @@ const utils_1 = require("./utils");
27
27
  const location_1 = __importDefault(require("./location"));
28
28
  const memory_store_1 = __importDefault(require("./memory_store"));
29
29
  const redis_store_1 = __importDefault(require("./redis_store"));
30
- const logger_1 = __importDefault(require("@fonoster/logger"));
30
+ const logger_1 = require("@fonoster/logger");
31
+ const logger = (0, logger_1.getLogger)({ service: "location", filePath: __filename });
31
32
  const allowedParameters = ["host", "port", "username", "password", "secure"];
33
+ /**
34
+ * Creates a new locator service.
35
+ *
36
+ * @param {LocationConfig} config - Service configuration
37
+ */
32
38
  function LocationService(config) {
33
39
  const { bindAddr, cache } = config;
34
40
  let store;
@@ -39,8 +45,8 @@ function LocationService(config) {
39
45
  store = new memory_store_1.default();
40
46
  }
41
47
  const backends = new Map();
42
- config.backends.forEach(b => backends.set(`backend:${b.ref}`, b));
48
+ config.backends.forEach((b) => backends.set(`backend:${b.ref}`, b));
43
49
  (0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store, backends)));
44
- logger_1.default.info(`using ${cache.provider} as cache provider`);
50
+ logger.info(`using ${cache.provider} as cache provider`);
45
51
  }
46
52
  exports.default = LocationService;
package/dist/tracer.d.ts CHANGED
@@ -1 +1,7 @@
1
+ /**
2
+ * This function registers the instrumentations for the service.
3
+ *
4
+ * @param {string} serviceName - The name of the service.
5
+ * @return {Tracer} The tracer object.
6
+ */
1
7
  export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
package/dist/tracer.js CHANGED
@@ -30,20 +30,24 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
30
30
  const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
31
31
  const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
32
32
  const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
33
+ /**
34
+ * This function registers the instrumentations for the service.
35
+ *
36
+ * @param {string} serviceName - The name of the service.
37
+ * @return {Tracer} The tracer object.
38
+ */
33
39
  function init(serviceName) {
34
40
  const provider = new sdk_trace_node_1.NodeTracerProvider({
35
41
  resource: new resources_1.Resource({
36
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName,
37
- }),
42
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
43
+ })
38
44
  });
39
45
  const exporter = new exporter_jaeger_1.JaegerExporter();
40
46
  provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
41
47
  provider.register();
42
48
  (0, instrumentation_1.registerInstrumentations)({
43
- instrumentations: [
44
- new instrumentation_grpc_1.GrpcInstrumentation(),
45
- ],
49
+ instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
46
50
  });
47
- return api_1.default.trace.getTracer('routr-tracer');
51
+ return api_1.default.trace.getTracer("routr-tracer");
48
52
  }
49
53
  exports.init = init;
package/dist/types.d.ts CHANGED
@@ -35,17 +35,14 @@ export interface RemoveRoutesRequest {
35
35
  export interface Backend {
36
36
  ref: string;
37
37
  balancingAlgorithm?: LB_ALGORITHM;
38
- sessionAffinity?: {
39
- enabled: boolean;
40
- ref: string;
41
- };
38
+ withSessionAffinity?: boolean;
42
39
  }
43
40
  export interface LocationConfig {
44
41
  bindAddr: string;
45
42
  backends?: Backend[];
46
43
  cache?: {
47
44
  provider: CACHE_PROVIDER;
48
- parameters: string;
45
+ parameters?: string;
49
46
  };
50
47
  }
51
48
  export interface RedisStoreConfig {
package/dist/utils.d.ts CHANGED
@@ -1,12 +1,9 @@
1
- import { Route } from "@routr/common";
2
- import { ServiceInfo } from "@routr/common";
3
- import { Backend, ILocationService, RedisStoreConfig } from "./types";
1
+ import { Route, ServiceInfo } from "@routr/common";
2
+ import { ILocationService } from "./types";
4
3
  export declare const expiredFilter: (r: Route) => boolean;
5
4
  export declare const duplicateFilter: (r1: Route, r2: Route) => boolean;
6
5
  export declare const mergeKeyValue: (map: Map<string, string>) => string[];
7
6
  export declare const compareArrays: (arr: string[], target: string[]) => boolean;
8
7
  export declare const filterOnlyMatchingLabels: (requestLabels: Map<string, string>) => (route: Route) => boolean;
9
- export declare const hasAffinitySession: (backend: Backend) => boolean;
10
- export declare function getServiceInfo(bindAddr: string, locator: ILocationService): ServiceInfo;
8
+ export declare const getServiceInfo: (bindAddr: string, locator: ILocationService) => ServiceInfo;
11
9
  export declare const configFromString: (params: string, allowedKeys: string[]) => Record<string, string | boolean>;
12
- export declare const getUrlString: (config: RedisStoreConfig) => string;
package/dist/utils.js CHANGED
@@ -9,27 +9,44 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getUrlString = exports.configFromString = exports.getServiceInfo = exports.hasAffinitySession = exports.filterOnlyMatchingLabels = exports.compareArrays = exports.mergeKeyValue = exports.duplicateFilter = exports.expiredFilter = void 0;
12
+ exports.configFromString = exports.getServiceInfo = exports.filterOnlyMatchingLabels = exports.compareArrays = exports.mergeKeyValue = exports.duplicateFilter = exports.expiredFilter = void 0;
13
+ /*
14
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/routr
16
+ *
17
+ * This file is part of Routr
18
+ *
19
+ * Licensed under the MIT License (the "License")
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
13
31
  const common_1 = require("@routr/common");
14
32
  const errors_1 = require("./errors");
15
- const expiredFilter = (r) => (r.expires - (Date.now() - r.registeredOn) / 1000) > 0;
33
+ const expiredFilter = (r) => r.expires - (Date.now() - r.registeredOn) / 1000 > 0;
16
34
  exports.expiredFilter = expiredFilter;
17
35
  const duplicateFilter = (r1, r2) => !(r1.host === r2.host && r1.port === r2.port);
18
36
  exports.duplicateFilter = duplicateFilter;
19
- const mergeKeyValue = (map) => Array.from(map).map(l => l[0] + l[1]);
37
+ const mergeKeyValue = (map) => Array.from(map).map((l) => l[0] + l[1]);
20
38
  exports.mergeKeyValue = mergeKeyValue;
21
- const compareArrays = (arr, target) => target.every(v => arr.includes(v)) && arr.length === target.length;
39
+ const compareArrays = (arr, target) => target.every((v) => arr.includes(v)) && arr.length === target.length;
22
40
  exports.compareArrays = compareArrays;
23
41
  const filterOnlyMatchingLabels = (requestLabels) => (route) => route.labels
24
42
  ? (0, exports.compareArrays)((0, exports.mergeKeyValue)(requestLabels), (0, exports.mergeKeyValue)(route.labels))
25
43
  : false;
26
44
  exports.filterOnlyMatchingLabels = filterOnlyMatchingLabels;
27
- const hasAffinitySession = (backend) => { var _a; return (_a = backend === null || backend === void 0 ? void 0 : backend.sessionAffinity) === null || _a === void 0 ? void 0 : _a.enabled; };
28
- exports.hasAffinitySession = hasAffinitySession;
29
- function getServiceInfo(bindAddr, locator) {
45
+ const getServiceInfo = (bindAddr, locator) => {
30
46
  return {
31
47
  name: "location",
32
48
  bindAddr,
49
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33
50
  service: common_1.LOCATION_OBJECT_PROTO.Location.service,
34
51
  handlers: {
35
52
  addRoute: (call, callback) => {
@@ -41,7 +58,7 @@ function getServiceInfo(bindAddr, locator) {
41
58
  callback(e, null);
42
59
  }
43
60
  },
44
- findRoutes: (call, callback) => __awaiter(this, void 0, void 0, function* () {
61
+ findRoutes: (call, callback) => __awaiter(void 0, void 0, void 0, function* () {
45
62
  try {
46
63
  const routes = yield locator.findRoutes(call.request);
47
64
  if (routes.length === 0)
@@ -54,7 +71,7 @@ function getServiceInfo(bindAddr, locator) {
54
71
  callback(e, null);
55
72
  }
56
73
  }),
57
- removeRoutes: (call, callback) => __awaiter(this, void 0, void 0, function* () {
74
+ removeRoutes: (call, callback) => __awaiter(void 0, void 0, void 0, function* () {
58
75
  try {
59
76
  callback(null, {
60
77
  routes: yield locator.findRoutes(call.request)
@@ -66,18 +83,18 @@ function getServiceInfo(bindAddr, locator) {
66
83
  })
67
84
  }
68
85
  };
69
- }
86
+ };
70
87
  exports.getServiceInfo = getServiceInfo;
71
88
  const configFromString = (params, allowedKeys) => {
72
89
  if (params.length === 0)
73
90
  return {};
74
91
  const parameters = {};
75
- params.split(',').forEach(par => {
92
+ params.split(",").forEach((par) => {
76
93
  try {
77
- const key = par.split('=')[0];
78
- const value = par.split('=')[1];
94
+ const key = par.split("=")[0];
95
+ const value = par.split("=")[1];
79
96
  if (allowedKeys.indexOf(key) === -1) {
80
- throw `invalid parameter: ${key}`;
97
+ throw new Error(`invalid parameter: ${key}`);
81
98
  }
82
99
  else {
83
100
  parameters[key] = value === "true" ? true : value;
@@ -90,10 +107,3 @@ const configFromString = (params, allowedKeys) => {
90
107
  return parameters;
91
108
  };
92
109
  exports.configFromString = configFromString;
93
- const getUrlString = (config) => {
94
- return `redis${config.secure ? 's' : ''}`
95
- + `://${config.username ? config.username : ''}`
96
- + `${config.password ? ':' + config.password + '@' : ''}`
97
- + `${config.host}:${config.port}`;
98
- };
99
- exports.getUrlString = getUrlString;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.0.5-alpha.15",
3
+ "version": "2.0.5-alpha.17",
4
4
  "description": "Creates and maintains a list of routes to all registered endpoints",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -25,6 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "dependencies": {
28
+ "@fonoster/logger": "0.3.17-alpha.2",
28
29
  "@grpc/grpc-js": "^1.5.9",
29
30
  "@opentelemetry/api": "^1.0.4",
30
31
  "@opentelemetry/exporter-jaeger": "^1.0.4",
@@ -34,8 +35,8 @@
34
35
  "@opentelemetry/sdk-trace-base": "^1.0.4",
35
36
  "@opentelemetry/sdk-trace-node": "^1.0.4",
36
37
  "@opentelemetry/semantic-conventions": "^1.0.4",
37
- "@routr/common": "^2.0.5-alpha.15",
38
- "@routr/processor": "^2.0.5-alpha.15",
38
+ "@routr/common": "^2.0.5-alpha.17",
39
+ "@routr/processor": "^2.0.5-alpha.17",
39
40
  "ajv": "^6.12.6",
40
41
  "fp-ts": "^2.11.8",
41
42
  "redis": "^4.0.4"
@@ -47,5 +48,5 @@
47
48
  "bugs": {
48
49
  "url": "https://github.com/fonoster/routr/issues"
49
50
  },
50
- "gitHead": "3e08aa86f1596252546134bff677d17d7dd54ced"
51
+ "gitHead": "724e4e690f3cdd960ad6660b602a84876fc444dc"
51
52
  }