@koolbase/core 10.0.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 +19 -0
- package/dist/cjs/analytics.d.ts +24 -0
- package/dist/cjs/analytics.js +110 -0
- package/dist/cjs/auth-errors.d.ts +117 -0
- package/dist/cjs/auth-errors.js +250 -0
- package/dist/cjs/auth.d.ts +213 -0
- package/dist/cjs/auth.js +813 -0
- package/dist/cjs/cache-store.d.ts +50 -0
- package/dist/cjs/cache-store.js +194 -0
- package/dist/cjs/conflict.d.ts +80 -0
- package/dist/cjs/conflict.js +84 -0
- package/dist/cjs/database-errors.d.ts +101 -0
- package/dist/cjs/database-errors.js +200 -0
- package/dist/cjs/database.d.ts +298 -0
- package/dist/cjs/database.js +852 -0
- package/dist/cjs/device-id.d.ts +1 -0
- package/dist/cjs/device-id.js +57 -0
- package/dist/cjs/device-metadata.d.ts +36 -0
- package/dist/cjs/device-metadata.js +94 -0
- package/dist/cjs/errors.d.ts +64 -0
- package/dist/cjs/errors.js +85 -0
- package/dist/cjs/flags.d.ts +15 -0
- package/dist/cjs/flags.js +76 -0
- package/dist/cjs/function-errors.d.ts +51 -0
- package/dist/cjs/function-errors.js +103 -0
- package/dist/cjs/functions.d.ts +15 -0
- package/dist/cjs/functions.js +83 -0
- package/dist/cjs/index.d.ts +22 -0
- package/dist/cjs/index.js +56 -0
- package/dist/cjs/messaging.d.ts +13 -0
- package/dist/cjs/messaging.js +36 -0
- package/dist/cjs/offline-state.d.ts +97 -0
- package/dist/cjs/offline-state.js +198 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pending-write.d.ts +47 -0
- package/dist/cjs/pending-write.js +22 -0
- package/dist/cjs/platform.d.ts +51 -0
- package/dist/cjs/platform.js +41 -0
- package/dist/cjs/realtime.d.ts +44 -0
- package/dist/cjs/realtime.js +195 -0
- package/dist/cjs/record.d.ts +2 -0
- package/dist/cjs/record.js +23 -0
- package/dist/cjs/shared.d.ts +9 -0
- package/dist/cjs/shared.js +43 -0
- package/dist/cjs/storage-errors.d.ts +163 -0
- package/dist/cjs/storage-errors.js +253 -0
- package/dist/cjs/storage.d.ts +198 -0
- package/dist/cjs/storage.js +451 -0
- package/dist/cjs/sync-engine.d.ts +30 -0
- package/dist/cjs/sync-engine.js +286 -0
- package/dist/cjs/types.d.ts +487 -0
- package/dist/cjs/types.js +40 -0
- package/dist/esm/analytics.d.ts +24 -0
- package/dist/esm/analytics.js +106 -0
- package/dist/esm/auth-errors.d.ts +117 -0
- package/dist/esm/auth-errors.js +222 -0
- package/dist/esm/auth.d.ts +213 -0
- package/dist/esm/auth.js +809 -0
- package/dist/esm/cache-store.d.ts +50 -0
- package/dist/esm/cache-store.js +179 -0
- package/dist/esm/conflict.d.ts +80 -0
- package/dist/esm/conflict.js +80 -0
- package/dist/esm/database-errors.d.ts +101 -0
- package/dist/esm/database-errors.js +189 -0
- package/dist/esm/database.d.ts +298 -0
- package/dist/esm/database.js +848 -0
- package/dist/esm/device-id.d.ts +1 -0
- package/dist/esm/device-id.js +54 -0
- package/dist/esm/device-metadata.d.ts +36 -0
- package/dist/esm/device-metadata.js +90 -0
- package/dist/esm/errors.d.ts +64 -0
- package/dist/esm/errors.js +79 -0
- package/dist/esm/flags.d.ts +15 -0
- package/dist/esm/flags.js +72 -0
- package/dist/esm/function-errors.d.ts +51 -0
- package/dist/esm/function-errors.js +93 -0
- package/dist/esm/functions.d.ts +15 -0
- package/dist/esm/functions.js +79 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.js +25 -0
- package/dist/esm/messaging.d.ts +13 -0
- package/dist/esm/messaging.js +32 -0
- package/dist/esm/offline-state.d.ts +97 -0
- package/dist/esm/offline-state.js +189 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/pending-write.d.ts +47 -0
- package/dist/esm/pending-write.js +19 -0
- package/dist/esm/platform.d.ts +51 -0
- package/dist/esm/platform.js +36 -0
- package/dist/esm/realtime.d.ts +44 -0
- package/dist/esm/realtime.js +191 -0
- package/dist/esm/record.d.ts +2 -0
- package/dist/esm/record.js +20 -0
- package/dist/esm/shared.d.ts +9 -0
- package/dist/esm/shared.js +39 -0
- package/dist/esm/storage-errors.d.ts +163 -0
- package/dist/esm/storage-errors.js +239 -0
- package/dist/esm/storage.d.ts +198 -0
- package/dist/esm/storage.js +447 -0
- package/dist/esm/sync-engine.d.ts +30 -0
- package/dist/esm/sync-engine.js +282 -0
- package/dist/esm/types.d.ts +487 -0
- package/dist/esm/types.js +37 -0
- package/package.json +45 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, SignInWithAppleParams, VerifyOtpParams } from './types.js';
|
|
2
|
+
import type { SignInWithGoogleParams } from './types.js';
|
|
3
|
+
export declare class KoolbaseAuth {
|
|
4
|
+
private config;
|
|
5
|
+
private storage;
|
|
6
|
+
private session;
|
|
7
|
+
private metadata;
|
|
8
|
+
private fetchFn;
|
|
9
|
+
private timeoutMs;
|
|
10
|
+
private ongoingRefresh;
|
|
11
|
+
private listeners;
|
|
12
|
+
constructor(config: KoolbaseConfig);
|
|
13
|
+
/**
|
|
14
|
+
* Subscribe to authentication state changes. The listener fires:
|
|
15
|
+
* - Immediately on subscribe, with the current user (or null).
|
|
16
|
+
* - On every successful login, register, refresh, session restoration.
|
|
17
|
+
* - On logout / explicit setSession(null).
|
|
18
|
+
* - On linkPhone success (user object updated with phone fields).
|
|
19
|
+
*
|
|
20
|
+
* Returns an unsubscribe function. Call it when the consumer no longer
|
|
21
|
+
* needs updates (e.g. in a React useEffect cleanup).
|
|
22
|
+
*
|
|
23
|
+
* Listener errors are swallowed so a buggy listener can't break auth
|
|
24
|
+
* state propagation to other listeners.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* const unsubscribe = auth.onAuthStateChange((user) => {
|
|
28
|
+
* setCurrentUser(user);
|
|
29
|
+
* });
|
|
30
|
+
* // later:
|
|
31
|
+
* unsubscribe();
|
|
32
|
+
*/
|
|
33
|
+
onAuthStateChange(listener: AuthStateListener): () => void;
|
|
34
|
+
private fireAuthStateChange;
|
|
35
|
+
/**
|
|
36
|
+
* Compose the full header set for an outbound request: base headers,
|
|
37
|
+
* device metadata, and optionally the Authorization bearer token.
|
|
38
|
+
* Async because device metadata's first build may read from keychain.
|
|
39
|
+
*/
|
|
40
|
+
private prepareHeaders;
|
|
41
|
+
/**
|
|
42
|
+
* Low-level request helper used by every endpoint. Wires together:
|
|
43
|
+
* - The injected fetch implementation (config.fetch or global fetch)
|
|
44
|
+
* - Device metadata + x-api-key + auth header in one place
|
|
45
|
+
* - AbortController-based timeout (config.authTimeout, default 10s)
|
|
46
|
+
*
|
|
47
|
+
* On timeout, fetch rejects with an AbortError; callers see this as a
|
|
48
|
+
* non-KoolbaseAuthError exception, which restoreSession() treats as
|
|
49
|
+
* Offline (preserving optimistic state).
|
|
50
|
+
*/
|
|
51
|
+
private authRequest;
|
|
52
|
+
/**
|
|
53
|
+
* Authenticated request wrapper. Refreshes the access token if it's
|
|
54
|
+
* stale (within 1-min buffer of expiry) before issuing the call, then
|
|
55
|
+
* delegates to {@link authRequest} with includeAuth=true.
|
|
56
|
+
*/
|
|
57
|
+
private authedRequest;
|
|
58
|
+
private setSessionInternal;
|
|
59
|
+
/**
|
|
60
|
+
* Discards the stored session without contacting the server.
|
|
61
|
+
*
|
|
62
|
+
* For when the session is already known to be unusable — the server rejected
|
|
63
|
+
* the token, or a build was pointed at a different project and the persisted
|
|
64
|
+
* session belongs to the old one. Unlike `logout()` there is no server call:
|
|
65
|
+
* the token has already been refused, and asking for it to be revoked would
|
|
66
|
+
* only add a round trip that cannot succeed.
|
|
67
|
+
*
|
|
68
|
+
* Safe in any state, including with no session at all. The SDK calls this
|
|
69
|
+
* itself when a request is rejected as unauthenticated, so most apps will not
|
|
70
|
+
* need to.
|
|
71
|
+
*/
|
|
72
|
+
clearStoredSession(): Promise<void>;
|
|
73
|
+
private clearSessionInternal;
|
|
74
|
+
restoreSession(): Promise<RestoreResult>;
|
|
75
|
+
register(params: RegisterParams): Promise<KoolbaseUser>;
|
|
76
|
+
login(params: LoginParams): Promise<KoolbaseSession>;
|
|
77
|
+
/**
|
|
78
|
+
* Sign in with Apple using a credential obtained from a native Apple
|
|
79
|
+
* Sign-In SDK.
|
|
80
|
+
*
|
|
81
|
+
* The SDK is library-agnostic — use any native Apple Sign-In package
|
|
82
|
+
* (`@invertase/react-native-apple-authentication`, etc.) and pass the
|
|
83
|
+
* resulting `identityToken`, optional `nonce`, and optional `fullName`.
|
|
84
|
+
*
|
|
85
|
+
* `fullName` is meaningful only on first sign-in — Apple omits name
|
|
86
|
+
* data on subsequent sign-ins. The server persists at link time and
|
|
87
|
+
* ignores on subsequent sign-ins.
|
|
88
|
+
*
|
|
89
|
+
* On success the session is persisted via the configured storage and
|
|
90
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
91
|
+
*
|
|
92
|
+
* @throws AppleSignInNotConfiguredError when Apple is not enabled in
|
|
93
|
+
* the dashboard OAuth config for this environment (400).
|
|
94
|
+
* @throws InvalidAppleTokenError when the token signature, audience,
|
|
95
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
96
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
97
|
+
* @throws AppleEmailRequiredError when Apple did not return email for
|
|
98
|
+
* a new-account sign-in (400).
|
|
99
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
100
|
+
* but auto-link rule blocked (409).
|
|
101
|
+
*/
|
|
102
|
+
signInWithApple(params: SignInWithAppleParams): Promise<KoolbaseSession>;
|
|
103
|
+
/**
|
|
104
|
+
* Sign in with Google using an idToken from a native Google Sign-In SDK.
|
|
105
|
+
*
|
|
106
|
+
* The SDK is library-agnostic — use any native Google Sign-In package
|
|
107
|
+
* (`@react-native-google-signin/google-signin`, etc.) and pass the
|
|
108
|
+
* resulting `idToken`. Google embeds the user's name and email in the
|
|
109
|
+
* idToken itself, so this method does not take a `fullName` parameter
|
|
110
|
+
* (unlike `signInWithApple`).
|
|
111
|
+
*
|
|
112
|
+
* On success the session is persisted via the configured storage and
|
|
113
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
114
|
+
*
|
|
115
|
+
* @throws GoogleSignInNotConfiguredError when Google is not enabled
|
|
116
|
+
* in the OAuth config for this environment (400).
|
|
117
|
+
* @throws InvalidGoogleTokenError when the token signature, audience,
|
|
118
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
119
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
120
|
+
* @throws GoogleEmailRequiredError when Google did not return email
|
|
121
|
+
* for a new-account sign-in (400).
|
|
122
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
123
|
+
* but auto-link rule blocked (409).
|
|
124
|
+
*/
|
|
125
|
+
signInWithGoogle(params: SignInWithGoogleParams): Promise<KoolbaseSession>;
|
|
126
|
+
/**
|
|
127
|
+
* Parses a /v1/sdk/auth/oauth/google response. Code-first: the server
|
|
128
|
+
* emits unified OAuth codes (oauth_not_configured, invalid_oauth_token,
|
|
129
|
+
* oauth_email_required, oauth_email_conflict) for both providers; the
|
|
130
|
+
* provider distinction is made here so Google codes map to Google-specific
|
|
131
|
+
* errors. Status + message logic is retained as a fallback for older servers.
|
|
132
|
+
*/
|
|
133
|
+
private parseGoogleSessionResponse;
|
|
134
|
+
/**
|
|
135
|
+
* Parses a /v1/sdk/auth/oauth/apple response. Code-first; the provider
|
|
136
|
+
* distinction is made here so the server's unified OAuth codes map to
|
|
137
|
+
* Apple-specific errors. Status + message logic is retained as a fallback
|
|
138
|
+
* for older servers.
|
|
139
|
+
*/
|
|
140
|
+
private parseAppleSessionResponse;
|
|
141
|
+
refresh(refreshToken?: string): Promise<KoolbaseSession>;
|
|
142
|
+
private _doRefresh;
|
|
143
|
+
logout(): Promise<boolean>;
|
|
144
|
+
forgotPassword(email: string): Promise<void>;
|
|
145
|
+
resetPassword(token: string, password: string): Promise<void>;
|
|
146
|
+
unlock(token: string): Promise<void>;
|
|
147
|
+
get currentUser(): KoolbaseUser | null;
|
|
148
|
+
get accessToken(): string | null;
|
|
149
|
+
/**
|
|
150
|
+
* Currently-valid access token for data-plane requests, refreshing
|
|
151
|
+
* (via refresh()) if the cached one is near expiry. Returns null when no
|
|
152
|
+
* session exists or refresh fails — callers then go api-key-only and the
|
|
153
|
+
* server treats it as having no end-user identity. The db/storage/functions
|
|
154
|
+
* clients pull from this per request so identity follows the live session.
|
|
155
|
+
*/
|
|
156
|
+
validAccessToken(): Promise<string | null>;
|
|
157
|
+
setSession(session: KoolbaseSession | null): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* @deprecated v1.9.0: Server endpoint /v1/sdk/auth/oauth not yet
|
|
160
|
+
* shipped. This method previously routed to /v1/auth/oauth (dashboard
|
|
161
|
+
* developer OAuth) which never created project-scoped end-user
|
|
162
|
+
* sessions. Properly implemented in v1.10.0 with provider-specific
|
|
163
|
+
* server endpoints under /v1/sdk/auth/oauth/{apple,google,github}.
|
|
164
|
+
* Use email/password sign-in for now.
|
|
165
|
+
*
|
|
166
|
+
* @throws Always throws KoolbaseAuthError('not_implemented').
|
|
167
|
+
*/
|
|
168
|
+
oauthLogin(_params: {
|
|
169
|
+
provider: string;
|
|
170
|
+
token: string;
|
|
171
|
+
email?: string;
|
|
172
|
+
name?: string;
|
|
173
|
+
avatarUrl?: string;
|
|
174
|
+
}): Promise<never>;
|
|
175
|
+
sendOtp(params: SendOtpParams): Promise<OtpSendResult>;
|
|
176
|
+
verifyOtp(params: VerifyOtpParams): Promise<PhoneVerifyResult>;
|
|
177
|
+
linkPhone(params: LinkPhoneParams): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Release resources held by this auth client. Clears the in-memory
|
|
180
|
+
* listener set. Does not invalidate sessions or clear storage — call
|
|
181
|
+
* {@link logout} for that.
|
|
182
|
+
*/
|
|
183
|
+
dispose(): void;
|
|
184
|
+
private validatePhone;
|
|
185
|
+
private _ensureValidToken;
|
|
186
|
+
private mapUser;
|
|
187
|
+
/**
|
|
188
|
+
* Parse a session-returning response (login, register, refresh).
|
|
189
|
+
* Non-2xx is delegated to throwTypedError, which is code-first
|
|
190
|
+
* (reads body.code) with a status/message fallback. isRefresh only
|
|
191
|
+
* affects how a bare 401 (no code, older server) is interpreted.
|
|
192
|
+
*/
|
|
193
|
+
private parseSessionResponse;
|
|
194
|
+
private checkResponse;
|
|
195
|
+
/**
|
|
196
|
+
* Map a non-2xx credential/session response to a typed error.
|
|
197
|
+
*
|
|
198
|
+
* Code-first: the server now emits a stable `code` on every error
|
|
199
|
+
* (contract conformance), so we switch on body.code. The status +
|
|
200
|
+
* message logic is retained as a fallback for older servers or any
|
|
201
|
+
* response that arrives without a code. isRefresh only changes how a
|
|
202
|
+
* bare 401 is interpreted in the fallback path.
|
|
203
|
+
*/
|
|
204
|
+
private throwTypedError;
|
|
205
|
+
/**
|
|
206
|
+
* Parse a phone-auth response. Code-first, with a phone-specific twist:
|
|
207
|
+
* the server emits the generic `rate_limit` code for the phone endpoints
|
|
208
|
+
* (they share the default 429), but phone has a dedicated server-side
|
|
209
|
+
* rate-limiter, so we surface OtpRateLimitError rather than RateLimitError.
|
|
210
|
+
* Status + message logic is retained as a fallback for older servers.
|
|
211
|
+
*/
|
|
212
|
+
private parsePhoneResponse;
|
|
213
|
+
}
|