@opensea/sdk 12.0.1 → 12.1.1

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.
@@ -5,6 +5,7 @@ import type {
5
5
  operations,
6
6
  } from "@opensea/api-types"
7
7
  import type { Camelize } from "../utils/case"
8
+ import { segment } from "./apiPaths"
8
9
  import type { WalletAuthFetcher } from "./fetcher"
9
10
 
10
11
  type OperationName = keyof operations
@@ -18,8 +19,6 @@ export type WalletAuthQuery<T extends OperationName> = Camelize<
18
19
  OperationQueryParams<T>
19
20
  >
20
21
 
21
- const segment = (value: string | number) => encodeURIComponent(String(value))
22
-
23
22
  /** Typed helpers for wallet-authenticated REST operations. */
24
23
  export class WalletAuthAPI {
25
24
  constructor(private fetcher: WalletAuthFetcher) {}
@@ -224,6 +223,12 @@ export class WalletAuthAPI {
224
223
  )
225
224
  }
226
225
 
226
+ /**
227
+ * `UploadContext.fields` is an opaque signed multipart field map that the
228
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
229
+ * legitimate field name such as S3's `success_action_status` comes back as
230
+ * `successActionStatus` and the form no longer matches the signed policy.
231
+ */
227
232
  createDropItemMediaUpload(
228
233
  slug: string,
229
234
  body: WalletAuthRequest<"upload_drop_item_media">,
@@ -232,6 +237,8 @@ export class WalletAuthAPI {
232
237
  "POST",
233
238
  `/api/v2/drops/${segment(slug)}/items/media`,
234
239
  body,
240
+ undefined,
241
+ { camelizeResponse: false },
235
242
  )
236
243
  }
237
244
 
@@ -246,10 +253,19 @@ export class WalletAuthAPI {
246
253
  )
247
254
  }
248
255
 
256
+ /**
257
+ * `UploadContext.fields` is an opaque signed multipart field map that the
258
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
259
+ * legitimate field name such as S3's `success_action_status` comes back as
260
+ * `successActionStatus` and the form no longer matches the signed policy.
261
+ */
249
262
  createDropAllowlistUpload(slug: string) {
250
263
  return this.fetcher.request<OperationResponse<"upload_drop_allowlist">>(
251
264
  "POST",
252
265
  `/api/v2/drops/${segment(slug)}/allowlist`,
266
+ undefined,
267
+ undefined,
268
+ { camelizeResponse: false },
253
269
  )
254
270
  }
255
271
 
@@ -292,6 +308,12 @@ export class WalletAuthAPI {
292
308
  )
293
309
  }
294
310
 
311
+ /**
312
+ * `UploadContext.fields` is an opaque signed multipart field map that the
313
+ * caller must submit unchanged, so the response is not camelized. Otherwise a
314
+ * legitimate field name such as S3's `success_action_status` comes back as
315
+ * `successActionStatus` and the form no longer matches the signed policy.
316
+ */
295
317
  createCollectionImageUpload(
296
318
  slug: string,
297
319
  imageType: string,
@@ -301,6 +323,9 @@ export class WalletAuthAPI {
301
323
  return this.fetcher.request<OperationResponse<"upload_collection_image">>(
302
324
  "POST",
303
325
  `/api/v2/collections/${segment(slug)}/images/${segment(imageType)}?${query}`,
326
+ undefined,
327
+ undefined,
328
+ { camelizeResponse: false },
304
329
  )
305
330
  }
306
331
 
@@ -332,7 +357,8 @@ export class WalletAuthAPI {
332
357
  /**
333
358
  * `UploadProfileImageRequest` is camelCase on the wire (`imageType`,
334
359
  * `contentType`) and both are required, so snake-casing the body made this
335
- * call fail validation every time. Sent verbatim.
360
+ * call fail validation every time. Sent verbatim. The response is not
361
+ * camelized either, for the `UploadContext.fields` reason above.
336
362
  */
337
363
  createProfileImageUpload(body: WalletAuthRequest<"upload_profile_image">) {
338
364
  return this.fetcher.request<OperationResponse<"upload_profile_image">>(
@@ -340,7 +366,7 @@ export class WalletAuthAPI {
340
366
  "/api/v2/profile/images",
341
367
  body,
342
368
  undefined,
343
- { snakeizeBody: false },
369
+ { snakeizeBody: false, camelizeResponse: false },
344
370
  )
345
371
  }
346
372
 
package/src/types.ts CHANGED
@@ -297,18 +297,27 @@ export type OpenSeaAccount = Camelize<AccountResponse>
297
297
  export type SocialMediaAccount = Camelize<ApiSocialMediaAccount>
298
298
 
299
299
  /**
300
- * Enhanced Error type for rate limit errors that includes retry-after information
300
+ * Error thrown for any non-OK API response. `statusCode` is always set, so a caller can separate
301
+ * a retryable failure from a permanent one without parsing the message. That matters for clients
302
+ * that scrub remote error text before surfacing it, which have no other way to recover the status.
301
303
  * @category API Models
302
304
  */
303
- export interface OpenSeaRateLimitError extends Error {
305
+ export interface OpenSeaApiError extends Error {
304
306
  /** The HTTP status code of the error response */
305
307
  statusCode?: number
306
- /** The number of seconds to wait before retrying the request */
308
+ /** The number of seconds to wait before retrying the request, on rate limit responses */
307
309
  retryAfter?: number
308
310
  /** The response body from the API */
309
311
  responseBody?: unknown
310
312
  }
311
313
 
314
+ /**
315
+ * @deprecated Use {@link OpenSeaApiError}. Retained as an alias: the shape is identical and
316
+ * `retryAfter` was always optional, so existing rate-limit handling is unaffected.
317
+ * @category API Models
318
+ */
319
+ export type OpenSeaRateLimitError = OpenSeaApiError
320
+
312
321
  /**
313
322
  * Options for controlling HTTP request behavior.
314
323
  * @category API Models
@@ -23,6 +23,12 @@ const CUSTOM_RATE_LIMIT_STATUS_CODE = 599
23
23
  export interface RateLimitOptions {
24
24
  /** Logger function for logging progress */
25
25
  logger?: (message: string) => void
26
+ /**
27
+ * Abort signal that cancels a pending retry delay. The operation itself is
28
+ * responsible for its own cancellation; this only stops the wait between
29
+ * attempts so an aborted caller does not sit out the full `Retry-After`.
30
+ */
31
+ signal?: AbortSignal
26
32
  /** Maximum number of retry attempts for rate limit errors */
27
33
  maxRetries?: number
28
34
  /** Base delay in ms to wait after a rate limit error if retry-after header is not present */
@@ -30,11 +36,29 @@ export interface RateLimitOptions {
30
36
  }
31
37
 
32
38
  /**
33
- * Sleep for a specified duration
39
+ * Sleep for a specified duration, optionally cancellable.
34
40
  * @param ms Duration in milliseconds
41
+ * @param signal Optional signal that rejects the sleep early
35
42
  */
36
- function sleep(ms: number): Promise<void> {
37
- return new Promise(resolve => setTimeout(resolve, ms))
43
+ function sleep(ms: number, signal?: AbortSignal): Promise<void> {
44
+ if (!signal) {
45
+ return new Promise(resolve => setTimeout(resolve, ms))
46
+ }
47
+ if (signal.aborted) {
48
+ return Promise.reject(new Error("Request aborted"))
49
+ }
50
+
51
+ return new Promise((resolve, reject) => {
52
+ const onAbort = () => {
53
+ clearTimeout(timeoutId)
54
+ reject(new Error("Request aborted"))
55
+ }
56
+ const timeoutId = setTimeout(() => {
57
+ signal.removeEventListener("abort", onAbort)
58
+ resolve()
59
+ }, ms)
60
+ signal.addEventListener("abort", onAbort, { once: true })
61
+ })
38
62
  }
39
63
 
40
64
  /**
@@ -52,6 +76,7 @@ export async function executeWithRateLimit<T>(
52
76
  ): Promise<T> {
53
77
  const {
54
78
  logger = () => {},
79
+ signal,
55
80
  maxRetries = DEFAULT_MAX_RETRIES,
56
81
  baseRetryDelay = DEFAULT_BASE_RETRY_DELAY_MS,
57
82
  } = options
@@ -92,7 +117,7 @@ export async function executeWithRateLimit<T>(
92
117
  )
93
118
  }
94
119
 
95
- await sleep(delayMs)
120
+ await sleep(delayMs, signal)
96
121
  logger(`Retrying operation...`)
97
122
  }
98
123
  }