@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
70 lines (67 loc) • 3.98 kB
text/typescript
import { z } from 'zod/v4';
/**
* Type mapping for more readable error messages.
* Maps STIX types to their corresponding readable type names.
*/
declare const stixTypeToTypeName: Record<StixType, string>;
declare const stixTypeSchema: z.ZodEnum<{
"attack-pattern": "attack-pattern";
bundle: "bundle";
campaign: "campaign";
"course-of-action": "course-of-action";
"extension-definition": "extension-definition";
identity: "identity";
"intrusion-set": "intrusion-set";
malware: "malware";
tool: "tool";
"marking-definition": "marking-definition";
"x-mitre-analytic": "x-mitre-analytic";
"x-mitre-data-component": "x-mitre-data-component";
"x-mitre-detection-strategy": "x-mitre-detection-strategy";
"x-mitre-tactic": "x-mitre-tactic";
"x-mitre-asset": "x-mitre-asset";
"x-mitre-data-source": "x-mitre-data-source";
"x-mitre-log-source": "x-mitre-log-source";
"x-mitre-matrix": "x-mitre-matrix";
"x-mitre-collection": "x-mitre-collection";
relationship: "relationship";
file: "file";
artifact: "artifact";
}>;
type StixType = z.infer<typeof stixTypeSchema>;
/**
* Creates a factory function that generates type-specific validators for STIX objects
*
* @param expectedType - The STIX type that should be validated against (e.g., 'x-mitre-tactic')
* @param objectName - The human-readable name of the object type (e.g., 'Tactic')
* @returns A Zod validator that confirms the type matches the expected value
*
* @example
* // Define type validation in your object schema
* const tacticSchema = z.object({
* type: createTypeValidator('x-mitre-tactic', 'Tactic'),
* // other schema properties
* });
*
* // Validate an object with incorrect type
* tacticSchema.validate({ type: 'invalid-type' });
* // Throws: "Invalid 'type' property. Expected 'x-mitre-tactic' for Tactic object, but received 'invalid-type'"
*/
declare function createStixTypeValidator(stixType: StixType): z.ZodLiteral<"attack-pattern" | "bundle" | "campaign" | "course-of-action" | "extension-definition" | "identity" | "intrusion-set" | "malware" | "tool" | "marking-definition" | "x-mitre-analytic" | "x-mitre-data-component" | "x-mitre-detection-strategy" | "x-mitre-tactic" | "x-mitre-asset" | "x-mitre-data-source" | "x-mitre-log-source" | "x-mitre-matrix" | "x-mitre-collection" | "relationship" | "file" | "artifact">;
/**
* Creates a type validator for STIX objects that can have multiple valid types
*
* @param stixTypes - Array of valid STIX types for this object
* @returns A configured Zod validator that accepts any of the specified types
*
* @example
* // For an object that can be either malware or tool
* const malwareToolSchema = attackBaseObjectSchema
* .extend({
* id: createStixIdentifierSchema(['malware', 'tool']),
* type: createMultiStixTypeValidator(['malware', 'tool']),
* // other properties...
* });
*/
declare function createMultiStixTypeValidator(stixTypes: StixType[]): z.ZodUnion<[z.ZodLiteral<"attack-pattern" | "bundle" | "campaign" | "course-of-action" | "extension-definition" | "identity" | "intrusion-set" | "malware" | "tool" | "marking-definition" | "x-mitre-analytic" | "x-mitre-data-component" | "x-mitre-detection-strategy" | "x-mitre-tactic" | "x-mitre-asset" | "x-mitre-data-source" | "x-mitre-log-source" | "x-mitre-matrix" | "x-mitre-collection" | "relationship" | "file" | "artifact">, ...z.ZodLiteral<"attack-pattern" | "bundle" | "campaign" | "course-of-action" | "extension-definition" | "identity" | "intrusion-set" | "malware" | "tool" | "marking-definition" | "x-mitre-analytic" | "x-mitre-data-component" | "x-mitre-detection-strategy" | "x-mitre-tactic" | "x-mitre-asset" | "x-mitre-data-source" | "x-mitre-log-source" | "x-mitre-matrix" | "x-mitre-collection" | "relationship" | "file" | "artifact">[]]>;
export { type StixType, createMultiStixTypeValidator, createStixTypeValidator, stixTypeSchema, stixTypeToTypeName };