@routr/common 2.12.1 → 2.13.1

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,5 +1,4 @@
1
1
  import * as grpc from "@grpc/grpc-js";
2
- import { JsonObject } from "pb-util/build";
3
2
  import { AccessControlList, Agent, Credentials, Domain, INumber, Kind, Peer, Trunk } from "../types";
4
3
  export interface DataAPIOptions {
5
4
  apiAddr: string;
@@ -37,7 +36,7 @@ export type APIClient = {
37
36
  numbers: ServiceAPI<INumber>;
38
37
  };
39
38
  export type ServiceAPI<R extends {
40
- extended?: JsonObject;
39
+ extended?: Record<string, unknown>;
41
40
  }> = {
42
41
  create: (request: unknown) => Promise<R>;
43
42
  update: (request: unknown) => Promise<R>;
@@ -11,7 +11,7 @@ export declare const hasValidACLRulesOrThrow: (acl: {
11
11
  deny: string[];
12
12
  allow: string[];
13
13
  }) => void;
14
- export declare const hasRefenceOrThrow: (ref: string) => void;
14
+ export declare const hasReferenceOrThrow: (ref: string) => void;
15
15
  export declare const hasNameOrThrow: (name: string) => void;
16
16
  export declare const isValidNameOrThrow: (name: string) => void;
17
17
  export declare const hasUsernameOrThrow: (username: string) => 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.hasReferenceOrThrow = 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
@@ -38,8 +38,8 @@ const hasACLRulesOrThrow = (acl) => validOrThrow(validations_1.hasACLRules, acl)
38
38
  exports.hasACLRulesOrThrow = hasACLRulesOrThrow;
39
39
  const hasValidACLRulesOrThrow = (acl) => validOrThrow(validations_1.hasValidACLRules, acl);
40
40
  exports.hasValidACLRulesOrThrow = hasValidACLRulesOrThrow;
41
- const hasRefenceOrThrow = (ref) => validOrThrow(validations_1.hasReference, ref);
42
- exports.hasRefenceOrThrow = hasRefenceOrThrow;
41
+ const hasReferenceOrThrow = (ref) => validOrThrow(validations_1.hasReference, ref);
42
+ exports.hasReferenceOrThrow = hasReferenceOrThrow;
43
43
  const hasNameOrThrow = (name) => validOrThrow(validations_1.hasName, name);
44
44
  exports.hasNameOrThrow = hasNameOrThrow;
45
45
  const isValidNameOrThrow = (name) => validOrThrow(validations_1.isValidName, name);
@@ -47,13 +47,7 @@ const grpc = __importStar(require("@grpc/grpc-js"));
47
47
  const helper_1 = require("../helper");
48
48
  const types_1 = require("./types");
49
49
  const protoLoader = require("@grpc/proto-loader");
50
- const protoOptions = {
51
- keepCase: false,
52
- longs: String,
53
- enums: String,
54
- defaults: true,
55
- oneofs: true
56
- };
50
+ const service_1 = require("../service");
57
51
  function getProtoPath(kind) {
58
52
  switch (kind) {
59
53
  case types_1.Kind.ACL:
@@ -65,7 +59,7 @@ function getProtoPath(kind) {
65
59
  }
66
60
  }
67
61
  function createConnectClient(options) {
68
- const def = protoLoader.loadSync(getProtoPath(options.kind), protoOptions);
62
+ const def = protoLoader.loadSync(getProtoPath(options.kind), service_1.protoLoadOptions);
69
63
  const descriptor = grpc.loadPackageDefinition(def);
70
64
  const base = descriptor.fonoster.routr.connect;
71
65
  switch (options.kind) {
@@ -79,7 +73,9 @@ function createConnectClient(options) {
79
73
  }
80
74
  exports.createConnectClient = createConnectClient;
81
75
  function createConnectService(kind) {
82
- const def = protoLoader.loadSync(getProtoPath(kind), protoOptions);
76
+ // Here we set defaults to simplify partial updates
77
+ const actualProtoOptions = Object.assign(Object.assign({}, service_1.protoLoadOptions), { defaults: false });
78
+ const def = protoLoader.loadSync(getProtoPath(kind), actualProtoOptions);
83
79
  const descriptor = grpc.loadPackageDefinition(def);
84
80
  const base = descriptor.fonoster.routr.connect;
85
81
  switch (kind) {
@@ -1,7 +1,7 @@
1
1
  import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
2
- import { Kind } from "./types";
2
+ import { APIVersion, Kind } from "./types";
3
3
  export interface ConfigBase {
4
- apiVersion: string;
4
+ apiVersion: APIVersion;
5
5
  ref: string;
6
6
  metadata: {
7
7
  name: string;
@@ -13,7 +13,9 @@ function mapToACL(config) {
13
13
  ref: config.ref,
14
14
  name: config.metadata.name,
15
15
  allow: (_b = (_a = config.spec.accessControlList) === null || _a === void 0 ? void 0 : _a.allow) !== null && _b !== void 0 ? _b : [],
16
- deny: (_d = (_c = config.spec.accessControlList) === null || _c === void 0 ? void 0 : _c.deny) !== null && _d !== void 0 ? _d : []
16
+ deny: (_d = (_c = config.spec.accessControlList) === null || _c === void 0 ? void 0 : _c.deny) !== null && _d !== void 0 ? _d : [],
17
+ createdAt: new Date().getTime(),
18
+ updatedAt: new Date().getTime()
17
19
  };
18
20
  }
19
21
  exports.mapToACL = mapToACL;
@@ -38,7 +38,9 @@ function mapToAgent(config) {
38
38
  domainRef: config.spec.domainRef,
39
39
  credentialsRef: config.spec.credentialsRef,
40
40
  maxContacts: config.spec.maxContacts,
41
- expires: config.spec.expires
41
+ expires: config.spec.expires,
42
+ createdAt: new Date().getTime(),
43
+ updatedAt: new Date().getTime()
42
44
  };
43
45
  }
44
46
  exports.mapToAgent = mapToAgent;
@@ -12,7 +12,9 @@ function mapToCredentials(config) {
12
12
  ref: config.ref,
13
13
  name: config.metadata.name,
14
14
  username: config.spec.credentials.username,
15
- password: config.spec.credentials.password
15
+ password: config.spec.credentials.password,
16
+ createdAt: new Date().getTime(),
17
+ updatedAt: new Date().getTime()
16
18
  };
17
19
  }
18
20
  exports.mapToCredentials = mapToCredentials;
@@ -13,7 +13,9 @@ function mapToDomain(config) {
13
13
  name: config.metadata.name,
14
14
  domainUri: config.spec.context.domainUri,
15
15
  accessControlListRef: config.spec.accessControlListRef,
16
- egressPolicies: config.spec.context.egressPolicies
16
+ egressPolicies: config.spec.context.egressPolicies,
17
+ createdAt: new Date().getTime(),
18
+ updatedAt: new Date().getTime()
17
19
  };
18
20
  }
19
21
  exports.mapToDomain = mapToDomain;
@@ -20,7 +20,9 @@ function mapToNumber(config) {
20
20
  aorLink: location.aorLink,
21
21
  sessionAffinityHeader: location.sessionAffinityHeader,
22
22
  extraHeaders: location.extraHeaders,
23
- trunkRef: config.spec.trunkRef
23
+ trunkRef: config.spec.trunkRef,
24
+ createdAt: new Date().getTime(),
25
+ updatedAt: new Date().getTime()
24
26
  };
25
27
  }
26
28
  exports.mapToNumber = mapToNumber;
@@ -21,7 +21,9 @@ function mapToPeer(config) {
21
21
  balancingAlgorithm: normalizeAlgorithm((_a = config.spec.loadBalancing) === null || _a === void 0 ? void 0 : _a.algorithm),
22
22
  withSessionAffinity: (_b = config.spec.loadBalancing) === null || _b === void 0 ? void 0 : _b.withSessionAffinity,
23
23
  maxContacts: config.spec.maxContacts,
24
- expires: config.spec.expires
24
+ expires: config.spec.expires,
25
+ createdAt: new Date().getTime(),
26
+ updatedAt: new Date().getTime()
25
27
  };
26
28
  }
27
29
  exports.mapToPeer = mapToPeer;
@@ -28,7 +28,9 @@ function mapToTrunk(config) {
28
28
  weight: entry.weight,
29
29
  priority: entry.priority
30
30
  };
31
- })
31
+ }),
32
+ createdAt: new Date().getTime(),
33
+ updatedAt: new Date().getTime()
32
34
  };
33
35
  }
34
36
  exports.mapToTrunk = mapToTrunk;
@@ -1,4 +1,3 @@
1
- import { JsonObject } from "pb-util/build";
2
1
  import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
3
2
  export declare enum Kind {
4
3
  AGENT = "agent",
@@ -12,16 +11,16 @@ export declare enum Kind {
12
11
  }
13
12
  export type KindWithoutUnknown = Exclude<Kind, Kind.UNKNOWN>;
14
13
  export declare enum APIVersion {
15
- v2beta1 = "v2beta1",
14
+ V2BETA1 = "v2beta1",
16
15
  V2 = "v2"
17
16
  }
18
17
  export interface BaseConnectModel {
19
- apiVersion: string;
18
+ apiVersion: APIVersion;
20
19
  ref: string;
21
20
  name: string;
22
- createdAt?: number;
23
- updatedAt?: number;
24
- extended?: JsonObject;
21
+ createdAt: number;
22
+ updatedAt: number;
23
+ extended?: Record<string, unknown>;
25
24
  }
26
25
  export interface AccessControlList extends BaseConnectModel {
27
26
  allow: string[];
@@ -59,8 +58,8 @@ export interface INumber extends BaseConnectModel {
59
58
  city: string;
60
59
  country: string;
61
60
  countryIsoCode: string;
62
- sessionAffinityHeader: string;
63
- extraHeaders: {
61
+ sessionAffinityHeader?: string;
62
+ extraHeaders?: {
64
63
  name: string;
65
64
  value: string;
66
65
  }[];
@@ -14,6 +14,6 @@ var Kind;
14
14
  })(Kind = exports.Kind || (exports.Kind = {}));
15
15
  var APIVersion;
16
16
  (function (APIVersion) {
17
- APIVersion["v2beta1"] = "v2beta1";
17
+ APIVersion["V2BETA1"] = "v2beta1";
18
18
  APIVersion["V2"] = "v2";
19
19
  })(APIVersion = exports.APIVersion || (exports.APIVersion = {}));
@@ -11,7 +11,7 @@ export declare const hasTelUrl: (telUrl: string) => true | BadRequestError;
11
11
  export declare const isValidTelUrl: (telUrl: string) => true | BadRequestError;
12
12
  export declare const isValidSessionAffinityHeader: (sessionAffinityHeader: string) => true | BadRequestError;
13
13
  export declare const isValidHeader: (header: string) => true | BadRequestError;
14
- export declare const hasValidHeaders: (headers: {
14
+ export declare const hasValidHeaders: (headers?: {
15
15
  name: string;
16
16
  value: string;
17
17
  }[]) => true | BadRequestError;
@@ -26,7 +26,7 @@ export declare const hasACLRules: (acl: {
26
26
  deny: string[];
27
27
  allow: string[];
28
28
  }) => true | BadRequestError;
29
- export declare const isValidACLRule: (rules: string[]) => true | BadRequestError;
29
+ export declare const isValidACLRule: (rules?: string[]) => true | BadRequestError;
30
30
  export declare const hasValidACLRules: (acl: {
31
31
  deny: string[];
32
32
  allow: string[];
@@ -108,7 +108,7 @@ const isValidHeader = (header) => {
108
108
  : true;
109
109
  };
110
110
  exports.isValidHeader = isValidHeader;
111
- const hasValidHeaders = (headers) => {
111
+ const hasValidHeaders = (headers = []) => {
112
112
  // eslint-disable-next-line no-loops/no-loops
113
113
  for (const header of headers) {
114
114
  const E = (0, exports.isValidHeader)(header.name);
@@ -161,7 +161,7 @@ const hasACLRules = (acl) => {
161
161
  return true;
162
162
  };
163
163
  exports.hasACLRules = hasACLRules;
164
- const isValidACLRule = (rules) => {
164
+ const isValidACLRule = (rules = []) => {
165
165
  // eslint-disable-next-line no-loops/no-loops
166
166
  for (const cidr of rules) {
167
167
  if (!Validator.default.isIPRange(cidr, 4) &&
@@ -65,13 +65,13 @@ message AddRouteRequest {
65
65
 
66
66
  message FindRoutesRequest {
67
67
  message Backend {
68
- enum Algoritm {
68
+ enum Algorithm {
69
69
  ROUND_ROBIN = 0;
70
70
  LEAST_SESSIONS = 1;
71
71
  }
72
72
  string ref = 1;
73
73
  bool with_session_affinity = 2;
74
- Algoritm algorithm = 3;
74
+ Algorithm algorithm = 3;
75
75
  }
76
76
  string call_id = 1;
77
77
  string aor = 2;
@@ -44,13 +44,8 @@ exports.REQUESTER_PROTO = void 0;
44
44
  */
45
45
  const grpc = __importStar(require("@grpc/grpc-js"));
46
46
  const protoLoader = require("@grpc/proto-loader");
47
- const packageDefinition = protoLoader.loadSync(__dirname + "/../protos/requester.proto", {
48
- keepCase: false,
49
- longs: String,
50
- enums: String,
51
- defaults: true,
52
- oneofs: true
53
- });
47
+ const service_1 = require("../service");
48
+ const packageDefinition = protoLoader.loadSync(__dirname + "/../protos/requester.proto", service_1.protoLoadOptions);
54
49
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
50
  const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
56
51
  exports.REQUESTER_PROTO = protoDescriptor.fonoster.routr.requester;
package/dist/service.d.ts CHANGED
@@ -1,5 +1,12 @@
1
1
  import { ObjectProto, ServiceInfo } from "./types";
2
2
  import { ServiceDefinitionNotFoundError } from "./errors";
3
+ export declare const protoLoadOptions: {
4
+ keepCase: boolean;
5
+ longs: StringConstructor;
6
+ enums: StringConstructor;
7
+ defaults: boolean;
8
+ oneofs: boolean;
9
+ };
3
10
  export declare const PROCESSOR_OBJECT_PROTO: unknown;
4
11
  export declare const LOCATION_OBJECT_PROTO: unknown;
5
12
  /**
package/dist/service.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.getObjectProto = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = void 0;
26
+ exports.getObjectProto = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.protoLoadOptions = void 0;
27
27
  /*
28
28
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/routr
@@ -49,7 +49,7 @@ const logger_1 = require("@fonoster/logger");
49
49
  const grpc_health_check_1 = require("grpc-health-check");
50
50
  const common_1 = require("@fonoster/common");
51
51
  const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
52
- const loadOptions = {
52
+ exports.protoLoadOptions = {
53
53
  keepCase: false,
54
54
  longs: String,
55
55
  enums: String,
@@ -77,7 +77,7 @@ exports.LOCATION_OBJECT_PROTO = getObjectProto({
77
77
  */
78
78
  function getObjectProto(objectProto) {
79
79
  var _a, _b;
80
- const definitions = protoLoader.loadSync(objectProto.path, loadOptions);
80
+ const definitions = protoLoader.loadSync(objectProto.path, exports.protoLoadOptions);
81
81
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
82
82
  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];
83
83
  return (objProto === null || objProto === void 0 ? void 0 : objProto[objectProto.version])
@@ -44,13 +44,8 @@ exports.VERIFIER_PROTO = void 0;
44
44
  */
45
45
  const grpc = __importStar(require("@grpc/grpc-js"));
46
46
  const protoLoader = require("@grpc/proto-loader");
47
- const packageDefinition = protoLoader.loadSync(__dirname + "/../protos/verifier.proto", {
48
- keepCase: false,
49
- longs: String,
50
- enums: String,
51
- defaults: true,
52
- oneofs: true
53
- });
47
+ const service_1 = require("../service");
48
+ const packageDefinition = protoLoader.loadSync(__dirname + "/../protos/verifier.proto", service_1.protoLoadOptions);
54
49
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
50
  const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
56
51
  exports.VERIFIER_PROTO = protoDescriptor.fonoster.verifier;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routr/common",
3
- "version": "2.12.1",
3
+ "version": "2.13.1",
4
4
  "description": "Common package",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/routr#readme",
@@ -55,5 +55,5 @@
55
55
  "devDependencies": {
56
56
  "@types/js-yaml": "^4.0.5"
57
57
  },
58
- "gitHead": "cf4c8276173ec4be0a8013e70935b6cffb29cda4"
58
+ "gitHead": "47b285ad57015b0df452eede4e76cbfc9c67cbbb"
59
59
  }