Skip to content

Phase 0: config file, --host option, auth and scaffold fixes - #12

Open
roncodes wants to merge 1 commit into
mainfrom
phase-0/cli-fixes
Open

roncodes wants to merge 1 commit into
mainfrom
phase-0/cli-fixes

Conversation

@roncodes

@roncodes roncodes commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Phase 0 (stabilise) of the Extensions Registry re-architecture, CLI side. Small, backwards-compatible fixes so developer accounts, the CLI and the registry are usable while the Registry Service is built.

Summary

  • Config file: ~/.fleetbase/config.json holding { host, registry, tokens: { "<host>": "<token>" }, defaultOrganization }, created with mode 0600. FLEETBASE_HOME overrides the directory (used by tests).
  • set-auth stores the token in the config file keyed by registry host (and by API host, plus saves host, when --host is given). It still writes <instance>/api/auth.json for Composer and no longer appends to <instance>/console/.npmrc. The token argument is optional when one is already stored.
  • bundle --upload / bundle-upload read the token from --auth-token, then the config file. ~/.npmrc is no longer consulted. The error handler guards error.response?.data.
  • --host <url>: global option plus per-command --host on install, uninstall, bundle, bundle-upload, search, register, verify, resend-verification, generate-token, login, set-auth. Precedence: flag > config file > https://api.fleetbase.io. All registry URLs are built from the host; the hard-coded packageLookupApi / bundleUploadApi / extensionsListApi constants are removed. Global options are positional so install-fleetbase --host keeps its own meaning.
  • Host normalisation in one helper: existing scheme kept; http:// for localhost, 127.0.0.1 and hosts with a port; https:// otherwise.
  • scaffold: fix the const reassignment crash when the target directory exists; remove the duplicate -n (namespace is --namespace only); --repo has no default so extension.json / package.json no longer point at the starter repo.
  • login: accepts --host (used as the registry unless --registry is given); npm-cli-login is wrapped in a promise so failures are caught and exit non-zero. The package's default export is callback based and threw from inside async callbacks.
  • Tokens are never printed by default: verify and generate-token save the token to the config file and show it masked; --show-token prints it.
  • install / uninstall / scaffold exit 1 on failure.
  • Tests: test/cli.test.js (plain node:assert, run by npm test) covers host normalisation, config read/write, token storage and lookup, host precedence and option registration.
  • README updated for the config file, --host, and the set-auth / login / scaffold / bundle changes.

Behaviour changes to be aware of

  • Bundle uploads no longer fall back to ~/.npmrc. A user who only ran flb login must run flb set-auth <token> once; the error message says so.
  • scaffold -n now only means --name.
  • -h, --host on register / verify / search is unchanged.

Verification

  • npm test: 17/17 pass.
  • Against a local mock API: verify masks and saves the token and --show-token prints it; bundle-upload sends the stored token and --auth-token overrides it; a 403 is reported cleanly with exit 1; install hits the lookup URL on the given host and exits 1 when pnpm fails; search uses the host from the config file; login against a closed port exits 1 with a clear error.

- Add ~/.fleetbase/config.json ({ host, registry, tokens: { "<host>": "<token>" },
  defaultOrganization }) with read/write helpers; FLEETBASE_HOME overrides the dir.
- set-auth stores the token in the config file (keyed by registry host, plus the
  API host when --host is given) and still writes <instance>/api/auth.json; it no
  longer appends to <instance>/console/.npmrc. Token argument is optional when one
  is already stored.
- bundle --upload / bundle-upload read the token from --auth-token, then the config
  file; ~/.npmrc is no longer consulted. Guard error.response?.data in the catch.
- Add a global --host <url> (flag > config file > https://api.fleetbase.io) and
  per-command --host on install, uninstall, bundle, bundle-upload, search,
  register, verify, resend-verification, generate-token, login, set-auth. Build all
  registry URLs from the host; drop the hard-coded packageLookupApi /
  bundleUploadApi / extensionsListApi constants. Global options are positional so
  install-fleetbase --host keeps its own meaning.
- One normalizeHost helper: keep an existing scheme; http:// for localhost,
  127.0.0.1 and hosts with a port; https:// otherwise.
- scaffold: fix const reassignment crash when the target dir exists; namespace is
  --namespace only (duplicate -n removed); --repo has no default so
  extension.json/package.json no longer point at the starter repo.
- login: accept --host (used as the registry unless --registry is given), wrap
  npm-cli-login in a promise, exit non-zero on failure.
- verify / generate-token: token is saved to the config file and masked unless
  --show-token is passed.
- install / uninstall / scaffold exit 1 on failure.
- Add test/cli.test.js (plain node assert) covering host normalisation, config
  read/write, token storage, host precedence and option registration; npm test
  runs it.
- README updated for the config file, --host, set-auth/login/scaffold changes and
  the removed -r on bundle commands.
Comment thread index.js
return host;
}

const value = host.trim().replace(/\/+$/, '');
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.

2 participants