@routr/common 2.0.8-alpha.2 → 2.0.8-alpha.20

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 (79) hide show
  1. package/dist/auth.d.ts +43 -4
  2. package/dist/auth.js +63 -1
  3. package/dist/connect/api/client.d.ts +3 -0
  4. package/dist/connect/api/client.js +158 -0
  5. package/dist/connect/api/index.d.ts +2 -0
  6. package/dist/connect/api/index.js +36 -0
  7. package/dist/connect/api/types.d.ts +51 -0
  8. package/dist/connect/api/types.js +2 -0
  9. package/dist/connect/client.d.ts +8 -0
  10. package/dist/connect/{grpc_client.js → client.js} +44 -6
  11. package/dist/connect/config.d.ts +113 -0
  12. package/dist/connect/config.js +2 -0
  13. package/dist/connect/connect_error.d.ts +21 -0
  14. package/dist/connect/connect_error.js +44 -0
  15. package/dist/connect/index.d.ts +4 -2
  16. package/dist/connect/index.js +4 -2
  17. package/dist/connect/mappers/acl.d.ts +3 -0
  18. package/dist/connect/mappers/acl.js +19 -0
  19. package/dist/connect/mappers/agent.d.ts +3 -0
  20. package/dist/connect/mappers/agent.js +42 -0
  21. package/dist/connect/mappers/assertions.d.ts +3 -0
  22. package/dist/connect/mappers/assertions.js +43 -0
  23. package/dist/connect/mappers/credentials.d.ts +3 -0
  24. package/dist/connect/mappers/credentials.js +18 -0
  25. package/dist/connect/mappers/domain.d.ts +3 -0
  26. package/dist/connect/mappers/domain.js +19 -0
  27. package/dist/connect/mappers/index.d.ts +7 -0
  28. package/dist/connect/mappers/index.js +41 -0
  29. package/dist/connect/mappers/number.d.ts +3 -0
  30. package/dist/connect/mappers/number.js +26 -0
  31. package/dist/connect/mappers/peer.d.ts +3 -0
  32. package/dist/connect/mappers/peer.js +25 -0
  33. package/dist/connect/mappers/trunk.d.ts +3 -0
  34. package/dist/connect/mappers/trunk.js +34 -0
  35. package/dist/connect/protos/acl.proto +112 -0
  36. package/dist/connect/protos/agents.proto +155 -0
  37. package/dist/connect/protos/credentials.proto +114 -0
  38. package/dist/connect/protos/domains.proto +148 -0
  39. package/dist/connect/protos/numbers.proto +174 -0
  40. package/dist/connect/protos/peers.proto +173 -0
  41. package/dist/connect/protos/trunks.proto +178 -0
  42. package/dist/connect/schemas/acl.d.ts +63 -0
  43. package/dist/connect/schemas/acl.js +82 -0
  44. package/dist/connect/schemas/agent.d.ts +62 -0
  45. package/dist/connect/schemas/agent.js +81 -0
  46. package/dist/connect/schemas/crendentials.d.ts +59 -0
  47. package/dist/connect/schemas/crendentials.js +78 -0
  48. package/dist/connect/schemas/domain.d.ts +75 -0
  49. package/dist/connect/schemas/domain.js +94 -0
  50. package/dist/connect/schemas/index.d.ts +1 -0
  51. package/dist/connect/schemas/index.js +35 -0
  52. package/dist/connect/schemas/number.d.ts +82 -0
  53. package/dist/connect/schemas/number.js +101 -0
  54. package/dist/connect/schemas/peer.d.ts +84 -0
  55. package/dist/connect/schemas/peer.js +103 -0
  56. package/dist/connect/schemas/trunk.d.ts +119 -0
  57. package/dist/connect/schemas/trunk.js +151 -0
  58. package/dist/connect/schemas/validators.d.ts +2 -0
  59. package/dist/connect/schemas/validators.js +43 -0
  60. package/dist/connect/types.d.ts +89 -23
  61. package/dist/connect/types.js +17 -37
  62. package/dist/errors.d.ts +35 -1
  63. package/dist/errors.js +51 -5
  64. package/dist/helper.d.ts +17 -4
  65. package/dist/helper.js +81 -7
  66. package/dist/index.d.ts +5 -4
  67. package/dist/index.js +5 -7
  68. package/dist/protos/common.proto +0 -2
  69. package/dist/protos/location.proto +22 -7
  70. package/dist/protos/sipmessage.proto +2 -0
  71. package/dist/service.d.ts +2 -2
  72. package/dist/service.js +1 -1
  73. package/dist/types.d.ts +52 -30
  74. package/dist/types.js +18 -11
  75. package/package.json +11 -5
  76. package/dist/connect/data_api.d.ts +0 -11
  77. package/dist/connect/data_api.js +0 -91
  78. package/dist/connect/grpc_client.d.ts +0 -1
  79. package/dist/protos/resources.proto +0 -108
@@ -0,0 +1,151 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /*
4
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
5
+ * http://github.com/fonoster
6
+ *
7
+ * This file is part of Routr.
8
+ *
9
+ * Licensed under the MIT License (the "License");
10
+ * you may not use this file except in compliance with
11
+ * the License. You may obtain a copy of the License at
12
+ *
13
+ * https://opensource.org/licenses/MIT
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+ exports.default = {
22
+ $id: "https://json-schema.org/draft/2020-12/schema",
23
+ title: "Agent validation schema",
24
+ description: "The spec defined for Peer validation",
25
+ type: "object",
26
+ properties: {
27
+ apiVersion: {
28
+ enum: ["v2draft1", "v2"]
29
+ },
30
+ kind: {
31
+ enum: ["Trunk", "trunk"]
32
+ },
33
+ ref: {
34
+ description: "Reference to the resource",
35
+ type: "string"
36
+ },
37
+ metadata: {
38
+ description: "Resource metadata",
39
+ type: "object",
40
+ properties: {
41
+ name: {
42
+ description: "Resource's friendly name",
43
+ type: "string",
44
+ minLength: 3,
45
+ maxLength: 64
46
+ }
47
+ },
48
+ required: ["name"]
49
+ },
50
+ spec: {
51
+ description: "Operations spec for an Trunk",
52
+ type: "object",
53
+ properties: {
54
+ inbound: {
55
+ description: "Inbound configuration",
56
+ type: "object",
57
+ properties: {
58
+ uri: {
59
+ description: "URI of the inbound endpoint",
60
+ type: "string",
61
+ maxLength: 255
62
+ },
63
+ accessControlListRef: {
64
+ description: "Reference to the ACL to be used for inbound traffic",
65
+ type: "string"
66
+ },
67
+ credentialsRef: {
68
+ description: "Reference to the credentials to be used for inbound traffic",
69
+ type: "string"
70
+ }
71
+ },
72
+ required: ["uri"]
73
+ },
74
+ outbound: {
75
+ description: "Outbound configuration",
76
+ type: "object",
77
+ properties: {
78
+ sendRegister: {
79
+ description: "Whether to send register messages",
80
+ type: "boolean"
81
+ },
82
+ credentialsRef: {
83
+ description: "Reference to the credentials to be used for outbound traffic",
84
+ type: "string"
85
+ },
86
+ uris: {
87
+ description: "List of URIs to be used for outbound traffic",
88
+ type: "array",
89
+ items: {
90
+ type: "object",
91
+ properties: {
92
+ uri: {
93
+ description: "URI to be used for outbound traffic",
94
+ type: "object",
95
+ properties: {
96
+ host: {
97
+ description: "Hostname of the URI",
98
+ type: "string"
99
+ },
100
+ port: {
101
+ description: "Port of the URI",
102
+ type: "integer"
103
+ },
104
+ transport: {
105
+ description: "Transport of the URI",
106
+ enum: [
107
+ "TCP",
108
+ "SCTP",
109
+ "UDP",
110
+ "TLS",
111
+ "WS",
112
+ "WSS",
113
+ "tcp",
114
+ "sctp",
115
+ "udp",
116
+ "tls",
117
+ "ws",
118
+ "wss"
119
+ ]
120
+ },
121
+ user: {
122
+ description: "Username of the URI",
123
+ type: "string"
124
+ }
125
+ },
126
+ required: ["host", "port", "transport"]
127
+ },
128
+ weight: {
129
+ description: "Weight of the URI",
130
+ type: "integer"
131
+ },
132
+ priority: {
133
+ description: "Priority of the URI",
134
+ type: "integer"
135
+ },
136
+ enabled: {
137
+ description: "Whether the URI is enabled",
138
+ type: "boolean"
139
+ }
140
+ },
141
+ required: ["uri"]
142
+ }
143
+ }
144
+ },
145
+ required: ["uris"]
146
+ }
147
+ }
148
+ }
149
+ },
150
+ required: ["apiVersion", "kind", "ref", "metadata", "spec"]
151
+ };
@@ -0,0 +1,2 @@
1
+ declare const schemaValidators: Map<any, any>;
2
+ export { schemaValidators };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.schemaValidators = void 0;
7
+ /*
8
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
9
+ * http://github.com/fonoster
10
+ *
11
+ * This file is part of Routr.
12
+ *
13
+ * Licensed under the MIT License (the "License");
14
+ * you may not use this file except in compliance with
15
+ * the License. You may obtain a copy of the License at
16
+ *
17
+ * https://opensource.org/licenses/MIT
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ const types_1 = require("../types");
26
+ const ajv_1 = __importDefault(require("ajv"));
27
+ const acl_1 = __importDefault(require("./acl"));
28
+ const agent_1 = __importDefault(require("./agent"));
29
+ const crendentials_1 = __importDefault(require("./crendentials"));
30
+ const domain_1 = __importDefault(require("./domain"));
31
+ const number_1 = __importDefault(require("./number"));
32
+ const peer_1 = __importDefault(require("./peer"));
33
+ const trunk_1 = __importDefault(require("./trunk"));
34
+ const validator = (schema) => new ajv_1.default().compile(schema);
35
+ const schemaValidators = new Map();
36
+ exports.schemaValidators = schemaValidators;
37
+ schemaValidators.set(types_1.Kind.ACL, validator(acl_1.default));
38
+ schemaValidators.set(types_1.Kind.AGENT, validator(agent_1.default));
39
+ schemaValidators.set(types_1.Kind.CREDENTIALS, validator(crendentials_1.default));
40
+ schemaValidators.set(types_1.Kind.DOMAIN, validator(domain_1.default));
41
+ schemaValidators.set(types_1.Kind.NUMBER, validator(number_1.default));
42
+ schemaValidators.set(types_1.Kind.PEER, validator(peer_1.default));
43
+ schemaValidators.set(types_1.Kind.TRUNK, validator(trunk_1.default));
@@ -1,35 +1,101 @@
1
- export declare enum KIND {
1
+ import { JsonObject } from "pb-util/build";
2
+ import { LoadBalancingAlgorithm, Privacy, Transport } from "../types";
3
+ export declare enum Kind {
2
4
  AGENT = "agent",
3
5
  PEER = "peer",
4
6
  NUMBER = "number",
5
7
  TRUNK = "trunk",
6
8
  DOMAIN = "domain",
7
9
  UNKNOWN = "unknown",
8
- CREDENTIAL = "credential"
10
+ CREDENTIALS = "credentials",
11
+ ACL = "accesscontrollist"
9
12
  }
10
- export declare enum FindCriteria {
11
- FIND_AGENT_BY_USERNAME = "find_agent_by_username",
12
- FIND_CREDENTIAL_BY_REFERENCE = "find_credential_by_reference",
13
- FIND_DOMAIN_BY_DOMAINURI = "find_domain_by_domainuri",
14
- FIND_NUMBER_BY_TELURL = "find_number_by_telurl",
15
- FIND_TRUNKS_WITH_SEND_REGISTER = "find_trunks_with_send_register"
13
+ export type KindWithoutUnknown = Exclude<Kind, Kind.UNKNOWN>;
14
+ export declare enum APIVersion {
15
+ V2DRAFT1 = "v2draft1",
16
+ V2 = "v2"
16
17
  }
17
- export interface FindParameters {
18
- kind: KIND;
19
- criteria: FindCriteria;
20
- parameters: Record<string, string>;
21
- }
22
- export interface DataAPI {
23
- get: (ref: string) => Promise<Resource>;
24
- findBy: (request: FindParameters) => Promise<Resource[]>;
25
- }
26
- export interface Resource {
18
+ export interface BaseConnectModel {
27
19
  apiVersion: string;
28
- kind: string;
29
20
  ref: string;
30
- metadata: {
21
+ name: string;
22
+ createdAt?: Date;
23
+ updatedAt?: Date;
24
+ extended?: JsonObject;
25
+ }
26
+ export interface AccessControlList extends BaseConnectModel {
27
+ allow: string[];
28
+ deny: string[];
29
+ }
30
+ export interface Domain extends BaseConnectModel {
31
+ domainUri: string;
32
+ accessControlListRef?: string;
33
+ accessControlList?: AccessControlList;
34
+ egressPolicies?: EgressPolicy[];
35
+ }
36
+ export interface EgressPolicy {
37
+ numberRef: string;
38
+ number?: INumber;
39
+ rule: string;
40
+ }
41
+ export interface Agent extends BaseConnectModel {
42
+ username: string;
43
+ privacy: Privacy;
44
+ enabled: boolean;
45
+ domainRef?: string;
46
+ domain?: Domain;
47
+ credentialsRef?: string;
48
+ credentials?: Credentials;
49
+ }
50
+ export interface Credentials extends BaseConnectModel {
51
+ username: string;
52
+ password: string;
53
+ }
54
+ export interface INumber extends BaseConnectModel {
55
+ telUrl: string;
56
+ aorLink: string;
57
+ city: string;
58
+ country: string;
59
+ countryISOCode: string;
60
+ sessionAffinityHeader: string;
61
+ extraHeaders: {
31
62
  name: string;
32
- region?: string;
33
- };
34
- spec: Record<string, any>;
63
+ value: string;
64
+ }[];
65
+ trunkRef?: string;
66
+ trunk?: Trunk;
67
+ }
68
+ export interface Trunk extends BaseConnectModel {
69
+ sendRegister: boolean;
70
+ inboundUri: string;
71
+ accessControlListRef?: string;
72
+ accessControlList?: AccessControlList;
73
+ inboundCredentialsRef?: string;
74
+ inboundCredentials?: Credentials;
75
+ outboundCredentialsRef?: string;
76
+ outboundCredentials?: Credentials;
77
+ uris: TrunkURI[];
78
+ }
79
+ export interface TrunkURI {
80
+ host: string;
81
+ port: number;
82
+ transport: Transport;
83
+ user: string;
84
+ weight: number;
85
+ priority: number;
86
+ enabled: boolean;
87
+ }
88
+ export interface Peer extends BaseConnectModel {
89
+ username: string;
90
+ aor: string;
91
+ contactAddr: string;
92
+ enabled: boolean;
93
+ accessControlListRef?: string;
94
+ accessControlList?: AccessControlList;
95
+ credentialsRef?: string;
96
+ credentials?: Credentials;
97
+ balancingAlgorithm?: LoadBalancingAlgorithm;
98
+ withSessionAffinity?: boolean;
35
99
  }
100
+ export type ConnectModel = Agent | Peer | INumber | Trunk | Domain | Credentials | AccessControlList;
101
+ export type RoutableResourceUnion = Agent | Peer | INumber;
@@ -1,39 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FindCriteria = exports.KIND = void 0;
4
- /*
5
- * Copyright (C) 2022 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
- var KIND;
23
- (function (KIND) {
24
- KIND["AGENT"] = "agent";
25
- KIND["PEER"] = "peer";
26
- KIND["NUMBER"] = "number";
27
- KIND["TRUNK"] = "trunk";
28
- KIND["DOMAIN"] = "domain";
29
- KIND["UNKNOWN"] = "unknown";
30
- KIND["CREDENTIAL"] = "credential";
31
- })(KIND = exports.KIND || (exports.KIND = {}));
32
- var FindCriteria;
33
- (function (FindCriteria) {
34
- FindCriteria["FIND_AGENT_BY_USERNAME"] = "find_agent_by_username";
35
- FindCriteria["FIND_CREDENTIAL_BY_REFERENCE"] = "find_credential_by_reference";
36
- FindCriteria["FIND_DOMAIN_BY_DOMAINURI"] = "find_domain_by_domainuri";
37
- FindCriteria["FIND_NUMBER_BY_TELURL"] = "find_number_by_telurl";
38
- FindCriteria["FIND_TRUNKS_WITH_SEND_REGISTER"] = "find_trunks_with_send_register";
39
- })(FindCriteria = exports.FindCriteria || (exports.FindCriteria = {}));
3
+ exports.APIVersion = exports.Kind = void 0;
4
+ var Kind;
5
+ (function (Kind) {
6
+ Kind["AGENT"] = "agent";
7
+ Kind["PEER"] = "peer";
8
+ Kind["NUMBER"] = "number";
9
+ Kind["TRUNK"] = "trunk";
10
+ Kind["DOMAIN"] = "domain";
11
+ Kind["UNKNOWN"] = "unknown";
12
+ Kind["CREDENTIALS"] = "credentials";
13
+ Kind["ACL"] = "accesscontrollist";
14
+ })(Kind = exports.Kind || (exports.Kind = {}));
15
+ var APIVersion;
16
+ (function (APIVersion) {
17
+ APIVersion["V2DRAFT1"] = "v2draft1";
18
+ APIVersion["V2"] = "v2";
19
+ })(APIVersion = exports.APIVersion || (exports.APIVersion = {}));
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,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.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
26
+ exports.BadRequestError = exports.ResourceNotFoundError = exports.UnimplementedError = exports.ServiceUnavailableError = exports.ServiceDefinitionNotFoundError = void 0;
27
27
  /*
28
28
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
29
29
  * http://github.com/fonoster/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;
package/dist/helper.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MessageRequest, Transport } from "./types";
1
+ import { NetInterface, Transport } from "./types";
2
2
  /**
3
3
  * Makes a deep copy of an object.
4
4
  *
@@ -9,8 +9,21 @@ export declare const deepCopy: <T>(source: T) => T;
9
9
  /**
10
10
  * Gets a listening point from a request.
11
11
  *
12
- * @param {MessageRequest} request - The source object.
13
- * @param {Transport} transport - The source object.
12
+ * @param {NetInterface[]} listeningPoints - The listening points.
13
+ * @param {Transport} transport - The transport.
14
14
  * @return {NetInterface} transport The deep copy of the source object.
15
15
  */
16
- export declare const getListeningPoint: (request: MessageRequest, transport: Transport) => import("./types").NetInterface;
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,4 +1,32 @@
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
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.toPascaleCase = exports.readConfigFile = exports.getListeningPoint = exports.deepCopy = void 0;
2
30
  /*
3
31
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
4
32
  * http://github.com/fonoster/routr
@@ -17,8 +45,9 @@
17
45
  * See the License for the specific language governing permissions and
18
46
  * limitations under the License.
19
47
  */
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.getListeningPoint = exports.deepCopy = void 0;
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.
@@ -44,17 +73,62 @@ exports.deepCopy = deepCopy;
44
73
  /**
45
74
  * Gets a listening point from a request.
46
75
  *
47
- * @param {MessageRequest} request - The source object.
48
- * @param {Transport} transport - The source object.
76
+ * @param {NetInterface[]} listeningPoints - The listening points.
77
+ * @param {Transport} transport - The transport.
49
78
  * @return {NetInterface} transport The deep copy of the source object.
50
79
  */
51
- const getListeningPoint = (request, transport) => {
80
+ const getListeningPoint = (listeningPoints, transport) => {
52
81
  const listeningPoint = transport
53
- ? request.listeningPoints.find((lp) => lp.transport.toLowerCase() === transport.toLowerCase())
54
- : request.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,14 @@
1
- import { calculateAuthResponse, generateNonce } from "./auth";
2
- import { ServiceUnavailableError } from "./errors";
3
1
  import createService, { getObjectProto, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
4
2
  import { HeaderModifier, MessageRequest, MessageResponse, Method, NetInterface, ObjectProto, ProcessorConfig, Route, ServiceInfo, Transport } from "./types";
5
- export { createService, getObjectProto, generateNonce, calculateAuthResponse, 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";
6
5
  export * as Redis from "./redis";
7
- export * as CommonTypes from "./types";
8
6
  export * as Helper from "./helper";
9
7
  export * as IpUtils from "./ip_utils";
10
8
  export * as Tracer from "./tracer";
11
9
  export * as Assertions from "./assertions";
12
10
  export * as CommonConnect from "./connect";
13
11
  export * as CommonRequester from "./requester";
12
+ export * as CommonTypes from "./types";
13
+ export * as CommonErrors from "./errors";
14
+ export * as ConnectSchemas from "./connect/schemas";