@qikdev/sdk 0.1.4 → 0.1.8

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/dist/index.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("axios"),require("lodash"),require("axios-extensions")):"function"==typeof define&&define.amd?define(["axios","lodash","axios-extensions"],r):"object"==typeof exports?exports["@qikdev/sdk"]=r(require("axios"),require("lodash"),require("axios-extensions")):e["@qikdev/sdk"]=r(e.axios,e._,e["axios-extensions"])}("undefined"!=typeof self?self:this,(function(e,r,t){return(()=>{"use strict";var n={818:(e,r)=>{var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};"undefined"!=typeof window&&window.document,"object"===("undefined"==typeof self?"undefined":t(self))&&self.constructor&&self.constructor.name,"undefined"!=typeof process&&null!=process.versions&&process.versions.node},798:e=>{var r=String.prototype.replace,t=/%20/g;e.exports={default:"RFC3986",formatters:{RFC1738:function(e){return r.call(e,t,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},129:(e,r,t)=>{var n=t(261),o=t(235),i=t(798);e.exports={formats:i,parse:o,stringify:n}},235:(e,r,t)=>{var n=t(769),o=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:n.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(e,r,t){if(e){var n=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,a=/(\[[^[\]]*])/.exec(n),s=a?n.slice(0,a.index):n,u=[];if(s){if(!t.plainObjects&&o.call(Object.prototype,s)&&!t.allowPrototypes)return;u.push(s)}for(var c=0;null!==(a=i.exec(n))&&c<t.depth;){if(c+=1,!t.plainObjects&&o.call(Object.prototype,a[1].slice(1,-1))&&!t.allowPrototypes)return;u.push(a[1])}return a&&u.push("["+n.slice(a.index)+"]"),function(e,r,t){for(var n=r,o=e.length-1;o>=0;--o){var i,a=e[o];if("[]"===a&&t.parseArrays)i=[].concat(n);else{i=t.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,u=parseInt(s,10);t.parseArrays||""!==s?!isNaN(u)&&a!==s&&String(u)===s&&u>=0&&t.parseArrays&&u<=t.arrayLimit?(i=[])[u]=n:"__proto__"!==s&&(i[s]=n):i={0:n}}n=i}return n}(u,r,t)}};e.exports=function(e,r){var t=r?n.assign({},r):{};if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(t.ignoreQueryPrefix=!0===t.ignoreQueryPrefix,t.delimiter="string"==typeof t.delimiter||n.isRegExp(t.delimiter)?t.delimiter:i.delimiter,t.depth="number"==typeof t.depth?t.depth:i.depth,t.arrayLimit="number"==typeof t.arrayLimit?t.arrayLimit:i.arrayLimit,t.parseArrays=!1!==t.parseArrays,t.decoder="function"==typeof t.decoder?t.decoder:i.decoder,t.allowDots="boolean"==typeof t.allowDots?t.allowDots:i.allowDots,t.plainObjects="boolean"==typeof t.plainObjects?t.plainObjects:i.plainObjects,t.allowPrototypes="boolean"==typeof t.allowPrototypes?t.allowPrototypes:i.allowPrototypes,t.parameterLimit="number"==typeof t.parameterLimit?t.parameterLimit:i.parameterLimit,t.strictNullHandling="boolean"==typeof t.strictNullHandling?t.strictNullHandling:i.strictNullHandling,""===e||null==e)return t.plainObjects?Object.create(null):{};for(var s="string"==typeof e?function(e,r){for(var t={},n=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=r.parameterLimit===1/0?void 0:r.parameterLimit,s=n.split(r.delimiter,a),u=0;u<s.length;++u){var c,l,f=s[u],p=f.indexOf("]="),d=-1===p?f.indexOf("="):p+1;-1===d?(c=r.decoder(f,i.decoder),l=r.strictNullHandling?null:""):(c=r.decoder(f.slice(0,d),i.decoder),l=r.decoder(f.slice(d+1),i.decoder)),o.call(t,c)?t[c]=[].concat(t[c]).concat(l):t[c]=l}return t}(e,t):e,u=t.plainObjects?Object.create(null):{},c=Object.keys(s),l=0;l<c.length;++l){var f=c[l],p=a(f,s[f],t);u=n.merge(u,p,t)}return n.compact(u)}},261:(e,r,t)=>{var n=t(769),o=t(798),i={brackets:function(e){return e+"[]"},indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},a=Array.isArray,s=Array.prototype.push,u=function(e,r){s.apply(e,a(r)?r:[r])},c=Date.prototype.toISOString,l={delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,serializeDate:function(e){return c.call(e)},skipNulls:!1,strictNullHandling:!1},f=function e(r,t,o,i,s,c,f,p,d,h,g,y){var m=r;if("function"==typeof f?m=f(t,m):m instanceof Date&&(m=h(m)),null===m){if(i)return c&&!y?c(t,l.encoder):t;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||n.isBuffer(m))return c?[g(y?t:c(t,l.encoder))+"="+g(c(m,l.encoder))]:[g(t)+"="+g(String(m))];var v,b=[];if(void 0===m)return b;if(a(f))v=f;else{var w=Object.keys(m);v=p?w.sort(p):w}for(var k=0;k<v.length;++k){var j=v[k];s&&null===m[j]||(a(m)?u(b,e(m[j],o(t,j),o,i,s,c,f,p,d,h,g,y)):u(b,e(m[j],t+(d?"."+j:"["+j+"]"),o,i,s,c,f,p,d,h,g,y)))}return b};e.exports=function(e,r){var t=e,s=r?n.assign({},r):{};if(null!==s.encoder&&void 0!==s.encoder&&"function"!=typeof s.encoder)throw new TypeError("Encoder has to be a function.");var c=void 0===s.delimiter?l.delimiter:s.delimiter,p="boolean"==typeof s.strictNullHandling?s.strictNullHandling:l.strictNullHandling,d="boolean"==typeof s.skipNulls?s.skipNulls:l.skipNulls,h="boolean"==typeof s.encode?s.encode:l.encode,g="function"==typeof s.encoder?s.encoder:l.encoder,y="function"==typeof s.sort?s.sort:null,m=void 0!==s.allowDots&&s.allowDots,v="function"==typeof s.serializeDate?s.serializeDate:l.serializeDate,b="boolean"==typeof s.encodeValuesOnly?s.encodeValuesOnly:l.encodeValuesOnly;if(void 0===s.format)s.format=o.default;else if(!Object.prototype.hasOwnProperty.call(o.formatters,s.format))throw new TypeError("Unknown format option provided.");var w,k,j=o.formatters[s.format];"function"==typeof s.filter?t=(k=s.filter)("",t):a(s.filter)&&(w=k=s.filter);var A,O=[];if("object"!=typeof t||null===t)return"";A=s.arrayFormat in i?s.arrayFormat:"indices"in s?s.indices?"indices":"repeat":"indices";var R=i[A];w||(w=Object.keys(t)),y&&w.sort(y);for(var q=0;q<w.length;++q){var x=w[q];d&&null===t[x]||u(O,f(t[x],x,R,p,d,h?g:null,k,y,m,v,j,b))}var S=O.join(c),P=!0===s.addQueryPrefix?"?":"";return S.length>0?P+S:""}},769:e=>{var r=Object.prototype.hasOwnProperty,t=function(){for(var e=[],r=0;r<256;++r)e.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return e}(),n=function(e,r){for(var t=r&&r.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t};e.exports={arrayToObject:n,assign:function(e,r){return Object.keys(r).reduce((function(e,t){return e[t]=r[t],e}),e)},compact:function(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],i=o.obj[o.prop],a=Object.keys(i),s=0;s<a.length;++s){var u=a[s],c=i[u];"object"==typeof c&&null!==c&&-1===t.indexOf(c)&&(r.push({obj:i,prop:u}),t.push(c))}return function(e){for(var r;e.length;){var t=e.pop();if(r=t.obj[t.prop],Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}return r}(r)},decode:function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(r){return e}},encode:function(e){if(0===e.length)return e;for(var r="string"==typeof e?e:String(e),n="",o=0;o<r.length;++o){var i=r.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?n+=r.charAt(o):i<128?n+=t[i]:i<2048?n+=t[192|i>>6]+t[128|63&i]:i<55296||i>=57344?n+=t[224|i>>12]+t[128|i>>6&63]+t[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&r.charCodeAt(o)),n+=t[240|i>>18]+t[128|i>>12&63]+t[128|i>>6&63]+t[128|63&i])}return n},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,o,i){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if(!t||"object"!=typeof t)return[t,o];(i&&(i.plainObjects||i.allowPrototypes)||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(o);var a=t;return Array.isArray(t)&&!Array.isArray(o)&&(a=n(t,i)),Array.isArray(t)&&Array.isArray(o)?(o.forEach((function(n,o){if(r.call(t,o)){var a=t[o];a&&"object"==typeof a&&n&&"object"==typeof n?t[o]=e(a,n,i):t.push(n)}else t[o]=n})),t):Object.keys(o).reduce((function(t,n){var a=o[n];return r.call(t,n)?t[n]=e(t[n],a,i):t[n]=a,t}),a)}}},103:r=>{r.exports=e},757:e=>{e.exports=t},607:e=>{e.exports=r}},o={};function i(e){var r=o[e];if(void 0!==r)return r.exports;var t=o[e]={exports:{}};return n[e](t,t.exports,i),t.exports}i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{i.r(a),i.d(a,{default:()=>g});var e=i(103),r=i(607),t=i(129);var n=i(757);const o=e.CancelToken,s=function(n){var i;process.browser&&(i=n.cache.get("api"));const a=e.defaults.adapter,s=(u=function(r){return new Promise((function(t,n){var o,s;switch(String(r.method).toLowerCase()){case"post":case"patch":case"put":case"delete":r.cache||(r.cache=!1)}if(!1===r.cache);else if(o=r.cache||i){var u=getCacheKeyFromConfig(r);s=o.get(u)}return s?t(s):(Object.assign(r,{adapter:a}),e.request(r).then((function(e){t(e)}),(function(e){n(e)})))}))},(c=e.create({paramsSerializer:e=>t.stringify(e,{arrayFormat:"repeat"}),adapter:u})).defaults.baseURL=n.apiURL,c.defaults.headers.common.Accept="application/json",c.interceptors.request.use((function(e){return e.headers["qik-request-date"]=(new Date).getTime(),Intl&&(e.headers["qik-request-timezone"]=Intl.DateTimeFormat().resolvedOptions().timeZone),e.headers["qik-api-version"]="0.1.0",e})),c.interceptors.response.use((function(e){return e.config,e}),(function(t){if(e.isCancel(t))return console.log("Request cancelled"),Promise.reject(t);var n=r.get(t,"response.status")||t.status;switch(n){case 401:case 404:break;case 502:case 504:return console.log(`qik.api > ${n} connection error retrying`),c.request(t.config);default:console.log("qik.api > connection error",n,t)}return Promise.reject(t)})),c);var u,c;return s.generateEndpointURL=function(e,r){if(e&&String(e).length){r||(r={});var t=`${n.apiURL}${e}`;t=function(e,r){if(!r.withoutToken){var t=n.auth.getCurrentToken();!r.access_token&&t&&(r.access_token=t)}return e}(t,r);var o=n.utils.mapParameters(r);return o.length&&(t+="?"+o),t}},s.CancelToken=o,s.axios=e,s};i(818);var u={mapParameters:function(e){return r.chain(e).reduce((function(e,t,n){return null==t||!1===t||(r.isArray(t)?r.each(t,(function(r){e.push(`${n}=${encodeURIComponent(r)}`)})):e.push(encodeURIComponent(n)+"="+encodeURIComponent(t))),e}),[]).compact().value().join("&")},formatCurrency:function(e,r){return e&&!isNaN(e)||(e=0),`${u.currencySymbol(r)}${parseFloat(parseInt(e)/100).toFixed(2)}`},currencySymbol:function(e){switch(e=String(e).toLowerCase(),String(e).toLowerCase()){case"gbp":return"£";case"eur":return"€";default:return"$"}},getAvailableCurrencies:function(e){var r=[];if(r.push({name:`USD (${u.currencySymbol("usd")})`,value:"usd",countryCode:{US:!0}}),r.push({name:`GBP (${u.currencySymbol("gbp")})`,value:"gbp",countryCode:{GB:!0,UK:!0}}),r.push({name:`CAD (${u.currencySymbol("cad")})`,value:"cad",countryCode:{CA:!0}}),r.push({name:`AUD (${u.currencySymbol("aud")})`,value:"aud",countryCode:{AU:!0}}),r.push({name:`NZD (${u.currencySymbol("nzd")})`,value:"nzd",countryCode:{NZ:!0}}),r.push({name:`SGD (${u.currencySymbol("sgd")})`,value:"sgd",countryCode:{SG:!0}}),e){var t=r.findIndex((function(r){return r.countryCode[e]}));const n=(e,r,t)=>{const n=[...e];return n.splice(t,0,...n.splice(r,1)),n};-1!=t&&(r=n(r,t,0))}return r},hash:function(e,t){return Array.isArray(e)||(e=[]),e.reduce((function(e,t){var n=r.get(t,n);return e[n]=t,e}),{})},guid:function(){var e=(new Date).getTime().toString(16)+Math.random().toString(16).substring(2)+"0".repeat(16);return e.substr(0,8)+"-"+e.substr(8,4)+"-4000-8"+e.substr(12,3)+"-"+e.substr(15,12)},extractFromArray:function(e,t,n,o,i,a,s){s||(s={}),n&&(s.sum=n),o&&(s.flatten=!0),i&&(s.unique=!0),a&&(s.excludeNull=!0);var u=r.reduce(e,(function(e,n){var o=r.get(n,t),i=!o&&!1!==o&&0!==o;return s.excludeNull&&i||e.push(o),e}),[]);return s.flatten&&(u=r.flatten(u)),s.unique&&(u=r.uniq(u)),s.sum&&(u=u.reduce((function(e,r){return e+r}),0)),u},matchInArray:function(e,t,n,o){return r.filter(e,(function(e){var i,a=r.get(e,t);switch(o){case">":i=a>n;break;case"<":i=a<n;break;case">=":i=a>=n;break;case"<=":i=a<=n;break;case"in":i=r.includes(a,n);break;default:i=void 0===n?a:a==n}return i}))},comma:function(e,t,n){return n&&(e=e.slice(0,n)),r.chain(e).compact().map((function(e){return t&&t.length?r.get(e,t):e})).value().join(", ")},id:function(e){var r;if(e&&(r=e._id?String(e._id):String(e),service.isValidID(r)))return r},ids:function(e){return r.chain(e).reduce((function(e,r){if(!r)return e;var t=service.id(r);return t&&(e[t]=1),e}),{}).keys().value()},isValidID:function(e){return new RegExp("^[0-9a-fA-F]{24}$").test(String(e))},errorMessage:function(e){r.isArray(e)&&(e=r.first(e));var t=r.chain(["response.data.message","response.data","message"]).map((function(t){return r.get(e,t)})).compact().first().value();return Array.isArray(t)&&(t=t[0]),t&&t.length?t:String(e)},machineName:function(e){if(e&&e.length)return e.replace(/[^a-zA-Z0-9-_]+/g,"")}};const c=u;function l(){var e={},r={removeAllListeners:function(){e={}},dispatch:function(r,t){e[r]&&e[r].forEach((function(e){return e(t)}))},addEventListener:function(r,t){e[r]||(e[r]=[]),-1==e[r].indexOf(t)&&e[r].push(t)},removeEventListener:function(r,t){e[r]||(e[r]=[]);var n=e[r].indexOf(t);-1!=n&&e[r].splice(n,1)},bootstrap:function(e){e&&(e.dispatch=r.dispatch,e.addEventListener=r.addEventListener,e.removeEventListener=r.removeEventListener,e.removeAllListeners=r.removeAllListeners)}};return r}const f=function(e){if(!e.api)throw new Error("Can't Instantiate QikAuth before QikAPI exists");var t={},n={debug:!1};Object.defineProperty(n,"store",{value:t,writable:!1});var o=new l;function i(e){var r=t.user;n.onChange&&n.onChange(r),o.dispatch("change",r,e)}function a(e){n.debug&&console.log(e)}o.bootstrap(n),n.set=function(e,r,n){return t.user=e,a("qik.auth > user set"),i(r)},n.logout=function(){return delete t.user,e.cache.reset(),a("qik.auth > user logout"),e.withCredentials&&(window.location.href="/qik/logout"),i()},n.changeOrganisation=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/switch/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.impersonate=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/impersonate/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.login=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"Missing credentials!"});if(!r.email||!r.email.length)return s({message:"Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});var u=`${e.apiURL}/user/login`;n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.signup=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"No details provided"});if(!r.firstName||!r.firstName.length)return s({message:"First Name was not provided"});if(!r.lastName||!r.lastName.length)return s({message:"Last Name was not provided"});if(!r.email||!r.email.length)return s({message:"Email/Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});if(!r.confirmPassword||!r.confirmPassword.length)return s({message:"Confirm Password was not provided"});if(r.confirmPassword!=r.password)return s({message:"Your passwords do not match"});var u=`${e.apiURL}/user/signup`;n.application&&(u=`${e.domain||""}/qik/application/signup`),n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.retrieveUserFromResetToken=function(r,t){return t||(t={}),new Promise((function(n,o){var i=`${e.apiURL}/user/reset/${r}`;t.url&&(i=t.url),e.api.get(i,{bypassInterceptor:!0}).then((function(e){return n(e.data)}),o)}))},n.updateUserWithToken=function(r,t,o){o||(o={});var i=!0;return o.disableAutoAuthentication&&(i=!1),new Promise((function(a,s){var u=`${e.apiURL}/user/reset/${r}`;o.url&&(u=o.url),e.api.post(u,t,{bypassInterceptor:!0}).then((function(r){return i&&(e.cache.reset(),n.set(r.data)),a(r.data)}),s)}))},n.sendResetPasswordRequest=function(r,t){return t||(t={}),new Promise((function(n,o){if(!r)return o({message:"No details provided"});if(!r.email||!r.email.length)return o({message:"Email was not provided"});r.email=r.email;var i=`${e.apiURL}/user/forgot`;t.url&&(i=t.url),e.api.post(i,r,{bypassInterceptor:!0}).then(n,o)}))};const s={};return n.refreshAccessToken=function(r){return s.inflightRefreshRequest?(a("qik.auth > use inflight request"),s.inflightRefreshRequest):(a("qik.auth > refresh token new request"),s.inflightRefreshRequest=new Promise((function(n,o){a(`qik.auth > refresh token ${r}`),e.api.post("/user/refresh",{refreshToken:r},{bypassInterceptor:!0}).then((function(e){if(!e)return a("qik.auth > no res"),s.inflightRefreshRequest=null,o();t.user?Object.assign(t.user,e.data):t.user=e.data,a(`qik.auth > token refreshed > ${e.data}`),i(),n(e.data.token),setTimeout((function(){s.inflightRefreshRequest=null}))})).catch((function(e){console.log("TOKEN REFRESH FAILED",e),setTimeout((function(){s.inflightRefreshRequest=null})),o(e)}))})),s.inflightRefreshRequest)},n.sync=function(){return e.api.get("/user").then((function(e){e.data?t.user&&Object.assign(t.user,e.data):t.user=null,a("qik.auth > server session refreshed"),i()})).catch((function(e){console.log("auth sync not logged in"),t.user=null,i()}))},n.getCurrentUser=function(){return t.user},n.getCurrentToken=function(){return n.getCurrentUser().accessToken},e.api.interceptors.request.use((function(e){if(e.bypassInterceptor)return console.log("auth interceptor was bypassed"),e;var o=e,i=r.get(t,"user.accessToken"),s=r.get(t,"user.refreshToken");if(!i)return a("qik.auth > no token"),o;if(o.headers.Authorization=`Bearer ${i}`,a("qik.auth > using user token"),!s)return a("qik.auth > no refresh token"),o;var u=new Date;u.setSeconds(u.getSeconds()+10);var c=r.get(t,"user.expires");return u<new Date(c)?o:(a("qik.auth > token expired"),new Promise((function(e,r){n.refreshAccessToken(s).then((function(r){return a("qik.auth > token refreshed",isManagedUser),o.headers.Authorization=`Bearer ${r}`,e(o)})).catch((function(e){return console.log("ERRRRRR",e),a("qik.auth > token refresh rejected"),r(e)}))})))}),(function(e){return Promise.reject(e)})),e.api.interceptors.response.use((function(e){return e}),(function(e){var t=r.get(e,"response.status")||e.status;return a("qik.auth > error"),401===t&&(console.log("logout from 401"),n.logout()),Promise.reject(e)})),n};var p={};const d={reset(){r.each(p,(function(e,r){e.reset()}))},get:(e,r)=>(p[e]||(p[e]=new n.Cache(r)),p[e])},h=function(e){if(!e.auth)throw new Error("Can't Instantiate QikAccess before QikAccess has been initialized");var t={};return(new l).bootstrap(t),t.has=function(e,n){var o=t.retrieveCurrentSession(n);if(!o)return!1;if(t.isQikAdmin()&&!n)return!0;var i=o.permissionSets,a=r.chain(i).reduce((function(e,r,t){return e.push(r.permissions),e}),[]).flattenDeep().compact().uniq().value();return r.includes(a,e)},t};console.log("qik 0.1.0");const g=function(e){switch(e||(e={}),e.apiURL&&e.apiURL.length||(e.apiURL="staging"),String(e.apiURL).toLowerCase()){case"production":e.apiURL="https://api.qik.dev";break;case"staging":e.apiURL="https://api.staging.qik.dev";break;case"local":e.apiURL="http://localhost:4001"}var r=Object.assign(e,{version:"0.1.0"}),t=d;Object.defineProperty(r,"cache",{value:t,writable:!1});var n=c;Object.defineProperty(r,"utils",{value:n,writable:!1}),(new l).bootstrap(r),r.error=function(e){return r.dispatch("error",n.errorMessage(e))},r.notify=function(e,t){return r.dispatch("notification",{message:e,options:t})};var o=new s(r);Object.defineProperty(r,"api",{value:o,writable:!1});var i=new f(r);Object.defineProperty(r,"auth",{value:i,writable:!1});var a=new h(r);return Object.defineProperty(r,"access",{value:a,writable:!1}),r}})(),a})()}));
1
+ !function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("axios"),require("lodash"),require("axios-extensions")):"function"==typeof define&&define.amd?define(["axios","lodash","axios-extensions"],r):"object"==typeof exports?exports["@qikdev/sdk"]=r(require("axios"),require("lodash"),require("axios-extensions")):e["@qikdev/sdk"]=r(e.axios,e._,e["axios-extensions"])}("undefined"!=typeof self?self:this,(function(e,r,t){return(()=>{"use strict";var n={818:(e,r)=>{var t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};"undefined"!=typeof window&&window.document,"object"===("undefined"==typeof self?"undefined":t(self))&&self.constructor&&self.constructor.name,"undefined"!=typeof process&&null!=process.versions&&process.versions.node},798:e=>{var r=String.prototype.replace,t=/%20/g;e.exports={default:"RFC3986",formatters:{RFC1738:function(e){return r.call(e,t,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:"RFC3986"}},129:(e,r,t)=>{var n=t(261),o=t(235),i=t(798);e.exports={formats:i,parse:o,stringify:n}},235:(e,r,t)=>{var n=t(769),o=Object.prototype.hasOwnProperty,i={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:n.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},a=function(e,r,t){if(e){var n=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,a=/(\[[^[\]]*])/.exec(n),s=a?n.slice(0,a.index):n,u=[];if(s){if(!t.plainObjects&&o.call(Object.prototype,s)&&!t.allowPrototypes)return;u.push(s)}for(var c=0;null!==(a=i.exec(n))&&c<t.depth;){if(c+=1,!t.plainObjects&&o.call(Object.prototype,a[1].slice(1,-1))&&!t.allowPrototypes)return;u.push(a[1])}return a&&u.push("["+n.slice(a.index)+"]"),function(e,r,t){for(var n=r,o=e.length-1;o>=0;--o){var i,a=e[o];if("[]"===a&&t.parseArrays)i=[].concat(n);else{i=t.plainObjects?Object.create(null):{};var s="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,u=parseInt(s,10);t.parseArrays||""!==s?!isNaN(u)&&a!==s&&String(u)===s&&u>=0&&t.parseArrays&&u<=t.arrayLimit?(i=[])[u]=n:"__proto__"!==s&&(i[s]=n):i={0:n}}n=i}return n}(u,r,t)}};e.exports=function(e,r){var t=r?n.assign({},r):{};if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(t.ignoreQueryPrefix=!0===t.ignoreQueryPrefix,t.delimiter="string"==typeof t.delimiter||n.isRegExp(t.delimiter)?t.delimiter:i.delimiter,t.depth="number"==typeof t.depth?t.depth:i.depth,t.arrayLimit="number"==typeof t.arrayLimit?t.arrayLimit:i.arrayLimit,t.parseArrays=!1!==t.parseArrays,t.decoder="function"==typeof t.decoder?t.decoder:i.decoder,t.allowDots="boolean"==typeof t.allowDots?t.allowDots:i.allowDots,t.plainObjects="boolean"==typeof t.plainObjects?t.plainObjects:i.plainObjects,t.allowPrototypes="boolean"==typeof t.allowPrototypes?t.allowPrototypes:i.allowPrototypes,t.parameterLimit="number"==typeof t.parameterLimit?t.parameterLimit:i.parameterLimit,t.strictNullHandling="boolean"==typeof t.strictNullHandling?t.strictNullHandling:i.strictNullHandling,""===e||null==e)return t.plainObjects?Object.create(null):{};for(var s="string"==typeof e?function(e,r){for(var t={},n=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,a=r.parameterLimit===1/0?void 0:r.parameterLimit,s=n.split(r.delimiter,a),u=0;u<s.length;++u){var c,l,f=s[u],p=f.indexOf("]="),d=-1===p?f.indexOf("="):p+1;-1===d?(c=r.decoder(f,i.decoder),l=r.strictNullHandling?null:""):(c=r.decoder(f.slice(0,d),i.decoder),l=r.decoder(f.slice(d+1),i.decoder)),o.call(t,c)?t[c]=[].concat(t[c]).concat(l):t[c]=l}return t}(e,t):e,u=t.plainObjects?Object.create(null):{},c=Object.keys(s),l=0;l<c.length;++l){var f=c[l],p=a(f,s[f],t);u=n.merge(u,p,t)}return n.compact(u)}},261:(e,r,t)=>{var n=t(769),o=t(798),i={brackets:function(e){return e+"[]"},indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},a=Array.isArray,s=Array.prototype.push,u=function(e,r){s.apply(e,a(r)?r:[r])},c=Date.prototype.toISOString,l={delimiter:"&",encode:!0,encoder:n.encode,encodeValuesOnly:!1,serializeDate:function(e){return c.call(e)},skipNulls:!1,strictNullHandling:!1},f=function e(r,t,o,i,s,c,f,p,d,h,g,y){var m=r;if("function"==typeof f?m=f(t,m):m instanceof Date&&(m=h(m)),null===m){if(i)return c&&!y?c(t,l.encoder):t;m=""}if("string"==typeof m||"number"==typeof m||"boolean"==typeof m||n.isBuffer(m))return c?[g(y?t:c(t,l.encoder))+"="+g(c(m,l.encoder))]:[g(t)+"="+g(String(m))];var v,b=[];if(void 0===m)return b;if(a(f))v=f;else{var w=Object.keys(m);v=p?w.sort(p):w}for(var k=0;k<v.length;++k){var j=v[k];s&&null===m[j]||(a(m)?u(b,e(m[j],o(t,j),o,i,s,c,f,p,d,h,g,y)):u(b,e(m[j],t+(d?"."+j:"["+j+"]"),o,i,s,c,f,p,d,h,g,y)))}return b};e.exports=function(e,r){var t=e,s=r?n.assign({},r):{};if(null!==s.encoder&&void 0!==s.encoder&&"function"!=typeof s.encoder)throw new TypeError("Encoder has to be a function.");var c=void 0===s.delimiter?l.delimiter:s.delimiter,p="boolean"==typeof s.strictNullHandling?s.strictNullHandling:l.strictNullHandling,d="boolean"==typeof s.skipNulls?s.skipNulls:l.skipNulls,h="boolean"==typeof s.encode?s.encode:l.encode,g="function"==typeof s.encoder?s.encoder:l.encoder,y="function"==typeof s.sort?s.sort:null,m=void 0!==s.allowDots&&s.allowDots,v="function"==typeof s.serializeDate?s.serializeDate:l.serializeDate,b="boolean"==typeof s.encodeValuesOnly?s.encodeValuesOnly:l.encodeValuesOnly;if(void 0===s.format)s.format=o.default;else if(!Object.prototype.hasOwnProperty.call(o.formatters,s.format))throw new TypeError("Unknown format option provided.");var w,k,j=o.formatters[s.format];"function"==typeof s.filter?t=(k=s.filter)("",t):a(s.filter)&&(w=k=s.filter);var A,O=[];if("object"!=typeof t||null===t)return"";A=s.arrayFormat in i?s.arrayFormat:"indices"in s?s.indices?"indices":"repeat":"indices";var R=i[A];w||(w=Object.keys(t)),y&&w.sort(y);for(var q=0;q<w.length;++q){var x=w[q];d&&null===t[x]||u(O,f(t[x],x,R,p,d,h?g:null,k,y,m,v,j,b))}var S=O.join(c),P=!0===s.addQueryPrefix?"?":"";return S.length>0?P+S:""}},769:e=>{var r=Object.prototype.hasOwnProperty,t=function(){for(var e=[],r=0;r<256;++r)e.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return e}(),n=function(e,r){for(var t=r&&r.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t};e.exports={arrayToObject:n,assign:function(e,r){return Object.keys(r).reduce((function(e,t){return e[t]=r[t],e}),e)},compact:function(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],i=o.obj[o.prop],a=Object.keys(i),s=0;s<a.length;++s){var u=a[s],c=i[u];"object"==typeof c&&null!==c&&-1===t.indexOf(c)&&(r.push({obj:i,prop:u}),t.push(c))}return function(e){for(var r;e.length;){var t=e.pop();if(r=t.obj[t.prop],Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}return r}(r)},decode:function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(r){return e}},encode:function(e){if(0===e.length)return e;for(var r="string"==typeof e?e:String(e),n="",o=0;o<r.length;++o){var i=r.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?n+=r.charAt(o):i<128?n+=t[i]:i<2048?n+=t[192|i>>6]+t[128|63&i]:i<55296||i>=57344?n+=t[224|i>>12]+t[128|i>>6&63]+t[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&r.charCodeAt(o)),n+=t[240|i>>18]+t[128|i>>12&63]+t[128|i>>6&63]+t[128|63&i])}return n},isBuffer:function(e){return null!=e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},merge:function e(t,o,i){if(!o)return t;if("object"!=typeof o){if(Array.isArray(t))t.push(o);else{if(!t||"object"!=typeof t)return[t,o];(i&&(i.plainObjects||i.allowPrototypes)||!r.call(Object.prototype,o))&&(t[o]=!0)}return t}if(!t||"object"!=typeof t)return[t].concat(o);var a=t;return Array.isArray(t)&&!Array.isArray(o)&&(a=n(t,i)),Array.isArray(t)&&Array.isArray(o)?(o.forEach((function(n,o){if(r.call(t,o)){var a=t[o];a&&"object"==typeof a&&n&&"object"==typeof n?t[o]=e(a,n,i):t.push(n)}else t[o]=n})),t):Object.keys(o).reduce((function(t,n){var a=o[n];return r.call(t,n)?t[n]=e(t[n],a,i):t[n]=a,t}),a)}}},103:r=>{r.exports=e},757:e=>{e.exports=t},607:e=>{e.exports=r}},o={};function i(e){var r=o[e];if(void 0!==r)return r.exports;var t=o[e]={exports:{}};return n[e](t,t.exports,i),t.exports}i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{i.r(a),i.d(a,{default:()=>y});var e=i(103),r=i(607),t=i(129);const n="0.1.8";var o=i(757);const s=e.CancelToken,u=function(o){var i;process.browser&&(i=o.cache.get("api"));const a=e.defaults.adapter,u=(c=function(r){return new Promise((function(t,n){var o,s;switch(String(r.method).toLowerCase()){case"post":case"patch":case"put":case"delete":r.cache||(r.cache=!1)}if(!1===r.cache);else if(o=r.cache||i){var u=getCacheKeyFromConfig(r);s=o.get(u)}return s?t(s):(Object.assign(r,{adapter:a}),e.request(r).then((function(e){t(e)}),(function(e){n(e)})))}))},(l=e.create({paramsSerializer:e=>t.stringify(e,{arrayFormat:"repeat"}),adapter:c})).defaults.baseURL=o.apiURL,l.defaults.headers.common.Accept="application/json",l.interceptors.request.use((function(e){return e.headers["qik-request-date"]=(new Date).getTime(),Intl&&(e.headers["qik-request-timezone"]=Intl.DateTimeFormat().resolvedOptions().timeZone),e.headers["qik-api-version"]=n,e})),l.interceptors.response.use((function(e){return e.config,e}),(function(t){if(e.isCancel(t))return console.log("Request cancelled"),Promise.reject(t);var n=r.get(t,"response.status")||t.status;switch(n){case 401:case 404:break;case 502:case 504:return console.log(`qik.api > ${n} connection error retrying`),l.request(t.config);default:console.log("qik.api > connection error",n,t)}return Promise.reject(t)})),l);var c,l;return u.generateEndpointURL=function(e,r){if(e&&String(e).length){r||(r={});var t=`${o.apiURL}${e}`;t=function(e,r){if(!r.withoutToken){var t=o.auth.getCurrentToken();!r.access_token&&t&&(r.access_token=t)}return e}(t,r);var n=o.utils.mapParameters(r);return n.length&&(t+="?"+n),t}},u.CancelToken=s,u.axios=e,u};i(818);var c={mapParameters:function(e){return r.chain(e).reduce((function(e,t,n){return null==t||!1===t||(r.isArray(t)?r.each(t,(function(r){e.push(`${n}=${encodeURIComponent(r)}`)})):e.push(encodeURIComponent(n)+"="+encodeURIComponent(t))),e}),[]).compact().value().join("&")},formatCurrency:function(e,r){return e&&!isNaN(e)||(e=0),`${c.currencySymbol(r)}${parseFloat(parseInt(e)/100).toFixed(2)}`},currencySymbol:function(e){switch(e=String(e).toLowerCase(),String(e).toLowerCase()){case"gbp":return"£";case"eur":return"€";default:return"$"}},getAvailableCurrencies:function(e){var r=[];if(r.push({name:`USD (${c.currencySymbol("usd")})`,value:"usd",countryCode:{US:!0}}),r.push({name:`GBP (${c.currencySymbol("gbp")})`,value:"gbp",countryCode:{GB:!0,UK:!0}}),r.push({name:`CAD (${c.currencySymbol("cad")})`,value:"cad",countryCode:{CA:!0}}),r.push({name:`AUD (${c.currencySymbol("aud")})`,value:"aud",countryCode:{AU:!0}}),r.push({name:`NZD (${c.currencySymbol("nzd")})`,value:"nzd",countryCode:{NZ:!0}}),r.push({name:`SGD (${c.currencySymbol("sgd")})`,value:"sgd",countryCode:{SG:!0}}),e){var t=r.findIndex((function(r){return r.countryCode[e]}));const n=(e,r,t)=>{const n=[...e];return n.splice(t,0,...n.splice(r,1)),n};-1!=t&&(r=n(r,t,0))}return r},hash:function(e,t){return Array.isArray(e)||(e=[]),e.reduce((function(e,t){var n=r.get(t,n);return e[n]=t,e}),{})},guid:function(){var e=(new Date).getTime().toString(16)+Math.random().toString(16).substring(2)+"0".repeat(16);return e.substr(0,8)+"-"+e.substr(8,4)+"-4000-8"+e.substr(12,3)+"-"+e.substr(15,12)},extractFromArray:function(e,t,n,o,i,a,s){s||(s={}),n&&(s.sum=n),o&&(s.flatten=!0),i&&(s.unique=!0),a&&(s.excludeNull=!0);var u=r.reduce(e,(function(e,n){var o=r.get(n,t),i=!o&&!1!==o&&0!==o;return s.excludeNull&&i||e.push(o),e}),[]);return s.flatten&&(u=r.flatten(u)),s.unique&&(u=r.uniq(u)),s.sum&&(u=u.reduce((function(e,r){return e+r}),0)),u},matchInArray:function(e,t,n,o){return r.filter(e,(function(e){var i,a=r.get(e,t);switch(o){case">":i=a>n;break;case"<":i=a<n;break;case">=":i=a>=n;break;case"<=":i=a<=n;break;case"in":i=r.includes(a,n);break;default:i=void 0===n?a:a==n}return i}))},comma:function(e,t,n){return n&&(e=e.slice(0,n)),r.chain(e).compact().map((function(e){return t&&t.length?r.get(e,t):e})).value().join(", ")},id:function(e){var r;if(e&&(r=e._id?String(e._id):String(e),service.isValidID(r)))return r},ids:function(e){return r.chain(e).reduce((function(e,r){if(!r)return e;var t=service.id(r);return t&&(e[t]=1),e}),{}).keys().value()},isValidID:function(e){return new RegExp("^[0-9a-fA-F]{24}$").test(String(e))},errorMessage:function(e){r.isArray(e)&&(e=r.first(e));var t=r.chain(["response.data.message","response.data","message"]).map((function(t){return r.get(e,t)})).compact().first().value();return Array.isArray(t)&&(t=t[0]),t&&t.length?t:String(e)},machineName:function(e){if(e&&e.length)return e.replace(/[^a-zA-Z0-9-_]+/g,"")}};const l=c;function f(){var e={},r={removeAllListeners:function(){e={}},dispatch:function(r,t){e[r]&&e[r].forEach((function(e){return e(t)}))},addEventListener:function(r,t){e[r]||(e[r]=[]),-1==e[r].indexOf(t)&&e[r].push(t)},removeEventListener:function(r,t){e[r]||(e[r]=[]);var n=e[r].indexOf(t);-1!=n&&e[r].splice(n,1)},bootstrap:function(e){e&&(e.dispatch=r.dispatch,e.addEventListener=r.addEventListener,e.removeEventListener=r.removeEventListener,e.removeAllListeners=r.removeAllListeners)}};return r}const p=function(e){if(!e.api)throw new Error("Can't Instantiate QikAuth before QikAPI exists");var t={},n={debug:!1};Object.defineProperty(n,"store",{value:t,writable:!1});var o=new f;function i(e){var r=t.user;n.onChange&&n.onChange(r),o.dispatch("change",r,e)}function a(e){n.debug&&console.log(e)}o.bootstrap(n),n.set=function(e,r,n){return t.user=e,a("qik.auth > user set"),i(r)},n.logout=function(){return delete t.user,e.cache.reset(),a("qik.auth > user logout"),e.withCredentials&&(window.location.href="/qik/logout"),i()},n.changeOrganisation=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/switch/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.impersonate=function(r,t){r=e.utils.getStringID(r),t||(t={});var o=!0;t.disableAutoAuthentication&&(o=!1);var i=e.api.post(`/user/impersonate/${r}`);return i.then((function(r){o&&(e.cache.reset(),n.set(r.data))}),(function(e){})),i},n.login=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"Missing credentials!"});if(!r.email||!r.email.length)return s({message:"Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});var u=`${e.apiURL}/user/login`;n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.signup=function(r,n){n||(n={});var o=!0;return n.disableAutoAuthentication&&(o=!1),new Promise((function(a,s){if(!r)return s({message:"No details provided"});if(!r.firstName||!r.firstName.length)return s({message:"First Name was not provided"});if(!r.lastName||!r.lastName.length)return s({message:"Last Name was not provided"});if(!r.email||!r.email.length)return s({message:"Email/Username was not provided"});if(!r.password||!r.password.length)return s({message:"Password was not provided"});if(!r.confirmPassword||!r.confirmPassword.length)return s({message:"Confirm Password was not provided"});if(r.confirmPassword!=r.password)return s({message:"Your passwords do not match"});var u=`${e.apiURL}/user/signup`;n.application&&(u=`${e.domain||""}/qik/application/signup`),n.url&&(u=n.url),e.api.post(u,r,{bypassInterceptor:!0}).then((function(e){o&&(t.user=e.data,i()),a(e)}),s)}))},n.retrieveUserFromResetToken=function(r,t){return t||(t={}),new Promise((function(n,o){var i=`${e.apiURL}/user/reset/${r}`;t.url&&(i=t.url),e.api.get(i,{bypassInterceptor:!0}).then((function(e){return n(e.data)}),o)}))},n.updateUserWithToken=function(r,t,o){o||(o={});var i=!0;return o.disableAutoAuthentication&&(i=!1),new Promise((function(a,s){var u=`${e.apiURL}/user/reset/${r}`;o.url&&(u=o.url),e.api.post(u,t,{bypassInterceptor:!0}).then((function(r){return i&&(e.cache.reset(),n.set(r.data)),a(r.data)}),s)}))},n.sendResetPasswordRequest=function(r,t){return t||(t={}),new Promise((function(n,o){if(!r)return o({message:"No details provided"});if(!r.email||!r.email.length)return o({message:"Email was not provided"});r.email=r.email;var i=`${e.apiURL}/user/forgot`;t.url&&(i=t.url),e.api.post(i,r,{bypassInterceptor:!0}).then(n,o)}))};const s={};return n.refreshAccessToken=function(r){return s.inflightRefreshRequest?(a("qik.auth > use inflight request"),s.inflightRefreshRequest):(a("qik.auth > refresh token new request"),s.inflightRefreshRequest=new Promise((function(n,o){a(`qik.auth > refresh token ${r}`),e.api.post("/user/refresh",{refreshToken:r},{bypassInterceptor:!0}).then((function(e){if(!e)return a("qik.auth > no res"),s.inflightRefreshRequest=null,o();t.user?Object.assign(t.user,e.data):t.user=e.data,a(`qik.auth > token refreshed > ${e.data}`),i(),n(e.data.token),setTimeout((function(){s.inflightRefreshRequest=null}))})).catch((function(e){console.log("TOKEN REFRESH FAILED",e),setTimeout((function(){s.inflightRefreshRequest=null})),o(e)}))})),s.inflightRefreshRequest)},n.sync=function(){return e.api.get("/user").then((function(e){e.data?t.user&&Object.assign(t.user,e.data):t.user=null,a("qik.auth > server session refreshed"),i()})).catch((function(e){console.log("auth sync not logged in"),t.user=null,i()}))},n.getCurrentUser=function(){return t.user},n.getCurrentToken=function(){return n.getCurrentUser().accessToken},e.api.interceptors.request.use((function(e){if(e.bypassInterceptor)return console.log("auth interceptor was bypassed"),e;var o=e,i=r.get(t,"user.accessToken"),s=r.get(t,"user.refreshToken");if(!i)return a("qik.auth > no token"),o;if(o.headers.Authorization=`Bearer ${i}`,a("qik.auth > using user token"),!s)return a("qik.auth > no refresh token"),o;var u=new Date;u.setSeconds(u.getSeconds()+10);var c=r.get(t,"user.expires");return u<new Date(c)?o:(a("qik.auth > token expired"),new Promise((function(e,r){n.refreshAccessToken(s).then((function(r){return a("qik.auth > token refreshed",isManagedUser),o.headers.Authorization=`Bearer ${r}`,e(o)})).catch((function(e){return console.log("ERRRRRR",e),a("qik.auth > token refresh rejected"),r(e)}))})))}),(function(e){return Promise.reject(e)})),e.api.interceptors.response.use((function(e){return e}),(function(e){var t=r.get(e,"response.status")||e.status;return a("qik.auth > error"),401===t&&(console.log("logout from 401"),n.logout()),Promise.reject(e)})),n};var d={};const h={reset(){r.each(d,(function(e,r){e.reset()}))},get:(e,r)=>(d[e]||(d[e]=new o.Cache(r)),d[e])},g=function(e){if(!e.auth)throw new Error("Can't Instantiate QikAccess before QikAccess has been initialized");var t={};return(new f).bootstrap(t),t.has=function(e,n){var o=t.retrieveCurrentSession(n);if(!o)return!1;if(t.isQikAdmin()&&!n)return!0;var i=o.permissionSets,a=r.chain(i).reduce((function(e,r,t){return e.push(r.permissions),e}),[]).flattenDeep().compact().uniq().value();return r.includes(a,e)},t};console.log("qik 0.1.8");const y=class{constructor(e){switch(e||(e={}),e.apiURL&&e.apiURL.length||(e.apiURL="staging"),String(e.apiURL).toLowerCase()){case"production":e.apiURL="https://api.qik.dev";break;case"staging":e.apiURL="https://api.staging.qik.dev";break;case"local":e.apiURL="http://localhost:4001"}const r=Object.assign(e,{version:n});console.log("Instantiate class",r);var t=h;Object.defineProperty(r,"cache",{value:t,writable:!1});var o=l;Object.defineProperty(r,"utils",{value:o,writable:!1}),(new f).bootstrap(r),r.error=function(e){return r.dispatch("error",o.errorMessage(e))},r.notify=function(e,t){return r.dispatch("notification",{message:e,options:t})};var i=new u(r);Object.defineProperty(r,"api",{value:i,writable:!1});var a=new p(r);Object.defineProperty(r,"auth",{value:a,writable:!1});var s=new g(r);return Object.defineProperty(r,"access",{value:s,writable:!1}),r}}})(),a})()}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qikdev/sdk",
3
- "version": "0.1.4",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "Promise based Javascript SDK",
6
6
  "scripts": {
@@ -35,140 +35,138 @@ import { EventDispatcher } from './qik.utils.js';
35
35
  * //Use the QikAsset package to generate an image url
36
36
  * var link = qik.asset.imageUrl('5ca3d64dd2bb085eb9d450db', 1920, 1080)
37
37
  */
38
- var QikCore = function(options) {
39
-
40
- if (!options) {
41
- options = {
42
- // apiURL,
43
- // applicationToken,
44
- // api:{}
45
- };
46
- }
47
-
48
- ///////////////////////////////////////
49
-
50
- if (!options.apiURL || !options.apiURL.length) {
51
- options.apiURL = 'staging';
52
- }
53
38
 
54
- ///////////////////////////////////////
55
-
56
- switch (String(options.apiURL).toLowerCase()) {
57
- case 'production':
58
- options.apiURL = 'https://api.qik.dev';
59
- break;
60
- case 'staging':
61
- options.apiURL = 'https://api.staging.qik.dev';
62
- break;
63
- case 'local':
64
- options.apiURL = 'http://localhost:4001';
65
- break;
66
- }
67
-
68
- ///////////////////////////////////////
69
-
70
- var core = Object.assign(options, {
71
- //Other options
72
- // domain:'',
73
- version:'0.1.0',
74
- })
75
-
76
-
77
-
78
- ///////////////////////////////////////
79
-
80
- /**
81
- * Provides a cache service, used for creating, clearing
82
- * and storing API requests and other information in memory
83
- * @type {QikCache}
84
- */
85
- var cache = QikCache;
86
- Object.defineProperty(core, 'cache', {
87
- value: cache,
88
- writable: false,
89
- });
90
- ///////////////////////////////////////
91
-
92
- /**
93
- * Provides helper functions for working
94
- * with Qik data
95
- * @type {QikUtils}
96
- */
97
- var utils = QikUtils;
98
- Object.defineProperty(core, 'utils', {
99
- value: utils,
100
- writable: false,
101
- });
102
-
103
- ///////////////////////////////////////
104
-
105
- //Create a new global dispatcher so we can trigger events
106
- var dispatcher = new EventDispatcher();
107
- dispatcher.bootstrap(core);
108
-
109
- //Set the function
110
- core.error = function(err) {
111
- //Dispatch an error event
112
- return core.dispatch('error', utils.errorMessage(err));
113
- }
39
+ import {version} from '../version.js';
40
+
41
+
42
+ export default class QikCore {
43
+ constructor(options) {
44
+ if (!options) {
45
+ options = {
46
+ // apiURL,
47
+ // applicationToken,
48
+ // api:{}
49
+ }
50
+ }
51
+
52
+ ///////////////////////////////////////
53
+
54
+ if (!options.apiURL || !options.apiURL.length) {
55
+ options.apiURL = 'staging';
56
+ }
57
+
58
+ ///////////////////////////////////////
59
+
60
+ switch (String(options.apiURL).toLowerCase()) {
61
+ case 'production':
62
+ options.apiURL = 'https://api.qik.dev';
63
+ break;
64
+ case 'staging':
65
+ options.apiURL = 'https://api.staging.qik.dev';
66
+ break;
67
+ case 'local':
68
+ options.apiURL = 'http://localhost:4001';
69
+ break;
70
+ }
71
+
72
+ ///////////////////////////////////////
73
+
74
+ const core = Object.assign(options, {
75
+ //Other options
76
+ // domain:'',
77
+ version,
78
+ })
79
+
80
+
81
+ console.log('Instantiate class', core)
82
+
83
+
84
+ ///////////////////////////////////////
85
+
86
+ /**
87
+ * Provides a cache service, used for creating, clearing
88
+ * and storing API requests and other information in memory
89
+ * @type {QikCache}
90
+ */
91
+ var cache = QikCache;
92
+ Object.defineProperty(core, 'cache', {
93
+ value: cache,
94
+ writable: false,
95
+ });
96
+ ///////////////////////////////////////
97
+
98
+ /**
99
+ * Provides helper functions for working
100
+ * with Qik data
101
+ * @type {QikUtils}
102
+ */
103
+ var utils = QikUtils;
104
+ Object.defineProperty(core, 'utils', {
105
+ value: utils,
106
+ writable: false,
107
+ });
108
+
109
+ ///////////////////////////////////////
110
+
111
+ //Create a new global dispatcher so we can trigger events
112
+ var dispatcher = new EventDispatcher();
113
+ dispatcher.bootstrap(core);
114
+
115
+ //Set the function
116
+ core.error = function(err) {
117
+ //Dispatch an error event
118
+ return core.dispatch('error', utils.errorMessage(err));
119
+ }
120
+
121
+ //And enable notifications with a short message
122
+ core.notify = function(message, options) {
123
+ return core.dispatch('notification', { message, options });
124
+ }
125
+
126
+ ///////////////////////////////////////
127
+
128
+ /**
129
+ * The default service for interacting with
130
+ * the Qik REST API, it's a wrapper around the axios library
131
+ * that works in conjunction with the other Qik modules
132
+ * @type {QikAPI}
133
+ */
134
+ var api = new QikAPI(core);
135
+ Object.defineProperty(core, 'api', {
136
+ value: api,
137
+ writable: false,
138
+ });
139
+
140
+ /**
141
+ * The default service for managing authentication
142
+ * handles automatic refreshing of access tokens, and provides login, logout
143
+ * and other user/application specific functionality
144
+ * @type {QikAuth}
145
+ */
146
+ var auth = new QikAuth(core);
147
+ Object.defineProperty(core, 'auth', {
148
+ value: auth,
149
+ writable: false,
150
+ });
151
+
152
+ ///////////////////////////////////////
153
+
154
+ /**
155
+ * A helper service for understanding a user's access permissions
156
+ * @type {QikAccess}
157
+ */
158
+ var access = new QikAccess(core);
159
+ Object.defineProperty(core, 'access', {
160
+ value: access,
161
+ writable: false,
162
+ });
163
+
164
+
165
+
166
+ ///////////////////////////////////////
167
+
168
+
169
+ return core;
114
170
 
115
- //And enable notifications with a short message
116
- core.notify = function(message, options) {
117
- return core.dispatch('notification', {message, options});
118
171
  }
119
-
120
- ///////////////////////////////////////
121
-
122
- /**
123
- * The default service for interacting with
124
- * the Qik REST API, it's a wrapper around the axios library
125
- * that works in conjunction with the other Qik modules
126
- * @type {QikAPI}
127
- */
128
- var api = new QikAPI(core);
129
- Object.defineProperty(core, 'api', {
130
- value: api,
131
- writable: false,
132
- });
133
-
134
- /**
135
- * The default service for managing authentication
136
- * handles automatic refreshing of access tokens, and provides login, logout
137
- * and other user/application specific functionality
138
- * @type {QikAuth}
139
- */
140
- var auth = new QikAuth(core);
141
- Object.defineProperty(core, 'auth', {
142
- value: auth,
143
- writable: false,
144
- });
145
-
146
- ///////////////////////////////////////
147
-
148
- /**
149
- * A helper service for understanding a user's access permissions
150
- * @type {QikAccess}
151
- */
152
- var access = new QikAccess(core);
153
- Object.defineProperty(core, 'access', {
154
- value: access,
155
- writable: false,
156
- });
157
-
158
-
159
-
160
- ///////////////////////////////////////
161
-
162
-
163
- return core;
164
-
165
- }
166
-
167
- ///////////////////////////////////////
168
- ///////////////////////////////////////
169
-
170
-
171
- ///////////////////////////////////////
172
- ///////////////////////////////////////
173
-
174
- QikCore;
172
+ }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export const version = '0.1.0'
1
+ export const version = '0.1.8'