@urbackend/sdk 0.2.1 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +560 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +343 -0
- package/dist/index.d.ts +343 -0
- package/dist/index.mjs +521 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +5 -1
- package/.prettierrc +0 -7
- package/eslint.config.js +0 -15
- package/src/client.ts +0 -143
- package/src/errors.ts +0 -90
- package/src/index.ts +0 -18
- package/src/modules/auth.ts +0 -209
- package/src/modules/database.ts +0 -124
- package/src/modules/mail.ts +0 -16
- package/src/modules/schema.ts +0 -24
- package/src/modules/storage.ts +0 -41
- package/src/types/index.ts +0 -154
- package/tests/auth.test.ts +0 -169
- package/tests/database.test.ts +0 -134
- package/tests/mail.test.ts +0 -41
- package/tests/schema.test.ts +0 -32
- package/tests/storage.test.ts +0 -62
- package/tests/tsconfig.json +0 -9
- package/tsconfig.json +0 -18
- package/tsup.config.ts +0 -16
- package/vitest.config.ts +0 -12
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
interface UrBackendConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
interface RequestOptions {
|
|
7
|
+
body?: unknown;
|
|
8
|
+
token?: string;
|
|
9
|
+
isMultipart?: boolean;
|
|
10
|
+
credentials?: RequestCredentials;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface QueryParams {
|
|
14
|
+
page?: number;
|
|
15
|
+
limit?: number;
|
|
16
|
+
sort?: string;
|
|
17
|
+
populate?: string | string[];
|
|
18
|
+
expand?: string | string[];
|
|
19
|
+
filter?: Record<string, unknown>;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface SignUpPayload {
|
|
23
|
+
email: string;
|
|
24
|
+
password: string;
|
|
25
|
+
username?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface LoginPayload {
|
|
30
|
+
email: string;
|
|
31
|
+
password: string;
|
|
32
|
+
}
|
|
33
|
+
interface UpdateProfilePayload {
|
|
34
|
+
username?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
interface ChangePasswordPayload {
|
|
39
|
+
currentPassword: string;
|
|
40
|
+
newPassword: string;
|
|
41
|
+
}
|
|
42
|
+
interface VerifyEmailPayload {
|
|
43
|
+
email: string;
|
|
44
|
+
otp: string;
|
|
45
|
+
}
|
|
46
|
+
interface ResendOtpPayload {
|
|
47
|
+
email: string;
|
|
48
|
+
}
|
|
49
|
+
interface RequestPasswordResetPayload {
|
|
50
|
+
email: string;
|
|
51
|
+
}
|
|
52
|
+
interface ResetPasswordPayload {
|
|
53
|
+
email: string;
|
|
54
|
+
otp: string;
|
|
55
|
+
newPassword: string;
|
|
56
|
+
}
|
|
57
|
+
interface SocialExchangePayload {
|
|
58
|
+
token: string;
|
|
59
|
+
rtCode: string;
|
|
60
|
+
}
|
|
61
|
+
interface SocialExchangeResponse {
|
|
62
|
+
refreshToken: string;
|
|
63
|
+
}
|
|
64
|
+
interface AuthUser {
|
|
65
|
+
_id: string;
|
|
66
|
+
email: string;
|
|
67
|
+
username?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
interface AuthResponse {
|
|
72
|
+
accessToken?: string;
|
|
73
|
+
/** @deprecated use accessToken instead */
|
|
74
|
+
token?: string;
|
|
75
|
+
expiresIn?: string;
|
|
76
|
+
userId?: string;
|
|
77
|
+
user?: AuthUser;
|
|
78
|
+
}
|
|
79
|
+
interface DocumentData {
|
|
80
|
+
_id: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
interface InsertPayload {
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
interface UpdatePayload {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
interface PatchPayload {
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface SchemaField {
|
|
93
|
+
key: string;
|
|
94
|
+
type: string;
|
|
95
|
+
required: boolean;
|
|
96
|
+
unique?: boolean;
|
|
97
|
+
ref?: string;
|
|
98
|
+
items?: {
|
|
99
|
+
type: string;
|
|
100
|
+
fields?: SchemaField[];
|
|
101
|
+
};
|
|
102
|
+
fields?: SchemaField[];
|
|
103
|
+
}
|
|
104
|
+
interface CollectionSchema {
|
|
105
|
+
name: string;
|
|
106
|
+
model: SchemaField[];
|
|
107
|
+
}
|
|
108
|
+
interface SendMailPayload {
|
|
109
|
+
to: string | string[];
|
|
110
|
+
subject: string;
|
|
111
|
+
text?: string;
|
|
112
|
+
html?: string;
|
|
113
|
+
}
|
|
114
|
+
interface SendMailResponse {
|
|
115
|
+
id: string | null;
|
|
116
|
+
provider: 'byok' | 'default';
|
|
117
|
+
monthlyUsage: number;
|
|
118
|
+
monthlyLimit: number;
|
|
119
|
+
}
|
|
120
|
+
interface UploadResponse {
|
|
121
|
+
url: string;
|
|
122
|
+
path: string;
|
|
123
|
+
provider: 'internal' | 'external';
|
|
124
|
+
message?: string;
|
|
125
|
+
}
|
|
126
|
+
interface ApiResponse<T> {
|
|
127
|
+
data: T;
|
|
128
|
+
success: boolean;
|
|
129
|
+
message?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare class AuthModule {
|
|
133
|
+
private client;
|
|
134
|
+
private sessionToken?;
|
|
135
|
+
constructor(client: UrBackendClient);
|
|
136
|
+
/**
|
|
137
|
+
* Create a new user account
|
|
138
|
+
*/
|
|
139
|
+
signUp(payload: SignUpPayload): Promise<AuthUser>;
|
|
140
|
+
/**
|
|
141
|
+
* Log in an existing user and store the session token
|
|
142
|
+
*/
|
|
143
|
+
login(payload: LoginPayload): Promise<AuthResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Get the current authenticated user's profile
|
|
146
|
+
*/
|
|
147
|
+
me(token?: string): Promise<AuthUser>;
|
|
148
|
+
/**
|
|
149
|
+
* Update the current authenticated user's profile
|
|
150
|
+
*/
|
|
151
|
+
updateProfile(payload: UpdateProfilePayload, token?: string): Promise<{
|
|
152
|
+
message: string;
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Change the current authenticated user's password
|
|
156
|
+
*/
|
|
157
|
+
changePassword(payload: ChangePasswordPayload, token?: string): Promise<{
|
|
158
|
+
message: string;
|
|
159
|
+
}>;
|
|
160
|
+
/**
|
|
161
|
+
* Verify user email with OTP
|
|
162
|
+
*/
|
|
163
|
+
verifyEmail(payload: VerifyEmailPayload): Promise<{
|
|
164
|
+
message: string;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Resend verification OTP
|
|
168
|
+
*/
|
|
169
|
+
resendVerificationOtp(payload: ResendOtpPayload): Promise<{
|
|
170
|
+
message: string;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Request password reset OTP
|
|
174
|
+
*/
|
|
175
|
+
requestPasswordReset(payload: RequestPasswordResetPayload): Promise<{
|
|
176
|
+
message: string;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Reset user password with OTP
|
|
180
|
+
*/
|
|
181
|
+
resetPassword(payload: ResetPasswordPayload): Promise<{
|
|
182
|
+
message: string;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Get public-safe profile by username
|
|
186
|
+
*/
|
|
187
|
+
publicProfile(username: string): Promise<AuthUser>;
|
|
188
|
+
/**
|
|
189
|
+
* Refresh the access token
|
|
190
|
+
* @param refreshToken Optional refresh token for header mode. If omitted, uses cookie mode.
|
|
191
|
+
*/
|
|
192
|
+
refreshToken(refreshToken?: string): Promise<AuthResponse>;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the start URL for social authentication.
|
|
195
|
+
* Redirect the user's browser to this URL to begin the flow.
|
|
196
|
+
*/
|
|
197
|
+
socialStart(provider: 'github' | 'google'): string;
|
|
198
|
+
/**
|
|
199
|
+
* Exchange social auth rtCode for a refresh token
|
|
200
|
+
*/
|
|
201
|
+
socialExchange(payload: SocialExchangePayload): Promise<SocialExchangeResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Revoke the current session and clear local state
|
|
204
|
+
*/
|
|
205
|
+
logout(token?: string): Promise<{
|
|
206
|
+
success: boolean;
|
|
207
|
+
message: string;
|
|
208
|
+
}>;
|
|
209
|
+
/**
|
|
210
|
+
* Manually set the session token (e.g. after social auth exchange)
|
|
211
|
+
*/
|
|
212
|
+
setToken(token: string): void;
|
|
213
|
+
/**
|
|
214
|
+
* Get the current stored session token
|
|
215
|
+
*/
|
|
216
|
+
getToken(): string | undefined;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class DatabaseModule {
|
|
220
|
+
private client;
|
|
221
|
+
constructor(client: UrBackendClient);
|
|
222
|
+
/**
|
|
223
|
+
* Fetch all documents from a collection with optional query parameters
|
|
224
|
+
*/
|
|
225
|
+
getAll<T extends DocumentData>(collection: string, params?: QueryParams): Promise<T[]>;
|
|
226
|
+
/**
|
|
227
|
+
* Fetch a single document by its ID
|
|
228
|
+
*/
|
|
229
|
+
getOne<T extends DocumentData>(collection: string, id: string, options?: {
|
|
230
|
+
populate?: string | string[];
|
|
231
|
+
expand?: string | string[];
|
|
232
|
+
}): Promise<T>;
|
|
233
|
+
/**
|
|
234
|
+
* Insert a new document into a collection
|
|
235
|
+
*/
|
|
236
|
+
insert<T extends DocumentData>(collection: string, data: InsertPayload, token?: string): Promise<T>;
|
|
237
|
+
/**
|
|
238
|
+
* Update an existing document by its ID (Full replacement)
|
|
239
|
+
*/
|
|
240
|
+
update<T extends DocumentData>(collection: string, id: string, data: UpdatePayload, token?: string): Promise<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Partially update an existing document by its ID
|
|
243
|
+
*/
|
|
244
|
+
patch<T extends DocumentData>(collection: string, id: string, data: PatchPayload, token?: string): Promise<T>;
|
|
245
|
+
/**
|
|
246
|
+
* Delete a document by its ID
|
|
247
|
+
*/
|
|
248
|
+
delete(collection: string, id: string, token?: string): Promise<{
|
|
249
|
+
deleted: boolean;
|
|
250
|
+
}>;
|
|
251
|
+
/**
|
|
252
|
+
* Internal helper to build query string from QueryParams
|
|
253
|
+
*/
|
|
254
|
+
private buildQueryString;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare class StorageModule {
|
|
258
|
+
private client;
|
|
259
|
+
constructor(client: UrBackendClient);
|
|
260
|
+
/**
|
|
261
|
+
* Upload a file to storage
|
|
262
|
+
*/
|
|
263
|
+
upload(file: unknown, filename?: string): Promise<UploadResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* Delete a file from storage by its path
|
|
266
|
+
*/
|
|
267
|
+
deleteFile(path: string): Promise<{
|
|
268
|
+
deleted: boolean;
|
|
269
|
+
}>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare class SchemaModule {
|
|
273
|
+
private client;
|
|
274
|
+
constructor(client: UrBackendClient);
|
|
275
|
+
/**
|
|
276
|
+
* Fetch the schema definition for a collection
|
|
277
|
+
*/
|
|
278
|
+
getSchema(collection: string): Promise<CollectionSchema>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare class MailModule {
|
|
282
|
+
private client;
|
|
283
|
+
constructor(client: UrBackendClient);
|
|
284
|
+
/**
|
|
285
|
+
* Send an email using the urBackend mail service.
|
|
286
|
+
* Note: This requires a Secret Key (sk_live_...) and should be called from a server environment.
|
|
287
|
+
*/
|
|
288
|
+
send(payload: SendMailPayload): Promise<SendMailResponse>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare class UrBackendClient {
|
|
292
|
+
private apiKey;
|
|
293
|
+
private baseUrl;
|
|
294
|
+
private _auth?;
|
|
295
|
+
private _db?;
|
|
296
|
+
private _storage?;
|
|
297
|
+
private _schema?;
|
|
298
|
+
private _mail?;
|
|
299
|
+
private headers;
|
|
300
|
+
constructor(config: UrBackendConfig);
|
|
301
|
+
get auth(): AuthModule;
|
|
302
|
+
get db(): DatabaseModule;
|
|
303
|
+
get storage(): StorageModule;
|
|
304
|
+
get schema(): SchemaModule;
|
|
305
|
+
get mail(): MailModule;
|
|
306
|
+
getBaseUrl(): string;
|
|
307
|
+
getApiKey(): string;
|
|
308
|
+
/**
|
|
309
|
+
* Internal request handler
|
|
310
|
+
*/
|
|
311
|
+
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
declare class UrBackendError extends Error {
|
|
315
|
+
message: string;
|
|
316
|
+
statusCode: number;
|
|
317
|
+
endpoint: string;
|
|
318
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
319
|
+
}
|
|
320
|
+
declare class AuthError extends UrBackendError {
|
|
321
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
322
|
+
}
|
|
323
|
+
declare class NotFoundError extends UrBackendError {
|
|
324
|
+
constructor(message: string, endpoint: string);
|
|
325
|
+
}
|
|
326
|
+
declare class RateLimitError extends UrBackendError {
|
|
327
|
+
retryAfter?: number;
|
|
328
|
+
constructor(message: string, endpoint: string, retryAfter?: number);
|
|
329
|
+
}
|
|
330
|
+
declare class StorageError extends UrBackendError {
|
|
331
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
332
|
+
}
|
|
333
|
+
declare class ValidationError extends UrBackendError {
|
|
334
|
+
constructor(message: string, endpoint: string);
|
|
335
|
+
}
|
|
336
|
+
declare function parseApiError(response: Response): Promise<UrBackendError>;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Factory function to create a new urBackend client
|
|
340
|
+
*/
|
|
341
|
+
declare function urBackend(config: UrBackendConfig): UrBackendClient;
|
|
342
|
+
|
|
343
|
+
export { type ApiResponse, AuthError, AuthModule, type AuthResponse, type AuthUser, type ChangePasswordPayload, type CollectionSchema, DatabaseModule, type DocumentData, type InsertPayload, type LoginPayload, MailModule, NotFoundError, type PatchPayload, type QueryParams, RateLimitError, type RequestOptions, type RequestPasswordResetPayload, type ResendOtpPayload, type ResetPasswordPayload, type SchemaField, SchemaModule, type SendMailPayload, type SendMailResponse, type SignUpPayload, type SocialExchangePayload, type SocialExchangeResponse, StorageError, StorageModule, type UpdatePayload, type UpdateProfilePayload, type UploadResponse, UrBackendClient, type UrBackendConfig, UrBackendError, ValidationError, type VerifyEmailPayload, urBackend as default, parseApiError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
interface UrBackendConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
interface RequestOptions {
|
|
7
|
+
body?: unknown;
|
|
8
|
+
token?: string;
|
|
9
|
+
isMultipart?: boolean;
|
|
10
|
+
credentials?: RequestCredentials;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
}
|
|
13
|
+
interface QueryParams {
|
|
14
|
+
page?: number;
|
|
15
|
+
limit?: number;
|
|
16
|
+
sort?: string;
|
|
17
|
+
populate?: string | string[];
|
|
18
|
+
expand?: string | string[];
|
|
19
|
+
filter?: Record<string, unknown>;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
interface SignUpPayload {
|
|
23
|
+
email: string;
|
|
24
|
+
password: string;
|
|
25
|
+
username?: string;
|
|
26
|
+
name?: string;
|
|
27
|
+
[key: string]: unknown;
|
|
28
|
+
}
|
|
29
|
+
interface LoginPayload {
|
|
30
|
+
email: string;
|
|
31
|
+
password: string;
|
|
32
|
+
}
|
|
33
|
+
interface UpdateProfilePayload {
|
|
34
|
+
username?: string;
|
|
35
|
+
name?: string;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
}
|
|
38
|
+
interface ChangePasswordPayload {
|
|
39
|
+
currentPassword: string;
|
|
40
|
+
newPassword: string;
|
|
41
|
+
}
|
|
42
|
+
interface VerifyEmailPayload {
|
|
43
|
+
email: string;
|
|
44
|
+
otp: string;
|
|
45
|
+
}
|
|
46
|
+
interface ResendOtpPayload {
|
|
47
|
+
email: string;
|
|
48
|
+
}
|
|
49
|
+
interface RequestPasswordResetPayload {
|
|
50
|
+
email: string;
|
|
51
|
+
}
|
|
52
|
+
interface ResetPasswordPayload {
|
|
53
|
+
email: string;
|
|
54
|
+
otp: string;
|
|
55
|
+
newPassword: string;
|
|
56
|
+
}
|
|
57
|
+
interface SocialExchangePayload {
|
|
58
|
+
token: string;
|
|
59
|
+
rtCode: string;
|
|
60
|
+
}
|
|
61
|
+
interface SocialExchangeResponse {
|
|
62
|
+
refreshToken: string;
|
|
63
|
+
}
|
|
64
|
+
interface AuthUser {
|
|
65
|
+
_id: string;
|
|
66
|
+
email: string;
|
|
67
|
+
username?: string;
|
|
68
|
+
name?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
interface AuthResponse {
|
|
72
|
+
accessToken?: string;
|
|
73
|
+
/** @deprecated use accessToken instead */
|
|
74
|
+
token?: string;
|
|
75
|
+
expiresIn?: string;
|
|
76
|
+
userId?: string;
|
|
77
|
+
user?: AuthUser;
|
|
78
|
+
}
|
|
79
|
+
interface DocumentData {
|
|
80
|
+
_id: string;
|
|
81
|
+
[key: string]: unknown;
|
|
82
|
+
}
|
|
83
|
+
interface InsertPayload {
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
interface UpdatePayload {
|
|
87
|
+
[key: string]: unknown;
|
|
88
|
+
}
|
|
89
|
+
interface PatchPayload {
|
|
90
|
+
[key: string]: unknown;
|
|
91
|
+
}
|
|
92
|
+
interface SchemaField {
|
|
93
|
+
key: string;
|
|
94
|
+
type: string;
|
|
95
|
+
required: boolean;
|
|
96
|
+
unique?: boolean;
|
|
97
|
+
ref?: string;
|
|
98
|
+
items?: {
|
|
99
|
+
type: string;
|
|
100
|
+
fields?: SchemaField[];
|
|
101
|
+
};
|
|
102
|
+
fields?: SchemaField[];
|
|
103
|
+
}
|
|
104
|
+
interface CollectionSchema {
|
|
105
|
+
name: string;
|
|
106
|
+
model: SchemaField[];
|
|
107
|
+
}
|
|
108
|
+
interface SendMailPayload {
|
|
109
|
+
to: string | string[];
|
|
110
|
+
subject: string;
|
|
111
|
+
text?: string;
|
|
112
|
+
html?: string;
|
|
113
|
+
}
|
|
114
|
+
interface SendMailResponse {
|
|
115
|
+
id: string | null;
|
|
116
|
+
provider: 'byok' | 'default';
|
|
117
|
+
monthlyUsage: number;
|
|
118
|
+
monthlyLimit: number;
|
|
119
|
+
}
|
|
120
|
+
interface UploadResponse {
|
|
121
|
+
url: string;
|
|
122
|
+
path: string;
|
|
123
|
+
provider: 'internal' | 'external';
|
|
124
|
+
message?: string;
|
|
125
|
+
}
|
|
126
|
+
interface ApiResponse<T> {
|
|
127
|
+
data: T;
|
|
128
|
+
success: boolean;
|
|
129
|
+
message?: string;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
declare class AuthModule {
|
|
133
|
+
private client;
|
|
134
|
+
private sessionToken?;
|
|
135
|
+
constructor(client: UrBackendClient);
|
|
136
|
+
/**
|
|
137
|
+
* Create a new user account
|
|
138
|
+
*/
|
|
139
|
+
signUp(payload: SignUpPayload): Promise<AuthUser>;
|
|
140
|
+
/**
|
|
141
|
+
* Log in an existing user and store the session token
|
|
142
|
+
*/
|
|
143
|
+
login(payload: LoginPayload): Promise<AuthResponse>;
|
|
144
|
+
/**
|
|
145
|
+
* Get the current authenticated user's profile
|
|
146
|
+
*/
|
|
147
|
+
me(token?: string): Promise<AuthUser>;
|
|
148
|
+
/**
|
|
149
|
+
* Update the current authenticated user's profile
|
|
150
|
+
*/
|
|
151
|
+
updateProfile(payload: UpdateProfilePayload, token?: string): Promise<{
|
|
152
|
+
message: string;
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Change the current authenticated user's password
|
|
156
|
+
*/
|
|
157
|
+
changePassword(payload: ChangePasswordPayload, token?: string): Promise<{
|
|
158
|
+
message: string;
|
|
159
|
+
}>;
|
|
160
|
+
/**
|
|
161
|
+
* Verify user email with OTP
|
|
162
|
+
*/
|
|
163
|
+
verifyEmail(payload: VerifyEmailPayload): Promise<{
|
|
164
|
+
message: string;
|
|
165
|
+
}>;
|
|
166
|
+
/**
|
|
167
|
+
* Resend verification OTP
|
|
168
|
+
*/
|
|
169
|
+
resendVerificationOtp(payload: ResendOtpPayload): Promise<{
|
|
170
|
+
message: string;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Request password reset OTP
|
|
174
|
+
*/
|
|
175
|
+
requestPasswordReset(payload: RequestPasswordResetPayload): Promise<{
|
|
176
|
+
message: string;
|
|
177
|
+
}>;
|
|
178
|
+
/**
|
|
179
|
+
* Reset user password with OTP
|
|
180
|
+
*/
|
|
181
|
+
resetPassword(payload: ResetPasswordPayload): Promise<{
|
|
182
|
+
message: string;
|
|
183
|
+
}>;
|
|
184
|
+
/**
|
|
185
|
+
* Get public-safe profile by username
|
|
186
|
+
*/
|
|
187
|
+
publicProfile(username: string): Promise<AuthUser>;
|
|
188
|
+
/**
|
|
189
|
+
* Refresh the access token
|
|
190
|
+
* @param refreshToken Optional refresh token for header mode. If omitted, uses cookie mode.
|
|
191
|
+
*/
|
|
192
|
+
refreshToken(refreshToken?: string): Promise<AuthResponse>;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the start URL for social authentication.
|
|
195
|
+
* Redirect the user's browser to this URL to begin the flow.
|
|
196
|
+
*/
|
|
197
|
+
socialStart(provider: 'github' | 'google'): string;
|
|
198
|
+
/**
|
|
199
|
+
* Exchange social auth rtCode for a refresh token
|
|
200
|
+
*/
|
|
201
|
+
socialExchange(payload: SocialExchangePayload): Promise<SocialExchangeResponse>;
|
|
202
|
+
/**
|
|
203
|
+
* Revoke the current session and clear local state
|
|
204
|
+
*/
|
|
205
|
+
logout(token?: string): Promise<{
|
|
206
|
+
success: boolean;
|
|
207
|
+
message: string;
|
|
208
|
+
}>;
|
|
209
|
+
/**
|
|
210
|
+
* Manually set the session token (e.g. after social auth exchange)
|
|
211
|
+
*/
|
|
212
|
+
setToken(token: string): void;
|
|
213
|
+
/**
|
|
214
|
+
* Get the current stored session token
|
|
215
|
+
*/
|
|
216
|
+
getToken(): string | undefined;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
declare class DatabaseModule {
|
|
220
|
+
private client;
|
|
221
|
+
constructor(client: UrBackendClient);
|
|
222
|
+
/**
|
|
223
|
+
* Fetch all documents from a collection with optional query parameters
|
|
224
|
+
*/
|
|
225
|
+
getAll<T extends DocumentData>(collection: string, params?: QueryParams): Promise<T[]>;
|
|
226
|
+
/**
|
|
227
|
+
* Fetch a single document by its ID
|
|
228
|
+
*/
|
|
229
|
+
getOne<T extends DocumentData>(collection: string, id: string, options?: {
|
|
230
|
+
populate?: string | string[];
|
|
231
|
+
expand?: string | string[];
|
|
232
|
+
}): Promise<T>;
|
|
233
|
+
/**
|
|
234
|
+
* Insert a new document into a collection
|
|
235
|
+
*/
|
|
236
|
+
insert<T extends DocumentData>(collection: string, data: InsertPayload, token?: string): Promise<T>;
|
|
237
|
+
/**
|
|
238
|
+
* Update an existing document by its ID (Full replacement)
|
|
239
|
+
*/
|
|
240
|
+
update<T extends DocumentData>(collection: string, id: string, data: UpdatePayload, token?: string): Promise<T>;
|
|
241
|
+
/**
|
|
242
|
+
* Partially update an existing document by its ID
|
|
243
|
+
*/
|
|
244
|
+
patch<T extends DocumentData>(collection: string, id: string, data: PatchPayload, token?: string): Promise<T>;
|
|
245
|
+
/**
|
|
246
|
+
* Delete a document by its ID
|
|
247
|
+
*/
|
|
248
|
+
delete(collection: string, id: string, token?: string): Promise<{
|
|
249
|
+
deleted: boolean;
|
|
250
|
+
}>;
|
|
251
|
+
/**
|
|
252
|
+
* Internal helper to build query string from QueryParams
|
|
253
|
+
*/
|
|
254
|
+
private buildQueryString;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
declare class StorageModule {
|
|
258
|
+
private client;
|
|
259
|
+
constructor(client: UrBackendClient);
|
|
260
|
+
/**
|
|
261
|
+
* Upload a file to storage
|
|
262
|
+
*/
|
|
263
|
+
upload(file: unknown, filename?: string): Promise<UploadResponse>;
|
|
264
|
+
/**
|
|
265
|
+
* Delete a file from storage by its path
|
|
266
|
+
*/
|
|
267
|
+
deleteFile(path: string): Promise<{
|
|
268
|
+
deleted: boolean;
|
|
269
|
+
}>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
declare class SchemaModule {
|
|
273
|
+
private client;
|
|
274
|
+
constructor(client: UrBackendClient);
|
|
275
|
+
/**
|
|
276
|
+
* Fetch the schema definition for a collection
|
|
277
|
+
*/
|
|
278
|
+
getSchema(collection: string): Promise<CollectionSchema>;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
declare class MailModule {
|
|
282
|
+
private client;
|
|
283
|
+
constructor(client: UrBackendClient);
|
|
284
|
+
/**
|
|
285
|
+
* Send an email using the urBackend mail service.
|
|
286
|
+
* Note: This requires a Secret Key (sk_live_...) and should be called from a server environment.
|
|
287
|
+
*/
|
|
288
|
+
send(payload: SendMailPayload): Promise<SendMailResponse>;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
declare class UrBackendClient {
|
|
292
|
+
private apiKey;
|
|
293
|
+
private baseUrl;
|
|
294
|
+
private _auth?;
|
|
295
|
+
private _db?;
|
|
296
|
+
private _storage?;
|
|
297
|
+
private _schema?;
|
|
298
|
+
private _mail?;
|
|
299
|
+
private headers;
|
|
300
|
+
constructor(config: UrBackendConfig);
|
|
301
|
+
get auth(): AuthModule;
|
|
302
|
+
get db(): DatabaseModule;
|
|
303
|
+
get storage(): StorageModule;
|
|
304
|
+
get schema(): SchemaModule;
|
|
305
|
+
get mail(): MailModule;
|
|
306
|
+
getBaseUrl(): string;
|
|
307
|
+
getApiKey(): string;
|
|
308
|
+
/**
|
|
309
|
+
* Internal request handler
|
|
310
|
+
*/
|
|
311
|
+
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
declare class UrBackendError extends Error {
|
|
315
|
+
message: string;
|
|
316
|
+
statusCode: number;
|
|
317
|
+
endpoint: string;
|
|
318
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
319
|
+
}
|
|
320
|
+
declare class AuthError extends UrBackendError {
|
|
321
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
322
|
+
}
|
|
323
|
+
declare class NotFoundError extends UrBackendError {
|
|
324
|
+
constructor(message: string, endpoint: string);
|
|
325
|
+
}
|
|
326
|
+
declare class RateLimitError extends UrBackendError {
|
|
327
|
+
retryAfter?: number;
|
|
328
|
+
constructor(message: string, endpoint: string, retryAfter?: number);
|
|
329
|
+
}
|
|
330
|
+
declare class StorageError extends UrBackendError {
|
|
331
|
+
constructor(message: string, statusCode: number, endpoint: string);
|
|
332
|
+
}
|
|
333
|
+
declare class ValidationError extends UrBackendError {
|
|
334
|
+
constructor(message: string, endpoint: string);
|
|
335
|
+
}
|
|
336
|
+
declare function parseApiError(response: Response): Promise<UrBackendError>;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Factory function to create a new urBackend client
|
|
340
|
+
*/
|
|
341
|
+
declare function urBackend(config: UrBackendConfig): UrBackendClient;
|
|
342
|
+
|
|
343
|
+
export { type ApiResponse, AuthError, AuthModule, type AuthResponse, type AuthUser, type ChangePasswordPayload, type CollectionSchema, DatabaseModule, type DocumentData, type InsertPayload, type LoginPayload, MailModule, NotFoundError, type PatchPayload, type QueryParams, RateLimitError, type RequestOptions, type RequestPasswordResetPayload, type ResendOtpPayload, type ResetPasswordPayload, type SchemaField, SchemaModule, type SendMailPayload, type SendMailResponse, type SignUpPayload, type SocialExchangePayload, type SocialExchangeResponse, StorageError, StorageModule, type UpdatePayload, type UpdateProfilePayload, type UploadResponse, UrBackendClient, type UrBackendConfig, UrBackendError, ValidationError, type VerifyEmailPayload, urBackend as default, parseApiError };
|