|
|
|
|
@ -13,8 +13,9 @@ public enum ResetOption { |
|
|
|
|
case synchronizedOnly |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enum StoreError: Error { |
|
|
|
|
public enum StoreError: Error { |
|
|
|
|
case missingService |
|
|
|
|
case missingUserId |
|
|
|
|
case unexpectedCollectionType(name: String) |
|
|
|
|
case apiCallCollectionNotRegistered(type: String) |
|
|
|
|
case collectionNotRegistered(type: String) |
|
|
|
|
@ -101,30 +102,21 @@ public class Store { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the user's UUID |
|
|
|
|
public var currentUserUUID: UUID? { |
|
|
|
|
if let uuidString = self._settingsStorage.item.userId, |
|
|
|
|
let uuid = UUID(uuidString: uuidString) { |
|
|
|
|
return uuid |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
public var userId: String? { |
|
|
|
|
return self._settingsStorage.item.userId |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns a UUID, using the user's if possible |
|
|
|
|
public func mandatoryUserUUID() -> UUID { |
|
|
|
|
if let uuid = self.currentUserUUID { |
|
|
|
|
return uuid |
|
|
|
|
} else { |
|
|
|
|
let uuid = UIDevice.current.identifierForVendor ?? UUID() |
|
|
|
|
self._settingsStorage.update { settings in |
|
|
|
|
settings.userId = uuid.uuidString |
|
|
|
|
} |
|
|
|
|
return uuid |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/// Returns the user's UUID |
|
|
|
|
// public var currentUserUUID: UUID? { |
|
|
|
|
// if let uuidString = self._settingsStorage.item.userId, |
|
|
|
|
// let uuid = UUID(uuidString: uuidString) { |
|
|
|
|
// return uuid |
|
|
|
|
// } |
|
|
|
|
// return nil |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
/// Returns the username |
|
|
|
|
func userName() -> String? { |
|
|
|
|
public func userName() -> String? { |
|
|
|
|
return self._settingsStorage.item.username |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -135,6 +127,10 @@ public class Store { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public func token() -> String? { |
|
|
|
|
return try? self.service().keychainStore.getToken() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Disconnect the user from the storage and resets collection |
|
|
|
|
public func disconnect(resetOption: ResetOption? = nil) { |
|
|
|
|
try? self.service().disconnect() |
|
|
|
|
|