🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@vc-shell/api-client-generator

Package Overview
Dependencies
Maintainers
1
Versions
378
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vc-shell/api-client-generator

Tool for API clients generation

1.1.52
latest
npm
Version published
Weekly downloads
1.3K
200%
Maintainers
1
Weekly downloads
 
Created
Source

Platform Manager REST Client

Generate API client

This guide describes the process of generating an API client to access the VC Platform API from your custom application.

!!! note Platform Manager REST Client offers generated REST API methods that make it easy to interact with the existing VirtoCommerce Platform API.

Prerequisites

  • .NET Core 6.0, particularly if you are using MacOS or Linux.

Generate TypeScript API clients

To enable TypeScript API client generation in your project:

  • Add dependencies to your project:

Using command

yarn add @vc-shell/api-client-generator cross-env

cross-env runs scripts that set and use environment variables across platforms.

Manually

Add the dependencies to your project's package.json:

{
    ...
    "devDependencies": {
        ...
        "@vc-shell/api-client-generator": "latest",
        "cross-env": "latest",
        ...
    }
}
  • Configure client generation in your project. Inside your project's package.json file, add a "generate-api-client" command to the list of scripts:

    {
        "scripts": {
        ...
        "generate-api-client": cross-env api-client-generator --APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Catalog,Virtocommerce.Orders]' --APP_API_CLIENT_DIRECTORY=./src/api_client/
        }
    }
    

    The options are listed in the table below:

    OptionsDescriptionExample
    --APP_PLATFORM_MODULESPlatform modules to generate API client.
    {==string[]==}
    Customize the --APP_PLATFORM_MODULES list
    to match your project's requirements.
    --APP_PLATFORM_MODULES='[Virtocommerce.MarketplaceVendor,Virtocommerce.Orders,Virtocommerce.Catalog]'
    --APP_API_CLIENT_DIRECTORYOutput directory for generated API clients.
    {==string==}
    --APP_API_CLIENT_DIRECTORY=./src/api_client/
    --APP_PLATFORM_URLPlatform URL to obtain client API configs.
    {==string==}
    --APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
    --APP_PACKAGE_NAMEPackage name for generated API clients.
    {==string==}
    --APP_PACKAGE_NAME=@api-client
    --APP_PACKAGE_VERSIONPackage version for generated API clients.
    {==string==}
    --APP_PACKAGE_VERSION=1.1.0
    --APP_OUT_DIROutput directory for generated API clients.
    {==string==}
    --APP_OUT_DIR=./src/api_client/
    --APP_TYPE_STYLESets the type style for generated DTOs. Can be 'Class' or 'Interface'.
    {==string==}
    --APP_TYPE_STYLE=Interface
    --APP_BUILD_DIRDirectory where TypeScript files will be compiled.
    {==string==}
    --APP_BUILD_DIR=lib (default is "dist")
    --SKIP_BUILDSkip build step.
    {==boolean==}
    --SKIP_BUILD=true
    --VERBOSEEnable verbose logging.
    {==boolean==}
    --VERBOSE=true
  • Configure Platform URL to ensure your project can access the platform's API configurations. Add the platform URL to your project's .env file:

    APP_PLATFORM_URL=https://vcmp-dev.govirto.com/
    

    !!! note Alternatively, you can specify the Platform URL as a command option in the previous step when running the "generate-api-client" command.

  • Generate the API clients using the following command:

    yarn generate-api-client
    

This command generates the required API clients for your custom application. Now you can effortlessly access the VC Platform API from your custom application using the generated API client.

Features

Smart Configuration Merging

The generator now intelligently merges configuration files to preserve your custom settings. When you update an existing API client:

  • Custom package.json fields like name, version, description, keywords, author and license are preserved
  • Custom tsconfig.json settings are maintained
  • Exports are intelligently updated to preserve existing paths

Metadata Tracking

API client now includes metadata to track the generation:

{
  "apiClientGenerator": {
    "version": "1.1.0",
    "generatedAt": "2025-04-01T12:30:45.123Z"
  }
}

Multiple API Exports

The generator handles multiple API clients effectively:

  • Creates standardized exports with both short names (./{moduleName}) and full names (./virtocommerce.{moduleName})
  • Prevents duplicate module exports by intelligently merging with existing ones
  • Automatically removes module and types fields that conflict with multiple exports
  • Works properly with incremental generation (can add new APIs without breaking existing ones)

Smart Root Export Handling

The generator now intelligently handles root exports based on the number of API modules:

  • Single API Module: When only one API module is generated, it automatically becomes the root export (.) and module/types fields are maintained
  • Multiple API Modules: When multiple API modules are generated, only subpath exports are used (e.g., ./moduleA, ./moduleB)
  • Preserving Preferences: If a root export already exists, it will be preserved as long as it points to one of the generated modules

This enables both simple usage for single-API packages and proper subpath exporting for multi-API packages:

// Single API package (using root export)
import { MyClient } from '@myapp/api';

// Multi-API package (using subpath exports)
import { ClientA } from '@myapp/api/moduleA';
import { ClientB } from '@myapp/api/moduleB';

Directory Creation

Target directories are automatically created if they don't exist.

Verbose Logging

Enable detailed logging to troubleshoot generation issues:

yarn generate-api-client --VERBOSE=true

Custom Build Directory

You can specify a custom build directory where TypeScript files will be compiled:

yarn generate-api-client --APP_BUILD_DIR=lib

By default, the build directory is "dist".

Error Handling Improvements

Better error handling and reporting make it easier to diagnose issues during client generation.

Recent Improvements (v1.1.8)

Fixed Issues

  • Configuration Preservation: Fixed issue where package.json and tsconfig.json user settings were being overwritten
  • Export Path Management: Improved export path handling to prevent incorrect paths with duplicated prefixes
  • Path Normalization: Added better path normalization to handle edge cases correctly
  • Export Deduplication: Implemented smarter export merging to prevent duplicate exports with different path formats
  • Build Directory Support: Added proper support for custom build directories via APP_BUILD_DIR parameter
  • Declaration Files Location: Fixed issue with TypeScript declaration files location to match the build directory
  • Error Handling: Improved JSON parsing error handling with better fallback strategies
  • Root Export Handling: Fixed issue with root exports being ignored or improperly handled

New Features

  • Intelligent Config Merging: Complete rewrite of configuration merging logic to better preserve user settings
  • Export Path Standardization: New system for standardizing export paths to improve consistency
  • Path Validation: Added strict validation of export paths to prevent invalid configurations
  • Improved Logging: Added more detailed logging for better debugging
  • Extended User Fields Preservation: Expanded the list of user-defined fields that are preserved during updates
  • Better Directory Management: Improved directory creation and validation process
  • Smart Single/Multi API Detection: Automatically detects single API scenarios and creates appropriate root exports
  • Module/Types Field Handling: Preserves module and types fields for single API packages while removing them for multi-API packages

Troubleshooting

If you encounter issues during API client generation:

  • Enable verbose logging with --VERBOSE=true
  • Ensure target directories have proper permissions
  • Check your connectivity to the platform URL
  • Verify that the specified platform modules exist
  • If you encounter JSON parsing errors in tsconfig.json or package.json, try using the --VERBOSE=true flag to see detailed error messages
  • Check for duplicate exports in your package.json which might cause conflicts
  • If you manually modified exports in package.json, ensure they follow the correct format

FAQs

Package last updated on 02 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts