@opensea/sdk 11.3.0 → 11.4.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.
@@ -0,0 +1,283 @@
1
+ import type {
2
+ OperationQueryParams,
3
+ OperationRequestBody,
4
+ OperationResponse,
5
+ operations,
6
+ } from "@opensea/api-types"
7
+ import type { Camelize } from "../utils/case"
8
+ import type { WalletAuthFetcher } from "./fetcher"
9
+
10
+ type OperationName = keyof operations
11
+ export type WalletAuthRequest<T extends OperationName> = Camelize<
12
+ OperationRequestBody<T>
13
+ >
14
+ export type WalletAuthResponse<T extends OperationName> = Camelize<
15
+ OperationResponse<T>
16
+ >
17
+ export type WalletAuthQuery<T extends OperationName> = Camelize<
18
+ OperationQueryParams<T>
19
+ >
20
+
21
+ const segment = (value: string | number) => encodeURIComponent(String(value))
22
+
23
+ /** Typed helpers for wallet-authenticated REST operations. */
24
+ export class WalletAuthAPI {
25
+ constructor(private fetcher: WalletAuthFetcher) {}
26
+
27
+ getDropEligibility(slug: string) {
28
+ return this.fetcher.get<OperationResponse<"get_drop_eligibility">>(
29
+ `/api/v2/drops/${segment(slug)}/eligibility`,
30
+ )
31
+ }
32
+
33
+ getFavorites(
34
+ address: string,
35
+ query?: WalletAuthQuery<"get_profile_favorites">,
36
+ ) {
37
+ return this.fetcher.get<OperationResponse<"get_profile_favorites">>(
38
+ `/api/v2/account/${segment(address)}/favorites`,
39
+ query,
40
+ )
41
+ }
42
+
43
+ getTokenWatchlist(address: string) {
44
+ return this.fetcher.get<OperationResponse<"get_account_token_watchlist">>(
45
+ `/api/v2/account/${segment(address)}/token_watchlist`,
46
+ )
47
+ }
48
+
49
+ getPerpetualWatchlist(address: string) {
50
+ return this.fetcher.get<
51
+ OperationResponse<"get_account_perpetual_watchlist">
52
+ >(`/api/v2/account/${segment(address)}/perpetual_watchlist`)
53
+ }
54
+
55
+ addWatchlistEntry(body: WalletAuthRequest<"add_watchlist_entry">) {
56
+ return this.fetcher.request<OperationResponse<"add_watchlist_entry">>(
57
+ "POST",
58
+ "/api/v2/watchlist",
59
+ body,
60
+ )
61
+ }
62
+
63
+ removeWatchlistEntry(body: WalletAuthRequest<"remove_watchlist_entry">) {
64
+ return this.fetcher.request<OperationResponse<"remove_watchlist_entry">>(
65
+ "DELETE",
66
+ "/api/v2/watchlist",
67
+ body,
68
+ )
69
+ }
70
+
71
+ cancelOrder(
72
+ chain: string,
73
+ protocolAddress: string,
74
+ orderHash: string,
75
+ body: WalletAuthRequest<"cancel_order">,
76
+ ) {
77
+ return this.fetcher.request<OperationResponse<"cancel_order">>(
78
+ "POST",
79
+ `/api/v2/orders/chain/${segment(chain)}/protocol/${segment(protocolAddress)}/${segment(orderHash)}/cancel`,
80
+ body,
81
+ )
82
+ }
83
+
84
+ saveDropEdits(slug: string, body: WalletAuthRequest<"save_drop_edits">) {
85
+ return this.fetcher.request<OperationResponse<"save_drop_edits">>(
86
+ "POST",
87
+ `/api/v2/drops/${segment(slug)}`,
88
+ body,
89
+ )
90
+ }
91
+
92
+ savePrerevealDropItem(
93
+ slug: string,
94
+ body: WalletAuthRequest<"save_prereveal_drop_item">,
95
+ ) {
96
+ return this.fetcher.request<OperationResponse<"save_prereveal_drop_item">>(
97
+ "POST",
98
+ `/api/v2/drops/${segment(slug)}/prereveal-item`,
99
+ body,
100
+ )
101
+ }
102
+
103
+ saveSelfMintDropItem(
104
+ slug: string,
105
+ body: WalletAuthRequest<"save_self_mint_drop_item">,
106
+ ) {
107
+ return this.fetcher.request<OperationResponse<"save_self_mint_drop_item">>(
108
+ "POST",
109
+ `/api/v2/drops/${segment(slug)}/items`,
110
+ body,
111
+ )
112
+ }
113
+
114
+ updateSelfMintDropItem(
115
+ slug: string,
116
+ tokenId: string | number,
117
+ body: WalletAuthRequest<"update_self_mint_drop_item">,
118
+ ) {
119
+ return this.fetcher.request<
120
+ OperationResponse<"update_self_mint_drop_item">
121
+ >("PUT", `/api/v2/drops/${segment(slug)}/items/${segment(tokenId)}`, body)
122
+ }
123
+
124
+ updateDropItem(
125
+ slug: string,
126
+ tokenId: string | number,
127
+ body: WalletAuthRequest<"update_drop_item">,
128
+ ) {
129
+ return this.fetcher.request<OperationResponse<"update_drop_item">>(
130
+ "PATCH",
131
+ `/api/v2/drops/${segment(slug)}/items/${segment(tokenId)}`,
132
+ body,
133
+ )
134
+ }
135
+
136
+ createDropItemMediaUpload(
137
+ slug: string,
138
+ body: WalletAuthRequest<"upload_drop_item_media">,
139
+ ) {
140
+ return this.fetcher.request<OperationResponse<"upload_drop_item_media">>(
141
+ "POST",
142
+ `/api/v2/drops/${segment(slug)}/items/media`,
143
+ body,
144
+ )
145
+ }
146
+
147
+ saveDropItemMedia(
148
+ slug: string,
149
+ body: WalletAuthRequest<"save_drop_item_media">,
150
+ ) {
151
+ return this.fetcher.request<OperationResponse<"save_drop_item_media">>(
152
+ "POST",
153
+ `/api/v2/drops/${segment(slug)}/items/media/save`,
154
+ body,
155
+ )
156
+ }
157
+
158
+ createDropAllowlistUpload(slug: string) {
159
+ return this.fetcher.request<OperationResponse<"upload_drop_allowlist">>(
160
+ "POST",
161
+ `/api/v2/drops/${segment(slug)}/allowlist`,
162
+ )
163
+ }
164
+
165
+ validateDropAllowlist(
166
+ slug: string,
167
+ body: WalletAuthRequest<"validate_drop_allowlist">,
168
+ ) {
169
+ return this.fetcher.request<OperationResponse<"validate_drop_allowlist">>(
170
+ "POST",
171
+ `/api/v2/drops/${segment(slug)}/allowlist/validate`,
172
+ body,
173
+ )
174
+ }
175
+
176
+ modifyCollection(slug: string, body: WalletAuthRequest<"modify_collection">) {
177
+ return this.fetcher.request<OperationResponse<"modify_collection">>(
178
+ "PATCH",
179
+ `/api/v2/collections/${segment(slug)}`,
180
+ body,
181
+ )
182
+ }
183
+
184
+ updateCollectionMetadata(
185
+ slug: string,
186
+ body: WalletAuthRequest<"update_collection_metadata">,
187
+ ) {
188
+ return this.fetcher.request<
189
+ OperationResponse<"update_collection_metadata">
190
+ >("PATCH", `/api/v2/collections/${segment(slug)}/metadata`, body)
191
+ }
192
+
193
+ setCollectionVisibility(
194
+ slug: string,
195
+ body: WalletAuthRequest<"set_collection_visibility">,
196
+ ) {
197
+ return this.fetcher.request<OperationResponse<"set_collection_visibility">>(
198
+ "PATCH",
199
+ `/api/v2/collections/${segment(slug)}/visibility`,
200
+ body,
201
+ )
202
+ }
203
+
204
+ createCollectionImageUpload(slug: string, imageType: string) {
205
+ return this.fetcher.request<OperationResponse<"upload_collection_image">>(
206
+ "POST",
207
+ `/api/v2/collections/${segment(slug)}/images/${segment(imageType)}`,
208
+ )
209
+ }
210
+
211
+ updateProfileSettings(body: WalletAuthRequest<"update_profile_settings">) {
212
+ return this.fetcher.request<OperationResponse<"update_profile_settings">>(
213
+ "PATCH",
214
+ "/api/v2/profile",
215
+ body,
216
+ )
217
+ }
218
+
219
+ claimProfileUsername(body: WalletAuthRequest<"claim_profile_username">) {
220
+ return this.fetcher.request<OperationResponse<"claim_profile_username">>(
221
+ "POST",
222
+ "/api/v2/profile/username",
223
+ body,
224
+ )
225
+ }
226
+
227
+ createProfileImageUpload(body: WalletAuthRequest<"upload_profile_image">) {
228
+ return this.fetcher.request<OperationResponse<"upload_profile_image">>(
229
+ "POST",
230
+ "/api/v2/profile/images",
231
+ body,
232
+ )
233
+ }
234
+
235
+ createProfileShelf(body: WalletAuthRequest<"create_profile_shelf">) {
236
+ return this.fetcher.request<OperationResponse<"create_profile_shelf">>(
237
+ "POST",
238
+ "/api/v2/profile/shelves",
239
+ body,
240
+ )
241
+ }
242
+
243
+ reorderProfileShelves(body: WalletAuthRequest<"reorder_profile_shelves">) {
244
+ return this.fetcher.request<OperationResponse<"reorder_profile_shelves">>(
245
+ "PATCH",
246
+ "/api/v2/profile/shelves",
247
+ body,
248
+ )
249
+ }
250
+
251
+ updateProfileShelf(
252
+ shelfId: string,
253
+ body: WalletAuthRequest<"update_profile_shelf">,
254
+ ) {
255
+ return this.fetcher.request<OperationResponse<"update_profile_shelf">>(
256
+ "PATCH",
257
+ `/api/v2/profile/shelves/${segment(shelfId)}`,
258
+ body,
259
+ )
260
+ }
261
+
262
+ deleteProfileShelf(shelfId: string) {
263
+ return this.fetcher.request<OperationResponse<"delete_profile_shelf">>(
264
+ "DELETE",
265
+ `/api/v2/profile/shelves/${segment(shelfId)}`,
266
+ )
267
+ }
268
+
269
+ linkWallet(body: WalletAuthRequest<"link_wallet_with_siwx">) {
270
+ return this.fetcher.request<OperationResponse<"link_wallet_with_siwx">>(
271
+ "POST",
272
+ "/api/v2/accounts/wallets/siwx",
273
+ body,
274
+ )
275
+ }
276
+
277
+ unlinkWallet(wallet: string) {
278
+ return this.fetcher.request<OperationResponse<"unlink_wallet">>(
279
+ "DELETE",
280
+ `/api/v2/accounts/wallets/${segment(wallet)}`,
281
+ )
282
+ }
283
+ }
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ import { OpenSeaOAuth } from "./auth/oauth"
4
4
  import { OpenSeaSDK } from "./sdk"
5
5
 
6
6
  export * from "./api/types"
7
+ export * from "./api/walletAuth"
7
8
  export * from "./auth"
8
9
  export * from "./auth/oauth"
9
10
  export * from "./auth/oauth-types"
package/src/scopes.ts CHANGED
@@ -12,9 +12,11 @@ import type { AuthScope } from "@opensea/api-types"
12
12
  export const OPENSEA_SCOPES = {
13
13
  READ_ELIGIBILITY: "read:eligibility",
14
14
  READ_FAVORITES: "read:favorites",
15
- READ_REWARDS: "read:rewards",
15
+ WRITE_FAVORITES: "write:favorites",
16
16
  WRITE_ORDERS: "write:orders",
17
17
  WRITE_DROPS: "write:drops",
18
+ WRITE_COLLECTIONS: "write:collections",
19
+ WRITE_PROFILE: "write:profile",
18
20
  WRITE_WALLETS: "write:wallets",
19
21
  } as const satisfies Record<string, AuthScope>
20
22
 
@@ -10,15 +10,11 @@ export function parseUnits(
10
10
  ): bigint {
11
11
  let str = value.toString()
12
12
 
13
- // Handle scientific notation (e.g. 1e-8 → "0.00000001") for both
14
- // number and string inputs. Note: toFixed has precision limits for very
15
- // large numbers, but this is sufficient for realistic token amounts.
16
- if (str.includes("e") || str.includes("E")) {
17
- const num = Number(str)
18
- if (isNaN(num)) {
19
- throw new Error(`Invalid numeric value: ${str}`)
20
- }
21
- str = num.toFixed(decimals)
13
+ // Handle JavaScript scientific notation (e.g. 1e-8 → "0.00000001").
14
+ // Note: toFixed has precision limits for very large numbers, but this is
15
+ // sufficient for realistic token amounts (up to ~2^53).
16
+ if (typeof value === "number" && str.includes("e")) {
17
+ str = value.toFixed(decimals)
22
18
  }
23
19
 
24
20
  // Handle negative values
package/src/viem.ts CHANGED
@@ -40,6 +40,7 @@ import {
40
40
  // Re-export everything from the main entry point
41
41
  export { OpenSeaAPI } from "./api/api"
42
42
  export * from "./api/types"
43
+ export * from "./api/walletAuth"
43
44
  export * from "./auth"
44
45
  export * from "./constants"
45
46
  export * from "./orders/types"