Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Use local api for self hosted snippets #4807

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
4 changes: 3 additions & 1 deletion frontend/common/code-help/create-user/create-user-curl.js
Original file line number Diff line number Diff line change
@@ -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}'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = (
) => `final flagsmithClient = FlagsmithClient(
apiKey: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n baseURI: '${Project.flagsmithClientAPI}',`
? `\n baseURI: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
config: config,
Expand All @@ -19,7 +19,7 @@ module.exports = (
//final flagsmithClient = await FlagsmithClient.init(
// apiKey: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n// baseURI: '${Project.flagsmithClientAPI}',`
? `\n// baseURI: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
// config: config,
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/create-user/create-user-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func application(_ application: UIApplication,

Flagsmith.shared.apiKey = "${envId}"${
Constants.isCustomFlagsmithUrl &&
`\n Flagsmith.shared.baseURL = "${Project.flagsmithClientAPI}"\n`
`\n Flagsmith.shared.baseURL = "${Constants.getFlagsmithSDKUrl()}"\n`
}

// This will create a user in the dashboard if they don't already exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (
.setApiKey("${envId}")${
Constants.isCustomFlagsmithUrl &&
`\n .withConfiguration(FlagsmithConfig.builder()
.baseUri("${Project.flagsmithClientAPI}")
.baseUri("${Constants.getFlagsmithSDKUrl()}")
.build())`
}
.build();
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/create-user/create-user-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = (
${LIB_NAME}.init({
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
identity: "${userId || USER_ID}",
Expand Down
4 changes: 2 additions & 2 deletions frontend/common/code-help/create-user/create-user-next.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function App({ Component, pageProps, flagsmithState } {
options={{
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
}}
Expand All @@ -43,7 +43,7 @@ MyApp.getInitialProps = async () => {
await flagsmith.init({ // fetches flags on the server
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
preventFetch: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (

const ${LIB_NAME} = new Flagsmith({${
Constants.isCustomFlagsmithUrl &&
`\n apiUrl: '${Project.flagsmithClientAPI}',`
`\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',`
}
environmentKey: '${envId}'
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/create-user/create-user-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (

flagsmith = Flagsmith(environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

# Identify the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function App() {
options={{
environmentID: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n api: '${Project.flagsmithClientAPI}',`
? `\n api: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
identity: '${userId || USER_ID}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (
$flagsmith = Flagsmith::Client.new(
environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

// Identify the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use flagsmith::{Flag, Flagsmith, FlagsmithOptions};

let options = FlagsmithOptions {${
Constants.isCustomFlagsmithUrl &&
`api_url: "${Project.flagsmithClientAPI}".to_string(),\n`
`api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n`
}..Default::default()};
let flagsmith = Flagsmith::new(
"${envId}".to_string(),
Expand Down
4 changes: 3 additions & 1 deletion frontend/common/code-help/init/init-curl.js
Original file line number Diff line number Diff line change
@@ -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}'
`
6 changes: 5 additions & 1 deletion frontend/common/code-help/init/init-dotnet.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import Constants from 'common/constants'

module.exports = (
envId,
{ FEATURE_NAME, FEATURE_NAME_ALT },
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions frontend/common/code-help/init/init-flutter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (
final flagsmithClient = FlagsmithClient(
apiKey: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n baseURI: '${Project.flagsmithClientAPI}',`
? `\n baseURI: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
config: config,
Expand All @@ -20,7 +20,7 @@ final flagsmithClient = FlagsmithClient(
//final flagsmithClient = await FlagsmithClient.init(
// apiKey: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n// baseURI: '${Project.flagsmithClientAPI}',`
? `\n// baseURI: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
// config: config,
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-go.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defer cancel()
// Initialise the Flagsmith client
client := flagsmith.NewClient('${envId}',${
Constants.isCustomFlagsmithUrl &&
`\nflagsmith.WithBaseURL("${Project.flagsmithClientAPI}"),\n`
`\nflagsmith.WithBaseURL("${Constants.getFlagsmithSDKUrl()}"),\n`
}flagsmith.WithContext(ctx))

// The method below triggers a network request
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func application(_ application: UIApplication,

Flagsmith.shared.apiKey = "${envId}"${
Constants.isCustomFlagsmithUrl &&
`\n Flagsmith.shared.baseURL = "${Project.flagsmithClientAPI}"\n`
`\n Flagsmith.shared.baseURL = "${Constants.getFlagsmithSDKUrl()}"\n`
}
// Check for a feature
Flagsmith.shared
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (
.setApiKey("${envId}")${
Constants.isCustomFlagsmithUrl
? `\n .withConfiguration(FlagsmithConfig.newBuilder()
.baseUri("${Project.flagsmithClientAPI}")
.baseUri("${Constants.getFlagsmithSDKUrl()}")
.build())`
: ''
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions frontend/common/code-help/init/init-next.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function App({ Component, pageProps, flagsmithState } {
options={{
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
}}
Expand All @@ -27,7 +27,7 @@ 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}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (

const ${LIB_NAME} = new Flagsmith({${
Constants.isCustomFlagsmithUrl &&
`\n apiUrl: '${Project.flagsmithClientAPI}',`
`\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',`
}
environmentKey: '${envId}'
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (

flagsmith = Flagsmith(environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

# The method below triggers a network request
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function App() {
options={{
environmentID: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n api: '${Project.flagsmithClientAPI}',`
? `\n api: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
}}
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (
$flagsmith = Flagsmith::Client.new(
environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

// Load the environment's flags locally
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/init/init-rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use flagsmith::{Flag, Flagsmith, FlagsmithOptions};

let options = FlagsmithOptions {${
Constants.isCustomFlagsmithUrl &&
`api_url: "${Project.flagsmithClientAPI}".to_string(),\n`
`api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n`
}..Default::default()};
let flagsmith = Flagsmith::new(
"${envId}".to_string(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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
`
Original file line number Diff line number Diff line change
@@ -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
`
4 changes: 3 additions & 1 deletion frontend/common/code-help/traits/traits-curl.js
Original file line number Diff line number Diff line change
@@ -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 $'{
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-java.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = (
.setApiKey("${envId}")${
Constants.isCustomFlagsmithUrl &&
`\n .withConfiguration(FlagsmithConfig.builder()
.baseUri("${Project.flagsmithClientAPI}")
.baseUri("${Constants.getFlagsmithSDKUrl()}")
.build())`
}
.build();
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (
${LIB_NAME}.init({
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
identity: "${userId || USER_ID}",
Expand Down
4 changes: 2 additions & 2 deletions frontend/common/code-help/traits/traits-next.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function App({ Component, pageProps, flagsmithState } {
options={{
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
}}
Expand All @@ -51,7 +51,7 @@ MyApp.getInitialProps = async () => {
await flagsmith.init({ // fetches flags on the server
environmentID: "${envId}",${
Constants.isCustomFlagsmithUrl
? `\n api: "${Project.flagsmithClientAPI}",`
? `\n api: "${Constants.getFlagsmithSDKUrl()}",`
: ''
}
preventFetch: true
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (

const ${LIB_NAME} = new Flagsmith({${
Constants.isCustomFlagsmithUrl &&
`\n apiUrl: '${Project.flagsmithClientAPI}',`
`\n apiUrl: '${Constants.getFlagsmithSDKUrl()}',`
}
environmentKey: '${envId}'
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-php.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-python.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (

flagsmith = Flagsmith(environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

traits = {"${TRAIT_NAME}": 42}
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function App() {
options={{
environmentID: '${envId}',${
Constants.isCustomFlagsmithUrl
? `\n api: '${Project.flagsmithClientAPI}',`
? `\n api: '${Constants.getFlagsmithSDKUrl()}',`
: ''
}
identity: '${userId || USER_ID}',
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-ruby.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = (envId, { TRAIT_NAME }, userId) => `require "flagsmith"
$flagsmith = Flagsmith::Client.new(
environment_key="${envId}"${
Constants.isCustomFlagsmithUrl &&
`,\n api_url="${Project.flagsmithClientAPI}"\n`
`,\n api_url="${Constants.getFlagsmithSDKUrl()}"\n`
})

traits = {"${TRAIT_NAME}": 42}
Expand Down
2 changes: 1 addition & 1 deletion frontend/common/code-help/traits/traits-rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use flagsmith_flag_engine::identities::Trait;

let options = FlagsmithOptions {${
Constants.isCustomFlagsmithUrl &&
`api_url: "${Project.flagsmithClientAPI}".to_string(),\n`
`api_url: "${Constants.getFlagsmithSDKUrl()}".to_string(),\n`
}..Default::default()};
let flagsmith = Flagsmith::new(
"${envId}".to_string(),
Expand Down
Loading
Loading