WebPush.Subscription (web_push v0.1.0)

Copy Markdown View Source

A browser push subscription: the endpoint plus its encryption keys.

Mirrors what pushManager.subscribe() returns in the browser, flattened for storage. Map your persistence row (Ecto schema, plain map, JSON body) into this struct before calling WebPush.send/3:

%WebPush.Subscription{
  endpoint: row.endpoint,
  p256dh: row.p256dh,
  auth: row.auth
}

Summary

Functions

Builds a subscription from the JSON shape the browser produces ({"endpoint": ..., "keys": {"p256dh": ..., "auth": ...}}), such as a request body posted by your subscribe endpoint.

Types

t()

@type t() :: %WebPush.Subscription{
  auth: String.t(),
  endpoint: String.t(),
  p256dh: String.t()
}

Functions

from_map(arg1)

@spec from_map(map()) :: {:ok, t()} | {:error, :invalid_subscription}

Builds a subscription from the JSON shape the browser produces ({"endpoint": ..., "keys": {"p256dh": ..., "auth": ...}}), such as a request body posted by your subscribe endpoint.

Returns {:error, :invalid_subscription} for any other shape.