@cloudbase/js-sdk 2.2.0 → 2.4.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],t):"object"==typeof exports?exports.cloudbase_oauth=t():e.cloudbase_oauth=t()}("undefined"!=typeof window?window:this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=3)}([function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},i=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function u(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.OAuth2Client=t.LocalCredentials=t.defaultStorage=t.generateRequestId=t.toResponseError=t.defaultRequest=void 0;var s=r(1),u=r(5),a=r(6);function c(){return u.uuidv4()}t.defaultRequest=function(e,t){return i(void 0,void 0,void 0,(function(){var r,n,i,u,a;return o(this,(function(o){switch(o.label){case 0:r=null,n=null,o.label=1;case 1:return o.trys.push([1,4,,5]),(i=Object.assign({},t)).method||(i.method="GET"),i.body&&"string"!=typeof i.body&&(i.body=JSON.stringify(i.body)),[4,fetch(e,i)];case 2:return[4,o.sent().json()];case 3:return(null==(u=o.sent())?void 0:u.error)?(n=u).error_uri=new URL(e).pathname:r=u,[3,5];case 4:return a=o.sent(),n={error:s.ErrorType.UNREACHABLE,error_description:a.message,error_uri:new URL(e).pathname},[3,5];case 5:if(n)throw n;return[2,r]}}))}))},t.toResponseError=function(e,t){var r,n=t||{};if(e instanceof Error)r={error:n.error||s.ErrorType.LOCAL,error_description:n.error_description||e.message,error_uri:n.error_uri,details:n.details||e.stack};else{var i=e||{};r={error:n.error||i.error||s.ErrorType.LOCAL,error_description:n.error_description||i.error_description,error_uri:n.error_uri||i.error_uri,details:n.details||i.details}}return r},t.generateRequestId=c;var l=function(){function e(){}return e.prototype.getItem=function(e){return i(this,void 0,void 0,(function(){return o(this,(function(t){return[2,window.localStorage.getItem(e)]}))}))},e.prototype.removeItem=function(e){return i(this,void 0,void 0,(function(){return o(this,(function(t){return window.localStorage.removeItem(e),[2]}))}))},e.prototype.setItem=function(e,t){return i(this,void 0,void 0,(function(){return o(this,(function(r){return window.localStorage.setItem(e,t),[2]}))}))},e.prototype.getItemSync=function(e){return window.localStorage.getItem(e)},e.prototype.removeItemSync=function(e){window.localStorage.removeItem(e)},e.prototype.setItemSync=function(e,t){window.localStorage.setItem(e,t)},e}();function d(e){var t=!0;return(null==e?void 0:e.expires_at)&&(null==e?void 0:e.access_token)&&(t=e.expires_at<new Date),t}t.defaultStorage=new l;var h=function(){function e(e){this._credentials=null,this._singlePromise=new a.SinglePromise,this._tokenSectionName=e.tokenSectionName,this._storage=e.storage}return e.prototype.setCredentials=function(e){return i(this,void 0,void 0,(function(){var t;return o(this,(function(r){switch(r.label){case 0:return(null==e?void 0:e.expires_in)?(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30)),this._storage?(t=JSON.stringify(e),[4,this._storage.setItem(this._tokenSectionName,t)]):[3,2]):[3,3];case 1:r.sent(),r.label=2;case 2:return this._credentials=e,[3,6];case 3:return this._storage?[4,this._storage.removeItem(this._tokenSectionName)]:[3,5];case 4:r.sent(),r.label=5;case 5:this._credentials=null,r.label=6;case 6:return[2]}}))}))},e.prototype.getCredentials=function(){return i(this,void 0,void 0,(function(){var e=this;return o(this,(function(t){return[2,this._singlePromise.run("getCredentials",(function(){return i(e,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return d(this._credentials)?(e=this,[4,this._getStorageCredentials()]):[3,2];case 1:e._credentials=t.sent(),t.label=2;case 2:return[2,this._credentials]}}))}))}))]}))}))},e.prototype._getStorageCredentials=function(){return i(this,void 0,void 0,(function(){var e=this;return o(this,(function(t){return[2,this._singlePromise.run("_getStorageCredentials",(function(){return i(e,void 0,void 0,(function(){var e,t;return o(this,(function(r){switch(r.label){case 0:return e=null,[4,this._storage.getItem(this._tokenSectionName)];case 1:if(null==(t=r.sent()))return[3,5];r.label=2;case 2:return r.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),[3,5];case 3:return r.sent(),[4,this._storage.removeItem(this._tokenSectionName)];case 4:return r.sent(),e=null,[3,5];case 5:return[2,e]}}))}))}))]}))}))},e.prototype._getStorageCredentialsSync=function(){var e=null,t=this._storage.getItemSync(this._tokenSectionName);if(null!=t)try{(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at))}catch(t){this._storage.removeItem(this._tokenSectionName),e=null}return e},e}();t.LocalCredentials=h;var _=function(){function e(r){this._singlePromise=new a.SinglePromise,this._apiOrigin=r.apiOrigin,this._clientId=r.clientId,this._retry=this._formatRetry(r.retry,e._defaultRetry),null!=r.baseRequest?this._baseRequest=r.baseRequest:this._baseRequest=t.defaultRequest,this._tokenInURL=r.tokenInURL,this._headers=r.headers,this._storage=r.storage||t.defaultStorage,this._localCredentials=new h({tokenSectionName:"credentials_"+r.clientId,storage:this._storage}),this._clientSecret=r.clientSecret,this._refreshTokenFunc=r.refreshTokenFunc||this._defaultRefreshTokenFunc}return e.prototype.setCredentials=function(e){return this._localCredentials.setCredentials(e)},e.prototype.getAccessToken=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return[4,this._getCredentials()];case 1:return(null==(e=t.sent())?void 0:e.access_token)?[2,Promise.resolve(e.access_token)]:[2,Promise.reject({error:s.ErrorType.UNAUTHENTICATED})]}}))}))},e.prototype.request=function(t,r){return i(this,void 0,void 0,(function(){var i,u,a,l,d,h,_;return o(this,(function(o){switch(o.label){case 0:return r||(r={}),i=this._formatRetry(r.retry,this._retry),r.headers=r.headers||{},this._headers&&(r.headers=n(n({},this._headers),r.headers)),r.headers["x-request-id"]||(r.headers["x-request-id"]=c()),r.headers["x-device-id"]?[3,2]:[4,this._getDeviceId()];case 1:u=o.sent(),r.headers["x-device-id"]=u,o.label=2;case 2:return(null==r?void 0:r.withCredentials)?[4,this._getCredentials()]:[3,4];case 3:return(a=o.sent())&&(this._tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token="+a.access_token):r.headers.Authorization=a.token_type+" "+a.access_token),[3,5];case 4:this._clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id="+this._clientId),o.label=5;case 5:t.startsWith("/")&&(t=this._apiOrigin+t),l=null,d=i+1,h=0,o.label=6;case 6:if(!(h<d))return[3,15];o.label=7;case 7:return o.trys.push([7,9,,12]),[4,this._baseRequest(t,r)];case 8:return l=o.sent(),[3,15];case 9:return _=o.sent(),r.withCredentials&&_&&_.error===s.ErrorType.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,11];case 10:return o.sent(),[2,Promise.reject(_)];case 11:return h!==i&&_&&"unreachable"===_.error?[3,12]:[2,Promise.reject(_)];case 12:return[4,this._sleep(e._retryInterval)];case 13:o.sent(),o.label=14;case 14:return h++,[3,6];case 15:return[2,l]}}))}))},e.prototype._checkRetry=function(t){var r=null;if(("number"!=typeof t||t<e._minRetry||t>e._maxRetry)&&(r={error:s.ErrorType.UNREACHABLE,error_description:"wrong options param: retry"}),r)throw r;return t},e.prototype._formatRetry=function(e,t){return void 0===e?t:this._checkRetry(e)},e.prototype._sleep=function(e){return i(this,void 0,void 0,(function(){return o(this,(function(t){return[2,new Promise((function(t){setTimeout((function(){t()}),e)}))]}))}))},e.prototype._refreshToken=function(e){return i(this,void 0,void 0,(function(){var t=this;return o(this,(function(r){return[2,this._singlePromise.run("_refreshToken",(function(){return i(t,void 0,void 0,(function(){var t,r;return o(this,(function(n){switch(n.label){case 0:if(!e||!e.refresh_token)return[2,this._unAuthenticatedError("no refresh token found in credentials")];n.label=1;case 1:return n.trys.push([1,4,,7]),[4,this._refreshTokenFunc(e.refresh_token)];case 2:return t=n.sent(),[4,this._localCredentials.setCredentials(t)];case 3:return n.sent(),[2,t];case 4:return(r=n.sent()).error!==s.ErrorType.INVALID_GRANT?[3,6]:[4,this._localCredentials.setCredentials(null)];case 5:return n.sent(),[2,this._unAuthenticatedError(r.error_description)];case 6:return[2,Promise.reject(r)];case 7:return[2]}}))}))}))]}))}))},e.prototype._anonymousSignIn=function(e){return i(this,void 0,void 0,(function(){var t=this;return o(this,(function(r){return[2,this._singlePromise.run("_anonymous",(function(){return i(t,void 0,void 0,(function(){var t,r;return o(this,(function(n){switch(n.label){case 0:if(!e||"anonymous"!==e.scope)return[2,this._unAuthenticatedError("no anonymous in credentials")];n.label=1;case 1:return n.trys.push([1,4,,7]),[4,this.request("/auth/v1/signin/anonymously",{method:"POST",body:{client_id:this._clientId,client_secret:this._clientSecret}})];case 2:return t=n.sent(),[4,this._localCredentials.setCredentials(t)];case 3:return n.sent(),[2,t];case 4:return(r=n.sent()).error!==s.ErrorType.INVALID_GRANT?[3,6]:[4,this._localCredentials.setCredentials(null)];case 5:return n.sent(),[2,this._unAuthenticatedError(r.error_description)];case 6:return[2,Promise.reject(r)];case 7:return[2]}}))}))}))]}))}))},e.prototype._defaultRefreshTokenFunc=function(e){return void 0===e||""===e?this._unAuthenticatedError("refresh token not found"):this.request("/auth/v1/token",{method:"POST",body:{client_id:this._clientId,client_secret:this._clientSecret,grant_type:"refresh_token",refresh_token:e}})},e.prototype._getCredentials=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return[4,this._localCredentials.getCredentials()];case 1:return d(e=t.sent())?e&&"anonymous"===e.scope?[4,this._anonymousSignIn(e)]:[3,3]:[3,5];case 2:return e=t.sent(),[3,5];case 3:return[4,this._refreshToken(e)];case 4:e=t.sent(),t.label=5;case 5:return[2,e]}}))}))},e.prototype.getCredentialsSync=function(){return this._localCredentials._getStorageCredentialsSync()},e.prototype.getCredentialsAsync=function(){return this._localCredentials.getCredentials()},e.prototype.getScope=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return[4,this._localCredentials.getCredentials()];case 1:return null==(e=t.sent())?[2,this._unAuthenticatedError("credentials not found")]:[2,e.scope]}}))}))},e.prototype._getDeviceId=function(){return i(this,void 0,void 0,(function(){var e;return o(this,(function(t){switch(t.label){case 0:return this._deviceID?[2,this._deviceID]:[4,this._storage.getItem("device_id")];case 1:return"string"==typeof(e=t.sent())&&e.length>=16&&e.length<=48?[3,3]:(e=u.uuidv4(),[4,this._storage.setItem("device_id",e)]);case 2:t.sent(),t.label=3;case 3:return this._deviceID=e,[2,e]}}))}))},e.prototype._unAuthenticatedError=function(e){return Promise.reject({error:s.ErrorType.UNAUTHENTICATED,error_description:e})},e._defaultRetry=2,e._minRetry=0,e._maxRetry=5,e._retryInterval=1e3,e}();t.OAuth2Client=_},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorType=t.Syntax=void 0,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"}(t.Syntax||(t.Syntax={})),function(e){e.UNREACHABLE="unreachable",e.LOCAL="local",e.CANCELLED="cancelled",e.UNKNOWN="unknown",e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.UNAUTHENTICATED="unauthenticated",e.RESOURCE_EXHAUSTED="resource_exhausted",e.FAILED_PRECONDITION="failed_precondition",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked",e.INVALID_VERIFICATION_CODE="invalid_verification_code",e.TWO_FACTOR_REQUIRED="two_factor_required",e.INVALID_TWO_FACTOR="invalid_two_factor",e.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",e.UNDER_REVIEW="under_review",e.INVALID_REQUEST="invalid_request",e.UNAUTHORIZED_CLIENT="unauthorized_client",e.ACCESS_DENIED="access_denied",e.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",e.INVALID_SCOPE="invalid_scope",e.INVALID_GRANT="invalid_grant",e.SERVER_ERROR="server_error",e.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",e.INTERACTION_REQUIRED="interaction_required",e.LOGIN_REQUIRED="login_required",e.ACCOUNT_SELECTION_REQUIRED="account_selection_required",e.CONSENT_REQUIRED="consent_required",e.INVALID_REQUEST_URI="invalid_request_uri",e.INVALID_REQUEST_OBJECT="invalid_request_object",e.REQUEST_NOT_SUPPORTED="request_not_supported",e.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",e.REGISTRATION_NOT_SUPPORTED="registration_not_supported"}(t.ErrorType||(t.ErrorType={}))},function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function u(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.Auth=void 0;var o=r(8),s=r(0),u=r(9),a=function(){function e(e){var t=e.request,r=e.credentialsClient;if(!r){var n={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage};r=new s.OAuth2Client(n)}if(!t){var i=r.request.bind(r),o=new u.Captcha({clientId:e.clientId,request:i,storage:e.storage});t=o.request.bind(o)}this._config={apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:r,storage:e.storage||s.defaultStorage}}return e.prototype.signIn=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return[4,this._config.request(o.ApiUrls.AUTH_SIGN_IN_URL,{method:"POST",body:e})];case 1:return t=r.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return r.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signInAnonymously=function(){return n(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this._config.request(o.ApiUrls.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:{}})];case 1:return e=t.sent(),[4,this._config.credentialsClient.setCredentials(e)];case 2:return t.sent(),[2,Promise.resolve(e)]}}))}))},e.prototype.signUp=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return[4,this._config.request(o.ApiUrls.AUTH_SIGN_UP_URL,{method:"POST",body:e})];case 1:return t=r.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return r.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signOut=function(){return n(this,void 0,void 0,(function(){var e,t;return i(this,(function(r){switch(r.label){case 0:return[4,this._config.credentialsClient.getAccessToken()];case 1:return e=r.sent(),[4,this._config.request(o.ApiUrls.AUTH_REVOKE_URL,{method:"POST",body:{token:e}})];case 2:return t=r.sent(),[4,this._config.credentialsClient.setCredentials()];case 3:return r.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.getVerification=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return t=!1,"CUR_USER"!=e.target?[3,1]:(t=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:r.sent()&&(t=!0),r.label=3;case 3:return[2,this._config.request(o.ApiUrls.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:!0,withCredentials:t})]}}))}))},e.prototype.verify=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.VERIFY_URL,{method:"POST",body:e})]}))}))},e.prototype.genProviderRedirectUri=function(e){return n(this,void 0,void 0,(function(){var t,r;return i(this,(function(n){return t=o.ApiUrls.PROVIDER_URI_URL+"?client_id="+this._config.clientId+"&provider_id="+e.provider_id+"&redirect_uri="+encodeURIComponent(e.provider_redirect_uri)+"&state="+e.state,(r=e.other_params)&&"string"==typeof r.sign_out_uri&&r.sign_out_uri.length>0&&(t+="&other_params[sign_out_uri]="+r.sign_out_uri),[2,this._config.request(t,{method:"GET"})]}))}))},e.prototype.grantProviderToken=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.PROVIDER_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.patchProviderToken=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})]}))}))},e.prototype.signInWithProvider=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return[4,this._config.request(o.ApiUrls.AUTH_SIGN_IN_WITH_PROVIDER_URL,{method:"POST",body:e})];case 1:return t=r.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return r.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.bindWithProvider=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.getUserProfile=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.getUserInfo()]}))}))},e.prototype.getUserInfo=function(){return n(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this._config.request(o.ApiUrls.USER_ME_URL,{method:"GET",withCredentials:!0})];case 1:return(e=t.sent()).sub&&(e.uid=e.sub),[2,e]}}))}))},e.prototype.deleteMe=function(t){return n(this,void 0,void 0,(function(){var r;return i(this,(function(n){return r=o.ApiUrls.USER_ME_URL+"?"+e.parseParamsToSearch(t),[2,this._config.request(r,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.hasLoginState=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this._config.credentialsClient.getAccessToken()];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},e.prototype.hasLoginStateSync=function(){return this._config.credentialsClient.getCredentialsSync()},e.prototype.getLoginState=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this._config.credentialsClient.getCredentialsAsync()]}))}))},e.prototype.transByProvider=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.grantToken=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.AUTH_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.getProviders=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this._config.request(o.ApiUrls.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},e.prototype.unbindProvider=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.PROVIDER_UNBIND_URL+"/"+e.provider_id,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.checkPassword=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(""+o.ApiUrls.CHECK_PWD_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.bindPhone=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(""+o.ApiUrls.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.bindEmail=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(""+o.ApiUrls.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.setPassword=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(""+o.ApiUrls.AUTH_SET_PASSWORD,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.updatePasswordByOld=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return[4,this.sudo({password:e.old_password})];case 1:return t=r.sent(),[2,this.setPassword({sudo_token:t.sudo_token,new_password:e.new_password})]}}))}))},e.prototype.sudo=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(""+o.ApiUrls.SUDO_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.getCurUserVerification=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return e.target="CUR_USER",[2,this._config.request(o.ApiUrls.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})]}))}))},e.prototype.changeBindedProvider=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.PROVIDER_LIST+"/"+e.provider_id+"/trans",{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})]}))}))},e.prototype.setUserProfile=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.queryUserProfile=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){return t=new URLSearchParams(e),[2,this._config.request(o.ApiUrls.USER_QUERY_URL+"?"+t.toString(),{method:"GET",withCredentials:!0})]}))}))},e.prototype.setCustomSignFunc=function(e){this._getCustomSignTicketFn=e},e.prototype.signInWithCustomTicket=function(){return n(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this._getCustomSignTicketFn()];case 1:return e=t.sent(),[2,this.signInWithProvider({provider_id:"custom",provider_token:e})]}}))}))},e.prototype.resetPassword=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.AUTH_RESET_PASSWORD,{method:"POST",body:e})]}))}))},e.prototype.deviceAuthorize=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.checkUsername=function(e){return n(this,void 0,void 0,(function(){return i(this,(function(t){return[2,this._config.request(o.ApiUrls.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})]}))}))},e.prototype.checkIfUserExist=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){return t=new URLSearchParams(e),[2,this._config.request(o.ApiUrls.CHECK_IF_USER_EXIST+"?"+t.toString(),{method:"GET"})]}))}))},e.prototype.loginScope=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this._config.credentialsClient.getScope()]}))}))},e.parseParamsToSearch=function(e){for(var t in e)e[t]||delete e[t];return new URLSearchParams(e).toString()},e}();t.Auth=a},function(e,t,r){"use strict";var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||t.hasOwnProperty(r)||n(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(4),t)},function(e,t,r){"use strict";var n=this&&this.__assign||function(){return(n=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},i=this&&this.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),s=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.hasOwnProperty.call(e,r)&&i(t,e,r);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.CloudbaseOAuth=t.authModels=void 0;var u=r(1);Object.defineProperty(t,"Syntax",{enumerable:!0,get:function(){return u.Syntax}}),Object.defineProperty(t,"ErrorType",{enumerable:!0,get:function(){return u.ErrorType}});var a=r(0),c=r(0);Object.defineProperty(t,"defaultStorage",{enumerable:!0,get:function(){return c.defaultStorage}}),Object.defineProperty(t,"defaultRequest",{enumerable:!0,get:function(){return c.defaultRequest}}),Object.defineProperty(t,"toResponseError",{enumerable:!0,get:function(){return c.toResponseError}}),Object.defineProperty(t,"generateRequestId",{enumerable:!0,get:function(){return c.generateRequestId}}),Object.defineProperty(t,"OAuth2Client",{enumerable:!0,get:function(){return c.OAuth2Client}});var l=r(7);Object.defineProperty(t,"AuthClient",{enumerable:!0,get:function(){return l.AuthClient}});var d=r(2),h=r(2);Object.defineProperty(t,"Auth",{enumerable:!0,get:function(){return h.Auth}});var _=s(r(10));t.authModels=_;var f=function(e){var t=e.apiOrigin,r=e.clientId;this.oauth2client=new a.OAuth2Client({apiOrigin:t,clientId:r}),this.authApi=new d.Auth(n({credentialsClient:this.oauth2client},e))};t.CloudbaseOAuth=f},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.uuidv4=void 0,t.uuidv4=function(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))}},function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function u(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.SinglePromise=void 0;var o=function(){function e(){this._fnPromiseMap=new Map}return e.prototype.run=function(e,t){return n(this,void 0,void 0,(function(){var r,o=this;return i(this,(function(s){return(r=this._fnPromiseMap.get(e))||(r=new Promise((function(r,s){return n(o,void 0,void 0,(function(){var n,o,u;return i(this,(function(i){switch(i.label){case 0:return i.trys.push([0,3,4,5]),[4,this._runIdlePromise()];case 1:return i.sent(),n=t(),o=r,[4,n];case 2:return o.apply(void 0,[i.sent()]),[3,5];case 3:return u=i.sent(),s(u),[3,5];case 4:return this._fnPromiseMap.delete(e),[7];case 5:return[2]}}))}))})),this._fnPromiseMap.set(e,r)),[2,r]}))}))},e.prototype._runIdlePromise=function(){return Promise.resolve()},e}();t.SinglePromise=o},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AuthClient=void 0;var n=function(){};t.AuthClient=n},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ErrorType=t.VerificationUsages=t.ApiUrls=void 0,function(e){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_UP_URL="/auth/v1/signup",e.AUTH_TOKEN_URL="/auth/v1/token",e.AUTH_REVOKE_URL="/auth/v1/revoke",e.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",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.USER_QUERY_URL="/auth/v1/user/query",e.USER_PRIFILE_URL="/auth/v1/user/profile",e.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",e.VERIFICATION_URL="/auth/v1/verification",e.VERIFY_URL="/auth/v1/verification/verify",e.PROVIDER_LIST="/auth/v1/user/provider",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.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"}(t.ApiUrls||(t.ApiUrls={})),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"}(t.VerificationUsages||(t.VerificationUsages={})),function(e){e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.PASSWORD_NOT_SET="password_not_set",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked"}(t.ErrorType||(t.ErrorType={}))},function(e,t,r){"use strict";var n=this&&this.__awaiter||function(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{a(n.next(e))}catch(e){o(e)}}function u(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))},i=this&&this.__generator||function(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,n=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.Captcha=void 0;var o=r(0),s=function(){function e(e){e.openURIWithCallback||(e.openURIWithCallback=this._getDefaultOpenURIWithCallback()),e.storage||(e.storage=o.defaultStorage),this._config=e,this._tokenSectionName="captcha_"+e.clientId}return e.prototype.request=function(e,t){return n(this,void 0,void 0,(function(){var r,n,o,s;return i(this,(function(i){switch(i.label){case 0:return t||(t={}),t.method||(t.method="GET"),r=t.method+":"+e,n=e,t.withCaptcha?[4,this._appendCaptchaTokenToURL(e,r,!1)]:[3,2];case 1:n=i.sent(),i.label=2;case 2:return i.trys.push([2,4,,8]),[4,this._config.request(n,t)];case 3:return o=i.sent(),[3,8];case 4:return"captcha_required"!==(s=i.sent()).error&&"captcha_invalid"!==s.error?[3,6]:[4,this._appendCaptchaTokenToURL(e,r,"captcha_invalid"===s.error)];case 5:return e=i.sent(),[2,this._config.request(e,t)];case 6:return[2,Promise.reject(s)];case 7:return[3,8];case 8:return[2,o]}}))}))},e.prototype._getDefaultOpenURIWithCallback=function(){if(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((function(){document.body.appendChild(e)}),0)}return this._defaultOpenURIWithCallback},e.prototype._defaultOpenURIWithCallback=function(e){return n(this,void 0,void 0,(function(){var t,r;return i(this,(function(n){return t=document.getElementById("captcha_panel_wrap"),r=document.createElement("iframe"),t.innerHTML="",r.setAttribute("src",e),r.setAttribute("id","review-panel-iframe"),r.style.cssText="min-width:355px;display:block;height:355px;margin:0 auto;background-color: rgb(255, 255, 255);border: none;",t.appendChild(r),t.style.display="block",[2,new Promise((function(e,n){r.onload=function(){try{var i=window.location,o=r.contentWindow.location;if(o.host+o.pathname===i.host+i.pathname){t.style.display="none";var s=new URLSearchParams(o.search),u=s.get("captcha_token");return u?e({captcha_token:u,expires_in:Number(s.get("expires_in"))}):n({error:s.get("error"),error_description:s.get("error_description")})}t.style.display="block"}catch(e){t.style.display="block"}}}))]}))}))},e.prototype._getCaptchaToken=function(e,t){return n(this,void 0,void 0,(function(){var r,n,o,s,u;return i(this,(function(i){switch(i.label){case 0:return e?[3,2]:[4,this._findCaptchaToken()];case 1:if(r=i.sent())return[2,r];i.label=2;case 2:return n=window.location.origin+window.location.pathname+"?__captcha=on",[4,this._config.request("/auth/v1/captcha/init",{method:"POST",body:{client_id:this._config.clientId,redirect_uri:n,state:t},withCredentials:!1})];case 3:return(o=i.sent()).captcha_token?(s={captcha_token:o.captcha_token,expires_in:o.expires_in},this._saveCaptchaToken(s),[2,o.captcha_token]):[4,this._config.openURIWithCallback(o.url)];case 4:return u=i.sent(),this._saveCaptchaToken(u),[2,u.captcha_token]}}))}))},e.prototype._appendCaptchaTokenToURL=function(e,t,r){return n(this,void 0,void 0,(function(){var n;return i(this,(function(i){switch(i.label){case 0:return[4,this._getCaptchaToken(r,t)];case 1:return n=i.sent(),e.indexOf("?")>0?e+="&captcha_token="+n:e+="?captcha_token="+n,[2,e]}}))}))},e.prototype._saveCaptchaToken=function(e){return n(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10)),t=JSON.stringify(e),[4,this._config.storage.setItem(this._tokenSectionName,t)];case 1:return r.sent(),[2]}}))}))},e.prototype._findCaptchaToken=function(){return n(this,void 0,void 0,(function(){var e,t;return i(this,(function(r){switch(r.label){case 0:return[4,this._config.storage.getItem(this._tokenSectionName)];case 1:if(null==(e=r.sent()))return[3,5];r.label=2;case 2:return r.trys.push([2,3,,5]),(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),t.expires_at<new Date?[2,null]:[2,t.captcha_token];case 3:return r.sent(),[4,this._config.storage.removeItem(this._tokenSectionName)];case 4:return r.sent(),[2,null];case 5:return[2,null]}}))}))},e}();t.Captcha=s},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0})}])}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("cloudbase_oauth",[],t):"object"==typeof exports?exports.cloudbase_oauth=t():e.cloudbase_oauth=t()}("undefined"!=typeof window?window:this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(r,i,function(t){return e[t]}.bind(null,i));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),i=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||t.hasOwnProperty(n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),i(n(2),t)},function(e,t,n){"use strict";var r,i;function o(){return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))}n.r(t),n.d(t,"Syntax",(function(){return r})),n.d(t,"ErrorType",(function(){return i})),n.d(t,"defaultStorage",(function(){return p})),n.d(t,"defaultRequest",(function(){return h})),n.d(t,"toResponseError",(function(){return _})),n.d(t,"generateRequestId",(function(){return f})),n.d(t,"OAuth2Client",(function(){return I})),n.d(t,"AuthClient",(function(){return S})),n.d(t,"Auth",(function(){return w})),n.d(t,"authModels",(function(){return O})),n.d(t,"CloudbaseOAuth",(function(){return N})),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"}(r||(r={})),function(e){e.UNREACHABLE="unreachable",e.LOCAL="local",e.CANCELLED="cancelled",e.UNKNOWN="unknown",e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.UNAUTHENTICATED="unauthenticated",e.RESOURCE_EXHAUSTED="resource_exhausted",e.FAILED_PRECONDITION="failed_precondition",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked",e.INVALID_VERIFICATION_CODE="invalid_verification_code",e.TWO_FACTOR_REQUIRED="two_factor_required",e.INVALID_TWO_FACTOR="invalid_two_factor",e.INVALID_TWO_FACTOR_RECOVERY="invalid_two_factor_recovery",e.UNDER_REVIEW="under_review",e.INVALID_REQUEST="invalid_request",e.UNAUTHORIZED_CLIENT="unauthorized_client",e.ACCESS_DENIED="access_denied",e.UNSUPPORTED_RESPONSE_TYPE="unsupported_response_type",e.INVALID_SCOPE="invalid_scope",e.INVALID_GRANT="invalid_grant",e.SERVER_ERROR="server_error",e.TEMPORARILY_UNAVAILABLE="temporarily_unavailable",e.INTERACTION_REQUIRED="interaction_required",e.LOGIN_REQUIRED="login_required",e.ACCOUNT_SELECTION_REQUIRED="account_selection_required",e.CONSENT_REQUIRED="consent_required",e.INVALID_REQUEST_URI="invalid_request_uri",e.INVALID_REQUEST_OBJECT="invalid_request_object",e.REQUEST_NOT_SUPPORTED="request_not_supported",e.REQUEST_URI_NOT_SUPPORTED="request_uri_not_supported",e.REGISTRATION_NOT_SUPPORTED="registration_not_supported"}(i||(i={}));var s=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},u=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},a=function(){function e(){this._fnPromiseMap=new Map}return e.prototype.run=function(e,t){return s(this,void 0,void 0,(function(){var n,r=this;return u(this,(function(i){return(n=this._fnPromiseMap.get(e))||(n=new Promise((function(n,i){return s(r,void 0,void 0,(function(){var r,o,s;return u(this,(function(u){switch(u.label){case 0:return u.trys.push([0,3,4,5]),[4,this._runIdlePromise()];case 1:return u.sent(),r=t(),o=n,[4,r];case 2:return o.apply(void 0,[u.sent()]),[3,5];case 3:return s=u.sent(),i(s),[3,5];case 4:return this._fnPromiseMap.delete(e),[7];case 5:return[2]}}))}))})),this._fnPromiseMap.set(e,n)),[2,n]}))}))},e.prototype._runIdlePromise=function(){return Promise.resolve()},e}(),c=function(){return(c=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},l=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},d=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},h=function(e,t){return l(void 0,void 0,void 0,(function(){var n,r,o,s,u;return d(this,(function(a){switch(a.label){case 0:n=null,r=null,a.label=1;case 1:return a.trys.push([1,4,,5]),(o=Object.assign({},t)).method||(o.method="GET"),o.body&&"string"!=typeof o.body&&(o.body=JSON.stringify(o.body)),[4,fetch(e,o)];case 2:return[4,a.sent().json()];case 3:return(null==(s=a.sent())?void 0:s.error)?(r=s).error_uri=new URL(e).pathname:n=s,[3,5];case 4:return u=a.sent(),r={error:i.UNREACHABLE,error_description:u.message,error_uri:new URL(e).pathname},[3,5];case 5:if(r)throw r;return[2,n]}}))}))},_=function(e,t){var n,r=t||{};if(e instanceof Error)n={error:r.error||i.LOCAL,error_description:r.error_description||e.message,error_uri:r.error_uri,details:r.details||e.stack};else{var o=e||{};n={error:r.error||o.error||i.LOCAL,error_description:r.error_description||o.error_description,error_uri:r.error_uri||o.error_uri,details:r.details||o.details}}return n};function f(){return o()}var p=new(function(){function e(){}return e.prototype.getItem=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return[2,window.localStorage.getItem(e)]}))}))},e.prototype.removeItem=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return window.localStorage.removeItem(e),[2]}))}))},e.prototype.setItem=function(e,t){return l(this,void 0,void 0,(function(){return d(this,(function(n){return window.localStorage.setItem(e,t),[2]}))}))},e.prototype.getItemSync=function(e){return window.localStorage.getItem(e)},e.prototype.removeItemSync=function(e){window.localStorage.removeItem(e)},e.prototype.setItemSync=function(e,t){window.localStorage.setItem(e,t)},e}());function v(e){var t=!0;return(null==e?void 0:e.expires_at)&&(null==e?void 0:e.access_token)&&(t=e.expires_at<new Date),t}var y,E,R,g=function(){function e(e){this._credentials=null,this._singlePromise=new a,this._tokenSectionName=e.tokenSectionName,this._storage=e.storage}return e.prototype.setCredentials=function(e){return l(this,void 0,void 0,(function(){var t;return d(this,(function(n){switch(n.label){case 0:return(null==e?void 0:e.expires_in)?(e.expires_at=new Date(Date.now()+1e3*(e.expires_in-30)),this._storage?(t=JSON.stringify(e),[4,this._storage.setItem(this._tokenSectionName,t)]):[3,2]):[3,3];case 1:n.sent(),n.label=2;case 2:return this._credentials=e,[3,6];case 3:return this._storage?[4,this._storage.removeItem(this._tokenSectionName)]:[3,5];case 4:n.sent(),n.label=5;case 5:this._credentials=null,n.label=6;case 6:return[2]}}))}))},e.prototype.getCredentials=function(){return l(this,void 0,void 0,(function(){var e=this;return d(this,(function(t){return[2,this._singlePromise.run("getCredentials",(function(){return l(e,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return v(this._credentials)?(e=this,[4,this._getStorageCredentials()]):[3,2];case 1:e._credentials=t.sent(),t.label=2;case 2:return[2,this._credentials]}}))}))}))]}))}))},e.prototype._getStorageCredentials=function(){return l(this,void 0,void 0,(function(){var e=this;return d(this,(function(t){return[2,this._singlePromise.run("_getStorageCredentials",(function(){return l(e,void 0,void 0,(function(){var e,t;return d(this,(function(n){switch(n.label){case 0:return e=null,[4,this._storage.getItem(this._tokenSectionName)];case 1:if(null==(t=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at)),[3,5];case 3:return n.sent(),[4,this._storage.removeItem(this._tokenSectionName)];case 4:return n.sent(),e=null,[3,5];case 5:return[2,e]}}))}))}))]}))}))},e.prototype._getStorageCredentialsSync=function(){var e=null,t=this._storage.getItemSync(this._tokenSectionName);if(null!=t)try{(null==(e=JSON.parse(t))?void 0:e.expires_at)&&(e.expires_at=new Date(e.expires_at))}catch(t){this._storage.removeItem(this._tokenSectionName),e=null}return e},e}(),I=function(){function e(t){this._singlePromise=new a,this._apiOrigin=t.apiOrigin,this._clientId=t.clientId,this._retry=this._formatRetry(t.retry,e._defaultRetry),null!=t.baseRequest?this._baseRequest=t.baseRequest:this._baseRequest=h,this._tokenInURL=t.tokenInURL,this._headers=t.headers,this._storage=t.storage||p,this._localCredentials=new g({tokenSectionName:"credentials_"+t.clientId,storage:this._storage}),this._clientSecret=t.clientSecret,this._refreshTokenFunc=t.refreshTokenFunc||this._defaultRefreshTokenFunc}return e.prototype.setCredentials=function(e){return this._localCredentials.setCredentials(e)},e.prototype.getAccessToken=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this._getCredentials()];case 1:return(null==(e=t.sent())?void 0:e.access_token)?[2,Promise.resolve(e.access_token)]:[2,Promise.reject({error:i.UNAUTHENTICATED})]}}))}))},e.prototype.request=function(t,n){return l(this,void 0,void 0,(function(){var r,o,s,u,a,l,h;return d(this,(function(d){switch(d.label){case 0:return n||(n={}),r=this._formatRetry(n.retry,this._retry),n.headers=n.headers||{},this._headers&&(n.headers=c(c({},this._headers),n.headers)),n.headers["x-request-id"]||(n.headers["x-request-id"]=f()),n.headers["x-device-id"]?[3,2]:[4,this._getDeviceId()];case 1:o=d.sent(),n.headers["x-device-id"]=o,d.label=2;case 2:return(null==n?void 0:n.withCredentials)?[4,this._getCredentials()]:[3,4];case 3:return(s=d.sent())&&(this._tokenInURL?(t.indexOf("?")<0&&(t+="?"),t+="access_token="+s.access_token):n.headers.Authorization=s.token_type+" "+s.access_token),[3,5];case 4:this._clientId&&t.indexOf("client_id")<0&&(t+=t.indexOf("?")<0?"?":"&",t+="client_id="+this._clientId),d.label=5;case 5:t.startsWith("/")&&(t=this._apiOrigin+t),u=null,a=r+1,l=0,d.label=6;case 6:if(!(l<a))return[3,15];d.label=7;case 7:return d.trys.push([7,9,,12]),[4,this._baseRequest(t,n)];case 8:return u=d.sent(),[3,15];case 9:return h=d.sent(),n.withCredentials&&h&&h.error===i.UNAUTHENTICATED?[4,this.setCredentials(null)]:[3,11];case 10:return d.sent(),[2,Promise.reject(h)];case 11:return l!==r&&h&&"unreachable"===h.error?[3,12]:[2,Promise.reject(h)];case 12:return[4,this._sleep(e._retryInterval)];case 13:d.sent(),d.label=14;case 14:return l++,[3,6];case 15:return[2,u]}}))}))},e.prototype._checkRetry=function(t){var n=null;if(("number"!=typeof t||t<e._minRetry||t>e._maxRetry)&&(n={error:i.UNREACHABLE,error_description:"wrong options param: retry"}),n)throw n;return t},e.prototype._formatRetry=function(e,t){return void 0===e?t:this._checkRetry(e)},e.prototype._sleep=function(e){return l(this,void 0,void 0,(function(){return d(this,(function(t){return[2,new Promise((function(t){setTimeout((function(){t()}),e)}))]}))}))},e.prototype._refreshToken=function(e){return l(this,void 0,void 0,(function(){var t=this;return d(this,(function(n){return[2,this._singlePromise.run("_refreshToken",(function(){return l(t,void 0,void 0,(function(){var t,n;return d(this,(function(r){switch(r.label){case 0:if(!e||!e.refresh_token)return[2,this._unAuthenticatedError("no refresh token found in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this._refreshTokenFunc(e.refresh_token)];case 2:return t=r.sent(),[4,this._localCredentials.setCredentials(t)];case 3:return r.sent(),[2,t];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this._localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this._unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},e.prototype._anonymousSignIn=function(e){return l(this,void 0,void 0,(function(){var t=this;return d(this,(function(n){return[2,this._singlePromise.run("_anonymous",(function(){return l(t,void 0,void 0,(function(){var t,n;return d(this,(function(r){switch(r.label){case 0:if(!e||"anonymous"!==e.scope)return[2,this._unAuthenticatedError("no anonymous in credentials")];r.label=1;case 1:return r.trys.push([1,4,,7]),[4,this.request("/auth/v1/signin/anonymously",{method:"POST",body:{client_id:this._clientId,client_secret:this._clientSecret}})];case 2:return t=r.sent(),[4,this._localCredentials.setCredentials(t)];case 3:return r.sent(),[2,t];case 4:return(n=r.sent()).error!==i.INVALID_GRANT?[3,6]:[4,this._localCredentials.setCredentials(null)];case 5:return r.sent(),[2,this._unAuthenticatedError(n.error_description)];case 6:return[2,Promise.reject(n)];case 7:return[2]}}))}))}))]}))}))},e.prototype._defaultRefreshTokenFunc=function(e){return void 0===e||""===e?this._unAuthenticatedError("refresh token not found"):this.request("/auth/v1/token",{method:"POST",body:{client_id:this._clientId,client_secret:this._clientSecret,grant_type:"refresh_token",refresh_token:e}})},e.prototype._getCredentials=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this._localCredentials.getCredentials()];case 1:return v(e=t.sent())?e&&"anonymous"===e.scope?[4,this._anonymousSignIn(e)]:[3,3]:[3,5];case 2:return e=t.sent(),[3,5];case 3:return[4,this._refreshToken(e)];case 4:e=t.sent(),t.label=5;case 5:return[2,e]}}))}))},e.prototype.getCredentialsSync=function(){return this._localCredentials._getStorageCredentialsSync()},e.prototype.getCredentialsAsync=function(){return this._localCredentials.getCredentials()},e.prototype.getScope=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this._localCredentials.getCredentials()];case 1:return null==(e=t.sent())?[2,this._unAuthenticatedError("credentials not found")]:[2,e.scope]}}))}))},e.prototype.getGroups=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return[4,this._localCredentials.getCredentials()];case 1:return null==(e=t.sent())?[2,this._unAuthenticatedError("credentials not found")]:[2,e.groups]}}))}))},e.prototype._getDeviceId=function(){return l(this,void 0,void 0,(function(){var e;return d(this,(function(t){switch(t.label){case 0:return this._deviceID?[2,this._deviceID]:[4,this._storage.getItem("device_id")];case 1:return"string"==typeof(e=t.sent())&&e.length>=16&&e.length<=48?[3,3]:(e=o(),[4,this._storage.setItem("device_id",e)]);case 2:t.sent(),t.label=3;case 3:return this._deviceID=e,[2,e]}}))}))},e.prototype._unAuthenticatedError=function(e){return Promise.reject({error:i.UNAUTHENTICATED,error_description:e})},e._defaultRetry=2,e._minRetry=0,e._maxRetry=5,e._retryInterval=1e3,e}(),S=function(){};!function(e){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_UP_URL="/auth/v1/signup",e.AUTH_TOKEN_URL="/auth/v1/token",e.AUTH_REVOKE_URL="/auth/v1/revoke",e.PROVIDER_BIND_URL="/auth/v1/user/provider/bind",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.USER_QUERY_URL="/auth/v1/user/query",e.USER_PRIFILE_URL="/auth/v1/user/profile",e.USER_TRANS_BY_PROVIDER_URL="/auth/v1/user/trans/by/provider",e.VERIFICATION_URL="/auth/v1/verification",e.VERIFY_URL="/auth/v1/verification/verify",e.PROVIDER_LIST="/auth/v1/user/provider",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.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"}(y||(y={})),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"}(E||(E={})),function(e){e.INVALID_ARGUMENT="invalid_argument",e.DEADLINE_EXCEEDED="deadline_exceeded",e.NOT_FOUND="not_found",e.ALREADY_EXISTS="already_exists",e.PERMISSION_DENIED="permission_denied",e.ABORTED="aborted",e.OUT_OF_RANGE="out_of_range",e.UNIMPLEMENTED="unimplemented",e.INTERNAL="internal",e.UNAVAILABLE="unavailable",e.DATA_LOSS="data_loss",e.CAPTCHA_REQUIRED="captcha_required",e.CAPTCHA_INVALID="captcha_invalid",e.INVALID_PASSWORD="invalid_password",e.PASSWORD_NOT_SET="password_not_set",e.INVALID_STATUS="invalid_status",e.USER_PENDING="user_pending",e.USER_BLOCKED="user_blocked"}(R||(R={}));var T=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},b=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},m=function(){function e(e){e.openURIWithCallback||(e.openURIWithCallback=this._getDefaultOpenURIWithCallback()),e.storage||(e.storage=p),this._config=e,this._tokenSectionName="captcha_"+e.clientId}return e.prototype.request=function(e,t){return T(this,void 0,void 0,(function(){var n,r,i,o;return b(this,(function(s){switch(s.label){case 0:return t||(t={}),t.method||(t.method="GET"),n=t.method+":"+e,r=e,t.withCaptcha?[4,this._appendCaptchaTokenToURL(e,n,!1)]:[3,2];case 1:r=s.sent(),s.label=2;case 2:return s.trys.push([2,4,,8]),[4,this._config.request(r,t)];case 3:return i=s.sent(),[3,8];case 4:return"captcha_required"!==(o=s.sent()).error&&"captcha_invalid"!==o.error?[3,6]:[4,this._appendCaptchaTokenToURL(e,n,"captcha_invalid"===o.error)];case 5:return e=s.sent(),[2,this._config.request(e,t)];case 6:return[2,Promise.reject(o)];case 7:return[3,8];case 8:return[2,i]}}))}))},e.prototype._getDefaultOpenURIWithCallback=function(){if(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((function(){document.body.appendChild(e)}),0)}return this._defaultOpenURIWithCallback},e.prototype._defaultOpenURIWithCallback=function(e){return T(this,void 0,void 0,(function(){var t,n;return b(this,(function(r){return t=document.getElementById("captcha_panel_wrap"),n=document.createElement("iframe"),t.innerHTML="",n.setAttribute("src",e),n.setAttribute("id","review-panel-iframe"),n.style.cssText="min-width:355px;display:block;height:355px;margin:0 auto;background-color: rgb(255, 255, 255);border: none;",t.appendChild(n),t.style.display="block",[2,new Promise((function(e,r){n.onload=function(){try{var i=window.location,o=n.contentWindow.location;if(o.host+o.pathname===i.host+i.pathname){t.style.display="none";var s=new URLSearchParams(o.search),u=s.get("captcha_token");return u?e({captcha_token:u,expires_in:Number(s.get("expires_in"))}):r({error:s.get("error"),error_description:s.get("error_description")})}t.style.display="block"}catch(e){t.style.display="block"}}}))]}))}))},e.prototype._getCaptchaToken=function(e,t){return T(this,void 0,void 0,(function(){var n,r,i,o,s;return b(this,(function(u){switch(u.label){case 0:return e?[3,2]:[4,this._findCaptchaToken()];case 1:if(n=u.sent())return[2,n];u.label=2;case 2:return r=window.location.origin+window.location.pathname+"?__captcha=on",[4,this._config.request("/auth/v1/captcha/init",{method:"POST",body:{client_id:this._config.clientId,redirect_uri:r,state:t},withCredentials:!1})];case 3:return(i=u.sent()).captcha_token?(o={captcha_token:i.captcha_token,expires_in:i.expires_in},this._saveCaptchaToken(o),[2,i.captcha_token]):[4,this._config.openURIWithCallback(i.url)];case 4:return s=u.sent(),this._saveCaptchaToken(s),[2,s.captcha_token]}}))}))},e.prototype._appendCaptchaTokenToURL=function(e,t,n){return T(this,void 0,void 0,(function(){var r;return b(this,(function(i){switch(i.label){case 0:return[4,this._getCaptchaToken(n,t)];case 1:return r=i.sent(),e.indexOf("?")>0?e+="&captcha_token="+r:e+="?captcha_token="+r,[2,e]}}))}))},e.prototype._saveCaptchaToken=function(e){return T(this,void 0,void 0,(function(){var t;return b(this,(function(n){switch(n.label){case 0:return e.expires_at=new Date(Date.now()+1e3*(e.expires_in-10)),t=JSON.stringify(e),[4,this._config.storage.setItem(this._tokenSectionName,t)];case 1:return n.sent(),[2]}}))}))},e.prototype._findCaptchaToken=function(){return T(this,void 0,void 0,(function(){var e,t;return b(this,(function(n){switch(n.label){case 0:return[4,this._config.storage.getItem(this._tokenSectionName)];case 1:if(null==(e=n.sent()))return[3,5];n.label=2;case 2:return n.trys.push([2,3,,5]),(null==(t=JSON.parse(e))?void 0:t.expires_at)&&(t.expires_at=new Date(t.expires_at)),t.expires_at<new Date?[2,null]:[2,t.captcha_token];case 3:return n.sent(),[4,this._config.storage.removeItem(this._tokenSectionName)];case 4:return n.sent(),[2,null];case 5:return[2,null]}}))}))},e}(),C=function(e,t,n,r){return new(n||(n=Promise))((function(i,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function u(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,u)}a((r=r.apply(e,t||[])).next())}))},U=function(e,t){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(o){return function(u){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){s.label=o[1];break}if(6===o[0]&&s.label<i[1]){s.label=i[1],i=o;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(o);break}i[2]&&s.ops.pop(),s.trys.pop();continue}o=t.call(e,s)}catch(e){o=[6,e],r=0}finally{n=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}},w=function(){function e(e){var t=e.request,n=e.credentialsClient;if(!n){var r={apiOrigin:e.apiOrigin,clientId:e.clientId,storage:e.storage};n=new I(r)}if(!t){var i=n.request.bind(n),o=new m({clientId:e.clientId,request:i,storage:e.storage});t=o.request.bind(o)}this._config={apiOrigin:e.apiOrigin,clientId:e.clientId,request:t,credentialsClient:n,storage:e.storage||p}}return e.prototype.signIn=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){switch(n.label){case 0:return[4,this._config.request(y.AUTH_SIGN_IN_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signInAnonymously=function(){return C(this,void 0,void 0,(function(){var e;return U(this,(function(t){switch(t.label){case 0:return[4,this._config.request(y.AUTH_SIGN_IN_ANONYMOUSLY_URL,{method:"POST",body:{}})];case 1:return e=t.sent(),[4,this._config.credentialsClient.setCredentials(e)];case 2:return t.sent(),[2,Promise.resolve(e)]}}))}))},e.prototype.signUp=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){switch(n.label){case 0:return[4,this._config.request(y.AUTH_SIGN_UP_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.signOut=function(){return C(this,void 0,void 0,(function(){var e,t;return U(this,(function(n){switch(n.label){case 0:return[4,this._config.credentialsClient.getAccessToken()];case 1:return e=n.sent(),[4,this._config.request(y.AUTH_REVOKE_URL,{method:"POST",body:{token:e}})];case 2:return t=n.sent(),[4,this._config.credentialsClient.setCredentials()];case 3:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.getVerification=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){switch(n.label){case 0:return t=!1,"CUR_USER"!=e.target?[3,1]:(t=!0,[3,3]);case 1:return[4,this.hasLoginState()];case 2:n.sent()&&(t=!0),n.label=3;case 3:return[2,this._config.request(y.VERIFICATION_URL,{method:"POST",body:e,withCaptcha:!0,withCredentials:t})]}}))}))},e.prototype.verify=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.VERIFY_URL,{method:"POST",body:e})]}))}))},e.prototype.genProviderRedirectUri=function(e){return C(this,void 0,void 0,(function(){var t,n;return U(this,(function(r){return t=y.PROVIDER_URI_URL+"?client_id="+this._config.clientId+"&provider_id="+e.provider_id+"&redirect_uri="+encodeURIComponent(e.provider_redirect_uri)+"&state="+e.state,(n=e.other_params)&&"string"==typeof n.sign_out_uri&&n.sign_out_uri.length>0&&(t+="&other_params[sign_out_uri]="+n.sign_out_uri),[2,this._config.request(t,{method:"GET"})]}))}))},e.prototype.grantProviderToken=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.PROVIDER_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.patchProviderToken=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})]}))}))},e.prototype.signInWithProvider=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){switch(n.label){case 0:return[4,this._config.request(y.AUTH_SIGN_IN_WITH_PROVIDER_URL,{method:"POST",body:e})];case 1:return t=n.sent(),[4,this._config.credentialsClient.setCredentials(t)];case 2:return n.sent(),[2,Promise.resolve(t)]}}))}))},e.prototype.bindWithProvider=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.getUserProfile=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){return[2,this.getUserInfo()]}))}))},e.prototype.getUserInfo=function(){return C(this,void 0,void 0,(function(){var e;return U(this,(function(t){switch(t.label){case 0:return[4,this._config.request(y.USER_ME_URL,{method:"GET",withCredentials:!0})];case 1:return(e=t.sent()).sub&&(e.uid=e.sub),[2,e]}}))}))},e.prototype.deleteMe=function(t){return C(this,void 0,void 0,(function(){var n;return U(this,(function(r){return n=y.USER_ME_URL+"?"+e.parseParamsToSearch(t),[2,this._config.request(n,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.hasLoginState=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,this._config.credentialsClient.getAccessToken()];case 1:return e.sent(),[2,!0];case 2:return e.sent(),[2,!1];case 3:return[2]}}))}))},e.prototype.hasLoginStateSync=function(){return this._config.credentialsClient.getCredentialsSync()},e.prototype.getLoginState=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){return[2,this._config.credentialsClient.getCredentialsAsync()]}))}))},e.prototype.transByProvider=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.USER_TRANS_BY_PROVIDER_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.grantToken=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.AUTH_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.getProviders=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){return[2,this._config.request(y.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},e.prototype.unbindProvider=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.PROVIDER_UNBIND_URL+"/"+e.provider_id,{method:"DELETE",withCredentials:!0})]}))}))},e.prototype.checkPassword=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(""+y.CHECK_PWD_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.bindPhone=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.bindEmail=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.setPassword=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(""+y.AUTH_SET_PASSWORD,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.updatePasswordByOld=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){switch(n.label){case 0:return[4,this.sudo({password:e.old_password})];case 1:return t=n.sent(),[2,this.setPassword({sudo_token:t.sudo_token,new_password:e.new_password})]}}))}))},e.prototype.sudo=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(""+y.SUDO_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.getCurUserVerification=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return e.target="CUR_USER",[2,this._config.request(y.VERIFICATION_URL,{method:"POST",body:e,withCredentials:!0,withCaptcha:!0})]}))}))},e.prototype.changeBindedProvider=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.PROVIDER_LIST+"/"+e.provider_id+"/trans",{method:"POST",body:{provider_trans_token:e.trans_token},withCredentials:!0})]}))}))},e.prototype.setUserProfile=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.queryUserProfile=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){return t=new URLSearchParams(e),[2,this._config.request(y.USER_QUERY_URL+"?"+t.toString(),{method:"GET",withCredentials:!0})]}))}))},e.prototype.setCustomSignFunc=function(e){this._getCustomSignTicketFn=e},e.prototype.signInWithCustomTicket=function(){return C(this,void 0,void 0,(function(){var e;return U(this,(function(t){switch(t.label){case 0:return[4,this._getCustomSignTicketFn()];case 1:return e=t.sent(),[2,this.signInWithProvider({provider_id:"custom",provider_token:e})]}}))}))},e.prototype.resetPassword=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.AUTH_RESET_PASSWORD,{method:"POST",body:e})]}))}))},e.prototype.deviceAuthorize=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.AUTH_GET_DEVICE_CODE,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.checkUsername=function(e){return C(this,void 0,void 0,(function(){return U(this,(function(t){return[2,this._config.request(y.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})]}))}))},e.prototype.checkIfUserExist=function(e){return C(this,void 0,void 0,(function(){var t;return U(this,(function(n){return t=new URLSearchParams(e),[2,this._config.request(y.CHECK_IF_USER_EXIST+"?"+t.toString(),{method:"GET"})]}))}))},e.prototype.loginScope=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){return[2,this._config.credentialsClient.getScope()]}))}))},e.prototype.loginGroups=function(){return C(this,void 0,void 0,(function(){return U(this,(function(e){return[2,this._config.credentialsClient.getGroups()]}))}))},e.parseParamsToSearch=function(e){for(var t in e)e[t]||delete e[t];return new URLSearchParams(e).toString()},e}(),O=n(0),A=function(){return(A=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},N=function(e){var t=e.apiOrigin,n=e.clientId;this.oauth2client=new I({apiOrigin:t,clientId:n}),this.authApi=new w(A({credentialsClient:this.oauth2client},e))}}])}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/js-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-beta.0",
|
|
4
4
|
"description": "cloudbase javascript sdk",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@cloudbase/analytics": "^2.0.0-alpha.4",
|
|
49
49
|
"@cloudbase/app": "^2.0.0-alpha.6",
|
|
50
|
-
"@cloudbase/auth": "^2.
|
|
50
|
+
"@cloudbase/auth": "^2.4.0-beta.0",
|
|
51
51
|
"@cloudbase/database": "0.9.18-next",
|
|
52
52
|
"@cloudbase/functions": "^2.0.0-alpha.4",
|
|
53
53
|
"@cloudbase/realtime": "^2.0.0-alpha.2",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"not dead",
|
|
89
89
|
"chrome 53"
|
|
90
90
|
],
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "497d76ae68cd3c4dada9abfaabf3fa1c9529a641"
|
|
92
92
|
}
|