Skip to content

Commit

Permalink
Create new PassKit product
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jun 26, 2024
1 parent a4a814f commit 42367dd
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
12 changes: 10 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.macOS(.v13), .iOS(.v16)
],
products: [
.library(name: "Passes", targets: ["Passes"]),
.library(name: "Passes", targets: ["PassKit", "Passes"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.102.0"),
Expand All @@ -17,7 +17,7 @@ let package = Package(
],
targets: [
.target(
name: "Passes",
name: "PassKit",
dependencies: [
.product(name: "Fluent", package: "fluent"),
.product(name: "Vapor", package: "vapor"),
Expand All @@ -26,9 +26,17 @@ let package = Package(
],
swiftSettings: swiftSettings
),
.target(
name: "Passes",
dependencies: [
.target(name: "PassKit"),
],
swiftSettings: swiftSettings
),
.testTarget(
name: "PassKitTests",
dependencies: [
.target(name: "PassKit"),
.target(name: "Passes"),
.product(name: "XCTVapor", package: "vapor"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@

import Vapor

struct ErrorLogDTO: Content {
let logs: [String]
package struct ErrorLogDTO: Content {
package let logs: [String]
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@

import Vapor

struct RegistrationDTO: Content {
let pushToken: String
package struct RegistrationDTO: Content {
package let pushToken: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
/// THE SOFTWARE.

// This is a temporary fix until RoutesBuilder and EmptyPayload are not Sendable
struct FakeSendable<T>: @unchecked Sendable {
let value: T
package struct FakeSendable<T>: @unchecked Sendable {
package let value: T

package init(value: T) {
self.value = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import Foundation

extension URL {
func unixPath() -> String {
package func unixPath() -> String {
absoluteString.replacingOccurrences(of: "file://", with: "")
}
}
13 changes: 7 additions & 6 deletions Sources/Passes/Passes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import VaporAPNS
@preconcurrency import APNSCore
import Fluent
import NIOSSL
import PassKit

/// The main class that handles PassKit passes.
public final class Passes: Sendable {
Expand Down Expand Up @@ -156,19 +157,19 @@ public final class PassesCustom<P, D, R: PassKitRegistration, E: PassKitErrorLog
/// ```
///
/// - Parameter middleware: The `Middleware` which will control authentication for the routes.
/// - Throws: An error of type `PassKitError`
/// - Throws: An error of type `PassesError`
public func registerPushRoutes(middleware: any Middleware) throws {
let privateKeyPath = URL(fileURLWithPath: delegate.pemPrivateKey, relativeTo:
delegate.sslSigningFilesDirectory).unixPath()

guard FileManager.default.fileExists(atPath: privateKeyPath) else {
throw PassKitError.pemPrivateKeyMissing
throw PassesError.pemPrivateKeyMissing
}

let pemPath = URL(fileURLWithPath: delegate.pemCertificate, relativeTo: delegate.sslSigningFilesDirectory).unixPath()

guard FileManager.default.fileExists(atPath: privateKeyPath) else {
throw PassKitError.pemCertificateMissing
throw PassesError.pemCertificateMissing
}

// PassKit *only* works with the production APNs. You can't pass in .sandbox here.
Expand Down Expand Up @@ -487,7 +488,7 @@ public final class PassesCustom<P, D, R: PassKitRegistration, E: PassKitErrorLog
let sslBinary = delegate.sslBinary

guard FileManager.default.fileExists(atPath: sslBinary.unixPath()) else {
throw PassKitError.opensslBinaryMissing
throw PassesError.opensslBinaryMissing
}

let proc = Process()
Expand Down Expand Up @@ -516,7 +517,7 @@ public final class PassesCustom<P, D, R: PassKitRegistration, E: PassKitErrorLog
private func zip(directory: URL, to: URL) throws {
let zipBinary = delegate.zipBinary
guard FileManager.default.fileExists(atPath: zipBinary.unixPath()) else {
throw PassKitError.zipBinaryMissing
throw PassesError.zipBinaryMissing
}

let proc = Process()
Expand All @@ -537,7 +538,7 @@ public final class PassesCustom<P, D, R: PassKitRegistration, E: PassKitErrorLog

let src = try await delegate.template(for: pass, db: db)
guard (try? src.resourceValues(forKeys: [.isDirectoryKey]).isDirectory) ?? false else {
throw PassKitError.templateNotDirectory
throw PassesError.templateNotDirectory
}

let encoded = try await self.delegate.encode(pass: pass, db: db, encoder: encoder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//
// File.swift
// PassesError.swift
//
//
// Created by Scott Grosch on 1/22/20.
//

import Foundation

public enum PassKitError: Error {
public enum PassesError: Error {
/// The template path is not a directory
case templateNotDirectory

Expand Down

0 comments on commit 42367dd

Please sign in to comment.