@techfinityedge/koolbase-react-native 1.8.0 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +114 -60
- package/dist/auth-errors.d.ts +83 -0
- package/dist/auth-errors.js +159 -1
- package/dist/auth-storage.d.ts +26 -0
- package/dist/auth-storage.js +105 -0
- package/dist/auth.d.ts +115 -8
- package/dist/auth.js +489 -67
- package/dist/device-metadata.d.ts +36 -0
- package/dist/device-metadata.js +102 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +27 -1
- package/dist/types.d.ts +84 -0
- package/dist/types.js +16 -1
- package/package.json +11 -4
package/dist/auth.d.ts
CHANGED
|
@@ -1,29 +1,136 @@
|
|
|
1
|
-
import { KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, SendOtpParams, VerifyOtpParams } from './types';
|
|
1
|
+
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, SignInWithAppleParams, VerifyOtpParams } from './types';
|
|
2
2
|
export declare class KoolbaseAuth {
|
|
3
3
|
private config;
|
|
4
|
+
private storage;
|
|
4
5
|
private session;
|
|
6
|
+
private metadata;
|
|
7
|
+
private fetchFn;
|
|
8
|
+
private timeoutMs;
|
|
9
|
+
private ongoingRefresh;
|
|
10
|
+
private listeners;
|
|
5
11
|
constructor(config: KoolbaseConfig);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Subscribe to authentication state changes. The listener fires:
|
|
14
|
+
* - Immediately on subscribe, with the current user (or null).
|
|
15
|
+
* - On every successful login, register, refresh, session restoration.
|
|
16
|
+
* - On logout / explicit setSession(null).
|
|
17
|
+
* - On linkPhone success (user object updated with phone fields).
|
|
18
|
+
*
|
|
19
|
+
* Returns an unsubscribe function. Call it when the consumer no longer
|
|
20
|
+
* needs updates (e.g. in a React useEffect cleanup).
|
|
21
|
+
*
|
|
22
|
+
* Listener errors are swallowed so a buggy listener can't break auth
|
|
23
|
+
* state propagation to other listeners.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const unsubscribe = auth.onAuthStateChange((user) => {
|
|
27
|
+
* setCurrentUser(user);
|
|
28
|
+
* });
|
|
29
|
+
* // later:
|
|
30
|
+
* unsubscribe();
|
|
31
|
+
*/
|
|
32
|
+
onAuthStateChange(listener: AuthStateListener): () => void;
|
|
33
|
+
private fireAuthStateChange;
|
|
34
|
+
/**
|
|
35
|
+
* Compose the full header set for an outbound request: base headers,
|
|
36
|
+
* device metadata, and optionally the Authorization bearer token.
|
|
37
|
+
* Async because device metadata's first build may read from keychain.
|
|
38
|
+
*/
|
|
39
|
+
private prepareHeaders;
|
|
40
|
+
/**
|
|
41
|
+
* Low-level request helper used by every endpoint. Wires together:
|
|
42
|
+
* - The injected fetch implementation (config.fetch or global fetch)
|
|
43
|
+
* - Device metadata + x-api-key + auth header in one place
|
|
44
|
+
* - AbortController-based timeout (config.authTimeout, default 10s)
|
|
45
|
+
*
|
|
46
|
+
* On timeout, fetch rejects with an AbortError; callers see this as a
|
|
47
|
+
* non-KoolbaseAuthError exception, which restoreSession() treats as
|
|
48
|
+
* Offline (preserving optimistic state).
|
|
49
|
+
*/
|
|
50
|
+
private authRequest;
|
|
51
|
+
/**
|
|
52
|
+
* Authenticated request wrapper. Refreshes the access token if it's
|
|
53
|
+
* stale (within 1-min buffer of expiry) before issuing the call, then
|
|
54
|
+
* delegates to {@link authRequest} with includeAuth=true.
|
|
55
|
+
*/
|
|
56
|
+
private authedRequest;
|
|
57
|
+
private setSessionInternal;
|
|
58
|
+
private clearSessionInternal;
|
|
59
|
+
restoreSession(): Promise<RestoreResult>;
|
|
9
60
|
register(params: RegisterParams): Promise<KoolbaseUser>;
|
|
10
61
|
login(params: LoginParams): Promise<KoolbaseSession>;
|
|
11
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Sign in with Apple using a credential obtained from a native Apple
|
|
64
|
+
* Sign-In SDK.
|
|
65
|
+
*
|
|
66
|
+
* The SDK is library-agnostic — use any native Apple Sign-In package
|
|
67
|
+
* (`@invertase/react-native-apple-authentication`, etc.) and pass the
|
|
68
|
+
* resulting `identityToken`, optional `nonce`, and optional `fullName`.
|
|
69
|
+
*
|
|
70
|
+
* `fullName` is meaningful only on first sign-in — Apple omits name
|
|
71
|
+
* data on subsequent sign-ins. The server persists at link time and
|
|
72
|
+
* ignores on subsequent sign-ins.
|
|
73
|
+
*
|
|
74
|
+
* On success the session is persisted via the configured storage and
|
|
75
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
76
|
+
*
|
|
77
|
+
* @throws AppleSignInNotConfiguredError when Apple is not enabled in
|
|
78
|
+
* the dashboard OAuth config for this environment (400).
|
|
79
|
+
* @throws InvalidAppleTokenError when the token signature, audience,
|
|
80
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
81
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
82
|
+
* @throws AppleEmailRequiredError when Apple did not return email for
|
|
83
|
+
* a new-account sign-in (400).
|
|
84
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
85
|
+
* but auto-link rule blocked (409).
|
|
86
|
+
*/
|
|
87
|
+
signInWithApple(params: SignInWithAppleParams): Promise<KoolbaseSession>;
|
|
88
|
+
/**
|
|
89
|
+
* Parses a /v1/sdk/auth/oauth/apple response. Distinct from
|
|
90
|
+
* parseSessionResponse because OAuth error semantics differ from
|
|
91
|
+
* credential auth — status codes map to a separate error set.
|
|
92
|
+
*/
|
|
93
|
+
private parseAppleSessionResponse;
|
|
94
|
+
refresh(refreshToken?: string): Promise<KoolbaseSession>;
|
|
95
|
+
private _doRefresh;
|
|
96
|
+
logout(): Promise<boolean>;
|
|
12
97
|
forgotPassword(email: string): Promise<void>;
|
|
13
98
|
resetPassword(token: string, password: string): Promise<void>;
|
|
99
|
+
unlock(token: string): Promise<void>;
|
|
14
100
|
get currentUser(): KoolbaseUser | null;
|
|
15
101
|
get accessToken(): string | null;
|
|
16
|
-
setSession(session: KoolbaseSession | null): void
|
|
17
|
-
|
|
102
|
+
setSession(session: KoolbaseSession | null): Promise<void>;
|
|
103
|
+
/**
|
|
104
|
+
* @deprecated v1.9.0: Server endpoint /v1/sdk/auth/oauth not yet
|
|
105
|
+
* shipped. This method previously routed to /v1/auth/oauth (dashboard
|
|
106
|
+
* developer OAuth) which never created project-scoped end-user
|
|
107
|
+
* sessions. Properly implemented in v1.10.0 with provider-specific
|
|
108
|
+
* server endpoints under /v1/sdk/auth/oauth/{apple,google,github}.
|
|
109
|
+
* Use email/password sign-in for now.
|
|
110
|
+
*
|
|
111
|
+
* @throws Always throws KoolbaseAuthError('not_implemented').
|
|
112
|
+
*/
|
|
113
|
+
oauthLogin(_params: {
|
|
18
114
|
provider: string;
|
|
19
115
|
token: string;
|
|
20
116
|
email?: string;
|
|
21
117
|
name?: string;
|
|
22
118
|
avatarUrl?: string;
|
|
23
|
-
}): Promise<
|
|
119
|
+
}): Promise<never>;
|
|
24
120
|
sendOtp(params: SendOtpParams): Promise<OtpSendResult>;
|
|
25
121
|
verifyOtp(params: VerifyOtpParams): Promise<PhoneVerifyResult>;
|
|
26
122
|
linkPhone(params: LinkPhoneParams): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Release resources held by this auth client. Clears the in-memory
|
|
125
|
+
* listener set. Does not invalidate sessions or clear storage — call
|
|
126
|
+
* {@link logout} for that.
|
|
127
|
+
*/
|
|
128
|
+
dispose(): void;
|
|
27
129
|
private validatePhone;
|
|
130
|
+
private _ensureValidToken;
|
|
131
|
+
private mapUser;
|
|
132
|
+
private parseSessionResponse;
|
|
133
|
+
private checkResponse;
|
|
134
|
+
private throwTypedError;
|
|
28
135
|
private parsePhoneResponse;
|
|
29
136
|
}
|