@cloudbase/oauth 2.19.1 → 2.19.3
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.d.ts +10 -0
- package/dist/cjs/auth/apis.js +6 -1
- package/dist/cjs/auth/consts.d.ts +50 -49
- package/dist/cjs/auth/consts.js +52 -51
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +10 -3
- package/dist/cjs/oauth2client/models.d.ts +5 -0
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +3 -0
- package/dist/cjs/oauth2client/oauth2client.js +94 -59
- package/dist/esm/auth/apis.d.ts +10 -0
- package/dist/esm/auth/apis.js +5 -0
- package/dist/esm/auth/consts.d.ts +50 -49
- package/dist/esm/auth/consts.js +50 -49
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +7 -1
- package/dist/esm/oauth2client/models.d.ts +5 -0
- package/dist/esm/oauth2client/oauth2client.d.ts +3 -0
- package/dist/esm/oauth2client/oauth2client.js +33 -10
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -3
- package/src/auth/apis.ts +10 -0
- package/src/auth/consts.ts +51 -49
- package/src/index.ts +7 -1
- package/src/oauth2client/models.ts +5 -0
- package/src/oauth2client/oauth2client.ts +39 -10
|
@@ -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={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Auth:()=>G,CloudbaseOAuth:()=>M,authModels:()=>s});var r,n,i,o,a,s={};function c(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}e.r(s),function(e){e.AUTH_SIGN_UP_URL="/auth/v1/signup",e.AUTH_TOKEN_URL="/auth/v1/token",e.AUTH_REVOKE_URL="/auth/v1/revoke",e.WEDA_USER_URL="/auth/v1/plugin/weda/userinfo",e.AUTH_RESET_PASSWORD="/auth/v1/reset",e.AUTH_GET_DEVICE_CODE="/auth/v1/device/code",e.CHECK_USERNAME="/auth/v1/checkUsername",e.CHECK_IF_USER_EXIST="/auth/v1/checkIfUserExist",e.GET_PROVIDER_TYPE="/auth/v1/mgr/provider/providerSubType",e.AUTH_SIGN_IN_URL="/auth/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/auth/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v1/signin/with/provider",e.AUTH_SIGN_IN_WITH_WECHAT_URL="/auth/v1/signin/wechat/noauth",e.AUTH_SIGN_IN_CUSTOM="/auth/v1/signin/custom",e.PROVIDER_TOKEN_URL="/auth/v1/provider/token",e.PROVIDER_URI_URL="/auth/v1/provider/uri",e.USER_ME_URL="/auth/v1/user/me",e.AUTH_SIGNOUT_URL="/auth/v1/user/signout",e.USER_QUERY_URL="/auth/v1/user/query",e.USER_PRIFILE_URL="/auth/v1/user/profile",e.USER_BASIC_EDIT_URL="/auth/v1/user/basic/edit",e.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",e.PROVIDER_LIST="/auth/v1/user/provider",e.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",e.PROVIDER_UNBIND_URL="/auth/v1/user/provider",e.CHECK_PWD_URL="/auth/v1/user/sudo",e.SUDO_URL="/auth/v1/user/sudo",e.BIND_CONTACT_URL="/auth/v1/user/contact",e.AUTH_SET_PASSWORD="/auth/v1/user/password",e.AUTHORIZE_DEVICE_URL="/auth/v1/user/device/authorize",e.AUTHORIZE_URL="/auth/v1/user/authorize",e.AUTHORIZE_INFO_URL="/auth/v1/user/authorize/info",e.AUTHORIZED_DEVICES_DELETE_URL="/auth/v1/user/authorized/devices/",e.AUTH_REVOKE_ALL_URL="/auth/v1/user/revoke/all",e.GET_USER_BEHAVIOR_LOG="/auth/v1/user/security/history",e.VERIFICATION_URL="/auth/v1/verification",e.VERIFY_URL="/auth/v1/verification/verify",e.CAPTCHA_DATA_URL="/auth/v1/captcha/data",e.VERIFY_CAPTCHA_DATA_URL="/auth/v1/captcha/data/verify",e.GET_CAPTCHA_URL="/auth/v1/captcha/init",e.GET_MINIPROGRAM_QRCODE="/auth/v1/qrcode/generate",e.GET_MINIPROGRAM_QRCODE_STATUS="/auth/v1/qrcode/get/status"}(r||(r={})),function(e){e.AUTH_SIGN_IN_URL="/auth/v2/signin/username",e.AUTH_TOKEN_URL="/auth/v2/token",e.USER_ME_URL="/auth/v2/user/me",e.VERIFY_URL="/auth/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/auth/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/auth/v2/signin/password/update"}(n||(n={})),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"}(i||(i={})),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"}(o||(o={})),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"}(a||(a={}));var u=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=u(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}},d=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""};function l(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 h(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){l(o,n,i,a,s,"next",e)}function s(e){l(o,n,i,a,s,"throw",e)}a(void 0)}))}}var _=new Map;class v{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",_=_||new Map}run(e,t){var r=this;return h((function*(){e="".concat(r.clientId,"_").concat(e);var n=_.get(e);return n||(n=new Promise((n,i)=>{h((function*(){try{yield r.runIdlePromise();var o=t();n(yield o)}catch(e){i(e)}finally{_.delete(e)}}))()}),_.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var f="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function p(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 y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){g(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function g(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 m(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 I=function(){var e=m((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 a=yield fetch(e,i),s=yield a.json();null!=s&&s.error?(n=s).error_uri=new URL(e).pathname:r=s}catch(t){n={error:o.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 R=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return m((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return m((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return m((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 T(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class S{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new v({clientId:this.clientId})}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 m((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}))()}getCredentials(){var e=this;return m((function*(){return e.singlePromise.run("getCredentials",m((function*(){return T(e.credentials)&&(e.credentials=yield e.getStorageCredentials()),e.credentials})))}))()}getStorageCredentials(){var e=this;return m((function*(){return e.singlePromise.run("_getStorageCredentials",m((function*(){var t=null,r=yield e.storage.getItem(e.tokenSectionName);if(null!=r)try{var n;null!==(n=t=JSON.parse(r))&&void 0!==n&&n.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}return t})))}))()}}class C{constructor(e){this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.clientId=e.clientId,this.singlePromise=new v({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,C.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=I,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||R,this.localCredentials=new S({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+=f.charAt((t=r<<16|n<<8|i)>>18&63)+f.charAt(t>>12&63)+f.charAt(t>>6&63)+f.charAt(63&t)}return s?o.slice(0,s-3)+"===".substring(s):o}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{(function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(e){return!1}return!0})()&&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}setCredentials(e){return this.localCredentials.setCredentials(e)}getAccessToken(){var e=this;return m((function*(){var t=yield e.getCredentials();if(null!=t&&t.access_token)return Promise.resolve(t.access_token);var r={error:o.UNAUTHENTICATED};return Promise.reject(r)}))()}request(e,t){var r=this;return m((function*(){var n,i;t||(t={});var a=r.formatRetry(t.retry,r.retry);if(t.headers=t.headers||{},r.headers&&(t.headers=y(y({},r.headers),t.headers)),t.headers["x-request-id"]||(t.headers["x-request-id"]=c()),!t.headers["x-device-id"]){var s=yield r.getDeviceId();t.headers["x-device-id"]=s}if(null!==(n=t)&&void 0!==n&&n.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(i=t)&&void 0!==i&&i.withCredentials){var u=yield r.getCredentials();u&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(u.access_token)):t.headers.Authorization="".concat(u.token_type," ").concat(u.access_token))}else r.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(r.clientId));e.startsWith("/")&&(e=r.apiOrigin+e);for(var d=null,l=a+1,h=0;h<l;h++){try{d=t.useWxCloud?yield r.wxCloudCallFunction(e,t):yield r.baseRequest(e,t);break}catch(e){if(t.withCredentials&&e&&e.error===o.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(e);if(h===a||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep(C.retryInterval)}return d}))()}wxCloudCallFunction(e,t){var r=this;return m((function*(){var n=null,i=null;try{var a,s="";try{s=yield wx.getRendererUserAgent()}catch(e){}var{result:c}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:y({origin:"https://servicewechat.com","User-Agent":s},t.headers),body:t.body}});null!=c&&null!==(a=c.body)&&void 0!==a&&a.error_code?(i=null==c?void 0:c.body).error_uri=d(e):n=null==c?void 0:c.body}catch(t){i={error:o.UNREACHABLE,error_description:t.message,error_uri:d(e)}}if(i)throw i;return n}))()}getCredentials(){var e=this;return m((function*(){var t=yield e.localCredentials.getCredentials();if(!t)return e.unAuthenticatedError("credentials not found");if(T(t))if(t.refresh_token)try{t=yield e.refreshToken(t)}catch(r){if("anonymous"!==t.scope)return Promise.reject(r);t=yield e.anonymousLogin(t)}else{if("anonymous"!==t.scope)return e.unAuthenticatedError("no refresh token found in credentials");t=yield e.anonymousLogin(t)}return t}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var e=this;return m((function*(){var t=yield e.localCredentials.getCredentials();return t?t.scope:e.unAuthenticatedError("credentials not found")}))()}getGroups(){var e=this;return m((function*(){var t=yield e.localCredentials.getCredentials();return t?t.groups:e.unAuthenticatedError("credentials not found")}))()}refreshToken(e){var t=this;return m((function*(){return t.singlePromise.run("_refreshToken",m((function*(){if(!e||!e.refresh_token)return t.unAuthenticatedError("no refresh token found in credentials");try{var r=yield t.refreshTokenFunc(e.refresh_token,e);return yield t.localCredentials.setCredentials(r),r}catch(e){return e.error===o.INVALID_GRANT?(yield t.localCredentials.setCredentials(null),t.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}anonymousLogin(e){var t=this;return m((function*(){return t.singlePromise.run("_anonymousLogin",m((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<C.minRetry||e>C.maxRetry)&&(t={error:o.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 m((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var t=this;return m((function*(){return t.singlePromise.run("_anonymous",m((function*(){if(!e||"anonymous"!==e.scope)return t.unAuthenticatedError("no anonymous in credentials");try{var n=yield t.request(r.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield t.localCredentials.setCredentials(n),n}catch(e){return e.error===o.INVALID_GRANT?(yield t.localCredentials.setCredentials(null),t.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,t){var i=this;return m((function*(){if(void 0===e||""===e)return i.unAuthenticatedError("refresh token not found");var o=r.AUTH_TOKEN_URL;return"v2"===(null==t?void 0:t.version)&&(o=n.AUTH_TOKEN_URL),y(y({},yield i.request(o,{method:"POST",body:{client_id:i.clientId,client_secret:i.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==t?void 0:t.version)||"v1"})}))()}getDeviceId(){var e=this;return m((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=c(),yield e.storage.setItem("device_id",t)),e.deviceID=t,t}))()}unAuthenticatedError(e){var t={error:o.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}}function O(){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.getSystemInfoSync)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.getSystemInfoSync())return!1;if("qq"===e.getSystemInfoSync().AppPlatform)return!1}catch(e){return!1}return!0}C.defaultRetry=2,C.minRetry=0,C.maxRetry=5,C.retryInterval=1e3;var U=!1;function A(){U=U||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{O()||(U=U||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?A():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",A,!1))}catch(e){}function P(){return U}const w=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("&")}};function b(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 N(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){b(o,n,i,a,s,"next",e)}function s(e){b(o,n,i,a,s,"throw",e)}a(void 0)}))}}class D{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=R),this.config=e,this.tokenSectionName="captcha_".concat(e.clientId)}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))||O()}request(e,t){var r=this;return N((function*(){t||(t={}),t.method||(t.method="GET");var n,i="".concat(t.method,":").concat(e),a=e;t.withCaptcha&&(a=yield r.appendCaptchaTokenToURL(e,i,!1));try{n=yield r.config.request(a,t)}catch(n){return n.error===o.CAPTCHA_REQUIRED||n.error===o.CAPTCHA_INVALID?(e=yield r.appendCaptchaTokenToURL(e,i,n.error===o.CAPTCHA_INVALID),r.config.request(e,t)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){if(!this.isMatch()&&!P()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap"))){var e=document.createElement("div");e.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",e.setAttribute("id","captcha_panel_wrap"),setTimeout(()=>{document.body.appendChild(e)},0)}return this.defaultOpenURIWithCallback}defaultOpenURIWithCallback(e,t){return N((function*(){var{width:r="355px",height:n="355px"}=t||{};if(e.match(/^(data:.*)$/))return Promise.reject({error:o.UNIMPLEMENTED,error_description:"need to impl captcha data"});var i=document.getElementById("captcha_panel_wrap"),a=document.createElement("iframe");return i.innerHTML="",a.setAttribute("src",e),a.setAttribute("id","review-panel-iframe"),a.style.cssText="min-width:".concat(r,";display:block;height:").concat(n,";margin:0 auto;background-color: rgb(255, 255, 255);border: none;"),i.appendChild(a),i.style.display="block",new Promise((e,t)=>{a.onload=function(){try{var r=window.location,n=a.contentWindow.location;if(n.host+n.pathname===r.host+r.pathname){i.style.display="none";var o=new w(n.search),s=o.get("captcha_token");return s?e({captcha_token:s,expires_in:Number(o.get("expires_in"))}):t({error:o.get("error"),error_description:o.get("error_description")})}i.style.display="block"}catch(e){i.style.display="block"}}})}))()}getCaptchaToken(e,t){var n=this;return N((function*(){if(!e){var i=yield n.findCaptchaToken();if(i)return i}var o;if(n.isMatch()||P()){var a=yield n.config.request(r.CAPTCHA_DATA_URL,{method:"POST",body:{state:t,redirect_uri:""},withCredentials:!1});o={url:"".concat(a.data,"?state=").concat(encodeURIComponent(t),"&token=").concat(encodeURIComponent(a.token))}}else{var s="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((o=yield n.config.request(r.GET_CAPTCHA_URL,{method:"POST",body:{client_id:n.config.clientId,redirect_uri:s,state:t},withCredentials:!1})).captcha_token){var c={captcha_token:o.captcha_token,expires_in:o.expires_in};return n.saveCaptchaToken(c),o.captcha_token}}var u=yield n.config.openURIWithCallback(o.url);return n.saveCaptchaToken(u),u.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return N((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 N((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 N((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}))()}}var L=["provider_redirect_uri","other_params"];function k(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 x(e){return function(){var t=this,r=arguments;return new Promise((function(n,i){var o=e.apply(t,r);function a(e){k(o,n,i,a,s,"next",e)}function s(e){k(o,n,i,a,s,"throw",e)}a(void 0)}))}}function q(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 H(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?q(Object(r),!0).forEach((function(t){j(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function j(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 V(e,t){try{var r;if(((null==t||null===(r=t.root)||void 0===r?void 0:r.globalThis)||globalThis).IS_MP_BUILD)return}catch(e){}}class G{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new w(e).toString()}constructor(e){var{request:t}=e,r=e.credentialsClient;if(!r){var n={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage,env:e.env,baseRequest:e.baseRequest,anonymousSignInFunc:e.anonymousSignInFunc,wxCloud:e.wxCloud};r=new C(n)}if(!t){var i=r.request.bind(r),o=new D(H({clientId:e.clientId,request:i,storage:e.storage,adapter:e.adapter},e.captchaOptions));t=o.request.bind(o)}this.config={env:e.env,apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||R,adapter:e.adapter}}getParamsByVersion(e,t){var i,o=u(e),a=(null===(i={v2:n}[null==o?void 0:o.version])||void 0===i?void 0:i[t])||r[t];return o&&delete o.version,{params:o,url:a}}signIn(e){var t=this;return x((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(H(H({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var e=arguments,t=this;return x((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=e.length>1&&void 0!==e[1]&&e[1],o=yield t.config.request(r.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:n,useWxCloud:i});return yield t.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(e){var t=this;return x((function*(){var n=yield t.config.request(r.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signOut(e){var t=this;return x((function*(){var n={};if(e){try{n=yield t.config.request(r.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==o.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield t.config.credentialsClient.setCredentials(),n}var i=yield t.config.credentialsClient.getAccessToken(),a=yield t.config.request(r.AUTH_REVOKE_URL,{method:"POST",body:{token:i}});return yield t.config.credentialsClient.setCredentials(),Promise.resolve(a)}))()}revokeAllDevices(){var e=this;return x((function*(){yield e.config.request(r.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var t=this;return x((function*(){yield t.config.request(r.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,t){var n=this;return x((function*(){var i=!1;"CUR_USER"===e.target?i=!0:(yield n.hasLoginState())&&(i=!0);return n.config.request(r.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(null==t?void 0:t.withCaptcha)||!1,withCredentials:i})}))()}verify(e){var t=this;return x((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(H(H({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var t=this;return x((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,L);n&&!o.redirect_uri&&(o.redirect_uri=n);var a="".concat(r.PROVIDER_URI_URL,"?").concat(G.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)))}),t.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var t=arguments,n=this;return x((function*(){var i=t.length>1&&void 0!==t[1]&&t[1];return n.config.request(r.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:i})}))()}patchProviderToken(e){var t=this;return x((function*(){return t.config.request(r.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return x((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(H(H({},o),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(o)}))()}signInCustom(e){var t=this;return x((function*(){var n=yield t.config.request(r.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signInWithWechat(){var e=arguments,t=this;return x((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},i=yield t.config.request(r.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:n});return yield t.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}bindWithProvider(e){var t=this;return x((function*(){return t.config.request(r.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return x((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return x((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 w(i.params.query);i.url+="?".concat(o.toString())}var a=yield t.config.request(i.url,{method:"GET",withCredentials:!0});return a.sub&&(a.uid=a.sub),a}))()}getWedaUserInfo(){var e=this;return x((function*(){return yield e.config.request(r.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return x((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(G.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return x((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return x((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var t=this;return x((function*(){return t.config.request(r.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return x((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 x((function*(){return e.config.request(r.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var t=this;return x((function*(){return t.config.request("".concat(r.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var t=this;return x((function*(){return t.config.request("".concat(r.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var t=this;return x((function*(){return t.config.request("".concat(r.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var t=this;return x((function*(){return t.config.request("".concat(r.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return x((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 t=this;return x((function*(){return t.config.request("".concat(r.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var t=this;return x((function*(){return e.target="CUR_USER",t.config.request(r.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var t=this;return x((function*(){return t.config.request("".concat(r.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var t=this;return x((function*(){return t.config.request(r.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var t=this;return x((function*(){return t.config.request(r.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var t=this;return x((function*(){var n=new w(e);return t.config.request("".concat(r.USER_QUERY_URL,"?").concat(n.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return x((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 t=this;return x((function*(){return t.config.request(r.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var t=this;return x((function*(){return t.config.request(r.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var t=this;return x((function*(){return t.config.request(r.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var t=this;return x((function*(){return t.config.request(r.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var t=this;return x((function*(){var n="".concat(r.AUTHORIZE_INFO_URL,"?").concat(G.parseParamsToSearch(e)),i=!0,o=!1;return(yield t.hasLoginState())&&(o=!0,i=!1),t.config.request(n,{method:"GET",withBasicAuth:i,withCredentials:o})}))()}checkUsername(e){var t=this;return x((function*(){return t.config.request(r.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var t=this;return x((function*(){var n=new w(e);return t.config.request("".concat(r.CHECK_IF_USER_EXIST,"?").concat(n.toString()),{method:"GET"})}))()}loginScope(){var e=this;return x((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return x((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return x((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(H(H({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return x((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return x((function*(){return e.config.request(n.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return x((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=u(e),i=V(0,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 x((function*(){return e.config.request(r.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var t=this;return x((function*(){var{token:n,key:i}=e;return t.config.request(r.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:n,key:i},withCredentials:!1})}))()}createCaptchaData(e){var t=this;return x((function*(){var{state:n,redirect_uri:i}=e;return t.config.request(r.CAPTCHA_DATA_URL,{method:"POST",body:{state:n,redirect_uri:i},withCredentials:!1})}))()}getMiniProgramCode(e){var t=this;return x((function*(){return t.config.request(r.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var t=this;return x((function*(){return t.config.request(r.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var t=this;return x((function*(){var n="".concat(r.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 t.config.request(n,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var t=this;return x((function*(){var n="",i="",o=V(0,t.config.adapter);if(!o)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield t.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 t.config.request(r.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 x((function*(){var r="",i="",o=V(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,i=a.public_key_thumbprint,!r||!i)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(n.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:s,new_password:c,public_key_thumbprint:i}})}))()}}function W(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 B(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?W(Object(r),!0).forEach((function(t){F(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function F(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 M{constructor(e){var{apiOrigin:t,clientId:r,env:n,storage:i,request:o,baseRequest:a,anonymousSignInFunc:s,wxCloud:c,adapter:u}=e;this.oauth2client=new C({apiOrigin:t,clientId:r,env:n,storage:i,baseRequest:a||o,anonymousSignInFunc:s,wxCloud:c}),this.authApi=new G(B(B({credentialsClient:this.oauth2client},e),{},{request:o?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:u}))}}return t})());
|
|
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={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AUTH_API_PREFIX:()=>c,Auth:()=>ve,CloudbaseOAuth:()=>me,authModels:()=>r});var r={};e.r(r);var n,o,i,a,s,c="/auth";function u(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}!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"}(n||(n={})),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"}(o||(o={})),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"}(i||(i={})),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"}(a||(a={})),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"}(s||(s={}));var l=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=l(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}},d=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""};function h(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function f(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){h(i,n,o,a,s,"next",e)}function s(e){h(i,n,o,a,s,"throw",e)}a(void 0)}))}}var p=new Map;class v{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",p=p||new Map}run(e,t){var r=this;return f((function*(){e="".concat(r.clientId,"_").concat(e);var n=p.get(e);return n||(n=new Promise((n,o)=>{f((function*(){try{yield r.runIdlePromise();var i=t();n(yield i)}catch(e){o(e)}finally{p.delete(e)}}))()}),p.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var _="@cloudbase/js-sdk";function g(){return _}var m="https:";var E,I="INVALID_PARAMS",R="INVALID_OPERATION",b="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(E||(E={}));var S=function(){};function T(e,t){console.warn("[".concat(g(),"][").concat(e,"]:").concat(t))}var O,w=(O=function(e,t){return(O=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}O(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),C=function(){return(C=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},A=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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())}))},P=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=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(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=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,o=t.timeoutMsg,i=t.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=o||"请求超时",r.restrictedMethods=i||["get","post","upload","download"],r}w(t,e),t.prototype.get=function(e){return this.request(C(C({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(C(C({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(C(C({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,o=e.method,i=e.headers,a=void 0===i?{}:i,s={post:"post",put:"put"}[null==o?void 0:o.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(C(C({},e),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(C(C({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return A(this,void 0,void 0,(function(){var t,r,n,o;return P(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(C(C({},e),{headers:{},responseType:"blob"}))];case 1:return t=i.sent().data,r=window.URL.createObjectURL(new Blob([t])),n=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=r,o.setAttribute("download",n),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(r),document.body.removeChild(o),[3,3];case 2:return i.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 A(this,void 0,void 0,(function(){var r,n,o,i,a,s,c,u,l,d,h,f=this;return P(this,(function(p){switch(p.label){case 0:return r=new AbortController,n=e.url,o=e.enableAbort,i=void 0!==o&&o,a=e.stream,s=void 0!==a&&a,c=e.signal,u=e.timeout,l=null!=u?u:this.timeout,c&&(c.aborted&&r.abort(),c.addEventListener("abort",(function(){return r.abort()}))),d=null,i&&l&&(d=setTimeout((function(){console.warn(f.timeoutMsg),r.abort(new Error(f.timeoutMsg))}),l)),[4,fetch(n,C(C({},e),{signal:r.signal})).then((function(e){return A(f,void 0,void 0,(function(){var t,r,n;return P(this,(function(o){switch(o.label){case 0:return clearTimeout(d),e.ok?(t=e,[3,3]):[3,1];case 1:return n=(r=Promise).reject,[4,e.json()];case 2:t=n.apply(r,[o.sent()]),o.label=3;case 3:return[2,t]}}))}))})).catch((function(e){return clearTimeout(d),Promise.reject(e)}))];case 1:return h=p.sent(),[2,{data:s?h.body:(null===(t=h.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?h.json():h.text(),statusCode:h.status,header:h.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(o){var i,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,y=function(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),o="";return Object.keys(r).forEach((function(e){""===o?!n&&(t+="?"):o+="&",o+="".concat(e,"=").concat(encodeURIComponent(r[e]))})),/^http(s)?:\/\//.test(t+=o)?t:"".concat(e).concat(t)}(m,c,"get"===n?d:{}),_=new XMLHttpRequest;_.open(n,y),h&&(_.responseType=h),Object.keys(l).forEach((function(e){_.setRequestHeader(e,l[e])})),v&&_.upload.addEventListener("progress",v),_.onreadystatechange=function(){var e={};if(4===_.readyState){var t=_.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};t.forEach((function(e){var t=e.split(": "),n=t.shift().toLowerCase(),o=t.join(": ");r[n]=o})),e.header=r,e.statusCode=_.status;try{e.data="blob"===h?_.response:JSON.parse(_.responseText)}catch(t){e.data="blob"===h?_.response:_.responseText}clearTimeout(i),o(e)}},t&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),_.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&&(_.withCredentials=!0),_.send(a)}))}}((function(){}));var U;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(U||(U={}));var N=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)}}(),L=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(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())}))},D=function(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,s[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=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(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=t.call(e,a)}catch(e){s=[6,e],n=0}finally{r=o=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 N(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}(S);!function(){function e(e){this.keys={};var t=e.persistence,r=e.platformInfo,n=void 0===r?{}:r,o=e.keys,i=void 0===o?{}:o;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:(T(I,"localStorage is not supported on current platform"),new k(t.root));case"none":return new k(t.root);default:return t.localStorage?t.localStorage:(T(I,"localStorage is not supported on current platform"),new k(t.root))}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}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:b,msg:"[".concat(g(),"][").concat(b,"]setStore failed"),info:e}))}}else T(R,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return L(this,void 0,void 0,(function(){var n;return D(this,(function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),n={version:r||"localCachev1",content:t},[4,this.storage.setItem(e,JSON.stringify(n))];case 2:return o.sent(),[3,4];case 3:return o.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:""}T(R,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return L(this,void 0,void 0,(function(){var n;return D(this,(function(o){switch(o.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=o.sent())&&n.indexOf(t)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},e.prototype.removeStore=function(e){"async"!==this.mode?this.storage.removeItem(e):T(R,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return L(this,void 0,void 0,(function(){return D(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var x=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)}}(),j=function(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))};var q=function(e,t){this.data=t||null,this.name=e},H=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return x(t,e),t}(q),G=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 H)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 o=0,i=this.listeners[n]?j([],this.listeners[n],!0):[];o<i.length;o++){i[o].call(this,r)}}return this},e.prototype.listens=function(e){return this.listeners[e]&&this.listeners[e].length>0},e}();new G;var V=new G;"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 M(e){this.message=e}M.prototype=new Error,M.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function F(e){this.message=e}F.prototype=new Error,F.prototype.name="InvalidTokenError";function W(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 B(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?W(Object(r),!0).forEach((function(t){K(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):W(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function K(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 Y(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function Q(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){Y(i,n,o,a,s,"next",e)}function s(e){Y(i,n,o,a,s,"throw",e)}a(void 0)}))}}var J=function(){var e=Q((function*(e,t){var r=null,n=null;try{var o=Object.assign({},t);o.method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body));var i=yield fetch(e,o),s=yield i.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 z=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return Q((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return Q((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return Q((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 X(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class Z{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new v({clientId:this.clientId})}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 Q((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}))()}getCredentials(){var e=this;return Q((function*(){return e.singlePromise.run("getCredentials",Q((function*(){return X(e.credentials)&&(e.credentials=yield e.getStorageCredentials()),e.credentials})))}))()}getStorageCredentials(){var e=this;return Q((function*(){return e.singlePromise.run("_getStorageCredentials",Q((function*(){var t=null,r=yield e.storage.getItem(e.tokenSectionName);if(null!=r)try{var n;null!==(n=t=JSON.parse(r))&&void 0!==n&&n.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}return t})))}))()}}class ${constructor(e){this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.apiPath=e.apiPath||c,this.clientId=e.clientId,this.i18n=e.i18n,this.singlePromise=new v({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,$.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=J,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||z,this.localCredentials=new Z({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,o,i="",a=0,s=(e=String(e)).length%3;a<e.length;){if((r=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255||(o=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.");i+=y.charAt((t=r<<16|n<<8|o)>>18&63)+y.charAt(t>>12&63)+y.charAt(t>>6&63)+y.charAt(63&t)}return s?i.slice(0,s-3)+"===".substring(s):i}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{(function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(e){return!1}return!0})()&&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,V.on("lang_change",e=>{var t;this.i18n=(null===(t=e.data)||void 0===t?void 0:t.i18n)||this.i18n})}setCredentials(e){return this.localCredentials.setCredentials(e)}getAccessToken(){var e=this;return Q((function*(){var t=yield e.getCredentials();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 Q((function*(){var n,o,i,s;t||(t={});var c=r.formatRetry(t.retry,r.retry);if(t.headers=B(B({},t.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(o=r.i18n)||void 0===o?void 0:o.lang}),r.headers&&(t.headers=B(B({},r.headers),t.headers)),t.headers["x-request-id"]||(t.headers["x-request-id"]=u()),!t.headers["x-device-id"]){var l=yield r.getDeviceId();t.headers["x-device-id"]=l}if(null!==(i=t)&&void 0!==i&&i.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(s=t)&&void 0!==s&&s.withCredentials){var d=yield r.getCredentials();d&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(d.access_token)):t.headers.Authorization="".concat(d.token_type," ").concat(d.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 h=null,f=c+1,p=0;p<f;p++){try{h=t.useWxCloud?yield r.wxCloudCallFunction(e,t):yield r.baseRequest(e,t);break}catch(e){if(t.withCredentials&&e&&e.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(e);if(p===c||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep($.retryInterval)}return h}))()}wxCloudCallFunction(e,t){var r=this;return Q((function*(){var n=null,o=null;try{var i,s="";try{s=yield wx.getRendererUserAgent()}catch(e){}var{result:c}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:B({origin:"https://servicewechat.com","User-Agent":s},t.headers),body:t.body}});null!=c&&null!==(i=c.body)&&void 0!==i&&i.error_code?(o=null==c?void 0:c.body).error_uri=d(e):n=null==c?void 0:c.body}catch(t){o={error:a.UNREACHABLE,error_description:t.message,error_uri:d(e)}}if(o)throw o;return n}))()}getCredentials(){var e=this;return Q((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)}if(X(t))if(t.refresh_token)try{t=yield e.refreshToken(t)}catch(r){var o;if("anonymous"!==t.scope)return null===(o=e.onCredentialsError)||void 0===o||o.call(e,{msg:r.error_description}),Promise.reject(r);t=yield e.anonymousLogin(t)}else{if("anonymous"!==t.scope){var i,a="no refresh token found in credentials";return null===(i=e.onCredentialsError)||void 0===i||i.call(e,{msg:a}),e.unAuthenticatedError(a)}t=yield e.anonymousLogin(t)}return t}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var e=this;return Q((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 Q((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){var t=this;return Q((function*(){return t.singlePromise.run("_refreshToken",Q((function*(){if(!e||!e.refresh_token){var r,n="no refresh token found in credentials";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}try{var o=yield t.refreshTokenFunc(e.refresh_token,e);return yield t.localCredentials.setCredentials(o),o}catch(e){var i;if(e.error===a.INVALID_GRANT){var s;yield t.localCredentials.setCredentials(null);var c=e.error_description;return null===(s=t.onCredentialsError)||void 0===s||s.call(t,{msg:c}),t.unAuthenticatedError(c)}return null===(i=t.onCredentialsError)||void 0===i||i.call(t,{msg:e.error_description}),Promise.reject(e)}})))}))()}anonymousLogin(e){var t=this;return Q((function*(){return t.singlePromise.run("_anonymousLogin",Q((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<$.minRetry||e>$.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 Q((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var t=this;return Q((function*(){return t.singlePromise.run("_anonymous",Q((function*(){if(!e||"anonymous"!==e.scope)return t.unAuthenticatedError("no anonymous in credentials");try{var r=yield t.request(n.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield t.localCredentials.setCredentials(r),r}catch(e){return e.error===a.INVALID_GRANT?(yield t.localCredentials.setCredentials(null),t.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,t){var r=this;return Q((function*(){if(void 0===e||""===e){var i,a="refresh token not found";return null===(i=r.onCredentialsError)||void 0===i||i.call(r,{msg:a}),r.unAuthenticatedError(a)}var s=n.AUTH_TOKEN_URL;return"v2"===(null==t?void 0:t.version)&&(s=o.AUTH_TOKEN_URL),B(B({},yield r.request(s,{method:"POST",body:{client_id:r.clientId,client_secret:r.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==t?void 0:t.version)||"v1"})}))()}getDeviceId(){var e=this;return Q((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=u(),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)}}function ee(){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.getSystemInfoSync)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.getSystemInfoSync())return!1;if("qq"===e.getSystemInfoSync().AppPlatform)return!1}catch(e){return!1}return!0}$.defaultRetry=2,$.minRetry=0,$.maxRetry=5,$.retryInterval=1e3;var te=!1;function re(){te=te||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{ee()||(te=te||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?re():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",re,!1))}catch(M){}function ne(){return te}const oe=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("&")}};function ie(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function ae(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ie(i,n,o,a,s,"next",e)}function s(e){ie(i,n,o,a,s,"throw",e)}a(void 0)}))}}class se{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=z),this.config=e,this.tokenSectionName="captcha_".concat(e.clientId)}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))||ee()}request(e,t){var r=this;return ae((function*(){t||(t={}),t.method||(t.method="GET");var n,o="".concat(t.method,":").concat(e),i=e;t.withCaptcha&&(i=yield r.appendCaptchaTokenToURL(e,o,!1));try{n=yield r.config.request(i,t)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(e=yield r.appendCaptchaTokenToURL(e,o,n.error===a.CAPTCHA_INVALID),r.config.request(e,t)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){if(!this.isMatch()&&!ne()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap"))){var e=document.createElement("div");e.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",e.setAttribute("id","captcha_panel_wrap"),setTimeout(()=>{document.body.appendChild(e)},0)}return this.defaultOpenURIWithCallback}defaultOpenURIWithCallback(e,t){return ae((function*(){var{width:r="355px",height:n="355px"}=t||{};if(e.match(/^(data:.*)$/))return Promise.reject({error:a.UNIMPLEMENTED,error_description:"need to impl captcha data"});var o=document.getElementById("captcha_panel_wrap"),i=document.createElement("iframe");return o.innerHTML="",i.setAttribute("src",e),i.setAttribute("id","review-panel-iframe"),i.style.cssText="min-width:".concat(r,";display:block;height:").concat(n,";margin:0 auto;background-color: rgb(255, 255, 255);border: none;"),o.appendChild(i),o.style.display="block",new Promise((e,t)=>{i.onload=function(){try{var r=window.location,n=i.contentWindow.location;if(n.host+n.pathname===r.host+r.pathname){o.style.display="none";var a=new oe(n.search),s=a.get("captcha_token");return s?e({captcha_token:s,expires_in:Number(a.get("expires_in"))}):t({error:a.get("error"),error_description:a.get("error_description")})}o.style.display="block"}catch(e){o.style.display="block"}}})}))()}getCaptchaToken(e,t){var r=this;return ae((function*(){if(!e){var o=yield r.findCaptchaToken();if(o)return o}var i;if(r.isMatch()||ne()){var a=yield r.config.request(n.CAPTCHA_DATA_URL,{method:"POST",body:{state:t,redirect_uri:""},withCredentials:!1});i={url:"".concat(a.data,"?state=").concat(encodeURIComponent(t),"&token=").concat(encodeURIComponent(a.token))}}else{var s="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((i=yield r.config.request(n.GET_CAPTCHA_URL,{method:"POST",body:{client_id:r.config.clientId,redirect_uri:s,state:t},withCredentials:!1})).captcha_token){var c={captcha_token:i.captcha_token,expires_in:i.expires_in};return r.saveCaptchaToken(c),i.captcha_token}}var u=yield r.config.openURIWithCallback(i.url);return r.saveCaptchaToken(u),u.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return ae((function*(){var o=yield n.getCaptchaToken(r,t);return e.indexOf("?")>0?e+="&captcha_token=".concat(o):e+="?captcha_token=".concat(o),e}))()}saveCaptchaToken(e){var t=this;return ae((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 ae((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}))()}}var ce=["provider_redirect_uri","other_params"];function ue(e,t,r,n,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function le(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ue(i,n,o,a,s,"next",e)}function s(e){ue(i,n,o,a,s,"throw",e)}a(void 0)}))}}function de(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 he(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?de(Object(r),!0).forEach((function(t){fe(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):de(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function fe(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 pe(e,t){try{var r;if(((null==t||null===(r=t.root)||void 0===r?void 0:r.globalThis)||globalThis).IS_MP_BUILD)return}catch(e){}}class ve{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new oe(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};r=new $(n)}if(!t){var o=r.request.bind(r),i=new se(he({clientId:e.clientId,request:o,storage:e.storage,adapter:e.adapter},e.captchaOptions));t=i.request.bind(i)}this.config={env:e.env,apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||z,adapter:e.adapter}}getParamsByVersion(e,t){var r,i=l(e),a=(null===(r={v2:o}[null==i?void 0:i.version])||void 0===r?void 0:r[t])||n[t];return i&&delete i.version,{params:i,url:a}}signIn(e){var t=this;return le((function*(){var r=e.version||"v1",n=t.getParamsByVersion(e,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var o=yield t.getEncryptParams(n.params),i=yield t.config.request(n.url,{method:"POST",body:o});return yield t.config.credentialsClient.setCredentials(he(he({},i),{},{version:r})),Promise.resolve(i)}))()}signInAnonymously(){var e=arguments,t=this;return le((function*(){var r=e.length>0&&void 0!==e[0]?e[0]:{},o=e.length>1&&void 0!==e[1]&&e[1],i=yield t.config.request(n.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:r,useWxCloud:o});return yield t.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}signUp(e){var t=this;return le((function*(){var r=yield t.config.request(n.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signOut(e){var t=this;return le((function*(){var r={};if(e){try{r=yield t.config.request(n.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield t.config.credentialsClient.setCredentials(),r}var o=yield t.config.credentialsClient.getAccessToken(),i=yield t.config.request(n.AUTH_REVOKE_URL,{method:"POST",body:{token:o}});return yield t.config.credentialsClient.setCredentials(),Promise.resolve(i)}))()}revokeAllDevices(){var e=this;return le((function*(){yield e.config.request(n.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var t=this;return le((function*(){yield t.config.request(n.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,t){var r=this;return le((function*(){var o=!1;"CUR_USER"===e.target?o=!0:(yield r.hasLoginState())&&(o=!0);return r.config.request(n.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(null==t?void 0:t.withCaptcha)||!1,withCredentials:o})}))()}verify(e){var t=this;return le((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(he(he({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var t=this;return le((function*(){var{provider_redirect_uri:r,other_params:o={}}=e,i=function(e,t){if(null==e)return{};var r,n,o=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 i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,ce);r&&!i.redirect_uri&&(i.redirect_uri=r);var a="".concat(n.PROVIDER_URI_URL,"?").concat(ve.parseParamsToSearch(i));return Object.keys(o).forEach(e=>{var t=o[e];("sign_out_uri"!==e||(null==t?void 0:t.length)>0)&&(a+="&other_params[".concat(e,"]=").concat(encodeURIComponent(t)))}),t.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var t=arguments,r=this;return le((function*(){var o=t.length>1&&void 0!==t[1]&&t[1];return r.config.request(n.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:o})}))()}patchProviderToken(e){var t=this;return le((function*(){return t.config.request(n.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return le((function*(){var n=t.length>1&&void 0!==t[1]&&t[1],o=r.getParamsByVersion(e,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),i=yield r.config.request(o.url,{method:"POST",body:o.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(he(he({},i),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(i)}))()}signInCustom(e){var t=this;return le((function*(){var r=yield t.config.request(n.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signInWithWechat(){var e=arguments,t=this;return le((function*(){var r=e.length>0&&void 0!==e[0]?e[0]:{},o=yield t.config.request(n.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:r});return yield t.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}bindWithProvider(e){var t=this;return le((function*(){return t.config.request(n.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return le((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return le((function*(){var r,n=e.length>0&&void 0!==e[0]?e[0]:{},o=t.getParamsByVersion(n,"USER_ME_URL");if(null!==(r=o.params)&&void 0!==r&&r.query){var i=new oe(o.params.query);o.url+="?".concat(i.toString())}var a=yield t.config.request(o.url,{method:"GET",withCredentials:!0});return a.sub&&(a.uid=a.sub),a}))()}getWedaUserInfo(){var e=this;return le((function*(){return yield e.config.request(n.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return le((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(ve.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return le((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return le((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var t=this;return le((function*(){return t.config.request(n.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return le((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 le((function*(){return e.config.request(n.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var t=this;return le((function*(){return t.config.request("".concat(n.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var t=this;return le((function*(){return t.config.request("".concat(n.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var t=this;return le((function*(){return t.config.request("".concat(n.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var t=this;return le((function*(){return t.config.request("".concat(n.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return le((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 t=this;return le((function*(){return t.config.request("".concat(n.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var t=this;return le((function*(){return e.target="CUR_USER",t.config.request(n.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var t=this;return le((function*(){return t.config.request("".concat(n.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var t=this;return le((function*(){return t.config.request(n.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var t=this;return le((function*(){return t.config.request(n.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var t=this;return le((function*(){var r=new oe(e);return t.config.request("".concat(n.USER_QUERY_URL,"?").concat(r.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return le((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 t=this;return le((function*(){return t.config.request(n.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var t=this;return le((function*(){return t.config.request(n.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var t=this;return le((function*(){return t.config.request(n.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var t=this;return le((function*(){return t.config.request(n.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var t=this;return le((function*(){var r="".concat(n.AUTHORIZE_INFO_URL,"?").concat(ve.parseParamsToSearch(e)),o=!0,i=!1;return(yield t.hasLoginState())&&(i=!0,o=!1),t.config.request(r,{method:"GET",withBasicAuth:o,withCredentials:i})}))()}checkUsername(e){var t=this;return le((function*(){return t.config.request(n.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var t=this;return le((function*(){var r=new oe(e);return t.config.request("".concat(n.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var e=this;return le((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return le((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return le((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(he(he({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return le((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return le((function*(){return e.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return le((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=l(e),o=pe(0,t.config.adapter);if(!o)return e;var i="",a="";try{var s=yield t.getPublicKey();if(i=s.public_key,a=s.public_key_thumbprint,!i||!a)throw s}catch(e){throw e}return{params:o.getEncryptInfo({publicKey:i,payload:n}),public_key_thumbprint:a}}))()}getProviderSubType(){var e=this;return le((function*(){return e.config.request(n.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var t=this;return le((function*(){var{token:r,key:o}=e;return t.config.request(n.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:r,key:o},withCredentials:!1})}))()}createCaptchaData(e){var t=this;return le((function*(){var{state:r,redirect_uri:o}=e;return t.config.request(n.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:o},withCredentials:!1})}))()}getMiniProgramCode(e){var t=this;return le((function*(){return t.config.request(n.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var t=this;return le((function*(){return t.config.request(n.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var t=this;return le((function*(){var r="".concat(n.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 t.config.request(r,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var t=this;return le((function*(){var r="",o="",i=pe(0,t.config.adapter);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield t.getPublicKey();if(r=a.public_key,o=a.public_key_thumbprint,!r||!o)throw a}catch(e){throw e}var s=e.password?i.getEncryptInfo({publicKey:r,payload:e.password}):"",c=i.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(n.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:s,encrypt_new_password:c,public_key_thumbprint:o}})}))()}modifyPasswordWithoutLogin(e){var t=this;return le((function*(){var r="",n="",i=pe(0,t.config.adapter);if(!i)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?i.getEncryptInfo({publicKey:r,payload:e.password}):"",c=i.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(o.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:s,new_password:c,public_key_thumbprint:n}})}))()}}function ye(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 _e(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ye(Object(r),!0).forEach((function(t){ge(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ye(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function ge(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 me{constructor(e){var{apiOrigin:t,apiPath:r=c,clientId:n,env:o,storage:i,request:a,baseRequest:s,anonymousSignInFunc:u,wxCloud:l,adapter:d,onCredentialsError:h,headers:f,i18n:p}=e;this.oauth2client=new $({apiOrigin:t,apiPath:r,clientId:n,env:o,storage:i,baseRequest:s||a,anonymousSignInFunc:u,wxCloud:l,onCredentialsError:h,headers:f||{},i18n:p}),this.authApi=new ve(_e(_e({credentialsClient:this.oauth2client},e),{},{request:a?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d}))}}return t})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/oauth",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.3",
|
|
4
4
|
"description": "cloudbase javascript sdk auth componets",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-env": "^7.25.3",
|
|
23
|
-
"@cloudbase/types": "2.19.
|
|
23
|
+
"@cloudbase/types": "2.19.3",
|
|
24
|
+
"@cloudbase/utilities": "2.19.3",
|
|
24
25
|
"@types/node": "^22.5.4",
|
|
25
26
|
"terser-webpack-plugin": "^3.0.2",
|
|
26
27
|
"ts-loader": "^9.5.1",
|
|
27
28
|
"webpack-bundle-analyzer": "^4.9.1"
|
|
28
29
|
},
|
|
29
30
|
"license": "Apache-2.0",
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "717aeb490c526ffa37eeb71291311257c0a4887b"
|
|
31
32
|
}
|
package/src/auth/apis.ts
CHANGED
|
@@ -68,6 +68,7 @@ import { Captcha, CaptchaOptions } from '../captcha/captcha'
|
|
|
68
68
|
import { deepClone } from '../utils'
|
|
69
69
|
import MyURLSearchParams from '../utils/urlSearchParams'
|
|
70
70
|
import { SDKAdapterInterface } from '@cloudbase/adapter-interface'
|
|
71
|
+
import { ICloudbaseConfig } from '@cloudbase/types'
|
|
71
72
|
|
|
72
73
|
function getEncryptUtils(isEncrypt, adapter: SDKAdapterInterface) {
|
|
73
74
|
try {
|
|
@@ -87,6 +88,7 @@ function getEncryptUtils(isEncrypt, adapter: SDKAdapterInterface) {
|
|
|
87
88
|
|
|
88
89
|
export interface AuthOptions {
|
|
89
90
|
apiOrigin: string
|
|
91
|
+
apiPath?: string
|
|
90
92
|
clientId: string
|
|
91
93
|
/**
|
|
92
94
|
* basic auth
|
|
@@ -101,6 +103,9 @@ export interface AuthOptions {
|
|
|
101
103
|
env?: string
|
|
102
104
|
wxCloud?: any
|
|
103
105
|
adapter?: SDKAdapterInterface
|
|
106
|
+
onCredentialsError?: (data: { msg: string, eventType?: 'credentials_error' }) => void
|
|
107
|
+
headers?: { [key: string]: string }
|
|
108
|
+
i18n?: ICloudbaseConfig['i18n']
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
/**
|
|
@@ -130,12 +135,16 @@ export class Auth {
|
|
|
130
135
|
if (!oAuth2Client) {
|
|
131
136
|
const initOptions = {
|
|
132
137
|
apiOrigin: opts.apiOrigin,
|
|
138
|
+
apiPath: opts.apiPath,
|
|
133
139
|
clientId: opts.clientId,
|
|
134
140
|
storage: opts.storage,
|
|
135
141
|
env: opts.env,
|
|
136
142
|
baseRequest: opts.baseRequest /* || opts.request */, // opts.request 废弃不用来表示 oauth rquest
|
|
137
143
|
anonymousSignInFunc: opts.anonymousSignInFunc,
|
|
138
144
|
wxCloud: opts.wxCloud,
|
|
145
|
+
onCredentialsError: opts.onCredentialsError,
|
|
146
|
+
headers: opts.headers || {},
|
|
147
|
+
i18n: opts.i18n,
|
|
139
148
|
}
|
|
140
149
|
oAuth2Client = new OAuth2Client(initOptions)
|
|
141
150
|
}
|
|
@@ -153,6 +162,7 @@ export class Auth {
|
|
|
153
162
|
this.config = {
|
|
154
163
|
env: opts.env,
|
|
155
164
|
apiOrigin: opts.apiOrigin,
|
|
165
|
+
apiPath: opts.apiPath,
|
|
156
166
|
clientId: opts.clientId,
|
|
157
167
|
request,
|
|
158
168
|
credentialsClient: oAuth2Client,
|
package/src/auth/consts.ts
CHANGED
|
@@ -1,62 +1,64 @@
|
|
|
1
|
+
export const AUTH_API_PREFIX = '/auth'
|
|
2
|
+
|
|
1
3
|
export enum ApiUrls {
|
|
2
|
-
AUTH_SIGN_UP_URL = '/
|
|
3
|
-
AUTH_TOKEN_URL = '/
|
|
4
|
-
AUTH_REVOKE_URL = '/
|
|
5
|
-
WEDA_USER_URL = '/
|
|
6
|
-
AUTH_RESET_PASSWORD = '/
|
|
7
|
-
AUTH_GET_DEVICE_CODE = '/
|
|
8
|
-
CHECK_USERNAME = '/
|
|
9
|
-
CHECK_IF_USER_EXIST = '/
|
|
10
|
-
GET_PROVIDER_TYPE = '/
|
|
4
|
+
AUTH_SIGN_UP_URL = '/v1/signup',
|
|
5
|
+
AUTH_TOKEN_URL = '/v1/token',
|
|
6
|
+
AUTH_REVOKE_URL = '/v1/revoke',
|
|
7
|
+
WEDA_USER_URL = '/v1/plugin/weda/userinfo',
|
|
8
|
+
AUTH_RESET_PASSWORD = '/v1/reset',
|
|
9
|
+
AUTH_GET_DEVICE_CODE = '/v1/device/code',
|
|
10
|
+
CHECK_USERNAME = '/v1/checkUsername',
|
|
11
|
+
CHECK_IF_USER_EXIST = '/v1/checkIfUserExist',
|
|
12
|
+
GET_PROVIDER_TYPE = '/v1/mgr/provider/providerSubType',
|
|
11
13
|
|
|
12
|
-
AUTH_SIGN_IN_URL = '/
|
|
13
|
-
AUTH_SIGN_IN_ANONYMOUSLY_URL = '/
|
|
14
|
-
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/
|
|
15
|
-
AUTH_SIGN_IN_WITH_WECHAT_URL = '/
|
|
16
|
-
AUTH_SIGN_IN_CUSTOM = '/
|
|
14
|
+
AUTH_SIGN_IN_URL = '/v1/signin',
|
|
15
|
+
AUTH_SIGN_IN_ANONYMOUSLY_URL = '/v1/signin/anonymously',
|
|
16
|
+
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/v1/signin/with/provider',
|
|
17
|
+
AUTH_SIGN_IN_WITH_WECHAT_URL = '/v1/signin/wechat/noauth',
|
|
18
|
+
AUTH_SIGN_IN_CUSTOM = '/v1/signin/custom',
|
|
17
19
|
|
|
18
|
-
PROVIDER_TOKEN_URL = '/
|
|
19
|
-
PROVIDER_URI_URL = '/
|
|
20
|
+
PROVIDER_TOKEN_URL = '/v1/provider/token',
|
|
21
|
+
PROVIDER_URI_URL = '/v1/provider/uri',
|
|
20
22
|
|
|
21
|
-
USER_ME_URL = '/
|
|
22
|
-
AUTH_SIGNOUT_URL = '/
|
|
23
|
-
USER_QUERY_URL = '/
|
|
24
|
-
USER_PRIFILE_URL = '/
|
|
25
|
-
USER_BASIC_EDIT_URL = '/
|
|
26
|
-
USER_TRANS_BY_PROVIDER_URL = '/
|
|
27
|
-
PROVIDER_LIST = '/
|
|
28
|
-
PROVIDER_BIND_URL = '/
|
|
29
|
-
PROVIDER_UNBIND_URL = '/
|
|
30
|
-
CHECK_PWD_URL = '/
|
|
31
|
-
SUDO_URL = '/
|
|
32
|
-
BIND_CONTACT_URL = '/
|
|
33
|
-
AUTH_SET_PASSWORD = '/
|
|
34
|
-
AUTHORIZE_DEVICE_URL = '/
|
|
35
|
-
AUTHORIZE_URL = '/
|
|
36
|
-
AUTHORIZE_INFO_URL = '/
|
|
37
|
-
AUTHORIZED_DEVICES_DELETE_URL = '/
|
|
38
|
-
AUTH_REVOKE_ALL_URL = '/
|
|
39
|
-
GET_USER_BEHAVIOR_LOG = '/
|
|
23
|
+
USER_ME_URL = '/v1/user/me',
|
|
24
|
+
AUTH_SIGNOUT_URL = '/v1/user/signout',
|
|
25
|
+
USER_QUERY_URL = '/v1/user/query',
|
|
26
|
+
USER_PRIFILE_URL = '/v1/user/profile',
|
|
27
|
+
USER_BASIC_EDIT_URL = '/v1/user/basic/edit',
|
|
28
|
+
USER_TRANS_BY_PROVIDER_URL = '/v1/user/trans/by/provider',
|
|
29
|
+
PROVIDER_LIST = '/v1/user/provider',
|
|
30
|
+
PROVIDER_BIND_URL = '/v1/user/provider/bind',
|
|
31
|
+
PROVIDER_UNBIND_URL = '/v1/user/provider',
|
|
32
|
+
CHECK_PWD_URL = '/v1/user/sudo',
|
|
33
|
+
SUDO_URL = '/v1/user/sudo',
|
|
34
|
+
BIND_CONTACT_URL = '/v1/user/contact',
|
|
35
|
+
AUTH_SET_PASSWORD = '/v1/user/password',
|
|
36
|
+
AUTHORIZE_DEVICE_URL = '/v1/user/device/authorize',
|
|
37
|
+
AUTHORIZE_URL = '/v1/user/authorize',
|
|
38
|
+
AUTHORIZE_INFO_URL = '/v1/user/authorize/info',
|
|
39
|
+
AUTHORIZED_DEVICES_DELETE_URL = '/v1/user/authorized/devices/',
|
|
40
|
+
AUTH_REVOKE_ALL_URL = '/v1/user/revoke/all',
|
|
41
|
+
GET_USER_BEHAVIOR_LOG = '/v1/user/security/history',
|
|
40
42
|
|
|
41
|
-
VERIFICATION_URL = '/
|
|
42
|
-
VERIFY_URL = '/
|
|
43
|
+
VERIFICATION_URL = '/v1/verification',
|
|
44
|
+
VERIFY_URL = '/v1/verification/verify',
|
|
43
45
|
|
|
44
|
-
CAPTCHA_DATA_URL = '/
|
|
45
|
-
VERIFY_CAPTCHA_DATA_URL = '/
|
|
46
|
-
GET_CAPTCHA_URL = '/
|
|
46
|
+
CAPTCHA_DATA_URL = '/v1/captcha/data',
|
|
47
|
+
VERIFY_CAPTCHA_DATA_URL = '/v1/captcha/data/verify',
|
|
48
|
+
GET_CAPTCHA_URL = '/v1/captcha/init',
|
|
47
49
|
|
|
48
|
-
GET_MINIPROGRAM_QRCODE = '/
|
|
49
|
-
GET_MINIPROGRAM_QRCODE_STATUS = '/
|
|
50
|
+
GET_MINIPROGRAM_QRCODE = '/v1/qrcode/generate',
|
|
51
|
+
GET_MINIPROGRAM_QRCODE_STATUS = '/v1/qrcode/get/status',
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
export enum ApiUrlsV2 {
|
|
53
|
-
AUTH_SIGN_IN_URL = '/
|
|
54
|
-
AUTH_TOKEN_URL = '/
|
|
55
|
-
USER_ME_URL = '/
|
|
56
|
-
VERIFY_URL = '/
|
|
57
|
-
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/
|
|
58
|
-
AUTH_PUBLIC_KEY = '/
|
|
59
|
-
AUTH_RESET_PASSWORD = '/
|
|
55
|
+
AUTH_SIGN_IN_URL = '/v2/signin/username',
|
|
56
|
+
AUTH_TOKEN_URL = '/v2/token',
|
|
57
|
+
USER_ME_URL = '/v2/user/me',
|
|
58
|
+
VERIFY_URL = '/v2/signin/verificationcode',
|
|
59
|
+
AUTH_SIGN_IN_WITH_PROVIDER_URL = '/v2/signin/with/provider',
|
|
60
|
+
AUTH_PUBLIC_KEY = '/v2/signin/publichkey',
|
|
61
|
+
AUTH_RESET_PASSWORD = '/v2/signin/password/update'
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
export enum VerificationUsages {
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { OAuth2Client } from './oauth2client/oauth2client'
|
|
2
2
|
import { AuthOptions, Auth } from './auth/apis'
|
|
3
|
+
import { AUTH_API_PREFIX } from './auth/consts'
|
|
3
4
|
export { Auth } from './auth/apis'
|
|
5
|
+
export { AUTH_API_PREFIX } from './auth/consts'
|
|
4
6
|
export * as authModels from './auth/models'
|
|
5
7
|
export type { ProviderProfile } from './auth/models'
|
|
6
8
|
export type { Credentials, OAuth2ClientOptions, ResponseError, AuthClientRequestOptions } from './oauth2client/models'
|
|
@@ -11,15 +13,19 @@ export class CloudbaseOAuth {
|
|
|
11
13
|
public authApi: Auth
|
|
12
14
|
|
|
13
15
|
constructor(authOptions: AuthOptions) {
|
|
14
|
-
const { apiOrigin, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter } = authOptions
|
|
16
|
+
const { apiOrigin, apiPath = AUTH_API_PREFIX, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError, headers, i18n } = authOptions
|
|
15
17
|
this.oauth2client = new OAuth2Client({
|
|
16
18
|
apiOrigin,
|
|
19
|
+
apiPath,
|
|
17
20
|
clientId,
|
|
18
21
|
env,
|
|
19
22
|
storage,
|
|
20
23
|
baseRequest: baseRequest || request,
|
|
21
24
|
anonymousSignInFunc,
|
|
22
25
|
wxCloud,
|
|
26
|
+
onCredentialsError,
|
|
27
|
+
headers: headers || {},
|
|
28
|
+
i18n,
|
|
23
29
|
})
|
|
24
30
|
|
|
25
31
|
this.authApi = new Auth({
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { SimpleStorage } from './interface'
|
|
2
2
|
import { ErrorType } from './consts'
|
|
3
|
+
import { AuthOptions } from '../auth/apis'
|
|
4
|
+
import { ICloudbaseConfig } from '@cloudbase/types'
|
|
3
5
|
|
|
4
6
|
/** Credentials **/
|
|
5
7
|
export interface Credentials {
|
|
@@ -51,6 +53,7 @@ export interface AuthClientRequestOptions extends RequestOptions {
|
|
|
51
53
|
export interface OAuth2ClientOptions {
|
|
52
54
|
devMode?: boolean;
|
|
53
55
|
apiOrigin: string;
|
|
56
|
+
apiPath?: string;
|
|
54
57
|
clientId: string;
|
|
55
58
|
env: string;
|
|
56
59
|
// default value is 1,min value is 0, max value is 5
|
|
@@ -66,4 +69,6 @@ export interface OAuth2ClientOptions {
|
|
|
66
69
|
// hook
|
|
67
70
|
anonymousSignInFunc?: (Credentials) => Promise<Credentials | void>
|
|
68
71
|
wxCloud?: any;
|
|
72
|
+
onCredentialsError?: AuthOptions['onCredentialsError']
|
|
73
|
+
i18n?: ICloudbaseConfig['i18n']
|
|
69
74
|
}
|