npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tonytang99/erp-to-magento-mapper

v1.0.0

Published

A declarative, flexible engine to transform ERP data objects into Magento 2 product payloads.

Readme

ERP to Magento Mapper

npm version

A declarative, flexible, and powerful engine to transform data objects from any source (like an ERP) into a fully-formed Magento 2 product payload, ready for the REST API.

This package is designed to separate your business mapping logic from the transformation engine, making your integration code cleaner, more maintainable, and easier to test. It fully supports simple mappings, complex transformations, static values, and even asynchronous lookups for things like fetching Magento attribute option IDs from a database.

Key Features

  • Declarative Mapping: Define your complex transformation rules in a simple, readable configuration file.
  • Asynchronous Support: Easily handle async/await operations within your mapping for database lookups or other API calls.
  • Nested Path Support: Maps directly to Magento's nested structures like extension_attributes.stock_item and custom_attributes.
  • Lightweight & Dependency-Free: Has only one tiny dependency (lodash.set) for utility.
  • Clean & Maintainable: Decouples mapping logic from your core application flow, making changes trivial.

Installation

npm install @tonytang99/erp-to-magento-mapper

Quick Start

The core idea is to create a mapping configuration file and then use the createMapper to process your source data.

1. Create Your Mapping Configuration

This file defines how your source ERP data maps to Magento's product structure.

erp-magento-mapping.js:

/**
 * Defines the mapping from an ERP source object to the Magento product payload.
 *
 * @param {object} deps - Optional dependencies for transformations (e.g., a DB client).
 */
const createMapping = (deps) => ({
  // Maps to top-level Magento product attributes
  core: {
    'sku': 'productId',             // Direct 1-to-1 mapping
    'name': 'description_1',
    'price': 'sales_price_3',
    'status': () => 1,              // Static value
    'visibility': () => 4,
  },

  // Maps to extension_attributes
  extensionAttributes: {
    'stock_item.qty': 'inventory',
    'stock_item.is_in_stock': (source) => source.inventory > 0, // Transformation function
  },

  // Maps to the custom_attributes array
  customAttributes: {
    'description': 'description_2',
    'rrp': 'sales_price_4',

    // Asynchronous transformation for lookups
    'brand': async (source) => {
      if (!source.class_2) return null;
      // const optionId = await lookupBrandId(source.class_2, deps.dbClient);
      // return optionId;
      const brandMap = { 'Nike': '124', 'Adidas': '125' };
      return brandMap[source.class_2] || null;
    },
  },
});

export default createMapping;

2. Use the Mapper in Your Application

In your integration logic (e.g., an AWS Lambda function), import and use the mapper.

importer.js:

import { createMapper } from '@your-username/erp-to-magento-mapper';
import createMapping from './erp-magento-mapping.js';

// Example ERP product data
const erpProduct = {
  productId: 'NK-SHOE-RED-10',
  description_1: 'Awesome Running Shoe',
  description_2: 'The best running shoe for any terrain.',
  inventory: 50,
  sales_price_3: 99.99,
  sales_price_4: 129.99,
  class_2: 'Nike', // Brand
};

// 1. Initialize the mapper with your configuration
const mappingConfig = createMapping(/* pass dependencies here if any */);
const mapper = createMapper(mappingConfig);

// 2. Transform the data
async function transformProduct() {
  try {
    const magentoPayload = await mapper.transform(erpProduct);
    console.log(JSON.stringify(magentoPayload, null, 2));
    // Now send this payload to the Magento API...
  } catch (error) {
    console.error('Transformation failed:', error);
  }
}

transformProduct();

Expected Output

The code above will generate the following Magento-ready payload:

{
  "product": {
    "custom_attributes": [
      {
        "attribute_code": "description",
        "value": "The best running shoe for any terrain."
      },
      {
        "attribute_code": "rrp",
        "value": 129.99
      },
      {
        "attribute_code": "brand",
        "value": "124"
      }
    ],
    "sku": "NK-SHOE-RED-10",
    "name": "Awesome Running Shoe",
    "price": 99.99,
    "status": 1,
    "visibility": 4,
    "extension_attributes": {
      "stock_item": {
        "qty": 50,
        "is_in_stock": true
      }
    }
  }
}

API

createMapper(mappingConfig)

  • mappingConfig <Object>: The configuration object that defines the mapping rules.
  • Returns <MagentoMapper>: An instance of the mapper.

mapper.transform(sourceObject)

  • sourceObject <Object>: The source data object to be transformed.
  • Returns <Promise<Object>>: A promise that resolves to the final Magento product payload.

The sourceObject is passed as an argument to any transformation functions defined in the mapping configuration.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is MIT licensed.