@routr/processor 2.0.5-alpha.10

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Fonoster Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ import { MessageRequest, Route } from "@routr/common";
2
+ export declare const updateRequestURI: (route: Route) => (request: MessageRequest) => MessageRequest;
3
+ export declare const addSelfVia: (route: Route) => (request: MessageRequest) => MessageRequest;
4
+ export declare const removeTopVia: (request: MessageRequest) => MessageRequest;
5
+ export declare const decreaseMaxForwards: (request: MessageRequest) => MessageRequest;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decreaseMaxForwards = exports.removeTopVia = exports.addSelfVia = exports.updateRequestURI = void 0;
4
+ /*
5
+ * Copyright (C) 2022 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 common_1 = require("@routr/common");
23
+ const extensions_1 = require("./extensions");
24
+ const updateRequestURI = (route) => {
25
+ return (request) => {
26
+ const req = common_1.Helper.deepCopy(request);
27
+ if (route.user) {
28
+ req.message.requestUri.user = route.user;
29
+ }
30
+ else {
31
+ req.message.requestUri.user = null;
32
+ }
33
+ req.message.requestUri.host = route.host;
34
+ req.message.requestUri.port = route.port;
35
+ req.message.requestUri.transport = route.transport;
36
+ return req;
37
+ };
38
+ };
39
+ exports.updateRequestURI = updateRequestURI;
40
+ const addSelfVia = (route) => {
41
+ return (request) => {
42
+ const req = common_1.Helper.deepCopy(request);
43
+ // If is comming from a different edgeport we the listening point instead
44
+ // of the endpoint to ensure connectivity is possible.
45
+ const nextHopHost = request.edgePortRef === route.edgePortRef
46
+ ? route.host : route.listeningPoint.host;
47
+ // If the nextHopHost host is local, then use use lp to construct via
48
+ // otherwise, we use the first external ip available.
49
+ const via = common_1.IpUtils.isLocalnet(req.localnets, nextHopHost)
50
+ ? req.listeningPoint
51
+ : {
52
+ // fallback to lp host if there is no external ips
53
+ host: req.externalIps[0] || req.listeningPoint.host,
54
+ port: req.listeningPoint.port,
55
+ transport: req.listeningPoint.transport
56
+ };
57
+ req.message.via = [...req.message.via, via];
58
+ return req;
59
+ };
60
+ };
61
+ exports.addSelfVia = addSelfVia;
62
+ const removeTopVia = (request) => {
63
+ const req = common_1.Helper.deepCopy(request);
64
+ req.message.via.shift();
65
+ return req;
66
+ };
67
+ exports.removeTopVia = removeTopVia;
68
+ const decreaseMaxForwards = (request) => extensions_1.updateHeader(request, {
69
+ name: 'Max-Forwards',
70
+ value: (parseInt(extensions_1.getHeaderValue(request, 'Max-Forwards')) - 1) + ''
71
+ });
72
+ exports.decreaseMaxForwards = decreaseMaxForwards;
@@ -0,0 +1,6 @@
1
+ import { MessageRequest } from "@routr/common";
2
+ export declare const getHeaderValue: (request: MessageRequest, name: string) => any;
3
+ export declare const updateHeader: (request: MessageRequest, header: {
4
+ name: string;
5
+ value: string;
6
+ }) => MessageRequest;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateHeader = exports.getHeaderValue = void 0;
4
+ /*
5
+ * Copyright (C) 2022 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 common_1 = require("@routr/common");
23
+ const getHeaderValue = (request, name) => { var _a; return (_a = request.message.extensions.find((ext) => ext.name.toLowerCase() === name.toLowerCase())) === null || _a === void 0 ? void 0 : _a.value; };
24
+ exports.getHeaderValue = getHeaderValue;
25
+ const updateHeader = (request, header) => {
26
+ const r = common_1.Helper.deepCopy(request);
27
+ r.message.extensions = request.message.extensions.map((ext) => {
28
+ return ext.name == header.name ? header : ext;
29
+ });
30
+ return r;
31
+ };
32
+ exports.updateHeader = updateHeader;
@@ -0,0 +1,3 @@
1
+ import { MessageRequest } from "@routr/common";
2
+ export declare const isTypeResponse: (request: MessageRequest) => boolean;
3
+ export declare const isTypeRequest: (request: MessageRequest) => boolean;
package/dist/helper.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTypeRequest = exports.isTypeResponse = void 0;
4
+ const isTypeResponse = (request) => request.message.messageType === "responseType";
5
+ exports.isTypeResponse = isTypeResponse;
6
+ const isTypeRequest = (request) => !exports.isTypeResponse(request);
7
+ exports.isTypeRequest = isTypeRequest;
@@ -0,0 +1,9 @@
1
+ import { MessageRequest } from "@routr/common";
2
+ import Processor from "./processor";
3
+ import Response from "./response";
4
+ import { ProcessorConfig } from "./types";
5
+ export * as Target from "./target";
6
+ export * as Extensions from "./extensions";
7
+ export * as Alterations from "./alterations";
8
+ export * as Helper from "./helper";
9
+ export { Processor as default, MessageRequest, Response, ProcessorConfig };
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.Response = exports.default = exports.Helper = exports.Alterations = exports.Extensions = exports.Target = void 0;
26
+ const processor_1 = __importDefault(require("./processor"));
27
+ exports.default = processor_1.default;
28
+ const response_1 = __importDefault(require("./response"));
29
+ exports.Response = response_1.default;
30
+ exports.Target = __importStar(require("./target"));
31
+ exports.Extensions = __importStar(require("./extensions"));
32
+ exports.Alterations = __importStar(require("./alterations"));
33
+ exports.Helper = __importStar(require("./helper"));
@@ -0,0 +1,9 @@
1
+ import Response from "./response";
2
+ import { ProcessorConfig } from "./types";
3
+ import { MessageRequest } from "@routr/common";
4
+ export default class Processor {
5
+ config: ProcessorConfig;
6
+ serviceInfo: any;
7
+ constructor(config?: ProcessorConfig);
8
+ listen(func: (request: MessageRequest, response: Response) => unknown): void;
9
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ /*
7
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/routr
9
+ *
10
+ * This file is part of Routr
11
+ *
12
+ * Licensed under the MIT License (the "License")
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const response_1 = __importDefault(require("./response"));
25
+ const common_1 = require("@routr/common");
26
+ class Processor {
27
+ constructor(config = { bindAddr: "0.0.0.0:51904", name: "" }) {
28
+ this.config = config;
29
+ }
30
+ listen(func) {
31
+ common_1.createService({
32
+ name: this.config.name,
33
+ bindAddr: this.config.bindAddr,
34
+ service: common_1.PROCESSOR_OBJECT_PROTO.Processor.service,
35
+ handlers: {
36
+ processMessage: (call, callback) => {
37
+ func(call.request, new response_1.default(callback));
38
+ }
39
+ }
40
+ });
41
+ }
42
+ }
43
+ exports.default = Processor;
@@ -0,0 +1,11 @@
1
+ import { MessageRequest } from "@routr/common";
2
+ export default class Response {
3
+ callback: any;
4
+ constructor(callback: Function);
5
+ sendOk(): void;
6
+ sendMethodNotAllowed(): void;
7
+ sendNotFound(): void;
8
+ sendNotImplemented(): void;
9
+ send(message: MessageRequest | Record<string, unknown>): void;
10
+ sendError(error: any): void;
11
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const buildResponse = (code) => {
4
+ return { message: { responseType: code } };
5
+ };
6
+ class Response {
7
+ constructor(callback) {
8
+ this.callback = callback;
9
+ }
10
+ sendOk() {
11
+ this.callback(null, buildResponse(7));
12
+ }
13
+ sendMethodNotAllowed() {
14
+ this.callback(null, buildResponse(21));
15
+ }
16
+ sendNotFound() {
17
+ this.callback(null, buildResponse(20));
18
+ }
19
+ sendNotImplemented() {
20
+ this.callback(null, buildResponse(47));
21
+ }
22
+ send(message) {
23
+ this.callback(null, message);
24
+ }
25
+ sendError(error) {
26
+ this.callback(error, null);
27
+ }
28
+ }
29
+ exports.default = Response;
@@ -0,0 +1,4 @@
1
+ import { MessageRequest } from "@routr/common";
2
+ export declare const getAOR: (uri: any) => string;
3
+ export declare const getTargetAOR: (request: MessageRequest) => string;
4
+ export declare const getTargetExpires: (request: MessageRequest) => number;
package/dist/target.js ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTargetExpires = exports.getTargetAOR = exports.getAOR = void 0;
4
+ const getAOR = (uri) => `${uri.secure ? 'sips' : 'sip'}:${uri.user ? uri.user + '@' : ''}${uri.host}`;
5
+ exports.getAOR = getAOR;
6
+ const getTargetAOR = (request) => exports.getAOR(request.message.to.address.uri);
7
+ exports.getTargetAOR = getTargetAOR;
8
+ const getTargetExpires = (request) => {
9
+ var _a, _b, _c;
10
+ // The expires value in the Contact header takes presendence over the value
11
+ // on the Expires header
12
+ const expires = ((_b = (_a = request.message) === null || _a === void 0 ? void 0 : _a.contact) === null || _b === void 0 ? void 0 : _b.expires) || -1;
13
+ return expires > -1 ? expires : ((_c = request.message.expires) === null || _c === void 0 ? void 0 : _c.expires) || -1;
14
+ };
15
+ exports.getTargetExpires = getTargetExpires;
@@ -0,0 +1,4 @@
1
+ export interface ProcessorConfig {
2
+ bindAddr: string;
3
+ name?: string;
4
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@routr/processor",
3
+ "version": "2.0.5-alpha.10",
4
+ "description": "Processor server and API",
5
+ "author": "Pedro Sanders <psanders@fonoster.com>",
6
+ "homepage": "https://github.com/fonoster/routr#readme",
7
+ "license": "MIT",
8
+ "main": "dist/index",
9
+ "types": "dist/index",
10
+ "scripts": {
11
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
12
+ "build": "tsc -b tsconfig.json"
13
+ },
14
+ "dependencies": {
15
+ "@fonoster/logger": "^0.3.3",
16
+ "@grpc/grpc-js": "^1.5.9",
17
+ "@grpc/proto-loader": "^0.6.9",
18
+ "@routr/common": "^2.0.5-alpha.10",
19
+ "fp-ts": "^2.11.8"
20
+ },
21
+ "directories": {
22
+ "src": "src",
23
+ "test": "test"
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/fonoster/routr.git"
34
+ },
35
+ "bugs": {
36
+ "url": "https://github.com/fonoster/routr/issues"
37
+ },
38
+ "gitHead": "10c6ff135a370a4a4634478fdaf5f42c5c13e28c"
39
+ }