Tink.Utils (Tink v1.0.0)

Copy Markdown View Source

Internal utility helpers shared across all Tink API modules.

Not part of the public API surface — subject to change without notice.

Summary

Functions

Standard pagination params from opts.

Build a params map from a keyword list, mapping atom keys to camelCase strings.

Hash a params map to a stable string for use in cache keys.

Poll fetch_fn repeatedly until it returns a response matching done_statuses, or until the deadline is exceeded.

Put value into map under key only when value is not nil.

Put a list as a comma-joined string, only when list is not nil.

A short prefix derived from a client token — used to scope cache keys per user session. Not a security boundary; purely for key namespacing.

Functions

pagination_params(opts)

@spec pagination_params(keyword()) :: map()

Standard pagination params from opts.

params_from_opts(opts, mappings)

@spec params_from_opts(
  keyword(),
  [{atom(), String.t()}]
) :: map()

Build a params map from a keyword list, mapping atom keys to camelCase strings.

params_hash(params)

@spec params_hash(map()) :: String.t()

Hash a params map to a stable string for use in cache keys.

poll_until(fetch_fn, done_statuses, opts \\ [])

@spec poll_until(
  fetch_fn :: (-> {:ok, map()} | {:error, any()}),
  done_statuses :: [String.t()],
  opts :: keyword()
) :: {:ok, map()} | {:error, Tink.Error.t() | :timeout}

Poll fetch_fn repeatedly until it returns a response matching done_statuses, or until the deadline is exceeded.

Returns {:ok, response} on success, {:error, :timeout} on deadline, or {:error, %Tink.Error{}} if the fetch_fn returns an error status.

Options

  • :timeout_ms — max wait time in ms (default: 30_000)
  • :interval_ms — sleep between polls in ms (default: 1_000)
  • :failed_statuses — list of statuses that mean terminal failure (default: ["FAILED", "ERROR"])

put_if_present(map, key, value)

@spec put_if_present(map(), String.t(), any()) :: map()

Put value into map under key only when value is not nil.

put_list_if_present(map, key, list)

@spec put_list_if_present(map(), String.t(), list() | nil) :: map()

Put a list as a comma-joined string, only when list is not nil.

token_prefix(arg1)

@spec token_prefix(Tink.Client.t()) :: String.t()

A short prefix derived from a client token — used to scope cache keys per user session. Not a security boundary; purely for key namespacing.