vendure-data-hub-plugin

Developer Guide

This guide covers the code-first DSL, architecture, and extending the Data Hub plugin.

Pipeline Hooks
Pipeline Hooks - Execute custom code at every stage of pipeline execution

Contents

  1. Architecture Overview - How the plugin works internally
  2. DSL Reference
  3. Testing Guide - Unit, integration, and end-to-end testing
  4. Programmatic Field Mapping - Typed record mapping and auto-mapping services
  5. Extending the Plugin
  6. GraphQL API - API reference for integration

When to Use Code-First

Use the code-first DSL when:

Use the visual builder when:

Quick Example

import { createPipeline } from '@oronts/vendure-data-hub-plugin';

const pipeline = createPipeline()
    .name('Product Sync')
    .description('Sync products from ERP system')
    .trigger('schedule', { type: 'SCHEDULE', cron: '0 2 * * *' })
    .extract('fetch-erp', {
        adapterCode: 'httpApi',
        connectionCode: 'erp-api',
        url: '/products',
        dataPath: 'data.products',
    })
    .transform('map-fields', {
        operators: [
            { op: 'rename', args: { from: 'product_name', to: 'name' } },
            { op: 'rename', args: { from: 'product_sku', to: 'sku' } },
            { op: 'slugify', args: { source: 'sku', target: 'slug' } },
        ],
    })
    .load('upsert-products', {
        adapterCode: 'productUpsert',
        strategy: 'UPSERT',
        slugField: 'slug',
    })
    .edge('schedule', 'fetch-erp')
    .edge('fetch-erp', 'map-fields')
    .edge('map-fields', 'upsert-products')
    .build();

Hook Scripts

Register functions that can modify records at the 18 data-processing stages:

DataHubPlugin.init({
    scripts: {
        'validate-sku': async (records, context) => {
            return records.filter(r => r.sku && String(r.sku).length > 0);
        },
    },
})

// Then in pipeline:
const pipeline = createPipeline()
    .name('Product Sync')
    // ... steps ...
    .hooks({
        AFTER_EXTRACT: [{ type: 'SCRIPT', scriptName: 'validate-sku' }],
    })
    .build();

24 hook stages are available (18 for step types and 6 global): BEFORE/AFTER for each step type (EXTRACT, TRANSFORM, VALIDATE, ENRICH, ROUTE, LOAD, EXPORT, FEED, SINK), plus PIPELINE_STARTED/COMPLETED/FAILED, ON_ERROR/ON_RETRY/ON_DEAD_LETTER.

The 18 data stages support record modification via interceptor and script hooks. The six lifecycle/error stages are observe-only and accept WEBHOOK, EMIT, LOG, or TRIGGER_PIPELINE actions.

Type Safety

The DSL is fully typed. TypeScript will catch errors like:

// TypeScript error: Property 'invalidOption' does not exist
.extract('fetch', {
    adapterCode: 'httpApi',
    invalidOption: true,  // Error!
})

Next Steps