@techfinityedge/koolbase-react-native 1.10.1 → 2.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 +29 -5
- package/dist/auth-errors.d.ts +9 -0
- package/dist/auth-errors.js +25 -1
- package/dist/auth.d.ts +30 -0
- package/dist/auth.js +79 -0
- package/dist/database.d.ts +1 -0
- package/dist/database.js +18 -32
- package/dist/device-metadata.d.ts +1 -1
- package/dist/device-metadata.js +1 -1
- package/dist/realtime.js +9 -1
- package/dist/record.d.ts +2 -0
- package/dist/record.js +20 -0
- package/dist/types.d.ts +13 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@ Auth, database, storage, realtime, functions, feature flags, remote config, vers
|
|
|
16
16
|
3. Add the SDK:
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm install @techfinityedge/koolbase-react-native@^
|
|
19
|
+
npm install @techfinityedge/koolbase-react-native@^2.0.0
|
|
20
20
|
# or
|
|
21
|
-
yarn add @techfinityedge/koolbase-react-native@^
|
|
21
|
+
yarn add @techfinityedge/koolbase-react-native@^2.0.0
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
**4. Initialize at app startup:**
|
|
@@ -38,7 +38,7 @@ That's it. Every feature below is now available via `Koolbase.*`.
|
|
|
38
38
|
|
|
39
39
|
## Authentication
|
|
40
40
|
|
|
41
|
-
Email + password, Apple Sign-In, and phone + OTP — out of the box.
|
|
41
|
+
Email + password, Apple Sign-In, Google Sign-In, and phone + OTP — out of the box.
|
|
42
42
|
|
|
43
43
|
```typescript
|
|
44
44
|
// Register
|
|
@@ -87,9 +87,28 @@ const session = await Koolbase.auth.signInWithApple({
|
|
|
87
87
|
});
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
Configure Apple Sign-In for your environment with your iOS app's Bundle ID. Full setup guide at [docs.koolbase.com/auth/oauth](https://docs.koolbase.com/auth/oauth).
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
### OAuth — Google
|
|
93
|
+
|
|
94
|
+
Google Sign-In uses the native authentication flow via `@react-native-google-signin/google-signin` as a peer dependency:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { GoogleSignin } from '@react-native-google-signin/google-signin';
|
|
98
|
+
import { Koolbase } from '@techfinityedge/koolbase-react-native';
|
|
99
|
+
|
|
100
|
+
GoogleSignin.configure({
|
|
101
|
+
webClientId: '<your-web-client-id>.apps.googleusercontent.com',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const userInfo = await GoogleSignin.signIn();
|
|
105
|
+
|
|
106
|
+
const session = await Koolbase.auth.signInWithGoogle({
|
|
107
|
+
idToken: userInfo.idToken!,
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Configure Google Sign-In for your environment with the OAuth client IDs from Google Cloud Console (typically one each for iOS, Android, and web). Full setup guide at [docs.koolbase.com/auth/oauth](https://docs.koolbase.com/auth/oauth).
|
|
93
112
|
|
|
94
113
|
### Phone + OTP
|
|
95
114
|
|
|
@@ -128,6 +147,11 @@ const { records } = await Koolbase.db.query('posts', {
|
|
|
128
147
|
orderDesc: true,
|
|
129
148
|
});
|
|
130
149
|
|
|
150
|
+
// Read fields off a record
|
|
151
|
+
const post = records[0];
|
|
152
|
+
console.log(post.data.title); // your fields live under .data
|
|
153
|
+
console.log(post.id, post.collection); // metadata
|
|
154
|
+
|
|
131
155
|
// Populate related records
|
|
132
156
|
const { records: postsWithAuthor } = await Koolbase.db.query('posts', {
|
|
133
157
|
populate: ['author_id:users'],
|
package/dist/auth-errors.d.ts
CHANGED
|
@@ -106,3 +106,12 @@ export declare class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
|
106
106
|
export declare class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
107
107
|
constructor();
|
|
108
108
|
}
|
|
109
|
+
export declare class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
110
|
+
constructor();
|
|
111
|
+
}
|
|
112
|
+
export declare class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
113
|
+
constructor();
|
|
114
|
+
}
|
|
115
|
+
export declare class GoogleEmailRequiredError extends KoolbaseAuthError {
|
|
116
|
+
constructor();
|
|
117
|
+
}
|
package/dist/auth-errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
3
|
+
exports.GoogleEmailRequiredError = exports.InvalidGoogleTokenError = exports.GoogleSignInNotConfiguredError = exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Base error type for all Koolbase auth errors. Catchable via
|
|
6
6
|
* `instanceof KoolbaseAuthError` to handle any auth-related failure
|
|
@@ -224,3 +224,27 @@ class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
226
|
exports.OAuthEmailConflictError = OAuthEmailConflictError;
|
|
227
|
+
class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
228
|
+
constructor() {
|
|
229
|
+
super('Google Sign-In is not configured for this environment', 'google_not_configured');
|
|
230
|
+
this.name = 'GoogleSignInNotConfiguredError';
|
|
231
|
+
Object.setPrototypeOf(this, GoogleSignInNotConfiguredError.prototype);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
exports.GoogleSignInNotConfiguredError = GoogleSignInNotConfiguredError;
|
|
235
|
+
class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
236
|
+
constructor() {
|
|
237
|
+
super('Invalid Google identity token', 'invalid_google_token');
|
|
238
|
+
this.name = 'InvalidGoogleTokenError';
|
|
239
|
+
Object.setPrototypeOf(this, InvalidGoogleTokenError.prototype);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.InvalidGoogleTokenError = InvalidGoogleTokenError;
|
|
243
|
+
class GoogleEmailRequiredError extends KoolbaseAuthError {
|
|
244
|
+
constructor() {
|
|
245
|
+
super('Google did not return email for this sign-in. Ensure the email scope is requested in the native flow.', 'google_email_required');
|
|
246
|
+
this.name = 'GoogleEmailRequiredError';
|
|
247
|
+
Object.setPrototypeOf(this, GoogleEmailRequiredError.prototype);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
exports.GoogleEmailRequiredError = GoogleEmailRequiredError;
|
package/dist/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AuthStateListener, KoolbaseConfig, KoolbaseSession, KoolbaseUser, LinkPhoneParams, LoginParams, OtpSendResult, PhoneVerifyResult, RegisterParams, RestoreResult, SendOtpParams, SignInWithAppleParams, VerifyOtpParams } from './types';
|
|
2
|
+
import type { SignInWithGoogleParams } from './types';
|
|
2
3
|
export declare class KoolbaseAuth {
|
|
3
4
|
private config;
|
|
4
5
|
private storage;
|
|
@@ -85,6 +86,35 @@ export declare class KoolbaseAuth {
|
|
|
85
86
|
* but auto-link rule blocked (409).
|
|
86
87
|
*/
|
|
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. Distinct from
|
|
114
|
+
* parseSessionResponse and parseAppleSessionResponse because OAuth
|
|
115
|
+
* error semantics differ per-provider.
|
|
116
|
+
*/
|
|
117
|
+
private parseGoogleSessionResponse;
|
|
88
118
|
/**
|
|
89
119
|
* Parses a /v1/sdk/auth/oauth/apple response. Distinct from
|
|
90
120
|
* parseSessionResponse because OAuth error semantics differ from
|
package/dist/auth.js
CHANGED
|
@@ -259,6 +259,85 @@ class KoolbaseAuth {
|
|
|
259
259
|
await this.setSessionInternal(session);
|
|
260
260
|
return session;
|
|
261
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* Sign in with Google using an idToken from a native Google Sign-In SDK.
|
|
264
|
+
*
|
|
265
|
+
* The SDK is library-agnostic — use any native Google Sign-In package
|
|
266
|
+
* (`@react-native-google-signin/google-signin`, etc.) and pass the
|
|
267
|
+
* resulting `idToken`. Google embeds the user's name and email in the
|
|
268
|
+
* idToken itself, so this method does not take a `fullName` parameter
|
|
269
|
+
* (unlike `signInWithApple`).
|
|
270
|
+
*
|
|
271
|
+
* On success the session is persisted via the configured storage and
|
|
272
|
+
* `onAuthStateChange` fires with the resolved user.
|
|
273
|
+
*
|
|
274
|
+
* @throws GoogleSignInNotConfiguredError when Google is not enabled
|
|
275
|
+
* in the OAuth config for this environment (400).
|
|
276
|
+
* @throws InvalidGoogleTokenError when the token signature, audience,
|
|
277
|
+
* expiry, replay, or nonce check failed server-side (401).
|
|
278
|
+
* @throws UserDisabledError when the account flag is set to disabled (403).
|
|
279
|
+
* @throws GoogleEmailRequiredError when Google did not return email
|
|
280
|
+
* for a new-account sign-in (400).
|
|
281
|
+
* @throws OAuthEmailConflictError when email matches existing user
|
|
282
|
+
* but auto-link rule blocked (409).
|
|
283
|
+
*/
|
|
284
|
+
async signInWithGoogle(params) {
|
|
285
|
+
const body = {
|
|
286
|
+
identity_token: params.idToken,
|
|
287
|
+
};
|
|
288
|
+
if (params.nonce && params.nonce.length > 0) {
|
|
289
|
+
body.nonce = params.nonce;
|
|
290
|
+
}
|
|
291
|
+
const res = await this.authRequest('/v1/sdk/auth/oauth/google', {
|
|
292
|
+
method: 'POST',
|
|
293
|
+
body,
|
|
294
|
+
});
|
|
295
|
+
const session = await this.parseGoogleSessionResponse(res);
|
|
296
|
+
await this.setSessionInternal(session);
|
|
297
|
+
return session;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Parses a /v1/sdk/auth/oauth/google response. Distinct from
|
|
301
|
+
* parseSessionResponse and parseAppleSessionResponse because OAuth
|
|
302
|
+
* error semantics differ per-provider.
|
|
303
|
+
*/
|
|
304
|
+
async parseGoogleSessionResponse(res) {
|
|
305
|
+
if (res.status === 200) {
|
|
306
|
+
const data = await res.json();
|
|
307
|
+
return {
|
|
308
|
+
accessToken: data.access_token,
|
|
309
|
+
refreshToken: data.refresh_token,
|
|
310
|
+
expiresAt: data.expires_at,
|
|
311
|
+
user: this.mapUser(data.user),
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
let errorMessage = '';
|
|
315
|
+
try {
|
|
316
|
+
const data = await res.json();
|
|
317
|
+
errorMessage = data?.error ?? '';
|
|
318
|
+
}
|
|
319
|
+
catch {
|
|
320
|
+
// best-effort error message extraction
|
|
321
|
+
}
|
|
322
|
+
if (res.status === 400) {
|
|
323
|
+
if (errorMessage.includes('not configured')) {
|
|
324
|
+
throw new auth_errors_1.GoogleSignInNotConfiguredError();
|
|
325
|
+
}
|
|
326
|
+
if (errorMessage.includes('did not return email')) {
|
|
327
|
+
throw new auth_errors_1.GoogleEmailRequiredError();
|
|
328
|
+
}
|
|
329
|
+
throw new auth_errors_1.KoolbaseAuthError(`google sign-in failed: ${errorMessage}`, 'google_signin_failed');
|
|
330
|
+
}
|
|
331
|
+
if (res.status === 401)
|
|
332
|
+
throw new auth_errors_1.InvalidGoogleTokenError();
|
|
333
|
+
if (res.status === 403)
|
|
334
|
+
throw new auth_errors_1.UserDisabledError();
|
|
335
|
+
if (res.status === 409)
|
|
336
|
+
throw new auth_errors_1.OAuthEmailConflictError();
|
|
337
|
+
if (res.status === 429)
|
|
338
|
+
throw new auth_errors_1.RateLimitError(errorMessage);
|
|
339
|
+
throw new auth_errors_1.KoolbaseAuthError(`google sign-in failed: ${res.status} ${errorMessage}`, `google_signin_http_${res.status}`);
|
|
340
|
+
}
|
|
262
341
|
/**
|
|
263
342
|
* Parses a /v1/sdk/auth/oauth/apple response. Distinct from
|
|
264
343
|
* parseSessionResponse because OAuth error semantics differ from
|
package/dist/database.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare class KoolbaseDatabase {
|
|
|
6
6
|
constructor(config: KoolbaseConfig, getUserId: () => string | null);
|
|
7
7
|
private get headers();
|
|
8
8
|
private request;
|
|
9
|
+
private runQuery;
|
|
9
10
|
query(collection: string, options?: QueryOptions): Promise<QueryResult>;
|
|
10
11
|
insert(collection: string, data: Record<string, unknown>): Promise<KoolbaseRecord>;
|
|
11
12
|
get(recordId: string): Promise<KoolbaseRecord>;
|
package/dist/database.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.KoolbaseDatabase = void 0;
|
|
4
4
|
const cache_store_1 = require("./cache-store");
|
|
5
5
|
const sync_engine_1 = require("./sync-engine");
|
|
6
|
+
const record_1 = require("./record");
|
|
6
7
|
function generateId() {
|
|
7
8
|
return 'local_' + Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
8
9
|
}
|
|
@@ -34,13 +35,8 @@ class KoolbaseDatabase {
|
|
|
34
35
|
return data;
|
|
35
36
|
}
|
|
36
37
|
// ─── Query (cache-first) ───────────────────────────────────────────────────
|
|
37
|
-
async
|
|
38
|
-
const
|
|
39
|
-
const queryHash = (0, cache_store_1.hashQuery)(collection, options);
|
|
40
|
-
// 1. Return cached data immediately if available
|
|
41
|
-
const cached = await (0, cache_store_1.getCached)(userId, collection, queryHash);
|
|
42
|
-
// 2. Fetch from network in background
|
|
43
|
-
this.request('POST', '/v1/sdk/db/query', {
|
|
38
|
+
async runQuery(collection, options) {
|
|
39
|
+
const raw = await this.request('POST', '/v1/sdk/db/query', {
|
|
44
40
|
collection,
|
|
45
41
|
filters: options.filters ?? {},
|
|
46
42
|
limit: options.limit ?? 20,
|
|
@@ -48,26 +44,22 @@ class KoolbaseDatabase {
|
|
|
48
44
|
order_by: options.orderBy,
|
|
49
45
|
order_desc: options.orderDesc ?? false,
|
|
50
46
|
populate: options.populate ?? [],
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
});
|
|
48
|
+
return { records: raw.records.map(record_1.recordFromWire), total: raw.total };
|
|
49
|
+
}
|
|
50
|
+
async query(collection, options = {}) {
|
|
51
|
+
const userId = this.getUserId() ?? 'anonymous';
|
|
52
|
+
const queryHash = (0, cache_store_1.hashQuery)(collection, options);
|
|
53
|
+
const cached = await (0, cache_store_1.getCached)(userId, collection, queryHash);
|
|
54
|
+
this.runQuery(collection, options)
|
|
55
|
+
.then(result => (0, cache_store_1.setCached)(userId, collection, queryHash, result))
|
|
55
56
|
.catch(() => {
|
|
56
|
-
// Network unavailable — cached data
|
|
57
|
+
// Network unavailable — cached data already returned
|
|
57
58
|
});
|
|
58
59
|
if (cached) {
|
|
59
60
|
return { ...cached, isFromCache: true };
|
|
60
61
|
}
|
|
61
|
-
|
|
62
|
-
const result = await this.request('POST', '/v1/sdk/db/query', {
|
|
63
|
-
collection,
|
|
64
|
-
filters: options.filters ?? {},
|
|
65
|
-
limit: options.limit ?? 20,
|
|
66
|
-
offset: options.offset ?? 0,
|
|
67
|
-
order_by: options.orderBy,
|
|
68
|
-
order_desc: options.orderDesc ?? false,
|
|
69
|
-
populate: options.populate ?? [],
|
|
70
|
-
});
|
|
62
|
+
const result = await this.runQuery(collection, options);
|
|
71
63
|
await (0, cache_store_1.setCached)(userId, collection, queryHash, result);
|
|
72
64
|
return { ...result, isFromCache: false };
|
|
73
65
|
}
|
|
@@ -77,8 +69,6 @@ class KoolbaseDatabase {
|
|
|
77
69
|
// Build optimistic record
|
|
78
70
|
const optimisticRecord = {
|
|
79
71
|
id: generateId(),
|
|
80
|
-
projectId: '',
|
|
81
|
-
collectionId: '',
|
|
82
72
|
createdBy: userId,
|
|
83
73
|
data,
|
|
84
74
|
createdAt: new Date().toISOString(),
|
|
@@ -109,29 +99,25 @@ class KoolbaseDatabase {
|
|
|
109
99
|
}
|
|
110
100
|
// ─── Get single record ──────────────────────────────────────────────────────
|
|
111
101
|
async get(recordId) {
|
|
112
|
-
|
|
102
|
+
const raw = await this.request('GET', `/v1/sdk/db/records/${recordId}`);
|
|
103
|
+
return (0, record_1.recordFromWire)(raw);
|
|
113
104
|
}
|
|
114
105
|
// ─── Update ─────────────────────────────────────────────────────────────────
|
|
115
106
|
async update(recordId, data) {
|
|
116
107
|
const userId = this.getUserId() ?? 'anonymous';
|
|
117
|
-
// Add to write queue
|
|
118
108
|
await (0, cache_store_1.addToWriteQueue)(userId, {
|
|
119
109
|
id: generateId(),
|
|
120
110
|
type: 'update',
|
|
121
111
|
recordId,
|
|
122
112
|
data,
|
|
123
113
|
});
|
|
124
|
-
// Try network
|
|
125
114
|
try {
|
|
126
|
-
const
|
|
127
|
-
return
|
|
115
|
+
const raw = await this.request('PATCH', `/v1/sdk/db/records/${recordId}`, { data });
|
|
116
|
+
return (0, record_1.recordFromWire)(raw);
|
|
128
117
|
}
|
|
129
118
|
catch {
|
|
130
|
-
// Return optimistic version
|
|
131
119
|
return {
|
|
132
120
|
id: recordId,
|
|
133
|
-
projectId: '',
|
|
134
|
-
collectionId: '',
|
|
135
121
|
data,
|
|
136
122
|
createdAt: '',
|
|
137
123
|
updatedAt: new Date().toISOString(),
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* version-conditional logic (deprecation warnings, schema migrations,
|
|
5
5
|
* feature flags). Must match the `version` field in package.json.
|
|
6
6
|
*/
|
|
7
|
-
export declare const koolbaseSdkVersion = "1.
|
|
7
|
+
export declare const koolbaseSdkVersion = "1.11.0";
|
|
8
8
|
/**
|
|
9
9
|
* Builds device-identifying headers attached to every Koolbase auth
|
|
10
10
|
* request. Mirrors the Flutter SDK's `DeviceMetadata` for parity. Apps
|
package/dist/device-metadata.js
CHANGED
|
@@ -9,7 +9,7 @@ const auth_storage_1 = require("./auth-storage");
|
|
|
9
9
|
* version-conditional logic (deprecation warnings, schema migrations,
|
|
10
10
|
* feature flags). Must match the `version` field in package.json.
|
|
11
11
|
*/
|
|
12
|
-
exports.koolbaseSdkVersion = '1.
|
|
12
|
+
exports.koolbaseSdkVersion = '1.11.0';
|
|
13
13
|
/**
|
|
14
14
|
* Generate a UUIDv4-shaped string for use as a stable per-install
|
|
15
15
|
* device label. Not cryptographically secure — this is a label, not a
|
package/dist/realtime.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.KoolbaseRealtime = void 0;
|
|
4
|
+
const record_1 = require("./record");
|
|
4
5
|
class KoolbaseRealtime {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
this.ws = null;
|
|
@@ -31,7 +32,14 @@ class KoolbaseRealtime {
|
|
|
31
32
|
this.ws = new WebSocket(`${wsUrl}/v1/sdk/realtime?key=${this.config.publicKey}`);
|
|
32
33
|
this.ws.onmessage = (event) => {
|
|
33
34
|
try {
|
|
34
|
-
const
|
|
35
|
+
const raw = JSON.parse(event.data);
|
|
36
|
+
if (!raw || !raw.record)
|
|
37
|
+
return;
|
|
38
|
+
const msg = {
|
|
39
|
+
type: raw.type,
|
|
40
|
+
collection: raw.collection,
|
|
41
|
+
record: (0, record_1.recordFromWire)(raw.record),
|
|
42
|
+
};
|
|
35
43
|
const callbacks = this.listeners.get(msg.collection) ?? [];
|
|
36
44
|
callbacks.forEach((cb) => cb(msg));
|
|
37
45
|
}
|
package/dist/record.d.ts
ADDED
package/dist/record.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.recordFromWire = recordFromWire;
|
|
4
|
+
// Converts the flat public wire shape into a KoolbaseRecord.
|
|
5
|
+
// Server sends: { $id, $createdAt, $updatedAt, $collection, $createdBy?, ...fields }
|
|
6
|
+
function recordFromWire(raw) {
|
|
7
|
+
const data = {};
|
|
8
|
+
for (const key of Object.keys(raw)) {
|
|
9
|
+
if (!key.startsWith('$'))
|
|
10
|
+
data[key] = raw[key];
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
id: raw['$id'],
|
|
14
|
+
collection: raw['$collection'],
|
|
15
|
+
createdBy: raw['$createdBy'],
|
|
16
|
+
data,
|
|
17
|
+
createdAt: raw['$createdAt'],
|
|
18
|
+
updatedAt: raw['$updatedAt'],
|
|
19
|
+
};
|
|
20
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -111,8 +111,7 @@ export interface PhoneVerifyResult {
|
|
|
111
111
|
}
|
|
112
112
|
export interface KoolbaseRecord {
|
|
113
113
|
id: string;
|
|
114
|
-
|
|
115
|
-
collectionId: string;
|
|
114
|
+
collection?: string;
|
|
116
115
|
createdBy?: string;
|
|
117
116
|
data: Record<string, unknown>;
|
|
118
117
|
createdAt: string;
|
|
@@ -224,3 +223,15 @@ export interface SignInWithAppleParams {
|
|
|
224
223
|
nonce?: string;
|
|
225
224
|
fullName?: AppleFullName;
|
|
226
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Parameters for `KoolbaseAuth.signInWithGoogle`. The SDK is
|
|
228
|
+
* library-agnostic — `idToken` should come from any native Google
|
|
229
|
+
* Sign-In package (e.g. `@react-native-google-signin/google-signin`).
|
|
230
|
+
*
|
|
231
|
+
* Unlike Apple, Google embeds the user's name and email in the idToken
|
|
232
|
+
* itself, so no separate `fullName` parameter is needed.
|
|
233
|
+
*/
|
|
234
|
+
export interface SignInWithGoogleParams {
|
|
235
|
+
idToken: string;
|
|
236
|
+
nonce?: string;
|
|
237
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@techfinityedge/koolbase-react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "React Native SDK for Koolbase \u2014 auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|