@routr/processor 2.31.3 → 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.
@@ -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 only from Route entries that point at this EdgePort: with
57
- * two EdgePorts on the path, the one that rewrote the INVITE is the one that
58
- * swaps, and the other leaves the request alone.
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
@@ -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) => {
@@ -425,10 +425,28 @@ const isOwnRoute = (request, route) => {
425
425
  return false;
426
426
  }
427
427
  };
428
- const applyIdentity = (uri, identity) => {
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;
429
445
  uri.user = identity.user;
430
446
  uri.host = identity.host;
431
447
  uri.userParam = identity.userParam;
448
+ if (exact)
449
+ uri.port = (_a = identity.port) !== null && _a !== void 0 ? _a : -1;
432
450
  };
433
451
  /**
434
452
  * Keeps each side of a dialog seeing the identities it knows. A request from the
@@ -436,43 +454,41 @@ const applyIdentity = (uri, identity) => {
436
454
  * Trunk, whose To is the Number, gets the caller's own identity back. Some phones
437
455
  * answer 481 to an in-dialog request whose To or From URI changed.
438
456
  *
439
- * The mapping is read only from Route entries that point at this EdgePort: with
440
- * two EdgePorts on the path, the one that rewrote the INVITE is the one that
441
- * swaps, and the other leaves the request alone.
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.
442
461
  *
443
462
  * @param {MessageRequest} request - an in-dialog request, with its Route set
444
463
  * @return {MessageRequest} the request with From and To swapped where they match
445
464
  */
446
465
  const swapIdentityFromRouteSet = (request) => {
447
466
  var _a;
448
- const own = ((_a = request.message.route) !== null && _a !== void 0 ? _a : []).find((r) => {
449
- var _a, _b;
450
- return ((_a = r.parameters) === null || _a === void 0 ? void 0 : _a[IDENTITY_PARAMETERS.fromNew]) ||
451
- ((_b = r.parameters) === null || _b === void 0 ? void 0 : _b[IDENTITY_PARAMETERS.toNew]);
452
- });
467
+ const own = ((_a = request.message.route) !== null && _a !== void 0 ? _a : []).find((r) => identityMapping(r));
453
468
  if (!own || !isOwnRoute(request, own))
454
469
  return request;
455
- const fromOriginal = decodeIdentity(own.parameters[IDENTITY_PARAMETERS.fromOriginal]);
456
- const fromNew = decodeIdentity(own.parameters[IDENTITY_PARAMETERS.fromNew]);
457
- const toOriginal = decodeIdentity(own.parameters[IDENTITY_PARAMETERS.toOriginal]);
458
- const toNew = decodeIdentity(own.parameters[IDENTITY_PARAMETERS.toNew]);
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]);
459
475
  const req = common_1.Helper.deepCopy(request);
460
476
  const from = req.message.from.address.uri;
461
477
  const to = req.message.to.address.uri;
462
478
  // From the caller: From is the caller, To is the callee
463
479
  if (fromNew && sameIdentity(from, fromOriginal)) {
464
- applyIdentity(from, fromNew);
480
+ applyIdentity(from, fromNew, exact);
465
481
  }
466
482
  else if (toOriginal && sameIdentity(from, toNew)) {
467
483
  // From the Trunk: From is the callee as the Trunk knows it
468
- applyIdentity(from, toOriginal);
484
+ applyIdentity(from, toOriginal, exact);
469
485
  }
470
486
  if (toNew && sameIdentity(to, toOriginal)) {
471
- applyIdentity(to, toNew);
487
+ applyIdentity(to, toNew, exact);
472
488
  }
473
489
  else if (fromOriginal && sameIdentity(to, fromNew)) {
474
490
  // From the Trunk: To is the Number the caller was presented as
475
- applyIdentity(to, fromOriginal);
491
+ applyIdentity(to, fromOriginal, exact);
476
492
  }
477
493
  return req;
478
494
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/processor",
3
- "version": "2.31.3",
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.3",
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": "7178a8d1ad402c3a00b31b55c8b63ecd2527c975"
39
+ "gitHead": "11c1ca25e5892aeea6f5b836b35cf9f90f020279"
40
40
  }