@routr/connect 2.0.6-alpha.2 → 2.0.8-alpha.0

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/router.js CHANGED
@@ -51,7 +51,7 @@ function router(location, dataAPI) {
51
51
  const routingDir = (0, utils_1.getRoutingDirection)(caller, callee);
52
52
  switch (routingDir) {
53
53
  case types_1.ROUTING_DIRECTION.AGENT_TO_PSTN:
54
- return yield toPSTN(dataAPI, req, caller);
54
+ return yield toPSTN(dataAPI, req, caller, requestURI.user);
55
55
  case types_1.ROUTING_DIRECTION.AGENT_TO_AGENT:
56
56
  return agentToAgent(location, req);
57
57
  case types_1.ROUTING_DIRECTION.FROM_PSTN:
@@ -99,19 +99,24 @@ function fromPSTN(location, _, callee) {
99
99
  });
100
100
  }
101
101
  // eslint-disable-next-line require-jsdoc
102
- function toPSTN(dataAPI, req, caller) {
103
- var _a;
102
+ function toPSTN(dataAPI, req, caller, calleeNumber) {
103
+ var _a, _b;
104
104
  return __awaiter(this, void 0, void 0, function* () {
105
105
  const domain = yield dataAPI.get(caller.spec.domainRef);
106
- const number = yield dataAPI.get((_a = domain.spec.context.egressPolicy) === null || _a === void 0 ? void 0 : _a.numberRef);
106
+ // Look for Number in domain that matches regex callee
107
+ const policy = (_a = domain.spec.context.egressPolicies) === null || _a === void 0 ? void 0 : _a.find((policy) => {
108
+ const regex = new RegExp(policy.rule);
109
+ return regex.test(calleeNumber);
110
+ });
111
+ const number = yield dataAPI.get(policy === null || policy === void 0 ? void 0 : policy.numberRef);
107
112
  const trunk = yield dataAPI.get(number === null || number === void 0 ? void 0 : number.spec.trunkRef);
108
- if (!domain.spec.context.egressPolicy) {
113
+ if (!domain.spec.context.egressPolicies) {
109
114
  // TODO: Create custom error
110
- throw new Error("no egress policy found for Domain ref" + domain.metadata.ref);
115
+ throw new Error(`no egress policy found for Domain ref: ${domain.ref}`);
111
116
  }
112
117
  if (!trunk) {
113
118
  // TODO: Create custom error
114
- throw new Error("no trunk associated with Number ref: " + number.metadata.ref);
119
+ throw new Error(`no trunk associated with Number ref: ${number === null || number === void 0 ? void 0 : number.ref}`);
115
120
  }
116
121
  const uri = (0, utils_1.getTrunkURI)(trunk);
117
122
  return {
@@ -124,7 +129,7 @@ function toPSTN(dataAPI, req, caller) {
124
129
  headers: [
125
130
  {
126
131
  name: "Privacy",
127
- value: caller.spec.privacy === common_1.CommonTypes.Privacy.PRIVATE
132
+ value: ((_b = caller.spec.privacy) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === common_1.CommonTypes.Privacy.PRIVATE
128
133
  ? common_1.CommonTypes.Privacy.PRIVATE
129
134
  : common_1.CommonTypes.Privacy.NONE,
130
135
  action: common_1.CommonTypes.HeaderModifierAction.ADD
package/dist/service.js CHANGED
@@ -65,18 +65,6 @@ function ConnectProcessor(config) {
65
65
  case common_1.Method.SUBSCRIBE:
66
66
  res.sendMethodNotAllowed();
67
67
  break;
68
- case common_1.Method.CANCEL:
69
- // eslint-disable-next-line no-case-declarations
70
- const route = (yield location.findRoutes({ aor: processor_1.Target.getTargetAOR(req) }))[0];
71
- if (route) {
72
- res.sendOk([
73
- {
74
- name: common_2.CommonTypes.ExtraHeader.REQUEST_URI,
75
- value: `${route === null || route === void 0 ? void 0 : route.user},${route.host},${route.port},${route.transport}`
76
- }
77
- ]);
78
- }
79
- break;
80
68
  case common_1.Method.REGISTER:
81
69
  if (processor_1.Extensions.getHeaderValue(req, common_2.CommonTypes.ExtraHeader.GATEWAY_AUTH)) {
82
70
  (0, handlers_1.handleRegistry)(req, res);
package/dist/tailor.js CHANGED
@@ -22,7 +22,9 @@ exports.tailor = void 0;
22
22
  const processor_1 = require("@routr/processor");
23
23
  const function_1 = require("fp-ts/function");
24
24
  // Q: Shoukd we add support for strict routing?
25
- const tailor = (route, req) => (0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.applyXHeaders(route), processor_1.Alterations.addRoute(route), processor_1.Alterations.addSelfRecordRoute, processor_1.Alterations.decreaseMaxForwards, processor_1.Alterations.removeAuthorization, processor_1.Alterations.removeRoutes, processor_1.Alterations.removeXEdgePortRef
25
+ const tailor = (route, req) => (0, function_1.pipe)(
26
+ // TODO: Fix this hardcode
27
+ processor_1.Extensions.removeHeader(req, "Privacy"), processor_1.Alterations.addSelfVia(route), processor_1.Alterations.applyXHeaders(route), processor_1.Alterations.addRoute(route), processor_1.Alterations.addSelfRecordRoute, processor_1.Alterations.decreaseMaxForwards, processor_1.Alterations.removeAuthorization, processor_1.Alterations.removeRoutes, processor_1.Alterations.removeXEdgePortRef
26
28
  // Add updateContact for SIP.js support
27
29
  );
28
30
  exports.tailor = tailor;
package/dist/utils.js CHANGED
@@ -68,8 +68,7 @@ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0,
68
68
  }
69
69
  }))[0]
70
70
  : res;
71
- if ((0, exports.isKind)(res, common_2.CommonConnect.KIND.AGENT) &&
72
- res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.metadata.ref)) {
71
+ if ((0, exports.isKind)(res, common_2.CommonConnect.KIND.AGENT) && res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
73
72
  // Not in the same domain
74
73
  return null;
75
74
  }
@@ -120,10 +119,11 @@ const createRemotePartyId = (trunk, number) => {
120
119
  };
121
120
  exports.createRemotePartyId = createRemotePartyId;
122
121
  const createTrunkAuthentication = (dataAPI, trunk) => __awaiter(void 0, void 0, void 0, function* () {
122
+ var _a, _b;
123
123
  const credentials = yield dataAPI.get(trunk.spec.outbound.credentialsRef);
124
124
  return {
125
125
  name: common_2.CommonTypes.ExtraHeader.GATEWAY_AUTH,
126
- value: Buffer.from(`${credentials.spec.credentials.username}:${credentials.spec.credentials.password}`).toString("base64"),
126
+ 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
127
  action: common_2.CommonTypes.HeaderModifierAction.ADD
128
128
  };
129
129
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/connect",
3
- "version": "2.0.6-alpha.2",
3
+ "version": "2.0.8-alpha.0",
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.6-alpha.2",
32
- "@routr/location": "^2.0.6-alpha.2",
33
- "@routr/processor": "^2.0.6-alpha.2"
31
+ "@routr/common": "^2.0.8-alpha.0",
32
+ "@routr/location": "^2.0.8-alpha.0",
33
+ "@routr/processor": "^2.0.8-alpha.0"
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": "d933de33862f322730e0b3dd01ec3c009d4f2fad"
48
+ "gitHead": "69c60f113c27bc00cbadb62dbdbbb70960ef0f4d"
49
49
  }