@routr/common 2.0.8-alpha.9 → 2.0.13

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.
Files changed (103) hide show
  1. package/dist/assertions.js +2 -2
  2. package/dist/auth.d.ts +18 -11
  3. package/dist/auth.js +34 -12
  4. package/dist/connect/api/client.d.ts +3 -0
  5. package/dist/connect/api/client.js +158 -0
  6. package/dist/connect/api/index.d.ts +2 -0
  7. package/dist/connect/api/index.js +36 -0
  8. package/dist/connect/api/types.d.ts +51 -0
  9. package/dist/connect/api/types.js +2 -0
  10. package/dist/connect/assertions.d.ts +37 -0
  11. package/dist/connect/assertions.js +112 -0
  12. package/dist/connect/client.d.ts +8 -0
  13. package/dist/connect/client.js +94 -0
  14. package/dist/connect/config.d.ts +113 -0
  15. package/dist/connect/config.js +2 -0
  16. package/dist/connect/connect_error.d.ts +21 -0
  17. package/dist/connect/connect_error.js +44 -0
  18. package/dist/connect/index.d.ts +7 -2
  19. package/dist/connect/index.js +8 -3
  20. package/dist/connect/mappers/acl.d.ts +3 -0
  21. package/dist/connect/mappers/acl.js +19 -0
  22. package/dist/connect/mappers/agent.d.ts +3 -0
  23. package/dist/connect/mappers/agent.js +42 -0
  24. package/dist/connect/mappers/assertions.d.ts +3 -0
  25. package/dist/connect/mappers/assertions.js +43 -0
  26. package/dist/connect/mappers/credentials.d.ts +3 -0
  27. package/dist/connect/mappers/credentials.js +18 -0
  28. package/dist/connect/mappers/domain.d.ts +3 -0
  29. package/dist/connect/mappers/domain.js +19 -0
  30. package/dist/connect/mappers/index.d.ts +7 -0
  31. package/dist/connect/mappers/index.js +41 -0
  32. package/dist/connect/mappers/number.d.ts +3 -0
  33. package/dist/connect/mappers/number.js +26 -0
  34. package/dist/connect/mappers/peer.d.ts +3 -0
  35. package/dist/connect/mappers/peer.js +26 -0
  36. package/dist/connect/mappers/trunk.d.ts +3 -0
  37. package/dist/connect/mappers/trunk.js +34 -0
  38. package/dist/connect/protos/acl.proto +112 -0
  39. package/dist/connect/protos/agents.proto +153 -0
  40. package/dist/connect/protos/credentials.proto +114 -0
  41. package/dist/connect/protos/domains.proto +146 -0
  42. package/dist/connect/protos/numbers.proto +166 -0
  43. package/dist/connect/protos/peers.proto +174 -0
  44. package/dist/connect/protos/trunks.proto +178 -0
  45. package/dist/connect/schemas/acl.d.ts +66 -0
  46. package/dist/connect/schemas/acl.js +85 -0
  47. package/dist/connect/schemas/agent.d.ts +61 -0
  48. package/dist/connect/schemas/agent.js +80 -0
  49. package/dist/connect/schemas/crendentials.d.ts +59 -0
  50. package/dist/connect/schemas/crendentials.js +78 -0
  51. package/dist/connect/schemas/domain.d.ts +72 -0
  52. package/dist/connect/schemas/domain.js +91 -0
  53. package/dist/connect/schemas/index.d.ts +1 -0
  54. package/dist/connect/schemas/index.js +35 -0
  55. package/dist/connect/schemas/number.d.ts +81 -0
  56. package/dist/connect/schemas/number.js +100 -0
  57. package/dist/connect/schemas/peer.d.ts +84 -0
  58. package/dist/connect/schemas/peer.js +103 -0
  59. package/dist/connect/schemas/trunk.d.ts +125 -0
  60. package/dist/connect/schemas/trunk.js +157 -0
  61. package/dist/connect/schemas/validators.d.ts +2 -0
  62. package/dist/connect/schemas/validators.js +43 -0
  63. package/dist/connect/types.d.ts +89 -23
  64. package/dist/connect/types.js +7 -29
  65. package/dist/connect/validations.d.ts +43 -0
  66. package/dist/connect/validations.js +272 -0
  67. package/dist/envs.d.ts +2 -0
  68. package/dist/envs.js +23 -0
  69. package/dist/errors.d.ts +35 -1
  70. package/dist/errors.js +52 -6
  71. package/dist/healthcheck.d.ts +1 -0
  72. package/dist/healthcheck.js +24 -0
  73. package/dist/helper.d.ts +13 -0
  74. package/dist/helper.js +78 -4
  75. package/dist/index.d.ts +8 -4
  76. package/dist/index.js +9 -6
  77. package/dist/ip_utils.js +1 -1
  78. package/dist/protos/common.proto +2 -4
  79. package/dist/protos/location.proto +21 -8
  80. package/dist/protos/processor.proto +8 -6
  81. package/dist/protos/requester.proto +6 -6
  82. package/dist/protos/sipmessage.proto +9 -2
  83. package/dist/protos/verifier.proto +39 -0
  84. package/dist/requester/grpc_client.js +1 -1
  85. package/dist/requester/index.js +1 -1
  86. package/dist/service.d.ts +2 -2
  87. package/dist/service.js +27 -5
  88. package/dist/tracer.js +1 -1
  89. package/dist/types.d.ts +119 -87
  90. package/dist/types.js +79 -69
  91. package/dist/verifier/grpc_client.d.ts +1 -0
  92. package/dist/{connect → verifier}/grpc_client.js +4 -4
  93. package/dist/verifier/index.d.ts +2 -0
  94. package/dist/verifier/index.js +36 -0
  95. package/dist/verifier/types.d.ts +10 -0
  96. package/dist/verifier/types.js +2 -0
  97. package/dist/verifier/verifier.d.ts +3 -0
  98. package/dist/verifier/verifier.js +64 -0
  99. package/package.json +17 -7
  100. package/dist/connect/data_api.d.ts +0 -11
  101. package/dist/connect/data_api.js +0 -91
  102. package/dist/connect/grpc_client.d.ts +0 -1
  103. package/dist/protos/resources.proto +0 -108
@@ -0,0 +1,272 @@
1
+ "use strict";
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;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isValidE164 = exports.isValidWeight = exports.isValidPriority = exports.isValidContactAddress = exports.isValidHost = exports.hasHost = exports.isValidPort = exports.isValidBalancingAlgorithm = exports.isValidInboundUri = exports.hasInboundUri = exports.hasValidACLRules = exports.isValidACLRule = exports.hasACLRules = exports.hasCountryISOCode = exports.hasCountry = exports.hasCity = exports.isValidAORLink = exports.hasAORLink = exports.isValidAOR = exports.hasAOR = exports.hasValidHeaders = exports.isValidHeader = exports.isValidSessionAffinityHeader = exports.hasTelUrl = exports.isValidDomainUri = exports.hasDomainUri = exports.hasPassword = exports.isValidUsername = exports.hasUsername = exports.isValidName = exports.hasName = exports.hasReference = void 0;
27
+ /*
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster
30
+ *
31
+ * This file is part of Routr.
32
+ *
33
+ * Licensed under the MIT License (the "License");
34
+ * you may not use this file except in compliance with
35
+ * the License. You may obtain a copy of the License at
36
+ *
37
+ * https://opensource.org/licenses/MIT
38
+ *
39
+ * Unless required by applicable law or agreed to in writing, software
40
+ * distributed under the License is distributed on an "AS IS" BASIS,
41
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
+ * See the License for the specific language governing permissions and
43
+ * limitations under the License.
44
+ */
45
+ const Validator = __importStar(require("validator"));
46
+ const errors_1 = require("../errors");
47
+ const types_1 = require("../types");
48
+ const phone_1 = require("phone");
49
+ const hasReference = (ref) => ref ? true : new errors_1.BadRequestError("the reference to the resource is required");
50
+ exports.hasReference = hasReference;
51
+ const hasName = (name) => name
52
+ ? true
53
+ : new errors_1.BadRequestError("the friendly name for the resource is required");
54
+ exports.hasName = hasName;
55
+ const isValidName = (name) => {
56
+ return Validator.default.isLength(name, { min: 1, max: 60 })
57
+ ? true
58
+ : new errors_1.BadRequestError("the friendly name must have less than 60 characters");
59
+ };
60
+ exports.isValidName = isValidName;
61
+ const hasUsername = (username) => username ? true : new errors_1.BadRequestError("the username is required");
62
+ exports.hasUsername = hasUsername;
63
+ const isValidUsername = (username) => {
64
+ if (username &&
65
+ (!Validator.default.isAlphanumeric(username) ||
66
+ !Validator.default.isLowercase(username))) {
67
+ return new errors_1.BadRequestError("the username must be a lowercase, alphanumeric, and without spaces");
68
+ }
69
+ return true;
70
+ };
71
+ exports.isValidUsername = isValidUsername;
72
+ const hasPassword = (password) => password ? true : new errors_1.BadRequestError("the password is required");
73
+ exports.hasPassword = hasPassword;
74
+ const hasDomainUri = (domainUri) => domainUri ? true : new errors_1.BadRequestError("the domainUri is required");
75
+ exports.hasDomainUri = hasDomainUri;
76
+ const isValidDomainUri = (domainUri) => {
77
+ return Validator.default.isFQDN(domainUri)
78
+ ? true
79
+ : new errors_1.BadRequestError("the domainUri must be a valid fully qualified domain name");
80
+ };
81
+ exports.isValidDomainUri = isValidDomainUri;
82
+ const hasTelUrl = (telUrl) => telUrl ? true : new errors_1.BadRequestError("the telUrl is required");
83
+ exports.hasTelUrl = hasTelUrl;
84
+ // Supports alphanumeric, underscore, and dash (cannot end with dash)
85
+ const isValidAlphanumeric = (value) => {
86
+ if (value.endsWith("-")) {
87
+ return false;
88
+ }
89
+ const regex = /^[a-zA-Z0-9-]+$/;
90
+ return regex.test(value);
91
+ };
92
+ const isValidSessionAffinityHeader = (sessionAffinityHeader) => {
93
+ return sessionAffinityHeader
94
+ ? isValidAlphanumeric(sessionAffinityHeader)
95
+ ? true
96
+ : new errors_1.BadRequestError("the sessionAffinityHeader must be alphanumeric and without spaces")
97
+ : true;
98
+ };
99
+ exports.isValidSessionAffinityHeader = isValidSessionAffinityHeader;
100
+ const isValidHeader = (header) => {
101
+ return header
102
+ ? isValidAlphanumeric(header)
103
+ ? true
104
+ : new errors_1.BadRequestError("the header must be alphanumeric and without spaces")
105
+ : true;
106
+ };
107
+ exports.isValidHeader = isValidHeader;
108
+ const hasValidHeaders = (headers) => {
109
+ // eslint-disable-next-line no-loops/no-loops
110
+ for (const header of headers) {
111
+ const E = (0, exports.isValidHeader)(header.name);
112
+ if (!header.value) {
113
+ return new errors_1.BadRequestError("the header value cannot be empty");
114
+ }
115
+ if (E instanceof errors_1.BadRequestError) {
116
+ return E;
117
+ }
118
+ }
119
+ return true;
120
+ };
121
+ exports.hasValidHeaders = hasValidHeaders;
122
+ const hasAOR = (aor) => aor ? true : new errors_1.BadRequestError("the address of record (aor) is required");
123
+ exports.hasAOR = hasAOR;
124
+ const isValidAOR = (aor) => {
125
+ if (aor) {
126
+ if (!aor.startsWith("backend:") && !aor.startsWith("sip:")) {
127
+ return new errors_1.BadRequestError("the aor schema must start with `backend:` or `sip:`");
128
+ }
129
+ }
130
+ return true;
131
+ };
132
+ exports.isValidAOR = isValidAOR;
133
+ const hasAORLink = (aorLink) => aorLink ? true : new errors_1.BadRequestError("the aorLink is required");
134
+ exports.hasAORLink = hasAORLink;
135
+ const isValidAORLink = (aorLink) => {
136
+ if (aorLink) {
137
+ if (!aorLink.startsWith("backend:") && !aorLink.startsWith("sip:")) {
138
+ return new errors_1.BadRequestError("the aorLink must start with backend: or sip:");
139
+ }
140
+ }
141
+ return true;
142
+ };
143
+ exports.isValidAORLink = isValidAORLink;
144
+ const hasCity = (city) => city ? true : new errors_1.BadRequestError("the city is required");
145
+ exports.hasCity = hasCity;
146
+ const hasCountry = (country) => country ? true : new errors_1.BadRequestError("the country is required");
147
+ exports.hasCountry = hasCountry;
148
+ const hasCountryISOCode = (countryIsoCode) => countryIsoCode ? true : new errors_1.BadRequestError("the countryISOCode is required");
149
+ exports.hasCountryISOCode = hasCountryISOCode;
150
+ const hasACLRules = (acl) => {
151
+ var _a, _b;
152
+ if (!(acl === null || acl === void 0 ? void 0 : acl.deny) ||
153
+ !(acl === null || acl === void 0 ? void 0 : acl.allow) ||
154
+ ((_a = acl.deny) === null || _a === void 0 ? void 0 : _a.length) === 0 ||
155
+ ((_b = acl.allow) === null || _b === void 0 ? void 0 : _b.length) === 0) {
156
+ return new errors_1.BadRequestError("acl rules are required");
157
+ }
158
+ return true;
159
+ };
160
+ exports.hasACLRules = hasACLRules;
161
+ const isValidACLRule = (rules) => {
162
+ // eslint-disable-next-line no-loops/no-loops
163
+ for (const cidr of rules) {
164
+ if (!Validator.default.isIPRange(cidr, 4) &&
165
+ !Validator.default.isIP(cidr, 4)) {
166
+ return new errors_1.BadRequestError(`${cidr} is not a valid cidr or ip`);
167
+ }
168
+ }
169
+ return true;
170
+ };
171
+ exports.isValidACLRule = isValidACLRule;
172
+ const hasValidACLRules = (acl) => {
173
+ const deny = (0, exports.isValidACLRule)(acl === null || acl === void 0 ? void 0 : acl.deny);
174
+ if (deny instanceof errors_1.BadRequestError) {
175
+ return deny;
176
+ }
177
+ const allow = (0, exports.isValidACLRule)(acl === null || acl === void 0 ? void 0 : acl.allow);
178
+ if (allow instanceof errors_1.BadRequestError) {
179
+ return allow;
180
+ }
181
+ return true;
182
+ };
183
+ exports.hasValidACLRules = hasValidACLRules;
184
+ const hasInboundUri = (inboundUri) => inboundUri ? true : new errors_1.BadRequestError("the inboundUri is required");
185
+ exports.hasInboundUri = hasInboundUri;
186
+ const isValidInboundUri = (inboundUri) => {
187
+ if (inboundUri && !Validator.default.isFQDN(inboundUri)) {
188
+ return new errors_1.BadRequestError("the inbound URI must be a valid FQDN (e.g. sip.example.com)");
189
+ }
190
+ return true;
191
+ };
192
+ exports.isValidInboundUri = isValidInboundUri;
193
+ const isValidBalancingAlgorithm = (aor, algorithm) => {
194
+ if (aor.startsWith("backend:")) {
195
+ if (!algorithm || algorithm === types_1.LoadBalancingAlgorithm.UNSPECIFIED) {
196
+ return new errors_1.BadRequestError("when the aor schema is `backend:`, the balancing algorithm is required");
197
+ }
198
+ }
199
+ else {
200
+ if (algorithm && algorithm !== types_1.LoadBalancingAlgorithm.UNSPECIFIED) {
201
+ return new errors_1.BadRequestError("when the aor schema is `sip:`, the balancing algorithm is not allowed");
202
+ }
203
+ }
204
+ };
205
+ exports.isValidBalancingAlgorithm = isValidBalancingAlgorithm;
206
+ const isValidPort = (port) => {
207
+ if (port) {
208
+ if (!Validator.default.isPort(port)) {
209
+ return new errors_1.BadRequestError("the port must be a valid port");
210
+ }
211
+ }
212
+ };
213
+ exports.isValidPort = isValidPort;
214
+ const hasHost = (host) => host ? true : new errors_1.BadRequestError("the host is required");
215
+ exports.hasHost = hasHost;
216
+ const isValidHost = (host) => {
217
+ if (host) {
218
+ if (!Validator.default.isFQDN(host) && !Validator.default.isIP(host)) {
219
+ return new errors_1.BadRequestError("the host must be a valid FQDN or IP");
220
+ }
221
+ }
222
+ return true;
223
+ };
224
+ exports.isValidHost = isValidHost;
225
+ const isValidContactAddress = (contactAddress) => {
226
+ if (contactAddress) {
227
+ const hostPart = contactAddress.split(":")[0];
228
+ const portPart = hostPart.split(":")[1] || "5060";
229
+ if (!Validator.default.isFQDN(hostPart) &&
230
+ !Validator.default.isIP(hostPart)) {
231
+ return new errors_1.BadRequestError("the contact address must be a valid FQDN or IP");
232
+ }
233
+ if (!Validator.default.isPort(portPart)) {
234
+ return new errors_1.BadRequestError("the contact port must be a valid port");
235
+ }
236
+ }
237
+ };
238
+ exports.isValidContactAddress = isValidContactAddress;
239
+ const isValidPriority = (priority) => {
240
+ if (priority) {
241
+ if (!Validator.default.isInt(priority)) {
242
+ return new errors_1.BadRequestError("the priority must be a valid integer");
243
+ }
244
+ const p = parseInt(priority);
245
+ if (p < 0 || p > 65535) {
246
+ return new errors_1.BadRequestError("the priority must be between 0 and 65535");
247
+ }
248
+ }
249
+ };
250
+ exports.isValidPriority = isValidPriority;
251
+ const isValidWeight = (weight) => {
252
+ if (weight) {
253
+ if (!Validator.default.isInt(weight)) {
254
+ return new errors_1.BadRequestError("the priority must be a valid integer");
255
+ }
256
+ const w = parseInt(weight);
257
+ if (w < 1 || w > 65535) {
258
+ return new errors_1.BadRequestError("the weight must be between 1 and 65535");
259
+ }
260
+ }
261
+ };
262
+ exports.isValidWeight = isValidWeight;
263
+ const isValidE164 = (e164Number, countryISOCode, validateMobilePrefix = false) => {
264
+ const result = (0, phone_1.phone)(e164Number, {
265
+ country: countryISOCode,
266
+ validateMobilePrefix
267
+ });
268
+ if (!result.isValid) {
269
+ return new errors_1.BadRequestError("the telUrl must be a valid e164 number");
270
+ }
271
+ };
272
+ exports.isValidE164 = isValidE164;
package/dist/envs.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const ENFORCE_E164: boolean;
2
+ export declare const ENFORCE_E164_WITH_MOBILE_PREFIX: boolean;
package/dist/envs.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENFORCE_E164_WITH_MOBILE_PREFIX = exports.ENFORCE_E164 = 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
+ exports.ENFORCE_E164 = process.env.ENFORCE_E164 === "true" ? true : false;
23
+ exports.ENFORCE_E164_WITH_MOBILE_PREFIX = process.env.ENFORCE_E164_WITH_MOBILE_PREFIX === "true" ? true : false;
package/dist/errors.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Error thrown if the definition for a service is not found.
3
3
  */
4
- export declare class ServiceDefinitionNotFound extends Error {
4
+ export declare class ServiceDefinitionNotFoundError extends Error {
5
5
  /**
6
6
  * Constructs a new ServiceDefinitionNotFound error.
7
7
  *
@@ -22,3 +22,37 @@ export declare class ServiceUnavailableError extends Error {
22
22
  */
23
23
  constructor(address: string);
24
24
  }
25
+ /**
26
+ * Thrown for unimplemented handlers.
27
+ */
28
+ export declare class UnimplementedError extends Error {
29
+ code: number;
30
+ /**
31
+ * Creates an instance of UnimplementedError.
32
+ */
33
+ constructor();
34
+ }
35
+ /**
36
+ * Thrown if the resource is not found.
37
+ */
38
+ export declare class ResourceNotFoundError extends Error {
39
+ code: number;
40
+ /**
41
+ * Creates an instance of UnimplementedError.
42
+ *
43
+ * @param {string} ref - the reference of the resource
44
+ */
45
+ constructor(ref: string);
46
+ }
47
+ /**
48
+ * Thrown if the request is invalid.
49
+ */
50
+ export declare class BadRequestError extends Error {
51
+ code: number;
52
+ /**
53
+ * Creates an instance of UnimplementedError.
54
+ *
55
+ * @param {string} message - optional message with the error. Defaults to "bad request."
56
+ */
57
+ constructor(message?: string);
58
+ }
package/dist/errors.js CHANGED
@@ -23,9 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
26
+ exports.BadRequestError = exports.ResourceNotFoundError = exports.UnimplementedError = exports.ServiceUnavailableError = exports.ServiceDefinitionNotFoundError = void 0;
27
27
  /*
28
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
30
30
  *
31
31
  * This file is part of Routr
@@ -46,7 +46,7 @@ const grpc = __importStar(require("@grpc/grpc-js"));
46
46
  /**
47
47
  * Error thrown if the definition for a service is not found.
48
48
  */
49
- class ServiceDefinitionNotFound extends Error {
49
+ class ServiceDefinitionNotFoundError extends Error {
50
50
  /**
51
51
  * Constructs a new ServiceDefinitionNotFound error.
52
52
  *
@@ -54,12 +54,12 @@ class ServiceDefinitionNotFound extends Error {
54
54
  * @param {string} version - The version of the service definition.
55
55
  */
56
56
  constructor(name, version) {
57
- super(`Service definition for ${name}/${version} not found`);
57
+ super(`service definition for ${name}/${version} not found`);
58
58
  // Set the prototype explicitly.
59
- Object.setPrototypeOf(this, ServiceDefinitionNotFound.prototype);
59
+ Object.setPrototypeOf(this, ServiceDefinitionNotFoundError.prototype);
60
60
  }
61
61
  }
62
- exports.ServiceDefinitionNotFound = ServiceDefinitionNotFound;
62
+ exports.ServiceDefinitionNotFoundError = ServiceDefinitionNotFoundError;
63
63
  /**
64
64
  * Error thrown if the service is not available.
65
65
  */
@@ -76,3 +76,49 @@ class ServiceUnavailableError extends Error {
76
76
  }
77
77
  }
78
78
  exports.ServiceUnavailableError = ServiceUnavailableError;
79
+ /**
80
+ * Thrown for unimplemented handlers.
81
+ */
82
+ class UnimplementedError extends Error {
83
+ /**
84
+ * Creates an instance of UnimplementedError.
85
+ */
86
+ constructor() {
87
+ super("this operation is not supported/enabled in this data api implementation.");
88
+ this.code = grpc.status.UNIMPLEMENTED;
89
+ Object.setPrototypeOf(this, UnimplementedError.prototype);
90
+ }
91
+ }
92
+ exports.UnimplementedError = UnimplementedError;
93
+ /**
94
+ * Thrown if the resource is not found.
95
+ */
96
+ class ResourceNotFoundError extends Error {
97
+ /**
98
+ * Creates an instance of UnimplementedError.
99
+ *
100
+ * @param {string} ref - the reference of the resource
101
+ */
102
+ constructor(ref) {
103
+ super(`resource not found: ${ref}`);
104
+ this.code = grpc.status.NOT_FOUND;
105
+ Object.setPrototypeOf(this, ResourceNotFoundError.prototype);
106
+ }
107
+ }
108
+ exports.ResourceNotFoundError = ResourceNotFoundError;
109
+ /**
110
+ * Thrown if the request is invalid.
111
+ */
112
+ class BadRequestError extends Error {
113
+ /**
114
+ * Creates an instance of UnimplementedError.
115
+ *
116
+ * @param {string} message - optional message with the error. Defaults to "bad request."
117
+ */
118
+ constructor(message) {
119
+ super(message !== null && message !== void 0 ? message : "bad request");
120
+ this.code = grpc.status.INVALID_ARGUMENT;
121
+ Object.setPrototypeOf(this, BadRequestError.prototype);
122
+ }
123
+ }
124
+ exports.BadRequestError = BadRequestError;
@@ -0,0 +1 @@
1
+ export declare const check: (address: string) => Promise<void>;
@@ -0,0 +1,24 @@
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;
package/dist/helper.d.ts CHANGED
@@ -14,3 +14,16 @@ export declare const deepCopy: <T>(source: T) => T;
14
14
  * @return {NetInterface} transport The deep copy of the source object.
15
15
  */
16
16
  export declare const getListeningPoint: (listeningPoints: NetInterface[], transport: Transport) => NetInterface;
17
+ /**
18
+ * Reads a file and returns a JSON object or throws an error.
19
+ * The file must be a valid JSON, YAML, or TOML file.
20
+ *
21
+ * @param {string} path - The path to the file.
22
+ * @return {object} The JSON object.
23
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
24
+ * @throws {Error} If the file does not exist.
25
+ * @throws {Error} If the file is not readable.
26
+ * @throws {Error} If the file is empty.
27
+ */
28
+ export declare const readConfigFile: (path: string) => Record<string, any>;
29
+ export declare const toPascaleCase: (str: string) => string;
package/dist/helper.js CHANGED
@@ -1,8 +1,34 @@
1
1
  "use strict";
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;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
2
28
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getListeningPoint = exports.deepCopy = void 0;
29
+ exports.toPascaleCase = exports.readConfigFile = exports.getListeningPoint = exports.deepCopy = void 0;
4
30
  /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
31
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
32
  * http://github.com/fonoster/routr
7
33
  *
8
34
  * This file is part of Routr
@@ -19,6 +45,9 @@ exports.getListeningPoint = exports.deepCopy = void 0;
19
45
  * See the License for the specific language governing permissions and
20
46
  * limitations under the License.
21
47
  */
48
+ const yaml = __importStar(require("js-yaml"));
49
+ const toml = __importStar(require("toml"));
50
+ const fs_1 = __importDefault(require("fs"));
22
51
  const types_1 = require("./types");
23
52
  /**
24
53
  * Makes a deep copy of an object.
@@ -50,11 +79,56 @@ exports.deepCopy = deepCopy;
50
79
  */
51
80
  const getListeningPoint = (listeningPoints, transport) => {
52
81
  const listeningPoint = transport
53
- ? listeningPoints.find((lp) => lp.transport.toLowerCase() === transport.toLowerCase())
54
- : listeningPoints.find((lp) => lp.transport.toLowerCase() === types_1.Transport.UDP);
82
+ ? listeningPoints.find((lp) => lp.transport.toUpperCase() === transport.toUpperCase())
83
+ : listeningPoints.find((lp) => lp.transport.toUpperCase() === types_1.Transport.UDP);
55
84
  if (!listeningPoint) {
56
85
  throw new Error(`no listening point found for transport ${transport}`);
57
86
  }
58
87
  return listeningPoint;
59
88
  };
60
89
  exports.getListeningPoint = getListeningPoint;
90
+ /**
91
+ * Reads a file and returns a JSON object or throws an error.
92
+ * The file must be a valid JSON, YAML, or TOML file.
93
+ *
94
+ * @param {string} path - The path to the file.
95
+ * @return {object} The JSON object.
96
+ * @throws {Error} If the file is not a valid JSON, YAML, or TOML file.
97
+ * @throws {Error} If the file does not exist.
98
+ * @throws {Error} If the file is not readable.
99
+ * @throws {Error} If the file is empty.
100
+ */
101
+ const readConfigFile = (path) => {
102
+ if (!fs_1.default.existsSync(path) || !fs_1.default.statSync(path).isFile()) {
103
+ throw new Error(`config file ${path} does not exist`);
104
+ }
105
+ const content = fs_1.default.readFileSync(path, "utf8");
106
+ try {
107
+ return yaml.load(content);
108
+ }
109
+ catch (e) {
110
+ // Ignore
111
+ }
112
+ // Experimental TOML support
113
+ try {
114
+ return toml.parse(content);
115
+ }
116
+ catch (e) {
117
+ // Ignore
118
+ }
119
+ try {
120
+ return JSON.parse(content);
121
+ }
122
+ catch (e) {
123
+ throw new Error("file is not a valid JSON or YAML file");
124
+ }
125
+ };
126
+ exports.readConfigFile = readConfigFile;
127
+ const toPascaleCase = (str) => {
128
+ return str
129
+ .replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
130
+ return index === 0 ? word.toUpperCase() : word.toUpperCase();
131
+ })
132
+ .replace(/\s+/g, "");
133
+ };
134
+ exports.toPascaleCase = toPascaleCase;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
- import { ServiceUnavailableError } from "./errors";
2
1
  import createService, { getObjectProto, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
3
2
  import { HeaderModifier, MessageRequest, MessageResponse, Method, NetInterface, ObjectProto, ProcessorConfig, Route, ServiceInfo, Transport } from "./types";
4
- export { createService, getObjectProto, HeaderModifier, Route, ServiceUnavailableError, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
3
+ export { createService, getObjectProto, HeaderModifier, Route, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
4
+ export * as Auth from "./auth";
5
5
  export * as Redis from "./redis";
6
- export * as CommonTypes from "./types";
7
6
  export * as Helper from "./helper";
8
7
  export * as IpUtils from "./ip_utils";
9
8
  export * as Tracer from "./tracer";
10
9
  export * as Assertions from "./assertions";
11
10
  export * as CommonConnect from "./connect";
12
11
  export * as CommonRequester from "./requester";
13
- export * as Auth from "./auth";
12
+ export * as CommonTypes from "./types";
13
+ export * as CommonErrors from "./errors";
14
+ export * as ConnectSchemas from "./connect/schemas";
15
+ export * as Environment from "./envs";
16
+ export * as HealthCheck from "./healthcheck";
17
+ export * as Verifier from "./verifier";
package/dist/index.js CHANGED
@@ -23,9 +23,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Auth = exports.CommonRequester = exports.CommonConnect = exports.Assertions = exports.Tracer = exports.IpUtils = exports.Helper = exports.CommonTypes = exports.Redis = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.ServiceUnavailableError = exports.getObjectProto = exports.createService = void 0;
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;
27
27
  /*
28
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
28
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
30
30
  *
31
31
  * This file is part of Routr
@@ -42,8 +42,6 @@ exports.Auth = exports.CommonRequester = exports.CommonConnect = exports.Asserti
42
42
  * See the License for the specific language governing permissions and
43
43
  * limitations under the License.
44
44
  */
45
- const errors_1 = require("./errors");
46
- Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_1.ServiceUnavailableError; } });
47
45
  const service_1 = __importStar(require("./service"));
48
46
  exports.createService = service_1.default;
49
47
  Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
@@ -52,12 +50,17 @@ Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get
52
50
  const types_1 = require("./types");
53
51
  Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return types_1.Method; } });
54
52
  Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return types_1.Transport; } });
53
+ exports.Auth = __importStar(require("./auth"));
55
54
  exports.Redis = __importStar(require("./redis"));
56
- exports.CommonTypes = __importStar(require("./types"));
57
55
  exports.Helper = __importStar(require("./helper"));
58
56
  exports.IpUtils = __importStar(require("./ip_utils"));
59
57
  exports.Tracer = __importStar(require("./tracer"));
60
58
  exports.Assertions = __importStar(require("./assertions"));
61
59
  exports.CommonConnect = __importStar(require("./connect"));
62
60
  exports.CommonRequester = __importStar(require("./requester"));
63
- exports.Auth = __importStar(require("./auth"));
61
+ exports.CommonTypes = __importStar(require("./types"));
62
+ exports.CommonErrors = __importStar(require("./errors"));
63
+ exports.ConnectSchemas = __importStar(require("./connect/schemas"));
64
+ exports.Environment = __importStar(require("./envs"));
65
+ exports.HealthCheck = __importStar(require("./healthcheck"));
66
+ exports.Verifier = __importStar(require("./verifier"));
package/dist/ip_utils.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLocalnetIp = exports.isLocalnet = exports.addressCount = exports.hasIp = exports.formatNet = void 0;
4
4
  /*
5
- * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
7
7
  *
8
8
  * This file is part of Routr