Skip to content

chore(setup): add SDK init/injection library and templates - #751

Open
ffantl-ld wants to merge 4 commits into
ffantl/setup-ld/2-installerfrom
ffantl/setup-ld/3-initializer
Open

chore(setup): add SDK init/injection library and templates#751
ffantl-ld wants to merge 4 commits into
ffantl/setup-ld/2-installerfrom
ffantl/setup-ld/3-initializer

Conversation

@ffantl-ld

@ffantl-ld ffantl-ld commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Describe the solution you've provided

Third layer of the guided setup command: SDK initialization. Renders per-SDK code snippets from embedded templates and injects them into the project (Initializer, RenderTemplate, InjectIntoFile), plus docs-URL helpers. Ships the sdk_init_templates/ for the supported SDKs.

Independent library layer.

Related issues

Part of the setup-ld feature. Stacked PR — base is ffantl/setup-ld/2-installer.

Requirements

  • I have added test coverage for new or changed functionality

Note

Medium Risk
Append-safe path mutates user project files and templates embed credentials placeholders; logic is well-tested but wrong injection could break entry files.

Overview
Adds the SDK initialization layer for guided setup: embedded per-SDK templates, rendering with InitConfig (SDK key, client-side ID, mobile key, flag key), and InjectIntoFile behavior that depends on language.

For append-safe runtimes (Node, Python, Ruby), init code is written into the target file—imports prepended, init block appended, or a default entry file created when missing. For compiled/framework SDKs (Go, Java, .NET, React, mobile, etc.), the user’s files are not modified; InitResult returns a copy-paste snippet plus a docs URL, with Success=false so callers don’t treat the project as auto-wired.

Also ships docs URL mapping for many SDK IDs (with or without templates), helpers like InjectsInPlace / DefaultEntryPoint, and tests that lock template imports to the packages InstallArgs installs.

Reviewed by Cursor Bugbot for commit 8daf723. Bugbot is set up for automated code reviews on this repo. Configure here.

@ffantl-ld
ffantl-ld marked this pull request as ready for review July 27, 2026 17:23
@ffantl-ld
ffantl-ld requested review from Vadman97 and erangeles July 27, 2026 17:23
Comment thread internal/setup/sdk_init_templates/react-native.tmpl Outdated
"python-server-sdk": "sdk/server-side/python",
"react-client-sdk": "sdk/client-side/react",
"react-native": "sdk/client-side/react-native",
"react-native-client-sdk": "sdk/client-side/react-native",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect React Native docs URL

Medium Severity

sdkDocsPaths maps react-native and react-native-client-sdk to sdk/client-side/react-native, but the live docs live at sdk/client-side/react/react-native. GetDocsURL therefore returns a dead link for those IDs.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.


content := string(existing)
if importSection != "" {
content = importSection + "\n" + content

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import prepend breaks shebang

High Severity

For append-safe SDKs, InjectIntoFile always prepends the import section at byte 0 of an existing file. That displaces a leading shebang and Python encoding cookies, so common entry points like manage.py stop being directly executable.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit c56c506. Configure here.

Comment thread internal/setup/sdk_init_templates/js-client-sdk.tmpl
@ffantl-ld
ffantl-ld requested review from a team and removed request for Vadman97 July 28, 2026 16:38
@ffantl-ld
ffantl-ld force-pushed the ffantl/setup-ld/3-initializer branch from c56c506 to 6a44381 Compare July 31, 2026 17:47
Comment thread internal/setup/sdk_init_templates/swift-client-sdk.tmpl Outdated
Comment thread internal/setup/sdk_init_templates/android.tmpl
@ffantl-ld
ffantl-ld force-pushed the ffantl/setup-ld/3-initializer branch from 6a44381 to 2efb79d Compare July 31, 2026 18:25
@@ -0,0 +1,15 @@
const LaunchDarkly = require('@launchdarkly/node-server-sdk');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node inject uses CommonJS only

Medium Severity

node-server is marked append-safe and its template loads the SDK with require, then InjectIntoFile reports Success. The detector often targets TypeScript or ESM entry points such as instrumentation.ts or src/index.ts, where CommonJS require fails at runtime, so setup can mark broken code as ready.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 2efb79d. Configure here.

@ffantl-ld
ffantl-ld force-pushed the ffantl/setup-ld/3-initializer branch from 2efb79d to 43d2d15 Compare August 3, 2026 18:52

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

There are 5 total unresolved issues (including 3 from previous reviews).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 43d2d15. Configure here.

"node-server": true,
"python-server-sdk": true,
"ruby-server-sdk": true,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsafe Node in-place injection

High Severity

node-server is treated as append-safe and writes a CommonJS require template as ready-to-run code. Detection often targets TypeScript/ESM entry points such as Next.js instrumentation.ts, where that inject neither parses nor matches the required register hook, yet still reports success.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 43d2d15. Configure here.

Comment thread internal/setup/sdk_init_templates/swift-client-sdk.tmpl
ffantl-ld and others added 4 commits August 3, 2026 15:45
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
react-native.tmpl bound the default export of
@launchdarkly/react-native-client-sdk, which has no default export, so the
snippet could not compile. The client is the named export ReactNativeLDClient.

Register the android template under the SDK ID the detector reports, keeping
android-client-sdk as an alias.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The Swift and Android snippets did not compile. LDConfig's only public
initializer takes autoEnvAttributes, and LDConfig.Builder's only constructor
takes AutoEnvAttributes, so neither config could be built as written. These
SDKs return a snippet for the user to paste rather than writing a file, so the
snippet is the entire deliverable.

AutoEnvAttributes is nested in LDConfig.Builder, which the package wildcard
import does not cover, so import it explicitly.

Add DefaultEntryPoint, naming the file to create for the SDKs that write one
when detection found no entry point for them.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
LDContextBuilder.build returns a Result, and the snippet unwrapped it with
`try ...get()`. try only compiles inside a throwing function, and the places
this snippet gets pasted — application(_:didFinishLaunchingWithOptions:) and
similar startup hooks — do not throw. Match on the Result instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ffantl-ld
ffantl-ld force-pushed the ffantl/setup-ld/3-initializer branch from 43d2d15 to 8daf723 Compare August 3, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant