@neurosity/sdk 6.5.6 → 6.5.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.
@@ -498,7 +498,7 @@ var t=require("process");Object.defineProperty(exports,"__esModule",{value:!0}),
498
498
  },{"@firebase/firestore":"oyBH"}],"TX5A":[function(require,module,exports) {
499
499
  "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.config=void 0,exports.config={apiKey:"AIzaSyB0TkZ83Fj0CIzn8AAmE-Osc92s3ER8hy8",authDomain:"neurosity-device.firebaseapp.com",databaseURL:"https://neurosity-device.firebaseio.com",projectId:"neurosity-device",storageBucket:"neurosity-device.appspot.com",messagingSenderId:"212595049674"};
500
500
  },{}],"OERo":[function(require,module,exports) {
501
- "use strict";function e(t){return(e="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})(t)}function t(e){return i(e)||o(e)||n(e)||r()}function r(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function i(e){if(Array.isArray(e))return a(e)}function a(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 u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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,l(n.key),n)}}function f(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(t){var r=p(t,"string");return"symbol"===e(r)?r:String(r)}function p(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,r||"default");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseApp=exports.SERVER_TIMESTAMP=void 0;var b=c(require("firebase/app"));require("firebase/database"),require("firebase/auth"),require("firebase/functions"),require("firebase/firestore");var m=require("./config");exports.SERVER_TIMESTAMP=b.default.database.ServerValue.TIMESTAMP;var d=function(){function e(t){u(this,e),this.app=this.getApp(t.deviceId),this.standalone=this.app.name===t.deviceId,t.emulator&&this.connectEmulators(t)}return f(e,[{key:"getApp",value:function(e){var r=b.default.apps,n="undefined"!=typeof window&&"firebase"in window&&"apps"in window.firebase?window.firebase.apps:[],o=[].concat(t(r),t(n)).find(function(e){return"[DEFAULT]"===e.name&&e.options.databaseURL===m.config.databaseURL});if(o)return o;if(e){var i=e,a=r.find(function(e){return e.name===i});return a||b.default.initializeApp(m.config,i)}return b.default.initializeApp(m.config)}},{key:"connectEmulators",value:function(e){var t=e.emulatorHost,r=e.emulatorAuthPort,n=e.emulatorDatabasePort,o=e.emulatorFunctionsPort,i=e.emulatorFirestorePort,a=e.emulatorOptions;this.app.auth().useEmulator("http://".concat(t,":").concat(r)),this.app.database().useEmulator(t,n,a),this.app.functions().useEmulator(t,o),this.app.firestore().useEmulator(t,i,a)}},{key:"goOnline",value:function(){this.app.database().goOnline()}},{key:"goOffline",value:function(){this.app.database().goOffline()}},{key:"disconnect",value:function(){return this.standalone?this.app.delete():Promise.resolve()}}]),e}();exports.FirebaseApp=d;
501
+ "use strict";function e(t){return(e="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})(t)}function t(e){return i(e)||o(e)||n(e)||r()}function r(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function i(e){if(Array.isArray(e))return a(e)}function a(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 u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(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,l(n.key),n)}}function f(e,t,r){return t&&s(e.prototype,t),r&&s(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(t){var r=p(t,"string");return"symbol"===e(r)?r:String(r)}function p(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,r||"default");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var c=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseApp=exports.__firebase=exports.SERVER_TIMESTAMP=void 0;var b=c(require("firebase/app"));require("firebase/database"),require("firebase/auth"),require("firebase/functions"),require("firebase/firestore");var d=require("./config");exports.SERVER_TIMESTAMP=b.default.database.ServerValue.TIMESTAMP,exports.__firebase=b.default;var m=function(){function e(t){u(this,e),this.app=this.getApp(t.deviceId),this.standalone=this.app.name===t.deviceId,t.emulator&&this.connectEmulators(t)}return f(e,[{key:"getApp",value:function(e){var r=b.default.apps,n="undefined"!=typeof window&&"firebase"in window&&"apps"in window.firebase?window.firebase.apps:[],o=[].concat(t(r),t(n)).find(function(e){return"[DEFAULT]"===e.name&&e.options.databaseURL===d.config.databaseURL});if(o)return o;if(e){var i=e,a=r.find(function(e){return e.name===i});return a||b.default.initializeApp(d.config,i)}return b.default.initializeApp(d.config)}},{key:"connectEmulators",value:function(e){var t=e.emulatorHost,r=e.emulatorAuthPort,n=e.emulatorDatabasePort,o=e.emulatorFunctionsPort,i=e.emulatorFirestorePort,a=e.emulatorOptions;this.app.auth().useEmulator("http://".concat(t,":").concat(r)),this.app.database().useEmulator(t,n,a),this.app.functions().useEmulator(t,o),this.app.firestore().useEmulator(t,i,a)}},{key:"goOnline",value:function(){this.app.database().goOnline()}},{key:"goOffline",value:function(){this.app.database().goOffline()}},{key:"disconnect",value:function(){return this.standalone?this.app.delete():Promise.resolve()}}]),e}();exports.FirebaseApp=m;
502
502
  },{"firebase/app":"OJEJ","firebase/database":"Uuoh","firebase/auth":"zKjx","firebase/functions":"a7Bh","firebase/firestore":"vHL5","./config":"TX5A"}],"Cc51":[function(require,module,exports) {
503
503
  "use strict";function e(t){return(e="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})(t)}function t(e,t,r){return(t=h(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(){r=function(){return t};var t={},n=Object.prototype,i=n.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function f(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{f({},"")}catch(L){f=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var i=t&&t.prototype instanceof v?t:v,o=Object.create(i.prototype),u=new T(n||[]);return a(o,"_invoke",{value:P(e,r,u)}),o}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(L){return{type:"throw",arg:L}}}t.wrap=l;var p={};function v(){}function d(){}function m(){}var y={};f(y,u,function(){return this});var b=Object.getPrototypeOf,g=b&&b(b(D([])));g&&g!==n&&i.call(g,u)&&(y=g);var w=m.prototype=v.prototype=Object.create(y);function x(e){["next","throw","return"].forEach(function(t){f(e,t,function(e){return this._invoke(t,e)})})}function k(t,r){var n;a(this,"_invoke",{value:function(a,o){function u(){return new r(function(n,u){!function n(a,o,u,c){var s=h(t[a],t,o);if("throw"!==s.type){var f=s.arg,l=f.value;return l&&"object"==e(l)&&i.call(l,"__await")?r.resolve(l.__await).then(function(e){n("next",e,u,c)},function(e){n("throw",e,u,c)}):r.resolve(l).then(function(e){f.value=e,u(f)},function(e){return n("throw",e,u,c)})}c(s.arg)}(a,o,n,u)})}return n=n?n.then(u,u):u()}})}function P(e,t,r){var n="suspendedStart";return function(i,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw a;return I()}for(r.method=i,r.arg=a;;){var o=r.delegate;if(o){var u=j(o,r);if(u){if(u===p)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=h(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function j(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,j(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),p;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,p;var a=i.arg;return a?a.done?(t[e.resultName]=a.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):a:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function E(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function O(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function T(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function D(e){if(e){var t=e[u];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(i.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return n.next=n}}return{next:I}}function I(){return{value:void 0,done:!0}}return d.prototype=m,a(w,"constructor",{value:m,configurable:!0}),a(m,"constructor",{value:d,configurable:!0}),d.displayName=f(m,s,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,f(e,s,"GeneratorFunction")),e.prototype=Object.create(w),e},t.awrap=function(e){return{__await:e}},x(k.prototype),f(k.prototype,c,function(){return this}),t.AsyncIterator=k,t.async=function(e,r,n,i,a){void 0===a&&(a=Promise);var o=new k(l(e,r,n,i),a);return t.isGeneratorFunction(r)?o:o.next().then(function(e){return e.done?e.value:o.next()})},x(w),f(w,s,"Generator"),f(w,u,function(){return this}),f(w,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=D,T.prototype={constructor:T,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(O),!e)for(var t in this)"t"===t.charAt(0)&&i.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return o.type="throw",o.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],o=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var u=i.call(a,"catchLoc"),c=i.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=e,o.arg=t,a?(this.method="next",this.next=a.finallyLoc,p):this.complete(o)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),O(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;O(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:D(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}function n(e,t){return c(e)||u(e,t)||a(e,t)||i()}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function a(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}}function o(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 u(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,o,u=[],c=!0,s=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=a.call(r)).done)&&(u.push(n.value),u.length!==t);c=!0);}catch(f){s=!0,i=f}finally{try{if(!c&&null!=r.return&&(o=r.return(),Object(o)!==o))return}finally{if(s)throw i}}return u}}function c(e){if(Array.isArray(e))return e}function s(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function f(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,h(n.key),n)}}function l(e,t,r){return t&&f(e.prototype,t),r&&f(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function h(t){var r=p(t,"string");return"symbol"===e(r)?r:String(r)}function p(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}function v(e,t,r){return(v=d()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&m(i,r.prototype),i}).apply(null,arguments)}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}function m(e,t){return(m=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}var y=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,a){function o(e){try{c(n.next(e))}catch(t){a(t)}}function u(e){try{c(n.throw(e))}catch(t){a(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(o,u)}c((n=n.apply(e,t||[])).next())})},b=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.FirebaseUser=exports.createUser=exports.credentialWithLink=void 0;var g=require("rxjs"),w=require("rxjs/operators"),x=b(require("firebase/app")),k=x.default.database.ServerValue.TIMESTAMP;function P(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return v(x.default.User,t)}exports.credentialWithLink=x.default.auth.EmailAuthProvider.credentialWithLink,exports.createUser=P;var j=function(){function e(t){var r=this;s(this,e),this.app=t.app,this.app.auth().onAuthStateChanged(function(e){r.user=e})}return l(e,[{key:"auth",value:function(){return this.app.auth()}},{key:"createAccount",value:function(e){return y(this,void 0,void 0,r().mark(function t(){var i,a,o,u,c,s;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return i=e.email,a=e.password,t.next=3,this.app.auth().createUserWithEmailAndPassword(i,a).then(function(e){return[null,e]}).catch(function(e){return[e,null]});case 3:if(o=t.sent,u=n(o,2),c=u[0],s=u[1],!c){t.next=9;break}return t.abrupt("return",Promise.reject(c));case 9:return t.abrupt("return",s);case 10:case"end":return t.stop()}},t,this)}))}},{key:"deleteAccount",value:function(){return y(this,void 0,void 0,r().mark(function e(){var t,i,a,o,u,c,s=this;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=this.app.auth().currentUser){e.next=3;break}return e.abrupt("return",Promise.reject(new Error("You are trying to delete an account that is not authenticated. To delete an account, the account must have signed in recently.")));case 3:return e.next=5,this.getDevices().then(function(e){return[null,e]}).catch(function(e){return[e,null]});case 5:if(i=e.sent,a=n(i,2),o=a[0],u=a[1],!o){e.next=11;break}return e.abrupt("return",Promise.reject(o));case 11:if(!u.length){e.next=17;break}return e.next=14,Promise.all(u.map(function(e){return s.removeDevice(e.deviceId)})).then(function(){return null}).catch(function(e){return e});case 14:if(!(c=e.sent)){e.next=17;break}return e.abrupt("return",Promise.reject(c));case 17:return e.abrupt("return",t.delete());case 18:case"end":return e.stop()}},e,this)}))}},{key:"onAuthStateChanged",value:function(){var e=this;return new g.Observable(function(t){try{e.app.auth().onAuthStateChanged(function(e){t.next(e)},function(e){t.error(e)})}catch(r){t.error(r)}})}},{key:"onLogin",value:function(){var e=this;return new g.Observable(function(t){var r=e.app.auth().onAuthStateChanged(function(e){e&&(t.next(e),t.complete())});return function(){return r()}})}},{key:"login",value:function(e){if("customToken"in e){var t=e.customToken;return this.app.auth().signInWithCustomToken(t)}if("idToken"in e&&"providerId"in e){var r=new x.default.auth.OAuthProvider(e.providerId).credential(e.idToken);return this.app.auth().signInWithCredential(r)}if("email"in e&&"password"in e){var n=e.email,i=e.password;return this.app.auth().signInWithEmailAndPassword(n,i)}throw new Error("Either {email,password}, {customToken}, or {idToken,providerId} is required")}},{key:"logout",value:function(){return this.app.auth().signOut()}},{key:"createCustomToken",value:function(){return y(this,void 0,void 0,r().mark(function e(){var t,i,a,o;return r().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.app.functions().httpsCallable("createCustomToken")().then(function(e){return[null,e.data]}).catch(function(e){return[e,null]});case 2:if(t=e.sent,i=n(t,2),a=i[0],o=i[1],!a){e.next=8;break}return e.abrupt("return",Promise.reject(a));case 8:return e.abrupt("return",o);case 9:case"end":return e.stop()}},e,this)}))}},{key:"removeOAuthAccess",value:function(){var e;return y(this,void 0,void 0,r().mark(function t(){var i,a,o,u,c;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null===(e=this.user)||void 0===e?void 0:e.uid){t.next=3;break}return t.abrupt("return",Promise.reject("OAuth access can only be removed while logged in via OAuth."));case 3:return t.next=5,this.app.functions().httpsCallable("removeAccessOAuthApp")().then(function(e){return[null,e.data]}).catch(function(e){return[e,null]});case 5:if(i=t.sent,a=n(i,2),o=a[0],u=a[1],!o){t.next=11;break}return t.abrupt("return",Promise.reject(o));case 11:return t.next=13,this.logout().then(function(){return!1}).catch(function(e){return e});case 13:if(!(c=t.sent)){t.next=16;break}return t.abrupt("return",Promise.reject(c));case 16:return t.abrupt("return",u);case 17:case"end":return t.stop()}},t,this)}))}},{key:"getDevices",value:function(){var e;return y(this,void 0,void 0,r().mark(function t(){var n,i;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(null===(e=this.user)||void 0===e?void 0:e.uid){t.next=3;break}return t.abrupt("return",Promise.reject("Please login."));case 3:return t.next=5,this.app.database().ref(this.getUserDevicesPath()).once("value");case 5:return n=t.sent,i=n.val(),t.abrupt("return",this.userDevicesToDeviceInfoList(i));case 8:case"end":return t.stop()}},t,this)}))}},{key:"addDevice",value:function(e){var i;return y(this,void 0,void 0,r().mark(function a(){var o,u,c,s,f,l,h,p,v,d,m,y,b;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(u=null===(i=this.user)||void 0===i?void 0:i.uid){r.next=3;break}return r.abrupt("return",Promise.reject("Please login."));case 3:return r.next=5,this.getDevices().catch(function(e){console.log(e)});case 5:if(c=r.sent,!(c&&c.length&&c.map(function(e){return e.deviceId}).includes(e))){r.next=9;break}return r.abrupt("return",Promise.reject("The device is already added to this account."));case 9:return r.next=11,this.isDeviceIdValid(e).then(function(e){return[e]}).catch(function(e){return[!1,e]});case 11:if(s=r.sent,f=n(s,2),l=f[0],h=f[1],l){r.next=17;break}return r.abrupt("return",Promise.reject(h));case 17:return p=this.getDeviceClaimedByPath(e),v=this.getUserClaimedDevicePath(e),r.next=21,this.app.database().ref().update((o={},t(o,p,u),t(o,v,{claimedOn:k}),o)).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 21:if(d=r.sent,m=n(d,2),y=m[0],b=m[1],!y){r.next=27;break}return r.abrupt("return",Promise.reject(b));case 27:case"end":return r.stop()}},a,this)}))}},{key:"removeDevice",value:function(e){var t;return y(this,void 0,void 0,r().mark(function i(){var a,o,u,c,s,f,l,h;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(null===(t=this.user)||void 0===t?void 0:t.uid){r.next=3;break}return r.abrupt("return",Promise.reject("Please login."));case 3:return a=this.getDeviceClaimedByPath(e),o=this.getUserClaimedDevicePath(e),u=this.app.database().ref(a),c=this.app.database().ref(o),r.next=9,Promise.all([u.remove(),c.remove()]).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 9:if(s=r.sent,f=n(s,2),l=f[0],h=f[1],!l){r.next=15;break}return r.abrupt("return",Promise.reject(h));case 15:case"end":return r.stop()}},i,this)}))}},{key:"transferDevice",value:function(e){var t;return y(this,void 0,void 0,r().mark(function i(){var a,o,u;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(null===(t=this.user)||void 0===t?void 0:t.uid){r.next=3;break}return r.abrupt("return",Promise.reject(new Error("transferDevice: auth is required.")));case 3:if("recipientsEmail"in e||"recipientsUserId"in e){r.next=5;break}return r.abrupt("return",Promise.reject(new Error("transferDevice: either 'recipientsEmail' or 'recipientsUserId' key is required.")));case 5:if(null==e?void 0:e.deviceId){r.next=7;break}return r.abrupt("return",Promise.reject(new Error("transferDevice: a deviceId is required.")));case 7:return r.next=9,this.app.functions().httpsCallable("transferDeviceOwnership")(e).then(function(e){return[null,e.data]}).catch(function(e){return[e,null]});case 9:if(a=r.sent,o=n(a,2),u=o[0],o[1],!u){r.next=15;break}return r.abrupt("return",Promise.reject(u));case 15:case"end":return r.stop()}},i,this)}))}},{key:"isDeviceIdValid",value:function(e){return y(this,void 0,void 0,r().mark(function t(){var n,i,a,o;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=/[0-9A-Fa-f]{32}/g,e&&32===e.length&&n.test(e)){t.next=3;break}return t.abrupt("return",Promise.reject("The device id is incorrectly formatted."));case 3:return i=this.getDeviceClaimedByPath(e),a=this.app.database().ref(i),t.next=7,a.once("value").catch(function(){return null});case 7:if((o=t.sent)&&!o.exists()){t.next=10;break}return t.abrupt("return",Promise.reject("The device has already been claimed."));case 10:return t.abrupt("return",!0);case 11:case"end":return t.stop()}},t,this)}))}},{key:"onUserDevicesChange",value:function(){var e=this;return this.onAuthStateChanged().pipe((0,w.switchMap)(function(t){if(!t)return g.EMPTY;var r=e.getUserDevicesPath(),i=e.app.database().ref(r);return(0,g.fromEventPattern)(function(e){return i.on("value",e)},function(e){return i.off("value",e)}).pipe((0,w.map)(function(e){return n(e,1)[0].val()}),(0,w.switchMap)(function(t){return(0,g.from)(e.userDevicesToDeviceInfoList(t))}))}))}},{key:"onUserClaimsChange",value:function(){var e=this;return this.onAuthStateChanged().pipe((0,w.switchMap)(function(t){if(!t)return g.EMPTY;var r=e.getUserClaimsUpdatedOnPath(),i=e.app.database().ref(r);return(0,g.fromEventPattern)(function(e){return i.on("value",e)},function(e){return i.off("value",e)}).pipe((0,w.map)(function(e){return n(e,1)[0].val()}),(0,w.switchMap)(function(){return(0,g.from)(e.getIdToken(!0)).pipe((0,w.switchMap)(function(){return(0,g.from)(e.getClaims())}))}))}))}},{key:"getIdToken",value:function(){var e,t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];return y(this,void 0,void 0,r().mark(function n(){var i;return r().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(i=null===(e=this.app.auth())||void 0===e?void 0:e.currentUser){r.next=3;break}return r.abrupt("return",Promise.reject("getUserIdToken: unable to get currentUser"));case 3:return r.next=5,i.getIdToken(t).catch(function(e){console.error(e)});case 5:case"end":return r.stop()}},n,this)}))}},{key:"getClaims",value:function(){var e,t=null===(e=this.app.auth())||void 0===e?void 0:e.currentUser;return t?t.getIdTokenResult().then(function(e){return e.claims}).catch(function(e){return console.error(e),null}):Promise.reject("getUserClaims: unable to get currentUser")}},{key:"userDevicesToDeviceInfoList",value:function(e){return y(this,void 0,void 0,r().mark(function t(){var n,i,a,o=this;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=Object.keys(null!=e?e:{}).map(function(e){return o.app.database().ref(o.getDeviceInfoPath(e)).once("value")}),t.next=3,Promise.all(n).then(function(e){return e.map(function(e){return e.val()})});case 3:return i=t.sent,(a=i.filter(function(e){return!!e})).sort(function(t,r){return e[t.deviceId].claimedOn-e[r.deviceId].claimedOn}),t.abrupt("return",a);case 7:case"end":return t.stop()}},t)}))}},{key:"hasDevicePermission",value:function(e){return y(this,void 0,void 0,r().mark(function t(){var n,i;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=this.getDeviceInfoPath(e),t.next=3,this.app.database().ref(n).once("value").then(function(){return!0}).catch(function(){return!1});case 3:return i=t.sent,t.abrupt("return",i);case 5:case"end":return t.stop()}},t,this)}))}},{key:"getDeviceClaimedByPath",value:function(e){return"devices/".concat(e,"/status/claimedBy")}},{key:"getUserClaimedDevicePath",value:function(e){var t=this.user.uid;return"users/".concat(t,"/devices/").concat(e)}},{key:"getUserDevicesPath",value:function(){var e=this.user.uid;return"users/".concat(e,"/devices")}},{key:"getUserClaimsUpdatedOnPath",value:function(){var e=this.user.uid;return"users/".concat(e,"/claimsUpdatedOn")}},{key:"getDeviceInfoPath",value:function(e){return"devices/".concat(e,"/info")}},{key:"onUserExperiments",value:function(){var e=this;return this.onAuthStateChanged().pipe((0,w.switchMap)(function(t){if(!t)return g.EMPTY;var r=e.user.uid,i=e.app.database().ref("experiments").orderByChild("userId").equalTo(r).limitToFirst(100);return(0,g.fromEventPattern)(function(e){return i.on("value",e)},function(e){return i.off("value",e)}).pipe((0,w.map)(function(e){return n(e,1)[0].val()}),(0,w.map)(function(e){return Object.entries(null!=e?e:{}).map(function(e){var t,r=n(e,2),i=r[0],a=r[1];return Object.assign({id:null!==(t=null==a?void 0:a.id)&&void 0!==t?t:i},a)}).sort(function(e,t){return new Date(null==t?void 0:t.timestamp).getTime()-new Date(null==e?void 0:e.timestamp).getTime()})}))}))}},{key:"deleteUserExperiment",value:function(e){return y(this,void 0,void 0,r().mark(function t(){var n,i,a=this;return r().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(e){t.next=2;break}return t.abrupt("return",Promise.reject("deleteUserExperiment: please provide an experiment id"));case 2:return n=function(e){return a.app.database().ref("experiments").child(e).remove()},i=function(e){return a.app.functions().httpsCallable("removeRelations")({experimentId:e})},t.next=6,Promise.all([n(e),i(e)]).catch(function(){});case 6:case"end":return t.stop()}},t)}))}}]),e}();exports.FirebaseUser=j;
504
504
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","firebase/app":"OJEJ"}],"mSvX":[function(require,module,exports) {
@@ -524,7 +524,7 @@ var r=Array.isArray;function n(n){if(r(n))return t(n);var e=null,u="string"==typ
524
524
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","../types/status":"Ttuy"}],"qny3":[function(require,module,exports) {
525
525
  "use strict";function r(r,n){return i(r)||o(r,n)||e(r,n)||t()}function t(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function e(r,t){if(r){if("string"==typeof r)return n(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?n(r,t):void 0}}function n(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=new Array(t);e<t;e++)n[e]=r[e];return n}function o(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;l=!1}else for(;!(l=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(f){c=!0,o=f}finally{try{if(!l&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}function i(r){if(Array.isArray(r))return r}Object.defineProperty(exports,"__esModule",{value:!0}),exports.filterInternalKeys=void 0;var u=require("rxjs"),a=require("rxjs/operators");function l(){return(0,u.pipe)((0,a.map)(function(t){return t?Object.entries(t).reduce(function(t,e){var n=r(e,2),o=n[0],i=n[1];return o.startsWith("__")||(t[o]=i),t},{}):t}))}exports.filterInternalKeys=l;
526
526
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE"}],"LXvB":[function(require,module,exports) {
527
- "use strict";function e(t){return(e="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})(t)}function t(e,t){return s(e)||o(e,t)||n(e,t)||r()}function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(e,t){if(e){if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}function i(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 o(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(f){u=!0,i=f}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}function s(e){if(Array.isArray(e))return e}function a(){a=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function f(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{f({},"")}catch(U){f=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var o=t&&t.prototype instanceof p?t:p,s=Object.create(o.prototype),a=new E(n||[]);return i(s,"_invoke",{value:D(e,r,a)}),s}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(U){return{type:"throw",arg:U}}}t.wrap=l;var v={};function p(){}function d(){}function y(){}var b={};f(b,s,function(){return this});var m=Object.getPrototypeOf,g=m&&m(m(O([])));g&&g!==r&&n.call(g,s)&&(b=g);var w=y.prototype=p.prototype=Object.create(b);function x(e){["next","throw","return"].forEach(function(t){f(e,t,function(e){return this._invoke(t,e)})})}function k(t,r){var o;i(this,"_invoke",{value:function(i,s){function a(){return new r(function(o,a){!function i(o,s,a,c){var u=h(t[o],t,s);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&n.call(l,"__await")?r.resolve(l.__await).then(function(e){i("next",e,a,c)},function(e){i("throw",e,a,c)}):r.resolve(l).then(function(e){f.value=e,a(f)},function(e){return i("throw",e,a,c)})}c(u.arg)}(i,s,o,a)})}return o=o?o.then(a,a):a()}})}function D(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return L()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=S(s,r);if(a){if(a===v)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=h(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,v;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,v):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function A(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function j(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(A,this),this.reset(!0)}function O(e){if(e){var t=e[s];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=y,i(w,"constructor",{value:y,configurable:!0}),i(y,"constructor",{value:d,configurable:!0}),d.displayName=f(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,f(e,u,"GeneratorFunction")),e.prototype=Object.create(w),e},t.awrap=function(e){return{__await:e}},x(k.prototype),f(k.prototype,c,function(){return this}),t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var s=new k(l(e,r,n,i),o);return t.isGeneratorFunction(r)?s:s.next().then(function(e){return e.done?e.value:s.next()})},x(w),f(w,u,"Generator"),f(w,s,function(){return this}),f(w,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var a=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:O(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),v}},t}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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,l(n.key),n)}}function f(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(t){var r=h(t,"string");return"symbol"===e(r)?r:String(r)}function h(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var v=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{c(n.next(e))}catch(t){o(t)}}function a(e){try{c(n.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloudClient=exports.SERVER_TIMESTAMP=exports.createUser=exports.credentialWithLink=void 0;var p=require("rxjs"),d=require("rxjs"),y=require("rxjs/operators"),b=require("./firebase"),m=require("../timesync"),g=require("../subscriptions/SubscriptionManager"),w=require("../utils/heartbeat"),x=require("../utils/filterInternalKeys"),k=require("./firebase");Object.defineProperty(exports,"credentialWithLink",{enumerable:!0,get:function(){return k.credentialWithLink}}),Object.defineProperty(exports,"createUser",{enumerable:!0,get:function(){return k.createUser}}),Object.defineProperty(exports,"SERVER_TIMESTAMP",{enumerable:!0,get:function(){return k.SERVER_TIMESTAMP}});var D=function(){function e(t){var r=this;c(this,e),this._selectedDevice=new p.ReplaySubject(1),this.options=t,this.subscriptionManager=new g.SubscriptionManager,this.firebaseApp=new b.FirebaseApp(t),this.firebaseUser=new b.FirebaseUser(this.firebaseApp),this._selectedDevice.next(void 0),this.status$=(0,w.heartbeatAwareStatus)(this.observeNamespace("status").pipe((0,y.share)())).pipe((0,x.filterInternalKeys)(),(0,y.shareReplay)(1)),this.osVersion$=this.observeNamespace("info/osVersion").pipe((0,y.shareReplay)(1)),this.firebaseUser.onAuthStateChanged().subscribe(function(e){r.user=e}),this.firebaseUser.onUserClaimsChange().subscribe(function(e){r.userClaims=e}),this.onDeviceChange().subscribe(function(e){r.firebaseDevice&&r.firebaseDevice.disconnect(),e&&(r.firebaseDevice=new b.FirebaseDevice({deviceId:e.deviceId,firebaseApp:r.firebaseApp,dependencies:{subscriptionManager:r.subscriptionManager}}),r.options.timesync&&(r.timesync=new m.Timesync({status$:r.status(),getTimesync:r.firebaseDevice.getTimesync.bind(r.firebaseDevice)})))})}return f(e,[{key:"onDeviceChange",value:function(){return this._selectedDevice.asObservable().pipe((0,y.filter)(function(e){return void 0!==e}))}},{key:"osVersion",value:function(){return this.osVersion$}},{key:"setAutoSelectedDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){var t=this;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.options.deviceId){e.next=4;break}return e.next=3,this.selectDevice(function(e){return e.find(function(e){return e.deviceId===t.options.deviceId})});case 3:return e.abrupt("return",e.sent);case 4:if(this.options.deviceId||!this.options.autoSelectDevice){e.next=8;break}return e.next=7,this.selectDevice(function(e){return e[0]});case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",null);case 9:case"end":return e.stop()}},e,this)}))}},{key:"actions",get:function(){var e=this;return{dispatch:function(t){return e.firebaseDevice.dispatchAction(t)}}}},{key:"dispatchAction",value:function(e){return v(this,void 0,void 0,a().mark(function t(){return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.firebaseDevice.dispatchAction(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"disconnect",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseApp.disconnect());case 1:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.firebaseDevice.getInfo();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"login",value:function(e){return v(this,void 0,void 0,a().mark(function t(){var r,n;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.user){t.next=2;break}return t.abrupt("return",Promise.reject("Already logged in."));case 2:return t.next=4,this.firebaseUser.login(e);case 4:return r=t.sent,t.next=7,this.setAutoSelectedDevice();case 7:return n=t.sent,t.abrupt("return",Object.assign(Object.assign({},r),{selectedDevice:n}));case 9:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.firebaseDevice&&this.firebaseDevice.disconnect(),e.next=3,this.firebaseUser.logout();case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)}))}},{key:"onAuthStateChanged",value:function(){var e=this;return this.firebaseUser.onAuthStateChanged().pipe((0,y.switchMap)(function(t){return v(e,void 0,void 0,a().mark(function e(){var r,n;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",null);case 2:if(!this.didSelectDevice()){e.next=8;break}return e.next=5,this.getSelectedDevice();case 5:e.t0=e.sent,e.next=11;break;case 8:return e.next=10,this.setAutoSelectedDevice();case 10:e.t0=e.sent;case 11:return r=e.t0,n=Object.assign(t,{selectedDevice:r}),e.abrupt("return",n);case 14:case"end":return e.stop()}},e,this)}))}))}},{key:"getDevices",value:function(){return this.firebaseUser.getDevices()}},{key:"addDevice",value:function(e){return this.firebaseUser.addDevice(e)}},{key:"removeDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o,s,c;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.removeDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=t(n,2),o=i[0],s=i[1],!o){r.next=8;break}return r.abrupt("return",Promise.reject(s));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(c=r.sent)?void 0:c.deviceId)===e&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"transferDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o,s,c;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.transferDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=t(n,2),o=i[0],s=i[1],!o){r.next=8;break}return r.abrupt("return",Promise.reject(s));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(c=r.sent)?void 0:c.deviceId)===e.deviceId&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"onUserDevicesChange",value:function(){return this.firebaseUser.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.firebaseUser.onUserClaimsChange()}},{key:"didSelectDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){var t;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSelectedDevice();case 2:return t=e.sent,e.abrupt("return",!!t);case 4:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.getDevices();case 2:if(n=r.sent){r.next=5;break}return r.abrupt("return",Promise.reject("Did not find any devices for this user. Make sure your device is claimed by your Neurosity account."));case 5:if(i=function(r){return r.find(function(r){if(!Array.isArray(e))return!1;var n=t(e,2),i=n[0],o=n[1];return JSON.stringify(null==r?void 0:r[i])===JSON.stringify(o)})},o="function"==typeof e?e(n):i(n)){r.next=9;break}return r.abrupt("return",Promise.reject("A device was not provided. Try returning a device from the devicesList provided in the callback."));case 9:return r.next=11,this.firebaseUser.hasDevicePermission(o.deviceId);case 11:if(r.sent){r.next=14;break}return r.abrupt("return",Promise.reject("Rejected device access due to permissions."));case 14:return this._selectedDevice.next(o),r.abrupt("return",o);case 16:case"end":return r.stop()}},r,this)}))}},{key:"getSelectedDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,d.firstValueFrom)(this._selectedDevice);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"status",value:function(){return this.status$}},{key:"observeNamespace",value:function(e){var t=this;return this.onDeviceChange().pipe((0,y.switchMap)(function(r){return r?(0,d.fromEventPattern)(function(r){return t.firebaseDevice.onNamespace(e,r)},function(r){return t.firebaseDevice.offNamespace(e,r)}):p.EMPTY}))}},{key:"onceNamespace",value:function(e){return v(this,void 0,void 0,a().mark(function t(){return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.firebaseDevice.onceNamespace(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"metrics",get:function(){var e=this;return{next:function(t,r){e.firebaseDevice.nextMetric(t,r)},on:function(t,r){return e.firebaseDevice.onMetric(t,r)},subscribe:function(t){var r=e.firebaseDevice.subscribeToMetric(t);return e.subscriptionManager.add(r),r},unsubscribe:function(t,r){e.subscriptionManager.remove(t),e.firebaseDevice.unsubscribeFromMetric(t),e.firebaseDevice.removeMetricListener(t,r)}}}},{key:"createAccount",value:function(e){return this.firebaseUser.createAccount(e)}},{key:"deleteAccount",value:function(){return this.firebaseUser.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.firebaseDevice.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.firebaseUser.createCustomToken()}},{key:"removeOAuthAccess",value:function(){return this.firebaseUser.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.firebaseUser.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.firebaseUser.deleteUserExperiment(e)}},{key:"skills",get:function(){var e=this;return{get:function(t){return v(e,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseDevice.getSkill(t));case 1:case"end":return e.stop()}},e,this)}))}}}},{key:"timestamp",get:function(){return this.options.timesync?this.timesync.timestamp:Date.now()}},{key:"getTimesyncOffset",value:function(){return this.timesync.offset}},{key:"changeSettings",value:function(e){return this.firebaseDevice.changeSettings(e)}},{key:"goOffline",value:function(){this.firebaseApp.goOffline()}},{key:"goOnline",value:function(){this.firebaseApp.goOnline()}},{key:"__getApp",value:function(){return this.firebaseApp.app}}]),e}();exports.CloudClient=D;
527
+ "use strict";function e(t){return(e="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})(t)}function t(e,t){return s(e)||o(e,t)||n(e,t)||r()}function r(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function n(e,t){if(e){if("string"==typeof e)return i(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?i(e,t):void 0}}function i(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 o(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],c=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);c=!0);}catch(f){u=!0,i=f}finally{try{if(!c&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}}function s(e){if(Array.isArray(e))return e}function a(){a=function(){return t};var t={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(e,t,r){e[t]=r.value},o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function f(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{f({},"")}catch(L){f=function(e,t,r){return e[t]=r}}function l(e,t,r,n){var o=t&&t.prototype instanceof p?t:p,s=Object.create(o.prototype),a=new E(n||[]);return i(s,"_invoke",{value:D(e,r,a)}),s}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(L){return{type:"throw",arg:L}}}t.wrap=l;var v={};function p(){}function d(){}function y(){}var b={};f(b,s,function(){return this});var m=Object.getPrototypeOf,g=m&&m(m(O([])));g&&g!==r&&n.call(g,s)&&(b=g);var w=y.prototype=p.prototype=Object.create(b);function x(e){["next","throw","return"].forEach(function(t){f(e,t,function(e){return this._invoke(t,e)})})}function k(t,r){var o;i(this,"_invoke",{value:function(i,s){function a(){return new r(function(o,a){!function i(o,s,a,c){var u=h(t[o],t,s);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==e(l)&&n.call(l,"__await")?r.resolve(l.__await).then(function(e){i("next",e,a,c)},function(e){i("throw",e,a,c)}):r.resolve(l).then(function(e){f.value=e,a(f)},function(e){return i("throw",e,a,c)})}c(u.arg)}(i,s,o,a)})}return o=o?o.then(a,a):a()}})}function D(e,t,r){var n="suspendedStart";return function(i,o){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===i)throw o;return _()}for(r.method=i,r.arg=o;;){var s=r.delegate;if(s){var a=S(s,r);if(a){if(a===v)continue;return a}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=h(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}function S(e,t){var r=t.method,n=e.iterator[r];if(void 0===n)return t.delegate=null,"throw"===r&&e.iterator.return&&(t.method="return",t.arg=void 0,S(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),v;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,v;var o=i.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,v):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,v)}function A(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function j(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(A,this),this.reset(!0)}function O(e){if(e){var t=e[s];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,i=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:_}}function _(){return{value:void 0,done:!0}}return d.prototype=y,i(w,"constructor",{value:y,configurable:!0}),i(y,"constructor",{value:d,configurable:!0}),d.displayName=f(y,u,"GeneratorFunction"),t.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},t.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,y):(e.__proto__=y,f(e,u,"GeneratorFunction")),e.prototype=Object.create(w),e},t.awrap=function(e){return{__await:e}},x(k.prototype),f(k.prototype,c,function(){return this}),t.AsyncIterator=k,t.async=function(e,r,n,i,o){void 0===o&&(o=Promise);var s=new k(l(e,r,n,i),o);return t.isGeneratorFunction(r)?s:s.next().then(function(e){return e.done?e.value:s.next()})},x(w),f(w,u,"Generator"),f(w,s,function(){return this}),f(w,"toString",function(){return"[object Generator]"}),t.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(j),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return s.type="throw",s.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],s=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var a=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var s=o?o.completion:{};return s.type=e,s.arg=t,o?(this.method="next",this.next=o.finallyLoc,v):this.complete(s)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),v},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),j(r),v}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var i=n.arg;j(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:O(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),v}},t}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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,l(n.key),n)}}function f(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function l(t){var r=h(t,"string");return"symbol"===e(r)?r:String(r)}function h(t,r){if("object"!==e(t)||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var i=n.call(t,r||"default");if("object"!==e(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}var v=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{c(n.next(e))}catch(t){o(t)}}function a(e){try{c(n.throw(e))}catch(t){o(t)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}c((n=n.apply(e,t||[])).next())})};Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloudClient=exports.__firebase=exports.SERVER_TIMESTAMP=exports.createUser=exports.credentialWithLink=void 0;var p=require("rxjs"),d=require("rxjs"),y=require("rxjs/operators"),b=require("./firebase"),m=require("../timesync"),g=require("../subscriptions/SubscriptionManager"),w=require("../utils/heartbeat"),x=require("../utils/filterInternalKeys"),k=require("./firebase");Object.defineProperty(exports,"credentialWithLink",{enumerable:!0,get:function(){return k.credentialWithLink}}),Object.defineProperty(exports,"createUser",{enumerable:!0,get:function(){return k.createUser}}),Object.defineProperty(exports,"SERVER_TIMESTAMP",{enumerable:!0,get:function(){return k.SERVER_TIMESTAMP}}),Object.defineProperty(exports,"__firebase",{enumerable:!0,get:function(){return k.__firebase}});var D=function(){function e(t){var r=this;c(this,e),this._selectedDevice=new p.ReplaySubject(1),this.options=t,this.subscriptionManager=new g.SubscriptionManager,this.firebaseApp=new b.FirebaseApp(t),this.firebaseUser=new b.FirebaseUser(this.firebaseApp),this._selectedDevice.next(void 0),this.status$=(0,w.heartbeatAwareStatus)(this.observeNamespace("status").pipe((0,y.share)())).pipe((0,x.filterInternalKeys)(),(0,y.shareReplay)(1)),this.osVersion$=this.observeNamespace("info/osVersion").pipe((0,y.shareReplay)(1)),this.firebaseUser.onAuthStateChanged().subscribe(function(e){r.user=e}),this.firebaseUser.onUserClaimsChange().subscribe(function(e){r.userClaims=e}),this.onDeviceChange().subscribe(function(e){r.firebaseDevice&&r.firebaseDevice.disconnect(),e&&(r.firebaseDevice=new b.FirebaseDevice({deviceId:e.deviceId,firebaseApp:r.firebaseApp,dependencies:{subscriptionManager:r.subscriptionManager}}),r.options.timesync&&(r.timesync=new m.Timesync({status$:r.status(),getTimesync:r.firebaseDevice.getTimesync.bind(r.firebaseDevice)})))})}return f(e,[{key:"onDeviceChange",value:function(){return this._selectedDevice.asObservable().pipe((0,y.filter)(function(e){return void 0!==e}))}},{key:"osVersion",value:function(){return this.osVersion$}},{key:"setAutoSelectedDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){var t=this;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!this.options.deviceId){e.next=4;break}return e.next=3,this.selectDevice(function(e){return e.find(function(e){return e.deviceId===t.options.deviceId})});case 3:return e.abrupt("return",e.sent);case 4:if(this.options.deviceId||!this.options.autoSelectDevice){e.next=8;break}return e.next=7,this.selectDevice(function(e){return e[0]});case 7:return e.abrupt("return",e.sent);case 8:return e.abrupt("return",null);case 9:case"end":return e.stop()}},e,this)}))}},{key:"actions",get:function(){var e=this;return{dispatch:function(t){return e.firebaseDevice.dispatchAction(t)}}}},{key:"dispatchAction",value:function(e){return v(this,void 0,void 0,a().mark(function t(){return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.firebaseDevice.dispatchAction(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"disconnect",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseApp.disconnect());case 1:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.firebaseDevice.getInfo();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"login",value:function(e){return v(this,void 0,void 0,a().mark(function t(){var r,n;return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.user){t.next=2;break}return t.abrupt("return",Promise.reject("Already logged in."));case 2:return t.next=4,this.firebaseUser.login(e);case 4:return r=t.sent,t.next=7,this.setAutoSelectedDevice();case 7:return n=t.sent,t.abrupt("return",Object.assign(Object.assign({},r),{selectedDevice:n}));case 9:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.firebaseDevice&&this.firebaseDevice.disconnect(),e.next=3,this.firebaseUser.logout();case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}},e,this)}))}},{key:"onAuthStateChanged",value:function(){var e=this;return this.firebaseUser.onAuthStateChanged().pipe((0,y.switchMap)(function(t){return v(e,void 0,void 0,a().mark(function e(){var r,n;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return",null);case 2:if(!this.didSelectDevice()){e.next=8;break}return e.next=5,this.getSelectedDevice();case 5:e.t0=e.sent,e.next=11;break;case 8:return e.next=10,this.setAutoSelectedDevice();case 10:e.t0=e.sent;case 11:return r=e.t0,n=Object.assign(t,{selectedDevice:r}),e.abrupt("return",n);case 14:case"end":return e.stop()}},e,this)}))}))}},{key:"getDevices",value:function(){return this.firebaseUser.getDevices()}},{key:"addDevice",value:function(e){return this.firebaseUser.addDevice(e)}},{key:"removeDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o,s,c;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.removeDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=t(n,2),o=i[0],s=i[1],!o){r.next=8;break}return r.abrupt("return",Promise.reject(s));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(c=r.sent)?void 0:c.deviceId)===e&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"transferDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o,s,c;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.firebaseUser.transferDevice(e).then(function(){return[!1]}).catch(function(e){return[!0,e]});case 2:if(n=r.sent,i=t(n,2),o=i[0],s=i[1],!o){r.next=8;break}return r.abrupt("return",Promise.reject(s));case 8:return r.next=10,this.getSelectedDevice();case 10:(null==(c=r.sent)?void 0:c.deviceId)===e.deviceId&&this._selectedDevice.next(null);case 12:case"end":return r.stop()}},r,this)}))}},{key:"onUserDevicesChange",value:function(){return this.firebaseUser.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.firebaseUser.onUserClaimsChange()}},{key:"didSelectDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){var t;return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getSelectedDevice();case 2:return t=e.sent,e.abrupt("return",!!t);case 4:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return v(this,void 0,void 0,a().mark(function r(){var n,i,o;return a().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.getDevices();case 2:if(n=r.sent){r.next=5;break}return r.abrupt("return",Promise.reject("Did not find any devices for this user. Make sure your device is claimed by your Neurosity account."));case 5:if(i=function(r){return r.find(function(r){if(!Array.isArray(e))return!1;var n=t(e,2),i=n[0],o=n[1];return JSON.stringify(null==r?void 0:r[i])===JSON.stringify(o)})},o="function"==typeof e?e(n):i(n)){r.next=9;break}return r.abrupt("return",Promise.reject("A device was not provided. Try returning a device from the devicesList provided in the callback."));case 9:return r.next=11,this.firebaseUser.hasDevicePermission(o.deviceId);case 11:if(r.sent){r.next=14;break}return r.abrupt("return",Promise.reject("Rejected device access due to permissions."));case 14:return this._selectedDevice.next(o),r.abrupt("return",o);case 16:case"end":return r.stop()}},r,this)}))}},{key:"getSelectedDevice",value:function(){return v(this,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,(0,d.firstValueFrom)(this._selectedDevice);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"status",value:function(){return this.status$}},{key:"observeNamespace",value:function(e){var t=this;return this.onDeviceChange().pipe((0,y.switchMap)(function(r){return r?(0,d.fromEventPattern)(function(r){return t.firebaseDevice.onNamespace(e,r)},function(r){return t.firebaseDevice.offNamespace(e,r)}):p.EMPTY}))}},{key:"onceNamespace",value:function(e){return v(this,void 0,void 0,a().mark(function t(){return a().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.firebaseDevice.onceNamespace(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"metrics",get:function(){var e=this;return{next:function(t,r){e.firebaseDevice.nextMetric(t,r)},on:function(t,r){return e.firebaseDevice.onMetric(t,r)},subscribe:function(t){var r=e.firebaseDevice.subscribeToMetric(t);return e.subscriptionManager.add(r),r},unsubscribe:function(t,r){e.subscriptionManager.remove(t),e.firebaseDevice.unsubscribeFromMetric(t),e.firebaseDevice.removeMetricListener(t,r)}}}},{key:"createAccount",value:function(e){return this.firebaseUser.createAccount(e)}},{key:"deleteAccount",value:function(){return this.firebaseUser.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.firebaseDevice.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.firebaseUser.createCustomToken()}},{key:"removeOAuthAccess",value:function(){return this.firebaseUser.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.firebaseUser.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.firebaseUser.deleteUserExperiment(e)}},{key:"skills",get:function(){var e=this;return{get:function(t){return v(e,void 0,void 0,a().mark(function e(){return a().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.firebaseDevice.getSkill(t));case 1:case"end":return e.stop()}},e,this)}))}}}},{key:"timestamp",get:function(){return this.options.timesync?this.timesync.timestamp:Date.now()}},{key:"getTimesyncOffset",value:function(){return this.timesync.offset}},{key:"changeSettings",value:function(e){return this.firebaseDevice.changeSettings(e)}},{key:"goOffline",value:function(){this.firebaseApp.goOffline()}},{key:"goOnline",value:function(){this.firebaseApp.goOnline()}},{key:"__getApp",value:function(){return this.firebaseApp.app}}]),e}();exports.CloudClient=D;
528
528
  },{"rxjs":"Zr8e","rxjs/operators":"v3iE","./firebase":"kM30","../timesync":"CXqr","../subscriptions/SubscriptionManager":"BX8M","../utils/heartbeat":"ImaE","../utils/filterInternalKeys":"qny3"}],"rekm":[function(require,module,exports) {
529
529
  "use strict";var t,o;Object.defineProperty(exports,"__esModule",{value:!0}),exports.STREAMING_MODE=exports.STREAMING_TYPE=void 0,function(t){t.WIFI="wifi",t.BLUETOOTH="bluetooth"}(t=exports.STREAMING_TYPE||(exports.STREAMING_TYPE={})),function(t){t.WIFI_ONLY="wifi-only",t.WIFI_WITH_BLUETOOTH_FALLBACK="wifi-with-bluetooth-fallback",t.BLUETOOTH_WITH_WIFI_FALLBACK="bluetooth-with-wifi-fallback"}(o=exports.STREAMING_MODE||(exports.STREAMING_MODE={}));
530
530
  },{}],"A5u5":[function(require,module,exports) {