# `KapsoEx.Functions`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/functions.ex#L1)

[Functions](https://docs.kapso.ai/docs/functions/overview): serverless
JavaScript deployed by Kapso, invoked over the API or from workflows.

# `result`

```elixir
@type result() :: {:ok, term()} | {:error, KapsoEx.Error.t()}
```

# `create`

```elixir
@spec create(KapsoEx.Client.t(), map() | keyword()) :: result()
```

Creates a draft function (not deployed yet).

Attributes: `name`, `code` and `function_type` (`"cloudflare_worker"` or
`"supabase_function"`) are required; also `slug`, `description`,
`public_endpoint`, `runtime_config`.

# `create_secret`

```elixir
@spec create_secret(KapsoEx.Client.t(), String.t(), String.t(), String.t() | map()) ::
  result()
```

Creates a secret, exposed to the function as an environment variable.

# `delete`

```elixir
@spec delete(KapsoEx.Client.t(), String.t()) :: result()
```

Deletes a function, its deployment and its secrets.

# `delete_secret`

```elixir
@spec delete_secret(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Deletes a secret.

# `deploy`

```elixir
@spec deploy(KapsoEx.Client.t(), String.t()) :: result()
```

Deploys a function in the background (usually 10-60 seconds). Poll `get/2` for the status.

# `get`

```elixir
@spec get(KapsoEx.Client.t(), String.t()) :: result()
```

Gets a function with its code, deployment status and URLs.

# `invoke`

```elixir
@spec invoke(KapsoEx.Client.t(), String.t(), map() | list()) :: result()
```

Invokes a deployed function with `payload` as the request body. Returns
the function's response (JSON decoded when it is JSON).

# `list`

```elixir
@spec list(KapsoEx.Client.t()) :: result()
```

Lists the project's functions.

# `list_invocations`

```elixir
@spec list_invocations(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Lists recent invocations with captured console logs. Params: `status`, `limit`.

# `list_secrets`

```elixir
@spec list_secrets(KapsoEx.Client.t(), String.t()) :: result()
```

Lists secret names (never values).

# `update`

```elixir
@spec update(KapsoEx.Client.t(), String.t(), map() | keyword()) :: result()
```

Updates a function (partial). Attributes: `name`, `slug`, `description`,
`code`, `invoke_response_mode`, `runtime_config`, `public_endpoint`, and
`lock_version` for optimistic locking.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
