@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
97 lines (94 loc) • 3.48 kB
TypeScript
import z from 'zod';
import { StixTypesWithAttackIds } from './attack-id.js';
import 'zod/v4';
import './stix-type.js';
/**
* Schema for validating a single external reference object.
*
* External references link STIX objects to external information sources such as
* reports, websites, or databases. For ATT&CK objects, the first external reference
* typically contains the ATT&CK ID.
*
* @example
* ```typescript
* externalReferenceSchema.parse({
* source_name: 'mitre-attack',
* external_id: 'T1059',
* url: 'https://attack.mitre.org/techniques/T1059'
* }); // Valid
*
* externalReferenceSchema.parse({
* source_name: 'ACME Research',
* description: 'Analysis of APT activity',
* url: 'https://example.com/report'
* }); // Valid - external_id is optional
* ```
*/
declare const externalReferenceSchema: z.ZodObject<{
source_name: z.ZodString;
description: z.ZodOptional<z.ZodString>;
url: z.ZodOptional<z.ZodURL>;
external_id: z.ZodOptional<z.ZodString>;
}, z.z.core.$strip>;
/**
* Type representing a single external reference.
*/
type ExternalReference = z.infer<typeof externalReferenceSchema>;
/**
* Schema for validating a list of external references.
*
* An array of external reference objects that link to non-STIX information sources.
* When present, at least one external reference must be provided.
*
* @example
* ```typescript
* externalReferencesSchema.parse([
* { source_name: 'mitre-attack', external_id: 'T1059' },
* { source_name: 'Research Paper', url: 'https://example.com/paper.pdf' }
* ]); // Valid
*
* externalReferencesSchema.parse([]); // Invalid - at least one required
* ```
*/
declare const externalReferencesSchema: z.ZodArray<z.ZodObject<{
source_name: z.ZodString;
description: z.ZodOptional<z.ZodString>;
url: z.ZodOptional<z.ZodURL>;
external_id: z.ZodOptional<z.ZodString>;
}, z.z.core.$strip>>;
/**
* Type representing a list of external references.
*/
type ExternalReferences = z.infer<typeof externalReferencesSchema>;
/**
* Creates a specialized schema for validating ATT&CK external references.
*
* This factory function generates schemas that validate external reference arrays for
* ATT&CK objects. The schema ensures that:
* 1. At least one external reference is present
* 2. The first external reference contains an `external_id` field
* 3. The `external_id` matches the appropriate ATT&CK ID format for the STIX type
*
* @param stixType - The STIX type to create the schema for
* @returns A Zod schema configured to validate ATT&CK external references for the given type
*
* @example
* ```typescript
* const techniqueRefsSchema = createAttackExternalReferencesSchema('attack-pattern');
* techniqueRefsSchema.parse([
* { source_name: 'mitre-attack', external_id: 'T1059' }
* ]); // Valid
*
* const tacticRefsSchema = createAttackExternalReferencesSchema('x-mitre-tactic');
* tacticRefsSchema.parse([
* { source_name: 'mitre-attack', external_id: 'TA0001' }
* ]); // Valid
* ```
*/
declare const createAttackExternalReferencesSchema: (stixType: StixTypesWithAttackIds) => z.ZodArray<z.ZodObject<{
source_name: z.ZodString;
description: z.ZodOptional<z.ZodString>;
url: z.ZodOptional<z.ZodURL>;
external_id: z.ZodOptional<z.ZodString>;
}, z.z.core.$strip>>;
export { type ExternalReference, type ExternalReferences, createAttackExternalReferencesSchema, externalReferenceSchema, externalReferencesSchema };