Skip to main content

Adapter Quality Standards

This document defines the quality criteria that all Idiomark adapters must meet to be accepted into the official repository.

Overview​

Idiomark adapters must meet strict quality standards to ensure reliability, security, and maintainability. These standards are enforced through automated CI/CD checks and manual code review.

Quality Checklist​

1. Interface Implementation​

  • Implements BaseAdapter interface
    • name property is a unique string identifier
    • authenticate() method returns Promise<boolean>
    • fetchData() method returns Promise<RawContent[]>
    • normalize() method returns NormalizedContent
// Required interface implementation
export class MyAdapter implements PlatformAdapter {
readonly name: string = 'myplatform'
authenticate(): Promise<boolean>
fetchData(options: FetchOptions): Promise<RawContent[]>
normalize(raw: RawContent): NormalizedContent
}

2. TypeScript Types​

  • Comprehensive type definitions
    • All API response types are defined in types.ts
    • No any types used (except for raw data field)
    • Strict mode enabled in tsconfig.json
    • All exported functions have type annotations
    • Generic types are properly constrained
// Good: Properly typed
interface APIResponse<T> {
data: T[]
pagination: PaginationInfo
}

// Bad: Using any
interface APIResponse {
data: any[]
}
  • Type coverage: 100% (all code is typed)

3. Rate Limiting​

  • Rate limiting is implemented
    • Respects platform's documented rate limits
    • Uses configurable rate limiter
    • Handles Retry-After headers when present
    • Implements exponential backoff for retries
// Required rate limiting
class MyAdapter implements PlatformAdapter {
private rateLimiter = new RateLimiter({
requests: 300,
window: 15 * 60 * 1000 // 15 minutes
})

async fetchData(options: FetchOptions): Promise<RawContent[]> {
await this.rateLimiter.wait() // Always rate limit
// ... fetch data
}
}

4. Error Handling​

  • Comprehensive error handling
    • All API calls wrapped in try/catch
    • Specific error types for different failure modes
    • Auth errors are distinguished from rate limit errors
    • Network errors are logged and retried when appropriate
    • User receives clear error messages
// Required error types
export class AuthError extends Error {
constructor(message: string) {
super(message)
this.name = 'AuthError'
}
}

export class RateLimitError extends Error {
constructor(retryAfter?: number) {
super('Rate limit exceeded')
this.name = 'RateLimitError'
this.retryAfter = retryAfter
}
retryAfter?: number
}

export class NetworkError extends Error {
constructor(message: string, public retryable: boolean = true) {
super(message)
this.name = 'NetworkError'
}
}
  • Error handling checklist:
    • 401 Unauthorized -> AuthError with clear message
    • 403 Forbidden -> AuthError with permission details
    • 429 Too Many Requests -> RateLimitError with retry delay
    • 5xx Server Errors -> NetworkError (retryable)
    • Network failures -> NetworkError (retryable)
    • Malformed responses -> Validation error with details

5. Testing Coverage​

  • Test coverage > 80%
    • Unit tests for all public methods
    • Integration tests for API calls (when possible)
    • Error path testing
    • Edge case coverage
# Required test commands
pnpm test # Run all tests
pnpm test:coverage # Generate coverage report
pnpm test:adapter myplatform # Test specific adapter
  • Test requirements:
    • All methods have unit tests
    • Authentication flow is tested
    • Data normalization is tested with various inputs
    • Error cases are tested (401, 429, 500, network errors)
    • Rate limiting is tested
    • Edge cases are tested (empty responses, malformed data, etc.)

6. Documentation​

  • Complete README.md
    • Adapter name and brief description
    • Supported data types (posts, comments, etc.)
    • Authentication setup instructions
    • API documentation link
    • Rate limit information
    • Example usage code
    • Environment variables reference
    • Troubleshooting section
# README.md Template

## @idiomark/adapter-myplatform

MyPlatform adapter for Idiomark personality extraction.

### Supported Data

- Posts
- Comments
- Reactions

### Authentication

This adapter uses OAuth 2.0. See [MyPlatform OAuth Guide](https://docs.myplatform.com/oauth) for setup.

### Rate Limits

- 300 requests per 15 minutes
- 10,000 requests per day

### Example Usage

\`\`\`typescript
import { MyPlatformAdapter } from '@idiomark/adapter-myplatform'

const adapter = new MyPlatformAdapter({
accessToken: process.env.MYPLATFORM_TOKEN,
userId: 'user123'
})

const data = await adapter.fetchData({ limit: 100 })
\`\`\`

### Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `MYPLATFORM_TOKEN` | Yes | OAuth access token |
| `MYPLATFORM_USER_ID` | Yes | Your user ID |

### Troubleshooting

**Issue**: "Invalid access token"
**Solution**: Ensure your token is not expired and has the correct scopes.
  • Code comments
    • All public methods have JSDoc comments
    • Complex logic is explained in comments
    • External API calls are documented with source URLs

7. Security​

  • No hardcoded credentials
    • No API keys, tokens, or passwords in source code
    • Use environment variables for all credentials
    • .env.example file shows required variables
// Good: Use environment variables
const token = process.env.MYPLATFORM_TOKEN

// Bad: Hardcoded credentials
const token = 'sk_live_abc123...'
  • Secrets scanning

    • All PRs are scanned for leaked secrets
    • Use gitleaks or similar tool
    • Never commit .env files
  • Credential handling

    • Credentials are passed via constructor/config
    • Credentials are never logged
    • Tokens are validated before use
    • Sensitive data is masked in error messages

8. Build Quality​

  • Builds without warnings
    • TypeScript compilation succeeds with strict: true
    • No ESLint warnings
    • No unused dependencies
    • Package.json has correct fields
# Required build commands - all must succeed
pnpm build # TypeScript compilation
pnpm lint # ESLint checks
pnpm typecheck # Type checking

9. Code Style​

  • Follows project conventions
    • Consistent naming (camelCase for variables, PascalCase for types)
    • 2-space indentation
    • Semicolons required
    • Double quotes for strings
    • Max line length: 100 characters
// Good style
async function fetchData(options: FetchOptions): Promise<RawContent[]> {
const { limit = 100 } = options
return await this.api.get('/posts', { limit })
}

// Bad style
async function fetch_data(options:any){
return await this.get('/posts')
}

10. Performance​

  • Efficient data fetching
    • Minimizes API calls
    • Uses pagination for large datasets
    • Implements caching where appropriate
    • Avoids redundant data fetching
// Good: Batch requests when possible
const posts = await this.fetchPosts(limit)
const comments = await Promise.all(
posts.map(post => this.fetchComments(post.id))
)

// Bad: Sequential requests
for (const post of posts) {
await this.fetchComments(post.id) // Slow!
}
  • Memory efficient
    • Streams large responses when possible
    • Cleans up resources after use
    • Avoids memory leaks (event listeners, timers)

11. Data Quality​

  • Proper data normalization
    • All required fields are populated
    • Dates are ISO 8601 strings
    • Text content is cleaned (HTML stripped, etc.)
    • Metrics are numbers, not strings
    • Author info is complete
// Required normalization format
{
id: string
platform: 'myplatform'
type: 'post' | 'comment' | 'reply'
text: string // Cleaned text content
timestamp: string // ISO 8601 format
author: {
id: string
username: string
name: string
}
metrics?: {
likes?: number
shares?: number
replies?: number
}
raw: any // Preserve original data
}

12. Metadata​

  • Package metadata
    • package.json has all required fields
    • Version follows semver
    • Description is clear and accurate
    • Keywords include 'idiomark', 'adapter', platform name
    • Repository field points to Idiomark repo
{
"name": "@idiomark/adapter-myplatform",
"version": "1.0.0",
"description": "MyPlatform adapter for Idiomark personality extraction",
"keywords": ["idiomark", "adapter", "myplatform", "personality"],
"repository": {
"type": "git",
"url": "https://github.com/idiomark/idiomarkengine.git",
"directory": "packages/adapters/myplatform"
}
}

Automated Checks​

CI/CD Pipeline​

All adapters are automatically checked in CI:

# .github/workflows/adapter-test.yml
steps:
- name: Build adapter
run: pnpm build --filter @idiomark/adapter-${{ adapter }}

- name: Type check
run: pnpm typecheck --filter @idiomark/adapter-${{ adapter }}

- name: Lint
run: pnpm lint --filter @idiomark/adapter-${{ adapter }}

- name: Run tests
run: pnpm test --filter @idiomark/adapter-${{ adapter }}

- name: Check coverage
run: pnpm test:coverage --filter @idiomark/adapter-${{ adapter }}

Validation Script​

Run before submitting:

# Validate adapter against all quality standards
pnpm adapter validate myplatform

# Output:
# ✅ Implements PlatformAdapter interface
# ✅ TypeScript types are complete
# ✅ Rate limiting is configured
# ✅ Error handling is comprehensive
# ✅ Test coverage: 87.5% (>80% required)
# ✅ README is complete
# ✅ No hardcoded credentials
# ✅ Build succeeds
# ✅ All checks passed!

Manual Review Criteria​

Code Review Checklist​

Maintainers will manually verify:

  1. Architecture

    • Clean separation of concerns
    • Proper use of dependency injection
    • No code duplication
    • Follows adapter template
  2. Security

    • Input validation
    • Output encoding
    • Secure credential handling
    • No sensitive data in logs
  3. Documentation

    • Clear README with examples
    • Inline comments for complex logic
    • API docs are accurate
    • Troubleshooting guide is helpful
  4. Testing

    • Tests cover happy paths
    • Tests cover error paths
    • Tests are maintainable
    • Mock data is realistic

Common Rejection Reasons​

IssueWhy It MattersHow to Fix
Hardcoded credentialsSecurity riskUse environment variables
Missing error handlingAdapter will crashAdd try/catch with specific errors
No rate limitingWill exceed API limitsImplement rate limiter
Low test coverageBugs will reach usersAdd more tests
Missing typesRuntime errorsAdd TypeScript types
No documentationOthers can't use itWrite a complete README
Builds with warningsQuality concernsFix all warnings

Template for New Adapters​

Use the official adapter template:

# Generate a new adapter with all required scaffolding
pnpm cli generate adapter

# Or manually copy the template
cp -r templates/adapter-template packages/adapters/myplatform

The template includes:

  • Pre-configured TypeScript settings
  • Example implementations
  • Test scaffolding
  • README template
  • CI/CD configuration

Resources​


Remember: Quality standards exist to ensure Idiomark adapters are reliable, secure, and maintainable. When in doubt, ask in a GitHub Discussion or PR!