Bunnyx.EdgeScript (Bunnyx v0.3.0)

Copy Markdown View Source

Edge scripting — deploy and manage JavaScript/TypeScript code at the edge.

Uses the main API client created with Bunnyx.new/1.

Usage

client = Bunnyx.new(api_key: "sk-...")

{:ok, script} = Bunnyx.EdgeScript.create(client, name: "my-script", script_type: 1)
{:ok, nil} = Bunnyx.EdgeScript.set_code(client, script["Id"], "export default { fetch() {} }")
{:ok, scripts} = Bunnyx.EdgeScript.list(client)

Summary

Functions

Adds a secret to an edge script.

Adds a variable to an edge script. Returns the created variable with its ID.

Creates an edge script.

Deletes an edge script.

Deletes a secret from an edge script.

Deletes a variable from an edge script.

Fetches an edge script by ID.

Returns the active release for an edge script.

Returns the current code for an edge script.

Gets a variable by ID.

Lists edge scripts.

Lists published releases for an edge script.

Lists secrets for an edge script.

Publishes a release for an edge script.

Rotates the deployment key for an edge script.

Sets the code for an edge script.

Returns statistics for an edge script.

Updates an edge script.

Updates an existing secret.

Updates an existing variable.

Adds or updates a secret (upsert).

Adds or updates a variable (upsert).

Functions

add_secret(client, id, name, secret)

@spec add_secret(Bunnyx.t() | keyword(), pos_integer(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Adds a secret to an edge script.

add_variable(client, id, attrs)

@spec add_variable(Bunnyx.t() | keyword(), pos_integer(), Bunnyx.Params.attrs()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Adds a variable to an edge script. Returns the created variable with its ID.

create(client, attrs)

@spec create(Bunnyx.t() | keyword(), Bunnyx.Params.attrs()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Creates an edge script.

Attributes

  • :name — script name (max 100 chars)
  • :script_type (required) — 0 = DNS, 1 = CDN, 2 = Middleware
  • :code — initial code
  • :create_linked_pull_zone — auto-create a linked pull zone
  • :linked_pull_zone_name — name for the linked pull zone

delete(client, id)

@spec delete(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes an edge script.

delete_secret(client, id, secret_id)

@spec delete_secret(Bunnyx.t() | keyword(), pos_integer(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a secret from an edge script.

delete_variable(client, id, variable_id)

@spec delete_variable(Bunnyx.t() | keyword(), pos_integer(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Deletes a variable from an edge script.

get(client, id)

@spec get(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Fetches an edge script by ID.

get_active_release(client, id)

@spec get_active_release(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns the active release for an edge script.

get_code(client, id)

@spec get_code(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns the current code for an edge script.

get_variable(client, id, variable_id)

@spec get_variable(Bunnyx.t() | keyword(), pos_integer(), pos_integer()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Gets a variable by ID.

list(client, opts \\ [])

@spec list(
  Bunnyx.t() | keyword(),
  keyword()
) ::
  {:ok,
   %{
     items: [map()],
     current_page: integer(),
     total_items: integer(),
     has_more_items: boolean()
   }}
  | {:error, Bunnyx.Error.t()}

Lists edge scripts.

Options

  • :page — page number
  • :per_page — items per page
  • :search — search term
  • :type — filter by script type (0 = DNS, 1 = CDN, 2 = Middleware)

list_releases(client, id, opts \\ [])

@spec list_releases(Bunnyx.t() | keyword(), pos_integer(), keyword()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Lists published releases for an edge script.

list_secrets(client, id)

@spec list_secrets(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, list()} | {:error, Bunnyx.Error.t()}

Lists secrets for an edge script.

publish_release(client, id, opts \\ [])

@spec publish_release(Bunnyx.t() | keyword(), pos_integer(), keyword()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Publishes a release for an edge script.

Options

  • :note — release note
  • :uuid — specific release UUID to publish

rotate_deployment_key(client, id)

@spec rotate_deployment_key(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Rotates the deployment key for an edge script.

set_code(client, id, code)

@spec set_code(Bunnyx.t() | keyword(), pos_integer(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Sets the code for an edge script.

statistics(client, id)

@spec statistics(Bunnyx.t() | keyword(), pos_integer()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Returns statistics for an edge script.

update(client, id, attrs)

@spec update(Bunnyx.t() | keyword(), pos_integer(), Bunnyx.Params.attrs()) ::
  {:ok, map()} | {:error, Bunnyx.Error.t()}

Updates an edge script.

update_secret(client, id, name, secret)

@spec update_secret(Bunnyx.t() | keyword(), pos_integer(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Updates an existing secret.

update_variable(client, id, variable_id, attrs)

@spec update_variable(
  Bunnyx.t() | keyword(),
  pos_integer(),
  pos_integer(),
  Bunnyx.Params.attrs()
) :: {:ok, nil} | {:error, Bunnyx.Error.t()}

Updates an existing variable.

upsert_secret(client, id, name, secret)

@spec upsert_secret(Bunnyx.t() | keyword(), pos_integer(), String.t(), String.t()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Adds or updates a secret (upsert).

upsert_variable(client, id, attrs)

@spec upsert_variable(Bunnyx.t() | keyword(), pos_integer(), Bunnyx.Params.attrs()) ::
  {:ok, nil} | {:error, Bunnyx.Error.t()}

Adds or updates a variable (upsert).