pinata 1.2.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 +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +210 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +210 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -276,8 +276,8 @@ type SwapHistoryOptions = {
|
|
|
276
276
|
domain: string;
|
|
277
277
|
};
|
|
278
278
|
type SwapCidResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
mapped_cid: string;
|
|
280
|
+
created_at: string;
|
|
281
281
|
};
|
|
282
282
|
type ContainsCIDResponse = {
|
|
283
283
|
containsCid: boolean;
|
|
@@ -302,6 +302,9 @@ declare class Files {
|
|
|
302
302
|
list(): FilterFiles;
|
|
303
303
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
304
304
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
305
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
306
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
307
|
+
deleteSwap(cid: string): Promise<string>;
|
|
305
308
|
}
|
|
306
309
|
declare class UploadBuilder<T> {
|
|
307
310
|
private config;
|
package/dist/index.d.ts
CHANGED
|
@@ -276,8 +276,8 @@ type SwapHistoryOptions = {
|
|
|
276
276
|
domain: string;
|
|
277
277
|
};
|
|
278
278
|
type SwapCidResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
mapped_cid: string;
|
|
280
|
+
created_at: string;
|
|
281
281
|
};
|
|
282
282
|
type ContainsCIDResponse = {
|
|
283
283
|
containsCid: boolean;
|
|
@@ -302,6 +302,9 @@ declare class Files {
|
|
|
302
302
|
list(): FilterFiles;
|
|
303
303
|
delete(files: string[]): Promise<DeleteResponse[]>;
|
|
304
304
|
update(options: UpdateFileOptions): Promise<FileListItem>;
|
|
305
|
+
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
306
|
+
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
307
|
+
deleteSwap(cid: string): Promise<string>;
|
|
305
308
|
}
|
|
306
309
|
declare class UploadBuilder<T> {
|
|
307
310
|
private config;
|
package/dist/index.js
CHANGED
|
@@ -1149,6 +1149,207 @@ 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) {
|
|
@@ -1286,6 +1487,15 @@ var Files = class {
|
|
|
1286
1487
|
update(options) {
|
|
1287
1488
|
return updateFile(this.config, options);
|
|
1288
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
|
+
}
|
|
1289
1499
|
};
|
|
1290
1500
|
var UploadBuilder = class {
|
|
1291
1501
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -1452,15 +1662,6 @@ var Gateways = class {
|
|
|
1452
1662
|
createSignedURL(options) {
|
|
1453
1663
|
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
1454
1664
|
}
|
|
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
1665
|
// topUsageAnalytics(options: {
|
|
1465
1666
|
// domain: string;
|
|
1466
1667
|
// start: string;
|
|
@@ -1497,15 +1698,6 @@ var Gateways = class {
|
|
|
1497
1698
|
// options.interval,
|
|
1498
1699
|
// );
|
|
1499
1700
|
// }
|
|
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
1701
|
};
|
|
1510
1702
|
var OptimizeImageGetCid = class {
|
|
1511
1703
|
constructor(config, cid) {
|