@routr/registry 2.0.5-alpha.16
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/LICENSE +21 -0
- package/dist/config/get_config.d.ts +4 -0
- package/dist/config/get_config.js +77 -0
- package/dist/config/schema.d.ts +77 -0
- package/dist/config/schema.js +98 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.js +61 -0
- package/dist/grpc_client.d.ts +1 -0
- package/dist/grpc_client.js +56 -0
- package/dist/memory_store.d.ts +25 -0
- package/dist/memory_store.js +51 -0
- package/dist/redis_store.d.ts +22 -0
- package/dist/redis_store.js +89 -0
- package/dist/request.d.ts +10 -0
- package/dist/request.js +161 -0
- package/dist/runner.d.ts +2 -0
- package/dist/runner.js +39 -0
- package/dist/sender.d.ts +3 -0
- package/dist/sender.js +64 -0
- package/dist/service.d.ts +7 -0
- package/dist/service.js +103 -0
- package/dist/tracer.d.ts +7 -0
- package/dist/tracer.js +53 -0
- package/dist/types.d.ts +89 -0
- package/dist/types.js +15 -0
- package/dist/utils.d.ts +23 -0
- package/dist/utils.js +135 -0
- package/package.json +55 -0
package/dist/request.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
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.getPortFromAddress = exports.getHostFromAddress = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
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 common_1 = require("@routr/common");
|
|
26
|
+
const types_1 = require("./types");
|
|
27
|
+
const uniqid_1 = __importDefault(require("uniqid"));
|
|
28
|
+
// Global count for Registry CSEQ
|
|
29
|
+
let cseq = 1;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new Registration request.
|
|
32
|
+
*
|
|
33
|
+
* @param {RequestParams} params - The parameters to build the request
|
|
34
|
+
* @return {RegistrationRequest}
|
|
35
|
+
*/
|
|
36
|
+
function createRegistrationRequest(params) {
|
|
37
|
+
var _a;
|
|
38
|
+
const credentials = params.auth
|
|
39
|
+
? {
|
|
40
|
+
name: "X-Gateway-Auth",
|
|
41
|
+
value: Buffer.from(`${params.auth.username}:${params.auth.secret}`).toString("base64")
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
44
|
+
return {
|
|
45
|
+
target: params.targetAddress,
|
|
46
|
+
method: common_1.Method.REGISTER,
|
|
47
|
+
transport: params.transport,
|
|
48
|
+
trunkRef: params.trunkRef,
|
|
49
|
+
user: params.user,
|
|
50
|
+
message: {
|
|
51
|
+
extensions: [
|
|
52
|
+
...(((_a = params.methods) === null || _a === void 0 ? void 0 : _a.map((value) => {
|
|
53
|
+
return { name: "Allow", value };
|
|
54
|
+
})) || []),
|
|
55
|
+
{
|
|
56
|
+
name: "CSeq",
|
|
57
|
+
value: `${cseq++} ${common_1.Method.REGISTER}`
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "User-Agent",
|
|
61
|
+
// TODO: Take from central location (commons?)
|
|
62
|
+
value: params.userAgent || "Routr Connect v2"
|
|
63
|
+
},
|
|
64
|
+
// TODO: Q. Should this be in the registry configuration?
|
|
65
|
+
{
|
|
66
|
+
name: "Allow-Events",
|
|
67
|
+
value: "presence"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "Proxy-Require",
|
|
71
|
+
value: "gin"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "Require",
|
|
75
|
+
value: "gin"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "Supported",
|
|
79
|
+
value: "path"
|
|
80
|
+
},
|
|
81
|
+
credentials
|
|
82
|
+
],
|
|
83
|
+
route: [
|
|
84
|
+
{
|
|
85
|
+
address: {
|
|
86
|
+
uri: {
|
|
87
|
+
host: (0, exports.getHostFromAddress)(params.proxyAddress),
|
|
88
|
+
port: (0, exports.getPortFromAddress)(params.proxyAddress),
|
|
89
|
+
transportParam: params.transport,
|
|
90
|
+
lrParam: true
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
from: {
|
|
96
|
+
address: {
|
|
97
|
+
uri: {
|
|
98
|
+
user: params.user,
|
|
99
|
+
host: params.targetDomain,
|
|
100
|
+
port: -1,
|
|
101
|
+
transportParam: params.transport,
|
|
102
|
+
secure: params.secure
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
tag: uniqid_1.default.time()
|
|
106
|
+
},
|
|
107
|
+
to: {
|
|
108
|
+
address: {
|
|
109
|
+
uri: {
|
|
110
|
+
user: params.user,
|
|
111
|
+
host: params.targetDomain,
|
|
112
|
+
port: -1,
|
|
113
|
+
transportParam: params.transport,
|
|
114
|
+
secure: params.secure
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
callId: {
|
|
119
|
+
callId: (0, uniqid_1.default)()
|
|
120
|
+
},
|
|
121
|
+
contentLength: {
|
|
122
|
+
contentLength: 0
|
|
123
|
+
},
|
|
124
|
+
expires: {
|
|
125
|
+
expires: params.expires || types_1.DEFAULT_EXPIRES
|
|
126
|
+
},
|
|
127
|
+
maxForwards: {
|
|
128
|
+
maxForwards: params.maxForwards || types_1.DEFAULT_MAX_FORWARDS
|
|
129
|
+
},
|
|
130
|
+
requestUri: {
|
|
131
|
+
user: params.user,
|
|
132
|
+
host: (0, exports.getHostFromAddress)(params.targetAddress),
|
|
133
|
+
port: (0, exports.getPortFromAddress)(params.targetAddress),
|
|
134
|
+
transportParam: params.transport,
|
|
135
|
+
methodParam: common_1.Method.REGISTER,
|
|
136
|
+
secure: params.secure
|
|
137
|
+
},
|
|
138
|
+
messageType: "requestUri"
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
exports.default = createRegistrationRequest;
|
|
143
|
+
const getHostFromAddress = (address) => {
|
|
144
|
+
if (address.split(":").length != 2) {
|
|
145
|
+
throw new Error("malformated address; must be ${host}:${port}");
|
|
146
|
+
}
|
|
147
|
+
return address.split(":")[0];
|
|
148
|
+
};
|
|
149
|
+
exports.getHostFromAddress = getHostFromAddress;
|
|
150
|
+
const getPortFromAddress = (address) => {
|
|
151
|
+
if (address.split(":").length != 2) {
|
|
152
|
+
throw new Error("malformated address; must be ${host}:${port}");
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
return parseInt(address.split(":")[1]);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
throw new Error("expects port to be a number");
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
exports.getPortFromAddress = getPortFromAddress;
|
package/dist/runner.d.ts
ADDED
package/dist/runner.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
26
|
+
require("./tracer").init("dispatcher");
|
|
27
|
+
const service_1 = __importDefault(require("./service"));
|
|
28
|
+
const get_config_1 = require("./config/get_config");
|
|
29
|
+
const common_1 = require("@routr/common");
|
|
30
|
+
const logger_1 = require("@fonoster/logger");
|
|
31
|
+
const logger = (0, logger_1.getLogger)({ service: "simpleauth", filePath: __filename });
|
|
32
|
+
common_1.Assertions.assertEnvsAreSet(["CONFIG_PATH"]);
|
|
33
|
+
const config = (0, get_config_1.getConfig)(process.env.CONFIG_PATH);
|
|
34
|
+
if (config._tag === "Right") {
|
|
35
|
+
(0, service_1.default)(config.right);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
logger.error(config.left);
|
|
39
|
+
}
|
package/dist/sender.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ServiceUnavailableError } from "@routr/common";
|
|
2
|
+
import { RegistrationRequest, SendMessageResponse } from "./types";
|
|
3
|
+
export declare const sendRegisterMessage: (requesterAddr: string) => (request: RegistrationRequest) => Promise<ServiceUnavailableError | SendMessageResponse>;
|
package/dist/sender.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
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.sendRegisterMessage = 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 common_1 = require("@routr/common");
|
|
47
|
+
const grpc_client_1 = require("./grpc_client");
|
|
48
|
+
const sendRegisterMessage = (requesterAddr) => {
|
|
49
|
+
return (request) => {
|
|
50
|
+
const client = new grpc_client_1.requester.v2draft1.Requester(requesterAddr, grpc.credentials.createInsecure());
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
client.sendMessage(request, (err, response) => {
|
|
53
|
+
if ((err === null || err === void 0 ? void 0 : err.code) === 14) {
|
|
54
|
+
return reject(new common_1.ServiceUnavailableError(requesterAddr));
|
|
55
|
+
}
|
|
56
|
+
else if (err) {
|
|
57
|
+
return reject(err);
|
|
58
|
+
}
|
|
59
|
+
resolve(Object.assign({ trunkRef: request.trunkRef }, response));
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.sendRegisterMessage = sendRegisterMessage;
|
package/dist/service.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
/*
|
|
16
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
17
|
+
* http://github.com/fonoster/routr
|
|
18
|
+
*
|
|
19
|
+
* This file is part of Routr
|
|
20
|
+
*
|
|
21
|
+
* Licensed under the MIT License (the "License");
|
|
22
|
+
* you may not use this file except in compliance with
|
|
23
|
+
* the License. You may obtain a copy of the License at
|
|
24
|
+
*
|
|
25
|
+
* https://opensource.org/licenses/MIT
|
|
26
|
+
*
|
|
27
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
28
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
29
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
30
|
+
* See the License for the specific language governing permissions and
|
|
31
|
+
* limitations under the License.
|
|
32
|
+
*/
|
|
33
|
+
const sender_1 = require("./sender");
|
|
34
|
+
const request_1 = __importDefault(require("./request"));
|
|
35
|
+
const types_1 = require("./types");
|
|
36
|
+
const utils_1 = require("./utils");
|
|
37
|
+
const common_1 = require("@routr/common");
|
|
38
|
+
const logger_1 = require("@fonoster/logger");
|
|
39
|
+
const common_2 = require("@routr/common");
|
|
40
|
+
const logger = (0, logger_1.getLogger)({ service: "registry", filePath: __filename });
|
|
41
|
+
const DEFAULT_REGISTRATION_INTERVAL = 60 * 1000;
|
|
42
|
+
const DEFAULT_RETENTION_TIME = 600 * 1000;
|
|
43
|
+
// TODO:
|
|
44
|
+
// - We need to filter quarentine trunks from final list of trunks
|
|
45
|
+
/**
|
|
46
|
+
* Loops through all the services and register them with the registry.
|
|
47
|
+
*
|
|
48
|
+
* @param {RegistryConfig} config
|
|
49
|
+
*/
|
|
50
|
+
function registryService(config) {
|
|
51
|
+
logger.info("starting registry service");
|
|
52
|
+
const store = (0, utils_1.buildStore)(config);
|
|
53
|
+
// Creates internval to send registration request every X seconds
|
|
54
|
+
setInterval(() => __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
logger.verbose("starting registration process");
|
|
56
|
+
let resources = [];
|
|
57
|
+
const dataAPI = common_1.CommonConnect.dataAPI(config.apiAddr);
|
|
58
|
+
try {
|
|
59
|
+
resources = yield (0, utils_1.findTrunks)(dataAPI);
|
|
60
|
+
}
|
|
61
|
+
catch (err) {
|
|
62
|
+
logger.error("failed to retrieve trunks from API", err);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const registryInvocations = resources.map((resource) => __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const registrationRequestInput = (0, utils_1.registrationRequestInputFromTrunk)(yield (0, utils_1.convertResourceToTrunk)(dataAPI, resource), config);
|
|
67
|
+
const request = (0, request_1.default)(registrationRequestInput);
|
|
68
|
+
return (0, sender_1.sendRegisterMessage)(config.requesterAddr)(request);
|
|
69
|
+
}));
|
|
70
|
+
const results = yield Promise.allSettled(registryInvocations);
|
|
71
|
+
results === null || results === void 0 ? void 0 : results.forEach((result) => __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
var _a;
|
|
73
|
+
logger.verbose("processing registration result", { result });
|
|
74
|
+
if (result.status === "rejected") {
|
|
75
|
+
logger.error("request rejected", result.reason);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (result.value instanceof common_2.ServiceUnavailableError) {
|
|
79
|
+
logger.error("service unavailable", result.value);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const message = result.value.message;
|
|
83
|
+
const retentionTime = ((_a = message.expires) === null || _a === void 0 ? void 0 : _a.expires) || DEFAULT_RETENTION_TIME;
|
|
84
|
+
// TODO: Refactor to use ResponseType instead of string
|
|
85
|
+
const status = message.responseType.toString() == "OK"
|
|
86
|
+
? types_1.RegistrationEntryStatus.REGISTERED
|
|
87
|
+
: types_1.RegistrationEntryStatus.QUARANTINE;
|
|
88
|
+
// Storing trunk in registry with status and retention time
|
|
89
|
+
logger.verbose("storing trunk in registry", {
|
|
90
|
+
trunkRef: result.value.trunkRef,
|
|
91
|
+
status,
|
|
92
|
+
retentionTime
|
|
93
|
+
});
|
|
94
|
+
store.put(result.value.trunkRef, {
|
|
95
|
+
trunkRef: result.value.trunkRef,
|
|
96
|
+
timeOfEntry: new Date().getTime(),
|
|
97
|
+
retentionTimeInSeconds: retentionTime,
|
|
98
|
+
status
|
|
99
|
+
});
|
|
100
|
+
}));
|
|
101
|
+
}), config.registerInterval * 1000 || DEFAULT_REGISTRATION_INTERVAL);
|
|
102
|
+
}
|
|
103
|
+
exports.default = registryService;
|
package/dist/tracer.d.ts
ADDED
package/dist/tracer.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
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.init = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (C) 2022 by Fonoster Inc (https://fonoster.com)
|
|
9
|
+
* http://github.com/fonoster/routr
|
|
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 api_1 = __importDefault(require("@opentelemetry/api"));
|
|
26
|
+
const instrumentation_1 = require("@opentelemetry/instrumentation");
|
|
27
|
+
const sdk_trace_node_1 = require("@opentelemetry/sdk-trace-node");
|
|
28
|
+
const resources_1 = require("@opentelemetry/resources");
|
|
29
|
+
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
30
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
31
|
+
const exporter_jaeger_1 = require("@opentelemetry/exporter-jaeger");
|
|
32
|
+
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
|
|
33
|
+
/**
|
|
34
|
+
* This function registers the instrumentations for the service.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} serviceName - The name of the service.
|
|
37
|
+
* @return {Tracer} The tracer object.
|
|
38
|
+
*/
|
|
39
|
+
function init(serviceName) {
|
|
40
|
+
const provider = new sdk_trace_node_1.NodeTracerProvider({
|
|
41
|
+
resource: new resources_1.Resource({
|
|
42
|
+
[semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: serviceName
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
const exporter = new exporter_jaeger_1.JaegerExporter();
|
|
46
|
+
provider.addSpanProcessor(new sdk_trace_base_1.SimpleSpanProcessor(exporter));
|
|
47
|
+
provider.register();
|
|
48
|
+
(0, instrumentation_1.registerInstrumentations)({
|
|
49
|
+
instrumentations: [new instrumentation_grpc_1.GrpcInstrumentation()]
|
|
50
|
+
});
|
|
51
|
+
return api_1.default.trace.getTracer("routr-tracer");
|
|
52
|
+
}
|
|
53
|
+
exports.init = init;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Method, Transport } from "@routr/common";
|
|
2
|
+
import { SIPMessage } from "@routr/common/src/types";
|
|
3
|
+
export declare const DEFAULT_MAX_FORWARDS = 70;
|
|
4
|
+
export declare const DEFAULT_EXPIRES = 600;
|
|
5
|
+
export declare enum CACHE_PROVIDER {
|
|
6
|
+
MEMORY = "memory",
|
|
7
|
+
REDIS = "redis"
|
|
8
|
+
}
|
|
9
|
+
export declare enum RegistrationEntryStatus {
|
|
10
|
+
REGISTERED = "registered",
|
|
11
|
+
QUARANTINE = "quarantine"
|
|
12
|
+
}
|
|
13
|
+
export interface EdgePort {
|
|
14
|
+
address: string;
|
|
15
|
+
region: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RegistryConfig {
|
|
18
|
+
bindAddr: string;
|
|
19
|
+
requesterAddr: string;
|
|
20
|
+
apiAddr: string;
|
|
21
|
+
edgePorts: EdgePort[];
|
|
22
|
+
registerInterval: number;
|
|
23
|
+
methods: Method[];
|
|
24
|
+
cache?: {
|
|
25
|
+
provider: CACHE_PROVIDER;
|
|
26
|
+
parameters?: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface RegistrationRequest {
|
|
30
|
+
trunkRef: string;
|
|
31
|
+
target: string;
|
|
32
|
+
user: string;
|
|
33
|
+
method: Method;
|
|
34
|
+
transport: Transport;
|
|
35
|
+
message: SIPMessage;
|
|
36
|
+
}
|
|
37
|
+
export interface SendMessageResponse {
|
|
38
|
+
trunkRef: string;
|
|
39
|
+
message: SIPMessage;
|
|
40
|
+
}
|
|
41
|
+
export interface RedisStoreConfig {
|
|
42
|
+
username?: string;
|
|
43
|
+
password?: string;
|
|
44
|
+
host: string;
|
|
45
|
+
port: number;
|
|
46
|
+
secure?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface RequestParams {
|
|
49
|
+
user: string;
|
|
50
|
+
trunkRef: string;
|
|
51
|
+
targetDomain: string;
|
|
52
|
+
targetAddress: string;
|
|
53
|
+
proxyAddress: string;
|
|
54
|
+
transport: Transport;
|
|
55
|
+
userAgent?: string;
|
|
56
|
+
methods?: Method[];
|
|
57
|
+
maxForwards?: number;
|
|
58
|
+
expires?: number;
|
|
59
|
+
secure?: boolean;
|
|
60
|
+
auth?: {
|
|
61
|
+
username: string;
|
|
62
|
+
secret: string;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export interface RegistrationEntry {
|
|
66
|
+
trunkRef: string;
|
|
67
|
+
timeOfEntry: number;
|
|
68
|
+
retentionTimeInSeconds: number;
|
|
69
|
+
status: RegistrationEntryStatus;
|
|
70
|
+
}
|
|
71
|
+
export interface IRegistryStore {
|
|
72
|
+
put(key: string, entry: RegistrationEntry): Promise<void>;
|
|
73
|
+
get(key: string): Promise<RegistrationEntry>;
|
|
74
|
+
delete(key: string): Promise<void>;
|
|
75
|
+
list(): Promise<RegistrationEntry[]>;
|
|
76
|
+
}
|
|
77
|
+
export interface Trunk {
|
|
78
|
+
ref: string;
|
|
79
|
+
name: string;
|
|
80
|
+
region: string;
|
|
81
|
+
host: string;
|
|
82
|
+
port: number;
|
|
83
|
+
user: string;
|
|
84
|
+
credentials?: {
|
|
85
|
+
username: string;
|
|
86
|
+
secret: string;
|
|
87
|
+
};
|
|
88
|
+
transport: Transport;
|
|
89
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RegistrationEntryStatus = exports.CACHE_PROVIDER = exports.DEFAULT_EXPIRES = exports.DEFAULT_MAX_FORWARDS = void 0;
|
|
4
|
+
exports.DEFAULT_MAX_FORWARDS = 70;
|
|
5
|
+
exports.DEFAULT_EXPIRES = 600;
|
|
6
|
+
var CACHE_PROVIDER;
|
|
7
|
+
(function (CACHE_PROVIDER) {
|
|
8
|
+
CACHE_PROVIDER["MEMORY"] = "memory";
|
|
9
|
+
CACHE_PROVIDER["REDIS"] = "redis";
|
|
10
|
+
})(CACHE_PROVIDER = exports.CACHE_PROVIDER || (exports.CACHE_PROVIDER = {}));
|
|
11
|
+
var RegistrationEntryStatus;
|
|
12
|
+
(function (RegistrationEntryStatus) {
|
|
13
|
+
RegistrationEntryStatus["REGISTERED"] = "registered";
|
|
14
|
+
RegistrationEntryStatus["QUARANTINE"] = "quarantine";
|
|
15
|
+
})(RegistrationEntryStatus = exports.RegistrationEntryStatus || (exports.RegistrationEntryStatus = {}));
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Transport } from "@routr/common";
|
|
2
|
+
import { CommonConnect as CC } from "@routr/common";
|
|
3
|
+
import MemoryStore from "./memory_store";
|
|
4
|
+
import RedisStore from "./redis_store";
|
|
5
|
+
import { IRegistryStore, RegistryConfig, Trunk } from "./types";
|
|
6
|
+
export declare function getUnregisteredTrunks(store: IRegistryStore): (trunks: Trunk[]) => Promise<Trunk[]>;
|
|
7
|
+
export declare function findTrunks(dataAPI: CC.DataAPI): Promise<CC.Resource[]>;
|
|
8
|
+
export declare const configFromString: (params: string, allowedKeys: string[]) => Record<string, string | boolean>;
|
|
9
|
+
export declare const buildStore: (config: RegistryConfig) => MemoryStore | RedisStore;
|
|
10
|
+
export declare const convertResourceToTrunk: (dataAPI: CC.DataAPI, resource: CC.Resource) => Promise<Trunk>;
|
|
11
|
+
export declare const registrationRequestInputFromTrunk: (trunk: Trunk, config: RegistryConfig) => {
|
|
12
|
+
trunkRef: string;
|
|
13
|
+
user: string;
|
|
14
|
+
targetDomain: string;
|
|
15
|
+
targetAddress: string;
|
|
16
|
+
proxyAddress: string;
|
|
17
|
+
transport: Transport;
|
|
18
|
+
auth: {
|
|
19
|
+
username: string;
|
|
20
|
+
secret: string;
|
|
21
|
+
};
|
|
22
|
+
methods: import("@routr/common").Method[];
|
|
23
|
+
};
|