Skip to content

Commit 4905d38

Browse files
Added missing documentation throughout the package
1 parent 1757d6b commit 4905d38

15 files changed

+40
-3
lines changed

Package.swift

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ let package = Package(
1616
.library(name: "WebPushTesting", targets: ["WebPush", "WebPushTesting"]),
1717
],
1818
dependencies: [
19+
/// Core dependency that allows us to sign Authorization tokens and encrypt push messages per subscriber before delivery.
1920
.package(url: "https://github.com/apple/swift-crypto.git", "3.10.0"..<"5.0.0"),
21+
/// Logging integration allowing runtime API missuse warnings and push status tracing.
2022
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"),
21-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.77.0"),
22-
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.24.0"),
23+
/// Service lifecycle integration for clean shutdowns in a server environment.
2324
.package(url: "https://github.com/swift-server/swift-service-lifecycle.git", from: "2.6.2"),
25+
/// Internal dependency allowing push message delivery over HTTP/2.
26+
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.24.0"),
27+
/// Internal dependency for event loop coordination and shared HTTP types.
28+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.77.0"),
2429
],
2530
targets: [
2631
.target(

Sources/WebPush/Errors/BadSubscriberError.swift

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Foundation
1212
///
1313
/// - Warning: Do not continue to send notifications to invalid subscriptions or you'll risk being rate limited by push services.
1414
public struct BadSubscriberError: LocalizedError, Hashable, Sendable {
15+
/// Create a new bad subscriber error.
1516
public init() {}
1617

1718
public var errorDescription: String? {

Sources/WebPush/Errors/Base64URLDecodingError.swift

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010

1111
/// An error encountered while decoding Base64 data.
1212
public struct Base64URLDecodingError: LocalizedError, Hashable, Sendable {
13+
/// Create a new base 64 decoding error.
1314
public init() {}
1415

1516
public var errorDescription: String? {

Sources/WebPush/Errors/HTTPError.swift

+4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ import Foundation
1515
/// - SeeAlso: [RFC 8292 Voluntary Application Server Identification (VAPID) for Web Push](https://datatracker.ietf.org/doc/html/rfc8292)
1616
/// - SeeAlso: [Sending web push notifications in web apps and browsers — Review responses for push notification errors](https://developer.apple.com/documentation/usernotifications/sending-web-push-notifications-in-web-apps-and-browsers#Review-responses-for-push-notification-errors)
1717
public struct HTTPError: LocalizedError, Sendable {
18+
/// The HTTP response that was returned from the push service..
1819
public let response: HTTPClientResponse
20+
21+
/// A cached description from the response that won't change over the lifetime of the error.
1922
let capturedResponseDescription: String
2023

24+
/// Create a new http error.
2125
public init(response: HTTPClientResponse) {
2226
self.response = response
2327
self.capturedResponseDescription = "\(response)"

Sources/WebPush/Errors/MessageTooLargeError.swift

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Foundation
1212
///
1313
/// - SeeAlso: ``WebPushManager/maximumMessageSize``
1414
public struct MessageTooLargeError: LocalizedError, Hashable, Sendable {
15+
/// Create a new message too large error.
1516
public init() {}
1617

1718
public var errorDescription: String? {

Sources/WebPush/Errors/UserAgentKeyMaterialError.swift

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ import Foundation
1010

1111
/// An error encountered during ``VAPID/Configuration`` initialization or decoding.
1212
public struct UserAgentKeyMaterialError: LocalizedError, Sendable {
13+
/// The kind of error that occured.
1314
enum Kind {
15+
/// The public key was invalid.
1416
case invalidPublicKey
17+
/// The authentication secret was invalid.
1518
case invalidAuthenticationSecret
1619
}
1720

21+
/// The kind of error that occured.
1822
var kind: Kind
19-
var underlyingError: any Error
23+
24+
/// The underlying error that caused this one.
25+
public var underlyingError: any Error
2026

2127
/// The public key was invalid.
2228
public static func invalidPublicKey(underlyingError: Error) -> Self {

Sources/WebPush/Errors/VAPIDConfigurationError.swift

+4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ import Foundation
1111
extension VAPID {
1212
/// An error encountered during ``VAPID/Configuration`` initialization or decoding.
1313
public struct ConfigurationError: LocalizedError, Hashable, Sendable {
14+
/// The kind of error that occured.
1415
enum Kind {
16+
/// VAPID keys not found during initialization.
1517
case keysNotProvided
18+
/// A VAPID key for the subscriber was not found.
1619
case matchingKeyNotFound
1720
}
1821

22+
/// The kind of error that occured.
1923
var kind: Kind
2024

2125
/// VAPID keys not found during initialization.

Sources/WebPush/Helpers/DataProtocol+Base64URLCoding.swift

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010

1111
extension DataProtocol {
12+
/// The receiver as a Base64 URL encoded string.
1213
@_disfavoredOverload
1314
@usableFromInline
1415
func base64URLEncodedString() -> String {
@@ -21,6 +22,7 @@ extension DataProtocol {
2122
}
2223

2324
extension ContiguousBytes {
25+
/// The receiver as a Base64 URL encoded string.
2426
@usableFromInline
2527
func base64URLEncodedString() -> String {
2628
withUnsafeBytes { bytes in
@@ -30,6 +32,7 @@ extension ContiguousBytes {
3032
}
3133

3234
extension DataProtocol where Self: RangeReplaceableCollection {
35+
/// Initialize data using a Base64 URL encoded string.
3336
@usableFromInline
3437
init?(base64URLEncoded string: some StringProtocol) {
3538
var base64String = string.replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")

Sources/WebPush/Helpers/HTTPClientProtocol.swift

+3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import AsyncHTTPClient
1010
import Logging
1111
import NIOCore
1212

13+
/// A protocol abstracting HTTP request execution.
1314
package protocol HTTPClientProtocol: Sendable {
15+
/// Execute the request.
1416
func execute(
1517
_ request: HTTPClientRequest,
1618
deadline: NIODeadline,
1719
logger: Logger?
1820
) async throws -> HTTPClientResponse
1921

22+
/// Shuts down the client.
2023
func syncShutdown() throws
2124
}
2225

Sources/WebPush/Helpers/PrintLogHandler.swift

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010
import Logging
1111

12+
/// A simple log handler that uses formatted print statements.
1213
package struct PrintLogHandler: LogHandler {
1314
private let label: String
1415

Sources/WebPush/VAPID/VAPID.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010

11+
/// The fully qualified name for VAPID.
1112
public typealias VoluntaryApplicationServerIdentification = VAPID
1213

1314
/// A set of types for Voluntary Application Server Identification, also known as VAPID.

Sources/WebPush/VAPID/VAPIDConfiguration.swift

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ extension VoluntaryApplicationServerIdentification {
157157
}
158158

159159
extension VAPID.Configuration: Codable {
160+
/// The coding keys used to encode a VAPID configuration.
160161
public enum CodingKeys: CodingKey {
161162
case primaryKey
162163
case keys
@@ -220,6 +221,7 @@ extension VAPID.Configuration {
220221
/// An email-based contact method.
221222
case email(String)
222223

224+
/// The string that representa the contact information as a fully-qualified URL.
223225
var urlString: String {
224226
switch self {
225227
case .url(let url): url.absoluteURL.absoluteString

Sources/WebPush/VAPID/VAPIDKey.swift

+2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ extension VAPID.Key: Identifiable {
6868
///
6969
/// - SeeAlso: [Push API Working Draft §7.2. `PushSubscriptionOptions` Interface](https://www.w3.org/TR/push-api/#pushsubscriptionoptions-interface)
7070
public struct ID: Hashable, Comparable, Codable, Sendable, CustomStringConvertible {
71+
/// The raw string that represents the ID.
7172
private var rawValue: String
7273

74+
/// Initialize an ID with a raw string.
7375
init(_ rawValue: String) {
7476
self.rawValue = rawValue
7577
}

Sources/WebPush/VAPID/VAPIDToken.swift

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ extension VAPID {
1616
/// - SeeAlso: [RFC 7515 JSON Web Signature (JWS)](https://datatracker.ietf.org/doc/html/rfc7515)
1717
///- SeeAlso: [RFC 7519 JSON Web Token (JWT)](https://datatracker.ietf.org/doc/html/rfc7519)
1818
struct Token: Hashable, Codable, Sendable {
19+
/// The coding keys used to encode the token.
1920
enum CodingKeys: String, CodingKey {
2021
case audience = "aud"
2122
case subject = "sub"
@@ -118,6 +119,7 @@ extension VAPID {
118119
}
119120

120121
protocol VAPIDKeyProtocol: Identifiable, Sendable {
122+
/// The signature type used by this key.
121123
associatedtype Signature: ContiguousBytes
122124

123125
/// Returns a JWS signature for the message.

Sources/WebPush/WebPushManager.swift

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public actor WebPushManager: Sendable {
134134
self.executor = executor
135135
}
136136

137+
/// Shutdown the client if it hasn't already been stopped.
137138
deinit {
138139
if !didShutdown, case let .httpClient(httpClient, _) = executor {
139140
try? httpClient.syncShutdown()

0 commit comments

Comments
 (0)