hydrousdb 3.5.0 → 3.5.2

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/dist/index.d.cts 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;
@@ -133,6 +193,49 @@ interface QueryOptions {
133
193
  startAt?: string;
134
194
  endAt?: string;
135
195
  dateRange?: DateRange;
196
+ /**
197
+ * Time-scope shorthand filter — narrows the query to a specific day, month, or year
198
+ * using the record ID prefix convention.
199
+ *
200
+ * Format: `_<type>_<code>`
201
+ * - Day: `_day_YYMMDD` e.g. `_day_260305` → March 5, 2026
202
+ * - Month: `_month_YYMM` e.g. `_month_2603` → March 2026
203
+ * - Year: `_year_YY` e.g. `_year_26` → 2026
204
+ *
205
+ * Maps to `?timeScope=` on the server.
206
+ *
207
+ * @example
208
+ * // All records from March 2026
209
+ * await posts.query({ timeScope: '_month_2603' });
210
+ *
211
+ * // All records from a specific day
212
+ * await posts.query({ timeScope: '_day_260305' });
213
+ */
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;
136
239
  }
137
240
  interface QueryResult<T = RecordData> {
138
241
  records: (T & RecordResult)[];
@@ -395,6 +498,83 @@ declare class AuthClient {
395
498
  sessionId: string;
396
499
  allDevices?: boolean;
397
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>;
398
578
  /**
399
579
  * Validate an existing session and retrieve the current user.
400
580
  *
@@ -1184,114 +1364,64 @@ declare class HydrousClient {
1184
1364
  */
1185
1365
  declare function createClient(config: HydrousConfig): HydrousClient;
1186
1366
 
1187
- /**
1188
- * routes.ts — Single source of truth for every API path in the HydrousDB SDK.
1189
- *
1190
- * Base URL: https://db-api-82687684612.us-central1.run.app
1191
- *
1192
- * Mount points (from server.js):
1193
- * /api → records router (X-Api-Key: bucketSecurityKey)
1194
- * /api/analytics → analytics router (X-Api-Key: bucketSecurityKey)
1195
- * /api/auth → auth router (X-Api-Key: authKey)
1196
- * /storage → storage router (X-Storage-Key: ssk_…)
1197
- *
1198
- * ⚠️ Keys MUST be sent in headers — NEVER in URLs or query strings.
1199
- * Records + Analytics: X-Api-Key (or Authorization: Bearer …)
1200
- * Storage: X-Storage-Key (or Authorization: Bearer …)
1201
- */
1202
1367
  declare const RECORDS: {
1203
- /** GET|POST|PATCH|DELETE|HEAD /api/:bucketKey */
1368
+ /** Base path for a bucket: GET|POST /api/:bucketKey */
1204
1369
  readonly bucket: (bucketKey: string) => string;
1205
- /** POST /api/:bucketKey/batch/insert */
1370
+ /** Batch insert: POST /api/:bucketKey/batch/insert */
1206
1371
  readonly batchInsert: (bucketKey: string) => string;
1207
- /** POST /api/:bucketKey/batch/update */
1372
+ /** Batch update: POST /api/:bucketKey/batch/update */
1208
1373
  readonly batchUpdate: (bucketKey: string) => string;
1209
- /** POST /api/:bucketKey/batch/delete */
1374
+ /** Batch delete: POST /api/:bucketKey/batch/delete */
1210
1375
  readonly batchDelete: (bucketKey: string) => string;
1211
1376
  };
1212
1377
  declare const ANALYTICS: {
1213
- /** POST /api/analytics/:bucketKey */
1378
+ /** Analytics query: POST /api/analytics/:bucketKey */
1214
1379
  readonly query: (bucketKey: string) => string;
1215
1380
  };
1216
1381
  declare const AUTH: {
1217
- /** POST /api/auth/signup body: { email, password, fullName?, ...extra } */
1218
1382
  readonly signup: "/api/auth/signup";
1219
- /** POST /api/auth/signin body: { email, password } */
1220
1383
  readonly signin: "/api/auth/signin";
1221
- /** POST /api/auth/signout body: { sessionId, allDevices? } */
1222
1384
  readonly signout: "/api/auth/signout";
1223
- /** POST /api/auth/session/validate body: { sessionId } */
1385
+ readonly googleSignIn: "/api/auth/google";
1386
+ readonly googleLink: "/api/auth/google/link";
1387
+ readonly googleUnlink: "/api/auth/google/unlink";
1224
1388
  readonly sessionValidate: "/api/auth/session/validate";
1225
- /** POST /api/auth/session/refresh body: { refreshToken } */
1226
1389
  readonly sessionRefresh: "/api/auth/session/refresh";
1227
- /** GET /api/auth/user?userId=... */
1228
1390
  readonly getUser: "/api/auth/user";
1229
- /** GET /api/auth/users?limit=&cursor= */
1230
- readonly listUsers: "/api/auth/users";
1231
- /** PATCH /api/auth/user body: { sessionId, userId, updates: {...} } */
1232
1391
  readonly updateUser: "/api/auth/user";
1233
- /** DELETE /api/auth/user?userId=... body: { sessionId } */
1234
1392
  readonly deleteUser: "/api/auth/user";
1235
- /** DELETE /api/auth/user/hard?userId=... body: { sessionId } */
1393
+ readonly listUsers: "/api/auth/users";
1236
1394
  readonly hardDeleteUser: "/api/auth/user/hard";
1237
- /** DELETE /api/auth/users/bulk body: { userIds, hard?, sessionId } */
1238
1395
  readonly bulkDeleteUsers: "/api/auth/users/bulk";
1239
- /** POST /api/auth/password/change body: { sessionId, userId, oldPassword, newPassword } */
1396
+ readonly accountLock: "/api/auth/account/lock";
1397
+ readonly accountUnlock: "/api/auth/account/unlock";
1240
1398
  readonly passwordChange: "/api/auth/password/change";
1241
- /** POST /api/auth/password/reset/request body: { email } */
1242
1399
  readonly passwordResetRequest: "/api/auth/password/reset/request";
1243
- /** POST /api/auth/password/reset/confirm body: { resetToken, newPassword } */
1244
1400
  readonly passwordResetConfirm: "/api/auth/password/reset/confirm";
1245
- /** POST /api/auth/email/verify/request body: { userId } */
1246
1401
  readonly emailVerifyRequest: "/api/auth/email/verify/request";
1247
- /** POST /api/auth/email/verify/confirm body: { verifyToken } */
1248
1402
  readonly emailVerifyConfirm: "/api/auth/email/verify/confirm";
1249
- /** POST /api/auth/account/lock body: { sessionId, userId, duration? } */
1250
- readonly accountLock: "/api/auth/account/lock";
1251
- /** POST /api/auth/account/unlock body: { sessionId, userId } */
1252
- readonly accountUnlock: "/api/auth/account/unlock";
1253
1403
  };
1254
1404
  declare const STORAGE: {
1255
- /** GET /storage/info — no auth required */
1256
- readonly info: "/storage/info";
1257
- /** GET /storage/public/:fullScopedPath — no auth required */
1258
- readonly publicFile: (fullScopedPath: string) => string;
1259
- /** POST /storage/upload-url body: { path, mimeType, size, isPublic?, overwrite?, expiresIn? } */
1260
- readonly uploadUrl: "/storage/upload-url";
1261
- /** POST /storage/batch-upload-urls body: { files: [...], expiresIn? } */
1262
- readonly batchUploadUrls: "/storage/batch-upload-urls";
1263
- /** POST /storage/confirm body: { path, mimeType, isPublic? } */
1264
- readonly confirm: "/storage/confirm";
1265
- /** POST /storage/batch-confirm body: { files: [...] } */
1266
- readonly batchConfirm: "/storage/batch-confirm";
1267
- /** POST /storage/upload multipart/form-data: file, path, mimeType, isPublic, overwrite */
1405
+ readonly base: "/storage";
1268
1406
  readonly upload: "/storage/upload";
1269
- /** POST /storage/upload-raw body: { path, content, mimeType?, isPublic?, overwrite? } */
1270
- readonly uploadRaw: "/storage/upload-raw";
1271
- /** GET /storage/list?prefix=&limit=&cursor= */
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";
1272
1414
  readonly list: "/storage/list";
1273
- /** GET /storage/download/:path — requires X-Storage-Key */
1274
- readonly download: (filePath: string) => string;
1275
- /** POST /storage/batch-download body: { paths: [...], concurrency? } */
1276
- readonly batchDownload: "/storage/batch-download";
1277
- /** GET /storage/metadata/:path */
1278
- readonly metadata: (filePath: string) => string;
1279
- /** POST /storage/signed-url body: { path, expiresIn? } */
1415
+ readonly metadata: (encodedPath: string) => string;
1280
1416
  readonly signedUrl: "/storage/signed-url";
1281
- /** PATCH /storage/visibility body: { path, isPublic } */
1282
1417
  readonly visibility: "/storage/visibility";
1283
- /** POST /storage/folder body: { path } */
1284
1418
  readonly folder: "/storage/folder";
1285
- /** DELETE /storage/file body: { path } */
1286
1419
  readonly file: "/storage/file";
1287
- /** DELETE /storage/folder body: { path } */
1288
- readonly folderDelete: "/storage/folder";
1289
- /** POST /storage/move body: { from, to } */
1420
+ readonly folderDelete: "/storage/folder/delete";
1290
1421
  readonly move: "/storage/move";
1291
- /** POST /storage/copy body: { from, to } */
1292
1422
  readonly copy: "/storage/copy";
1293
- /** GET /storage/stats */
1294
1423
  readonly stats: "/storage/stats";
1424
+ readonly info: "/storage/info";
1295
1425
  };
1296
1426
 
1297
1427
  declare class HydrousError extends Error {
@@ -1322,4 +1452,4 @@ declare class NetworkError extends HydrousError {
1322
1452
  constructor(message: string, cause?: unknown);
1323
1453
  }
1324
1454
 
1325
- 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 };