@memberjunction/actions-base 2.42.1 → 2.44.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/README.md +280 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# @memberjunction/actions-base
|
|
2
|
+
|
|
3
|
+
Base classes and interfaces for the MemberJunction Actions framework. This library provides the foundational components for implementing and executing actions across both server and client environments.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Actions framework in MemberJunction provides a flexible, metadata-driven system for executing business logic and operations. This base package contains the core classes and interfaces that enable:
|
|
8
|
+
|
|
9
|
+
- **Action Engine**: Core engine for loading, configuring, and executing actions
|
|
10
|
+
- **Entity Actions**: Actions that operate on specific entities with various invocation contexts
|
|
11
|
+
- **Code Generation**: Support for dynamically generated action code with library management
|
|
12
|
+
- **Execution Logging**: Built-in logging and result tracking for all action executions
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @memberjunction/actions-base
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Core Components
|
|
21
|
+
|
|
22
|
+
### ActionEngineBase
|
|
23
|
+
|
|
24
|
+
The singleton base class that manages all action metadata and provides the foundation for action execution.
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { ActionEngineBase } from '@memberjunction/actions-base';
|
|
28
|
+
|
|
29
|
+
// Get the singleton instance
|
|
30
|
+
const actionEngine = ActionEngineBase.Instance;
|
|
31
|
+
|
|
32
|
+
// Configure the engine (required before use)
|
|
33
|
+
await actionEngine.Config(false, userInfo);
|
|
34
|
+
|
|
35
|
+
// Access action metadata
|
|
36
|
+
const allActions = actionEngine.Actions;
|
|
37
|
+
const coreActions = actionEngine.CoreActions;
|
|
38
|
+
const actionParams = actionEngine.ActionParams;
|
|
39
|
+
const actionFilters = actionEngine.ActionFilters;
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### EntityActionEngineBase
|
|
43
|
+
|
|
44
|
+
Manages entity-specific actions and their various invocation contexts (single record, view-based, list-based).
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { EntityActionEngineBase } from '@memberjunction/actions-base';
|
|
48
|
+
|
|
49
|
+
// Get the singleton instance
|
|
50
|
+
const entityActionEngine = EntityActionEngineBase.Instance;
|
|
51
|
+
|
|
52
|
+
// Configure the engine
|
|
53
|
+
await entityActionEngine.Config(false, userInfo);
|
|
54
|
+
|
|
55
|
+
// Get actions for a specific entity
|
|
56
|
+
const customerActions = entityActionEngine.GetActionsByEntityName('Customers', 'Active');
|
|
57
|
+
|
|
58
|
+
// Get actions by invocation type
|
|
59
|
+
const viewActions = entityActionEngine.GetActionsByEntityNameAndInvocationType(
|
|
60
|
+
'Orders',
|
|
61
|
+
'View',
|
|
62
|
+
'Active'
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Action Types and Models
|
|
67
|
+
|
|
68
|
+
### ActionParam
|
|
69
|
+
|
|
70
|
+
Represents input/output parameters for actions:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { ActionParam } from '@memberjunction/actions-base';
|
|
74
|
+
|
|
75
|
+
const param: ActionParam = {
|
|
76
|
+
Name: 'CustomerID',
|
|
77
|
+
Value: '12345',
|
|
78
|
+
Type: 'Input' // 'Input' | 'Output' | 'Both'
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### RunActionParams
|
|
83
|
+
|
|
84
|
+
Configuration for running an action:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { RunActionParams } from '@memberjunction/actions-base';
|
|
88
|
+
|
|
89
|
+
const runParams: RunActionParams = {
|
|
90
|
+
Action: actionEntity,
|
|
91
|
+
ContextUser: userInfo,
|
|
92
|
+
SkipActionLog: false, // Optional
|
|
93
|
+
Filters: [], // Optional filters to run before action
|
|
94
|
+
Params: [
|
|
95
|
+
{ Name: 'Input1', Value: 'test', Type: 'Input' }
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### ActionResult
|
|
101
|
+
|
|
102
|
+
The result object returned from action execution:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
import { ActionResult } from '@memberjunction/actions-base';
|
|
106
|
+
|
|
107
|
+
// ActionResult contains:
|
|
108
|
+
// - Success: boolean indicating if action succeeded
|
|
109
|
+
// - Result: ActionResultCodeEntity with the specific result code
|
|
110
|
+
// - LogEntry: ActionExecutionLogEntity for tracking
|
|
111
|
+
// - Message: Optional message about the outcome
|
|
112
|
+
// - Params: All parameters including outputs
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### EntityActionInvocationParams
|
|
116
|
+
|
|
117
|
+
Parameters for invoking entity-specific actions:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
import { EntityActionInvocationParams } from '@memberjunction/actions-base';
|
|
121
|
+
|
|
122
|
+
const invocationParams: EntityActionInvocationParams = {
|
|
123
|
+
EntityAction: entityActionExtended,
|
|
124
|
+
InvocationType: invocationTypeEntity,
|
|
125
|
+
ContextUser: userInfo,
|
|
126
|
+
// One of these based on invocation type:
|
|
127
|
+
EntityObject: customerEntity, // For single record
|
|
128
|
+
ViewID: 'view-123', // For view-based
|
|
129
|
+
ListID: 'list-456' // For list-based
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Extended Entity Classes
|
|
134
|
+
|
|
135
|
+
### ActionEntityExtended
|
|
136
|
+
|
|
137
|
+
Enhanced action entity with additional functionality:
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { ActionEntityExtended } from '@memberjunction/actions-base';
|
|
141
|
+
|
|
142
|
+
// Provides additional properties:
|
|
143
|
+
const action = actionEngine.Actions[0] as ActionEntityExtended;
|
|
144
|
+
console.log(action.IsCoreAction); // true if core MJ action
|
|
145
|
+
console.log(action.ProgrammaticName); // Code-friendly name
|
|
146
|
+
console.log(action.ResultCodes); // Possible result codes
|
|
147
|
+
console.log(action.Params); // Action parameters
|
|
148
|
+
console.log(action.Libraries); // Required libraries
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### EntityActionEntityExtended
|
|
152
|
+
|
|
153
|
+
Enhanced entity action with related data:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { EntityActionEntityExtended } from '@memberjunction/actions-base';
|
|
157
|
+
|
|
158
|
+
// Provides lazy-loaded related data:
|
|
159
|
+
const entityAction = entityActionEngine.EntityActions[0] as EntityActionEntityExtended;
|
|
160
|
+
console.log(entityAction.Filters); // Associated filters
|
|
161
|
+
console.log(entityAction.Invocations); // Invocation configurations
|
|
162
|
+
console.log(entityAction.Params); // Action parameters
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Code Generation Support
|
|
166
|
+
|
|
167
|
+
The framework includes support for generated code with library tracking:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { GeneratedCode, ActionLibrary } from '@memberjunction/actions-base';
|
|
171
|
+
|
|
172
|
+
// GeneratedCode structure
|
|
173
|
+
const generatedCode: GeneratedCode = {
|
|
174
|
+
Success: true,
|
|
175
|
+
Code: 'function execute() { ... }',
|
|
176
|
+
LibrariesUsed: [
|
|
177
|
+
{
|
|
178
|
+
LibraryName: 'lodash',
|
|
179
|
+
ItemsUsed: ['map', 'filter']
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
Comments: 'Processes customer data',
|
|
183
|
+
ErrorMessage: undefined
|
|
184
|
+
};
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Usage Examples
|
|
188
|
+
|
|
189
|
+
### Basic Action Engine Configuration
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { ActionEngineBase } from '@memberjunction/actions-base';
|
|
193
|
+
import { UserInfo } from '@memberjunction/core';
|
|
194
|
+
|
|
195
|
+
async function initializeActionEngine(user: UserInfo) {
|
|
196
|
+
const engine = ActionEngineBase.Instance;
|
|
197
|
+
|
|
198
|
+
// Initial configuration
|
|
199
|
+
await engine.Config(false, user);
|
|
200
|
+
|
|
201
|
+
// Force refresh if needed
|
|
202
|
+
await engine.Config(true, user);
|
|
203
|
+
|
|
204
|
+
// Access loaded metadata
|
|
205
|
+
console.log(`Loaded ${engine.Actions.length} actions`);
|
|
206
|
+
console.log(`Core actions: ${engine.CoreActions.length}`);
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Working with Entity Actions
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { EntityActionEngineBase } from '@memberjunction/actions-base';
|
|
214
|
+
|
|
215
|
+
async function getEntityActions(entityName: string, user: UserInfo) {
|
|
216
|
+
const engine = EntityActionEngineBase.Instance;
|
|
217
|
+
await engine.Config(false, user);
|
|
218
|
+
|
|
219
|
+
// Get all active actions for an entity
|
|
220
|
+
const actions = engine.GetActionsByEntityName(entityName, 'Active');
|
|
221
|
+
|
|
222
|
+
// Filter by invocation type
|
|
223
|
+
const singleRecordActions = actions.filter(a =>
|
|
224
|
+
a.Invocations.some(i => i.InvocationType === 'Single Record')
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
return singleRecordActions;
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Action Parameter Handling
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { ActionParam } from '@memberjunction/actions-base';
|
|
235
|
+
|
|
236
|
+
function prepareActionParams(inputs: Record<string, any>): ActionParam[] {
|
|
237
|
+
return Object.entries(inputs).map(([name, value]) => ({
|
|
238
|
+
Name: name,
|
|
239
|
+
Value: value,
|
|
240
|
+
Type: 'Input'
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// Example usage
|
|
245
|
+
const params = prepareActionParams({
|
|
246
|
+
CustomerID: '123',
|
|
247
|
+
OrderDate: new Date(),
|
|
248
|
+
TotalAmount: 150.00
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Dependencies
|
|
253
|
+
|
|
254
|
+
- `@memberjunction/global`: Global utilities and registration system
|
|
255
|
+
- `@memberjunction/core`: Core MemberJunction interfaces and base classes
|
|
256
|
+
- `@memberjunction/core-entities`: Entity definitions for MemberJunction metadata
|
|
257
|
+
|
|
258
|
+
## Integration with Other MemberJunction Packages
|
|
259
|
+
|
|
260
|
+
This package serves as the foundation for:
|
|
261
|
+
|
|
262
|
+
- `@memberjunction/actions-server`: Server-side action execution implementation
|
|
263
|
+
- `@memberjunction/actions-client`: Client-side action execution
|
|
264
|
+
- Custom action implementations in your applications
|
|
265
|
+
|
|
266
|
+
## Best Practices
|
|
267
|
+
|
|
268
|
+
1. **Always Configure Before Use**: Call `Config()` on the engine instances before accessing any metadata
|
|
269
|
+
2. **Use Singleton Instances**: Always use the `.Instance` property to get engine instances
|
|
270
|
+
3. **Handle Async Operations**: All configuration and many operations are asynchronous
|
|
271
|
+
4. **Check Action Status**: Filter actions by status ('Active', 'Pending', 'Disabled') when appropriate
|
|
272
|
+
5. **Validate Parameters**: Ensure all required input parameters are provided before execution
|
|
273
|
+
|
|
274
|
+
## TypeScript Support
|
|
275
|
+
|
|
276
|
+
This package is written in TypeScript and provides full type definitions. All classes and interfaces are properly typed for optimal development experience.
|
|
277
|
+
|
|
278
|
+
## License
|
|
279
|
+
|
|
280
|
+
ISC License - see LICENSE file in the root of the repository.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/actions-base",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "Base Classes for MemberJunction Actions. This library is used on both server and network nodes.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"typescript": "^5.4.5"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@memberjunction/global": "2.
|
|
23
|
-
"@memberjunction/core": "2.
|
|
24
|
-
"@memberjunction/core-entities": "2.
|
|
22
|
+
"@memberjunction/global": "2.44.0",
|
|
23
|
+
"@memberjunction/core": "2.44.0",
|
|
24
|
+
"@memberjunction/core-entities": "2.44.0"
|
|
25
25
|
}
|
|
26
26
|
}
|