@fedmcp/core
Version:
Federal Model Context Protocol - TypeScript implementation
75 lines • 2.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FedMCPClient = void 0;
const artifact_1 = require("./artifact");
class FedMCPClient {
constructor(options) {
this.baseUrl = options.baseUrl.replace(/\/$/, '');
this.workspaceId = options.workspaceId;
this.signer = options.signer;
this.headers = {
'Content-Type': 'application/json',
'X-Workspace-ID': this.workspaceId
};
if (options.apiKey) {
this.headers['Authorization'] = `Bearer ${options.apiKey}`;
}
}
async createArtifact(type, jsonBody, version = 1, sign = true) {
const artifact = new artifact_1.FedMCPArtifact({
type,
version,
workspaceId: this.workspaceId,
jsonBody
});
let jws;
if (sign && this.signer) {
jws = await this.signer.sign(artifact.toJSON());
}
const response = await fetch(`${this.baseUrl}/artifacts`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({
artifact: artifact.toJSON(),
sign: sign && !!this.signer
})
});
if (!response.ok) {
const error = await response.text();
throw new Error(`Failed to create artifact: ${response.statusText} - ${error}`);
}
const result = await response.json();
return {
artifactId: result.artifact_id || artifact.id,
jws: result.jws || jws
};
}
async getArtifact(artifactId) {
const response = await fetch(`${this.baseUrl}/artifacts/${artifactId}`, { headers: this.headers });
if (!response.ok) {
throw new Error(`Failed to get artifact: ${response.statusText}`);
}
return response.json();
}
async verifyArtifact(artifact, jws) {
const response = await fetch(`${this.baseUrl}/artifacts/verify`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify({ artifact, jws })
});
if (!response.ok) {
throw new Error(`Failed to verify artifact: ${response.statusText}`);
}
return response.json();
}
async getAuditTrail(artifactId) {
const response = await fetch(`${this.baseUrl}/audit/artifacts/${artifactId}`, { headers: this.headers });
if (!response.ok) {
throw new Error(`Failed to get audit trail: ${response.statusText}`);
}
const data = await response.json();
return data.events;
}
}
exports.FedMCPClient = FedMCPClient;
//# sourceMappingURL=client.js.map