@neurosity/sdk 6.5.7 → 6.5.9
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/browser/neurosity.iife.js +2 -0
- package/dist/browser/neurosity.js +4 -4
- package/dist/browser/neurosity.js.map +1 -1
- package/dist/cjs/Neurosity.d.ts +5 -0
- package/dist/cjs/Neurosity.js +7 -1
- package/dist/cjs/api/firebase/FirebaseApp.d.ts +1 -0
- package/dist/cjs/api/firebase/FirebaseApp.js +2 -1
- package/dist/cjs/api/index.d.ts +1 -1
- package/dist/cjs/api/index.js +2 -1
- package/dist/electron/index.js +4 -4
- package/dist/electron/index.js.map +1 -1
- package/dist/esm/Neurosity.d.ts +5 -0
- package/dist/esm/Neurosity.js +5 -0
- package/dist/esm/api/firebase/FirebaseApp.d.ts +1 -0
- package/dist/esm/api/firebase/FirebaseApp.js +1 -0
- package/dist/esm/api/index.d.ts +1 -1
- package/dist/esm/api/index.js +1 -1
- package/dist/esm/neurosity.mjs +2 -1
- package/dist/examples/neurosity.iife.js +2 -0
- package/dist/examples/neurosity.js +4 -4
- package/dist/examples/neurosity.mjs +2 -1
- package/package.json +1 -1
|
@@ -41775,6 +41775,7 @@ var Neurosity = (function (exports) {
|
|
|
41775
41775
|
};
|
|
41776
41776
|
|
|
41777
41777
|
const SERVER_TIMESTAMP$1 = firebase.database.ServerValue.TIMESTAMP;
|
|
41778
|
+
const __firebase = firebase;
|
|
41778
41779
|
/**
|
|
41779
41780
|
* @hidden
|
|
41780
41781
|
*/
|
|
@@ -51085,6 +51086,7 @@ var Neurosity = (function (exports) {
|
|
|
51085
51086
|
|
|
51086
51087
|
exports.Neurosity = Neurosity;
|
|
51087
51088
|
exports.Notion = Notion;
|
|
51089
|
+
exports.__firebase = __firebase;
|
|
51088
51090
|
exports.BluetoothClient = BluetoothClient;
|
|
51089
51091
|
exports.WebBluetoothTransport = WebBluetoothTransport;
|
|
51090
51092
|
exports.ReactNativeTransport = ReactNativeTransport;
|
|
@@ -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
|
|
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) {
|
|
@@ -675,8 +675,8 @@ var r=require("./compare"),e=function(e,o,u){return r(e,o,u)>=0};module.exports=
|
|
|
675
675
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,o){void 0===o&&(o=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,o,i)}:function(e,t,r,o){void 0===o&&(o=r),e[o]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var o in t)"default"===o||Object.prototype.hasOwnProperty.call(r,o)||e(r,t,o)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./BluetoothClient"),exports),t(require("./web/WebBluetoothTransport"),exports),t(require("./react-native/ReactNativeTransport"),exports),t(require("./utils/osHasBluetoothSupport"),exports),t(require("./types/index"),exports);
|
|
676
676
|
},{"./BluetoothClient":"fihV","./web/WebBluetoothTransport":"ouKb","./react-native/ReactNativeTransport":"FtS5","./utils/osHasBluetoothSupport":"rH2Y","./types/index":"iwtf"}],"BZP9":[function(require,module,exports) {
|
|
677
677
|
var define;
|
|
678
|
-
var e;function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&r(e,t)}function r(e,t){return(r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function n(e){var t=u();return function(){var r,n=c(e);if(t){var o=c(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return i(this,r)}}function i(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){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 c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e){return(a="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})(e)}function s(e,t){return p(e)||d(e,t)||h(e,t)||l()}function l(){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 h(e,t){if(e){if("string"==typeof e)return f(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)?f(e,t):void 0}}function f(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 d(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,u,c=[],a=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;a=!1}else for(;!(a=(n=o.call(r)).done)&&(c.push(n.value),c.length!==t);a=!0);}catch(l){s=!0,i=l}finally{try{if(!a&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw i}}return c}}function p(e){if(Array.isArray(e))return e}function v(){"use strict";v=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(A){s=function(e,t,r){return e[t]=r}}function l(e,t,r,i){var o=t&&t.prototype instanceof d?t:d,u=Object.create(o.prototype),c=new _(i||[]);return n(u,"_invoke",{value:S(e,r,c)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(A){return{type:"throw",arg:A}}}e.wrap=l;var f={};function d(){}function p(){}function m(){}var y={};s(y,o,function(){return this});var b=Object.getPrototypeOf,g=b&&b(b(M([])));g&&g!==t&&r.call(g,o)&&(y=g);var w=m.prototype=d.prototype=Object.create(y);function C(e){["next","throw","return"].forEach(function(t){s(e,t,function(e){return this._invoke(t,e)})})}function O(e,t){var i;n(this,"_invoke",{value:function(n,o){function u(){return new t(function(i,u){!function n(i,o,u,c){var s=h(e[i],e,o);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==a(f)&&r.call(f,"__await")?t.resolve(f.__await).then(function(e){n("next",e,u,c)},function(e){n("throw",e,u,c)}):t.resolve(f).then(function(e){l.value=e,u(l)},function(e){return n("throw",e,u,c)})}c(s.arg)}(n,o,i,u)})}return i=i?i.then(u,u):u()}})}function S(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 T()}for(r.method=i,r.arg=o;;){var u=r.delegate;if(u){var c=x(u,r);if(c){if(c===f)continue;return c}}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 a=h(e,t,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.arg)}}}function x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,f;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,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function k(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 E(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function _(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=m,n(w,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:p,configurable:!0}),p.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},C(O.prototype),s(O.prototype,u,function(){return this}),e.AsyncIterator=O,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new O(l(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then(function(e){return e.done?e.value:u.next()})},C(w),s(w,c,"Generator"),s(w,o,function(){return this}),s(w,"toString",function(){return"[object Generator]"}),e.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}},e.values=M,_.prototype={constructor:_,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(E),!e)for(var t in this)"t"===t.charAt(0)&&r.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 n(r,n){return u.type="throw",u.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],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var c=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(c&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.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 u=o?o.completion:{};return u.type=e,u.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(u)},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),f},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),E(r),f}},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;E(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:M(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(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,g(n.key),n)}}function b(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e){var t=w(e,"string");return"symbol"===a(t)?t:String(t)}function w(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var C=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),O=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),S=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&C(t,e,r);return O(t,e),t},x=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{a(n.next(e))}catch(t){o(t)}}function c(e){try{a(n.throw(e))}catch(t){o(t)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}a((n=n.apply(e,t||[])).next())})},k=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Notion=exports.Neurosity=void 0;var E=require("rxjs"),_=require("rxjs"),M=require("rxjs/operators"),T=require("rxjs/operators"),A=k(require("fast-deep-equal")),D=require("./api/index"),N=require("./api/index"),I=require("./types/streaming"),j=require("./utils/subscription"),P=require("./types/status"),F=S(require("./utils/errors")),L=S(require("./utils/platform")),R=S(require("./utils/hapticEffects")),B=require("./utils/oauth"),U=require("./utils/oauth"),G=require("./api/https/createOAuthURL"),q=require("./api/https/getOAuthToken"),H=require("./utils/is-node"),W=require("./utils/metrics"),Y=require("./api/bluetooth"),V=require("./api/bluetooth/types"),$={timesync:!1,autoSelectDevice:!0,streamingMode:I.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},K=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m(this,e),this.streamingMode$=new _.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},$),t)),this.cloudClient=new D.CloudClient(this.options),n&&(this.bluetoothClient=new Y.BluetoothClient({selectedDevice$:this.onDeviceChange(),osHasBluetoothSupport$:this._osHasBluetoothSupport(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return b(e,[{key:"_initStreamingMode",value:function(e,t){var r=[I.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,I.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(I.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(I.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"_osHasBluetoothSupport",value:function(){return(0,E.combineLatest)({selectedDevice:this.onDeviceChange(),osVersion:this.osVersion().pipe((0,M.startWith)(null))}).pipe((0,M.map)(function(e){var t=e.selectedDevice,r=e.osVersion;return(0,Y.osHasBluetoothSupport)(t,r)}))}},{key:"streamingState",value:function(){var e=this,t=function(e){return[P.STATUS.ONLINE,P.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,M.switchMap)(function(r){return(0,E.combineLatest)({selectedDevice:e.onDeviceChange(),osHasBluetoothSupport:e._osHasBluetoothSupport()}).pipe((0,M.switchMap)(function(n){var i=n.selectedDevice,o=n.osHasBluetoothSupport;return i?e.isMissingBluetoothTransport||!o?e.cloudClient.status().pipe((0,M.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI}})):(0,E.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,E.of)(V.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,M.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===V.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case I.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI};case I.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?I.STREAMING_TYPE.WIFI:I.STREAMING_TYPE.BLUETOOTH};case I.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?I.STREAMING_TYPE.BLUETOOTH:I.STREAMING_TYPE.WIFI}}}),(0,T.distinctUntilChanged)(function(e,t){return(0,A.default)(e,t)})):(0,E.of)({connected:!1,streamingMode:r,activeMode:I.STREAMING_TYPE.WIFI})}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,M.switchMap)(function(e){switch(e.activeMode){case I.STREAMING_TYPE.WIFI:return t();case I.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,_.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===I.STREAMING_TYPE.WIFI?8:t.t0===I.STREAMING_TYPE.BLUETOOTH?11:14;break;case 8:return t.next=10,r();case 10:return t.abrupt("return",t.sent);case 11:return t.next=13,n();case 13:return t.abrupt("return",t.sent);case 14:return t.next=16,r();case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}},t,this)}))}},{key:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{key:"_getCloudMetricDependencies",value:function(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}}},{key:"login",value:function(e){return x(this,void 0,void 0,v().mark(function t(){return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.login(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.logout();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"__getApp",value:function(){return this.cloudClient.__getApp()}},{key:"onAuthStateChanged",value:function(){return this.cloudClient.onAuthStateChanged()}},{key:"addDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"addDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.addDevice(e)}},{key:"removeDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"removeDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.removeDevice(e)}},{key:"transferDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"transferDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.transferDevice(e)}},{key:"onUserDevicesChange",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=s(r,2),i=n[0],o=n[1],!i){t.next=3;break}return t.abrupt("return",Promise.reject(o));case 3:return t.next=5,this.cloudClient.selectDevice(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}},t,this)}))}},{key:"getSelectedDevice",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t,r,n,i;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=s(t,2),n=r[0],i=r[1],!n){e.next=3;break}return e.abrupt("return",Promise.reject(i));case 3:return e.next=5,this.cloudClient.getSelectedDevice();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t,r,n,i,o=this;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}return e.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=s(t,2),n=r[0],i=r[1],!n){e.next=7;break}return e.abrupt("return",Promise.reject(i));case 7:return e.next=9,this._withStreamingModePromise({wifi:function(){return o.cloudClient.getInfo()},bluetooth:function(){return o.bluetoothClient.getInfo()}});case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)}))}},{key:"onDeviceChange",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t=this;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withStreamingModePromise({wifi:function(){return t.cloudClient.disconnect()},bluetooth:function(){return t.bluetoothClient.disconnect()}});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o,u=this;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(r=(0,U.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=s(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this._withStreamingModePromise({wifi:function(){return u.cloudClient.dispatchAction(e)},bluetooth:function(){return u.bluetoothClient.dispatchAction(e)}});case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"addMarker",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r=this;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}throw F.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(F.prefix,"A label is required for addMarker"));case 6:return t.next=8,this._withStreamingModePromise({wifi:function(){return r.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:r.cloudClient.timestamp}})},bluetooth:function(){return r.bluetoothClient.addMarker(e)}});case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}},t,this)}))}},{key:"haptics",value:function(e){var t;return x(this,void 0,void 0,v().mark(function r(){var n,i,o,u,c,a,s=this;return v().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n="haptics",r.next=3,this.cloudClient.didSelectDevice();case 3:if(r.sent){r.next=5;break}return r.abrupt("return",Promise.reject(F.mustSelectDevice));case 5:return r.next=7,this.getSelectedDevice();case 7:if(r.t1=t=r.sent,r.t0=null===r.t1,r.t0){r.next=11;break}r.t0=void 0===t;case 11:if(!r.t0){r.next=15;break}r.t2=void 0,r.next=16;break;case 15:r.t2=t.modelVersion;case 16:if(i=r.t2,L.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(F.metricNotSupportedByModel(n,i)));case 20:o=L.getPlatformHapticMotors(i),r.t3=v().keys(e);case 22:if((r.t4=r.t3()).done){r.next=33;break}if(u=r.t4.value,Object.keys(o).includes(u)){r.next=26;break}return r.abrupt("return",Promise.reject(F.locationNotFound(u,i)));case 26:if(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(F.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return a={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(a)},bluetooth:function(){return s.bluetoothClient.dispatchAction(a)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return R}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this.onDeviceChange().pipe((0,M.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||L.MODEL_VERSION_1;return L.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,j.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,E.throwError)(function(){return F.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(t._getCloudMetricDependencies(),{metric:"brainwaves",labels:e?[e]:[],atomic:!1})},bluetooth:function(){return t.bluetoothClient.brainwaves(e)}})}},{key:"calm",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.calm()}})}},{key:"signalQuality",value:function(){var e=this,t="signalQuality",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,E.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,j.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"osVersion",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion"),2),t=e[0],r=e[1];return t?(0,E.throwError)(function(){return r}):this.cloudClient.osVersion()}},{key:"focus",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,E.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=s(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this.cloudClient.changeSettings(e);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"training",get:function(){var e=this;return{record:function(t){return x(e,void 0,void 0,v().mark(function e(){var r,n;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return r=this.cloudClient.user&&"uid"in this.cloudClient.user?this.cloudClient.user.uid:null,n=Object.assign(Object.assign({fit:!1,baseline:!1,timestamp:this.cloudClient.timestamp},t),{userId:r}),e.next=8,this.cloudClient.actions.dispatch({command:"training",action:"record",message:n});case 8:case"end":return e.stop()}},e,this)}))},stop:function(t){return x(e,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stop",message:Object.assign({},t)});case 6:case"end":return e.stop()}},e,this)}))},stopAll:function(){return x(e,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}});case 6:case"end":return e.stop()}},e,this)}))}}}},{key:"goOffline",value:function(){this.cloudClient.goOffline()}},{key:"goOnline",value:function(){this.cloudClient.goOnline()}},{key:"createAccount",value:function(e){return this.cloudClient.createAccount(e)}},{key:"deleteAccount",value:function(){return this.cloudClient.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.cloudClient.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.cloudClient.createCustomToken()}},{key:"getTimesyncOffset",value:function(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0}},{key:"createOAuthURL",value:function(e){return H.isNode?(0,G.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return H.isNode?(0,q.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the getOAuthToken method must be used on the server side (node.js) for security reasons.")))}},{key:"removeOAuthAccess",value:function(){return this.cloudClient.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.cloudClient.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.cloudClient.deleteUserExperiment(e)}}]),e}();exports.Neurosity=K,K.credentialWithLink=N.credentialWithLink,K.createUser=D.createUser,K.SERVER_TIMESTAMP=N.SERVER_TIMESTAMP;var Q=function(e){t(i,K);var r=n(i);function i(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return m(this,i),e=r.call(this,t),console.log("The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()"),e}return b(i)}();exports.Notion=Q;
|
|
679
|
-
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","./api/index":"LXvB","./types/streaming":"rekm","./utils/subscription":"yLLB","./types/status":"Ttuy","./utils/errors":"WDyG","./utils/platform":"wAkn","./utils/hapticEffects":"lLai","./utils/oauth":"xIH5","./api/https/createOAuthURL":"MDrB","./api/https/getOAuthToken":"nfg4","./utils/is-node":"vsps","./utils/metrics":"DCuD","./api/bluetooth":"TICO","./api/bluetooth/types":"iwtf"}],"QCba":[function(require,module,exports) {
|
|
678
|
+
var e;function t(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&r(e,t)}function r(e,t){return(r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function n(e){var t=u();return function(){var r,n=c(e);if(t){var o=c(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return i(this,r)}}function i(e,t){if(t&&("object"===a(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return o(e)}function o(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(){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 c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e){return(a="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})(e)}function s(e,t){return p(e)||d(e,t)||h(e,t)||l()}function l(){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 h(e,t){if(e){if("string"==typeof e)return f(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)?f(e,t):void 0}}function f(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 d(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,u,c=[],a=!0,s=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;a=!1}else for(;!(a=(n=o.call(r)).done)&&(c.push(n.value),c.length!==t);a=!0);}catch(l){s=!0,i=l}finally{try{if(!a&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(s)throw i}}return c}}function p(e){if(Array.isArray(e))return e}function v(){"use strict";v=function(){return e};var e={},t=Object.prototype,r=t.hasOwnProperty,n=Object.defineProperty||function(e,t,r){e[t]=r.value},i="function"==typeof Symbol?Symbol:{},o=i.iterator||"@@iterator",u=i.asyncIterator||"@@asyncIterator",c=i.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(A){s=function(e,t,r){return e[t]=r}}function l(e,t,r,i){var o=t&&t.prototype instanceof d?t:d,u=Object.create(o.prototype),c=new E(i||[]);return n(u,"_invoke",{value:S(e,r,c)}),u}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(A){return{type:"throw",arg:A}}}e.wrap=l;var f={};function d(){}function p(){}function m(){}var y={};s(y,o,function(){return this});var b=Object.getPrototypeOf,g=b&&b(b(M([])));g&&g!==t&&r.call(g,o)&&(y=g);var w=m.prototype=d.prototype=Object.create(y);function C(e){["next","throw","return"].forEach(function(t){s(e,t,function(e){return this._invoke(t,e)})})}function O(e,t){var i;n(this,"_invoke",{value:function(n,o){function u(){return new t(function(i,u){!function n(i,o,u,c){var s=h(e[i],e,o);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==a(f)&&r.call(f,"__await")?t.resolve(f.__await).then(function(e){n("next",e,u,c)},function(e){n("throw",e,u,c)}):t.resolve(f).then(function(e){l.value=e,u(l)},function(e){return n("throw",e,u,c)})}c(s.arg)}(n,o,i,u)})}return i=i?i.then(u,u):u()}})}function S(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 T()}for(r.method=i,r.arg=o;;){var u=r.delegate;if(u){var c=x(u,r);if(c){if(c===f)continue;return c}}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 a=h(e,t,r);if("normal"===a.type){if(n=r.done?"completed":"suspendedYield",a.arg===f)continue;return{value:a.arg,done:r.done}}"throw"===a.type&&(n="completed",r.method="throw",r.arg=a.arg)}}}function x(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,x(e,t),"throw"===t.method)||"return"!==r&&(t.method="throw",t.arg=new TypeError("The iterator does not provide a '"+r+"' method")),f;var i=h(n,e.iterator,t.arg);if("throw"===i.type)return t.method="throw",t.arg=i.arg,t.delegate=null,f;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,f):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,f)}function k(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 _(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(k,this),this.reset(!0)}function M(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,i=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return i.next=i}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=m,n(w,"constructor",{value:m,configurable:!0}),n(m,"constructor",{value:p,configurable:!0}),p.displayName=s(m,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,s(e,c,"GeneratorFunction")),e.prototype=Object.create(w),e},e.awrap=function(e){return{__await:e}},C(O.prototype),s(O.prototype,u,function(){return this}),e.AsyncIterator=O,e.async=function(t,r,n,i,o){void 0===o&&(o=Promise);var u=new O(l(t,r,n,i),o);return e.isGeneratorFunction(r)?u:u.next().then(function(e){return e.done?e.value:u.next()})},C(w),s(w,c,"Generator"),s(w,o,function(){return this}),s(w,"toString",function(){return"[object Generator]"}),e.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}},e.values=M,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(_),!e)for(var t in this)"t"===t.charAt(0)&&r.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 n(r,n){return u.type="throw",u.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],u=o.completion;if("root"===o.tryLoc)return n("end");if(o.tryLoc<=this.prev){var c=r.call(o,"catchLoc"),a=r.call(o,"finallyLoc");if(c&&a){if(this.prev<o.catchLoc)return n(o.catchLoc,!0);if(this.prev<o.finallyLoc)return n(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return n(o.catchLoc,!0)}else{if(!a)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return n(o.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.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 u=o?o.completion:{};return u.type=e,u.arg=t,o?(this.method="next",this.next=o.finallyLoc,f):this.complete(u)},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),f},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),_(r),f}},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;_(r)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:M(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},e}function m(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function y(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,g(n.key),n)}}function b(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e){var t=w(e,"string");return"symbol"===a(t)?t:String(t)}function w(e,t){if("object"!==a(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==a(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}var C=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&("get"in i?t.__esModule:!i.writable&&!i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),O=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),S=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&C(t,e,r);return O(t,e),t},x=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))(function(i,o){function u(e){try{a(n.next(e))}catch(t){o(t)}}function c(e){try{a(n.throw(e))}catch(t){o(t)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(u,c)}a((n=n.apply(e,t||[])).next())})},k=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.__firebase=exports.Notion=exports.Neurosity=void 0;var _=require("rxjs"),E=require("rxjs"),M=require("rxjs/operators"),T=require("rxjs/operators"),A=k(require("fast-deep-equal")),D=require("./api/index"),N=require("./api/index"),j=require("./types/streaming"),I=require("./utils/subscription"),P=require("./types/status"),F=S(require("./utils/errors")),L=S(require("./utils/platform")),R=S(require("./utils/hapticEffects")),B=require("./utils/oauth"),U=require("./utils/oauth"),G=require("./api/https/createOAuthURL"),q=require("./api/https/getOAuthToken"),H=require("./utils/is-node"),W=require("./utils/metrics"),Y=require("./api/bluetooth"),V=require("./api/bluetooth/types"),$={timesync:!1,autoSelectDevice:!0,streamingMode:j.STREAMING_MODE.WIFI_ONLY,emulator:!1,emulatorHost:"localhost",emulatorAuthPort:9099,emulatorDatabasePort:9e3,emulatorFunctionsPort:5001,emulatorFirestorePort:8080,emulatorOptions:{}},K=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};m(this,e),this.streamingMode$=new E.ReplaySubject(1);var r=t.streamingMode,n=t.bluetoothTransport;this.options=Object.freeze(Object.assign(Object.assign({},$),t)),this.cloudClient=new D.CloudClient(this.options),n&&(this.bluetoothClient=new Y.BluetoothClient({selectedDevice$:this.onDeviceChange(),osHasBluetoothSupport$:this._osHasBluetoothSupport(),createBluetoothToken:this.createBluetoothToken.bind(this),transport:n})),this._initStreamingMode(r,!!n)}return b(e,[{key:"_initStreamingMode",value:function(e,t){var r=[j.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK,j.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK].includes(e),n=!Object.values(j.STREAMING_MODE).includes(e),i=r&&!t;this.isMissingBluetoothTransport=i,!e||n||i?this.streamingMode$.next(j.STREAMING_MODE.WIFI_ONLY):this.streamingMode$.next(e)}},{key:"_osHasBluetoothSupport",value:function(){return(0,_.combineLatest)({selectedDevice:this.onDeviceChange(),osVersion:this.osVersion().pipe((0,M.startWith)(null))}).pipe((0,M.map)(function(e){var t=e.selectedDevice,r=e.osVersion;return(0,Y.osHasBluetoothSupport)(t,r)}))}},{key:"streamingState",value:function(){var e=this,t=function(e){return[P.STATUS.ONLINE,P.STATUS.UPDATING].includes(e)};return this.streamingMode$.pipe((0,M.switchMap)(function(r){return(0,_.combineLatest)({selectedDevice:e.onDeviceChange(),osHasBluetoothSupport:e._osHasBluetoothSupport()}).pipe((0,M.switchMap)(function(n){var i=n.selectedDevice,o=n.osHasBluetoothSupport;return i?e.isMissingBluetoothTransport||!o?e.cloudClient.status().pipe((0,M.map)(function(e){var n=e.state;return{connected:t(n),streamingMode:r,activeMode:j.STREAMING_TYPE.WIFI}})):(0,_.combineLatest)({wifiStatus:e.cloudClient.status(),bluetoothConnection:(null==e?void 0:e.bluetoothClient)?e.bluetoothClient.connection():(0,_.of)(V.BLUETOOTH_CONNECTION.DISCONNECTED)}).pipe((0,M.map)(function(e){var n=e.wifiStatus,i=e.bluetoothConnection===V.BLUETOOTH_CONNECTION.CONNECTED;switch(r){default:case j.STREAMING_MODE.WIFI_ONLY:return{connected:t(n.state),streamingMode:r,activeMode:j.STREAMING_TYPE.WIFI};case j.STREAMING_MODE.WIFI_WITH_BLUETOOTH_FALLBACK:return{connected:t(n.state)||!i?t(n.state):i,streamingMode:r,activeMode:t(n.state)||!i?j.STREAMING_TYPE.WIFI:j.STREAMING_TYPE.BLUETOOTH};case j.STREAMING_MODE.BLUETOOTH_WITH_WIFI_FALLBACK:return{connected:!!i||t(n.state),streamingMode:r,activeMode:i?j.STREAMING_TYPE.BLUETOOTH:j.STREAMING_TYPE.WIFI}}}),(0,T.distinctUntilChanged)(function(e,t){return(0,A.default)(e,t)})):(0,_.of)({connected:!1,streamingMode:r,activeMode:j.STREAMING_TYPE.WIFI})}))}))}},{key:"_withStreamingModeObservable",value:function(e){var t=e.wifi,r=e.bluetooth;return this.streamingState().pipe((0,M.switchMap)(function(e){switch(e.activeMode){case j.STREAMING_TYPE.WIFI:return t();case j.STREAMING_TYPE.BLUETOOTH:return r();default:return t()}}))}},{key:"_withStreamingModePromise",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return r=e.wifi,n=e.bluetooth,t.next=3,(0,E.firstValueFrom)(this.streamingState());case 3:i=t.sent,o=i.activeMode,t.t0=o,t.next=t.t0===j.STREAMING_TYPE.WIFI?8:t.t0===j.STREAMING_TYPE.BLUETOOTH?11:14;break;case 8:return t.next=10,r();case 10:return t.abrupt("return",t.sent);case 11:return t.next=13,n();case 13:return t.abrupt("return",t.sent);case 14:return t.next=16,r();case 16:return t.abrupt("return",t.sent);case 17:case"end":return t.stop()}},t,this)}))}},{key:"bluetooth",get:function(){return null==this?void 0:this.bluetoothClient}},{key:"_getCloudMetricDependencies",value:function(){return{options:this.options,cloudClient:this.cloudClient,onDeviceChange:this.onDeviceChange.bind(this),status:this.status.bind(this)}}},{key:"login",value:function(e){return x(this,void 0,void 0,v().mark(function t(){return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.login(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)}))}},{key:"logout",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.logout();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"__getApp",value:function(){return this.cloudClient.__getApp()}},{key:"onAuthStateChanged",value:function(){return this.cloudClient.onAuthStateChanged()}},{key:"addDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"addDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.addDevice(e)}},{key:"removeDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"removeDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.removeDevice(e)}},{key:"transferDevice",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"transferDevice"),2),r=t[0],n=t[1];return r?Promise.reject(n):this.cloudClient.transferDevice(e)}},{key:"onUserDevicesChange",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onUserDevicesChange"),2),t=e[0],r=e[1];return t?(0,_.throwError)(function(){return r}):this.cloudClient.onUserDevicesChange()}},{key:"onUserClaimsChange",value:function(){return this.cloudClient.onUserClaimsChange()}},{key:"getDevices",value:function(){return x(this,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.getDevices();case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"selectDevice",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"selectDevice"),n=s(r,2),i=n[0],o=n[1],!i){t.next=3;break}return t.abrupt("return",Promise.reject(o));case 3:return t.next=5,this.cloudClient.selectDevice(e);case 5:return t.abrupt("return",t.sent);case 6:case"end":return t.stop()}},t,this)}))}},{key:"getSelectedDevice",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t,r,n,i;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getSelectedDevice"),r=s(t,2),n=r[0],i=r[1],!n){e.next=3;break}return e.abrupt("return",Promise.reject(i));case 3:return e.next=5,this.cloudClient.getSelectedDevice();case 5:return e.abrupt("return",e.sent);case 6:case"end":return e.stop()}},e,this)}))}},{key:"getInfo",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t,r,n,i,o=this;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}return e.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(t=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"getInfo"),r=s(t,2),n=r[0],i=r[1],!n){e.next=7;break}return e.abrupt("return",Promise.reject(i));case 7:return e.next=9,this._withStreamingModePromise({wifi:function(){return o.cloudClient.getInfo()},bluetooth:function(){return o.bluetoothClient.getInfo()}});case 9:return e.abrupt("return",e.sent);case 10:case"end":return e.stop()}},e,this)}))}},{key:"onDeviceChange",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"onDeviceChange"),2),t=e[0],r=e[1];return t?(0,_.throwError)(function(){return r}):this.cloudClient.onDeviceChange()}},{key:"disconnect",value:function(){return x(this,void 0,void 0,v().mark(function e(){var t=this;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this._withStreamingModePromise({wifi:function(){return t.cloudClient.disconnect()},bluetooth:function(){return t.bluetoothClient.disconnect()}});case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)}))}},{key:"dispatchAction",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o,u=this;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(r=(0,U.validateOAuthScopeForAction)(this.cloudClient.userClaims,e),n=s(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this._withStreamingModePromise({wifi:function(){return u.cloudClient.dispatchAction(e)},bluetooth:function(){return u.bluetoothClient.dispatchAction(e)}});case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"addMarker",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r=this;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}throw F.mustSelectDevice;case 4:if(e){t.next=6;break}throw new Error("".concat(F.prefix,"A label is required for addMarker"));case 6:return t.next=8,this._withStreamingModePromise({wifi:function(){return r.cloudClient.dispatchAction({command:"marker",action:"add",message:{label:e,timestamp:r.cloudClient.timestamp}})},bluetooth:function(){return r.bluetoothClient.addMarker(e)}});case 8:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}},t,this)}))}},{key:"haptics",value:function(e){var t;return x(this,void 0,void 0,v().mark(function r(){var n,i,o,u,c,a,s=this;return v().wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return n="haptics",r.next=3,this.cloudClient.didSelectDevice();case 3:if(r.sent){r.next=5;break}return r.abrupt("return",Promise.reject(F.mustSelectDevice));case 5:return r.next=7,this.getSelectedDevice();case 7:if(r.t1=t=r.sent,r.t0=null===r.t1,r.t0){r.next=11;break}r.t0=void 0===t;case 11:if(!r.t0){r.next=15;break}r.t2=void 0,r.next=16;break;case 15:r.t2=t.modelVersion;case 16:if(i=r.t2,L.supportsHaptics(i)){r.next=20;break}return r.abrupt("return",Promise.reject(F.metricNotSupportedByModel(n,i)));case 20:o=L.getPlatformHapticMotors(i),r.t3=v().keys(e);case 22:if((r.t4=r.t3()).done){r.next=33;break}if(u=r.t4.value,Object.keys(o).includes(u)){r.next=26;break}return r.abrupt("return",Promise.reject(F.locationNotFound(u,i)));case 26:if(c=e[u],7,!(c.length>7)){r.next=30;break}return r.abrupt("return",Promise.reject(F.exceededMaxItems(7)));case 30:o[u]=c,r.next=22;break;case 33:return a={command:n,action:"queue",responseRequired:!0,responseTimeout:1e3,message:{effects:o}},r.next=36,this._withStreamingModePromise({wifi:function(){return s.cloudClient.dispatchAction(a)},bluetooth:function(){return s.bluetoothClient.dispatchAction(a)}});case 36:return r.abrupt("return",r.sent);case 37:case"end":return r.stop()}},r,this)}))}},{key:"getHapticEffects",value:function(){return R}},{key:"accelerometer",value:function(){var e=this,t="accelerometer",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,_.throwError)(function(){return i}):this.onDeviceChange().pipe((0,M.switchMap)(function(r){var n=(null==r?void 0:r.modelVersion)||L.MODEL_VERSION_1;return L.supportsAccel(n)?e._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,I.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.accelerometer()}}):(0,_.throwError)(function(){return F.metricNotSupportedByModel(t,n)})}))}},{key:"brainwaves",value:function(e){var t=this,r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"brainwaves"),2),n=r[0],i=r[1];return n?(0,_.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(t._getCloudMetricDependencies(),{metric:"brainwaves",labels:e?[e]:[],atomic:!1})},bluetooth:function(){return t.bluetoothClient.brainwaves(e)}})}},{key:"calm",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"calm"),2),r=t[0],n=t[1];return r?(0,_.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["calm"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.calm()}})}},{key:"signalQuality",value:function(){var e=this,t="signalQuality",r=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,t),2),n=r[0],i=r[1];return n?(0,_.throwError)(function(){return i}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:t,labels:(0,I.getLabels)(t),atomic:!0})},bluetooth:function(){return e.bluetoothClient.signalQuality()}})}},{key:"settings",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"settings"),2),t=e[0],r=e[1];return t?(0,_.throwError)(function(){return r}):this.cloudClient.observeNamespace("settings")}},{key:"osVersion",value:function(){var e=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"osVersion"),2),t=e[0],r=e[1];return t?(0,_.throwError)(function(){return r}):this.cloudClient.osVersion()}},{key:"focus",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"focus"),2),r=t[0],n=t[1];return r?(0,_.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return(0,W.getCloudMetric)(e._getCloudMetricDependencies(),{metric:"awareness",labels:["focus"],atomic:!1})},bluetooth:function(){return e.bluetoothClient.focus()}})}},{key:"kinesis",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"kinesis"),2),r=t[0],n=t[1];return r?(0,_.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"kinesis",labels:e?[e]:[],atomic:!1})}},{key:"predictions",value:function(e){var t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"predictions"),2),r=t[0],n=t[1];return r?(0,_.throwError)(function(){return n}):(0,W.getCloudMetric)(this._getCloudMetricDependencies(),{metric:"predictions",labels:e?[e]:[],atomic:!1})}},{key:"status",value:function(){var e=this,t=s((0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"status"),2),r=t[0],n=t[1];return r?(0,_.throwError)(function(){return n}):this._withStreamingModeObservable({wifi:function(){return e.cloudClient.status()},bluetooth:function(){return e.bluetoothClient.status()}})}},{key:"changeSettings",value:function(e){return x(this,void 0,void 0,v().mark(function t(){var r,n,i,o;return v().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.cloudClient.didSelectDevice();case 2:if(t.sent){t.next=4;break}return t.abrupt("return",Promise.reject(F.mustSelectDevice));case 4:if(r=(0,B.validateOAuthScopeForFunctionName)(this.cloudClient.userClaims,"changeSettings"),n=s(r,2),i=n[0],o=n[1],!i){t.next=7;break}return t.abrupt("return",Promise.reject(o));case 7:return t.next=9,this.cloudClient.changeSettings(e);case 9:return t.abrupt("return",t.sent);case 10:case"end":return t.stop()}},t,this)}))}},{key:"training",get:function(){var e=this;return{record:function(t){return x(e,void 0,void 0,v().mark(function e(){var r,n;return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return r=this.cloudClient.user&&"uid"in this.cloudClient.user?this.cloudClient.user.uid:null,n=Object.assign(Object.assign({fit:!1,baseline:!1,timestamp:this.cloudClient.timestamp},t),{userId:r}),e.next=8,this.cloudClient.actions.dispatch({command:"training",action:"record",message:n});case 8:case"end":return e.stop()}},e,this)}))},stop:function(t){return x(e,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stop",message:Object.assign({},t)});case 6:case"end":return e.stop()}},e,this)}))},stopAll:function(){return x(e,void 0,void 0,v().mark(function e(){return v().wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.cloudClient.didSelectDevice();case 2:if(e.sent){e.next=4;break}throw F.mustSelectDevice;case 4:return e.next=6,this.cloudClient.actions.dispatch({command:"training",action:"stopAll",message:{}});case 6:case"end":return e.stop()}},e,this)}))}}}},{key:"goOffline",value:function(){this.cloudClient.goOffline()}},{key:"goOnline",value:function(){this.cloudClient.goOnline()}},{key:"createAccount",value:function(e){return this.cloudClient.createAccount(e)}},{key:"deleteAccount",value:function(){return this.cloudClient.deleteAccount()}},{key:"createBluetoothToken",value:function(){return this.cloudClient.createBluetoothToken()}},{key:"createCustomToken",value:function(){return this.cloudClient.createCustomToken()}},{key:"getTimesyncOffset",value:function(){return this.options.timesync||console.warn("getTimesyncOffset() requires options.timesync to be true."),this.options.timesync?this.cloudClient.getTimesyncOffset():0}},{key:"createOAuthURL",value:function(e){return H.isNode?(0,G.createOAuthURL)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the createOAuthURL method must be used on the server side (node.js) for security reasons.")))}},{key:"getOAuthToken",value:function(e){return H.isNode?(0,q.getOAuthToken)(e,this.options):Promise.reject(new Error("".concat(F.prefix,"the getOAuthToken method must be used on the server side (node.js) for security reasons.")))}},{key:"removeOAuthAccess",value:function(){return this.cloudClient.removeOAuthAccess()}},{key:"onUserExperiments",value:function(){return this.cloudClient.onUserExperiments()}},{key:"deleteUserExperiment",value:function(e){return this.cloudClient.deleteUserExperiment(e)}}]),e}();exports.Neurosity=K,K.credentialWithLink=N.credentialWithLink,K.createUser=D.createUser,K.SERVER_TIMESTAMP=N.SERVER_TIMESTAMP;var Q=function(e){t(i,K);var r=n(i);function i(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return m(this,i),e=r.call(this,t),console.log("The Notion class is deprecated and will be removed in the next version of the SDK. Please use the Neurosity class instead. e.g. new Notion() => new Neurosity()"),e}return b(i)}();exports.Notion=Q;var z=require("./api/firebase");Object.defineProperty(exports,"__firebase",{enumerable:!0,get:function(){return z.__firebase}});
|
|
679
|
+
},{"rxjs":"Zr8e","rxjs/operators":"v3iE","fast-deep-equal":"jIGR","./api/index":"LXvB","./types/streaming":"rekm","./utils/subscription":"yLLB","./types/status":"Ttuy","./utils/errors":"WDyG","./utils/platform":"wAkn","./utils/hapticEffects":"lLai","./utils/oauth":"xIH5","./api/https/createOAuthURL":"MDrB","./api/https/getOAuthToken":"nfg4","./utils/is-node":"vsps","./utils/metrics":"DCuD","./api/bluetooth":"TICO","./api/bluetooth/types":"iwtf","./api/firebase":"kM30"}],"QCba":[function(require,module,exports) {
|
|
680
680
|
"use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var o=Object.getOwnPropertyDescriptor(t,r);o&&("get"in o?t.__esModule:!o.writable&&!o.configurable)||(o={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,o)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(r,i)||e(r,t,i)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./Neurosity"),exports),t(require("./api/bluetooth"),exports),t(require("./types/streaming"),exports);
|
|
681
681
|
},{"./Neurosity":"BZP9","./api/bluetooth":"TICO","./types/streaming":"rekm"}]},{},["QCba"], null)
|
|
682
682
|
//# sourceMappingURL=/neurosity.js.map
|