@talkpilot/core-db 1.3.14 → 1.3.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/README.md +55 -53
- package/README_OLD.md +160 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/municipal/index.d.ts +1 -1
- package/dist/municipal/index.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts +3 -0
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.d.ts.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js +17 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.getters.js.map +1 -1
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts +1 -2
- package/dist/talkpilot/clientsConfig/clientsConfig.types.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.d.ts +0 -3
- package/dist/talkpilot/flows/flows.schema.d.ts.map +1 -1
- package/dist/talkpilot/flows/flows.schema.js +0 -1
- package/dist/talkpilot/flows/flows.schema.js.map +1 -1
- package/dist/talkpilot/flows/flows.types.d.ts +0 -2
- package/dist/talkpilot/flows/flows.types.d.ts.map +1 -1
- package/dist/test-utils/factories/index.d.ts +1 -0
- package/dist/test-utils/factories/index.d.ts.map +1 -1
- package/dist/test-utils/factories/index.js +1 -0
- package/dist/test-utils/factories/index.js.map +1 -1
- package/dist/test-utils/factories/websitalk/scans.d.ts.map +1 -1
- package/dist/test-utils/factories/websitalk/scans.js +2 -1
- package/dist/test-utils/factories/websitalk/scans.js.map +1 -1
- package/dist/test-utils/factories/websitalk/websiteUrls.d.ts +5 -0
- package/dist/test-utils/factories/websitalk/websiteUrls.d.ts.map +1 -0
- package/dist/test-utils/factories/websitalk/websiteUrls.js +17 -0
- package/dist/test-utils/factories/websitalk/websiteUrls.js.map +1 -0
- package/dist/websitalk/index.d.ts +1 -0
- package/dist/websitalk/index.d.ts.map +1 -1
- package/dist/websitalk/index.js +1 -0
- package/dist/websitalk/index.js.map +1 -1
- package/dist/websitalk/scans/index.d.ts +2 -0
- package/dist/websitalk/scans/index.d.ts.map +1 -1
- package/dist/websitalk/scans/index.js +2 -0
- package/dist/websitalk/scans/index.js.map +1 -1
- package/dist/websitalk/scans/scans.constants.d.ts +11 -0
- package/dist/websitalk/scans/scans.constants.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.constants.js +18 -0
- package/dist/websitalk/scans/scans.constants.js.map +1 -0
- package/dist/websitalk/scans/scans.getters.d.ts +10 -3
- package/dist/websitalk/scans/scans.getters.d.ts.map +1 -1
- package/dist/websitalk/scans/scans.getters.js +49 -9
- package/dist/websitalk/scans/scans.getters.js.map +1 -1
- package/dist/websitalk/scans/scans.types.d.ts +3 -8
- package/dist/websitalk/scans/scans.types.d.ts.map +1 -1
- package/dist/websitalk/scans/scans.utils.d.ts +3 -0
- package/dist/websitalk/scans/scans.utils.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.utils.js +7 -0
- package/dist/websitalk/scans/scans.utils.js.map +1 -0
- package/dist/websitalk/websitalk.setup.d.ts +3 -0
- package/dist/websitalk/websitalk.setup.d.ts.map +1 -0
- package/dist/websitalk/websitalk.setup.js +34 -0
- package/dist/websitalk/websitalk.setup.js.map +1 -0
- package/dist/websitalk/websiteUrls/index.d.ts +3 -0
- package/dist/websitalk/websiteUrls/index.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/index.js +19 -0
- package/dist/websitalk/websiteUrls/index.js.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.constants.d.ts +2 -0
- package/dist/websitalk/websiteUrls/websiteUrls.constants.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.constants.js +5 -0
- package/dist/websitalk/websiteUrls/websiteUrls.constants.js.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.context.d.ts +11 -0
- package/dist/websitalk/websiteUrls/websiteUrls.context.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.context.js +35 -0
- package/dist/websitalk/websiteUrls/websiteUrls.context.js.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.getters.d.ts +10 -0
- package/dist/websitalk/websiteUrls/websiteUrls.getters.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.getters.js +47 -0
- package/dist/websitalk/websiteUrls/websiteUrls.getters.js.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.setters.d.ts +7 -0
- package/dist/websitalk/websiteUrls/websiteUrls.setters.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.setters.js +29 -0
- package/dist/websitalk/websiteUrls/websiteUrls.setters.js.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.types.d.ts +13 -0
- package/dist/websitalk/websiteUrls/websiteUrls.types.d.ts.map +1 -0
- package/dist/websitalk/websiteUrls/websiteUrls.types.js +3 -0
- package/dist/websitalk/websiteUrls/websiteUrls.types.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/municipal/index.ts +1 -1
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.getters.spec.ts +57 -5
- package/src/talkpilot/clientsConfig/__tests__/clientsConfig.spec.ts +0 -4
- package/src/talkpilot/clientsConfig/clientsConfig.getters.ts +24 -0
- package/src/talkpilot/clientsConfig/clientsConfig.types.ts +1 -2
- package/src/talkpilot/flows/__tests__/flows.schema.spec.ts +0 -3
- package/src/talkpilot/flows/flows.schema.ts +0 -1
- package/src/talkpilot/flows/flows.types.ts +0 -2
- package/src/test-utils/factories/index.ts +1 -0
- package/src/test-utils/factories/websitalk/scans.ts +2 -1
- package/src/test-utils/factories/websitalk/websiteUrls.ts +17 -0
- package/src/websitalk/index.ts +1 -0
- package/src/websitalk/scans/__tests__/scans.spec.ts +121 -26
- package/src/websitalk/scans/index.ts +2 -0
- package/src/websitalk/scans/scans.constants.ts +15 -0
- package/src/websitalk/scans/scans.getters.ts +64 -17
- package/src/websitalk/scans/scans.types.ts +3 -11
- package/src/websitalk/scans/scans.utils.ts +5 -0
- package/src/websitalk/websiteUrls/__tests__/websiteUrls.spec.ts +77 -0
- package/src/websitalk/websiteUrls/index.ts +2 -0
- package/src/websitalk/websiteUrls/websiteUrls.getters.ts +65 -0
- package/src/websitalk/websiteUrls/websiteUrls.types.ts +13 -0
- package/tsconfig.json +4 -4
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts +0 -4
- package/dist/talkpilot/subscriptions/subscriptions.utils.d.ts.map +0 -1
- package/dist/talkpilot/subscriptions/subscriptions.utils.js +0 -20
- package/dist/talkpilot/subscriptions/subscriptions.utils.js.map +0 -1
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteWebsiteUrl = exports.updateWebsiteUrl = exports.createWebsiteUrl = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
const websiteUrls_getters_1 = require("./websiteUrls.getters");
|
|
6
|
+
const createWebsiteUrl = async (input) => {
|
|
7
|
+
const now = new Date();
|
|
8
|
+
const { insertedId } = await (0, websiteUrls_getters_1.getWebsiteUrlsCollection)().insertOne({
|
|
9
|
+
clientId: input.clientId,
|
|
10
|
+
name: input.name,
|
|
11
|
+
baseUrl: input.baseUrl,
|
|
12
|
+
createdAt: now,
|
|
13
|
+
updatedAt: now,
|
|
14
|
+
});
|
|
15
|
+
return insertedId;
|
|
16
|
+
};
|
|
17
|
+
exports.createWebsiteUrl = createWebsiteUrl;
|
|
18
|
+
const updateWebsiteUrl = async (id, updates) => {
|
|
19
|
+
return (0, websiteUrls_getters_1.getWebsiteUrlsCollection)().findOneAndUpdate({ _id: new index_1.ObjectId(id) }, { $set: { ...updates, updatedAt: new Date() } }, { returnDocument: "after" });
|
|
20
|
+
};
|
|
21
|
+
exports.updateWebsiteUrl = updateWebsiteUrl;
|
|
22
|
+
const deleteWebsiteUrl = async (id) => {
|
|
23
|
+
const result = await (0, websiteUrls_getters_1.getWebsiteUrlsCollection)().deleteOne({
|
|
24
|
+
_id: new index_1.ObjectId(id),
|
|
25
|
+
});
|
|
26
|
+
return result.deletedCount > 0;
|
|
27
|
+
};
|
|
28
|
+
exports.deleteWebsiteUrl = deleteWebsiteUrl;
|
|
29
|
+
//# sourceMappingURL=websiteUrls.setters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websiteUrls.setters.js","sourceRoot":"","sources":["../../../src/websitalk/websiteUrls/websiteUrls.setters.ts"],"names":[],"mappings":";;;AACA,oCAAoC;AACpC,+DAAoF;AAQ7E,MAAM,gBAAgB,GAAG,KAAK,EACnC,KAA4B,EACJ,EAAE;IAC1B,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,8CAAwB,GAAE,CAAC,SAAS,CAAC;QAChE,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,SAAS,EAAE,GAAG;QACd,SAAS,EAAE,GAAG;KACf,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAbW,QAAA,gBAAgB,oBAa3B;AAEK,MAAM,gBAAgB,GAAG,KAAK,EACnC,EAAU,EACV,OAAsD,EACvB,EAAE;IACjC,OAAO,IAAA,8CAAwB,GAAE,CAAC,gBAAgB,CAChD,EAAE,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC,EAAE,EACzB,EAAE,IAAI,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,EAC/C,EAAE,cAAc,EAAE,OAAO,EAAE,CAC5B,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,gBAAgB,oBAS3B;AAEK,MAAM,gBAAgB,GAAG,KAAK,EAAE,EAAU,EAAoB,EAAE;IACrE,MAAM,MAAM,GAAG,MAAM,IAAA,8CAAwB,GAAE,CAAC,SAAS,CAAC;QACxD,GAAG,EAAE,IAAI,gBAAQ,CAAC,EAAE,CAAC;KACtB,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC;AACjC,CAAC,CAAC;AANW,QAAA,gBAAgB,oBAM3B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObjectId } from "mongodb";
|
|
2
|
+
export type WebsiteUrl = {
|
|
3
|
+
clientId: string;
|
|
4
|
+
name: string;
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
createdAt: Date;
|
|
7
|
+
updatedAt: Date;
|
|
8
|
+
};
|
|
9
|
+
export type WebsiteUrlDoc = WebsiteUrl & {
|
|
10
|
+
_id: ObjectId;
|
|
11
|
+
};
|
|
12
|
+
export type CreateWebsiteUrlInput = Omit<WebsiteUrl, "createdAt" | "updatedAt">;
|
|
13
|
+
//# sourceMappingURL=websiteUrls.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websiteUrls.types.d.ts","sourceRoot":"","sources":["../../../src/websitalk/websiteUrls/websiteUrls.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG;IAAE,GAAG,EAAE,QAAQ,CAAA;CAAE,CAAC;AAE3D,MAAM,MAAM,qBAAqB,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websiteUrls.types.js","sourceRoot":"","sources":["../../../src/websitalk/websiteUrls/websiteUrls.types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/municipal/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./tickets";
|
|
|
7
7
|
export * from "./systemInstructions";
|
|
8
8
|
export * from "./muniIssues";
|
|
9
9
|
export * from "./utils/types";
|
|
10
|
-
export { CityName } from "./utils/types";
|
|
10
|
+
export type { CityName } from "./utils/types";
|
|
11
11
|
export { municipalDataMongodbClient } from "./mongodb-client";
|
|
12
12
|
|
|
13
13
|
let db: Db;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { describe, it, expect, beforeEach, afterEach } from "@jest/globals";
|
|
2
2
|
import {
|
|
3
3
|
getClientsConfigCollection,
|
|
4
|
+
getActiveScanId,
|
|
5
|
+
updateActiveScanId,
|
|
6
|
+
clearActiveScanId,
|
|
4
7
|
updateProductConfig,
|
|
5
8
|
} from "../clientsConfig.getters";
|
|
6
9
|
|
|
@@ -23,8 +26,6 @@ describe("updateProductConfig", () => {
|
|
|
23
26
|
websiteTalk: {
|
|
24
27
|
language: "English",
|
|
25
28
|
companyName: "OldCorp",
|
|
26
|
-
defaultBaseUrl: "https://old-url.com",
|
|
27
|
-
logoUrl: "",
|
|
28
29
|
timezone: "UTC",
|
|
29
30
|
},
|
|
30
31
|
},
|
|
@@ -38,9 +39,7 @@ describe("updateProductConfig", () => {
|
|
|
38
39
|
expect(updatedDoc).toBeDefined();
|
|
39
40
|
expect(updatedDoc?.products.websiteTalk?.language).toBe("Hebrew");
|
|
40
41
|
expect(updatedDoc?.products.websiteTalk?.companyName).toBe("TestCorp");
|
|
41
|
-
expect(updatedDoc?.products.websiteTalk?.
|
|
42
|
-
"https://old-url.com",
|
|
43
|
-
);
|
|
42
|
+
expect(updatedDoc?.products.websiteTalk?.timezone).toBe("UTC");
|
|
44
43
|
});
|
|
45
44
|
|
|
46
45
|
it("should throw an error if no client config is found", async () => {
|
|
@@ -51,3 +50,56 @@ describe("updateProductConfig", () => {
|
|
|
51
50
|
).rejects.toThrow("No client config found for clientId: invalid-client");
|
|
52
51
|
});
|
|
53
52
|
});
|
|
53
|
+
|
|
54
|
+
describe("activeScanId", () => {
|
|
55
|
+
beforeEach(async () => {
|
|
56
|
+
await getClientsConfigCollection().deleteMany({});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
afterEach(async () => {
|
|
60
|
+
await getClientsConfigCollection().deleteMany({});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should return undefined when activeScanId is not set", async () => {
|
|
64
|
+
const clientId = "client-active";
|
|
65
|
+
await getClientsConfigCollection().insertOne({
|
|
66
|
+
clientId,
|
|
67
|
+
products: {
|
|
68
|
+
websiteTalk: { companyName: "X", timezone: "UTC", language: "he" },
|
|
69
|
+
},
|
|
70
|
+
} as any);
|
|
71
|
+
|
|
72
|
+
expect(await getActiveScanId(clientId)).toBeUndefined();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should persist activeScanId and return it from getActiveScanId", async () => {
|
|
76
|
+
const clientId = "client-active-2";
|
|
77
|
+
await getClientsConfigCollection().insertOne({
|
|
78
|
+
clientId,
|
|
79
|
+
products: {
|
|
80
|
+
websiteTalk: { companyName: "X", timezone: "UTC", language: "he" },
|
|
81
|
+
},
|
|
82
|
+
} as any);
|
|
83
|
+
|
|
84
|
+
await updateActiveScanId(clientId, "scan-abc");
|
|
85
|
+
expect(await getActiveScanId(clientId)).toBe("scan-abc");
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should clear activeScanId and return undefined from getActiveScanId", async () => {
|
|
89
|
+
const clientId = "client-active-3";
|
|
90
|
+
await getClientsConfigCollection().insertOne({
|
|
91
|
+
clientId,
|
|
92
|
+
products: {
|
|
93
|
+
websiteTalk: {
|
|
94
|
+
companyName: "X",
|
|
95
|
+
timezone: "UTC",
|
|
96
|
+
language: "he",
|
|
97
|
+
activeScanId: "scan-old",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
} as any);
|
|
101
|
+
|
|
102
|
+
await clearActiveScanId(clientId);
|
|
103
|
+
expect(await getActiveScanId(clientId)).toBeUndefined();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -31,11 +31,9 @@ describe("db.clientsConfig", () => {
|
|
|
31
31
|
clientId,
|
|
32
32
|
products: {
|
|
33
33
|
websiteTalk: {
|
|
34
|
-
logoUrl: "https://cdn.example.com/branding/acme/logo.png",
|
|
35
34
|
companyName: "Acme Ltd",
|
|
36
35
|
timezone: "Asia/Jerusalem",
|
|
37
36
|
language: "he",
|
|
38
|
-
defaultBaseUrl: "https://acme.example",
|
|
39
37
|
},
|
|
40
38
|
},
|
|
41
39
|
});
|
|
@@ -48,11 +46,9 @@ describe("db.clientsConfig", () => {
|
|
|
48
46
|
clientId,
|
|
49
47
|
products: {
|
|
50
48
|
websiteTalk: {
|
|
51
|
-
logoUrl: "https://cdn.example.com/branding/acme/logo.png",
|
|
52
49
|
companyName: "Acme Ltd",
|
|
53
50
|
timezone: "Asia/Jerusalem",
|
|
54
51
|
language: "he",
|
|
55
|
-
defaultBaseUrl: "https://acme.example",
|
|
56
52
|
},
|
|
57
53
|
},
|
|
58
54
|
});
|
|
@@ -53,3 +53,27 @@ export async function updateProductConfig<K extends KnownProductKey>(
|
|
|
53
53
|
throw new Error(`No client config found for clientId: ${clientId}`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
export const getActiveScanId = async (
|
|
58
|
+
clientId: string,
|
|
59
|
+
): Promise<string | undefined> => {
|
|
60
|
+
const cfg = await getClientConfig(clientId);
|
|
61
|
+
return cfg?.products?.websiteTalk?.activeScanId;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const updateActiveScanId = async (
|
|
65
|
+
clientId: string,
|
|
66
|
+
scanId: string,
|
|
67
|
+
): Promise<void> => {
|
|
68
|
+
await updateProductConfig(clientId, "websiteTalk", { activeScanId: scanId });
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const clearActiveScanId = async (clientId: string): Promise<void> => {
|
|
72
|
+
const result = await getClientsConfigCollection().updateOne(
|
|
73
|
+
{ clientId },
|
|
74
|
+
{ $unset: { "products.websiteTalk.activeScanId": "" } },
|
|
75
|
+
);
|
|
76
|
+
if (result.matchedCount === 0) {
|
|
77
|
+
throw new Error(`No client config found for clientId: ${clientId}`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
@@ -58,11 +58,10 @@ export type WebsiteTalkScheduler = {
|
|
|
58
58
|
|
|
59
59
|
/** Product config for the websiteTalk */
|
|
60
60
|
export type WebsiteTalkProduct = {
|
|
61
|
-
logoUrl: string;
|
|
62
61
|
companyName: string;
|
|
63
62
|
timezone: string;
|
|
64
63
|
language: string;
|
|
65
|
-
|
|
64
|
+
activeScanId?: string;
|
|
66
65
|
};
|
|
67
66
|
|
|
68
67
|
// ---------------------------------------------------------------------------
|
|
@@ -79,9 +79,6 @@ describe("flowMongoSchema", () => {
|
|
|
79
79
|
expect(toolItem.properties).toHaveProperty("runInBackground");
|
|
80
80
|
expect(toolItem.properties.runInBackground.bsonType).toBe("bool");
|
|
81
81
|
|
|
82
|
-
expect(toolItem.properties).toHaveProperty("useRedisTranscription");
|
|
83
|
-
expect(toolItem.properties.useRedisTranscription.bsonType).toBe("bool");
|
|
84
|
-
|
|
85
82
|
expect(toolItem.properties).toHaveProperty("backgroundToolType");
|
|
86
83
|
expect(toolItem.properties.backgroundToolType.bsonType).toBe("string");
|
|
87
84
|
expect(toolItem.properties.backgroundToolType.enum).toEqual([
|
|
@@ -138,7 +138,6 @@ export const flowMongoSchema = {
|
|
|
138
138
|
parameters: { bsonType: "object" },
|
|
139
139
|
bodyFormat: { bsonType: "string", enum: ["json", "form-data"] },
|
|
140
140
|
preventAudioDuringTool: { bsonType: "bool" },
|
|
141
|
-
useRedisTranscription: { bsonType: "bool" },
|
|
142
141
|
sendUserAuthToken: { bsonType: "bool" },
|
|
143
142
|
runInBackground: { bsonType: "bool" },
|
|
144
143
|
backgroundToolType: {
|
|
@@ -71,8 +71,6 @@ export type FlowTool = {
|
|
|
71
71
|
parameters: Record<string, unknown>;
|
|
72
72
|
bodyFormat?: "json" | "form-data";
|
|
73
73
|
preventAudioDuringTool?: boolean;
|
|
74
|
-
/** When true, prefer cached transcription from Redis (default: false). */
|
|
75
|
-
useRedisTranscription?: boolean;
|
|
76
74
|
sendUserAuthToken?: boolean;
|
|
77
75
|
runInBackground?: boolean;
|
|
78
76
|
backgroundToolType?: "backgroundToolAlways" | "backgroundToolOnce";
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { Factory } from "fishery";
|
|
2
2
|
import { faker } from "@faker-js/faker";
|
|
3
|
+
import { ObjectId } from "mongodb";
|
|
3
4
|
import type { Scan } from "../../../websitalk";
|
|
4
5
|
|
|
5
6
|
export const scanFactory = Factory.define<Scan>(() => ({
|
|
6
7
|
clientId: faker.string.uuid(),
|
|
7
|
-
|
|
8
|
+
websiteUrlId: new ObjectId().toString(),
|
|
8
9
|
status: "CHECKING",
|
|
9
10
|
activeTasksCount: 0,
|
|
10
11
|
pagesScanned: 0,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Factory } from "fishery";
|
|
2
|
+
import { faker } from "@faker-js/faker";
|
|
3
|
+
import type { WebsiteUrl } from "../../../websitalk/websiteUrls";
|
|
4
|
+
|
|
5
|
+
export const websiteUrlFactory = Factory.define<WebsiteUrl>(() => ({
|
|
6
|
+
clientId: faker.string.uuid(),
|
|
7
|
+
name: faker.company.name(),
|
|
8
|
+
baseUrl: faker.internet.url(),
|
|
9
|
+
createdAt: new Date(),
|
|
10
|
+
updatedAt: new Date(),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
export function createWebsiteUrlFixture(
|
|
14
|
+
overrides?: Partial<WebsiteUrl>,
|
|
15
|
+
): WebsiteUrl {
|
|
16
|
+
return websiteUrlFactory.build(overrides);
|
|
17
|
+
}
|
package/src/websitalk/index.ts
CHANGED
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
countScans,
|
|
7
7
|
createScanDoc,
|
|
8
8
|
updateScanDoc,
|
|
9
|
-
|
|
9
|
+
findInProgressScansByClient,
|
|
10
|
+
getScansByWebsiteUrl,
|
|
11
|
+
getLatestScanByWebsiteUrl,
|
|
12
|
+
getInProgressScanByWebsiteUrl,
|
|
13
|
+
getLatestCompletedScanByWebsiteUrl,
|
|
14
|
+
deleteScansByWebsiteUrl,
|
|
10
15
|
} from "../scans.getters";
|
|
11
16
|
import { createScanFixture } from "../../../test-utils/factories";
|
|
12
17
|
import { ObjectId } from "mongodb";
|
|
@@ -37,7 +42,7 @@ describe("db.websitalk.scans", () => {
|
|
|
37
42
|
expect(result.length).toBe(1);
|
|
38
43
|
expect(result[0]).toMatchObject({
|
|
39
44
|
clientId,
|
|
40
|
-
|
|
45
|
+
websiteUrlId: scanInside.websiteUrlId,
|
|
41
46
|
status: "COMPLETED",
|
|
42
47
|
});
|
|
43
48
|
expect(result[0]).toHaveProperty("siteChrome");
|
|
@@ -83,12 +88,12 @@ describe("db.websitalk.scans", () => {
|
|
|
83
88
|
clientId,
|
|
84
89
|
new Date("2023-05-01"),
|
|
85
90
|
new Date("2023-05-31"),
|
|
86
|
-
["clientId", "
|
|
91
|
+
["clientId", "websiteUrlId", "status"],
|
|
87
92
|
);
|
|
88
93
|
|
|
89
94
|
expect(result).toMatchObject({
|
|
90
95
|
clientId,
|
|
91
|
-
|
|
96
|
+
websiteUrlId: scan.websiteUrlId,
|
|
92
97
|
status: "COMPLETED",
|
|
93
98
|
});
|
|
94
99
|
expect(result).toHaveProperty("_id");
|
|
@@ -110,7 +115,7 @@ describe("db.websitalk.scans", () => {
|
|
|
110
115
|
const count = await countScans({ clientId });
|
|
111
116
|
|
|
112
117
|
expect(result.length).toBe(1);
|
|
113
|
-
expect(result[0].
|
|
118
|
+
expect(result[0].websiteUrlId).toBe(completed.websiteUrlId);
|
|
114
119
|
expect(count).toBe(2);
|
|
115
120
|
});
|
|
116
121
|
});
|
|
@@ -118,15 +123,15 @@ describe("db.websitalk.scans", () => {
|
|
|
118
123
|
describe("createScanDoc()", () => {
|
|
119
124
|
it("should insert a scan with default values for the rest of the fields", async () => {
|
|
120
125
|
const clientId = "createClient";
|
|
121
|
-
const
|
|
126
|
+
const websiteUrlId = new ObjectId().toString();
|
|
122
127
|
|
|
123
|
-
const { insertedId } = await createScanDoc({ clientId,
|
|
128
|
+
const { insertedId } = await createScanDoc({ clientId, websiteUrlId });
|
|
124
129
|
|
|
125
130
|
const result = await getScansCollection().findOne({ _id: insertedId });
|
|
126
131
|
|
|
127
132
|
expect(result).toMatchObject({
|
|
128
133
|
clientId,
|
|
129
|
-
|
|
134
|
+
websiteUrlId,
|
|
130
135
|
status: "CHECKING",
|
|
131
136
|
activeTasksCount: 0,
|
|
132
137
|
pagesScanned: 0,
|
|
@@ -166,53 +171,143 @@ describe("db.websitalk.scans", () => {
|
|
|
166
171
|
});
|
|
167
172
|
});
|
|
168
173
|
|
|
169
|
-
describe("
|
|
170
|
-
|
|
171
|
-
const clientId = "activeClient";
|
|
174
|
+
describe("in-progress scan helpers", () => {
|
|
175
|
+
const websiteUrlId = "website-123";
|
|
172
176
|
|
|
177
|
+
it("should return website scan history newest first", async () => {
|
|
173
178
|
await getScansCollection().insertMany([
|
|
174
179
|
createScanFixture({
|
|
175
|
-
|
|
180
|
+
websiteUrlId,
|
|
176
181
|
status: "COMPLETED",
|
|
177
182
|
createdAt: new Date("2023-05-01"),
|
|
178
183
|
}),
|
|
179
184
|
createScanFixture({
|
|
180
|
-
|
|
181
|
-
status: "
|
|
185
|
+
websiteUrlId,
|
|
186
|
+
status: "COMPLETED",
|
|
182
187
|
createdAt: new Date("2023-05-15"),
|
|
183
188
|
}),
|
|
184
189
|
]);
|
|
185
190
|
|
|
186
|
-
const
|
|
191
|
+
const scans = await getScansByWebsiteUrl(websiteUrlId);
|
|
192
|
+
expect(scans).toHaveLength(2);
|
|
193
|
+
expect(scans[0].createdAt.getTime()).toBeGreaterThan(
|
|
194
|
+
scans[1].createdAt.getTime(),
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should return the newest scan for a website", async () => {
|
|
199
|
+
await getScansCollection().insertMany([
|
|
200
|
+
createScanFixture({
|
|
201
|
+
websiteUrlId,
|
|
202
|
+
status: "COMPLETED",
|
|
203
|
+
createdAt: new Date("2023-05-01"),
|
|
204
|
+
}),
|
|
205
|
+
createScanFixture({
|
|
206
|
+
websiteUrlId,
|
|
207
|
+
status: "FAILED",
|
|
208
|
+
createdAt: new Date("2023-05-15"),
|
|
209
|
+
}),
|
|
210
|
+
]);
|
|
187
211
|
|
|
188
|
-
|
|
212
|
+
const latest = await getLatestScanByWebsiteUrl(websiteUrlId);
|
|
213
|
+
expect(latest?.status).toBe("FAILED");
|
|
189
214
|
});
|
|
190
215
|
|
|
191
|
-
it("should return
|
|
192
|
-
|
|
216
|
+
it("should return in-progress scan and return null when only completed exists", async () => {
|
|
217
|
+
await getScansCollection().insertMany([
|
|
218
|
+
createScanFixture({
|
|
219
|
+
websiteUrlId,
|
|
220
|
+
status: "COMPLETED",
|
|
221
|
+
createdAt: new Date("2023-05-01"),
|
|
222
|
+
}),
|
|
223
|
+
createScanFixture({
|
|
224
|
+
websiteUrlId,
|
|
225
|
+
status: "SCANNING",
|
|
226
|
+
createdAt: new Date("2023-05-15"),
|
|
227
|
+
}),
|
|
228
|
+
]);
|
|
193
229
|
|
|
230
|
+
const inProgressScan = await getInProgressScanByWebsiteUrl(websiteUrlId);
|
|
231
|
+
expect(inProgressScan?.status).toBe("SCANNING");
|
|
232
|
+
|
|
233
|
+
await getScansCollection().deleteMany({ websiteUrlId });
|
|
234
|
+
await getScansCollection().insertOne(
|
|
235
|
+
createScanFixture({
|
|
236
|
+
websiteUrlId,
|
|
237
|
+
status: "COMPLETED",
|
|
238
|
+
createdAt: new Date("2023-05-20"),
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect(await getInProgressScanByWebsiteUrl(websiteUrlId)).toBeNull();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("should return all in-progress scans across websites for a client", async () => {
|
|
246
|
+
const clientId = "multiScanClient";
|
|
194
247
|
await getScansCollection().insertMany([
|
|
195
248
|
createScanFixture({
|
|
196
249
|
clientId,
|
|
250
|
+
websiteUrlId: "website-a",
|
|
197
251
|
status: "SCANNING",
|
|
198
|
-
createdAt: new Date("2023-05-01"),
|
|
199
252
|
}),
|
|
200
253
|
createScanFixture({
|
|
201
254
|
clientId,
|
|
202
|
-
|
|
203
|
-
|
|
255
|
+
websiteUrlId: "website-b",
|
|
256
|
+
status: "PROCESSING",
|
|
257
|
+
}),
|
|
258
|
+
createScanFixture({
|
|
259
|
+
clientId,
|
|
260
|
+
websiteUrlId: "website-c",
|
|
261
|
+
status: "COMPLETED",
|
|
204
262
|
}),
|
|
205
263
|
]);
|
|
206
264
|
|
|
207
|
-
const
|
|
265
|
+
const scans = await findInProgressScansByClient(clientId);
|
|
266
|
+
expect(scans).toHaveLength(2);
|
|
267
|
+
expect(scans.map((s) => s.websiteUrlId).sort()).toEqual([
|
|
268
|
+
"website-a",
|
|
269
|
+
"website-b",
|
|
270
|
+
]);
|
|
271
|
+
});
|
|
272
|
+
});
|
|
208
273
|
|
|
209
|
-
|
|
274
|
+
describe("website delete helpers", () => {
|
|
275
|
+
it("should return the newest completed scan only", async () => {
|
|
276
|
+
const websiteUrlId = new ObjectId().toString();
|
|
277
|
+
await getScansCollection().insertMany([
|
|
278
|
+
createScanFixture({
|
|
279
|
+
websiteUrlId,
|
|
280
|
+
status: "FAILED",
|
|
281
|
+
createdAt: new Date("2023-05-25"),
|
|
282
|
+
}),
|
|
283
|
+
createScanFixture({
|
|
284
|
+
websiteUrlId,
|
|
285
|
+
status: "COMPLETED",
|
|
286
|
+
createdAt: new Date("2023-05-20"),
|
|
287
|
+
}),
|
|
288
|
+
createScanFixture({
|
|
289
|
+
websiteUrlId,
|
|
290
|
+
status: "COMPLETED",
|
|
291
|
+
createdAt: new Date("2023-05-22"),
|
|
292
|
+
}),
|
|
293
|
+
]);
|
|
294
|
+
|
|
295
|
+
const latest = await getLatestCompletedScanByWebsiteUrl(websiteUrlId);
|
|
296
|
+
expect(latest?.status).toBe("COMPLETED");
|
|
297
|
+
expect(latest?.createdAt).toEqual(new Date("2023-05-22"));
|
|
210
298
|
});
|
|
211
299
|
|
|
212
|
-
it("should
|
|
213
|
-
const
|
|
300
|
+
it("should delete all scans for the website and return count", async () => {
|
|
301
|
+
const websiteUrlId = new ObjectId().toString();
|
|
302
|
+
await getScansCollection().insertMany([
|
|
303
|
+
createScanFixture({ websiteUrlId }),
|
|
304
|
+
createScanFixture({ websiteUrlId }),
|
|
305
|
+
createScanFixture({ websiteUrlId: new ObjectId().toString() }),
|
|
306
|
+
]);
|
|
214
307
|
|
|
215
|
-
|
|
308
|
+
const deleted = await deleteScansByWebsiteUrl(websiteUrlId);
|
|
309
|
+
expect(deleted).toBe(2);
|
|
310
|
+
expect(await countScans({ websiteUrlId })).toBe(0);
|
|
216
311
|
});
|
|
217
312
|
});
|
|
218
313
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const SCAN_STATUSES = {
|
|
2
|
+
CHECKING: "CHECKING",
|
|
3
|
+
PREPARING: "PREPARING",
|
|
4
|
+
SCANNING: "SCANNING",
|
|
5
|
+
PROCESSING: "PROCESSING",
|
|
6
|
+
COMPLETED: "COMPLETED",
|
|
7
|
+
FAILED: "FAILED",
|
|
8
|
+
OVERWRITTEN: "OVERWRITTEN",
|
|
9
|
+
} as const;
|
|
10
|
+
|
|
11
|
+
export const FINISHED_SCAN_STATUSES = [
|
|
12
|
+
SCAN_STATUSES.COMPLETED,
|
|
13
|
+
SCAN_STATUSES.FAILED,
|
|
14
|
+
SCAN_STATUSES.OVERWRITTEN,
|
|
15
|
+
] as const;
|