@relazio/plugin-sdk 0.1.0 → 0.2.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.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * SDK ufficiale per creare plugin esterni per Relazio
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ExpressServer = exports.MemoryStorage = exports.InstallationRegistry = exports.InMemorySecretProvider = exports.JobQueue = exports.JobProgressTracker = exports.verifyWebhookSignature = exports.HMACUtils = exports.ManifestGenerator = exports.OSINTPlugin = exports.RelazioPlugin = void 0;
7
+ exports.multiEntityResult = exports.singleEntityResult = exports.errorResult = exports.emptyResult = exports.ResultBuilder = exports.isValidEdgeId = exports.isValidEntityId = exports.normalizeValue = exports.generateRandomId = exports.generateEdgeId = exports.generateEntityId = exports.validateTransformResult = exports.validateEdges = exports.validateEntities = exports.EdgeBuilder = exports.EntityBuilder = exports.createEdge = exports.createEntity = exports.ExpressServer = exports.MemoryStorage = exports.InstallationRegistry = exports.InMemorySecretProvider = exports.JobQueue = exports.JobProgressTracker = exports.verifyWebhookSignature = exports.HMACUtils = exports.ManifestGenerator = exports.OSINTPlugin = exports.RelazioPlugin = void 0;
8
8
  // Core exports
9
9
  var plugin_1 = require("./core/plugin");
10
10
  Object.defineProperty(exports, "RelazioPlugin", { enumerable: true, get: function () { return plugin_1.RelazioPlugin; } });
@@ -27,3 +27,29 @@ Object.defineProperty(exports, "MemoryStorage", { enumerable: true, get: functio
27
27
  // Server
28
28
  var express_1 = require("./server/express");
29
29
  Object.defineProperty(exports, "ExpressServer", { enumerable: true, get: function () { return express_1.ExpressServer; } });
30
+ // Utils - Entity & Edge Builders
31
+ var builders_1 = require("./utils/builders");
32
+ // Core builders (scalabili e dinamici)
33
+ Object.defineProperty(exports, "createEntity", { enumerable: true, get: function () { return builders_1.createEntity; } });
34
+ Object.defineProperty(exports, "createEdge", { enumerable: true, get: function () { return builders_1.createEdge; } });
35
+ Object.defineProperty(exports, "EntityBuilder", { enumerable: true, get: function () { return builders_1.EntityBuilder; } });
36
+ Object.defineProperty(exports, "EdgeBuilder", { enumerable: true, get: function () { return builders_1.EdgeBuilder; } });
37
+ // Validazione
38
+ Object.defineProperty(exports, "validateEntities", { enumerable: true, get: function () { return builders_1.validateEntities; } });
39
+ Object.defineProperty(exports, "validateEdges", { enumerable: true, get: function () { return builders_1.validateEdges; } });
40
+ Object.defineProperty(exports, "validateTransformResult", { enumerable: true, get: function () { return builders_1.validateTransformResult; } });
41
+ // Utils - ID Generation
42
+ var id_generator_1 = require("./utils/id-generator");
43
+ Object.defineProperty(exports, "generateEntityId", { enumerable: true, get: function () { return id_generator_1.generateEntityId; } });
44
+ Object.defineProperty(exports, "generateEdgeId", { enumerable: true, get: function () { return id_generator_1.generateEdgeId; } });
45
+ Object.defineProperty(exports, "generateRandomId", { enumerable: true, get: function () { return id_generator_1.generateRandomId; } });
46
+ Object.defineProperty(exports, "normalizeValue", { enumerable: true, get: function () { return id_generator_1.normalizeValue; } });
47
+ Object.defineProperty(exports, "isValidEntityId", { enumerable: true, get: function () { return id_generator_1.isValidEntityId; } });
48
+ Object.defineProperty(exports, "isValidEdgeId", { enumerable: true, get: function () { return id_generator_1.isValidEdgeId; } });
49
+ // Utils - Result Builder
50
+ var result_builder_1 = require("./utils/result-builder");
51
+ Object.defineProperty(exports, "ResultBuilder", { enumerable: true, get: function () { return result_builder_1.ResultBuilder; } });
52
+ Object.defineProperty(exports, "emptyResult", { enumerable: true, get: function () { return result_builder_1.emptyResult; } });
53
+ Object.defineProperty(exports, "errorResult", { enumerable: true, get: function () { return result_builder_1.errorResult; } });
54
+ Object.defineProperty(exports, "singleEntityResult", { enumerable: true, get: function () { return result_builder_1.singleEntityResult; } });
55
+ Object.defineProperty(exports, "multiEntityResult", { enumerable: true, get: function () { return result_builder_1.multiEntityResult; } });
@@ -0,0 +1,147 @@
1
+ import type { OSINTEntity, OSINTEdge, EntityType } from '../core/types';
2
+ /**
3
+ * Crea un'entità OSINT nel formato corretto
4
+ * Genera automaticamente un ID deterministico se non specificato
5
+ *
6
+ * @param type - Tipo di entità
7
+ * @param value - Valore dell'entità (obbligatorio)
8
+ * @param options - Opzioni aggiuntive (label, metadata, id)
9
+ * @returns Entità nel formato corretto
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * // Esempio semplice
14
+ * createEntity('ip', '8.8.8.8')
15
+ *
16
+ * // Con label e metadata
17
+ * createEntity('ip', '8.8.8.8', {
18
+ * label: 'Google DNS',
19
+ * metadata: { country: 'US', isp: 'Google LLC' }
20
+ * })
21
+ *
22
+ * // Con ID personalizzato
23
+ * createEntity('location', 'Mountain View, CA', {
24
+ * id: 'custom-location-id',
25
+ * metadata: { latitude: 37.386, longitude: -122.084 }
26
+ * })
27
+ * ```
28
+ */
29
+ export declare function createEntity(type: EntityType, value: string, options?: {
30
+ id?: string;
31
+ label?: string;
32
+ metadata?: Record<string, any>;
33
+ }): OSINTEntity;
34
+ /**
35
+ * Crea un edge tra due entità nel formato corretto
36
+ * Genera automaticamente un ID deterministico se non specificato
37
+ *
38
+ * @param sourceId - ID dell'entità sorgente
39
+ * @param targetId - ID dell'entità target
40
+ * @param label - Label visibile dell'edge (obbligatorio)
41
+ * @param options - Opzioni aggiuntive (id, relationship, metadata)
42
+ * @returns Edge nel formato corretto
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // Esempio semplice
47
+ * createEdge('ip-c909e98d', 'location-a3f42bc1', 'located in')
48
+ *
49
+ * // Con relationship e metadata
50
+ * createEdge('ip-c909e98d', 'org-5b3c1a2d', 'assigned by', {
51
+ * relationship: 'isp_assignment',
52
+ * metadata: { confidence: 0.98 }
53
+ * })
54
+ *
55
+ * // Con ID personalizzato
56
+ * createEdge('node-1', 'node-2', 'related to', {
57
+ * id: 'custom-edge-id'
58
+ * })
59
+ * ```
60
+ */
61
+ export declare function createEdge(sourceId: string, targetId: string, label: string, options?: {
62
+ id?: string;
63
+ relationship?: string;
64
+ metadata?: Record<string, any>;
65
+ }): OSINTEdge;
66
+ /**
67
+ * NOTA: Gli helper specifici sono stati rimossi per rendere l'SDK più scalabile.
68
+ * Usa `createEntity(type, value, options)` per creare qualsiasi tipo di entità.
69
+ *
70
+ * Esempio:
71
+ * ```ts
72
+ * createEntity('ip', '8.8.8.8', { metadata: { country: 'US' } })
73
+ * createEntity('domain', 'example.com')
74
+ * createEntity('custom-type', 'value') // Funziona anche con tipi futuri!
75
+ * ```
76
+ */
77
+ /**
78
+ * Builder fluente per creare entità complesse
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * const entity = EntityBuilder
83
+ * .create('ip', '8.8.8.8')
84
+ * .withLabel('Google DNS')
85
+ * .withMetadata({ country: 'US', isp: 'Google LLC' })
86
+ * .build();
87
+ * ```
88
+ */
89
+ export declare class EntityBuilder {
90
+ private entity;
91
+ private constructor();
92
+ static create(type: EntityType, value: string): EntityBuilder;
93
+ withId(id: string): this;
94
+ withLabel(label: string): this;
95
+ withMetadata(metadata: Record<string, any>): this;
96
+ addMetadata(key: string, value: any): this;
97
+ build(): OSINTEntity;
98
+ }
99
+ /**
100
+ * Builder fluente per creare edge complessi
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * const edge = EdgeBuilder
105
+ * .create('ip-abc', 'location-xyz', 'located in')
106
+ * .withRelationship('geolocation')
107
+ * .withMetadata({ confidence: 0.98 })
108
+ * .build();
109
+ * ```
110
+ */
111
+ export declare class EdgeBuilder {
112
+ private edge;
113
+ private constructor();
114
+ static create(sourceId: string, targetId: string, label: string): EdgeBuilder;
115
+ withId(id: string): this;
116
+ withRelationship(relationship: string): this;
117
+ withMetadata(metadata: Record<string, any>): this;
118
+ addMetadata(key: string, value: any): this;
119
+ build(): OSINTEdge;
120
+ }
121
+ /**
122
+ * Helper per validare un array di entità
123
+ * Controlla ID duplicati e campi obbligatori
124
+ */
125
+ export declare function validateEntities(entities: OSINTEntity[]): {
126
+ valid: boolean;
127
+ errors: string[];
128
+ };
129
+ /**
130
+ * Helper per validare un array di edge
131
+ * Controlla ID duplicati, campi obbligatori e riferimenti validi
132
+ */
133
+ export declare function validateEdges(edges: OSINTEdge[], entities: OSINTEntity[], inputEntityId?: string): {
134
+ valid: boolean;
135
+ errors: string[];
136
+ };
137
+ /**
138
+ * Helper per validare una risposta completa di transform
139
+ */
140
+ export declare function validateTransformResult(result: {
141
+ entities: OSINTEntity[];
142
+ edges: OSINTEdge[];
143
+ }, inputEntityId?: string): {
144
+ valid: boolean;
145
+ errors: string[];
146
+ };
147
+ //# sourceMappingURL=builders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../../src/utils/builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGxE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IACR,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,GACA,WAAW,CAYb;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE;IACR,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC,GACA,SAAS,CAmBX;AAED;;;;;;;;;;GAUG;AAEH;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAuB;IAErC,OAAO;IAOP,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,aAAa;IAI7D,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAK9B,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKjD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAQ1C,KAAK,IAAI,WAAW;CAkBrB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,IAAI,CAAqB;IAEjC,OAAO;IAQP,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW;IAI7E,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAKxB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI;IAK5C,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI;IAKjD,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAQ1C,KAAK,IAAI,SAAS;CA0BnB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA6B9F;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,SAAS,EAAE,EAClB,QAAQ,EAAE,WAAW,EAAE,EACvB,aAAa,CAAC,EAAE,MAAM,GACrB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CA8CtC;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE;IAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IAAC,KAAK,EAAE,SAAS,EAAE,CAAA;CAAE,EACvD,aAAa,CAAC,EAAE,MAAM,GACrB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAQtC"}
@@ -0,0 +1,316 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EdgeBuilder = exports.EntityBuilder = void 0;
4
+ exports.createEntity = createEntity;
5
+ exports.createEdge = createEdge;
6
+ exports.validateEntities = validateEntities;
7
+ exports.validateEdges = validateEdges;
8
+ exports.validateTransformResult = validateTransformResult;
9
+ const id_generator_1 = require("./id-generator");
10
+ /**
11
+ * Crea un'entità OSINT nel formato corretto
12
+ * Genera automaticamente un ID deterministico se non specificato
13
+ *
14
+ * @param type - Tipo di entità
15
+ * @param value - Valore dell'entità (obbligatorio)
16
+ * @param options - Opzioni aggiuntive (label, metadata, id)
17
+ * @returns Entità nel formato corretto
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // Esempio semplice
22
+ * createEntity('ip', '8.8.8.8')
23
+ *
24
+ * // Con label e metadata
25
+ * createEntity('ip', '8.8.8.8', {
26
+ * label: 'Google DNS',
27
+ * metadata: { country: 'US', isp: 'Google LLC' }
28
+ * })
29
+ *
30
+ * // Con ID personalizzato
31
+ * createEntity('location', 'Mountain View, CA', {
32
+ * id: 'custom-location-id',
33
+ * metadata: { latitude: 37.386, longitude: -122.084 }
34
+ * })
35
+ * ```
36
+ */
37
+ function createEntity(type, value, options) {
38
+ if (!value || value.trim() === '') {
39
+ throw new Error('Entity value cannot be empty');
40
+ }
41
+ return {
42
+ id: options?.id || (0, id_generator_1.generateEntityId)(type, value),
43
+ type,
44
+ value: value.trim(),
45
+ ...(options?.label && { label: options.label }),
46
+ ...(options?.metadata && { metadata: options.metadata }),
47
+ };
48
+ }
49
+ /**
50
+ * Crea un edge tra due entità nel formato corretto
51
+ * Genera automaticamente un ID deterministico se non specificato
52
+ *
53
+ * @param sourceId - ID dell'entità sorgente
54
+ * @param targetId - ID dell'entità target
55
+ * @param label - Label visibile dell'edge (obbligatorio)
56
+ * @param options - Opzioni aggiuntive (id, relationship, metadata)
57
+ * @returns Edge nel formato corretto
58
+ *
59
+ * @example
60
+ * ```ts
61
+ * // Esempio semplice
62
+ * createEdge('ip-c909e98d', 'location-a3f42bc1', 'located in')
63
+ *
64
+ * // Con relationship e metadata
65
+ * createEdge('ip-c909e98d', 'org-5b3c1a2d', 'assigned by', {
66
+ * relationship: 'isp_assignment',
67
+ * metadata: { confidence: 0.98 }
68
+ * })
69
+ *
70
+ * // Con ID personalizzato
71
+ * createEdge('node-1', 'node-2', 'related to', {
72
+ * id: 'custom-edge-id'
73
+ * })
74
+ * ```
75
+ */
76
+ function createEdge(sourceId, targetId, label, options) {
77
+ if (!sourceId || sourceId.trim() === '') {
78
+ throw new Error('Edge sourceId cannot be empty');
79
+ }
80
+ if (!targetId || targetId.trim() === '') {
81
+ throw new Error('Edge targetId cannot be empty');
82
+ }
83
+ if (!label || label.trim() === '') {
84
+ throw new Error('Edge label cannot be empty');
85
+ }
86
+ return {
87
+ id: options?.id || (0, id_generator_1.generateEdgeId)(sourceId, targetId, label),
88
+ sourceId: sourceId.trim(),
89
+ targetId: targetId.trim(),
90
+ label: label.trim(),
91
+ ...(options?.relationship && { relationship: options.relationship }),
92
+ ...(options?.metadata && { metadata: options.metadata }),
93
+ };
94
+ }
95
+ /**
96
+ * NOTA: Gli helper specifici sono stati rimossi per rendere l'SDK più scalabile.
97
+ * Usa `createEntity(type, value, options)` per creare qualsiasi tipo di entità.
98
+ *
99
+ * Esempio:
100
+ * ```ts
101
+ * createEntity('ip', '8.8.8.8', { metadata: { country: 'US' } })
102
+ * createEntity('domain', 'example.com')
103
+ * createEntity('custom-type', 'value') // Funziona anche con tipi futuri!
104
+ * ```
105
+ */
106
+ /**
107
+ * Builder fluente per creare entità complesse
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const entity = EntityBuilder
112
+ * .create('ip', '8.8.8.8')
113
+ * .withLabel('Google DNS')
114
+ * .withMetadata({ country: 'US', isp: 'Google LLC' })
115
+ * .build();
116
+ * ```
117
+ */
118
+ class EntityBuilder {
119
+ constructor(type, value) {
120
+ this.entity = {
121
+ type,
122
+ value: value.trim(),
123
+ };
124
+ }
125
+ static create(type, value) {
126
+ return new EntityBuilder(type, value);
127
+ }
128
+ withId(id) {
129
+ this.entity.id = id;
130
+ return this;
131
+ }
132
+ withLabel(label) {
133
+ this.entity.label = label;
134
+ return this;
135
+ }
136
+ withMetadata(metadata) {
137
+ this.entity.metadata = { ...this.entity.metadata, ...metadata };
138
+ return this;
139
+ }
140
+ addMetadata(key, value) {
141
+ if (!this.entity.metadata) {
142
+ this.entity.metadata = {};
143
+ }
144
+ this.entity.metadata[key] = value;
145
+ return this;
146
+ }
147
+ build() {
148
+ if (!this.entity.value) {
149
+ throw new Error('Entity value is required');
150
+ }
151
+ if (!this.entity.type) {
152
+ throw new Error('Entity type is required');
153
+ }
154
+ const id = this.entity.id || (0, id_generator_1.generateEntityId)(this.entity.type, this.entity.value);
155
+ return {
156
+ id,
157
+ type: this.entity.type,
158
+ value: this.entity.value,
159
+ ...(this.entity.label && { label: this.entity.label }),
160
+ ...(this.entity.metadata && { metadata: this.entity.metadata }),
161
+ };
162
+ }
163
+ }
164
+ exports.EntityBuilder = EntityBuilder;
165
+ /**
166
+ * Builder fluente per creare edge complessi
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * const edge = EdgeBuilder
171
+ * .create('ip-abc', 'location-xyz', 'located in')
172
+ * .withRelationship('geolocation')
173
+ * .withMetadata({ confidence: 0.98 })
174
+ * .build();
175
+ * ```
176
+ */
177
+ class EdgeBuilder {
178
+ constructor(sourceId, targetId, label) {
179
+ this.edge = {
180
+ sourceId: sourceId.trim(),
181
+ targetId: targetId.trim(),
182
+ label: label.trim(),
183
+ };
184
+ }
185
+ static create(sourceId, targetId, label) {
186
+ return new EdgeBuilder(sourceId, targetId, label);
187
+ }
188
+ withId(id) {
189
+ this.edge.id = id;
190
+ return this;
191
+ }
192
+ withRelationship(relationship) {
193
+ this.edge.relationship = relationship;
194
+ return this;
195
+ }
196
+ withMetadata(metadata) {
197
+ this.edge.metadata = { ...this.edge.metadata, ...metadata };
198
+ return this;
199
+ }
200
+ addMetadata(key, value) {
201
+ if (!this.edge.metadata) {
202
+ this.edge.metadata = {};
203
+ }
204
+ this.edge.metadata[key] = value;
205
+ return this;
206
+ }
207
+ build() {
208
+ if (!this.edge.sourceId) {
209
+ throw new Error('Edge sourceId is required');
210
+ }
211
+ if (!this.edge.targetId) {
212
+ throw new Error('Edge targetId is required');
213
+ }
214
+ if (!this.edge.label) {
215
+ throw new Error('Edge label is required');
216
+ }
217
+ const id = this.edge.id || (0, id_generator_1.generateEdgeId)(this.edge.sourceId, this.edge.targetId, this.edge.label);
218
+ return {
219
+ id,
220
+ sourceId: this.edge.sourceId,
221
+ targetId: this.edge.targetId,
222
+ label: this.edge.label,
223
+ ...(this.edge.relationship && { relationship: this.edge.relationship }),
224
+ ...(this.edge.metadata && { metadata: this.edge.metadata }),
225
+ };
226
+ }
227
+ }
228
+ exports.EdgeBuilder = EdgeBuilder;
229
+ /**
230
+ * Helper per validare un array di entità
231
+ * Controlla ID duplicati e campi obbligatori
232
+ */
233
+ function validateEntities(entities) {
234
+ const errors = [];
235
+ const ids = new Set();
236
+ for (const entity of entities) {
237
+ // Verifica campi obbligatori
238
+ if (!entity.id) {
239
+ errors.push(`Entity missing required field: id`);
240
+ }
241
+ if (!entity.type) {
242
+ errors.push(`Entity missing required field: type`);
243
+ }
244
+ if (!entity.value) {
245
+ errors.push(`Entity missing required field: value`);
246
+ }
247
+ // Verifica ID duplicati
248
+ if (entity.id) {
249
+ if (ids.has(entity.id)) {
250
+ errors.push(`Duplicate entity ID: ${entity.id}`);
251
+ }
252
+ ids.add(entity.id);
253
+ }
254
+ }
255
+ return {
256
+ valid: errors.length === 0,
257
+ errors,
258
+ };
259
+ }
260
+ /**
261
+ * Helper per validare un array di edge
262
+ * Controlla ID duplicati, campi obbligatori e riferimenti validi
263
+ */
264
+ function validateEdges(edges, entities, inputEntityId) {
265
+ const errors = [];
266
+ const edgeIds = new Set();
267
+ const entityIds = new Set(entities.map(e => e.id));
268
+ // Aggiungi l'ID dell'entità di input se fornito
269
+ if (inputEntityId) {
270
+ entityIds.add(inputEntityId);
271
+ }
272
+ for (const edge of edges) {
273
+ // Verifica campi obbligatori
274
+ if (!edge.id) {
275
+ errors.push(`Edge missing required field: id`);
276
+ }
277
+ if (!edge.sourceId) {
278
+ errors.push(`Edge missing required field: sourceId`);
279
+ }
280
+ if (!edge.targetId) {
281
+ errors.push(`Edge missing required field: targetId`);
282
+ }
283
+ if (!edge.label) {
284
+ errors.push(`Edge missing required field: label`);
285
+ }
286
+ // Verifica ID duplicati
287
+ if (edge.id) {
288
+ if (edgeIds.has(edge.id)) {
289
+ errors.push(`Duplicate edge ID: ${edge.id}`);
290
+ }
291
+ edgeIds.add(edge.id);
292
+ }
293
+ // Verifica riferimenti validi
294
+ if (edge.targetId && !entityIds.has(edge.targetId)) {
295
+ errors.push(`Edge references non-existent target entity: ${edge.targetId}`);
296
+ }
297
+ if (edge.sourceId && !entityIds.has(edge.sourceId)) {
298
+ errors.push(`Edge references non-existent source entity: ${edge.sourceId}`);
299
+ }
300
+ }
301
+ return {
302
+ valid: errors.length === 0,
303
+ errors,
304
+ };
305
+ }
306
+ /**
307
+ * Helper per validare una risposta completa di transform
308
+ */
309
+ function validateTransformResult(result, inputEntityId) {
310
+ const entityValidation = validateEntities(result.entities);
311
+ const edgeValidation = validateEdges(result.edges, result.entities, inputEntityId);
312
+ return {
313
+ valid: entityValidation.valid && edgeValidation.valid,
314
+ errors: [...entityValidation.errors, ...edgeValidation.errors],
315
+ };
316
+ }
@@ -0,0 +1,81 @@
1
+ import type { EntityType } from '../core/types';
2
+ /**
3
+ * Genera un ID deterministico per un'entità
4
+ * Formato: {type}-{hash-short}
5
+ *
6
+ * @param type - Tipo di entità
7
+ * @param value - Valore dell'entità
8
+ * @returns ID univoco e deterministico
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * generateEntityId('ip', '8.8.8.8')
13
+ * // => "ip-c909e98d"
14
+ *
15
+ * generateEntityId('location', 'Mountain View, CA')
16
+ * // => "location-a3f42bc1"
17
+ * ```
18
+ */
19
+ export declare function generateEntityId(type: EntityType, value: string): string;
20
+ /**
21
+ * Genera un ID deterministico per un edge
22
+ * Formato: edge-{hash-short}
23
+ *
24
+ * @param sourceId - ID dell'entità sorgente
25
+ * @param targetId - ID dell'entità target
26
+ * @param label - Label dell'edge (opzionale, per maggiore unicità)
27
+ * @returns ID univoco e deterministico
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * generateEdgeId('ip-c909e98d', 'location-a3f42bc1')
32
+ * // => "edge-4f8a2d1c"
33
+ *
34
+ * generateEdgeId('ip-c909e98d', 'org-5b3c1a2d', 'assigned by')
35
+ * // => "edge-7e9b3f4a"
36
+ * ```
37
+ */
38
+ export declare function generateEdgeId(sourceId: string, targetId: string, label?: string): string;
39
+ /**
40
+ * Genera un ID casuale con prefisso
41
+ * Utile per entità temporanee o quando non serve deterministicità
42
+ *
43
+ * @param prefix - Prefisso per l'ID (es: 'note', 'temp')
44
+ * @returns ID univoco random
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * generateRandomId('note')
49
+ * // => "note-1735123456789"
50
+ * ```
51
+ */
52
+ export declare function generateRandomId(prefix: string): string;
53
+ /**
54
+ * Normalizza un valore per la generazione di ID
55
+ * Rimuove spazi extra, converte a lowercase, rimuove caratteri speciali
56
+ *
57
+ * @param value - Valore da normalizzare
58
+ * @returns Valore normalizzato
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * normalizeValue(' Mountain View, CA ')
63
+ * // => "mountain-view-ca"
64
+ * ```
65
+ */
66
+ export declare function normalizeValue(value: string): string;
67
+ /**
68
+ * Valida un ID di entità
69
+ *
70
+ * @param id - ID da validare
71
+ * @returns true se l'ID è valido
72
+ */
73
+ export declare function isValidEntityId(id: string): boolean;
74
+ /**
75
+ * Valida un ID di edge
76
+ *
77
+ * @param id - ID da validare
78
+ * @returns true se l'ID è valido
79
+ */
80
+ export declare function isValidEdgeId(id: string): boolean;
81
+ //# sourceMappingURL=id-generator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.d.ts","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAQxE;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,CAYR;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAQpD;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEnD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEjD"}