@cloudbase/oauth 2.19.6 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/auth/apis.d.ts +1 -0
- package/dist/cjs/auth/apis.js +5 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/oauth2client/models.d.ts +1 -0
- package/dist/cjs/oauth2client/models.js +1 -1
- package/dist/cjs/oauth2client/oauth2client.d.ts +1 -0
- package/dist/cjs/oauth2client/oauth2client.js +13 -1
- package/dist/esm/auth/apis.d.ts +1 -0
- package/dist/esm/auth/apis.js +4 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/oauth2client/models.d.ts +1 -0
- package/dist/esm/oauth2client/oauth2client.d.ts +1 -0
- package/dist/esm/oauth2client/oauth2client.js +12 -0
- package/dist/miniprogram/index.js +1 -1
- package/package.json +4 -4
- package/src/auth/apis.ts +5 -1
- package/src/index.ts +2 -1
- package/src/oauth2client/models.ts +1 -0
- package/src/oauth2client/oauth2client.ts +14 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcboauth",[],t):"object"==typeof exports?exports.tcboauth=t():e.tcboauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var e={3:(e,t,r)=>{r.r(t),r.d(t,{getEncryptInfo:()=>i});const n=void 0;var o=r(912),i=function(){var{publicKey:e="",payload:t={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e)return"";try{var r=(0,o.I)(t),i=new n;i.setPublicKey(e);var a=i.encryptLong("object"==typeof r?JSON.stringify(r):r);return a}catch(e){console.error("encrypt error:",e)}return""}},912:(e,t,r)=>{r.d(t,{I:()=>n,y:()=>o});var n=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},r=null==e?"NullOrUndefined":Object.prototype.toString.call(e).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return e.slice();switch(r){case"Object":return t(Object.create(Object.getPrototypeOf(e)));case"Array":return t([]);case"Date":return new Date(e.valueOf());case"RegExp":return new RegExp(e.source,(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.sticky?"y":"")+(e.unicode?"u":""));default:return e}},o=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{AUTH_API_PREFIX:()=>c,Auth:()=>pe,CloudbaseOAuth:()=>ge,authModels:()=>e});var e={};r.r(e);var t,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"}(t||(t={})),function(e){e.AUTH_SIGN_IN_URL="/v2/signin/username",e.AUTH_TOKEN_URL="/v2/token",e.USER_ME_URL="/v2/user/me",e.VERIFY_URL="/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(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=r(912);function d(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 h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){d(i,n,o,a,s,"next",e)}function s(e){d(i,n,o,a,s,"throw",e)}a(void 0)}))}}var f=new Map;class p{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",f=f||new Map}run(e,t){var r=this;return h((function*(){e="".concat(r.clientId,"_").concat(e);var n=f.get(e);return n||(n=new Promise((n,o)=>{h((function*(){try{yield r.runIdlePromise();var i=t();n(yield i)}catch(e){o(e)}finally{f.delete(e)}}))()}),f.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var y="@cloudbase/js-sdk";function _(){return y}var g="https:";var m,E="INVALID_PARAMS",I="INVALID_OPERATION",R="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(m||(m={}));var b=function(){};function S(e,t){console.warn("[".concat(_(),"][").concat(e,"]:").concat(t))}var T,O=(T=function(e,t){return(T=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}T(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),w=function(){return(w=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)},C=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())}))},A=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}O(t,e),t.prototype.get=function(e){return this.request(w(w({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(w(w({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(w(w({},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(w(w({},e),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(w(w({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return C(this,void 0,void 0,(function(){var t,r,n,o;return A(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(w(w({},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 C(this,void 0,void 0,(function(){var r,n,o,i,a,s,c,u,l,d,h,f=this;return A(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,w(w({},e),{signal:r.signal})).then((function(e){return C(f,void 0,void 0,(function(){var t,r,n;return A(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)}(g,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 P;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(P||(P={}));var U=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)}}(),N=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())}))},L=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])}}},D=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return U(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}(b);!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:(S(E,"localStorage is not supported on current platform"),new D(t.root));case"none":return new D(t.root);default:return t.localStorage?t.localStorage:(S(E,"localStorage is not supported on current platform"),new D(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:R,msg:"[".concat(_(),"][").concat(R,"]setStore failed"),info:e}))}}else S(I,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return N(this,void 0,void 0,(function(){var n;return L(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:""}S(I,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return N(this,void 0,void 0,(function(){var n;return L(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):S(I,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return N(this,void 0,void 0,(function(){return L(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var k=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)}}(),x=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 j=function(e,t){this.data=t||null,this.name=e},q=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return k(t,e),t}(j),H=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 q)return console.error(e.error),this;var r="string"==typeof e?new j(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?x([],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 H;var G=new H;"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 V(e){this.message=e}V.prototype=new Error,V.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function M(e){this.message=e}M.prototype=new Error,M.prototype.name="InvalidTokenError";function F(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 W(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?F(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):F(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(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 K(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 Y(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){K(i,n,o,a,s,"next",e)}function s(e){K(i,n,o,a,s,"throw",e)}a(void 0)}))}}var Q=function(){var e=Y((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 J=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return Y((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return Y((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return Y((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 z(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class X{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new p({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 Y((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 Y((function*(){return e.singlePromise.run("getCredentials",Y((function*(){return z(e.credentials)&&(e.credentials=yield e.getStorageCredentials()),e.credentials})))}))()}getStorageCredentials(){var e=this;return Y((function*(){return e.singlePromise.run("_getStorageCredentials",Y((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 Z{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 p({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,Z.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=Q,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||J,this.localCredentials=new X({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+=v.charAt((t=r<<16|n<<8|o)>>18&63)+v.charAt(t>>12&63)+v.charAt(t>>6&63)+v.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,G.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 Y((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 Y((function*(){var n,o,i,s;t||(t={});var c=r.formatRetry(t.retry,r.retry);if(t.headers=W(W({},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=W(W({},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(Z.retryInterval)}return h}))()}wxCloudCallFunction(e,t){var r=this;return Y((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:W({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=(0,l.y)(e):n=null==c?void 0:c.body}catch(t){o={error:a.UNREACHABLE,error_description:t.message,error_uri:(0,l.y)(e)}}if(o)throw o;return n}))()}getCredentials(){var e=this;return Y((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(z(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 Y((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 Y((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 Y((function*(){return t.singlePromise.run("_refreshToken",Y((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 Y((function*(){return t.singlePromise.run("_anonymousLogin",Y((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<Z.minRetry||e>Z.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 Y((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var r=this;return Y((function*(){return r.singlePromise.run("_anonymous",Y((function*(){if(!e||"anonymous"!==e.scope)return r.unAuthenticatedError("no anonymous in credentials");try{var n=yield r.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield r.localCredentials.setCredentials(n),n}catch(e){return e.error===a.INVALID_GRANT?(yield r.localCredentials.setCredentials(null),r.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,r){var n=this;return Y((function*(){if(void 0===e||""===e){var i,a="refresh token not found";return null===(i=n.onCredentialsError)||void 0===i||i.call(n,{msg:a}),n.unAuthenticatedError(a)}var s=t.AUTH_TOKEN_URL;return"v2"===(null==r?void 0:r.version)&&(s=o.AUTH_TOKEN_URL),W(W({},yield n.request(s,{method:"POST",body:{client_id:n.clientId,client_secret:n.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==r?void 0:r.version)||"v1"})}))()}getDeviceId(){var e=this;return Y((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 $(){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}Z.defaultRetry=2,Z.minRetry=0,Z.maxRetry=5,Z.retryInterval=1e3;var ee=!1;function te(){ee=ee||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{$()||(ee=ee||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?te():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",te,!1))}catch(V){}function re(){return ee}const ne=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 oe(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 ie(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){oe(i,n,o,a,s,"next",e)}function s(e){oe(i,n,o,a,s,"throw",e)}a(void 0)}))}}class ae{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=J),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))||$()}request(e,t){var r=this;return ie((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()&&!re()&&(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 ie((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 ne(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,r){var n=this;return ie((function*(){if(!e){var o=yield n.findCaptchaToken();if(o)return o}var i;if(n.isMatch()||re()){var a=yield n.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:""},withCredentials:!1});i={url:"".concat(a.data,"?state=").concat(encodeURIComponent(r),"&token=").concat(encodeURIComponent(a.token))}}else{var s="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((i=yield n.config.request(t.GET_CAPTCHA_URL,{method:"POST",body:{client_id:n.config.clientId,redirect_uri:s,state:r},withCredentials:!1})).captcha_token){var c={captcha_token:i.captcha_token,expires_in:i.expires_in};return n.saveCaptchaToken(c),i.captcha_token}}var u=yield n.config.openURIWithCallback(i.url);return n.saveCaptchaToken(u),u.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return ie((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 ie((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 ie((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 se=["provider_redirect_uri","other_params"];function ce(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 ue(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ce(i,n,o,a,s,"next",e)}function s(e){ce(i,n,o,a,s,"throw",e)}a(void 0)}))}}function le(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 de(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?le(Object(r),!0).forEach((function(t){he(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):le(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function he(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 fe(e,t){try{var n;if(((null==t||null===(n=t.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return;0}catch(e){return(()=>{try{return r(3)}catch(e){return}})()}}class pe{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new ne(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 Z(n)}if(!t){var o=r.request.bind(r),i=new ae(de({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||J,adapter:e.adapter}}getParamsByVersion(e,r){var n,i=(0,l.I)(e),a=(null===(n={v2:o}[null==i?void 0:i.version])||void 0===n?void 0:n[r])||t[r];return i&&delete i.version,{params:i,url:a}}signIn(e){var t=this;return ue((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(de(de({},i),{},{version:r})),Promise.resolve(i)}))()}signInAnonymously(){var e=arguments,r=this;return ue((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},o=e.length>1&&void 0!==e[1]&&e[1],i=yield r.config.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:n,useWxCloud:o});return yield r.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}signUp(e){var r=this;return ue((function*(){var n=yield r.config.request(t.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signOut(e){var r=this;return ue((function*(){var n={};if(e){try{n=yield r.config.request(t.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield r.config.credentialsClient.setCredentials(),n}var o=yield r.config.credentialsClient.getAccessToken(),i=yield r.config.request(t.AUTH_REVOKE_URL,{method:"POST",body:{token:o}});return yield r.config.credentialsClient.setCredentials(),Promise.resolve(i)}))()}revokeAllDevices(){var e=this;return ue((function*(){yield e.config.request(t.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var r=this;return ue((function*(){yield r.config.request(t.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,r){var n=this;return ue((function*(){var o=!1;"CUR_USER"===e.target?o=!0:(yield n.hasLoginState())&&(o=!0);return n.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(null==r?void 0:r.withCaptcha)||!1,withCredentials:o})}))()}verify(e){var t=this;return ue((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(de(de({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var r=this;return ue((function*(){var{provider_redirect_uri:n,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,se);n&&!i.redirect_uri&&(i.redirect_uri=n);var a="".concat(t.PROVIDER_URI_URL,"?").concat(pe.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)))}),r.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var r=arguments,n=this;return ue((function*(){var o=r.length>1&&void 0!==r[1]&&r[1];return n.config.request(t.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:o})}))()}patchProviderToken(e){var r=this;return ue((function*(){return r.config.request(t.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return ue((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(de(de({},i),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(i)}))()}signInCustom(e){var r=this;return ue((function*(){var n=yield r.config.request(t.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signInWithWechat(){var e=arguments,r=this;return ue((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},o=yield r.config.request(t.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:n});return yield r.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}bindWithProvider(e){var r=this;return ue((function*(){return r.config.request(t.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return ue((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return ue((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 ne(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 ue((function*(){return yield e.config.request(t.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return ue((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(pe.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return ue((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return ue((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var r=this;return ue((function*(){return r.config.request(t.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return ue((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 ue((function*(){return e.config.request(t.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var r=this;return ue((function*(){return r.config.request("".concat(t.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var r=this;return ue((function*(){return r.config.request("".concat(t.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var r=this;return ue((function*(){return r.config.request("".concat(t.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var r=this;return ue((function*(){return r.config.request("".concat(t.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return ue((function*(){var r=yield t.sudo({password:e.old_password});return t.setPassword({sudo_token:r.sudo_token,new_password:e.new_password})}))()}sudo(e){var r=this;return ue((function*(){return r.config.request("".concat(t.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var r=this;return ue((function*(){return e.target="CUR_USER",r.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var r=this;return ue((function*(){return r.config.request("".concat(t.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var r=this;return ue((function*(){return r.config.request(t.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var r=this;return ue((function*(){return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var r=this;return ue((function*(){var n=new ne(e);return r.config.request("".concat(t.USER_QUERY_URL,"?").concat(n.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return ue((function*(){var t=e.getCustomSignTicketFn;if(!t)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield t();return e.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(e){var r=this;return ue((function*(){return r.config.request(t.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var r=this;return ue((function*(){return r.config.request(t.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var r=this;return ue((function*(){return r.config.request(t.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var r=this;return ue((function*(){return r.config.request(t.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var r=this;return ue((function*(){var n="".concat(t.AUTHORIZE_INFO_URL,"?").concat(pe.parseParamsToSearch(e)),o=!0,i=!1;return(yield r.hasLoginState())&&(i=!0,o=!1),r.config.request(n,{method:"GET",withBasicAuth:o,withCredentials:i})}))()}checkUsername(e){var r=this;return ue((function*(){return r.config.request(t.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var r=this;return ue((function*(){var n=new ne(e);return r.config.request("".concat(t.CHECK_IF_USER_EXIST,"?").concat(n.toString()),{method:"GET"})}))()}loginScope(){var e=this;return ue((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return ue((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return ue((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(de(de({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return ue((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return ue((function*(){return e.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return ue((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=(0,l.I)(e),o=fe(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 ue((function*(){return e.config.request(t.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var r=this;return ue((function*(){var{token:n,key:o}=e;return r.config.request(t.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:n,key:o},withCredentials:!1})}))()}createCaptchaData(e){var r=this;return ue((function*(){var{state:n,redirect_uri:o}=e;return r.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:n,redirect_uri:o},withCredentials:!1})}))()}getMiniProgramCode(e){var r=this;return ue((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var r=this;return ue((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var r=this;return ue((function*(){var n="".concat(t.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[e.type],"&limit=").concat(e.limit).concat(e.page_token?"&page_token=".concat(e.page_token):"");return r.config.request(n,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var r=this;return ue((function*(){var n="",o="",i=fe(0,r.config.adapter);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield r.getPublicKey();if(n=a.public_key,o=a.public_key_thumbprint,!n||!o)throw a}catch(e){throw e}var s=e.password?i.getEncryptInfo({publicKey:n,payload:e.password}):"",c=i.getEncryptInfo({publicKey:n,payload:e.new_password});return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:s,encrypt_new_password:c,public_key_thumbprint:o}})}))()}modifyPasswordWithoutLogin(e){var t=this;return ue((function*(){var r="",n="",i=fe(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 ve(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 ye(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ve(Object(r),!0).forEach((function(t){_e(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ve(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _e(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 ge{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 Z({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 pe(ye(ye({credentialsClient:this.oauth2client},e),{},{request:a?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d}))}}})(),n})());
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("tcboauth",[],t):"object"==typeof exports?exports.tcboauth=t():e.tcboauth=t()}("undefined"!=typeof window?window:this,()=>(()=>{"use strict";var e={3:(e,t,r)=>{r.r(t),r.d(t,{getEncryptInfo:()=>i});const n=void 0;var o=r(912),i=function(){var{publicKey:e="",payload:t={}}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!e)return"";try{var r=(0,o.I)(t),i=new n;i.setPublicKey(e);var a=i.encryptLong("object"==typeof r?JSON.stringify(r):r);return a}catch(e){console.error("encrypt error:",e)}return""}},912:(e,t,r)=>{r.d(t,{I:()=>n,y:()=>o});var n=e=>{var t=t=>{for(var r in e)e.hasOwnProperty(r)&&(t[r]=n(e[r]));return t},r=null==e?"NullOrUndefined":Object.prototype.toString.call(e).slice(8,-1);if(["Int8Array","Uint8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"].includes(r))return e.slice();switch(r){case"Object":return t(Object.create(Object.getPrototypeOf(e)));case"Array":return t([]);case"Date":return new Date(e.valueOf());case"RegExp":return new RegExp(e.source,(e.global?"g":"")+(e.ignoreCase?"i":"")+(e.multiline?"m":"")+(e.sticky?"y":"")+(e.unicode?"u":""));default:return e}},o=e=>{var t=e.match(/^(?:http(s)?:\/\/[^\/]+)?(\/[^\?#]*)/);return t&&t[2]||""}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{r.r(n),r.d(n,{AUTH_API_PREFIX:()=>c,Auth:()=>pe,CloudbaseOAuth:()=>ge,authModels:()=>e});var e={};r.r(e);var t,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"}(t||(t={})),function(e){e.AUTH_SIGN_IN_URL="/v2/signin/username",e.AUTH_TOKEN_URL="/v2/token",e.USER_ME_URL="/v2/user/me",e.VERIFY_URL="/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(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=r(912);function d(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 h(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){d(i,n,o,a,s,"next",e)}function s(e){d(i,n,o,a,s,"throw",e)}a(void 0)}))}}var f=new Map;class p{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",f=f||new Map}run(e,t){var r=this;return h((function*(){e="".concat(r.clientId,"_").concat(e);var n=f.get(e);return n||(n=new Promise((n,o)=>{h((function*(){try{yield r.runIdlePromise();var i=t();n(yield i)}catch(e){o(e)}finally{f.delete(e)}}))()}),f.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var v="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var y="@cloudbase/js-sdk";function _(){return y}var g="https:";var m,E="INVALID_PARAMS",I="INVALID_OPERATION",b="OPERATION_FAIL";!function(e){e.local="local",e.none="none",e.session="session"}(m||(m={}));var R=function(){};function S(e,t){console.warn("[".concat(_(),"][").concat(e,"]:").concat(t))}var T,w=(T=function(e,t){return(T=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}T(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),O=function(){return(O=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)},C=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())}))},A=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(O(O({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(O(O({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(O(O({},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(O(O({},e),{data:c,method:s}),this.restrictedMethods.includes("upload"))):this.request(O(O({},e),{method:"put",headers:a,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return C(this,void 0,void 0,(function(){var t,r,n,o;return A(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(O(O({},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 C(this,void 0,void 0,(function(){var r,n,o,i,a,s,c,u,l,d,h,f=this;return A(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,O(O({},e),{signal:r.signal})).then((function(e){return C(f,void 0,void 0,(function(){var t,r,n;return A(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)}(g,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 P;!function(e){e.WEB="web",e.WX_MP="wx_mp"}(P||(P={}));var U=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)}}(),N=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())}))},L=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])}}},D=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return U(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}(R);!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:(S(E,"localStorage is not supported on current platform"),new D(t.root));case"none":return new D(t.root);default:return t.localStorage?t.localStorage:(S(E,"localStorage is not supported on current platform"),new D(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(_(),"][").concat(b,"]setStore failed"),info:e}))}}else S(I,"current platform's storage is asynchronous, please use setStoreAsync insteed")},e.prototype.setStoreAsync=function(e,t,r){return N(this,void 0,void 0,(function(){var n;return L(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:""}S(I,"current platform's storage is asynchronous, please use getStoreAsync insteed")},e.prototype.getStoreAsync=function(e,t){var r;return N(this,void 0,void 0,(function(){var n;return L(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):S(I,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},e.prototype.removeStoreAsync=function(e){return N(this,void 0,void 0,(function(){return L(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var k=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)}}(),x=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 j=function(e,t){this.data=t||null,this.name=e},q=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return k(t,e),t}(j),H=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 q)return console.error(e.error),this;var r="string"==typeof e?new j(e,t||{}):e,n=r.name;if(this.listens(n)){r.target=this;for(var o=0,i=this.listeners[n]?x([],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 H;var G=new H;"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 V(e){this.message=e}V.prototype=new Error,V.prototype.name="InvalidCharacterError";"undefined"!=typeof window&&window.atob&&window.atob.bind(window);function M(e){this.message=e}M.prototype=new Error,M.prototype.name="InvalidTokenError";function F(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?F(Object(r),!0).forEach((function(t){W(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):F(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function W(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 K(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 Y(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){K(i,n,o,a,s,"next",e)}function s(e){K(i,n,o,a,s,"throw",e)}a(void 0)}))}}var Q=function(){var e=Y((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 J=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return Y((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return Y((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return Y((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 z(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class X{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new p({clientId:this.clientId}),this.credentials=e.credentials||null,this.credentials&&this.setCredentials(this.credentials)}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 Y((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 Y((function*(){return e.singlePromise.run("getCredentials",Y((function*(){return z(e.credentials)&&(e.credentials=yield e.getStorageCredentials()),e.credentials})))}))()}getStorageCredentials(){var e=this;return Y((function*(){return e.singlePromise.run("_getStorageCredentials",Y((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 Z{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.publishable_key=e.publishable_key,this.singlePromise=new p({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,Z.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=Q,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||J,this.localCredentials=new X({tokenSectionName:"credentials_".concat(e.clientId),storage:this.storage,clientId:e.clientId,credentials:this.publishable_key?{access_token:this.publishable_key,token_type:"Bearer",scope:"publishable_key",expires_at:new Date(+new Date+ +new Date),expires_in:+new Date+ +new Date}:null}),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+=v.charAt((t=r<<16|n<<8|o)>>18&63)+v.charAt(t>>12&63)+v.charAt(t>>6&63)+v.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,G.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 Y((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 Y((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(Z.retryInterval)}return h}))()}wxCloudCallFunction(e,t){var r=this;return Y((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=(0,l.y)(e):n=null==c?void 0:c.body}catch(t){o={error:a.UNREACHABLE,error_description:t.message,error_uri:(0,l.y)(e)}}if(o)throw o;return n}))()}getCredentials(){var e=this;return Y((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(z(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 Y((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 Y((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 Y((function*(){return t.singlePromise.run("_refreshToken",Y((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 Y((function*(){return t.singlePromise.run("_anonymousLogin",Y((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<Z.minRetry||e>Z.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 Y((function*(){return new Promise(t=>{setTimeout(()=>{t()},e)})}))()}anonymousSignIn(e){var r=this;return Y((function*(){return r.singlePromise.run("_anonymous",Y((function*(){if(!e||"anonymous"!==e.scope)return r.unAuthenticatedError("no anonymous in credentials");try{var n=yield r.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield r.localCredentials.setCredentials(n),n}catch(e){return e.error===a.INVALID_GRANT?(yield r.localCredentials.setCredentials(null),r.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,r){var n=this;return Y((function*(){if(void 0===e||""===e){var i,a="refresh token not found";return null===(i=n.onCredentialsError)||void 0===i||i.call(n,{msg:a}),n.unAuthenticatedError(a)}var s=t.AUTH_TOKEN_URL;return"v2"===(null==r?void 0:r.version)&&(s=o.AUTH_TOKEN_URL),B(B({},yield n.request(s,{method:"POST",body:{client_id:n.clientId,client_secret:n.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==r?void 0:r.version)||"v1"})}))()}getDeviceId(){var e=this;return Y((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 $(){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}Z.defaultRetry=2,Z.minRetry=0,Z.maxRetry=5,Z.retryInterval=1e3;var ee=!1;function te(){ee=ee||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{$()||(ee=ee||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?te():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",te,!1))}catch(V){}function re(){return ee}const ne=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 oe(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 ie(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){oe(i,n,o,a,s,"next",e)}function s(e){oe(i,n,o,a,s,"throw",e)}a(void 0)}))}}class ae{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=J),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))||$()}request(e,t){var r=this;return ie((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()&&!re()&&(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 ie((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 ne(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,r){var n=this;return ie((function*(){if(!e){var o=yield n.findCaptchaToken();if(o)return o}var i;if(n.isMatch()||re()){var a=yield n.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:""},withCredentials:!1});i={url:"".concat(a.data,"?state=").concat(encodeURIComponent(r),"&token=").concat(encodeURIComponent(a.token))}}else{var s="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((i=yield n.config.request(t.GET_CAPTCHA_URL,{method:"POST",body:{client_id:n.config.clientId,redirect_uri:s,state:r},withCredentials:!1})).captcha_token){var c={captcha_token:i.captcha_token,expires_in:i.expires_in};return n.saveCaptchaToken(c),i.captcha_token}}var u=yield n.config.openURIWithCallback(i.url);return n.saveCaptchaToken(u),u.captcha_token}))()}appendCaptchaTokenToURL(e,t,r){var n=this;return ie((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 ie((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 ie((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 se=["provider_redirect_uri","other_params"];function ce(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 ue(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function a(e){ce(i,n,o,a,s,"next",e)}function s(e){ce(i,n,o,a,s,"throw",e)}a(void 0)}))}}function le(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 de(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?le(Object(r),!0).forEach((function(t){he(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):le(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function he(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 fe(e,t){try{var n;if(((null==t||null===(n=t.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return;0}catch(t){if(e)return(()=>{try{return r(3)}catch(e){return}})()}}class pe{static parseParamsToSearch(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),new ne(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,publishable_key:e.publishable_key};r=new Z(n)}if(!t){var o=r.request.bind(r),i=new ae(de({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||J,adapter:e.adapter}}getParamsByVersion(e,r){var n,i=(0,l.I)(e),a=(null===(n={v2:o}[null==i?void 0:i.version])||void 0===n?void 0:n[r])||t[r];return i&&delete i.version,{params:i,url:a}}signIn(e){var t=this;return ue((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(de(de({},i),{},{version:r})),Promise.resolve(i)}))()}signInAnonymously(){var e=arguments,r=this;return ue((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},o=e.length>1&&void 0!==e[1]&&e[1],i=yield r.config.request(t.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:n,useWxCloud:o});return yield r.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}signUp(e){var r=this;return ue((function*(){var n=yield r.config.request(t.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signOut(e){var r=this;return ue((function*(){var n={};if(e){try{n=yield r.config.request(t.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield r.config.credentialsClient.setCredentials(),n}var o=yield r.config.credentialsClient.getAccessToken(),i=yield r.config.request(t.AUTH_REVOKE_URL,{method:"POST",body:{token:o}});return yield r.config.credentialsClient.setCredentials(),Promise.resolve(i)}))()}revokeAllDevices(){var e=this;return ue((function*(){yield e.config.request(t.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var r=this;return ue((function*(){yield r.config.request(t.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,r){var n=this;return ue((function*(){var o=!1;"CUR_USER"===e.target?o=!0:(yield n.hasLoginState())&&(o=!0);return n.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(null==r?void 0:r.withCaptcha)||!1,withCredentials:o})}))()}verify(e){var t=this;return ue((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(de(de({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var r=this;return ue((function*(){var{provider_redirect_uri:n,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,se);n&&!i.redirect_uri&&(i.redirect_uri=n);var a="".concat(t.PROVIDER_URI_URL,"?").concat(pe.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)))}),r.config.request(a,{method:"GET"})}))()}grantProviderToken(e){var r=arguments,n=this;return ue((function*(){var o=r.length>1&&void 0!==r[1]&&r[1];return n.config.request(t.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:o})}))()}patchProviderToken(e){var r=this;return ue((function*(){return r.config.request(t.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return ue((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(de(de({},i),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(i)}))()}signInCustom(e){var r=this;return ue((function*(){var n=yield r.config.request(t.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield r.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}signInWithWechat(){var e=arguments,r=this;return ue((function*(){var n=e.length>0&&void 0!==e[0]?e[0]:{},o=yield r.config.request(t.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:n});return yield r.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}bindWithProvider(e){var r=this;return ue((function*(){return r.config.request(t.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return ue((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return ue((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 ne(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 ue((function*(){return yield e.config.request(t.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return ue((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(pe.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return ue((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return ue((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var r=this;return ue((function*(){return r.config.request(t.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return ue((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 ue((function*(){return e.config.request(t.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var r=this;return ue((function*(){return r.config.request("".concat(t.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var r=this;return ue((function*(){return r.config.request("".concat(t.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var r=this;return ue((function*(){return r.config.request("".concat(t.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var r=this;return ue((function*(){return r.config.request("".concat(t.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return ue((function*(){var r=yield t.sudo({password:e.old_password});return t.setPassword({sudo_token:r.sudo_token,new_password:e.new_password})}))()}sudo(e){var r=this;return ue((function*(){return r.config.request("".concat(t.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var r=this;return ue((function*(){return e.target="CUR_USER",r.config.request(t.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var r=this;return ue((function*(){return r.config.request("".concat(t.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var r=this;return ue((function*(){return r.config.request(t.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var r=this;return ue((function*(){return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var r=this;return ue((function*(){var n=new ne(e);return r.config.request("".concat(t.USER_QUERY_URL,"?").concat(n.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return ue((function*(){var t=e.getCustomSignTicketFn;if(!t)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield t();return e.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(e){var r=this;return ue((function*(){return r.config.request(t.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var r=this;return ue((function*(){return r.config.request(t.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var r=this;return ue((function*(){return r.config.request(t.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var r=this;return ue((function*(){return r.config.request(t.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var r=this;return ue((function*(){var n="".concat(t.AUTHORIZE_INFO_URL,"?").concat(pe.parseParamsToSearch(e)),o=!0,i=!1;return(yield r.hasLoginState())&&(i=!0,o=!1),r.config.request(n,{method:"GET",withBasicAuth:o,withCredentials:i})}))()}checkUsername(e){var r=this;return ue((function*(){return r.config.request(t.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var r=this;return ue((function*(){var n=new ne(e);return r.config.request("".concat(t.CHECK_IF_USER_EXIST,"?").concat(n.toString()),{method:"GET"})}))()}loginScope(){var e=this;return ue((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return ue((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return ue((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(de(de({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return ue((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return ue((function*(){return e.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return ue((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=(0,l.I)(e),o=fe(r,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 ue((function*(){return e.config.request(t.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var r=this;return ue((function*(){var{token:n,key:o}=e;return r.config.request(t.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:n,key:o},withCredentials:!1})}))()}createCaptchaData(e){var r=this;return ue((function*(){var{state:n,redirect_uri:o}=e;return r.config.request(t.CAPTCHA_DATA_URL,{method:"POST",body:{state:n,redirect_uri:o},withCredentials:!1})}))()}getMiniProgramCode(e){var r=this;return ue((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var r=this;return ue((function*(){return r.config.request(t.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var r=this;return ue((function*(){var n="".concat(t.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[e.type],"&limit=").concat(e.limit).concat(e.page_token?"&page_token=".concat(e.page_token):"");return r.config.request(n,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var r=this;return ue((function*(){var n="",o="",i=fe(!0,r.config.adapter);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var a=yield r.getPublicKey();if(n=a.public_key,o=a.public_key_thumbprint,!n||!o)throw a}catch(e){throw e}var s=e.password?i.getEncryptInfo({publicKey:n,payload:e.password}):"",c=i.getEncryptInfo({publicKey:n,payload:e.new_password});return r.config.request(t.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:s,encrypt_new_password:c,public_key_thumbprint:o}})}))()}modifyPasswordWithoutLogin(e){var t=this;return ue((function*(){var r="",n="",i=fe(!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 ve(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 ye(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ve(Object(r),!0).forEach((function(t){_e(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ve(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _e(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 ge{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,publishable_key:v}=e;this.oauth2client=new Z({apiOrigin:t,apiPath:r,clientId:n,env:o,storage:i,baseRequest:s||a,anonymousSignInFunc:u,wxCloud:l,onCredentialsError:h,headers:f||{},i18n:p,publishable_key:v}),this.authApi=new pe(ye(ye({credentialsClient:this.oauth2client},e),{},{request:a?this.oauth2client.request.bind(this.oauth2client):void 0,adapter:d}))}}})(),n})());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/oauth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "cloudbase javascript sdk auth componets",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -20,13 +20,13 @@
|
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@babel/preset-env": "^7.25.3",
|
|
23
|
-
"@cloudbase/types": "
|
|
24
|
-
"@cloudbase/utilities": "
|
|
23
|
+
"@cloudbase/types": "3.0.0",
|
|
24
|
+
"@cloudbase/utilities": "3.0.0",
|
|
25
25
|
"@types/node": "^22.5.4",
|
|
26
26
|
"terser-webpack-plugin": "^3.0.2",
|
|
27
27
|
"ts-loader": "^9.5.1",
|
|
28
28
|
"webpack-bundle-analyzer": "^4.9.1"
|
|
29
29
|
},
|
|
30
30
|
"license": "Apache-2.0",
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "a70e7266db7be901d909b1fa63c1651e2a7943e4"
|
|
32
32
|
}
|
package/src/auth/apis.ts
CHANGED
|
@@ -92,7 +92,9 @@ function getEncryptUtils(isEncrypt, adapter: SDKAdapterInterface) {
|
|
|
92
92
|
return getUtils()
|
|
93
93
|
}
|
|
94
94
|
} catch (error) {
|
|
95
|
-
|
|
95
|
+
if (isEncrypt) {
|
|
96
|
+
return getUtils()
|
|
97
|
+
}
|
|
96
98
|
}
|
|
97
99
|
}
|
|
98
100
|
|
|
@@ -116,6 +118,7 @@ export interface AuthOptions {
|
|
|
116
118
|
onCredentialsError?: (data: { msg: string; eventType?: 'credentials_error' }) => void
|
|
117
119
|
headers?: { [key: string]: string }
|
|
118
120
|
i18n?: ICloudbaseConfig['i18n']
|
|
121
|
+
publishable_key?: string
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
/**
|
|
@@ -155,6 +158,7 @@ export class Auth {
|
|
|
155
158
|
onCredentialsError: opts.onCredentialsError,
|
|
156
159
|
headers: opts.headers || {},
|
|
157
160
|
i18n: opts.i18n,
|
|
161
|
+
publishable_key: opts.publishable_key,
|
|
158
162
|
}
|
|
159
163
|
oAuth2Client = new OAuth2Client(initOptions)
|
|
160
164
|
}
|
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export class CloudbaseOAuth {
|
|
|
13
13
|
public authApi: Auth
|
|
14
14
|
|
|
15
15
|
constructor(authOptions: AuthOptions) {
|
|
16
|
-
const { apiOrigin, apiPath = AUTH_API_PREFIX, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError, headers, i18n } = authOptions
|
|
16
|
+
const { apiOrigin, apiPath = AUTH_API_PREFIX, clientId, env, storage, request, baseRequest, anonymousSignInFunc, wxCloud, adapter, onCredentialsError, headers, i18n, publishable_key } = authOptions
|
|
17
17
|
this.oauth2client = new OAuth2Client({
|
|
18
18
|
apiOrigin,
|
|
19
19
|
apiPath,
|
|
@@ -26,6 +26,7 @@ export class CloudbaseOAuth {
|
|
|
26
26
|
onCredentialsError,
|
|
27
27
|
headers: headers || {},
|
|
28
28
|
i18n,
|
|
29
|
+
publishable_key,
|
|
29
30
|
})
|
|
30
31
|
|
|
31
32
|
this.authApi = new Auth({
|
|
@@ -168,6 +168,7 @@ interface LocalCredentialsOptions {
|
|
|
168
168
|
tokenSectionName: string
|
|
169
169
|
storage: SimpleStorage
|
|
170
170
|
clientId: string
|
|
171
|
+
credentials?: Credentials
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
/**
|
|
@@ -208,6 +209,10 @@ class LocalCredentials {
|
|
|
208
209
|
this.storage = options.storage
|
|
209
210
|
this.clientId = options.clientId
|
|
210
211
|
this.singlePromise = new SinglePromise({ clientId: this.clientId })
|
|
212
|
+
this.credentials = options.credentials || null
|
|
213
|
+
if (this.credentials) {
|
|
214
|
+
this.setCredentials(this.credentials)
|
|
215
|
+
}
|
|
211
216
|
}
|
|
212
217
|
|
|
213
218
|
public getStorageCredentialsSync(): Credentials | null {
|
|
@@ -312,6 +317,7 @@ export class OAuth2Client implements AuthClient {
|
|
|
312
317
|
private wxCloud: any
|
|
313
318
|
private basicAuth: string
|
|
314
319
|
private onCredentialsError: AuthOptions['onCredentialsError'] | undefined
|
|
320
|
+
private publishable_key: ICloudbaseConfig['publishable_key']
|
|
315
321
|
|
|
316
322
|
/**
|
|
317
323
|
* constructor
|
|
@@ -330,6 +336,7 @@ export class OAuth2Client implements AuthClient {
|
|
|
330
336
|
this.apiPath = options.apiPath || AUTH_API_PREFIX
|
|
331
337
|
this.clientId = options.clientId
|
|
332
338
|
this.i18n = options.i18n
|
|
339
|
+
this.publishable_key = options.publishable_key
|
|
333
340
|
this.singlePromise = new SinglePromise({ clientId: this.clientId })
|
|
334
341
|
this.retry = this.formatRetry(options.retry, OAuth2Client.defaultRetry)
|
|
335
342
|
if (options.baseRequest) {
|
|
@@ -345,6 +352,13 @@ export class OAuth2Client implements AuthClient {
|
|
|
345
352
|
tokenSectionName: `credentials_${options.clientId}`,
|
|
346
353
|
storage: this.storage,
|
|
347
354
|
clientId: options.clientId,
|
|
355
|
+
credentials: this.publishable_key ? {
|
|
356
|
+
access_token: this.publishable_key,
|
|
357
|
+
token_type: 'Bearer',
|
|
358
|
+
scope: 'publishable_key',
|
|
359
|
+
expires_at: new Date(+new Date() + +new Date()),
|
|
360
|
+
expires_in: +new Date() + +new Date(),
|
|
361
|
+
} : null,
|
|
348
362
|
})
|
|
349
363
|
|
|
350
364
|
this.clientSecret = options.clientSecret
|