@tspvivek/baasix-sdk 0.1.0-alpha.1
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 +942 -0
- package/dist/client-CzF9B60b.d.ts +614 -0
- package/dist/client-aXK_gEyr.d.cts +614 -0
- package/dist/index.cjs +4159 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1498 -0
- package/dist/index.d.ts +1498 -0
- package/dist/index.js +4135 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/auth.cjs +651 -0
- package/dist/modules/auth.cjs.map +1 -0
- package/dist/modules/auth.d.cts +384 -0
- package/dist/modules/auth.d.ts +384 -0
- package/dist/modules/auth.js +649 -0
- package/dist/modules/auth.js.map +1 -0
- package/dist/modules/files.cjs +266 -0
- package/dist/modules/files.cjs.map +1 -0
- package/dist/modules/files.d.cts +187 -0
- package/dist/modules/files.d.ts +187 -0
- package/dist/modules/files.js +264 -0
- package/dist/modules/files.js.map +1 -0
- package/dist/modules/items.cjs +654 -0
- package/dist/modules/items.cjs.map +1 -0
- package/dist/modules/items.d.cts +472 -0
- package/dist/modules/items.d.ts +472 -0
- package/dist/modules/items.js +651 -0
- package/dist/modules/items.js.map +1 -0
- package/dist/modules/schemas.cjs +269 -0
- package/dist/modules/schemas.cjs.map +1 -0
- package/dist/modules/schemas.d.cts +239 -0
- package/dist/modules/schemas.d.ts +239 -0
- package/dist/modules/schemas.js +267 -0
- package/dist/modules/schemas.js.map +1 -0
- package/dist/storage/index.cjs +162 -0
- package/dist/storage/index.cjs.map +1 -0
- package/dist/storage/index.d.cts +96 -0
- package/dist/storage/index.d.ts +96 -0
- package/dist/storage/index.js +157 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types-BdjsGANq.d.cts +40 -0
- package/dist/types-BdjsGANq.d.ts +40 -0
- package/package.json +107 -0
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { H as HttpClient, A as AuthMode, a as AuthStateEvent, U as User, R as RegisterData, b as AuthResponse, L as LoginCredentials, c as AuthTokens, M as MagicLinkOptions, P as PasswordResetOptions, T as Tenant, d as AuthState } from '../client-CzF9B60b.js';
|
|
2
|
+
import { S as StorageAdapter } from '../types-BdjsGANq.js';
|
|
3
|
+
|
|
4
|
+
type OAuthProvider = "google" | "facebook" | "apple" | "github";
|
|
5
|
+
interface OAuthOptions {
|
|
6
|
+
provider: OAuthProvider;
|
|
7
|
+
redirectUrl: string;
|
|
8
|
+
scopes?: string[];
|
|
9
|
+
state?: string;
|
|
10
|
+
}
|
|
11
|
+
interface InviteOptions {
|
|
12
|
+
email: string;
|
|
13
|
+
roleId: string;
|
|
14
|
+
tenantId?: string;
|
|
15
|
+
redirectUrl: string;
|
|
16
|
+
}
|
|
17
|
+
interface VerifyInviteResult {
|
|
18
|
+
valid: boolean;
|
|
19
|
+
email?: string;
|
|
20
|
+
tenantId?: string;
|
|
21
|
+
roleId?: string;
|
|
22
|
+
}
|
|
23
|
+
interface AuthModuleConfig {
|
|
24
|
+
client: HttpClient;
|
|
25
|
+
storage: StorageAdapter;
|
|
26
|
+
authMode: AuthMode;
|
|
27
|
+
onAuthStateChange?: (event: AuthStateEvent, user: User | null) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Authentication module for handling user authentication, sessions, and token management.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Login
|
|
35
|
+
* const { user, token } = await baasix.auth.login({
|
|
36
|
+
* email: 'user@example.com',
|
|
37
|
+
* password: 'password123'
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Get current user
|
|
41
|
+
* const user = await baasix.auth.getUser();
|
|
42
|
+
*
|
|
43
|
+
* // Logout
|
|
44
|
+
* await baasix.auth.logout();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare class AuthModule {
|
|
48
|
+
private client;
|
|
49
|
+
private storage;
|
|
50
|
+
private authMode;
|
|
51
|
+
private onAuthStateChange?;
|
|
52
|
+
private currentUser;
|
|
53
|
+
constructor(config: AuthModuleConfig);
|
|
54
|
+
/**
|
|
55
|
+
* Emit an authentication state change event
|
|
56
|
+
*/
|
|
57
|
+
private emitAuthStateChange;
|
|
58
|
+
/**
|
|
59
|
+
* Store authentication tokens
|
|
60
|
+
*/
|
|
61
|
+
private storeTokens;
|
|
62
|
+
/**
|
|
63
|
+
* Clear stored authentication data
|
|
64
|
+
*/
|
|
65
|
+
private clearAuth;
|
|
66
|
+
/**
|
|
67
|
+
* Register a new user
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const { user, token } = await baasix.auth.register({
|
|
72
|
+
* email: 'newuser@example.com',
|
|
73
|
+
* password: 'securepassword',
|
|
74
|
+
* firstName: 'John',
|
|
75
|
+
* lastName: 'Doe'
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
register(data: RegisterData): Promise<AuthResponse>;
|
|
80
|
+
/**
|
|
81
|
+
* Login with email and password
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const { user, token } = await baasix.auth.login({
|
|
86
|
+
* email: 'user@example.com',
|
|
87
|
+
* password: 'password123'
|
|
88
|
+
* });
|
|
89
|
+
*
|
|
90
|
+
* // Login with tenant (multi-tenant mode)
|
|
91
|
+
* const result = await baasix.auth.login({
|
|
92
|
+
* email: 'user@example.com',
|
|
93
|
+
* password: 'password123',
|
|
94
|
+
* tenantId: 'tenant-uuid'
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
login(credentials: LoginCredentials): Promise<AuthResponse>;
|
|
99
|
+
/**
|
|
100
|
+
* Logout the current user
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* await baasix.auth.logout();
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
logout(): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Get the current authenticated user from the server
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* const user = await baasix.auth.getUser();
|
|
114
|
+
* console.log(user?.email);
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
getUser(): Promise<User | null>;
|
|
118
|
+
/**
|
|
119
|
+
* Get the cached current user (does not make an API call)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* const user = await baasix.auth.getCachedUser();
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
getCachedUser(): Promise<User | null>;
|
|
127
|
+
/**
|
|
128
|
+
* Check if user is authenticated (has valid token)
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* if (await baasix.auth.isAuthenticated()) {
|
|
133
|
+
* // User is logged in
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
isAuthenticated(): Promise<boolean>;
|
|
138
|
+
/**
|
|
139
|
+
* Get the current access token
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* const token = await baasix.auth.getToken();
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
getToken(): Promise<string | null>;
|
|
147
|
+
/**
|
|
148
|
+
* Set a static token (useful for server-side or service accounts)
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* baasix.auth.setToken('your-api-token');
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
setToken(token: string): Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Refresh the current token
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```typescript
|
|
161
|
+
* const tokens = await baasix.auth.refreshToken();
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
refreshToken(): Promise<AuthTokens>;
|
|
165
|
+
/**
|
|
166
|
+
* Request a magic link for passwordless login
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* await baasix.auth.sendMagicLink({
|
|
171
|
+
* email: 'user@example.com',
|
|
172
|
+
* redirectUrl: 'https://myapp.com/auth/callback'
|
|
173
|
+
* });
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
sendMagicLink(options: MagicLinkOptions): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Verify magic link/code and complete login
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* const { user, token } = await baasix.auth.verifyMagicLink('verification-token');
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
verifyMagicLink(token: string): Promise<AuthResponse>;
|
|
186
|
+
/**
|
|
187
|
+
* Request a password reset
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* await baasix.auth.forgotPassword({
|
|
192
|
+
* email: 'user@example.com',
|
|
193
|
+
* redirectUrl: 'https://myapp.com/reset-password'
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
forgotPassword(options: PasswordResetOptions): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Reset password using a reset token
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* await baasix.auth.resetPassword('reset-token', 'newpassword123');
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
resetPassword(token: string, newPassword: string): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Change the current user's password
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* await baasix.auth.changePassword('currentPassword', 'newPassword');
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
changePassword(currentPassword: string, newPassword: string): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Update the current user's profile
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* const updatedUser = await baasix.auth.updateProfile({
|
|
222
|
+
* firstName: 'Jane',
|
|
223
|
+
* lastName: 'Doe'
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
updateProfile(data: Partial<User>): Promise<User>;
|
|
228
|
+
/**
|
|
229
|
+
* Get available tenants for the current user (multi-tenant mode)
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* const tenants = await baasix.auth.getTenants();
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
getTenants(): Promise<Tenant[]>;
|
|
237
|
+
/**
|
|
238
|
+
* Switch to a different tenant (multi-tenant mode)
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* const { user, token } = await baasix.auth.switchTenant('tenant-uuid');
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
switchTenant(tenantId: string): Promise<AuthResponse>;
|
|
246
|
+
/**
|
|
247
|
+
* Get the current authentication state
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const state = await baasix.auth.getState();
|
|
252
|
+
* console.log(state.isAuthenticated, state.user);
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
getState(): Promise<AuthState>;
|
|
256
|
+
/**
|
|
257
|
+
* Initialize authentication state from storage
|
|
258
|
+
* Call this on app startup to restore previous session
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* await baasix.auth.initialize();
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
initialize(): Promise<AuthState>;
|
|
266
|
+
/**
|
|
267
|
+
* Get the OAuth authorization URL for a provider
|
|
268
|
+
* Redirect the user to this URL to start the OAuth flow
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```typescript
|
|
272
|
+
* const url = baasix.auth.getOAuthUrl({
|
|
273
|
+
* provider: 'google',
|
|
274
|
+
* redirectUrl: 'https://myapp.com/auth/callback'
|
|
275
|
+
* });
|
|
276
|
+
* window.location.href = url;
|
|
277
|
+
* ```
|
|
278
|
+
*/
|
|
279
|
+
getOAuthUrl(options: OAuthOptions): string;
|
|
280
|
+
/**
|
|
281
|
+
* Handle OAuth callback and complete login
|
|
282
|
+
* Call this from your callback page with the token from URL
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* // In your callback page
|
|
287
|
+
* const params = new URLSearchParams(window.location.search);
|
|
288
|
+
* const token = params.get('token');
|
|
289
|
+
*
|
|
290
|
+
* if (token) {
|
|
291
|
+
* await baasix.auth.handleOAuthCallback(token);
|
|
292
|
+
* }
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
handleOAuthCallback(token: string): Promise<AuthResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Request email verification
|
|
298
|
+
* Sends a verification email to the current user
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```typescript
|
|
302
|
+
* await baasix.auth.requestEmailVerification('https://myapp.com/verify-email');
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
requestEmailVerification(redirectUrl: string): Promise<void>;
|
|
306
|
+
/**
|
|
307
|
+
* Verify email with token
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* const params = new URLSearchParams(window.location.search);
|
|
312
|
+
* const token = params.get('token');
|
|
313
|
+
*
|
|
314
|
+
* await baasix.auth.verifyEmail(token);
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
317
|
+
verifyEmail(token: string): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* Check if current session/token is valid
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* const isValid = await baasix.auth.checkSession();
|
|
324
|
+
* ```
|
|
325
|
+
*/
|
|
326
|
+
checkSession(): Promise<boolean>;
|
|
327
|
+
/**
|
|
328
|
+
* Send an invitation to a user (multi-tenant mode)
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* await baasix.auth.sendInvite({
|
|
333
|
+
* email: 'newuser@example.com',
|
|
334
|
+
* roleId: 'role-uuid',
|
|
335
|
+
* tenantId: 'tenant-uuid',
|
|
336
|
+
* redirectUrl: 'https://myapp.com/accept-invite'
|
|
337
|
+
* });
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
sendInvite(options: InviteOptions): Promise<void>;
|
|
341
|
+
/**
|
|
342
|
+
* Verify an invitation token
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
346
|
+
* const params = new URLSearchParams(window.location.search);
|
|
347
|
+
* const token = params.get('token');
|
|
348
|
+
*
|
|
349
|
+
* const result = await baasix.auth.verifyInvite(token);
|
|
350
|
+
* if (result.valid) {
|
|
351
|
+
* // Show registration form with pre-filled email
|
|
352
|
+
* }
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
verifyInvite(token: string, redirectUrl?: string): Promise<VerifyInviteResult>;
|
|
356
|
+
/**
|
|
357
|
+
* Accept an invitation (for existing users)
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* await baasix.auth.acceptInvite(token);
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
acceptInvite(token: string): Promise<AuthResponse>;
|
|
365
|
+
/**
|
|
366
|
+
* Register with an invitation token
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```typescript
|
|
370
|
+
* const { user, token } = await baasix.auth.registerWithInvite({
|
|
371
|
+
* email: 'user@example.com',
|
|
372
|
+
* password: 'password',
|
|
373
|
+
* firstName: 'John',
|
|
374
|
+
* lastName: 'Doe',
|
|
375
|
+
* inviteToken: 'invite-token'
|
|
376
|
+
* });
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
registerWithInvite(data: RegisterData & {
|
|
380
|
+
inviteToken: string;
|
|
381
|
+
}): Promise<AuthResponse>;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export { AuthModule, type AuthModuleConfig, AuthResponse, AuthState, AuthStateEvent, AuthTokens, type InviteOptions, LoginCredentials, MagicLinkOptions, type OAuthOptions, type OAuthProvider, PasswordResetOptions, RegisterData, Tenant, User, type VerifyInviteResult };
|