pinata 1.5.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 +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +178 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -30,6 +30,7 @@ type FileObject = {
|
|
|
30
30
|
type JsonBody = Record<string, unknown>;
|
|
31
31
|
type PinataMetadata = {
|
|
32
32
|
name?: string;
|
|
33
|
+
keyvalues?: Record<string, string>;
|
|
33
34
|
};
|
|
34
35
|
type UpdateFileOptions = {
|
|
35
36
|
id: string;
|
|
@@ -63,6 +64,7 @@ type FileListResponse = {
|
|
|
63
64
|
type FileListQuery = {
|
|
64
65
|
name?: string;
|
|
65
66
|
group?: string;
|
|
67
|
+
noGroup?: boolean;
|
|
66
68
|
mimeType?: string;
|
|
67
69
|
cid?: string;
|
|
68
70
|
cidPending?: boolean;
|
|
@@ -261,7 +263,11 @@ type GroupQueryOptions = {
|
|
|
261
263
|
};
|
|
262
264
|
type GroupCIDOptions = {
|
|
263
265
|
groupId: string;
|
|
264
|
-
|
|
266
|
+
files: string[];
|
|
267
|
+
};
|
|
268
|
+
type UpdateGroupFilesResponse = {
|
|
269
|
+
id: string;
|
|
270
|
+
status: string;
|
|
265
271
|
};
|
|
266
272
|
type SignatureOptions = {
|
|
267
273
|
cid: string;
|
|
@@ -346,6 +352,7 @@ declare class FilterFiles {
|
|
|
346
352
|
limit(limit: number): FilterFiles;
|
|
347
353
|
cidPending(cidPending: boolean): FilterFiles;
|
|
348
354
|
metadata(keyvalues: Record<string, string>): FilterFiles;
|
|
355
|
+
noGroup(noGroup: boolean): FilterFiles;
|
|
349
356
|
pageToken(pageToken: string): FilterFiles;
|
|
350
357
|
then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
|
|
351
358
|
private fetchPage;
|
|
@@ -403,6 +410,8 @@ declare class Groups {
|
|
|
403
410
|
create(options: GroupOptions): Promise<GroupResponseItem>;
|
|
404
411
|
list(): FilterGroups;
|
|
405
412
|
get(options: GetGroupOptions): Promise<GroupResponseItem>;
|
|
413
|
+
addFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
|
|
414
|
+
removeFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
|
|
406
415
|
update(options: UpdateGroupOptions): Promise<GroupResponseItem>;
|
|
407
416
|
delete(options: GetGroupOptions): Promise<string>;
|
|
408
417
|
}
|
|
@@ -421,4 +430,4 @@ declare class FilterGroups {
|
|
|
421
430
|
all(): Promise<GroupResponseItem[]>;
|
|
422
431
|
}
|
|
423
432
|
|
|
424
|
-
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
|
@@ -30,6 +30,7 @@ type FileObject = {
|
|
|
30
30
|
type JsonBody = Record<string, unknown>;
|
|
31
31
|
type PinataMetadata = {
|
|
32
32
|
name?: string;
|
|
33
|
+
keyvalues?: Record<string, string>;
|
|
33
34
|
};
|
|
34
35
|
type UpdateFileOptions = {
|
|
35
36
|
id: string;
|
|
@@ -63,6 +64,7 @@ type FileListResponse = {
|
|
|
63
64
|
type FileListQuery = {
|
|
64
65
|
name?: string;
|
|
65
66
|
group?: string;
|
|
67
|
+
noGroup?: boolean;
|
|
66
68
|
mimeType?: string;
|
|
67
69
|
cid?: string;
|
|
68
70
|
cidPending?: boolean;
|
|
@@ -261,7 +263,11 @@ type GroupQueryOptions = {
|
|
|
261
263
|
};
|
|
262
264
|
type GroupCIDOptions = {
|
|
263
265
|
groupId: string;
|
|
264
|
-
|
|
266
|
+
files: string[];
|
|
267
|
+
};
|
|
268
|
+
type UpdateGroupFilesResponse = {
|
|
269
|
+
id: string;
|
|
270
|
+
status: string;
|
|
265
271
|
};
|
|
266
272
|
type SignatureOptions = {
|
|
267
273
|
cid: string;
|
|
@@ -346,6 +352,7 @@ declare class FilterFiles {
|
|
|
346
352
|
limit(limit: number): FilterFiles;
|
|
347
353
|
cidPending(cidPending: boolean): FilterFiles;
|
|
348
354
|
metadata(keyvalues: Record<string, string>): FilterFiles;
|
|
355
|
+
noGroup(noGroup: boolean): FilterFiles;
|
|
349
356
|
pageToken(pageToken: string): FilterFiles;
|
|
350
357
|
then(onfulfilled?: ((value: FileListResponse) => any) | null): Promise<any>;
|
|
351
358
|
private fetchPage;
|
|
@@ -403,6 +410,8 @@ declare class Groups {
|
|
|
403
410
|
create(options: GroupOptions): Promise<GroupResponseItem>;
|
|
404
411
|
list(): FilterGroups;
|
|
405
412
|
get(options: GetGroupOptions): Promise<GroupResponseItem>;
|
|
413
|
+
addFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
|
|
414
|
+
removeFiles(options: GroupCIDOptions): Promise<UpdateGroupFilesResponse[]>;
|
|
406
415
|
update(options: UpdateGroupOptions): Promise<GroupResponseItem>;
|
|
407
416
|
delete(options: GetGroupOptions): Promise<string>;
|
|
408
417
|
}
|
|
@@ -421,4 +430,4 @@ declare class FilterGroups {
|
|
|
421
430
|
all(): Promise<GroupResponseItem[]>;
|
|
422
431
|
}
|
|
423
432
|
|
|
424
|
-
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
|
@@ -122,6 +122,9 @@ var uploadFile = async (config, file, options) => {
|
|
|
122
122
|
if (options?.groupId) {
|
|
123
123
|
data.append("group_id", options.groupId);
|
|
124
124
|
}
|
|
125
|
+
if (options?.metadata?.keyvalues) {
|
|
126
|
+
data.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
|
|
127
|
+
}
|
|
125
128
|
let headers;
|
|
126
129
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
127
130
|
headers = {
|
|
@@ -188,6 +191,9 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
188
191
|
if (options?.groupId) {
|
|
189
192
|
data.append("group_id", options.groupId);
|
|
190
193
|
}
|
|
194
|
+
if (options?.metadata?.keyvalues) {
|
|
195
|
+
data.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
|
|
196
|
+
}
|
|
191
197
|
let headers;
|
|
192
198
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
193
199
|
headers = {
|
|
@@ -266,6 +272,9 @@ var uploadUrl = async (config, url, options) => {
|
|
|
266
272
|
if (options?.groupId) {
|
|
267
273
|
data.append("group_id", options.groupId);
|
|
268
274
|
}
|
|
275
|
+
if (options?.metadata?.keyvalues) {
|
|
276
|
+
data.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
|
|
277
|
+
}
|
|
269
278
|
let headers;
|
|
270
279
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
271
280
|
headers = {
|
|
@@ -332,6 +341,9 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
332
341
|
if (options?.groupId) {
|
|
333
342
|
data.append("group_id", options.groupId);
|
|
334
343
|
}
|
|
344
|
+
if (options?.metadata?.keyvalues) {
|
|
345
|
+
data.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
|
|
346
|
+
}
|
|
335
347
|
let headers;
|
|
336
348
|
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
337
349
|
headers = {
|
|
@@ -470,7 +482,8 @@ var listFiles = async (config, options) => {
|
|
|
470
482
|
mimeType,
|
|
471
483
|
pageToken,
|
|
472
484
|
cidPending,
|
|
473
|
-
metadata
|
|
485
|
+
metadata,
|
|
486
|
+
noGroup
|
|
474
487
|
} = options;
|
|
475
488
|
if (limit)
|
|
476
489
|
params.append("limit", limit.toString());
|
|
@@ -488,6 +501,8 @@ var listFiles = async (config, options) => {
|
|
|
488
501
|
params.append("pageToken", pageToken);
|
|
489
502
|
if (cidPending)
|
|
490
503
|
params.append("cidPending", "true");
|
|
504
|
+
if (noGroup)
|
|
505
|
+
params.append("group", "null");
|
|
491
506
|
if (metadata && typeof metadata === "object") {
|
|
492
507
|
Object.entries(metadata).forEach(([key, value]) => {
|
|
493
508
|
params.append(`metadata[${key}]`, value.toString());
|
|
@@ -1125,6 +1140,82 @@ var getGroup = async (config, options) => {
|
|
|
1125
1140
|
}
|
|
1126
1141
|
};
|
|
1127
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
|
+
|
|
1128
1219
|
// src/core/groups/updateGroup.ts
|
|
1129
1220
|
var updateGroup = async (config, options) => {
|
|
1130
1221
|
if (!config) {
|
|
@@ -1187,6 +1278,82 @@ var updateGroup = async (config, options) => {
|
|
|
1187
1278
|
}
|
|
1188
1279
|
};
|
|
1189
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
|
+
|
|
1190
1357
|
// src/core/groups/deleteGroup.ts
|
|
1191
1358
|
var deleteGroup = async (config, options) => {
|
|
1192
1359
|
if (!config) {
|
|
@@ -1740,6 +1907,10 @@ var FilterFiles = class {
|
|
|
1740
1907
|
this.query.metadata = keyvalues;
|
|
1741
1908
|
return this;
|
|
1742
1909
|
}
|
|
1910
|
+
noGroup(noGroup) {
|
|
1911
|
+
this.query.noGroup = noGroup;
|
|
1912
|
+
return this;
|
|
1913
|
+
}
|
|
1743
1914
|
pageToken(pageToken) {
|
|
1744
1915
|
this.query.pageToken = pageToken;
|
|
1745
1916
|
return this;
|
|
@@ -1971,12 +2142,12 @@ var Groups = class {
|
|
|
1971
2142
|
get(options) {
|
|
1972
2143
|
return getGroup(this.config, options);
|
|
1973
2144
|
}
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2145
|
+
addFiles(options) {
|
|
2146
|
+
return addToGroup(this.config, options);
|
|
2147
|
+
}
|
|
2148
|
+
removeFiles(options) {
|
|
2149
|
+
return removeFromGroup(this.config, options);
|
|
2150
|
+
}
|
|
1980
2151
|
update(options) {
|
|
1981
2152
|
return updateGroup(this.config, options);
|
|
1982
2153
|
}
|