@fonoster/common 0.8.20 → 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.
@@ -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";
package/dist/types.d.ts CHANGED
@@ -1,8 +1,5 @@
1
- type BaseApiObject = {
2
- ref: string;
3
- };
4
1
  type NumberPreconditionsCheck = (request: {
5
2
  appRef?: string;
6
3
  agentAor?: string;
7
4
  }) => Promise<void>;
8
- export { BaseApiObject, NumberPreconditionsCheck };
5
+ export { NumberPreconditionsCheck };
@@ -9,3 +9,4 @@ export * from "./toPascalCase";
9
9
  export * from "./withErrorHandling";
10
10
  export * from "./withErrorHandlingAndValidation";
11
11
  export * from "./withValidation";
12
+ export * from "./types";
@@ -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,4 @@
1
+ import { CallDetailRecord } from "@fonoster/types";
2
+ import { InfluxDBClient } from "./types";
3
+ declare function createFetchSingleCall(influxdb: InfluxDBClient): (accessKeyId: string, callId: string) => Promise<CallDetailRecord>;
4
+ export { createFetchSingleCall };
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ import { ParameterizedQuery } from "@influxdata/influxdb-client";
2
+ type InfluxDBClient = {
3
+ collectRows(query: ParameterizedQuery): Promise<unknown[]>;
4
+ };
5
+ export { InfluxDBClient };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/common",
3
- "version": "0.8.20",
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",
@@ -21,6 +21,7 @@
21
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": "4e605a379fec5ac31bf0a3d2f57cbd54da6c732b"
49
+ "gitHead": "2590a20d7309494faca50831ac0c0abdb14c2308"
49
50
  }