UNPKG

@cloudbase/js-sdk

Version:
2 lines 275 kB
/*! For license information please see index.js.LICENSE.txt */ !function(){"use strict";var t,e,r={548:function(t,e,r){var n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)},i=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())})},o=this&&this.__generator||function(t,e){var r,n,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(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=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++,n=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],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};Object.defineProperty(e,"__esModule",{value:!0}),e.useAuthAdapter=void 0;var s=r(19),a=function(){function t(t){var e,r;try{this.localStorage=(null==t?void 0:t.localStorage)||((null===(r=null===(e=null==t?void 0:t.adapter)||void 0===e?void 0:e.root)||void 0===r?void 0:r.globalThis)||globalThis).localStorage}catch(e){this.localStorage=(null==t?void 0:t.localStorage)||{}}}return t.prototype.getItem=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.localStorage.getItem(t)]})})},t.prototype.removeItem=function(t){return i(this,void 0,void 0,function(){return o(this,function(e){return this.localStorage.removeItem(t),[2]})})},t.prototype.setItem=function(t,e){return i(this,void 0,Promise,function(){return o(this,function(r){return this.localStorage.setItem(t,e),[2]})})},t.prototype.getItemSync=function(t){return this.localStorage.getItem(t)},t.prototype.setItemSync=function(t,e){this.localStorage.setItem(t,e)},t.prototype.removeItemSync=function(t){this.localStorage.removeItem(t)},t}(),u=/^[^:]+:\/\/[^/]+(\/[^?#]+)/,c=function(t,e){var r,n,i,o,s=null===(r=null==e?void 0:e.headers)||void 0===r?void 0:r["x-request-id"];return t||(t={}),((null==t?void 0:t.code)||(null===(n=null==t?void 0:t.data)||void 0===n?void 0:n.error_code))&&(t={error:t.code||t.data.error,error_description:t.data.error_description||t.message||t.code||t.data.error_code,request_id:t.requestId,error_code:null===(i=t.data)||void 0===i?void 0:i.error_code}),(null==t?void 0:t.request_id)||(t.request_id=t.request_id||s),(null==t?void 0:t.error)?(t.error_uri=(o=null==e?void 0:e.url,u.test(o)?RegExp.$1:o),t):(null==t?void 0:t.data)||{}};e.useAuthAdapter=function(t){return t.adapter&&"default"!==t.adapter.type?function(t,e){var r=n({},t);try{if(!(null==t?void 0:t.storage)&&(null==e?void 0:e.localStorage)&&(r.storage=new a({localStorage:e.localStorage,adapter:e})),!t.captchaOptions&&(null==e?void 0:e.captchaOptions)&&(r.captchaOptions=e.captchaOptions),!t.baseRequest&&!t.request&&(null==e?void 0:e.reqClass)){var s={timeout:1e4,restrictedMethods:["get","post","upload","download","request"],auth:t.auth},u=new e.reqClass(s);r.baseRequest=function(t,e){var r,s,a,h,l;return i(this,void 0,void 0,function(){var i,d,p,f;return o(this,function(o){switch(o.label){case 0:if(i={},d=(null===(r=e.method)||void 0===r?void 0:r.toLocaleLowerCase())||"post","function"!=typeof(p=null===(a=null===(s=null==u?void 0:u[d])||void 0===s?void 0:s.bind)||void 0===a?void 0:a.call(s,u)))throw new Error("invalid 【".concat(d,"】 request method"));o.label=1;case 1:return o.trys.push([1,3,,4]),(null===(h=e.headers)||void 0===h?void 0:h["content-type"])&&!(null===(l=e.headers)||void 0===l?void 0:l["content-type"].includes("application/json"))||["string","undefined"].includes(typeof e.body)||(e.data=e.data||e.body,e.body=JSON.stringify(e.body)),[4,p(n({url:t},e))];case 2:return i=o.sent(),i=c(i,n(n({},e),{url:t})),[3,4];case 3:throw f=o.sent(),i=n(n({},null==f?void 0:f.data),f);case 4:if(null==i?void 0:i.error)throw i;return[2,i]}})})}}}catch(t){console.error("user adapter generate fail:",t)}return r}(t,t.adapter):function(t,e){var r=n({},t),u={};if((null==e?void 0:e.captchaOptions)&&(r.captchaOptions=e.captchaOptions),!s.adapterForWxMp.isMatch()||t.storage&&t.baseRequest)return r;try{var h=s.adapterForWxMp.genAdapter({}),l=h.localStorage,d=h.reqClass;if(l&&(u.storage=new a({localStorage:l,adapter:e})),d){var p=new d({timeout:1e4,restrictedMethods:["get","post","upload","download","request"]});u.request=function(t){return function(e,r){return i(this,void 0,void 0,function(){return o(this,function(i){return[2,new Promise(function(i,o){var s=Object.assign({},r);s.body&&"string"!=typeof s.body&&(s.body=JSON.stringify(s.body));var a=wx.request({url:e,data:s.body,timeout:t._timeout,method:s.method||"GET",header:s.headers,success:function(t){(t=c(t,n(n({},r),{url:e}))).error&&o(t),i(t)},fail:function(t){o({error:"unreachable",error_description:t.message})},complete:function(e){if(e&&e.errMsg&&t._timeout&&-1!==t._restrictedMethods.indexOf("request")&&"request:fail timeout"===e.errMsg){console.warn(t._timeoutMsg);try{a.abort()}catch(t){}}}})})]})})}}(p)}return r.captchaOptions&&(u.baseRequest=u.request,u.request=void 0),n(n({},r),u)}catch(t){console.error("adapter generate fail:",t)}return r}(t,t.adapter)}},895:function(t,e,r){var n,i=this&&this.__extends||(n=function(t,e){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},n(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),o=this&&this.__assign||function(){return o=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},o.apply(this,arguments)},s=this&&this.__decorate||function(t,e,r,n){var i,o=arguments.length,s=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(o<3?i(s):o>3?i(e,r,s):i(e,r))||s);return o>3&&s&&Object.defineProperty(e,r,s),s},a=this&&this.__metadata||function(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)},u=this&&this.__awaiter||function(t,e,r,n){return new(r||(r=Promise))(function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r(function(t){t(e)})).then(s,a)}u((n=n.apply(t,e||[])).next())})},c=this&&this.__generator||function(t,e){var r,n,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(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=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++,n=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],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},h=this&&this.__rest||function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]])}return r};Object.defineProperty(e,"__esModule",{value:!0}),e.registerAuth=e.AuthError=e.AuthErrorCode=e.AuthErrorCategory=e.AnonymousAuthProvider=e.CustomAuthProvider=e.WeixinAuthProvider=e.Auth=e.generateAuthInstance=e.LoginState=e.User=void 0;var l=r(722),d=r(548),p=r(19),f=r(266),v=r(916);Object.defineProperty(e,"WeixinAuthProvider",{enumerable:!0,get:function(){return v.WeixinAuthProvider}}),Object.defineProperty(e,"CustomAuthProvider",{enumerable:!0,get:function(){return v.CustomAuthProvider}}),Object.defineProperty(e,"AnonymousAuthProvider",{enumerable:!0,get:function(){return v.AnonymousAuthProvider}});var g=r(683),y=function(){return"undefined"!=typeof window&&"undefined"!=typeof document},m=e.User=function(){function t(t){var e=t.cache,r=t.oauthInstance;this.cache=e,this.oauthInstance=r,this.setUserInfo()}var e,r,n;return t.prototype.checkLocalInfo=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return this.uid=this.getLocalUserInfo("uid"),this.gender=this.getLocalUserInfo("gender"),this.picture=this.getLocalUserInfo("picture"),this.email=this.getLocalUserInfo("email"),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),this.username=this.getLocalUserInfo("username"),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]})})},t.prototype.checkLocalInfoAsync=function(){return u(this,void 0,void 0,function(){var t,e,r,n;return c(this,function(i){switch(i.label){case 0:return t=this,[4,this.getLocalUserInfoAsync("uid")];case 1:return t.uid=i.sent(),e=this,[4,this.getLocalUserInfoAsync("gender")];case 2:return e.gender=i.sent(),this.picture=this.getLocalUserInfo("picture"),r=this,[4,this.getLocalUserInfoAsync("email")];case 3:return r.email=i.sent(),this.emailVerified=this.getLocalUserInfo("email_verified"),this.phoneNumber=this.getLocalUserInfo("phone_number"),n=this,[4,this.getLocalUserInfoAsync("username")];case 4:return n.username=i.sent(),this.name=this.getLocalUserInfo("name"),this.birthdate=this.getLocalUserInfo("birthdate"),this.zoneinfo=this.getLocalUserInfo("zoneinfo"),this.locale=this.getLocalUserInfo("locale"),this.sub=this.getLocalUserInfo("sub"),this.createdFrom=this.getLocalUserInfo("created_from"),this.providers=this.getLocalUserInfo("providers"),[2]}})})},t.prototype.update=function(t){return u(this,void 0,Promise,function(){var e;return c(this,function(r){switch(r.label){case 0:return[4,this.oauthInstance.authApi.setUserProfile(o({},t))];case 1:return e=r.sent(),this.setLocalUserInfo(e),[2]}})})},t.prototype.updateUserBasicInfo=function(t){return u(this,void 0,Promise,function(){return c(this,function(e){switch(e.label){case 0:return[4,this.oauthInstance.authApi.updateUserBasicInfo(o({},t))];case 1:return e.sent(),[4,this.refresh()];case 2:return e.sent(),[2]}})})},t.prototype.updatePassword=function(t,e){return this.oauthInstance.authApi.updatePasswordByOld({old_password:e,new_password:t})},t.prototype.updateUsername=function(t){return"string"!=typeof t&&(0,p.throwError)(p.ERRORS.INVALID_PARAMS,"username must be a string"),this.update({username:t})},t.prototype.refresh=function(t){return u(this,void 0,Promise,function(){var e;return c(this,function(r){switch(r.label){case 0:return[4,this.oauthInstance.authApi.getUserInfo(t)];case 1:if("INVALID_ACCESS_TOKEN"===(e=r.sent()).code)throw this.setLocalUserInfo({}),e;return this.setLocalUserInfo(e),[2,e]}})})},t.prototype.getLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey,r=this.cache.getStore(e);return t?r[t]:r||{}},t.prototype.setLocalUserInfo=function(t){var e=this.cache.keys.userInfoKey;this.cache.setStore(e,t),this.setUserInfo()},t.prototype.getLocalUserInfoAsync=function(t){return u(this,void 0,Promise,function(){var e;return c(this,function(r){switch(r.label){case 0:return e=this.cache.keys.userInfoKey,[4,this.cache.getStoreAsync(e)];case 1:return[2,r.sent()[t]]}})})},t.prototype.setUserInfo=function(){var t=this,e=this.cache.keys.userInfoKey,r=this.cache.getStore(e);["uid","email","name","gender","picture","email_verified","phone_number","birthdate","zoneinfo","locale","sub","created_from","providers","username","created_at","open_id"].forEach(function(e){t[e]=r[e]})},s([(0,p.catchErrorsDecorator)({title:"更新用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.update() 的语法或参数是否正确"," 2 - 用户信息中是否包含非法值","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(p.COMMUNITY_SITE_URL)]}),a("design:type",Function),a("design:paramtypes",["function"==typeof(e=void 0!==l.authModels&&l.authModels.UserProfile)?e:Object]),a("design:returntype","function"==typeof(r="undefined"!=typeof Promise&&Promise)?r:Object)],t.prototype,"update",null),s([(0,p.catchErrorsDecorator)({title:"更新密码失败",messages:["请确认以下各项:"," 1 - 调用 User.updatePassword() 的语法或参数是否正确"," 3 - 新密码中是否包含非法字符","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(p.COMMUNITY_SITE_URL)]}),a("design:type",Function),a("design:paramtypes",[String,String]),a("design:returntype",void 0)],t.prototype,"updatePassword",null),s([(0,p.catchErrorsDecorator)({title:"更新用户名失败",messages:["请确认以下各项:"," 1 - 调用 User.updateUsername() 的语法或参数是否正确"," 2 - 当前环境是否开通了用户名密码登录","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(p.COMMUNITY_SITE_URL)]}),a("design:type",Function),a("design:paramtypes",[String]),a("design:returntype",void 0)],t.prototype,"updateUsername",null),s([(0,p.catchErrorsDecorator)({title:"刷新本地用户信息失败",messages:["请确认以下各项:"," 1 - 调用 User.refresh() 的语法或参数是否正确","如果问题依然存在,建议到官方问答社区提问或寻找帮助:".concat(p.COMMUNITY_SITE_URL)]}),a("design:type",Function),a("design:paramtypes",[Object]),a("design:returntype","function"==typeof(n="undefined"!=typeof Promise&&Promise)?n:Object)],t.prototype,"refresh",null),t}();(0,v.applyUserV1Compat)(m);var _=function(){function t(t){var e=t.envId,r=t.cache,n=t.oauthInstance;e||(0,p.throwError)(p.ERRORS.INVALID_PARAMS,"envId is not defined"),this.cache=r,this.oauthInstance=n,this.user=new m({cache:this.cache,oauthInstance:n})}return t.prototype.checkLocalState=function(){var t;this.oauthLoginState=null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.hasLoginStateSync(),this.user.checkLocalInfo()},t.prototype.checkLocalStateAsync=function(){var t;return u(this,void 0,void 0,function(){return c(this,function(e){switch(e.label){case 0:return[4,null===(t=this.oauthInstance)||void 0===t?void 0:t.authApi.getLoginState()];case 1:return e.sent(),[4,this.user.checkLocalInfoAsync()];case 2:return e.sent(),[2]}})})},t}();e.LoginState=_;var E=function(t){function e(e){var r=t.call(this)||this;return r.listeners=new Map,r.hasListenerSetUp=!1,r.config=e,r.oauthInstance=e.oauthInstance,r.cache=e.cache,r.init(),r.setAccessKey(),r}var r,n,d,v,m,E,b,I,A,w,T,S,O,P,R,C,N,U,D,L,k;return i(e,t),e.prototype.signInAnonymously=function(t){return u(this,void 0,Promise,function(){var e,r,n,i,s;return c(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),[4,this.oauthInstance.authApi.signInAnonymously(t)];case 1:return a.sent(),[4,this.createLoginState()];case 2:return e=a.sent(),[4,this.getSession()];case 3:return r=a.sent().data,n=(void 0===r?{}:r).session,[2,o(o({},e),{data:{user:n.user,session:n},error:null})];case 4:return i=a.sent(),(s=new l.AuthError(i,{method:"signInAnonymously"})).category===l.AuthErrorCategory.PROVIDER_NOT_ENABLED?(console.error(s.helpMessage),console.error("[CloudBase Auth] 提示:匿名登录需要在控制台开启「匿名登录」。\n 如果您需要使用用户名密码登录,请改用 auth.signInWithPassword({ username, password })。\n 不要在匿名登录失败后自动回退到密码登录,这两种方式的使用场景不同。")):(console.warn("[CloudBase Auth] signInAnonymously 失败 [".concat(s.category,"]: ").concat(s.message)),s.loginMethodHint&&console.warn(s.loginMethodHint)),[2,{data:{user:null,session:null},error:s}];case 5:return[2]}})})},e.prototype.signUp=function(t){return u(this,void 0,Promise,function(){var e,r,n=this;return c(this,function(i){switch(i.label){case 0:return t.phone_number||t.verification_code||t.verification_token||t.provider_token?(t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[4,this.oauthInstance.authApi.signUp(t)]):[3,2];case 1:return i.sent(),[2,this.createLoginState()];case 2:return i.trys.push([2,4,,5]),this.validateAtLeastOne(t,[["email"],["phone"]],"You must provide either an email or phone number"),[4,this.getVerification(t.email?{email:t.email}:{phone_number:this.formatPhone(t.phone)})];case 3:return e=i.sent(),[2,{data:{verifyOtp:function(r){var i=r.token,s=r.messageId,a=void 0===s?e.verification_id:s;return u(n,void 0,Promise,function(){var r,n,s,u,h;return c(this,function(c){switch(c.label){case 0:return c.trys.push([0,8,,9]),[4,this.verify({verification_id:a||e.verification_id,verification_code:String(i)})];case 1:return r=c.sent(),e.is_user?[4,this.signIn({username:t.email||this.formatPhone(t.phone),verification_token:r.verification_token})]:[3,3];case 2:return c.sent(),[3,6];case 3:return delete(n=JSON.parse(JSON.stringify(t))).email,delete n.phone,[4,this.oauthInstance.authApi.signUp(o(o(o({},n),t.email?{email:t.email}:{phone_number:this.formatPhone(t.phone)}),{verification_token:r.verification_token,verification_code:i}))];case 4:return c.sent(),[4,this.createLoginState()];case 5:c.sent(),c.label=6;case 6:return[4,this.getSession()];case 7:return s=c.sent().data,[2,{data:{user:(u=(void 0===s?{}:s).session).user,session:u},error:null}];case 8:return h=c.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(h,{method:"signUp"})}];case 9:return[2]}})})}},error:null}];case 4:return r=i.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(r,{method:"signUp"})}];case 5:return[2]}})})},e.prototype.signOut=function(t){var e,r;return u(this,void 0,Promise,function(){var n,i,s;return c(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),n=this.cache.keys.userInfoKey,[4,this.oauthInstance.authApi.signOut(t)];case 1:return i=a.sent(),[4,this.cache.removeStoreAsync(n)];case 2:return a.sent(),this.setAccessKey(),null===(e=this.config.eventBus)||void 0===e||e.fire(l.EVENTS.LOGIN_STATE_CHANGED,{eventType:l.LOGIN_STATE_CHANGED_TYPE.SIGN_OUT}),null===(r=this.config.eventBus)||void 0===r||r.fire(l.EVENTS.AUTH_STATE_CHANGED,{event:l.AUTH_STATE_CHANGED_TYPE.SIGNED_OUT}),[2,o(o({},i),{data:{},error:null})];case 3:return s=a.sent(),[2,{data:{},error:new l.AuthError(s,{method:"signOut"})}];case 4:return[2]}})})},e.prototype.onAuthStateChange=function(t){var e=this;this.hasListenerSetUp||(this.setupListeners(),this.hasListenerSetUp=!0);var r=Math.random().toString(36);return this.listeners.has(r)||this.listeners.set(r,new Set),this.listeners.get(r).add(t),{data:{subscription:{id:r,callback:t,unsubscribe:function(){var n=e.listeners.get(r);n&&(n.delete(t),0===n.size&&e.listeners.delete(r))}}}}},e.prototype.signInWithPassword=function(t){var e,r;return u(this,void 0,Promise,function(){var n,i,s,a,u,h,d,p;return c(this,function(c){switch(c.label){case 0:return c.trys.push([0,3,,4]),this.validateAtLeastOne(t,[["username"],["email"],["phone"]],"You must provide either username, email, or phone"),this.validateParams(t,{password:{required:!0,message:"Password is required"}}),n="username"in t?t.username:void 0,i="email"in t?t.email:void 0,s="phone"in t?t.phone:void 0,a=null!==(r=null===(e=t.options)||void 0===e?void 0:e.is_encrypt)&&void 0!==r?r:t.is_encrypt,[4,this.signIn(o({username:n||i||this.formatPhone(s),password:t.password},a?{isEncrypt:!0,version:"v2"}:{}))];case 1:return c.sent(),[4,this.getSession()];case 2:return u=c.sent().data,[2,{data:{user:(h=(void 0===u?{}:u).session).user,session:h},error:null}];case 3:return d=c.sent(),(p=new l.AuthError(d,{method:"signInWithPassword"})).category===l.AuthErrorCategory.PROVIDER_NOT_ENABLED?console.error(p.helpMessage):p.category===l.AuthErrorCategory.INVALID_CREDENTIALS||p.category===l.AuthErrorCategory.USER_NOT_FOUND?console.warn(p.helpMessage):console.warn("[CloudBase Auth] signInWithPassword 失败 [".concat(p.category,"]: ").concat(p.message)),p.loginMethodHint&&console.info(p.loginMethodHint),[2,{data:{user:null,session:null},error:p}];case 4:return[2]}})})},e.prototype.signInWithIdToken=function(t){return u(this,void 0,Promise,function(){var e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),this.validateParams(t,{token:{required:!0,message:"Token is required"}}),[4,this.signInWithProvider({provider_token:t.token})];case 1:return i.sent(),[4,this.getSession()];case 2:return e=i.sent().data,[2,{data:{user:(r=(void 0===e?{}:e).session).user,session:r},error:null}];case 3:return n=i.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(n,{method:"signInWithIdToken"})}];case 4:return[2]}})})},e.prototype.signInWithOtp=function(t){return u(this,void 0,Promise,function(){var e,r,n,i,s,a=this;return c(this,function(h){switch(h.label){case 0:if(e=t.options,r="email"in t?t.email:void 0,n="phone"in t?t.phone:void 0,!(null==e?void 0:e.emailRedirectTo)&&(void 0===(null==e?void 0:e.shouldCreateUser)||(null==e?void 0:e.shouldCreateUser)))return[2,this.signUp(r?{email:r}:{phone:n})];h.label=1;case 1:return h.trys.push([1,3,,4]),this.validateAtLeastOne(t,[["email"],["phone"]],"You must provide either an email or phone number"),[4,this.getVerification(o(o({email_redirect_to:null==e?void 0:e.emailRedirectTo},r?{email:r}:{phone_number:this.formatPhone(n)}),{target:"USER"}))];case 2:return i=h.sent(),[2,{data:{user:null,session:null,verifyOtp:function(t){var e=t.token,o=t.messageId,s=void 0===o?i.verification_id:o;return u(a,void 0,Promise,function(){return c(this,function(t){return[2,this.verifyOtp(r?{email:r,token:String(e),messageId:s}:{phone:n,token:String(e),messageId:s})]})})}},error:null}];case 3:return s=h.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(s,{method:"signInWithOtp"})}];case 4:return[2]}})})},e.prototype.verifyOAuth=function(t){return u(this,void 0,Promise,function(){var e,r,n,i,s,a,u,h,d;return c(this,function(c){switch(c.label){case 0:e={},c.label=1;case 1:return c.trys.push([1,7,,8]),r=(null==t?void 0:t.code)||g.utils.getQuery("code"),n=(null==t?void 0:t.state)||g.utils.getQuery("state"),r?n?(i=(0,f.getBrowserSession)(n),e.type=null==i?void 0:i.type,(s=(null==t?void 0:t.provider)||(null==i?void 0:i.provider)||g.utils.getQuery("provider"))?[4,this.grantProviderToken({provider_id:s,provider_redirect_uri:location.origin+location.pathname,provider_code:r})]:[2,{data:o(o({},e),{user:null,session:null,redirectUrl:null}),error:new l.AuthError({message:"Provider is required"})}]):[2,{data:{user:null,session:null,redirectUrl:null},error:new l.AuthError({message:"State is required"})}]:[2,{data:{user:null,session:null,redirectUrl:null},error:new l.AuthError({message:"Code is required"})}];case 2:return a=c.sent().provider_token,u=void 0,i.type!==l.OAUTH_TYPE.BIND_IDENTITY?[3,4]:[4,this.oauthInstance.authApi.toBindIdentity({provider_token:a,provider:s,fireEvent:!0})];case 3:return u=c.sent(),[3,6];case 4:return[4,this.signInWithIdToken({token:a})];case 5:(u=c.sent()).data=o(o({},e),u.data),c.label=6;case 6:return(h=new URLSearchParams(null===location||void 0===location?void 0:location.search)).delete("code"),h.delete("state"),u.data.redirectUrl=(0,f.addUrlSearch)(void 0===(null==i?void 0:i.search)?"?".concat(h.toString()):null==i?void 0:i.search,(null==i?void 0:i.hash)||location.hash),(0,f.removeBrowserSession)(n),[2,u];case 7:return d=c.sent(),[2,{data:o(o({},e),{user:null,session:null,redirectUrl:null}),error:new l.AuthError(d,{method:"verifyOAuth"})}];case 8:return[2]}})})},e.prototype.signInWithOAuth=function(t){var e,r,n,i,o;return u(this,void 0,Promise,function(){var s,a,u,h,d,p,v,g,m;return c(this,function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}}),s=(null===(e=t.options)||void 0===e?void 0:e.redirectTo)||location.href,a=new URL(s),u=a.origin+a.pathname,h=(null===(r=t.options)||void 0===r?void 0:r.state)||"prd-".concat(t.provider,"-").concat(Math.random().toString(36).slice(2)),[4,this.genProviderRedirectUri({provider_id:t.provider,provider_redirect_uri:u,state:h})];case 1:return d=c.sent().uri,p=decodeURIComponent(d),v=p,(null===(n=t.options)||void 0===n?void 0:n.queryParams)&&(g=new URL(p),Object.entries(t.options.queryParams).forEach(function(t){var e=t[0],r=t[1];g.searchParams.set(e,r)}),v=g.toString()),(0,f.saveToBrowserSession)(h,{provider:t.provider,search:a.search,hash:a.hash,type:(null===(i=t.options)||void 0===i?void 0:i.type)||l.OAUTH_TYPE.SIGN_IN}),y()&&!(null===(o=t.options)||void 0===o?void 0:o.skipBrowserRedirect)&&window.location.assign(v),[2,{data:{url:v,provider:t.provider},error:null}];case 2:return m=c.sent(),[2,{data:{url:null,provider:null},error:new l.AuthError(m,{method:"signInWithOAuth"})}];case 3:return[2]}})})},e.prototype.getClaims=function(){return u(this,void 0,Promise,function(){var t,e;return c(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this.getAccessToken()];case 1:return t=r.sent().accessToken,[2,{data:(0,l.weAppJwtDecodeAll)(t),error:null}];case 2:return e=r.sent(),[2,{data:{claims:null,header:null,signature:null},error:new l.AuthError(e,{method:"getClaims"})}];case 3:return[2]}})})},e.prototype.resetPasswordForEmail=function(t,e){return u(this,void 0,Promise,function(){var r,n,i,s,a,h,d=this;return c(this,function(p){switch(p.label){case 0:return p.trys.push([0,2,,3]),this.validateParams({emailOrPhone:t},{emailOrPhone:{required:!0,message:"Email or phone is required"}}),r=(e||{}).redirectTo,n=t.includes("@"),i=void 0,n?i={email:t}:(s=this.formatPhone(t),i={phone_number:s}),[4,this.getVerification(o(o({},i),{target:"USER"}))];case 1:return a=p.sent(),[2,{data:{updateUser:function(e){return u(d,void 0,Promise,function(){var i,o,s,u;return c(this,function(c){switch(c.label){case 0:this.validateParams(e,{nonce:{required:!0,message:"Nonce is required"},password:{required:!0,message:"Password is required"}}),c.label=1;case 1:return c.trys.push([1,5,,6]),[4,this.verify({verification_id:a.verification_id,verification_code:e.nonce})];case 2:return i=c.sent(),[4,this.oauthInstance.authApi.resetPassword({email:n?t:void 0,phone_number:n?void 0:t,new_password:e.password,verification_token:i.verification_token})];case 3:return c.sent(),null===(u=this.config.eventBus)||void 0===u||u.fire(l.EVENTS.AUTH_STATE_CHANGED,{event:l.AUTH_STATE_CHANGED_TYPE.PASSWORD_RECOVERY}),[4,this.signInWithPassword({email:n?t:void 0,phone:n?void 0:t,password:e.password})];case 4:return o=c.sent(),r&&y()&&window.location.assign(r),[2,o];case 5:return s=c.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(s,{method:"resetPasswordForEmail"})}];case 6:return[2]}})})}},error:null}];case 2:return h=p.sent(),[2,{data:{updateUser:null},error:new l.AuthError(h,{method:"resetPasswordForEmail"})}];case 3:return[2]}})})},e.prototype.resetPasswordForOld=function(t){return u(this,void 0,Promise,function(){var e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.oauthInstance.authApi.updatePasswordByOld({old_password:t.old_password,new_password:t.new_password})];case 1:return i.sent(),[4,this.getSession()];case 2:return e=i.sent().data,[2,{data:{user:(r=(void 0===e?{}:e).session).user,session:r},error:null}];case 3:return n=i.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(n,{method:"resetPasswordForOld"})}];case 4:return[2]}})})},e.prototype.verifyOtp=function(t){return u(this,void 0,Promise,function(){var e,r,n,i,o,s,a;return c(this,function(u){switch(u.label){case 0:return u.trys.push([0,6,,7]),e=t.type,r=String(t.token),n="email"in t?t.email:void 0,i="phone"in t?t.phone:void 0,this.validateParams(t,{token:{required:!0,message:"Token is required"},messageId:{required:!0,message:"messageId is required"}}),["phone_change","email_change"].includes(e)?[4,this.verify({verification_id:t.messageId,verification_code:r})]:[3,2];case 1:return u.sent(),[3,4];case 2:return[4,this.signInWithUsername({verificationInfo:{verification_id:t.messageId,is_user:!0},verificationCode:r,username:n||this.formatPhone(i)||"",loginType:n?"email":"phone"})];case 3:u.sent(),u.label=4;case 4:return[4,this.getSession()];case 5:return o=u.sent().data,[2,{data:{user:(s=(void 0===o?{}:o).session).user,session:s},error:null}];case 6:return a=u.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(a,{method:"verifyOtp"})}];case 7:return[2]}})})},e.prototype.getSession=function(){return u(this,void 0,Promise,function(){var t,e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(t=i.sent())&&"accessKey"!==t.scope?[4,this.getUser(!1)]:[2,{data:{session:null,user:null},error:null}];case 2:return e=i.sent().data,r=(void 0===e?{}:e).user,[2,{data:{session:o(o({},t),{user:r}),user:r},error:null}];case 3:return n=i.sent(),[2,{data:{session:null,user:null},error:new l.AuthError(n,{method:"getSession"})}];case 4:return[2]}})})},e.prototype.refreshSession=function(t){return u(this,void 0,Promise,function(){var e,r,n,i,s;return c(this,function(a){switch(a.label){case 0:return a.trys.push([0,4,,5]),[4,this.oauthInstance.oauth2client.localCredentials.getCredentials()];case 1:return(e=a.sent()).refresh_token=t||e.refresh_token,[4,this.oauthInstance.oauth2client.refreshToken(e)];case 2:return r=a.sent(),[4,this.getUser(!1)];case 3:return n=a.sent().data,[2,{data:{user:i=(void 0===n?{}:n).user,session:o(o({},r),{user:i})},error:null}];case 4:return s=a.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(s,{method:"refreshSession"})}];case 5:return[2]}})})},e.prototype.getUser=function(t){return void 0===t&&(t=!0),u(this,void 0,Promise,function(){var e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,3,,4]),[4,this.oauthInstance.oauth2client.getCredentials()];case 1:return(e=i.sent())&&"accessKey"!==e.scope?(r=this.convertToUser,[4,this.getCurrentUser(t)]):[2,{data:{user:null},error:null}];case 2:return[2,{data:{user:r.apply(this,[i.sent()])},error:null}];case 3:return n=i.sent(),[2,{data:{user:null},error:new l.AuthError(n,{method:"getUser"})}];case 4:return[2]}})})},e.prototype.refreshUser=function(){return u(this,void 0,Promise,function(){var t,e,r;return c(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),[4,this.currentUser.refresh()];case 1:return n.sent(),[4,this.getSession()];case 2:return t=n.sent().data,[2,{data:{user:(e=(void 0===t?{}:t).session).user,session:e},error:null}];case 3:return r=n.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(r,{method:"refreshUser"})}];case 4:return[2]}})})},e.prototype.updateUser=function(t){var e;return u(this,void 0,Promise,function(){var r,n,i,s,a,d,p,f,v,g,y,m,_,E=this;return c(this,function(b){switch(b.label){case 0:if(b.trys.push([0,8,,9]),r=["password","new_password"].find(function(e){var r=t[e];return null!=r&&""!==r}))throw new l.AuthError({message:'updateUser 不支持更新密码,检测到传入了 "'.concat(r,'" 参数。如需修改密码请使用 resetPasswordForOld(旧密码修改)、resetPasswordForEmail(验证码重置)或 reauthenticate(重新认证后改密)')});if(!Object.keys(t).some(function(e){return void 0!==t[e]&&null!==t[e]&&""!==t[e]}))throw new l.AuthError({message:"At least one field must be provided for update"});return n=t.email,i=t.phone,s=h(t,["email","phone"]),d=void 0!==i,p={},(a=void 0!==n)||d?(f=void 0,a?(f={email:t.email},v="email_change"):(g=this.formatPhone(t.phone),f={phone_number:g},v="phone_change"),[4,this.getVerification(o({},f))]):[3,4];case 1:return y=b.sent(),Object.keys(s).length>0?[4,this.updateUserBasicInfo(s)]:[3,3];case 2:b.sent(),b.label=3;case 3:return p={messageId:y.verification_id,verifyOtp:function(e){return u(E,void 0,Promise,function(){var r,n,i,o;return c(this,function(s){switch(s.label){case 0:return s.trys.push([0,11,,12]),e.email&&t.email===e.email?[4,this.verifyOtp({type:"email_change",email:t.email,token:e.token,messageId:y.verification_id})]:[3,3];case 1:return(r=s.sent()).error?[2,r]:[4,this.updateUserBasicInfo({email:t.email})];case 2:return s.sent(),[3,9];case 3:return e.phone&&t.phone===e.phone?[4,this.verifyOtp({type:"phone_change",phone:t.phone,token:e.token,messageId:y.verification_id})]:[3,6];case 4:return(r=s.sent()).error?[2,r]:[4,this.updateUserBasicInfo({phone:this.formatPhone(t.phone)})];case 5:return s.sent(),[3,9];case 6:return[4,this.verifyOtp(a?{type:v,email:t.email,token:e.token,messageId:y.verification_id}:{type:v,phone:t.phone,token:e.token,messageId:y.verification_id})];case 7:return(r=s.sent()).error?[2,r]:[4,this.updateUserBasicInfo(t)];case 8:s.sent(),s.label=9;case 9:return[4,this.getUser(!1)];case 10:return n=s.sent().data.user,null===(o=this.config.eventBus)||void 0===o||o.fire(l.EVENTS.AUTH_STATE_CHANGED,{event:l.AUTH_STATE_CHANGED_TYPE.USER_UPDATED}),[2,{data:{user:n},error:null}];case 11:return i=s.sent(),[2,{data:{user:null},error:new l.AuthError(i,{method:"updateUser"})}];case 12:return[2]}})})}},[3,6];case 4:return[4,this.updateUserBasicInfo(t)];case 5:b.sent(),b.label=6;case 6:return[4,this.getUser(!1)];case 7:return m=b.sent().data.user,Object.keys(s).length>0&&(null===(e=this.config.eventBus)||void 0===e||e.fire(l.EVENTS.AUTH_STATE_CHANGED,{event:l.AUTH_STATE_CHANGED_TYPE.USER_UPDATED})),[2,{data:o({user:m},p),error:null}];case 8:return _=b.sent(),[2,{data:{user:null},error:new l.AuthError(_,{method:"updateUser"})}];case 9:return[2]}})})},e.prototype.getUserIdentities=function(){var t;return u(this,void 0,Promise,function(){var e,r;return c(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,this.oauthInstance.authApi.getProviders()];case 1:return e=n.sent(),[2,{data:{identities:null===(t=null==e?void 0:e.data)||void 0===t?void 0:t.filter(function(t){return!!t.bind})},error:null}];case 2:return r=n.sent(),[2,{data:{identities:null},error:new l.AuthError(r,{method:"getUserIdentities"})}];case 3:return[2]}})})},e.prototype.linkIdentity=function(t){return u(this,void 0,Promise,function(){var e;return c(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}}),[4,this.signInWithOAuth({provider:t.provider,options:{type:l.OAUTH_TYPE.BIND_IDENTITY}})];case 1:return r.sent(),[2,{data:{provider:t.provider},error:null}];case 2:return e=r.sent(),[2,{data:{provider:null},error:new l.AuthError(e,{method:"linkIdentity"})}];case 3:return[2]}})})},e.prototype.unlinkIdentity=function(t){return u(this,void 0,Promise,function(){var e;return c(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),this.validateParams(t,{provider:{required:!0,message:"Provider is required"}}),[4,this.oauthInstance.authApi.unbindProvider({provider_id:t.provider})];case 1:return r.sent(),[2,{data:{},error:null}];case 2:return e=r.sent(),[2,{data:{},error:new l.AuthError(e,{method:"unlinkIdentity"})}];case 3:return[2]}})})},e.prototype.reauthenticate=function(){return u(this,void 0,Promise,function(){var t,e,r,n,i=this;return c(this,function(s){switch(s.label){case 0:return s.trys.push([0,3,,4]),[4,this.getUser(!1)];case 1:return t=s.sent().data.user,this.validateAtLeastOne(t,[["email","phone"]],"You must provide either an email or phone number"),e=t.email?{email:t.email}:{phone_number:this.formatPhone(t.phone)},[4,this.getVerification(e)];case 2:return r=s.sent(),[2,{data:{updateUser:function(t){return u(i,void 0,Promise,function(){var n,i,s,a,u;return c(this,function(c){switch(c.label){case 0:this.validateParams(t,{nonce:{required:!0,message:"Nonce is required"}}),c.label=1;case 1:return c.trys.push([1,9,,10]),t.password?[4,this.verify({verification_id:r.verification_id,verification_code:t.nonce})]:[3,5];case 2:return n=c.sent(),[4,this.oauthInstance.authApi.sudo({verification_token:n.verification_token})];case 3:return i=c.sent(),[4,this.oauthInstance.authApi.setPassword({new_password:t.password,sudo_token:i.sudo_token})];case 4:return c.sent(),[3,7];case 5:return[4,this.signInWithUsername(o(o({verificationInfo:r,verificationCode:t.nonce},e),{loginType:e.email?"email":"phone"}))];case 6:c.sent(),c.label=7;case 7:return[4,this.getSession()];case 8:return s=c.sent().data,[2,{data:{user:(a=(void 0===s?{}:s).session).user,session:a},error:null}];case 9:return u=c.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(u,{method:"reauthenticate"})}];case 10:return[2]}})})}},error:null}];case 3:return n=s.sent(),[2,{data:{updateUser:null},error:new l.AuthError(n,{method:"reauthenticate"})}];case 4:return[2]}})})},e.prototype.resend=function(t){return u(this,void 0,Promise,function(){var e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),this.validateAtLeastOne(t,[["email"],["phone"]],"You must provide either an email or phone number"),e="signup"===t.type?"ANY":"USER",r={target:e},"email"in t&&(r.email=t.email),"phone"in t&&(r.phone_number=this.formatPhone(t.phone)),[4,this.oauthInstance.authApi.getVerification(r)];case 1:return[2,{data:{messageId:i.sent().verification_id},error:null}];case 2:return n=i.sent(),[2,{data:{messageId:null},error:new l.AuthError(n,{method:"resend"})}];case 3:return[2]}})})},e.prototype.setSession=function(t){var e;return u(this,void 0,Promise,function(){var r,n,i;return c(this,function(o){switch(o.label){case 0:return o.trys.push([0,3,,4]),this.validateParams(t,{access_token:{required:!0,message:"Access token is required"},refresh_token:{required:!0,message:"Refresh token is required"}}),[4,this.oauthInstance.oauth2client.refreshToken(t,{throwError:!0})];case 1:return o.sent(),[4,this.getSession()];case 2:return r=o.sent().data,n=(void 0===r?{}:r).session,null===(e=this.config.eventBus)||void 0===e||e.fire(l.EVENTS.AUTH_STATE_CHANGED,{event:l.AUTH_STATE_CHANGED_TYPE.SIGNED_IN}),[2,{data:{user:n.user,session:n},error:null}];case 3:return i=o.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(i,{method:"setSession"})}];case 4:return[2]}})})},e.prototype.exchangeCodeForSession=function(){return u(this,void 0,void 0,function(){return c(this,function(t){return[2]})})},e.prototype.deleteUser=function(t){return u(this,void 0,Promise,function(){var e,r;return c(this,function(n){switch(n.label){case 0:return n.trys.push([0,3,,4]),this.validateParams(t,{password:{required:!0,message:"Password is required"}}),[4,this.oauthInstance.authApi.sudo(t)];case 1:return e=n.sent().sudo_token,[4,this.oauthInstance.authApi.deleteMe({sudo_token:e})];case 2:return n.sent(),[2,{data:{},error:null}];case 3:return r=n.sent(),[2,{data:{},error:new l.AuthError(r,{method:"deleteUser"})}];case 4:return[2]}})})},e.prototype.toDefaultLoginPage=function(t){return void 0===t&&(t={}),u(this,void 0,Promise,function(){var e,r,n,i,o;return c(this,function(s){try{return e=t.config_version||"env",r=Object.keys(t.query||{}).map(function(e){return"".concat(e,"=").concat(t.query[e])}).join("&"),p.adapterForWxMp.isMatch()?wx.navigateTo({url:"/packages/$wd_system/pages/login/index".concat(r?"?".concat(r):"")}):(n=t.redirect_uri||window.location.href,i=new URL(n),o="".concat(i.origin,"/__auth/?app_id=").concat(t.app_id||"","&env_id=").concat(this.config.env,"&client_id=").concat(this.config.clientId||this.config.env,"&config_version=").concat(e,"&redirect_uri=").concat(encodeURIComponent(n)).concat(r?"&".concat(r):""),window.location.href=o),[2,{data:{},error:null}]}catch(t){return[2,{data:{},error:new l.AuthError(t,{method:"toDefaultLoginPage"})}]}return[2]})})},e.prototype.signInWithCustomTicket=function(t){return u(this,void 0,Promise,function(){var e,r,n,i;return c(this,function(s){switch(s.label){case 0:t&&this.setCustomSignFunc(t),s.label=1;case 1:return s.trys.push([1,5,,6]),[4,this.oauthInstance.authApi.signInWithCustomTicket()];case 2:return s.sent(),[4,this.createLoginState()];case 3:return e=s.sent(),[4,this.getSession()];case 4:return r=s.sent().data,n=(void 0===r?{}:r).session,[2,o(o({},e),{data:{user:n.user,session:n},error:null})];case 5:return i=s.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(i,{method:"signInWithCustomTicket"})}];case 6:return[2]}})})},e.prototype.signInWithOpenId=function(t){var e=(void 0===t?{}:t).useWxCloud,r=void 0===e||e;return u(this,void 0,Promise,function(){var t,e,n,i,s,a,h=this;return c(this,function(d){switch(d.label){case 0:if(!p.adapterForWxMp.isMatch())throw Error("wx api undefined");t=wx.getAccountInfoSync().miniProgram,e=function(e){return u(h,void 0,void 0,function(){var n,i;return c(this,function(o){switch(o.label){case 0:n=void 0,i=void 0,o.label=1;case 1:return o.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},r)];case 2:if((null==(n=o.sent())?void 0:n.error_code)||!n.provider_token)throw n;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:n.provider_token},r)];case 3:if(null==(i=o.sent())?void 0:i.error_code)throw i;return[3,5];case 4:throw o.sent();case 5:return[4,this.oauthInstance.oauth2client.setCredentials(i)];case 6:return o.sent(),[2]}})})},d.label=1;case 1:return d.trys.push([1,5,,6]),[4,new Promise(function(t,r){wx.login({success:function(n){return u(h,void 0,void 0,function(){var i;return c(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,e(n.code)];case 1:return o.sent(),t(!0),[3,3];case 2:return i=o.sent(),r(i),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,r(e)}})})];case 2:return d.sent(),[4,this.createLoginState()];case 3:return n=d.sent(),[4,this.getSession()];case 4:return i=d.sent().data,s=(void 0===i?{}:i).session,[2,o(o({},n),{data:{user:s.user,session:s},error:null})];case 5:return a=d.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(a,{method:"signInWithOpenId"})}];case 6:return[2]}})})},e.prototype.signInWithPhoneAuth=function(t){var e=t.phoneCode,r=void 0===e?"":e,n=t.useWxCloud,i=void 0!==n&&n;return u(this,void 0,Promise,function(){var t,e,n,s,a,u,h,d,f;return c(this,function(c){switch(c.label){case 0:return p.adapterForWxMp.isMatch()?(t=wx.getAccountInfoSync().miniProgram,e={provider_params:{provider_code_type:"phone",code:r,appid:t.appId},provider_id:t.appId},[4,wx.login()]):[2,{data:{user:null,session:null},error:new l.AuthError({message:"wx api undefined"})}];case 1:n=c.sent().code,e.provider_code=n,c.label=2;case 2:return c.trys.push([2,5,,6]),[4,this.oauthInstance.authApi.grantProviderToken(e,i)];case 3:if((s=c.sent()).error_code)throw s;return[4,this.oauthInstance.authApi.signInWithProvider({provider_token:s.provider_token},i)];case 4:if(null==(a=c.sent())?void 0:a.error_code)throw a;return[3,6];case 5:return u=c.sent(),[2,{data:{user:null,session:null},error:new l.AuthError(u,{method:"signInWithPhoneAuth"})}];case 6:return[4,this.createLoginState()];case 7:return h=c.sent(),[4,this.getSession()];case 8:return d=c.sent().data,f=(void 0===d?{}:d).session,[2,o(o({},h),{data:{user:f.user,session:f},error:null})]}})})},e.prototype.bindPhoneNumber=function(t){return u(this,void 0,void 0,function(){return c(this,function(e){return[2,this.oauthInstance.authApi.editContact(t)]})})},e.prototype.unbindProvider=function(t){return u(this,void 0,Promise,function(){return c(this,function(e){return[2,this.oauthInstance.authApi.unbindProvider(t)]})})},e.prototype.bindEmail=function(t){return this.oauthInstance.authApi.editContact(t)},e.prototype.verify=function(t){return u(this,void 0,Promise,function(){return c(this,function(e){return[2,this.oauthInstance.authApi.verify(t)]})})},e.prototype.getVerification=function(t,e){return u(this,void 0,Promise,function(){return c(this,function(r){return t.phone_number&&(t.phone_number=this.formatPhone(t.phone_number)),[2,this.oauthInstance.authApi.getVerification(t,e)]})})},Object.defineProperty(e.prototype,"currentUser",{get:function(){if("async"!==this.cache.mode){var t=this.hasLoginState();return t&&t.user||null}(0,p.printWarn)(p.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getCurrentUser instead")},enumerable:!1,configurable:!0}),e.prototype.getCurrentUser=function(t){return void 0===t&&(t=!0),u(this,void 0,Promise,function(){var e,r,n;return c(this,function(i){switch(i.label){case 0:return i.trys.push([0,4,,5]),t?[4,this.getLoginState()]:[3,3];case 1:return(e=i.sent())?[4,e.user.refresh()]:[3,3];case 2:i.sent(),i.label=3;case 3:return[3,5];case 4:return i.sent(),[3,5];case 5:return[4,this.getLoginState()];case 6:return(r=i.sent())?(n=r.user.getLocalUserInfo(),[4,r.user.checkLocalInfoAsync()]):[3,8];case 7:return i.sent(),[2,o(o({},r.user),n)];case 8:return[2,null]}})})},e.prototype.signInAnonymouslyInWx=function(t){var e=(void 0===t?{}:t).useWxCloud;return u(this,void 0,Promise,function(){var t,r,n=this;return c(this,function(i){switch(i.label){case 0:if(!p.adapterForWxMp.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,r=function(r){return u(n,void 0,void 0,function(){var n,i;return c(this,function(o){switch(o.label){case 0:n=void 0,i=void 0,o.label=1;case 1:return o.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:r,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}},e)];case 2:if((null==(n=o.sent())?void 0:n.error_code)||!n.provider_token)throw n;return[4,this.oauthInstance.authApi.signInAnonymously({provider_token:n.provider_token},e)];case 3:if(null==(i=o.sent())?void 0:i.error_code)throw i;return[3,5];case 4:throw o.sent();case 5:return[2]}})})},[4,new Promise(function(t,e){wx.login({success:function(i){return u(n,void 0,void 0,function(){var n;return c(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,r(i.code)];case 1:return o.sent(),t(!0),[3,3];case 2:return n=o.sent(),e(n),[3,3];case 3:return[2]}})})},fail:function(t){var r=new Error(null==t?void 0:t.errMsg);r.code=null==t?void 0:t.errno,e(r)}})})];case 1:return i.sent(),[2,this.createLoginState(void 0,{asyncRefreshUser:!0})]}})})},e.prototype.bindOpenId=function(){return u(this,void 0,Promise,function(){var t,e,r=this;return c(this,function(n){switch(n.label){case 0:if(!p.adapterForWxMp.isMatch())throw Error("wx api undefined");return t=wx.getAccountInfoSync().miniProgram,e=function(e){return u(r,void 0,void 0,function(){var r;return c(this,function(n){switch(n.label){case 0:r=void 0,n.label=1;case 1:return n.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_id:null==t?void 0:t.appId,provider_code:e,provider_params:{provider_code_type:"open_id",appid:null==t?void 0:t.appId}})];case 2:if((null==(r=n.sent())?void 0:r.error_code)||!r.provider_token)throw r;return[4,this.oauthInstance.authApi.bindWithProvider({provider_token:r.provider_token})];case 3:return n.sent(),[3,5];case 4:throw n.sent();case 5:return[2]}})})},[4,new Promise(function(t,n){wx.login({success:function(i){return u(r,void 0,void 0,function(){var r;return c(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,e(i.code)];case 1:return o.sent(),t(!0),[3,3];case 2:return r=o.sent(),n(r),[3,3];case 3:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,n(e)}})})];case 1:return n.sent(),[2]}})})},e.prototype.signInWithUnionId=function(){return u(this,void 0,Promise,function(){var t=this;return c(this,function(e){switch(e.label){case 0:if(!p.adapterForWxMp.isMatch())throw Error("wx api undefined");e.label=1;case 1:return e.trys.push([1,3,,4]),[4,new Promise(function(e,r){var n=wx.getAccountInfoSync().miniProgram;wx.login({success:function(i){return u(t,void 0,void 0,function(){var t,o,s,a,u;return c(this,function(c){switch(c.label){case 0:t=null==n?void 0:n.appId,c.label=1;case 1:return c.trys.push([1,4,,5]),[4,this.oauthInstance.authApi.grantProviderToken({provider_code:i.code,provider_id:t,provider_params:{provider_code_type:"union_id",appid:null==n?void 0:n.appId}})];case 2:return o=c.sent(),(s=o.provider_token)?[4,this.oauthInstance.authApi.signInWithProvider({provider_id:t,provider_token:s})]:(r(o),[2]);case 3:return(null==(a=c.sent())?void 0:a.error_code)?(r(a),[2]):(e(!0),[3,5]);case 4:return u=c.sent(),r(u),[3,5];case 5:return[2]}})})},fail:function(t){var e=new Error(null==t?void 0:t.errMsg);e.code=null==t?void 0:t.errno,r(e)}})})];case 2:return e.sent(),[3,4];case 3:throw e.sent();case 4:return[2,this.createLoginState()]}})})},e.prototype.signInWithSms=function(t){var e=t.verificationInfo,r=void 0===e?{verification_id:"",is_user:!1}:e,n=t.verificationCode,i=void 0===n?"":n,o=t.phoneNum,s=void 0===o?"":o,a=t.bindInfo,h=void 0===a?voi