@blueid/access-capacitor 0.78.0 → 0.80.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.
@@ -10,7 +10,7 @@
10
10
  <key>HeadersPath</key>
11
11
  <string>Headers</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>macos-arm64_x86_64</string>
13
+ <string>ios-arm64_x86_64-simulator</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>libCBlueIDAccess.a</string>
16
16
  <key>SupportedArchitectures</key>
@@ -19,7 +19,9 @@
19
19
  <string>x86_64</string>
20
20
  </array>
21
21
  <key>SupportedPlatform</key>
22
- <string>macos</string>
22
+ <string>ios</string>
23
+ <key>SupportedPlatformVariant</key>
24
+ <string>simulator</string>
23
25
  </dict>
24
26
  <dict>
25
27
  <key>BinaryPath</key>
@@ -27,18 +29,15 @@
27
29
  <key>HeadersPath</key>
28
30
  <string>Headers</string>
29
31
  <key>LibraryIdentifier</key>
30
- <string>ios-arm64_x86_64-simulator</string>
32
+ <string>ios-arm64</string>
31
33
  <key>LibraryPath</key>
32
34
  <string>libCBlueIDAccess.a</string>
33
35
  <key>SupportedArchitectures</key>
34
36
  <array>
35
37
  <string>arm64</string>
36
- <string>x86_64</string>
37
38
  </array>
38
39
  <key>SupportedPlatform</key>
39
40
  <string>ios</string>
40
- <key>SupportedPlatformVariant</key>
41
- <string>simulator</string>
42
41
  </dict>
43
42
  <dict>
44
43
  <key>BinaryPath</key>
@@ -46,15 +45,16 @@
46
45
  <key>HeadersPath</key>
47
46
  <string>Headers</string>
48
47
  <key>LibraryIdentifier</key>
49
- <string>ios-arm64</string>
48
+ <string>macos-arm64_x86_64</string>
50
49
  <key>LibraryPath</key>
51
50
  <string>libCBlueIDAccess.a</string>
52
51
  <key>SupportedArchitectures</key>
53
52
  <array>
54
53
  <string>arm64</string>
54
+ <string>x86_64</string>
55
55
  </array>
56
56
  <key>SupportedPlatform</key>
57
- <string>ios</string>
57
+ <string>macos</string>
58
58
  </dict>
59
59
  </array>
60
60
  <key>CFBundlePackageType</key>
@@ -56,9 +56,7 @@ internal class BlueAbstractSynchronizeAccessCommand<T>: BlueAPIAsyncCommand wher
56
56
  return
57
57
  }
58
58
 
59
- guard let synchronizationResult = response.data else {
60
- return
61
- }
59
+ let synchronizationResult = try response.getData()
62
60
 
63
61
  if synchronizationResult.noRefresh == true {
64
62
  return
@@ -188,3 +186,68 @@ internal class BlueSynchronizeMobileAccessCommand: BlueAbstractSynchronizeAccess
188
186
  blueAccessDevicesStorage.deleteEntry(id: credential.credentialID.id)
189
187
  }
190
188
  }
189
+
190
+ /**
191
+ * @class BlueSynchronizeAccessCredentialsCommand
192
+ * A command to synchronize all stored credentials.
193
+ */
194
+ public class BlueSynchronizeAccessCredentialsCommand: BlueAPIAsyncCommand {
195
+ internal override func runAsync(arg0: Any?, arg1: Any?, arg2: Any?) async throws -> Any? {
196
+ return try await runAsync()
197
+ }
198
+
199
+ /// Synchronizes all stored credentials.
200
+ /// Note: Master credentials are not synced in case of any, as they can only be synced once during the claiming process.
201
+ ///
202
+ /// - throws: Throws an error of type `BlueError(.sdkUnsupportedPlatform)` If the macOS version is earlier than 10.15.
203
+ /// - returns: The exit status (BlueReturnCode) of each credential, and its error description, if any.
204
+ public func runAsync() async throws -> BlueSynchronizeAccessCredentials {
205
+ guard #available(macOS 10.15, *) else {
206
+ throw BlueError(.sdkUnsupportedPlatform)
207
+ }
208
+
209
+ let credentials = try await BlueGetAccessCredentialsCommand().runAsync().credentials
210
+ .filter { $0.credentialType != .master }
211
+
212
+ if (credentials.isEmpty) {
213
+ return BlueSynchronizeAccessCredentials()
214
+ }
215
+
216
+ return await withTaskGroup(of: BlueSynchronizeAccessCredential.self, returning: BlueSynchronizeAccessCredentials.self) { group in
217
+
218
+ for credential in credentials {
219
+ group.addTask { await self.handleCredential(credential) }
220
+ }
221
+
222
+ var credentials: [BlueSynchronizeAccessCredential] = []
223
+
224
+ for await resultItem in group {
225
+ credentials.append(resultItem)
226
+ }
227
+
228
+ return BlueSynchronizeAccessCredentials(credentials: credentials)
229
+ }
230
+ }
231
+
232
+ private func handleCredential(_ credential: BlueAccessCredential) async -> BlueSynchronizeAccessCredential {
233
+ var resultItem = BlueSynchronizeAccessCredential()
234
+ resultItem.credentialID.id = credential.credentialID.id
235
+
236
+ do {
237
+ try await BlueSynchronizeAccessCredentialCommand(self.blueAPI)
238
+ .runAsync(credentialID: credential.credentialID.id, forceRefresh: true)
239
+
240
+ resultItem.returnCode = .ok
241
+ }
242
+ catch let error as BlueError {
243
+ resultItem.returnCode = error.returnCode
244
+ resultItem.errorDescription = error.localizedDescription
245
+ }
246
+ catch {
247
+ resultItem.returnCode = .error
248
+ resultItem.errorDescription = error.localizedDescription
249
+ }
250
+
251
+ return resultItem
252
+ }
253
+ }
@@ -0,0 +1,145 @@
1
+ import Foundation
2
+
3
+ private class ForegroundScheduler {
4
+ private var timer: Timer?
5
+ private var scheduler: BlueAccessSyncScheduler?
6
+
7
+ func setup(_ scheduler: BlueAccessSyncScheduler) {
8
+ self.scheduler = scheduler
9
+ }
10
+
11
+ func suspend() {
12
+ timer?.invalidate()
13
+ timer = nil
14
+ }
15
+
16
+ func schedule(_ now: Bool? = false) {
17
+ guard #available(macOS 10.15, *) else {
18
+ blueLogWarn("Unsupported platform")
19
+ return
20
+ }
21
+
22
+ suspend()
23
+
24
+ if now == true {
25
+ self.handleTask()
26
+ } else {
27
+ blueRunInMainThread {
28
+ self.timer = Timer.scheduledTimer(
29
+ timeInterval: self.scheduler!.timeInterval,
30
+ target: self,
31
+ selector: #selector(self.handleTask),
32
+ userInfo: nil,
33
+ repeats: false
34
+ )
35
+ }
36
+ }
37
+ }
38
+
39
+ @available(macOS 10.15, *)
40
+ @objc private func handleTask() {
41
+ DispatchQueue.global(qos: .background).async {
42
+ Task {
43
+ do {
44
+ try await self.scheduler!.synchronizeAccessCredentials()
45
+ } catch {
46
+ blueLogError(error.localizedDescription)
47
+ }
48
+
49
+ if (self.scheduler!.autoSchedule) {
50
+ self.schedule()
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ internal class BlueAccessSyncScheduler: BlueEventListener {
58
+ public static let shared = BlueAccessSyncScheduler()
59
+
60
+ let timeInterval: TimeInterval
61
+ let autoSchedule: Bool
62
+
63
+ private let foregroundScheduler = ForegroundScheduler()
64
+
65
+ private let command: BlueSynchronizeAccessCredentialsCommand
66
+
67
+ private var syncing = false
68
+
69
+ init(
70
+ timeInterval: TimeInterval? = 60 * 60 * 6, // every 6h by default
71
+ autoSchedule: Bool? = true,
72
+ command: BlueSynchronizeAccessCredentialsCommand? = nil
73
+ ) {
74
+ self.command = command ?? blueCommands.synchronizeAccessCredentials
75
+ self.timeInterval = timeInterval ?? 60
76
+ self.autoSchedule = autoSchedule ?? true
77
+
78
+ foregroundScheduler.setup(self)
79
+
80
+ blueAddEventListener(listener: self)
81
+ }
82
+
83
+ deinit {
84
+ blueRemoveEventListener(listener: self)
85
+ }
86
+
87
+ func willResignActive() {
88
+ suspend()
89
+ }
90
+
91
+ func willTerminate() {
92
+ suspend()
93
+ }
94
+
95
+ func didBecomeActive() {
96
+ schedule(true)
97
+ }
98
+
99
+ func didFinishLaunching() {
100
+ schedule(true)
101
+ }
102
+
103
+ func blueEvent(event: BlueEventType, data: Any?) {
104
+ if (event == .accessCredentialAdded) {
105
+ schedule()
106
+ }
107
+ }
108
+
109
+ func schedule(_ now: Bool? = false) {
110
+ do {
111
+ guard try blueAccessCredentialsKeyChain.getNumberOfEntries() > 0 else {
112
+ return
113
+ }
114
+ } catch {
115
+ blueLogError(error.localizedDescription)
116
+ }
117
+
118
+ blueRemoveEventListener(listener: self)
119
+
120
+ foregroundScheduler.schedule(now)
121
+ }
122
+
123
+ func suspend() {
124
+ foregroundScheduler.suspend()
125
+ }
126
+
127
+ func synchronizeAccessCredentials() async throws -> Void {
128
+ if (syncing) {
129
+ blueLogInfo("There is already a synchronization in progress")
130
+ return
131
+ }
132
+
133
+ syncing = true
134
+
135
+ blueFireListeners(fireEvent: BlueEventType.tokenSyncStarted, data: nil)
136
+
137
+ defer {
138
+ syncing = false
139
+
140
+ blueFireListeners(fireEvent: BlueEventType.tokenSyncFinished, data: nil)
141
+ }
142
+
143
+ _ = try await command.runAsync()
144
+ }
145
+ }
@@ -40,18 +40,3 @@ public struct BlueOpenAppSettingsCommand: BlueAsyncCommand {
40
40
  completionHandler(false)
41
41
  }
42
42
  }
43
-
44
- internal func blueAppHasLaunchedBefore() -> Bool {
45
- if let hasLaunchedBefore = hasLaunchedBefore {
46
- return hasLaunchedBefore
47
- }
48
-
49
- let result = blueAppStorage.getBool(id: "hasLaunchedBefore")
50
- if (!result) {
51
- blueAppStorage.storeBool(id: "hasLaunchedBefore", bool: true)
52
- }
53
-
54
- hasLaunchedBefore = true
55
-
56
- return result
57
- }
@@ -18,7 +18,7 @@ public final class BlueAppDelegate: NSObject {
18
18
  }
19
19
  #endif
20
20
 
21
- BlueTokenSyncScheduler.shared.didFinishLaunching()
21
+ BlueAccessSyncScheduler.shared.didFinishLaunching()
22
22
  }
23
23
 
24
24
  #if os(iOS) || os(watchOS)
@@ -38,7 +38,7 @@ public final class BlueAppDelegate: NSObject {
38
38
  #endif
39
39
 
40
40
  @objc public static func willResignActive() {
41
- BlueTokenSyncScheduler.shared.willResignActive()
41
+ BlueAccessSyncScheduler.shared.willResignActive()
42
42
  }
43
43
 
44
44
  @objc public static func didBecomeActive() {
@@ -46,7 +46,7 @@ public final class BlueAppDelegate: NSObject {
46
46
  blueNearbyAppBecameActive()
47
47
  #endif
48
48
 
49
- BlueTokenSyncScheduler.shared.didBecomeActive()
49
+ BlueAccessSyncScheduler.shared.didBecomeActive()
50
50
  }
51
51
 
52
52
  @objc public static func didEnterBackground() {
@@ -62,6 +62,6 @@ public final class BlueAppDelegate: NSObject {
62
62
  fatalError(error.localizedDescription)
63
63
  }
64
64
 
65
- BlueTokenSyncScheduler.shared.willTerminate()
65
+ BlueAccessSyncScheduler.shared.willTerminate()
66
66
  }
67
67
  }
@@ -74,6 +74,7 @@ public struct BlueCommands {
74
74
  public let claimAccessCredential = BlueClaimAccessCredentialCommand()
75
75
  public let getAccessCredentials = BlueGetAccessCredentialsCommand()
76
76
  public let synchronizeAccessCredential = BlueSynchronizeAccessCredentialCommand()
77
+ public let synchronizeAccessCredentials = BlueSynchronizeAccessCredentialsCommand()
77
78
  public let getAccessDevices = BlueGetAccessDevicesCommand()
78
79
  public let listAccessDevices = BlueListAccessDevicesCommand()
79
80
  public let updateDeviceConfiguration = BlueUpdateDeviceConfigurationCommand()
@@ -751,6 +751,59 @@ public struct BlueRefreshOssSoCredentials {
751
751
  public init() {}
752
752
  }
753
753
 
754
+ public struct BlueSynchronizeAccessCredential {
755
+ // SwiftProtobuf.Message conformance is added in an extension below. See the
756
+ // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
757
+ // methods supported on all messages.
758
+
759
+ public var credentialID: BlueCredentialId {
760
+ get {return _credentialID ?? BlueCredentialId()}
761
+ set {_credentialID = newValue}
762
+ }
763
+ /// Returns true if `credentialID` has been explicitly set.
764
+ public var hasCredentialID: Bool {return self._credentialID != nil}
765
+ /// Clears the value of `credentialID`. Subsequent reads from it will return its default value.
766
+ public mutating func clearCredentialID() {self._credentialID = nil}
767
+
768
+ public var returnCode: BlueReturnCode {
769
+ get {return _returnCode ?? .ok}
770
+ set {_returnCode = newValue}
771
+ }
772
+ /// Returns true if `returnCode` has been explicitly set.
773
+ public var hasReturnCode: Bool {return self._returnCode != nil}
774
+ /// Clears the value of `returnCode`. Subsequent reads from it will return its default value.
775
+ public mutating func clearReturnCode() {self._returnCode = nil}
776
+
777
+ public var errorDescription: String {
778
+ get {return _errorDescription ?? String()}
779
+ set {_errorDescription = newValue}
780
+ }
781
+ /// Returns true if `errorDescription` has been explicitly set.
782
+ public var hasErrorDescription: Bool {return self._errorDescription != nil}
783
+ /// Clears the value of `errorDescription`. Subsequent reads from it will return its default value.
784
+ public mutating func clearErrorDescription() {self._errorDescription = nil}
785
+
786
+ public var unknownFields = SwiftProtobuf.UnknownStorage()
787
+
788
+ public init() {}
789
+
790
+ fileprivate var _credentialID: BlueCredentialId? = nil
791
+ fileprivate var _returnCode: BlueReturnCode? = nil
792
+ fileprivate var _errorDescription: String? = nil
793
+ }
794
+
795
+ public struct BlueSynchronizeAccessCredentials {
796
+ // SwiftProtobuf.Message conformance is added in an extension below. See the
797
+ // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
798
+ // methods supported on all messages.
799
+
800
+ public var credentials: [BlueSynchronizeAccessCredential] = []
801
+
802
+ public var unknownFields = SwiftProtobuf.UnknownStorage()
803
+
804
+ public init() {}
805
+ }
806
+
754
807
  #if swift(>=5.5) && canImport(_Concurrency)
755
808
  extension BlueDeviceType: @unchecked Sendable {}
756
809
  extension BlueRefreshOssSoCredentialStatus: @unchecked Sendable {}
@@ -767,6 +820,8 @@ extension BlueAccessObject: @unchecked Sendable {}
767
820
  extension BlueAccessObjectList: @unchecked Sendable {}
768
821
  extension BlueRefreshOssSoCredential: @unchecked Sendable {}
769
822
  extension BlueRefreshOssSoCredentials: @unchecked Sendable {}
823
+ extension BlueSynchronizeAccessCredential: @unchecked Sendable {}
824
+ extension BlueSynchronizeAccessCredentials: @unchecked Sendable {}
770
825
  #endif // swift(>=5.5) && canImport(_Concurrency)
771
826
 
772
827
  // MARK: - Code below here is support for the SwiftProtobuf runtime.
@@ -1715,3 +1770,95 @@ extension BlueRefreshOssSoCredentials: SwiftProtobuf.Message, SwiftProtobuf._Mes
1715
1770
  return true
1716
1771
  }
1717
1772
  }
1773
+
1774
+ extension BlueSynchronizeAccessCredential: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1775
+ public static let protoMessageName: String = "BlueSynchronizeAccessCredential"
1776
+ public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1777
+ 1: .same(proto: "credentialId"),
1778
+ 2: .same(proto: "returnCode"),
1779
+ 3: .same(proto: "errorDescription"),
1780
+ ]
1781
+
1782
+ public var isInitialized: Bool {
1783
+ if self._credentialID == nil {return false}
1784
+ if self._returnCode == nil {return false}
1785
+ if let v = self._credentialID, !v.isInitialized {return false}
1786
+ return true
1787
+ }
1788
+
1789
+ public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
1790
+ while let fieldNumber = try decoder.nextFieldNumber() {
1791
+ // The use of inline closures is to circumvent an issue where the compiler
1792
+ // allocates stack space for every case branch when no optimizations are
1793
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
1794
+ switch fieldNumber {
1795
+ case 1: try { try decoder.decodeSingularMessageField(value: &self._credentialID) }()
1796
+ case 2: try { try decoder.decodeSingularEnumField(value: &self._returnCode) }()
1797
+ case 3: try { try decoder.decodeSingularStringField(value: &self._errorDescription) }()
1798
+ default: break
1799
+ }
1800
+ }
1801
+ }
1802
+
1803
+ public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
1804
+ // The use of inline closures is to circumvent an issue where the compiler
1805
+ // allocates stack space for every if/case branch local when no optimizations
1806
+ // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
1807
+ // https://github.com/apple/swift-protobuf/issues/1182
1808
+ try { if let v = self._credentialID {
1809
+ try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
1810
+ } }()
1811
+ try { if let v = self._returnCode {
1812
+ try visitor.visitSingularEnumField(value: v, fieldNumber: 2)
1813
+ } }()
1814
+ try { if let v = self._errorDescription {
1815
+ try visitor.visitSingularStringField(value: v, fieldNumber: 3)
1816
+ } }()
1817
+ try unknownFields.traverse(visitor: &visitor)
1818
+ }
1819
+
1820
+ public static func ==(lhs: BlueSynchronizeAccessCredential, rhs: BlueSynchronizeAccessCredential) -> Bool {
1821
+ if lhs._credentialID != rhs._credentialID {return false}
1822
+ if lhs._returnCode != rhs._returnCode {return false}
1823
+ if lhs._errorDescription != rhs._errorDescription {return false}
1824
+ if lhs.unknownFields != rhs.unknownFields {return false}
1825
+ return true
1826
+ }
1827
+ }
1828
+
1829
+ extension BlueSynchronizeAccessCredentials: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
1830
+ public static let protoMessageName: String = "BlueSynchronizeAccessCredentials"
1831
+ public static let _protobuf_nameMap: SwiftProtobuf._NameMap = [
1832
+ 1: .same(proto: "credentials"),
1833
+ ]
1834
+
1835
+ public var isInitialized: Bool {
1836
+ if !SwiftProtobuf.Internal.areAllInitialized(self.credentials) {return false}
1837
+ return true
1838
+ }
1839
+
1840
+ public mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
1841
+ while let fieldNumber = try decoder.nextFieldNumber() {
1842
+ // The use of inline closures is to circumvent an issue where the compiler
1843
+ // allocates stack space for every case branch when no optimizations are
1844
+ // enabled. https://github.com/apple/swift-protobuf/issues/1034
1845
+ switch fieldNumber {
1846
+ case 1: try { try decoder.decodeRepeatedMessageField(value: &self.credentials) }()
1847
+ default: break
1848
+ }
1849
+ }
1850
+ }
1851
+
1852
+ public func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
1853
+ if !self.credentials.isEmpty {
1854
+ try visitor.visitRepeatedMessageField(value: self.credentials, fieldNumber: 1)
1855
+ }
1856
+ try unknownFields.traverse(visitor: &visitor)
1857
+ }
1858
+
1859
+ public static func ==(lhs: BlueSynchronizeAccessCredentials, rhs: BlueSynchronizeAccessCredentials) -> Bool {
1860
+ if lhs.credentials != rhs.credentials {return false}
1861
+ if lhs.unknownFields != rhs.unknownFields {return false}
1862
+ return true
1863
+ }
1864
+ }
@@ -198,6 +198,12 @@ extension BlueRefreshOssSoCredentials {
198
198
  }
199
199
  }
200
200
 
201
+ extension BlueSynchronizeAccessCredentials {
202
+ public init(credentials: [BlueSynchronizeAccessCredential]) {
203
+ self.credentials = credentials
204
+ }
205
+ }
206
+
201
207
  extension Array {
202
208
 
203
209
  /// Extension function for Arrays, allowing the splitting of the collection into subarrays of a specified size.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueid/access-capacitor",
3
- "version": "0.78.0",
3
+ "version": "0.80.0",
4
4
  "description": "Capacitor JS plugin for the BlueID Access SDK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",