pinata 1.9.1 → 1.10.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/dist/index.d.mts CHANGED
@@ -44,6 +44,7 @@ type UploadOptions = {
44
44
  keys?: string;
45
45
  groupId?: string;
46
46
  vectorize?: boolean;
47
+ url?: string;
47
48
  };
48
49
  type DeleteResponse = {
49
50
  id: string;
@@ -316,6 +317,14 @@ type VectorizeQueryResponse = {
316
317
  count: number;
317
318
  matches: VectorQueryMatch[];
318
319
  };
320
+ type SignedUploadUrlOptions = {
321
+ date?: number;
322
+ expires: number;
323
+ groupId?: string;
324
+ name?: string;
325
+ keyvalues?: Record<string, string>;
326
+ vectorize?: boolean;
327
+ };
319
328
 
320
329
  declare class PinataSDK {
321
330
  config: PinataConfig | undefined;
@@ -352,10 +361,12 @@ declare class UploadBuilder<T> {
352
361
  private keys;
353
362
  private groupId;
354
363
  private vector;
364
+ private uploadUrl;
355
365
  constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
356
366
  addMetadata(metadata: PinataMetadata): UploadBuilder<T>;
357
367
  key(jwt: string): UploadBuilder<T>;
358
368
  vectorize(): UploadBuilder<T>;
369
+ url(url: string): UploadBuilder<T>;
359
370
  group(groupId: string): UploadBuilder<T>;
360
371
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
361
372
  }
@@ -367,6 +378,7 @@ declare class Upload {
367
378
  base64(base64String: string, options?: UploadOptions): UploadBuilder<UploadResponse>;
368
379
  url(url: string, options?: UploadOptions): UploadBuilder<UploadResponse>;
369
380
  json(data: object, options?: UploadOptions): UploadBuilder<UploadResponse>;
381
+ createSignedURL(options: SignedUploadUrlOptions): Promise<string>;
370
382
  }
371
383
  declare class FilterFiles {
372
384
  private config;
@@ -524,4 +536,4 @@ declare class TimeIntervalAnalyticsBuilder extends AnalyticsBuilder<TimeInterval
524
536
  all(): Promise<TimeIntervalAnalyticsResponse>;
525
537
  }
526
538
 
527
- export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
539
+ export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUploadUrlOptions, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ type UploadOptions = {
44
44
  keys?: string;
45
45
  groupId?: string;
46
46
  vectorize?: boolean;
47
+ url?: string;
47
48
  };
48
49
  type DeleteResponse = {
49
50
  id: string;
@@ -316,6 +317,14 @@ type VectorizeQueryResponse = {
316
317
  count: number;
317
318
  matches: VectorQueryMatch[];
318
319
  };
320
+ type SignedUploadUrlOptions = {
321
+ date?: number;
322
+ expires: number;
323
+ groupId?: string;
324
+ name?: string;
325
+ keyvalues?: Record<string, string>;
326
+ vectorize?: boolean;
327
+ };
319
328
 
320
329
  declare class PinataSDK {
321
330
  config: PinataConfig | undefined;
@@ -352,10 +361,12 @@ declare class UploadBuilder<T> {
352
361
  private keys;
353
362
  private groupId;
354
363
  private vector;
364
+ private uploadUrl;
355
365
  constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
356
366
  addMetadata(metadata: PinataMetadata): UploadBuilder<T>;
357
367
  key(jwt: string): UploadBuilder<T>;
358
368
  vectorize(): UploadBuilder<T>;
369
+ url(url: string): UploadBuilder<T>;
359
370
  group(groupId: string): UploadBuilder<T>;
360
371
  then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
361
372
  }
@@ -367,6 +378,7 @@ declare class Upload {
367
378
  base64(base64String: string, options?: UploadOptions): UploadBuilder<UploadResponse>;
368
379
  url(url: string, options?: UploadOptions): UploadBuilder<UploadResponse>;
369
380
  json(data: object, options?: UploadOptions): UploadBuilder<UploadResponse>;
381
+ createSignedURL(options: SignedUploadUrlOptions): Promise<string>;
370
382
  }
371
383
  declare class FilterFiles {
372
384
  private config;
@@ -524,4 +536,4 @@ declare class TimeIntervalAnalyticsBuilder extends AnalyticsBuilder<TimeInterval
524
536
  all(): Promise<TimeIntervalAnalyticsResponse>;
525
537
  }
526
538
 
527
- export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
539
+ export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUploadUrlOptions, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
package/dist/index.js CHANGED
@@ -150,7 +150,11 @@ var uploadFile = async (config, file, options) => {
150
150
  if (options?.metadata?.keyvalues) {
151
151
  metadata + `,keyvalues ${btoa(JSON.stringify(options.metadata.keyvalues))}`;
152
152
  }
153
- const urlReq = await fetch(`${endpoint}/files`, {
153
+ let updatedEndpoint = `${endpoint}/files`;
154
+ if (options?.url) {
155
+ updatedEndpoint = options.url;
156
+ }
157
+ const urlReq = await fetch(updatedEndpoint, {
154
158
  method: "POST",
155
159
  headers: {
156
160
  "Upload-Length": `${file.size}`,
@@ -242,6 +246,43 @@ var uploadFile = async (config, file, options) => {
242
246
  }
243
247
  const data = new FormData();
244
248
  data.append("file", file, file.name);
249
+ if (options?.url) {
250
+ try {
251
+ const request = await fetch(options.url, {
252
+ method: "POST",
253
+ headers,
254
+ body: data
255
+ });
256
+ if (!request.ok) {
257
+ const errorData = await request.text();
258
+ if (request.status === 401 || request.status === 403) {
259
+ throw new AuthenticationError(
260
+ `Authentication failed: ${errorData}`,
261
+ request.status,
262
+ errorData
263
+ );
264
+ }
265
+ throw new NetworkError(
266
+ `HTTP error: ${errorData}`,
267
+ request.status,
268
+ errorData
269
+ );
270
+ }
271
+ const res = await request.json();
272
+ const resData = res.data;
273
+ return resData;
274
+ } catch (error) {
275
+ if (error instanceof PinataError) {
276
+ throw error;
277
+ }
278
+ if (error instanceof Error) {
279
+ throw new PinataError(`Error processing base64: ${error.message}`);
280
+ }
281
+ throw new PinataError(
282
+ "An unknown error occurred while trying to upload base64"
283
+ );
284
+ }
285
+ }
245
286
  data.append("name", options?.metadata?.name || file.name || "File from SDK");
246
287
  if (options?.groupId) {
247
288
  data.append("group_id", options.groupId);
@@ -340,6 +381,42 @@ var uploadBase64 = async (config, base64String, options) => {
340
381
  if (config.uploadUrl) {
341
382
  endpoint = config.uploadUrl;
342
383
  }
384
+ if (options?.url) {
385
+ try {
386
+ const request = await fetch(options.url, {
387
+ method: "POST",
388
+ body: data
389
+ });
390
+ if (!request.ok) {
391
+ const errorData = await request.text();
392
+ if (request.status === 401 || request.status === 403) {
393
+ throw new AuthenticationError(
394
+ `Authentication failed: ${errorData}`,
395
+ request.status,
396
+ errorData
397
+ );
398
+ }
399
+ throw new NetworkError(
400
+ `HTTP error: ${errorData}`,
401
+ request.status,
402
+ errorData
403
+ );
404
+ }
405
+ const res = await request.json();
406
+ const resData = res.data;
407
+ return resData;
408
+ } catch (error) {
409
+ if (error instanceof PinataError) {
410
+ throw error;
411
+ }
412
+ if (error instanceof Error) {
413
+ throw new PinataError(`Error processing base64: ${error.message}`);
414
+ }
415
+ throw new PinataError(
416
+ "An unknown error occurred while trying to upload base64"
417
+ );
418
+ }
419
+ }
343
420
  try {
344
421
  const request = await fetch(`${endpoint}/files`, {
345
422
  method: "POST",
@@ -443,6 +520,42 @@ var uploadUrl = async (config, url, options) => {
443
520
  if (config.uploadUrl) {
444
521
  endpoint = config.uploadUrl;
445
522
  }
523
+ if (options?.url) {
524
+ try {
525
+ const request = await fetch(options.url, {
526
+ method: "POST",
527
+ body: data
528
+ });
529
+ if (!request.ok) {
530
+ const errorData = await request.text();
531
+ if (request.status === 401 || request.status === 403) {
532
+ throw new AuthenticationError(
533
+ `Authentication failed: ${errorData}`,
534
+ request.status,
535
+ errorData
536
+ );
537
+ }
538
+ throw new NetworkError(
539
+ `HTTP error: ${errorData}`,
540
+ request.status,
541
+ errorData
542
+ );
543
+ }
544
+ const res = await request.json();
545
+ const resData = res.data;
546
+ return resData;
547
+ } catch (error) {
548
+ if (error instanceof PinataError) {
549
+ throw error;
550
+ }
551
+ if (error instanceof Error) {
552
+ throw new PinataError(`Error processing base64: ${error.message}`);
553
+ }
554
+ throw new PinataError(
555
+ "An unknown error occurred while trying to upload base64"
556
+ );
557
+ }
558
+ }
446
559
  try {
447
560
  const request = await fetch(`${endpoint}/files`, {
448
561
  method: "POST",
@@ -534,6 +647,42 @@ var uploadJson = async (config, jsonData, options) => {
534
647
  if (config.uploadUrl) {
535
648
  endpoint = config.uploadUrl;
536
649
  }
650
+ if (options?.url) {
651
+ try {
652
+ const request = await fetch(options.url, {
653
+ method: "POST",
654
+ body: data
655
+ });
656
+ if (!request.ok) {
657
+ const errorData = await request.text();
658
+ if (request.status === 401 || request.status === 403) {
659
+ throw new AuthenticationError(
660
+ `Authentication failed: ${errorData}`,
661
+ request.status,
662
+ errorData
663
+ );
664
+ }
665
+ throw new NetworkError(
666
+ `HTTP error: ${errorData}`,
667
+ request.status,
668
+ errorData
669
+ );
670
+ }
671
+ const res = await request.json();
672
+ const resData = res.data;
673
+ return resData;
674
+ } catch (error) {
675
+ if (error instanceof PinataError) {
676
+ throw error;
677
+ }
678
+ if (error instanceof Error) {
679
+ throw new PinataError(`Error processing base64: ${error.message}`);
680
+ }
681
+ throw new PinataError(
682
+ "An unknown error occurred while trying to upload base64"
683
+ );
684
+ }
685
+ }
537
686
  try {
538
687
  const request = await fetch(`${endpoint}/files`, {
539
688
  method: "POST",
@@ -2310,6 +2459,79 @@ var deleteFileVectors = async (config, fileId) => {
2310
2459
  }
2311
2460
  };
2312
2461
 
2462
+ // src/core/uploads/createSignedUploadURL.ts
2463
+ var createSignedUploadURL = async (config, options) => {
2464
+ if (!config) {
2465
+ throw new ValidationError("Pinata configuration is missing");
2466
+ }
2467
+ const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
2468
+ const payload = {
2469
+ date,
2470
+ expires: options.expires
2471
+ };
2472
+ if (options.groupId) {
2473
+ payload.group_id = options.groupId;
2474
+ }
2475
+ if (options.name) {
2476
+ payload.filename = options.name;
2477
+ }
2478
+ if (options.keyvalues) {
2479
+ payload.keyvalues = options.keyvalues;
2480
+ }
2481
+ let endpoint = "https://uploads.pinata.cloud/v3";
2482
+ if (config.uploadUrl) {
2483
+ endpoint = config.uploadUrl;
2484
+ }
2485
+ let headers;
2486
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2487
+ headers = {
2488
+ Authorization: `Bearer ${config.pinataJwt}`,
2489
+ "Content-Type": "application/json",
2490
+ ...config.customHeaders
2491
+ };
2492
+ } else {
2493
+ headers = {
2494
+ "Content-Type": "application/json",
2495
+ Authorization: `Bearer ${config.pinataJwt}`,
2496
+ Source: "sdk/createSignURL"
2497
+ };
2498
+ }
2499
+ try {
2500
+ const request = await fetch(`${endpoint}/files/sign`, {
2501
+ method: "POST",
2502
+ headers,
2503
+ body: JSON.stringify(payload)
2504
+ });
2505
+ if (!request.ok) {
2506
+ const errorData = await request.text();
2507
+ if (request.status === 401 || request.status === 403) {
2508
+ throw new AuthenticationError(
2509
+ `Authentication Failed: ${errorData}`,
2510
+ request.status,
2511
+ errorData
2512
+ );
2513
+ }
2514
+ throw new NetworkError(
2515
+ `HTTP error: ${errorData}`,
2516
+ request.status,
2517
+ errorData
2518
+ );
2519
+ }
2520
+ const res = await request.json();
2521
+ return res.data;
2522
+ } catch (error) {
2523
+ if (error instanceof PinataError) {
2524
+ throw error;
2525
+ }
2526
+ if (error instanceof Error) {
2527
+ throw new PinataError(
2528
+ `Error processing createSignedURL: ${error.message}`
2529
+ );
2530
+ }
2531
+ throw new PinataError("An unknown error occurred while getting signed url");
2532
+ }
2533
+ };
2534
+
2313
2535
  // src/core/pinataSDK.ts
2314
2536
  var formatConfig = (config) => {
2315
2537
  let gateway = config?.pinataGateway;
@@ -2413,6 +2635,10 @@ var UploadBuilder = class {
2413
2635
  this.vector = true;
2414
2636
  return this;
2415
2637
  }
2638
+ url(url) {
2639
+ this.uploadUrl = url;
2640
+ return this;
2641
+ }
2416
2642
  // cidVersion(v: 0 | 1): UploadBuilder<T> {
2417
2643
  // this.version = v;
2418
2644
  // return this;
@@ -2435,6 +2661,9 @@ var UploadBuilder = class {
2435
2661
  if (this.vector) {
2436
2662
  options.vectorize = this.vector;
2437
2663
  }
2664
+ if (this.uploadUrl) {
2665
+ options.url = this.uploadUrl;
2666
+ }
2438
2667
  this.args[this.args.length - 1] = options;
2439
2668
  return this.uploadFunction(this.config, ...this.args).then(
2440
2669
  onfulfilled,
@@ -2467,6 +2696,9 @@ var Upload = class {
2467
2696
  json(data, options) {
2468
2697
  return new UploadBuilder(this.config, uploadJson, data, options);
2469
2698
  }
2699
+ createSignedURL(options) {
2700
+ return createSignedUploadURL(this.config, options);
2701
+ }
2470
2702
  };
2471
2703
  var FilterFiles = class {
2472
2704
  // rate limit vars