@open-mercato/search 0.10.1-develop.7787.1.96c7cfc66f → 0.10.1-develop.7793.1.9e0c43fdde
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/.turbo/turbo-build.log +1 -1
- package/dist/di.js +14 -1
- package/dist/di.js.map +2 -2
- package/dist/indexer/search-indexer.js +28 -5
- package/dist/indexer/search-indexer.js.map +2 -2
- package/dist/lib/debug.js +9 -0
- package/dist/lib/debug.js.map +2 -2
- package/dist/lib/encrypted-custom-field-resolver.js +19 -0
- package/dist/lib/encrypted-custom-field-resolver.js.map +7 -0
- package/dist/lib/plaintext-fields.js +17 -0
- package/dist/lib/plaintext-fields.js.map +7 -0
- package/dist/strategies/fulltext.strategy.js +2 -1
- package/dist/strategies/fulltext.strategy.js.map +2 -2
- package/dist/strategies/vector.strategy.js +2 -1
- package/dist/strategies/vector.strategy.js.map +2 -2
- package/package.json +4 -4
- package/src/__tests__/di-plaintext-custom-field-policy.test.ts +88 -0
- package/src/__tests__/encrypted-custom-field-resolver.test.ts +43 -0
- package/src/__tests__/plaintext-custom-field-boundaries.test.ts +262 -0
- package/src/di.ts +18 -0
- package/src/indexer/search-indexer.ts +36 -3
- package/src/lib/debug.ts +14 -0
- package/src/lib/encrypted-custom-field-resolver.ts +36 -0
- package/src/lib/plaintext-fields.ts +15 -0
- package/src/strategies/fulltext.strategy.ts +2 -1
- package/src/strategies/vector.strategy.ts +2 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { plaintextSearchFields } from "../lib/plaintext-fields.js";
|
|
1
2
|
class FullTextSearchStrategy {
|
|
2
3
|
// Highest priority when available
|
|
3
4
|
constructor(driver) {
|
|
@@ -116,7 +117,7 @@ class FullTextSearchStrategy {
|
|
|
116
117
|
entityId: record.entityId,
|
|
117
118
|
tenantId: record.tenantId,
|
|
118
119
|
organizationId: record.organizationId,
|
|
119
|
-
fields: record
|
|
120
|
+
fields: plaintextSearchFields(record),
|
|
120
121
|
presenter: record.presenter,
|
|
121
122
|
url: record.url,
|
|
122
123
|
links: record.links
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/strategies/fulltext.strategy.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n SearchStrategy,\n SearchStrategyId,\n SearchOptions,\n SearchResult,\n IndexableRecord,\n} from '../types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type {\n FullTextSearchDriver,\n FullTextSearchDocument,\n FullTextSearchHit,\n DocumentLookupKey,\n ListDocumentIdsOptions,\n IndexStats,\n} from '../fulltext/types'\n\n/**\n * FullTextSearchStrategy provides full-text fuzzy search using a pluggable driver.\n * Default driver is Meilisearch, but can be swapped for Algolia, Elasticsearch, etc.\n */\nexport class FullTextSearchStrategy implements SearchStrategy {\n readonly id: SearchStrategyId = 'fulltext'\n readonly name = 'Full-Text Search'\n readonly priority = 30 // Highest priority when available\n\n constructor(private readonly driver: FullTextSearchDriver) {}\n\n async isAvailable(): Promise<boolean> {\n return this.driver.isHealthy()\n }\n\n async ensureReady(): Promise<void> {\n return this.driver.ensureReady()\n }\n\n async search(query: string, options: SearchOptions): Promise<SearchResult[]> {\n if (options.indexDocFilter) return []\n if (Array.isArray(options.organizationIds)) {\n const organizationIds = options.organizationIds\n .map((value) => (typeof value === 'string' ? value.trim() : ''))\n .filter((value) => value.length > 0)\n if (!options.organizationId && organizationIds.length === 0) return []\n }\n\n const hits = await this.driver.search(query, {\n tenantId: options.tenantId,\n organizationId: options.organizationId,\n organizationIds: options.organizationIds,\n entityTypes: options.entityTypes,\n limit: options.limit,\n offset: options.offset,\n })\n\n return hits.map((hit) => this.mapHitToResult(hit))\n }\n\n async index(record: IndexableRecord): Promise<void> {\n const doc = this.mapRecordToDocument(record)\n await this.driver.index(doc)\n }\n\n async delete(entityId: EntityId, recordId: string, tenantId: string): Promise<void> {\n return this.driver.delete(recordId, tenantId)\n }\n\n async bulkIndex(records: IndexableRecord[]): Promise<void> {\n if (!this.driver.bulkIndex) {\n // Fallback to sequential indexing\n for (const record of records) {\n await this.index(record)\n }\n return\n }\n\n const docs = records.map((record) => this.mapRecordToDocument(record))\n return this.driver.bulkIndex(docs)\n }\n\n async purge(entityId: EntityId, tenantId: string, organizationId?: string | null): Promise<void> {\n if (!this.driver.purge) {\n return\n }\n return this.driver.purge(entityId, tenantId, organizationId)\n }\n\n // Additional methods exposed for enrichment and admin purposes\n // These delegate to optional driver methods\n\n async clearIndex(tenantId: string): Promise<void> {\n if (!this.driver.clearIndex) {\n return\n }\n return this.driver.clearIndex(tenantId)\n }\n\n async recreateIndex(tenantId: string): Promise<void> {\n if (!this.driver.recreateIndex) {\n return\n }\n return this.driver.recreateIndex(tenantId)\n }\n\n async getDocuments(\n ids: DocumentLookupKey[],\n tenantId: string\n ): Promise<Map<string, SearchResult>> {\n if (!this.driver.getDocuments) {\n return new Map()\n }\n\n const hits = await this.driver.getDocuments(ids, tenantId)\n const result = new Map<string, SearchResult>()\n\n for (const [key, hit] of hits) {\n result.set(key, this.mapHitToResult(hit))\n }\n\n return result\n }\n\n async getIndexStats(tenantId: string): Promise<IndexStats | null> {\n if (!this.driver.getIndexStats) {\n return null\n }\n return this.driver.getIndexStats(tenantId)\n }\n\n async getEntityCounts(tenantId: string): Promise<Record<string, number> | null> {\n if (!this.driver.getEntityCounts) {\n return null\n }\n return this.driver.getEntityCounts(tenantId)\n }\n\n async listDocumentIds(\n entityId: EntityId,\n tenantId: string,\n options?: ListDocumentIdsOptions\n ): Promise<string[] | null> {\n if (!this.driver.listDocumentIds) {\n return null\n }\n return this.driver.listDocumentIds(entityId, tenantId, options)\n }\n\n get driverId(): string {\n return this.driver.id\n }\n\n private mapHitToResult(hit: FullTextSearchHit): SearchResult {\n return {\n entityId: hit.entityId,\n recordId: hit.recordId,\n score: hit.score,\n source: this.id,\n organizationId: hit.organizationId ?? null,\n presenter: hit.presenter,\n url: hit.url,\n links: hit.links,\n metadata: hit.metadata,\n }\n }\n\n private mapRecordToDocument(record: IndexableRecord): FullTextSearchDocument {\n return {\n recordId: record.recordId,\n entityId: record.entityId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n fields: record
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type {\n SearchStrategy,\n SearchStrategyId,\n SearchOptions,\n SearchResult,\n IndexableRecord,\n} from '../types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport { plaintextSearchFields } from '../lib/plaintext-fields'\nimport type {\n FullTextSearchDriver,\n FullTextSearchDocument,\n FullTextSearchHit,\n DocumentLookupKey,\n ListDocumentIdsOptions,\n IndexStats,\n} from '../fulltext/types'\n\n/**\n * FullTextSearchStrategy provides full-text fuzzy search using a pluggable driver.\n * Default driver is Meilisearch, but can be swapped for Algolia, Elasticsearch, etc.\n */\nexport class FullTextSearchStrategy implements SearchStrategy {\n readonly id: SearchStrategyId = 'fulltext'\n readonly name = 'Full-Text Search'\n readonly priority = 30 // Highest priority when available\n\n constructor(private readonly driver: FullTextSearchDriver) {}\n\n async isAvailable(): Promise<boolean> {\n return this.driver.isHealthy()\n }\n\n async ensureReady(): Promise<void> {\n return this.driver.ensureReady()\n }\n\n async search(query: string, options: SearchOptions): Promise<SearchResult[]> {\n if (options.indexDocFilter) return []\n if (Array.isArray(options.organizationIds)) {\n const organizationIds = options.organizationIds\n .map((value) => (typeof value === 'string' ? value.trim() : ''))\n .filter((value) => value.length > 0)\n if (!options.organizationId && organizationIds.length === 0) return []\n }\n\n const hits = await this.driver.search(query, {\n tenantId: options.tenantId,\n organizationId: options.organizationId,\n organizationIds: options.organizationIds,\n entityTypes: options.entityTypes,\n limit: options.limit,\n offset: options.offset,\n })\n\n return hits.map((hit) => this.mapHitToResult(hit))\n }\n\n async index(record: IndexableRecord): Promise<void> {\n const doc = this.mapRecordToDocument(record)\n await this.driver.index(doc)\n }\n\n async delete(entityId: EntityId, recordId: string, tenantId: string): Promise<void> {\n return this.driver.delete(recordId, tenantId)\n }\n\n async bulkIndex(records: IndexableRecord[]): Promise<void> {\n if (!this.driver.bulkIndex) {\n // Fallback to sequential indexing\n for (const record of records) {\n await this.index(record)\n }\n return\n }\n\n const docs = records.map((record) => this.mapRecordToDocument(record))\n return this.driver.bulkIndex(docs)\n }\n\n async purge(entityId: EntityId, tenantId: string, organizationId?: string | null): Promise<void> {\n if (!this.driver.purge) {\n return\n }\n return this.driver.purge(entityId, tenantId, organizationId)\n }\n\n // Additional methods exposed for enrichment and admin purposes\n // These delegate to optional driver methods\n\n async clearIndex(tenantId: string): Promise<void> {\n if (!this.driver.clearIndex) {\n return\n }\n return this.driver.clearIndex(tenantId)\n }\n\n async recreateIndex(tenantId: string): Promise<void> {\n if (!this.driver.recreateIndex) {\n return\n }\n return this.driver.recreateIndex(tenantId)\n }\n\n async getDocuments(\n ids: DocumentLookupKey[],\n tenantId: string\n ): Promise<Map<string, SearchResult>> {\n if (!this.driver.getDocuments) {\n return new Map()\n }\n\n const hits = await this.driver.getDocuments(ids, tenantId)\n const result = new Map<string, SearchResult>()\n\n for (const [key, hit] of hits) {\n result.set(key, this.mapHitToResult(hit))\n }\n\n return result\n }\n\n async getIndexStats(tenantId: string): Promise<IndexStats | null> {\n if (!this.driver.getIndexStats) {\n return null\n }\n return this.driver.getIndexStats(tenantId)\n }\n\n async getEntityCounts(tenantId: string): Promise<Record<string, number> | null> {\n if (!this.driver.getEntityCounts) {\n return null\n }\n return this.driver.getEntityCounts(tenantId)\n }\n\n async listDocumentIds(\n entityId: EntityId,\n tenantId: string,\n options?: ListDocumentIdsOptions\n ): Promise<string[] | null> {\n if (!this.driver.listDocumentIds) {\n return null\n }\n return this.driver.listDocumentIds(entityId, tenantId, options)\n }\n\n get driverId(): string {\n return this.driver.id\n }\n\n private mapHitToResult(hit: FullTextSearchHit): SearchResult {\n return {\n entityId: hit.entityId,\n recordId: hit.recordId,\n score: hit.score,\n source: this.id,\n organizationId: hit.organizationId ?? null,\n presenter: hit.presenter,\n url: hit.url,\n links: hit.links,\n metadata: hit.metadata,\n }\n }\n\n private mapRecordToDocument(record: IndexableRecord): FullTextSearchDocument {\n return {\n recordId: record.recordId,\n entityId: record.entityId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n fields: plaintextSearchFields(record),\n presenter: record.presenter,\n url: record.url,\n links: record.links,\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
2
|
import { searchDebugWarn } from "../lib/debug.js";
|
|
3
|
+
import { plaintextSearchFields } from "../lib/plaintext-fields.js";
|
|
3
4
|
function normalizeOrganizationIds(options) {
|
|
4
5
|
const single = typeof options.organizationId === "string" ? options.organizationId.trim() : "";
|
|
5
6
|
if (single) return [single];
|
|
@@ -119,7 +120,7 @@ class VectorSearchStrategy {
|
|
|
119
120
|
if (record.presenter?.subtitle) {
|
|
120
121
|
parts.push(record.presenter.subtitle);
|
|
121
122
|
}
|
|
122
|
-
for (const [, value] of Object.entries(record
|
|
123
|
+
for (const [, value] of Object.entries(plaintextSearchFields(record))) {
|
|
123
124
|
if (typeof value === "string" && value.trim()) {
|
|
124
125
|
parts.push(value);
|
|
125
126
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/strategies/vector.strategy.ts"],
|
|
4
|
-
"sourcesContent": ["import { createHash } from 'crypto'\nimport type {\n SearchStrategy,\n SearchStrategyId,\n SearchOptions,\n SearchResult,\n IndexableRecord,\n} from '../types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { VectorDriver, VectorDriverDocument } from '../vector/types'\nimport { searchDebugWarn } from '../lib/debug'\n\n/**\n * Embedding service interface - minimal subset needed by VectorSearchStrategy.\n */\nexport interface EmbeddingService {\n createEmbedding(text: string): Promise<number[]>\n available: boolean\n}\n\n/**\n * Configuration for VectorSearchStrategy.\n */\nexport type VectorStrategyConfig = {\n /** Default limit for search results */\n defaultLimit?: number\n}\n\nfunction normalizeOrganizationIds(options: SearchOptions): string[] | null {\n const single = typeof options.organizationId === 'string' ? options.organizationId.trim() : ''\n if (single) return [single]\n if (!Array.isArray(options.organizationIds)) return null\n return Array.from(new Set(\n options.organizationIds\n .map((value) => (typeof value === 'string' ? value.trim() : ''))\n .filter((value) => value.length > 0),\n ))\n}\n\n/**\n * VectorSearchStrategy provides semantic search using embeddings.\n * It wraps the existing vector module infrastructure.\n */\nexport class VectorSearchStrategy implements SearchStrategy {\n readonly id: SearchStrategyId = 'vector'\n readonly name = 'Vector Search'\n readonly priority = 20 // Medium priority\n\n get supportsIndexDocFilter(): boolean {\n return this.vectorDriver.supportsIndexDocFilter === true\n }\n\n private readonly defaultLimit: number\n private ready = false\n private readyPromise: Promise<void> | null = null\n\n constructor(\n private readonly embeddingService: EmbeddingService,\n private readonly vectorDriver: VectorDriver,\n config?: VectorStrategyConfig,\n ) {\n this.defaultLimit = config?.defaultLimit ?? 20\n }\n\n async isAvailable(): Promise<boolean> {\n if (!this.embeddingService.available) return false\n // A configured embedding provider says nothing about the vector store. When the\n // store cannot serve writes (pgvector extension missing), reporting availability\n // here makes SearchService call ensureReady() for every record and fail the whole\n // index/delete operation. Drivers without a probe keep the previous behavior.\n if (!this.vectorDriver.isHealthy) return true\n return this.vectorDriver.isHealthy()\n }\n\n async ensureReady(): Promise<void> {\n if (this.ready) return\n if (!this.readyPromise) {\n this.readyPromise = this.vectorDriver.ensureReady().then(() => {\n this.ready = true\n })\n }\n return this.readyPromise\n }\n\n async search(query: string, options: SearchOptions): Promise<SearchResult[]> {\n const organizationIds = normalizeOrganizationIds(options)\n if (organizationIds && organizationIds.length === 0) return []\n if (options.indexDocFilter && !this.supportsIndexDocFilter) return []\n\n await this.ensureReady()\n const embedding = await this.embeddingService.createEmbedding(query)\n\n // Build filter - only include organizationId if it's a real value\n // The pgvector driver treats null as \"only records with null org_id\",\n // but we want null/undefined to mean \"no organization filter\"\n const filter: {\n tenantId: string\n organizationId?: string | null\n organizationIds?: string[] | null\n entityIds?: EntityId[]\n indexDocFilter?: SearchOptions['indexDocFilter']\n } = {\n tenantId: options.tenantId,\n entityIds: options.entityTypes as EntityId[],\n ...(options.indexDocFilter ? { indexDocFilter: options.indexDocFilter } : {}),\n }\n\n if (organizationIds) {\n filter.organizationIds = organizationIds\n if (organizationIds.length === 1) {\n filter.organizationId = organizationIds[0]\n }\n }\n\n const results = await this.vectorDriver.query({\n vector: embedding,\n limit: options.limit ?? this.defaultLimit,\n filter,\n })\n\n return results.map((hit) => ({\n entityId: hit.entityId,\n recordId: hit.recordId,\n score: hit.score,\n source: this.id,\n organizationId: hit.organizationId ?? null,\n presenter: hit.presenter ?? undefined,\n url: hit.primaryLinkHref ?? hit.url ?? undefined,\n links: hit.links?.map((link) => ({\n href: link.href,\n label: link.label ?? '',\n kind: link.kind,\n })),\n metadata: hit.payload ?? undefined,\n }))\n }\n\n async index(record: IndexableRecord): Promise<void> {\n await this.ensureReady()\n // Use text from buildSource if available, otherwise fall back to generic extraction\n const textContent = record.text !== undefined\n ? (Array.isArray(record.text) ? record.text.join('\\n') : record.text)\n : this.buildTextContent(record)\n if (!textContent.trim()) return\n\n const embedding = await this.embeddingService.createEmbedding(textContent)\n\n const doc: VectorDriverDocument = {\n entityId: record.entityId as EntityId,\n recordId: record.recordId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n checksum: this.computeChecksum(record),\n embedding,\n url: record.url,\n presenter: record.presenter,\n links: record.links,\n driverId: this.vectorDriver.id,\n resultTitle: record.presenter?.title ?? record.recordId,\n resultSubtitle: record.presenter?.subtitle,\n resultIcon: record.presenter?.icon,\n resultBadge: record.presenter?.badge,\n }\n\n await this.vectorDriver.upsert(doc)\n }\n\n async delete(entityId: EntityId, recordId: string, tenantId: string): Promise<void> {\n await this.ensureReady()\n await this.vectorDriver.delete(entityId, recordId, tenantId)\n }\n\n async purge(entityId: EntityId, tenantId: string, organizationId?: string | null): Promise<void> {\n await this.ensureReady()\n if (this.vectorDriver.purge) {\n await this.vectorDriver.purge(entityId, tenantId, organizationId)\n }\n }\n\n /**\n * Build text content from record fields for embedding.\n */\n private buildTextContent(record: IndexableRecord): string {\n const parts: string[] = []\n\n // Add presenter info\n if (record.presenter?.title) {\n parts.push(record.presenter.title)\n }\n if (record.presenter?.subtitle) {\n parts.push(record.presenter.subtitle)\n }\n\n // Add string fields from record\n for (const [, value] of Object.entries(record
|
|
5
|
-
"mappings": "AAAA,SAAS,kBAAkB;AAU3B,SAAS,uBAAuB;
|
|
4
|
+
"sourcesContent": ["import { createHash } from 'crypto'\nimport type {\n SearchStrategy,\n SearchStrategyId,\n SearchOptions,\n SearchResult,\n IndexableRecord,\n} from '../types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { VectorDriver, VectorDriverDocument } from '../vector/types'\nimport { searchDebugWarn } from '../lib/debug'\nimport { plaintextSearchFields } from '../lib/plaintext-fields'\n\n/**\n * Embedding service interface - minimal subset needed by VectorSearchStrategy.\n */\nexport interface EmbeddingService {\n createEmbedding(text: string): Promise<number[]>\n available: boolean\n}\n\n/**\n * Configuration for VectorSearchStrategy.\n */\nexport type VectorStrategyConfig = {\n /** Default limit for search results */\n defaultLimit?: number\n}\n\nfunction normalizeOrganizationIds(options: SearchOptions): string[] | null {\n const single = typeof options.organizationId === 'string' ? options.organizationId.trim() : ''\n if (single) return [single]\n if (!Array.isArray(options.organizationIds)) return null\n return Array.from(new Set(\n options.organizationIds\n .map((value) => (typeof value === 'string' ? value.trim() : ''))\n .filter((value) => value.length > 0),\n ))\n}\n\n/**\n * VectorSearchStrategy provides semantic search using embeddings.\n * It wraps the existing vector module infrastructure.\n */\nexport class VectorSearchStrategy implements SearchStrategy {\n readonly id: SearchStrategyId = 'vector'\n readonly name = 'Vector Search'\n readonly priority = 20 // Medium priority\n\n get supportsIndexDocFilter(): boolean {\n return this.vectorDriver.supportsIndexDocFilter === true\n }\n\n private readonly defaultLimit: number\n private ready = false\n private readyPromise: Promise<void> | null = null\n\n constructor(\n private readonly embeddingService: EmbeddingService,\n private readonly vectorDriver: VectorDriver,\n config?: VectorStrategyConfig,\n ) {\n this.defaultLimit = config?.defaultLimit ?? 20\n }\n\n async isAvailable(): Promise<boolean> {\n if (!this.embeddingService.available) return false\n // A configured embedding provider says nothing about the vector store. When the\n // store cannot serve writes (pgvector extension missing), reporting availability\n // here makes SearchService call ensureReady() for every record and fail the whole\n // index/delete operation. Drivers without a probe keep the previous behavior.\n if (!this.vectorDriver.isHealthy) return true\n return this.vectorDriver.isHealthy()\n }\n\n async ensureReady(): Promise<void> {\n if (this.ready) return\n if (!this.readyPromise) {\n this.readyPromise = this.vectorDriver.ensureReady().then(() => {\n this.ready = true\n })\n }\n return this.readyPromise\n }\n\n async search(query: string, options: SearchOptions): Promise<SearchResult[]> {\n const organizationIds = normalizeOrganizationIds(options)\n if (organizationIds && organizationIds.length === 0) return []\n if (options.indexDocFilter && !this.supportsIndexDocFilter) return []\n\n await this.ensureReady()\n const embedding = await this.embeddingService.createEmbedding(query)\n\n // Build filter - only include organizationId if it's a real value\n // The pgvector driver treats null as \"only records with null org_id\",\n // but we want null/undefined to mean \"no organization filter\"\n const filter: {\n tenantId: string\n organizationId?: string | null\n organizationIds?: string[] | null\n entityIds?: EntityId[]\n indexDocFilter?: SearchOptions['indexDocFilter']\n } = {\n tenantId: options.tenantId,\n entityIds: options.entityTypes as EntityId[],\n ...(options.indexDocFilter ? { indexDocFilter: options.indexDocFilter } : {}),\n }\n\n if (organizationIds) {\n filter.organizationIds = organizationIds\n if (organizationIds.length === 1) {\n filter.organizationId = organizationIds[0]\n }\n }\n\n const results = await this.vectorDriver.query({\n vector: embedding,\n limit: options.limit ?? this.defaultLimit,\n filter,\n })\n\n return results.map((hit) => ({\n entityId: hit.entityId,\n recordId: hit.recordId,\n score: hit.score,\n source: this.id,\n organizationId: hit.organizationId ?? null,\n presenter: hit.presenter ?? undefined,\n url: hit.primaryLinkHref ?? hit.url ?? undefined,\n links: hit.links?.map((link) => ({\n href: link.href,\n label: link.label ?? '',\n kind: link.kind,\n })),\n metadata: hit.payload ?? undefined,\n }))\n }\n\n async index(record: IndexableRecord): Promise<void> {\n await this.ensureReady()\n // Use text from buildSource if available, otherwise fall back to generic extraction\n const textContent = record.text !== undefined\n ? (Array.isArray(record.text) ? record.text.join('\\n') : record.text)\n : this.buildTextContent(record)\n if (!textContent.trim()) return\n\n const embedding = await this.embeddingService.createEmbedding(textContent)\n\n const doc: VectorDriverDocument = {\n entityId: record.entityId as EntityId,\n recordId: record.recordId,\n tenantId: record.tenantId,\n organizationId: record.organizationId,\n checksum: this.computeChecksum(record),\n embedding,\n url: record.url,\n presenter: record.presenter,\n links: record.links,\n driverId: this.vectorDriver.id,\n resultTitle: record.presenter?.title ?? record.recordId,\n resultSubtitle: record.presenter?.subtitle,\n resultIcon: record.presenter?.icon,\n resultBadge: record.presenter?.badge,\n }\n\n await this.vectorDriver.upsert(doc)\n }\n\n async delete(entityId: EntityId, recordId: string, tenantId: string): Promise<void> {\n await this.ensureReady()\n await this.vectorDriver.delete(entityId, recordId, tenantId)\n }\n\n async purge(entityId: EntityId, tenantId: string, organizationId?: string | null): Promise<void> {\n await this.ensureReady()\n if (this.vectorDriver.purge) {\n await this.vectorDriver.purge(entityId, tenantId, organizationId)\n }\n }\n\n /**\n * Build text content from record fields for embedding.\n */\n private buildTextContent(record: IndexableRecord): string {\n const parts: string[] = []\n\n // Add presenter info\n if (record.presenter?.title) {\n parts.push(record.presenter.title)\n }\n if (record.presenter?.subtitle) {\n parts.push(record.presenter.subtitle)\n }\n\n // Add string fields from record\n for (const [, value] of Object.entries(plaintextSearchFields(record))) {\n if (typeof value === 'string' && value.trim()) {\n parts.push(value)\n }\n }\n\n return parts.join(' ').trim()\n }\n\n /**\n * Compute a checksum for change detection using SHA-256.\n * Uses checksumSource from buildSource if available, otherwise uses fields/presenter/url.\n */\n private computeChecksum(record: IndexableRecord): string {\n const source = record.checksumSource !== undefined\n ? record.checksumSource\n : {\n fields: record.fields,\n presenter: record.presenter,\n url: record.url,\n }\n const content = JSON.stringify(source)\n return createHash('sha256').update(content).digest('hex').slice(0, 16)\n }\n\n /**\n * List entries in the vector index (for admin/debugging).\n */\n async listEntries(options: {\n tenantId: string\n organizationId?: string | null\n entityId?: string\n limit?: number\n offset?: number\n }): Promise<Array<{\n entityId: string\n recordId: string\n tenantId: string\n organizationId: string | null\n presenter?: unknown\n url?: string\n }>> {\n await this.ensureReady()\n // Delegate to vector driver's list method if available\n const listMethod = (this.vectorDriver as unknown as {\n list?: (options: {\n tenantId: string\n organizationId?: string | null\n entityId?: string\n limit?: number\n offset?: number\n }) => Promise<unknown[]>\n }).list\n\n if (typeof listMethod === 'function') {\n const entries = await listMethod.call(this.vectorDriver, options)\n return entries as Array<{\n entityId: string\n recordId: string\n tenantId: string\n organizationId: string | null\n presenter?: unknown\n url?: string\n }>\n }\n\n // Fallback: return empty array if driver doesn't support listing\n searchDebugWarn('VectorSearchStrategy', 'Vector driver does not support listing entries')\n return []\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/search",
|
|
3
|
-
"version": "0.10.1-develop.
|
|
3
|
+
"version": "0.10.1-develop.7793.1.9e0c43fdde",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -127,9 +127,9 @@
|
|
|
127
127
|
"zod": "^4.4.3"
|
|
128
128
|
},
|
|
129
129
|
"peerDependencies": {
|
|
130
|
-
"@open-mercato/core": "0.10.1-develop.
|
|
131
|
-
"@open-mercato/queue": "0.10.1-develop.
|
|
132
|
-
"@open-mercato/shared": "0.10.1-develop.
|
|
130
|
+
"@open-mercato/core": "0.10.1-develop.7793.1.9e0c43fdde",
|
|
131
|
+
"@open-mercato/queue": "0.10.1-develop.7793.1.9e0c43fdde",
|
|
132
|
+
"@open-mercato/shared": "0.10.1-develop.7793.1.9e0c43fdde"
|
|
133
133
|
},
|
|
134
134
|
"devDependencies": {
|
|
135
135
|
"@types/jest": "^30.0.0",
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { registerSearchModule, type SearchContainer } from '../di'
|
|
2
|
+
import type { SearchIndexer } from '../indexer/search-indexer'
|
|
3
|
+
import type { FullTextSearchDocument } from '../fulltext/types'
|
|
4
|
+
|
|
5
|
+
jest.mock('awilix', () => ({ asValue: (value: unknown) => ({ _value: value }) }))
|
|
6
|
+
jest.mock('../fulltext/drivers', () => ({
|
|
7
|
+
createFulltextDriver: () => ({
|
|
8
|
+
id: 'capture',
|
|
9
|
+
ensureReady: async () => {},
|
|
10
|
+
isHealthy: async () => true,
|
|
11
|
+
search: async () => [],
|
|
12
|
+
index: async (document: FullTextSearchDocument) => { mockDocuments.push(document) },
|
|
13
|
+
delete: async () => {},
|
|
14
|
+
}),
|
|
15
|
+
}))
|
|
16
|
+
|
|
17
|
+
const mockDocuments: FullTextSearchDocument[] = []
|
|
18
|
+
const originalSingletonSetting = process.env.SEARCH_DISABLE_SINGLETON_CACHE
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mockDocuments.length = 0
|
|
22
|
+
process.env.SEARCH_DISABLE_SINGLETON_CACHE = '1'
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
afterAll(() => {
|
|
26
|
+
if (originalSingletonSetting === undefined) delete process.env.SEARCH_DISABLE_SINGLETON_CACHE
|
|
27
|
+
else process.env.SEARCH_DISABLE_SINGLETON_CACHE = originalSingletonSetting
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
function makeContainer(em?: unknown): SearchContainer {
|
|
31
|
+
const registrations: Record<string, unknown> = {}
|
|
32
|
+
return {
|
|
33
|
+
resolve<T>(name: string): T {
|
|
34
|
+
if (name === 'em' && em) return em as T
|
|
35
|
+
if (name in registrations) return registrations[name] as T
|
|
36
|
+
throw new Error('[internal] Missing registration')
|
|
37
|
+
},
|
|
38
|
+
register(values) {
|
|
39
|
+
for (const [key, resolver] of Object.entries(values)) {
|
|
40
|
+
registrations[key] = (resolver as { _value: unknown })._value
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function registerIndexer(container: SearchContainer): SearchIndexer {
|
|
47
|
+
registerSearchModule(container, {
|
|
48
|
+
skipTokens: true,
|
|
49
|
+
skipVector: true,
|
|
50
|
+
defaultStrategies: ['fulltext'],
|
|
51
|
+
moduleConfigs: [{ entities: [{ entityId: 'example:todo' }] }],
|
|
52
|
+
})
|
|
53
|
+
return container.resolve<SearchIndexer>('searchIndexer')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function index(indexer: SearchIndexer) {
|
|
57
|
+
await indexer.indexRecord({
|
|
58
|
+
entityId: 'example:todo', recordId: 'record-1', tenantId: 'tenant-1',
|
|
59
|
+
record: { title: 'Public title', cf_secret: 'PRIVATE', cf_note: 'Public note' },
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
it('wires live definitions into the production indexer independently of the base-column encryption flag', async () => {
|
|
64
|
+
const query = {
|
|
65
|
+
select: () => query,
|
|
66
|
+
where: () => query,
|
|
67
|
+
execute: async () => [{ key: 'secret', config_json: { encrypted: true } }],
|
|
68
|
+
}
|
|
69
|
+
const container = makeContainer({ getKysely: () => ({ selectFrom: () => query }) })
|
|
70
|
+
|
|
71
|
+
await index(registerIndexer(container))
|
|
72
|
+
|
|
73
|
+
expect(mockDocuments[0].fields).toEqual({ title: 'Public title', cf_note: 'Public note' })
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('fails closed for custom fields when the DI container has no entity manager', async () => {
|
|
77
|
+
await index(registerIndexer(makeContainer()))
|
|
78
|
+
|
|
79
|
+
expect(mockDocuments[0].fields).toEqual({ title: 'Public title' })
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('fails closed for custom fields when the live definition query fails', async () => {
|
|
83
|
+
const container = makeContainer({ getKysely: () => ({ selectFrom: () => { throw new Error('[internal] Lookup failed') } }) })
|
|
84
|
+
|
|
85
|
+
await index(registerIndexer(container))
|
|
86
|
+
|
|
87
|
+
expect(mockDocuments[0].fields).toEqual({ title: 'Public title' })
|
|
88
|
+
})
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
import { createEncryptedCustomFieldKeysResolver, type CustomFieldDefinitionsDatabase } from '../lib/encrypted-custom-field-resolver'
|
|
3
|
+
|
|
4
|
+
type Definition = { key: string; config_json: unknown }
|
|
5
|
+
|
|
6
|
+
function makeDatabase(definitions: Definition[]) {
|
|
7
|
+
const predicates: Array<[string, string, unknown]> = []
|
|
8
|
+
const query = {
|
|
9
|
+
select: () => query,
|
|
10
|
+
where: (field: string, operator: string, value: unknown) => { predicates.push([field, operator, value]); return query },
|
|
11
|
+
execute: async () => definitions,
|
|
12
|
+
}
|
|
13
|
+
const database = { selectFrom: (table: string) => { expect(table).toBe('custom_field_defs'); return query } } as unknown as Kysely<CustomFieldDefinitionsDatabase>
|
|
14
|
+
return { database, predicates }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('encrypted custom-field definitions', () => {
|
|
18
|
+
it('unions encrypted keys across scopes, including sanitized query-engine aliases and JSON config', async () => {
|
|
19
|
+
const { database, predicates } = makeDatabase([
|
|
20
|
+
{ key: ' Tax-Number ', config_json: { encrypted: true } },
|
|
21
|
+
{ key: 'private.code', config_json: '{"encrypted":true}' },
|
|
22
|
+
{ key: 'plain', config_json: { encrypted: false } },
|
|
23
|
+
{ key: '', config_json: { encrypted: true } },
|
|
24
|
+
])
|
|
25
|
+
|
|
26
|
+
const keys = await createEncryptedCustomFieldKeysResolver(database)('example:todo')
|
|
27
|
+
|
|
28
|
+
expect(keys).toEqual(new Set(['tax-number', 'tax_number', 'private.code', 'private_code']))
|
|
29
|
+
expect(predicates).toEqual([['entity_id', '=', 'example:todo'], ['deleted_at', 'is', null]])
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('returns an explicit empty policy when the entity has no encrypted definitions', async () => {
|
|
33
|
+
const { database } = makeDatabase([{ key: 'plain', config_json: {} }])
|
|
34
|
+
|
|
35
|
+
await expect(createEncryptedCustomFieldKeysResolver(database)('example:todo')).resolves.toEqual(new Set())
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('propagates unreadable definitions so the indexer can deny all custom fields', async () => {
|
|
39
|
+
const database = { selectFrom: () => { throw new Error('[internal] Database unavailable') } } as unknown as Kysely<CustomFieldDefinitionsDatabase>
|
|
40
|
+
|
|
41
|
+
await expect(createEncryptedCustomFieldKeysResolver(database)('example:todo')).rejects.toThrow('Database unavailable')
|
|
42
|
+
})
|
|
43
|
+
})
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import type { Kysely } from 'kysely'
|
|
2
|
+
import { SearchService } from '../service'
|
|
3
|
+
import { SearchIndexer } from '../indexer/search-indexer'
|
|
4
|
+
import { FullTextSearchStrategy } from '../strategies/fulltext.strategy'
|
|
5
|
+
import { VectorSearchStrategy } from '../strategies/vector.strategy'
|
|
6
|
+
import { TokenSearchStrategy } from '../strategies/token.strategy'
|
|
7
|
+
import type { FullTextSearchDriver, FullTextSearchDocument } from '../fulltext/types'
|
|
8
|
+
import type { VectorDriver } from '../vector/types'
|
|
9
|
+
import type { SearchEntityConfig, IndexableRecord } from '../types'
|
|
10
|
+
import type { QueryEngine, QueryResult } from '@open-mercato/shared/lib/query/types'
|
|
11
|
+
import type { EncryptedCustomFieldKeysResolver } from '../lib/encrypted-custom-field-resolver'
|
|
12
|
+
import { replaceSearchTokensForRecord, replaceSearchTokensForBatch } from '@open-mercato/core/modules/query_index/lib/search-tokens'
|
|
13
|
+
import { resolveQueryIndexSearchScope } from '@open-mercato/core/modules/query_index/lib/search-scope'
|
|
14
|
+
|
|
15
|
+
jest.mock('@open-mercato/core/modules/query_index/lib/search-scope', () => ({
|
|
16
|
+
...jest.requireActual<typeof import('@open-mercato/core/modules/query_index/lib/search-scope')>('@open-mercato/core/modules/query_index/lib/search-scope'),
|
|
17
|
+
resolveQueryIndexSearchScope: jest.fn(async () => ({
|
|
18
|
+
searchableEntityTypes: ['example:todo'],
|
|
19
|
+
registeredSourceTypes: ['example:todo'],
|
|
20
|
+
blockedEntityTypes: [],
|
|
21
|
+
tenantGlobalEntityTypes: [],
|
|
22
|
+
customEntityStorage: false,
|
|
23
|
+
})),
|
|
24
|
+
}))
|
|
25
|
+
|
|
26
|
+
jest.mock('@open-mercato/core/modules/query_index/lib/search-tokens', () => ({
|
|
27
|
+
replaceSearchTokensForRecord: jest.fn(async () => {}),
|
|
28
|
+
replaceSearchTokensForBatch: jest.fn(async () => {}),
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
jest.mock('@open-mercato/shared/lib/telemetry/runtime', () => ({
|
|
32
|
+
getTelemetryRuntime: () => ({ reportError: (...args: unknown[]) => mockReportError(...args) }),
|
|
33
|
+
}))
|
|
34
|
+
|
|
35
|
+
const mockReportError = jest.fn((..._args: unknown[]) => {})
|
|
36
|
+
const entityId = 'example:todo'
|
|
37
|
+
|
|
38
|
+
function makeFields(id = 'record-1') {
|
|
39
|
+
return {
|
|
40
|
+
id,
|
|
41
|
+
title: 'Public title',
|
|
42
|
+
cf_secret: 'PRIVATE-ALIAS',
|
|
43
|
+
'cf:secret': 'PRIVATE-CANONICAL',
|
|
44
|
+
cf_order_ref: 'PRIVATE-SANITIZED',
|
|
45
|
+
'cf:order-ref': 'PRIVATE-PUNCTUATED',
|
|
46
|
+
cf_note: 'Visible custom note',
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function createHarness(options: {
|
|
51
|
+
resolver?: EncryptedCustomFieldKeysResolver | null
|
|
52
|
+
buildSource?: SearchEntityConfig['buildSource']
|
|
53
|
+
records?: Record<string, unknown>[]
|
|
54
|
+
bulkDriver?: boolean
|
|
55
|
+
} = {}) {
|
|
56
|
+
const documents: FullTextSearchDocument[] = []
|
|
57
|
+
const embeddings: string[] = []
|
|
58
|
+
const driver: FullTextSearchDriver = {
|
|
59
|
+
id: 'capture',
|
|
60
|
+
ensureReady: async () => {},
|
|
61
|
+
isHealthy: async () => true,
|
|
62
|
+
search: async () => [],
|
|
63
|
+
index: async (document) => { documents.push(document) },
|
|
64
|
+
delete: async () => {},
|
|
65
|
+
...(options.bulkDriver === false ? {} : {
|
|
66
|
+
bulkIndex: async (batch: FullTextSearchDocument[]) => { documents.push(...batch) },
|
|
67
|
+
}),
|
|
68
|
+
}
|
|
69
|
+
const vectorDriver: VectorDriver = {
|
|
70
|
+
id: 'pgvector',
|
|
71
|
+
ensureReady: async () => {},
|
|
72
|
+
upsert: async () => {},
|
|
73
|
+
query: async () => [],
|
|
74
|
+
delete: async () => {},
|
|
75
|
+
getChecksum: async () => null,
|
|
76
|
+
}
|
|
77
|
+
const embeddingService = {
|
|
78
|
+
available: true,
|
|
79
|
+
createEmbedding: async (text: string) => { embeddings.push(text); return [0.1] },
|
|
80
|
+
}
|
|
81
|
+
const service = new SearchService({
|
|
82
|
+
strategies: [new FullTextSearchStrategy(driver), new VectorSearchStrategy(embeddingService, vectorDriver), new TokenSearchStrategy({} as Kysely<unknown>)],
|
|
83
|
+
defaultStrategies: ['fulltext', 'vector', 'tokens'],
|
|
84
|
+
})
|
|
85
|
+
const resolver = options.resolver === undefined
|
|
86
|
+
? jest.fn(async () => new Set(['secret', 'order-ref', 'order_ref']))
|
|
87
|
+
: options.resolver
|
|
88
|
+
const queryEngine: QueryEngine = {
|
|
89
|
+
query: async (_entity, query) => {
|
|
90
|
+
const id = (query?.filters as { id?: string } | undefined)?.id
|
|
91
|
+
const rows = options.records ?? [makeFields()]
|
|
92
|
+
const items = id ? rows.filter((row) => row.id === id) : rows
|
|
93
|
+
return { items, total: items.length } as QueryResult
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
const indexer = new SearchIndexer(service, [{ entities: [{ entityId, buildSource: options.buildSource }] }], {
|
|
97
|
+
queryEngine,
|
|
98
|
+
...(resolver ? { encryptedCustomFieldKeysResolver: resolver } : {}),
|
|
99
|
+
})
|
|
100
|
+
return { indexer, service, documents, embeddings, resolver }
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function expectPlaintextSafe(harness: ReturnType<typeof createHarness>, count = 1) {
|
|
104
|
+
expect(harness.documents).toHaveLength(count)
|
|
105
|
+
expect(harness.embeddings).toHaveLength(count)
|
|
106
|
+
for (const document of harness.documents) {
|
|
107
|
+
expect(document.fields).toEqual(expect.objectContaining({ title: 'Public title', cf_note: 'Visible custom note' }))
|
|
108
|
+
expect(JSON.stringify(document)).not.toContain('PRIVATE-')
|
|
109
|
+
}
|
|
110
|
+
for (const text of harness.embeddings) {
|
|
111
|
+
expect(text).toContain('Public title')
|
|
112
|
+
expect(text).toContain('Visible custom note')
|
|
113
|
+
expect(text).not.toContain('PRIVATE-')
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
beforeEach(() => {
|
|
118
|
+
jest.clearAllMocks()
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('plaintext custom-field boundaries (#7894)', () => {
|
|
122
|
+
it.each(['single', 'bulk'] as const)('retains the real token source-scope rejection through %s indexing', async (entryPoint) => {
|
|
123
|
+
jest.mocked(resolveQueryIndexSearchScope).mockResolvedValueOnce({
|
|
124
|
+
searchableEntityTypes: [],
|
|
125
|
+
registeredSourceTypes: [entityId],
|
|
126
|
+
blockedEntityTypes: [entityId],
|
|
127
|
+
tenantGlobalEntityTypes: [],
|
|
128
|
+
customEntityStorage: false,
|
|
129
|
+
})
|
|
130
|
+
const harness = createHarness()
|
|
131
|
+
const params = { entityId, recordId: 'record-1', tenantId: 'tenant-1', record: makeFields() }
|
|
132
|
+
|
|
133
|
+
if (entryPoint === 'single') {
|
|
134
|
+
await harness.indexer.indexRecord(params)
|
|
135
|
+
} else {
|
|
136
|
+
await harness.indexer.bulkIndexRecords([params])
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
expectPlaintextSafe(harness)
|
|
140
|
+
expect(resolveQueryIndexSearchScope).toHaveBeenCalledTimes(1)
|
|
141
|
+
expect(replaceSearchTokensForRecord).not.toHaveBeenCalled()
|
|
142
|
+
expect(replaceSearchTokensForBatch).not.toHaveBeenCalled()
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('filters canonical, aliased and sanitized keys before real fulltext/vector strategies, retaining token input and the original record', async () => {
|
|
146
|
+
const harness = createHarness()
|
|
147
|
+
const fields = makeFields()
|
|
148
|
+
const original = { ...fields }
|
|
149
|
+
|
|
150
|
+
await harness.indexer.indexRecord({ entityId, recordId: 'record-1', tenantId: 'tenant-1', record: fields })
|
|
151
|
+
|
|
152
|
+
expectPlaintextSafe(harness)
|
|
153
|
+
expect(jest.mocked(replaceSearchTokensForRecord).mock.calls[0][1].doc).toEqual(expect.objectContaining({
|
|
154
|
+
'cf:secret': 'PRIVATE-CANONICAL', 'cf:order_ref': 'PRIVATE-SANITIZED', 'cf:order-ref': 'PRIVATE-PUNCTUATED',
|
|
155
|
+
}))
|
|
156
|
+
expect(fields).toEqual(original)
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
it.each([true, false])('protects bulk indexing with native driver bulk=%s and shares one entity lookup', async (bulkDriver) => {
|
|
160
|
+
const resolver = jest.fn(async () => new Set(['secret', 'order-ref', 'order_ref']))
|
|
161
|
+
const harness = createHarness({ resolver, bulkDriver })
|
|
162
|
+
const rows = [makeFields('first'), makeFields('second')]
|
|
163
|
+
|
|
164
|
+
await harness.indexer.bulkIndexRecords(rows.map((record) => ({ entityId, recordId: record.id, tenantId: 'tenant-1', record })))
|
|
165
|
+
|
|
166
|
+
expectPlaintextSafe(harness, 2)
|
|
167
|
+
expect(resolver).toHaveBeenCalledTimes(1)
|
|
168
|
+
const payloads = jest.mocked(replaceSearchTokensForBatch).mock.calls[0][1]
|
|
169
|
+
expect(payloads.map((record) => record.doc['cf:secret'])).toEqual(['PRIVATE-CANONICAL', 'PRIVATE-CANONICAL'])
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('protects ID-loaded batches used by queue workers with one lookup per entity', async () => {
|
|
173
|
+
const resolver = jest.fn(async () => new Set(['secret', 'order-ref', 'order_ref']))
|
|
174
|
+
const rows = [makeFields('first'), makeFields('second')]
|
|
175
|
+
const harness = createHarness({ resolver, records: rows })
|
|
176
|
+
|
|
177
|
+
await harness.indexer.indexRecordsById({ items: rows.map((record) => ({ entityId, recordId: record.id })), tenantId: 'tenant-1' })
|
|
178
|
+
|
|
179
|
+
expectPlaintextSafe(harness, 2)
|
|
180
|
+
expect(resolver).toHaveBeenCalledTimes(1)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('protects the reindex builder as well as direct and ID-loaded indexing', async () => {
|
|
184
|
+
const harness = createHarness()
|
|
185
|
+
|
|
186
|
+
const result = await harness.indexer.reindexEntity({ entityId, tenantId: 'tenant-1' })
|
|
187
|
+
|
|
188
|
+
expect(result.success).toBe(true)
|
|
189
|
+
expectPlaintextSafe(harness)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
it.each(['by-id', 'bulk', 'reindex'] as const)('keeps fulltext exclusions and skips vector fallback when buildSource throws through %s', async (entryPoint) => {
|
|
193
|
+
const harness = createHarness({ buildSource: async () => { throw new Error('[internal] Source unavailable') } })
|
|
194
|
+
|
|
195
|
+
if (entryPoint === 'by-id') {
|
|
196
|
+
await harness.indexer.indexRecordById({ entityId, recordId: 'record-1', tenantId: 'tenant-1' })
|
|
197
|
+
} else if (entryPoint === 'bulk') {
|
|
198
|
+
await harness.indexer.bulkIndexRecords([{ entityId, recordId: 'record-1', tenantId: 'tenant-1', record: makeFields() }])
|
|
199
|
+
} else {
|
|
200
|
+
const result = await harness.indexer.reindexEntity({ entityId, tenantId: 'tenant-1' })
|
|
201
|
+
expect(result.success).toBe(true)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
expect(harness.documents).toHaveLength(1)
|
|
205
|
+
expect(harness.documents[0].fields).toEqual({ id: 'record-1', title: 'Public title', cf_note: 'Visible custom note' })
|
|
206
|
+
expect(JSON.stringify(harness.documents[0])).not.toContain('PRIVATE-')
|
|
207
|
+
expect(harness.embeddings).toEqual([])
|
|
208
|
+
const tokenDocuments = [
|
|
209
|
+
...jest.mocked(replaceSearchTokensForRecord).mock.calls.map((call) => call[1].doc),
|
|
210
|
+
...jest.mocked(replaceSearchTokensForBatch).mock.calls.flatMap((call) => call[1].map((record) => record.doc)),
|
|
211
|
+
]
|
|
212
|
+
expect(tokenDocuments).toHaveLength(1)
|
|
213
|
+
expect(tokenDocuments[0]).toEqual(expect.objectContaining({ 'cf:secret': 'PRIVATE-CANONICAL', 'cf:note': 'Visible custom note' }))
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
it.each(['async', 'sync'] as const)('fails closed for all custom fields on a %s resolver error while token inputs remain unchanged', async (kind) => {
|
|
217
|
+
const error = new Error('[internal] Definition lookup unavailable')
|
|
218
|
+
const resolver: EncryptedCustomFieldKeysResolver = kind === 'async'
|
|
219
|
+
? async () => { throw error }
|
|
220
|
+
: () => { throw error }
|
|
221
|
+
const harness = createHarness({ resolver })
|
|
222
|
+
|
|
223
|
+
await harness.indexer.indexRecord({ entityId, recordId: 'record-1', tenantId: 'tenant-1', record: makeFields() })
|
|
224
|
+
|
|
225
|
+
expect(harness.documents[0].fields).toEqual({ id: 'record-1', title: 'Public title' })
|
|
226
|
+
expect(harness.embeddings[0]).toBe('record-1 Public title')
|
|
227
|
+
expect(jest.mocked(replaceSearchTokensForRecord).mock.calls[0][1].doc).toEqual(expect.objectContaining({ 'cf:secret': 'PRIVATE-CANONICAL', 'cf:note': 'Visible custom note' }))
|
|
228
|
+
expect(mockReportError).toHaveBeenCalledWith(error, expect.objectContaining({ code: 'search.encrypted_custom_fields_unresolved' }))
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('refreshes definitions on each indexing call instead of reusing an older positive policy', async () => {
|
|
232
|
+
const resolver = jest.fn<ReturnType<EncryptedCustomFieldKeysResolver>, Parameters<EncryptedCustomFieldKeysResolver>>()
|
|
233
|
+
.mockResolvedValueOnce(new Set()).mockResolvedValueOnce(new Set(['secret', 'order-ref', 'order_ref']))
|
|
234
|
+
const harness = createHarness({ resolver })
|
|
235
|
+
const params = { entityId, recordId: 'record-1', tenantId: 'tenant-1', record: makeFields() }
|
|
236
|
+
|
|
237
|
+
await harness.indexer.indexRecord(params)
|
|
238
|
+
await harness.indexer.indexRecord(params)
|
|
239
|
+
|
|
240
|
+
expect(harness.documents[0].fields.cf_secret).toBe('PRIVATE-ALIAS')
|
|
241
|
+
expect(JSON.stringify(harness.documents[1])).not.toContain('PRIVATE-')
|
|
242
|
+
expect(resolver).toHaveBeenCalledTimes(2)
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('preserves explicit source text and legacy direct clients without metadata', async () => {
|
|
246
|
+
const harness = createHarness({ resolver: null, buildSource: async () => ({ text: 'Explicit source text' }) })
|
|
247
|
+
|
|
248
|
+
await harness.indexer.indexRecord({ entityId, recordId: 'record-1', tenantId: 'tenant-1', record: makeFields() })
|
|
249
|
+
|
|
250
|
+
expect(harness.embeddings).toEqual(['Explicit source text'])
|
|
251
|
+
expect(harness.documents[0].fields.cf_secret).toBe('PRIVATE-ALIAS')
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it('keeps exclusion metadata effective after JSON serialization for custom direct clients', async () => {
|
|
255
|
+
const harness = createHarness({ resolver: null })
|
|
256
|
+
const record: IndexableRecord = { entityId, recordId: 'record-1', tenantId: 'tenant-1', fields: makeFields(), plaintextExcludedCustomFields: ['secret', 'order-ref'] }
|
|
257
|
+
|
|
258
|
+
await harness.service.index(JSON.parse(JSON.stringify(record)) as IndexableRecord)
|
|
259
|
+
|
|
260
|
+
expectPlaintextSafe(harness)
|
|
261
|
+
})
|
|
262
|
+
})
|
package/src/di.ts
CHANGED
|
@@ -26,9 +26,15 @@ import type { EncryptionMapEntry } from './lib/field-policy'
|
|
|
26
26
|
import type { TenantDataEncryptionService } from '@open-mercato/shared/lib/encryption/tenantDataEncryptionService'
|
|
27
27
|
import { createPresenterEnricher } from './lib/presenter-enricher'
|
|
28
28
|
import { createEncryptionMapResolver } from './lib/encryption-map-resolver'
|
|
29
|
+
import { createEncryptedCustomFieldKeysResolver, type CustomFieldDefinitionsDatabase, type EncryptedCustomFieldKeysResolver } from './lib/encrypted-custom-field-resolver'
|
|
30
|
+
import { reportSearchError } from './lib/debug'
|
|
29
31
|
|
|
30
32
|
export { createEncryptionMapResolver } from './lib/encryption-map-resolver'
|
|
31
33
|
|
|
34
|
+
type KyselyEntityManager = {
|
|
35
|
+
getKysely<Database>(): Kysely<Database>
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
const FULLTEXT_DRIVER_KEY = '__omSearchFulltextDriver__'
|
|
33
39
|
|
|
34
40
|
type SearchModuleGlobals = {
|
|
@@ -251,10 +257,22 @@ export function registerSearchModule(
|
|
|
251
257
|
// Queue not available, queue-based vector reindex will be disabled
|
|
252
258
|
}
|
|
253
259
|
|
|
260
|
+
let encryptedCustomFieldKeysResolver: EncryptedCustomFieldKeysResolver
|
|
261
|
+
try {
|
|
262
|
+
const em = container.resolve<KyselyEntityManager>('em')
|
|
263
|
+
encryptedCustomFieldKeysResolver = createEncryptedCustomFieldKeysResolver(em.getKysely<CustomFieldDefinitionsDatabase>())
|
|
264
|
+
} catch (error) {
|
|
265
|
+
reportSearchError('SearchModule', error, 'search.custom_field_definitions_unavailable')
|
|
266
|
+
encryptedCustomFieldKeysResolver = async () => {
|
|
267
|
+
throw new Error('[internal] Custom-field definitions are unavailable')
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
254
271
|
const searchIndexer = new SearchIndexer(searchService, moduleConfigs, {
|
|
255
272
|
queryEngine,
|
|
256
273
|
fulltextQueue,
|
|
257
274
|
vectorQueue,
|
|
275
|
+
encryptedCustomFieldKeysResolver,
|
|
258
276
|
})
|
|
259
277
|
|
|
260
278
|
// Register in container
|