@routr/processor 2.0.5-alpha.3 → 2.0.5-alpha.6

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.
@@ -0,0 +1,5 @@
1
+ import { MessageRequest, Route } from "@routr/common";
2
+ export declare const updateRequestURI: (route: Route) => (request: MessageRequest) => any;
3
+ export declare const addSelfVia: (request: MessageRequest) => MessageRequest;
4
+ export declare const removeTopVia: (request: MessageRequest) => MessageRequest;
5
+ export declare const decreaseMaxForwards: (request: MessageRequest) => MessageRequest;
@@ -0,0 +1,59 @@
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.request_uri.user = route.user;
29
+ }
30
+ else {
31
+ req.message.request_uri.user = null;
32
+ }
33
+ req.message.request_uri.host = route.host;
34
+ req.message.request_uri.port = route.port;
35
+ req.message.request_uri.transport = route.transport;
36
+ return req;
37
+ };
38
+ };
39
+ exports.updateRequestURI = updateRequestURI;
40
+ const addSelfVia = (request) => {
41
+ /*message.via = [...message.via, {
42
+ host: "192.168.1.3",
43
+ port: 5060,
44
+ transport: 'udp'
45
+ }]*/
46
+ return request;
47
+ };
48
+ exports.addSelfVia = addSelfVia;
49
+ const removeTopVia = (request) => {
50
+ const req = common_1.Helper.deepCopy(request);
51
+ req.message.via.shift();
52
+ return req;
53
+ };
54
+ exports.removeTopVia = removeTopVia;
55
+ const decreaseMaxForwards = (request) => extensions_1.updateHeader(request, {
56
+ name: 'Max-Forwards',
57
+ value: (parseInt(extensions_1.getHeaderValue(request, 'Max-Forwards')) - 1) + ''
58
+ });
59
+ 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.message_type === "response_type";
5
+ exports.isTypeResponse = isTypeResponse;
6
+ const isTypeRequest = (request) => !exports.isTypeResponse(request);
7
+ exports.isTypeRequest = isTypeRequest;
package/dist/index.d.ts CHANGED
@@ -2,4 +2,8 @@ import { MessageRequest } from "@routr/common";
2
2
  import Processor from "./processor";
3
3
  import Response from "./response";
4
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";
5
9
  export { Processor as default, MessageRequest, Response, ProcessorConfig };
package/dist/index.js CHANGED
@@ -1,10 +1,33 @@
1
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
+ };
2
21
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
23
  };
5
24
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Response = exports.default = void 0;
25
+ exports.Response = exports.default = exports.Helper = exports.Alterations = exports.Extensions = exports.Target = void 0;
7
26
  const processor_1 = __importDefault(require("./processor"));
8
27
  exports.default = processor_1.default;
9
28
  const response_1 = __importDefault(require("./response"));
10
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"));
@@ -4,6 +4,7 @@ export default class Response {
4
4
  constructor(callback: Function);
5
5
  sendOk(): void;
6
6
  sendMethodNotAllowed(): void;
7
+ sendNotFound(): void;
7
8
  sendNotImplemented(): void;
8
9
  send(message: MessageRequest | Record<string, unknown>): void;
9
10
  sendError(error: any): void;
package/dist/response.js CHANGED
@@ -13,6 +13,9 @@ class Response {
13
13
  sendMethodNotAllowed() {
14
14
  this.callback(null, buildResponse(21));
15
15
  }
16
+ sendNotFound() {
17
+ this.callback(null, buildResponse(20));
18
+ }
16
19
  sendNotImplemented() {
17
20
  this.callback(null, buildResponse(47));
18
21
  }
@@ -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;
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 : request.message.expires.expires;
14
+ };
15
+ exports.getTargetExpires = getTargetExpires;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/processor",
3
- "version": "2.0.5-alpha.3",
3
+ "version": "2.0.5-alpha.6",
4
4
  "description": "Processor server and API",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@fonoster/logger": "^0.3.3",
16
- "@grpc/grpc-js": "^1.5.5",
16
+ "@grpc/grpc-js": "^1.5.9",
17
17
  "@grpc/proto-loader": "^0.6.9",
18
- "@routr/common": "^2.0.5-alpha.3",
18
+ "@routr/common": "^2.0.5-alpha.6",
19
19
  "fp-ts": "^2.11.8"
20
20
  },
21
21
  "directories": {
@@ -35,5 +35,5 @@
35
35
  "bugs": {
36
36
  "url": "https://github.com/fonoster/routr/issues"
37
37
  },
38
- "gitHead": "7d942466133a03f4bcfe0dc100f1a922b3ed14ad"
38
+ "gitHead": "ac4963e735fbc4ad3045379463796137e650509c"
39
39
  }