fix(core): Improve nested DNS record management and worker script multipart handling
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/cloudflare',
|
||||
version: '6.3.0',
|
||||
version: '6.3.1',
|
||||
description: 'A TypeScript client for managing Cloudflare accounts, zones, DNS records, and workers with ease.'
|
||||
}
|
||||
|
@ -229,15 +229,17 @@ export class CloudflareAccount {
|
||||
const domain = new plugins.smartstring.Domain(domainNameArg);
|
||||
const zoneId = await this.convenience.getZoneId(domain.zoneName);
|
||||
|
||||
const records = await this.convenience.listRecords(domainNameArg);
|
||||
// List all records in the zone for this domain
|
||||
const records = await this.convenience.listRecords(domain.zoneName);
|
||||
|
||||
if (!Array.isArray(records)) {
|
||||
logger.log('warn', `Expected records array for ${domainNameArg} but got ${typeof records}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// Only delete records matching the specified name and type
|
||||
const recordsToDelete = records.filter((recordArg) => {
|
||||
return recordArg.type === typeArg;
|
||||
return recordArg.type === typeArg && recordArg.name === domainNameArg;
|
||||
});
|
||||
|
||||
logger.log('info', `Found ${recordsToDelete.length} ${typeArg} records to delete for ${domainNameArg}`);
|
||||
|
@ -167,11 +167,15 @@ export class CloudflareWorker {
|
||||
try {
|
||||
logger.log('info', `Updating script for worker ${this.id}`);
|
||||
|
||||
// Use the official client to update the script
|
||||
// Use the official client to update the script (upload new content)
|
||||
const updatedWorker = await this.workerManager.cfAccount.apiAccount.workers.scripts.content.update(this.id, {
|
||||
account_id: this.workerManager.cfAccount.preselectedAccountId,
|
||||
"CF-WORKER-BODY-PART": scriptContent,
|
||||
metadata: {}
|
||||
// name the multipart part for the updated script code
|
||||
metadata: { body_part: 'script' },
|
||||
/* header to indicate which part contains the script */
|
||||
'CF-WORKER-BODY-PART': 'script',
|
||||
// include the new script as a form part named 'script'
|
||||
script: scriptContent,
|
||||
});
|
||||
|
||||
// Update this instance with new data
|
||||
|
@ -22,11 +22,15 @@ export class WorkerManager {
|
||||
}
|
||||
|
||||
try {
|
||||
// Use the official client to create/update the worker
|
||||
// Use the official client to create/update the worker (upload script content)
|
||||
await this.cfAccount.apiAccount.workers.scripts.content.update(workerName, {
|
||||
account_id: this.cfAccount.preselectedAccountId,
|
||||
"CF-WORKER-BODY-PART": workerScript,
|
||||
metadata: {}
|
||||
// name the multipart part for the script code
|
||||
metadata: { body_part: 'script' },
|
||||
/* header to indicate which part contains the script */
|
||||
'CF-WORKER-BODY-PART': 'script',
|
||||
// include the actual script as a form part named 'script'
|
||||
script: workerScript,
|
||||
});
|
||||
|
||||
// Create a new worker instance
|
||||
|
Reference in New Issue
Block a user