pinata 1.6.0 → 1.7.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 +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +158 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +158 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1114,6 +1114,82 @@ var getGroup = async (config, options) => {
|
|
|
1114
1114
|
}
|
|
1115
1115
|
};
|
|
1116
1116
|
|
|
1117
|
+
// src/core/groups/addToGroup.ts
|
|
1118
|
+
var addToGroup = async (config, options) => {
|
|
1119
|
+
if (!config) {
|
|
1120
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1121
|
+
}
|
|
1122
|
+
const wait3 = (milliseconds) => {
|
|
1123
|
+
return new Promise((resolve) => {
|
|
1124
|
+
setTimeout(resolve, milliseconds);
|
|
1125
|
+
});
|
|
1126
|
+
};
|
|
1127
|
+
const responses = [];
|
|
1128
|
+
let headers;
|
|
1129
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1130
|
+
headers = {
|
|
1131
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1132
|
+
"Content-Type": "application/json",
|
|
1133
|
+
...config.customHeaders
|
|
1134
|
+
};
|
|
1135
|
+
} else {
|
|
1136
|
+
headers = {
|
|
1137
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1138
|
+
"Content-Type": "application/json",
|
|
1139
|
+
Source: "sdk/addToGroup"
|
|
1140
|
+
};
|
|
1141
|
+
}
|
|
1142
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1143
|
+
if (config.endpointUrl) {
|
|
1144
|
+
endpoint = config.endpointUrl;
|
|
1145
|
+
}
|
|
1146
|
+
for (const id of options.files) {
|
|
1147
|
+
try {
|
|
1148
|
+
const response = await fetch(
|
|
1149
|
+
`${endpoint}/files/groups/${options.groupId}/ids/${id}`,
|
|
1150
|
+
{
|
|
1151
|
+
method: "PUT",
|
|
1152
|
+
headers
|
|
1153
|
+
}
|
|
1154
|
+
);
|
|
1155
|
+
await wait3(300);
|
|
1156
|
+
if (!response.ok) {
|
|
1157
|
+
const errorData = await response.text();
|
|
1158
|
+
if (response.status === 401) {
|
|
1159
|
+
throw new AuthenticationError(
|
|
1160
|
+
`Authentication failed: ${errorData}`,
|
|
1161
|
+
response.status,
|
|
1162
|
+
errorData
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
throw new NetworkError(
|
|
1166
|
+
`HTTP error: ${errorData}`,
|
|
1167
|
+
response.status,
|
|
1168
|
+
errorData
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
responses.push({
|
|
1172
|
+
id,
|
|
1173
|
+
status: response.statusText
|
|
1174
|
+
});
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
let errorMessage;
|
|
1177
|
+
if (error instanceof PinataError) {
|
|
1178
|
+
errorMessage = error.message;
|
|
1179
|
+
} else if (error instanceof Error) {
|
|
1180
|
+
errorMessage = `Error adding file ${id} to group: ${error.message}`;
|
|
1181
|
+
} else {
|
|
1182
|
+
errorMessage = `An unknown error occurred while adding file ${id} to group`;
|
|
1183
|
+
}
|
|
1184
|
+
responses.push({
|
|
1185
|
+
id,
|
|
1186
|
+
status: errorMessage
|
|
1187
|
+
});
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
return responses;
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1117
1193
|
// src/core/groups/updateGroup.ts
|
|
1118
1194
|
var updateGroup = async (config, options) => {
|
|
1119
1195
|
if (!config) {
|
|
@@ -1176,6 +1252,82 @@ var updateGroup = async (config, options) => {
|
|
|
1176
1252
|
}
|
|
1177
1253
|
};
|
|
1178
1254
|
|
|
1255
|
+
// src/core/groups/removeFromGroup.ts
|
|
1256
|
+
var removeFromGroup = async (config, options) => {
|
|
1257
|
+
if (!config) {
|
|
1258
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
1259
|
+
}
|
|
1260
|
+
const wait3 = (milliseconds) => {
|
|
1261
|
+
return new Promise((resolve) => {
|
|
1262
|
+
setTimeout(resolve, milliseconds);
|
|
1263
|
+
});
|
|
1264
|
+
};
|
|
1265
|
+
const responses = [];
|
|
1266
|
+
let headers;
|
|
1267
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
1268
|
+
headers = {
|
|
1269
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1270
|
+
"Content-Type": "application/json",
|
|
1271
|
+
...config.customHeaders
|
|
1272
|
+
};
|
|
1273
|
+
} else {
|
|
1274
|
+
headers = {
|
|
1275
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
1276
|
+
"Content-Type": "application/json",
|
|
1277
|
+
Source: "sdk/addToGroup"
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
let endpoint = "https://api.pinata.cloud/v3";
|
|
1281
|
+
if (config.endpointUrl) {
|
|
1282
|
+
endpoint = config.endpointUrl;
|
|
1283
|
+
}
|
|
1284
|
+
for (const id of options.files) {
|
|
1285
|
+
try {
|
|
1286
|
+
const response = await fetch(
|
|
1287
|
+
`${endpoint}/files/groups/${options.groupId}/ids/${id}`,
|
|
1288
|
+
{
|
|
1289
|
+
method: "DELETE",
|
|
1290
|
+
headers
|
|
1291
|
+
}
|
|
1292
|
+
);
|
|
1293
|
+
await wait3(300);
|
|
1294
|
+
if (!response.ok) {
|
|
1295
|
+
const errorData = await response.text();
|
|
1296
|
+
if (response.status === 401) {
|
|
1297
|
+
throw new AuthenticationError(
|
|
1298
|
+
`Authentication failed: ${errorData}`,
|
|
1299
|
+
response.status,
|
|
1300
|
+
errorData
|
|
1301
|
+
);
|
|
1302
|
+
}
|
|
1303
|
+
throw new NetworkError(
|
|
1304
|
+
`HTTP error: ${errorData}`,
|
|
1305
|
+
response.status,
|
|
1306
|
+
errorData
|
|
1307
|
+
);
|
|
1308
|
+
}
|
|
1309
|
+
responses.push({
|
|
1310
|
+
id,
|
|
1311
|
+
status: response.statusText
|
|
1312
|
+
});
|
|
1313
|
+
} catch (error) {
|
|
1314
|
+
let errorMessage;
|
|
1315
|
+
if (error instanceof PinataError) {
|
|
1316
|
+
errorMessage = error.message;
|
|
1317
|
+
} else if (error instanceof Error) {
|
|
1318
|
+
errorMessage = `Error adding file ${id} to group: ${error.message}`;
|
|
1319
|
+
} else {
|
|
1320
|
+
errorMessage = `An unknown error occurred while adding file ${id} to group`;
|
|
1321
|
+
}
|
|
1322
|
+
responses.push({
|
|
1323
|
+
id,
|
|
1324
|
+
status: errorMessage
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return responses;
|
|
1329
|
+
};
|
|
1330
|
+
|
|
1179
1331
|
// src/core/groups/deleteGroup.ts
|
|
1180
1332
|
var deleteGroup = async (config, options) => {
|
|
1181
1333
|
if (!config) {
|
|
@@ -1964,12 +2116,12 @@ var Groups = class {
|
|
|
1964
2116
|
get(options) {
|
|
1965
2117
|
return getGroup(this.config, options);
|
|
1966
2118
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2119
|
+
addFiles(options) {
|
|
2120
|
+
return addToGroup(this.config, options);
|
|
2121
|
+
}
|
|
2122
|
+
removeFiles(options) {
|
|
2123
|
+
return removeFromGroup(this.config, options);
|
|
2124
|
+
}
|
|
1973
2125
|
update(options) {
|
|
1974
2126
|
return updateGroup(this.config, options);
|
|
1975
2127
|
}
|