Skip to content

feat(samples/kotlin): support GRID_API_BASE_URL override#589

Open
pengying wants to merge 1 commit into
mainfrom
06-16-feat_samples_kotlin_support_grid_api_base_url_override
Open

feat(samples/kotlin): support GRID_API_BASE_URL override#589
pengying wants to merge 1 commit into
mainfrom
06-16-feat_samples_kotlin_support_grid_api_base_url_override

Conversation

@pengying

Copy link
Copy Markdown
Contributor

Add an optional GRID_API_BASE_URL environment variable so the Kotlin
sample can target a non-production Grid API base path (e.g. a dev/RC
environment). When unset, the SDK's default base URL is used.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Actions Updated (UTC)
grid-flow-builder Ignored Ignored Preview Jun 18, 2026 6:13pm
grid-wallet-demo Ignored Ignored Preview Jun 18, 2026 6:13pm

Request Review

@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds an optional GRID_API_BASE_URL environment variable to the Kotlin sample so it can target non-production Grid API endpoints; when unset, the SDK's default production URL is used.

  • Config.kt gains a private getEnvVarOrNull helper and exposes apiBaseUrl: String?, refactoring the existing getEnvVar to delegate to it.
  • GridClientBuilder.kt applies baseUrl(it) on the SDK builder only when apiBaseUrl is non-null, using idiomatic Kotlin apply/let.

Confidence Score: 5/5

Safe to merge — the change is additive and isolated to the Kotlin sample; the SDK default URL is preserved whenever the variable is unset.

The change is a small, self-contained addition to a sample app. The new code path only activates when GRID_API_BASE_URL is explicitly set, and the SDK builder is otherwise untouched. No production code is affected.

No files require special attention.

Important Files Changed

Filename Overview
samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt Adds optional GRID_API_BASE_URL env var via a new getEnvVarOrNull helper; refactors getEnvVar to delegate to it. Clean extraction, though blank-string values pass through as non-null (flagged in prior thread).
samples/kotlin/src/main/kotlin/com/grid/sample/GridClientBuilder.kt Applies apiBaseUrl to the SDK builder only when non-null using idiomatic apply/let; no issues found.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Env as Environment<br/>(sys prop / .env / env var)
    participant Config as Config.kt
    participant Builder as GridClientBuilder.kt
    participant SDK as LightsparkGridOkHttpClient

    Config->>Env: getEnvVar("GRID_CLIENT_ID")
    Env-->>Config: apiTokenId
    Config->>Env: getEnvVar("GRID_CLIENT_SECRET")
    Env-->>Config: apiClientSecret
    Config->>Env: getEnvVarOrNull("GRID_API_BASE_URL")
    Env-->>Config: apiBaseUrl (String? — null if unset)

    Builder->>SDK: builder().username().password()
    alt "apiBaseUrl != null"
        Builder->>SDK: ".apply { baseUrl(apiBaseUrl) }"
    end
    Builder->>SDK: .build()
    SDK-->>Builder: LightsparkGridClient
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Env as Environment<br/>(sys prop / .env / env var)
    participant Config as Config.kt
    participant Builder as GridClientBuilder.kt
    participant SDK as LightsparkGridOkHttpClient

    Config->>Env: getEnvVar("GRID_CLIENT_ID")
    Env-->>Config: apiTokenId
    Config->>Env: getEnvVar("GRID_CLIENT_SECRET")
    Env-->>Config: apiClientSecret
    Config->>Env: getEnvVarOrNull("GRID_API_BASE_URL")
    Env-->>Config: apiBaseUrl (String? — null if unset)

    Builder->>SDK: builder().username().password()
    alt "apiBaseUrl != null"
        Builder->>SDK: ".apply { baseUrl(apiBaseUrl) }"
    end
    Builder->>SDK: .build()
    SDK-->>Builder: LightsparkGridClient
Loading

Reviews (2): Last reviewed commit: "feat(samples/kotlin): support GRID_API_B..." | Re-trigger Greptile


// Optional override for the Grid API base URL (e.g. a dev/RC environment).
// When unset, the SDK uses its default (production) base URL.
val apiBaseUrl: String? = getEnvVarOrNull("GRID_API_BASE_URL")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Empty string not treated as "unset"

getEnvVarOrNull returns an empty string if GRID_API_BASE_URL is set to "" (e.g. an accidentally blank .env entry). That empty string is non-null, so apiBaseUrl will be "" and baseUrl("") will be called on the SDK builder — almost certainly producing a malformed URL at runtime instead of silently falling back to the default.

Suggested change
val apiBaseUrl: String? = getEnvVarOrNull("GRID_API_BASE_URL")
val apiBaseUrl: String? = getEnvVarOrNull("GRID_API_BASE_URL")?.takeIf { it.isNotBlank() }
Prompt To Fix With AI
This is a comment left during a code review.
Path: samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt
Line: 18

Comment:
**Empty string not treated as "unset"**

`getEnvVarOrNull` returns an empty string if `GRID_API_BASE_URL` is set to `""` (e.g. an accidentally blank `.env` entry). That empty string is non-null, so `apiBaseUrl` will be `""` and `baseUrl("")` will be called on the SDK builder — almost certainly producing a malformed URL at runtime instead of silently falling back to the default.

```suggestion
    val apiBaseUrl: String? = getEnvVarOrNull("GRID_API_BASE_URL")?.takeIf { it.isNotBlank() }
```

How can I resolve this? If you propose a fix, please make it concise.

Add an optional GRID_API_BASE_URL environment variable so the Kotlin
sample can target a non-production Grid API base path (e.g. a dev/RC
environment). When unset, the SDK's default base URL is used.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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