@activepieces/piece-sftp 0.5.2 → 0.5.3
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/package.json +1 -1
- package/src/index.js +1 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -31,7 +31,7 @@ ${r}`}};var av=2**32,Im=(()=>{try{return new Function("return 2n ** 32n")()}catc
|
|
|
31
31
|
|
|
32
32
|
`).replace(/\s+(-----END [A-Z0-9 ]+ KEY-----)/,`
|
|
33
33
|
$1`);let _=g.match(/(-----BEGIN [A-Z0-9 ]+ KEY-----\n(?:Proc-Type:[^\n]+\n)?(?:DEK-Info:[^\n]+\n\n)?)/),E=g.match(/(\n-----END [A-Z0-9 ]+ KEY-----)/);if(_&&E){let b=_[1],I=E[1],H=g.replace(b,"").replace(I,"").replace(/\s+/g,"").match(/.{1,64}/g)||[];g=b+H.join(`
|
|
34
|
-
`)+I}}let h={host:r,port:n,username:s,privateKey:g,timeout:1e4};a&&(h.passphrase=a),l&&l.length>0&&(h.algorithms={serverHostKey:l}),await p.connect(h)}else a&&await p.connect({host:r,port:n,username:s,password:a,timeout:1e4});return p}else{let p=new dA.Client;return await p.access({host:r,port:n,user:s,password:a,secure:d==="ftps",secureOptions:{rejectUnauthorized:!(i??!1)}}),p}}c(Ft,"getClient");async function Zt(t,e){await Dt(e)==="sftp"?await t.end():t.close()}c(Zt,"endClient");var nr=zo.CustomAuth({props:{protocol:pt.StaticDropdown({displayName:"Protocol",description:"The protocol to use",required:!1,options:{options:[{value:"sftp",label:"SFTP"},{value:"ftp",label:"FTP"},{value:"ftps",label:"FTPS"}]}}),allow_unauthorized_certificates:pt.Checkbox({displayName:"Allow Unauthorized Certificates",description:"Allow connections to servers with self-signed certificates",defaultValue:!1,required:!1}),allow_anonymous_login:pt.Checkbox({displayName:"Allow Anonymous Login",description:"Allow anonymous login to FTP servers (only applicable for FTP/FTPS)",defaultValue:!1,required:!1}),host:pt.ShortText({displayName:"Host",description:"The host of the server",required:!0}),port:pt.Number({displayName:"Port",description:"The port of the server",required:!0,defaultValue:22}),username:pt.ShortText({displayName:"Username",description:"The username to authenticate with",required:!0}),password:zo.SecretText({displayName:"Password",description:"The password to authenticate with. Either this or private key is required. When using a private key, this field is used as the passphrase to decrypt the key.",required:!1}),privateKey:zo.SecretText({displayName:"Private Key",description:"The private key to authenticate with. Either this or password is required.",required:!1}),algorithm:pt.StaticMultiSelectDropdown({displayName:"Host Key Algorithm",description:"The host key algorithm to use for SFTP connection. Only needed if you want to override the default algorithms (e.g., to support ssh-dss).",required:!1,options:{options:[{value:"ssh-rsa",label:"ssh-rsa"},{value:"ssh-dss",label:"ssh-dss"},{value:"ecdsa-sha2-nistp256",label:"ecdsa-sha2-nistp256"},{value:"ecdsa-sha2-nistp384",label:"ecdsa-sha2-nistp384"},{value:"ecdsa-sha2-nistp521",label:"ecdsa-sha2-nistp521"},{value:"ssh-ed25519",label:"ssh-ed25519"},{value:"rsa-sha2-256",label:"rsa-sha2-256"},{value:"rsa-sha2-512",label:"rsa-sha2-512"}]}})},validate:c(async({auth:t})=>{let e=null,r=await Dt(t.protocol);try{if(!t.privateKey&&!t.password&&!t.allow_anonymous_login)return{valid:!1,error:"Either password or private key must be provided for non-anonymous authentication."};switch(r){case"sftp":{if(t.allow_anonymous_login)return{valid:!1,error:"Anonymous login is not supported for SFTP protocol."};e=await Ft(t);break}default:{e=await Ft(t);break}}return{valid:!0}}catch(n){return{valid:!1,error:n?.message}}finally{e&&await Zt(e,t.protocol)}},"validate"),required:!0});var hA=require("stream");var c1={0:{error:"OK",description:"Indicates successful completion of the operation."},1:{error:"EOF",description:"An attempt to read past the end-of-file was made; or, there are no more directory entries to return."},2:{error:"No such file",description:"A reference was made to a file which does not exist."},3:{error:"Permission denied",description:"The user does not have sufficient permissions to perform the operation."},4:{error:"Failure",description:"An error occurred, but no specific error code exists to describe the failure. This error message should always have meaningful text in the error message field."},5:{error:"Bad message",description:"A badly formatted packet or other SFTP protocol incompatibility was detected."},6:{error:"No connection",description:"There is no connection to the server. This error may be used locally, but must not be returned by a server."},7:{error:"Connection lost",description:"The connection to the server was lost. This error may be used locally, but must not be returned by a server."},8:{error:"Operation unsupported",description:"An attempted operation could not be completed by the server because the server does not support the operation."},9:{error:"Invalid handle",description:"The handle value was invalid."},10:{error:"No such path",description:"The file path does not exist or is invalid."},11:{error:"File already exists",description:"The file already exists."},12:{error:"Write protect",description:"The file is on read-only media, or the media is write protected."},13:{error:"No media",description:"The requested operation cannot be completed because there is no media available in the drive."},14:{error:"No space on file-system",description:"The requested operation cannot be completed because there is insufficient free space on the filesystem."},15:{error:"Quota exceeded",description:"The operation cannot be completed because it would exceed the user\u2019s storage quota."},16:{error:"Unknown principal",description:"A principal referenced by the request (either the owner, group, or who field of an ACL), was unknown."},17:{error:"Lock conflict",description:"The file could not be opened because it is locked by another process."},18:{error:"Directory not empty",description:"The directory is not empty."},19:{error:"Not a directory",description:"The specified file is not a directory."},20:{error:"Invalid filename",description:"The filename is not valid."},21:{error:"Link loop",description:"Too many symbolic links encountered or an SSH_FXF_NOFOLLOW encountered a symbolic link as the final component."},22:{error:"Cannot delete",description:"The file cannot be deleted. One possible reason is that the advisory read-only attribute-bit is set."},23:{error:"Invalid parameter",description:"One of the parameters was out of range or the parameters specified cannot be used together."},24:{error:"File is a directory",description:"The specified file was a directory in a context where a directory cannot be used."},25:{error:"Range lock conflict",description:"A read or write operation failed because another process\u2019s mandatory byte-range lock overlaps with the request."},26:{error:"Range lock refused",description:"A request for a byte range lock was refused."},27:{error:"Delete pending",description:"An operation was attempted on a file for which a delete operation is pending."},28:{error:"File corrupt",description:"The file is corrupt; a filesystem integrity check should be run."},29:{error:"Owner invalid",description:"The principal specified cannot be assigned as an owner of a file."},30:{error:"Group invalid",description:"The principal specified cannot be assigned as the primary group of a file."},31:{error:"No matching byte range lock",description:"The requested operation could not be completed because the specified byte range lock has not been granted."}};function Bt(t){return c1[t]??{error:"Unknown error code"}}c(Bt,"getSftpError");async function u1(t,e,r){if(!await t.exists(e)){let i=e.substring(0,e.lastIndexOf("/"));await t.mkdir(i,!0)}await t.put(Buffer.from(r),e)}c(u1,"createFileWithSFTP");async function l1(t,e,r){let n=e.substring(0,e.lastIndexOf("/"));await t.ensureDir(n);let i=Buffer.from(r);await t.uploadFrom(hA.Readable.from(i),e)}c(l1,"createFileWithFTP");var gA=hr({audience:"both",auth:nr,name:"create_file",displayName:"Create File from Text",description:"Create a new file in the given path",props:{fileName:pt.ShortText({displayName:"File Path",required:!0}),fileContent:pt.LongText({displayName:"File content",required:!0})},async run(t){let e=t.propsValue.fileName,r=t.propsValue.fileContent,n=await Dt(t.auth.props.protocol),i=await Ft(t.auth.props);try{switch(n){case"ftps":case"ftp":await l1(i,e,r);break;default:case"sftp":await u1(i,e,r);break}return{status:"success"}}catch(o){return o instanceof pA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(i,t.auth.props.protocol)}}});var mA=Ar(rn());var _A=require("stream");async function f1(t,e,r){let n=e.substring(0,e.lastIndexOf("/"));await t.ensureDir(n),await t.uploadFrom(_A.Readable.from(r.data),e)}c(f1,"uploadFileToFTP");async function d1(t,e,r){if(!await t.exists(e)){let i=e.substring(0,e.lastIndexOf("/"));await t.mkdir(i,!0)}await t.put(r.data,e),await t.end()}c(d1,"uploadFileToSFTP");var yA=hr({audience:"both",auth:nr,name:"upload_file",displayName:"Upload File",description:"Upload a file to the given path.",props:{fileName:pt.ShortText({displayName:"File Path",required:!0,description:"The path on the sftp server to store the file. e.g. `./myfolder/test.mp3`"}),fileContent:pt.File({displayName:"File content",required:!0})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.fileName,n=t.propsValue.fileContent,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await f1(e,r,n);break;default:case"sftp":await d1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof mA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var AA=Ar(rn()),EA=require("stream");async function p1(t,e){let r=[],n=new EA.Writable({write(i,o,s){r.push(i),s()}});return await t.downloadTo(n,e),Buffer.concat(r)}c(p1,"readFTP");async function h1(t,e){let r=await t.get(e);return await t.end(),r}c(h1,"readSFTP");var bA=hr({audience:"both",auth:nr,name:"read_file_content",displayName:"Read File Content",description:"Read the content of a file.",props:{filePath:pt.ShortText({displayName:"File Path",required:!0})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.filePath,n=r.split("/").pop()??r,i=await Dt(t.auth.props.protocol);try{let o;switch(i){case"ftps":case"ftp":o=await p1(e,r);break;default:case"sftp":o=await h1(e,r);break}return{file:await t.files.write({fileName:n,data:o})}}catch(o){return o instanceof AA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var $s={async poll(t,{store:e,auth:r,propsValue:n,maxItemsToPoll:i,files:o,server:s}){switch(t.strategy){case 0:{let a=await e.get("lastPoll");if(gr(a))throw new Error("lastPoll doesn't exist in the store.");let u=await t.items({store:e,auth:r,propsValue:n,lastFetchEpochMS:a,server:s}),l=u.reduce((d,p)=>Math.max(d,p.epochMilliSeconds),a);return await e.put("lastPoll",l),u.filter(d=>d.epochMilliSeconds>a).map(d=>d.data)}case 1:{let a=await e.get("lastItem"),u=await t.items({store:e,auth:r,propsValue:n,lastItemId:a,files:o,server:s}),l=u.findIndex(g=>g.id===a),d=[];gr(a)||l==-1?d=u??[]:d=u?.slice(0,l)??[],gr(i)||(d=d.slice(-i));let p=d?.[0]?.id;return gr(p)||await e.put("lastItem",p),d.map(g=>g.data)}}},async onEnable(t,{store:e,auth:r,propsValue:n,server:i}){switch(t.strategy){case 0:{await e.put("lastPoll",Date.now());break}case 1:{let s=(await t.items({store:e,auth:r,propsValue:n,lastItemId:null,server:i}))?.[0]?.id;gr(s)?await e.delete("lastItem"):await e.put("lastItem",s);break}}},async onDisable(t,e){switch(t.strategy){case 0:case 1:return}},async test(t,{auth:e,propsValue:r,store:n,files:i,server:o}){let s=[];switch(t.strategy){case 0:{s=await t.items({store:n,auth:e,propsValue:r,lastFetchEpochMS:0,server:o});break}case 1:{s=await t.items({store:n,auth:e,propsValue:r,lastItemId:null,files:i,server:o});break}}return g1(s.map(a=>a.data))}};function g1(t){return t.length<=5?t:t.slice(0,5)}c(g1,"getFirstFiveOrAll");var Pc=Ar(xA());function IA(t,e){return e==="sftp"?t.modifyTime:(0,Pc.default)(t.modifiedAt).valueOf()}c(IA,"getModifyTime");var wc={strategy:0,items:c(async({auth:t,propsValue:e,lastFetchEpochMS:r})=>{let n=null;try{let i=await Dt(t.props.protocol);n=await Ft(t.props);let s=(await n.list(e.path)).filter(u=>{let l=IA(u,i);return(0,Pc.default)(l).valueOf()>r});return(e.ignoreHiddenFiles?s.filter(u=>!u.name.startsWith(".")):s).map(u=>{let l=IA(u,i);return{data:{...u,path:`${e.path}/${u.name}`},epochMilliSeconds:(0,Pc.default)(l).valueOf()}})}catch{return[]}finally{n&&await Zt(n,t.props.protocol)}},"items")},vA=_h({auth:nr,name:"new_file",displayName:"New File",description:"Trigger when a new file is created or modified.",props:{path:pt.ShortText({displayName:"Path",description:"The path to watch for new files",required:!0,defaultValue:"./"}),ignoreHiddenFiles:pt.Checkbox({displayName:"Ignore hidden files",description:"Ignore hidden files",required:!1,defaultValue:!1})},type:"POLLING",onEnable:c(async t=>{await $s.onEnable(wc,t)},"onEnable"),onDisable:c(async t=>{await $s.onDisable(wc,t)},"onDisable"),run:c(async t=>await $s.poll(wc,t),"run"),test:c(async t=>await $s.test(wc,t),"test"),sampleData:null});var SA=Ar(rn());async function m1(t,e,r){r?await t.removeDir(e):await t.removeEmptyDir(e)}c(m1,"deleteFolderFTP");async function _1(t,e,r){await t.rmdir(e,r)}c(_1,"deleteFolderSFTP");var wA=hr({audience:"both",auth:nr,name:"deleteFolder",displayName:"Delete Folder",description:"Deletes an existing folder at given path.",props:{folderPath:pt.ShortText({displayName:"Folder Path",required:!0,description:"The path of the folder to delete e.g. `./myfolder`"}),recursive:pt.Checkbox({displayName:"Recursive",defaultValue:!1,required:!1,description:"Enable this option to delete the folder and all its contents, including subfolders and files."})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.folderPath,n=t.propsValue.recursive??!1,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await m1(e,r,n);break;default:case"sftp":await _1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof SA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var PA=Ar(rn());async function y1(t,e){await t.remove(e)}c(y1,"deleteFileFromFTP");async function A1(t,e){await t.delete(e)}c(A1,"deleteFileFromSFTP");var TA=hr({audience:"both",auth:nr,name:"deleteFile",displayName:"Delete file",description:"Deletes a file at given path.",props:{filePath:pt.ShortText({displayName:"File Path",required:!0,description:"The path of the file to delete e.g. `./myfolder/test.mp3`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.filePath,n=await Dt(t.auth.props.protocol);try{switch(n){case"ftps":case"ftp":await y1(e,r);break;default:case"sftp":await A1(e,r);break}return{status:"success"}}catch(i){return i instanceof PA.FTPError?(console.error(Bt(i.code)),{status:"error",error:Bt(i.code)}):{status:"error",error:i}}finally{await Zt(e,t.auth.props.protocol)}}});var kA=Ar(rn());async function E1(t,e){let r=await t.list(e);return await t.end(),r}c(E1,"listSFTP");async function b1(t,e){return(await t.list(e)).map(n=>({type:n.type===1?"d":"-",name:n.name,size:n.size,modifyTime:n.modifiedAt,accessTime:n.modifiedAt,rights:{user:n.permissions||"",group:"",other:""},owner:"",group:""}))}c(b1,"listFTP");var CA=hr({audience:"both",auth:nr,name:"listFolderContents",displayName:"List Folder Contents",description:"Lists the contents of a given folder.",props:{directoryPath:pt.ShortText({displayName:"Directory Path",required:!0,description:"The path of the folder to list e.g. `./myfolder`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.directoryPath,n=await Dt(t.auth.props.protocol);try{let i;switch(n){case"ftps":case"ftp":i=await b1(e,r);break;default:case"sftp":i=await E1(e,r);break}return{status:"success",contents:i}}catch(i){return i instanceof kA.FTPError?(console.error(Bt(i.code)),{status:"error",content:null,error:Bt(i.code)}):{status:"error",content:null,error:i}}finally{await Zt(e,t.auth.props.protocol)}}});var RA=Ar(rn());var NA=hr({audience:"both",auth:nr,name:"createFolder",displayName:"Create Folder",description:"Creates a folder at given path.",props:{folderPath:pt.ShortText({displayName:"Folder Path",required:!0,description:"The new folder path e.g. `./myfolder`. For FTP/FTPS, it will create nested folders if necessary."}),recursive:pt.Checkbox({displayName:"Recursive",defaultValue:!1,required:!1,description:"For SFTP only: Create parent directories if they do not exist"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.folderPath,n=t.propsValue.recursive??!1,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await e.ensureDir(r);break;default:case"sftp":await e.mkdir(r,n);break}return{status:"success"}}catch(o){return o instanceof RA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var OA=Ar(rn());async function x1(t,e,r){await t.rename(e,r)}c(x1,"renameFTP");async function I1(t,e,r){await t.rename(e,r),await t.end()}c(I1,"renameSFTP");var $A=hr({audience:"both",auth:nr,name:"renameFileOrFolder",displayName:"Rename File or Folder",description:"Renames a file or folder at given path.",props:{information:pt.MarkDown({value:"Depending on the server you can also use this to move a file to another directory, as long as the directory exists.",variant:"INFO"}),oldPath:pt.ShortText({displayName:"Old Path",required:!0,description:"The path of the file or folder to rename e.g. `./myfolder/test.mp3`"}),newPath:pt.ShortText({displayName:"New Path",required:!0,description:"The new path of the file or folder e.g. `./myfolder/new-name.mp3`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.oldPath,n=t.propsValue.newPath,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await x1(e,r,n);break;default:case"sftp":await I1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof OA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var v1=Ah({displayName:"FTP/SFTP",description:"Connect to FTP, FTPS or SFTP servers",minimumSupportedRelease:"0.30.0",logoUrl:"https://cdn.activepieces.com/pieces/new-core/sftp.svg",categories:["CORE","DEVELOPER_TOOLS"],authors:["Abdallah-Alwarawreh","kishanprmr","AbdulTheActivePiecer","khaledmashaly","abuaboud","prasanna2000-max"],auth:nr,actions:[gA,yA,bA,TA,NA,wA,CA,$A],triggers:[vA]});0&&(module.exports={endClient,ftpSftp,getClient,getProtocolBackwardCompatibility});
|
|
34
|
+
`)+I}}let h={host:r,port:n,username:s,privateKey:g,timeout:1e4};a&&(h.passphrase=a),l&&l.length>0&&(h.algorithms={serverHostKey:l}),await p.connect(h)}else a&&await p.connect({host:r,port:n,username:s,password:a,timeout:1e4});return p}else{let p=new dA.Client;return await p.access({host:r,port:n,user:s,password:a,secure:d==="ftps",secureOptions:{rejectUnauthorized:!(i??!1)}}),p}}c(Ft,"getClient");async function Zt(t,e){await Dt(e)==="sftp"?await t.end():t.close()}c(Zt,"endClient");var nr=zo.CustomAuth({props:{protocol:pt.StaticDropdown({displayName:"Protocol",description:"The protocol to use",required:!1,options:{options:[{value:"sftp",label:"SFTP"},{value:"ftp",label:"FTP"},{value:"ftps",label:"FTPS"}]}}),allow_unauthorized_certificates:pt.Checkbox({displayName:"Allow Unauthorized Certificates",description:"Allow connections to servers with self-signed certificates",defaultValue:!1,required:!1}),allow_anonymous_login:pt.Checkbox({displayName:"Allow Anonymous Login",description:"Allow anonymous login to FTP servers (only applicable for FTP/FTPS)",defaultValue:!1,required:!1}),host:pt.ShortText({displayName:"Host",description:"The host of the server",required:!0}),port:pt.Number({displayName:"Port",description:"The port of the server",required:!0,defaultValue:22}),username:pt.ShortText({displayName:"Username",description:"The username to authenticate with",required:!0}),password:zo.SecretText({displayName:"Password",description:"The password to authenticate with. Either this or private key is required. When using a private key, this field is used as the passphrase to decrypt the key.",required:!1}),privateKey:zo.SecretText({displayName:"Private Key",description:"The private key to authenticate with. Either this or password is required.",required:!1}),algorithm:pt.StaticMultiSelectDropdown({displayName:"Host Key Algorithm",description:"The host key algorithm to use for SFTP connection. Only needed if you want to override the default algorithms (e.g., to support ssh-dss).",required:!1,options:{options:[{value:"ssh-rsa",label:"ssh-rsa"},{value:"ssh-dss",label:"ssh-dss"},{value:"ecdsa-sha2-nistp256",label:"ecdsa-sha2-nistp256"},{value:"ecdsa-sha2-nistp384",label:"ecdsa-sha2-nistp384"},{value:"ecdsa-sha2-nistp521",label:"ecdsa-sha2-nistp521"},{value:"ssh-ed25519",label:"ssh-ed25519"},{value:"rsa-sha2-256",label:"rsa-sha2-256"},{value:"rsa-sha2-512",label:"rsa-sha2-512"}]}})},validate:c(async({auth:t})=>{let e=null,r=await Dt(t.protocol);try{if(!t.privateKey&&!t.password&&!t.allow_anonymous_login)return{valid:!1,error:"Either password or private key must be provided for non-anonymous authentication."};switch(r){case"sftp":{if(t.allow_anonymous_login)return{valid:!1,error:"Anonymous login is not supported for SFTP protocol."};e=await Ft(t);break}default:{e=await Ft(t);break}}return{valid:!0}}catch(n){return{valid:!1,error:n?.message}}finally{e&&await Zt(e,t.protocol)}},"validate"),required:!0});var hA=require("stream");var c1={0:{error:"OK",description:"Indicates successful completion of the operation."},1:{error:"EOF",description:"An attempt to read past the end-of-file was made; or, there are no more directory entries to return."},2:{error:"No such file",description:"A reference was made to a file which does not exist."},3:{error:"Permission denied",description:"The user does not have sufficient permissions to perform the operation."},4:{error:"Failure",description:"An error occurred, but no specific error code exists to describe the failure. This error message should always have meaningful text in the error message field."},5:{error:"Bad message",description:"A badly formatted packet or other SFTP protocol incompatibility was detected."},6:{error:"No connection",description:"There is no connection to the server. This error may be used locally, but must not be returned by a server."},7:{error:"Connection lost",description:"The connection to the server was lost. This error may be used locally, but must not be returned by a server."},8:{error:"Operation unsupported",description:"An attempted operation could not be completed by the server because the server does not support the operation."},9:{error:"Invalid handle",description:"The handle value was invalid."},10:{error:"No such path",description:"The file path does not exist or is invalid."},11:{error:"File already exists",description:"The file already exists."},12:{error:"Write protect",description:"The file is on read-only media, or the media is write protected."},13:{error:"No media",description:"The requested operation cannot be completed because there is no media available in the drive."},14:{error:"No space on file-system",description:"The requested operation cannot be completed because there is insufficient free space on the filesystem."},15:{error:"Quota exceeded",description:"The operation cannot be completed because it would exceed the user\u2019s storage quota."},16:{error:"Unknown principal",description:"A principal referenced by the request (either the owner, group, or who field of an ACL), was unknown."},17:{error:"Lock conflict",description:"The file could not be opened because it is locked by another process."},18:{error:"Directory not empty",description:"The directory is not empty."},19:{error:"Not a directory",description:"The specified file is not a directory."},20:{error:"Invalid filename",description:"The filename is not valid."},21:{error:"Link loop",description:"Too many symbolic links encountered or an SSH_FXF_NOFOLLOW encountered a symbolic link as the final component."},22:{error:"Cannot delete",description:"The file cannot be deleted. One possible reason is that the advisory read-only attribute-bit is set."},23:{error:"Invalid parameter",description:"One of the parameters was out of range or the parameters specified cannot be used together."},24:{error:"File is a directory",description:"The specified file was a directory in a context where a directory cannot be used."},25:{error:"Range lock conflict",description:"A read or write operation failed because another process\u2019s mandatory byte-range lock overlaps with the request."},26:{error:"Range lock refused",description:"A request for a byte range lock was refused."},27:{error:"Delete pending",description:"An operation was attempted on a file for which a delete operation is pending."},28:{error:"File corrupt",description:"The file is corrupt; a filesystem integrity check should be run."},29:{error:"Owner invalid",description:"The principal specified cannot be assigned as an owner of a file."},30:{error:"Group invalid",description:"The principal specified cannot be assigned as the primary group of a file."},31:{error:"No matching byte range lock",description:"The requested operation could not be completed because the specified byte range lock has not been granted."}};function Bt(t){return c1[t]??{error:"Unknown error code"}}c(Bt,"getSftpError");async function u1(t,e,r){if(!await t.exists(e)){let i=e.substring(0,e.lastIndexOf("/"));await t.mkdir(i,!0)}await t.put(Buffer.from(r),e)}c(u1,"createFileWithSFTP");async function l1(t,e,r){let n=e.substring(0,e.lastIndexOf("/"));await t.ensureDir(n);let i=Buffer.from(r);await t.uploadFrom(hA.Readable.from(i),e)}c(l1,"createFileWithFTP");var gA=hr({audience:"human",auth:nr,name:"create_file",displayName:"Create File from Text",description:"Create a new file in the given path",props:{fileName:pt.ShortText({displayName:"File Path",required:!0}),fileContent:pt.LongText({displayName:"File content",required:!0})},async run(t){let e=t.propsValue.fileName,r=t.propsValue.fileContent,n=await Dt(t.auth.props.protocol),i=await Ft(t.auth.props);try{switch(n){case"ftps":case"ftp":await l1(i,e,r);break;default:case"sftp":await u1(i,e,r);break}return{status:"success"}}catch(o){return o instanceof pA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(i,t.auth.props.protocol)}}});var mA=Ar(rn());var _A=require("stream");async function f1(t,e,r){let n=e.substring(0,e.lastIndexOf("/"));await t.ensureDir(n),await t.uploadFrom(_A.Readable.from(r.data),e)}c(f1,"uploadFileToFTP");async function d1(t,e,r){if(!await t.exists(e)){let i=e.substring(0,e.lastIndexOf("/"));await t.mkdir(i,!0)}await t.put(r.data,e),await t.end()}c(d1,"uploadFileToSFTP");var yA=hr({audience:"human",auth:nr,name:"upload_file",displayName:"Upload File",description:"Upload a file to the given path.",props:{fileName:pt.ShortText({displayName:"File Path",required:!0,description:"The path on the sftp server to store the file. e.g. `./myfolder/test.mp3`"}),fileContent:pt.File({displayName:"File content",required:!0})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.fileName,n=t.propsValue.fileContent,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await f1(e,r,n);break;default:case"sftp":await d1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof mA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var AA=Ar(rn()),EA=require("stream");async function p1(t,e){let r=[],n=new EA.Writable({write(i,o,s){r.push(i),s()}});return await t.downloadTo(n,e),Buffer.concat(r)}c(p1,"readFTP");async function h1(t,e){let r=await t.get(e);return await t.end(),r}c(h1,"readSFTP");var bA=hr({audience:"human",auth:nr,name:"read_file_content",displayName:"Read File Content",description:"Read the content of a file.",props:{filePath:pt.ShortText({displayName:"File Path",required:!0})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.filePath,n=r.split("/").pop()??r,i=await Dt(t.auth.props.protocol);try{let o;switch(i){case"ftps":case"ftp":o=await p1(e,r);break;default:case"sftp":o=await h1(e,r);break}return{file:await t.files.write({fileName:n,data:o})}}catch(o){return o instanceof AA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var $s={async poll(t,{store:e,auth:r,propsValue:n,maxItemsToPoll:i,files:o,server:s}){switch(t.strategy){case 0:{let a=await e.get("lastPoll");if(gr(a))throw new Error("lastPoll doesn't exist in the store.");let u=await t.items({store:e,auth:r,propsValue:n,lastFetchEpochMS:a,server:s}),l=u.reduce((d,p)=>Math.max(d,p.epochMilliSeconds),a);return await e.put("lastPoll",l),u.filter(d=>d.epochMilliSeconds>a).map(d=>d.data)}case 1:{let a=await e.get("lastItem"),u=await t.items({store:e,auth:r,propsValue:n,lastItemId:a,files:o,server:s}),l=u.findIndex(g=>g.id===a),d=[];gr(a)||l==-1?d=u??[]:d=u?.slice(0,l)??[],gr(i)||(d=d.slice(-i));let p=d?.[0]?.id;return gr(p)||await e.put("lastItem",p),d.map(g=>g.data)}}},async onEnable(t,{store:e,auth:r,propsValue:n,server:i}){switch(t.strategy){case 0:{await e.put("lastPoll",Date.now());break}case 1:{let s=(await t.items({store:e,auth:r,propsValue:n,lastItemId:null,server:i}))?.[0]?.id;gr(s)?await e.delete("lastItem"):await e.put("lastItem",s);break}}},async onDisable(t,e){switch(t.strategy){case 0:case 1:return}},async test(t,{auth:e,propsValue:r,store:n,files:i,server:o}){let s=[];switch(t.strategy){case 0:{s=await t.items({store:n,auth:e,propsValue:r,lastFetchEpochMS:0,server:o});break}case 1:{s=await t.items({store:n,auth:e,propsValue:r,lastItemId:null,files:i,server:o});break}}return g1(s.map(a=>a.data))}};function g1(t){return t.length<=5?t:t.slice(0,5)}c(g1,"getFirstFiveOrAll");var Pc=Ar(xA());function IA(t,e){return e==="sftp"?t.modifyTime:(0,Pc.default)(t.modifiedAt).valueOf()}c(IA,"getModifyTime");var wc={strategy:0,items:c(async({auth:t,propsValue:e,lastFetchEpochMS:r})=>{let n=null;try{let i=await Dt(t.props.protocol);n=await Ft(t.props);let s=(await n.list(e.path)).filter(u=>{let l=IA(u,i);return(0,Pc.default)(l).valueOf()>r});return(e.ignoreHiddenFiles?s.filter(u=>!u.name.startsWith(".")):s).map(u=>{let l=IA(u,i);return{data:{...u,path:`${e.path}/${u.name}`},epochMilliSeconds:(0,Pc.default)(l).valueOf()}})}catch{return[]}finally{n&&await Zt(n,t.props.protocol)}},"items")},vA=_h({auth:nr,name:"new_file",displayName:"New File",description:"Trigger when a new file is created or modified.",props:{path:pt.ShortText({displayName:"Path",description:"The path to watch for new files",required:!0,defaultValue:"./"}),ignoreHiddenFiles:pt.Checkbox({displayName:"Ignore hidden files",description:"Ignore hidden files",required:!1,defaultValue:!1})},type:"POLLING",onEnable:c(async t=>{await $s.onEnable(wc,t)},"onEnable"),onDisable:c(async t=>{await $s.onDisable(wc,t)},"onDisable"),run:c(async t=>await $s.poll(wc,t),"run"),test:c(async t=>await $s.test(wc,t),"test"),sampleData:null});var SA=Ar(rn());async function m1(t,e,r){r?await t.removeDir(e):await t.removeEmptyDir(e)}c(m1,"deleteFolderFTP");async function _1(t,e,r){await t.rmdir(e,r)}c(_1,"deleteFolderSFTP");var wA=hr({audience:"human",auth:nr,name:"deleteFolder",displayName:"Delete Folder",description:"Deletes an existing folder at given path.",props:{folderPath:pt.ShortText({displayName:"Folder Path",required:!0,description:"The path of the folder to delete e.g. `./myfolder`"}),recursive:pt.Checkbox({displayName:"Recursive",defaultValue:!1,required:!1,description:"Enable this option to delete the folder and all its contents, including subfolders and files."})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.folderPath,n=t.propsValue.recursive??!1,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await m1(e,r,n);break;default:case"sftp":await _1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof SA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var PA=Ar(rn());async function y1(t,e){await t.remove(e)}c(y1,"deleteFileFromFTP");async function A1(t,e){await t.delete(e)}c(A1,"deleteFileFromSFTP");var TA=hr({audience:"human",auth:nr,name:"deleteFile",displayName:"Delete file",description:"Deletes a file at given path.",props:{filePath:pt.ShortText({displayName:"File Path",required:!0,description:"The path of the file to delete e.g. `./myfolder/test.mp3`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.filePath,n=await Dt(t.auth.props.protocol);try{switch(n){case"ftps":case"ftp":await y1(e,r);break;default:case"sftp":await A1(e,r);break}return{status:"success"}}catch(i){return i instanceof PA.FTPError?(console.error(Bt(i.code)),{status:"error",error:Bt(i.code)}):{status:"error",error:i}}finally{await Zt(e,t.auth.props.protocol)}}});var kA=Ar(rn());async function E1(t,e){let r=await t.list(e);return await t.end(),r}c(E1,"listSFTP");async function b1(t,e){return(await t.list(e)).map(n=>({type:n.type===1?"d":"-",name:n.name,size:n.size,modifyTime:n.modifiedAt,accessTime:n.modifiedAt,rights:{user:n.permissions||"",group:"",other:""},owner:"",group:""}))}c(b1,"listFTP");var CA=hr({audience:"human",auth:nr,name:"listFolderContents",displayName:"List Folder Contents",description:"Lists the contents of a given folder.",props:{directoryPath:pt.ShortText({displayName:"Directory Path",required:!0,description:"The path of the folder to list e.g. `./myfolder`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.directoryPath,n=await Dt(t.auth.props.protocol);try{let i;switch(n){case"ftps":case"ftp":i=await b1(e,r);break;default:case"sftp":i=await E1(e,r);break}return{status:"success",contents:i}}catch(i){return i instanceof kA.FTPError?(console.error(Bt(i.code)),{status:"error",content:null,error:Bt(i.code)}):{status:"error",content:null,error:i}}finally{await Zt(e,t.auth.props.protocol)}}});var RA=Ar(rn());var NA=hr({audience:"human",auth:nr,name:"createFolder",displayName:"Create Folder",description:"Creates a folder at given path.",props:{folderPath:pt.ShortText({displayName:"Folder Path",required:!0,description:"The new folder path e.g. `./myfolder`. For FTP/FTPS, it will create nested folders if necessary."}),recursive:pt.Checkbox({displayName:"Recursive",defaultValue:!1,required:!1,description:"For SFTP only: Create parent directories if they do not exist"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.folderPath,n=t.propsValue.recursive??!1,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await e.ensureDir(r);break;default:case"sftp":await e.mkdir(r,n);break}return{status:"success"}}catch(o){return o instanceof RA.FTPError?(console.error(Bt(o.code)),{status:"error",error:Bt(o.code)}):{status:"error",error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var OA=Ar(rn());async function x1(t,e,r){await t.rename(e,r)}c(x1,"renameFTP");async function I1(t,e,r){await t.rename(e,r),await t.end()}c(I1,"renameSFTP");var $A=hr({audience:"human",auth:nr,name:"renameFileOrFolder",displayName:"Rename File or Folder",description:"Renames a file or folder at given path.",props:{information:pt.MarkDown({value:"Depending on the server you can also use this to move a file to another directory, as long as the directory exists.",variant:"INFO"}),oldPath:pt.ShortText({displayName:"Old Path",required:!0,description:"The path of the file or folder to rename e.g. `./myfolder/test.mp3`"}),newPath:pt.ShortText({displayName:"New Path",required:!0,description:"The new path of the file or folder e.g. `./myfolder/new-name.mp3`"})},async run(t){let e=await Ft(t.auth.props),r=t.propsValue.oldPath,n=t.propsValue.newPath,i=await Dt(t.auth.props.protocol);try{switch(i){case"ftps":case"ftp":await x1(e,r,n);break;default:case"sftp":await I1(e,r,n);break}return{status:"success"}}catch(o){return o instanceof OA.FTPError?(console.error(Bt(o.code)),{status:"error",content:null,error:Bt(o.code)}):{status:"error",content:null,error:o}}finally{await Zt(e,t.auth.props.protocol)}}});var v1=Ah({displayName:"FTP/SFTP",description:"Connect to FTP, FTPS or SFTP servers",minimumSupportedRelease:"0.30.0",logoUrl:"https://cdn.activepieces.com/pieces/new-core/sftp.svg",categories:["CORE","DEVELOPER_TOOLS"],authors:["Abdallah-Alwarawreh","kishanprmr","AbdulTheActivePiecer","khaledmashaly","abuaboud","prasanna2000-max"],auth:nr,actions:[gA,yA,bA,TA,NA,wA,CA,$A],triggers:[vA]});0&&(module.exports={endClient,ftpSftp,getClient,getProtocolBackwardCompatibility});
|
|
35
35
|
/*! Bundled license information:
|
|
36
36
|
|
|
37
37
|
safe-buffer/index.js:
|