Skip to main content

lib/coffrify/resources/scim.ex

defmodule Coffrify.Resources.Scim do
  @moduledoc "SCIM 2.0 — user provisioning tokens and audit log (Enterprise plan)."

  alias Coffrify

  @doc "List SCIM tokens."
  @spec list_tokens(Coffrify.t()) :: {:ok, map()} | {:error, Exception.t()}
  def list_tokens(client), do: Coffrify.request(client, :get, "/scim/tokens")

  @doc "Create a SCIM token. Returns the value ONCE."
  @spec create_token(Coffrify.t(), map() | keyword()) :: {:ok, map()} | {:error, Exception.t()}
  def create_token(client, opts), do: Coffrify.request(client, :post, "/scim/tokens", Map.new(opts))

  @doc "Revoke a SCIM token."
  @spec revoke_token(Coffrify.t(), String.t()) :: {:ok, map()} | {:error, Exception.t()}
  def revoke_token(client, id), do: Coffrify.request(client, :delete, "/scim/tokens/#{URI.encode(id)}")

  @doc "Fetch SCIM audit log entries."
  @spec audit(Coffrify.t(), keyword()) :: {:ok, map()} | {:error, Exception.t()}
  def audit(client, opts \\ []) do
    Coffrify.request(client, :get, "/scim/audit", nil, query: opts)
  end
end