@routr/connect 2.0.8-alpha.14 → 2.0.8-alpha.15
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/access.d.ts +5 -5
- package/dist/access.js +18 -27
- package/dist/handlers.d.ts +2 -2
- package/dist/handlers.js +8 -8
- package/dist/router.d.ts +1 -1
- package/dist/router.js +30 -34
- package/dist/service.js +2 -2
- package/dist/utils.d.ts +9 -10
- package/dist/utils.js +49 -64
- package/package.json +5 -5
package/dist/access.d.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import { MessageRequest, CommonTypes as CT, CommonConnect as CC } from "@routr/common";
|
2
2
|
import { RoutingDirection } from "./types";
|
3
3
|
export declare const checkAccess: (accessRequest: {
|
4
|
-
|
4
|
+
apiClient: CC.APIClient;
|
5
5
|
request: MessageRequest;
|
6
|
-
caller: CC.
|
7
|
-
callee: CC.
|
6
|
+
caller: CC.RoutableResourceUnion;
|
7
|
+
callee: CC.RoutableResourceUnion;
|
8
8
|
routingDirection: RoutingDirection;
|
9
9
|
}) => Promise<Record<string, unknown>>;
|
10
|
-
export declare const checkAgentOrPeerAccess: (
|
10
|
+
export declare const checkAgentOrPeerAccess: (request: MessageRequest, caller: CC.RoutableResourceUnion) => Promise<{
|
11
11
|
message: {
|
12
12
|
responseType: CT.ResponseType;
|
13
13
|
wwwAuthenticate: {
|
@@ -21,7 +21,7 @@ export declare const checkAgentOrPeerAccess: (dataAPI: CC.DataAPI, request: Mess
|
|
21
21
|
};
|
22
22
|
};
|
23
23
|
}>;
|
24
|
-
export declare const checkAccessFromPSTN: (
|
24
|
+
export declare const checkAccessFromPSTN: (apiClient: CC.APIClient, request: MessageRequest, callee: CC.INumber) => Promise<{
|
25
25
|
message: {
|
26
26
|
responseType: CT.ResponseType;
|
27
27
|
};
|
package/dist/access.js
CHANGED
@@ -31,32 +31,31 @@ exports.checkAccessFromPSTN = exports.checkAgentOrPeerAccess = exports.checkAcce
|
|
31
31
|
const logger_1 = require("@fonoster/logger");
|
32
32
|
const common_1 = require("@routr/common");
|
33
33
|
const types_1 = require("./types");
|
34
|
-
const utils_1 = require("./utils");
|
35
34
|
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
36
35
|
const checkAccess = (accessRequest) => __awaiter(void 0, void 0, void 0, function* () {
|
37
|
-
const {
|
36
|
+
const { apiClient, request, caller, callee, routingDirection } = accessRequest;
|
38
37
|
switch (routingDirection) {
|
39
38
|
case types_1.RoutingDirection.PEER_TO_PSTN:
|
40
39
|
case types_1.RoutingDirection.AGENT_TO_AGENT:
|
41
40
|
case types_1.RoutingDirection.AGENT_TO_PSTN:
|
42
|
-
return (0, exports.checkAgentOrPeerAccess)(
|
41
|
+
return (0, exports.checkAgentOrPeerAccess)(request, caller);
|
43
42
|
case types_1.RoutingDirection.FROM_PSTN:
|
44
|
-
return (0, exports.checkAccessFromPSTN)(
|
43
|
+
return (0, exports.checkAccessFromPSTN)(apiClient, request, callee);
|
45
44
|
case types_1.RoutingDirection.UNKNOWN:
|
46
45
|
return common_1.Auth.createForbideenResponse();
|
47
46
|
}
|
48
47
|
});
|
49
48
|
exports.checkAccess = checkAccess;
|
50
|
-
const checkAgentOrPeerAccess = (
|
49
|
+
const checkAgentOrPeerAccess = (request, caller) => __awaiter(void 0, void 0, void 0, function* () {
|
51
50
|
// Calculate and return challenge
|
52
51
|
if (request.message.authorization) {
|
53
52
|
const auth = Object.assign({}, request.message.authorization);
|
54
53
|
auth.method = request.method;
|
55
|
-
const credentials =
|
54
|
+
const credentials = caller.credentials;
|
56
55
|
// Calculate response and compare with the one send by the endpoint
|
57
56
|
const calcRes = common_1.Auth.calculateAuthResponse(auth, {
|
58
|
-
username: credentials === null || credentials === void 0 ? void 0 : credentials.
|
59
|
-
secret: credentials === null || credentials === void 0 ? void 0 : credentials.
|
57
|
+
username: credentials === null || credentials === void 0 ? void 0 : credentials.username,
|
58
|
+
secret: credentials === null || credentials === void 0 ? void 0 : credentials.password
|
60
59
|
});
|
61
60
|
if (calcRes !== auth.response) {
|
62
61
|
return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
|
@@ -67,26 +66,23 @@ const checkAgentOrPeerAccess = (dataAPI, request, caller) => __awaiter(void 0, v
|
|
67
66
|
}
|
68
67
|
});
|
69
68
|
exports.checkAgentOrPeerAccess = checkAgentOrPeerAccess;
|
70
|
-
const checkAccessFromPSTN = (
|
71
|
-
var _a, _b;
|
69
|
+
const checkAccessFromPSTN = (apiClient, request, callee) => __awaiter(void 0, void 0, void 0, function* () {
|
72
70
|
// Get the Trunk associated with the SIP URI
|
73
|
-
const trunk = yield
|
71
|
+
const trunk = (yield apiClient.trunks.findBy({
|
72
|
+
fieldName: "inboundUri",
|
73
|
+
fieldValue: request.message.requestUri.host
|
74
|
+
})).items[0];
|
74
75
|
// If the Trunk or Number doesn't exist reject the call
|
75
76
|
if (!callee || !trunk) {
|
76
77
|
return common_1.Auth.createForbideenResponse();
|
77
78
|
}
|
78
|
-
if (callee.
|
79
|
+
if (callee.trunk.ref !== trunk.ref) {
|
79
80
|
return common_1.Auth.createForbideenResponse();
|
80
81
|
}
|
81
82
|
// Verify that the IP is whitelisted which means getting the access control list for the trunk
|
82
|
-
if (
|
83
|
+
if (trunk.accessControlList) {
|
83
84
|
try {
|
84
|
-
const
|
85
|
-
if (!acl) {
|
86
|
-
// Should never happen since the ACL is required on start
|
87
|
-
return common_1.Auth.createServerInternalErrorResponse();
|
88
|
-
}
|
89
|
-
const allow = acl.spec.accessControlList.allow.filter((net) => {
|
85
|
+
const allow = trunk.accessControlList.allow.filter((net) => {
|
90
86
|
return common_1.IpUtils.hasIp(net, request.sender.host);
|
91
87
|
})[0];
|
92
88
|
if (!allow) {
|
@@ -99,20 +95,15 @@ const checkAccessFromPSTN = (dataAPI, request, callee) => __awaiter(void 0, void
|
|
99
95
|
}
|
100
96
|
}
|
101
97
|
// If the Trunk has a User/Password we must verify that the User/Password are valid
|
102
|
-
if (
|
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
|
-
}
|
98
|
+
if (trunk.inboundCredentials) {
|
108
99
|
// Calculate and return challenge
|
109
100
|
if (request.message.authorization) {
|
110
101
|
const auth = Object.assign({}, request.message.authorization);
|
111
102
|
auth.method = request.method;
|
112
103
|
// Calculate response and compare with the one send by the endpoint
|
113
104
|
const calcRes = common_1.Auth.calculateAuthResponse(auth, {
|
114
|
-
username:
|
115
|
-
secret:
|
105
|
+
username: trunk.inboundCredentials.username,
|
106
|
+
secret: trunk.inboundCredentials.password
|
116
107
|
});
|
117
108
|
if (calcRes !== auth.response) {
|
118
109
|
return common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host);
|
package/dist/handlers.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { MessageRequest, Response } from "@routr/processor";
|
2
2
|
import { ILocationService } from "@routr/location";
|
3
3
|
import { CommonConnect as CC } from "@routr/common";
|
4
|
-
export declare const handleRegister: (
|
4
|
+
export declare const handleRegister: (apiClient: CC.APIClient, location: ILocationService) => (request: MessageRequest, res: Response) => Promise<void>;
|
5
5
|
export declare const handleRegistry: (req: MessageRequest, res: Response) => void;
|
6
|
-
export declare const handleRequest: (location: ILocationService,
|
6
|
+
export declare const handleRequest: (location: ILocationService, apiClient?: CC.APIClient) => (req: MessageRequest, res: Response) => Promise<void>;
|
package/dist/handlers.js
CHANGED
@@ -35,29 +35,29 @@ const function_1 = require("fp-ts/function");
|
|
35
35
|
const router_1 = require("./router");
|
36
36
|
const common_1 = require("@routr/common");
|
37
37
|
const utils_1 = require("./utils");
|
38
|
-
const handleRegister = (
|
38
|
+
const handleRegister = (apiClient, location) => {
|
39
39
|
return (request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
40
40
|
// Calculate and return challenge
|
41
41
|
if (request.message.authorization) {
|
42
42
|
const auth = Object.assign({}, request.message.authorization);
|
43
43
|
auth.method = request.method;
|
44
44
|
const fromURI = request.message.from.address.uri;
|
45
|
-
const peerOrAgent = yield (0, utils_1.findResource)(
|
45
|
+
const peerOrAgent = yield (0, utils_1.findResource)(apiClient, fromURI.host, fromURI.user);
|
46
46
|
if (!peerOrAgent) {
|
47
47
|
return res.send(common_1.Auth.createForbideenResponse());
|
48
48
|
}
|
49
|
-
const credentials =
|
49
|
+
const credentials = peerOrAgent.credentials;
|
50
50
|
// Calculate response and compare with the one send by the endpoint
|
51
51
|
const calcRes = common_1.Auth.calculateAuthResponse(auth, {
|
52
|
-
username: credentials === null || credentials === void 0 ? void 0 : credentials.
|
53
|
-
secret: credentials === null || credentials === void 0 ? void 0 : credentials.
|
52
|
+
username: credentials === null || credentials === void 0 ? void 0 : credentials.username,
|
53
|
+
secret: credentials === null || credentials === void 0 ? void 0 : credentials.password
|
54
54
|
});
|
55
55
|
if (calcRes !== auth.response) {
|
56
56
|
return res.send(common_1.Auth.createUnauthorizedResponse(request.message.requestUri.host));
|
57
57
|
}
|
58
58
|
// TODO: Needs test
|
59
59
|
yield location.addRoute({
|
60
|
-
aor: peerOrAgent.
|
60
|
+
aor: "aor" in peerOrAgent ? peerOrAgent.aor : processor_1.Target.getTargetAOR(request),
|
61
61
|
route: location_1.Helper.createRoute(request)
|
62
62
|
});
|
63
63
|
res.sendOk();
|
@@ -75,11 +75,11 @@ const handleRegistry = (req, res) => {
|
|
75
75
|
};
|
76
76
|
exports.handleRegistry = handleRegistry;
|
77
77
|
// TODO: If request has X-Connect-Token then validate the JWT value and continue
|
78
|
-
const handleRequest = (location,
|
78
|
+
const handleRequest = (location, apiClient) => (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
79
79
|
try {
|
80
80
|
const route = processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.EDGEPORT_REF)
|
81
81
|
? processor_1.Helper.createRouteFromLastMessage(req)
|
82
|
-
: yield (0, router_1.router)(location,
|
82
|
+
: yield (0, router_1.router)(location, apiClient)(req);
|
83
83
|
if (!route)
|
84
84
|
return res.sendNotFound();
|
85
85
|
// If route is not type Route then return
|
package/dist/router.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import { CommonConnect as CC, Route } from "@routr/common";
|
2
2
|
import { MessageRequest } from "@routr/processor";
|
3
3
|
import { ILocationService } from "@routr/location";
|
4
|
-
export declare function router(location: ILocationService,
|
4
|
+
export declare function router(location: ILocationService, apiClient: CC.APIClient): (request: MessageRequest) => Promise<Route | Record<string, unknown>>;
|
package/dist/router.js
CHANGED
@@ -38,13 +38,12 @@ const logger_1 = require("@fonoster/logger");
|
|
38
38
|
const access_1 = require("./access");
|
39
39
|
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
40
40
|
// eslint-disable-next-line require-jsdoc
|
41
|
-
function router(location,
|
41
|
+
function router(location, apiClient) {
|
42
42
|
return (request) => __awaiter(this, void 0, void 0, function* () {
|
43
|
-
var _a;
|
44
43
|
const fromURI = request.message.from.address.uri;
|
45
44
|
const requestURI = request.message.requestUri;
|
46
|
-
const caller = yield (0, utils_1.findResource)(
|
47
|
-
const callee = yield (0, utils_1.findResource)(
|
45
|
+
const caller = yield (0, utils_1.findResource)(apiClient, fromURI.host, fromURI.user);
|
46
|
+
const callee = yield (0, utils_1.findResource)(apiClient, requestURI.host, requestURI.user);
|
48
47
|
const routingDirection = (0, utils_1.getRoutingDirection)(caller, callee);
|
49
48
|
logger.verbose("routing request from: " +
|
50
49
|
(0, utils_1.getSIPURI)(fromURI) +
|
@@ -52,12 +51,12 @@ function router(location, dataAPI) {
|
|
52
51
|
(0, utils_1.getSIPURI)(requestURI), {
|
53
52
|
fromURI: (0, utils_1.getSIPURI)(fromURI),
|
54
53
|
requestURI: (0, utils_1.getSIPURI)(requestURI),
|
55
|
-
routingDirection
|
56
|
-
sessionAffinityHeader:
|
54
|
+
routingDirection
|
55
|
+
// sessionAffinityHeader: callee?.spec.location?.sessionAffinityHeader
|
57
56
|
});
|
58
57
|
if (request.method === common_1.CommonTypes.Method.INVITE) {
|
59
58
|
const failedCheck = yield (0, access_1.checkAccess)({
|
60
|
-
|
59
|
+
apiClient,
|
61
60
|
request,
|
62
61
|
caller,
|
63
62
|
callee,
|
@@ -71,11 +70,11 @@ function router(location, dataAPI) {
|
|
71
70
|
case types_1.RoutingDirection.AGENT_TO_AGENT:
|
72
71
|
return agentToAgent(location, request);
|
73
72
|
case types_1.RoutingDirection.AGENT_TO_PSTN:
|
74
|
-
return yield agentToPSTN(
|
73
|
+
return yield agentToPSTN(request, caller, requestURI.user);
|
75
74
|
case types_1.RoutingDirection.FROM_PSTN:
|
76
75
|
return yield fromPSTN(location, callee, request);
|
77
76
|
case types_1.RoutingDirection.PEER_TO_PSTN:
|
78
|
-
return yield peerToPSTN(
|
77
|
+
return yield peerToPSTN(apiClient, request);
|
79
78
|
default:
|
80
79
|
throw new errors_1.UnsuportedRoutingError(routingDirection);
|
81
80
|
}
|
@@ -99,18 +98,18 @@ function agentToAgent(location, req) {
|
|
99
98
|
function fromPSTN(location, callee, req) {
|
100
99
|
var _a;
|
101
100
|
return __awaiter(this, void 0, void 0, function* () {
|
102
|
-
const sessionAffinityRef = processor_1.Extensions.getHeaderValue(req, callee.
|
101
|
+
const sessionAffinityRef = processor_1.Extensions.getHeaderValue(req, callee.sessionAffinityHeader);
|
103
102
|
const route = (yield location.findRoutes({
|
104
|
-
aor: callee.
|
103
|
+
aor: callee.aorLink,
|
105
104
|
callId: req.ref,
|
106
105
|
sessionAffinityRef
|
107
106
|
}))[0];
|
108
107
|
if (!route) {
|
109
|
-
throw new location_1.NotRoutesFoundForAOR(callee.
|
108
|
+
throw new location_1.NotRoutesFoundForAOR(callee.aorLink);
|
110
109
|
}
|
111
110
|
if (!route.headers)
|
112
111
|
route.headers = [];
|
113
|
-
(_a = callee.
|
112
|
+
(_a = callee.extraHeaders) === null || _a === void 0 ? void 0 : _a.forEach((prop) => {
|
114
113
|
const p = {
|
115
114
|
name: prop.name,
|
116
115
|
value: prop.value,
|
@@ -122,24 +121,22 @@ function fromPSTN(location, callee, req) {
|
|
122
121
|
});
|
123
122
|
}
|
124
123
|
// eslint-disable-next-line require-jsdoc
|
125
|
-
function agentToPSTN(
|
126
|
-
var _a;
|
124
|
+
function agentToPSTN(req, agent, calleeNumber) {
|
125
|
+
var _a, _b, _c, _d;
|
127
126
|
return __awaiter(this, void 0, void 0, function* () {
|
128
|
-
|
129
|
-
if (!domain.spec.context.egressPolicies) {
|
127
|
+
if (!((_a = agent.domain) === null || _a === void 0 ? void 0 : _a.egressPolicies)) {
|
130
128
|
// TODO: Create custom error
|
131
|
-
throw new Error(`no egress policy found for Domain ref: ${domain.ref}`);
|
129
|
+
throw new Error(`no egress policy found for Domain ref: ${agent.domain.ref}`);
|
132
130
|
}
|
133
131
|
// Look for Number in domain that matches regex callee
|
134
|
-
const policy = domain.
|
132
|
+
const policy = agent.domain.egressPolicies.find((policy) => {
|
135
133
|
const regex = new RegExp(policy.rule);
|
136
134
|
return regex.test(calleeNumber);
|
137
135
|
});
|
138
|
-
const
|
139
|
-
const trunk = yield dataAPI.get(number === null || number === void 0 ? void 0 : number.spec.trunkRef);
|
136
|
+
const trunk = (_b = policy.number) === null || _b === void 0 ? void 0 : _b.trunk;
|
140
137
|
if (!trunk) {
|
141
138
|
// This should never happen
|
142
|
-
throw new Error(`no trunk associated with Number ref: ${number.ref}`);
|
139
|
+
throw new Error(`no trunk associated with Number ref: ${(_c = policy.number) === null || _c === void 0 ? void 0 : _c.ref}`);
|
143
140
|
}
|
144
141
|
const uri = (0, utils_1.getTrunkURI)(trunk);
|
145
142
|
return {
|
@@ -159,33 +156,32 @@ function agentToPSTN(dataAPI, req, caller, calleeNumber) {
|
|
159
156
|
},
|
160
157
|
{
|
161
158
|
name: "Privacy",
|
162
|
-
value: ((
|
159
|
+
value: ((_d = agent.privacy) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === common_1.CommonTypes.Privacy.PRIVATE
|
163
160
|
? common_1.CommonTypes.Privacy.PRIVATE
|
164
161
|
: common_1.CommonTypes.Privacy.NONE,
|
165
162
|
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
166
163
|
},
|
167
|
-
(0, utils_1.createRemotePartyId)(trunk, number),
|
168
|
-
(0, utils_1.createPAssertedIdentity)(req, trunk, number),
|
169
|
-
yield (0, utils_1.createTrunkAuthentication)(
|
164
|
+
(0, utils_1.createRemotePartyId)(trunk, policy.number),
|
165
|
+
(0, utils_1.createPAssertedIdentity)(req, trunk, policy.number),
|
166
|
+
yield (0, utils_1.createTrunkAuthentication)(trunk)
|
170
167
|
]
|
171
168
|
};
|
172
169
|
});
|
173
170
|
}
|
174
171
|
// eslint-disable-next-line require-jsdoc
|
175
|
-
function peerToPSTN(
|
172
|
+
function peerToPSTN(apiClient, req) {
|
176
173
|
return __awaiter(this, void 0, void 0, function* () {
|
177
174
|
const numberTel = processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.DOD_NUMBER);
|
178
175
|
const privacy = processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.DOD_PRIVACY);
|
179
|
-
const number = yield (0, utils_1.findNumberByTelUrl)(
|
176
|
+
const number = yield (0, utils_1.findNumberByTelUrl)(apiClient, `tel:${numberTel}`);
|
180
177
|
if (!number) {
|
181
178
|
throw new Error(`no Number found for tel: ${numberTel}`);
|
182
179
|
}
|
183
|
-
|
184
|
-
if (!trunk) {
|
180
|
+
if (!number.trunk) {
|
185
181
|
// TODO: Create custom error
|
186
182
|
throw new Error(`no trunk associated with Number ref: ${number.ref}`);
|
187
183
|
}
|
188
|
-
const uri = (0, utils_1.getTrunkURI)(trunk);
|
184
|
+
const uri = (0, utils_1.getTrunkURI)(number.trunk);
|
189
185
|
return {
|
190
186
|
user: uri.user,
|
191
187
|
host: uri.host,
|
@@ -208,9 +204,9 @@ function peerToPSTN(dataAPI, req) {
|
|
208
204
|
: common_1.CommonTypes.Privacy.NONE,
|
209
205
|
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
210
206
|
},
|
211
|
-
(0, utils_1.createRemotePartyId)(trunk, number),
|
212
|
-
(0, utils_1.createPAssertedIdentity)(req, trunk, number),
|
213
|
-
yield (0, utils_1.createTrunkAuthentication)(
|
207
|
+
(0, utils_1.createRemotePartyId)(number.trunk, number),
|
208
|
+
(0, utils_1.createPAssertedIdentity)(req, number.trunk, number),
|
209
|
+
yield (0, utils_1.createTrunkAuthentication)(number.trunk)
|
214
210
|
]
|
215
211
|
};
|
216
212
|
});
|
package/dist/service.js
CHANGED
@@ -70,7 +70,7 @@ function ConnectProcessor(config) {
|
|
70
70
|
(0, handlers_1.handleRegistry)(req, res);
|
71
71
|
}
|
72
72
|
else {
|
73
|
-
(0, handlers_1.handleRegister)(common_2.CommonConnect.
|
73
|
+
(0, handlers_1.handleRegister)(common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }), location)(req, res);
|
74
74
|
}
|
75
75
|
break;
|
76
76
|
case common_1.Method.BYE:
|
@@ -78,7 +78,7 @@ function ConnectProcessor(config) {
|
|
78
78
|
res.send((0, tailor_1.tailor)(processor_1.Helper.createRouteFromLastMessage(req), req));
|
79
79
|
break;
|
80
80
|
default:
|
81
|
-
(0, handlers_1.handleRequest)(location, common_2.CommonConnect.
|
81
|
+
(0, handlers_1.handleRequest)(location, common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }))(req, res);
|
82
82
|
}
|
83
83
|
}));
|
84
84
|
}
|
package/dist/utils.d.ts
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
import { HeaderModifier, MessageRequest, Transport, CommonConnect as CC } from "@routr/common";
|
2
2
|
import { RoutingDirection } from "./types";
|
3
|
-
export declare const isKind: (res: CC.
|
4
|
-
export declare const findDomain: (
|
5
|
-
export declare const
|
6
|
-
export declare const
|
7
|
-
export declare const
|
8
|
-
export declare const
|
9
|
-
export declare const
|
10
|
-
export declare const
|
11
|
-
export declare const
|
12
|
-
export declare const getTrunkURI: (trunk: CC.Resource) => {
|
3
|
+
export declare const isKind: (res: CC.RoutableResourceUnion, kind: CC.Kind) => boolean;
|
4
|
+
export declare const findDomain: (apiClient: CC.APIClient, domainUri: string) => Promise<CC.Domain>;
|
5
|
+
export declare const findNumberByTelUrl: (apiClient: CC.APIClient, telUrl: string) => Promise<CC.INumber>;
|
6
|
+
export declare const findResource: (apiClient: CC.APIClient, domainUri: string, userpart: string) => Promise<CC.RoutableResourceUnion>;
|
7
|
+
export declare const getRoutingDirection: (caller: CC.RoutableResourceUnion, callee: CC.RoutableResourceUnion) => RoutingDirection;
|
8
|
+
export declare const createPAssertedIdentity: (req: MessageRequest, trunk: CC.Trunk, number: CC.INumber) => HeaderModifier;
|
9
|
+
export declare const createRemotePartyId: (trunk: CC.Trunk, number: CC.INumber) => HeaderModifier;
|
10
|
+
export declare const createTrunkAuthentication: (trunk: CC.Trunk) => Promise<HeaderModifier>;
|
11
|
+
export declare const getTrunkURI: (trunk: CC.Trunk) => {
|
13
12
|
host: string;
|
14
13
|
port: number;
|
15
14
|
user: 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.getSIPURI = exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePartyId = exports.createPAssertedIdentity = exports.getRoutingDirection = exports.findResource = exports.findNumberByTelUrl = exports.
|
12
|
+
exports.getSIPURI = exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePartyId = exports.createPAssertedIdentity = exports.getRoutingDirection = exports.findResource = exports.findNumberByTelUrl = 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
|
@@ -30,72 +30,61 @@ exports.getSIPURI = exports.getTrunkURI = exports.createTrunkAuthentication = ex
|
|
30
30
|
*/
|
31
31
|
const common_1 = require("@routr/common");
|
32
32
|
const types_1 = require("./types");
|
33
|
+
// OMG, this is so ugly and hacky
|
33
34
|
const isKind = (res, kind) => {
|
34
35
|
if (res == null && kind === common_1.CommonConnect.Kind.UNKNOWN) {
|
35
36
|
return true;
|
36
37
|
}
|
37
|
-
|
38
|
+
else if (res == null) {
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
else if ("privacy" in res && kind === common_1.CommonConnect.Kind.AGENT) {
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
else if ("telUrl" in res && kind === common_1.CommonConnect.Kind.NUMBER) {
|
45
|
+
return true;
|
46
|
+
}
|
47
|
+
else if ("username" in res && kind === common_1.CommonConnect.Kind.PEER) {
|
48
|
+
return true;
|
49
|
+
}
|
38
50
|
};
|
39
51
|
exports.isKind = isKind;
|
40
|
-
const findDomain = (
|
41
|
-
return (yield
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
domainUri
|
46
|
-
}
|
47
|
-
}))[0];
|
52
|
+
const findDomain = (apiClient, domainUri) => __awaiter(void 0, void 0, void 0, function* () {
|
53
|
+
return (yield apiClient.domains.findBy({
|
54
|
+
fieldName: "domainUri",
|
55
|
+
fieldValue: domainUri
|
56
|
+
})).items[0];
|
48
57
|
});
|
49
58
|
exports.findDomain = findDomain;
|
50
|
-
const
|
51
|
-
return (yield
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
requestUri
|
56
|
-
}
|
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];
|
59
|
+
const findNumberByTelUrl = (apiClient, telUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
60
|
+
return (yield apiClient.numbers.findBy({
|
61
|
+
fieldName: "telUrl",
|
62
|
+
fieldValue: telUrl
|
63
|
+
})).items[0];
|
68
64
|
});
|
69
65
|
exports.findNumberByTelUrl = findNumberByTelUrl;
|
70
|
-
const findResource = (
|
71
|
-
const domain = yield (0, exports.findDomain)(
|
72
|
-
//
|
73
|
-
|
66
|
+
const findResource = (apiClient, domainUri, userpart) => __awaiter(void 0, void 0, void 0, function* () {
|
67
|
+
const domain = yield (0, exports.findDomain)(apiClient, domainUri);
|
68
|
+
// First, try to find a number
|
69
|
+
const number = yield (0, exports.findNumberByTelUrl)(apiClient, `tel:${userpart}`);
|
70
|
+
if (number != null)
|
71
|
+
return number;
|
74
72
|
// Next, try to find an agent
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
username: userpart
|
81
|
-
}
|
82
|
-
}))[0];
|
83
|
-
}
|
84
|
-
// Next, try to find a peer
|
85
|
-
if (res == null) {
|
86
|
-
res = (yield dataAPI.findBy({
|
87
|
-
kind: common_1.CommonConnect.Kind.PEER,
|
88
|
-
criteria: common_1.CommonConnect.FindCriteria.FIND_PEER_BY_USERNAME,
|
89
|
-
parameters: {
|
90
|
-
username: userpart
|
91
|
-
}
|
92
|
-
}))[0];
|
93
|
-
}
|
94
|
-
if ((0, exports.isKind)(res, common_1.CommonConnect.Kind.AGENT) && res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
|
73
|
+
const agent = (yield apiClient.agents.findBy({
|
74
|
+
fieldName: "username",
|
75
|
+
fieldValue: userpart
|
76
|
+
})).items[0];
|
77
|
+
if (agent && agent.domain.ref != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
|
95
78
|
// Not in the same domain
|
96
79
|
return null;
|
97
80
|
}
|
98
|
-
|
81
|
+
if (agent != null)
|
82
|
+
return agent;
|
83
|
+
// Next, try to find a peer
|
84
|
+
return (yield apiClient.peers.findBy({
|
85
|
+
fieldName: "username",
|
86
|
+
fieldValue: userpart
|
87
|
+
})).items[0];
|
99
88
|
});
|
100
89
|
exports.findResource = findResource;
|
101
90
|
const getRoutingDirection = (caller, callee) => {
|
@@ -120,7 +109,7 @@ const getRoutingDirection = (caller, callee) => {
|
|
120
109
|
exports.getRoutingDirection = getRoutingDirection;
|
121
110
|
const createPAssertedIdentity = (req, trunk, number) => {
|
122
111
|
const displayName = req.message.from.address.displayName;
|
123
|
-
const remoteNumber = number.
|
112
|
+
const remoteNumber = number.telUrl.split(":")[1];
|
124
113
|
const trunkHost = (0, exports.getTrunkURI)(trunk).host;
|
125
114
|
return {
|
126
115
|
name: "P-Asserted-Identity",
|
@@ -132,7 +121,7 @@ const createPAssertedIdentity = (req, trunk, number) => {
|
|
132
121
|
};
|
133
122
|
exports.createPAssertedIdentity = createPAssertedIdentity;
|
134
123
|
const createRemotePartyId = (trunk, number) => {
|
135
|
-
const remoteNumber = number.
|
124
|
+
const remoteNumber = number.telUrl.split(":")[1];
|
136
125
|
const trunkHost = (0, exports.getTrunkURI)(trunk).host;
|
137
126
|
return {
|
138
127
|
name: "Remote-Party-ID",
|
@@ -141,29 +130,25 @@ const createRemotePartyId = (trunk, number) => {
|
|
141
130
|
};
|
142
131
|
};
|
143
132
|
exports.createRemotePartyId = createRemotePartyId;
|
144
|
-
const createTrunkAuthentication = (
|
133
|
+
const createTrunkAuthentication = (trunk) => __awaiter(void 0, void 0, void 0, function* () {
|
145
134
|
var _a, _b;
|
146
|
-
const credentials = yield dataAPI.get(trunk.spec.outbound.credentialsRef);
|
147
135
|
return {
|
148
136
|
name: common_1.CommonTypes.ExtraHeader.GATEWAY_AUTH,
|
149
|
-
value: Buffer.from(`${(_a =
|
137
|
+
value: Buffer.from(`${(_a = trunk.outboundCredentials) === null || _a === void 0 ? void 0 : _a.username}:${(_b = trunk.outboundCredentials) === null || _b === void 0 ? void 0 : _b.password}`).toString("base64"),
|
150
138
|
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
151
139
|
};
|
152
140
|
});
|
153
141
|
exports.createTrunkAuthentication = createTrunkAuthentication;
|
154
142
|
const getTrunkURI = (trunk) => {
|
155
|
-
if (!trunk.
|
143
|
+
if (!trunk.uris) {
|
156
144
|
throw new Error(`trunk ${trunk.ref} has no outbound settings`);
|
157
145
|
}
|
158
|
-
const { user, host, port, transport } = trunk.
|
159
|
-
const t = !transport
|
160
|
-
? common_1.Transport.UDP
|
161
|
-
: Object.values(common_1.Transport)[Object.values(common_1.Transport).indexOf(transport.toLowerCase())];
|
146
|
+
const { user, host, port, transport } = trunk.uris[0];
|
162
147
|
return {
|
163
148
|
user,
|
164
149
|
host,
|
165
150
|
port: port !== null && port !== void 0 ? port : 5060,
|
166
|
-
transport:
|
151
|
+
transport: transport !== null && transport !== void 0 ? transport : common_1.Transport.UDP
|
167
152
|
};
|
168
153
|
};
|
169
154
|
exports.getTrunkURI = getTrunkURI;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@routr/connect",
|
3
|
-
"version": "2.0.8-alpha.
|
3
|
+
"version": "2.0.8-alpha.15",
|
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.
|
32
|
-
"@routr/location": "^2.0.8-alpha.
|
33
|
-
"@routr/processor": "^2.0.8-alpha.
|
31
|
+
"@routr/common": "^2.0.8-alpha.15",
|
32
|
+
"@routr/location": "^2.0.8-alpha.15",
|
33
|
+
"@routr/processor": "^2.0.8-alpha.15"
|
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": "
|
48
|
+
"gitHead": "713d176551252a157b5a7693ef8dba4e3e798dea"
|
49
49
|
}
|