@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/utils.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.registrationRequestInputFromTrunk = exports.convertResourceToTrunk = exports.buildStore = exports.configFromString = exports.findTrunks = exports.getUnregisteredTrunks = void 0;
|
|
39
|
+
const common_1 = require("@routr/common");
|
|
40
|
+
const memory_store_1 = __importDefault(require("./memory_store"));
|
|
41
|
+
const redis_store_1 = __importDefault(require("./redis_store"));
|
|
42
|
+
const types_1 = require("./types");
|
|
43
|
+
const protobufUtil = __importStar(require("pb-util"));
|
|
44
|
+
const jsonFromStruct = protobufUtil.struct.decode;
|
|
45
|
+
// eslint-disable-next-line require-jsdoc
|
|
46
|
+
function getUnregisteredTrunks(store) {
|
|
47
|
+
return (trunks) => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const registryEntries = yield store.list();
|
|
49
|
+
return trunks === null || trunks === void 0 ? void 0 : trunks.filter((t) => !registryEntries
|
|
50
|
+
.map((r) => r.trunkRef)
|
|
51
|
+
.includes(t.ref));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.getUnregisteredTrunks = getUnregisteredTrunks;
|
|
55
|
+
// eslint-disable-next-line require-jsdoc
|
|
56
|
+
function findTrunks(dataAPI) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return yield dataAPI.findBy({
|
|
59
|
+
kind: common_1.CommonConnect.KIND.TRUNK,
|
|
60
|
+
criteria: common_1.CommonConnect.FindCriteria.FIND_TRUNKS_WITH_SEND_REGISTER,
|
|
61
|
+
parameters: {}
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
exports.findTrunks = findTrunks;
|
|
66
|
+
const configFromString = (params, allowedKeys) => {
|
|
67
|
+
if (params.length === 0)
|
|
68
|
+
return {};
|
|
69
|
+
const parameters = {};
|
|
70
|
+
params.split(",").forEach((par) => {
|
|
71
|
+
try {
|
|
72
|
+
const key = par.split("=")[0];
|
|
73
|
+
const value = par.split("=")[1];
|
|
74
|
+
if (allowedKeys.indexOf(key) === -1) {
|
|
75
|
+
throw new Error(`invalid parameter: ${key}`);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
parameters[key] = value === "true" ? true : value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
throw new Error(`invalid parameters string: ${params}; should be something like 'host=localhost,port=6379'`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
return parameters;
|
|
86
|
+
};
|
|
87
|
+
exports.configFromString = configFromString;
|
|
88
|
+
const buildStore = (config) => {
|
|
89
|
+
if (config.cache.provider === types_1.CACHE_PROVIDER.REDIS) {
|
|
90
|
+
const allowedParameters = ["host", "port", "username", "password", "secure"];
|
|
91
|
+
return new redis_store_1.default((0, exports.configFromString)(config.cache.parameters, allowedParameters));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return new memory_store_1.default();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports.buildStore = buildStore;
|
|
98
|
+
const convertResourceToTrunk = (dataAPI, resource) => __awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
var _a, _b, _c, _d;
|
|
100
|
+
const metadata = resource.metadata;
|
|
101
|
+
const trunkSpec = jsonFromStruct(resource.spec);
|
|
102
|
+
const uri = (_b = (_a = trunkSpec.outbound) === null || _a === void 0 ? void 0 : _a.uris[0]) === null || _b === void 0 ? void 0 : _b.uri;
|
|
103
|
+
// WARNING: Perhaps we should bring this on a single API call
|
|
104
|
+
const credentials = yield dataAPI.get((_c = trunkSpec.outbound) === null || _c === void 0 ? void 0 : _c.credentialsRef);
|
|
105
|
+
const credSpec = jsonFromStruct(credentials.spec);
|
|
106
|
+
const usernameAndPassword = credSpec.credentials;
|
|
107
|
+
return {
|
|
108
|
+
ref: resource.metadata.ref,
|
|
109
|
+
name: resource.metadata.name,
|
|
110
|
+
region: metadata.region,
|
|
111
|
+
host: uri.host,
|
|
112
|
+
port: uri.port || 5060,
|
|
113
|
+
user: uri.user,
|
|
114
|
+
credentials: {
|
|
115
|
+
username: usernameAndPassword.username,
|
|
116
|
+
secret: usernameAndPassword.password
|
|
117
|
+
},
|
|
118
|
+
transport: (((_d = uri.transport) === null || _d === void 0 ? void 0 : _d.toUpperCase()) || "TCP")
|
|
119
|
+
};
|
|
120
|
+
});
|
|
121
|
+
exports.convertResourceToTrunk = convertResourceToTrunk;
|
|
122
|
+
const registrationRequestInputFromTrunk = (trunk, config) => {
|
|
123
|
+
return {
|
|
124
|
+
trunkRef: trunk.ref,
|
|
125
|
+
user: trunk.user,
|
|
126
|
+
targetDomain: trunk.host,
|
|
127
|
+
targetAddress: `${trunk.host}:${trunk.port}`,
|
|
128
|
+
// TODO: Find closest edgeport instead of [0]
|
|
129
|
+
proxyAddress: config.edgePorts[0].address,
|
|
130
|
+
transport: trunk.transport,
|
|
131
|
+
auth: trunk.credentials,
|
|
132
|
+
methods: config.methods
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
exports.registrationRequestInputFromTrunk = registrationRequestInputFromTrunk;
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@routr/registry",
|
|
3
|
+
"version": "2.0.5-alpha.16",
|
|
4
|
+
"description": "Sends trunks registrations and maintains their bindings",
|
|
5
|
+
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
|
+
"homepage": "https://github.com/fonoster/routr#readme",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "dist/index",
|
|
9
|
+
"types": "dist/index",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
|
|
12
|
+
"build": "tsc -b tsconfig.json"
|
|
13
|
+
},
|
|
14
|
+
"bin": {
|
|
15
|
+
"run_location": "dist/runner.js"
|
|
16
|
+
},
|
|
17
|
+
"directories": {
|
|
18
|
+
"src": "src",
|
|
19
|
+
"test": "test"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist"
|
|
23
|
+
],
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@grpc/grpc-js": "^1.5.9",
|
|
29
|
+
"@opentelemetry/api": "^1.0.4",
|
|
30
|
+
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
31
|
+
"@opentelemetry/instrumentation": "^0.27.0",
|
|
32
|
+
"@opentelemetry/instrumentation-grpc": "^0.27.0",
|
|
33
|
+
"@opentelemetry/resources": "^1.0.4",
|
|
34
|
+
"@opentelemetry/sdk-trace-base": "^1.0.4",
|
|
35
|
+
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
36
|
+
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
37
|
+
"@routr/common": "^2.0.5-alpha.16",
|
|
38
|
+
"@routr/processor": "^2.0.5-alpha.16",
|
|
39
|
+
"ajv": "^6.12.6",
|
|
40
|
+
"fp-ts": "^2.11.8",
|
|
41
|
+
"redis": "^4.0.4",
|
|
42
|
+
"uniqid": "^5.4.0"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/fonoster/routr.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/fonoster/routr/issues"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/uniqid": "^5.3.2"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "b40323ac18cc3872b168bf4e8273f5bdb3f7510a"
|
|
55
|
+
}
|