data-primals-engine 1.7.2 → 1.7.3
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/README.md +160 -160
- package/client/package-lock.json +8430 -8430
- package/client/src/APIInfo.jsx +1 -1
- package/client/src/App.jsx +2 -1
- package/client/src/App.scss +1635 -1626
- package/client/src/AssistantChat.jsx +1 -0
- package/client/src/CalendarView.jsx +1 -0
- package/client/src/ContentView.jsx +3 -3
- package/client/src/Dashboard.jsx +5 -2
- package/client/src/DashboardChart.jsx +1 -0
- package/client/src/DashboardFlexViewItem.jsx +1 -0
- package/client/src/DashboardHtmlViewItem.jsx +1 -0
- package/client/src/DashboardView.jsx +2 -0
- package/client/src/DataEditor.jsx +0 -1
- package/client/src/DataImporter.jsx +489 -468
- package/client/src/DataLayout.jsx +6 -3
- package/client/src/DataTable.jsx +4 -3
- package/client/src/Dialog.jsx +92 -90
- package/client/src/Dialog.scss +122 -116
- package/client/src/DisplayFlexNodeRenderer.jsx +1 -0
- package/client/src/FlexBuilderControls.jsx +1 -0
- package/client/src/FlexBuilderPreview.jsx +1 -1
- package/client/src/FlexNode.jsx +1 -1
- package/client/src/HistoryDialog.jsx +3 -2
- package/client/src/KPIWidget.jsx +1 -1
- package/client/src/KanbanView.jsx +1 -0
- package/client/src/ModelCreator.jsx +4 -0
- package/client/src/ModelList.jsx +1 -0
- package/client/src/PackGallery.jsx +5 -4
- package/client/src/RTETrans.jsx +1 -1
- package/client/src/RelationField.jsx +2 -0
- package/client/src/RelationSelectorWidget.jsx +2 -0
- package/client/src/RelationValue.jsx +1 -0
- package/client/src/RestoreDialog.jsx +1 -0
- package/client/src/WorkflowEditor.jsx +3 -0
- package/client/src/contexts/CommandContext.jsx +2 -1
- package/client/src/contexts/ModelContext.jsx +3 -3
- package/client/src/hooks/data.js +1 -0
- package/client/src/hooks/useValidation.js +1 -0
- package/client/src/translations.js +24 -24
- package/doc/AI-assistance.md +87 -63
- package/doc/Concepts.md +122 -0
- package/doc/Custom-Endpoints.md +31 -0
- package/doc/Event-system.md +13 -14
- package/doc/Home.md +33 -0
- package/doc/Modules.md +83 -0
- package/doc/Packs-gallery.md +8 -23
- package/doc/Workflows.md +32 -0
- package/doc/automation-workflows.md +141 -102
- package/doc/dashboards-kpis-charts.md +47 -49
- package/doc/data-management.md +126 -120
- package/doc/data-models.md +68 -75
- package/doc/roles-permissions.md +144 -43
- package/doc/sharding-replication.md +158 -0
- package/doc/users.md +54 -30
- package/package.json +1 -1
- package/server.js +37 -37
- package/src/constants.js +7 -8
- package/src/data.js +521 -520
- package/src/email.js +157 -154
- package/src/engine.js +117 -7
- package/src/gameObject.js +6 -0
- package/src/i18n.js +0 -1
- package/src/modules/auth-google/index.js +53 -50
- package/src/modules/bucket.js +346 -339
- package/src/modules/data/data.backup.js +400 -376
- package/src/modules/data/data.cluster.js +410 -42
- package/src/modules/data/data.operations.js +3666 -3635
- package/src/modules/data/data.replication.js +106 -64
- package/src/modules/data/data.routes.js +87 -64
- package/src/modules/data/data.scheduling.js +2 -1
- package/src/modules/file.js +248 -247
- package/src/modules/user.js +11 -1
- package/src/sso.js +91 -25
- package/test/cluster.test.js +221 -0
- package/test/core.test.js +0 -2
- package/test/replication.test.js +163 -0
- package/doc/core-concepts.md +0 -33
|
@@ -1,102 +1,141 @@
|
|
|
1
|
-
# Automation with Workflows: Create Automated Processes
|
|
2
|
-
|
|
3
|
-
The `data-primals-engine` features a powerful **Workflow** system that enables you to define and automate complex business processes. Workflows are sequences of steps and actions that can be triggered by various events or on a schedule, allowing for sophisticated automation directly within your backend.
|
|
4
|
-
|
|
5
|
-
## Core Workflow Models
|
|
6
|
-
|
|
7
|
-
The workflow system is composed of several interconnected data models:
|
|
8
|
-
|
|
9
|
-
### 1. `workflow`
|
|
10
|
-
|
|
11
|
-
The `workflow` model is the top-level definition of an automated process. It outlines the overall flow and its starting point.
|
|
12
|
-
|
|
13
|
-
- **`name`** (string, required): A unique, descriptive name for the workflow (e.g., "Order Validation", "Low Stock Notification").
|
|
14
|
-
- **`description`** (richtext, optional): A detailed explanation of the workflow's purpose.
|
|
15
|
-
- **`startStep`** (relation to `workflowStep`, optional): The first step to execute when the workflow is initiated.
|
|
16
|
-
|
|
17
|
-
### 2. `workflowTrigger`
|
|
18
|
-
|
|
19
|
-
A `workflowTrigger` defines an event or schedule that initiates a workflow.
|
|
20
|
-
|
|
21
|
-
- **`workflow`** (relation to `workflow`, required): The workflow that this trigger belongs to.
|
|
22
|
-
- **`name`** (string, required, unique): A descriptive name for the trigger (e.g., "New Order Created", "Stock < 5", "Monday 9 AM Report").
|
|
23
|
-
- **`type`** (enum, required): How the workflow is initiated:
|
|
24
|
-
- `manual`: Triggered by a data event.
|
|
25
|
-
- `scheduled`: Triggered by a cron schedule.
|
|
26
|
-
- **`onEvent`** (enum, for `manual` type): The data event that triggers the workflow: `DataAdded`, `DataEdited`, `DataDeleted`, `ModelAdded`, `ModelEdited`, `ModelDeleted`.
|
|
27
|
-
- **`targetModel`** (string, for `manual` type): The name of the model targeted by the `onEvent`.
|
|
28
|
-
- **`dataFilter`** (code - JSON, optional, for `manual` type): Optional MongoDB filter conditions checked against the `triggerData` before executing the workflow.
|
|
29
|
-
- **`cronExpression`** (string, for `scheduled` type): A cron expression (e.g., `'0 9 * * 1'` for Monday 9 AM) to schedule the workflow.
|
|
30
|
-
- **`isActive`** (boolean): Whether the trigger is currently active.
|
|
31
|
-
- **`env`** (code - JSON, optional): Environment variables (JSON key/value pairs) specific to this trigger.
|
|
32
|
-
|
|
33
|
-
### 3. `workflowStep`
|
|
34
|
-
|
|
35
|
-
A `workflowStep` represents a single stage within a workflow process. It can contain conditions, actions, and define the next steps based on success or failure.
|
|
36
|
-
|
|
37
|
-
- **`workflow`** (relation to `workflow`, required): The workflow this step belongs to.
|
|
38
|
-
- **`name`** (string, optional): A descriptive name for the step (e.g., "Check Inventory", "Send Confirmation Email").
|
|
39
|
-
- **`conditions`** (code - JSON, optional): Optional conditions (MongoDB filter syntax) that must be met before the step's actions are executed. These can reference `contextData`.
|
|
40
|
-
- **`actions`** (multiple relation to `workflowAction`, required): The main operations performed by this step.
|
|
41
|
-
- **`onSuccessStep`** (relation to `workflowStep`, optional): The next step to execute if this step's conditions are met and actions succeed.
|
|
42
|
-
- **`onFailureStep`** (relation to `workflowStep`, optional): The next step if conditions fail or any action within this step fails.
|
|
43
|
-
- **`isTerminal`** (boolean, default: `false`): Indicates if this step marks the end of a workflow path.
|
|
44
|
-
|
|
45
|
-
### 4. `workflowAction`
|
|
46
|
-
|
|
47
|
-
A `workflowAction` defines a specific operation to be performed by a `workflowStep`. This is where the actual work of the workflow happens.
|
|
48
|
-
|
|
49
|
-
- **`name`** (string, required): Name of the action (e.g., "Update Order Status", "Send Email", "Call Payment API").
|
|
50
|
-
- **`type`** (enum, required): The type of operation to perform:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
- `DeleteData`: Remove data from a `targetModel`.
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
- **`
|
|
69
|
-
- **`
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
# Automation with Workflows: Create Automated Processes
|
|
2
|
+
|
|
3
|
+
The `data-primals-engine` features a powerful **Workflow** system that enables you to define and automate complex business processes. Workflows are sequences of steps and actions that can be triggered by various events or on a schedule, allowing for sophisticated automation directly within your backend.
|
|
4
|
+
|
|
5
|
+
## Core Workflow Models
|
|
6
|
+
|
|
7
|
+
The workflow system is composed of several interconnected data models:
|
|
8
|
+
|
|
9
|
+
### 1. `workflow`
|
|
10
|
+
|
|
11
|
+
The `workflow` model is the top-level definition of an automated process. It outlines the overall flow and its starting point.
|
|
12
|
+
|
|
13
|
+
- **`name`** (string, required): A unique, descriptive name for the workflow (e.g., "Order Validation", "Low Stock Notification").
|
|
14
|
+
- **`description`** (richtext, optional): A detailed explanation of the workflow's purpose.
|
|
15
|
+
- **`startStep`** (relation to `workflowStep`, optional): The first step to execute when the workflow is initiated.
|
|
16
|
+
|
|
17
|
+
### 2. `workflowTrigger`
|
|
18
|
+
|
|
19
|
+
A `workflowTrigger` defines an event or schedule that initiates a workflow.
|
|
20
|
+
|
|
21
|
+
- **`workflow`** (relation to `workflow`, required): The workflow that this trigger belongs to.
|
|
22
|
+
- **`name`** (string, required, unique): A descriptive name for the trigger (e.g., "New Order Created", "Stock < 5", "Monday 9 AM Report").
|
|
23
|
+
- **`type`** (enum, required): How the workflow is initiated:
|
|
24
|
+
- `manual`: Triggered by a data event.
|
|
25
|
+
- `scheduled`: Triggered by a cron schedule.
|
|
26
|
+
- **`onEvent`** (enum, for `manual` type): The data event that triggers the workflow: `DataAdded`, `DataEdited`, `DataDeleted`, `ModelAdded`, `ModelEdited`, `ModelDeleted`.
|
|
27
|
+
- **`targetModel`** (string, for `manual` type): The name of the model targeted by the `onEvent`.
|
|
28
|
+
- **`dataFilter`** (code - JSON, optional, for `manual` type): Optional MongoDB filter conditions checked against the `triggerData` before executing the workflow.
|
|
29
|
+
- **`cronExpression`** (string, for `scheduled` type): A cron expression (e.g., `'0 9 * * 1'` for Monday 9 AM) to schedule the workflow.
|
|
30
|
+
- **`isActive`** (boolean): Whether the trigger is currently active.
|
|
31
|
+
- **`env`** (code - JSON, optional): Environment variables (JSON key/value pairs) specific to this trigger.
|
|
32
|
+
|
|
33
|
+
### 3. `workflowStep`
|
|
34
|
+
|
|
35
|
+
A `workflowStep` represents a single stage within a workflow process. It can contain conditions, actions, and define the next steps based on success or failure.
|
|
36
|
+
|
|
37
|
+
- **`workflow`** (relation to `workflow`, required): The workflow this step belongs to.
|
|
38
|
+
- **`name`** (string, optional): A descriptive name for the step (e.g., "Check Inventory", "Send Confirmation Email").
|
|
39
|
+
- **`conditions`** (code - JSON, optional): Optional conditions (MongoDB filter syntax) that must be met before the step's actions are executed. These can reference `contextData`.
|
|
40
|
+
- **`actions`** (multiple relation to `workflowAction`, required): The main operations performed by this step.
|
|
41
|
+
- **`onSuccessStep`** (relation to `workflowStep`, optional): The next step to execute if this step's conditions are met and actions succeed.
|
|
42
|
+
- **`onFailureStep`** (relation to `workflowStep`, optional): The next step if conditions fail or any action within this step fails.
|
|
43
|
+
- **`isTerminal`** (boolean, default: `false`): Indicates if this step marks the end of a workflow path.
|
|
44
|
+
|
|
45
|
+
### 4. `workflowAction`
|
|
46
|
+
|
|
47
|
+
A `workflowAction` defines a specific operation to be performed by a `workflowStep`. This is where the actual work of the workflow happens.
|
|
48
|
+
|
|
49
|
+
- **`name`** (string, required): Name of the action (e.g., "Update Order Status", "Send Email", "Call Payment API").
|
|
50
|
+
- **`type`** (enum, required): The type of operation to perform:
|
|
51
|
+
|
|
52
|
+
| Action Type | Description | Related Properties |
|
|
53
|
+
|:---------------------------|:-------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
54
|
+
| **`UpdateData`** | Modify existing data in a `targetModel`. | - **`targetModel`**: The model to target. Ex: `'product'`<br/>- **`targetSelector`**: Expression to filter the target document(s). Ex: `{ "_id": "{triggerData._id}" }`<br/>- **`fieldsToUpdate`**: Key-value pairs of fields to update. Ex: `{ "status": "shipped", "shippedAt": "{now}" }` |
|
|
55
|
+
| **`CreateData`** | Add new data to a `targetModel`. | - **`targetModel`**: The model to target. Ex: `'product'`<br/>- **`dataToCreate`**: Object template for the new document. Ex: `{ "title": "New Task for {triggerData.name}", "status": "todo" }` |
|
|
56
|
+
| **`DeleteData`** | Remove data from a `targetModel`. | - **`targetModel`**: The model to target. Ex: `'product'`<br/>- **`targetSelector`**: Expression to filter the target document(s). Ex: `{ "_id": "{triggerData._id}" }` |
|
|
57
|
+
| **`ExecuteScript`** | Run custom JavaScript code in a secure sandbox. | - **`script`**: The JavaScript code to execute. Ex: `return { newPrice: context.triggerData.price * 1.1 };` |
|
|
58
|
+
| **`HttpRequest`** | Make an HTTP request to an external service. | - **`url`**: The URL for the HTTP request. Ex: `'https://api.example.com/orders/{triggerData.orderId}'`<br/>- **`method`**: The HTTP method. Ex: `'POST'`<br/>- **`headers`**: The HTTP headers. Ex: `{ "Authorization": "Bearer {env.API_KEY}" }`<br/>- **`body`**: The request body. Ex: `{ "status": "completed" }` |
|
|
59
|
+
| **`SendEmail`** | Send an email using the configured SMTP settings. | - **`emailRecipients`**: List of email recipients. Ex: `['{triggerData.customer.email}']`<br/>- **`emailSubject`**: The email subject. Ex: `'Order Confirmation #{triggerData.orderId}'`<br/>- **`emailContent`**: The email body (HTML). Ex: `'<h1>Thank you!</h1>'` |
|
|
60
|
+
| **`Wait`** | Pause the workflow for a specified duration. | - **`duration`**: How long to pause. Ex: `10`<br/>- **`durationUnit`**: The unit for the duration. Ex: `'minutes'` |
|
|
61
|
+
| **`GenerateAIContent`** | Generate content using an AI model (e.g., OpenAI, Google Gemini). | - **`aiProvider`**: The AI provider. Ex: `'OpenAI'`<br/>- **`aiModel`**: The specific model to use. Ex: `'gpt-4o-mini'`<br/>- **`prompt`**: The prompt to send to the AI. Ex: `'Summarize: {triggerData.description}'` |
|
|
62
|
+
| **`ExecuteServiceFunction`** | Call a function from a registered internal service (e.g., 'stripe'). | - **`serviceName`**: The name of the service. Ex: `'stripe'`<br/>- **`functionName`**: The function to call. Ex: `'createRefund'`<br/>- **`args`**: Arguments for the function. Ex: `['{triggerData.chargeId}', 5000]` |
|
|
63
|
+
|
|
64
|
+
## Workflow Execution (`workflowRun`)
|
|
65
|
+
|
|
66
|
+
Each time a workflow is triggered, a `workflowRun` document is created to track its execution.
|
|
67
|
+
|
|
68
|
+
- **`workflow`** (relation to `workflow`): The workflow definition that was executed.
|
|
69
|
+
- **`contextData`** (code - JSON): A snapshot of the data or event that triggered this run, and any data generated during execution.
|
|
70
|
+
- **`status`** (enum): The current status (`pending`, `running`, `completed`, `failed`, `waiting`, `cancelled`).
|
|
71
|
+
- **`history`** (array of objects): Detailed execution history of each step and action.
|
|
72
|
+
- **`startedAt`, `completedAt`**: Timestamps for the run.
|
|
73
|
+
- **`error`**: Error message if the workflow run failed.
|
|
74
|
+
|
|
75
|
+
## Creating a Workflow Programmatically: A Step-by-Step Example
|
|
76
|
+
|
|
77
|
+
Let's build a complete workflow that sends a welcome email to every new user who signs up. This entire process can be automated by creating the necessary workflow documents via API calls using `insertData`.
|
|
78
|
+
|
|
79
|
+
### 1. The `workflow`
|
|
80
|
+
|
|
81
|
+
First, we define the main workflow document. This acts as a container for the steps and logic. We link it to its starting step by name.
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
await insertData("workflow", {
|
|
85
|
+
"name": "New User Onboarding",
|
|
86
|
+
"description": "Sends a welcome email to new users upon registration.",
|
|
87
|
+
"startStep": { "$find": { "name": "Send Welcome Email" } } // Link to the first step
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 2. The `workflowAction`
|
|
92
|
+
|
|
93
|
+
Next, we define the specific task to be performed: sending the email. The `emailRecipients`, `emailSubject`, and `emailContent` fields use placeholders like `{triggerData.contact.email}`. These will be automatically replaced with the data from the user document that triggered the workflow.
|
|
94
|
+
|
|
95
|
+
```javascript
|
|
96
|
+
await insertData("workflowAction", {
|
|
97
|
+
"name": "Send Welcome Email Action",
|
|
98
|
+
"type": "SendEmail",
|
|
99
|
+
"emailRecipients": "{triggerData.contact.email}",
|
|
100
|
+
"emailSubject": "Welcome to Our Platform, {triggerData.contact.firstName}!",
|
|
101
|
+
"emailContent": "<h1>Welcome aboard, {triggerData.contact.firstName}!</h1><p>We're thrilled to have you join our community.</p>"
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
> **Note**: For this to work, your SMTP settings must be configured either in your `.env` file or in the `env` model for the user running the workflow.
|
|
105
|
+
|
|
106
|
+
### 3. The `workflowStep`
|
|
107
|
+
|
|
108
|
+
Now, we create a step that executes our action. A workflow can have multiple steps, but for this simple case, we only need one. We link the step to the workflow and the action by their names.
|
|
109
|
+
|
|
110
|
+
```javascript
|
|
111
|
+
await insertData("workflowStep", {
|
|
112
|
+
"name": "Send Welcome Email",
|
|
113
|
+
"workflow": { "$find": { "name": "New User Onboarding" } },
|
|
114
|
+
"actions": [
|
|
115
|
+
{ "$find": { "name": "Send Welcome Email Action" } }
|
|
116
|
+
],
|
|
117
|
+
"isTerminal": true // This is the last step in this path.
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### 4. The `workflowTrigger`
|
|
122
|
+
|
|
123
|
+
Finally, we define what will start the workflow. This trigger will listen for new documents being added (`DataAdded`) to the `user` model.
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
await insertData("workflowTrigger", {
|
|
127
|
+
"name": "On New User Registration",
|
|
128
|
+
"workflow": { "$find": { "name": "New User Onboarding" } },
|
|
129
|
+
"type": "manual",
|
|
130
|
+
"onEvent": "DataAdded",
|
|
131
|
+
"targetModel": "user",
|
|
132
|
+
"isActive": true
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
With these four API calls, your automated welcome email system is now active. Any new user created in the system will automatically receive a personalized welcome email.
|
|
137
|
+
|
|
138
|
+
This powerful system allows you to automate virtually any process, from simple notifications to complex data transformations and integrations with external services.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
**[Next: Data Packs](packs-gallery)**
|
|
@@ -1,49 +1,47 @@
|
|
|
1
|
-
# Dashboards, KPIs, and Charts: Track Your Key Metrics
|
|
2
|
-
|
|
3
|
-
The `data-primals-engine` provides robust features for visualizing and tracking your application's performance and key metrics through customizable Dashboards and Key Performance Indicators (KPIs).
|
|
4
|
-
|
|
5
|
-
## Dashboards
|
|
6
|
-
|
|
7
|
-
A **Dashboard** serves as a personalized overview, allowing users to arrange and display various KPIs and charts relevant to their needs.
|
|
8
|
-
|
|
9
|
-
###
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
**Next: Users**
|
|
1
|
+
# Dashboards, KPIs, and Charts: Track Your Key Metrics
|
|
2
|
+
|
|
3
|
+
The `data-primals-engine` provides robust features for visualizing and tracking your application's performance and key metrics through customizable Dashboards and Key Performance Indicators (KPIs).
|
|
4
|
+
|
|
5
|
+
## Dashboards
|
|
6
|
+
|
|
7
|
+
A **Dashboard** serves as a personalized overview, allowing users to arrange and display various KPIs and charts relevant to their needs.
|
|
8
|
+
|
|
9
|
+
### The `dashboard` Model
|
|
10
|
+
|
|
11
|
+
| Attribute | Type | Description |
|
|
12
|
+
|:------------------|:--------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
13
|
+
| **`name`** | string, required | The customizable display name of the dashboard. |
|
|
14
|
+
| **`description`** | string, optional | Provides additional context for the dashboard. |
|
|
15
|
+
| **`layout`** | code (JSON), required | A JSON structure describing the organization of KPIs and charts. Defines how elements are arranged (e.g., in columns).<br/>*Example: `"{ \"type\": \"columns\", \"columns\": [ [\"kpi_id_1\"], [\"kpi_id_2\"] ] }"`* |
|
|
16
|
+
| **`settings`** | code (JSON), optional | JSON settings for the dashboard, such as a `defaultTimeRange` (e.g., 'last_7_days') or a `refreshInterval` in seconds. |
|
|
17
|
+
| **`isDefault`** | boolean, optional | If `true`, this dashboard is displayed by default for the user. |
|
|
18
|
+
|
|
19
|
+
## Key Performance Indicators (KPIs)
|
|
20
|
+
|
|
21
|
+
**KPIs** are quantifiable measures used to evaluate the success of an organization, employee, etc., in meeting objectives. In `data-primals-engine`, KPIs are highly configurable to extract meaningful insights from your data.
|
|
22
|
+
|
|
23
|
+
### The `kpi` Model
|
|
24
|
+
|
|
25
|
+
| Attribute | Type | Description |
|
|
26
|
+
|:-----------------------|:--------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
27
|
+
| **`name`** | string, required | The display name of the KPI (e.g., "Total Revenue", "Active Users"). |
|
|
28
|
+
| **`description`** | string, optional | Additional information about the KPI. |
|
|
29
|
+
| **`targetModel`** | string, required | The name of the data model on which to calculate the KPI (e.g., `order`, `user`). |
|
|
30
|
+
| **`aggregationType`** | enum, required | The type of calculation to perform: `count`, `sum`, `avg`, `min`, or `max`. |
|
|
31
|
+
| **`aggregationField`** | string, optional | The name of the numeric field to aggregate (e.g., `totalAmount`). Not required for `count`. |
|
|
32
|
+
| **`matchFormula`** | code (JSON), optional | A MongoDB `$match` filter to apply before aggregation (e.g., `{ "status": "delivered" }`). |
|
|
33
|
+
| **`showTotal`** | boolean, optional | If `true`, displays a grand total alongside the KPI. |
|
|
34
|
+
| **`showPercentTotal`** | boolean, optional | If `true`, displays the KPI value as a percentage of a total. |
|
|
35
|
+
| **`totalMatchFormula`** | code (JSON), optional | A MongoDB `$match` filter for calculating the total when `showPercentTotal` is enabled. |
|
|
36
|
+
| **`unit`** | string, optional | The unit to display with the KPI value (e.g., "€", "$", "users"). |
|
|
37
|
+
| **`icon`** | string, optional | An icon name (e.g., `FaUsers`, `FaShoppingCart`) to visually represent the KPI. |
|
|
38
|
+
| **`order`** | number, optional | The display order of the KPI on a dashboard. |
|
|
39
|
+
| **`color`** | string, optional | A color associated with the KPI for visual distinction. |
|
|
40
|
+
|
|
41
|
+
## Charts
|
|
42
|
+
|
|
43
|
+
While the `kpi` model focuses on single aggregated values, the engine also supports the integration of charts to visualize data trends and distributions over time or across categories. These are typically rendered based on underlying KPI data or direct queries, offering a richer analytical experience.
|
|
44
|
+
|
|
45
|
+
By combining Dashboards, configurable KPIs, and charting capabilities, `data-primals-engine` empowers users to effectively monitor and understand their key business metrics.
|
|
46
|
+
|
|
47
|
+
**[Next: Users](users)**
|