Skip to content

feat: export ServerConfigSchema from public validation module — closes #127#187

Merged
0xNgoo merged 4 commits into0xNgoo:mainfrom
spiffamani:feat/export-server-config-schema-127
Apr 1, 2026
Merged

feat: export ServerConfigSchema from public validation module — closes #127#187
0xNgoo merged 4 commits into0xNgoo:mainfrom
spiffamani:feat/export-server-config-schema-127

Conversation

@spiffamani
Copy link
Copy Markdown
Contributor

Summary

Exports ServerConfigSchema from the public validation module, closing #127.

Changes

  • src/utils/validation.ts — Added ServerConfigSchema and validateServerConfig
  • tests/utils/server-config-schema.test.ts — 18 focused tests

What's exported

  • ServerConfigSchema — runtime schema object with validate() per field
  • validateServerConfig() — validates partial ServerConfig, returns error strings

Usage

import { ServerConfigSchema, validateServerConfig } from 'anchor-kit';

ServerConfigSchema.port.validate(3000); // true
validateServerConfig({ port: -1 }); // ['port: invalid value']

Test Results

bun test v1.3.11
18 pass | 0 fail | 54 expect() calls

Checklist

  • ServerConfigSchema is publicly importable
  • Existing validation exports continue to work
  • bun test passes
  • Narrowly scoped to described behavior
  • No new runtime dependencies

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@spiffamani Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a runtime validation schema and utility function for server configurations, along with a comprehensive test suite. The feedback identifies that the schema is currently incomplete relative to the ServerConfig type, missing properties like corsOrigins and requestTimeout. Additionally, there are suggestions to improve the precision of test assertions and to verify the export of all validation utilities from the package index.

Comment on lines +105 to +142
export const ServerConfigSchema: Record<keyof Required<ServerConfig>, SchemaField> = {
host: {
type: 'string',
required: false,
description: 'Server host address. Defaults to 0.0.0.0',
validate: (value) => typeof value === 'string' && value.length > 0,
},
port: {
type: 'number',
required: false,
description: 'Server port number. Defaults to 3000.',
validate: (value) =>
typeof value === 'number' &&
Number.isInteger(value) &&
value > 0 &&
value <= 65535,
},
debug: {
type: 'boolean',
required: false,
description: 'Enable debug mode for verbose logging. Defaults to false.',
validate: (value) => typeof value === 'boolean',
},
interactiveDomain: {
type: 'string',
required: false,
description: 'Interactive web portal domain/URL for SEP-24 flows.',
validate: (value) => {
if (typeof value !== 'string' || value.length === 0) return false;
try {
const url = new URL(value);
return url.protocol === 'http:' || url.protocol === 'https:';
} catch {
return false;
}
},
},
};
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.

critical

The ServerConfigSchema is incomplete. It is typed as Record<keyof Required<ServerConfig>, SchemaField>, which requires all properties of ServerConfig to be defined in the schema. However, corsOrigins and requestTimeout from the ServerConfig interface are missing.

This will likely cause a TypeScript compilation error. If not, it's a significant bug because the validation logic will not cover these properties, which could lead to invalid configuration being silently accepted.

Please add the missing properties to the schema with appropriate validation.

export const ServerConfigSchema: Record<keyof Required<ServerConfig>, SchemaField> = {
  host: {
    type: 'string',
    required: false,
    description: 'Server host address. Defaults to 0.0.0.0',
    validate: (value) => typeof value === 'string' && value.length > 0,
  },
  port: {
    type: 'number',
    required: false,
    description: 'Server port number. Defaults to 3000.',
    validate: (value) =>
      typeof value === 'number' &&
      Number.isInteger(value) &&
      value > 0 &&
      value <= 65535,
  },
  debug: {
    type: 'boolean',
    required: false,
    description: 'Enable debug mode for verbose logging. Defaults to false.',
    validate: (value) => typeof value === 'boolean',
  },
  interactiveDomain: {
    type: 'string',
    required: false,
    description: 'Interactive web portal domain/URL for SEP-24 flows.',
    validate: (value) => {
      if (typeof value !== 'string' || value.length === 0) return false;
      try {
        const url = new URL(value);
        return url.protocol === 'http:' || url.protocol === 'https:';
      } catch {
        return false;
      }
    },
  },
  corsOrigins: {
    type: 'string[]',
    required: false,
    description: 'Allowed origins for CORS.',
    validate: (value) =>
      Array.isArray(value) &&
      value.every((item) => typeof item === 'string' && item.length > 0),
  },
  requestTimeout: {
    type: 'number',
    required: false,
    description: 'Request timeout in milliseconds.',
    validate: (value) =>
      typeof value === 'number' && Number.isInteger(value) && value > 0,
  },
};

port: 0,
debug: 'yes' as unknown as boolean,
});
expect(errors.length).toBeGreaterThanOrEqual(2);
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.

medium

The assertion expect(errors.length).toBeGreaterThanOrEqual(2) is not very precise. For a more robust test that prevents future regressions, it's better to assert the exact length and content of the errors array.

    expect(errors).toHaveLength(2);
    expect(errors).toContain('port: invalid value');
    expect(errors).toContain('debug: invalid value');


it('is accessible through the utils index', async () => {
const mod = await import('../../src/utils/index');
expect(mod.ServerConfigSchema).toBeDefined();
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.

medium

This test is incomplete. It only checks for ServerConfigSchema being exported from the utils index. Since validateServerConfig is also exported and intended for public use, the test should verify that it's also accessible from the index file.

    expect(mod.ServerConfigSchema).toBeDefined();
    expect(mod.validateServerConfig).toBeDefined();

@0xNgoo 0xNgoo linked an issue Apr 1, 2026 that may be closed by this pull request
@0xNgoo 0xNgoo merged commit 99e08cf into 0xNgoo:main Apr 1, 2026
1 check passed
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.

Export ServerConfigSchema from the public validation module

2 participants