UNPKG

@mitre-attack/attack-data-model

Version:

A TypeScript API for the MITRE ATT&CK data model

47 lines (44 loc) 2.23 kB
import { z } from 'zod'; /** * 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", "bundle", "campaign", "course-of-action", "identity", "intrusion-set", "malware", "tool", "marking-definition", "x-mitre-data-component", "x-mitre-data-source", "x-mitre-tactic", "x-mitre-asset", "x-mitre-matrix", "x-mitre-collection", "relationship", "file", "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.ZodEffects<z.ZodString, string, string>; /** * 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.ZodEffects<z.ZodString, string, string>; export { type StixType, createMultiStixTypeValidator, createStixTypeValidator, stixTypeSchema, stixTypeToTypeName };