Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/moody-glasses-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codee-sh/medusa-plugin-automations": patch
---

Add changeset
34 changes: 22 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# Medusa plugin automations

A comprehensive automation plugin for Medusa v2 that provides a flexible rule-based automation system with triggers, conditions, and actions. Create automated workflows that can send notifications (email, Slack), execute custom actions, or trigger other processes based on events, schedules, or manual triggers with customizable rules.
Automation plugin for Medusa v2 with rule-based
triggers and actions for notifications and workflows.

## Features

- **Automation Triggers**: Create automations triggered by events, schedules, or manual actions ([see details](#automation-triggers))
- **Rule-Based Conditions**: Define complex conditions with support for arrays, relations, and multiple data types ([see details](#rules-and-conditions))
- **Rich Attribute Support**: Pre-configured attributes for Products, Variants, Tags, Categories, and Inventory ([see available attributes](./docs/configuration.md#available-attributes-reference))
- **Multiple Action Types**: Execute various actions including email notifications, Slack messages, SMS, push notifications, and custom actions ([see details](#actions))
- **Event Subscribers**: Built-in subscribers for common Medusa events ([see available events](./docs/configuration.md#available-subscribers))
- **Automation Triggers**: Events, schedules, or manual actions ([see details](#automation-triggers))
- **Rule-Based Conditions**: Arrays, relations, and multiple data types ([see details](#rules-and-conditions))
- **Rich Attribute Support**: Products, Variants, Tags, Categories, Inventory ([see available attributes](./docs/attributes.md))
- **Multiple Action Types**: Email, Slack, and custom actions ([see details](#actions))
- **Event Subscribers**: Built-in subscribers for common Medusa events ([see available events](./docs/available-subscribers.md))
- **Admin Panel**: Manage automations directly from Medusa Admin ([see details](#admin-panel))
- **Extensible**: Add custom action handlers and extend automation capabilities
- **Extensible**: Add custom action handlers
- **Type-Safe**: Full TypeScript support with exported types and workflows

## Compatibility
Expand Down Expand Up @@ -64,19 +65,20 @@ Navigate to **Notifications > Automations** in your Medusa Admin dashboard, or d

Automations are triggered by:
- **Events**: Medusa events (e.g., `inventory.inventory-level.updated`, `product.updated`)
- **Schedule**: Time-based triggers with configurable intervals (In progress)
- **Schedule**: Time-based triggers with configurable intervals
- **Manual**: Triggered manually from the admin panel

See [Available Subscribers](./docs/configuration.md#available-subscribers) in the configuration documentation for a complete list of supported events.
See [Available Subscribers](./docs/available-subscribers.md) for a complete list of supported events.

### Rules and Conditions

Each automation can have multiple rules that define when actions should be executed. Rules support primitive fields, relations (arrays), nested objects, and various operators for complex conditions.

For detailed information, see:
- [Available Attributes Reference](./docs/configuration.md#available-attributes-reference) - Complete list of attributes for each event type
- [Rule Operators](./docs/configuration.md#rule-operators) - All supported operators with examples
- [Available Attributes Reference](./docs/attributes.md) - Complete list of attributes for each event type
- [Rule Operators](./docs/rule-operators.md) - All supported operators with examples
- [Rule Values](./docs/configuration.md#rule-values) - Supported data types and usage
- [Custom Action Handlers](./docs/custom-action-handlers.md) - Extend actions with custom handlers

### Actions

Expand All @@ -88,6 +90,9 @@ When automation rules pass, actions are executed. Supported action types include

See [Actions](./docs/configuration.md#actions) and [Slack Notification Provider](./docs/configuration.md#slack-notification-provider) in the configuration documentation for details on configuring and extending actions.

Email and Slack templates are rendered by
`@codee-sh/medusa-plugin-notification-emails`.

## Admin Panel

Access the automations management interface in Medusa Admin at `/app/notifications/automations`. See [Admin Panel Documentation](./docs/admin.md) for details.
Expand All @@ -114,7 +119,7 @@ The plugin exports the following:

## Related Plugins

For email templates and rendering functionality, see [@codee-sh/medusa-plugin-automations-emails](https://github.com/codee-sh/medusa-plugin-notification-emails).
For email and Slack template rendering, see [@codee-sh/medusa-plugin-notification-emails](https://github.com/codee-sh/medusa-plugin-notification-emails).

## License

Expand All @@ -123,3 +128,8 @@ MIT
## Author

Codee Team - [https://codee.dev](https://codee.dev)

## See Also

- [Configuration](./docs/configuration.md)
- [Admin Panel](./docs/admin.md)
45 changes: 19 additions & 26 deletions docs/admin.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Admin Panel Documentation

The plugin provides an admin interface for managing notification automations.
User guide for managing automations in the admin panel.

## Accessing the Admin Panel

Expand Down Expand Up @@ -30,7 +30,7 @@ The admin panel allows you to:
Automations can be triggered by:

- **Events**: Medusa events (e.g., `inventory.inventory-level.updated`, `order.placed`)
- **Schedule**: Time-based triggers with configurable intervals (in minutes)
- **Schedule**: Time-based triggers with configurable intervals in seconds
- **Manual**: Triggered manually from the admin panel

#### Rules
Expand All @@ -57,28 +57,20 @@ When all rules pass, actions are executed:
- **Channels**: Configure delivery channels (email, slack etc.)
- **Metadata**: Add custom config for actions

#### Template Selection

Email and Slack actions use a `Template Name` field.
The template list loads dynamically and is grouped
as `System`, `Database`, and `External`.

## Using the Admin Panel

### Creating an Automation

1. **Navigate to Automations**: Go to `/app/notifications/automations`
2. **Click Create**: Start creating a new automation
3. **Configure Trigger**:
- Set trigger type (event, schedule, or manual)
- If event: Select the event name
- If schedule: Set interval in minutes
- Set a name and description
4. **Add Rules**:
- Select rule attributes from available options (including relations and nested objects)
- Choose operators based on your needs:
- Use `in` or `not in` for checking if a value exists in an array
- Use `contains` or `not contains` for partial matches in arrays
- Use `empty` or `not empty` to check for null/empty values
- Set comparison values:
- For array operators (`in`, `not in`, `contains`, `not contains`): Use the chip input to add multiple values
- For basic operators: Enter a single value
- For `empty`/`not empty`: No value input needed
- Add multiple rules as needed (all rules must pass for the automation to trigger)
3. **Configure Trigger**: Set trigger type (event, schedule, or manual). If event, select the event name. If schedule, set interval in seconds. Set a name and description.
4. **Add Rules**: Select rule attributes, choose operators, and set values. For array operators, use the chip input. For `empty`/`not empty`, no value input is required. Add multiple rules as needed (all rules must pass for the automation to trigger).
5. **Configure Actions**:
- Set delivery channels
- Add config if needed
Expand Down Expand Up @@ -110,15 +102,15 @@ Create an automation that sends a notification when inventory levels drop below

Create an automation that triggers when a product has specific tags:

- **Trigger**: Event `product.product.updated`
- **Trigger**: Event `product.updated`
- **Rule**: `product.tags.id` is `in` `[tag-premium, tag-featured]` (use chip input for multiple tag IDs)
- **Action**: Send Slack notification

### Category-Based Automation

Create an automation for products in specific categories:

- **Trigger**: Event `product.product.created`
- **Trigger**: Event `product.updated`
- **Rule**: `product.categories.name` contains `"Electronics"` (or use `in` operator with multiple category names)
- **Action**: Send email notification

Expand Down Expand Up @@ -146,9 +138,10 @@ Create an automation for when inventory exceeds a certain level:
4. **Use Appropriate Triggers**: Choose the right trigger type for your use case
5. **Combine Rules**: Use multiple rules to create complex conditions
6. **Document Automations**: Add descriptions to explain automation purpose
7. **Choose the Right Operator**:
- Use `in`/`not in` for exact matches in arrays (e.g., checking if product has specific tags)
- Use `contains`/`not contains` for partial matches (e.g., checking if category name contains a substring)
- Use `empty`/`not empty` for null checks
8. **Use Array Values Correctly**: When using array operators (`in`, `not in`, `contains`, `not contains`), use the chip input to add multiple values
9. **Leverage Relations**: Use relation-based attributes (e.g., `product.tags.id`, `product.categories.name`) to create powerful automations based on related data
7. **Choose the Right Operator**: Use `in`/`not in` for exact array matches, `contains`/`not contains` for partial matches, and `empty`/`not empty` for null checks
8. **Use Array Values Correctly**: For array operators, use the chip input to add multiple values
9. **Leverage Relations**: Use relation-based attributes (e.g., `product.tags.id`, `product.categories.name`) to create powerful automations

## See Also

- [Configuration](./configuration.md)
134 changes: 134 additions & 0 deletions docs/attributes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Available Attributes Reference

Complete list of rule attributes available per event type.

## Inventory Level Attributes

Available for events: `inventory.inventory-level.created`, `inventory.inventory-level.updated`, `inventory.inventory-level.deleted`

**Primitive Fields:**
- `inventory_level.available_quantity` - Available quantity
- `inventory_level.reserved_quantity` - Reserved quantity
- `inventory_level.stocked_quantity` - Stocked quantity
- `inventory_level.location_id` - Location ID
- `inventory_level.inventory_item_id` - Inventory item ID
- `inventory_level.created_at` - Creation timestamp
- `inventory_level.updated_at` - Update timestamp

**Relation-Based Attributes:**
- `inventory_level.inventory_item.*` - All inventory item fields (object)
- `inventory_level.stock_locations.id` - Stock location IDs (array)
- `inventory_level.stock_locations.name` - Stock location names (array)
- `inventory_level.stock_locations.address` - Stock location addresses (array)
- `inventory_level.stock_locations.metadata` - Stock location metadata (array)

## Inventory Item Attributes

Available for events: `inventory.inventory-item.created`, `inventory.inventory-item.updated`, `inventory.inventory-item.deleted`

**Primitive Fields:**
- `inventory_item.sku` - SKU code
- `inventory_item.origin_country` - Origin country
- `inventory_item.hs_code` - HS code
- `inventory_item.mid_code` - MID code
- `inventory_item.material` - Material
- `inventory_item.weight` - Weight
- `inventory_item.length` - Length
- `inventory_item.height` - Height
- `inventory_item.width` - Width
- `inventory_item.metadata` - Metadata (object)
- `inventory_item.created_at` - Creation timestamp
- `inventory_item.updated_at` - Update timestamp

## Product Attributes

Available for events: `product.updated`

**Primitive Fields:**
- `product.id` - Product ID
- `product.title` - Product title
- `product.description` - Product description
- `product.subtitle` - Product subtitle
- `product.handle` - Product handle
- `product.is_giftcard` - Is gift card
- `product.status` - Product status
- `product.thumbnail` - Thumbnail URL
- `product.hs_code` - HS code
- `product.origin_country` - Origin country
- `product.mid_code` - MID code
- `product.material` - Material
- `product.weight` - Weight
- `product.length` - Length
- `product.height` - Height
- `product.width` - Width
- `product.metadata` - Metadata (object)
- `product.created_at` - Creation timestamp
- `product.updated_at` - Update timestamp
- `product.deleted_at` - Deletion timestamp

**Relation-Based Attributes (Arrays):**
- `product.tags.id` - Product tag IDs (array)
- `product.tags.value` - Product tag values (array)
- `product.categories.id` - Category IDs (array)
- `product.categories.name` - Category names (array)
- `product.categories.handle` - Category handles (array)
- `product.variants.*` - Product variants (array of objects)
- `product.type.*` - Product type (object)
- `product.collection.*` - Product collection (object)

## Product Variant Attributes

Available for events: `product-variant.updated`

**Primitive Fields:**
- `product_variant.id` - Variant ID
- `product_variant.title` - Variant title
- `product_variant.sku` - SKU code
- `product_variant.barcode` - Barcode
- `product_variant.ean` - EAN code
- `product_variant.upc` - UPC code
- `product_variant.allow_backorder` - Allow backorder
- `product_variant.manage_inventory` - Manage inventory
- `product_variant.hs_code` - HS code
- `product_variant.origin_country` - Origin country
- `product_variant.mid_code` - MID code
- `product_variant.material` - Material
- `product_variant.weight` - Weight
- `product_variant.length` - Length
- `product_variant.height` - Height
- `product_variant.width` - Width
- `product_variant.metadata` - Metadata (object)
- `product_variant.variant_rank` - Variant rank
- `product_variant.product_id` - Product ID
- `product_variant.created_at` - Creation timestamp
- `product_variant.updated_at` - Update timestamp

## Product Tag Attributes

Available for events: `product-tag.updated`

**Primitive Fields:**
- `product_tag.id` - Tag ID
- `product_tag.value` - Tag value
- `product_tag.created_at` - Creation timestamp
- `product_tag.updated_at` - Update timestamp

## Product Category Attributes

Available for events: `product-category.updated`

**Primitive Fields:**
- `product_category.id` - Category ID
- `product_category.name` - Category name
- `product_category.description` - Category description
- `product_category.handle` - Category handle
- `product_category.is_active` - Is active
- `product_category.is_internal` - Is internal
- `product_category.rank` - Category rank
- `product_category.parent_category_id` - Parent category ID
- `product_category.created_at` - Creation timestamp
- `product_category.updated_at` - Update timestamp

## See Also

- [Configuration](./configuration.md)
62 changes: 62 additions & 0 deletions docs/available-subscribers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Available Subscribers

List of built-in subscribers and the events they handle.

## `inventory.inventory-level.updated`

Evaluates automations when inventory levels are updated.

- **Event**: `inventory.inventory-level.updated`
- **Context**: Provides `inventory_level` data with related `inventory_item` and `stock_locations`
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## `inventory.inventory-item.updated`

Evaluates automations when inventory items are updated.

- **Event**: `inventory.inventory-item.updated`
- **Context**: Provides `inventory_item` data
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## `inventory.reservation-item.updated`

Evaluates automations when inventory reservations are updated.

- **Event**: `inventory.reservation-item.updated`
- **Context**: Provides reservation data

## `product.updated`

Evaluates automations when products are updated.

- **Event**: `product.updated`
- **Context**: Provides `product` data with relations (tags, categories, variants, type, collection)
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## `product-variant.updated`

Evaluates automations when product variants are updated.

- **Event**: `product-variant.updated`
- **Context**: Provides `product_variant` data
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## `product-tag.updated`

Evaluates automations when product tags are updated.

- **Event**: `product-tag.updated`
- **Context**: Provides `product_tag` data
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## `product-category.updated`

Evaluates automations when product categories are updated.

- **Event**: `product-category.updated`
- **Context**: Provides `product_category` data
- **Available Attributes**: See [Available Attributes Reference](./attributes.md)

## See Also

- [Configuration](./configuration.md)
Loading