hydrousdb 2.0.0 → 2.0.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.
@@ -1,182 +0,0 @@
1
- // src/analytics/client.ts
2
- var AnalyticsClient = class {
3
- constructor(http) {
4
- this.http = http;
5
- }
6
- /** Builds the path for a given bucket: /api/analytics/:bucketKey/:securityKey */
7
- path(bucketKey) {
8
- return `/api/analytics/${bucketKey}/${this.http.securityKey}`;
9
- }
10
- // ── Raw query ─────────────────────────────────────────────────────────────
11
- /**
12
- * Run any analytics query with full control over the payload.
13
- * Prefer the typed convenience methods below for everyday use.
14
- */
15
- async query(payload, options) {
16
- const { bucketKey, ...rest } = options;
17
- return this.http.post(this.path(bucketKey), payload, rest);
18
- }
19
- // ── count ──────────────────────────────────────────────────────────────────
20
- /**
21
- * Total record count, optionally scoped to a date range.
22
- *
23
- * @example
24
- * const { data } = await db.analytics.count({ bucketKey: 'orders' });
25
- * console.log(data.count);
26
- *
27
- * const { data } = await db.analytics.count({
28
- * bucketKey: 'orders',
29
- * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' },
30
- * });
31
- */
32
- async count(options) {
33
- const { dateRange, ...rest } = options;
34
- return this.query({ queryType: "count", dateRange }, rest);
35
- }
36
- // ── distribution ───────────────────────────────────────────────────────────
37
- /**
38
- * Value distribution (histogram) for a field.
39
- *
40
- * @example
41
- * const { data } = await db.analytics.distribution('status', { bucketKey: 'orders' });
42
- * // [{ value: 'active', count: 80 }, { value: 'archived', count: 20 }]
43
- */
44
- async distribution(field, options) {
45
- const { limit, order, dateRange, ...rest } = options;
46
- return this.query({ queryType: "distribution", field, limit, order, dateRange }, rest);
47
- }
48
- // ── sum ────────────────────────────────────────────────────────────────────
49
- /**
50
- * Sum a numeric field, with optional group-by.
51
- *
52
- * @example
53
- * const { data } = await db.analytics.sum('revenue', { bucketKey: 'orders', groupBy: 'region' });
54
- */
55
- async sum(field, options) {
56
- const { groupBy, limit, dateRange, ...rest } = options;
57
- return this.query({ queryType: "sum", field, groupBy, limit, dateRange }, rest);
58
- }
59
- // ── timeSeries ─────────────────────────────────────────────────────────────
60
- /**
61
- * Record count grouped over time.
62
- *
63
- * @example
64
- * const { data } = await db.analytics.timeSeries({ bucketKey: 'orders', granularity: 'day' });
65
- * // [{ date: '2025-01-01', count: 42 }, ...]
66
- */
67
- async timeSeries(options) {
68
- const { granularity, dateRange, ...rest } = options;
69
- return this.query({ queryType: "timeSeries", granularity, dateRange }, rest);
70
- }
71
- // ── fieldTimeSeries ────────────────────────────────────────────────────────
72
- /**
73
- * Aggregate a numeric field over time.
74
- *
75
- * @example
76
- * const { data } = await db.analytics.fieldTimeSeries('revenue', {
77
- * bucketKey: 'orders',
78
- * granularity: 'month',
79
- * aggregation: 'sum',
80
- * });
81
- */
82
- async fieldTimeSeries(field, options) {
83
- const { aggregation, granularity, dateRange, ...rest } = options;
84
- return this.query({ queryType: "fieldTimeSeries", field, aggregation, granularity, dateRange }, rest);
85
- }
86
- // ── topN ───────────────────────────────────────────────────────────────────
87
- /**
88
- * Top N most frequent values for a field.
89
- *
90
- * @example
91
- * const { data } = await db.analytics.topN('country', 5, { bucketKey: 'users' });
92
- * // [{ label: 'US', value: 'US', count: 500 }, ...]
93
- */
94
- async topN(field, n = 10, options) {
95
- const { labelField, order, dateRange, ...rest } = options;
96
- return this.query({ queryType: "topN", field, n, labelField, order, dateRange }, rest);
97
- }
98
- // ── stats ──────────────────────────────────────────────────────────────────
99
- /**
100
- * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.
101
- *
102
- * @example
103
- * const { data } = await db.analytics.stats('score', { bucketKey: 'users' });
104
- * console.log(data.avg, data.p99);
105
- */
106
- async stats(field, options) {
107
- const { dateRange, ...rest } = options;
108
- return this.query({ queryType: "stats", field, dateRange }, rest);
109
- }
110
- // ── records ────────────────────────────────────────────────────────────────
111
- /**
112
- * Filtered, paginated raw records with optional field projection.
113
- * Supports filter ops: == != > < >= <= CONTAINS
114
- *
115
- * @example
116
- * const { data } = await db.analytics.records({
117
- * bucketKey: 'users',
118
- * filters: [{ field: 'role', op: '==', value: 'admin' }],
119
- * selectFields: ['email', 'createdAt'],
120
- * limit: 25,
121
- * });
122
- */
123
- async records(options) {
124
- const { filters, selectFields, limit, offset, orderBy, order, dateRange, ...rest } = options;
125
- return this.query(
126
- { queryType: "records", filters, selectFields, limit, offset, orderBy, order, dateRange },
127
- rest
128
- );
129
- }
130
- // ── multiMetric ────────────────────────────────────────────────────────────
131
- /**
132
- * Multiple aggregations in a single call — ideal for dashboard stat cards.
133
- *
134
- * @example
135
- * const { data } = await db.analytics.multiMetric(
136
- * [
137
- * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },
138
- * { name: 'avgScore', field: 'score', aggregation: 'avg' },
139
- * ],
140
- * { bucketKey: 'orders' }
141
- * );
142
- * console.log(data.totalRevenue, data.avgScore);
143
- */
144
- async multiMetric(metrics, options) {
145
- const { dateRange, ...rest } = options;
146
- return this.query({ queryType: "multiMetric", metrics, dateRange }, rest);
147
- }
148
- // ── storageStats ───────────────────────────────────────────────────────────
149
- /**
150
- * Storage statistics for a bucket — total records, bytes, avg/min/max size.
151
- *
152
- * @example
153
- * const { data } = await db.analytics.storageStats({ bucketKey: 'orders' });
154
- * console.log(data.totalRecords, data.totalBytes);
155
- */
156
- async storageStats(options) {
157
- const { dateRange, ...rest } = options;
158
- return this.query({ queryType: "storageStats", dateRange }, rest);
159
- }
160
- // ── crossBucket ────────────────────────────────────────────────────────────
161
- /**
162
- * Compare a metric across multiple buckets in one query.
163
- * Note: `bucketKey` here is used only for auth — the actual buckets
164
- * compared are specified via `bucketKeys`.
165
- *
166
- * @example
167
- * const { data } = await db.analytics.crossBucket({
168
- * bucketKey: 'sales-2025', // auth bucket
169
- * bucketKeys: ['sales-2024', 'sales-2025'],
170
- * field: 'amount',
171
- * aggregation: 'sum',
172
- * });
173
- */
174
- async crossBucket(options) {
175
- const { bucketKeys, field, aggregation, dateRange, ...rest } = options;
176
- return this.query({ queryType: "crossBucket", bucketKeys, field, aggregation, dateRange }, rest);
177
- }
178
- };
179
-
180
- export { AnalyticsClient };
181
- //# sourceMappingURL=index.mjs.map
182
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/analytics/client.ts"],"names":[],"mappings":";AAuCO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGxC,KAAK,SAAA,EAA2B;AACtC,IAAA,OAAO,CAAA,eAAA,EAAkB,SAAS,CAAA,CAAA,EAAI,IAAA,CAAK,KAAK,WAAW,CAAA,CAAA;AAAA,EAC7D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,KAAA,CACJ,OAAA,EACA,OAAA,EAC6B;AAC7B,IAAA,MAAM,EAAE,SAAA,EAAW,GAAG,IAAA,EAAK,GAAI,OAAA;AAC/B,IAAA,OAAO,IAAA,CAAK,KAAK,IAAA,CAAyB,IAAA,CAAK,KAAK,SAAS,CAAA,EAAG,SAAS,IAAI,CAAA;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBA,MAAM,MACJ,OAAA,EACuC;AACvC,IAAA,MAAM,EAAE,SAAA,EAAW,GAAG,IAAA,EAAK,GAAI,OAAA;AAC/B,IAAA,OAAO,KAAK,KAAA,CAAmB,EAAE,WAAW,OAAA,EAAS,SAAA,IAAa,IAAI,CAAA;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,YAAA,CACJ,KAAA,EACA,OAAA,EAC8C;AAC9C,IAAA,MAAM,EAAE,KAAA,EAAO,KAAA,EAAO,SAAA,EAAW,GAAG,MAAK,GAAI,OAAA;AAC7C,IAAA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I,CAAA;AAAA,EAClG;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWA,MAAM,aACJ,OAAA,EAC8C;AAC9C,IAAA,MAAM,EAAE,SAAA,EAAW,GAAG,IAAA,EAAK,GAAI,OAAA;AAC/B,IAAA,OAAO,KAAK,KAAA,CAA0B,EAAE,WAAW,cAAA,EAAgB,SAAA,IAAa,IAAI,CAAA;AAAA,EACtF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAiBA,MAAM,YACJ,OAAA,EAMmC;AACnC,IAAA,MAAM,EAAE,UAAA,EAAY,KAAA,EAAO,aAAa,SAAA,EAAW,GAAG,MAAK,GAAI,OAAA;AAC/D,IAAA,OAAO,IAAA,CAAK,KAAA,CAAe,EAAE,SAAA,EAAW,aAAA,EAAe,YAAY,KAAA,EAAO,WAAA,EAAa,SAAA,EAAU,EAAG,IAAI,CAAA;AAAA,EAC1G;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'> & {\n data: T;\n queryType: string;\n bucketKey: string | null;\n projectId: string;\n};\n\n/** Options accepted by every analytics method */\nexport interface BucketOptions {\n /**\n * The bucket to run the analytics query against.\n * Required on all analytics calls.\n *\n * @example\n * const { data } = await db.analytics.count({ bucketKey: 'orders' });\n */\n bucketKey: string;\n}\n\nexport class AnalyticsClient {\n constructor(private readonly http: HttpClient) {}\n\n /** Builds the path for a given bucket: /api/analytics/:bucketKey/:securityKey */\n private path(bucketKey: string): string {\n return `/api/analytics/${bucketKey}/${this.http.securityKey}`;\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>(\n payload: AnalyticsQuery,\n options: BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<T>> {\n const { bucketKey, ...rest } = options;\n return this.http.post<AnalyticsResult<T>>(this.path(bucketKey), payload, rest);\n }\n\n // ── count ──────────────────────────────────────────────────────────────────\n\n /**\n * Total record count, optionally scoped to a date range.\n *\n * @example\n * const { data } = await db.analytics.count({ bucketKey: 'orders' });\n * console.log(data.count);\n *\n * const { data } = await db.analytics.count({\n * bucketKey: 'orders',\n * dateRange: { startDate: '2025-01-01', endDate: '2025-12-31' },\n * });\n */\n async count(\n options: { dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<CountResult>> {\n const { dateRange, ...rest } = options;\n return this.query<CountResult>({ queryType: 'count', dateRange }, rest);\n }\n\n // ── distribution ───────────────────────────────────────────────────────────\n\n /**\n * Value distribution (histogram) for a field.\n *\n * @example\n * const { data } = await db.analytics.distribution('status', { bucketKey: 'orders' });\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 } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<DistributionItem[]>> {\n const { limit, order, dateRange, ...rest } = options;\n return this.query<DistributionItem[]>({ queryType: 'distribution', field, limit, order, dateRange }, rest);\n }\n\n // ── sum ────────────────────────────────────────────────────────────────────\n\n /**\n * Sum a numeric field, with optional group-by.\n *\n * @example\n * const { data } = await db.analytics.sum('revenue', { bucketKey: 'orders', groupBy: 'region' });\n */\n async sum(\n field: string,\n options: { groupBy?: string; limit?: number; dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<SumResult>> {\n const { groupBy, limit, dateRange, ...rest } = options;\n return this.query<SumResult>({ queryType: 'sum', field, groupBy, limit, dateRange }, rest);\n }\n\n // ── timeSeries ─────────────────────────────────────────────────────────────\n\n /**\n * Record count grouped over time.\n *\n * @example\n * const { data } = await db.analytics.timeSeries({ bucketKey: 'orders', granularity: 'day' });\n * // [{ date: '2025-01-01', count: 42 }, ...]\n */\n async timeSeries(\n options: { granularity?: 'hour' | 'day' | 'week' | 'month'; dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<TimeSeriesPoint[]>> {\n const { granularity, dateRange, ...rest } = options;\n return this.query<TimeSeriesPoint[]>({ queryType: 'timeSeries', granularity, dateRange }, rest);\n }\n\n // ── fieldTimeSeries ────────────────────────────────────────────────────────\n\n /**\n * Aggregate a numeric field over time.\n *\n * @example\n * const { data } = await db.analytics.fieldTimeSeries('revenue', {\n * bucketKey: 'orders',\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 } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<FieldTimeSeriesPoint[]>> {\n const { aggregation, granularity, dateRange, ...rest } = options;\n return this.query<FieldTimeSeriesPoint[]>({ queryType: 'fieldTimeSeries', field, aggregation, granularity, dateRange }, rest);\n }\n\n // ── topN ───────────────────────────────────────────────────────────────────\n\n /**\n * Top N most frequent values for a field.\n *\n * @example\n * const { data } = await db.analytics.topN('country', 5, { bucketKey: 'users' });\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 } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<TopNItem[]>> {\n const { labelField, order, dateRange, ...rest } = options;\n return this.query<TopNItem[]>({ queryType: 'topN', field, n, labelField, order, dateRange }, rest);\n }\n\n // ── stats ──────────────────────────────────────────────────────────────────\n\n /**\n * Statistical summary for a numeric field: min, max, avg, stddev, p50, p90, p99.\n *\n * @example\n * const { data } = await db.analytics.stats('score', { bucketKey: 'users' });\n * console.log(data.avg, data.p99);\n */\n async stats(\n field: string,\n options: { dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<FieldStatsResult>> {\n const { dateRange, ...rest } = options;\n return this.query<FieldStatsResult>({ queryType: 'stats', field, dateRange }, rest);\n }\n\n // ── records ────────────────────────────────────────────────────────────────\n\n /**\n * Filtered, paginated raw records with optional field projection.\n * Supports filter ops: == != > < >= <= CONTAINS\n *\n * @example\n * const { data } = await db.analytics.records({\n * bucketKey: 'users',\n * filters: [{ field: 'role', op: '==', value: 'admin' }],\n * selectFields: ['email', 'createdAt'],\n * limit: 25,\n * });\n */\n async records(\n options: {\n filters?: Filter[];\n selectFields?: string[];\n limit?: number;\n offset?: number;\n orderBy?: string;\n order?: 'asc' | 'desc';\n dateRange?: DateRange;\n } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<FilteredRecordsResult>> {\n const { filters, selectFields, limit, offset, orderBy, order, dateRange, ...rest } = options;\n return this.query<FilteredRecordsResult>(\n { queryType: 'records', filters, selectFields, limit, offset, orderBy, order, dateRange },\n rest\n );\n }\n\n // ── multiMetric ────────────────────────────────────────────────────────────\n\n /**\n * Multiple aggregations in a single call — ideal for dashboard stat cards.\n *\n * @example\n * const { data } = await db.analytics.multiMetric(\n * [\n * { name: 'totalRevenue', field: 'amount', aggregation: 'sum' },\n * { name: 'avgScore', field: 'score', aggregation: 'avg' },\n * ],\n * { bucketKey: 'orders' }\n * );\n * console.log(data.totalRevenue, data.avgScore);\n */\n async multiMetric(\n metrics: MultiMetricItem[],\n options: { dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<Record<string, number>>> {\n const { dateRange, ...rest } = options;\n return this.query<Record<string, number>>({ queryType: 'multiMetric', metrics, dateRange }, rest);\n }\n\n // ── storageStats ───────────────────────────────────────────────────────────\n\n /**\n * Storage statistics for a bucket — total records, bytes, avg/min/max size.\n *\n * @example\n * const { data } = await db.analytics.storageStats({ bucketKey: 'orders' });\n * console.log(data.totalRecords, data.totalBytes);\n */\n async storageStats(\n options: { dateRange?: DateRange } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<StorageStatsResult>> {\n const { dateRange, ...rest } = options;\n return this.query<StorageStatsResult>({ queryType: 'storageStats', dateRange }, rest);\n }\n\n // ── crossBucket ────────────────────────────────────────────────────────────\n\n /**\n * Compare a metric across multiple buckets in one query.\n * Note: `bucketKey` here is used only for auth — the actual buckets\n * compared are specified via `bucketKeys`.\n *\n * @example\n * const { data } = await db.analytics.crossBucket({\n * bucketKey: 'sales-2025', // auth bucket\n * bucketKeys: ['sales-2024', 'sales-2025'],\n * field: 'amount',\n * aggregation: 'sum',\n * });\n */\n async crossBucket(\n options: {\n bucketKeys: string[];\n field: string;\n aggregation?: 'sum' | 'avg' | 'min' | 'max' | 'count';\n dateRange?: DateRange;\n } & BucketOptions & RequestOptions\n ): Promise<AnalyticsResult<unknown>> {\n const { bucketKeys, field, aggregation, dateRange, ...rest } = options;\n return this.query<unknown>({ queryType: 'crossBucket', bucketKeys, field, aggregation, dateRange }, rest);\n }\n}\n"]}
@@ -1,180 +0,0 @@
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-DTukpdAU.mjs';
2
- export { W as SessionInfo } from '../http-DTukpdAU.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 };
@@ -1,180 +0,0 @@
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-DTukpdAU.js';
2
- export { W as SessionInfo } from '../http-DTukpdAU.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 };