@orzattyholding/account-sdk
v1.0.1
Published
TypeScript SDK for OrzattyAccount integration
Downloads
194
Maintainers
Readme
OrzattyAccount TypeScript SDK
A comprehensive TypeScript SDK for integrating with the OrzattyAccount authentication system.
Installation
npm install @orzattyholding/account-sdkQuick Start
import { OrzattyAccountClient, OAuthClient } from '@orzattyholding/account-sdk';
// Initialize the client
const client = new OrzattyAccountClient({
baseUrl: 'https://account.orzatty.com',
clientId: 'your-client-id',
clientSecret: 'your-client-secret', // Optional for public clients
});
// Get current user
const user = await client.getCurrentUser();
console.log(user);OAuth Flow
import { OAuthClient } from '@orzattyholding/account-sdk';
const oauth = new OAuthClient({
baseUrl: 'https://account.orzatty.com',
clientId: 'your-client-id',
clientSecret: 'your-client-secret',
});
// Generate PKCE for security
const pkce = oauth.generatePKCE();
// Get authorization URL
const authUrl = oauth.getAuthorizationUrl({
clientId: 'your-client-id',
redirectUri: 'https://yourapp.com/callback',
scope: ['openid', 'profile', 'email'],
state: 'random-state',
codeChallenge: pkce.codeChallenge,
codeChallengeMethod: pkce.codeChallengeMethod,
});
// Exchange code for tokens
const tokens = await oauth.exchangeCodeForToken({
code: 'authorization-code',
redirectUri: 'https://yourapp.com/callback',
codeVerifier: pkce.codeVerifier,
});
// Set tokens on main client
client.setTokens(tokens);Webhooks
import { WebhookClient } from '@orzattyholding/account-sdk';
const webhooks = new WebhookClient({
baseUrl: 'https://account.orzatty.com',
clientId: 'your-client-id',
apiKey: 'your-api-key',
});
// Register a webhook
const webhook = await webhooks.registerWebhook({
serviceId: 'your-service-id',
url: 'https://yourapp.com/webhooks',
events: ['user.created', 'user.updated'],
secret: 'webhook-secret',
});
// Verify webhook signature
const isValid = WebhookClient.verifySignature(
payload,
signature,
'webhook-secret'
);Service Registry
import { ServiceRegistryClient } from '@orzattyholding/account-sdk';
const registry = new ServiceRegistryClient({
baseUrl: 'https://account.orzatty.com',
clientId: 'your-client-id',
apiKey: 'your-api-key',
});
// Register your service
const service = await registry.registerService({
name: 'my-service',
type: 'web-app',
version: '1.0.0',
baseUrl: 'https://myservice.com',
healthEndpoint: '/health',
description: 'My awesome service',
});
// Get service health
const health = await registry.getServiceHealth(service.id);Error Handling
import {
AuthenticationError,
ValidationError,
RateLimitError
} from '@orzattyholding/account-sdk';
try {
const user = await client.getCurrentUser();
} catch (error) {
if (error instanceof AuthenticationError) {
// Handle authentication error
console.log('Please log in');
} else if (error instanceof ValidationError) {
// Handle validation error
console.log('Invalid data:', error.details);
} else if (error instanceof RateLimitError) {
// Handle rate limit
console.log('Rate limited, retry after:', error.retryAfter);
}
}Configuration
interface SDKConfig {
baseUrl: string;
clientId: string;
clientSecret?: string; // Required for confidential clients
apiKey?: string; // Alternative to client secret
timeout?: number; // Request timeout in milliseconds
retries?: number; // Number of retry attempts
userAgent?: string; // Custom user agent
}API Reference
OrzattyAccountClient
getCurrentUser()- Get current user profileupdateUserProfile(updates)- Update user profilegetUserSessions()- Get user sessionsrevokeSession(sessionId)- Revoke a sessiongetUserOrganizations()- Get user's organizationsgetOrganization(id)- Get organization detailscreateOrganization(data)- Create new organizationupdateOrganization(id, updates)- Update organizationgetPrivacySettings()- Get privacy settingsupdatePrivacySettings(service, settings)- Update privacy settingsenableTwoFactor()- Enable 2FAverifyTwoFactor(token)- Verify 2FA setupdisableTwoFactor(token)- Disable 2FA
OAuthClient
generatePKCE()- Generate PKCE challengegetAuthorizationUrl(request)- Get authorization URLexchangeCodeForToken(request)- Exchange code for tokensrefreshToken(refreshToken)- Refresh access tokenrevokeToken(token)- Revoke tokengetUserInfo(accessToken)- Get user infogetDiscoveryDocument()- Get OIDC discovery documentgetJWKS()- Get JSON Web Key Set
WebhookClient
registerWebhook(request)- Register webhookgetWebhook(id)- Get webhook detailsupdateWebhook(id, updates)- Update webhookdeleteWebhook(id)- Delete webhookpublishEvent(event)- Publish eventgetDeliveryHistory(webhookId)- Get delivery historyretryDelivery(deliveryId)- Retry failed deliverytestWebhook(webhookId)- Test webhook endpoint
ServiceRegistryClient
registerService(request)- Register servicegetService(id)- Get service detailsgetAllServices()- Get all servicesupdateService(id, updates)- Update servicedeleteService(id)- Delete servicegetServiceHealth(id)- Get service healthtriggerHealthCheck(id)- Trigger health check
License
MIT
