@routr/location 2.0.8-alpha.17 → 2.0.8-alpha.19

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
@@ -32,6 +32,7 @@ export default class Location implements ILocationService {
32
32
  * @param {FindRoutesResponse} request - Request to find routes
33
33
  * @param {string} request.aor - AOR of the route
34
34
  * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
35
+ * @param {object} request.backend - Optional Route backend (reserved for future use)
35
36
  * @return {Promise<void>}
36
37
  */
37
38
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
package/dist/client.js CHANGED
@@ -76,6 +76,7 @@ class Location {
76
76
  * @param {FindRoutesResponse} request - Request to find routes
77
77
  * @param {string} request.aor - AOR of the route
78
78
  * @param {Map<string, string>} request.labels - Optional Route labels (reserved for future use)
79
+ * @param {object} request.backend - Optional Route backend (reserved for future use)
79
80
  * @return {Promise<void>}
80
81
  */
81
82
  findRoutes(request) {
@@ -1,4 +1,4 @@
1
1
  import { LocationConfig } from "../types";
2
2
  import * as E from "fp-ts/Either";
3
- import { InvalidConfiguration } from "../errors";
4
- export declare const getConfig: (path: string) => E.Either<InvalidConfiguration, LocationConfig>;
3
+ import { InvalidSchemaConfiguration } from "../errors";
4
+ export declare const getConfig: (path: string) => E.Either<InvalidSchemaConfiguration, LocationConfig>;
@@ -53,10 +53,6 @@ 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.LoadBalancingAlgorithm.ROUND_ROBIN &&
57
- b.withSessionAffinity);
58
- const hasBadAlgorithm = (backends) => backends.some((b) => b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.ROUND_ROBIN &&
59
- b.balancingAlgorithm !== types_1.LoadBalancingAlgorithm.LEAST_SESSIONS);
60
56
  const getConfig = (path) => {
61
57
  var _a, _b, _c;
62
58
  const c = common_1.Helper.readConfigFile(path);
@@ -64,21 +60,6 @@ const getConfig = (path) => {
64
60
  return E.left(new errors_1.InvalidSchemaConfiguration(JSON.stringify(validate.errors[0].message)));
65
61
  }
66
62
  const config = c.spec;
67
- if (config.backends) {
68
- config.backends.map((b) => {
69
- // Setting round-robin by default
70
- b.balancingAlgorithm = b.balancingAlgorithm
71
- ? b.balancingAlgorithm
72
- : types_1.LoadBalancingAlgorithm.ROUND_ROBIN;
73
- return b;
74
- });
75
- if (hasBadCombiniation(config.backends)) {
76
- return E.left(new errors_1.BadAlgorithmAndAffinityCombination());
77
- }
78
- if (hasBadAlgorithm(config.backends)) {
79
- return E.left(new errors_1.InvalidLoadBalancerAlgorithm());
80
- }
81
- }
82
63
  if (!((_a = config.cache) === null || _a === void 0 ? void 0 : _a.provider)) {
83
64
  config.cache = {
84
65
  provider: types_1.CacheProvider.MEMORY
@@ -34,26 +34,6 @@ export declare const schema: {
34
34
  };
35
35
  required: string[];
36
36
  };
37
- backends: {
38
- description: string;
39
- type: string;
40
- items: {
41
- type: string;
42
- };
43
- properties: {
44
- ref: {
45
- type: string;
46
- };
47
- balancingAlgorithm: {
48
- enum: string[];
49
- };
50
- withSessionAffinity: {
51
- description: string;
52
- type: string;
53
- };
54
- };
55
- required: string[];
56
- };
57
37
  };
58
38
  };
59
39
  };
@@ -29,7 +29,7 @@ exports.schema = {
29
29
  enum: ["Location", "location"]
30
30
  },
31
31
  apiVersion: {
32
- enum: ["v2draft1"]
32
+ enum: ["v2draft1", "v2"]
33
33
  },
34
34
  metadata: {
35
35
  description: "Resource metadata",
@@ -47,33 +47,13 @@ exports.schema = {
47
47
  type: "object",
48
48
  properties: {
49
49
  provider: {
50
- enum: ["memory", "redis"]
50
+ enum: ["Memory", "Redis", "memory", "redis"]
51
51
  },
52
52
  parameters: {
53
53
  type: "string"
54
54
  }
55
55
  },
56
56
  required: ["provider"]
57
- },
58
- backends: {
59
- description: "Optional SIP backends",
60
- type: "array",
61
- items: {
62
- type: "object"
63
- },
64
- properties: {
65
- ref: {
66
- type: "string"
67
- },
68
- balancingAlgorithm: {
69
- enum: ["round-robin", "least-sessions"]
70
- },
71
- withSessionAffinity: {
72
- description: "Optional session affinity",
73
- type: "boolean"
74
- }
75
- },
76
- required: ["ref"]
77
57
  }
78
58
  }
79
59
  }
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import * as grpc from "@grpc/grpc-js";
2
2
  export type LocationError = UnsupportedSchema | NotRoutesFoundForAOR;
3
- export type InvalidConfiguration = BadAlgorithmAndAffinityCombination | InvalidSchemaConfiguration;
4
3
  /**
5
4
  * Error thrown when the location service returns an unsupported schema.
6
5
  */
@@ -37,23 +36,3 @@ export declare class InvalidSchemaConfiguration extends Error {
37
36
  */
38
37
  constructor(msg: string);
39
38
  }
40
- /**
41
- * Error thrown when the location finds incompatible algorithm and session affinity.
42
- */
43
- export declare class BadAlgorithmAndAffinityCombination extends Error {
44
- code: grpc.status;
45
- /**
46
- * Create a new BadAlgorithmAndAffinityCombination error.
47
- */
48
- constructor();
49
- }
50
- /**
51
- * Error thrown when the location finds an invalid balancing algorithm.
52
- */
53
- export declare class InvalidLoadBalancerAlgorithm extends Error {
54
- code: grpc.status;
55
- /**
56
- * Create a new InvalidLoadBalancerAlgorithm error.
57
- */
58
- constructor();
59
- }
package/dist/errors.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.InvalidLoadBalancerAlgorithm = exports.BadAlgorithmAndAffinityCombination = exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
26
+ exports.InvalidSchemaConfiguration = exports.NotRoutesFoundForAOR = exports.UnsupportedSchema = void 0;
27
27
  /*
28
28
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
@@ -92,29 +92,3 @@ class InvalidSchemaConfiguration extends Error {
92
92
  }
93
93
  }
94
94
  exports.InvalidSchemaConfiguration = InvalidSchemaConfiguration;
95
- /**
96
- * Error thrown when the location finds incompatible algorithm and session affinity.
97
- */
98
- class BadAlgorithmAndAffinityCombination extends Error {
99
- /**
100
- * Create a new BadAlgorithmAndAffinityCombination error.
101
- */
102
- constructor() {
103
- super("session affinity can not be combined with round-robin load balancing");
104
- Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
105
- }
106
- }
107
- exports.BadAlgorithmAndAffinityCombination = BadAlgorithmAndAffinityCombination;
108
- /**
109
- * Error thrown when the location finds an invalid balancing algorithm.
110
- */
111
- class InvalidLoadBalancerAlgorithm extends Error {
112
- /**
113
- * Create a new InvalidLoadBalancerAlgorithm error.
114
- */
115
- constructor() {
116
- super("found invalid load balancing algorithm. must be round-robin or least-sessions");
117
- Object.setPrototypeOf(this, BadAlgorithmAndAffinityCombination.prototype);
118
- }
119
- }
120
- exports.InvalidLoadBalancerAlgorithm = InvalidLoadBalancerAlgorithm;
package/dist/helper.js CHANGED
@@ -28,6 +28,7 @@ const processor_1 = require("@routr/processor");
28
28
  // Also consider: https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L116
29
29
  // and https://github.com/fonoster/routr/blob/ee5d339888344013939d06c734385f17f0cd75c2/mod/registrar/utils.js#L131
30
30
  const createRoute = (request) => {
31
+ var _a;
31
32
  const uri = request.message.contact.address.uri;
32
33
  const sessionCount = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT)
33
34
  ? parseInt(processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.SESSION_COUNT))
@@ -37,7 +38,7 @@ const createRoute = (request) => {
37
38
  user: uri.user,
38
39
  host: uri.host,
39
40
  port: uri.port,
40
- transport: uri.transportParam.toLowerCase(),
41
+ transport: (_a = uri.transportParam) === null || _a === void 0 ? void 0 : _a.toUpperCase(),
41
42
  registeredOn: Date.now(),
42
43
  sessionCount,
43
44
  expires: processor_1.Target.getTargetExpires(request),
@@ -1,11 +1,10 @@
1
- import { AddRouteRequest, Backend, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
1
+ import { AddRouteRequest, FindRoutesRequest, ILocationService, ILocatorStore, RemoveRoutesRequest } from "./types";
2
2
  import { Route } from "@routr/common";
3
3
  /**
4
4
  * A locator store that uses the location service to find routes for AORs.
5
5
  */
6
6
  export default class Location implements ILocationService {
7
7
  private store;
8
- private backends;
9
8
  private rrCount;
10
9
  /**
11
10
  * Creates a new Location service. Should fail if any backend has sessionAffinity and round-robin
@@ -13,7 +12,7 @@ export default class Location implements ILocationService {
13
12
  * @param {ILocatorStore} store - The store to use for the location service
14
13
  * @param {Map<string, Backend>} backends - The backends to use for the location service
15
14
  */
16
- constructor(store: ILocatorStore, backends?: Map<string, Backend>);
15
+ constructor(store: ILocatorStore);
17
16
  /** @inheritdoc */
18
17
  addRoute(request: AddRouteRequest): Promise<void>;
19
18
  /** @inheritdoc */
package/dist/location.js CHANGED
@@ -28,7 +28,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
28
28
  * limitations under the License.
29
29
  */
30
30
  const errors_1 = require("./errors");
31
- const types_1 = require("./types");
31
+ const common_1 = require("@routr/common");
32
32
  const utils_1 = require("./utils");
33
33
  var AOR_SCHEME;
34
34
  (function (AOR_SCHEME) {
@@ -45,11 +45,9 @@ class Location {
45
45
  * @param {ILocatorStore} store - The store to use for the location service
46
46
  * @param {Map<string, Backend>} backends - The backends to use for the location service
47
47
  */
48
- constructor(store, backends = new Map()) {
48
+ constructor(store) {
49
49
  this.store = store;
50
- this.backends = backends;
51
50
  this.rrCount = new Map();
52
- this.backends.forEach((_, key) => this.rrCount.set(key, 0));
53
51
  }
54
52
  /** @inheritdoc */
55
53
  addRoute(request) {
@@ -76,10 +74,7 @@ class Location {
76
74
  return routes;
77
75
  }
78
76
  else if (request.aor.startsWith(AOR_SCHEME.BACKEND)) {
79
- const backend = this.backends.get(request.aor);
80
- if (!backend) {
81
- throw new errors_1.NotRoutesFoundForAOR(request.aor);
82
- }
77
+ const { backend } = request;
83
78
  // If it has not affinity sesssion then get next
84
79
  const r =
85
80
  // Falls back to round-robin if no session affinity ref is provided
@@ -99,11 +94,12 @@ class Location {
99
94
  }
100
95
  // eslint-disable-next-line require-jsdoc
101
96
  next(routes, backend) {
102
- if (backend.balancingAlgorithm === types_1.LoadBalancingAlgorithm.LEAST_SESSIONS) {
97
+ var _a;
98
+ if (backend.balancingAlgorithm === common_1.CommonTypes.LoadBalancingAlgorithm.LEAST_SESSIONS) {
103
99
  return routes.sort((r1, r2) => r1.sessionCount - r2.sessionCount)[0];
104
100
  }
105
101
  // Continues using round-robin
106
- const nextPosition = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`);
102
+ const nextPosition = (_a = this.rrCount.get(`${AOR_SCHEME.BACKEND}${backend.ref}`)) !== null && _a !== void 0 ? _a : 0;
107
103
  const result = routes[nextPosition];
108
104
  if (nextPosition >= routes.length - 1) {
109
105
  // Restarting round-robin counter
package/dist/service.js CHANGED
@@ -36,17 +36,16 @@ const allowedParameters = ["host", "port", "username", "password", "secure"];
36
36
  * @param {LocationConfig} config - Service configuration
37
37
  */
38
38
  function LocationService(config) {
39
+ var _a;
39
40
  const { bindAddr, cache } = config;
40
41
  let store;
41
- if (cache.provider === types_1.CacheProvider.REDIS) {
42
+ if (((_a = cache.provider) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === types_1.CacheProvider.REDIS) {
42
43
  store = new redis_store_1.default((0, utils_1.configFromString)(cache.parameters, allowedParameters));
43
44
  }
44
45
  else {
45
46
  store = new memory_store_1.default();
46
47
  }
47
- const backends = new Map();
48
- config.backends.forEach((b) => backends.set(`backend:${b.ref}`, b));
49
- (0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store, backends)));
48
+ (0, common_1.createService)((0, utils_1.getServiceInfo)(bindAddr, new location_1.default(store)));
50
49
  logger.info(`using ${cache.provider} as cache provider`);
51
50
  }
52
51
  exports.default = LocationService;
package/dist/types.d.ts CHANGED
@@ -1,12 +1,4 @@
1
- import { Route } from "@routr/common";
2
- export declare enum LoadBalancingAlgorithm {
3
- ROUND_ROBIN = "round-robin",
4
- LEAST_SESSIONS = "least-sessions"
5
- }
6
- export declare enum CacheProvider {
7
- MEMORY = "memory",
8
- REDIS = "redis"
9
- }
1
+ import { Route, CommonTypes as CT } from "@routr/common";
10
2
  export interface ILocationService {
11
3
  addRoute(request: AddRouteRequest): Promise<void>;
12
4
  findRoutes(request: FindRoutesRequest): Promise<Route[]>;
@@ -25,6 +17,7 @@ export interface FindRoutesRequest {
25
17
  aor: string;
26
18
  callId: string;
27
19
  sessionAffinityRef?: string;
20
+ backend?: Backend;
28
21
  labels?: Map<string, string>;
29
22
  }
30
23
  export interface FindRoutesResponse {
@@ -35,12 +28,15 @@ export interface RemoveRoutesRequest {
35
28
  }
36
29
  export interface Backend {
37
30
  ref: string;
38
- balancingAlgorithm?: LoadBalancingAlgorithm;
39
- withSessionAffinity?: boolean;
31
+ balancingAlgorithm: CT.LoadBalancingAlgorithm;
32
+ withSessionAffinity: boolean;
33
+ }
34
+ export declare enum CacheProvider {
35
+ MEMORY = "MEMORY",
36
+ REDIS = "REDIS"
40
37
  }
41
38
  export interface LocationConfig {
42
39
  bindAddr: string;
43
- backends?: Backend[];
44
40
  cache?: {
45
41
  provider: CacheProvider;
46
42
  parameters?: string;
package/dist/types.js CHANGED
@@ -1,13 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CacheProvider = exports.LoadBalancingAlgorithm = void 0;
4
- var LoadBalancingAlgorithm;
5
- (function (LoadBalancingAlgorithm) {
6
- LoadBalancingAlgorithm["ROUND_ROBIN"] = "round-robin";
7
- LoadBalancingAlgorithm["LEAST_SESSIONS"] = "least-sessions";
8
- })(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
3
+ exports.CacheProvider = void 0;
9
4
  var CacheProvider;
10
5
  (function (CacheProvider) {
11
- CacheProvider["MEMORY"] = "memory";
12
- CacheProvider["REDIS"] = "redis";
6
+ CacheProvider["MEMORY"] = "MEMORY";
7
+ CacheProvider["REDIS"] = "REDIS";
13
8
  })(CacheProvider = exports.CacheProvider || (exports.CacheProvider = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/location",
3
- "version": "2.0.8-alpha.17",
3
+ "version": "2.0.8-alpha.19",
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",
@@ -35,8 +35,8 @@
35
35
  "@opentelemetry/sdk-trace-base": "^1.0.4",
36
36
  "@opentelemetry/sdk-trace-node": "^1.0.4",
37
37
  "@opentelemetry/semantic-conventions": "^1.0.4",
38
- "@routr/common": "^2.0.8-alpha.17",
39
- "@routr/processor": "^2.0.8-alpha.17",
38
+ "@routr/common": "^2.0.8-alpha.19",
39
+ "@routr/processor": "^2.0.8-alpha.19",
40
40
  "ajv": "^6.12.6",
41
41
  "fp-ts": "^2.11.8",
42
42
  "redis": "^4.0.4"
@@ -48,5 +48,5 @@
48
48
  "bugs": {
49
49
  "url": "https://github.com/fonoster/routr/issues"
50
50
  },
51
- "gitHead": "58f2415a0c32ab860a254a6fac0c1d3de8718dfb"
51
+ "gitHead": "ff62abb0ff7704a79f98a8e0b10c0036b949cc11"
52
52
  }