npm package: @onlineapps/conn-base-validator
Description: Validation client for microservices - handles local pre-validation as part of two-tier validation architecture
Author: OnlineApps
Latest version: 1.0.4
Deprecated: This package is no longer needed - use conn-e2e-testing for pre-validation via cookbook tests instead

# @onlineapps/conn-base-validator

Validation client for microservices - handles local pre-validation as part of two-tier validation architecture.

## Installation

```bash
npm install @onlineapps/conn-base-validator
```

## Usage

### As CLI

```bash
# Run in service directory
npx @onlineapps/conn-base-validator validate

# With options
npx @onlineapps/conn-base-validator validate --name my-service --version 1.0.0
```

### As Library

```javascript
const LocalValidator = require('@onlineapps/conn-base-validator');

const validator = new LocalValidator({
  servicePath: '/path/to/service',
  configDir: 'connector-config'
});

// Run validation
const results = await validator.validate('my-service', '1.0.0');

if (results.success) {
  console.log('Pre-validation token:', results.token);
}
```

## Configuration

Create a `connector-config` directory in your service root with:

### openapi.yaml or openapi.json
Your OpenAPI 3.0 specification

### manifest.json
```json
{
  "metadata": {
    "name": "my-service",
    "version": "1.0.0",
    "connectors": {
      "conn-base-logger": { "version": "1.0.0", "enabled": true },
      "conn-base-storage": { "version": "1.0.0", "enabled": true },
      "conn-orch-registry": { "version": "1.0.0", "enabled": true },
      "conn-infra-mq": { "version": "1.0.0", "enabled": true },
      "conn-orch-cookbook": { "version": "1.0.0", "enabled": true }
    }
  },
  "health": "/health",
  "endpoints": [
    { "path": "/api/test", "method": "GET" },
    { "path": "/api/data", "method": "POST" }
  ]
}
```

## Validation Process

1. Loads service configuration from files
2. Runs validation checks:
   - OpenAPI specification
   - Endpoint definitions
   - Required connectors
   - Health check endpoint
3. Generates pre-validation token if successful
4. Saves token to `.validation-token` file

## Output

The validator provides detailed output:
- ✅ Successful checks
- ❌ Failed checks
- ⚠️ Warnings
- 🎫 Pre-validation token (if successful)

## API Reference

### Constructor

```javascript
new LocalValidator(config)
```

**Parameters:**
- `config` (Object) - Configuration options
  - `servicePath` (string) - Path to service directory (default: `process.cwd()`)
  - `configDir` (string) - Configuration directory name (default: `'connector-config'`)
  - `strictMode` (boolean) - Use strict validation mode (default: `false`)

### Methods

#### validate(serviceName, version)
Performs local pre-validation of the service.

**Parameters:**
- `serviceName` (string) - Name of the service to validate
- `version` (string) - Service version in semver format

**Returns:** Promise<ValidationResult>
- `success` (boolean) - Whether validation passed
- `validated` (boolean) - Whether validation was performed
- `errors` (Array<string>) - List of validation errors
- `warnings` (Array<string>) - List of validation warnings
- `checks` (Object) - Individual check results
- `token` (string) - Pre-validation token (if successful)
- `tokenSecret` (string) - Token secret for verification (if successful)
- `preValidation` (Object) - Validation metadata

**Example:**
```javascript
const results = await validator.validate('hello-service', '1.0.0');
if (results.success) {
  console.log('Token:', results.token);
}
```

#### loadServiceConfiguration()
Loads service configuration from files.

**Returns:** Promise<ServiceConfig>
- `endpoints` (Array) - Service endpoints
- `metadata` (Object) - Service metadata
- `health` (string) - Health check endpoint path
- `openApiSpec` (Object) - OpenAPI specification

#### runCLI(options)
Runs validation as CLI command with console output.

**Parameters:**
- `options` (Object) - CLI options
  - `name` (string) - Service name
  - `version` (string) - Service version
  - `servicePath` (string) - Path to service directory
  - `configDir` (string) - Configuration directory name

**Returns:** Promise<void> - Exits process with code 0 (success) or 1 (failure)

## Integration with Registry

After successful pre-validation:

1. Service reads token from `.validation-token`
2. Includes token in registration request to Registry
3. Registry forwards to system validator
4. System validator verifies token and issues certificate

## Related Documentation

- **[⭐ Complete Two-Tier Validation System](/docs/modules/validator.md)** - Full architecture and flow
- [schema-validator-core](/shared/schema-validator-core/README.md) - Core validation engine
- [api_schema_validator](/api/api_schema_validator/README.md) - System validator service

## License

MIT