@ai-pip/csl 0.1.0 → 0.1.3
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 +607 -56
- package/package.json +10 -28
- package/src/index.test.ts +429 -0
- package/{index.ts → src/index.ts} +100 -65
- package/src/test-external.js +547 -0
- package/layers/csl/adapters/index.ts +0 -9
- package/layers/csl/adapters/input/DOMAdapter.ts +0 -236
- package/layers/csl/adapters/input/UIAdapter.ts +0 -0
- package/layers/csl/adapters/output/ConsoleLogger.ts +0 -34
- package/layers/csl/adapters/output/CryptoHashGenerator.ts +0 -29
- package/layers/csl/adapters/output/FilePolicyRepository.ts +0 -0
- package/layers/csl/adapters/output/InMemoryPolicyRepository.ts +0 -135
- package/layers/csl/adapters/output/SystemTimestampProvider.ts +0 -9
- package/layers/csl/domain/entities/CSLResult.ts +0 -309
- package/layers/csl/domain/entities/Segment.ts +0 -338
- package/layers/csl/domain/entities/index.ts +0 -2
- package/layers/csl/domain/exceptions/ClassificationError.ts +0 -26
- package/layers/csl/domain/exceptions/SegmentationError.ts +0 -30
- package/layers/csl/domain/exceptions/index.ts +0 -2
- package/layers/csl/domain/index.ts +0 -4
- package/layers/csl/domain/services/AnomalyService.ts +0 -255
- package/layers/csl/domain/services/LineageService.ts +0 -224
- package/layers/csl/domain/services/NormalizationService.ts +0 -392
- package/layers/csl/domain/services/OriginClassificationService.ts +0 -69
- package/layers/csl/domain/services/PiDetectionService.ts +0 -475
- package/layers/csl/domain/services/PolicyService.ts +0 -296
- package/layers/csl/domain/services/SegmentClassificationService.ts +0 -105
- package/layers/csl/domain/services/SerializationService.ts +0 -229
- package/layers/csl/domain/services/index.ts +0 -7
- package/layers/csl/domain/value-objects/AnomalyScore.ts +0 -23
- package/layers/csl/domain/value-objects/ContentHash.ts +0 -54
- package/layers/csl/domain/value-objects/LineageEntry.ts +0 -42
- package/layers/csl/domain/value-objects/Origin-map.ts +0 -67
- package/layers/csl/domain/value-objects/Origin.ts +0 -99
- package/layers/csl/domain/value-objects/Pattern.ts +0 -221
- package/layers/csl/domain/value-objects/PiDetection.ts +0 -140
- package/layers/csl/domain/value-objects/PiDetectionResult.ts +0 -275
- package/layers/csl/domain/value-objects/PolicyRule.ts +0 -151
- package/layers/csl/domain/value-objects/TrustLevel.ts +0 -34
- package/layers/csl/domain/value-objects/index.ts +0 -10
- package/layers/csl/index.ts +0 -3
- package/layers/csl/ports/index.ts +0 -10
- package/layers/csl/ports/input/ClassificationPort.ts +0 -76
- package/layers/csl/ports/input/SegmentationPort.ts +0 -81
- package/layers/csl/ports/output/DOMAdapter.ts +0 -14
- package/layers/csl/ports/output/HashGenerator.ts +0 -18
- package/layers/csl/ports/output/Logger.ts +0 -17
- package/layers/csl/ports/output/PolicyRepository.ts +0 -29
- package/layers/csl/ports/output/SegmentClassified.ts +0 -8
- package/layers/csl/ports/output/TimeStampProvider.ts +0 -5
- package/layers/csl/services/CSLService.ts +0 -393
- package/layers/csl/services/index.ts +0 -1
- package/layers/csl/types/entities-types.ts +0 -37
- package/layers/csl/types/index.ts +0 -4
- package/layers/csl/types/pi-types.ts +0 -111
- package/layers/csl/types/port-output-types.ts +0 -17
- package/layers/csl/types/value-objects-types.ts +0 -213
- package/layers/csl/utils/colors.ts +0 -25
- package/layers/csl/utils/pattern-helpers.ts +0 -174
|
@@ -28,112 +28,111 @@
|
|
|
28
28
|
// ============================================================================
|
|
29
29
|
|
|
30
30
|
// Servicio principal
|
|
31
|
-
export { CSLService, type CSLServiceConfig } from '
|
|
31
|
+
export { CSLService, type CSLServiceConfig } from '@ai-pip/csl-layer'
|
|
32
32
|
|
|
33
33
|
// ============================================================================
|
|
34
34
|
// PORTS (Interfaces públicas)
|
|
35
35
|
// ============================================================================
|
|
36
36
|
|
|
37
37
|
// Input ports (interfaces que CSL expone)
|
|
38
|
-
export type { SegmentationPort } from '
|
|
39
|
-
export type { ClassificationPort } from '
|
|
38
|
+
export type { SegmentationPort } from '@ai-pip/csl-layer'
|
|
39
|
+
export type { ClassificationPort } from '@ai-pip/csl-layer'
|
|
40
40
|
|
|
41
41
|
// Output ports (interfaces que CSL necesita)
|
|
42
|
-
export type { LoggerPort } from '
|
|
43
|
-
export type { HashGeneratorPort } from '
|
|
44
|
-
export type { TimeStampProviderPort } from '
|
|
45
|
-
export type { PolicyRepositoryPort } from '
|
|
46
|
-
export type { SegmentClassified } from '
|
|
42
|
+
export type { LoggerPort } from '@ai-pip/csl-layer'
|
|
43
|
+
export type { HashGeneratorPort } from '@ai-pip/csl-layer'
|
|
44
|
+
export type { TimeStampProviderPort } from '@ai-pip/csl-layer'
|
|
45
|
+
export type { PolicyRepositoryPort } from '@ai-pip/csl-layer'
|
|
46
|
+
export type { SegmentClassified } from '@ai-pip/csl-layer'
|
|
47
47
|
|
|
48
48
|
// ============================================================================
|
|
49
49
|
// ENTIDADES
|
|
50
50
|
// ============================================================================
|
|
51
51
|
|
|
52
|
-
export { CSLResult } from '
|
|
53
|
-
export { Segment } from '
|
|
52
|
+
export { CSLResult } from '@ai-pip/csl-layer'
|
|
53
|
+
export { Segment } from '@ai-pip/csl-layer'
|
|
54
54
|
|
|
55
55
|
// ============================================================================
|
|
56
56
|
// VALUE OBJECTS
|
|
57
57
|
// ============================================================================
|
|
58
58
|
|
|
59
|
-
export { Origin } from '
|
|
60
|
-
export { TrustLevel } from '
|
|
61
|
-
export { AnomalyScore } from '
|
|
62
|
-
export { ContentHash } from '
|
|
63
|
-
export { LineageEntry } from '
|
|
64
|
-
export { PiDetection } from '
|
|
65
|
-
export { PiDetectionResult } from '
|
|
66
|
-
export { PolicyRule } from '
|
|
67
|
-
export { Pattern } from '
|
|
59
|
+
export { Origin } from '@ai-pip/csl-layer'
|
|
60
|
+
export { TrustLevel } from '@ai-pip/csl-layer'
|
|
61
|
+
export { AnomalyScore } from '@ai-pip/csl-layer'
|
|
62
|
+
export { ContentHash } from '@ai-pip/csl-layer'
|
|
63
|
+
export { LineageEntry } from '@ai-pip/csl-layer'
|
|
64
|
+
export { PiDetection } from '@ai-pip/csl-layer'
|
|
65
|
+
export { PiDetectionResult } from '@ai-pip/csl-layer'
|
|
66
|
+
export { PolicyRule } from '@ai-pip/csl-layer'
|
|
67
|
+
export { Pattern } from '@ai-pip/csl-layer'
|
|
68
68
|
|
|
69
69
|
// ============================================================================
|
|
70
70
|
// SERVICIOS DE DOMINIO
|
|
71
71
|
// ============================================================================
|
|
72
72
|
|
|
73
|
-
export { NormalizationService } from '
|
|
74
|
-
export { OriginClassificationService } from '
|
|
75
|
-
export { PiDetectionService } from '
|
|
76
|
-
export { AnomalyService } from '
|
|
77
|
-
export { PolicyService } from '
|
|
78
|
-
export { LineageService } from '
|
|
79
|
-
export { SerializationService } from '
|
|
73
|
+
export { NormalizationService } from '@ai-pip/csl-layer'
|
|
74
|
+
export { OriginClassificationService } from '@ai-pip/csl-layer'
|
|
75
|
+
export { PiDetectionService } from '@ai-pip/csl-layer'
|
|
76
|
+
export { AnomalyService } from '@ai-pip/csl-layer'
|
|
77
|
+
export { PolicyService } from '@ai-pip/csl-layer'
|
|
78
|
+
export { LineageService } from '@ai-pip/csl-layer'
|
|
79
|
+
export { SerializationService } from '@ai-pip/csl-layer'
|
|
80
80
|
|
|
81
81
|
// ============================================================================
|
|
82
82
|
// ADAPTERS (Implementaciones por defecto)
|
|
83
83
|
// ============================================================================
|
|
84
84
|
|
|
85
85
|
// Input adapters
|
|
86
|
-
export { DOMAdapter } from '
|
|
86
|
+
export { DOMAdapter } from '@ai-pip/csl-layer'
|
|
87
87
|
|
|
88
88
|
// Output adapters
|
|
89
|
-
export { ConsoleLogger } from '
|
|
90
|
-
export { CryptoHashGenerator } from '
|
|
91
|
-
export { SystemTimestamProvider } from '
|
|
92
|
-
export { InMemoryPolicyRepository } from '
|
|
89
|
+
export { ConsoleLogger } from '@ai-pip/csl-layer'
|
|
90
|
+
export { CryptoHashGenerator } from '@ai-pip/csl-layer'
|
|
91
|
+
export { SystemTimestamProvider } from '@ai-pip/csl-layer'
|
|
92
|
+
export { InMemoryPolicyRepository } from '@ai-pip/csl-layer'
|
|
93
93
|
|
|
94
94
|
// ============================================================================
|
|
95
95
|
// EXCEPCIONES
|
|
96
96
|
// ============================================================================
|
|
97
97
|
|
|
98
|
-
export { SegmentationError } from '
|
|
99
|
-
export { ClassificationError } from '
|
|
98
|
+
export { SegmentationError } from '@ai-pip/csl-layer'
|
|
99
|
+
export { ClassificationError } from '@ai-pip/csl-layer'
|
|
100
100
|
|
|
101
101
|
// ============================================================================
|
|
102
102
|
// TIPOS
|
|
103
103
|
// ============================================================================
|
|
104
104
|
|
|
105
|
-
export type * from '
|
|
105
|
+
export type * from '@ai-pip/csl-layer'
|
|
106
|
+
// Exportar enums y valores (no solo tipos)
|
|
107
|
+
export { OriginType } from '@ai-pip/csl-layer'
|
|
106
108
|
|
|
107
109
|
// ============================================================================
|
|
108
110
|
// FACTORY FUNCTION - Creación fácil del servicio
|
|
109
111
|
// ============================================================================
|
|
110
112
|
|
|
111
|
-
import {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
import {
|
|
114
|
+
CSLService,
|
|
115
|
+
type CSLServiceConfig,
|
|
116
|
+
DOMAdapter,
|
|
117
|
+
OriginClassificationService,
|
|
118
|
+
PiDetectionService,
|
|
119
|
+
AnomalyService,
|
|
120
|
+
PolicyService,
|
|
121
|
+
LineageService,
|
|
122
|
+
CryptoHashGenerator,
|
|
123
|
+
ConsoleLogger,
|
|
124
|
+
SystemTimestamProvider,
|
|
125
|
+
InMemoryPolicyRepository,
|
|
126
|
+
type PolicyRepositoryPort,
|
|
127
|
+
type LoggerPort,
|
|
128
|
+
type HashGeneratorPort,
|
|
129
|
+
type TimeStampProviderPort
|
|
130
|
+
} from '@ai-pip/csl-layer'
|
|
126
131
|
|
|
127
132
|
/**
|
|
128
133
|
* Opciones para crear el servicio CSL
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* - enableLineageTracking?: boolean
|
|
132
|
-
* - hashAlgorithm?: 'sha256' | 'sha512'
|
|
133
|
-
* - policyRepository?: PolicyRepositoryPort
|
|
134
|
-
* - logger?: LoggerPort
|
|
135
|
-
* - hashGenerator?: HashGeneratorPort
|
|
136
|
-
* - timestampProvider?: TimeStampProviderPort
|
|
134
|
+
* Todas las opciones son opcionales. Si no se proporcionan, se usan valores por defecto.
|
|
135
|
+
*
|
|
137
136
|
* @example
|
|
138
137
|
* ```typescript
|
|
139
138
|
* const options: CreateCSLServiceOptions = {
|
|
@@ -143,7 +142,25 @@ import type { TimeStampProviderPort } from './layers/csl/ports/output/TimeStampP
|
|
|
143
142
|
* }
|
|
144
143
|
|
|
145
144
|
*/
|
|
146
|
-
export interface CreateCSLServiceOptions
|
|
145
|
+
export interface CreateCSLServiceOptions {
|
|
146
|
+
/**
|
|
147
|
+
* Habilita la validación de políticas.
|
|
148
|
+
* Si no se proporciona, se usa `true` por defecto.
|
|
149
|
+
*/
|
|
150
|
+
enablePolicyValidation?: boolean
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Habilita el tracking de linaje para trazabilidad.
|
|
154
|
+
* Si no se proporciona, se usa `true` por defecto.
|
|
155
|
+
*/
|
|
156
|
+
enableLineageTracking?: boolean
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Algoritmo de hash a utilizar.
|
|
160
|
+
* Si no se proporciona, se usa `'sha256'` por defecto.
|
|
161
|
+
*/
|
|
162
|
+
hashAlgorithm?: 'sha256' | 'sha512'
|
|
163
|
+
|
|
147
164
|
/**
|
|
148
165
|
* Repositorio de políticas personalizado.
|
|
149
166
|
* Si no se proporciona, se usa InMemoryPolicyRepository por defecto.
|
|
@@ -176,13 +193,24 @@ export interface CreateCSLServiceOptions extends Partial<CSLServiceConfig> {
|
|
|
176
193
|
* implementaciones por defecto para todas las dependencias. Los usuarios pueden
|
|
177
194
|
* personalizar cualquier componente pasando opciones personalizadas.
|
|
178
195
|
*
|
|
179
|
-
*
|
|
196
|
+
* **Valores por defecto:**
|
|
197
|
+
* - `enablePolicyValidation`: `true`
|
|
198
|
+
* - `enableLineageTracking`: `true`
|
|
199
|
+
* - `hashAlgorithm`: `'sha256'`
|
|
200
|
+
* - `policyRepository`: `InMemoryPolicyRepository`
|
|
201
|
+
* - `logger`: `ConsoleLogger`
|
|
202
|
+
* - `hashGenerator`: `CryptoHashGenerator`
|
|
203
|
+
* - `timestampProvider`: `SystemTimestampProvider`
|
|
204
|
+
*
|
|
205
|
+
* @param options - Opciones de configuración opcionales para el servicio y sus dependencias
|
|
180
206
|
*
|
|
181
207
|
* @returns Una instancia configurada de CSLService lista para usar
|
|
182
208
|
*
|
|
183
209
|
* @example
|
|
184
210
|
* ```typescript
|
|
185
|
-
*
|
|
211
|
+
* import { createCSLService } from '@ai-pip/csl'
|
|
212
|
+
*
|
|
213
|
+
* // Uso básico con valores por defecto
|
|
186
214
|
* const cslService = createCSLService()
|
|
187
215
|
*
|
|
188
216
|
* // Con configuración personalizada
|
|
@@ -193,17 +221,24 @@ export interface CreateCSLServiceOptions extends Partial<CSLServiceConfig> {
|
|
|
193
221
|
* })
|
|
194
222
|
*
|
|
195
223
|
* // Con dependencias personalizadas
|
|
196
|
-
*
|
|
197
|
-
*
|
|
224
|
+
* import { ConsoleLogger, InMemoryPolicyRepository } from '@ai-pip/csl'
|
|
225
|
+
*
|
|
226
|
+
* class CustomLogger extends ConsoleLogger {
|
|
227
|
+
* error(message: string) {
|
|
228
|
+
* // Implementación personalizada
|
|
229
|
+
* super.error(message)
|
|
230
|
+
* }
|
|
231
|
+
* }
|
|
198
232
|
*
|
|
199
233
|
* const cslService = createCSLService({
|
|
200
|
-
* logger:
|
|
201
|
-
* policyRepository:
|
|
234
|
+
* logger: new CustomLogger(),
|
|
235
|
+
* policyRepository: new InMemoryPolicyRepository(),
|
|
202
236
|
* enablePolicyValidation: true
|
|
203
237
|
* })
|
|
204
238
|
*
|
|
205
|
-
* // Procesar contenido
|
|
239
|
+
* // Procesar contenido del DOM
|
|
206
240
|
* const result = await cslService.segment(document.body)
|
|
241
|
+
* console.log(`Segmentos procesados: ${result.metadata.total_segments}`)
|
|
207
242
|
* ```
|
|
208
243
|
*/
|
|
209
244
|
export function createCSLService(options?: CreateCSLServiceOptions): CSLService {
|