@routr/pgdata 2.11.5 → 2.12.1
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/README.md +3 -0
- package/dist/api/update.js +3 -6
- package/dist/db.d.ts +28 -0
- package/dist/db.js +31 -0
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +2 -1
- package/dist/mappers/number.js +4 -4
- package/dist/service.js +9 -8
- package/package.json +8 -7
package/README.md
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
<a href="https://gitpod.io/#https://github.com/fonoster/routr"> <img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod" />
|
|
2
|
+
|
|
3
|
+
This module is part of the [Routr](https://routr.io) project. By itself, it does not do much. It is intended to be used as a dependency for other modules. For more information about the project, please visit [https://github.com/fonoster/routr](https://github.com/fonoster/routr).
|
package/dist/api/update.js
CHANGED
|
@@ -32,10 +32,7 @@ exports.update = void 0;
|
|
|
32
32
|
const pb_util_1 = require("pb-util");
|
|
33
33
|
const common_1 = require("@routr/common");
|
|
34
34
|
const utils_1 = require("../mappers/utils");
|
|
35
|
-
const
|
|
36
|
-
// TODO: The entire function should be wrapped in a transaction
|
|
37
|
-
// TODO: We should reuse the prisma client
|
|
38
|
-
const prisma = new client_1.PrismaClient();
|
|
35
|
+
const db_1 = require("../db");
|
|
39
36
|
function update(operation, kind) {
|
|
40
37
|
return (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
41
38
|
try {
|
|
@@ -47,14 +44,14 @@ function update(operation, kind) {
|
|
|
47
44
|
const manager = new Manager(request);
|
|
48
45
|
manager.validOrThrowUpdate();
|
|
49
46
|
if (kind === common_1.CommonConnect.Kind.DOMAIN) {
|
|
50
|
-
yield prisma.egressPolicy.deleteMany({
|
|
47
|
+
yield db_1.prisma.egressPolicy.deleteMany({
|
|
51
48
|
where: {
|
|
52
49
|
domainRef: request.ref
|
|
53
50
|
}
|
|
54
51
|
});
|
|
55
52
|
}
|
|
56
53
|
if (kind === common_1.CommonConnect.Kind.TRUNK) {
|
|
57
|
-
yield prisma.trunkURI.deleteMany({
|
|
54
|
+
yield db_1.prisma.trunkURI.deleteMany({
|
|
58
55
|
where: {
|
|
59
56
|
trunkRef: request.ref
|
|
60
57
|
}
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { PrismaClient } from "@prisma/client";
|
|
2
|
+
declare const prisma: PrismaClient<import(".prisma/client").Prisma.PrismaClientOptions, never, import("@prisma/client/runtime/library").DefaultArgs> | import("@prisma/client/runtime/library").DynamicClientExtensionThis<import(".prisma/client").Prisma.TypeMap<import("@prisma/client/runtime/library").InternalArgs<{
|
|
3
|
+
[x: string]: {
|
|
4
|
+
[x: string]: unknown;
|
|
5
|
+
};
|
|
6
|
+
}, {
|
|
7
|
+
[x: string]: {
|
|
8
|
+
[x: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
}, {
|
|
11
|
+
[x: string]: {
|
|
12
|
+
[x: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
}, {
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
}> & {
|
|
17
|
+
result: {};
|
|
18
|
+
model: {};
|
|
19
|
+
query: {};
|
|
20
|
+
client: {};
|
|
21
|
+
}>, import(".prisma/client").Prisma.TypeMapCb, {
|
|
22
|
+
result: {};
|
|
23
|
+
model: {};
|
|
24
|
+
query: {};
|
|
25
|
+
client: {};
|
|
26
|
+
}>;
|
|
27
|
+
type Prisma = typeof prisma;
|
|
28
|
+
export { prisma, Prisma };
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prisma = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 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 client_1 = require("@prisma/client");
|
|
23
|
+
const prisma_field_encryption_1 = require("prisma-field-encryption");
|
|
24
|
+
const envs_1 = require("./envs");
|
|
25
|
+
// Conditional Prisma Client initialization based on the presence of the encryption key
|
|
26
|
+
const prisma = envs_1.CLOAK_ENCRYPTION_KEY
|
|
27
|
+
? new client_1.PrismaClient().$extends((0, prisma_field_encryption_1.fieldEncryptionExtension)({
|
|
28
|
+
encryptionKey: envs_1.CLOAK_ENCRYPTION_KEY
|
|
29
|
+
}))
|
|
30
|
+
: new client_1.PrismaClient();
|
|
31
|
+
exports.prisma = prisma;
|
package/dist/envs.d.ts
CHANGED
package/dist/envs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var _a, _b, _c, _d, _e;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.EXTERNAL_SERVER_BIND_ADDR = exports.BIND_ADDR = exports.SERVER_KEY = exports.SERVER_CERT = exports.CACERT = exports.VERIFY_CLIENT_CERT = exports.TLS_ON = void 0;
|
|
4
|
+
exports.CLOAK_ENCRYPTION_KEY = exports.EXTERNAL_SERVER_BIND_ADDR = exports.BIND_ADDR = exports.SERVER_KEY = exports.SERVER_CERT = exports.CACERT = exports.VERIFY_CLIENT_CERT = exports.TLS_ON = void 0;
|
|
5
5
|
/*
|
|
6
6
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
7
7
|
* http://github.com/fonoster/routr
|
|
@@ -29,6 +29,7 @@ exports.SERVER_CERT = (_b = process.env.SERVER_CERT) !== null && _b !== void 0 ?
|
|
|
29
29
|
exports.SERVER_KEY = (_c = process.env.SERVER_KEY) !== null && _c !== void 0 ? _c : "/etc/routr/certs/server.key";
|
|
30
30
|
exports.BIND_ADDR = (_d = process.env.BIND_ADDR) !== null && _d !== void 0 ? _d : "0.0.0.0:51907";
|
|
31
31
|
exports.EXTERNAL_SERVER_BIND_ADDR = (_e = process.env.EXTERNAL_SERVER_BIND_ADDR) !== null && _e !== void 0 ? _e : "0.0.0.0:51908";
|
|
32
|
+
exports.CLOAK_ENCRYPTION_KEY = process.env.CLOAK_ENCRYPTION_KEY;
|
|
32
33
|
if (exports.TLS_ON) {
|
|
33
34
|
if (exports.VERIFY_CLIENT_CERT) {
|
|
34
35
|
common_1.Assertions.assertFileExist(exports.CACERT);
|
package/dist/mappers/number.js
CHANGED
|
@@ -34,7 +34,7 @@ class NumberManager extends manager_1.EntityManager {
|
|
|
34
34
|
common_1.CommonConnect.isValidAORLinkOrThrow(this.number.aorLink);
|
|
35
35
|
common_1.CommonConnect.hasCityOrThrow(this.number.city);
|
|
36
36
|
common_1.CommonConnect.hasCountryOrThrow(this.number.country);
|
|
37
|
-
common_1.CommonConnect.
|
|
37
|
+
common_1.CommonConnect.hasCountryIsoCodeOrThrow(this.number.countryIsoCode);
|
|
38
38
|
common_1.CommonConnect.hasValidHeadersOrThrow(this.number.extraHeaders);
|
|
39
39
|
common_1.CommonConnect.isValidSessionAffinityHeaderOrThrow(this.number.sessionAffinityHeader);
|
|
40
40
|
}
|
|
@@ -56,7 +56,7 @@ class NumberManager extends manager_1.EntityManager {
|
|
|
56
56
|
aorLink: this.number.aorLink || null,
|
|
57
57
|
city: this.number.city || undefined,
|
|
58
58
|
country: this.number.country,
|
|
59
|
-
|
|
59
|
+
countryIsoCode: this.number.countryIsoCode,
|
|
60
60
|
sessionAffinityHeader: this.number.sessionAffinityHeader || null,
|
|
61
61
|
extraHeaders: this.number.extraHeaders || null,
|
|
62
62
|
createdAt: this.number.createdAt
|
|
@@ -80,7 +80,7 @@ class NumberManager extends manager_1.EntityManager {
|
|
|
80
80
|
aorLink: number.aorLink,
|
|
81
81
|
city: number.city,
|
|
82
82
|
country: number.country,
|
|
83
|
-
countryIsoCode: number.
|
|
83
|
+
countryIsoCode: number.countryIsoCode,
|
|
84
84
|
sessionAffinityHeader: number.sessionAffinityHeader,
|
|
85
85
|
extraHeaders: number.extraHeaders,
|
|
86
86
|
extended: number.extended,
|
|
@@ -100,7 +100,7 @@ class NumberManager extends manager_1.EntityManager {
|
|
|
100
100
|
aorLink: number.aorLink,
|
|
101
101
|
city: number.city,
|
|
102
102
|
country: number.country,
|
|
103
|
-
countryIsoCode: number.
|
|
103
|
+
countryIsoCode: number.countryIsoCode,
|
|
104
104
|
sessionAffinityHeader: number.sessionAffinityHeader,
|
|
105
105
|
extraHeaders: number.extraHeaders,
|
|
106
106
|
extended: number.extended,
|
package/dist/service.js
CHANGED
|
@@ -47,19 +47,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
47
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
48
48
|
const common_1 = require("@routr/common");
|
|
49
49
|
const logger_1 = require("@fonoster/logger");
|
|
50
|
-
const client_1 = require("@prisma/client");
|
|
51
50
|
const create_1 = require("./api/create");
|
|
52
51
|
const update_1 = require("./api/update");
|
|
53
52
|
const get_1 = require("./api/get");
|
|
54
53
|
const delete_1 = require("./api/delete");
|
|
55
54
|
const find_1 = require("./api/find");
|
|
56
55
|
const list_1 = require("./api/list");
|
|
57
|
-
const grpc_health_check_1 = require("@fonoster/grpc-health-check");
|
|
58
56
|
const envs_1 = require("./envs");
|
|
59
57
|
const fs_1 = __importDefault(require("fs"));
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
58
|
+
const grpc_health_check_1 = require("grpc-health-check");
|
|
59
|
+
const common_2 = require("@fonoster/common");
|
|
60
|
+
const db_1 = require("./db");
|
|
63
61
|
const logger = (0, logger_1.getLogger)({ service: "pgdata", filePath: __filename });
|
|
64
62
|
/**
|
|
65
63
|
* Starts a new posgres data service.
|
|
@@ -68,6 +66,7 @@ const logger = (0, logger_1.getLogger)({ service: "pgdata", filePath: __filename
|
|
|
68
66
|
*/
|
|
69
67
|
function pgDataService(config) {
|
|
70
68
|
const { bindAddr } = config;
|
|
69
|
+
const healthImpl = new grpc_health_check_1.HealthImplementation(common_2.statusMap);
|
|
71
70
|
const internalServer = new grpc.Server();
|
|
72
71
|
const externalServer = new grpc.Server();
|
|
73
72
|
logger.info("starting routr service", { bindAddr, name: "pgdata" });
|
|
@@ -82,7 +81,7 @@ function pgDataService(config) {
|
|
|
82
81
|
];
|
|
83
82
|
kinds.forEach((kind) => {
|
|
84
83
|
const k = kind.toLowerCase();
|
|
85
|
-
const delegate = prisma[kind];
|
|
84
|
+
const delegate = db_1.prisma[kind];
|
|
86
85
|
const funcs = {
|
|
87
86
|
create: (0, create_1.create)(delegate.create, k),
|
|
88
87
|
get: (0, get_1.get)(delegate.findUnique, k),
|
|
@@ -95,8 +94,9 @@ function pgDataService(config) {
|
|
|
95
94
|
externalServer.addService(common_1.CommonConnect.createConnectService(k), funcs);
|
|
96
95
|
});
|
|
97
96
|
const credentials = grpc.ServerCredentials.createInsecure();
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
// Add the health check service to the server
|
|
98
|
+
healthImpl.addToServer(internalServer);
|
|
99
|
+
internalServer.bindAsync(config.bindAddr, credentials, () => {
|
|
100
100
|
logger.info("internal server started", { bindAddr: config.bindAddr });
|
|
101
101
|
});
|
|
102
102
|
if (envs_1.TLS_ON) {
|
|
@@ -119,6 +119,7 @@ function pgDataService(config) {
|
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
externalServer.bindAsync(config.externalServerBindAddr, credentials, () => {
|
|
122
|
+
healthImpl.setStatus("", common_2.GRPC_SERVING_STATUS);
|
|
122
123
|
logger.info("secure connection disabled");
|
|
123
124
|
logger.info("external server started", {
|
|
124
125
|
externalServerBindAddr: config.externalServerBindAddr
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@routr/pgdata",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"description": "Postgres API Server for Routr Connect",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/routr#readme",
|
|
@@ -19,9 +19,8 @@
|
|
|
19
19
|
"run_pgdata": "dist/runner.js"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@fonoster/
|
|
23
|
-
"@fonoster/
|
|
24
|
-
"@fonoster/logger": "0.3.20",
|
|
22
|
+
"@fonoster/common": "0.6.0",
|
|
23
|
+
"@fonoster/logger": "0.6.0",
|
|
25
24
|
"@grpc/grpc-js": "~1.10.1",
|
|
26
25
|
"@opentelemetry/api": "^1.0.4",
|
|
27
26
|
"@opentelemetry/exporter-jaeger": "^1.0.4",
|
|
@@ -32,11 +31,13 @@
|
|
|
32
31
|
"@opentelemetry/sdk-trace-node": "^1.0.4",
|
|
33
32
|
"@opentelemetry/semantic-conventions": "^1.0.4",
|
|
34
33
|
"@prisma/client": "^5.9.1",
|
|
35
|
-
"@routr/common": "^2.
|
|
36
|
-
"@routr/processor": "^2.
|
|
34
|
+
"@routr/common": "^2.12.1",
|
|
35
|
+
"@routr/processor": "^2.12.1",
|
|
37
36
|
"google-protobuf": "^3.9.2",
|
|
37
|
+
"grpc-health-check": "^2.0.2",
|
|
38
38
|
"pb-util": "^1.0.3",
|
|
39
39
|
"phone": "^3.1.32",
|
|
40
|
+
"prisma-field-encryption": "^1.5.2",
|
|
40
41
|
"validator": "^13.7.0"
|
|
41
42
|
},
|
|
42
43
|
"files": [
|
|
@@ -57,5 +58,5 @@
|
|
|
57
58
|
"@types/validator": "^13.7.10",
|
|
58
59
|
"prisma": "^5.9.1"
|
|
59
60
|
},
|
|
60
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "cf4c8276173ec4be0a8013e70935b6cffb29cda4"
|
|
61
62
|
}
|