@talkpilot/core-db 1.3.14 → 1.3.15
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 +1 -0
- package/dist/websitalk/scans/index.d.ts.map +1 -1
- package/dist/websitalk/scans/index.js +1 -0
- package/dist/websitalk/scans/index.js.map +1 -1
- package/dist/websitalk/scans/scans.constants.d.ts +5 -0
- package/dist/websitalk/scans/scans.constants.d.ts.map +1 -0
- package/dist/websitalk/scans/scans.constants.js +12 -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 +48 -9
- package/dist/websitalk/scans/scans.getters.js.map +1 -1
- package/dist/websitalk/scans/scans.types.d.ts +2 -8
- package/dist/websitalk/scans/scans.types.d.ts.map +1 -1
- 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 +1 -0
- package/src/websitalk/scans/scans.constants.ts +12 -0
- package/src/websitalk/scans/scans.getters.ts +67 -17
- package/src/websitalk/scans/scans.types.ts +3 -6
- 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,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createWebsiteUrl,
|
|
3
|
+
getWebsiteUrlsByClient,
|
|
4
|
+
getWebsiteUrlById,
|
|
5
|
+
getWebsiteUrlsCollection,
|
|
6
|
+
updateWebsiteUrl,
|
|
7
|
+
deleteWebsiteUrl,
|
|
8
|
+
} from "../websiteUrls.getters";
|
|
9
|
+
import { createWebsiteUrlFixture } from "../../../test-utils/factories/websitalk/websiteUrls";
|
|
10
|
+
|
|
11
|
+
describe("db.websitalk.websiteUrls", () => {
|
|
12
|
+
const clientId = "test-client";
|
|
13
|
+
|
|
14
|
+
describe("createWebsiteUrl", () => {
|
|
15
|
+
it("should create a website URL configuration", async () => {
|
|
16
|
+
const id = await createWebsiteUrl({
|
|
17
|
+
clientId,
|
|
18
|
+
name: "Primary",
|
|
19
|
+
baseUrl: "https://example.com",
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const saved = await getWebsiteUrlById(id.toString());
|
|
23
|
+
expect(saved).toMatchObject({
|
|
24
|
+
clientId,
|
|
25
|
+
name: "Primary",
|
|
26
|
+
baseUrl: "https://example.com",
|
|
27
|
+
});
|
|
28
|
+
expect(saved?.createdAt).toBeInstanceOf(Date);
|
|
29
|
+
expect(saved?.updatedAt).toBeInstanceOf(Date);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("getWebsiteUrlsByClient", () => {
|
|
34
|
+
it("should return all configurations for a client", async () => {
|
|
35
|
+
await getWebsiteUrlsCollection().insertMany([
|
|
36
|
+
createWebsiteUrlFixture({ clientId, name: "A" }),
|
|
37
|
+
createWebsiteUrlFixture({ clientId, name: "B" }),
|
|
38
|
+
createWebsiteUrlFixture({ clientId: "other-client", name: "Other" }),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
const results = await getWebsiteUrlsByClient(clientId);
|
|
42
|
+
expect(results).toHaveLength(2);
|
|
43
|
+
expect(results.map((doc) => doc.name)).toEqual(["A", "B"]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("updateWebsiteUrl", () => {
|
|
48
|
+
it("should update name and baseUrl", async () => {
|
|
49
|
+
const id = await createWebsiteUrl({
|
|
50
|
+
clientId,
|
|
51
|
+
name: "Old",
|
|
52
|
+
baseUrl: "https://old.example",
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const updated = await updateWebsiteUrl(id.toString(), {
|
|
56
|
+
name: "New",
|
|
57
|
+
baseUrl: "https://new.example",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(updated?.name).toBe("New");
|
|
61
|
+
expect(updated?.baseUrl).toBe("https://new.example");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("deleteWebsiteUrl", () => {
|
|
66
|
+
it("should delete the website and return true", async () => {
|
|
67
|
+
const id = await createWebsiteUrl({
|
|
68
|
+
clientId: "delete-client",
|
|
69
|
+
name: "Gone",
|
|
70
|
+
baseUrl: "https://gone.example",
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(await deleteWebsiteUrl(id.toString())).toBe(true);
|
|
74
|
+
expect(await getWebsiteUrlById(id.toString())).toBeNull();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Collection, Filter, ObjectId as MongoObjectId } from "mongodb";
|
|
2
|
+
import { getDb, ObjectId } from "../index";
|
|
3
|
+
import type {
|
|
4
|
+
CreateWebsiteUrlInput,
|
|
5
|
+
WebsiteUrl,
|
|
6
|
+
WebsiteUrlDoc,
|
|
7
|
+
} from "./websiteUrls.types";
|
|
8
|
+
|
|
9
|
+
export const getWebsiteUrlsCollection = (): Collection<WebsiteUrl> => {
|
|
10
|
+
return getDb().collection<WebsiteUrl>("websiteUrls");
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const getWebsiteUrlsByClient = async (
|
|
14
|
+
clientId: string,
|
|
15
|
+
): Promise<WebsiteUrlDoc[]> => {
|
|
16
|
+
return getWebsiteUrlsCollection()
|
|
17
|
+
.find({ clientId })
|
|
18
|
+
.sort({ createdAt: 1 })
|
|
19
|
+
.toArray();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getWebsiteUrlById = async (
|
|
23
|
+
id: string,
|
|
24
|
+
): Promise<WebsiteUrlDoc | null> => {
|
|
25
|
+
return getWebsiteUrlsCollection().findOne({ _id: new ObjectId(id) });
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const findWebsiteUrls = async (
|
|
29
|
+
filter: Filter<WebsiteUrl> = {},
|
|
30
|
+
): Promise<WebsiteUrlDoc[]> => {
|
|
31
|
+
return getWebsiteUrlsCollection().find(filter).toArray();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const createWebsiteUrl = async (
|
|
35
|
+
input: CreateWebsiteUrlInput,
|
|
36
|
+
): Promise<MongoObjectId> => {
|
|
37
|
+
const now = new Date();
|
|
38
|
+
const { insertedId } = await getWebsiteUrlsCollection().insertOne({
|
|
39
|
+
clientId: input.clientId,
|
|
40
|
+
name: input.name,
|
|
41
|
+
baseUrl: input.baseUrl,
|
|
42
|
+
createdAt: now,
|
|
43
|
+
updatedAt: now,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return insertedId;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const updateWebsiteUrl = async (
|
|
50
|
+
id: string,
|
|
51
|
+
updates: Partial<Pick<WebsiteUrl, "name" | "baseUrl">>,
|
|
52
|
+
): Promise<WebsiteUrlDoc | null> => {
|
|
53
|
+
return getWebsiteUrlsCollection().findOneAndUpdate(
|
|
54
|
+
{ _id: new ObjectId(id) },
|
|
55
|
+
{ $set: { ...updates, updatedAt: new Date() } },
|
|
56
|
+
{ returnDocument: "after" },
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const deleteWebsiteUrl = async (id: string): Promise<boolean> => {
|
|
61
|
+
const result = await getWebsiteUrlsCollection().deleteOne({
|
|
62
|
+
_id: new ObjectId(id),
|
|
63
|
+
});
|
|
64
|
+
return result.deletedCount === 1;
|
|
65
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObjectId } from "mongodb";
|
|
2
|
+
|
|
3
|
+
export type WebsiteUrl = {
|
|
4
|
+
clientId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
createdAt: Date;
|
|
8
|
+
updatedAt: Date;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type WebsiteUrlDoc = WebsiteUrl & { _id: ObjectId };
|
|
12
|
+
|
|
13
|
+
export type CreateWebsiteUrlInput = Omit<WebsiteUrl, "createdAt" | "updatedAt">;
|
package/tsconfig.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
|
-
"module": "
|
|
5
|
-
"moduleResolution": "
|
|
4
|
+
"module": "Node16",
|
|
5
|
+
"moduleResolution": "node16",
|
|
6
|
+
"isolatedModules": true,
|
|
6
7
|
"lib": ["ES2022"],
|
|
7
8
|
"declaration": true,
|
|
8
9
|
"declarationMap": true,
|
|
@@ -15,8 +16,7 @@
|
|
|
15
16
|
"skipLibCheck": true,
|
|
16
17
|
"resolveJsonModule": true,
|
|
17
18
|
"experimentalDecorators": true,
|
|
18
|
-
"emitDecoratorMetadata": true
|
|
19
|
-
"baseUrl": "."
|
|
19
|
+
"emitDecoratorMetadata": true
|
|
20
20
|
},
|
|
21
21
|
"include": ["src/**/*"],
|
|
22
22
|
"exclude": ["node_modules", "dist", "test", "**/*.test.ts", "**/__tests__/*", "**/*.spec.ts"]
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions.utils.d.ts","sourceRoot":"","sources":["../../../src/talkpilot/subscriptions/subscriptions.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAA6B,MAAM,UAAU,CAAC;AAE7F,eAAO,MAAM,gBAAgB,GAAI,QAAQ,wBAAwB,KAAG,MAAM,CAAC,YAAY,CAetF,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.buildSimpleQuery = void 0;
|
|
4
|
-
const mongodb_1 = require("mongodb");
|
|
5
|
-
const index_1 = require("../index");
|
|
6
|
-
const buildSimpleQuery = (filter) => {
|
|
7
|
-
const query = {};
|
|
8
|
-
if (filter._id) {
|
|
9
|
-
query._id = new mongodb_1.ObjectId(filter._id);
|
|
10
|
-
}
|
|
11
|
-
index_1.simpleFields.forEach((field) => {
|
|
12
|
-
const val = filter[field];
|
|
13
|
-
if (val !== undefined) {
|
|
14
|
-
query[field] = val;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return query;
|
|
18
|
-
};
|
|
19
|
-
exports.buildSimpleQuery = buildSimpleQuery;
|
|
20
|
-
//# sourceMappingURL=subscriptions.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscriptions.utils.js","sourceRoot":"","sources":["../../../src/talkpilot/subscriptions/subscriptions.utils.ts"],"names":[],"mappings":";;;AAAA,qCAA2C;AAC3C,oCAA6F;AAEtF,MAAM,gBAAgB,GAAG,CAAC,MAAgC,EAAwB,EAAE;IACzF,MAAM,KAAK,GAAyB,EAAE,CAAC;IAEvC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,KAAK,CAAC,GAAG,GAAG,IAAI,kBAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACvC,CAAC;IAED,oBAAY,CAAC,OAAO,CAAC,CAAC,KAAkB,EAAE,EAAE;QAC1C,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtB,KAAK,CAAC,KAAK,CAAC,GAAG,GAAU,CAAC;QAC5B,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAfW,QAAA,gBAAgB,oBAe3B"}
|