-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathingest-manifest.domain.ts
More file actions
42 lines (38 loc) · 1.4 KB
/
ingest-manifest.domain.ts
File metadata and controls
42 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { omit } from '../../utils/utils';
import { DocumentApp } from '../services/document/document.app';
import {
Connector,
INTEGRATION_CONNECTOR_METADATA_KEYS,
OPENCTI_INTEGRATION_DOCUMENT_TYPE,
} from '../services/document/opencti/integrations/integrations.model';
import { telemetryApp } from '../telemetry/telemetry.app';
import { buildCreateEvent } from '../telemetry/telemetry.helper';
import { base64ToUpload } from './ingest-manifest.helper';
import { ManifestInformation } from './ingest-manifest.model';
export const upsertConnectors = async (manifestInfo: ManifestInformation[]) => {
const results: Array<Connector> = [];
for (const connector of manifestInfo) {
try {
const uploadLogo = base64ToUpload(
connector.logo,
`${connector.name}-logo.png`
);
const doc = await DocumentApp.upsertDocumentWithExternalImage<Connector>(
OPENCTI_INTEGRATION_DOCUMENT_TYPE,
{ ...omit(connector, ['logo']) } as Connector,
uploadLogo,
INTEGRATION_CONNECTOR_METADATA_KEYS
);
const newDocIsCreated = !doc.updated_at;
if (newDocIsCreated) {
const createEvent = await buildCreateEvent(doc);
await telemetryApp.sendTelemetryEvent(createEvent);
}
results.push(doc);
} catch (error) {
console.error(`Failed to upsert connector ${connector.name}:`, error);
throw error;
}
}
return results;
};