@routr/connect 2.6.2 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/access.js CHANGED
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.checkAccessFromPSTN = exports.checkAgentOrPeerAccess = exports.checkAccess = void 0;
13
13
  /*
14
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
16
16
  *
17
17
  * This file is part of Routr.
@@ -42,7 +42,7 @@ const checkAccess = (accessRequest) => __awaiter(void 0, void 0, void 0, functio
42
42
  case types_1.RoutingDirection.FROM_PSTN:
43
43
  return (0, exports.checkAccessFromPSTN)(apiClient, request, callee);
44
44
  case types_1.RoutingDirection.UNKNOWN:
45
- return common_1.Auth.createForbideenResponse();
45
+ return common_1.CommonResponse.createForbideenResponse();
46
46
  }
47
47
  });
48
48
  exports.checkAccess = checkAccess;
@@ -58,11 +58,11 @@ const checkAgentOrPeerAccess = (request, caller) => __awaiter(void 0, void 0, vo
58
58
  secret: credentials === null || credentials === void 0 ? void 0 : credentials.password
59
59
  });
60
60
  if (calcRes !== auth.response) {
61
- return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
61
+ return common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host);
62
62
  }
63
63
  }
64
64
  else {
65
- return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
65
+ return common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host);
66
66
  }
67
67
  });
68
68
  exports.checkAgentOrPeerAccess = checkAgentOrPeerAccess;
@@ -74,10 +74,10 @@ const checkAccessFromPSTN = (apiClient, request, callee) => __awaiter(void 0, vo
74
74
  })).items[0];
75
75
  // If the Trunk or Number doesn't exist reject the call
76
76
  if (!callee || !trunk) {
77
- return common_1.Auth.createForbideenResponse();
77
+ return common_1.CommonResponse.createForbideenResponse();
78
78
  }
79
79
  if (callee.trunk.ref !== trunk.ref) {
80
- return common_1.Auth.createForbideenResponse();
80
+ return common_1.CommonResponse.createForbideenResponse();
81
81
  }
82
82
  // Verify that the IP is allowlist which means getting the access control list for the trunk
83
83
  if (trunk.accessControlList) {
@@ -86,12 +86,12 @@ const checkAccessFromPSTN = (apiClient, request, callee) => __awaiter(void 0, vo
86
86
  return common_1.IpUtils.hasIp(net, request.sender.host);
87
87
  })[0];
88
88
  if (!allow) {
89
- return common_1.Auth.createUnauthorizedResponseWithoutChallenge();
89
+ return common_1.CommonResponse.createUnauthorizedResponseWithoutChallenge();
90
90
  }
91
91
  }
92
92
  catch (e) {
93
93
  logger.error(e);
94
- return common_1.Auth.createServerInternalErrorResponse();
94
+ return common_1.CommonResponse.createServerInternalErrorResponse();
95
95
  }
96
96
  }
97
97
  // If the Trunk has a User/Password we must verify that the User/Password are valid
@@ -106,11 +106,11 @@ const checkAccessFromPSTN = (apiClient, request, callee) => __awaiter(void 0, vo
106
106
  secret: trunk.inboundCredentials.password
107
107
  });
108
108
  if (calcRes !== auth.response) {
109
- return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
109
+ return common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host);
110
110
  }
111
111
  }
112
112
  else {
113
- return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
113
+ return common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host);
114
114
  }
115
115
  }
116
116
  });
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertOnlyOneEnvIsSet = void 0;
4
4
  /*
5
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
package/dist/envs.js CHANGED
@@ -3,7 +3,7 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.CONNECT_VERIFIER_OPTIONS = exports.CONNECT_VERIFIER_PUBLIC_KEY_PATH = exports.CONNECT_VERIFIER_ADDR = exports.API_ADDR = exports.LOCATION_ADDR = exports.BIND_ADDR = void 0;
5
5
  /*
6
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
7
7
  * http://github.com/fonoster/routr
8
8
  *
9
9
  * This file is part of Routr.
package/dist/errors.js CHANGED
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.UnsuportedRoutingError = exports.ServiceUnavailableError = void 0;
27
27
  /*
28
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
28
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
30
30
  *
31
31
  * This file is part of Routr
@@ -1,4 +1,4 @@
1
- import { MessageRequest, Response } from "@routr/processor";
2
1
  import { ILocationService } from "@routr/location";
2
+ import { MessageRequest, Response } from "@routr/processor";
3
3
  import { CommonConnect as CC } from "@routr/common";
4
4
  export declare const handleRegister: (apiClient: CC.APIClient, location: ILocationService) => (request: MessageRequest, res: Response) => Promise<void>;
@@ -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) {
@@ -11,7 +34,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  exports.handleRegister = void 0;
13
36
  /*
14
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
37
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
38
  * http://github.com/fonoster/routr
16
39
  *
17
40
  * This file is part of Routr
@@ -28,6 +51,7 @@ exports.handleRegister = void 0;
28
51
  * See the License for the specific language governing permissions and
29
52
  * limitations under the License.
30
53
  */
54
+ const grpc = __importStar(require("@grpc/grpc-js"));
31
55
  const location_1 = require("@routr/location");
32
56
  const processor_1 = require("@routr/processor");
33
57
  const common_1 = require("@routr/common");
@@ -42,9 +66,9 @@ const handleRegister = (apiClient, location) => {
42
66
  const auth = Object.assign({}, request.message.authorization);
43
67
  auth.method = request.method;
44
68
  const fromURI = request.message.from.address.uri;
45
- const peerOrAgent = yield (0, utils_1.findResource)(apiClient, fromURI.host, fromURI.user);
69
+ const peerOrAgent = (yield (0, utils_1.findResource)(apiClient, fromURI.host, fromURI.user));
46
70
  if (!peerOrAgent) {
47
- return res.send(common_1.Auth.createForbideenResponse());
71
+ return res.send(common_1.CommonResponse.createForbideenResponse());
48
72
  }
49
73
  const credentials = peerOrAgent.credentials;
50
74
  // Calculate response and compare with the one send by the endpoint
@@ -53,25 +77,38 @@ const handleRegister = (apiClient, location) => {
53
77
  secret: credentials === null || credentials === void 0 ? void 0 : credentials.password
54
78
  });
55
79
  if (calcRes !== auth.response) {
56
- return res.send(common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host));
80
+ return res.send(common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host));
81
+ }
82
+ try {
83
+ yield location.addRoute({
84
+ aor: "aor" in peerOrAgent ? peerOrAgent.aor : processor_1.Target.getTargetAOR(request),
85
+ route: location_1.Helper.createRoute(request),
86
+ maxContacts: peerOrAgent.maxContacts
87
+ });
88
+ res.sendRegisterOk(request);
89
+ }
90
+ catch (e) {
91
+ if (e.code === grpc.status.INVALID_ARGUMENT) {
92
+ const details = e.details;
93
+ res.sendForbidden(details);
94
+ logger.verbose(details);
95
+ return;
96
+ }
97
+ logger.error(e);
98
+ res.sendInternalServerError();
57
99
  }
58
- // TODO: Needs test
59
- yield location.addRoute({
60
- aor: "aor" in peerOrAgent ? peerOrAgent.aor : processor_1.Target.getTargetAOR(request),
61
- route: location_1.Helper.createRoute(request)
62
- });
63
- res.sendRegisterOk(request);
64
100
  }
65
101
  else if ((0, utils_1.hasXConnectObjectHeader)(request)) {
66
102
  const connectToken = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.CONNECT_TOKEN);
67
103
  try {
68
104
  const payload = (yield jwtVerifier.verify(connectToken));
69
105
  if (!payload.allowedMethods.includes(common_1.Method.REGISTER)) {
70
- return res.send(common_1.Auth.createForbideenResponse());
106
+ return res.send(common_1.CommonResponse.createForbideenResponse());
71
107
  }
72
108
  yield location.addRoute({
73
109
  aor: payload.aor,
74
- route: location_1.Helper.createRoute(request)
110
+ route: location_1.Helper.createRoute(request),
111
+ maxContacts: payload.maxContacts || -1
75
112
  });
76
113
  res.sendRegisterOk(request);
77
114
  }
@@ -79,11 +116,11 @@ const handleRegister = (apiClient, location) => {
79
116
  logger.verbose("unable to validate connect token", {
80
117
  originalError: e.message
81
118
  });
82
- res.send(common_1.Auth.createForbideenResponse());
119
+ res.send(common_1.CommonResponse.createForbideenResponse());
83
120
  }
84
121
  }
85
122
  else {
86
- res.send(common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host));
123
+ res.send(common_1.CommonResponse.createUnauthorizedResponse(request.message.requestUri.host));
87
124
  }
88
125
  });
89
126
  };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handleRegistry = void 0;
4
4
  /*
5
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.handleRequest = void 0;
13
13
  /*
14
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
16
16
  *
17
17
  * This file is part of Routr
package/dist/router.js CHANGED
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.router = void 0;
13
13
  /*
14
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
16
16
  *
17
17
  * This file is part of Routr.
@@ -49,12 +49,12 @@ function router(location, apiClient) {
49
49
  const connectToken = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.CONNECT_TOKEN);
50
50
  try {
51
51
  if (!jwtVerifier) {
52
- return common_1.Auth.createServerInternalErrorResponse();
52
+ return common_1.CommonResponse.createServerInternalErrorResponse();
53
53
  }
54
54
  const payload = (yield jwtVerifier.verify(connectToken));
55
55
  const domain = yield (0, utils_1.findDomain)(apiClient, payload.domain);
56
56
  if (!payload.allowedMethods.includes(common_1.Method.INVITE)) {
57
- return common_1.Auth.createForbideenResponse();
57
+ return common_1.CommonResponse.createForbideenResponse();
58
58
  }
59
59
  caller = {
60
60
  apiVersion: common_1.CommonConnect.APIVersion.V2,
@@ -88,7 +88,7 @@ function router(location, apiClient) {
88
88
  logger.verbose("unable to validate connect token", {
89
89
  originalError: e.message
90
90
  });
91
- return common_1.Auth.createForbideenResponse();
91
+ return common_1.CommonResponse.createForbideenResponse();
92
92
  }
93
93
  }
94
94
  else {
@@ -172,13 +172,12 @@ function fromPSTN(apiClient, location, callee, req) {
172
172
  return __awaiter(this, void 0, void 0, function* () {
173
173
  const sessionAffinityRef = processor_1.Extensions.getHeaderValue(req, callee.sessionAffinityHeader);
174
174
  let backend;
175
- if (callee.aorLink.startsWith("backend:")) {
176
- const peer = (yield apiClient.peers.findBy({
177
- fieldName: "aor",
178
- fieldValue: callee.aorLink
179
- })).items[0];
175
+ const peer = (yield apiClient.peers.findBy({
176
+ fieldName: "aor",
177
+ fieldValue: callee.aorLink
178
+ })).items[0];
179
+ if (peer) {
180
180
  backend = {
181
- ref: peer.ref,
182
181
  balancingAlgorithm: peer.balancingAlgorithm,
183
182
  withSessionAffinity: peer.withSessionAffinity
184
183
  };
@@ -260,7 +259,6 @@ function agentToPSTN(req, agent, calleeNumber) {
260
259
  function agentToPeer(location, callee, req) {
261
260
  return __awaiter(this, void 0, void 0, function* () {
262
261
  const backend = {
263
- ref: callee.ref,
264
262
  balancingAlgorithm: callee.balancingAlgorithm,
265
263
  withSessionAffinity: callee.withSessionAffinity
266
264
  };
package/dist/runner.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  /*
8
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/dist/tailor.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tailor = void 0;
4
4
  /*
5
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr
package/dist/tracer.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = void 0;
7
7
  /*
8
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
9
9
  * http://github.com/fonoster/routr
10
10
  *
11
11
  * This file is part of Routr
package/dist/utils.js CHANGED
@@ -37,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.getVerifierImpl = exports.hasXConnectObjectHeader = exports.getSIPURI = exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePartyId = exports.createPAssertedIdentity = exports.getRoutingDirection = exports.findResource = exports.findNumberByTelUrl = exports.findDomain = exports.isKind = void 0;
39
39
  /*
40
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
40
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
41
41
  * http://github.com/fonoster/routr
42
42
  *
43
43
  * This file is part of Routr
@@ -54,12 +54,13 @@ exports.getVerifierImpl = exports.hasXConnectObjectHeader = exports.getSIPURI =
54
54
  * See the License for the specific language governing permissions and
55
55
  * limitations under the License.
56
56
  */
57
+ const grpc = __importStar(require("@grpc/grpc-js"));
57
58
  const jwt = __importStar(require("jsonwebtoken"));
59
+ const envs_1 = require("./envs");
58
60
  const fs_1 = __importDefault(require("fs"));
59
61
  const common_1 = require("@routr/common");
60
62
  const processor_1 = require("@routr/processor");
61
63
  const types_1 = require("./types");
62
- const envs_1 = require("./envs");
63
64
  // OMG, this is so ugly and hacky
64
65
  const isKind = (res, kind) => {
65
66
  if (res == null && kind === common_1.CommonConnect.Kind.UNKNOWN) {
@@ -94,27 +95,34 @@ const findNumberByTelUrl = (apiClient, telUrl) => __awaiter(void 0, void 0, void
94
95
  });
95
96
  exports.findNumberByTelUrl = findNumberByTelUrl;
96
97
  const findResource = (apiClient, domainUri, userpart) => __awaiter(void 0, void 0, void 0, function* () {
97
- const domain = yield (0, exports.findDomain)(apiClient, domainUri);
98
- // First, try to find a number
99
- const number = yield (0, exports.findNumberByTelUrl)(apiClient, `tel:${userpart}`);
100
- if (number != null)
101
- return number;
102
- // Next, try to find an agent
103
- const agent = (yield apiClient.agents.findBy({
104
- fieldName: "username",
105
- fieldValue: userpart
106
- })).items[0];
107
- if (agent && agent.domain.ref != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
108
- // Not in the same domain
109
- return null;
110
- }
111
- if (agent != null)
112
- return agent;
113
- // Next, try to find a peer
114
- return (yield apiClient.peers.findBy({
115
- fieldName: "username",
116
- fieldValue: userpart
117
- })).items[0];
98
+ try {
99
+ const domain = yield (0, exports.findDomain)(apiClient, domainUri);
100
+ // First, try to find a number
101
+ const number = yield (0, exports.findNumberByTelUrl)(apiClient, `tel:${userpart}`);
102
+ if (number != null)
103
+ return number;
104
+ // Next, try to find an agent
105
+ const agent = (yield apiClient.agents.findBy({
106
+ fieldName: "username",
107
+ fieldValue: userpart
108
+ })).items[0];
109
+ if (agent && agent.domain.ref != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
110
+ // Not in the same domain
111
+ return null;
112
+ }
113
+ if (agent != null)
114
+ return agent;
115
+ // Next, try to find a peer
116
+ return (yield apiClient.peers.findBy({
117
+ fieldName: "username",
118
+ fieldValue: userpart
119
+ })).items[0];
120
+ }
121
+ catch (err) {
122
+ if (err.code === grpc.status.NOT_FOUND) {
123
+ return null;
124
+ }
125
+ }
118
126
  });
119
127
  exports.findResource = findResource;
120
128
  const getRoutingDirection = (caller, callee) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/connect",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "Default processor",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -28,9 +28,9 @@
28
28
  "@opentelemetry/sdk-trace-base": "^1.0.4",
29
29
  "@opentelemetry/sdk-trace-node": "^1.0.4",
30
30
  "@opentelemetry/semantic-conventions": "^1.0.4",
31
- "@routr/common": "^2.6.1",
32
- "@routr/location": "^2.6.2",
33
- "@routr/processor": "^2.6.2",
31
+ "@routr/common": "^2.7.0",
32
+ "@routr/location": "^2.7.0",
33
+ "@routr/processor": "^2.7.0",
34
34
  "jsonwebtoken": "^9.0.0"
35
35
  },
36
36
  "devDependencies": {
@@ -49,5 +49,5 @@
49
49
  "bugs": {
50
50
  "url": "https://github.com/fonoster/routr/issues"
51
51
  },
52
- "gitHead": "87f2724c378af3b3b3a4ae22b91dfa63201161d3"
52
+ "gitHead": "46d067f61a0797fbab905073f70c7ab319979d1d"
53
53
  }