PERS SDK - v2.3.26 / Exports / ApiKeyManager
API Key Manager
Provides high-level API key management operations for tenant admins. Handles JWT token creation, API key listing, and revocation with proper error handling.
Admin Access Required: All operations require tenant admin authentication
Example
// Create JWT token for tenant
const jwtToken = await sdk.apiKeys.createJwtToken('Frontend App');
console.log('Store this JWT securely:', jwtToken.key);
// List all tenant API keys
const apiKeys = await sdk.apiKeys.listApiKeys();
apiKeys.forEach(key => {
console.log(`${key.name} (${key.type}) - Active: ${key.isActive}`);
});
// Revoke an API key
await sdk.apiKeys.revokeApiKey('key-id-to-revoke');• new ApiKeyManager(apiClient): ApiKeyManager
| Name | Type |
|---|---|
apiClient | PersApiClient |
managers/api-key-manager.ts:41
▸ listApiKeys(type?, includeRevoked?, options?): Promise<PaginatedResponseDTO<ApiKeyDTO>>
Get all API keys for the current tenant with pagination
Admin Only: Requires tenant admin authentication
| Name | Type | Default value | Description |
|---|---|---|---|
type? | IntegrationApiKeyType | undefined | Optional filter by integration API key type (database-stored tokens) |
includeRevoked | boolean | false | Include revoked API keys in results (default: false) |
options? | PaginationOptions | undefined | - |
Promise<PaginatedResponseDTO<ApiKeyDTO>>
Paginated API keys with metadata (excludes actual key values)
Example
// Get all active API keys
const { data: allKeys } = await sdk.apiKeys.listApiKeys();
// Get only active JWT tokens
const { data: jwtKeys } = await sdk.apiKeys.listApiKeys('TENANT_SYSTEM_JWT');
// Get all JWT tokens including revoked ones
const { data: allJwtKeys } = await sdk.apiKeys.listApiKeys('TENANT_SYSTEM_JWT', true);managers/api-key-manager.ts:70
▸ createApiKey(req): Promise<ApiKeyCreatedDTO>
Create a new API key with specified type
Admin Only: Requires tenant admin authentication Security Warning: The returned API key is only shown once - store it securely
| Name | Type | Description |
|---|---|---|
req | ApiKeyRequestDTO | API key creation request containing type, name, and optional configuration |
Promise<ApiKeyCreatedDTO>
Created API key with the actual key value
Example
// Create a JWT token
const jwtKey = await sdk.apiKeys.createApiKey('TENANT_SYSTEM_JWT', 'Frontend App');
console.log('Store this JWT securely:', jwtKey.privateKey);managers/api-key-manager.ts:95
▸ revokeApiKey(apiKeyId): Promise<ApiKeyVerificationDTO>
Permanently revoke an API key
Admin Only: Requires tenant admin authentication Warning: This operation cannot be undone. The API key will be permanently disabled.
| Name | Type | Description |
|---|---|---|
apiKeyId | string | Unique identifier of the API key to revoke |
Promise<ApiKeyVerificationDTO>
API key verification details with revocation status
Example
try {
// List keys to find the one to revoke
const apiKeys = await sdk.apiKeys.listApiKeys();
const oldKey = apiKeys.find(key => key.name === 'Old Frontend App');
if (oldKey) {
const result = await sdk.apiKeys.revokeApiKey(oldKey.id);
console.log('Revocation successful:', result.success);
if (result.apiKey) {
console.log('Revoked key:', result.apiKey.name);
}
}
} catch (error) {
console.error('Failed to revoke API key:', error.message);
}