pinata 2.4.8 → 2.5.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/README.md CHANGED
@@ -113,3 +113,4 @@ Run Tests
113
113
  ```bash
114
114
  npm run test
115
115
  ```
116
+
package/dist/index.d.mts CHANGED
@@ -274,7 +274,7 @@ declare class AnalyticsFilter {
274
274
  limit(limit: number): this;
275
275
  sort(order: "asc" | "desc"): this;
276
276
  days(numberOfDays: number): this;
277
- then(onfulfilled?: ((value: TopAnalyticsResponse) => any) | null): Promise<any>;
277
+ then(onfulfilled?: ((value: TopAnalyticsResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
278
278
  }
279
279
 
280
280
  declare class AnalyticsBandwidth extends AnalyticsFilter {
@@ -301,7 +301,7 @@ declare class AnalyticsBuilder<T extends AnalyticsQuery, R> {
301
301
  limit(limit: number): this;
302
302
  sort(order: "asc" | "desc"): this;
303
303
  protected getAnalytics(): Promise<R>;
304
- then(onfulfilled?: ((value: R) => any) | null): Promise<any>;
304
+ then(onfulfilled?: ((value: R) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
305
305
  }
306
306
 
307
307
  declare class AnalyticsRequests extends AnalyticsFilter {
@@ -328,7 +328,7 @@ declare class FilterGroups {
328
328
  limit(limit: number): FilterGroups;
329
329
  isPublic(isPublic: boolean): FilterGroups;
330
330
  pageToken(pageToken: string): FilterGroups;
331
- then(onfulfilled?: ((value: GroupListResponse) => any) | null): Promise<GroupListResponse>;
331
+ then(onfulfilled?: ((value: GroupListResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<GroupListResponse>;
332
332
  private fetchPage;
333
333
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
334
334
  all(): Promise<GroupResponseItem[]>;
@@ -386,7 +386,7 @@ declare class FilterKeys {
386
386
  limitedUse(limitedUse: boolean): FilterKeys;
387
387
  exhausted(exhausted: boolean): FilterKeys;
388
388
  name(name: string): FilterKeys;
389
- then(onfulfilled?: ((value: KeyListItem[]) => any) | null): Promise<any>;
389
+ then(onfulfilled?: ((value: KeyListItem[]) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
390
390
  [Symbol.asyncIterator](): AsyncGenerator<KeyListItem, void, unknown>;
391
391
  all(): Promise<KeyListItem[]>;
392
392
  }
@@ -405,7 +405,7 @@ declare class OptimizeImageCreateAccessLink {
405
405
  private imgOpts;
406
406
  constructor(config: PinataConfig | undefined, urlOpts: AccessLinkOptions);
407
407
  optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateAccessLink;
408
- then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
408
+ then(onfulfilled?: ((value: string) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
409
409
  }
410
410
 
411
411
  declare class OptimizeImageGetCid {
@@ -415,7 +415,7 @@ declare class OptimizeImageGetCid {
415
415
  private options;
416
416
  constructor(config: PinataConfig | undefined, cid: string, gatewayType?: "ipfs" | "files");
417
417
  optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
418
- then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
418
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
419
419
  }
420
420
 
421
421
  declare class PrivateGateways {
@@ -448,7 +448,7 @@ declare class FilterFiles {
448
448
  keyvalues(keyvalues: Record<string, string>): FilterFiles;
449
449
  noGroup(noGroup: boolean): FilterFiles;
450
450
  pageToken(pageToken: string): FilterFiles;
451
- then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
451
+ then(onfulfilled?: ((value: FileListResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
452
452
  private fetchPage;
453
453
  [Symbol.asyncIterator](): AsyncGenerator<FileListItem, void, unknown>;
454
454
  all(): Promise<FileListItem[]>;
@@ -469,7 +469,7 @@ declare class FilterQueue {
469
469
  pageToken(pageToken: string): FilterQueue;
470
470
  private fetchPage;
471
471
  sort(sort: "ASC" | "DSC"): FilterQueue;
472
- then(onfulfilled?: ((value: PinQueueResponse) => any) | null): Promise<any>;
472
+ then(onfulfilled?: ((value: PinQueueResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
473
473
  private rateLimit;
474
474
  [Symbol.asyncIterator](): AsyncGenerator<PinQueueItem, void, unknown>;
475
475
  all(): Promise<PinQueueItem[]>;
package/dist/index.d.ts CHANGED
@@ -274,7 +274,7 @@ declare class AnalyticsFilter {
274
274
  limit(limit: number): this;
275
275
  sort(order: "asc" | "desc"): this;
276
276
  days(numberOfDays: number): this;
277
- then(onfulfilled?: ((value: TopAnalyticsResponse) => any) | null): Promise<any>;
277
+ then(onfulfilled?: ((value: TopAnalyticsResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
278
278
  }
279
279
 
280
280
  declare class AnalyticsBandwidth extends AnalyticsFilter {
@@ -301,7 +301,7 @@ declare class AnalyticsBuilder<T extends AnalyticsQuery, R> {
301
301
  limit(limit: number): this;
302
302
  sort(order: "asc" | "desc"): this;
303
303
  protected getAnalytics(): Promise<R>;
304
- then(onfulfilled?: ((value: R) => any) | null): Promise<any>;
304
+ then(onfulfilled?: ((value: R) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
305
305
  }
306
306
 
307
307
  declare class AnalyticsRequests extends AnalyticsFilter {
@@ -328,7 +328,7 @@ declare class FilterGroups {
328
328
  limit(limit: number): FilterGroups;
329
329
  isPublic(isPublic: boolean): FilterGroups;
330
330
  pageToken(pageToken: string): FilterGroups;
331
- then(onfulfilled?: ((value: GroupListResponse) => any) | null): Promise<GroupListResponse>;
331
+ then(onfulfilled?: ((value: GroupListResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<GroupListResponse>;
332
332
  private fetchPage;
333
333
  [Symbol.asyncIterator](): AsyncGenerator<GroupResponseItem, void, unknown>;
334
334
  all(): Promise<GroupResponseItem[]>;
@@ -386,7 +386,7 @@ declare class FilterKeys {
386
386
  limitedUse(limitedUse: boolean): FilterKeys;
387
387
  exhausted(exhausted: boolean): FilterKeys;
388
388
  name(name: string): FilterKeys;
389
- then(onfulfilled?: ((value: KeyListItem[]) => any) | null): Promise<any>;
389
+ then(onfulfilled?: ((value: KeyListItem[]) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
390
390
  [Symbol.asyncIterator](): AsyncGenerator<KeyListItem, void, unknown>;
391
391
  all(): Promise<KeyListItem[]>;
392
392
  }
@@ -405,7 +405,7 @@ declare class OptimizeImageCreateAccessLink {
405
405
  private imgOpts;
406
406
  constructor(config: PinataConfig | undefined, urlOpts: AccessLinkOptions);
407
407
  optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateAccessLink;
408
- then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
408
+ then(onfulfilled?: ((value: string) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
409
409
  }
410
410
 
411
411
  declare class OptimizeImageGetCid {
@@ -415,7 +415,7 @@ declare class OptimizeImageGetCid {
415
415
  private options;
416
416
  constructor(config: PinataConfig | undefined, cid: string, gatewayType?: "ipfs" | "files");
417
417
  optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
418
- then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
418
+ then(onfulfilled?: ((value: GetCIDResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
419
419
  }
420
420
 
421
421
  declare class PrivateGateways {
@@ -448,7 +448,7 @@ declare class FilterFiles {
448
448
  keyvalues(keyvalues: Record<string, string>): FilterFiles;
449
449
  noGroup(noGroup: boolean): FilterFiles;
450
450
  pageToken(pageToken: string): FilterFiles;
451
- then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
451
+ then(onfulfilled?: ((value: FileListResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
452
452
  private fetchPage;
453
453
  [Symbol.asyncIterator](): AsyncGenerator<FileListItem, void, unknown>;
454
454
  all(): Promise<FileListItem[]>;
@@ -469,7 +469,7 @@ declare class FilterQueue {
469
469
  pageToken(pageToken: string): FilterQueue;
470
470
  private fetchPage;
471
471
  sort(sort: "ASC" | "DSC"): FilterQueue;
472
- then(onfulfilled?: ((value: PinQueueResponse) => any) | null): Promise<any>;
472
+ then(onfulfilled?: ((value: PinQueueResponse) => any) | null, onrejected?: ((reason: any) => any) | null): Promise<any>;
473
473
  private rateLimit;
474
474
  [Symbol.asyncIterator](): AsyncGenerator<PinQueueItem, void, unknown>;
475
475
  all(): Promise<PinQueueItem[]>;
package/dist/index.js CHANGED
@@ -2458,49 +2458,77 @@ var createSignedUploadURL = async (config, options, network) => {
2458
2458
  Source: "sdk/createSignURL"
2459
2459
  };
2460
2460
  }
2461
- try {
2462
- const request = await fetch(`${endpoint}/files/sign`, {
2463
- method: "POST",
2464
- headers,
2465
- cache: "no-store",
2466
- body: JSON.stringify(payload)
2467
- });
2468
- if (!request.ok) {
2469
- const errorData = await request.text();
2470
- if (request.status === 401 || request.status === 403) {
2471
- throw new chunkBK3CLF3Z_js.AuthenticationError(
2472
- `Authentication Failed: ${errorData}`,
2461
+ let retryCount = 0;
2462
+ const maxRetries = 3;
2463
+ while (retryCount <= maxRetries) {
2464
+ try {
2465
+ const request = await fetch(`${endpoint}/files/sign`, {
2466
+ method: "POST",
2467
+ headers,
2468
+ cache: "no-store",
2469
+ body: JSON.stringify(payload)
2470
+ });
2471
+ if (!request.ok) {
2472
+ const errorData = await request.text();
2473
+ if (request.status === 401 || request.status === 403) {
2474
+ throw new chunkBK3CLF3Z_js.AuthenticationError(
2475
+ `Authentication Failed: ${errorData}`,
2476
+ request.status,
2477
+ {
2478
+ error: errorData,
2479
+ code: "AUTH_ERROR",
2480
+ metadata: {
2481
+ requestUrl: request.url
2482
+ }
2483
+ }
2484
+ );
2485
+ }
2486
+ const error = new chunkBK3CLF3Z_js.NetworkError(
2487
+ `HTTP error: ${errorData}`,
2473
2488
  request.status,
2474
2489
  {
2475
2490
  error: errorData,
2476
- code: "AUTH_ERROR",
2491
+ code: "HTTP_ERROR",
2477
2492
  metadata: {
2478
2493
  requestUrl: request.url
2479
2494
  }
2480
2495
  }
2481
2496
  );
2497
+ if (request.status >= 400 && request.status < 500 && request.status !== 429) {
2498
+ throw error;
2499
+ }
2500
+ throw error;
2482
2501
  }
2483
- throw new chunkBK3CLF3Z_js.NetworkError(`HTTP error: ${errorData}`, request.status, {
2484
- error: errorData,
2485
- code: "HTTP_ERROR",
2486
- metadata: {
2487
- requestUrl: request.url
2502
+ const res = await request.json();
2503
+ return res.data;
2504
+ } catch (error) {
2505
+ if (error instanceof chunkBK3CLF3Z_js.AuthenticationError) {
2506
+ throw error;
2507
+ }
2508
+ if (error instanceof chunkBK3CLF3Z_js.NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
2509
+ throw error;
2510
+ }
2511
+ retryCount++;
2512
+ if (retryCount > maxRetries) {
2513
+ if (error instanceof chunkBK3CLF3Z_js.PinataError) {
2514
+ throw error;
2488
2515
  }
2489
- });
2490
- }
2491
- const res = await request.json();
2492
- return res.data;
2493
- } catch (error) {
2494
- if (error instanceof chunkBK3CLF3Z_js.PinataError) {
2495
- throw error;
2496
- }
2497
- if (error instanceof Error) {
2498
- throw new chunkBK3CLF3Z_js.PinataError(
2499
- `Error processing createSignedURL: ${error.message}`
2500
- );
2516
+ if (error instanceof Error) {
2517
+ throw new chunkBK3CLF3Z_js.PinataError(
2518
+ `Error processing createSignedURL after ${maxRetries} retries: ${error.message}`
2519
+ );
2520
+ }
2521
+ throw new chunkBK3CLF3Z_js.PinataError(
2522
+ `An unknown error occurred while getting signed url after ${maxRetries} retries`
2523
+ );
2524
+ }
2525
+ const delay = Math.min(1e3 * Math.pow(2, retryCount - 1), 4e3);
2526
+ await new Promise((resolve) => setTimeout(resolve, delay));
2501
2527
  }
2502
- throw new chunkBK3CLF3Z_js.PinataError("An unknown error occurred while getting signed url");
2503
2528
  }
2529
+ return Promise.reject(
2530
+ new chunkBK3CLF3Z_js.PinataError("Unexpected error: retry loop completed without resolution")
2531
+ );
2504
2532
  };
2505
2533
 
2506
2534
  // src/core/functions/uploads/file.ts
@@ -3419,8 +3447,11 @@ var AnalyticsFilter = class {
3419
3447
  this.query.end_date = end;
3420
3448
  return this;
3421
3449
  }
3422
- then(onfulfilled) {
3423
- return analyticsTopUsage(this.config, this.query).then(onfulfilled);
3450
+ then(onfulfilled, onrejected) {
3451
+ return analyticsTopUsage(this.config, this.query).then(
3452
+ onfulfilled,
3453
+ onrejected
3454
+ );
3424
3455
  }
3425
3456
  };
3426
3457
 
@@ -3502,8 +3533,8 @@ var AnalyticsBuilder = class {
3502
3533
  async getAnalytics() {
3503
3534
  throw new Error("getAnalytics method must be implemented in derived class");
3504
3535
  }
3505
- then(onfulfilled) {
3506
- return this.getAnalytics().then(onfulfilled);
3536
+ then(onfulfilled, onrejected) {
3537
+ return this.getAnalytics().then(onfulfilled, onrejected);
3507
3538
  }
3508
3539
  };
3509
3540
 
@@ -3572,11 +3603,11 @@ var FilterGroups = class {
3572
3603
  this.query.pageToken = pageToken;
3573
3604
  return this;
3574
3605
  }
3575
- then(onfulfilled) {
3606
+ then(onfulfilled, onrejected) {
3576
3607
  return this.fetchPage().then((response) => {
3577
3608
  this.nextPageToken = response.next_page_token;
3578
3609
  return response;
3579
- }).then(onfulfilled);
3610
+ }).then(onfulfilled, onrejected);
3580
3611
  }
3581
3612
  async fetchPage() {
3582
3613
  if (this.nextPageToken) {
@@ -3743,8 +3774,8 @@ var FilterKeys = class {
3743
3774
  this.query.name = name;
3744
3775
  return this;
3745
3776
  }
3746
- then(onfulfilled) {
3747
- return listKeys(this.config, this.query).then(onfulfilled);
3777
+ then(onfulfilled, onrejected) {
3778
+ return listKeys(this.config, this.query).then(onfulfilled, onrejected);
3748
3779
  }
3749
3780
  // private async rateLimit(): Promise<void> {
3750
3781
  // this.requestCount++;
@@ -3807,9 +3838,10 @@ var OptimizeImageCreateAccessLink = class {
3807
3838
  this.imgOpts = { ...this.imgOpts, ...options };
3808
3839
  return this;
3809
3840
  }
3810
- then(onfulfilled) {
3841
+ then(onfulfilled, onrejected) {
3811
3842
  return createAccessLink(this.config, this.urlOpts, this.imgOpts).then(
3812
- onfulfilled
3843
+ onfulfilled,
3844
+ onrejected
3813
3845
  );
3814
3846
  }
3815
3847
  };
@@ -3826,9 +3858,10 @@ var OptimizeImageGetCid = class {
3826
3858
  this.options = { ...this.options, ...options };
3827
3859
  return this;
3828
3860
  }
3829
- then(onfulfilled) {
3861
+ then(onfulfilled, onrejected) {
3830
3862
  return getCid(this.config, this.cid, this.gatewayType, this.options).then(
3831
- onfulfilled
3863
+ onfulfilled,
3864
+ onrejected
3832
3865
  );
3833
3866
  }
3834
3867
  };
@@ -3978,8 +4011,8 @@ var FilterFiles = class {
3978
4011
  this.query.pageToken = pageToken;
3979
4012
  return this;
3980
4013
  }
3981
- then(onfulfilled) {
3982
- return this.fetchPage().then(onfulfilled);
4014
+ then(onfulfilled, onrejected) {
4015
+ return this.fetchPage().then(onfulfilled, onrejected);
3983
4016
  }
3984
4017
  async fetchPage() {
3985
4018
  if (this.currentPageToken) {
@@ -4062,8 +4095,8 @@ var FilterQueue = class {
4062
4095
  this.query.sort = sort;
4063
4096
  return this;
4064
4097
  }
4065
- then(onfulfilled) {
4066
- return queue(this.config, this.query).then(onfulfilled);
4098
+ then(onfulfilled, onrejected) {
4099
+ return queue(this.config, this.query).then(onfulfilled, onrejected);
4067
4100
  }
4068
4101
  // rate limit, hopefully temporary?
4069
4102
  async rateLimit() {