@depup/base44__sdk 0.8.22-depup.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 +32 -0
- package/changes.json +14 -0
- package/dist/client.d.ts +96 -0
- package/dist/client.js +375 -0
- package/dist/client.types.d.ts +144 -0
- package/dist/client.types.js +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +5 -0
- package/dist/modules/agents.d.ts +2 -0
- package/dist/modules/agents.js +77 -0
- package/dist/modules/agents.types.d.ts +377 -0
- package/dist/modules/agents.types.js +1 -0
- package/dist/modules/analytics.d.ts +20 -0
- package/dist/modules/analytics.js +277 -0
- package/dist/modules/analytics.types.d.ts +122 -0
- package/dist/modules/analytics.types.js +1 -0
- package/dist/modules/app-logs.d.ts +11 -0
- package/dist/modules/app-logs.js +27 -0
- package/dist/modules/app-logs.types.d.ts +46 -0
- package/dist/modules/app-logs.types.js +1 -0
- package/dist/modules/app.types.d.ts +142 -0
- package/dist/modules/app.types.js +1 -0
- package/dist/modules/auth.d.ts +13 -0
- package/dist/modules/auth.js +180 -0
- package/dist/modules/auth.types.d.ts +481 -0
- package/dist/modules/auth.types.js +1 -0
- package/dist/modules/connectors.d.ts +20 -0
- package/dist/modules/connectors.js +71 -0
- package/dist/modules/connectors.types.d.ts +296 -0
- package/dist/modules/connectors.types.js +1 -0
- package/dist/modules/custom-integrations.d.ts +11 -0
- package/dist/modules/custom-integrations.js +32 -0
- package/dist/modules/custom-integrations.types.d.ts +89 -0
- package/dist/modules/custom-integrations.types.js +1 -0
- package/dist/modules/entities.d.ts +20 -0
- package/dist/modules/entities.js +149 -0
- package/dist/modules/entities.types.d.ts +552 -0
- package/dist/modules/entities.types.js +1 -0
- package/dist/modules/functions.d.ts +12 -0
- package/dist/modules/functions.js +79 -0
- package/dist/modules/functions.types.d.ts +103 -0
- package/dist/modules/functions.types.js +1 -0
- package/dist/modules/integrations.d.ts +11 -0
- package/dist/modules/integrations.js +77 -0
- package/dist/modules/integrations.types.d.ts +413 -0
- package/dist/modules/integrations.types.js +1 -0
- package/dist/modules/sso.d.ts +12 -0
- package/dist/modules/sso.js +23 -0
- package/dist/modules/sso.types.d.ts +44 -0
- package/dist/modules/sso.types.js +1 -0
- package/dist/modules/types.d.ts +4 -0
- package/dist/modules/types.js +4 -0
- package/dist/modules/users.d.ts +16 -0
- package/dist/modules/users.js +23 -0
- package/dist/types.d.ts +72 -0
- package/dist/types.js +1 -0
- package/dist/utils/auth-utils.d.ts +117 -0
- package/dist/utils/auth-utils.js +189 -0
- package/dist/utils/auth-utils.types.d.ts +146 -0
- package/dist/utils/auth-utils.types.js +1 -0
- package/dist/utils/axios-client.d.ts +100 -0
- package/dist/utils/axios-client.js +193 -0
- package/dist/utils/axios-client.types.d.ts +28 -0
- package/dist/utils/axios-client.types.js +1 -0
- package/dist/utils/common.d.ts +3 -0
- package/dist/utils/common.js +6 -0
- package/dist/utils/sharedInstance.d.ts +1 -0
- package/dist/utils/sharedInstance.js +15 -0
- package/dist/utils/socket-utils.d.ts +47 -0
- package/dist/utils/socket-utils.js +115 -0
- package/package.json +87 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates the auth module for the Base44 SDK.
|
|
3
|
+
*
|
|
4
|
+
* @param axios - Axios instance for API requests
|
|
5
|
+
* @param functionsAxiosClient - Axios instance for functions API requests
|
|
6
|
+
* @param appId - Application ID
|
|
7
|
+
* @param options - Configuration options including server URLs
|
|
8
|
+
* @returns Auth module with authentication and user management methods
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export function createAuthModule(axios, functionsAxiosClient, appId, options) {
|
|
12
|
+
return {
|
|
13
|
+
// Get current user information
|
|
14
|
+
async me() {
|
|
15
|
+
return axios.get(`/apps/${appId}/entities/User/me`);
|
|
16
|
+
},
|
|
17
|
+
// Update current user data
|
|
18
|
+
async updateMe(data) {
|
|
19
|
+
return axios.put(`/apps/${appId}/entities/User/me`, data);
|
|
20
|
+
},
|
|
21
|
+
// Redirects the user to the app's login page
|
|
22
|
+
redirectToLogin(nextUrl) {
|
|
23
|
+
// This function only works in a browser environment
|
|
24
|
+
if (typeof window === "undefined") {
|
|
25
|
+
throw new Error("Login method can only be used in a browser environment");
|
|
26
|
+
}
|
|
27
|
+
// If nextUrl is not provided, use the current URL
|
|
28
|
+
const redirectUrl = nextUrl
|
|
29
|
+
? new URL(nextUrl, window.location.origin).toString()
|
|
30
|
+
: window.location.href;
|
|
31
|
+
// Build the login URL
|
|
32
|
+
const loginUrl = `${options.appBaseUrl}/login?from_url=${encodeURIComponent(redirectUrl)}`;
|
|
33
|
+
// Redirect to the login page
|
|
34
|
+
window.location.href = loginUrl;
|
|
35
|
+
},
|
|
36
|
+
// Redirects the user to a provider's login page
|
|
37
|
+
loginWithProvider(provider, fromUrl = "/") {
|
|
38
|
+
// Build the full redirect URL
|
|
39
|
+
const redirectUrl = new URL(fromUrl, window.location.origin).toString();
|
|
40
|
+
const queryParams = `app_id=${appId}&from_url=${encodeURIComponent(redirectUrl)}`;
|
|
41
|
+
// SSO uses a different URL structure with appId in the path
|
|
42
|
+
let authPath;
|
|
43
|
+
if (provider === "sso") {
|
|
44
|
+
authPath = `/apps/${appId}/auth/sso/login`;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// Google is the default provider, so no provider path segment needed
|
|
48
|
+
const providerPath = provider === "google" ? "" : `/${provider}`;
|
|
49
|
+
authPath = `/apps/auth${providerPath}/login`;
|
|
50
|
+
}
|
|
51
|
+
const loginUrl = `${options.appBaseUrl}/api${authPath}?${queryParams}`;
|
|
52
|
+
// Redirect to the provider login page
|
|
53
|
+
window.location.href = loginUrl;
|
|
54
|
+
},
|
|
55
|
+
// Logout the current user
|
|
56
|
+
logout(redirectUrl) {
|
|
57
|
+
// Remove token from axios headers (always do this)
|
|
58
|
+
delete axios.defaults.headers.common["Authorization"];
|
|
59
|
+
// Only do the rest if in a browser environment
|
|
60
|
+
if (typeof window !== "undefined") {
|
|
61
|
+
// Remove token from localStorage
|
|
62
|
+
if (window.localStorage) {
|
|
63
|
+
try {
|
|
64
|
+
window.localStorage.removeItem("base44_access_token");
|
|
65
|
+
// Remove "token" that is set by the built-in SDK of platform version 2
|
|
66
|
+
window.localStorage.removeItem("token");
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
console.error("Failed to remove token from localStorage:", e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Determine the from_url parameter
|
|
73
|
+
const fromUrl = redirectUrl || window.location.href;
|
|
74
|
+
// Redirect to server-side logout endpoint to clear HTTP-only cookies
|
|
75
|
+
const logoutUrl = `${options.appBaseUrl}/api/apps/auth/logout?from_url=${encodeURIComponent(fromUrl)}`;
|
|
76
|
+
window.location.href = logoutUrl;
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
// Set authentication token
|
|
80
|
+
setToken(token, saveToStorage = true) {
|
|
81
|
+
if (!token)
|
|
82
|
+
return;
|
|
83
|
+
// handle token change for axios clients
|
|
84
|
+
axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
85
|
+
functionsAxiosClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
|
|
86
|
+
// Save token to localStorage if requested
|
|
87
|
+
if (saveToStorage &&
|
|
88
|
+
typeof window !== "undefined" &&
|
|
89
|
+
window.localStorage) {
|
|
90
|
+
try {
|
|
91
|
+
window.localStorage.setItem("base44_access_token", token);
|
|
92
|
+
// Set "token" that is set by the built-in SDK of platform version 2
|
|
93
|
+
window.localStorage.setItem("token", token);
|
|
94
|
+
}
|
|
95
|
+
catch (e) {
|
|
96
|
+
console.error("Failed to save token to localStorage:", e);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
// Login using username and password
|
|
101
|
+
async loginViaEmailPassword(email, password, turnstileToken) {
|
|
102
|
+
var _a;
|
|
103
|
+
try {
|
|
104
|
+
const response = await axios.post(`/apps/${appId}/auth/login`, {
|
|
105
|
+
email,
|
|
106
|
+
password,
|
|
107
|
+
...(turnstileToken && { turnstile_token: turnstileToken }),
|
|
108
|
+
});
|
|
109
|
+
const { access_token, user } = response;
|
|
110
|
+
if (access_token) {
|
|
111
|
+
this.setToken(access_token);
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
access_token,
|
|
115
|
+
user,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// Handle authentication errors and cleanup
|
|
120
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
|
|
121
|
+
await this.logout();
|
|
122
|
+
}
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
// Verify if the current token is valid
|
|
127
|
+
async isAuthenticated() {
|
|
128
|
+
try {
|
|
129
|
+
await this.me();
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
// Invite a user to the app
|
|
137
|
+
inviteUser(userEmail, role) {
|
|
138
|
+
return axios.post(`/apps/${appId}/users/invite-user`, {
|
|
139
|
+
user_email: userEmail,
|
|
140
|
+
role,
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
// Register a new user account
|
|
144
|
+
register(payload) {
|
|
145
|
+
return axios.post(`/apps/${appId}/auth/register`, payload);
|
|
146
|
+
},
|
|
147
|
+
// Verify an OTP (One-time password) code
|
|
148
|
+
verifyOtp({ email, otpCode }) {
|
|
149
|
+
return axios.post(`/apps/${appId}/auth/verify-otp`, {
|
|
150
|
+
email,
|
|
151
|
+
otp_code: otpCode,
|
|
152
|
+
});
|
|
153
|
+
},
|
|
154
|
+
// Resend an OTP code to the user's email
|
|
155
|
+
resendOtp(email) {
|
|
156
|
+
return axios.post(`/apps/${appId}/auth/resend-otp`, { email });
|
|
157
|
+
},
|
|
158
|
+
// Request a password reset
|
|
159
|
+
resetPasswordRequest(email) {
|
|
160
|
+
return axios.post(`/apps/${appId}/auth/reset-password-request`, {
|
|
161
|
+
email,
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
// Reset password using a reset token
|
|
165
|
+
resetPassword({ resetToken, newPassword }) {
|
|
166
|
+
return axios.post(`/apps/${appId}/auth/reset-password`, {
|
|
167
|
+
reset_token: resetToken,
|
|
168
|
+
new_password: newPassword,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
// Change the user's password
|
|
172
|
+
changePassword({ userId, currentPassword, newPassword, }) {
|
|
173
|
+
return axios.post(`/apps/${appId}/auth/change-password`, {
|
|
174
|
+
user_id: userId,
|
|
175
|
+
current_password: currentPassword,
|
|
176
|
+
new_password: newPassword,
|
|
177
|
+
});
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
@@ -0,0 +1,481 @@
|
|
|
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
|
+
* Only the fields included in the data object will be updated.
|
|
132
|
+
* Commonly updated fields include `full_name` and custom profile fields.
|
|
133
|
+
*
|
|
134
|
+
* @param data - Object containing the fields to update.
|
|
135
|
+
* @returns Promise resolving to the updated user data.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* // Update specific fields
|
|
140
|
+
* const updatedUser = await base44.auth.updateMe({
|
|
141
|
+
* full_name: 'John Doe'
|
|
142
|
+
* });
|
|
143
|
+
* console.log(`Updated user: ${updatedUser.full_name}`);
|
|
144
|
+
* ```
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // Update custom fields defined in your User entity
|
|
149
|
+
* await base44.auth.updateMe({
|
|
150
|
+
* bio: 'Software developer',
|
|
151
|
+
* phone: '+1234567890',
|
|
152
|
+
* preferences: { theme: 'dark' }
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
updateMe(data: Partial<Omit<User, "id" | "created_date" | "updated_date">>): Promise<User>;
|
|
157
|
+
/**
|
|
158
|
+
* Redirects the user to the app's login page.
|
|
159
|
+
*
|
|
160
|
+
* Redirects with a callback URL to return to after successful authentication. Requires a browser environment and can't be used in the backend.
|
|
161
|
+
*
|
|
162
|
+
* @param nextUrl - URL to redirect to after successful login.
|
|
163
|
+
* @throws {Error} When not in a browser environment.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* // Redirect to login and come back to current page
|
|
168
|
+
* base44.auth.redirectToLogin(window.location.href);
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Redirect to login and then go to the dashboard page
|
|
174
|
+
* base44.auth.redirectToLogin('/dashboard');
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
redirectToLogin(nextUrl: string): void;
|
|
178
|
+
/**
|
|
179
|
+
* Redirects the user to a third-party authentication provider's login page.
|
|
180
|
+
*
|
|
181
|
+
* Initiates an OAuth login flow with one of the built-in providers. Requires a browser environment and can't be used in the backend.
|
|
182
|
+
*
|
|
183
|
+
* Supported providers:
|
|
184
|
+
* - `'google'`: {@link https://developers.google.com/identity/protocols/oauth2 | Google OAuth}. Enabled by default.
|
|
185
|
+
* - `'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.
|
|
186
|
+
* - `'facebook'`: {@link https://developers.facebook.com/docs/facebook-login | Facebook Login}. Enable Facebook in your app's authentication settings before using.
|
|
187
|
+
* - `'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.
|
|
188
|
+
* - `'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.
|
|
189
|
+
*
|
|
190
|
+
* @param provider - The authentication provider to use: `'google'`, `'microsoft'`, `'facebook'`, `'apple'`, or `'sso'`.
|
|
191
|
+
* @param fromUrl - URL to redirect to after successful authentication. Defaults to `'/'`.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* // Google
|
|
196
|
+
* base44.auth.loginWithProvider('google', window.location.pathname);
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* // Microsoft
|
|
202
|
+
* base44.auth.loginWithProvider('microsoft', '/dashboard');
|
|
203
|
+
* ```
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```typescript
|
|
207
|
+
* // Apple
|
|
208
|
+
* base44.auth.loginWithProvider('apple', '/dashboard');
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```typescript
|
|
213
|
+
* // SSO
|
|
214
|
+
* base44.auth.loginWithProvider('sso', '/dashboard');
|
|
215
|
+
* ```
|
|
216
|
+
*
|
|
217
|
+
*/
|
|
218
|
+
loginWithProvider(provider: string, fromUrl?: string): void;
|
|
219
|
+
/**
|
|
220
|
+
* Logs out the current user.
|
|
221
|
+
*
|
|
222
|
+
* 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.
|
|
223
|
+
*
|
|
224
|
+
* @param redirectUrl - Optional URL to redirect to after logout. Reloads the page if not provided.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* // Logout and reload page
|
|
229
|
+
* base44.auth.logout();
|
|
230
|
+
* ```
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```typescript
|
|
234
|
+
* // Logout and redirect to login page
|
|
235
|
+
* base44.auth.logout('/login');
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```typescript
|
|
240
|
+
* // Logout and redirect to home
|
|
241
|
+
* base44.auth.logout('/');
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
logout(redirectUrl?: string): void;
|
|
245
|
+
/**
|
|
246
|
+
* Sets the authentication token.
|
|
247
|
+
*
|
|
248
|
+
* 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.
|
|
249
|
+
*
|
|
250
|
+
* @param token - JWT authentication token.
|
|
251
|
+
* @param saveToStorage - Whether to save the token to local storage. Defaults to true.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* // Set token and save to local storage
|
|
256
|
+
* base44.auth.setToken('eyJhbGciOiJIUzI1NiIs...');
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* // Set token without saving to local storage
|
|
262
|
+
* base44.auth.setToken('eyJhbGciOiJIUzI1NiIs...', false);
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
setToken(token: string, saveToStorage?: boolean): void;
|
|
266
|
+
/**
|
|
267
|
+
* Logs in a registered user using email and password.
|
|
268
|
+
*
|
|
269
|
+
* 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.
|
|
270
|
+
*
|
|
271
|
+
* @param email - User's email address.
|
|
272
|
+
* @param password - User's password.
|
|
273
|
+
* @param turnstileToken - Optional {@link https://developers.cloudflare.com/turnstile/ | Cloudflare Turnstile CAPTCHA token} for bot protection.
|
|
274
|
+
* @returns Promise resolving to login response with access token and user data.
|
|
275
|
+
* @throws Error if the email and password combination is invalid or the user is not registered.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* // Login with email and password
|
|
280
|
+
* try {
|
|
281
|
+
* const { access_token, user } = await base44.auth.loginViaEmailPassword(
|
|
282
|
+
* 'user@example.com',
|
|
283
|
+
* 'securePassword123'
|
|
284
|
+
* );
|
|
285
|
+
* console.log('Login successful!', user);
|
|
286
|
+
* } catch (error) {
|
|
287
|
+
* console.error('Login failed:', error);
|
|
288
|
+
* }
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* // With captcha token
|
|
294
|
+
* const response = await base44.auth.loginViaEmailPassword(
|
|
295
|
+
* 'user@example.com',
|
|
296
|
+
* 'securePassword123',
|
|
297
|
+
* 'captcha-token-here'
|
|
298
|
+
* );
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
loginViaEmailPassword(email: string, password: string, turnstileToken?: string): Promise<LoginResponse>;
|
|
302
|
+
/**
|
|
303
|
+
* Checks if the current user is authenticated.
|
|
304
|
+
*
|
|
305
|
+
* @returns Promise resolving to true if authenticated, false otherwise.
|
|
306
|
+
*
|
|
307
|
+
* @example
|
|
308
|
+
* ```typescript
|
|
309
|
+
* // Check authentication status
|
|
310
|
+
* const isAuthenticated = await base44.auth.isAuthenticated();
|
|
311
|
+
* if (isAuthenticated) {
|
|
312
|
+
* console.log('User is logged in');
|
|
313
|
+
* } else {
|
|
314
|
+
* // Redirect to login page
|
|
315
|
+
* base44.auth.redirectToLogin(window.location.href);
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
isAuthenticated(): Promise<boolean>;
|
|
320
|
+
/**
|
|
321
|
+
* Invites a user to the app.
|
|
322
|
+
*
|
|
323
|
+
* Sends an invitation email to a potential user with a specific role.
|
|
324
|
+
* Roles are configured in the app settings and determine
|
|
325
|
+
* the user's permissions and access levels.
|
|
326
|
+
*
|
|
327
|
+
* @param userEmail - Email address of the user to invite.
|
|
328
|
+
* @param role - Role to assign to the invited user. Must match a role defined in the app. For example, `'admin'` or `'user'`.
|
|
329
|
+
* @returns Promise that resolves when the invitation is sent successfully. Throws an error if the invitation fails.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* try {
|
|
334
|
+
* await base44.auth.inviteUser('newuser@example.com', 'user');
|
|
335
|
+
* console.log('Invitation sent successfully!');
|
|
336
|
+
* } catch (error) {
|
|
337
|
+
* console.error('Failed to send invitation:', error);
|
|
338
|
+
* }
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
inviteUser(userEmail: string, role: string): Promise<any>;
|
|
342
|
+
/**
|
|
343
|
+
* Registers a new user account.
|
|
344
|
+
*
|
|
345
|
+
* Creates a new user account with email and password. After successful registration,
|
|
346
|
+
* use {@linkcode loginViaEmailPassword | loginViaEmailPassword()} to log in the user.
|
|
347
|
+
*
|
|
348
|
+
* @param params - Registration details including email, password, and optional fields.
|
|
349
|
+
* @returns Promise resolving to the registration response.
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* ```typescript
|
|
353
|
+
* // Register a new user
|
|
354
|
+
* await base44.auth.register({
|
|
355
|
+
* email: 'newuser@example.com',
|
|
356
|
+
* password: 'securePassword123',
|
|
357
|
+
* referral_code: 'FRIEND2024'
|
|
358
|
+
* });
|
|
359
|
+
*
|
|
360
|
+
* // Login after registration
|
|
361
|
+
* const { access_token, user } = await base44.auth.loginViaEmailPassword(
|
|
362
|
+
* 'newuser@example.com',
|
|
363
|
+
* 'securePassword123'
|
|
364
|
+
* );
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
register(params: RegisterParams): Promise<any>;
|
|
368
|
+
/**
|
|
369
|
+
* Verifies an OTP (One-time password) code.
|
|
370
|
+
*
|
|
371
|
+
* Validates an OTP code sent to the user's email during registration
|
|
372
|
+
* or authentication.
|
|
373
|
+
*
|
|
374
|
+
* @param params - Object containing email and OTP code.
|
|
375
|
+
* @returns Promise resolving to the verification response if valid.
|
|
376
|
+
* @throws Error if the OTP code is invalid, expired, or verification fails.
|
|
377
|
+
*
|
|
378
|
+
* @example
|
|
379
|
+
* ```typescript
|
|
380
|
+
* try {
|
|
381
|
+
* await base44.auth.verifyOtp({
|
|
382
|
+
* email: 'user@example.com',
|
|
383
|
+
* otpCode: '123456'
|
|
384
|
+
* });
|
|
385
|
+
* console.log('Email verified successfully!');
|
|
386
|
+
* } catch (error) {
|
|
387
|
+
* console.error('Invalid or expired OTP code');
|
|
388
|
+
* }
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
verifyOtp(params: VerifyOtpParams): Promise<any>;
|
|
392
|
+
/**
|
|
393
|
+
* Resends an OTP code to the user's email address.
|
|
394
|
+
*
|
|
395
|
+
* Requests a new OTP code to be sent to the specified email address.
|
|
396
|
+
*
|
|
397
|
+
* @param email - Email address to send the OTP to.
|
|
398
|
+
* @returns Promise resolving when the OTP is sent successfully.
|
|
399
|
+
* @throws Error if the email is invalid or the request fails.
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* try {
|
|
404
|
+
* await base44.auth.resendOtp('user@example.com');
|
|
405
|
+
* console.log('OTP resent! Please check your email.');
|
|
406
|
+
* } catch (error) {
|
|
407
|
+
* console.error('Failed to resend OTP:', error);
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
resendOtp(email: string): Promise<any>;
|
|
412
|
+
/**
|
|
413
|
+
* Requests a password reset.
|
|
414
|
+
*
|
|
415
|
+
* Sends a password reset email to the specified email address.
|
|
416
|
+
*
|
|
417
|
+
* @param email - Email address for the account to reset.
|
|
418
|
+
* @returns Promise resolving when the password reset email is sent successfully.
|
|
419
|
+
* @throws Error if the email is invalid or the request fails.
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* ```typescript
|
|
423
|
+
* try {
|
|
424
|
+
* await base44.auth.resetPasswordRequest('user@example.com');
|
|
425
|
+
* console.log('Password reset email sent!');
|
|
426
|
+
* } catch (error) {
|
|
427
|
+
* console.error('Failed to send password reset email:', error);
|
|
428
|
+
* }
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
resetPasswordRequest(email: string): Promise<any>;
|
|
432
|
+
/**
|
|
433
|
+
* Resets password using a reset token.
|
|
434
|
+
*
|
|
435
|
+
* Completes the password reset flow by setting a new password
|
|
436
|
+
* using the token received by email.
|
|
437
|
+
*
|
|
438
|
+
* @param params - Object containing the reset token and new password.
|
|
439
|
+
* @returns Promise resolving when the password is reset successfully.
|
|
440
|
+
* @throws Error if the reset token is invalid, expired, or the request fails.
|
|
441
|
+
*
|
|
442
|
+
* @example
|
|
443
|
+
* ```typescript
|
|
444
|
+
* try {
|
|
445
|
+
* await base44.auth.resetPassword({
|
|
446
|
+
* resetToken: 'token-from-email',
|
|
447
|
+
* newPassword: 'newSecurePassword456'
|
|
448
|
+
* });
|
|
449
|
+
* console.log('Password reset successful!');
|
|
450
|
+
* } catch (error) {
|
|
451
|
+
* console.error('Failed to reset password:', error);
|
|
452
|
+
* }
|
|
453
|
+
* ```
|
|
454
|
+
*/
|
|
455
|
+
resetPassword(params: ResetPasswordParams): Promise<any>;
|
|
456
|
+
/**
|
|
457
|
+
* Changes the user's password.
|
|
458
|
+
*
|
|
459
|
+
* Updates the password for an authenticated user by verifying
|
|
460
|
+
* the current password and setting a new one.
|
|
461
|
+
*
|
|
462
|
+
* @param params - Object containing user ID, current password, and new password.
|
|
463
|
+
* @returns Promise resolving when the password is changed successfully.
|
|
464
|
+
* @throws Error if the current password is incorrect or the request fails.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* try {
|
|
469
|
+
* await base44.auth.changePassword({
|
|
470
|
+
* userId: 'user-123',
|
|
471
|
+
* currentPassword: 'oldPassword123',
|
|
472
|
+
* newPassword: 'newSecurePassword456'
|
|
473
|
+
* });
|
|
474
|
+
* console.log('Password changed successfully!');
|
|
475
|
+
* } catch (error) {
|
|
476
|
+
* console.error('Failed to change password:', error);
|
|
477
|
+
* }
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
changePassword(params: ChangePasswordParams): Promise<any>;
|
|
481
|
+
}
|
|
@@ -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;
|