@codee-sh/medusa-plugin-automations 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.medusa/server/src/admin/index.js +9931 -0
- package/.medusa/server/src/admin/index.mjs +9929 -0
- package/.medusa/server/src/admin/lib/sdk.js +15 -0
- package/.medusa/server/src/api/admin/mpn/automations/actions/route.js +78 -0
- package/.medusa/server/src/api/admin/mpn/automations/available-actions/route.js +12 -0
- package/.medusa/server/src/api/admin/mpn/automations/available-events/route.js +14 -0
- package/.medusa/server/src/api/admin/mpn/automations/available-triggers/route.js +12 -0
- package/.medusa/server/src/api/admin/mpn/automations/route.js +71 -0
- package/.medusa/server/src/api/admin/mpn/automations/rules/route.js +85 -0
- package/.medusa/server/src/api/middlewares.js +125 -0
- package/.medusa/server/src/emails/example-template.js +68 -0
- package/.medusa/server/src/hooks/api/automations/automations.js +74 -0
- package/.medusa/server/src/hooks/api/automations/index.js +18 -0
- package/.medusa/server/src/hooks/api/automations-actions/automations-actions.js +51 -0
- package/.medusa/server/src/hooks/api/automations-actions/index.js +18 -0
- package/.medusa/server/src/hooks/api/automations-rules/automations-rules.js +51 -0
- package/.medusa/server/src/hooks/api/automations-rules/index.js +18 -0
- package/.medusa/server/src/hooks/api/available-actions/actions.js +34 -0
- package/.medusa/server/src/hooks/api/available-actions/index.js +18 -0
- package/.medusa/server/src/hooks/api/available-events/events.js +34 -0
- package/.medusa/server/src/hooks/api/available-events/index.js +18 -0
- package/.medusa/server/src/hooks/api/available-triggers/index.js +18 -0
- package/.medusa/server/src/hooks/api/available-triggers/triggers.js +34 -0
- package/.medusa/server/src/modules/mpn-automation/index.js +10 -0
- package/.medusa/server/src/modules/mpn-automation/interfaces.js +3 -0
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127115228.js +37 -0
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127193345.js +20 -0
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251127195615.js +19 -0
- package/.medusa/server/src/modules/mpn-automation/migrations/Migration20251130144047.js +16 -0
- package/.medusa/server/src/modules/mpn-automation/models/index.js +14 -0
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_rule.js +27 -0
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_rule_value.js +15 -0
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_state.js +17 -0
- package/.medusa/server/src/modules/mpn-automation/models/mpn_automation_trigger.js +52 -0
- package/.medusa/server/src/modules/mpn-automation/models/npm_automation_action.js +23 -0
- package/.medusa/server/src/modules/mpn-automation/services/index.js +9 -0
- package/.medusa/server/src/modules/mpn-automation/services/service.js +38 -0
- package/.medusa/server/src/modules/mpn-automation/types.js +199 -0
- package/.medusa/server/src/subscribers/inventory-item-updated.js +22 -0
- package/.medusa/server/src/subscribers/inventory-level-updated.js +43 -0
- package/.medusa/server/src/subscribers/inventory-reservation-item-updated.js +22 -0
- package/.medusa/server/src/subscribers/mpn.automation.action.email.executed.js +45 -0
- package/.medusa/server/src/subscribers/order-completed.js +110 -0
- package/.medusa/server/src/subscribers/order-placed.js +108 -0
- package/.medusa/server/src/subscribers/payment-captured.js +96 -0
- package/.medusa/server/src/utils/index.js +20 -0
- package/.medusa/server/src/utils/plugins.js +20 -0
- package/.medusa/server/src/utils/types/index.js +19 -0
- package/.medusa/server/src/utils/validate-rules.js +85 -0
- package/.medusa/server/src/workflows/index.js +20 -0
- package/.medusa/server/src/workflows/inventory/get-inventory-level-by-id.js +23 -0
- package/.medusa/server/src/workflows/inventory/index.js +18 -0
- package/.medusa/server/src/workflows/inventory/steps/get-inventory-level-by-id.js +25 -0
- package/.medusa/server/src/workflows/inventory/steps/index.js +18 -0
- package/.medusa/server/src/workflows/mpn-automation/create-automation.js +14 -0
- package/.medusa/server/src/workflows/mpn-automation/edit-automation-actions.js +15 -0
- package/.medusa/server/src/workflows/mpn-automation/edit-automation-rules.js +15 -0
- package/.medusa/server/src/workflows/mpn-automation/edit-automation.js +14 -0
- package/.medusa/server/src/workflows/mpn-automation/index.js +24 -0
- package/.medusa/server/src/workflows/mpn-automation/run-automation.js +76 -0
- package/.medusa/server/src/workflows/mpn-automation/send-email-action.js +73 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/create-automation.js +19 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation-actions.js +51 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation-rules.js +87 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/edit-automation.js +20 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/index.js +24 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/retrieve-automation-triggers-by-event.js +62 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/run-automation-actions.js +92 -0
- package/.medusa/server/src/workflows/mpn-automation/steps/validate-automation-triggers.js +29 -0
- package/.medusa/server/src/workflows/mpn-automation/validate-automation-triggers-by-event.js +38 -0
- package/.medusa/server/src/workflows/notifications/index.js +18 -0
- package/.medusa/server/src/workflows/notifications/send-email.js +51 -0
- package/.medusa/server/src/workflows/notifications/steps/index.js +18 -0
- package/.medusa/server/src/workflows/notifications/steps/send-email.js +119 -0
- package/.medusa/server/src/workflows/steps/log-step.js +16 -0
- package/LICENSE +21 -0
- package/README.md +104 -0
- package/package.json +72 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendEmailStep = exports.sendEmailStepId = void 0;
|
|
4
|
+
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
|
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
|
+
const emails_1 = require("@codee-sh/medusa-plugin-notification-emails/templates/emails");
|
|
7
|
+
const plugins_1 = require("@codee-sh/medusa-plugin-automations/utils/plugins");
|
|
8
|
+
exports.sendEmailStepId = "send-email";
|
|
9
|
+
/**
|
|
10
|
+
* Universal step that sends an email notification.
|
|
11
|
+
*
|
|
12
|
+
* This step can be used independently or as part of automation workflows.
|
|
13
|
+
*
|
|
14
|
+
* Configuration:
|
|
15
|
+
* - templateName: Required - Name of the email template to use
|
|
16
|
+
* - to: Required - Recipient email address
|
|
17
|
+
* - locale: Optional - Locale for translations (default: "pl")
|
|
18
|
+
* - customTemplate: Optional - Path to custom template function
|
|
19
|
+
* - subject: Optional - Custom subject (otherwise uses template default)
|
|
20
|
+
* - template: Optional - Template identifier for notification (defaults to templateName)
|
|
21
|
+
* - resourceId: Optional - Resource ID for notification tracking
|
|
22
|
+
* - resourceType: Optional - Resource type for notification tracking
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* // Standalone usage
|
|
27
|
+
* const result = await sendEmailStep({
|
|
28
|
+
* settings: {
|
|
29
|
+
* templateName: "inventory-level",
|
|
30
|
+
* to: "admin@example.com",
|
|
31
|
+
* locale: "pl"
|
|
32
|
+
* },
|
|
33
|
+
* templateData: {
|
|
34
|
+
* inventory_level: { ... }
|
|
35
|
+
* }
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
exports.sendEmailStep = (0, workflows_sdk_1.createStep)(exports.sendEmailStepId, async (input, { container }) => {
|
|
40
|
+
const { settings, templateData, eventName } = input;
|
|
41
|
+
// Validate required config
|
|
42
|
+
if (!settings.templateName) {
|
|
43
|
+
return new workflows_sdk_1.StepResponse({
|
|
44
|
+
success: false,
|
|
45
|
+
error: "templateName is required in config",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (!settings.to) {
|
|
49
|
+
return new workflows_sdk_1.StepResponse({
|
|
50
|
+
success: false,
|
|
51
|
+
error: "to (recipient email) is required in config",
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const notificationModuleService = container.resolve(utils_1.Modules.NOTIFICATION);
|
|
56
|
+
const pluginOptions = (0, plugins_1.getPluginOptions)(container, "@codee-sh/medusa-plugin-notification-emails");
|
|
57
|
+
const templateName = settings.templateName;
|
|
58
|
+
const to = settings.to;
|
|
59
|
+
const locale = settings.locale || "pl";
|
|
60
|
+
const customSubject = settings.subject;
|
|
61
|
+
const resourceId = settings.resourceId || 'unknown';
|
|
62
|
+
const resourceType = settings.resourceType || "email.notification";
|
|
63
|
+
const channel = settings.channel || "email";
|
|
64
|
+
const triggerType = settings.triggerType || "system";
|
|
65
|
+
// Prepare render options
|
|
66
|
+
const renderOptions = {
|
|
67
|
+
locale,
|
|
68
|
+
theme: pluginOptions?.theme,
|
|
69
|
+
customTranslations: pluginOptions?.customTranslations?.[templateName],
|
|
70
|
+
};
|
|
71
|
+
// Load custom template function if specified
|
|
72
|
+
let customTemplateFunction;
|
|
73
|
+
if (settings.customTemplate) {
|
|
74
|
+
try {
|
|
75
|
+
// Dynamic import of custom template
|
|
76
|
+
// config.customTemplate should be a relative path like "../emails/pos-email-inventory"
|
|
77
|
+
// or absolute path from project root like "src/emails/pos-email-inventory"
|
|
78
|
+
const customTemplateModule = await import(settings.customTemplate);
|
|
79
|
+
customTemplateFunction = customTemplateModule.default || customTemplateModule.createCustomTemplate || customTemplateModule.createTemplate;
|
|
80
|
+
if (!customTemplateFunction) {
|
|
81
|
+
console.warn(`Custom template module from ${settings.customTemplate} does not export a default function or createCustomTemplate/createTemplate`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
console.warn(`Failed to load custom template from ${settings.customTemplate}:`, error);
|
|
86
|
+
// Continue with default template
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Render email template
|
|
90
|
+
const { html, text, subject } = await (0, emails_1.renderTemplate)(templateName, templateData, renderOptions, customTemplateFunction);
|
|
91
|
+
// Send notification
|
|
92
|
+
const notificationResult = await notificationModuleService.createNotifications({
|
|
93
|
+
to: to,
|
|
94
|
+
channel: channel,
|
|
95
|
+
template: settings.template || templateName,
|
|
96
|
+
trigger_type: triggerType,
|
|
97
|
+
resource_id: resourceId,
|
|
98
|
+
resource_type: resourceType,
|
|
99
|
+
data: templateData,
|
|
100
|
+
content: {
|
|
101
|
+
subject: customSubject || subject,
|
|
102
|
+
html: html,
|
|
103
|
+
text: text,
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
return new workflows_sdk_1.StepResponse({
|
|
107
|
+
success: true,
|
|
108
|
+
notificationId: notificationResult?.id,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
console.error(`Failed to send email:`, error);
|
|
113
|
+
return new workflows_sdk_1.StepResponse({
|
|
114
|
+
success: false,
|
|
115
|
+
error: error?.message || "Unknown error occurred",
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2VuZC1lbWFpbC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3NyYy93b3JrZmxvd3Mvbm90aWZpY2F0aW9ucy9zdGVwcy9zZW5kLWVtYWlsLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUNBLHFFQUE0RTtBQUM1RSxxREFBbUQ7QUFDbkQseUZBQTZGO0FBQzdGLCtFQUFvRjtBQTZCdkUsUUFBQSxlQUFlLEdBQUcsWUFBWSxDQUFBO0FBRTNDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQTZCRztBQUNVLFFBQUEsYUFBYSxHQUFHLElBQUEsMEJBQVUsRUFDckMsdUJBQWUsRUFDZixLQUFLLEVBQ0gsS0FBeUIsRUFDekIsRUFBRSxTQUFTLEVBQUUsRUFDK0IsRUFBRTtJQUM5QyxNQUFNLEVBQUUsUUFBUSxFQUFFLFlBQVksRUFBRSxTQUFTLEVBQUUsR0FBRyxLQUFLLENBQUE7SUFFbkQsMkJBQTJCO0lBQzNC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4
|
+
const workflows_sdk_1 = require("@medusajs/framework/workflows-sdk");
|
|
5
|
+
const logStep = (0, workflows_sdk_1.createStep)({
|
|
6
|
+
name: "log-step",
|
|
7
|
+
}, function (input) {
|
|
8
|
+
console.log("log-step", JSON.stringify(input, null, 2));
|
|
9
|
+
return new workflows_sdk_1.StepResponse({
|
|
10
|
+
status: "success",
|
|
11
|
+
message: "Requested",
|
|
12
|
+
input: input,
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
exports.logStep = logStep;
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nLXN0ZXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvd29ya2Zsb3dzL3N0ZXBzL2xvZy1zdGVwLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7OztBQUFBLHFFQUE2RTtBQUU3RSxNQUFNLE9BQU8sR0FBRyxJQUFBLDBCQUFVLEVBQ3hCO0lBQ0UsSUFBSSxFQUFFLFVBQVU7Q0FDakIsRUFDRCxVQUFVLEtBQVU7SUFDbEIsT0FBTyxDQUFDLEdBQUcsQ0FBQyxVQUFVLEVBQUUsSUFBSSxDQUFDLFNBQVMsQ0FBQyxLQUFLLEVBQUUsSUFBSSxFQUFFLENBQUMsQ0FBQyxDQUFDLENBQUM7SUFFeEQsT0FBTyxJQUFJLDRCQUFZLENBQUM7UUFDdEIsTUFBTSxFQUFFLFNBQVM7UUFDakIsT0FBTyxFQUFFLFdBQVc7UUFDcEIsS0FBSyxFQUFFLEtBQUs7S0FDYixDQUFDLENBQUM7QUFDTCxDQUFDLENBQ0YsQ0FBQztBQUVPLDBCQUFPIn0=
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Codee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Medusa plugin automations
|
|
2
|
+
|
|
3
|
+
A comprehensive notification automation plugin for Medusa v2 that provides a flexible rule-based notification system with triggers, conditions, and actions. Create automated notifications based on events, schedules, or manual triggers with customizable rules.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Automation Triggers**: Create notification automations triggered by events, schedules, or manual actions
|
|
8
|
+
- **Rule-Based Conditions**: Define complex conditions using rule attributes (e.g., inventory levels, order status)
|
|
9
|
+
- **Event Subscribers**: Built-in subscribers for common Medusa events (inventory updates, order events, payment events)
|
|
10
|
+
- **Admin Panel**: Manage automations directly from Medusa Admin
|
|
11
|
+
- **Flexible Rules**: Support for multiple rule types and operators (equals, greater than, less than, contains, etc.)
|
|
12
|
+
- **Type-Safe**: Full TypeScript support with exported types and workflows
|
|
13
|
+
- **Extensible**: Add custom rule attributes and extend functionality via plugin options
|
|
14
|
+
|
|
15
|
+
## Compatibility
|
|
16
|
+
|
|
17
|
+
- **Medusa Version**: `>= 2.8.8`
|
|
18
|
+
- **Node Version**: `>= 20`
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @codee-sh/medusa-plugin-automations
|
|
24
|
+
# or
|
|
25
|
+
yarn add @codee-sh/medusa-plugin-automations
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
### 1. Register the Plugin
|
|
31
|
+
|
|
32
|
+
Add to your `medusa-config.ts`:
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
module.exports = defineConfig({
|
|
36
|
+
plugins: [
|
|
37
|
+
"@codee-sh/medusa-plugin-automations"
|
|
38
|
+
]
|
|
39
|
+
})
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 2. Run Migrations
|
|
43
|
+
|
|
44
|
+
The plugin includes database migrations for automation models. Run migrations to set up the required tables:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
medusa migrations run
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 3. Access Admin Panel
|
|
51
|
+
|
|
52
|
+
Navigate to **Notifications > Automations** in your Medusa Admin dashboard, or directly access:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
/app/notifications/automations
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## How It Works
|
|
59
|
+
|
|
60
|
+
### Automation Triggers
|
|
61
|
+
|
|
62
|
+
Automations are triggered by:
|
|
63
|
+
- **Events**: Medusa events (e.g., `inventory.inventory-level.updated`, `order.placed`)
|
|
64
|
+
- **Schedule**: Time-based triggers with configurable intervals
|
|
65
|
+
- **Manual**: Triggered manually from the admin panel
|
|
66
|
+
|
|
67
|
+
### Rules and Conditions
|
|
68
|
+
|
|
69
|
+
Each automation can have multiple rules that define when notifications should be sent:
|
|
70
|
+
|
|
71
|
+
- **Rule Attributes**: Available attributes for conditions (e.g., `inventory_level.available_quantity`, `inventory_item.sku`)
|
|
72
|
+
- **Operators**: Comparison operators (equals, greater than, less than, contains, in, etc.)
|
|
73
|
+
- **Rule Values**: Values to compare against
|
|
74
|
+
|
|
75
|
+
See [Configuration Documentation](./docs/configuration.md) for details on built-in subscribers, available rule attributes, and extending functionality.
|
|
76
|
+
|
|
77
|
+
## Admin Panel
|
|
78
|
+
|
|
79
|
+
Access the automations management interface in Medusa Admin at `/app/notifications/automations`. See [Admin Panel Documentation](./docs/admin.md) for details.
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- [Configuration](./docs/configuration.md) - Plugin configuration options and extending functionality
|
|
84
|
+
- [Admin Panel](./docs/admin.md) - Admin interface usage and automation management
|
|
85
|
+
|
|
86
|
+
## Exports
|
|
87
|
+
|
|
88
|
+
The plugin exports the following:
|
|
89
|
+
|
|
90
|
+
- `@codee-sh/medusa-plugin-notification/workflows` - Workflow functions for automation management
|
|
91
|
+
- `@codee-sh/medusa-plugin-notification/modules/mpn-automation` - Automation module service
|
|
92
|
+
- `@codee-sh/medusa-plugin-notification/utils` - Utility functions
|
|
93
|
+
|
|
94
|
+
## Related Plugins
|
|
95
|
+
|
|
96
|
+
For email templates and rendering functionality, see [@codee-sh/medusa-plugin-notification-emails](https://github.com/codee-sh/medusa-plugin-notification-emails).
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT
|
|
101
|
+
|
|
102
|
+
## Author
|
|
103
|
+
|
|
104
|
+
Codee Team - [https://codee.dev](https://codee.dev)
|
package/package.json
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codee-sh/medusa-plugin-automations",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Medusa plugin for automations.",
|
|
5
|
+
"author": "Codee (https://codee.dev)",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
".medusa/server"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
"./workflows": "./.medusa/server/src/workflows/index.js",
|
|
16
|
+
"./.medusa/server/src/modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
17
|
+
"./modules/*": "./.medusa/server/src/modules/*/index.js",
|
|
18
|
+
"./providers/*": "./.medusa/server/src/providers/*/index.js",
|
|
19
|
+
"./utils": "./.medusa/server/src/utils/index.js",
|
|
20
|
+
"./utils/types": "./.medusa/server/src/types/index.js",
|
|
21
|
+
"./*": "./.medusa/server/src/*.js",
|
|
22
|
+
"./admin": {
|
|
23
|
+
"import": "./.medusa/server/src/admin/index.mjs",
|
|
24
|
+
"require": "./.medusa/server/src/admin/index.js",
|
|
25
|
+
"default": "./.medusa/server/src/admin/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"medusa",
|
|
30
|
+
"plugin",
|
|
31
|
+
"medusa-plugin-automations",
|
|
32
|
+
"medusa-plugin",
|
|
33
|
+
"medusa-v2"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "medusa plugin:build",
|
|
37
|
+
"dev": "medusa plugin:develop",
|
|
38
|
+
"prepublishOnly": "medusa plugin:build",
|
|
39
|
+
"publish-local": "npx medusa plugin:publish",
|
|
40
|
+
"publish-package": "dotenv npm publish --access public"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@medusajs/admin-sdk": "2.8.8",
|
|
44
|
+
"@medusajs/cli": "2.8.8",
|
|
45
|
+
"@medusajs/framework": "2.8.8",
|
|
46
|
+
"@medusajs/icons": "2.8.8",
|
|
47
|
+
"@medusajs/medusa": "2.8.8",
|
|
48
|
+
"@medusajs/test-utils": "2.8.8",
|
|
49
|
+
"@medusajs/ui": "^4.0.9",
|
|
50
|
+
"@mikro-orm/core": "6.4.3",
|
|
51
|
+
"@mikro-orm/knex": "6.4.3",
|
|
52
|
+
"@mikro-orm/migrations": "6.4.3",
|
|
53
|
+
"@mikro-orm/postgresql": "6.4.3",
|
|
54
|
+
"@swc/core": "1.5.7",
|
|
55
|
+
"@types/node": "^20.0.0",
|
|
56
|
+
"@types/react": "^18.3.2",
|
|
57
|
+
"@types/react-dom": "^18.2.25",
|
|
58
|
+
"awilix": "^8.0.1",
|
|
59
|
+
"dotenv": "^17.2.3",
|
|
60
|
+
"prop-types": "^15.8.1",
|
|
61
|
+
"react": "^18.2.0",
|
|
62
|
+
"react-dom": "^18.2.0",
|
|
63
|
+
"ts-node": "^10.9.2",
|
|
64
|
+
"typescript": "^5.6.2",
|
|
65
|
+
"vite": "^5.2.11",
|
|
66
|
+
"yalc": "^1.0.0-pre.53"
|
|
67
|
+
},
|
|
68
|
+
"engines": {
|
|
69
|
+
"node": ">=20"
|
|
70
|
+
},
|
|
71
|
+
"packageManager": "yarn@3.2.3+sha512.f26f951f67de0c6a33ee381e5ff364709c87e70eb5e65c694e4facde3512f1fa80b8679e6ba31ce7d340fbb46f08dd683af9457e240f25a204be7427940d767e"
|
|
72
|
+
}
|