@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
65 lines (63 loc) • 2.44 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/schemas/common/stix-timestamp.ts
var stix_timestamp_exports = {};
__export(stix_timestamp_exports, {
stixCreatedTimestampSchema: () => stixCreatedTimestampSchema,
stixModifiedTimestampSchema: () => stixModifiedTimestampSchema,
stixTimestampSchema: () => stixTimestampSchema
});
module.exports = __toCommonJS(stix_timestamp_exports);
var import_zod = require("zod");
var RFC3339_REGEX = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d+)?)Z$/;
var StixTimestampError = {
InvalidFormat: {
code: import_zod.z.ZodIssueCode.custom,
message: "Invalid STIX timestamp format: must be an RFC3339 timestamp with a timezone specification of 'Z'."
}
};
var isValidRFC3339 = (timestamp) => {
if (!RFC3339_REGEX.test(timestamp)) return false;
const date = new Date(timestamp);
return !isNaN(date.getTime());
};
var stixTimestampSchema = import_zod.z.custom(
(val) => {
if (val instanceof Date) {
return isValidRFC3339(val.toISOString());
}
if (typeof val === "string") {
return isValidRFC3339(val);
}
return false;
},
{
message: StixTimestampError.InvalidFormat.message
}
).describe(
"Represents timestamps across the CTI specifications. The format is an RFC3339 timestamp, with a required timezone specification of 'Z'."
);
var stixCreatedTimestampSchema = stixTimestampSchema.brand("StixCreatedTimestamp");
var stixModifiedTimestampSchema = stixTimestampSchema.brand("StixModifiedTimestamp");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
stixCreatedTimestampSchema,
stixModifiedTimestampSchema,
stixTimestampSchema
});