Skip to content

Commit a4c9685

Browse files
authored
Webhook update hotfix (#289) (#292)
* Webhook update hotfix (#289) * update webhook bugfix * address comments * Update CHANGELOG.md * Update webhook quickstart guide and package.json (#293) * Update README.md * Revert "Update README.md" This reverts commit 9a7fb38. * Update README.md * 0.8.1
1 parent 107a76a commit a4c9685

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Unreleased
44

5+
## [0.8.1] - 2024-10-09
6+
7+
### Fixed
8+
- Fixed a bug that overwrites existing webhook notification URI when only updating a webhook's addresses
9+
510
## [0.8.0] - 2024-10-04
611

712
### Added

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "ISC",
55
"description": "Coinbase Platform SDK",
66
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
7-
"version": "0.8.0",
7+
"version": "0.8.1",
88
"main": "dist/index.js",
99
"types": "dist/index.d.ts",
1010
"scripts": {

quickstart-template/webhook/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ curl -X POST -H "Content-Type:application/json" -d '{"app": "webhook"}' http://l
2323
## Public Webhook App
2424

2525
To setup a temporary public URL that points to this local webhook app,
26-
you can use [Pinggy](https://pinggy.io/) in another terminal window:
26+
you can use [Pinggy](https://pinggy.io/) or [ngrok](https://ngrok.com/) in another terminal window:
2727

2828
```bash
2929
ssh -p 443 -R0:localhost:3000 -L4300:localhost:4300 [email protected]
3030
```
3131

32-
You can also use [Vercel](https://vercel.com/) or other hosting solutions for your webhook app.
32+
You can also use [Vercel](https://vercel.com/), [webhook.site](https://webhook.site/) or other hosting solutions for your webhook app.
3333

3434
Once the public webhook app is setup, copy the URL provided and test it with:
3535

src/coinbase/webhook.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,13 @@ export class Webhook {
185185
notificationUri,
186186
eventTypeFilter,
187187
}: UpdateWebhookOptions): Promise<Webhook> {
188+
const finalNotificationUri = notificationUri ?? this.getNotificationURI();
189+
const finalEventTypeFilter = eventTypeFilter ?? this.getEventTypeFilter();
190+
188191
const result = await Coinbase.apiClients.webhook!.updateWebhook(this.getId()!, {
189-
notification_uri: notificationUri,
192+
notification_uri: finalNotificationUri,
190193
event_filters: this.getEventFilters()!,
191-
event_type_filter: eventTypeFilter,
194+
event_type_filter: finalEventTypeFilter,
192195
});
193196

194197
this.model = result.data;

src/tests/webhook_test.ts

+17
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,27 @@ describe("Webhook", () => {
206206
expect(Coinbase.apiClients.webhook!.updateWebhook).toHaveBeenCalledWith("test-id", {
207207
notification_uri: "https://new-url.com/callback",
208208
event_filters: [{ contract_address: "0x...", from_address: "0x...", to_address: "0x..." }],
209+
event_type_filter: {
210+
addresses: ["0xa55C5950F7A3C42Fa5799B2Cac0e455774a07382"],
211+
wallet_id: "w1",
212+
},
209213
});
210214

211215
expect(webhook.getNotificationURI()).toBe("https://new-url.com/callback");
212216
});
217+
it("should update the webhook address list only", async () => {
218+
const webhook = Webhook.init(mockModel);
219+
await webhook.update({ eventTypeFilter: { addresses: ["0x1..", "0x2.."] } });
220+
221+
expect(Coinbase.apiClients.webhook!.updateWebhook).toHaveBeenCalledWith("test-id", {
222+
notification_uri: "https://example.com/callback",
223+
event_filters: [{ contract_address: "0x...", from_address: "0x...", to_address: "0x..." }],
224+
event_type_filter: { addresses: ["0x1..", "0x2.."] },
225+
});
226+
227+
expect(webhook.getNotificationURI()).toBe("https://example.com/callback");
228+
expect(webhook.getEventTypeFilter()?.addresses).toEqual(["0x1..", "0x2.."]);
229+
});
213230
it("should update both the webhook notification URI and the list of addresses monitoring", async () => {
214231
const mockModel: WebhookModel = {
215232
id: "test-id",

0 commit comments

Comments
 (0)