@routr/common 2.0.5-alpha.15 → 2.0.5-alpha.17
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/dist/assertions.d.ts +6 -0
- package/dist/assertions.js +37 -0
- package/dist/auth.d.ts +1 -1
- package/dist/auth.js +12 -4
- package/dist/connect/data_api.d.ts +11 -0
- package/dist/connect/data_api.js +79 -0
- package/dist/connect/grpc_client.d.ts +1 -0
- package/dist/connect/grpc_client.js +56 -0
- package/dist/connect/index.d.ts +3 -0
- package/dist/connect/index.js +37 -0
- package/dist/connect/types.d.ts +36 -0
- package/dist/connect/types.js +39 -0
- package/dist/errors.d.ts +18 -1
- package/dist/errors.js +43 -3
- package/dist/helper.d.ts +6 -0
- package/dist/helper.js +11 -4
- package/dist/index.d.ts +7 -3
- package/dist/index.js +8 -4
- package/dist/ip_utils.js +5 -5
- package/dist/protos/common.proto +18 -0
- package/dist/protos/location.proto +21 -8
- package/dist/protos/processor.proto +40 -0
- package/dist/protos/requester.proto +47 -0
- package/dist/protos/resources.proto +107 -0
- package/dist/protos/sipmessage.proto +47 -8
- package/dist/redis.d.ts +8 -0
- package/dist/redis.js +10 -0
- package/dist/service.d.ts +13 -2
- package/dist/service.js +46 -11
- package/dist/tracer.d.ts +6 -0
- package/dist/tracer.js +10 -6
- package/dist/types.d.ts +190 -7
- package/dist/types.js +66 -19
- package/package.json +3 -3
|
@@ -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
CHANGED
|
@@ -9,7 +9,7 @@ export declare const buildAuthChallenge: (request: AuthChallengeRequest) => {
|
|
|
9
9
|
stale: boolean;
|
|
10
10
|
nonce: string;
|
|
11
11
|
};
|
|
12
|
-
export declare const calculateAuthResponse: (res: AuthChallengeResponse, credentials
|
|
12
|
+
export declare const calculateAuthResponse: (res: AuthChallengeResponse, credentials: {
|
|
13
13
|
username: string;
|
|
14
14
|
secret: string;
|
|
15
15
|
}) => string;
|
package/dist/auth.js
CHANGED
|
@@ -5,14 +5,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.calculateAuthResponse = exports.buildAuthChallenge = exports.generateNonce = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
-
const DEFAULT_ALGORITHM =
|
|
9
|
-
const md5hex = (str, algorithm = DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest(
|
|
8
|
+
const DEFAULT_ALGORITHM = "MD5";
|
|
9
|
+
const md5hex = (str, algorithm = DEFAULT_ALGORITHM) => crypto_1.default.createHash(algorithm).update(str).digest("hex");
|
|
10
10
|
const decToHex = (dec) => (dec + Math.pow(16, 8)).toString(16).substr(-8);
|
|
11
11
|
const generateNonce = (algorithm = DEFAULT_ALGORITHM) => md5hex(`${new Date().getTime()}${Math.random()}`, algorithm);
|
|
12
12
|
exports.generateNonce = generateNonce;
|
|
13
13
|
const buildAuthChallenge = (request) => {
|
|
14
14
|
const { realm, scheme, algorithm, qop, opaque, stale } = request;
|
|
15
|
-
return {
|
|
15
|
+
return {
|
|
16
|
+
realm,
|
|
17
|
+
scheme,
|
|
18
|
+
algorithm,
|
|
19
|
+
qop,
|
|
20
|
+
opaque,
|
|
21
|
+
stale,
|
|
22
|
+
nonce: (0, exports.generateNonce)(algorithm)
|
|
23
|
+
};
|
|
16
24
|
};
|
|
17
25
|
exports.buildAuthChallenge = buildAuthChallenge;
|
|
18
26
|
const calculateAuthResponse = (res, credentials) => {
|
|
@@ -22,7 +30,7 @@ const calculateAuthResponse = (res, credentials) => {
|
|
|
22
30
|
const a2 = `${res.method.toUpperCase()}:${res.uri}`;
|
|
23
31
|
const ha1 = md5hex(a1);
|
|
24
32
|
const ha2 = md5hex(a2);
|
|
25
|
-
return res.qop ===
|
|
33
|
+
return res.qop === "auth"
|
|
26
34
|
? md5hex(`${ha1}:${res.nonce}:${decToHex(res.nonceCount)}:${res.cNonce}:${res.qop}:${ha2}`)
|
|
27
35
|
: md5hex(`${ha1}:${res.nonce}:${ha2}`);
|
|
28
36
|
};
|
|
@@ -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,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,7 +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
|
+
*/
|
|
4
16
|
export declare class ServiceUnavailableError extends Error {
|
|
5
17
|
code: number;
|
|
6
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Constructs a new ServiceUnavailableError error.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} address - The address of the service.
|
|
22
|
+
*/
|
|
23
|
+
constructor(address: string);
|
|
7
24
|
}
|
package/dist/errors.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
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
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
|
|
4
27
|
/*
|
|
@@ -19,8 +42,17 @@ exports.ServiceUnavailableError = exports.ServiceDefinitionNotFound = void 0;
|
|
|
19
42
|
* See the License for the specific language governing permissions and
|
|
20
43
|
* limitations under the License.
|
|
21
44
|
*/
|
|
22
|
-
const grpc = require("@grpc/grpc-js");
|
|
45
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown if the definition for a service is not found.
|
|
48
|
+
*/
|
|
23
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
|
+
*/
|
|
24
56
|
constructor(name, version) {
|
|
25
57
|
super(`Service definition for ${name}/${version} not found`);
|
|
26
58
|
// Set the prototype explicitly.
|
|
@@ -28,9 +60,17 @@ class ServiceDefinitionNotFound extends Error {
|
|
|
28
60
|
}
|
|
29
61
|
}
|
|
30
62
|
exports.ServiceDefinitionNotFound = ServiceDefinitionNotFound;
|
|
63
|
+
/**
|
|
64
|
+
* Error thrown if the service is not available.
|
|
65
|
+
*/
|
|
31
66
|
class ServiceUnavailableError extends Error {
|
|
32
|
-
|
|
33
|
-
|
|
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}]`);
|
|
34
74
|
this.code = grpc.status.UNAVAILABLE;
|
|
35
75
|
Object.setPrototypeOf(this, ServiceUnavailableError.prototype);
|
|
36
76
|
}
|
package/dist/helper.d.ts
CHANGED
package/dist/helper.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepCopy = void 0;
|
|
4
2
|
/*
|
|
5
3
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
6
4
|
* http://github.com/fonoster/routr
|
|
@@ -19,14 +17,23 @@ exports.deepCopy = void 0;
|
|
|
19
17
|
* See the License for the specific language governing permissions and
|
|
20
18
|
* limitations under the License.
|
|
21
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
|
+
*/
|
|
22
28
|
const deepCopy = (source) => {
|
|
23
29
|
return Array.isArray(source)
|
|
24
|
-
? source.map(item => (0, exports.deepCopy)(item))
|
|
30
|
+
? source.map((item) => (0, exports.deepCopy)(item))
|
|
25
31
|
: source instanceof Date
|
|
26
32
|
? new Date(source.getTime())
|
|
27
|
-
: source && typeof source ===
|
|
33
|
+
: source && typeof source === "object"
|
|
28
34
|
? Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
|
29
35
|
Object.defineProperty(o, prop, Object.getOwnPropertyDescriptor(source, prop));
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
37
|
o[prop] = (0, exports.deepCopy)(source[prop]);
|
|
31
38
|
return o;
|
|
32
39
|
}, Object.create(Object.getPrototypeOf(source)))
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { calculateAuthResponse, generateNonce } from "./auth";
|
|
2
2
|
import { ServiceUnavailableError } from "./errors";
|
|
3
|
-
import createService, {
|
|
4
|
-
import {
|
|
5
|
-
export { createService, getObjectProto, generateNonce, calculateAuthResponse, Route, ServiceUnavailableError, Transport, ProcessorConfig, MessageRequest, MessageResponse, NetInterface, Method, ObjectProto, ServiceInfo, PROCESSOR_OBJECT_PROTO, LOCATION_OBJECT_PROTO };
|
|
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";
|
|
6
8
|
export * as Helper from "./helper";
|
|
7
9
|
export * as IpUtils from "./ip_utils";
|
|
8
10
|
export * as Tracer from "./tracer";
|
|
11
|
+
export * as Assertions from "./assertions";
|
|
12
|
+
export * as CommonConnect from "./connect";
|
package/dist/index.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.Tracer = exports.IpUtils = exports.Helper = exports.LOCATION_OBJECT_PROTO = exports.PROCESSOR_OBJECT_PROTO = exports.Method = exports.Transport = exports.ServiceUnavailableError = exports.calculateAuthResponse = exports.generateNonce = exports.getObjectProto = exports.createService = void 0;
|
|
26
|
+
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;
|
|
27
27
|
/*
|
|
28
28
|
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
29
29
|
* http://github.com/fonoster/routr
|
|
@@ -49,12 +49,16 @@ const errors_1 = require("./errors");
|
|
|
49
49
|
Object.defineProperty(exports, "ServiceUnavailableError", { enumerable: true, get: function () { return errors_1.ServiceUnavailableError; } });
|
|
50
50
|
const service_1 = __importStar(require("./service"));
|
|
51
51
|
exports.createService = service_1.default;
|
|
52
|
-
Object.defineProperty(exports, "PROCESSOR_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.PROCESSOR_OBJECT_PROTO; } });
|
|
53
|
-
Object.defineProperty(exports, "LOCATION_OBJECT_PROTO", { enumerable: true, get: function () { return service_1.LOCATION_OBJECT_PROTO; } });
|
|
54
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
55
|
const types_1 = require("./types");
|
|
56
|
-
Object.defineProperty(exports, "Transport", { enumerable: true, get: function () { return types_1.Transport; } });
|
|
57
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"));
|
|
58
60
|
exports.Helper = __importStar(require("./helper"));
|
|
59
61
|
exports.IpUtils = __importStar(require("./ip_utils"));
|
|
60
62
|
exports.Tracer = __importStar(require("./tracer"));
|
|
63
|
+
exports.Assertions = __importStar(require("./assertions"));
|
|
64
|
+
exports.CommonConnect = __importStar(require("./connect"));
|
package/dist/ip_utils.js
CHANGED
|
@@ -21,15 +21,15 @@ exports.isLocalnet = exports.addressCount = exports.hasIp = exports.formatNet =
|
|
|
21
21
|
*/
|
|
22
22
|
const ip_utils_1 = require("ip-utils");
|
|
23
23
|
const formatNet = (net) => {
|
|
24
|
-
if (net.split(
|
|
24
|
+
if (net.split("/").length === 1) {
|
|
25
25
|
if ((0, ip_utils_1.isValidIpv4)(net))
|
|
26
26
|
return `${net}/32`;
|
|
27
27
|
if ((0, ip_utils_1.isValidIpv6)(net))
|
|
28
28
|
return `${net}/128`;
|
|
29
|
-
throw
|
|
29
|
+
throw new Error("Invalid address! Must be a valid Ipv4 or Ipv6");
|
|
30
30
|
}
|
|
31
|
-
const p1 = net.split(
|
|
32
|
-
const p2 = net.split(
|
|
31
|
+
const p1 = net.split("/")[0];
|
|
32
|
+
const p2 = net.split("/")[1];
|
|
33
33
|
return (0, ip_utils_1.isValidIpv4)(p2)
|
|
34
34
|
? `${p1}/${(0, ip_utils_1.subnetInfo)(p1, p2).cidrMask}`
|
|
35
35
|
: `${p1}/${p2}`;
|
|
@@ -39,5 +39,5 @@ const hasIp = (net, addr) => (0, ip_utils_1.subnet)((0, exports.formatNet)(net))
|
|
|
39
39
|
exports.hasIp = hasIp;
|
|
40
40
|
const addressCount = (net) => (0, ip_utils_1.cidrInfo)((0, exports.formatNet)(net)).inclusiveNumberHosts;
|
|
41
41
|
exports.addressCount = addressCount;
|
|
42
|
-
const isLocalnet = (nets, addr) => nets && nets.length > 0 && nets.filter(net => (0, exports.hasIp)(net, addr)).length > 0;
|
|
42
|
+
const isLocalnet = (nets, addr) => nets && nets.length > 0 && nets.filter((net) => (0, exports.hasIp)(net, addr)).length > 0;
|
|
43
43
|
exports.isLocalnet = isLocalnet;
|
package/dist/protos/common.proto
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/routr
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Routr
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
1
19
|
syntax = "proto3";
|
|
2
20
|
|
|
3
21
|
package fonoster.routr.common.v2draft1;
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
3
|
+
* http://github.com/fonoster/routr
|
|
4
|
+
*
|
|
5
|
+
* This file is part of Routr
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the MIT License (the "License");
|
|
8
|
+
* you may not use this file except in compliance with
|
|
9
|
+
* the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://opensource.org/licenses/MIT
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
1
19
|
syntax = "proto3";
|
|
2
20
|
|
|
3
21
|
package fonoster.routr.location.v2draft1;
|
|
@@ -27,14 +45,9 @@ message Route {
|
|
|
27
45
|
int32 session_count = 7;
|
|
28
46
|
string edge_port_ref = 8;
|
|
29
47
|
fonoster.routr.processor.v2draft1.NetInterface listening_point = 9;
|
|
30
|
-
// During route creation, an endpoint can
|
|
31
|
-
// used as
|
|
32
|
-
// that it is the
|
|
33
|
-
//
|
|
34
|
-
// Another use case is to use the label to determine which endpoint will back certain
|
|
35
|
-
// feature. For example, we could use the label `backend=voice` to indicate that this
|
|
36
|
-
// route can serve voice applications. If the FindRoutes method includes the label the
|
|
37
|
-
// Location Service will only return routes that includes such label.
|
|
48
|
+
// During route creation, an endpoint can request to add labels than can later be
|
|
49
|
+
// used as selectors. For example, a Softphone can add a label `priority=1` to indicate
|
|
50
|
+
// that it is the prefered endpoint for the given AOR.
|
|
38
51
|
map<string, string> labels = 10;
|
|
39
52
|
}
|
|
40
53
|
|