From eba444d3615a63cff474cd76bb38f52ec8892514 Mon Sep 17 00:00:00 2001 From: Daniel Jilg Date: Wed, 21 Aug 2024 16:44:28 +0200 Subject: [PATCH] Add hashedDefaultUser property (#180) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows customers to access the hashed version of the user string they’ve set, in order to hand it over to other SDKs or webhooks. --- Sources/TelemetryClient/TelemetryClient.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/TelemetryClient/TelemetryClient.swift b/Sources/TelemetryClient/TelemetryClient.swift index 91e5466..501d212 100644 --- a/Sources/TelemetryClient/TelemetryClient.swift +++ b/Sources/TelemetryClient/TelemetryClient.swift @@ -246,6 +246,11 @@ public final class TelemetryManager: @unchecked Sendable { configuration.defaultUser = newDefaultUser } + public var hashedDefaultUser: String? { + guard let defaultUser = configuration.defaultUser else { return nil } + return CryptoHashing.sha256(string: defaultUser, salt: configuration.salt) + } + /// Generate a new Session ID for all new Signals, in order to begin a new session instead of continuing the old one. @available(*, deprecated, renamed: "TelemetryDeck.generateNewSession()", message: "This call was renamed to `TelemetryDeck.generateNewSession()`. Please migrate – a fix-it is available.") public static func generateNewSession() {