@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/types.d.ts DELETED
@@ -1,470 +0,0 @@
1
- export interface KoolbaseConfig {
2
- publicKey: string;
3
- baseUrl: string;
4
- codePushChannel?: string;
5
- onMandatoryUpdate?: (info: {
6
- version: number;
7
- bundleId: string;
8
- }) => void;
9
- analyticsEnabled?: boolean;
10
- appVersion?: string;
11
- messagingEnabled?: boolean;
12
- /**
13
- * Optional custom storage adapter for persisting auth state. If omitted,
14
- * the SDK uses SecureAuthStorage backed by react-native-keychain (must
15
- * be installed). For Expo Go or custom secure backends, provide your
16
- * own KoolbaseAuthStorage implementation.
17
- */
18
- authStorage?: KoolbaseAuthStorage;
19
- /**
20
- * Per-request timeout in milliseconds for auth endpoints. Default 10000.
21
- * On timeout, fetch rejects with an AbortError. restoreSession() treats
22
- * this as Offline (preserves optimistic state).
23
- */
24
- authTimeout?: number;
25
- /**
26
- * Injectable fetch implementation. Defaults to the global fetch. Useful
27
- * for testing (mock fetch), corporate proxies, or instrumented HTTP.
28
- */
29
- fetch?: FetchLike;
30
- }
31
- export interface KoolbaseUser {
32
- id: string;
33
- email: string;
34
- phoneNumber?: string;
35
- phoneVerified?: boolean;
36
- fullName?: string;
37
- avatarUrl?: string;
38
- verified: boolean;
39
- createdAt: string;
40
- }
41
- export interface KoolbaseSession {
42
- accessToken: string;
43
- refreshToken: string;
44
- /** ISO 8601 timestamp when accessToken expires; from server response. */
45
- expiresAt: string;
46
- user: KoolbaseUser;
47
- }
48
- /**
49
- * Abstract storage interface for persisting authentication state.
50
- *
51
- * The SDK ships with SecureAuthStorage (react-native-keychain) as the
52
- * default. Apps with custom requirements — Expo Go (where keychain is
53
- * unavailable), compliant encryption layers, or in-memory test mocks —
54
- * can implement this interface and inject it via KoolbaseConfig.authStorage.
55
- */
56
- export interface KoolbaseAuthStorage {
57
- saveSession(session: KoolbaseSession): Promise<void>;
58
- readSession(): Promise<KoolbaseSession | null>;
59
- clear(): Promise<void>;
60
- }
61
- /**
62
- * Result of KoolbaseAuth.restoreSession(). Apps should branch on this:
63
- * - NoSession → show login screen
64
- * - Restored → show authenticated UI
65
- * - Expired → show login screen with "session expired" message
66
- * - Offline → show authenticated UI optimistically; API calls will
67
- * fail until network is reachable
68
- */
69
- export declare enum RestoreResult {
70
- NoSession = "no_session",
71
- Restored = "restored",
72
- Expired = "expired",
73
- Offline = "offline"
74
- }
75
- /**
76
- * Callback invoked when authentication state changes. Receives the
77
- * current user, or null when signed out. Listeners fire on login,
78
- * register, refresh, session restoration, logout, setSession, and
79
- * linkPhone. Errors thrown from a listener are swallowed so one
80
- * broken listener cannot break propagation to others.
81
- */
82
- export type AuthStateListener = (user: KoolbaseUser | null) => void;
83
- /**
84
- * Drop-in replacement for the global `fetch` function. Inject via
85
- * KoolbaseConfig.fetch for testing (mock fetch), proxying, or
86
- * monitoring. Matches the standard fetch signature.
87
- */
88
- export type FetchLike = (input: string, init?: RequestInit) => Promise<Response>;
89
- export interface RegisterParams {
90
- email: string;
91
- password: string;
92
- fullName?: string;
93
- }
94
- export interface LoginParams {
95
- email: string;
96
- password: string;
97
- }
98
- export interface SendOtpParams {
99
- phoneNumber: string;
100
- }
101
- export interface VerifyOtpParams {
102
- phoneNumber: string;
103
- code: string;
104
- }
105
- export interface LinkPhoneParams {
106
- phoneNumber: string;
107
- code: string;
108
- }
109
- export interface OtpSendResult {
110
- expiresAt: string;
111
- }
112
- export interface PhoneVerifyResult {
113
- session: KoolbaseSession;
114
- isNewUser: boolean;
115
- }
116
- export interface KoolbaseRecord {
117
- id: string;
118
- collection?: string;
119
- createdBy?: string;
120
- data: Record<string, unknown>;
121
- createdAt: string;
122
- updatedAt: string;
123
- }
124
- export interface QueryOptions {
125
- filters?: Record<string, unknown>;
126
- limit?: number;
127
- offset?: number;
128
- orderBy?: string;
129
- orderDesc?: boolean;
130
- populate?: string[];
131
- }
132
- export interface QueryResult {
133
- records: KoolbaseRecord[];
134
- total: number;
135
- isFromCache?: boolean;
136
- }
137
- export interface UpsertResult {
138
- record: KoolbaseRecord;
139
- created: boolean;
140
- }
141
- export interface PendingWrite {
142
- id: string;
143
- type: 'insert' | 'update' | 'delete';
144
- collection?: string;
145
- recordId?: string;
146
- data?: Record<string, unknown>;
147
- retries: number;
148
- createdAt: string;
149
- }
150
- /**
151
- * A stored vector retrieved by `KoolbaseDatabase.getVector()`. The `vector`
152
- * field carries the float values exactly as stored on the server; the
153
- * `recordId` + `fieldName` pair identifies which slot they came from.
154
- */
155
- export interface KoolbaseVector {
156
- recordId: string;
157
- fieldName: string;
158
- vector: number[];
159
- /** ISO 8601 timestamp from the server. */
160
- createdAt: string;
161
- /** ISO 8601 timestamp from the server. */
162
- updatedAt: string;
163
- }
164
- /**
165
- * Retrieval strategy for `KoolbaseDatabase.searchSemantic()`.
166
- *
167
- * - `'semantic'` (default) — pure vector search via HNSW on cosine
168
- * distance. Best for fuzzy / conceptual queries where exact term
169
- * match isn't required.
170
- * - `'lexical'` — pure BM25 over the field's source text (Postgres
171
- * `ts_rank_cd`). Best for exact terms, codes, names, acronyms.
172
- * - `'hybrid'` — vector + lexical fused with reciprocal rank fusion
173
- * (k=60). Generally the strongest default for production search.
174
- */
175
- export type SearchMode = 'semantic' | 'lexical' | 'hybrid';
176
- /**
177
- * One ranked hit from `KoolbaseDatabase.searchSemantic()`. `record` is
178
- * the full record (same wire shape as a record returned by query/get).
179
- * `distance` is the cosine distance between the query vector and the
180
- * stored vector — lower means more similar. Range: 0 (identical
181
- * direction) to 2 (opposite direction).
182
- */
183
- export interface KoolbaseSemanticHit {
184
- record: KoolbaseRecord;
185
- distance: number;
186
- }
187
- /**
188
- * Result of `KoolbaseDatabase.searchSemantic()`. `hits` is the ranked
189
- * list of nearest neighbors (best match first); `total` is the count of
190
- * hits returned (matches `hits.length` in v1 — preserved as a separate
191
- * field for future pagination).
192
- */
193
- export interface SemanticSearchResult {
194
- hits: KoolbaseSemanticHit[];
195
- total: number;
196
- }
197
- export interface UploadOptions {
198
- bucket: string;
199
- path: string;
200
- file: {
201
- uri: string;
202
- name: string;
203
- type: string;
204
- };
205
- /**
206
- * If `false` (default in v5+), an upload to a path where an object
207
- * already exists is rejected with `KoolbaseStorageConflictError`. Pass
208
- * `true` to silently replace the existing object.
209
- */
210
- overwrite?: boolean;
211
- /**
212
- * User-defined key/value metadata to attach to the object at confirm
213
- * time. Optional — when omitted, the object stores empty metadata `{}`.
214
- *
215
- * Subject to server-side validation (≤50 keys, ≤8KB total, keys 1–64
216
- * chars matching `[a-z0-9_]+`, values ≤1024 chars, leading underscore
217
- * reserved); violations throw `KoolbaseStorageMetadataInvalidError`.
218
- *
219
- * On the `overwrite: true` path, metadata REPLACES any prior metadata
220
- * at this path (matches GCS semantics — a new upload at a path
221
- * produces a new object, not a patch of the old). Use `updateMetadata`
222
- * for post-upload merge changes.
223
- */
224
- metadata?: Record<string, string>;
225
- onProgress?: (percent: number) => void;
226
- }
227
- /**
228
- * A stored object's server-side metadata. Field names are camelCase here
229
- * even though the wire format is snake_case — the SDK maps for you.
230
- */
231
- export interface KoolbaseObject {
232
- id: string;
233
- projectId: string;
234
- bucketId: string;
235
- /**
236
- * Name of the physical R2 bucket holding this object's bytes
237
- * (Gap #2). `'koolbase-storage-public'` means the object has a
238
- * stable CDN URL — construct it with
239
- * `KoolbaseStorage.publicUrlForObject(obj, bucket)`. Anything else
240
- * (typically `'koolbase-storage'`) means the object is in private
241
- * storage and reads go through {@link KoolbaseStorage.getDownloadUrl},
242
- * which returns a 1-hour presigned URL.
243
- */
244
- r2Bucket: string;
245
- userId: string | null;
246
- path: string;
247
- size: number;
248
- contentType: string | null;
249
- /**
250
- * User-defined key/value metadata attached to this object. Always
251
- * non-null — empty object when no metadata has been set (the server
252
- * returns `{}` rather than `null` so callers can treat it as a
253
- * guaranteed object without null checks). Set on upload via
254
- * `upload({ metadata })` or mutated post-upload via `updateMetadata`.
255
- */
256
- metadata: Record<string, string>;
257
- /** ISO 8601 timestamp from the server. */
258
- createdAt: string;
259
- /** ISO 8601 timestamp from the server. */
260
- updatedAt: string;
261
- }
262
- /**
263
- * One entry in an object's version timeline. Covers both the current
264
- * row (when {@link isCurrent} is true) and every history row, including
265
- * soft-delete markers (when {@link isDeleteMarker} is true — size 0, no
266
- * fetchable bytes). Returned from {@link KoolbaseStorage.listVersions}
267
- * and {@link KoolbaseStorage.getVersion}; the underlying bytes are
268
- * downloadable via {@link KoolbaseStorage.getDownloadUrl} with the
269
- * `versionId` argument.
270
- *
271
- * `versionId` may be null only on legacy rows uploaded before versioning
272
- * was enabled on the bucket — for those, {@link isCurrent} is true and
273
- * the row carries no history identity yet (gets backfilled on the next
274
- * overwrite).
275
- */
276
- export interface KoolbaseObjectVersion {
277
- versionId: string | null;
278
- path: string;
279
- size: number;
280
- contentType: string | null;
281
- etag: string | null;
282
- metadata: Record<string, string>;
283
- r2Bucket: string;
284
- userId: string | null;
285
- /**
286
- * True for a tombstone row recording a soft-delete event. Size is 0
287
- * and there are no R2 bytes — treat as "the path was deleted at this
288
- * time" rather than fetchable content.
289
- */
290
- isDeleteMarker: boolean;
291
- /**
292
- * True for the row that currently lives in `storage_objects` (i.e.
293
- * what a no-versionId download returns). False for everything in
294
- * `storage_object_versions`.
295
- */
296
- isCurrent: boolean;
297
- /**
298
- * For the current row this is the time the current version became
299
- * current (overwrite or upload time). For history rows it's the time
300
- * the version was originally uploaded.
301
- */
302
- createdAt: string;
303
- }
304
- /**
305
- * Result of a successful `KoolbaseStorage.upload()` call.
306
- */
307
- export interface UploadResult {
308
- object: KoolbaseObject;
309
- downloadUrl: string;
310
- }
311
- export interface RealtimeEvent {
312
- type: 'created' | 'updated' | 'deleted';
313
- collection: string;
314
- record?: KoolbaseRecord;
315
- recordId?: string;
316
- }
317
- export type RealtimeCallback = (event: RealtimeEvent) => void;
318
- export interface BootstrapPayload {
319
- payload_version: string;
320
- flags: Record<string, {
321
- enabled: boolean;
322
- rollout_percentage: number;
323
- kill_switch: boolean;
324
- }>;
325
- config: Record<string, unknown>;
326
- version: {
327
- min_version: string;
328
- latest_version: string;
329
- force_update: boolean;
330
- update_message: string;
331
- };
332
- }
333
- export type VersionStatus = 'up_to_date' | 'soft_update' | 'force_update';
334
- export interface VersionCheckResult {
335
- status: VersionStatus;
336
- message: string;
337
- latestVersion: string;
338
- }
339
- export declare enum FunctionRuntime {
340
- Deno = "deno",
341
- Dart = "dart"
342
- }
343
- export interface DeployOptions {
344
- name: string;
345
- code: string;
346
- runtime?: FunctionRuntime;
347
- timeoutMs?: number;
348
- }
349
- export interface DeployResult {
350
- id: string;
351
- name: string;
352
- runtime: string;
353
- version: number;
354
- isActive: boolean;
355
- timeoutMs: number;
356
- lastDeployedAt: string | null;
357
- }
358
- export interface FunctionInvokeResult {
359
- statusCode: number;
360
- data: Record<string, unknown> | null;
361
- success: boolean;
362
- }
363
- /**
364
- * Apple's optional full-name structure returned only on a user's FIRST
365
- * Sign in with Apple. Both fields nullable; subsequent sign-ins omit
366
- * this entirely.
367
- *
368
- * Pass to `KoolbaseAuth.signInWithApple` only on first sign-in. The
369
- * server persists at link time and ignores on subsequent sign-ins
370
- * (matches Apple's documented contract).
371
- */
372
- export interface AppleFullName {
373
- givenName?: string;
374
- familyName?: string;
375
- }
376
- /**
377
- * Parameters for `KoolbaseAuth.signInWithApple`. The SDK is
378
- * library-agnostic — `identityToken` should come from any native
379
- * Apple Sign-In package (e.g. `@invertase/react-native-apple-authentication`).
380
- */
381
- export interface SignInWithAppleParams {
382
- identityToken: string;
383
- nonce?: string;
384
- fullName?: AppleFullName;
385
- }
386
- /**
387
- * Parameters for `KoolbaseAuth.signInWithGoogle`. The SDK is
388
- * library-agnostic — `idToken` should come from any native Google
389
- * Sign-In package (e.g. `@react-native-google-signin/google-signin`).
390
- *
391
- * Unlike Apple, Google embeds the user's name and email in the idToken
392
- * itself, so no separate `fullName` parameter is needed.
393
- */
394
- export interface SignInWithGoogleParams {
395
- idToken: string;
396
- nonce?: string;
397
- }
398
- export type BatchOp = {
399
- type: 'insert';
400
- collection: string;
401
- data: Record<string, unknown>;
402
- } | {
403
- type: 'update';
404
- recordId: string;
405
- data: Record<string, unknown>;
406
- } | {
407
- type: 'delete';
408
- recordId: string;
409
- } | {
410
- type: 'upsert';
411
- collection: string;
412
- match: Record<string, unknown>;
413
- data: Record<string, unknown>;
414
- };
415
- /**
416
- * Factory helpers for constructing batch operations. Same shape as
417
- * Flutter's `KoolbaseBatchOp.insert(...)` etc., so the mental model
418
- * transfers between platforms.
419
- */
420
- export declare const BatchOp: {
421
- insert: (collection: string, data: Record<string, unknown>) => BatchOp;
422
- update: (recordId: string, data: Record<string, unknown>) => BatchOp;
423
- delete: (recordId: string) => BatchOp;
424
- upsert: (collection: string, opts: {
425
- match: Record<string, unknown>;
426
- data: Record<string, unknown>;
427
- }) => BatchOp;
428
- };
429
- export interface BatchResult {
430
- type: string;
431
- record?: KoolbaseRecord;
432
- /** For upsert: true if a new record was inserted, false if one was updated. */
433
- created?: boolean;
434
- /** True for a successful delete. */
435
- deleted?: boolean;
436
- }
437
- export type KoolbaseImageFormat = 'auto' | 'webp' | 'avif' | 'jpeg' | 'png';
438
- export type KoolbaseImageFit = 'scale-down' | 'contain' | 'cover' | 'crop' | 'pad';
439
- export type KoolbaseImageGravity = 'auto' | 'center' | 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
440
- /**
441
- * Image-transformation options for `KoolbaseStorage.publicUrl` and
442
- * `KoolbaseStorage.publicUrlForObject`. Each field maps to one Cloudflare
443
- * Image Transformations parameter; unset fields are omitted.
444
- *
445
- * All numeric inputs are clamped silently to Cloudflare-supported ranges
446
- * (width/height 1-2000, quality 1-100, dpr 1-3) so a stray `width: 99999`
447
- * can't trigger error 9422 at the edge.
448
- *
449
- * @example
450
- * const url = KoolbaseStorage.publicUrl({
451
- * projectId: pid, bucket: 'avatars', path: 'user.jpg',
452
- * transform: { width: 400, height: 400, format: 'webp', quality: 80, fit: 'cover' },
453
- * });
454
- */
455
- export interface KoolbaseImageTransform {
456
- /** Output width in pixels. Clamped to 1-2000. */
457
- width?: number;
458
- /** Output height in pixels. Clamped to 1-2000. */
459
- height?: number;
460
- /** Output format. `auto` negotiates based on the request's `Accept` header. */
461
- format?: KoolbaseImageFormat;
462
- /** Quality 1-100. Clamped. Has no effect on lossless formats (`png`). */
463
- quality?: number;
464
- /** Resize mode when both width and height are specified. */
465
- fit?: KoolbaseImageFit;
466
- /** Device pixel ratio multiplier. Clamped to 1-3. */
467
- dpr?: number;
468
- /** Crop anchor. Use with `fit: 'cover'` or `fit: 'crop'`. */
469
- gravity?: KoolbaseImageGravity;
470
- }
package/dist/types.js DELETED
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BatchOp = exports.FunctionRuntime = exports.RestoreResult = void 0;
4
- /**
5
- * Result of KoolbaseAuth.restoreSession(). Apps should branch on this:
6
- * - NoSession → show login screen
7
- * - Restored → show authenticated UI
8
- * - Expired → show login screen with "session expired" message
9
- * - Offline → show authenticated UI optimistically; API calls will
10
- * fail until network is reachable
11
- */
12
- var RestoreResult;
13
- (function (RestoreResult) {
14
- RestoreResult["NoSession"] = "no_session";
15
- RestoreResult["Restored"] = "restored";
16
- RestoreResult["Expired"] = "expired";
17
- RestoreResult["Offline"] = "offline";
18
- })(RestoreResult || (exports.RestoreResult = RestoreResult = {}));
19
- // ─── Functions ─────────────────────────────────────────────────────────────
20
- var FunctionRuntime;
21
- (function (FunctionRuntime) {
22
- FunctionRuntime["Deno"] = "deno";
23
- FunctionRuntime["Dart"] = "dart";
24
- })(FunctionRuntime || (exports.FunctionRuntime = FunctionRuntime = {}));
25
- /**
26
- * Factory helpers for constructing batch operations. Same shape as
27
- * Flutter's `KoolbaseBatchOp.insert(...)` etc., so the mental model
28
- * transfers between platforms.
29
- */
30
- exports.BatchOp = {
31
- insert: (collection, data) => ({ type: 'insert', collection, data }),
32
- update: (recordId, data) => ({ type: 'update', recordId, data }),
33
- delete: (recordId) => ({ type: 'delete', recordId }),
34
- upsert: (collection, opts) => ({
35
- type: 'upsert',
36
- collection,
37
- match: opts.match,
38
- data: opts.data,
39
- }),
40
- };
File without changes