@cloudbase/js-sdk
Version:
cloudbase javascript sdk
1 lines • 91.2 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],e):"object"==typeof exports?exports.cloudbase_oauth=e():t.cloudbase_oauth=e()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var t={118:function(t,e,r){var n=this&&this.__createBinding||(Object.create?function(t,e,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(e,r);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,n,i)}:function(t,e,r,n){void 0===n&&(n=r),t[n]=e[r]}),i=this&&this.__exportStar||function(t,e){for(var r in t)"default"===r||Object.prototype.hasOwnProperty.call(e,r)||n(e,t,r)};Object.defineProperty(e,"__esModule",{value:!0}),i(r(340),e)},340:(t,e,r)=>{r.r(e),r.d(e,{AUTH_API_PREFIX:()=>h,Auth:()=>vt,CloudbaseOAuth:()=>_t,authModels:()=>n});var n={};r.r(n);var i,o,s,a,u,c,h="/auth";function l(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(t=>{var e=16*Math.random()|0;return("x"===t?e:3&e|8).toString(16)}))}!function(t){t.AUTH_SIGN_UP_URL="/v1/signup",t.AUTH_TOKEN_URL="/v1/token",t.AUTH_REVOKE_URL="/v1/revoke",t.WEDA_USER_URL="/v1/plugin/weda/userinfo",t.AUTH_RESET_PASSWORD="/v1/reset",t.AUTH_GET_DEVICE_CODE="/v1/device/code",t.CHECK_USERNAME="/v1/checkUsername",t.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",t.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",t.AUTH_SIGN_IN_URL="/v1/signin",t.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",t.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",t.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",t.PROVIDER_TOKEN_URL="/v1/provider/token",t.PROVIDER_URI_URL="/v1/provider/uri",t.USER_ME_URL="/v1/user/me",t.AUTH_SIGNOUT_URL="/v1/user/signout",t.USER_QUERY_URL="/v1/user/query",t.USER_PRIFILE_URL="/v1/user/profile",t.USER_BASIC_EDIT_URL="/v1/user/basic/edit",t.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",t.PROVIDER_LIST="/v1/user/provider",t.PROVIDER_BIND_URL="/v1/user/provider/bind",t.PROVIDER_UNBIND_URL="/v1/user/provider",t.CHECK_PWD_URL="/v1/user/sudo",t.SUDO_URL="/v1/user/sudo",t.BIND_CONTACT_URL="/v1/user/contact",t.AUTH_SET_PASSWORD="/v1/user/password",t.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",t.AUTHORIZE_URL="/v1/user/authorize",t.AUTHORIZE_INFO_URL="/v1/user/authorize/info",t.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",t.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",t.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",t.VERIFICATION_URL="/v1/verification",t.VERIFY_URL="/v1/verification/verify",t.CAPTCHA_DATA_URL="/v1/captcha/data",t.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",t.GET_CAPTCHA_URL="/v1/captcha/init",t.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",t.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(i||(i={})),function(t){t.AUTH_SIGN_IN_URL="/v2/signin/username",t.AUTH_TOKEN_URL="/v2/token",t.USER_ME_URL="/v2/user/me",t.VERIFY_URL="/v2/signin/verificationcode",t.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",t.AUTH_PUBLIC_KEY="/v2/signin/publichkey",t.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(o||(o={})),function(t){t.REGISTER="REGISTER",t.SIGN_IN="SIGN_IN",t.PASSWORD_RESET="PASSWORD_RESET",t.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",t.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(s||(s={})),(c=a||(a={})).UNREACHABLE="unreachable",c.LOCAL="local",c.CANCELLED="cancelled",c.UNKNOWN="unknown",c.UNAUTHENTICATED="unauthenticated",c.RESOURCE_EXHAUSTED="resource_exhausted",c.FAILED_PRECONDITION="failed_precondition",c.INVALID_ARGUMENT="invalid_argument",c.DEADLINE_EXCEEDED="deadline_exceeded",c.NOT_FOUND="not_found",c.ALREADY_EXISTS="already_exists",c.PERMISSION_DENIED="permission_denied",c.ABORTED="aborted",c.OUT_OF_RANGE="out_of_range",c.UNIMPLEMENTED="unimplemented",c.INTERNAL="internal",c.UNAVAILABLE="unavailable",c.DATA_LOSS="data_loss",c.INVALID_PASSWORD="invalid_password",c.PASSWORD_NOT_SET="password_not_set",c.INVALID_STATUS="invalid_status",c.USER_PENDING="user_pending",c.USER_BLOCKED="user_blocked",c.INVALID_VERIFICATION_CODE="invalid_verification_code",c.TWO_FACTOR_REQUIRED="two_factor_required",c.INVALID_TWO_FACTOR="invalid_two_factor",c.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",c.UNDER_REVIEW="under_review",c.INVALID_REQUEST="invalid_request",c.UNAUTHORIZED_CLIENT="unauthorized_client",c.ACCESS_DENIED="access_denied",c.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",c.INVALID_SCOPE="invalid_scope",c.INVALID_GRANT="invalid_grant",c.SERVER_ERROR="server_error",c.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",c.INTERACTION_REQUIRED="interaction_required",c.LOGIN_REQUIRED="login_required",c.ACCOUNT_SELECTION_REQUIRED="account_selection_required",c.CONSENT_REQUIRED="consent_required",c.INVALID_REQUEST_URI="invalid_request_uri",c.INVALID_REQUEST_OBJECT="invalid_request_object",c.REQUEST_NOT_SUPPORTED="request_not_supported",c.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",c.REGISTRATION_NOT_SUPPORTED="registration_not_supported",c.CAPTCHA_REQUIRED="captcha_required",c.CAPTCHA_INVALID="captcha_invalid",function(t){t.CLIENT_ID="client_id",t.CLIENT_SECRET="client_secret",t.RESPONSE_TYPE="response_type",t.SCOPE="scope",t.STATE="state",t.REDIRECT_URI="redirect_uri",t.ERROR="error",t.ERROR_DESCRIPTION="error_description",t.ERROR_URI="error_uri",t.GRANT_TYPE="grant_type",t.CODE="code",t.ACCESS_TOKEN="access_token",t.TOKEN_TYPE="token_type",t.EXPIRES_IN="expires_in",t.USERNAME="username",t.PASSWORD="password",t.REFRESH_TOKEN="refresh_token"}(u||(u={}));var d=r(655);function f(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function p(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){f(o,n,i,s,a,"next",t)}function a(t){f(o,n,i,s,a,"throw",t)}s(void 0)}))}}var v=new Map;class g{constructor(t){this.clientId=(null==t?void 0:t.clientId)||"",v=v||new Map}run(t,e){var r=this;return p((function*(){t="".concat(r.clientId,"_").concat(t);var n=v.get(t);return n||(n=new Promise(((n,i)=>{p((function*(){try{yield r.runIdlePromise();var o=e();n(yield o)}catch(t){i(t)}finally{v.delete(t)}}))()})),v.set(t,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var m="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function y(){if("undefined"==typeof globalThis)return!1;var{wx:t}=globalThis;if(void 0===t)return!1;if(void 0===globalThis.Page)return!1;if(!t.getSystemInfoSync)return!1;if(!t.getStorageSync)return!1;if(!t.setStorageSync)return!1;if(!t.connectSocket)return!1;if(!t.request)return!1;try{if(!t.getSystemInfoSync())return!1;if("qq"===t.getSystemInfoSync().AppPlatform)return!1}catch(t){return!1}return!0}var _=!1;function b(){_=_||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{y()||(_=_||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?b():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",b,!1))}catch(G){}function T(){return _}var E="@cloudbase/js-sdk";function S(){return E}var w,I="INVALID_OPERATION",O="OPERATION_FAIL";!function(t){t.local="local",t.none="none",t.session="session"}(w||(w={}));function R(t,e){console.warn("[".concat(S(),"][").concat(t,"]:").concat(e))}var C,A,P=(C=function(t,e){return C=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},C(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function r(){this.constructor=t}C(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),U=function(){return U=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var i in e=arguments[r])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},U.apply(this,arguments)},D=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},N=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};!function(t){function e(e){var r=t.call(this)||this,n=e.timeout,i=e.timeoutMsg,o=e.restrictedMethods;return r.timeout=n||0,r.timeoutMsg=i||"请求超时",r.restrictedMethods=o||["get","post","upload","download"],r}P(e,t),e.prototype.get=function(t){return this.request(U(U({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(U(U({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(U(U({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,r=t.file,n=t.name,i=t.method,o=t.headers,s=void 0===o?{}:o,a={post:"post",put:"put"}[null==i?void 0:i.toLowerCase()]||"put",u=new FormData;return"post"===a?(Object.keys(e).forEach((function(t){u.append(t,e[t])})),u.append("key",n),u.append("file",r),this.request(U(U({},t),{data:u,method:a}),this.restrictedMethods.includes("upload"))):this.request(U(U({},t),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return D(this,void 0,void 0,(function(){var e,r,n,i;return N(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,this.get(U(U({},t),{headers:{},responseType:"blob"}))];case 1:return e=o.sent().data,r=window.URL.createObjectURL(new Blob([e])),n=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(i=document.createElement("a")).href=r,i.setAttribute("download",n),i.style.display="none",document.body.appendChild(i),i.click(),window.URL.revokeObjectURL(r),document.body.removeChild(i),[3,3];case 2:return o.sent(),[3,3];case 3:return[2,new Promise((function(e){e({statusCode:200,tempFilePath:t.url})}))]}}))}))},e.prototype.fetch=function(t){var e;return D(this,void 0,void 0,(function(){var r,n,i,o,s,a,u,c,h,l,d,f=this;return N(this,(function(p){switch(p.label){case 0:return r=new AbortController,n=t.url,i=t.enableAbort,o=void 0!==i&&i,s=t.stream,a=void 0!==s&&s,u=t.signal,c=t.timeout,h=null!=c?c:this.timeout,u&&(u.aborted&&r.abort(),u.addEventListener("abort",(function(){return r.abort()}))),l=null,o&&h&&(l=setTimeout((function(){console.warn(f.timeoutMsg),r.abort(new Error(f.timeoutMsg))}),h)),[4,fetch(n,U(U({},t),{signal:r.signal})).then((function(t){return D(f,void 0,void 0,(function(){var e,r,n;return N(this,(function(i){switch(i.label){case 0:return clearTimeout(l),t.ok?(e=t,[3,3]):[3,1];case 1:return n=(r=Promise).reject,[4,t.json()];case 2:e=n.apply(r,[i.sent()]),i.label=3;case 3:return[2,e]}}))}))})).catch((function(t){return clearTimeout(l),Promise.reject(t)}))];case 1:return d=p.sent(),[2,{data:a?d.body:(null===(e=d.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.headers}]}}))}))},e.prototype.request=function(t,e){var r=this;void 0===e&&(e=!1);var n=String(t.method).toLowerCase()||"get";return new Promise((function(i){var o,s,a,u=t.url,c=t.headers,h=void 0===c?{}:c,l=t.data,d=t.responseType,f=t.withCredentials,p=t.body,v=t.onUploadProgress,g=function(t,e,r){void 0===r&&(r={});var n=/\?/.test(e),i="";return Object.keys(r).forEach((function(t){""===i?!n&&(e+="?"):i+="&",i+="".concat(t,"=").concat(encodeURIComponent(r[t]))})),/^http(s)?:\/\//.test(e+=i)?e:"".concat(t).concat(e)}("https:",u,"get"===n?l:{}),m=new XMLHttpRequest;m.open(n,g),d&&(m.responseType=d),Object.keys(h).forEach((function(t){m.setRequestHeader(t,h[t])})),v&&m.upload.addEventListener("progress",v),m.onreadystatechange=function(){var t={};if(4===m.readyState){var e=m.getAllResponseHeaders().trim().split(/[\r\n]+/),r={};e.forEach((function(t){var e=t.split(": "),n=e.shift().toLowerCase(),i=e.join(": ");r[n]=i})),t.header=r,t.statusCode=m.status;try{t.data="blob"===d?m.response:JSON.parse(m.responseText)}catch(e){t.data="blob"===d?m.response:m.responseText}clearTimeout(o),i(t)}},e&&r.timeout&&(o=setTimeout((function(){console.warn(r.timeoutMsg),m.abort()}),r.timeout)),a=l,s="[object FormData]"===Object.prototype.toString.call(a)?l:"application/x-www-form-urlencoded"===h["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach((function(r){e.push("".concat(r,"=").concat(encodeURIComponent(t[r])))})),e.join("&")}(l):p||(l?JSON.stringify(l):void 0),f&&(m.withCredentials=!0),m.send(s)}))}}((function(){})),function(t){t.WEB="web",t.WX_MP="wx_mp"}(A||(A={}));var L=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,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=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),x=function(t,e,r,n){return new(r||(r=Promise))((function(i,o){function s(t){try{u(n.next(t))}catch(t){o(t)}}function a(t){try{u(n.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(s,a)}u((n=n.apply(t,e||[])).next())}))},k=function(t,e){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!((i=(i=s.trys).length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},q=function(t){function e(e){var r=t.call(this)||this;return r.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),r}return L(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}((function(){}));!function(){function t(t){this.keys={};var e=t.persistence,r=t.platformInfo,n=void 0===r?{}:r,i=t.keys,o=void 0===i?{}:i;this.platformInfo=n,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(R("INVALID_PARAMS","localStorage is not supported on current platform"),new q(e.root));case"none":return new q(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=o)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,r){if("async"!==this.mode){if(this.storage)try{var n={version:r||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(n))}catch(t){throw new Error(JSON.stringify({code:O,msg:"[".concat(S(),"][").concat(O,"]setStore failed"),info:t}))}}else R(I,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,r){return x(this,void 0,void 0,(function(){var n;return k(this,(function(i){switch(i.label){case 0:if(!this.storage)return[2];i.label=1;case 1:return i.trys.push([1,3,,4]),n={version:r||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(n))];case 2:return i.sent(),[3,4];case 3:return i.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,e){var r;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var n=this.storage.getItem(t);return n&&n.indexOf(e)>=0?JSON.parse(n).content:""}R(I,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var r;return x(this,void 0,void 0,(function(){var n;return k(this,(function(i){switch(i.label){case 0:try{if("undefined"!=typeof process&&(null===(r={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return[2,{IS_MP_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(n=i.sent())&&n.indexOf(e)>=0?[2,JSON.parse(n).content]:[2,""]}}))}))},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):R(I,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return x(this,void 0,void 0,(function(){return k(this,(function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}}))}))}}();var B=function(){var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])},t(e,r)};return function(e,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=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),j=function(t,e){this.data=e||null,this.name=t},M=function(t){function e(e,r){var n=t.call(this,"error",{error:e,data:r})||this;return n.error=e,n}return B(e,t),e}(j),H=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,r){r[t]=r[t]||[],r[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,r){if(null==r?void 0:r[t]){var n=r[t].indexOf(e);-1!==n&&r[t].splice(n,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof M)return console.error(t.error),this;var r="string"==typeof t?new j(t,e||{}):t,n=r.name;if(this.listens(n)){r.target=this;for(var i=0,o=this.listeners[n]?function(t,e,r){if(r||2===arguments.length)for(var n,i=0,o=e.length;i<o;i++)!n&&i in e||(n||(n=Array.prototype.slice.call(e,0,i)),n[i]=e[i]);return t.concat(n||Array.prototype.slice.call(e))}([],this.listeners[n],!0):[];i<o.length;i++)o[i].call(this,r)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new H;var V=new H;function G(t){this.message=t}function F(t){this.message=t}function K(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function W(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?K(Object(r),!0).forEach((function(e){Y(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):K(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function Y(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function z(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function Z(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){z(o,n,i,s,a,"next",t)}function a(t){z(o,n,i,s,a,"throw",t)}s(void 0)}))}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),G.prototype=new Error,G.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),F.prototype=new Error,F.prototype.name="InvalidTokenError";var Q="x-request-id",J="x-device-id",X="device_id",$=function(){var t=Z((function*(t,e){var r=null,n=null;try{var i=Object.assign({},e);i.method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body));var o=yield fetch(t,i),s=yield o.json();null!=s&&s.error?(n=s).error_uri=new URL(t).pathname:r=s}catch(e){n={error:a.UNREACHABLE,error_description:e.message,error_uri:new URL(t).pathname}}if(n)throw n;return r}));return function(e,r){return t.apply(this,arguments)}}(),tt=new class{constructor(t){this._env=(null==t?void 0:t.env)||""}getItem(t){var e=this;return Z((function*(){return window.localStorage.getItem("".concat(t).concat(e._env))}))()}removeItem(t){var e=this;return Z((function*(){window.localStorage.removeItem("".concat(t).concat(e._env))}))()}setItem(t,e){var r=this;return Z((function*(){window.localStorage.setItem("".concat(t).concat(r._env),e)}))()}getItemSync(t){return window.localStorage.getItem("".concat(t).concat(this._env))}removeItemSync(t){window.localStorage.removeItem("".concat(t).concat(this._env))}setItemSync(t,e){window.localStorage.setItem("".concat(t).concat(this._env),e)}};function et(t){var e=!0;return null!=t&&t.expires_at&&null!=t&&t.access_token&&(e=t.expires_at<new Date),e}class rt{constructor(t){this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=t.tokenSectionName,this.storage=t.storage,this.clientId=t.clientId,this.singlePromise=new g({clientId:this.clientId}),this.credentials=t.credentials||null}getStorageCredentialsSync(){var t=null,e=this.storage.getItemSync(this.tokenSectionName);if(null!=e)try{var r;null!==(r=t=JSON.parse(e))&&void 0!==r&&r.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(e){this.storage.removeItem(this.tokenSectionName),t=null}return t}setCredentials(t){var e=this;return Z((function*(){if(null!=t&&t.expires_in){if(null!=t&&t.expires_at||(t.expires_at=new Date(Date.now()+1e3*(t.expires_in-30))),e.storage){var r=JSON.stringify(t);yield e.storage.setItem(e.tokenSectionName,r)}e.credentials=t}else e.storage&&(yield e.storage.removeItem(e.tokenSectionName)),e.credentials=null}))()}setAccessKeyCredentials(t){this.accessKeyCredentials=t}getCredentials(){var t=this;return Z((function*(){return t.singlePromise.run("getCredentials",Z((function*(){if(et(t.credentials)){var{credentials:e,isAccessKeyCredentials:r}=yield t.getStorageCredentials();if(r)return e;t.credentials=e}return t.credentials})))}))()}getStorageCredentials(){var t=this;return Z((function*(){return t.singlePromise.run("_getStorageCredentials",Z((function*(){var e=null,r=!1,n=yield t.storage.getItem(t.tokenSectionName);if(n)try{var i;null!==(i=e=JSON.parse(n))&&void 0!==i&&i.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(r){yield t.storage.removeItem(t.tokenSectionName),e=null}else e=t.accessKeyCredentials||null,r=!0;return{credentials:e,isAccessKeyCredentials:r}})))}))()}}class nt{constructor(t){this.singlePromise=null,t.clientSecret||(t.clientSecret=""),!t.clientId&&t.env&&(t.clientId=t.env),this.apiOrigin=t.apiOrigin,this.apiPath=t.apiPath||h,this.clientId=t.clientId,this.i18n=t.i18n,this.singlePromise=new g({clientId:this.clientId}),this.retry=this.formatRetry(t.retry,nt.defaultRetry),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=$,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||tt,this.localCredentials=new rt({tokenSectionName:"credentials_".concat(t.clientId),storage:this.storage,clientId:t.clientId}),this.clientSecret=t.clientSecret,t.clientId&&(this.basicAuth="Basic ".concat(function(t){for(var e,r,n,i,o="",s=0,a=(t=String(t)).length%3;s<t.length;){if((r=t.charCodeAt(s++))>255||(n=t.charCodeAt(s++))>255||(i=t.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");o+=m.charAt((e=r<<16|n<<8|i)>>18&63)+m.charAt(e>>12&63)+m.charAt(e>>6&63)+m.charAt(63&e)}return a?o.slice(0,a-3)+"===".substring(a):o}("".concat(t.clientId,":").concat(this.clientSecret)))),this.wxCloud=t.wxCloud;try{y()&&(this.useWxCloud=t.useWxCloud,void 0===this.wxCloud&&t.env&&(wx.cloud.init({env:t.env}),this.wxCloud=wx.cloud))}catch(t){}this.refreshTokenFunc=t.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=t.anonymousSignInFunc,this.onCredentialsError=t.onCredentialsError,V.on("lang_change",(t=>{var e;this.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||this.i18n}))}setCredentials(t){return this.localCredentials.setCredentials(t)}setAccessKeyCredentials(t){return this.localCredentials.setAccessKeyCredentials(t)}getAccessToken(){var t=this;return Z((function*(){var e=yield t.getCredentials();if(null!=e&&e.access_token)return Promise.resolve(e.access_token);var r={error:a.UNAUTHENTICATED};return Promise.reject(r)}))()}request(t,e){var r=this;return Z((function*(){var n,i,o,s;e||(e={});var u=r.formatRetry(e.retry,r.retry);if(e.headers=W(W({},e.headers),{},{[null===(n=r.i18n)||void 0===n?void 0:n.LANG_HEADER_KEY]:null===(i=r.i18n)||void 0===i?void 0:i.lang}),r.headers&&(e.headers=W(W({},r.headers),e.headers)),e.headers[Q]||(e.headers[Q]=l()),!e.headers[J]){var c=yield r.getDeviceId();e.headers[J]=c}if(null!==(o=e)&&void 0!==o&&o.withBasicAuth&&r.basicAuth&&(e.headers.Authorization=r.basicAuth),null!==(s=e)&&void 0!==s&&s.withCredentials){var h=yield r.getCredentials();h&&(r.tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token=".concat(h.access_token)):e.headers.Authorization="".concat(h.token_type," ").concat(h.access_token))}else r.clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id=".concat(r.clientId));t.startsWith("/")&&(t="".concat(r.apiOrigin).concat(r.apiPath).concat(t));for(var d=null,f=u+1,p=0;p<f;p++){try{d=e.useWxCloud||r.useWxCloud?yield r.wxCloudCallFunction(t,e):yield r.baseRequest(t,e);break}catch(t){if(e.withCredentials&&t&&t.error===a.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(t);if(p===u||!t||"unreachable"!==t.error)return Promise.reject(t)}yield r.sleep(nt.retryInterval)}return d}))()}wxCloudCallFunction(t,e){var r=this;return Z((function*(){var n=null,i=null;try{var o,s="";try{s=yield wx.getRendererUserAgent()}catch(t){}var{result:u}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:t,method:e.method,headers:W({origin:"https://servicewechat.com","User-Agent":s},e.headers),body:e.body}});null!=u&&null!==(o=u.body)&&void 0!==o&&o.error_code?(i=null==u?void 0:u.body).error_uri=(0,d.y)(t):n=null==u?void 0:u.body}catch(e){i={error:a.UNREACHABLE,error_description:e.message,error_uri:(0,d.y)(t)}}if(i)throw i;return n}))()}getCredentials(){var t=this;return Z((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}if(et(e))if(e.refresh_token)try{e=yield t.refreshToken(e)}catch(r){var i;if("anonymous"!==e.scope)return null===(i=t.onCredentialsError)||void 0===i||i.call(t,{msg:r.error_description}),Promise.reject(r);e=yield t.anonymousLogin(e)}else{if("anonymous"!==e.scope){var o,s="no refresh token found in credentials";return null===(o=t.onCredentialsError)||void 0===o||o.call(t,{msg:s}),t.unAuthenticatedError(s)}e=yield t.anonymousLogin(e)}return e}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var t=this;return Z((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.scope}))()}getGroups(){var t=this;return Z((function*(){var e=yield t.localCredentials.getCredentials();if(!e){var r,n="credentials not found";return null===(r=t.onCredentialsError)||void 0===r||r.call(t,{msg:n}),t.unAuthenticatedError(n)}return e.groups}))()}refreshToken(t){var e=this;return Z((function*(){return e.singlePromise.run("_refreshToken",Z((function*(){if(!t||!t.refresh_token){var r,n="no refresh token found in credentials";return null===(r=e.onCredentialsError)||void 0===r||r.call(e,{msg:n}),e.unAuthenticatedError(n)}try{var i=yield e.refreshTokenFunc(t.refresh_token,t);return yield e.localCredentials.setCredentials(i),i}catch(t){var o;if(t.error===a.INVALID_GRANT){var s;yield e.localCredentials.setCredentials(null);var u=t.error_description;return null===(s=e.onCredentialsError)||void 0===s||s.call(e,{msg:u}),e.unAuthenticatedError(u)}return null===(o=e.onCredentialsError)||void 0===o||o.call(e,{msg:t.error_description}),Promise.reject(t)}})))}))()}anonymousLogin(t){var e=this;return Z((function*(){return e.singlePromise.run("_anonymousLogin",Z((function*(){if(e.anonymousSignInFunc){var r=yield e.anonymousSignInFunc(t);t=r||(yield e.localCredentials.getCredentials())}else t=yield e.anonymousSignIn(t);return t})))}))()}checkRetry(t){var e=null;if(("number"!=typeof t||t<nt.minRetry||t>nt.maxRetry)&&(e={error:a.UNREACHABLE,error_description:"wrong options param: retry"}),e)throw e;return t}formatRetry(t,e){return void 0===t?e:this.checkRetry(t)}sleep(t){return Z((function*(){return new Promise((e=>{setTimeout((()=>{e()}),t)}))}))()}anonymousSignIn(t){var e=this;return Z((function*(){return e.singlePromise.run("_anonymous",Z((function*(){if(!t||"anonymous"!==t.scope)return e.unAuthenticatedError("no anonymous in credentials");try{var r=yield e.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield e.localCredentials.setCredentials(r),r}catch(t){return t.error===a.INVALID_GRANT?(yield e.localCredentials.setCredentials(null),e.unAuthenticatedError(t.error_description)):Promise.reject(t)}})))}))()}defaultRefreshTokenFunc(t,e){var r=this;return Z((function*(){if(void 0===t||""===t){var n,s="refresh token not found";return null===(n=r.onCredentialsError)||void 0===n||n.call(r,{msg:s}),r.unAuthenticatedError(s)}var a=i.AUTH_TOKEN_URL;return"v2"===(null==e?void 0:e.version)&&(a=o.AUTH_TOKEN_URL),W(W({},yield r.request(a,{method:"POST",body:{client_id:r.clientId,client_secret:r.clientSecret,grant_type:"refresh_token",refresh_token:t}})),{},{version:(null==e?void 0:e.version)||"v1"})}))()}getDeviceId(){var t=this;return Z((function*(){if(t.deviceID)return t.deviceID;var e=yield t.storage.getItem(X);return"string"==typeof e&&e.length>=16&&e.length<=48||(e=l(),yield t.storage.setItem(X,e)),t.deviceID=e,e}))()}unAuthenticatedError(t){var e={error:a.UNAUTHENTICATED,error_description:t};return Promise.reject(e)}}nt.defaultRetry=2,nt.minRetry=0,nt.maxRetry=5,nt.retryInterval=1e3;const it=class{constructor(t){if(this.params={},"string"==typeof t)this.parse(t);else if(t&&"object"==typeof t)for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&this.append(e,t[e])}parse(t){t.split("&").forEach((t=>{var[e,r]=t.split("=").map(decodeURIComponent);this.append(e,r)}))}append(t,e){this.params[t]?this.params[t]=this.params[t].concat([e]):this.params[t]=[e]}get(t){return this.params[t]?this.params[t][0]:null}getAll(t){return this.params[t]||[]}delete(t){delete this.params[t]}has(t){return Object.prototype.hasOwnProperty.call(this.params,t)}set(t,e){this.params[t]=[e]}toString(){var t=this,e=[],r=function(r){Object.prototype.hasOwnProperty.call(t.params,r)&&t.params[r].forEach((t=>{e.push("".concat(encodeURIComponent(r),"=").concat(encodeURIComponent(t)))}))};for(var n in this.params)r(n);return e.join("&")}};function ot(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function st(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){ot(o,n,i,s,a,"next",t)}function a(t){ot(o,n,i,s,a,"throw",t)}s(void 0)}))}}class at{constructor(t){t.openURIWithCallback||(t.openURIWithCallback=this.getDefaultOpenURIWithCallback()),t.storage||(t.storage=tt),this.config=t,this.tokenSectionName="captcha_".concat(t.clientId)}isMatch(){var t,e;return(null===(t=this.config)||void 0===t||null===(t=t.adapter)||void 0===t||null===(e=t.isMatch)||void 0===e?void 0:e.call(t))||y()}request(t,e){var r=this;return st((function*(){e||(e={}),e.method||(e.method="GET");var n,i="".concat(e.method,":").concat(t),o=t;e.withCaptcha&&(o=yield r.appendCaptchaTokenToURL(t,i,!1));try{n=yield r.config.request(o,e)}catch(n){return n.error===a.CAPTCHA_REQUIRED||n.error===a.CAPTCHA_INVALID?(t=yield r.appendCaptchaTokenToURL(t,i,n.error===a.CAPTCHA_INVALID),r.config.request(t,e)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){if(!this.isMatch()&&!T()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap"))){var t=document.createElement("div");t.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;",t.setAttribute("id","captcha_panel_wrap"),setTimeout((()=>{document.body.appendChild(t)}),0)}return this.defaultOpenURIWithCallback}defaultOpenURIWithCallback(t,e){return st((function*(){var{width:r="355px",height:n="355px"}=e||{};if(t.match(/^(data:.*)$/))return Promise.reject({error:a.UNIMPLEMENTED,error_description:"need to impl captcha data"});var i=document.getElementById("captcha_panel_wrap"),o=document.createElement("iframe");return i.innerHTML="",o.setAttribute("src",t),o.setAttribute("id","review-panel-iframe"),o.style.cssText="min-width:".concat(r,";display:block;height:").concat(n,";margin:0 auto;background-color: rgb(255, 255, 255);border: none;"),i.appendChild(o),i.style.display="block",new Promise(((t,e)=>{o.onload=function(){try{var r=window.location,n=o.contentWindow.location;if(n.host+n.pathname===r.host+r.pathname){i.style.display="none";var s=new it(n.search),a=s.get("captcha_token");return a?t({captcha_token:a,expires_in:Number(s.get("expires_in"))}):e({error:s.get("error"),error_description:s.get("error_description")})}i.style.display="block"}catch(t){i.style.display="block"}}}))}))()}getCaptchaToken(t,e){var r=this;return st((function*(){if(!t){var n=yield r.findCaptchaToken();if(n)return n}var o;if(r.isMatch()||T()){var s=yield r.config.request(i.CAPTCHA_DATA_URL,{method:"POST",body:{state:e,redirect_uri:""},withCredentials:!1});o={url:"".concat(s.data,"?state=").concat(encodeURIComponent(e),"&token=").concat(encodeURIComponent(s.token))}}else{var a="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((o=yield r.config.request(i.GET_CAPTCHA_URL,{method:"POST",body:{client_id:r.config.clientId,redirect_uri:a,state:e},withCredentials:!1})).captcha_token){var u={captcha_token:o.captcha_token,expires_in:o.expires_in};return r.saveCaptchaToken(u),o.captcha_token}}var c=yield r.config.openURIWithCallback(o.url);return r.saveCaptchaToken(c),c.captcha_token}))()}appendCaptchaTokenToURL(t,e,r){var n=this;return st((function*(){var i=yield n.getCaptchaToken(r,e);return t.indexOf("?")>0?t+="&captcha_token=".concat(i):t+="?captcha_token=".concat(i),t}))()}saveCaptchaToken(t){var e=this;return st((function*(){t.expires_at=new Date(Date.now()+1e3*(t.expires_in-10));var r=JSON.stringify(t);yield e.config.storage.setItem(e.tokenSectionName,r)}))()}findCaptchaToken(){var t=this;return st((function*(){var e=yield t.config.storage.getItem(t.tokenSectionName);if(null!=e)try{var r=JSON.parse(e);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(e){return yield t.config.storage.removeItem(t.tokenSectionName),null}return null}))()}}var ut=["provider_redirect_uri","other_params"];function ct(t,e,r,n,i,o,s){try{var a=t[o](s),u=a.value}catch(t){return void r(t)}a.done?e(u):Promise.resolve(u).then(n,i)}function ht(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var o=t.apply(e,r);function s(t){ct(o,n,i,s,a,"next",t)}function a(t){ct(o,n,i,s,a,"throw",t)}s(void 0)}))}}function lt(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function dt(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?lt(Object(r),!0).forEach((function(e){ft(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):lt(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function ft(t,e,r){return(e=function(t){var e=function(t){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var r=e.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function pt(t,e){try{var n;if(((null==e||null===(n=e.root)||void 0===n?void 0:n.globalThis)||globalThis).IS_MP_BUILD)return}catch(e){if(t)return(()=>{try{return r(171)}catch(t){return}})()}}class vt{static parseParamsToSearch(t){return Object.keys(t).forEach((e=>{t[e]||delete t[e]})),new it(t).toString()}constructor(t){var{request:e}=t,r=t.credentialsClient;if(!r){var n={apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,storage:t.storage,env:t.env,baseRequest:t.baseRequest,anonymousSignInFunc:t.anonymousSignInFunc,wxCloud:t.wxCloud,onCredentialsError:t.onCredentialsError,headers:t.headers||{},i18n:t.i18n};r=new nt(n)}if(!e){var i=r.request.bind(r),o=new at(dt({clientId:t.clientId,request:i,storage:t.storage,adapter:t.adapter},t.captchaOptions));e=o.request.bind(o)}this.config={env:t.env,apiOrigin:t.apiOrigin,apiPath:t.apiPath,clientId:t.clientId,request:e,credentialsClient:r,storage:t.storage||tt,adapter:t.adapter}}getParamsByVersion(t,e){var r,n=(0,d.I)(t),s=(null===(r={v2:o}[null==n?void 0:n.version])||void 0===r?void 0:r[e])||i[e];return n&&delete n.version,{params:n,url:s}}signIn(t){var e=this;return ht((function*(){var r=t.version||"v1",n=e.getParamsByVersion(t,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var i=yield e.getEncryptParams(n.params),o=yield e.config.request(n.url,{method:"POST",body:i});return yield e.config.credentialsClient.setCredentials(dt(dt({},o),{},{version:r})),Promise.resolve(o)}))()}signInAnonymously(){var t=arguments,e=this;return ht((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=t.length>1&&void 0!==t[1]&&t[1],o=yield e.config.request(i.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:r,useWxCloud:n});return yield e.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}signUp(t){var e=this;return ht((function*(){var r=yield e.config.request(i.AUTH_SIGN_UP_URL,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signOut(t){var e=this;return ht((function*(){var r={};if(t){try{r=yield e.config.request(i.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:t})}catch(t){t.error!==a.UNAUTHENTICATED&&console.log("sign_out_error",t)}return yield e.config.credentialsClient.setCredentials(),r}var n=yield e.config.credentialsClient.getAccessToken(),o=yield e.config.request(i.AUTH_REVOKE_URL,{method:"POST",body:{token:n}});return yield e.config.credentialsClient.setCredentials(),Promise.resolve(o)}))()}revokeAllDevices(){var t=this;return ht((function*(){yield t.config.request(i.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(t){var e=this;return ht((function*(){yield e.config.request(i.AUTHORIZED_DEVICES_DELETE_URL+t.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(t,e){var r=this;return ht((function*(){var n=!1;return("CUR_USER"===t.target||(yield r.hasLoginState()))&&(n=!0),r.config.request(i.VERIFICATION_URL,{method:"POST",body:t,withCaptcha:(null==e?void 0:e.withCaptcha)||!1,withCredentials:n})}))()}verify(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"VERIFY_URL"),n=yield e.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==t?void 0:t.version)&&(yield e.config.credentialsClient.setCredentials(dt(dt({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(t){var e=this;return ht((function*(){var{provider_redirect_uri:r,other_params:n={}}=t,o=function(t,e){if(null==t)return{};var r,n,i=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(e.includes(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(n=0;n<o.length;n++)r=o[n],e.includes(r)||{}.propertyIsEnumerable.call(t,r)&&(i[r]=t[r])}return i}(t,ut);r&&!o.redirect_uri&&(o.redirect_uri=r);var s="".concat(i.PROVIDER_URI_URL,"?").concat(vt.parseParamsToSearch(o));return Object.keys(n).forEach((t=>{var e=n[t];("sign_out_uri"!==t||(null==e?void 0:e.length)>0)&&(s+="&other_params[".concat(t,"]=").concat(encodeURIComponent(e)))})),e.config.request(s,{method:"GET"})}))()}grantProviderToken(t){var e=arguments,r=this;return ht((function*(){var n=e.length>1&&void 0!==e[1]&&e[1];return r.config.request(i.PROVIDER_TOKEN_URL,{method:"POST",body:t,useWxCloud:n})}))()}patchProviderToken(t){var e=this;return ht((function*(){return e.config.request(i.PROVIDER_TOKEN_URL,{method:"PATCH",body:t})}))()}signInWithProvider(t){var e=arguments,r=this;return ht((function*(){var n=e.length>1&&void 0!==e[1]&&e[1],i=r.getParamsByVersion(t,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),o=yield r.config.request(i.url,{method:"POST",body:i.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(dt(dt({},o),{},{version:(null==t?void 0:t.version)||"v1"})),Promise.resolve(o)}))()}signInCustom(t){var e=this;return ht((function*(){var r=yield e.config.request(i.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:t});return yield e.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signInWithWechat(){var t=arguments,e=this;return ht((function*(){var r=t.length>0&&void 0!==t[0]?t[0]:{},n=yield e.config.request(i.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:r});return yield e.config.credentialsClient.setCredentials(n),Promise.resolve(n)}))()}bindWithProvider(t){var e=this;return ht((function*(){return e.config.request(i.PROVIDER_BIND_URL,{method:"POST",body:t,withCredentials:!0})}))()}getUserProfile(t){var e=this;return ht((function*(){return e.getUserInfo(t)}))()}getUserInfo(){var t=arguments,e=this;return ht((function*(){var r,n=t.length>0&&void 0!==t[0]?t[0]:{},i=e.getParamsByVersion(n,"USER_ME_URL");if(null!==(r=i.params)&&void 0!==r&&r.query){var o=new it(i.params.query);i.url+="?".concat(o.toString())}var s=yield e.config.request(i.url,{method:"GET",withCredentials:!0});return s.sub&&(s.uid=s.sub),s}))()}getWedaUserInfo(){var t=this;return ht((function*(){return yield t.config.request(i.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"USER_ME_URL"),n="".concat(r.url,"?").concat(vt.parseParamsToSearch(r.params));return e.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var t=this;return ht((function*(){try{return yield t.config.credentialsClient.getAccessToken(),!0}catch(t){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var t=this;return ht((function*(){return t.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(t){var e=this;return ht((function*(){return e.config.request(i.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}grantToken(t){var e=this;return ht((function*(){var r=e.getParamsByVersion(t,"AUTH_TOKEN_URL");return e.config.request(r.url,{method:"POST",body:r.params})}))()}getProviders(){var t=this;return ht((function*(){return t.config.request(i.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(t){var e=this;return ht((function*(){return e.config.request("".concat(i.PROVIDER_UNBIND_URL,"/").concat(t.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(t){var e=this;return ht((function*(){return e.config.request("".concat(i.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:t})}))()}editContact(t){var e=this;return ht((function*(){return e.config.request("".concat(i.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:t})}))()}setPassword(t){var e=this;return ht((function*(){return e.config.request("".concat(i.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:t})}))()}updatePasswordByOld(t){var e=this;return ht((function*(){var r=yield e.sudo({password:t.old_password});return e.setPassword({sudo_token:r.sudo_token,new_password:t.new_password})}))()}sudo(t){var e=this;return ht((function*(){return e.config.request("".concat(i.SUDO_URL),{method:"POST",withCredentials:!0,body:t})}))()}sendVerificationCodeToCurrentUser(t){var e=this;return ht((function*(){return t.target="CUR_USER",e.config.request(i.VERIFICATION_URL,{method:"POST",body:t,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(t){var e=this;return ht((function*(){return e.config.request("".concat(i.PROVIDER_LIST,"/").concat(t.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:t.trans_token},withCredentials:!0})}))()}setUserProfile(t){var e=this;return ht((function*(){return e.config.request(i.USER_PRIFILE_URL,{method:"PATCH",body:t,withCredentials:!0})}))()}updateUserBasicInfo(t){var e=this;return ht((function*(){return e.config.request(i.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:t})}))()}queryUserProfile(t){var e=this;return ht((function*(){var r=new it(t);return e.config.request("".concat(i.USER_QUERY_URL,"?").concat(r.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(t){this.getCustomSignTicketFn=t}signInWithCustomTicket(){var t=this;return ht((function*(){var e=t.getCustomSignTicketFn;if(!e)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield e();return t.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(t){var e=this;return ht((function*(){return e.config.request(i.AUTH_RESET_PASSWORD,{method:"POST",body:t})}))()}authorize(t){var e=this;return ht((function*(){return e.config.request(i.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:t})}))()}authorizeDevice(t){var e=this;return ht((function*(){return e.config.request(i.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:t})}))()}deviceAuthorize(t){var e=this;return ht((function*(){return e.config.request(i.AUTH_GET_DEVICE_CODE,{method:"POST",body:t,withCredentials:!0})}))()}authorizeInfo(t){var e=this;return ht((function*(){var r="".concat(i.AUTHORIZE_INFO_URL,"?").concat(vt.parseParamsToSearch(t)),n=!0,o=!1;return(yield e.hasLoginState())&&(o=!0,n=!1),e.config.request(r,{method:"GET",withBasicAuth:n,withCredentials:o})}))()}checkUsername(t){var e=this;return ht((function*(){return e.config.request(i.CHECK_USERNAME,{method:"GET",body:t,withCredentials:!0})}))()}checkIfUserExist(t){var e=this;return ht((function*(){var r=new it(t);return e.config.request("".concat(i.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var t=this;return ht((function*(){return t.config.credentialsClient.getScope()}))()}loginGroups(){var t=this;return ht((function*(){return t.config.credentialsClient.getGroups()}))()}refreshTokenForce(t){var e=this;return ht((function*(){var r=yield e.config.credentialsClient.getCredentials();return yield e.config.credentialsClient.refreshToken(dt(dt({},r),{},{version:(null==t?void 0:t.version)||"v1"}))}))()}getCredentials(){var t=this;return ht((function*(){return t.config.credentialsClient.getCredentials()}))()}getPublicKey(){var t=this;return ht((function*(){return t.config.requ