pinata 0.3.0 → 0.3.2

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
@@ -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
@@ -876,12 +876,7 @@ var getCid = async (config, cid) => {
876
876
  newUrl = `${newUrl}?pinataGatewayToken=${config?.pinataGatewayKey}`;
877
877
  }
878
878
  try {
879
- const request = await fetch(newUrl, {
880
- method: "GET",
881
- headers: {
882
- Source: "sdk/getCid"
883
- }
884
- });
879
+ const request = await fetch(newUrl);
885
880
  if (!request.ok) {
886
881
  const errorData = await request.json();
887
882
  if (request.status === 401) {
@@ -2079,6 +2074,207 @@ var analyticsDateInterval = async (config, options) => {
2079
2074
  }
2080
2075
  };
2081
2076
 
2077
+ // src/core/gateway/swapCid.ts
2078
+ var swapCid = async (config, options) => {
2079
+ if (!config || !config.pinataJwt) {
2080
+ throw new ValidationError("Pinata configuration or JWT is missing");
2081
+ }
2082
+ const data = JSON.stringify({
2083
+ swapCid: options.swapCid
2084
+ });
2085
+ let headers;
2086
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2087
+ headers = { ...config.customHeaders };
2088
+ } else {
2089
+ headers = {
2090
+ Authorization: `Bearer ${config.pinataJwt}`,
2091
+ "Content-Type": "application/json",
2092
+ Source: "sdk/swapCid"
2093
+ };
2094
+ }
2095
+ let endpoint = "https://api.pinata.cloud";
2096
+ if (config.endpointUrl) {
2097
+ endpoint = config.endpointUrl;
2098
+ }
2099
+ try {
2100
+ const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
2101
+ method: "PUT",
2102
+ headers,
2103
+ body: data
2104
+ });
2105
+ if (!request.ok) {
2106
+ const errorData = await request.json();
2107
+ if (request.status === 401) {
2108
+ throw new AuthenticationError(
2109
+ "Authentication failed",
2110
+ request.status,
2111
+ errorData
2112
+ );
2113
+ }
2114
+ if (request.status === 403) {
2115
+ throw new PinataError(
2116
+ "Unauthorized CID Swap",
2117
+ request.status,
2118
+ errorData
2119
+ );
2120
+ }
2121
+ if (request.status === 404) {
2122
+ throw new PinataError(
2123
+ "CID not pinned to account",
2124
+ request.status,
2125
+ errorData
2126
+ );
2127
+ }
2128
+ throw new NetworkError(
2129
+ `HTTP error! status: ${request.status}`,
2130
+ request.status,
2131
+ errorData
2132
+ );
2133
+ }
2134
+ const res = await request.json();
2135
+ const resData = res.data;
2136
+ return resData;
2137
+ } catch (error) {
2138
+ if (error instanceof PinataError) {
2139
+ throw error;
2140
+ }
2141
+ if (error instanceof Error) {
2142
+ throw new PinataError(`Error processing CID Swap: ${error.message}`);
2143
+ }
2144
+ throw new PinataError("An unknown error occurred while swapping CID");
2145
+ }
2146
+ };
2147
+
2148
+ // src/core/gateway/swapHistory.ts
2149
+ var swapHistory = async (config, options) => {
2150
+ if (!config || !config.pinataJwt) {
2151
+ throw new ValidationError("Pinata configuration or JWT is missing");
2152
+ }
2153
+ let headers;
2154
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2155
+ headers = { ...config.customHeaders };
2156
+ } else {
2157
+ headers = {
2158
+ Authorization: `Bearer ${config.pinataJwt}`,
2159
+ "Content-Type": "application/json",
2160
+ Source: "sdk/swapHistory"
2161
+ };
2162
+ }
2163
+ let endpoint = "https://api.pinata.cloud";
2164
+ if (config.endpointUrl) {
2165
+ endpoint = config.endpointUrl;
2166
+ }
2167
+ try {
2168
+ const request = await fetch(
2169
+ `${endpoint}/v3/ipfs/swap/${options.cid}?domain=${options.domain}`,
2170
+ {
2171
+ method: "GET",
2172
+ headers
2173
+ }
2174
+ );
2175
+ if (!request.ok) {
2176
+ const errorData = await request.json();
2177
+ if (request.status === 401) {
2178
+ throw new AuthenticationError(
2179
+ "Authentication failed",
2180
+ request.status,
2181
+ errorData
2182
+ );
2183
+ }
2184
+ if (request.status === 404) {
2185
+ throw new PinataError(
2186
+ "CID does not have history",
2187
+ request.status,
2188
+ errorData
2189
+ );
2190
+ }
2191
+ throw new NetworkError(
2192
+ `HTTP error! status: ${request.status}`,
2193
+ request.status,
2194
+ errorData
2195
+ );
2196
+ }
2197
+ const res = await request.json();
2198
+ const resData = res.data;
2199
+ return resData;
2200
+ } catch (error) {
2201
+ if (error instanceof PinataError) {
2202
+ throw error;
2203
+ }
2204
+ if (error instanceof Error) {
2205
+ throw new PinataError(`Error fetching swap history: ${error.message}`);
2206
+ }
2207
+ throw new PinataError(
2208
+ "An unknown error occurred while fetching swap history"
2209
+ );
2210
+ }
2211
+ };
2212
+
2213
+ // src/core/gateway/deleteSwap.ts
2214
+ var deleteSwap = async (config, cid) => {
2215
+ if (!config || !config.pinataJwt) {
2216
+ throw new ValidationError("Pinata configuration or JWT is missing");
2217
+ }
2218
+ let headers;
2219
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2220
+ headers = { ...config.customHeaders };
2221
+ } else {
2222
+ headers = {
2223
+ Authorization: `Bearer ${config.pinataJwt}`,
2224
+ "Content-Type": "application/json",
2225
+ Source: "sdk/deleteSwap"
2226
+ };
2227
+ }
2228
+ let endpoint = "https://api.pinata.cloud";
2229
+ if (config.endpointUrl) {
2230
+ endpoint = config.endpointUrl;
2231
+ }
2232
+ try {
2233
+ const request = await fetch(`${endpoint}/v3/ipfs/swap/${cid}`, {
2234
+ method: "DELETE",
2235
+ headers
2236
+ });
2237
+ if (!request.ok) {
2238
+ const errorData = await request.json();
2239
+ if (request.status === 401) {
2240
+ throw new AuthenticationError(
2241
+ "Authentication failed",
2242
+ request.status,
2243
+ errorData
2244
+ );
2245
+ }
2246
+ if (request.status === 403) {
2247
+ throw new PinataError(
2248
+ "Unauthorized CID Swap Deletion",
2249
+ request.status,
2250
+ errorData
2251
+ );
2252
+ }
2253
+ if (request.status === 404) {
2254
+ throw new PinataError(
2255
+ "CID not pinned to account",
2256
+ request.status,
2257
+ errorData
2258
+ );
2259
+ }
2260
+ throw new NetworkError(
2261
+ `HTTP error! status: ${request.status}`,
2262
+ request.status,
2263
+ errorData
2264
+ );
2265
+ }
2266
+ return request.statusText;
2267
+ } catch (error) {
2268
+ if (error instanceof PinataError) {
2269
+ throw error;
2270
+ }
2271
+ if (error instanceof Error) {
2272
+ throw new PinataError(`Error processing deleteSwap: ${error.message}`);
2273
+ }
2274
+ throw new PinataError("An unknown error occurred while deleting swap");
2275
+ }
2276
+ };
2277
+
2082
2278
  // src/core/pinataSDK.ts
2083
2279
  var formatConfig = (config) => {
2084
2280
  let gateway = config?.pinataGateway;
@@ -2335,6 +2531,15 @@ var Gateways = class {
2335
2531
  options.interval
2336
2532
  );
2337
2533
  }
2534
+ swapCid(options) {
2535
+ return swapCid(this.config, options);
2536
+ }
2537
+ swapHistory(options) {
2538
+ return swapHistory(this.config, options);
2539
+ }
2540
+ deleteSwap(cid) {
2541
+ return deleteSwap(this.config, cid);
2542
+ }
2338
2543
  };
2339
2544
  var FilterPinJobs = class {
2340
2545
  constructor(config) {