@fonoster/common 0.8.18 → 0.8.21
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/constants.d.ts +2 -0
- package/dist/constants.js +3 -1
- package/dist/errors/handleError.js +9 -6
- package/dist/types.d.ts +1 -4
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/makeFetchSingleCall.d.ts +4 -0
- package/dist/utils/makeFetchSingleCall.js +49 -0
- package/dist/utils/types.d.ts +5 -0
- package/dist/utils/types.js +2 -0
- package/dist/validators/sipnet/trunks.d.ts +1 -1
- package/dist/validators/sipnet/trunks.js +1 -1
- package/package.json +4 -3
package/dist/constants.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ import { ServingStatus } from "grpc-health-check";
|
|
|
2
2
|
export declare const GRPC_NOT_SERVING_STATUS: ServingStatus;
|
|
3
3
|
export declare const GRPC_SERVING_STATUS: ServingStatus;
|
|
4
4
|
export declare const STASIS_APP_NAME = "mediacontroller";
|
|
5
|
+
export declare const CALL_DETAIL_RECORD_MEASUREMENT = "cdr";
|
|
6
|
+
export declare const INFLUXDB_CALLS_BUCKET = "calls";
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.STASIS_APP_NAME = exports.GRPC_SERVING_STATUS = exports.GRPC_NOT_SERVING_STATUS = void 0;
|
|
3
|
+
exports.INFLUXDB_CALLS_BUCKET = exports.CALL_DETAIL_RECORD_MEASUREMENT = exports.STASIS_APP_NAME = exports.GRPC_SERVING_STATUS = exports.GRPC_NOT_SERVING_STATUS = void 0;
|
|
4
4
|
exports.GRPC_NOT_SERVING_STATUS = "NOT_SERVING";
|
|
5
5
|
exports.GRPC_SERVING_STATUS = "SERVING";
|
|
6
6
|
exports.STASIS_APP_NAME = "mediacontroller";
|
|
7
|
+
exports.CALL_DETAIL_RECORD_MEASUREMENT = "cdr";
|
|
8
|
+
exports.INFLUXDB_CALLS_BUCKET = "calls";
|
|
@@ -77,24 +77,27 @@ function handleError(error, callback) {
|
|
|
77
77
|
switch (code) {
|
|
78
78
|
case PrismaErrorEnum_1.PrismaErrorEnum.RECORD_ALREADY_EXISTS:
|
|
79
79
|
case grpc.status.ALREADY_EXISTS:
|
|
80
|
-
logAndCallback(grpc_js_1.status.ALREADY_EXISTS,
|
|
80
|
+
logAndCallback(grpc_js_1.status.ALREADY_EXISTS, "The resource already exists", "duplicated entity error");
|
|
81
81
|
break;
|
|
82
82
|
case PrismaErrorEnum_1.PrismaErrorEnum.RECORD_NOT_FOUND:
|
|
83
83
|
case grpc.status.NOT_FOUND:
|
|
84
|
-
logAndCallback(grpc_js_1.status.NOT_FOUND,
|
|
84
|
+
logAndCallback(grpc_js_1.status.NOT_FOUND, "The requested resource was not found", "not found error");
|
|
85
85
|
break;
|
|
86
86
|
case PrismaErrorEnum_1.PrismaErrorEnum.FAILED_PRECONDITION:
|
|
87
87
|
case grpc.status.FAILED_PRECONDITION:
|
|
88
|
-
logAndCallback(grpc_js_1.status.FAILED_PRECONDITION,
|
|
88
|
+
logAndCallback(grpc_js_1.status.FAILED_PRECONDITION, "Failed precondition error (e.g., missing dependency)", "failed precondition error");
|
|
89
89
|
break;
|
|
90
90
|
case grpc.status.PERMISSION_DENIED:
|
|
91
|
-
logAndCallback(grpc_js_1.status.PERMISSION_DENIED,
|
|
91
|
+
logAndCallback(grpc_js_1.status.PERMISSION_DENIED, "You don't have permission to perform this action", "permission denied error");
|
|
92
92
|
break;
|
|
93
93
|
case grpc.status.UNAUTHENTICATED:
|
|
94
|
-
logAndCallback(grpc_js_1.status.UNAUTHENTICATED,
|
|
94
|
+
logAndCallback(grpc_js_1.status.UNAUTHENTICATED, "You need to be authenticated to perform this action", "unauthenticated error");
|
|
95
|
+
break;
|
|
96
|
+
case grpc.status.INVALID_ARGUMENT:
|
|
97
|
+
logAndCallback(grpc_js_1.status.INVALID_ARGUMENT, message !== null && message !== void 0 ? message : "Your request has invalid arguments", "invalid argument error");
|
|
95
98
|
break;
|
|
96
99
|
default:
|
|
97
100
|
logger.error("unknown error:", error);
|
|
98
|
-
callback({ code: grpc_js_1.status.UNKNOWN, message:
|
|
101
|
+
callback({ code: grpc_js_1.status.UNKNOWN, message: "Unknown error" });
|
|
99
102
|
}
|
|
100
103
|
}
|
package/dist/types.d.ts
CHANGED
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -43,3 +43,4 @@ __exportStar(require("./toPascalCase"), exports);
|
|
|
43
43
|
__exportStar(require("./withErrorHandling"), exports);
|
|
44
44
|
__exportStar(require("./withErrorHandlingAndValidation"), exports);
|
|
45
45
|
__exportStar(require("./withValidation"), exports);
|
|
46
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createFetchSingleCall = createFetchSingleCall;
|
|
13
|
+
/*
|
|
14
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
|
+
* http://github.com/fonoster/fonoster
|
|
16
|
+
*
|
|
17
|
+
* This file is part of Fonoster
|
|
18
|
+
*
|
|
19
|
+
* Licensed under the MIT License (the "License");
|
|
20
|
+
* you may not use this file except in compliance with
|
|
21
|
+
* the License. You may obtain a copy of the License at
|
|
22
|
+
*
|
|
23
|
+
* https://opensource.org/licenses/MIT
|
|
24
|
+
*
|
|
25
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
26
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
27
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
28
|
+
* See the License for the specific language governing permissions and
|
|
29
|
+
* limitations under the License.
|
|
30
|
+
*/
|
|
31
|
+
const influxdb_client_1 = require("@influxdata/influxdb-client");
|
|
32
|
+
const constants_1 = require("../constants");
|
|
33
|
+
function createFetchSingleCall(influxdb) {
|
|
34
|
+
return (accessKeyId, callId) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const query = (0, influxdb_client_1.flux) `from(bucket: "${constants_1.INFLUXDB_CALLS_BUCKET}")
|
|
36
|
+
|> range(start: -5m)
|
|
37
|
+
|> pivot(rowKey: ["callId"], columnKey: ["_field"], valueColumn: "_value")
|
|
38
|
+
|> map(fn: (r) => ({
|
|
39
|
+
r with
|
|
40
|
+
duration: int(v: r.endedAt) - int(v: r.startedAt)
|
|
41
|
+
}))
|
|
42
|
+
|> filter(fn: (r) => r._measurement == "${constants_1.CALL_DETAIL_RECORD_MEASUREMENT}")
|
|
43
|
+
|> filter(fn: (r) => r.callId == ${callId} and r.accessKeyId == "${accessKeyId}")
|
|
44
|
+
|> sort(columns: ["_time"], desc: true)
|
|
45
|
+
|> limit(n: 1)`;
|
|
46
|
+
const items = (yield influxdb.collectRows(query));
|
|
47
|
+
return items.length > 0 ? items[0] : null;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -8,7 +8,7 @@ declare const createTrunkRequestSchema: z.ZodObject<{
|
|
|
8
8
|
host: z.ZodEffects<z.ZodString, string, string>;
|
|
9
9
|
port: z.ZodNumber;
|
|
10
10
|
transport: z.ZodNativeEnum<typeof Transport>;
|
|
11
|
-
user: z.ZodString
|
|
11
|
+
user: z.ZodOptional<z.ZodString>;
|
|
12
12
|
weight: z.ZodNumber;
|
|
13
13
|
priority: z.ZodNumber;
|
|
14
14
|
enabled: z.ZodBoolean;
|
|
@@ -69,7 +69,7 @@ const createTrunkRequestSchema = zod_1.z.object({
|
|
|
69
69
|
host: hostOrIPSchema,
|
|
70
70
|
port: zod_1.z.number(),
|
|
71
71
|
transport: zod_1.z.nativeEnum(types_1.Transport, { message: "Invalid transport" }),
|
|
72
|
-
user: zod_1.z.string(),
|
|
72
|
+
user: zod_1.z.string().optional(),
|
|
73
73
|
weight: zod_1.z.number(),
|
|
74
74
|
priority: zod_1.z.number(),
|
|
75
75
|
enabled: zod_1.z.boolean()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/common",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.21",
|
|
4
4
|
"description": "Common library for Fonoster projects",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -18,9 +18,10 @@
|
|
|
18
18
|
"clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@fonoster/logger": "^0.8.
|
|
21
|
+
"@fonoster/logger": "^0.8.20",
|
|
22
22
|
"@grpc/grpc-js": "~1.10.6",
|
|
23
23
|
"@grpc/proto-loader": "^0.7.12",
|
|
24
|
+
"@influxdata/influxdb-client": "^1.35.0",
|
|
24
25
|
"dotenv": "^16.4.7",
|
|
25
26
|
"grpc-health-check": "^2.0.2",
|
|
26
27
|
"handlebars": "^4.7.8",
|
|
@@ -45,5 +46,5 @@
|
|
|
45
46
|
"devDependencies": {
|
|
46
47
|
"@types/nodemailer": "^6.4.14"
|
|
47
48
|
},
|
|
48
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "2590a20d7309494faca50831ac0c0abdb14c2308"
|
|
49
50
|
}
|