@doany-ai/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +60 -0
  3. package/dist/client.d.ts +96 -0
  4. package/dist/client.js +395 -0
  5. package/dist/client.types.d.ts +149 -0
  6. package/dist/client.types.js +1 -0
  7. package/dist/index.d.ts +17 -0
  8. package/dist/index.js +5 -0
  9. package/dist/modules/agents.d.ts +2 -0
  10. package/dist/modules/agents.js +89 -0
  11. package/dist/modules/agents.types.d.ts +397 -0
  12. package/dist/modules/agents.types.js +1 -0
  13. package/dist/modules/ai-gateway.d.ts +2 -0
  14. package/dist/modules/ai-gateway.js +13 -0
  15. package/dist/modules/ai-gateway.types.d.ts +88 -0
  16. package/dist/modules/ai-gateway.types.js +1 -0
  17. package/dist/modules/analytics.d.ts +20 -0
  18. package/dist/modules/analytics.js +284 -0
  19. package/dist/modules/analytics.types.d.ts +122 -0
  20. package/dist/modules/analytics.types.js +1 -0
  21. package/dist/modules/app-logs.d.ts +11 -0
  22. package/dist/modules/app-logs.js +27 -0
  23. package/dist/modules/app-logs.types.d.ts +46 -0
  24. package/dist/modules/app-logs.types.js +1 -0
  25. package/dist/modules/app.types.d.ts +142 -0
  26. package/dist/modules/app.types.js +1 -0
  27. package/dist/modules/auth.d.ts +13 -0
  28. package/dist/modules/auth.js +240 -0
  29. package/dist/modules/auth.types.d.ts +517 -0
  30. package/dist/modules/auth.types.js +1 -0
  31. package/dist/modules/connectors.d.ts +20 -0
  32. package/dist/modules/connectors.js +98 -0
  33. package/dist/modules/connectors.types.d.ts +376 -0
  34. package/dist/modules/connectors.types.js +1 -0
  35. package/dist/modules/custom-integrations.d.ts +11 -0
  36. package/dist/modules/custom-integrations.js +32 -0
  37. package/dist/modules/custom-integrations.types.d.ts +89 -0
  38. package/dist/modules/custom-integrations.types.js +1 -0
  39. package/dist/modules/entities.d.ts +20 -0
  40. package/dist/modules/entities.js +163 -0
  41. package/dist/modules/entities.types.d.ts +702 -0
  42. package/dist/modules/entities.types.js +1 -0
  43. package/dist/modules/functions.d.ts +12 -0
  44. package/dist/modules/functions.js +79 -0
  45. package/dist/modules/functions.types.d.ts +150 -0
  46. package/dist/modules/functions.types.js +1 -0
  47. package/dist/modules/integrations.d.ts +11 -0
  48. package/dist/modules/integrations.js +77 -0
  49. package/dist/modules/integrations.types.d.ts +418 -0
  50. package/dist/modules/integrations.types.js +1 -0
  51. package/dist/modules/sso.d.ts +11 -0
  52. package/dist/modules/sso.js +22 -0
  53. package/dist/modules/sso.types.d.ts +68 -0
  54. package/dist/modules/sso.types.js +1 -0
  55. package/dist/modules/types.d.ts +5 -0
  56. package/dist/modules/types.js +5 -0
  57. package/dist/modules/users.d.ts +16 -0
  58. package/dist/modules/users.js +23 -0
  59. package/dist/types.d.ts +72 -0
  60. package/dist/types.js +1 -0
  61. package/dist/utils/auth-utils.d.ts +117 -0
  62. package/dist/utils/auth-utils.js +189 -0
  63. package/dist/utils/auth-utils.types.d.ts +146 -0
  64. package/dist/utils/auth-utils.types.js +1 -0
  65. package/dist/utils/axios-client.d.ts +100 -0
  66. package/dist/utils/axios-client.js +202 -0
  67. package/dist/utils/axios-client.types.d.ts +28 -0
  68. package/dist/utils/axios-client.types.js +1 -0
  69. package/dist/utils/common.d.ts +4 -0
  70. package/dist/utils/common.js +11 -0
  71. package/dist/utils/sharedInstance.d.ts +1 -0
  72. package/dist/utils/sharedInstance.js +15 -0
  73. package/dist/utils/socket-utils.d.ts +47 -0
  74. package/dist/utils/socket-utils.js +170 -0
  75. package/package.json +54 -0
@@ -0,0 +1,517 @@
1
+ /**
2
+ * An authenticated user.
3
+ */
4
+ export interface User {
5
+ /** Unique user identifier. */
6
+ id: string;
7
+ /** When the user was created. */
8
+ created_date: string;
9
+ /** When the user was last updated. */
10
+ updated_date: string;
11
+ /** User's email address. */
12
+ email: string;
13
+ /** User's full name. */
14
+ full_name: string | null;
15
+ /** Whether the user is disabled. */
16
+ disabled: boolean | null;
17
+ /** Whether the user's email has been verified. */
18
+ is_verified: boolean;
19
+ /** The app ID this user belongs to. */
20
+ app_id: string;
21
+ /** Whether this is a service account. */
22
+ is_service: boolean;
23
+ /** Internal app role.
24
+ * @internal
25
+ */
26
+ _app_role: string;
27
+ /**
28
+ * User's role in the app. Roles are configured in the app settings and determine the user's permissions and access levels.
29
+ */
30
+ role: string;
31
+ /**
32
+ * Additional custom fields defined in the user schema. Any custom properties added to the user schema in the app will be available here with their configured types and values.
33
+ */
34
+ [key: string]: any;
35
+ }
36
+ /**
37
+ * Response from login endpoints containing user information and access token.
38
+ */
39
+ export interface LoginResponse {
40
+ /** JWT access token for authentication. */
41
+ access_token: string;
42
+ /** User information. */
43
+ user: User;
44
+ }
45
+ /**
46
+ * Payload for user registration.
47
+ */
48
+ export interface RegisterParams {
49
+ /** User's email address. */
50
+ email: string;
51
+ /** User's password. */
52
+ password: string;
53
+ /** Optional {@link https://developers.cloudflare.com/turnstile/ | Cloudflare Turnstile CAPTCHA token} for bot protection. */
54
+ turnstile_token?: string | null;
55
+ /** Optional {@link https://docs.base44.com/Getting-Started/Referral-program | referral code} from an existing user. */
56
+ referral_code?: string | null;
57
+ }
58
+ /**
59
+ * Parameters for OTP verification.
60
+ */
61
+ export interface VerifyOtpParams {
62
+ /** User's email address. */
63
+ email: string;
64
+ /** One-time password code received by email. */
65
+ otpCode: string;
66
+ }
67
+ /**
68
+ * Parameters for changing a user's password.
69
+ */
70
+ export interface ChangePasswordParams {
71
+ /** User ID. */
72
+ userId: string;
73
+ /** Current password for verification. */
74
+ currentPassword: string;
75
+ /** New password to set. */
76
+ newPassword: string;
77
+ }
78
+ /**
79
+ * Parameters for resetting a password with a token.
80
+ */
81
+ export interface ResetPasswordParams {
82
+ /** Reset token received by email. */
83
+ resetToken: string;
84
+ /** New password to set. */
85
+ newPassword: string;
86
+ }
87
+ /**
88
+ * Configuration options for the auth module.
89
+ */
90
+ export interface AuthModuleOptions {
91
+ /** Server URL for API requests. */
92
+ serverUrl: string;
93
+ /** Base URL for the app (used for login redirects). */
94
+ appBaseUrl: string;
95
+ }
96
+ /**
97
+ * Authentication module for managing user authentication and authorization. The module automatically stores tokens in local storage when available and manages authorization headers for API requests.
98
+ *
99
+ * ## Features
100
+ *
101
+ * This module provides comprehensive authentication functionality including:
102
+ * - Email/password login and registration
103
+ * - Token management
104
+ * - User profile access and updates
105
+ * - Password reset flows
106
+ * - OTP verification
107
+ * - User invitations
108
+ *
109
+ * ## Authentication Modes
110
+ *
111
+ * The auth module is only available in user authentication mode (`base44.auth`).
112
+ */
113
+ export interface AuthModule {
114
+ /**
115
+ * Gets the current authenticated user's information.
116
+ *
117
+ * @returns Promise resolving to the user's profile data.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * // Get current user information
122
+ * const user = await base44.auth.me();
123
+ * console.log(`Logged in as: ${user.email}`);
124
+ * console.log(`User ID: ${user.id}`);
125
+ * ```
126
+ */
127
+ me(): Promise<User>;
128
+ /**
129
+ * Updates the current authenticated user's information.
130
+ *
131
+ * You can update `role` and any [custom fields](/developers/backend/resources/entities/user-schema#custom-fields) defined in your
132
+ * User entity schema.
133
+ * The `role` value must be either `'user'` or `'admin'`.
134
+ * <Note>
135
+ * The following fields are read-only and can't be changed with this method:
136
+ * `id`, `email`, `full_name`, `created_date`, `updated_date`, and `created_by`.
137
+ * </Note>
138
+ *
139
+ * @param data - Object containing the fields to update.
140
+ * @returns Promise resolving to the updated user data.
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // Update role and custom fields defined in your User entity
145
+ * await base44.auth.updateMe({
146
+ * role: 'admin',
147
+ * bio: 'Software developer',
148
+ * preferences: { theme: 'dark' }
149
+ * });
150
+ * ```
151
+ */
152
+ updateMe(data: Record<string, any>): Promise<User>;
153
+ /**
154
+ * Redirects the user to the app's login page.
155
+ *
156
+ * Redirects with a callback URL to return to after successful authentication. Requires a browser environment and can't be used in the backend.
157
+ *
158
+ * @param nextUrl - URL to redirect to after successful login.
159
+ * @throws {Error} When not in a browser environment.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Redirect to login and come back to current page
164
+ * base44.auth.redirectToLogin(window.location.href);
165
+ * ```
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * // Redirect to login and then go to the dashboard page
170
+ * base44.auth.redirectToLogin('/dashboard');
171
+ * ```
172
+ */
173
+ redirectToLogin(nextUrl: string): void;
174
+ /**
175
+ * Redirects the user to a third-party authentication provider's login page.
176
+ *
177
+ * Initiates an OAuth login flow with one of the built-in providers. Requires a browser environment and can't be used in the backend.
178
+ *
179
+ * Supported providers:
180
+ * - `'google'`: {@link https://developers.google.com/identity/protocols/oauth2 | Google OAuth}. Enabled by default.
181
+ * - `'microsoft'`: {@link https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow | Microsoft OAuth}. Enable Microsoft in your app's authentication settings before specifying this provider.
182
+ * - `'facebook'`: {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using.
183
+ * - `'apple'`: {@link https://developer.apple.com/sign-in-with-apple/ | Sign in with Apple}. Enable Apple in your app's authentication settings before using this provider.
184
+ * - `'sso'`: Enterprise SSO. {@link https://docs.base44.com/Setting-up-your-app/Setting-up-SSO | Set up an SSO provider} in your app's authentication settings before using this provider.
185
+ *
186
+ * @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, `'apple'`, or `'sso'`.
187
+ * @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * // Google
192
+ * base44.auth.loginWithProvider('google', window.location.pathname);
193
+ * ```
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * // Microsoft
198
+ * base44.auth.loginWithProvider('microsoft', '/dashboard');
199
+ * ```
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * // Apple
204
+ * base44.auth.loginWithProvider('apple', '/dashboard');
205
+ * ```
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * // SSO
210
+ * base44.auth.loginWithProvider('sso', '/dashboard');
211
+ * ```
212
+ *
213
+ */
214
+ loginWithProvider(provider: string, fromUrl?: string): void;
215
+ /**
216
+ * Logs out the current user.
217
+ *
218
+ * Removes the authentication token from local storage and Axios headers, then optionally redirects to a URL or reloads the page. Requires a browser environment and can't be used in the backend.
219
+ *
220
+ * @param redirectUrl - Optional URL to redirect to after logout. Reloads the page if not provided.
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * // Logout and reload page
225
+ * base44.auth.logout();
226
+ * ```
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * // Logout and redirect to login page
231
+ * base44.auth.logout('/login');
232
+ * ```
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * // Logout and redirect to home
237
+ * base44.auth.logout('/');
238
+ * ```
239
+ */
240
+ logout(redirectUrl?: string): void;
241
+ /**
242
+ * Sets the authentication token.
243
+ *
244
+ * Updates the authorization header for API requests and optionally saves the token to local storage for persistence. Saving to local storage requires a browser environment and is automatically skipped in backend environments.
245
+ *
246
+ * @param token - JWT authentication token.
247
+ * @param saveToStorage - Whether to save the token to local storage. Defaults to true.
248
+ *
249
+ * @example
250
+ * ```typescript
251
+ * // Set token and save to local storage
252
+ * base44.auth.setToken('eyJhbGciOiJIUzI1NiIs...');
253
+ * ```
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * // Set token without saving to local storage
258
+ * base44.auth.setToken('eyJhbGciOiJIUzI1NiIs...', false);
259
+ * ```
260
+ */
261
+ setToken(token: string, saveToStorage?: boolean): void;
262
+ /**
263
+ * Logs in a registered user using email and password.
264
+ *
265
+ * Authenticates a user with email and password credentials. The user must already have a registered account. For new users, use {@linkcode register | register()} first to create an account. On successful login, automatically sets the token for subsequent requests.
266
+ *
267
+ * @param email - User's email address.
268
+ * @param password - User's password.
269
+ * @param turnstileToken - Optional {@link https://developers.cloudflare.com/turnstile/ | Cloudflare Turnstile CAPTCHA token} for bot protection.
270
+ * @returns Promise resolving to login response with access token and user data.
271
+ * @throws Error if the email and password combination is invalid or the user is not registered.
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * // Login with email and password
276
+ * try {
277
+ * const { access_token, user } = await base44.auth.loginViaEmailPassword(
278
+ * 'user@example.com',
279
+ * 'securePassword123'
280
+ * );
281
+ * console.log('Login successful!', user);
282
+ * } catch (error) {
283
+ * console.error('Login failed:', error);
284
+ * }
285
+ * ```
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * // With captcha token
290
+ * const response = await base44.auth.loginViaEmailPassword(
291
+ * 'user@example.com',
292
+ * 'securePassword123',
293
+ * 'captcha-token-here'
294
+ * );
295
+ * ```
296
+ */
297
+ loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<LoginResponse>;
298
+ /**
299
+ * Checks if the current user is authenticated.
300
+ *
301
+ * @returns Promise resolving to true if authenticated, false otherwise.
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * // Check authentication status
306
+ * const isAuthenticated = await base44.auth.isAuthenticated();
307
+ * if (isAuthenticated) {
308
+ * console.log('User is logged in');
309
+ * } else {
310
+ * // Redirect to login page
311
+ * base44.auth.redirectToLogin(window.location.href);
312
+ * }
313
+ * ```
314
+ */
315
+ isAuthenticated(): Promise<boolean>;
316
+ /**
317
+ * Invites a user to the app.
318
+ *
319
+ * Sends an invitation email to a potential user with a specific role.
320
+ * Roles are configured in the app settings and determine
321
+ * the user's permissions and access levels.
322
+ *
323
+ * @param userEmail - Email address of the user to invite.
324
+ * @param role - Role to assign to the invited user. Must match a role defined in the app. For example, `'admin'` or `'user'`.
325
+ * @returns Promise that resolves when the invitation is sent successfully. Throws an error if the invitation fails.
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * try {
330
+ * await base44.auth.inviteUser('newuser@example.com', 'user');
331
+ * console.log('Invitation sent successfully!');
332
+ * } catch (error) {
333
+ * console.error('Failed to send invitation:', error);
334
+ * }
335
+ * ```
336
+ */
337
+ inviteUser(userEmail: string, role: string): Promise<any>;
338
+ /**
339
+ * Registers a new user account.
340
+ *
341
+ * Creates a new user account with email and password. Registration sends an OTP
342
+ * code to the user's email. Pass that code to
343
+ * {@linkcode verifyOtp | verifyOtp()} to complete verification, then log the user
344
+ * in with {@linkcode loginViaEmailPassword | loginViaEmailPassword()}.
345
+ *
346
+ * @param params - Registration details including email, password, and optional fields.
347
+ * @returns Promise resolving to the registration response.
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * // Register a new user
352
+ * await base44.auth.register({
353
+ * email: 'newuser@example.com',
354
+ * password: 'securePassword123',
355
+ * referral_code: 'FRIEND2024'
356
+ * });
357
+ *
358
+ * // Verify with the OTP code from the user's email
359
+ * await base44.auth.verifyOtp({
360
+ * email: 'newuser@example.com',
361
+ * otpCode: '123456'
362
+ * });
363
+ *
364
+ * // Log the user in after verification
365
+ * const { access_token, user } = await base44.auth.loginViaEmailPassword(
366
+ * 'newuser@example.com',
367
+ * 'securePassword123'
368
+ * );
369
+ * ```
370
+ */
371
+ register(params: RegisterParams): Promise<any>;
372
+ /**
373
+ * Verifies an OTP (one-time password) code.
374
+ *
375
+ * Confirms that the user owns the email address by checking the code sent to
376
+ * their inbox during {@linkcode register | register()}. After a successful
377
+ * call, log the user in with
378
+ * {@linkcode loginViaEmailPassword | loginViaEmailPassword()}. If the code
379
+ * has expired or the user didn't receive it, send a fresh one with
380
+ * {@linkcode resendOtp | resendOtp()}.
381
+ *
382
+ * @param params - The email being verified and the OTP code the user entered.
383
+ * @returns Promise resolving to the verification response, which includes an
384
+ * access token for the now-verified user.
385
+ * @throws Error if the OTP code is invalid or expired.
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * // Verify the code the user entered from their email
390
+ * try {
391
+ * await base44.auth.verifyOtp({
392
+ * email: 'user@example.com',
393
+ * otpCode: '123456'
394
+ * });
395
+ * console.log('Email verified successfully!');
396
+ * } catch (error) {
397
+ * console.error('Invalid or expired OTP code');
398
+ * }
399
+ * ```
400
+ *
401
+ * @example
402
+ * ```typescript
403
+ * // Full registration flow
404
+ * await base44.auth.register({
405
+ * email: 'newuser@example.com',
406
+ * password: 'securePassword123'
407
+ * });
408
+ *
409
+ * // The user receives an OTP code by email. Collect it and verify.
410
+ * await base44.auth.verifyOtp({
411
+ * email: 'newuser@example.com',
412
+ * otpCode: '123456'
413
+ * });
414
+ *
415
+ * // Log the user in after verification
416
+ * const { access_token, user } = await base44.auth.loginViaEmailPassword(
417
+ * 'newuser@example.com',
418
+ * 'securePassword123'
419
+ * );
420
+ * ```
421
+ */
422
+ verifyOtp(params: VerifyOtpParams): Promise<any>;
423
+ /**
424
+ * Resends an OTP code to the user's email address.
425
+ *
426
+ * Call this when the user didn't receive the original code sent by
427
+ * {@linkcode register | register()}, or when the previous code has expired.
428
+ * The new code replaces the previous one. Pass it to
429
+ * {@linkcode verifyOtp | verifyOtp()} to complete verification.
430
+ *
431
+ * @param email - Email address to send the new OTP to.
432
+ * @returns Promise resolving once the new OTP has been sent, with a
433
+ * confirmation message and the new code's expiration window.
434
+ * @throws Error if the email is invalid or the request fails.
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * // Resend the OTP when the user didn't receive the original
439
+ * try {
440
+ * await base44.auth.resendOtp('user@example.com');
441
+ * console.log('OTP resent! Please check your email.');
442
+ * } catch (error) {
443
+ * console.error('Failed to resend OTP:', error);
444
+ * }
445
+ * ```
446
+ */
447
+ resendOtp(email: string): Promise<any>;
448
+ /**
449
+ * Requests a password reset.
450
+ *
451
+ * Sends a password reset email to the specified email address.
452
+ *
453
+ * @param email - Email address for the account to reset.
454
+ * @returns Promise resolving when the password reset email is sent successfully.
455
+ * @throws Error if the email is invalid or the request fails.
456
+ *
457
+ * @example
458
+ * ```typescript
459
+ * try {
460
+ * await base44.auth.resetPasswordRequest('user@example.com');
461
+ * console.log('Password reset email sent!');
462
+ * } catch (error) {
463
+ * console.error('Failed to send password reset email:', error);
464
+ * }
465
+ * ```
466
+ */
467
+ resetPasswordRequest(email: string): Promise<any>;
468
+ /**
469
+ * Resets password using a reset token.
470
+ *
471
+ * Completes the password reset flow by setting a new password
472
+ * using the token received by email.
473
+ *
474
+ * @param params - Object containing the reset token and new password.
475
+ * @returns Promise resolving when the password is reset successfully.
476
+ * @throws Error if the reset token is invalid, expired, or the request fails.
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * try {
481
+ * await base44.auth.resetPassword({
482
+ * resetToken: 'token-from-email',
483
+ * newPassword: 'newSecurePassword456'
484
+ * });
485
+ * console.log('Password reset successful!');
486
+ * } catch (error) {
487
+ * console.error('Failed to reset password:', error);
488
+ * }
489
+ * ```
490
+ */
491
+ resetPassword(params: ResetPasswordParams): Promise<any>;
492
+ /**
493
+ * Changes the user's password.
494
+ *
495
+ * Updates the password for an authenticated user by verifying
496
+ * the current password and setting a new one.
497
+ *
498
+ * @param params - Object containing user ID, current password, and new password.
499
+ * @returns Promise resolving when the password is changed successfully.
500
+ * @throws Error if the current password is incorrect or the request fails.
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * try {
505
+ * await base44.auth.changePassword({
506
+ * userId: 'user-123',
507
+ * currentPassword: 'oldPassword123',
508
+ * newPassword: 'newSecurePassword456'
509
+ * });
510
+ * console.log('Password changed successfully!');
511
+ * } catch (error) {
512
+ * console.error('Failed to change password:', error);
513
+ * }
514
+ * ```
515
+ */
516
+ changePassword(params: ChangePasswordParams): Promise<any>;
517
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,20 @@
1
+ import { AxiosInstance } from "axios";
2
+ import { ConnectorsModule, UserConnectorsModule } from "./connectors.types.js";
3
+ /**
4
+ * Creates the Connectors module for the Base44 SDK.
5
+ *
6
+ * @param axios - Axios instance (should be service role client)
7
+ * @param appId - Application ID
8
+ * @returns Connectors module with methods to retrieve OAuth tokens
9
+ * @internal
10
+ */
11
+ export declare function createConnectorsModule(axios: AxiosInstance, appId: string): ConnectorsModule;
12
+ /**
13
+ * Creates the user-scoped Connectors module (app-user OAuth flows).
14
+ *
15
+ * @param axios - Axios instance (user-scoped client)
16
+ * @param appId - Application ID
17
+ * @returns User connectors module with app-user OAuth methods
18
+ * @internal
19
+ */
20
+ export declare function createUserConnectorsModule(axios: AxiosInstance, appId: string): UserConnectorsModule;
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Creates the Connectors module for the Base44 SDK.
3
+ *
4
+ * @param axios - Axios instance (should be service role client)
5
+ * @param appId - Application ID
6
+ * @returns Connectors module with methods to retrieve OAuth tokens
7
+ * @internal
8
+ */
9
+ export function createConnectorsModule(axios, appId) {
10
+ return {
11
+ /**
12
+ * Retrieve an OAuth access token for a specific external integration type.
13
+ * @deprecated Use getConnection(integrationType) and use the returned accessToken (and connectionConfig when needed) instead.
14
+ */
15
+ // @ts-expect-error Return type mismatch with interface - implementation returns string, interface expects string but implementation is typed as ConnectorAccessTokenResponse
16
+ async getAccessToken(integrationType) {
17
+ if (!integrationType || typeof integrationType !== "string") {
18
+ throw new Error("Integration type is required and must be a string");
19
+ }
20
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
21
+ // @ts-expect-error
22
+ return response.access_token;
23
+ },
24
+ async getConnection(integrationType) {
25
+ var _a;
26
+ if (!integrationType || typeof integrationType !== "string") {
27
+ throw new Error("Integration type is required and must be a string");
28
+ }
29
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/${integrationType}`);
30
+ const data = response;
31
+ return {
32
+ accessToken: data.access_token,
33
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
34
+ };
35
+ },
36
+ async getWorkspaceConnection(connectorId) {
37
+ var _a;
38
+ if (!connectorId || typeof connectorId !== "string") {
39
+ throw new Error("Connector ID is required and must be a string");
40
+ }
41
+ const response = await axios.get(`/apps/${appId}/external-auth/tokens/connectors/${connectorId}`);
42
+ const data = response;
43
+ return {
44
+ accessToken: data.access_token,
45
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
46
+ };
47
+ },
48
+ /**
49
+ * @deprecated Use getCurrentAppUserConnection(connectorId) and use the returned accessToken (and connectionConfig when needed) instead.
50
+ */
51
+ async getCurrentAppUserAccessToken(connectorId) {
52
+ if (!connectorId || typeof connectorId !== "string") {
53
+ throw new Error("Connector ID is required and must be a string");
54
+ }
55
+ const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`);
56
+ const data = response;
57
+ return data.access_token;
58
+ },
59
+ async getCurrentAppUserConnection(connectorId) {
60
+ var _a;
61
+ if (!connectorId || typeof connectorId !== "string") {
62
+ throw new Error("Connector ID is required and must be a string");
63
+ }
64
+ const response = await axios.get(`/apps/${appId}/app-user-auth/connectors/${connectorId}/token`);
65
+ const data = response;
66
+ return {
67
+ accessToken: data.access_token,
68
+ connectionConfig: (_a = data.connection_config) !== null && _a !== void 0 ? _a : null,
69
+ };
70
+ },
71
+ };
72
+ }
73
+ /**
74
+ * Creates the user-scoped Connectors module (app-user OAuth flows).
75
+ *
76
+ * @param axios - Axios instance (user-scoped client)
77
+ * @param appId - Application ID
78
+ * @returns User connectors module with app-user OAuth methods
79
+ * @internal
80
+ */
81
+ export function createUserConnectorsModule(axios, appId) {
82
+ return {
83
+ async connectAppUser(connectorId) {
84
+ if (!connectorId || typeof connectorId !== "string") {
85
+ throw new Error("Connector ID is required and must be a string");
86
+ }
87
+ const response = await axios.post(`/apps/${appId}/app-user-auth/connectors/${connectorId}/initiate`);
88
+ const data = response;
89
+ return data.redirect_url;
90
+ },
91
+ async disconnectAppUser(connectorId) {
92
+ if (!connectorId || typeof connectorId !== "string") {
93
+ throw new Error("Connector ID is required and must be a string");
94
+ }
95
+ await axios.delete(`/apps/${appId}/app-user-auth/connectors/${connectorId}`);
96
+ },
97
+ };
98
+ }