npm package: @pactosigna/schemas
Description: Zod schemas, types, and constants for PactoSigna QMS document validation (ISO 13485)
Latest version: 0.1.51

# @pactosigna/schemas

Zod schemas, TypeScript types, and constants for validating PactoSigna QMS documents (ISO 13485, IEC 62304, ISO 14971).

This package is the public-facing subset of `@pactosigna/shared`. It bundles everything inline via tsup so consumers only need `zod` as a dependency.

## Installation

```bash
npm install @pactosigna/schemas
```

## Usage

### Validate document frontmatter

Use `getSchemaForDocumentType` to retrieve the Zod schema for a given document type, then validate frontmatter parsed from YAML.

```typescript
import { getSchemaForDocumentType } from '@pactosigna/schemas';

const schema = getSchemaForDocumentType('user_need');
if (schema) {
  const result = schema.safeParse({
    id: 'UN-001',
    title: 'Role-Based Access Control',
    status: 'draft',
    stakeholder: 'Quality Manager',
    priority: 'must_have',
  });

  if (!result.success) {
    console.error('Validation errors:', result.error.issues);
  }
}
```

### Check required sections

Each document type can declare mandatory H2 sections. The sync engine uses this to flag missing content.

```typescript
import { REQUIRED_SECTIONS } from '@pactosigna/schemas';

const sections = REQUIRED_SECTIONS.user_need;
// ['User Story', 'Validation Criteria']
```

### List all document types

```typescript
import { DOCUMENT_TYPES } from '@pactosigna/schemas';

for (const [key, label] of Object.entries(DOCUMENT_TYPES)) {
  console.log(`${key}: ${label}`);
}
// user_need: User Need
// requirement: Requirement
// ...
```

### Use TypeScript types

All frontmatter schemas export their inferred types.

```typescript
import type { UserNeedFrontmatter, RequirementFrontmatter } from '@pactosigna/schemas';

const need: UserNeedFrontmatter = {
  id: 'UN-001',
  title: 'Audit Trail Visibility',
  status: 'approved',
  stakeholder: 'Quality Manager',
  priority: 'must_have',
};
```

### Classify document types

```typescript
import {
  isQmsDocumentType,
  isDeviceDocumentType,
  QMS_DOCUMENT_TYPES,
  DEVICE_DOCUMENT_TYPES,
} from '@pactosigna/schemas';

isQmsDocumentType('sop'); // true
isDeviceDocumentType('user_need'); // true
```

## Exports

| Category                | Examples                                                                                                                            |
| ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| **Constants**           | `DOCUMENT_TYPES`, `REQUIRED_SECTIONS`, `LINK_TYPES`                                                                                 |
| **Classification**      | `QMS_DOCUMENT_TYPES`, `DEVICE_DOCUMENT_TYPES`, `CHANGE_DOCUMENT_TYPES`                                                              |
| **Predicates**          | `isQmsDocumentType`, `isDeviceDocumentType`, `isChangeDocumentType`                                                                 |
| **Zod enums**           | `DocumentTypeSchema`, `DocumentStatusSchema`, `LinkTypeSchema`, `SafetyClassSchema`                                                 |
| **Frontmatter schemas** | `UserNeedFrontmatterSchema`, `RequirementFrontmatterSchema`, `RiskEntryFrontmatterSchema`, `AnomalyFrontmatterSchema`, and 30+ more |
| **Schema map**          | `SCHEMA_MAP`, `getSchemaForDocumentType`                                                                                            |
| **Repo config**         | `RepoConfigSchema`, `ReleaseReviewConfigSchema`                                                                                     |
| **Retention**           | `RetentionPolicySchema`, `isWithinRetentionPeriod`, `getEffectiveRetentionYears`                                                    |

## License

MIT