Executor
An internal type representing the executor for a push message.
enum Executor
An internal type representing the executor for a push message.
enum Executor
import WebPush
actor WebPushManager
A manager for sending push messages to subscribers.
case httpClient(any HTTPClientProtocol, KeyProvider)
Use an HTTP client and optional private key to send an encrypted payload to a subscriber.
case handler((_ message: _Message, _ subscriber: Subscriber, _ topic: Topic?, _ expiration: Expiration, _ urgency: Urgency) async throws -> Void)
Use a handler to capture the original message.
convenience init(vapidConfiguration: VAPID.Configuration, networkConfiguration: NetworkConfiguration = .default, backgroundActivityLogger: Logger? = .defaultWebPushPrintLogger, eventLoopGroupProvider: NIOEventLoopGroupProvider = .shared(.singletonMultiThreadedEventLoopGroup))
Initialize a manager with a VAPID configuration.
init(vapidConfiguration: VAPID.Configuration, networkConfiguration: NetworkConfiguration = .default, backgroundActivityLogger: Logger, executor: Executor, skipClientShutdown: Bool = false)
Internal method to install a different executor for mocking.
convenience init(vapidConfiguration: VAPID.Configuration, networkConfiguration: NetworkConfiguration = .default, backgroundActivityLogger: Logger? = .defaultWebPushPrintLogger, unsafeHTTPClient: HTTPClient)
Initialize a manager with an unsafe HTTP Client.
static let maximumEncryptedPayloadSize: Int
The maximum encrypted payload size guaranteed by the spec.
static let maximumMessageSize: Int
The maximum message size allowed.
static let messageEncoder: JSONEncoder
The encoder used when serializing JSON messages.
nonisolated let networkConfiguration: NetworkConfiguration
The network configuration used when configuring the manager.
nonisolated var nextVAPIDKeyID: VAPID.Key.ID { get }
Request a VAPID key to supply to the client when requesting a new subscription.
nonisolated let vapidConfiguration: VAPID.Configuration
The VAPID configuration used when configuring the manager.
nonisolated func checkMessageSize(data message: some DataProtocol) throws(MessageTooLargeError)
Check to see if a message is potentially too large to be sent to a push service.
nonisolated func checkMessageSize(json message: some Encodable & Sendable) throws
Check to see if a message is potentially too large to be sent to a push service.
nonisolated func checkMessageSize<Contents>(notification: PushMessage.Notification<Contents>) throws where Contents : Encodable, Contents : Sendable
Check to see if a message is potentially too large to be sent to a push service.
nonisolated func checkMessageSize(string message: some StringProtocol) throws(MessageTooLargeError)
Check to see if a message is potentially too large to be sent to a push service.
nonisolated func keyStatus(for keyID: VAPID.Key.ID) -> VAPID.Configuration.KeyStatus
Check the status of a key against the current configuration.
func run() async throws
func send(data message: some DataProtocol, to subscriber: some SubscriberProtocol, deduplicationTopic topic: Topic? = nil, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as raw data.
func send(data message: some DataProtocol, to subscriber: some SubscriberProtocol, encodableDeduplicationTopic: some Encodable, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as raw data.
func send(json message: some Encodable & Sendable, to subscriber: some SubscriberProtocol, deduplicationTopic topic: Topic? = nil, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as encoded JSON.
func send(json message: some Encodable & Sendable, to subscriber: some SubscriberProtocol, encodableDeduplicationTopic: some Encodable, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as encoded JSON.
func send<Contents>(notification: PushMessage.Notification<Contents>, to subscriber: some SubscriberProtocol, deduplicationTopic topic: Topic? = nil, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws where Contents : Encodable, Contents : Sendable
Send a push notification.
func send<Contents>(notification: PushMessage.Notification<Contents>, to subscriber: some SubscriberProtocol, encodableDeduplicationTopic: some Encodable, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws where Contents : Encodable, Contents : Sendable
Send a push notification.
func send(string message: some StringProtocol, to subscriber: some SubscriberProtocol, deduplicationTopic topic: Topic? = nil, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as a string.
func send(string message: some StringProtocol, to subscriber: some SubscriberProtocol, encodableDeduplicationTopic: some Encodable, expiration: Expiration = .recommendedMaximum, urgency: Urgency = .high, logger: Logger? = nil) async throws
Send a push message as a string.
struct Expiration
A duration in seconds used to express when push messages will expire.
struct NetworkConfiguration
The network configuration for a web push manager.
struct Urgency
The urgency with which to deliver a push message.
enum _Message
An internal type representing a push message, accessible when using WebPushTesting
.
protocol Sendable
static func httpClient(_ httpClient: any HTTPClientProtocol) -> WebPushManager.Executor
Use an HTTP client to send an encrypted payload to a subscriber.
enum KeyProvider
A Private Key and Shared Secret provider.