Skip to content

Commit fc143cb

Browse files
add webhook naming via sdk (alchemyplatform#492)
* add webhook naming via sdk * addressing comments
1 parent 6aba6ba commit fc143cb

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/api/notify-namespace.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ export class NotifyNamespace {
519519
webhook_type: type,
520520
webhook_url: url,
521521
...(appId && { app_id: appId }),
522+
...(params.name && { name: params.name }),
522523

523524
// Only include the filters/addresses in the final response if they're defined
524525
...nftFilterObj,
@@ -667,7 +668,9 @@ function parseRawWebhook(rawWebhook: RawWebhook): Webhook {
667668
signingKey: rawWebhook.signing_key,
668669
version: rawWebhook.version as WebhookVersion,
669670
// Only include the appId in the final response if it's defined
670-
...(rawWebhook.app_id !== undefined && { appId: rawWebhook.app_id })
671+
...(rawWebhook.app_id !== undefined && { appId: rawWebhook.app_id }),
672+
// Only include the name in the final response if it's defined
673+
...(rawWebhook.name !== undefined && { name: rawWebhook.name })
671674
};
672675
}
673676

src/internal/raw-interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ export interface RawWebhook {
255255
signing_key: string;
256256
version: string;
257257
app_id?: string;
258+
name?: string;
258259
}
259260

260261
export interface RawWebhookPagination {

src/types/types.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { BigNumberish } from '@ethersproject/bignumber';
77
import { ConnectionInfo } from '@ethersproject/web';
88

9+
import { NotifyNamespace } from '../api/notify-namespace';
910
import {
1011
ERC1155Metadata,
1112
NftRefreshState,
@@ -1129,6 +1130,8 @@ export interface Webhook {
11291130
* {@link MinedTransactionWebhook} and {@link DroppedTransactionWebhook}
11301131
*/
11311132
appId?: string;
1133+
/** The name of the webhook. */
1134+
name?: string;
11321135
}
11331136

11341137
/** The version of the webhook. All newly created webhooks default to V2. */
@@ -1235,6 +1238,14 @@ export interface CustomGraphqlWebhookConfig {
12351238
graphqlQuery: string;
12361239
}
12371240

1241+
/**
1242+
* Base interface for all webhook parameters that includes common fields.
1243+
*/
1244+
export interface BaseWebhookParams {
1245+
/** Optional name for the webhook. */
1246+
name?: string;
1247+
}
1248+
12381249
/**
12391250
* Params to pass in when calling {@link NotifyNamespace.createWebhook} in order
12401251
* to create a {@link MinedTransactionWebhook} or {@link DroppedTransactionWebhook}.
@@ -1246,7 +1257,7 @@ export interface CustomGraphqlWebhookConfig {
12461257
* This is a temporary workaround for now. We're planning on detecting the app
12471258
* id from the provided api key directly. Stay tuned!
12481259
*/
1249-
export interface TransactionWebhookParams {
1260+
export interface TransactionWebhookParams extends BaseWebhookParams {
12501261
/** The app id of the project to create the webhook on. */
12511262
appId: string;
12521263
}
@@ -1255,7 +1266,7 @@ export interface TransactionWebhookParams {
12551266
* Params to pass in when calling {@link NotifyNamespace.createWebhook} in order
12561267
* to create a {@link NftActivityWebhook} or {@link NftMetadataUpdateWebhook}.
12571268
*/
1258-
export interface NftWebhookParams {
1269+
export interface NftWebhookParams extends BaseWebhookParams {
12591270
/** Array of NFT filters the webhook should track. */
12601271
filters: NftFilter[];
12611272
/**
@@ -1269,7 +1280,7 @@ export interface NftWebhookParams {
12691280
* Params to pass in when calling {@link NotifyNamespace.createWebhook} in order
12701281
* to create a {@link CustomGraphqlWebhook}
12711282
*/
1272-
export interface CustomGraphqlWebhookParams {
1283+
export interface CustomGraphqlWebhookParams extends BaseWebhookParams {
12731284
/** GraphQL query */
12741285
graphqlQuery: string;
12751286
/**
@@ -1302,7 +1313,7 @@ export interface CustomGraphqlWebhookParams {
13021313
* Params to pass in when calling {@link NotifyNamespace.createWebhook} in order
13031314
* to create a {@link AddressActivityWebhook}.
13041315
*/
1305-
export interface AddressWebhookParams {
1316+
export interface AddressWebhookParams extends BaseWebhookParams {
13061317
/** Array of addresses the webhook should activity for. */
13071318
addresses: string[];
13081319
/**

0 commit comments

Comments
 (0)