@routr/common 2.0.5-alpha.1 → 2.0.5-alpha.4

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/auth.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { AuthChallengeRequest, AuthChallengeResponse } from "./types";
2
+ export declare const generateNonce: (algorithm?: string) => string;
3
+ export declare const buildAuthChallenge: (request: AuthChallengeRequest) => {
4
+ realm: string;
5
+ scheme: string;
6
+ algorithm: string;
7
+ qop: string;
8
+ opaque: string;
9
+ stale: boolean;
10
+ nonce: string;
11
+ };
12
+ export declare const calculateAuthResponse: (res: AuthChallengeResponse, credentials?: {
13
+ username: string;
14
+ secret: string;
15
+ }) => string;
package/dist/auth.js ADDED
@@ -0,0 +1,29 @@
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.calculateAuthResponse = exports.buildAuthChallenge = exports.generateNonce = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const DEFAULT_ALGORITHM = 'MD5';
9
+ const md5hex = (str, algorithm = DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest('hex');
10
+ const decToHex = (dec) => (dec + Math.pow(16, 8)).toString(16).substr(-8);
11
+ const generateNonce = (algorithm = DEFAULT_ALGORITHM) => md5hex(`${new Date().getTime()}${Math.random()}`, algorithm);
12
+ exports.generateNonce = generateNonce;
13
+ const buildAuthChallenge = (request) => {
14
+ const { realm, scheme, algorithm, qop, opaque, stale } = request;
15
+ return { realm, scheme, algorithm, qop, opaque, stale, nonce: exports.generateNonce(algorithm) };
16
+ };
17
+ exports.buildAuthChallenge = buildAuthChallenge;
18
+ const calculateAuthResponse = (res, credentials) => {
19
+ if (!credentials)
20
+ return null;
21
+ const a1 = `${credentials.username}:${res.realm}:${credentials.secret}`;
22
+ const a2 = `${res.method.toUpperCase()}:${res.uri}`;
23
+ const ha1 = md5hex(a1);
24
+ const ha2 = md5hex(a2);
25
+ return res.qop === 'auth'
26
+ ? md5hex(`${ha1}:${res.nonce}:${decToHex(res.nonce_count)}:${res.c_nonce}:${res.qop}:${ha2}`)
27
+ : md5hex(`${ha1}:${res.nonce}:${ha2}`);
28
+ };
29
+ exports.calculateAuthResponse = calculateAuthResponse;
package/dist/errors.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export declare class ServiceDefinitionNotFound extends Error {
2
2
  constructor(name: string, version: string);
3
3
  }
4
+ export declare class ServiceUnavailableError extends Error {
5
+ code: number;
6
+ constructor(addr: string);
7
+ }
package/dist/errors.js CHANGED
@@ -1,21 +1,6 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ServiceDefinitionNotFound = void 0;
3
+ exports.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
19
4
  /*
20
5
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
21
6
  * http://github.com/fonoster/routr
@@ -34,14 +19,20 @@ exports.ServiceDefinitionNotFound = void 0;
34
19
  * See the License for the specific language governing permissions and
35
20
  * limitations under the License.
36
21
  */
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;
22
+ const grpc = require("@grpc/grpc-js");
23
+ class ServiceDefinitionNotFound extends Error {
24
+ constructor(name, version) {
25
+ super(`Service definition for ${name}/${version} not found`);
41
26
  // Set the prototype explicitly.
42
- Object.setPrototypeOf(_this, ServiceDefinitionNotFound.prototype);
43
- return _this;
27
+ Object.setPrototypeOf(this, ServiceDefinitionNotFound.prototype);
44
28
  }
45
- return ServiceDefinitionNotFound;
46
- }(Error));
29
+ }
47
30
  exports.ServiceDefinitionNotFound = ServiceDefinitionNotFound;
31
+ class ServiceUnavailableError extends Error {
32
+ constructor(addr) {
33
+ super(`service unavailable [addr = ${addr}]`);
34
+ this.code = grpc.status.UNAVAILABLE;
35
+ Object.setPrototypeOf(this, ServiceUnavailableError.prototype);
36
+ }
37
+ }
38
+ exports.ServiceUnavailableError = ServiceUnavailableError;
@@ -0,0 +1 @@
1
+ export declare const deepCopy: <T>(source: T) => T;
package/dist/helper.js ADDED
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepCopy = 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 deepCopy = (source) => {
23
+ return Array.isArray(source)
24
+ ? source.map(item => exports.deepCopy(item))
25
+ : source instanceof Date
26
+ ? new Date(source.getTime())
27
+ : source && typeof source === 'object'
28
+ ? Object.getOwnPropertyNames(source).reduce((o, prop) => {
29
+ Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop));
30
+ o[prop] = exports.deepCopy(source[prop]);
31
+ return o;
32
+ }, Object.create(Object.getPrototypeOf(source)))
33
+ : source;
34
+ };
35
+ exports.deepCopy = deepCopy;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,6 @@
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 };
1
+ import createService, { PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO, getObjectProto } from "./service";
2
+ import { calculateAuthResponse, generateNonce } from "./auth";
3
+ import { ServiceUnavailableError } from "./errors";
4
+ import { Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, Route } from "./types";
5
+ export { createService, getObjectProto, generateNonce, calculateAuthResponse, Route, ServiceUnavailableError, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
6
+ export * as Helper from "./helper";
package/dist/index.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.PROCESSOR_OBJECT_PROTO = exports.getObjectProto = exports.createService = void 0;
22
+ exports.Helper = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.ServiceUnavailableError = exports.calculateAuthResponse = exports.generateNonce = exports.getObjectProto = exports.createService = void 0;
23
23
  /*
24
24
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
25
25
  * http://github.com/fonoster/routr
@@ -38,7 +38,14 @@ exports.PROCESSOR_OBJECT_PROTO = exports.getObjectProto = exports.createService
38
38
  * See the License for the specific language governing permissions and
39
39
  * limitations under the License.
40
40
  */
41
- var service_1 = __importStar(require("./service"));
41
+ const service_1 = __importStar(require("./service"));
42
42
  exports.createService = service_1.default;
43
43
  Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
44
+ Object.defineProperty(exports, "LOCATION_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.LOCATION_OBJECT_PROTO; } });
44
45
  Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
46
+ const auth_1 = require("./auth");
47
+ Object.defineProperty(exports, "calculateAuthResponse", { enumerable: true, get: function () { return auth_1.calculateAuthResponse; } });
48
+ Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function () { return auth_1.generateNonce; } });
49
+ const errors_1 = require("./errors");
50
+ Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_1.ServiceUnavailableError; } });
51
+ exports.Helper = __importStar(require("./helper"));
@@ -0,0 +1,19 @@
1
+ syntax = "proto3";
2
+
3
+ package fonoster.routr.common.v2draft1;
4
+
5
+ option java_multiple_files = true;
6
+ option java_package = "io.routr.common";
7
+ option java_outer_classname = "CommonProto";
8
+ option objc_class_prefix = "CM";
9
+
10
+ enum Transport {
11
+ TCP = 0;
12
+ UDP = 1;
13
+ TLS = 2;
14
+ SCTP = 3;
15
+ WS = 4;
16
+ WSS = 5;
17
+ }
18
+
19
+ message Empty {}
@@ -0,0 +1,56 @@
1
+ syntax = "proto3";
2
+
3
+ package fonoster.routr.location.v2draft1;
4
+
5
+ option java_multiple_files = true;
6
+ option java_package = "io.routr.location";
7
+ option java_outer_classname = "LocationProto";
8
+ option objc_class_prefix = "LC";
9
+
10
+ import "common.proto";
11
+
12
+ service Location {
13
+ rpc AddRoute (AddRouteRequest) returns (fonoster.routr.common.v2draft1.Empty) {}
14
+ rpc FindRoutes (FindRoutesRequest) returns (FindRoutesResponse) {}
15
+ rpc RemoveRoutes (RemoveRoutesRequest) returns (fonoster.routr.common.v2draft1.Empty) {}
16
+ }
17
+
18
+ // A binding create by an actual endpoint (Softphone, PBX, Conference System, etc.)
19
+ message Route {
20
+ string user = 1;
21
+ string host = 2;
22
+ string port = 3;
23
+ fonoster.routr.common.v2draft1.Transport transport = 4;
24
+ int32 registered_on = 5;
25
+ int32 expires = 6;
26
+ int32 session_count = 7;
27
+ string edge_port_ref = 8;
28
+ // During route creation, an endpoint can requet to add labels than can later be
29
+ // used as selector. For example, a Softphone can add a label `priority=1` to indicate
30
+ // that it is the prefer endpoint for the given AOR.
31
+ //
32
+ // Another use case is to use the label to determine which endpoint will back certain
33
+ // feature. For example, we could use the label `backend=voice` to indicate that this
34
+ // route can serve voice applications. If the FindRoutes method includes the label the
35
+ // Location Service will only return routes that includes such label.
36
+ map<string, string> labels = 9;
37
+ }
38
+
39
+ message AddRouteRequest {
40
+ // Address of record for the endpoint or trunk
41
+ string aor = 1;
42
+ Route route = 2;
43
+ }
44
+
45
+ message FindRoutesRequest {
46
+ string aor = 1;
47
+ map<string, string> labels = 2;
48
+ }
49
+
50
+ message FindRoutesResponse {
51
+ repeated Route routes = 1;
52
+ }
53
+
54
+ message RemoveRoutesRequest {
55
+ string aor = 1;
56
+ }
@@ -1,28 +1,19 @@
1
1
  syntax = "proto3";
2
2
 
3
+ package fonoster.routr.processor.v2draft1;
4
+
3
5
  option java_multiple_files = true;
4
- option java_package = "io.routr";
6
+ option java_package = "io.routr.processor";
5
7
  option java_outer_classname = "ProcessorProto";
6
8
  option objc_class_prefix = "PR";
7
9
 
8
- package fonoster.routr.processor.v2draft1;
10
+ import "common.proto";
11
+ import "sipmessage.proto";
9
12
 
10
13
  // Processor service
11
14
  service Processor {
12
15
  // Process Message Request
13
- rpc ProcessMessage (MessageRequest) returns (MessageRequest) {}
14
- }
15
-
16
- // Message process IN or OUT
17
- enum Direction {
18
- IN = 0;
19
- OUT = 1;
20
- }
21
-
22
- // Message process IN or OUT
23
- enum Type {
24
- REQUEST = 0;
25
- RESPONSE = 1;
16
+ rpc ProcessMessage (MessageRequest) returns (MessageResponse) {}
26
17
  }
27
18
 
28
19
  enum Method {
@@ -35,32 +26,24 @@ enum Method {
35
26
  SUBSCRIBE = 6;
36
27
  }
37
28
 
38
- enum Transport {
39
- TCP = 0;
40
- UDP = 1;
41
- TLS = 2;
42
- SCTP = 3;
43
- WS = 4;
44
- WSS = 5;
45
- }
46
-
47
29
  message NetInterface {
48
30
  string host = 1;
49
31
  int32 port = 2;
50
- Transport transport = 3;
51
- }
52
-
53
- message SIPMessage {
54
- string call_id = 1;
32
+ fonoster.routr.common.v2draft1.Transport transport = 3;
55
33
  }
56
34
 
57
35
  message MessageRequest {
36
+ // Same as the Call-Id header
58
37
  string ref = 1;
59
- Type type = 2;
38
+ string edge_port_ref = 2;
60
39
  Method method = 3;
61
- Direction direction = 4;
62
- // .google.protobuf.Struct metadata = 5
63
- NetInterface origin_interface = 6;
64
- NetInterface target_interface = 7;
65
- SIPMessage sip_message = 8;
40
+ NetInterface sender = 4;
41
+ repeated NetInterface external_addrs = 5;
42
+ repeated string localnets = 6;
43
+ fonoster.routr.sipmessage.v2draft1.SIPMessage message = 7;
44
+ // .google.protobuf.Struct metadata = 8;
45
+ }
46
+
47
+ message MessageResponse {
48
+ fonoster.routr.sipmessage.v2draft1.SIPMessage message = 1;
66
49
  }
@@ -0,0 +1,171 @@
1
+ syntax = "proto3";
2
+
3
+ package fonoster.routr.sipmessage.v2draft1;
4
+
5
+ option java_multiple_files = true;
6
+ option java_package = "io.routr.message";
7
+ option java_outer_classname = "SIPMessageProto";
8
+ option objc_class_prefix = "SM";
9
+
10
+ enum ResponseType {
11
+ UNKNOWN = 0;
12
+ TRYING = 1;
13
+ RINGING = 2;
14
+ CALL_IS_BEING_FORWARDED = 3;
15
+ QUEUED = 4;
16
+ SESSION_PROGRESS = 5;
17
+ SUCCESS = 6;
18
+ OK = 7;
19
+ ACCEPTED = 8;
20
+ REDIRECTION = 9;
21
+ MULTIPLE_CHOICES = 10;
22
+ MOVED_PERMANENTLY = 11;
23
+ MOVED_TEMPORARILY = 12;
24
+ USE_PROXY = 13;
25
+ ALTERNATIVE_SERVICE = 14;
26
+ CLIENT_ERROR = 15;
27
+ BAD_REQUEST = 16;
28
+ UNAUTHORIZED = 17;
29
+ PAYMENT_REQUIRED = 18;
30
+ FORBIDDEN = 19;
31
+ NOT_FOUND = 20;
32
+ METHOD_NOT_ALLOWED = 21;
33
+ NOT_ACCEPTABLE = 22;
34
+ PROXY_AUTHENTICATION_REQUIRED = 23;
35
+ REQUEST_TIMEOUT = 24;
36
+ GONE = 25;
37
+ REQUEST_ENTITY_TOO_LARGE = 26;
38
+ REQUEST_URI_TOO_LONG = 27;
39
+ UNSUPPORTED_MEDIA_TYPE = 28;
40
+ UNSUPPORTED_URI_SCHEME = 29;
41
+ BAD_EXTENSION = 30;
42
+ EXTENSION_REQUIRED = 31;
43
+ INTERVAL_TOO_BRIEF = 32;
44
+ TEMPORARILY_UNAVAILABLE = 33;
45
+ CALL_OR_TRANSACTION_DOES_NOT_EXIST = 34;
46
+ LOOP_DETECTED = 35;
47
+ TOO_MANY_HOPS = 36;
48
+ ADDRESS_INCOMPLETE = 37;
49
+ AMBIGUOUS = 38;
50
+ BUSY_HERE = 39;
51
+ REQUEST_TERMINATED = 40;
52
+ NOT_ACCEPTABLE_HERE = 41;
53
+ BAD_EVENT = 42;
54
+ REQUEST_PENDING = 43;
55
+ UNDECIPHERABLE = 44;
56
+ SERVER_ERROR =45;
57
+ SERVER_INTERNAL_ERROR = 46;
58
+ NOT_IMPLEMENTED = 47;
59
+ BAD_GATEWAY = 48;
60
+ SERVICE_UNAVAILABLE = 49;
61
+ SERVER_TIMEOUT = 50;
62
+ VERSION_NOT_SUPPORTED = 51;
63
+ MESSAGE_TOO_LARGE = 52;
64
+ GLOBAL_ERROR = 53;
65
+ BUSY_EVERYWHERE = 54;
66
+ DECLINE = 55;
67
+ DOES_NOT_EXIST_ANYWHERE = 56;
68
+ SESSION_NOT_ACCEPTABLE = 57;
69
+ }
70
+
71
+ message WWWAuthenticate {
72
+ string realm = 1;
73
+ string domain = 2;
74
+ string scheme = 3;
75
+ string nonce = 4;
76
+ string algorithm = 5;
77
+ string qop = 6;
78
+ string opaque = 7;
79
+ bool stale = 8;
80
+ }
81
+
82
+ message Authorization {
83
+ string realm = 1;
84
+ string scheme = 2;
85
+ string c_nonce = 3;
86
+ string nonce = 4;
87
+ string algorithm = 5;
88
+ string qop = 6;
89
+ string opaque = 7;
90
+ string response = 8;
91
+ string username = 9;
92
+ string uri = 10;
93
+ int32 nonce_count = 11;
94
+ }
95
+
96
+ message CallID {
97
+ string call_id = 1;
98
+ }
99
+
100
+ message ContentLength {
101
+ int32 content_length = 1;
102
+ }
103
+
104
+ message Extension {
105
+ string name = 1;
106
+ string value = 2;
107
+ }
108
+
109
+ message Via {
110
+ string host = 1;
111
+ int32 port = 2;
112
+ string branch = 3;
113
+ string transport = 4;
114
+ }
115
+
116
+ message SipURI {
117
+ string user = 1;
118
+ string user_password = 2;
119
+ string host = 3;
120
+ string transport_param = 4;
121
+ string m_addr_param = 5;
122
+ string method_param = 6;
123
+ string user_param = 7;
124
+ int32 t_t_l_param = 8;
125
+ int32 port = 9;
126
+ bool lr_param = 10;
127
+ bool secure = 11;
128
+ }
129
+
130
+ message Address {
131
+ SipURI uri = 1;
132
+ string display_name = 2;
133
+ bool wildcard = 3;
134
+ }
135
+
136
+ message From {
137
+ Address address = 1;
138
+ string tag = 2;
139
+ }
140
+
141
+ message To {
142
+ Address address = 1;
143
+ string tag = 2;
144
+ }
145
+
146
+ message Contact {
147
+ Address address = 1;
148
+ int32 expires = 2;
149
+ float q_value = 3;
150
+ }
151
+
152
+ message Expires {
153
+ int32 expires = 1;
154
+ }
155
+
156
+ message SIPMessage {
157
+ oneof message_type {
158
+ ResponseType response_type = 1;
159
+ SipURI request_uri = 2;
160
+ }
161
+ From from = 3;
162
+ To to = 4;
163
+ Contact contact = 5;
164
+ CallID call_id = 6;
165
+ ContentLength content_length = 7;
166
+ Expires expires = 8;
167
+ repeated Via via = 9;
168
+ repeated Extension extensions = 10;
169
+ WWWAuthenticate www_authenticate = 11;
170
+ Authorization authorization = 12;
171
+ }
package/dist/service.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ObjectProto, ServiceInfo } from "./types";
2
2
  import { ServiceDefinitionNotFound } from "./errors";
3
3
  export declare const PROCESSOR_OBJECT_PROTO: any;
4
+ export declare const LOCATION_OBJECT_PROTO: any;
4
5
  export declare function getObjectProto<A>(objectProto: ObjectProto): A | ServiceDefinitionNotFound;
5
6
  export default function createService(serviceInfo: ServiceInfo): void;
package/dist/service.js CHANGED
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getObjectProto = exports.PROCESSOR_OBJECT_PROTO = void 0;
7
- var errors_1 = require("./errors");
8
- var logger_1 = __importDefault(require("@fonoster/logger"));
9
- var protoLoader = require('@grpc/proto-loader');
10
- var grpc = require('@grpc/grpc-js');
11
- var loadOptions = {
6
+ exports.getObjectProto = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = void 0;
7
+ const errors_1 = require("./errors");
8
+ const logger_1 = __importDefault(require("@fonoster/logger"));
9
+ const protoLoader = require('@grpc/proto-loader');
10
+ const grpc = require('@grpc/grpc-js');
11
+ const loadOptions = {
12
12
  keepCase: true,
13
13
  longs: String,
14
14
  enums: String,
@@ -21,22 +21,27 @@ exports.PROCESSOR_OBJECT_PROTO = getObjectProto({
21
21
  version: "v2draft1",
22
22
  path: __dirname + '/protos/processor.proto'
23
23
  });
24
+ exports.LOCATION_OBJECT_PROTO = getObjectProto({
25
+ name: "location",
26
+ version: "v2draft1",
27
+ path: __dirname + '/protos/location.proto'
28
+ });
24
29
  function getObjectProto(objectProto) {
25
30
  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];
31
+ const definitions = protoLoader.loadSync(objectProto.path, loadOptions);
32
+ const 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
33
  return objProto && objProto[objectProto.version]
29
34
  ? objProto[objectProto.version]
30
35
  : new errors_1.ServiceDefinitionNotFound(objectProto.name, objectProto.version);
31
36
  }
32
37
  exports.getObjectProto = getObjectProto;
33
38
  function createService(serviceInfo) {
34
- var cb = function () {
35
- logger_1.default.info("starting " + serviceInfo.name + " service at " + serviceInfo.bindAddr);
39
+ const cb = () => {
40
+ logger_1.default.info(`starting ${serviceInfo.name} service @ ${serviceInfo.bindAddr}`);
36
41
  server.start();
37
42
  };
38
- var credentials = grpc.ServerCredentials.createInsecure();
39
- var server = new grpc.Server();
43
+ const credentials = grpc.ServerCredentials.createInsecure();
44
+ const server = new grpc.Server();
40
45
  server.addService(serviceInfo.service, serviceInfo.handlers);
41
46
  server.bindAsync(serviceInfo.bindAddr, credentials, cb);
42
47
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export declare type Direction = 'IN' | 'OUT';
2
1
  export declare type Method = 'UNKNOWN' | 'REGISTER' | 'INVITE' | 'MESSAGE' | 'PUBLISH' | 'NOTIFY' | 'SUBSCRIBE';
3
2
  export declare type Transport = 'TCP' | 'UDP' | 'TLS' | 'SCTP' | 'WS' | 'WSS';
4
3
  export interface NetInterface {
@@ -8,11 +7,15 @@ export interface NetInterface {
8
7
  }
9
8
  export interface MessageRequest {
10
9
  ref: string;
11
- direction: Direction;
10
+ edge_port_ref: string;
12
11
  method: Method;
13
- originInterface: NetInterface;
14
- targetInterface: NetInterface;
15
- sipMessage: Record<string, unknown>;
12
+ sender: NetInterface;
13
+ external_addrs: NetInterface[];
14
+ localnets: string[];
15
+ message: Record<string, unknown>;
16
+ }
17
+ export interface MessageResponse {
18
+ message: Record<string, unknown>;
16
19
  }
17
20
  export interface ProcessorConfig {
18
21
  ref: string;
@@ -21,6 +24,10 @@ export interface ProcessorConfig {
21
24
  isFallback?: boolean;
22
25
  matchFunc?: (request: MessageRequest) => boolean;
23
26
  }
27
+ export interface MiddlewareConfig {
28
+ ref: string;
29
+ addr: string;
30
+ }
24
31
  export interface ServiceInfo {
25
32
  name: string;
26
33
  bindAddr: string;
@@ -32,3 +39,40 @@ export interface ObjectProto {
32
39
  path: string;
33
40
  version: string;
34
41
  }
42
+ export interface AuthChallengeRequest {
43
+ realm: string;
44
+ domain: string;
45
+ scheme: string;
46
+ nonce: string;
47
+ algorithm: string;
48
+ qop: string;
49
+ opaque: string;
50
+ stale: boolean;
51
+ }
52
+ export interface AuthChallengeResponse {
53
+ realm: string;
54
+ domain: string;
55
+ scheme: string;
56
+ c_nonce: string;
57
+ nonce_count: number;
58
+ response: string;
59
+ username: string;
60
+ nonce: string;
61
+ algorithm: string;
62
+ qop: string;
63
+ opaque: string;
64
+ stale: boolean;
65
+ uri: string;
66
+ method: string;
67
+ }
68
+ export interface Route {
69
+ user: string;
70
+ host: string;
71
+ port: number;
72
+ transport: string;
73
+ registeredOn: number;
74
+ sessionCount?: number;
75
+ expires: number;
76
+ edgePortRef: string;
77
+ labels?: Map<string, string>;
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.0.5-alpha.1",
3
+ "version": "2.0.5-alpha.4",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -14,8 +14,9 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@fonoster/logger": "^0.3.3",
17
- "@grpc/grpc-js": "^1.5.5",
18
- "@grpc/proto-loader": "^0.6.9"
17
+ "@grpc/grpc-js": "^1.5.9",
18
+ "@grpc/proto-loader": "^0.6.9",
19
+ "fp-ts": "^2.11.8"
19
20
  },
20
21
  "directories": {
21
22
  "src": "src",
@@ -34,5 +35,5 @@
34
35
  "bugs": {
35
36
  "url": "https://github.com/fonoster/routr/issues"
36
37
  },
37
- "gitHead": "12ed1225fc28e8dfed240522319d8f8178620586"
38
+ "gitHead": "822b26227df5873d60b9c5c4ca69b884f6df5722"
38
39
  }