@cloudbase/js-sdk 2.5.4-beta.0 → 2.5.5-alpha.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 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 _})),n.d(t,"defaultRequest",(function(){return h})),n.d(t,"toResponseError",(function(){return f})),n.d(t,"generateRequestId",(function(){return p})),n.d(t,"OAuth2Client",(function(){return I})),n.d(t,"AuthClient",(function(){return O})),n.d(t,"Auth",(function(){return w})),n.d(t,"authModels",(function(){return U})),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){switch(i.label){case 0:return[4,n=this.fnPromiseMap.get(e)];case 1:return i.sent()||(n=new Promise((function(n,i){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(this,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]}}))}))},f=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 p(){return o()}var _=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.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.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}(),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),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=h,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||_,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,t;return d(this,(function(n){switch(n.label){case 0:return[4,this.getCredentials()];case 1:return(null==(e=n.sent())?void 0:e.access_token)?[2,Promise.resolve(e.access_token)]:(t={error:i.UNAUTHENTICATED},[2,Promise.reject(t)])}}))}))},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"]=p()),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.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(e=t.sent())?[2,e.scope]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},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(e=t.sent())?[2,e.groups]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},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.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){var t={error:i.UNAUTHENTICATED,error_description:e};return Promise.reject(t)},e.defaultRetry=2,e.minRetry=0,e.maxRetry=5,e.retryInterval=1e3,e}();!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 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())}))},T=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])}}},b=function(){function e(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=_),this.config=e,this.tokenSectionName="captcha_"+e.clientId}return e.prototype.request=function(e,t){return S(this,void 0,void 0,(function(){var n,r,i,o;return T(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,,7]),[4,this.config.request(r,t)];case 3:return i=s.sent(),[3,7];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[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 S(this,void 0,void 0,(function(){var t,n;return T(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 S(this,void 0,void 0,(function(){var n,r,i,o,s;return T(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 S(this,void 0,void 0,(function(){var r;return T(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 S(this,void 0,void 0,(function(){var t;return T(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 S(this,void 0,void 0,(function(){var e,t;return T(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}(),m=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())}))},C=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 b({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||_}}return e.parseParamsToSearch=function(e){return Object.keys(e).forEach((function(t){e[t]||delete e[t]})),new URLSearchParams(e).toString()},e.prototype.signIn=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){var e;return C(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 m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){var e,t;return C(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 m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.VERIFY_URL,{method:"POST",body:e})]}))}))},e.prototype.genProviderRedirectUri=function(e){return m(this,void 0,void 0,(function(){var t,n;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.patchProviderToken=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})]}))}))},e.prototype.signInWithProvider=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.getUserProfile=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.getUserInfo()]}))}))},e.prototype.getUserInfo=function(){return m(this,void 0,void 0,(function(){var e;return C(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 m(this,void 0,void 0,(function(){var n;return C(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 m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getCredentialsAsync()]}))}))},e.prototype.transByProvider=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.getProviders=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.request(y.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},e.prototype.unbindProvider=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.CHECK_PWD_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.bindPhone=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.bindEmail=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.setPassword=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.AUTH_SET_PASSWORD,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.updatePasswordByOld=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.SUDO_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.getCurUserVerification=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.queryUserProfile=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){var e;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_RESET_PASSWORD,{method:"POST",body:e})]}))}))},e.prototype.deviceAuthorize=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})]}))}))},e.prototype.checkIfUserExist=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getScope()]}))}))},e.prototype.loginGroups=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getGroups()]}))}))},e}(),U=n(0),O=function(){},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,r=e.storage;this.oauth2client=new I({apiOrigin:t,clientId:n,storage:r}),this.authApi=new w(A({credentialsClient:this.oauth2client},e))}}])}));
|
|
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 _})),n.d(t,"defaultRequest",(function(){return h})),n.d(t,"toResponseError",(function(){return f})),n.d(t,"generateRequestId",(function(){return p})),n.d(t,"OAuth2Client",(function(){return I})),n.d(t,"AuthClient",(function(){return O})),n.d(t,"Auth",(function(){return w})),n.d(t,"authModels",(function(){return U})),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){switch(i.label){case 0:return[4,n=this.fnPromiseMap.get(e)];case 1:return i.sent()||(n=new Promise((function(n,i){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(this,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]}}))}))},f=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 p(){return o()}var _=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,g,R=function(){function e(e){this.credentials=null,this.singlePromise=new a,this.tokenSectionName=e.tokenSectionName,this.storage=e.storage}return 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.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}(),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),t.baseRequest?this.baseRequest=t.baseRequest:this.baseRequest=h,this.tokenInURL=t.tokenInURL,this.headers=t.headers,this.storage=t.storage||_,this.localCredentials=new R({tokenSectionName:"credentials_"+t.clientId,storage:this.storage}),this.clientSecret=t.clientSecret,this.refreshTokenFunc=t.refreshTokenFunc||this.defaultRefreshTokenFunc,this.anonymousSignInFunc=t.anonymousSignInFunc}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,t;return d(this,(function(n){switch(n.label){case 0:return[4,this.getCredentials()];case 1:return(null==(e=n.sent())?void 0:e.access_token)?[2,Promise.resolve(e.access_token)]:(t={error:i.UNAUTHENTICATED},[2,Promise.reject(t)])}}))}))},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"]=p()),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.getCredentials=function(){return l(this,void 0,void 0,(function(){var e,t,n;return d(this,(function(r){switch(r.label){case 0:return[4,this.localCredentials.getCredentials()];case 1:return v(e=r.sent())?e&&"anonymous"===e.scope?this.anonymousSignInFunc?[4,this.anonymousSignInFunc(e)]:[3,5]:[3,8]:[3,10];case 2:return t=r.sent(),(n=t)?[3,4]:[4,this.localCredentials.getCredentials()];case 3:n=r.sent(),r.label=4;case 4:return e=n,[3,7];case 5:return[4,this.anonymousSignIn(e)];case 6:e=r.sent(),r.label=7;case 7:return[3,10];case 8:return[4,this.refreshToken(e)];case 9:e=r.sent(),r.label=10;case 10: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(e=t.sent())?[2,e.scope]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},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(e=t.sent())?[2,e.groups]:[2,this.unAuthenticatedError("credentials not found")]}}))}))},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.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){var t={error:i.UNAUTHENTICATED,error_description:e};return Promise.reject(t)},e.defaultRetry=2,e.minRetry=0,e.maxRetry=5,e.retryInterval=1e3,e}();!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"}(g||(g={}));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())}))},T=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])}}},b=function(){function e(e){e.openURIWithCallback||(e.openURIWithCallback=this.getDefaultOpenURIWithCallback()),e.storage||(e.storage=_),this.config=e,this.tokenSectionName="captcha_"+e.clientId}return e.prototype.request=function(e,t){return S(this,void 0,void 0,(function(){var n,r,i,o;return T(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,,7]),[4,this.config.request(r,t)];case 3:return i=s.sent(),[3,7];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[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 S(this,void 0,void 0,(function(){var t,n;return T(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 S(this,void 0,void 0,(function(){var n,r,i,o,s;return T(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 S(this,void 0,void 0,(function(){var r;return T(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 S(this,void 0,void 0,(function(){var t;return T(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 S(this,void 0,void 0,(function(){var e,t;return T(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}(),m=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())}))},C=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 b({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||_}}return e.parseParamsToSearch=function(e){return Object.keys(e).forEach((function(t){e[t]||delete e[t]})),new URLSearchParams(e).toString()},e.prototype.signIn=function(e){return m(this,void 0,void 0,(function(){var t;return C(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(e){return void 0===e&&(e={}),m(this,void 0,void 0,(function(){var t;return C(this,(function(n){switch(n.label){case 0:return[4,this.config.request(y.AUTH_SIGN_IN_ANONYMOUSLY_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.signUp=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){var e,t;return C(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 m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.VERIFY_URL,{method:"POST",body:e})]}))}))},e.prototype.genProviderRedirectUri=function(e){return m(this,void 0,void 0,(function(){var t,n;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.patchProviderToken=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_TOKEN_URL,{method:"PATCH",body:e})]}))}))},e.prototype.signInWithProvider=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.PROVIDER_BIND_URL,{method:"POST",body:e,withCredentials:!0})]}))}))},e.prototype.getUserProfile=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.getUserInfo()]}))}))},e.prototype.getUserInfo=function(){return m(this,void 0,void 0,(function(){var e;return C(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 m(this,void 0,void 0,(function(){var n;return C(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 m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getCredentialsAsync()]}))}))},e.prototype.transByProvider=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_TOKEN_URL,{method:"POST",body:e})]}))}))},e.prototype.getProviders=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.request(y.PROVIDER_LIST,{method:"GET",withCredentials:!0})]}))}))},e.prototype.unbindProvider=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.CHECK_PWD_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.bindPhone=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.bindEmail=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.BIND_CONTACT_URL,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.setPassword=function(e){return m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.AUTH_SET_PASSWORD,{method:"PATCH",withCredentials:!0,body:e})]}))}))},e.prototype.updatePasswordByOld=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(""+y.SUDO_URL,{method:"POST",withCredentials:!0,body:e})]}))}))},e.prototype.getCurUserVerification=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.USER_PRIFILE_URL,{method:"PATCH",body:e,withCredentials:!0})]}))}))},e.prototype.queryUserProfile=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){var e;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.AUTH_RESET_PASSWORD,{method:"POST",body:e})]}))}))},e.prototype.deviceAuthorize=function(e){return m(this,void 0,void 0,(function(){return C(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 m(this,void 0,void 0,(function(){return C(this,(function(t){return[2,this.config.request(y.CHECK_USERNAME,{method:"GET",body:e,withCredentials:!0})]}))}))},e.prototype.checkIfUserExist=function(e){return m(this,void 0,void 0,(function(){var t;return C(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 m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getScope()]}))}))},e.prototype.loginGroups=function(){return m(this,void 0,void 0,(function(){return C(this,(function(e){return[2,this.config.credentialsClient.getGroups()]}))}))},e}(),U=n(0),O=function(){},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,r=e.storage,i=e.request,o=e.anonymousSignInFunc;this.oauth2client=new I({apiOrigin:t,clientId:n,storage:r,baseRequest:i,anonymousSignInFunc:o}),this.authApi=new w(A(A({credentialsClient:this.oauth2client},e),{request:i?this.oauth2client.request.bind(this.oauth2client):void 0}))}}])}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/js-sdk",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.5-alpha.0",
|
|
4
4
|
"description": "cloudbase javascript sdk",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -95,5 +95,5 @@
|
|
|
95
95
|
"eslint --fix"
|
|
96
96
|
]
|
|
97
97
|
},
|
|
98
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "176a0fbd69fbd5d85b31ca2437d83c53d52f5ca3"
|
|
99
99
|
}
|