Skip to content

Commit

Permalink
Revert "Allow Optimizely targeting w CodePush on mobile C-2394" (#3133)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoback2 committed Mar 30, 2023
1 parent a83c4a8 commit a2f9caa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,14 @@ type State = {
id: Nullable<number>
}

type MobileClientInfo = {
/** This is the type of Platform.OS, but we only expect ios or android here */
mobilePlatform: 'ios' | 'android' | 'web' | 'windows' | 'macos'
mobileAppVersion: string
codePushUpdateNumber: number | undefined
}

export type RemoteConfigOptions<Client> = {
createOptimizelyClient: () => Promise<Client>
getFeatureFlagSessionId: () => Promise<Nullable<number>>
setFeatureFlagSessionId: (id: number) => Promise<void>
setLogLevel: () => void
environment: Environment
appVersion: string
platform: 'web' | 'mobile' | 'desktop'
getMobileClientInfo?: () => Promise<MobileClientInfo> | MobileClientInfo
getMobileClientVersion?: () => Promise<string> | string
}

export const remoteConfig = <
Expand All @@ -72,8 +64,7 @@ export const remoteConfig = <
setLogLevel,
environment,
appVersion,
platform,
getMobileClientInfo
getMobileClientVersion
}: RemoteConfigOptions<Client>) => {
const state: State = {
didInitialize: false,
Expand All @@ -85,9 +76,8 @@ export const remoteConfig = <

// Optimizely client
let client: Client | undefined

/** Mobile app info if platform is mobile */
let mobileClientInfo: MobileClientInfo | undefined
/** Mobile app version that is being run */
let mobileClientVersion: string | undefined

const emitter = new EventEmitter()
emitter.setMaxListeners(1000)
Expand All @@ -102,8 +92,8 @@ export const remoteConfig = <
} else {
state.id = savedSessionId
}
mobileClientInfo = getMobileClientInfo
? await getMobileClientInfo()
mobileClientVersion = getMobileClientVersion
? await getMobileClientVersion()
: undefined
client = await createOptimizelyClient()

Expand Down Expand Up @@ -244,10 +234,7 @@ export const remoteConfig = <
return client.isFeatureEnabled(f, id.toString(), {
userId: id,
appVersion,
platform,
mobilePlatform: mobileClientInfo?.mobilePlatform,
mobileAppVersion: mobileClientInfo?.mobileAppVersion,
codePushUpdateNumber: mobileClientInfo?.codePushUpdateNumber
mobileClientVersion: mobileClientVersion ?? 'N/A'
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,31 @@ const { version: appVersion } = packageInfo
const OPTIMIZELY_KEY = Config.OPTIMIZELY_KEY
const DATA_FILE_URL = 'https://experiments.audius.co/datafiles/%s.json'

/** Returns mobile platform (ios or android), mobile app version, and code push update number (if any) */
const getMobileClientInfo = async () => {
const mobilePlatform = Platform.OS
const mobileAppVersion = VersionNumber.appVersion

let codePushUpdateMetadata: LocalPackage | null = null
/** Returns version in the form of `a1.1.33+codepush:v5` if Android, `i1.1.33+codepush:v5` if iOS. The `+codepush:*` portion is omitted if there is no CodePush update installed. */
const getMobileClientVersion = async () => {
const baseVersion = `${Platform.OS === 'android' ? 'a' : 'i'}${
VersionNumber.appVersion
}`
let res = baseVersion // This is our default value if getting the CodePush update metadata fails for some reason, or if there is no CodePush update installed.
let codePushUpdateMetadata: LocalPackage | null
try {
codePushUpdateMetadata = await codePush.getUpdateMetadata()
} catch (e) {
console.error(
'Error getting CodePush metadata for remote config instance.',
e
)
return res
}

let codePushUpdateNumber: number | undefined
if (
codePushUpdateMetadata &&
codePushUpdateMetadata.label &&
codePushUpdateMetadata.label.length > 1
) {
// Codepush version nunbers are formatted as e.g."v10" - remove the leading "v".
codePushUpdateNumber = Number(codePushUpdateMetadata.label.slice(1))
}
return {
mobilePlatform,
mobileAppVersion,
codePushUpdateNumber
if (codePushUpdateMetadata) {
res = `${baseVersion}+codepush:${codePushUpdateMetadata.label}`
}
return res
}

export const remoteConfigInstance = remoteConfig({
appVersion,
platform: 'mobile',
getMobileClientInfo,
getMobileClientVersion,
createOptimizelyClient: async () => {
return optimizely.createInstance({
sdkKey: OPTIMIZELY_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import optimizely, { Config } from '@optimizely/optimizely-sdk'
import { isEmpty } from 'lodash'

import { reportToSentry } from 'store/errors/reportToSentry'
import { isElectron } from 'utils/clientUtil'

import packageInfo from '../../../package.json'

Expand All @@ -19,7 +18,6 @@ export const FEATURE_FLAG_LOCAL_STORAGE_SESSION_KEY = 'featureFlagSessionId-2'

export const remoteConfigInstance = remoteConfig({
appVersion,
platform: isElectron() ? 'desktop' : 'web',
createOptimizelyClient: async () => {
// Wait for optimizely to load if necessary (as it can be an async or defer tag)
if (!window.optimizelyDatafile) {
Expand Down

0 comments on commit a2f9caa

Please sign in to comment.