@agconnect/auth
Advanced tools
Comparing version 1.2.0 to 1.2.1-beta
import { AGCAuth, AGConnectAuthCredential, AGConnectUser, Persistence, SignInResult, PhoneUser, EmailUser, crypt } from '@agconnect/auth-types'; | ||
import "@agconnect/util"; | ||
export declare class AGCAuthImpl implements AGCAuth { | ||
import { Logger } from "@agconnect/log"; | ||
declare let authLogger: Logger; | ||
declare class AGCAuthImpl implements AGCAuth { | ||
private static persistence; | ||
@@ -20,1 +22,2 @@ private static cryptImpl; | ||
} | ||
export { authLogger, AGCAuthImpl }; |
@@ -9,5 +9,7 @@ import { AGCApi } from '@agconnect/api-types'; | ||
import { QQAuthProvider } from './internal/provider/QQAuthProvider'; | ||
import { HwIdAuthProvider } from './internal/provider/HwIdAuthProvider'; | ||
import "@agconnect/network"; | ||
import "@agconnect/storage"; | ||
import "@agconnect/util"; | ||
import '@agconnect/log'; | ||
declare module '@agconnect/api-types' { | ||
@@ -21,2 +23,3 @@ interface AGCApi { | ||
QQAuthProvider: typeof QQAuthProvider; | ||
HwIdAuthProvider: typeof HwIdAuthProvider; | ||
Action: typeof Action; | ||
@@ -23,0 +26,0 @@ PhoneUser: typeof PhoneUserImpl; |
@@ -1,2 +0,2 @@ | ||
import e from"@agconnect/api";import{Singleton as t}from"@agconnect/core";import"@agconnect/baseservice";import"@agconnect/instance";import"@agconnect/util";import"@agconnect/network";import"@agconnect/storage"; | ||
import e from"@agconnect/api";import{Singleton as t}from"@agconnect/core";import"@agconnect/baseservice";import"@agconnect/instance";import"@agconnect/util";import{Logger as r}from"@agconnect/log";import"@agconnect/network";import"@agconnect/storage"; | ||
/*! ***************************************************************************** | ||
@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function n(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function o(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(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())}))}function i(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var s,u=function(){function e(){this.providerInfo=new Array}return e.prototype.getProviderInfo=function(){return this.providerInfo},e.prototype.setProviderInfo=function(e){this.providerInfo=e},e.prototype.updateProvider=function(e){if(e&&this.providerInfo){var t=e.provider;t&&this.deleteProvider(t),this.providerInfo.push(e)}},e.prototype.deleteProvider=function(e){var t=this.findProviderIndex(e);this.providerInfo&&null!=t&&this.providerInfo.splice(t,1)},e.prototype.findProviderIndex=function(e){var t=void 0;if(e&&this.providerInfo)for(var r=0;r<this.providerInfo.length;r++){var n=this.providerInfo[r];if(n&&e==n.provider){t=r;break}}return t},e}(),a=function(){function e(e,t,r,n){this.state=void 0,this.expiration=e,this.issuedAt=t,this.notBefore=r,this.tokenString=n}return e.prototype.getState=function(){return this.state},e.prototype.getToken=function(){return this.tokenString},e}(),c=function(){function e(e,t){this.code=t,this.errMsg=e}return e.getMsgByCode=function(t){switch(t){case e.INVALID_EMAIL:return"email can not be null or empty";case e.PASSWORD_IS_EMPTY:return"password can not be null or empty";case e.EMAIL_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty";case e.INVALID_PHONE:return"countrycode and phone can not be null or empty";case e.PHONE_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty"}return""},e.NULL_TOKEN=1,e.NOT_SIGN_IN=2,e.USER_LINKED=3,e.USER_UNLINKED=4,e.ALREADY_SIGN_IN_USER=5,e.EMAIL_VERIFICATION_IS_EMPTY=6,e.PHONE_VERIFICATION_IS_EMPTY=7,e.INVALID_EMAIL=203817223,e.INVALID_PHONE=203817224,e.GET_UID_ERROR=203817728,e.UID_PRODUCTID_NOT_MATCH=203817729,e.GET_USER_INFO_ERROR=203817730,e.AUTH_METHOD_NOT_SUPPORT=203817732,e.PRODUCT_STATUS_ERROR=203817744,e.PASSWORD_VERIFICATION_CODE_OVER_LIMIT=203817811,e.INVALID_TOKEN=203817984,e.INVALID_ACCESS_TOKEN=203817985,e.INVALID_REFRESH_TOKEN=203817986,e.CLIENT_TOKEN_EXPIRED=205524993,e.ACCESS_TOKEN_EXPIRED=205524994,e.TOKEN_AND_PRODUCTID_NOT_MATCH=203817987,e.AUTH_METHOD_IS_DISABLED=203817988,e.FAIL_TO_GET_THIRD_USER_INFO=203817989,e.FAIL_TO_GET_THIRD_USER_UNION_ID=203817990,e.ACCESS_TOKEN_OVER_LIMIT=203817991,e.FAIL_TO_USER_LINK=203817992,e.FAIL_TO_USER_UNLINK=203817993,e.ANONYMOUS_SIGNIN_OVER_LIMIT=203818019,e.INVALID_APPID=203818020,e.INVALID_APPSECRET=203818021,e.GET_QQ_USERINFO_ERROR=203818023,e.QQINFO_RESPONSE_IS_NULL=203818024,e.GET_QQ_UID_ERROR=203818025,e.PASSWORD_VERIFY_CODE_ERROR=203818032,e.GOOGLE_RESPONSE_NOT_EQUAL_APPID=203818033,e.SIGNIN_USER_STATUS_ERROR=203818036,e.SIGNIN_USER_PASSWORD_ERROR=203818037,e.PROVIDER_USER_HAVE_BEEN_LINKED=203818038,e.PROVIDER_HAVE_LINKED_ONE_USER=203818039,e.FAIL_GET_PROVIDER_USER=203818040,e.CANNOT_UNLINK_ONE_PROVIDER_USER=203818041,e.VERIFY_CODE_INTERVAL_LIMIT=203818048,e.VERIFY_CODE_EMPTY=203818049,e.VERIFY_CODE_LANGUAGE_EMPTY=203818050,e.VERIFY_CODE_RECEIVER_EMPTY=203818051,e.VERIFY_CODE_ACTION_ERROR=203818052,e.VERIFY_CODE_TIME_LIMIT=203818053,e.ACCOUNT_PASSWORD_SAME=203818064,e.PASSWORD_STRENGTH_LOW=203818065,e.UPDATE_PASSWORD_ERROR=203818066,e.PASSWORD_SAME_AS_BEFORE=203818067,e.PASSWORD_IS_EMPTY=203818068,e.PASSWORD_TOO_LONG=203818071,e.SENSITIVE_OPERATION_TIMEOUT=203818081,e.ACCOUNT_HAVE_BEEN_REGISTERED=203818082,e.UPDATE_ACCOUNT_ERROR=203818084,e.USER_NOT_REGISTERED=203818087,e.VERIFY_CODE_ERROR=203818129,e.USER_HAVE_BEEN_REGISTERED=203818130,e.REGISTER_ACCOUNT_IS_EMPTY=203818132,e.VERIFY_CODE_FORMAT_ERROR=203818134,e.VERIFY_CODE_AND_PASSWORD_BOTH_NULL=203818135,e.SEND_EMAIL_FAIL=203818240,e.SEND_MESSAGE_FAIL=203818241,e.CONFIG_LOCK_TIME_ERROR=203818261,e}(),p=function(){function t(){this.sdkPlatform="",this.sdkPlatformVersion="",this.packageName="",this.appVersion="",this.headerProductId="",this.headerAppId="",this.headerClientId="",this.agcgwUrl="",this.agcgwBackUrl="",this.sdkServiceName="agconnect-auth",this.sdkVersion="1.2.0";var t,r=e.instance().getService("AGCPlatformInfoService");r&&(this.sdkPlatform=r.getPlatform(),this.sdkPlatformVersion=r.getPlatformVersion(),this.packageName=r.getPackageName(),this.appVersion=r.getAppVersion()),this.accessToken="",this.authorization="",this.headerAaId="";try{t=e.instance().config()}catch(e){return void console.error(e)}this.headerProductId=t.client.product_id,this.headerClientId=t.client.client_id,this.headerAppId=t.client.app_id,this.agcgwUrl=this.addHttpToUrl(t.agcgw.url),this.agcgwBackUrl=this.addHttpToUrl(t.agcgw.backurl)}return t.prototype.getSdkServiceName=function(){return this.sdkServiceName},t.prototype.setSdkServiceName=function(e){this.sdkServiceName=e},t.prototype.getSdkVersion=function(){return this.sdkVersion},t.prototype.setSdkVersion=function(e){this.sdkVersion=e},t.prototype.getSdkPlatform=function(){return this.sdkPlatform},t.prototype.setSdkPlatform=function(e){this.sdkPlatform=e},t.prototype.getSdkPlatformVersion=function(){return this.sdkPlatformVersion},t.prototype.setSdkPlatformVersion=function(e){this.sdkPlatformVersion=e},t.prototype.getPackageName=function(){return this.packageName},t.prototype.setPackageName=function(e){this.packageName=e},t.prototype.getAppVersion=function(){return this.appVersion},t.prototype.setAppVersion=function(e){this.appVersion=e},t.prototype.getHeaderProductId=function(){return this.headerProductId},t.prototype.setHeaderProductId=function(e){this.headerProductId=e},t.prototype.getHeaderAppId=function(){return this.headerAppId},t.prototype.setHeaderAppId=function(e){this.headerAppId=e},t.prototype.getHeaderAaId=function(){return this.headerAaId},t.prototype.setHeaderAaId=function(e){this.headerAaId=e},t.prototype.getHeaderClientId=function(){return this.headerClientId},t.prototype.setHeaderClientId=function(e){this.headerClientId=e},t.prototype.getAuthorization=function(){return this.authorization},t.prototype.setAuthorization=function(e){this.authorization=e},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getAgcgwUrl=function(){return this.agcgwUrl},t.prototype.setAgcgwUrl=function(e){this.agcgwUrl=e},t.prototype.getAgcgwBackUrl=function(){return this.agcgwBackUrl},t.prototype.setAgcgwBackUrl=function(e){this.agcgwBackUrl=e},t.prototype.addHttpToUrl=function(e){return e&&!e.startsWith("https://")?"https://"+e:e},t.prototype.getAuthHeader=function(){return{sdkVersion:this.getSdkVersion(),sdkPlatform:this.getSdkPlatform(),sdkPlatformVersion:this.getSdkPlatformVersion(),packageName:this.getPackageName(),appVersion:this.getAppVersion(),sdkServiceName:this.getSdkServiceName(),app_id:this.getHeaderAppId(),client_id:this.getHeaderClientId(),productId:this.getHeaderProductId(),access_token:this.getAccessToken(),Authorization:this.getAuthorization(),"Content-Type":"application/json;charset=UTF-8"}},t}(),d=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t.SERVER_URL="/agc/apigw/oauth2/third/v1",t}(p),h=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=d.SERVER_URL+"/user-auth/refresh-token",n.useJwt=0,n.refreshToken=t,n.useJwt=r,n}return n(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),f=function(){function e(e,t){void 0===e&&(e=0),void 0===t&&(t=""),this.code=e,this.msg=t}return e.prototype.getCode=function(){return this.code},e.prototype.setCode=function(e){this.code=e},e.prototype.getMsg=function(){return this.msg},e.prototype.setMsg=function(e){this.msg=e},e}(),l=function(){function e(){this.ret=new f}return e.prototype.isSuccess=function(){return null!=this.ret&&0==this.ret.getCode()},e.prototype.getRet=function(){return this.ret},e.prototype.setRet=function(e){this.ret=e},e.prototype.constructResponse=function(e){},e}(),g=function(){function e(){this.token="",this.validPeriod=0}return e.prototype.getToken=function(){return this.token},e.prototype.setToken=function(e){this.token=e},e.prototype.getValidPeriod=function(){return this.validPeriod},e.prototype.setValidPeriod=function(e){this.validPeriod=e},e}(),v=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new g,t.productId="",t.uid="",t}return n(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(l);!function(e){e[e.POST=0]="POST",e[e.GET=1]="GET"}(s||(s={}));var y,I,T,m=function(){function t(){}return t.getClientToken=function(t){return o(this,void 0,void 0,(function(){var r,n;return i(this,(function(o){switch(o.label){case 0:return(r=e.instance().getService("CredentialsService"))?(n="",[4,r.getToken(t).then((function(e){n=e.tokenString}))]):[2,Promise.reject("Get credentialProvider failed.")];case 1:return o.sent(),null==n||""==n?[2,Promise.reject("Get clientToken failed.")]:[2,Promise.resolve(n)]}}))}))},t.post=function(e,r){return o(this,void 0,void 0,(function(){var n,o,u;return i(this,(function(i){switch(i.label){case 0:return n=e.getHeader(),o=n,u="Bearer ",[4,t.getClientToken()];case 1:return o.Authorization=u+i.sent(),[2,this.sendRequest(e,s.POST,r,n,!0,!0)]}}))}))},t.get=function(e,r){return o(this,void 0,void 0,(function(){var n,o,u;return i(this,(function(i){switch(i.label){case 0:return n=e.getHeader(),o=n,u="Bearer ",[4,t.getClientToken()];case 1:return o.Authorization=u+i.sent(),[2,this.sendRequest(e,s.GET,r,n,!0,!0)]}}))}))},t.sendRequest=function(r,n,s,u,a,p){return o(this,void 0,void 0,(function(){var d=this;return i(this,(function(h){switch(h.label){case 0:return[4,this.doNetworkOption(n,r,u,s).then((function(e){return Promise.resolve()})).catch((function(h){return o(d,void 0,void 0,(function(){var o,d,l,g,v;return i(this,(function(i){switch(i.label){case 0:return 401!=h.response.status?[2,Promise.reject(h)]:(o="0x0"+(o=h.response.data.ret.code).toString(16))==c.CLIENT_TOKEN_EXPIRED&&a?(d=e.instance().getService("CredentialsService"))?[4,d.removeToken()]:[2,Promise.reject("Get credentialProvider failed.")]:[3,3];case 1:return i.sent(),l=u,g="Bearer ",[4,t.getClientToken(!0)];case 2:return l.Authorization=g+i.sent(),s.setRet(new f),[2,t.sendRequest(r,n,s,u,!1,p)];case 3:return o==c.ACCESS_TOKEN_EXPIRED&&p?(v=null,[4,e.auth().getCurrentUser().then((function(e){return null==e?Promise.reject("no user sigIn."):(v=e,Promise.resolve())}))]):[3,6];case 4:return i.sent(),[4,v.getToken(!0).then((function(e){u.access_token=e.getToken()}))];case 5:return i.sent(),s.setRet(new f),[2,t.sendRequest(r,n,s,u,a,!1)];case 6:return[2,Promise.reject(h)]}}))}))}))];case 1:return[2,h.sent()]}}))}))},t.doNetworkOption=function(t,r,n,u){return o(this,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return null==(o=e.instance().getService("AGCNetworkService"))?[2,Promise.reject("Get agcNetwork service failed.")]:t!=s.POST?[3,2]:[4,o.post(r.getUrl(),r.getBody(),n).then((function(e){0==e.data.ret.code&&u.constructResponse(e),u.setRet(new f(e.data.ret.code,e.data.ret.msg))})).catch((function(e){return Promise.reject(e)}))];case 1:return i.sent(),[3,4];case 2:return[4,o.get(r.getUrl(),r.getBody(),n).then((function(e){u.constructResponse(e)})).catch((function(e){return Promise.reject(e)}))];case 3:i.sent(),i.label=4;case 4:return[2,Promise.resolve()]}}))}))},t}(),P=function(){function e(){this.accessToken="",this.accessTokenValidPeriod=-1,this.refreshToken="",this.validTime=-1,this.TIME_EARLY=3e5}return e.prototype.constructeSecureTokenService=function(e,t){this.accessToken=e.getToken(),this.accessTokenValidPeriod=e.getValidPeriod(),this.refreshToken=t.getToken(),this.validTime=(new Date).getTime()+1e3*e.getValidPeriod()},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.getRefreshToken=function(){return this.refreshToken},e.prototype.isValidAccessToken=function(){return null!=this.accessToken&&this.remainToRefreshTime()>0},e.prototype.remainToRefreshTime=function(){return this.validTime-(new Date).getTime()-this.TIME_EARLY},e.prototype.fetchAccessToken=function(e){return o(this,void 0,void 0,(function(){var t,r,n,o=this;return i(this,(function(i){switch(i.label){case 0:return!e&&this.isValidAccessToken()?[2,Promise.resolve(new a(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]:this.accessToken&&this.refreshToken?(t=new h(this.refreshToken,1),r=new v,[4,m.post(t,r)]):[2,Promise.reject(new c("Token is null.",c.NULL_TOKEN))];case 1:return i.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:null==(n=r.accessToken)||n.getToken()==this.accessToken&&n.getValidPeriod()==this.accessTokenValidPeriod?[3,3]:(this.accessToken=n.getToken(),this.accessTokenValidPeriod=n.getValidPeriod(),this.validTime=(new Date).getTime()+1e3*this.accessTokenValidPeriod,[4,L.getStoredUser().then((function(e){return e&&(e.tokenService.accessToken=o.accessToken,e.tokenService.accessTokenValidPeriod=o.accessTokenValidPeriod,e.tokenService.refreshToken=o.refreshToken,e.tokenService.validTime=o.validTime),L.updateStoredUser(e)}))]);case 2:i.sent(),i.label=3;case 3:return[2,Promise.resolve(new a(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]}}))}))},e}(),S=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/user-profile",t}return n(t,e),t.prototype.getBody=function(){},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(p),E=function(e){function t(){var t=e.call(this)||this;return t.displayName="",t.photoUrl="",t.emailVerified=0,t.passwordSetted=0,t.email="",t.phone="",t.userExtra=null,t}return n(t,e),t.prototype.constructResponse=function(e){this.displayName=e.data.displayName,this.photoUrl=e.data.photoUrl,this.emailVerified=e.data.emailVerified,this.passwordSetted=e.data.passwordSetted,this.email=e.data.email,this.phone=e.data.phone,this.userExtra=new k,this.userExtra.createTime=e.data.userMetaData.createTime,this.userExtra.lastSignInTime=e.data.userMetaData.lastSignInTime,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(l),k=function(){function e(){this.createTime="",this.lastSignInTime=""}return e.prototype.getCreateTime=function(){return this.createTime},e.prototype.getLastSignInTime=function(){return this.lastSignInTime},e}(),U=function(){function e(e,t){this.token=e,this.expirePeriod=t}return e.prototype.getToken=function(){return this.token},e.prototype.getExpirePeriod=function(){return this.expirePeriod},e}(),R=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/user-link",t.provider=-1,t.token="",t.extraData="",t.useJwt=0,t}return n(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getToken=function(){return this.token},t.prototype.setToken=function(e){this.token=e},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{provider:this.getProvider(),token:this.getToken(),extraData:this.getExtraData(),useJwt:this.getUseJwt()}},t}(d),_=function(){function e(){this.autoCreateUser=!0}return e.prototype.getProvider=function(){return-1},e}(),w=function(){function e(){this.password="",this.verifyCode=""}return e.prototype.getProvider=function(){return-1},e}(),A=function(e){function t(){var t=e.call(this)||this;return t.providerUserInfo=void 0,t}return n(t,e),t.prototype.getProviderUserInfo=function(){return this.providerUserInfo},t.prototype.setProviderUserInfo=function(e){this.providerUserInfo=e},t.prototype.constructResponse=function(e){this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),e.data.providerUserInfo&&this.setProviderUserInfo(e.data.providerUserInfo)},t}(l),N=function(){function e(e){this.user=e}return e.prototype.getUser=function(){return this.user},e}(),C=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/user-unlink",t.provider=-1,t}return n(t,e),t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()+"&provider="+this.getProvider()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{}},t}(d),O=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t}(l),V=function(){function e(){this.anonymous=!1,this.uid="",this.displayName="",this.photoUrl="",this.email="",this.phone="",this.providerId="",this.emailVerified=-1,this.passwordSetted=-1,this.providerService=new u,this.tokenService=new P}return e.prototype.constructFromJson=function(e){this.anonymous=e.anonymous,this.uid=e.uid,this.displayName=e.displayName,this.photoUrl=e.photoUrl,this.email=e.email,this.phone=e.phone,this.providerId=e.providerId,this.emailVerified=e.emailVerified,this.passwordSetted=e.passwordSetted,this.providerService.setProviderInfo(e.providerService.providerInfo),this.tokenService.accessToken=e.tokenService.accessToken,this.tokenService.accessTokenValidPeriod=e.tokenService.accessTokenValidPeriod,this.tokenService.refreshToken=e.tokenService.refreshToken,this.tokenService.validTime=e.tokenService.validTime},e.prototype.isAnonymous=function(){return this.anonymous},e.prototype.getUid=function(){return this.uid},e.prototype.getEmail=function(){return this.email},e.prototype.getPhone=function(){return this.phone},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.getProviderId=function(){return this.providerId},e.prototype.getProviderInfo=function(){for(var e=new Array,t=0;t<this.providerService.getProviderInfo().length;t++){for(var r=new Map,n=Object.keys(this.providerService.getProviderInfo()[t]),o=0;n&&o<n.length;o++)r.set(n[o],this.providerService.getProviderInfo()[t][n[o]]);e.push(r)}return e},e.prototype.getUserExtra=function(){return o(this,void 0,void 0,(function(){var e,t,r,n,o;return i(this,(function(i){switch(i.label){case 0:return e=new B,t=null,r="",[4,e.getCurrentUser().then((function(e){r=e.getAccessToken()}))];case 1:return i.sent(),""==r?[3,3]:(n=new S,o=new E,n.setAccessToken(r),[4,m.get(n,o).then((function(e){console.log("getUserExtra success.")})).catch((function(e){console.error("getUserExtra fail."+e)}))]);case 2:if(i.sent(),0!=o.getRet().getCode())return[2,Promise.reject(o.getRet())];this.displayName=o.displayName,this.photoUrl=o.photoUrl,this.emailVerified=o.emailVerified,this.passwordSetted=o.passwordSetted,this.email=o.email,this.phone=o.phone,this.displayName=o.displayName,t=o.userExtra,L.updateStoredUser(this),i.label=3;case 3:return[2,Promise.resolve(t)]}}))}))},e.prototype.getAccessToken=function(){return this.tokenService.getAccessToken()},e.prototype.getRefreshToken=function(){return this.tokenService.getRefreshToken()},e.prototype.buildUser=function(e){this.anonymous=!1,this.uid=e.getUserInfo().getUid(),this.displayName=e.getUserInfo().getDisplayName(),this.photoUrl=e.getUserInfo().getPhotoUrl(),this.email=e.getUserInfo().getEmail(),this.emailVerified=e.getUserInfo().getEmailVerified(),this.passwordSetted=e.getUserInfo().getPasswordSetted(),this.phone=e.getUserInfo().getPhone(),this.providerId=e.getUserInfo().getProvider().toString(),this.tokenService.constructeSecureTokenService(e.getAccessToken(),e.getRefreshToken()),this.providerService.setProviderInfo(e.getProviders())},e.prototype.getToken=function(e){return this.tokenService.fetchAccessToken(e).then((function(e){return Promise.resolve(new U(e.tokenString,parseInt(e.expiration)))})).catch((function(e){return Promise.reject(e)}))},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.link=function(e){return o(this,void 0,void 0,(function(){var t,r,n,o,s,u,a,c,p;return i(this,(function(i){switch(i.label){case 0:if(!e)return[2,Promise.reject("credential cannot be null or undefined")];if(t=new R,e instanceof _)e.prepareUserLinkRequest(t);else{if(!(e instanceof w))return[2,Promise.reject("credential type error")];e.prepareUserLinkRequest(t)}return[4,this.getToken(!1)];case 1:return r=i.sent(),t.setAccessToken(r.getToken()),n=new A,[4,m.post(t,n)];case 2:return i.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return(o=n.getProviderUserInfo())&&(s={},this.userInfoToMap(o,s),this.anonymous&&this.updateAnonymousUserInfo(s),this.providerService.updateProvider(s),s.provider&&(u=s.provider,12..toString()==u?(a=s.email)&&(this.email=a):11..toString()==u&&(c=s.phone)&&(this.phone=c))),[4,L.updateStoredUser(this)];case 4:return i.sent(),[4,L.getStoredUser()];case 5:return p=i.sent(),[2,Promise.resolve(new N(p))]}}))}))},e.prototype.unlink=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(t){return e?this.anonymous?[2,Promise.reject(new f(c.USER_UNLINKED,"anonymous user can not unlink"))]:[2,this.sendUnlinkRequest(e)]:[2,Promise.reject("credentialProvider cannot be null or undefined")]}))}))},e.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},e.prototype.updateAnonymousUserInfo=function(e){this.anonymous=!1,this.displayName=e.displayName?e.displayName:"",this.photoUrl=e.photoUrl?e.photoUrl:"",this.email=e.email?e.email:"",this.phone=e.phone?e.phone:"",this.providerId=e.provider?e.provider:""},e.prototype.sendUnlinkRequest=function(e){return o(this,void 0,void 0,(function(){var t,r,n,o;return i(this,(function(i){switch(i.label){case 0:return(t=new C).setProvider(e),[4,this.getToken(!1)];case 1:return r=i.sent(),t.setAccessToken(r.getToken()),n=new O,[4,m.post(t,n)];case 2:return i.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return this.providerService.deleteProvider(e.toString()),12==e&&(this.email=""),11==e&&(this.phone=""),[4,L.updateStoredUser(this)];case 4:return i.sent(),[4,L.getStoredUser()];case 5:return o=i.sent(),[2,Promise.resolve(new N(o))]}}))}))},e}(),D=function(){function t(){this.storageImpl=void 0}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.getStorage=function(){var t=e.instance().getService("AGCStorageService");if(null!=t)return this.storageImpl||(this.storageImpl=t.getStorageNewInstance(Number(B.getUserInfoPersistence()),B.getCryptImp()?B.getCryptImp():e.instance().getCryptImp())),this.storageImpl;console.error("Get AGC storage Service failed.")},t}(),L=function(){function t(){this.user=null}return t.constructUserKey=function(){if(null==t.USER_KEY){var r=void 0;try{r=e.instance().config()}catch(e){return void console.error(e)}t.USER_KEY="agcCurrentUser:"+r.client.client_id}},t.loadStoredUser=function(){return o(this,void 0,void 0,(function(){var e;return i(this,(function(r){switch(r.label){case 0:return t.constructUserKey(),null==(e=D.getInstance().getStorage())?[2,Promise.reject("get agcStorage failed.")]:[4,e.get(t.USER_KEY).then((function(e){null!=e&&null!=e&&""!=e&&(t.INSTANCE.user=new V,t.INSTANCE.user.constructFromJson(JSON.parse(e)))})).catch((function(e){console.error("----loadStoredUser error ",e)}))];case 1:return r.sent(),[2,Promise.resolve()]}}))}))},t.getStoredUser=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return null!=t.INSTANCE.user?[3,2]:[4,this.loadStoredUser().then((function(e){}))];case 1:e.sent(),e.label=2;case 2:return[2,Promise.resolve(t.INSTANCE.user)]}}))}))},t.updateStoredUser=function(e){return o(this,void 0,void 0,(function(){return i(this,(function(r){switch(r.label){case 0:return t.INSTANCE.user=e,[4,t.saveCurrentUser()];case 1:return r.sent(),[2]}}))}))},t.saveCurrentUser=function(){return o(this,void 0,void 0,(function(){var e;return i(this,(function(r){switch(r.label){case 0:return t.constructUserKey(),null==(e=D.getInstance().getStorage())?[2]:null!=t.INSTANCE.user?[3,2]:[4,e.remove(t.USER_KEY)];case 1:return r.sent(),[3,4];case 2:return[4,e.set(t.USER_KEY,JSON.stringify(t.INSTANCE.user))];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))},t.INSTANCE=new t,t}(),b=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.URL=d.SERVER_URL+"/user-signin-anonymous",i.useJwt=0,i.provider=t,i.token=r,i.extraData=n,i.useJwt=o,i}return n(t,e),t.prototype.getBody=function(){return{provider:0,token:this.token,extraData:"",useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),H=function(e){function t(){var t=e.call(this)||this;return t.accessToken=new g,t.refreshToken=new g,t.uid="",t}return n(t,e),t.prototype.constructResponse=function(e){this.uid=e.data.uid,this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getUid=function(){return this.uid},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t}(l),M=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=d.SERVER_URL+"/user-signout",n.bodyAccessToken=t,n.refreshToken=r,n}return n(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,accessToken:this.bodyAccessToken}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(p),x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return n(t,e),t}(l),G=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/user-delete",t}return n(t,e),t.prototype.getBody=function(){return""},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(p),j=function(e){function t(t,r,n,o,i){var s=e.call(this)||this;return s.URL=d.SERVER_URL+"/user-register",s.provider=-1,s.useJwt=0,s.email=t,s.phone=r,s.password=n,s.verifyCode=o,s.useJwt=i,s}return n(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getVerifyCode=function(){return this.verifyCode},t.prototype.setVerifyCode=function(e){this.verifyCode=e},t.prototype.getPassword=function(){return this.password},t.prototype.setPassword=function(e){this.password=e},t.prototype.getBody=function(){return{phone:this.phone,provider:this.provider,email:this.email,password:this.password,verifyCode:this.verifyCode,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),J=function(){function e(){this.uid="",this.displayName="",this.photoUrl="",this.phone="",this.email="",this.provider=-1,this.openId="",this.emailVerified=-1,this.passwordSetted=-1}return e.prototype.getUid=function(){return this.uid},e.prototype.setUid=function(e){this.uid=e},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.setDisplayName=function(e){this.displayName=e},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.setPhotoUrl=function(e){this.photoUrl=e},e.prototype.getPhone=function(){return this.phone},e.prototype.setPhone=function(e){this.phone=e},e.prototype.getEmail=function(){return this.email},e.prototype.setEmail=function(e){this.email=e},e.prototype.getProvider=function(){return this.provider},e.prototype.setProvider=function(e){this.provider=e},e.prototype.getOpenId=function(){return this.openId},e.prototype.setOpenId=function(e){this.openId=e},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.setEmailVerified=function(e){this.emailVerified=e},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.setPasswordSetted=function(e){this.passwordSetted=e},e}(),Y=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new g,t.refreshToken=new g,t.userInfo=new J,t.providers=[],t}return n(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.setRefreshToken=function(e){this.refreshToken=e},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(l),F=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/user-signin",t.provider=-1,t.token="",t.extraData="",t.autoCreateUser=-1,t.useJwt=0,t.verifyCode="",t}return n(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.getToken=function(){return this.token},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.isAutoCreateUser=function(){return this.autoCreateUser},t.prototype.setAutoCreateUser=function(e){this.autoCreateUser=e},t.prototype.setProvider=function(e){this.provider=e},t.prototype.setToken=function(e){this.token=e},t.prototype.getBody=function(){return{provider:this.provider,token:this.token,extraData:this.extraData,autoCreateUser:this.autoCreateUser,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new g,t.refreshToken=new g,t.userInfo=new J,t.providers=[],t}return n(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(l),B=function(){function t(){}return t.prototype.createEmailUser=function(e){return o(this,void 0,void 0,(function(){var t,r,n,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=i.sent())||t.isAnonymous()?e?0!=(r=e.verifyEmailUser(!1))?[2,Promise.reject(new f(r,c.getMsgByCode(r)))]:((n=new j(e.email,"",e.password,e.verifyCode,1)).setProvider(12),o=new Y,[4,m.post(n,o)]):[2,Promise.reject(new f(c.INVALID_EMAIL,"emailUser invalid"))]:[2,Promise.reject(new f(c.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return i.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((s=new V).buildUser(o),L.updateStoredUser(s),[2,Promise.resolve(new N(s))])}}))}))},t.prototype.createPhoneUser=function(e){return o(this,void 0,void 0,(function(){var t,r,n,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=i.sent())||t.isAnonymous()?e?0!=(r=e.verifyPhoneUser(!1))?[2,Promise.reject(new f(r,c.getMsgByCode(r)))]:((n=new j("",e.getPhone(),e.password,e.verifyCode,1)).setProvider(11),o=new Y,[4,m.post(n,o)]):[2,Promise.reject(new f(c.INVALID_PHONE,"phoneUser invalid"))]:[2,Promise.reject(new f(c.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return i.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((s=new V).buildUser(o),L.updateStoredUser(s),[2,Promise.resolve(new N(s))])}}))}))},t.prototype.signIn=function(e){return o(this,void 0,void 0,(function(){var t,r=this;return i(this,(function(n){switch(n.label){case 0:if(!e)throw new Error("credential invalid");return[4,this.getCurrentUser()];case 1:return null==(t=n.sent())||t.isAnonymous()?[2,new Promise((function(t,n){r.getUserWithCredential(e).then((function(e){t(e)})).catch((function(e){n(e)}))}))]:[2,Promise.reject(new f(c.ALREADY_SIGN_IN_USER,"already sign in a user"))]}}))}))},t.prototype.getUserWithCredential=function(e){return o(this,void 0,void 0,(function(){var t,r,n;return i(this,(function(o){switch(o.label){case 0:if(t=new F,e instanceof _)e.prepareUserAuthRequest(t),t.setAutoCreateUser(e.autoCreateUser?1:0);else{if(!(e instanceof w))throw new Error("credential type error");e.prepareUserAuthRequest(t)}return t.setUseJwt(1),r=new q,[4,m.post(t,r)];case 1:return o.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:((n=new V).buildUser(r),L.updateStoredUser(n),[2,Promise.resolve(new N(n))])}}))}))},t.prototype.deleteUser=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return o(this,void 0,void 0,(function(){var t,r,n,s=this;return i(this,(function(u){switch(u.label){case 0:return null==e?[3,2]:(t=e,r=new G,n=new x,r.setAccessToken(t.getAccessToken()),[4,m.post(r,n).then((function(e){return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return console.log("deleteUser success."),[4,L.updateStoredUser(null)];case 1:return e.sent(),[2]}}))}))})).catch((function(e){console.error("deleteUser fail.",e.response)}))]);case 1:u.sent(),u.label=2;case 2:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},t.prototype.signOut=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return o(this,void 0,void 0,(function(){var t,r,n;return i(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(r=new M((t=e).getAccessToken(),t.getRefreshToken()),n=new x,[4,m.post(r,n).then((function(e){console.log("signOut success.")})).catch((function(e){console.error("signOut fail."+e)}))]);case 1:return o.sent(),[4,L.updateStoredUser(null)];case 2:o.sent(),o.label=3;case 3:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},t.prototype.getCurrentUser=function(){return L.getStoredUser()},t.prototype.signInAnonymously=function(){var e=this;return this.getCurrentUser().then((function(t){if(null!=t){if(t.isAnonymous()){var r=new N(t);return Promise.resolve(r)}return Promise.reject(new f(c.ALREADY_SIGN_IN_USER,"already sign in a user"))}return e.getUserWithAnonymously()})).catch((function(e){return Promise.reject(e)}))},t.prototype.getUserWithAnonymously=function(){return o(this,void 0,void 0,(function(){var t,r,n,o,s;return i(this,(function(i){switch(i.label){case 0:return null==(t=e.instance().getService("ClientInfoService"))?[2,Promise.reject("Get clientInfoUtil service failed.")]:(r="",[4,t.getAaid().then((function(e){r=e}))]);case 1:return i.sent(),r?(n=new b(0,r,"",1),o=new H,[4,m.post(n,o)]):[2,Promise.reject("The aaid is null.")];case 2:return i.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((s=new V).uid=o.getUid(),s.providerId=(0).toString(),s.tokenService.constructeSecureTokenService(o.getAccessToken(),o.getRefreshToken()),s.anonymous=!0,[4,L.updateStoredUser(s)]);case 3:return i.sent(),[2,Promise.resolve(new N(s))]}}))}))},t.prototype.setUserInfoPersistence=function(e){t.persistence=e},t.getUserInfoPersistence=function(){return t.persistence},t.prototype.setCryptImp=function(e){return e?e.decrypt&&e.encrypt?(t.cryptImpl=e,!0):(console.error("the crypt is not exist necessary methods."),!1):(console.error("the crypt is not available."),!1)},t.getCryptImp=function(){return t.cryptImpl},t.persistence=2,t.cryptImpl=void 0,t}(),W=function(){function e(){}return e.combinatePhone=function(e,t){return null==e||e.startsWith("+")||(e="+"+e),e+"-"+t},e}(),K=function(){function e(e,t,r,n){this.countryCode="",this.phoneNumber="",this.password="",this.verifyCode="",this.countryCode=e,this.phoneNumber=t,this.password=r,this.verifyCode=n}return e.prototype.getPhone=function(){return W.combinatePhone(this.countryCode,this.phoneNumber)},e.prototype.verifyPhoneUser=function(e){return""==this.phoneNumber?c.INVALID_EMAIL:""==this.password&&e?c.PASSWORD_IS_EMPTY:""==this.verifyCode?c.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),z=function(){function e(e,t,r){this.email="",this.password="",this.verifyCode="",this.email=e,this.password=t,this.verifyCode=r}return e.prototype.verifyEmailUser=function(e){return""==this.email?c.INVALID_EMAIL:""==this.password&&e?c.PASSWORD_IS_EMPTY:""==this.verifyCode?c.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),Q=function(e){function t(t,r,n){var o=e.call(this)||this;return o.email=t,o.password=r,o.verifyCode=n,o}return n(t,e),t.prototype.getProvider=function(){return 12},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t}(w),X=function(){function e(e,t,r){this.action=e,this.lang=t,this.sendInterval=r}return e.prototype.getAction=function(){return this.action},e.prototype.getLang=function(){return this.lang},e.prototype.getSendInterval=function(){return this.sendInterval},e.prototype.setAction=function(e){this.action=e},e.prototype.setLang=function(e){this.lang=e},e.prototype.setSendInterval=function(e){this.sendInterval=e},e}(),Z=function(){function e(e,t){this.shortestInterval=e,this.validityPeriod=t}return e.prototype.getShortestInterval=function(){return this.shortestInterval},e.prototype.getValidityPeriod=function(){return this.validityPeriod},e}(),$=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=d.SERVER_URL+"/verify-code",t.phone="",t.email="",t.action=-1,t.lang="",t.sendInterval=-1,t}return n(t,e),t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getAction=function(){return this.action},t.prototype.setAction=function(e){this.action=e},t.prototype.getLang=function(){return this.lang},t.prototype.setLang=function(e){this.lang=e},t.prototype.getSendInterval=function(){return this.sendInterval},t.prototype.setSendInterval=function(e){this.sendInterval=e},t.prototype.getBody=function(){return{phone:this.phone,email:this.email,lang:this.lang,action:this.action,sendInterval:this.sendInterval}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),ee=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.shortestInterval="",t.validityPeriod="",t}return n(t,e),t.prototype.constructResponse=function(e){this.shortestInterval=e.data.shortestInterval,this.validityPeriod=e.data.validityPeriod,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getShortestInterval=function(){return this.shortestInterval},t.prototype.setShortestInterval=function(e){this.shortestInterval=e},t.prototype.getValidityPeriod=function(){return this.validityPeriod},t.prototype.setValidityPeriod=function(e){this.validityPeriod=e},t}(l),te=function(){function e(){}return e.requestEmailVerifyCode=function(e,t){var r=this.buildRequest(e,"",t);return this.requestVerifyCode(r)},e.requestPhoneVerifyCode=function(e,t,r){var n=W.combinatePhone(e,t),o=this.buildRequest("",n,r);return this.requestVerifyCode(o)},e.requestVerifyCode=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(r){switch(r.label){case 0:return t=new ee,[4,m.post(e,t)];case 1:return r.sent(),0!=t.getRet().getCode()?[2,Promise.reject(t.getRet())]:[2,Promise.resolve(new Z(t.getShortestInterval(),t.getValidityPeriod()))]}}))}))},e.buildRequest=function(e,t,r){if(null==r)throw new Error("invalid verifyCodeSettings.");var n=new $;return n.setEmail(e),n.setPhone(t),n.setAction(r.getAction()),n.setLang(r.getLang()),n.setSendInterval(r.getSendInterval()),n},e}(),re=function(){function e(){}return e.credentialWithPassword=function(e,t){return new Q(e,t,"")},e.credentialWithVerifyCode=function(e,t,r){return new Q(e,t,r)},e.requestVerifyCode=function(e,t,r,n){return te.requestEmailVerifyCode(e,new X(t,r,n))},e}(),ne=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.countryCode=t,i.phoneNumber=r,i.password=n,i.verifyCode=o,i}return n(t,e),t.prototype.getProvider=function(){return 11},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t.prototype.getPhone=function(){return W.combinatePhone(this.countryCode,this.phoneNumber)},t}(w),oe=function(){function e(){}return e.credentialWithPassword=function(e,t,r){return new ne(e,t,r,"")},e.credentialWithVerifyCode=function(e,t,r,n){return new ne(e,t,r,n)},e.requestVerifyCode=function(e,t,r,n,o){return te.requestPhoneVerifyCode(e,t,new X(r,n,o))},e}(),ie=function(e){function t(t,r,n){var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return n(t,e),t.prototype.getProvider=function(){return 4},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(_),se=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ie(e,t,r)},e}(),ue=function(e){function t(t,r,n){void 0===n&&(n=!0);var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return n(t,e),t.prototype.getProvider=function(){return 6},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(_),ae=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ue(e,t,r)},e}(),ce=function(){function t(){}return t.prototype.getToken=function(t){return o(this,void 0,void 0,(function(){var r,n,o;return i(this,(function(i){switch(i.label){case 0:return e.instance().getCustomAuthProvider()?[4,e.instance().getCustomAuthProvider().getToken(t)]:[3,2];case 1:return(r=i.sent())&&r.tokenString&&r.expiration?isNaN(Number(r.expiration))||Number(r.expiration)<=0?(console.error("the customAuthProvider getToken must return valid expiration."),[2,Promise.reject("the customAuthProvider getToken must return valid expiration.")]):(n=new(function(){function e(){}return e.prototype.getExpirePeriod=function(){return Number(r.expiration)},e.prototype.getToken=function(){return r.tokenString},e}()),[2,Promise.resolve(n)]):(console.error("the customAuthProvider getToken method must contain return value: tokenString, expiration."),[2,Promise.reject("the customAuthProvider getToken method must contain return value: tokenString, expiration.")]);case 2:return[4,L.getStoredUser()];case 3:return(o=i.sent())?[2,o.getToken(t)]:[2,Promise.resolve(null)]}}))}))},t}(),pe=new t((function(){return new B}));function de(e){return new ce}!function(e){e[e.ACTION_REGISTER_LOGIN=1001]="ACTION_REGISTER_LOGIN",e[e.ACTION_RESET_PASSWORD=1002]="ACTION_RESET_PASSWORD"}(y||(y={})),T={PhoneUser:K,EmailUser:z,EmailAuthProvider:re,PhoneAuthProvider:oe,WeixinAuthProvider:se,QQAuthProvider:ae,Action:y},(I=e).registerApiProvider("auth",(function(){return pe.get()}),T),I.registerInternalService({name:"AuthProviderService",serviceFactory:de}); | ||
***************************************************************************** */var n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function o(e,t){function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function i(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(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())}))}function s(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var u,a=function(){function e(){this.providerInfo=new Array}return e.prototype.getProviderInfo=function(){return this.providerInfo},e.prototype.setProviderInfo=function(e){this.providerInfo=e},e.prototype.updateProvider=function(e){if(e&&this.providerInfo){var t=e.provider;t&&this.deleteProvider(t),this.providerInfo.push(e)}},e.prototype.deleteProvider=function(e){var t=this.findProviderIndex(e);this.providerInfo&&null!=t&&this.providerInfo.splice(t,1)},e.prototype.findProviderIndex=function(e){var t=void 0;if(e&&this.providerInfo)for(var r=0;r<this.providerInfo.length;r++){var n=this.providerInfo[r];if(n&&e==n.provider){t=r;break}}return t},e}(),c=function(){function e(e,t,r,n){this.state=void 0,this.expiration=e,this.issuedAt=t,this.notBefore=r,this.tokenString=n}return e.prototype.getState=function(){return this.state},e.prototype.getToken=function(){return this.tokenString},e}(),p=function(){function e(e,t){this.code=t,this.errMsg=e}return e.getMsgByCode=function(t){switch(t){case e.INVALID_EMAIL:return"email can not be null or empty";case e.PASSWORD_IS_EMPTY:return"password can not be null or empty";case e.EMAIL_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty";case e.INVALID_PHONE:return"countrycode and phone can not be null or empty";case e.PHONE_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty"}return""},e.NULL_TOKEN=1,e.NOT_SIGN_IN=2,e.USER_LINKED=3,e.USER_UNLINKED=4,e.ALREADY_SIGN_IN_USER=5,e.EMAIL_VERIFICATION_IS_EMPTY=6,e.PHONE_VERIFICATION_IS_EMPTY=7,e.INVALID_EMAIL=203817223,e.INVALID_PHONE=203817224,e.GET_UID_ERROR=203817728,e.UID_PRODUCTID_NOT_MATCH=203817729,e.GET_USER_INFO_ERROR=203817730,e.AUTH_METHOD_NOT_SUPPORT=203817732,e.PRODUCT_STATUS_ERROR=203817744,e.PASSWORD_VERIFICATION_CODE_OVER_LIMIT=203817811,e.INVALID_TOKEN=203817984,e.INVALID_ACCESS_TOKEN=203817985,e.INVALID_REFRESH_TOKEN=203817986,e.CLIENT_TOKEN_EXPIRED=205524993,e.ACCESS_TOKEN_EXPIRED=205524994,e.TOKEN_AND_PRODUCTID_NOT_MATCH=203817987,e.AUTH_METHOD_IS_DISABLED=203817988,e.FAIL_TO_GET_THIRD_USER_INFO=203817989,e.FAIL_TO_GET_THIRD_USER_UNION_ID=203817990,e.ACCESS_TOKEN_OVER_LIMIT=203817991,e.FAIL_TO_USER_LINK=203817992,e.FAIL_TO_USER_UNLINK=203817993,e.ANONYMOUS_SIGNIN_OVER_LIMIT=203818019,e.INVALID_APPID=203818020,e.INVALID_APPSECRET=203818021,e.GET_QQ_USERINFO_ERROR=203818023,e.QQINFO_RESPONSE_IS_NULL=203818024,e.GET_QQ_UID_ERROR=203818025,e.PASSWORD_VERIFY_CODE_ERROR=203818032,e.GOOGLE_RESPONSE_NOT_EQUAL_APPID=203818033,e.SIGNIN_USER_STATUS_ERROR=203818036,e.SIGNIN_USER_PASSWORD_ERROR=203818037,e.PROVIDER_USER_HAVE_BEEN_LINKED=203818038,e.PROVIDER_HAVE_LINKED_ONE_USER=203818039,e.FAIL_GET_PROVIDER_USER=203818040,e.CANNOT_UNLINK_ONE_PROVIDER_USER=203818041,e.VERIFY_CODE_INTERVAL_LIMIT=203818048,e.VERIFY_CODE_EMPTY=203818049,e.VERIFY_CODE_LANGUAGE_EMPTY=203818050,e.VERIFY_CODE_RECEIVER_EMPTY=203818051,e.VERIFY_CODE_ACTION_ERROR=203818052,e.VERIFY_CODE_TIME_LIMIT=203818053,e.ACCOUNT_PASSWORD_SAME=203818064,e.PASSWORD_STRENGTH_LOW=203818065,e.UPDATE_PASSWORD_ERROR=203818066,e.PASSWORD_SAME_AS_BEFORE=203818067,e.PASSWORD_IS_EMPTY=203818068,e.PASSWORD_TOO_LONG=203818071,e.SENSITIVE_OPERATION_TIMEOUT=203818081,e.ACCOUNT_HAVE_BEEN_REGISTERED=203818082,e.UPDATE_ACCOUNT_ERROR=203818084,e.USER_NOT_REGISTERED=203818087,e.VERIFY_CODE_ERROR=203818129,e.USER_HAVE_BEEN_REGISTERED=203818130,e.REGISTER_ACCOUNT_IS_EMPTY=203818132,e.VERIFY_CODE_FORMAT_ERROR=203818134,e.VERIFY_CODE_AND_PASSWORD_BOTH_NULL=203818135,e.SEND_EMAIL_FAIL=203818240,e.SEND_MESSAGE_FAIL=203818241,e.CONFIG_LOCK_TIME_ERROR=203818261,e}(),d=function(){function t(){this.sdkPlatform="",this.sdkPlatformVersion="",this.packageName="",this.appVersion="",this.headerProductId="",this.headerAppId="",this.headerClientId="",this.agcgwUrl="",this.agcgwBackUrl="",this.sdkServiceName="agconnect-auth",this.sdkVersion="1.2.1-beta";var t,r=e.instance().getService("AGCPlatformInfoService");r&&(this.sdkPlatform=r.getPlatform(),this.sdkPlatformVersion=r.getPlatformVersion(),this.packageName=r.getPackageName(),this.appVersion=r.getAppVersion()),this.accessToken="",this.authorization="",this.headerAaId="";try{t=e.instance().config()}catch(e){return void W.error(e)}this.headerProductId=t.client.product_id,this.headerClientId=t.client.client_id,this.headerAppId=t.client.app_id,this.agcgwUrl=this.addHttpToUrl(t.agcgw.url),this.agcgwBackUrl=this.addHttpToUrl(t.agcgw.backurl)}return t.prototype.getSdkServiceName=function(){return this.sdkServiceName},t.prototype.setSdkServiceName=function(e){this.sdkServiceName=e},t.prototype.getSdkVersion=function(){return this.sdkVersion},t.prototype.setSdkVersion=function(e){this.sdkVersion=e},t.prototype.getSdkPlatform=function(){return this.sdkPlatform},t.prototype.setSdkPlatform=function(e){this.sdkPlatform=e},t.prototype.getSdkPlatformVersion=function(){return this.sdkPlatformVersion},t.prototype.setSdkPlatformVersion=function(e){this.sdkPlatformVersion=e},t.prototype.getPackageName=function(){return this.packageName},t.prototype.setPackageName=function(e){this.packageName=e},t.prototype.getAppVersion=function(){return this.appVersion},t.prototype.setAppVersion=function(e){this.appVersion=e},t.prototype.getHeaderProductId=function(){return this.headerProductId},t.prototype.setHeaderProductId=function(e){this.headerProductId=e},t.prototype.getHeaderAppId=function(){return this.headerAppId},t.prototype.setHeaderAppId=function(e){this.headerAppId=e},t.prototype.getHeaderAaId=function(){return this.headerAaId},t.prototype.setHeaderAaId=function(e){this.headerAaId=e},t.prototype.getHeaderClientId=function(){return this.headerClientId},t.prototype.setHeaderClientId=function(e){this.headerClientId=e},t.prototype.getAuthorization=function(){return this.authorization},t.prototype.setAuthorization=function(e){this.authorization=e},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getAgcgwUrl=function(){return this.agcgwUrl},t.prototype.setAgcgwUrl=function(e){this.agcgwUrl=e},t.prototype.getAgcgwBackUrl=function(){return this.agcgwBackUrl},t.prototype.setAgcgwBackUrl=function(e){this.agcgwBackUrl=e},t.prototype.addHttpToUrl=function(e){return e&&!e.startsWith("https://")?"https://"+e:e},t.prototype.getAuthHeader=function(){return{sdkVersion:this.getSdkVersion(),sdkPlatform:this.getSdkPlatform(),sdkPlatformVersion:this.getSdkPlatformVersion(),packageName:this.getPackageName(),appVersion:this.getAppVersion(),sdkServiceName:this.getSdkServiceName(),app_id:this.getHeaderAppId(),client_id:this.getHeaderClientId(),productId:this.getHeaderProductId(),access_token:this.getAccessToken(),Authorization:this.getAuthorization(),"Content-Type":"application/json;charset=UTF-8"}},t}(),h=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.SERVER_URL="/agc/apigw/oauth2/third/v1",t}(d),f=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=h.SERVER_URL+"/user-auth/refresh-token",n.useJwt=0,n.refreshToken=t,n.useJwt=r,n}return o(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),l=function(){function e(e,t){void 0===e&&(e=0),void 0===t&&(t=""),this.code=e,this.msg=t}return e.prototype.getCode=function(){return this.code},e.prototype.setCode=function(e){this.code=e},e.prototype.getMsg=function(){return this.msg},e.prototype.setMsg=function(e){this.msg=e},e}(),g=function(){function e(){this.ret=new l}return e.prototype.isSuccess=function(){return null!=this.ret&&0==this.ret.getCode()},e.prototype.getRet=function(){return this.ret},e.prototype.setRet=function(e){this.ret=e},e.prototype.constructResponse=function(e){},e}(),v=function(){function e(){this.token="",this.validPeriod=0}return e.prototype.getToken=function(){return this.token},e.prototype.setToken=function(e){this.token=e},e.prototype.getValidPeriod=function(){return this.validPeriod},e.prototype.setValidPeriod=function(e){this.validPeriod=e},e}(),y=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new v,t.productId="",t.uid="",t}return o(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(g);!function(e){e[e.POST=0]="POST",e[e.GET=1]="GET"}(u||(u={}));var I,m,T,P=function(){function t(){}return t.getClientToken=function(t){return i(this,void 0,void 0,(function(){var r,n;return s(this,(function(o){switch(o.label){case 0:return(r=e.instance().getService("CredentialsService"))?(n="",[4,r.getToken(t).then((function(e){n=e.tokenString}))]):[2,Promise.reject("Get credentialProvider failed.")];case 1:return o.sent(),[2,Promise.resolve(n)]}}))}))},t.post=function(e,r){return i(this,void 0,void 0,(function(){var n,o,i;return s(this,(function(s){switch(s.label){case 0:return n=e.getHeader(),o=n,i="Bearer ",[4,t.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(e,u.POST,r,n,!0,!0)]}}))}))},t.get=function(e,r){return i(this,void 0,void 0,(function(){var n,o,i;return s(this,(function(s){switch(s.label){case 0:return n=e.getHeader(),o=n,i="Bearer ",[4,t.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(e,u.GET,r,n,!0,!0)]}}))}))},t.sendRequest=function(r,n,o,u,a,c){return i(this,void 0,void 0,(function(){var d=this;return s(this,(function(h){switch(h.label){case 0:return[4,this.doNetworkOption(n,r,u,o).then((function(e){return Promise.resolve()})).catch((function(h){return i(d,void 0,void 0,(function(){var i,d,f,g,v;return s(this,(function(s){switch(s.label){case 0:return 401!=h.response.status?[2,Promise.reject(h)]:(i="0x0"+(i=h.response.data.ret.code).toString(16))==p.CLIENT_TOKEN_EXPIRED&&a?(d=e.instance().getService("CredentialsService"))?[4,d.removeToken()]:[2,Promise.reject("Get credentialProvider failed.")]:[3,3];case 1:return s.sent(),f=u,g="Bearer ",[4,t.getClientToken(!0)];case 2:return f.Authorization=g+s.sent(),o.setRet(new l),[2,t.sendRequest(r,n,o,u,!1,c)];case 3:return i==p.ACCESS_TOKEN_EXPIRED&&c?(v=null,[4,e.auth().getCurrentUser().then((function(e){return null==e?Promise.reject("no user sigIn."):(v=e,Promise.resolve())}))]):[3,6];case 4:return s.sent(),[4,v.getToken(!0).then((function(e){u.access_token=e.getToken()}))];case 5:return s.sent(),o.setRet(new l),[2,t.sendRequest(r,n,o,u,a,!1)];case 6:return[2,Promise.reject(h)]}}))}))}))];case 1:return[2,h.sent()]}}))}))},t.doNetworkOption=function(t,r,n,o){return i(this,void 0,void 0,(function(){var i;return s(this,(function(s){switch(s.label){case 0:return null==(i=e.instance().getService("AGCNetworkService"))?[2,Promise.reject("Get agcNetwork service failed.")]:t!=u.POST?[3,2]:[4,i.post(r.getUrl(),r.getBody(),n).then((function(e){0==e.data.ret.code&&o.constructResponse(e),o.setRet(new l(e.data.ret.code,e.data.ret.msg))})).catch((function(e){return Promise.reject(e)}))];case 1:return s.sent(),[3,4];case 2:return[4,i.get(r.getUrl(),r.getBody(),n).then((function(e){o.constructResponse(e)})).catch((function(e){return Promise.reject(e)}))];case 3:s.sent(),s.label=4;case 4:return[2,Promise.resolve()]}}))}))},t}(),S=function(){function e(){this.accessToken="",this.accessTokenValidPeriod=-1,this.refreshToken="",this.validTime=-1,this.TIME_EARLY=3e5}return e.prototype.constructeSecureTokenService=function(e,t){this.accessToken=e.getToken(),this.accessTokenValidPeriod=e.getValidPeriod(),this.refreshToken=t.getToken(),this.validTime=(new Date).getTime()+1e3*e.getValidPeriod()},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.getRefreshToken=function(){return this.refreshToken},e.prototype.isValidAccessToken=function(){return null!=this.accessToken&&this.remainToRefreshTime()>0},e.prototype.remainToRefreshTime=function(){return this.validTime-(new Date).getTime()-this.TIME_EARLY},e.prototype.fetchAccessToken=function(e){return i(this,void 0,void 0,(function(){var t,r,n,o=this;return s(this,(function(i){switch(i.label){case 0:return!e&&this.isValidAccessToken()?[2,Promise.resolve(new c(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]:this.accessToken&&this.refreshToken?(t=new f(this.refreshToken,1),r=new y,[4,P.post(t,r)]):[2,Promise.reject(new p("Token is null.",p.NULL_TOKEN))];case 1:return i.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:null==(n=r.accessToken)||n.getToken()==this.accessToken&&n.getValidPeriod()==this.accessTokenValidPeriod?[3,3]:(this.accessToken=n.getToken(),this.accessTokenValidPeriod=n.getValidPeriod(),this.validTime=(new Date).getTime()+1e3*this.accessTokenValidPeriod,[4,b.getStoredUser().then((function(e){return e&&(e.tokenService.accessToken=o.accessToken,e.tokenService.accessTokenValidPeriod=o.accessTokenValidPeriod,e.tokenService.refreshToken=o.refreshToken,e.tokenService.validTime=o.validTime),b.updateStoredUser(e)}))]);case 2:i.sent(),i.label=3;case 3:return[2,Promise.resolve(new c(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]}}))}))},e}(),k=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/user-profile",t}return o(t,e),t.prototype.getBody=function(){},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),E=function(e){function t(){var t=e.call(this)||this;return t.displayName="",t.photoUrl="",t.emailVerified=0,t.passwordSetted=0,t.email="",t.phone="",t.userExtra=null,t}return o(t,e),t.prototype.constructResponse=function(e){this.displayName=e.data.displayName,this.photoUrl=e.data.photoUrl,this.emailVerified=e.data.emailVerified,this.passwordSetted=e.data.passwordSetted,this.email=e.data.email,this.phone=e.data.phone,this.userExtra=new U,this.userExtra.createTime=e.data.userMetaData.createTime,this.userExtra.lastSignInTime=e.data.userMetaData.lastSignInTime,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(g),U=function(){function e(){this.createTime="",this.lastSignInTime=""}return e.prototype.getCreateTime=function(){return this.createTime},e.prototype.getLastSignInTime=function(){return this.lastSignInTime},e}(),R=function(){function e(e,t){this.token=e,this.expirePeriod=t}return e.prototype.getToken=function(){return this.token},e.prototype.getExpirePeriod=function(){return this.expirePeriod},e}(),_=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/user-link",t.provider=-1,t.token="",t.extraData="",t.useJwt=0,t}return o(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getToken=function(){return this.token},t.prototype.setToken=function(e){this.token=e},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{provider:this.getProvider(),token:this.getToken(),extraData:this.getExtraData(),useJwt:this.getUseJwt()}},t}(h),w=function(){function e(){this.autoCreateUser=!0}return e.prototype.getProvider=function(){return-1},e}(),A=function(){function e(){this.password=void 0,this.verifyCode=void 0}return e.prototype.getProvider=function(){return-1},e}(),N=function(e){function t(){var t=e.call(this)||this;return t.providerUserInfo=void 0,t}return o(t,e),t.prototype.getProviderUserInfo=function(){return this.providerUserInfo},t.prototype.setProviderUserInfo=function(e){this.providerUserInfo=e},t.prototype.constructResponse=function(e){this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),e.data.providerUserInfo&&this.setProviderUserInfo(e.data.providerUserInfo)},t}(g),C=function(){function e(e){this.user=e}return e.prototype.getUser=function(){return this.user},e}(),O=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/user-unlink",t.provider=-1,t}return o(t,e),t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()+"&provider="+this.getProvider()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{}},t}(h),V=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(g),D=function(){function e(){this.anonymous=!1,this.uid="",this.displayName="",this.photoUrl="",this.email="",this.phone="",this.providerId="",this.emailVerified=0,this.passwordSetted=0,this.providerService=new a,this.tokenService=new S}return e.prototype.constructFromJson=function(e){this.anonymous=e.anonymous,this.uid=e.uid,this.displayName=e.displayName,this.photoUrl=e.photoUrl,this.email=e.email,this.phone=e.phone,this.providerId=e.providerId,this.emailVerified=e.emailVerified,this.passwordSetted=e.passwordSetted,this.providerService.setProviderInfo(e.providerService.providerInfo),this.tokenService.accessToken=e.tokenService.accessToken,this.tokenService.accessTokenValidPeriod=e.tokenService.accessTokenValidPeriod,this.tokenService.refreshToken=e.tokenService.refreshToken,this.tokenService.validTime=e.tokenService.validTime},e.prototype.isAnonymous=function(){return this.anonymous},e.prototype.getUid=function(){return this.uid},e.prototype.getEmail=function(){return this.email},e.prototype.getPhone=function(){return this.phone},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.getProviderId=function(){return this.providerId},e.prototype.getProviderInfo=function(){for(var e=new Array,t=0;t<this.providerService.getProviderInfo().length;t++){for(var r=new Map,n=Object.keys(this.providerService.getProviderInfo()[t]),o=0;n&&o<n.length;o++)r.set(n[o],this.providerService.getProviderInfo()[t][n[o]]);e.push(r)}return e},e.prototype.getUserExtra=function(){return i(this,void 0,void 0,(function(){var e,t,r,n,o;return s(this,(function(i){switch(i.label){case 0:return e=new K,t=null,r="",[4,e.getCurrentUser().then((function(e){r=e.getAccessToken()}))];case 1:return i.sent(),""==r?[3,3]:(n=new k,o=new E,n.setAccessToken(r),[4,P.get(n,o).then((function(e){W.log("getUserExtra success.")})).catch((function(e){W.error("getUserExtra fail."+e)}))]);case 2:if(i.sent(),0!=o.getRet().getCode())return[2,Promise.reject(o.getRet())];this.displayName=o.displayName,this.photoUrl=o.photoUrl,this.emailVerified=o.emailVerified,this.passwordSetted=o.passwordSetted,this.email=o.email,this.phone=o.phone,this.displayName=o.displayName,t=o.userExtra,b.updateStoredUser(this),i.label=3;case 3:return[2,Promise.resolve(t)]}}))}))},e.prototype.getAccessToken=function(){return this.tokenService.getAccessToken()},e.prototype.getRefreshToken=function(){return this.tokenService.getRefreshToken()},e.prototype.buildUser=function(e){this.anonymous=!1,this.uid=e.getUserInfo().getUid(),this.displayName=e.getUserInfo().getDisplayName(),this.photoUrl=e.getUserInfo().getPhotoUrl(),this.email=e.getUserInfo().getEmail(),this.emailVerified=e.getUserInfo().getEmailVerified(),this.passwordSetted=e.getUserInfo().getPasswordSetted(),this.phone=e.getUserInfo().getPhone(),this.providerId=e.getUserInfo().getProvider().toString(),this.tokenService.constructeSecureTokenService(e.getAccessToken(),e.getRefreshToken()),this.providerService.setProviderInfo(e.getProviders())},e.prototype.getToken=function(e){return this.tokenService.fetchAccessToken(e).then((function(e){return Promise.resolve(new R(e.tokenString,parseInt(e.expiration)))})).catch((function(e){return Promise.reject(e)}))},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.link=function(e){return i(this,void 0,void 0,(function(){var t,r,n,o,i,u,a,c,p;return s(this,(function(s){switch(s.label){case 0:if(!e)return[2,Promise.reject("credential cannot be null or undefined")];if(t=new _,e instanceof w)e.prepareUserLinkRequest(t);else{if(!(e instanceof A))return[2,Promise.reject("credential type error")];e.prepareUserLinkRequest(t)}return[4,this.getToken(!1)];case 1:return r=s.sent(),t.setAccessToken(r.getToken()),n=new N,[4,P.post(t,n)];case 2:return s.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return(o=n.getProviderUserInfo())&&(i={},this.userInfoToMap(o,i),this.anonymous&&this.updateAnonymousUserInfo(i),this.providerService.updateProvider(i),i.provider&&(u=i.provider,12..toString()==u?(a=i.email)&&(this.email=a,this.emailVerified=1):11..toString()==u&&(c=i.phone)&&(this.phone=c),e instanceof A&&null!=e.password&&null!=e.password&&""!=e.password&&(this.passwordSetted=1))),[4,b.updateStoredUser(this)];case 4:return s.sent(),[4,b.getStoredUser()];case 5:return p=s.sent(),[2,Promise.resolve(new C(p))]}}))}))},e.prototype.unlink=function(e){return i(this,void 0,void 0,(function(){return s(this,(function(t){return e?this.anonymous?[2,Promise.reject(new l(p.USER_UNLINKED,"anonymous user can not unlink"))]:[2,this.sendUnlinkRequest(e)]:[2,Promise.reject("credentialProvider cannot be null or undefined")]}))}))},e.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},e.prototype.updateAnonymousUserInfo=function(e){this.anonymous=!1,this.displayName=e.displayName?e.displayName:"",this.photoUrl=e.photoUrl?e.photoUrl:"",this.email=e.email?e.email:"",this.phone=e.phone?e.phone:"",this.providerId=e.provider?e.provider:""},e.prototype.sendUnlinkRequest=function(e){return i(this,void 0,void 0,(function(){var t,r,n,o;return s(this,(function(i){switch(i.label){case 0:return(t=new O).setProvider(e),[4,this.getToken(!1)];case 1:return r=i.sent(),t.setAccessToken(r.getToken()),n=new V,[4,P.post(t,n)];case 2:return i.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return this.providerService.deleteProvider(e.toString()),12==e&&(this.email="",this.emailVerified=0),11==e&&(this.phone=""),null==this.providerService.findProviderIndex(12..toString())&&null==this.providerService.findProviderIndex(11..toString())&&(this.passwordSetted=0),[4,b.updateStoredUser(this)];case 4:return i.sent(),[4,b.getStoredUser()];case 5:return o=i.sent(),[2,Promise.resolve(new C(o))]}}))}))},e}(),L=function(){function t(){this.storageImpl=void 0}return t.getInstance=function(){return t.instance||(t.instance=new t),t.instance},t.prototype.getStorage=function(){var t=e.instance().getService("AGCStorageService");if(null!=t)return this.storageImpl||(this.storageImpl=t.getStorageNewInstance(Number(K.getUserInfoPersistence()),K.getCryptImp()?K.getCryptImp():e.instance().getCryptImp())),this.storageImpl;W.error("Get AGC storage Service failed.")},t}(),b=function(){function t(){this.user=null}return t.constructUserKey=function(){if(null==t.USER_KEY){var r=void 0;try{r=e.instance().config()}catch(e){return void W.error(e)}t.USER_KEY="agcCurrentUser:"+r.client.client_id}},t.loadStoredUser=function(){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return t.constructUserKey(),null==(e=L.getInstance().getStorage())?[2,Promise.reject("get agcStorage failed.")]:[4,e.get(t.USER_KEY).then((function(e){null!=e&&null!=e&&""!=e&&(t.INSTANCE.user=new D,t.INSTANCE.user.constructFromJson(JSON.parse(e)))})).catch((function(e){W.error("----loadStoredUser error ",e)}))];case 1:return r.sent(),[2,Promise.resolve()]}}))}))},t.getStoredUser=function(){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return null!=t.INSTANCE.user?[3,2]:[4,this.loadStoredUser().then((function(e){}))];case 1:e.sent(),e.label=2;case 2:return[2,Promise.resolve(t.INSTANCE.user)]}}))}))},t.updateStoredUser=function(e){return i(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:return t.INSTANCE.user=e,[4,t.saveCurrentUser()];case 1:return r.sent(),[2]}}))}))},t.saveCurrentUser=function(){return i(this,void 0,void 0,(function(){var e;return s(this,(function(r){switch(r.label){case 0:return t.constructUserKey(),null==(e=L.getInstance().getStorage())?[2]:null!=t.INSTANCE.user?[3,2]:[4,e.remove(t.USER_KEY)];case 1:return r.sent(),[3,4];case 2:return[4,e.set(t.USER_KEY,JSON.stringify(t.INSTANCE.user))];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))},t.INSTANCE=new t,t}(),H=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.URL=h.SERVER_URL+"/user-signin-anonymous",i.useJwt=0,i.provider=t,i.token=r,i.extraData=n,i.useJwt=o,i}return o(t,e),t.prototype.getBody=function(){return{provider:0,token:this.token,extraData:"",useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),M=function(e){function t(){var t=e.call(this)||this;return t.accessToken=new v,t.refreshToken=new v,t.uid="",t}return o(t,e),t.prototype.constructResponse=function(e){this.uid=e.data.uid,this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getUid=function(){return this.uid},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t}(g),x=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=h.SERVER_URL+"/user-signout",n.bodyAccessToken=t,n.refreshToken=r,n}return o(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,accessToken:this.bodyAccessToken}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),G=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(g),j=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/user-delete",t}return o(t,e),t.prototype.getBody=function(){return""},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(d),J=function(e){function t(t,r,n,o,i){var s=e.call(this)||this;return s.URL=h.SERVER_URL+"/user-register",s.provider=-1,s.useJwt=0,s.email=t,s.phone=r,s.password=n,s.verifyCode=o,s.useJwt=i,s}return o(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getVerifyCode=function(){return this.verifyCode},t.prototype.setVerifyCode=function(e){this.verifyCode=e},t.prototype.getPassword=function(){return this.password},t.prototype.setPassword=function(e){this.password=e},t.prototype.getBody=function(){return{phone:this.phone,provider:this.provider,email:this.email,password:this.password,verifyCode:this.verifyCode,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),Y=function(){function e(){this.uid="",this.displayName="",this.photoUrl="",this.phone="",this.email="",this.provider=-1,this.openId="",this.emailVerified=0,this.passwordSetted=0}return e.prototype.getUid=function(){return this.uid},e.prototype.setUid=function(e){this.uid=e},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.setDisplayName=function(e){this.displayName=e},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.setPhotoUrl=function(e){this.photoUrl=e},e.prototype.getPhone=function(){return this.phone},e.prototype.setPhone=function(e){this.phone=e},e.prototype.getEmail=function(){return this.email},e.prototype.setEmail=function(e){this.email=e},e.prototype.getProvider=function(){return this.provider},e.prototype.setProvider=function(e){this.provider=e},e.prototype.getOpenId=function(){return this.openId},e.prototype.setOpenId=function(e){this.openId=e},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.setEmailVerified=function(e){this.emailVerified=e},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.setPasswordSetted=function(e){this.passwordSetted=e},e}(),F=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new v,t.refreshToken=new v,t.userInfo=new Y,t.providers=[],t}return o(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.setRefreshToken=function(e){this.refreshToken=e},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(g),q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/user-signin",t.provider=-1,t.token="",t.extraData="",t.autoCreateUser=-1,t.useJwt=0,t.verifyCode="",t}return o(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.getToken=function(){return this.token},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.isAutoCreateUser=function(){return this.autoCreateUser},t.prototype.setAutoCreateUser=function(e){this.autoCreateUser=e},t.prototype.setProvider=function(e){this.provider=e},t.prototype.setToken=function(e){this.token=e},t.prototype.getBody=function(){return{provider:this.provider,token:this.token,extraData:this.extraData,autoCreateUser:this.autoCreateUser,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),B=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new v,t.refreshToken=new v,t.userInfo=new Y,t.providers=[],t}return o(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(g),W=r.createLogger("auth"),K=function(){function t(){}return t.prototype.createEmailUser=function(e){return i(this,void 0,void 0,(function(){var t,r,n,o,i;return s(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyEmailUser(!1))?[2,Promise.reject(new l(r,p.getMsgByCode(r)))]:((n=new J(e.email,"",e.password,e.verifyCode,1)).setProvider(12),o=new F,[4,P.post(n,o)]):[2,Promise.reject(new l(p.INVALID_EMAIL,"emailUser invalid"))]:[2,Promise.reject(new l(p.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new D).buildUser(o),b.updateStoredUser(i),[2,Promise.resolve(new C(i))])}}))}))},t.prototype.createPhoneUser=function(e){return i(this,void 0,void 0,(function(){var t,r,n,o,i;return s(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyPhoneUser(!1))?[2,Promise.reject(new l(r,p.getMsgByCode(r)))]:((n=new J("",e.getPhone(),e.password,e.verifyCode,1)).setProvider(11),o=new F,[4,P.post(n,o)]):[2,Promise.reject(new l(p.INVALID_PHONE,"phoneUser invalid"))]:[2,Promise.reject(new l(p.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new D).buildUser(o),b.updateStoredUser(i),[2,Promise.resolve(new C(i))])}}))}))},t.prototype.signIn=function(e){return i(this,void 0,void 0,(function(){var t,r=this;return s(this,(function(n){switch(n.label){case 0:if(!e)throw new Error("credential invalid");return[4,this.getCurrentUser()];case 1:return null==(t=n.sent())||t.isAnonymous()?[2,new Promise((function(t,n){r.getUserWithCredential(e).then((function(e){t(e)})).catch((function(e){n(e)}))}))]:[2,Promise.reject(new l(p.ALREADY_SIGN_IN_USER,"already sign in a user"))]}}))}))},t.prototype.getUserWithCredential=function(e){return i(this,void 0,void 0,(function(){var t,r,n;return s(this,(function(o){switch(o.label){case 0:if(t=new q,e instanceof w)e.prepareUserAuthRequest(t),t.setAutoCreateUser(e.autoCreateUser?1:0);else{if(!(e instanceof A))throw new Error("credential type error");e.prepareUserAuthRequest(t)}return t.setUseJwt(1),r=new B,[4,P.post(t,r)];case 1:return o.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:((n=new D).buildUser(r),b.updateStoredUser(n),[2,Promise.resolve(new C(n))])}}))}))},t.prototype.deleteUser=function(){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return i(this,void 0,void 0,(function(){var t,r,n;return s(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(t=e,r=new j,n=new G,r.setAccessToken(t.getAccessToken()),[4,P.post(r,n)]);case 1:return o.sent(),0!=n.getRet().getCode()?(W.error("deleteUser fail."),[2,Promise.reject(n.getRet())]):[4,b.updateStoredUser(null)];case 2:return o.sent(),W.log("deleteUser success."),[2,Promise.resolve()];case 3:return W.error("deleteUser fail, no user signed in."),[2,Promise.reject(new l(p.NOT_SIGN_IN,"no user signed in"))]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},t.prototype.signOut=function(){return i(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return i(this,void 0,void 0,(function(){var t,r,n;return s(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(r=new x((t=e).getAccessToken(),t.getRefreshToken()),n=new G,[4,P.post(r,n).then((function(e){W.log("signOut success.")})).catch((function(e){W.error("signOut fail."+e)}))]);case 1:return o.sent(),[4,b.updateStoredUser(null)];case 2:o.sent(),o.label=3;case 3:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},t.prototype.getCurrentUser=function(){return b.getStoredUser()},t.prototype.signInAnonymously=function(){var e=this;return this.getCurrentUser().then((function(t){if(null!=t){if(t.isAnonymous()){var r=new C(t);return Promise.resolve(r)}return Promise.reject(new l(p.ALREADY_SIGN_IN_USER,"already sign in a user"))}return e.getUserWithAnonymously()})).catch((function(e){return Promise.reject(e)}))},t.prototype.getUserWithAnonymously=function(){return i(this,void 0,void 0,(function(){var t,r,n,o,i;return s(this,(function(s){switch(s.label){case 0:return null==(t=e.instance().getService("ClientInfoService"))?[2,Promise.reject("Get clientInfoUtil service failed.")]:(r="",[4,t.getAaid().then((function(e){r=e}))]);case 1:return s.sent(),r?(n=new H(0,r,"",1),o=new M,[4,P.post(n,o)]):[2,Promise.reject("The aaid is null.")];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new D).uid=o.getUid(),i.providerId=(0).toString(),i.tokenService.constructeSecureTokenService(o.getAccessToken(),o.getRefreshToken()),i.anonymous=!0,[4,b.updateStoredUser(i)]);case 3:return s.sent(),[2,Promise.resolve(new C(i))]}}))}))},t.prototype.setUserInfoPersistence=function(e){t.persistence=e},t.getUserInfoPersistence=function(){return t.persistence},t.prototype.setCryptImp=function(e){return e?e.decrypt&&e.encrypt?(t.cryptImpl=e,!0):(W.error("the crypt is not exist necessary methods."),!1):(W.error("the crypt is not available."),!1)},t.getCryptImp=function(){return t.cryptImpl},t.persistence=2,t.cryptImpl=void 0,t}(),z=function(){function e(){}return e.combinatePhone=function(e,t){return null==e||e.startsWith("+")||(e="+"+e),e+"-"+t},e}(),Q=function(){function e(e,t,r,n){this.countryCode="",this.phoneNumber="",this.password="",this.verifyCode="",this.countryCode=e,this.phoneNumber=t,this.password=r,this.verifyCode=n}return e.prototype.getPhone=function(){return z.combinatePhone(this.countryCode,this.phoneNumber)},e.prototype.verifyPhoneUser=function(e){return""==this.phoneNumber?p.INVALID_EMAIL:""==this.password&&e?p.PASSWORD_IS_EMPTY:""==this.verifyCode?p.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),X=function(){function e(e,t,r){this.email="",this.password="",this.verifyCode="",this.email=e,this.password=t,this.verifyCode=r}return e.prototype.verifyEmailUser=function(e){return""==this.email?p.INVALID_EMAIL:""==this.password&&e?p.PASSWORD_IS_EMPTY:""==this.verifyCode?p.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),Z=function(e){function t(t,r,n){var o=e.call(this)||this;return o.email=t,o.password=r,o.verifyCode=n,o}return o(t,e),t.prototype.getProvider=function(){return 12},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t}(A),$=function(){function e(e,t,r){this.action=e,this.lang=t,this.sendInterval=r}return e.prototype.getAction=function(){return this.action},e.prototype.getLang=function(){return this.lang},e.prototype.getSendInterval=function(){return this.sendInterval},e.prototype.setAction=function(e){this.action=e},e.prototype.setLang=function(e){this.lang=e},e.prototype.setSendInterval=function(e){this.sendInterval=e},e}(),ee=function(){function e(e,t){this.shortestInterval=e,this.validityPeriod=t}return e.prototype.getShortestInterval=function(){return this.shortestInterval},e.prototype.getValidityPeriod=function(){return this.validityPeriod},e}(),te=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=h.SERVER_URL+"/verify-code",t.phone="",t.email="",t.action=-1,t.lang="",t.sendInterval=-1,t}return o(t,e),t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getAction=function(){return this.action},t.prototype.setAction=function(e){this.action=e},t.prototype.getLang=function(){return this.lang},t.prototype.setLang=function(e){this.lang=e},t.prototype.getSendInterval=function(){return this.sendInterval},t.prototype.setSendInterval=function(e){this.sendInterval=e},t.prototype.getBody=function(){return{phone:this.phone,email:this.email,lang:this.lang,action:this.action,sendInterval:this.sendInterval}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),re=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.shortestInterval="",t.validityPeriod="",t}return o(t,e),t.prototype.constructResponse=function(e){this.shortestInterval=e.data.shortestInterval,this.validityPeriod=e.data.validityPeriod,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getShortestInterval=function(){return this.shortestInterval},t.prototype.setShortestInterval=function(e){this.shortestInterval=e},t.prototype.getValidityPeriod=function(){return this.validityPeriod},t.prototype.setValidityPeriod=function(e){this.validityPeriod=e},t}(g),ne=function(){function e(){}return e.requestEmailVerifyCode=function(e,t){var r=this.buildRequest(e,"",t);return this.requestVerifyCode(r)},e.requestPhoneVerifyCode=function(e,t,r){var n=z.combinatePhone(e,t),o=this.buildRequest("",n,r);return this.requestVerifyCode(o)},e.requestVerifyCode=function(e){return i(this,void 0,void 0,(function(){var t;return s(this,(function(r){switch(r.label){case 0:return t=new re,[4,P.post(e,t)];case 1:return r.sent(),0!=t.getRet().getCode()?[2,Promise.reject(t.getRet())]:[2,Promise.resolve(new ee(t.getShortestInterval(),t.getValidityPeriod()))]}}))}))},e.buildRequest=function(e,t,r){if(null==r)throw new Error("invalid verifyCodeSettings.");var n=new te;return n.setEmail(e),n.setPhone(t),n.setAction(r.getAction()),n.setLang(r.getLang()),n.setSendInterval(r.getSendInterval()),n},e}(),oe=function(){function e(){}return e.credentialWithPassword=function(e,t){return new Z(e,t,"")},e.credentialWithVerifyCode=function(e,t,r){return new Z(e,t,r)},e.requestVerifyCode=function(e,t,r,n){return ne.requestEmailVerifyCode(e,new $(t,r,n))},e}(),ie=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.countryCode=t,i.phoneNumber=r,i.password=n,i.verifyCode=o,i}return o(t,e),t.prototype.getProvider=function(){return 11},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t.prototype.getPhone=function(){return z.combinatePhone(this.countryCode,this.phoneNumber)},t}(A),se=function(){function e(){}return e.credentialWithPassword=function(e,t,r){return new ie(e,t,r,"")},e.credentialWithVerifyCode=function(e,t,r,n){return new ie(e,t,r,n)},e.requestVerifyCode=function(e,t,r,n,o){return ne.requestPhoneVerifyCode(e,t,new $(r,n,o))},e}(),ue=function(e){function t(t,r,n){var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return o(t,e),t.prototype.getProvider=function(){return 4},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(w),ae=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ue(e,t,r)},e}(),ce=function(e){function t(t,r,n){void 0===n&&(n=!0);var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return o(t,e),t.prototype.getProvider=function(){return 6},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(w),pe=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ce(e,t,r)},e}(),de=function(){function t(){}return t.prototype.getToken=function(t){return i(this,void 0,void 0,(function(){var r,n,o;return s(this,(function(i){switch(i.label){case 0:return e.instance().getCustomAuthProvider()?[4,e.instance().getCustomAuthProvider().getToken(t)]:[3,2];case 1:return(r=i.sent())&&r.tokenString&&r.expiration?isNaN(Number(r.expiration))||Number(r.expiration)<=0?(W.error("the customAuthProvider getToken must return valid expiration."),[2,Promise.reject("the customAuthProvider getToken must return valid expiration.")]):(n=new(function(){function e(){}return e.prototype.getExpirePeriod=function(){return Number(r.expiration)},e.prototype.getToken=function(){return r.tokenString},e}()),[2,Promise.resolve(n)]):(W.error("the customAuthProvider getToken method must contain return value: tokenString, expiration."),[2,Promise.reject("the customAuthProvider getToken method must contain return value: tokenString, expiration.")]);case 2:return[4,b.getStoredUser()];case 3:return(o=i.sent())?[2,o.getToken(t)]:[2,Promise.resolve(null)]}}))}))},t}(),he=function(e){function t(t,r){var n=e.call(this)||this;return n.token=t,n.autoCreateUser=r,n}return o(t,e),t.prototype.getProvider=function(){return 1},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(1),e.setToken(this.token)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(1),e.setToken(this.token),e.setUseJwt(1)},t}(w),fe=function(){function e(){}return e.credentialWithToken=function(e,t){return void 0===t&&(t=!0),new he(e,t)},e}(),le=new t((function(){return new K}));function ge(e){return new de}!function(e){e[e.ACTION_REGISTER_LOGIN=1001]="ACTION_REGISTER_LOGIN",e[e.ACTION_RESET_PASSWORD=1002]="ACTION_RESET_PASSWORD"}(I||(I={})),T={PhoneUser:Q,EmailUser:X,EmailAuthProvider:oe,PhoneAuthProvider:se,WeixinAuthProvider:ae,QQAuthProvider:pe,HwIdAuthProvider:fe,Action:I},(m=e).registerApiProvider("auth",(function(){return le.get()}),T),m.registerInternalService({name:"AuthProviderService",serviceFactory:ge}); |
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("@agconnect/api"),t=require("@agconnect/core");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@agconnect/baseservice"),require("@agconnect/instance"),require("@agconnect/util"),require("@agconnect/network"),require("@agconnect/storage");var n=r(e),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)}; | ||
"use strict";var e=require("@agconnect/api"),t=require("@agconnect/core");require("@agconnect/baseservice"),require("@agconnect/instance"),require("@agconnect/util");var r=require("@agconnect/log");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@agconnect/network"),require("@agconnect/storage");var o=n(e),i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)}; | ||
/*! ***************************************************************************** | ||
@@ -15,2 +15,2 @@ Copyright (c) Microsoft Corporation. | ||
PERFORMANCE OF THIS SOFTWARE. | ||
***************************************************************************** */function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function s(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(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())}))}function u(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var a,c=function(){function e(){this.providerInfo=new Array}return e.prototype.getProviderInfo=function(){return this.providerInfo},e.prototype.setProviderInfo=function(e){this.providerInfo=e},e.prototype.updateProvider=function(e){if(e&&this.providerInfo){var t=e.provider;t&&this.deleteProvider(t),this.providerInfo.push(e)}},e.prototype.deleteProvider=function(e){var t=this.findProviderIndex(e);this.providerInfo&&null!=t&&this.providerInfo.splice(t,1)},e.prototype.findProviderIndex=function(e){var t=void 0;if(e&&this.providerInfo)for(var r=0;r<this.providerInfo.length;r++){var n=this.providerInfo[r];if(n&&e==n.provider){t=r;break}}return t},e}(),d=function(){function e(e,t,r,n){this.state=void 0,this.expiration=e,this.issuedAt=t,this.notBefore=r,this.tokenString=n}return e.prototype.getState=function(){return this.state},e.prototype.getToken=function(){return this.tokenString},e}(),p=function(){function e(e,t){this.code=t,this.errMsg=e}return e.getMsgByCode=function(t){switch(t){case e.INVALID_EMAIL:return"email can not be null or empty";case e.PASSWORD_IS_EMPTY:return"password can not be null or empty";case e.EMAIL_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty";case e.INVALID_PHONE:return"countrycode and phone can not be null or empty";case e.PHONE_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty"}return""},e.NULL_TOKEN=1,e.NOT_SIGN_IN=2,e.USER_LINKED=3,e.USER_UNLINKED=4,e.ALREADY_SIGN_IN_USER=5,e.EMAIL_VERIFICATION_IS_EMPTY=6,e.PHONE_VERIFICATION_IS_EMPTY=7,e.INVALID_EMAIL=203817223,e.INVALID_PHONE=203817224,e.GET_UID_ERROR=203817728,e.UID_PRODUCTID_NOT_MATCH=203817729,e.GET_USER_INFO_ERROR=203817730,e.AUTH_METHOD_NOT_SUPPORT=203817732,e.PRODUCT_STATUS_ERROR=203817744,e.PASSWORD_VERIFICATION_CODE_OVER_LIMIT=203817811,e.INVALID_TOKEN=203817984,e.INVALID_ACCESS_TOKEN=203817985,e.INVALID_REFRESH_TOKEN=203817986,e.CLIENT_TOKEN_EXPIRED=205524993,e.ACCESS_TOKEN_EXPIRED=205524994,e.TOKEN_AND_PRODUCTID_NOT_MATCH=203817987,e.AUTH_METHOD_IS_DISABLED=203817988,e.FAIL_TO_GET_THIRD_USER_INFO=203817989,e.FAIL_TO_GET_THIRD_USER_UNION_ID=203817990,e.ACCESS_TOKEN_OVER_LIMIT=203817991,e.FAIL_TO_USER_LINK=203817992,e.FAIL_TO_USER_UNLINK=203817993,e.ANONYMOUS_SIGNIN_OVER_LIMIT=203818019,e.INVALID_APPID=203818020,e.INVALID_APPSECRET=203818021,e.GET_QQ_USERINFO_ERROR=203818023,e.QQINFO_RESPONSE_IS_NULL=203818024,e.GET_QQ_UID_ERROR=203818025,e.PASSWORD_VERIFY_CODE_ERROR=203818032,e.GOOGLE_RESPONSE_NOT_EQUAL_APPID=203818033,e.SIGNIN_USER_STATUS_ERROR=203818036,e.SIGNIN_USER_PASSWORD_ERROR=203818037,e.PROVIDER_USER_HAVE_BEEN_LINKED=203818038,e.PROVIDER_HAVE_LINKED_ONE_USER=203818039,e.FAIL_GET_PROVIDER_USER=203818040,e.CANNOT_UNLINK_ONE_PROVIDER_USER=203818041,e.VERIFY_CODE_INTERVAL_LIMIT=203818048,e.VERIFY_CODE_EMPTY=203818049,e.VERIFY_CODE_LANGUAGE_EMPTY=203818050,e.VERIFY_CODE_RECEIVER_EMPTY=203818051,e.VERIFY_CODE_ACTION_ERROR=203818052,e.VERIFY_CODE_TIME_LIMIT=203818053,e.ACCOUNT_PASSWORD_SAME=203818064,e.PASSWORD_STRENGTH_LOW=203818065,e.UPDATE_PASSWORD_ERROR=203818066,e.PASSWORD_SAME_AS_BEFORE=203818067,e.PASSWORD_IS_EMPTY=203818068,e.PASSWORD_TOO_LONG=203818071,e.SENSITIVE_OPERATION_TIMEOUT=203818081,e.ACCOUNT_HAVE_BEEN_REGISTERED=203818082,e.UPDATE_ACCOUNT_ERROR=203818084,e.USER_NOT_REGISTERED=203818087,e.VERIFY_CODE_ERROR=203818129,e.USER_HAVE_BEEN_REGISTERED=203818130,e.REGISTER_ACCOUNT_IS_EMPTY=203818132,e.VERIFY_CODE_FORMAT_ERROR=203818134,e.VERIFY_CODE_AND_PASSWORD_BOTH_NULL=203818135,e.SEND_EMAIL_FAIL=203818240,e.SEND_MESSAGE_FAIL=203818241,e.CONFIG_LOCK_TIME_ERROR=203818261,e}(),h=function(){function e(){this.sdkPlatform="",this.sdkPlatformVersion="",this.packageName="",this.appVersion="",this.headerProductId="",this.headerAppId="",this.headerClientId="",this.agcgwUrl="",this.agcgwBackUrl="",this.sdkServiceName="agconnect-auth",this.sdkVersion="1.2.0";var e,t=n.default.instance().getService("AGCPlatformInfoService");t&&(this.sdkPlatform=t.getPlatform(),this.sdkPlatformVersion=t.getPlatformVersion(),this.packageName=t.getPackageName(),this.appVersion=t.getAppVersion()),this.accessToken="",this.authorization="",this.headerAaId="";try{e=n.default.instance().config()}catch(e){return void console.error(e)}this.headerProductId=e.client.product_id,this.headerClientId=e.client.client_id,this.headerAppId=e.client.app_id,this.agcgwUrl=this.addHttpToUrl(e.agcgw.url),this.agcgwBackUrl=this.addHttpToUrl(e.agcgw.backurl)}return e.prototype.getSdkServiceName=function(){return this.sdkServiceName},e.prototype.setSdkServiceName=function(e){this.sdkServiceName=e},e.prototype.getSdkVersion=function(){return this.sdkVersion},e.prototype.setSdkVersion=function(e){this.sdkVersion=e},e.prototype.getSdkPlatform=function(){return this.sdkPlatform},e.prototype.setSdkPlatform=function(e){this.sdkPlatform=e},e.prototype.getSdkPlatformVersion=function(){return this.sdkPlatformVersion},e.prototype.setSdkPlatformVersion=function(e){this.sdkPlatformVersion=e},e.prototype.getPackageName=function(){return this.packageName},e.prototype.setPackageName=function(e){this.packageName=e},e.prototype.getAppVersion=function(){return this.appVersion},e.prototype.setAppVersion=function(e){this.appVersion=e},e.prototype.getHeaderProductId=function(){return this.headerProductId},e.prototype.setHeaderProductId=function(e){this.headerProductId=e},e.prototype.getHeaderAppId=function(){return this.headerAppId},e.prototype.setHeaderAppId=function(e){this.headerAppId=e},e.prototype.getHeaderAaId=function(){return this.headerAaId},e.prototype.setHeaderAaId=function(e){this.headerAaId=e},e.prototype.getHeaderClientId=function(){return this.headerClientId},e.prototype.setHeaderClientId=function(e){this.headerClientId=e},e.prototype.getAuthorization=function(){return this.authorization},e.prototype.setAuthorization=function(e){this.authorization=e},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.setAccessToken=function(e){this.accessToken=e},e.prototype.getAgcgwUrl=function(){return this.agcgwUrl},e.prototype.setAgcgwUrl=function(e){this.agcgwUrl=e},e.prototype.getAgcgwBackUrl=function(){return this.agcgwBackUrl},e.prototype.setAgcgwBackUrl=function(e){this.agcgwBackUrl=e},e.prototype.addHttpToUrl=function(e){return e&&!e.startsWith("https://")?"https://"+e:e},e.prototype.getAuthHeader=function(){return{sdkVersion:this.getSdkVersion(),sdkPlatform:this.getSdkPlatform(),sdkPlatformVersion:this.getSdkPlatformVersion(),packageName:this.getPackageName(),appVersion:this.getAppVersion(),sdkServiceName:this.getSdkServiceName(),app_id:this.getHeaderAppId(),client_id:this.getHeaderClientId(),productId:this.getHeaderProductId(),access_token:this.getAccessToken(),Authorization:this.getAuthorization(),"Content-Type":"application/json;charset=UTF-8"}},e}(),f=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t.SERVER_URL="/agc/apigw/oauth2/third/v1",t}(h),l=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=f.SERVER_URL+"/user-auth/refresh-token",n.useJwt=0,n.refreshToken=t,n.useJwt=r,n}return i(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),g=function(){function e(e,t){void 0===e&&(e=0),void 0===t&&(t=""),this.code=e,this.msg=t}return e.prototype.getCode=function(){return this.code},e.prototype.setCode=function(e){this.code=e},e.prototype.getMsg=function(){return this.msg},e.prototype.setMsg=function(e){this.msg=e},e}(),v=function(){function e(){this.ret=new g}return e.prototype.isSuccess=function(){return null!=this.ret&&0==this.ret.getCode()},e.prototype.getRet=function(){return this.ret},e.prototype.setRet=function(e){this.ret=e},e.prototype.constructResponse=function(e){},e}(),y=function(){function e(){this.token="",this.validPeriod=0}return e.prototype.getToken=function(){return this.token},e.prototype.setToken=function(e){this.token=e},e.prototype.getValidPeriod=function(){return this.validPeriod},e.prototype.setValidPeriod=function(e){this.validPeriod=e},e}(),I=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new y,t.productId="",t.uid="",t}return i(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(v);!function(e){e[e.POST=0]="POST",e[e.GET=1]="GET"}(a||(a={}));var T,P,m,S=function(){function e(){}return e.getClientToken=function(e){return s(this,void 0,void 0,(function(){var t,r;return u(this,(function(o){switch(o.label){case 0:return(t=n.default.instance().getService("CredentialsService"))?(r="",[4,t.getToken(e).then((function(e){r=e.tokenString}))]):[2,Promise.reject("Get credentialProvider failed.")];case 1:return o.sent(),null==r||""==r?[2,Promise.reject("Get clientToken failed.")]:[2,Promise.resolve(r)]}}))}))},e.post=function(t,r){return s(this,void 0,void 0,(function(){var n,o,i;return u(this,(function(s){switch(s.label){case 0:return n=t.getHeader(),o=n,i="Bearer ",[4,e.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(t,a.POST,r,n,!0,!0)]}}))}))},e.get=function(t,r){return s(this,void 0,void 0,(function(){var n,o,i;return u(this,(function(s){switch(s.label){case 0:return n=t.getHeader(),o=n,i="Bearer ",[4,e.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(t,a.GET,r,n,!0,!0)]}}))}))},e.sendRequest=function(t,r,o,i,a,c){return s(this,void 0,void 0,(function(){var d=this;return u(this,(function(h){switch(h.label){case 0:return[4,this.doNetworkOption(r,t,i,o).then((function(e){return Promise.resolve()})).catch((function(h){return s(d,void 0,void 0,(function(){var s,d,f,l,v;return u(this,(function(u){switch(u.label){case 0:return 401!=h.response.status?[2,Promise.reject(h)]:(s="0x0"+(s=h.response.data.ret.code).toString(16))==p.CLIENT_TOKEN_EXPIRED&&a?(d=n.default.instance().getService("CredentialsService"))?[4,d.removeToken()]:[2,Promise.reject("Get credentialProvider failed.")]:[3,3];case 1:return u.sent(),f=i,l="Bearer ",[4,e.getClientToken(!0)];case 2:return f.Authorization=l+u.sent(),o.setRet(new g),[2,e.sendRequest(t,r,o,i,!1,c)];case 3:return s==p.ACCESS_TOKEN_EXPIRED&&c?(v=null,[4,n.default.auth().getCurrentUser().then((function(e){return null==e?Promise.reject("no user sigIn."):(v=e,Promise.resolve())}))]):[3,6];case 4:return u.sent(),[4,v.getToken(!0).then((function(e){i.access_token=e.getToken()}))];case 5:return u.sent(),o.setRet(new g),[2,e.sendRequest(t,r,o,i,a,!1)];case 6:return[2,Promise.reject(h)]}}))}))}))];case 1:return[2,h.sent()]}}))}))},e.doNetworkOption=function(e,t,r,o){return s(this,void 0,void 0,(function(){var i;return u(this,(function(s){switch(s.label){case 0:return null==(i=n.default.instance().getService("AGCNetworkService"))?[2,Promise.reject("Get agcNetwork service failed.")]:e!=a.POST?[3,2]:[4,i.post(t.getUrl(),t.getBody(),r).then((function(e){0==e.data.ret.code&&o.constructResponse(e),o.setRet(new g(e.data.ret.code,e.data.ret.msg))})).catch((function(e){return Promise.reject(e)}))];case 1:return s.sent(),[3,4];case 2:return[4,i.get(t.getUrl(),t.getBody(),r).then((function(e){o.constructResponse(e)})).catch((function(e){return Promise.reject(e)}))];case 3:s.sent(),s.label=4;case 4:return[2,Promise.resolve()]}}))}))},e}(),E=function(){function e(){this.accessToken="",this.accessTokenValidPeriod=-1,this.refreshToken="",this.validTime=-1,this.TIME_EARLY=3e5}return e.prototype.constructeSecureTokenService=function(e,t){this.accessToken=e.getToken(),this.accessTokenValidPeriod=e.getValidPeriod(),this.refreshToken=t.getToken(),this.validTime=(new Date).getTime()+1e3*e.getValidPeriod()},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.getRefreshToken=function(){return this.refreshToken},e.prototype.isValidAccessToken=function(){return null!=this.accessToken&&this.remainToRefreshTime()>0},e.prototype.remainToRefreshTime=function(){return this.validTime-(new Date).getTime()-this.TIME_EARLY},e.prototype.fetchAccessToken=function(e){return s(this,void 0,void 0,(function(){var t,r,n,o=this;return u(this,(function(i){switch(i.label){case 0:return!e&&this.isValidAccessToken()?[2,Promise.resolve(new d(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]:this.accessToken&&this.refreshToken?(t=new l(this.refreshToken,1),r=new I,[4,S.post(t,r)]):[2,Promise.reject(new p("Token is null.",p.NULL_TOKEN))];case 1:return i.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:null==(n=r.accessToken)||n.getToken()==this.accessToken&&n.getValidPeriod()==this.accessTokenValidPeriod?[3,3]:(this.accessToken=n.getToken(),this.accessTokenValidPeriod=n.getValidPeriod(),this.validTime=(new Date).getTime()+1e3*this.accessTokenValidPeriod,[4,H.getStoredUser().then((function(e){return e&&(e.tokenService.accessToken=o.accessToken,e.tokenService.accessTokenValidPeriod=o.accessTokenValidPeriod,e.tokenService.refreshToken=o.refreshToken,e.tokenService.validTime=o.validTime),H.updateStoredUser(e)}))]);case 2:i.sent(),i.label=3;case 3:return[2,Promise.resolve(new d(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]}}))}))},e}(),k=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/user-profile",t}return i(t,e),t.prototype.getBody=function(){},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),U=function(e){function t(){var t=e.call(this)||this;return t.displayName="",t.photoUrl="",t.emailVerified=0,t.passwordSetted=0,t.email="",t.phone="",t.userExtra=null,t}return i(t,e),t.prototype.constructResponse=function(e){this.displayName=e.data.displayName,this.photoUrl=e.data.photoUrl,this.emailVerified=e.data.emailVerified,this.passwordSetted=e.data.passwordSetted,this.email=e.data.email,this.phone=e.data.phone,this.userExtra=new R,this.userExtra.createTime=e.data.userMetaData.createTime,this.userExtra.lastSignInTime=e.data.userMetaData.lastSignInTime,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(v),R=function(){function e(){this.createTime="",this.lastSignInTime=""}return e.prototype.getCreateTime=function(){return this.createTime},e.prototype.getLastSignInTime=function(){return this.lastSignInTime},e}(),_=function(){function e(e,t){this.token=e,this.expirePeriod=t}return e.prototype.getToken=function(){return this.token},e.prototype.getExpirePeriod=function(){return this.expirePeriod},e}(),w=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/user-link",t.provider=-1,t.token="",t.extraData="",t.useJwt=0,t}return i(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getToken=function(){return this.token},t.prototype.setToken=function(e){this.token=e},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{provider:this.getProvider(),token:this.getToken(),extraData:this.getExtraData(),useJwt:this.getUseJwt()}},t}(f),A=function(){function e(){this.autoCreateUser=!0}return e.prototype.getProvider=function(){return-1},e}(),N=function(){function e(){this.password="",this.verifyCode=""}return e.prototype.getProvider=function(){return-1},e}(),C=function(e){function t(){var t=e.call(this)||this;return t.providerUserInfo=void 0,t}return i(t,e),t.prototype.getProviderUserInfo=function(){return this.providerUserInfo},t.prototype.setProviderUserInfo=function(e){this.providerUserInfo=e},t.prototype.constructResponse=function(e){this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),e.data.providerUserInfo&&this.setProviderUserInfo(e.data.providerUserInfo)},t}(v),O=function(){function e(e){this.user=e}return e.prototype.getUser=function(){return this.user},e}(),V=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/user-unlink",t.provider=-1,t}return i(t,e),t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()+"&provider="+this.getProvider()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{}},t}(f),D=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(v),L=function(){function e(){this.anonymous=!1,this.uid="",this.displayName="",this.photoUrl="",this.email="",this.phone="",this.providerId="",this.emailVerified=-1,this.passwordSetted=-1,this.providerService=new c,this.tokenService=new E}return e.prototype.constructFromJson=function(e){this.anonymous=e.anonymous,this.uid=e.uid,this.displayName=e.displayName,this.photoUrl=e.photoUrl,this.email=e.email,this.phone=e.phone,this.providerId=e.providerId,this.emailVerified=e.emailVerified,this.passwordSetted=e.passwordSetted,this.providerService.setProviderInfo(e.providerService.providerInfo),this.tokenService.accessToken=e.tokenService.accessToken,this.tokenService.accessTokenValidPeriod=e.tokenService.accessTokenValidPeriod,this.tokenService.refreshToken=e.tokenService.refreshToken,this.tokenService.validTime=e.tokenService.validTime},e.prototype.isAnonymous=function(){return this.anonymous},e.prototype.getUid=function(){return this.uid},e.prototype.getEmail=function(){return this.email},e.prototype.getPhone=function(){return this.phone},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.getProviderId=function(){return this.providerId},e.prototype.getProviderInfo=function(){for(var e=new Array,t=0;t<this.providerService.getProviderInfo().length;t++){for(var r=new Map,n=Object.keys(this.providerService.getProviderInfo()[t]),o=0;n&&o<n.length;o++)r.set(n[o],this.providerService.getProviderInfo()[t][n[o]]);e.push(r)}return e},e.prototype.getUserExtra=function(){return s(this,void 0,void 0,(function(){var e,t,r,n,o;return u(this,(function(i){switch(i.label){case 0:return e=new K,t=null,r="",[4,e.getCurrentUser().then((function(e){r=e.getAccessToken()}))];case 1:return i.sent(),""==r?[3,3]:(n=new k,o=new U,n.setAccessToken(r),[4,S.get(n,o).then((function(e){console.log("getUserExtra success.")})).catch((function(e){console.error("getUserExtra fail."+e)}))]);case 2:if(i.sent(),0!=o.getRet().getCode())return[2,Promise.reject(o.getRet())];this.displayName=o.displayName,this.photoUrl=o.photoUrl,this.emailVerified=o.emailVerified,this.passwordSetted=o.passwordSetted,this.email=o.email,this.phone=o.phone,this.displayName=o.displayName,t=o.userExtra,H.updateStoredUser(this),i.label=3;case 3:return[2,Promise.resolve(t)]}}))}))},e.prototype.getAccessToken=function(){return this.tokenService.getAccessToken()},e.prototype.getRefreshToken=function(){return this.tokenService.getRefreshToken()},e.prototype.buildUser=function(e){this.anonymous=!1,this.uid=e.getUserInfo().getUid(),this.displayName=e.getUserInfo().getDisplayName(),this.photoUrl=e.getUserInfo().getPhotoUrl(),this.email=e.getUserInfo().getEmail(),this.emailVerified=e.getUserInfo().getEmailVerified(),this.passwordSetted=e.getUserInfo().getPasswordSetted(),this.phone=e.getUserInfo().getPhone(),this.providerId=e.getUserInfo().getProvider().toString(),this.tokenService.constructeSecureTokenService(e.getAccessToken(),e.getRefreshToken()),this.providerService.setProviderInfo(e.getProviders())},e.prototype.getToken=function(e){return this.tokenService.fetchAccessToken(e).then((function(e){return Promise.resolve(new _(e.tokenString,parseInt(e.expiration)))})).catch((function(e){return Promise.reject(e)}))},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.link=function(e){return s(this,void 0,void 0,(function(){var t,r,n,o,i,s,a,c,d;return u(this,(function(u){switch(u.label){case 0:if(!e)return[2,Promise.reject("credential cannot be null or undefined")];if(t=new w,e instanceof A)e.prepareUserLinkRequest(t);else{if(!(e instanceof N))return[2,Promise.reject("credential type error")];e.prepareUserLinkRequest(t)}return[4,this.getToken(!1)];case 1:return r=u.sent(),t.setAccessToken(r.getToken()),n=new C,[4,S.post(t,n)];case 2:return u.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return(o=n.getProviderUserInfo())&&(i={},this.userInfoToMap(o,i),this.anonymous&&this.updateAnonymousUserInfo(i),this.providerService.updateProvider(i),i.provider&&(s=i.provider,12..toString()==s?(a=i.email)&&(this.email=a):11..toString()==s&&(c=i.phone)&&(this.phone=c))),[4,H.updateStoredUser(this)];case 4:return u.sent(),[4,H.getStoredUser()];case 5:return d=u.sent(),[2,Promise.resolve(new O(d))]}}))}))},e.prototype.unlink=function(e){return s(this,void 0,void 0,(function(){return u(this,(function(t){return e?this.anonymous?[2,Promise.reject(new g(p.USER_UNLINKED,"anonymous user can not unlink"))]:[2,this.sendUnlinkRequest(e)]:[2,Promise.reject("credentialProvider cannot be null or undefined")]}))}))},e.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},e.prototype.updateAnonymousUserInfo=function(e){this.anonymous=!1,this.displayName=e.displayName?e.displayName:"",this.photoUrl=e.photoUrl?e.photoUrl:"",this.email=e.email?e.email:"",this.phone=e.phone?e.phone:"",this.providerId=e.provider?e.provider:""},e.prototype.sendUnlinkRequest=function(e){return s(this,void 0,void 0,(function(){var t,r,n,o;return u(this,(function(i){switch(i.label){case 0:return(t=new V).setProvider(e),[4,this.getToken(!1)];case 1:return r=i.sent(),t.setAccessToken(r.getToken()),n=new D,[4,S.post(t,n)];case 2:return i.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return this.providerService.deleteProvider(e.toString()),12==e&&(this.email=""),11==e&&(this.phone=""),[4,H.updateStoredUser(this)];case 4:return i.sent(),[4,H.getStoredUser()];case 5:return o=i.sent(),[2,Promise.resolve(new O(o))]}}))}))},e}(),b=function(){function e(){this.storageImpl=void 0}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.getStorage=function(){var e=n.default.instance().getService("AGCStorageService");if(null!=e)return this.storageImpl||(this.storageImpl=e.getStorageNewInstance(Number(K.getUserInfoPersistence()),K.getCryptImp()?K.getCryptImp():n.default.instance().getCryptImp())),this.storageImpl;console.error("Get AGC storage Service failed.")},e}(),H=function(){function e(){this.user=null}return e.constructUserKey=function(){if(null==e.USER_KEY){var t=void 0;try{t=n.default.instance().config()}catch(e){return void console.error(e)}e.USER_KEY="agcCurrentUser:"+t.client.client_id}},e.loadStoredUser=function(){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return e.constructUserKey(),null==(t=b.getInstance().getStorage())?[2,Promise.reject("get agcStorage failed.")]:[4,t.get(e.USER_KEY).then((function(t){null!=t&&null!=t&&""!=t&&(e.INSTANCE.user=new L,e.INSTANCE.user.constructFromJson(JSON.parse(t)))})).catch((function(e){console.error("----loadStoredUser error ",e)}))];case 1:return r.sent(),[2,Promise.resolve()]}}))}))},e.getStoredUser=function(){return s(this,void 0,void 0,(function(){return u(this,(function(t){switch(t.label){case 0:return null!=e.INSTANCE.user?[3,2]:[4,this.loadStoredUser().then((function(e){}))];case 1:t.sent(),t.label=2;case 2:return[2,Promise.resolve(e.INSTANCE.user)]}}))}))},e.updateStoredUser=function(t){return s(this,void 0,void 0,(function(){return u(this,(function(r){switch(r.label){case 0:return e.INSTANCE.user=t,[4,e.saveCurrentUser()];case 1:return r.sent(),[2]}}))}))},e.saveCurrentUser=function(){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return e.constructUserKey(),null==(t=b.getInstance().getStorage())?[2]:null!=e.INSTANCE.user?[3,2]:[4,t.remove(e.USER_KEY)];case 1:return r.sent(),[3,4];case 2:return[4,t.set(e.USER_KEY,JSON.stringify(e.INSTANCE.user))];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))},e.INSTANCE=new e,e}(),M=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.URL=f.SERVER_URL+"/user-signin-anonymous",i.useJwt=0,i.provider=t,i.token=r,i.extraData=n,i.useJwt=o,i}return i(t,e),t.prototype.getBody=function(){return{provider:0,token:this.token,extraData:"",useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),x=function(e){function t(){var t=e.call(this)||this;return t.accessToken=new y,t.refreshToken=new y,t.uid="",t}return i(t,e),t.prototype.constructResponse=function(e){this.uid=e.data.uid,this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getUid=function(){return this.uid},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t}(v),G=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=f.SERVER_URL+"/user-signout",n.bodyAccessToken=t,n.refreshToken=r,n}return i(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,accessToken:this.bodyAccessToken}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),j=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return i(t,e),t}(v),J=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/user-delete",t}return i(t,e),t.prototype.getBody=function(){return""},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(h),q=function(e){function t(t,r,n,o,i){var s=e.call(this)||this;return s.URL=f.SERVER_URL+"/user-register",s.provider=-1,s.useJwt=0,s.email=t,s.phone=r,s.password=n,s.verifyCode=o,s.useJwt=i,s}return i(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getVerifyCode=function(){return this.verifyCode},t.prototype.setVerifyCode=function(e){this.verifyCode=e},t.prototype.getPassword=function(){return this.password},t.prototype.setPassword=function(e){this.password=e},t.prototype.getBody=function(){return{phone:this.phone,provider:this.provider,email:this.email,password:this.password,verifyCode:this.verifyCode,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),Y=function(){function e(){this.uid="",this.displayName="",this.photoUrl="",this.phone="",this.email="",this.provider=-1,this.openId="",this.emailVerified=-1,this.passwordSetted=-1}return e.prototype.getUid=function(){return this.uid},e.prototype.setUid=function(e){this.uid=e},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.setDisplayName=function(e){this.displayName=e},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.setPhotoUrl=function(e){this.photoUrl=e},e.prototype.getPhone=function(){return this.phone},e.prototype.setPhone=function(e){this.phone=e},e.prototype.getEmail=function(){return this.email},e.prototype.setEmail=function(e){this.email=e},e.prototype.getProvider=function(){return this.provider},e.prototype.setProvider=function(e){this.provider=e},e.prototype.getOpenId=function(){return this.openId},e.prototype.setOpenId=function(e){this.openId=e},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.setEmailVerified=function(e){this.emailVerified=e},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.setPasswordSetted=function(e){this.passwordSetted=e},e}(),F=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new y,t.refreshToken=new y,t.userInfo=new Y,t.providers=[],t}return i(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.setRefreshToken=function(e){this.refreshToken=e},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(v),B=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/user-signin",t.provider=-1,t.token="",t.extraData="",t.autoCreateUser=-1,t.useJwt=0,t.verifyCode="",t}return i(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.getToken=function(){return this.token},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.isAutoCreateUser=function(){return this.autoCreateUser},t.prototype.setAutoCreateUser=function(e){this.autoCreateUser=e},t.prototype.setProvider=function(e){this.provider=e},t.prototype.setToken=function(e){this.token=e},t.prototype.getBody=function(){return{provider:this.provider,token:this.token,extraData:this.extraData,autoCreateUser:this.autoCreateUser,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),W=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new y,t.refreshToken=new y,t.userInfo=new Y,t.providers=[],t}return i(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(v),K=function(){function e(){}return e.prototype.createEmailUser=function(e){return s(this,void 0,void 0,(function(){var t,r,n,o,i;return u(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyEmailUser(!1))?[2,Promise.reject(new g(r,p.getMsgByCode(r)))]:((n=new q(e.email,"",e.password,e.verifyCode,1)).setProvider(12),o=new F,[4,S.post(n,o)]):[2,Promise.reject(new g(p.INVALID_EMAIL,"emailUser invalid"))]:[2,Promise.reject(new g(p.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new L).buildUser(o),H.updateStoredUser(i),[2,Promise.resolve(new O(i))])}}))}))},e.prototype.createPhoneUser=function(e){return s(this,void 0,void 0,(function(){var t,r,n,o,i;return u(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyPhoneUser(!1))?[2,Promise.reject(new g(r,p.getMsgByCode(r)))]:((n=new q("",e.getPhone(),e.password,e.verifyCode,1)).setProvider(11),o=new F,[4,S.post(n,o)]):[2,Promise.reject(new g(p.INVALID_PHONE,"phoneUser invalid"))]:[2,Promise.reject(new g(p.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new L).buildUser(o),H.updateStoredUser(i),[2,Promise.resolve(new O(i))])}}))}))},e.prototype.signIn=function(e){return s(this,void 0,void 0,(function(){var t,r=this;return u(this,(function(n){switch(n.label){case 0:if(!e)throw new Error("credential invalid");return[4,this.getCurrentUser()];case 1:return null==(t=n.sent())||t.isAnonymous()?[2,new Promise((function(t,n){r.getUserWithCredential(e).then((function(e){t(e)})).catch((function(e){n(e)}))}))]:[2,Promise.reject(new g(p.ALREADY_SIGN_IN_USER,"already sign in a user"))]}}))}))},e.prototype.getUserWithCredential=function(e){return s(this,void 0,void 0,(function(){var t,r,n;return u(this,(function(o){switch(o.label){case 0:if(t=new B,e instanceof A)e.prepareUserAuthRequest(t),t.setAutoCreateUser(e.autoCreateUser?1:0);else{if(!(e instanceof N))throw new Error("credential type error");e.prepareUserAuthRequest(t)}return t.setUseJwt(1),r=new W,[4,S.post(t,r)];case 1:return o.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:((n=new L).buildUser(r),H.updateStoredUser(n),[2,Promise.resolve(new O(n))])}}))}))},e.prototype.deleteUser=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return s(this,void 0,void 0,(function(){var t,r,n,o=this;return u(this,(function(i){switch(i.label){case 0:return null==e?[3,2]:(t=e,r=new J,n=new j,r.setAccessToken(t.getAccessToken()),[4,S.post(r,n).then((function(e){return s(o,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return console.log("deleteUser success."),[4,H.updateStoredUser(null)];case 1:return e.sent(),[2]}}))}))})).catch((function(e){console.error("deleteUser fail.",e.response)}))]);case 1:i.sent(),i.label=2;case 2:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},e.prototype.signOut=function(){return s(this,void 0,void 0,(function(){return u(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return s(this,void 0,void 0,(function(){var t,r,n;return u(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(r=new G((t=e).getAccessToken(),t.getRefreshToken()),n=new j,[4,S.post(r,n).then((function(e){console.log("signOut success.")})).catch((function(e){console.error("signOut fail."+e)}))]);case 1:return o.sent(),[4,H.updateStoredUser(null)];case 2:o.sent(),o.label=3;case 3:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},e.prototype.getCurrentUser=function(){return H.getStoredUser()},e.prototype.signInAnonymously=function(){var e=this;return this.getCurrentUser().then((function(t){if(null!=t){if(t.isAnonymous()){var r=new O(t);return Promise.resolve(r)}return Promise.reject(new g(p.ALREADY_SIGN_IN_USER,"already sign in a user"))}return e.getUserWithAnonymously()})).catch((function(e){return Promise.reject(e)}))},e.prototype.getUserWithAnonymously=function(){return s(this,void 0,void 0,(function(){var e,t,r,o,i;return u(this,(function(s){switch(s.label){case 0:return null==(e=n.default.instance().getService("ClientInfoService"))?[2,Promise.reject("Get clientInfoUtil service failed.")]:(t="",[4,e.getAaid().then((function(e){t=e}))]);case 1:return s.sent(),t?(r=new M(0,t,"",1),o=new x,[4,S.post(r,o)]):[2,Promise.reject("The aaid is null.")];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new L).uid=o.getUid(),i.providerId=(0).toString(),i.tokenService.constructeSecureTokenService(o.getAccessToken(),o.getRefreshToken()),i.anonymous=!0,[4,H.updateStoredUser(i)]);case 3:return s.sent(),[2,Promise.resolve(new O(i))]}}))}))},e.prototype.setUserInfoPersistence=function(t){e.persistence=t},e.getUserInfoPersistence=function(){return e.persistence},e.prototype.setCryptImp=function(t){return t?t.decrypt&&t.encrypt?(e.cryptImpl=t,!0):(console.error("the crypt is not exist necessary methods."),!1):(console.error("the crypt is not available."),!1)},e.getCryptImp=function(){return e.cryptImpl},e.persistence=2,e.cryptImpl=void 0,e}(),z=function(){function e(){}return e.combinatePhone=function(e,t){return null==e||e.startsWith("+")||(e="+"+e),e+"-"+t},e}(),Q=function(){function e(e,t,r,n){this.countryCode="",this.phoneNumber="",this.password="",this.verifyCode="",this.countryCode=e,this.phoneNumber=t,this.password=r,this.verifyCode=n}return e.prototype.getPhone=function(){return z.combinatePhone(this.countryCode,this.phoneNumber)},e.prototype.verifyPhoneUser=function(e){return""==this.phoneNumber?p.INVALID_EMAIL:""==this.password&&e?p.PASSWORD_IS_EMPTY:""==this.verifyCode?p.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),X=function(){function e(e,t,r){this.email="",this.password="",this.verifyCode="",this.email=e,this.password=t,this.verifyCode=r}return e.prototype.verifyEmailUser=function(e){return""==this.email?p.INVALID_EMAIL:""==this.password&&e?p.PASSWORD_IS_EMPTY:""==this.verifyCode?p.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),Z=function(e){function t(t,r,n){var o=e.call(this)||this;return o.email=t,o.password=r,o.verifyCode=n,o}return i(t,e),t.prototype.getProvider=function(){return 12},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t}(N),$=function(){function e(e,t,r){this.action=e,this.lang=t,this.sendInterval=r}return e.prototype.getAction=function(){return this.action},e.prototype.getLang=function(){return this.lang},e.prototype.getSendInterval=function(){return this.sendInterval},e.prototype.setAction=function(e){this.action=e},e.prototype.setLang=function(e){this.lang=e},e.prototype.setSendInterval=function(e){this.sendInterval=e},e}(),ee=function(){function e(e,t){this.shortestInterval=e,this.validityPeriod=t}return e.prototype.getShortestInterval=function(){return this.shortestInterval},e.prototype.getValidityPeriod=function(){return this.validityPeriod},e}(),te=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=f.SERVER_URL+"/verify-code",t.phone="",t.email="",t.action=-1,t.lang="",t.sendInterval=-1,t}return i(t,e),t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getAction=function(){return this.action},t.prototype.setAction=function(e){this.action=e},t.prototype.getLang=function(){return this.lang},t.prototype.setLang=function(e){this.lang=e},t.prototype.getSendInterval=function(){return this.sendInterval},t.prototype.setSendInterval=function(e){this.sendInterval=e},t.prototype.getBody=function(){return{phone:this.phone,email:this.email,lang:this.lang,action:this.action,sendInterval:this.sendInterval}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),re=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.shortestInterval="",t.validityPeriod="",t}return i(t,e),t.prototype.constructResponse=function(e){this.shortestInterval=e.data.shortestInterval,this.validityPeriod=e.data.validityPeriod,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getShortestInterval=function(){return this.shortestInterval},t.prototype.setShortestInterval=function(e){this.shortestInterval=e},t.prototype.getValidityPeriod=function(){return this.validityPeriod},t.prototype.setValidityPeriod=function(e){this.validityPeriod=e},t}(v),ne=function(){function e(){}return e.requestEmailVerifyCode=function(e,t){var r=this.buildRequest(e,"",t);return this.requestVerifyCode(r)},e.requestPhoneVerifyCode=function(e,t,r){var n=z.combinatePhone(e,t),o=this.buildRequest("",n,r);return this.requestVerifyCode(o)},e.requestVerifyCode=function(e){return s(this,void 0,void 0,(function(){var t;return u(this,(function(r){switch(r.label){case 0:return t=new re,[4,S.post(e,t)];case 1:return r.sent(),0!=t.getRet().getCode()?[2,Promise.reject(t.getRet())]:[2,Promise.resolve(new ee(t.getShortestInterval(),t.getValidityPeriod()))]}}))}))},e.buildRequest=function(e,t,r){if(null==r)throw new Error("invalid verifyCodeSettings.");var n=new te;return n.setEmail(e),n.setPhone(t),n.setAction(r.getAction()),n.setLang(r.getLang()),n.setSendInterval(r.getSendInterval()),n},e}(),oe=function(){function e(){}return e.credentialWithPassword=function(e,t){return new Z(e,t,"")},e.credentialWithVerifyCode=function(e,t,r){return new Z(e,t,r)},e.requestVerifyCode=function(e,t,r,n){return ne.requestEmailVerifyCode(e,new $(t,r,n))},e}(),ie=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.countryCode=t,i.phoneNumber=r,i.password=n,i.verifyCode=o,i}return i(t,e),t.prototype.getProvider=function(){return 11},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t.prototype.getPhone=function(){return z.combinatePhone(this.countryCode,this.phoneNumber)},t}(N),se=function(){function e(){}return e.credentialWithPassword=function(e,t,r){return new ie(e,t,r,"")},e.credentialWithVerifyCode=function(e,t,r,n){return new ie(e,t,r,n)},e.requestVerifyCode=function(e,t,r,n,o){return ne.requestPhoneVerifyCode(e,t,new $(r,n,o))},e}(),ue=function(e){function t(t,r,n){var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return i(t,e),t.prototype.getProvider=function(){return 4},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(A),ae=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ue(e,t,r)},e}(),ce=function(e){function t(t,r,n){void 0===n&&(n=!0);var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return i(t,e),t.prototype.getProvider=function(){return 6},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(A),de=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ce(e,t,r)},e}(),pe=function(){function e(){}return e.prototype.getToken=function(e){return s(this,void 0,void 0,(function(){var t,r,o;return u(this,(function(i){switch(i.label){case 0:return n.default.instance().getCustomAuthProvider()?[4,n.default.instance().getCustomAuthProvider().getToken(e)]:[3,2];case 1:return(t=i.sent())&&t.tokenString&&t.expiration?isNaN(Number(t.expiration))||Number(t.expiration)<=0?(console.error("the customAuthProvider getToken must return valid expiration."),[2,Promise.reject("the customAuthProvider getToken must return valid expiration.")]):(r=new(function(){function e(){}return e.prototype.getExpirePeriod=function(){return Number(t.expiration)},e.prototype.getToken=function(){return t.tokenString},e}()),[2,Promise.resolve(r)]):(console.error("the customAuthProvider getToken method must contain return value: tokenString, expiration."),[2,Promise.reject("the customAuthProvider getToken method must contain return value: tokenString, expiration.")]);case 2:return[4,H.getStoredUser()];case 3:return(o=i.sent())?[2,o.getToken(e)]:[2,Promise.resolve(null)]}}))}))},e}(),he=new t.Singleton((function(){return new K}));function fe(e){return new pe}!function(e){e[e.ACTION_REGISTER_LOGIN=1001]="ACTION_REGISTER_LOGIN",e[e.ACTION_RESET_PASSWORD=1002]="ACTION_RESET_PASSWORD"}(T||(T={})),P=n.default,m={PhoneUser:Q,EmailUser:X,EmailAuthProvider:oe,PhoneAuthProvider:se,WeixinAuthProvider:ae,QQAuthProvider:de,Action:T},P.registerApiProvider("auth",(function(){return he.get()}),m),P.registerInternalService({name:"AuthProviderService",serviceFactory:fe}); | ||
***************************************************************************** */function s(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function u(e,t,r,n){return new(r||(r=Promise))((function(o,i){function s(e){try{a(n.next(e))}catch(e){i(e)}}function u(e){try{a(n.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(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())}))}function a(e,t){var r,n,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;s;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,n=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}}var c,d=function(){function e(){this.providerInfo=new Array}return e.prototype.getProviderInfo=function(){return this.providerInfo},e.prototype.setProviderInfo=function(e){this.providerInfo=e},e.prototype.updateProvider=function(e){if(e&&this.providerInfo){var t=e.provider;t&&this.deleteProvider(t),this.providerInfo.push(e)}},e.prototype.deleteProvider=function(e){var t=this.findProviderIndex(e);this.providerInfo&&null!=t&&this.providerInfo.splice(t,1)},e.prototype.findProviderIndex=function(e){var t=void 0;if(e&&this.providerInfo)for(var r=0;r<this.providerInfo.length;r++){var n=this.providerInfo[r];if(n&&e==n.provider){t=r;break}}return t},e}(),p=function(){function e(e,t,r,n){this.state=void 0,this.expiration=e,this.issuedAt=t,this.notBefore=r,this.tokenString=n}return e.prototype.getState=function(){return this.state},e.prototype.getToken=function(){return this.tokenString},e}(),h=function(){function e(e,t){this.code=t,this.errMsg=e}return e.getMsgByCode=function(t){switch(t){case e.INVALID_EMAIL:return"email can not be null or empty";case e.PASSWORD_IS_EMPTY:return"password can not be null or empty";case e.EMAIL_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty";case e.INVALID_PHONE:return"countrycode and phone can not be null or empty";case e.PHONE_VERIFICATION_IS_EMPTY:return"verify code can not be null or empty"}return""},e.NULL_TOKEN=1,e.NOT_SIGN_IN=2,e.USER_LINKED=3,e.USER_UNLINKED=4,e.ALREADY_SIGN_IN_USER=5,e.EMAIL_VERIFICATION_IS_EMPTY=6,e.PHONE_VERIFICATION_IS_EMPTY=7,e.INVALID_EMAIL=203817223,e.INVALID_PHONE=203817224,e.GET_UID_ERROR=203817728,e.UID_PRODUCTID_NOT_MATCH=203817729,e.GET_USER_INFO_ERROR=203817730,e.AUTH_METHOD_NOT_SUPPORT=203817732,e.PRODUCT_STATUS_ERROR=203817744,e.PASSWORD_VERIFICATION_CODE_OVER_LIMIT=203817811,e.INVALID_TOKEN=203817984,e.INVALID_ACCESS_TOKEN=203817985,e.INVALID_REFRESH_TOKEN=203817986,e.CLIENT_TOKEN_EXPIRED=205524993,e.ACCESS_TOKEN_EXPIRED=205524994,e.TOKEN_AND_PRODUCTID_NOT_MATCH=203817987,e.AUTH_METHOD_IS_DISABLED=203817988,e.FAIL_TO_GET_THIRD_USER_INFO=203817989,e.FAIL_TO_GET_THIRD_USER_UNION_ID=203817990,e.ACCESS_TOKEN_OVER_LIMIT=203817991,e.FAIL_TO_USER_LINK=203817992,e.FAIL_TO_USER_UNLINK=203817993,e.ANONYMOUS_SIGNIN_OVER_LIMIT=203818019,e.INVALID_APPID=203818020,e.INVALID_APPSECRET=203818021,e.GET_QQ_USERINFO_ERROR=203818023,e.QQINFO_RESPONSE_IS_NULL=203818024,e.GET_QQ_UID_ERROR=203818025,e.PASSWORD_VERIFY_CODE_ERROR=203818032,e.GOOGLE_RESPONSE_NOT_EQUAL_APPID=203818033,e.SIGNIN_USER_STATUS_ERROR=203818036,e.SIGNIN_USER_PASSWORD_ERROR=203818037,e.PROVIDER_USER_HAVE_BEEN_LINKED=203818038,e.PROVIDER_HAVE_LINKED_ONE_USER=203818039,e.FAIL_GET_PROVIDER_USER=203818040,e.CANNOT_UNLINK_ONE_PROVIDER_USER=203818041,e.VERIFY_CODE_INTERVAL_LIMIT=203818048,e.VERIFY_CODE_EMPTY=203818049,e.VERIFY_CODE_LANGUAGE_EMPTY=203818050,e.VERIFY_CODE_RECEIVER_EMPTY=203818051,e.VERIFY_CODE_ACTION_ERROR=203818052,e.VERIFY_CODE_TIME_LIMIT=203818053,e.ACCOUNT_PASSWORD_SAME=203818064,e.PASSWORD_STRENGTH_LOW=203818065,e.UPDATE_PASSWORD_ERROR=203818066,e.PASSWORD_SAME_AS_BEFORE=203818067,e.PASSWORD_IS_EMPTY=203818068,e.PASSWORD_TOO_LONG=203818071,e.SENSITIVE_OPERATION_TIMEOUT=203818081,e.ACCOUNT_HAVE_BEEN_REGISTERED=203818082,e.UPDATE_ACCOUNT_ERROR=203818084,e.USER_NOT_REGISTERED=203818087,e.VERIFY_CODE_ERROR=203818129,e.USER_HAVE_BEEN_REGISTERED=203818130,e.REGISTER_ACCOUNT_IS_EMPTY=203818132,e.VERIFY_CODE_FORMAT_ERROR=203818134,e.VERIFY_CODE_AND_PASSWORD_BOTH_NULL=203818135,e.SEND_EMAIL_FAIL=203818240,e.SEND_MESSAGE_FAIL=203818241,e.CONFIG_LOCK_TIME_ERROR=203818261,e}(),f=function(){function e(){this.sdkPlatform="",this.sdkPlatformVersion="",this.packageName="",this.appVersion="",this.headerProductId="",this.headerAppId="",this.headerClientId="",this.agcgwUrl="",this.agcgwBackUrl="",this.sdkServiceName="agconnect-auth",this.sdkVersion="1.2.1-beta";var e,t=o.default.instance().getService("AGCPlatformInfoService");t&&(this.sdkPlatform=t.getPlatform(),this.sdkPlatformVersion=t.getPlatformVersion(),this.packageName=t.getPackageName(),this.appVersion=t.getAppVersion()),this.accessToken="",this.authorization="",this.headerAaId="";try{e=o.default.instance().config()}catch(e){return void z.error(e)}this.headerProductId=e.client.product_id,this.headerClientId=e.client.client_id,this.headerAppId=e.client.app_id,this.agcgwUrl=this.addHttpToUrl(e.agcgw.url),this.agcgwBackUrl=this.addHttpToUrl(e.agcgw.backurl)}return e.prototype.getSdkServiceName=function(){return this.sdkServiceName},e.prototype.setSdkServiceName=function(e){this.sdkServiceName=e},e.prototype.getSdkVersion=function(){return this.sdkVersion},e.prototype.setSdkVersion=function(e){this.sdkVersion=e},e.prototype.getSdkPlatform=function(){return this.sdkPlatform},e.prototype.setSdkPlatform=function(e){this.sdkPlatform=e},e.prototype.getSdkPlatformVersion=function(){return this.sdkPlatformVersion},e.prototype.setSdkPlatformVersion=function(e){this.sdkPlatformVersion=e},e.prototype.getPackageName=function(){return this.packageName},e.prototype.setPackageName=function(e){this.packageName=e},e.prototype.getAppVersion=function(){return this.appVersion},e.prototype.setAppVersion=function(e){this.appVersion=e},e.prototype.getHeaderProductId=function(){return this.headerProductId},e.prototype.setHeaderProductId=function(e){this.headerProductId=e},e.prototype.getHeaderAppId=function(){return this.headerAppId},e.prototype.setHeaderAppId=function(e){this.headerAppId=e},e.prototype.getHeaderAaId=function(){return this.headerAaId},e.prototype.setHeaderAaId=function(e){this.headerAaId=e},e.prototype.getHeaderClientId=function(){return this.headerClientId},e.prototype.setHeaderClientId=function(e){this.headerClientId=e},e.prototype.getAuthorization=function(){return this.authorization},e.prototype.setAuthorization=function(e){this.authorization=e},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.setAccessToken=function(e){this.accessToken=e},e.prototype.getAgcgwUrl=function(){return this.agcgwUrl},e.prototype.setAgcgwUrl=function(e){this.agcgwUrl=e},e.prototype.getAgcgwBackUrl=function(){return this.agcgwBackUrl},e.prototype.setAgcgwBackUrl=function(e){this.agcgwBackUrl=e},e.prototype.addHttpToUrl=function(e){return e&&!e.startsWith("https://")?"https://"+e:e},e.prototype.getAuthHeader=function(){return{sdkVersion:this.getSdkVersion(),sdkPlatform:this.getSdkPlatform(),sdkPlatformVersion:this.getSdkPlatformVersion(),packageName:this.getPackageName(),appVersion:this.getAppVersion(),sdkServiceName:this.getSdkServiceName(),app_id:this.getHeaderAppId(),client_id:this.getHeaderClientId(),productId:this.getHeaderProductId(),access_token:this.getAccessToken(),Authorization:this.getAuthorization(),"Content-Type":"application/json;charset=UTF-8"}},e}(),l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t.SERVER_URL="/agc/apigw/oauth2/third/v1",t}(f),g=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=l.SERVER_URL+"/user-auth/refresh-token",n.useJwt=0,n.refreshToken=t,n.useJwt=r,n}return s(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(l),v=function(){function e(e,t){void 0===e&&(e=0),void 0===t&&(t=""),this.code=e,this.msg=t}return e.prototype.getCode=function(){return this.code},e.prototype.setCode=function(e){this.code=e},e.prototype.getMsg=function(){return this.msg},e.prototype.setMsg=function(e){this.msg=e},e}(),y=function(){function e(){this.ret=new v}return e.prototype.isSuccess=function(){return null!=this.ret&&0==this.ret.getCode()},e.prototype.getRet=function(){return this.ret},e.prototype.setRet=function(e){this.ret=e},e.prototype.constructResponse=function(e){},e}(),I=function(){function e(){this.token="",this.validPeriod=0}return e.prototype.getToken=function(){return this.token},e.prototype.setToken=function(e){this.token=e},e.prototype.getValidPeriod=function(){return this.validPeriod},e.prototype.setValidPeriod=function(e){this.validPeriod=e},e}(),T=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new I,t.productId="",t.uid="",t}return s(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(y);!function(e){e[e.POST=0]="POST",e[e.GET=1]="GET"}(c||(c={}));var P,m,S,k=function(){function e(){}return e.getClientToken=function(e){return u(this,void 0,void 0,(function(){var t,r;return a(this,(function(n){switch(n.label){case 0:return(t=o.default.instance().getService("CredentialsService"))?(r="",[4,t.getToken(e).then((function(e){r=e.tokenString}))]):[2,Promise.reject("Get credentialProvider failed.")];case 1:return n.sent(),[2,Promise.resolve(r)]}}))}))},e.post=function(t,r){return u(this,void 0,void 0,(function(){var n,o,i;return a(this,(function(s){switch(s.label){case 0:return n=t.getHeader(),o=n,i="Bearer ",[4,e.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(t,c.POST,r,n,!0,!0)]}}))}))},e.get=function(t,r){return u(this,void 0,void 0,(function(){var n,o,i;return a(this,(function(s){switch(s.label){case 0:return n=t.getHeader(),o=n,i="Bearer ",[4,e.getClientToken()];case 1:return o.Authorization=i+s.sent(),[2,this.sendRequest(t,c.GET,r,n,!0,!0)]}}))}))},e.sendRequest=function(t,r,n,i,s,c){return u(this,void 0,void 0,(function(){var d=this;return a(this,(function(p){switch(p.label){case 0:return[4,this.doNetworkOption(r,t,i,n).then((function(e){return Promise.resolve()})).catch((function(p){return u(d,void 0,void 0,(function(){var u,d,f,l,g;return a(this,(function(a){switch(a.label){case 0:return 401!=p.response.status?[2,Promise.reject(p)]:(u="0x0"+(u=p.response.data.ret.code).toString(16))==h.CLIENT_TOKEN_EXPIRED&&s?(d=o.default.instance().getService("CredentialsService"))?[4,d.removeToken()]:[2,Promise.reject("Get credentialProvider failed.")]:[3,3];case 1:return a.sent(),f=i,l="Bearer ",[4,e.getClientToken(!0)];case 2:return f.Authorization=l+a.sent(),n.setRet(new v),[2,e.sendRequest(t,r,n,i,!1,c)];case 3:return u==h.ACCESS_TOKEN_EXPIRED&&c?(g=null,[4,o.default.auth().getCurrentUser().then((function(e){return null==e?Promise.reject("no user sigIn."):(g=e,Promise.resolve())}))]):[3,6];case 4:return a.sent(),[4,g.getToken(!0).then((function(e){i.access_token=e.getToken()}))];case 5:return a.sent(),n.setRet(new v),[2,e.sendRequest(t,r,n,i,s,!1)];case 6:return[2,Promise.reject(p)]}}))}))}))];case 1:return[2,p.sent()]}}))}))},e.doNetworkOption=function(e,t,r,n){return u(this,void 0,void 0,(function(){var i;return a(this,(function(s){switch(s.label){case 0:return null==(i=o.default.instance().getService("AGCNetworkService"))?[2,Promise.reject("Get agcNetwork service failed.")]:e!=c.POST?[3,2]:[4,i.post(t.getUrl(),t.getBody(),r).then((function(e){0==e.data.ret.code&&n.constructResponse(e),n.setRet(new v(e.data.ret.code,e.data.ret.msg))})).catch((function(e){return Promise.reject(e)}))];case 1:return s.sent(),[3,4];case 2:return[4,i.get(t.getUrl(),t.getBody(),r).then((function(e){n.constructResponse(e)})).catch((function(e){return Promise.reject(e)}))];case 3:s.sent(),s.label=4;case 4:return[2,Promise.resolve()]}}))}))},e}(),E=function(){function e(){this.accessToken="",this.accessTokenValidPeriod=-1,this.refreshToken="",this.validTime=-1,this.TIME_EARLY=3e5}return e.prototype.constructeSecureTokenService=function(e,t){this.accessToken=e.getToken(),this.accessTokenValidPeriod=e.getValidPeriod(),this.refreshToken=t.getToken(),this.validTime=(new Date).getTime()+1e3*e.getValidPeriod()},e.prototype.getAccessToken=function(){return this.accessToken},e.prototype.getRefreshToken=function(){return this.refreshToken},e.prototype.isValidAccessToken=function(){return null!=this.accessToken&&this.remainToRefreshTime()>0},e.prototype.remainToRefreshTime=function(){return this.validTime-(new Date).getTime()-this.TIME_EARLY},e.prototype.fetchAccessToken=function(e){return u(this,void 0,void 0,(function(){var t,r,n,o=this;return a(this,(function(i){switch(i.label){case 0:return!e&&this.isValidAccessToken()?[2,Promise.resolve(new p(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]:this.accessToken&&this.refreshToken?(t=new g(this.refreshToken,1),r=new T,[4,k.post(t,r)]):[2,Promise.reject(new h("Token is null.",h.NULL_TOKEN))];case 1:return i.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:null==(n=r.accessToken)||n.getToken()==this.accessToken&&n.getValidPeriod()==this.accessTokenValidPeriod?[3,3]:(this.accessToken=n.getToken(),this.accessTokenValidPeriod=n.getValidPeriod(),this.validTime=(new Date).getTime()+1e3*this.accessTokenValidPeriod,[4,M.getStoredUser().then((function(e){return e&&(e.tokenService.accessToken=o.accessToken,e.tokenService.accessTokenValidPeriod=o.accessTokenValidPeriod,e.tokenService.refreshToken=o.refreshToken,e.tokenService.validTime=o.validTime),M.updateStoredUser(e)}))]);case 2:i.sent(),i.label=3;case 3:return[2,Promise.resolve(new p(this.accessTokenValidPeriod.toLocaleString(),"0","0",this.accessToken))]}}))}))},e}(),U=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/user-profile",t}return s(t,e),t.prototype.getBody=function(){},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),R=function(e){function t(){var t=e.call(this)||this;return t.displayName="",t.photoUrl="",t.emailVerified=0,t.passwordSetted=0,t.email="",t.phone="",t.userExtra=null,t}return s(t,e),t.prototype.constructResponse=function(e){this.displayName=e.data.displayName,this.photoUrl=e.data.photoUrl,this.emailVerified=e.data.emailVerified,this.passwordSetted=e.data.passwordSetted,this.email=e.data.email,this.phone=e.data.phone,this.userExtra=new _,this.userExtra.createTime=e.data.userMetaData.createTime,this.userExtra.lastSignInTime=e.data.userMetaData.lastSignInTime,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t}(y),_=function(){function e(){this.createTime="",this.lastSignInTime=""}return e.prototype.getCreateTime=function(){return this.createTime},e.prototype.getLastSignInTime=function(){return this.lastSignInTime},e}(),w=function(){function e(e,t){this.token=e,this.expirePeriod=t}return e.prototype.getToken=function(){return this.token},e.prototype.getExpirePeriod=function(){return this.expirePeriod},e}(),A=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/user-link",t.provider=-1,t.token="",t.extraData="",t.useJwt=0,t}return s(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getToken=function(){return this.token},t.prototype.setToken=function(e){this.token=e},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{provider:this.getProvider(),token:this.getToken(),extraData:this.getExtraData(),useJwt:this.getUseJwt()}},t}(l),N=function(){function e(){this.autoCreateUser=!0}return e.prototype.getProvider=function(){return-1},e}(),C=function(){function e(){this.password=void 0,this.verifyCode=void 0}return e.prototype.getProvider=function(){return-1},e}(),O=function(e){function t(){var t=e.call(this)||this;return t.providerUserInfo=void 0,t}return s(t,e),t.prototype.getProviderUserInfo=function(){return this.providerUserInfo},t.prototype.setProviderUserInfo=function(e){this.providerUserInfo=e},t.prototype.constructResponse=function(e){this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),e.data.providerUserInfo&&this.setProviderUserInfo(e.data.providerUserInfo)},t}(y),V=function(){function e(e){this.user=e}return e.prototype.getUser=function(){return this.user},e}(),D=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/user-unlink",t.provider=-1,t}return s(t,e),t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()+"&provider="+this.getProvider()},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getBody=function(){return{}},t}(l),L=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t}(y),b=function(){function e(){this.anonymous=!1,this.uid="",this.displayName="",this.photoUrl="",this.email="",this.phone="",this.providerId="",this.emailVerified=0,this.passwordSetted=0,this.providerService=new d,this.tokenService=new E}return e.prototype.constructFromJson=function(e){this.anonymous=e.anonymous,this.uid=e.uid,this.displayName=e.displayName,this.photoUrl=e.photoUrl,this.email=e.email,this.phone=e.phone,this.providerId=e.providerId,this.emailVerified=e.emailVerified,this.passwordSetted=e.passwordSetted,this.providerService.setProviderInfo(e.providerService.providerInfo),this.tokenService.accessToken=e.tokenService.accessToken,this.tokenService.accessTokenValidPeriod=e.tokenService.accessTokenValidPeriod,this.tokenService.refreshToken=e.tokenService.refreshToken,this.tokenService.validTime=e.tokenService.validTime},e.prototype.isAnonymous=function(){return this.anonymous},e.prototype.getUid=function(){return this.uid},e.prototype.getEmail=function(){return this.email},e.prototype.getPhone=function(){return this.phone},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.getProviderId=function(){return this.providerId},e.prototype.getProviderInfo=function(){for(var e=new Array,t=0;t<this.providerService.getProviderInfo().length;t++){for(var r=new Map,n=Object.keys(this.providerService.getProviderInfo()[t]),o=0;n&&o<n.length;o++)r.set(n[o],this.providerService.getProviderInfo()[t][n[o]]);e.push(r)}return e},e.prototype.getUserExtra=function(){return u(this,void 0,void 0,(function(){var e,t,r,n,o;return a(this,(function(i){switch(i.label){case 0:return e=new Q,t=null,r="",[4,e.getCurrentUser().then((function(e){r=e.getAccessToken()}))];case 1:return i.sent(),""==r?[3,3]:(n=new U,o=new R,n.setAccessToken(r),[4,k.get(n,o).then((function(e){z.log("getUserExtra success.")})).catch((function(e){z.error("getUserExtra fail."+e)}))]);case 2:if(i.sent(),0!=o.getRet().getCode())return[2,Promise.reject(o.getRet())];this.displayName=o.displayName,this.photoUrl=o.photoUrl,this.emailVerified=o.emailVerified,this.passwordSetted=o.passwordSetted,this.email=o.email,this.phone=o.phone,this.displayName=o.displayName,t=o.userExtra,M.updateStoredUser(this),i.label=3;case 3:return[2,Promise.resolve(t)]}}))}))},e.prototype.getAccessToken=function(){return this.tokenService.getAccessToken()},e.prototype.getRefreshToken=function(){return this.tokenService.getRefreshToken()},e.prototype.buildUser=function(e){this.anonymous=!1,this.uid=e.getUserInfo().getUid(),this.displayName=e.getUserInfo().getDisplayName(),this.photoUrl=e.getUserInfo().getPhotoUrl(),this.email=e.getUserInfo().getEmail(),this.emailVerified=e.getUserInfo().getEmailVerified(),this.passwordSetted=e.getUserInfo().getPasswordSetted(),this.phone=e.getUserInfo().getPhone(),this.providerId=e.getUserInfo().getProvider().toString(),this.tokenService.constructeSecureTokenService(e.getAccessToken(),e.getRefreshToken()),this.providerService.setProviderInfo(e.getProviders())},e.prototype.getToken=function(e){return this.tokenService.fetchAccessToken(e).then((function(e){return Promise.resolve(new w(e.tokenString,parseInt(e.expiration)))})).catch((function(e){return Promise.reject(e)}))},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.link=function(e){return u(this,void 0,void 0,(function(){var t,r,n,o,i,s,u,c,d;return a(this,(function(a){switch(a.label){case 0:if(!e)return[2,Promise.reject("credential cannot be null or undefined")];if(t=new A,e instanceof N)e.prepareUserLinkRequest(t);else{if(!(e instanceof C))return[2,Promise.reject("credential type error")];e.prepareUserLinkRequest(t)}return[4,this.getToken(!1)];case 1:return r=a.sent(),t.setAccessToken(r.getToken()),n=new O,[4,k.post(t,n)];case 2:return a.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return(o=n.getProviderUserInfo())&&(i={},this.userInfoToMap(o,i),this.anonymous&&this.updateAnonymousUserInfo(i),this.providerService.updateProvider(i),i.provider&&(s=i.provider,12..toString()==s?(u=i.email)&&(this.email=u,this.emailVerified=1):11..toString()==s&&(c=i.phone)&&(this.phone=c),e instanceof C&&null!=e.password&&null!=e.password&&""!=e.password&&(this.passwordSetted=1))),[4,M.updateStoredUser(this)];case 4:return a.sent(),[4,M.getStoredUser()];case 5:return d=a.sent(),[2,Promise.resolve(new V(d))]}}))}))},e.prototype.unlink=function(e){return u(this,void 0,void 0,(function(){return a(this,(function(t){return e?this.anonymous?[2,Promise.reject(new v(h.USER_UNLINKED,"anonymous user can not unlink"))]:[2,this.sendUnlinkRequest(e)]:[2,Promise.reject("credentialProvider cannot be null or undefined")]}))}))},e.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},e.prototype.updateAnonymousUserInfo=function(e){this.anonymous=!1,this.displayName=e.displayName?e.displayName:"",this.photoUrl=e.photoUrl?e.photoUrl:"",this.email=e.email?e.email:"",this.phone=e.phone?e.phone:"",this.providerId=e.provider?e.provider:""},e.prototype.sendUnlinkRequest=function(e){return u(this,void 0,void 0,(function(){var t,r,n,o;return a(this,(function(i){switch(i.label){case 0:return(t=new D).setProvider(e),[4,this.getToken(!1)];case 1:return r=i.sent(),t.setAccessToken(r.getToken()),n=new L,[4,k.post(t,n)];case 2:return i.sent(),0==n.getRet().getCode()?[3,3]:[2,Promise.reject(n.getRet())];case 3:return this.providerService.deleteProvider(e.toString()),12==e&&(this.email="",this.emailVerified=0),11==e&&(this.phone=""),null==this.providerService.findProviderIndex(12..toString())&&null==this.providerService.findProviderIndex(11..toString())&&(this.passwordSetted=0),[4,M.updateStoredUser(this)];case 4:return i.sent(),[4,M.getStoredUser()];case 5:return o=i.sent(),[2,Promise.resolve(new V(o))]}}))}))},e}(),H=function(){function e(){this.storageImpl=void 0}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.prototype.getStorage=function(){var e=o.default.instance().getService("AGCStorageService");if(null!=e)return this.storageImpl||(this.storageImpl=e.getStorageNewInstance(Number(Q.getUserInfoPersistence()),Q.getCryptImp()?Q.getCryptImp():o.default.instance().getCryptImp())),this.storageImpl;z.error("Get AGC storage Service failed.")},e}(),M=function(){function e(){this.user=null}return e.constructUserKey=function(){if(null==e.USER_KEY){var t=void 0;try{t=o.default.instance().config()}catch(e){return void z.error(e)}e.USER_KEY="agcCurrentUser:"+t.client.client_id}},e.loadStoredUser=function(){return u(this,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return e.constructUserKey(),null==(t=H.getInstance().getStorage())?[2,Promise.reject("get agcStorage failed.")]:[4,t.get(e.USER_KEY).then((function(t){null!=t&&null!=t&&""!=t&&(e.INSTANCE.user=new b,e.INSTANCE.user.constructFromJson(JSON.parse(t)))})).catch((function(e){z.error("----loadStoredUser error ",e)}))];case 1:return r.sent(),[2,Promise.resolve()]}}))}))},e.getStoredUser=function(){return u(this,void 0,void 0,(function(){return a(this,(function(t){switch(t.label){case 0:return null!=e.INSTANCE.user?[3,2]:[4,this.loadStoredUser().then((function(e){}))];case 1:t.sent(),t.label=2;case 2:return[2,Promise.resolve(e.INSTANCE.user)]}}))}))},e.updateStoredUser=function(t){return u(this,void 0,void 0,(function(){return a(this,(function(r){switch(r.label){case 0:return e.INSTANCE.user=t,[4,e.saveCurrentUser()];case 1:return r.sent(),[2]}}))}))},e.saveCurrentUser=function(){return u(this,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return e.constructUserKey(),null==(t=H.getInstance().getStorage())?[2]:null!=e.INSTANCE.user?[3,2]:[4,t.remove(e.USER_KEY)];case 1:return r.sent(),[3,4];case 2:return[4,t.set(e.USER_KEY,JSON.stringify(e.INSTANCE.user))];case 3:r.sent(),r.label=4;case 4:return[2]}}))}))},e.INSTANCE=new e,e}(),x=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.URL=l.SERVER_URL+"/user-signin-anonymous",i.useJwt=0,i.provider=t,i.token=r,i.extraData=n,i.useJwt=o,i}return s(t,e),t.prototype.getBody=function(){return{provider:0,token:this.token,extraData:"",useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(l),G=function(e){function t(){var t=e.call(this)||this;return t.accessToken=new I,t.refreshToken=new I,t.uid="",t}return s(t,e),t.prototype.constructResponse=function(e){this.uid=e.data.uid,this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getUid=function(){return this.uid},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t}(y),j=function(e){function t(t,r){var n=e.call(this)||this;return n.URL=l.SERVER_URL+"/user-signout",n.bodyAccessToken=t,n.refreshToken=r,n}return s(t,e),t.prototype.getBody=function(){return{refreshToken:this.refreshToken,accessToken:this.bodyAccessToken}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),J=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return s(t,e),t}(y),q=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/user-delete",t}return s(t,e),t.prototype.getBody=function(){return""},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(f),Y=function(e){function t(t,r,n,o,i){var s=e.call(this)||this;return s.URL=l.SERVER_URL+"/user-register",s.provider=-1,s.useJwt=0,s.email=t,s.phone=r,s.password=n,s.verifyCode=o,s.useJwt=i,s}return s(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.setProvider=function(e){this.provider=e},t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getVerifyCode=function(){return this.verifyCode},t.prototype.setVerifyCode=function(e){this.verifyCode=e},t.prototype.getPassword=function(){return this.password},t.prototype.setPassword=function(e){this.password=e},t.prototype.getBody=function(){return{phone:this.phone,provider:this.provider,email:this.email,password:this.password,verifyCode:this.verifyCode,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(l),F=function(){function e(){this.uid="",this.displayName="",this.photoUrl="",this.phone="",this.email="",this.provider=-1,this.openId="",this.emailVerified=0,this.passwordSetted=0}return e.prototype.getUid=function(){return this.uid},e.prototype.setUid=function(e){this.uid=e},e.prototype.getDisplayName=function(){return this.displayName},e.prototype.setDisplayName=function(e){this.displayName=e},e.prototype.getPhotoUrl=function(){return this.photoUrl},e.prototype.setPhotoUrl=function(e){this.photoUrl=e},e.prototype.getPhone=function(){return this.phone},e.prototype.setPhone=function(e){this.phone=e},e.prototype.getEmail=function(){return this.email},e.prototype.setEmail=function(e){this.email=e},e.prototype.getProvider=function(){return this.provider},e.prototype.setProvider=function(e){this.provider=e},e.prototype.getOpenId=function(){return this.openId},e.prototype.setOpenId=function(e){this.openId=e},e.prototype.getEmailVerified=function(){return this.emailVerified},e.prototype.setEmailVerified=function(e){this.emailVerified=e},e.prototype.getPasswordSetted=function(){return this.passwordSetted},e.prototype.setPasswordSetted=function(e){this.passwordSetted=e},e}(),B=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new I,t.refreshToken=new I,t.userInfo=new F,t.providers=[],t}return s(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.setAccessToken=function(e){this.accessToken=e},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.setRefreshToken=function(e){this.refreshToken=e},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(y),W=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/user-signin",t.provider=-1,t.token="",t.extraData="",t.autoCreateUser=-1,t.useJwt=0,t.verifyCode="",t}return s(t,e),t.prototype.getUseJwt=function(){return this.useJwt},t.prototype.setUseJwt=function(e){this.useJwt=e},t.prototype.getProvider=function(){return this.provider},t.prototype.getToken=function(){return this.token},t.prototype.getExtraData=function(){return this.extraData},t.prototype.setExtraData=function(e){this.extraData=e},t.prototype.isAutoCreateUser=function(){return this.autoCreateUser},t.prototype.setAutoCreateUser=function(e){this.autoCreateUser=e},t.prototype.setProvider=function(e){this.provider=e},t.prototype.setToken=function(e){this.token=e},t.prototype.getBody=function(){return{provider:this.provider,token:this.token,extraData:this.extraData,autoCreateUser:this.autoCreateUser,useJwt:this.useJwt}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(l),K=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.accessToken=new I,t.refreshToken=new I,t.userInfo=new F,t.providers=[],t}return s(t,e),t.prototype.constructResponse=function(e){this.accessToken.setToken(e.data.accessToken.token),this.accessToken.setValidPeriod(e.data.accessToken.validPeriod),this.refreshToken.setToken(e.data.refreshToken.token),this.refreshToken.setValidPeriod(e.data.refreshToken.validPeriod),this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code),this.userInfo.setUid(e.data.userInfo.uid),this.userInfo.setEmail(e.data.userInfo.email),this.userInfo.setPhone(e.data.userInfo.phone),this.userInfo.setProvider(e.data.userInfo.provider),this.userInfo.setEmailVerified(e.data.userInfo.emailVerified),this.userInfo.setPasswordSetted(e.data.userInfo.passwordSetted),this.userInfo.setDisplayName(e.data.userInfo.displayName),this.userInfo.setOpenId(e.data.userInfo.openId),this.userInfo.setPhotoUrl(e.data.userInfo.photoUrl);for(var t=new Array,r=0;r<e.data.providers.length;r++){var n={};this.userInfoToMap(e.data.providers[r],n),t.push(n)}this.providers=t},t.prototype.getAccessToken=function(){return this.accessToken},t.prototype.getRefreshToken=function(){return this.refreshToken},t.prototype.getUserInfo=function(){return this.userInfo},t.prototype.getProviders=function(){return this.providers},t.prototype.userInfoToMap=function(e,t){e.uid&&(t.uid=e.uid.toString()),e.displayName&&(t.displayName=e.displayName.toString()),e.photoUrl&&(t.photoUrl=e.photoUrl.toString()),e.email&&(t.email=e.email.toString()),e.phone&&(t.phone=e.phone.toString()),e.provider&&(t.provider=e.provider.toString()),e.openId&&(t.openId=e.openId.toString())},t}(y),z=r.Logger.createLogger("auth"),Q=function(){function e(){}return e.prototype.createEmailUser=function(e){return u(this,void 0,void 0,(function(){var t,r,n,o,i;return a(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyEmailUser(!1))?[2,Promise.reject(new v(r,h.getMsgByCode(r)))]:((n=new Y(e.email,"",e.password,e.verifyCode,1)).setProvider(12),o=new B,[4,k.post(n,o)]):[2,Promise.reject(new v(h.INVALID_EMAIL,"emailUser invalid"))]:[2,Promise.reject(new v(h.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new b).buildUser(o),M.updateStoredUser(i),[2,Promise.resolve(new V(i))])}}))}))},e.prototype.createPhoneUser=function(e){return u(this,void 0,void 0,(function(){var t,r,n,o,i;return a(this,(function(s){switch(s.label){case 0:return[4,this.getCurrentUser()];case 1:return null==(t=s.sent())||t.isAnonymous()?e?0!=(r=e.verifyPhoneUser(!1))?[2,Promise.reject(new v(r,h.getMsgByCode(r)))]:((n=new Y("",e.getPhone(),e.password,e.verifyCode,1)).setProvider(11),o=new B,[4,k.post(n,o)]):[2,Promise.reject(new v(h.INVALID_PHONE,"phoneUser invalid"))]:[2,Promise.reject(new v(h.ALREADY_SIGN_IN_USER,"already sign in a user"))];case 2:return s.sent(),0!=o.getRet().getCode()?[2,Promise.reject(o.getRet())]:((i=new b).buildUser(o),M.updateStoredUser(i),[2,Promise.resolve(new V(i))])}}))}))},e.prototype.signIn=function(e){return u(this,void 0,void 0,(function(){var t,r=this;return a(this,(function(n){switch(n.label){case 0:if(!e)throw new Error("credential invalid");return[4,this.getCurrentUser()];case 1:return null==(t=n.sent())||t.isAnonymous()?[2,new Promise((function(t,n){r.getUserWithCredential(e).then((function(e){t(e)})).catch((function(e){n(e)}))}))]:[2,Promise.reject(new v(h.ALREADY_SIGN_IN_USER,"already sign in a user"))]}}))}))},e.prototype.getUserWithCredential=function(e){return u(this,void 0,void 0,(function(){var t,r,n;return a(this,(function(o){switch(o.label){case 0:if(t=new W,e instanceof N)e.prepareUserAuthRequest(t),t.setAutoCreateUser(e.autoCreateUser?1:0);else{if(!(e instanceof C))throw new Error("credential type error");e.prepareUserAuthRequest(t)}return t.setUseJwt(1),r=new K,[4,k.post(t,r)];case 1:return o.sent(),0!=r.getRet().getCode()?[2,Promise.reject(r.getRet())]:((n=new b).buildUser(r),M.updateStoredUser(n),[2,Promise.resolve(new V(n))])}}))}))},e.prototype.deleteUser=function(){return u(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return u(this,void 0,void 0,(function(){var t,r,n;return a(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(t=e,r=new q,n=new J,r.setAccessToken(t.getAccessToken()),[4,k.post(r,n)]);case 1:return o.sent(),0!=n.getRet().getCode()?(z.error("deleteUser fail."),[2,Promise.reject(n.getRet())]):[4,M.updateStoredUser(null)];case 2:return o.sent(),z.log("deleteUser success."),[2,Promise.resolve()];case 3:return z.error("deleteUser fail, no user signed in."),[2,Promise.reject(new v(h.NOT_SIGN_IN,"no user signed in"))]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},e.prototype.signOut=function(){return u(this,void 0,void 0,(function(){return a(this,(function(e){switch(e.label){case 0:return[4,this.getCurrentUser().then((function(e){return u(this,void 0,void 0,(function(){var t,r,n;return a(this,(function(o){switch(o.label){case 0:return null==e?[3,3]:(r=new j((t=e).getAccessToken(),t.getRefreshToken()),n=new J,[4,k.post(r,n).then((function(e){z.log("signOut success.")})).catch((function(e){z.error("signOut fail."+e)}))]);case 1:return o.sent(),[4,M.updateStoredUser(null)];case 2:o.sent(),o.label=3;case 3:return[2]}}))}))}))];case 1:return e.sent(),[2,Promise.resolve()]}}))}))},e.prototype.getCurrentUser=function(){return M.getStoredUser()},e.prototype.signInAnonymously=function(){var e=this;return this.getCurrentUser().then((function(t){if(null!=t){if(t.isAnonymous()){var r=new V(t);return Promise.resolve(r)}return Promise.reject(new v(h.ALREADY_SIGN_IN_USER,"already sign in a user"))}return e.getUserWithAnonymously()})).catch((function(e){return Promise.reject(e)}))},e.prototype.getUserWithAnonymously=function(){return u(this,void 0,void 0,(function(){var e,t,r,n,i;return a(this,(function(s){switch(s.label){case 0:return null==(e=o.default.instance().getService("ClientInfoService"))?[2,Promise.reject("Get clientInfoUtil service failed.")]:(t="",[4,e.getAaid().then((function(e){t=e}))]);case 1:return s.sent(),t?(r=new x(0,t,"",1),n=new G,[4,k.post(r,n)]):[2,Promise.reject("The aaid is null.")];case 2:return s.sent(),0!=n.getRet().getCode()?[2,Promise.reject(n.getRet())]:((i=new b).uid=n.getUid(),i.providerId=(0).toString(),i.tokenService.constructeSecureTokenService(n.getAccessToken(),n.getRefreshToken()),i.anonymous=!0,[4,M.updateStoredUser(i)]);case 3:return s.sent(),[2,Promise.resolve(new V(i))]}}))}))},e.prototype.setUserInfoPersistence=function(t){e.persistence=t},e.getUserInfoPersistence=function(){return e.persistence},e.prototype.setCryptImp=function(t){return t?t.decrypt&&t.encrypt?(e.cryptImpl=t,!0):(z.error("the crypt is not exist necessary methods."),!1):(z.error("the crypt is not available."),!1)},e.getCryptImp=function(){return e.cryptImpl},e.persistence=2,e.cryptImpl=void 0,e}(),X=function(){function e(){}return e.combinatePhone=function(e,t){return null==e||e.startsWith("+")||(e="+"+e),e+"-"+t},e}(),Z=function(){function e(e,t,r,n){this.countryCode="",this.phoneNumber="",this.password="",this.verifyCode="",this.countryCode=e,this.phoneNumber=t,this.password=r,this.verifyCode=n}return e.prototype.getPhone=function(){return X.combinatePhone(this.countryCode,this.phoneNumber)},e.prototype.verifyPhoneUser=function(e){return""==this.phoneNumber?h.INVALID_EMAIL:""==this.password&&e?h.PASSWORD_IS_EMPTY:""==this.verifyCode?h.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),$=function(){function e(e,t,r){this.email="",this.password="",this.verifyCode="",this.email=e,this.password=t,this.verifyCode=r}return e.prototype.verifyEmailUser=function(e){return""==this.email?h.INVALID_EMAIL:""==this.password&&e?h.PASSWORD_IS_EMPTY:""==this.verifyCode?h.EMAIL_VERIFICATION_IS_EMPTY:0},e}(),ee=function(e){function t(t,r,n){var o=e.call(this)||this;return o.email=t,o.password=r,o.verifyCode=n,o}return s(t,e),t.prototype.getProvider=function(){return 12},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(12),e.setToken(this.email),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t}(C),te=function(){function e(e,t,r){this.action=e,this.lang=t,this.sendInterval=r}return e.prototype.getAction=function(){return this.action},e.prototype.getLang=function(){return this.lang},e.prototype.getSendInterval=function(){return this.sendInterval},e.prototype.setAction=function(e){this.action=e},e.prototype.setLang=function(e){this.lang=e},e.prototype.setSendInterval=function(e){this.sendInterval=e},e}(),re=function(){function e(e,t){this.shortestInterval=e,this.validityPeriod=t}return e.prototype.getShortestInterval=function(){return this.shortestInterval},e.prototype.getValidityPeriod=function(){return this.validityPeriod},e}(),ne=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.URL=l.SERVER_URL+"/verify-code",t.phone="",t.email="",t.action=-1,t.lang="",t.sendInterval=-1,t}return s(t,e),t.prototype.getPhone=function(){return this.phone},t.prototype.setPhone=function(e){this.phone=e},t.prototype.getEmail=function(){return this.email},t.prototype.setEmail=function(e){this.email=e},t.prototype.getAction=function(){return this.action},t.prototype.setAction=function(e){this.action=e},t.prototype.getLang=function(){return this.lang},t.prototype.setLang=function(e){this.lang=e},t.prototype.getSendInterval=function(){return this.sendInterval},t.prototype.setSendInterval=function(e){this.sendInterval=e},t.prototype.getBody=function(){return{phone:this.phone,email:this.email,lang:this.lang,action:this.action,sendInterval:this.sendInterval}},t.prototype.getHeader=function(){return this.getAuthHeader()},t.prototype.getUrl=function(){return this.getAgcgwUrl()+this.URL+"?productId="+this.getHeaderProductId()},t}(l),oe=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.shortestInterval="",t.validityPeriod="",t}return s(t,e),t.prototype.constructResponse=function(e){this.shortestInterval=e.data.shortestInterval,this.validityPeriod=e.data.validityPeriod,this.ret.setMsg(e.data.ret.msg),this.ret.setCode(e.data.ret.code)},t.prototype.getShortestInterval=function(){return this.shortestInterval},t.prototype.setShortestInterval=function(e){this.shortestInterval=e},t.prototype.getValidityPeriod=function(){return this.validityPeriod},t.prototype.setValidityPeriod=function(e){this.validityPeriod=e},t}(y),ie=function(){function e(){}return e.requestEmailVerifyCode=function(e,t){var r=this.buildRequest(e,"",t);return this.requestVerifyCode(r)},e.requestPhoneVerifyCode=function(e,t,r){var n=X.combinatePhone(e,t),o=this.buildRequest("",n,r);return this.requestVerifyCode(o)},e.requestVerifyCode=function(e){return u(this,void 0,void 0,(function(){var t;return a(this,(function(r){switch(r.label){case 0:return t=new oe,[4,k.post(e,t)];case 1:return r.sent(),0!=t.getRet().getCode()?[2,Promise.reject(t.getRet())]:[2,Promise.resolve(new re(t.getShortestInterval(),t.getValidityPeriod()))]}}))}))},e.buildRequest=function(e,t,r){if(null==r)throw new Error("invalid verifyCodeSettings.");var n=new ne;return n.setEmail(e),n.setPhone(t),n.setAction(r.getAction()),n.setLang(r.getLang()),n.setSendInterval(r.getSendInterval()),n},e}(),se=function(){function e(){}return e.credentialWithPassword=function(e,t){return new ee(e,t,"")},e.credentialWithVerifyCode=function(e,t,r){return new ee(e,t,r)},e.requestVerifyCode=function(e,t,r,n){return ie.requestEmailVerifyCode(e,new te(t,r,n))},e}(),ue=function(e){function t(t,r,n,o){var i=e.call(this)||this;return i.countryCode=t,i.phoneNumber=r,i.password=n,i.verifyCode=o,i}return s(t,e),t.prototype.getProvider=function(){return 11},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData())},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(11),e.setToken(this.getPhone()),e.setExtraData(this.generateExtraData()),e.setUseJwt(1)},t.prototype.generateExtraData=function(){return JSON.stringify({password:this.password,verifyCode:this.verifyCode})},t.prototype.getPhone=function(){return X.combinatePhone(this.countryCode,this.phoneNumber)},t}(C),ae=function(){function e(){}return e.credentialWithPassword=function(e,t,r){return new ue(e,t,r,"")},e.credentialWithVerifyCode=function(e,t,r,n){return new ue(e,t,r,n)},e.requestVerifyCode=function(e,t,r,n,o){return ie.requestPhoneVerifyCode(e,t,new te(r,n,o))},e}(),ce=function(e){function t(t,r,n){var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return s(t,e),t.prototype.getProvider=function(){return 4},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(4),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(N),de=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new ce(e,t,r)},e}(),pe=function(e){function t(t,r,n){void 0===n&&(n=!0);var o=e.call(this)||this;return o.token=t,o.openId=r,o.autoCreateUser=n,o}return s(t,e),t.prototype.getProvider=function(){return 6},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(6),e.setToken(this.token),e.setExtraData(this.openId),e.setUseJwt(1)},t}(N),he=function(){function e(){}return e.credentialWithToken=function(e,t,r){return void 0===r&&(r=!0),new pe(e,t,r)},e}(),fe=function(){function e(){}return e.prototype.getToken=function(e){return u(this,void 0,void 0,(function(){var t,r,n;return a(this,(function(i){switch(i.label){case 0:return o.default.instance().getCustomAuthProvider()?[4,o.default.instance().getCustomAuthProvider().getToken(e)]:[3,2];case 1:return(t=i.sent())&&t.tokenString&&t.expiration?isNaN(Number(t.expiration))||Number(t.expiration)<=0?(z.error("the customAuthProvider getToken must return valid expiration."),[2,Promise.reject("the customAuthProvider getToken must return valid expiration.")]):(r=new(function(){function e(){}return e.prototype.getExpirePeriod=function(){return Number(t.expiration)},e.prototype.getToken=function(){return t.tokenString},e}()),[2,Promise.resolve(r)]):(z.error("the customAuthProvider getToken method must contain return value: tokenString, expiration."),[2,Promise.reject("the customAuthProvider getToken method must contain return value: tokenString, expiration.")]);case 2:return[4,M.getStoredUser()];case 3:return(n=i.sent())?[2,n.getToken(e)]:[2,Promise.resolve(null)]}}))}))},e}(),le=function(e){function t(t,r){var n=e.call(this)||this;return n.token=t,n.autoCreateUser=r,n}return s(t,e),t.prototype.getProvider=function(){return 1},t.prototype.prepareUserAuthRequest=function(e){e.setProvider(1),e.setToken(this.token)},t.prototype.prepareUserLinkRequest=function(e){e.setProvider(1),e.setToken(this.token),e.setUseJwt(1)},t}(N),ge=function(){function e(){}return e.credentialWithToken=function(e,t){return void 0===t&&(t=!0),new le(e,t)},e}(),ve=new t.Singleton((function(){return new Q}));function ye(e){return new fe}!function(e){e[e.ACTION_REGISTER_LOGIN=1001]="ACTION_REGISTER_LOGIN",e[e.ACTION_RESET_PASSWORD=1002]="ACTION_RESET_PASSWORD"}(P||(P={})),m=o.default,S={PhoneUser:Z,EmailUser:$,EmailAuthProvider:se,PhoneAuthProvider:ae,WeixinAuthProvider:de,QQAuthProvider:he,HwIdAuthProvider:ge,Action:P},m.registerApiProvider("auth",(function(){return ve.get()}),S),m.registerInternalService({name:"AuthProviderService",serviceFactory:ye}); |
@@ -5,4 +5,4 @@ import { AGConnectAuthCredential } from '@agconnect/auth-types'; | ||
export declare abstract class AccountCredential implements AGConnectAuthCredential { | ||
password: string; | ||
verifyCode: string; | ||
password: string | undefined; | ||
verifyCode: string | undefined; | ||
getProvider(): number; | ||
@@ -9,0 +9,0 @@ /** |
@@ -13,3 +13,3 @@ export declare class ProviderInfoService { | ||
deleteProvider(provider: string): void; | ||
private findProviderIndex; | ||
findProviderIndex(provider: string): number | undefined; | ||
} |
{ | ||
"name": "@agconnect/auth", | ||
"version": "1.2.0", | ||
"version": "1.2.1-beta", | ||
"main": "./dist/index.node.cjs.js", | ||
"module": "./dist/index.esm.js", | ||
"description": "@agconnect/auth", | ||
"author": " ", | ||
"author": "https://developer.huawei.com/", | ||
"license": "ISC", | ||
@@ -28,16 +28,17 @@ "scripts": { | ||
"dependencies": { | ||
"@agconnect/api": "1.2.0", | ||
"@agconnect/api-types": "1.2.0", | ||
"@agconnect/auth-types": "1.2.0", | ||
"@agconnect/baseservice": "1.2.0", | ||
"@agconnect/baseservice-types": "1.2.0", | ||
"@agconnect/core": "1.2.0", | ||
"@agconnect/instance": "1.2.0", | ||
"@agconnect/instance-types": "1.2.0", | ||
"@agconnect/network": "1.2.0", | ||
"@agconnect/network-types": "1.2.0", | ||
"@agconnect/storage": "1.2.0", | ||
"@agconnect/storage-types": "1.2.0", | ||
"@agconnect/util": "1.2.0" | ||
"@agconnect/api": "1.2.1-beta", | ||
"@agconnect/api-types": "1.2.1-beta", | ||
"@agconnect/auth-types": "1.2.1-beta", | ||
"@agconnect/baseservice": "1.2.1-beta", | ||
"@agconnect/baseservice-types": "1.2.1-beta", | ||
"@agconnect/core": "1.2.1-beta", | ||
"@agconnect/instance": "1.2.1-beta", | ||
"@agconnect/instance-types": "1.2.1-beta", | ||
"@agconnect/network": "1.2.1-beta", | ||
"@agconnect/network-types": "1.2.1-beta", | ||
"@agconnect/storage": "1.2.1-beta", | ||
"@agconnect/storage-types": "1.2.1-beta", | ||
"@agconnect/util": "1.2.1-beta", | ||
"@agconnect/log": "1.2.1-beta" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
146012
1606
14
3
+ Added@agconnect/log@1.2.1-beta
+ Added@agconnect/api@1.2.1-beta(transitive)
+ Added@agconnect/api-types@1.2.1-beta(transitive)
+ Added@agconnect/auth-types@1.2.1-beta(transitive)
+ Added@agconnect/baseservice@1.2.1-beta(transitive)
+ Added@agconnect/baseservice-types@1.2.1-beta(transitive)
+ Added@agconnect/core@1.2.1-beta(transitive)
+ Added@agconnect/instance@1.2.1-beta(transitive)
+ Added@agconnect/instance-types@1.2.1-beta(transitive)
+ Added@agconnect/log@1.2.1-beta(transitive)
+ Added@agconnect/network@1.2.1-beta(transitive)
+ Added@agconnect/network-types@1.2.1-beta(transitive)
+ Added@agconnect/storage@1.2.1-beta(transitive)
+ Added@agconnect/storage-types@1.2.1-beta(transitive)
+ Added@agconnect/util@1.2.1-beta(transitive)
- Removed@agconnect/api@1.2.0(transitive)
- Removed@agconnect/api-types@1.2.0(transitive)
- Removed@agconnect/auth-types@1.2.0(transitive)
- Removed@agconnect/baseservice@1.2.0(transitive)
- Removed@agconnect/baseservice-types@1.2.0(transitive)
- Removed@agconnect/core@1.2.0(transitive)
- Removed@agconnect/instance@1.2.0(transitive)
- Removed@agconnect/instance-types@1.2.0(transitive)
- Removed@agconnect/network@1.2.0(transitive)
- Removed@agconnect/network-types@1.2.0(transitive)
- Removed@agconnect/storage@1.2.0(transitive)
- Removed@agconnect/storage-types@1.2.0(transitive)
- Removed@agconnect/util@1.2.0(transitive)
Updated@agconnect/api@1.2.1-beta
Updated@agconnect/core@1.2.1-beta
Updated@agconnect/util@1.2.1-beta