UNPKG

@cloudbase/js-sdk

Version:
2 lines 212 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}},232:(e,t,r)=>{var n,o,i,s,a,u;function c(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(e=>{var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))}r.r(t),r.d(t,{Auth:()=>Wo,LoginState:()=>Bo,generateAuthInstance:()=>Fo,registerAuth:()=>Ho}),function(e){e.AUTH_SIGN_UP_URL="/auth/v1/signup",e.AUTH_TOKEN_URL="/auth/v1/token",e.AUTH_REVOKE_URL="/auth/v1/revoke",e.WEDA_USER_URL="/auth/v1/plugin/weda/userinfo",e.AUTH_RESET_PASSWORD="/auth/v1/reset",e.AUTH_GET_DEVICE_CODE="/auth/v1/device/code",e.CHECK_USERNAME="/auth/v1/checkUsername",e.CHECK_IF_USER_EXIST="/auth/v1/checkIfUserExist",e.GET_PROVIDER_TYPE="/auth/v1/mgr/provider/providerSubType",e.AUTH_SIGN_IN_URL="/auth/v1/signin",e.AUTH_SIGN_IN_ANONYMOUSLY_URL="/auth/v1/signin/anonymously",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v1/signin/with/provider",e.AUTH_SIGN_IN_WITH_WECHAT_URL="/auth/v1/signin/wechat/noauth",e.AUTH_SIGN_IN_CUSTOM="/auth/v1/signin/custom",e.PROVIDER_TOKEN_URL="/auth/v1/provider/token",e.PROVIDER_URI_URL="/auth/v1/provider/uri",e.USER_ME_URL="/auth/v1/user/me",e.AUTH_SIGNOUT_URL="/auth/v1/user/signout",e.USER_QUERY_URL="/auth/v1/user/query",e.USER_PRIFILE_URL="/auth/v1/user/profile",e.USER_BASIC_EDIT_URL="/auth/v1/user/basic/edit",e.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",e.PROVIDER_LIST="/auth/v1/user/provider",e.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",e.PROVIDER_UNBIND_URL="/auth/v1/user/provider",e.CHECK_PWD_URL="/auth/v1/user/sudo",e.SUDO_URL="/auth/v1/user/sudo",e.BIND_CONTACT_URL="/auth/v1/user/contact",e.AUTH_SET_PASSWORD="/auth/v1/user/password",e.AUTHORIZE_DEVICE_URL="/auth/v1/user/device/authorize",e.AUTHORIZE_URL="/auth/v1/user/authorize",e.AUTHORIZE_INFO_URL="/auth/v1/user/authorize/info",e.AUTHORIZED_DEVICES_DELETE_URL="/auth/v1/user/authorized/devices/",e.AUTH_REVOKE_ALL_URL="/auth/v1/user/revoke/all",e.GET_USER_BEHAVIOR_LOG="/auth/v1/user/security/history",e.VERIFICATION_URL="/auth/v1/verification",e.VERIFY_URL="/auth/v1/verification/verify",e.CAPTCHA_DATA_URL="/auth/v1/captcha/data",e.VERIFY_CAPTCHA_DATA_URL="/auth/v1/captcha/data/verify",e.GET_CAPTCHA_URL="/auth/v1/captcha/init",e.GET_MINIPROGRAM_QRCODE="/auth/v1/qrcode/generate",e.GET_MINIPROGRAM_QRCODE_STATUS="/auth/v1/qrcode/get/status"}(n||(n={})),function(e){e.AUTH_SIGN_IN_URL="/auth/v2/signin/username",e.AUTH_TOKEN_URL="/auth/v2/token",e.USER_ME_URL="/auth/v2/user/me",e.VERIFY_URL="/auth/v2/signin/verificationcode",e.AUTH_SIGN_IN_WITH_PROVIDER_URL="/auth/v2/signin/with/provider",e.AUTH_PUBLIC_KEY="/auth/v2/signin/publichkey",e.AUTH_RESET_PASSWORD="/auth/v2/signin/password/update"}(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 l=r(655);function h(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 d(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function s(e){h(i,n,o,s,a,"next",e)}function a(e){h(i,n,o,s,a,"throw",e)}s(void 0)}))}}class f{constructor(e){this.clientId=(null==e?void 0:e.clientId)||"",globalThis.jsSdkFnPromiseMap=globalThis.jsSdkFnPromiseMap||new Map}run(e,t){var r=this;return d((function*(){e="".concat(r.clientId,"_").concat(e);var n=globalThis.jsSdkFnPromiseMap.get(e);return n||(n=new Promise(((n,o)=>{d((function*(){try{yield r.runIdlePromise();var i=t();n(yield i)}catch(e){o(e)}finally{globalThis.jsSdkFnPromiseMap.delete(e)}}))()})),globalThis.jsSdkFnPromiseMap.set(e,n)),n}))()}runIdlePromise(){return Promise.resolve()}}var p="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function v(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 m(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?v(Object(r),!0).forEach((function(t){g(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):v(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 y(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 _(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function s(e){y(i,n,o,s,a,"next",e)}function a(e){y(i,n,o,s,a,"throw",e)}s(void 0)}))}}var b="x-request-id",w="x-device-id",S="device_id",T=function(){var e=_((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)}}(),I=new class{constructor(e){this._env=(null==e?void 0:e.env)||""}getItem(e){var t=this;return _((function*(){return window.localStorage.getItem("".concat(e).concat(t._env))}))()}removeItem(e){var t=this;return _((function*(){window.localStorage.removeItem("".concat(e).concat(t._env))}))()}setItem(e,t){var r=this;return _((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 E(e){var t=!0;return null!=e&&e.expires_at&&null!=e&&e.access_token&&(t=e.expires_at<new Date),t}class R{constructor(e){this.credentials=null,this.singlePromise=null,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage,this.clientId=e.clientId,this.singlePromise=new f({clientId:this.clientId})}getStorageCredentialsSync(){var e=null,t=this.storage.getItemSync(this.tokenSectionName);if(null!=t)try{var r;null!==(r=e=JSON.parse(t))&&void 0!==r&&r.expires_at&&(e.expires_at=new Date(e.expires_at))}catch(t){this.storage.removeItem(this.tokenSectionName),e=null}return e}setCredentials(e){var t=this;return _((function*(){if(null!=e&&e.expires_in){if(null!=e&&e.expires_at||(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30))),t.storage){var r=JSON.stringify(e);yield t.storage.setItem(t.tokenSectionName,r)}t.credentials=e}else t.storage&&(yield t.storage.removeItem(t.tokenSectionName)),t.credentials=null}))()}getCredentials(){var e=this;return _((function*(){return e.singlePromise.run("getCredentials",_((function*(){return E(e.credentials)&&(e.credentials=yield e.getStorageCredentials()),e.credentials})))}))()}getStorageCredentials(){var e=this;return _((function*(){return e.singlePromise.run("_getStorageCredentials",_((function*(){var t=null,r=yield e.storage.getItem(e.tokenSectionName);if(null!=r)try{var n;null!==(n=t=JSON.parse(r))&&void 0!==n&&n.expires_at&&(t.expires_at=new Date(t.expires_at))}catch(r){yield e.storage.removeItem(e.tokenSectionName),t=null}return t})))}))()}}class O{constructor(e){this.singlePromise=null,e.clientSecret||(e.clientSecret=""),!e.clientId&&e.env&&(e.clientId=e.env),this.apiOrigin=e.apiOrigin,this.clientId=e.clientId,this.singlePromise=new f({clientId:this.clientId}),this.retry=this.formatRetry(e.retry,O.defaultRetry),e.baseRequest?this.baseRequest=e.baseRequest:this.baseRequest=T,this.tokenInURL=e.tokenInURL,this.headers=e.headers,this.storage=e.storage||I,this.localCredentials=new R({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+=p.charAt((t=r<<16|n<<8|o)>>18&63)+p.charAt(t>>12&63)+p.charAt(t>>6&63)+p.charAt(63&t)}return a?i.slice(0,a-3)+"===".substring(a):i}("".concat(e.clientId,":").concat(this.clientSecret)))),this.wxCloud=e.wxCloud;try{(function(){if("undefined"==typeof wx)return!1;if("undefined"==typeof Page)return!1;if(!wx.getSystemInfoSync)return!1;if(!wx.getStorageSync)return!1;if(!wx.setStorageSync)return!1;if(!wx.connectSocket)return!1;if(!wx.request)return!1;try{if(!wx.getSystemInfoSync())return!1;if("qq"===wx.getSystemInfoSync().AppPlatform)return!1}catch(e){return!1}return!0})()&&void 0===this.wxCloud&&e.env&&(wx.cloud.init({env:e.env}),this.wxCloud=wx.cloud)}catch(e){}this.refreshTokenFunc=e.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=e.anonymousSignInFunc}setCredentials(e){return this.localCredentials.setCredentials(e)}getAccessToken(){var e=this;return _((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 _((function*(){var n,o;t||(t={});var i=r.formatRetry(t.retry,r.retry);if(t.headers=t.headers||{},r.headers&&(t.headers=m(m({},r.headers),t.headers)),t.headers[b]||(t.headers[b]=c()),!t.headers[w]){var a=yield r.getDeviceId();t.headers[w]=a}if(null!==(n=t)&&void 0!==n&&n.withBasicAuth&&r.basicAuth&&(t.headers.Authorization=r.basicAuth),null!==(o=t)&&void 0!==o&&o.withCredentials){var u=yield r.getCredentials();u&&(r.tokenInURL?(e.indexOf("?")<0&&(e+="?"),e+="access_token=".concat(u.access_token)):t.headers.Authorization="".concat(u.token_type," ").concat(u.access_token))}else r.clientId&&e.indexOf("client_id")<0&&(e+=e.indexOf("?")<0?"?":"&",e+="client_id=".concat(r.clientId));e.startsWith("/")&&(e=r.apiOrigin+e);for(var l=null,h=i+1,d=0;d<h;d++){try{l=t.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(d===i||!e||"unreachable"!==e.error)return Promise.reject(e)}yield r.sleep(O.retryInterval)}return l}))()}wxCloudCallFunction(e,t){var r=this;return _((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:m({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,l.y)(e):n=null==u?void 0:u.body}catch(t){o={error:s.UNREACHABLE,error_description:t.message,error_uri:(0,l.y)(e)}}if(o)throw o;return n}))()}getCredentials(){var e=this;return _((function*(){var t=yield e.localCredentials.getCredentials();return t?(E(t)&&(t=t&&"anonymous"===t.scope?e.anonymousSignInFunc?(yield e.anonymousSignInFunc(t))||(yield e.localCredentials.getCredentials()):yield e.anonymousSignIn(t):yield e.refreshToken(t)),t):e.unAuthenticatedError("credentials not found")}))()}getCredentialsSync(){return this.localCredentials.getStorageCredentialsSync()}getCredentialsAsync(){return this.getCredentials()}getScope(){var e=this;return _((function*(){var t=yield e.localCredentials.getCredentials();return t?t.scope:e.unAuthenticatedError("credentials not found")}))()}getGroups(){var e=this;return _((function*(){var t=yield e.localCredentials.getCredentials();return t?t.groups:e.unAuthenticatedError("credentials not found")}))()}refreshToken(e){var t=this;return _((function*(){return t.singlePromise.run("_refreshToken",_((function*(){if(!e||!e.refresh_token)return t.unAuthenticatedError("no refresh token found in credentials");try{var r=yield t.refreshTokenFunc(e.refresh_token,e);return yield t.localCredentials.setCredentials(r),r}catch(e){return e.error===s.INVALID_GRANT?(yield t.localCredentials.setCredentials(null),t.unAuthenticatedError(e.error_description)):Promise.reject(e)}})))}))()}checkRetry(e){var t=null;if(("number"!=typeof e||e<O.minRetry||e>O.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 _((function*(){return new Promise((t=>{setTimeout((()=>{t()}),e)}))}))()}anonymousSignIn(e){var t=this;return _((function*(){return t.singlePromise.run("_anonymous",_((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 _((function*(){if(void 0===e||""===e)return r.unAuthenticatedError("refresh token not found");var i=n.AUTH_TOKEN_URL;return"v2"===(null==t?void 0:t.version)&&(i=o.AUTH_TOKEN_URL),m(m({},yield r.request(i,{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 _((function*(){if(e.deviceID)return e.deviceID;var t=yield e.storage.getItem(S);return"string"==typeof t&&t.length>=16&&t.length<=48||(t=c(),yield e.storage.setItem(S,t)),e.deviceID=t,t}))()}unAuthenticatedError(e){var t={error:s.UNAUTHENTICATED,error_description:e};return Promise.reject(t)}}function P(){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}O.defaultRetry=2,O.minRetry=0,O.maxRetry=5,O.retryInterval=1e3;var C=!1;function A(){C=C||void 0!==typeof window&&"miniprogram"===window.__wxjs_environment}try{P()||(C=C||!!navigator.userAgent.match(/miniprogram/i)||"miniprogram"===window.__wxjs_environment,window&&window.WeixinJSBridge&&window.WeixinJSBridge.invoke?A():"undefined"!=typeof document&&document.addEventListener("WeixinJSBridgeReady",A,!1))}catch(ee){}function U(){return C}const L=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 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 N(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)}))}}class q{constructor(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=I),this.config=e,this.tokenSectionName="captcha_".concat(e.clientId)}request(e,t){var r=this;return N((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(!P()&&!U()&&(window.location.search.indexOf("__captcha")>0&&(document.body.style.display="none"),null===document.getElementById("captcha_panel_wrap"))){var e=document.createElement("div");e.style.cssText="background-color: rgba(0, 0, 0, 0.7);position: fixed;left: 0px;right: 0px;top: 0px;bottom: 0px;padding: 9vw 0 0 0;display: none;z-index:100;",e.setAttribute("id","captcha_panel_wrap"),setTimeout((()=>{document.body.appendChild(e)}),0)}return this.defaultOpenURIWithCallback}defaultOpenURIWithCallback(e,t){return N((function*(){var{width:r="355px",height:n="355px"}=t||{};if(e.match(/^(data:.*)$/))return Promise.reject({error: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 L(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 N((function*(){if(!e){var o=yield r.findCaptchaToken();if(o)return o}var i;if(P()||U()){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 N((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 N((function*(){e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10));var r=JSON.stringify(e);yield t.config.storage.setItem(t.tokenSectionName,r)}))()}findCaptchaToken(){var e=this;return N((function*(){var t=yield e.config.storage.getItem(e.tokenSectionName);if(null!=t)try{var r=JSON.parse(t);return null!=r&&r.expires_at&&(r.expires_at=new Date(r.expires_at)),r.expires_at<new Date?null:r.captcha_token}catch(t){return yield e.config.storage.removeItem(e.tokenSectionName),null}return null}))()}}var D=["provider_redirect_uri","other_params"];function x(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 j(e){return function(){var t=this,r=arguments;return new Promise((function(n,o){var i=e.apply(t,r);function s(e){x(i,n,o,s,a,"next",e)}function a(e){x(i,n,o,s,a,"throw",e)}s(void 0)}))}}function M(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function B(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?M(Object(r),!0).forEach((function(t){W(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):M(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function W(e,t,r){return(t=function(e){var t=function(e){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 F(e){if(!globalThis.IS_MP_BUILD&&e)return r(171)}class V{static parseParamsToSearch(e){return Object.keys(e).forEach((t=>{e[t]||delete e[t]})),new L(e).toString()}constructor(e){var{request:t}=e,r=e.credentialsClient;if(!r){var n={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage,env:e.env,baseRequest:e.baseRequest,anonymousSignInFunc:e.anonymousSignInFunc,wxCloud:e.wxCloud};r=new O(n)}if(!t){var o=r.request.bind(r),i=new q(B({clientId:e.clientId,request:o,storage:e.storage},e.captchaOptions));t=i.request.bind(i)}this.config={env:e.env,apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||I}}getParamsByVersion(e,t){var r,i=(0,l.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 j((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(B(B({},i),{},{version:r})),Promise.resolve(i)}))()}signInAnonymously(){var e=arguments,t=this;return j((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 j((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 j((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 j((function*(){yield e.config.request(n.AUTH_REVOKE_ALL_URL,{method:"DELETE",withCredentials:!0})}))()}revokeDevice(e){var t=this;return j((function*(){yield t.config.request(n.AUTHORIZED_DEVICES_DELETE_URL+e.device_id,{method:"DELETE",withCredentials:!0})}))()}getVerification(e,t){var r=this;return j((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 j((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(B(B({},n),{},{version:"v2"}))),n}))()}genProviderRedirectUri(e){var t=this;return j((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,D);r&&!i.redirect_uri&&(i.redirect_uri=r);var s="".concat(n.PROVIDER_URI_URL,"?").concat(V.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 j((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 j((function*(){return t.config.request(n.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})}))()}signInWithProvider(e){var t=arguments,r=this;return j((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(B(B({},i),{},{version:(null==e?void 0:e.version)||"v1"})),Promise.resolve(i)}))()}signInCustom(e){var t=this;return j((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 j((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 j((function*(){return t.config.request(n.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})}))()}getUserProfile(e){var t=this;return j((function*(){return t.getUserInfo(e)}))()}getUserInfo(){var e=arguments,t=this;return j((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 L(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 j((function*(){return yield e.config.request(n.WEDA_USER_URL,{method:"GET",withCredentials:!0})}))()}deleteMe(e){var t=this;return j((function*(){var r=t.getParamsByVersion(e,"USER_ME_URL"),n="".concat(r.url,"?").concat(V.parseParamsToSearch(r.params));return t.config.request(n,{method:"DELETE",withCredentials:!0})}))()}hasLoginState(){var e=this;return j((function*(){try{return yield e.config.credentialsClient.getAccessToken(),!0}catch(e){return!1}}))()}hasLoginStateSync(){return this.config.credentialsClient.getCredentialsSync()}getLoginState(){var e=this;return j((function*(){return e.config.credentialsClient.getCredentialsAsync()}))()}transByProvider(e){var t=this;return j((function*(){return t.config.request(n.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}grantToken(e){var t=this;return j((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 j((function*(){return e.config.request(n.PROVIDER_LIST,{method:"GET",withCredentials:!0})}))()}unbindProvider(e){var t=this;return j((function*(){return t.config.request("".concat(n.PROVIDER_UNBIND_URL,"/").concat(e.provider_id),{method:"DELETE",withCredentials:!0})}))()}checkPassword(e){var t=this;return j((function*(){return t.config.request("".concat(n.CHECK_PWD_URL),{method:"POST",withCredentials:!0,body:e})}))()}editContact(e){var t=this;return j((function*(){return t.config.request("".concat(n.BIND_CONTACT_URL),{method:"PATCH",withCredentials:!0,body:e})}))()}setPassword(e){var t=this;return j((function*(){return t.config.request("".concat(n.AUTH_SET_PASSWORD),{method:"PATCH",withCredentials:!0,body:e})}))()}updatePasswordByOld(e){var t=this;return j((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 j((function*(){return t.config.request("".concat(n.SUDO_URL),{method:"POST",withCredentials:!0,body:e})}))()}sendVerificationCodeToCurrentUser(e){var t=this;return j((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 j((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 j((function*(){return t.config.request(n.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})}))()}updateUserBasicInfo(e){var t=this;return j((function*(){return t.config.request(n.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:e})}))()}queryUserProfile(e){var t=this;return j((function*(){var r=new L(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 j((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 j((function*(){return t.config.request(n.AUTH_RESET_PASSWORD,{method:"POST",body:e})}))()}authorize(e){var t=this;return j((function*(){return t.config.request(n.AUTHORIZE_URL,{method:"POST",withCredentials:!0,body:e})}))()}authorizeDevice(e){var t=this;return j((function*(){return t.config.request(n.AUTHORIZE_DEVICE_URL,{method:"POST",withCredentials:!0,body:e})}))()}deviceAuthorize(e){var t=this;return j((function*(){return t.config.request(n.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})}))()}authorizeInfo(e){var t=this;return j((function*(){var r="".concat(n.AUTHORIZE_INFO_URL,"?").concat(V.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 j((function*(){return t.config.request(n.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})}))()}checkIfUserExist(e){var t=this;return j((function*(){var r=new L(e);return t.config.request("".concat(n.CHECK_IF_USER_EXIST,"?").concat(r.toString()),{method:"GET"})}))()}loginScope(){var e=this;return j((function*(){return e.config.credentialsClient.getScope()}))()}loginGroups(){var e=this;return j((function*(){return e.config.credentialsClient.getGroups()}))()}refreshTokenForce(e){var t=this;return j((function*(){var r=yield t.config.credentialsClient.getCredentials();return yield t.config.credentialsClient.refreshToken(B(B({},r),{},{version:(null==e?void 0:e.version)||"v1"}))}))()}getCredentials(){var e=this;return j((function*(){return e.config.credentialsClient.getCredentials()}))()}getPublicKey(){var e=this;return j((function*(){return e.config.request(o.AUTH_PUBLIC_KEY,{method:"POST",body:{}})}))()}getEncryptParams(e){var t=this;return j((function*(){var{isEncrypt:r}=e;delete e.isEncrypt;var n=(0,l.I)(e),o=F(r);if(!o)return e;var i="",s="";try{var a=yield t.getPublicKey();if(i=a.public_key,s=a.public_key_thumbprint,!i||!s)throw a}catch(e){throw e}return{params:o.getEncryptInfo({publicKey:i,payload:n}),public_key_thumbprint:s}}))()}getProviderSubType(){var e=this;return j((function*(){return e.config.request(n.GET_PROVIDER_TYPE,{method:"POST",body:{provider_id:"weda"}})}))()}verifyCaptchaData(e){var t=this;return j((function*(){var{token:r,key:o}=e;return t.config.request(n.VERIFY_CAPTCHA_DATA_URL,{method:"POST",body:{token:r,key:o},withCredentials:!1})}))()}createCaptchaData(e){var t=this;return j((function*(){var{state:r,redirect_uri:o}=e;return t.config.request(n.CAPTCHA_DATA_URL,{method:"POST",body:{state:r,redirect_uri:o},withCredentials:!1})}))()}getMiniProgramCode(e){var t=this;return j((function*(){return t.config.request(n.GET_MINIPROGRAM_QRCODE,{method:"POST",body:e})}))()}getMiniProgramQrCodeStatus(e){var t=this;return j((function*(){return t.config.request(n.GET_MINIPROGRAM_QRCODE_STATUS,{method:"POST",body:e})}))()}getUserBehaviorLog(e){var t=this;return j((function*(){var r="".concat(n.GET_USER_BEHAVIOR_LOG,"?").concat({LOGIN:"query[action]=USER_LOGIN",MODIFY:"ne_query[action]=USER_LOGIN"}[e.type],"&limit=").concat(e.limit).concat(e.page_token?"&page_token=".concat(e.page_token):"");return t.config.request(r,{method:"GET",withCredentials:!0})}))()}modifyPassword(e){var t=this;return j((function*(){var r="",o="",i=F(!0);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield t.getPublicKey();if(r=s.public_key,o=s.public_key_thumbprint,!r||!o)throw s}catch(e){throw e}var a=e.password?i.getEncryptInfo({publicKey:r,payload:e.password}):"",u=i.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(n.USER_BASIC_EDIT_URL,{method:"POST",withCredentials:!0,body:{user_id:e.user_id,encrypt_password:a,encrypt_new_password:u,public_key_thumbprint:o}})}))()}modifyPasswordWithoutLogin(e){var t=this;return j((function*(){var r="",n="",i=F(!0);if(!i)throw new Error("do not support encrypt, a encrypt util required.");try{var s=yield t.getPublicKey();if(r=s.public_key,n=s.public_key_thumbprint,!r||!n)throw s}catch(e){throw e}var a=e.password?i.getEncryptInfo({publicKey:r,payload:e.password}):"",u=i.getEncryptInfo({publicKey:r,payload:e.new_password});return t.config.request(o.AUTH_RESET_PASSWORD,{method:"POST",body:{username:e.username,password:a,new_password:u,public_key_thumbprint:n}})}))()}}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}class Y{constructor(e){var{apiOrigin:t,clientId:r,env:n,storage:o,request:i,baseRequest:s,anonymousSignInFunc:a,wxCloud:u}=e;this.oauth2client=new O({apiOrigin:t,clientId:r,env:n,storage:o,baseRequest:s||i,anonymousSignInFunc:a,wxCloud:u}),this.authApi=new V(z(z({credentialsClient:this.oauth2client},e),{},{request:i?this.oauth2client.request.bind(this.oauth2client):void 0}))}}var $=r(616),K=r(794),Q=r(141),Z=r(689),J=r(197),X=r(325);function ee(){}function te(e){return"object"==typeof e&&null!==e||"function"==typeof e}const re=ee;function ne(e,t){try{Object.defineProperty(e,"name",{value:t,configurable:!0})}catch(e){}}const oe=Promise,ie=Promise.resolve.bind(oe),se=Promise.prototype.then,ae=Promise.reject.bind(oe),ue=ie;function ce(e){return new oe(e)}function le(e){return ce((t=>t(e)))}function he(e){return ae(e)}function de(e,t,r){return se.call(e,t,r)}function fe(e,t,r){de(de(e,t,r),void 0,re)}function pe(e,t){fe(e,t)}function ve(e,t){fe(e,void 0,t)}function me(e,t,r){return de(e,t,r)}function ge(e){de(e,void 0,re)}let ye=e=>{if("function"==typeof queueMicrotask)ye=queueMicrotask;else{const e=le(void 0);ye=t=>de(e,t)}return ye(e)};function _e(e,t,r){if("function"!=typeof e)throw new TypeError("Argument is not a function");return Function.prototype.apply.call(e,t,r)}function be(e,t,r){try{return le(_e(e,t,r))}catch(e){return he(e)}}class we{constructor(){this._cursor=0,this._size=0,this._front={_elements:[],_next:void 0},this._back=this._front,this._cursor=0,this._size=0}get length(){return this._size}push(e){const t=this._back;let r=t;16383===t._elements.length&&(r={_elements:[],_next:void 0}),t._elements.push(e),r!==t&&(this._back=r,t._next=r),++this._size}shift(){const e=this._front;let t=e;const r=this._cursor;let n=r+1;const o=e._elements,i=o[r];return 16384===n&&(t=e._next,n=0),--this._size,this._cursor=n,e!==t&&(this._front=t),o[r]=void 0,i}forEach(e){let t=this._cursor,r=this._front,n=r._elements;for(;!(t===n.length&&void 0===r._next||t===n.length&&(r=r._next,n=r._elements,t=0,0===n.length));)e(n[t]),++t}peek(){const e=this._front,t=this._cursor;return e._elements[t]}}const Se=Symbol("[[AbortSteps]]"),Te=Symbol("[[ErrorSteps]]"),Ie=Symbol("[[CancelSteps]]"),Ee=Symbol("[[PullSteps]]"),Re=Symbol("[[ReleaseSteps]]");function Oe(e,t){e._ownerReadableStream=t,t._reader=e,"readable"===t._state?Ue(e):"closed"===t._state?function(e){Ue(e),Ne(e)}(e):Le(e,t._storedError)}function Pe(e,t){return xn(e._ownerReadableStream,t)}function Ce(e){const t=e._ownerReadableStream;"readable"===t._state?ke(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness")):function(e){Le(e,new TypeError("Reader was released and can no longer be used to monitor the stream's closedness"))}(e),t._readableStreamController[Re](),t._reader=void 0,e._ownerReadableStream=void 0}function Ae(e){return new TypeError("Cannot "+e+" a stream using a released reader")}function Ue(e){e._closedPromise=ce(((t,r)=>{e._closedPromise_resolve=t,e._closedPromise_reject=r}))}function Le(e,t){Ue(e),ke(e,t)}function ke(e,t){void 0!==e._closedPromise_reject&&(ge(e._closedPromise),e._closedPromise_reject(t),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}function Ne(e){void 0!==e._closedPromise_resolve&&(e._closedPromise_resolve(void 0),e._closedPromise_resolve=void 0,e._closedPromise_reject=void 0)}const qe=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},De=Math.trunc||function(e){return e<0?Math.ceil(e):Math.floor(e)};function xe(e,t){if(void 0!==e&&"object"!=typeof(r=e)&&"function"!=typeof r)throw new TypeError(`${t} is not an object.`);var r}function je(e,t){if("function"!=typeof e)throw new TypeError(`${t} is not a function.`)}function Me(e,t){if(!function(e){return"object"==typeof e&&null!==e||"function"==typeof e}(e))throw new TypeError(`${t} is not an object.`)}function Be(e,t,r){if(void 0===e)throw new TypeError(`Parameter ${t} is required in '${r}'.`)}function We(e,t,r){if(void 0===e)throw new TypeError(`${t} is required in '${r}'.`)}function Fe(e){return Number(e)}function Ve(e){return 0===e?0:e}function He(e,t){const r=Number.MAX_SAFE_INTEGER;let n=Number(e);if(n=Ve(n),!qe(n))throw new TypeError(`${t} is not a finite number`);if(n=function(e){return Ve(De(e))}(n),n<0||n>r)throw new TypeError(`${t} is outside the accepted range of 0 to ${r}, inclusive`);return qe(n)&&0!==n?n:0}function ze(e,t){if(!qn(e))throw new TypeError(`${t} is not a ReadableStream.`)}function Ge(e){return new Ze(e)}function Ye(e,t){e._reader._readRequests.push(t)}function $e(e,t,r){const n=e._reader._readRequests.shift();r?n._closeSteps():n._chunkSteps(t)}function Ke(e){return e._reader._readRequests.length}function Qe(e){const t=e._reader;return void 0!==t&&!!Je(t)}class Ze{constructor(e){if(Be(e,1,"ReadableStreamDefaultReader"),ze(e,"First parameter"),Dn(e))throw new TypeError("This stream has already been locked for exclusive reading by another reader");Oe(this,e),this._readRequests=new we}get closed(){return Je(this)?this._closedPromise:he(tt("closed"))}cancel(e=void 0){return Je(this)?void 0===this._ownerReadableStream?he(Ae("cancel")):Pe(this,e):he(tt("cancel"))}read(){if(!Je(this))return he(tt("read"));if(void 0===this._ownerReadableStream)return he(Ae("read from"));let e,t;const r=ce(((r,n)=>{e=r,t=n}));return Xe(this,{_chunkSteps:t=>e({value:t,done:!1}),_closeSteps:()=>e({value:void 0,done:!0}),_errorSteps:e=>t(e)}),r}releaseLock(){if(!Je(this))throw tt("releaseLock");void 0!==this._ownerReadableStream&&function(e){Ce(e),et(e,new TypeError("Reader was released"))}(this)}}function Je(e){return!!te(e)&&!!Object.prototype.hasOwnProperty.call(e,"_readRequests")&&e instanceof Ze}function Xe(e,t){const r=e._ownerReadableStream;r._disturbed=!0,"closed"===r._state?t._closeSteps():"errored"===r._state?t._errorSteps(r._storedError):r._readableStreamController[Ee](t)}function et(e,t){const r=e._readRequests;e._readRequests=new we,r.forEach((e=>{e._errorSteps(t)}))}function tt(e){return new TypeError(`ReadableStreamDefaultReader.prototype.${e} can only be used on a ReadableStreamDefaultReader`)}var rt,nt,ot;function it(e){return e.slice()}function st(e,t,r,n,o){new Uint8Array(e).set(new Uint8Array(r,n,o),t)}Object.defineProperties(Ze.prototype,{cancel:{enumerable:!0},read:{enumerable:!0},releaseLock:{enumerable:!0},closed:{enumerable:!0}}),ne(Ze.prototype.cancel,"cancel"),ne(Ze.prototype.read,"read"),ne(Ze.prototype.releaseLock,"releaseLock"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Ze.prototype,Symbol.toStringTag,{value:"ReadableStreamDefaultReader",configurable:!0});let at=e=>(at="function"==typeof e.transfer?e=>e.transfer():"function"==typeof structuredClone?e=>structuredClone(e,{transfer:[e]}):e=>e,at(e)),ut=e=>(ut="boolean"==typeof e.detached?e=>e.detached:e=>0===e.byteLength,ut(e));function ct(e,t,r){if(e.slice)return e.slice(t,r);const n=r-t,o=new ArrayBuffer(n);return st(o,0,e,t,n),o}function lt(e,t){const r=e[t];if(null!=r){if("function"!=typeof r)throw new TypeError(`${String(t)} is not a function`);return r}}function ht(e){try{const t=e.done,r=e.value;return de(ue(r),(e=>({done:t,value:e})))}catch(e){return he(e)}}const dt=null!==(ot=null!==(rt=Symbol.asyncIterator)&&void 0!==rt?rt:null===(nt=Symbol.for)||void 0===nt?void 0:nt.call(Symbol,"Symbol.asyncIterator"))&&void 0!==ot?ot:"@@asyncIterator";function ft(e,t="sync",r){if(void 0===r)if("async"===t){if(void 0===(r=lt(e,dt)))return function(e){const t={next(){let t;try{t=pt(e)}catch(e){return he(e)}return ht(t)},return(t){let r;try{const n=lt(e.iterator,"return");if(void 0===n)return le({done:!0,value:t});r=_e(n,e.iterator,[t])}catch(e){return he(e)}return te(r)?ht(r):he(new TypeError("The iterator.return() method must return an object"))}};return{iterator:t,nextMethod:t.next,done:!1}}(ft(e,"sync",lt(e,Symbol.iterator)))}else r=lt(e,Symbol.iterator);if(void 0===r)throw new TypeError("The object is not iterable");const n=_e(r,e,[]);if(!te(n))throw new TypeError("The iterator method must return an object");return{iterator:n,nextMethod:n.next,done:!1}}function pt(e){const t=_e(e.nextMethod,e.iterator,[]);if(!te(t))throw new TypeError("The iterator.next() method must return an object");return t}class vt{constructor(e,t){this._ongoingPromise=void 0,this._isFinished=!1,this._reader=e,this._preventCancel=t}next(){const e=()=>this._nextSteps();return this._ongoingPromise=this._ongoingPromise?me(this._ongoingPromise,e,e):e(),this._ongoingPromise}return(e){const t=()=>this._returnSteps(e);return this._ongoingPromise?me(this._ongoingPromise,t,t):t()}_nextSteps(){if(this._isFinished)return Promise.resolve({value:void 0,done:!0});const e=this._reader;let t,r;const n=ce(((e,n)=>{t=e,r=n}));return Xe(e,{_chunkSteps:e=>{this._ongoingPromise=void 0,ye((()=>t({value:e,done:!1})))},_closeSteps:()=>{this._ongoingPromise=void 0,this._isFinished=!0,Ce(e),t({value:void 0,done:!0})},_errorSteps:t=>{this._ongoingPromise=void 0,this._isFinished=!0,Ce(e),r(t)}}),n}_returnSteps(e){if(this._isFinished)return Promise.resolve({value:e,done:!0});this._isFinished=!0;const t=this._reader;if(!this._preventCancel){const r=Pe(t,e);return Ce(t),me(r,(()=>({value:e,done:!0})))}return Ce(t),le({value:e,done:!0})}}const mt={next(){return gt(this)?this._asyncIteratorImpl.next():he(yt("next"))},return(e){return gt(this)?this._asyncIteratorImpl.return(e):he(yt("return"))},[dt](){return this}};function gt(e){if(!te(e))return!1;if(!Object.prototype.hasOwnProperty.call(e,"_asyncIteratorImpl"))return!1;try{return e._asyncIteratorImpl instanceof vt}catch(e){return!1}}function yt(e){return new TypeError(`ReadableStreamAsyncIterator.${e} can only be used on a ReadableSteamAsyncIterator`)}Object.defineProperty(mt,dt,{enumerable:!1});const _t=Number.isNaN||function(e){return e!=e};function bt(e){const t=ct(e.buffer,e.byteOffset,e.byteOffset+e.byteLength);return new Uint8Array(t)}function wt(e){const t=e._queue.shift();return e._queueTotalSize-=t.size,e._queueTotalSize<0&&(e._queueTotalSize=0),t.value}function St(e,t,r){if("number"!=typeof(n=r)||_t(n)||n<0||r===1/0)throw new RangeError("Size must be a finite, non-NaN, non-negative number.");var n;e._queue.push({value:t,size:r}),e._queueTotalSize+=r}function Tt(e){e._queue=new we,e._queueTotalSize=0}function It(e){return e===DataView}class Et{constructor(){throw new TypeError("Illegal constructor")}get view(){if(!Pt(this))throw Xt("view");return this._view}respond(e){if(!Pt(this))throw Xt("respond");if(Be(e,1,"respond"),e=He(e,"First parameter"),void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(ut(this._view.buffer))throw new TypeError("The BYOB request's buffer has been detached and so cannot be used as a response");Qt(this._associatedReadableByteStreamController,e)}respondWithNewView(e){if(!Pt(this))throw Xt("respondWithNewView");if(Be(e,1,"respondWithNewView"),!ArrayBuffer.isView(e))throw new TypeError("You can only respond with array buffer views");if(void 0===this._associatedReadableByteStreamController)throw new TypeError("This BYOB request has been invalidated");if(ut(e.buffer))throw new TypeError("The given view's buffer has been detached and so cannot be used as a response");Zt(this._associatedReadableByteStreamController,e)}}Object.defineProperties(Et.prototype,{respond:{enumerable:!0},respondWithNewView:{enumerable:!0},view:{enumerable:!0}}),ne(Et.prototype.respond,"respond"),ne(Et.prototype.respondWithNewView,"respondWithNewView"),"symbol"==typeof Symbol.toStringTag&&Object.defineProperty(Et.prototype,Symbol.toStringTag,{value:"ReadableStreamBYOBRequest",configurable:!0});class Rt{constructor(){thro