@cloudbase/js-sdk 2.5.22-beta.0 → 2.5.24-beta.0

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.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],t):"object"==typeof exports?exports.cloudbase_oauth=t():e.cloudbase_oauth=t()}("undefined"!=typeof window?window:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||t.hasOwnProperty(n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(2),t)},function(e,t,n){"use strict";var r,i;function o(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}n.r(t),n.d(t,"Syntax",(function(){return r})),n.d(t,"ErrorType",(function(){return i})),n.d(t,"defaultStorage",(function(){return _})),n.d(t,"defaultRequest",(function(){return h})),n.d(t,"toResponseError",(function(){return f})),n.d(t,"generateRequestId",(function(){return p})),n.d(t,"OAuth2Client",(function(){return I})),n.d(t,"AuthClient",(function(){return O})),n.d(t,"Auth",(function(){return w})),n.d(t,"authModels",(function(){return U})),n.d(t,"CloudbaseOAuth",(function(){return N})),function(e){e.CLIENT_ID="client_id",e.CLIENT_SECRET="client_secret",e.RESPONSE_TYPE="response_type",e.SCOPE="scope",e.STATE="state",e.REDIRECT_URI="redirect_uri",e.ERROR="error",e.ERROR_DESCRIPTION="error_description",e.ERROR_URI="error_uri",e.GRANT_TYPE="grant_type",e.CODE="code",e.ACCESS_TOKEN="access_token",e.TOKEN_TYPE="token_type",e.EXPIRES_IN="expires_in",e.USERNAME="username",e.PASSWORD="password",e.REFRESH_TOKEN="refresh_token"}(r||(r={})),function(e){e.UNREACHABLE="unreachable",e.LOCAL="local",e.CANCELLED="cancelled",e.UNKNOWN="unknown",e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.UNAUTHENTICATED="unauthenticated",e.RESOURCE_EXHAUSTED="resource_exhausted",e.FAILED_PRECONDITION="failed_precondition",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked",e.INVALID_VERIFICATION_CODE="invalid_verification_code",e.TWO_FACTOR_REQUIRED="two_factor_required",e.INVALID_TWO_FACTOR="invalid_two_factor",e.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",e.UNDER_REVIEW="under_review",e.INVALID_REQUEST="invalid_request",e.UNAUTHORIZED_CLIENT="unauthorized_client",e.ACCESS_DENIED="access_denied",e.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",e.INVALID_SCOPE="invalid_scope",e.INVALID_GRANT="invalid_grant",e.SERVER_ERROR="server_error",e.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",e.INTERACTION_REQUIRED="interaction_required",e.LOGIN_REQUIRED="login_required",e.ACCOUNT_SELECTION_REQUIRED="account_selection_required",e.CONSENT_REQUIRED="consent_required",e.INVALID_REQUEST_URI="invalid_request_uri",e.INVALID_REQUEST_OBJECT="invalid_request_object",e.REQUEST_NOT_SUPPORTED="request_not_supported",e.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",e.REGISTRATION_NOT_SUPPORTED="registration_not_supported"}(i||(i={}));var s=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},u=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},a=function(){function e(){this.fnPromiseMap=new Map}return e.prototype.run=function(e,t){return s(this,void 0,void 0,(function(){var n,r=this;return u(this,(function(i){switch(i.label){case 0:return[4,n=this.fnPromiseMap.get(e)];case 1:return i.sent()||(n=new Promise((function(n,i){s(r,void 0,void 0,(function(){var r,o,s;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,3,4,5]),[4,this.runIdlePromise()];case 1:return u.sent(),r=t(),o=n,[4,r];case 2:return o.apply(void 0,[u.sent()]),[3,5];case 3:return s=u.sent(),i(s),[3,5];case 4:return this.fnPromiseMap.delete(e),[7];case 5:return[2]}}))}))})),this.fnPromiseMap.set(e,n)),[2,n]}}))}))},e.prototype.runIdlePromise=function(){return Promise.resolve()},e}(),c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},l=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},d=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},h=function(e,t){return l(this,void 0,void 0,(function(){var n,r,o,s,u;return d(this,(function(a){switch(a.label){case 0:n=null,r=null,a.label=1;case 1:return a.trys.push([1,4,,5]),(o=Object.assign({},t)).method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)),[4,fetch(e,o)];case 2:return[4,a.sent().json()];case 3:return(null==(s=a.sent())?void 0:s.error)?(r=s).error_uri=new URL(e).pathname:n=s,[3,5];case 4:return u=a.sent(),r={error:i.UNREACHABLE,error_description:u.message,error_uri:new URL(e).pathname},[3,5];case 5:if(r)throw r;return[2,n]}}))}))},f=function(e,t){var n,r=t||{};if(e instanceof Error)n={error:r.error||i.LOCAL,error_description:r.error_description||e.message,error_uri:r.error_uri,details:r.details||e.stack};else{var o=e||{};n={error:r.error||o.error||i.LOCAL,error_description:r.error_description||o.error_description,error_uri:r.error_uri||o.error_uri,details:r.details||o.details}}return n};function p(){return o()}var _=new(function(){function e(){}return e.prototype.getItem=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return[2,window.localStorage.getItem(e)]}))}))},e.prototype.removeItem=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return window.localStorage.removeItem(e),[2]}))}))},e.prototype.setItem=function(e,t){return l(this,void 0,void 0,(function(){return d(this,(function(n){return window.localStorage.setItem(e,t),[2]}))}))},e.prototype.getItemSync=function(e){return window.localStorage.getItem(e)},e.prototype.removeItemSync=function(e){window.localStorage.removeItem(e)},e.prototype.setItemSync=function(e,t){window.localStorage.setItem(e,t)},e}());function v(e){var t=!0;return(null==e?void 0:e.expires_at)&&(null==e?void 0:e.access_token)&&(t=e.expires_at<new Date),t}var y,E,g,R=function(){function e(e){this.credentials=null,this.singlePromise=new a,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage}return e.prototype.getStorageCredentialsSync=function(){var e=null,t=this.storage.getItemSync(this.tokenSectionName);if(null!=t)try{(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at))}catch(t){this.storage.removeItem(this.tokenSectionName),e=null}return e},e.prototype.setCredentials=function(e){return l(this,void 0,void 0,(function(){var t;return d(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.expires_in)?(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30)),this.storage?(t=JSON.stringify(e),[4,this.storage.setItem(this.tokenSectionName,t)]):[3,2]):[3,3];case 1:n.sent(),n.label=2;case 2:return this.credentials=e,[3,6];case 3:return this.storage?[4,this.storage.removeItem(this.tokenSectionName)]:[3,5];case 4:n.sent(),n.label=5;case 5:this.credentials=null,n.label=6;case 6:return[2]}}))}))},e.prototype.getCredentials=function(){return l(this,void 0,void 0,(function(){var e=this;return d(this,(function(t){return[2,this.singlePromise.run("getCredentials",(function(){return l(e,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return v(this.credentials)?(e=this,[4,this.getStorageCredentials()]):[3,2];case 1:e.credentials=t.sent(),t.label=2;case 2:return[2,this.credentials]}}))}))}))]}))}))},e.prototype.getStorageCredentials=function(){return l(this,void 0,void 0,(function(){var e=this;return d(this,(function(t){return[2,this.singlePromise.run("_getStorageCredentials",(function(){return l(e,void 0,void 0,(function(){var e,t;return d(this,(function(n){switch(n.label){case 0:return e=null,[4,this.storage.getItem(this.tokenSectionName)];case 1:if(null==(t=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),[3,5];case 3:return n.sent(),[4,this.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),e=null,[3,5];case 5:return[2,e]}}))}))}))]}))}))},e}(),I=function(){function e(t){this.singlePromise=new a,this.apiOrigin=t.apiOrigin,this.clientId=t.clientId,this.retry=this.formatRetry(t.retry,e.defaultRetry),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=h,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||_,this.localCredentials=new R({tokenSectionName:"credentials_"+t.clientId,storage:this.storage}),this.clientSecret=t.clientSecret,this.refreshTokenFunc=t.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=t.anonymousSignInFunc}return e.prototype.setCredentials=function(e){return this.localCredentials.setCredentials(e)},e.prototype.getAccessToken=function(){return l(this,void 0,void 0,(function(){var e,t;return d(this,(function(n){switch(n.label){case 0:return[4,this.getCredentials()];case 1:return(null==(e=n.sent())?void 0:e.access_token)?[2,Promise.resolve(e.access_token)]:(t={error:i.UNAUTHENTICATED},[2,Promise.reject(t)])}}))}))},e.prototype.request=function(t,n){return l(this,void 0,void 0,(function(){var r,o,s,u,a,l,h;return d(this,(function(d){switch(d.label){case 0:return n||(n={}),r=this.formatRetry(n.retry,this.retry),n.headers=n.headers||{},this.headers&&(n.headers=c(c({},this.headers),n.headers)),n.headers["x-request-id"]||(n.headers["x-request-id"]=p()),n.headers["x-device-id"]?[3,2]:[4,this.getDeviceId()];case 1:o=d.sent(),n.headers["x-device-id"]=o,d.label=2;case 2:return(null==n?void 0:n.withCredentials)?[4,this.getCredentials()]:[3,4];case 3:return(s=d.sent())&&(this.tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token="+s.access_token):n.headers.Authorization=s.token_type+" "+s.access_token),[3,5];case 4:this.clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id="+this.clientId),d.label=5;case 5:t.startsWith("/")&&(t=this.apiOrigin+t),u=null,a=r+1,l=0,d.label=6;case 6:if(!(l<a))return[3,15];d.label=7;case 7:return d.trys.push([7,9,,12]),[4,this.baseRequest(t,n)];case 8:return u=d.sent(),[3,15];case 9:return h=d.sent(),n.withCredentials&&h&&h.error===i.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,11];case 10:return d.sent(),[2,Promise.reject(h)];case 11:return l!==r&&h&&"unreachable"===h.error?[3,12]:[2,Promise.reject(h)];case 12:return[4,this.sleep(e.retryInterval)];case 13:d.sent(),d.label=14;case 14:return l++,[3,6];case 15:return[2,u]}}))}))},e.prototype.getCredentials=function(){return l(this,void 0,void 0,(function(){var e,t,n;return d(this,(function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return v(e=r.sent())?e&&"anonymous"===e.scope?this.anonymousSignInFunc?[4,this.anonymousSignInFunc(e)]:[3,5]:[3,8]:[3,10];case 2:return t=r.sent(),(n=t)?[3,4]:[4,this.localCredentials.getCredentials()];case 3:n=r.sent(),r.label=4;case 4:return e=n,[3,7];case 5:return[4,this.anonymousSignIn(e)];case 6:e=r.sent(),r.label=7;case 7:return[3,10];case 8:return[4,this.refreshToken(e)];case 9:e=r.sent(),r.label=10;case 10:return[2,e]}}))}))},e.prototype.getCredentialsSync=function(){return this.localCredentials.getStorageCredentialsSync()},e.prototype.getCredentialsAsync=function(){return this.getCredentials()},e.prototype.getScope=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=t.sent())?[2,e.scope]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},e.prototype.getGroups=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(e=t.sent())?[2,e.groups]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},e.prototype.checkRetry=function(t){var n=null;if(("number"!=typeof t||t<e.minRetry||t>e.maxRetry)&&(n={error:i.UNREACHABLE,error_description:"wrong options param: retry"}),n)throw n;return t},e.prototype.formatRetry=function(e,t){return void 0===e?t:this.checkRetry(e)},e.prototype.sleep=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return[2,new Promise((function(t){setTimeout((function(){t()}),e)}))]}))}))},e.prototype.refreshToken=function(e){return l(this,void 0,void 0,(function(){var t=this;return d(this,(function(n){return[2,this.singlePromise.run("_refreshToken",(function(){return l(t,void 0,void 0,(function(){var t,n;return d(this,(function(r){switch(r.label){case 0:if(!e||!e.refresh_token)return[2,this.unAuthenticatedError("no refresh token found in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.refreshTokenFunc(e.refresh_token)];case 2:return t=r.sent(),[4,this.localCredentials.setCredentials(t)];case 3:return r.sent(),[2,t];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},e.prototype.anonymousSignIn=function(e){return l(this,void 0,void 0,(function(){var t=this;return d(this,(function(n){return[2,this.singlePromise.run("_anonymous",(function(){return l(t,void 0,void 0,(function(){var t,n;return d(this,(function(r){switch(r.label){case 0:if(!e||"anonymous"!==e.scope)return[2,this.unAuthenticatedError("no anonymous in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.request("/auth/v1/signin/anonymously",{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret}})];case 2:return t=r.sent(),[4,this.localCredentials.setCredentials(t)];case 3:return r.sent(),[2,t];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},e.prototype.defaultRefreshTokenFunc=function(e){return void 0===e||""===e?this.unAuthenticatedError("refresh token not found"):this.request("/auth/v1/token",{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"refresh_token",refresh_token:e}})},e.prototype.getDeviceId=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return this.deviceID?[2,this.deviceID]:[4,this.storage.getItem("device_id")];case 1:return"string"==typeof(e=t.sent())&&e.length>=16&&e.length<=48?[3,3]:(e=o(),[4,this.storage.setItem("device_id",e)]);case 2:t.sent(),t.label=3;case 3:return this.deviceID=e,[2,e]}}))}))},e.prototype.unAuthenticatedError=function(e){var t={error:i.UNAUTHENTICATED,error_description:e};return Promise.reject(t)},e.defaultRetry=2,e.minRetry=0,e.maxRetry=5,e.retryInterval=1e3,e}();!function(e){e.AUTH_SIGN_IN_URL="/auth/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/auth/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v1/signin/with/provider",e.AUTH_SIGN_UP_URL="/auth/v1/signup",e.AUTH_TOKEN_URL="/auth/v1/token",e.AUTH_REVOKE_URL="/auth/v1/revoke",e.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",e.PROVIDER_TOKEN_URL="/auth/v1/provider/token",e.PROVIDER_URI_URL="/auth/v1/provider/uri",e.USER_ME_URL="/auth/v1/user/me",e.USER_QUERY_URL="/auth/v1/user/query",e.USER_PRIFILE_URL="/auth/v1/user/profile",e.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",e.VERIFICATION_URL="/auth/v1/verification",e.VERIFY_URL="/auth/v1/verification/verify",e.PROVIDER_LIST="/auth/v1/user/provider",e.PROVIDER_UNBIND_URL="/auth/v1/user/provider",e.CHECK_PWD_URL="/auth/v1/user/sudo",e.SUDO_URL="/auth/v1/user/sudo",e.BIND_CONTACT_URL="/auth/v1/user/contact",e.AUTH_SET_PASSWORD="/auth/v1/user/password",e.AUTH_RESET_PASSWORD="/auth/v1/reset",e.AUTH_GET_DEVICE_CODE="/auth/v1/device/code",e.CHECK_USERNAME="/auth/v1/checkUsername",e.CHECK_IF_USER_EXIST="/auth/v1/checkIfUserExist"}(y||(y={})),function(e){e.REGISTER="REGISTER",e.SIGN_IN="SIGN_IN",e.PASSWORD_RESET="PASSWORD_RESET",e.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",e.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(E||(E={})),function(e){e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.PASSWORD_NOT_SET="password_not_set",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked"}(g||(g={}));var S=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},T=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},b=function(){function e(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=_),this.config=e,this.tokenSectionName="captcha_"+e.clientId}return e.prototype.request=function(e,t){return S(this,void 0,void 0,(function(){var n,r,i,o;return T(this,(function(s){switch(s.label){case 0:return t||(t={}),t.method||(t.method="GET"),n=t.method+":"+e,r=e,t.withCaptcha?[4,this.appendCaptchaTokenToURL(e,n,!1)]:[3,2];case 1:r=s.sent(),s.label=2;case 2:return s.trys.push([2,4,,7]),[4,this.config.request(r,t)];case 3:return i=s.sent(),[3,7];case 4:return"captcha_required"!==(o=s.sent()).error&&"captcha_invalid"!==o.error?[3,6]:[4,this.appendCaptchaTokenToURL(e,n,"captcha_invalid"===o.error)];case 5:return e=s.sent(),[2,this.config.request(e,t)];case 6:return[2,Promise.reject(o)];case 7:return[2,i]}}))}))},e.prototype.getDefaultOpenURIWithCallback=function(){if(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap")){var e=document.createElement("div");e.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",e.setAttribute("id","captcha_panel_wrap"),setTimeout((function(){document.body.appendChild(e)}),0)}return this.defaultOpenURIWithCallback},e.prototype.defaultOpenURIWithCallback=function(e){return S(this,void 0,void 0,(function(){var t,n;return T(this,(function(r){return t=document.getElementById("captcha_panel_wrap"),n=document.createElement("iframe"),t.innerHTML="",n.setAttribute("src",e),n.setAttribute("id","review-panel-iframe"),n.style.cssText="min-width:355px;display:block;height:355px;margin:0 auto;background-color: rgb(255, 255, 255);border: none;",t.appendChild(n),t.style.display="block",[2,new Promise((function(e,r){n.onload=function(){try{var i=window.location,o=n.contentWindow.location;if(o.host+o.pathname===i.host+i.pathname){t.style.display="none";var s=new URLSearchParams(o.search),u=s.get("captcha_token");return u?e({captcha_token:u,expires_in:Number(s.get("expires_in"))}):r({error:s.get("error"),error_description:s.get("error_description")})}t.style.display="block"}catch(e){t.style.display="block"}}}))]}))}))},e.prototype.getCaptchaToken=function(e,t){return S(this,void 0,void 0,(function(){var n,r,i,o,s;return T(this,(function(u){switch(u.label){case 0:return e?[3,2]:[4,this.findCaptchaToken()];case 1:if(n=u.sent())return[2,n];u.label=2;case 2:return r=window.location.origin+window.location.pathname+"?__captcha=on",[4,this.config.request("/auth/v1/captcha/init",{method:"POST",body:{client_id:this.config.clientId,redirect_uri:r,state:t},withCredentials:!1})];case 3:return(i=u.sent()).captcha_token?(o={captcha_token:i.captcha_token,expires_in:i.expires_in},this.saveCaptchaToken(o),[2,i.captcha_token]):[4,this.config.openURIWithCallback(i.url)];case 4:return s=u.sent(),this.saveCaptchaToken(s),[2,s.captcha_token]}}))}))},e.prototype.appendCaptchaTokenToURL=function(e,t,n){return S(this,void 0,void 0,(function(){var r;return T(this,(function(i){switch(i.label){case 0:return[4,this.getCaptchaToken(n,t)];case 1:return r=i.sent(),e.indexOf("?")>0?e+="&captcha_token="+r:e+="?captcha_token="+r,[2,e]}}))}))},e.prototype.saveCaptchaToken=function(e){return S(this,void 0,void 0,(function(){var t;return T(this,(function(n){switch(n.label){case 0:return e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10)),t=JSON.stringify(e),[4,this.config.storage.setItem(this.tokenSectionName,t)];case 1:return n.sent(),[2]}}))}))},e.prototype.findCaptchaToken=function(){return S(this,void 0,void 0,(function(){var e,t;return T(this,(function(n){switch(n.label){case 0:return[4,this.config.storage.getItem(this.tokenSectionName)];case 1:if(null==(e=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),t.expires_at<new Date?[2,null]:[2,t.captcha_token];case 3:return n.sent(),[4,this.config.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),[2,null];case 5:return[2,null]}}))}))},e}(),m=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},C=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},w=function(){function e(e){var t=e.request,n=e.credentialsClient;if(!n){var r={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage};n=new I(r)}if(!t){var i=n.request.bind(n),o=new b({clientId:e.clientId,request:i,storage:e.storage});t=o.request.bind(o)}this.config={apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:n,storage:e.storage||_}}return e.parseParamsToSearch=function(e){return Object.keys(e).forEach((function(t){e[t]||delete e[t]})),new URLSearchParams(e).toString()},e.prototype.signIn=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.request(y.AUTH_SIGN_IN_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this.config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signInAnonymously=function(e){return void 0===e&&(e={}),m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.request(y.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this.config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signUp=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.request(y.AUTH_SIGN_UP_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this.config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signOut=function(){return m(this,void 0,void 0,(function(){var e,t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.credentialsClient.getAccessToken()];case 1:return e=n.sent(),[4,this.config.request(y.AUTH_REVOKE_URL,{method:"POST",body:{token:e}})];case 2:return t=n.sent(),[4,this.config.credentialsClient.setCredentials()];case 3:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.getVerification=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return t=!1,"CUR_USER"!==e.target?[3,1]:(t=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:n.sent()&&(t=!0),n.label=3;case 3:return[2,this.config.request(y.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:!0,withCredentials:t})]}}))}))},e.prototype.verify=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.VERIFY_URL,{method:"POST",body:e})]}))}))},e.prototype.genProviderRedirectUri=function(e){return m(this,void 0,void 0,(function(){var t,n;return C(this,(function(r){return t=y.PROVIDER_URI_URL+"?client_id="+this.config.clientId+"&provider_id="+e.provider_id+"&redirect_uri="+encodeURIComponent(e.provider_redirect_uri)+"&state="+e.state,(n=e.other_params)&&"string"==typeof n.sign_out_uri&&n.sign_out_uri.length>0&&(t+="&other_params[sign_out_uri]="+n.sign_out_uri),[2,this.config.request(t,{method:"GET"})]}))}))},e.prototype.grantProviderToken=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.patchProviderToken=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})]}))}))},e.prototype.signInWithProvider=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.request(y.AUTH_SIGN_IN_WITH_PROVIDER_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this.config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.bindWithProvider=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.getUserProfile=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.getUserInfo()]}))}))},e.prototype.getUserInfo=function(){return m(this,void 0,void 0,(function(){var e;return C(this,(function(t){switch(t.label){case 0:return[4,this.config.request(y.USER_ME_URL,{method:"GET",withCredentials:!0})];case 1:return(e=t.sent()).sub&&(e.uid=e.sub),[2,e]}}))}))},e.prototype.deleteMe=function(t){return m(this,void 0,void 0,(function(){var n;return C(this,(function(r){return n=y.USER_ME_URL+"?"+e.parseParamsToSearch(t),[2,this.config.request(n,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.hasLoginState=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this.config.credentialsClient.getAccessToken()];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},e.prototype.hasLoginStateSync=function(){return this.config.credentialsClient.getCredentialsSync()},e.prototype.getLoginState=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getCredentialsAsync()]}))}))},e.prototype.transByProvider=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.grantToken=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.getProviders=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.request(y.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},e.prototype.unbindProvider=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_UNBIND_URL+"/"+e.provider_id,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.checkPassword=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.CHECK_PWD_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.bindPhone=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.bindEmail=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.setPassword=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.AUTH_SET_PASSWORD,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.updatePasswordByOld=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.sudo({password:e.old_password})];case 1:return t=n.sent(),[2,this.setPassword({sudo_token:t.sudo_token,new_password:e.new_password})]}}))}))},e.prototype.sudo=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.SUDO_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.getCurUserVerification=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return e.target="CUR_USER",[2,this.config.request(y.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})]}))}))},e.prototype.changeBindedProvider=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_LIST+"/"+e.provider_id+"/trans",{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})]}))}))},e.prototype.setUserProfile=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.queryUserProfile=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){return t=new URLSearchParams(e),[2,this.config.request(y.USER_QUERY_URL+"?"+t.toString(),{method:"GET",withCredentials:!0})]}))}))},e.prototype.setCustomSignFunc=function(e){this.getCustomSignTicketFn=e},e.prototype.signInWithCustomTicket=function(){return m(this,void 0,void 0,(function(){var e;return C(this,(function(t){switch(t.label){case 0:return[4,this.getCustomSignTicketFn()];case 1:return e=t.sent(),[2,this.signInWithProvider({provider_id:"custom",provider_token:e})]}}))}))},e.prototype.resetPassword=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_RESET_PASSWORD,{method:"POST",body:e})]}))}))},e.prototype.deviceAuthorize=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.checkUsername=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})]}))}))},e.prototype.checkIfUserExist=function(e){return m(this,void 0,void 0,(function(){var t;return C(this,(function(n){return t=new URLSearchParams(e),[2,this.config.request(y.CHECK_IF_USER_EXIST+"?"+t.toString(),{method:"GET"})]}))}))},e.prototype.loginScope=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getScope()]}))}))},e.prototype.loginGroups=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getGroups()]}))}))},e}(),U=n(0),O=function(){},A=function(){return(A=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},N=function(e){var t=e.apiOrigin,n=e.clientId,r=e.storage,i=e.request,o=e.anonymousSignInFunc;this.oauth2client=new I({apiOrigin:t,clientId:n,storage:r,baseRequest:i,anonymousSignInFunc:o}),this.authApi=new w(A(A({credentialsClient:this.oauth2client},e),{request:i?this.oauth2client.request.bind(this.oauth2client):void 0}))}}])}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],e):"object"==typeof exports?exports.cloudbase_oauth=e():t.cloudbase_oauth=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={543:(t,e,n)=>{n.r(e),n.d(e,{Auth:()=>N,AuthClient:()=>P,CloudbaseOAuth:()=>L,ErrorType:()=>i,OAuth2Client:()=>m,Syntax:()=>r,authModels:()=>o,defaultRequest:()=>v,defaultStorage:()=>g,generateRequestId:()=>E,toResponseError:()=>y});var r,i,o={};function s(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}n.r(o),function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(r||(r={})),function(t){t.UNREACHABLE="unreachable",t.LOCAL="local",t.CANCELLED="cancelled",t.UNKNOWN="unknown",t.INVALID_ARGUMENT="invalid_argument",t.DEADLINE_EXCEEDED="deadline_exceeded",t.NOT_FOUND="not_found",t.ALREADY_EXISTS="already_exists",t.PERMISSION_DENIED="permission_denied",t.UNAUTHENTICATED="unauthenticated",t.RESOURCE_EXHAUSTED="resource_exhausted",t.FAILED_PRECONDITION="failed_precondition",t.ABORTED="aborted",t.OUT_OF_RANGE="out_of_range",t.UNIMPLEMENTED="unimplemented",t.INTERNAL="internal",t.UNAVAILABLE="unavailable",t.DATA_LOSS="data_loss",t.CAPTCHA_REQUIRED="captcha_required",t.CAPTCHA_INVALID="captcha_invalid",t.INVALID_PASSWORD="invalid_password",t.INVALID_STATUS="invalid_status",t.USER_PENDING="user_pending",t.USER_BLOCKED="user_blocked",t.INVALID_VERIFICATION_CODE="invalid_verification_code",t.TWO_FACTOR_REQUIRED="two_factor_required",t.INVALID_TWO_FACTOR="invalid_two_factor",t.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",t.UNDER_REVIEW="under_review",t.INVALID_REQUEST="invalid_request",t.UNAUTHORIZED_CLIENT="unauthorized_client",t.ACCESS_DENIED="access_denied",t.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",t.INVALID_SCOPE="invalid_scope",t.INVALID_GRANT="invalid_grant",t.SERVER_ERROR="server_error",t.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",t.INTERACTION_REQUIRED="interaction_required",t.LOGIN_REQUIRED="login_required",t.ACCOUNT_SELECTION_REQUIRED="account_selection_required",t.CONSENT_REQUIRED="consent_required",t.INVALID_REQUEST_URI="invalid_request_uri",t.INVALID_REQUEST_OBJECT="invalid_request_object",t.REQUEST_NOT_SUPPORTED="request_not_supported",t.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",t.REGISTRATION_NOT_SUPPORTED="registration_not_supported"}(i||(i={}));var a=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))},u=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},c=function(){function t(){this.fnPromiseMap=new Map}return t.prototype.run=function(t,e){return a(this,void 0,void 0,(function(){var n,r=this;return u(this,(function(i){switch(i.label){case 0:return[4,n=this.fnPromiseMap.get(t)];case 1:return i.sent()||(n=new Promise((function(n,i){a(r,void 0,void 0,(function(){var r,o,s;return u(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,4,5]),[4,this.runIdlePromise()];case 1:return a.sent(),r=e(),o=n,[4,r];case 2:return o.apply(void 0,[a.sent()]),[3,5];case 3:return s=a.sent(),i(s),[3,5];case 4:return this.fnPromiseMap.delete(t),[7];case 5:return[2]}}))}))})),this.fnPromiseMap.set(t,n)),[2,n]}}))}))},t.prototype.runIdlePromise=function(){return Promise.resolve()},t}(),l=function(){return l=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},l.apply(this,arguments)},h=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))},d=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},f="x-request-id",p="x-device-id",_="device_id",v=function(t,e){return h(this,void 0,void 0,(function(){var n,r,o,s,a;return d(this,(function(u){switch(u.label){case 0:n=null,r=null,u.label=1;case 1:return u.trys.push([1,4,,5]),(o=Object.assign({},e)).method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)),[4,fetch(t,o)];case 2:return[4,u.sent().json()];case 3:return(null==(s=u.sent())?void 0:s.error)?(r=s).error_uri=new URL(t).pathname:n=s,[3,5];case 4:return a=u.sent(),r={error:i.UNREACHABLE,error_description:a.message,error_uri:new URL(t).pathname},[3,5];case 5:if(r)throw r;return[2,n]}}))}))},y=function(t,e){var n,r=e||{};if(t instanceof Error)n={error:r.error||i.LOCAL,error_description:r.error_description||t.message,error_uri:r.error_uri,details:r.details||t.stack};else{var o=t||{};n={error:r.error||o.error||i.LOCAL,error_description:r.error_description||o.error_description,error_uri:r.error_uri||o.error_uri,details:r.details||o.details}}return n};function E(){return s()}var g=new(function(){function t(){}return t.prototype.getItem=function(t){return h(this,void 0,void 0,(function(){return d(this,(function(e){return[2,window.localStorage.getItem(t)]}))}))},t.prototype.removeItem=function(t){return h(this,void 0,void 0,(function(){return d(this,(function(e){return window.localStorage.removeItem(t),[2]}))}))},t.prototype.setItem=function(t,e){return h(this,void 0,void 0,(function(){return d(this,(function(n){return window.localStorage.setItem(t,e),[2]}))}))},t.prototype.getItemSync=function(t){return window.localStorage.getItem(t)},t.prototype.removeItemSync=function(t){window.localStorage.removeItem(t)},t.prototype.setItemSync=function(t,e){window.localStorage.setItem(t,e)},t}());function R(t){var e=!0;return(null==t?void 0:t.expires_at)&&(null==t?void 0:t.access_token)&&(e=t.expires_at<new Date),e}var I,S,T,b=function(){function t(t){this.credentials=null,this.singlePromise=new c,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage}return t.prototype.getStorageCredentialsSync=function(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t},t.prototype.setCredentials=function(t){return h(this,void 0,void 0,(function(){var e;return d(this,(function(n){switch(n.label){case 0:return(null==t?void 0:t.expires_in)?(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30)),this.storage?(e=JSON.stringify(t),[4,this.storage.setItem(this.tokenSectionName,e)]):[3,2]):[3,3];case 1:n.sent(),n.label=2;case 2:return this.credentials=t,[3,6];case 3:return this.storage?[4,this.storage.removeItem(this.tokenSectionName)]:[3,5];case 4:n.sent(),n.label=5;case 5:this.credentials=null,n.label=6;case 6:return[2]}}))}))},t.prototype.getCredentials=function(){return h(this,void 0,void 0,(function(){var t=this;return d(this,(function(e){return[2,this.singlePromise.run("getCredentials",(function(){return h(t,void 0,void 0,(function(){var t;return d(this,(function(e){switch(e.label){case 0:return R(this.credentials)?(t=this,[4,this.getStorageCredentials()]):[3,2];case 1:t.credentials=e.sent(),e.label=2;case 2:return[2,this.credentials]}}))}))}))]}))}))},t.prototype.getStorageCredentials=function(){return h(this,void 0,void 0,(function(){var t=this;return d(this,(function(e){return[2,this.singlePromise.run("_getStorageCredentials",(function(){return h(t,void 0,void 0,(function(){var t,e;return d(this,(function(n){switch(n.label){case 0:return t=null,[4,this.storage.getItem(this.tokenSectionName)];case 1:if(null==(e=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),[3,5];case 3:return n.sent(),[4,this.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),t=null,[3,5];case 5:return[2,t]}}))}))}))]}))}))},t}(),m=function(){function t(e){this.singlePromise=new c,this.apiOrigin=e.apiOrigin,this.clientId=e.clientId,this.retry=this.formatRetry(e.retry,t.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=v,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||g,this.localCredentials=new b({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage}),this.clientSecret=e.clientSecret,this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc}return t.prototype.setCredentials=function(t){return this.localCredentials.setCredentials(t)},t.prototype.getAccessToken=function(){return h(this,void 0,void 0,(function(){var t,e;return d(this,(function(n){switch(n.label){case 0:return[4,this.getCredentials()];case 1:return(null==(t=n.sent())?void 0:t.access_token)?[2,Promise.resolve(t.access_token)]:(e={error:i.UNAUTHENTICATED},[2,Promise.reject(e)])}}))}))},t.prototype.request=function(e,n){return h(this,void 0,void 0,(function(){var r,o,s,a,u,c,h;return d(this,(function(d){switch(d.label){case 0:return n||(n={}),r=this.formatRetry(n.retry,this.retry),n.headers=n.headers||{},this.headers&&(n.headers=l(l({},this.headers),n.headers)),n.headers[f]||(n.headers[f]=E()),n.headers[p]?[3,2]:[4,this.getDeviceId()];case 1:o=d.sent(),n.headers[p]=o,d.label=2;case 2:return(null==n?void 0:n.withCredentials)?[4,this.getCredentials()]:[3,4];case 3:return(s=d.sent())&&(this.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(s.access_token)):n.headers.Authorization="".concat(s.token_type," ").concat(s.access_token)),[3,5];case 4:this.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(this.clientId)),d.label=5;case 5:e.startsWith("/")&&(e=this.apiOrigin+e),a=null,u=r+1,c=0,d.label=6;case 6:if(!(c<u))return[3,15];d.label=7;case 7:return d.trys.push([7,9,,12]),[4,this.baseRequest(e,n)];case 8:return a=d.sent(),[3,15];case 9:return h=d.sent(),n.withCredentials&&h&&h.error===i.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,11];case 10:return d.sent(),[2,Promise.reject(h)];case 11:return c!==r&&h&&"unreachable"===h.error?[3,12]:[2,Promise.reject(h)];case 12:return[4,this.sleep(t.retryInterval)];case 13:d.sent(),d.label=14;case 14:return c++,[3,6];case 15:return[2,a]}}))}))},t.prototype.getCredentials=function(){return h(this,void 0,void 0,(function(){var t,e,n;return d(this,(function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return R(t=r.sent())?t&&"anonymous"===t.scope?this.anonymousSignInFunc?[4,this.anonymousSignInFunc(t)]:[3,5]:[3,8]:[3,10];case 2:return e=r.sent(),(n=e)?[3,4]:[4,this.localCredentials.getCredentials()];case 3:n=r.sent(),r.label=4;case 4:return t=n,[3,7];case 5:return[4,this.anonymousSignIn(t)];case 6:t=r.sent(),r.label=7;case 7:return[3,10];case 8:return[4,this.refreshToken(t)];case 9:t=r.sent(),r.label=10;case 10:return[2,t]}}))}))},t.prototype.getCredentialsSync=function(){return this.localCredentials.getStorageCredentialsSync()},t.prototype.getCredentialsAsync=function(){return this.getCredentials()},t.prototype.getScope=function(){return h(this,void 0,void 0,(function(){var t;return d(this,(function(e){switch(e.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(t=e.sent())?[2,t.scope]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},t.prototype.getGroups=function(){return h(this,void 0,void 0,(function(){var t;return d(this,(function(e){switch(e.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return(t=e.sent())?[2,t.groups]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},t.prototype.checkRetry=function(e){var n=null;if(("number"!=typeof e||e<t.minRetry||e>t.maxRetry)&&(n={error:i.UNREACHABLE,error_description:"wrong options param: retry"}),n)throw n;return e},t.prototype.formatRetry=function(t,e){return void 0===t?e:this.checkRetry(t)},t.prototype.sleep=function(t){return h(this,void 0,void 0,(function(){return d(this,(function(e){return[2,new Promise((function(e){setTimeout((function(){e()}),t)}))]}))}))},t.prototype.refreshToken=function(t){return h(this,void 0,void 0,(function(){var e=this;return d(this,(function(n){return[2,this.singlePromise.run("_refreshToken",(function(){return h(e,void 0,void 0,(function(){var e,n;return d(this,(function(r){switch(r.label){case 0:if(!t||!t.refresh_token)return[2,this.unAuthenticatedError("no refresh token found in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.refreshTokenFunc(t.refresh_token)];case 2:return e=r.sent(),[4,this.localCredentials.setCredentials(e)];case 3:return r.sent(),[2,e];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},t.prototype.anonymousSignIn=function(t){return h(this,void 0,void 0,(function(){var e=this;return d(this,(function(n){return[2,this.singlePromise.run("_anonymous",(function(){return h(e,void 0,void 0,(function(){var e,n;return d(this,(function(r){switch(r.label){case 0:if(!t||"anonymous"!==t.scope)return[2,this.unAuthenticatedError("no anonymous in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.request("/auth/v1/signin/anonymously",{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret}})];case 2:return e=r.sent(),[4,this.localCredentials.setCredentials(e)];case 3:return r.sent(),[2,e];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this.localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this.unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},t.prototype.defaultRefreshTokenFunc=function(t){return void 0===t||""===t?this.unAuthenticatedError("refresh token not found"):this.request("/auth/v1/token",{method:"POST",body:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"refresh_token",refresh_token:t}})},t.prototype.getDeviceId=function(){return h(this,void 0,void 0,(function(){var t;return d(this,(function(e){switch(e.label){case 0:return this.deviceID?[2,this.deviceID]:[4,this.storage.getItem(_)];case 1:return"string"==typeof(t=e.sent())&&t.length>=16&&t.length<=48?[3,3]:(t=s(),[4,this.storage.setItem(_,t)]);case 2:e.sent(),e.label=3;case 3:return this.deviceID=t,[2,t]}}))}))},t.prototype.unAuthenticatedError=function(t){var e={error:i.UNAUTHENTICATED,error_description:t};return Promise.reject(e)},t.defaultRetry=2,t.minRetry=0,t.maxRetry=5,t.retryInterval=1e3,t}();!function(t){t.AUTH_SIGN_IN_URL="/auth/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/auth/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v1/signin/with/provider",t.AUTH_SIGN_UP_URL="/auth/v1/signup",t.AUTH_TOKEN_URL="/auth/v1/token",t.AUTH_REVOKE_URL="/auth/v1/revoke",t.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",t.PROVIDER_TOKEN_URL="/auth/v1/provider/token",t.PROVIDER_URI_URL="/auth/v1/provider/uri",t.USER_ME_URL="/auth/v1/user/me",t.USER_QUERY_URL="/auth/v1/user/query",t.USER_PRIFILE_URL="/auth/v1/user/profile",t.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",t.VERIFICATION_URL="/auth/v1/verification",t.VERIFY_URL="/auth/v1/verification/verify",t.PROVIDER_LIST="/auth/v1/user/provider",t.PROVIDER_UNBIND_URL="/auth/v1/user/provider",t.CHECK_PWD_URL="/auth/v1/user/sudo",t.SUDO_URL="/auth/v1/user/sudo",t.BIND_CONTACT_URL="/auth/v1/user/contact",t.AUTH_SET_PASSWORD="/auth/v1/user/password",t.AUTH_RESET_PASSWORD="/auth/v1/reset",t.AUTH_GET_DEVICE_CODE="/auth/v1/device/code",t.CHECK_USERNAME="/auth/v1/checkUsername",t.CHECK_IF_USER_EXIST="/auth/v1/checkIfUserExist"}(I||(I={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(S||(S={})),function(t){t.INVALID_ARGUMENT="invalid_argument",t.DEADLINE_EXCEEDED="deadline_exceeded",t.NOT_FOUND="not_found",t.ALREADY_EXISTS="already_exists",t.PERMISSION_DENIED="permission_denied",t.ABORTED="aborted",t.OUT_OF_RANGE="out_of_range",t.UNIMPLEMENTED="unimplemented",t.INTERNAL="internal",t.UNAVAILABLE="unavailable",t.DATA_LOSS="data_loss",t.CAPTCHA_REQUIRED="captcha_required",t.CAPTCHA_INVALID="captcha_invalid",t.INVALID_PASSWORD="invalid_password",t.PASSWORD_NOT_SET="password_not_set",t.INVALID_STATUS="invalid_status",t.USER_PENDING="user_pending",t.USER_BLOCKED="user_blocked"}(T||(T={}));var C=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))},w=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},U=function(){function t(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=g),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId)}return t.prototype.request=function(t,e){return C(this,void 0,void 0,(function(){var n,r,i,o;return w(this,(function(s){switch(s.label){case 0:return e||(e={}),e.method||(e.method="GET"),n="".concat(e.method,":").concat(t),r=t,e.withCaptcha?[4,this.appendCaptchaTokenToURL(t,n,!1)]:[3,2];case 1:r=s.sent(),s.label=2;case 2:return s.trys.push([2,4,,7]),[4,this.config.request(r,e)];case 3:return i=s.sent(),[3,7];case 4:return"captcha_required"!==(o=s.sent()).error&&"captcha_invalid"!==o.error?[3,6]:[4,this.appendCaptchaTokenToURL(t,n,"captcha_invalid"===o.error)];case 5:return t=s.sent(),[2,this.config.request(t,e)];case 6:return[2,Promise.reject(o)];case 7:return[2,i]}}))}))},t.prototype.getDefaultOpenURIWithCallback=function(){if(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap")){var t=document.createElement("div");t.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",t.setAttribute("id","captcha_panel_wrap"),setTimeout((function(){document.body.appendChild(t)}),0)}return this.defaultOpenURIWithCallback},t.prototype.defaultOpenURIWithCallback=function(t){return C(this,void 0,void 0,(function(){var e,n;return w(this,(function(r){return e=document.getElementById("captcha_panel_wrap"),n=document.createElement("iframe"),e.innerHTML="",n.setAttribute("src",t),n.setAttribute("id","review-panel-iframe"),n.style.cssText="min-width:355px;display:block;height:355px;margin:0 auto;background-color: rgb(255, 255, 255);border: none;",e.appendChild(n),e.style.display="block",[2,new Promise((function(t,r){n.onload=function(){try{var i=window.location,o=n.contentWindow.location;if(o.host+o.pathname===i.host+i.pathname){e.style.display="none";var s=new URLSearchParams(o.search),a=s.get("captcha_token");return a?t({captcha_token:a,expires_in:Number(s.get("expires_in"))}):r({error:s.get("error"),error_description:s.get("error_description")})}e.style.display="block"}catch(t){e.style.display="block"}}}))]}))}))},t.prototype.getCaptchaToken=function(t,e){return C(this,void 0,void 0,(function(){var n,r,i,o,s;return w(this,(function(a){switch(a.label){case 0:return t?[3,2]:[4,this.findCaptchaToken()];case 1:if(n=a.sent())return[2,n];a.label=2;case 2:return r="".concat(window.location.origin+window.location.pathname,"?__captcha=on"),[4,this.config.request("/auth/v1/captcha/init",{method:"POST",body:{client_id:this.config.clientId,redirect_uri:r,state:e},withCredentials:!1})];case 3:return(i=a.sent()).captcha_token?(o={captcha_token:i.captcha_token,expires_in:i.expires_in},this.saveCaptchaToken(o),[2,i.captcha_token]):[4,this.config.openURIWithCallback(i.url)];case 4:return s=a.sent(),this.saveCaptchaToken(s),[2,s.captcha_token]}}))}))},t.prototype.appendCaptchaTokenToURL=function(t,e,n){return C(this,void 0,void 0,(function(){var r;return w(this,(function(i){switch(i.label){case 0:return[4,this.getCaptchaToken(n,e)];case 1:return r=i.sent(),t.indexOf("?")>0?t+="&captcha_token=".concat(r):t+="?captcha_token=".concat(r),[2,t]}}))}))},t.prototype.saveCaptchaToken=function(t){return C(this,void 0,void 0,(function(){var e;return w(this,(function(n){switch(n.label){case 0:return t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10)),e=JSON.stringify(t),[4,this.config.storage.setItem(this.tokenSectionName,e)];case 1:return n.sent(),[2]}}))}))},t.prototype.findCaptchaToken=function(){return C(this,void 0,void 0,(function(){var t,e;return w(this,(function(n){switch(n.label){case 0:return[4,this.config.storage.getItem(this.tokenSectionName)];case 1:if(null==(t=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),e.expires_at<new Date?[2,null]:[2,e.captcha_token];case 3:return n.sent(),[4,this.config.storage.removeItem(this.tokenSectionName)];case 4:return n.sent(),[2,null];case 5:return[2,null]}}))}))},t}(),O=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{u(r.next(t))}catch(t){o(t)}}function a(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}u((r=r.apply(t,e||[])).next())}))},A=function(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},N=function(){function t(t){var e=t.request,n=t.credentialsClient;if(!n){var r={apiOrigin:t.apiOrigin,clientId:t.clientId,storage:t.storage};n=new m(r)}if(!e){var i=n.request.bind(n),o=new U({clientId:t.clientId,request:i,storage:t.storage});e=o.request.bind(o)}this.config={apiOrigin:t.apiOrigin,clientId:t.clientId,request:e,credentialsClient:n,storage:t.storage||g}}return t.parseParamsToSearch=function(t){return Object.keys(t).forEach((function(e){t[e]||delete t[e]})),new URLSearchParams(t).toString()},t.prototype.signIn=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return[4,this.config.request(I.AUTH_SIGN_IN_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}}))}))},t.prototype.signInAnonymously=function(t){return void 0===t&&(t={}),O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return[4,this.config.request(I.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}}))}))},t.prototype.signUp=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return[4,this.config.request(I.AUTH_SIGN_UP_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}}))}))},t.prototype.signOut=function(){return O(this,void 0,void 0,(function(){var t,e;return A(this,(function(n){switch(n.label){case 0:return[4,this.config.credentialsClient.getAccessToken()];case 1:return t=n.sent(),[4,this.config.request(I.AUTH_REVOKE_URL,{method:"POST",body:{token:t}})];case 2:return e=n.sent(),[4,this.config.credentialsClient.setCredentials()];case 3:return n.sent(),[2,Promise.resolve(e)]}}))}))},t.prototype.getVerification=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return e=!1,"CUR_USER"!==t.target?[3,1]:(e=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:n.sent()&&(e=!0),n.label=3;case 3:return[2,this.config.request(I.VERIFICATION_URL,{method:"POST",body:t,withCaptcha:!0,withCredentials:e})]}}))}))},t.prototype.verify=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.VERIFY_URL,{method:"POST",body:t})]}))}))},t.prototype.genProviderRedirectUri=function(t){return O(this,void 0,void 0,(function(){var e,n;return A(this,(function(r){return e="".concat(I.PROVIDER_URI_URL,"?client_id=").concat(this.config.clientId,"&provider_id=").concat(t.provider_id,"&redirect_uri=").concat(encodeURIComponent(t.provider_redirect_uri),"&state=").concat(t.state),(n=t.other_params)&&"string"==typeof n.sign_out_uri&&n.sign_out_uri.length>0&&(e+="&other_params[sign_out_uri]=".concat(n.sign_out_uri)),[2,this.config.request(e,{method:"GET"})]}))}))},t.prototype.grantProviderToken=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.PROVIDER_TOKEN_URL,{method:"POST",body:t})]}))}))},t.prototype.patchProviderToken=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})]}))}))},t.prototype.signInWithProvider=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return[4,this.config.request(I.AUTH_SIGN_IN_WITH_PROVIDER_URL,{method:"POST",body:t})];case 1:return e=n.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return n.sent(),[2,Promise.resolve(e)]}}))}))},t.prototype.bindWithProvider=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0})]}))}))},t.prototype.getUserProfile=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){return[2,this.getUserInfo()]}))}))},t.prototype.getUserInfo=function(){return O(this,void 0,void 0,(function(){var t;return A(this,(function(e){switch(e.label){case 0:return[4,this.config.request(I.USER_ME_URL,{method:"GET",withCredentials:!0})];case 1:return(t=e.sent()).sub&&(t.uid=t.sub),[2,t]}}))}))},t.prototype.deleteMe=function(e){return O(this,void 0,void 0,(function(){var n;return A(this,(function(r){return n="".concat(I.USER_ME_URL,"?").concat(t.parseParamsToSearch(e)),[2,this.config.request(n,{method:"DELETE",withCredentials:!0})]}))}))},t.prototype.hasLoginState=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.config.credentialsClient.getAccessToken()];case 1:return t.sent(),[2,!0];case 2:return t.sent(),[2,!1];case 3:return[2]}}))}))},t.prototype.hasLoginStateSync=function(){return this.config.credentialsClient.getCredentialsSync()},t.prototype.getLoginState=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){return[2,this.config.credentialsClient.getCredentialsAsync()]}))}))},t.prototype.transByProvider=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})]}))}))},t.prototype.grantToken=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.AUTH_TOKEN_URL,{method:"POST",body:t})]}))}))},t.prototype.getProviders=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){return[2,this.config.request(I.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},t.prototype.unbindProvider=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})]}))}))},t.prototype.checkPassword=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})]}))}))},t.prototype.bindPhone=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})]}))}))},t.prototype.bindEmail=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})]}))}))},t.prototype.setPassword=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})]}))}))},t.prototype.updatePasswordByOld=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){switch(n.label){case 0:return[4,this.sudo({password:t.old_password})];case 1:return e=n.sent(),[2,this.setPassword({sudo_token:e.sudo_token,new_password:t.new_password})]}}))}))},t.prototype.sudo=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.SUDO_URL),{method:"POST",withCredentials:!0,body:t})]}))}))},t.prototype.getCurUserVerification=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return t.target="CUR_USER",[2,this.config.request(I.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})]}))}))},t.prototype.changeBindedProvider=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request("".concat(I.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})]}))}))},t.prototype.setUserProfile=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})]}))}))},t.prototype.queryUserProfile=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){return e=new URLSearchParams(t),[2,this.config.request("".concat(I.USER_QUERY_URL,"?").concat(e.toString()),{method:"GET",withCredentials:!0})]}))}))},t.prototype.setCustomSignFunc=function(t){this.getCustomSignTicketFn=t},t.prototype.signInWithCustomTicket=function(){return O(this,void 0,void 0,(function(){var t;return A(this,(function(e){switch(e.label){case 0:return[4,this.getCustomSignTicketFn()];case 1:return t=e.sent(),[2,this.signInWithProvider({provider_id:"custom",provider_token:t})]}}))}))},t.prototype.resetPassword=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.AUTH_RESET_PASSWORD,{method:"POST",body:t})]}))}))},t.prototype.deviceAuthorize=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.AUTH_GET_DEVICE_CODE,{method:"POST",body:t,withCredentials:!0})]}))}))},t.prototype.checkUsername=function(t){return O(this,void 0,void 0,(function(){return A(this,(function(e){return[2,this.config.request(I.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})]}))}))},t.prototype.checkIfUserExist=function(t){return O(this,void 0,void 0,(function(){var e;return A(this,(function(n){return e=new URLSearchParams(t),[2,this.config.request("".concat(I.CHECK_IF_USER_EXIST,"?").concat(e.toString()),{method:"GET"})]}))}))},t.prototype.loginScope=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){return[2,this.config.credentialsClient.getScope()]}))}))},t.prototype.loginGroups=function(){return O(this,void 0,void 0,(function(){return A(this,(function(t){return[2,this.config.credentialsClient.getGroups()]}))}))},t}(),P=function(){},D=function(){return D=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},D.apply(this,arguments)},L=function(t){var e=t.apiOrigin,n=t.clientId,r=t.storage,i=t.request,o=t.anonymousSignInFunc;this.oauth2client=new m({apiOrigin:e,clientId:n,storage:r,baseRequest:i,anonymousSignInFunc:o}),this.authApi=new N(D(D({credentialsClient:this.oauth2client},t),{request:i?this.oauth2client.request.bind(this.oauth2client):void 0}))}},118:function(t,e,n){var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),i(n(543),e)}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r].call(o.exports,o,o.exports,n),o.exports}return n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(118)})()));
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_realtime",[],t):"object"==typeof exports?exports.cloudbase_realtime=t():e.cloudbase_realtime=t()}("undefined"!=typeof window?window:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=4)}([function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e,t,n){(function(t){var n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/,i=/^\./,o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,s=/\\(\\)?/g,a=/^\[object .+?Constructor\]$/,c=/^(?:0|[1-9]\d*)$/,u="object"==typeof t&&t&&t.Object===Object&&t,l="object"==typeof self&&self&&self.Object===Object&&self,h=u||l||Function("return this")();var d,f=Array.prototype,p=Function.prototype,v=Object.prototype,_=h["__core-js_shared__"],E=(d=/[^.]+$/.exec(_&&_.keys&&_.keys.IE_PROTO||""))?"Symbol(src)_1."+d:"",g=p.toString,I=v.hasOwnProperty,y=v.toString,m=RegExp("^"+g.call(I).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),b=h.Symbol,w=f.splice,S=M(h,"Map"),T=M(Object,"create"),A=b?b.prototype:void 0,R=A?A.toString:void 0;function C(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function D(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function N(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function O(e,t,n){var r=e[t];I.call(e,t)&&H(r,n)&&(void 0!==n||t in e)||(e[t]=n)}function L(e,t){for(var n=e.length;n--;)if(H(e[n][0],t))return n;return-1}function W(e){return!(!F(e)||(t=e,E&&E in t))&&(function(e){var t=F(e)?y.call(e):"";return"[object Function]"==t||"[object GeneratorFunction]"==t}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?m:a).test(function(e){if(null!=e){try{return g.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var t}function j(e,t,i,o){if(!F(e))return e;for(var s=-1,a=(t=function(e,t){if(q(e))return!1;var i=typeof e;if("number"==i||"symbol"==i||"boolean"==i||null==e||U(e))return!0;return r.test(e)||!n.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:function(e){return q(e)?e:k(e)}(t)).length,c=a-1,u=e;null!=u&&++s<a;){var l=K(t[s]),h=i;if(s!=c){var d=u[l];void 0===(h=o?o(d,l,u):void 0)&&(h=F(d)?d:x(t[s+1])?[]:{})}O(u,l,h),u=u[l]}return e}function P(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function M(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return W(n)?n:void 0}function x(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||c.test(e))&&e>-1&&e%1==0&&e<t}C.prototype.clear=function(){this.__data__=T?T(null):{}},C.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},C.prototype.get=function(e){var t=this.__data__;if(T){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return I.call(t,e)?t[e]:void 0},C.prototype.has=function(e){var t=this.__data__;return T?void 0!==t[e]:I.call(t,e)},C.prototype.set=function(e,t){return this.__data__[e]=T&&void 0===t?"__lodash_hash_undefined__":t,this},D.prototype.clear=function(){this.__data__=[]},D.prototype.delete=function(e){var t=this.__data__,n=L(t,e);return!(n<0)&&(n==t.length-1?t.pop():w.call(t,n,1),!0)},D.prototype.get=function(e){var t=this.__data__,n=L(t,e);return n<0?void 0:t[n][1]},D.prototype.has=function(e){return L(this.__data__,e)>-1},D.prototype.set=function(e,t){var n=this.__data__,r=L(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},N.prototype.clear=function(){this.__data__={hash:new C,map:new(S||D),string:new C}},N.prototype.delete=function(e){return P(this,e).delete(e)},N.prototype.get=function(e){return P(this,e).get(e)},N.prototype.has=function(e){return P(this,e).has(e)},N.prototype.set=function(e,t){return P(this,e).set(e,t),this};var k=B((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(U(e))return R?R.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return i.test(e)&&n.push(""),e.replace(o,(function(e,t,r,i){n.push(r?i.replace(s,"$1"):t||e)})),n}));function K(e){if("string"==typeof e||U(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function B(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;if(o.has(i))return o.get(i);var s=e.apply(this,r);return n.cache=o.set(i,s),s};return n.cache=new(B.Cache||N),n}function H(e,t){return e===t||e!=e&&t!=t}B.Cache=N;var q=Array.isArray;function F(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function U(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==y.call(e)}e.exports=function(e,t,n){return null==e?e:j(e,t,n)}}).call(this,n(0))},function(e,t,n){(function(t){var n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/,i=/^\./,o=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,s=/\\(\\)?/g,a=/^\[object .+?Constructor\]$/,c="object"==typeof t&&t&&t.Object===Object&&t,u="object"==typeof self&&self&&self.Object===Object&&self,l=c||u||Function("return this")();var h,d=Array.prototype,f=Function.prototype,p=Object.prototype,v=l["__core-js_shared__"],_=(h=/[^.]+$/.exec(v&&v.keys&&v.keys.IE_PROTO||""))?"Symbol(src)_1."+h:"",E=f.toString,g=p.hasOwnProperty,I=p.toString,y=RegExp("^"+E.call(g).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),m=l.Symbol,b=d.splice,w=P(l,"Map"),S=P(Object,"create"),T=m?m.prototype:void 0,A=T?T.toString:void 0;function R(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function C(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function D(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function N(e,t){for(var n,r,i=e.length;i--;)if((n=e[i][0])===(r=t)||n!=n&&r!=r)return i;return-1}function O(e){return!(!H(e)||(t=e,_&&_ in t))&&(function(e){var t=H(e)?I.call(e):"";return"[object Function]"==t||"[object GeneratorFunction]"==t}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?y:a).test(function(e){if(null!=e){try{return E.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e));var t}function L(e,t){e=function(e,t){return 1==t.length?e:function(e,t){for(var n=0,r=(t=M(t,e)?[t]:W(t)).length;null!=e&&n<r;)e=e[k(t[n++])];return n&&n==r?e:void 0}(e,function(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),(n=n>i?i:n)<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var o=Array(i);++r<i;)o[r]=e[r+t];return o}(t,0,-1))}(e,t=M(t,e)?[t]:W(t));var n,r,i=k((r=(n=t)?n.length:0)?n[r-1]:void 0);return!(null!=e&&g.call(e,i))||delete e[i]}function W(e){return B(e)?e:x(e)}function j(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function P(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return O(n)?n:void 0}function M(e,t){if(B(e))return!1;var i=typeof e;return!("number"!=i&&"symbol"!=i&&"boolean"!=i&&null!=e&&!q(e))||(r.test(e)||!n.test(e)||null!=t&&e in Object(t))}R.prototype.clear=function(){this.__data__=S?S(null):{}},R.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},R.prototype.get=function(e){var t=this.__data__;if(S){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return g.call(t,e)?t[e]:void 0},R.prototype.has=function(e){var t=this.__data__;return S?void 0!==t[e]:g.call(t,e)},R.prototype.set=function(e,t){return this.__data__[e]=S&&void 0===t?"__lodash_hash_undefined__":t,this},C.prototype.clear=function(){this.__data__=[]},C.prototype.delete=function(e){var t=this.__data__,n=N(t,e);return!(n<0)&&(n==t.length-1?t.pop():b.call(t,n,1),!0)},C.prototype.get=function(e){var t=this.__data__,n=N(t,e);return n<0?void 0:t[n][1]},C.prototype.has=function(e){return N(this.__data__,e)>-1},C.prototype.set=function(e,t){var n=this.__data__,r=N(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},D.prototype.clear=function(){this.__data__={hash:new R,map:new(w||C),string:new R}},D.prototype.delete=function(e){return j(this,e).delete(e)},D.prototype.get=function(e){return j(this,e).get(e)},D.prototype.has=function(e){return j(this,e).has(e)},D.prototype.set=function(e,t){return j(this,e).set(e,t),this};var x=K((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(q(e))return A?A.call(e):"";var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}(t);var n=[];return i.test(e)&&n.push(""),e.replace(o,(function(e,t,r,i){n.push(r?i.replace(s,"$1"):t||e)})),n}));function k(e){if("string"==typeof e||q(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t}function K(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError("Expected a function");var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],o=n.cache;if(o.has(i))return o.get(i);var s=e.apply(this,r);return n.cache=o.set(i,s),s};return n.cache=new(K.Cache||D),n}K.Cache=D;var B=Array.isArray;function H(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function q(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&"[object Symbol]"==I.call(e)}e.exports=function(e,t){return null==e||L(e,t)}}).call(this,n(0))},function(e,t,n){(function(e,n){var r="[object Arguments]",i="[object Function]",o="[object GeneratorFunction]",s="[object Map]",a="[object Set]",c=/\w*$/,u=/^\[object .+?Constructor\]$/,l=/^(?:0|[1-9]\d*)$/,h={};h[r]=h["[object Array]"]=h["[object ArrayBuffer]"]=h["[object DataView]"]=h["[object Boolean]"]=h["[object Date]"]=h["[object Float32Array]"]=h["[object Float64Array]"]=h["[object Int8Array]"]=h["[object Int16Array]"]=h["[object Int32Array]"]=h[s]=h["[object Number]"]=h["[object Object]"]=h["[object RegExp]"]=h[a]=h["[object String]"]=h["[object Symbol]"]=h["[object Uint8Array]"]=h["[object Uint8ClampedArray]"]=h["[object Uint16Array]"]=h["[object Uint32Array]"]=!0,h["[object Error]"]=h[i]=h["[object WeakMap]"]=!1;var d="object"==typeof e&&e&&e.Object===Object&&e,f="object"==typeof self&&self&&self.Object===Object&&self,p=d||f||Function("return this")(),v=t&&!t.nodeType&&t,_=v&&"object"==typeof n&&n&&!n.nodeType&&n,E=_&&_.exports===v;function g(e,t){return e.set(t[0],t[1]),e}function I(e,t){return e.add(t),e}function y(e,t,n,r){var i=-1,o=e?e.length:0;for(r&&o&&(n=e[++i]);++i<o;)n=t(n,e[i],i,e);return n}function m(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}function b(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function w(e,t){return function(n){return e(t(n))}}function S(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var T,A=Array.prototype,R=Function.prototype,C=Object.prototype,D=p["__core-js_shared__"],N=(T=/[^.]+$/.exec(D&&D.keys&&D.keys.IE_PROTO||""))?"Symbol(src)_1."+T:"",O=R.toString,L=C.hasOwnProperty,W=C.toString,j=RegExp("^"+O.call(L).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),P=E?p.Buffer:void 0,M=p.Symbol,x=p.Uint8Array,k=w(Object.getPrototypeOf,Object),K=Object.create,B=C.propertyIsEnumerable,H=A.splice,q=Object.getOwnPropertySymbols,F=P?P.isBuffer:void 0,U=w(Object.keys,Object),G=_e(p,"DataView"),V=_e(p,"Map"),$=_e(p,"Promise"),J=_e(p,"Set"),X=_e(p,"WeakMap"),Y=_e(Object,"create"),z=me(G),Q=me(V),Z=me($),ee=me(J),te=me(X),ne=M?M.prototype:void 0,re=ne?ne.valueOf:void 0;function ie(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function oe(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function se(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function ae(e){this.__data__=new oe(e)}function ce(e,t){var n=we(e)||function(e){return function(e){return function(e){return!!e&&"object"==typeof e}(e)&&Se(e)}(e)&&L.call(e,"callee")&&(!B.call(e,"callee")||W.call(e)==r)}(e)?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],i=n.length,o=!!i;for(var s in e)!t&&!L.call(e,s)||o&&("length"==s||Ie(s,i))||n.push(s);return n}function ue(e,t,n){var r=e[t];L.call(e,t)&&be(r,n)&&(void 0!==n||t in e)||(e[t]=n)}function le(e,t){for(var n=e.length;n--;)if(be(e[n][0],t))return n;return-1}function he(e,t,n,u,l,d,f){var p;if(u&&(p=d?u(e,l,d,f):u(e)),void 0!==p)return p;if(!Re(e))return e;var v=we(e);if(v){if(p=function(e){var t=e.length,n=e.constructor(t);t&&"string"==typeof e[0]&&L.call(e,"index")&&(n.index=e.index,n.input=e.input);return n}(e),!t)return function(e,t){var n=-1,r=e.length;t||(t=Array(r));for(;++n<r;)t[n]=e[n];return t}(e,p)}else{var _=ge(e),E=_==i||_==o;if(Te(e))return function(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}(e,t);if("[object Object]"==_||_==r||E&&!d){if(m(e))return d?e:{};if(p=function(e){return"function"!=typeof e.constructor||ye(e)?{}:(t=k(e),Re(t)?K(t):{});var t}(E?{}:e),!t)return function(e,t){return pe(e,Ee(e),t)}(e,function(e,t){return e&&pe(t,Ce(t),e)}(p,e))}else{if(!h[_])return d?e:{};p=function(e,t,n,r){var i=e.constructor;switch(t){case"[object ArrayBuffer]":return fe(e);case"[object Boolean]":case"[object Date]":return new i(+e);case"[object DataView]":return function(e,t){var n=t?fe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}(e,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return function(e,t){var n=t?fe(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}(e,r);case s:return function(e,t,n){return y(t?n(b(e),!0):b(e),g,new e.constructor)}(e,r,n);case"[object Number]":case"[object String]":return new i(e);case"[object RegExp]":return function(e){var t=new e.constructor(e.source,c.exec(e));return t.lastIndex=e.lastIndex,t}(e);case a:return function(e,t,n){return y(t?n(S(e),!0):S(e),I,new e.constructor)}(e,r,n);case"[object Symbol]":return o=e,re?Object(re.call(o)):{}}var o}(e,_,he,t)}}f||(f=new ae);var w=f.get(e);if(w)return w;if(f.set(e,p),!v)var T=n?function(e){return function(e,t,n){var r=t(e);return we(e)?r:function(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}(r,n(e))}(e,Ce,Ee)}(e):Ce(e);return function(e,t){for(var n=-1,r=e?e.length:0;++n<r&&!1!==t(e[n],n,e););}(T||e,(function(r,i){T&&(r=e[i=r]),ue(p,i,he(r,t,n,u,i,e,f))})),p}function de(e){return!(!Re(e)||(t=e,N&&N in t))&&(Ae(e)||m(e)?j:u).test(me(e));var t}function fe(e){var t=new e.constructor(e.byteLength);return new x(t).set(new x(e)),t}function pe(e,t,n,r){n||(n={});for(var i=-1,o=t.length;++i<o;){var s=t[i],a=r?r(n[s],e[s],s,n,e):void 0;ue(n,s,void 0===a?e[s]:a)}return n}function ve(e,t){var n,r,i=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?i["string"==typeof t?"string":"hash"]:i.map}function _e(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return de(n)?n:void 0}ie.prototype.clear=function(){this.__data__=Y?Y(null):{}},ie.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},ie.prototype.get=function(e){var t=this.__data__;if(Y){var n=t[e];return"__lodash_hash_undefined__"===n?void 0:n}return L.call(t,e)?t[e]:void 0},ie.prototype.has=function(e){var t=this.__data__;return Y?void 0!==t[e]:L.call(t,e)},ie.prototype.set=function(e,t){return this.__data__[e]=Y&&void 0===t?"__lodash_hash_undefined__":t,this},oe.prototype.clear=function(){this.__data__=[]},oe.prototype.delete=function(e){var t=this.__data__,n=le(t,e);return!(n<0)&&(n==t.length-1?t.pop():H.call(t,n,1),!0)},oe.prototype.get=function(e){var t=this.__data__,n=le(t,e);return n<0?void 0:t[n][1]},oe.prototype.has=function(e){return le(this.__data__,e)>-1},oe.prototype.set=function(e,t){var n=this.__data__,r=le(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},se.prototype.clear=function(){this.__data__={hash:new ie,map:new(V||oe),string:new ie}},se.prototype.delete=function(e){return ve(this,e).delete(e)},se.prototype.get=function(e){return ve(this,e).get(e)},se.prototype.has=function(e){return ve(this,e).has(e)},se.prototype.set=function(e,t){return ve(this,e).set(e,t),this},ae.prototype.clear=function(){this.__data__=new oe},ae.prototype.delete=function(e){return this.__data__.delete(e)},ae.prototype.get=function(e){return this.__data__.get(e)},ae.prototype.has=function(e){return this.__data__.has(e)},ae.prototype.set=function(e,t){var n=this.__data__;if(n instanceof oe){var r=n.__data__;if(!V||r.length<199)return r.push([e,t]),this;n=this.__data__=new se(r)}return n.set(e,t),this};var Ee=q?w(q,Object):function(){return[]},ge=function(e){return W.call(e)};function Ie(e,t){return!!(t=null==t?9007199254740991:t)&&("number"==typeof e||l.test(e))&&e>-1&&e%1==0&&e<t}function ye(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||C)}function me(e){if(null!=e){try{return O.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function be(e,t){return e===t||e!=e&&t!=t}(G&&"[object DataView]"!=ge(new G(new ArrayBuffer(1)))||V&&ge(new V)!=s||$&&"[object Promise]"!=ge($.resolve())||J&&ge(new J)!=a||X&&"[object WeakMap]"!=ge(new X))&&(ge=function(e){var t=W.call(e),n="[object Object]"==t?e.constructor:void 0,r=n?me(n):void 0;if(r)switch(r){case z:return"[object DataView]";case Q:return s;case Z:return"[object Promise]";case ee:return a;case te:return"[object WeakMap]"}return t});var we=Array.isArray;function Se(e){return null!=e&&function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991}(e.length)&&!Ae(e)}var Te=F||function(){return!1};function Ae(e){var t=Re(e)?W.call(e):"";return t==i||t==o}function Re(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Ce(e){return Se(e)?ce(e):function(e){if(!ye(e))return U(e);var t=[];for(var n in Object(e))L.call(e,n)&&"constructor"!=n&&t.push(n);return t}(e)}n.exports=function(e){return he(e,!0,!0)}}).call(this,n(0),n(5)(e))},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerRealtime=void 0;var r=n(6);t.registerRealtime=r.registerRealtime},function(e,t){e.exports=function(e){return e.webpackPolyfill||(e.deprecate=function(){},e.paths=[],e.children||(e.children=[]),Object.defineProperty(e,"loaded",{enumerable:!0,get:function(){return e.l}}),Object.defineProperty(e,"id",{enumerable:!0,get:function(){return e.i}}),e.webpackPolyfill=1),e}},function(e,t,n){"use strict";n.r(t),n.d(t,"registerRealtime",(function(){return B}));var r=n(1),i=n.n(r),o=n(2),s=n.n(o),a=n(3),c=n.n(a);function u(e){return void 0===e&&(e=""),(e?e+"_":"")+ +new Date+"_"+Math.random()}var l,h,d=function(e){this.close=e.close,this.onChange=e.onChange,this.onError=e.onError,e.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return e.virtualClient}})},f=function(e){var t,n,r=e.id,i=e.docChanges,o=e.docs,s=e.msgType,a=e.type;Object.defineProperties(this,{id:{get:function(){return r},enumerable:!0},docChanges:{get:function(){return t||(t=JSON.parse(JSON.stringify(i))),t},enumerable:!0},docs:{get:function(){return n||(n=JSON.parse(JSON.stringify(o))),n},enumerable:!0},msgType:{get:function(){return s},enumerable:!0},type:{get:function(){return a},enumerable:!0}})},p=(l=function(e,t){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),v=function(e){function t(t){var n=e.call(this,"Watch Error "+JSON.stringify(t.msgData)+" (requestid: "+t.requestId+")")||this;return n.isRealtimeErrorMessageError=!0,n.payload=t,n}return p(t,e),t}(Error),_=function(e){return null==e?void 0:e.isRealtimeErrorMessageError},E=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="timeout",t.payload=null,t.generic=!0,t}return p(t,e),t}(Error),g=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="cancelled",t.payload=null,t.generic=!0,t}return p(t,e),t}(Error),I=function(e){function t(t){var n=e.call(this,t.errMsg)||this;return n.errCode="UNKNOWN_ERROR",Object.defineProperties(n,{message:{get:function(){return"errCode: "+this.errCode+" "+(y[this.errCode]||"")+" | errMsg: "+this.errMsg},set:function(e){this.errMsg=e}}}),n.errCode=t.errCode||"UNKNOWN_ERROR",n.errMsg=t.errMsg,n}return p(t,e),Object.defineProperty(t.prototype,"message",{get:function(){return"errCode: "+this.errCode+" | errMsg: "+this.errMsg},set:function(e){this.errMsg=e},enumerable:!1,configurable:!0}),t}(Error),y={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"},m=function(e){return void 0===e&&(e=0),new Promise((function(t){return setTimeout(t,e)}))},b=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},w=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},S=function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),i=0;for(t=0;t<n;t++)for(var o=arguments[t],s=0,a=o.length;s<a;s++,i++)r[i]=o[s];return r};!function(e){e.LOGGINGIN="LOGGINGIN",e.INITING="INITING",e.REBUILDING="REBUILDING",e.ACTIVE="ACTIVE",e.ERRORED="ERRORED",e.CLOSING="CLOSING",e.CLOSED="CLOSED",e.PAUSED="PAUSED",e.RESUMING="RESUMING"}(h||(h={}));var T=function(){function e(e){var t=this;this.watchStatus=h.INITING,this.wsLogin=function(e,n){return b(t,void 0,void 0,(function(){var t;return w(this,(function(r){switch(r.label){case 0:return this.watchStatus=h.LOGGINGIN,[4,this.login(e,n)];case 1:return t=r.sent(),this.envId||(this.envId=t.envId),[2,t]}}))}))},this.initWatch=function(e){return b(t,void 0,void 0,(function(){var t,n=this;return w(this,(function(r){switch(r.label){case 0:if(null!==this.initWatchPromise&&void 0!==this.initWatchPromise)return[2,this.initWatchPromise];this.initWatchPromise=new Promise((function(t,r){b(n,void 0,void 0,(function(){var n,i,o,s,a,c,l,d,p,v;return w(this,(function(_){switch(_.label){case 0:return _.trys.push([0,3,,4]),this.watchStatus===h.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:return n=_.sent().envId,this.watchStatus===h.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):(this.watchStatus=h.INITING,i={watchId:this.watchId,requestId:u(),msgType:"INIT_WATCH",msgData:{envId:n,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:i,waitResponse:!0,skipOnMessage:!0,timeout:1e4})]);case 2:if(o=_.sent(),s=o.msgData,a=s.events,c=s.currEvent,this.sessionInfo={queryID:o.msgData.queryID,currentEventId:c-1,currentDocs:[]},a.length>0){for(l=0,d=a;l<d.length;l++)d[l].ID=c;this.handleServerEvents(o)}else this.sessionInfo.currentEventId=c,p=new f({id:c,docChanges:[],docs:[],type:"init"}),this.listener.onChange(p),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=h.ACTIVE,this.availableRetries.INIT_WATCH=2,t(),[3,4];case 3:return v=_.sent(),this.handleWatchEstablishmentError(v,{operationName:"INIT_WATCH",resolve:t,reject:r}),[3,4];case 4:return[2]}}))}))})),t=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return r.sent(),t=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch "+(t?"success":"fail")),[2]}}))}))},this.rebuildWatch=function(e){return b(t,void 0,void 0,(function(){var t,n=this;return w(this,(function(r){switch(r.label){case 0:if(null!==this.rebuildWatchPromise&&void 0!==this.rebuildWatchPromise)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise((function(t,r){b(n,void 0,void 0,(function(){var n,i,o,s;return w(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),this.watchStatus===h.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:if(n=a.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===h.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):(this.watchStatus=h.REBUILDING,i={watchId:this.watchId,requestId:u(),msgType:"REBUILD_WATCH",msgData:{envId:n,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:i,waitResponse:!0,skipOnMessage:!1,timeout:1e4})]);case 2:return o=a.sent(),this.handleServerEvents(o),this.watchStatus=h.ACTIVE,this.availableRetries.REBUILD_WATCH=2,t(),[3,4];case 3:return s=a.sent(),this.handleWatchEstablishmentError(s,{operationName:"REBUILD_WATCH",resolve:t,reject:r}),[3,4];case 4:return[2]}}))}))})),t=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return r.sent(),t=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch "+(t?"success":"fail")),[2]}}))}))},this.handleWatchEstablishmentError=function(e,n){return b(t,void 0,void 0,(function(){var t,r,i,o=this;return w(this,(function(s){return t="INIT_WATCH"===n.operationName,r=function(){o.closeWithError(new I({errCode:t?y.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:y.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:e})),n.reject(e)},i=function(e){o.useRetryTicket(n.operationName)?t?(o.initWatchPromise=void 0,n.resolve(o.initWatch(e))):(o.rebuildWatchPromise=void 0,n.resolve(o.rebuildWatch(e))):r()},this.handleCommonError(e,{onSignError:function(){return i(!0)},onTimeoutError:function(){return i(!1)},onNotRetryableError:r,onCancelledError:n.reject,onUnknownError:function(){b(o,void 0,void 0,(function(){var e,t=this;return w(this,(function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),e=function(){return b(t,void 0,void 0,(function(){return w(this,(function(e){switch(e.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return e.sent(),i(!0),[2]}}))}))},this.isWSConnected()?[3,2]:[4,e()];case 1:return r.sent(),[3,7];case 2:return[4,m(100)];case 3:return r.sent(),this.watchStatus!==h.PAUSED?[3,4]:(n.reject(new g(n.operationName+" cancelled due to pause after unknownError")),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,e()];case 5:return r.sent(),[3,7];case 6:i(!1),r.label=7;case 7:return[3,9];case 8:return r.sent(),i(!0),[3,9];case 9:return[2]}}))}))}}),[2]}))}))},this.closeWatch=function(){return b(t,void 0,void 0,(function(){var e,t,n;return w(this,(function(r){switch(r.label){case 0:if(e=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==h.ACTIVE)return this.watchStatus=h.CLOSED,this.onWatchClose(this,e),[2];r.label=1;case 1:return r.trys.push([1,3,4,5]),this.watchStatus=h.CLOSING,t={watchId:this.watchId,requestId:u(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:t})];case 2:return r.sent(),this.sessionInfo=void 0,this.watchStatus=h.CLOSED,[3,5];case 3:return n=r.sent(),this.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:n})),[3,5];case 4:return this.onWatchClose(this,e),[7];case 5:return[2]}}))}))},this.scheduleSendACK=function(){t.clearACKSchedule(),t.ackTimeoutId=setTimeout((function(){t.waitExpectedTimeoutId?t.scheduleSendACK():t.sendACK()}),1e4)},this.clearACKSchedule=function(){t.ackTimeoutId&&clearTimeout(t.ackTimeoutId)},this.sendACK=function(){return b(t,void 0,void 0,(function(){var e,t,n;return w(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.watchStatus!==h.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(e={watchId:this.watchId,requestId:u(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:e})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return r.sent(),this.scheduleSendACK(),[3,3];case 2:if(t=r.sent(),_(t))switch((n=t.payload).msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:n.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:t})),[3,3];case 3:return[2]}}))}))},this.handleCommonError=function(e,t){if(_(e)){switch(e.payload.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return void t.onSignError(e);case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":default:return void t.onNotRetryableError(e)}}else{if(function(e){return"timeout"===e.type}(e))return void t.onTimeoutError(e);if(function(e){return"cancelled"===e.type}(e))return void t.onCancelledError(e)}t.onUnknownError(e)},this.watchId="watchid_"+ +new Date+"_"+Math.random(),this.envId=e.envId,this.collectionName=e.collectionName,this.query=e.query,this.limit=e.limit,this.orderBy=e.orderBy,this.send=e.send,this.login=e.login,this.isWSConnected=e.isWSConnected,this.onceWSConnected=e.onceWSConnected,this.getWaitExpectedTimeoutLength=e.getWaitExpectedTimeoutLength,this.onWatchStart=e.onWatchStart,this.onWatchClose=e.onWatchClose,this.debug=e.debug,this.availableRetries={INIT_WATCH:2,REBUILD_WATCH:2,CHECK_LAST:2},this.listener=new d({close:function(){t.closeWatch()},onChange:e.onChange,onError:e.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return e.prototype.onMessage=function(e){var t=this;switch(this.watchStatus){case h.PAUSED:if("ERROR"!==e.msgType)return;break;case h.LOGGINGIN:case h.INITING:case h.REBUILDING:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received while "+this.watchStatus);case h.CLOSED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");case h.ERRORED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error")}if(this.sessionInfo)switch(this.scheduleSendACK(),e.msgType){case"NEXT_EVENT":console.warn("nextevent "+e.msgData.currEvent+" ignored",e),this.handleServerEvents(e);break;case"CHECK_EVENT":this.sessionInfo.currentEventId<e.msgData.currEvent&&(this.sessionInfo.expectEventId=e.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout((function(){t.rebuildWatch()}),this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength "+this.getWaitExpectedTimeoutLength()));break;case"ERROR":this.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:e.msgData.code+" - "+e.msgData.message}));break;default:console.warn("[realtime listener] virtual client receive unexpected msg "+e.msgType+": ",e)}else console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.")},e.prototype.closeWithError=function(e){var t;this.watchStatus=h.ERRORED,this.clearACKSchedule(),this.listener.onError(e),this.onWatchClose(this,(null===(t=this.sessionInfo)||void 0===t?void 0:t.queryID)||""),console.log("[realtime] client closed ("+this.collectionName+" "+this.query+") (watchId "+this.watchId+")")},e.prototype.pause=function(){this.watchStatus=h.PAUSED,console.log("[realtime] client paused ("+this.collectionName+" "+this.query+") (watchId "+this.watchId+")")},e.prototype.resume=function(){return b(this,void 0,void 0,(function(){var e;return w(this,(function(t){switch(t.label){case 0:this.watchStatus=h.RESUMING,console.log("[realtime] client resuming with "+(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH")+" ("+this.collectionName+" "+this.query+") ("+this.watchId+")"),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return t.sent(),console.log("[realtime] client successfully resumed ("+this.collectionName+" "+this.query+") ("+this.watchId+")"),[3,4];case 3:return e=t.sent(),console.error("[realtime] client resume failed ("+this.collectionName+" "+this.query+") ("+this.watchId+")",e),[3,4];case 4:return[2]}}))}))},e.prototype.useRetryTicket=function(e){return!!(this.availableRetries[e]&&this.availableRetries[e]>0)&&(this.availableRetries[e]-=1,console.log("[realtime] "+e+" use a retry ticket, now only "+this.availableRetries[e]+" retry left"),!0)},e.prototype.handleServerEvents=function(e){return b(this,void 0,void 0,(function(){var t;return w(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(e)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(e),[3,3];case 2:throw t=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",t),t;case 3:return[2]}}))}))},e.prototype.handleServerEventsInternel=function(e){return b(this,void 0,void 0,(function(){var t,n,r,o,a,u,l,h,d,p,v,_;return w(this,(function(E){switch(E.label){case 0:if(t=e.requestId,n=e.msgData.events,r=e.msgType,!n.length||!this.sessionInfo)return[2];o=this.sessionInfo;try{a=n.map(A)}catch(e){return this.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:e})),[2]}u=S(o.currentDocs),l=!1,h=function(n,h){var p,v,_,E,g,m,b,T,A,R,C,D;return w(this,(function(w){switch(w.label){case 0:return p=a[n],o.currentEventId>=p.id?(!a[n-1]||p.id>a[n-1].id?console.warn("[realtime] duplicate event received, cur "+o.currentEventId+" but got "+p.id):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId "+t+")"),[2,"continue"]):[3,1];case 1:if(o.currentEventId!==p.id-1)return[3,2];switch(p.dataType){case"update":if(!p.doc)switch(p.queueType){case"update":case"dequeue":if(v=u.find((function(e){return e._id===p.docId}))){if(_=c()(v),p.updatedFields&&Object.keys(p.updatedFields).forEach((function(e){i()(_,e,p.updatedFields[e])})),p.removedFields)for(E=0,g=p.removedFields;E<g.length;E++)m=g[E],s()(_,m);p.doc=_}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break;case"enqueue":throw T=new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '+e.requestId+")"}),d.closeWithError(T),T}break;case"replace":if(!p.doc)throw T=new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '+e.requestId+")"}),d.closeWithError(T),T;break;case"remove":(b=u.find((function(e){return e._id===p.docId})))?p.doc=b:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break;case"limit":if(!p.doc)switch(p.queueType){case"dequeue":(b=u.find((function(e){return e._id===p.docId})))?p.doc=b:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break;case"enqueue":throw T=new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '+e.requestId+")"}),d.closeWithError(T),T}}switch(p.queueType){case"init":l?u.push(p.doc):(l=!0,u=[p.doc]);break;case"enqueue":u.push(p.doc);break;case"dequeue":(A=u.findIndex((function(e){return e._id===p.docId})))>-1?u.splice(A,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break;case"update":(A=u.findIndex((function(e){return e._id===p.docId})))>-1?u[A]=p.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.")}return(n===h-1||a[n+1]&&a[n+1].id!==p.id)&&(R=S(u),C=a.slice(0,n+1).filter((function(e){return e.id===p.id})),d.sessionInfo.currentEventId=p.id,d.sessionInfo.currentDocs=u,D=new f({id:p.id,docChanges:C,docs:R,msgType:r}),d.listener.onChange(D)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur "+d.sessionInfo.currentEventId+" but got "+p.id),[4,d.rebuildWatch()];case 3:return w.sent(),[2,{value:void 0}];case 4:return[2]}}))},d=this,p=0,v=a.length,E.label=1;case 1:return p<v?[5,h(p,v)]:[3,4];case 2:if("object"==typeof(_=E.sent()))return[2,_.value];E.label=3;case 3:return p++,[3,1];case 4:return[2]}}))}))},e.prototype.postHandleServerEventsValidityCheck=function(e){this.sessionInfo?(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<e.msgData.currEvent&&console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling")):console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur")},e.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},e}();function A(e){var t={id:e.ID,dataType:e.DataType,queueType:e.QueueType,docId:e.DocID,doc:e.Doc&&"{}"!==e.Doc?JSON.parse(e.Doc):void 0};return"update"===e.DataType&&(e.UpdatedFields&&(t.updatedFields=JSON.parse(e.UpdatedFields)),(e.removedFields||e.RemovedFields)&&(t.removedFields=JSON.parse(e.removedFields))),t}var R,C={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}};!function(e){e[e.NormalClosure=1e3]="NormalClosure",e[e.GoingAway=1001]="GoingAway",e[e.ProtocolError=1002]="ProtocolError",e[e.UnsupportedData=1003]="UnsupportedData",e[e.NoStatusReceived=1005]="NoStatusReceived",e[e.AbnormalClosure=1006]="AbnormalClosure",e[e.InvalidFramePayloadData=1007]="InvalidFramePayloadData",e[e.PolicyViolation=1008]="PolicyViolation",e[e.MessageTooBig=1009]="MessageTooBig",e[e.MissingExtension=1010]="MissingExtension",e[e.InternalError=1011]="InternalError",e[e.ServiceRestart=1012]="ServiceRestart",e[e.TryAgainLater=1013]="TryAgainLater",e[e.BadGateway=1014]="BadGateway",e[e.TLSHandshake=1015]="TLSHandshake",e[e.ReconnectWebSocket=3e3]="ReconnectWebSocket",e[e.NoRealtimeListeners=3001]="NoRealtimeListeners",e[e.HeartbeatPingError=3002]="HeartbeatPingError",e[e.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",e[e.NoAuthentication=3050]="NoAuthentication"}(R||(R={}));var D=function(e,t){var n=C[e],r=n?n.name+", code "+e+", reason "+(t||n.description):"code "+e;return new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:r})},N=null,O="web";function L(){return O}var W=function(){return(W=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},j=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{c(r.next(e))}catch(e){o(e)}}function a(e){try{c(r.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},P=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,a])}}},M=1,x=function(){function e(e){var t=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(e){return j(t,void 0,void 0,(function(){var t=this;return P(this,(function(n){return[2,new Promise((function(n,r){j(t,void 0,void 0,(function(){var t,i,o,s,a,c,u,l,h=this;return P(this,(function(d){switch(d.label){case 0:i=!1,o=!1,s=function(e){i=!0,t&&clearTimeout(t),n(e)},a=function(e){o=!0,t&&clearTimeout(t),r(e)},e.timeout&&(t=setTimeout((function(){j(h,void 0,void 0,(function(){return P(this,(function(e){switch(e.label){case 0:return i&&o?[3,2]:[4,m(0)];case 1:e.sent(),i&&o||a(new E("wsclient.send timedout")),e.label=2;case 2:return[2]}}))}))}),e.timeout)),d.label=1;case 1:return d.trys.push([1,8,,9]),void 0===this.wsInitPromise&&null===this.wsInitPromise?[3,3]:[4,this.wsInitPromise];case 2:d.sent(),d.label=3;case 3:if(!this.ws)return a(new Error("invalid state: ws connection not exists, can not send message")),[2];if(this.ws.readyState!==M)return a(new Error("ws readyState invalid: "+this.ws.readyState+", can not send message")),[2];e.waitResponse&&(c={resolve:s,reject:a,skipOnMessage:e.skipOnMessage},this.wsResponseWait.set(e.msg.requestId,c)),d.label=4;case 4:return d.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(e.msg))];case 5:return d.sent(),e.waitResponse||s(void 0),[3,7];case 6:return(u=d.sent())&&(a(u),e.waitResponse&&this.wsResponseWait.delete(e.msg.requestId)),[3,7];case 7:return[3,9];case 8:return l=d.sent(),a(l),[3,9];case 9:return[2]}}))}))}))]}))}))},this.closeAllClients=function(e){t.virtualWSClient.forEach((function(t){t.closeWithError(e)}))},this.pauseClients=function(e){(e||t.virtualWSClient).forEach((function(e){e.pause()}))},this.resumeClients=function(e){(e||t.virtualWSClient).forEach((function(e){e.resume()}))},this.initWebSocketConnection=function(e,n){return void 0===n&&(n=t.maxReconnect),j(t,void 0,void 0,(function(){var t=this;return P(this,(function(r){switch(r.label){case 0:if(e&&this.reconnectState)return[2];if(e&&(this.reconnectState=!0),void 0!==this.wsInitPromise&&null!==this.wsInitPromise)return[2,this.wsInitPromise];e&&this.pauseClients(),this.close(R.ReconnectWebSocket),this.wsInitPromise=new Promise((function(r,i){j(t,void 0,void 0,(function(){var t,o,s=this;return P(this,(function(a){switch(a.label){case 0:return a.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return t=a.sent(),[4,new Promise((function(e){var n=t.wsUrl||"wss://tcb-ws.tencentcloudapi.com",r=N;s.ws=r?new r(n):new WebSocket(n),e(void 0)}))];case 2:return a.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:a.sent(),a.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return a.sent(),r(),e&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return o=a.sent(),console.error("[realtime] initWebSocketConnection connect fail",o),n>0?(this.wsInitPromise=void 0,[4,m(this.reconnectInterval)]):[3,9];case 7:a.sent(),e&&(this.reconnectState=!1),a.label=8;case 8:return r(this.initWebSocketConnection(e,n-1)),[3,10];case 9:i(o),e&&this.closeAllClients(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:o})),a.label=10;case 10:return[3,11];case 11:return[2]}}))}))})),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return r.sent(),this.wsReadySubsribers.forEach((function(e){return(0,e.resolve)()})),[3,5];case 3:return r.sent(),this.wsReadySubsribers.forEach((function(e){return(0,e.reject)()})),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}}))}))},this.initWebSocketEvent=function(){return new Promise((function(e,n){if(!t.ws)throw new Error("can not initWebSocketEvent, ws not exists");var r=!1;t.ws.onopen=function(t){console.warn("[realtime] ws event: open",t),r=!0,e()},t.ws.onerror=function(e){t.logins=new Map,r?(console.error("[realtime] ws event: error",e),t.clearHeartbeat(),t.virtualWSClient.forEach((function(t){return t.closeWithError(new I({errCode:y.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:e}))}))):(console.error("[realtime] ws open failed with ws event: error",e),n(e))},t.ws.onclose=function(e){switch(console.warn("[realtime] ws event: close",e),t.logins=new Map,t.clearHeartbeat(),e.code){case R.ReconnectWebSocket:case R.NoRealtimeListeners:break;case R.HeartbeatPingError:case R.HeartbeatPongTimeoutError:case R.NormalClosure:case R.AbnormalClosure:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(D(e.code));break;case R.NoAuthentication:t.closeAllClients(D(e.code,e.reason));break;default:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(D(e.code))}},t.ws.onmessage=function(e){var n,r=e.data;t.heartbeat();try{n=JSON.parse(r)}catch(e){throw new Error("[realtime] onMessage parse res.data error: "+e)}if("ERROR"===n.msgType){var i=null;t.virtualWSClient.forEach((function(e){e.watchId===n.watchId&&(i=e)})),i&&i.listener.onError(n)}var o=t.wsResponseWait.get(n.requestId);if(o){try{"ERROR"===n.msgType?o.reject(new v(n)):o.resolve(n)}catch(e){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",e)}finally{t.wsResponseWait.delete(n.requestId)}if(o.skipOnMessage)return}if("PONG"!==n.msgType){var s=n.watchId&&t.watchIdClientMap.get(n.watchId);if(s)s.onMessage(n);else switch(console.error("[realtime] no realtime listener found responsible for watchId "+n.watchId+": ",n),n.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":(s=t.queryIdClientMap.get(n.msgData.queryID))&&s.onMessage(n);break;default:for(var a=0,c=Array.from(t.watchIdClientMap.entries());a<c.length;a++){c[a][1].onMessage(n);break}}}else if(t.lastPingSendTS){var u=Date.now()-t.lastPingSendTS;if(u>1e4)return void console.warn("[realtime] untrusted rtt observed: "+u);t.rttObserved.length>=3&&t.rttObserved.splice(0,t.rttObserved.length-3+1),t.rttObserved.push(u)}},t.heartbeat()}))},this.isWSConnected=function(){return Boolean(t.ws&&t.ws.readyState===M)},this.onceWSConnected=function(){return j(t,void 0,void 0,(function(){var e=this;return P(this,(function(t){return this.isWSConnected()?[2]:null!==this.wsInitPromise&&void 0!==this.wsInitPromise?[2,this.wsInitPromise]:[2,new Promise((function(t,n){e.wsReadySubsribers.push({resolve:t,reject:n})}))]}))}))},this.webLogin=function(e,n){return j(t,void 0,void 0,(function(){var t,r,i,o,s,a,c,l,h=this;return P(this,(function(d){switch(d.label){case 0:if(!n)if(e){if(t=this.logins.get(e)){if(t.loggedIn&&t.loginResult)return[2,t.loginResult];if(null!==t.loggingInPromise&&void 0!==t.loggingInPromise)return[2,t.loggingInPromise]}}else if(null!==(null==(r=this.logins.get(""))?void 0:r.loggingInPromise)&&void 0!==(null==r?void 0:r.loggingInPromise))return[2,r.loggingInPromise];i=new Promise((function(e,t){j(h,void 0,void 0,(function(){var n,r,i,o,s;return P(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return n=a.sent(),r={envId:n.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},i={watchId:void 0,requestId:u(),msgType:"LOGIN",msgData:r,exMsgData:{runtime:L(),signStr:n.signStr,secretVersion:n.secretVersion}},[4,this.send({msg:i,waitResponse:!0,skipOnMessage:!0,timeout:5e3})];case 2:return(o=a.sent()).msgData.code?t(new Error(o.msgData.code+" "+o.msgData.message)):e({envId:n.envId}),[3,4];case 3:return s=a.sent(),t(s),[3,4];case 4:return[2]}}))}))})),o=e&&this.logins.get(e),s=Date.now(),o?(o.loggedIn=!1,o.loggingInPromise=i,o.loginStartTS=s):(o={loggedIn:!1,loggingInPromise:i,loginStartTS:s},this.logins.set(e||"",o)),d.label=1;case 1:return d.trys.push([1,3,,4]),[4,i];case 2:if(a=d.sent(),(c=e&&this.logins.get(e))&&c===o&&c.loginStartTS===s)return o.loggedIn=!0,o.loggingInPromise=void 0,o.loginStartTS=void 0,o.loginResult=a,[2,a];if(c){if(c.loggedIn&&c.loginResult)return[2,c.loginResult];if(null!==c.loggingInPromise&&void 0!==c.loggingInPromise)return[2,c.loggingInPromise];throw new Error("ws unexpected login info")}throw new Error("ws login info reset");case 3:throw l=d.sent(),o.loggedIn=!1,o.loggingInPromise=void 0,o.loginStartTS=void 0,o.loginResult=void 0,l;case 4:return[2]}}))}))},this.getWsSign=function(){return j(t,void 0,void 0,(function(){var e,t,n,r,i,o,s;return P(this,(function(a){switch(a.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(e=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:L()})]);case 1:if((t=a.sent()).code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: "+t.code);if(t.data)return n=t.data,r=n.signStr,i=n.wsUrl,o=n.secretVersion,s=n.envId,[2,{signStr:r,wsUrl:i,secretVersion:o,envId:s,expiredTs:e}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}}))}))},this.getWaitExpectedTimeoutLength=function(){return t.rttObserved.length?t.rttObserved.reduce((function(e,t){return e+t}))/t.rttObserved.length*1.5:5e3},this.ping=function(){return j(t,void 0,void 0,(function(){var e;return P(this,(function(t){switch(t.label){case 0:return e={watchId:void 0,requestId:u(),msgType:"PING",msgData:null},[4,this.send({msg:e})];case 1:return t.sent(),[2]}}))}))},this.onWatchStart=function(e,n){t.queryIdClientMap.set(n,e)},this.onWatchClose=function(e,n){n&&t.queryIdClientMap.delete(n),t.watchIdClientMap.delete(e.watchId),t.virtualWSClient.delete(e),t.virtualWSClient.size||t.close(R.NoRealtimeListeners)},this.maxReconnect=e.maxReconnect||5,this.reconnectInterval=e.reconnectInterval||1e4,this.context=e.context}return e.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},e.prototype.close=function(e){this.clearHeartbeat(),this.ws&&(this.ws.close(e,C[e].name),this.ws=void 0)},e.prototype.watch=function(e){this.ws||void 0!==this.wsInitPromise&&null!==this.wsInitPromise||this.initWebSocketConnection(!1);var t=new T(W(W({},e),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(t),this.watchIdClientMap.set(t.watchId,t),t.listener},e.prototype.heartbeat=function(e){var t=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout((function(){j(t,void 0,void 0,(function(){var e=this;return P(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.ws&&this.ws.readyState===M?(this.lastPingSendTS=Date.now(),[4,this.ping()]):[2];case 1:return t.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout((function(){console.error("pong timed out"),e.pongMissed<2?(e.pongMissed+=1,e.heartbeat(!0)):e.initWebSocketConnection(!0)}),this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return t.sent(),this.pingFailed<2?(this.pingFailed+=1,this.heartbeat()):this.close(R.HeartbeatPingError),[3,3];case 3:return[2]}}))}))}),e?0:this.context.appConfig.realtimePingInterval)},e}(),k={target:"database",entity:function(){var e,t=this.platform,n=t.adapter,r=t.runtime;e=n.wsClass,N=e,function(e){O=e}(r)}},K={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=x}};try{cloudbase.registerComponent(K),cloudbase.registerHook(k)}catch(e){}function B(e){try{e.registerComponent(K),e.registerHook(k)}catch(e){console.warn(e)}}}])}));
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_realtime",[],t):"object"==typeof exports?exports.cloudbase_realtime=t():e.cloudbase_realtime=t()}("undefined"!=typeof window?window:this,(()=>(()=>{var e={78:(e,t,n)=>{e=n.nmd(e);var r="__lodash_hash_undefined__",o=9007199254740991,i="[object Arguments]",s="[object Boolean]",a="[object Date]",c="[object Function]",u="[object GeneratorFunction]",l="[object Map]",h="[object Number]",d="[object Object]",f="[object Promise]",p="[object RegExp]",v="[object Set]",_="[object String]",g="[object Symbol]",E="[object WeakMap]",y="[object ArrayBuffer]",I="[object DataView]",m="[object Float32Array]",w="[object Float64Array]",b="[object Int8Array]",S="[object Int16Array]",T="[object Int32Array]",A="[object Uint8Array]",R="[object Uint8ClampedArray]",C="[object Uint16Array]",N="[object Uint32Array]",D=/\w*$/,L=/^\[object .+?Constructor\]$/,O=/^(?:0|[1-9]\d*)$/,W={};W[i]=W["[object Array]"]=W[y]=W[I]=W[s]=W[a]=W[m]=W[w]=W[b]=W[S]=W[T]=W[l]=W[h]=W[d]=W[p]=W[v]=W[_]=W[g]=W[A]=W[R]=W[C]=W[N]=!0,W["[object Error]"]=W[c]=W[E]=!1;var P="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,M="object"==typeof self&&self&&self.Object===Object&&self,j=P||M||Function("return this")(),x=t&&!t.nodeType&&t,k=x&&e&&!e.nodeType&&e,K=k&&k.exports===x;function B(e,t){return e.set(t[0],t[1]),e}function H(e,t){return e.add(t),e}function q(e,t,n,r){var o=-1,i=e?e.length:0;for(r&&i&&(n=e[++o]);++o<i;)n=t(n,e[o],o,e);return n}function F(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}function G(e){var t=-1,n=Array(e.size);return e.forEach((function(e,r){n[++t]=[r,e]})),n}function U(e,t){return function(n){return e(t(n))}}function V(e){var t=-1,n=Array(e.size);return e.forEach((function(e){n[++t]=e})),n}var $,J=Array.prototype,X=Function.prototype,z=Object.prototype,Q=j["__core-js_shared__"],Y=($=/[^.]+$/.exec(Q&&Q.keys&&Q.keys.IE_PROTO||""))?"Symbol(src)_1."+$:"",Z=X.toString,ee=z.hasOwnProperty,te=z.toString,ne=RegExp("^"+Z.call(ee).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),re=K?j.Buffer:void 0,oe=j.Symbol,ie=j.Uint8Array,se=U(Object.getPrototypeOf,Object),ae=Object.create,ce=z.propertyIsEnumerable,ue=J.splice,le=Object.getOwnPropertySymbols,he=re?re.isBuffer:void 0,de=U(Object.keys,Object),fe=je(j,"DataView"),pe=je(j,"Map"),ve=je(j,"Promise"),_e=je(j,"Set"),ge=je(j,"WeakMap"),Ee=je(Object,"create"),ye=He(fe),Ie=He(pe),me=He(ve),we=He(_e),be=He(ge),Se=oe?oe.prototype:void 0,Te=Se?Se.valueOf:void 0;function Ae(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Re(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Ce(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function Ne(e){this.__data__=new Re(e)}function De(e,t,n){var r=e[t];ee.call(e,t)&&qe(r,n)&&(void 0!==n||t in e)||(e[t]=n)}function Le(e,t){for(var n=e.length;n--;)if(qe(e[n][0],t))return n;return-1}function Oe(e,t,n,r,o,f,E){var L;if(r&&(L=f?r(e,o,f,E):r(e)),void 0!==L)return L;if(!$e(e))return e;var O=Fe(e);if(O){if(L=function(e){var t=e.length,n=e.constructor(t);return t&&"string"==typeof e[0]&&ee.call(e,"index")&&(n.index=e.index,n.input=e.input),n}(e),!t)return function(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}(e,L)}else{var P=ke(e),M=P==c||P==u;if(Ue(e))return function(e,t){if(t)return e.slice();var n=new e.constructor(e.length);return e.copy(n),n}(e,t);if(P==d||P==i||M&&!f){if(F(e))return f?e:{};if(L=function(e){return"function"!=typeof e.constructor||Be(e)?{}:$e(t=se(e))?ae(t):{};var t}(M?{}:e),!t)return function(e,t){return Pe(e,xe(e),t)}(e,function(e,t){return e&&Pe(t,Je(t),e)}(L,e))}else{if(!W[P])return f?e:{};L=function(e,t,n,r){var o,i=e.constructor;switch(t){case y:return We(e);case s:case a:return new i(+e);case I:return function(e,t){var n=t?We(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}(e,r);case m:case w:case b:case S:case T:case A:case R:case C:case N:return function(e,t){var n=t?We(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}(e,r);case l:return function(e,t,n){return q(t?n(G(e),!0):G(e),B,new e.constructor)}(e,r,n);case h:case _:return new i(e);case p:return function(e){var t=new e.constructor(e.source,D.exec(e));return t.lastIndex=e.lastIndex,t}(e);case v:return function(e,t,n){return q(t?n(V(e),!0):V(e),H,new e.constructor)}(e,r,n);case g:return o=e,Te?Object(Te.call(o)):{}}}(e,P,Oe,t)}}E||(E=new Ne);var j=E.get(e);if(j)return j;if(E.set(e,L),!O)var x=n?function(e){return function(e,t,n){var r=t(e);return Fe(e)?r:function(e,t){for(var n=-1,r=t.length,o=e.length;++n<r;)e[o+n]=t[n];return e}(r,n(e))}(e,Je,xe)}(e):Je(e);return function(e,t){for(var n=-1,r=e?e.length:0;++n<r&&!1!==t(e[n],n););}(x||e,(function(o,i){x&&(o=e[i=o]),De(L,i,Oe(o,t,n,r,i,e,E))})),L}function We(e){var t=new e.constructor(e.byteLength);return new ie(t).set(new ie(e)),t}function Pe(e,t,n,r){n||(n={});for(var o=-1,i=t.length;++o<i;){var s=t[o],a=r?r(n[s],e[s],s,n,e):void 0;De(n,s,void 0===a?e[s]:a)}return n}function Me(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function je(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){return!(!$e(e)||(t=e,Y&&Y in t))&&(Ve(e)||F(e)?ne:L).test(He(e));var t}(n)?n:void 0}Ae.prototype.clear=function(){this.__data__=Ee?Ee(null):{}},Ae.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},Ae.prototype.get=function(e){var t=this.__data__;if(Ee){var n=t[e];return n===r?void 0:n}return ee.call(t,e)?t[e]:void 0},Ae.prototype.has=function(e){var t=this.__data__;return Ee?void 0!==t[e]:ee.call(t,e)},Ae.prototype.set=function(e,t){return this.__data__[e]=Ee&&void 0===t?r:t,this},Re.prototype.clear=function(){this.__data__=[]},Re.prototype.delete=function(e){var t=this.__data__,n=Le(t,e);return!(n<0||(n==t.length-1?t.pop():ue.call(t,n,1),0))},Re.prototype.get=function(e){var t=this.__data__,n=Le(t,e);return n<0?void 0:t[n][1]},Re.prototype.has=function(e){return Le(this.__data__,e)>-1},Re.prototype.set=function(e,t){var n=this.__data__,r=Le(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},Ce.prototype.clear=function(){this.__data__={hash:new Ae,map:new(pe||Re),string:new Ae}},Ce.prototype.delete=function(e){return Me(this,e).delete(e)},Ce.prototype.get=function(e){return Me(this,e).get(e)},Ce.prototype.has=function(e){return Me(this,e).has(e)},Ce.prototype.set=function(e,t){return Me(this,e).set(e,t),this},Ne.prototype.clear=function(){this.__data__=new Re},Ne.prototype.delete=function(e){return this.__data__.delete(e)},Ne.prototype.get=function(e){return this.__data__.get(e)},Ne.prototype.has=function(e){return this.__data__.has(e)},Ne.prototype.set=function(e,t){var n=this.__data__;if(n instanceof Re){var r=n.__data__;if(!pe||r.length<199)return r.push([e,t]),this;n=this.__data__=new Ce(r)}return n.set(e,t),this};var xe=le?U(le,Object):function(){return[]},ke=function(e){return te.call(e)};function Ke(e,t){return!!(t=null==t?o:t)&&("number"==typeof e||O.test(e))&&e>-1&&e%1==0&&e<t}function Be(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||z)}function He(e){if(null!=e){try{return Z.call(e)}catch(e){}try{return e+""}catch(e){}}return""}function qe(e,t){return e===t||e!=e&&t!=t}(fe&&ke(new fe(new ArrayBuffer(1)))!=I||pe&&ke(new pe)!=l||ve&&ke(ve.resolve())!=f||_e&&ke(new _e)!=v||ge&&ke(new ge)!=E)&&(ke=function(e){var t=te.call(e),n=t==d?e.constructor:void 0,r=n?He(n):void 0;if(r)switch(r){case ye:return I;case Ie:return l;case me:return f;case we:return v;case be:return E}return t});var Fe=Array.isArray;function Ge(e){return null!=e&&function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=o}(e.length)&&!Ve(e)}var Ue=he||function(){return!1};function Ve(e){var t=$e(e)?te.call(e):"";return t==c||t==u}function $e(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function Je(e){return Ge(e)?function(e,t){var n=Fe(e)||function(e){return function(e){return function(e){return!!e&&"object"==typeof e}(e)&&Ge(e)}(e)&&ee.call(e,"callee")&&(!ce.call(e,"callee")||te.call(e)==i)}(e)?function(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}(e.length,String):[],r=n.length,o=!!r;for(var s in e)!t&&!ee.call(e,s)||o&&("length"==s||Ke(s,r))||n.push(s);return n}(e):function(e){if(!Be(e))return de(e);var t=[];for(var n in Object(e))ee.call(e,n)&&"constructor"!=n&&t.push(n);return t}(e)}e.exports=function(e){return Oe(e,!0,!0)}},484:(e,t,n)=>{var r,o="Expected a function",i="__lodash_hash_undefined__",s=1/0,a=9007199254740991,c="[object Function]",u="[object GeneratorFunction]",l="[object Symbol]",h=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,d=/^\w*$/,f=/^\./,p=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,v=/\\(\\)?/g,_=/^\[object .+?Constructor\]$/,g=/^(?:0|[1-9]\d*)$/,E="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,y="object"==typeof self&&self&&self.Object===Object&&self,I=E||y||Function("return this")(),m=Array.prototype,w=Function.prototype,b=Object.prototype,S=I["__core-js_shared__"],T=(r=/[^.]+$/.exec(S&&S.keys&&S.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",A=w.toString,R=b.hasOwnProperty,C=b.toString,N=RegExp("^"+A.call(R).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),D=I.Symbol,L=m.splice,O=q(I,"Map"),W=q(Object,"create"),P=D?D.prototype:void 0,M=P?P.toString:void 0;function j(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function x(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function k(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function K(e,t,n){var r=e[t];R.call(e,t)&&$(r,n)&&(void 0!==n||t in e)||(e[t]=n)}function B(e,t){for(var n=e.length;n--;)if($(e[n][0],t))return n;return-1}function H(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function q(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){if(!X(e)||T&&T in e)return!1;var t=function(e){var t=X(e)?C.call(e):"";return t==c||t==u}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?N:_;return t.test(function(e){if(null!=e){try{return A.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}(n)?n:void 0}function F(e,t){return!!(t=null==t?a:t)&&("number"==typeof e||g.test(e))&&e>-1&&e%1==0&&e<t}j.prototype.clear=function(){this.__data__=W?W(null):{}},j.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},j.prototype.get=function(e){var t=this.__data__;if(W){var n=t[e];return n===i?void 0:n}return R.call(t,e)?t[e]:void 0},j.prototype.has=function(e){var t=this.__data__;return W?void 0!==t[e]:R.call(t,e)},j.prototype.set=function(e,t){return this.__data__[e]=W&&void 0===t?i:t,this},x.prototype.clear=function(){this.__data__=[]},x.prototype.delete=function(e){var t=this.__data__,n=B(t,e);return!(n<0||(n==t.length-1?t.pop():L.call(t,n,1),0))},x.prototype.get=function(e){var t=this.__data__,n=B(t,e);return n<0?void 0:t[n][1]},x.prototype.has=function(e){return B(this.__data__,e)>-1},x.prototype.set=function(e,t){var n=this.__data__,r=B(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},k.prototype.clear=function(){this.__data__={hash:new j,map:new(O||x),string:new j}},k.prototype.delete=function(e){return H(this,e).delete(e)},k.prototype.get=function(e){return H(this,e).get(e)},k.prototype.has=function(e){return H(this,e).has(e)},k.prototype.set=function(e,t){return H(this,e).set(e,t),this};var G=V((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if(z(e))return M?M.call(e):"";var t=e+"";return"0"==t&&1/e==-s?"-0":t}(t);var n=[];return f.test(e)&&n.push(""),e.replace(p,(function(e,t,r,o){n.push(r?o.replace(v,"$1"):t||e)})),n}));function U(e){if("string"==typeof e||z(e))return e;var t=e+"";return"0"==t&&1/e==-s?"-0":t}function V(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError(o);var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=e.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(V.Cache||k),n}function $(e,t){return e===t||e!=e&&t!=t}V.Cache=k;var J=Array.isArray;function X(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function z(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&C.call(e)==l}e.exports=function(e,t,n){return null==e?e:function(e,t,n,r){if(!X(e))return e;t=function(e,t){if(J(e))return!1;var n=typeof e;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!z(e))||d.test(e)||!h.test(e)||null!=t&&e in Object(t)}(t,e)?[t]:function(e){return J(e)?e:G(e)}(t);for(var o=-1,i=t.length,s=i-1,a=e;null!=a&&++o<i;){var c=U(t[o]),u=n;if(o!=s){var l=a[c];void 0===(u=r?r(l,c,a):void 0)&&(u=X(l)?l:F(t[o+1])?[]:{})}K(a,c,u),a=a[c]}return e}(e,t,n)}},857:(e,t,n)=>{var r,o="Expected a function",i="__lodash_hash_undefined__",s=1/0,a="[object Function]",c="[object GeneratorFunction]",u="[object Symbol]",l=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,h=/^\w*$/,d=/^\./,f=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,p=/\\(\\)?/g,v=/^\[object .+?Constructor\]$/,_="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,g="object"==typeof self&&self&&self.Object===Object&&self,E=_||g||Function("return this")(),y=Array.prototype,I=Function.prototype,m=Object.prototype,w=E["__core-js_shared__"],b=(r=/[^.]+$/.exec(w&&w.keys&&w.keys.IE_PROTO||""))?"Symbol(src)_1."+r:"",S=I.toString,T=m.hasOwnProperty,A=m.toString,R=RegExp("^"+S.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),C=E.Symbol,N=y.splice,D=B(E,"Map"),L=B(Object,"create"),O=C?C.prototype:void 0,W=O?O.toString:void 0;function P(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function M(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function j(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function x(e,t){for(var n,r,o=e.length;o--;)if((n=e[o][0])===(r=t)||n!=n&&r!=r)return o;return-1}function k(e){return U(e)?e:q(e)}function K(e,t){var n,r,o=e.__data__;return("string"==(r=typeof(n=t))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof t?"string":"hash"]:o.map}function B(e,t){var n=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){if(!V(e)||b&&b in e)return!1;var t=function(e){var t=V(e)?A.call(e):"";return t==a||t==c}(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e)?R:v;return t.test(function(e){if(null!=e){try{return S.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}(n)?n:void 0}function H(e,t){if(U(e))return!1;var n=typeof e;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=e&&!$(e))||h.test(e)||!l.test(e)||null!=t&&e in Object(t)}P.prototype.clear=function(){this.__data__=L?L(null):{}},P.prototype.delete=function(e){return this.has(e)&&delete this.__data__[e]},P.prototype.get=function(e){var t=this.__data__;if(L){var n=t[e];return n===i?void 0:n}return T.call(t,e)?t[e]:void 0},P.prototype.has=function(e){var t=this.__data__;return L?void 0!==t[e]:T.call(t,e)},P.prototype.set=function(e,t){return this.__data__[e]=L&&void 0===t?i:t,this},M.prototype.clear=function(){this.__data__=[]},M.prototype.delete=function(e){var t=this.__data__,n=x(t,e);return!(n<0||(n==t.length-1?t.pop():N.call(t,n,1),0))},M.prototype.get=function(e){var t=this.__data__,n=x(t,e);return n<0?void 0:t[n][1]},M.prototype.has=function(e){return x(this.__data__,e)>-1},M.prototype.set=function(e,t){var n=this.__data__,r=x(n,e);return r<0?n.push([e,t]):n[r][1]=t,this},j.prototype.clear=function(){this.__data__={hash:new P,map:new(D||M),string:new P}},j.prototype.delete=function(e){return K(this,e).delete(e)},j.prototype.get=function(e){return K(this,e).get(e)},j.prototype.has=function(e){return K(this,e).has(e)},j.prototype.set=function(e,t){return K(this,e).set(e,t),this};var q=G((function(e){var t;e=null==(t=e)?"":function(e){if("string"==typeof e)return e;if($(e))return W?W.call(e):"";var t=e+"";return"0"==t&&1/e==-s?"-0":t}(t);var n=[];return d.test(e)&&n.push(""),e.replace(f,(function(e,t,r,o){n.push(r?o.replace(p,"$1"):t||e)})),n}));function F(e){if("string"==typeof e||$(e))return e;var t=e+"";return"0"==t&&1/e==-s?"-0":t}function G(e,t){if("function"!=typeof e||t&&"function"!=typeof t)throw new TypeError(o);var n=function(){var r=arguments,o=t?t.apply(this,r):r[0],i=n.cache;if(i.has(o))return i.get(o);var s=e.apply(this,r);return n.cache=i.set(o,s),s};return n.cache=new(G.Cache||j),n}G.Cache=j;var U=Array.isArray;function V(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function $(e){return"symbol"==typeof e||function(e){return!!e&&"object"==typeof e}(e)&&A.call(e)==u}e.exports=function(e,t){return null==e||function(e,t){e=function(e,t){return 1==t.length?e:function(e,t){for(var n=0,r=(t=H(t,e)?[t]:k(t)).length;null!=e&&n<r;)e=e[F(t[n++])];return n&&n==r?e:void 0}(e,function(e,t,n){var r=-1,o=e.length;t<0&&(t=-t>o?0:o+t),(n=n>o?o:n)<0&&(n+=o),o=t>n?0:n-t>>>0,t>>>=0;for(var i=Array(o);++r<o;)i[r]=e[r+t];return i}(t,0,-1))}(e,t=H(t,e)?[t]:k(t));var n,r,o=F((r=(n=t)?n.length:0)?n[r-1]:void 0);return!(null!=e&&T.call(e,o))||delete e[o]}(e,t)}},337:(e,t,n)=>{"use strict";n.r(t),n.d(t,{registerRealtime:()=>H});var r=n(484),o=n.n(r),i=n(857),s=n.n(i),a=n(78),c=n.n(a);function u(e){return void 0===e&&(e=""),"".concat(e?"".concat(e,"_"):"").concat(+new Date,"_").concat(Math.random())}var l,h,d=function(e){this.close=e.close,this.onChange=e.onChange,this.onError=e.onError,e.debug&&Object.defineProperty(this,"virtualClient",{get:function(){return e.virtualClient}})},f=function(e){var t,n,r=e.id,o=e.docChanges,i=e.docs,s=e.msgType,a=e.type;Object.defineProperties(this,{id:{get:function(){return r},enumerable:!0},docChanges:{get:function(){return t||(t=JSON.parse(JSON.stringify(o))),t},enumerable:!0},docs:{get:function(){return n||(n=JSON.parse(JSON.stringify(i))),n},enumerable:!0},msgType:{get:function(){return s},enumerable:!0},type:{get:function(){return a},enumerable:!0}})},p=(l=function(e,t){return l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},l(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}l(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),v=function(e){function t(t){var n=e.call(this,"Watch Error ".concat(JSON.stringify(t.msgData)," (requestid: ").concat(t.requestId,")"))||this;return n.isRealtimeErrorMessageError=!0,n.payload=t,n}return p(t,e),t}(Error),_=function(e){return null==e?void 0:e.isRealtimeErrorMessageError},g=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="timeout",t.payload=null,t.generic=!0,t}return p(t,e),t}(Error),E=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.type="cancelled",t.payload=null,t.generic=!0,t}return p(t,e),t}(Error),y=function(e){function t(t){var n=e.call(this,t.errMsg)||this;return n.errCode="UNKNOWN_ERROR",Object.defineProperties(n,{message:{get:function(){return"errCode: ".concat(this.errCode," ").concat(I[this.errCode]||""," | errMsg: ").concat(this.errMsg)},set:function(e){this.errMsg=e}}}),n.errCode=t.errCode||"UNKNOWN_ERROR",n.errMsg=t.errMsg,n}return p(t,e),Object.defineProperty(t.prototype,"message",{get:function(){return"errCode: ".concat(this.errCode," | errMsg: ").concat(this.errMsg)},set:function(e){this.errMsg=e},enumerable:!1,configurable:!0}),t}(Error),I={UNKNOWN_ERROR:"UNKNOWN_ERROR",SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL",SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG:"SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG",SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA:"SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR",SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED:"SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED",SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL:"SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL",SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR:"SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR"},m=function(e){return void 0===e&&(e=0),new Promise((function(t){return setTimeout(t,e)}))},w=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},b=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},S=function(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))};!function(e){e.LOGGINGIN="LOGGINGIN",e.INITING="INITING",e.REBUILDING="REBUILDING",e.ACTIVE="ACTIVE",e.ERRORED="ERRORED",e.CLOSING="CLOSING",e.CLOSED="CLOSED",e.PAUSED="PAUSED",e.RESUMING="RESUMING"}(h||(h={}));var T=function(){function e(e){var t=this;this.watchStatus=h.INITING,this.wsLogin=function(e,n){return w(t,void 0,void 0,(function(){var t;return b(this,(function(r){switch(r.label){case 0:return this.watchStatus=h.LOGGINGIN,[4,this.login(e,n)];case 1:return t=r.sent(),this.envId||(this.envId=t.envId),[2,t]}}))}))},this.initWatch=function(e){return w(t,void 0,void 0,(function(){var t,n=this;return b(this,(function(r){switch(r.label){case 0:if(null!==this.initWatchPromise&&void 0!==this.initWatchPromise)return[2,this.initWatchPromise];this.initWatchPromise=new Promise((function(t,r){w(n,void 0,void 0,(function(){var n,o,i,s,a,c,l,d,p,v;return b(this,(function(_){switch(_.label){case 0:return _.trys.push([0,3,,4]),this.watchStatus===h.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:return n=_.sent().envId,this.watchStatus===h.PAUSED?(console.log("[realtime] initWatch cancelled on pause"),[2,t()]):(this.watchStatus=h.INITING,o={watchId:this.watchId,requestId:u(),msgType:"INIT_WATCH",msgData:{envId:n,collName:this.collectionName,query:this.query,limit:this.limit,orderBy:this.orderBy}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:1e4})]);case 2:if(i=_.sent(),s=i.msgData,a=s.events,c=s.currEvent,this.sessionInfo={queryID:i.msgData.queryID,currentEventId:c-1,currentDocs:[]},a.length>0){for(l=0,d=a;l<d.length;l++)d[l].ID=c;this.handleServerEvents(i)}else this.sessionInfo.currentEventId=c,p=new f({id:c,docChanges:[],docs:[],type:"init"}),this.listener.onChange(p),this.scheduleSendACK();return this.onWatchStart(this,this.sessionInfo.queryID),this.watchStatus=h.ACTIVE,this.availableRetries.INIT_WATCH=2,t(),[3,4];case 3:return v=_.sent(),this.handleWatchEstablishmentError(v,{operationName:"INIT_WATCH",resolve:t,reject:r}),[3,4];case 4:return[2]}}))}))})),t=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.initWatchPromise];case 2:return r.sent(),t=!0,[3,4];case 3:return this.initWatchPromise=void 0,[7];case 4:return console.log("[realtime] initWatch ".concat(t?"success":"fail")),[2]}}))}))},this.rebuildWatch=function(e){return w(t,void 0,void 0,(function(){var t,n=this;return b(this,(function(r){switch(r.label){case 0:if(null!==this.rebuildWatchPromise&&void 0!==this.rebuildWatchPromise)return[2,this.rebuildWatchPromise];this.rebuildWatchPromise=new Promise((function(t,r){w(n,void 0,void 0,(function(){var n,o,i,s;return b(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),this.watchStatus===h.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):[4,this.wsLogin(this.envId,e)];case 1:if(n=a.sent().envId,!this.sessionInfo)throw new Error("can not rebuildWatch without a successful initWatch (lack of sessionInfo)");return this.watchStatus===h.PAUSED?(console.log("[realtime] rebuildWatch cancelled on pause"),[2,t()]):(this.watchStatus=h.REBUILDING,o={watchId:this.watchId,requestId:u(),msgType:"REBUILD_WATCH",msgData:{envId:n,collName:this.collectionName,queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!1,timeout:1e4})]);case 2:return i=a.sent(),this.handleServerEvents(i),this.watchStatus=h.ACTIVE,this.availableRetries.REBUILD_WATCH=2,t(),[3,4];case 3:return s=a.sent(),this.handleWatchEstablishmentError(s,{operationName:"REBUILD_WATCH",resolve:t,reject:r}),[3,4];case 4:return[2]}}))}))})),t=!1,r.label=1;case 1:return r.trys.push([1,,3,4]),[4,this.rebuildWatchPromise];case 2:return r.sent(),t=!0,[3,4];case 3:return this.rebuildWatchPromise=void 0,[7];case 4:return console.log("[realtime] rebuildWatch ".concat(t?"success":"fail")),[2]}}))}))},this.handleWatchEstablishmentError=function(e,n){return w(t,void 0,void 0,(function(){var t,r,o,i=this;return b(this,(function(s){return t="INIT_WATCH"===n.operationName,r=function(){i.closeWithError(new y({errCode:t?I.SDK_DATABASE_REALTIME_LISTENER_INIT_WATCH_FAIL:I.SDK_DATABASE_REALTIME_LISTENER_REBUILD_WATCH_FAIL,errMsg:e})),n.reject(e)},o=function(e){i.useRetryTicket(n.operationName)?t?(i.initWatchPromise=void 0,n.resolve(i.initWatch(e))):(i.rebuildWatchPromise=void 0,n.resolve(i.rebuildWatch(e))):r()},this.handleCommonError(e,{onSignError:function(){return o(!0)},onTimeoutError:function(){return o(!1)},onNotRetryableError:r,onCancelledError:n.reject,onUnknownError:function(){w(i,void 0,void 0,(function(){var e,t=this;return b(this,(function(r){switch(r.label){case 0:return r.trys.push([0,8,,9]),e=function(){return w(t,void 0,void 0,(function(){return b(this,(function(e){switch(e.label){case 0:return this.pause(),[4,this.onceWSConnected()];case 1:return e.sent(),o(!0),[2]}}))}))},this.isWSConnected()?[3,2]:[4,e()];case 1:return r.sent(),[3,7];case 2:return[4,m(100)];case 3:return r.sent(),this.watchStatus!==h.PAUSED?[3,4]:(n.reject(new E("".concat(n.operationName," cancelled due to pause after unknownError"))),[3,7]);case 4:return this.isWSConnected()?[3,6]:[4,e()];case 5:return r.sent(),[3,7];case 6:o(!1),r.label=7;case 7:return[3,9];case 8:return r.sent(),o(!0),[3,9];case 9:return[2]}}))}))}}),[2]}))}))},this.closeWatch=function(){return w(t,void 0,void 0,(function(){var e,t,n;return b(this,(function(r){switch(r.label){case 0:if(e=this.sessionInfo?this.sessionInfo.queryID:"",this.watchStatus!==h.ACTIVE)return this.watchStatus=h.CLOSED,this.onWatchClose(this,e),[2];r.label=1;case 1:return r.trys.push([1,3,4,5]),this.watchStatus=h.CLOSING,t={watchId:this.watchId,requestId:u(),msgType:"CLOSE_WATCH",msgData:null},[4,this.send({msg:t})];case 2:return r.sent(),this.sessionInfo=void 0,this.watchStatus=h.CLOSED,[3,5];case 3:return n=r.sent(),this.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_CLOSE_WATCH_FAIL,errMsg:n})),[3,5];case 4:return this.onWatchClose(this,e),[7];case 5:return[2]}}))}))},this.scheduleSendACK=function(){t.clearACKSchedule(),t.ackTimeoutId=setTimeout((function(){t.waitExpectedTimeoutId?t.scheduleSendACK():t.sendACK()}),1e4)},this.clearACKSchedule=function(){t.ackTimeoutId&&clearTimeout(t.ackTimeoutId)},this.sendACK=function(){return w(t,void 0,void 0,(function(){var e,t,n;return b(this,(function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.watchStatus!==h.ACTIVE?(this.scheduleSendACK(),[2]):this.sessionInfo?(e={watchId:this.watchId,requestId:u(),msgType:"CHECK_LAST",msgData:{queryID:this.sessionInfo.queryID,eventID:this.sessionInfo.currentEventId}},[4,this.send({msg:e})]):(console.warn("[realtime listener] can not send ack without a successful initWatch (lack of sessionInfo)"),[2]);case 1:return r.sent(),this.scheduleSendACK(),[3,3];case 2:if(t=r.sent(),_(t))switch((n=t.payload).msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return this.rebuildWatch(),[2];case"QUERYID_INVALID_ERROR":case"SYS_ERR":case"INVALIID_ENV":case"COLLECTION_PERMISSION_DENIED":return this.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:n.msgData.code})),[2]}return this.availableRetries.CHECK_LAST&&this.availableRetries.CHECK_LAST>0?(this.availableRetries.CHECK_LAST-=1,this.scheduleSendACK()):this.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_CHECK_LAST_FAIL,errMsg:t})),[3,3];case 3:return[2]}}))}))},this.handleCommonError=function(e,t){if(_(e))switch(e.payload.msgData.code){case"CHECK_LOGIN_FAILED":case"SIGN_EXPIRED_ERROR":case"SIGN_INVALID_ERROR":case"SIGN_PARAM_INVALID":return void t.onSignError(e);default:return void t.onNotRetryableError(e)}else{if(function(e){return"timeout"===e.type}(e))return void t.onTimeoutError(e);if(function(e){return"cancelled"===e.type}(e))return void t.onCancelledError(e)}t.onUnknownError(e)},this.watchId="watchid_".concat(+new Date,"_").concat(Math.random()),this.envId=e.envId,this.collectionName=e.collectionName,this.query=e.query,this.limit=e.limit,this.orderBy=e.orderBy,this.send=e.send,this.login=e.login,this.isWSConnected=e.isWSConnected,this.onceWSConnected=e.onceWSConnected,this.getWaitExpectedTimeoutLength=e.getWaitExpectedTimeoutLength,this.onWatchStart=e.onWatchStart,this.onWatchClose=e.onWatchClose,this.debug=e.debug,this.availableRetries={INIT_WATCH:2,REBUILD_WATCH:2,CHECK_LAST:2},this.listener=new d({close:function(){t.closeWatch()},onChange:e.onChange,onError:e.onError,debug:this.debug,virtualClient:this}),this.initWatch()}return e.prototype.onMessage=function(e){var t=this;switch(this.watchStatus){case h.PAUSED:if("ERROR"!==e.msgType)return;break;case h.LOGGINGIN:case h.INITING:case h.REBUILDING:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received while ".concat(this.watchStatus));case h.CLOSED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has closed");case h.ERRORED:return void console.warn("[realtime listener] internal non-fatal error: unexpected message received when the watch has ended with error")}if(this.sessionInfo)switch(this.scheduleSendACK(),e.msgType){case"NEXT_EVENT":console.warn("nextevent ".concat(e.msgData.currEvent," ignored"),e),this.handleServerEvents(e);break;case"CHECK_EVENT":this.sessionInfo.currentEventId<e.msgData.currEvent&&(this.sessionInfo.expectEventId=e.msgData.currEvent,this.clearWaitExpectedEvent(),this.waitExpectedTimeoutId=setTimeout((function(){t.rebuildWatch()}),this.getWaitExpectedTimeoutLength()),console.log("[realtime] waitExpectedTimeoutLength ".concat(this.getWaitExpectedTimeoutLength())));break;case"ERROR":this.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_SERVER_ERROR_MSG,errMsg:"".concat(e.msgData.code," - ").concat(e.msgData.message)}));break;default:console.warn("[realtime listener] virtual client receive unexpected msg ".concat(e.msgType,": "),e)}else console.warn("[realtime listener] internal non-fatal error: sessionInfo not found while message is received.")},e.prototype.closeWithError=function(e){var t;this.watchStatus=h.ERRORED,this.clearACKSchedule(),this.listener.onError(e),this.onWatchClose(this,(null===(t=this.sessionInfo)||void 0===t?void 0:t.queryID)||""),console.log("[realtime] client closed (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},e.prototype.pause=function(){this.watchStatus=h.PAUSED,console.log("[realtime] client paused (".concat(this.collectionName," ").concat(this.query,") (watchId ").concat(this.watchId,")"))},e.prototype.resume=function(){return w(this,void 0,void 0,(function(){var e;return b(this,(function(t){switch(t.label){case 0:this.watchStatus=h.RESUMING,console.log("[realtime] client resuming with ".concat(this.sessionInfo?"REBUILD_WATCH":"INIT_WATCH"," (").concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.sessionInfo?this.rebuildWatch():this.initWatch()];case 2:return t.sent(),console.log("[realtime] client successfully resumed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")")),[3,4];case 3:return e=t.sent(),console.error("[realtime] client resume failed (".concat(this.collectionName," ").concat(this.query,") (").concat(this.watchId,")"),e),[3,4];case 4:return[2]}}))}))},e.prototype.useRetryTicket=function(e){return!!(this.availableRetries[e]&&this.availableRetries[e]>0)&&(this.availableRetries[e]-=1,console.log("[realtime] ".concat(e," use a retry ticket, now only ").concat(this.availableRetries[e]," retry left")),!0)},e.prototype.handleServerEvents=function(e){return w(this,void 0,void 0,(function(){var t;return b(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),this.scheduleSendACK(),[4,this.handleServerEventsInternel(e)];case 1:return n.sent(),this.postHandleServerEventsValidityCheck(e),[3,3];case 2:throw t=n.sent(),console.error("[realtime listener] internal non-fatal error: handle server events failed with error: ",t),t;case 3:return[2]}}))}))},e.prototype.handleServerEventsInternel=function(e){return w(this,void 0,void 0,(function(){var t,n,r,i,a,u,l,h,d,p,v,_;return b(this,(function(g){switch(g.label){case 0:if(t=e.requestId,n=e.msgData.events,r=e.msgType,!n.length||!this.sessionInfo)return[2];i=this.sessionInfo;try{a=n.map(A)}catch(e){return this.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_RECEIVE_INVALID_SERVER_DATA,errMsg:e})),[2]}u=S([],i.currentDocs,!0),l=!1,h=function(n,h){var p,v,_,g,E,m,w,T,A,R,C,N;return b(this,(function(b){switch(b.label){case 0:return p=a[n],i.currentEventId>=p.id?(!a[n-1]||p.id>a[n-1].id?console.warn("[realtime] duplicate event received, cur ".concat(i.currentEventId," but got ").concat(p.id)):console.error("[realtime listener] server non-fatal error: events out of order (the latter event's id is smaller than that of the former) (requestId ".concat(t,")")),[2,"continue"]):[3,1];case 1:if(i.currentEventId!==p.id-1)return[3,2];switch(p.dataType){case"update":if(!p.doc)switch(p.queueType){case"update":case"dequeue":if(v=u.find((function(e){return e._id===p.docId})),v){if(_=c()(v),p.updatedFields&&Object.keys(p.updatedFields).forEach((function(e){o()(_,e,p.updatedFields[e])})),p.removedFields)for(g=0,E=p.removedFields;g<E.length;g++)m=E[g],s()(_,m);p.doc=_}else console.error("[realtime listener] internal non-fatal server error: unexpected update dataType event where no doc is associated.");break;case"enqueue":throw T=new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="update" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),d.closeWithError(T),T}break;case"replace":if(!p.doc)throw T=new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="replace" (requestId '.concat(e.requestId,")")}),d.closeWithError(T),T;break;case"remove":(w=u.find((function(e){return e._id===p.docId})))?p.doc=w:console.error("[realtime listener] internal non-fatal server error: unexpected remove event where no doc is associated.");break;case"limit":if(!p.doc)switch(p.queueType){case"dequeue":(w=u.find((function(e){return e._id===p.docId})))?p.doc=w:console.error("[realtime listener] internal non-fatal server error: unexpected limit dataType event where no doc is associated.");break;case"enqueue":throw T=new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_UNEXPECTED_FATAL_ERROR,errMsg:'HandleServerEvents: full doc is not provided with dataType="limit" and queueType="enqueue" (requestId '.concat(e.requestId,")")}),d.closeWithError(T),T}}switch(p.queueType){case"init":l?u.push(p.doc):(l=!0,u=[p.doc]);break;case"enqueue":u.push(p.doc);break;case"dequeue":A=u.findIndex((function(e){return e._id===p.docId})),A>-1?u.splice(A,1):console.error("[realtime listener] internal non-fatal server error: unexpected dequeue event where no doc is associated.");break;case"update":A=u.findIndex((function(e){return e._id===p.docId})),A>-1?u[A]=p.doc:console.error("[realtime listener] internal non-fatal server error: unexpected queueType update event where no doc is associated.")}return(n===h-1||a[n+1]&&a[n+1].id!==p.id)&&(R=S([],u,!0),C=a.slice(0,n+1).filter((function(e){return e.id===p.id})),d.sessionInfo.currentEventId=p.id,d.sessionInfo.currentDocs=u,N=new f({id:p.id,docChanges:C,docs:R,msgType:r}),d.listener.onChange(N)),[3,4];case 2:return console.warn("[realtime listener] event received is out of order, cur ".concat(d.sessionInfo.currentEventId," but got ").concat(p.id)),[4,d.rebuildWatch()];case 3:return b.sent(),[2,{value:void 0}];case 4:return[2]}}))},d=this,p=0,v=a.length,g.label=1;case 1:return p<v?[5,h(p,v)]:[3,4];case 2:if("object"==typeof(_=g.sent()))return[2,_.value];g.label=3;case 3:return p++,[3,1];case 4:return[2]}}))}))},e.prototype.postHandleServerEventsValidityCheck=function(e){this.sessionInfo?(this.sessionInfo.expectEventId&&this.sessionInfo.currentEventId>=this.sessionInfo.expectEventId&&this.clearWaitExpectedEvent(),this.sessionInfo.currentEventId<e.msgData.currEvent&&console.warn("[realtime listener] internal non-fatal error: client eventId does not match with server event id after server event handling")):console.error("[realtime listener] internal non-fatal error: sessionInfo lost after server event handling, this should never occur")},e.prototype.clearWaitExpectedEvent=function(){this.waitExpectedTimeoutId&&(clearTimeout(this.waitExpectedTimeoutId),this.waitExpectedTimeoutId=void 0)},e}();function A(e){var t={id:e.ID,dataType:e.DataType,queueType:e.QueueType,docId:e.DocID,doc:e.Doc&&"{}"!==e.Doc?JSON.parse(e.Doc):void 0};return"update"===e.DataType&&(e.UpdatedFields&&(t.updatedFields=JSON.parse(e.UpdatedFields)),(e.removedFields||e.RemovedFields)&&(t.removedFields=JSON.parse(e.removedFields))),t}var R,C={1e3:{code:1e3,name:"Normal Closure",description:"Normal closure; the connection successfully completed whatever purpose for which it was created."},1001:{code:1001,name:"Going Away",description:"The endpoint is going away, either because of a server failure or because the browser is navigating away from the page that opened the connection."},1002:{code:1002,name:"Protocol Error",description:"The endpoint is terminating the connection due to a protocol error."},1003:{code:1003,name:"Unsupported Data",description:"The connection is being terminated because the endpoint received data of a type it cannot accept (for example, a text-only endpoint received binary data)."},1005:{code:1005,name:"No Status Received",description:"Indicates that no status code was provided even though one was expected."},1006:{code:1006,name:"Abnormal Closure",description:"Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected."},1007:{code:1007,name:"Invalid frame payload data",description:"The endpoint is terminating the connection because a message was received that contained inconsistent data (e.g., non-UTF-8 data within a text message)."},1008:{code:1008,name:"Policy Violation",description:"The endpoint is terminating the connection because it received a message that violates its policy. This is a generic status code, used when codes 1003 and 1009 are not suitable."},1009:{code:1009,name:"Message too big",description:"The endpoint is terminating the connection because a data frame was received that is too large."},1010:{code:1010,name:"Missing Extension",description:"The client is terminating the connection because it expected the server to negotiate one or more extension, but the server didn't."},1011:{code:1011,name:"Internal Error",description:"The server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."},1012:{code:1012,name:"Service Restart",description:"The server is terminating the connection because it is restarting."},1013:{code:1013,name:"Try Again Later",description:"The server is terminating the connection due to a temporary condition, e.g. it is overloaded and is casting off some of its clients."},1014:{code:1014,name:"Bad Gateway",description:"The server was acting as a gateway or proxy and received an invalid response from the upstream server. This is similar to 502 HTTP Status Code."},1015:{code:1015,name:"TLS Handshake",description:"Indicates that the connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."},3e3:{code:3e3,name:"Reconnect WebSocket",description:"The client is terminating the connection because it wants to reconnect"},3001:{code:3001,name:"No Realtime Listeners",description:"The client is terminating the connection because no more realtime listeners exist"},3002:{code:3002,name:"Heartbeat Ping Error",description:"The client is terminating the connection due to its failure in sending heartbeat messages"},3003:{code:3003,name:"Heartbeat Pong Timeout Error",description:"The client is terminating the connection because no heartbeat response is received from the server"},3050:{code:3050,name:"Server Close",description:"The client is terminating the connection because no heartbeat response is received from the server"}};!function(e){e[e.NormalClosure=1e3]="NormalClosure",e[e.GoingAway=1001]="GoingAway",e[e.ProtocolError=1002]="ProtocolError",e[e.UnsupportedData=1003]="UnsupportedData",e[e.NoStatusReceived=1005]="NoStatusReceived",e[e.AbnormalClosure=1006]="AbnormalClosure",e[e.InvalidFramePayloadData=1007]="InvalidFramePayloadData",e[e.PolicyViolation=1008]="PolicyViolation",e[e.MessageTooBig=1009]="MessageTooBig",e[e.MissingExtension=1010]="MissingExtension",e[e.InternalError=1011]="InternalError",e[e.ServiceRestart=1012]="ServiceRestart",e[e.TryAgainLater=1013]="TryAgainLater",e[e.BadGateway=1014]="BadGateway",e[e.TLSHandshake=1015]="TLSHandshake",e[e.ReconnectWebSocket=3e3]="ReconnectWebSocket",e[e.NoRealtimeListeners=3001]="NoRealtimeListeners",e[e.HeartbeatPingError=3002]="HeartbeatPingError",e[e.HeartbeatPongTimeoutError=3003]="HeartbeatPongTimeoutError",e[e.NoAuthentication=3050]="NoAuthentication"}(R||(R={}));var N=function(e,t){var n=C[e],r=n?"".concat(n.name,", code ").concat(e,", reason ").concat(t||n.description):"code ".concat(e);return new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_CLOSED,errMsg:r})},D=null,L="web";function O(){return D}function W(){return L}function P(e){L=e}var M=function(){return M=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},M.apply(this,arguments)},j=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{c(r.next(e))}catch(e){i(e)}}function a(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((r=r.apply(e,t||[])).next())}))},x=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}},k=function(){function e(e){var t=this;this.virtualWSClient=new Set,this.queryIdClientMap=new Map,this.watchIdClientMap=new Map,this.pingFailed=0,this.pongMissed=0,this.logins=new Map,this.wsReadySubsribers=[],this.wsResponseWait=new Map,this.rttObserved=[],this.send=function(e){return j(t,void 0,void 0,(function(){var t=this;return x(this,(function(n){return[2,new Promise((function(n,r){j(t,void 0,void 0,(function(){var t,o,i,s,a,c,u,l,h=this;return x(this,(function(d){switch(d.label){case 0:o=!1,i=!1,s=function(e){o=!0,t&&clearTimeout(t),n(e)},a=function(e){i=!0,t&&clearTimeout(t),r(e)},e.timeout&&(t=setTimeout((function(){j(h,void 0,void 0,(function(){return x(this,(function(e){switch(e.label){case 0:return o&&i?[3,2]:[4,m(0)];case 1:e.sent(),o&&i||a(new g("wsclient.send timedout")),e.label=2;case 2:return[2]}}))}))}),e.timeout)),d.label=1;case 1:return d.trys.push([1,8,,9]),void 0===this.wsInitPromise&&null===this.wsInitPromise?[3,3]:[4,this.wsInitPromise];case 2:d.sent(),d.label=3;case 3:if(!this.ws)return a(new Error("invalid state: ws connection not exists, can not send message")),[2];if(1!==this.ws.readyState)return a(new Error("ws readyState invalid: ".concat(this.ws.readyState,", can not send message"))),[2];e.waitResponse&&(c={resolve:s,reject:a,skipOnMessage:e.skipOnMessage},this.wsResponseWait.set(e.msg.requestId,c)),d.label=4;case 4:return d.trys.push([4,6,,7]),[4,this.ws.send(JSON.stringify(e.msg))];case 5:return d.sent(),e.waitResponse||s(void 0),[3,7];case 6:return(u=d.sent())&&(a(u),e.waitResponse&&this.wsResponseWait.delete(e.msg.requestId)),[3,7];case 7:return[3,9];case 8:return l=d.sent(),a(l),[3,9];case 9:return[2]}}))}))}))]}))}))},this.closeAllClients=function(e){t.virtualWSClient.forEach((function(t){t.closeWithError(e)}))},this.pauseClients=function(e){(e||t.virtualWSClient).forEach((function(e){e.pause()}))},this.resumeClients=function(e){(e||t.virtualWSClient).forEach((function(e){e.resume()}))},this.initWebSocketConnection=function(e,n){return void 0===n&&(n=t.maxReconnect),j(t,void 0,void 0,(function(){var t=this;return x(this,(function(r){switch(r.label){case 0:if(e&&this.reconnectState)return[2];if(e&&(this.reconnectState=!0),void 0!==this.wsInitPromise&&null!==this.wsInitPromise)return[2,this.wsInitPromise];e&&this.pauseClients(),this.close(R.ReconnectWebSocket),this.wsInitPromise=new Promise((function(r,o){j(t,void 0,void 0,(function(){var t,i,s=this;return x(this,(function(a){switch(a.label){case 0:return a.trys.push([0,6,,11]),[4,this.getWsSign()];case 1:return t=a.sent(),[4,new Promise((function(e){var n=t.wsUrl||"wss://tcb-ws.tencentcloudapi.com",r=O();s.ws=r?new r(n):new WebSocket(n),e(void 0)}))];case 2:return a.sent(),this.ws.connect?[4,this.ws.connect()]:[3,4];case 3:a.sent(),a.label=4;case 4:return[4,this.initWebSocketEvent()];case 5:return a.sent(),r(),e&&(this.resumeClients(),this.reconnectState=!1),[3,11];case 6:return i=a.sent(),console.error("[realtime] initWebSocketConnection connect fail",i),n>0?(this.wsInitPromise=void 0,[4,m(this.reconnectInterval)]):[3,9];case 7:a.sent(),e&&(this.reconnectState=!1),a.label=8;case 8:return r(this.initWebSocketConnection(e,n-1)),[3,10];case 9:o(i),e&&this.closeAllClients(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_RECONNECT_WATCH_FAIL,errMsg:i})),a.label=10;case 10:return[3,11];case 11:return[2]}}))}))})),r.label=1;case 1:return r.trys.push([1,3,4,5]),[4,this.wsInitPromise];case 2:return r.sent(),this.wsReadySubsribers.forEach((function(e){return(0,e.resolve)()})),[3,5];case 3:return r.sent(),this.wsReadySubsribers.forEach((function(e){return(0,e.reject)()})),[3,5];case 4:return this.wsInitPromise=void 0,this.wsReadySubsribers=[],[7];case 5:return[2]}}))}))},this.initWebSocketEvent=function(){return new Promise((function(e,n){if(!t.ws)throw new Error("can not initWebSocketEvent, ws not exists");var r=!1;t.ws.onopen=function(t){console.warn("[realtime] ws event: open",t),r=!0,e()},t.ws.onerror=function(e){t.logins=new Map,r?(console.error("[realtime] ws event: error",e),t.clearHeartbeat(),t.virtualWSClient.forEach((function(t){return t.closeWithError(new y({errCode:I.SDK_DATABASE_REALTIME_LISTENER_WEBSOCKET_CONNECTION_ERROR,errMsg:e}))}))):(console.error("[realtime] ws open failed with ws event: error",e),n(e))},t.ws.onclose=function(e){switch(console.warn("[realtime] ws event: close",e),t.logins=new Map,t.clearHeartbeat(),e.code){case R.ReconnectWebSocket:case R.NoRealtimeListeners:break;case R.HeartbeatPingError:case R.HeartbeatPongTimeoutError:case R.NormalClosure:case R.AbnormalClosure:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(N(e.code));break;case R.NoAuthentication:t.closeAllClients(N(e.code,e.reason));break;default:t.maxReconnect>0?t.initWebSocketConnection(!0,t.maxReconnect):t.closeAllClients(N(e.code))}},t.ws.onmessage=function(e){var n,r=e.data;t.heartbeat();try{n=JSON.parse(r)}catch(e){throw new Error("[realtime] onMessage parse res.data error: ".concat(e))}if("ERROR"===n.msgType){var o=null;t.virtualWSClient.forEach((function(e){e.watchId===n.watchId&&(o=e)})),o&&o.listener.onError(n)}var i=t.wsResponseWait.get(n.requestId);if(i){try{"ERROR"===n.msgType?i.reject(new v(n)):i.resolve(n)}catch(e){console.error("ws onMessage responseWaitSpec.resolve(msg) errored:",e)}finally{t.wsResponseWait.delete(n.requestId)}if(i.skipOnMessage)return}if("PONG"!==n.msgType){var s=n.watchId&&t.watchIdClientMap.get(n.watchId);if(s)s.onMessage(n);else switch(console.error("[realtime] no realtime listener found responsible for watchId ".concat(n.watchId,": "),n),n.msgType){case"INIT_EVENT":case"NEXT_EVENT":case"CHECK_EVENT":(s=t.queryIdClientMap.get(n.msgData.queryID))&&s.onMessage(n);break;default:for(var a=0,c=Array.from(t.watchIdClientMap.entries());a<c.length;a++){c[a][1].onMessage(n);break}}}else if(t.lastPingSendTS){var u=Date.now()-t.lastPingSendTS;if(u>1e4)return void console.warn("[realtime] untrusted rtt observed: ".concat(u));t.rttObserved.length>=3&&t.rttObserved.splice(0,t.rttObserved.length-3+1),t.rttObserved.push(u)}},t.heartbeat()}))},this.isWSConnected=function(){return Boolean(t.ws&&1===t.ws.readyState)},this.onceWSConnected=function(){return j(t,void 0,void 0,(function(){var e=this;return x(this,(function(t){return this.isWSConnected()?[2]:null!==this.wsInitPromise&&void 0!==this.wsInitPromise?[2,this.wsInitPromise]:[2,new Promise((function(t,n){e.wsReadySubsribers.push({resolve:t,reject:n})}))]}))}))},this.webLogin=function(e,n){return j(t,void 0,void 0,(function(){var t,r,o,i,s,a,c,l,h=this;return x(this,(function(d){switch(d.label){case 0:if(!n)if(e){if(t=this.logins.get(e)){if(t.loggedIn&&t.loginResult)return[2,t.loginResult];if(null!==t.loggingInPromise&&void 0!==t.loggingInPromise)return[2,t.loggingInPromise]}}else if(null!==(null==(r=this.logins.get(""))?void 0:r.loggingInPromise)&&void 0!==(null==r?void 0:r.loggingInPromise))return[2,r.loggingInPromise];o=new Promise((function(e,t){j(h,void 0,void 0,(function(){var n,r,o,i,s;return x(this,(function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.getWsSign()];case 1:return n=a.sent(),r={envId:n.envId||"",accessToken:"",referrer:"web",sdkVersion:"",dataVersion:""},o={watchId:void 0,requestId:u(),msgType:"LOGIN",msgData:r,exMsgData:{runtime:W(),signStr:n.signStr,secretVersion:n.secretVersion}},[4,this.send({msg:o,waitResponse:!0,skipOnMessage:!0,timeout:5e3})];case 2:return(i=a.sent()).msgData.code?t(new Error("".concat(i.msgData.code," ").concat(i.msgData.message))):e({envId:n.envId}),[3,4];case 3:return s=a.sent(),t(s),[3,4];case 4:return[2]}}))}))})),i=e&&this.logins.get(e),s=Date.now(),i?(i.loggedIn=!1,i.loggingInPromise=o,i.loginStartTS=s):(i={loggedIn:!1,loggingInPromise:o,loginStartTS:s},this.logins.set(e||"",i)),d.label=1;case 1:return d.trys.push([1,3,,4]),[4,o];case 2:if(a=d.sent(),(c=e&&this.logins.get(e))&&c===i&&c.loginStartTS===s)return i.loggedIn=!0,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=a,[2,a];if(c){if(c.loggedIn&&c.loginResult)return[2,c.loginResult];if(null!==c.loggingInPromise&&void 0!==c.loggingInPromise)return[2,c.loggingInPromise];throw new Error("ws unexpected login info")}throw new Error("ws login info reset");case 3:throw l=d.sent(),i.loggedIn=!1,i.loggingInPromise=void 0,i.loginStartTS=void 0,i.loginResult=void 0,l;case 4:return[2]}}))}))},this.getWsSign=function(){return j(t,void 0,void 0,(function(){var e,t,n,r,o,i,s;return x(this,(function(a){switch(a.label){case 0:return this.wsSign&&this.wsSign.expiredTs>Date.now()?[2,this.wsSign]:(e=Date.now()+6e4,[4,this.context.appConfig.request.send("auth.wsWebSign",{runtime:W()})]);case 1:if((t=a.sent()).code)throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败: ".concat(t.code));if(t.data)return n=t.data,r=n.signStr,o=n.wsUrl,i=n.secretVersion,s=n.envId,[2,{signStr:r,wsUrl:o,secretVersion:i,envId:s,expiredTs:e}];throw new Error("[tcb-js-sdk] 获取实时数据推送登录票据失败")}}))}))},this.getWaitExpectedTimeoutLength=function(){return t.rttObserved.length?t.rttObserved.reduce((function(e,t){return e+t}))/t.rttObserved.length*1.5:5e3},this.ping=function(){return j(t,void 0,void 0,(function(){var e;return x(this,(function(t){switch(t.label){case 0:return e={watchId:void 0,requestId:u(),msgType:"PING",msgData:null},[4,this.send({msg:e})];case 1:return t.sent(),[2]}}))}))},this.onWatchStart=function(e,n){t.queryIdClientMap.set(n,e)},this.onWatchClose=function(e,n){n&&t.queryIdClientMap.delete(n),t.watchIdClientMap.delete(e.watchId),t.virtualWSClient.delete(e),t.virtualWSClient.size||t.close(R.NoRealtimeListeners)},this.maxReconnect=e.maxReconnect||5,this.reconnectInterval=e.reconnectInterval||1e4,this.context=e.context}return e.prototype.clearHeartbeat=function(){this.pingTimeoutId&&clearTimeout(this.pingTimeoutId),this.pongTimeoutId&&clearTimeout(this.pongTimeoutId)},e.prototype.close=function(e){this.clearHeartbeat(),this.ws&&(this.ws.close(e,C[e].name),this.ws=void 0)},e.prototype.watch=function(e){this.ws||void 0!==this.wsInitPromise&&null!==this.wsInitPromise||this.initWebSocketConnection(!1);var t=new T(M(M({},e),{send:this.send,login:this.webLogin,isWSConnected:this.isWSConnected,onceWSConnected:this.onceWSConnected,getWaitExpectedTimeoutLength:this.getWaitExpectedTimeoutLength,onWatchStart:this.onWatchStart,onWatchClose:this.onWatchClose,debug:!0}));return this.virtualWSClient.add(t),this.watchIdClientMap.set(t.watchId,t),t.listener},e.prototype.heartbeat=function(e){var t=this;this.clearHeartbeat(),this.pingTimeoutId=setTimeout((function(){j(t,void 0,void 0,(function(){var e=this;return x(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),this.ws&&1===this.ws.readyState?(this.lastPingSendTS=Date.now(),[4,this.ping()]):[2];case 1:return t.sent(),this.pingFailed=0,this.pongTimeoutId=setTimeout((function(){console.error("pong timed out"),e.pongMissed<2?(e.pongMissed+=1,e.heartbeat(!0)):e.initWebSocketConnection(!0)}),this.context.appConfig.realtimePongWaitTimeout),[3,3];case 2:return t.sent(),this.pingFailed<2?(this.pingFailed+=1,this.heartbeat()):this.close(R.HeartbeatPingError),[3,3];case 3:return[2]}}))}))}),e?0:this.context.appConfig.realtimePingInterval)},e}(),K={target:"database",entity:function(){var e,t=this.platform,n=t.adapter,r=t.runtime;e=n.wsClass,D=e,P(r)}},B={name:"realtime",IIFE:!0,entity:function(){this.prototype.wsClientClass=k}};try{cloudbase.registerComponent(B),cloudbase.registerHook(K)}catch(e){}function H(e){try{e.registerComponent(B),e.registerHook(K)}catch(e){console.warn(e)}}}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={id:r,loaded:!1,exports:{}};return e[r](i,i.exports,n),i.loaded=!0,i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nmd=e=>(e.paths=[],e.children||(e.children=[]),e);var r={};return(()=>{"use strict";var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.registerRealtime=void 0;var t=n(337);e.registerRealtime=t.registerRealtime})(),r})()));