pinata 0.3.0 → 0.3.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 +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +210 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +210 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -268,6 +268,18 @@ type SignatureResponse = {
|
|
|
268
268
|
cid: string;
|
|
269
269
|
signature: string;
|
|
270
270
|
};
|
|
271
|
+
type SwapCidOptions = {
|
|
272
|
+
cid: string;
|
|
273
|
+
swapCid: string;
|
|
274
|
+
};
|
|
275
|
+
type SwapHistoryOptions = {
|
|
276
|
+
cid: string;
|
|
277
|
+
domain: string;
|
|
278
|
+
};
|
|
279
|
+
type SwapCidResponse = {
|
|
280
|
+
mappedCid: string;
|
|
281
|
+
createdAt: string;
|
|
282
|
+
};
|
|
271
283
|
|
|
272
284
|
declare class PinataSDK {
|
|
273
285
|
config: PinataConfig | undefined;
|
|
@@ -355,6 +367,9 @@ declare class Gateways {
|
|
|
355
367
|
end: string;
|
|
356
368
|
interval: "day" | "week";
|
|
357
369
|
}): TimeIntervalGatewayAnalyticsBuilder;
|
|
370
|
+
swapCid(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
371
|
+
swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
372
|
+
deleteSwap(cid: string): Promise<string>;
|
|
358
373
|
}
|
|
359
374
|
declare class FilterPinJobs {
|
|
360
375
|
private config;
|
|
@@ -475,4 +490,4 @@ declare class TimeIntervalGatewayAnalyticsBuilder extends GatewayAnalyticsBuilde
|
|
|
475
490
|
all(): Promise<TimeIntervalGatewayAnalyticsResponse>;
|
|
476
491
|
}
|
|
477
492
|
|
|
478
|
-
export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
|
|
493
|
+
export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
|
package/dist/index.d.ts
CHANGED
|
@@ -268,6 +268,18 @@ type SignatureResponse = {
|
|
|
268
268
|
cid: string;
|
|
269
269
|
signature: string;
|
|
270
270
|
};
|
|
271
|
+
type SwapCidOptions = {
|
|
272
|
+
cid: string;
|
|
273
|
+
swapCid: string;
|
|
274
|
+
};
|
|
275
|
+
type SwapHistoryOptions = {
|
|
276
|
+
cid: string;
|
|
277
|
+
domain: string;
|
|
278
|
+
};
|
|
279
|
+
type SwapCidResponse = {
|
|
280
|
+
mappedCid: string;
|
|
281
|
+
createdAt: string;
|
|
282
|
+
};
|
|
271
283
|
|
|
272
284
|
declare class PinataSDK {
|
|
273
285
|
config: PinataConfig | undefined;
|
|
@@ -355,6 +367,9 @@ declare class Gateways {
|
|
|
355
367
|
end: string;
|
|
356
368
|
interval: "day" | "week";
|
|
357
369
|
}): TimeIntervalGatewayAnalyticsBuilder;
|
|
370
|
+
swapCid(options: SwapCidOptions): Promise<SwapCidResponse>;
|
|
371
|
+
swapHistory(options: SwapHistoryOptions): Promise<SwapCidResponse[]>;
|
|
372
|
+
deleteSwap(cid: string): Promise<string>;
|
|
358
373
|
}
|
|
359
374
|
declare class FilterPinJobs {
|
|
360
375
|
private config;
|
|
@@ -475,4 +490,4 @@ declare class TimeIntervalGatewayAnalyticsBuilder extends GatewayAnalyticsBuilde
|
|
|
475
490
|
all(): Promise<TimeIntervalGatewayAnalyticsResponse>;
|
|
476
491
|
}
|
|
477
492
|
|
|
478
|
-
export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
|
|
493
|
+
export { type AuthTestResponse, type ContentType, type DataEndponts, type Endpoints, type FileObject, type GatewayAnalyticsQuery, type GetCIDResponse, type GetGroupOptions, type GroupCIDOptions, type GroupOptions, type GroupQueryOptions, type GroupResponseItem, type JsonBody, type KeyListItem, type KeyListQuery, type KeyListResponse, type KeyOptions, type KeyPermissions, type KeyResponse, type PinByCIDResponse, type PinJobItem, type PinJobQuery, type PinJobResponse, type PinListItem, type PinListQuery, type PinListResponse, type PinResponse, type PinataConfig, type PinataMetadata, type PinataMetadataUpdate, PinataSDK, type PinningEndpoints, type RevokeKeyResponse, type SignatureOptions, type SignatureResponse, type SwapCidOptions, type SwapCidResponse, type SwapHistoryOptions, type TimeIntervalGatewayAnalyticsQuery, type TimeIntervalGatewayAnalyticsResponse, type TimePeriodItem, type TopGatewayAnalyticsItem, type TopGatewayAnalyticsQuery, type UnpinResponse, type UpdateGroupOptions, type UploadCIDOptions, type UploadOptions, type UserPinnedDataResponse };
|
package/dist/index.js
CHANGED
|
@@ -2079,6 +2079,207 @@ var analyticsDateInterval = async (config, options) => {
|
|
|
2079
2079
|
}
|
|
2080
2080
|
};
|
|
2081
2081
|
|
|
2082
|
+
// src/core/gateway/swapCid.ts
|
|
2083
|
+
var swapCid = async (config, options) => {
|
|
2084
|
+
if (!config || !config.pinataJwt) {
|
|
2085
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
2086
|
+
}
|
|
2087
|
+
const data = JSON.stringify({
|
|
2088
|
+
swapCid: options.swapCid
|
|
2089
|
+
});
|
|
2090
|
+
let headers;
|
|
2091
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2092
|
+
headers = { ...config.customHeaders };
|
|
2093
|
+
} else {
|
|
2094
|
+
headers = {
|
|
2095
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2096
|
+
"Content-Type": "application/json",
|
|
2097
|
+
Source: "sdk/swapCid"
|
|
2098
|
+
};
|
|
2099
|
+
}
|
|
2100
|
+
let endpoint = "https://api.pinata.cloud";
|
|
2101
|
+
if (config.endpointUrl) {
|
|
2102
|
+
endpoint = config.endpointUrl;
|
|
2103
|
+
}
|
|
2104
|
+
try {
|
|
2105
|
+
const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
|
|
2106
|
+
method: "PUT",
|
|
2107
|
+
headers,
|
|
2108
|
+
body: data
|
|
2109
|
+
});
|
|
2110
|
+
if (!request.ok) {
|
|
2111
|
+
const errorData = await request.json();
|
|
2112
|
+
if (request.status === 401) {
|
|
2113
|
+
throw new AuthenticationError(
|
|
2114
|
+
"Authentication failed",
|
|
2115
|
+
request.status,
|
|
2116
|
+
errorData
|
|
2117
|
+
);
|
|
2118
|
+
}
|
|
2119
|
+
if (request.status === 403) {
|
|
2120
|
+
throw new PinataError(
|
|
2121
|
+
"Unauthorized CID Swap",
|
|
2122
|
+
request.status,
|
|
2123
|
+
errorData
|
|
2124
|
+
);
|
|
2125
|
+
}
|
|
2126
|
+
if (request.status === 404) {
|
|
2127
|
+
throw new PinataError(
|
|
2128
|
+
"CID not pinned to account",
|
|
2129
|
+
request.status,
|
|
2130
|
+
errorData
|
|
2131
|
+
);
|
|
2132
|
+
}
|
|
2133
|
+
throw new NetworkError(
|
|
2134
|
+
`HTTP error! status: ${request.status}`,
|
|
2135
|
+
request.status,
|
|
2136
|
+
errorData
|
|
2137
|
+
);
|
|
2138
|
+
}
|
|
2139
|
+
const res = await request.json();
|
|
2140
|
+
const resData = res.data;
|
|
2141
|
+
return resData;
|
|
2142
|
+
} catch (error) {
|
|
2143
|
+
if (error instanceof PinataError) {
|
|
2144
|
+
throw error;
|
|
2145
|
+
}
|
|
2146
|
+
if (error instanceof Error) {
|
|
2147
|
+
throw new PinataError(`Error processing CID Swap: ${error.message}`);
|
|
2148
|
+
}
|
|
2149
|
+
throw new PinataError("An unknown error occurred while swapping CID");
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
|
|
2153
|
+
// src/core/gateway/swapHistory.ts
|
|
2154
|
+
var swapHistory = async (config, options) => {
|
|
2155
|
+
if (!config || !config.pinataJwt) {
|
|
2156
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
2157
|
+
}
|
|
2158
|
+
let headers;
|
|
2159
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2160
|
+
headers = { ...config.customHeaders };
|
|
2161
|
+
} else {
|
|
2162
|
+
headers = {
|
|
2163
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2164
|
+
"Content-Type": "application/json",
|
|
2165
|
+
Source: "sdk/swapHistory"
|
|
2166
|
+
};
|
|
2167
|
+
}
|
|
2168
|
+
let endpoint = "https://api.pinata.cloud";
|
|
2169
|
+
if (config.endpointUrl) {
|
|
2170
|
+
endpoint = config.endpointUrl;
|
|
2171
|
+
}
|
|
2172
|
+
try {
|
|
2173
|
+
const request = await fetch(
|
|
2174
|
+
`${endpoint}/v3/ipfs/swap/${options.cid}?domain=${options.domain}`,
|
|
2175
|
+
{
|
|
2176
|
+
method: "GET",
|
|
2177
|
+
headers
|
|
2178
|
+
}
|
|
2179
|
+
);
|
|
2180
|
+
if (!request.ok) {
|
|
2181
|
+
const errorData = await request.json();
|
|
2182
|
+
if (request.status === 401) {
|
|
2183
|
+
throw new AuthenticationError(
|
|
2184
|
+
"Authentication failed",
|
|
2185
|
+
request.status,
|
|
2186
|
+
errorData
|
|
2187
|
+
);
|
|
2188
|
+
}
|
|
2189
|
+
if (request.status === 404) {
|
|
2190
|
+
throw new PinataError(
|
|
2191
|
+
"CID does not have history",
|
|
2192
|
+
request.status,
|
|
2193
|
+
errorData
|
|
2194
|
+
);
|
|
2195
|
+
}
|
|
2196
|
+
throw new NetworkError(
|
|
2197
|
+
`HTTP error! status: ${request.status}`,
|
|
2198
|
+
request.status,
|
|
2199
|
+
errorData
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2202
|
+
const res = await request.json();
|
|
2203
|
+
const resData = res.data;
|
|
2204
|
+
return resData;
|
|
2205
|
+
} catch (error) {
|
|
2206
|
+
if (error instanceof PinataError) {
|
|
2207
|
+
throw error;
|
|
2208
|
+
}
|
|
2209
|
+
if (error instanceof Error) {
|
|
2210
|
+
throw new PinataError(`Error fetching swap history: ${error.message}`);
|
|
2211
|
+
}
|
|
2212
|
+
throw new PinataError(
|
|
2213
|
+
"An unknown error occurred while fetching swap history"
|
|
2214
|
+
);
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
|
|
2218
|
+
// src/core/gateway/deleteSwap.ts
|
|
2219
|
+
var deleteSwap = async (config, cid) => {
|
|
2220
|
+
if (!config || !config.pinataJwt) {
|
|
2221
|
+
throw new ValidationError("Pinata configuration or JWT is missing");
|
|
2222
|
+
}
|
|
2223
|
+
let headers;
|
|
2224
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2225
|
+
headers = { ...config.customHeaders };
|
|
2226
|
+
} else {
|
|
2227
|
+
headers = {
|
|
2228
|
+
Authorization: `Bearer ${config.pinataJwt}`,
|
|
2229
|
+
"Content-Type": "application/json",
|
|
2230
|
+
Source: "sdk/deleteSwap"
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
let endpoint = "https://api.pinata.cloud";
|
|
2234
|
+
if (config.endpointUrl) {
|
|
2235
|
+
endpoint = config.endpointUrl;
|
|
2236
|
+
}
|
|
2237
|
+
try {
|
|
2238
|
+
const request = await fetch(`${endpoint}/v3/ipfs/swap/${cid}`, {
|
|
2239
|
+
method: "DELETE",
|
|
2240
|
+
headers
|
|
2241
|
+
});
|
|
2242
|
+
if (!request.ok) {
|
|
2243
|
+
const errorData = await request.json();
|
|
2244
|
+
if (request.status === 401) {
|
|
2245
|
+
throw new AuthenticationError(
|
|
2246
|
+
"Authentication failed",
|
|
2247
|
+
request.status,
|
|
2248
|
+
errorData
|
|
2249
|
+
);
|
|
2250
|
+
}
|
|
2251
|
+
if (request.status === 403) {
|
|
2252
|
+
throw new PinataError(
|
|
2253
|
+
"Unauthorized CID Swap Deletion",
|
|
2254
|
+
request.status,
|
|
2255
|
+
errorData
|
|
2256
|
+
);
|
|
2257
|
+
}
|
|
2258
|
+
if (request.status === 404) {
|
|
2259
|
+
throw new PinataError(
|
|
2260
|
+
"CID not pinned to account",
|
|
2261
|
+
request.status,
|
|
2262
|
+
errorData
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
throw new NetworkError(
|
|
2266
|
+
`HTTP error! status: ${request.status}`,
|
|
2267
|
+
request.status,
|
|
2268
|
+
errorData
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
return request.statusText;
|
|
2272
|
+
} catch (error) {
|
|
2273
|
+
if (error instanceof PinataError) {
|
|
2274
|
+
throw error;
|
|
2275
|
+
}
|
|
2276
|
+
if (error instanceof Error) {
|
|
2277
|
+
throw new PinataError(`Error processing deleteSwap: ${error.message}`);
|
|
2278
|
+
}
|
|
2279
|
+
throw new PinataError("An unknown error occurred while deleting swap");
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
|
|
2082
2283
|
// src/core/pinataSDK.ts
|
|
2083
2284
|
var formatConfig = (config) => {
|
|
2084
2285
|
let gateway = config?.pinataGateway;
|
|
@@ -2335,6 +2536,15 @@ var Gateways = class {
|
|
|
2335
2536
|
options.interval
|
|
2336
2537
|
);
|
|
2337
2538
|
}
|
|
2539
|
+
swapCid(options) {
|
|
2540
|
+
return swapCid(this.config, options);
|
|
2541
|
+
}
|
|
2542
|
+
swapHistory(options) {
|
|
2543
|
+
return swapHistory(this.config, options);
|
|
2544
|
+
}
|
|
2545
|
+
deleteSwap(cid) {
|
|
2546
|
+
return deleteSwap(this.config, cid);
|
|
2547
|
+
}
|
|
2338
2548
|
};
|
|
2339
2549
|
var FilterPinJobs = class {
|
|
2340
2550
|
constructor(config) {
|