@routr/connect 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/{handlers.d.ts → handlers/register.d.ts} +0 -2
- package/dist/{handlers.js → handlers/register.js} +4 -44
- package/dist/handlers/registry.d.ts +2 -0
- package/dist/handlers/registry.js +30 -0
- package/dist/handlers/request.d.ts +4 -0
- package/dist/handlers/request.js +78 -0
- package/dist/router.d.ts +5 -1
- package/dist/router.js +24 -9
- package/dist/service.js +6 -4
- package/package.json +5 -5
@@ -2,5 +2,3 @@ import { MessageRequest, Response } from "@routr/processor";
|
|
2
2
|
import { ILocationService } from "@routr/location";
|
3
3
|
import { CommonConnect as CC } from "@routr/common";
|
4
4
|
export declare const handleRegister: (apiClient: CC.APIClient, location: ILocationService) => (request: MessageRequest, res: Response) => Promise<void>;
|
5
|
-
export declare const handleRegistry: (req: MessageRequest, res: Response) => void;
|
6
|
-
export declare const handleRequest: (location: ILocationService, apiClient?: CC.APIClient) => (request: MessageRequest, res: Response) => Promise<void>;
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.
|
12
|
+
exports.handleRegister = void 0;
|
13
13
|
/*
|
14
14
|
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
15
15
|
* http://github.com/fonoster/routr
|
@@ -29,15 +29,11 @@ exports.handleRequest = exports.handleRegistry = exports.handleRegister = void 0
|
|
29
29
|
* limitations under the License.
|
30
30
|
*/
|
31
31
|
const location_1 = require("@routr/location");
|
32
|
-
const tailor_1 = require("./tailor");
|
33
32
|
const processor_1 = require("@routr/processor");
|
34
|
-
const function_1 = require("fp-ts/function");
|
35
|
-
const router_1 = require("./router");
|
36
33
|
const common_1 = require("@routr/common");
|
37
|
-
const utils_1 = require("
|
34
|
+
const utils_1 = require("../utils");
|
38
35
|
const logger_1 = require("@fonoster/logger");
|
39
36
|
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
40
|
-
const enforceE164 = processor_1.Alterations.enforceE164(common_1.Environment.ENFORCE_E164, common_1.Environment.ENFORCE_E164_WITH_MOBILE_PREFIX);
|
41
37
|
const jwtVerifier = (0, utils_1.getVerifierImpl)();
|
42
38
|
const handleRegister = (apiClient, location) => {
|
43
39
|
return (request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
@@ -64,7 +60,7 @@ const handleRegister = (apiClient, location) => {
|
|
64
60
|
aor: "aor" in peerOrAgent ? peerOrAgent.aor : processor_1.Target.getTargetAOR(request),
|
65
61
|
route: location_1.Helper.createRoute(request)
|
66
62
|
});
|
67
|
-
res.
|
63
|
+
res.sendRegisterOk(request);
|
68
64
|
}
|
69
65
|
else if ((0, utils_1.hasXConnectObjectHeader)(request)) {
|
70
66
|
const connectToken = processor_1.Extensions.getHeaderValue(request, common_1.CommonTypes.ExtraHeader.CONNECT_TOKEN);
|
@@ -77,6 +73,7 @@ const handleRegister = (apiClient, location) => {
|
|
77
73
|
aor: payload.aor,
|
78
74
|
route: location_1.Helper.createRoute(request)
|
79
75
|
});
|
76
|
+
res.sendRegisterOk(request);
|
80
77
|
}
|
81
78
|
catch (e) {
|
82
79
|
logger.verbose("unable to validate connect token", {
|
@@ -91,40 +88,3 @@ const handleRegister = (apiClient, location) => {
|
|
91
88
|
});
|
92
89
|
};
|
93
90
|
exports.handleRegister = handleRegister;
|
94
|
-
// TODO: Needs test
|
95
|
-
const handleRegistry = (req, res) => {
|
96
|
-
const route = location_1.Helper.createRouteFromLastMessage(req);
|
97
|
-
res.send((0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.decreaseMaxForwards, processor_1.Alterations.removeAuthorization, processor_1.Alterations.removeSelfRoutes, processor_1.Alterations.removeXEdgePortRef));
|
98
|
-
};
|
99
|
-
exports.handleRegistry = handleRegistry;
|
100
|
-
const handleRequest = (location, apiClient) => (request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
101
|
-
try {
|
102
|
-
const req = common_1.Environment.ENFORCE_E164 ? enforceE164(request) : request;
|
103
|
-
// Must get the metadata here before the request is forwarded
|
104
|
-
const route = processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.EDGEPORT_REF)
|
105
|
-
? location_1.Helper.createRouteFromLastMessage(req)
|
106
|
-
: yield (0, router_1.router)(location, apiClient)(req);
|
107
|
-
if (!route)
|
108
|
-
return res.sendNotFound();
|
109
|
-
// If route is not type Route then return
|
110
|
-
if (!("listeningPoints" in route)) {
|
111
|
-
return res.send(route);
|
112
|
-
}
|
113
|
-
else {
|
114
|
-
// Forward request to peer edgeport
|
115
|
-
if (req.edgePortRef !== route.edgePortRef) {
|
116
|
-
return res.send((0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.addSelfRecordRoute(route),
|
117
|
-
// The order of the routes is important
|
118
|
-
processor_1.Alterations.addRouteToPeerEdgePort(route), processor_1.Alterations.addRouteToNextHop(route), processor_1.Alterations.addXEdgePortRef, processor_1.Alterations.decreaseMaxForwards));
|
119
|
-
}
|
120
|
-
// TODO: We should add this the Tailor API
|
121
|
-
req.metadata = route.metadata;
|
122
|
-
res.send((0, tailor_1.tailor)(route, req));
|
123
|
-
}
|
124
|
-
}
|
125
|
-
catch (err) {
|
126
|
-
logger.error(err);
|
127
|
-
res.sendInternalServerError();
|
128
|
-
}
|
129
|
-
});
|
130
|
-
exports.handleRequest = handleRequest;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.handleRegistry = void 0;
|
4
|
+
/*
|
5
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
6
|
+
* http://github.com/fonoster/routr
|
7
|
+
*
|
8
|
+
* This file is part of Routr
|
9
|
+
*
|
10
|
+
* Licensed under the MIT License (the "License")
|
11
|
+
* you may not use this file except in compliance with
|
12
|
+
* the License. You may obtain a copy of the License at
|
13
|
+
*
|
14
|
+
* https://opensource.org/licenses/MIT
|
15
|
+
*
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
+
* See the License for the specific language governing permissions and
|
20
|
+
* limitations under the License.
|
21
|
+
*/
|
22
|
+
const location_1 = require("@routr/location");
|
23
|
+
const processor_1 = require("@routr/processor");
|
24
|
+
const function_1 = require("fp-ts/function");
|
25
|
+
// TODO: Needs test
|
26
|
+
const handleRegistry = (req, res) => {
|
27
|
+
const route = location_1.Helper.createRouteFromLastMessage(req);
|
28
|
+
res.send((0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.decreaseMaxForwards, processor_1.Alterations.removeAuthorization, processor_1.Alterations.removeSelfRoutes, processor_1.Alterations.removeXEdgePortRef));
|
29
|
+
};
|
30
|
+
exports.handleRegistry = handleRegistry;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import { MessageRequest, Response } from "@routr/processor";
|
2
|
+
import { ILocationService } from "@routr/location";
|
3
|
+
import { CommonConnect as CC } from "@routr/common";
|
4
|
+
export declare const handleRequest: (location: ILocationService, apiClient?: CC.APIClient) => (request: MessageRequest, res: Response) => Promise<void>;
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
exports.handleRequest = void 0;
|
13
|
+
/*
|
14
|
+
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
15
|
+
* http://github.com/fonoster/routr
|
16
|
+
*
|
17
|
+
* This file is part of Routr
|
18
|
+
*
|
19
|
+
* Licensed under the MIT License (the "License")
|
20
|
+
* you may not use this file except in compliance with
|
21
|
+
* the License. You may obtain a copy of the License at
|
22
|
+
*
|
23
|
+
* https://opensource.org/licenses/MIT
|
24
|
+
*
|
25
|
+
* Unless required by applicable law or agreed to in writing, software
|
26
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
27
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
28
|
+
* See the License for the specific language governing permissions and
|
29
|
+
* limitations under the License.
|
30
|
+
*/
|
31
|
+
const location_1 = require("@routr/location");
|
32
|
+
const tailor_1 = require("../tailor");
|
33
|
+
const processor_1 = require("@routr/processor");
|
34
|
+
const function_1 = require("fp-ts/function");
|
35
|
+
const router_1 = require("../router");
|
36
|
+
const common_1 = require("@routr/common");
|
37
|
+
const logger_1 = require("@fonoster/logger");
|
38
|
+
const types_1 = require("./../types");
|
39
|
+
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
40
|
+
const enforceE164 = processor_1.Alterations.enforceE164(common_1.Environment.ENFORCE_E164, common_1.Environment.ENFORCE_E164_WITH_MOBILE_PREFIX);
|
41
|
+
const handleRequest = (location, apiClient) => (request, res) => __awaiter(void 0, void 0, void 0, function* () {
|
42
|
+
try {
|
43
|
+
const req = common_1.Environment.ENFORCE_E164 ? enforceE164(request) : request;
|
44
|
+
let route;
|
45
|
+
if (processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.EDGEPORT_REF)) {
|
46
|
+
route = location_1.Helper.createRouteFromLastMessage(req);
|
47
|
+
}
|
48
|
+
else {
|
49
|
+
const routerResult = yield (0, router_1.router)(location, apiClient)(req);
|
50
|
+
const direction = routerResult.direction;
|
51
|
+
route = routerResult.route;
|
52
|
+
// If direction is not present result is an error response
|
53
|
+
if (!("direction" in routerResult)) {
|
54
|
+
return res.send(routerResult);
|
55
|
+
}
|
56
|
+
else if (!route && direction === types_1.RoutingDirection.AGENT_TO_PSTN) {
|
57
|
+
return res.sendNotFound();
|
58
|
+
}
|
59
|
+
else if (!routerResult.route) {
|
60
|
+
return res.sendTemporaryUnavailable();
|
61
|
+
}
|
62
|
+
}
|
63
|
+
// Forward request to peer edgeport
|
64
|
+
if (req.edgePortRef !== route.edgePortRef) {
|
65
|
+
return res.send((0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.addSelfRecordRoute(route),
|
66
|
+
// The order of the routes is important
|
67
|
+
processor_1.Alterations.addRouteToPeerEdgePort(route), processor_1.Alterations.addRouteToNextHop(route), processor_1.Alterations.addXEdgePortRef, processor_1.Alterations.decreaseMaxForwards));
|
68
|
+
}
|
69
|
+
// TODO: We should add this the Tailor API
|
70
|
+
req.metadata = route.metadata;
|
71
|
+
res.send((0, tailor_1.tailor)(route, req));
|
72
|
+
}
|
73
|
+
catch (err) {
|
74
|
+
logger.error(err);
|
75
|
+
res.sendInternalServerError();
|
76
|
+
}
|
77
|
+
});
|
78
|
+
exports.handleRequest = handleRequest;
|
package/dist/router.d.ts
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
+
import { RoutingDirection } from "./types";
|
1
2
|
import { CommonConnect as CC, Route } from "@routr/common";
|
2
3
|
import { MessageRequest } from "@routr/processor";
|
3
4
|
import { ILocationService } from "@routr/location";
|
4
|
-
export declare function router(location: ILocationService, apiClient: CC.APIClient): (request: MessageRequest) => Promise<
|
5
|
+
export declare function router(location: ILocationService, apiClient: CC.APIClient): (request: MessageRequest) => Promise<{
|
6
|
+
route: Route;
|
7
|
+
direction: RoutingDirection;
|
8
|
+
} | Record<string, unknown>>;
|
package/dist/router.js
CHANGED
@@ -70,6 +70,19 @@ function router(location, apiClient) {
|
|
70
70
|
fieldName: "aor",
|
71
71
|
fieldValue: payload.aorLink
|
72
72
|
})).items[0];
|
73
|
+
// Experimental support for Ephemeral Agents when calling agent-to-agent
|
74
|
+
if (!callee) {
|
75
|
+
callee = {
|
76
|
+
apiVersion: common_1.CommonConnect.APIVersion.V2,
|
77
|
+
ref: common_1.CommonTypes.ANONYMOUS,
|
78
|
+
name: common_1.CommonTypes.ANONYMOUS,
|
79
|
+
domain: domain,
|
80
|
+
domainRef: payload.domainRef,
|
81
|
+
username: common_1.CommonTypes.ANONYMOUS,
|
82
|
+
privacy: processor_1.Extensions.getHeaderValue(request, "Privacy"),
|
83
|
+
enabled: true
|
84
|
+
};
|
85
|
+
}
|
73
86
|
}
|
74
87
|
catch (e) {
|
75
88
|
logger.verbose("unable to validate connect token", {
|
@@ -104,30 +117,32 @@ function router(location, apiClient) {
|
|
104
117
|
return failedCheck;
|
105
118
|
}
|
106
119
|
}
|
120
|
+
const result = (direction, route, extended) => {
|
121
|
+
return {
|
122
|
+
direction,
|
123
|
+
route: Object.assign(Object.assign({}, route), { metadata: extended })
|
124
|
+
};
|
125
|
+
};
|
107
126
|
// We add metadata to the route object so we can use it later to link to an account
|
108
127
|
switch (routingDirection) {
|
109
128
|
case types_1.RoutingDirection.AGENT_TO_AGENT: {
|
110
129
|
const route = yield agentToAgent(location, request);
|
111
|
-
return route
|
112
|
-
? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
|
130
|
+
return result(routingDirection, route, caller.extended);
|
113
131
|
}
|
114
132
|
case types_1.RoutingDirection.AGENT_TO_PEER: {
|
115
133
|
const route = yield agentToPeer(location, callee, request);
|
116
|
-
return route
|
117
|
-
? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
|
134
|
+
return result(routingDirection, route, caller.extended);
|
118
135
|
}
|
119
136
|
case types_1.RoutingDirection.AGENT_TO_PSTN: {
|
120
137
|
const route = yield agentToPSTN(request, caller, requestURI.user);
|
121
|
-
return route
|
122
|
-
? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
|
138
|
+
return result(routingDirection, route, caller.extended);
|
123
139
|
}
|
124
140
|
case types_1.RoutingDirection.FROM_PSTN: {
|
125
141
|
const route = yield fromPSTN(apiClient, location, callee, request);
|
126
|
-
return route
|
127
|
-
? Object.assign(Object.assign({}, route), { metadata: callee.extended }) : null;
|
142
|
+
return result(routingDirection, route, callee.extended);
|
128
143
|
}
|
129
144
|
case types_1.RoutingDirection.PEER_TO_PSTN:
|
130
|
-
return yield peerToPSTN(apiClient, request);
|
145
|
+
return result(routingDirection, yield peerToPSTN(apiClient, request), callee === null || callee === void 0 ? void 0 : callee.extended);
|
131
146
|
default:
|
132
147
|
throw new errors_1.UnsuportedRoutingError(routingDirection);
|
133
148
|
}
|
package/dist/service.js
CHANGED
@@ -34,11 +34,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
35
35
|
const common_1 = require("@routr/common");
|
36
36
|
const location_1 = require("@routr/location");
|
37
|
-
const handlers_1 = require("./handlers");
|
38
37
|
const processor_1 = __importStar(require("@routr/processor"));
|
39
38
|
const common_2 = require("@routr/common");
|
40
39
|
const function_1 = require("fp-ts/function");
|
41
40
|
const logger_1 = require("@fonoster/logger");
|
41
|
+
const request_1 = require("./handlers/request");
|
42
|
+
const registry_1 = require("./handlers/registry");
|
43
|
+
const register_1 = require("./handlers/register");
|
42
44
|
const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
|
43
45
|
// eslint-disable-next-line require-jsdoc
|
44
46
|
function connectProcessor(config) {
|
@@ -70,10 +72,10 @@ function connectProcessor(config) {
|
|
70
72
|
break;
|
71
73
|
case common_1.Method.REGISTER:
|
72
74
|
if (processor_1.Extensions.getHeaderValue(req, common_2.CommonTypes.ExtraHeader.GATEWAY_AUTH)) {
|
73
|
-
(0,
|
75
|
+
(0, registry_1.handleRegistry)(req, res);
|
74
76
|
}
|
75
77
|
else {
|
76
|
-
(0,
|
78
|
+
(0, register_1.handleRegister)(common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }), location)(req, res);
|
77
79
|
}
|
78
80
|
break;
|
79
81
|
case common_1.Method.BYE:
|
@@ -84,7 +86,7 @@ function connectProcessor(config) {
|
|
84
86
|
processor_1.Alterations.addSelfViaUsingTheRouteHeaders, processor_1.Alterations.removeSelfRoutes));
|
85
87
|
break;
|
86
88
|
default:
|
87
|
-
(0,
|
89
|
+
(0, request_1.handleRequest)(location, common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }))(req, res);
|
88
90
|
}
|
89
91
|
}));
|
90
92
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@routr/connect",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.4.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.
|
32
|
-
"@routr/location": "^2.
|
33
|
-
"@routr/processor": "^2.
|
31
|
+
"@routr/common": "^2.4.0",
|
32
|
+
"@routr/location": "^2.4.0",
|
33
|
+
"@routr/processor": "^2.4.0",
|
34
34
|
"jsonwebtoken": "^9.0.0"
|
35
35
|
},
|
36
36
|
"devDependencies": {
|
@@ -49,5 +49,5 @@
|
|
49
49
|
"bugs": {
|
50
50
|
"url": "https://github.com/fonoster/routr/issues"
|
51
51
|
},
|
52
|
-
"gitHead": "
|
52
|
+
"gitHead": "704808be190e0fc8b07ceb3d98c15758c5c6c33c"
|
53
53
|
}
|