@routr/common 2.11.5 → 2.12.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.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ <a href="https://gitpod.io/#https://github.com/fonoster/routr"> <img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod" />
2
+
3
+ This module is part of the [Routr](https://routr.io) project. By itself, it does not do much. It is intended to be used as a dependency for other modules. For more information about the project, please visit [https://github.com/fonoster/routr](https://github.com/fonoster/routr).
@@ -24,7 +24,7 @@ export declare const isValidTelUrlOrThrow: (telUrl: string) => void;
24
24
  export declare const isValidSessionAffinityHeaderOrThrow: (sessionAffinityHeader: string) => void;
25
25
  export declare const hasCityOrThrow: (city: string) => void;
26
26
  export declare const hasCountryOrThrow: (country: string) => void;
27
- export declare const hasCountryISOCodeOrThrow: (countryIsoCode: string) => void;
27
+ export declare const hasCountryIsoCodeOrThrow: (countryIsoCode: string) => void;
28
28
  export declare const hasInboundUriOrThrow: (inboundUri: string) => void;
29
29
  export declare const isValidInboundUriOrThrow: (inboundUri: string) => void;
30
30
  export declare const hasAOROrThrow: (aor: string) => void;
@@ -32,5 +32,5 @@ export declare const isValidAOROrThrow: (aor: string) => void;
32
32
  export declare const hasAORLinkOrThrow: (aorLink: string) => void;
33
33
  export declare const isValidAORLinkOrThrow: (aorLink: string) => void;
34
34
  export declare const isValidContactAddressOrThrow: (contactAddress: string) => void;
35
- export declare const isValidE164OrThrow: (e164Number: string, countryISOCode: string, validateMobilePrefix: boolean) => void;
35
+ export declare const isValidE164OrThrow: (e164Number: string, countryIsoCode: string, validateMobilePrefix: boolean) => void;
36
36
  export declare const hasValidOutboundUrisOrThrow: (outboundUris: TrunkURI[]) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hasValidOutboundUrisOrThrow = exports.isValidE164OrThrow = exports.isValidContactAddressOrThrow = exports.isValidAORLinkOrThrow = exports.hasAORLinkOrThrow = exports.isValidAOROrThrow = exports.hasAOROrThrow = exports.isValidInboundUriOrThrow = exports.hasInboundUriOrThrow = exports.hasCountryISOCodeOrThrow = exports.hasCountryOrThrow = exports.hasCityOrThrow = exports.isValidSessionAffinityHeaderOrThrow = exports.isValidTelUrlOrThrow = exports.hasTelUrlOrThrow = exports.isValidDomainUriOrThrow = exports.hasDomainUriOrThrow = exports.hasPasswordOrThrow = exports.isValidUsernameOrThrow = exports.hasUsernameOrThrow = exports.isValidNameOrThrow = exports.hasNameOrThrow = exports.hasRefenceOrThrow = exports.hasValidACLRulesOrThrow = exports.hasACLRulesOrThrow = exports.hasValidHeadersOrThrow = void 0;
3
+ exports.hasValidOutboundUrisOrThrow = exports.isValidE164OrThrow = exports.isValidContactAddressOrThrow = exports.isValidAORLinkOrThrow = exports.hasAORLinkOrThrow = exports.isValidAOROrThrow = exports.hasAOROrThrow = exports.isValidInboundUriOrThrow = exports.hasInboundUriOrThrow = exports.hasCountryIsoCodeOrThrow = exports.hasCountryOrThrow = exports.hasCityOrThrow = exports.isValidSessionAffinityHeaderOrThrow = exports.isValidTelUrlOrThrow = exports.hasTelUrlOrThrow = exports.isValidDomainUriOrThrow = exports.hasDomainUriOrThrow = exports.hasPasswordOrThrow = exports.isValidUsernameOrThrow = exports.hasUsernameOrThrow = exports.isValidNameOrThrow = exports.hasNameOrThrow = exports.hasRefenceOrThrow = exports.hasValidACLRulesOrThrow = exports.hasACLRulesOrThrow = exports.hasValidHeadersOrThrow = void 0;
4
4
  /*
5
5
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
6
  * http://github.com/fonoster/routr
@@ -64,8 +64,8 @@ const hasCityOrThrow = (city) => validOrThrow(validations_1.hasCity, city);
64
64
  exports.hasCityOrThrow = hasCityOrThrow;
65
65
  const hasCountryOrThrow = (country) => validOrThrow(validations_1.hasCountry, country);
66
66
  exports.hasCountryOrThrow = hasCountryOrThrow;
67
- const hasCountryISOCodeOrThrow = (countryIsoCode) => validOrThrow(validations_1.hasCountryISOCode, countryIsoCode);
68
- exports.hasCountryISOCodeOrThrow = hasCountryISOCodeOrThrow;
67
+ const hasCountryIsoCodeOrThrow = (countryIsoCode) => validOrThrow(validations_1.hasCountryIsoCode, countryIsoCode);
68
+ exports.hasCountryIsoCodeOrThrow = hasCountryIsoCodeOrThrow;
69
69
  const hasInboundUriOrThrow = (inboundUri) => validOrThrow(validations_1.hasInboundUri, inboundUri);
70
70
  exports.hasInboundUriOrThrow = hasInboundUriOrThrow;
71
71
  const isValidInboundUriOrThrow = (inboundUri) => validOrThrow(validations_1.isValidInboundUri, inboundUri);
@@ -80,8 +80,8 @@ const isValidAORLinkOrThrow = (aorLink) => validOrThrow(validations_1.isValidAOR
80
80
  exports.isValidAORLinkOrThrow = isValidAORLinkOrThrow;
81
81
  const isValidContactAddressOrThrow = (contactAddress) => validOrThrow(validations_1.isValidContactAddress, contactAddress);
82
82
  exports.isValidContactAddressOrThrow = isValidContactAddressOrThrow;
83
- const isValidE164OrThrow = (e164Number, countryISOCode, validateMobilePrefix) => {
84
- const R = (0, validations_1.isValidE164)(e164Number, countryISOCode, validateMobilePrefix);
83
+ const isValidE164OrThrow = (e164Number, countryIsoCode, validateMobilePrefix) => {
84
+ const R = (0, validations_1.isValidE164)(e164Number, countryIsoCode, validateMobilePrefix);
85
85
  if (R instanceof errors_1.BadRequestError) {
86
86
  throw R;
87
87
  }
@@ -73,7 +73,7 @@ export interface NumberConfig extends Omit<ConfigBase, "metadata"> {
73
73
  geoInfo: {
74
74
  city: string;
75
75
  country: string;
76
- countryISOCode: string;
76
+ countryIsoCode: string;
77
77
  };
78
78
  };
79
79
  spec: {
@@ -15,7 +15,7 @@ function mapToNumber(config) {
15
15
  name: metadata.name,
16
16
  city: metadata.geoInfo.city,
17
17
  country: metadata.geoInfo.country,
18
- countryIsoCode: metadata.geoInfo.countryISOCode,
18
+ countryIsoCode: metadata.geoInfo.countryIsoCode,
19
19
  telUrl: location.telUrl,
20
20
  aorLink: location.aorLink,
21
21
  sessionAffinityHeader: location.sessionAffinityHeader,
@@ -21,7 +21,7 @@ export declare const hasAORLink: (aorLink: string) => true | BadRequestError;
21
21
  export declare const isValidAORLink: (aorLink: string) => true | BadRequestError;
22
22
  export declare const hasCity: (city: string) => true | BadRequestError;
23
23
  export declare const hasCountry: (country: string) => true | BadRequestError;
24
- export declare const hasCountryISOCode: (countryIsoCode: string) => true | BadRequestError;
24
+ export declare const hasCountryIsoCode: (countryIsoCode: string) => true | BadRequestError;
25
25
  export declare const hasACLRules: (acl: {
26
26
  deny: string[];
27
27
  allow: string[];
@@ -39,4 +39,4 @@ export declare const isValidHost: (host: string) => true | BadRequestError;
39
39
  export declare const isValidContactAddress: (contactAddress: string) => BadRequestError;
40
40
  export declare const isValidPriority: (priority: string) => BadRequestError;
41
41
  export declare const isValidWeight: (weight: string) => BadRequestError;
42
- export declare const isValidE164: (e164Number: string, countryISOCode: string, validateMobilePrefix?: boolean) => BadRequestError;
42
+ export declare const isValidE164: (e164Number: string, countryIsoCode: string, validateMobilePrefix?: boolean) => BadRequestError;
@@ -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.isValidE164 = exports.isValidWeight = exports.isValidPriority = exports.isValidContactAddress = exports.isValidHost = exports.hasHost = exports.isValidPort = 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.isValidTelUrl = exports.hasTelUrl = exports.isValidDomainUri = exports.hasDomainUri = exports.hasPassword = exports.isValidUsername = exports.hasUsername = exports.isValidName = exports.hasName = exports.hasReference = void 0;
26
+ exports.isValidE164 = exports.isValidWeight = exports.isValidPriority = exports.isValidContactAddress = exports.isValidHost = exports.hasHost = exports.isValidPort = 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.isValidTelUrl = exports.hasTelUrl = exports.isValidDomainUri = exports.hasDomainUri = exports.hasPassword = exports.isValidUsername = exports.hasUsername = exports.isValidName = exports.hasName = exports.hasReference = void 0;
27
27
  /*
28
28
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
@@ -148,8 +148,8 @@ const hasCity = (city) => city ? true : new errors_1.BadRequestError("the city i
148
148
  exports.hasCity = hasCity;
149
149
  const hasCountry = (country) => country ? true : new errors_1.BadRequestError("the country is required");
150
150
  exports.hasCountry = hasCountry;
151
- const hasCountryISOCode = (countryIsoCode) => countryIsoCode ? true : new errors_1.BadRequestError("the countryISOCode is required");
152
- exports.hasCountryISOCode = hasCountryISOCode;
151
+ const hasCountryIsoCode = (countryIsoCode) => countryIsoCode ? true : new errors_1.BadRequestError("the countryIsoCode is required");
152
+ exports.hasCountryIsoCode = hasCountryIsoCode;
153
153
  const hasACLRules = (acl) => {
154
154
  var _a, _b;
155
155
  if (!(acl === null || acl === void 0 ? void 0 : acl.deny) ||
@@ -187,8 +187,10 @@ exports.hasValidACLRules = hasValidACLRules;
187
187
  const hasInboundUri = (inboundUri) => inboundUri ? true : new errors_1.BadRequestError("the inboundUri is required");
188
188
  exports.hasInboundUri = hasInboundUri;
189
189
  const isValidInboundUri = (inboundUri) => {
190
- if (inboundUri && !Validator.default.isFQDN(inboundUri)) {
191
- return new errors_1.BadRequestError("the inbound URI must be a valid FQDN (e.g. sip.example.com)");
190
+ if (inboundUri &&
191
+ !Validator.default.isFQDN(inboundUri) &&
192
+ !Validator.default.isIP(inboundUri)) {
193
+ return new errors_1.BadRequestError("the inbound URI must be a valid FQDN or IP address (e.g., sip.example.com or 47.132.130.31)");
192
194
  }
193
195
  return true;
194
196
  };
@@ -250,9 +252,9 @@ const isValidWeight = (weight) => {
250
252
  }
251
253
  };
252
254
  exports.isValidWeight = isValidWeight;
253
- const isValidE164 = (e164Number, countryISOCode, validateMobilePrefix = false) => {
255
+ const isValidE164 = (e164Number, countryIsoCode, validateMobilePrefix = false) => {
254
256
  const result = (0, phone_1.phone)(e164Number, {
255
- country: countryISOCode,
257
+ country: countryIsoCode,
256
258
  validateMobilePrefix
257
259
  });
258
260
  if (!result.isValid) {
package/dist/service.js CHANGED
@@ -46,9 +46,8 @@ const grpc = __importStar(require("@grpc/grpc-js"));
46
46
  const protoLoader = __importStar(require("@grpc/proto-loader"));
47
47
  const errors_1 = require("./errors");
48
48
  const logger_1 = require("@fonoster/logger");
49
- const grpc_health_check_1 = require("@fonoster/grpc-health-check");
50
- // eslint-disable-next-line @typescript-eslint/no-var-requires
51
- const interceptor = require("@fonoster/grpc-interceptors");
49
+ const grpc_health_check_1 = require("grpc-health-check");
50
+ const common_1 = require("@fonoster/common");
52
51
  const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
53
52
  const loadOptions = {
54
53
  keepCase: false,
@@ -93,6 +92,7 @@ exports.getObjectProto = getObjectProto;
93
92
  */
94
93
  function createService(serviceInfo) {
95
94
  const cb = () => {
95
+ healthImpl.setStatus("", common_1.GRPC_SERVING_STATUS);
96
96
  logger.info("starting routr service", {
97
97
  name: serviceInfo.name,
98
98
  bindAddr: serviceInfo.bindAddr
@@ -101,7 +101,9 @@ function createService(serviceInfo) {
101
101
  const credentials = grpc.ServerCredentials.createInsecure();
102
102
  const server = new grpc.Server();
103
103
  server.addService(serviceInfo.service, serviceInfo.handlers);
104
- const withHealthChecks = interceptor.serverProxy((0, grpc_health_check_1.useHealth)(server));
105
- withHealthChecks.bindAsync(serviceInfo.bindAddr, credentials, cb);
104
+ const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
105
+ // Add the health check service to the server
106
+ healthImpl.addToServer(server);
107
+ server.bindAsync(serviceInfo.bindAddr, credentials, cb);
106
108
  }
107
109
  exports.default = createService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.11.5",
3
+ "version": "2.12.0",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -13,9 +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.3",
17
- "@fonoster/grpc-interceptors": "^0.2.5",
18
- "@fonoster/logger": "0.3.20",
16
+ "@fonoster/logger": "0.6.0",
19
17
  "@grpc/grpc-js": "~1.10.1",
20
18
  "@grpc/proto-loader": "~0.7.10",
21
19
  "@opentelemetry/api": "^1.0.4",
@@ -28,6 +26,7 @@
28
26
  "@opentelemetry/semantic-conventions": "^1.0.4",
29
27
  "ajv": "^6.12.6",
30
28
  "fp-ts": "^2.11.8",
29
+ "grpc-health-check": "^2.0.2",
31
30
  "ip-utils": "^2.4.0",
32
31
  "js-yaml": "^4.1.0",
33
32
  "pb-util": "^1.0.3",
@@ -55,5 +54,5 @@
55
54
  "devDependencies": {
56
55
  "@types/js-yaml": "^4.0.5"
57
56
  },
58
- "gitHead": "5183aed7ea8b3c0a2a963224ef6068a7922a9e0b"
57
+ "gitHead": "83c134c9ad3f414bdd8c30222ac5be7cdfd13420"
59
58
  }