@talkpilot/core-db 1.3.88 → 1.3.89
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 +65 -12
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts +8 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.d.ts.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.js +26 -0
- package/dist/talkpilot/auditLogs/auditLogs.getters.js.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts +11 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.d.ts.map +1 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.js +3 -0
- package/dist/talkpilot/auditLogs/auditLogs.types.js.map +1 -0
- package/dist/talkpilot/auditLogs/index.d.ts +3 -0
- package/dist/talkpilot/auditLogs/index.d.ts.map +1 -0
- package/dist/talkpilot/auditLogs/index.js +19 -0
- package/dist/talkpilot/auditLogs/index.js.map +1 -0
- package/dist/talkpilot/calls/calls.constants.d.ts +11 -1
- package/dist/talkpilot/calls/calls.constants.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.constants.js +11 -1
- package/dist/talkpilot/calls/calls.constants.js.map +1 -1
- package/dist/talkpilot/calls/calls.getters.d.ts +8 -1
- package/dist/talkpilot/calls/calls.getters.d.ts.map +1 -1
- package/dist/talkpilot/calls/calls.getters.js +216 -1
- package/dist/talkpilot/calls/calls.getters.js.map +1 -1
- package/dist/talkpilot/calls/calls.types.d.ts +45 -0
- package/dist/talkpilot/calls/calls.types.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.constants.d.ts +4 -0
- package/dist/talkpilot/clients/clients.constants.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.constants.js +7 -0
- package/dist/talkpilot/clients/clients.constants.js.map +1 -0
- package/dist/talkpilot/clients/clients.getters.d.ts +6 -0
- package/dist/talkpilot/clients/clients.getters.d.ts.map +1 -1
- package/dist/talkpilot/clients/clients.getters.js +62 -1
- package/dist/talkpilot/clients/clients.getters.js.map +1 -1
- package/dist/talkpilot/clients/clients.lifecycle.d.ts +10 -0
- package/dist/talkpilot/clients/clients.lifecycle.d.ts.map +1 -0
- package/dist/talkpilot/clients/clients.lifecycle.js +109 -0
- package/dist/talkpilot/clients/clients.lifecycle.js.map +1 -0
- package/dist/talkpilot/clients/clients.types.d.ts +53 -0
- package/dist/talkpilot/clients/clients.types.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.d.ts +2 -0
- package/dist/talkpilot/clients/index.d.ts.map +1 -1
- package/dist/talkpilot/clients/index.js +2 -0
- package/dist/talkpilot/clients/index.js.map +1 -1
- package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts +1 -7
- package/dist/talkpilot/contextNotes/contextNotes.getters.d.ts.map +1 -1
- package/dist/talkpilot/contextNotes/contextNotes.getters.js +1 -37
- package/dist/talkpilot/contextNotes/contextNotes.getters.js.map +1 -1
- package/dist/talkpilot/contextNotes/contextNotes.types.d.ts +0 -6
- package/dist/talkpilot/contextNotes/contextNotes.types.d.ts.map +1 -1
- package/dist/talkpilot/index.d.ts +1 -0
- package/dist/talkpilot/index.d.ts.map +1 -1
- package/dist/talkpilot/index.js +1 -0
- package/dist/talkpilot/index.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts +9 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.d.ts.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js +70 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.getter.js.map +1 -1
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts +5 -0
- package/dist/talkpilot/phone_numbers/phone_numbers.types.d.ts.map +1 -1
- package/dist/test-utils/factories/index.d.ts +2 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +2 -0
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/test-utils/factories/talkpilot/clients.d.ts +14 -0
- package/dist/test-utils/factories/talkpilot/clients.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/clients.js +19 -0
- package/dist/test-utils/factories/talkpilot/clients.js.map +1 -0
- package/dist/test-utils/factories/talkpilot/results.d.ts +16 -0
- package/dist/test-utils/factories/talkpilot/results.d.ts.map +1 -0
- package/dist/test-utils/factories/talkpilot/results.js +40 -0
- package/dist/test-utils/factories/talkpilot/results.js.map +1 -0
- package/dist/utils/regex.utils.d.ts +2 -0
- package/dist/utils/regex.utils.d.ts.map +1 -0
- package/dist/utils/regex.utils.js +6 -0
- package/dist/utils/regex.utils.js.map +1 -0
- package/dist/websitalk/scanResources/scanResources.getters.d.ts.map +1 -1
- package/dist/websitalk/scanResources/scanResources.getters.js +2 -1
- package/dist/websitalk/scanResources/scanResources.getters.js.map +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.d.ts +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.d.ts.map +1 -1
- package/dist/websitalk/scanResources/scanResources.utils.js +3 -3
- package/dist/websitalk/scanResources/scanResources.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/talkpilot/auditLogs/__tests__/auditLogs.spec.ts +91 -0
- package/src/talkpilot/auditLogs/auditLogs.getters.ts +26 -0
- package/src/talkpilot/auditLogs/auditLogs.types.ts +12 -0
- package/src/talkpilot/auditLogs/index.ts +2 -0
- package/src/talkpilot/calls/__tests__/calls.statistics.getters.spec.ts +559 -0
- package/src/talkpilot/calls/calls.constants.ts +14 -0
- package/src/talkpilot/calls/calls.getters.ts +320 -0
- package/src/talkpilot/calls/calls.types.ts +52 -0
- package/src/talkpilot/clients/__tests__/clients.getters.spec.ts +224 -0
- package/src/talkpilot/clients/__tests__/clients.lifecycle.spec.ts +194 -0
- package/src/talkpilot/clients/clients.constants.ts +4 -0
- package/src/talkpilot/clients/clients.getters.ts +91 -2
- package/src/talkpilot/clients/clients.lifecycle.ts +132 -0
- package/src/talkpilot/clients/clients.types.ts +58 -0
- package/src/talkpilot/clients/index.ts +2 -0
- package/src/talkpilot/contextNotes/__tests__/contextNotes.getters.spec.ts +0 -141
- package/src/talkpilot/contextNotes/contextNotes.getters.ts +1 -75
- package/src/talkpilot/contextNotes/contextNotes.types.ts +0 -7
- package/src/talkpilot/index.ts +1 -0
- package/src/talkpilot/phone_numbers/__tests__/phone_numbers.spec.ts +284 -13
- package/src/talkpilot/phone_numbers/phone_numbers.getter.ts +89 -1
- package/src/talkpilot/phone_numbers/phone_numbers.types.ts +6 -0
- package/src/test-utils/factories/index.ts +2 -0
- package/src/test-utils/factories/talkpilot/clients.ts +21 -0
- package/src/test-utils/factories/talkpilot/results.ts +43 -0
- package/src/utils/regex.utils.ts +2 -0
- package/src/websitalk/scanResources/scanResources.getters.ts +2 -6
- package/src/websitalk/scanResources/scanResources.utils.ts +2 -3
- package/dist/configuration/gptLive.seed.d.ts +0 -2
- package/dist/configuration/gptLive.seed.d.ts.map +0 -1
- package/dist/configuration/gptLive.seed.js +0 -59
- package/dist/configuration/gptLive.seed.js.map +0 -1
- package/dist/talkpilot/clients/clients.quota.constants.d.ts +0 -2
- package/dist/talkpilot/clients/clients.quota.constants.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.constants.js +0 -5
- package/dist/talkpilot/clients/clients.quota.constants.js.map +0 -1
- package/dist/talkpilot/clients/clients.quota.utils.d.ts +0 -8
- package/dist/talkpilot/clients/clients.quota.utils.d.ts.map +0 -1
- package/dist/talkpilot/clients/clients.quota.utils.js +0 -45
- package/dist/talkpilot/clients/clients.quota.utils.js.map +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Factory } from "fishery";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import { faker } from "@faker-js/faker";
|
|
4
|
+
import type { Result, CallResult } from "../../../talkpilot";
|
|
5
|
+
|
|
6
|
+
export const callResultFactory = Factory.define<CallResult>(() => ({
|
|
7
|
+
callSid: `CA${faker.string.alphanumeric(32)}`,
|
|
8
|
+
status: "completed",
|
|
9
|
+
date: new Date(),
|
|
10
|
+
statuses: ["completed"],
|
|
11
|
+
userAnswer: null,
|
|
12
|
+
color: null,
|
|
13
|
+
name: null,
|
|
14
|
+
callLength: "60 seconds",
|
|
15
|
+
answeredBy: null,
|
|
16
|
+
to: faker.phone.number(),
|
|
17
|
+
from: faker.phone.number(),
|
|
18
|
+
transcription: [],
|
|
19
|
+
flowId: new ObjectId().toString(),
|
|
20
|
+
recordingUrl: null,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
export function createCallResult(overrides?: Partial<CallResult>): CallResult {
|
|
24
|
+
return callResultFactory.build(overrides);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const resultFactory = Factory.define<Result & { _id?: ObjectId }>(
|
|
28
|
+
() => ({
|
|
29
|
+
_id: new ObjectId(),
|
|
30
|
+
calls: [],
|
|
31
|
+
clientId: faker.string.uuid(),
|
|
32
|
+
date: new Date(),
|
|
33
|
+
runId: `run_${new ObjectId().toString()}`,
|
|
34
|
+
sessionId: "incomingCall",
|
|
35
|
+
sessionName: "incomingCall",
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export function createResult(
|
|
40
|
+
overrides?: Partial<Result>,
|
|
41
|
+
): Result & { _id?: ObjectId } {
|
|
42
|
+
return resultFactory.build(overrides);
|
|
43
|
+
}
|
|
@@ -17,12 +17,8 @@ import type {
|
|
|
17
17
|
ScanResourcePageSummary,
|
|
18
18
|
UrlTaskStatus,
|
|
19
19
|
} from "./scanResources.types";
|
|
20
|
-
import {
|
|
21
|
-
|
|
22
|
-
encodeCursor,
|
|
23
|
-
escapeRegex,
|
|
24
|
-
statusesForColumn,
|
|
25
|
-
} from "./scanResources.utils";
|
|
20
|
+
import { decodeCursor, encodeCursor, statusesForColumn } from "./scanResources.utils";
|
|
21
|
+
import { escapeRegex } from "../../utils/regex.utils";
|
|
26
22
|
|
|
27
23
|
export const getScanResourcesCollection = (): Collection<ScanResource> =>
|
|
28
24
|
getDb().collection<ScanResource>(SCAN_RESOURCES_COLLECTION);
|
|
@@ -2,6 +2,8 @@ import { ObjectId } from "mongodb";
|
|
|
2
2
|
import { BOARD_COLUMN_STATUSES } from "./scanResources.constants";
|
|
3
3
|
import type { BoardColumn, UrlTaskStatus } from "./scanResources.types";
|
|
4
4
|
|
|
5
|
+
export { escapeRegex } from "../../utils/regex.utils";
|
|
6
|
+
|
|
5
7
|
const STATUS_TO_COLUMN: Record<UrlTaskStatus, BoardColumn> = Object.entries(
|
|
6
8
|
BOARD_COLUMN_STATUSES,
|
|
7
9
|
).reduce(
|
|
@@ -26,6 +28,3 @@ export const encodeCursor = (id: ObjectId): string =>
|
|
|
26
28
|
|
|
27
29
|
export const decodeCursor = (cursor: string): ObjectId =>
|
|
28
30
|
new ObjectId(Buffer.from(cursor, "base64").toString("utf-8"));
|
|
29
|
-
|
|
30
|
-
export const escapeRegex = (text: string): string =>
|
|
31
|
-
text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gptLive.seed.d.ts","sourceRoot":"","sources":["../../src/configuration/gptLive.seed.ts"],"names":[],"mappings":"AA2BA,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAyC1D"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.seedGptLiveDocuments = seedGptLiveDocuments;
|
|
4
|
-
const mongodb_1 = require("mongodb");
|
|
5
|
-
const models_getters_1 = require("./models/models.getters");
|
|
6
|
-
const prompts_getters_1 = require("./prompts/prompts.getters");
|
|
7
|
-
const GPT_LIVE_MODEL_ID = "gpt-live-1";
|
|
8
|
-
const VOICE_PROMPT = "gptLiveVoiceInstructions";
|
|
9
|
-
const BACKEND_PROMPT = "gptLiveBackendInstructions";
|
|
10
|
-
const VOICE_INSTRUCTIONS = [
|
|
11
|
-
"You are a phone agent on a live call. Speak naturally and briefly.",
|
|
12
|
-
"{{flowInstructions}}",
|
|
13
|
-
"Backchannel: {{backchannelPolicy}}",
|
|
14
|
-
"Interruptions: {{interruptionPolicy}}",
|
|
15
|
-
"Delegation: {{delegationPolicy}}",
|
|
16
|
-
"When the flow is finished, say one short closing line and then stop talking.",
|
|
17
|
-
].join("\n");
|
|
18
|
-
const BACKEND_INSTRUCTIONS = [
|
|
19
|
-
"You are the reasoning backend for a phone agent. Use the tools to do the work.",
|
|
20
|
-
"Return only what the tools returned. Never invent a result, a ticket number, or a confirmation.",
|
|
21
|
-
"{{flowInstructions}}",
|
|
22
|
-
"{{backchannelPolicy}}",
|
|
23
|
-
"{{interruptionPolicy}}",
|
|
24
|
-
"{{delegationPolicy}}",
|
|
25
|
-
].join("\n");
|
|
26
|
-
async function seedGptLiveDocuments() {
|
|
27
|
-
const now = new Date();
|
|
28
|
-
await (0, models_getters_1.getModelsCollection)().updateOne({ modelId: GPT_LIVE_MODEL_ID, type: "realtime" }, {
|
|
29
|
-
$setOnInsert: {
|
|
30
|
-
_id: new mongodb_1.ObjectId(),
|
|
31
|
-
modelId: GPT_LIVE_MODEL_ID,
|
|
32
|
-
name: "GPT-Live 1",
|
|
33
|
-
description: "Turnless full-duplex voice",
|
|
34
|
-
type: "realtime",
|
|
35
|
-
provider: "openai-live",
|
|
36
|
-
available: true,
|
|
37
|
-
features: { supportsAudio: true },
|
|
38
|
-
configDefaults: { backendModel: "gpt-5.6-luna" },
|
|
39
|
-
createdAt: now,
|
|
40
|
-
updatedAt: now,
|
|
41
|
-
},
|
|
42
|
-
}, { upsert: true });
|
|
43
|
-
for (const prompt of [
|
|
44
|
-
{ name: VOICE_PROMPT, content: VOICE_INSTRUCTIONS },
|
|
45
|
-
{ name: BACKEND_PROMPT, content: BACKEND_INSTRUCTIONS },
|
|
46
|
-
]) {
|
|
47
|
-
await (0, prompts_getters_1.getPromptsCollection)().updateOne({ name: prompt.name }, {
|
|
48
|
-
$setOnInsert: {
|
|
49
|
-
_id: new mongodb_1.ObjectId(),
|
|
50
|
-
name: prompt.name,
|
|
51
|
-
content: prompt.content,
|
|
52
|
-
productName: "municipal",
|
|
53
|
-
createdAt: now,
|
|
54
|
-
updatedAt: now,
|
|
55
|
-
},
|
|
56
|
-
}, { upsert: true });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=gptLive.seed.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gptLive.seed.js","sourceRoot":"","sources":["../../src/configuration/gptLive.seed.ts"],"names":[],"mappings":";;AA2BA,oDAyCC;AApED,qCAA2C;AAC3C,4DAA8D;AAC9D,+DAAiE;AAGjE,MAAM,iBAAiB,GAAG,YAAY,CAAC;AACvC,MAAM,YAAY,GAAG,0BAA0B,CAAC;AAChD,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,kBAAkB,GAAG;IACzB,oEAAoE;IACpE,sBAAsB;IACtB,oCAAoC;IACpC,uCAAuC;IACvC,kCAAkC;IAClC,8EAA8E;CAC/E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEb,MAAM,oBAAoB,GAAG;IAC3B,gFAAgF;IAChF,iGAAiG;IACjG,sBAAsB;IACtB,uBAAuB;IACvB,wBAAwB;IACxB,sBAAsB;CACvB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEN,KAAK,UAAU,oBAAoB;IACxC,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,IAAA,oCAAmB,GAAE,CAAC,SAAS,CACnC,EAAE,OAAO,EAAE,iBAAiB,EAAE,IAAI,EAAE,UAAU,EAAsB,EACpE;QACE,YAAY,EAAE;YACZ,GAAG,EAAE,IAAI,kBAAQ,EAAE;YACnB,OAAO,EAAE,iBAAiB;YAC1B,IAAI,EAAE,YAAY;YAClB,WAAW,EAAE,4BAA4B;YACzC,IAAI,EAAE,UAAU;YAChB,QAAQ,EAAE,aAAa;YACvB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE;YACjC,cAAc,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE;YAChD,SAAS,EAAE,GAAG;YACd,SAAS,EAAE,GAAG;SACQ;KACzB,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;IAEF,KAAK,MAAM,MAAM,IAAI;QACnB,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,kBAAkB,EAAE;QACnD,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,oBAAoB,EAAE;KACxD,EAAE,CAAC;QACF,MAAM,IAAA,sCAAoB,GAAE,CAAC,SAAS,CACpC,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,EACrB;YACE,YAAY,EAAE;gBACZ,GAAG,EAAE,IAAI,kBAAQ,EAAE;gBACnB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,WAAW,EAAE,WAAW;gBACxB,SAAS,EAAE,GAAG;gBACd,SAAS,EAAE,GAAG;aACf;SACF,EACD,EAAE,MAAM,EAAE,IAAI,EAAE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.quota.constants.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.quota.constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,MAAM,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.quota.constants.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.quota.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,GAAG,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ClientQuotaNotifications, ClientQuotaState, ClientQuotaStatus, QuotaThresholdAlert } from "./clients.quota.types";
|
|
2
|
-
export declare const computeClientQuotaStatus: (quota: ClientQuotaState | null) => ClientQuotaStatus;
|
|
3
|
-
export declare const getQuotaAlerts: (quota?: ClientQuotaState) => QuotaThresholdAlert[];
|
|
4
|
-
export declare const findFullQuotaAlertIndex: (alerts: QuotaThresholdAlert[]) => number;
|
|
5
|
-
export declare const getFullQuotaAlert: (quota?: ClientQuotaState) => QuotaThresholdAlert | undefined;
|
|
6
|
-
export declare const isFullQuotaAlert: (thresholdPct: number) => boolean;
|
|
7
|
-
export declare const toClientQuotaNotifications: (quota: ClientQuotaState | null) => ClientQuotaNotifications;
|
|
8
|
-
//# sourceMappingURL=clients.quota.utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.quota.utils.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.quota.utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,uBAAuB,CAAC;AAQ/B,eAAO,MAAM,wBAAwB,GACnC,OAAO,gBAAgB,GAAG,IAAI,KAC7B,iBAiBF,CAAC;AAEF,eAAO,MAAM,cAAc,GAAI,QAAQ,gBAAgB,KAAG,mBAAmB,EAClC,CAAC;AAE5C,eAAO,MAAM,uBAAuB,GAAI,QAAQ,mBAAmB,EAAE,KAAG,MACP,CAAC;AAElE,eAAO,MAAM,iBAAiB,GAC5B,QAAQ,gBAAgB,KACvB,mBAAmB,GAAG,SAIxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,cAAc,MAAM,KAAG,OAClB,CAAC;AAEvC,eAAO,MAAM,0BAA0B,GACrC,OAAO,gBAAgB,GAAG,IAAI,KAC7B,wBASD,CAAC"}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toClientQuotaNotifications = exports.isFullQuotaAlert = exports.getFullQuotaAlert = exports.findFullQuotaAlertIndex = exports.getQuotaAlerts = exports.computeClientQuotaStatus = void 0;
|
|
4
|
-
const clients_quota_constants_1 = require("./clients.quota.constants");
|
|
5
|
-
const computeUsagePct = (usedQuota, totalQuota) => totalQuota > 0 ? Math.round((usedQuota / totalQuota) * 100) : 0;
|
|
6
|
-
const isPastExpiration = (expiresAt) => expiresAt ? Date.now() > new Date(expiresAt).getTime() : false;
|
|
7
|
-
const computeClientQuotaStatus = (quota) => {
|
|
8
|
-
if (!quota) {
|
|
9
|
-
return { hasQuota: false };
|
|
10
|
-
}
|
|
11
|
-
const totalQuota = quota.totalQuota;
|
|
12
|
-
const usedQuota = quota.usedQuota ?? 0;
|
|
13
|
-
return {
|
|
14
|
-
hasQuota: true,
|
|
15
|
-
totalQuota,
|
|
16
|
-
usedQuota,
|
|
17
|
-
pct: computeUsagePct(usedQuota, totalQuota),
|
|
18
|
-
expiresAt: quota.expiresAt ? new Date(quota.expiresAt).toISOString() : null,
|
|
19
|
-
isExceeded: usedQuota >= totalQuota,
|
|
20
|
-
isExpired: isPastExpiration(quota.expiresAt),
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
exports.computeClientQuotaStatus = computeClientQuotaStatus;
|
|
24
|
-
const getQuotaAlerts = (quota) => quota?.alerts?.length ? quota.alerts : [];
|
|
25
|
-
exports.getQuotaAlerts = getQuotaAlerts;
|
|
26
|
-
const findFullQuotaAlertIndex = (alerts) => alerts.findIndex((a) => a.thresholdPct >= clients_quota_constants_1.FULL_QUOTA_THRESHOLD);
|
|
27
|
-
exports.findFullQuotaAlertIndex = findFullQuotaAlertIndex;
|
|
28
|
-
const getFullQuotaAlert = (quota) => {
|
|
29
|
-
const alerts = (0, exports.getQuotaAlerts)(quota);
|
|
30
|
-
const index = (0, exports.findFullQuotaAlertIndex)(alerts);
|
|
31
|
-
return index >= 0 ? alerts[index] : undefined;
|
|
32
|
-
};
|
|
33
|
-
exports.getFullQuotaAlert = getFullQuotaAlert;
|
|
34
|
-
const isFullQuotaAlert = (thresholdPct) => thresholdPct >= clients_quota_constants_1.FULL_QUOTA_THRESHOLD;
|
|
35
|
-
exports.isFullQuotaAlert = isFullQuotaAlert;
|
|
36
|
-
const toClientQuotaNotifications = (quota) => ({
|
|
37
|
-
alerts: (0, exports.getQuotaAlerts)(quota ?? undefined).map(({ thresholdPct, recipientEmails, thresholdSent }) => ({
|
|
38
|
-
thresholdPct,
|
|
39
|
-
recipientEmails: recipientEmails ?? [],
|
|
40
|
-
...(thresholdSent ? { thresholdSent: true } : {}),
|
|
41
|
-
})),
|
|
42
|
-
...(quota?.expiredSent ? { expiredSent: true } : {}),
|
|
43
|
-
});
|
|
44
|
-
exports.toClientQuotaNotifications = toClientQuotaNotifications;
|
|
45
|
-
//# sourceMappingURL=clients.quota.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clients.quota.utils.js","sourceRoot":"","sources":["../../../src/talkpilot/clients/clients.quota.utils.ts"],"names":[],"mappings":";;;AAAA,uEAAiE;AAQjE,MAAM,eAAe,GAAG,CAAC,SAAiB,EAAE,UAAkB,EAAU,EAAE,CACxE,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAElE,MAAM,gBAAgB,GAAG,CAAC,SAAwC,EAAW,EAAE,CAC7E,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;AAE1D,MAAM,wBAAwB,GAAG,CACtC,KAA8B,EACX,EAAE;IACrB,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED,MAAM,UAAU,GAA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