Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook update hotfix (#289) #292

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

## [0.8.1] - 2024-10-09
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@howard-at-cb also update package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @jazz-cb , package.json change is covered here #293


### Fixed
- Fixed a bug that overwrites existing webhook notification URI when only updating a webhook's addresses

## [0.8.0] - 2024-10-04

### Added
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "ISC",
"description": "Coinbase Platform SDK",
"repository": "https://github.com/coinbase/coinbase-sdk-nodejs",
"version": "0.8.0",
"version": "0.8.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions quickstart-template/webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ curl -X POST -H "Content-Type:application/json" -d '{"app": "webhook"}' http://l
## Public Webhook App

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

```bash
ssh -p 443 -R0:localhost:3000 -L4300:localhost:4300 qr@a.pinggy.io
```

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

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

Expand Down
7 changes: 5 additions & 2 deletions src/coinbase/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,13 @@ export class Webhook {
notificationUri,
eventTypeFilter,
}: UpdateWebhookOptions): Promise<Webhook> {
const finalNotificationUri = notificationUri ?? this.getNotificationURI();
const finalEventTypeFilter = eventTypeFilter ?? this.getEventTypeFilter();

const result = await Coinbase.apiClients.webhook!.updateWebhook(this.getId()!, {
notification_uri: notificationUri,
notification_uri: finalNotificationUri,
event_filters: this.getEventFilters()!,
event_type_filter: eventTypeFilter,
event_type_filter: finalEventTypeFilter,
});

this.model = result.data;
Expand Down
17 changes: 17 additions & 0 deletions src/tests/webhook_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,27 @@ describe("Webhook", () => {
expect(Coinbase.apiClients.webhook!.updateWebhook).toHaveBeenCalledWith("test-id", {
notification_uri: "https://new-url.com/callback",
event_filters: [{ contract_address: "0x...", from_address: "0x...", to_address: "0x..." }],
event_type_filter: {
addresses: ["0xa55C5950F7A3C42Fa5799B2Cac0e455774a07382"],
wallet_id: "w1",
},
});

expect(webhook.getNotificationURI()).toBe("https://new-url.com/callback");
});
it("should update the webhook address list only", async () => {
const webhook = Webhook.init(mockModel);
await webhook.update({ eventTypeFilter: { addresses: ["0x1..", "0x2.."] } });

expect(Coinbase.apiClients.webhook!.updateWebhook).toHaveBeenCalledWith("test-id", {
notification_uri: "https://example.com/callback",
event_filters: [{ contract_address: "0x...", from_address: "0x...", to_address: "0x..." }],
event_type_filter: { addresses: ["0x1..", "0x2.."] },
});

expect(webhook.getNotificationURI()).toBe("https://example.com/callback");
expect(webhook.getEventTypeFilter()?.addresses).toEqual(["0x1..", "0x2.."]);
});
it("should update both the webhook notification URI and the list of addresses monitoring", async () => {
const mockModel: WebhookModel = {
id: "test-id",
Expand Down
Loading