@apart-tech/intelligence-core 1.0.6 → 1.1.0
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/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/__tests__/crypto.test.d.ts +2 -0
- package/dist/lib/__tests__/crypto.test.d.ts.map +1 -0
- package/dist/lib/__tests__/crypto.test.js +63 -0
- package/dist/lib/__tests__/crypto.test.js.map +1 -0
- package/dist/lib/crypto.d.ts +14 -0
- package/dist/lib/crypto.d.ts.map +1 -0
- package/dist/lib/crypto.js +33 -0
- package/dist/lib/crypto.js.map +1 -0
- package/dist/services/__tests__/pii-detector-service.test.d.ts +2 -0
- package/dist/services/__tests__/pii-detector-service.test.d.ts.map +1 -0
- package/dist/services/__tests__/pii-detector-service.test.js +75 -0
- package/dist/services/__tests__/pii-detector-service.test.js.map +1 -0
- package/dist/services/__tests__/pii-encryption-service.test.d.ts +2 -0
- package/dist/services/__tests__/pii-encryption-service.test.d.ts.map +1 -0
- package/dist/services/__tests__/pii-encryption-service.test.js +151 -0
- package/dist/services/__tests__/pii-encryption-service.test.js.map +1 -0
- package/dist/services/node-service.d.ts +11 -1
- package/dist/services/node-service.d.ts.map +1 -1
- package/dist/services/node-service.js +90 -27
- package/dist/services/node-service.js.map +1 -1
- package/dist/services/org-embedding-config-service.d.ts.map +1 -1
- package/dist/services/org-embedding-config-service.js +4 -21
- package/dist/services/org-embedding-config-service.js.map +1 -1
- package/dist/services/org-pii-config-service.d.ts +30 -0
- package/dist/services/org-pii-config-service.d.ts.map +1 -0
- package/dist/services/org-pii-config-service.js +97 -0
- package/dist/services/org-pii-config-service.js.map +1 -0
- package/dist/services/pii-detector-service.d.ts +24 -0
- package/dist/services/pii-detector-service.d.ts.map +1 -0
- package/dist/services/pii-detector-service.js +89 -0
- package/dist/services/pii-detector-service.js.map +1 -0
- package/dist/services/pii-encryption-service.d.ts +55 -0
- package/dist/services/pii-encryption-service.d.ts.map +1 -0
- package/dist/services/pii-encryption-service.js +216 -0
- package/dist/services/pii-encryption-service.js.map +1 -0
- package/package.json +2 -1
- package/prisma/schema.prisma +17 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export type { Database } from "./db/connection.js";
|
|
|
3
3
|
export { PrismaClient } from "@prisma/client";
|
|
4
4
|
export { createTenantClient, tenantWhere, SINGLE_TENANT_ORG_ID } from "./db/tenant.js";
|
|
5
5
|
export type { TenantContext } from "./db/tenant.js";
|
|
6
|
+
export { encryptAesGcm, decryptAesGcm, deriveKey } from "./lib/crypto.js";
|
|
6
7
|
export * from "./types/index.js";
|
|
7
8
|
export { loadConfig } from "./config/index.js";
|
|
8
9
|
export { NodeService } from "./services/node-service.js";
|
|
@@ -14,6 +15,12 @@ export { WorkspaceService } from "./services/workspace-service.js";
|
|
|
14
15
|
export type { WorkspaceFilter, CreateWorkspaceInput, UpdateWorkspaceInput } from "./services/workspace-service.js";
|
|
15
16
|
export { CleaningService } from "./services/cleaning-service.js";
|
|
16
17
|
export { OrgEmbeddingConfigService } from "./services/org-embedding-config-service.js";
|
|
18
|
+
export { PiiDetectorService } from "./services/pii-detector-service.js";
|
|
19
|
+
export type { PiiMatch, PiiDetectionResult } from "./services/pii-detector-service.js";
|
|
20
|
+
export { PiiEncryptionService } from "./services/pii-encryption-service.js";
|
|
21
|
+
export type { PiiEncryptionOptions, PiiReport, PiiProcessingResult } from "./services/pii-encryption-service.js";
|
|
22
|
+
export { OrgPiiConfigService } from "./services/org-pii-config-service.js";
|
|
23
|
+
export type { OrgPiiConfig, OrgPiiConfigWithKey, PiiMode } from "./services/org-pii-config-service.js";
|
|
17
24
|
export type { OrgEmbeddingConfig, OrgEmbeddingConfigWithKey } from "./services/org-embedding-config-service.js";
|
|
18
25
|
export type { OrphanNode, DuplicatePair, HealthReport, LinkSuggestion, Island, IslandBridge, ValidationReport, ValidationIssue, ValidationCategory, ValidationSeverity, NormalizeSuggestion, NormalizeReport } from "./services/cleaning-service.js";
|
|
19
26
|
export { createEmbeddingProvider, validateEmbeddingKey, OpenAIEmbeddingProvider, VoyageEmbeddingProvider, OllamaEmbeddingProvider } from "./providers/index.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACjE,YAAY,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACvF,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGpD,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,YAAY,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACh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M,sBAAsB,CAAC;AAChK,YAAY,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpG,YAAY,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
export { getDb, getTenantDb, closeDb } from "./db/connection.js";
|
|
3
3
|
export { PrismaClient } from "@prisma/client";
|
|
4
4
|
export { createTenantClient, tenantWhere, SINGLE_TENANT_ORG_ID } from "./db/tenant.js";
|
|
5
|
+
// Crypto
|
|
6
|
+
export { encryptAesGcm, decryptAesGcm, deriveKey } from "./lib/crypto.js";
|
|
5
7
|
// Types
|
|
6
8
|
export * from "./types/index.js";
|
|
7
9
|
// Config
|
|
@@ -15,6 +17,9 @@ export { DomainService } from "./services/domain-service.js";
|
|
|
15
17
|
export { WorkspaceService } from "./services/workspace-service.js";
|
|
16
18
|
export { CleaningService } from "./services/cleaning-service.js";
|
|
17
19
|
export { OrgEmbeddingConfigService } from "./services/org-embedding-config-service.js";
|
|
20
|
+
export { PiiDetectorService } from "./services/pii-detector-service.js";
|
|
21
|
+
export { PiiEncryptionService } from "./services/pii-encryption-service.js";
|
|
22
|
+
export { OrgPiiConfigService } from "./services/org-pii-config-service.js";
|
|
18
23
|
// Providers
|
|
19
24
|
export { createEmbeddingProvider, validateEmbeddingKey, OpenAIEmbeddingProvider, VoyageEmbeddingProvider, OllamaEmbeddingProvider } from "./providers/index.js";
|
|
20
25
|
export { BatchingEmbeddingProvider } from "./providers/batching.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGvF,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,WAAW;AACX,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGvF,SAAS;AACT,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE1E,QAAQ;AACR,cAAc,kBAAkB,CAAC;AAEjC,SAAS;AACT,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,WAAW;AACX,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAE5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAK3E,YAAY;AACZ,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEhK,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEpE,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.test.d.ts","sourceRoot":"","sources":["../../../src/lib/__tests__/crypto.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { encryptAesGcm, decryptAesGcm, deriveKey } from "../crypto.js";
|
|
3
|
+
describe("crypto", () => {
|
|
4
|
+
const key = deriveKey("test-secret");
|
|
5
|
+
describe("deriveKey", () => {
|
|
6
|
+
it("returns a 32-byte buffer", () => {
|
|
7
|
+
expect(key.length).toBe(32);
|
|
8
|
+
});
|
|
9
|
+
it("is deterministic", () => {
|
|
10
|
+
expect(deriveKey("test-secret")).toEqual(key);
|
|
11
|
+
});
|
|
12
|
+
it("produces different keys for different secrets", () => {
|
|
13
|
+
expect(deriveKey("other-secret")).not.toEqual(key);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
describe("encryptAesGcm / decryptAesGcm", () => {
|
|
17
|
+
it("roundtrips plaintext correctly", () => {
|
|
18
|
+
const plaintext = "hello world";
|
|
19
|
+
const encrypted = encryptAesGcm(plaintext, key);
|
|
20
|
+
const decrypted = decryptAesGcm(encrypted, key);
|
|
21
|
+
expect(decrypted).toBe(plaintext);
|
|
22
|
+
});
|
|
23
|
+
it("produces iv:tag:ciphertext format", () => {
|
|
24
|
+
const encrypted = encryptAesGcm("test", key);
|
|
25
|
+
const parts = encrypted.split(":");
|
|
26
|
+
expect(parts).toHaveLength(3);
|
|
27
|
+
// Each part should be valid base64
|
|
28
|
+
for (const part of parts) {
|
|
29
|
+
expect(() => Buffer.from(part, "base64")).not.toThrow();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
it("produces different ciphertext each time (random IV)", () => {
|
|
33
|
+
const a = encryptAesGcm("same text", key);
|
|
34
|
+
const b = encryptAesGcm("same text", key);
|
|
35
|
+
expect(a).not.toBe(b);
|
|
36
|
+
// But both decrypt to same value
|
|
37
|
+
expect(decryptAesGcm(a, key)).toBe("same text");
|
|
38
|
+
expect(decryptAesGcm(b, key)).toBe("same text");
|
|
39
|
+
});
|
|
40
|
+
it("fails with wrong key", () => {
|
|
41
|
+
const encrypted = encryptAesGcm("secret", key);
|
|
42
|
+
const wrongKey = deriveKey("wrong-secret");
|
|
43
|
+
expect(() => decryptAesGcm(encrypted, wrongKey)).toThrow();
|
|
44
|
+
});
|
|
45
|
+
it("fails with tampered ciphertext", () => {
|
|
46
|
+
const encrypted = encryptAesGcm("secret", key);
|
|
47
|
+
const parts = encrypted.split(":");
|
|
48
|
+
// Tamper with the ciphertext part
|
|
49
|
+
const tampered = parts[0] + ":" + parts[1] + ":AAAA";
|
|
50
|
+
expect(() => decryptAesGcm(tampered, key)).toThrow();
|
|
51
|
+
});
|
|
52
|
+
it("handles empty string", () => {
|
|
53
|
+
const encrypted = encryptAesGcm("", key);
|
|
54
|
+
expect(decryptAesGcm(encrypted, key)).toBe("");
|
|
55
|
+
});
|
|
56
|
+
it("handles unicode", () => {
|
|
57
|
+
const plaintext = "Hello 🌍 — résumé";
|
|
58
|
+
const encrypted = encryptAesGcm(plaintext, key);
|
|
59
|
+
expect(decryptAesGcm(encrypted, key)).toBe(plaintext);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=crypto.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.test.js","sourceRoot":"","sources":["../../../src/lib/__tests__/crypto.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEvE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,GAAG,GAAG,SAAS,CAAC,aAAa,CAAC,CAAC;IAErC,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;QACzB,EAAE,CAAC,0BAA0B,EAAE,GAAG,EAAE;YAClC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC9B,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;YAC1B,MA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Aa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjD,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,iBAAiB,EAAE,GAAG,EAAE;YACzB,MAAM,SAAS,GAAG,mBAAmB,CAAC;YACtC,MAAM,SAAS,GAAG,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;YAChD,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Derive a 32-byte AES key from a secret string using SHA-256.
|
|
3
|
+
*/
|
|
4
|
+
export declare function deriveKey(secret: string): Buffer;
|
|
5
|
+
/**
|
|
6
|
+
* Encrypt plaintext using AES-256-GCM.
|
|
7
|
+
* Returns a string in the format: base64(iv):base64(authTag):base64(ciphertext)
|
|
8
|
+
*/
|
|
9
|
+
export declare function encryptAesGcm(plaintext: string, key: Buffer): string;
|
|
10
|
+
/**
|
|
11
|
+
* Decrypt an AES-256-GCM encoded string (iv:tag:ciphertext format).
|
|
12
|
+
*/
|
|
13
|
+
export declare function decryptAesGcm(encoded: string, key: Buffer): string;
|
|
14
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/lib/crypto.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMpE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQlE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createCipheriv, createDecipheriv, randomBytes, createHash } from "node:crypto";
|
|
2
|
+
const ALGORITHM = "aes-256-gcm";
|
|
3
|
+
const IV_LENGTH = 16;
|
|
4
|
+
/**
|
|
5
|
+
* Derive a 32-byte AES key from a secret string using SHA-256.
|
|
6
|
+
*/
|
|
7
|
+
export function deriveKey(secret) {
|
|
8
|
+
return createHash("sha256").update(secret).digest();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Encrypt plaintext using AES-256-GCM.
|
|
12
|
+
* Returns a string in the format: base64(iv):base64(authTag):base64(ciphertext)
|
|
13
|
+
*/
|
|
14
|
+
export function encryptAesGcm(plaintext, key) {
|
|
15
|
+
const iv = randomBytes(IV_LENGTH);
|
|
16
|
+
const cipher = createCipheriv(ALGORITHM, key, iv);
|
|
17
|
+
const encrypted = Buffer.concat([cipher.update(plaintext, "utf8"), cipher.final()]);
|
|
18
|
+
const tag = cipher.getAuthTag();
|
|
19
|
+
return `${iv.toString("base64")}:${tag.toString("base64")}:${encrypted.toString("base64")}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Decrypt an AES-256-GCM encoded string (iv:tag:ciphertext format).
|
|
23
|
+
*/
|
|
24
|
+
export function decryptAesGcm(encoded, key) {
|
|
25
|
+
const [ivB64, tagB64, ciphertextB64] = encoded.split(":");
|
|
26
|
+
const iv = Buffer.from(ivB64, "base64");
|
|
27
|
+
const tag = Buffer.from(tagB64, "base64");
|
|
28
|
+
const ciphertext = Buffer.from(ciphertextB64, "base64");
|
|
29
|
+
const decipher = createDecipheriv(ALGORITHM, key, iv);
|
|
30
|
+
decipher.setAuthTag(tag);
|
|
31
|
+
return Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString("utf8");
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @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AM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC;IACxD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC;IACtD,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AACzF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detector-service.test.d.ts","sourceRoot":"","sources":["../../../src/services/__tests__/pii-detector-service.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { PiiDetectorService } from "../pii-detector-service.js";
|
|
3
|
+
describe("PiiDetectorService", () => {
|
|
4
|
+
const detector = new PiiDetectorService();
|
|
5
|
+
describe("detect", () => {
|
|
6
|
+
it("detects email addresses", () => {
|
|
7
|
+
const result = detector.detect("Contact john@example.com for details");
|
|
8
|
+
expect(result.hasPii).toBe(true);
|
|
9
|
+
expect(result.matches).toHaveLength(1);
|
|
10
|
+
expect(result.matches[0].type).toBe("email");
|
|
11
|
+
expect(result.matches[0].value).toBe("john@example.com");
|
|
12
|
+
});
|
|
13
|
+
it("detects phone numbers", () => {
|
|
14
|
+
const result = detector.detect("Call me at (555) 123-4567");
|
|
15
|
+
expect(result.hasPii).toBe(true);
|
|
16
|
+
expect(result.matches.some((m) => m.type === "phone_number")).toBe(true);
|
|
17
|
+
});
|
|
18
|
+
it("detects credit card numbers", () => {
|
|
19
|
+
const result = detector.detect("Card: 4111-1111-1111-1111");
|
|
20
|
+
expect(result.hasPii).toBe(true);
|
|
21
|
+
expect(result.matches.some((m) => m.type === "credit_card")).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
it("detects US SSNs", () => {
|
|
24
|
+
const result = detector.detect("SSN: 123-45-6789");
|
|
25
|
+
expect(result.hasPii).toBe(true);
|
|
26
|
+
expect(result.matches.some((m) => m.type === "ssn_us")).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
it("returns no matches for clean text", () => {
|
|
29
|
+
const result = detector.detect("This is a normal sentence about software engineering.");
|
|
30
|
+
expect(result.hasPii).toBe(false);
|
|
31
|
+
expect(result.matches).toHaveLength(0);
|
|
32
|
+
});
|
|
33
|
+
it("handles empty string", () => {
|
|
34
|
+
const result = detector.detect("");
|
|
35
|
+
expect(result.hasPii).toBe(false);
|
|
36
|
+
expect(result.matches).toHaveLength(0);
|
|
37
|
+
});
|
|
38
|
+
it("detects multiple PII types in one string", () => {
|
|
39
|
+
const result = detector.detect("Email john@example.com or call (555) 123-4567");
|
|
40
|
+
expect(result.hasPii).toBe(true);
|
|
41
|
+
const types = result.matches.map((m) => m.type);
|
|
42
|
+
expect(types).toContain("email");
|
|
43
|
+
expect(types).toContain("phone_number");
|
|
44
|
+
});
|
|
45
|
+
it("includes correct start/end positions", () => {
|
|
46
|
+
const text = "Contact john@example.com please";
|
|
47
|
+
const result = detector.detect(text);
|
|
48
|
+
expect(result.matches).toHaveLength(1);
|
|
49
|
+
const match = result.matches[0];
|
|
50
|
+
expect(text.slice(match.start, match.end)).toBe("john@example.com");
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
describe("detectInObject", () => {
|
|
54
|
+
it("detects PII in string values", () => {
|
|
55
|
+
const results = detector.detectInObject({
|
|
56
|
+
name: "John",
|
|
57
|
+
email: "john@example.com",
|
|
58
|
+
age: 30,
|
|
59
|
+
});
|
|
60
|
+
expect(results["email"]).toBeDefined();
|
|
61
|
+
expect(results["email"].hasPii).toBe(true);
|
|
62
|
+
// Non-string values should not be in results
|
|
63
|
+
expect(results["age"]).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
it("handles object with no PII", () => {
|
|
66
|
+
const results = detector.detectInObject({
|
|
67
|
+
title: "Hello world",
|
|
68
|
+
content: "Just a normal string",
|
|
69
|
+
});
|
|
70
|
+
expect(results["title"].hasPii).toBe(false);
|
|
71
|
+
expect(results["content"].hasPii).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=pii-detector-service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-detector-service.test.js","sourceRoot":"","sources":["../../../src/services/__tests__/pii-detector-service.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;IAClC,MAAM,QAAQ,GAAG,IAAI,kBAAkB,EAAE,CAAC;IAE1C,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;QACtB,EAAE,CAAC,yBAAyB,EAAE,GAAG,EAAE;YACjC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,sCAAsC,CAAC,CAAC;YACvE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;QAEH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oot":"","sources":["../../../src/services/__tests__/pii-encryption-service.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { PiiEncryptionService } from "../pii-encryption-service.js";
|
|
3
|
+
import { PiiDetectorService } from "../pii-detector-service.js";
|
|
4
|
+
import { deriveKey } from "../../lib/crypto.js";
|
|
5
|
+
describe("PiiEncryptionService", () => {
|
|
6
|
+
const detector = new PiiDetectorService();
|
|
7
|
+
const service = new PiiEncryptionService(detector);
|
|
8
|
+
const orgKey = deriveKey("test-org-key");
|
|
9
|
+
describe("processText", () => {
|
|
10
|
+
it("encrypts PII and replaces with tokens", () => {
|
|
11
|
+
const result = service.processText("Email john@example.com for info", {
|
|
12
|
+
orgKey,
|
|
13
|
+
mode: "encrypt",
|
|
14
|
+
});
|
|
15
|
+
expect(result.text).not.toContain("john@example.com");
|
|
16
|
+
expect(result.text).toMatch(/\[PII:email:[^\]]+\]/);
|
|
17
|
+
expect(result.report.matchCount).toBe(1);
|
|
18
|
+
expect(result.report.encryptedCount).toBe(1);
|
|
19
|
+
expect(result.report.mode).toBe("encrypt");
|
|
20
|
+
});
|
|
21
|
+
it("detect-warn mode reports but does not encrypt", () => {
|
|
22
|
+
const result = service.processText("Email john@example.com for info", {
|
|
23
|
+
orgKey,
|
|
24
|
+
mode: "detect-warn",
|
|
25
|
+
});
|
|
26
|
+
expect(result.text).toContain("john@example.com");
|
|
27
|
+
expect(result.report.matchCount).toBe(1);
|
|
28
|
+
expect(result.report.encryptedCount).toBe(0);
|
|
29
|
+
expect(result.report.bypassedCount).toBe(1);
|
|
30
|
+
});
|
|
31
|
+
it("disabled mode does no processing", () => {
|
|
32
|
+
const result = service.processText("Email john@example.com for info", {
|
|
33
|
+
orgKey,
|
|
34
|
+
mode: "disabled",
|
|
35
|
+
});
|
|
36
|
+
expect(result.text).toBe("Email john@example.com for info");
|
|
37
|
+
expect(result.report.matchCount).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
it("bypass skips encryption", () => {
|
|
40
|
+
const result = service.processText("Email john@example.com for info", {
|
|
41
|
+
orgKey,
|
|
42
|
+
mode: "encrypt",
|
|
43
|
+
bypass: true,
|
|
44
|
+
});
|
|
45
|
+
expect(result.text).toContain("john@example.com");
|
|
46
|
+
expect(result.report.bypassed).toBe(true);
|
|
47
|
+
expect(result.report.encryptedCount).toBe(0);
|
|
48
|
+
});
|
|
49
|
+
it("allowedPiiTypes skips specified types", () => {
|
|
50
|
+
const result = service.processText("Email john@example.com, SSN: 123-45-6789", {
|
|
51
|
+
orgKey,
|
|
52
|
+
mode: "encrypt",
|
|
53
|
+
allowedPiiTypes: ["email"],
|
|
54
|
+
});
|
|
55
|
+
// Email should still be in plaintext
|
|
56
|
+
expect(result.text).toContain("john@example.com");
|
|
57
|
+
// SSN should be encrypted
|
|
58
|
+
expect(result.text).not.toContain("123-45-6789");
|
|
59
|
+
expect(result.text).toMatch(/\[PII:ssn_us:[^\]]+\]/);
|
|
60
|
+
});
|
|
61
|
+
it("handles text with no PII", () => {
|
|
62
|
+
const result = service.processText("Just a normal sentence", {
|
|
63
|
+
orgKey,
|
|
64
|
+
mode: "encrypt",
|
|
65
|
+
});
|
|
66
|
+
expect(result.text).toBe("Just a normal sentence");
|
|
67
|
+
expect(result.report.matchCount).toBe(0);
|
|
68
|
+
expect(result.report.encryptedCount).toBe(0);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe("decryptText", () => {
|
|
72
|
+
it("roundtrips: encrypt then decrypt yields original", () => {
|
|
73
|
+
const original = "Contact john@example.com or call (555) 123-4567";
|
|
74
|
+
const encrypted = service.processText(original, { orgKey, mode: "encrypt" });
|
|
75
|
+
const decrypted = service.decryptText(encrypted.text, orgKey);
|
|
76
|
+
expect(decrypted).toBe(original);
|
|
77
|
+
});
|
|
78
|
+
it("leaves non-PII text unchanged", () => {
|
|
79
|
+
const text = "No PII here";
|
|
80
|
+
expect(service.decryptText(text, orgKey)).toBe(text);
|
|
81
|
+
});
|
|
82
|
+
it("handles wrong key gracefully (leaves tokens intact)", () => {
|
|
83
|
+
const encrypted = service.processText("Email john@example.com", {
|
|
84
|
+
orgKey,
|
|
85
|
+
mode: "encrypt",
|
|
86
|
+
});
|
|
87
|
+
const wrongKey = deriveKey("wrong-key");
|
|
88
|
+
const result = service.decryptText(encrypted.text, wrongKey);
|
|
89
|
+
// Should still contain the token (decryption failed gracefully)
|
|
90
|
+
expect(result).toMatch(/\[PII:email:[^\]]+\]/);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe("processNodeFields", () => {
|
|
94
|
+
it("processes title, content, and metadata", () => {
|
|
95
|
+
const result = service.processNodeFields({
|
|
96
|
+
title: "Contact john@example.com",
|
|
97
|
+
content: "Call (555) 123-4567 for details",
|
|
98
|
+
metadata: { note: "SSN is 123-45-6789" },
|
|
99
|
+
}, { orgKey, mode: "encrypt" });
|
|
100
|
+
expect(result.title).not.toContain("john@example.com");
|
|
101
|
+
expect(result.content).not.toContain("(555) 123-4567");
|
|
102
|
+
expect(result.report.matchCount).toBeGreaterThan(0);
|
|
103
|
+
expect(result.report.encryptedCount).toBeGreaterThan(0);
|
|
104
|
+
});
|
|
105
|
+
it("disabled mode passes through unchanged", () => {
|
|
106
|
+
const input = {
|
|
107
|
+
title: "john@example.com",
|
|
108
|
+
content: "test",
|
|
109
|
+
metadata: { key: "value" },
|
|
110
|
+
};
|
|
111
|
+
const result = service.processNodeFields(input, { orgKey, mode: "disabled" });
|
|
112
|
+
expect(result.title).toBe(input.title);
|
|
113
|
+
expect(result.content).toBe(input.content);
|
|
114
|
+
expect(result.metadata).toEqual(input.metadata);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
describe("decryptNodeFields", () => {
|
|
118
|
+
it("decrypts PII in all node fields", () => {
|
|
119
|
+
const original = {
|
|
120
|
+
title: "Contact john@example.com",
|
|
121
|
+
content: "Call (555) 123-4567",
|
|
122
|
+
metadata: { note: "regular text" },
|
|
123
|
+
};
|
|
124
|
+
const encrypted = service.processNodeFields(original, { orgKey, mode: "encrypt" });
|
|
125
|
+
const node = {
|
|
126
|
+
id: "test",
|
|
127
|
+
title: encrypted.title,
|
|
128
|
+
content: encrypted.content,
|
|
129
|
+
metadata: encrypted.metadata ?? {},
|
|
130
|
+
};
|
|
131
|
+
const decrypted = service.decryptNodeFields(node, orgKey);
|
|
132
|
+
expect(decrypted.title).toBe(original.title);
|
|
133
|
+
expect(decrypted.content).toBe(original.content);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe("token format", () => {
|
|
137
|
+
it("produces parseable PII tokens", () => {
|
|
138
|
+
const result = service.processText("Email john@example.com", {
|
|
139
|
+
orgKey,
|
|
140
|
+
mode: "encrypt",
|
|
141
|
+
});
|
|
142
|
+
const tokenRegex = /\[PII:(\w+):([A-Za-z0-9+/=]+:[A-Za-z0-9+/=]+:[A-Za-z0-9+/=]+)\]/g;
|
|
143
|
+
const match = tokenRegex.exec(result.text);
|
|
144
|
+
expect(match).not.toBeNull();
|
|
145
|
+
expect(match[1]).toBe("email");
|
|
146
|
+
// The encrypted payload should have 3 colon-separated base64 parts
|
|
147
|
+
expect(match[2].split(":")).toHaveLength(3);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=pii-encryption-service.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pii-encryption-service.test.js","sourceRoot":"","sources":["../../../src/services/__tests__/pii-encryption-service.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,QAAQ,CA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Q,IAAI,EAAE;aACnC,CAAC;YAEF,MAAM,SAAS,GAAG,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YAC1D,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;QAC5B,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE;YACvC,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,wBAAwB,EAAE;gBAC3D,MAAM;gBACN,IAAI,EAAE,SAAS;aAChB,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,kEAAkE,CAAC;YACtF,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC3C,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC7B,MAAM,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAChC,mEAAmE;YACnE,MAAM,CAAC,KAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { PrismaClient } from "@prisma/client";
|
|
2
2
|
import type { Node, NodeStatus, EmbeddingProvider } from "../types/index.js";
|
|
3
3
|
import { type TenantContext } from "../db/tenant.js";
|
|
4
|
+
import type { PiiEncryptionService } from "./pii-encryption-service.js";
|
|
5
|
+
import type { PiiEncryptionOptions } from "./pii-encryption-service.js";
|
|
4
6
|
export declare class NodeService {
|
|
5
7
|
private db;
|
|
6
8
|
private embeddings;
|
|
9
|
+
private piiEncryption?;
|
|
10
|
+
private piiOptions?;
|
|
7
11
|
private tenantCtx;
|
|
8
|
-
constructor(db: PrismaClient, embeddings: EmbeddingProvider, tenantCtx?: TenantContext);
|
|
12
|
+
constructor(db: PrismaClient, embeddings: EmbeddingProvider, tenantCtx?: TenantContext, piiEncryption?: PiiEncryptionService | undefined, piiOptions?: PiiEncryptionOptions | undefined);
|
|
9
13
|
create(input: {
|
|
10
14
|
type: string;
|
|
11
15
|
title: string;
|
|
@@ -31,6 +35,7 @@ export declare class NodeService {
|
|
|
31
35
|
type?: string;
|
|
32
36
|
domainId?: string;
|
|
33
37
|
}, embedding: number[]): Promise<Node | null>;
|
|
38
|
+
resolveId(idOrPrefix: string): Promise<string | null>;
|
|
34
39
|
getById(id: string): Promise<Node | null>;
|
|
35
40
|
update(id: string, input: {
|
|
36
41
|
title?: string;
|
|
@@ -46,5 +51,10 @@ export declare class NodeService {
|
|
|
46
51
|
type: string;
|
|
47
52
|
count: number;
|
|
48
53
|
}[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Apply PII detection/encryption to node fields.
|
|
56
|
+
* Returns processed fields and whether PII was found.
|
|
57
|
+
*/
|
|
58
|
+
private applyPii;
|
|
49
59
|
}
|
|
50
60
|
//# sourceMappingURL=node-service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-service.d.ts","sourceRoot":"","sources":["../../src/services/node-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EACV,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAqC,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"node-service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