@postato/shared

v0.2.15

Published

CLI tool and library for generating TypeScript API test skeletons from Postman collections. Automatically detects architecture patterns and creates production-ready test files.

Readme

@postato/shared

Shared utilities and modules for the Postman-to-API-Tests conversion system. This library provides reusable, deterministic modules for parsing Postman collections and generating API test scaffolding.

Features

  • Postman Parser Utilities: Parse and analyze Postman collections and environments
  • Schema Generation: Automatically generate JSON schemas from API responses
  • URL Parsing: Extract path/query parameters and infer TypeScript types
  • Variable Classification: Detect architecture patterns (single/microservices, single/multiple auth)
  • Code Generation: Generate request wrappers and test file skeletons
  • CLI Tool: Command-line interface for generating test scaffolding

Installation

npm install @postato/shared

CLI Usage

Generate test scaffolding from Postman collection:

postato-generate --collection <path> --environment <path> --output <path>

Options:

  • --collection, -c: Path to Postman collection JSON file (required)
  • --environment, -e: Path to Postman environment JSON file (required)
  • --output, -o: Path to project root directory (required)
  • --overwrite: Overwrite existing files (optional, default: false)

Programmatic Usage

URL Parser

import { UrlParser } from '@postato/shared';

const result = UrlParser.parseUrl('{{baseUrl}}/users/:userId/posts?page=1&limit=10');

console.log(result.pathParams);
// [{ name: 'userId', type: 'number', camelCase: 'userId' }]

console.log(result.queryParams);
// [
//   { name: 'page', type: 'number', camelCase: 'page', required: true },
//   { name: 'limit', type: 'number', camelCase: 'limit', required: true }
// ]

Schema Generator

import { SchemaGenerator } from '@postato/shared';

const response = {
  id: 1,
  email: '[email protected]',
  createdAt: '2025-01-01T00:00:00Z'
};

const schema = SchemaGenerator.generateSchema(response);
// Generates JSON Schema draft-07 with detected formats (email, date-time)

Variable Classifier

import { VariableClassifier } from '@postato/shared';

const variables = [
  { key: 'mainApiUrl', value: 'https://api.example.com', enabled: true },
  { key: 'adminToken', value: 'token123', enabled: true }
];

const classified = VariableClassifier.classifyVariables(variables);
console.log(classified.architecture);
// { urlPattern: 'SINGLE', authPattern: 'SINGLE' }

Name Transformer

import { NameTransformer } from '@postato/shared';

NameTransformer.toCamelCase('Get User Profile'); // 'getUserProfile'
NameTransformer.toKebabCase('getUserProfile'); // 'get-user-profile'
NameTransformer.toPascalCase('get-user-profile'); // 'GetUserProfile'
NameTransformer.toConstantName('mainApiUrl'); // 'MAIN_API_URL'

Module Structure

@postato/shared
├── utils/               # Utility modules
│   ├── name-transformer     # String transformations
│   └── variable-classifier  # Architecture pattern detection
├── parsers/             # Parser modules
│   ├── url-parser          # URL/parameter extraction
│   └── schema-generator    # JSON Schema generation
├── generators/          # Code generators
│   ├── config-writer       # Config file updates
│   ├── env-writer          # Environment file generation
│   ├── skeleton-writer     # Skeleton code generation
│   └── postman-generator   # Main orchestrator
└── templates/           # Code templates
    ├── request.template    # Request wrapper template
    └── test.template       # Test file template

Requirements

  • Node.js >= 18
  • TypeScript >= 5.0 (for TypeScript projects)

Development

# Install dependencies
npm install

# Run tests
npm test

# Build
npm run build

# Watch tests
npm run test:watch

# Coverage
npm run test:coverage

Test Coverage

The library maintains high test coverage standards:

  • Branches: ≥ 85%
  • Functions: ≥ 90%
  • Lines: ≥ 90%
  • Statements: ≥ 90%

Current: 284 tests across unit and integration suites

License

This project is licensed under the MIT License - see the LICENSE file for details.