pinata 1.2.0 → 1.4.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 +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +217 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +217 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -116,6 +116,7 @@ type SignedUrlOptions = {
|
|
|
116
116
|
cid: string;
|
|
117
117
|
date?: number;
|
|
118
118
|
expires: number;
|
|
119
|
+
gateway?: string;
|
|
119
120
|
};
|
|
120
121
|
type GatewayAnalyticsQuery = {
|
|
121
122
|
gateway_domain: string;
|
|
@@ -276,8 +277,8 @@ type SwapHistoryOptions = {
|
|
|
276
277
|
domain: string;
|
|
277
278
|
};
|
|
278
279
|
type SwapCidResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
mapped_cid: string;
|
|
281
|
+
created_at: string;
|
|
281
282
|
};
|
|
282
283
|
type ContainsCIDResponse = {
|
|
283
284
|
containsCid: boolean;
|
|
@@ -302,6 +303,9 @@ declare class Files {
|
|
|
302
303
|
list(): FilterFiles;
|
|
303
304
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
304
305
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
306
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
307
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
308
|
+
deleteSwap(cid: string): Promise<string>;
|
|
305
309
|
}
|
|
306
310
|
declare class UploadBuilder<T> {
|
|
307
311
|
private config;
|
package/dist/index.d.ts
CHANGED
|
@@ -116,6 +116,7 @@ type SignedUrlOptions = {
|
|
|
116
116
|
cid: string;
|
|
117
117
|
date?: number;
|
|
118
118
|
expires: number;
|
|
119
|
+
gateway?: string;
|
|
119
120
|
};
|
|
120
121
|
type GatewayAnalyticsQuery = {
|
|
121
122
|
gateway_domain: string;
|
|
@@ -276,8 +277,8 @@ type SwapHistoryOptions = {
|
|
|
276
277
|
domain: string;
|
|
277
278
|
};
|
|
278
279
|
type SwapCidResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
280
|
+
mapped_cid: string;
|
|
281
|
+
created_at: string;
|
|
281
282
|
};
|
|
282
283
|
type ContainsCIDResponse = {
|
|
283
284
|
containsCid: boolean;
|
|
@@ -302,6 +303,9 @@ declare class Files {
|
|
|
302
303
|
list(): FilterFiles;
|
|
303
304
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
304
305
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
306
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
307
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
308
|
+
deleteSwap(cid: string): Promise<string>;
|
|
305
309
|
}
|
|
306
310
|
declare class UploadBuilder<T> {
|
|
307
311
|
private config;
|
package/dist/index.js
CHANGED
|
@@ -1149,12 +1149,219 @@ var deleteGroup = async (config, options) => {
|
|
|
1149
1149
|
}
|
|
1150
1150
|
};
|
|
1151
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
|
+
|
|
1152
1353
|
// src/core/gateway/createSignedURL.ts
|
|
1153
1354
|
var createSignedURL = async (config, options, imgOpts) => {
|
|
1154
1355
|
if (!config) {
|
|
1155
1356
|
throw new ValidationError("Pinata configuration is missing");
|
|
1156
1357
|
}
|
|
1157
|
-
let
|
|
1358
|
+
let baseUrl;
|
|
1359
|
+
if (options?.gateway) {
|
|
1360
|
+
baseUrl = options.gateway.startsWith("https://") ? options.gateway : `https://${options.gateway}`;
|
|
1361
|
+
} else {
|
|
1362
|
+
baseUrl = config.pinataGateway;
|
|
1363
|
+
}
|
|
1364
|
+
let newUrl = `${baseUrl}/files/${options.cid}`;
|
|
1158
1365
|
const params = new URLSearchParams();
|
|
1159
1366
|
if (imgOpts) {
|
|
1160
1367
|
if (imgOpts.width)
|
|
@@ -1286,6 +1493,15 @@ var Files = class {
|
|
|
1286
1493
|
update(options) {
|
|
1287
1494
|
return updateFile(this.config, options);
|
|
1288
1495
|
}
|
|
1496
|
+
addSwap(options) {
|
|
1497
|
+
return swapCid(this.config, options);
|
|
1498
|
+
}
|
|
1499
|
+
getSwapHistory(options) {
|
|
1500
|
+
return swapHistory(this.config, options);
|
|
1501
|
+
}
|
|
1502
|
+
deleteSwap(cid) {
|
|
1503
|
+
return deleteSwap(this.config, cid);
|
|
1504
|
+
}
|
|
1289
1505
|
};
|
|
1290
1506
|
var UploadBuilder = class {
|
|
1291
1507
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -1452,15 +1668,6 @@ var Gateways = class {
|
|
|
1452
1668
|
createSignedURL(options) {
|
|
1453
1669
|
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
1454
1670
|
}
|
|
1455
|
-
// get(cid: string): OptimizeImage {
|
|
1456
|
-
// return new OptimizeImage(this.config, cid);
|
|
1457
|
-
// }
|
|
1458
|
-
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1459
|
-
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1460
|
-
// }
|
|
1461
|
-
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1462
|
-
// return containsCID(cid);
|
|
1463
|
-
// }
|
|
1464
1671
|
// topUsageAnalytics(options: {
|
|
1465
1672
|
// domain: string;
|
|
1466
1673
|
// start: string;
|
|
@@ -1497,15 +1704,6 @@ var Gateways = class {
|
|
|
1497
1704
|
// options.interval,
|
|
1498
1705
|
// );
|
|
1499
1706
|
// }
|
|
1500
|
-
// swapCid(options: SwapCidOptions): Promise<SwapCidResponse> {
|
|
1501
|
-
// return swapCid(this.config, options);
|
|
1502
|
-
// }
|
|
1503
|
-
// swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
|
|
1504
|
-
// return swapHistory(this.config, options);
|
|
1505
|
-
// }
|
|
1506
|
-
// deleteSwap(cid: string): Promise<string> {
|
|
1507
|
-
// return deleteSwap(this.config, cid);
|
|
1508
|
-
// }
|
|
1509
1707
|
};
|
|
1510
1708
|
var OptimizeImageGetCid = class {
|
|
1511
1709
|
constructor(config, cid) {
|