Skip to content

Athena::MercureBundle::Schema#

Represents the possible properties used to configure and customize the Mercure integration. See the Getting Started docs for more information on how the bundle system works in Athena.

A full example showing all properties is as follows:

ADI.configure({
  mercure: {
    hubs: {
      default: {
        url:        "https://internal-hub/.well-known/mercure",
        public_url: "https://hub.example.com/.well-known/mercure",
        jwt:        {
          # Provide *secret* to generate JWTs dynamically via a token factory...
          secret:     "my-jwt-secret",
          publish:    ["*"],
          subscribe:  ["https://example.com/books/{id}"],
          algorithm:  :hs256,
          passphrase: "",

          # ...or provide *value* to use a static JWT token directly.
          # value: "eyJhbGciOiJIUzI1NiJ9...",
        },
      },
    },
    default_hub:             "default",
    default_cookie_lifetime: 1.hour,
  },
})

Configuration Properties

hubs#

type:

Hash(K, V)

default:

{__nil: nil}

Named Mercure hub definitions. Each hub requires a url and jwt configuration.

This property consists of a map of key/value pairs where each value has the following properties:

url#

type:

String

Required

The internal URL used by the server to publish updates to this hub. Should be set via ENV var.


public_url#

type:

String | ::Nil

default:

nil

The public URL exposed to clients via the Link header for hub discovery. Falls back to url if not set. Useful when the internal hub URL differs from the one clients should connect to. Should be set via ENV var.


jwt#

type:

JWT

Required

JWT configuration for authenticating with a Mercure hub. Provide either secret to generate tokens dynamically, or value to use a static token.

This property consists of an object with the following properties:

secret#
type:

String | ::Nil

default:

nil

The secret key used to sign JWTs. Required when generating tokens dynamically via a AMC::TokenFactory::JWT (i.e. when value is not set). Should be set via ENV var.


publish#
type:

Array(String)

default:

[] of String

Topic selectors that the generated JWT grants publish access to. Included in the JWT's mercure.publish claim.


subscribe#
type:

Array(String)

default:

[] of String

Topic selectors that the generated JWT grants subscribe access to. Included in the JWT's mercure.subscribe claim.


algorithm#
type:

::JWT::Algorithm

default:

hs256

The signing algorithm used to encode the JWT.


passphrase#
type:

String

Required

Passphrase for the secret key, if the algorithm requires one (e.g. RSA).


value#
type:

String | ::Nil

default:

nil

A pre-built static JWT token string provided via AMC::TokenProvider::Static. When set, the token is used as-is and secret, algorithm, and passphrase are ignored.


default_hub#

type:

String | ::Nil

default:

nil

The name of the hub to use when none is specified. Defaults to the first defined hub if not explicitly set.


type:

Time::Span

default:

1.hour

Default lifetime for authorization cookies set via ABM::Authorization.