@routr/connect 2.3.1 → 2.4.1

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/access.js CHANGED
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.checkAccessFromPSTN = exports.checkAgentOrPeerAccess = exports.checkAccess = void 0;
13
13
  /*
14
14
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
15
- * http://github.com/fonoster
15
+ * http://github.com/fonoster/routr
16
16
  *
17
17
  * This file is part of Routr.
18
18
  *
package/dist/envs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.CONNECT_VERIFIER_OPTIONS = exports.CONNECT_VERIFIER_PUBLIC_KEY_PATH = exports.CONNECT_VERIFIER_ADDR = exports.API_ADDR = exports.LOCATION_ADDR = exports.BIND_ADDR = void 0;
5
5
  /*
6
6
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
7
- * http://github.com/fonoster
7
+ * http://github.com/fonoster/routr
8
8
  *
9
9
  * This file is part of Routr.
10
10
  *
@@ -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,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.handleRequest = exports.handleRegistry = exports.handleRegister = void 0;
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
16
16
  *
17
17
  * This file is part of Routr
18
18
  *
19
- * Licensed under the MIT License (the "License")
19
+ * Licensed under the MIT License (the "License");
20
20
  * you may not use this file except in compliance with
21
21
  * the License. You may obtain a copy of the License at
22
22
  *
@@ -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("./utils");
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.sendOk();
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,7 +73,7 @@ const handleRegister = (apiClient, location) => {
77
73
  aor: payload.aor,
78
74
  route: location_1.Helper.createRoute(request)
79
75
  });
80
- res.sendOk();
76
+ res.sendRegisterOk(request);
81
77
  }
82
78
  catch (e) {
83
79
  logger.verbose("unable to validate connect token", {
@@ -92,40 +88,3 @@ const handleRegister = (apiClient, location) => {
92
88
  });
93
89
  };
94
90
  exports.handleRegister = handleRegister;
95
- // TODO: Needs test
96
- const handleRegistry = (req, res) => {
97
- const route = location_1.Helper.createRouteFromLastMessage(req);
98
- 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));
99
- };
100
- exports.handleRegistry = handleRegistry;
101
- const handleRequest = (location, apiClient) => (request, res) => __awaiter(void 0, void 0, void 0, function* () {
102
- try {
103
- const req = common_1.Environment.ENFORCE_E164 ? enforceE164(request) : request;
104
- // Must get the metadata here before the request is forwarded
105
- const route = processor_1.Extensions.getHeaderValue(req, common_1.CommonTypes.ExtraHeader.EDGEPORT_REF)
106
- ? location_1.Helper.createRouteFromLastMessage(req)
107
- : yield (0, router_1.router)(location, apiClient)(req);
108
- if (!route)
109
- return res.sendNotFound();
110
- // If route is not type Route then return
111
- if (!("listeningPoints" in route)) {
112
- return res.send(route);
113
- }
114
- else {
115
- // Forward request to peer edgeport
116
- if (req.edgePortRef !== route.edgePortRef) {
117
- return res.send((0, function_1.pipe)(req, processor_1.Alterations.addSelfVia(route), processor_1.Alterations.addSelfRecordRoute(route),
118
- // The order of the routes is important
119
- processor_1.Alterations.addRouteToPeerEdgePort(route), processor_1.Alterations.addRouteToNextHop(route), processor_1.Alterations.addXEdgePortRef, processor_1.Alterations.decreaseMaxForwards));
120
- }
121
- // TODO: We should add this the Tailor API
122
- req.metadata = route.metadata;
123
- res.send((0, tailor_1.tailor)(route, req));
124
- }
125
- }
126
- catch (err) {
127
- logger.error(err);
128
- res.sendInternalServerError();
129
- }
130
- });
131
- exports.handleRequest = handleRequest;
@@ -0,0 +1,2 @@
1
+ import { MessageRequest, Response } from "@routr/processor";
2
+ export declare const handleRegistry: (req: MessageRequest, res: Response) => void;
@@ -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<Route | Record<string, unknown>>;
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
@@ -14,9 +14,9 @@ exports.router = void 0;
14
14
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/routr
16
16
  *
17
- * This file is part of Routr
17
+ * This file is part of Routr.
18
18
  *
19
- * Licensed under the MIT License (the "License")
19
+ * Licensed under the MIT License (the "License");
20
20
  * you may not use this file except in compliance with
21
21
  * the License. You may obtain a copy of the License at
22
22
  *
@@ -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,35 @@ function router(location, apiClient) {
104
117
  return failedCheck;
105
118
  }
106
119
  }
120
+ const result = (direction, route, extended) => route
121
+ ? {
122
+ direction,
123
+ route: Object.assign(Object.assign({}, route), { metadata: extended })
124
+ }
125
+ : {
126
+ direction,
127
+ route: null
128
+ };
107
129
  // We add metadata to the route object so we can use it later to link to an account
108
130
  switch (routingDirection) {
109
131
  case types_1.RoutingDirection.AGENT_TO_AGENT: {
110
132
  const route = yield agentToAgent(location, request);
111
- return route
112
- ? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
133
+ return result(routingDirection, route, caller.extended);
113
134
  }
114
135
  case types_1.RoutingDirection.AGENT_TO_PEER: {
115
136
  const route = yield agentToPeer(location, callee, request);
116
- return route
117
- ? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
137
+ return result(routingDirection, route, caller.extended);
118
138
  }
119
139
  case types_1.RoutingDirection.AGENT_TO_PSTN: {
120
140
  const route = yield agentToPSTN(request, caller, requestURI.user);
121
- return route
122
- ? Object.assign(Object.assign({}, route), { metadata: caller.extended }) : null;
141
+ return result(routingDirection, route, caller.extended);
123
142
  }
124
143
  case types_1.RoutingDirection.FROM_PSTN: {
125
144
  const route = yield fromPSTN(apiClient, location, callee, request);
126
- return route
127
- ? Object.assign(Object.assign({}, route), { metadata: callee.extended }) : null;
145
+ return result(routingDirection, route, callee.extended);
128
146
  }
129
147
  case types_1.RoutingDirection.PEER_TO_PSTN:
130
- return yield peerToPSTN(apiClient, request);
148
+ return result(routingDirection, yield peerToPSTN(apiClient, request), callee === null || callee === void 0 ? void 0 : callee.extended);
131
149
  default:
132
150
  throw new errors_1.UnsuportedRoutingError(routingDirection);
133
151
  }
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, handlers_1.handleRegistry)(req, res);
75
+ (0, registry_1.handleRegistry)(req, res);
74
76
  }
75
77
  else {
76
- (0, handlers_1.handleRegister)(common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }), location)(req, res);
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, handlers_1.handleRequest)(location, common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }))(req, res);
89
+ (0, request_1.handleRequest)(location, common_2.CommonConnect.apiClient({ apiAddr: config.apiAddr }))(req, res);
88
90
  }
89
91
  }));
90
92
  }
package/dist/tailor.js CHANGED
@@ -7,7 +7,7 @@ exports.tailor = void 0;
7
7
  *
8
8
  * This file is part of Routr
9
9
  *
10
- * Licensed under the MIT License (the "License")
10
+ * Licensed under the MIT License (the "License");
11
11
  * you may not use this file except in compliance with
12
12
  * the License. You may obtain a copy of the License at
13
13
  *
package/dist/tracer.js CHANGED
@@ -10,7 +10,7 @@ exports.init = void 0;
10
10
  *
11
11
  * This file is part of Routr
12
12
  *
13
- * Licensed under the MIT License (the "License")
13
+ * Licensed under the MIT License (the "License");
14
14
  * you may not use this file except in compliance with
15
15
  * the License. You may obtain a copy of the License at
16
16
  *
package/dist/utils.js CHANGED
@@ -42,7 +42,7 @@ exports.getVerifierImpl = exports.hasXConnectObjectHeader = exports.getSIPURI =
42
42
  *
43
43
  * This file is part of Routr
44
44
  *
45
- * Licensed under the MIT License (the "License")
45
+ * Licensed under the MIT License (the "License");
46
46
  * you may not use this file except in compliance with
47
47
  * the License. You may obtain a copy of the License at
48
48
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/connect",
3
- "version": "2.3.1",
3
+ "version": "2.4.1",
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.3.0",
32
- "@routr/location": "^2.3.0",
33
- "@routr/processor": "^2.3.0",
31
+ "@routr/common": "^2.4.1",
32
+ "@routr/location": "^2.4.1",
33
+ "@routr/processor": "^2.4.1",
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": "efa5789d53d7767537ca9c63b2eacd2fcbe7bc01"
52
+ "gitHead": "3897ad320d98a0d17ca7dd552fc0ca7c5a84368d"
53
53
  }