@cloudbase/auth 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/adapter.js +19 -16
- package/dist/cjs/index.d.ts +107 -33
- package/dist/cjs/index.js +1529 -428
- package/dist/cjs/type.d.ts +242 -0
- package/dist/cjs/type.js +3 -0
- package/dist/cjs/utils.d.ts +5 -0
- package/dist/cjs/utils.js +59 -0
- package/dist/esm/adapter.js +19 -16
- package/dist/esm/index.d.ts +107 -33
- package/dist/esm/index.js +1527 -426
- package/dist/esm/type.d.ts +242 -0
- package/dist/esm/type.js +2 -0
- package/dist/esm/utils.d.ts +5 -0
- package/dist/esm/utils.js +51 -0
- package/dist/miniprogram/index.js +1 -1
- package/package.json +6 -6
- package/src/adapter.ts +13 -8
- package/src/index.ts +1606 -363
- package/src/type.ts +306 -0
- package/src/utils.ts +69 -0
- package/tsconfig.json +1 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ICloudbase, ICloudbaseConfig } from '@cloudbase/types';
|
|
2
2
|
import type { ICloudbaseCache } from '@cloudbase/types/cache';
|
|
3
3
|
import type { ICloudbaseRequest } from '@cloudbase/types/request';
|
|
4
|
-
import type { ICloudbaseAuthConfig, IUser,
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
4
|
+
import type { ICloudbaseAuthConfig, IUser, ILoginState } from '@cloudbase/types/auth';
|
|
5
|
+
import type { AuthOptions, Credentials } from '@cloudbase/oauth';
|
|
6
|
+
import { CloudbaseOAuth, AuthError, authModels } from '@cloudbase/oauth';
|
|
7
|
+
import { CommonRes, DeleteMeReq, GetClaimsRes, GetUserIdentitiesRes, GetUserRes, LinkIdentityReq, LinkIdentityRes, OnAuthStateChangeCallback, ReauthenticateRes, ResendReq, ResendRes, ResetPasswordForEmailRes, ResetPasswordForOldReq, SetSessionReq, SignInAnonymouslyReq, SignInOAuthRes, SignInRes, SignInWithIdTokenReq, SignInWithOAuthReq, SignInWithOtpReq, SignInWithOtpRes, SignInWithPasswordReq, SignUpRes, UnlinkIdentityReq, UpdateUserReq, UpdateUserWithVerificationRes, VerifyOAuthReq, VerifyOtpReq } from './type';
|
|
8
|
+
export type { SignInRes, GetUserRes, CommonRes, SignInWithOtpRes, SignInOAuthRes, GetClaimsRes, ResetPasswordForEmailRes, GetUserIdentitiesRes, LinkIdentityRes, ReauthenticateRes, ResendRes, UpdateUserWithVerificationRes, OnAuthStateChangeCallback, SignInWithPasswordReq, SignInWithIdTokenReq, SignInWithOAuthReq, VerifyOAuthReq, VerifyOtpReq, LinkIdentityReq, UnlinkIdentityReq, UpdateUserReq, SignInWithOtpReq, ResetPasswordForOldReq, ResendReq, SetSessionReq, DeleteMeReq, SignUpRes, } from './type';
|
|
8
9
|
interface UserInfo {
|
|
9
10
|
uid?: string;
|
|
10
11
|
gender?: string;
|
|
@@ -24,7 +25,7 @@ interface IUserOptions {
|
|
|
24
25
|
cache: ICloudbaseCache;
|
|
25
26
|
oauthInstance: CloudbaseOAuth;
|
|
26
27
|
}
|
|
27
|
-
declare class User implements IUser {
|
|
28
|
+
export declare class User implements IUser {
|
|
28
29
|
uid?: string;
|
|
29
30
|
gender?: string;
|
|
30
31
|
picture?: string;
|
|
@@ -55,11 +56,11 @@ declare class User implements IUser {
|
|
|
55
56
|
refresh(params?: {
|
|
56
57
|
version?: string;
|
|
57
58
|
query?: any;
|
|
58
|
-
}): Promise<
|
|
59
|
-
|
|
59
|
+
}): Promise<authModels.UserInfo>;
|
|
60
|
+
getLocalUserInfo(key?: string): string | boolean | Record<string, any>;
|
|
61
|
+
setLocalUserInfo(userInfo: any): void;
|
|
60
62
|
private getLocalUserInfoAsync;
|
|
61
63
|
private setUserInfo;
|
|
62
|
-
private setLocalUserInfo;
|
|
63
64
|
}
|
|
64
65
|
interface ILoginStateOptions extends IUserOptions {
|
|
65
66
|
envId: string;
|
|
@@ -74,9 +75,11 @@ export declare class LoginState implements ILoginState {
|
|
|
74
75
|
checkLocalStateAsync(): Promise<void>;
|
|
75
76
|
}
|
|
76
77
|
declare class Auth {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
readonly config: ICloudbaseAuthConfig;
|
|
79
|
+
oauthInstance: CloudbaseOAuth;
|
|
80
|
+
readonly cache: ICloudbaseCache;
|
|
81
|
+
private listeners;
|
|
82
|
+
private hasListenerSetUp;
|
|
80
83
|
constructor(config: ICloudbaseAuthConfig & {
|
|
81
84
|
cache: ICloudbaseCache;
|
|
82
85
|
request?: ICloudbaseRequest;
|
|
@@ -90,21 +93,12 @@ declare class Auth {
|
|
|
90
93
|
withCaptcha: boolean;
|
|
91
94
|
}): Promise<authModels.GetVerificationResponse>;
|
|
92
95
|
get currentUser(): User;
|
|
93
|
-
getCurrentUser(): Promise<User>;
|
|
94
|
-
signInAnonymously(data?: {
|
|
95
|
-
provider_token?: string;
|
|
96
|
-
}): Promise<LoginState>;
|
|
96
|
+
getCurrentUser(): Promise<(authModels.UserInfo & Partial<User>) | null>;
|
|
97
97
|
signInAnonymouslyInWx({ useWxCloud, }?: {
|
|
98
98
|
useWxCloud?: boolean;
|
|
99
99
|
}): Promise<LoginState>;
|
|
100
100
|
bindOpenId(): Promise<void>;
|
|
101
|
-
signInWithOpenId({ useWxCloud }?: {
|
|
102
|
-
useWxCloud?: boolean;
|
|
103
|
-
}): Promise<LoginState>;
|
|
104
101
|
signInWithUnionId(): Promise<LoginState>;
|
|
105
|
-
signInWithPhoneAuth({ phoneCode }: {
|
|
106
|
-
phoneCode?: string;
|
|
107
|
-
}): Promise<LoginState>;
|
|
108
102
|
signInWithSms({ verificationInfo, verificationCode, phoneNum, bindInfo, }: {
|
|
109
103
|
verificationInfo?: {
|
|
110
104
|
verification_id: string;
|
|
@@ -124,17 +118,12 @@ declare class Auth {
|
|
|
124
118
|
email?: string;
|
|
125
119
|
}): Promise<LoginState>;
|
|
126
120
|
setCustomSignFunc(getTickFn: authModels.GetCustomSignTicketFn): void;
|
|
127
|
-
signInWithCustomTicket(): Promise<LoginState>;
|
|
128
121
|
signIn(params: authModels.SignInRequest): Promise<LoginState>;
|
|
129
|
-
signUp(params: authModels.SignUpRequest): Promise<LoginState>;
|
|
130
122
|
setPassword(params: authModels.SetPasswordRequest): Promise<void>;
|
|
131
123
|
isUsernameRegistered(username: string): Promise<boolean>;
|
|
132
|
-
signOut(params?: authModels.SignoutRequest): Promise<void | authModels.SignoutReponse>;
|
|
133
124
|
hasLoginState(): LoginState | null;
|
|
134
125
|
getLoginState(): Promise<LoginState>;
|
|
135
|
-
getUserInfo(
|
|
136
|
-
version?: string;
|
|
137
|
-
}): Promise<IUserInfo>;
|
|
126
|
+
getUserInfo(): Promise<(authModels.UserInfo & Partial<User>) | null>;
|
|
138
127
|
getWedaUserInfo(): Promise<any>;
|
|
139
128
|
updateUserBasicInfo(params: authModels.ModifyUserBasicInfoRequest): Promise<void>;
|
|
140
129
|
getAuthHeader(): {};
|
|
@@ -163,7 +152,7 @@ declare class Auth {
|
|
|
163
152
|
}): Promise<Credentials>;
|
|
164
153
|
getCredentials(): Promise<Credentials>;
|
|
165
154
|
setCredentials(credentials: Credentials): Promise<void>;
|
|
166
|
-
getProviderSubType(): Promise<ProviderSubType>;
|
|
155
|
+
getProviderSubType(): Promise<authModels.ProviderSubType>;
|
|
167
156
|
createCaptchaData(params: {
|
|
168
157
|
state: string;
|
|
169
158
|
redirect_uri?: string;
|
|
@@ -183,12 +172,96 @@ declare class Auth {
|
|
|
183
172
|
modifyPassword(params: authModels.ModifyUserBasicInfoRequest): Promise<void>;
|
|
184
173
|
modifyPasswordWithoutLogin(params: authModels.ModifyPasswordWithoutLoginRequest): Promise<void>;
|
|
185
174
|
getUserBehaviorLog(params: authModels.GetUserBehaviorLog): Promise<authModels.GetUserBehaviorLogRes>;
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
175
|
+
signInWithUsername({ verificationInfo, verificationCode, username: rawUsername, bindInfo, loginType, }: {
|
|
176
|
+
verificationInfo?: authModels.GetVerificationResponse;
|
|
177
|
+
verificationCode?: string;
|
|
178
|
+
username?: string;
|
|
179
|
+
bindInfo?: any;
|
|
180
|
+
loginType?: string;
|
|
181
|
+
}): Promise<LoginState>;
|
|
182
|
+
createLoginState(params?: {
|
|
183
|
+
version?: string;
|
|
184
|
+
query?: any;
|
|
185
|
+
}, options?: {
|
|
186
|
+
asyncRefreshUser?: boolean;
|
|
187
|
+
userInfo?: any;
|
|
188
|
+
}): Promise<LoginState>;
|
|
189
|
+
setAccessKey(): Promise<void>;
|
|
190
|
+
signInAnonymously(params: SignInAnonymouslyReq): Promise<SignInRes>;
|
|
191
|
+
signUp(params: authModels.SignUpRequest & {
|
|
192
|
+
phone?: string;
|
|
193
|
+
}): Promise<SignUpRes>;
|
|
194
|
+
signOut(params?: authModels.SignoutRequest): Promise<authModels.SignoutResponse & {
|
|
195
|
+
data: Object;
|
|
196
|
+
error: AuthError;
|
|
197
|
+
}>;
|
|
198
|
+
onAuthStateChange(callback: OnAuthStateChangeCallback): {
|
|
199
|
+
data: {
|
|
200
|
+
subscription: {
|
|
201
|
+
id: string;
|
|
202
|
+
callback: OnAuthStateChangeCallback;
|
|
203
|
+
unsubscribe: () => void;
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
signInWithPassword(params: SignInWithPasswordReq): Promise<SignInRes>;
|
|
208
|
+
signInWithIdToken(params: SignInWithIdTokenReq): Promise<SignInRes>;
|
|
209
|
+
signInWithOtp(params: SignInWithOtpReq): Promise<SignInWithOtpRes>;
|
|
210
|
+
verifyOAuth(params?: VerifyOAuthReq): Promise<SignInRes | LinkIdentityRes>;
|
|
211
|
+
signInWithOAuth(params: SignInWithOAuthReq): Promise<SignInOAuthRes>;
|
|
212
|
+
getClaims(): Promise<GetClaimsRes>;
|
|
213
|
+
resetPasswordForEmail(emailOrPhone: string, options?: {
|
|
214
|
+
redirectTo?: string;
|
|
215
|
+
}): Promise<ResetPasswordForEmailRes>;
|
|
216
|
+
resetPasswordForOld(params: ResetPasswordForOldReq): Promise<{
|
|
217
|
+
data: {
|
|
218
|
+
user: import("./type").User;
|
|
219
|
+
session: import("./type").Session;
|
|
220
|
+
};
|
|
221
|
+
error: any;
|
|
222
|
+
} | {
|
|
223
|
+
data: {
|
|
224
|
+
user?: undefined;
|
|
225
|
+
session?: undefined;
|
|
226
|
+
};
|
|
227
|
+
error: AuthError;
|
|
228
|
+
}>;
|
|
229
|
+
verifyOtp(params: VerifyOtpReq): Promise<SignInRes>;
|
|
230
|
+
getSession(): Promise<SignInRes>;
|
|
231
|
+
refreshSession(refresh_token?: string): Promise<SignInRes>;
|
|
232
|
+
getUser(): Promise<GetUserRes>;
|
|
233
|
+
refreshUser(): Promise<CommonRes>;
|
|
234
|
+
updateUser(params: UpdateUserReq): Promise<GetUserRes | UpdateUserWithVerificationRes>;
|
|
235
|
+
getUserIdentities(): Promise<GetUserIdentitiesRes>;
|
|
236
|
+
linkIdentity(params: LinkIdentityReq): Promise<LinkIdentityRes>;
|
|
237
|
+
unlinkIdentity(params: UnlinkIdentityReq): Promise<CommonRes>;
|
|
238
|
+
reauthenticate(): Promise<ReauthenticateRes>;
|
|
239
|
+
resend(params: ResendReq): Promise<ResendRes>;
|
|
240
|
+
setSession(params: SetSessionReq): Promise<SignInRes>;
|
|
241
|
+
exchangeCodeForSession(): Promise<void>;
|
|
242
|
+
deleteUser(params: DeleteMeReq): Promise<CommonRes>;
|
|
243
|
+
toDefaultLoginPage(params?: authModels.ToDefaultLoginPage): Promise<CommonRes>;
|
|
244
|
+
signInWithCustomTicket(getTickFn?: authModels.GetCustomSignTicketFn): Promise<SignInRes>;
|
|
245
|
+
signInWithOpenId({ useWxCloud }?: {
|
|
246
|
+
useWxCloud?: boolean;
|
|
247
|
+
}): Promise<SignInRes>;
|
|
248
|
+
signInWithPhoneAuth({ phoneCode }: {
|
|
249
|
+
phoneCode?: string;
|
|
250
|
+
}): Promise<SignInRes>;
|
|
251
|
+
private formatPhone;
|
|
252
|
+
private notifyListeners;
|
|
253
|
+
private setupListeners;
|
|
254
|
+
private convertToUser;
|
|
255
|
+
private validateParams;
|
|
256
|
+
private validateAtLeastOne;
|
|
257
|
+
private init;
|
|
189
258
|
}
|
|
190
|
-
type TInitAuthOptions = Pick<ICloudbaseAuthConfig, 'region' | 'persistence' | 'i18n' | '
|
|
191
|
-
|
|
259
|
+
type TInitAuthOptions = Pick<ICloudbaseAuthConfig, 'region' | 'persistence' | 'i18n' | 'accessKey' | 'useWxCloud'> & Partial<AuthOptions> & {
|
|
260
|
+
detectSessionInUrl?: boolean;
|
|
261
|
+
};
|
|
262
|
+
export declare function generateAuthInstance(config: TInitAuthOptions & {
|
|
263
|
+
sdkVersion?: string;
|
|
264
|
+
}, options?: {
|
|
192
265
|
clientId: ICloudbaseConfig['clientId'];
|
|
193
266
|
env: ICloudbaseConfig['env'];
|
|
194
267
|
apiOrigin: string;
|
|
@@ -196,6 +269,7 @@ export declare function generateAuthInstance(config: TInitAuthOptions, options?:
|
|
|
196
269
|
platform?: ICloudbase['platform'];
|
|
197
270
|
app?: ICloudbase;
|
|
198
271
|
debug?: ICloudbaseAuthConfig['debug'];
|
|
272
|
+
detectSessionInUrl?: ICloudbaseAuthConfig['detectSessionInUrl'];
|
|
199
273
|
}): {
|
|
200
274
|
authInstance: Auth;
|
|
201
275
|
oauthInstance: CloudbaseOAuth;
|