@routr/processor 2.31.2 → 2.31.4
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/alterations.d.ts +4 -3
- package/dist/alterations.js +40 -21
- package/package.json +3 -3
package/dist/alterations.d.ts
CHANGED
|
@@ -53,9 +53,10 @@ export declare const identityRewriteParameters: (original: MessageRequest, alter
|
|
|
53
53
|
* Trunk, whose To is the Number, gets the caller's own identity back. Some phones
|
|
54
54
|
* answer 481 to an in-dialog request whose To or From URI changed.
|
|
55
55
|
*
|
|
56
|
-
* The mapping is read
|
|
57
|
-
*
|
|
58
|
-
*
|
|
56
|
+
* The mapping is read from the first Route entry that carries one, in its URI
|
|
57
|
+
* user part or else its header parameters, and only when that entry points at
|
|
58
|
+
* this EdgePort: with two EdgePorts on the path, the one that rewrote the INVITE
|
|
59
|
+
* is the one that swaps, and the other leaves the request alone.
|
|
59
60
|
*
|
|
60
61
|
* @param {MessageRequest} request - an in-dialog request, with its Route set
|
|
61
62
|
* @return {MessageRequest} the request with From and To swapped where they match
|
package/dist/alterations.js
CHANGED
|
@@ -22,7 +22,7 @@ exports.swapIdentityFromRouteSet = exports.identityRewriteParameters = exports.r
|
|
|
22
22
|
const common_1 = require("@routr/common");
|
|
23
23
|
const phone_1 = require("phone");
|
|
24
24
|
const helper_1 = require("./helper");
|
|
25
|
-
const { IDENTITY_PARAMETERS, encodeIdentity, decodeIdentity } = common_1.Identity;
|
|
25
|
+
const { IDENTITY_PARAMETERS, encodeIdentity, decodeIdentity, decodeIdentityUser } = common_1.Identity;
|
|
26
26
|
// Forces the requestURI to be the same as the trunk uri.
|
|
27
27
|
// This is a workaround for Twilio.
|
|
28
28
|
const fixRequestURI = (route) => (request) => {
|
|
@@ -242,15 +242,18 @@ const removeAuthorization = (request) => {
|
|
|
242
242
|
};
|
|
243
243
|
exports.removeAuthorization = removeAuthorization;
|
|
244
244
|
// Whether a Route entry points at this EdgePort (one of its local or external
|
|
245
|
-
// addresses, on the port of the matching listening point)
|
|
245
|
+
// addresses or aliases, on the port of the matching listening point). Aliases
|
|
246
|
+
// compare case-insensitively (RFC 3261 section 19.1.4)
|
|
246
247
|
const isSelfRoute = (request) => (r) => {
|
|
247
|
-
var _a;
|
|
248
|
+
var _a, _b;
|
|
248
249
|
const localIps = request.localnets.map((ln) => ln.split("/")[0]);
|
|
249
250
|
const lp = common_1.Helper.getListeningPoint(request.listeningPoints, ((_a = r.address.uri.transportParam) === null || _a === void 0 ? void 0 : _a.toUpperCase()) ||
|
|
250
251
|
common_1.Transport.UDP);
|
|
251
252
|
const routeUri = r.address.uri;
|
|
253
|
+
const aliases = (request.aliases || []).map((a) => a.toLowerCase());
|
|
252
254
|
return ((localIps.includes(routeUri.host) ||
|
|
253
|
-
request.externalAddrs.includes(routeUri.host)
|
|
255
|
+
request.externalAddrs.includes(routeUri.host) ||
|
|
256
|
+
aliases.includes((_b = routeUri.host) === null || _b === void 0 ? void 0 : _b.toLowerCase())) &&
|
|
254
257
|
routeUri.port === (lp === null || lp === void 0 ? void 0 : lp.port));
|
|
255
258
|
};
|
|
256
259
|
const removeSelfRoutes = (request) => {
|
|
@@ -422,10 +425,28 @@ const isOwnRoute = (request, route) => {
|
|
|
422
425
|
return false;
|
|
423
426
|
}
|
|
424
427
|
};
|
|
425
|
-
|
|
428
|
+
// The mapping a Route entry carries: in its URI user part, which a user agent
|
|
429
|
+
// keeps (RFC 3261 section 12.1.2), else in its header parameters, which it may
|
|
430
|
+
// drop. Only the user part carries the port, so only it is applied exactly.
|
|
431
|
+
const identityMapping = (route) => {
|
|
432
|
+
var _a, _b;
|
|
433
|
+
const hasMapping = (values) => !!(values === null || values === void 0 ? void 0 : values[IDENTITY_PARAMETERS.fromNew]) ||
|
|
434
|
+
!!(values === null || values === void 0 ? void 0 : values[IDENTITY_PARAMETERS.toNew]);
|
|
435
|
+
const inUser = decodeIdentityUser((_b = (_a = route.address) === null || _a === void 0 ? void 0 : _a.uri) === null || _b === void 0 ? void 0 : _b.user);
|
|
436
|
+
if (hasMapping(inUser))
|
|
437
|
+
return { values: inUser, exact: true };
|
|
438
|
+
if (hasMapping(route.parameters)) {
|
|
439
|
+
return { values: route.parameters, exact: false };
|
|
440
|
+
}
|
|
441
|
+
return undefined;
|
|
442
|
+
};
|
|
443
|
+
const applyIdentity = (uri, identity, exact) => {
|
|
444
|
+
var _a;
|
|
426
445
|
uri.user = identity.user;
|
|
427
446
|
uri.host = identity.host;
|
|
428
447
|
uri.userParam = identity.userParam;
|
|
448
|
+
if (exact)
|
|
449
|
+
uri.port = (_a = identity.port) !== null && _a !== void 0 ? _a : -1;
|
|
429
450
|
};
|
|
430
451
|
/**
|
|
431
452
|
* Keeps each side of a dialog seeing the identities it knows. A request from the
|
|
@@ -433,43 +454,41 @@ const applyIdentity = (uri, identity) => {
|
|
|
433
454
|
* Trunk, whose To is the Number, gets the caller's own identity back. Some phones
|
|
434
455
|
* answer 481 to an in-dialog request whose To or From URI changed.
|
|
435
456
|
*
|
|
436
|
-
* The mapping is read
|
|
437
|
-
*
|
|
438
|
-
*
|
|
457
|
+
* The mapping is read from the first Route entry that carries one, in its URI
|
|
458
|
+
* user part or else its header parameters, and only when that entry points at
|
|
459
|
+
* this EdgePort: with two EdgePorts on the path, the one that rewrote the INVITE
|
|
460
|
+
* is the one that swaps, and the other leaves the request alone.
|
|
439
461
|
*
|
|
440
462
|
* @param {MessageRequest} request - an in-dialog request, with its Route set
|
|
441
463
|
* @return {MessageRequest} the request with From and To swapped where they match
|
|
442
464
|
*/
|
|
443
465
|
const swapIdentityFromRouteSet = (request) => {
|
|
444
466
|
var _a;
|
|
445
|
-
const own = ((_a = request.message.route) !== null && _a !== void 0 ? _a : []).find((r) =>
|
|
446
|
-
var _a, _b;
|
|
447
|
-
return ((_a = r.parameters) === null || _a === void 0 ? void 0 : _a[IDENTITY_PARAMETERS.fromNew]) ||
|
|
448
|
-
((_b = r.parameters) === null || _b === void 0 ? void 0 : _b[IDENTITY_PARAMETERS.toNew]);
|
|
449
|
-
});
|
|
467
|
+
const own = ((_a = request.message.route) !== null && _a !== void 0 ? _a : []).find((r) => identityMapping(r));
|
|
450
468
|
if (!own || !isOwnRoute(request, own))
|
|
451
469
|
return request;
|
|
452
|
-
const
|
|
453
|
-
const
|
|
454
|
-
const
|
|
455
|
-
const
|
|
470
|
+
const { values, exact } = identityMapping(own);
|
|
471
|
+
const fromOriginal = decodeIdentity(values[IDENTITY_PARAMETERS.fromOriginal]);
|
|
472
|
+
const fromNew = decodeIdentity(values[IDENTITY_PARAMETERS.fromNew]);
|
|
473
|
+
const toOriginal = decodeIdentity(values[IDENTITY_PARAMETERS.toOriginal]);
|
|
474
|
+
const toNew = decodeIdentity(values[IDENTITY_PARAMETERS.toNew]);
|
|
456
475
|
const req = common_1.Helper.deepCopy(request);
|
|
457
476
|
const from = req.message.from.address.uri;
|
|
458
477
|
const to = req.message.to.address.uri;
|
|
459
478
|
// From the caller: From is the caller, To is the callee
|
|
460
479
|
if (fromNew && sameIdentity(from, fromOriginal)) {
|
|
461
|
-
applyIdentity(from, fromNew);
|
|
480
|
+
applyIdentity(from, fromNew, exact);
|
|
462
481
|
}
|
|
463
482
|
else if (toOriginal && sameIdentity(from, toNew)) {
|
|
464
483
|
// From the Trunk: From is the callee as the Trunk knows it
|
|
465
|
-
applyIdentity(from, toOriginal);
|
|
484
|
+
applyIdentity(from, toOriginal, exact);
|
|
466
485
|
}
|
|
467
486
|
if (toNew && sameIdentity(to, toOriginal)) {
|
|
468
|
-
applyIdentity(to, toNew);
|
|
487
|
+
applyIdentity(to, toNew, exact);
|
|
469
488
|
}
|
|
470
489
|
else if (fromOriginal && sameIdentity(to, fromNew)) {
|
|
471
490
|
// From the Trunk: To is the Number the caller was presented as
|
|
472
|
-
applyIdentity(to, fromOriginal);
|
|
491
|
+
applyIdentity(to, fromOriginal, exact);
|
|
473
492
|
}
|
|
474
493
|
return req;
|
|
475
494
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/processor",
|
|
3
|
-
"version": "2.31.
|
|
3
|
+
"version": "2.31.4",
|
|
4
4
|
"description": "Processor server and API",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"@fonoster/logger": "0.6.0",
|
|
16
16
|
"@grpc/grpc-js": "~1.14.6",
|
|
17
17
|
"@grpc/proto-loader": "~0.7.10",
|
|
18
|
-
"@routr/common": "^2.31.
|
|
18
|
+
"@routr/common": "^2.31.4",
|
|
19
19
|
"fp-ts": "^2.11.8",
|
|
20
20
|
"phone": "^3.1.68"
|
|
21
21
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"bugs": {
|
|
37
37
|
"url": "https://github.com/fonoster/routr/issues"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "11c1ca25e5892aeea6f5b836b35cf9f90f020279"
|
|
40
40
|
}
|