UNPKG

@fightmegg/transferwise

Version:
2 lines (1 loc) 3.21 kB
import t from"node-fetch";import{encode as e}from"querystring";import s from"crypto";export default class{constructor({token:t,sandbox:e=!1}={}){if(!t)throw new Error("token is required");this.token=t,this.sandbox=e,this.url=e?"https://api.sandbox.transferwise.tech":"https://api.transferwise.com"}request({method:e="GET",path:s="",body:r,version:n}={}){const o="/"+(n||"v1"),a=this.url+o+s,i={method:e,json:!0,headers:{Authorization:"Bearer "+this.token,"Content-Type":"application/json","cache-control":"no-cache"}};return r&&(i.body=JSON.stringify(r)),"DELETE"===e?t(a,i):t(a,i).then(t=>t.json())}profiles(){return this.request({path:"/profiles"})}borderlessAccounts(t){return this.request({path:"/borderless-accounts?profileId="+t})}get recipientAccounts(){return{create:t=>this.request({method:"POST",body:t,path:"/accounts"}),get:t=>this.request({path:"/accounts/"+t}),delete:t=>this.request({method:"DELETE",path:"/accounts/"+t}),list:t=>this.request({path:"/accounts?"+e(t)})}}get quotes(){return{temporary:t=>this.request({path:"/quotes?"+e(t)}),create:t=>this.request({method:"POST",body:t,path:"/quotes"}),get:t=>this.request({path:"/quotes/"+t})}}get transfers(){return{create:t=>this.request({method:"POST",body:t,path:"/transfers"}),cancel:t=>this.request({method:"PUT",path:`/transfers/${t}/cancel`}),get:t=>this.request({path:"/transfers/"+t}),issues:t=>this.request({path:`/transfers/${t}/issues`}),fund:(t,e)=>this.request({method:"POST",version:"v3",body:{type:"BALANCE"},path:`/profiles/${t}/transfers/${e}/payments`}),deliveryEstimate:t=>this.request({path:"/delivery-estimates/"+t}),list:t=>this.request({path:"/transfers?"+e(t)})}}get simulation(){return{transfers:{processing:t=>this.request({path:`/simulation/transfers/${t}/processing`}),fundsConverted:t=>this.request({path:`/simulation/transfers/${t}/funds_converted`}),outgoingPaymentSent:t=>this.request({path:`/simulation/transfers/${t}/outgoing_payment_sent`}),bouncedBack:t=>this.request({path:`/simulation/transfers/${t}/bounced_back`}),fundsRefunded:t=>this.request({path:`/simulation/transfers/${t}/funds_refunded`})}}}get webhooks(){return{constructEvent:(t,e)=>((t=!1,e,r)=>{const n=s.createVerify("RSA-SHA1");n.update(e);return n.verify(t?"\n-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwpb91cEYuyJNQepZAVfP\nZIlPZfNUefH+n6w9SW3fykqKu938cR7WadQv87oF2VuT+fDt7kqeRziTmPSUhqPU\nys/V2Q1rlfJuXbE+Gga37t7zwd0egQ+KyOEHQOpcTwKmtZ81ieGHynAQzsn1We3j\nwt760MsCPJ7GMT141ByQM+yW1Bx+4SG3IGjXWyqOWrcXsxAvIXkpUD/jK/L958Cg\nnZEgz0BSEh0QxYLITnW1lLokSx/dTianWPFEhMC9BgijempgNXHNfcVirg1lPSyg\nz7KqoKUN0oHqWLr2U1A+7kqrl6O2nx3CKs1bj1hToT1+p4kcMoHXA7kA+VBLUpEs\nVwIDAQAB\n-----END PUBLIC KEY-----":"\n-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvO8vXV+JksBzZAY6GhSO\nXdoTCfhXaaiZ+qAbtaDBiu2AGkGVpmEygFmWP4Li9m5+Ni85BhVvZOodM9epgW3F\nbA5Q1SexvAF1PPjX4JpMstak/QhAgl1qMSqEevL8cmUeTgcMuVWCJmlge9h7B1CS\nD4rtlimGZozG39rUBDg6Qt2K+P4wBfLblL0k4C4YUdLnpGYEDIth+i8XsRpFlogx\nCAFyH9+knYsDbR43UJ9shtc42Ybd40Afihj8KnYKXzchyQ42aC8aZ/h5hyZ28yVy\nOj3Vos0VdBIs/gAyJ/4yyQFCXYte64I7ssrlbGRaco4nKF3HmaNhxwyKyJafz19e\nHwIDAQAB\n-----END PUBLIC KEY-----",r,"base64")?JSON.parse(e):null})(this.sandbox,t,e)}}}