# scribase functions

Manages the edge functions of a hosted environment through the management API.
Every deploy is a new immutable version; the runtime boots it once and makes it
active only if the boot succeeds, so a broken deploy never replaces a working
one.

## Usage

```sh
scribase functions list     <org> <project> <env>
scribase functions deploy   <org> <project> <env> <name> <dir|file> [--import-map FILE]
scribase functions get      <org> <project> <env> <name> [--version N]
scribase functions logs     <org> <project> <env> <name> [--limit N]
scribase functions invoke   <org> <project> <env> <name> [--data JSON | --data-file FILE]
scribase functions rollback <org> <project> <env> <name> <version>
scribase functions delete   <org> <project> <env> <name>
```

## Deploying

Point `deploy` at a function directory or a single entrypoint file:

- **Directory** — `index.ts` is the entrypoint. Every module beside it and in
  its subdirectories (`.ts`, `.tsx`, `.js`, `.jsx`, `.mjs`, `.mts`, `.json`) is
  sent with it. Hidden entries, `node_modules`, `tests` and `__tests__` are
  skipped. An `import_map.json` in the directory is used as the import map.
- **File** — the file becomes the function's `index.ts`.

`--import-map FILE` uses an import map from anywhere on disk. A deploy may
contain at most 64 modules and 2 MiB of source.

```sh
scribase functions deploy acme store production hello ./functions/hello
```

The environment's secrets are bound into the function at deploy time and kept
current afterwards. See [`scribase secrets`](https://docs.scribase.com/docs/cli/secrets.md).

## Options

| Flag | Applies to | Description |
|---|---|---|
| `--import-map` | `deploy` | Path to an import map JSON file |
| `--version` | `get` | Show the source of a retained earlier version |
| `--limit` | `logs` | Number of lines, 1-200 (default 100) |
| `--data` | `invoke` | JSON payload sent to the function |
| `--data-file` | `invoke` | Read the JSON payload from a file (up to 1 MiB) |

## Logs

`logs` returns the newest lines first. They include one line per invocation
(method, path, status and duration), deploy and rollback markers, and the
function's own `console.*` output, uncaught exceptions and limit terminations.

```sh
scribase functions logs acme store production hello --limit 50
```

## Rolling back

The runtime keeps the 20 most recent versions. `get` lists them; `rollback`
makes an earlier one active again without redeploying:

```sh
scribase functions get acme store production hello
scribase functions rollback acme store production hello 4
```
