@koolbase/react-native 9.1.0 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +1342 -0
  2. package/README.md +462 -511
  3. package/dist/{auth-storage.d.ts → cjs/auth-storage.d.ts} +1 -1
  4. package/dist/cjs/index.d.ts +19 -0
  5. package/dist/cjs/index.js +125 -0
  6. package/dist/cjs/package.json +3 -0
  7. package/dist/cjs/platform.d.ts +2 -0
  8. package/dist/cjs/platform.js +43 -0
  9. package/dist/esm/auth-storage.d.ts +26 -0
  10. package/dist/esm/auth-storage.js +100 -0
  11. package/dist/esm/index.d.ts +19 -0
  12. package/dist/esm/index.js +106 -0
  13. package/dist/esm/package.json +3 -0
  14. package/dist/esm/platform.d.ts +2 -0
  15. package/dist/esm/platform.js +37 -0
  16. package/package.json +30 -24
  17. package/dist/analytics.d.ts +0 -24
  18. package/dist/analytics.js +0 -114
  19. package/dist/apple-auth.d.ts +0 -22
  20. package/dist/apple-auth.js +0 -74
  21. package/dist/auth-errors.d.ts +0 -117
  22. package/dist/auth-errors.js +0 -250
  23. package/dist/auth.d.ts +0 -199
  24. package/dist/auth.js +0 -794
  25. package/dist/cache-store.d.ts +0 -11
  26. package/dist/cache-store.js +0 -136
  27. package/dist/code-push.d.ts +0 -59
  28. package/dist/code-push.js +0 -255
  29. package/dist/database-errors.d.ts +0 -95
  30. package/dist/database-errors.js +0 -173
  31. package/dist/database.d.ts +0 -208
  32. package/dist/database.js +0 -508
  33. package/dist/device-id.d.ts +0 -1
  34. package/dist/device-id.js +0 -60
  35. package/dist/device-metadata.d.ts +0 -36
  36. package/dist/device-metadata.js +0 -102
  37. package/dist/flags.d.ts +0 -15
  38. package/dist/flags.js +0 -76
  39. package/dist/functions.d.ts +0 -8
  40. package/dist/functions.js +0 -70
  41. package/dist/index.d.ts +0 -45
  42. package/dist/index.js +0 -193
  43. package/dist/logic-engine.d.ts +0 -17
  44. package/dist/logic-engine.js +0 -193
  45. package/dist/messaging.d.ts +0 -13
  46. package/dist/messaging.js +0 -36
  47. package/dist/realtime.d.ts +0 -19
  48. package/dist/realtime.js +0 -148
  49. package/dist/record.d.ts +0 -2
  50. package/dist/record.js +0 -20
  51. package/dist/storage-errors.d.ts +0 -163
  52. package/dist/storage-errors.js +0 -249
  53. package/dist/storage.d.ts +0 -184
  54. package/dist/storage.js +0 -438
  55. package/dist/sync-engine.d.ts +0 -16
  56. package/dist/sync-engine.js +0 -86
  57. package/dist/types.d.ts +0 -470
  58. package/dist/types.js +0 -40
  59. /package/dist/{auth-storage.js → cjs/auth-storage.js} +0 -0
package/dist/auth.d.ts DELETED
@@ -1,199 +0,0 @@
1
- import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, SignInWithAppleParams, VerifyOtpParams } from './types';
2
- import type { SignInWithGoogleParams } from './types';
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
- private clearSessionInternal;
60
- restoreSession(): Promise<RestoreResult>;
61
- register(params: RegisterParams): Promise<KoolbaseUser>;
62
- login(params: LoginParams): Promise<KoolbaseSession>;
63
- /**
64
- * Sign in with Apple using a credential obtained from a native Apple
65
- * Sign-In SDK.
66
- *
67
- * The SDK is library-agnostic — use any native Apple Sign-In package
68
- * (`@invertase/react-native-apple-authentication`, etc.) and pass the
69
- * resulting `identityToken`, optional `nonce`, and optional `fullName`.
70
- *
71
- * `fullName` is meaningful only on first sign-in — Apple omits name
72
- * data on subsequent sign-ins. The server persists at link time and
73
- * ignores on subsequent sign-ins.
74
- *
75
- * On success the session is persisted via the configured storage and
76
- * `onAuthStateChange` fires with the resolved user.
77
- *
78
- * @throws AppleSignInNotConfiguredError when Apple is not enabled in
79
- * the dashboard OAuth config for this environment (400).
80
- * @throws InvalidAppleTokenError when the token signature, audience,
81
- * expiry, replay, or nonce check failed server-side (401).
82
- * @throws UserDisabledError when the account flag is set to disabled (403).
83
- * @throws AppleEmailRequiredError when Apple did not return email for
84
- * a new-account sign-in (400).
85
- * @throws OAuthEmailConflictError when email matches existing user
86
- * but auto-link rule blocked (409).
87
- */
88
- signInWithApple(params: SignInWithAppleParams): Promise<KoolbaseSession>;
89
- /**
90
- * Sign in with Google using an idToken from a native Google Sign-In SDK.
91
- *
92
- * The SDK is library-agnostic — use any native Google Sign-In package
93
- * (`@react-native-google-signin/google-signin`, etc.) and pass the
94
- * resulting `idToken`. Google embeds the user's name and email in the
95
- * idToken itself, so this method does not take a `fullName` parameter
96
- * (unlike `signInWithApple`).
97
- *
98
- * On success the session is persisted via the configured storage and
99
- * `onAuthStateChange` fires with the resolved user.
100
- *
101
- * @throws GoogleSignInNotConfiguredError when Google is not enabled
102
- * in the OAuth config for this environment (400).
103
- * @throws InvalidGoogleTokenError when the token signature, audience,
104
- * expiry, replay, or nonce check failed server-side (401).
105
- * @throws UserDisabledError when the account flag is set to disabled (403).
106
- * @throws GoogleEmailRequiredError when Google did not return email
107
- * for a new-account sign-in (400).
108
- * @throws OAuthEmailConflictError when email matches existing user
109
- * but auto-link rule blocked (409).
110
- */
111
- signInWithGoogle(params: SignInWithGoogleParams): Promise<KoolbaseSession>;
112
- /**
113
- * Parses a /v1/sdk/auth/oauth/google response. Code-first: the server
114
- * emits unified OAuth codes (oauth_not_configured, invalid_oauth_token,
115
- * oauth_email_required, oauth_email_conflict) for both providers; the
116
- * provider distinction is made here so Google codes map to Google-specific
117
- * errors. Status + message logic is retained as a fallback for older servers.
118
- */
119
- private parseGoogleSessionResponse;
120
- /**
121
- * Parses a /v1/sdk/auth/oauth/apple response. Code-first; the provider
122
- * distinction is made here so the server's unified OAuth codes map to
123
- * Apple-specific errors. Status + message logic is retained as a fallback
124
- * for older servers.
125
- */
126
- private parseAppleSessionResponse;
127
- refresh(refreshToken?: string): Promise<KoolbaseSession>;
128
- private _doRefresh;
129
- logout(): Promise<boolean>;
130
- forgotPassword(email: string): Promise<void>;
131
- resetPassword(token: string, password: string): Promise<void>;
132
- unlock(token: string): Promise<void>;
133
- get currentUser(): KoolbaseUser | null;
134
- get accessToken(): string | null;
135
- /**
136
- * Currently-valid access token for data-plane requests, refreshing
137
- * (via refresh()) if the cached one is near expiry. Returns null when no
138
- * session exists or refresh fails — callers then go api-key-only and the
139
- * server treats it as having no end-user identity. The db/storage/functions
140
- * clients pull from this per request so identity follows the live session.
141
- */
142
- validAccessToken(): Promise<string | null>;
143
- setSession(session: KoolbaseSession | null): Promise<void>;
144
- /**
145
- * @deprecated v1.9.0: Server endpoint /v1/sdk/auth/oauth not yet
146
- * shipped. This method previously routed to /v1/auth/oauth (dashboard
147
- * developer OAuth) which never created project-scoped end-user
148
- * sessions. Properly implemented in v1.10.0 with provider-specific
149
- * server endpoints under /v1/sdk/auth/oauth/{apple,google,github}.
150
- * Use email/password sign-in for now.
151
- *
152
- * @throws Always throws KoolbaseAuthError('not_implemented').
153
- */
154
- oauthLogin(_params: {
155
- provider: string;
156
- token: string;
157
- email?: string;
158
- name?: string;
159
- avatarUrl?: string;
160
- }): Promise<never>;
161
- sendOtp(params: SendOtpParams): Promise<OtpSendResult>;
162
- verifyOtp(params: VerifyOtpParams): Promise<PhoneVerifyResult>;
163
- linkPhone(params: LinkPhoneParams): Promise<void>;
164
- /**
165
- * Release resources held by this auth client. Clears the in-memory
166
- * listener set. Does not invalidate sessions or clear storage — call
167
- * {@link logout} for that.
168
- */
169
- dispose(): void;
170
- private validatePhone;
171
- private _ensureValidToken;
172
- private mapUser;
173
- /**
174
- * Parse a session-returning response (login, register, refresh).
175
- * Non-2xx is delegated to throwTypedError, which is code-first
176
- * (reads body.code) with a status/message fallback. isRefresh only
177
- * affects how a bare 401 (no code, older server) is interpreted.
178
- */
179
- private parseSessionResponse;
180
- private checkResponse;
181
- /**
182
- * Map a non-2xx credential/session response to a typed error.
183
- *
184
- * Code-first: the server now emits a stable `code` on every error
185
- * (contract conformance), so we switch on body.code. The status +
186
- * message logic is retained as a fallback for older servers or any
187
- * response that arrives without a code. isRefresh only changes how a
188
- * bare 401 is interpreted in the fallback path.
189
- */
190
- private throwTypedError;
191
- /**
192
- * Parse a phone-auth response. Code-first, with a phone-specific twist:
193
- * the server emits the generic `rate_limit` code for the phone endpoints
194
- * (they share the default 429), but phone has a dedicated server-side
195
- * rate-limiter, so we surface OtpRateLimitError rather than RateLimitError.
196
- * Status + message logic is retained as a fallback for older servers.
197
- */
198
- private parsePhoneResponse;
199
- }