@routr/common 2.0.5-alpha.15 → 2.0.5-alpha.17

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.
@@ -1,3 +1,21 @@
1
+ /*
2
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/routr
4
+ *
5
+ * This file is part of Routr
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
1
19
  syntax = "proto3";
2
20
 
3
21
  package fonoster.routr.processor.v2draft1;
@@ -18,12 +36,34 @@ service Processor {
18
36
 
19
37
  enum Method {
20
38
  UNKNOWN = 0;
39
+ // Communicates user location (host name, IP)
21
40
  REGISTER = 1;
41
+ // Establishes a session
22
42
  INVITE = 2;
43
+ // Transports Instant Messages
23
44
  MESSAGE = 3;
45
+ // Publishes an event to the Server
24
46
  PUBLISH = 4;
47
+ // Notifies the subscriber of a new event
25
48
  NOTIFY = 5;
49
+ // Subscribes for Notification from the notifier
26
50
  SUBSCRIBE = 6;
51
+ // Confirms an INVITE request
52
+ ACK = 7;
53
+ // Terminates a session
54
+ BYE = 8;
55
+ // Cancels establishing of a session
56
+ CANCEL = 9;
57
+ // Communicates information about the capabilities of the calling and receiving SIP phones
58
+ OPTIONS = 10;
59
+ // Provisional Acknowledgement
60
+ PRACK = 11;
61
+ // Sends mid session information
62
+ INFO = 12;
63
+ // Asks the recipient to issue call transfer
64
+ REFER = 13;
65
+ // Modifies the state of a session
66
+ UPDATE = 14;
27
67
  }
28
68
 
29
69
  message NetInterface {
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/routr
4
+ *
5
+ * This file is part of Routr
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ syntax = "proto3";
20
+
21
+ package fonoster.routr.requester.v2draft1;
22
+
23
+ option java_multiple_files = true;
24
+ option java_package = "io.routr.requester";
25
+ option java_outer_classname = "RequesterProto";
26
+ option objc_class_prefix = "RP";
27
+
28
+ import "common.proto";
29
+ import "sipmessage.proto";
30
+ import "processor.proto";
31
+
32
+ // Requester service
33
+ service Requester {
34
+ // Send Message Request
35
+ rpc SendMessage (SendMessageRequest) returns (SendMessageResponse) {}
36
+ }
37
+
38
+ message SendMessageRequest {
39
+ string target = 1;
40
+ fonoster.routr.processor.v2draft1.Method method = 2;
41
+ fonoster.routr.common.v2draft1.Transport transport = 3;
42
+ fonoster.routr.sipmessage.v2draft1.SIPMessage message = 4;
43
+ }
44
+
45
+ message SendMessageResponse {
46
+ fonoster.routr.sipmessage.v2draft1.SIPMessage message = 1;
47
+ }
@@ -0,0 +1,107 @@
1
+ // TODO: Show a link to were this proto was downloaded from
2
+ syntax = "proto3";
3
+
4
+ package fonoster.routr.resources.v2draft1;
5
+
6
+ import "google/protobuf/struct.proto";
7
+
8
+ // Resources service
9
+ service Resources {
10
+ rpc Create (CreateRequest) returns (Resource) {}
11
+ rpc Update (UpdateRequest) returns (Resource) {}
12
+ rpc Get (GetRequest) returns (Resource) {}
13
+ rpc Delete (DeleteRequest) returns (Empty) {}
14
+ rpc List (ListRequest) returns (ListResponse) {}
15
+ rpc FindBy (FindByRequest) returns (FindByResponse) {}
16
+ }
17
+
18
+ message Metadata {
19
+ string ref = 1;
20
+ // The resource's name
21
+ string name = 2;
22
+ // Link to dependencies of this resource
23
+ repeated string depends_on = 3;
24
+ // Created at
25
+ int32 create_time = 4;
26
+ // Updated at
27
+ int32 update_time = 5;
28
+ }
29
+
30
+ message Resource {
31
+ // The resources's metadata
32
+
33
+ // The resource's metadata
34
+ Metadata metadata = 1;
35
+ // The resource's data
36
+ .google.protobuf.Struct spec = 2;
37
+ }
38
+
39
+ message CreateRequest {
40
+ Metadata metadata = 1;
41
+ .google.protobuf.Struct spec = 2;
42
+ }
43
+
44
+ message UpdateRequest {
45
+ Metadata metadata = 1;
46
+ .google.protobuf.Struct spec = 2;
47
+ }
48
+
49
+ message DeleteRequest {
50
+ string ref = 1;
51
+ }
52
+
53
+ message GetRequest {
54
+ string ref = 1;
55
+ }
56
+
57
+ message ListRequest {
58
+ // The maximum number of items in the list
59
+ int32 page_size = 1;
60
+
61
+ // The next_page_token value returned from the previous request, if any
62
+ string page_token = 2;
63
+
64
+ // The filter to apply to the list
65
+ string filter = 3;
66
+
67
+ // The type of resource to list
68
+ string kind = 4;
69
+
70
+ // Level of detail of the individual entities (reserved)
71
+ View view = 5;
72
+ }
73
+
74
+ message ListResponse {
75
+ // List of Resources
76
+ repeated Resource resources = 1;
77
+
78
+ // Token to retrieve the next page of results, or empty if there are no more results in the list
79
+ string next_page_token = 2;
80
+ }
81
+
82
+ message FindByRequest {
83
+ // The type of resource to find
84
+ string kind = 1;
85
+
86
+ // Search criteria for the request
87
+ string criteria = 2;
88
+
89
+ // Parameters to apply in combination with the search criteria
90
+ .google.protobuf.Struct parameters = 3;
91
+
92
+ // Level of detail of the individual entities (reserved)
93
+ View view = 4;
94
+ }
95
+
96
+ message FindByResponse {
97
+ // List of Resources
98
+ repeated Resource resources = 1;
99
+ }
100
+
101
+ enum View {
102
+ BASIC = 0;
103
+ STANDARD = 1;
104
+ FULL = 2;
105
+ }
106
+
107
+ message Empty {}
@@ -1,3 +1,21 @@
1
+ /*
2
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/routr
4
+ *
5
+ * This file is part of Routr
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
1
19
  syntax = "proto3";
2
20
 
3
21
  package fonoster.routr.sipmessage.v2draft1;
@@ -53,7 +71,7 @@ enum ResponseType {
53
71
  BAD_EVENT = 42;
54
72
  REQUEST_PENDING = 43;
55
73
  UNDECIPHERABLE = 44;
56
- SERVER_ERROR =45;
74
+ SERVER_ERROR = 45;
57
75
  SERVER_INTERNAL_ERROR = 46;
58
76
  NOT_IMPLEMENTED = 47;
59
77
  BAD_GATEWAY = 48;
@@ -90,7 +108,8 @@ message Authorization {
90
108
  string response = 8;
91
109
  string username = 9;
92
110
  string uri = 10;
93
- int32 nonce_count = 11;
111
+ string method = 11;
112
+ int32 nonce_count = 12;
94
113
  }
95
114
 
96
115
  message CallID {
@@ -124,23 +143,40 @@ message SipURI {
124
143
  int32 ttl_param = 8;
125
144
  int32 port = 9;
126
145
  bool lr_param = 10;
127
- bool secure = 11;
146
+ bool bnc_param = 11;
147
+ bool secure = 12;
128
148
  }
129
149
 
130
150
  message Address {
131
151
  SipURI uri = 1;
132
- string displayName = 2;
152
+ string display_name = 2;
133
153
  bool wildcard = 3;
134
154
  }
135
155
 
156
+ message MaxForwards {
157
+ int32 max_forwards = 1;
158
+ }
159
+
160
+ message Route {
161
+ Address address = 1;
162
+ map<string, string> parameters = 2;
163
+ }
164
+
165
+ message RecordRoute {
166
+ Address address = 1;
167
+ map<string, string> parameters = 2;
168
+ }
169
+
136
170
  message From {
137
171
  Address address = 1;
138
172
  string tag = 2;
173
+ map<string, string> parameters = 3;
139
174
  }
140
175
 
141
176
  message To {
142
177
  Address address = 1;
143
178
  string tag = 2;
179
+ map<string, string> parameters = 3;
144
180
  }
145
181
 
146
182
  message Contact {
@@ -164,8 +200,11 @@ message SIPMessage {
164
200
  CallID call_id = 6;
165
201
  ContentLength content_length = 7;
166
202
  Expires expires = 8;
167
- repeated Via via = 9;
168
- repeated Extension extensions = 10;
169
- WWWAuthenticate www_authenticate = 11;
170
- Authorization authorization = 12;
203
+ WWWAuthenticate www_authenticate = 9;
204
+ MaxForwards max_forwards = 10;
205
+ Authorization authorization = 11;
206
+ repeated Extension extensions = 12;
207
+ repeated Via via = 13;
208
+ repeated Route route = 14;
209
+ repeated RecordRoute record_route = 15;
171
210
  }
@@ -0,0 +1,8 @@
1
+ export interface RedisStoreConfig {
2
+ username?: string;
3
+ password?: string;
4
+ host: string;
5
+ port: number;
6
+ secure?: boolean;
7
+ }
8
+ export declare const getRedisUrlFromConfig: (config: RedisStoreConfig) => string;
package/dist/redis.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRedisUrlFromConfig = void 0;
4
+ const getRedisUrlFromConfig = (config) => {
5
+ return (`redis${config.secure ? "s" : ""}` +
6
+ `://${config.username ? config.username : ""}` +
7
+ `${config.password ? ":" + config.password + "@" : ""}` +
8
+ `${config.host}:${config.port}`);
9
+ };
10
+ exports.getRedisUrlFromConfig = getRedisUrlFromConfig;
package/dist/service.d.ts CHANGED
@@ -1,6 +1,17 @@
1
1
  import { ObjectProto, ServiceInfo } from "./types";
2
2
  import { ServiceDefinitionNotFound } from "./errors";
3
- export declare const PROCESSOR_OBJECT_PROTO: any;
4
- export declare const LOCATION_OBJECT_PROTO: any;
3
+ export declare const PROCESSOR_OBJECT_PROTO: unknown;
4
+ export declare const LOCATION_OBJECT_PROTO: unknown;
5
+ /**
6
+ * Gets the proto definition for the given object.
7
+ *
8
+ * @param {ObjectProt} objectProto - The object proto to load.
9
+ * @return {A} The proto definition.
10
+ */
5
11
  export declare function getObjectProto<A>(objectProto: ObjectProto): A | ServiceDefinitionNotFound;
12
+ /**
13
+ * Creates a new service using the given service definition.
14
+ *
15
+ * @param {ServiceInfo} serviceInfo - The service info to create the service from.
16
+ */
6
17
  export default function createService(serviceInfo: ServiceInfo): void;
package/dist/service.js CHANGED
@@ -1,13 +1,34 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.getObjectProto = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = void 0;
7
27
  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');
28
+ const grpc = __importStar(require("@grpc/grpc-js"));
29
+ const protoLoader = __importStar(require("@grpc/proto-loader"));
30
+ const logger_1 = require("@fonoster/logger");
31
+ const logger = (0, logger_1.getLogger)({ service: "connect", filePath: __filename });
11
32
  const loadOptions = {
12
33
  keepCase: false,
13
34
  longs: String,
@@ -15,29 +36,43 @@ const loadOptions = {
15
36
  defaults: true,
16
37
  oneofs: true
17
38
  };
39
+ // TODO: Get version from the proto or package
40
+ const API_VERSION = "v2draft1";
18
41
  // We currenly don't have a way to obtain the proto type
19
42
  exports.PROCESSOR_OBJECT_PROTO = getObjectProto({
20
43
  name: "processor",
21
- version: "v2draft1",
22
- path: __dirname + '/protos/processor.proto'
44
+ version: API_VERSION,
45
+ path: __dirname + "/protos/processor.proto"
23
46
  });
24
47
  exports.LOCATION_OBJECT_PROTO = getObjectProto({
25
48
  name: "location",
26
- version: "v2draft1",
27
- path: __dirname + '/protos/location.proto'
49
+ version: API_VERSION,
50
+ path: __dirname + "/protos/location.proto"
28
51
  });
52
+ /**
53
+ * Gets the proto definition for the given object.
54
+ *
55
+ * @param {ObjectProt} objectProto - The object proto to load.
56
+ * @return {A} The proto definition.
57
+ */
29
58
  function getObjectProto(objectProto) {
30
59
  var _a, _b;
31
60
  const definitions = protoLoader.loadSync(objectProto.path, loadOptions);
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
62
  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];
33
- return objProto && objProto[objectProto.version]
63
+ return (objProto === null || objProto === void 0 ? void 0 : objProto[objectProto.version])
34
64
  ? objProto[objectProto.version]
35
65
  : new errors_1.ServiceDefinitionNotFound(objectProto.name, objectProto.version);
36
66
  }
37
67
  exports.getObjectProto = getObjectProto;
68
+ /**
69
+ * Creates a new service using the given service definition.
70
+ *
71
+ * @param {ServiceInfo} serviceInfo - The service info to create the service from.
72
+ */
38
73
  function createService(serviceInfo) {
39
74
  const cb = () => {
40
- logger_1.default.info(`starting routr service`, {
75
+ logger.info("starting routr service", {
41
76
  name: serviceInfo.name,
42
77
  bindAddr: serviceInfo.bindAddr
43
78
  });
package/dist/tracer.d.ts CHANGED
@@ -1 +1,7 @@
1
+ /**
2
+ * This function registers the instrumentations for the service.
3
+ *
4
+ * @param {string} serviceName - The name of the service.
5
+ * @return {Tracer} The tracer object.
6
+ */
1
7
  export declare function init(serviceName: string): import("@opentelemetry/api").Tracer;
package/dist/tracer.js CHANGED
@@ -30,20 +30,24 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
30
30
  const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
31
31
  const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
32
32
  const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
33
+ /**
34
+ * This function registers the instrumentations for the service.
35
+ *
36
+ * @param {string} serviceName - The name of the service.
37
+ * @return {Tracer} The tracer object.
38
+ */
33
39
  function init(serviceName) {
34
40
  const provider = new sdk_trace_node_1.NodeTracerProvider({
35
41
  resource: new resources_1.Resource({
36
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName,
37
- }),
42
+ [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
43
+ })
38
44
  });
39
45
  const exporter = new exporter_jaeger_1.JaegerExporter();
40
46
  provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
41
47
  provider.register();
42
48
  (0, instrumentation_1.registerInstrumentations)({
43
- instrumentations: [
44
- new instrumentation_grpc_1.GrpcInstrumentation(),
45
- ],
49
+ instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
46
50
  });
47
- return api_1.default.trace.getTracer('routr-tracer');
51
+ return api_1.default.trace.getTracer("routr-tracer");
48
52
  }
49
53
  exports.init = init;