function e(){return e=Object.assign?Object.assign.bind():function(e){for(var t=1;te.length)&&(t=e.length);for(var r=0,n=new Array(t);r=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 n={ACCOMMODATION:"accommodation",ENTERTAINMENT:"entertainment",GROCERIES:"groceries",RESTAURANTS:"restaurants",TRANSPORT:"transport",CUSTOM:"custom"},i=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?')},o=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 a(t,a){"group"in a?o(a.group.objectId,"entry.group.objectId"):o(a.groupObjectId,"entry.groupObjectId"),function(e){if(null!=e){var t=Object.values(n).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(n).includes(e.type))throw new Error("SplidJs.entry.create: Invalid entry category: must be { type: "+t.join(" | ")+'; originalName: string }, but received "'+JSON.stringify(e)+'".')}}(a.category),i(a.primaryPayer,"entry.primaryPayer");for(var s=0,u=Object.keys(null!=(l=a.secondaryPayers)?l:{});s=0||(i[r]=e[r]);return i}(e,h)};function v(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=y(t);return r.UpdateID=e.randomUUID(),{id:"updateEntry",path:"/parse/classes/Entry/"+t.objectId,method:"PUT",body:r}})}function g(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=y(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 m(e,t){return(Array.isArray(t)?t:[t]).map(function(t){var r=y(t);return r.UpdateID=e.randomUUID(),{id:"updatePerson",path:"/parse/classes/Person/"+t.objectId,method:"PUT",body:r}})}var b=/*#__PURE__*/function(){function e(e){this.requestConfig=void 0,this.person={create:this.injectRequestConfig(p),set:this.injectRequestConfig(m)},this.groupInfo={set:this.injectRequestConfig(g)},this.entry={create:this.injectRequestConfig(a),set:this.injectRequestConfig(v),expense:{create:this.injectRequestConfig(l)},payment:{create:this.injectRequestConfig(c)}},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}(),I=function(e,t){return parseFloat(e.toFixed(t))},P=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=I(e,12);return(Math.round((n-Number.EPSILON)*r)/r).toFixed(t)},D=/*#__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}(),C={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},S=function(t){return e({},t,{id:void 0})},j=function(e,t){try{var r=t.map(S);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)}},R=function(e){return function(){try{var t=[].slice.call(arguments);return Promise.resolve(e.apply(void 0,t)).then(function(e){return Promise.resolve(j(t[0],Array.isArray(e)?e:[e]))})}catch(e){return Promise.reject(e)}}},U=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 p(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:C,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(j(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)}},O=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)}}},A=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 T(e,t){return{id:"getFileWrapper",path:"/parse/functions/getFileWrapper",method:"POST",body:{dataID:t}}}var G,N=function(e,t){try{var r=R(T);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)}},B=function(e,t){try{var r=E(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)}},E=function(e){return e.replace(/\s/g,"")},_=function(t,r){try{return Promise.resolve(t.fetch(t.baseUrl+"/parse/files/file",{method:"POST",body:r,headers:e({},t.getHeaders(),{"Content-Type":"application/octet-stream"})})).then(function(e){var r=t.randomUUID();return Promise.resolve(e.json()).then(function(e){return Promise.resolve(t.fetch(t.baseUrl+"/parse/classes/FileWrapper",{method:"POST",body:JSON.stringify({dataID:r,file:{__type:"File",url:e.url,name:e.name}}),headers:t.getHeaders()})).then(function(t){return Promise.resolve(t.json()).then(function(t){return{dataID:r,file:e,fileWrapper:t}})})})})}catch(e){return Promise.reject(e)}};function q(e,t,r){if(!e.s){if(r instanceof M){if(!r.s)return void(r.o=q.bind(null,e,t));1&t&&(t=r.s),r=r.v}if(r&&r.then)return void r.then(q.bind(null,e,t),q.bind(null,e,2));e.s=t,e.v=r;var n=e.o;n&&n(e)}}var M=/*#__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{q(n,1,o(this.v))}catch(e){q(n,2,e)}return n}return this}return this.o=function(e){try{var i=e.v;1&e.s?q(n,1,t?t(i):i):r?q(n,1,r(i)):q(n,2,i)}catch(e){q(n,2,e)}},n},e}();function x(e){return e instanceof M&&1&e.s}function F(e,t,r){for(var n;;){var i=e();if(x(i)&&(i=i.v),!i)return o;if(i.then){n=0;break}var o=r();if(o&&o.then){if(!x(o)){n=1;break}o=o.s}if(t){var a=t();if(a&&a.then&&!x(a)){n=2;break}}}var s=new M,u=q.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&&!x(a))return void a.then(d).then(void 0,u);if(!(i=e())||x(i)&&!i.v)return void q(s,1,o);if(i.then)return void i.then(c).then(void 0,u);x(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):q(s,1,o)}function d(){(i=e())?i.then?i.then(c).then(void 0,u):c(i):q(s,1,o)}}var K=/*#__PURE__*/function(){function e(e){var t,r,n,i,o,s=this,u=this;this.requestConfig=void 0,this.disableAutomaticInstallationIdRefresh=void 0,this.parseApplicationId=void 0,this.parseClientKey=void 0,this.getCodeConfig=this.injectRequestConfig(A),this.getCurrencyRates=this.injectRequestConfig(function(){return R(w)(u.requestConfig).then(function(e){return e[0].success.result})}),this.group={getByInviteCode:this.injectRequestConfig(B),create:this.injectRequestConfig(U)},this.groupInfo={getByGroup:this.injectRequestConfig(O("GroupInfo")),getOneByGroup:this.injectRequestConfig(function(e,t){return O("GroupInfo")(e,t).then(function(e){return e.result.results[0]})}),updateCurrencyRates:function(e){return u.injectRequestConfig(function(e){})},set:this.injectRequestConfig(R(g))},this.person={create:this.injectRequestConfig(R(p)),getByGroup:this.injectRequestConfig(O("Person")),getAllByGroup:function(e){try{var t=this,r=!1,n=[],i=F(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(R(m))},this.entry={set:this.injectRequestConfig(R(v)),getByGroup:this.injectRequestConfig(O("Entry")),getAllByGroup:function(e){try{var t=this,r=!1,n=[],i=F(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(R(a)),expense:{create:this.injectRequestConfig(R(l))},payment:{create:this.injectRequestConfig(R(c))}},this.file={upload:this.injectRequestConfig(_),getInfo:this.injectRequestConfig(R(T)),getBlob:this.injectRequestConfig(N)},this.batch=function(e){try{var t=e(new b(s.requestConfig)).flat();return Promise.resolve(j(s.requestConfig,t))}catch(e){return Promise.reject(e)}};var d=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 D("splid-js"),installationId:null!=(r=null==e?void 0:e.installationId)?r:d(),randomUUID:d,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;r0?t.push({id:a,balance:u}):u<0&&r.push({id:a,balance:-u})}for(var l=[],c=0,d=0;c0&&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},K.dedupeByGlobalId=f,K.getRoundedBalance=P,K.getTotal=function(e){return G.getRoundedBalance(Object.values(e).reduce(function(e,t){return e+(t.payedBy-t.payedFor)},0))},exports.SplidClient=K; //# sourceMappingURL=index.cjs.map