-
Notifications
You must be signed in to change notification settings - Fork 14
chore(setup): add SDK init/injection library and templates #751
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3a1d4dd
chore(setup): add SDK/project detection library
ffantl-ld 9efecc7
fix(setup): report whether the detected entry point exists
ffantl-ld 2259349
fix(setup): keep the Next.js SDK key out of the browser bundle
ffantl-ld 3fefe37
docs(setup): cite the sources for the entry-point candidates
ffantl-ld c276645
fix(setup): detect backend manifests before package.json
ffantl-ld 0b61639
test(setup): assert the whole result per project shape
ffantl-ld b5d737c
fix(setup): find the src/main entry a Node app bootstraps from
ffantl-ld 37bb50b
chore(setup): add SDK installer library
ffantl-ld 6d3551a
fix(setup): install with the project's own package manager
ffantl-ld 45e5847
fix(setup): match whole packages and target the right .NET project
ffantl-ld d2de7f2
chore(setup): add SDK init/injection library and templates
ffantl-ld 0d6a927
fix(setup): correct the React Native init snippet
ffantl-ld 519fe65
fix(setup): pass the required auto-env argument in mobile snippets
ffantl-ld 8daf723
fix(setup): build the Swift context without try
ffantl-ld 82b2cb3
Merge branch 'setup-ld' into ffantl/setup-ld/3-initializer
ffantl-ld 9126132
fix(setup): keep the shebang first when injecting imports
ffantl-ld 51ae9ec
fix(setup): inject node imports in the entry file's module syntax
ffantl-ld 26827c0
fix(setup): keep leading directives above injected imports
ffantl-ld 1d4cf46
fix(setup): treat block comments as part of the leading header
ffantl-ld File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import com.launchdarkly.sdk.android.*; | ||
| import com.launchdarkly.sdk.android.LDConfig.Builder.AutoEnvAttributes; | ||
| import com.launchdarkly.sdk.*; | ||
| // --- init --- | ||
| LDConfig ldConfig = new LDConfig.Builder(AutoEnvAttributes.Enabled) | ||
| .mobileKey("{{.MobileKey}}") | ||
| .build(); | ||
| LDContext ldContext = LDContext.builder(ContextKind.DEFAULT, "example-user-key") | ||
| .name("Example User") | ||
| .build(); | ||
| LDClient ldClient = LDClient.init(this.getApplication(), ldConfig, ldContext, 5); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using LaunchDarkly.Sdk; | ||
| using LaunchDarkly.Sdk.Server; | ||
| // --- init --- | ||
| var ldClient = new LdClient("{{.SDKKey}}"); | ||
|
|
||
| var context = Context.Builder("example-user-key") | ||
| .Name("Example User") | ||
| .Build(); | ||
|
|
||
| var flagValue = ldClient.BoolVariation("{{.FlagKey}}", context, false); | ||
| Console.WriteLine($"Flag '{{.FlagKey}}' is {flagValue}"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import ( | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/launchdarkly/go-sdk-common/v3/ldcontext" | ||
| ld "github.com/launchdarkly/go-server-sdk/v7" | ||
| ) | ||
| // --- init --- | ||
| ldClient, _ := ld.MakeClient("{{.SDKKey}}", 5*time.Second) | ||
|
|
||
| context := ldcontext.NewBuilder("example-user-key"). | ||
| Name("Example User"). | ||
| Build() | ||
|
|
||
| flagValue, _ := ldClient.BoolVariation("{{.FlagKey}}", context, false) | ||
| fmt.Printf("Flag '{{.FlagKey}}' is %t\n", flagValue) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import com.launchdarkly.sdk.*; | ||
| import com.launchdarkly.sdk.server.*; | ||
| // --- init --- | ||
| LDClient ldClient = new LDClient("{{.SDKKey}}"); | ||
|
|
||
| LDContext context = LDContext.builder("example-user-key") | ||
| .name("Example User") | ||
| .build(); | ||
|
|
||
| boolean flagValue = ldClient.boolVariation("{{.FlagKey}}", context, false); | ||
| System.out.println("Flag '{{.FlagKey}}' is " + flagValue); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import * as LDClient from 'launchdarkly-js-client-sdk'; | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| // --- init --- | ||
| const ldClient = LDClient.initialize('{{.ClientSideID}}', { | ||
| kind: 'user', | ||
| key: 'example-user-key', | ||
| name: 'Example User', | ||
| }); | ||
|
|
||
| ldClient.on('ready', () => { | ||
| const flagValue = ldClient.variation('{{.FlagKey}}', false); | ||
| console.log(`Flag '{{.FlagKey}}' is ${flagValue}`); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import * as LaunchDarkly from '@launchdarkly/node-server-sdk'; | ||
| // --- init --- | ||
| const ldClient = LaunchDarkly.init('{{.SDKKey}}'); | ||
|
|
||
| const context = { | ||
| kind: 'user', | ||
| key: 'example-user-key', | ||
| name: 'Example User', | ||
| }; | ||
|
|
||
| ldClient.on('ready', () => { | ||
| ldClient.variation('{{.FlagKey}}', context, false, (err, flagValue) => { | ||
| console.log(`Flag '{{.FlagKey}}' is ${flagValue}`); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| const LaunchDarkly = require('@launchdarkly/node-server-sdk'); | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| // --- init --- | ||
| const ldClient = LaunchDarkly.init('{{.SDKKey}}'); | ||
|
|
||
| const context = { | ||
| kind: 'user', | ||
| key: 'example-user-key', | ||
| name: 'Example User', | ||
| }; | ||
|
|
||
| ldClient.on('ready', () => { | ||
| ldClient.variation('{{.FlagKey}}', context, false, (err, flagValue) => { | ||
| console.log(`Flag '{{.FlagKey}}' is ${flagValue}`); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import ldclient | ||
| from ldclient import Context | ||
| from ldclient.config import Config | ||
| # --- init --- | ||
| ldclient.set_config(Config("{{.SDKKey}}")) | ||
| ld_client = ldclient.get() | ||
|
|
||
| context = Context.builder("example-user-key").name("Example User").build() | ||
|
|
||
| flag_value = ld_client.variation("{{.FlagKey}}", context, False) | ||
| print(f"Flag '{{.FlagKey}}' is {flag_value}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { asyncWithLDProvider } from 'launchdarkly-react-client-sdk'; | ||
| // --- init --- | ||
| const LDProvider = await asyncWithLDProvider({ | ||
| clientSideID: '{{.ClientSideID}}', | ||
| context: { | ||
| kind: 'user', | ||
| key: 'example-user-key', | ||
| name: 'Example User', | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { AutoEnvAttributes, ReactNativeLDClient } from '@launchdarkly/react-native-client-sdk'; | ||
| // --- init --- | ||
| const featureClient = new ReactNativeLDClient('{{.MobileKey}}', AutoEnvAttributes.Enabled); | ||
| await featureClient.identify({ kind: 'user', key: 'example-user-key', name: 'Example User' }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| require 'ldclient-rb' | ||
| # --- init --- | ||
| ld_client = LaunchDarkly::LDClient.new("{{.SDKKey}}") | ||
|
|
||
| context = LaunchDarkly::LDContext.create({ | ||
| key: "example-user-key", | ||
| kind: "user", | ||
| name: "Example User" | ||
| }) | ||
|
|
||
| flag_value = ld_client.variation("{{.FlagKey}}", context, false) | ||
| puts "Flag '{{.FlagKey}}' is #{flag_value}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import LaunchDarkly | ||
| // --- init --- | ||
| let ldConfig = LDConfig(mobileKey: "{{.MobileKey}}", autoEnvAttributes: .enabled) | ||
| guard case .success(let ldContext) = LDContextBuilder(key: "example-user-key").build() | ||
| else { return } | ||
| LDClient.start(config: ldConfig, context: ldContext) | ||
|
cursor[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.