@taqueria/plugin-ipfs-pinata 0.13.0 → 0.14.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/README.md CHANGED
@@ -4,6 +4,8 @@ This is a plugin developed for Taqueria built on NodeJS using the Taqueria Node
4
4
 
5
5
  The IPFS Pinata plugin provides a `publish` task to upload metadata, media, or other files to IPFS via Pinata
6
6
 
7
+ The IPFS Pinata plugin also provides a `pin` task to link any existing files on Pinata to your Pinata account
8
+
7
9
 
8
10
 
9
11
  ## Requirements
@@ -25,7 +27,7 @@ taq install @taqueria/plugin-ipfs-pinata
25
27
  In order for Taqueria to connect to Pinata, you must first add your Pinata JWT token to the project. To do this, follow the steps below:
26
28
 
27
29
  1. Sign into your Pinata account [here](https://app.pinata.cloud/signin)
28
- 2. Find your JWT token and copy it
30
+ 2. Create/find your JWT token and copy it
29
31
  3. Create the file `.env` in your Taqueria project
30
32
  4. Add the JWT token to a property called `pinataJwtToken` as shown below:
31
33
 
@@ -43,11 +45,19 @@ You will first need to create a new directory in your project and add any metada
43
45
  taq publish < path >
44
46
  ```
45
47
 
48
+ The IPFS Pinata plugin exposes a `pin` task which links files already existing on Pinata to your Pinata account
49
+
50
+ You will need to find the CID for a file on Pinata then use that to pin the file to your account that is linked with the JWT you're using
51
+
52
+ ```shell
53
+ taq pin < hash >
54
+ ```
55
+
46
56
  ## Tasks
47
57
 
48
58
  ### The `taq publish` Task
49
59
 
50
- The `publish` task is used for compiling Archetype smart contracts to Michelson and the task has the following structure:
60
+ The `publish` task is used for uploading files/directories of files to IPFS and the task has the following structure:
51
61
 
52
62
  ```shell
53
63
  taq publish < sourceDirectory >
@@ -61,6 +71,22 @@ taq publish < sourceDirectory >
61
71
  | command | 'publish < path > |
62
72
  | aliases | N/A |
63
73
 
74
+ ### The `taq pin` Task
75
+
76
+ The `pin` task is used for pinning existing files on Pinata to your account and the task has the following structure:
77
+
78
+ ```shell
79
+ taq pin < hash >
80
+ ```
81
+
82
+ #### Task Properties
83
+
84
+ | attribute | value |
85
+ |------------|:-------------------------------:|
86
+ | task | 'pin' |
87
+ | command | 'pin < hash > |
88
+ | aliases | N/A |
89
+
64
90
 
65
91
  ## Plugin Architecture
66
92
 
package/_readme.eta CHANGED
@@ -6,8 +6,10 @@ This is a plugin developed for Taqueria built on NodeJS using the Taqueria Node
6
6
 
7
7
  The IPFS Pinata plugin provides a `publish` task to upload metadata, media, or other files to IPFS via Pinata
8
8
 
9
+ The IPFS Pinata plugin also provides a `pin` task to link any existing files on Pinata to your Pinata account
10
+
9
11
  <% /* <%~ it.noteOpenAdmonition %>
10
- In order to connect to Pinata, you will need to first create an account on Pinata, then add your JWT token to the project
12
+ In order to connect to Pinata, you will need to first [register](https://app.pinata.cloud/register) an account on Pinata, then add your JWT token to the project
11
13
  <%= it.closeAdmonition %> */ %>
12
14
 
13
15
 
@@ -30,7 +32,7 @@ taq install @taqueria/plugin-ipfs-pinata
30
32
  In order for Taqueria to connect to Pinata, you must first add your Pinata JWT token to the project. To do this, follow the steps below:
31
33
 
32
34
  1. Sign into your Pinata account [here](https://app.pinata.cloud/signin)
33
- 2. Find your JWT token and copy it
35
+ 2. Create/find your JWT token and copy it
34
36
  3. Create the file `.env` in your Taqueria project
35
37
  4. Add the JWT token to a property called `pinataJwtToken` as shown below:
36
38
 
@@ -48,11 +50,19 @@ You will first need to create a new directory in your project and add any metada
48
50
  taq publish < path >
49
51
  ```
50
52
 
53
+ The IPFS Pinata plugin exposes a `pin` task which links files already existing on Pinata to your Pinata account
54
+
55
+ You will need to find the CID for a file on Pinata then use that to pin the file to your account that is linked with the JWT you're using
56
+
57
+ ```shell
58
+ taq pin < hash >
59
+ ```
60
+
51
61
  ## Tasks
52
62
 
53
63
  ### The `taq publish` Task
54
64
 
55
- The `publish` task is used for compiling Archetype smart contracts to Michelson and the task has the following structure:
65
+ The `publish` task is used for uploading files/directories of files to IPFS and the task has the following structure:
56
66
 
57
67
  ```shell
58
68
  taq publish < sourceDirectory >
@@ -66,6 +76,22 @@ taq publish < sourceDirectory >
66
76
  | command | 'publish < path > |
67
77
  | aliases | N/A |
68
78
 
79
+ ### The `taq pin` Task
80
+
81
+ The `pin` task is used for pinning existing files on Pinata to your account and the task has the following structure:
82
+
83
+ ```shell
84
+ taq pin < hash >
85
+ ```
86
+
87
+ #### Task Properties
88
+
89
+ | attribute | value |
90
+ |------------|:-------------------------------:|
91
+ | task | 'pin' |
92
+ | command | 'pin < hash > |
93
+ | aliases | N/A |
94
+
69
95
 
70
96
  ## Plugin Architecture
71
97
 
package/index.js CHANGED
@@ -151,6 +151,21 @@ const $3f348f69899f8bee$var$checkIfFileIsPinned = async ({ auth: auth , item: it
151
151
  ipfsHash: ipfsHash
152
152
  };
153
153
  };
154
+ const $3f348f69899f8bee$export$979daf0e3ae9695f = async ({ auth: auth , ipfsHash: ipfsHash })=>{
155
+ const response = await (0, $khbt3$nodefetch)(`https://api.pinata.cloud/pinning/pinByHash`, {
156
+ headers: {
157
+ Authorization: `Bearer ${auth.pinataJwtToken}`,
158
+ "Content-Type": "application/json"
159
+ },
160
+ method: "post",
161
+ body: JSON.stringify({
162
+ hashToPin: ipfsHash
163
+ })
164
+ });
165
+ if (!response.ok) throw new Error(`Failed to pin '${ipfsHash}' with pinata: ${response.statusText}`);
166
+ // Ok is the only response if successful
167
+ return;
168
+ };
154
169
 
155
170
 
156
171
  async function $81b0536a41de4891$export$1391212d75b2ee65(timeout) {
@@ -249,8 +264,18 @@ const $e26bf59b4820ce36$var$publishToIpfs = async (fileOrDirPath, auth)=>{
249
264
  };
250
265
  const $e26bf59b4820ce36$var$pinToIpfs = async (hash, auth)=>{
251
266
  if (!hash) throw new Error(`ipfs hash was not provided`);
252
- // TODO: Implement pinning
253
- throw new Error("pinToIpfs: Not Implemented");
267
+ await (0, $3f348f69899f8bee$export$979daf0e3ae9695f)({
268
+ ipfsHash: hash,
269
+ auth: auth
270
+ });
271
+ return {
272
+ render: "table",
273
+ data: [
274
+ {
275
+ ipfsHash: hash
276
+ }
277
+ ]
278
+ };
254
279
  };
255
280
  const $e26bf59b4820ce36$var$execute = async (opts)=>{
256
281
  const { task: task , path: path , hash: hash , config: config , } = opts;
@@ -303,6 +328,20 @@ var $e26bf59b4820ce36$export$2e2bcd8739ae039 = async (args)=>{
303
328
  }),
304
329
  ],
305
330
  encoding: "json"
331
+ }),
332
+ (0, $khbt3$Task).create({
333
+ task: "pin",
334
+ command: "pin [hash]",
335
+ description: "Pin a file already on ipfs with your pinata account.",
336
+ aliases: [],
337
+ handler: "proxy",
338
+ positionals: [
339
+ (0, $khbt3$PositionalArg).create({
340
+ placeholder: "hash",
341
+ description: "Ipfs hash of the file or directory that is already on the ipfs network.",
342
+ type: "string"
343
+ }),
344
+ ]
306
345
  }),
307
346
  ],
308
347
  proxy: $e26bf59b4820ce36$export$2e2bcd8739ae039
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;ACAA;;ACAA;;AAGA,kBAAkB;AAClB,4FAA4F;AAC5F,gBAAgB,8BAAQ,CAAC,aAAqB,EAAyC;IACtF,MAAM,OAAO,GAAG,MAAM,CAAA,GAAA,iBAAE,CAAA,CAAC,IAAI,CAAC,aAAa,CAAC,AAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACrB,MAAM,aAAa,CAAC;QACpB,OAAO;KACP;IAED,MAAM,OAAO,GAAG,MAAM,CAAA,GAAA,iBAAE,CAAA,CAAC,OAAO,CAAC,aAAa,EAAE;QAAE,aAAa,EAAE,IAAI;KAAE,CAAC,AAAC;IACzE,KAAK,MAAM,MAAM,IAAI,OAAO,CAAE;QAC7B,MAAM,GAAG,GAAG,CAAA,GAAA,WAAI,CAAA,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,AAAC;QACrD,IAAI,MAAM,CAAC,WAAW,EAAE,EACvB,OAAO,8BAAQ,CAAC,GAAG,CAAC,CAAC;aAErB,MAAM,G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plugin-ipfs-pinata/src/file-processing.ts","taqueria-plugin-ipfs-pinata/src/pinata-api.ts","taqueria-plugin-ipfs-pinata/src/utils.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';\nimport proxy from './src/proxy';\n\nPlugin.create(() => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'pinata',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'publish',\n\t\t\tcommand: 'publish [path]',\n\t\t\tdescription: 'Upload and pin files using your pinata account.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'path',\n\t\t\t\t\tdescription: 'Directory or file path to publish',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\tencoding: 'json',\n\t\t}),\n\t\t// Pinning Not Implemented Yet\n\t\t// Task.create({\n\t\t// \ttask: 'pin',\n\t\t// \tcommand: 'pin [hash]',\n\t\t// \tdescription: 'Pin a file already on ipfs with your pinata account.',\n\t\t// \taliases: [],\n\t\t// \thandler: 'proxy',\n\t\t// \tpositionals: [\n\t\t// \t\tPositionalArg.create({\n\t\t// \t\t\tplaceholder: 'hash',\n\t\t// \t\t\tdescription: 'Ipfs hash of the file or directory that is already on the ipfs network.',\n\t\t// \t\t\ttype: 'string',\n\t\t// \t\t}),\n\t\t// \t]\n\t\t// }),\n\t],\n\tproxy,\n}), process.argv);\n","import { sendAsyncErr, sendAsyncRes, sendErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { LoadedConfig, RequestArgs, SanitizedAbsPath } from '@taqueria/node-sdk/types';\nimport path from 'path';\nimport { processFiles } from './file-processing';\nimport { PinataAuth, publishFileToIpfs } from './pinata-api';\nimport { createProcessBackoffController } from './utils';\n\n// Load .env for jwt token\n// TODO: How should this be stored in a secure way?\nimport 'dotenv/config';\n\n// TODO: What should this be, it was removed from the sdk\ntype PluginResponse =\n\t| void\n\t| {\n\t\trender: 'table';\n\t\tdata: unknown[];\n\t};\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\treadonly path?: string;\n\treadonly hash?: string;\n}\n\nconst publishToIpfs = async (fileOrDirPath: undefined | string, auth: PinataAuth): Promise<PluginResponse> => {\n\tif (!fileOrDirPath) {\n\t\tthrow new Error(`path was not provided`);\n\t}\n\n\t// Pinata is limited to 180 requests per minute\n\t// So for the first 180 requests they can go fast\n\n\tconst { processWithBackoff } = createProcessBackoffController({\n\t\tretryCount: 5,\n\t\ttargetRequestsPerMinute: 180,\n\t});\n\n\tconst result = await processFiles({\n\t\tfileOrDirPath,\n\t\tparallelCount: 10,\n\t\tprocessFile: async filePath => {\n\t\t\t// // TEMP: Debug\n\t\t\t// console.log(`publishing: ${filePath}`);\n\n\t\t\treturn processWithBackoff(() =>\n\t\t\t\tpublishFileToIpfs({\n\t\t\t\t\tauth,\n\t\t\t\t\titem: { filePath, name: path.basename(filePath) },\n\t\t\t\t})\n\t\t\t);\n\t\t},\n\t\tonProgress: ({ processedFilesCount, estimateFileCount }) => {\n\t\t\tif (estimateFileCount && processedFilesCount % 10) {\n\t\t\t\tlet ratio = processedFilesCount / estimateFileCount;\n\t\t\t\tif (ratio > 1) ratio = 1;\n\n\t\t\t\t// // TODO: Call task sdk progress\n\t\t\t\t// console.log(`Progress: ${(ratio * 100).toFixed(0)}%`);\n\t\t\t}\n\t\t},\n\t});\n\n\t// // TEMP: DEBUG: Show error\n\t// if (result.failures.length) {\n\t// \tconsole.log('❗ Failures:\\n' + result.failures.map(f => `${f.filePath}: ${f.error}`).join('\\n'));\n\t// }\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: [\n\t\t\t...result.failures.map(x => ({\n\t\t\t\t'?': '❌',\n\t\t\t\tfilePath: x.filePath,\n\t\t\t\tipfsHash: undefined,\n\t\t\t\terror: (x.error as { message?: string })?.message ?? JSON.stringify(x.error),\n\t\t\t})),\n\t\t\t...result.successes.map(x => ({\n\t\t\t\t'?': '✔',\n\t\t\t\tfilePath: x.filePath,\n\t\t\t\tipfsHash: x.result.ipfsHash,\n\t\t\t\terror: undefined,\n\t\t\t})),\n\t\t],\n\t};\n};\n\nconst pinToIpfs = async (hash: undefined | string, auth: PinataAuth): Promise<PluginResponse> => {\n\tif (!hash) {\n\t\tthrow new Error(`ipfs hash was not provided`);\n\t}\n\n\t// TODO: Implement pinning\n\tthrow new Error('pinToIpfs: Not Implemented');\n};\n\nconst execute = async (opts: Opts): Promise<PluginResponse> => {\n\tconst {\n\t\ttask,\n\t\tpath,\n\t\thash,\n\t\tconfig,\n\t} = opts;\n\n\tconst auth: PinataAuth = {\n\t\t// TODO: Where should this be stored?\n\t\t// pinataJwtToken: (config as Record<string, any>).credentials.pinataJwtToken,\n\t\tpinataJwtToken: process.env['pinataJwtToken'] as string,\n\t};\n\n\tif (!auth.pinataJwtToken) {\n\t\tthrow new Error(`The 'credentials.pinataJwtToken' was not found in config`);\n\t}\n\n\tswitch (task) {\n\t\tcase 'publish':\n\t\t\treturn publishToIpfs(path, auth);\n\t\tcase 'pin':\n\t\t\treturn pinToIpfs(hash, auth);\n\t\tdefault:\n\t\t\tthrow new Error(`${task} is not an understood task by the ipfs-pinata plugin`);\n\t}\n};\n\nexport default async (args: RequestArgs.ProxyRequestArgs): Promise<PluginResponse> => {\n\tconst opts = args as Opts;\n\n\ttry {\n\t\tconst resultRaw = await execute(opts) as Record<string, unknown>;\n\t\t// TODO: Fix deno parsing\n\t\t// Without this, `data.reduce is not a function`\n\t\tconst result = ('data' in resultRaw) ? resultRaw.data : resultRaw;\n\t\treturn sendJsonRes(result);\n\t} catch (err) {\n\t\tconst error = err as Error;\n\t\tif (error.message) {\n\t\t\treturn sendAsyncErr(error.message);\n\t\t}\n\t}\n};\n","import fs from 'fs/promises';\nimport path from 'path';\n\n// Async generator\n// https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search\nasync function* getFiles(fileOrDirPath: string): AsyncGenerator<string, void, unknown> {\n\tconst dirInfo = await fs.stat(fileOrDirPath);\n\tif (dirInfo.isFile()) {\n\t\tyield fileOrDirPath;\n\t\treturn;\n\t}\n\n\tconst dirents = await fs.readdir(fileOrDirPath, { withFileTypes: true });\n\tfor (const dirent of dirents) {\n\t\tconst res = path.resolve(fileOrDirPath, dirent.name);\n\t\tif (dirent.isDirectory()) {\n\t\t\tyield* getFiles(res);\n\t\t} else {\n\t\t\tyield res;\n\t\t}\n\t}\n}\n\nconst createFileProvider = async ({\n\tfileOrDirPath,\n\tfilter,\n\tshouldEstimateFileCount,\n}: {\n\tfileOrDirPath: string;\n\tfilter?: (filePath: string) => boolean;\n\tshouldEstimateFileCount?: boolean;\n}) => {\n\tfileOrDirPath = path.resolve(fileOrDirPath);\n\tconst pathInfo = await fs.stat(fileOrDirPath);\n\tif (\n\t\t!pathInfo.isFile()\n\t\t&& !pathInfo.isDirectory()\n\t) {\n\t\tthrow new Error(`The path '${fileOrDirPath}' is not a file or directory`);\n\t}\n\n\tlet estimateFileCount = undefined as undefined | number;\n\tif (shouldEstimateFileCount) {\n\t\testimateFileCount = 0;\n\t\tfor await (const filePath of getFiles(fileOrDirPath)) {\n\t\t\tif (filter && !filter(filePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\testimateFileCount++;\n\t\t}\n\t}\n\n\tconst fileGenerator = getFiles(fileOrDirPath);\n\tconst getNextFile = async () => {\n\t\tlet nextFile = (await fileGenerator.next()).value;\n\t\tif (!filter) {\n\t\t\treturn nextFile;\n\t\t}\n\n\t\twhile (nextFile && !filter(nextFile)) {\n\t\t\tnextFile = await getNextFile();\n\t\t}\n\n\t\treturn nextFile;\n\t};\n\treturn {\n\t\tgetNextFile,\n\t\testimateFileCount,\n\t};\n};\n\ntype ProgressInfo = { processedFilesCount: number; estimateFileCount: undefined | number };\nexport const processFiles = async <TResult>({\n\tfileOrDirPath,\n\tprocessFile,\n\tfilter,\n\tparallelCount = 10,\n\tonProgress,\n}: {\n\tfileOrDirPath: string;\n\tprocessFile: (filePath: string, progress: ProgressInfo) => Promise<TResult>;\n\tfilter?: (filePath: string) => boolean;\n\tparallelCount?: number;\n\tonProgress?: (progress: ProgressInfo) => void;\n}) => {\n\tconst { getNextFile, estimateFileCount } = await createFileProvider({\n\t\tfileOrDirPath,\n\t\tfilter,\n\t\tshouldEstimateFileCount: true,\n\t});\n\n\tconst successes = [] as { filePath: string; result: TResult }[];\n\tconst failures = [] as { filePath: string; error: unknown }[];\n\n\tonProgress?.({\n\t\tprocessedFilesCount: 0,\n\t\testimateFileCount,\n\t});\n\n\tawait Promise.all([...new Array(parallelCount)].map(async x => {\n\t\tlet fileToProcess = await getNextFile();\n\t\twhile (fileToProcess) {\n\t\t\tconst progressInfo = {\n\t\t\t\tprocessedFilesCount: successes.length + failures.length,\n\t\t\t\testimateFileCount,\n\t\t\t};\n\t\t\tonProgress?.(progressInfo);\n\n\t\t\ttry {\n\t\t\t\tconst result = await processFile(fileToProcess, progressInfo);\n\t\t\t\tsuccesses.push({ filePath: fileToProcess, result });\n\t\t\t} catch (err) {\n\t\t\t\tfailures.push({ filePath: fileToProcess, error: err });\n\t\t\t}\n\n\t\t\tfileToProcess = await getNextFile();\n\t\t}\n\t}));\n\n\tonProgress?.({\n\t\tprocessedFilesCount: successes.length + failures.length,\n\t\testimateFileCount,\n\t});\n\n\treturn {\n\t\tsuccesses,\n\t\tfailures,\n\t};\n};\n","import FormData from 'form-data';\nimport fs from 'fs';\nimport Hash from 'ipfs-only-hash';\nimport fetch from 'node-fetch';\n\nexport type PinataAuth = {\n\tpinataJwtToken: string;\n};\n\nexport type PublishFileResult = {\n\tipfsHash: string;\n};\n\nexport const publishFileToIpfs = async ({\n\tauth,\n\titem,\n}: {\n\tauth: PinataAuth;\n\titem: {\n\t\tname: string;\n\t\tfilePath: string;\n\t};\n}): Promise<PublishFileResult> => {\n\t// The data api to check for existing file is limited to 30 requests per minute\n\t// While uploading allows 180 requests per minute\n\t// i.e. it's faster to just upload again\n\n\t// // Skip if already pinned\n\t// const { isPinned, ipfsHash } = await checkIfFileIsPinned({ auth, item });\n\t// if (isPinned) {\n\t// \treturn {\n\t// \t\tipfsHash,\n\t// \t};\n\t// }\n\n\tconst data = new FormData();\n\tdata.append('file', fs.createReadStream(item.filePath));\n\tdata.append(\n\t\t'pinataMetadata',\n\t\tJSON.stringify({\n\t\t\tname: item.name,\n\t\t}),\n\t);\n\n\tconst response = await fetch(`https://api.pinata.cloud/pinning/pinFileToIPFS`, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${auth.pinataJwtToken}`,\n\t\t\t'Content-Type': `multipart/form-data; boundary=${(data as unknown as { _boundary: string })._boundary}`,\n\t\t},\n\t\tbody: data,\n\t\tmethod: 'post',\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to upload '${item.name}' to ipfs ${response.statusText}`);\n\t}\n\n\tconst uploadResult = await response.json() as {\n\t\tIpfsHash: string; // This is the IPFS multi-hash provided back for your content,\n\t\tPinSize: string; // This is how large (in bytes) the content you just pinned is,\n\t\tTimestamp: string; // This is the timestamp for your content pinning (represented in ISO 8601 format)\n\t};\n\n\treturn {\n\t\tipfsHash: uploadResult.IpfsHash,\n\t};\n};\n\nconst checkIfFileIsPinned = async ({\n\tauth,\n\titem,\n}: {\n\tauth: PinataAuth;\n\titem: {\n\t\tname: string;\n\t\tfilePath: string;\n\t};\n}) => {\n\tconst ipfsHash = await Hash.of(fs.createReadStream(item.filePath));\n\n\tconst response = await fetch(`https://api.pinata.cloud/data/pinList?status=pinned&hashContains=${ipfsHash}`, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${auth.pinataJwtToken}`,\n\t\t},\n\t\tmethod: 'get',\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to query '${item.name}' status from pinata ${response.statusText}`);\n\t}\n\n\tconst pinResult = await response.json() as {\n\t\tcount: number;\n\t\trows: {\n\t\t\tid: string;\n\t\t\tipfs_pin_hash: string;\n\t\t\tsize: number;\n\t\t\tuser_id: string;\n\t\t\tdate_pinned: null | string;\n\t\t\tdate_unpinned: null | string;\n\t\t\tmetadata: {\n\t\t\t\tname: string;\n\t\t\t\tkeyvalues: null | string;\n\t\t\t};\n\t\t\tregions: {\n\t\t\t\tregionId: string;\n\t\t\t\tcurrentReplicationCount: number;\n\t\t\t\tdesiredReplicationCount: number;\n\t\t\t}[];\n\t\t}[];\n\t};\n\n\tconst isPinned = pinResult.rows.some(x =>\n\t\tx.ipfs_pin_hash === ipfsHash\n\t\t&& x.date_pinned\n\t\t&& !x.date_unpinned\n\t);\n\n\treturn {\n\t\tisPinned,\n\t\tipfsHash,\n\t};\n};\n","export async function delay(timeout: number): Promise<void> {\n\treturn await new Promise(resolve => {\n\t\tsetTimeout(resolve, timeout);\n\t});\n}\n\nexport const createProcessBackoffController = ({\n\tretryCount = 5,\n\ttargetRequestsPerMinute = 180,\n}: {\n\tretryCount?: number;\n\ttargetRequestsPerMinute?: number;\n}) => {\n\tlet averageTimePerRequest = 5000;\n\tlet targetTimePerRequest = 60000 / targetRequestsPerMinute;\n\tlet lastTime = Date.now();\n\n\tconst processWithBackoff = async <TResult>(process: () => Promise<TResult>) => {\n\t\tlet attempt = 0;\n\t\tlet lastError = undefined as unknown;\n\t\twhile (attempt < retryCount) {\n\t\t\ttry {\n\t\t\t\tlet delayTimeMs = Math.max(10, targetTimePerRequest - averageTimePerRequest);\n\n\t\t\t\t// Partially randomized delay to ensure parallel requests don't line up\n\t\t\t\tawait delay(Math.floor(delayTimeMs * (1 + 0.5 * Math.random())));\n\n\t\t\t\tconst result = await process();\n\n\t\t\t\tconst timeNow = Date.now();\n\t\t\t\tconst timeElapsed = timeNow - lastTime;\n\t\t\t\tlastTime = timeNow;\n\n\t\t\t\t// Running average\n\t\t\t\taverageTimePerRequest = averageTimePerRequest * 0.97 + timeElapsed * 0.03;\n\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tlastError = err;\n\t\t\t}\n\n\t\t\t// Quickly increase time to wait if failure (allow negatives to wait longer than target)\n\t\t\taverageTimePerRequest -= (attempt + 1) * 1000;\n\t\t\tattempt++;\n\t\t}\n\n\t\t// All attempts failed\n\t\tthrow lastError;\n\t};\n\n\treturn {\n\t\tprocessWithBackoff,\n\t};\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
1
+ {"mappings":";;;;;;;;;AAAA;ACAA;;ACAA;;AAGA,kBAAkB;AAClB,4FAA4F;AAC5F,gBAAgB,8BAAQ,CAAC,aAAqB,EAAyC;IACtF,MAAM,OAAO,GAAG,MAAM,CAAA,GAAA,iBAAE,CAAA,CAAC,IAAI,CAAC,aAAa,CAAC,AAAC;IAC7C,IAAI,OAAO,CAAC,MAAM,EAAE,EAAE;QACrB,MAAM,aAAa,CAAC;QACpB,OAAO;KACP;IAED,MAAM,OAAO,GAAG,MAAM,CAAA,GAAA,iBAAE,CAAA,CAAC,OAAO,CAAC,aAAa,EAAE;QAAE,aAAa,EAAE,IAAI;KAAE,CAAC,AAAC;IACzE,KAAK,MAAM,MAAM,IAAI,OAAO,CAAE;QAC7B,MAAM,GAAG,GAAG,CAAA,GAAA,WAAI,CAAA,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,AAAC;QACrD,IAAI,MAAM,CAAC,WAAW,EAAE,EACvB,OAAO,8BAAQ,CAAC,GAAG,CAAC,CAAC;aAErB,MAAM,GAAG,CAAC;KAEX;CACD;AAED,MAAM,wCAAkB,GAAG,OAAO,iBACjC,aAAa,CAAA,UACb,MAAM,CAAA,2BACN,uBAAuB,CAAA,EAKvB,GAAK;IACL,aAAa,GAAG,CAAA,GAAA,WAAI,CAAA,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5C,MAAM,QAAQ,GAAG,MAAM,CAAA,GAAA,iBAAE,CAAA,CAAC,IAAI,CAAC,aAAa,CAAC,AAAC;IAC9C,IACC,CAAC,QAAQ,CAAC,MAAM,EAAE,IACf,CAAC,Q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AAO,EAAE,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE;oBACZ,CAAA,GAAA,oBAAa,CAAA,CAAC,MAAM,CAAC;wBACpB,WAAW,EAAE,MAAM;wBACnB,WAAW,EAAE,mCAAmC;wBAChD,IAAI,EAAE,QAAQ;qBACd,CAAC;iBACF;gBACD,QAAQ,EAAE,MAAM;aAChB,CAAC;YACF,CAAA,GAAA,WAAI,CAAA,CAAC,MAAM,CAAC;gBACX,IAAI,EAAE,KAAK;gBACX,OAAO,EAAE,YAAY;gBACrB,WAAW,EAAE,sDAAsD;gBACnE,OAAO,EAAE,EAAE;gBACX,OAAO,EAAE,OAAO;gBAChB,WAAW,EAAE;oBACZ,CAAA,GAAA,oBAAa,CAAA,CAAC,MAAM,CAAC;wBACpB,WAAW,EAAE,MAAM;wBACnB,WAAW,EAAE,yEAAyE;wBACtF,IAAI,EAAE,QAAQ;qBACd,CAAC;iBACF;aACD,CAAC;SACF;eACD,wCAAK;KACL,CAAA,AAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sources":["taqueria-plugin-ipfs-pinata/index.ts","taqueria-plugin-ipfs-pinata/src/proxy.ts","taqueria-plugin-ipfs-pinata/src/file-processing.ts","taqueria-plugin-ipfs-pinata/src/pinata-api.ts","taqueria-plugin-ipfs-pinata/src/utils.ts"],"sourcesContent":["import { Option, Plugin, PositionalArg, Task } from '@taqueria/node-sdk';\nimport proxy from './src/proxy';\n\nPlugin.create(() => ({\n\tschema: '0.1',\n\tversion: '0.4.0',\n\talias: 'pinata',\n\ttasks: [\n\t\tTask.create({\n\t\t\ttask: 'publish',\n\t\t\tcommand: 'publish [path]',\n\t\t\tdescription: 'Upload and pin files using your pinata account.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'path',\n\t\t\t\t\tdescription: 'Directory or file path to publish',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t\tencoding: 'json',\n\t\t}),\n\t\tTask.create({\n\t\t\ttask: 'pin',\n\t\t\tcommand: 'pin [hash]',\n\t\t\tdescription: 'Pin a file already on ipfs with your pinata account.',\n\t\t\taliases: [],\n\t\t\thandler: 'proxy',\n\t\t\tpositionals: [\n\t\t\t\tPositionalArg.create({\n\t\t\t\t\tplaceholder: 'hash',\n\t\t\t\t\tdescription: 'Ipfs hash of the file or directory that is already on the ipfs network.',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t}),\n\t\t\t],\n\t\t}),\n\t],\n\tproxy,\n}), process.argv);\n","import { sendAsyncErr, sendAsyncRes, sendErr, sendJsonRes } from '@taqueria/node-sdk';\nimport { LoadedConfig, RequestArgs, SanitizedAbsPath } from '@taqueria/node-sdk/types';\nimport path from 'path';\nimport { processFiles } from './file-processing';\nimport { PinataAuth, pinHash, publishFileToIpfs } from './pinata-api';\nimport { createProcessBackoffController } from './utils';\n\n// Load .env for jwt token\n// TODO: How should this be stored in a secure way?\nimport 'dotenv/config';\n\n// TODO: What should this be, it was removed from the sdk\ntype PluginResponse =\n\t| void\n\t| {\n\t\trender: 'table';\n\t\tdata: unknown[];\n\t};\n\ninterface Opts extends RequestArgs.ProxyRequestArgs {\n\treadonly path?: string;\n\treadonly hash?: string;\n}\n\nconst publishToIpfs = async (fileOrDirPath: undefined | string, auth: PinataAuth): Promise<PluginResponse> => {\n\tif (!fileOrDirPath) {\n\t\tthrow new Error(`path was not provided`);\n\t}\n\n\t// Pinata is limited to 180 requests per minute\n\t// So for the first 180 requests they can go fast\n\n\tconst { processWithBackoff } = createProcessBackoffController({\n\t\tretryCount: 5,\n\t\ttargetRequestsPerMinute: 180,\n\t});\n\n\tconst result = await processFiles({\n\t\tfileOrDirPath,\n\t\tparallelCount: 10,\n\t\tprocessFile: async filePath => {\n\t\t\t// // TEMP: Debug\n\t\t\t// console.log(`publishing: ${filePath}`);\n\n\t\t\treturn processWithBackoff(() =>\n\t\t\t\tpublishFileToIpfs({\n\t\t\t\t\tauth,\n\t\t\t\t\titem: { filePath, name: path.basename(filePath) },\n\t\t\t\t})\n\t\t\t);\n\t\t},\n\t\tonProgress: ({ processedFilesCount, estimateFileCount }) => {\n\t\t\tif (estimateFileCount && processedFilesCount % 10) {\n\t\t\t\tlet ratio = processedFilesCount / estimateFileCount;\n\t\t\t\tif (ratio > 1) ratio = 1;\n\n\t\t\t\t// // TODO: Call task sdk progress\n\t\t\t\t// console.log(`Progress: ${(ratio * 100).toFixed(0)}%`);\n\t\t\t}\n\t\t},\n\t});\n\n\t// // TEMP: DEBUG: Show error\n\t// if (result.failures.length) {\n\t// \tconsole.log('❗ Failures:\\n' + result.failures.map(f => `${f.filePath}: ${f.error}`).join('\\n'));\n\t// }\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: [\n\t\t\t...result.failures.map(x => ({\n\t\t\t\t'?': '❌',\n\t\t\t\tfilePath: x.filePath,\n\t\t\t\tipfsHash: undefined,\n\t\t\t\terror: (x.error as { message?: string })?.message ?? JSON.stringify(x.error),\n\t\t\t})),\n\t\t\t...result.successes.map(x => ({\n\t\t\t\t'?': '✔',\n\t\t\t\tfilePath: x.filePath,\n\t\t\t\tipfsHash: x.result.ipfsHash,\n\t\t\t\terror: undefined,\n\t\t\t})),\n\t\t],\n\t};\n};\n\nconst pinToIpfs = async (hash: undefined | string, auth: PinataAuth): Promise<PluginResponse> => {\n\tif (!hash) {\n\t\tthrow new Error(`ipfs hash was not provided`);\n\t}\n\n\tawait pinHash({ ipfsHash: hash, auth });\n\n\treturn {\n\t\trender: 'table',\n\t\tdata: [{ ipfsHash: hash }],\n\t};\n};\n\nconst execute = async (opts: Opts): Promise<PluginResponse> => {\n\tconst {\n\t\ttask,\n\t\tpath,\n\t\thash,\n\t\tconfig,\n\t} = opts;\n\n\tconst auth: PinataAuth = {\n\t\t// TODO: Where should this be stored?\n\t\t// pinataJwtToken: (config as Record<string, any>).credentials.pinataJwtToken,\n\t\tpinataJwtToken: process.env['pinataJwtToken'] as string,\n\t};\n\n\tif (!auth.pinataJwtToken) {\n\t\tthrow new Error(`The 'credentials.pinataJwtToken' was not found in config`);\n\t}\n\n\tswitch (task) {\n\t\tcase 'publish':\n\t\t\treturn publishToIpfs(path, auth);\n\t\tcase 'pin':\n\t\t\treturn pinToIpfs(hash, auth);\n\t\tdefault:\n\t\t\tthrow new Error(`${task} is not an understood task by the ipfs-pinata plugin`);\n\t}\n};\n\nexport default async (args: RequestArgs.ProxyRequestArgs): Promise<PluginResponse> => {\n\tconst opts = args as Opts;\n\n\ttry {\n\t\tconst resultRaw = await execute(opts) as Record<string, unknown>;\n\t\t// TODO: Fix deno parsing\n\t\t// Without this, `data.reduce is not a function`\n\t\tconst result = ('data' in resultRaw) ? resultRaw.data : resultRaw;\n\t\treturn sendJsonRes(result);\n\t} catch (err) {\n\t\tconst error = err as Error;\n\t\tif (error.message) {\n\t\t\treturn sendAsyncErr(error.message);\n\t\t}\n\t}\n};\n","import fs from 'fs/promises';\nimport path from 'path';\n\n// Async generator\n// https://stackoverflow.com/questions/5827612/node-js-fs-readdir-recursive-directory-search\nasync function* getFiles(fileOrDirPath: string): AsyncGenerator<string, void, unknown> {\n\tconst dirInfo = await fs.stat(fileOrDirPath);\n\tif (dirInfo.isFile()) {\n\t\tyield fileOrDirPath;\n\t\treturn;\n\t}\n\n\tconst dirents = await fs.readdir(fileOrDirPath, { withFileTypes: true });\n\tfor (const dirent of dirents) {\n\t\tconst res = path.resolve(fileOrDirPath, dirent.name);\n\t\tif (dirent.isDirectory()) {\n\t\t\tyield* getFiles(res);\n\t\t} else {\n\t\t\tyield res;\n\t\t}\n\t}\n}\n\nconst createFileProvider = async ({\n\tfileOrDirPath,\n\tfilter,\n\tshouldEstimateFileCount,\n}: {\n\tfileOrDirPath: string;\n\tfilter?: (filePath: string) => boolean;\n\tshouldEstimateFileCount?: boolean;\n}) => {\n\tfileOrDirPath = path.resolve(fileOrDirPath);\n\tconst pathInfo = await fs.stat(fileOrDirPath);\n\tif (\n\t\t!pathInfo.isFile()\n\t\t&& !pathInfo.isDirectory()\n\t) {\n\t\tthrow new Error(`The path '${fileOrDirPath}' is not a file or directory`);\n\t}\n\n\tlet estimateFileCount = undefined as undefined | number;\n\tif (shouldEstimateFileCount) {\n\t\testimateFileCount = 0;\n\t\tfor await (const filePath of getFiles(fileOrDirPath)) {\n\t\t\tif (filter && !filter(filePath)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\testimateFileCount++;\n\t\t}\n\t}\n\n\tconst fileGenerator = getFiles(fileOrDirPath);\n\tconst getNextFile = async () => {\n\t\tlet nextFile = (await fileGenerator.next()).value;\n\t\tif (!filter) {\n\t\t\treturn nextFile;\n\t\t}\n\n\t\twhile (nextFile && !filter(nextFile)) {\n\t\t\tnextFile = await getNextFile();\n\t\t}\n\n\t\treturn nextFile;\n\t};\n\treturn {\n\t\tgetNextFile,\n\t\testimateFileCount,\n\t};\n};\n\ntype ProgressInfo = { processedFilesCount: number; estimateFileCount: undefined | number };\nexport const processFiles = async <TResult>({\n\tfileOrDirPath,\n\tprocessFile,\n\tfilter,\n\tparallelCount = 10,\n\tonProgress,\n}: {\n\tfileOrDirPath: string;\n\tprocessFile: (filePath: string, progress: ProgressInfo) => Promise<TResult>;\n\tfilter?: (filePath: string) => boolean;\n\tparallelCount?: number;\n\tonProgress?: (progress: ProgressInfo) => void;\n}) => {\n\tconst { getNextFile, estimateFileCount } = await createFileProvider({\n\t\tfileOrDirPath,\n\t\tfilter,\n\t\tshouldEstimateFileCount: true,\n\t});\n\n\tconst successes = [] as { filePath: string; result: TResult }[];\n\tconst failures = [] as { filePath: string; error: unknown }[];\n\n\tonProgress?.({\n\t\tprocessedFilesCount: 0,\n\t\testimateFileCount,\n\t});\n\n\tawait Promise.all([...new Array(parallelCount)].map(async x => {\n\t\tlet fileToProcess = await getNextFile();\n\t\twhile (fileToProcess) {\n\t\t\tconst progressInfo = {\n\t\t\t\tprocessedFilesCount: successes.length + failures.length,\n\t\t\t\testimateFileCount,\n\t\t\t};\n\t\t\tonProgress?.(progressInfo);\n\n\t\t\ttry {\n\t\t\t\tconst result = await processFile(fileToProcess, progressInfo);\n\t\t\t\tsuccesses.push({ filePath: fileToProcess, result });\n\t\t\t} catch (err) {\n\t\t\t\tfailures.push({ filePath: fileToProcess, error: err });\n\t\t\t}\n\n\t\t\tfileToProcess = await getNextFile();\n\t\t}\n\t}));\n\n\tonProgress?.({\n\t\tprocessedFilesCount: successes.length + failures.length,\n\t\testimateFileCount,\n\t});\n\n\treturn {\n\t\tsuccesses,\n\t\tfailures,\n\t};\n};\n","import FormData from 'form-data';\nimport fs from 'fs';\nimport Hash from 'ipfs-only-hash';\nimport fetch from 'node-fetch';\n\nexport type PinataAuth = {\n\tpinataJwtToken: string;\n};\n\nexport type PublishFileResult = {\n\tipfsHash: string;\n};\n\nexport const publishFileToIpfs = async ({\n\tauth,\n\titem,\n}: {\n\tauth: PinataAuth;\n\titem: {\n\t\tname: string;\n\t\tfilePath: string;\n\t};\n}): Promise<PublishFileResult> => {\n\t// The data api to check for existing file is limited to 30 requests per minute\n\t// While uploading allows 180 requests per minute\n\t// i.e. it's faster to just upload again\n\n\t// // Skip if already pinned\n\t// const { isPinned, ipfsHash } = await checkIfFileIsPinned({ auth, item });\n\t// if (isPinned) {\n\t// \treturn {\n\t// \t\tipfsHash,\n\t// \t};\n\t// }\n\n\tconst data = new FormData();\n\tdata.append('file', fs.createReadStream(item.filePath));\n\tdata.append(\n\t\t'pinataMetadata',\n\t\tJSON.stringify({\n\t\t\tname: item.name,\n\t\t}),\n\t);\n\n\tconst response = await fetch(`https://api.pinata.cloud/pinning/pinFileToIPFS`, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${auth.pinataJwtToken}`,\n\t\t\t'Content-Type': `multipart/form-data; boundary=${(data as unknown as { _boundary: string })._boundary}`,\n\t\t},\n\t\tbody: data,\n\t\tmethod: 'post',\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to upload '${item.name}' to ipfs ${response.statusText}`);\n\t}\n\n\tconst uploadResult = await response.json() as {\n\t\tIpfsHash: string; // This is the IPFS multi-hash provided back for your content,\n\t\tPinSize: string; // This is how large (in bytes) the content you just pinned is,\n\t\tTimestamp: string; // This is the timestamp for your content pinning (represented in ISO 8601 format)\n\t};\n\n\treturn {\n\t\tipfsHash: uploadResult.IpfsHash,\n\t};\n};\n\nconst checkIfFileIsPinned = async ({\n\tauth,\n\titem,\n}: {\n\tauth: PinataAuth;\n\titem: {\n\t\tname: string;\n\t\tfilePath: string;\n\t};\n}) => {\n\tconst ipfsHash = await Hash.of(fs.createReadStream(item.filePath));\n\n\tconst response = await fetch(`https://api.pinata.cloud/data/pinList?status=pinned&hashContains=${ipfsHash}`, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${auth.pinataJwtToken}`,\n\t\t},\n\t\tmethod: 'get',\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to query '${item.name}' status from pinata ${response.statusText}`);\n\t}\n\n\tconst pinResult = await response.json() as {\n\t\tcount: number;\n\t\trows: {\n\t\t\tid: string;\n\t\t\tipfs_pin_hash: string;\n\t\t\tsize: number;\n\t\t\tuser_id: string;\n\t\t\tdate_pinned: null | string;\n\t\t\tdate_unpinned: null | string;\n\t\t\tmetadata: {\n\t\t\t\tname: string;\n\t\t\t\tkeyvalues: null | string;\n\t\t\t};\n\t\t\tregions: {\n\t\t\t\tregionId: string;\n\t\t\t\tcurrentReplicationCount: number;\n\t\t\t\tdesiredReplicationCount: number;\n\t\t\t}[];\n\t\t}[];\n\t};\n\n\tconst isPinned = pinResult.rows.some(x =>\n\t\tx.ipfs_pin_hash === ipfsHash\n\t\t&& x.date_pinned\n\t\t&& !x.date_unpinned\n\t);\n\n\treturn {\n\t\tisPinned,\n\t\tipfsHash,\n\t};\n};\n\nexport const pinHash = async ({\n\tauth,\n\tipfsHash,\n}: {\n\tauth: PinataAuth;\n\tipfsHash: string;\n}) => {\n\tconst response = await fetch(`https://api.pinata.cloud/pinning/pinByHash`, {\n\t\theaders: {\n\t\t\tAuthorization: `Bearer ${auth.pinataJwtToken}`,\n\t\t\t'Content-Type': 'application/json',\n\t\t},\n\t\tmethod: 'post',\n\t\tbody: JSON.stringify({\n\t\t\thashToPin: ipfsHash,\n\t\t}),\n\t});\n\n\tif (!response.ok) {\n\t\tthrow new Error(`Failed to pin '${ipfsHash}' with pinata: ${response.statusText}`);\n\t}\n\n\t// Ok is the only response if successful\n\treturn;\n};\n","export async function delay(timeout: number): Promise<void> {\n\treturn await new Promise(resolve => {\n\t\tsetTimeout(resolve, timeout);\n\t});\n}\n\nexport const createProcessBackoffController = ({\n\tretryCount = 5,\n\ttargetRequestsPerMinute = 180,\n}: {\n\tretryCount?: number;\n\ttargetRequestsPerMinute?: number;\n}) => {\n\tlet averageTimePerRequest = 5000;\n\tlet targetTimePerRequest = 60000 / targetRequestsPerMinute;\n\tlet lastTime = Date.now();\n\n\tconst processWithBackoff = async <TResult>(process: () => Promise<TResult>) => {\n\t\tlet attempt = 0;\n\t\tlet lastError = undefined as unknown;\n\t\twhile (attempt < retryCount) {\n\t\t\ttry {\n\t\t\t\tlet delayTimeMs = Math.max(10, targetTimePerRequest - averageTimePerRequest);\n\n\t\t\t\t// Partially randomized delay to ensure parallel requests don't line up\n\t\t\t\tawait delay(Math.floor(delayTimeMs * (1 + 0.5 * Math.random())));\n\n\t\t\t\tconst result = await process();\n\n\t\t\t\tconst timeNow = Date.now();\n\t\t\t\tconst timeElapsed = timeNow - lastTime;\n\t\t\t\tlastTime = timeNow;\n\n\t\t\t\t// Running average\n\t\t\t\taverageTimePerRequest = averageTimePerRequest * 0.97 + timeElapsed * 0.03;\n\n\t\t\t\treturn result;\n\t\t\t} catch (err) {\n\t\t\t\tlastError = err;\n\t\t\t}\n\n\t\t\t// Quickly increase time to wait if failure (allow negatives to wait longer than target)\n\t\t\taverageTimePerRequest -= (attempt + 1) * 1000;\n\t\t\tattempt++;\n\t\t}\n\n\t\t// All attempts failed\n\t\tthrow lastError;\n\t};\n\n\treturn {\n\t\tprocessWithBackoff,\n\t};\n};\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
package/index.ts CHANGED
@@ -21,21 +21,20 @@ Plugin.create(() => ({
21
21
  ],
22
22
  encoding: 'json',
23
23
  }),
24
- // Pinning Not Implemented Yet
25
- // Task.create({
26
- // task: 'pin',
27
- // command: 'pin [hash]',
28
- // description: 'Pin a file already on ipfs with your pinata account.',
29
- // aliases: [],
30
- // handler: 'proxy',
31
- // positionals: [
32
- // PositionalArg.create({
33
- // placeholder: 'hash',
34
- // description: 'Ipfs hash of the file or directory that is already on the ipfs network.',
35
- // type: 'string',
36
- // }),
37
- // ]
38
- // }),
24
+ Task.create({
25
+ task: 'pin',
26
+ command: 'pin [hash]',
27
+ description: 'Pin a file already on ipfs with your pinata account.',
28
+ aliases: [],
29
+ handler: 'proxy',
30
+ positionals: [
31
+ PositionalArg.create({
32
+ placeholder: 'hash',
33
+ description: 'Ipfs hash of the file or directory that is already on the ipfs network.',
34
+ type: 'string',
35
+ }),
36
+ ],
37
+ }),
39
38
  ],
40
39
  proxy,
41
40
  }), process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taqueria/plugin-ipfs-pinata",
3
- "version": "0.13.0",
3
+ "version": "0.14.2",
4
4
  "description": "A plugin for Taqueria providing ipfs publishing and pinning using the Pinata service",
5
5
  "keywords": [
6
6
  "taqueria",
@@ -33,7 +33,7 @@
33
33
  "directory": "taqueria-plugin-ipfs-pinata"
34
34
  },
35
35
  "dependencies": {
36
- "@taqueria/node-sdk": "^0.13.0",
36
+ "@taqueria/node-sdk": "^0.14.2",
37
37
  "dotenv": "^16.0.0",
38
38
  "form-data": "^4.0.0",
39
39
  "ipfs-only-hash": "^4.0.0",
package/src/pinata-api.ts CHANGED
@@ -121,3 +121,29 @@ const checkIfFileIsPinned = async ({
121
121
  ipfsHash,
122
122
  };
123
123
  };
124
+
125
+ export const pinHash = async ({
126
+ auth,
127
+ ipfsHash,
128
+ }: {
129
+ auth: PinataAuth;
130
+ ipfsHash: string;
131
+ }) => {
132
+ const response = await fetch(`https://api.pinata.cloud/pinning/pinByHash`, {
133
+ headers: {
134
+ Authorization: `Bearer ${auth.pinataJwtToken}`,
135
+ 'Content-Type': 'application/json',
136
+ },
137
+ method: 'post',
138
+ body: JSON.stringify({
139
+ hashToPin: ipfsHash,
140
+ }),
141
+ });
142
+
143
+ if (!response.ok) {
144
+ throw new Error(`Failed to pin '${ipfsHash}' with pinata: ${response.statusText}`);
145
+ }
146
+
147
+ // Ok is the only response if successful
148
+ return;
149
+ };
package/src/proxy.ts CHANGED
@@ -2,7 +2,7 @@ import { sendAsyncErr, sendAsyncRes, sendErr, sendJsonRes } from '@taqueria/node
2
2
  import { LoadedConfig, RequestArgs, SanitizedAbsPath } from '@taqueria/node-sdk/types';
3
3
  import path from 'path';
4
4
  import { processFiles } from './file-processing';
5
- import { PinataAuth, publishFileToIpfs } from './pinata-api';
5
+ import { PinataAuth, pinHash, publishFileToIpfs } from './pinata-api';
6
6
  import { createProcessBackoffController } from './utils';
7
7
 
8
8
  // Load .env for jwt token
@@ -89,8 +89,12 @@ const pinToIpfs = async (hash: undefined | string, auth: PinataAuth): Promise<Pl
89
89
  throw new Error(`ipfs hash was not provided`);
90
90
  }
91
91
 
92
- // TODO: Implement pinning
93
- throw new Error('pinToIpfs: Not Implemented');
92
+ await pinHash({ ipfsHash: hash, auth });
93
+
94
+ return {
95
+ render: 'table',
96
+ data: [{ ipfsHash: hash }],
97
+ };
94
98
  };
95
99
 
96
100
  const execute = async (opts: Opts): Promise<PluginResponse> => {