Compare commits

..

4 Commits

7 changed files with 1077 additions and 277 deletions

View File

@ -1,5 +1,17 @@
# Changelog # Changelog
## 2025-04-30 - 6.4.0 - feat(CloudflareAccount)
Bump dependency versions and add domain support check in CloudflareAccount
- Upgrade dependencies: @push.rocks/smartrequest, @tsclass/tsclass, @git.zone/tsbuild, @push.rocks/tapbundle, and @types/node
- Implement the isDomainSupported convenience method in CloudflareAccount for validating domain management
## 2025-04-26 - 6.3.2 - fix(worker)
Refactor worker script update and creation to use intermediate parameter objects
- Build updateParams in CloudflareWorker for proper multipart form handling when updating scripts
- Use contentParams in WorkerManager to improve clarity and consistency in worker creation
## 2025-04-26 - 6.3.1 - fix(core) ## 2025-04-26 - 6.3.1 - fix(core)
Improve nested DNS record management and worker script multipart handling Improve nested DNS record management and worker script multipart handling

View File

@ -1,6 +1,6 @@
{ {
"name": "@apiclient.xyz/cloudflare", "name": "@apiclient.xyz/cloudflare",
"version": "6.3.1", "version": "6.4.0",
"private": false, "private": false,
"description": "A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.", "description": "A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",
@ -38,18 +38,18 @@
"@push.rocks/smartdelay": "^3.0.1", "@push.rocks/smartdelay": "^3.0.1",
"@push.rocks/smartlog": "^3.0.2", "@push.rocks/smartlog": "^3.0.2",
"@push.rocks/smartpromise": "^4.2.3", "@push.rocks/smartpromise": "^4.2.3",
"@push.rocks/smartrequest": "^2.0.23", "@push.rocks/smartrequest": "^2.1.0",
"@push.rocks/smartstring": "^4.0.5", "@push.rocks/smartstring": "^4.0.5",
"@tsclass/tsclass": "^5.0.0", "@tsclass/tsclass": "^9.1.0",
"cloudflare": "^4.2.0" "cloudflare": "^4.2.0"
}, },
"devDependencies": { "devDependencies": {
"@git.zone/tsbuild": "^2.2.7", "@git.zone/tsbuild": "^2.3.2",
"@git.zone/tsrun": "^1.3.3", "@git.zone/tsrun": "^1.3.3",
"@git.zone/tstest": "^1.0.96", "@git.zone/tstest": "^1.0.96",
"@push.rocks/qenv": "^6.1.0", "@push.rocks/qenv": "^6.1.0",
"@push.rocks/tapbundle": "^5.6.0", "@push.rocks/tapbundle": "^6.0.0",
"@types/node": "^22.13.10", "@types/node": "^22.15.3",
"openapi-typescript": "^7.6.1" "openapi-typescript": "^7.6.1"
}, },
"files": [ "files": [

1282
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@apiclient.xyz/cloudflare', name: '@apiclient.xyz/cloudflare',
version: '6.3.1', version: '6.4.0',
description: 'A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.' description: 'A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.'
} }

View File

@ -6,7 +6,7 @@ import * as interfaces from './interfaces/index.js';
import { WorkerManager } from './cloudflare.classes.workermanager.js'; import { WorkerManager } from './cloudflare.classes.workermanager.js';
import { ZoneManager } from './cloudflare.classes.zonemanager.js'; import { ZoneManager } from './cloudflare.classes.zonemanager.js';
export class CloudflareAccount { export class CloudflareAccount implements plugins.tsclass.network.IConvenientDnsProvider {
private authToken: string; private authToken: string;
public preselectedAccountId: string; public preselectedAccountId: string;
@ -353,6 +353,24 @@ export class CloudflareAccount {
return []; return [];
} }
}, },
/**
* Determines whether the given domain can be managed by this account
* @param domainName Full domain name to check (e.g., "sub.example.com")
* @returns True if the zone for the domain exists in the account, false otherwise
*/
isDomainSupported: async (domainName: string): Promise<boolean> => {
try {
// Parse out the apex/zone name from the full domain
const domain = new plugins.smartstring.Domain(domainName);
// List zones filtered by the zone name
const zones = await this.convenience.listZones(domain.zoneName);
// If any zone matches, we can manage this domain
return Array.isArray(zones) && zones.length > 0;
} catch (error) {
logger.log('error', `Error checking domain support for ${domainName}: ${error.message}`);
return false;
}
},
/** /**
* purges a zone * purges a zone
*/ */

View File

@ -168,15 +168,14 @@ export class CloudflareWorker {
logger.log('info', `Updating script for worker ${this.id}`); logger.log('info', `Updating script for worker ${this.id}`);
// Use the official client to update the script (upload new content) // Use the official client to update the script (upload new content)
const updatedWorker = await this.workerManager.cfAccount.apiAccount.workers.scripts.content.update(this.id, { // Build params as any to include the script form part without TS errors
const updateParams: any = {
account_id: this.workerManager.cfAccount.preselectedAccountId, account_id: this.workerManager.cfAccount.preselectedAccountId,
// name the multipart part for the updated script code
metadata: { body_part: 'script' }, metadata: { body_part: 'script' },
/* header to indicate which part contains the script */ };
'CF-WORKER-BODY-PART': 'script', updateParams['CF-WORKER-BODY-PART'] = 'script';
// include the new script as a form part named 'script' updateParams['script'] = scriptContent;
script: scriptContent, const updatedWorker = await this.workerManager.cfAccount.apiAccount.workers.scripts.content.update(this.id, updateParams);
});
// Update this instance with new data // Update this instance with new data
if (updatedWorker && typeof updatedWorker === 'object') { if (updatedWorker && typeof updatedWorker === 'object') {

View File

@ -23,15 +23,14 @@ export class WorkerManager {
try { try {
// Use the official client to create/update the worker (upload script content) // Use the official client to create/update the worker (upload script content)
await this.cfAccount.apiAccount.workers.scripts.content.update(workerName, { // Build params as any to include the script form part without TS errors
const contentParams: any = {
account_id: this.cfAccount.preselectedAccountId, account_id: this.cfAccount.preselectedAccountId,
// name the multipart part for the script code
metadata: { body_part: 'script' }, metadata: { body_part: 'script' },
/* header to indicate which part contains the script */ };
'CF-WORKER-BODY-PART': 'script', contentParams['CF-WORKER-BODY-PART'] = 'script';
// include the actual script as a form part named 'script' contentParams['script'] = workerScript;
script: workerScript, await this.cfAccount.apiAccount.workers.scripts.content.update(workerName, contentParams);
});
// Create a new worker instance // Create a new worker instance
const worker = new CloudflareWorker(this); const worker = new CloudflareWorker(this);