hydrousdb 1.1.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.
@@ -0,0 +1,219 @@
1
+ // src/analytics/client.ts
2
+ var AnalyticsClient = class {
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ get path() {
7
+ return `/api/analytics/${this.http.bucketKey}/${this.http.bucketKey}`;
8
+ }
9
+ // ── Raw query ─────────────────────────────────────────────────────────────
10
+ /**
11
+ * Run any analytics query with full control over the payload.
12
+ * Prefer the typed convenience methods below for everyday use.
13
+ */
14
+ async query(payload, opts) {
15
+ return this.http.post(this.path, payload, opts);
16
+ }
17
+ // ── count ──────────────────────────────────────────────────────────────────
18
+ /**
19
+ * Total record count, optionally scoped to a date range.
20
+ * Server `queryType`: **"count"**
21
+ *
22
+ * @example
23
+ * const { data } = await db.analytics.count();
24
+ * console.log(data.count); // 1234
25
+ *
26
+ * // With date range
27
+ * const { data } = await db.analytics.count({
28
+ * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' }
29
+ * });
30
+ */
31
+ async count(options) {
32
+ return this.query({ queryType: "count", dateRange: options?.dateRange }, options);
33
+ }
34
+ // ── distribution ───────────────────────────────────────────────────────────
35
+ /**
36
+ * Value distribution (histogram) for a field.
37
+ * Server `queryType`: **"distribution"**
38
+ *
39
+ * @example
40
+ * const { data } = await db.analytics.distribution('status');
41
+ * // [{ value: 'active', count: 80 }, { value: 'archived', count: 20 }]
42
+ */
43
+ async distribution(field, options) {
44
+ return this.query({
45
+ queryType: "distribution",
46
+ field,
47
+ limit: options?.limit,
48
+ order: options?.order,
49
+ dateRange: options?.dateRange
50
+ }, options);
51
+ }
52
+ // ── sum ────────────────────────────────────────────────────────────────────
53
+ /**
54
+ * Sum a numeric field, with optional group-by.
55
+ * Server `queryType`: **"sum"**
56
+ *
57
+ * @example
58
+ * const { data } = await db.analytics.sum('revenue', { groupBy: 'region' });
59
+ */
60
+ async sum(field, options) {
61
+ return this.query({
62
+ queryType: "sum",
63
+ field,
64
+ groupBy: options?.groupBy,
65
+ limit: options?.limit,
66
+ dateRange: options?.dateRange
67
+ }, options);
68
+ }
69
+ // ── timeSeries ─────────────────────────────────────────────────────────────
70
+ /**
71
+ * Record count grouped over time.
72
+ * Server `queryType`: **"timeSeries"**
73
+ *
74
+ * @example
75
+ * const { data } = await db.analytics.timeSeries({ granularity: 'day' });
76
+ * // [{ date: '2025-01-01', count: 42 }, ...]
77
+ */
78
+ async timeSeries(options) {
79
+ return this.query({
80
+ queryType: "timeSeries",
81
+ granularity: options?.granularity,
82
+ dateRange: options?.dateRange
83
+ }, options);
84
+ }
85
+ // ── fieldTimeSeries ────────────────────────────────────────────────────────
86
+ /**
87
+ * Aggregate a numeric field over time.
88
+ * Server `queryType`: **"fieldTimeSeries"**
89
+ *
90
+ * @example
91
+ * const { data } = await db.analytics.fieldTimeSeries('revenue', {
92
+ * granularity: 'month',
93
+ * aggregation: 'sum',
94
+ * });
95
+ */
96
+ async fieldTimeSeries(field, options) {
97
+ return this.query({
98
+ queryType: "fieldTimeSeries",
99
+ field,
100
+ aggregation: options?.aggregation,
101
+ granularity: options?.granularity,
102
+ dateRange: options?.dateRange
103
+ }, options);
104
+ }
105
+ // ── topN ───────────────────────────────────────────────────────────────────
106
+ /**
107
+ * Top N most frequent values for a field.
108
+ * Server `queryType`: **"topN"**
109
+ *
110
+ * @example
111
+ * const { data } = await db.analytics.topN('country', 5);
112
+ * // [{ label: 'US', value: 'US', count: 500 }, ...]
113
+ */
114
+ async topN(field, n = 10, options) {
115
+ return this.query({
116
+ queryType: "topN",
117
+ field,
118
+ n,
119
+ labelField: options?.labelField,
120
+ order: options?.order,
121
+ dateRange: options?.dateRange
122
+ }, options);
123
+ }
124
+ // ── stats ──────────────────────────────────────────────────────────────────
125
+ /**
126
+ * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.
127
+ * Server `queryType`: **"stats"**
128
+ *
129
+ * @example
130
+ * const { data } = await db.analytics.stats('score');
131
+ * console.log(data.avg, data.p99);
132
+ */
133
+ async stats(field, options) {
134
+ return this.query({ queryType: "stats", field, dateRange: options?.dateRange }, options);
135
+ }
136
+ // ── records ────────────────────────────────────────────────────────────────
137
+ /**
138
+ * Filtered, paginated raw records with optional field projection.
139
+ * Supports filter ops: == != > < >= <= CONTAINS
140
+ * Server `queryType`: **"records"**
141
+ *
142
+ * @example
143
+ * const { data } = await db.analytics.records({
144
+ * filters: [{ field: 'role', op: '==', value: 'admin' }],
145
+ * selectFields: ['email', 'createdAt'],
146
+ * limit: 25,
147
+ * });
148
+ * console.log(data.data, data.hasMore);
149
+ */
150
+ async records(options) {
151
+ return this.query({
152
+ queryType: "records",
153
+ filters: options?.filters,
154
+ selectFields: options?.selectFields,
155
+ limit: options?.limit,
156
+ offset: options?.offset,
157
+ orderBy: options?.orderBy,
158
+ order: options?.order,
159
+ dateRange: options?.dateRange
160
+ }, options);
161
+ }
162
+ // ── multiMetric ────────────────────────────────────────────────────────────
163
+ /**
164
+ * Multiple aggregations in a single BigQuery call — ideal for dashboard stat cards.
165
+ * Server `queryType`: **"multiMetric"**
166
+ *
167
+ * @example
168
+ * const { data } = await db.analytics.multiMetric([
169
+ * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
170
+ * { name: 'avgScore', field: 'score', aggregation: 'avg' },
171
+ * { name: 'userCount', field: 'userId', aggregation: 'count' },
172
+ * ]);
173
+ * console.log(data.totalRevenue, data.avgScore, data.userCount);
174
+ */
175
+ async multiMetric(metrics, options) {
176
+ return this.query({
177
+ queryType: "multiMetric",
178
+ metrics,
179
+ dateRange: options?.dateRange
180
+ }, options);
181
+ }
182
+ // ── storageStats ───────────────────────────────────────────────────────────
183
+ /**
184
+ * Storage statistics for the bucket — total records, bytes, avg/min/max size.
185
+ * Server `queryType`: **"storageStats"**
186
+ *
187
+ * @example
188
+ * const { data } = await db.analytics.storageStats();
189
+ * console.log(data.totalRecords, data.totalBytes);
190
+ */
191
+ async storageStats(options) {
192
+ return this.query({ queryType: "storageStats", dateRange: options?.dateRange }, options);
193
+ }
194
+ // ── crossBucket ────────────────────────────────────────────────────────────
195
+ /**
196
+ * Compare a metric across multiple buckets in one query.
197
+ * Server `queryType`: **"crossBucket"**
198
+ *
199
+ * @example
200
+ * const { data } = await db.analytics.crossBucket({
201
+ * bucketKeys: ['sales', 'refunds', 'trials'],
202
+ * field: 'amount',
203
+ * aggregation: 'sum',
204
+ * });
205
+ */
206
+ async crossBucket(options) {
207
+ return this.query({
208
+ queryType: "crossBucket",
209
+ bucketKeys: options.bucketKeys,
210
+ field: options.field,
211
+ aggregation: options.aggregation,
212
+ dateRange: options.dateRange
213
+ }, options);
214
+ }
215
+ };
216
+
217
+ export { AnalyticsClient };
218
+ //# sourceMappingURL=index.mjs.map
219
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/analytics/client.ts"],"names":[],"mappings":";AAsBO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA,EAEhD,IAAY,IAAA,GAAO;AAEjB,IAAA,OAAO,kBAAkB,IAAA,CAAK,IAAA,CAAK,SAAS,CAAA,CAAA,EAAI,IAAA,CAAK,KAAK,SAAS,CAAA,CAAA;AAAA,EACrE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,KAAA,CAAmB,OAAA,EAAyB,IAAA,EAAoD;AACpG,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAyB,IAAA,CAAK,IAAA,EAAM,SAAS,IAAI,CAAA;AAAA,EACpE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,MAAM,OAAA,EAA6F;AACvG,IAAA,OAAO,IAAA,CAAK,MAAmB,EAAE,SAAA,EAAW,SAAS,S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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,WAAA,CACJ,OAAA,EACA,OAAA,EACkD;AAClD,IAAA,OAAO,KAAK,KAAA,CAA8B;AAAA,MACxC,SAAA,EAAW,aAAA;AAAA,MACX,OAAA;AAAA,MACA,WAAW,OAAA,EAAS;AAAA,OACnB,OAAO,CAAA;AAAA,EACZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,aACJ,OAAA,EAC8C;AAC9C,IAAA,OAAO,IAAA,CAAK,MAA0B,EAAE,SAAA,EAAW,gBAAgB,SAAA,EAAW,OAAA,EAAS,SAAA,EAAU,EAAG,OAAO,CAAA;AAAA,EAC7G;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAeA,MAAM,YAAY,OAAA,EAKqC;AACrD,IAAA,OAAO,KAAK,KAAA,CAAe;AAAA,MACzB,SAAA,EAAa,aAAA;AAAA,MACb,YAAa,OAAA,CAAQ,UAAA;AAAA,MACrB,OAAa,OAAA,CAAQ,KAAA;AAAA,MACrB,aAAa,OAAA,CAAQ,WAAA;AAAA,MACrB,WAAa,OAAA,CAAQ;AAAA,OACpB,OAAO,CAAA;AAAA,EACZ;AACF","file":"index.mjs","sourcesContent":["import type { HttpClient } from '../utils/http.js';\nimport type {\n AnalyticsQuery,\n AnalyticsResponse,\n DateRange,\n Filter,\n MultiMetricItem,\n RequestOptions,\n CountResult,\n DistributionItem,\n SumResult,\n TimeSeriesPoint,\n FieldTimeSeriesPoint,\n TopNItem,\n FieldStatsResult,\n FilteredRecordsResult,\n StorageStatsResult,\n} from '../types/index.js';\n\n// Typed wrapper so callers get proper return types\ntype AnalyticsResult<T> = Omit<AnalyticsResponse, 'data'> & { data: T; queryType: string; bucketKey: string | null; projectId: string };\n\nexport class AnalyticsClient {\n constructor(private readonly http: HttpClient) {}\n\n private get path() {\n // POST /api/analytics/:bucketKey/:key — bucketKey and apiKey both in URL\n return `/api/analytics/${this.http.bucketKey}/${this.http.bucketKey}`;\n }\n\n // ── Raw query ─────────────────────────────────────────────────────────────\n\n /**\n * Run any analytics query with full control over the payload.\n * Prefer the typed convenience methods below for everyday use.\n */\n async query<T = unknown>(payload: AnalyticsQuery, opts?: RequestOptions): Promise<AnalyticsResult<T>> {\n return this.http.post<AnalyticsResult<T>>(this.path, payload, opts);\n }\n\n // ── count ──────────────────────────────────────────────────────────────────\n\n /**\n * Total record count, optionally scoped to a date range.\n * Server `queryType`: **\"count\"**\n *\n * @example\n * const { data } = await db.analytics.count();\n * console.log(data.count); // 1234\n *\n * // With date range\n * const { data } = await db.analytics.count({\n * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' }\n * });\n */\n async count(options?: { dateRange?: DateRange } & RequestOptions): Promise<AnalyticsResult<CountResult>> {\n return this.query<CountResult>({ queryType: 'count', dateRange: options?.dateRange }, options);\n }\n\n // ── distribution ───────────────────────────────────────────────────────────\n\n /**\n * Value distribution (histogram) for a field.\n * Server `queryType`: **\"distribution\"**\n *\n * @example\n * const { data } = await db.analytics.distribution('status');\n * // [{ value: 'active', count: 80 }, { value: 'archived', count: 20 }]\n */\n async distribution(\n field: string,\n options?: { limit?: number; order?: 'asc' | 'desc'; dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<DistributionItem[]>> {\n return this.query<DistributionItem[]>({\n queryType: 'distribution',\n field,\n limit: options?.limit,\n order: options?.order,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── sum ────────────────────────────────────────────────────────────────────\n\n /**\n * Sum a numeric field, with optional group-by.\n * Server `queryType`: **\"sum\"**\n *\n * @example\n * const { data } = await db.analytics.sum('revenue', { groupBy: 'region' });\n */\n async sum(\n field: string,\n options?: { groupBy?: string; limit?: number; dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<SumResult>> {\n return this.query<SumResult>({\n queryType: 'sum',\n field,\n groupBy: options?.groupBy,\n limit: options?.limit,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── timeSeries ─────────────────────────────────────────────────────────────\n\n /**\n * Record count grouped over time.\n * Server `queryType`: **\"timeSeries\"**\n *\n * @example\n * const { data } = await db.analytics.timeSeries({ granularity: 'day' });\n * // [{ date: '2025-01-01', count: 42 }, ...]\n */\n async timeSeries(options?: {\n granularity?: 'hour' | 'day' | 'week' | 'month';\n dateRange?: DateRange;\n } & RequestOptions): Promise<AnalyticsResult<TimeSeriesPoint[]>> {\n return this.query<TimeSeriesPoint[]>({\n queryType: 'timeSeries',\n granularity: options?.granularity,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── fieldTimeSeries ────────────────────────────────────────────────────────\n\n /**\n * Aggregate a numeric field over time.\n * Server `queryType`: **\"fieldTimeSeries\"**\n *\n * @example\n * const { data } = await db.analytics.fieldTimeSeries('revenue', {\n * granularity: 'month',\n * aggregation: 'sum',\n * });\n */\n async fieldTimeSeries(\n field: string,\n options?: {\n aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';\n granularity?: 'hour' | 'day' | 'week' | 'month';\n dateRange?: DateRange;\n } & RequestOptions\n ): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>> {\n return this.query<FieldTimeSeriesPoint[]>({\n queryType: 'fieldTimeSeries',\n field,\n aggregation: options?.aggregation,\n granularity: options?.granularity,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── topN ───────────────────────────────────────────────────────────────────\n\n /**\n * Top N most frequent values for a field.\n * Server `queryType`: **\"topN\"**\n *\n * @example\n * const { data } = await db.analytics.topN('country', 5);\n * // [{ label: 'US', value: 'US', count: 500 }, ...]\n */\n async topN(\n field: string,\n n = 10,\n options?: { labelField?: string; order?: 'asc' | 'desc'; dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<TopNItem[]>> {\n return this.query<TopNItem[]>({\n queryType: 'topN',\n field,\n n,\n labelField: options?.labelField,\n order: options?.order,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── stats ──────────────────────────────────────────────────────────────────\n\n /**\n * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.\n * Server `queryType`: **\"stats\"**\n *\n * @example\n * const { data } = await db.analytics.stats('score');\n * console.log(data.avg, data.p99);\n */\n async stats(\n field: string,\n options?: { dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<FieldStatsResult>> {\n return this.query<FieldStatsResult>({ queryType: 'stats', field, dateRange: options?.dateRange }, options);\n }\n\n // ── records ────────────────────────────────────────────────────────────────\n\n /**\n * Filtered, paginated raw records with optional field projection.\n * Supports filter ops: == != > < >= <= CONTAINS\n * Server `queryType`: **\"records\"**\n *\n * @example\n * const { data } = await db.analytics.records({\n * filters: [{ field: 'role', op: '==', value: 'admin' }],\n * selectFields: ['email', 'createdAt'],\n * limit: 25,\n * });\n * console.log(data.data, data.hasMore);\n */\n async records(options?: {\n filters?: Filter[];\n selectFields?: string[];\n limit?: number;\n offset?: number;\n orderBy?: string;\n order?: 'asc' | 'desc';\n dateRange?: DateRange;\n } & RequestOptions): Promise<AnalyticsResult<FilteredRecordsResult>> {\n return this.query<FilteredRecordsResult>({\n queryType: 'records',\n filters: options?.filters,\n selectFields: options?.selectFields,\n limit: options?.limit,\n offset: options?.offset,\n orderBy: options?.orderBy,\n order: options?.order,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── multiMetric ────────────────────────────────────────────────────────────\n\n /**\n * Multiple aggregations in a single BigQuery call — ideal for dashboard stat cards.\n * Server `queryType`: **\"multiMetric\"**\n *\n * @example\n * const { data } = await db.analytics.multiMetric([\n * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },\n * { name: 'avgScore', field: 'score', aggregation: 'avg' },\n * { name: 'userCount', field: 'userId', aggregation: 'count' },\n * ]);\n * console.log(data.totalRevenue, data.avgScore, data.userCount);\n */\n async multiMetric(\n metrics: MultiMetricItem[],\n options?: { dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<Record<string, number>>> {\n return this.query<Record<string, number>>({\n queryType: 'multiMetric',\n metrics,\n dateRange: options?.dateRange,\n }, options);\n }\n\n // ── storageStats ───────────────────────────────────────────────────────────\n\n /**\n * Storage statistics for the bucket — total records, bytes, avg/min/max size.\n * Server `queryType`: **\"storageStats\"**\n *\n * @example\n * const { data } = await db.analytics.storageStats();\n * console.log(data.totalRecords, data.totalBytes);\n */\n async storageStats(\n options?: { dateRange?: DateRange } & RequestOptions\n ): Promise<AnalyticsResult<StorageStatsResult>> {\n return this.query<StorageStatsResult>({ queryType: 'storageStats', dateRange: options?.dateRange }, options);\n }\n\n // ── crossBucket ────────────────────────────────────────────────────────────\n\n /**\n * Compare a metric across multiple buckets in one query.\n * Server `queryType`: **\"crossBucket\"**\n *\n * @example\n * const { data } = await db.analytics.crossBucket({\n * bucketKeys: ['sales', 'refunds', 'trials'],\n * field: 'amount',\n * aggregation: 'sum',\n * });\n */\n async crossBucket(options: {\n bucketKeys: string[];\n field: string;\n aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';\n dateRange?: DateRange;\n } & RequestOptions): Promise<AnalyticsResult<unknown>> {\n return this.query<unknown>({\n queryType: 'crossBucket',\n bucketKeys: options.bucketKeys,\n field: options.field,\n aggregation: options.aggregation,\n dateRange: options.dateRange,\n }, options);\n }\n}\n"]}
@@ -0,0 +1,180 @@
1
+ import { a9 as HttpClient, _ as SignUpPayload, V as RequestOptions, $ as SignUpResponse, X as SignInPayload, Y as SignInResponse, Z as SignOutPayload, a8 as ValidateSessionResponse, U as RefreshSessionResponse, x as GetUserResponse, L as ListUsersResponse, a6 as UpdateUserPayload, a7 as UpdateUserResponse, K as PasswordChangePayload, O as PasswordResetRequestPayload, N as PasswordResetConfirmPayload, q as EmailVerifyRequestPayload, E as EmailVerifyConfirmPayload, A as AccountLockPayload, b as AccountLockResponse, g as AuthUser } from '../http-CIXLF5GV.mjs';
2
+ export { W as SessionInfo } from '../http-CIXLF5GV.mjs';
3
+
4
+ declare class AuthClient {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ private get path();
8
+ /**
9
+ * Create a new user account. Returns the user and a session immediately.
10
+ *
11
+ * @example
12
+ * const { data, session } = await db.auth.signUp({
13
+ * email: 'alice@example.com',
14
+ * password: 'Str0ngP@ss!',
15
+ * fullName: 'Alice Smith',
16
+ * });
17
+ * // Store session.sessionId and session.refreshToken in your app
18
+ */
19
+ signUp(payload: SignUpPayload, opts?: RequestOptions): Promise<SignUpResponse>;
20
+ /**
21
+ * Authenticate with email + password. Returns user data and a new session.
22
+ *
23
+ * @example
24
+ * const { data, session } = await db.auth.signIn({
25
+ * email: 'alice@example.com',
26
+ * password: 'Str0ngP@ss!',
27
+ * });
28
+ */
29
+ signIn(payload: SignInPayload, opts?: RequestOptions): Promise<SignInResponse>;
30
+ /**
31
+ * Revoke a session (or all sessions for a user).
32
+ *
33
+ * @example
34
+ * // Single device
35
+ * await db.auth.signOut({ sessionId: 'sess_...' });
36
+ *
37
+ * // All devices
38
+ * await db.auth.signOut({ allDevices: true, userId: 'user_...' });
39
+ */
40
+ signOut(payload: SignOutPayload, opts?: RequestOptions): Promise<{
41
+ success: true;
42
+ message: string;
43
+ }>;
44
+ /**
45
+ * Validate a session token — use this on every protected request in your backend.
46
+ *
47
+ * @example
48
+ * try {
49
+ * const { data } = await db.auth.validateSession(sessionId);
50
+ * // data is the authenticated user
51
+ * } catch (err) {
52
+ * // Session expired or invalid
53
+ * }
54
+ */
55
+ validateSession(sessionId: string, opts?: RequestOptions): Promise<ValidateSessionResponse>;
56
+ /**
57
+ * Exchange a refresh token for a new session (rotation).
58
+ * The old session is revoked.
59
+ *
60
+ * @example
61
+ * const { session } = await db.auth.refreshSession(refreshToken);
62
+ */
63
+ refreshSession(refreshToken: string, opts?: RequestOptions): Promise<RefreshSessionResponse>;
64
+ /**
65
+ * Fetch a user by their ID.
66
+ *
67
+ * @example
68
+ * const { data } = await db.auth.getUser('user_abc123');
69
+ */
70
+ getUser(userId: string, opts?: RequestOptions): Promise<GetUserResponse>;
71
+ /**
72
+ * List users with cursor-based pagination.
73
+ *
74
+ * @example
75
+ * const { data, meta } = await db.auth.listUsers({ limit: 50 });
76
+ */
77
+ listUsers(options?: {
78
+ limit?: number;
79
+ cursor?: string;
80
+ } & RequestOptions): Promise<ListUsersResponse>;
81
+ /**
82
+ * Update user profile fields.
83
+ *
84
+ * @example
85
+ * await db.auth.updateUser({ userId: 'user_abc', updates: { fullName: 'Bob Smith' } });
86
+ */
87
+ updateUser(payload: UpdateUserPayload, opts?: RequestOptions): Promise<UpdateUserResponse>;
88
+ /**
89
+ * Soft-delete a user. All their sessions are revoked automatically.
90
+ *
91
+ * @example
92
+ * await db.auth.deleteUser('user_abc123');
93
+ */
94
+ deleteUser(userId: string, opts?: RequestOptions): Promise<{
95
+ success: true;
96
+ message: string;
97
+ }>;
98
+ /**
99
+ * Change password for a signed-in user (requires old password).
100
+ * All sessions are revoked after success.
101
+ *
102
+ * @example
103
+ * await db.auth.changePassword({
104
+ * userId: 'user_abc',
105
+ * oldPassword: 'Old@Pass1',
106
+ * newPassword: 'New@Pass2',
107
+ * });
108
+ */
109
+ changePassword(payload: PasswordChangePayload, opts?: RequestOptions): Promise<{
110
+ success: true;
111
+ message: string;
112
+ }>;
113
+ /**
114
+ * Request a password reset email.
115
+ * Always returns success to prevent email enumeration.
116
+ *
117
+ * @example
118
+ * await db.auth.requestPasswordReset({ email: 'alice@example.com' });
119
+ */
120
+ requestPasswordReset(payload: PasswordResetRequestPayload, opts?: RequestOptions): Promise<{
121
+ success: true;
122
+ message: string;
123
+ }>;
124
+ /**
125
+ * Confirm a password reset using the token from the reset email.
126
+ *
127
+ * @example
128
+ * await db.auth.confirmPasswordReset({ resetToken: 'tok_...', newPassword: 'New@Pass2' });
129
+ */
130
+ confirmPasswordReset(payload: PasswordResetConfirmPayload, opts?: RequestOptions): Promise<{
131
+ success: true;
132
+ message: string;
133
+ }>;
134
+ /**
135
+ * Send a verification email to the user.
136
+ *
137
+ * @example
138
+ * await db.auth.requestEmailVerification({ userId: 'user_abc' });
139
+ */
140
+ requestEmailVerification(payload: EmailVerifyRequestPayload, opts?: RequestOptions): Promise<{
141
+ success: true;
142
+ message: string;
143
+ }>;
144
+ /**
145
+ * Confirm email address using the token from the verification email.
146
+ *
147
+ * @example
148
+ * await db.auth.confirmEmailVerification({ verifyToken: 'tok_...' });
149
+ */
150
+ confirmEmailVerification(payload: EmailVerifyConfirmPayload, opts?: RequestOptions): Promise<{
151
+ success: true;
152
+ message: string;
153
+ }>;
154
+ /**
155
+ * Lock a user account for a given duration (default: 15 min).
156
+ *
157
+ * @example
158
+ * await db.auth.lockAccount({ userId: 'user_abc', duration: 30 * 60 * 1000 });
159
+ */
160
+ lockAccount(payload: AccountLockPayload, opts?: RequestOptions): Promise<AccountLockResponse>;
161
+ /**
162
+ * Unlock a previously locked user account.
163
+ *
164
+ * @example
165
+ * await db.auth.unlockAccount('user_abc');
166
+ */
167
+ unlockAccount(userId: string, opts?: RequestOptions): Promise<{
168
+ success: true;
169
+ message: string;
170
+ }>;
171
+ /**
172
+ * Fetch all users, automatically following cursors.
173
+ *
174
+ * @example
175
+ * const users = await db.auth.listAllUsers();
176
+ */
177
+ listAllUsers(opts?: RequestOptions): Promise<AuthUser[]>;
178
+ }
179
+
180
+ export { AccountLockPayload, AccountLockResponse, AuthClient, AuthUser, EmailVerifyConfirmPayload, EmailVerifyRequestPayload, GetUserResponse, ListUsersResponse, PasswordChangePayload, PasswordResetConfirmPayload, PasswordResetRequestPayload, RefreshSessionResponse, SignInPayload, SignInResponse, SignOutPayload, SignUpPayload, SignUpResponse, UpdateUserPayload, UpdateUserResponse, ValidateSessionResponse };
@@ -0,0 +1,180 @@
1
+ import { a9 as HttpClient, _ as SignUpPayload, V as RequestOptions, $ as SignUpResponse, X as SignInPayload, Y as SignInResponse, Z as SignOutPayload, a8 as ValidateSessionResponse, U as RefreshSessionResponse, x as GetUserResponse, L as ListUsersResponse, a6 as UpdateUserPayload, a7 as UpdateUserResponse, K as PasswordChangePayload, O as PasswordResetRequestPayload, N as PasswordResetConfirmPayload, q as EmailVerifyRequestPayload, E as EmailVerifyConfirmPayload, A as AccountLockPayload, b as AccountLockResponse, g as AuthUser } from '../http-CIXLF5GV.js';
2
+ export { W as SessionInfo } from '../http-CIXLF5GV.js';
3
+
4
+ declare class AuthClient {
5
+ private readonly http;
6
+ constructor(http: HttpClient);
7
+ private get path();
8
+ /**
9
+ * Create a new user account. Returns the user and a session immediately.
10
+ *
11
+ * @example
12
+ * const { data, session } = await db.auth.signUp({
13
+ * email: 'alice@example.com',
14
+ * password: 'Str0ngP@ss!',
15
+ * fullName: 'Alice Smith',
16
+ * });
17
+ * // Store session.sessionId and session.refreshToken in your app
18
+ */
19
+ signUp(payload: SignUpPayload, opts?: RequestOptions): Promise<SignUpResponse>;
20
+ /**
21
+ * Authenticate with email + password. Returns user data and a new session.
22
+ *
23
+ * @example
24
+ * const { data, session } = await db.auth.signIn({
25
+ * email: 'alice@example.com',
26
+ * password: 'Str0ngP@ss!',
27
+ * });
28
+ */
29
+ signIn(payload: SignInPayload, opts?: RequestOptions): Promise<SignInResponse>;
30
+ /**
31
+ * Revoke a session (or all sessions for a user).
32
+ *
33
+ * @example
34
+ * // Single device
35
+ * await db.auth.signOut({ sessionId: 'sess_...' });
36
+ *
37
+ * // All devices
38
+ * await db.auth.signOut({ allDevices: true, userId: 'user_...' });
39
+ */
40
+ signOut(payload: SignOutPayload, opts?: RequestOptions): Promise<{
41
+ success: true;
42
+ message: string;
43
+ }>;
44
+ /**
45
+ * Validate a session token — use this on every protected request in your backend.
46
+ *
47
+ * @example
48
+ * try {
49
+ * const { data } = await db.auth.validateSession(sessionId);
50
+ * // data is the authenticated user
51
+ * } catch (err) {
52
+ * // Session expired or invalid
53
+ * }
54
+ */
55
+ validateSession(sessionId: string, opts?: RequestOptions): Promise<ValidateSessionResponse>;
56
+ /**
57
+ * Exchange a refresh token for a new session (rotation).
58
+ * The old session is revoked.
59
+ *
60
+ * @example
61
+ * const { session } = await db.auth.refreshSession(refreshToken);
62
+ */
63
+ refreshSession(refreshToken: string, opts?: RequestOptions): Promise<RefreshSessionResponse>;
64
+ /**
65
+ * Fetch a user by their ID.
66
+ *
67
+ * @example
68
+ * const { data } = await db.auth.getUser('user_abc123');
69
+ */
70
+ getUser(userId: string, opts?: RequestOptions): Promise<GetUserResponse>;
71
+ /**
72
+ * List users with cursor-based pagination.
73
+ *
74
+ * @example
75
+ * const { data, meta } = await db.auth.listUsers({ limit: 50 });
76
+ */
77
+ listUsers(options?: {
78
+ limit?: number;
79
+ cursor?: string;
80
+ } & RequestOptions): Promise<ListUsersResponse>;
81
+ /**
82
+ * Update user profile fields.
83
+ *
84
+ * @example
85
+ * await db.auth.updateUser({ userId: 'user_abc', updates: { fullName: 'Bob Smith' } });
86
+ */
87
+ updateUser(payload: UpdateUserPayload, opts?: RequestOptions): Promise<UpdateUserResponse>;
88
+ /**
89
+ * Soft-delete a user. All their sessions are revoked automatically.
90
+ *
91
+ * @example
92
+ * await db.auth.deleteUser('user_abc123');
93
+ */
94
+ deleteUser(userId: string, opts?: RequestOptions): Promise<{
95
+ success: true;
96
+ message: string;
97
+ }>;
98
+ /**
99
+ * Change password for a signed-in user (requires old password).
100
+ * All sessions are revoked after success.
101
+ *
102
+ * @example
103
+ * await db.auth.changePassword({
104
+ * userId: 'user_abc',
105
+ * oldPassword: 'Old@Pass1',
106
+ * newPassword: 'New@Pass2',
107
+ * });
108
+ */
109
+ changePassword(payload: PasswordChangePayload, opts?: RequestOptions): Promise<{
110
+ success: true;
111
+ message: string;
112
+ }>;
113
+ /**
114
+ * Request a password reset email.
115
+ * Always returns success to prevent email enumeration.
116
+ *
117
+ * @example
118
+ * await db.auth.requestPasswordReset({ email: 'alice@example.com' });
119
+ */
120
+ requestPasswordReset(payload: PasswordResetRequestPayload, opts?: RequestOptions): Promise<{
121
+ success: true;
122
+ message: string;
123
+ }>;
124
+ /**
125
+ * Confirm a password reset using the token from the reset email.
126
+ *
127
+ * @example
128
+ * await db.auth.confirmPasswordReset({ resetToken: 'tok_...', newPassword: 'New@Pass2' });
129
+ */
130
+ confirmPasswordReset(payload: PasswordResetConfirmPayload, opts?: RequestOptions): Promise<{
131
+ success: true;
132
+ message: string;
133
+ }>;
134
+ /**
135
+ * Send a verification email to the user.
136
+ *
137
+ * @example
138
+ * await db.auth.requestEmailVerification({ userId: 'user_abc' });
139
+ */
140
+ requestEmailVerification(payload: EmailVerifyRequestPayload, opts?: RequestOptions): Promise<{
141
+ success: true;
142
+ message: string;
143
+ }>;
144
+ /**
145
+ * Confirm email address using the token from the verification email.
146
+ *
147
+ * @example
148
+ * await db.auth.confirmEmailVerification({ verifyToken: 'tok_...' });
149
+ */
150
+ confirmEmailVerification(payload: EmailVerifyConfirmPayload, opts?: RequestOptions): Promise<{
151
+ success: true;
152
+ message: string;
153
+ }>;
154
+ /**
155
+ * Lock a user account for a given duration (default: 15 min).
156
+ *
157
+ * @example
158
+ * await db.auth.lockAccount({ userId: 'user_abc', duration: 30 * 60 * 1000 });
159
+ */
160
+ lockAccount(payload: AccountLockPayload, opts?: RequestOptions): Promise<AccountLockResponse>;
161
+ /**
162
+ * Unlock a previously locked user account.
163
+ *
164
+ * @example
165
+ * await db.auth.unlockAccount('user_abc');
166
+ */
167
+ unlockAccount(userId: string, opts?: RequestOptions): Promise<{
168
+ success: true;
169
+ message: string;
170
+ }>;
171
+ /**
172
+ * Fetch all users, automatically following cursors.
173
+ *
174
+ * @example
175
+ * const users = await db.auth.listAllUsers();
176
+ */
177
+ listAllUsers(opts?: RequestOptions): Promise<AuthUser[]>;
178
+ }
179
+
180
+ export { AccountLockPayload, AccountLockResponse, AuthClient, AuthUser, EmailVerifyConfirmPayload, EmailVerifyRequestPayload, GetUserResponse, ListUsersResponse, PasswordChangePayload, PasswordResetConfirmPayload, PasswordResetRequestPayload, RefreshSessionResponse, SignInPayload, SignInResponse, SignOutPayload, SignUpPayload, SignUpResponse, UpdateUserPayload, UpdateUserResponse, ValidateSessionResponse };