feat(core): Release 6.2.0: Improved async iterator support, enhanced error handling and refined API interfaces for better type safety and consistent behavior.

This commit is contained in:
2025-04-26 12:15:16 +00:00
parent 092a6ba55b
commit 1b34bee35d
8 changed files with 301 additions and 120 deletions

View File

@@ -10,10 +10,11 @@ An elegant, class-based TypeScript client for the Cloudflare API that makes mana
- **Comprehensive coverage** of the Cloudflare API including zones, DNS records, and Workers
- **Class-based design** with intuitive methods for all Cloudflare operations
- **Strong TypeScript typing** for excellent IDE autocompletion and type safety
- **Built on the official Cloudflare client** but with a more developer-friendly interface
- **Fully integrated with the official Cloudflare client** using modern async iterators
- **Convenience methods** for common operations to reduce boilerplate code
- **Promise-based API** for easy async/await usage
- **ESM and browser compatible** for maximum flexibility
- **ESM compatible** for modern JavaScript projects
- **Comprehensive error handling** for robust applications
## Installation
@@ -123,8 +124,14 @@ await cfAccount.convenience.removeRecord('api.example.com', 'A');
await cfAccount.convenience.cleanRecord('example.com', 'TXT');
// Support for ACME DNS challenges (for certificate issuance)
await cfAccount.convenience.acmeSetDnsChallenge('example.com', 'challenge-token-here');
await cfAccount.convenience.acmeRemoveDnsChallenge('example.com');
await cfAccount.convenience.acmeSetDnsChallenge({
hostName: '_acme-challenge.example.com',
challenge: 'token-validation-string'
});
await cfAccount.convenience.acmeRemoveDnsChallenge({
hostName: '_acme-challenge.example.com',
challenge: 'token-validation-string'
});
```
### Workers Management
@@ -161,7 +168,15 @@ await worker.setRoutes([
// Get all routes for a worker
const routes = await worker.getRoutes();
// Update a worker's script
await worker.updateScript(`
addEventListener('fetch', event => {
event.respondWith(new Response('Updated worker content!'))
})`);
// Delete a worker
await worker.delete();
// Or using the worker manager
await cfAccount.workerManager.deleteWorker('my-worker');
```
@@ -174,7 +189,7 @@ import * as cflare from '@apiclient.xyz/cloudflare';
async function manageCloudflare() {
try {
// Initialize with API token
// Initialize with API token from environment variable
const cfAccount = new cflare.CloudflareAccount(process.env.CLOUDFLARE_API_TOKEN);
// Preselect account if needed
@@ -230,35 +245,35 @@ The main entry point for all Cloudflare operations.
class CloudflareAccount {
constructor(apiToken: string);
// Account selection
async listAccounts(): Promise<any[]>;
// Account management
async listAccounts(): Promise<Array<ICloudflareTypes['Account']>>;
async preselectAccountByName(accountName: string): Promise<void>;
// Managers
readonly zoneManager: ZoneManager;
readonly workerManager: WorkerManager;
// Direct API access
async request(endpoint: string, method?: string, data?: any): Promise<any>;
// Official Cloudflare client
readonly apiAccount: cloudflare.Cloudflare;
// Convenience namespace with helper methods
readonly convenience: {
// Zone operations
listZones(): Promise<CloudflareZone[]>;
listZones(domainName?: string): Promise<CloudflareZone[]>;
getZoneId(domainName: string): Promise<string>;
purgeZone(domainName: string): Promise<void>;
// DNS operations
listRecords(domainName: string): Promise<CloudflareRecord[]>;
getRecord(domainName: string, recordType: string): Promise<CloudflareRecord>;
getRecord(domainName: string, recordType: string): Promise<CloudflareRecord | undefined>;
createRecord(domainName: string, recordType: string, content: string, ttl?: number): Promise<any>;
updateRecord(domainName: string, recordType: string, content: string, ttl?: number): Promise<any>;
removeRecord(domainName: string, recordType: string): Promise<any>;
cleanRecord(domainName: string, recordType: string): Promise<void>;
// ACME operations
acmeSetDnsChallenge(domainName: string, token: string): Promise<any>;
acmeRemoveDnsChallenge(domainName: string): Promise<any>;
acmeSetDnsChallenge(dnsChallenge: IDnsChallenge): Promise<any>;
acmeRemoveDnsChallenge(dnsChallenge: IDnsChallenge): Promise<any>;
};
}
```
@@ -316,11 +331,19 @@ Represents a Cloudflare Worker.
class CloudflareWorker {
// Properties
readonly id: string;
readonly name: string;
readonly script: string;
readonly routes: IWorkerRoute[];
// Methods
async getRoutes(): Promise<any[]>;
async setRoutes(routes: Array<{ zoneName: string, pattern: string }>): Promise<any>;
async getRoutes(): Promise<IWorkerRoute[]>;
async setRoutes(routes: Array<IWorkerRouteDefinition>): Promise<void>;
async updateScript(scriptContent: string): Promise<CloudflareWorker>;
async delete(): Promise<boolean>;
}
interface IWorkerRouteDefinition {
zoneName: string;
pattern: string;
}
```
@@ -340,20 +363,35 @@ CloudflareUtils.isValidRecordType('A'); // true
// Format URL for cache purging
CloudflareUtils.formatUrlForPurge('example.com/page'); // 'https://example.com/page'
// Format TTL value
CloudflareUtils.formatTtl(3600); // '1 hour'
```
## What's New in 6.2.0
- **Improved async iterator support**: Fully leverages the official Cloudflare client's async iterator pattern
- **Enhanced error handling**: Better error detection and recovery
- **Simplified API**: More consistent method signatures and return types
- **Better type safety**: Improved TypeScript typing throughout the library
- **Detailed logging**: More informative logging for easier debugging
## Development & Testing
To build the project:
```bash
npm run build
# or
pnpm run build
```
To run tests:
```bash
npm test
# or
pnpm run test
```
## License