Skip to content

feat: validate client config on construction#36

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
Clement-coder:feat/config-validation
Jun 16, 2026
Merged

feat: validate client config on construction#36
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
Clement-coder:feat/config-validation

Conversation

@Clement-coder

Copy link
Copy Markdown
Contributor

Description

Adds early config validation to GuildPassClient so invalid values throw a
clear GuildPassError at construction time instead of causing confusing
errors later inside HttpClient or fetch.

Semver impact: patch

Linked Issue

Closes #21

Type of Change

  • 🐛 Bug fix (patch)

Changes Made

  • src/config/sdkConfig.ts — adds validateConfig function; validates
    apiUrl is a non-empty absolute http/https URL and timeoutMs (when provided)
    is a positive number
  • src/client/GuildPassClient.ts — imports and calls
    validateConfig(config) at the top of the constructor, before merging
    defaults
  • tests/client.test.ts — adds GuildPassClient config validation suite
    covering all acceptance criteria (empty apiUrl, invalid URL, timeoutMs: 0,
    negative timeoutMs, and a valid config)

Public API Changes

typescript
// src/config/sdkConfig.ts
export function validateConfig(config: GuildPassClientConfig): void

No existing exports changed. No new exported types.

Test Evidence

pnpm test:run

Test Files 6 passed (6)
Tests 25 passed (25)
Duration 1.79s

Build Evidence

pnpm build

CJS dist/index.js 6.00 KB
CJS ⚡️ Build success in 588ms
ESM dist/index.mjs 5.90 KB
ESM ⚡️ Build success in 590ms
DTS dist/index.d.ts 8.79 KB
DTS ⚡️ Build success in 3389ms

Checklist

  • I have read CONTRIBUTING.md
  • This PR is linked to an open issue
  • pnpm typecheck passes
  • pnpm lint passes (0 errors, pre-existing warnings only)
  • pnpm test:run passes — all tests green
  • pnpm build succeeds — dist/ generated cleanly
  • All new public methods/types have TypeDoc comments
  • New behaviour is covered by at least one Vitest unit test
  • No new runtime dependencies added without prior maintainer approval
  • Backwards compatibility maintained

Additional Notes

chainId is intentionally not validated against SUPPORTED_NETWORKS per the
issue notes — unsupported chains are allowed unless maintainers decide
otherwise.

- Add validateConfig helper in sdkConfig.ts
- Throw GuildPassError(INVALID_CONFIG) for missing/invalid apiUrl
- Throw GuildPassError(INVALID_CONFIG) for non-positive timeoutMs
- Call validateConfig at the top of GuildPassClient constructor
- Add test suite covering all invalid and valid config cases

Closes Adamantine-guild#21
@Lakes41 Lakes41 merged commit e5368c5 into Adamantine-guild:main Jun 16, 2026
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.

Validate client configuration at construction time

2 participants