@lifestreamdynamics/vault-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1121 -0
- package/dist/client.d.ts +143 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +286 -0
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +28 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +49 -0
- package/dist/errors.js.map +1 -0
- package/dist/handle-error.d.ts +8 -0
- package/dist/handle-error.d.ts.map +1 -0
- package/dist/handle-error.js +35 -0
- package/dist/handle-error.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audit-logger.d.ts +29 -0
- package/dist/lib/audit-logger.d.ts.map +1 -0
- package/dist/lib/audit-logger.js +99 -0
- package/dist/lib/audit-logger.js.map +1 -0
- package/dist/lib/encryption.d.ts +34 -0
- package/dist/lib/encryption.d.ts.map +1 -0
- package/dist/lib/encryption.js +87 -0
- package/dist/lib/encryption.js.map +1 -0
- package/dist/lib/signature.d.ts +47 -0
- package/dist/lib/signature.d.ts.map +1 -0
- package/dist/lib/signature.js +71 -0
- package/dist/lib/signature.js.map +1 -0
- package/dist/lib/token-manager.d.ts +80 -0
- package/dist/lib/token-manager.d.ts.map +1 -0
- package/dist/lib/token-manager.js +116 -0
- package/dist/lib/token-manager.js.map +1 -0
- package/dist/resources/admin.d.ts +280 -0
- package/dist/resources/admin.d.ts.map +1 -0
- package/dist/resources/admin.js +236 -0
- package/dist/resources/admin.js.map +1 -0
- package/dist/resources/ai.d.ts +184 -0
- package/dist/resources/ai.d.ts.map +1 -0
- package/dist/resources/ai.js +179 -0
- package/dist/resources/ai.js.map +1 -0
- package/dist/resources/api-keys.d.ts +172 -0
- package/dist/resources/api-keys.d.ts.map +1 -0
- package/dist/resources/api-keys.js +166 -0
- package/dist/resources/api-keys.js.map +1 -0
- package/dist/resources/connectors.d.ts +263 -0
- package/dist/resources/connectors.d.ts.map +1 -0
- package/dist/resources/connectors.js +226 -0
- package/dist/resources/connectors.js.map +1 -0
- package/dist/resources/documents.d.ts +334 -0
- package/dist/resources/documents.d.ts.map +1 -0
- package/dist/resources/documents.js +377 -0
- package/dist/resources/documents.js.map +1 -0
- package/dist/resources/hooks.d.ts +195 -0
- package/dist/resources/hooks.d.ts.map +1 -0
- package/dist/resources/hooks.js +166 -0
- package/dist/resources/hooks.js.map +1 -0
- package/dist/resources/publish.d.ts +165 -0
- package/dist/resources/publish.d.ts.map +1 -0
- package/dist/resources/publish.js +150 -0
- package/dist/resources/publish.js.map +1 -0
- package/dist/resources/search.d.ts +94 -0
- package/dist/resources/search.d.ts.map +1 -0
- package/dist/resources/search.js +76 -0
- package/dist/resources/search.js.map +1 -0
- package/dist/resources/shares.d.ts +130 -0
- package/dist/resources/shares.d.ts.map +1 -0
- package/dist/resources/shares.js +115 -0
- package/dist/resources/shares.js.map +1 -0
- package/dist/resources/subscription.d.ts +172 -0
- package/dist/resources/subscription.d.ts.map +1 -0
- package/dist/resources/subscription.js +166 -0
- package/dist/resources/subscription.js.map +1 -0
- package/dist/resources/teams.d.ts +356 -0
- package/dist/resources/teams.d.ts.map +1 -0
- package/dist/resources/teams.js +395 -0
- package/dist/resources/teams.js.map +1 -0
- package/dist/resources/user.d.ts +92 -0
- package/dist/resources/user.d.ts.map +1 -0
- package/dist/resources/user.js +64 -0
- package/dist/resources/user.js.map +1 -0
- package/dist/resources/vaults.d.ts +144 -0
- package/dist/resources/vaults.d.ts.map +1 -0
- package/dist/resources/vaults.js +158 -0
- package/dist/resources/vaults.js.map +1 -0
- package/dist/resources/webhooks.d.ts +187 -0
- package/dist/resources/webhooks.d.ts.map +1 -0
- package/dist/resources/webhooks.js +171 -0
- package/dist/resources/webhooks.js.map +1 -0
- package/dist/types/api.d.ts +17 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/resources.d.ts +5 -0
- package/dist/types/resources.d.ts.map +1 -0
- package/dist/types/resources.js +2 -0
- package/dist/types/resources.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import type { KyInstance } from 'ky';
|
|
2
|
+
/** System-wide statistics returned by the admin stats endpoint. */
|
|
3
|
+
export interface SystemStats {
|
|
4
|
+
/** Total number of registered users. */
|
|
5
|
+
totalUsers: number;
|
|
6
|
+
/** Total number of vaults across all users. */
|
|
7
|
+
totalVaults: number;
|
|
8
|
+
/** Total number of documents across all vaults. */
|
|
9
|
+
totalDocuments: number;
|
|
10
|
+
/** Total storage used in bytes. */
|
|
11
|
+
totalStorageBytes: number;
|
|
12
|
+
/** Number of active users (logged in within 30 days). */
|
|
13
|
+
activeUsers: number;
|
|
14
|
+
}
|
|
15
|
+
/** A single data point in a timeseries response. */
|
|
16
|
+
export interface TimeseriesDataPoint {
|
|
17
|
+
/** ISO 8601 date string (e.g., `2024-01-15`). */
|
|
18
|
+
date: string;
|
|
19
|
+
/** Numeric value for the metric at this date. */
|
|
20
|
+
value: number;
|
|
21
|
+
}
|
|
22
|
+
/** Response from the timeseries endpoint. */
|
|
23
|
+
export interface TimeseriesResponse {
|
|
24
|
+
/** The metric queried. */
|
|
25
|
+
metric: string;
|
|
26
|
+
/** The time period queried. */
|
|
27
|
+
period: string;
|
|
28
|
+
/** Array of data points. */
|
|
29
|
+
data: TimeseriesDataPoint[];
|
|
30
|
+
}
|
|
31
|
+
/** A user record as returned by admin user listing. */
|
|
32
|
+
export interface AdminUser {
|
|
33
|
+
/** Unique user identifier. */
|
|
34
|
+
id: string;
|
|
35
|
+
/** User email address. */
|
|
36
|
+
email: string;
|
|
37
|
+
/** Display name, or `null`. */
|
|
38
|
+
name: string | null;
|
|
39
|
+
/** User role (`user` or `admin`). */
|
|
40
|
+
role: string;
|
|
41
|
+
/** Whether the user account is active. */
|
|
42
|
+
isActive: boolean;
|
|
43
|
+
/** Current subscription tier. */
|
|
44
|
+
subscriptionTier: string;
|
|
45
|
+
/** ISO 8601 creation timestamp. */
|
|
46
|
+
createdAt: string;
|
|
47
|
+
}
|
|
48
|
+
/** Paginated response for admin user listing. */
|
|
49
|
+
export interface AdminUserListResponse {
|
|
50
|
+
/** Array of user records. */
|
|
51
|
+
users: AdminUser[];
|
|
52
|
+
/** Total number of users matching the filters. */
|
|
53
|
+
total: number;
|
|
54
|
+
/** Current page number. */
|
|
55
|
+
page: number;
|
|
56
|
+
/** Number of users per page. */
|
|
57
|
+
limit: number;
|
|
58
|
+
}
|
|
59
|
+
/** Detailed user information returned by the admin user detail endpoint. */
|
|
60
|
+
export interface AdminUserDetail extends AdminUser {
|
|
61
|
+
/** ISO 8601 last-updated timestamp. */
|
|
62
|
+
updatedAt: string;
|
|
63
|
+
/** Number of vaults owned by the user. */
|
|
64
|
+
vaultCount: number;
|
|
65
|
+
/** Number of documents owned by the user. */
|
|
66
|
+
documentCount: number;
|
|
67
|
+
/** Total storage used in bytes. */
|
|
68
|
+
storageBytes: number;
|
|
69
|
+
}
|
|
70
|
+
/** Parameters for filtering the admin user list. */
|
|
71
|
+
export interface AdminUserListParams {
|
|
72
|
+
/** Page number (1-based). */
|
|
73
|
+
page?: number;
|
|
74
|
+
/** Number of results per page (max 100). */
|
|
75
|
+
limit?: number;
|
|
76
|
+
/** Search query (matches email or name). */
|
|
77
|
+
search?: string;
|
|
78
|
+
/** Filter by subscription tier. */
|
|
79
|
+
tier?: 'free' | 'pro' | 'business';
|
|
80
|
+
/** Filter by user role. */
|
|
81
|
+
role?: 'user' | 'admin';
|
|
82
|
+
}
|
|
83
|
+
/** Parameters for updating a user via admin endpoint. */
|
|
84
|
+
export interface AdminUpdateUserParams {
|
|
85
|
+
/** New role for the user. */
|
|
86
|
+
role?: 'user' | 'admin';
|
|
87
|
+
/** Whether the user account should be active. */
|
|
88
|
+
isActive?: boolean;
|
|
89
|
+
/** New subscription tier. */
|
|
90
|
+
subscriptionTier?: 'free' | 'pro' | 'business';
|
|
91
|
+
}
|
|
92
|
+
/** A recent activity entry. */
|
|
93
|
+
export interface ActivityEntry {
|
|
94
|
+
/** Event type (e.g., `create`, `update`, `delete`). */
|
|
95
|
+
type: string;
|
|
96
|
+
/** ID of the user who performed the action. */
|
|
97
|
+
userId: string;
|
|
98
|
+
/** ID of the vault where the event occurred. */
|
|
99
|
+
vaultId: string;
|
|
100
|
+
/** Document path involved, or `null`. */
|
|
101
|
+
path: string | null;
|
|
102
|
+
/** ISO 8601 timestamp. */
|
|
103
|
+
createdAt: string;
|
|
104
|
+
}
|
|
105
|
+
/** Subscription summary with per-tier counts. */
|
|
106
|
+
export interface SubscriptionSummary {
|
|
107
|
+
/** Number of users on the free tier. */
|
|
108
|
+
free: number;
|
|
109
|
+
/** Number of users on the pro tier. */
|
|
110
|
+
pro: number;
|
|
111
|
+
/** Number of users on the business tier. */
|
|
112
|
+
business: number;
|
|
113
|
+
/** Total number of users with subscriptions. */
|
|
114
|
+
total: number;
|
|
115
|
+
}
|
|
116
|
+
/** System health check result. */
|
|
117
|
+
export interface SystemHealth {
|
|
118
|
+
/** Overall system status. */
|
|
119
|
+
status: string;
|
|
120
|
+
/** Database connection status. */
|
|
121
|
+
database: string;
|
|
122
|
+
/** Redis connection status. */
|
|
123
|
+
redis: string;
|
|
124
|
+
/** Server uptime in seconds. */
|
|
125
|
+
uptime: number;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Resource for admin operations including system stats, user management,
|
|
129
|
+
* activity monitoring, subscription summaries, and system health.
|
|
130
|
+
*
|
|
131
|
+
* All methods require admin-level authentication.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```typescript
|
|
135
|
+
* const stats = await client.admin.getStats();
|
|
136
|
+
* console.log(`Total users: ${stats.totalUsers}`);
|
|
137
|
+
*
|
|
138
|
+
* const users = await client.admin.listUsers({ tier: 'pro' });
|
|
139
|
+
* users.users.forEach(u => console.log(u.email));
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare class AdminResource {
|
|
143
|
+
private http;
|
|
144
|
+
constructor(http: KyInstance);
|
|
145
|
+
/**
|
|
146
|
+
* Retrieves system-wide statistics.
|
|
147
|
+
*
|
|
148
|
+
* @returns System statistics object
|
|
149
|
+
* @throws {AuthenticationError} If not authenticated
|
|
150
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
151
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```typescript
|
|
155
|
+
* const stats = await client.admin.getStats();
|
|
156
|
+
* console.log(`Users: ${stats.totalUsers}, Vaults: ${stats.totalVaults}`);
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
getStats(): Promise<SystemStats>;
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves timeseries data for a given metric and period.
|
|
162
|
+
*
|
|
163
|
+
* @param metric - The metric to query (`signups`, `documents`, or `storage`)
|
|
164
|
+
* @param period - The time period (`7d`, `30d`, or `90d`)
|
|
165
|
+
* @returns Timeseries response with data points
|
|
166
|
+
* @throws {AuthenticationError} If not authenticated
|
|
167
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
168
|
+
* @throws {ValidationError} If the metric or period is invalid
|
|
169
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const ts = await client.admin.getTimeseries('signups', '30d');
|
|
174
|
+
* ts.data.forEach(d => console.log(`${d.date}: ${d.value}`));
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
getTimeseries(metric: string, period: string): Promise<TimeseriesResponse>;
|
|
178
|
+
/**
|
|
179
|
+
* Lists users with optional filtering and pagination.
|
|
180
|
+
*
|
|
181
|
+
* @param params - Optional filter and pagination parameters
|
|
182
|
+
* @returns Paginated list of users
|
|
183
|
+
* @throws {AuthenticationError} If not authenticated
|
|
184
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
185
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const result = await client.admin.listUsers({ search: 'alice', tier: 'pro' });
|
|
190
|
+
* console.log(`Found ${result.total} users`);
|
|
191
|
+
* result.users.forEach(u => console.log(u.email));
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
listUsers(params?: AdminUserListParams): Promise<AdminUserListResponse>;
|
|
195
|
+
/**
|
|
196
|
+
* Retrieves detailed information about a specific user.
|
|
197
|
+
*
|
|
198
|
+
* @param userId - The unique identifier of the user
|
|
199
|
+
* @returns Detailed user information
|
|
200
|
+
* @throws {NotFoundError} If no user exists with the given ID
|
|
201
|
+
* @throws {AuthenticationError} If not authenticated
|
|
202
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
203
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* const user = await client.admin.getUser('user-uuid');
|
|
208
|
+
* console.log(`${user.email}: ${user.vaultCount} vaults, ${user.documentCount} docs`);
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
getUser(userId: string): Promise<AdminUserDetail>;
|
|
212
|
+
/**
|
|
213
|
+
* Updates a user's role, active status, or subscription tier.
|
|
214
|
+
*
|
|
215
|
+
* @param userId - The unique identifier of the user to update
|
|
216
|
+
* @param params - Fields to update
|
|
217
|
+
* @returns The updated user record
|
|
218
|
+
* @throws {NotFoundError} If no user exists with the given ID
|
|
219
|
+
* @throws {ValidationError} If the update parameters are invalid
|
|
220
|
+
* @throws {AuthenticationError} If not authenticated
|
|
221
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
222
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* const updated = await client.admin.updateUser('user-uuid', {
|
|
227
|
+
* role: 'admin',
|
|
228
|
+
* isActive: true,
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
updateUser(userId: string, params: AdminUpdateUserParams): Promise<AdminUser>;
|
|
233
|
+
/**
|
|
234
|
+
* Retrieves recent activity across all vaults.
|
|
235
|
+
*
|
|
236
|
+
* @param limit - Maximum number of entries to return (default: 20, max: 100)
|
|
237
|
+
* @returns Array of recent activity entries
|
|
238
|
+
* @throws {AuthenticationError} If not authenticated
|
|
239
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
240
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const activity = await client.admin.getActivity(10);
|
|
245
|
+
* activity.forEach(a => console.log(`${a.type} by ${a.userId} at ${a.createdAt}`));
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
getActivity(limit?: number): Promise<ActivityEntry[]>;
|
|
249
|
+
/**
|
|
250
|
+
* Retrieves subscription summary with per-tier user counts.
|
|
251
|
+
*
|
|
252
|
+
* @returns Subscription summary object
|
|
253
|
+
* @throws {AuthenticationError} If not authenticated
|
|
254
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
255
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const summary = await client.admin.getSubscriptionSummary();
|
|
260
|
+
* console.log(`Free: ${summary.free}, Pro: ${summary.pro}, Business: ${summary.business}`);
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
getSubscriptionSummary(): Promise<SubscriptionSummary>;
|
|
264
|
+
/**
|
|
265
|
+
* Checks the system health status including database and Redis connectivity.
|
|
266
|
+
*
|
|
267
|
+
* @returns System health check result
|
|
268
|
+
* @throws {AuthenticationError} If not authenticated
|
|
269
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
270
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```typescript
|
|
274
|
+
* const health = await client.admin.getHealth();
|
|
275
|
+
* console.log(`Status: ${health.status}, DB: ${health.database}, Redis: ${health.redis}`);
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
getHealth(): Promise<SystemHealth>;
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=admin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.d.ts","sourceRoot":"","sources":["../../src/resources/admin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAGrC,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,UAAU,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;IACpB,mDAAmD;IACnD,cAAc,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,oDAAoD;AACpD,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,6CAA6C;AAC7C,MAAM,WAAW,kBAAkB;IACjC,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,4BAA4B;IAC5B,IAAI,EAAE,mBAAmB,EAAE,CAAC;CAC7B;AAED,uDAAuD;AAC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MAAM,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAiB7E;;;;;;;;;;;;;;;OAeG;IACG,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAQvD;;;;;;;;;;;;;;;;;;;OAmBG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,SAAS,CAAC;IAUnF;;;;;;;;;;;;;;OAcG;IACG,WAAW,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAc3D;;;;;;;;;;;;;OAaG;IACG,sBAAsB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAQ5D;;;;;;;;;;;;;OAaG;IACG,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;CAOzC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { handleError } from '../handle-error.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resource for admin operations including system stats, user management,
|
|
4
|
+
* activity monitoring, subscription summaries, and system health.
|
|
5
|
+
*
|
|
6
|
+
* All methods require admin-level authentication.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const stats = await client.admin.getStats();
|
|
11
|
+
* console.log(`Total users: ${stats.totalUsers}`);
|
|
12
|
+
*
|
|
13
|
+
* const users = await client.admin.listUsers({ tier: 'pro' });
|
|
14
|
+
* users.users.forEach(u => console.log(u.email));
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export class AdminResource {
|
|
18
|
+
http;
|
|
19
|
+
constructor(http) {
|
|
20
|
+
this.http = http;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Retrieves system-wide statistics.
|
|
24
|
+
*
|
|
25
|
+
* @returns System statistics object
|
|
26
|
+
* @throws {AuthenticationError} If not authenticated
|
|
27
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
28
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const stats = await client.admin.getStats();
|
|
33
|
+
* console.log(`Users: ${stats.totalUsers}, Vaults: ${stats.totalVaults}`);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
async getStats() {
|
|
37
|
+
try {
|
|
38
|
+
return await this.http.get('admin/stats').json();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw await handleError(error, 'Admin stats', '');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves timeseries data for a given metric and period.
|
|
46
|
+
*
|
|
47
|
+
* @param metric - The metric to query (`signups`, `documents`, or `storage`)
|
|
48
|
+
* @param period - The time period (`7d`, `30d`, or `90d`)
|
|
49
|
+
* @returns Timeseries response with data points
|
|
50
|
+
* @throws {AuthenticationError} If not authenticated
|
|
51
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
52
|
+
* @throws {ValidationError} If the metric or period is invalid
|
|
53
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const ts = await client.admin.getTimeseries('signups', '30d');
|
|
58
|
+
* ts.data.forEach(d => console.log(`${d.date}: ${d.value}`));
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
async getTimeseries(metric, period) {
|
|
62
|
+
try {
|
|
63
|
+
return await this.http.get('admin/stats/timeseries', {
|
|
64
|
+
searchParams: { metric, period },
|
|
65
|
+
}).json();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw await handleError(error, 'Timeseries', metric);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Lists users with optional filtering and pagination.
|
|
73
|
+
*
|
|
74
|
+
* @param params - Optional filter and pagination parameters
|
|
75
|
+
* @returns Paginated list of users
|
|
76
|
+
* @throws {AuthenticationError} If not authenticated
|
|
77
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
78
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const result = await client.admin.listUsers({ search: 'alice', tier: 'pro' });
|
|
83
|
+
* console.log(`Found ${result.total} users`);
|
|
84
|
+
* result.users.forEach(u => console.log(u.email));
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
async listUsers(params) {
|
|
88
|
+
try {
|
|
89
|
+
const searchParams = {};
|
|
90
|
+
if (params?.page !== undefined)
|
|
91
|
+
searchParams.page = params.page;
|
|
92
|
+
if (params?.limit !== undefined)
|
|
93
|
+
searchParams.limit = params.limit;
|
|
94
|
+
if (params?.search)
|
|
95
|
+
searchParams.search = params.search;
|
|
96
|
+
if (params?.tier)
|
|
97
|
+
searchParams.tier = params.tier;
|
|
98
|
+
if (params?.role)
|
|
99
|
+
searchParams.role = params.role;
|
|
100
|
+
return await this.http.get('admin/users', {
|
|
101
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : undefined,
|
|
102
|
+
}).json();
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
throw await handleError(error, 'Users', '');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves detailed information about a specific user.
|
|
110
|
+
*
|
|
111
|
+
* @param userId - The unique identifier of the user
|
|
112
|
+
* @returns Detailed user information
|
|
113
|
+
* @throws {NotFoundError} If no user exists with the given ID
|
|
114
|
+
* @throws {AuthenticationError} If not authenticated
|
|
115
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
116
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const user = await client.admin.getUser('user-uuid');
|
|
121
|
+
* console.log(`${user.email}: ${user.vaultCount} vaults, ${user.documentCount} docs`);
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
async getUser(userId) {
|
|
125
|
+
try {
|
|
126
|
+
return await this.http.get(`admin/users/${userId}`).json();
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
throw await handleError(error, 'User', userId);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Updates a user's role, active status, or subscription tier.
|
|
134
|
+
*
|
|
135
|
+
* @param userId - The unique identifier of the user to update
|
|
136
|
+
* @param params - Fields to update
|
|
137
|
+
* @returns The updated user record
|
|
138
|
+
* @throws {NotFoundError} If no user exists with the given ID
|
|
139
|
+
* @throws {ValidationError} If the update parameters are invalid
|
|
140
|
+
* @throws {AuthenticationError} If not authenticated
|
|
141
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
142
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const updated = await client.admin.updateUser('user-uuid', {
|
|
147
|
+
* role: 'admin',
|
|
148
|
+
* isActive: true,
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
async updateUser(userId, params) {
|
|
153
|
+
try {
|
|
154
|
+
return await this.http.patch(`admin/users/${userId}`, {
|
|
155
|
+
json: params,
|
|
156
|
+
}).json();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
throw await handleError(error, 'User', userId);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Retrieves recent activity across all vaults.
|
|
164
|
+
*
|
|
165
|
+
* @param limit - Maximum number of entries to return (default: 20, max: 100)
|
|
166
|
+
* @returns Array of recent activity entries
|
|
167
|
+
* @throws {AuthenticationError} If not authenticated
|
|
168
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
169
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const activity = await client.admin.getActivity(10);
|
|
174
|
+
* activity.forEach(a => console.log(`${a.type} by ${a.userId} at ${a.createdAt}`));
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async getActivity(limit) {
|
|
178
|
+
try {
|
|
179
|
+
const searchParams = {};
|
|
180
|
+
if (limit !== undefined)
|
|
181
|
+
searchParams.limit = limit;
|
|
182
|
+
const data = await this.http.get('admin/activity', {
|
|
183
|
+
searchParams: Object.keys(searchParams).length > 0 ? searchParams : undefined,
|
|
184
|
+
}).json();
|
|
185
|
+
return data;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
throw await handleError(error, 'Activity', '');
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Retrieves subscription summary with per-tier user counts.
|
|
193
|
+
*
|
|
194
|
+
* @returns Subscription summary object
|
|
195
|
+
* @throws {AuthenticationError} If not authenticated
|
|
196
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
197
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const summary = await client.admin.getSubscriptionSummary();
|
|
202
|
+
* console.log(`Free: ${summary.free}, Pro: ${summary.pro}, Business: ${summary.business}`);
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
async getSubscriptionSummary() {
|
|
206
|
+
try {
|
|
207
|
+
return await this.http.get('admin/subscriptions').json();
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
throw await handleError(error, 'Subscriptions', '');
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Checks the system health status including database and Redis connectivity.
|
|
215
|
+
*
|
|
216
|
+
* @returns System health check result
|
|
217
|
+
* @throws {AuthenticationError} If not authenticated
|
|
218
|
+
* @throws {AuthorizationError} If the user is not an admin
|
|
219
|
+
* @throws {NetworkError} If the request fails due to network issues
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const health = await client.admin.getHealth();
|
|
224
|
+
* console.log(`Status: ${health.status}, DB: ${health.database}, Redis: ${health.redis}`);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
async getHealth() {
|
|
228
|
+
try {
|
|
229
|
+
return await this.http.get('admin/health').json();
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
throw await handleError(error, 'Health', '');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=admin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"admin.js","sourceRoot":"","sources":["../../src/resources/admin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AA0IjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,aAAa;IACJ;IAApB,YAAoB,IAAgB;QAAhB,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAExC;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,QAAQ;QACZ,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,IAAI,EAAe,CAAC;QAChE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,CAAC,aAAa,CAAC,MAAc,EAAE,MAAc;QAChD,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,wBAAwB,EAAE;gBACnD,YAAY,EAAE,EAAE,MAAM,EAAE,MAAM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