@routr/connect 2.0.8-alpha.4 → 2.0.8-alpha.6

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.
@@ -0,0 +1,28 @@
1
+ import { MessageRequest, CommonConnect as CC } from "@routr/common";
2
+ import { RoutingDirection } from "./types";
3
+ export declare const checkAccess: (accessRequest: {
4
+ dataAPI: CC.DataAPI;
5
+ request: MessageRequest;
6
+ caller: CC.Resource;
7
+ callee: CC.Resource;
8
+ routingDirection: RoutingDirection;
9
+ }) => Promise<Record<string, unknown>>;
10
+ export declare const checkAgentAccess: (dataAPI: CC.DataAPI, request: MessageRequest, caller: CC.Resource) => Promise<{
11
+ message: {
12
+ responseType: number;
13
+ wwwAuthenticate: {
14
+ scheme: string;
15
+ realm: string;
16
+ qop: string;
17
+ opaque: string;
18
+ stale: boolean;
19
+ nonce: string;
20
+ algorithm: string;
21
+ };
22
+ };
23
+ }>;
24
+ export declare const checkAccessFromPSTN: (dataAPI: CC.DataAPI, request: MessageRequest, callee: CC.Resource) => Promise<{
25
+ message: {
26
+ responseType: number;
27
+ };
28
+ }>;
package/dist/access.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.checkAccessFromPSTN = exports.checkAgentAccess = exports.checkAccess = void 0;
13
+ /*
14
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster
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
+ */
31
+ const logger_1 = require("@fonoster/logger");
32
+ const common_1 = require("@routr/common");
33
+ const types_1 = require("./types");
34
+ const utils_1 = require("./utils");
35
+ const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
36
+ const checkAccess = (accessRequest) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const { dataAPI, request, caller, callee, routingDirection } = accessRequest;
38
+ switch (routingDirection) {
39
+ case types_1.RoutingDirection.AGENT_TO_AGENT:
40
+ return (0, exports.checkAgentAccess)(dataAPI, request, caller);
41
+ case types_1.RoutingDirection.AGENT_TO_PSTN:
42
+ return (0, exports.checkAgentAccess)(dataAPI, request, caller);
43
+ case types_1.RoutingDirection.FROM_PSTN:
44
+ return (0, exports.checkAccessFromPSTN)(dataAPI, request, callee);
45
+ case types_1.RoutingDirection.UNKNOWN:
46
+ return common_1.Auth.createForbideenResponse();
47
+ }
48
+ });
49
+ exports.checkAccess = checkAccess;
50
+ const checkAgentAccess = (dataAPI, request, caller) => __awaiter(void 0, void 0, void 0, function* () {
51
+ // Calculate and return challenge
52
+ if (request.message.authorization) {
53
+ const auth = Object.assign({}, request.message.authorization);
54
+ auth.method = request.method;
55
+ const credentials = yield dataAPI.get(caller.spec.credentialsRef);
56
+ // Calculate response and compare with the one send by the endpoint
57
+ const calcRes = common_1.Auth.calculateAuthResponse(auth, {
58
+ username: credentials === null || credentials === void 0 ? void 0 : credentials.spec.credentials.username,
59
+ secret: credentials === null || credentials === void 0 ? void 0 : credentials.spec.credentials.password
60
+ });
61
+ if (calcRes !== auth.response) {
62
+ return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
63
+ }
64
+ }
65
+ else {
66
+ return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
67
+ }
68
+ });
69
+ exports.checkAgentAccess = checkAgentAccess;
70
+ const checkAccessFromPSTN = (dataAPI, request, callee) => __awaiter(void 0, void 0, void 0, function* () {
71
+ var _a, _b;
72
+ // Get the Trunk associated with the SIP URI
73
+ const trunk = yield (0, utils_1.findTrunkByRequestURI)(dataAPI, request.message.requestUri.host);
74
+ // If the Trunk or Number doesn't exist reject the call
75
+ if (!callee || !trunk) {
76
+ return common_1.Auth.createForbideenResponse();
77
+ }
78
+ if (callee.spec.trunkRef !== trunk.ref) {
79
+ return common_1.Auth.createForbideenResponse();
80
+ }
81
+ // Verify that the IP is whitelisted which means getting the access control list for the trunk
82
+ if ((_a = trunk.spec.inbound) === null || _a === void 0 ? void 0 : _a.accessControlListRef) {
83
+ try {
84
+ const acl = yield dataAPI.get(trunk.spec.inbound.accessControlListRef);
85
+ if (!acl) {
86
+ // Should never happen since the ACL is required
87
+ return common_1.Auth.createServerInternalErrorResponse();
88
+ }
89
+ const allow = acl.spec.accessControlList.allow.filter((net) => {
90
+ return common_1.IpUtils.hasIp(net, request.sender.host);
91
+ })[0];
92
+ if (!allow) {
93
+ // TODO: Replace with Unauthorized
94
+ return common_1.Auth.createUnauthorizedResponseWithoutChallenge();
95
+ }
96
+ }
97
+ catch (e) {
98
+ logger.error(e);
99
+ }
100
+ }
101
+ // If the Trunk has a User/Password we must verify that the User/Password are valid
102
+ if ((_b = trunk.spec.inbound) === null || _b === void 0 ? void 0 : _b.credentialsRef) {
103
+ const credentials = yield dataAPI.get(trunk.spec.inbound.credentialsRef);
104
+ if (!credentials) {
105
+ // Should never happen since the Credentials is required
106
+ return common_1.Auth.createServerInternalErrorResponse();
107
+ }
108
+ // Calculate and return challenge
109
+ if (request.message.authorization) {
110
+ const auth = Object.assign({}, request.message.authorization);
111
+ auth.method = request.method;
112
+ // Calculate response and compare with the one send by the endpoint
113
+ const calcRes = common_1.Auth.calculateAuthResponse(auth, {
114
+ username: credentials === null || credentials === void 0 ? void 0 : credentials.spec.credentials.username,
115
+ secret: credentials === null || credentials === void 0 ? void 0 : credentials.spec.credentials.password
116
+ });
117
+ if (calcRes !== auth.response) {
118
+ return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
119
+ }
120
+ }
121
+ else {
122
+ return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
123
+ }
124
+ }
125
+ });
126
+ exports.checkAccessFromPSTN = checkAccessFromPSTN;
package/dist/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ROUTING_DIRECTION } from "./types";
1
+ import { RoutingDirection } from "./types";
2
2
  /**
3
3
  * Throw when the API server is unavailable.
4
4
  */
@@ -19,7 +19,7 @@ export declare class UnsuportedRoutingError extends Error {
19
19
  /**
20
20
  * Create a new ServiceUnavailableError.
21
21
  *
22
- * @param {string} routingDir - The routing direction
22
+ * @param {RoutingDirection} routingDirection - The routing direction
23
23
  */
24
- constructor(routingDir: ROUTING_DIRECTION);
24
+ constructor(routingDirection: RoutingDirection);
25
25
  }
package/dist/errors.js CHANGED
@@ -67,10 +67,10 @@ class UnsuportedRoutingError extends Error {
67
67
  /**
68
68
  * Create a new ServiceUnavailableError.
69
69
  *
70
- * @param {string} routingDir - The routing direction
70
+ * @param {RoutingDirection} routingDirection - The routing direction
71
71
  */
72
- constructor(routingDir) {
73
- super("unsupported routing direction: " + routingDir);
72
+ constructor(routingDirection) {
73
+ super("unsupported routing direction: " + routingDirection);
74
74
  this.code = grpc.status.UNKNOWN;
75
75
  // Set the prototype explicitly.
76
76
  Object.setPrototypeOf(this, ServiceUnavailableError.prototype);
package/dist/handlers.js CHANGED
@@ -58,13 +58,17 @@ const handleRequest = (location, dataAPI) => (req, res) => __awaiter(void 0, voi
58
58
  : yield (0, router_1.router)(location, dataAPI)(req);
59
59
  if (!route)
60
60
  return res.sendNotFound();
61
- // Forward request to peer edgeport
62
- if (req.edgePortRef !== route.edgePortRef) {
63
- return (0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route),
64
- // The LP address belongs to another edgeport
65
- processor_1.Alterations.addRouteToListeningPoint(route), processor_1.Alterations.addXEdgePortRef, processor_1.Alterations.decreaseMaxForwards);
61
+ // If route is not type Route then return
62
+ if (!("user" in route)) {
63
+ return res.send(route);
64
+ }
65
+ else {
66
+ // Forward request to peer edgeport
67
+ if (req.edgePortRef !== route.edgePortRef) {
68
+ return (0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.addRouteToPeerEdgePort(route), processor_1.Alterations.addXEdgePortRef, processor_1.Alterations.decreaseMaxForwards);
69
+ }
70
+ res.send((0, tailor_1.tailor)(route, req));
66
71
  }
67
- res.send((0, tailor_1.tailor)(route, req));
68
72
  }
69
73
  catch (err) {
70
74
  res.sendError(err);
package/dist/router.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { Route } from "@routr/common";
1
+ import { CommonConnect as CC, Route } from "@routr/common";
2
2
  import { MessageRequest } from "@routr/processor";
3
3
  import { ILocationService } from "@routr/location";
4
- import { CommonConnect as CC } from "@routr/common";
5
- export declare function router(location: ILocationService, dataAPI: CC.DataAPI): (req: MessageRequest) => Promise<Route>;
4
+ export declare function router(location: ILocationService, dataAPI: CC.DataAPI): (request: MessageRequest) => Promise<Route | Record<string, unknown>>;
package/dist/router.js CHANGED
@@ -32,33 +32,44 @@ const types_1 = require("./types");
32
32
  const common_1 = require("@routr/common");
33
33
  const utils_1 = require("./utils");
34
34
  const processor_1 = require("@routr/processor");
35
- const errors_1 = require("./errors");
36
35
  const location_1 = require("@routr/location");
36
+ const errors_1 = require("./errors");
37
37
  const logger_1 = require("@fonoster/logger");
38
- const common_2 = require("@routr/common");
38
+ const access_1 = require("./access");
39
39
  const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
40
- const getSIPURI = (uri) => `sip:${uri.user}@${uri.host}`;
41
40
  // eslint-disable-next-line require-jsdoc
42
41
  function router(location, dataAPI) {
43
- return (req) => __awaiter(this, void 0, void 0, function* () {
44
- const fromURI = req.message.from.address.uri;
45
- const requestURI = req.message.requestUri;
42
+ return (request) => __awaiter(this, void 0, void 0, function* () {
43
+ const fromURI = request.message.from.address.uri;
44
+ const requestURI = request.message.requestUri;
46
45
  logger.verbose("routing request from: " +
47
- getSIPURI(fromURI) +
46
+ (0, utils_1.getSIPURI)(fromURI) +
48
47
  ", to: " +
49
- getSIPURI(requestURI), { fromURI: getSIPURI(fromURI), requestURI: getSIPURI(requestURI) });
48
+ (0, utils_1.getSIPURI)(requestURI), { fromURI: (0, utils_1.getSIPURI)(fromURI), requestURI: (0, utils_1.getSIPURI)(requestURI) });
50
49
  const caller = yield (0, utils_1.findResource)(dataAPI, fromURI.host, fromURI.user);
51
50
  const callee = yield (0, utils_1.findResource)(dataAPI, requestURI.host, requestURI.user);
52
- const routingDir = (0, utils_1.getRoutingDirection)(caller, callee);
53
- switch (routingDir) {
54
- case types_1.ROUTING_DIRECTION.AGENT_TO_PSTN:
55
- return yield toPSTN(dataAPI, req, caller, requestURI.user);
56
- case types_1.ROUTING_DIRECTION.AGENT_TO_AGENT:
57
- return agentToAgent(location, req);
58
- case types_1.ROUTING_DIRECTION.FROM_PSTN:
51
+ const routingDirection = (0, utils_1.getRoutingDirection)(caller, callee);
52
+ if (request.method === common_1.CommonTypes.Method.INVITE) {
53
+ const failedCheck = yield (0, access_1.checkAccess)({
54
+ dataAPI,
55
+ request,
56
+ caller,
57
+ callee,
58
+ routingDirection
59
+ });
60
+ if (failedCheck) {
61
+ return failedCheck;
62
+ }
63
+ }
64
+ switch (routingDirection) {
65
+ case types_1.RoutingDirection.AGENT_TO_AGENT:
66
+ return agentToAgent(location, request);
67
+ case types_1.RoutingDirection.AGENT_TO_PSTN:
68
+ return yield toPSTN(dataAPI, request, caller, requestURI.user);
69
+ case types_1.RoutingDirection.FROM_PSTN:
59
70
  return yield fromPSTN(location, dataAPI, callee);
60
71
  default:
61
- throw new errors_1.UnsuportedRoutingError(routingDir);
72
+ throw new errors_1.UnsuportedRoutingError(routingDirection);
62
73
  }
63
74
  });
64
75
  }
@@ -92,7 +103,7 @@ function fromPSTN(location, _, callee) {
92
103
  const p = {
93
104
  name: prop.name,
94
105
  value: prop.value,
95
- action: common_2.CommonTypes.HeaderModifierAction.ADD
106
+ action: common_1.CommonTypes.HeaderModifierAction.ADD
96
107
  };
97
108
  route.headers.push(p);
98
109
  });
@@ -120,26 +131,27 @@ function toPSTN(dataAPI, req, caller, calleeNumber) {
120
131
  throw new Error(`no trunk associated with Number ref: ${number === null || number === void 0 ? void 0 : number.ref}`);
121
132
  }
122
133
  const uri = (0, utils_1.getTrunkURI)(trunk);
123
- const egressListeningPoint = common_1.Helper.getListeningPoint(req, uri.transport);
124
134
  return {
125
135
  user: uri.user,
126
136
  host: uri.host,
127
137
  port: uri.port,
128
138
  transport: uri.transport,
129
139
  edgePortRef: req.edgePortRef,
130
- egressListeningPoint,
140
+ listeningPoints: req.listeningPoints,
141
+ localnets: req.localnets,
142
+ externalAddrs: req.externalAddrs,
131
143
  headers: [
132
144
  // TODO: Find a more deterministic way to re-add the Privacy header
133
145
  {
134
146
  name: "Privacy",
135
- action: common_2.CommonTypes.HeaderModifierAction.REMOVE
147
+ action: common_1.CommonTypes.HeaderModifierAction.REMOVE
136
148
  },
137
149
  {
138
150
  name: "Privacy",
139
- value: ((_b = caller.spec.privacy) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === common_2.CommonTypes.Privacy.PRIVATE
140
- ? common_2.CommonTypes.Privacy.PRIVATE
141
- : common_2.CommonTypes.Privacy.NONE,
142
- action: common_2.CommonTypes.HeaderModifierAction.ADD
151
+ value: ((_b = caller.spec.privacy) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === common_1.CommonTypes.Privacy.PRIVATE
152
+ ? common_1.CommonTypes.Privacy.PRIVATE
153
+ : common_1.CommonTypes.Privacy.NONE,
154
+ action: common_1.CommonTypes.HeaderModifierAction.ADD
143
155
  },
144
156
  (0, utils_1.createRemotePartyId)(trunk, number),
145
157
  (0, utils_1.createPAssertedIdentity)(req, trunk, number),
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { HeaderModifier } from "@routr/common";
2
- export declare enum ROUTING_DIRECTION {
2
+ export declare enum RoutingDirection {
3
3
  FROM_PSTN = "from-pstn",
4
4
  AGENT_TO_AGENT = "agent-to-agent",
5
5
  AGENT_TO_PSTN = "agent-to-pstn",
package/dist/types.js CHANGED
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ROUTING_DIRECTION = void 0;
4
- var ROUTING_DIRECTION;
5
- (function (ROUTING_DIRECTION) {
6
- ROUTING_DIRECTION["FROM_PSTN"] = "from-pstn";
7
- ROUTING_DIRECTION["AGENT_TO_AGENT"] = "agent-to-agent";
8
- ROUTING_DIRECTION["AGENT_TO_PSTN"] = "agent-to-pstn";
9
- ROUTING_DIRECTION["PEER_TO_AGENT"] = "peer-to-agent";
10
- ROUTING_DIRECTION["PEER_TO_PSTN"] = "peer-to-pstn";
11
- ROUTING_DIRECTION["UNKNOWN"] = "unknown";
12
- })(ROUTING_DIRECTION = exports.ROUTING_DIRECTION || (exports.ROUTING_DIRECTION = {}));
3
+ exports.RoutingDirection = void 0;
4
+ var RoutingDirection;
5
+ (function (RoutingDirection) {
6
+ RoutingDirection["FROM_PSTN"] = "from-pstn";
7
+ RoutingDirection["AGENT_TO_AGENT"] = "agent-to-agent";
8
+ RoutingDirection["AGENT_TO_PSTN"] = "agent-to-pstn";
9
+ RoutingDirection["PEER_TO_AGENT"] = "peer-to-agent";
10
+ RoutingDirection["PEER_TO_PSTN"] = "peer-to-pstn";
11
+ RoutingDirection["UNKNOWN"] = "unknown";
12
+ })(RoutingDirection = exports.RoutingDirection || (exports.RoutingDirection = {}));
package/dist/utils.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- import { HeaderModifier, MessageRequest, Transport } from "@routr/common";
2
- import { CommonConnect as CC } from "@routr/common";
3
- import { ROUTING_DIRECTION } from "./types";
4
- export declare const isKind: (res: CC.Resource, kind: CC.KIND) => boolean;
1
+ import { HeaderModifier, MessageRequest, Transport, CommonConnect as CC } from "@routr/common";
2
+ import { RoutingDirection } from "./types";
3
+ export declare const isKind: (res: CC.Resource, kind: CC.Kind) => boolean;
5
4
  export declare const findDomain: (dataAPI: CC.DataAPI, domainUri: string) => Promise<CC.Resource>;
5
+ export declare const findTrunkByRequestURI: (dataAPI: CC.DataAPI, requestUri: string) => Promise<CC.Resource>;
6
+ export declare const findNumberByTelUrl: (dataAPI: CC.DataAPI, telUrl: string) => Promise<CC.Resource>;
6
7
  export declare const findResource: (dataAPI: CC.DataAPI, domainUri: string, userpart: string) => Promise<CC.Resource>;
7
- export declare const getRoutingDirection: (caller: CC.Resource, callee: CC.Resource) => ROUTING_DIRECTION;
8
+ export declare const getRoutingDirection: (caller: CC.Resource, callee: CC.Resource) => RoutingDirection;
8
9
  export declare const createPAssertedIdentity: (req: MessageRequest, trunk: CC.Resource, number: CC.Resource) => HeaderModifier;
9
10
  export declare const createRemotePartyId: (trunk: CC.Resource, number: CC.Resource) => HeaderModifier;
10
11
  export declare const createTrunkAuthentication: (dataAPI: CC.DataAPI, trunk: CC.Resource) => Promise<HeaderModifier>;
@@ -14,3 +15,7 @@ export declare const getTrunkURI: (trunk: CC.Resource) => {
14
15
  user: string;
15
16
  transport: Transport;
16
17
  };
18
+ export declare const getSIPURI: (uri: {
19
+ user?: string;
20
+ host: string;
21
+ }) => string;
package/dist/utils.js CHANGED
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePartyId = exports.createPAssertedIdentity = exports.getRoutingDirection = exports.findResource = exports.findDomain = exports.isKind = void 0;
12
+ exports.getSIPURI = exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePartyId = exports.createPAssertedIdentity = exports.getRoutingDirection = exports.findResource = exports.findNumberByTelUrl = exports.findTrunkByRequestURI = exports.findDomain = exports.isKind = void 0;
13
13
  /*
14
14
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
@@ -29,10 +29,9 @@ exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePa
29
29
  * limitations under the License.
30
30
  */
31
31
  const common_1 = require("@routr/common");
32
- const common_2 = require("@routr/common");
33
32
  const types_1 = require("./types");
34
33
  const isKind = (res, kind) => {
35
- if (res == null && kind === common_2.CommonConnect.KIND.UNKNOWN) {
34
+ if (res == null && kind === common_1.CommonConnect.Kind.UNKNOWN) {
36
35
  return true;
37
36
  }
38
37
  return (res === null || res === void 0 ? void 0 : res.kind.toLowerCase()) === kind;
@@ -40,35 +39,49 @@ const isKind = (res, kind) => {
40
39
  exports.isKind = isKind;
41
40
  const findDomain = (dataAPI, domainUri) => __awaiter(void 0, void 0, void 0, function* () {
42
41
  return (yield dataAPI.findBy({
43
- kind: common_2.CommonConnect.KIND.DOMAIN,
44
- criteria: common_2.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI,
42
+ kind: common_1.CommonConnect.Kind.DOMAIN,
43
+ criteria: common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI,
45
44
  parameters: {
46
45
  domainUri
47
46
  }
48
47
  }))[0];
49
48
  });
50
49
  exports.findDomain = findDomain;
51
- const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0, void 0, function* () {
52
- const domain = yield (0, exports.findDomain)(dataAPI, domainUri);
53
- // TODO: Fix jsonpath not working for logical AND and OR
54
- let res = (yield dataAPI.findBy({
55
- kind: common_2.CommonConnect.KIND.NUMBER,
56
- criteria: common_2.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL,
50
+ const findTrunkByRequestURI = (dataAPI, requestUri) => __awaiter(void 0, void 0, void 0, function* () {
51
+ return (yield dataAPI.findBy({
52
+ kind: common_1.CommonConnect.Kind.TRUNK,
53
+ criteria: common_1.CommonConnect.FindCriteria.FIND_TRUNK_BY_REQUEST_URI,
57
54
  parameters: {
58
- telUrl: `tel:${userpart}`
55
+ requestUri
59
56
  }
60
57
  }))[0];
58
+ });
59
+ exports.findTrunkByRequestURI = findTrunkByRequestURI;
60
+ const findNumberByTelUrl = (dataAPI, telUrl) => __awaiter(void 0, void 0, void 0, function* () {
61
+ return (yield dataAPI.findBy({
62
+ kind: common_1.CommonConnect.Kind.NUMBER,
63
+ criteria: common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL,
64
+ parameters: {
65
+ telUrl
66
+ }
67
+ }))[0];
68
+ });
69
+ exports.findNumberByTelUrl = findNumberByTelUrl;
70
+ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0, void 0, function* () {
71
+ const domain = yield (0, exports.findDomain)(dataAPI, domainUri);
72
+ // TODO: Fix jsonpath not working for logical AND and OR
73
+ let res = yield (0, exports.findNumberByTelUrl)(dataAPI, `tel:${userpart}`);
61
74
  res =
62
75
  res == null
63
76
  ? (yield dataAPI.findBy({
64
- kind: common_2.CommonConnect.KIND.AGENT,
65
- criteria: common_2.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME,
77
+ kind: common_1.CommonConnect.Kind.AGENT,
78
+ criteria: common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME,
66
79
  parameters: {
67
80
  username: userpart
68
81
  }
69
82
  }))[0]
70
83
  : res;
71
- if ((0, exports.isKind)(res, common_2.CommonConnect.KIND.AGENT) && res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
84
+ if ((0, exports.isKind)(res, common_1.CommonConnect.Kind.AGENT) && res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
72
85
  // Not in the same domain
73
86
  return null;
74
87
  }
@@ -76,23 +89,23 @@ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0,
76
89
  });
77
90
  exports.findResource = findResource;
78
91
  const getRoutingDirection = (caller, callee) => {
79
- if ((0, exports.isKind)(caller, common_2.CommonConnect.KIND.AGENT) && (0, exports.isKind)(callee, common_2.CommonConnect.KIND.AGENT)) {
80
- return types_1.ROUTING_DIRECTION.AGENT_TO_AGENT;
92
+ if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.AGENT) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.AGENT)) {
93
+ return types_1.RoutingDirection.AGENT_TO_AGENT;
81
94
  }
82
- if ((0, exports.isKind)(caller, common_2.CommonConnect.KIND.AGENT) && (0, exports.isKind)(callee, common_2.CommonConnect.KIND.UNKNOWN)) {
83
- return types_1.ROUTING_DIRECTION.AGENT_TO_PSTN;
95
+ if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.AGENT) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.UNKNOWN)) {
96
+ return types_1.RoutingDirection.AGENT_TO_PSTN;
84
97
  }
85
- if ((0, exports.isKind)(caller, common_2.CommonConnect.KIND.PEER) && (0, exports.isKind)(callee, common_2.CommonConnect.KIND.AGENT)) {
86
- return types_1.ROUTING_DIRECTION.PEER_TO_AGENT;
98
+ if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.PEER) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.AGENT)) {
99
+ return types_1.RoutingDirection.PEER_TO_AGENT;
87
100
  }
88
101
  // All we know is that the Number is managed by this instance of Routr
89
- if ((0, exports.isKind)(callee, common_2.CommonConnect.KIND.NUMBER)) {
90
- return types_1.ROUTING_DIRECTION.FROM_PSTN;
102
+ if ((0, exports.isKind)(callee, common_1.CommonConnect.Kind.NUMBER)) {
103
+ return types_1.RoutingDirection.FROM_PSTN;
91
104
  }
92
- if ((0, exports.isKind)(caller, common_2.CommonConnect.KIND.PEER) && (0, exports.isKind)(callee, common_2.CommonConnect.KIND.UNKNOWN)) {
93
- return types_1.ROUTING_DIRECTION.PEER_TO_PSTN;
105
+ if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.PEER) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.UNKNOWN)) {
106
+ return types_1.RoutingDirection.PEER_TO_PSTN;
94
107
  }
95
- return types_1.ROUTING_DIRECTION.UNKNOWN;
108
+ return types_1.RoutingDirection.UNKNOWN;
96
109
  };
97
110
  exports.getRoutingDirection = getRoutingDirection;
98
111
  const createPAssertedIdentity = (req, trunk, number) => {
@@ -104,7 +117,7 @@ const createPAssertedIdentity = (req, trunk, number) => {
104
117
  value: displayName
105
118
  ? `"${displayName}" <sip:${remoteNumber}@${trunkHost};user=phone>`
106
119
  : `<sip:${remoteNumber}@${trunkHost};user=phone>`,
107
- action: common_2.CommonTypes.HeaderModifierAction.ADD
120
+ action: common_1.CommonTypes.HeaderModifierAction.ADD
108
121
  };
109
122
  };
110
123
  exports.createPAssertedIdentity = createPAssertedIdentity;
@@ -114,7 +127,7 @@ const createRemotePartyId = (trunk, number) => {
114
127
  return {
115
128
  name: "Remote-Party-ID",
116
129
  value: `<sip:${remoteNumber}@${trunkHost}>;screen=yes;party=calling`,
117
- action: common_2.CommonTypes.HeaderModifierAction.ADD
130
+ action: common_1.CommonTypes.HeaderModifierAction.ADD
118
131
  };
119
132
  };
120
133
  exports.createRemotePartyId = createRemotePartyId;
@@ -122,9 +135,9 @@ const createTrunkAuthentication = (dataAPI, trunk) => __awaiter(void 0, void 0,
122
135
  var _a, _b;
123
136
  const credentials = yield dataAPI.get(trunk.spec.outbound.credentialsRef);
124
137
  return {
125
- name: common_2.CommonTypes.ExtraHeader.GATEWAY_AUTH,
138
+ name: common_1.CommonTypes.ExtraHeader.GATEWAY_AUTH,
126
139
  value: Buffer.from(`${(_a = credentials.spec.credentials) === null || _a === void 0 ? void 0 : _a.username}:${(_b = credentials.spec.credentials) === null || _b === void 0 ? void 0 : _b.password}`).toString("base64"),
127
- action: common_2.CommonTypes.HeaderModifierAction.ADD
140
+ action: common_1.CommonTypes.HeaderModifierAction.ADD
128
141
  };
129
142
  });
130
143
  exports.createTrunkAuthentication = createTrunkAuthentication;
@@ -142,3 +155,5 @@ const getTrunkURI = (trunk) => {
142
155
  };
143
156
  };
144
157
  exports.getTrunkURI = getTrunkURI;
158
+ const getSIPURI = (uri) => uri.user ? `sip:${uri.user}@${uri.host}` : `sip:${uri.host}`;
159
+ exports.getSIPURI = getSIPURI;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/connect",
3
- "version": "2.0.8-alpha.4",
3
+ "version": "2.0.8-alpha.6",
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.0.8-alpha.4",
32
- "@routr/location": "^2.0.8-alpha.4",
33
- "@routr/processor": "^2.0.8-alpha.4"
31
+ "@routr/common": "^2.0.8-alpha.6",
32
+ "@routr/location": "^2.0.8-alpha.6",
33
+ "@routr/processor": "^2.0.8-alpha.6"
34
34
  },
35
35
  "files": [
36
36
  "dist"
@@ -45,5 +45,5 @@
45
45
  "bugs": {
46
46
  "url": "https://github.com/fonoster/routr/issues"
47
47
  },
48
- "gitHead": "320abeb05175976ddfca265096a2ea63004607f4"
48
+ "gitHead": "0647d7472b78b4a60e54e3577fed9e9fd4e9eaa4"
49
49
  }