Skip to content
Last updated

PERS SDK - v2.3.26 / Exports / ApiKeyManager

Class: 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');

Table of contents

Constructors

Methods

Constructors

constructor

• new ApiKeyManager(apiClient): ApiKeyManager

Parameters

NameType
apiClientPersApiClient

Returns

ApiKeyManager

Defined in

managers/api-key-manager.ts:41

Methods

listApiKeys

▸ listApiKeys(type?, includeRevoked?, options?): Promise<PaginatedResponseDTO<ApiKeyDTO>>

Get all API keys for the current tenant with pagination

Admin Only: Requires tenant admin authentication

Parameters

NameTypeDefault valueDescription
type?IntegrationApiKeyTypeundefinedOptional filter by integration API key type (database-stored tokens)
includeRevokedbooleanfalseInclude revoked API keys in results (default: false)
options?PaginationOptionsundefined-

Returns

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);

Defined in

managers/api-key-manager.ts:70


createApiKey

▸ 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

Parameters

NameTypeDescription
reqApiKeyRequestDTOAPI key creation request containing type, name, and optional configuration

Returns

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);

Defined in

managers/api-key-manager.ts:95


revokeApiKey

▸ 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.

Parameters

NameTypeDescription
apiKeyIdstringUnique identifier of the API key to revoke

Returns

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);
}

Defined in

managers/api-key-manager.ts:133