biff.misc

Functions that don't have enough siblings for their own library.

assoc-url

(assoc-url url & kvs)
Adds query parameters to a URL.

generate-secret

(generate-secret n-bytes)
Generates a base64 string from the given number of random bytes.

jwt-decrypt

(jwt-decrypt token secret)
TODO add docstring

jwt-encrypt

(jwt-encrypt claims secret)
TODO add docstring

malli-registry

(malli-registry registry)
Returns registry combined with the default registry.

parse-form-tx

(parse-form-tx {:keys [biff.reitit/get-router], {:keys [tx-info], :as params} :params, :as req} {:keys [coercions]})
Gets a Biff transaction from a form POST.

Returns a tuple of Biff transaction, redirect path. See
https://biff.findka.com/#receiving-transactions.

get-router: A function returning a Reitit router.
tx-info:    A map serialized as EDN.
coercions:  A map from keywords (field types) to coercion functions, e.g.
            {:text identity, :checkbox #(= % "on")}.

tx-info has the following keys:
:tx           - A Biff transaction, with symbols (corresponding to field
                names) marking where field values should be inserted, e.g.
                {[:foo "abc"] {:foo/text 'text-field}}
:fields       - A map from symbols to field types, e.g. {'text-field :text}
:redirect     - The name of a Reitit route (a keyword). The route must have
                :biff/redirect true for redirects to be authorized.
:path-params,
:query-params - Maps used by Reitit to resolve the redirect path.

send-mailgun

(send-mailgun #:mailgun{:keys [api-key endpoint from]} opts)
Sends an email with Mailgun.

use-jetty

(use-jetty {:biff/keys [host port handler], :biff.jetty/keys [quiet websockets], :or {host "localhost", port 8080}, :as sys})
Starts a Jetty web server.

websockets: A map from paths to handlers, e.g. {"/api/chsk" ...}.

use-nrepl

(use-nrepl {:keys [biff.nrepl/port biff.nrepl/quiet], :as sys})
Starts an nREPL server.

no-op if port is nil/false.

use-reitit

(use-reitit {:biff.reitit/keys [routes default-handlers mode], :keys [biff/on-error], :as sys})
Sets :biff/handler from Reitit routes.

Also sets :biff.reitit/get-router to a function that returns the router.

routes,
default-handlers: Passed to Reitit.
on-error:         A handler that takes a request with :status set to one of
                  #{404 405 406}. Added to default-handlers.
mode:             If set to :dev, the routes will be re-compiled on each
                  request. routes is passed to biff.util/realize, so it can
                  be a var or a zero-arg function.

use-sente

(use-sente {:keys [biff.sente/adapter biff.sente/event-handler biff.sente/route biff.reitit/routes], :or {adapter (sente-jetty/get-sch-adapter), route "/api/chsk"}, :as sys})
Starts a Sente channel socket and event router, and adds a Reitit route.

The keys returned by sente/make-channel-socket! are prefixed with biff.sente
and added to the system map.