pinata 1.1.0 → 1.3.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/dist/index.d.mts +36 -6
- package/dist/index.d.ts +36 -6
- package/dist/index.js +351 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +351 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,9 +59,14 @@ type FileListResponse = {
|
|
|
59
59
|
next_page_token: string;
|
|
60
60
|
};
|
|
61
61
|
type FileListQuery = {
|
|
62
|
+
name?: string;
|
|
63
|
+
group?: string;
|
|
64
|
+
mimeType?: string;
|
|
65
|
+
cid?: string;
|
|
66
|
+
cidPending?: boolean;
|
|
67
|
+
order?: "ASC" | "DESC";
|
|
62
68
|
limit?: number;
|
|
63
69
|
pageToken?: string;
|
|
64
|
-
cidPending?: boolean;
|
|
65
70
|
};
|
|
66
71
|
type PinJobQuery = {
|
|
67
72
|
sort?: "ASC" | "DSC";
|
|
@@ -245,7 +250,7 @@ type GroupResponseItem = {
|
|
|
245
250
|
createdAt: string;
|
|
246
251
|
};
|
|
247
252
|
type GroupQueryOptions = {
|
|
248
|
-
|
|
253
|
+
name?: string;
|
|
249
254
|
limit?: number;
|
|
250
255
|
pageToken?: string;
|
|
251
256
|
isPublic?: boolean;
|
|
@@ -271,8 +276,8 @@ type SwapHistoryOptions = {
|
|
|
271
276
|
domain: string;
|
|
272
277
|
};
|
|
273
278
|
type SwapCidResponse = {
|
|
274
|
-
|
|
275
|
-
|
|
279
|
+
mapped_cid: string;
|
|
280
|
+
created_at: string;
|
|
276
281
|
};
|
|
277
282
|
type ContainsCIDResponse = {
|
|
278
283
|
containsCid: boolean;
|
|
@@ -297,6 +302,9 @@ declare class Files {
|
|
|
297
302
|
list(): FilterFiles;
|
|
298
303
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
299
304
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
305
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
306
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
307
|
+
deleteSwap(cid: string): Promise<string>;
|
|
300
308
|
}
|
|
301
309
|
declare class UploadBuilder<T> {
|
|
302
310
|
private config;
|
|
@@ -325,6 +333,11 @@ declare class FilterFiles {
|
|
|
325
333
|
private query;
|
|
326
334
|
private currentPageToken;
|
|
327
335
|
constructor(config: PinataConfig | undefined);
|
|
336
|
+
name(name: string): FilterFiles;
|
|
337
|
+
group(group: string): FilterFiles;
|
|
338
|
+
cid(cid: string): FilterFiles;
|
|
339
|
+
mimeType(mimeType: string): FilterFiles;
|
|
340
|
+
order(order: "ASC" | "DESC"): FilterFiles;
|
|
328
341
|
limit(limit: number): FilterFiles;
|
|
329
342
|
cidPending(cidPending: boolean): FilterFiles;
|
|
330
343
|
pageToken(pageToken: string): FilterFiles;
|
|
@@ -337,8 +350,24 @@ declare class Gateways {
|
|
|
337
350
|
config: PinataConfig | undefined;
|
|
338
351
|
constructor(config?: PinataConfig);
|
|
339
352
|
updateConfig(newConfig: PinataConfig): void;
|
|
340
|
-
get(cid: string):
|
|
341
|
-
createSignedURL(options: SignedUrlOptions):
|
|
353
|
+
get(cid: string): OptimizeImageGetCid;
|
|
354
|
+
createSignedURL(options: SignedUrlOptions): OptimizeImageCreateSignedURL;
|
|
355
|
+
}
|
|
356
|
+
declare class OptimizeImageGetCid {
|
|
357
|
+
private config;
|
|
358
|
+
private cid;
|
|
359
|
+
private options;
|
|
360
|
+
constructor(config: PinataConfig | undefined, cid: string);
|
|
361
|
+
optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
|
|
362
|
+
then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
|
|
363
|
+
}
|
|
364
|
+
declare class OptimizeImageCreateSignedURL {
|
|
365
|
+
private config;
|
|
366
|
+
private urlOpts;
|
|
367
|
+
private imgOpts;
|
|
368
|
+
constructor(config: PinataConfig | undefined, urlOpts: SignedUrlOptions);
|
|
369
|
+
optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateSignedURL;
|
|
370
|
+
then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
|
|
342
371
|
}
|
|
343
372
|
declare class Keys {
|
|
344
373
|
config: PinataConfig | undefined;
|
|
@@ -376,6 +405,7 @@ declare class FilterGroups {
|
|
|
376
405
|
private query;
|
|
377
406
|
private nextPageToken;
|
|
378
407
|
constructor(config: PinataConfig | undefined);
|
|
408
|
+
name(name: string): FilterGroups;
|
|
379
409
|
limit(limit: number): FilterGroups;
|
|
380
410
|
isPublic(isPublic: boolean): FilterGroups;
|
|
381
411
|
pageToken(pageToken: string): FilterGroups;
|
package/dist/index.d.ts
CHANGED
|
@@ -59,9 +59,14 @@ type FileListResponse = {
|
|
|
59
59
|
next_page_token: string;
|
|
60
60
|
};
|
|
61
61
|
type FileListQuery = {
|
|
62
|
+
name?: string;
|
|
63
|
+
group?: string;
|
|
64
|
+
mimeType?: string;
|
|
65
|
+
cid?: string;
|
|
66
|
+
cidPending?: boolean;
|
|
67
|
+
order?: "ASC" | "DESC";
|
|
62
68
|
limit?: number;
|
|
63
69
|
pageToken?: string;
|
|
64
|
-
cidPending?: boolean;
|
|
65
70
|
};
|
|
66
71
|
type PinJobQuery = {
|
|
67
72
|
sort?: "ASC" | "DSC";
|
|
@@ -245,7 +250,7 @@ type GroupResponseItem = {
|
|
|
245
250
|
createdAt: string;
|
|
246
251
|
};
|
|
247
252
|
type GroupQueryOptions = {
|
|
248
|
-
|
|
253
|
+
name?: string;
|
|
249
254
|
limit?: number;
|
|
250
255
|
pageToken?: string;
|
|
251
256
|
isPublic?: boolean;
|
|
@@ -271,8 +276,8 @@ type SwapHistoryOptions = {
|
|
|
271
276
|
domain: string;
|
|
272
277
|
};
|
|
273
278
|
type SwapCidResponse = {
|
|
274
|
-
|
|
275
|
-
|
|
279
|
+
mapped_cid: string;
|
|
280
|
+
created_at: string;
|
|
276
281
|
};
|
|
277
282
|
type ContainsCIDResponse = {
|
|
278
283
|
containsCid: boolean;
|
|
@@ -297,6 +302,9 @@ declare class Files {
|
|
|
297
302
|
list(): FilterFiles;
|
|
298
303
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
299
304
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
305
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
306
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
307
|
+
deleteSwap(cid: string): Promise<string>;
|
|
300
308
|
}
|
|
301
309
|
declare class UploadBuilder<T> {
|
|
302
310
|
private config;
|
|
@@ -325,6 +333,11 @@ declare class FilterFiles {
|
|
|
325
333
|
private query;
|
|
326
334
|
private currentPageToken;
|
|
327
335
|
constructor(config: PinataConfig | undefined);
|
|
336
|
+
name(name: string): FilterFiles;
|
|
337
|
+
group(group: string): FilterFiles;
|
|
338
|
+
cid(cid: string): FilterFiles;
|
|
339
|
+
mimeType(mimeType: string): FilterFiles;
|
|
340
|
+
order(order: "ASC" | "DESC"): FilterFiles;
|
|
328
341
|
limit(limit: number): FilterFiles;
|
|
329
342
|
cidPending(cidPending: boolean): FilterFiles;
|
|
330
343
|
pageToken(pageToken: string): FilterFiles;
|
|
@@ -337,8 +350,24 @@ declare class Gateways {
|
|
|
337
350
|
config: PinataConfig | undefined;
|
|
338
351
|
constructor(config?: PinataConfig);
|
|
339
352
|
updateConfig(newConfig: PinataConfig): void;
|
|
340
|
-
get(cid: string):
|
|
341
|
-
createSignedURL(options: SignedUrlOptions):
|
|
353
|
+
get(cid: string): OptimizeImageGetCid;
|
|
354
|
+
createSignedURL(options: SignedUrlOptions): OptimizeImageCreateSignedURL;
|
|
355
|
+
}
|
|
356
|
+
declare class OptimizeImageGetCid {
|
|
357
|
+
private config;
|
|
358
|
+
private cid;
|
|
359
|
+
private options;
|
|
360
|
+
constructor(config: PinataConfig | undefined, cid: string);
|
|
361
|
+
optimizeImage(options: OptimizeImageOptions): OptimizeImageGetCid;
|
|
362
|
+
then(onfulfilled?: ((value: GetCIDResponse) => any) | null): Promise<any>;
|
|
363
|
+
}
|
|
364
|
+
declare class OptimizeImageCreateSignedURL {
|
|
365
|
+
private config;
|
|
366
|
+
private urlOpts;
|
|
367
|
+
private imgOpts;
|
|
368
|
+
constructor(config: PinataConfig | undefined, urlOpts: SignedUrlOptions);
|
|
369
|
+
optimizeImage(options: OptimizeImageOptions): OptimizeImageCreateSignedURL;
|
|
370
|
+
then(onfulfilled?: ((value: string) => any) | null): Promise<any>;
|
|
342
371
|
}
|
|
343
372
|
declare class Keys {
|
|
344
373
|
config: PinataConfig | undefined;
|
|
@@ -376,6 +405,7 @@ declare class FilterGroups {
|
|
|
376
405
|
private query;
|
|
377
406
|
private nextPageToken;
|
|
378
407
|
constructor(config: PinataConfig | undefined);
|
|
408
|
+
name(name: string): FilterGroups;
|
|
379
409
|
limit(limit: number): FilterGroups;
|
|
380
410
|
isPublic(isPublic: boolean): FilterGroups;
|
|
381
411
|
pageToken(pageToken: string): FilterGroups;
|
package/dist/index.js
CHANGED
|
@@ -443,9 +443,19 @@ var listFiles = async (config, options) => {
|
|
|
443
443
|
}
|
|
444
444
|
const params = new URLSearchParams();
|
|
445
445
|
if (options) {
|
|
446
|
-
const { limit, pageToken, cidPending } = options;
|
|
446
|
+
const { name, group, cid, order, limit, mimeType, pageToken, cidPending } = options;
|
|
447
447
|
if (limit)
|
|
448
448
|
params.append("limit", limit.toString());
|
|
449
|
+
if (name)
|
|
450
|
+
params.append("name", name);
|
|
451
|
+
if (group)
|
|
452
|
+
params.append("group", group);
|
|
453
|
+
if (cid)
|
|
454
|
+
params.append("cid", cid);
|
|
455
|
+
if (mimeType)
|
|
456
|
+
params.append("mimeType", mimeType);
|
|
457
|
+
if (order)
|
|
458
|
+
params.append("order", order);
|
|
449
459
|
if (pageToken)
|
|
450
460
|
params.append("pageToken", pageToken);
|
|
451
461
|
if (cidPending)
|
|
@@ -557,13 +567,41 @@ var updateFile = async (config, options) => {
|
|
|
557
567
|
};
|
|
558
568
|
|
|
559
569
|
// src/core/gateway/getCid.ts
|
|
560
|
-
var getCid = async (config, cid) => {
|
|
570
|
+
var getCid = async (config, cid, options) => {
|
|
561
571
|
if (!config) {
|
|
562
572
|
throw new ValidationError("Pinata configuration is missing");
|
|
563
573
|
}
|
|
564
574
|
let data;
|
|
565
575
|
let newUrl = `${config?.pinataGateway}/files/${cid}`;
|
|
566
576
|
const params = new URLSearchParams();
|
|
577
|
+
if (options) {
|
|
578
|
+
if (options.width)
|
|
579
|
+
params.append("img-width", options.width.toString());
|
|
580
|
+
if (options.height)
|
|
581
|
+
params.append("img-height", options.height.toString());
|
|
582
|
+
if (options.dpr)
|
|
583
|
+
params.append("img-dpr", options.dpr.toString());
|
|
584
|
+
if (options.fit)
|
|
585
|
+
params.append("img-fit", options.fit);
|
|
586
|
+
if (options.gravity)
|
|
587
|
+
params.append("img-gravity", options.gravity);
|
|
588
|
+
if (options.quality)
|
|
589
|
+
params.append("img-quality", options.quality.toString());
|
|
590
|
+
if (options.format)
|
|
591
|
+
params.append("img-format", options.format);
|
|
592
|
+
if (options.animation !== void 0)
|
|
593
|
+
params.append("img-anim", options.animation.toString());
|
|
594
|
+
if (options.sharpen)
|
|
595
|
+
params.append("img-sharpen", options.sharpen.toString());
|
|
596
|
+
if (options.onError === true)
|
|
597
|
+
params.append("img-onerror", "redirect");
|
|
598
|
+
if (options.metadata)
|
|
599
|
+
params.append("img-metadata", options.metadata);
|
|
600
|
+
}
|
|
601
|
+
const queryString = params.toString();
|
|
602
|
+
if (queryString) {
|
|
603
|
+
newUrl += `?${queryString}`;
|
|
604
|
+
}
|
|
567
605
|
const date = Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
568
606
|
const payload = JSON.stringify({
|
|
569
607
|
url: newUrl,
|
|
@@ -571,17 +609,18 @@ var getCid = async (config, cid) => {
|
|
|
571
609
|
expires: 30,
|
|
572
610
|
method: "GET"
|
|
573
611
|
});
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
612
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
613
|
+
if (config.endpointUrl) {
|
|
614
|
+
endpoint = config.endpointUrl;
|
|
615
|
+
}
|
|
616
|
+
const signedUrlRequest = await fetch(`${endpoint}/files/sign`, {
|
|
617
|
+
method: "POST",
|
|
618
|
+
headers: {
|
|
619
|
+
"Content-Type": "application/json",
|
|
620
|
+
Authorization: `Bearer ${config?.pinataJwt}`
|
|
621
|
+
},
|
|
622
|
+
body: payload
|
|
623
|
+
});
|
|
585
624
|
const signedUrl = await signedUrlRequest.json();
|
|
586
625
|
try {
|
|
587
626
|
const request = await fetch(signedUrl.data);
|
|
@@ -894,13 +933,13 @@ var listGroups = async (config, options) => {
|
|
|
894
933
|
}
|
|
895
934
|
const params = new URLSearchParams();
|
|
896
935
|
if (options) {
|
|
897
|
-
const { pageToken,
|
|
936
|
+
const { pageToken, name, limit, isPublic } = options;
|
|
898
937
|
if (pageToken)
|
|
899
938
|
params.append("pageToken", pageToken.toString());
|
|
900
939
|
if (isPublic)
|
|
901
940
|
params.append("isPublic", isPublic.toString());
|
|
902
|
-
if (
|
|
903
|
-
params.append("
|
|
941
|
+
if (name)
|
|
942
|
+
params.append("name", name);
|
|
904
943
|
if (limit !== void 0)
|
|
905
944
|
params.append("limit", limit.toString());
|
|
906
945
|
}
|
|
@@ -1110,12 +1149,242 @@ var deleteGroup = async (config, options) => {
|
|
|
1110
1149
|
}
|
|
1111
1150
|
};
|
|
1112
1151
|
|
|
1152
|
+
// src/core/files/swapCid.ts
|
|
1153
|
+
var swapCid = async (config, options) => {
|
|
1154
|
+
if (!config) {
|
|
1155
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1156
|
+
}
|
|
1157
|
+
const data = JSON.stringify({
|
|
1158
|
+
swap_cid: options.swapCid
|
|
1159
|
+
});
|
|
1160
|
+
let headers;
|
|
1161
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1162
|
+
headers = { ...config.customHeaders };
|
|
1163
|
+
} else {
|
|
1164
|
+
headers = {
|
|
1165
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1166
|
+
"Content-Type": "application/json",
|
|
1167
|
+
Source: "sdk/swapCid"
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1171
|
+
if (config.endpointUrl) {
|
|
1172
|
+
endpoint = config.endpointUrl;
|
|
1173
|
+
}
|
|
1174
|
+
try {
|
|
1175
|
+
const request = await fetch(`${endpoint}/files/swap/${options.cid}`, {
|
|
1176
|
+
method: "PUT",
|
|
1177
|
+
headers,
|
|
1178
|
+
body: data
|
|
1179
|
+
});
|
|
1180
|
+
if (!request.ok) {
|
|
1181
|
+
const errorData = await request.text();
|
|
1182
|
+
if (request.status === 401 || request.status === 403) {
|
|
1183
|
+
throw new AuthenticationError(
|
|
1184
|
+
`Authentication failed: ${errorData}`,
|
|
1185
|
+
request.status,
|
|
1186
|
+
errorData
|
|
1187
|
+
);
|
|
1188
|
+
}
|
|
1189
|
+
if (request.status === 403) {
|
|
1190
|
+
throw new PinataError(
|
|
1191
|
+
"Unauthorized CID Swap",
|
|
1192
|
+
request.status,
|
|
1193
|
+
errorData
|
|
1194
|
+
);
|
|
1195
|
+
}
|
|
1196
|
+
if (request.status === 404) {
|
|
1197
|
+
throw new PinataError(
|
|
1198
|
+
"CID not pinned to account",
|
|
1199
|
+
request.status,
|
|
1200
|
+
errorData
|
|
1201
|
+
);
|
|
1202
|
+
}
|
|
1203
|
+
throw new NetworkError(
|
|
1204
|
+
`HTTP error: ${errorData}`,
|
|
1205
|
+
request.status,
|
|
1206
|
+
errorData
|
|
1207
|
+
);
|
|
1208
|
+
}
|
|
1209
|
+
const res = await request.json();
|
|
1210
|
+
const resData = res.data;
|
|
1211
|
+
return resData;
|
|
1212
|
+
} catch (error) {
|
|
1213
|
+
if (error instanceof PinataError) {
|
|
1214
|
+
throw error;
|
|
1215
|
+
}
|
|
1216
|
+
if (error instanceof Error) {
|
|
1217
|
+
throw new PinataError(`Error processing CID Swap: ${error.message}`);
|
|
1218
|
+
}
|
|
1219
|
+
throw new PinataError("An unknown error occurred while swapping CID");
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
|
|
1223
|
+
// src/core/files/swapHistory.ts
|
|
1224
|
+
var swapHistory = async (config, options) => {
|
|
1225
|
+
if (!config) {
|
|
1226
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1227
|
+
}
|
|
1228
|
+
let headers;
|
|
1229
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1230
|
+
headers = { ...config.customHeaders };
|
|
1231
|
+
} else {
|
|
1232
|
+
headers = {
|
|
1233
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1234
|
+
"Content-Type": "application/json",
|
|
1235
|
+
Source: "sdk/swapHistory"
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1239
|
+
if (config.endpointUrl) {
|
|
1240
|
+
endpoint = config.endpointUrl;
|
|
1241
|
+
}
|
|
1242
|
+
try {
|
|
1243
|
+
const request = await fetch(
|
|
1244
|
+
`${endpoint}/files/swap/${options.cid}?domain=${options.domain}`,
|
|
1245
|
+
{
|
|
1246
|
+
method: "GET",
|
|
1247
|
+
headers
|
|
1248
|
+
}
|
|
1249
|
+
);
|
|
1250
|
+
if (!request.ok) {
|
|
1251
|
+
const errorData = await request.text();
|
|
1252
|
+
if (request.status === 401 || request.status === 403) {
|
|
1253
|
+
throw new AuthenticationError(
|
|
1254
|
+
`Authentication failed: ${errorData}`,
|
|
1255
|
+
request.status,
|
|
1256
|
+
errorData
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
if (request.status === 404) {
|
|
1260
|
+
throw new PinataError(
|
|
1261
|
+
"CID does not have history",
|
|
1262
|
+
request.status,
|
|
1263
|
+
errorData
|
|
1264
|
+
);
|
|
1265
|
+
}
|
|
1266
|
+
throw new NetworkError(
|
|
1267
|
+
`HTTP error: ${errorData}`,
|
|
1268
|
+
request.status,
|
|
1269
|
+
errorData
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
const res = await request.json();
|
|
1273
|
+
const resData = res.data;
|
|
1274
|
+
return resData;
|
|
1275
|
+
} catch (error) {
|
|
1276
|
+
if (error instanceof PinataError) {
|
|
1277
|
+
throw error;
|
|
1278
|
+
}
|
|
1279
|
+
if (error instanceof Error) {
|
|
1280
|
+
throw new PinataError(`Error fetching swap history: ${error.message}`);
|
|
1281
|
+
}
|
|
1282
|
+
throw new PinataError(
|
|
1283
|
+
"An unknown error occurred while fetching swap history"
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
// src/core/files/deleteSwap.ts
|
|
1289
|
+
var deleteSwap = async (config, cid) => {
|
|
1290
|
+
if (!config) {
|
|
1291
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1292
|
+
}
|
|
1293
|
+
let headers;
|
|
1294
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1295
|
+
headers = { ...config.customHeaders };
|
|
1296
|
+
} else {
|
|
1297
|
+
headers = {
|
|
1298
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1299
|
+
"Content-Type": "application/json",
|
|
1300
|
+
Source: "sdk/deleteSwap"
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1304
|
+
if (config.endpointUrl) {
|
|
1305
|
+
endpoint = config.endpointUrl;
|
|
1306
|
+
}
|
|
1307
|
+
try {
|
|
1308
|
+
const request = await fetch(`${endpoint}/files/swap/${cid}`, {
|
|
1309
|
+
method: "DELETE",
|
|
1310
|
+
headers
|
|
1311
|
+
});
|
|
1312
|
+
if (!request.ok) {
|
|
1313
|
+
const errorData = await request.text();
|
|
1314
|
+
if (request.status === 401 || request.status === 403) {
|
|
1315
|
+
throw new AuthenticationError(
|
|
1316
|
+
`Authentication failed: ${errorData}`,
|
|
1317
|
+
request.status,
|
|
1318
|
+
errorData
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
if (request.status === 403) {
|
|
1322
|
+
throw new PinataError(
|
|
1323
|
+
"Unauthorized CID Swap Deletion",
|
|
1324
|
+
request.status,
|
|
1325
|
+
errorData
|
|
1326
|
+
);
|
|
1327
|
+
}
|
|
1328
|
+
if (request.status === 404) {
|
|
1329
|
+
throw new PinataError(
|
|
1330
|
+
"CID not pinned to account",
|
|
1331
|
+
request.status,
|
|
1332
|
+
errorData
|
|
1333
|
+
);
|
|
1334
|
+
}
|
|
1335
|
+
throw new NetworkError(
|
|
1336
|
+
`HTTP error: ${errorData}`,
|
|
1337
|
+
request.status,
|
|
1338
|
+
errorData
|
|
1339
|
+
);
|
|
1340
|
+
}
|
|
1341
|
+
return request.statusText;
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
if (error instanceof PinataError) {
|
|
1344
|
+
throw error;
|
|
1345
|
+
}
|
|
1346
|
+
if (error instanceof Error) {
|
|
1347
|
+
throw new PinataError(`Error processing deleteSwap: ${error.message}`);
|
|
1348
|
+
}
|
|
1349
|
+
throw new PinataError("An unknown error occurred while deleting swap");
|
|
1350
|
+
}
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1113
1353
|
// src/core/gateway/createSignedURL.ts
|
|
1114
|
-
var createSignedURL = async (config, options) => {
|
|
1354
|
+
var createSignedURL = async (config, options, imgOpts) => {
|
|
1115
1355
|
if (!config) {
|
|
1116
1356
|
throw new ValidationError("Pinata configuration is missing");
|
|
1117
1357
|
}
|
|
1118
1358
|
let newUrl = `${config?.pinataGateway}/files/${options.cid}`;
|
|
1359
|
+
const params = new URLSearchParams();
|
|
1360
|
+
if (imgOpts) {
|
|
1361
|
+
if (imgOpts.width)
|
|
1362
|
+
params.append("img-width", imgOpts.width.toString());
|
|
1363
|
+
if (imgOpts.height)
|
|
1364
|
+
params.append("img-height", imgOpts.height.toString());
|
|
1365
|
+
if (imgOpts.dpr)
|
|
1366
|
+
params.append("img-dpr", imgOpts.dpr.toString());
|
|
1367
|
+
if (imgOpts.fit)
|
|
1368
|
+
params.append("img-fit", imgOpts.fit);
|
|
1369
|
+
if (imgOpts.gravity)
|
|
1370
|
+
params.append("img-gravity", imgOpts.gravity);
|
|
1371
|
+
if (imgOpts.quality)
|
|
1372
|
+
params.append("img-quality", imgOpts.quality.toString());
|
|
1373
|
+
if (imgOpts.format)
|
|
1374
|
+
params.append("img-format", imgOpts.format);
|
|
1375
|
+
if (imgOpts.animation !== void 0)
|
|
1376
|
+
params.append("img-anim", imgOpts.animation.toString());
|
|
1377
|
+
if (imgOpts.sharpen)
|
|
1378
|
+
params.append("img-sharpen", imgOpts.sharpen.toString());
|
|
1379
|
+
if (imgOpts.onError === true)
|
|
1380
|
+
params.append("img-onerror", "redirect");
|
|
1381
|
+
if (imgOpts.metadata)
|
|
1382
|
+
params.append("img-metadata", imgOpts.metadata);
|
|
1383
|
+
}
|
|
1384
|
+
const queryString = params.toString();
|
|
1385
|
+
if (queryString) {
|
|
1386
|
+
newUrl += `?${queryString}`;
|
|
1387
|
+
}
|
|
1119
1388
|
const date = options?.date || Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3);
|
|
1120
1389
|
const payload = JSON.stringify({
|
|
1121
1390
|
url: newUrl,
|
|
@@ -1218,6 +1487,15 @@ var Files = class {
|
|
|
1218
1487
|
update(options) {
|
|
1219
1488
|
return updateFile(this.config, options);
|
|
1220
1489
|
}
|
|
1490
|
+
addSwap(options) {
|
|
1491
|
+
return swapCid(this.config, options);
|
|
1492
|
+
}
|
|
1493
|
+
getSwapHistory(options) {
|
|
1494
|
+
return swapHistory(this.config, options);
|
|
1495
|
+
}
|
|
1496
|
+
deleteSwap(cid) {
|
|
1497
|
+
return deleteSwap(this.config, cid);
|
|
1498
|
+
}
|
|
1221
1499
|
};
|
|
1222
1500
|
var UploadBuilder = class {
|
|
1223
1501
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -1295,6 +1573,26 @@ var FilterFiles = class {
|
|
|
1295
1573
|
this.query = {};
|
|
1296
1574
|
this.config = config;
|
|
1297
1575
|
}
|
|
1576
|
+
name(name) {
|
|
1577
|
+
this.query.name = name;
|
|
1578
|
+
return this;
|
|
1579
|
+
}
|
|
1580
|
+
group(group) {
|
|
1581
|
+
this.query.group = group;
|
|
1582
|
+
return this;
|
|
1583
|
+
}
|
|
1584
|
+
cid(cid) {
|
|
1585
|
+
this.query.cid = cid;
|
|
1586
|
+
return this;
|
|
1587
|
+
}
|
|
1588
|
+
mimeType(mimeType) {
|
|
1589
|
+
this.query.mimeType = mimeType;
|
|
1590
|
+
return this;
|
|
1591
|
+
}
|
|
1592
|
+
order(order) {
|
|
1593
|
+
this.query.order = order;
|
|
1594
|
+
return this;
|
|
1595
|
+
}
|
|
1298
1596
|
limit(limit) {
|
|
1299
1597
|
this.query.limit = limit;
|
|
1300
1598
|
return this;
|
|
@@ -1359,20 +1657,11 @@ var Gateways = class {
|
|
|
1359
1657
|
this.config = newConfig;
|
|
1360
1658
|
}
|
|
1361
1659
|
get(cid) {
|
|
1362
|
-
return
|
|
1660
|
+
return new OptimizeImageGetCid(this.config, cid);
|
|
1363
1661
|
}
|
|
1364
1662
|
createSignedURL(options) {
|
|
1365
|
-
return
|
|
1663
|
+
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
1366
1664
|
}
|
|
1367
|
-
// get(cid: string): OptimizeImage {
|
|
1368
|
-
// return new OptimizeImage(this.config, cid);
|
|
1369
|
-
// }
|
|
1370
|
-
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1371
|
-
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1372
|
-
// }
|
|
1373
|
-
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1374
|
-
// return containsCID(cid);
|
|
1375
|
-
// }
|
|
1376
1665
|
// topUsageAnalytics(options: {
|
|
1377
1666
|
// domain: string;
|
|
1378
1667
|
// start: string;
|
|
@@ -1409,15 +1698,36 @@ var Gateways = class {
|
|
|
1409
1698
|
// options.interval,
|
|
1410
1699
|
// );
|
|
1411
1700
|
// }
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1701
|
+
};
|
|
1702
|
+
var OptimizeImageGetCid = class {
|
|
1703
|
+
constructor(config, cid) {
|
|
1704
|
+
this.options = {};
|
|
1705
|
+
this.config = config;
|
|
1706
|
+
this.cid = cid;
|
|
1707
|
+
}
|
|
1708
|
+
optimizeImage(options) {
|
|
1709
|
+
this.options = { ...this.options, ...options };
|
|
1710
|
+
return this;
|
|
1711
|
+
}
|
|
1712
|
+
then(onfulfilled) {
|
|
1713
|
+
return getCid(this.config, this.cid, this.options).then(onfulfilled);
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
var OptimizeImageCreateSignedURL = class {
|
|
1717
|
+
constructor(config, urlOpts) {
|
|
1718
|
+
this.imgOpts = {};
|
|
1719
|
+
this.config = config;
|
|
1720
|
+
this.urlOpts = urlOpts;
|
|
1721
|
+
}
|
|
1722
|
+
optimizeImage(options) {
|
|
1723
|
+
this.imgOpts = { ...this.imgOpts, ...options };
|
|
1724
|
+
return this;
|
|
1725
|
+
}
|
|
1726
|
+
then(onfulfilled) {
|
|
1727
|
+
return createSignedURL(this.config, this.urlOpts, this.imgOpts).then(
|
|
1728
|
+
onfulfilled
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1421
1731
|
};
|
|
1422
1732
|
var Keys = class {
|
|
1423
1733
|
constructor(config) {
|
|
@@ -1540,10 +1850,10 @@ var FilterGroups = class {
|
|
|
1540
1850
|
this.query = {};
|
|
1541
1851
|
this.config = config;
|
|
1542
1852
|
}
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1853
|
+
name(name) {
|
|
1854
|
+
this.query.name = name;
|
|
1855
|
+
return this;
|
|
1856
|
+
}
|
|
1547
1857
|
limit(limit) {
|
|
1548
1858
|
this.query.limit = limit;
|
|
1549
1859
|
return this;
|