@zoralabs/protocol-sdk 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +11 -0
- package/dist/allow-list/allow-list-client.d.ts +26 -0
- package/dist/allow-list/allow-list-client.d.ts.map +1 -0
- package/dist/allow-list/types.d.ts +14 -0
- package/dist/allow-list/types.d.ts.map +1 -0
- package/dist/apis/generated/allow-list-api-types.d.ts +288 -0
- package/dist/apis/generated/allow-list-api-types.d.ts.map +1 -0
- package/dist/apis/http-api-base.d.ts.map +1 -1
- package/dist/apis/subgraph-querier.d.ts +18 -0
- package/dist/apis/subgraph-querier.d.ts.map +1 -0
- package/dist/create/contract-setup.d.ts +1 -0
- package/dist/create/contract-setup.d.ts.map +1 -1
- package/dist/create/minter-defaults.d.ts +5 -0
- package/dist/create/minter-defaults.d.ts.map +1 -0
- package/dist/create/minter-setup.d.ts +14 -0
- package/dist/create/minter-setup.d.ts.map +1 -0
- package/dist/create/token-setup.d.ts +4 -19
- package/dist/create/token-setup.d.ts.map +1 -1
- package/dist/create/types.d.ts +32 -7
- package/dist/create/types.d.ts.map +1 -1
- package/dist/create/update.d.ts +15 -0
- package/dist/create/update.d.ts.map +1 -0
- package/dist/index.cjs +2249 -1936
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2284 -1966
- package/dist/index.js.map +1 -1
- package/dist/ipfs/token-metadata.d.ts +1 -0
- package/dist/ipfs/token-metadata.d.ts.map +1 -1
- package/dist/mint/mint-client.d.ts +2 -6
- package/dist/mint/mint-client.d.ts.map +1 -1
- package/dist/mint/mint-queries.d.ts +3 -1
- package/dist/mint/mint-queries.d.ts.map +1 -1
- package/dist/mint/mint-transactions.d.ts +9 -7
- package/dist/mint/mint-transactions.d.ts.map +1 -1
- package/dist/mint/subgraph-mint-getter.d.ts +5 -4
- package/dist/mint/subgraph-mint-getter.d.ts.map +1 -1
- package/dist/mint/subgraph-queries.d.ts +42 -15
- package/dist/mint/subgraph-queries.d.ts.map +1 -1
- package/dist/mint/types.d.ts +32 -13
- package/dist/mint/types.d.ts.map +1 -1
- package/dist/sparks/sparks-contracts.d.ts +96 -96
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -8
- package/dist/utils.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/allow-list/allow-list-client.ts +105 -0
- package/src/allow-list/types.ts +15 -0
- package/src/apis/generated/allow-list-api-types.ts +288 -0
- package/src/apis/http-api-base.ts +12 -0
- package/src/apis/subgraph-querier.ts +38 -0
- package/src/create/1155-create-helper.test.ts +216 -66
- package/src/create/1155-create-helper.ts +4 -4
- package/src/create/contract-setup.ts +8 -0
- package/src/create/minter-defaults.test.ts +21 -0
- package/src/create/minter-defaults.ts +134 -0
- package/src/create/minter-setup.ts +293 -0
- package/src/create/token-setup.ts +14 -190
- package/src/create/types.ts +56 -9
- package/src/create/update.ts +93 -0
- package/src/index.ts +4 -0
- package/src/ipfs/token-metadata.ts +18 -0
- package/src/mint/mint-client.test.ts +219 -15
- package/src/mint/mint-client.ts +2 -34
- package/src/mint/mint-queries.ts +34 -13
- package/src/mint/mint-transactions.ts +104 -17
- package/src/mint/subgraph-mint-getter.ts +107 -50
- package/src/mint/subgraph-queries.ts +67 -37
- package/src/mint/types.ts +55 -16
- package/src/premint/premint-client.test.ts +6 -5
- package/src/types.ts +1 -1
- package/src/utils.ts +1 -25
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,MAAM,CAAC;AAC1E,OAAO,EAAE,qCAAqC,EAAE,MAAM,SAAS,CAAC;AAEhE,eAAO,MAAM,sBAAsB,SAC3B,qCAAqC,0CACpC,CAAC;AAEV,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,gBAAgB,EAAE,cAAc,GAAG,UAAU,CAAC,CAAC;AAE/E,MAAM,MAAM,YAAY,GAAG;IACzB,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAgB,WAAW,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,YAAY;;;EAKlE;AAED,wBAAgB,sBAAsB,CAAC,EACrC,aAAa,EACb,aAAa,GACd,EAAE;IACD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC;CAClC,GAAG,OAAO,CAKV;AAED,MAAM,MAAM,QAAQ,CAAC,IAAI,IAAI;KAC1B,QAAQ,IAAI,MAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC;CAC3C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zoralabs/protocol-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"repository": "https://github.com/ourzora/zora-protocol",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"tsup": "^7.2.0",
|
|
37
37
|
"typescript": "^5.2.2",
|
|
38
38
|
"vite": "^4.5.0",
|
|
39
|
-
"vitest": "^0.
|
|
39
|
+
"vitest": "^2.0.5",
|
|
40
40
|
"@zoralabs/tsconfig": "^0.0.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import {
|
|
2
|
+
IHttpClient,
|
|
3
|
+
httpClient as defaultHttpClient,
|
|
4
|
+
} from "src/apis/http-api-base";
|
|
5
|
+
import { paths } from "../apis/generated/allow-list-api-types";
|
|
6
|
+
import { Hex } from "viem";
|
|
7
|
+
import { AllowList } from "./types";
|
|
8
|
+
|
|
9
|
+
type AllowListCreateType = paths["/allowlist"]["post"];
|
|
10
|
+
type AllowListCreateParameters =
|
|
11
|
+
AllowListCreateType["requestBody"]["content"]["application/json"];
|
|
12
|
+
type AllowListCreateResponse = {
|
|
13
|
+
existing?: {
|
|
14
|
+
entries: AllowListCreateParameters["entries"];
|
|
15
|
+
root: string;
|
|
16
|
+
added: string;
|
|
17
|
+
};
|
|
18
|
+
success: boolean;
|
|
19
|
+
root: string;
|
|
20
|
+
associated_id?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const ALLOW_LIST_API_BASE = "http://allowlist.zora.co/";
|
|
24
|
+
type AllowListAllowedResponse = {
|
|
25
|
+
maxCanMint: number;
|
|
26
|
+
price: string;
|
|
27
|
+
proof: string[];
|
|
28
|
+
}[];
|
|
29
|
+
|
|
30
|
+
export const createAllowList = async ({
|
|
31
|
+
allowList,
|
|
32
|
+
httpClient = defaultHttpClient,
|
|
33
|
+
baseUrl = ALLOW_LIST_API_BASE,
|
|
34
|
+
}: {
|
|
35
|
+
allowList: AllowList;
|
|
36
|
+
httpClient?: IHttpClient;
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
}) => {
|
|
39
|
+
const { post, retries } = httpClient;
|
|
40
|
+
|
|
41
|
+
const data: AllowListCreateParameters = {
|
|
42
|
+
entries: allowList.entries.map((entry) => ({
|
|
43
|
+
user: entry.user,
|
|
44
|
+
maxCanMint: entry.maxCanMint,
|
|
45
|
+
price: entry.price.toString(),
|
|
46
|
+
})),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
await retries(() =>
|
|
51
|
+
post<AllowListCreateResponse>(`${baseUrl}allowlist`, data),
|
|
52
|
+
)
|
|
53
|
+
).root;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function padHex(value: string): Hex {
|
|
57
|
+
if (value.startsWith("0x")) return value as Hex;
|
|
58
|
+
|
|
59
|
+
return `0x${value}`;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const getAllowListEntry = async ({
|
|
63
|
+
merkleRoot,
|
|
64
|
+
address,
|
|
65
|
+
httpClient = defaultHttpClient,
|
|
66
|
+
baseUrl = ALLOW_LIST_API_BASE,
|
|
67
|
+
}: {
|
|
68
|
+
merkleRoot: string;
|
|
69
|
+
httpClient?: IHttpClient;
|
|
70
|
+
address: string;
|
|
71
|
+
baseUrl?: string;
|
|
72
|
+
}) => {
|
|
73
|
+
const { retries, get } = httpClient;
|
|
74
|
+
|
|
75
|
+
const response = await retries(() =>
|
|
76
|
+
get<AllowListAllowedResponse>(
|
|
77
|
+
`${baseUrl}allowed?user=${address}&root=${merkleRoot}`,
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const entries = response?.map((x) => ({
|
|
82
|
+
maxCanMint: x.maxCanMint,
|
|
83
|
+
price: BigInt(x.price),
|
|
84
|
+
proof: x.proof.map(padHex),
|
|
85
|
+
}));
|
|
86
|
+
|
|
87
|
+
const entry = entries?.sort(
|
|
88
|
+
(a, b) => Number(a.price) - Number(b.price) || b.maxCanMint - a.maxCanMint,
|
|
89
|
+
)[0];
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
accessAllowed: entry && entry?.proof?.length,
|
|
93
|
+
allowListEntry: entry,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export interface IAllowListClient {
|
|
98
|
+
createAllowList: typeof createAllowList;
|
|
99
|
+
getAllowListEntry: typeof getAllowListEntry;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const defaultAllowListClient = (): IAllowListClient => ({
|
|
103
|
+
createAllowList,
|
|
104
|
+
getAllowListEntry,
|
|
105
|
+
});
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was auto-generated by openapi-typescript.
|
|
3
|
+
* Do not make direct changes to the file.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface paths {
|
|
7
|
+
"/_health": {
|
|
8
|
+
parameters: {
|
|
9
|
+
query?: never;
|
|
10
|
+
header?: never;
|
|
11
|
+
path?: never;
|
|
12
|
+
cookie?: never;
|
|
13
|
+
};
|
|
14
|
+
/** Health */
|
|
15
|
+
get: operations["health__health_get"];
|
|
16
|
+
put?: never;
|
|
17
|
+
post?: never;
|
|
18
|
+
delete?: never;
|
|
19
|
+
options?: never;
|
|
20
|
+
head?: never;
|
|
21
|
+
patch?: never;
|
|
22
|
+
trace?: never;
|
|
23
|
+
};
|
|
24
|
+
"/allowlist": {
|
|
25
|
+
parameters: {
|
|
26
|
+
query?: never;
|
|
27
|
+
header?: never;
|
|
28
|
+
path?: never;
|
|
29
|
+
cookie?: never;
|
|
30
|
+
};
|
|
31
|
+
get?: never;
|
|
32
|
+
put?: never;
|
|
33
|
+
/**
|
|
34
|
+
* Add Allowlist
|
|
35
|
+
* @description This route adds a new allowlist
|
|
36
|
+
*/
|
|
37
|
+
post: operations["add_allowlist_allowlist_post"];
|
|
38
|
+
delete?: never;
|
|
39
|
+
options?: never;
|
|
40
|
+
head?: never;
|
|
41
|
+
patch?: never;
|
|
42
|
+
trace?: never;
|
|
43
|
+
};
|
|
44
|
+
"/allowed": {
|
|
45
|
+
parameters: {
|
|
46
|
+
query?: never;
|
|
47
|
+
header?: never;
|
|
48
|
+
path?: never;
|
|
49
|
+
cookie?: never;
|
|
50
|
+
};
|
|
51
|
+
/** Allowed */
|
|
52
|
+
get: operations["allowed_allowed_get"];
|
|
53
|
+
put?: never;
|
|
54
|
+
post?: never;
|
|
55
|
+
delete?: never;
|
|
56
|
+
options?: never;
|
|
57
|
+
head?: never;
|
|
58
|
+
patch?: never;
|
|
59
|
+
trace?: never;
|
|
60
|
+
};
|
|
61
|
+
"/allowlist/{root}": {
|
|
62
|
+
parameters: {
|
|
63
|
+
query?: never;
|
|
64
|
+
header?: never;
|
|
65
|
+
path?: never;
|
|
66
|
+
cookie?: never;
|
|
67
|
+
};
|
|
68
|
+
/** Allowlist */
|
|
69
|
+
get: operations["allowlist_allowlist__root__get"];
|
|
70
|
+
put?: never;
|
|
71
|
+
post?: never;
|
|
72
|
+
delete?: never;
|
|
73
|
+
options?: never;
|
|
74
|
+
head?: never;
|
|
75
|
+
patch?: never;
|
|
76
|
+
trace?: never;
|
|
77
|
+
};
|
|
78
|
+
"/allowlist/{root}/count": {
|
|
79
|
+
parameters: {
|
|
80
|
+
query?: never;
|
|
81
|
+
header?: never;
|
|
82
|
+
path?: never;
|
|
83
|
+
cookie?: never;
|
|
84
|
+
};
|
|
85
|
+
/** Allowlist Count */
|
|
86
|
+
get: operations["allowlist_count_allowlist__root__count_get"];
|
|
87
|
+
put?: never;
|
|
88
|
+
post?: never;
|
|
89
|
+
delete?: never;
|
|
90
|
+
options?: never;
|
|
91
|
+
head?: never;
|
|
92
|
+
patch?: never;
|
|
93
|
+
trace?: never;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
export type webhooks = Record<string, never>;
|
|
97
|
+
export interface components {
|
|
98
|
+
schemas: {
|
|
99
|
+
/**
|
|
100
|
+
* AllowlistEntry
|
|
101
|
+
* @description Currently matches zora-nft-drops model
|
|
102
|
+
*/
|
|
103
|
+
AllowlistEntry: {
|
|
104
|
+
/** User */
|
|
105
|
+
user: string;
|
|
106
|
+
/** Price */
|
|
107
|
+
price: string;
|
|
108
|
+
/** Maxcanmint */
|
|
109
|
+
maxCanMint: number;
|
|
110
|
+
};
|
|
111
|
+
/** AllowlistRequest */
|
|
112
|
+
AllowlistRequest: {
|
|
113
|
+
/** Entries */
|
|
114
|
+
entries: components["schemas"]["AllowlistEntry"][];
|
|
115
|
+
/** Contract */
|
|
116
|
+
contract?: string;
|
|
117
|
+
};
|
|
118
|
+
/** HTTPValidationError */
|
|
119
|
+
HTTPValidationError: {
|
|
120
|
+
/** Detail */
|
|
121
|
+
detail?: components["schemas"]["ValidationError"][];
|
|
122
|
+
};
|
|
123
|
+
/** ValidationError */
|
|
124
|
+
ValidationError: {
|
|
125
|
+
/** Location */
|
|
126
|
+
loc: (string | number)[];
|
|
127
|
+
/** Message */
|
|
128
|
+
msg: string;
|
|
129
|
+
/** Error Type */
|
|
130
|
+
type: string;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
responses: never;
|
|
134
|
+
parameters: never;
|
|
135
|
+
requestBodies: never;
|
|
136
|
+
headers: never;
|
|
137
|
+
pathItems: never;
|
|
138
|
+
}
|
|
139
|
+
export type $defs = Record<string, never>;
|
|
140
|
+
export interface operations {
|
|
141
|
+
health__health_get: {
|
|
142
|
+
parameters: {
|
|
143
|
+
query?: never;
|
|
144
|
+
header?: never;
|
|
145
|
+
path?: never;
|
|
146
|
+
cookie?: never;
|
|
147
|
+
};
|
|
148
|
+
requestBody?: never;
|
|
149
|
+
responses: {
|
|
150
|
+
/** @description Successful Response */
|
|
151
|
+
200: {
|
|
152
|
+
headers: {
|
|
153
|
+
[name: string]: unknown;
|
|
154
|
+
};
|
|
155
|
+
content: {
|
|
156
|
+
"application/json": unknown;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
add_allowlist_allowlist_post: {
|
|
162
|
+
parameters: {
|
|
163
|
+
query?: never;
|
|
164
|
+
header?: never;
|
|
165
|
+
path?: never;
|
|
166
|
+
cookie?: never;
|
|
167
|
+
};
|
|
168
|
+
requestBody: {
|
|
169
|
+
content: {
|
|
170
|
+
"application/json": components["schemas"]["AllowlistRequest"];
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
responses: {
|
|
174
|
+
/** @description Successful Response */
|
|
175
|
+
200: {
|
|
176
|
+
headers: {
|
|
177
|
+
[name: string]: unknown;
|
|
178
|
+
};
|
|
179
|
+
content: {
|
|
180
|
+
"application/json": unknown;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
/** @description Validation Error */
|
|
184
|
+
422: {
|
|
185
|
+
headers: {
|
|
186
|
+
[name: string]: unknown;
|
|
187
|
+
};
|
|
188
|
+
content: {
|
|
189
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
190
|
+
};
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
allowed_allowed_get: {
|
|
195
|
+
parameters: {
|
|
196
|
+
query: {
|
|
197
|
+
user: string;
|
|
198
|
+
root: string;
|
|
199
|
+
};
|
|
200
|
+
header?: never;
|
|
201
|
+
path?: never;
|
|
202
|
+
cookie?: never;
|
|
203
|
+
};
|
|
204
|
+
requestBody?: never;
|
|
205
|
+
responses: {
|
|
206
|
+
/** @description Successful Response */
|
|
207
|
+
200: {
|
|
208
|
+
headers: {
|
|
209
|
+
[name: string]: unknown;
|
|
210
|
+
};
|
|
211
|
+
content: {
|
|
212
|
+
"application/json": unknown;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
/** @description Validation Error */
|
|
216
|
+
422: {
|
|
217
|
+
headers: {
|
|
218
|
+
[name: string]: unknown;
|
|
219
|
+
};
|
|
220
|
+
content: {
|
|
221
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
allowlist_allowlist__root__get: {
|
|
227
|
+
parameters: {
|
|
228
|
+
query?: never;
|
|
229
|
+
header?: never;
|
|
230
|
+
path: {
|
|
231
|
+
root: string;
|
|
232
|
+
};
|
|
233
|
+
cookie?: never;
|
|
234
|
+
};
|
|
235
|
+
requestBody?: never;
|
|
236
|
+
responses: {
|
|
237
|
+
/** @description Successful Response */
|
|
238
|
+
200: {
|
|
239
|
+
headers: {
|
|
240
|
+
[name: string]: unknown;
|
|
241
|
+
};
|
|
242
|
+
content: {
|
|
243
|
+
"application/json": unknown;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
/** @description Validation Error */
|
|
247
|
+
422: {
|
|
248
|
+
headers: {
|
|
249
|
+
[name: string]: unknown;
|
|
250
|
+
};
|
|
251
|
+
content: {
|
|
252
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
allowlist_count_allowlist__root__count_get: {
|
|
258
|
+
parameters: {
|
|
259
|
+
query?: never;
|
|
260
|
+
header?: never;
|
|
261
|
+
path: {
|
|
262
|
+
root: string;
|
|
263
|
+
};
|
|
264
|
+
cookie?: never;
|
|
265
|
+
};
|
|
266
|
+
requestBody?: never;
|
|
267
|
+
responses: {
|
|
268
|
+
/** @description Successful Response */
|
|
269
|
+
200: {
|
|
270
|
+
headers: {
|
|
271
|
+
[name: string]: unknown;
|
|
272
|
+
};
|
|
273
|
+
content: {
|
|
274
|
+
"application/json": unknown;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
/** @description Validation Error */
|
|
278
|
+
422: {
|
|
279
|
+
headers: {
|
|
280
|
+
[name: string]: unknown;
|
|
281
|
+
};
|
|
282
|
+
content: {
|
|
283
|
+
"application/json": components["schemas"]["HTTPValidationError"];
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
}
|
|
@@ -49,6 +49,15 @@ export const get = async <T>(url: string) => {
|
|
|
49
49
|
* @throws Error when HTTP response fails
|
|
50
50
|
*/
|
|
51
51
|
export const post = async <T>(url: string, data: any) => {
|
|
52
|
+
const controller = new AbortController();
|
|
53
|
+
const { signal } = controller;
|
|
54
|
+
|
|
55
|
+
// 30 minute timeout:
|
|
56
|
+
const timeout = 30 * 60 * 1000;
|
|
57
|
+
|
|
58
|
+
// Set a timeout to automatically abort the request
|
|
59
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
60
|
+
|
|
52
61
|
const response = await fetch(url, {
|
|
53
62
|
method: "POST",
|
|
54
63
|
headers: {
|
|
@@ -56,7 +65,10 @@ export const post = async <T>(url: string, data: any) => {
|
|
|
56
65
|
accept: "application/json",
|
|
57
66
|
},
|
|
58
67
|
body: JSON.stringify(data),
|
|
68
|
+
signal,
|
|
59
69
|
});
|
|
70
|
+
|
|
71
|
+
clearTimeout(timeoutId);
|
|
60
72
|
if (response.status !== 200) {
|
|
61
73
|
let json;
|
|
62
74
|
try {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { IHttpClient } from "./http-api-base";
|
|
2
|
+
|
|
3
|
+
export interface ISubgraphQuerier {
|
|
4
|
+
query: (params: {
|
|
5
|
+
subgraphUrl: string;
|
|
6
|
+
query: string;
|
|
7
|
+
variables?: Record<string, any>;
|
|
8
|
+
}) => Promise<object | undefined>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export class SubgraphQuerier implements ISubgraphQuerier {
|
|
12
|
+
httpClient: IHttpClient;
|
|
13
|
+
|
|
14
|
+
constructor(httpClient: IHttpClient) {
|
|
15
|
+
this.httpClient = httpClient;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async query({
|
|
19
|
+
subgraphUrl,
|
|
20
|
+
query,
|
|
21
|
+
variables,
|
|
22
|
+
}: {
|
|
23
|
+
subgraphUrl: string;
|
|
24
|
+
query: string;
|
|
25
|
+
variables?: Record<string, any>;
|
|
26
|
+
}) {
|
|
27
|
+
const { retries, post } = this.httpClient;
|
|
28
|
+
|
|
29
|
+
const result = await retries(async () => {
|
|
30
|
+
return await post<any>(subgraphUrl, {
|
|
31
|
+
query,
|
|
32
|
+
variables,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return result?.data;
|
|
37
|
+
}
|
|
38
|
+
}
|