Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .claude/skills/sdk-docs-writing/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ You write JSDoc. The tooling produces the final pages.

| File pattern | Role |
|---|---|
| `src/modules/*.types.ts` | **Public API surface** — JSDoc here becomes the published docs |
| `src/modules/*.ts` | Implementation — mark with `@internal` to hide from docs |
| `src/client.types.ts` | Client factory types |
| `src/types.ts` | Shared types |
| `packages/sdk/src/modules/*.types.ts` | **Public API surface** — JSDoc here becomes the published docs |
| `packages/sdk/src/modules/*.ts` | Implementation — mark with `@internal` to hide from docs |
| `packages/sdk/src/client.types.ts` | Client factory types |
| `packages/sdk/src/types.ts` | Shared types |

Only types and functions **not** marked `@internal` appear in the generated docs. Implementation files should mark their exports `@internal`.

Expand Down Expand Up @@ -93,4 +93,4 @@ Every public method needs: description, `@param` tags, `@returns`, and at least
2. **`@internal` on implementation:** Factory functions, config interfaces, and helpers are marked `@internal`.
3. **Examples work:** Code examples are syntactically valid TypeScript and use the `base44.` call path.
4. **Pipeline config:** New public types are in `types-to-expose.json`. Helper types that belong on another page are in `appended-articles.json`.
5. **Generate and review:** Run `npm run create-docs` and check the output renders correctly.
5. **Generate and review:** Run `npm run create-docs -w @base44/sdk` and check the output renders correctly.
14 changes: 7 additions & 7 deletions .github/workflows/claude-docs-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ on:
pull_request:
types: [opened, synchronize]
paths:
- "src/modules/**"
- "src/client.types.ts"
- "src/types.ts"
- "packages/sdk/src/modules/**"
- "packages/sdk/src/client.types.ts"
- "packages/sdk/src/types.ts"

jobs:
claude-docs-draft:
Expand Down Expand Up @@ -50,9 +50,9 @@ jobs:
## Your task

1. Read the documentation skill file at `.claude/skills/sdk-docs-writing/SKILL.md`. Follow its rules exactly.
2. Look at the changes in this PR (the diff of files under `src/modules/`, `src/client.types.ts`, and `src/types.ts`).
2. Look at the changes in this PR (the diff of files under `packages/sdk/src/modules/`, `packages/sdk/src/client.types.ts`, and `packages/sdk/src/types.ts`).
3. Identify any **new or modified public APIs** (interfaces, types, methods, properties) that are missing JSDoc or have incomplete JSDoc according to the skill's rules.
4. Check the existing `.types.ts` files in `src/modules/` and the generated docs in `docs/content/` to understand the established patterns and voice. Your suggestions must match these patterns.
4. Check the existing `.types.ts` files in `packages/sdk/src/modules/` and the generated docs in `packages/sdk/docs/content/` to understand the established patterns and voice. Your suggestions must match these patterns.

## How to report

Expand All @@ -68,7 +68,7 @@ jobs:

---

#### `src/modules/example.types.ts`
#### `packages/sdk/src/modules/example.types.ts`

**`ExampleModule.myMethod`** — *New method, missing JSDoc entirely.*

Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
- If a public API already has complete, correct JSDoc, skip it — don't suggest changes for the sake of it.

- name: Add docs-draft label
if: success() && fromJSON(steps.claude-docs-drafter.outputs.structured_output).needs_docs == true
if: success() && fromJSON(steps.claude-docs-drafter.outputs.structured_output || '{}').needs_docs == true
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
Expand Down
11 changes: 9 additions & 2 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
env:
PACKAGE_DIR: packages/sdk
permissions:
# contents: write for the version-bump commit, tag, and GitHub Release.
# id-token: write for npm trusted publishing (OIDC).
Expand Down Expand Up @@ -72,7 +74,7 @@ jobs:
run: npm ci

- name: Build package
run: npm run build
run: npm run build -w ${{ env.PACKAGE_DIR }}

- name: Check if version needs to be bumped
id: check-version
Expand All @@ -86,18 +88,21 @@ jobs:
fi

- name: Bump version
working-directory: ${{ env.PACKAGE_DIR }}
if: steps.check-version.outputs.bump_version == 'true'
run: |
npm version ${{ steps.check-version.outputs.version_type }} --no-git-tag-version
echo "NEW_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV

- name: Set version manually
working-directory: ${{ env.PACKAGE_DIR }}
if: steps.check-version.outputs.bump_version == 'false'
run: |
npm version ${{ github.event.inputs.version }} --no-git-tag-version
echo "NEW_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV

- name: Show package info
working-directory: ${{ env.PACKAGE_DIR }}
run: |
echo "Package name: $(node -p "require('./package.json').name")"
echo "Version: ${{ env.NEW_VERSION }}"
Expand All @@ -109,11 +114,13 @@ jobs:
# the build. Needs a trusted publisher for `@base44/sdk` on npmjs.com
# registered against this repo and this workflow filename — the registry
# keys on the filename, so each publish workflow needs its own entry.
working-directory: ${{ env.PACKAGE_DIR }}
if: github.event.inputs.dry_run == 'false'
run: |
npm publish --tag ${{ github.event.inputs.npm_tag }}

- name: Dry run publish
working-directory: ${{ env.PACKAGE_DIR }}
if: github.event.inputs.dry_run == 'true'
run: |
npm publish --dry-run --tag ${{ github.event.inputs.npm_tag }}
Expand All @@ -123,7 +130,7 @@ jobs:
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add package.json package-lock.json
git add ${{ env.PACKAGE_DIR }}/package.json package-lock.json
git commit -m "chore: bump version to ${{ env.NEW_VERSION }}"
git tag v${{ env.NEW_VERSION }}
git push origin HEAD:${{ github.ref }}
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/preview-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ jobs:
run: npm ci

- name: Build package
run: npm run build
run: npm run build -w @base44/sdk

- name: Generate preview package name and version
working-directory: packages/sdk
id: preview_info
run: |
PR_NUMBER="${{ github.event.number }}"
Expand All @@ -70,6 +71,7 @@ jobs:
echo "full_package=@base44-preview/sdk@$PREVIEW_VERSION" >> $GITHUB_OUTPUT

- name: Update package.json for preview
working-directory: packages/sdk
run: |
# Create a backup of original package.json
cp package.json package.json.bak
Expand Down Expand Up @@ -103,6 +105,7 @@ jobs:
echo "✅ Package.json updated successfully"

- name: Final safety check before publish
working-directory: packages/sdk
run: |
# Double-check package name one more time before publishing
CURRENT_PACKAGE_NAME=$(node -p "require('./package.json').name")
Expand All @@ -119,6 +122,7 @@ jobs:
echo "✅ Safety check passed. Package name is safe to publish."

- name: Publish preview package
working-directory: packages/sdk
# Authenticates via npm trusted publishing (OIDC), so no NPM_TOKEN reaches
# the build. Needs a trusted publisher for `@base44-preview/sdk` on
# npmjs.com registered against this repo and this workflow filename — the
Expand All @@ -133,6 +137,7 @@ jobs:
fi

- name: Restore original package.json
working-directory: packages/sdk
if: always()
run: |
if [ -f package.json.bak ]; then
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ jobs:
run: npm ci

- name: Run type tests
run: npm run test:types
run: npm run test:types -w @base44/sdk

- name: Run unit tests
run: npm run test:unit
run: npm run test:unit -w @base44/sdk

151 changes: 8 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,153 +1,18 @@
# Base44 JavaScript SDK
# Base44 JavaScript SDKs

The Base44 SDK provides a JavaScript interface for building apps on the Base44 platform.
| Package | Directory | What it's for |
| :- | :- | :- |
| [`@base44/sdk`](https://www.npmjs.com/package/@base44/sdk) | [`packages/sdk`](packages/sdk) | Apps built on Base44: entities, functions, auth and integrations |

You can use it in two ways:

- **Inside Base44 apps**: When Base44 generates your app, the SDK is already set up and ready to use.
- **External apps**: Use the SDK to build your own frontend or backend that uses Base44 as a backend service.

## Installation

**Inside Base44 apps**: The SDK is already available. No installation needed.

**External apps**: Install the SDK via npm:

```bash
npm install @base44/sdk
```

## Modules

The SDK provides access to Base44's functionality through the following modules:

- **[`agents`](https://docs.base44.com/developers/references/sdk/docs/interfaces/agents)**: Interact with AI agents and manage conversations.
- **[`analytics`](https://docs.base44.com/developers/references/sdk/docs/interfaces/analytics)**: Track custom events in your app.
- **[`app-logs`](https://docs.base44.com/developers/references/sdk/docs/interfaces/app-logs)**: Access and query app logs.
- **[`auth`](https://docs.base44.com/developers/references/sdk/docs/interfaces/auth)**: Manage user authentication, registration, and session handling.
- **[`connectors`](https://docs.base44.com/developers/references/sdk/docs/interfaces/connectors)**: Manage OAuth connections and access tokens for third-party services.
- **[`entities`](https://docs.base44.com/developers/references/sdk/docs/interfaces/entities)**: Work with your app's data entities using CRUD operations.
- **[`functions`](https://docs.base44.com/developers/references/sdk/docs/interfaces/functions)**: Execute backend functions.
- **[`integrations`](https://docs.base44.com/developers/references/sdk/docs/type-aliases/integrations)**: Access pre-built and third-party integrations.

## Quickstarts

How you get started depends on whether you're working inside a Base44-generated app or building your own.

### Inside Base44 apps

In Base44-generated apps, the client is pre-configured. Just import and use it:

```typescript
import { base44 } from "@/api/base44Client";

// Create a new task
const newTask = await base44.entities.Task.create({
title: "Complete project documentation",
status: "pending",
dueDate: "2024-12-31",
});

// Update the task
await base44.entities.Task.update(newTask.id, {
status: "in-progress",
});

// List all tasks
const tasks = await base44.entities.Task.list();
```

### External apps

When using Base44 as a backend for your own app, install the SDK and create the client yourself:

```typescript
import { createClient } from "@base44/sdk";

// Create a client for your Base44 app
const base44 = createClient({
appId: "your-app-id", // Find this in the Base44 editor URL
});

// Read public data
const products = await base44.entities.Products.list();

// Authenticate a user (token is automatically set)
await base44.auth.loginViaEmailPassword("user@example.com", "password");

// Access user's data
const userOrders = await base44.entities.Orders.list();
```

### Service role

By default, the client operates with user-level permissions, limiting access to what the current user can see and do. The service role provides elevated permissions for backend operations and is only available in Base44-hosted backend functions. External backends can't use service role permissions.

```typescript
import { createClientFromRequest } from "npm:@base44/sdk";

Deno.serve(async (req) => {
const base44 = createClientFromRequest(req);

// Access all data with admin-level permissions
const allOrders = await base44.asServiceRole.entities.Orders.list();

return Response.json({ orders: allOrders });
});
```

## Learn more

The best way to get started with the JavaScript SDK is to have Base44 build an app for you. Once you have an app, you can explore the generated code and experiment with the SDK to see how it works in practice. You can also ask Base44 to demonstrate specific features of the SDK.

For a deeper understanding, check out these guides:

1. [Base44 client](https://docs.base44.com/developers/references/sdk/getting-started/client) - Work with the client in frontend, backend, and external app contexts.
2. [Work with data](https://docs.base44.com/developers/references/sdk/getting-started/work-with-data) - Create, read, update, and delete data.
3. [Common SDK patterns](https://docs.base44.com/developers/references/sdk/getting-started/work-with-sdk) - Authentication, integrations, functions, and error handling.

For the complete documentation and API reference, visit the **[Base44 Developer Docs](https://docs.base44.com/developers/home)**.
Each package is versioned and released on its own through the **Manual Package Publish** workflow.

## Development

### Build the SDK

Build the SDK from source:

```bash
npm install
npm ci
npm run build
```

### Run tests

Run the test suite:

```bash
# Run all tests
npm run lint
npm test

# Run unit tests only
npm run test:unit

# Run with coverage
npm run test:coverage
```

For E2E tests, create a `tests/.env` file with:

```
BASE44_APP_ID=your_app_id
BASE44_AUTH_TOKEN=your_auth_token
```

### Generate documentation

Generate API documentation locally:

```bash
# Process and preview locally
npm run create-docs
cd docs
mintlify dev
```
Run a script in one package with `-w`, e.g. `npm run test:unit -w @base44/sdk`.
5 changes: 4 additions & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import tsParser from "@typescript-eslint/parser";

export default [
{
files: ["src/**/*.ts"],
ignores: ["**/dist/**", "**/docs/**"],
},
{
files: ["packages/*/src/**/*.ts"],
languageOptions: {
parser: tsParser,
},
Expand Down
Loading
Loading