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.mjs
CHANGED
|
@@ -1123,12 +1123,219 @@ var deleteGroup = async (config, options) => {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
};
|
|
1125
1125
|
|
|
1126
|
+
// src/core/files/swapCid.ts
|
|
1127
|
+
var swapCid = async (config, options) => {
|
|
1128
|
+
if (!config) {
|
|
1129
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1130
|
+
}
|
|
1131
|
+
const data = JSON.stringify({
|
|
1132
|
+
swap_cid: options.swapCid
|
|
1133
|
+
});
|
|
1134
|
+
let headers;
|
|
1135
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1136
|
+
headers = { ...config.customHeaders };
|
|
1137
|
+
} else {
|
|
1138
|
+
headers = {
|
|
1139
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1140
|
+
"Content-Type": "application/json",
|
|
1141
|
+
Source: "sdk/swapCid"
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1145
|
+
if (config.endpointUrl) {
|
|
1146
|
+
endpoint = config.endpointUrl;
|
|
1147
|
+
}
|
|
1148
|
+
try {
|
|
1149
|
+
const request = await fetch(`${endpoint}/files/swap/${options.cid}`, {
|
|
1150
|
+
method: "PUT",
|
|
1151
|
+
headers,
|
|
1152
|
+
body: data
|
|
1153
|
+
});
|
|
1154
|
+
if (!request.ok) {
|
|
1155
|
+
const errorData = await request.text();
|
|
1156
|
+
if (request.status === 401 || request.status === 403) {
|
|
1157
|
+
throw new AuthenticationError(
|
|
1158
|
+
`Authentication failed: ${errorData}`,
|
|
1159
|
+
request.status,
|
|
1160
|
+
errorData
|
|
1161
|
+
);
|
|
1162
|
+
}
|
|
1163
|
+
if (request.status === 403) {
|
|
1164
|
+
throw new PinataError(
|
|
1165
|
+
"Unauthorized CID Swap",
|
|
1166
|
+
request.status,
|
|
1167
|
+
errorData
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
if (request.status === 404) {
|
|
1171
|
+
throw new PinataError(
|
|
1172
|
+
"CID not pinned to account",
|
|
1173
|
+
request.status,
|
|
1174
|
+
errorData
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
throw new NetworkError(
|
|
1178
|
+
`HTTP error: ${errorData}`,
|
|
1179
|
+
request.status,
|
|
1180
|
+
errorData
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
const res = await request.json();
|
|
1184
|
+
const resData = res.data;
|
|
1185
|
+
return resData;
|
|
1186
|
+
} catch (error) {
|
|
1187
|
+
if (error instanceof PinataError) {
|
|
1188
|
+
throw error;
|
|
1189
|
+
}
|
|
1190
|
+
if (error instanceof Error) {
|
|
1191
|
+
throw new PinataError(`Error processing CID Swap: ${error.message}`);
|
|
1192
|
+
}
|
|
1193
|
+
throw new PinataError("An unknown error occurred while swapping CID");
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
// src/core/files/swapHistory.ts
|
|
1198
|
+
var swapHistory = async (config, options) => {
|
|
1199
|
+
if (!config) {
|
|
1200
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1201
|
+
}
|
|
1202
|
+
let headers;
|
|
1203
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1204
|
+
headers = { ...config.customHeaders };
|
|
1205
|
+
} else {
|
|
1206
|
+
headers = {
|
|
1207
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1208
|
+
"Content-Type": "application/json",
|
|
1209
|
+
Source: "sdk/swapHistory"
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1213
|
+
if (config.endpointUrl) {
|
|
1214
|
+
endpoint = config.endpointUrl;
|
|
1215
|
+
}
|
|
1216
|
+
try {
|
|
1217
|
+
const request = await fetch(
|
|
1218
|
+
`${endpoint}/files/swap/${options.cid}?domain=${options.domain}`,
|
|
1219
|
+
{
|
|
1220
|
+
method: "GET",
|
|
1221
|
+
headers
|
|
1222
|
+
}
|
|
1223
|
+
);
|
|
1224
|
+
if (!request.ok) {
|
|
1225
|
+
const errorData = await request.text();
|
|
1226
|
+
if (request.status === 401 || request.status === 403) {
|
|
1227
|
+
throw new AuthenticationError(
|
|
1228
|
+
`Authentication failed: ${errorData}`,
|
|
1229
|
+
request.status,
|
|
1230
|
+
errorData
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (request.status === 404) {
|
|
1234
|
+
throw new PinataError(
|
|
1235
|
+
"CID does not have history",
|
|
1236
|
+
request.status,
|
|
1237
|
+
errorData
|
|
1238
|
+
);
|
|
1239
|
+
}
|
|
1240
|
+
throw new NetworkError(
|
|
1241
|
+
`HTTP error: ${errorData}`,
|
|
1242
|
+
request.status,
|
|
1243
|
+
errorData
|
|
1244
|
+
);
|
|
1245
|
+
}
|
|
1246
|
+
const res = await request.json();
|
|
1247
|
+
const resData = res.data;
|
|
1248
|
+
return resData;
|
|
1249
|
+
} catch (error) {
|
|
1250
|
+
if (error instanceof PinataError) {
|
|
1251
|
+
throw error;
|
|
1252
|
+
}
|
|
1253
|
+
if (error instanceof Error) {
|
|
1254
|
+
throw new PinataError(`Error fetching swap history: ${error.message}`);
|
|
1255
|
+
}
|
|
1256
|
+
throw new PinataError(
|
|
1257
|
+
"An unknown error occurred while fetching swap history"
|
|
1258
|
+
);
|
|
1259
|
+
}
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// src/core/files/deleteSwap.ts
|
|
1263
|
+
var deleteSwap = async (config, cid) => {
|
|
1264
|
+
if (!config) {
|
|
1265
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1266
|
+
}
|
|
1267
|
+
let headers;
|
|
1268
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1269
|
+
headers = { ...config.customHeaders };
|
|
1270
|
+
} else {
|
|
1271
|
+
headers = {
|
|
1272
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1273
|
+
"Content-Type": "application/json",
|
|
1274
|
+
Source: "sdk/deleteSwap"
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1278
|
+
if (config.endpointUrl) {
|
|
1279
|
+
endpoint = config.endpointUrl;
|
|
1280
|
+
}
|
|
1281
|
+
try {
|
|
1282
|
+
const request = await fetch(`${endpoint}/files/swap/${cid}`, {
|
|
1283
|
+
method: "DELETE",
|
|
1284
|
+
headers
|
|
1285
|
+
});
|
|
1286
|
+
if (!request.ok) {
|
|
1287
|
+
const errorData = await request.text();
|
|
1288
|
+
if (request.status === 401 || request.status === 403) {
|
|
1289
|
+
throw new AuthenticationError(
|
|
1290
|
+
`Authentication failed: ${errorData}`,
|
|
1291
|
+
request.status,
|
|
1292
|
+
errorData
|
|
1293
|
+
);
|
|
1294
|
+
}
|
|
1295
|
+
if (request.status === 403) {
|
|
1296
|
+
throw new PinataError(
|
|
1297
|
+
"Unauthorized CID Swap Deletion",
|
|
1298
|
+
request.status,
|
|
1299
|
+
errorData
|
|
1300
|
+
);
|
|
1301
|
+
}
|
|
1302
|
+
if (request.status === 404) {
|
|
1303
|
+
throw new PinataError(
|
|
1304
|
+
"CID not pinned to account",
|
|
1305
|
+
request.status,
|
|
1306
|
+
errorData
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
throw new NetworkError(
|
|
1310
|
+
`HTTP error: ${errorData}`,
|
|
1311
|
+
request.status,
|
|
1312
|
+
errorData
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
return request.statusText;
|
|
1316
|
+
} catch (error) {
|
|
1317
|
+
if (error instanceof PinataError) {
|
|
1318
|
+
throw error;
|
|
1319
|
+
}
|
|
1320
|
+
if (error instanceof Error) {
|
|
1321
|
+
throw new PinataError(`Error processing deleteSwap: ${error.message}`);
|
|
1322
|
+
}
|
|
1323
|
+
throw new PinataError("An unknown error occurred while deleting swap");
|
|
1324
|
+
}
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1126
1327
|
// src/core/gateway/createSignedURL.ts
|
|
1127
1328
|
var createSignedURL = async (config, options, imgOpts) => {
|
|
1128
1329
|
if (!config) {
|
|
1129
1330
|
throw new ValidationError("Pinata configuration is missing");
|
|
1130
1331
|
}
|
|
1131
|
-
let
|
|
1332
|
+
let baseUrl;
|
|
1333
|
+
if (options?.gateway) {
|
|
1334
|
+
baseUrl = options.gateway.startsWith("https://") ? options.gateway : `https://${options.gateway}`;
|
|
1335
|
+
} else {
|
|
1336
|
+
baseUrl = config.pinataGateway;
|
|
1337
|
+
}
|
|
1338
|
+
let newUrl = `${baseUrl}/files/${options.cid}`;
|
|
1132
1339
|
const params = new URLSearchParams();
|
|
1133
1340
|
if (imgOpts) {
|
|
1134
1341
|
if (imgOpts.width)
|
|
@@ -1260,6 +1467,15 @@ var Files = class {
|
|
|
1260
1467
|
update(options) {
|
|
1261
1468
|
return updateFile(this.config, options);
|
|
1262
1469
|
}
|
|
1470
|
+
addSwap(options) {
|
|
1471
|
+
return swapCid(this.config, options);
|
|
1472
|
+
}
|
|
1473
|
+
getSwapHistory(options) {
|
|
1474
|
+
return swapHistory(this.config, options);
|
|
1475
|
+
}
|
|
1476
|
+
deleteSwap(cid) {
|
|
1477
|
+
return deleteSwap(this.config, cid);
|
|
1478
|
+
}
|
|
1263
1479
|
};
|
|
1264
1480
|
var UploadBuilder = class {
|
|
1265
1481
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -1426,15 +1642,6 @@ var Gateways = class {
|
|
|
1426
1642
|
createSignedURL(options) {
|
|
1427
1643
|
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
1428
1644
|
}
|
|
1429
|
-
// get(cid: string): OptimizeImage {
|
|
1430
|
-
// return new OptimizeImage(this.config, cid);
|
|
1431
|
-
// }
|
|
1432
|
-
// convert(url: string, gatewayPrefix?: string): Promise<string> {
|
|
1433
|
-
// return convertIPFSUrl(this.config, url, gatewayPrefix);
|
|
1434
|
-
// }
|
|
1435
|
-
// containsCID(cid: string): Promise<ContainsCIDResponse> {
|
|
1436
|
-
// return containsCID(cid);
|
|
1437
|
-
// }
|
|
1438
1645
|
// topUsageAnalytics(options: {
|
|
1439
1646
|
// domain: string;
|
|
1440
1647
|
// start: string;
|
|
@@ -1471,15 +1678,6 @@ var Gateways = class {
|
|
|
1471
1678
|
// options.interval,
|
|
1472
1679
|
// );
|
|
1473
1680
|
// }
|
|
1474
|
-
// swapCid(options: SwapCidOptions): Promise<SwapCidResponse> {
|
|
1475
|
-
// return swapCid(this.config, options);
|
|
1476
|
-
// }
|
|
1477
|
-
// swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]> {
|
|
1478
|
-
// return swapHistory(this.config, options);
|
|
1479
|
-
// }
|
|
1480
|
-
// deleteSwap(cid: string): Promise<string> {
|
|
1481
|
-
// return deleteSwap(this.config, cid);
|
|
1482
|
-
// }
|
|
1483
1681
|
};
|
|
1484
1682
|
var OptimizeImageGetCid = class {
|
|
1485
1683
|
constructor(config, cid) {
|