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 CHANGED
@@ -263,7 +263,11 @@ type GroupQueryOptions = {
263
263
  };
264
264
  type GroupCIDOptions = {
265
265
  groupId: string;
266
- cids: string[];
266
+ files: string[];
267
+ };
268
+ type UpdateGroupFilesResponse = {
269
+ id: string;
270
+ status: string;
267
271
  };
268
272
  type SignatureOptions = {
269
273
  cid: string;
@@ -406,6 +410,8 @@ declare class Groups {
406
410
  create(options: GroupOptions): Promise<GroupResponseItem>;
407
411
  list(): FilterGroups;
408
412
  get(options: GetGroupOptions): Promise<GroupResponseItem>;
413
+ addFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
414
+ removeFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
409
415
  update(options: UpdateGroupOptions): Promise<GroupResponseItem>;
410
416
  delete(options: GetGroupOptions): Promise<string>;
411
417
  }
@@ -424,4 +430,4 @@ declare class FilterGroups {
424
430
  all(): Promise<GroupResponseItem[]>;
425
431
  }
426
432
 
427
- export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UpdateFileOptions, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
433
+ export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
package/dist/index.d.ts CHANGED
@@ -263,7 +263,11 @@ type GroupQueryOptions = {
263
263
  };
264
264
  type GroupCIDOptions = {
265
265
  groupId: string;
266
- cids: string[];
266
+ files: string[];
267
+ };
268
+ type UpdateGroupFilesResponse = {
269
+ id: string;
270
+ status: string;
267
271
  };
268
272
  type SignatureOptions = {
269
273
  cid: string;
@@ -406,6 +410,8 @@ declare class Groups {
406
410
  create(options: GroupOptions): Promise<GroupResponseItem>;
407
411
  list(): FilterGroups;
408
412
  get(options: GetGroupOptions): Promise<GroupResponseItem>;
413
+ addFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
414
+ removeFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
409
415
  update(options: UpdateGroupOptions): Promise<GroupResponseItem>;
410
416
  delete(options: GetGroupOptions): Promise<string>;
411
417
  }
@@ -424,4 +430,4 @@ declare class FilterGroups {
424
430
  all(): Promise<GroupResponseItem[]>;
425
431
  }
426
432
 
427
- export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UpdateFileOptions, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
433
+ export { type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupListResponse, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type OptimizeImageOptions, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinataConfig, type PinataMetadata, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SignedUrlOptions, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
package/dist/index.js CHANGED
@@ -1140,6 +1140,82 @@ var getGroup = async (config, options) => {
1140
1140
  }
1141
1141
  };
1142
1142
 
1143
+ // src/core/groups/addToGroup.ts
1144
+ var addToGroup = async (config, options) => {
1145
+ if (!config) {
1146
+ throw new ValidationError("Pinata configuration is missing");
1147
+ }
1148
+ const wait3 = (milliseconds) => {
1149
+ return new Promise((resolve) => {
1150
+ setTimeout(resolve, milliseconds);
1151
+ });
1152
+ };
1153
+ const responses = [];
1154
+ let headers;
1155
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1156
+ headers = {
1157
+ Authorization: `Bearer ${config.pinataJwt}`,
1158
+ "Content-Type": "application/json",
1159
+ ...config.customHeaders
1160
+ };
1161
+ } else {
1162
+ headers = {
1163
+ Authorization: `Bearer ${config.pinataJwt}`,
1164
+ "Content-Type": "application/json",
1165
+ Source: "sdk/addToGroup"
1166
+ };
1167
+ }
1168
+ let endpoint = "https://api.pinata.cloud/v3";
1169
+ if (config.endpointUrl) {
1170
+ endpoint = config.endpointUrl;
1171
+ }
1172
+ for (const id of options.files) {
1173
+ try {
1174
+ const response = await fetch(
1175
+ `${endpoint}/files/groups/${options.groupId}/ids/${id}`,
1176
+ {
1177
+ method: "PUT",
1178
+ headers
1179
+ }
1180
+ );
1181
+ await wait3(300);
1182
+ if (!response.ok) {
1183
+ const errorData = await response.text();
1184
+ if (response.status === 401) {
1185
+ throw new AuthenticationError(
1186
+ `Authentication failed: ${errorData}`,
1187
+ response.status,
1188
+ errorData
1189
+ );
1190
+ }
1191
+ throw new NetworkError(
1192
+ `HTTP error: ${errorData}`,
1193
+ response.status,
1194
+ errorData
1195
+ );
1196
+ }
1197
+ responses.push({
1198
+ id,
1199
+ status: response.statusText
1200
+ });
1201
+ } catch (error) {
1202
+ let errorMessage;
1203
+ if (error instanceof PinataError) {
1204
+ errorMessage = error.message;
1205
+ } else if (error instanceof Error) {
1206
+ errorMessage = `Error adding file ${id} to group: ${error.message}`;
1207
+ } else {
1208
+ errorMessage = `An unknown error occurred while adding file ${id} to group`;
1209
+ }
1210
+ responses.push({
1211
+ id,
1212
+ status: errorMessage
1213
+ });
1214
+ }
1215
+ }
1216
+ return responses;
1217
+ };
1218
+
1143
1219
  // src/core/groups/updateGroup.ts
1144
1220
  var updateGroup = async (config, options) => {
1145
1221
  if (!config) {
@@ -1202,6 +1278,82 @@ var updateGroup = async (config, options) => {
1202
1278
  }
1203
1279
  };
1204
1280
 
1281
+ // src/core/groups/removeFromGroup.ts
1282
+ var removeFromGroup = async (config, options) => {
1283
+ if (!config) {
1284
+ throw new ValidationError("Pinata configuration is missing");
1285
+ }
1286
+ const wait3 = (milliseconds) => {
1287
+ return new Promise((resolve) => {
1288
+ setTimeout(resolve, milliseconds);
1289
+ });
1290
+ };
1291
+ const responses = [];
1292
+ let headers;
1293
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
1294
+ headers = {
1295
+ Authorization: `Bearer ${config.pinataJwt}`,
1296
+ "Content-Type": "application/json",
1297
+ ...config.customHeaders
1298
+ };
1299
+ } else {
1300
+ headers = {
1301
+ Authorization: `Bearer ${config.pinataJwt}`,
1302
+ "Content-Type": "application/json",
1303
+ Source: "sdk/addToGroup"
1304
+ };
1305
+ }
1306
+ let endpoint = "https://api.pinata.cloud/v3";
1307
+ if (config.endpointUrl) {
1308
+ endpoint = config.endpointUrl;
1309
+ }
1310
+ for (const id of options.files) {
1311
+ try {
1312
+ const response = await fetch(
1313
+ `${endpoint}/files/groups/${options.groupId}/ids/${id}`,
1314
+ {
1315
+ method: "DELETE",
1316
+ headers
1317
+ }
1318
+ );
1319
+ await wait3(300);
1320
+ if (!response.ok) {
1321
+ const errorData = await response.text();
1322
+ if (response.status === 401) {
1323
+ throw new AuthenticationError(
1324
+ `Authentication failed: ${errorData}`,
1325
+ response.status,
1326
+ errorData
1327
+ );
1328
+ }
1329
+ throw new NetworkError(
1330
+ `HTTP error: ${errorData}`,
1331
+ response.status,
1332
+ errorData
1333
+ );
1334
+ }
1335
+ responses.push({
1336
+ id,
1337
+ status: response.statusText
1338
+ });
1339
+ } catch (error) {
1340
+ let errorMessage;
1341
+ if (error instanceof PinataError) {
1342
+ errorMessage = error.message;
1343
+ } else if (error instanceof Error) {
1344
+ errorMessage = `Error adding file ${id} to group: ${error.message}`;
1345
+ } else {
1346
+ errorMessage = `An unknown error occurred while adding file ${id} to group`;
1347
+ }
1348
+ responses.push({
1349
+ id,
1350
+ status: errorMessage
1351
+ });
1352
+ }
1353
+ }
1354
+ return responses;
1355
+ };
1356
+
1205
1357
  // src/core/groups/deleteGroup.ts
1206
1358
  var deleteGroup = async (config, options) => {
1207
1359
  if (!config) {
@@ -1990,12 +2142,12 @@ var Groups = class {
1990
2142
  get(options) {
1991
2143
  return getGroup(this.config, options);
1992
2144
  }
1993
- // addFiles(options: GroupCIDOptions): Promise<string> {
1994
- // return addToGroup(this.config, options);
1995
- // }
1996
- // removeFiles(options: GroupCIDOptions): Promise<string> {
1997
- // return removeFromGroup(this.config, options);
1998
- // }
2145
+ addFiles(options) {
2146
+ return addToGroup(this.config, options);
2147
+ }
2148
+ removeFiles(options) {
2149
+ return removeFromGroup(this.config, options);
2150
+ }
1999
2151
  update(options) {
2000
2152
  return updateGroup(this.config, options);
2001
2153
  }