Skip to content

Conversation

JasoonS
Copy link
Contributor

@JasoonS JasoonS commented Sep 17, 2025

Summary by CodeRabbit

  • New Features

    • Add CLI authentication: login/logout commands and HyperSync connect flow.
    • Automatically provision and store HyperSync API tokens using the system keychain.
    • Introduce configurable Ethereum address format (checksum or lowercase) across config, codegen, and runtime; default preserved.
    • Allow disabling checksum addresses in HyperSync sources via a new option.
  • Documentation

    • Update CLI help with an auth subcommand.
    • Add config template comments for address_format options.
  • Tests

    • Add tests for lowercase address handling and updated config shape.
  • Chores

    • Add keyring dependency for secure token storage.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

Walkthrough

Adds CLI authentication and HyperSync token provisioning with OS keyring storage, new Login/Logout/Hypersync commands, and best-effort token provisioning during startup. Introduces configurable Ethereum address casing (checksum or lowercase) across schema, configs, templates, and runtime, including HyperSync client/source toggles and Rescript address parsing. Updates tests and docs accordingly.

Changes

Cohort / File(s) Summary
Auth, tokens, and CLI commands
codegenerator/cli/src/commands.rs, codegenerator/cli/src/utils/mod.rs, codegenerator/cli/src/utils/token_manager.rs, codegenerator/cli/src/cli_args/clap_definitions.rs, codegenerator/cli/src/executor/mod.rs, codegenerator/cli/src/executor/local.rs, codegenerator/cli/src/executor/dev.rs, codegenerator/cli/src/cli_args/interactive_init/mod.rs, codegenerator/cli/CommandLineHelp.md, codegenerator/cli/Cargo.toml
Adds login/logout and hypersync connect commands, JWT and HyperSync token provisioning, keyring-backed storage, startup best-effort provisioning, interactive init auto-provisioning fallback, help text for auth, and keyring dependency.
Address format config (Rust/schema/templates)
codegenerator/cli/src/config_parsing/human_config.rs, codegenerator/cli/src/config_parsing/system_config.rs, codegenerator/cli/src/cli_args/init_config.rs, codegenerator/cli/src/config_parsing/graph_migration/mod.rs, codegenerator/cli/npm/envio/evm.schema.json, codegenerator/cli/templates/static/*/*/config.yaml
Adds optional address_format (checksum/lowercase) to human config and schema; maps to SystemConfig.lowercase_addresses; initializes to None in builders/migration; updates starter templates to set address_format: lowercase.
Runtime/codegen for lowercase addresses & HyperSync options
codegenerator/cli/npm/envio/src/Address.res, codegenerator/cli/npm/envio/src/sources/HyperSyncClient.res, codegenerator/cli/npm/envio/src/sources/HyperSyncSource.res, codegenerator/cli/templates/static/codegen/src/Config.res, codegenerator/cli/templates/static/codegen/src/UserContext.res, codegenerator/cli/templates/static/codegen/src/eventFetching/NetworkSources.res, codegenerator/cli/templates/dynamic/codegen/src/RegisterHandlers.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/ConfigYAML.res.hbs, codegenerator/cli/src/hbs_templating/codegen_templates.rs
Adds lowercase parsing helpers and error handling; threads lowercaseAddresses through generated configs and handler registration; toggles HyperSync enableChecksumAddresses; emits lowercaseAddresses in templates and YAML; codegen templates updated accordingly.
Tests and scenarios
scenarios/test_codegen/test/AddressLowercase_test.res, scenarios/test_codegen/test/Config_test.res, scenarios/test_codegen/rescript.json
Adds tests for lowercase address helpers and config shape; minor JSON formatting change.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor U as User
  participant CLI as envio CLI
  participant B as Browser
  participant AUTH as Auth Service
  participant HS as HyperSync API
  participant KR as TokenManager (Keyring)

  rect rgba(200,230,255,0.25)
    U->>CLI: envio login
    CLI->>B: Open login URL
    U->>AUTH: Authenticate
    CLI->>AUTH: Poll session
    AUTH-->>CLI: JWT
    CLI->>KR: Store JWT
    CLI-->>U: Print JWT
  end

  rect rgba(220,255,220,0.25)
    U->>CLI: envio hypersync connect
    CLI->>KR: Get JWT (or trigger login)
    CLI->>HS: Provision user/token (JWT)
    HS-->>CLI: HyperSync API token
    CLI->>KR: Store HyperSync token
    CLI-->>U: Print token / write to .env (if exists)
  end

  rect rgba(255,240,200,0.25)
    note over CLI: Startup
    CLI->>CLI: Detect HyperSync usage
    alt uses HyperSync
      CLI->>HS: Best-effort provision token
      HS-->>CLI: Token or error
      CLI-->>CLI: Warn on error, continue
    end
  end
Loading
sequenceDiagram
  autonumber
  participant CFG as config.yaml (address_format)
  participant CLI as Codegen (Rust)
  participant GEN as Generated Config (Rescript)
  participant SRC as HyperSyncSource
  participant HC as HyperSyncClient
  participant ADR as Address.Evm

  CFG-->>CLI: address_format = checksum/lowercase
  CLI-->>GEN: lowercaseAddresses = (format == lowercase)
  GEN-->>SRC: make(..., lowercaseAddresses)
  SRC-->>HC: enableChecksumAddresses = !lowercaseAddresses
  alt lowercaseAddresses
    GEN-->>ADR: fromStringLowercaseOrThrow / fromAddressLowercaseOrThrow
  else checksum
    GEN-->>ADR: fromStringOrThrow / fromAddressOrThrow
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

Suggested reviewers

  • JonoPrest
  • DZakh

Poem

A rabbit taps the keys with glee,
“Login, connect—tokens for me!”
Addresses, lowercase and neat,
HyperSync hums with steady beat.
In keyring burrows secrets stay,
Hop hop—envio leads the way. 🐇🔑✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.15% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary change—adding an authentication CLI for managing tokens—and references the initial use case of generating Hypersync API tokens, which aligns directly with the bulk of the pull request’s modifications around login, logout, and token provisioning commands. It is clear, specific, and focused on the main feature without extraneous detail.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch auth-cli2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@JasoonS JasoonS changed the base branch from main to lower-case-address September 17, 2025 08:29
Comment on lines +46 to +48
pub const SERVICE_NAME: &str = "envio-cli";
pub const JWT_ACCOUNT: &str = "oauth_token";
pub const HYPERSYNC_ACCOUNT: &str = "hypersync_api_token";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are used by 'keyring' to locate the correct secrets.

))
}

async fn execute_command_with_env(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This allows us to run the command with the api token set in the environment.

let args = vec!["run", "start"];
let exit = execute_command(cmd, args, &config.parsed_project_paths.generated).await?;

// Determine whether to inject ENVIO_API_TOKEN from vault
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This determines whether it needs to inject the API token from the vault. If the user has the API token defined in their .env file, then it uses that as an override.

@JasoonS JasoonS force-pushed the auth-cli2 branch 2 times, most recently from 4c8ab91 to f1d739c Compare September 18, 2025 10:09
}

fn try_get_type_def(&self, name: &String) -> anyhow::Result<TypeDef> {
fn try_get_type_def(&self, name: &String) -> anyhow::Result<TypeDef<'_>> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting warnings about this... Didn't dig deep, something about the function signature was ambiguous without it...

println!(
"HyperSync is enabled but no ENVIO_API_TOKEN was found. Attempting to log in to provision or retrieve a HyperSync API token..."
);
if let Err(e) = crate::commands::hypersync::provision_and_get_token().await {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will log the user in if they are not logged in in the dev flow.
If they have an env variable with their token set it will not prompt them to log in and use that instead.

Comment on lines +43 to +46
Js.Console.error("HyperSync is configured as a datasource but ENVIO_API_TOKEN is not set.")
Js.Console.error(
"Please run 'envio login` to log in, or alternatively add your ENVIO_API_TOKEN to your project .env file.",
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the user does not set an Envio API token (either via cli login, or .env file, or an environment variable) the code will stop and get stuck here.

…ogin for `envio start` - and cleanup comments
@JasoonS JasoonS requested a review from DZakh September 18, 2025 10:40
@JasoonS
Copy link
Contributor Author

JasoonS commented Sep 18, 2025

Temporarily you can test it with export ENVIO_API_URL="https://indexer-git-mj-cli-hack-rebase-envio-9ec2d675.vercel.app" - but I'll remove that url from github as soon as it gets merged and then it should work by default.

@JasoonS
Copy link
Contributor Author

JasoonS commented Sep 18, 2025

I've spent way too long trying to get this to work without actually publishing the new ui code 💩 I think unfortunately we'll have to do that. Otherwise I have to add in some hacky code temporarily.

The easiest way to test this is to run the UI locally on this branch: https://github.com/enviodev/ui/pull/639 and set `export ENVIO_API_URL="http://localhost:3000"

@JasoonS JasoonS changed the base branch from lower-case-address to main September 29, 2025 09:10
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