@fedmcp/core
Version:
Federal Model Context Protocol - TypeScript implementation
55 lines • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FedMCPArtifact = void 0;
const uuid_1 = require("uuid");
const crypto_1 = require("crypto");
class FedMCPArtifact {
constructor(params) {
this.id = params.id || (0, uuid_1.v4)();
this.type = params.type;
this.version = params.version || 1;
this.workspaceId = params.workspaceId;
this.createdAt = params.createdAt || new Date().toISOString();
this.jsonBody = params.jsonBody;
this.validate();
}
validate() {
if (!this.id)
throw new Error('Artifact ID is required');
if (!this.type)
throw new Error('Artifact type is required');
if (!this.workspaceId)
throw new Error('Workspace ID is required');
if (this.version < 1)
throw new Error('Version must be >= 1');
if (!this.jsonBody || Object.keys(this.jsonBody).length === 0) {
throw new Error('jsonBody cannot be empty');
}
// Check 1 MiB size limit
const size = new TextEncoder().encode(JSON.stringify(this.jsonBody)).length;
if (size > 1024 * 1024) {
throw new Error(`jsonBody size ${size} exceeds 1 MiB limit`);
}
}
canonicalize() {
// RFC 8785 JSON Canonicalization
// For now, using sorted keys
return JSON.stringify(this, Object.keys(this).sort());
}
hash() {
const canonical = this.canonicalize();
return (0, crypto_1.createHash)('sha256').update(canonical).digest('hex');
}
toJSON() {
return {
id: this.id,
type: this.type,
version: this.version,
workspaceId: this.workspaceId,
createdAt: this.createdAt,
jsonBody: this.jsonBody
};
}
}
exports.FedMCPArtifact = FedMCPArtifact;
//# sourceMappingURL=artifact.js.map