pinata 1.8.1 → 1.9.1
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 +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +311 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +311 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -19,6 +19,8 @@ type UploadResponse = {
|
|
|
19
19
|
mime_type: string;
|
|
20
20
|
user_id: string;
|
|
21
21
|
group_id: string | null;
|
|
22
|
+
is_duplicate: true | null;
|
|
23
|
+
vectorized: true | null;
|
|
22
24
|
};
|
|
23
25
|
type FileObject = {
|
|
24
26
|
name: string;
|
|
@@ -41,6 +43,7 @@ type UploadOptions = {
|
|
|
41
43
|
metadata?: PinataMetadata;
|
|
42
44
|
keys?: string;
|
|
43
45
|
groupId?: string;
|
|
46
|
+
vectorize?: boolean;
|
|
44
47
|
};
|
|
45
48
|
type DeleteResponse = {
|
|
46
49
|
id: string;
|
|
@@ -296,6 +299,23 @@ type ContainsCIDResponse = {
|
|
|
296
299
|
containsCid: boolean;
|
|
297
300
|
cid: string | null;
|
|
298
301
|
};
|
|
302
|
+
type VectorizeFileResponse = {
|
|
303
|
+
status: boolean;
|
|
304
|
+
};
|
|
305
|
+
type VectorizeQuery = {
|
|
306
|
+
groupId: string;
|
|
307
|
+
query: string;
|
|
308
|
+
returnFile?: boolean;
|
|
309
|
+
};
|
|
310
|
+
type VectorQueryMatch = {
|
|
311
|
+
file_id: string;
|
|
312
|
+
cid: string;
|
|
313
|
+
score: number;
|
|
314
|
+
};
|
|
315
|
+
type VectorizeQueryResponse = {
|
|
316
|
+
count: number;
|
|
317
|
+
matches: VectorQueryMatch[];
|
|
318
|
+
};
|
|
299
319
|
|
|
300
320
|
declare class PinataSDK {
|
|
301
321
|
config: PinataConfig | undefined;
|
|
@@ -320,6 +340,9 @@ declare class Files {
|
|
|
320
340
|
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
321
341
|
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
322
342
|
deleteSwap(cid: string): Promise<string>;
|
|
343
|
+
vectorize(fileId: string): Promise<VectorizeFileResponse>;
|
|
344
|
+
queryVectors(options: VectorizeQuery): Promise<VectorizeQueryResponse | GetCIDResponse>;
|
|
345
|
+
deleteVectors(fileId: string): Promise<VectorizeFileResponse>;
|
|
323
346
|
}
|
|
324
347
|
declare class UploadBuilder<T> {
|
|
325
348
|
private config;
|
|
@@ -328,9 +351,11 @@ declare class UploadBuilder<T> {
|
|
|
328
351
|
private metadata;
|
|
329
352
|
private keys;
|
|
330
353
|
private groupId;
|
|
354
|
+
private vector;
|
|
331
355
|
constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
|
|
332
356
|
addMetadata(metadata: PinataMetadata): UploadBuilder<T>;
|
|
333
357
|
key(jwt: string): UploadBuilder<T>;
|
|
358
|
+
vectorize(): UploadBuilder<T>;
|
|
334
359
|
group(groupId: string): UploadBuilder<T>;
|
|
335
360
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
336
361
|
}
|
|
@@ -499,4 +524,4 @@ declare class TimeIntervalAnalyticsBuilder extends AnalyticsBuilder<TimeInterval
|
|
|
499
524
|
all(): Promise<TimeIntervalAnalyticsResponse>;
|
|
500
525
|
}
|
|
501
526
|
|
|
502
|
-
export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, 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 TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
|
|
527
|
+
export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, 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 TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ type UploadResponse = {
|
|
|
19
19
|
mime_type: string;
|
|
20
20
|
user_id: string;
|
|
21
21
|
group_id: string | null;
|
|
22
|
+
is_duplicate: true | null;
|
|
23
|
+
vectorized: true | null;
|
|
22
24
|
};
|
|
23
25
|
type FileObject = {
|
|
24
26
|
name: string;
|
|
@@ -41,6 +43,7 @@ type UploadOptions = {
|
|
|
41
43
|
metadata?: PinataMetadata;
|
|
42
44
|
keys?: string;
|
|
43
45
|
groupId?: string;
|
|
46
|
+
vectorize?: boolean;
|
|
44
47
|
};
|
|
45
48
|
type DeleteResponse = {
|
|
46
49
|
id: string;
|
|
@@ -296,6 +299,23 @@ type ContainsCIDResponse = {
|
|
|
296
299
|
containsCid: boolean;
|
|
297
300
|
cid: string | null;
|
|
298
301
|
};
|
|
302
|
+
type VectorizeFileResponse = {
|
|
303
|
+
status: boolean;
|
|
304
|
+
};
|
|
305
|
+
type VectorizeQuery = {
|
|
306
|
+
groupId: string;
|
|
307
|
+
query: string;
|
|
308
|
+
returnFile?: boolean;
|
|
309
|
+
};
|
|
310
|
+
type VectorQueryMatch = {
|
|
311
|
+
file_id: string;
|
|
312
|
+
cid: string;
|
|
313
|
+
score: number;
|
|
314
|
+
};
|
|
315
|
+
type VectorizeQueryResponse = {
|
|
316
|
+
count: number;
|
|
317
|
+
matches: VectorQueryMatch[];
|
|
318
|
+
};
|
|
299
319
|
|
|
300
320
|
declare class PinataSDK {
|
|
301
321
|
config: PinataConfig | undefined;
|
|
@@ -320,6 +340,9 @@ declare class Files {
|
|
|
320
340
|
addSwap(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
321
341
|
getSwapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
322
342
|
deleteSwap(cid: string): Promise<string>;
|
|
343
|
+
vectorize(fileId: string): Promise<VectorizeFileResponse>;
|
|
344
|
+
queryVectors(options: VectorizeQuery): Promise<VectorizeQueryResponse | GetCIDResponse>;
|
|
345
|
+
deleteVectors(fileId: string): Promise<VectorizeFileResponse>;
|
|
323
346
|
}
|
|
324
347
|
declare class UploadBuilder<T> {
|
|
325
348
|
private config;
|
|
@@ -328,9 +351,11 @@ declare class UploadBuilder<T> {
|
|
|
328
351
|
private metadata;
|
|
329
352
|
private keys;
|
|
330
353
|
private groupId;
|
|
354
|
+
private vector;
|
|
331
355
|
constructor(config: PinataConfig | undefined, uploadFunction: (config: PinataConfig | undefined, ...args: any[]) => Promise<T>, ...args: any[]);
|
|
332
356
|
addMetadata(metadata: PinataMetadata): UploadBuilder<T>;
|
|
333
357
|
key(jwt: string): UploadBuilder<T>;
|
|
358
|
+
vectorize(): UploadBuilder<T>;
|
|
334
359
|
group(groupId: string): UploadBuilder<T>;
|
|
335
360
|
then<TResult1 = T, TResult2 = never>(onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined): Promise<TResult1 | TResult2>;
|
|
336
361
|
}
|
|
@@ -499,4 +524,4 @@ declare class TimeIntervalAnalyticsBuilder extends AnalyticsBuilder<TimeInterval
|
|
|
499
524
|
all(): Promise<TimeIntervalAnalyticsResponse>;
|
|
500
525
|
}
|
|
501
526
|
|
|
502
|
-
export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, 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 TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse };
|
|
527
|
+
export { type AnalyticsQuery, type AuthTestResponse, type ContainsCIDResponse, type ContentType, type DataEndponts, type DeleteResponse, type Endpoints, type FileListItem, type FileListQuery, type FileListResponse, type FileObject, 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 TimeIntervalAnalyticsQuery, type TimeIntervalAnalyticsResponse, type TimePeriodItem, type TopAnalyticsItem, type TopAnalyticsQuery, type TopAnalyticsResponse, type UpdateFileOptions, type UpdateGroupFilesResponse, type UpdateGroupOptions, type UploadOptions, type UploadResponse, type UserPinnedDataResponse, type VectorQueryMatch, type VectorizeFileResponse, type VectorizeQuery, type VectorizeQueryResponse };
|
package/dist/index.js
CHANGED
|
@@ -198,11 +198,33 @@ var uploadFile = async (config, file, options) => {
|
|
|
198
198
|
const fileInfoReq = await fetch(`${dataEndpoint}/files/${fileId}`, {
|
|
199
199
|
method: "GET",
|
|
200
200
|
headers: {
|
|
201
|
-
Authorization: `Bearer ${
|
|
201
|
+
Authorization: `Bearer ${jwt}`
|
|
202
202
|
}
|
|
203
203
|
});
|
|
204
204
|
const fileInfo = await fileInfoReq.json();
|
|
205
205
|
const data2 = fileInfo.data;
|
|
206
|
+
if (options?.vectorize) {
|
|
207
|
+
const vectorReq = await fetch(
|
|
208
|
+
`${endpoint}/vectorize/files/${data2.id}`,
|
|
209
|
+
{
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers: {
|
|
212
|
+
Authorization: `Bearer ${jwt}`
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
if (vectorReq.ok) {
|
|
217
|
+
data2.vectorized = true;
|
|
218
|
+
return data2;
|
|
219
|
+
} else {
|
|
220
|
+
const errorData = await vectorReq.text();
|
|
221
|
+
throw new NetworkError(
|
|
222
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
223
|
+
vectorReq.status,
|
|
224
|
+
errorData
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
206
228
|
return data2;
|
|
207
229
|
}
|
|
208
230
|
}
|
|
@@ -250,6 +272,28 @@ var uploadFile = async (config, file, options) => {
|
|
|
250
272
|
}
|
|
251
273
|
const res = await request.json();
|
|
252
274
|
const resData = res.data;
|
|
275
|
+
if (options?.vectorize) {
|
|
276
|
+
const vectorReq = await fetch(
|
|
277
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
278
|
+
{
|
|
279
|
+
method: "POST",
|
|
280
|
+
headers: {
|
|
281
|
+
Authorization: `Bearer ${jwt}`
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
);
|
|
285
|
+
if (vectorReq.ok) {
|
|
286
|
+
resData.vectorized = true;
|
|
287
|
+
return resData;
|
|
288
|
+
} else {
|
|
289
|
+
const errorData = await vectorReq.text();
|
|
290
|
+
throw new NetworkError(
|
|
291
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
292
|
+
vectorReq.status,
|
|
293
|
+
errorData
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
253
297
|
return resData;
|
|
254
298
|
} catch (error) {
|
|
255
299
|
if (error instanceof PinataError) {
|
|
@@ -319,6 +363,28 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
319
363
|
}
|
|
320
364
|
const res = await request.json();
|
|
321
365
|
const resData = res.data;
|
|
366
|
+
if (options?.vectorize) {
|
|
367
|
+
const vectorReq = await fetch(
|
|
368
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
369
|
+
{
|
|
370
|
+
method: "POST",
|
|
371
|
+
headers: {
|
|
372
|
+
Authorization: `Bearer ${jwt}`
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
if (vectorReq.ok) {
|
|
377
|
+
resData.vectorized = true;
|
|
378
|
+
return resData;
|
|
379
|
+
} else {
|
|
380
|
+
const errorData = await vectorReq.text();
|
|
381
|
+
throw new NetworkError(
|
|
382
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
383
|
+
vectorReq.status,
|
|
384
|
+
errorData
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
322
388
|
return resData;
|
|
323
389
|
} catch (error) {
|
|
324
390
|
if (error instanceof PinataError) {
|
|
@@ -400,6 +466,28 @@ var uploadUrl = async (config, url, options) => {
|
|
|
400
466
|
}
|
|
401
467
|
const res = await request.json();
|
|
402
468
|
const resData = res.data;
|
|
469
|
+
if (options?.vectorize) {
|
|
470
|
+
const vectorReq = await fetch(
|
|
471
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
472
|
+
{
|
|
473
|
+
method: "POST",
|
|
474
|
+
headers: {
|
|
475
|
+
Authorization: `Bearer ${jwt}`
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
if (vectorReq.ok) {
|
|
480
|
+
resData.vectorized = true;
|
|
481
|
+
return resData;
|
|
482
|
+
} else {
|
|
483
|
+
const errorData = await vectorReq.text();
|
|
484
|
+
throw new NetworkError(
|
|
485
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
486
|
+
vectorReq.status,
|
|
487
|
+
errorData
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
403
491
|
return resData;
|
|
404
492
|
} catch (error) {
|
|
405
493
|
if (error instanceof PinataError) {
|
|
@@ -469,6 +557,28 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
469
557
|
}
|
|
470
558
|
const res = await request.json();
|
|
471
559
|
const resData = res.data;
|
|
560
|
+
if (options?.vectorize) {
|
|
561
|
+
const vectorReq = await fetch(
|
|
562
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
563
|
+
{
|
|
564
|
+
method: "POST",
|
|
565
|
+
headers: {
|
|
566
|
+
Authorization: `Bearer ${jwt}`
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
);
|
|
570
|
+
if (vectorReq.ok) {
|
|
571
|
+
resData.vectorized = true;
|
|
572
|
+
return resData;
|
|
573
|
+
} else {
|
|
574
|
+
const errorData = await vectorReq.text();
|
|
575
|
+
throw new NetworkError(
|
|
576
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
577
|
+
vectorReq.status,
|
|
578
|
+
errorData
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
472
582
|
return resData;
|
|
473
583
|
} catch (error) {
|
|
474
584
|
if (error instanceof PinataError) {
|
|
@@ -2016,6 +2126,190 @@ var createSignedURL = async (config, options, imgOpts) => {
|
|
|
2016
2126
|
}
|
|
2017
2127
|
};
|
|
2018
2128
|
|
|
2129
|
+
// src/core/files/vectorizeFile.ts
|
|
2130
|
+
var vectorizeFile = async (config, fileId) => {
|
|
2131
|
+
if (!config) {
|
|
2132
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2133
|
+
}
|
|
2134
|
+
let headers;
|
|
2135
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2136
|
+
headers = {
|
|
2137
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2138
|
+
...config.customHeaders
|
|
2139
|
+
};
|
|
2140
|
+
} else {
|
|
2141
|
+
headers = {
|
|
2142
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2143
|
+
Source: "sdk/vectorizeFile"
|
|
2144
|
+
};
|
|
2145
|
+
}
|
|
2146
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2147
|
+
if (config.uploadUrl) {
|
|
2148
|
+
endpoint = config.uploadUrl;
|
|
2149
|
+
}
|
|
2150
|
+
try {
|
|
2151
|
+
const request = await fetch(`${endpoint}/vectorize/files/${fileId}`, {
|
|
2152
|
+
method: "POST",
|
|
2153
|
+
headers
|
|
2154
|
+
});
|
|
2155
|
+
if (!request.ok) {
|
|
2156
|
+
const errorData = await request.text();
|
|
2157
|
+
if (request.status === 401 || request.status === 403) {
|
|
2158
|
+
throw new AuthenticationError(
|
|
2159
|
+
`Authentication failed: ${errorData}`,
|
|
2160
|
+
request.status,
|
|
2161
|
+
errorData
|
|
2162
|
+
);
|
|
2163
|
+
}
|
|
2164
|
+
throw new NetworkError(
|
|
2165
|
+
`HTTP error: ${errorData}`,
|
|
2166
|
+
request.status,
|
|
2167
|
+
errorData
|
|
2168
|
+
);
|
|
2169
|
+
}
|
|
2170
|
+
const res = await request.json();
|
|
2171
|
+
return res;
|
|
2172
|
+
} catch (error) {
|
|
2173
|
+
if (error instanceof PinataError) {
|
|
2174
|
+
throw error;
|
|
2175
|
+
}
|
|
2176
|
+
if (error instanceof Error) {
|
|
2177
|
+
throw new PinataError(
|
|
2178
|
+
`Error processing vectorize file: ${error.message}`
|
|
2179
|
+
);
|
|
2180
|
+
}
|
|
2181
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2182
|
+
}
|
|
2183
|
+
};
|
|
2184
|
+
|
|
2185
|
+
// src/core/files/vectorizeQuery.ts
|
|
2186
|
+
var vectorizeQuery = async (config, options) => {
|
|
2187
|
+
if (!config) {
|
|
2188
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2189
|
+
}
|
|
2190
|
+
let headers;
|
|
2191
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2192
|
+
headers = {
|
|
2193
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2194
|
+
...config.customHeaders
|
|
2195
|
+
};
|
|
2196
|
+
} else {
|
|
2197
|
+
headers = {
|
|
2198
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2199
|
+
Source: "sdk/vectorQuery"
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2203
|
+
if (config.uploadUrl) {
|
|
2204
|
+
endpoint = config.uploadUrl;
|
|
2205
|
+
}
|
|
2206
|
+
const body = JSON.stringify({
|
|
2207
|
+
text: options.query
|
|
2208
|
+
});
|
|
2209
|
+
try {
|
|
2210
|
+
const request = await fetch(
|
|
2211
|
+
`${endpoint}/vectorize/groups/${options.groupId}/query`,
|
|
2212
|
+
{
|
|
2213
|
+
method: "POST",
|
|
2214
|
+
headers,
|
|
2215
|
+
body
|
|
2216
|
+
}
|
|
2217
|
+
);
|
|
2218
|
+
if (!request.ok) {
|
|
2219
|
+
const errorData = await request.text();
|
|
2220
|
+
if (request.status === 401 || request.status === 403) {
|
|
2221
|
+
throw new AuthenticationError(
|
|
2222
|
+
`Authentication failed: ${errorData}`,
|
|
2223
|
+
request.status,
|
|
2224
|
+
errorData
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2227
|
+
throw new NetworkError(
|
|
2228
|
+
`HTTP error: ${errorData}`,
|
|
2229
|
+
request.status,
|
|
2230
|
+
errorData
|
|
2231
|
+
);
|
|
2232
|
+
}
|
|
2233
|
+
const res = await request.json();
|
|
2234
|
+
const resData = res.data;
|
|
2235
|
+
if (options.returnFile) {
|
|
2236
|
+
if (resData.matches.length === 0) {
|
|
2237
|
+
throw new PinataError(`No files returned in query to fetch`);
|
|
2238
|
+
}
|
|
2239
|
+
const cid = resData.matches[0].cid;
|
|
2240
|
+
const fileRes = await getCid(config, cid, void 0);
|
|
2241
|
+
return fileRes;
|
|
2242
|
+
}
|
|
2243
|
+
return resData;
|
|
2244
|
+
} catch (error) {
|
|
2245
|
+
if (error instanceof PinataError) {
|
|
2246
|
+
throw error;
|
|
2247
|
+
}
|
|
2248
|
+
if (error instanceof Error) {
|
|
2249
|
+
throw new PinataError(
|
|
2250
|
+
`Error processing vectorize file: ${error.message}`
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
|
|
2257
|
+
// src/core/files/deleteFileVectors.ts
|
|
2258
|
+
var deleteFileVectors = async (config, fileId) => {
|
|
2259
|
+
if (!config) {
|
|
2260
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2261
|
+
}
|
|
2262
|
+
let headers;
|
|
2263
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2264
|
+
headers = {
|
|
2265
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2266
|
+
...config.customHeaders
|
|
2267
|
+
};
|
|
2268
|
+
} else {
|
|
2269
|
+
headers = {
|
|
2270
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2271
|
+
Source: "sdk/vectorizeFile"
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2274
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2275
|
+
if (config.uploadUrl) {
|
|
2276
|
+
endpoint = config.uploadUrl;
|
|
2277
|
+
}
|
|
2278
|
+
try {
|
|
2279
|
+
const request = await fetch(`${endpoint}/vectorize/files/${fileId}`, {
|
|
2280
|
+
method: "DELETE",
|
|
2281
|
+
headers
|
|
2282
|
+
});
|
|
2283
|
+
if (!request.ok) {
|
|
2284
|
+
const errorData = await request.text();
|
|
2285
|
+
if (request.status === 401 || request.status === 403) {
|
|
2286
|
+
throw new AuthenticationError(
|
|
2287
|
+
`Authentication failed: ${errorData}`,
|
|
2288
|
+
request.status,
|
|
2289
|
+
errorData
|
|
2290
|
+
);
|
|
2291
|
+
}
|
|
2292
|
+
throw new NetworkError(
|
|
2293
|
+
`HTTP error: ${errorData}`,
|
|
2294
|
+
request.status,
|
|
2295
|
+
errorData
|
|
2296
|
+
);
|
|
2297
|
+
}
|
|
2298
|
+
const res = await request.json();
|
|
2299
|
+
return res;
|
|
2300
|
+
} catch (error) {
|
|
2301
|
+
if (error instanceof PinataError) {
|
|
2302
|
+
throw error;
|
|
2303
|
+
}
|
|
2304
|
+
if (error instanceof Error) {
|
|
2305
|
+
throw new PinataError(
|
|
2306
|
+
`Error processing vectorize file: ${error.message}`
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
|
|
2019
2313
|
// src/core/pinataSDK.ts
|
|
2020
2314
|
var formatConfig = (config) => {
|
|
2021
2315
|
let gateway = config?.pinataGateway;
|
|
@@ -2091,6 +2385,15 @@ var Files = class {
|
|
|
2091
2385
|
deleteSwap(cid) {
|
|
2092
2386
|
return deleteSwap(this.config, cid);
|
|
2093
2387
|
}
|
|
2388
|
+
vectorize(fileId) {
|
|
2389
|
+
return vectorizeFile(this.config, fileId);
|
|
2390
|
+
}
|
|
2391
|
+
queryVectors(options) {
|
|
2392
|
+
return vectorizeQuery(this.config, options);
|
|
2393
|
+
}
|
|
2394
|
+
deleteVectors(fileId) {
|
|
2395
|
+
return deleteFileVectors(this.config, fileId);
|
|
2396
|
+
}
|
|
2094
2397
|
};
|
|
2095
2398
|
var UploadBuilder = class {
|
|
2096
2399
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -2106,6 +2409,10 @@ var UploadBuilder = class {
|
|
|
2106
2409
|
this.keys = jwt;
|
|
2107
2410
|
return this;
|
|
2108
2411
|
}
|
|
2412
|
+
vectorize() {
|
|
2413
|
+
this.vector = true;
|
|
2414
|
+
return this;
|
|
2415
|
+
}
|
|
2109
2416
|
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
2110
2417
|
// this.version = v;
|
|
2111
2418
|
// return this;
|
|
@@ -2125,6 +2432,9 @@ var UploadBuilder = class {
|
|
|
2125
2432
|
if (this.groupId) {
|
|
2126
2433
|
options.groupId = this.groupId;
|
|
2127
2434
|
}
|
|
2435
|
+
if (this.vector) {
|
|
2436
|
+
options.vectorize = this.vector;
|
|
2437
|
+
}
|
|
2128
2438
|
this.args[this.args.length - 1] = options;
|
|
2129
2439
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2130
2440
|
onfulfilled,
|
|
@@ -2265,42 +2575,6 @@ var Gateways = class {
|
|
|
2265
2575
|
createSignedURL(options) {
|
|
2266
2576
|
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
2267
2577
|
}
|
|
2268
|
-
// topUsageAnalytics(options: {
|
|
2269
|
-
// domain: string;
|
|
2270
|
-
// start: string;
|
|
2271
|
-
// end: string;
|
|
2272
|
-
// sortBy: "requests" | "bandwidth";
|
|
2273
|
-
// attribute:
|
|
2274
|
-
// | "cid"
|
|
2275
|
-
// | "country"
|
|
2276
|
-
// | "region"
|
|
2277
|
-
// | "user_agent"
|
|
2278
|
-
// | "referer"
|
|
2279
|
-
// | "file_name";
|
|
2280
|
-
// }): TopGatewayAnalyticsBuilder {
|
|
2281
|
-
// return new TopGatewayAnalyticsBuilder(
|
|
2282
|
-
// this.config,
|
|
2283
|
-
// options.domain,
|
|
2284
|
-
// options.start,
|
|
2285
|
-
// options.end,
|
|
2286
|
-
// options.sortBy,
|
|
2287
|
-
// options.attribute,
|
|
2288
|
-
// );
|
|
2289
|
-
// }
|
|
2290
|
-
// dateIntervalAnalytics(options: {
|
|
2291
|
-
// domain: string;
|
|
2292
|
-
// start: string;
|
|
2293
|
-
// end: string;
|
|
2294
|
-
// interval: "day" | "week";
|
|
2295
|
-
// }): TimeIntervalGatewayAnalyticsBuilder {
|
|
2296
|
-
// return new TimeIntervalGatewayAnalyticsBuilder(
|
|
2297
|
-
// this.config,
|
|
2298
|
-
// options.domain,
|
|
2299
|
-
// options.start,
|
|
2300
|
-
// options.end,
|
|
2301
|
-
// options.interval,
|
|
2302
|
-
// );
|
|
2303
|
-
// }
|
|
2304
2578
|
};
|
|
2305
2579
|
var OptimizeImageGetCid = class {
|
|
2306
2580
|
constructor(config, cid) {
|
|
@@ -2526,28 +2800,6 @@ var Analytics = class {
|
|
|
2526
2800
|
this.requests.updateConfig(newConfig);
|
|
2527
2801
|
this.bandwidth.updateConfig(newConfig);
|
|
2528
2802
|
}
|
|
2529
|
-
// detailed(options: {
|
|
2530
|
-
// domain: string;
|
|
2531
|
-
// start: string;
|
|
2532
|
-
// end: string;
|
|
2533
|
-
// sortBy: "requests" | "bandwidth";
|
|
2534
|
-
// attribute:
|
|
2535
|
-
// | "cid"
|
|
2536
|
-
// | "country"
|
|
2537
|
-
// | "region"
|
|
2538
|
-
// | "user_agent"
|
|
2539
|
-
// | "referer"
|
|
2540
|
-
// | "file_name";
|
|
2541
|
-
// }): TopAnalyticsBuilder {
|
|
2542
|
-
// return new TopAnalyticsBuilder(
|
|
2543
|
-
// this.config,
|
|
2544
|
-
// options.domain,
|
|
2545
|
-
// options.start,
|
|
2546
|
-
// options.end,
|
|
2547
|
-
// options.sortBy,
|
|
2548
|
-
// options.attribute,
|
|
2549
|
-
// );
|
|
2550
|
-
// }
|
|
2551
2803
|
summary(options) {
|
|
2552
2804
|
return new TimeIntervalAnalyticsBuilder(
|
|
2553
2805
|
this.config,
|