@routr/common 2.0.8-alpha.18 → 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.
@@ -1,4 +1,4 @@
1
- import { Privacy, Transport } from "../types";
1
+ import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
2
2
  import { Kind } from "./types";
3
3
  export interface ConfigBase {
4
4
  apiVersion: string;
@@ -34,6 +34,10 @@ export interface PeerConfig extends ConfigBase {
34
34
  credentialsRef?: string;
35
35
  contactAddr?: string;
36
36
  enabled?: boolean;
37
+ loadBalancing?: {
38
+ algorithm: LoadBalancingAlgorithm;
39
+ withSessionAffinity: boolean;
40
+ };
37
41
  };
38
42
  }
39
43
  export interface CredentialsConfig extends ConfigBase {
@@ -1,2 +1,3 @@
1
1
  import { UserConfig } from "../config";
2
2
  export declare const assertValidSchema: (config: UserConfig, valid: (config: UserConfig) => boolean) => void;
3
+ export declare const assertValidAorSchema: (config: UserConfig) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertValidSchema = void 0;
3
+ exports.assertValidAorSchema = exports.assertValidSchema = void 0;
4
4
  /*
5
5
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster
@@ -29,3 +29,15 @@ const assertValidSchema = (config, valid) => {
29
29
  }
30
30
  };
31
31
  exports.assertValidSchema = assertValidSchema;
32
+ const assertValidAorSchema = (config) => {
33
+ const spec = config.spec;
34
+ if (spec.aor.startsWith("backend:") && !spec.loadBalancing) {
35
+ logger.error("found a bad resource: balancing algorithm is required for `backend:` aors");
36
+ process.exit(1);
37
+ }
38
+ if (spec.aor.startsWith("sip:") && spec.loadBalancing) {
39
+ logger.error("found a bad resource: balancing algorithm is not allowed for `sip:` aors");
40
+ process.exit(1);
41
+ }
42
+ };
43
+ exports.assertValidAorSchema = assertValidAorSchema;
@@ -6,7 +6,9 @@ const types_1 = require("../types");
6
6
  const assertions_1 = require("./assertions");
7
7
  const valid = schemas_1.schemaValidators.get(types_1.Kind.PEER);
8
8
  function mapToPeer(config) {
9
+ var _a, _b;
9
10
  (0, assertions_1.assertValidSchema)(config, valid);
11
+ (0, assertions_1.assertValidAorSchema)(config);
10
12
  return {
11
13
  apiVersion: config.apiVersion,
12
14
  ref: config.ref,
@@ -15,7 +17,9 @@ function mapToPeer(config) {
15
17
  aor: config.spec.aor,
16
18
  contactAddr: config.spec.contactAddr,
17
19
  enabled: config.spec.enabled,
18
- credentialsRef: config.spec.credentialsRef
20
+ credentialsRef: config.spec.credentialsRef,
21
+ balancingAlgorithm: (_a = config.spec.loadBalancing) === null || _a === void 0 ? void 0 : _a.algorithm.toUpperCase(),
22
+ withSessionAffinity: (_b = config.spec.loadBalancing) === null || _b === void 0 ? void 0 : _b.withSessionAffinity
19
23
  };
20
24
  }
21
25
  exports.mapToPeer = mapToPeer;
@@ -41,6 +41,13 @@ service Peers {
41
41
  rpc FindBy (FindByRequest) returns (FindByResponse) {}
42
42
  }
43
43
 
44
+ enum LoadBalancingAlgorithm {
45
+ // The round robin load balancing algorithm
46
+ ROUND_ROBIN = 0;
47
+ // The least sessions load balancing algorithm
48
+ LEAST_SESSIONS = 1;
49
+ }
50
+
44
51
  // The message for the Peer resource
45
52
  message Peer {
46
53
  // The API version of the Peer
@@ -55,18 +62,22 @@ message Peer {
55
62
  string aor = 5;
56
63
  // The contact address of the Peer
57
64
  string contact_addr = 6;
65
+ // The load balancing algorithm of the Peer
66
+ LoadBalancingAlgorithm load_balancing_algorithm = 7;
67
+ // The session affinity of the Peer
68
+ bool with_session_affinity = 8;
58
69
  // The status of the Peer
59
- bool enabled = 7;
70
+ bool enabled = 9;
60
71
  // The date and time when the Peer was created
61
- int32 created_at = 8;
72
+ int32 created_at = 10;
62
73
  // The date and time when the Peer was last updated
63
- int32 updated_at = 9;
74
+ int32 updated_at = 11;
64
75
  // The list of IP addresses that are allowed to access the Peer
65
- fonoster.routr.connect.acl.v2draft1.AccessControlList access_control_list = 10;
76
+ fonoster.routr.connect.acl.v2draft1.AccessControlList access_control_list = 12;
66
77
  // The credentials of the Peer
67
- fonoster.routr.connect.credentials.v2draft1.Credentials credentials = 11;
78
+ fonoster.routr.connect.credentials.v2draft1.Credentials credentials = 13;
68
79
  // The extended attributes of the Peer
69
- .google.protobuf.Struct extended = 12;
80
+ .google.protobuf.Struct extended = 14;
70
81
  }
71
82
 
72
83
  // The request message for the Peers.Create method
@@ -79,14 +90,18 @@ message CreatePeerRequest {
79
90
  string aor = 3;
80
91
  // The contact address of the Peer
81
92
  string contact_addr = 4;
82
- // The status of the Peer
83
- bool enabled = 5;
93
+ // The load balancing algorithm of the Peer
94
+ LoadBalancingAlgorithm load_balancing_algorithm = 5;
95
+ // The session affinity of the Peer
96
+ bool with_session_affinity = 6;
84
97
  // Reference to the ACL of the Peer
85
- string access_control_list_ref = 6;
98
+ string access_control_list_ref = 7;
86
99
  // Reference to the Credentials of the Peer
87
- string credentials_ref = 7;
100
+ string credentials_ref = 8;
101
+ // The status of the Peer
102
+ bool enabled = 9;
88
103
  // The extended attributes of the Peer
89
- .google.protobuf.Struct extended = 8;
104
+ .google.protobuf.Struct extended = 10;
90
105
  }
91
106
 
92
107
  // The request message for the Peers.Update method
@@ -101,14 +116,18 @@ message UpdatePeerRequest {
101
116
  string aor = 4;
102
117
  // The contact address of the Peer
103
118
  string contact_addr = 5;
104
- // The status of the Peer
105
- bool enabled = 6;
119
+ // The load balancing algorithm of the Peer
120
+ LoadBalancingAlgorithm load_balancing_algorithm = 6;
121
+ // The session affinity of the Peer
122
+ bool with_session_affinity = 7;
106
123
  // Reference to the ACL of the Peer
107
- string access_control_list_ref = 7;
124
+ string access_control_list_ref = 8;
108
125
  // Reference to the Credentials of the Peer
109
- string credentials_ref = 8;
126
+ string credentials_ref = 9;
127
+ // The status of the Peer
128
+ bool enabled = 10;
110
129
  // The extended attributes of the Peer
111
- .google.protobuf.Struct extended = 9;
130
+ .google.protobuf.Struct extended = 11;
112
131
  }
113
132
 
114
133
  // The request message for the Peers.Get method
@@ -57,6 +57,20 @@ declare const _default: {
57
57
  description: string;
58
58
  type: string;
59
59
  };
60
+ loadBalancing: {
61
+ description: string;
62
+ type: string;
63
+ properties: {
64
+ algorithm: {
65
+ description: string;
66
+ enum: string[];
67
+ };
68
+ withSessionAffinity: {
69
+ description: string;
70
+ type: string;
71
+ };
72
+ };
73
+ };
60
74
  enabled: {
61
75
  description: string;
62
76
  type: string;
@@ -77,6 +77,20 @@ exports.default = {
77
77
  description: "The ACL the Peer uses to control access to the Peer (Reserved for future use)",
78
78
  type: "string"
79
79
  },
80
+ loadBalancing: {
81
+ description: "The load balancing strategy for the Peer",
82
+ type: "object",
83
+ properties: {
84
+ algorithm: {
85
+ description: "The load balancing algorithm",
86
+ enum: ["round-robin", "least-sessions"]
87
+ },
88
+ withSessionAffinity: {
89
+ description: "Whether to allow session affinity",
90
+ type: "boolean"
91
+ }
92
+ }
93
+ },
80
94
  enabled: {
81
95
  description: "Whether the Peer is enabled",
82
96
  type: "boolean"
@@ -1,5 +1,5 @@
1
1
  import { JsonObject } from "pb-util/build";
2
- import { Privacy, Transport } from "../types";
2
+ import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
3
3
  export declare enum Kind {
4
4
  AGENT = "agent",
5
5
  PEER = "peer",
@@ -94,6 +94,8 @@ export interface Peer extends BaseConnectModel {
94
94
  accessControlList?: AccessControlList;
95
95
  credentialsRef?: string;
96
96
  credentials?: Credentials;
97
+ balancingAlgorithm?: LoadBalancingAlgorithm;
98
+ withSessionAffinity?: boolean;
97
99
  }
98
100
  export type ConnectModel = Agent | Peer | INumber | Trunk | Domain | Credentials | AccessControlList;
99
101
  export type RoutableResourceUnion = Agent | Peer | INumber;
@@ -61,10 +61,20 @@ message AddRouteRequest {
61
61
  }
62
62
 
63
63
  message FindRoutesRequest {
64
+ message Backend {
65
+ enum Algoritm {
66
+ ROUND_ROBIN = 0;
67
+ LEAST_SESSIONS = 1;
68
+ }
69
+ string ref = 1;
70
+ bool with_session_affinity = 2;
71
+ Algoritm algorithm = 3;
72
+ }
64
73
  string call_id = 1;
65
74
  string aor = 2;
66
75
  string session_affinity_ref = 3;
67
- map<string, string> labels = 4;
76
+ Backend backend = 4;
77
+ map<string, string> labels = 5;
68
78
  }
69
79
 
70
80
  message FindRoutesResponse {
package/dist/types.d.ts CHANGED
@@ -22,6 +22,10 @@ export declare enum Transport {
22
22
  WS = "WS",
23
23
  WSS = "WSS"
24
24
  }
25
+ export declare enum LoadBalancingAlgorithm {
26
+ ROUND_ROBIN = "ROUND-ROBIN",
27
+ LEAST_SESSIONS = "LEAST-SESSIONS"
28
+ }
25
29
  export declare enum ExtraHeader {
26
30
  REQUEST_URI = "X-Request-Uri",
27
31
  GATEWAY_AUTH = "X-Gateway-Auth",
@@ -103,8 +107,8 @@ export interface AuthChallengeResponse {
103
107
  qop: Qop;
104
108
  }
105
109
  export declare enum HeaderModifierAction {
106
- ADD = "add",
107
- REMOVE = "remove"
110
+ ADD = 0,
111
+ REMOVE = 1
108
112
  }
109
113
  export interface HeaderModifier {
110
114
  name: string;
package/dist/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.Transport = exports.Method = void 0;
3
+ exports.MessageType = exports.ResponseType = exports.HeaderModifierAction = exports.Privacy = exports.ExtraHeader = exports.LoadBalancingAlgorithm = exports.Transport = exports.Method = void 0;
4
4
  var Method;
5
5
  (function (Method) {
6
6
  Method["UNKNOWN"] = "UNKNOWN";
@@ -24,6 +24,11 @@ var Transport;
24
24
  Transport["WS"] = "WS";
25
25
  Transport["WSS"] = "WSS";
26
26
  })(Transport = exports.Transport || (exports.Transport = {}));
27
+ var LoadBalancingAlgorithm;
28
+ (function (LoadBalancingAlgorithm) {
29
+ LoadBalancingAlgorithm["ROUND_ROBIN"] = "ROUND-ROBIN";
30
+ LoadBalancingAlgorithm["LEAST_SESSIONS"] = "LEAST-SESSIONS";
31
+ })(LoadBalancingAlgorithm = exports.LoadBalancingAlgorithm || (exports.LoadBalancingAlgorithm = {}));
27
32
  var ExtraHeader;
28
33
  (function (ExtraHeader) {
29
34
  ExtraHeader["REQUEST_URI"] = "X-Request-Uri";
@@ -40,8 +45,8 @@ var Privacy;
40
45
  })(Privacy = exports.Privacy || (exports.Privacy = {}));
41
46
  var HeaderModifierAction;
42
47
  (function (HeaderModifierAction) {
43
- HeaderModifierAction["ADD"] = "add";
44
- HeaderModifierAction["REMOVE"] = "remove";
48
+ HeaderModifierAction[HeaderModifierAction["ADD"] = 0] = "ADD";
49
+ HeaderModifierAction[HeaderModifierAction["REMOVE"] = 1] = "REMOVE";
45
50
  })(HeaderModifierAction = exports.HeaderModifierAction || (exports.HeaderModifierAction = {}));
46
51
  var ResponseType;
47
52
  (function (ResponseType) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.0.8-alpha.18",
3
+ "version": "2.0.8-alpha.19",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -51,5 +51,5 @@
51
51
  "devDependencies": {
52
52
  "@types/js-yaml": "^4.0.5"
53
53
  },
54
- "gitHead": "66ce6b3ed832bb8c549d344b3367aceed4b6da8f"
54
+ "gitHead": "ff62abb0ff7704a79f98a8e0b10c0036b949cc11"
55
55
  }