Package Exports
- @postato/shared
- @postato/shared/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@postato/shared) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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/sharedCLI 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: 'user@example.com',
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 templateRequirements
- 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:coverageTest 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
MIT © chatonode
Keywords
postman, api-testing, test-generation, typescript, parser, code-generation, json-schema