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.mjs CHANGED
@@ -2043,6 +2043,207 @@ var analyticsDateInterval = async (config, options) => {
2043
2043
  }
2044
2044
  };
2045
2045
 
2046
+ // src/core/gateway/swapCid.ts
2047
+ var swapCid = async (config, options) => {
2048
+ if (!config || !config.pinataJwt) {
2049
+ throw new ValidationError("Pinata configuration or JWT is missing");
2050
+ }
2051
+ const data = JSON.stringify({
2052
+ swapCid: options.swapCid
2053
+ });
2054
+ let headers;
2055
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2056
+ headers = { ...config.customHeaders };
2057
+ } else {
2058
+ headers = {
2059
+ Authorization: `Bearer ${config.pinataJwt}`,
2060
+ "Content-Type": "application/json",
2061
+ Source: "sdk/swapCid"
2062
+ };
2063
+ }
2064
+ let endpoint = "https://api.pinata.cloud";
2065
+ if (config.endpointUrl) {
2066
+ endpoint = config.endpointUrl;
2067
+ }
2068
+ try {
2069
+ const request = await fetch(`${endpoint}/v3/ipfs/swap/${options.cid}`, {
2070
+ method: "PUT",
2071
+ headers,
2072
+ body: data
2073
+ });
2074
+ if (!request.ok) {
2075
+ const errorData = await request.json();
2076
+ if (request.status === 401) {
2077
+ throw new AuthenticationError(
2078
+ "Authentication failed",
2079
+ request.status,
2080
+ errorData
2081
+ );
2082
+ }
2083
+ if (request.status === 403) {
2084
+ throw new PinataError(
2085
+ "Unauthorized CID Swap",
2086
+ request.status,
2087
+ errorData
2088
+ );
2089
+ }
2090
+ if (request.status === 404) {
2091
+ throw new PinataError(
2092
+ "CID not pinned to account",
2093
+ request.status,
2094
+ errorData
2095
+ );
2096
+ }
2097
+ throw new NetworkError(
2098
+ `HTTP error! status: ${request.status}`,
2099
+ request.status,
2100
+ errorData
2101
+ );
2102
+ }
2103
+ const res = await request.json();
2104
+ const resData = res.data;
2105
+ return resData;
2106
+ } catch (error) {
2107
+ if (error instanceof PinataError) {
2108
+ throw error;
2109
+ }
2110
+ if (error instanceof Error) {
2111
+ throw new PinataError(`Error processing CID Swap: ${error.message}`);
2112
+ }
2113
+ throw new PinataError("An unknown error occurred while swapping CID");
2114
+ }
2115
+ };
2116
+
2117
+ // src/core/gateway/swapHistory.ts
2118
+ var swapHistory = async (config, options) => {
2119
+ if (!config || !config.pinataJwt) {
2120
+ throw new ValidationError("Pinata configuration or JWT is missing");
2121
+ }
2122
+ let headers;
2123
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2124
+ headers = { ...config.customHeaders };
2125
+ } else {
2126
+ headers = {
2127
+ Authorization: `Bearer ${config.pinataJwt}`,
2128
+ "Content-Type": "application/json",
2129
+ Source: "sdk/swapHistory"
2130
+ };
2131
+ }
2132
+ let endpoint = "https://api.pinata.cloud";
2133
+ if (config.endpointUrl) {
2134
+ endpoint = config.endpointUrl;
2135
+ }
2136
+ try {
2137
+ const request = await fetch(
2138
+ `${endpoint}/v3/ipfs/swap/${options.cid}?domain=${options.domain}`,
2139
+ {
2140
+ method: "GET",
2141
+ headers
2142
+ }
2143
+ );
2144
+ if (!request.ok) {
2145
+ const errorData = await request.json();
2146
+ if (request.status === 401) {
2147
+ throw new AuthenticationError(
2148
+ "Authentication failed",
2149
+ request.status,
2150
+ errorData
2151
+ );
2152
+ }
2153
+ if (request.status === 404) {
2154
+ throw new PinataError(
2155
+ "CID does not have history",
2156
+ request.status,
2157
+ errorData
2158
+ );
2159
+ }
2160
+ throw new NetworkError(
2161
+ `HTTP error! status: ${request.status}`,
2162
+ request.status,
2163
+ errorData
2164
+ );
2165
+ }
2166
+ const res = await request.json();
2167
+ const resData = res.data;
2168
+ return resData;
2169
+ } catch (error) {
2170
+ if (error instanceof PinataError) {
2171
+ throw error;
2172
+ }
2173
+ if (error instanceof Error) {
2174
+ throw new PinataError(`Error fetching swap history: ${error.message}`);
2175
+ }
2176
+ throw new PinataError(
2177
+ "An unknown error occurred while fetching swap history"
2178
+ );
2179
+ }
2180
+ };
2181
+
2182
+ // src/core/gateway/deleteSwap.ts
2183
+ var deleteSwap = async (config, cid) => {
2184
+ if (!config || !config.pinataJwt) {
2185
+ throw new ValidationError("Pinata configuration or JWT is missing");
2186
+ }
2187
+ let headers;
2188
+ if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
2189
+ headers = { ...config.customHeaders };
2190
+ } else {
2191
+ headers = {
2192
+ Authorization: `Bearer ${config.pinataJwt}`,
2193
+ "Content-Type": "application/json",
2194
+ Source: "sdk/deleteSwap"
2195
+ };
2196
+ }
2197
+ let endpoint = "https://api.pinata.cloud";
2198
+ if (config.endpointUrl) {
2199
+ endpoint = config.endpointUrl;
2200
+ }
2201
+ try {
2202
+ const request = await fetch(`${endpoint}/v3/ipfs/swap/${cid}`, {
2203
+ method: "DELETE",
2204
+ headers
2205
+ });
2206
+ if (!request.ok) {
2207
+ const errorData = await request.json();
2208
+ if (request.status === 401) {
2209
+ throw new AuthenticationError(
2210
+ "Authentication failed",
2211
+ request.status,
2212
+ errorData
2213
+ );
2214
+ }
2215
+ if (request.status === 403) {
2216
+ throw new PinataError(
2217
+ "Unauthorized CID Swap Deletion",
2218
+ request.status,
2219
+ errorData
2220
+ );
2221
+ }
2222
+ if (request.status === 404) {
2223
+ throw new PinataError(
2224
+ "CID not pinned to account",
2225
+ request.status,
2226
+ errorData
2227
+ );
2228
+ }
2229
+ throw new NetworkError(
2230
+ `HTTP error! status: ${request.status}`,
2231
+ request.status,
2232
+ errorData
2233
+ );
2234
+ }
2235
+ return request.statusText;
2236
+ } catch (error) {
2237
+ if (error instanceof PinataError) {
2238
+ throw error;
2239
+ }
2240
+ if (error instanceof Error) {
2241
+ throw new PinataError(`Error processing deleteSwap: ${error.message}`);
2242
+ }
2243
+ throw new PinataError("An unknown error occurred while deleting swap");
2244
+ }
2245
+ };
2246
+
2046
2247
  // src/core/pinataSDK.ts
2047
2248
  var formatConfig = (config) => {
2048
2249
  let gateway = config?.pinataGateway;
@@ -2299,6 +2500,15 @@ var Gateways = class {
2299
2500
  options.interval
2300
2501
  );
2301
2502
  }
2503
+ swapCid(options) {
2504
+ return swapCid(this.config, options);
2505
+ }
2506
+ swapHistory(options) {
2507
+ return swapHistory(this.config, options);
2508
+ }
2509
+ deleteSwap(cid) {
2510
+ return deleteSwap(this.config, cid);
2511
+ }
2302
2512
  };
2303
2513
  var FilterPinJobs = class {
2304
2514
  constructor(config) {