-
Notifications
You must be signed in to change notification settings - Fork 417
Add workflows network layer for multipage paywalls #6557
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
Open
vegaro
wants to merge
27
commits into
main
Choose a base branch
from
feat/workflows-network-layer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
10a4c26
Add workflows network layer for multipage paywalls
vegaro 27ba13e
fix xcodeproj
vegaro 76e8094
reset Package.resolved
vegaro 83cc392
Update WorkflowStep models to match actual backend response
vegaro e559dcc
Update WorkflowResponseTests to match updated models
vegaro 7765b6a
Disable file_length lint rule in HTTPRequestPath.swift
vegaro 6ee4a5b
Merge branch 'main' into feat/workflows-network-layer
vegaro 9e3caf8
Fix GetWorkflowOperation to compute result once before distributing t…
vegaro a0339f0
Merge branch 'feat/workflows-network-layer' of github.com:RevenueCat/…
vegaro 12498e8
Fix CDN fetcher: use URLSession instead of Data(contentsOf:), classif…
vegaro 7c082bd
Replace semaphore CDN fetch with async/await using withCheckedThrowin…
vegaro 95b96c7
Make CDN fetcher and processor completion-handler based for consistency
vegaro ef79c3d
Fix ambiguous cache key delimiter in GetWorkflowOperation
vegaro 55db06c
PR comments
vegaro bde2ae6
remove cdn fetcher
vegaro c167f2d
fix response in BackendGetWorkflowsTests.swift
vegaro 36642b1
fix WorkflowResponseTests
vegaro 613aafa
fix error
vegaro 2409291
[skip ci] Generating new test snapshots (#6584)
RCGitBot 8b02381
[skip ci] Generating new test snapshots (#6585)
RCGitBot 243c89e
[skip ci] Generating new test snapshots (#6586)
RCGitBot 89f7f47
[skip ci] Generating new test snapshots (#6587)
RCGitBot 9276217
[skip ci] Generating new test snapshots (#6588)
RCGitBot 7a40c56
[skip ci] Generating new test snapshots (#6589)
RCGitBot ea64ecf
[skip ci] Generating new test snapshots (#6590)
RCGitBot 30001f0
Merge branch 'main' into feat/workflows-network-layer
vegaro e7b8a9f
Test CDN mock is not re-assignable per test
vegaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // | ||
| // Copyright RevenueCat Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the MIT License (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://opensource.org/licenses/MIT | ||
| // | ||
| // WorkflowsCallback.swift | ||
| // | ||
| // Created by RevenueCat. | ||
|
|
||
| import Foundation | ||
|
|
||
| struct WorkflowsListCallback: CacheKeyProviding { | ||
|
|
||
| let cacheKey: String | ||
| let completion: (Result<WorkflowsListResponse, BackendError>) -> Void | ||
|
|
||
| } | ||
|
|
||
| struct WorkflowDetailCallback: CacheKeyProviding { | ||
|
|
||
| let cacheKey: String | ||
| let completion: (Result<WorkflowFetchResult, BackendError>) -> Void | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
Sources/Networking/Operations/GetWorkflowOperation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // | ||
| // Copyright RevenueCat Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the MIT License (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://opensource.org/licenses/MIT | ||
| // | ||
| // GetWorkflowOperation.swift | ||
| // | ||
| // Created by RevenueCat. | ||
|
|
||
| import Foundation | ||
|
|
||
| final class GetWorkflowOperation: CacheableNetworkOperation { | ||
|
|
||
| private let workflowDetailCallbackCache: CallbackCache<WorkflowDetailCallback> | ||
| private let configuration: AppUserConfiguration | ||
| private let workflowId: String | ||
| private let detailProcessor: WorkflowDetailProcessor | ||
|
|
||
| static func createFactory( | ||
| configuration: UserSpecificConfiguration, | ||
| workflowId: String, | ||
| detailProcessor: WorkflowDetailProcessor, | ||
| workflowDetailCallbackCache: CallbackCache<WorkflowDetailCallback> | ||
| ) -> CacheableNetworkOperationFactory<GetWorkflowOperation> { | ||
| return .init({ cacheKey in | ||
| .init( | ||
| configuration: configuration, | ||
| workflowId: workflowId, | ||
| detailProcessor: detailProcessor, | ||
| workflowDetailCallbackCache: workflowDetailCallbackCache, | ||
| cacheKey: cacheKey | ||
| ) | ||
| }, | ||
| individualizedCacheKeyPart: configuration.appUserID + "\n" + workflowId) | ||
| } | ||
|
|
||
| private init(configuration: UserSpecificConfiguration, | ||
| workflowId: String, | ||
| detailProcessor: WorkflowDetailProcessor, | ||
| workflowDetailCallbackCache: CallbackCache<WorkflowDetailCallback>, | ||
| cacheKey: String) { | ||
| self.configuration = configuration | ||
| self.workflowId = workflowId | ||
| self.detailProcessor = detailProcessor | ||
| self.workflowDetailCallbackCache = workflowDetailCallbackCache | ||
|
|
||
| super.init(configuration: configuration, cacheKey: cacheKey) | ||
| } | ||
|
|
||
| override func begin(completion: @escaping () -> Void) { | ||
| self.getWorkflow(completion: completion) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Restating inherited @unchecked Sendable from Foundation's Operation | ||
| extension GetWorkflowOperation: @unchecked Sendable {} | ||
|
|
||
| private extension GetWorkflowOperation { | ||
|
|
||
| func getWorkflow(completion: @escaping () -> Void) { | ||
| let appUserID = self.configuration.appUserID | ||
|
|
||
| guard appUserID.isNotEmpty else { | ||
| self.workflowDetailCallbackCache.performOnAllItemsAndRemoveFromCache(withCacheable: self) { callback in | ||
| callback.completion(.failure(.missingAppUserID())) | ||
| } | ||
| completion() | ||
| return | ||
| } | ||
|
|
||
| let request = HTTPRequest( | ||
| method: .get, | ||
| path: .getWorkflow(appUserID: appUserID, workflowId: self.workflowId) | ||
| ) | ||
|
|
||
| httpClient.perform(request) { (response: VerifiedHTTPResponse<Data>.Result) in | ||
| self.handleResponse(response, completion: completion) | ||
| } | ||
| } | ||
|
|
||
| func handleResponse(_ response: VerifiedHTTPResponse<Data>.Result, completion: @escaping () -> Void) { | ||
| switch response { | ||
| case .failure(let networkError): | ||
| self.workflowDetailCallbackCache.performOnAllItemsAndRemoveFromCache( | ||
| withCacheable: self | ||
| ) { callbackObject in | ||
| callbackObject.completion(.failure(BackendError.networkError(networkError))) | ||
| } | ||
| completion() | ||
|
|
||
| case .success(let verifiedResponse): | ||
| self.detailProcessor.process(verifiedResponse.body) { processingResult in | ||
| self.distribute(self.backendResult(from: processingResult, envelopeData: verifiedResponse.body)) | ||
| completion() | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| func backendResult( | ||
| from processingResult: Result<WorkflowDetailProcessingResult, Error>, | ||
| envelopeData: Data | ||
| ) -> Result<WorkflowFetchResult, BackendError> { | ||
| switch processingResult { | ||
| case .success(let processed): | ||
| do { | ||
| let workflow = try PublishedWorkflow.create(with: processed.workflowData) | ||
| return .success(WorkflowFetchResult(workflow: workflow, enrolledVariants: processed.enrolledVariants)) | ||
| } catch { | ||
| return .failure(BackendError.networkError(NetworkError.decoding(error, envelopeData))) | ||
| } | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| case .failure(WorkflowDetailProcessingError.cdnFetchFailed(let underlyingError)): | ||
| return .failure(BackendError.networkError(NetworkError.networkError(underlyingError))) | ||
| case .failure(let error): | ||
| return .failure(BackendError.networkError(NetworkError.decoding(error, envelopeData))) | ||
| } | ||
| } | ||
|
|
||
| func distribute(_ result: Result<WorkflowFetchResult, BackendError>) { | ||
| self.workflowDetailCallbackCache.performOnAllItemsAndRemoveFromCache( | ||
| withCacheable: self | ||
| ) { callbackObject in | ||
| callbackObject.completion(result) | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| // | ||
| // Copyright RevenueCat Inc. All Rights Reserved. | ||
| // | ||
| // Licensed under the MIT License (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://opensource.org/licenses/MIT | ||
| // | ||
| // GetWorkflowsOperation.swift | ||
| // | ||
| // Created by RevenueCat. | ||
|
|
||
| import Foundation | ||
|
|
||
| final class GetWorkflowsOperation: CacheableNetworkOperation { | ||
|
|
||
| private let workflowsCallbackCache: CallbackCache<WorkflowsListCallback> | ||
| private let configuration: AppUserConfiguration | ||
|
|
||
| static func createFactory( | ||
| configuration: UserSpecificConfiguration, | ||
| workflowsCallbackCache: CallbackCache<WorkflowsListCallback> | ||
| ) -> CacheableNetworkOperationFactory<GetWorkflowsOperation> { | ||
| return .init({ cacheKey in | ||
| .init( | ||
| configuration: configuration, | ||
| workflowsCallbackCache: workflowsCallbackCache, | ||
| cacheKey: cacheKey | ||
| ) | ||
| }, | ||
| individualizedCacheKeyPart: configuration.appUserID) | ||
| } | ||
|
|
||
| private init(configuration: UserSpecificConfiguration, | ||
| workflowsCallbackCache: CallbackCache<WorkflowsListCallback>, | ||
| cacheKey: String) { | ||
| self.configuration = configuration | ||
| self.workflowsCallbackCache = workflowsCallbackCache | ||
|
|
||
| super.init(configuration: configuration, cacheKey: cacheKey) | ||
| } | ||
|
|
||
| override func begin(completion: @escaping () -> Void) { | ||
| self.getWorkflows(completion: completion) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Restating inherited @unchecked Sendable from Foundation's Operation | ||
| extension GetWorkflowsOperation: @unchecked Sendable {} | ||
|
|
||
| private extension GetWorkflowsOperation { | ||
|
|
||
| func getWorkflows(completion: @escaping () -> Void) { | ||
| let appUserID = self.configuration.appUserID | ||
|
|
||
| guard appUserID.isNotEmpty else { | ||
| self.workflowsCallbackCache.performOnAllItemsAndRemoveFromCache(withCacheable: self) { callback in | ||
| callback.completion(.failure(.missingAppUserID())) | ||
| } | ||
| completion() | ||
| return | ||
| } | ||
|
|
||
| let request = HTTPRequest(method: .get, path: .getWorkflows(appUserID: appUserID)) | ||
|
|
||
| httpClient.perform(request) { (response: VerifiedHTTPResponse<WorkflowsListResponse>.Result) in | ||
| defer { | ||
| completion() | ||
| } | ||
|
|
||
| self.workflowsCallbackCache.performOnAllItemsAndRemoveFromCache( | ||
| withCacheable: self | ||
| ) { callbackObject in | ||
| callbackObject.completion(response | ||
| .map { $0.body } | ||
| .mapError(BackendError.networkError) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it deliberate to have
getWorkflowssupportsSignatureVerification--> true whilegetWorkflowisfalse?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the backend only supports signature verification for the endpoint that lists workflows
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to bring it up because it looks like an oversight to me