@opensea/sdk 10.5.0 → 11.0.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/lib/api/accounts.js +12 -8
- package/lib/api/accounts.js.map +1 -1
- package/lib/api/api.d.ts +16 -10
- package/lib/api/api.js +42 -18
- package/lib/api/api.js.map +1 -1
- package/lib/api/collections.js +7 -15
- package/lib/api/collections.js.map +1 -1
- package/lib/api/fetcher.d.ts +35 -5
- package/lib/api/listings.js +3 -3
- package/lib/api/listings.js.map +1 -1
- package/lib/api/nfts.d.ts +1 -1
- package/lib/api/nfts.js +2 -5
- package/lib/api/nfts.js.map +1 -1
- package/lib/api/offers.d.ts +11 -0
- package/lib/api/offers.js +14 -11
- package/lib/api/offers.js.map +1 -1
- package/lib/api/orders.d.ts +16 -1
- package/lib/api/orders.js +17 -3
- package/lib/api/orders.js.map +1 -1
- package/lib/api/tokens.d.ts +2 -2
- package/lib/api/tokens.js +1 -1
- package/lib/api/tokens.js.map +1 -1
- package/lib/api/types.d.ts +196 -356
- package/lib/api/types.js +2 -1
- package/lib/api/types.js.map +1 -1
- package/lib/orders/types.d.ts +2 -2
- package/lib/orders/utils.d.ts +53 -13
- package/lib/orders/utils.js +33 -50
- package/lib/orders/utils.js.map +1 -1
- package/lib/sdk/base.d.ts +11 -4
- package/lib/sdk/base.js +4 -4
- package/lib/sdk/base.js.map +1 -1
- package/lib/sdk/cancellation.d.ts +3 -1
- package/lib/sdk/cancellation.js +12 -6
- package/lib/sdk/cancellation.js.map +1 -1
- package/lib/sdk/fulfillment.js +7 -4
- package/lib/sdk/fulfillment.js.map +1 -1
- package/lib/sdk/orders.js +1 -1
- package/lib/sdk/orders.js.map +1 -1
- package/lib/types.d.ts +22 -122
- package/lib/types.js.map +1 -1
- package/lib/utils/case.d.ts +63 -0
- package/lib/utils/case.js +83 -0
- package/lib/utils/case.js.map +1 -0
- package/lib/utils/utils.d.ts +0 -1
- package/lib/utils/utils.js +0 -1
- package/lib/utils/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/api/accounts.ts +14 -8
- package/src/api/api.ts +60 -25
- package/src/api/collections.ts +7 -21
- package/src/api/fetcher.ts +41 -6
- package/src/api/listings.ts +3 -3
- package/src/api/nfts.ts +3 -7
- package/src/api/offers.ts +17 -10
- package/src/api/orders.ts +29 -5
- package/src/api/tokens.ts +2 -2
- package/src/api/types.ts +265 -399
- package/src/orders/types.ts +2 -2
- package/src/orders/utils.ts +57 -79
- package/src/sdk/base.ts +4 -4
- package/src/sdk/cancellation.ts +16 -6
- package/src/sdk/fulfillment.ts +7 -6
- package/src/sdk/orders.ts +1 -1
- package/src/types.ts +33 -120
- package/src/utils/case.ts +150 -0
- package/src/utils/utils.ts +0 -1
- package/lib/utils/converters.d.ts +0 -37
- package/lib/utils/converters.js +0 -137
- package/lib/utils/converters.js.map +0 -1
- package/src/utils/converters.ts +0 -145
package/src/api/api.ts
CHANGED
|
@@ -11,6 +11,11 @@ import {
|
|
|
11
11
|
type OrderSide,
|
|
12
12
|
type RequestOptions,
|
|
13
13
|
} from "../types"
|
|
14
|
+
import {
|
|
15
|
+
type Camelize,
|
|
16
|
+
camelizeKeysDeep,
|
|
17
|
+
snakeizeKeysDeep,
|
|
18
|
+
} from "../utils/case"
|
|
14
19
|
import { executeWithRateLimit } from "../utils/rateLimit"
|
|
15
20
|
import { AccountsAPI } from "./accounts"
|
|
16
21
|
import { getInstantApiKeyPath } from "./apiPaths"
|
|
@@ -19,6 +24,7 @@ import { ChainsAPI } from "./chains"
|
|
|
19
24
|
import { CollectionsAPI } from "./collections"
|
|
20
25
|
import { DropsAPI } from "./drops"
|
|
21
26
|
import { EventsAPI } from "./events"
|
|
27
|
+
import type { PostOptions } from "./fetcher"
|
|
22
28
|
import { ListingsAPI } from "./listings"
|
|
23
29
|
import { NFTsAPI } from "./nfts"
|
|
24
30
|
import { OffersAPI } from "./offers"
|
|
@@ -373,7 +379,7 @@ export class OpenSeaAPI {
|
|
|
373
379
|
unitsToFill?: string,
|
|
374
380
|
recipientAddress?: string,
|
|
375
381
|
includeOptionalCreatorFees: boolean = false,
|
|
376
|
-
): Promise<FulfillmentDataResponse
|
|
382
|
+
): Promise<Camelize<FulfillmentDataResponse>> {
|
|
377
383
|
return this.ordersAPI.generateFulfillmentData(
|
|
378
384
|
fulfillerAddress,
|
|
379
385
|
orderHash,
|
|
@@ -637,7 +643,7 @@ export class OpenSeaAPI {
|
|
|
637
643
|
address: string,
|
|
638
644
|
identifier: string,
|
|
639
645
|
chain: Chain = this.chain,
|
|
640
|
-
): Promise<
|
|
646
|
+
): Promise<Record<string, unknown>> {
|
|
641
647
|
return this.nftsAPI.refreshNFTMetadata(address, identifier, chain)
|
|
642
648
|
}
|
|
643
649
|
|
|
@@ -1050,13 +1056,13 @@ export class OpenSeaAPI {
|
|
|
1050
1056
|
* Fetch OHLCV candles for a token.
|
|
1051
1057
|
* @param chain Chain the token lives on.
|
|
1052
1058
|
* @param address Token contract address.
|
|
1053
|
-
* @param args Time-series window plus candle `
|
|
1059
|
+
* @param args Time-series window plus candle `bucketSize` (required).
|
|
1054
1060
|
* @returns The {@link OhlcvResponse} returned by the API.
|
|
1055
1061
|
*/
|
|
1056
1062
|
public async getTokenOhlcv(
|
|
1057
1063
|
chain: Chain,
|
|
1058
1064
|
address: string,
|
|
1059
|
-
args: TokenTimeSeriesArgs & {
|
|
1065
|
+
args: TokenTimeSeriesArgs & { bucketSize: string },
|
|
1060
1066
|
): Promise<OhlcvResponse> {
|
|
1061
1067
|
return this.tokensAPI.getTokenOhlcv(chain, address, args)
|
|
1062
1068
|
}
|
|
@@ -1261,14 +1267,17 @@ export class OpenSeaAPI {
|
|
|
1261
1267
|
apiPath: string,
|
|
1262
1268
|
query: object = {},
|
|
1263
1269
|
options?: RequestOptions,
|
|
1264
|
-
): Promise<T
|
|
1270
|
+
): Promise<Camelize<T>> {
|
|
1265
1271
|
return executeWithRateLimit(
|
|
1266
1272
|
async () => {
|
|
1267
|
-
|
|
1273
|
+
// Snakeize query keys so consumers can pass camelCase args even
|
|
1274
|
+
// though the API expects snake_case URL params.
|
|
1275
|
+
const qs = this.objectToSearchParams(snakeizeKeysDeep(query))
|
|
1268
1276
|
const url = qs
|
|
1269
1277
|
? `${this.apiBaseUrl}${apiPath}?${qs}`
|
|
1270
1278
|
: `${this.apiBaseUrl}${apiPath}`
|
|
1271
|
-
|
|
1279
|
+
const raw = await this._fetch(url, undefined, undefined, options)
|
|
1280
|
+
return camelizeKeysDeep(raw) as Camelize<T>
|
|
1272
1281
|
},
|
|
1273
1282
|
{ logger: this.logger },
|
|
1274
1283
|
)
|
|
@@ -1279,19 +1288,30 @@ export class OpenSeaAPI {
|
|
|
1279
1288
|
* @param apiPath Path to URL endpoint under API
|
|
1280
1289
|
* @param body Data to send.
|
|
1281
1290
|
* @param headers Additional headers to send with the request.
|
|
1282
|
-
* @param options Request options
|
|
1291
|
+
* @param options Request options. Includes the {@link PostOptions.snakeizeBody}
|
|
1292
|
+
* opt-out (defaults to `true`) for callers that need to emit
|
|
1293
|
+
* the body in exact wire shape (e.g. Seaport-shaped POSTs
|
|
1294
|
+
* whose inner keys are camelCase on the wire).
|
|
1283
1295
|
* @returns @typeParam T The response from the API.
|
|
1284
1296
|
*/
|
|
1285
1297
|
public async post<T>(
|
|
1286
1298
|
apiPath: string,
|
|
1287
1299
|
body?: object,
|
|
1288
1300
|
headers?: object,
|
|
1289
|
-
options?:
|
|
1290
|
-
): Promise<T
|
|
1301
|
+
options?: PostOptions,
|
|
1302
|
+
): Promise<Camelize<T>> {
|
|
1291
1303
|
return executeWithRateLimit(
|
|
1292
1304
|
async () => {
|
|
1293
1305
|
const url = `${this.apiBaseUrl}${apiPath}`
|
|
1294
|
-
|
|
1306
|
+
// Snakeize the body so consumers can pass camelCase even though the
|
|
1307
|
+
// API expects snake_case JSON. Opt-out via `snakeizeBody: false` for
|
|
1308
|
+
// Seaport-shaped bodies whose inner keys must remain camelCase on the
|
|
1309
|
+
// wire (the OpenSea OpenAPI spec uses mixed casing for these).
|
|
1310
|
+
const shouldSnakeize = options?.snakeizeBody !== false
|
|
1311
|
+
const wireBody =
|
|
1312
|
+
body == null || !shouldSnakeize ? body : snakeizeKeysDeep(body)
|
|
1313
|
+
const raw = await this._fetch(url, headers, wireBody, options)
|
|
1314
|
+
return camelizeKeysDeep(raw) as Camelize<T>
|
|
1295
1315
|
},
|
|
1296
1316
|
{ logger: this.logger },
|
|
1297
1317
|
)
|
|
@@ -1387,15 +1407,26 @@ export class OpenSeaAPI {
|
|
|
1387
1407
|
if (response.status === 599 || response.status === 429) {
|
|
1388
1408
|
throw await this._createRateLimitError(response)
|
|
1389
1409
|
}
|
|
1390
|
-
const
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1410
|
+
const rawBody = await response.json().catch(() => ({}))
|
|
1411
|
+
const responseBody = camelizeKeysDeep(rawBody) as {
|
|
1412
|
+
errors?: { length?: number } | unknown[]
|
|
1413
|
+
}
|
|
1414
|
+
const errors = responseBody?.errors as
|
|
1415
|
+
| { length?: number }
|
|
1416
|
+
| unknown[]
|
|
1417
|
+
| undefined
|
|
1418
|
+
if (errors?.length !== undefined && errors.length > 0) {
|
|
1419
|
+
// Handle both string entries (`["not found"]`) and structured ones
|
|
1420
|
+
// (`[{code: "invalid_param", message: "..."}]`) — String() on an
|
|
1421
|
+
// object yields "[object Object]", so JSON-stringify any non-string
|
|
1422
|
+
// element individually before joining.
|
|
1423
|
+
const errorMessage = Array.isArray(errors)
|
|
1424
|
+
? errors
|
|
1425
|
+
.map(e => (typeof e === "string" ? e : JSON.stringify(e)))
|
|
1426
|
+
.join(", ")
|
|
1427
|
+
: typeof errors === "string"
|
|
1428
|
+
? errors
|
|
1429
|
+
: JSON.stringify(errors)
|
|
1399
1430
|
throw new Error(`Server Error: ${errorMessage}`)
|
|
1400
1431
|
}
|
|
1401
1432
|
throw new Error(
|
|
@@ -1421,12 +1452,13 @@ export class OpenSeaAPI {
|
|
|
1421
1452
|
*
|
|
1422
1453
|
* @example
|
|
1423
1454
|
* ```ts
|
|
1424
|
-
* const {
|
|
1425
|
-
* const api = new OpenSeaAPI({ apiKey
|
|
1455
|
+
* const { apiKey } = await OpenSeaAPI.requestInstantApiKey()
|
|
1456
|
+
* const api = new OpenSeaAPI({ apiKey })
|
|
1426
1457
|
* ```
|
|
1427
1458
|
*
|
|
1428
1459
|
* @param apiBaseUrl Optional base URL override (defaults to mainnet).
|
|
1429
|
-
* @returns The {@link RequestInstantApiKeyResponse} containing the new key
|
|
1460
|
+
* @returns The {@link RequestInstantApiKeyResponse} containing the new key,
|
|
1461
|
+
* with response keys camelized to match SDK conventions.
|
|
1430
1462
|
*/
|
|
1431
1463
|
public static async requestInstantApiKey(
|
|
1432
1464
|
apiBaseUrl: string = API_BASE_MAINNET,
|
|
@@ -1444,7 +1476,8 @@ export class OpenSeaAPI {
|
|
|
1444
1476
|
`Server Error (${response.status}): ${response.statusText}`,
|
|
1445
1477
|
)
|
|
1446
1478
|
}
|
|
1447
|
-
|
|
1479
|
+
const raw = await response.json()
|
|
1480
|
+
return camelizeKeysDeep(raw) as RequestInstantApiKeyResponse
|
|
1448
1481
|
}
|
|
1449
1482
|
|
|
1450
1483
|
/**
|
|
@@ -1509,7 +1542,9 @@ export class OpenSeaAPI {
|
|
|
1509
1542
|
// Add status code and retry-after information to the error object
|
|
1510
1543
|
error.statusCode = response.status
|
|
1511
1544
|
error.retryAfter = retryAfter
|
|
1512
|
-
|
|
1545
|
+
const rawBody = await response.json().catch(() => undefined)
|
|
1546
|
+
error.responseBody =
|
|
1547
|
+
rawBody === undefined ? undefined : camelizeKeysDeep(rawBody)
|
|
1513
1548
|
return error
|
|
1514
1549
|
}
|
|
1515
1550
|
}
|
package/src/api/collections.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Chain, OpenSeaCollection, OpenSeaCollectionStats } from "../types"
|
|
2
|
-
import { collectionFromJSON } from "../utils/converters"
|
|
3
2
|
import {
|
|
4
3
|
getBatchCollectionsPath,
|
|
5
4
|
getCollectionFloorPricesPath,
|
|
@@ -43,8 +42,7 @@ export class CollectionsAPI {
|
|
|
43
42
|
*/
|
|
44
43
|
async getCollection(slug: string): Promise<OpenSeaCollection> {
|
|
45
44
|
const path = getCollectionPath(slug)
|
|
46
|
-
|
|
47
|
-
return collectionFromJSON(response)
|
|
45
|
+
return this.fetcher.get<GetCollectionResponse>(path)
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
/**
|
|
@@ -60,18 +58,14 @@ export class CollectionsAPI {
|
|
|
60
58
|
): Promise<GetCollectionsResponse> {
|
|
61
59
|
const path = getCollectionsPath()
|
|
62
60
|
const args: GetCollectionsArgs = {
|
|
63
|
-
|
|
61
|
+
orderBy,
|
|
64
62
|
chain,
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
creatorUsername,
|
|
64
|
+
includeHidden,
|
|
67
65
|
limit,
|
|
68
66
|
next,
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
response.collections = response.collections.map(collection =>
|
|
72
|
-
collectionFromJSON(collection),
|
|
73
|
-
)
|
|
74
|
-
return response
|
|
68
|
+
return this.fetcher.get<GetCollectionsResponse>(path, args)
|
|
75
69
|
}
|
|
76
70
|
|
|
77
71
|
/**
|
|
@@ -98,17 +92,13 @@ export class CollectionsAPI {
|
|
|
98
92
|
async getTrendingCollections(
|
|
99
93
|
args?: GetTrendingCollectionsArgs,
|
|
100
94
|
): Promise<GetCollectionsPaginatedResponse> {
|
|
101
|
-
|
|
95
|
+
return this.fetcher.get<GetCollectionsPaginatedResponse>(
|
|
102
96
|
getTrendingCollectionsPath(),
|
|
103
97
|
{
|
|
104
98
|
...args,
|
|
105
99
|
chains: args?.chains?.join(","),
|
|
106
100
|
},
|
|
107
101
|
)
|
|
108
|
-
response.collections = response.collections.map(collection =>
|
|
109
|
-
collectionFromJSON(collection),
|
|
110
|
-
)
|
|
111
|
-
return response
|
|
112
102
|
}
|
|
113
103
|
|
|
114
104
|
/**
|
|
@@ -117,17 +107,13 @@ export class CollectionsAPI {
|
|
|
117
107
|
async getTopCollections(
|
|
118
108
|
args?: GetTopCollectionsArgs,
|
|
119
109
|
): Promise<GetCollectionsPaginatedResponse> {
|
|
120
|
-
|
|
110
|
+
return this.fetcher.get<GetCollectionsPaginatedResponse>(
|
|
121
111
|
getTopCollectionsPath(),
|
|
122
112
|
{
|
|
123
113
|
...args,
|
|
124
114
|
chains: args?.chains?.join(","),
|
|
125
115
|
},
|
|
126
116
|
)
|
|
127
|
-
response.collections = response.collections.map(collection =>
|
|
128
|
-
collectionFromJSON(collection),
|
|
129
|
-
)
|
|
130
|
-
return response
|
|
131
117
|
}
|
|
132
118
|
|
|
133
119
|
/**
|
package/src/api/fetcher.ts
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
1
|
import type { RequestOptions } from "../types"
|
|
2
|
+
import type { Camelize } from "../utils/case"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options for the {@link Fetcher.post} method.
|
|
6
|
+
*
|
|
7
|
+
* Extends {@link RequestOptions} with a `snakeizeBody` opt-out so callers
|
|
8
|
+
* with mixed-casing wire bodies (e.g. Seaport order structs whose inner
|
|
9
|
+
* keys are camelCase on-wire) can disable the automatic camel→snake key
|
|
10
|
+
* rewrite and submit the body verbatim.
|
|
11
|
+
*
|
|
12
|
+
* @category API Models
|
|
13
|
+
*/
|
|
14
|
+
export interface PostOptions extends RequestOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Whether to recursively rewrite the body's keys from camelCase to
|
|
17
|
+
* snake_case before sending. Defaults to `true`.
|
|
18
|
+
*
|
|
19
|
+
* Set to `false` when the body contains Seaport-shaped structs or other
|
|
20
|
+
* mixed-casing payloads where some keys (`parameters.startTime`,
|
|
21
|
+
* `numericTraits`, `offererSignature`, …) must remain camelCase on the
|
|
22
|
+
* wire per the OpenSea OpenAPI spec. The caller is then responsible
|
|
23
|
+
* for emitting the body in exact wire shape.
|
|
24
|
+
*/
|
|
25
|
+
snakeizeBody?: boolean
|
|
26
|
+
}
|
|
2
27
|
|
|
3
28
|
/**
|
|
4
29
|
* Fetcher context interface for making HTTP requests to the OpenSea API.
|
|
5
30
|
* This interface abstracts the HTTP methods used by specialized API clients.
|
|
31
|
+
*
|
|
32
|
+
* Responses are camelized at this boundary — pass the API's snake_case shape
|
|
33
|
+
* (e.g. an api-types response type) as `T` and the return is the camelCase
|
|
34
|
+
* view. See `utils/case.ts`.
|
|
6
35
|
*/
|
|
7
36
|
export interface Fetcher {
|
|
8
37
|
/**
|
|
@@ -10,22 +39,28 @@ export interface Fetcher {
|
|
|
10
39
|
* @param apiPath Path to URL endpoint under API
|
|
11
40
|
* @param query URL query params. Will be used to create a URLSearchParams object.
|
|
12
41
|
* @param options Request options like timeout and abort signal.
|
|
13
|
-
* @returns The
|
|
42
|
+
* @returns The camelCase view of the API response.
|
|
14
43
|
*/
|
|
15
|
-
get<T>(
|
|
44
|
+
get<T>(
|
|
45
|
+
apiPath: string,
|
|
46
|
+
query?: object,
|
|
47
|
+
options?: RequestOptions,
|
|
48
|
+
): Promise<Camelize<T>>
|
|
16
49
|
|
|
17
50
|
/**
|
|
18
51
|
* Generic post method for POST requests with automatic rate limit retry
|
|
19
52
|
* @param apiPath Path to URL endpoint under API
|
|
20
53
|
* @param body Data to send.
|
|
21
54
|
* @param headers Additional headers to send with the request.
|
|
22
|
-
* @param options Request options
|
|
23
|
-
*
|
|
55
|
+
* @param options Request options. Includes the {@link PostOptions.snakeizeBody}
|
|
56
|
+
* opt-out for callers that need to emit the body in exact wire
|
|
57
|
+
* shape (e.g. Seaport-shaped POSTs).
|
|
58
|
+
* @returns The camelCase view of the API response.
|
|
24
59
|
*/
|
|
25
60
|
post<T>(
|
|
26
61
|
apiPath: string,
|
|
27
62
|
body?: object,
|
|
28
63
|
headers?: object,
|
|
29
|
-
options?:
|
|
30
|
-
): Promise<T
|
|
64
|
+
options?: PostOptions,
|
|
65
|
+
): Promise<Camelize<T>>
|
|
31
66
|
}
|
package/src/api/listings.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class ListingsAPI {
|
|
|
45
45
|
limit,
|
|
46
46
|
next,
|
|
47
47
|
...(includePrivateListings !== undefined && {
|
|
48
|
-
|
|
48
|
+
includePrivateListings,
|
|
49
49
|
}),
|
|
50
50
|
},
|
|
51
51
|
)
|
|
@@ -66,7 +66,7 @@ export class ListingsAPI {
|
|
|
66
66
|
const response = await this.fetcher.get<GetBestListingResponse>(
|
|
67
67
|
getBestListingAPIPath(collectionSlug, tokenId),
|
|
68
68
|
includePrivateListings !== undefined
|
|
69
|
-
? {
|
|
69
|
+
? { includePrivateListings }
|
|
70
70
|
: undefined,
|
|
71
71
|
)
|
|
72
72
|
return response
|
|
@@ -89,7 +89,7 @@ export class ListingsAPI {
|
|
|
89
89
|
limit,
|
|
90
90
|
next,
|
|
91
91
|
...(includePrivateListings !== undefined && {
|
|
92
|
-
|
|
92
|
+
includePrivateListings,
|
|
93
93
|
}),
|
|
94
94
|
traits: encodeTraitsParam(traits),
|
|
95
95
|
},
|
package/src/api/nfts.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Chain, OpenSeaCollection } from "../types"
|
|
2
|
-
import { collectionFromJSON } from "../utils/converters"
|
|
3
2
|
import {
|
|
4
3
|
getBatchNFTsPath,
|
|
5
4
|
getContractPath,
|
|
@@ -117,13 +116,11 @@ export class NFTsAPI {
|
|
|
117
116
|
address: string,
|
|
118
117
|
identifier: string,
|
|
119
118
|
chain: Chain = this.chain,
|
|
120
|
-
): Promise<
|
|
121
|
-
|
|
119
|
+
): Promise<Record<string, unknown>> {
|
|
120
|
+
return this.fetcher.post<Record<string, unknown>>(
|
|
122
121
|
getRefreshMetadataPath(chain, address, identifier),
|
|
123
122
|
{},
|
|
124
123
|
)
|
|
125
|
-
|
|
126
|
-
return response
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
/**
|
|
@@ -166,10 +163,9 @@ export class NFTsAPI {
|
|
|
166
163
|
identifier: string,
|
|
167
164
|
chain: Chain = this.chain,
|
|
168
165
|
): Promise<OpenSeaCollection> {
|
|
169
|
-
|
|
166
|
+
return this.fetcher.get<GetCollectionResponse>(
|
|
170
167
|
getNFTCollectionPath(chain, address, identifier),
|
|
171
168
|
)
|
|
172
|
-
return collectionFromJSON(response)
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
/**
|
package/src/api/offers.ts
CHANGED
|
@@ -114,18 +114,10 @@ export class OffersAPI {
|
|
|
114
114
|
floatValue?: number,
|
|
115
115
|
intValue?: number,
|
|
116
116
|
): Promise<GetOffersResponse> {
|
|
117
|
-
|
|
117
|
+
return this.fetcher.get<GetOffersResponse>(
|
|
118
118
|
getTraitOffersPath(collectionSlug),
|
|
119
|
-
{
|
|
120
|
-
type,
|
|
121
|
-
value,
|
|
122
|
-
limit,
|
|
123
|
-
next,
|
|
124
|
-
float_value: floatValue,
|
|
125
|
-
int_value: intValue,
|
|
126
|
-
},
|
|
119
|
+
{ type, value, limit, next, floatValue, intValue },
|
|
127
120
|
)
|
|
128
|
-
return response
|
|
129
121
|
}
|
|
130
122
|
|
|
131
123
|
/**
|
|
@@ -143,6 +135,12 @@ export class OffersAPI {
|
|
|
143
135
|
|
|
144
136
|
/**
|
|
145
137
|
* Build a OpenSea collection offer.
|
|
138
|
+
*
|
|
139
|
+
* The body uses mixed casing per the OpenSea OpenAPI spec: the outer
|
|
140
|
+
* envelope (`protocol_address`, `offer_protection_enabled`) is snake_case,
|
|
141
|
+
* but `criteria.numericTraits` keeps its camelCase key on the wire per
|
|
142
|
+
* the {@link CriteriaObject} schema. Opt out of automatic snakeize and
|
|
143
|
+
* emit the body in exact wire shape.
|
|
146
144
|
*/
|
|
147
145
|
async buildOffer(
|
|
148
146
|
offererAddress: string,
|
|
@@ -169,6 +167,8 @@ export class OffersAPI {
|
|
|
169
167
|
const response = await this.fetcher.post<BuildOfferResponse>(
|
|
170
168
|
getBuildOfferPath(),
|
|
171
169
|
payload,
|
|
170
|
+
undefined,
|
|
171
|
+
{ snakeizeBody: false },
|
|
172
172
|
)
|
|
173
173
|
return response
|
|
174
174
|
}
|
|
@@ -192,6 +192,11 @@ export class OffersAPI {
|
|
|
192
192
|
|
|
193
193
|
/**
|
|
194
194
|
* Post a collection offer to OpenSea.
|
|
195
|
+
*
|
|
196
|
+
* Mixed-casing body: outer `protocol_address`, `protocol_data` are
|
|
197
|
+
* snake_case, but `protocol_data.parameters` (Seaport struct) and
|
|
198
|
+
* `criteria.numericTraits` keep their camelCase keys on the wire. Opt out
|
|
199
|
+
* of automatic snakeize and emit the body in exact wire shape.
|
|
195
200
|
*/
|
|
196
201
|
async postCollectionOffer(
|
|
197
202
|
order: ProtocolData,
|
|
@@ -214,6 +219,8 @@ export class OffersAPI {
|
|
|
214
219
|
return await this.fetcher.post<CollectionOffer>(
|
|
215
220
|
getPostCollectionOfferPath(),
|
|
216
221
|
payload,
|
|
222
|
+
undefined,
|
|
223
|
+
{ snakeizeBody: false },
|
|
217
224
|
)
|
|
218
225
|
}
|
|
219
226
|
|
package/src/api/orders.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getFulfillOfferPayload,
|
|
6
6
|
} from "../orders/utils"
|
|
7
7
|
import { type Chain, OrderSide } from "../types"
|
|
8
|
+
import type { Camelize } from "../utils/case"
|
|
8
9
|
import {
|
|
9
10
|
getCancelOrderPath,
|
|
10
11
|
getOrderByHashPath,
|
|
@@ -56,7 +57,7 @@ export class OrdersAPI {
|
|
|
56
57
|
unitsToFill?: string,
|
|
57
58
|
recipientAddress?: string,
|
|
58
59
|
includeOptionalCreatorFees: boolean = false,
|
|
59
|
-
): Promise<FulfillmentDataResponse
|
|
60
|
+
): Promise<Camelize<FulfillmentDataResponse>> {
|
|
60
61
|
const payload =
|
|
61
62
|
side === OrderSide.LISTING
|
|
62
63
|
? getFulfillListingPayload(
|
|
@@ -88,6 +89,12 @@ export class OrdersAPI {
|
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* Post a listing to OpenSea.
|
|
92
|
+
*
|
|
93
|
+
* The body uses mixed casing per the OpenSea OpenAPI spec: the outer
|
|
94
|
+
* envelope (`protocol_address`) is snake_case, but the inner Seaport
|
|
95
|
+
* struct (`parameters.startTime`, `parameters.orderType`, `offer[].itemType`,
|
|
96
|
+
* etc.) mirrors the on-chain struct names and must stay camelCase on the
|
|
97
|
+
* wire. We pass `snakeizeBody: false` and emit the body in exact wire shape.
|
|
91
98
|
*/
|
|
92
99
|
async postListing(
|
|
93
100
|
order: ProtocolData,
|
|
@@ -106,11 +113,18 @@ export class OrdersAPI {
|
|
|
106
113
|
...order,
|
|
107
114
|
protocol_address: protocolAddress,
|
|
108
115
|
},
|
|
116
|
+
undefined,
|
|
117
|
+
{ snakeizeBody: false },
|
|
109
118
|
)
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
/**
|
|
113
122
|
* Post an offer to OpenSea.
|
|
123
|
+
*
|
|
124
|
+
* Same mixed-casing wire shape as {@link postListing}: outer
|
|
125
|
+
* `protocol_address` is snake_case but the inner Seaport struct stays
|
|
126
|
+
* camelCase. We opt out of automatic snakeize so `parameters` is sent
|
|
127
|
+
* verbatim.
|
|
114
128
|
*/
|
|
115
129
|
async postOffer(
|
|
116
130
|
order: ProtocolData,
|
|
@@ -123,14 +137,22 @@ export class OrdersAPI {
|
|
|
123
137
|
throw new Error("Invalid protocol address format")
|
|
124
138
|
}
|
|
125
139
|
|
|
126
|
-
return this.fetcher.post<Offer>(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
return this.fetcher.post<Offer>(
|
|
141
|
+
getPostOfferPath(this.chain, "seaport"),
|
|
142
|
+
{
|
|
143
|
+
...order,
|
|
144
|
+
protocol_address: protocolAddress,
|
|
145
|
+
},
|
|
146
|
+
undefined,
|
|
147
|
+
{ snakeizeBody: false },
|
|
148
|
+
)
|
|
130
149
|
}
|
|
131
150
|
|
|
132
151
|
/**
|
|
133
152
|
* Offchain cancel an order, offer or listing, by its order hash when protected by the SignedZone.
|
|
153
|
+
*
|
|
154
|
+
* The OpenSea OpenAPI `CancelRequest` schema uses camelCase
|
|
155
|
+
* `offererSignature`, so we opt out of automatic snakeize.
|
|
134
156
|
*/
|
|
135
157
|
async offchainCancelOrder(
|
|
136
158
|
protocolAddress: string,
|
|
@@ -141,6 +163,8 @@ export class OrdersAPI {
|
|
|
141
163
|
return this.fetcher.post<CancelOrderResponse>(
|
|
142
164
|
getCancelOrderPath(chain, protocolAddress, orderHash),
|
|
143
165
|
{ offererSignature },
|
|
166
|
+
undefined,
|
|
167
|
+
{ snakeizeBody: false },
|
|
144
168
|
)
|
|
145
169
|
}
|
|
146
170
|
}
|
package/src/api/tokens.ts
CHANGED
|
@@ -135,12 +135,12 @@ export class TokensAPI {
|
|
|
135
135
|
|
|
136
136
|
/**
|
|
137
137
|
* Fetch OHLCV (open / high / low / close / volume) candles for a token.
|
|
138
|
-
* `
|
|
138
|
+
* `startTime` and `bucketSize` are required.
|
|
139
139
|
*/
|
|
140
140
|
async getTokenOhlcv(
|
|
141
141
|
chain: Chain,
|
|
142
142
|
address: string,
|
|
143
|
-
args: TokenTimeSeriesArgs & {
|
|
143
|
+
args: TokenTimeSeriesArgs & { bucketSize: string },
|
|
144
144
|
): Promise<OhlcvResponse> {
|
|
145
145
|
return this.fetcher.get<OhlcvResponse>(
|
|
146
146
|
getTokenOhlcvPath(chain, address),
|