@routr/common 2.0.5-alpha.2 → 2.0.5-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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Function that asserts that the given environment variable is set.
3
+ *
4
+ * @param {string[]} variables environment variables to check
5
+ */
6
+ export declare function assertEnvsAreSet(variables: string[]): void;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertEnvsAreSet = void 0;
4
+ /*
5
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/routr
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 logger_1 = require("@fonoster/logger");
23
+ const logger = (0, logger_1.getLogger)({ service: "common", filePath: __filename });
24
+ /**
25
+ * Function that asserts that the given environment variable is set.
26
+ *
27
+ * @param {string[]} variables environment variables to check
28
+ */
29
+ function assertEnvsAreSet(variables) {
30
+ variables.forEach((variable) => {
31
+ if (!(variable in process.env)) {
32
+ logger.error(`The environment variable ${variable} is required but was not found`);
33
+ process.exit(1);
34
+ }
35
+ });
36
+ }
37
+ exports.assertEnvsAreSet = assertEnvsAreSet;
package/dist/auth.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { AuthChallengeRequest, AuthChallengeResponse } from "./types";
2
+ export declare const generateNonce: (algorithm?: string) => string;
3
+ export declare const buildAuthChallenge: (request: AuthChallengeRequest) => {
4
+ realm: string;
5
+ scheme: string;
6
+ algorithm: string;
7
+ qop: string;
8
+ opaque: string;
9
+ stale: boolean;
10
+ nonce: string;
11
+ };
12
+ export declare const calculateAuthResponse: (res: AuthChallengeResponse, credentials: {
13
+ username: string;
14
+ secret: string;
15
+ }) => string;
package/dist/auth.js ADDED
@@ -0,0 +1,37 @@
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.calculateAuthResponse = exports.buildAuthChallenge = exports.generateNonce = void 0;
7
+ const crypto_1 = __importDefault(require("crypto"));
8
+ const DEFAULT_ALGORITHM = "MD5";
9
+ const md5hex = (str, algorithm = DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest("hex");
10
+ const decToHex = (dec) => (dec + Math.pow(16, 8)).toString(16).substr(-8);
11
+ const generateNonce = (algorithm = DEFAULT_ALGORITHM) => md5hex(`${new Date().getTime()}${Math.random()}`, algorithm);
12
+ exports.generateNonce = generateNonce;
13
+ const buildAuthChallenge = (request) => {
14
+ const { realm, scheme, algorithm, qop, opaque, stale } = request;
15
+ return {
16
+ realm,
17
+ scheme,
18
+ algorithm,
19
+ qop,
20
+ opaque,
21
+ stale,
22
+ nonce: (0, exports.generateNonce)(algorithm)
23
+ };
24
+ };
25
+ exports.buildAuthChallenge = buildAuthChallenge;
26
+ const calculateAuthResponse = (res, credentials) => {
27
+ if (!credentials)
28
+ return null;
29
+ const a1 = `${credentials.username}:${res.realm}:${credentials.secret}`;
30
+ const a2 = `${res.method.toUpperCase()}:${res.uri}`;
31
+ const ha1 = md5hex(a1);
32
+ const ha2 = md5hex(a2);
33
+ return res.qop === "auth"
34
+ ? md5hex(`${ha1}:${res.nonce}:${decToHex(res.nonceCount)}:${res.cNonce}:${res.qop}:${ha2}`)
35
+ : md5hex(`${ha1}:${res.nonce}:${ha2}`);
36
+ };
37
+ exports.calculateAuthResponse = calculateAuthResponse;
@@ -0,0 +1,11 @@
1
+ import { FindParameters, Resource } from "./types";
2
+ /**
3
+ * Data API for the Connect module.
4
+ *
5
+ * @param {string} apiAddr - The address of the API server
6
+ * @return {Promise<Resource[]>}
7
+ */
8
+ export declare function dataAPI(apiAddr: string): {
9
+ get: (ref: string) => Promise<Resource>;
10
+ findBy: (request: FindParameters) => Promise<Resource[]>;
11
+ };
@@ -0,0 +1,79 @@
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.dataAPI = void 0;
27
+ /*
28
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster/routr
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 grpc = __importStar(require("@grpc/grpc-js"));
46
+ const errors_1 = require("../errors");
47
+ const grpc_client_1 = require("./grpc_client");
48
+ /**
49
+ * Data API for the Connect module.
50
+ *
51
+ * @param {string} apiAddr - The address of the API server
52
+ * @return {Promise<Resource[]>}
53
+ */
54
+ function dataAPI(apiAddr) {
55
+ const client = new grpc_client_1.RESOURCES_PROTO.v2draft1.Resources(apiAddr, grpc.credentials.createInsecure());
56
+ return {
57
+ get: (ref) => new Promise((resolve, reject) => {
58
+ client.get({ ref }, (err, response) => {
59
+ if (err) {
60
+ return (err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE
61
+ ? reject(new errors_1.ServiceUnavailableError(`api server at ${apiAddr} is unavailable`))
62
+ : reject(err);
63
+ }
64
+ resolve(response);
65
+ });
66
+ }),
67
+ findBy: (request) => new Promise((resolve, reject) => {
68
+ client.findBy(request, (err, response) => {
69
+ if (err) {
70
+ return (err === null || err === void 0 ? void 0 : err.code) === grpc.status.UNAVAILABLE
71
+ ? reject(new errors_1.ServiceUnavailableError(`api server at ${apiAddr} is unavailable`))
72
+ : reject(err);
73
+ }
74
+ resolve(response.resources);
75
+ });
76
+ })
77
+ };
78
+ }
79
+ exports.dataAPI = dataAPI;
@@ -0,0 +1 @@
1
+ export declare const RESOURCES_PROTO: any;
@@ -0,0 +1,56 @@
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.RESOURCES_PROTO = void 0;
27
+ /*
28
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
29
+ * http://github.com/fonoster/routr
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 grpc = __importStar(require("@grpc/grpc-js"));
46
+ const protoLoader = require("@grpc/proto-loader");
47
+ const packageDefinition = protoLoader.loadSync(__dirname + "/../protos/resources.proto", {
48
+ keepCase: false,
49
+ longs: String,
50
+ enums: String,
51
+ defaults: true,
52
+ oneofs: true
53
+ });
54
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
+ const protoDescriptor = grpc.loadPackageDefinition(packageDefinition);
56
+ exports.RESOURCES_PROTO = protoDescriptor.fonoster.routr.resources;
@@ -0,0 +1,3 @@
1
+ export * from "./data_api";
2
+ export * from "./grpc_client";
3
+ export * from "./types";
@@ -0,0 +1,37 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster
20
+ *
21
+ * This file is part of Routr.
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./data_api"), exports);
36
+ __exportStar(require("./grpc_client"), exports);
37
+ __exportStar(require("./types"), exports);
@@ -0,0 +1,36 @@
1
+ export declare enum KIND {
2
+ AGENT = "agent",
3
+ PEER = "peer",
4
+ NUMBER = "number",
5
+ TRUNK = "trunk",
6
+ DOMAIN = "domain",
7
+ UNKNOWN = "unknown",
8
+ CREDENTIAL = "credential"
9
+ }
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"
16
+ }
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 {
27
+ apiVersion: string;
28
+ kind: string;
29
+ metadata: {
30
+ ref: string;
31
+ name: string;
32
+ region?: string;
33
+ linkTo?: Array<string>;
34
+ };
35
+ spec: Record<string, any>;
36
+ }
@@ -0,0 +1,39 @@
1
+ "use strict";
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 = {}));
package/dist/errors.d.ts CHANGED
@@ -1,3 +1,24 @@
1
+ /**
2
+ * Error thrown if the definition for a service is not found.
3
+ */
1
4
  export declare class ServiceDefinitionNotFound extends Error {
5
+ /**
6
+ * Constructs a new ServiceDefinitionNotFound error.
7
+ *
8
+ * @param {string} name - The name of the service definition.
9
+ * @param {string} version - The version of the service definition.
10
+ */
2
11
  constructor(name: string, version: string);
3
12
  }
13
+ /**
14
+ * Error thrown if the service is not available.
15
+ */
16
+ export declare class ServiceUnavailableError extends Error {
17
+ code: number;
18
+ /**
19
+ * Constructs a new ServiceUnavailableError error.
20
+ *
21
+ * @param {string} address - The address of the service.
22
+ */
23
+ constructor(address: string);
24
+ }
package/dist/errors.js CHANGED
@@ -1,21 +1,29 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
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
+ };
17
25
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.ServiceDefinitionNotFound = void 0;
26
+ exports.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
19
27
  /*
20
28
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
21
29
  * http://github.com/fonoster/routr
@@ -34,14 +42,37 @@ exports.ServiceDefinitionNotFound = void 0;
34
42
  * See the License for the specific language governing permissions and
35
43
  * limitations under the License.
36
44
  */
37
- var ServiceDefinitionNotFound = /** @class */ (function (_super) {
38
- __extends(ServiceDefinitionNotFound, _super);
39
- function ServiceDefinitionNotFound(name, version) {
40
- var _this = _super.call(this, "Service definition for " + name + "/" + version + " not found") || this;
45
+ const grpc = __importStar(require("@grpc/grpc-js"));
46
+ /**
47
+ * Error thrown if the definition for a service is not found.
48
+ */
49
+ class ServiceDefinitionNotFound extends Error {
50
+ /**
51
+ * Constructs a new ServiceDefinitionNotFound error.
52
+ *
53
+ * @param {string} name - The name of the service definition.
54
+ * @param {string} version - The version of the service definition.
55
+ */
56
+ constructor(name, version) {
57
+ super(`Service definition for ${name}/${version} not found`);
41
58
  // Set the prototype explicitly.
42
- Object.setPrototypeOf(_this, ServiceDefinitionNotFound.prototype);
43
- return _this;
59
+ Object.setPrototypeOf(this, ServiceDefinitionNotFound.prototype);
44
60
  }
45
- return ServiceDefinitionNotFound;
46
- }(Error));
61
+ }
47
62
  exports.ServiceDefinitionNotFound = ServiceDefinitionNotFound;
63
+ /**
64
+ * Error thrown if the service is not available.
65
+ */
66
+ class ServiceUnavailableError extends Error {
67
+ /**
68
+ * Constructs a new ServiceUnavailableError error.
69
+ *
70
+ * @param {string} address - The address of the service.
71
+ */
72
+ constructor(address) {
73
+ super(`service unavailable [service address = ${address}]`);
74
+ this.code = grpc.status.UNAVAILABLE;
75
+ Object.setPrototypeOf(this, ServiceUnavailableError.prototype);
76
+ }
77
+ }
78
+ exports.ServiceUnavailableError = ServiceUnavailableError;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Makes a deep copy of an object.
3
+ *
4
+ * @param {object} source - The source object.
5
+ * @return {object} The deep copy of the source object.
6
+ */
7
+ export declare const deepCopy: <T>(source: T) => T;
package/dist/helper.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
4
+ * http://github.com/fonoster/routr
5
+ *
6
+ * This file is part of Routr
7
+ *
8
+ * Licensed under the MIT License (the "License")
9
+ * you may not use this file except in compliance with
10
+ * the License. You may obtain a copy of the License at
11
+ *
12
+ * https://opensource.org/licenses/MIT
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.deepCopy = void 0;
22
+ /**
23
+ * Makes a deep copy of an object.
24
+ *
25
+ * @param {object} source - The source object.
26
+ * @return {object} The deep copy of the source object.
27
+ */
28
+ const deepCopy = (source) => {
29
+ return Array.isArray(source)
30
+ ? source.map((item) => (0, exports.deepCopy)(item))
31
+ : source instanceof Date
32
+ ? new Date(source.getTime())
33
+ : source && typeof source === "object"
34
+ ? Object.getOwnPropertyNames(source).reduce((o, prop) => {
35
+ Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop));
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ o[prop] = (0, exports.deepCopy)(source[prop]);
38
+ return o;
39
+ }, Object.create(Object.getPrototypeOf(source)))
40
+ : source;
41
+ };
42
+ exports.deepCopy = deepCopy;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,13 @@
1
- import createService, { PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO, getObjectProto } from "./service";
2
- import { Transport, ProcessorConfig, MessageRequest, NetInterface, Method, Direction, ObjectProto, ServiceInfo } from "./types";
3
- export { createService, getObjectProto, Transport, ProcessorConfig, MessageRequest, NetInterface, Method, Direction, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
1
+ import { calculateAuthResponse, generateNonce } from "./auth";
2
+ import { ServiceUnavailableError } from "./errors";
3
+ import createService, { getObjectProto, LOCATION_OBJECT_PROTO, PROCESSOR_OBJECT_PROTO } from "./service";
4
+ 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 };
6
+ export * as Redis from "./redis";
7
+ export * as CommonTypes from "./types";
8
+ export * as Helper from "./helper";
9
+ export * as IpUtils from "./ip_utils";
10
+ export * as Tracer from "./tracer";
11
+ export * as Assertions from "./assertions";
12
+ export * as CommonConnect from "./connect";
13
+ export * as CommonRequester from "./requester";
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.getObjectProto = exports.createService = void 0;
26
+ 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.calculateAuthResponse = exports.generateNonce = exports.getObjectProto = exports.createService = void 0;
23
27
  /*
24
28
  * Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
25
29
  * http://github.com/fonoster/routr
@@ -38,8 +42,24 @@ exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.getObje
38
42
  * See the License for the specific language governing permissions and
39
43
  * limitations under the License.
40
44
  */
41
- var service_1 = __importStar(require("./service"));
45
+ const auth_1 = require("./auth");
46
+ Object.defineProperty(exports, "calculateAuthResponse", { enumerable: true, get: function () { return auth_1.calculateAuthResponse; } });
47
+ Object.defineProperty(exports, "generateNonce", { enumerable: true, get: function () { return auth_1.generateNonce; } });
48
+ const errors_1 = require("./errors");
49
+ Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_1.ServiceUnavailableError; } });
50
+ const service_1 = __importStar(require("./service"));
42
51
  exports.createService = service_1.default;
43
- Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
44
- Object.defineProperty(exports, "LOCATION_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.LOCATION_OBJECT_PROTO; } });
45
52
  Object.defineProperty(exports, "getObjectProto", { enumerable: true, get: function () { return service_1.getObjectProto; } });
53
+ Object.defineProperty(exports, "LOCATION_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.LOCATION_OBJECT_PROTO; } });
54
+ Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
55
+ const types_1 = require("./types");
56
+ Object.defineProperty(exports, "Method", { enumerable: true, get: function () { return types_1.Method; } });
57
+ Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return types_1.Transport; } });
58
+ exports.Redis = __importStar(require("./redis"));
59
+ exports.CommonTypes = __importStar(require("./types"));
60
+ exports.Helper = __importStar(require("./helper"));
61
+ exports.IpUtils = __importStar(require("./ip_utils"));
62
+ exports.Tracer = __importStar(require("./tracer"));
63
+ exports.Assertions = __importStar(require("./assertions"));
64
+ exports.CommonConnect = __importStar(require("./connect"));
65
+ exports.CommonRequester = __importStar(require("./requester"));
@@ -0,0 +1,4 @@
1
+ export declare const formatNet: (net: string) => string;
2
+ export declare const hasIp: (net: string, addr: string) => boolean;
3
+ export declare const addressCount: (net: string) => number;
4
+ export declare const isLocalnet: (nets: string[], addr: string) => boolean;