UNPKG

@cloudbase/js-sdk

Version:
2 lines 233 kB
/*! For license information please see auth.js.LICENSE.txt */ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_auth",[],t):"object"==typeof exports?exports.cloudbase_auth=t():e.cloudbase_auth=t()}("undefined"!=typeof window?window:this,(()=>(()=>{"use strict";var e={325:(e,t,r)=>{var n;r.r(t),r.d(t,{AbstractSDKRequest:()=>o,AbstractStorage:()=>i,StorageType:()=>n,formatUrl:()=>s}),function(e){e.local="local",e.none="none",e.session="session"}(n||(n={}));var o=function(){},i=function(){};function s(e,t,r){void 0===r&&(r={});var n=/\?/.test(t),o="";for(var i in r)""===o?!n&&(t+="?"):o+="&",o+=i+"="+encodeURIComponent(r[i]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}},545:(e,t,r)=>{r.r(t),r.d(t,{Auth:()=>fi,LoginState:()=>di,generateAuthInstance:()=>pi,registerAuth:()=>yi});var n,o,i,s,a,u,c="/auth";function l(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}!function(e){e.AUTH_SIGN_UP_URL="/v1/signup",e.AUTH_TOKEN_URL="/v1/token",e.AUTH_REVOKE_URL="/v1/revoke",e.WEDA_USER_URL="/v1/plugin/weda/userinfo",e.AUTH_RESET_PASSWORD="/v1/reset",e.AUTH_GET_DEVICE_CODE="/v1/device/code",e.CHECK_USERNAME="/v1/checkUsername",e.CHECK_IF_USER_EXIST="/v1/checkIfUserExist",e.GET_PROVIDER_TYPE="/v1/mgr/provider/providerSubType",e.AUTH_SIGN_IN_URL="/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v1/signin/with/provider",e.AUTH_SIGN_IN_WITH_WECHAT_URL="/v1/signin/wechat/noauth",e.AUTH_SIGN_IN_CUSTOM="/v1/signin/custom",e.PROVIDER_TOKEN_URL="/v1/provider/token",e.PROVIDER_URI_URL="/v1/provider/uri",e.USER_ME_URL="/v1/user/me",e.AUTH_SIGNOUT_URL="/v1/user/signout",e.USER_QUERY_URL="/v1/user/query",e.USER_PRIFILE_URL="/v1/user/profile",e.USER_BASIC_EDIT_URL="/v1/user/basic/edit",e.USER_TRANS_BY_PROVIDER_URL="/v1/user/trans/by/provider",e.PROVIDER_LIST="/v1/user/provider",e.PROVIDER_BIND_URL="/v1/user/provider/bind",e.PROVIDER_UNBIND_URL="/v1/user/provider",e.CHECK_PWD_URL="/v1/user/sudo",e.SUDO_URL="/v1/user/sudo",e.BIND_CONTACT_URL="/v1/user/contact",e.AUTH_SET_PASSWORD="/v1/user/password",e.AUTHORIZE_DEVICE_URL="/v1/user/device/authorize",e.AUTHORIZE_URL="/v1/user/authorize",e.AUTHORIZE_INFO_URL="/v1/user/authorize/info",e.AUTHORIZED_DEVICES_DELETE_URL="/v1/user/authorized/devices/",e.AUTH_REVOKE_ALL_URL="/v1/user/revoke/all",e.GET_USER_BEHAVIOR_LOG="/v1/user/security/history",e.VERIFICATION_URL="/v1/verification",e.VERIFY_URL="/v1/verification/verify",e.CAPTCHA_DATA_URL="/v1/captcha/data",e.VERIFY_CAPTCHA_DATA_URL="/v1/captcha/data/verify",e.GET_CAPTCHA_URL="/v1/captcha/init",e.GET_MINIPROGRAM_QRCODE="/v1/qrcode/generate",e.GET_MINIPROGRAM_QRCODE_STATUS="/v1/qrcode/get/status"}(n||(n={})),function(e){e.AUTH_SIGN_IN_URL="/v2/signin/username",e.AUTH_TOKEN_URL="/v2/token",e.USER_ME_URL="/v2/user/me",e.VERIFY_URL="/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/v2/signin/password/update"}(o||(o={})),function(e){e.REGISTER="REGISTER",e.SIGN_IN="SIGN_IN",e.PASSWORD_RESET="PASSWORD_RESET",e.EMAIL_ADDRESS_CHANGE="EMAIL_ADDRESS_CHANGE",e.PHONE_NUMBER_CHANGE="PHONE_NUMBER_CHANGE"}(i||(i={})),(u=s||(s={})).UNREACHABLE="unreachable",u.LOCAL="local",u.CANCELLED="cancelled",u.UNKNOWN="unknown",u.UNAUTHENTICATED="unauthenticated",u.RESOURCE_EXHAUSTED="resource_exhausted",u.FAILED_PRECONDITION="failed_precondition",u.INVALID_ARGUMENT="invalid_argument",u.DEADLINE_EXCEEDED="deadline_exceeded",u.NOT_FOUND="not_found",u.ALREADY_EXISTS="already_exists",u.PERMISSION_DENIED="permission_denied",u.ABORTED="aborted",u.OUT_OF_RANGE="out_of_range",u.UNIMPLEMENTED="unimplemented",u.INTERNAL="internal",u.UNAVAILABLE="unavailable",u.DATA_LOSS="data_loss",u.INVALID_PASSWORD="invalid_password",u.PASSWORD_NOT_SET="password_not_set",u.INVALID_STATUS="invalid_status",u.USER_PENDING="user_pending",u.USER_BLOCKED="user_blocked",u.INVALID_VERIFICATION_CODE="invalid_verification_code",u.TWO_FACTOR_REQUIRED="two_factor_required",u.INVALID_TWO_FACTOR="invalid_two_factor",u.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",u.UNDER_REVIEW="under_review",u.INVALID_REQUEST="invalid_request",u.UNAUTHORIZED_CLIENT="unauthorized_client",u.ACCESS_DENIED="access_denied",u.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",u.INVALID_SCOPE="invalid_scope",u.INVALID_GRANT="invalid_grant",u.SERVER_ERROR="server_error",u.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",u.INTERACTION_REQUIRED="interaction_required",u.LOGIN_REQUIRED="login_required",u.ACCOUNT_SELECTION_REQUIRED="account_selection_required",u.CONSENT_REQUIRED="consent_required",u.INVALID_REQUEST_URI="invalid_request_uri",u.INVALID_REQUEST_OBJECT="invalid_request_object",u.REQUEST_NOT_SUPPORTED="request_not_supported",u.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",u.REGISTRATION_NOT_SUPPORTED="registration_not_supported",u.CAPTCHA_REQUIRED="captcha_required",u.CAPTCHA_INVALID="captcha_invalid",function(e){e.CLIENT_ID="client_id",e.CLIENT_SECRET="client_secret",e.RESPONSE_TYPE="response_type",e.SCOPE="scope",e.STATE="state",e.REDIRECT_URI="redirect_uri",e.ERROR="error",e.ERROR_DESCRIPTION="error_description",e.ERROR_URI="error_uri",e.GRANT_TYPE="grant_type",e.CODE="code",e.ACCESS_TOKEN="access_token",e.TOKEN_TYPE="token_type",e.EXPIRES_IN="expires_in",e.USERNAME="username",e.PASSWORD="password",e.REFRESH_TOKEN="refresh_token"}(a||(a={}));var h=r(655);function d(e,t,r,n,o,i,s){try{var a=e[i](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,o)}function f(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function s(e){d(i,n,o,s,a,"next",e)}function a(e){d(i,n,o,s,a,"throw",e)}s(void 0)}))}}var p=new Map;class v{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",p=p||new Map}run(e,t){var r=this;return f((function*(){e="".concat(r.clientId,"_").concat(e);var n=p.get(e);return n||(n=new Promise(((n,o)=>{f((function*(){try{yield r.runIdlePromise();var i=t();n(yield i)}catch(e){o(e)}finally{p.delete(e)}}))()})),p.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function g(){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}var m=!1;function _(){m=m||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{g()||(m=m||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?_():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",_,!1))}catch(F){}function b(){return m}var w="@cloudbase/js-sdk";function S(){return w}var I="INVALID_OPERATION",T="OPERATION_FAIL",E=r(325);function O(e,t){console.warn("[".concat(S(),"][").concat(e,"]:").concat(t))}var R,P,C=(R=function(e,t){return R=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])},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}R(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}),A=function(){return A=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},A.apply(this,arguments)},U=function(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},L=function(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=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(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}};!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}C(t,e),t.prototype.get=function(e){return this.request(A(A({},e),{method:"get"}),this.restrictedMethods.includes("get"))},t.prototype.post=function(e){return this.request(A(A({},e),{method:"post"}),this.restrictedMethods.includes("post"))},t.prototype.put=function(e){return this.request(A(A({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,r=e.file,n=e.name,o=e.method,i=e.headers,s=void 0===i?{}:i,a={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",u=new FormData;return"post"===a?(Object.keys(t).forEach((function(e){u.append(e,t[e])})),u.append("key",n),u.append("file",r),this.request(A(A({},e),{data:u,method:a}),this.restrictedMethods.includes("upload"))):this.request(A(A({},e),{method:"put",headers:s,body:r}),this.restrictedMethods.includes("upload"))},t.prototype.download=function(e){return U(this,void 0,void 0,(function(){var t,r,n,o;return L(this,(function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(A(A({},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 U(this,void 0,void 0,(function(){var r,n,o,i,s,a,u,c,l,h,d,f=this;return L(this,(function(p){switch(p.label){case 0:return r=new AbortController,n=e.url,o=e.enableAbort,i=void 0!==o&&o,s=e.stream,a=void 0!==s&&s,u=e.signal,c=e.timeout,l=null!=c?c:this.timeout,u&&(u.aborted&&r.abort(),u.addEventListener("abort",(function(){return r.abort()}))),h=null,i&&l&&(h=setTimeout((function(){console.warn(f.timeoutMsg),r.abort(new Error(f.timeoutMsg))}),l)),[4,fetch(n,A(A({},e),{signal:r.signal})).then((function(e){return U(f,void 0,void 0,(function(){var t,r,n;return L(this,(function(o){switch(o.label){case 0:return clearTimeout(h),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(h),Promise.reject(e)}))];case 1:return d=p.sent(),[2,{data:a?d.body:(null===(t=d.headers.get("content-type"))||void 0===t?void 0:t.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.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,s,a,u=e.url,c=e.headers,l=void 0===c?{}:c,h=e.data,d=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)}("https:",u,"get"===n?h:{}),g=new XMLHttpRequest;g.open(n,y),d&&(g.responseType=d),Object.keys(l).forEach((function(e){g.setRequestHeader(e,l[e])})),v&&g.upload.addEventListener("progress",v),g.onreadystatechange=function(){var e={};if(4===g.readyState){var t=g.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=g.status;try{e.data="blob"===d?g.response:JSON.parse(g.responseText)}catch(t){e.data="blob"===d?g.response:g.responseText}clearTimeout(i),o(e)}},t&&r.timeout&&(i=setTimeout((function(){console.warn(r.timeoutMsg),g.abort()}),r.timeout)),a=h,s="[object FormData]"===Object.prototype.toString.call(a)?h:"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("&")}(h):p||(h?JSON.stringify(h):void 0),f&&(g.withCredentials=!0),g.send(s)}))}}(E.AbstractSDKRequest),function(e){e.WEB="web",e.WX_MP="wx_mp"}(P||(P={}));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])},e(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 s(e){try{u(n.next(e))}catch(e){i(e)}}function a(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))},q=function(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(s=0)),s;)try{if(r=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=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(!((o=(o=s.trys).length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}catch(e){a=[6,e],n=0}finally{r=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}},D=function(e){function t(t){var r=e.call(this)||this;return r.root=t,t.tcbCacheObject||(t.tcbCacheObject={}),r}return k(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}(E.AbstractStorage);!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":default:return t.localStorage?t.localStorage:(O("INVALID_PARAMS","localStorage is not supported on current platform"),new D(t.root));case"none":return 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:T,msg:"[".concat(S(),"][").concat(T,"]setStore failed"),info:e}))}}else O(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 q(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={IS_MP_BUILD:!0})||void 0===r?void 0:r.tcb_token))return{IS_MP_BUILD:!0}.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:""}O(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 q(this,(function(o){switch(o.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(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):O(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 q(this,(function(t){switch(t.label){case 0:return[4,this.storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))}}();var x=function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},e(t,r)};return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function n(){this.constructor=t}e(t,r),t.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}}(),j=function(e,t){this.data=t||null,this.name=e},M=function(e){function t(t,r){var n=e.call(this,"error",{error:t,data:r})||this;return n.error=t,n}return x(t,e),t}(j),B=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 M)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]?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))}([],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 B;var W=new B;function F(e){this.message=e}function V(e){this.message=e}function H(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 z(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?H(Object(r),!0).forEach((function(t){G(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):H(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function G(e,t,r){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);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,s){try{var a=e[i](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).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 s(e){K(i,n,o,s,a,"next",e)}function a(e){K(i,n,o,s,a,"throw",e)}s(void 0)}))}}"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox"),F.prototype=new Error,F.prototype.name="InvalidCharacterError","undefined"!=typeof window&&window.atob&&window.atob.bind(window),V.prototype=new Error,V.prototype.name="InvalidTokenError";var $="x-request-id",Q="x-device-id",J="device_id",Z=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),a=yield i.json();null!=a&&a.error?(n=a).error_uri=new URL(e).pathname:r=a}catch(t){n={error:s.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)}}(),X=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 ee(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class te{constructor(e){this.credentials=null,this.accessKeyCredentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new v({clientId:this.clientId}),this.credentials=e.credentials||null}getStorageCredentialsSync(){var e=null,t=this.storage.getItemSync(this.tokenSectionName);if(null!=t)try{var r;null!==(r=e=JSON.parse(t))&&void 0!==r&&r.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(t){this.storage.removeItem(this.tokenSectionName),e=null}return e}setCredentials(e){var t=this;return 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}))()}setAccessKeyCredentials(e){this.accessKeyCredentials=e}getCredentials(){var e=this;return Y((function*(){return e.singlePromise.run("getCredentials",Y((function*(){if(ee(e.credentials)){var{credentials:t,isAccessKeyCredentials:r}=yield e.getStorageCredentials();if(r)return t;e.credentials=t}return e.credentials})))}))()}getStorageCredentials(){var e=this;return Y((function*(){return e.singlePromise.run("_getStorageCredentials",Y((function*(){var t=null,r=!1,n=yield e.storage.getItem(e.tokenSectionName);if(n)try{var o;null!==(o=t=JSON.parse(n))&&void 0!==o&&o.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}else t=e.accessKeyCredentials||null,r=!0;return{credentials:t,isAccessKeyCredentials:r}})))}))()}}class re{constructor(e){this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.apiPath=e.apiPath||c,this.clientId=e.clientId,this.i18n=e.i18n,this.singlePromise=new v({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,re.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=Z,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||X,this.localCredentials=new te({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="",s=0,a=(e=String(e)).length%3;s<e.length;){if((r=e.charCodeAt(s++))>255||(n=e.charCodeAt(s++))>255||(o=e.charCodeAt(s++))>255)throw new TypeError("Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.");i+=y.charAt((t=r<<16|n<<8|o)>>18&63)+y.charAt(t>>12&63)+y.charAt(t>>6&63)+y.charAt(63&t)}return a?i.slice(0,a-3)+"===".substring(a):i}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{g()&&(this.useWxCloud=e.useWxCloud,void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud))}catch(e){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc,this.onCredentialsError=e.onCredentialsError,W.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)}setAccessKeyCredentials(e){return this.localCredentials.setAccessKeyCredentials(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:s.UNAUTHENTICATED};return Promise.reject(r)}))()}request(e,t){var r=this;return Y((function*(){var n,o,i,a;t||(t={});var u=r.formatRetry(t.retry,r.retry);if(t.headers=z(z({},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=z(z({},r.headers),t.headers)),t.headers[$]||(t.headers[$]=l()),!t.headers[Q]){var c=yield r.getDeviceId();t.headers[Q]=c}if(null!==(i=t)&&void 0!==i&&i.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(a=t)&&void 0!==a&&a.withCredentials){var h=yield r.getCredentials();h&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(h.access_token)):t.headers.Authorization="".concat(h.token_type," ").concat(h.access_token))}else r.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(r.clientId));e.startsWith("/")&&(e="".concat(r.apiOrigin).concat(r.apiPath).concat(e));for(var d=null,f=u+1,p=0;p<f;p++){try{d=t.useWxCloud||r.useWxCloud?yield r.wxCloudCallFunction(e,t):yield r.baseRequest(e,t);break}catch(e){if(t.withCredentials&&e&&e.error===s.UNAUTHENTICATED)return yield r.setCredentials(null),Promise.reject(e);if(p===u||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep(re.retryInterval)}return d}))()}wxCloudCallFunction(e,t){var r=this;return Y((function*(){var n=null,o=null;try{var i,a="";try{a=yield wx.getRendererUserAgent()}catch(e){}var{result:u}=yield r.wxCloud.callFunction({name:"httpOverCallFunction",data:{url:e,method:t.method,headers:z({origin:"https://servicewechat.com","User-Agent":a},t.headers),body:t.body}});null!=u&&null!==(i=u.body)&&void 0!==i&&i.error_code?(o=null==u?void 0:u.body).error_uri=(0,h.y)(e):n=null==u?void 0:u.body}catch(t){o={error:s.UNREACHABLE,error_description:t.message,error_uri:(0,h.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(ee(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,s="no refresh token found in credentials";return null===(i=e.onCredentialsError)||void 0===i||i.call(e,{msg:s}),e.unAuthenticatedError(s)}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===s.INVALID_GRANT){var a;yield t.localCredentials.setCredentials(null);var u=e.error_description;return null===(a=t.onCredentialsError)||void 0===a||a.call(t,{msg:u}),t.unAuthenticatedError(u)}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<re.minRetry||e>re.maxRetry)&&(t={error:s.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 t=this;return Y((function*(){return t.singlePromise.run("_anonymous",Y((function*(){if(!e||"anonymous"!==e.scope)return t.unAuthenticatedError("no anonymous in credentials");try{var r=yield t.request(n.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",withBasicAuth:!0,body:{}});return yield t.localCredentials.setCredentials(r),r}catch(e){return e.error===s.INVALID_GRANT?(yield t.localCredentials.setCredentials(null),t.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}defaultRefreshTokenFunc(e,t){var r=this;return Y((function*(){if(void 0===e||""===e){var i,s="refresh token not found";return null===(i=r.onCredentialsError)||void 0===i||i.call(r,{msg:s}),r.unAuthenticatedError(s)}var a=n.AUTH_TOKEN_URL;return"v2"===(null==t?void 0:t.version)&&(a=o.AUTH_TOKEN_URL),z(z({},yield r.request(a,{method:"POST",body:{client_id:r.clientId,client_secret:r.clientSecret,grant_type:"refresh_token",refresh_token:e}})),{},{version:(null==t?void 0:t.version)||"v1"})}))()}getDeviceId(){var e=this;return Y((function*(){if(e.deviceID)return e.deviceID;var t=yield e.storage.getItem(J);return"string"==typeof t&&t.length>=16&&t.length<=48||(t=l(),yield e.storage.setItem(J,t)),e.deviceID=t,t}))()}unAuthenticatedError(e){var t={error:s.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}}re.defaultRetry=2,re.minRetry=0,re.maxRetry=5,re.retryInterval=1e3;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,s){try{var a=e[i](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).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 s(e){oe(i,n,o,s,a,"next",e)}function a(e){oe(i,n,o,s,a,"throw",e)}s(void 0)}))}}class se{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=X),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))||g()}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===s.CAPTCHA_REQUIRED||n.error===s.CAPTCHA_INVALID?(e=yield r.appendCaptchaTokenToURL(e,o,n.error===s.CAPTCHA_INVALID),r.config.request(e,t)):Promise.reject(n)}return n}))()}getDefaultOpenURIWithCallback(){if(!this.isMatch()&&!b()&&(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:s.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 s=new ne(n.search),a=s.get("captcha_token");return a?e({captcha_token:a,expires_in:Number(s.get("expires_in"))}):t({error:s.get("error"),error_description:s.get("error_description")})}o.style.display="block"}catch(e){o.style.display="block"}}}))}))()}getCaptchaToken(e,t){var r=this;return ie((function*(){if(!e){var o=yield r.findCaptchaToken();if(o)return o}var i;if(r.isMatch()||b()){var s=yield r.config.request(n.CAPTCHA_DATA_URL,{method:"POST",body:{state:t,redirect_uri:""},withCredentials:!1});i={url:"".concat(s.data,"?state=").concat(encodeURIComponent(t),"&token=").concat(encodeURIComponent(s.token))}}else{var a="".concat(window.location.origin+window.location.pathname,"?__captcha=on");if((i=yield r.config.request(n.GET_CAPTCHA_URL,{method:"POST",body:{client_id:r.config.clientId,redirect_uri:a,state:t},withCredentials:!1})).captcha_token){var u={captcha_token:i.captcha_token,expires_in:i.expires_in};return r.saveCaptchaToken(u),i.captcha_token}}var c=yield r.config.openURIWithCallback(i.url);return r.saveCaptchaToken(c),c.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 ae=["provider_redirect_uri","other_params"];function ue(e,t,r,n,o,i,s){try{var a=e[i](s),u=a.value}catch(e){return void r(e)}a.done?t(u):Promise.resolve(u).then(n,o)}function ce(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function s(e){ue(i,n,o,s,a,"next",e)}function a(e){ue(i,n,o,s,a,"throw",e)}s(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 he(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){de(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 de(e,t,r){return(t=function(e){var t=function(e){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);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}catch(t){if(e)return(()=>{try{return r(171)}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 re(n)}if(!t){var o=r.request.bind(r),i=new se(he({clientId:e.clientId,request:o,storage:e.storage,adapter:e.adapter},e.captchaOptions));t=i.request.bind(i)}this.config={env:e.env,apiOrigin:e.apiOrigin,apiPath:e.apiPath,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||X,adapter:e.adapter}}getParamsByVersion(e,t){var r,i=(0,h.I)(e),s=(null===(r={v2:o}[null==i?void 0:i.version])||void 0===r?void 0:r[t])||n[t];return i&&delete i.version,{params:i,url:s}}signIn(e){var t=this;return ce((function*(){var r=e.version||"v1",n=t.getParamsByVersion(e,"AUTH_SIGN_IN_URL");n.params.query&&delete n.params.query;var o=yield t.getEncryptParams(n.params),i=yield t.config.request(n.url,{method:"POST",body:o});return yield t.config.credentialsClient.setCredentials(he(he({},i),{},{version:r})),Promise.resolve(i)}))()}signInAnonymously(){var e=arguments,t=this;return ce((function*(){var r=e.length>0&&void 0!==e[0]?e[0]:{},o=e.length>1&&void 0!==e[1]&&e[1],i=yield t.config.request(n.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:r,useWxCloud:o});return yield t.config.credentialsClient.setCredentials(i),Promise.resolve(i)}))()}signUp(e){var t=this;return ce((function*(){var r=yield t.config.request(n.AUTH_SIGN_UP_URL,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signOut(e){var t=this;return ce((function*(){var r={};if(e){try{r=yield t.config.request(n.AUTH_SIGNOUT_URL,{method:"POST",withCredentials:!0,body:e})}catch(e){e.error!==s.UNAUTHENTICATED&&console.log("sign_out_error",e)}return yield t.config.credentialsClient.setCredentials(),r}var o=yield t.config.credentialsClient.getAccessToken(),i=yield t.config.request(n.AUTH_REVOKE_URL,{method:"POST",body:{token:o}});return yield t.config.credentialsClient.setCredentials(),Promise.resolve(i)}))()}revokeAllDevices(){var e=this;return ce((function*(){yield e.config.request(n.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var t=this;return ce((function*(){yield t.config.request(n.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,t){var r=this;return ce((function*(){var o=!1;return("CUR_USER"===e.target||(yield r.hasLoginState()))&&(o=!0),r.config.request(n.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:(null==t?void 0:t.withCaptcha)||!1,withCredentials:o})}))()}verify(e){var t=this;return ce((function*(){var r=t.getParamsByVersion(e,"VERIFY_URL"),n=yield t.config.request(r.url,{method:"POST",body:r.params});return"v2"===(null==e?void 0:e.version)&&(yield t.config.credentialsClient.setCredentials(he(he({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var t=this;return ce((function*(){var{provider_redirect_uri:r,other_params:o={}}=e,i=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(t.includes(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.includes(r)||{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,ae);r&&!i.redirect_uri&&(i.redirect_uri=r);var s="".concat(n.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)&&(s+="&other_params[".concat(e,"]=").concat(encodeURIComponent(t)))})),t.config.request(s,{method:"GET"})}))()}grantProviderToken(e){var t=arguments,r=this;return ce((function*(){var o=t.length>1&&void 0!==t[1]&&t[1];return r.config.request(n.PROVIDER_TOKEN_URL,{method:"POST",body:e,useWxCloud:o})}))()}patchProviderToken(e){var t=this;return ce((function*(){return t.config.request(n.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return ce((function*(){var n=t.length>1&&void 0!==t[1]&&t[1],o=r.getParamsByVersion(e,"AUTH_SIGN_IN_WITH_PROVIDER_URL"),i=yield r.config.request(o.url,{method:"POST",body:o.params,useWxCloud:n});return yield r.config.credentialsClient.setCredentials(he(he({},i),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(i)}))()}signInCustom(e){var t=this;return ce((function*(){var r=yield t.config.request(n.AUTH_SIGN_IN_CUSTOM,{method:"POST",body:e});return yield t.config.credentialsClient.setCredentials(r),Promise.resolve(r)}))()}signInWithWechat(){var e=arguments,t=this;return ce((function*(){var r=e.length>0&&void 0!==e[0]?e[0]:{},o=yield t.config.request(n.AUTH_SIGN_IN_WITH_WECHAT_URL,{method:"POST",body:r});return yield t.config.credentialsClient.setCredentials(o),Promise.resolve(o)}))()}bindWithProvider(e){var t=this;return ce((function*(){return t.config.request(n.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return ce((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return ce((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 s=yield t.config.request(o.url,{method:"GET",withCredentials:!0});return s.sub&&(s.uid=s.sub),s}))()}getWedaUserInfo(){var e=this;return ce((function*(){return yield e.config.request(n.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return ce((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 ce((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return ce((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var t=this;return ce((function*(){return t.config.request(n.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return ce((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 ce((function*(){return e.config.request(n.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var t=this;return ce((function*(){return t.config.request("".concat(n.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var t=this;return ce((function*(){return t.config.request("".concat(n.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var t=this;return ce((function*(){return t.config.request("".concat(n.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var t=this;return ce((function*(){return t.config.request("".concat(n.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return ce((function*(){var r=yield t.sudo({password:e.old_password});return t.setPassword({sudo_token:r.sudo_token,new_password:e.new_password})}))()}sudo(e){var t=this;return ce((function*(){return t.config.request("".concat(n.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var t=this;return ce((function*(){return e.target="CUR_USER",t.config.request(n.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})}))()}changeBoundProvider(e){var t=this;return ce((function*(){return t.config.request("".concat(n.PROVIDER_LIST,"/").concat(e.provider_id,"/trans"),{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})}))()}setUserProfile(e){var t=this;return ce((function*(){return t.config.request(n.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var t=this;return ce((function*(){return t.config.request(n.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var t=this;return ce((function*(){var r=new ne(e);return t.config.request("".concat(n.USER_QUERY_URL,"?").concat(r.toString()),{method:"GET",withCredentials:!0})}))()}setCustomSignFunc(e){this.getCustomSignTicketFn=e}signInWithCustomTicket(){var e=this;return ce((function*(){var t=e.getCustomSignTicketFn;if(!t)return Promise.reject({error:"failed_precondition",error_description:"please use setCustomSignFunc to set custom sign function"});var r=yield t();return e.signInCustom({provider_id:"custom",ticket:r})}))()}resetPassword(e){var t=this;return ce((function*(){return t.config.request(n.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var t=this;return ce((function*(){return t.config.request(n.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var t=this;return ce((function*(){return t.config.request(n.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var t=this;return ce((function*(){return t.config.request(n.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var t=this;return ce((function*(){var r="".concat(n.AUTHORIZE_INFO_URL,"?").concat(pe.parseParamsToSearch(e)),o=!0,i=!1;return(yield t.hasLoginState())&&(i=!0,o=!1),t.config.request(r,{method:"GET",withBasicAuth:o,withCredentials:i})}))()}checkUsername(e){var t=this;return ce((function*(){return t.config.request(n.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var t=this;return ce((function*(){var r=new ne(e);return t.config.request("".concat(n.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var e=this;return ce((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return ce((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return ce((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(he(he({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return ce((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return ce((function*(){return e.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return ce((function*(){var{isEncrypt:r}=e;