npm package: @onlineapps/connector-cookbook
Description: Parser and validator for workflow cookbook JSON format - enables microservice orchestration and workflow definition
Author: OnlineApps Team
Latest version: 1.1.0
Deprecated: This package has been deprecated. ⚠️ This package has been renamed to @onlineapps/connector-registry-client. Please install @onlineapps/connector-registry-client instead. See: https://www.npmjs.com/package/@onlineapps/conn-orch-registry

# @onlineapps/connector-cookbook

> Parser and validator for workflow cookbook JSON format - enables microservice orchestration and workflow definition

## 🚀 Features

* **JSON Schema validation** with strict type checking
* **Recursive step validation** for nested workflows  
* **Support for multiple step types**: task, foreach, fork_join, switch, sub_workflow, wait, dispatch
* **Unique ID validation** across all nested steps
* **Comprehensive error messages** for debugging
* **Parse from file or object**

## 📦 Installation

```bash
npm install @onlineapps/connector-cookbook
# or
yarn add @onlineapps/connector-cookbook
```

## 🔧 Quick Start

```javascript
const { 
  parseCookbookFromFile, 
  parseCookbookFromObject 
} = require('@onlineapps/connector-cookbook');

// Parse from file
const cookbook = parseCookbookFromFile('./workflow.json');

// Parse from object
const cookbook = parseCookbookFromObject({
  version: "1.0.0",
  steps: [
    {
      id: "step1",
      type: "task",
      service: "invoice_service",
      input: { "customer": "api_input.customer" },
      output: { "invoice_id": "this.invoice_id" }
    }
  ]
});
```

## 📖 Cookbook Structure

### Basic Example
```json
{
  "version": "1.0.0",
  "api_input": {
    "customer": "ACME Corp",
    "amount": 1000
  },
  "steps": [
    {
      "id": "invoice_step",
      "type": "task",
      "service": "invoice_service",
      "input": {
        "customer": "api_input.customer",
        "amount": "api_input.amount"
      },
      "output": {
        "invoice_id": "this.invoice_id"
      },
      "retry": {
        "maxAttempts": 3,
        "delayMs": 2000
      }
    }
  ]
}
```

## 📚 Step Types

### Task Step
Execute a service task with input/output mapping:
```json
{
  "id": "task1",
  "type": "task",
  "service": "my_service",
  "input": { "key": "value" },
  "output": { "result": "this.result" },
  "retry": { "maxAttempts": 3, "delayMs": 1000 },
  "timeoutMs": 5000
}
```

### Foreach Step
Iterate over an array:
```json
{
  "id": "foreach1",
  "type": "foreach",
  "iterator": "api_input.items",
  "body": [
    {
      "id": "process_item",
      "type": "task",
      "service": "item_processor",
      "input": { "item": "foreach.item" },
      "output": { "processed": "this.result" }
    }
  ]
}
```

### Fork-Join Step
Execute parallel branches:
```json
{
  "id": "parallel1",
  "type": "fork_join",
  "branches": [
    { "id": "branch1", "type": "task", ... },
    { "id": "branch2", "type": "task", ... }
  ],
  "join": {
    "strategy": "merge",
    "output": { "combined": "branches.results" }
  }
}
```

### Switch Step
Conditional branching:
```json
{
  "id": "switch1",
  "type": "switch",
  "expression": "api_input.priority",
  "cases": {
    "high": { "id": "high_priority", "type": "task", ... },
    "low": { "id": "low_priority", "type": "task", ... }
  },
  "default": { "id": "default_case", "type": "task", ... }
}
```

### Wait Step
Delay execution:
```json
{
  "id": "wait1",
  "type": "wait",
  "durationMs": 5000
}
```

### Dispatch Step
Webhook dispatch:
```json
{
  "id": "webhook1",
  "type": "dispatch",
  "method": "webhook",
  "target": "https://api.example.com/webhook",
  "input": { "data": "value" },
  "retry": { "maxAttempts": 2, "delayMs": 1000 }
}
```

## 🔍 Validation Rules

- All steps must have unique `id` values
- Required fields vary by step type
- `retry.maxAttempts` must be ≥ 1
- `retry.delayMs` must be ≥ 0
- `timeoutMs` must be ≥ 1
- String maps must have at least one non-empty value
- No additional properties allowed (strict mode)

## 📝 License

MIT