@cloudbase/oauth 3.3.6 → 3.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/apis.js +18 -6
- package/dist/cjs/auth/models.d.ts +2 -0
- package/dist/cjs/auth/models.js +1 -1
- package/dist/esm/auth/apis.js +13 -1
- package/dist/esm/auth/models.d.ts +2 -0
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -4
- package/src/auth/apis.ts +15 -0
- package/src/auth/models.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcboauth",[],t):"object"==typeof exports?exports.tcboauth=t():e.tcboauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var e={3:(e,t,r)=>{r.r(t),r.d(t,{getEncryptInfo:()=>o});const n=void 0;var i=r(912),o=function(){var{publicKey:e="",payload:t={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e)return"";try{var r=(0,i.I)(t),o=new n;o.setPublicKey(e);var a=o.encryptLong("object"==typeof r?JSON.stringify(r):r);return a}catch(e){console.error("encrypt error:",e)}return""}},912:(e,t,r)=>{r.d(t,{I:()=>n,y:()=>i});var n=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},r=null==e?"NullOrUndefined":Object.prototype.toString.call(e).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return e.slice();switch(r){case"Object":return t(Object.create(Object.getPrototypeOf(e)));case"Array":return t([]);case"Date":return new Date(e.valueOf());case"RegExp":return new RegExp(e.source,(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.sticky?"y":"")+(e.unicode?"u":""));default:return e}},i=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMMUNITY_SITE_URL=t.IS_DEBUG_MODE=t.getProtocol=t.setProtocol=t.getSdkName=t.setSdkName=void 0;var r="@cloudbase/js-sdk";t.setSdkName=function(e){r=e},t.getSdkName=function(){return r};var n="https:";t.setProtocol=function(e){n=e},t.getProtocol=function(){return n},t.IS_DEBUG_MODE=("undefined"==typeof process||process.env,!1),t.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},205:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ERRORS=void 0,t.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.OATUH_LOGINTYPE=void 0,i(r(946),t),i(r(205),t),t.OATUH_LOGINTYPE="constants"},689:function(e,t,r){var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),o=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.removeEventListener=t.activateEvent=t.addEventListener=t.CloudbaseEventEmitter=t.IErrorEvent=t.CloudbaseEvent=void 0;var a=r(616);var s=function(e,t){this.data=t||null,this.name=e};t.CloudbaseEvent=s;var c=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return i(t,e),t}(s);t.IErrorEvent=c;var u=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if((0,a.isInstanceOf)(e,c))return console.error(e.error),this;var r=(0,a.isString)(e)?new s(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,u=this.listeners[n]?o([],this.listeners[n],!0):[];i<u.length;i++){u[i].call(this,r)}}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();t.CloudbaseEventEmitter=u;var l=new u;t.addEventListener=function(e,t){l.on(e,t)},t.activateEvent=function(e,t){void 0===t&&(t={}),l.fire(e,t)},t.removeEventListener=function(e,t){l.off(e,t)}},616:function(e,t,r){var n=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.parseCaptcha=t.parseQueryString=t.transformPhone=t.sleep=t.printGroupLog=t.throwError=t.printInfo=t.printError=t.printWarn=t.execCallback=t.createPromiseCallback=t.removeParam=t.getHash=t.getQuery=t.toQueryString=t.formatUrl=t.generateRequestId=t.genSeqId=t.isFormData=t.isInstanceOf=t.isNull=t.isPalinObject=t.isUndefined=t.isString=t.isArray=void 0;var i=r(794);t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isPalinObject=function(e){return"[object Object]"===Object.prototype.toString.call(e)},t.isNull=function(e){return"[object Null]"===Object.prototype.toString.call(e)},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.generateRequestId=function(){var e=(new Date).getTime(),t=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var n=16*Math.random();return e>0?(n=(e+n)%16|0,e=Math.floor(e/16)):(n=(t+n)%16|0,t=Math.floor(t/16)),("x"===r?n:7&n|8).toString(16)}))},t.formatUrl=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),i="";return Object.keys(r).forEach((function(e){""===i?!n&&(t+="?"):i+="&",i+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=i)?t:"".concat(e).concat(t)},t.toQueryString=function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")},t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var r=t||decodeURIComponent(window.location.search),n=new RegExp("(^|&)".concat(e,"=([^&]*)(&|$)")),i=r.substr(r.indexOf("?")+1).match(n);return null!=i?i[2]:""};t.getHash=function(e){if("undefined"==typeof window)return"";var t=window.location.hash.match(new RegExp("[#?&/]".concat(e,"=([^&#]*)")));return t?t[1]:""},t.removeParam=function(e,t){var r=t.split("?")[0],n=[],i=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==i){for(var o=(n=i.split("&")).length-1;o>=0;o-=1)n[o].split("=")[0]===e&&n.splice(o,1);r="".concat(r,"?").concat(n.join("&"))}return r},t.createPromiseCallback=function(){var e={};if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var r=new Promise((function(t,r){e=function(e,n){return e?r(e):t(n)}}));return e.promise=r,e},t.execCallback=function(e,t,r){if(void 0===r&&(r=null),e&&"function"==typeof e)return e(t,r);if(t)throw t;return r},t.printWarn=function(e,t){console.warn("[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t))},t.printError=function(e,t){console.error({code:e,msg:"[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t)})},t.printInfo=function(e,t){console.log("[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t))},t.throwError=function(e,t){throw new Error(JSON.stringify({code:e,msg:"[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t)}))},t.printGroupLog=function(e){var t,r=e.title,n=e.subtitle,i=void 0===n?"":n,o=e.content,a=void 0===o?[]:o,s=e.printTrace,c=void 0!==s&&s,u=e.collapsed;void 0!==u&&u?(console.groupCollapsed||console.error)(r,i):(console.group||console.error)(r,i);for(var l=0,d=a;l<d.length;l++){var h=d[l],f=h.type,p=h.body;switch(f){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}c&&(console.trace||console.log)("stack trace:"),null===(t=console.groupEnd)||void 0===t||t.call(console)};t.sleep=function(e){return void 0===e&&(e=0),new Promise((function(t){return setTimeout(t,e)}))},t.transformPhone=function(e){return"+86".concat(e)};t.parseQueryString=function(e){e=e.replace(/^\?/,"");var t={};return e.split("&").forEach((function(e){var r=e.split("="),n=r[0],i=r[1];n=decodeURIComponent(n),i=decodeURIComponent(i),n&&(t[n]?Array.isArray(t[n])?t[n].push(i):t[n]=[t[n],i]:t[n]=i)})),t},t.parseCaptcha=function(e){var r={},i=e.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){e=i[1];var o=i[2];o&&(r=(0,t.parseQueryString)(o))}var a=r.token,s=n(r,["token"]);return/^data:/.test(e)&&!a?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(e)}:a?{state:s.state,token:a,captchaData:e}:{error:"unimplemented",error_description:"need to impl captcha data"}}}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{AUTH_API_PREFIX:()=>s,AUTH_STATE_CHANGED_TYPE:()=>l,Auth:()=>ze,AuthError:()=>He,AuthErrorCategory:()=>ke,CloudbaseOAuth:()=>Xe,DEFAULT_NODE_ACCESS_SCOPE:()=>f,EVENTS:()=>d,LOGIN_STATE_CHANGED_TYPE:()=>u,OAUTH_TYPE:()=>h,authModels:()=>e,weAppJwtDecodeAll:()=>b});var e={};r.r(e);var t,i,o,a,s="/auth";!function(e){e.AUTH_SIGN_UP_URL="/v1/signup",e.AUTH_TOKEN_URL="/v1/token",e.AUTH_REVOKE_URL="/v1/revoke",e.WEDA_USER_URL="/v1/plugin/weda/userinfo",e.AUTH_RESET_PASSWORD="/v1/reset",e.AUTH_GET_DEVICE_CODE="/v1/device/code",e.CHECK_USERNAME="/v1/checkUsername",e.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",e.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",e.AUTH_SIGN_IN_URL="/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",e.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",e.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",e.PROVIDER_TOKEN_URL="/v1/provider/token",e.PROVIDER_URI_URL="/v1/provider/uri",e.USER_ME_URL="/v1/user/me",e.AUTH_SIGNOUT_URL="/v1/user/signout",e.USER_QUERY_URL="/v1/user/query",e.USER_PRIFILE_URL="/v1/user/profile",e.USER_BASIC_EDIT_URL="/v1/user/basic/edit",e.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",e.PROVIDER_LIST="/v1/user/provider",e.PROVIDER_BIND_URL="/v1/user/provider/bind",e.PROVIDER_UNBIND_URL="/v1/user/provider",e.CHECK_PWD_URL="/v1/user/sudo",e.SUDO_URL="/v1/user/sudo",e.BIND_CONTACT_URL="/v1/user/contact",e.AUTH_SET_PASSWORD="/v1/user/password",e.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",e.AUTHORIZE_URL="/v1/user/authorize",e.AUTHORIZE_INFO_URL="/v1/user/authorize/info",e.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",e.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",e.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",e.VERIFICATION_URL="/v1/verification",e.VERIFY_URL="/v1/verification/verify",e.CAPTCHA_DATA_URL="/v1/captcha/data",e.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",e.GET_CAPTCHA_URL="/v1/captcha/init",e.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",e.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(t||(t={})),function(e){e.AUTH_SIGN_IN_URL="/v2/signin/username",e.AUTH_TOKEN_URL="/v2/token",e.USER_ME_URL="/v2/user/me",e.VERIFY_URL="/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(i||(i={})),function(e){e.REGISTER="REGISTER",e.SIGN_IN="SIGN_IN",e.PASSWORD_RESET="PASSWORD_RESET",e.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",e.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(o||(o={})),function(e){e.UNREACHABLE="unreachable",e.LOCAL="local",e.CANCELLED="cancelled",e.UNKNOWN="unknown",e.UNAUTHENTICATED="unauthenticated",e.RESOURCE_EXHAUSTED="resource_exhausted",e.FAILED_PRECONDITION="failed_precondition",e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.INVALID_PASSWORD="invalid_password",e.PASSWORD_NOT_SET="password_not_set",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked",e.INVALID_VERIFICATION_CODE="invalid_verification_code",e.TWO_FACTOR_REQUIRED="two_factor_required",e.INVALID_TWO_FACTOR="invalid_two_factor",e.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",e.UNDER_REVIEW="under_review",e.INVALID_REQUEST="invalid_request",e.UNAUTHORIZED_CLIENT="unauthorized_client",e.ACCESS_DENIED="access_denied",e.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",e.INVALID_SCOPE="invalid_scope",e.INVALID_GRANT="invalid_grant",e.SERVER_ERROR="server_error",e.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",e.INTERACTION_REQUIRED="interaction_required",e.LOGIN_REQUIRED="login_required",e.ACCOUNT_SELECTION_REQUIRED="account_selection_required",e.CONSENT_REQUIRED="consent_required",e.INVALID_REQUEST_URI="invalid_request_uri",e.INVALID_REQUEST_OBJECT="invalid_request_object",e.REQUEST_NOT_SUPPORTED="request_not_supported",e.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",e.REGISTRATION_NOT_SUPPORTED="registration_not_supported",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.PROVIDER_NOT_ENABLED="provider_not_enabled",e.LOGIN_METHOD_DISABLED="login_method_disabled",e.INVALID_USERNAME_OR_PASSWORD="invalid_username_or_password",e.INVALID_CREDENTIALS="invalid_credentials",e.WRONG_PASSWORD="wrong_password",e.USER_NOT_FOUND="user_not_found"}(a||(a={}));var c,u={SIGN_OUT:"sign_out",SIGN_IN:"sign_in",CREDENTIALS_ERROR:"credentials_error"},l={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"},d={LOGIN_STATE_CHANGED:"loginStateChanged",AUTH_STATE_CHANGED:"authStateChanged"},h={SIGN_IN:"sign_in",BIND_IDENTITY:"bind_identity"},f="node-sdk-scope";function p(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}!function(e){e.CLIENT_ID="client_id",e.CLIENT_SECRET="client_secret",e.RESPONSE_TYPE="response_type",e.SCOPE="scope",e.STATE="state",e.REDIRECT_URI="redirect_uri",e.ERROR="error",e.ERROR_DESCRIPTION="error_description",e.ERROR_URI="error_uri",e.GRANT_TYPE="grant_type",e.CODE="code",e.ACCESS_TOKEN="access_token",e.TOKEN_TYPE="token_type",e.EXPIRES_IN="expires_in",e.USERNAME="username",e.PASSWORD="password",e.REFRESH_TOKEN="refresh_token"}(c||(c={}));var v=r(912);function _(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function y(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_(o,n,i,a,s,"next",e)}function s(e){_(o,n,i,a,s,"throw",e)}a(void 0)}))}}var g=new Map;class E{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",g=g||new Map}run(e,t){var r=this;return y((function*(){e="".concat(r.clientId,"_").concat(e);var n=g.get(e);return n||(n=new Promise((n,i)=>{y((function*(){try{yield r.runIdlePromise();var o=t();n(yield o)}catch(e){i(e)}finally{g.delete(e)}}))()}),g.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;var O=function(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!m.test(e))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var t;e+="==".slice(2-(3&e.length));for(var r,n,i="",o=0;o<e.length;)t=I.indexOf(e.charAt(o++))<<18|I.indexOf(e.charAt(o++))<<12|(r=I.indexOf(e.charAt(o++)))<<6|(n=I.indexOf(e.charAt(o++))),i+=64===r?String.fromCharCode(t>>16&255):64===n?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,255&t);return i};function S(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("Illegal base64url string!")}try{return function(e){return decodeURIComponent(O(e).replace(/(.)/g,e=>{var t=e.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0".concat(t)),"%".concat(t)}))}(t)}catch(e){return O(t)}}function b(e){if("string"!=typeof e)throw new Error("Invalid token specified");try{var t=e.split(".").map((e,t)=>2===t?e:JSON.parse(S(e)));return{claims:t[1],header:t[0],signature:t[2]}}catch(e){throw new Error("Invalid token specified: ".concat(e)?e.message:0)}}function R(){if("undefined"==typeof globalThis)return!1;var{wx:e}=globalThis;if(void 0===e)return!1;if(void 0===globalThis.Page)return!1;if(!e.getDeviceInfo)return!1;if(!e.getStorageSync)return!1;if(!e.setStorageSync)return!1;if(!e.connectSocket)return!1;if(!e.request)return!1;try{if(!e.getDeviceInfo())return!1;if("qq"===e.getDeviceInfo().platform)return!1}catch(e){return!1}return!0}var A=!1;function T(){A=A||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{R()||(A=A||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?T():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",T,!1))}catch($){}var C="@cloudbase/js-sdk";function w(){return C}var P="https:";"undefined"==typeof process||process.env;var N,U="INVALID_PARAMS",D="INVALID_OPERATION",L="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(N||(N={}));var x=function(){};function k(e,t){console.warn("[".concat(w(),"][").concat(e,"]:").concat(t))}var j,q=(j=function(e,t){return(j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}j(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),H=function(){return(H=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},V=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},M=function(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};!function(e){function t(t){var r=e.call(this)||this,n=t.timeout,i=t.timeoutMsg,o=t.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=i||"请求超时",r.restrictedMethods=o||["get","post","upload","download"],r}q(t,e),t.prototype.get=function(e){return this.request(H(H({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(H(H({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(H(H({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,i=e.method,o=e.headers,a=void 0===o?{}:o,s={post:"post",put:"put"}[null==i?void 0:i.toLowerCase()]||"put",c=new FormData;return"post"===s?(Object.keys(t).forEach((function(e){c.append(e,t[e])})),c.append("key",n),c.append("file",r),this.request(H(H({},e),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(H(H({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return V(this,void 0,void 0,(function(){var t,r,n,i;return M(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.get(H(H({},e),{headers:{},responseType:"blob"}))];case 1:return t=o.sent().data,r=window.URL.createObjectURL(new Blob([t])),n=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(i=document.createElement("a")).href=r,i.setAttribute("download",n),i.style.display="none",document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i),[3,3];case 2:return o.sent(),[3,3];case 3:return[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}}))}))},t.prototype.fetch=function(e){var t;return V(this,void 0,void 0,(function(){var r,n,i,o,a,s,c,u,l,d,h,f,p,v=this;return M(this,(function(_){switch(_.label){case 0:return r=new AbortController,n=e.url,i=e.enableAbort,o=void 0!==i&&i,a=e.stream,s=void 0!==a&&a,c=e.signal,u=e.timeout,l=e.shouldThrowOnError,d=void 0===l||l,h=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),f=null,o&&h&&(f=setTimeout((function(){console.warn(v.timeoutMsg),r.abort(new Error(v.timeoutMsg))}),h)),[4,fetch(n,H(H({},e),{signal:r.signal})).then((function(e){return V(v,void 0,void 0,(function(){var t,r,n;return M(this,(function(i){switch(i.label){case 0:return clearTimeout(f),d?e.ok?(t=e,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,e.json()];case 2:t=n.apply(r,[i.sent()]),i.label=3;case 3:return[2,t];case 4:return[2,e]}}))}))})).catch((function(e){if(clearTimeout(f),d)return Promise.reject(e)}))];case 1:return p=_.sent(),[2,{data:s?p.body:(null===(t=p.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers}]}}))}))},t.prototype.request=function(e,t){var r=this;void 0===t&&(t=!1);var n=String(e.method).toLowerCase()||"get";return new Promise((function(i){var o,a,s,c=e.url,u=e.headers,l=void 0===u?{}:u,d=e.data,h=e.responseType,f=e.withCredentials,p=e.body,v=e.onUploadProgress,_=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),i="";return Object.keys(r).forEach((function(e){""===i?!n&&(t+="?"):i+="&",i+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=i)?t:"".concat(e).concat(t)}(P,c,"get"===n?d:{}),y=new XMLHttpRequest;y.open(n,_),h&&(y.responseType=h),Object.keys(l).forEach((function(e){y.setRequestHeader(e,l[e])})),v&&y.upload.addEventListener("progress",v),y.onreadystatechange=function(){var e={};if(4===y.readyState){var t=y.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};t.forEach((function(e){var t=e.split(": "),n=t.shift().toLowerCase(),i=t.join(": ");r[n]=i})),e.header=r,e.statusCode=y.status;try{e.data="blob"===h?y.response:JSON.parse(y.responseText)}catch(t){e.data="blob"===h?y.response:y.responseText}clearTimeout(o),i(e)}},t&&r.timeout&&(o=setTimeout((function(){console.warn(r.timeoutMsg),y.abort()}),r.timeout)),s=d,a="[object FormData]"===Object.prototype.toString.call(s)?d:"application/x-www-form-urlencoded"===l["content-type"]?function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")}(d):p||(d?JSON.stringify(d):void 0),f&&(y.withCredentials=!0),y.send(a)}))}}((function(){}));var G;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(G||(G={}));var W=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),B=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},F=function(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},K=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return W(t,e),t.prototype.setItem=function(e,t){this.root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this.root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this.root.tcbCacheObject[e]},t.prototype.clear=function(){delete this.root.tcbCacheObject},t}(x);!function(){function e(e){this.keys={};var t=e.persistence,r=e.platformInfo,n=void 0===r?{}:r,i=e.keys,o=void 0===i?{}:i;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=function(e,t){switch(e){case"local":return t.localStorage?t.localStorage:(k(U,"localStorage is not supported on current platform"),new K(t.root));case"none":return new K(t.root);default:return t.localStorage?t.localStorage:(k(U,"localStorage is not supported on current platform"),new K(t.root))}}(this.persistenceTag,this.platformInfo.adapter),this.keys=o)}Object.defineProperty(e.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),e.prototype.setStore=function(e,t,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(n))}catch(e){throw new Error(JSON.stringify({code:L,msg:"[".concat(w(),"][").concat(L,"]setStore failed"),info:e}))}}else k(D,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return B(this,void 0,void 0,(function(){var n;return F(this,(function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),n={version:r||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(n))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}}))}))},e.prototype.getStore=function(e,t){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return process.env.tcb_token;if(!this.storage)return""}catch(e){return""}t=t||"localCachev1";var n=this.storage.getItem(e);return n&&n.indexOf(t)>=0?JSON.parse(n).content:""}k(D,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return B(this,void 0,void 0,(function(){var n;return F(this,(function(i){switch(i.label){case 0:try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return[2,process.env.tcb_token];if(!this.storage)return[2,""]}catch(e){return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return(n=i.sent())&&n.indexOf(t)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):k(D,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return B(this,void 0,void 0,(function(){return F(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Y=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),z=function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};var Q=function(e,t){this.data=t||null,this.name=e},J=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Y(t,e),t}(Q),Z=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if(e instanceof J)return console.error(e.error),this;var r="string"==typeof e?new Q(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,o=this.listeners[n]?z([],this.listeners[n],!0):[];i<o.length;i++){o[i].call(this,r)}}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();new Z;var X=new Z;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");!function(){function e(){var e=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(t,r){"abort"===t&&e.listeners.push(r)}}}e.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach((function(e){return e()})))}}();function $(e){this.message=e}$.prototype=new Error,$.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function ee(e){this.message=e}ee.prototype=new Error,ee.prototype.name="InvalidTokenError";function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function re(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?te(Object(r),!0).forEach((function(t){ne(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):te(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ne(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ie(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function oe(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){ie(o,n,i,a,s,"next",e)}function s(e){ie(o,n,i,a,s,"throw",e)}a(void 0)}))}}var ae=function(){var e=oe((function*(e,t){var r=null,n=null;try{var i=Object.assign({},t);i.method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var o=yield fetch(e,i),s=yield o.json();null!=s&&s.error?(n=s).error_uri=new URL(e).pathname:r=s}catch(t){n={error:a.UNREACHABLE,error_description:t.message,error_uri:new URL(e).pathname}}if(n)throw n;return r}));return function(t,r){return e.apply(this,arguments)}}();var se=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return oe((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return oe((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return oe((function*(){window.localStorage.setItem("".concat(e).concat(r._env),t)}))()}getItemSync(e){return window.localStorage.getItem("".concat(e).concat(this._env))}removeItemSync(e){window.localStorage.removeItem("".concat(e).concat(this._env))}setItemSync(e,t){window.localStorage.setItem("".concat(e).concat(this._env),t)}};function ce(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class ue{constructor(e){this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new E({clientId:this.clientId}),this.credentials=e.credentials||null}getStorageCredentialsSync(){var e=null,t=this.storage.getItemSync(this.tokenSectionName);if(null!=t)try{var r;null!==(r=e=JSON.parse(t))&&void 0!==r&&r.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(t){this.storage.removeItem(this.tokenSectionName),e=null}return e}setCredentials(e){var t=this;return oe((function*(){if(null!=e&&e.expires_in){if(null!=e&&e.expires_at||(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30))),t.storage){var r=JSON.stringify(e);yield t.storage.setItem(t.tokenSectionName,r)}t.credentials=e}else t.storage&&(yield t.storage.removeItem(t.tokenSectionName)),t.credentials=null}))()}setAccessKeyCredentials(e){this.accessKeyCredentials=e,e.scope===f&&(this.credentials=e)}getCredentials(){var e=this;return oe((function*(){return e.singlePromise.run("getCredentials",oe((function*(){if(ce(e.credentials)){var{credentials:t,isAccessKeyCredentials:r}=yield e.getStorageCredentials();if(r)return t;e.credentials=t}return e.credentials})))}))()}getStorageCredentials(){var e=this;return oe((function*(){return e.singlePromise.run("_getStorageCredentials",oe((function*(){var t=null,r=!1,n=yield e.storage.getItem(e.tokenSectionName);if(n)try{var i;null!==(i=t=JSON.parse(n))&&void 0!==i&&i.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}else t=e.accessKeyCredentials||null,r=!0;return{credentials:t,isAccessKeyCredentials:r}})))}))()}}class le{constructor(e){var t;this.initializePromise=null,this.lockAcquired=!1,this.pendingInLock=[],this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.apiPath=e.apiPath||s,this.clientId=e.clientId,this.i18n=e.i18n,this.eventBus=e.eventBus,this.singlePromise=new E({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,le.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=ae,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||se,this.localCredentials=new ue({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage,clientId:e.clientId}),this.clientSecret=e.clientSecret,e.clientId&&(this.basicAuth="Basic ".concat(function(e){for(var t,r,n,i,o="",a=0,s=(e=String(e)).length%3;a<e.length;){if((r=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");o+=I.charAt((t=r<<16|n<<8|i)>>18&63)+I.charAt(t>>12&63)+I.charAt(t>>6&63)+I.charAt(63&t)}return s?o.slice(0,s-3)+"===".substring(s):o}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{R()&&(this.useWxCloud=e.useWxCloud,void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud))}catch(e){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc,this.onCredentialsError=e.onCredentialsError,this.getInitialSession=e.getInitialSession,this.onInitialSessionObtained=e.onInitialSessionObtained,this.logDebugMessages=null!==(t=e.debug)&&void 0!==t&&t,X.on("lang_change",e=>{var t;this.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||this.i18n})}setGetInitialSession(e){this.getInitialSession=e}setOnInitialSessionObtained(e){this.onInitialSessionObtained=e}initialize(e){var t=this;return oe((function*(){return t.initializePromise?yield t.initializePromise:void 0!==e?(t.initializePromise=e,yield t.initializePromise):(t.initializePromise=oe((function*(){return yield t._acquireLock(-1,oe((function*(){return yield t._initialize()})))}))(),yield t.initializePromise)}))()}setCredentials(e){var t=this;return oe((function*(){return yield t.initializePromise,t._acquireLock(-1,oe((function*(){return t.localCredentials.setCredentials(e)})))}))()}setAccessKeyCredentials(e){return this.localCredentials.setAccessKeyCredentials(e)}getAccessToken(){var e=this;return oe((function*(){yield e.initializePromise;var t=yield e.getCredentials();if((null==t?void 0:t.scope)===f)return Promise.resolve(t.access_token);if(null!=t&&t.access_token)return Promise.resolve(t.access_token);var r={error:a.UNAUTHENTICATED};return Promise.reject(r)}))()}request(e,t){var r=this;return oe((function*(){var n,i,o,s;t||(t={});var c=r.formatRetry(t.retry,r.retry);if(t.headers=re(re({},t.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(i=r.i18n)||void 0===i?void 0:i.lang}),r.headers&&(t.headers=re(re({},r.headers),t.headers)),t.headers["x-request-id"]||(t.headers["x-request-id"]=p()),!t.headers["x-device-id"]){var u=yield r.getDeviceId();t.headers["x-device-id"]=u}if(null!==(o=t)&&void 0!==o&&o.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(s=t)&&void 0!==s&&s.withCredentials){var l=t.getCredentials?yield t.getCredentials():yield r.getCredentials();l&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(l.access_token)):t.headers.Authorization="".concat(l.token_type," ").concat(l.access_token))}else r.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(r.clientId));e.startsWith("/")&&(e="".concat(r.apiOrigin).concat(r.apiPath).concat(e));for(var d=null,h=c+1,f=0;f<h;f++){try{var v;if(null!==(v=d=t.useWxCloud||r.useWxCloud?yield r.wxCloudCallFunction(e,t):yield r.baseRequest(e,t))&&void 0!==v&&v.code)throw{error:d.code,error_description:d.message,error_uri:new URL(e).pathname};break}catch(e){try{e.requestId=e.requestId||t.headers["x-request-id"]||""}catch(e){}if(t.withCredentials&&e&&e.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(e);if(f===c||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep(le.retryInterval)}return d}))()}wxCloudCallFunction(e,t){var r=this;return oe((function*(){var n=null,i=null;try{var o,s="";try{s=yield wx.getRendererUserAgent()}catch(e){}var{result:c}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:re({origin:"https://servicewechat.com","User-Agent":s},t.headers),body:t.body}});null!=c&&null!==(o=c.body)&&void 0!==o&&o.error_code?(i=null==c?void 0:c.body).error_uri=(0,v.y)(e):n=null==c?void 0:c.body}catch(t){i={error:a.UNREACHABLE,error_description:t.message,error_uri:(0,v.y)(e)}}if(i)throw i;return n}))()}getCredentials(){var e=this;return oe((function*(){return yield e.initializePromise,e._acquireLock(-1,oe((function*(){return e._getCredentials()})))}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}return t.scope}))()}getGroups(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}return t.groups}))()}refreshToken(e,t){var r=this;return oe((function*(){return yield r.initializePromise,r._acquireLock(-1,oe((function*(){return r._refreshToken(e,t)})))}))()}_refreshToken(e,t){var r=this;return oe((function*(){return r.singlePromise.run("_refreshToken",oe((function*(){if((null==e?void 0:e.scope)===f)return e;if(!e||!e.refresh_token){var n,i="no refresh token found in credentials";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:i}),r.unAuthenticatedError(i)}try{var o,s=yield r.refreshTokenFunc(e.refresh_token,e);return yield r.localCredentials.setCredentials(s),null===(o=r.eventBus)||void 0===o||o.fire(d.AUTH_STATE_CHANGED,{event:l.TOKEN_REFRESHED}),s}catch(e){var c;if(null!=t&&t.throwError)throw e;if(e.error===a.INVALID_GRANT){var u;yield r.localCredentials.setCredentials(null);var h=e.error_description;return null===(u=r.onCredentialsError)||void 0===u||u.call(r,{msg:h}),r.unAuthenticatedError(h)}return null===(c=r.onCredentialsError)||void 0===c||c.call(r,{msg:e.error_description}),Promise.reject(e)}})))}))()}anonymousLogin(e){var t=this;return oe((function*(){return t.singlePromise.run("_anonymousLogin",oe((function*(){if(t.anonymousSignInFunc){var r=yield t.anonymousSignInFunc(e);e=r||(yield t.localCredentials.getCredentials())}else e=yield t.anonymousSignIn(e);return e})))}))()}checkRetry(e){var t=null;if(("number"!=typeof e||e<le.minRetry||e>le.maxRetry)&&(t={error:a.UNREACHABLE,error_description:"wrong options param: retry"}),t)throw t;return e}formatRetry(e,t){return void 0===e?t:this.checkRetry(e)}sleep(e){return oe((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var r=this;return oe((function*(){return r.singlePromise.run("_anonymous",oe((function*(){if(!e||"anonymous"!==e.scope)return r.unAuthenticatedError("no anonymous in credentials");try{var n=yield r.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield r.localCredentials.setCredentials(n),n}catch(e){return e.error===a.INVALID_GRANT?(yield r.localCredentials.setCredentials(null),r.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,r){var n=this;return oe((function*(){if(void 0===e||""===e){var o,a="refresh token not found";return null===(o=n.onCredentialsError)||void 0===o||o.call(n,{msg:a}),n.unAuthenticatedError(a)}var s=t.AUTH_TOKEN_URL;return"v2"===(null==r?void 0:r.version)&&(s=i.AUTH_TOKEN_URL),re(re({},yield n.request(s,{method:"POST",body:{client_id:n.clientId,client_secret:n.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==r?void 0:r.version)||"v1"})}))()}getDeviceId(){var e=this;return oe((function*(){if(e.deviceID)return e.deviceID;var t=yield e.storage.getItem("device_id");return"string"==typeof t&&t.length>=16&&t.length<=48||(t=p(),yield e.storage.setItem("device_id",t)),e.deviceID=t,t}))()}unAuthenticatedError(e){var t={error:a.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}_debug(){if(this.logDebugMessages){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[OAuth2Client]",...t)}}_initialize(){var e=this;return oe((function*(){try{if(!e.getInitialSession)return e._debug("#_initialize()","no getInitialSession callback set, skipping"),{error:null};e._debug("#_initialize()","calling getInitialSession callback");try{var{data:t,error:r}=yield e.getInitialSession();if(null!=t&&t.session&&(e._debug("#_initialize()","session obtained from getInitialSession",t.session),yield e.localCredentials.setCredentials(null==t?void 0:t.session)),e.onInitialSessionObtained){e._debug("#_initialize()","calling onInitialSessionObtained callback");try{yield e.onInitialSessionObtained(t,r)}catch(t){e._debug("#_initialize()","error in onInitialSessionObtained",t)}}return r?(e._debug("#_initialize()","error from getInitialSession",r),{error:r}):{error:null}}catch(t){return e._debug("#_initialize()","exception during getInitialSession",t),{error:t instanceof Error?t:new Error(String(t))}}}catch(r){return e._debug("#_initialize()","unexpected error",r),{error:r instanceof Error?r:new Error(String(r))}}finally{e._debug("#_initialize()","end")}}))()}_acquireLock(e,t){var r=this;return oe((function*(){r._debug("#_acquireLock","begin",e);try{if(r.lockAcquired){var n=r.pendingInLock.length?r.pendingInLock[r.pendingInLock.length-1]:Promise.resolve(),i=oe((function*(){return yield n,yield t()}))();return r.pendingInLock.push(oe((function*(){try{yield i}catch(e){}}))()),i}r._debug("#_acquireLock","acquiring lock for client",r.clientId);try{r.lockAcquired=!0;var o=t();for(r.pendingInLock.push(oe((function*(){try{yield o}catch(e){}}))()),yield o;r.pendingInLock.length;){var a=[...r.pendingInLock];yield Promise.all(a),r.pendingInLock.splice(0,a.length)}return yield o}finally{r._debug("#_acquireLock","releasing lock for client",r.clientId),r.lockAcquired=!1}}finally{r._debug("#_acquireLock","end")}}))()}_getCredentials(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(t.scope===f)return t;if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}if(ce(t))if(t.refresh_token)try{t=yield e._refreshToken(t)}catch(r){var i;if("anonymous"!==t.scope)return null===(i=e.onCredentialsError)||void 0===i||i.call(e,{msg:r.error_description}),Promise.reject(r);t=yield e.anonymousLogin(t)}else{if("anonymous"!==t.scope){var o,a="no refresh token found in credentials";return null===(o=e.onCredentialsError)||void 0===o||o.call(e,{msg:a}),e.unAuthenticatedError(a)}t=yield e.anonymousLogin(t)}return t}))()}}le.defaultRetry=2,le.minRetry=0,le.maxRetry=5,le.retryInterval=1e3;var de=r(689),he=r(616);function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function pe(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?fe(Object(r),!0).forEach((function(t){ve(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ve(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _e(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function ye(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_e(o,n,i,a,s,"next",e)}function s(e){_e(o,n,i,a,s,"throw",e)}a(void 0)}))}}var ge=(e,t)=>{var r;return function(){for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>e.apply(null,i),t)}},Ee=new de.CloudbaseEventEmitter,Ie="resolveCaptchaData",me="position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999",Oe="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",Se="margin-bottom:15px",be="display:flex;align-items:center;justify-content:space-between;margin-bottom:15px",Re="width:100%;height:auto;border:1px solid #eee",Ae="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",Te="width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px",Ce="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",we="background:#6c757d;cursor:not-allowed",Pe=e=>{var{oauthInstance:t,captchaState:r}=e,n=function(){var e=ye((function*(){try{var e=yield t.createCaptchaData({state:r.state});r=pe(pe({},r),{},{captchaData:e.data,token:e.token}),document.getElementById("captcha-image").src=e.data}catch(e){console.error("刷新图形验证码失败",e)}}));return function(){return e.apply(this,arguments)}}(),i=(e,t,r)=>{var n=document.createElement(e);return t&&(n.style.cssText=t),r&&(n.textContent=r),n},o=i("div",me),a=i("div",Oe);a.appendChild(i("p",Se,"请输入你看到的字符:"));var s=i("div",be),c=i("img",Re);c.id="captcha-image",c.src=r.captchaData,s.appendChild(c);var u=i("button",Ae,"刷新");u.onclick=ge(ye((function*(){u.textContent="加载中...",u.disabled=!0,u.style.cssText="".concat(Ae,";").concat(we);try{yield n()}finally{u.textContent="刷新",u.disabled=!1,u.style.cssText=Ae}})),500),s.appendChild(u),a.appendChild(s);var l=i("input",Te);l.type="text",l.placeholder="输入字符",l.maxLength=4,a.appendChild(l);var d=i("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");a.appendChild(d);var h=e=>{d.textContent=e,d.style.display="block"},f=i("button",Ce,"确定");f.onclick=ge(ye((function*(){var e=l.value.trim();if(e){d.style.display="none",f.textContent="验证中...",f.disabled=!0,f.style.cssText="".concat(Ce,";").concat(we);try{var i=yield t.verifyCaptchaData({token:r.token,key:e});Ee.fire(Ie,i),console.log("图形验证码校验成功"),document.body.removeChild(o),document.body.removeChild(a)}catch(e){console.error("图形验证码校验失败",e);var s=e.error_description||"图形验证码校验失败";h(s),l.value="",l.focus(),yield n()}finally{f.textContent="确定",f.disabled=!1,f.style.cssText=Ce}}else h("请输入字符")})),500),a.appendChild(f),document.body.appendChild(o),document.body.appendChild(a)},Ne=function(){var e=ye((function*(e,t){var{captchaData:r,state:n,token:i}=(0,he.parseCaptcha)(e);return Pe({oauthInstance:t,captchaState:{captchaData:r,state:n,token:i}}),new Promise(e=>{console.log("等待图形验证码校验结果..."),Ee.on(Ie,t=>{e(null==t?void 0:t.data)})})}));return function(t,r){return e.apply(this,arguments)}}();function Ue(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function De(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){Ue(o,n,i,a,s,"next",e)}function s(e){Ue(o,n,i,a,s,"throw",e)}a(void 0)}))}}class Le{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=se),this.config=e,this.tokenSectionName="captcha_".concat(e.clientId||e.env)}isMatch(){var e,t;return(null===(e=this.config)||void 0===e||null===(e=e.adapter)||void 0===e||null===(t=e.isMatch)||void 0===t?void 0:t.call(e))||R()}request(e,t){var r=this;return De((function*(){t||(t={}),t.method||(t.method="GET");var n,i="".concat(t.method,":").concat(e),o=e;t.withCaptcha&&(o=yield r.appendCaptchaTokenToURL(e,i,!1));try{n=yield r.config.request(o,t)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(e=yield r.appendCaptchaTokenToURL(e,i,n.error===a.CAPTCHA_INVALID),r.config.request(e,t)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){return e=>Ne(e,this.config.oauthInstance)}getCaptchaToken(e,r){var n=this;return De((function*(){if(!e){var i=yield n.findCaptchaToken();if(i)return i}var o=yield n.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:""},withCredentials:!1}),a="".concat(o.data,"?state=").concat(encodeURIComponent(r),"&token=").concat(encodeURIComponent(o.token)),s=yield n.config.openURIWithCallback(a);return n.saveCaptchaToken(s),s.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return De((function*(){var i=yield n.getCaptchaToken(r,t);return e.indexOf("?")>0?e+="&captcha_token=".concat(i):e+="?captcha_token=".concat(i),e}))()}saveCaptchaToken(e){var t=this;return De((function*(){e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10));var r=JSON.stringify(e);yield t.config.storage.setItem(t.tokenSectionName,r)}))()}findCaptchaToken(){var e=this;return De((function*(){var t=yield e.config.storage.getItem(e.tokenSectionName);if(null!=t)try{var r=JSON.parse(t);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(t){return yield e.config.storage.removeItem(e.tokenSectionName),null}return null}))()}}const xe=class{constructor(e){if(this.params={},"string"==typeof e)this.parse(e);else if(e&&"object"==typeof e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&this.append(t,e[t])}parse(e){e.split("&").forEach(e=>{var[t,r]=e.split("=").map(decodeURIComponent);this.append(t,r)})}append(e,t){this.params[e]?this.params[e]=this.params[e].concat([t]):this.params[e]=[t]}get(e){return this.params[e]?this.params[e][0]:null}getAll(e){return this.params[e]||[]}delete(e){delete this.params[e]}has(e){return Object.prototype.hasOwnProperty.call(this.params,e)}set(e,t){this.params[e]=[t]}toString(){var e=this,t=[],r=function(r){Object.prototype.hasOwnProperty.call(e.params,r)&&e.params[r].forEach(e=>{t.push("".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(e)))})};for(var n in this.params)r(n);return t.join("&")}};var ke;!function(e){e.PROVIDER_NOT_ENABLED="PROVIDER_NOT_ENABLED",e.INVALID_CREDENTIALS="INVALID_CREDENTIALS",e.USER_NOT_FOUND="USER_NOT_FOUND",e.USER_STATUS_ABNORMAL="USER_STATUS_ABNORMAL",e.SERVICE_ERROR="SERVICE_ERROR",e.INVALID_PARAMS="INVALID_PARAMS",e.AUTH_METHOD_MISMATCH="AUTH_METHOD_MISMATCH",e.UNKNOWN="UNKNOWN"}(ke||(ke={}));var je="https://tcb.cloud.tencent.com/dev?envId=#/identity/login-manage",qe="https://docs.cloudbase.net/api-reference/webv3-next/initialization";class He extends Error{constructor(e,t){var r,n=e.error_description||e.message;super(n),this.__isAuthError=!0,this.name="AuthError",this.status=e.error,this.code=e.error_code,this.requestId=e.requestId,this.category=function(e,t){if(!e&&!t)return ke.UNKNOWN;try{var r=(e||"").toLowerCase();return t===a.FAILED_PRECONDITION||t===a.PROVIDER_NOT_ENABLED||t===a.LOGIN_METHOD_DISABLED||r.includes("身份源")||r.includes("开启")||r.includes("identity provider")||r.includes("provider not enabled")||r.includes("login method")||r.includes("登录方式")||r.includes("not enabled")||r.includes("未开启")||r.includes("未启用")||r.includes("请联系开发者")||r.includes("anonymous login is not enabled")||r.includes("匿名登录未开启")?ke.PROVIDER_NOT_ENABLED:t===a.INVALID_PASSWORD||t===a.INVALID_GRANT||t===a.INVALID_VERIFICATION_CODE||t===a.INVALID_USERNAME_OR_PASSWORD||t===a.INVALID_CREDENTIALS||t===a.WRONG_PASSWORD||t===a.UNAUTHENTICATED||t===a.INVALID_TWO_FACTOR||t===a.INVALID_TWO_FACTOR_RECOVERY||t===a.PASSWORD_NOT_SET||r.includes("密码不正确")||r.includes("password")||r.includes("invalid_password")||r.includes("凭据")||r.includes("credentials")||r.includes("验证码")||r.includes("verification")||r.includes("invalid_verification_code")||r.includes("invalid_username_or_password")||r.includes("username or password")||r.includes("用户名或密码")||r.includes("wrong password")||r.includes("incorrect password")?ke.INVALID_CREDENTIALS:t===a.NOT_FOUND||t===a.USER_NOT_FOUND||r.includes("用户不存在")||r.includes("not found")||r.includes("user not found")||r.includes("不存在")||r.includes("no such user")||r.includes("user does not exist")?ke.USER_NOT_FOUND:t===a.USER_BLOCKED||t===a.USER_PENDING||t===a.UNDER_REVIEW||t===a.INVALID_STATUS||r.includes("被封禁")||r.includes("blocked")||r.includes("pending")||r.includes("审核")||r.includes("review")||r.includes("locked")||r.includes("已锁定")?ke.USER_STATUS_ABNORMAL:t===a.SERVER_ERROR||t===a.UNAVAILABLE||t===a.TEMPORARILY_UNAVAILABLE||t===a.INTERNAL||t===a.UNREACHABLE||t===a.DEADLINE_EXCEEDED||t===a.DATA_LOSS||r.includes("network")||r.includes("timeout")||r.includes("服务")||r.includes("timed out")||r.includes("超时")?ke.SERVICE_ERROR:t===a.INVALID_ARGUMENT||t===a.INVALID_REQUEST||t===a.INVALID_SCOPE||t===a.INVALID_REQUEST_URI||t===a.INVALID_REQUEST_OBJECT?ke.INVALID_PARAMS:t===a.PERMISSION_DENIED||t===a.ACCESS_DENIED||t===a.UNAUTHORIZED_CLIENT?ke.PROVIDER_NOT_ENABLED:ke.UNKNOWN}catch(e){return t}}(n,this.status),this.helpMessage=function(e,t){var r=(null==t?void 0:t.method)||"signIn",n={signInWithPassword:"「用户名密码登录」",signInAnonymously:"「匿名登录」",signInWithOtp:"「短信验证码登录」或「邮箱验证码登录」",signUp:"「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"对应的第三方身份源",signInWithIdToken:"对应的第三方身份源",signInWithOpenId:"「微信小程序 OpenID 登录」",signInWithPhoneAuth:"「微信小程序手机号授权登录」",signInWithCustomTicket:"「自定义登录」"}[r]||"对应的登录方式";switch(e){case ke.PROVIDER_NOT_ENABLED:return"[CloudBase Auth] 登录方式未开启\n\n"+" 当前调用的 ".concat(r,"() 所需的登录方式尚未在云开发控制台启用。\n")+" 需要开启的登录方式:".concat(n,"\n")+"\n 请按以下步骤开启:\n"+" 1. 打开云开发控制台:".concat(je,"\n")+" 2. 选择对应的云开发环境\n 3. 进入「登录授权」页面,在「登录方式」或「身份源列表」中开启所需的登录方式\n\n 各登录方法与所需登录方式的对应关系:\n - signInWithPassword → 「用户名密码登录」\n - signInAnonymously → 「匿名登录」\n - signInWithOtp/signUp → 「短信验证码登录」或「邮箱验证码登录」\n - signInWithOAuth/signInWithIdToken → 对应的第三方身份源\n\n 如使用 CLI/MCP 工具,可通过 auth 工具查询和配置身份源状态。\n"+" 更多帮助请参考文档:".concat(qe);case ke.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 ke.USER_NOT_FOUND:return"[CloudBase Auth] 用户不存在\n\n 请检查以下项目:\n 1. 确认用户名/邮箱/手机号是否正确\n 2. 确认是在正确的云开发环境(envId)下操作\n 3. 如果是新用户,请先通过 auth.signUp() 注册\n"+" 4. 也可在云开发控制台手动创建用户:".concat(je,"\n")+"\n 提示:不同环境(开发/测试/生产)的用户库是隔离的,请确认 envId 正确。";case ke.USER_STATUS_ABNORMAL:return"[CloudBase Auth] 用户状态异常\n\n 当前用户账号可能处于以下状态之一:\n - 账号已被封禁\n - 账号正在审核中\n - 账号已被锁定(多次密码错误)\n\n"+" 请联系管理员在云开发控制台检查用户状态:".concat(je);case ke.SERVICE_ERROR:return"[CloudBase Auth] 服务异常\n\n 请检查以下项目:\n 1. 网络连接是否正常\n 2. 云开发环境是否正常运行\n 3. 稍后重试,如持续失败请联系技术支持\n\n 提示:如果是超时错误,请检查网络环境和请求频率。";case ke.INVALID_PARAMS:return"[CloudBase Auth] 参数错误\n\n 请检查传入的参数是否符合要求,参考 API 文档确认各参数的格式和约束。\n"+" 文档地址:".concat(qe);case ke.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(je);default:return"[CloudBase Auth] 操作失败\n\n 如果问题持续存在,建议:\n"+" 1. 检查云开发控制台的认证配置:".concat(je,"\n")+" 2. 到官方问答社区提问:https://cnb.cool/tencent/cloud/cloudbase/community/-/issues\n"+" 3. 查阅文档:".concat(qe)}}(this.category,t),this.loginMethodHint=(r=null==t?void 0:t.method)&&{signInWithPassword:"当前使用「用户名密码登录」,需确保:\n ✓ 控制台已开启「用户名密码登录」\n ✓ 用户已注册且凭据正确\n 如果不需要用户系统,建议改用 auth.signInAnonymously()",signInAnonymously:"当前使用「匿名登录」,需确保:\n ✓ 控制台已开启「匿名登录」\n 注意:匿名用户无需用户名密码,适用于快速体验或临时访问场景",signInWithOtp:"当前使用「OTP 验证码登录」,需确保:\n ✓ 控制台已开启「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"当前使用「第三方 OAuth 登录」,需确保:\n ✓ 控制台已配置并开启对应的第三方身份源"}[r]||""}}var Ve=["provider_redirect_uri","other_params"];function Me(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ge(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Me(Object(r),!0).forEach((function(t){We(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Me(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function We(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Be(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function Fe(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){Be(o,n,i,a,s,"next",e)}function s(e){Be(o,n,i,a,s,"throw",e)}a(void 0)}))}}function Ke(e,t){return Ye.apply(this,arguments)}function Ye(){return(Ye=Fe((function*(e,t){var n=function(){var e=Fe((function*(){try{return r(3)}catch(e){try{return yield Promise.resolve().then(r.bind(r,3))}catch(e){return}}}));return function(){return e.apply(this,arguments)}}();try{var i;if(((null==t||null===(i=t.root)||void 0===i?void 0:i.globalThis)||globalThis).IS_MP_BUILD)return;0}catch(t){if(e)return n()}}))).apply(this,arguments)}class ze{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new xe(e).toString()}constructor(e){var{request:t}=e,r=e.credentialsClient;if(!r){var n={apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,storage:e.storage,env:e.env,baseRequest:e.baseRequest,anonymousSignInFunc:e.anonymousSignInFunc,wxCloud:e.wxCloud,onCredentialsError:e.onCredentialsError,headers:e.headers||{},i18n:e.i18n,debug:e.debug};r=new le(n)}if(!t){var i=r.request.bind(r),o=new Le(Ge({env:e.env,clientId:e.clientId,request:i,storage:e.storage,adapter:e.adapter,oauthInstance:this},e.captchaOptions));t=o.request.bind(o)}this.config={env:e.env,apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||se,adapter:e.adapter}}getParamsByVersion(e,r){var n,o=(0,v.I)(e),a=(null===(n={v2:i}[null==o?void 0:o.version])||void 0===n?void 0:n[r])||t[r];return o&&delete o.version,{params:o,url:a}}signIn(e){var t=this;return Fe((function*(){var r=e.version||"v1",n=t.getParamsByVersion(e,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var i=yield t.getEncryptParams(n.params),o=yield t.config.request(n.url,{method:"POST",body:i});return yield t.config.credentialsClient.setCredentials(Ge(Ge({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var e=arguments,r=this;return Fe((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=e.length>1&&void 0!==e[1]&&e[1],o=yield r.config.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:n,useWxCloud:i});return yield r.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(e){var r=this;return Fe((function*(){var n=yield r.config.request(t.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signOut(e){var r=this;return Fe((function*(){var n={};if(e){try{n=yield r.config.request(t.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield r.config.credentialsClient.setCredentials(),n}var i=yield r.config.credentialsClient.getAccessToken(),o=yield r.config.request(t.AUTH_REVOKE_URL,{method:"POST",body:{token:i}});return yield r.config.credentialsClient.setCredentials(),Promise.resolve(o)}))()}revokeAllDevices(){var e=this;return Fe((function*(){yield e.config.request(t.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var r=this;return Fe((function*(){yield r.config.request(t.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,r){var n=this;return Fe((function*(){var i=!1;"CUR_USER"===e.target?i=!0:(yield n.hasLoginState())&&(i=!0);var o=(0,v.I)(e);return o.phone_number&&!/^\+\d{1,3}\s+\d+/.test(o.phone_number)&&(o.phone_number="+86 ".concat(o.phone_number)),n.config.request(t.VERIFICATION_URL,{method:"POST",body:o,withCaptcha:(null==r?void 0:r.withCaptcha)||!1,withCredentials:i})}))()}verify(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"VERIFY_URL"),n=yield t.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==e?void 0:e.version)&&(yield t.config.credentialsClient.setCredentials(Ge(Ge({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var r=this;return Fe((function*(){var{provider_redirect_uri:n,other_params:i={}}=e,o=function(e,t){if(null==e)return{};var r,n,i=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}(e,Ve);n&&!o.redirect_uri&&(o.redirect_uri=n);var a="".concat(t.PROVIDER_URI_URL,"?").concat(ze.parseParamsToSearch(o));return Object.keys(i).forEach(e=>{var t=i[e];("sign_out_uri"!==e||(null==t?void 0:t.length)>0)&&(a+="&other_params[".concat(e,"]=").concat(encodeURIComponent(t)))}),r.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var r=arguments,n=this;return Fe((function*(){var i=r.length>1&&void 0!==r[1]&&r[1];return n.config.request(t.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:i})}))()}patchProviderToken(e){var r=this;return Fe((function*(){return r.config.request(t.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return Fe((function*(){var n=t.length>1&&void 0!==t[1]&&t[1],i=r.getParamsByVersion(e,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=yield r.config.request(i.url,{method:"POST",body:i.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(Ge(Ge({},o),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(o)}))()}toBindIdentity(e){var t=this;return Fe((function*(){var r,n,i,o=e.credentials||(yield t.config.credentialsClient.localCredentials.getCredentials());try{yield t.bindWithProvider({provider_token:e.provider_token},o),r={data:{type:h.BIND_IDENTITY,provider:e.provider},error:null}}catch(e){r={data:{type:h.BIND_IDENTITY},error:new He(e)}}e.fireEvent&&(null===(n=t.config.eventBus)||void 0===n||null===(i=n.fire)||void 0===i||i.call(n,d.AUTH_STATE_CHANGED,{event:l.BIND_IDENTITY,info:r}));return r}))()}getInitialSession(){var e=this;return Fe((function*(){var t={};try{var r,n,i,o,a;if("undefined"==typeof window||"undefined"==typeof document)return{data:null,error:null};var s=new URLSearchParams(null===(r=location)||void 0===r?void 0:r.search),c=s.get("code"),u=s.get("state");if(!c||!u)return{data:null,error:null};var l=null;try{l=JSON.parse(sessionStorage.getItem(u)||"null")}catch(e){}t={type:null===(n=l)||void 0===n?void 0:n.type};var d=s.get("error"),f=s.get("error_description");if(d||f)return{data:t,error:new He({message:f||d||"Unknown error from OAuth provider"})};var p=(null===(i=l)||void 0===i?void 0:i.provider)||s.get("provider");if(!p)return{data:t,error:new He({message:"Provider is required for OAuth verification"})};var v,_,y=location.origin+location.pathname,{provider_token:g}=yield e.grantProviderToken({provider_id:p,provider_redirect_uri:y,provider_code:c}),E=null;if(l.type===h.BIND_IDENTITY)v=yield e.config.credentialsClient.localCredentials.getCredentials(),_=yield e.toBindIdentity({provider:p,provider_token:g,credentials:v});else if(l.type===h.SIGN_IN){_=e.getParamsByVersion({provider:p},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),v=yield e.config.request(_.url,{method:"POST",body:{provider_token:g}});try{E=yield e.getUserInfo({credentials:v})}catch(e){console.error("get user info error",e)}_={data:Ge(Ge({},t),{},{session:v,user:E}),error:null}}s.delete("code"),s.delete("state"),s.delete("provider"),e.restoreUrlState(void 0===(null===(o=l)||void 0===o?void 0:o.search)?"?".concat(s.toString()):l.search,(null===(a=l)||void 0===a?void 0:a.hash)||location.hash);try{sessionStorage.removeItem(u)}catch(e){}return _}catch(e){return{data:t,error:new He(e)}}}))()}signInCustom(e){var r=this;return Fe((function*(){var n=yield r.config.request(t.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signInWithWechat(){var e=arguments,r=this;return Fe((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=yield r.config.request(t.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:n});return yield r.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}bindWithProvider(e,r){var n=this;return Fe((function*(){return n.config.request(t.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0,getCredentials:r?()=>r:void 0})}))()}getUserProfile(e){var t=this;return Fe((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return Fe((function*(){var r,n=e.length>0&&void 0!==e[0]?e[0]:{},i=t.getParamsByVersion(n,"USER_ME_URL");if(null!==(r=i.params)&&void 0!==r&&r.query){var o=new xe(i.params.query);i.url+="?".concat(o.toString())}var a=yield t.config.request(i.url,{method:"GET",withCredentials:!0,getCredentials:n.credentials?()=>n.credentials:void 0});return a.sub&&(a.uid=a.sub),a}))()}getWedaUserInfo(){var e=this;return Fe((function*(){return yield e.config.request(t.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(ze.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return Fe((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return Fe((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var r=this;return Fe((function*(){return r.config.request(t.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"AUTH_TOKEN_URL");return t.config.request(r.url,{method:"POST",body:r.params})}))()}getProviders(){var e=this;return Fe((function*(){return e.config.request(t.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return Fe((function*(){var r=yield t.sudo({password:e.old_password});return t.setPassword({sudo_token:r.sudo_token,new_password:e.new_password})}))()}sudo(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var r=this;return Fe((function*(){return e.target="CUR_USER",r.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var r=this;return Fe((function*(){return r.config.request(t.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var r=this;return Fe((function*(){return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var r=this;return Fe((function*(){var n=new xe(e);return r.config.request("".concat(t.USER_QUERY_URL,"?").concat(n.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return Fe((function*(){var t=e.getCustomSignTicketFn;if(!t)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield t();return e.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(e){var r=this;return Fe((function*(){return r.config.request(t.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var r=this;return Fe((function*(){return r.config.request(t.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var r=this;return Fe((function*(){return r.config.request(t.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var r=this;return Fe((function*(){return r.config.request(t.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var r=this;return Fe((function*(){var n="".concat(t.AUTHORIZE_INFO_URL,"?").concat(ze.parseParamsToSearch(e)),i=!0,o=!1;return(yield r.hasLoginState())&&(o=!0,i=!1),r.config.request(n,{method:"GET",withBasicAuth:i,withCredentials:o})}))()}checkUsername(e){var r=this;return Fe((function*(){return r.config.request(t.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var r=this;return Fe((function*(){var n=new xe(e);return r.config.request("".concat(t.CHECK_IF_USER_EXIST,"?").concat(n.toString()),{method:"GET"})}))()}loginScope(){var e=this;return Fe((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return Fe((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return Fe((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(Ge(Ge({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return Fe((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return Fe((function*(){return e.config.request(i.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return Fe((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=(0,v.I)(e),i=yield Ke(r,t.config.adapter);if(!i)return e;var o="",a="";try{var s=yield t.getPublicKey();if(o=s.public_key,a=s.public_key_thumbprint,!o||!a)throw s}catch(e){throw e}return{params:i.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:a}}))()}getProviderSubType(){var e=this;return Fe((function*(){return e.config.request(t.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var r=this;return Fe((function*(){var{token:n,key:i}=e;return r.config.request(t.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:n,key:i},withCredentials:!1})}))()}createCaptchaData(e){var r=this;return Fe((function*(){var{state:n,redirect_uri:i}=e;return r.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:n,redirect_uri:i},withCredentials:!1})}))()}getMiniProgramCode(e){var r=this;return Fe((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var r=this;return Fe((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var r=this;return Fe((function*(){var n="".concat(t.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[e.type],"&limit=").concat(e.limit).concat(e.page_token?"&page_token=".concat(e.page_token):"");return r.config.request(n,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var r=this;return Fe((function*(){var n="",i="",o=yield Ke(!0,r.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield r.getPublicKey();if(n=a.public_key,i=a.public_key_thumbprint,!n||!i)throw a}catch(e){throw e}var s=e.password?o.getEncryptInfo({publicKey:n,payload:e.password}):"",c=o.getEncryptInfo({publicKey:n,payload:e.new_password});return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:s,encrypt_new_password:c,public_key_thumbprint:i}})}))()}modifyPasswordWithoutLogin(e){var t=this;return Fe((function*(){var r="",n="",o=yield Ke(!0,t.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield t.getPublicKey();if(r=a.public_key,n=a.public_key_thumbprint,!r||!n)throw a}catch(e){throw e}var s=e.password?o.getEncryptInfo({publicKey:r,payload:e.password}):"",c=o.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(i.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:s,new_password:c,public_key_thumbprint:n}})}))()}restoreUrlState(e,t){if(void 0!==e)try{var r=new URL(window.location.href);r.search=e,r.hash=t||"",window.history.replaceState(null,"",r.toString()),window.location.replace(r.toString())}catch(e){}}}function Qe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Je(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Qe(Object(r),!0).forEach((function(t){Ze(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Qe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Ze(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class Xe{constructor(e){var{apiOrigin:t,apiPath:r=s,clientId:n,env:i,storage:o,request:a,baseRequest:c,anonymousSignInFunc:u,wxCloud:l,adapter:d,onCredentialsError:h,headers:f,i18n:p,useWxCloud:v,eventBus:_,detectSessionInUrl:y,debug:g}=e;if(this.detectSessionInUrl=null!=y&&y,this.oauth2client=new le({apiOrigin:t,apiPath:r,clientId:n,env:i,storage:o,baseRequest:c||a,anonymousSignInFunc:u,wxCloud:l,onCredentialsError:h,headers:f||{},i18n:p,useWxCloud:v,eventBus:_,debug:g}),this.authApi=new ze(Je(Je({credentialsClient:this.oauth2client},e),{},{request:a?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d})),y)this.oauth2client.setGetInitialSession(this.authApi.getInitialSession.bind(this.authApi));else try{var E=new URL(window.location.href),I=E.searchParams.get("code"),m=E.searchParams.get("state"),O=JSON.parse(sessionStorage.getItem(m)||"null");I&&m&&null!=O&&O.hash&&(E.hash=O.hash,window.history.replaceState(null,"",E.toString()),window.location.replace(E.toString()))}catch(e){}}initializeSession(e){this.detectSessionInUrl?(this.oauth2client.setOnInitialSessionObtained(e),this.oauth2client.initialize()):this.oauth2client.initialize(Promise.resolve({error:null}))}}})(),n})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcboauth",[],t):"object"==typeof exports?exports.tcboauth=t():e.tcboauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var e={3:(e,t,r)=>{r.r(t),r.d(t,{getEncryptInfo:()=>o});const n=void 0;var i=r(912),o=function(){var{publicKey:e="",payload:t={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e)return"";try{var r=(0,i.I)(t),o=new n;o.setPublicKey(e);var a=o.encryptLong("object"==typeof r?JSON.stringify(r):r);return a}catch(e){console.error("encrypt error:",e)}return""}},912:(e,t,r)=>{r.d(t,{I:()=>n,y:()=>i});var n=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},r=null==e?"NullOrUndefined":Object.prototype.toString.call(e).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return e.slice();switch(r){case"Object":return t(Object.create(Object.getPrototypeOf(e)));case"Array":return t([]);case"Date":return new Date(e.valueOf());case"RegExp":return new RegExp(e.source,(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.sticky?"y":"")+(e.unicode?"u":""));default:return e}},i=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""}},946:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.COMMUNITY_SITE_URL=t.IS_DEBUG_MODE=t.getProtocol=t.setProtocol=t.getSdkName=t.setSdkName=void 0;var r="@cloudbase/js-sdk";t.setSdkName=function(e){r=e},t.getSdkName=function(){return r};var n="https:";t.setProtocol=function(e){n=e},t.getProtocol=function(){return n},t.IS_DEBUG_MODE=("undefined"==typeof process||process.env,!1),t.COMMUNITY_SITE_URL="https://support.qq.com/products/148793"},205:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ERRORS=void 0,t.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},794:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),t.OATUH_LOGINTYPE=void 0,i(r(946),t),i(r(205),t),t.OATUH_LOGINTYPE="constants"},689:function(e,t,r){var n,i=this&&this.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),o=this&&this.__spreadArray||function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};Object.defineProperty(t,"__esModule",{value:!0}),t.removeEventListener=t.activateEvent=t.addEventListener=t.CloudbaseEventEmitter=t.IErrorEvent=t.CloudbaseEvent=void 0;var a=r(616);var s=function(e,t){this.data=t||null,this.name=e};t.CloudbaseEvent=s;var c=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return i(t,e),t}(s);t.IErrorEvent=c;var u=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if((0,a.isInstanceOf)(e,c))return console.error(e.error),this;var r=(0,a.isString)(e)?new s(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,u=this.listeners[n]?o([],this.listeners[n],!0):[];i<u.length;i++){u[i].call(this,r)}}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();t.CloudbaseEventEmitter=u;var l=new u;t.addEventListener=function(e,t){l.on(e,t)},t.activateEvent=function(e,t){void 0===t&&(t={}),l.fire(e,t)},t.removeEventListener=function(e,t){l.off(e,t)}},616:function(e,t,r){var n=this&&this.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r};Object.defineProperty(t,"__esModule",{value:!0}),t.parseCaptcha=t.parseQueryString=t.transformPhone=t.sleep=t.printGroupLog=t.throwError=t.printInfo=t.printError=t.printWarn=t.execCallback=t.createPromiseCallback=t.removeParam=t.getHash=t.getQuery=t.toQueryString=t.formatUrl=t.generateRequestId=t.genSeqId=t.isFormData=t.isInstanceOf=t.isNull=t.isPalinObject=t.isUndefined=t.isString=t.isArray=void 0;var i=r(794);t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isPalinObject=function(e){return"[object Object]"===Object.prototype.toString.call(e)},t.isNull=function(e){return"[object Null]"===Object.prototype.toString.call(e)},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.generateRequestId=function(){var e=(new Date).getTime(),t=(null===Date||void 0===Date?void 0:Date.now)&&1e3*Date.now()||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(r){var n=16*Math.random();return e>0?(n=(e+n)%16|0,e=Math.floor(e/16)):(n=(t+n)%16|0,t=Math.floor(t/16)),("x"===r?n:7&n|8).toString(16)}))},t.formatUrl=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),i="";return Object.keys(r).forEach((function(e){""===i?!n&&(t+="?"):i+="&",i+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=i)?t:"".concat(e).concat(t)},t.toQueryString=function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")},t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var r=t||decodeURIComponent(window.location.search),n=new RegExp("(^|&)".concat(e,"=([^&]*)(&|$)")),i=r.substr(r.indexOf("?")+1).match(n);return null!=i?i[2]:""};t.getHash=function(e){if("undefined"==typeof window)return"";var t=window.location.hash.match(new RegExp("[#?&/]".concat(e,"=([^&#]*)")));return t?t[1]:""},t.removeParam=function(e,t){var r=t.split("?")[0],n=[],i=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==i){for(var o=(n=i.split("&")).length-1;o>=0;o-=1)n[o].split("=")[0]===e&&n.splice(o,1);r="".concat(r,"?").concat(n.join("&"))}return r},t.createPromiseCallback=function(){var e={};if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var r=new Promise((function(t,r){e=function(e,n){return e?r(e):t(n)}}));return e.promise=r,e},t.execCallback=function(e,t,r){if(void 0===r&&(r=null),e&&"function"==typeof e)return e(t,r);if(t)throw t;return r},t.printWarn=function(e,t){console.warn("[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t))},t.printError=function(e,t){console.error({code:e,msg:"[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t)})},t.printInfo=function(e,t){console.log("[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t))},t.throwError=function(e,t){throw new Error(JSON.stringify({code:e,msg:"[".concat((0,i.getSdkName)(),"][").concat(e,"]:").concat(t)}))},t.printGroupLog=function(e){var t,r=e.title,n=e.subtitle,i=void 0===n?"":n,o=e.content,a=void 0===o?[]:o,s=e.printTrace,c=void 0!==s&&s,u=e.collapsed;void 0!==u&&u?(console.groupCollapsed||console.error)(r,i):(console.group||console.error)(r,i);for(var l=0,d=a;l<d.length;l++){var h=d[l],f=h.type,p=h.body;switch(f){case"info":console.log(p);break;case"warn":console.warn(p);break;case"error":console.error(p)}}c&&(console.trace||console.log)("stack trace:"),null===(t=console.groupEnd)||void 0===t||t.call(console)};t.sleep=function(e){return void 0===e&&(e=0),new Promise((function(t){return setTimeout(t,e)}))},t.transformPhone=function(e){return"+86".concat(e)};t.parseQueryString=function(e){e=e.replace(/^\?/,"");var t={};return e.split("&").forEach((function(e){var r=e.split("="),n=r[0],i=r[1];n=decodeURIComponent(n),i=decodeURIComponent(i),n&&(t[n]?Array.isArray(t[n])?t[n].push(i):t[n]=[t[n],i]:t[n]=i)})),t},t.parseCaptcha=function(e){var r={},i=e.match(/^(data:.*?)(\?[^#\s]*)?$/);if(i){e=i[1];var o=i[2];o&&(r=(0,t.parseQueryString)(o))}var a=r.token,s=n(r,["token"]);return/^data:/.test(e)&&!a?{error:"invalid_argument",error_description:"invalid captcha data: ".concat(e)}:a?{state:s.state,token:a,captchaData:e}:{error:"unimplemented",error_description:"need to impl captcha data"}}}},t={};function r(n){var i=t[n];if(void 0!==i)return i.exports;var o=t[n]={exports:{}};return e[n].call(o.exports,o,o.exports,r),o.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{AUTH_API_PREFIX:()=>s,AUTH_STATE_CHANGED_TYPE:()=>l,Auth:()=>ze,AuthError:()=>He,AuthErrorCategory:()=>ke,CloudbaseOAuth:()=>Xe,DEFAULT_NODE_ACCESS_SCOPE:()=>f,EVENTS:()=>d,LOGIN_STATE_CHANGED_TYPE:()=>u,OAUTH_TYPE:()=>h,authModels:()=>e,weAppJwtDecodeAll:()=>b});var e={};r.r(e);var t,i,o,a,s="/auth";!function(e){e.AUTH_SIGN_UP_URL="/v1/signup",e.AUTH_TOKEN_URL="/v1/token",e.AUTH_REVOKE_URL="/v1/revoke",e.WEDA_USER_URL="/v1/plugin/weda/userinfo",e.AUTH_RESET_PASSWORD="/v1/reset",e.AUTH_GET_DEVICE_CODE="/v1/device/code",e.CHECK_USERNAME="/v1/checkUsername",e.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",e.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",e.AUTH_SIGN_IN_URL="/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",e.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",e.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",e.PROVIDER_TOKEN_URL="/v1/provider/token",e.PROVIDER_URI_URL="/v1/provider/uri",e.USER_ME_URL="/v1/user/me",e.AUTH_SIGNOUT_URL="/v1/user/signout",e.USER_QUERY_URL="/v1/user/query",e.USER_PRIFILE_URL="/v1/user/profile",e.USER_BASIC_EDIT_URL="/v1/user/basic/edit",e.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",e.PROVIDER_LIST="/v1/user/provider",e.PROVIDER_BIND_URL="/v1/user/provider/bind",e.PROVIDER_UNBIND_URL="/v1/user/provider",e.CHECK_PWD_URL="/v1/user/sudo",e.SUDO_URL="/v1/user/sudo",e.BIND_CONTACT_URL="/v1/user/contact",e.AUTH_SET_PASSWORD="/v1/user/password",e.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",e.AUTHORIZE_URL="/v1/user/authorize",e.AUTHORIZE_INFO_URL="/v1/user/authorize/info",e.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",e.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",e.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",e.VERIFICATION_URL="/v1/verification",e.VERIFY_URL="/v1/verification/verify",e.CAPTCHA_DATA_URL="/v1/captcha/data",e.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",e.GET_CAPTCHA_URL="/v1/captcha/init",e.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",e.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(t||(t={})),function(e){e.AUTH_SIGN_IN_URL="/v2/signin/username",e.AUTH_TOKEN_URL="/v2/token",e.USER_ME_URL="/v2/user/me",e.VERIFY_URL="/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(i||(i={})),function(e){e.REGISTER="REGISTER",e.SIGN_IN="SIGN_IN",e.PASSWORD_RESET="PASSWORD_RESET",e.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",e.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(o||(o={})),function(e){e.UNREACHABLE="unreachable",e.LOCAL="local",e.CANCELLED="cancelled",e.UNKNOWN="unknown",e.UNAUTHENTICATED="unauthenticated",e.RESOURCE_EXHAUSTED="resource_exhausted",e.FAILED_PRECONDITION="failed_precondition",e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.INVALID_PASSWORD="invalid_password",e.PASSWORD_NOT_SET="password_not_set",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked",e.INVALID_VERIFICATION_CODE="invalid_verification_code",e.TWO_FACTOR_REQUIRED="two_factor_required",e.INVALID_TWO_FACTOR="invalid_two_factor",e.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",e.UNDER_REVIEW="under_review",e.INVALID_REQUEST="invalid_request",e.UNAUTHORIZED_CLIENT="unauthorized_client",e.ACCESS_DENIED="access_denied",e.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",e.INVALID_SCOPE="invalid_scope",e.INVALID_GRANT="invalid_grant",e.SERVER_ERROR="server_error",e.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",e.INTERACTION_REQUIRED="interaction_required",e.LOGIN_REQUIRED="login_required",e.ACCOUNT_SELECTION_REQUIRED="account_selection_required",e.CONSENT_REQUIRED="consent_required",e.INVALID_REQUEST_URI="invalid_request_uri",e.INVALID_REQUEST_OBJECT="invalid_request_object",e.REQUEST_NOT_SUPPORTED="request_not_supported",e.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",e.REGISTRATION_NOT_SUPPORTED="registration_not_supported",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.PROVIDER_NOT_ENABLED="provider_not_enabled",e.LOGIN_METHOD_DISABLED="login_method_disabled",e.INVALID_USERNAME_OR_PASSWORD="invalid_username_or_password",e.INVALID_CREDENTIALS="invalid_credentials",e.WRONG_PASSWORD="wrong_password",e.USER_NOT_FOUND="user_not_found"}(a||(a={}));var c,u={SIGN_OUT:"sign_out",SIGN_IN:"sign_in",CREDENTIALS_ERROR:"credentials_error"},l={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"},d={LOGIN_STATE_CHANGED:"loginStateChanged",AUTH_STATE_CHANGED:"authStateChanged"},h={SIGN_IN:"sign_in",BIND_IDENTITY:"bind_identity"},f="node-sdk-scope";function p(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}!function(e){e.CLIENT_ID="client_id",e.CLIENT_SECRET="client_secret",e.RESPONSE_TYPE="response_type",e.SCOPE="scope",e.STATE="state",e.REDIRECT_URI="redirect_uri",e.ERROR="error",e.ERROR_DESCRIPTION="error_description",e.ERROR_URI="error_uri",e.GRANT_TYPE="grant_type",e.CODE="code",e.ACCESS_TOKEN="access_token",e.TOKEN_TYPE="token_type",e.EXPIRES_IN="expires_in",e.USERNAME="username",e.PASSWORD="password",e.REFRESH_TOKEN="refresh_token"}(c||(c={}));var v=r(912);function _(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function y(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_(o,n,i,a,s,"next",e)}function s(e){_(o,n,i,a,s,"throw",e)}a(void 0)}))}}var g=new Map;class E{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",g=g||new Map}run(e,t){var r=this;return y((function*(){e="".concat(r.clientId,"_").concat(e);var n=g.get(e);return n||(n=new Promise((n,i)=>{y((function*(){try{yield r.runIdlePromise();var o=t();n(yield o)}catch(e){i(e)}finally{g.delete(e)}}))()}),g.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var I="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",m=/^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/;var O=function(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!m.test(e))throw new TypeError("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.");var t;e+="==".slice(2-(3&e.length));for(var r,n,i="",o=0;o<e.length;)t=I.indexOf(e.charAt(o++))<<18|I.indexOf(e.charAt(o++))<<12|(r=I.indexOf(e.charAt(o++)))<<6|(n=I.indexOf(e.charAt(o++))),i+=64===r?String.fromCharCode(t>>16&255):64===n?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,255&t);return i};function S(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("Illegal base64url string!")}try{return function(e){return decodeURIComponent(O(e).replace(/(.)/g,e=>{var t=e.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0".concat(t)),"%".concat(t)}))}(t)}catch(e){return O(t)}}function b(e){if("string"!=typeof e)throw new Error("Invalid token specified");try{var t=e.split(".").map((e,t)=>2===t?e:JSON.parse(S(e)));return{claims:t[1],header:t[0],signature:t[2]}}catch(e){throw new Error("Invalid token specified: ".concat(e)?e.message:0)}}function R(){if("undefined"==typeof globalThis)return!1;var{wx:e}=globalThis;if(void 0===e)return!1;if(void 0===globalThis.Page)return!1;if(!e.getDeviceInfo)return!1;if(!e.getStorageSync)return!1;if(!e.setStorageSync)return!1;if(!e.connectSocket)return!1;if(!e.request)return!1;try{if(!e.getDeviceInfo())return!1;if("qq"===e.getDeviceInfo().platform)return!1}catch(e){return!1}return!0}var A=!1;function T(){A=A||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{R()||(A=A||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?T():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",T,!1))}catch($){}var C="@cloudbase/js-sdk";function w(){return C}var P="https:";"undefined"==typeof process||process.env;var N,U="INVALID_PARAMS",D="INVALID_OPERATION",L="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(N||(N={}));var x=function(){};function k(e,t){console.warn("[".concat(w(),"][").concat(e,"]:").concat(t))}var j,q=(j=function(e,t){return(j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}j(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),H=function(){return(H=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},V=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},M=function(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}};!function(e){function t(t){var r=e.call(this)||this,n=t.timeout,i=t.timeoutMsg,o=t.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=i||"请求超时",r.restrictedMethods=o||["get","post","upload","download"],r}q(t,e),t.prototype.get=function(e){return this.request(H(H({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(H(H({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(H(H({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,i=e.method,o=e.headers,a=void 0===o?{}:o,s={post:"post",put:"put"}[null==i?void 0:i.toLowerCase()]||"put",c=new FormData;return"post"===s?(Object.keys(t).forEach((function(e){c.append(e,t[e])})),c.append("key",n),c.append("file",r),this.request(H(H({},e),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(H(H({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return V(this,void 0,void 0,(function(){var t,r,n,i;return M(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.get(H(H({},e),{headers:{},responseType:"blob"}))];case 1:return t=o.sent().data,r=window.URL.createObjectURL(new Blob([t])),n=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(i=document.createElement("a")).href=r,i.setAttribute("download",n),i.style.display="none",document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i),[3,3];case 2:return o.sent(),[3,3];case 3:return[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}}))}))},t.prototype.fetch=function(e){var t;return V(this,void 0,void 0,(function(){var r,n,i,o,a,s,c,u,l,d,h,f,p,v=this;return M(this,(function(_){switch(_.label){case 0:return r=new AbortController,n=e.url,i=e.enableAbort,o=void 0!==i&&i,a=e.stream,s=void 0!==a&&a,c=e.signal,u=e.timeout,l=e.shouldThrowOnError,d=void 0===l||l,h=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),f=null,o&&h&&(f=setTimeout((function(){console.warn(v.timeoutMsg),r.abort(new Error(v.timeoutMsg))}),h)),[4,fetch(n,H(H({},e),{signal:r.signal})).then((function(e){return V(v,void 0,void 0,(function(){var t,r,n;return M(this,(function(i){switch(i.label){case 0:return clearTimeout(f),d?e.ok?(t=e,[3,3]):[3,1]:[3,4];case 1:return n=(r=Promise).reject,[4,e.json()];case 2:t=n.apply(r,[i.sent()]),i.label=3;case 3:return[2,t];case 4:return[2,e]}}))}))})).catch((function(e){if(clearTimeout(f),d)return Promise.reject(e)}))];case 1:return p=_.sent(),[2,{data:s?p.body:(null===(t=p.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?p.json():p.text(),statusCode:p.status,header:p.headers}]}}))}))},t.prototype.request=function(e,t){var r=this;void 0===t&&(t=!1);var n=String(e.method).toLowerCase()||"get";return new Promise((function(i){var o,a,s,c=e.url,u=e.headers,l=void 0===u?{}:u,d=e.data,h=e.responseType,f=e.withCredentials,p=e.body,v=e.onUploadProgress,_=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),i="";return Object.keys(r).forEach((function(e){""===i?!n&&(t+="?"):i+="&",i+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=i)?t:"".concat(e).concat(t)}(P,c,"get"===n?d:{}),y=new XMLHttpRequest;y.open(n,_),h&&(y.responseType=h),Object.keys(l).forEach((function(e){y.setRequestHeader(e,l[e])})),v&&y.upload.addEventListener("progress",v),y.onreadystatechange=function(){var e={};if(4===y.readyState){var t=y.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};t.forEach((function(e){var t=e.split(": "),n=t.shift().toLowerCase(),i=t.join(": ");r[n]=i})),e.header=r,e.statusCode=y.status;try{e.data="blob"===h?y.response:JSON.parse(y.responseText)}catch(t){e.data="blob"===h?y.response:y.responseText}clearTimeout(o),i(e)}},t&&r.timeout&&(o=setTimeout((function(){console.warn(r.timeoutMsg),y.abort()}),r.timeout)),s=d,a="[object FormData]"===Object.prototype.toString.call(s)?d:"application/x-www-form-urlencoded"===l["content-type"]?function(e){void 0===e&&(e={});var t=[];return Object.keys(e).forEach((function(r){t.push("".concat(r,"=").concat(encodeURIComponent(e[r])))})),t.join("&")}(d):p||(d?JSON.stringify(d):void 0),f&&(y.withCredentials=!0),y.send(a)}))}}((function(){}));var G;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(G||(G={}));var W=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),B=function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{c(n.next(e))}catch(e){o(e)}}function s(e){try{c(n.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))},F=function(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){a.label=s[1];break}if(6===s[0]&&a.label<i[1]){a.label=i[1],i=s;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(s);break}i[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}},K=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return W(t,e),t.prototype.setItem=function(e,t){this.root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this.root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this.root.tcbCacheObject[e]},t.prototype.clear=function(){delete this.root.tcbCacheObject},t}(x);!function(){function e(e){this.keys={};var t=e.persistence,r=e.platformInfo,n=void 0===r?{}:r,i=e.keys,o=void 0===i?{}:i;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||t,this.storage=function(e,t){switch(e){case"local":return t.localStorage?t.localStorage:(k(U,"localStorage is not supported on current platform"),new K(t.root));case"none":return new K(t.root);default:return t.localStorage?t.localStorage:(k(U,"localStorage is not supported on current platform"),new K(t.root))}}(this.persistenceTag,this.platformInfo.adapter),this.keys=o)}Object.defineProperty(e.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),e.prototype.setStore=function(e,t,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:t};this.storage.setItem(e,JSON.stringify(n))}catch(e){throw new Error(JSON.stringify({code:L,msg:"[".concat(w(),"][").concat(L,"]setStore failed"),info:e}))}}else k(D,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return B(this,void 0,void 0,(function(){var n;return F(this,(function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),n={version:r||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(n))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}}))}))},e.prototype.getStore=function(e,t){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return process.env.tcb_token;if(!this.storage)return""}catch(e){return""}t=t||"localCachev1";var n=this.storage.getItem(e);return n&&n.indexOf(t)>=0?JSON.parse(n).content:""}k(D,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return B(this,void 0,void 0,(function(){var n;return F(this,(function(i){switch(i.label){case 0:try{if("undefined"!=typeof process&&(null===(r=process.env)||void 0===r?void 0:r.tcb_token))return[2,process.env.tcb_token];if(!this.storage)return[2,""]}catch(e){return[2,""]}return t=t||"localCachev1",[4,this.storage.getItem(e)];case 1:return(n=i.sent())&&n.indexOf(t)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):k(D,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return B(this,void 0,void 0,(function(){return F(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var Y=function(){var e=function(t,r){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),z=function(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))};var Q=function(e,t){this.data=t||null,this.name=e},J=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return Y(t,e),t}(Q),Z=function(){function e(){this.listeners={}}return e.prototype.on=function(e,t){return function(e,t,r){r[e]=r[e]||[],r[e].push(t)}(e,t,this.listeners),this},e.prototype.off=function(e,t){return function(e,t,r){if(null==r?void 0:r[e]){var n=r[e].indexOf(t);-1!==n&&r[e].splice(n,1)}}(e,t,this.listeners),this},e.prototype.fire=function(e,t){if(e instanceof J)return console.error(e.error),this;var r="string"==typeof e?new Q(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,o=this.listeners[n]?z([],this.listeners[n],!0):[];i<o.length;i++){o[i].call(this,r)}}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();new Z;var X=new Z;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");!function(){function e(){var e=this;this.listeners=[],this.signal={aborted:!1,addEventListener:function(t,r){"abort"===t&&e.listeners.push(r)}}}e.prototype.abort=function(){this.signal.aborted||(this.signal.aborted=!0,this.listeners.forEach((function(e){return e()})))}}();function $(e){this.message=e}$.prototype=new Error,$.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function ee(e){this.message=e}ee.prototype=new Error,ee.prototype.name="InvalidTokenError";function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function re(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?te(Object(r),!0).forEach((function(t){ne(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):te(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ne(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function ie(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function oe(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){ie(o,n,i,a,s,"next",e)}function s(e){ie(o,n,i,a,s,"throw",e)}a(void 0)}))}}var ae=function(){var e=oe((function*(e,t){var r=null,n=null;try{var i=Object.assign({},t);i.method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var o=yield fetch(e,i),s=yield o.json();null!=s&&s.error?(n=s).error_uri=new URL(e).pathname:r=s}catch(t){n={error:a.UNREACHABLE,error_description:t.message,error_uri:new URL(e).pathname}}if(n)throw n;return r}));return function(t,r){return e.apply(this,arguments)}}();var se=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return oe((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return oe((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return oe((function*(){window.localStorage.setItem("".concat(e).concat(r._env),t)}))()}getItemSync(e){return window.localStorage.getItem("".concat(e).concat(this._env))}removeItemSync(e){window.localStorage.removeItem("".concat(e).concat(this._env))}setItemSync(e,t){window.localStorage.setItem("".concat(e).concat(this._env),t)}};function ce(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class ue{constructor(e){this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new E({clientId:this.clientId}),this.credentials=e.credentials||null}getStorageCredentialsSync(){var e=null,t=this.storage.getItemSync(this.tokenSectionName);if(null!=t)try{var r;null!==(r=e=JSON.parse(t))&&void 0!==r&&r.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(t){this.storage.removeItem(this.tokenSectionName),e=null}return e}setCredentials(e){var t=this;return oe((function*(){if(null!=e&&e.expires_in){if(null!=e&&e.expires_at||(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30))),t.storage){var r=JSON.stringify(e);yield t.storage.setItem(t.tokenSectionName,r)}t.credentials=e}else t.storage&&(yield t.storage.removeItem(t.tokenSectionName)),t.credentials=null}))()}setAccessKeyCredentials(e){this.accessKeyCredentials=e,e.scope===f&&(this.credentials=e)}getCredentials(){var e=this;return oe((function*(){return e.singlePromise.run("getCredentials",oe((function*(){if(ce(e.credentials)){var{credentials:t,isAccessKeyCredentials:r}=yield e.getStorageCredentials();if(r)return t;e.credentials=t}return e.credentials})))}))()}getStorageCredentials(){var e=this;return oe((function*(){return e.singlePromise.run("_getStorageCredentials",oe((function*(){var t=null,r=!1,n=yield e.storage.getItem(e.tokenSectionName);if(n)try{var i;null!==(i=t=JSON.parse(n))&&void 0!==i&&i.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}else t=e.accessKeyCredentials||null,r=!0;return{credentials:t,isAccessKeyCredentials:r}})))}))()}}class le{constructor(e){var t;this.initializePromise=null,this.lockAcquired=!1,this.pendingInLock=[],this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.apiPath=e.apiPath||s,this.clientId=e.clientId,this.i18n=e.i18n,this.eventBus=e.eventBus,this.singlePromise=new E({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,le.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=ae,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||se,this.localCredentials=new ue({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage,clientId:e.clientId}),this.clientSecret=e.clientSecret,e.clientId&&(this.basicAuth="Basic ".concat(function(e){for(var t,r,n,i,o="",a=0,s=(e=String(e)).length%3;a<e.length;){if((r=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255||(i=e.charCodeAt(a++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");o+=I.charAt((t=r<<16|n<<8|i)>>18&63)+I.charAt(t>>12&63)+I.charAt(t>>6&63)+I.charAt(63&t)}return s?o.slice(0,s-3)+"===".substring(s):o}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{R()&&(this.useWxCloud=e.useWxCloud,void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud))}catch(e){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc,this.onCredentialsError=e.onCredentialsError,this.getInitialSession=e.getInitialSession,this.onInitialSessionObtained=e.onInitialSessionObtained,this.logDebugMessages=null!==(t=e.debug)&&void 0!==t&&t,X.on("lang_change",e=>{var t;this.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||this.i18n})}setGetInitialSession(e){this.getInitialSession=e}setOnInitialSessionObtained(e){this.onInitialSessionObtained=e}initialize(e){var t=this;return oe((function*(){return t.initializePromise?yield t.initializePromise:void 0!==e?(t.initializePromise=e,yield t.initializePromise):(t.initializePromise=oe((function*(){return yield t._acquireLock(-1,oe((function*(){return yield t._initialize()})))}))(),yield t.initializePromise)}))()}setCredentials(e){var t=this;return oe((function*(){return yield t.initializePromise,t._acquireLock(-1,oe((function*(){return t.localCredentials.setCredentials(e)})))}))()}setAccessKeyCredentials(e){return this.localCredentials.setAccessKeyCredentials(e)}getAccessToken(){var e=this;return oe((function*(){yield e.initializePromise;var t=yield e.getCredentials();if((null==t?void 0:t.scope)===f)return Promise.resolve(t.access_token);if(null!=t&&t.access_token)return Promise.resolve(t.access_token);var r={error:a.UNAUTHENTICATED};return Promise.reject(r)}))()}request(e,t){var r=this;return oe((function*(){var n,i,o,s;t||(t={});var c=r.formatRetry(t.retry,r.retry);if(t.headers=re(re({},t.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(i=r.i18n)||void 0===i?void 0:i.lang}),r.headers&&(t.headers=re(re({},r.headers),t.headers)),t.headers["x-request-id"]||(t.headers["x-request-id"]=p()),!t.headers["x-device-id"]){var u=yield r.getDeviceId();t.headers["x-device-id"]=u}if(null!==(o=t)&&void 0!==o&&o.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(s=t)&&void 0!==s&&s.withCredentials){var l=t.getCredentials?yield t.getCredentials():yield r.getCredentials();l&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(l.access_token)):t.headers.Authorization="".concat(l.token_type," ").concat(l.access_token))}else r.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(r.clientId));e.startsWith("/")&&(e="".concat(r.apiOrigin).concat(r.apiPath).concat(e));for(var d=null,h=c+1,f=0;f<h;f++){try{var v;if(null!==(v=d=t.useWxCloud||r.useWxCloud?yield r.wxCloudCallFunction(e,t):yield r.baseRequest(e,t))&&void 0!==v&&v.code)throw{error:d.code,error_description:d.message,error_uri:new URL(e).pathname};break}catch(e){try{e.requestId=e.requestId||t.headers["x-request-id"]||""}catch(e){}if(t.withCredentials&&e&&e.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(e);if(f===c||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep(le.retryInterval)}return d}))()}wxCloudCallFunction(e,t){var r=this;return oe((function*(){var n=null,i=null;try{var o,s="";try{s=yield wx.getRendererUserAgent()}catch(e){}var{result:c}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:re({origin:"https://servicewechat.com","User-Agent":s},t.headers),body:t.body}});null!=c&&null!==(o=c.body)&&void 0!==o&&o.error_code?(i=null==c?void 0:c.body).error_uri=(0,v.y)(e):n=null==c?void 0:c.body}catch(t){i={error:a.UNREACHABLE,error_description:t.message,error_uri:(0,v.y)(e)}}if(i)throw i;return n}))()}getCredentials(){var e=this;return oe((function*(){return yield e.initializePromise,e._acquireLock(-1,oe((function*(){return e._getCredentials()})))}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}return t.scope}))()}getGroups(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}return t.groups}))()}refreshToken(e,t){var r=this;return oe((function*(){return yield r.initializePromise,r._acquireLock(-1,oe((function*(){return r._refreshToken(e,t)})))}))()}_refreshToken(e,t){var r=this;return oe((function*(){return r.singlePromise.run("_refreshToken",oe((function*(){if((null==e?void 0:e.scope)===f)return e;if(!e||!e.refresh_token){var n,i="no refresh token found in credentials";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:i}),r.unAuthenticatedError(i)}try{var o,s=yield r.refreshTokenFunc(e.refresh_token,e);return yield r.localCredentials.setCredentials(s),null===(o=r.eventBus)||void 0===o||o.fire(d.AUTH_STATE_CHANGED,{event:l.TOKEN_REFRESHED}),s}catch(e){var c;if(null!=t&&t.throwError)throw e;if(e.error===a.INVALID_GRANT){var u;yield r.localCredentials.setCredentials(null);var h=e.error_description;return null===(u=r.onCredentialsError)||void 0===u||u.call(r,{msg:h}),r.unAuthenticatedError(h)}return null===(c=r.onCredentialsError)||void 0===c||c.call(r,{msg:e.error_description}),Promise.reject(e)}})))}))()}anonymousLogin(e){var t=this;return oe((function*(){return t.singlePromise.run("_anonymousLogin",oe((function*(){if(t.anonymousSignInFunc){var r=yield t.anonymousSignInFunc(e);e=r||(yield t.localCredentials.getCredentials())}else e=yield t.anonymousSignIn(e);return e})))}))()}checkRetry(e){var t=null;if(("number"!=typeof e||e<le.minRetry||e>le.maxRetry)&&(t={error:a.UNREACHABLE,error_description:"wrong options param: retry"}),t)throw t;return e}formatRetry(e,t){return void 0===e?t:this.checkRetry(e)}sleep(e){return oe((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var r=this;return oe((function*(){return r.singlePromise.run("_anonymous",oe((function*(){if(!e||"anonymous"!==e.scope)return r.unAuthenticatedError("no anonymous in credentials");try{var n=yield r.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield r.localCredentials.setCredentials(n),n}catch(e){return e.error===a.INVALID_GRANT?(yield r.localCredentials.setCredentials(null),r.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,r){var n=this;return oe((function*(){if(void 0===e||""===e){var o,a="refresh token not found";return null===(o=n.onCredentialsError)||void 0===o||o.call(n,{msg:a}),n.unAuthenticatedError(a)}var s=t.AUTH_TOKEN_URL;return"v2"===(null==r?void 0:r.version)&&(s=i.AUTH_TOKEN_URL),re(re({},yield n.request(s,{method:"POST",body:{client_id:n.clientId,client_secret:n.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==r?void 0:r.version)||"v1"})}))()}getDeviceId(){var e=this;return oe((function*(){if(e.deviceID)return e.deviceID;var t=yield e.storage.getItem("device_id");return"string"==typeof t&&t.length>=16&&t.length<=48||(t=p(),yield e.storage.setItem("device_id",t)),e.deviceID=t,t}))()}unAuthenticatedError(e){var t={error:a.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}_debug(){if(this.logDebugMessages){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];console.log("[OAuth2Client]",...t)}}_initialize(){var e=this;return oe((function*(){try{if(!e.getInitialSession)return e._debug("#_initialize()","no getInitialSession callback set, skipping"),{error:null};e._debug("#_initialize()","calling getInitialSession callback");try{var{data:t,error:r}=yield e.getInitialSession();if(null!=t&&t.session&&(e._debug("#_initialize()","session obtained from getInitialSession",t.session),yield e.localCredentials.setCredentials(null==t?void 0:t.session)),e.onInitialSessionObtained){e._debug("#_initialize()","calling onInitialSessionObtained callback");try{yield e.onInitialSessionObtained(t,r)}catch(t){e._debug("#_initialize()","error in onInitialSessionObtained",t)}}return r?(e._debug("#_initialize()","error from getInitialSession",r),{error:r}):{error:null}}catch(t){return e._debug("#_initialize()","exception during getInitialSession",t),{error:t instanceof Error?t:new Error(String(t))}}}catch(r){return e._debug("#_initialize()","unexpected error",r),{error:r instanceof Error?r:new Error(String(r))}}finally{e._debug("#_initialize()","end")}}))()}_acquireLock(e,t){var r=this;return oe((function*(){r._debug("#_acquireLock","begin",e);try{if(r.lockAcquired){var n=r.pendingInLock.length?r.pendingInLock[r.pendingInLock.length-1]:Promise.resolve(),i=oe((function*(){return yield n,yield t()}))();return r.pendingInLock.push(oe((function*(){try{yield i}catch(e){}}))()),i}r._debug("#_acquireLock","acquiring lock for client",r.clientId);try{r.lockAcquired=!0;var o=t();for(r.pendingInLock.push(oe((function*(){try{yield o}catch(e){}}))()),yield o;r.pendingInLock.length;){var a=[...r.pendingInLock];yield Promise.all(a),r.pendingInLock.splice(0,a.length)}return yield o}finally{r._debug("#_acquireLock","releasing lock for client",r.clientId),r.lockAcquired=!1}}finally{r._debug("#_acquireLock","end")}}))()}_getCredentials(){var e=this;return oe((function*(){var t=yield e.localCredentials.getCredentials();if(t.scope===f)return t;if(!t){var r,n="credentials not found";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}if(ce(t))if(t.refresh_token)try{t=yield e._refreshToken(t)}catch(r){var i;if("anonymous"!==t.scope)return null===(i=e.onCredentialsError)||void 0===i||i.call(e,{msg:r.error_description}),Promise.reject(r);t=yield e.anonymousLogin(t)}else{if("anonymous"!==t.scope){var o,a="no refresh token found in credentials";return null===(o=e.onCredentialsError)||void 0===o||o.call(e,{msg:a}),e.unAuthenticatedError(a)}t=yield e.anonymousLogin(t)}return t}))()}}le.defaultRetry=2,le.minRetry=0,le.maxRetry=5,le.retryInterval=1e3;var de=r(689),he=r(616);function fe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function pe(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?fe(Object(r),!0).forEach((function(t){ve(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):fe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ve(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function _e(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function ye(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){_e(o,n,i,a,s,"next",e)}function s(e){_e(o,n,i,a,s,"throw",e)}a(void 0)}))}}var ge=(e,t)=>{var r;return function(){for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];clearTimeout(r),r=setTimeout(()=>e.apply(null,i),t)}},Ee=new de.CloudbaseEventEmitter,Ie="resolveCaptchaData",me="position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.5);z-index:999",Oe="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",Se="margin-bottom:15px",be="display:flex;align-items:center;justify-content:space-between;margin-bottom:15px",Re="width:100%;height:auto;border:1px solid #eee",Ae="padding:10px 8px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer;flex:1;white-space:nowrap;margin-left:10px",Te="width:100%;padding:14px 16px;margin-bottom:15px;box-sizing:border-box;border:2px solid #e8ecf4;border-radius:10px;font-size:15px",Ce="width:100%;padding:10px;background:#007bff;color:#fff;border:none;border-radius:4px;cursor:pointer",we="background:#6c757d;cursor:not-allowed",Pe=e=>{var{oauthInstance:t,captchaState:r}=e,n=function(){var e=ye((function*(){try{var e=yield t.createCaptchaData({state:r.state});r=pe(pe({},r),{},{captchaData:e.data,token:e.token}),document.getElementById("captcha-image").src=e.data}catch(e){console.error("刷新图形验证码失败",e)}}));return function(){return e.apply(this,arguments)}}(),i=(e,t,r)=>{var n=document.createElement(e);return t&&(n.style.cssText=t),r&&(n.textContent=r),n},o=i("div",me),a=i("div",Oe);a.appendChild(i("p",Se,"请输入你看到的字符:"));var s=i("div",be),c=i("img",Re);c.id="captcha-image",c.src=r.captchaData,s.appendChild(c);var u=i("button",Ae,"刷新");u.onclick=ge(ye((function*(){u.textContent="加载中...",u.disabled=!0,u.style.cssText="".concat(Ae,";").concat(we);try{yield n()}finally{u.textContent="刷新",u.disabled=!1,u.style.cssText=Ae}})),500),s.appendChild(u),a.appendChild(s);var l=i("input",Te);l.type="text",l.placeholder="输入字符",l.maxLength=4,a.appendChild(l);var d=i("div","color:#dc3545;font-size:12px;margin-bottom:10px;display:none;padding:8px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px");a.appendChild(d);var h=e=>{d.textContent=e,d.style.display="block"},f=i("button",Ce,"确定");f.onclick=ge(ye((function*(){var e=l.value.trim();if(e){d.style.display="none",f.textContent="验证中...",f.disabled=!0,f.style.cssText="".concat(Ce,";").concat(we);try{var i=yield t.verifyCaptchaData({token:r.token,key:e});Ee.fire(Ie,i),console.log("图形验证码校验成功"),document.body.removeChild(o),document.body.removeChild(a)}catch(e){console.error("图形验证码校验失败",e);var s=e.error_description||"图形验证码校验失败";h(s),l.value="",l.focus(),yield n()}finally{f.textContent="确定",f.disabled=!1,f.style.cssText=Ce}}else h("请输入字符")})),500),a.appendChild(f),document.body.appendChild(o),document.body.appendChild(a)},Ne=function(){var e=ye((function*(e,t){var{captchaData:r,state:n,token:i}=(0,he.parseCaptcha)(e);return Pe({oauthInstance:t,captchaState:{captchaData:r,state:n,token:i}}),new Promise(e=>{console.log("等待图形验证码校验结果..."),Ee.on(Ie,t=>{e(null==t?void 0:t.data)})})}));return function(t,r){return e.apply(this,arguments)}}();function Ue(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function De(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){Ue(o,n,i,a,s,"next",e)}function s(e){Ue(o,n,i,a,s,"throw",e)}a(void 0)}))}}class Le{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=se),this.config=e,this.tokenSectionName="captcha_".concat(e.clientId||e.env)}isMatch(){var e,t;return(null===(e=this.config)||void 0===e||null===(e=e.adapter)||void 0===e||null===(t=e.isMatch)||void 0===t?void 0:t.call(e))||R()}request(e,t){var r=this;return De((function*(){t||(t={}),t.method||(t.method="GET");var n,i="".concat(t.method,":").concat(e),o=e;t.withCaptcha&&(o=yield r.appendCaptchaTokenToURL(e,i,!1));try{n=yield r.config.request(o,t)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(e=yield r.appendCaptchaTokenToURL(e,i,n.error===a.CAPTCHA_INVALID),r.config.request(e,t)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){return e=>Ne(e,this.config.oauthInstance)}getCaptchaToken(e,r){var n=this;return De((function*(){if(!e){var i=yield n.findCaptchaToken();if(i)return i}var o=yield n.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:""},withCredentials:!1}),a="".concat(o.data,"?state=").concat(encodeURIComponent(r),"&token=").concat(encodeURIComponent(o.token)),s=yield n.config.openURIWithCallback(a);return n.saveCaptchaToken(s),s.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return De((function*(){var i=yield n.getCaptchaToken(r,t);return e.indexOf("?")>0?e+="&captcha_token=".concat(i):e+="?captcha_token=".concat(i),e}))()}saveCaptchaToken(e){var t=this;return De((function*(){e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10));var r=JSON.stringify(e);yield t.config.storage.setItem(t.tokenSectionName,r)}))()}findCaptchaToken(){var e=this;return De((function*(){var t=yield e.config.storage.getItem(e.tokenSectionName);if(null!=t)try{var r=JSON.parse(t);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(t){return yield e.config.storage.removeItem(e.tokenSectionName),null}return null}))()}}const xe=class{constructor(e){if(this.params={},"string"==typeof e)this.parse(e);else if(e&&"object"==typeof e)for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&this.append(t,e[t])}parse(e){e.split("&").forEach(e=>{var[t,r]=e.split("=").map(decodeURIComponent);this.append(t,r)})}append(e,t){this.params[e]?this.params[e]=this.params[e].concat([t]):this.params[e]=[t]}get(e){return this.params[e]?this.params[e][0]:null}getAll(e){return this.params[e]||[]}delete(e){delete this.params[e]}has(e){return Object.prototype.hasOwnProperty.call(this.params,e)}set(e,t){this.params[e]=[t]}toString(){var e=this,t=[],r=function(r){Object.prototype.hasOwnProperty.call(e.params,r)&&e.params[r].forEach(e=>{t.push("".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(e)))})};for(var n in this.params)r(n);return t.join("&")}};var ke;!function(e){e.PROVIDER_NOT_ENABLED="PROVIDER_NOT_ENABLED",e.INVALID_CREDENTIALS="INVALID_CREDENTIALS",e.USER_NOT_FOUND="USER_NOT_FOUND",e.USER_STATUS_ABNORMAL="USER_STATUS_ABNORMAL",e.SERVICE_ERROR="SERVICE_ERROR",e.INVALID_PARAMS="INVALID_PARAMS",e.AUTH_METHOD_MISMATCH="AUTH_METHOD_MISMATCH",e.UNKNOWN="UNKNOWN"}(ke||(ke={}));var je="https://tcb.cloud.tencent.com/dev?envId=#/identity/login-manage",qe="https://docs.cloudbase.net/api-reference/webv3-next/initialization";class He extends Error{constructor(e,t){var r,n=e.error_description||e.message;super(n),this.__isAuthError=!0,this.name="AuthError",this.status=e.error,this.code=e.error_code,this.requestId=e.requestId,this.category=function(e,t){if(!e&&!t)return ke.UNKNOWN;try{var r=(e||"").toLowerCase();return t===a.FAILED_PRECONDITION||t===a.PROVIDER_NOT_ENABLED||t===a.LOGIN_METHOD_DISABLED||r.includes("身份源")||r.includes("开启")||r.includes("identity provider")||r.includes("provider not enabled")||r.includes("login method")||r.includes("登录方式")||r.includes("not enabled")||r.includes("未开启")||r.includes("未启用")||r.includes("请联系开发者")||r.includes("anonymous login is not enabled")||r.includes("匿名登录未开启")?ke.PROVIDER_NOT_ENABLED:t===a.INVALID_PASSWORD||t===a.INVALID_GRANT||t===a.INVALID_VERIFICATION_CODE||t===a.INVALID_USERNAME_OR_PASSWORD||t===a.INVALID_CREDENTIALS||t===a.WRONG_PASSWORD||t===a.UNAUTHENTICATED||t===a.INVALID_TWO_FACTOR||t===a.INVALID_TWO_FACTOR_RECOVERY||t===a.PASSWORD_NOT_SET||r.includes("密码不正确")||r.includes("password")||r.includes("invalid_password")||r.includes("凭据")||r.includes("credentials")||r.includes("验证码")||r.includes("verification")||r.includes("invalid_verification_code")||r.includes("invalid_username_or_password")||r.includes("username or password")||r.includes("用户名或密码")||r.includes("wrong password")||r.includes("incorrect password")?ke.INVALID_CREDENTIALS:t===a.NOT_FOUND||t===a.USER_NOT_FOUND||r.includes("用户不存在")||r.includes("not found")||r.includes("user not found")||r.includes("不存在")||r.includes("no such user")||r.includes("user does not exist")?ke.USER_NOT_FOUND:t===a.USER_BLOCKED||t===a.USER_PENDING||t===a.UNDER_REVIEW||t===a.INVALID_STATUS||r.includes("被封禁")||r.includes("blocked")||r.includes("pending")||r.includes("审核")||r.includes("review")||r.includes("locked")||r.includes("已锁定")?ke.USER_STATUS_ABNORMAL:t===a.SERVER_ERROR||t===a.UNAVAILABLE||t===a.TEMPORARILY_UNAVAILABLE||t===a.INTERNAL||t===a.UNREACHABLE||t===a.DEADLINE_EXCEEDED||t===a.DATA_LOSS||r.includes("network")||r.includes("timeout")||r.includes("服务")||r.includes("timed out")||r.includes("超时")?ke.SERVICE_ERROR:t===a.INVALID_ARGUMENT||t===a.INVALID_REQUEST||t===a.INVALID_SCOPE||t===a.INVALID_REQUEST_URI||t===a.INVALID_REQUEST_OBJECT?ke.INVALID_PARAMS:t===a.PERMISSION_DENIED||t===a.ACCESS_DENIED||t===a.UNAUTHORIZED_CLIENT?ke.PROVIDER_NOT_ENABLED:ke.UNKNOWN}catch(e){return t}}(n,this.status),this.helpMessage=function(e,t){var r=(null==t?void 0:t.method)||"signIn",n={signInWithPassword:"「用户名密码登录」",signInAnonymously:"「匿名登录」",signInWithOtp:"「短信验证码登录」或「邮箱验证码登录」",signUp:"「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"对应的第三方身份源",signInWithIdToken:"对应的第三方身份源",signInWithOpenId:"「微信小程序 OpenID 登录」",signInWithPhoneAuth:"「微信小程序手机号授权登录」",signInWithCustomTicket:"「自定义登录」"}[r]||"对应的登录方式";switch(e){case ke.PROVIDER_NOT_ENABLED:return"[CloudBase Auth] 登录方式未开启\n\n"+" 当前调用的 ".concat(r,"() 所需的登录方式尚未在云开发控制台启用。\n")+" 需要开启的登录方式:".concat(n,"\n")+"\n 请按以下步骤开启:\n"+" 1. 打开云开发控制台:".concat(je,"\n")+" 2. 选择对应的云开发环境\n 3. 进入「登录授权」页面,在「登录方式」或「身份源列表」中开启所需的登录方式\n\n 各登录方法与所需登录方式的对应关系:\n - signInWithPassword → 「用户名密码登录」\n - signInAnonymously → 「匿名登录」\n - signInWithOtp/signUp → 「短信验证码登录」或「邮箱验证码登录」\n - signInWithOAuth/signInWithIdToken → 对应的第三方身份源\n\n 如使用 CLI/MCP 工具,可通过 auth 工具查询和配置身份源状态。\n"+" 更多帮助请参考文档:".concat(qe);case ke.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 ke.USER_NOT_FOUND:return"[CloudBase Auth] 用户不存在\n\n 请检查以下项目:\n 1. 确认用户名/邮箱/手机号是否正确\n 2. 确认是在正确的云开发环境(envId)下操作\n 3. 如果是新用户,请先通过 auth.signUp() 注册\n"+" 4. 也可在云开发控制台手动创建用户:".concat(je,"\n")+"\n 提示:不同环境(开发/测试/生产)的用户库是隔离的,请确认 envId 正确。";case ke.USER_STATUS_ABNORMAL:return"[CloudBase Auth] 用户状态异常\n\n 当前用户账号可能处于以下状态之一:\n - 账号已被封禁\n - 账号正在审核中\n - 账号已被锁定(多次密码错误)\n\n"+" 请联系管理员在云开发控制台检查用户状态:".concat(je);case ke.SERVICE_ERROR:return"[CloudBase Auth] 服务异常\n\n 请检查以下项目:\n 1. 网络连接是否正常\n 2. 云开发环境是否正常运行\n 3. 稍后重试,如持续失败请联系技术支持\n\n 提示:如果是超时错误,请检查网络环境和请求频率。";case ke.INVALID_PARAMS:return"[CloudBase Auth] 参数错误\n\n 请检查传入的参数是否符合要求,参考 API 文档确认各参数的格式和约束。\n"+" 文档地址:".concat(qe);case ke.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(je);default:return"[CloudBase Auth] 操作失败\n\n 如果问题持续存在,建议:\n"+" 1. 检查云开发控制台的认证配置:".concat(je,"\n")+" 2. 到官方问答社区提问:https://cnb.cool/tencent/cloud/cloudbase/community/-/issues\n"+" 3. 查阅文档:".concat(qe)}}(this.category,t),this.loginMethodHint=(r=null==t?void 0:t.method)&&{signInWithPassword:"当前使用「用户名密码登录」,需确保:\n ✓ 控制台已开启「用户名密码登录」\n ✓ 用户已注册且凭据正确\n 如果不需要用户系统,建议改用 auth.signInAnonymously()",signInAnonymously:"当前使用「匿名登录」,需确保:\n ✓ 控制台已开启「匿名登录」\n 注意:匿名用户无需用户名密码,适用于快速体验或临时访问场景",signInWithOtp:"当前使用「OTP 验证码登录」,需确保:\n ✓ 控制台已开启「短信验证码登录」或「邮箱验证码登录」",signInWithOAuth:"当前使用「第三方 OAuth 登录」,需确保:\n ✓ 控制台已配置并开启对应的第三方身份源"}[r]||""}}var Ve=["provider_redirect_uri","other_params"];function Me(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Ge(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Me(Object(r),!0).forEach((function(t){We(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Me(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function We(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Be(e,t,r,n,i,o,a){try{var s=e[o](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,i)}function Fe(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){Be(o,n,i,a,s,"next",e)}function s(e){Be(o,n,i,a,s,"throw",e)}a(void 0)}))}}function Ke(e,t){return Ye.apply(this,arguments)}function Ye(){return(Ye=Fe((function*(e,t){var n=function(){var e=Fe((function*(){try{return r(3)}catch(e){try{return yield Promise.resolve().then(r.bind(r,3))}catch(e){return}}}));return function(){return e.apply(this,arguments)}}();try{var i;if(((null==t||null===(i=t.root)||void 0===i?void 0:i.globalThis)||globalThis).IS_MP_BUILD)return;0}catch(t){if(e)return n()}}))).apply(this,arguments)}class ze{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new xe(e).toString()}constructor(e){var{request:t}=e,r=e.credentialsClient;if(!r){var n={apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,storage:e.storage,env:e.env,baseRequest:e.baseRequest,anonymousSignInFunc:e.anonymousSignInFunc,wxCloud:e.wxCloud,onCredentialsError:e.onCredentialsError,headers:e.headers||{},i18n:e.i18n,debug:e.debug};r=new le(n)}if(!t){var i=r.request.bind(r),o=new Le(Ge({env:e.env,clientId:e.clientId,request:i,storage:e.storage,adapter:e.adapter,oauthInstance:this},e.captchaOptions));t=o.request.bind(o)}this.config={env:e.env,apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||se,adapter:e.adapter}}getParamsByVersion(e,r){var n,o=(0,v.I)(e),a=(null===(n={v2:i}[null==o?void 0:o.version])||void 0===n?void 0:n[r])||t[r];return o&&delete o.version,{params:o,url:a}}signIn(e){var t=this;return Fe((function*(){var r=e.version||"v1",n=t.getParamsByVersion(e,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var i=yield t.getEncryptParams(n.params),o=yield t.config.request(n.url,{method:"POST",body:i});return yield t.config.credentialsClient.setCredentials(Ge(Ge({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var e=arguments,r=this;return Fe((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=e.length>1&&void 0!==e[1]&&e[1],o=yield r.config.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:n,useWxCloud:i});return yield r.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(e){var r=this;return Fe((function*(){var n=yield r.config.request(t.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signOut(e){var r=this;return Fe((function*(){var n={};if(e){try{n=yield r.config.request(t.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield r.config.credentialsClient.setCredentials(),n}var i=yield r.config.credentialsClient.getAccessToken(),o=yield r.config.request(t.AUTH_REVOKE_URL,{method:"POST",body:{token:i}});return yield r.config.credentialsClient.setCredentials(),Promise.resolve(o)}))()}revokeAllDevices(){var e=this;return Fe((function*(){yield e.config.request(t.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var r=this;return Fe((function*(){yield r.config.request(t.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,r){var n=this;return Fe((function*(){var i=!1;"CUR_USER"===e.target?i=!0:(yield n.hasLoginState())&&(i=!0);var o=(0,v.I)(e);return o.phone_number&&!/^\+\d{1,3}\s+\d+/.test(o.phone_number)&&(o.phone_number="+86 ".concat(o.phone_number)),n.config.request(t.VERIFICATION_URL,{method:"POST",body:o,withCaptcha:(null==r?void 0:r.withCaptcha)||!1,withCredentials:i})}))()}verify(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"VERIFY_URL"),n=yield t.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==e?void 0:e.version)&&(yield t.config.credentialsClient.setCredentials(Ge(Ge({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var r=this;return Fe((function*(){var{provider_redirect_uri:n,other_params:i={}}=e,o=function(e,t){if(null==e)return{};var r,n,i=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(n=0;n<o.length;n++)r=o[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}(e,Ve);n&&!o.redirect_uri&&(o.redirect_uri=n);var a="".concat(t.PROVIDER_URI_URL,"?").concat(ze.parseParamsToSearch(o));return Object.keys(i).forEach(e=>{var t=i[e];("sign_out_uri"!==e||(null==t?void 0:t.length)>0)&&(a+="&other_params[".concat(e,"]=").concat(encodeURIComponent(t)))}),r.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var r=arguments,n=this;return Fe((function*(){var i=r.length>1&&void 0!==r[1]&&r[1];return n.config.request(t.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:i})}))()}patchProviderToken(e){var r=this;return Fe((function*(){return r.config.request(t.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return Fe((function*(){var n=t.length>1&&void 0!==t[1]&&t[1],i=r.getParamsByVersion(e,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=yield r.config.request(i.url,{method:"POST",body:i.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(Ge(Ge({},o),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(o)}))()}toBindIdentity(e){var t=this;return Fe((function*(){var r,n,i,o=e.credentials||(yield t.config.credentialsClient.localCredentials.getCredentials());try{yield t.bindWithProvider({provider_token:e.provider_token},o),r={data:{type:h.BIND_IDENTITY,provider:e.provider},error:null}}catch(e){r={data:{type:h.BIND_IDENTITY},error:new He(e)}}e.fireEvent&&(null===(n=t.config.eventBus)||void 0===n||null===(i=n.fire)||void 0===i||i.call(n,d.AUTH_STATE_CHANGED,{event:l.BIND_IDENTITY,info:r}));return r}))()}getInitialSession(){var e=this;return Fe((function*(){var t={};try{var r,n,i,o,a;if("undefined"==typeof window||"undefined"==typeof document)return{data:null,error:null};var s=new URLSearchParams(null===(r=location)||void 0===r?void 0:r.search),c=s.get("code"),u=s.get("state");if(!c||!u)return{data:null,error:null};var l=null;try{l=JSON.parse(sessionStorage.getItem(u)||"null")}catch(e){}t={type:null===(n=l)||void 0===n?void 0:n.type};var d=s.get("error"),f=s.get("error_description");if(d||f)return{data:t,error:new He({message:f||d||"Unknown error from OAuth provider"})};var p=(null===(i=l)||void 0===i?void 0:i.provider)||s.get("provider");if(!p)return{data:t,error:new He({message:"Provider is required for OAuth verification"})};var v,_,y=location.origin+location.pathname,{provider_token:g}=yield e.grantProviderToken({provider_id:p,provider_redirect_uri:y,provider_code:c}),E=null;if(l.type===h.BIND_IDENTITY)v=yield e.config.credentialsClient.localCredentials.getCredentials(),_=yield e.toBindIdentity({provider:p,provider_token:g,credentials:v});else if(l.type===h.SIGN_IN){_=e.getParamsByVersion({provider:p},"AUTH_SIGN_IN_WITH_PROVIDER_URL"),v=yield e.config.request(_.url,{method:"POST",body:{provider_token:g}});try{E=yield e.getUserInfo({credentials:v})}catch(e){console.error("get user info error",e)}_={data:Ge(Ge({},t),{},{session:v,user:E}),error:null}}s.delete("code"),s.delete("state"),s.delete("provider"),e.restoreUrlState(void 0===(null===(o=l)||void 0===o?void 0:o.search)?"?".concat(s.toString()):l.search,(null===(a=l)||void 0===a?void 0:a.hash)||location.hash);try{sessionStorage.removeItem(u)}catch(e){}return _}catch(e){return{data:t,error:new He(e)}}}))()}signInCustom(e){var r=this;return Fe((function*(){var n=yield r.config.request(t.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signInWithWechat(){var e=arguments,r=this;return Fe((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=yield r.config.request(t.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:n});return yield r.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}bindWithProvider(e,r){var n=this;return Fe((function*(){return n.config.request(t.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0,getCredentials:r?()=>r:void 0})}))()}getUserProfile(e){var t=this;return Fe((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return Fe((function*(){var r,n,i=e.length>0&&void 0!==e[0]?e[0]:{},o=t.getParamsByVersion(i,"USER_ME_URL");if(null!==(r=o.params)&&void 0!==r&&r.query){var a=new xe(o.params.query);o.url+="?".concat(a.toString())}var s=yield t.config.request(o.url,{method:"GET",withCredentials:!0,getCredentials:i.credentials?()=>i.credentials:void 0});if(s.sub&&(s.uid=s.sub),null!==(n=s.providers)&&void 0!==n&&n.length)try{if("undefined"!=typeof wx&&wx.getAccountInfoSync){var c,u=null===(c=wx.getAccountInfoSync().miniProgram)||void 0===c?void 0:c.appId,l=s.providers.find(e=>e.id===u);null!=l&&l.provider_user_id&&(s.open_id=l.provider_user_id)}}catch(e){}return s}))()}getWedaUserInfo(){var e=this;return Fe((function*(){return yield e.config.request(t.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(ze.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return Fe((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return Fe((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var r=this;return Fe((function*(){return r.config.request(t.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return Fe((function*(){var r=t.getParamsByVersion(e,"AUTH_TOKEN_URL");return t.config.request(r.url,{method:"POST",body:r.params})}))()}getProviders(){var e=this;return Fe((function*(){return e.config.request(t.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return Fe((function*(){var r=yield t.sudo({password:e.old_password});return t.setPassword({sudo_token:r.sudo_token,new_password:e.new_password})}))()}sudo(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var r=this;return Fe((function*(){return e.target="CUR_USER",r.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var r=this;return Fe((function*(){return r.config.request("".concat(t.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var r=this;return Fe((function*(){return r.config.request(t.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var r=this;return Fe((function*(){return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var r=this;return Fe((function*(){var n=new xe(e);return r.config.request("".concat(t.USER_QUERY_URL,"?").concat(n.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return Fe((function*(){var t=e.getCustomSignTicketFn;if(!t)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield t();return e.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(e){var r=this;return Fe((function*(){return r.config.request(t.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var r=this;return Fe((function*(){return r.config.request(t.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var r=this;return Fe((function*(){return r.config.request(t.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var r=this;return Fe((function*(){return r.config.request(t.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var r=this;return Fe((function*(){var n="".concat(t.AUTHORIZE_INFO_URL,"?").concat(ze.parseParamsToSearch(e)),i=!0,o=!1;return(yield r.hasLoginState())&&(o=!0,i=!1),r.config.request(n,{method:"GET",withBasicAuth:i,withCredentials:o})}))()}checkUsername(e){var r=this;return Fe((function*(){return r.config.request(t.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var r=this;return Fe((function*(){var n=new xe(e);return r.config.request("".concat(t.CHECK_IF_USER_EXIST,"?").concat(n.toString()),{method:"GET"})}))()}loginScope(){var e=this;return Fe((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return Fe((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return Fe((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(Ge(Ge({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return Fe((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return Fe((function*(){return e.config.request(i.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return Fe((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=(0,v.I)(e),i=yield Ke(r,t.config.adapter);if(!i)return e;var o="",a="";try{var s=yield t.getPublicKey();if(o=s.public_key,a=s.public_key_thumbprint,!o||!a)throw s}catch(e){throw e}return{params:i.getEncryptInfo({publicKey:o,payload:n}),public_key_thumbprint:a}}))()}getProviderSubType(){var e=this;return Fe((function*(){return e.config.request(t.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var r=this;return Fe((function*(){var{token:n,key:i}=e;return r.config.request(t.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:n,key:i},withCredentials:!1})}))()}createCaptchaData(e){var r=this;return Fe((function*(){var{state:n,redirect_uri:i}=e;return r.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:n,redirect_uri:i},withCredentials:!1})}))()}getMiniProgramCode(e){var r=this;return Fe((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var r=this;return Fe((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var r=this;return Fe((function*(){var n="".concat(t.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[e.type],"&limit=").concat(e.limit).concat(e.page_token?"&page_token=".concat(e.page_token):"");return r.config.request(n,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var r=this;return Fe((function*(){var n="",i="",o=yield Ke(!0,r.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield r.getPublicKey();if(n=a.public_key,i=a.public_key_thumbprint,!n||!i)throw a}catch(e){throw e}var s=e.password?o.getEncryptInfo({publicKey:n,payload:e.password}):"",c=o.getEncryptInfo({publicKey:n,payload:e.new_password});return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:s,encrypt_new_password:c,public_key_thumbprint:i}})}))()}modifyPasswordWithoutLogin(e){var t=this;return Fe((function*(){var r="",n="",o=yield Ke(!0,t.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield t.getPublicKey();if(r=a.public_key,n=a.public_key_thumbprint,!r||!n)throw a}catch(e){throw e}var s=e.password?o.getEncryptInfo({publicKey:r,payload:e.password}):"",c=o.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(i.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:s,new_password:c,public_key_thumbprint:n}})}))()}restoreUrlState(e,t){if(void 0!==e)try{var r=new URL(window.location.href);r.search=e,r.hash=t||"",window.history.replaceState(null,"",r.toString()),window.location.replace(r.toString())}catch(e){}}}function Qe(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function Je(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?Qe(Object(r),!0).forEach((function(t){Ze(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):Qe(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function Ze(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}class Xe{constructor(e){var{apiOrigin:t,apiPath:r=s,clientId:n,env:i,storage:o,request:a,baseRequest:c,anonymousSignInFunc:u,wxCloud:l,adapter:d,onCredentialsError:h,headers:f,i18n:p,useWxCloud:v,eventBus:_,detectSessionInUrl:y,debug:g}=e;if(this.detectSessionInUrl=null!=y&&y,this.oauth2client=new le({apiOrigin:t,apiPath:r,clientId:n,env:i,storage:o,baseRequest:c||a,anonymousSignInFunc:u,wxCloud:l,onCredentialsError:h,headers:f||{},i18n:p,useWxCloud:v,eventBus:_,debug:g}),this.authApi=new ze(Je(Je({credentialsClient:this.oauth2client},e),{},{request:a?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d})),y)this.oauth2client.setGetInitialSession(this.authApi.getInitialSession.bind(this.authApi));else try{var E=new URL(window.location.href),I=E.searchParams.get("code"),m=E.searchParams.get("state"),O=JSON.parse(sessionStorage.getItem(m)||"null");I&&m&&null!=O&&O.hash&&(E.hash=O.hash,window.history.replaceState(null,"",E.toString()),window.location.replace(E.toString()))}catch(e){}}initializeSession(e){this.detectSessionInUrl?(this.oauth2client.setOnInitialSessionObtained(e),this.oauth2client.initialize()):this.oauth2client.initialize(Promise.resolve({error:null}))}}})(),n})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/oauth",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
4
4
|
"description": "cloudbase javascript sdk auth componets",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"precommit": "npm run lint"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@cloudbase/utilities": "3.3.
|
|
23
|
+
"@cloudbase/utilities": "3.3.8"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/preset-env": "^7.25.3",
|
|
27
|
-
"@cloudbase/types": "3.3.
|
|
27
|
+
"@cloudbase/types": "3.3.8",
|
|
28
28
|
"@types/node": "^22.5.4",
|
|
29
29
|
"terser-webpack-plugin": "^3.0.2",
|
|
30
30
|
"ts-loader": "^9.5.1",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"@cloudbase/utilities": "2.25.0"
|
|
35
35
|
},
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "4f541a7d5c351d74996ebbde2deeac3bc3ee9eb1"
|
|
38
38
|
}
|
package/src/auth/apis.ts
CHANGED
|
@@ -71,6 +71,8 @@ import { SDKAdapterInterface } from '@cloudbase/adapter-interface'
|
|
|
71
71
|
import { ICloudbaseConfig } from '@cloudbase/types'
|
|
72
72
|
import { AuthError } from './auth-error'
|
|
73
73
|
|
|
74
|
+
declare const wx: any
|
|
75
|
+
|
|
74
76
|
async function getEncryptUtils(isEncrypt, adapter: SDKAdapterInterface) {
|
|
75
77
|
const getUtils = async () => {
|
|
76
78
|
try {
|
|
@@ -689,6 +691,19 @@ export class Auth {
|
|
|
689
691
|
userInfo.uid = userInfo.sub
|
|
690
692
|
}
|
|
691
693
|
|
|
694
|
+
// 优先从 providers 中找到当前小程序 appId 对应的 provider_user_id 作为 open_id
|
|
695
|
+
if (userInfo.providers?.length) {
|
|
696
|
+
try {
|
|
697
|
+
if (typeof wx !== 'undefined' && wx.getAccountInfoSync) {
|
|
698
|
+
const wxAppId = wx.getAccountInfoSync().miniProgram?.appId
|
|
699
|
+
const matched = userInfo.providers.find(p => p.id === wxAppId)
|
|
700
|
+
if (matched?.provider_user_id) {
|
|
701
|
+
userInfo.open_id = matched.provider_user_id
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
} catch (e) {}
|
|
705
|
+
}
|
|
706
|
+
|
|
692
707
|
return userInfo
|
|
693
708
|
}
|
|
694
709
|
|
package/src/auth/models.ts
CHANGED
|
@@ -149,6 +149,7 @@ export interface UserProfile {
|
|
|
149
149
|
province?: string // TODO:
|
|
150
150
|
country?: string // TODO:
|
|
151
151
|
city?: string // TODO:
|
|
152
|
+
open_id?: string;
|
|
152
153
|
}
|
|
153
154
|
|
|
154
155
|
export type UserInfo = UserProfile
|
|
@@ -349,6 +350,7 @@ export interface UserProfile {
|
|
|
349
350
|
avatarUrl?: string
|
|
350
351
|
location?: any
|
|
351
352
|
hasPassword?: boolean
|
|
353
|
+
open_id?: string;
|
|
352
354
|
}
|
|
353
355
|
|
|
354
356
|
interface UserProvider {
|