hydrousdb 3.5.1 → 3.5.3
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 +222 -31
- package/dist/index.cjs +153 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +184 -73
- package/dist/index.d.ts +184 -73
- package/dist/index.mjs +153 -68
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -57,6 +57,35 @@ interface LoginOptions {
|
|
|
57
57
|
email: string;
|
|
58
58
|
password: string;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Options for `auth.continueWithGoogle()`.
|
|
62
|
+
*
|
|
63
|
+
* Pass the Google ID token returned by the Google Sign-In SDK.
|
|
64
|
+
* Your server verifies this token — the SDK never calls Google APIs directly.
|
|
65
|
+
*
|
|
66
|
+
* How to get the idToken:
|
|
67
|
+
* Web (Google Identity Services):
|
|
68
|
+
* `google.accounts.id.initialize({ callback: ({ credential }) => ... })`
|
|
69
|
+
* → credential IS the idToken
|
|
70
|
+
* React Native (@react-native-google-signin/google-signin):
|
|
71
|
+
* `const { idToken } = await GoogleSignin.signIn()`
|
|
72
|
+
* Flutter (google_sign_in):
|
|
73
|
+
* `final idToken = (await account.authentication).idToken`
|
|
74
|
+
*/
|
|
75
|
+
interface GoogleSignInOptions {
|
|
76
|
+
idToken: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Options for `auth.linkGoogle()`.
|
|
80
|
+
* Links a Google account to an existing email/password account so the
|
|
81
|
+
* user can sign in with either method going forward.
|
|
82
|
+
*/
|
|
83
|
+
interface GoogleLinkOptions {
|
|
84
|
+
/** Active session ID of the currently signed-in user. */
|
|
85
|
+
sessionId: string;
|
|
86
|
+
/** Google ID token from the Google Sign-In SDK. */
|
|
87
|
+
idToken: string;
|
|
88
|
+
}
|
|
60
89
|
interface UserRecord {
|
|
61
90
|
id: string;
|
|
62
91
|
email: string;
|
|
@@ -67,6 +96,24 @@ interface UserRecord {
|
|
|
67
96
|
createdAt: number;
|
|
68
97
|
updatedAt: number;
|
|
69
98
|
metadata?: Record<string, unknown>;
|
|
99
|
+
/**
|
|
100
|
+
* Primary authentication provider for this account.
|
|
101
|
+
* 'email' — signed up with email + password
|
|
102
|
+
* 'google' — signed up via Google (no password unless added later)
|
|
103
|
+
*/
|
|
104
|
+
authProvider?: 'email' | 'google' | 'github';
|
|
105
|
+
/**
|
|
106
|
+
* Google profile picture URL.
|
|
107
|
+
* Present for users who signed up or linked Google.
|
|
108
|
+
* Refreshed automatically on each Google sign-in.
|
|
109
|
+
*/
|
|
110
|
+
picture?: string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Stable Google user ID (the `sub` claim from the Google ID token).
|
|
113
|
+
* Never changes even if the user changes their Google email.
|
|
114
|
+
* Only present for users with Google linked.
|
|
115
|
+
*/
|
|
116
|
+
googleId?: string;
|
|
70
117
|
[key: string]: unknown;
|
|
71
118
|
}
|
|
72
119
|
interface Session {
|
|
@@ -81,6 +128,19 @@ interface Session {
|
|
|
81
128
|
interface AuthResult {
|
|
82
129
|
user: UserRecord;
|
|
83
130
|
session: Session;
|
|
131
|
+
/**
|
|
132
|
+
* `true` when this is the very first sign-in (account was just created).
|
|
133
|
+
* `false` for returning users.
|
|
134
|
+
* Present for all auth methods — signup, login, and continueWithGoogle.
|
|
135
|
+
*
|
|
136
|
+
* Use to drive onboarding flows:
|
|
137
|
+
* ```ts
|
|
138
|
+
* const { user, session, isNew } = await auth.continueWithGoogle({ idToken });
|
|
139
|
+
* if (isNew) router.push('/onboarding');
|
|
140
|
+
* else router.push('/dashboard');
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
isNew?: boolean;
|
|
84
144
|
}
|
|
85
145
|
interface UpdateUserOptions {
|
|
86
146
|
sessionId: string;
|
|
@@ -152,6 +212,30 @@ interface QueryOptions {
|
|
|
152
212
|
* await posts.query({ timeScope: '_day_260305' });
|
|
153
213
|
*/
|
|
154
214
|
timeScope?: string;
|
|
215
|
+
/**
|
|
216
|
+
* Start of a date range — inclusive. ISO date string (YYYY-MM-DD).
|
|
217
|
+
* Maps to `?startDate=` on the server.
|
|
218
|
+
* @example '2026-01-01'
|
|
219
|
+
*/
|
|
220
|
+
startDate?: string;
|
|
221
|
+
/**
|
|
222
|
+
* End of a date range — inclusive. ISO date string (YYYY-MM-DD).
|
|
223
|
+
* Maps to `?endDate=` on the server.
|
|
224
|
+
* @example '2026-12-31'
|
|
225
|
+
*/
|
|
226
|
+
endDate?: string;
|
|
227
|
+
/**
|
|
228
|
+
* Restrict the monthly walk to a specific two-digit year.
|
|
229
|
+
* Maps to `?year=` on the server.
|
|
230
|
+
* @example '26' for 2026
|
|
231
|
+
*/
|
|
232
|
+
year?: string;
|
|
233
|
+
/**
|
|
234
|
+
* Field to sort by. Maps to `?sortBy=` on the server.
|
|
235
|
+
* Works on every query path — sorting is always done in-memory after hydration
|
|
236
|
+
* so any field name is accepted, not just indexed ones.
|
|
237
|
+
*/
|
|
238
|
+
sortBy?: string;
|
|
155
239
|
}
|
|
156
240
|
interface QueryResult<T = RecordData> {
|
|
157
241
|
records: (T & RecordResult)[];
|
|
@@ -414,6 +498,83 @@ declare class AuthClient {
|
|
|
414
498
|
sessionId: string;
|
|
415
499
|
allDevices?: boolean;
|
|
416
500
|
}): Promise<void>;
|
|
501
|
+
/**
|
|
502
|
+
* Sign in or create an account using a Google ID token.
|
|
503
|
+
*
|
|
504
|
+
* Pass the `idToken` from the Google Sign-In SDK. Your server verifies the
|
|
505
|
+
* token against Google's public keys, then either creates a new account or
|
|
506
|
+
* signs in the returning user. No password is ever set or required.
|
|
507
|
+
*
|
|
508
|
+
* The returned `AuthResult` is identical in shape to `login()` and `signup()`.
|
|
509
|
+
* Sessions from Google sign-in work with `validateSession`, `refreshSession`,
|
|
510
|
+
* and `logout` — nothing changes after the initial sign-in.
|
|
511
|
+
*
|
|
512
|
+
* Use `isNew` to drive onboarding flows.
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```ts
|
|
516
|
+
* // Web — Google Identity Services
|
|
517
|
+
* google.accounts.id.initialize({
|
|
518
|
+
* client_id: 'YOUR_GOOGLE_CLIENT_ID',
|
|
519
|
+
* callback: async ({ credential }) => {
|
|
520
|
+
* const { user, session, isNew } = await db.auth().continueWithGoogle({
|
|
521
|
+
* idToken: credential,
|
|
522
|
+
* });
|
|
523
|
+
* if (isNew) router.push('/onboarding');
|
|
524
|
+
* else router.push('/dashboard');
|
|
525
|
+
* },
|
|
526
|
+
* });
|
|
527
|
+
*
|
|
528
|
+
* // React Native
|
|
529
|
+
* const { idToken } = await GoogleSignin.signIn();
|
|
530
|
+
* const { user, session, isNew } = await db.auth().continueWithGoogle({ idToken });
|
|
531
|
+
* ```
|
|
532
|
+
*
|
|
533
|
+
* Server: POST /api/auth/google
|
|
534
|
+
* Body: { idToken }
|
|
535
|
+
*/
|
|
536
|
+
continueWithGoogle(options: GoogleSignInOptions): Promise<AuthResult>;
|
|
537
|
+
/**
|
|
538
|
+
* Link a Google account to the currently signed-in user.
|
|
539
|
+
*
|
|
540
|
+
* After linking, the user can sign in with either their email + password
|
|
541
|
+
* or with Google — both produce valid sessions.
|
|
542
|
+
*
|
|
543
|
+
* The server is idempotent — calling this when Google is already linked
|
|
544
|
+
* returns the updated user without creating duplicate entries.
|
|
545
|
+
*
|
|
546
|
+
* @example
|
|
547
|
+
* ```ts
|
|
548
|
+
* // User is signed in with email. They click "Connect Google" in settings.
|
|
549
|
+
* const { idToken } = await GoogleSignin.signIn();
|
|
550
|
+
* const updatedUser = await db.auth().linkGoogle({
|
|
551
|
+
* sessionId: currentSession.sessionId,
|
|
552
|
+
* idToken,
|
|
553
|
+
* });
|
|
554
|
+
* ```
|
|
555
|
+
*
|
|
556
|
+
* Server: POST /api/auth/google/link
|
|
557
|
+
* Body: { sessionId, idToken }
|
|
558
|
+
*/
|
|
559
|
+
linkGoogle(options: GoogleLinkOptions): Promise<UserRecord>;
|
|
560
|
+
/**
|
|
561
|
+
* Unlink Google from the currently signed-in user's account.
|
|
562
|
+
*
|
|
563
|
+
* Only succeeds if the user has a password set — you cannot remove the only
|
|
564
|
+
* sign-in method. If the account was created via Google and has no password,
|
|
565
|
+
* call `changePassword` first.
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```ts
|
|
569
|
+
* await db.auth().unlinkGoogle({ sessionId: currentSession.sessionId });
|
|
570
|
+
* ```
|
|
571
|
+
*
|
|
572
|
+
* Server: DELETE /api/auth/google/unlink
|
|
573
|
+
* Body: { sessionId }
|
|
574
|
+
*/
|
|
575
|
+
unlinkGoogle(options: {
|
|
576
|
+
sessionId: string;
|
|
577
|
+
}): Promise<void>;
|
|
417
578
|
/**
|
|
418
579
|
* Validate an existing session and retrieve the current user.
|
|
419
580
|
*
|
|
@@ -1203,114 +1364,64 @@ declare class HydrousClient {
|
|
|
1203
1364
|
*/
|
|
1204
1365
|
declare function createClient(config: HydrousConfig): HydrousClient;
|
|
1205
1366
|
|
|
1206
|
-
/**
|
|
1207
|
-
* routes.ts — Single source of truth for every API path in the HydrousDB SDK.
|
|
1208
|
-
*
|
|
1209
|
-
* Base URL: https://db-api-82687684612.us-central1.run.app
|
|
1210
|
-
*
|
|
1211
|
-
* Mount points (from server.js):
|
|
1212
|
-
* /api → records router (X-Api-Key: bucketSecurityKey)
|
|
1213
|
-
* /api/analytics → analytics router (X-Api-Key: bucketSecurityKey)
|
|
1214
|
-
* /api/auth → auth router (X-Api-Key: authKey)
|
|
1215
|
-
* /storage → storage router (X-Storage-Key: ssk_…)
|
|
1216
|
-
*
|
|
1217
|
-
* ⚠️ Keys MUST be sent in headers — NEVER in URLs or query strings.
|
|
1218
|
-
* Records + Analytics: X-Api-Key (or Authorization: Bearer …)
|
|
1219
|
-
* Storage: X-Storage-Key (or Authorization: Bearer …)
|
|
1220
|
-
*/
|
|
1221
1367
|
declare const RECORDS: {
|
|
1222
|
-
/** GET|POST
|
|
1368
|
+
/** Base path for a bucket: GET|POST /api/:bucketKey */
|
|
1223
1369
|
readonly bucket: (bucketKey: string) => string;
|
|
1224
|
-
/** POST /api/:bucketKey/batch/insert */
|
|
1370
|
+
/** Batch insert: POST /api/:bucketKey/batch/insert */
|
|
1225
1371
|
readonly batchInsert: (bucketKey: string) => string;
|
|
1226
|
-
/** POST /api/:bucketKey/batch/update */
|
|
1372
|
+
/** Batch update: POST /api/:bucketKey/batch/update */
|
|
1227
1373
|
readonly batchUpdate: (bucketKey: string) => string;
|
|
1228
|
-
/** POST /api/:bucketKey/batch/delete */
|
|
1374
|
+
/** Batch delete: POST /api/:bucketKey/batch/delete */
|
|
1229
1375
|
readonly batchDelete: (bucketKey: string) => string;
|
|
1230
1376
|
};
|
|
1231
1377
|
declare const ANALYTICS: {
|
|
1232
|
-
/** POST /api/analytics/:bucketKey */
|
|
1378
|
+
/** Analytics query: POST /api/analytics/:bucketKey */
|
|
1233
1379
|
readonly query: (bucketKey: string) => string;
|
|
1234
1380
|
};
|
|
1235
1381
|
declare const AUTH: {
|
|
1236
|
-
/** POST /api/auth/signup body: { email, password, fullName?, ...extra } */
|
|
1237
1382
|
readonly signup: "/api/auth/signup";
|
|
1238
|
-
/** POST /api/auth/signin body: { email, password } */
|
|
1239
1383
|
readonly signin: "/api/auth/signin";
|
|
1240
|
-
/** POST /api/auth/signout body: { sessionId, allDevices? } */
|
|
1241
1384
|
readonly signout: "/api/auth/signout";
|
|
1242
|
-
|
|
1385
|
+
readonly googleSignIn: "/api/auth/google";
|
|
1386
|
+
readonly googleLink: "/api/auth/google/link";
|
|
1387
|
+
readonly googleUnlink: "/api/auth/google/unlink";
|
|
1243
1388
|
readonly sessionValidate: "/api/auth/session/validate";
|
|
1244
|
-
/** POST /api/auth/session/refresh body: { refreshToken } */
|
|
1245
1389
|
readonly sessionRefresh: "/api/auth/session/refresh";
|
|
1246
|
-
/** GET /api/auth/user?userId=... */
|
|
1247
1390
|
readonly getUser: "/api/auth/user";
|
|
1248
|
-
/** GET /api/auth/users?limit=&cursor= */
|
|
1249
|
-
readonly listUsers: "/api/auth/users";
|
|
1250
|
-
/** PATCH /api/auth/user body: { sessionId, userId, updates: {...} } */
|
|
1251
1391
|
readonly updateUser: "/api/auth/user";
|
|
1252
|
-
/** DELETE /api/auth/user?userId=... body: { sessionId } */
|
|
1253
1392
|
readonly deleteUser: "/api/auth/user";
|
|
1254
|
-
|
|
1393
|
+
readonly listUsers: "/api/auth/users";
|
|
1255
1394
|
readonly hardDeleteUser: "/api/auth/user/hard";
|
|
1256
|
-
/** DELETE /api/auth/users/bulk body: { userIds, hard?, sessionId } */
|
|
1257
1395
|
readonly bulkDeleteUsers: "/api/auth/users/bulk";
|
|
1258
|
-
|
|
1396
|
+
readonly accountLock: "/api/auth/account/lock";
|
|
1397
|
+
readonly accountUnlock: "/api/auth/account/unlock";
|
|
1259
1398
|
readonly passwordChange: "/api/auth/password/change";
|
|
1260
|
-
/** POST /api/auth/password/reset/request body: { email } */
|
|
1261
1399
|
readonly passwordResetRequest: "/api/auth/password/reset/request";
|
|
1262
|
-
/** POST /api/auth/password/reset/confirm body: { resetToken, newPassword } */
|
|
1263
1400
|
readonly passwordResetConfirm: "/api/auth/password/reset/confirm";
|
|
1264
|
-
/** POST /api/auth/email/verify/request body: { userId } */
|
|
1265
1401
|
readonly emailVerifyRequest: "/api/auth/email/verify/request";
|
|
1266
|
-
/** POST /api/auth/email/verify/confirm body: { verifyToken } */
|
|
1267
1402
|
readonly emailVerifyConfirm: "/api/auth/email/verify/confirm";
|
|
1268
|
-
/** POST /api/auth/account/lock body: { sessionId, userId, duration? } */
|
|
1269
|
-
readonly accountLock: "/api/auth/account/lock";
|
|
1270
|
-
/** POST /api/auth/account/unlock body: { sessionId, userId } */
|
|
1271
|
-
readonly accountUnlock: "/api/auth/account/unlock";
|
|
1272
1403
|
};
|
|
1273
1404
|
declare const STORAGE: {
|
|
1274
|
-
|
|
1275
|
-
readonly info: "/storage/info";
|
|
1276
|
-
/** GET /storage/public/:fullScopedPath — no auth required */
|
|
1277
|
-
readonly publicFile: (fullScopedPath: string) => string;
|
|
1278
|
-
/** POST /storage/upload-url body: { path, mimeType, size, isPublic?, overwrite?, expiresIn? } */
|
|
1279
|
-
readonly uploadUrl: "/storage/upload-url";
|
|
1280
|
-
/** POST /storage/batch-upload-urls body: { files: [...], expiresIn? } */
|
|
1281
|
-
readonly batchUploadUrls: "/storage/batch-upload-urls";
|
|
1282
|
-
/** POST /storage/confirm body: { path, mimeType, isPublic? } */
|
|
1283
|
-
readonly confirm: "/storage/confirm";
|
|
1284
|
-
/** POST /storage/batch-confirm body: { files: [...] } */
|
|
1285
|
-
readonly batchConfirm: "/storage/batch-confirm";
|
|
1286
|
-
/** POST /storage/upload multipart/form-data: file, path, mimeType, isPublic, overwrite */
|
|
1405
|
+
readonly base: "/storage";
|
|
1287
1406
|
readonly upload: "/storage/upload";
|
|
1288
|
-
|
|
1289
|
-
readonly
|
|
1290
|
-
|
|
1407
|
+
readonly uploadRaw: "/storage/upload/raw";
|
|
1408
|
+
readonly uploadUrl: "/storage/upload/url";
|
|
1409
|
+
readonly confirm: "/storage/upload/confirm";
|
|
1410
|
+
readonly batchUploadUrls: "/storage/upload/batch/urls";
|
|
1411
|
+
readonly batchConfirm: "/storage/upload/batch/confirm";
|
|
1412
|
+
readonly download: (encodedPath: string) => string;
|
|
1413
|
+
readonly batchDownload: "/storage/download/batch";
|
|
1291
1414
|
readonly list: "/storage/list";
|
|
1292
|
-
|
|
1293
|
-
readonly download: (filePath: string) => string;
|
|
1294
|
-
/** POST /storage/batch-download body: { paths: [...], concurrency? } */
|
|
1295
|
-
readonly batchDownload: "/storage/batch-download";
|
|
1296
|
-
/** GET /storage/metadata/:path */
|
|
1297
|
-
readonly metadata: (filePath: string) => string;
|
|
1298
|
-
/** POST /storage/signed-url body: { path, expiresIn? } */
|
|
1415
|
+
readonly metadata: (encodedPath: string) => string;
|
|
1299
1416
|
readonly signedUrl: "/storage/signed-url";
|
|
1300
|
-
/** PATCH /storage/visibility body: { path, isPublic } */
|
|
1301
1417
|
readonly visibility: "/storage/visibility";
|
|
1302
|
-
/** POST /storage/folder body: { path } */
|
|
1303
1418
|
readonly folder: "/storage/folder";
|
|
1304
|
-
/** DELETE /storage/file body: { path } */
|
|
1305
1419
|
readonly file: "/storage/file";
|
|
1306
|
-
|
|
1307
|
-
readonly folderDelete: "/storage/folder";
|
|
1308
|
-
/** POST /storage/move body: { from, to } */
|
|
1420
|
+
readonly folderDelete: "/storage/folder/delete";
|
|
1309
1421
|
readonly move: "/storage/move";
|
|
1310
|
-
/** POST /storage/copy body: { from, to } */
|
|
1311
1422
|
readonly copy: "/storage/copy";
|
|
1312
|
-
/** GET /storage/stats */
|
|
1313
1423
|
readonly stats: "/storage/stats";
|
|
1424
|
+
readonly info: "/storage/info";
|
|
1314
1425
|
};
|
|
1315
1426
|
|
|
1316
1427
|
declare class HydrousError extends Error {
|
|
@@ -1341,4 +1452,4 @@ declare class NetworkError extends HydrousError {
|
|
|
1341
1452
|
constructor(message: string, cause?: unknown);
|
|
1342
1453
|
}
|
|
1343
1454
|
|
|
1344
|
-
export { ANALYTICS, AUTH, type Aggregation, AnalyticsClient, AnalyticsError, type AnalyticsFilter, type AnalyticsQuery, type AnalyticsResult, AuthClient, AuthError, type AuthResult, type BatchCreateOptions, type BatchDownloadResult, type BatchUploadItem, type BatchUploadUrlResult, type ChangePasswordOptions, type CountResult, type CreateRecordOptions, type CrossBucketRow, DEFAULT_BASE_URL, type DateRange, type DistributionRow, type FieldStats, type FieldTimeSeriesRow, type FileEntry, type FileMetadata, type Granularity, HttpClient, HydrousClient, type HydrousConfig, HydrousError, type ListOptions, type ListResult, type ListUsersOptions, type ListUsersResult, type LoginOptions, type MetricDefinition, type MultiMetricResult, NetworkError, type PatchRecordOptions, type QueryFilter, type QueryOptions, type QueryResult, type QueryType, RECORDS, type RecordData, RecordError, type RecordHistoryEntry, type RecordResult, RecordsClient, STORAGE, ScopedStorage, type Session, type SignedUrlResult, type SignupOptions, type SortOrder, StorageError, type StorageKeys, StorageManager, type StorageStats, type StorageStatsResult, type SumRow, type TimeSeriesRow, type TopNRow, type UpdateUserOptions, type UploadOptions, type UploadResult, type UploadUrlResult, type UserRecord, ValidationError, createClient };
|
|
1455
|
+
export { ANALYTICS, AUTH, type Aggregation, AnalyticsClient, AnalyticsError, type AnalyticsFilter, type AnalyticsQuery, type AnalyticsResult, AuthClient, AuthError, type AuthResult, type BatchCreateOptions, type BatchDownloadResult, type BatchUploadItem, type BatchUploadUrlResult, type ChangePasswordOptions, type CountResult, type CreateRecordOptions, type CrossBucketRow, DEFAULT_BASE_URL, type DateRange, type DistributionRow, type FieldStats, type FieldTimeSeriesRow, type FileEntry, type FileMetadata, type GoogleLinkOptions, type GoogleSignInOptions, type Granularity, HttpClient, HydrousClient, type HydrousConfig, HydrousError, type ListOptions, type ListResult, type ListUsersOptions, type ListUsersResult, type LoginOptions, type MetricDefinition, type MultiMetricResult, NetworkError, type PatchRecordOptions, type QueryFilter, type QueryOptions, type QueryResult, type QueryType, RECORDS, type RecordData, RecordError, type RecordHistoryEntry, type RecordResult, RecordsClient, STORAGE, ScopedStorage, type Session, type SignedUrlResult, type SignupOptions, type SortOrder, StorageError, type StorageKeys, StorageManager, type StorageStats, type StorageStatsResult, type SumRow, type TimeSeriesRow, type TopNRow, type UpdateUserOptions, type UploadOptions, type UploadResult, type UploadUrlResult, type UserRecord, ValidationError, createClient };
|
package/dist/index.mjs
CHANGED
|
@@ -177,98 +177,74 @@ var HttpClient = class {
|
|
|
177
177
|
|
|
178
178
|
// src/routes.ts
|
|
179
179
|
var RECORDS = {
|
|
180
|
-
/** GET|POST
|
|
180
|
+
/** Base path for a bucket: GET|POST /api/:bucketKey */
|
|
181
181
|
bucket: (bucketKey) => `/api/${bucketKey}`,
|
|
182
|
-
/** POST /api/:bucketKey/batch/insert */
|
|
182
|
+
/** Batch insert: POST /api/:bucketKey/batch/insert */
|
|
183
183
|
batchInsert: (bucketKey) => `/api/${bucketKey}/batch/insert`,
|
|
184
|
-
/** POST /api/:bucketKey/batch/update */
|
|
184
|
+
/** Batch update: POST /api/:bucketKey/batch/update */
|
|
185
185
|
batchUpdate: (bucketKey) => `/api/${bucketKey}/batch/update`,
|
|
186
|
-
/** POST /api/:bucketKey/batch/delete */
|
|
186
|
+
/** Batch delete: POST /api/:bucketKey/batch/delete */
|
|
187
187
|
batchDelete: (bucketKey) => `/api/${bucketKey}/batch/delete`
|
|
188
188
|
};
|
|
189
189
|
var ANALYTICS = {
|
|
190
|
-
/** POST /api/analytics/:bucketKey */
|
|
190
|
+
/** Analytics query: POST /api/analytics/:bucketKey */
|
|
191
191
|
query: (bucketKey) => `/api/analytics/${bucketKey}`
|
|
192
192
|
};
|
|
193
193
|
var AUTH = {
|
|
194
|
-
|
|
194
|
+
// ── Core ────────────────────────────────────────────────────────────────
|
|
195
195
|
signup: "/api/auth/signup",
|
|
196
|
-
/** POST /api/auth/signin body: { email, password } */
|
|
197
196
|
signin: "/api/auth/signin",
|
|
198
|
-
/** POST /api/auth/signout body: { sessionId, allDevices? } */
|
|
199
197
|
signout: "/api/auth/signout",
|
|
200
|
-
|
|
198
|
+
// ── Google OAuth ─────────────────────────────────────────────────────────
|
|
199
|
+
// POST /api/auth/google — sign in or create account via Google ID token
|
|
200
|
+
// POST /api/auth/google/link — link Google to an existing email/password account
|
|
201
|
+
// DELETE /api/auth/google/unlink — remove Google (only if a password is set)
|
|
202
|
+
googleSignIn: "/api/auth/google",
|
|
203
|
+
googleLink: "/api/auth/google/link",
|
|
204
|
+
googleUnlink: "/api/auth/google/unlink",
|
|
205
|
+
// ── Session ──────────────────────────────────────────────────────────────
|
|
201
206
|
sessionValidate: "/api/auth/session/validate",
|
|
202
|
-
/** POST /api/auth/session/refresh body: { refreshToken } */
|
|
203
207
|
sessionRefresh: "/api/auth/session/refresh",
|
|
204
|
-
|
|
208
|
+
// ── User ─────────────────────────────────────────────────────────────────
|
|
205
209
|
getUser: "/api/auth/user",
|
|
206
|
-
/** GET /api/auth/users?limit=&cursor= */
|
|
207
|
-
listUsers: "/api/auth/users",
|
|
208
|
-
/** PATCH /api/auth/user body: { sessionId, userId, updates: {...} } */
|
|
209
210
|
updateUser: "/api/auth/user",
|
|
210
|
-
/** DELETE /api/auth/user?userId=... body: { sessionId } */
|
|
211
211
|
deleteUser: "/api/auth/user",
|
|
212
|
-
|
|
212
|
+
// ── Admin ─────────────────────────────────────────────────────────────────
|
|
213
|
+
listUsers: "/api/auth/users",
|
|
213
214
|
hardDeleteUser: "/api/auth/user/hard",
|
|
214
|
-
/** DELETE /api/auth/users/bulk body: { userIds, hard?, sessionId } */
|
|
215
215
|
bulkDeleteUsers: "/api/auth/users/bulk",
|
|
216
|
-
|
|
216
|
+
// ── Account ───────────────────────────────────────────────────────────────
|
|
217
|
+
accountLock: "/api/auth/account/lock",
|
|
218
|
+
accountUnlock: "/api/auth/account/unlock",
|
|
219
|
+
// ── Password ──────────────────────────────────────────────────────────────
|
|
217
220
|
passwordChange: "/api/auth/password/change",
|
|
218
|
-
/** POST /api/auth/password/reset/request body: { email } */
|
|
219
221
|
passwordResetRequest: "/api/auth/password/reset/request",
|
|
220
|
-
/** POST /api/auth/password/reset/confirm body: { resetToken, newPassword } */
|
|
221
222
|
passwordResetConfirm: "/api/auth/password/reset/confirm",
|
|
222
|
-
|
|
223
|
+
// ── Email Verification ────────────────────────────────────────────────────
|
|
223
224
|
emailVerifyRequest: "/api/auth/email/verify/request",
|
|
224
|
-
|
|
225
|
-
emailVerifyConfirm: "/api/auth/email/verify/confirm",
|
|
226
|
-
/** POST /api/auth/account/lock body: { sessionId, userId, duration? } */
|
|
227
|
-
accountLock: "/api/auth/account/lock",
|
|
228
|
-
/** POST /api/auth/account/unlock body: { sessionId, userId } */
|
|
229
|
-
accountUnlock: "/api/auth/account/unlock"
|
|
225
|
+
emailVerifyConfirm: "/api/auth/email/verify/confirm"
|
|
230
226
|
};
|
|
231
227
|
var STORAGE = {
|
|
232
|
-
|
|
233
|
-
info: "/storage/info",
|
|
234
|
-
/** GET /storage/public/:fullScopedPath — no auth required */
|
|
235
|
-
publicFile: (fullScopedPath) => `/storage/public/${fullScopedPath}`,
|
|
236
|
-
/** POST /storage/upload-url body: { path, mimeType, size, isPublic?, overwrite?, expiresIn? } */
|
|
237
|
-
uploadUrl: "/storage/upload-url",
|
|
238
|
-
/** POST /storage/batch-upload-urls body: { files: [...], expiresIn? } */
|
|
239
|
-
batchUploadUrls: "/storage/batch-upload-urls",
|
|
240
|
-
/** POST /storage/confirm body: { path, mimeType, isPublic? } */
|
|
241
|
-
confirm: "/storage/confirm",
|
|
242
|
-
/** POST /storage/batch-confirm body: { files: [...] } */
|
|
243
|
-
batchConfirm: "/storage/batch-confirm",
|
|
244
|
-
/** POST /storage/upload multipart/form-data: file, path, mimeType, isPublic, overwrite */
|
|
228
|
+
base: "/storage",
|
|
245
229
|
upload: "/storage/upload",
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
230
|
+
uploadRaw: "/storage/upload/raw",
|
|
231
|
+
uploadUrl: "/storage/upload/url",
|
|
232
|
+
confirm: "/storage/upload/confirm",
|
|
233
|
+
batchUploadUrls: "/storage/upload/batch/urls",
|
|
234
|
+
batchConfirm: "/storage/upload/batch/confirm",
|
|
235
|
+
download: (encodedPath) => `/storage/download/${encodedPath}`,
|
|
236
|
+
batchDownload: "/storage/download/batch",
|
|
249
237
|
list: "/storage/list",
|
|
250
|
-
|
|
251
|
-
download: (filePath) => `/storage/download/${filePath}`,
|
|
252
|
-
/** POST /storage/batch-download body: { paths: [...], concurrency? } */
|
|
253
|
-
batchDownload: "/storage/batch-download",
|
|
254
|
-
/** GET /storage/metadata/:path */
|
|
255
|
-
metadata: (filePath) => `/storage/metadata/${filePath}`,
|
|
256
|
-
/** POST /storage/signed-url body: { path, expiresIn? } */
|
|
238
|
+
metadata: (encodedPath) => `/storage/metadata/${encodedPath}`,
|
|
257
239
|
signedUrl: "/storage/signed-url",
|
|
258
|
-
/** PATCH /storage/visibility body: { path, isPublic } */
|
|
259
240
|
visibility: "/storage/visibility",
|
|
260
|
-
/** POST /storage/folder body: { path } */
|
|
261
241
|
folder: "/storage/folder",
|
|
262
|
-
/** DELETE /storage/file body: { path } */
|
|
263
242
|
file: "/storage/file",
|
|
264
|
-
|
|
265
|
-
folderDelete: "/storage/folder",
|
|
266
|
-
/** POST /storage/move body: { from, to } */
|
|
243
|
+
folderDelete: "/storage/folder/delete",
|
|
267
244
|
move: "/storage/move",
|
|
268
|
-
/** POST /storage/copy body: { from, to } */
|
|
269
245
|
copy: "/storage/copy",
|
|
270
|
-
|
|
271
|
-
|
|
246
|
+
stats: "/storage/stats",
|
|
247
|
+
info: "/storage/info"
|
|
272
248
|
};
|
|
273
249
|
|
|
274
250
|
// src/auth/client.ts
|
|
@@ -296,8 +272,7 @@ var AuthClient = class {
|
|
|
296
272
|
*/
|
|
297
273
|
async signup(options) {
|
|
298
274
|
const result = await this.post(AUTH.signup, options);
|
|
299
|
-
|
|
300
|
-
return this._buildAuthResult(user, result.session);
|
|
275
|
+
return this._buildAuthResult(result.data, result.session, result.isNew);
|
|
301
276
|
}
|
|
302
277
|
/**
|
|
303
278
|
* Sign in with email + password.
|
|
@@ -307,8 +282,7 @@ var AuthClient = class {
|
|
|
307
282
|
*/
|
|
308
283
|
async login(options) {
|
|
309
284
|
const result = await this.post(AUTH.signin, options);
|
|
310
|
-
|
|
311
|
-
return this._buildAuthResult(user, result.session);
|
|
285
|
+
return this._buildAuthResult(result.data, result.session, result.isNew);
|
|
312
286
|
}
|
|
313
287
|
/**
|
|
314
288
|
* Sign out — revoke a session (or all sessions with `allDevices: true`).
|
|
@@ -319,6 +293,111 @@ var AuthClient = class {
|
|
|
319
293
|
async logout(options) {
|
|
320
294
|
await this.post(AUTH.signout, options);
|
|
321
295
|
}
|
|
296
|
+
// ─── Google Sign-In ───────────────────────────────────────────────────────
|
|
297
|
+
/**
|
|
298
|
+
* Sign in or create an account using a Google ID token.
|
|
299
|
+
*
|
|
300
|
+
* Pass the `idToken` from the Google Sign-In SDK. Your server verifies the
|
|
301
|
+
* token against Google's public keys, then either creates a new account or
|
|
302
|
+
* signs in the returning user. No password is ever set or required.
|
|
303
|
+
*
|
|
304
|
+
* The returned `AuthResult` is identical in shape to `login()` and `signup()`.
|
|
305
|
+
* Sessions from Google sign-in work with `validateSession`, `refreshSession`,
|
|
306
|
+
* and `logout` — nothing changes after the initial sign-in.
|
|
307
|
+
*
|
|
308
|
+
* Use `isNew` to drive onboarding flows.
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* // Web — Google Identity Services
|
|
313
|
+
* google.accounts.id.initialize({
|
|
314
|
+
* client_id: 'YOUR_GOOGLE_CLIENT_ID',
|
|
315
|
+
* callback: async ({ credential }) => {
|
|
316
|
+
* const { user, session, isNew } = await db.auth().continueWithGoogle({
|
|
317
|
+
* idToken: credential,
|
|
318
|
+
* });
|
|
319
|
+
* if (isNew) router.push('/onboarding');
|
|
320
|
+
* else router.push('/dashboard');
|
|
321
|
+
* },
|
|
322
|
+
* });
|
|
323
|
+
*
|
|
324
|
+
* // React Native
|
|
325
|
+
* const { idToken } = await GoogleSignin.signIn();
|
|
326
|
+
* const { user, session, isNew } = await db.auth().continueWithGoogle({ idToken });
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* Server: POST /api/auth/google
|
|
330
|
+
* Body: { idToken }
|
|
331
|
+
*/
|
|
332
|
+
async continueWithGoogle(options) {
|
|
333
|
+
if (!options.idToken || typeof options.idToken !== "string") {
|
|
334
|
+
throw new Error("[HydrousDB] continueWithGoogle: idToken is required and must be a string.");
|
|
335
|
+
}
|
|
336
|
+
const result = await this.post(AUTH.googleSignIn, {
|
|
337
|
+
idToken: options.idToken
|
|
338
|
+
});
|
|
339
|
+
return this._buildAuthResult(result.data, result.session, result.isNew);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Link a Google account to the currently signed-in user.
|
|
343
|
+
*
|
|
344
|
+
* After linking, the user can sign in with either their email + password
|
|
345
|
+
* or with Google — both produce valid sessions.
|
|
346
|
+
*
|
|
347
|
+
* The server is idempotent — calling this when Google is already linked
|
|
348
|
+
* returns the updated user without creating duplicate entries.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* // User is signed in with email. They click "Connect Google" in settings.
|
|
353
|
+
* const { idToken } = await GoogleSignin.signIn();
|
|
354
|
+
* const updatedUser = await db.auth().linkGoogle({
|
|
355
|
+
* sessionId: currentSession.sessionId,
|
|
356
|
+
* idToken,
|
|
357
|
+
* });
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* Server: POST /api/auth/google/link
|
|
361
|
+
* Body: { sessionId, idToken }
|
|
362
|
+
*/
|
|
363
|
+
async linkGoogle(options) {
|
|
364
|
+
if (!options.sessionId) {
|
|
365
|
+
throw new Error("[HydrousDB] linkGoogle: sessionId is required.");
|
|
366
|
+
}
|
|
367
|
+
if (!options.idToken || typeof options.idToken !== "string") {
|
|
368
|
+
throw new Error("[HydrousDB] linkGoogle: idToken is required and must be a string.");
|
|
369
|
+
}
|
|
370
|
+
const result = await this.post(AUTH.googleLink, {
|
|
371
|
+
sessionId: options.sessionId,
|
|
372
|
+
idToken: options.idToken
|
|
373
|
+
});
|
|
374
|
+
return result.data;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Unlink Google from the currently signed-in user's account.
|
|
378
|
+
*
|
|
379
|
+
* Only succeeds if the user has a password set — you cannot remove the only
|
|
380
|
+
* sign-in method. If the account was created via Google and has no password,
|
|
381
|
+
* call `changePassword` first.
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```ts
|
|
385
|
+
* await db.auth().unlinkGoogle({ sessionId: currentSession.sessionId });
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* Server: DELETE /api/auth/google/unlink
|
|
389
|
+
* Body: { sessionId }
|
|
390
|
+
*/
|
|
391
|
+
async unlinkGoogle(options) {
|
|
392
|
+
if (!options.sessionId) {
|
|
393
|
+
throw new Error("[HydrousDB] unlinkGoogle: sessionId is required.");
|
|
394
|
+
}
|
|
395
|
+
await this.http.request(AUTH.googleUnlink, {
|
|
396
|
+
method: "DELETE",
|
|
397
|
+
body: { sessionId: options.sessionId },
|
|
398
|
+
headers: { "X-Api-Key": this.authKey }
|
|
399
|
+
});
|
|
400
|
+
}
|
|
322
401
|
// ─── Session Management ───────────────────────────────────────────────────
|
|
323
402
|
/**
|
|
324
403
|
* Validate an existing session and retrieve the current user.
|
|
@@ -533,7 +612,7 @@ var AuthClient = class {
|
|
|
533
612
|
await this.post(AUTH.emailVerifyConfirm, { verifyToken });
|
|
534
613
|
}
|
|
535
614
|
// ─── Private helpers ──────────────────────────────────────────────────────
|
|
536
|
-
_buildAuthResult(user, session) {
|
|
615
|
+
_buildAuthResult(user, session, isNew) {
|
|
537
616
|
return {
|
|
538
617
|
user,
|
|
539
618
|
session: {
|
|
@@ -544,7 +623,8 @@ var AuthClient = class {
|
|
|
544
623
|
expiresAt: session.expiresAt,
|
|
545
624
|
refreshToken: session.refreshToken,
|
|
546
625
|
refreshExpiresAt: session.expiresAt
|
|
547
|
-
}
|
|
626
|
+
},
|
|
627
|
+
isNew: isNew ?? false
|
|
548
628
|
};
|
|
549
629
|
}
|
|
550
630
|
};
|
|
@@ -554,16 +634,21 @@ function buildQueryParams(options = {}) {
|
|
|
554
634
|
const params = new URLSearchParams();
|
|
555
635
|
if (options.limit !== void 0) params.set("limit", String(options.limit));
|
|
556
636
|
if (options.offset !== void 0) params.set("offset", String(options.offset));
|
|
557
|
-
if (options.orderBy !== void 0) params.set("sortBy", options.orderBy);
|
|
558
637
|
if (options.order !== void 0) params.set("sortOrder", options.order);
|
|
559
638
|
if (options.fields !== void 0) params.set("fields", options.fields);
|
|
639
|
+
if (options.orderBy !== void 0) params.set("sortBy", options.orderBy);
|
|
640
|
+
if (options.sortBy !== void 0) params.set("sortBy", options.sortBy);
|
|
560
641
|
if (options.startAfter !== void 0) params.set("cursor", options.startAfter);
|
|
561
642
|
if (options.startAt !== void 0) params.set("cursor", options.startAt);
|
|
643
|
+
if (options.endAt !== void 0) params.set("endAt", options.endAt);
|
|
562
644
|
if (options.timeScope !== void 0) params.set("timeScope", options.timeScope);
|
|
563
|
-
if (options.
|
|
645
|
+
if (options.startDate !== void 0) params.set("startDate", options.startDate);
|
|
646
|
+
if (options.endDate !== void 0) params.set("endDate", options.endDate);
|
|
647
|
+
if (options.dateRange?.start !== void 0 && options.startDate === void 0)
|
|
564
648
|
params.set("startDate", new Date(options.dateRange.start).toISOString().split("T")[0]);
|
|
565
|
-
if (options.dateRange?.end !== void 0)
|
|
649
|
+
if (options.dateRange?.end !== void 0 && options.endDate === void 0)
|
|
566
650
|
params.set("endDate", new Date(options.dateRange.end).toISOString().split("T")[0]);
|
|
651
|
+
if (options.year !== void 0) params.set("year", options.year);
|
|
567
652
|
if (options.filters && options.filters.length > 0) {
|
|
568
653
|
for (const f of options.filters) {
|
|
569
654
|
const key = f.op === "==" ? f.field : `${f.field}[${f.op}]`;
|