@routr/common 2.1.11 → 2.3.0

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.
@@ -48,9 +48,9 @@ const pb_util_1 = require("pb-util");
48
48
  const errors_1 = require("../../errors");
49
49
  const client_1 = require("../client");
50
50
  const types_1 = require("../types");
51
- function fire(err, apiAddr) {
51
+ function fire(err, apiAddr, isSecure) {
52
52
  if (err.code === grpc.status.UNAVAILABLE) {
53
- return new errors_1.ServiceUnavailableError(apiAddr);
53
+ return new errors_1.ClientConnectionError(apiAddr, isSecure);
54
54
  }
55
55
  return err;
56
56
  }
@@ -75,11 +75,13 @@ function serviceAPI(options) {
75
75
  meta.set(key, metadata.getMap()[key]);
76
76
  });
77
77
  }
78
+ const clientCredentials = credentials !== null && credentials !== void 0 ? credentials : grpc.credentials.createInsecure();
78
79
  const client = (0, client_1.createConnectClient)({
79
80
  kind,
80
81
  apiAddr,
81
- credentials: credentials !== null && credentials !== void 0 ? credentials : grpc.credentials.createInsecure()
82
+ credentials: clientCredentials
82
83
  });
84
+ const isSecure = clientCredentials._isSecure();
83
85
  return {
84
86
  create: (request) => new Promise((resolve, reject) => {
85
87
  if (request.extended) {
@@ -87,7 +89,7 @@ function serviceAPI(options) {
87
89
  }
88
90
  client.create(request, meta, (err, response) => {
89
91
  if (err) {
90
- return reject(fire(err, apiAddr));
92
+ return reject(fire(err, apiAddr, isSecure));
91
93
  }
92
94
  if (response.extended) {
93
95
  response.extended = pb_util_1.struct.decode(response.extended);
@@ -101,7 +103,7 @@ function serviceAPI(options) {
101
103
  }
102
104
  client.update(request, meta, (err, response) => {
103
105
  if (err) {
104
- return reject(fire(err, apiAddr));
106
+ return reject(fire(err, apiAddr, isSecure));
105
107
  }
106
108
  if (response.extended) {
107
109
  response.extended = pb_util_1.struct.decode(response.extended);
@@ -112,7 +114,7 @@ function serviceAPI(options) {
112
114
  get: (ref) => new Promise((resolve, reject) => {
113
115
  client.get({ ref }, meta, (err, response) => {
114
116
  if (err) {
115
- return reject(fire(err, apiAddr));
117
+ return reject(fire(err, apiAddr, isSecure));
116
118
  }
117
119
  if (response.extended) {
118
120
  response.extended = pb_util_1.struct.decode(response.extended);
@@ -124,7 +126,7 @@ function serviceAPI(options) {
124
126
  client.list(request, meta, (err, response) => {
125
127
  var _a;
126
128
  if (err) {
127
- return reject(fire(err, apiAddr));
129
+ return reject(fire(err, apiAddr, isSecure));
128
130
  }
129
131
  response.items.forEach((item) => {
130
132
  if (item.extended) {
@@ -140,7 +142,7 @@ function serviceAPI(options) {
140
142
  findBy: (request) => new Promise((resolve, reject) => {
141
143
  client.findBy(request, meta, (err, response) => {
142
144
  if (err) {
143
- return reject(fire(err, apiAddr));
145
+ return reject(fire(err, apiAddr, isSecure));
144
146
  }
145
147
  response.items.forEach((item) => {
146
148
  if (item.extended) {
@@ -151,7 +153,7 @@ function serviceAPI(options) {
151
153
  });
152
154
  }),
153
155
  del: (ref) => new Promise((resolve, reject) => {
154
- client.delete({ ref }, meta, (err) => err ? reject(fire(err, apiAddr)) : resolve());
156
+ client.delete({ ref }, meta, (err) => err ? reject(fire(err, apiAddr, isSecure)) : resolve());
155
157
  })
156
158
  };
157
159
  }
package/dist/errors.d.ts CHANGED
@@ -22,6 +22,17 @@ export declare class ServiceUnavailableError extends Error {
22
22
  */
23
23
  constructor(address: string);
24
24
  }
25
+ /**
26
+ * Error thrown if the client cannot connect to the service.
27
+ */
28
+ export declare class ClientConnectionError extends Error {
29
+ /**
30
+ * Constructs a new ClientConnectionError error.
31
+ * @param {string} address - The address of the service.
32
+ * @param {boolean} isSecure - Whether the connection is secure.
33
+ */
34
+ constructor(address: string, isSecure: boolean);
35
+ }
25
36
  /**
26
37
  * Thrown for unimplemented handlers.
27
38
  */
package/dist/errors.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.BadRequestError = exports.ResourceNotFoundError = exports.UnimplementedError = exports.ServiceUnavailableError = exports.ServiceDefinitionNotFoundError = void 0;
26
+ exports.BadRequestError = exports.ResourceNotFoundError = exports.UnimplementedError = exports.ClientConnectionError = exports.ServiceUnavailableError = exports.ServiceDefinitionNotFoundError = void 0;
27
27
  /*
28
28
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
@@ -76,6 +76,20 @@ class ServiceUnavailableError extends Error {
76
76
  }
77
77
  }
78
78
  exports.ServiceUnavailableError = ServiceUnavailableError;
79
+ /**
80
+ * Error thrown if the client cannot connect to the service.
81
+ */
82
+ class ClientConnectionError extends Error {
83
+ /**
84
+ * Constructs a new ClientConnectionError error.
85
+ * @param {string} address - The address of the service.
86
+ * @param {boolean} isSecure - Whether the connection is secure.
87
+ */
88
+ constructor(address, isSecure) {
89
+ super(`cannot connect to service [service address = ${address}, tlsOn = ${isSecure}]`);
90
+ }
91
+ }
92
+ exports.ClientConnectionError = ClientConnectionError;
79
93
  /**
80
94
  * Thrown for unimplemented handlers.
81
95
  */
package/dist/index.d.ts CHANGED
@@ -13,5 +13,4 @@ export * as CommonTypes from "./types";
13
13
  export * as CommonErrors from "./errors";
14
14
  export * as ConnectSchemas from "./connect/schemas";
15
15
  export * as Environment from "./envs";
16
- export * as HealthCheck from "./healthcheck";
17
16
  export * as Verifier from "./verifier";
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Verifier = exports.HealthCheck = exports.Environment = exports.ConnectSchemas = exports.CommonErrors = exports.CommonTypes = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.Redis = exports.Auth = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.getObjectProto = exports.createService = void 0;
26
+ exports.Verifier = exports.Environment = exports.ConnectSchemas = exports.CommonErrors = exports.CommonTypes = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.Redis = exports.Auth = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.getObjectProto = exports.createService = void 0;
27
27
  /*
28
28
  * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
@@ -62,5 +62,4 @@ exports.CommonTypes = __importStar(require("./types"));
62
62
  exports.CommonErrors = __importStar(require("./errors"));
63
63
  exports.ConnectSchemas = __importStar(require("./connect/schemas"));
64
64
  exports.Environment = __importStar(require("./envs"));
65
- exports.HealthCheck = __importStar(require("./healthcheck"));
66
65
  exports.Verifier = __importStar(require("./verifier"));
@@ -50,7 +50,7 @@ message Route {
50
50
  repeated fonoster.routr.processor.v2beta1.NetInterface listening_points = 9;
51
51
  repeated string localnets = 10;
52
52
  repeated string external_addrs = 11;
53
- // During route creation, an endpoint can request to add labels than can later be
53
+ // During route creation, an endpoint can request to add labels that can later be
54
54
  // used as selectors. For example, a Softphone can add a label `priority=1` to indicate
55
55
  // that it is the preferred endpoint for the given AOR.
56
56
  map<string, string> labels = 12;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.1.11",
3
+ "version": "2.3.0",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -13,7 +13,7 @@
13
13
  "postbuild": "cp -a src/protos dist/protos && cp -a src/connect/protos dist/connect/protos"
14
14
  },
15
15
  "dependencies": {
16
- "@fonoster/grpc-health-check": "^3.1.2",
16
+ "@fonoster/grpc-health-check": "^3.1.3",
17
17
  "@fonoster/logger": "0.3.20",
18
18
  "@grpc/grpc-js": "^1.8.4",
19
19
  "@grpc/proto-loader": "^0.7.2",
@@ -55,5 +55,5 @@
55
55
  "devDependencies": {
56
56
  "@types/js-yaml": "^4.0.5"
57
57
  },
58
- "gitHead": "7c3161336c29feb497a256018a08b65c1dedd0fd"
58
+ "gitHead": "a07009852c37cf04303a5adef42bdac75a747a32"
59
59
  }
@@ -1 +0,0 @@
1
- export declare const check: (address: string) => Promise<void>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.check = void 0;
4
- /*
5
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster
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 grpc_health_check_1 = require("@fonoster/grpc-health-check");
23
- const check = (address) => (0, grpc_health_check_1.checker)("", address);
24
- exports.check = check;