UNPKG

@cloudbase/js-sdk

Version:
2 lines 167 kB
/*! For license information please see index.js.LICENSE.txt */ !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,e,r={829:(t,e,r)=>{var n;r.r(e),r.d(e,{AbstractSDKRequest:()=>i,AbstractStorage:()=>o,StorageType:()=>n,formatUrl:()=>s}),function(t){t.local="local",t.none="none",t.session="session"}(n||(n={}));var i=function(){},o=function(){};function s(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),i="";for(var o in r)""===i?!n&&(e+="?"):i+="&",i+=o+"="+encodeURIComponent(r[o]);return/^http(s)?\:\/\//.test(e+=i)?e:""+t+e}},413: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])}}},s=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},a=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),e.Auth=void 0;var u=r(949),c=r(257),l=r(462),h=r(631),d=a(r(639)),f=r(308);function p(t,e){var n;return i(this,void 0,void 0,function(){var s,a=this;return o(this,function(u){s=function(){return i(a,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:return t.trys.push([0,1,,6]),[2,r(814)];case 1:t.sent(),t.label=2;case 2:return t.trys.push([2,4,,5]),[4,Promise.resolve().then(r.t.bind(r,814,23))];case 3:return[2,t.sent()];case 4:return t.sent(),[2];case 5:return[3,6];case 6:return[2]}})})};try{if(((null===(n=null==e?void 0:e.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return[2]}catch(e){if(t)return[2,s()]}return[2]})})}var v=function(){function t(t){var e=t.request,r=t.credentialsClient;if(!r){var i={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n,debug:t.debug};r=new c.OAuth2Client(i)}if(!e){var o=r.request.bind(r),s=new l.Captcha(n({env:t.env,clientId:t.clientId,request:o,storage:t.storage,adapter:t.adapter,oauthInstance:this},t.captchaOptions));e=s.request.bind(s)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:r,storage:t.storage||c.defaultStorage,adapter:t.adapter}}return t.parseParamsToSearch=function(t){return Object.keys(t).forEach(function(e){t[e]||delete t[e]}),new d.default(t).toString()},t.prototype.getParamsByVersion=function(t,e){var r,n=(0,h.deepClone)(t),i=(null===(r={v2:u.ApiUrlsV2}[null==n?void 0:n.version])||void 0===r?void 0:r[e])||u.ApiUrls[e];return n&&delete n.version,{params:n,url:i}},t.prototype.signIn=function(t){return i(this,void 0,Promise,function(){var e,r,i,s;return o(this,function(o){switch(o.label){case 0:return e=t.version||"v1",(r=this.getParamsByVersion(t,"AUTH_SIGN_IN_URL")).params.query&&delete r.params.query,[4,this.getEncryptParams(r.params)];case 1:return i=o.sent(),[4,this.config.request(r.url,{method:"POST",body:i})];case 2:return s=o.sent(),[4,this.config.credentialsClient.setCredentials(n(n({},s),{version:e}))];case 3:return o.sent(),[2,Promise.resolve(s)]}})})},t.prototype.signInAnonymously=function(t,e){return void 0===t&&(t={}),void 0===e&&(e=!1),i(this,void 0,Promise,function(){var r;return o(this,function(n){switch(n.label){case 0:return[4,this.config.request(u.ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:t,useWxCloud:e})];case 1:return r=n.sent(),[4,this.config.credentialsClient.setCredentials(r)];case 2:return n.sent(),[2,Promise.resolve(r)]}})})},t.prototype.signUp=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){switch(r.label){case 0:return[4,this.config.request(u.ApiUrls.AUTH_SIGN_UP_URL,{method:"POST",body:t})];case 1:return e=r.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return r.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signOut=function(t){return i(this,void 0,Promise,function(){var e,r,n,i;return o(this,function(o){switch(o.label){case 0:if(e={},!t)return[3,6];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,this.config.request(u.ApiUrls.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})];case 2:return e=o.sent(),[3,4];case 3:return(r=o.sent()).error!==u.ErrorType.UNAUTHENTICATED&&console.log("sign_out_error",r),[3,4];case 4:return[4,this.config.credentialsClient.setCredentials()];case 5:return o.sent(),[2,e];case 6:return[4,this.config.credentialsClient.getAccessToken()];case 7:return n=o.sent(),[4,this.config.request(u.ApiUrls.AUTH_REVOKE_URL,{method:"POST",body:{token:n}})];case 8:return i=o.sent(),[4,this.config.credentialsClient.setCredentials()];case 9:return o.sent(),[2,Promise.resolve(i)]}})})},t.prototype.revokeAllDevices=function(){return i(this,void 0,Promise,function(){return o(this,function(t){switch(t.label){case 0:return[4,this.config.request(u.ApiUrls.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})];case 1:return t.sent(),[2]}})})},t.prototype.revokeDevice=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){switch(e.label){case 0:return[4,this.config.request(u.ApiUrls.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})];case 1:return e.sent(),[2]}})})},t.prototype.getVerification=function(t,e){return i(this,void 0,Promise,function(){var r,n;return o(this,function(i){switch(i.label){case 0:return r=!1,"CUR_USER"!==t.target?[3,1]:(r=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:i.sent()&&(r=!0),i.label=3;case 3:return(n=(0,h.deepClone)(t)).phone_number&&!/^\+\d{1,3}\s+\d+/.test(n.phone_number)&&(n.phone_number="+86 ".concat(n.phone_number)),[2,this.config.request(u.ApiUrls.VERIFICATION_URL,{method:"POST",body:n,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:r})]}})})},t.prototype.verify=function(t){return i(this,void 0,Promise,function(){var e,r;return o(this,function(i){switch(i.label){case 0:return e=this.getParamsByVersion(t,"VERIFY_URL"),[4,this.config.request(e.url,{method:"POST",body:e.params})];case 1:return r=i.sent(),"v2"!==(null==t?void 0:t.version)?[3,3]:[4,this.config.credentialsClient.setCredentials(n(n({},r),{version:"v2"}))];case 2:i.sent(),i.label=3;case 3:return[2,r]}})})},t.prototype.genProviderRedirectUri=function(e){return i(this,void 0,Promise,function(){var r,n,i,a,c;return o(this,function(o){return r=e.provider_redirect_uri,n=e.other_params,i=void 0===n?{}:n,a=s(e,["provider_redirect_uri","other_params"]),r&&!a.redirect_uri&&(a.redirect_uri=r),c="".concat(u.ApiUrls.PROVIDER_URI_URL,"?").concat(t.parseParamsToSearch(a)),Object.keys(i).forEach(function(t){var e=i[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(c+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))}),[2,this.config.request(c,{method:"GET"})]})})},t.prototype.grantProviderToken=function(t,e){return void 0===e&&(e=!1),i(this,void 0,Promise,function(){return o(this,function(r){return[2,this.config.request(u.ApiUrls.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:e})]})})},t.prototype.patchProviderToken=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})]})})},t.prototype.signInWithProvider=function(t,e){return void 0===e&&(e=!1),i(this,void 0,Promise,function(){var r,i;return o(this,function(o){switch(o.label){case 0:return r=this.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(r.url,{method:"POST",body:r.params,useWxCloud:e})];case 1:return i=o.sent(),[4,this.config.credentialsClient.setCredentials(n(n({},i),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return o.sent(),[2,Promise.resolve(i)]}})})},t.prototype.toBindIdentity=function(t){var e,r;return i(this,void 0,void 0,function(){var n,i,s,a;return o(this,function(o){switch(o.label){case 0:return(i=t.credentials)?[3,2]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 1:i=o.sent(),o.label=2;case 2:n=i,o.label=3;case 3:return o.trys.push([3,5,,6]),[4,this.bindWithProvider({provider_token:t.provider_token},n)];case 4:return o.sent(),s={data:{type:u.OAUTH_TYPE.BIND_IDENTITY,provider:t.provider},error:null},[3,6];case 5:return a=o.sent(),s={data:{type:u.OAUTH_TYPE.BIND_IDENTITY},error:new f.AuthError(a)},[3,6];case 6:return t.fireEvent&&(null===(r=null===(e=this.config.eventBus)||void 0===e?void 0:e.fire)||void 0===r||r.call(e,u.EVENTS.AUTH_STATE_CHANGED,{event:u.AUTH_STATE_CHANGED_TYPE.BIND_IDENTITY,info:s})),[2,s]}})})},t.prototype.getInitialSession=function(){return i(this,void 0,Promise,function(){var t,e,r,i,s,a,c,l,h,d,p,v,g,_,y;return o(this,function(o){switch(o.label){case 0:t={},o.label=1;case 1:if(o.trys.push([1,12,,13]),"undefined"==typeof window||"undefined"==typeof document)return[2,{data:null,error:null}];if(e=new URLSearchParams(null===location||void 0===location?void 0:location.search),r=e.get("code"),i=e.get("state"),!r||!i)return[2,{data:null,error:null}];s=null;try{s=JSON.parse(sessionStorage.getItem(i)||"null")}catch(t){}return t={type:null==s?void 0:s.type},a=e.get("error"),c=e.get("error_description"),a||c?[2,{data:t,error:new f.AuthError({message:c||a||"Unknown error from OAuth provider"})}]:(l=(null==s?void 0:s.provider)||e.get("provider"))?(h=location.origin+location.pathname,[4,this.grantProviderToken({provider_id:l,provider_redirect_uri:h,provider_code:r})]):[2,{data:t,error:new f.AuthError({message:"Provider is required for OAuth verification"})}];case 2:return d=o.sent().provider_token,p=void 0,v=null,g=void 0,s.type!==u.OAUTH_TYPE.BIND_IDENTITY?[3,5]:[4,this.config.credentialsClient.localCredentials.getCredentials()];case 3:return p=o.sent(),[4,this.toBindIdentity({provider:l,provider_token:d,credentials:p})];case 4:return g=o.sent(),[3,11];case 5:return s.type!==u.OAUTH_TYPE.SIGN_IN?[3,11]:(g=this.getParamsByVersion({provider:l},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),[4,this.config.request(g.url,{method:"POST",body:{provider_token:d}})]);case 6:p=o.sent(),o.label=7;case 7:return o.trys.push([7,9,,10]),[4,this.getUserInfo({credentials:p})];case 8:return v=o.sent(),[3,10];case 9:return _=o.sent(),console.error("get user info error",_),[3,10];case 10:g={data:n(n({},t),{session:p,user:v}),error:null},o.label=11;case 11:e.delete("code"),e.delete("state"),e.delete("provider"),this.restoreUrlState(void 0===(null==s?void 0:s.search)?"?".concat(e.toString()):s.search,(null==s?void 0:s.hash)||location.hash);try{sessionStorage.removeItem(i)}catch(t){}return[2,g];case 12:return y=o.sent(),[2,{data:t,error:new f.AuthError(y)}];case 13:return[2]}})})},t.prototype.signInCustom=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){switch(r.label){case 0:return[4,this.config.request(u.ApiUrls.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t})];case 1:return e=r.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return r.sent(),[2,Promise.resolve(e)]}})})},t.prototype.signInWithWechat=function(t){return void 0===t&&(t={}),i(this,void 0,Promise,function(){var e;return o(this,function(r){switch(r.label){case 0:return[4,this.config.request(u.ApiUrls.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:t})];case 1:return e=r.sent(),[4,this.config.credentialsClient.setCredentials(e)];case 2:return r.sent(),[2,Promise.resolve(e)]}})})},t.prototype.bindWithProvider=function(t,e){return i(this,void 0,Promise,function(){return o(this,function(r){return[2,this.config.request(u.ApiUrls.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0,getCredentials:e?function(){return e}:void 0})]})})},t.prototype.getUserProfile=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.getUserInfo(t)]})})},t.prototype.getUserInfo=function(t){var e,r,n;return void 0===t&&(t={}),i(this,void 0,Promise,function(){var i,s,a,u,c;return o(this,function(o){switch(o.label){case 0:return i=this.getParamsByVersion(t,"USER_ME_URL"),(null===(e=i.params)||void 0===e?void 0:e.query)&&(s=new d.default(i.params.query),i.url+="?".concat(s.toString())),[4,this.config.request(i.url,{method:"GET",withCredentials:!0,getCredentials:t.credentials?function(){return t.credentials}:void 0})];case 1:if((a=o.sent()).sub&&(a.uid=a.sub),null===(r=a.providers)||void 0===r?void 0:r.length)try{"undefined"!=typeof wx&&wx.getAccountInfoSync&&(u=null===(n=wx.getAccountInfoSync().miniProgram)||void 0===n?void 0:n.appId,(null==(c=a.providers.find(function(t){return t.id===u}))?void 0:c.provider_user_id)&&(a.open_id=c.provider_user_id))}catch(t){}return[2,a]}})})},t.prototype.getWedaUserInfo=function(){return i(this,void 0,Promise,function(){return o(this,function(t){switch(t.label){case 0:return[4,this.config.request(u.ApiUrls.WEDA_USER_URL,{method:"GET",withCredentials:!0})];case 1:return[2,t.sent()]}})})},t.prototype.deleteMe=function(e){return i(this,void 0,Promise,function(){var r,n;return o(this,function(i){return r=this.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(t.parseParamsToSearch(r.params)),[2,this.config.request(n,{method:"DELETE",withCredentials:!0})]})})},t.prototype.hasLoginState=function(){return i(this,void 0,Promise,function(){return o(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 i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.credentialsClient.getCredentialsAsync()]})})},t.prototype.transByProvider=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.grantToken=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){return e=this.getParamsByVersion(t,"AUTH_TOKEN_URL"),[2,this.config.request(e.url,{method:"POST",body:e.params})]})})},t.prototype.getProviders=function(){return i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.request(u.ApiUrls.PROVIDER_LIST,{method:"GET",withCredentials:!0})]})})},t.prototype.unbindProvider=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})]})})},t.prototype.checkPassword=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.editContact=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.setPassword=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})]})})},t.prototype.updatePasswordByOld=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){switch(r.label){case 0:return[4,this.sudo({password:t.old_password})];case 1:return e=r.sent(),[2,this.setPassword({sudo_token:e.sudo_token,new_password:t.new_password})]}})})},t.prototype.sudo=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.SUDO_URL),{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.sendVerificationCodeToCurrentUser=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return t.target="CUR_USER",[2,this.config.request(u.ApiUrls.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})]})})},t.prototype.changeBoundProvider=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request("".concat(u.ApiUrls.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})]})})},t.prototype.setUserProfile=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})]})})},t.prototype.updateUserBasicInfo=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.queryUserProfile=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){return e=new d.default(t),[2,this.config.request("".concat(u.ApiUrls.USER_QUERY_URL,"?").concat(e.toString()),{method:"GET",withCredentials:!0})]})})},t.prototype.setCustomSignFunc=function(t){this.getCustomSignTicketFn=t},t.prototype.signInWithCustomTicket=function(){return i(this,void 0,Promise,function(){var t,e;return o(this,function(r){switch(r.label){case 0:return(t=this.getCustomSignTicketFn)?[4,t()]:[2,Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"})];case 1:return e=r.sent(),[2,this.signInCustom({provider_id:"custom",ticket:e})]}})})},t.prototype.resetPassword=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.AUTH_RESET_PASSWORD,{method:"POST",body:t})]})})},t.prototype.authorize=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.authorizeDevice=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})]})})},t.prototype.deviceAuthorize=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.AUTH_GET_DEVICE_CODE,{method:"POST",body:t})]})})},t.prototype.authorizeInfo=function(e){return i(this,void 0,Promise,function(){var r,n,i;return o(this,function(o){switch(o.label){case 0:return r="".concat(u.ApiUrls.AUTHORIZE_INFO_URL,"?").concat(t.parseParamsToSearch(e)),n=!0,i=!1,[4,this.hasLoginState()];case 1:return o.sent()&&(i=!0,n=!1),[2,this.config.request(r,{method:"GET",withBasicAuth:n,withCredentials:i})]}})})},t.prototype.checkUsername=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})]})})},t.prototype.checkIfUserExist=function(t){return i(this,void 0,Promise,function(){var e;return o(this,function(r){return e=new d.default(t),[2,this.config.request("".concat(u.ApiUrls.CHECK_IF_USER_EXIST,"?").concat(e.toString()),{method:"GET"})]})})},t.prototype.loginScope=function(){return i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.credentialsClient.getScope()]})})},t.prototype.loginGroups=function(){return i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.credentialsClient.getGroups()]})})},t.prototype.refreshTokenForce=function(t){return i(this,void 0,void 0,function(){var e;return o(this,function(r){switch(r.label){case 0:return[4,this.config.credentialsClient.getCredentials()];case 1:return e=r.sent(),[4,this.config.credentialsClient.refreshToken(n(n({},e),{version:(null==t?void 0:t.version)||"v1"}))];case 2:return[2,r.sent()]}})})},t.prototype.getCredentials=function(){return i(this,void 0,void 0,function(){return o(this,function(t){return[2,this.config.credentialsClient.getCredentials()]})})},t.prototype.getPublicKey=function(){return i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.request(u.ApiUrlsV2.AUTH_PUBLIC_KEY,{method:"POST",body:{}})]})})},t.prototype.getEncryptParams=function(t){return i(this,void 0,Promise,function(){var e,r,n,i,s,a;return o(this,function(o){switch(o.label){case 0:return e=t.isEncrypt,delete t.isEncrypt,r=(0,h.deepClone)(t),[4,p(e,this.config.adapter)];case 1:if(!(n=o.sent()))return[2,t];i="",s="",o.label=2;case 2:return o.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(a=o.sent(),i=a.public_key,s=a.public_key_thumbprint,!i||!s)throw a;return[3,5];case 4:throw o.sent();case 5:return[2,{params:n.getEncryptInfo({publicKey:i,payload:r}),public_key_thumbprint:s}]}})})},t.prototype.getProviderSubType=function(){return i(this,void 0,Promise,function(){return o(this,function(t){return[2,this.config.request(u.ApiUrls.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})]})})},t.prototype.verifyCaptchaData=function(t){var e=t.token,r=t.key;return i(this,void 0,void 0,function(){return o(this,function(t){return[2,this.config.request(u.ApiUrls.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:e,key:r},withCredentials:!1})]})})},t.prototype.createCaptchaData=function(t){var e=t.state,r=t.redirect_uri,n=void 0===r?void 0:r;return i(this,void 0,void 0,function(){return o(this,function(t){return[2,this.config.request(u.ApiUrls.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:n},withCredentials:!1})]})})},t.prototype.getMiniProgramCode=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.GET_MINIPROGRAM_QRCODE,{method:"POST",body:t})]})})},t.prototype.getMiniProgramQrCodeStatus=function(t){return i(this,void 0,Promise,function(){return o(this,function(e){return[2,this.config.request(u.ApiUrls.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:t})]})})},t.prototype.getUserBehaviorLog=function(t){return i(this,void 0,Promise,function(){var e,r;return o(this,function(n){return e={LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"},r="".concat(u.ApiUrls.GET_USER_BEHAVIOR_LOG,"?").concat(e[t.type],"&limit=").concat(t.limit).concat(t.page_token?"&page_token=".concat(t.page_token):""),[2,this.config.request(r,{method:"GET",withCredentials:!0})]})})},t.prototype.modifyPassword=function(t){return i(this,void 0,Promise,function(){var e,r,n,i,s,a;return o(this,function(o){switch(o.label){case 0:return e="",r="",[4,p(!0,this.config.adapter)];case 1:if(!(n=o.sent()))throw new Error("do not support encrypt, a encrypt util required.");o.label=2;case 2:return o.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(i=o.sent(),e=i.public_key,r=i.public_key_thumbprint,!e||!r)throw i;return[3,5];case 4:throw o.sent();case 5:return s=t.password?n.getEncryptInfo({publicKey:e,payload:t.password}):"",a=n.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(u.ApiUrls.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:t.user_id,encrypt_password:s,encrypt_new_password:a,public_key_thumbprint:r}})]}})})},t.prototype.modifyPasswordWithoutLogin=function(t){return i(this,void 0,Promise,function(){var e,r,n,i,s,a;return o(this,function(o){switch(o.label){case 0:return e="",r="",[4,p(!0,this.config.adapter)];case 1:if(!(n=o.sent()))throw new Error("do not support encrypt, a encrypt util required.");o.label=2;case 2:return o.trys.push([2,4,,5]),[4,this.getPublicKey()];case 3:if(i=o.sent(),e=i.public_key,r=i.public_key_thumbprint,!e||!r)throw i;return[3,5];case 4:throw o.sent();case 5:return s=t.password?n.getEncryptInfo({publicKey:e,payload:t.password}):"",a=n.getEncryptInfo({publicKey:e,payload:t.new_password}),[2,this.config.request(u.ApiUrlsV2.AUTH_RESET_PASSWORD,{method:"POST",body:{username:t.username,password:s,new_password:a,public_key_thumbprint:r}})]}})})},t.prototype.restoreUrlState=function(t,e){if(void 0!==t)try{var r=new URL(window.location.href);r.search=t,r.hash=e||"",window.history.replaceState(null,"",r.toString()),window.location.replace(r.toString())}catch(t){}},t}();e.Auth=v},308: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)});Object.defineProperty(e,"__esModule",{value:!0}),e.isAuthError=e.AuthError=e.AuthErrorCategory=void 0;var o,s=r(949);!function(t){t.PROVIDER_NOT_ENABLED="PROVIDER_NOT_ENABLED",t.INVALID_CREDENTIALS="INVALID_CREDENTIALS",t.USER_NOT_FOUND="USER_NOT_FOUND",t.USER_STATUS_ABNORMAL="USER_STATUS_ABNORMAL",t.SERVICE_ERROR="SERVICE_ERROR",t.INVALID_PARAMS="INVALID_PARAMS",t.AUTH_METHOD_MISMATCH="AUTH_METHOD_MISMATCH",t.RATE_LIMITED="RATE_LIMITED",t.CAPTCHA_REQUIRED="CAPTCHA_REQUIRED",t.CAPTCHA_INVALID="CAPTCHA_INVALID",t.MFA_REQUIRED="MFA_REQUIRED",t.PRECONDITION_FAILED="PRECONDITION_FAILED",t.VERIFICATION_FAILED="VERIFICATION_FAILED",t.UNKNOWN="UNKNOWN"}(o=e.AuthErrorCategory||(e.AuthErrorCategory={}));var a="https://tcb.cloud.tencent.com/dev?envId=#/identity/login-manage",u="https://docs.cloudbase.net/api-reference/webv3/initialization",c=function(t){function e(e,r){var n,i=this,c=e.error_description||e.message;return(i=t.call(this,c)||this).__isAuthError=!0,i.name="AuthError",i.status=e.error,i.code=String(e.error||e.error_code||"unknown").toLowerCase(),i.errorCode="number"==typeof e.error_code?e.error_code:"string"==typeof e.error_code&&parseInt(e.error_code,10)||void 0,i.requestId=e.requestId,i.category=function(t,e,r){if(!t&&!e&&!r)return o.UNKNOWN;try{var n=(t||"").toLowerCase(),i="string"==typeof r?parseInt(r,10):r;return i===s.AuthErrorCode.CAPTCHA_REQUIRED||e===s.ErrorType.CAPTCHA_REQUIRED?o.CAPTCHA_REQUIRED:i===s.AuthErrorCode.CAPTCHA_INVALID||e===s.ErrorType.CAPTCHA_INVALID?o.CAPTCHA_INVALID:i===s.AuthErrorCode.MFA_PHONE_REQUIRED||e===s.ErrorType.MFA_PHONE_REQUIRED?o.MFA_REQUIRED:i===s.AuthErrorCode.LOGIN_TYPE_DISABLED||e===s.ErrorType.LOGIN_TYPE_DISABLED?o.PROVIDER_NOT_ENABLED:i===s.AuthErrorCode.RESOURCE_EXHAUSTED||e===s.ErrorType.RESOURCE_EXHAUSTED?o.RATE_LIMITED:i===s.AuthErrorCode.INTERNAL||i===s.AuthErrorCode.UNAVAILABLE||i===s.AuthErrorCode.UNIMPLEMENTED||i===s.AuthErrorCode.ABORTED?o.SERVICE_ERROR:i===s.AuthErrorCode.NOT_FOUND?o.USER_NOT_FOUND:i===s.AuthErrorCode.UNAUTHENTICATED?o.INVALID_CREDENTIALS:i===s.AuthErrorCode.INVALID_ARGUMENT&&(n.includes("验证码")||n.includes("verification")||n.includes("verification_code")||n.includes("verification_id")||n.includes("does not match")||n.includes("token expired")||n.includes("token error")||n.includes("过期"))?o.VERIFICATION_FAILED:e===s.ErrorType.PROVIDER_NOT_ENABLED||e===s.ErrorType.LOGIN_METHOD_DISABLED||n.includes("身份源")||n.includes("开启")||n.includes("identity provider")||n.includes("provider not enabled")||n.includes("login method")||n.includes("登录方式")||n.includes("not enabled")||n.includes("未开启")||n.includes("未启用")||n.includes("请联系开发者")||n.includes("anonymous login is not enabled")||n.includes("匿名登录未开启")?o.PROVIDER_NOT_ENABLED:e===s.ErrorType.FAILED_PRECONDITION||i===s.AuthErrorCode.FAILED_PRECONDITION&&!n.includes("请联系开发者")?n.includes("不存在")||n.includes("not found")||n.includes("未注册")?o.USER_NOT_FOUND:o.PRECONDITION_FAILED:e===s.ErrorType.INVALID_PASSWORD||e===s.ErrorType.INVALID_GRANT||e===s.ErrorType.INVALID_VERIFICATION_CODE||e===s.ErrorType.INVALID_USERNAME_OR_PASSWORD||e===s.ErrorType.INVALID_CREDENTIALS||e===s.ErrorType.WRONG_PASSWORD||e===s.ErrorType.UNAUTHENTICATED||e===s.ErrorType.INVALID_TWO_FACTOR||e===s.ErrorType.INVALID_TWO_FACTOR_RECOVERY||e===s.ErrorType.PASSWORD_NOT_SET||n.includes("密码不正确")||n.includes("password")||n.includes("invalid_password")||n.includes("凭据")||n.includes("credentials")||n.includes("验证码")||n.includes("verification")||n.includes("invalid_verification_code")||n.includes("invalid_username_or_password")||n.includes("username or password")||n.includes("用户名或密码")||n.includes("wrong password")||n.includes("incorrect password")?o.INVALID_CREDENTIALS:e===s.ErrorType.NOT_FOUND||e===s.ErrorType.USER_NOT_FOUND||n.includes("用户不存在")||n.includes("not found")||n.includes("user not found")||n.includes("no such user")||n.includes("user does not exist")?o.USER_NOT_FOUND:e===s.ErrorType.USER_BLOCKED||e===s.ErrorType.USER_PENDING||e===s.ErrorType.UNDER_REVIEW||e===s.ErrorType.INVALID_STATUS||n.includes("被封禁")||n.includes("blocked")||n.includes("pending")||n.includes("审核")||n.includes("review")||n.includes("locked")||n.includes("已锁定")?o.USER_STATUS_ABNORMAL:e===s.ErrorType.SERVER_ERROR||e===s.ErrorType.UNAVAILABLE||e===s.ErrorType.TEMPORARILY_UNAVAILABLE||e===s.ErrorType.INTERNAL||e===s.ErrorType.UNREACHABLE||e===s.ErrorType.DEADLINE_EXCEEDED||e===s.ErrorType.DATA_LOSS||e===s.ErrorType.ABORTED||n.includes("network")||n.includes("timeout")||n.includes("timed out")||n.includes("超时")||n.includes("smtp is not set")||n.includes("sms sender does not config")?o.SERVICE_ERROR:e===s.ErrorType.INVALID_ARGUMENT||e===s.ErrorType.INVALID_REQUEST||e===s.ErrorType.INVALID_SCOPE||e===s.ErrorType.INVALID_REQUEST_URI||e===s.ErrorType.INVALID_REQUEST_OBJECT||i===s.AuthErrorCode.INVALID_ARGUMENT?o.INVALID_PARAMS:e===s.ErrorType.PERMISSION_DENIED||e===s.ErrorType.ACCESS_DENIED||e===s.ErrorType.UNAUTHORIZED_CLIENT?o.PROVIDER_NOT_ENABLED:o.UNKNOWN}catch(t){return e}}(c,i.status,i.errorCode),i.helpMessage=function(t,e){var r=(null==e?void 0:e.method)||"signIn",n={signInWithPassword:"「用户名密码登录」",signInAnonymously:"「匿名登录」",signInWithOtp:"「短信验证码登录」或「邮箱验证码登录」",signUp:"「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"对应的第三方身份源",signInWithIdToken:"对应的第三方身份源",signInWithOpenId:"「微信小程序 OpenID 登录」",signInWithPhoneAuth:"「微信小程序手机号授权登录」",signInWithCustomTicket:"「自定义登录」",getVerification:"「短信验证码登录」或「邮箱验证码登录」",verify:"「短信验证码登录」或「邮箱验证码登录」",verifyOtp:"「短信验证码登录」或「邮箱验证码登录」",resetPasswordForEmail:"「邮箱验证码登录」",reauthenticate:"「短信验证码登录」或「邮箱验证码登录」"}[r]||"对应的登录方式";switch(t){case o.PROVIDER_NOT_ENABLED:return"[CloudBase Auth] 登录方式未开启\n\n"+" 当前调用的 ".concat(r,"() 所需的登录方式尚未在云开发控制台启用。\n")+" 需要开启的登录方式:".concat(n,"\n")+"\n 请按以下步骤开启:\n"+" 1. 打开云开发控制台:".concat(a,"\n")+" 2. 选择对应的云开发环境\n 3. 进入「登录授权」页面,在「登录方式」或「身份源列表」中开启所需的登录方式\n\n 各登录方法与所需登录方式的对应关系:\n - signInWithPassword → 「用户名密码登录」\n - signInAnonymously → 「匿名登录」\n - signInWithOtp/signUp → 「短信验证码登录」或「邮箱验证码登录」\n - signInWithOAuth/signInWithIdToken → 对应的第三方身份源\n\n 如使用 CLI/MCP 工具,可通过 auth 工具查询和配置身份源状态。\n"+" 更多帮助请参考文档:".concat(u);case o.INVALID_CREDENTIALS:return"[CloudBase Auth] 凭据验证失败\n\n"+" 调用 ".concat(r,"() 时凭据校验未通过。\n")+"\n 请按优先级逐项排查:\n 1. 确认用户名/邮箱/手机号是否拼写正确、格式完整\n 2. 确认密码是否正确(注意大小写、特殊字符、前后空格)\n 3. 确认用户账号确实存在(可通过 auth.isUsernameRegistered() 检查)\n 4. 确认凭据参数来源可靠(环境变量、配置文件中的值是否已正确设置)\n 5. 如使用加密登录(is_encrypt: true),请确认公钥版本正确\n\n 如忘记密码,可通过 auth.resetPasswordForEmail() 重置密码。\n\n 提示:如果是 AI agent / 自动化测试场景,请确认 ENV_ID、USERNAME、PASSWORD\n 等环境变量已正确传入,且对应用户已在目标环境中注册。";case o.USER_NOT_FOUND:return"[CloudBase Auth] 用户不存在\n\n 请检查以下项目:\n 1. 确认用户名/邮箱/手机号是否正确\n 2. 确认是在正确的云开发环境(envId)下操作\n 3. 如果是新用户,请先通过 auth.signUp() 注册\n"+" 4. 也可在云开发控制台手动创建用户:".concat(a,"\n")+"\n 提示:不同环境(开发/测试/生产)的用户库是隔离的,请确认 envId 正确。";case o.USER_STATUS_ABNORMAL:return"[CloudBase Auth] 用户状态异常\n\n 当前用户账号可能处于以下状态之一:\n - 账号已被封禁\n - 账号正在审核中\n - 账号已被锁定(多次密码错误)\n\n"+" 请联系管理员在云开发控制台检查用户状态:".concat(a);case o.SERVICE_ERROR:return"[CloudBase Auth] 服务异常\n\n 请检查以下项目:\n 1. 网络连接是否正常\n 2. 云开发环境是否正常运行\n 3. 稍后重试,如持续失败请联系技术支持\n\n 提示:如果是超时错误,请检查网络环境和请求频率。\n 常见服务端错误:smtp 未配置、短信服务未配置、wedaapis 未设置等。";case o.INVALID_PARAMS:return"[CloudBase Auth] 参数错误\n\n 请检查传入的参数是否符合要求:\n - 不能同时输入手机号和邮箱\n - 手机号格式需正确(如 +86 开头)\n - 必须提供手机号或邮箱\n\n"+" 参考 API 文档确认各参数的格式和约束:".concat(u);case o.AUTH_METHOD_MISMATCH:return"[CloudBase Auth] 登录方式不匹配\n\n"+" 调用 ".concat(r,"() 时遇到错误,可能原因:\n")+" - 匿名登录失败后尝试了用户名密码登录,但凭据不正确或用户不存在\n - 应使用匿名登录但传入了密码参数\n - 应使用密码登录但未传入正确的凭据\n\n 建议:\n 1. 明确当前场景需要的登录方式:\n - 无需用户注册 → auth.signInAnonymously()\n - 有用户名和密码 → auth.signInWithPassword({ username, password })\n - 第三方平台 → auth.signInWithOAuth({ provider })\n 2. 不要在同一流程中混合使用不同的登录方式\n 3. 每种登录方式需要在控制台开启对应的身份源\n"+" 4. 控制台地址:".concat(a);case o.RATE_LIMITED:return"[CloudBase Auth] 发送频率受限\n\n 验证码发送过于频繁,已触发频率限制。\n\n 限制规则:\n - 手机号:每分钟最多 1 条,每天有上限\n - 邮箱:每分钟有上限,每天有上限(默认 50 条)\n\n 建议:\n 1. 检查 error.retryAfter 获取建议等待时间\n 2. 在 UI 中显示倒计时,防止用户重复点击\n 3. 如业务需要更高频率,请联系技术支持调整限额";case o.CAPTCHA_REQUIRED:return"[CloudBase Auth] 需要滑块验证码\n\n 当前操作触发了风控策略,需要完成滑块验证。\n\n 处理方式:\n 1. 调用滑块验证码 SDK 展示验证组件\n 2. 用户完成验证后,将 captcha_token 附带到请求中重新发送\n 3. 可通过 getVerification 的 options.withCaptcha 参数自动携带验证码";case o.CAPTCHA_INVALID:return"[CloudBase Auth] 滑块验证码校验失败\n\n 提交的验证码 token 校验未通过(可能已过期或 client_id 不匹配)。\n\n 处理方式:\n 1. 刷新滑块验证码,让用户重新验证\n 2. 确认 captcha 组件初始化的 client_id 与认证配置一致";case o.MFA_REQUIRED:return"[CloudBase Auth] 需要 MFA 验证\n\n 当前操作要求用户绑定手机号进行多因素认证 (MFA)。\n\n 处理方式:\n 1. 引导用户进入手机号绑定流程\n 2. 绑定完成后重新执行原操作\n 3. error 中可能包含 MFA 详情信息";case o.PRECONDITION_FAILED:return"[CloudBase Auth] 前置条件不满足\n\n 当前操作的前置条件不满足,常见原因:\n - 该手机号/邮箱已被其他账号绑定\n - 目标用户不存在或已存在(与 target 参数冲突)\n - 当前邮箱/手机号未注册用户\n\n 请根据 error.message 中的具体描述处理。";case o.VERIFICATION_FAILED:return'[CloudBase Auth] 验证码校验失败\n\n 验证码验证未通过,常见原因:\n - 验证码已过期(通常有效期为几分钟)\n - 验证码输入不正确\n - verification_id 无效或已被使用\n - 验证码不属于当前项目(project id does not match)\n\n 处理方式:\n 1. 提示用户"验证码已过期或不正确,请重新获取"\n 2. 调用 getVerification() 重新发送验证码\n 3. 确保 verification_id 与最新发送的验证码对应\n\n 注意:每次重新发送验证码后,之前的 verification_id 即失效。';default:return"[CloudBase Auth] 操作失败\n\n 如果问题持续存在,建议:\n"+" 1. 检查云开发控制台的认证配置:".concat(a,"\n")+" 2. 到官方问答社区提问:https://cnb.cool/tencent/cloud/cloudbase/community/-/issues\n"+" 3. 查阅文档:".concat(u)}}(i.category,r),i.loginMethodHint=(n=null==r?void 0:r.method)&&{signInWithPassword:"当前使用「用户名密码登录」,需确保:\n ✓ 控制台已开启「用户名密码登录」\n ✓ 用户已注册且凭据正确\n 如果不需要用户系统,建议改用 auth.signInAnonymously()",signInAnonymously:"当前使用「匿名登录」,需确保:\n ✓ 控制台已开启「匿名登录」\n 注意:匿名用户无需用户名密码,适用于快速体验或临时访问场景",signInWithOtp:"当前使用「OTP 验证码登录」,需确保:\n ✓ 控制台已开启「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"当前使用「第三方 OAuth 登录」,需确保:\n ✓ 控制台已配置并开启对应的第三方身份源"}[n]||"",i.category===o.RATE_LIMITED&&(i.retryAfter=e.retry_after||e.retryAfter||void 0),i}return i(e,t),e.prototype.toJSON=function(){return{name:this.name,message:this.message,code:this.code,errorCode:this.errorCode,status:this.status,requestId:this.requestId,category:this.category,retryAfter:this.retryAfter}},e}(Error);e.AuthError=c,e.isAuthError=function(t){return"object"==typeof t&&null!==t&&"__isAuthError"in t}},949:(t,e)=>{var r,n,i,o,s;Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_NODE_ACCESS_SCOPE=e.OAUTH_TYPE=e.EVENTS=e.AUTH_STATE_CHANGED_TYPE=e.LOGIN_STATE_CHANGED_TYPE=e.AuthErrorCode=e.ErrorType=e.VerificationUsages=e.ApiUrlsV2=e.ApiUrls=e.AUTH_API_PREFIX=void 0,e.AUTH_API_PREFIX="/auth",(s=e.ApiUrls||(e.ApiUrls={})).AUTH_SIGN_UP_URL="/v1/signup",s.AUTH_TOKEN_URL="/v1/token",s.AUTH_REVOKE_URL="/v1/revoke",s.WEDA_USER_URL="/v1/plugin/weda/userinfo",s.AUTH_RESET_PASSWORD="/v1/reset",s.AUTH_GET_DEVICE_CODE="/v1/device/code",s.CHECK_USERNAME="/v1/checkUsername",s.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",s.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",s.AUTH_SIGN_IN_URL="/v1/signin",s.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",s.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",s.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",s.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",s.PROVIDER_TOKEN_URL="/v1/provider/token",s.PROVIDER_URI_URL="/v1/provider/uri",s.USER_ME_URL="/v1/user/me",s.AUTH_SIGNOUT_URL="/v1/user/signout",s.USER_QUERY_URL="/v1/user/query",s.USER_PRIFILE_URL="/v1/user/profile",s.USER_BASIC_EDIT_URL="/v1/user/basic/edit",s.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",s.PROVIDER_LIST="/v1/user/provider",s.PROVIDER_BIND_URL="/v1/user/provider/bind",s.PROVIDER_UNBIND_URL="/v1/user/provider",s.CHECK_PWD_URL="/v1/user/sudo",s.SUDO_URL="/v1/user/sudo",s.BIND_CONTACT_URL="/v1/user/contact",s.AUTH_SET_PASSWORD="/v1/user/password",s.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",s.AUTHORIZE_URL="/v1/user/authorize",s.AUTHORIZE_INFO_URL="/v1/user/authorize/info",s.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",s.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",s.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",s.VERIFICATION_URL="/v1/verification",s.VERIFY_URL="/v1/verification/verify",s.CAPTCHA_DATA_URL="/v1/captcha/data",s.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",s.GET_CAPTCHA_URL="/v1/captcha/init",s.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",s.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status",(o=e.ApiUrlsV2||(e.ApiUrlsV2={})).AUTH_SIGN_IN_URL="/v2/signin/username",o.AUTH_TOKEN_URL="/v2/token",o.USER_ME_URL="/v2/user/me",o.VERIFY_URL="/v2/signin/verificationcode",o.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",o.AUTH_PUBLIC_KEY="/v2/signin/publichkey",o.AUTH_RESET_PASSWORD="/v2/signin/password/update",(i=e.VerificationUsages||(e.VerificationUsages={})).REGISTER="REGISTER",i.SIGN_IN="SIGN_IN",i.PASSWORD_RESET="PASSWORD_RESET",i.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",i.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE",(n=e.ErrorType||(e.ErrorType={})).UNREACHABLE="unreachable",n.LOCAL="local",n.CANCELLED="cancelled",n.UNKNOWN="unknown",n.UNAUTHENTICATED="unauthenticated",n.RESOURCE_EXHAUSTED="resource_exhausted",n.FAILED_PRECONDITION="failed_precondition",n.INVALID_ARGUMENT="invalid_argument",n.DEADLINE_EXCEEDED="deadline_exceeded",n.NOT_FOUND="not_found",n.ALREADY_EXISTS="already_exists",n.PERMISSION_DENIED="permission_denied",n.ABORTED="aborted",n.OUT_OF_RANGE="out_of_range",n.UNIMPLEMENTED="unimplemented",n.INTERNAL="internal",n.UNAVAILABLE="unavailable",n.DATA_LOSS="data_loss",n.INVALID_PASSWORD="invalid_password",n.PASSWORD_NOT_SET="password_not_set",n.INVALID_STATUS="invalid_status",n.USER_PENDING="user_pending",n.USER_BLOCKED="user_blocked",n.INVALID_VERIFICATION_CODE="invalid_verification_code",n.TWO_FACTOR_REQUIRED="two_factor_required",n.INVALID_TWO_FACTOR="invalid_two_factor",n.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",n.UNDER_REVIEW="under_review",n.INVALID_REQUEST="invalid_request",n.UNAUTHORIZED_CLIENT="unauthorized_client",n.ACCESS_DENIED="access_denied",n.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",n.INVALID_SCOPE="invalid_scope",n.INVALID_GRANT="invalid_grant",n.SERVER_ERROR="server_error",n.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",n.INTERACTION_REQUIRED="interaction_required",n.LOGIN_REQUIRED="login_required",n.ACCOUNT_SELECTION_REQUIRED="account_selection_required",n.CONSENT_REQUIRED="consent_required",n.INVALID_REQUEST_URI="invalid_request_uri",n.INVALID_REQUEST_OBJECT="invalid_request_object",n.REQUEST_NOT_SUPPORTED="request_not_supported",n.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",n.REGISTRATION_NOT_SUPPORTED="registration_not_supported",n.CAPTCHA_REQUIRED="captcha_required",n.CAPTCHA_INVALID="captcha_invalid",n.PROVIDER_NOT_ENABLED="provider_not_enabled",n.LOGIN_METHOD_DISABLED="login_method_disabled",n.INVALID_USERNAME_OR_PASSWORD="invalid_username_or_password",n.INVALID_CREDENTIALS="invalid_credentials",n.WRONG_PASSWORD="wrong_password",n.USER_NOT_FOUND="user_not_found",n.MFA_PHONE_REQUIRED="mfa_phone_required",n.LOGIN_TYPE_DISABLED="login_type_disabled",n.PROVIDER_ERROR="provider_error",(r=e.AuthErrorCode||(e.AuthErrorCode={}))[r.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",r[r.NOT_FOUND=5]="NOT_FOUND",r[r.PERMISSION_DENIED=7]="PERMISSION_DENIED",r[r.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",r[r.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",r[r.ABORTED=10]="ABORTED",r[r.UNIMPLEMENTED=12]="UNIMPLEMENTED",r[r.INTERNAL=13]="INTERNAL",r[r.UNAVAILABLE=14]="UNAVAILABLE",r[r.UNAUTHENTICATED=16]="UNAUTHENTICATED",r[r.CAPTCHA_REQUIRED=4001]="CAPTCHA_REQUIRED",r[r.CAPTCHA_INVALID=4002]="CAPTCHA_INVALID",r[r.PROVIDER_ERROR=4019]="PROVIDER_ERROR",r[r.UNAUTHORIZED_CLIENT=4022]="UNAUTHORIZED_CLIENT",r[r.MFA_PHONE_REQUIRED=4042]="MFA_PHONE_REQUIRED",r[r.LOGIN_TYPE_DISABLED=4045]="LOGIN_TYPE_DISABLED",e.LOGIN_STATE_CHANGED_TYPE={SIGN_OUT:"sign_out",SIGN_IN:"sign_in",CREDENTIALS_ERROR:"credentials_error"},e.AUTH_STATE_CHANGED_TYPE={SIGNED_OUT:"SIGNED_OUT",SIGNED_IN:"SIGNED_IN",INITIAL_SESSION:"INITIAL_SESSION",PASSWORD_RECOVERY:"PASSWORD_RECOVERY",TOKEN_REFRESHED:"TOKEN_REFRESHED",USER_UPDATED:"USER_UPDATED",BIND_IDENTITY:"BIND_IDENTITY"},e.EVENTS={LOGIN_STATE_CHANGED:"loginStateChanged",AUTH_STATE_CHANGED:"authStateChanged"},e.OAUTH_TYPE={SIGN_IN:"sign_in",BIND_IDENTITY:"bind_identity"},e.DEFAULT_NODE_ACCESS_SCOPE="node-sdk-scope"},538:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0})},84: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.openURIWithCallback=void 0;var s=r(689),a=r(616),u=function(t,e){var r;return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];clearTimeout(r),r=setTimeout(function(){return t.apply(null,n)},e)}},c=new s.CloudbaseEventEmitter,l="resolveCaptchaData",h="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",d="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",f="background:#6c757d;cursor:not-allowed";e.openURIWithCallback=function(t,e){return i(void 0,void 0,Promise,function(){var r,s,p,v;return o(this,function(g){return r=(0,a.parseCaptcha)(t),s=r.captchaData,p=r.state,v=r.token,function(t){var e=t.oauthInstance,r=t.captchaState,s="captcha-image",a=function(){return i(void 0,void 0,void 0,function(){var t,i;return o(this,function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,e.createCaptchaData({state:r.state})];case 1:return t=o.sent(),r=n(n({},r),{captchaData:t.data,token:t.token}),document.getElementById(s).src=t.data,[3,3];case 2:return i=o.sent(),console.error("刷新图形验证码失败",i),[3,3];case 3:return[2]}})})},p=function(t,e,r){var n=document.createElement(t);return e&&(n.style.cssText=e),r&&(n.textContent=r),n},v=p("div","position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999"),g=p("div","position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:320px;padding:20px;background:#fff;border-radius:8px;box-shadow:0 0 10px rgba(0,0,0,0.2);z-index:1000");g.appendChild(p("p","margin-bottom:15px","请输入你看到的字符:"));var _=p("div","display:flex;align-items:center;justify-content:space-between;margin-bottom:15px"),y=p("img","width:100%;height:auto;border:1px solid #eee");y.id=s,y.src=r.captchaData,_.appendChild(y);var E=p("button",h,"刷新");E.onclick=u(function(){return i(void 0,void 0,void 0,function(){return o(this,function(t){switch(t.label){case 0:E.textContent="加载中...",E.disabled=!0,E.style.cssText="".concat(h,";").concat(f),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,a()];case 2:return t.sent(),[3,4];case 3:return E.textContent="刷新",E.disabled=!1,E.style.cssText=h,[7];case 4:return[2]}})})},500),_.appendChild(E),g.appendChild(_);var m=p("input","width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px");m.type="text",m.placeholder="输入字符",m.maxLength=4,g.appendChild(m);var b=p("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");g.appendChild(b);var T=function(t){b.textContent=t,b.style.display="block"},I=p("button",d,"确定");I.onclick=u(function(){return i(void 0,void 0,void 0,function(){var t,n,i,s;return o(this,function(o){switch(o.label){case 0:if(!(t=m.value.trim()))return T("请输入字符"),[2];b.style.display="none",I.textContent="验证中...",I.disabled=!0,I.style.cssText="".concat(d,";").concat(f),o.label=1;case 1:return o.trys.push([1,3,5,6]),[4,e.verifyCaptchaData({token:r.token,key:t})];case 2:return n=o.sent(),c.fire(l,n),console.log("图形验证码校验成功"),document.body.removeChild(v),document.body.removeChild(g),[3,6];case 3:return i=o.sent(),console.error("图形验证码校验失败",i),s=i.error_description||"图形验证码校验失败",T(s),m.value="",m.focus(),[4,a()];case 4:return o.sent(),[3,6];case 5:return I.textContent="确定",I.disabled=!1,I.style.cssText=d,[7];case 6:return[2]}})})},500),g.appendChild(I),document.body.appendChild(v),document.body.appendChild(g)}({oauthInstance:e,captchaState:{captchaData:s,state:p,token:v}}),[2,new Promise(function(t){console.log("等待图形验证码校验结果..."),c.on(l,function(e){t(null==e?void 0:e.data)})})]})})}},462:function(t,e,r){var n=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())})},i=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.Captcha=void 0;var o=r(949),s=r(257),a=r(425),u=r(84),c=function(){function t(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=s.defaultStorage),th