Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 4d909ea

Browse files
authored
Jstep/sdk predefined queries/create webhooks (#19)
* CreateWebhooks mutation * CreateWebhooks mutation and example * Test webhook * linting * DeleteWebhook with example
1 parent 6868d15 commit 4d909ea

File tree

10 files changed

+6355
-1585
lines changed

10 files changed

+6355
-1585
lines changed

examples/simple/index.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { Defined } from "@definedfi/sdk";
22

3-
import { Network } from "../../src/resources/graphql";
3+
// import { AlertRecurrence } from "../../dist/sdk/generated/graphql";
4+
import { AlertRecurrence, Network } from "../../src/resources/graphql";
45

56
const sdk = new Defined(process.env.DEFINED_API_KEY || "");
67

78
sdk
89
.send<{ getNetworks: Network[] }>(
910
`query GetNetworks { getNetworks { id name } }`,
10-
{}
11+
{},
1112
)
1213
.then((res) => {
1314
console.log("Networks: ", res.getNetworks);
@@ -74,6 +75,50 @@ sdk.queries
7475

7576
sdk.queries
7677
.getWebhooks({
77-
webhookId: "45b7de27-8063-40b9-85c1-c716c37379ba",
78+
webhookId: "802cda45-5cc4-4bec-b456-5bec5a08cec4",
7879
})
7980
.then(console.log);
81+
82+
// Mutations
83+
84+
// Example showing how to create a webhook and how to delete it.
85+
sdk.mutations
86+
.createWebhooks({
87+
input: {
88+
priceWebhooksInput: {
89+
webhooks: [
90+
{
91+
name: "SDK test webhook",
92+
callbackUrl:
93+
"https://webhook.site/#!/697da597-6f40-4bec-b59a-3b6dc2e680b8",
94+
securityToken: "1234567890",
95+
alertRecurrence: AlertRecurrence.Once,
96+
conditions: {
97+
priceUsd: {
98+
gt: "100",
99+
},
100+
networkId: {
101+
eq: 1,
102+
},
103+
tokenAddress: {
104+
eq: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
105+
},
106+
},
107+
},
108+
],
109+
},
110+
},
111+
})
112+
.then((data) => {
113+
console.log(data);
114+
const webhookId = data?.createWebhooks?.priceWebhooks?.[0]?.id;
115+
if (webhookId) {
116+
sdk.mutations
117+
.deleteWebhooks({
118+
input: {
119+
webhookIds: [webhookId],
120+
},
121+
})
122+
.then(console.log);
123+
}
124+
});

0 commit comments

Comments
 (0)