UNPKG

atp-sdk

Version:

Official TypeScript SDK for Agent Trust Protocol™ - Build secure, verifiable, and trustworthy applications with decentralized identity, verifiable credentials, and robust access control

90 lines 3.22 kB
import { IdentityClient } from './identity.js'; import { CredentialsClient } from './credentials.js'; import { PermissionsClient } from './permissions.js'; import { AuditClient } from './audit.js'; import { GatewayClient } from './gateway.js'; /** * Main ATP™ SDK Client * * Provides a unified interface to all ATP services with convenient access * to identity, credentials, permissions, audit, and gateway functionality. */ export class ATPClient { constructor(config) { this.config = config; this.identity = new IdentityClient(config); this.credentials = new CredentialsClient(config); this.permissions = new PermissionsClient(config); this.audit = new AuditClient(config); this.gateway = new GatewayClient(config); } /** * Update authentication for all service clients */ setAuthentication(auth) { this.config.auth = { ...this.config.auth, ...auth }; // Update auth for all clients this.identity.updateAuth(auth); this.credentials.updateAuth(auth); this.permissions.updateAuth(auth); this.audit.updateAuth(auth); this.gateway.updateAuth(auth); } /** * Get current configuration */ getConfig() { return { ...this.config }; } /** * Update configuration */ updateConfig(updates) { this.config = { ...this.config, ...updates }; } /** * Check if client is authenticated */ isAuthenticated() { return !!(this.config.auth?.token || (this.config.auth?.did && this.config.auth?.privateKey)); } /** * Test connectivity to all ATP services */ async testConnectivity() { const results = { identity: false, credentials: false, permissions: false, audit: false, gateway: false, overall: false }; try { const healthChecks = await Promise.allSettled([ this.identity.getHealth().then(() => true).catch(() => false), this.credentials.getHealth().then(() => true).catch(() => false), this.permissions.getHealth().then(() => true).catch(() => false), this.audit.getHealth().then(() => true).catch(() => false), this.gateway.getHealth().then(() => true).catch(() => false) ]); results.identity = healthChecks[0].status === 'fulfilled' && healthChecks[0].value; results.credentials = healthChecks[1].status === 'fulfilled' && healthChecks[1].value; results.permissions = healthChecks[2].status === 'fulfilled' && healthChecks[2].value; results.audit = healthChecks[3].status === 'fulfilled' && healthChecks[3].value; results.gateway = healthChecks[4].status === 'fulfilled' && healthChecks[4].value; results.overall = Object.values(results).slice(0, 5).every(status => status); } catch (error) { // All results remain false } return results; } /** * Cleanup resources */ cleanup() { this.gateway.cleanup(); } } //# sourceMappingURL=atp.js.map