diff --git a/frontend/common/code-help/create-user/create-user-curl.js b/frontend/common/code-help/create-user/create-user-curl.js index a13d8edc5224..61b439ceb38b 100644 --- a/frontend/common/code-help/create-user/create-user-curl.js +++ b/frontend/common/code-help/create-user/create-user-curl.js @@ -1,6 +1,8 @@ +import Constants from 'common/constants' + module.exports = (envId, { USER_ID }, userId) => `// Identify/create user -curl -i '${Project.flagsmithClientAPI}identities/?identifier=${ +curl -i '${Constants.getFlagsmithSDKUrl()}identities/?identifier=${ userId || USER_ID }' \\ -H 'x-environment-key: ${envId}' diff --git a/frontend/common/code-help/create-user/create-user-flutter.js b/frontend/common/code-help/create-user/create-user-flutter.js index c639c79ed466..1aacaedc5341 100644 --- a/frontend/common/code-help/create-user/create-user-flutter.js +++ b/frontend/common/code-help/create-user/create-user-flutter.js @@ -5,8 +5,8 @@ module.exports = ( userId, ) => `final flagsmithClient = FlagsmithClient( apiKey: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n baseURI: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n baseURI: '${Constants.getFlagsmithSDKUrl()}',` : '' } config: config, @@ -18,8 +18,8 @@ module.exports = ( //if you prefer async initialization then you should use //final flagsmithClient = await FlagsmithClient.init( // apiKey: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n// baseURI: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n// baseURI: '${Constants.getFlagsmithSDKUrl()}',` : '' } // config: config, diff --git a/frontend/common/code-help/create-user/create-user-ios.js b/frontend/common/code-help/create-user/create-user-ios.js index c1fbe2958494..fc285ae62d96 100644 --- a/frontend/common/code-help/create-user/create-user-ios.js +++ b/frontend/common/code-help/create-user/create-user-ios.js @@ -11,8 +11,8 @@ func application(_ application: UIApplication, [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Flagsmith.shared.apiKey = "${envId}"${ - Constants.isCustomFlagsmithUrl && - `\n Flagsmith.shared.baseURL = "${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `\n Flagsmith.shared.baseURL = "${Constants.getFlagsmithSDKUrl()}"\n` } // This will create a user in the dashboard if they don't already exist diff --git a/frontend/common/code-help/create-user/create-user-java.js b/frontend/common/code-help/create-user/create-user-java.js index 40809e0af308..db8d0bf0894a 100644 --- a/frontend/common/code-help/create-user/create-user-java.js +++ b/frontend/common/code-help/create-user/create-user-java.js @@ -7,9 +7,9 @@ module.exports = ( ) => `${LIB_NAME_JAVA} ${LIB_NAME} = ${LIB_NAME_JAVA} .newBuilder() .setApiKey("${envId}")${ - Constants.isCustomFlagsmithUrl && + Constants.isCustomFlagsmithUrl() && `\n .withConfiguration(FlagsmithConfig.builder() - .baseUri("${Project.flagsmithClientAPI}") + .baseUri("${Constants.getFlagsmithSDKUrl()}") .build())` } .build(); diff --git a/frontend/common/code-help/create-user/create-user-js.js b/frontend/common/code-help/create-user/create-user-js.js index eaa8aad92bf1..892e2eb4614f 100644 --- a/frontend/common/code-help/create-user/create-user-js.js +++ b/frontend/common/code-help/create-user/create-user-js.js @@ -15,8 +15,8 @@ module.exports = ( // Option 1: initialise with an identity and traits ${LIB_NAME}.init({ environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } identity: "${userId || USER_ID}", diff --git a/frontend/common/code-help/create-user/create-user-next.js b/frontend/common/code-help/create-user/create-user-next.js index 796ace1b04c1..68cb4585b42b 100644 --- a/frontend/common/code-help/create-user/create-user-next.js +++ b/frontend/common/code-help/create-user/create-user-next.js @@ -27,8 +27,8 @@ export default function App({ Component, pageProps, flagsmithState } { serverState={flagsmithState} options={{ environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } }} @@ -42,8 +42,8 @@ MyApp.getInitialProps = async () => { // calls page's \`getInitialProps\` and fills \`appProps.pageProps\` await flagsmith.init({ // fetches flags on the server environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } preventFetch: true diff --git a/frontend/common/code-help/create-user/create-user-node.js b/frontend/common/code-help/create-user/create-user-node.js index 46e393cb1a1b..d1c3f8de2d23 100644 --- a/frontend/common/code-help/create-user/create-user-node.js +++ b/frontend/common/code-help/create-user/create-user-node.js @@ -7,8 +7,8 @@ module.exports = ( ) => `import Flagsmith from "${NPM_NODE_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm const ${LIB_NAME} = new Flagsmith({${ - Constants.isCustomFlagsmithUrl && - `\n apiUrl: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() && + `\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',` } environmentKey: '${envId}' }); diff --git a/frontend/common/code-help/create-user/create-user-php.js b/frontend/common/code-help/create-user/create-user-php.js index 1995d959d0df..89bdfcf2d173 100644 --- a/frontend/common/code-help/create-user/create-user-php.js +++ b/frontend/common/code-help/create-user/create-user-php.js @@ -7,7 +7,7 @@ module.exports = ( ) => `use Flagsmith\\Flagsmith; $flagsmith = new Flagsmith('${envId}'${ - Constants.isCustomFlagsmithUrl && `,\n '${Project.flagsmithClientAPI}'\n` + Constants.isCustomFlagsmithUrl() && `,\n '${Constants.getFlagsmithSDKUrl()}'\n` }); // Identify the user diff --git a/frontend/common/code-help/create-user/create-user-python.js b/frontend/common/code-help/create-user/create-user-python.js index 82c8bbf9e42a..bc3e32a28a71 100644 --- a/frontend/common/code-help/create-user/create-user-python.js +++ b/frontend/common/code-help/create-user/create-user-python.js @@ -7,8 +7,8 @@ module.exports = ( ) => `from flagsmith import Flagsmith flagsmith = Flagsmith(environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) # Identify the user diff --git a/frontend/common/code-help/create-user/create-user-react.js b/frontend/common/code-help/create-user/create-user-react.js index 2b17dd249c76..193b969a9aa0 100644 --- a/frontend/common/code-help/create-user/create-user-react.js +++ b/frontend/common/code-help/create-user/create-user-react.js @@ -13,8 +13,8 @@ export default function App() { <FlagsmithProvider options={{ environmentID: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n api: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n api: '${Constants.getFlagsmithSDKUrl()}',` : '' } identity: '${userId || USER_ID}', diff --git a/frontend/common/code-help/create-user/create-user-ruby.js b/frontend/common/code-help/create-user/create-user-ruby.js index 5da2f36aeedd..80a7f4b7e057 100644 --- a/frontend/common/code-help/create-user/create-user-ruby.js +++ b/frontend/common/code-help/create-user/create-user-ruby.js @@ -8,8 +8,8 @@ module.exports = ( $flagsmith = Flagsmith::Client.new( environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) // Identify the user diff --git a/frontend/common/code-help/create-user/create-user-rust.js b/frontend/common/code-help/create-user/create-user-rust.js index 93fdd7818f79..cee264a873bb 100644 --- a/frontend/common/code-help/create-user/create-user-rust.js +++ b/frontend/common/code-help/create-user/create-user-rust.js @@ -8,8 +8,8 @@ module.exports = ( use flagsmith::{Flag, Flagsmith, FlagsmithOptions}; let options = FlagsmithOptions {${ - Constants.isCustomFlagsmithUrl && - `api_url: "${Project.flagsmithClientAPI}".to_string(),\n` + Constants.isCustomFlagsmithUrl() && + `api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n` }..Default::default()}; let flagsmith = Flagsmith::new( "${envId}".to_string(), diff --git a/frontend/common/code-help/init/init-curl.js b/frontend/common/code-help/init/init-curl.js index 5f847440ad67..6abe379b1bc8 100644 --- a/frontend/common/code-help/init/init-curl.js +++ b/frontend/common/code-help/init/init-curl.js @@ -1,4 +1,6 @@ +import Constants from 'common/constants' + module.exports = (envId) => ` -curl -i '${Project.flagsmithClientAPI}flags/' \\ +curl -i '${Constants.getFlagsmithSDKUrl()}flags/' \\ -H 'x-environment-key: ${envId}' ` diff --git a/frontend/common/code-help/init/init-dotnet.js b/frontend/common/code-help/init/init-dotnet.js index 6be49b891dfa..2aed77aec70f 100644 --- a/frontend/common/code-help/init/init-dotnet.js +++ b/frontend/common/code-help/init/init-dotnet.js @@ -1,3 +1,5 @@ +import Constants from 'common/constants' + module.exports = ( envId, { FEATURE_NAME, FEATURE_NAME_ALT }, @@ -6,7 +8,9 @@ module.exports = ( static FlagsmithClient _flagsmithClient; -_flagsmithClient = new("${envId}"); +_flagsmithClient = new("${envId}"${ + Constants.isCustomFlagsmithUrl() ? `, apiUrl: ${Constants.getFlagsmithSDKUrl()}` : '' +}); var flags = await _flagsmithClient.GetEnvironmentFlags(); # This method triggers a network request diff --git a/frontend/common/code-help/init/init-flutter.js b/frontend/common/code-help/init/init-flutter.js index bcd3c531b0df..deb8da2fa4b9 100644 --- a/frontend/common/code-help/init/init-flutter.js +++ b/frontend/common/code-help/init/init-flutter.js @@ -6,8 +6,8 @@ module.exports = ( final flagsmithClient = FlagsmithClient( apiKey: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n baseURI: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n baseURI: '${Constants.getFlagsmithSDKUrl()}',` : '' } config: config, @@ -19,8 +19,8 @@ final flagsmithClient = FlagsmithClient( //if you prefer async initialization then you should use //final flagsmithClient = await FlagsmithClient.init( // apiKey: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n// baseURI: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n// baseURI: '${Constants.getFlagsmithSDKUrl()}',` : '' } // config: config, diff --git a/frontend/common/code-help/init/init-go.js b/frontend/common/code-help/init/init-go.js index 3441e307a04b..f86359c56b2c 100644 --- a/frontend/common/code-help/init/init-go.js +++ b/frontend/common/code-help/init/init-go.js @@ -6,8 +6,8 @@ defer cancel() // Initialise the Flagsmith client client := flagsmith.NewClient('${envId}',${ - Constants.isCustomFlagsmithUrl && - `\nflagsmith.WithBaseURL("${Project.flagsmithClientAPI}"),\n` + Constants.isCustomFlagsmithUrl() && + `\nflagsmith.WithBaseURL("${Constants.getFlagsmithSDKUrl()}"),\n` }flagsmith.WithContext(ctx)) // The method below triggers a network request diff --git a/frontend/common/code-help/init/init-ios.js b/frontend/common/code-help/init/init-ios.js index e983bd0a1e5c..52c81256955b 100644 --- a/frontend/common/code-help/init/init-ios.js +++ b/frontend/common/code-help/init/init-ios.js @@ -9,8 +9,8 @@ func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Flagsmith.shared.apiKey = "${envId}"${ - Constants.isCustomFlagsmithUrl && - `\n Flagsmith.shared.baseURL = "${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `\n Flagsmith.shared.baseURL = "${Constants.getFlagsmithSDKUrl()}"\n` } // Check for a feature Flagsmith.shared diff --git a/frontend/common/code-help/init/init-java.js b/frontend/common/code-help/init/init-java.js index 35b86ebe131b..ea5c8b5a5635 100644 --- a/frontend/common/code-help/init/init-java.js +++ b/frontend/common/code-help/init/init-java.js @@ -6,9 +6,9 @@ module.exports = ( ) => `${LIB_NAME_JAVA} ${LIB_NAME} = ${LIB_NAME_JAVA} .newBuilder() .setApiKey("${envId}")${ - Constants.isCustomFlagsmithUrl + Constants.isCustomFlagsmithUrl() ? `\n .withConfiguration(FlagsmithConfig.newBuilder() - .baseUri("${Project.flagsmithClientAPI}") + .baseUri("${Constants.getFlagsmithSDKUrl()}") .build())` : '' } diff --git a/frontend/common/code-help/init/init-js.js b/frontend/common/code-help/init/init-js.js index def8e9a2867e..b2a57ed20d61 100644 --- a/frontend/common/code-help/init/init-js.js +++ b/frontend/common/code-help/init/init-js.js @@ -6,7 +6,7 @@ module.exports = ( ) => `import ${LIB_NAME} from "${NPM_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm ${LIB_NAME}.init({ - environmentID: "${envId}",${Constants.isCustomFlagsmithUrl ? `\n api: "${Project.flagsmithClientAPI}",` : ''} + environmentID: "${envId}",${Constants.isCustomFlagsmithUrl() ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : ''} onChange: (oldFlags, params) => { // Occurs whenever flags are changed // Determines if the update came from the server or local cached storage const { isFromServer } = params; diff --git a/frontend/common/code-help/init/init-next.js b/frontend/common/code-help/init/init-next.js index 07e0047ad0e9..5c42a0ab3806 100644 --- a/frontend/common/code-help/init/init-next.js +++ b/frontend/common/code-help/init/init-next.js @@ -12,8 +12,8 @@ export default function App({ Component, pageProps, flagsmithState } { serverState={flagsmithState} options={{ environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } }} @@ -26,8 +26,8 @@ export default function App({ Component, pageProps, flagsmithState } { App.getInitialProps = async () => { await flagsmith.init({ // fetches flags on the server and passes them to the App environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } }); diff --git a/frontend/common/code-help/init/init-node.js b/frontend/common/code-help/init/init-node.js index 4c49926e9a06..8d65ff81bf0a 100644 --- a/frontend/common/code-help/init/init-node.js +++ b/frontend/common/code-help/init/init-node.js @@ -7,8 +7,8 @@ module.exports = ( ) => `import Flagsmith from "${NPM_NODE_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm const ${LIB_NAME} = new Flagsmith({${ - Constants.isCustomFlagsmithUrl && - `\n apiUrl: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() && + `\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',` } environmentKey: '${envId}' }); diff --git a/frontend/common/code-help/init/init-php.js b/frontend/common/code-help/init/init-php.js index 9d27c31711a4..d7fed21aa469 100644 --- a/frontend/common/code-help/init/init-php.js +++ b/frontend/common/code-help/init/init-php.js @@ -5,7 +5,7 @@ module.exports = ( ) => `use Flagsmith\\Flagsmith; $flagsmith = new Flagsmith('${envId}'${ - Constants.isCustomFlagsmithUrl && `,\n '${Project.flagsmithClientAPI}'\n` + Constants.isCustomFlagsmithUrl() && `,\n '${Constants.getFlagsmithSDKUrl()}'\n` }); // Check for a feature diff --git a/frontend/common/code-help/init/init-python.js b/frontend/common/code-help/init/init-python.js index 088300c490e9..0400b24488c1 100644 --- a/frontend/common/code-help/init/init-python.js +++ b/frontend/common/code-help/init/init-python.js @@ -6,8 +6,8 @@ module.exports = ( ) => `from flagsmith import Flagsmith flagsmith = Flagsmith(environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) # The method below triggers a network request diff --git a/frontend/common/code-help/init/init-react.js b/frontend/common/code-help/init/init-react.js index f04e0233719f..4b9a7e3d9527 100644 --- a/frontend/common/code-help/init/init-react.js +++ b/frontend/common/code-help/init/init-react.js @@ -12,8 +12,8 @@ export default function App() { <FlagsmithProvider options={{ environmentID: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n api: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n api: '${Constants.getFlagsmithSDKUrl()}',` : '' } }} diff --git a/frontend/common/code-help/init/init-ruby.js b/frontend/common/code-help/init/init-ruby.js index 2d91a0006fc3..194818449d7a 100644 --- a/frontend/common/code-help/init/init-ruby.js +++ b/frontend/common/code-help/init/init-ruby.js @@ -8,8 +8,8 @@ module.exports = ( $flagsmith = Flagsmith::Client.new( environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) // Load the environment's flags locally diff --git a/frontend/common/code-help/init/init-rust.js b/frontend/common/code-help/init/init-rust.js index f547961eded4..a7776e4a17d2 100644 --- a/frontend/common/code-help/init/init-rust.js +++ b/frontend/common/code-help/init/init-rust.js @@ -4,8 +4,8 @@ module.exports = (envId, { FEATURE_NAME, FEATURE_NAME_ALT }) => ` use flagsmith::{Flag, Flagsmith, FlagsmithOptions}; let options = FlagsmithOptions {${ - Constants.isCustomFlagsmithUrl && - `api_url: "${Project.flagsmithClientAPI}".to_string(),\n` + Constants.isCustomFlagsmithUrl() && + `api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n` }..Default::default()}; let flagsmith = Flagsmith::new( "${envId}".to_string(), diff --git a/frontend/common/code-help/offline_client/offline-client-curl.js b/frontend/common/code-help/offline_client/offline-client-curl.js index ceee3d366008..014f3fc9c083 100644 --- a/frontend/common/code-help/offline_client/offline-client-curl.js +++ b/frontend/common/code-help/offline_client/offline-client-curl.js @@ -1,4 +1,6 @@ +import Constants from 'common/constants' + module.exports = (envId) => ` -curl -i '${Project.flagsmithClientAPI}flags/' \\ +curl -i '${Constants.getFlagsmithSDKUrl()}flags/' \\ -H 'x-environment-key: ${envId}' | tee flagsmith.json ` diff --git a/frontend/common/code-help/offline_server/offline-server-curl.js b/frontend/common/code-help/offline_server/offline-server-curl.js index 44ceb1f56f61..4f3e5e1d0cf1 100644 --- a/frontend/common/code-help/offline_server/offline-server-curl.js +++ b/frontend/common/code-help/offline_server/offline-server-curl.js @@ -1,4 +1,6 @@ +import Constants from 'common/constants' + module.exports = (serversideEnvironmentKey) => ` -curl -i '${Project.flagsmithClientAPI}environment-document/' \\ +curl -i '${Constants.getFlagsmithSDKUrl()}environment-document/' \\ -H 'x-environment-key: ${serversideEnvironmentKey}' | tee flagsmith.json ` diff --git a/frontend/common/code-help/traits/traits-curl.js b/frontend/common/code-help/traits/traits-curl.js index 4837e58c34bb..9f9bd71a1a32 100644 --- a/frontend/common/code-help/traits/traits-curl.js +++ b/frontend/common/code-help/traits/traits-curl.js @@ -1,8 +1,10 @@ +import Constants from 'common/constants' + module.exports = ( envId, { TRAIT_NAME, USER_ID }, userId, -) => `curl -i -X POST '${Project.flagsmithClientAPI}identities/' \\ +) => `curl -i -X POST '${Constants.getFlagsmithSDKUrl()}identities/' \\ -H 'x-environment-key: ${envId}' \\ -H 'Content-Type: application/json; charset=utf-8' \\ -d $'{ diff --git a/frontend/common/code-help/traits/traits-java.js b/frontend/common/code-help/traits/traits-java.js index 6b4db8cb1815..6f74d258e3ba 100644 --- a/frontend/common/code-help/traits/traits-java.js +++ b/frontend/common/code-help/traits/traits-java.js @@ -7,9 +7,9 @@ module.exports = ( ) => `${LIB_NAME_JAVA} ${LIB_NAME} = ${LIB_NAME_JAVA} .newBuilder() .setApiKey("${envId}")${ - Constants.isCustomFlagsmithUrl && + Constants.isCustomFlagsmithUrl() && `\n .withConfiguration(FlagsmithConfig.builder() - .baseUri("${Project.flagsmithClientAPI}") + .baseUri("${Constants.getFlagsmithSDKUrl()}") .build())` } .build(); diff --git a/frontend/common/code-help/traits/traits-js.js b/frontend/common/code-help/traits/traits-js.js index 11f8708cf5a3..f705ab4da449 100644 --- a/frontend/common/code-help/traits/traits-js.js +++ b/frontend/common/code-help/traits/traits-js.js @@ -7,8 +7,8 @@ module.exports = ( ) => `// Option 1: initialise with an identity and traits ${LIB_NAME}.init({ environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } identity: "${userId || USER_ID}", diff --git a/frontend/common/code-help/traits/traits-next.js b/frontend/common/code-help/traits/traits-next.js index 11618d3b1752..e6e8db85ec9a 100644 --- a/frontend/common/code-help/traits/traits-next.js +++ b/frontend/common/code-help/traits/traits-next.js @@ -35,8 +35,8 @@ export default function App({ Component, pageProps, flagsmithState } { serverState={flagsmithState} options={{ environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } }} @@ -50,8 +50,8 @@ MyApp.getInitialProps = async () => { // calls page's \`getInitialProps\` and fills \`appProps.pageProps\` await flagsmith.init({ // fetches flags on the server environmentID: "${envId}",${ - Constants.isCustomFlagsmithUrl - ? `\n api: "${Project.flagsmithClientAPI}",` + Constants.isCustomFlagsmithUrl() + ? `\n api: "${Constants.getFlagsmithSDKUrl()}",` : '' } preventFetch: true diff --git a/frontend/common/code-help/traits/traits-node.js b/frontend/common/code-help/traits/traits-node.js index 0692cdd2a963..1ff7a3e48c13 100644 --- a/frontend/common/code-help/traits/traits-node.js +++ b/frontend/common/code-help/traits/traits-node.js @@ -7,8 +7,8 @@ module.exports = ( ) => `import Flagsmith from "${NPM_NODE_CLIENT}"; // Add this line if you're using ${LIB_NAME} via npm const ${LIB_NAME} = new Flagsmith({${ - Constants.isCustomFlagsmithUrl && - `\n apiUrl: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() && + `\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',` } environmentKey: '${envId}' }); diff --git a/frontend/common/code-help/traits/traits-php.js b/frontend/common/code-help/traits/traits-php.js index e889ea288e43..ac92c5fbc6ac 100644 --- a/frontend/common/code-help/traits/traits-php.js +++ b/frontend/common/code-help/traits/traits-php.js @@ -2,7 +2,7 @@ import Constants from 'common/constants' module.exports = (envId, { TRAIT_NAME }, userId) => `use Flagsmith\\Flagsmith; $flagsmith = new Flagsmith('${envId}'${ - Constants.isCustomFlagsmithUrl && `,\n '${Project.flagsmithClientAPI}'\n` + Constants.isCustomFlagsmithUrl() && `,\n '${Constants.getFlagsmithSDKUrl()}'\n` }); $traits = (object) [ '${TRAIT_NAME}' => 42 ]; diff --git a/frontend/common/code-help/traits/traits-python.js b/frontend/common/code-help/traits/traits-python.js index 45f65e79c72f..95a08591ed21 100644 --- a/frontend/common/code-help/traits/traits-python.js +++ b/frontend/common/code-help/traits/traits-python.js @@ -7,8 +7,8 @@ module.exports = ( ) => `from flagsmith import Flagsmith flagsmith = Flagsmith(environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) traits = {"${TRAIT_NAME}": 42} diff --git a/frontend/common/code-help/traits/traits-react.js b/frontend/common/code-help/traits/traits-react.js index dd80794752c0..95a79527d9a3 100644 --- a/frontend/common/code-help/traits/traits-react.js +++ b/frontend/common/code-help/traits/traits-react.js @@ -13,8 +13,8 @@ export default function App() { <FlagsmithProvider options={{ environmentID: '${envId}',${ - Constants.isCustomFlagsmithUrl - ? `\n api: '${Project.flagsmithClientAPI}',` + Constants.isCustomFlagsmithUrl() + ? `\n api: '${Constants.getFlagsmithSDKUrl()}',` : '' } identity: '${userId || USER_ID}', diff --git a/frontend/common/code-help/traits/traits-ruby.js b/frontend/common/code-help/traits/traits-ruby.js index bde960f914e3..4e4b2e852b4d 100644 --- a/frontend/common/code-help/traits/traits-ruby.js +++ b/frontend/common/code-help/traits/traits-ruby.js @@ -4,8 +4,8 @@ module.exports = (envId, { TRAIT_NAME }, userId) => `require "flagsmith" $flagsmith = Flagsmith::Client.new( environment_key="${envId}"${ - Constants.isCustomFlagsmithUrl && - `,\n api_url="${Project.flagsmithClientAPI}"\n` + Constants.isCustomFlagsmithUrl() && + `,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n` }) traits = {"${TRAIT_NAME}": 42} diff --git a/frontend/common/code-help/traits/traits-rust.js b/frontend/common/code-help/traits/traits-rust.js index f2ea797712e7..225116ed2530 100644 --- a/frontend/common/code-help/traits/traits-rust.js +++ b/frontend/common/code-help/traits/traits-rust.js @@ -6,8 +6,8 @@ use flagsmith_flag_engine::types::{FlagsmithValue, FlagsmithValueType}; use flagsmith_flag_engine::identities::Trait; let options = FlagsmithOptions {${ - Constants.isCustomFlagsmithUrl && - `api_url: "${Project.flagsmithClientAPI}".to_string(),\n` + Constants.isCustomFlagsmithUrl() && + `api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n` }..Default::default()}; let flagsmith = Flagsmith::new( "${envId}".to_string(), diff --git a/frontend/common/constants.ts b/frontend/common/constants.ts index ecb4b967560c..3d7d69984e7f 100644 --- a/frontend/common/constants.ts +++ b/frontend/common/constants.ts @@ -22,7 +22,7 @@ const keywordsReactNative = { ...keywords, NPM_CLIENT: 'react-native-flagsmith', } -export default { +const Constants = { archivedTag: { color: '#8f8f8f', label: 'Archived' }, codeHelp: { 'CREATE_USER': (envId: string, userId: string = keywords.USER_ID) => ({ @@ -441,6 +441,10 @@ export default { 'TRAITS_ID': 150, }, }, + getFlagsmithSDKUrl: () => + Utils.isSaas() || Project.api.startsWith('https://api.flagsmith.com') + ? Project.flagsmithClientEdgeAPI + : Project.api, getUpgradeUrl: (feature?: string) => { return Utils.isSaas() ? '/organisation-settings?tab=billing' @@ -452,9 +456,9 @@ export default { githubIssue: 'GitHub Issue', githubPR: 'Github PR', }, + isCustomFlagsmithUrl: () => + Constants.getFlagsmithSDKUrl() !== 'https://edge.api.flagsmith.com/api/v1/', defaultTagColor: '#3d4db6', - isCustomFlagsmithUrl: - Project.flagsmithClientAPI !== 'https://edge.api.flagsmith.com/api/v1/', modals: { 'PAYMENT': 'Payment Modal', }, @@ -565,3 +569,5 @@ export default { ], untaggedTag: { color: '#dedede', label: 'Untagged' }, } + +export default Constants diff --git a/frontend/web/components/pages/UserPage.tsx b/frontend/web/components/pages/UserPage.tsx index 43454dc20e09..388e3d3ac437 100644 --- a/frontend/web/components/pages/UserPage.tsx +++ b/frontend/web/components/pages/UserPage.tsx @@ -1201,7 +1201,7 @@ const UserPage: FC = (props) => { title='Managing user traits and segments' snippets={Constants.codeHelp.USER_TRAITS( environmentId, - identity, + identity?.identifier, )} />