Skip to content

Commit 9b7759c

Browse files
authored
Merge branch 'trunk' into adborbas/woomob-1611
2 parents f2e5a27 + b86ecd7 commit 9b7759c

File tree

97 files changed

+2868
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2868
-464
lines changed

Modules/Sources/Experiments/DefaultFeatureFlagService.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ public struct DefaultFeatureFlagService: FeatureFlagService {
100100
return buildConfig == .localDeveloper || buildConfig == .alpha
101101
case .pointOfSaleSurveys:
102102
return buildConfig == .localDeveloper || buildConfig == .alpha
103-
case .pointOfSaleSettingsCardReaderFlow:
104-
return buildConfig == .localDeveloper || buildConfig == .alpha
105103
case .pointOfSaleCatalogAPI:
106104
return false
107105
default:

Modules/Sources/Experiments/FeatureFlag.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ public enum FeatureFlag: Int {
208208
///
209209
case pointOfSaleSurveys
210210

211-
/// Enables card reader connection flow within POS settings
212-
///
213-
case pointOfSaleSettingsCardReaderFlow
214-
215211
/// Enables using the catalog API endpoint for Point of Sale catalog full sync
216212
///
217213
case pointOfSaleCatalogAPI

Modules/Sources/Fakes/Networking.generated.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ extension Networking.POSProduct {
812812
attributes: .fake(),
813813
manageStock: .fake(),
814814
stockQuantity: .fake(),
815-
stockStatusKey: .fake()
815+
stockStatusKey: .fake(),
816+
variationIDs: .fake()
816817
)
817818
}
818819
}

Modules/Sources/Fakes/Yosemite.generated.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ extension Yosemite.ProductReviewFromNoteParcel {
7676
)
7777
}
7878
}
79+
extension Yosemite.StoredBookingFilters {
80+
/// Returns a "ready to use" type filled with fake values.
81+
///
82+
public static func fake() -> Yosemite.StoredBookingFilters {
83+
.init(
84+
filters: .fake()
85+
)
86+
}
87+
}
7988
extension Yosemite.SystemInformation {
8089
/// Returns a "ready to use" type filled with fake values.
8190
///

Modules/Sources/Networking/Model/Bookings/Booking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ enum BookingDecodingError: Error {
216216
//
217217

218218
/// Represents a Booking Status.
219-
public enum BookingStatus: String, CaseIterable {
219+
public enum BookingStatus: String, CaseIterable, Codable {
220220
case complete
221221
case paid
222222
case unpaid
@@ -226,7 +226,7 @@ public enum BookingStatus: String, CaseIterable {
226226
case unknown
227227
}
228228

229-
public enum BookingAttendanceStatus: String, CaseIterable {
229+
public enum BookingAttendanceStatus: String, CaseIterable, Codable {
230230
case booked
231231
case checkedIn = "checked-in"
232232
case cancelled

Modules/Sources/Networking/Model/Copiable/Models+Copiable.generated.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ extension Networking.Booking {
436436
allDay: CopiableProp<Bool> = .copy,
437437
cost: CopiableProp<String> = .copy,
438438
customerID: CopiableProp<Int64> = .copy,
439-
dateCreated: CopiableProp<Date> = .copy,
440-
dateModified: CopiableProp<Date> = .copy,
439+
dateCreated: NullableCopiableProp<Date> = .copy,
440+
dateModified: NullableCopiableProp<Date> = .copy,
441441
endDate: CopiableProp<Date> = .copy,
442442
googleCalendarEventID: NullableCopiableProp<String> = .copy,
443443
orderID: CopiableProp<Int64> = .copy,
@@ -1367,7 +1367,8 @@ extension Networking.POSProduct {
13671367
attributes: CopiableProp<[ProductAttribute]> = .copy,
13681368
manageStock: CopiableProp<Bool> = .copy,
13691369
stockQuantity: NullableCopiableProp<Decimal> = .copy,
1370-
stockStatusKey: CopiableProp<String> = .copy
1370+
stockStatusKey: CopiableProp<String> = .copy,
1371+
variationIDs: CopiableProp<[Int64]> = .copy
13711372
) -> Networking.POSProduct {
13721373
let siteID = siteID ?? self.siteID
13731374
let productID = productID ?? self.productID
@@ -1385,6 +1386,7 @@ extension Networking.POSProduct {
13851386
let manageStock = manageStock ?? self.manageStock
13861387
let stockQuantity = stockQuantity ?? self.stockQuantity
13871388
let stockStatusKey = stockStatusKey ?? self.stockStatusKey
1389+
let variationIDs = variationIDs ?? self.variationIDs
13881390

13891391
return Networking.POSProduct(
13901392
siteID: siteID,
@@ -1402,7 +1404,8 @@ extension Networking.POSProduct {
14021404
attributes: attributes,
14031405
manageStock: manageStock,
14041406
stockQuantity: stockQuantity,
1405-
stockStatusKey: stockStatusKey
1407+
stockStatusKey: stockStatusKey,
1408+
variationIDs: variationIDs
14061409
)
14071410
}
14081411
}

Modules/Sources/Networking/Model/POSProduct.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
4343
public let stockQuantity: Decimal?
4444
public let stockStatusKey: String
4545

46+
public let variationIDs: [Int64]
47+
4648
public init(siteID: Int64,
4749
productID: Int64,
4850
name: String,
@@ -58,7 +60,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
5860
attributes: [ProductAttribute],
5961
manageStock: Bool,
6062
stockQuantity: Decimal?,
61-
stockStatusKey: String) {
63+
stockStatusKey: String,
64+
variationIDs: [Int64]) {
6265
self.siteID = siteID
6366
self.productID = productID
6467
self.name = name
@@ -81,6 +84,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
8184
self.manageStock = manageStock
8285
self.stockQuantity = stockQuantity
8386
self.stockStatusKey = stockStatusKey
87+
88+
self.variationIDs = variationIDs
8489
}
8590

8691
public init(from decoder: any Decoder) throws {
@@ -124,6 +129,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
124129
let stockQuantity = container.failsafeDecodeIfPresent(decimalForKey: .stockQuantity)
125130
let stockStatusKey = try container.decode(String.self, forKey: .stockStatusKey)
126131

132+
let variationIDs = try container.decodeIfPresent([Int64].self, forKey: .variationIDs) ?? []
133+
127134
self.init(siteID: siteID,
128135
productID: productID,
129136
name: name,
@@ -139,7 +146,8 @@ public struct POSProduct: Codable, Equatable, GeneratedCopiable, GeneratedFakeab
139146
attributes: attributes,
140147
manageStock: manageStock,
141148
stockQuantity: stockQuantity,
142-
stockStatusKey: stockStatusKey)
149+
stockStatusKey: stockStatusKey,
150+
variationIDs: variationIDs)
143151
}
144152

145153
static let requestFields: [String] = {
@@ -172,5 +180,6 @@ private extension POSProduct {
172180
case manageStock = "manage_stock"
173181
case stockQuantity = "stock_quantity"
174182
case stockStatusKey = "stock_status"
183+
case variationIDs = "variations"
175184
}
176185
}

Modules/Sources/Networking/Model/Site.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
117117
let siteID = try siteContainer.decode(Int64.self, forKey: .siteID)
118118
let name = try siteContainer.decode(String.self, forKey: .name)
119119
let description = try siteContainer.decode(String.self, forKey: .description)
120-
let url = try siteContainer.decode(String.self, forKey: .url)
120+
let url = Self.safeURL(try siteContainer.decode(String.self, forKey: .url))
121121
let capabilitiesContainer = try siteContainer.nestedContainer(keyedBy: CapabilitiesKeys.self, forKey: .capabilities)
122122
let isSiteOwner = try capabilitiesContainer.decode(Bool.self, forKey: .isSiteOwner)
123123
let isAdmin = try capabilitiesContainer.decode(Bool.self, forKey: .isAdmin)
@@ -130,8 +130,8 @@ public struct Site: Decodable, Equatable, Hashable, GeneratedFakeable, Generated
130130
let jetpackConnectionActivePlugins = try optionsContainer.decodeIfPresent([String].self, forKey: .jetpackConnectionActivePlugins) ?? []
131131
let timezone = try optionsContainer.decode(String.self, forKey: .timezone)
132132
let gmtOffset = try optionsContainer.decode(Double.self, forKey: .gmtOffset)
133-
let adminURL = try optionsContainer.decode(String.self, forKey: .adminURL)
134-
let loginURL = try optionsContainer.decode(String.self, forKey: .loginURL)
133+
let adminURL = Self.safeURL(try optionsContainer.decode(String.self, forKey: .adminURL))
134+
let loginURL = Self.safeURL(try optionsContainer.decode(String.self, forKey: .loginURL))
135135
let frameNonce = try optionsContainer.decode(String.self, forKey: .frameNonce)
136136
let canBlaze = optionsContainer.failsafeDecodeIfPresent(booleanForKey: .canBlaze) ?? false
137137
let visibility = optionsContainer.failsafeDecodeIfPresent(SiteVisibility.self, forKey: .visibility) ?? .privateSite
@@ -333,7 +333,8 @@ public enum SiteVisibility: Int, Codable, GeneratedFakeable {
333333
///
334334
public extension Site {
335335

336-
private var jetpackCanonicalURL: String {
336+
/// Force URL to use HTTPS if possible to avoid App Transport Security errors
337+
private static func safeURL(_ url: String) -> String {
337338
guard let originalURL = URL(string: url),
338339
originalURL.scheme?.lowercased() == "http"
339340
else {
@@ -360,7 +361,7 @@ public extension Site {
360361
}
361362

362363
func toJetpackSite() -> JetpackSite {
363-
JetpackSite(siteID: siteID, siteAddress: jetpackCanonicalURL, applicationPasswordAvailable: applicationPasswordAvailable)
364+
JetpackSite(siteID: siteID, siteAddress: url, applicationPasswordAvailable: applicationPasswordAvailable)
364365
}
365366
}
366367

Modules/Sources/Networking/Remote/POSCatalogSyncRemote.swift

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,39 @@ public protocol POSCatalogSyncRemoteProtocol {
3030
/// - Parameters:
3131
/// - siteID: Site ID to generate catalog for.
3232
/// - forceGeneration: Whether to always generate a catalog.
33+
/// - allowCellular: Should cellular data be used if required.
3334
/// - Returns: Catalog job response with job ID.
3435
///
3536
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
36-
func requestCatalogGeneration(for siteID: Int64, forceGeneration: Bool) async throws -> POSCatalogRequestResponse
37+
func requestCatalogGeneration(for siteID: Int64, forceGeneration: Bool, allowCellular: Bool) async throws -> POSCatalogRequestResponse
3738

3839
/// Downloads the generated catalog at the specified download URL.
3940
/// - Parameters:
4041
/// - siteID: Site ID to download catalog for.
4142
/// - downloadURL: Download URL of the catalog file.
43+
/// - allowCellular: Should cellular data be used if required.
4244
/// - Returns: List of products and variations in the POS catalog.
43-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
44-
func downloadCatalog(for siteID: Int64, downloadURL: String) async throws -> POSCatalogResponse
45+
func downloadCatalog(for siteID: Int64,
46+
downloadURL: String,
47+
allowCellular: Bool) async throws -> POSCatalogResponse
4548

4649
/// Loads POS products for full sync.
4750
///
4851
/// - Parameters:
4952
/// - siteID: Site ID to load products from.
5053
/// - pageNumber: Page number for pagination.
54+
/// - allowCellular: Should cellular data be used if required.
5155
/// - Returns: Paginated list of POS products.
52-
func loadProducts(siteID: Int64, pageNumber: Int) async throws -> PagedItems<POSProduct>
56+
func loadProducts(siteID: Int64, pageNumber: Int, allowCellular: Bool) async throws -> PagedItems<POSProduct>
5357

5458
/// Loads POS product variations for full sync.
5559
///
5660
/// - Parameters:
5761
/// - siteID: Site ID to load variations from.
5862
/// - pageNumber: Page number for pagination.
63+
/// - allowCellular: Should cellular data be used if required.
5964
/// - Returns: Paginated list of POS product variations.
60-
func loadProductVariations(siteID: Int64, pageNumber: Int) async throws -> PagedItems<POSProductVariation>
65+
func loadProductVariations(siteID: Int64, pageNumber: Int, allowCellular: Bool) async throws -> PagedItems<POSProductVariation>
6166

6267
/// Gets the total count of products for the specified site.
6368
///
@@ -87,7 +92,6 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
8792
/// - pageNumber: Page number for pagination.
8893
/// - Returns: Paginated list of POS products.
8994
///
90-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
9195
public func loadProducts(modifiedAfter: Date, siteID: Int64, pageNumber: Int)
9296
async throws -> PagedItems<POSProduct> {
9397
let path = Path.products
@@ -120,7 +124,6 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
120124
/// - pageNumber: Page number for pagination.
121125
/// - Returns: Paginated list of POS product variations.
122126
///
123-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
124127
public func loadProductVariations(modifiedAfter: Date, siteID: Int64, pageNumber: Int) async throws -> PagedItems<POSProductVariation> {
125128
let path = Path.variations
126129
let parameters = [
@@ -131,7 +134,7 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
131134
]
132135

133136
let request = JetpackRequest(
134-
wooApiVersion: .wcAnalytics,
137+
wooApiVersion: .mark3,
135138
method: .get,
136139
siteID: siteID,
137140
path: path,
@@ -151,10 +154,11 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
151154
///
152155
/// - Parameters:
153156
/// - siteID: Site ID to generate catalog for.
157+
/// - forceGeneration: Whether to always generate a catalog.
158+
/// - allowCellular: Should cellular data be used if required.
154159
/// - Returns: Catalog job response with job ID.
155160
///
156-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
157-
public func requestCatalogGeneration(for siteID: Int64, forceGeneration: Bool) async throws -> POSCatalogRequestResponse {
161+
public func requestCatalogGeneration(for siteID: Int64, forceGeneration: Bool, allowCellular: Bool) async throws -> POSCatalogRequestResponse {
158162
let path = "products/catalog"
159163
let parameters: [String: Any] = [
160164
ParameterKey.fullSyncFields: POSProduct.requestFields,
@@ -166,7 +170,8 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
166170
siteID: siteID,
167171
path: path,
168172
parameters: parameters,
169-
availableAsRESTRequest: true
173+
availableAsRESTRequest: true,
174+
allowsCellularAccess: allowCellular
170175
)
171176
let mapper = SingleItemMapper<POSCatalogRequestResponse>(siteID: siteID)
172177
return try await enqueue(request, mapper: mapper)
@@ -176,14 +181,17 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
176181
/// - Parameters:
177182
/// - siteID: Site ID to download catalog for.
178183
/// - downloadURL: Download URL of the catalog file.
184+
/// - allowCellular: Should cellular data be used if required.
179185
/// - Returns: List of products and variations in the POS catalog.
180-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
181-
public func downloadCatalog(for siteID: Int64, downloadURL: String) async throws -> POSCatalogResponse {
186+
public func downloadCatalog(for siteID: Int64,
187+
downloadURL: String,
188+
allowCellular: Bool) async throws -> POSCatalogResponse {
182189
// TODO: WOOMOB-1173 - move download task to the background using `URLSessionConfiguration.background`
183190
guard let url = URL(string: downloadURL) else {
184191
throw NetworkError.invalidURL
185192
}
186-
let request = URLRequest(url: url)
193+
var request = URLRequest(url: url)
194+
request.allowsCellularAccess = allowCellular
187195
let mapper = ListMapper<POSProduct>(siteID: siteID)
188196
let items = try await enqueue(request, mapper: mapper)
189197
let variationProductTypeKey = "variation"
@@ -198,10 +206,10 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
198206
/// - Parameters:
199207
/// - siteID: Site ID to load products from.
200208
/// - pageNumber: Page number for pagination.
209+
/// - allowCellular: Should cellular data be used if required.
201210
/// - Returns: Paginated list of POS products.
202211
///
203-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
204-
public func loadProducts(siteID: Int64, pageNumber: Int) async throws -> PagedItems<POSProduct> {
212+
public func loadProducts(siteID: Int64, pageNumber: Int, allowCellular: Bool) async throws -> PagedItems<POSProduct> {
205213
let path = Path.products
206214
let parameters = [
207215
ParameterKey.page: String(pageNumber),
@@ -215,7 +223,8 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
215223
siteID: siteID,
216224
path: path,
217225
parameters: parameters,
218-
availableAsRESTRequest: true
226+
availableAsRESTRequest: true,
227+
allowsCellularAccess: allowCellular
219228
)
220229
let mapper = ListMapper<POSProduct>(siteID: siteID)
221230
let (products, responseHeaders) = try await enqueueWithResponseHeaders(request, mapper: mapper)
@@ -228,10 +237,10 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
228237
/// - Parameters:
229238
/// - siteID: Site ID to load variations from.
230239
/// - pageNumber: Page number for pagination.
240+
/// - allowCellular: Should cellular data be used if required.
231241
/// - Returns: Paginated list of POS product variations.
232242
///
233-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
234-
public func loadProductVariations(siteID: Int64, pageNumber: Int) async throws -> PagedItems<POSProductVariation> {
243+
public func loadProductVariations(siteID: Int64, pageNumber: Int, allowCellular: Bool) async throws -> PagedItems<POSProductVariation> {
235244
let path = Path.variations
236245
let parameters = [
237246
ParameterKey.page: String(pageNumber),
@@ -240,12 +249,13 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
240249
]
241250

242251
let request = JetpackRequest(
243-
wooApiVersion: .wcAnalytics,
252+
wooApiVersion: .mark3,
244253
method: .get,
245254
siteID: siteID,
246255
path: path,
247256
parameters: parameters,
248-
availableAsRESTRequest: true
257+
availableAsRESTRequest: true,
258+
allowsCellularAccess: allowCellular
249259
)
250260
let mapper = ListMapper<POSProductVariation>(siteID: siteID)
251261
let (variations, responseHeaders) = try await enqueueWithResponseHeaders(request, mapper: mapper)
@@ -293,7 +303,7 @@ public class POSCatalogSyncRemote: Remote, POSCatalogSyncRemoteProtocol {
293303
]
294304

295305
let request = JetpackRequest(
296-
wooApiVersion: .wcAnalytics,
306+
wooApiVersion: .mark3,
297307
method: .get,
298308
siteID: siteID,
299309
path: path,
@@ -331,7 +341,6 @@ private extension POSCatalogSyncRemote {
331341
// MARK: - Response Models
332342

333343
/// Response from catalog generation request.
334-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
335344
public struct POSCatalogRequestResponse: Decodable {
336345
/// Current status of the catalog generation job.
337346
public let status: POSCatalogStatus
@@ -353,7 +362,6 @@ public enum POSCatalogStatus: String, Decodable {
353362
}
354363

355364
/// POS catalog from download.
356-
// periphery:ignore - TODO - remove this periphery ignore comment when this endpoint is integrated with catalog sync
357365
public struct POSCatalogResponse {
358366
public let products: [POSProduct]
359367
public let variations: [POSProductVariation]

0 commit comments

Comments
 (0)