Skip to content

Commit 567e803

Browse files
jkoe-cfedmundhung
authored andcommitted
Making explicit that if a body is sent to delete event notification config rules it is sent with an array of ruleIds
1 parent 7c95836 commit 567e803

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

.changeset/blue-bags-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
fix: making explicit to only send a body if there are rule ids specified in the config delete

packages/wrangler/src/__tests__/r2.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ describe("r2", () => {
10391039
async ({ request, params }) => {
10401040
const { accountId } = params;
10411041
expect(accountId).toEqual("some-account-id");
1042+
expect(request.body).toBeNull();
10421043
expect(request.headers.get("authorization")).toEqual(
10431044
"Bearer some-api-token"
10441045
);
@@ -1100,6 +1101,9 @@ describe("r2", () => {
11001101
async ({ request, params }) => {
11011102
const { accountId } = params;
11021103
expect(accountId).toEqual("some-account-id");
1104+
expect(request.body).not.toBeNull();
1105+
const requestBody = await request.text();
1106+
expect(requestBody).toContain(`"ruleIds":["${ruleId}"]`);
11031107
expect(request.headers.get("authorization")).toEqual(
11041108
"Bearer some-api-token"
11051109
);

packages/wrangler/src/r2/helpers.ts

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,24 @@ export async function deleteEventNotificationConfig(
584584
logger.log(
585585
`Disabling event notifications for "${bucketName}" to queue ${queueName}...`
586586
);
587-
588-
const body: DeleteNotificationRequestBody =
589-
ruleId !== undefined
590-
? {
591-
ruleIds: [ruleId],
592-
}
593-
: {};
594-
595-
return await fetchResult<null>(
596-
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
597-
{ method: "DELETE", body: JSON.stringify(body), headers }
598-
);
587+
if (ruleId !== undefined) {
588+
const body: DeleteNotificationRequestBody =
589+
ruleId !== undefined
590+
? {
591+
ruleIds: [ruleId],
592+
}
593+
: {};
594+
595+
return await fetchResult<null>(
596+
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
597+
{ method: "DELETE", body: JSON.stringify(body), headers }
598+
);
599+
} else {
600+
return await fetchResult<null>(
601+
`/accounts/${accountId}/event_notifications/r2/${bucketName}/configuration/queues/${queue.queue_id}`,
602+
{ method: "DELETE", headers }
603+
);
604+
}
599605
}
600606

601607
/**

0 commit comments

Comments
 (0)