@routr/processor 2.31.4 → 2.31.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.
@@ -32,13 +32,18 @@ export declare const isAnonymous: (uri: CommonTypes.SipURI) => boolean;
32
32
  * domain. The tag and display name stay, so the dialog is unchanged for Routr,
33
33
  * which matches on tags and Call-ID. An anonymous From is left as it is.
34
34
  *
35
+ * To moves to the Trunk URI's host and port, so it matches the Request-URI
36
+ * (RFC 3261 section 8.1.1.1): WhatsApp Business Calling answers 403 when the
37
+ * digest uri, the Request-URI, differs from To. Its user stays as
38
+ * normalizeToE164 left it, and an anonymous From doesn't change that.
39
+ *
35
40
  * @param {Route} route - the route; does nothing unless route.rewriteFrom is set
36
41
  * @return {Function} the alteration
37
42
  */
38
43
  export declare const rewriteFromWithNumber: (route: Route) => (request: MessageRequest) => MessageRequest;
39
44
  /**
40
- * The Record-Route parameters that remember how the identity alterations changed
41
- * a request's From and To. Both ends of the dialog copy Record-Route into the
45
+ * The identity mapping that remembers how the identity alterations changed a
46
+ * request's From and To; addSelfRecordRoute writes it in its Record-Route URI. Both ends of the dialog copy Record-Route into the
42
47
  * Route of their in-dialog requests, so the mapping comes back to Routr on every
43
48
  * BYE, re-INVITE and ACK without any state in Routr (see swapIdentityFromRouteSet).
44
49
  *
@@ -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, decodeIdentityUser } = common_1.Identity;
25
+ const { IDENTITY_PARAMETERS, encodeIdentity, encodeIdentityUser, decodeIdentity, decodeIdentityUser, portOf } = 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) => {
@@ -146,10 +146,13 @@ const applyXHeaders = (route) => (request) => {
146
146
  return req;
147
147
  };
148
148
  exports.applyXHeaders = applyXHeaders;
149
- // The parameters argument is merged into every Record-Route entry this adds;
150
- // identityRewriteParameters uses it to carry a rewritten From or To.
149
+ // The parameters argument is the identity mapping from identityRewriteParameters.
150
+ // It goes in the URI user part of every Record-Route entry this adds, which a
151
+ // user agent keeps (RFC 3261 section 12.1.2), so a rewritten From or To comes
152
+ // back on the dialog's later requests (see swapIdentityFromRouteSet).
151
153
  const addSelfRecordRoute = (route, parameters = {}) => (request) => {
152
154
  const req = common_1.Helper.deepCopy(request);
155
+ const user = encodeIdentityUser(parameters);
153
156
  const originIntf = (0, helper_1.getEdgeInterface)({
154
157
  listeningPoints: request.listeningPoints,
155
158
  localnets: request.localnets,
@@ -169,12 +172,7 @@ const addSelfRecordRoute = (route, parameters = {}) => (request) => {
169
172
  });
170
173
  const originRoute = {
171
174
  address: {
172
- uri: {
173
- host: originIntf.host,
174
- port: originIntf.port,
175
- transportParam: originIntf.transport,
176
- lrParam: true
177
- }
175
+ uri: Object.assign(Object.assign({}, (user ? { user } : {})), { host: originIntf.host, port: originIntf.port, transportParam: originIntf.transport, lrParam: true })
178
176
  }
179
177
  };
180
178
  if (originIntf.host !== targetIntf.host ||
@@ -182,17 +180,16 @@ const addSelfRecordRoute = (route, parameters = {}) => (request) => {
182
180
  originIntf.transport !== targetIntf.transport) {
183
181
  const targetRoute = {
184
182
  address: {
185
- uri: {
186
- host: targetIntf.host,
187
- port: targetIntf.port,
188
- transportParam: targetIntf.transport,
189
- lrParam: true
190
- }
183
+ uri: Object.assign(Object.assign({}, (user ? { user } : {})), { host: targetIntf.host, port: targetIntf.port, transportParam: targetIntf.transport, lrParam: true })
191
184
  },
192
- parameters: Object.assign({ r2: "on" }, parameters)
185
+ parameters: {
186
+ r2: "on"
187
+ }
193
188
  };
194
189
  // Add r2 on to origin route
195
- originRoute.parameters = Object.assign({ r2: "on" }, parameters);
190
+ originRoute.parameters = {
191
+ r2: "on"
192
+ };
196
193
  req.message.recordRoute = [
197
194
  targetRoute,
198
195
  originRoute,
@@ -200,9 +197,6 @@ const addSelfRecordRoute = (route, parameters = {}) => (request) => {
200
197
  ];
201
198
  }
202
199
  else {
203
- if (Object.keys(parameters).length > 0) {
204
- originRoute.parameters = Object.assign({}, parameters);
205
- }
206
200
  req.message.recordRoute = [originRoute, ...req.message.recordRoute];
207
201
  }
208
202
  return req;
@@ -355,15 +349,23 @@ exports.isAnonymous = isAnonymous;
355
349
  * domain. The tag and display name stay, so the dialog is unchanged for Routr,
356
350
  * which matches on tags and Call-ID. An anonymous From is left as it is.
357
351
  *
352
+ * To moves to the Trunk URI's host and port, so it matches the Request-URI
353
+ * (RFC 3261 section 8.1.1.1): WhatsApp Business Calling answers 403 when the
354
+ * digest uri, the Request-URI, differs from To. Its user stays as
355
+ * normalizeToE164 left it, and an anonymous From doesn't change that.
356
+ *
358
357
  * @param {Route} route - the route; does nothing unless route.rewriteFrom is set
359
358
  * @return {Function} the alteration
360
359
  */
361
360
  const rewriteFromWithNumber = (route) => (request) => {
362
361
  if (!route.rewriteFrom)
363
362
  return request;
364
- if ((0, exports.isAnonymous)(request.message.from.address.uri))
365
- return request;
366
363
  const req = common_1.Helper.deepCopy(request);
364
+ const to = req.message.to.address.uri;
365
+ to.host = route.host;
366
+ to.port = route.port;
367
+ if ((0, exports.isAnonymous)(req.message.from.address.uri))
368
+ return req;
367
369
  const uri = req.message.from.address.uri;
368
370
  uri.user = route.rewriteFrom.user;
369
371
  uri.host = route.rewriteFrom.host;
@@ -386,11 +388,12 @@ const changed = (a, b) => {
386
388
  var _a, _b, _c, _d;
387
389
  return ((_a = a.user) !== null && _a !== void 0 ? _a : "") !== ((_b = b.user) !== null && _b !== void 0 ? _b : "") ||
388
390
  a.host !== b.host ||
391
+ portOf(a) !== portOf(b) ||
389
392
  ((_c = a.userParam) !== null && _c !== void 0 ? _c : "") !== ((_d = b.userParam) !== null && _d !== void 0 ? _d : "");
390
393
  };
391
394
  /**
392
- * The Record-Route parameters that remember how the identity alterations changed
393
- * a request's From and To. Both ends of the dialog copy Record-Route into the
395
+ * The identity mapping that remembers how the identity alterations changed a
396
+ * request's From and To; addSelfRecordRoute writes it in its Record-Route URI. Both ends of the dialog copy Record-Route into the
394
397
  * Route of their in-dialog requests, so the mapping comes back to Routr on every
395
398
  * BYE, re-INVITE and ACK without any state in Routr (see swapIdentityFromRouteSet).
396
399
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/processor",
3
- "version": "2.31.4",
3
+ "version": "2.31.6",
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.4",
18
+ "@routr/common": "^2.31.6",
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": "11c1ca25e5892aeea6f5b836b35cf9f90f020279"
39
+ "gitHead": "6b8037538e00b4465bafc9b57118a79b82b56e41"
40
40
  }