@routr/common 2.0.3

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,3 @@
1
+ export declare class ServiceDefinitionNotFound extends Error {
2
+ constructor(name: string, version: string);
3
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ServiceDefinitionNotFound = void 0;
19
+ /*
20
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
21
+ * http://github.com/fonoster/routr
22
+ *
23
+ * This file is part of Routr
24
+ *
25
+ * Licensed under the MIT License (the "License")
26
+ * you may not use this file except in compliance with
27
+ * the License. You may obtain a copy of the License at
28
+ *
29
+ * https://opensource.org/licenses/MIT
30
+ *
31
+ * Unless required by applicable law or agreed to in writing, software
32
+ * distributed under the License is distributed on an "AS IS" BASIS,
33
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
+ * See the License for the specific language governing permissions and
35
+ * limitations under the License.
36
+ */
37
+ var ServiceDefinitionNotFound = /** @class */ (function (_super) {
38
+ __extends(ServiceDefinitionNotFound, _super);
39
+ function ServiceDefinitionNotFound(name, version) {
40
+ var _this = _super.call(this, "Service definition for " + name + "/" + version + " not found") || this;
41
+ // Set the prototype explicitly.
42
+ Object.setPrototypeOf(_this, ServiceDefinitionNotFound.prototype);
43
+ return _this;
44
+ }
45
+ return ServiceDefinitionNotFound;
46
+ }(Error));
47
+ exports.ServiceDefinitionNotFound = ServiceDefinitionNotFound;
@@ -0,0 +1,3 @@
1
+ import createService, { PROCESSOR_OBJECT_PROTO, getObjectProto } from "./service";
2
+ import { Transport, ProcessorConfig, MessageRequest, NetInterface, Method, Direction, ObjectProto, ServiceInfo } from "./types";
3
+ export { createService, getObjectProto, Transport, ProcessorConfig, MessageRequest, NetInterface, Method, Direction, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO };
package/dist/index.js ADDED
@@ -0,0 +1,44 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.PROCESSOR_OBJECT_PROTO = exports.getObjectProto = exports.createService = void 0;
23
+ /*
24
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
25
+ * http://github.com/fonoster/routr
26
+ *
27
+ * This file is part of Routr
28
+ *
29
+ * Licensed under the MIT License (the "License")
30
+ * you may not use this file except in compliance with
31
+ * the License. You may obtain a copy of the License at
32
+ *
33
+ * https://opensource.org/licenses/MIT
34
+ *
35
+ * Unless required by applicable law or agreed to in writing, software
36
+ * distributed under the License is distributed on an "AS IS" BASIS,
37
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ * See the License for the specific language governing permissions and
39
+ * limitations under the License.
40
+ */
41
+ var service_1 = __importStar(require("./service"));
42
+ exports.createService = service_1.default;
43
+ Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
44
+ Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
@@ -0,0 +1,5 @@
1
+ import { ObjectProto, ServiceInfo } from "./types";
2
+ import { ServiceDefinitionNotFound } from "./errors";
3
+ export declare const PROCESSOR_OBJECT_PROTO: any;
4
+ export declare function getObjectProto<A>(objectProto: ObjectProto): A | ServiceDefinitionNotFound;
5
+ export default function createService(serviceInfo: ServiceInfo): void;
@@ -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
+ exports.getObjectProto = exports.PROCESSOR_OBJECT_PROTO = void 0;
7
+ var logger_1 = __importDefault(require("@fonoster/logger"));
8
+ var errors_1 = require("./errors");
9
+ var protoLoader = require('@grpc/proto-loader');
10
+ var grpc = require('@grpc/grpc-js');
11
+ var loadOptions = {
12
+ keepCase: true,
13
+ longs: String,
14
+ enums: String,
15
+ defaults: true,
16
+ oneofs: true
17
+ };
18
+ // We currenly don't have a way to obtain the proto type
19
+ exports.PROCESSOR_OBJECT_PROTO = getObjectProto({
20
+ name: "processor",
21
+ version: "v2draft1",
22
+ path: __dirname + '../../../../protos/processor.proto'
23
+ });
24
+ function getObjectProto(objectProto) {
25
+ var _a, _b;
26
+ var definitions = protoLoader.loadSync(objectProto.path, loadOptions);
27
+ var objProto = (_b = (_a = grpc.loadPackageDefinition(definitions)) === null || _a === void 0 ? void 0 : _a.fonoster) === null || _b === void 0 ? void 0 : _b.routr[objectProto.name];
28
+ return objProto && objProto[objectProto.version]
29
+ ? objProto[objectProto.version]
30
+ : new errors_1.ServiceDefinitionNotFound(objectProto.name, objectProto.version);
31
+ }
32
+ exports.getObjectProto = getObjectProto;
33
+ function createService(serviceInfo) {
34
+ var cb = function () {
35
+ logger_1.default.info("starting " + serviceInfo.name + " service at " + serviceInfo.bindAddr);
36
+ server.start();
37
+ };
38
+ var credentials = grpc.ServerCredentials.createInsecure();
39
+ var server = new grpc.Server();
40
+ server.addService(serviceInfo.service, serviceInfo.handlers);
41
+ server.bindAsync(serviceInfo.bindAddr, credentials, cb);
42
+ }
43
+ exports.default = createService;
@@ -0,0 +1,34 @@
1
+ export declare type Direction = 'IN' | 'OUT';
2
+ export declare type Method = 'UNKNOWN' | 'REGISTER' | 'INVITE' | 'MESSAGE' | 'PUBLISH' | 'NOTIFY' | 'SUBSCRIBE';
3
+ export declare type Transport = 'TCP' | 'UDP' | 'TLS' | 'SCTP' | 'WS' | 'WSS';
4
+ export interface NetInterface {
5
+ host: string;
6
+ port: number;
7
+ transport: Transport;
8
+ }
9
+ export interface MessageRequest {
10
+ ref: string;
11
+ direction: Direction;
12
+ method: Method;
13
+ originInterface: NetInterface;
14
+ targetInterface: NetInterface;
15
+ sipMessage: Record<string, unknown>;
16
+ }
17
+ export interface ProcessorConfig {
18
+ ref: string;
19
+ addr: string;
20
+ methods: Array<Method>;
21
+ isFallback?: boolean;
22
+ matchFunc?: (request: MessageRequest) => boolean;
23
+ }
24
+ export interface ServiceInfo {
25
+ name: string;
26
+ bindAddr: string;
27
+ service: unknown;
28
+ handlers: Record<string, (call: unknown, callback: Function) => unknown>;
29
+ }
30
+ export interface ObjectProto {
31
+ name: string;
32
+ path: string;
33
+ version: string;
34
+ }
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,32 @@
1
+ {
2
+ "name": "@routr/common",
3
+ "version": "2.0.3",
4
+ "description": "Common package",
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
+ "directories": {
15
+ "src": "src",
16
+ "test": "test"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/fonoster/routr.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/fonoster/routr/issues"
30
+ },
31
+ "gitHead": "aaacb51da7787d678a89e34a64655fa9a1990364"
32
+ }