@routr/connect 2.0.8-alpha.3 → 2.0.8-alpha.5
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/errors.d.ts +2 -2
- package/dist/router.d.ts +1 -2
- package/dist/router.js +10 -11
- package/dist/types.d.ts +1 -1
- package/dist/types.js +10 -10
- package/dist/utils.d.ts +4 -5
- package/dist/utils.js +23 -24
- package/package.json +5 -5
package/dist/errors.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { RoutingDirection } from "./types";
|
2
2
|
/**
|
3
3
|
* Throw when the API server is unavailable.
|
4
4
|
*/
|
@@ -21,5 +21,5 @@ export declare class UnsuportedRoutingError extends Error {
|
|
21
21
|
*
|
22
22
|
* @param {string} routingDir - The routing direction
|
23
23
|
*/
|
24
|
-
constructor(routingDir:
|
24
|
+
constructor(routingDir: RoutingDirection);
|
25
25
|
}
|
package/dist/router.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
import { Route } from "@routr/common";
|
1
|
+
import { CommonConnect as CC, Route } from "@routr/common";
|
2
2
|
import { MessageRequest } from "@routr/processor";
|
3
3
|
import { ILocationService } from "@routr/location";
|
4
|
-
import { CommonConnect as CC } from "@routr/common";
|
5
4
|
export declare function router(location: ILocationService, dataAPI: CC.DataAPI): (req: MessageRequest) => Promise<Route>;
|
package/dist/router.js
CHANGED
@@ -32,10 +32,9 @@ const types_1 = require("./types");
|
|
32
32
|
const common_1 = require("@routr/common");
|
33
33
|
const utils_1 = require("./utils");
|
34
34
|
const processor_1 = require("@routr/processor");
|
35
|
-
const errors_1 = require("./errors");
|
36
35
|
const location_1 = require("@routr/location");
|
36
|
+
const errors_1 = require("./errors");
|
37
37
|
const logger_1 = require("@fonoster/logger");
|
38
|
-
const common_2 = require("@routr/common");
|
39
38
|
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
40
39
|
const getSIPURI = (uri) => `sip:${uri.user}@${uri.host}`;
|
41
40
|
// eslint-disable-next-line require-jsdoc
|
@@ -51,11 +50,11 @@ function router(location, dataAPI) {
|
|
51
50
|
const callee = yield (0, utils_1.findResource)(dataAPI, requestURI.host, requestURI.user);
|
52
51
|
const routingDir = (0, utils_1.getRoutingDirection)(caller, callee);
|
53
52
|
switch (routingDir) {
|
54
|
-
case types_1.
|
53
|
+
case types_1.RoutingDirection.AGENT_TO_PSTN:
|
55
54
|
return yield toPSTN(dataAPI, req, caller, requestURI.user);
|
56
|
-
case types_1.
|
55
|
+
case types_1.RoutingDirection.AGENT_TO_AGENT:
|
57
56
|
return agentToAgent(location, req);
|
58
|
-
case types_1.
|
57
|
+
case types_1.RoutingDirection.FROM_PSTN:
|
59
58
|
return yield fromPSTN(location, dataAPI, callee);
|
60
59
|
default:
|
61
60
|
throw new errors_1.UnsuportedRoutingError(routingDir);
|
@@ -92,7 +91,7 @@ function fromPSTN(location, _, callee) {
|
|
92
91
|
const p = {
|
93
92
|
name: prop.name,
|
94
93
|
value: prop.value,
|
95
|
-
action:
|
94
|
+
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
96
95
|
};
|
97
96
|
route.headers.push(p);
|
98
97
|
});
|
@@ -132,14 +131,14 @@ function toPSTN(dataAPI, req, caller, calleeNumber) {
|
|
132
131
|
// TODO: Find a more deterministic way to re-add the Privacy header
|
133
132
|
{
|
134
133
|
name: "Privacy",
|
135
|
-
action:
|
134
|
+
action: common_1.CommonTypes.HeaderModifierAction.REMOVE
|
136
135
|
},
|
137
136
|
{
|
138
137
|
name: "Privacy",
|
139
|
-
value: ((_b = caller.spec.privacy) === null || _b === void 0 ? void 0 : _b.toLowerCase()) ===
|
140
|
-
?
|
141
|
-
:
|
142
|
-
action:
|
138
|
+
value: ((_b = caller.spec.privacy) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === common_1.CommonTypes.Privacy.PRIVATE
|
139
|
+
? common_1.CommonTypes.Privacy.PRIVATE
|
140
|
+
: common_1.CommonTypes.Privacy.NONE,
|
141
|
+
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
143
142
|
},
|
144
143
|
(0, utils_1.createRemotePartyId)(trunk, number),
|
145
144
|
(0, utils_1.createPAssertedIdentity)(req, trunk, number),
|
package/dist/types.d.ts
CHANGED
package/dist/types.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
var
|
5
|
-
(function (
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
})(
|
3
|
+
exports.RoutingDirection = void 0;
|
4
|
+
var RoutingDirection;
|
5
|
+
(function (RoutingDirection) {
|
6
|
+
RoutingDirection["FROM_PSTN"] = "from-pstn";
|
7
|
+
RoutingDirection["AGENT_TO_AGENT"] = "agent-to-agent";
|
8
|
+
RoutingDirection["AGENT_TO_PSTN"] = "agent-to-pstn";
|
9
|
+
RoutingDirection["PEER_TO_AGENT"] = "peer-to-agent";
|
10
|
+
RoutingDirection["PEER_TO_PSTN"] = "peer-to-pstn";
|
11
|
+
RoutingDirection["UNKNOWN"] = "unknown";
|
12
|
+
})(RoutingDirection = exports.RoutingDirection || (exports.RoutingDirection = {}));
|
package/dist/utils.d.ts
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
import { HeaderModifier, MessageRequest, Transport } from "@routr/common";
|
2
|
-
import {
|
3
|
-
|
4
|
-
export declare const isKind: (res: CC.Resource, kind: CC.KIND) => boolean;
|
1
|
+
import { HeaderModifier, MessageRequest, Transport, CommonConnect as CC } from "@routr/common";
|
2
|
+
import { RoutingDirection } from "./types";
|
3
|
+
export declare const isKind: (res: CC.Resource, kind: CC.Kind) => boolean;
|
5
4
|
export declare const findDomain: (dataAPI: CC.DataAPI, domainUri: string) => Promise<CC.Resource>;
|
6
5
|
export declare const findResource: (dataAPI: CC.DataAPI, domainUri: string, userpart: string) => Promise<CC.Resource>;
|
7
|
-
export declare const getRoutingDirection: (caller: CC.Resource, callee: CC.Resource) =>
|
6
|
+
export declare const getRoutingDirection: (caller: CC.Resource, callee: CC.Resource) => RoutingDirection;
|
8
7
|
export declare const createPAssertedIdentity: (req: MessageRequest, trunk: CC.Resource, number: CC.Resource) => HeaderModifier;
|
9
8
|
export declare const createRemotePartyId: (trunk: CC.Resource, number: CC.Resource) => HeaderModifier;
|
10
9
|
export declare const createTrunkAuthentication: (dataAPI: CC.DataAPI, trunk: CC.Resource) => Promise<HeaderModifier>;
|
package/dist/utils.js
CHANGED
@@ -29,10 +29,9 @@ exports.getTrunkURI = exports.createTrunkAuthentication = exports.createRemotePa
|
|
29
29
|
* limitations under the License.
|
30
30
|
*/
|
31
31
|
const common_1 = require("@routr/common");
|
32
|
-
const common_2 = require("@routr/common");
|
33
32
|
const types_1 = require("./types");
|
34
33
|
const isKind = (res, kind) => {
|
35
|
-
if (res == null && kind ===
|
34
|
+
if (res == null && kind === common_1.CommonConnect.Kind.UNKNOWN) {
|
36
35
|
return true;
|
37
36
|
}
|
38
37
|
return (res === null || res === void 0 ? void 0 : res.kind.toLowerCase()) === kind;
|
@@ -40,8 +39,8 @@ const isKind = (res, kind) => {
|
|
40
39
|
exports.isKind = isKind;
|
41
40
|
const findDomain = (dataAPI, domainUri) => __awaiter(void 0, void 0, void 0, function* () {
|
42
41
|
return (yield dataAPI.findBy({
|
43
|
-
kind:
|
44
|
-
criteria:
|
42
|
+
kind: common_1.CommonConnect.Kind.DOMAIN,
|
43
|
+
criteria: common_1.CommonConnect.FindCriteria.FIND_DOMAIN_BY_DOMAINURI,
|
45
44
|
parameters: {
|
46
45
|
domainUri
|
47
46
|
}
|
@@ -52,8 +51,8 @@ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0,
|
|
52
51
|
const domain = yield (0, exports.findDomain)(dataAPI, domainUri);
|
53
52
|
// TODO: Fix jsonpath not working for logical AND and OR
|
54
53
|
let res = (yield dataAPI.findBy({
|
55
|
-
kind:
|
56
|
-
criteria:
|
54
|
+
kind: common_1.CommonConnect.Kind.NUMBER,
|
55
|
+
criteria: common_1.CommonConnect.FindCriteria.FIND_NUMBER_BY_TELURL,
|
57
56
|
parameters: {
|
58
57
|
telUrl: `tel:${userpart}`
|
59
58
|
}
|
@@ -61,14 +60,14 @@ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0,
|
|
61
60
|
res =
|
62
61
|
res == null
|
63
62
|
? (yield dataAPI.findBy({
|
64
|
-
kind:
|
65
|
-
criteria:
|
63
|
+
kind: common_1.CommonConnect.Kind.AGENT,
|
64
|
+
criteria: common_1.CommonConnect.FindCriteria.FIND_AGENT_BY_USERNAME,
|
66
65
|
parameters: {
|
67
66
|
username: userpart
|
68
67
|
}
|
69
68
|
}))[0]
|
70
69
|
: res;
|
71
|
-
if ((0, exports.isKind)(res,
|
70
|
+
if ((0, exports.isKind)(res, common_1.CommonConnect.Kind.AGENT) && res.spec.domainRef != (domain === null || domain === void 0 ? void 0 : domain.ref)) {
|
72
71
|
// Not in the same domain
|
73
72
|
return null;
|
74
73
|
}
|
@@ -76,23 +75,23 @@ const findResource = (dataAPI, domainUri, userpart) => __awaiter(void 0, void 0,
|
|
76
75
|
});
|
77
76
|
exports.findResource = findResource;
|
78
77
|
const getRoutingDirection = (caller, callee) => {
|
79
|
-
if ((0, exports.isKind)(caller,
|
80
|
-
return types_1.
|
78
|
+
if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.AGENT) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.AGENT)) {
|
79
|
+
return types_1.RoutingDirection.AGENT_TO_AGENT;
|
81
80
|
}
|
82
|
-
if ((0, exports.isKind)(caller,
|
83
|
-
return types_1.
|
81
|
+
if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.AGENT) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.UNKNOWN)) {
|
82
|
+
return types_1.RoutingDirection.AGENT_TO_PSTN;
|
84
83
|
}
|
85
|
-
if ((0, exports.isKind)(caller,
|
86
|
-
return types_1.
|
84
|
+
if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.PEER) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.AGENT)) {
|
85
|
+
return types_1.RoutingDirection.PEER_TO_AGENT;
|
87
86
|
}
|
88
87
|
// All we know is that the Number is managed by this instance of Routr
|
89
|
-
if ((0, exports.isKind)(callee,
|
90
|
-
return types_1.
|
88
|
+
if ((0, exports.isKind)(callee, common_1.CommonConnect.Kind.NUMBER)) {
|
89
|
+
return types_1.RoutingDirection.FROM_PSTN;
|
91
90
|
}
|
92
|
-
if ((0, exports.isKind)(caller,
|
93
|
-
return types_1.
|
91
|
+
if ((0, exports.isKind)(caller, common_1.CommonConnect.Kind.PEER) && (0, exports.isKind)(callee, common_1.CommonConnect.Kind.UNKNOWN)) {
|
92
|
+
return types_1.RoutingDirection.PEER_TO_PSTN;
|
94
93
|
}
|
95
|
-
return types_1.
|
94
|
+
return types_1.RoutingDirection.UNKNOWN;
|
96
95
|
};
|
97
96
|
exports.getRoutingDirection = getRoutingDirection;
|
98
97
|
const createPAssertedIdentity = (req, trunk, number) => {
|
@@ -104,7 +103,7 @@ const createPAssertedIdentity = (req, trunk, number) => {
|
|
104
103
|
value: displayName
|
105
104
|
? `"${displayName}" <sip:${remoteNumber}@${trunkHost};user=phone>`
|
106
105
|
: `<sip:${remoteNumber}@${trunkHost};user=phone>`,
|
107
|
-
action:
|
106
|
+
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
108
107
|
};
|
109
108
|
};
|
110
109
|
exports.createPAssertedIdentity = createPAssertedIdentity;
|
@@ -114,7 +113,7 @@ const createRemotePartyId = (trunk, number) => {
|
|
114
113
|
return {
|
115
114
|
name: "Remote-Party-ID",
|
116
115
|
value: `<sip:${remoteNumber}@${trunkHost}>;screen=yes;party=calling`,
|
117
|
-
action:
|
116
|
+
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
118
117
|
};
|
119
118
|
};
|
120
119
|
exports.createRemotePartyId = createRemotePartyId;
|
@@ -122,9 +121,9 @@ const createTrunkAuthentication = (dataAPI, trunk) => __awaiter(void 0, void 0,
|
|
122
121
|
var _a, _b;
|
123
122
|
const credentials = yield dataAPI.get(trunk.spec.outbound.credentialsRef);
|
124
123
|
return {
|
125
|
-
name:
|
124
|
+
name: common_1.CommonTypes.ExtraHeader.GATEWAY_AUTH,
|
126
125
|
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
|
-
action:
|
126
|
+
action: common_1.CommonTypes.HeaderModifierAction.ADD
|
128
127
|
};
|
129
128
|
});
|
130
129
|
exports.createTrunkAuthentication = createTrunkAuthentication;
|
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.5",
|
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.5",
|
32
|
+
"@routr/location": "^2.0.8-alpha.5",
|
33
|
+
"@routr/processor": "^2.0.8-alpha.5"
|
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": "215638b9d7b56b2db2c2f0bc1bada3b6accbde58"
|
49
49
|
}
|