Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Modules/Sources/NetworkingCore/Settings/WooConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ public enum WooConstants {

/// Slug of the free trial WooExpress plan
public static let freeTrialPlanSlug = "ecommerce-trial-bundle-monthly"

/// Keychain Access's Key for merchant AI provider API key
public static let merchantAIProviderKey = "merchantAIProviderKey"
}
11 changes: 11 additions & 0 deletions Modules/Sources/Yosemite/Extensions/Keychain+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import KeychainAccess
import NetworkingCore

extension Keychain {
/// AI key provided by the merchant
///
var merchantAIProviderKey: String? {
get { self[WooConstants.merchantAIProviderKey] }
set { self[WooConstants.merchantAIProviderKey] = newValue }
}
}
9 changes: 6 additions & 3 deletions Modules/Sources/Yosemite/Stores/ProductStore.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
import KeychainAccess
import Networking
import NetworkingCore
import Storage

// MARK: - ProductStore
Expand Down Expand Up @@ -604,8 +606,8 @@ private extension ProductStore {
completion(result)
case .merchant:
let result = await Result {
// Temporary. This will come from the KeyChain rather than the environment
let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found"
let keychain = Keychain(service: WooConstants.keychainServiceName)
let key = keychain.merchantAIProviderKey ?? ""
return try await MerchantGenerativeContentRemote(apiKey: key).identifyLanguage(siteID: siteID,
string: string,
feature: feature)
Expand Down Expand Up @@ -768,7 +770,8 @@ private extension ProductStore {
completion(result)
case .merchant:
let result = await Result {
let key = ProcessInfo.processInfo.environment["openai-debug-api-key"] ?? "api key not found"
let keychain = Keychain(service: WooConstants.keychainServiceName)
let key = keychain.merchantAIProviderKey ?? ""
return try await MerchantGenerativeContentRemote(apiKey: key).generateAIProduct(siteID: siteID,
productName: productName,
keywords: keywords,
Expand Down