A comprehensive JavaScript/TypeScript client library generator for the REST PKI Core API, featuring auto-generated clients from OpenAPI specifications and a unified facade interface.
This project provides tools and configurations to generate a complete Node.js client library for REST PKI Core API, including:
- Auto-generated API clients from OpenAPI specifications
- Unified facade client with simplified interface
- Complete TypeScript support with full type definitions
- Configurable generation process with JSON configuration
- Ready-to-publish npm package with proper metadata
RestPkiCoreNodeClient/
βββ π§ Generation Tools
β βββ generate-api-client.ps1 # PowerShell generation script
β βββ openapi-generator-config.json # Complete OpenAPI Generator config
β βββ openapitools.json # OpenAPI tools configuration
β
βββ π― Custom Client Library
β βββ rest-pki-core-client.ts # TypeScript facade client
β βββ rest-pki-core-client.js # JavaScript facade client
β βββ CLIENT_USAGE_GUIDE.md # Complete client documentation
β βββ lib/ # Legacy library files
β
βββ π€ Generated Client (Output)
β βββ generated-client/
β β βββ api/ # 13 generated API classes
β β βββ model/ # 130+ generated type definitions
β β βββ dist/ # Compiled JavaScript output
β β βββ package.json # NPM package configuration
β β βββ README.md # User-focused documentation
β βββ [All files generated from OpenAPI spec]
β
βββ π Documentation
βββ README.md # This developer guide
βββ [Generated documentation files]
git clone <repository-url>
cd RestPkiCoreNodeClient
# Ensure you have OpenAPI Generator CLI installed
npm install @openapitools/openapi-generator-cli -g
# or use the local installation via npx
# Run the PowerShell script to generate everything
powershell -ExecutionPolicy Bypass -File .\generate-api-client.ps1 -Force
# Or on Unix systems, you can call the OpenAPI generator directly:
# npx @openapitools/openapi-generator-cli generate -c openapi-generator-config.json
cd generated-client
npm install
npm run build # Compile TypeScript
npm test # Run tests (if configured)
cd ..
# Make changes to configuration
edit openapi-generator-config.json
# Regenerate client
.\generate-api-client.ps1 -Force
# Test the facade client
node rest-pki-core-client.js
# Or test with TypeScript
npx ts-node rest-pki-core-client.ts
The library uses a comprehensive JSON configuration file for OpenAPI generation:
{
"generatorName": "typescript-node",
"inputSpec": "https://homolog.core.pki.rest/swagger/api/swagger.json",
"outputDir": "./generated-client",
"additionalProperties": {
"npmName": "restpki-core-client",
"npmVersion": "1.0.2",
"supportsES6": true,
"withInterfaces": true,
"typescriptThreePlus": true,
"emitJSDoc": true,
"withNodeImports": true,
"npmRepository": "https://github.com/your-username/rest-pki-core-node-client",
"npmDescription": "REST PKI Core Node.js Client Library",
"modelPropertyNaming": "camelCase",
"paramNaming": "camelCase",
"enumPropertyNaming": "UPPERCASE",
"stringEnums": true,
"usePromises": true,
"useRxJS": false,
"platform": "node",
"withSeparateModelsAndApi": true,
"modelPackage": "model",
"apiPackage": "api",
"sortParamsByRequiredFlag": true,
"ensureUniqueParams": true,
"allowUnicodeIdentifiers": false,
"disallowAdditionalPropertiesIfNotPresent": false,
"prependFormOrBodyParameters": false,
"legacyDiscriminatorBehavior": false,
"useObjectParameters": false
},
"globalProperties": {
"models": "",
"apis": "",
"supportingFiles": "true",
"modelTests": "false",
"modelDocs": "false",
"apiTests": "false",
"apiDocs": "false"
}
}
generatorName
: Usestypescript-node
for Node.js TypeScript clientinputSpec
: REST PKI Core OpenAPI specification URLoutputDir
: Output directory for generated filesnpmName
: Package name for publishing to npmsupportsES6
: Enables ES6+ featureswithInterfaces
: Generates TypeScript interfacestypescriptThreePlus
: Uses TypeScript 3+ featuresmodelPropertyNaming
: Converts property names to camelCaseusePromises
: Uses Promise-based API instead of callbacks
The generate-api-client.ps1
script automates the entire generation process:
param(
[switch]$Force = $false
)
# Check if OpenAPI Generator CLI is available
if (!(Get-Command "openapi-generator-cli" -ErrorAction SilentlyContinue)) {
Write-Host "OpenAPI Generator CLI not found. Installing..." -ForegroundColor Yellow
npm install -g @openapitools/openapi-generator-cli
}
# Remove existing generated client if Force is specified
if ($Force -and (Test-Path "generated-client")) {
Write-Host "Removing existing generated-client directory..." -ForegroundColor Yellow
Remove-Item -Recurse -Force "generated-client"
}
# Generate the client
Write-Host "Generating REST PKI Core client..." -ForegroundColor Green
openapi-generator-cli generate -c openapi-generator-config.json
# Navigate to generated client and install dependencies
cd generated-client
Write-Host "Installing dependencies..." -ForegroundColor Green
npm install
# Build TypeScript
Write-Host "Building TypeScript..." -ForegroundColor Green
npx tsc
Write-Host "Client generation completed successfully!" -ForegroundColor Green
# Generate using npx (recommended)
npx @openapitools/openapi-generator-cli generate -c openapi-generator-config.json
# Or using global installation
openapi-generator-cli generate -c openapi-generator-config.json
# Validate configuration before generation
npx @openapitools/openapi-generator-cli config-help -g typescript-node
AuthenticationApi.ts
- Authentication operationsCadesSignatureApi.ts
- CAdES signature operationsDocumentsApi.ts
- Document managementDocumentKeysApi.ts
- Document key allocationPadesSignatureApi.ts
- PAdES signature operationsPadesVisualPositioningPresetsApi.ts
- Visual positioningPdfApi.ts
- PDF processing operationsSignatureApi.ts
- General signature operationsSignatureInspectionApi.ts
- Signature validationSignatureSessionsApi.ts
- Signature session managementTimestampApi.ts
- Timestamp servicesUploadApi.ts
- File upload operationsXmlSignatureApi.ts
- XML signature operations
All request/response models, enums, and type definitions are generated in the model/
directory with full TypeScript support.
package.json
- NPM package configurationtsconfig.json
- TypeScript compilation settingsindex.ts
- Main export fileREADME.md
- User documentation
The facade client (rest-pki-core-client.ts
) provides a unified interface over all generated APIs:
- Single Configuration: One configuration object for all APIs
- Unified Error Handling: Consistent error handling across all operations
- Response Wrapping: Standardized response format with status codes
- Type Safety: Full TypeScript support with IntelliSense
- Method Consistency: Standardized method naming conventions
// Facade client structure
export class RestPkiCoreClient {
private config: ClientConfig;
private apis: {
documents: DocumentsApi;
signatures: PadesSignatureApi;
// ... other APIs
};
constructor(config: ClientConfig) {
this.config = config;
this.initializeApis();
}
// Wrapper methods for each API operation
async getDocument(id: string): Promise<ApiResponse<DocumentModel>> {
try {
const response = await this.apis.documents.apiDocumentsIdGet(id);
return {
success: true,
data: response.data,
status: response.status,
headers: response.headers
};
} catch (error) {
return this.handleError(error);
}
}
}
- The OpenAPI specification is updated automatically
- Run the generation script to get latest changes:
.\generate-api-client.ps1 -Force
- Edit
openapi-generator-config.json
- Regenerate the client
- Test the changes
- Update facade client if needed
- Update version in
openapi-generator-config.json
- Regenerate client
- Update
package.json
version - Commit and tag release
- OpenAPI Generator CLI is installed
- Configuration file is valid
- Output directory is clean (use
-Force
if needed) - Internet connection for downloading OpenAPI spec
- Generated files compile without errors
- TypeScript definitions are complete
- Package.json has correct metadata
- README.md is appropriate for users
- No sensitive information in generated files
- Version number is incremented
- All tests pass
- Documentation is up to date
- License file is present
- Repository URL is correct
cd generated-client
npm test # Run generated tests (if configured)
// Test facade client functionality
const client = createRestPkiCoreClient({
baseUrl: 'https://homolog.core.pki.rest',
apiKey: process.env.REST_PKI_API_KEY
});
// Test connection
await client.testConnection();
// Test document operations
const documents = await client.getDocuments();
# Test generated APIs directly
node -e "
const { DocumentsApi } = require('./generated-client/dist/api');
const api = new DocumentsApi('https://homolog.core.pki.rest');
api.defaultHeaders = { 'X-Api-Key': 'test-key' };
console.log('API instance created successfully');
"
- 13 API Classes: Complete coverage of REST PKI Core
- 130+ Type Definitions: Full TypeScript support
- Zero Manual Code: Everything generated from OpenAPI spec
- Full Documentation: JSDoc comments in all generated code
- npm Ready: Configured for immediate publishing
cd generated-client
npm version patch # or minor/major
npm run build
npm pack --dry-run # Test packaging
npm login
npm publish
# Or with tag
npm publish --tag beta
npm view restpki-core-client # Verify publication
- Fork the repository
- Clone your fork
- Install dependencies
- Make changes to configuration or facade client
- Regenerate and test
- Submit pull request
- Follow TypeScript best practices
- Use consistent naming conventions
- Include JSDoc comments for public APIs
- Maintain backward compatibility when possible
- v1.0.2 - Initial release with full API coverage
- v1.0.0 - Beta release with basic functionality
MIT License - See LICENSE file for details.
Developer Note: This project uses OpenAPI Generator to automatically create client libraries from the REST PKI Core API specification. The generated code should not be manually edited as it will be overwritten on regeneration. All customizations should be made in the facade client or configuration files.