filecoin 0.5.0 → 0.5.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.
Files changed (63) hide show
  1. package/README.md +1 -1
  2. package/dist/chunks/{chunk-YVRWI5E3.js → chunk-3NEWBVNS.js} +2 -2
  3. package/dist/chunks/{chunk-BFBNDHQG.js → chunk-3QZV62NY.js} +2 -2
  4. package/dist/chunks/{chunk-GCPUMM4E.js → chunk-4WNPDK5J.js} +2 -2
  5. package/dist/chunks/{chunk-BZITZ3BI.js → chunk-AK3TY773.js} +2 -2
  6. package/dist/chunks/{chunk-Z6O5SHUU.js → chunk-AX2TW2N4.js} +2 -2
  7. package/dist/chunks/{chunk-CIVQHT3F.js → chunk-DQD55GP5.js} +2 -2
  8. package/dist/chunks/{chunk-72RYXITT.js → chunk-DSBE7JWR.js} +53 -53
  9. package/dist/chunks/{chunk-72RYXITT.js.map → chunk-DSBE7JWR.js.map} +4 -4
  10. package/dist/chunks/{chunk-MWVOEA6K.js → chunk-E73DKTGP.js} +2 -2
  11. package/dist/chunks/{chunk-JFBUOLJ3.js → chunk-KDWK2AA4.js} +2 -2
  12. package/dist/chunks/{chunk-IAJFQYLN.js → chunk-LNTCGGNH.js} +2 -2
  13. package/dist/chunks/{chunk-DHTPICN4.js → chunk-NYPSIN7B.js} +2 -2
  14. package/dist/chunks/{chunk-ASZ5KTWE.js → chunk-QXRO3WEV.js} +2 -2
  15. package/dist/chunks/{chunk-K63EJUGU.js → chunk-RLWURURD.js} +2 -2
  16. package/dist/chunks/{chunk-QRFSFJOZ.js → chunk-RPMAMGIM.js} +2 -2
  17. package/dist/chunks/{chunk-63JLHZEK.js → chunk-WB3TWFGS.js} +2 -2
  18. package/dist/chunks/chunk-YXYHQTNK.js +3 -0
  19. package/dist/chunks/chunk-YXYHQTNK.js.map +7 -0
  20. package/dist/chunks/{delete-BO7K4456.js → delete-6FAMX5W5.js} +2 -2
  21. package/dist/chunks/{doctor-NF75MDBO.js → doctor-UTF5UDXY.js} +2 -2
  22. package/dist/chunks/{get-3EC2XCFH.js → get-LTXETE2C.js} +2 -2
  23. package/dist/chunks/{inspect-FDI442BE.js → inspect-EVK3NFBO.js} +2 -2
  24. package/dist/chunks/{inspect-RJCGSGKG.js → inspect-UZ6NBVNE.js} +2 -2
  25. package/dist/chunks/{login-NNTYQ37I.js → login-3SAES4JH.js} +2 -2
  26. package/dist/chunks/{logout-3RWZFH2E.js → logout-HFZTYLPK.js} +2 -2
  27. package/dist/chunks/{ls-GNEVBKRP.js → ls-RY6LIV7M.js} +2 -2
  28. package/dist/chunks/{ls-F546AXRG.js → ls-WHPFBJZU.js} +2 -2
  29. package/dist/chunks/{put-FXMGPSU6.js → put-UKZN63HP.js} +2 -2
  30. package/dist/chunks/{resume-G5PS246S.js → resume-HKMEASEF.js} +2 -2
  31. package/dist/chunks/{status-HOLDXKMR.js → status-PEOO3TAE.js} +2 -2
  32. package/dist/chunks/{status-HOLDXKMR.js.map → status-PEOO3TAE.js.map} +1 -1
  33. package/dist/main.js +1 -1
  34. package/dist/main.js.map +2 -2
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +3 -3
  37. package/dist/chunks/chunk-AKXAQJ6H.js +0 -3
  38. package/dist/chunks/chunk-AKXAQJ6H.js.map +0 -7
  39. /package/dist/chunks/{chunk-YVRWI5E3.js.map → chunk-3NEWBVNS.js.map} +0 -0
  40. /package/dist/chunks/{chunk-BFBNDHQG.js.map → chunk-3QZV62NY.js.map} +0 -0
  41. /package/dist/chunks/{chunk-GCPUMM4E.js.map → chunk-4WNPDK5J.js.map} +0 -0
  42. /package/dist/chunks/{chunk-BZITZ3BI.js.map → chunk-AK3TY773.js.map} +0 -0
  43. /package/dist/chunks/{chunk-Z6O5SHUU.js.map → chunk-AX2TW2N4.js.map} +0 -0
  44. /package/dist/chunks/{chunk-CIVQHT3F.js.map → chunk-DQD55GP5.js.map} +0 -0
  45. /package/dist/chunks/{chunk-MWVOEA6K.js.map → chunk-E73DKTGP.js.map} +0 -0
  46. /package/dist/chunks/{chunk-JFBUOLJ3.js.map → chunk-KDWK2AA4.js.map} +0 -0
  47. /package/dist/chunks/{chunk-IAJFQYLN.js.map → chunk-LNTCGGNH.js.map} +0 -0
  48. /package/dist/chunks/{chunk-DHTPICN4.js.map → chunk-NYPSIN7B.js.map} +0 -0
  49. /package/dist/chunks/{chunk-ASZ5KTWE.js.map → chunk-QXRO3WEV.js.map} +0 -0
  50. /package/dist/chunks/{chunk-K63EJUGU.js.map → chunk-RLWURURD.js.map} +0 -0
  51. /package/dist/chunks/{chunk-QRFSFJOZ.js.map → chunk-RPMAMGIM.js.map} +0 -0
  52. /package/dist/chunks/{chunk-63JLHZEK.js.map → chunk-WB3TWFGS.js.map} +0 -0
  53. /package/dist/chunks/{delete-BO7K4456.js.map → delete-6FAMX5W5.js.map} +0 -0
  54. /package/dist/chunks/{doctor-NF75MDBO.js.map → doctor-UTF5UDXY.js.map} +0 -0
  55. /package/dist/chunks/{get-3EC2XCFH.js.map → get-LTXETE2C.js.map} +0 -0
  56. /package/dist/chunks/{inspect-FDI442BE.js.map → inspect-EVK3NFBO.js.map} +0 -0
  57. /package/dist/chunks/{inspect-RJCGSGKG.js.map → inspect-UZ6NBVNE.js.map} +0 -0
  58. /package/dist/chunks/{login-NNTYQ37I.js.map → login-3SAES4JH.js.map} +0 -0
  59. /package/dist/chunks/{logout-3RWZFH2E.js.map → logout-HFZTYLPK.js.map} +0 -0
  60. /package/dist/chunks/{ls-GNEVBKRP.js.map → ls-RY6LIV7M.js.map} +0 -0
  61. /package/dist/chunks/{ls-F546AXRG.js.map → ls-WHPFBJZU.js.map} +0 -0
  62. /package/dist/chunks/{put-FXMGPSU6.js.map → put-UKZN63HP.js.map} +0 -0
  63. /package/dist/chunks/{resume-G5PS246S.js.map → resume-HKMEASEF.js.map} +0 -0
package/README.md CHANGED
@@ -131,7 +131,7 @@ Ctrl+C, SIGTERM, or SIGHUP stops the work at the next step. `filecoin` returns a
131
131
  | `FILECOIN_STATE_DIR` | SQLite state and staged CARs. Default: the platform data directory for `filecoin` |
132
132
  | `FILECOIN_RPC_URL` | RPC endpoint. Default: synapse-core's fallback transport for the chain |
133
133
  | `FILECOIN_CONSOLE_URL` | filecoin-app origin for approval and funding links, such as `http://localhost:5173` for a local app. Default: `https://poc.filecoin.cloud` |
134
- | `FILECOIN_API_URL` | filecoin-api origin for retrieval links, such as `http://localhost:8787` for a local API. Default: `https://api.filecoin.cloud` |
134
+ | `FILECOIN_API_URL` | filecoin-api origin for retrieval links, such as `http://localhost:8787` for a local API. Default: `https://api.filecoin.io` |
135
135
  | `FILECOIN_OUTPUT`, `FILECOIN_AGENT` | Override clipact's output mode and agent detection |
136
136
 
137
137
  The prototype saves the session private key in the config file with mode 0600, so only its owner can read it. `filecoin logout` deletes the local key. The key stays authorized on chain until it expires or you revoke it on the filecoin-app session keys page.
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{d as n,e as o,n as s}from"./chunk-72RYXITT.js";function f(r){if(r===n.id.toString())return"mainnet";if(r===o.id.toString())return"calibration";throw new Error(`Unknown chain ID ${r}.`)}function c(r,e,d,a,t){let i=new URL(`get/${encodeURIComponent(d)}`,r.endsWith("/")?r:`${r}/`);return i.searchParams.set("network",e),a&&i.searchParams.set("browser","true"),t&&i.searchParams.set("provider",t),i.toString()}function p(r){let e=f(r.chainId);return{piece:c(r.apiUrl,e,r.pieceCid,!1,r.providerId),browser:c(r.apiUrl,e,r.rootCid??r.pieceCid,!0,r.rootCid?void 0:r.providerId)}}function l(r,e){return p({apiUrl:e,chainId:r.chainId,pieceCid:r.pieceCid,rootCid:r.rootCid})}function w(r){let[e]=r.copies;if(!e)throw new Error(`Resource ${r.ref} has no stored copies.`);return s({cid:r.pieceCid,serviceURL:e.serviceURL.endsWith("/")?e.serviceURL:`${e.serviceURL}/`})}export{p as a,l as b,w as c};
3
- //# sourceMappingURL=chunk-YVRWI5E3.js.map
2
+ import{d as n,e as o,n as s}from"./chunk-DSBE7JWR.js";function f(r){if(r===n.id.toString())return"mainnet";if(r===o.id.toString())return"calibration";throw new Error(`Unknown chain ID ${r}.`)}function c(r,e,d,a,t){let i=new URL(`get/${encodeURIComponent(d)}`,r.endsWith("/")?r:`${r}/`);return i.searchParams.set("network",e),a&&i.searchParams.set("browser","true"),t&&i.searchParams.set("provider",t),i.toString()}function p(r){let e=f(r.chainId);return{piece:c(r.apiUrl,e,r.pieceCid,!1,r.providerId),browser:c(r.apiUrl,e,r.rootCid??r.pieceCid,!0,r.rootCid?void 0:r.providerId)}}function l(r,e){return p({apiUrl:e,chainId:r.chainId,pieceCid:r.pieceCid,rootCid:r.rootCid})}function w(r){let[e]=r.copies;if(!e)throw new Error(`Resource ${r.ref} has no stored copies.`);return s({cid:r.pieceCid,serviceURL:e.serviceURL.endsWith("/")?e.serviceURL:`${e.serviceURL}/`})}export{p as a,l as b,w as c};
3
+ //# sourceMappingURL=chunk-3NEWBVNS.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{C as l,a as e,b as r,c as n,f as s,g as u,i as c,k as i,u as a,v as f}from"./chunk-JUFFOBKU.js";import{d as o}from"./chunk-3TJUKWFC.js";var b=o({name:"get",description:"Download and verify a resource (by ref or PieceCID)",examples:["filecoin get res_abc123","filecoin get res_abc123 --output ./copy"],input:u({target:e().describe("Resource ref (res_\u2026), PieceCID, or root CID"),output:e().optional().describe("Output path (default: the resource name)"),force:n().default(!1).describe("Overwrite an existing file"),...a}),positionals:["target"],env:f,secrets:["sessionKey"],output:s({kind:c(["file","folder"]),ref:e().optional(),pieceCid:e(),output:e().describe("Written file or directory"),size:r().int().describe("Verified bytes downloaded"),files:r().int().optional().describe("Files extracted"),url:e()}),errors:[i.authRequired,i.loginPending,i.notFound,i.outputExists,i.verificationFailed,i.unsafePath],idempotent:!0,human:t=>`Wrote ${t.output} (${l(t.size)}${t.files==null?"":`, ${t.files} files`}), verified against ${t.pieceCid}`,handler:()=>import("./get-3EC2XCFH.js")});export{b as a};
3
- //# sourceMappingURL=chunk-BFBNDHQG.js.map
2
+ import{C as l,a as e,b as r,c as n,f as s,g as u,i as c,k as i,u as a,v as f}from"./chunk-JUFFOBKU.js";import{d as o}from"./chunk-3TJUKWFC.js";var b=o({name:"get",description:"Download and verify a resource (by ref or PieceCID)",examples:["filecoin get res_abc123","filecoin get res_abc123 --output ./copy"],input:u({target:e().describe("Resource ref (res_\u2026), PieceCID, or root CID"),output:e().optional().describe("Output path (default: the resource name)"),force:n().default(!1).describe("Overwrite an existing file"),...a}),positionals:["target"],env:f,secrets:["sessionKey"],output:s({kind:c(["file","folder"]),ref:e().optional(),pieceCid:e(),output:e().describe("Written file or directory"),size:r().int().describe("Verified bytes downloaded"),files:r().int().optional().describe("Files extracted"),url:e()}),errors:[i.authRequired,i.loginPending,i.notFound,i.outputExists,i.verificationFailed,i.unsafePath],idempotent:!0,human:t=>`Wrote ${t.output} (${l(t.size)}${t.files==null?"":`, ${t.files} files`}), verified against ${t.pieceCid}`,handler:()=>import("./get-LTXETE2C.js")});export{b as a};
3
+ //# sourceMappingURL=chunk-3QZV62NY.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{a as w}from"./chunk-AKXAQJ6H.js";import{a as y,b as M}from"./chunk-YVRWI5E3.js";import{C as L,F as g,L as J,M as _,N as S,O as T,Q as b,R as z,S as F,T as B,U as v}from"./chunk-72RYXITT.js";import{k as p,o as E,p as I,q as l}from"./chunk-JUFFOBKU.js";import{p as m,q as $}from"./chunk-3TJUKWFC.js";import{createReadStream as j}from"node:fs";import{rm as q,stat as k}from"node:fs/promises";import{basename as Q,join as X,resolve as V}from"node:path";var G={source:"filecoin"},K={source:"filecoin",withIPFSIndexing:""},Y=96;async function H(e){let t=V(e.path),i=await k(t).catch(()=>{});if(!i||!(i.isFile()||i.isDirectory()))throw I(`No file or directory at ${e.path}.`,"path");let r=e.name??Q(t);return i.isDirectory()?{sourcePath:t,kind:"folder",name:r}:(C(i.size),{sourcePath:t,kind:"file",name:r,size:i.size})}async function ve(e,t){let i=await H(t),r=S(e.db,{action:"put",resourceRef:_("res"),chainId:e.chainId,payer:e.payer,input:{sourcePath:i.sourcePath,name:i.name,kind:i.kind,providerId:t.providerId?.toString()}});return await N(e,r.id)}async function Se(e){let t=await H(e),i;if(t.kind==="file")i={kind:"file",name:t.name,size:t.size??0,files:1};else{let d=await w(t.sourcePath);C(d.size),i={kind:"folder",name:t.name,size:d.size,files:d.files,rootCid:d.rootCid.toString()}}if(!e.backend)return i;let r=await e.backend.selectPlacement({metadata:P(i.kind),providerId:e.providerId}),a=await e.backend.quote({size:i.size,placement:r});return{...i,placement:r,quote:a}}async function N(e,t){let i=T(e.db,t);if(!i)throw l(`Operation ${t} not found.`);if(i.executionStatus==="completed")return x(e,i);let r=z(e.db,t);try{return e.onOperation?.(r),r.action==="put"?await te(e,r):await ae(e,r)}catch(a){throw b(e.db,r.id,{executionStatus:"failed",pid:null,error:e.signal?.aborted?"Interrupted":a instanceof Error?a.message:String(a)}),e.signal?.aborted?a:E(a,r.id)}finally{F(r.id)}}function x(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} of ${t.id} no longer exists.`);return Z(e,t,i)}function Z(e,t,i){return{operationId:t.id,state:t.action==="put"?"ready":"removal_pending",resource:i,urls:M(i,e.apiUrl)}}function W(e,t,i,r={}){J(e.db,()=>{B(e.db,i),b(e.db,t.id,{executionStatus:"completed",phase:"done",pid:null,error:null,checkpoint:r})})}function C(e){if(e<g.MIN_UPLOAD_SIZE||e>g.MAX_UPLOAD_SIZE)throw I(`Content must be between ${g.MIN_UPLOAD_SIZE} and ${g.MAX_UPLOAD_SIZE} bytes; got ${e}.`,"path")}function P(e){return e==="folder"?K:G}async function ee(e,t){let i=j(e,{signal:t});return(await L(i)).toString()}function u(e,t,i,r){return b(e.db,t.id,{checkpoint:i,...r?{phase:r}:{}})}async function te(e,t){let{input:i}=t,r=i.kind??"file",a=i.name??"upload",d=e.signal;if(!i.sourcePath)throw new Error(`Operation ${t.id} has no source.`);let s=i.sourcePath;if(r==="folder"&&(s=X(e.stagingDir(t.id),"folder.car"),!await k(s).catch(()=>{}))){if(t.checkpoint.pieceCid)throw new m({code:p.stagingMissing,message:`The staged CAR of ${t.id} is missing, so it cannot be resumed.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put of the same directory"}]});t=u(e,t,{},"packing"),e.progress?.({phase:"packing",message:`Packing ${i.sourcePath}`});let D=await w(i.sourcePath,s);t=u(e,t,{rootCid:D.rootCid.toString(),size:D.size})}d?.throwIfAborted();let c=(await k(s)).size;C(c),e.progress?.({phase:"hashing",message:"Computing PieceCID"});let o=await ee(s,d);if(t.checkpoint.pieceCid&&t.checkpoint.pieceCid!==o)throw new m({code:p.sourceChanged,message:`${s} changed since operation ${t.id} started.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put with the current content"}]});t=u(e,t,{pieceCid:o,size:c},"storing");let n=ne(t.checkpoint);if(!n){e.progress?.({phase:"placing",message:"Selecting a storage provider"}),n=await e.backend.selectPlacement({metadata:P(r),providerId:i.providerId?BigInt(i.providerId):void 0});let h=await e.backend.quote({size:c,placement:n});if(!h.ready)throw re(h);t=u(e,t,{providerId:n.providerId.toString(),serviceURL:n.serviceURL,payee:n.payee,...n.dataSetId==null?{}:{dataSetId:n.dataSetId.toString(),clientDataSetId:n.clientDataSetId?.toString()}})}t.checkpoint.commit||t.checkpoint.stored||(await e.backend.hasPiece({serviceURL:n.serviceURL,pieceCid:o})||(e.progress?.({phase:"uploading",message:`Uploading ${c} bytes to provider ${n.providerId}`}),await e.backend.upload({serviceURL:n.serviceURL,path:s,size:c,pieceCid:o})),t=u(e,t,{stored:!0}));let R=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid,providerId:n.providerId.toString()}),U=()=>e.progress?.({phase:"link",message:R.browser,data:{pieceCid:o,urls:R}});r==="file"&&U();let f=await ie(e,t,n,{pieceCid:o,name:a},r==="folder"?U:void 0),O=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid}),A={ref:t.resourceRef,kind:r,name:a,chainId:t.chainId,payer:t.payer,pieceCid:o,...t.checkpoint.rootCid?{rootCid:t.checkpoint.rootCid}:{},size:c,copies:[{providerId:n.providerId.toString(),dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString(),serviceURL:n.serviceURL}],url:O.browser,status:"active",createdAt:new Date().toISOString()};return W(e,t,A,{dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString()}),r==="folder"&&await q(e.stagingDir(t.id),{recursive:!0,force:!0}).catch(()=>{}),{operationId:t.id,state:"ready",resource:A,urls:O}}async function ie(e,t,i,r,a){let d={name:r.name.slice(0,Y),...t.checkpoint.rootCid?{ipfsRootCID:t.checkpoint.rootCid}:{}},s=t.checkpoint.commit;if(s){let n=await e.backend.findCommit({nonce:BigInt(s.nonce)});if(n)return n}t=u(e,t,{},"committing");let c=s;if(c||(e.progress?.({phase:"committing",message:"Signing the commit"}),c=await e.backend.signCommit({placement:i,pieceCid:r.pieceCid,metadata:P(t.input.kind??"file"),pieceMetadata:d}),t=u(e,t,{commit:c})),!t.checkpoint.statusUrl){e.progress?.({phase:"committing",message:c.created?"Creating data set and adding piece":"Adding piece"});let n=await e.backend.submitCommit({placement:i,pieceCid:r.pieceCid,commit:c,pieceMetadata:d});t=u(e,t,{statusUrl:n.statusUrl,transactionHash:n.transactionHash})}a?.();let{transactionHash:o}=t.checkpoint;e.progress?.({phase:"committing",message:o?`Waiting for confirmation of transaction ${o}`:"Waiting for on-chain confirmation",...o?{data:{transactionHash:o}}:{}});try{return await e.backend.waitForCommit({statusUrl:t.checkpoint.statusUrl,created:c.created})}catch(n){throw $(n)&&n.code===p.commitRejected&&u(e,t,{statusUrl:void 0,transactionHash:void 0}),n}}function re(e){return new m({code:p.insufficientFunds,message:e.needsApproval?"The payer must deposit USDFC and approve Warm Storage before uploading.":"The payer must deposit more USDFC before uploading.",details:{fundingUrl:e.fundingUrl,depositNeeded:e.depositNeeded.toString(),needsApproval:e.needsApproval},next:[{by:"user",description:`Fund the account at ${e.fundingUrl}`}]})}function ne(e){if(e.providerId&&e.serviceURL&&e.payee)return{providerId:BigInt(e.providerId),serviceURL:e.serviceURL,payee:e.payee,...e.dataSetId&&e.clientDataSetId?{dataSetId:BigInt(e.dataSetId),clientDataSetId:BigInt(e.clientDataSetId)}:{}}}async function we(e,t){let i=v(e.db,t,e);if(!i)throw l(`No managed resource ${t} for this account.`,{by:"agent",command:"filecoin ls",description:"List managed resources"});if(i.status!=="active")throw I(`${t} is already pending removal.`,"ref");let[r]=i.copies;if(!r)throw new Error(`Resource ${t} has no stored copies.`);let a=S(e.db,{action:"delete",resourceRef:t,chainId:e.chainId,payer:e.payer,input:{},checkpoint:{providerId:r.providerId,serviceURL:r.serviceURL,dataSetId:r.dataSetId,pieceId:r.pieceId}});return await N(e,a.id)}async function ae(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} no longer exists.`);let{serviceURL:r,dataSetId:a,pieceId:d}=t.checkpoint;if(!(r&&a&&d))throw new Error(`Operation ${t.id} is missing its removal target.`);if(!t.checkpoint.transactionHash){t=u(e,t,{},"removing"),e.progress?.({phase:"removing",message:`Scheduling removal of piece ${d}`});let{transactionHash:n}=await e.backend.schedulePieceRemoval({serviceURL:r,dataSetId:BigInt(a),pieceId:BigInt(d)});t=u(e,t,{transactionHash:n})}let s=t.checkpoint.transactionHash;if(e.progress?.({phase:"removing",message:`Waiting for confirmation of removal transaction ${s}`,data:{transactionHash:s}}),(await e.backend.waitForTransaction(s)).status!=="success")throw u(e,t,{transactionHash:void 0}),new m({code:p.removalReverted,message:`Removal transaction ${s} reverted; the piece is still stored.`});let o={...i,status:"removal_pending"};return W(e,t,o),Z(e,t,o)}export{ve as a,Se as b,N as c,x as d,we as e};
3
- //# sourceMappingURL=chunk-GCPUMM4E.js.map
2
+ import{a as w}from"./chunk-YXYHQTNK.js";import{a as y,b as M}from"./chunk-3NEWBVNS.js";import{C as L,F as g,L as J,M as _,N as S,O as T,Q as b,R as z,S as F,T as B,U as v}from"./chunk-DSBE7JWR.js";import{k as p,o as E,p as I,q as l}from"./chunk-JUFFOBKU.js";import{p as m,q as $}from"./chunk-3TJUKWFC.js";import{createReadStream as j}from"node:fs";import{rm as q,stat as k}from"node:fs/promises";import{basename as Q,join as X,resolve as V}from"node:path";var G={source:"filecoin"},K={source:"filecoin",withIPFSIndexing:""},Y=96;async function H(e){let t=V(e.path),i=await k(t).catch(()=>{});if(!i||!(i.isFile()||i.isDirectory()))throw I(`No file or directory at ${e.path}.`,"path");let r=e.name??Q(t);return i.isDirectory()?{sourcePath:t,kind:"folder",name:r}:(C(i.size),{sourcePath:t,kind:"file",name:r,size:i.size})}async function ve(e,t){let i=await H(t),r=S(e.db,{action:"put",resourceRef:_("res"),chainId:e.chainId,payer:e.payer,input:{sourcePath:i.sourcePath,name:i.name,kind:i.kind,providerId:t.providerId?.toString()}});return await N(e,r.id)}async function Se(e){let t=await H(e),i;if(t.kind==="file")i={kind:"file",name:t.name,size:t.size??0,files:1};else{let d=await w(t.sourcePath);C(d.size),i={kind:"folder",name:t.name,size:d.size,files:d.files,rootCid:d.rootCid.toString()}}if(!e.backend)return i;let r=await e.backend.selectPlacement({metadata:P(i.kind),providerId:e.providerId}),a=await e.backend.quote({size:i.size,placement:r});return{...i,placement:r,quote:a}}async function N(e,t){let i=T(e.db,t);if(!i)throw l(`Operation ${t} not found.`);if(i.executionStatus==="completed")return x(e,i);let r=z(e.db,t);try{return e.onOperation?.(r),r.action==="put"?await te(e,r):await ae(e,r)}catch(a){throw b(e.db,r.id,{executionStatus:"failed",pid:null,error:e.signal?.aborted?"Interrupted":a instanceof Error?a.message:String(a)}),e.signal?.aborted?a:E(a,r.id)}finally{F(r.id)}}function x(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} of ${t.id} no longer exists.`);return Z(e,t,i)}function Z(e,t,i){return{operationId:t.id,state:t.action==="put"?"ready":"removal_pending",resource:i,urls:M(i,e.apiUrl)}}function W(e,t,i,r={}){J(e.db,()=>{B(e.db,i),b(e.db,t.id,{executionStatus:"completed",phase:"done",pid:null,error:null,checkpoint:r})})}function C(e){if(e<g.MIN_UPLOAD_SIZE||e>g.MAX_UPLOAD_SIZE)throw I(`Content must be between ${g.MIN_UPLOAD_SIZE} and ${g.MAX_UPLOAD_SIZE} bytes; got ${e}.`,"path")}function P(e){return e==="folder"?K:G}async function ee(e,t){let i=j(e,{signal:t});return(await L(i)).toString()}function u(e,t,i,r){return b(e.db,t.id,{checkpoint:i,...r?{phase:r}:{}})}async function te(e,t){let{input:i}=t,r=i.kind??"file",a=i.name??"upload",d=e.signal;if(!i.sourcePath)throw new Error(`Operation ${t.id} has no source.`);let s=i.sourcePath;if(r==="folder"&&(s=X(e.stagingDir(t.id),"folder.car"),!await k(s).catch(()=>{}))){if(t.checkpoint.pieceCid)throw new m({code:p.stagingMissing,message:`The staged CAR of ${t.id} is missing, so it cannot be resumed.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put of the same directory"}]});t=u(e,t,{},"packing"),e.progress?.({phase:"packing",message:`Packing ${i.sourcePath}`});let D=await w(i.sourcePath,s);t=u(e,t,{rootCid:D.rootCid.toString(),size:D.size})}d?.throwIfAborted();let c=(await k(s)).size;C(c),e.progress?.({phase:"hashing",message:"Computing PieceCID"});let o=await ee(s,d);if(t.checkpoint.pieceCid&&t.checkpoint.pieceCid!==o)throw new m({code:p.sourceChanged,message:`${s} changed since operation ${t.id} started.`,next:[{by:"agent",command:`filecoin put ${i.sourcePath}`,description:"Start a new put with the current content"}]});t=u(e,t,{pieceCid:o,size:c},"storing");let n=ne(t.checkpoint);if(!n){e.progress?.({phase:"placing",message:"Selecting a storage provider"}),n=await e.backend.selectPlacement({metadata:P(r),providerId:i.providerId?BigInt(i.providerId):void 0});let h=await e.backend.quote({size:c,placement:n});if(!h.ready)throw re(h);t=u(e,t,{providerId:n.providerId.toString(),serviceURL:n.serviceURL,payee:n.payee,...n.dataSetId==null?{}:{dataSetId:n.dataSetId.toString(),clientDataSetId:n.clientDataSetId?.toString()}})}t.checkpoint.commit||t.checkpoint.stored||(await e.backend.hasPiece({serviceURL:n.serviceURL,pieceCid:o})||(e.progress?.({phase:"uploading",message:`Uploading ${c} bytes to provider ${n.providerId}`}),await e.backend.upload({serviceURL:n.serviceURL,path:s,size:c,pieceCid:o})),t=u(e,t,{stored:!0}));let R=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid,providerId:n.providerId.toString()}),U=()=>e.progress?.({phase:"link",message:R.browser,data:{pieceCid:o,urls:R}});r==="file"&&U();let f=await ie(e,t,n,{pieceCid:o,name:a},r==="folder"?U:void 0),O=y({apiUrl:e.apiUrl,chainId:t.chainId,pieceCid:o,rootCid:t.checkpoint.rootCid}),A={ref:t.resourceRef,kind:r,name:a,chainId:t.chainId,payer:t.payer,pieceCid:o,...t.checkpoint.rootCid?{rootCid:t.checkpoint.rootCid}:{},size:c,copies:[{providerId:n.providerId.toString(),dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString(),serviceURL:n.serviceURL}],url:O.browser,status:"active",createdAt:new Date().toISOString()};return W(e,t,A,{dataSetId:f.dataSetId.toString(),pieceId:f.pieceId.toString()}),r==="folder"&&await q(e.stagingDir(t.id),{recursive:!0,force:!0}).catch(()=>{}),{operationId:t.id,state:"ready",resource:A,urls:O}}async function ie(e,t,i,r,a){let d={name:r.name.slice(0,Y),...t.checkpoint.rootCid?{ipfsRootCID:t.checkpoint.rootCid}:{}},s=t.checkpoint.commit;if(s){let n=await e.backend.findCommit({nonce:BigInt(s.nonce)});if(n)return n}t=u(e,t,{},"committing");let c=s;if(c||(e.progress?.({phase:"committing",message:"Signing the commit"}),c=await e.backend.signCommit({placement:i,pieceCid:r.pieceCid,metadata:P(t.input.kind??"file"),pieceMetadata:d}),t=u(e,t,{commit:c})),!t.checkpoint.statusUrl){e.progress?.({phase:"committing",message:c.created?"Creating data set and adding piece":"Adding piece"});let n=await e.backend.submitCommit({placement:i,pieceCid:r.pieceCid,commit:c,pieceMetadata:d});t=u(e,t,{statusUrl:n.statusUrl,transactionHash:n.transactionHash})}a?.();let{transactionHash:o}=t.checkpoint;e.progress?.({phase:"committing",message:o?`Waiting for confirmation of transaction ${o}`:"Waiting for on-chain confirmation",...o?{data:{transactionHash:o}}:{}});try{return await e.backend.waitForCommit({statusUrl:t.checkpoint.statusUrl,created:c.created})}catch(n){throw $(n)&&n.code===p.commitRejected&&u(e,t,{statusUrl:void 0,transactionHash:void 0}),n}}function re(e){return new m({code:p.insufficientFunds,message:e.needsApproval?"The payer must deposit USDFC and approve Warm Storage before uploading.":"The payer must deposit more USDFC before uploading.",details:{fundingUrl:e.fundingUrl,depositNeeded:e.depositNeeded.toString(),needsApproval:e.needsApproval},next:[{by:"user",description:`Fund the account at ${e.fundingUrl}`}]})}function ne(e){if(e.providerId&&e.serviceURL&&e.payee)return{providerId:BigInt(e.providerId),serviceURL:e.serviceURL,payee:e.payee,...e.dataSetId&&e.clientDataSetId?{dataSetId:BigInt(e.dataSetId),clientDataSetId:BigInt(e.clientDataSetId)}:{}}}async function we(e,t){let i=v(e.db,t,e);if(!i)throw l(`No managed resource ${t} for this account.`,{by:"agent",command:"filecoin ls",description:"List managed resources"});if(i.status!=="active")throw I(`${t} is already pending removal.`,"ref");let[r]=i.copies;if(!r)throw new Error(`Resource ${t} has no stored copies.`);let a=S(e.db,{action:"delete",resourceRef:t,chainId:e.chainId,payer:e.payer,input:{},checkpoint:{providerId:r.providerId,serviceURL:r.serviceURL,dataSetId:r.dataSetId,pieceId:r.pieceId}});return await N(e,a.id)}async function ae(e,t){let i=v(e.db,t.resourceRef);if(!i)throw l(`Resource ${t.resourceRef} no longer exists.`);let{serviceURL:r,dataSetId:a,pieceId:d}=t.checkpoint;if(!(r&&a&&d))throw new Error(`Operation ${t.id} is missing its removal target.`);if(!t.checkpoint.transactionHash){t=u(e,t,{},"removing"),e.progress?.({phase:"removing",message:`Scheduling removal of piece ${d}`});let{transactionHash:n}=await e.backend.schedulePieceRemoval({serviceURL:r,dataSetId:BigInt(a),pieceId:BigInt(d)});t=u(e,t,{transactionHash:n})}let s=t.checkpoint.transactionHash;if(e.progress?.({phase:"removing",message:`Waiting for confirmation of removal transaction ${s}`,data:{transactionHash:s}}),(await e.backend.waitForTransaction(s)).status!=="success")throw u(e,t,{transactionHash:void 0}),new m({code:p.removalReverted,message:`Removal transaction ${s} reverted; the piece is still stored.`});let o={...i,status:"removal_pending"};return W(e,t,o),Z(e,t,o)}export{ve as a,Se as b,N as c,x as d,we as e};
3
+ //# sourceMappingURL=chunk-4WNPDK5J.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{D as l,F as f,a as e,b as i,c as n,e as r,f as p,g as m,i as t,k as o,u as a,v as d}from"./chunk-JUFFOBKU.js";import{d as c}from"./chunk-3TJUKWFC.js";var z=c({name:"login",description:"Authorize a session key in the filecoin-app dashboard",examples:["filecoin login","filecoin login --scopes createDataSet --scopes addPieces","filecoin login --check",'filecoin login --name "filecoin on laptop" --days 7',"filecoin login --network mainnet --fresh"],input:m({network:a.network,sessionKey:a.sessionKey,scopes:r(t(l)).min(1).optional().describe("Scopes to request (default: the saved key's, else createDataSet, addPieces, schedulePieceRemovals)"),name:e().trim().min(1).max(64).optional().describe(`Key name the owner sees, recorded on chain (default: the saved key's, else ${f})`),days:i().int().min(1).max(365).optional().describe("Days until the approval expires (default: the saved key's, else 30)"),wait:n().optional().describe("Wait for approval (default: only when a human is present)"),open:n().default(!0).describe("Open the approval page in a browser; never for agents"),fresh:n().default(!1).describe("Generate a new key, replacing a pending or valid saved key"),check:n().default(!1).describe("Only confirm the saved key; never generate a new one"),timeout:i().int().min(1).default(600).describe("Seconds to wait for approval")}),env:{network:d.network,sessionKey:d.sessionKey},secrets:["sessionKey"],output:p({network:e(),address:e().describe("Session key address"),rootAddress:e().describe("Wallet that authorized it"),scopes:r(t(l)).describe("Granted scopes"),expiresAt:e().optional().describe("Earliest scope expiry")}),errors:[o.authRequired,o.loginPending,o.permissionDenied,o.sessionConflict,o.sessionExpired],idempotent:!0,human:s=>`Logged in on ${s.network} as ${s.rootAddress} with ${s.scopes.join(", ")}${s.expiresAt?` until ${s.expiresAt}`:""}.`,handler:()=>import("./login-NNTYQ37I.js")});export{z as a};
3
- //# sourceMappingURL=chunk-BZITZ3BI.js.map
2
+ import{D as l,F as f,a as e,b as i,c as n,e as r,f as p,g as m,i as t,k as o,u as a,v as d}from"./chunk-JUFFOBKU.js";import{d as c}from"./chunk-3TJUKWFC.js";var z=c({name:"login",description:"Authorize a session key in the filecoin-app dashboard",examples:["filecoin login","filecoin login --scopes createDataSet --scopes addPieces","filecoin login --check",'filecoin login --name "filecoin on laptop" --days 7',"filecoin login --network mainnet --fresh"],input:m({network:a.network,sessionKey:a.sessionKey,scopes:r(t(l)).min(1).optional().describe("Scopes to request (default: the saved key's, else createDataSet, addPieces, schedulePieceRemovals)"),name:e().trim().min(1).max(64).optional().describe(`Key name the owner sees, recorded on chain (default: the saved key's, else ${f})`),days:i().int().min(1).max(365).optional().describe("Days until the approval expires (default: the saved key's, else 30)"),wait:n().optional().describe("Wait for approval (default: only when a human is present)"),open:n().default(!0).describe("Open the approval page in a browser; never for agents"),fresh:n().default(!1).describe("Generate a new key, replacing a pending or valid saved key"),check:n().default(!1).describe("Only confirm the saved key; never generate a new one"),timeout:i().int().min(1).default(600).describe("Seconds to wait for approval")}),env:{network:d.network,sessionKey:d.sessionKey},secrets:["sessionKey"],output:p({network:e(),address:e().describe("Session key address"),rootAddress:e().describe("Wallet that authorized it"),scopes:r(t(l)).describe("Granted scopes"),expiresAt:e().optional().describe("Earliest scope expiry")}),errors:[o.authRequired,o.loginPending,o.permissionDenied,o.sessionConflict,o.sessionExpired],idempotent:!0,human:s=>`Logged in on ${s.network} as ${s.rootAddress} with ${s.scopes.join(", ")}${s.expiresAt?` until ${s.expiresAt}`:""}.`,handler:()=>import("./login-3SAES4JH.js")});export{z as a};
3
+ //# sourceMappingURL=chunk-AK3TY773.js.map
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
- import{a as e,c as t,f as r,g as s,u as i,v as m}from"./chunk-JUFFOBKU.js";import{d as n}from"./chunk-3TJUKWFC.js";var d=n({name:"logout",description:"Forget the local session key (revoke it on-chain in the console)",examples:["filecoin logout","filecoin logout --network mainnet"],input:s({network:i.network}),env:{network:m.network},output:r({network:e(),removed:t(),address:e().optional().describe("Forgotten session key address")}),idempotent:!0,human:o=>o.removed?`Forgot session key ${o.address} on ${o.network}.`:`No session key on ${o.network}.`,handler:()=>import("./logout-3RWZFH2E.js")});export{d as a};
3
- //# sourceMappingURL=chunk-Z6O5SHUU.js.map
2
+ import{a as e,c as t,f as r,g as s,u as i,v as m}from"./chunk-JUFFOBKU.js";import{d as n}from"./chunk-3TJUKWFC.js";var d=n({name:"logout",description:"Forget the local session key (revoke it on-chain in the console)",examples:["filecoin logout","filecoin logout --network mainnet"],input:s({network:i.network}),env:{network:m.network},output:r({network:e(),removed:t(),address:e().optional().describe("Forgotten session key address")}),idempotent:!0,human:o=>o.removed?`Forgot session key ${o.address} on ${o.network}.`:`No session key on ${o.network}.`,handler:()=>import("./logout-HFZTYLPK.js")});export{d as a};
3
+ //# sourceMappingURL=chunk-AX2TW2N4.js.map
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __createRequire } from 'node:module'; const require = __createRequire(import.meta.url);
2
2
  import{C as h,a as e,b as s,c as r,e as c,f as i,g as l,i as a,j as d,m as u,u as z,v as m,x as f,y as g}from"./chunk-JUFFOBKU.js";import{d as p}from"./chunk-3TJUKWFC.js";var b=i({kind:a(["file","folder"]),name:e(),size:s().int().describe("Bytes to store: the file, or the packed CAR"),files:s().int(),rootCid:e().optional(),network:e(),authorization:a(["ready","login_required","login_pending","scopes_missing"]).describe("Whether the session key can sign this put"),missingScopes:c(e()).optional(),provider:i({id:e(),serviceURL:e(),dataSetId:e().optional().describe("Existing data set to add to")}).optional(),cost:i({token:d("USDFC"),ready:r().describe("The payer can cover it now"),depositNeeded:e(),needsApproval:r(),ratePerMonth:e(),lockup:e(),fundingUrl:e().optional()}).optional(),checkedAt:e()}),k=p({name:"put",description:"Store a file (raw piece) or directory (UnixFS CAR) with one copy",examples:["filecoin put ./report.pdf","filecoin put ./site --name docs","filecoin publish ./site --dry-run"],input:l({path:e().describe("File or directory to store"),name:e().min(1).optional().describe("Display name (default: basename)"),provider:e().regex(/^\d+$/,"Expected a decimal provider ID").optional().describe("Storage provider ID (default: automatic)"),...z}),positionals:["path"],env:m,secrets:["sessionKey"],output:i({dryRun:r(),operationId:e().optional().describe("Set when dryRun is false"),state:d("ready").optional(),resource:f.optional(),urls:g.optional(),estimate:b.optional().describe("Set when dryRun is true")}),errors:u,dryRun:!0,human:o=>{if(o.estimate){let t=o.estimate,n=[`Would store ${t.kind} ${t.name}: ${h(t.size)}, ${t.files} file(s) on ${t.network}`,`authorization: ${t.authorization}`];return t.provider&&n.push(`provider: ${t.provider.id} (${t.provider.serviceURL})`),t.cost&&n.push(`cost: ${t.cost.ratePerMonth} USDFC/month, lockup ${t.cost.lockup} USDFC, ${t.cost.ready?"funded":`deposit ${t.cost.depositNeeded} USDFC first`}`),n.join(`
3
3
  `)}return`Stored ${o.resource?.name} (${o.resource?.ref})
4
- ${o.urls?.browser}`},handler:()=>import("./put-FXMGPSU6.js")});export{k as a};
5
- //# sourceMappingURL=chunk-CIVQHT3F.js.map
4
+ ${o.urls?.browser}`},handler:()=>import("./put-UKZN63HP.js")});export{k as a};
5
+ //# sourceMappingURL=chunk-DQD55GP5.js.map