var __generator=this&&this.__generator||function(e,n){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,o,i,a;return a={next:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(a[Symbol.iterator]=function(){return this}),a;function u(e){return function(n){return s([e,n])}}function s(a){if(r)throw new TypeError("Generator is already executing.");while(t)try{if(r=1,o&&(i=a[0]&2?o["return"]:a[0]?o["throw"]||((i=o["return"])&&i.call(o),0):o.next)&&!(i=i.call(o,a[1])).done)return i;if(o=0,i)a=[a[0]&2,i.value];switch(a[0]){case 0:case 1:i=a;break;case 4:t.label++;return{value:a[1],done:false};case 5:t.label++;o=a[1];a=[0];continue;case 7:a=t.ops.pop();t.trys.pop();continue;default:if(!(i=t.trys,i=i.length>0&&i[i.length-1])&&(a[0]===6||a[0]===2)){t=0;continue}if(a[0]===3&&(!i||a[1]>i[0]&&a[1]<i[3])){t.label=a[1];break}if(a[0]===6&&t.label<i[1]){t.label=i[1];i=a;break}if(i&&t.label<i[2]){t.label=i[2];t.ops.push(a);break}if(i[2])t.ops.pop();t.trys.pop();continue}a=n.call(e,t)}catch(e){a=[6,e];o=0}finally{r=i=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{C as Credentials,E as Error}from"./Credentials-b84c0c5f.js";import{I as Identifier,a as Token}from"./Token-ba2c5d5c.js";import{a as Connection}from"./Item-f4cbd6f4.js";import"./TextDecoder-357ac2ce.js";import"./_commonjsHelpers-9943807e.js";import"./index-1f953d81.js";var __awaiter=undefined&&undefined.__awaiter||function(e,n,t,r){function o(e){return e instanceof t?e:new t((function(n){n(e)}))}return new(t||(t=Promise))((function(t,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function u(e){try{s(r["throw"](e))}catch(e){i(e)}}function s(e){e.done?t(e.value):o(e.value).then(a,u)}s((r=r.apply(e,n||[])).next())}))};var Me=function(){function e(e){var n=this;this.connection=e;this.connection.onUnauthorized=function(){return __awaiter(n,void 0,void 0,(function(){var e;return __generator(this,(function(n){switch(n.label){case 0:e=this.onUnauthorized!=undefined;if(!e)return[3,2];return[4,this.onUnauthorized(this)];case 1:e=n.sent();n.label=2;case 2:return[2,e]}}))}))}}e.prototype.login=function(e,n){return __awaiter(this,void 0,void 0,(function(){var t,r;return __generator(this,(function(o){switch(o.label){case 0:t=typeof e=="string"?{user:e,password:n}:e;return[4,this.connection.get("me",{authorization:Credentials.toBasic(t)})];case 1:r=o.sent();if(!Error.is(r)){Connection.key=Array.isArray(r.merchant)?r.merchant[0].key.private:r.merchant.key.private;this.user=r}return[2,r]}}))}))};e.prototype.logout=function(){Connection.url=undefined;Connection.key=undefined;this.user=undefined};Object.defineProperty(e.prototype,"user",{get:function(){var e=Connection.storage;if(e){var n=e.getItem("Intergiro user");this.userValue=n?JSON.parse(n):undefined}return this.userValue},set:function(e){var n=Connection.storage;if(n)e?n.setItem("Intergiro user",JSON.stringify(e)):n.removeItem("Intergiro user");this.userValue=e},enumerable:false,configurable:true});Object.defineProperty(e.prototype,"customerKeys",{get:function(){var e;var n=Connection.storage;var t=[];for(var r=0;r<((e=n===null||n===void 0?void 0:n.length)!==null&&e!==void 0?e:0);r++){var o=n===null||n===void 0?void 0:n.key(r);if(Identifier.is(o,16))t.push(n===null||n===void 0?void 0:n.getItem(o))}return t.filter(Token.is)},enumerable:false,configurable:true});e.prototype.addCustomerKey=function(e,n){var t=Connection.storage;t&&t.setItem(n,e)};e.open=function(n,t){var r=Connection.open(n,t);return r&&new e(r)};return e}();export{Me};