You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+67-4Lines changed: 67 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,21 @@
1
1
# Base44 JavaScript SDK
2
2
3
-
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform. When Base44 generates your app, the generated code uses the SDK to authenticate users, manage your app's data, interact with AI agents, and more. You can then use the same SDK to modify and extend your app.
3
+
The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
4
+
5
+
You can use it in two ways:
6
+
7
+
-**Inside Base44 apps**: When Base44 generates your app, the SDK is already set up and ready to use.
8
+
-**External apps**: Use the SDK to build your own frontend or backend that uses Base44 as a backend service.
9
+
10
+
## Installation
11
+
12
+
Install the SDK via npm:
13
+
14
+
```bash
15
+
npm install @base44/sdk
16
+
```
17
+
18
+
> **Note**: In Base44-generated apps, the SDK is already installed for you.
4
19
5
20
## Modules
6
21
@@ -12,11 +27,15 @@ The SDK provides access to Base44's functionality through the following modules:
12
27
-**[`connectors`](https://docs.base44.com/sdk-docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
13
28
-**[`entities`](https://docs.base44.com/sdk-docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
-**[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built server-side functions for external services.
30
+
-**[`integrations`](https://docs.base44.com/sdk-docs/type-aliases/integrations)**: Pre-built integrations for external services.
16
31
17
-
## Example
32
+
## Quick starts
18
33
19
-
Here's a quick look at working with data in the SDK, using the `entities` module to create, update, and list records. In this example, we're working with a custom `Task` entity:
34
+
How you get started depends on your context:
35
+
36
+
### Inside a Base44 app
37
+
38
+
In Base44-generated apps, the client is pre-configured. Just import and use it:
* This is the main entry point for the Base44 SDK. It creates a client that provides access to the SDK's modules, such as {@linkcode EntitiesModule | entities}, {@linkcode AuthModule | auth}, and {@linkcode FunctionsModule | functions}.
27
27
*
28
-
* Typically, you don't need to call this function because Base44 creates the client for you. You can then import and use the client to make API calls. The client takes care of managing authentication for you.
28
+
* How you get a client depends on your context:
29
+
* - **Inside a Base44 app:** The client is automatically created and configured for you. Import it from `@/api/base44Client`.
30
+
* - **External app using Base44 as a backend:** Call `createClient()` directly in your code to create and configure the client.
29
31
*
30
32
* The client supports three authentication modes:
31
-
* - **Anonymous**: Access modules anonymously without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
32
-
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions.
33
-
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Can only be used in the backend. Typically, you create a client with service role authentication using the {@linkcode createClientFromRequest | createClientFromRequest()} function in your backend functions.
33
+
* - **Anonymous**: Access modules without authentication using `base44.moduleName`. Operations are scoped to public data and permissions.
34
+
* - **User authentication**: Access modules with user-level permissions using `base44.moduleName`. Operations are scoped to the authenticated user's data and permissions. Use `base44.auth.loginViaEmailPassword()` or other auth methods to get a token.
35
+
* - **Service role authentication**: Access modules with elevated permissions using `base44.asServiceRole.moduleName`. Operations can access any data available to the app's admin. Only available in Base44-hosted backend functions. Create a client with service role authentication using {@linkcode createClientFromRequest | createClientFromRequest()}.
34
36
*
35
37
* For example, when using the {@linkcode EntitiesModule | entities} module:
36
38
* - **Anonymous**: Can only read public data.
@@ -265,7 +267,7 @@ export function createClient(config: CreateClientConfig): Base44Client {
265
267
/**
266
268
* Provides access to service role modules.
267
269
*
268
-
* Service role authentication provides elevated permissions for server-side operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
270
+
* Service role authentication provides elevated permissions for backend operations. Unlike user authentication, which is scoped to a specific user's permissions, service role authentication has access to the data and operations available to the app's admin.
269
271
*
270
272
* @throws {Error} When accessed without providing a serviceToken during client creation.
271
273
*
@@ -296,7 +298,9 @@ export function createClient(config: CreateClientConfig): Base44Client {
296
298
/**
297
299
* Creates a Base44 client from an HTTP request.
298
300
*
299
-
* The client is created by automatically extracting authentication tokens from a request to a backend function. Base44 inserts the necessary headers when forwarding requests to backend functions.
301
+
* This function is designed for use in Base44-hosted backend functions. For frontends and external backends, use {@linkcode createClient | createClient()} instead.
302
+
*
303
+
* When used in a Base44-hosted backend function, `createClientFromRequest()` automatically extracts authentication tokens from the request headers that Base44 injects when forwarding requests. The returned client includes service role access using `base44.asServiceRole`, which provides admin-level permissions.
300
304
*
301
305
* To learn more about the Base44 client, see {@linkcode createClient | createClient()}.
* User authentication token. Used to authenticate as a specific user.
44
+
*
45
+
* Inside Base44 apps, the token is managed automatically. For external apps, use auth methods like {@linkcode AuthModule.loginViaEmailPassword | loginViaEmailPassword()} which set the token automatically.
44
46
*/
45
47
token?: string;
46
48
/**
47
-
* Service role authentication token. Use this in the backend when you need elevated permissions to access data available to the app's admin or perform admin operations. This token should be kept secret and never exposed in the app's frontend. Typically, you get this token from a request to a backend function using {@linkcode createClientFromRequest | createClientFromRequest()}.
49
+
* Service role authentication token. Provides elevated permissions to access data available to the app's admin. Only available in Base44-hosted backend functions. Automatically added to client's created using {@linkcode createClientFromRequest | createClientFromRequest()}.
0 commit comments