def send.signed

bend-kit-webhooks@0.11.0.1 · webhooks.bend:456

import bend-kit-webhooks@0.11.0.1/webhooks.bend as Webhooks
import Base
import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import bend-kit-hairpin@0.13.0.1/hairpin.bend as Hairpin
import bend-kit-retry@0.2.0.0/retry.bend as Retry
import bend-kit-http@0.38.1.1/http.bend as Http

456# Receivers deduplicate on the event ID, so the POST is safe to repeat.
457def send.signed(c: Hairpin.Client, b: Retry.Budget, +url: String, r: Bytes.Bytes & Result<&1, &1, Err, Map<&2, List<&2, String>>>) ->
458    IO(Hairpin.Client & Retry.Budget & Result<&1, &1, SendErr, Http.Res>):
459  (body, signed) = r
460  match signed:
461    case Fail{e}:
462      IO.pure(Hairpin.Client & Retry.Budget & Result<&1, &1, SendErr, Http.Res>, (c, b, Fail{SendSign{e}}))
463    case Done{+h}:
464      do IO<Hairpin.Client & Retry.Budget & Result<&1, &1, SendErr, Http.Res>>:
465        enc : String <- Http.codings()
466        x : Hairpin.Client & Retry.Budget & Result<&1, &1, Hairpin.Err, Http.Res> <-
467          Hairpin.request.as(~send.judge, Hairpin.redirect(c, Http.ModeManual{}), b, True{}, enc, "POST", url,
468            Http.set(h, "content-type", "application/json"), body)
469        return send.result(x)

Uses (24)

Used by (1)