fix(worker): Refactor worker script update and creation to use intermediate parameter objects
This commit is contained in:
parent
6cd5aa2913
commit
d8ca3dc115
@ -1,5 +1,11 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@apiclient.xyz/cloudflare',
|
name: '@apiclient.xyz/cloudflare',
|
||||||
version: '6.3.1',
|
version: '6.3.2',
|
||||||
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.'
|
||||||
}
|
}
|
||||||
|
@ -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') {
|
||||||
|
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user