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.mjs CHANGED
@@ -1123,6 +1123,207 @@ 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) {
@@ -1260,6 +1461,15 @@ var Files = class {
1260
1461
  update(options) {
1261
1462
  return updateFile(this.config, options);
1262
1463
  }
1464
+ addSwap(options) {
1465
+ return swapCid(this.config, options);
1466
+ }
1467
+ getSwapHistory(options) {
1468
+ return swapHistory(this.config, options);
1469
+ }
1470
+ deleteSwap(cid) {
1471
+ return deleteSwap(this.config, cid);
1472
+ }
1263
1473
  };
1264
1474
  var UploadBuilder = class {
1265
1475
  constructor(config, uploadFunction, ...args) {
@@ -1426,15 +1636,6 @@ var Gateways = class {
1426
1636
  createSignedURL(options) {
1427
1637
  return new OptimizeImageCreateSignedURL(this.config, options);
1428
1638
  }
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
1639
  // topUsageAnalytics(options: {
1439
1640
  // domain: string;
1440
1641
  // start: string;
@@ -1471,15 +1672,6 @@ var Gateways = class {
1471
1672
  // options.interval,
1472
1673
  // );
1473
1674
  // }
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
1675
  };
1484
1676
  var OptimizeImageGetCid = class {
1485
1677
  constructor(config, cid) {