pinata 2.4.9 → 2.5.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.
package/LICENSE CHANGED
File without changes
package/README.md CHANGED
File without changes
@@ -156,6 +156,7 @@ type UploadOptions = {
156
156
  url?: string;
157
157
  streamable?: boolean;
158
158
  peerAddresses?: string[];
159
+ car?: boolean;
159
160
  };
160
161
  type SignedUploadUrlOptions = {
161
162
  date?: number;
@@ -167,6 +168,7 @@ type SignedUploadUrlOptions = {
167
168
  maxFileSize?: number;
168
169
  mimeTypes?: string[];
169
170
  streamable?: boolean;
171
+ car?: boolean;
170
172
  };
171
173
  type UploadCIDOptions = {
172
174
  metadata?: PinataMetadata;
@@ -156,6 +156,7 @@ type UploadOptions = {
156
156
  url?: string;
157
157
  streamable?: boolean;
158
158
  peerAddresses?: string[];
159
+ car?: boolean;
159
160
  };
160
161
  type SignedUploadUrlOptions = {
161
162
  date?: number;
@@ -167,6 +168,7 @@ type SignedUploadUrlOptions = {
167
168
  maxFileSize?: number;
168
169
  mimeTypes?: string[];
169
170
  streamable?: boolean;
171
+ car?: boolean;
170
172
  };
171
173
  type UploadCIDOptions = {
172
174
  metadata?: PinataMetadata;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-l9hk7kz4.mjs';
2
- export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-l9hk7kz4.mjs';
1
+ import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-Cd7xutmh.mjs';
2
+ export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-Cd7xutmh.mjs';
3
3
 
4
4
  type PinataConfig = {
5
5
  pinataJwt?: string;
@@ -523,6 +523,7 @@ declare class UploadBuilder<T> {
523
523
  private uploadUrl;
524
524
  private isStreamable;
525
525
  private peerAddresses;
526
+ private carFormat;
526
527
  constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
527
528
  name(name: string): UploadBuilder<T>;
528
529
  keyvalues(keyvalues: Record<string, string>): UploadBuilder<T>;
@@ -531,6 +532,7 @@ declare class UploadBuilder<T> {
531
532
  url(url: string): UploadBuilder<T>;
532
533
  group(groupId: string): UploadBuilder<T>;
533
534
  streamable(): UploadBuilder<T>;
535
+ car(): UploadBuilder<T>;
534
536
  peerAddress(peerAddresses: string[]): UploadBuilder<T>;
535
537
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
536
538
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-l9hk7kz4.js';
2
- export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-l9hk7kz4.js';
1
+ import { D as DeleteResponse, V as VectorizeFileResponse, F as FileListQuery, a as FileListResponse, S as SwapCidOptions, b as SwapCidResponse, c as SwapHistoryOptions, U as UpdateFileOptions, d as FileListItem, e as VectorizeQuery, f as VectorizeQueryResponse, G as GetCIDResponse, P as PinQueueQuery, g as PinQueueResponse, O as OptimizeImageOptions, A as AccessLinkOptions, h as UploadOptions, i as UploadResponse, j as SignedUploadUrlOptions, J as JsonBody, k as UploadCIDOptions, l as PinByCIDResponse, m as PinQueueItem } from './gateway-tools-Cd7xutmh.js';
2
+ export { s as AuthenticationError, q as ContainsCIDResponse, C as ContentType, n as FileObject, N as NetworkError, r as PinataError, o as PinataMetadata, t as ValidationError, p as VectorQueryMatch, u as containsCID, v as convertToDesiredGateway } from './gateway-tools-Cd7xutmh.js';
3
3
 
4
4
  type PinataConfig = {
5
5
  pinataJwt?: string;
@@ -523,6 +523,7 @@ declare class UploadBuilder<T> {
523
523
  private uploadUrl;
524
524
  private isStreamable;
525
525
  private peerAddresses;
526
+ private carFormat;
526
527
  constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
527
528
  name(name: string): UploadBuilder<T>;
528
529
  keyvalues(keyvalues: Record<string, string>): UploadBuilder<T>;
@@ -531,6 +532,7 @@ declare class UploadBuilder<T> {
531
532
  url(url: string): UploadBuilder<T>;
532
533
  group(groupId: string): UploadBuilder<T>;
533
534
  streamable(): UploadBuilder<T>;
535
+ car(): UploadBuilder<T>;
534
536
  peerAddress(peerAddresses: string[]): UploadBuilder<T>;
535
537
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
536
538
  }
package/dist/index.js CHANGED
@@ -2458,49 +2458,65 @@ 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}`,
2473
- request.status,
2474
- {
2475
- error: errorData,
2476
- code: "AUTH_ERROR",
2477
- metadata: {
2478
- requestUrl: request.url
2461
+ const maxRetries = 3;
2462
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
2463
+ try {
2464
+ const request = await fetch(`${endpoint}/files/sign`, {
2465
+ method: "POST",
2466
+ headers,
2467
+ cache: "no-store",
2468
+ body: JSON.stringify(payload)
2469
+ });
2470
+ if (!request.ok) {
2471
+ const errorData = await request.text();
2472
+ if (request.status === 401 || request.status === 403) {
2473
+ throw new chunkBK3CLF3Z_js.AuthenticationError(
2474
+ `Authentication Failed: ${errorData}`,
2475
+ request.status,
2476
+ {
2477
+ error: errorData,
2478
+ code: "AUTH_ERROR",
2479
+ metadata: {
2480
+ requestUrl: request.url
2481
+ }
2479
2482
  }
2483
+ );
2484
+ }
2485
+ throw new chunkBK3CLF3Z_js.NetworkError(`HTTP error: ${errorData}`, request.status, {
2486
+ error: errorData,
2487
+ code: "HTTP_ERROR",
2488
+ metadata: {
2489
+ requestUrl: request.url
2480
2490
  }
2481
- );
2491
+ });
2482
2492
  }
2483
- throw new chunkBK3CLF3Z_js.NetworkError(`HTTP error: ${errorData}`, request.status, {
2484
- error: errorData,
2485
- code: "HTTP_ERROR",
2486
- metadata: {
2487
- requestUrl: request.url
2493
+ const res = await request.json();
2494
+ return res.data;
2495
+ } catch (error) {
2496
+ if (error instanceof chunkBK3CLF3Z_js.AuthenticationError) {
2497
+ throw error;
2498
+ }
2499
+ if (error instanceof chunkBK3CLF3Z_js.NetworkError && error.statusCode && error.statusCode >= 400 && error.statusCode < 500 && error.statusCode !== 429) {
2500
+ throw error;
2501
+ }
2502
+ if (attempt === maxRetries) {
2503
+ if (error instanceof chunkBK3CLF3Z_js.PinataError) {
2504
+ throw error;
2488
2505
  }
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
- );
2506
+ if (error instanceof Error) {
2507
+ throw new chunkBK3CLF3Z_js.PinataError(
2508
+ `Error processing createSignedURL: ${error.message}`
2509
+ );
2510
+ }
2511
+ throw new chunkBK3CLF3Z_js.PinataError(
2512
+ "An unknown error occurred while getting signed url"
2513
+ );
2514
+ }
2515
+ const delay = Math.min(1e3 * Math.pow(2, attempt), 4e3);
2516
+ await new Promise((resolve) => setTimeout(resolve, delay));
2501
2517
  }
2502
- throw new chunkBK3CLF3Z_js.PinataError("An unknown error occurred while getting signed url");
2503
2518
  }
2519
+ throw new chunkBK3CLF3Z_js.PinataError("An unknown error occurred while getting signed url");
2504
2520
  };
2505
2521
 
2506
2522
  // src/core/functions/uploads/file.ts
@@ -2537,6 +2553,9 @@ var uploadFile = async (config, file, network, options) => {
2537
2553
  if (options?.streamable) {
2538
2554
  metadata += `,streamable ${btoa("true")}`;
2539
2555
  }
2556
+ if (options?.car) {
2557
+ metadata += `,car ${btoa("true")}`;
2558
+ }
2540
2559
  let updatedEndpoint = `${endpoint}/files`;
2541
2560
  if (options?.url) {
2542
2561
  updatedEndpoint = options.url;
@@ -2700,6 +2719,9 @@ var uploadFile = async (config, file, network, options) => {
2700
2719
  if (options?.streamable) {
2701
2720
  data.append("streamable", "true");
2702
2721
  }
2722
+ if (options?.car) {
2723
+ data.append("car", "true");
2724
+ }
2703
2725
  if (options?.url) {
2704
2726
  try {
2705
2727
  const request = await fetch(options.url, {
@@ -4234,6 +4256,10 @@ var UploadBuilder = class {
4234
4256
  this.isStreamable = true;
4235
4257
  return this;
4236
4258
  }
4259
+ car() {
4260
+ this.carFormat = true;
4261
+ return this;
4262
+ }
4237
4263
  peerAddress(peerAddresses) {
4238
4264
  this.peerAddresses = peerAddresses;
4239
4265
  return this;
@@ -4261,6 +4287,9 @@ var UploadBuilder = class {
4261
4287
  if (this.peerAddresses) {
4262
4288
  options.peerAddresses = this.peerAddresses;
4263
4289
  }
4290
+ if (this.carFormat) {
4291
+ options.car = this.carFormat;
4292
+ }
4264
4293
  this.args[this.args.length - 1] = options;
4265
4294
  return this.uploadFunction(this.config, ...this.args).then(
4266
4295
  onfulfilled,