@blueid/access-capacitor 0.90.0 → 0.92.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/dist/esm/BlueCore_pb.d.ts +29 -0
  2. package/dist/esm/BlueCore_pb.js +33 -0
  3. package/dist/esm/BlueCore_pb.js.map +1 -1
  4. package/dist/plugin.cjs.js +35 -0
  5. package/dist/plugin.cjs.js.map +1 -1
  6. package/dist/plugin.js +35 -0
  7. package/dist/plugin.js.map +1 -1
  8. package/ios/CBlueIDAccess.xcframework/Info.plist +6 -6
  9. package/ios/CBlueIDAccess.xcframework/ios-arm64/Headers/core/BlueCore.pb.h +35 -5
  10. package/ios/CBlueIDAccess.xcframework/ios-arm64/libCBlueIDAccess.a +0 -0
  11. package/ios/CBlueIDAccess.xcframework/ios-arm64_x86_64-simulator/Headers/core/BlueCore.pb.h +35 -5
  12. package/ios/CBlueIDAccess.xcframework/ios-arm64_x86_64-simulator/libCBlueIDAccess.a +0 -0
  13. package/ios/CBlueIDAccess.xcframework/macos-arm64_x86_64/Headers/core/BlueCore.pb.h +35 -5
  14. package/ios/CBlueIDAccess.xcframework/macos-arm64_x86_64/libCBlueIDAccess.a +0 -0
  15. package/ios/Plugin/BlueIDAccessSDK/BlueAPI.swift +8 -1
  16. package/ios/Plugin/BlueIDAccessSDK/BlueAccess.swift +78 -63
  17. package/ios/Plugin/BlueIDAccessSDK/BlueAccessEventService.swift +98 -0
  18. package/ios/Plugin/BlueIDAccessSDK/BlueAccessEventServiceProtocol.swift +5 -0
  19. package/ios/Plugin/BlueIDAccessSDK/BlueAccessSync.swift +9 -9
  20. package/ios/Plugin/BlueIDAccessSDK/BlueCommands.swift +24 -20
  21. package/ios/Plugin/BlueIDAccessSDK/BlueCore.pb.swift +105 -0
  22. package/ios/Plugin/BlueIDAccessSDK/BlueDeviceBluetooth.swift +6 -0
  23. package/ios/Plugin/BlueIDAccessSDK/BlueNetworkMonitorService.swift +26 -0
  24. package/ios/Plugin/BlueIDAccessSDK/BlueOssSo.swift +9 -9
  25. package/ios/Plugin/BlueIDAccessSDK/BlueSdkService.swift +18 -0
  26. package/ios/Plugin/BlueIDAccessSDK/BlueTerminal.swift +2 -2
  27. package/package.json +1 -1
@@ -6,7 +6,7 @@ internal let blueAccessAuthenticationTokensKeyChain = BlueKeychain(attrService:
6
6
  internal let blueAccessDevicesStorage = BlueStorage(collection: "blueid.accessDevices")
7
7
  internal let blueAccessOssSettingsKeyChain = BlueKeychain(attrService: "blueid.accessOssSettings")
8
8
 
9
- public class BlueAddAccessCredentialCommand: BlueAPIAsyncCommand {
9
+ public class BlueAddAccessCredentialCommand: BlueSdkAsyncCommand {
10
10
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
11
11
  return try await runAsync(credential: try blueCastArg(BlueAccessCredential.self, arg0))
12
12
  }
@@ -18,22 +18,22 @@ public class BlueAddAccessCredentialCommand: BlueAPIAsyncCommand {
18
18
 
19
19
  try blueAccessCredentialsKeyChain.storeEntry(id: credential.credentialID.id, data: credential.jsonUTF8Data())
20
20
 
21
- try await BlueSynchronizeAccessCredentialCommand(self.blueAPI)
21
+ try await BlueSynchronizeAccessCredentialCommand(sdkService)
22
22
  .runAsync(credentialID: credential.credentialID.id)
23
23
 
24
24
  blueFireListeners(fireEvent: .accessCredentialAdded, data: nil)
25
25
  }
26
26
  }
27
27
 
28
- public class BlueClaimAccessCredentialCommand: BlueAPIAsyncCommand {
28
+ public class BlueClaimAccessCredentialCommand: BlueSdkAsyncCommand {
29
29
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
30
30
  return try await runAsync(activationToken: try blueCastArg(String.self, arg0))
31
31
  }
32
32
 
33
33
  public func runAsync(activationToken: String) async throws -> Void {
34
- let credential = try await blueAPI!.claimAccessCredential(activationToken: activationToken).getData()
34
+ let credential = try await sdkService.apiService.claimAccessCredential(activationToken: activationToken).getData()
35
35
 
36
- try await BlueAddAccessCredentialCommand(self.blueAPI).runAsync(credential: credential)
36
+ try await BlueAddAccessCredentialCommand(sdkService).runAsync(credential: credential)
37
37
  }
38
38
  }
39
39
 
@@ -123,7 +123,7 @@ public struct BlueGetAccessDevicesCommand: BlueCommand {
123
123
  }
124
124
  }
125
125
 
126
- public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
126
+ public class BlueSynchronizeAccessDeviceCommand: BlueSdkAsyncCommand {
127
127
  internal override func runAsync(arg0: Any? = nil, arg1: Any? = nil, arg2: Any? = nil) async throws -> Any? {
128
128
  if #available(macOS 10.15, *) {
129
129
  return try await runAsync(
@@ -145,7 +145,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
145
145
  throw BlueError(.sdkCredentialNotFound)
146
146
  }
147
147
 
148
- let tokenAuthentication = try await BlueAccessAPIHelper(blueAPI!)
148
+ let tokenAuthentication = try await sdkService.authenticationTokenService
149
149
  .getTokenAuthentication(credential: credential)
150
150
 
151
151
  let config = try await getBlueSystemConfig(deviceID: deviceID, with: tokenAuthentication)
@@ -197,7 +197,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
197
197
  @available(macOS 10.15, *)
198
198
  private func deployBlacklistEntries(deviceID: String, with tokenAuthentication: BlueTokenAuthentication) async throws {
199
199
  do {
200
- let response = try await blueAPI!.getBlacklistEntries(deviceID: deviceID, with: tokenAuthentication, limit: 50).getData()
200
+ let response = try await sdkService.apiService.getBlacklistEntries(deviceID: deviceID, with: tokenAuthentication, limit: 50).getData()
201
201
 
202
202
  guard let data = Data(base64Encoded: response.blacklistEntries) else {
203
203
  return
@@ -218,7 +218,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
218
218
 
219
219
  private func getBlueSystemConfig(deviceID: String, with tokenAuthentication: BlueTokenAuthentication) async throws -> BlueSystemConfig? {
220
220
  do {
221
- let result = try await blueAPI!.createDeviceConfiguration(deviceID: deviceID, with: tokenAuthentication).getData()
221
+ let result = try await sdkService.apiService.createDeviceConfiguration(deviceID: deviceID, with: tokenAuthentication).getData()
222
222
 
223
223
  guard let systemConfiguration = result.systemConfiguration else {
224
224
  return nil
@@ -238,7 +238,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
238
238
 
239
239
  private func pushDeviceSystemStatus(status: BlueSystemStatus, with tokenAuthentication: BlueTokenAuthentication) async throws {
240
240
  do {
241
- let result = try await blueAPI!.updateDeviceSystemStatus(systemStatus: blueEncodeMessage(status).base64EncodedString(), with: tokenAuthentication).getData()
241
+ let result = try await sdkService.apiService.updateDeviceSystemStatus(systemStatus: blueEncodeMessage(status).base64EncodedString(), with: tokenAuthentication).getData()
242
242
 
243
243
  if (!result.updated) {
244
244
  blueLogWarn("System status could not be deployed")
@@ -278,7 +278,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
278
278
  if (!logResult.events.isEmpty) {
279
279
  let events = logResult.events.map{ BluePushEvent(event: $0, deviceId: deviceID) }
280
280
 
281
- let result = try await self.blueAPI!.pushEvents(events: events, with: tokenAuthentication).getData()
281
+ let result = try await sdkService.apiService.pushEvents(events: events, with: tokenAuthentication).getData()
282
282
 
283
283
  if (result.storedEvents.count != events.count) {
284
284
  blueLogWarn("Some event logs have not been deployed")
@@ -323,7 +323,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
323
323
  if (!logResult.entries.isEmpty) {
324
324
  let logEntries = logResult.entries.map{ BluePushSystemLogEntry(logEntry: $0) }
325
325
 
326
- let result = try await self.blueAPI!.pushSystemLogs(deviceID: deviceID, logEntries: logEntries, with: tokenAuthentication).getData()
326
+ let result = try await sdkService.apiService.pushSystemLogs(deviceID: deviceID, logEntries: logEntries, with: tokenAuthentication).getData()
327
327
 
328
328
  if (result.storedLogEntries.count != logEntries.count) {
329
329
  blueLogWarn("Some system log entries have not been deployed")
@@ -352,7 +352,7 @@ public class BlueSynchronizeAccessDeviceCommand: BlueAPIAsyncCommand {
352
352
  }
353
353
  }
354
354
 
355
- public class BlueGetAccessObjectsCommand: BlueAPIAsyncCommand {
355
+ public class BlueGetAccessObjectsCommand: BlueSdkAsyncCommand {
356
356
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
357
357
  return try await runAsync(
358
358
  credentialID: try blueCastArg(String.self, arg0)
@@ -364,10 +364,10 @@ public class BlueGetAccessObjectsCommand: BlueAPIAsyncCommand {
364
364
  throw BlueError(.sdkCredentialNotFound)
365
365
  }
366
366
 
367
- let tokenAuthentication = try await BlueAccessAPIHelper(blueAPI!)
367
+ let tokenAuthentication = try await sdkService.authenticationTokenService
368
368
  .getTokenAuthentication(credential: credential)
369
369
 
370
- let objects = try await blueAPI!.getAccessObjects(with: tokenAuthentication).getData()
370
+ let objects = try await sdkService.apiService.getAccessObjects(with: tokenAuthentication).getData()
371
371
 
372
372
  return BlueAccessObjectList(objects: objects)
373
373
  }
@@ -402,7 +402,7 @@ public struct BlueListAccessDevicesCommand: BlueAsyncCommand {
402
402
  }
403
403
  }
404
404
 
405
- public class BlueClaimAccessDeviceCommand: BlueAPIAsyncCommand {
405
+ public class BlueClaimAccessDeviceCommand: BlueSdkAsyncCommand {
406
406
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
407
407
  if #available(macOS 10.15, *) {
408
408
  return try await runAsync(
@@ -425,14 +425,14 @@ public class BlueClaimAccessDeviceCommand: BlueAPIAsyncCommand {
425
425
  throw BlueError(.sdkCredentialNotFound)
426
426
  }
427
427
 
428
- let tokenAuthentication = try await BlueAccessAPIHelper(blueAPI!)
428
+ let tokenAuthentication = try await sdkService.authenticationTokenService
429
429
  .getTokenAuthentication(credential: credential)
430
430
 
431
- _ = try await blueAPI!.claimDevice(deviceID: deviceID, objectID: objectID, with: tokenAuthentication).getData()
431
+ _ = try await sdkService.apiService.claimDevice(deviceID: deviceID, objectID: objectID, with: tokenAuthentication).getData()
432
432
 
433
- try await BlueSynchronizeMobileAccessCommand(self.blueAPI).runAsync(credentialID: credential.credentialID.id)
433
+ try await BlueSynchronizeMobileAccessCommand(sdkService).runAsync(credentialID: credential.credentialID.id)
434
434
 
435
- let status = try await BlueSynchronizeAccessDeviceCommand(self.blueAPI).runAsync(credentialID: credential.credentialID.id, deviceID: deviceID)
435
+ let status = try await BlueSynchronizeAccessDeviceCommand(sdkService).runAsync(credentialID: credential.credentialID.id, deviceID: deviceID)
436
436
 
437
437
  blueFireListeners(fireEvent: .accessDeviceClaimed, data: nil)
438
438
 
@@ -440,7 +440,7 @@ public class BlueClaimAccessDeviceCommand: BlueAPIAsyncCommand {
440
440
  }
441
441
  }
442
442
 
443
- public class BlueGetWritableAccessCredentialsCommand: BlueAPIAsyncCommand {
443
+ public class BlueGetWritableAccessCredentialsCommand: BlueSdkAsyncCommand {
444
444
  override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
445
445
  return try await runAsync(
446
446
  organisation: blueCastArg(String.self, arg0),
@@ -453,10 +453,10 @@ public class BlueGetWritableAccessCredentialsCommand: BlueAPIAsyncCommand {
453
453
  throw BlueError(.sdkCredentialNotFound)
454
454
  }
455
455
 
456
- let tokenAuthentication = try await BlueAccessAPIHelper(blueAPI!)
456
+ let tokenAuthentication = try await sdkService.authenticationTokenService
457
457
  .getTokenAuthentication(credential: credential)
458
458
 
459
- let credentials = try await blueAPI!.getAccessCredentials(with: tokenAuthentication).getData()
459
+ let credentials = try await sdkService.apiService.getAccessCredentials(with: tokenAuthentication).getData()
460
460
 
461
461
  return BlueAccessCredentialList(credentials: credentials)
462
462
  }
@@ -478,24 +478,31 @@ public struct BlueClearDataCommand: BlueCommand {
478
478
  }
479
479
  }
480
480
 
481
- internal typealias BlueTerminalRunClosure = (
482
- _ deviceID: String,
483
- _ timeoutSeconds: Double,
484
- _ action: String
485
- ) async throws -> BlueOssAccessResult
481
+ protocol BlueTerminalRunProtocol {
482
+ func runOssSoMobile(deviceID: String) async throws -> BlueOssAccessEventsResult
483
+ func runOssSidMobile(deviceID: String) async throws -> BlueOssAccessResult
484
+ }
486
485
 
487
- public struct BlueTryAccessDeviceCommand: BlueAsyncCommand {
488
- private let terminalRun: BlueTerminalRunClosure?
486
+ internal class BlueTerminalRunImplementation: BlueTerminalRunProtocol {
487
+ func runOssSoMobile(deviceID: String) async throws -> BlueOssAccessEventsResult {
488
+ return try await blueTerminalRun(deviceID: deviceID, action: "ossSoMobile")
489
+ }
489
490
 
490
- init(using terminalRun: BlueTerminalRunClosure? = nil) {
491
- if #available(macOS 10.15, *) {
492
- self.terminalRun = terminalRun ?? blueTerminalRun
493
- } else {
494
- self.terminalRun = nil
495
- }
491
+ func runOssSidMobile(deviceID: String) async throws -> BlueOssAccessResult {
492
+ return try await blueTerminalRun(deviceID: deviceID, action: "ossSidMobile")
496
493
  }
494
+ }
495
+
496
+ public class BlueTryAccessDeviceCommand: BlueSdkAsyncCommand {
497
+ private let terminalRun: BlueTerminalRunProtocol
497
498
 
498
- internal func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
499
+ init(_ sdkService: BlueSdkService, using terminalRun: BlueTerminalRunProtocol? = nil) {
500
+ self.terminalRun = terminalRun ?? BlueTerminalRunImplementation()
501
+
502
+ super.init(sdkService)
503
+ }
504
+
505
+ override internal func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
499
506
  return try await runAsync(deviceID: blueCastArg(String.self, arg0))
500
507
  }
501
508
 
@@ -505,46 +512,54 @@ public struct BlueTryAccessDeviceCommand: BlueAsyncCommand {
505
512
  /// - parameter deviceID: The Device ID.
506
513
  /// - throws: Throws an error of type `BlueError(.sdkDeviceNotFound)` if the device could not be found.
507
514
  /// - throws: Throws an error of type `BlueError(.sdkSpTokenNotFound)` if neither an OssSo nor an OssSid token is found.
508
- /// - throws: Throws an error of type `BlueError(.sdkUnsupportedPlatform)` If the macOS version is earlier than 10.15.
509
515
  public func runAsync(deviceID: String) async throws -> BlueOssAccessResult {
510
516
  guard let device = blueGetDevice(deviceID) else {
511
517
  throw BlueError(.sdkDeviceNotFound)
512
518
  }
513
519
 
520
+ #if os(iOS) || os(watchOS)
521
+ return try await blueShowAccessDeviceModal {
522
+ return try await self.tryOssAccess(device)
523
+ }
524
+ #else
525
+ return try await tryOssAccess(device)
526
+ #endif
527
+ }
528
+
529
+ private func tryOssAccess(_ device: BlueDevice) async throws -> BlueOssAccessResult {
514
530
  let hasOssSoToken = blueHasSpTokenForAction(device: device, action: "ossSoMobile")
515
531
  let hasOssSidToken = blueHasSpTokenForAction(device: device, action: "ossSidMobile")
516
532
 
517
- if (!hasOssSoToken && !hasOssSidToken) {
518
- throw BlueError(.sdkSpTokenNotFound)
519
- }
533
+ if (hasOssSoToken) {
534
+ let accessResult = try await terminalRun.runOssSoMobile(deviceID: device.info.deviceID)
520
535
 
521
- let tryOssAccess: () async throws -> BlueOssAccessResult = {
522
- guard #available(macOS 10.15, *) else {
523
- throw BlueError(.sdkUnsupportedPlatform)
536
+ if (!accessResult.events.isEmpty) {
537
+ pushEvents(device: device, events: accessResult.events)
524
538
  }
525
539
 
526
- guard let terminalRun = self.terminalRun else {
527
- throw BlueError(.sdkUnsupportedPlatform)
528
- }
529
-
530
- if (hasOssSoToken) {
531
- return try await terminalRun(deviceID, defaultTimeoutSec, "ossSoMobile")
532
- }
533
-
534
- if (hasOssSidToken) {
535
- return try await terminalRun(deviceID, defaultTimeoutSec, "ossSidMobile")
536
- }
537
-
538
- throw BlueError(.sdkSpTokenNotFound)
540
+ return accessResult.accessResult
539
541
  }
540
542
 
541
- #if os(iOS) || os(watchOS)
542
- return try await blueShowAccessDeviceModal {
543
- return try await tryOssAccess()
543
+ if (hasOssSidToken) {
544
+ return try await terminalRun.runOssSidMobile(deviceID: device.info.deviceID)
545
+ }
546
+
547
+ throw BlueError(.sdkSpTokenNotFound)
548
+ }
549
+
550
+ private func pushEvents(device: BlueDevice, events: [BlueEvent]) {
551
+ do {
552
+ let token = try blueGetSpTokenForAction(device: device, action: "ossSoMobile", data: nil)
553
+
554
+ let credentialID = String(data: token.ossSo.infoFile.subdata(in: 3..<13), encoding: .utf8) ?? ""
555
+
556
+ sdkService.eventService.pushEvents(
557
+ credentialID,
558
+ events.map { BluePushEvent(event: $0, deviceId: device.info.deviceID) }
559
+ )
560
+ } catch {
561
+ blueLogError(error.localizedDescription)
544
562
  }
545
- #else
546
- return try await tryOssAccess()
547
- #endif
548
563
  }
549
564
  }
550
565
 
@@ -0,0 +1,98 @@
1
+ import Foundation
2
+ import Combine
3
+
4
+ internal struct BlueCredentialPushEventPair {
5
+ let credentialID: String
6
+ let event: BluePushEvent
7
+ }
8
+
9
+ internal class BlueAccessEventService: BlueAccessEventServiceProtocol {
10
+ private let MAX_EVENTS = 100
11
+
12
+ private let apiService: BlueAPIProtocol
13
+ private let networkMonitorService: BlueNetworkMonitorService
14
+ private var networkSubscriber: AnyCancellable?
15
+
16
+ private var events: [BlueCredentialPushEventPair] = []
17
+ private var eventsQueue = DispatchQueue(label: "blueid.events", qos: .background, attributes: .concurrent)
18
+
19
+ init(_ apiService: BlueAPIProtocol, _ networkMonitorService: BlueNetworkMonitorService) {
20
+ self.apiService = apiService
21
+ self.networkMonitorService = networkMonitorService
22
+
23
+ self.networkSubscriber = self.networkMonitorService.networkStatus
24
+ .sink { _ in
25
+ self.eventsQueue.async {
26
+ Task {
27
+ await self.flush()
28
+ }
29
+ }
30
+ }
31
+ }
32
+
33
+ func pushEvents(_ credentialID: String, _ newEvents: [BluePushEvent]) {
34
+ eventsQueue.async(flags: .barrier) {
35
+ Task {
36
+ self.events.append(contentsOf: newEvents.map{ BlueCredentialPushEventPair(credentialID: credentialID, event: $0) })
37
+
38
+ if (self.events.count > self.MAX_EVENTS) {
39
+ blueLogWarn("Events overflowed, only last \(self.MAX_EVENTS) events will be kept")
40
+
41
+ self.events = self.events.suffix(self.MAX_EVENTS)
42
+ }
43
+
44
+ await self.flush()
45
+ }
46
+ }
47
+ }
48
+
49
+ private func flush() async {
50
+ guard networkMonitorService.isConnected() else {
51
+ blueLogInfo("No internet connection, events will be pushed once there is a connection")
52
+ return
53
+ }
54
+
55
+ guard !self.events.isEmpty else {
56
+ blueLogInfo("No events to be pushed")
57
+ return
58
+ }
59
+
60
+ let events: [BlueCredentialPushEventPair] = Array(self.events)
61
+
62
+ self.events.removeAll()
63
+
64
+ let chunks = events.reduce(into: [String: [BluePushEvent]]()) { result, element in
65
+ result[element.credentialID, default: []].append(element.event)
66
+ }
67
+
68
+ await withTaskGroup(of: Void.self) { group in
69
+ for chunk in chunks {
70
+ group.addTask { await self.handleChunk(chunk) }
71
+ }
72
+ }
73
+ }
74
+
75
+ private func handleChunk(_ chunk: (key: String, value: [BluePushEvent])) async {
76
+ do {
77
+ guard let credential = blueGetAccessCredential(credentialID: chunk.key) else {
78
+ blueLogWarn("Credential not found")
79
+ return
80
+ }
81
+
82
+ // /access/pushEvents can only handle 50 events
83
+ let subchunks = chunk.value.chunks(of: 50)
84
+
85
+ for subchunk in subchunks {
86
+ let tokenAuthentication = try await BlueAccessAPIHelper(apiService).getTokenAuthentication(credential: credential)
87
+
88
+ let result = try await apiService.pushEvents(events: subchunk, with: tokenAuthentication).getData()
89
+
90
+ if (result.storedEvents.count != subchunk.count) {
91
+ blueLogWarn("Some events have not been deployed")
92
+ }
93
+ }
94
+ } catch {
95
+ blueLogError(error.localizedDescription)
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,5 @@
1
+ import Foundation
2
+
3
+ internal protocol BlueAccessEventServiceProtocol {
4
+ func pushEvents(_ credentialID: String, _ events: [BluePushEvent])
5
+ }
@@ -1,6 +1,6 @@
1
1
  import Foundation
2
2
 
3
- public class BlueSynchronizeAccessCredentialCommand: BlueAPIAsyncCommand {
3
+ public class BlueSynchronizeAccessCredentialCommand: BlueSdkAsyncCommand {
4
4
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
5
5
  return try await runAsync(
6
6
  credentialID: try blueCastArg(String.self, arg0)
@@ -13,16 +13,16 @@ public class BlueSynchronizeAccessCredentialCommand: BlueAPIAsyncCommand {
13
13
  }
14
14
 
15
15
  if (credential.credentialType == .nfcWriter) {
16
- return try await BlueSynchronizeNfcAccessCommand(self.blueAPI)
16
+ return try await BlueSynchronizeNfcAccessCommand(sdkService)
17
17
  .runAsync(credentialID: credentialID, forceRefresh: forceRefresh)
18
18
  }
19
19
 
20
- return try await BlueSynchronizeMobileAccessCommand(self.blueAPI)
20
+ return try await BlueSynchronizeMobileAccessCommand(sdkService)
21
21
  .runAsync(credentialID: credentialID, forceRefresh: forceRefresh)
22
22
  }
23
23
  }
24
24
 
25
- internal class BlueAbstractSynchronizeAccessCommand<T>: BlueAPIAsyncCommand where T: BlueSynchronizationResponse {
25
+ internal class BlueAbstractSynchronizeAccessCommand<T>: BlueSdkAsyncCommand where T: BlueSynchronizationResponse {
26
26
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
27
27
  return try await runAsync(
28
28
  credentialID: try blueCastArg(String.self, arg0)
@@ -34,7 +34,7 @@ internal class BlueAbstractSynchronizeAccessCommand<T>: BlueAPIAsyncCommand wher
34
34
  throw BlueError(.sdkCredentialNotFound)
35
35
  }
36
36
 
37
- let tokenAuthentication = try await BlueAccessAPIHelper(blueAPI!)
37
+ let tokenAuthentication = try await sdkService.authenticationTokenService
38
38
  .getTokenAuthentication(credential: credential, refreshToken: false)
39
39
 
40
40
  guard let response = try? await self.sync(with: tokenAuthentication, forceRefresh: forceRefresh) else {
@@ -85,7 +85,7 @@ internal struct BlueOssEntry: Codable {
85
85
 
86
86
  internal class BlueSynchronizeNfcAccessCommand: BlueAbstractSynchronizeAccessCommand<BlueNfcAccessSynchronizationResult> {
87
87
  override func sync(with tokenAuthentication: BlueTokenAuthentication, forceRefresh: Bool? = nil) async throws -> BlueFetchResponse<BlueNfcAccessSynchronizationResult> {
88
- return try await self.blueAPI!.synchronizeNfcAccess(with: tokenAuthentication)
88
+ return try await sdkService.apiService.synchronizeNfcAccess(with: tokenAuthentication)
89
89
  }
90
90
 
91
91
  override func update(_ credential: BlueAccessCredential, _ synchronizationResult: BlueNfcAccessSynchronizationResult) throws {
@@ -116,7 +116,7 @@ internal class BlueSynchronizeNfcAccessCommand: BlueAbstractSynchronizeAccessCom
116
116
 
117
117
  internal class BlueSynchronizeMobileAccessCommand: BlueAbstractSynchronizeAccessCommand<BlueMobileAccessSynchronizationResult> {
118
118
  override func sync(with tokenAuthentication: BlueTokenAuthentication, forceRefresh: Bool? = nil) async throws -> BlueFetchResponse<BlueMobileAccessSynchronizationResult> {
119
- return try await self.blueAPI!.synchronizeMobileAccess(with: tokenAuthentication, forceRefresh: forceRefresh)
119
+ return try await sdkService.apiService.synchronizeMobileAccess(with: tokenAuthentication, forceRefresh: forceRefresh)
120
120
  }
121
121
 
122
122
  override func update(_ credential: BlueAccessCredential, _ synchronizationResult: BlueMobileAccessSynchronizationResult) throws {
@@ -185,7 +185,7 @@ internal class BlueSynchronizeMobileAccessCommand: BlueAbstractSynchronizeAccess
185
185
  * @class BlueSynchronizeAccessCredentialsCommand
186
186
  * A command to synchronize all stored credentials.
187
187
  */
188
- public class BlueSynchronizeAccessCredentialsCommand: BlueAPIAsyncCommand {
188
+ public class BlueSynchronizeAccessCredentialsCommand: BlueSdkAsyncCommand {
189
189
  internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
190
190
  return try await runAsync()
191
191
  }
@@ -231,7 +231,7 @@ public class BlueSynchronizeAccessCredentialsCommand: BlueAPIAsyncCommand {
231
231
  resultItem.credentialID.id = credential.credentialID.id
232
232
 
233
233
  do {
234
- try await BlueSynchronizeAccessCredentialCommand(self.blueAPI)
234
+ try await BlueSynchronizeAccessCredentialCommand(sdkService)
235
235
  .runAsync(credentialID: credential.credentialID.id, forceRefresh: true)
236
236
 
237
237
  resultItem.returnCode = .ok
@@ -11,15 +11,11 @@ protocol BlueAsyncCommand: Command {
11
11
  func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any?
12
12
  }
13
13
 
14
- public class BlueAPIAsyncCommand: BlueAsyncCommand {
15
- internal let blueAPI: BlueAPIProtocol?
14
+ public class BlueSdkAsyncCommand: BlueAsyncCommand {
15
+ internal let sdkService: BlueSdkService
16
16
 
17
- init(_ blueAPI: BlueAPIProtocol? = nil) {
18
- if #available(macOS 12.0, *) {
19
- self.blueAPI = blueAPI ?? BlueAPI()
20
- } else {
21
- self.blueAPI = nil
22
- }
17
+ init(_ sdkService: BlueSdkService) {
18
+ self.sdkService = sdkService
23
19
  }
24
20
 
25
21
  internal func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
@@ -27,6 +23,14 @@ public class BlueAPIAsyncCommand: BlueAsyncCommand {
27
23
  }
28
24
  }
29
25
 
26
+ private let blueApiService = BlueAPI()
27
+ private let blueNetworkMonitorService = BlueNetworkMonitorService()
28
+
29
+ private let defaultSdkService = BlueSdkService(
30
+ blueApiService,
31
+ BlueAccessEventService(blueApiService, blueNetworkMonitorService)
32
+ )
33
+
30
34
  public struct BlueCommands {
31
35
  public let initialize = BlueInitializeCommand()
32
36
  public let release = BlueReleaseCommand()
@@ -55,9 +59,9 @@ public struct BlueCommands {
55
59
  public let ossSoReadConfiguration = BlueOssSoReadConfigurationCommand()
56
60
  public let ossSoUpdateConfiguration = BlueOssSoUpdateConfigurationCommand()
57
61
  public let readOssSoCredential = BlueReadOssSoCredentialCommand()
58
- public let writeOssSoCredential = BlueWriteOssSoCredentialCommand()
59
- public let refreshOssSoCredential = BlueRefreshOssSoCredentialCommand()
60
- public let refreshOssSoCredentials = BlueRefreshOssSoCredentialsCommand()
62
+ public let writeOssSoCredential = BlueWriteOssSoCredentialCommand(defaultSdkService)
63
+ public let refreshOssSoCredential = BlueRefreshOssSoCredentialCommand(defaultSdkService)
64
+ public let refreshOssSoCredentials = BlueRefreshOssSoCredentialsCommand(defaultSdkService)
61
65
  public let formatOssSoCredential = BlueFormatOssSoCredentialCommand()
62
66
 
63
67
  public let ossSidCreateMobile = BlueOssSidCreateMobileCommand()
@@ -69,18 +73,18 @@ public struct BlueCommands {
69
73
  public let ossSidUnprovision = BlueOssSidUnprovisionCommand()
70
74
  public let ossSidReadConfiguration = BlueOssSidReadConfigurationCommand()
71
75
 
72
- public let tryAccessDevice = BlueTryAccessDeviceCommand()
73
- public let addAccessCredential = BlueAddAccessCredentialCommand()
74
- public let claimAccessCredential = BlueClaimAccessCredentialCommand()
76
+ public let tryAccessDevice = BlueTryAccessDeviceCommand(defaultSdkService)
77
+ public let addAccessCredential = BlueAddAccessCredentialCommand(defaultSdkService)
78
+ public let claimAccessCredential = BlueClaimAccessCredentialCommand(defaultSdkService)
75
79
  public let getAccessCredentials = BlueGetAccessCredentialsCommand()
76
- public let synchronizeAccessCredential = BlueSynchronizeAccessCredentialCommand()
77
- public let synchronizeAccessCredentials = BlueSynchronizeAccessCredentialsCommand()
80
+ public let synchronizeAccessCredential = BlueSynchronizeAccessCredentialCommand(defaultSdkService)
81
+ public let synchronizeAccessCredentials = BlueSynchronizeAccessCredentialsCommand(defaultSdkService)
78
82
  public let getAccessDevices = BlueGetAccessDevicesCommand()
79
83
  public let listAccessDevices = BlueListAccessDevicesCommand()
80
- public let synchronizeAccessDevice = BlueSynchronizeAccessDeviceCommand()
81
- public let getAccessObjects = BlueGetAccessObjectsCommand()
82
- public let claimAccessDevice = BlueClaimAccessDeviceCommand()
83
- public let getWritableAccessCredentials = BlueGetWritableAccessCredentialsCommand()
84
+ public let synchronizeAccessDevice = BlueSynchronizeAccessDeviceCommand(defaultSdkService)
85
+ public let getAccessObjects = BlueGetAccessObjectsCommand(defaultSdkService)
86
+ public let claimAccessDevice = BlueClaimAccessDeviceCommand(defaultSdkService)
87
+ public let getWritableAccessCredentials = BlueGetWritableAccessCredentialsCommand(defaultSdkService)
84
88
 
85
89
  public let clearBlacklist = BlueClearBlacklistCommand()
86
90
  public let clearEventLog = BlueClearEventLogCommand()