Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
98490f0
feat: Enhance automation rule value handling to support multiple data…
kriss145 Dec 17, 2025
4f3c076
feat: Add product attributes and event metadata for product categorie…
kriss145 Dec 17, 2025
1eaad83
feat: Refactor automation rules form to improve value input handling
kriss145 Dec 17, 2025
5303a0c
fix: Correct import order in automation form schema file
kriss145 Dec 17, 2025
98c886f
- Added a new utility function `getFieldsFromAttributes` to field ext…
kriss145 Dec 17, 2025
e7ac64d
- Add stock location attributes to inventory level
kriss145 Dec 17, 2025
68e9d49
Merge pull request #8 from codee-sh/feat--extendattributes
kriss145 Dec 17, 2025
9f823eb
Update package.json to include Prettier as a development dependency
kriss145 Dec 17, 2025
8799a52
- update changeset
kriss145 Dec 17, 2025
67c97c0
Merge pull request #9 from codee-sh/feat--clean
kriss145 Dec 17, 2025
e5c0dc1
refactor: Update value handling in automation rules and triggers
kriss145 Dec 18, 2025
76981f8
Merge pull request #10 from codee-sh/fix-types
kriss145 Dec 18, 2025
54a4b20
chore: Add repository information to package.json and update release.…
kriss145 Dec 18, 2025
2fa7f51
Merge pull request #11 from codee-sh/improvement/update-githubs
kriss145 Dec 18, 2025
b3306a3
docs: Enhance README and documentation for automation features and ru…
kriss145 Dec 18, 2025
91cde9e
Merge pull request #12 from codee-sh/improvement/update-githubs
kriss145 Dec 18, 2025
9a31b8e
chore: add changeset for merged PRs
kriss145 Dec 18, 2025
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/major-mugs-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codee-sh/medusa-plugin-automations": patch
---

Add array operators, relation support, and documentation updates
5 changes: 5 additions & 0 deletions .changeset/open-plants-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@codee-sh/medusa-plugin-automations": patch
---

Clean files by prettier
14 changes: 1 addition & 13 deletions .github/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@ changelog:
- title: Features
labels:
- "type: feature"
- "type: enhancement"
- enhancement
- feature
- title: Bug Fixes
- title: Bugs
labels:
- "type: bug"
- "type: bugfix"
- bug
- fix
- bugfix
- title: Improvements
labels:
- "type: improvement"
- "type: refactor"
- improvement
- refactor
- title: Documentation
labels:
- "type: docs"
- "type: documentation"
- documentation
- docs
- title: Dependencies
labels:
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ A comprehensive automation plugin for Medusa v2 that provides a flexible rule-ba

## Features

- **Automation Triggers**: Create automations triggered by events, schedules, or manual actions
- **Automation Management**: Create, edit, and delete automation triggers with automatic cleanup of related data
- **Rule-Based Conditions**: Define complex conditions using rule attributes (e.g., inventory levels, order status)
- **Multiple Action Types**: Execute various actions including email notifications, Slack messages, SMS, push notifications, and custom actions
- **Event Subscribers**: Built-in subscribers for common Medusa events (inventory updates, order events, payment events)
- **Admin Panel**: Manage automations directly from Medusa Admin
- **Flexible Rules**: Support for multiple rule types and operators (equals, greater than, less than, contains, etc.)
- **Slack Notifications**: Rich Slack notifications with Block Kit support including headers, action buttons, and dividers
- **Extensible Actions**: Add custom action handlers to extend automation capabilities
- **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))
- **Admin Panel**: Manage automations directly from Medusa Admin ([see details](#admin-panel))
- **Extensible**: Add custom action handlers and extend automation capabilities
- **Type-Safe**: Full TypeScript support with exported types and workflows

## Compatibility
Expand Down Expand Up @@ -50,6 +48,8 @@ The plugin includes database migrations for automation models. Run migrations to
medusa migrations run
```

See [Database Migrations](./docs/configuration.md#database-migrations) for more details about the created tables.

### 3. Access Admin Panel

Navigate to **Notifications > Automations** in your Medusa Admin dashboard, or directly access:
Expand All @@ -63,17 +63,20 @@ Navigate to **Notifications > Automations** in your Medusa Admin dashboard, or d
### Automation Triggers

Automations are triggered by:
- **Events**: Medusa events (e.g., `inventory.inventory-level.updated`, `order.placed`)
- **Events**: Medusa events (e.g., `inventory.inventory-level.updated`, `product.updated`)
- **Schedule**: Time-based triggers with configurable intervals (In progress)
- **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.

### Rules and Conditions

Each automation can have multiple rules that define when actions should be executed:
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.

- **Rule Attributes**: Available attributes for conditions
- **Operators**: Comparison operators (equals, greater than, less than, contains, in, etc.)
- **Rule Values**: Values to compare against
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
- [Rule Values](./docs/configuration.md#rule-values) - Supported data types and usage

### Actions

Expand All @@ -83,7 +86,7 @@ When automation rules pass, actions are executed. Supported action types include
- **Slack**: Send Slack messages with Block Kit formatting
- **Custom**: Extend with custom action handlers

See [Configuration Documentation](./docs/configuration.md) for details on built-in subscribers, available actions, and extending functionality.
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.

## Admin Panel

Expand Down
77 changes: 57 additions & 20 deletions docs/admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,25 @@ Automations can be triggered by:

Each automation can have multiple rules that define conditions:

- **Rule Attributes**: Select from available attributes (e.g., `inventory_level.available_quantity`)
- **Operators**: Choose comparison operators (equals, greater than, less than, contains, in, etc.)
- **Values**: Set values to compare against
- **Rule Attributes**: Select from available attributes including:
- Primitive fields: `product.title`, `inventory_level.available_quantity`
- Relations: `product.tags.id`, `product.categories.name` (arrays)
- Nested objects: `inventory_level.inventory_item.*`
- **Operators**: Choose comparison operators:
- **Basic**: `equals`, `not equals`, `greater than`, `less than`, `greater than or equal`, `less than or equal`
- **Array operations**: `in`, `not in`, `contains`, `not contains`
- **Null checks**: `empty`, `not empty`
- **Values**: Set values to compare against:
- **Single values**: Enter a single string or number (e.g., `10`, `"Electronics"`)
- **Array values**: Use the chip input to add multiple values (e.g., tag IDs, category names)
- **No value**: For `empty` and `not empty` operators, no value input is required

#### Actions

When all rules pass, actions are executed:

- **Channels**: Configure delivery channels (email, slack, admin, etc.)
- **Metadata**: Add custom metadata for actions
- **Channels**: Configure delivery channels (email, slack etc.)
- **Metadata**: Add custom config for actions

## Using the Admin Panel

Expand All @@ -60,13 +69,19 @@ When all rules pass, actions are executed:
- If schedule: Set interval in minutes
- Set a name and description
4. **Add Rules**:
- Select rule attributes from available options
- Choose operators
- Set comparison values
- Add multiple rules as needed
- 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)
5. **Configure Actions**:
- Set delivery channels
- Add metadata if needed
- Add config if needed
6. **Save**: Save the automation configuration

### Editing an Automation
Expand All @@ -91,21 +106,37 @@ Create an automation that sends a notification when inventory levels drop below
- **Rule**: `inventory_level.available_quantity` is less than `10`
- **Action**: Send email notification

### High Stock Alert
### Product Tag Automation

Create an automation for when inventory exceeds a certain level:
Create an automation that triggers when a product has specific tags:

- **Trigger**: Event `product.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`
- **Rule**: `product.categories.name` contains `"Electronics"` (or use `in` operator with multiple category names)
- **Action**: Send email notification

### Empty Inventory Check

Create an automation that triggers when inventory is empty:

- **Trigger**: Event `inventory.inventory-level.updated`
- **Rule**: `inventory_level.stocked_quantity` is greater than `1000`
- **Action**: Send admin notification
- **Rule**: `inventory_level.available_quantity` is `empty`
- **Action**: Send Slack notification

### Scheduled Inventory Report
### High Stock Alert

Create a scheduled automation that runs periodically:
Create an automation for when inventory exceeds a certain level:

- **Trigger**: Schedule with interval of `1440` minutes (daily)
- **Rules**: Configure conditions for what to include in the report
- **Action**: Generate and send inventory report
- **Trigger**: Event `inventory.inventory-level.updated`
- **Rule**: `inventory_level.stocked_quantity` is greater than `1000`
- **Action**: Send Slack notification

## Best Practices

Expand All @@ -114,4 +145,10 @@ Create a scheduled automation that runs periodically:
3. **Monitor Performance**: Keep an eye on automation execution and performance
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
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
Loading