pinata 1.8.1 → 1.9.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 +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.js +312 -59
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +312 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -172,11 +172,33 @@ var uploadFile = async (config, file, options) => {
|
|
|
172
172
|
const fileInfoReq = await fetch(`${dataEndpoint}/files/${fileId}`, {
|
|
173
173
|
method: "GET",
|
|
174
174
|
headers: {
|
|
175
|
-
Authorization: `Bearer ${
|
|
175
|
+
Authorization: `Bearer ${jwt}`
|
|
176
176
|
}
|
|
177
177
|
});
|
|
178
178
|
const fileInfo = await fileInfoReq.json();
|
|
179
179
|
const data2 = fileInfo.data;
|
|
180
|
+
if (options?.vectorize) {
|
|
181
|
+
const vectorReq = await fetch(
|
|
182
|
+
`${endpoint}/vectorize/files/${data2.id}`,
|
|
183
|
+
{
|
|
184
|
+
method: "POST",
|
|
185
|
+
headers: {
|
|
186
|
+
Authorization: `Bearer ${jwt}`
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
if (vectorReq.ok) {
|
|
191
|
+
data2.vectorized = true;
|
|
192
|
+
return data2;
|
|
193
|
+
} else {
|
|
194
|
+
const errorData = await vectorReq.text();
|
|
195
|
+
throw new NetworkError(
|
|
196
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
197
|
+
vectorReq.status,
|
|
198
|
+
errorData
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
180
202
|
return data2;
|
|
181
203
|
}
|
|
182
204
|
}
|
|
@@ -224,6 +246,28 @@ var uploadFile = async (config, file, options) => {
|
|
|
224
246
|
}
|
|
225
247
|
const res = await request.json();
|
|
226
248
|
const resData = res.data;
|
|
249
|
+
if (options?.vectorize) {
|
|
250
|
+
const vectorReq = await fetch(
|
|
251
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
252
|
+
{
|
|
253
|
+
method: "POST",
|
|
254
|
+
headers: {
|
|
255
|
+
Authorization: `Bearer ${jwt}`
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
if (vectorReq.ok) {
|
|
260
|
+
resData.vectorized = true;
|
|
261
|
+
return resData;
|
|
262
|
+
} else {
|
|
263
|
+
const errorData = await vectorReq.text();
|
|
264
|
+
throw new NetworkError(
|
|
265
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
266
|
+
vectorReq.status,
|
|
267
|
+
errorData
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
227
271
|
return resData;
|
|
228
272
|
} catch (error) {
|
|
229
273
|
if (error instanceof PinataError) {
|
|
@@ -293,6 +337,28 @@ var uploadBase64 = async (config, base64String, options) => {
|
|
|
293
337
|
}
|
|
294
338
|
const res = await request.json();
|
|
295
339
|
const resData = res.data;
|
|
340
|
+
if (options?.vectorize) {
|
|
341
|
+
const vectorReq = await fetch(
|
|
342
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
343
|
+
{
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: {
|
|
346
|
+
Authorization: `Bearer ${jwt}`
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
if (vectorReq.ok) {
|
|
351
|
+
resData.vectorized = true;
|
|
352
|
+
return resData;
|
|
353
|
+
} else {
|
|
354
|
+
const errorData = await vectorReq.text();
|
|
355
|
+
throw new NetworkError(
|
|
356
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
357
|
+
vectorReq.status,
|
|
358
|
+
errorData
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
296
362
|
return resData;
|
|
297
363
|
} catch (error) {
|
|
298
364
|
if (error instanceof PinataError) {
|
|
@@ -374,6 +440,28 @@ var uploadUrl = async (config, url, options) => {
|
|
|
374
440
|
}
|
|
375
441
|
const res = await request.json();
|
|
376
442
|
const resData = res.data;
|
|
443
|
+
if (options?.vectorize) {
|
|
444
|
+
const vectorReq = await fetch(
|
|
445
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
446
|
+
{
|
|
447
|
+
method: "POST",
|
|
448
|
+
headers: {
|
|
449
|
+
Authorization: `Bearer ${jwt}`
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
);
|
|
453
|
+
if (vectorReq.ok) {
|
|
454
|
+
resData.vectorized = true;
|
|
455
|
+
return resData;
|
|
456
|
+
} else {
|
|
457
|
+
const errorData = await vectorReq.text();
|
|
458
|
+
throw new NetworkError(
|
|
459
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
460
|
+
vectorReq.status,
|
|
461
|
+
errorData
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
377
465
|
return resData;
|
|
378
466
|
} catch (error) {
|
|
379
467
|
if (error instanceof PinataError) {
|
|
@@ -443,6 +531,28 @@ var uploadJson = async (config, jsonData, options) => {
|
|
|
443
531
|
}
|
|
444
532
|
const res = await request.json();
|
|
445
533
|
const resData = res.data;
|
|
534
|
+
if (options?.vectorize) {
|
|
535
|
+
const vectorReq = await fetch(
|
|
536
|
+
`${endpoint}/vectorize/files/${resData.id}`,
|
|
537
|
+
{
|
|
538
|
+
method: "POST",
|
|
539
|
+
headers: {
|
|
540
|
+
Authorization: `Bearer ${jwt}`
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
);
|
|
544
|
+
if (vectorReq.ok) {
|
|
545
|
+
resData.vectorized = true;
|
|
546
|
+
return resData;
|
|
547
|
+
} else {
|
|
548
|
+
const errorData = await vectorReq.text();
|
|
549
|
+
throw new NetworkError(
|
|
550
|
+
`HTTP error during vectorization: ${errorData}`,
|
|
551
|
+
vectorReq.status,
|
|
552
|
+
errorData
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
446
556
|
return resData;
|
|
447
557
|
} catch (error) {
|
|
448
558
|
if (error instanceof PinataError) {
|
|
@@ -1990,6 +2100,191 @@ var createSignedURL = async (config, options, imgOpts) => {
|
|
|
1990
2100
|
}
|
|
1991
2101
|
};
|
|
1992
2102
|
|
|
2103
|
+
// src/core/files/vectorizeFile.ts
|
|
2104
|
+
var vectorizeFile = async (config, fileId) => {
|
|
2105
|
+
if (!config) {
|
|
2106
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2107
|
+
}
|
|
2108
|
+
let headers;
|
|
2109
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2110
|
+
headers = {
|
|
2111
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2112
|
+
...config.customHeaders
|
|
2113
|
+
};
|
|
2114
|
+
} else {
|
|
2115
|
+
headers = {
|
|
2116
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2117
|
+
Source: "sdk/vectorizeFile"
|
|
2118
|
+
};
|
|
2119
|
+
}
|
|
2120
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2121
|
+
if (config.uploadUrl) {
|
|
2122
|
+
endpoint = config.uploadUrl;
|
|
2123
|
+
}
|
|
2124
|
+
try {
|
|
2125
|
+
const request = await fetch(`${endpoint}/vectorize/files/${fileId}`, {
|
|
2126
|
+
method: "POST",
|
|
2127
|
+
headers
|
|
2128
|
+
});
|
|
2129
|
+
if (!request.ok) {
|
|
2130
|
+
const errorData = await request.text();
|
|
2131
|
+
if (request.status === 401 || request.status === 403) {
|
|
2132
|
+
throw new AuthenticationError(
|
|
2133
|
+
`Authentication failed: ${errorData}`,
|
|
2134
|
+
request.status,
|
|
2135
|
+
errorData
|
|
2136
|
+
);
|
|
2137
|
+
}
|
|
2138
|
+
throw new NetworkError(
|
|
2139
|
+
`HTTP error: ${errorData}`,
|
|
2140
|
+
request.status,
|
|
2141
|
+
errorData
|
|
2142
|
+
);
|
|
2143
|
+
}
|
|
2144
|
+
const res = await request.json();
|
|
2145
|
+
return res;
|
|
2146
|
+
} catch (error) {
|
|
2147
|
+
if (error instanceof PinataError) {
|
|
2148
|
+
throw error;
|
|
2149
|
+
}
|
|
2150
|
+
if (error instanceof Error) {
|
|
2151
|
+
throw new PinataError(
|
|
2152
|
+
`Error processing vectorize file: ${error.message}`
|
|
2153
|
+
);
|
|
2154
|
+
}
|
|
2155
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
// src/core/files/vectorizeQuery.ts
|
|
2160
|
+
var vectorizeQuery = async (config, options) => {
|
|
2161
|
+
if (!config) {
|
|
2162
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2163
|
+
}
|
|
2164
|
+
let headers;
|
|
2165
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2166
|
+
headers = {
|
|
2167
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2168
|
+
...config.customHeaders
|
|
2169
|
+
};
|
|
2170
|
+
} else {
|
|
2171
|
+
headers = {
|
|
2172
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2173
|
+
Source: "sdk/vectorQuery"
|
|
2174
|
+
};
|
|
2175
|
+
}
|
|
2176
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2177
|
+
if (config.uploadUrl) {
|
|
2178
|
+
endpoint = config.uploadUrl;
|
|
2179
|
+
}
|
|
2180
|
+
const body = JSON.stringify({
|
|
2181
|
+
text: options.query
|
|
2182
|
+
});
|
|
2183
|
+
try {
|
|
2184
|
+
const request = await fetch(
|
|
2185
|
+
`${endpoint}/vectorize/groups/${options.groupId}/query`,
|
|
2186
|
+
{
|
|
2187
|
+
method: "POST",
|
|
2188
|
+
headers,
|
|
2189
|
+
body
|
|
2190
|
+
}
|
|
2191
|
+
);
|
|
2192
|
+
if (!request.ok) {
|
|
2193
|
+
const errorData = await request.text();
|
|
2194
|
+
if (request.status === 401 || request.status === 403) {
|
|
2195
|
+
throw new AuthenticationError(
|
|
2196
|
+
`Authentication failed: ${errorData}`,
|
|
2197
|
+
request.status,
|
|
2198
|
+
errorData
|
|
2199
|
+
);
|
|
2200
|
+
}
|
|
2201
|
+
throw new NetworkError(
|
|
2202
|
+
`HTTP error: ${errorData}`,
|
|
2203
|
+
request.status,
|
|
2204
|
+
errorData
|
|
2205
|
+
);
|
|
2206
|
+
}
|
|
2207
|
+
const res = await request.json();
|
|
2208
|
+
const resData = res.data;
|
|
2209
|
+
if (options.returnFile) {
|
|
2210
|
+
if (resData.matches.length === 0) {
|
|
2211
|
+
throw new PinataError(`No files returned in query to fetch`);
|
|
2212
|
+
}
|
|
2213
|
+
console.log(config.pinataGateway);
|
|
2214
|
+
const cid = resData.matches[0].cid;
|
|
2215
|
+
const fileRes = await getCid(config, cid, void 0);
|
|
2216
|
+
return fileRes;
|
|
2217
|
+
}
|
|
2218
|
+
return resData;
|
|
2219
|
+
} catch (error) {
|
|
2220
|
+
if (error instanceof PinataError) {
|
|
2221
|
+
throw error;
|
|
2222
|
+
}
|
|
2223
|
+
if (error instanceof Error) {
|
|
2224
|
+
throw new PinataError(
|
|
2225
|
+
`Error processing vectorize file: ${error.message}`
|
|
2226
|
+
);
|
|
2227
|
+
}
|
|
2228
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2229
|
+
}
|
|
2230
|
+
};
|
|
2231
|
+
|
|
2232
|
+
// src/core/files/deleteFileVectors.ts
|
|
2233
|
+
var deleteFileVectors = async (config, fileId) => {
|
|
2234
|
+
if (!config) {
|
|
2235
|
+
throw new ValidationError("Pinata configuration is missing");
|
|
2236
|
+
}
|
|
2237
|
+
let headers;
|
|
2238
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2239
|
+
headers = {
|
|
2240
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2241
|
+
...config.customHeaders
|
|
2242
|
+
};
|
|
2243
|
+
} else {
|
|
2244
|
+
headers = {
|
|
2245
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2246
|
+
Source: "sdk/vectorizeFile"
|
|
2247
|
+
};
|
|
2248
|
+
}
|
|
2249
|
+
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2250
|
+
if (config.uploadUrl) {
|
|
2251
|
+
endpoint = config.uploadUrl;
|
|
2252
|
+
}
|
|
2253
|
+
try {
|
|
2254
|
+
const request = await fetch(`${endpoint}/vectorize/files/${fileId}`, {
|
|
2255
|
+
method: "DELETE",
|
|
2256
|
+
headers
|
|
2257
|
+
});
|
|
2258
|
+
if (!request.ok) {
|
|
2259
|
+
const errorData = await request.text();
|
|
2260
|
+
if (request.status === 401 || request.status === 403) {
|
|
2261
|
+
throw new AuthenticationError(
|
|
2262
|
+
`Authentication failed: ${errorData}`,
|
|
2263
|
+
request.status,
|
|
2264
|
+
errorData
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
throw new NetworkError(
|
|
2268
|
+
`HTTP error: ${errorData}`,
|
|
2269
|
+
request.status,
|
|
2270
|
+
errorData
|
|
2271
|
+
);
|
|
2272
|
+
}
|
|
2273
|
+
const res = await request.json();
|
|
2274
|
+
return res;
|
|
2275
|
+
} catch (error) {
|
|
2276
|
+
if (error instanceof PinataError) {
|
|
2277
|
+
throw error;
|
|
2278
|
+
}
|
|
2279
|
+
if (error instanceof Error) {
|
|
2280
|
+
throw new PinataError(
|
|
2281
|
+
`Error processing vectorize file: ${error.message}`
|
|
2282
|
+
);
|
|
2283
|
+
}
|
|
2284
|
+
throw new PinataError("An unknown error occurred while vectorizing file");
|
|
2285
|
+
}
|
|
2286
|
+
};
|
|
2287
|
+
|
|
1993
2288
|
// src/core/pinataSDK.ts
|
|
1994
2289
|
var formatConfig = (config) => {
|
|
1995
2290
|
let gateway = config?.pinataGateway;
|
|
@@ -2065,6 +2360,15 @@ var Files = class {
|
|
|
2065
2360
|
deleteSwap(cid) {
|
|
2066
2361
|
return deleteSwap(this.config, cid);
|
|
2067
2362
|
}
|
|
2363
|
+
vectorize(fileId) {
|
|
2364
|
+
return vectorizeFile(this.config, fileId);
|
|
2365
|
+
}
|
|
2366
|
+
queryVectors(options) {
|
|
2367
|
+
return vectorizeQuery(this.config, options);
|
|
2368
|
+
}
|
|
2369
|
+
deleteVectors(fileId) {
|
|
2370
|
+
return deleteFileVectors(this.config, fileId);
|
|
2371
|
+
}
|
|
2068
2372
|
};
|
|
2069
2373
|
var UploadBuilder = class {
|
|
2070
2374
|
constructor(config, uploadFunction, ...args) {
|
|
@@ -2080,6 +2384,10 @@ var UploadBuilder = class {
|
|
|
2080
2384
|
this.keys = jwt;
|
|
2081
2385
|
return this;
|
|
2082
2386
|
}
|
|
2387
|
+
vectorize() {
|
|
2388
|
+
this.vector = true;
|
|
2389
|
+
return this;
|
|
2390
|
+
}
|
|
2083
2391
|
// cidVersion(v: 0 | 1): UploadBuilder<T> {
|
|
2084
2392
|
// this.version = v;
|
|
2085
2393
|
// return this;
|
|
@@ -2099,6 +2407,9 @@ var UploadBuilder = class {
|
|
|
2099
2407
|
if (this.groupId) {
|
|
2100
2408
|
options.groupId = this.groupId;
|
|
2101
2409
|
}
|
|
2410
|
+
if (this.vector) {
|
|
2411
|
+
options.vectorize = this.vector;
|
|
2412
|
+
}
|
|
2102
2413
|
this.args[this.args.length - 1] = options;
|
|
2103
2414
|
return this.uploadFunction(this.config, ...this.args).then(
|
|
2104
2415
|
onfulfilled,
|
|
@@ -2239,42 +2550,6 @@ var Gateways = class {
|
|
|
2239
2550
|
createSignedURL(options) {
|
|
2240
2551
|
return new OptimizeImageCreateSignedURL(this.config, options);
|
|
2241
2552
|
}
|
|
2242
|
-
// topUsageAnalytics(options: {
|
|
2243
|
-
// domain: string;
|
|
2244
|
-
// start: string;
|
|
2245
|
-
// end: string;
|
|
2246
|
-
// sortBy: "requests" | "bandwidth";
|
|
2247
|
-
// attribute:
|
|
2248
|
-
// | "cid"
|
|
2249
|
-
// | "country"
|
|
2250
|
-
// | "region"
|
|
2251
|
-
// | "user_agent"
|
|
2252
|
-
// | "referer"
|
|
2253
|
-
// | "file_name";
|
|
2254
|
-
// }): TopGatewayAnalyticsBuilder {
|
|
2255
|
-
// return new TopGatewayAnalyticsBuilder(
|
|
2256
|
-
// this.config,
|
|
2257
|
-
// options.domain,
|
|
2258
|
-
// options.start,
|
|
2259
|
-
// options.end,
|
|
2260
|
-
// options.sortBy,
|
|
2261
|
-
// options.attribute,
|
|
2262
|
-
// );
|
|
2263
|
-
// }
|
|
2264
|
-
// dateIntervalAnalytics(options: {
|
|
2265
|
-
// domain: string;
|
|
2266
|
-
// start: string;
|
|
2267
|
-
// end: string;
|
|
2268
|
-
// interval: "day" | "week";
|
|
2269
|
-
// }): TimeIntervalGatewayAnalyticsBuilder {
|
|
2270
|
-
// return new TimeIntervalGatewayAnalyticsBuilder(
|
|
2271
|
-
// this.config,
|
|
2272
|
-
// options.domain,
|
|
2273
|
-
// options.start,
|
|
2274
|
-
// options.end,
|
|
2275
|
-
// options.interval,
|
|
2276
|
-
// );
|
|
2277
|
-
// }
|
|
2278
2553
|
};
|
|
2279
2554
|
var OptimizeImageGetCid = class {
|
|
2280
2555
|
constructor(config, cid) {
|
|
@@ -2500,28 +2775,6 @@ var Analytics = class {
|
|
|
2500
2775
|
this.requests.updateConfig(newConfig);
|
|
2501
2776
|
this.bandwidth.updateConfig(newConfig);
|
|
2502
2777
|
}
|
|
2503
|
-
// detailed(options: {
|
|
2504
|
-
// domain: string;
|
|
2505
|
-
// start: string;
|
|
2506
|
-
// end: string;
|
|
2507
|
-
// sortBy: "requests" | "bandwidth";
|
|
2508
|
-
// attribute:
|
|
2509
|
-
// | "cid"
|
|
2510
|
-
// | "country"
|
|
2511
|
-
// | "region"
|
|
2512
|
-
// | "user_agent"
|
|
2513
|
-
// | "referer"
|
|
2514
|
-
// | "file_name";
|
|
2515
|
-
// }): TopAnalyticsBuilder {
|
|
2516
|
-
// return new TopAnalyticsBuilder(
|
|
2517
|
-
// this.config,
|
|
2518
|
-
// options.domain,
|
|
2519
|
-
// options.start,
|
|
2520
|
-
// options.end,
|
|
2521
|
-
// options.sortBy,
|
|
2522
|
-
// options.attribute,
|
|
2523
|
-
// );
|
|
2524
|
-
// }
|
|
2525
2778
|
summary(options) {
|
|
2526
2779
|
return new TimeIntervalAnalyticsBuilder(
|
|
2527
2780
|
this.config,
|