2 lines
25 KiB
JavaScript
2 lines
25 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e||self).splidJs={})}(this,function(e){function t(){return t=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},t.apply(this,arguments)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function n(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var i=0;return function(){return i>=e.length?{done:!0}:{done:!1,value:e[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i={ACCOMMODATION:"accommodation",ENTERTAINMENT:"entertainment",GROCERIES:"groceries",RESTAURANTS:"restaurants",TRANSPORT:"transport",CUSTOM:"custom"},o=function(e,t){if("string"!=typeof e)throw new Error('Invalid UUID: must be string, but received "'+e+'".');if(!/^[a-zA-Z0-9-]+$/.test(e)||!e.includes("-"))throw new Error("SplidJs.entry.create: Invalid UUID for "+t+': "'+e+'". Did you accidentally pass user.objectId instead of user.GlobalId?')},a=function(e,t){if("string"!=typeof e)throw new Error('Invalid objectId: must be string, but received "'+e+'".');if(!/^[a-zA-Z0-9]+$/.test(e))throw new Error("SplidJs.entry.create: Invalid objectId for "+t+': must be alphanumeric, but received "'+e+'". Did you accidentally pass group.GlobalId instead of group.objectId?')};function s(e,r){"group"in r?a(r.group.objectId,"entry.group.objectId"):a(r.groupObjectId,"entry.groupObjectId"),function(e){if(null!=e){var t=Object.values(i).map(function(e){return'"'+e+'"'});if("object"!=typeof e||!("type"in e)||"string"!=typeof e.type||!("originalName"in e)||"string"!=typeof e.originalName||!Object.values(i).includes(e.type))throw new Error("SplidJs.entry.create: Invalid entry category: must be { type: "+t.join(" | ")+'; originalName: string }, but received "'+JSON.stringify(e)+'".')}}(r.category),o(r.primaryPayer,"entry.primaryPayer");for(var s=0,u=Object.keys(null!=(l=r.secondaryPayers)?l:{});s<u.length;s++){var l;o(u[s],"entry.secondaryPayers")}for(var c,d=n(r.items);!(c=d()).done;)for(var f=0,p=Object.keys(c.value.P.P);f<p.length;f++)o(p[f],"entry.items.P.P");if(r.items.length<1)throw new Error("SplidJs.entry.create: entry must have at least one item.");if(r.items.length<2&&!r.title)throw new Error("SplidJs.entry.create: entry must have a title if it only has one item.");for(var h,y=n(r.items);!(h=y()).done;){var g=h.value;if(Object.keys(g.P.P).length<1)throw new Error('SplidJs.entry.create: item must have at least one profiteer, but received "'+JSON.stringify(g.P)+'".')}var v={id:"createExpense",path:"/parse/classes/Entry",method:"POST",body:t({isDeleted:!1,isPayment:!1,UpdateInstallationID:e.installationId,GlobalId:e.randomUUID(),notes:{__op:"Delete"},createdGlobally:{__type:"Date",iso:(new Date).toISOString()},UpdateID:e.randomUUID(),secondaryPayers:{},group:"group"in r?r.group:{__type:"Pointer",className:"_User",objectId:r.groupObjectId}},r)};return delete v.body.groupObjectId,v}var u=function(e){var t,r=l(e.profiteers);return{T:null!=(t=e.title)?t:"",AM:e.amount,P:{PT:0,P:r}}},l=function(e){if(!Array.isArray(e))return e;for(var t,r=e.filter(function(e){return"string"!=typeof e}),i=e.filter(function(e){return"string"==typeof e}),o=1/r.reduce(function(e,t){return e+t.share},0),a={},s=n(r);!(t=s()).done;){var u=t.value;a[u.id]=u.share}for(var l,c=n(i);!(l=c()).done;)a[l.value]=o/r.length;return a};function c(e,r,i){var o,a=Array.isArray(i)?i.map(u):[i].map(u);if(Object.entries(r.payers).length<1)throw new Error("expense has to have at least one payer");var s=Array.isArray(i)?i.reduce(function(e,t){return e+t.amount},0):i.amount,l=function(e,t){if(!Array.isArray(e))return e;for(var r,i=e.filter(function(e){return"string"!=typeof e}),o=e.filter(function(e){return"string"==typeof e}),a=t-i.reduce(function(e,t){return e+t.amount},0),s={},u=n(i);!(r=u()).done;){var l=r.value;s[l.id]=l.amount}for(var c,d=n(o);!(c=d()).done;)s[c.value]=a/i.length;return s}(r.payers,s),c=Object.entries(l)[0][0],d=Object.entries(l).slice(1).reduce(function(e,r){var n;return t({},e,((n={})[r[0]]=r[1],n))},{});return{id:"createExpense",path:"/parse/classes/Entry",method:"POST",body:{category:r.category,UpdateInstallationID:e.installationId,GlobalId:e.randomUUID(),title:r.title,secondaryPayers:d,notes:{__op:"Delete"},primaryPayer:c,date:r.date?{__type:"Date",iso:r.date.toISOString()}:void 0,createdGlobally:{__type:"Date",iso:(new Date).toISOString()},isDeleted:!1,group:{__type:"Pointer",className:"_User",objectId:r.groupId},items:a,isPayment:!1,UpdateID:e.randomUUID(),currencyCode:null!=(o=r.currencyCode)?o:"EUR"}}}function d(e,t){var r,n,i=t.payer;return{id:"createPayment",path:"/parse/classes/Entry",method:"POST",body:{category:{__op:"Delete"},UpdateInstallationID:e.installationId,GlobalId:e.randomUUID(),title:{__op:"Delete"},secondaryPayers:{__op:"Delete"},notes:{__op:"Delete"},primaryPayer:i,date:t.date?{__type:"Date",iso:t.date.toISOString()}:void 0,createdGlobally:{__type:"Date",iso:(new Date).toISOString()},isDeleted:!1,group:{__type:"Pointer",className:"_User",objectId:t.groupId},items:[{T:"",AM:t.amount,P:{PT:0,P:(r={},r[t.profiteer]=1,r)}}],isPayment:!0,UpdateID:e.randomUUID(),currencyCode:null!=(n=t.currencyCode)?n:"EUR"}}}var f=function(e){var t;return null!=(t=e.split(" ").map(function(e){return e[0]}).join(""))?t:""},p=function(e){return e.filter(function(e,t,r){if(!e.GlobalId)throw new Error('SplidClient.dedupeByGlobalId: item is missing "GlobalId" field');return r.findIndex(function(t){return t.GlobalId===e.GlobalId})===t})};function h(e,t,r,n){return{id:"createPerson",path:"/parse/classes/Person",method:"POST",body:{GlobalId:e.randomUUID(),UpdateID:e.randomUUID(),isDeleted:!1,createdGlobally:{__type:"Date",iso:(new Date).toISOString()},UpdateInstallationID:e.installationId,group:{__type:"Pointer",className:"_User",objectId:t},name:r,initials:null!=n?n:f(r)}}}var y=["objectId","createdAt","updatedAt","__type","className"],g=function(e){return function(e,t){if(null==e)return{};var r,n,i={},o=Object.keys(e);for(n=0;n<o.length;n++)t.indexOf(r=o[n])>=0||(i[r]=e[r]);return i}(e,y)};function v(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=g(t);return r.UpdateID=e.randomUUID(),{id:"updateEntry",path:"/parse/classes/Entry/"+t.objectId,method:"PUT",body:r}})}function m(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=g(t);return r.UpdateID=e.randomUUID(),r.wallpaperID||(r.wallpaperID={__op:"Delete"}),{id:"updateGroup",path:"/parse/classes/GroupInfo/"+t.objectId,method:"PUT",body:r}})}function b(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=g(t);return r.UpdateID=e.randomUUID(),{id:"updatePerson",path:"/parse/classes/Person/"+t.objectId,method:"PUT",body:r}})}var I=/*#__PURE__*/function(){function e(e){this.requestConfig=void 0,this.person={create:this.injectRequestConfig(h),set:this.injectRequestConfig(b)},this.groupInfo={set:this.injectRequestConfig(m)},this.entry={create:this.injectRequestConfig(s),set:this.injectRequestConfig(v),expense:{create:this.injectRequestConfig(c)},payment:{create:this.injectRequestConfig(d)}},this.requestConfig=e}return e.prototype.injectRequestConfig=function(e){var t=this;return function(){return e.apply(void 0,[t.requestConfig].concat([].slice.call(arguments)))}},e}(),P=function(e,t){return parseFloat(e.toFixed(t))},D=function(e,t){if(void 0===t&&(t=2),127.70500000000004===e)return"127.70";if(21.985000000000007===e)return"21.98";var r=Math.pow(10,t);if(e>=0)return(Math.round((e+Number.EPSILON)*r)/r).toFixed(t);if(e>=-.004)return"0.00";if(e>=-.005)return"-0.00";var n=P(e,12);return(Math.round((n-Number.EPSILON)*r)/r).toFixed(t)},C=/*#__PURE__*/function(){function e(){var e,t,r,n,i,o,a=this;this.prefixes=void 0,this.fatal=(e=a,function(){var t;return(t=console).error.apply(t,[e.getPrefixesString()].concat([].slice.call(arguments)))}),this.error=(t=a,function(){var e;return(e=console).error.apply(e,[t.getPrefixesString()].concat([].slice.call(arguments)))}),this.warn=(r=a,function(){var e;return(e=console).warn.apply(e,[r.getPrefixesString()].concat([].slice.call(arguments)))}),this.info=(n=a,function(){var e;return(e=console).info.apply(e,[n.getPrefixesString()].concat([].slice.call(arguments)))}),this.debug=(i=a,function(){var e;return(e=console).debug.apply(e,[i.getPrefixesString()].concat([].slice.call(arguments)))}),this.trace=(o=a,function(){var e;return(e=console).log.apply(e,[o.getPrefixesString()].concat([].slice.call(arguments)))}),this.prefixes=[].slice.call(arguments)}var t=e.prototype;return t.getPrefixesString=function(){return this.prefixes.map(function(e){return"["+e+"]"}).join("")},t.extendScope=function(e){return this.prefixes.push(e),this},e}(),S={HRK:.14464756981234148,HUF:.0026724023833275485,CDF:.0003510522680451083,ILS:.266679253927452,NGN:.000608350215051801,GYD:.004772579362900076,BHD:2.653723572230375,SZL:.05705922136644168,INR:.01188592667296082,SDG:.0016625103906899418,PEN:.2647683131637245,EUR:1.0899301354783157,QAR:.2741729367732532,PGK:.24923671256776123,LRD:.005204877376081824,ISK:.007319036814755178,SYP:.0003980051979478852,TRY:.0291147463395194,UAH:.024111448516005444,SGD:.7593302707012415,MMK:.00047664442326024784,NIO:.027157869237032256,BIF:.0003439385196028609,AFN:.01493399963662592,LKR:.003408737771604902,GTQ:.129347716281993,CHF:1.1590950712959378,XPT:985.0372836611865,THB:.029679755438815188,AMD:.00258198180829602,AOA:.001100048292120024,SEK:.09359834143738974,SAR:.2662523070762408,KWD:3.2630047052527846,IRR:2375720140167488e-20,WST:.35714285714285715,BMD:1,BGN:.5573949589199916,PHP:.01712416733736322,ZMW:.03725465250070924,XAF:.0016615875728522864,BDT:.008362675592562886,NOK:.0910282551704049,BOB:.14430139366286,TZS:.00037162660593792425,XAG:32.51409729973673,VUV:.008423038695439767,ANG:.5545072288334887,BND:.7594917481221567,XCD:.37002090618119926,SCR:.07005744710662744,KYD:1.1991529183784573,DJF:.005611969032458995,CLF:28.861694758716233,LSL:.057083490312931695,MOP:.12482603931096527,ALL:.011094913769775436,UZS:781390950718276e-19,UYU:.02403650163909712,PLN:.25070196550340956,LYD:.20782394817702027,JPY:.0065793152906577015,MNT:.0002942907592701589,FJD:.4452855393521095,ZWL:.003105590062111801,KPW:.0011111111111111111,PKR:.003597760115142139,OMR:2.5971799819755708,GBP:1.2981045077977138,SHP:1.2981045077977138,CNH:.14077210685166,GEL:.3656307129798903,TND:.32377244107260633,DKK:.1461503913834406,NPR:.007426425161993912,KRW:.0007269340727431456,BSD:1,CRC:.0019472584882672145,EGP:.02038376680840315,MAD:.10181665345765283,AUD:.6599902057453467,BTC:68616.88667070317,SLL:47688309210996924e-21,MWK:.000576321757541795,RSD:.009312894633910112,NZD:.599033758547463,SRD:.02864836990775225,CLP:.0010459047599125624,RUB:.01009623835361045,MRU:.02527484242778611,NAD:.057083490312931695,HKD:.12867126460563608,GMD:.013986013986013986,VES:.02336181301873008,LAK:4562423035795743e-20,VND:3949499430270272e-20,CUC:1,RON:.21906284913141583,MUR:.021819767758247097,XAU:2738.075680411807,GGP:1.2981045077977138,MXN:.04996034397696828,BRL:.17340338830220745,STD:44879677584396233e-21,AWG:.5547850208044383,MVR:.06489292667099286,PAB:1,TJS:.09383458894960717,GNF:.00011587954818413982,MGA:.00021673877274122117,XDR:1.3303604212453237,ETB:.008348431192864589,ZAR:.05706166654303306,COP:.00022525100434022443,IDR:6341315390670045e-20,SVC:.11421719702089571,CVE:.009891170614898864,TTD:.1474222844999473,GIP:1.2981045077977138,PYG:.00012689283048494395,MZN:.015647005067783295,FKP:1.2981045077977138,KZT:.0020452303259242645,USD:1,UGX:.0002730749395015238,RWF:.0007345299305304876,GHS:.06112026353101786,ARS:.0010078152037792264,JEP:1.2981045077977138,DOP:.016636057983582673,LBP:11159788884633067e-21,BZD:.4957860663292346,BTN:.011882274276327017,MYR:.22870211549456834,YER:.003994406775990225,JMD:.006324866255959368,TOP:.4198963695759886,SOS:.0017486465632978265,TMT:.2857142857142857,XPD:1067.2700299902879,MDL:.05614472267959897,XOF:.0016615875728522864,TWD:.031346488409635914,BBD:.5,CAD:.7199589911358649,CNY:.14085300580314383,JOD:1.4100394811054708,XPF:.009133613383315633,IQD:.0007628591385010084,STN:.04451673566612306,AED:.27225701061802343,HNL:.039644506127772025,SSP:.0076769537847382165,ERN:.06666666666666667,KES:.007747133560582584,KMF:.0022033727454068256,DZD:.0075175908430751845,MKD:.017696176852476937,CUP:.038834951456310676,BWP:.07505023299720086,AZN:.5882352941176471,SBD:.12019326114846585,BYN:.3053617865374538,KGS:.011655011655011656,KHR:.0002461931857947893,HTG:.0075940672746725,CZK:.04305705244594413,BAM:.5576541941729598,IMP:1.2981045077977138},j=function(e){return t({},e,{id:void 0})},R=function(e,t){try{var r=t.map(j);return Promise.resolve(e.fetch(e.baseUrl+"/parse/batch",{method:"POST",body:JSON.stringify({requests:r}),headers:e.getHeaders()})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}},U=function(e){return function(){try{var t=[].slice.call(arguments);return Promise.resolve(e.apply(void 0,t)).then(function(e){return Promise.resolve(R(t[0],Array.isArray(e)?e:[e]))})}catch(e){return Promise.reject(e)}}},O=function(e,t,r,n){try{return Promise.resolve(e.fetch(e.baseUrl+"/parse/functions/createGroup",{method:"POST",body:JSON.stringify({}),headers:e.getHeaders()})).then(function(i){return Promise.resolve(i.json()).then(function(i){var o,a,s,u,l=i.result.objectId,c=r.map(function(e){return"string"==typeof e?{name:e}:e}).map(function(t){return h(e,l,t.name,t.initials)}),d={id:"updateGroup",path:"/parse/classes/GroupInfo",method:"POST",body:{UpdateInstallationID:e.installationId,customCategories:null!=(o=null==n?void 0:n.customCategories)?o:{__op:"Delete"},GlobalId:e.randomUUID(),currencyRates:null!=(a=null==n?void 0:n.currencyRates)?a:S,isDeleted:!1,wallpaperID:null!=(s=null==n?void 0:n.wallpaperID)?s:{__op:"Delete"},creatorExperiments:{},createdGlobally:{__type:"Date",iso:(new Date).toISOString()},defaultCurrencyCode:null!=(u=null==n?void 0:n.defaultCurrencyCode)?u:"EUR",UpdateID:e.randomUUID(),group:{__type:"Pointer",className:"_User",objectId:l},creatorInstallationID:e.installationId,name:t}};return Promise.resolve(R(e,[d].concat(c))).then(function(e){var t=e[0],r=e.slice(1);return{group:i,groupInfo:t,groupMembers:r}})})})}catch(e){return Promise.reject(e)}},A=function(e){return function(t,r,n,i,o){void 0===n&&(n=0),void 0===i&&(i=100);try{var a,s={className:e,minDate:{__type:"Date",iso:null!=(a=null==o?void 0:o.toISOString())?a:"1969-12-31T00:00:00.000Z"},group:r,limit:i,skip:n};return Promise.resolve(t.fetch(t.baseUrl+"/parse/functions/findObjects",{method:"POST",body:JSON.stringify(s),headers:t.getHeaders()})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}}},T=function(e,t){try{return Promise.resolve(e.fetch(e.baseUrl+"/parse/functions/getCodeConfig",{method:"POST",body:JSON.stringify({device:t}),headers:e.getHeaders()})).then(function(e){return Promise.resolve(e.json())})}catch(e){return Promise.reject(e)}};function w(e){return{id:"getCurrencyRates",path:"/parse/functions/getCurrencyRates",method:"POST",body:{}}}function G(e,t){return{id:"getFileWrapper",path:"/parse/functions/getFileWrapper",method:"POST",body:{dataID:t}}}var N,B=function(e,t){try{var r=U(G);return Promise.resolve(r(e,t)).then(function(t){var r,n=null==t||null==(r=t[0])||null==(r=r.success)||null==(r=r.result)||null==(r=r.file)?void 0:r.url;if(!n)throw new Error("SplidClient.file.getBlob: failed to get url from invalid response");return Promise.resolve(e.fetch(n)).then(function(e){if(!e.ok)throw new Error("SplidClient.file.getBlob: GET "+n+" failed with status "+e.status);return Promise.resolve(e.blob())})})}catch(e){return Promise.reject(e)}},E=function(e,t){try{var r=_(t).toUpperCase();return Promise.resolve(e.fetch(e.baseUrl+"/parse/functions/joinGroupWithAnyCode",{method:"POST",body:JSON.stringify({code:r}),headers:e.getHeaders()})).then(function(t){return Promise.resolve(t.json()).then(function(t){return e.assertResponseBody(t)})})}catch(e){return Promise.reject(e)}},_=function(e){return e.replace(/\s/g,"")},q=function(e,r){try{return Promise.resolve(e.fetch(e.baseUrl+"/parse/files/file",{method:"POST",body:r,headers:t({},e.getHeaders(),{"Content-Type":"application/octet-stream"})})).then(function(t){var r=e.randomUUID();return Promise.resolve(t.json()).then(function(t){return Promise.resolve(e.fetch(e.baseUrl+"/parse/classes/FileWrapper",{method:"POST",body:JSON.stringify({dataID:r,file:{__type:"File",url:t.url,name:t.name}}),headers:e.getHeaders()})).then(function(e){return Promise.resolve(e.json()).then(function(e){return{dataID:r,file:t,fileWrapper:e}})})})})}catch(e){return Promise.reject(e)}};function M(e,t,r){if(!e.s){if(r instanceof x){if(!r.s)return void(r.o=M.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(M.bind(null,e,t),M.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var x=/*#__PURE__*/function(){function e(){}return e.prototype.then=function(t,r){var n=new e,i=this.s;if(i){var o=1&i?t:r;if(o){try{M(n,1,o(this.v))}catch(e){M(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?M(n,1,t?t(i):i):r?M(n,1,r(i)):M(n,2,i)}catch(e){M(n,2,e)}},n},e}();function F(e){return e instanceof x&&1&e.s}function K(e,t,r){for(var n;;){var i=e();if(F(i)&&(i=i.v),!i)return o;if(i.then){n=0;break}var o=r();if(o&&o.then){if(!F(o)){n=1;break}o=o.s}if(t){var a=t();if(a&&a.then&&!F(a)){n=2;break}}}var s=new x,u=M.bind(null,s,2);return(0===n?i.then(c):1===n?o.then(l):a.then(d)).then(void 0,u),s;function l(n){o=n;do{if(t&&(a=t())&&a.then&&!F(a))return void a.then(d).then(void 0,u);if(!(i=e())||F(i)&&!i.v)return void M(s,1,o);if(i.then)return void i.then(c).then(void 0,u);F(o=r())&&(o=o.v)}while(!o||!o.then);o.then(l).then(void 0,u)}function c(e){e?(o=r())&&o.then?o.then(l).then(void 0,u):l(o):M(s,1,o)}function d(){(i=e())?i.then?i.then(c).then(void 0,u):c(i):M(s,1,o)}}var J=/*#__PURE__*/function(){function e(e){var t,r,n,i,o,a=this,u=this;this.requestConfig=void 0,this.disableAutomaticInstallationIdRefresh=void 0,this.parseApplicationId=void 0,this.parseClientKey=void 0,this.getCodeConfig=this.injectRequestConfig(T),this.getCurrencyRates=this.injectRequestConfig(function(){return U(w)(u.requestConfig).then(function(e){return e[0].success.result})}),this.group={getByInviteCode:this.injectRequestConfig(E),create:this.injectRequestConfig(O)},this.groupInfo={getByGroup:this.injectRequestConfig(A("GroupInfo")),getOneByGroup:this.injectRequestConfig(function(e,t){return A("GroupInfo")(e,t).then(function(e){return e.result.results[0]})}),updateCurrencyRates:function(e){return u.injectRequestConfig(function(e){})},set:this.injectRequestConfig(U(m))},this.person={create:this.injectRequestConfig(U(h)),getByGroup:this.injectRequestConfig(A("Person")),getAllByGroup:function(e){try{var t=this,r=!1,n=[],i=K(function(){return!r},void 0,function(){return Promise.resolve(t.person.getByGroup(e,n.length)).then(function(e){n=n.concat(e.result.results),e.result.results.length<100&&(r=!0)})});return Promise.resolve(i&&i.then?i.then(function(){return n}):n)}catch(e){return Promise.reject(e)}}.bind(this),set:this.injectRequestConfig(U(b))},this.entry={set:this.injectRequestConfig(U(v)),getByGroup:this.injectRequestConfig(A("Entry")),getAllByGroup:function(e){try{var t=this,r=!1,n=[],i=K(function(){return!r},void 0,function(){return Promise.resolve(t.entry.getByGroup(e,n.length)).then(function(e){n=n.concat(e.result.results),e.result.results.length<100&&(r=!0)})});return Promise.resolve(i&&i.then?i.then(function(){return n}):n)}catch(e){return Promise.reject(e)}}.bind(this),create:this.injectRequestConfig(U(s)),expense:{create:this.injectRequestConfig(U(c))},payment:{create:this.injectRequestConfig(U(d))}},this.file={upload:this.injectRequestConfig(q),getInfo:this.injectRequestConfig(U(G)),getBlob:this.injectRequestConfig(B)},this.batch=function(e){try{var t=e(new I(a.requestConfig)).flat();return Promise.resolve(R(a.requestConfig,t))}catch(e){return Promise.reject(e)}};var l=function(){return crypto.randomUUID()},f=null!=(t=null==e?void 0:e.fetch)?t:fetch;if(!f)throw new Error("SplidClient is based on the fetch API, but no global fetch implementation could be found. this might occur if you are using NodeJs < v18.0.0. please upgrade your runtime or pass a fetch implementation into the SplidClient constructor options.");this.requestConfig={baseUrl:"https://splid.herokuapp.com",getHeaders:this.getHeaders.bind(this),fetch:f,logger:new C("splid-js"),installationId:null!=(r=null==e?void 0:e.installationId)?r:l(),randomUUID:l,assertResponseBody:this.assertResponseBody.bind(this)},this.disableAutomaticInstallationIdRefresh=null!=(n=null==e?void 0:e.disableAutomaticInstallationIdRefresh)&&n,this.parseApplicationId=null!=(i=null==e?void 0:e.parseApplicationId)?i:"AKCaB0FCF0NIigWjxcDBpDYh7q6eN7gYfKxk5QBN",this.parseClientKey=null!=(o=null==e?void 0:e.parseClientKey)?o:"4Z29DJvRGdVnB5dcTvDTTG01fbkITxvcPCPOt21M"}var t,r,n=e.prototype;return n.setInstallationId=function(e){this.requestConfig.installationId=e},n.setRandomInstallationId=function(){this.requestConfig.installationId=this.requestConfig.randomUUID()},n.getHeaders=function(){return{"x-parse-app-build-version":"182063","x-parse-app-display-version":"1.8.2","x-parse-application-id":this.parseApplicationId,"x-parse-client-key":this.parseClientKey,"x-parse-installation-id":this.requestConfig.installationId,"X-Parse-Client-Version":"i1.17.3","x-parse-os-version":"13","Content-Type":"application/json"}},n.assertResponseBody=function(e){if("object"==typeof e&&null!=e&&"error"in e){if("Access denied: too many invalid codes"===e.error&&!this.disableAutomaticInstallationIdRefresh)return this.requestConfig.logger.info("encountered rate limit, switching installation id"),void this.setRandomInstallationId();throw new Error("request failed: "+e.error)}return e},n.injectRequestConfig=function(e){var t=this;return function(){return e.apply(void 0,[t.requestConfig].concat([].slice.call(arguments))).catch(function(e){throw t.requestConfig.logger.error("request failed:",JSON.stringify(e,null,2)),e})}},t=e,(r=[{key:"installationId",get:function(){return this.requestConfig.installationId}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(i=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?i:String(i),n)}var i}(t.prototype,r),Object.defineProperty(t,"prototype",{writable:!1}),e}();N=J,J.getBalance=function(e,t,r){for(var i,o=p(e),a=p(t),s=o.reduce(function(e,t){return e[t.GlobalId]={payedFor:0,payedBy:0,balance:""},e},{}),u=n(a);!(i=u()).done;){var l,c,d,f=i.value;if(!f.isDeleted){if(!s[f.primaryPayer])throw new Error('SplidClient.getBalance: failed to resolve primary payer with id "'+f.primaryPayer+'"');for(var h=null!=(l=null==r?void 0:r.defaultCurrencyCode)?l:"USD",y=null!=(null==r||null==(c=r.currencyRates)?void 0:c[f.currencyCode])&&null!=(null==r||null==(d=r.currencyRates)?void 0:d[h])?(null==r?void 0:r.currencyRates[f.currencyCode])/(null==r?void 0:r.currencyRates[h]):1,g=0,v=Object.entries(null!=(m=f.secondaryPayers)?m:{});g<v.length;g++){var m,b=v[g],I=b[0],P=b[1];if(!s[I])throw new Error('SplidClient.getBalance: failed to resolve secondary payer with id "'+I+'"');s[I].payedFor+=P*y,s[f.primaryPayer].payedFor-=P*y}for(var C,S=n(f.items);!(C=S()).done;){var j=C.value;s[f.primaryPayer].payedFor+=j.AM*y;for(var R=0,U=Object.entries(j.P.P);R<U.length;R++){var O=U[R],A=O[0],T=O[1];if(!s[A])throw new Error('SplidClient.getBalance: failed to resolve profiteer with id "'+A+'"');s[A].payedBy+=j.AM*T*y}}}}for(var w=0,G=Object.values(s);w<G.length;w++){var N=G[w];N.balance=D(N.payedFor-N.payedBy)}return s},J.getSuggestedPayments=function(e){for(var t=[],r=[],n=0,i=Object.entries(e);n<i.length;n++){var o=i[n],a=o[0],s=o[1],u=s.payedFor-s.payedBy;u>0?t.push({id:a,balance:u}):u<0&&r.push({id:a,balance:-u})}for(var l=[],c=0,d=0;c<t.length&&d<r.length;){var f=t[c],p=r[d],h=Math.min(f.balance,p.balance);P(h,2)>0&&l.push({from:p.id,to:f.id,amount:h.toFixed(2)}),f.balance-=h,p.balance-=h,0===f.balance&&c++,0===p.balance&&d++}return l},J.dedupeByGlobalId=p,J.getRoundedBalance=D,J.getTotal=function(e){return N.getRoundedBalance(Object.values(e).reduce(function(e,t){return e+(t.payedBy-t.payedFor)},0))},e.SplidClient=J});
|
|
//# sourceMappingURL=index.umd.js.map
|