Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for Strict Concurrency #5

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ let package = Package(
.library(name: "PassKit", targets: ["PassKit"]),
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.92.4"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.92.5"),
.package(url: "https://github.com/vapor/fluent.git", from: "4.9.0"),
.package(url: "https://github.com/vapor/apns.git", from: "4.0.0"),
.package(url: "https://github.com/vapor/apns.git", from: "4.1.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.5.4")
],
targets: [
Expand Down Expand Up @@ -46,6 +46,6 @@ var swiftSettings: [SwiftSetting] { [
.enableUpcomingFeature("ConciseMagicFile"),
.enableUpcomingFeature("ForwardTrailingClosures"),
.enableUpcomingFeature("DisableOutwardActorInference"),
// .enableUpcomingFeature("StrictConcurrency"),
// .enableExperimentalFeature("StrictConcurrency=complete"),
.enableUpcomingFeature("StrictConcurrency"),
.enableExperimentalFeature("StrictConcurrency=complete"),
] }
35 changes: 18 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,37 +119,38 @@ struct PassJsonData: Encodable {

Create a delegate file that implements `PassKitDelegate`.
In the `sslSigningFilesDirectory` you specify there must be the `WWDR.pem`, `passcertificate.pem` and `passkey.pem` files. If they are named like that you're good to go, otherwise you have to specify the custom name.
Obtaining the three certificates files could be a bit tricky, you could get some guidance from [this guide](https://github.com/alexandercerutti/passkit-generator/wiki/Generating-Certificates) and [this video](https://www.youtube.com/watch?v=rJZdPoXHtzI).
There are other fields available which have reasonable default values. See the delegate's documentation.
Because the files for your pass' template and the method of encoding might vary by pass type, you'll be provided the pass for those methods.

```swift
import Vapor
import Fluent
import PassKit

class PKD: PassKitDelegate {
var sslSigningFilesDirectory = URL(fileURLWithPath: "/www/myapp/sign", isDirectory: true)
final class PKDelegate: PassKitDelegate {
let sslSigningFilesDirectory = URL(fileURLWithPath: "/www/myapp/sign", isDirectory: true)

var pemPrivateKeyPassword: String? = Environment.get("PEM_PRIVATE_KEY_PASSWORD")!
let pemPrivateKeyPassword: String? = Environment.get("PEM_PRIVATE_KEY_PASSWORD")!

func encode<P: PassKitPass>(pass: P, db: Database, encoder: JSONEncoder) -> EventLoopFuture<Data> {
func encode<P: PassKitPass>(pass: P, db: Database, encoder: JSONEncoder) async throws -> Data {
// The specific PassData class you use here may vary based on the pass.type if you have multiple
// different types of passes, and thus multiple types of pass data.
return PassData.query(on: db)
.filter(\.$pass == pass.id!)
guard let passData = try await PassData.query(on: db)
.filter(\.$pass.$id == pass.id!)
.first()
.unwrap(or: Abort(.internalServerError))
.flatMap { passData in
guard let data = try? encoder.encode(PassJsonData(data: passData, pass: pass)) else {
return db.eventLoop.makeFailedFuture(Abort(.internalServerError))
}
return db.eventLoop.makeSucceededFuture(data)
else {
throw Abort(.internalServerError)
}
guard let data = try? encoder.encode(PassJsonData(data: passData, pass: pass)) else {
throw Abort(.internalServerError)
}
return data
}

func template<P: PassKitPass>(for: P, db: Database) -> EventLoopFuture<URL> {
func template<P: PassKitPass>(for: P, db: Database) async throws -> URL {
// The location might vary depending on the type of pass.
let url = URL(fileURLWithPath: "/www/myapp/pass", isDirectory: true)
return db.eventLoop.makeSucceededFuture(url)
return URL(fileURLWithPath: "/www/myapp/pass", isDirectory: true)
}
}
```
Expand All @@ -163,7 +164,7 @@ a global variable. You need to ensure that the delegate doesn't go out of scope
This will implement all of the routes that PassKit expects to exist on your server for you.

```swift
let delegate = PKD()
let delegate = PKDelegate()

func routes(_ app: Application) throws {
let pk = PassKit(app: app, delegate: delegate)
Expand Down Expand Up @@ -294,7 +295,7 @@ fileprivate func passHandler(_ req: Request) async throws -> Response {
throw Abort(.notFound)
}

let bundle = try await passKit.generatePassContent(for: passData.pass, on: req.db).get()
let bundle = try await passKit.generatePassContent(for: passData.pass, on: req.db)
let body = Response.Body(data: bundle)
var headers = HTTPHeaders()
headers.add(name: .contentType, value: "application/vnd.apple.pkpass")
Expand Down
34 changes: 34 additions & 0 deletions Sources/PassKit/FakeSendable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/// Copyright 2020 Gargoyle Software, LLC
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy
/// of this software and associated documentation files (the "Software"), to deal
/// in the Software without restriction, including without limitation the rights
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
/// copies of the Software, and to permit persons to whom the Software is
/// furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in
/// all copies or substantial portions of the Software.
///
/// Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
/// distribute, sublicense, create a derivative work, and/or sell copies of the
/// Software in any work that is designed, intended, or marketed for pedagogical or
/// instructional purposes related to programming, coding, application development,
/// or information technology. Permission for such use, copying, modification,
/// merger, publication, distribution, sublicensing, creation of derivative works,
/// or sale is expressly withheld.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
/// THE SOFTWARE.

import Foundation
fpseverino marked this conversation as resolved.
Show resolved Hide resolved

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