# `Alternera.Plugins.Sqs.Client`
[🔗](https://github.com/10e-ab/alternera-sqs/blob/v0.9.0/lib/alternera/plugins/sqs/client.ex#L1)

The calls an SQS step makes, for `Alternera.Plugins.Sqs`. SQS's
JSON protocol: every call is a `POST /` to the queue URL's origin with
`Content-Type: application/x-amz-json-1.0`, the action in
`X-Amz-Target: AmazonSQS.<Action>` and the queue URL in the JSON body:

  * send: `SendMessage` with `MessageBody`, `MessageAttributes`,
    `MessageGroupId`, `MessageDeduplicationId` and `DelaySeconds`,
    answered with its `MessageId`;
  * receive: `ReceiveMessage` with `MaxNumberOfMessages`,
    `WaitTimeSeconds` and `VisibilityTimeout`, answered with
    `{"Messages": [...]}`, empty or left out when none came; with
    immediate deletes, `DeleteMessageBatch` with an entry per message;
  * delete: `DeleteMessage` with the `ReceiptHandle`;
  * release: `ChangeMessageVisibility` with the `ReceiptHandle` and its
    `VisibilityTimeout`;
  * counts: `GetQueueAttributes` with the three
    `ApproximateNumberOf…` names, answered with an `Attributes` object
    of strings.

Each call is signed with AWS Signature Version 4 (`Sqs.SigV4`) over its
`content-type`, `host`, `x-amz-date` and `x-amz-target` headers and its
body, with the access key id and the secret the step reveals
(`Plugin.Secret.reveal/3`), and goes out through
`Plugin.Provisional.Outbound` as the step's proxy user, its recording
redacted. A forward pipeline of that proxy user that changes one of
those headers or the body breaks the signature, and SQS answers `403`.
The calls end `call_reserve_ms/1` before the step's own time, so a slow
queue fails the step `timeout` with its call recorded rather than the
runner stopping it.

# `answer`

```elixir
@spec answer(tuple(), String.t()) :: {:ok, term()} | {:error, String.t(), String.t()}
```

An outbound call's result for `action`, read: `{:ok, answer}`, the
answer's decoded JSON (nil when empty), or the call's failure, a status
outside 2xx (`http_status`, with SQS's error) or an answer that is not
JSON (`invalid_response`).

# `batch_failures`

```elixir
@spec batch_failures(term()) :: %{required(String.t()) =&gt; String.t()}
```

The entries a batch call's answer (its decoded JSON) says SQS refused, by
their `Id`, each as `"<code>: <message>"`; none when it names none.

# `batch_successes`

```elixir
@spec batch_successes(term()) :: MapSet.t(String.t())
```

The `Id`s of the entries a batch call's answer (its decoded JSON) says
SQS settled; none when it names none.

# `call_reserve_ms`

```elixir
@spec call_reserve_ms(non_neg_integer()) :: non_neg_integer()
```

How long before the step's time is up its calls must be done.

# `check_queue_url`

```elixir
@spec check_queue_url(String.t()) :: {:ok, String.t()} | {:error, String.t()}
```

`url` as a queue URL: `http` or `https`, a host, a path naming the queue,
no query or fragment; `{:error, message}` otherwise.

# `delay_seconds`

```elixir
@spec delay_seconds(String.t()) :: {:ok, non_neg_integer()} | {:error, String.t()}
```

A release's `delay` as whole seconds within `visibility_timeout_s`'s
range: `{:ok, seconds}` or `{:error, message}`, a message that names
the editor's box and not the value. `Sqs.init/1` checks a literal one
with it, the run one a template resolved to.

# `fifo?`

```elixir
@spec fifo?(String.t()) :: boolean()
```

Whether `queue_url` names a FIFO queue: its name ends in `.fifo`, as SQS
requires of one.

# `fingerprint`

```elixir
@spec fingerprint(map(), map()) :: String.t()
```

The fingerprint of a resolved call: the operation, action, endpoint,
body (a receive's wait time, which is cut to the time left, left out)
and proxy user, so a dry run and the real run of the same call agree.
The date and the signature are not part of it.

# `integer`

```elixir
@spec integer(term()) :: integer() | nil
```

`value`, a whole number SQS sent as a number or as digits, or nil.

# `queue_name`

```elixir
@spec queue_name(String.t()) :: String.t()
```

The queue's name: the last segment of its URL, or the URL as it is.

# `raw_messages`

```elixir
@spec raw_messages(term()) :: {:ok, [map()]} | {:error, String.t()}
```

The messages of a `ReceiveMessage` answer (its decoded JSON, nil when
empty), as SQS sent them: none when it carries none, `{:error, message}`
(a fragment after "SQS's answer to a receive") when it is not a list of
messages each with an id and a receipt handle.

# `region_of`

```elixir
@spec region_of(String.t()) :: String.t() | nil
```

The region an AWS queue URL's host names, or nil.

# `reveal_secret`

```elixir
@spec reveal_secret(map(), String.t()) ::
  {:ok, Alternera.Plugin.Secret.t()} | {:error, String.t(), String.t()}
```

The secret access key `reference` names, revealed for `context` (whose
`reveal_keys` hold `secret_access_key`), or `auth_failed`.

# `run`

```elixir
@spec run(Alternera.Plugin.Inputs.t(), map(), map()) :: tuple()
```

Runs the step's operation: `call/3`'s result.

# `settle_region`

```elixir
@spec settle_region(String.t() | nil, String.t()) ::
  {:ok, String.t()} | {:error, String.t(), String.t()}
```

The region a call to `queue_url` is signed for: `given` when it is set,
else the one an AWS queue URL's host names; `invalid_config` when
neither names one.

# `signed_request`

```elixir
@spec signed_request(String.t(), map(), map()) :: map()
```

The request for `action` with the JSON `fields` on `target`'s queue
(`%{queue_url:, region:, access_key_id:, secret:}`, the secret revealed),
signed now, as `Plugin.Provisional.Outbound.call/3` takes it. The queue
URL goes into the body as every call's does. `Sqs.Source` calls it; a
step builds its calls from its inputs (`run/3`).

# `would_call`

```elixir
@spec would_call(Alternera.Plugin.Inputs.t(), map(), map()) :: map()
```

What a preview says the step would do: the call, as whom and its
fingerprint, with nothing sent and no secret revealed. A setting that
does not resolve is named in place of the call.

---

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