Skip to content

Latest commit

 

History

History
229 lines (181 loc) · 5.82 KB

File metadata and controls

229 lines (181 loc) · 5.82 KB

SDK Generation Microservice

A NestJS microservice for generating and downloading enterprise-grade cryptographic SDKs for multiple programming languages.

Overview

This microservice handles:

  • SDK Generation: Generate SDKs for 13+ programming languages
  • SDK Download: Create and stream ZIP archives of generated SDKs
  • Code Reusability: Modular architecture with separated concerns

Architecture

┌─────────────────────────────────────────┐
│         SDK Controller                  │
│  (REST API Endpoints)                   │
└──────────────┬──────────────────────────┘
               │
       ┌───────┴────────┐
       │                 │
┌──────▼──────┐  ┌──────▼────────┐
│ Generation  │  │ Download      │
│ Service     │  │ Service       │
└──────┬──────┘  └──────┬────────┘
       │                 │
       └────────┬────────┘
                │
        ┌───────▼──────────┐
        │ Enterprise       │
        │ Adapter Service  │
        └───────┬──────────┘
                │
        ┌───────▼──────────┐
        │ SDK Generator    │
        │ (CommonJS)       │
        └──────────────────┘

Features

  • Multi-language Support: JavaScript, Python, Java, Go, C/C++, C#, Swift, Kotlin, Rust, PHP, Ruby, Scala, Dart
  • Enterprise Security: All 18 security gates implemented
  • ZIP Archive Generation: Automatic packaging of SDK files
  • Validation: Request validation with class-validator
  • Error Handling: Comprehensive error handling and logging
  • Modular Design: Separated services for generation and download

API Endpoints

POST /sdk/generate

Generate SDKs for specified languages.

Request Body:

{
  "sdkId": "sdk-123",
  "name": "MySDK",
  "version": "2.0.0",
  "languages": ["javascript", "python"],
  "algorithms": ["aes-256-gcm"],
  "tenantId": "tenant-123",
  "telemetryEnabled": true,
  "envelopeEncryptionEnabled": true
}

Response:

{
  "success": true,
  "data": {
    "success": true,
    "sdkId": "sdk-123",
    "languages": ["javascript", "python"],
    "fileCounts": {
      "javascript": 15,
      "python": 12
    },
    "message": "SDK generation completed successfully"
  }
}

POST /sdk/download

Generate and download SDK as ZIP archive.

Request Body: (Same as generate endpoint)

Response: ZIP file stream with appropriate headers

POST /sdk/size

Get estimated archive size before download.

Request Body: (Same as generate endpoint)

Response:

{
  "success": true,
  "size": 1024000,
  "sizeFormatted": "1 MB"
}

GET /sdk/health

Health check endpoint.

Response:

{
  "status": "ok",
  "service": "sdk-generation",
  "timestamp": "2024-01-01T00:00:00.000Z"
}

Installation

cd services/sdk
npm install

Running the Service

# Development
npm run start:dev

# Production
npm run build
npm run start:prod

Environment Variables

PORT=33201
ALLOWED_ORIGINS=http://localhost:3000,https://yourdomain.com

Dependencies

  • @nestjs/common: NestJS core framework
  • archiver: ZIP archive creation
  • class-validator: Request validation
  • class-transformer: Data transformation

Project Structure

src/
├── main.ts                          # Application entry point
├── app.module.ts                    # Root module
└── sdk/
    ├── sdk.controller.ts            # REST API endpoints
    ├── sdk.module.ts               # SDK module
    ├── sdk.service.ts              # Base SDK service
    ├── dto/
    │   ├── create-sdk.dto.ts       # Create SDK DTO
    │   ├── generate-sdk.dto.ts     # Generate SDK DTO
    │   └── update-sdk.dto.ts       # Update SDK DTO
    ├── entities/
    │   └── sdk.entity.ts           # SDK entity
    ├── interfaces/
    │   └── sdk-generator.interface.ts  # TypeScript interfaces
    └── services/
        ├── enterprise-adapter.service.ts  # Generator adapter
        ├── sdk-generation.service.ts       # Generation logic
        └── sdk-download.service.ts         # Download logic

Integration with Main Application

The main application can call this microservice via HTTP:

// Example: Call from main application
const response = await fetch('http://localhost:33201/sdk/generate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    sdkId: sdk.id,
    name: sdk.name,
    version: sdk.version,
    languages: sdk.languages,
    algorithms: sdk.algorithms,
    // ... other fields
  }),
});

Generator Path Resolution

The service automatically resolves the SDK generator path by checking:

  1. ../../generators/main-generator.cjs (modular structure)
  2. ../enterprise-sdk-generator-fixed.cjs (original structure)
  3. Current working directory paths

Ensure the generator files are accessible from the microservice location.

Error Handling

All endpoints include comprehensive error handling:

  • Validation errors return 400 Bad Request
  • Generation errors return 500 Internal Server Error
  • All errors are logged with context

Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Coverage
npm run test:cov

License

UNLICENSED