@memberjunction/core-entities 2.43.0 → 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/dist/custom/AIPromptExtended.d.ts +12 -0
- package/dist/custom/AIPromptExtended.d.ts.map +1 -0
- package/dist/custom/AIPromptExtended.js +30 -0
- package/dist/custom/AIPromptExtended.js.map +1 -0
- package/dist/generated/entity_subclasses.d.ts +23 -22
- package/dist/generated/entity_subclasses.d.ts.map +1 -1
- package/dist/generated/entity_subclasses.js +33 -31
- package/dist/generated/entity_subclasses.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/readme.md +268 -1
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from './generated/entity_subclasses';
|
|
|
2
2
|
export * from "./custom/UserViewEntity";
|
|
3
3
|
export * from './custom/DashboardEntityExtended';
|
|
4
4
|
export * from './custom/AIModelExtended';
|
|
5
|
+
export * from './custom/AIPromptExtended';
|
|
5
6
|
export * from './custom/ListDetailEntityExtended';
|
|
6
7
|
export * from './custom/TypeTablesCache';
|
|
7
8
|
export * from './custom/ScheduledActionExtended';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,2CAA2C,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAC;AACxC,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,0BAA0B,CAAC;AACzC,cAAc,kCAAkC,CAAC;AACjD,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,2CAA2C,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ __exportStar(require("./generated/entity_subclasses"), exports);
|
|
|
18
18
|
__exportStar(require("./custom/UserViewEntity"), exports);
|
|
19
19
|
__exportStar(require("./custom/DashboardEntityExtended"), exports);
|
|
20
20
|
__exportStar(require("./custom/AIModelExtended"), exports);
|
|
21
|
+
__exportStar(require("./custom/AIPromptExtended"), exports);
|
|
21
22
|
__exportStar(require("./custom/ListDetailEntityExtended"), exports);
|
|
22
23
|
__exportStar(require("./custom/TypeTablesCache"), exports);
|
|
23
24
|
__exportStar(require("./custom/ScheduledActionExtended"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAC7C,0DAAwC;AACxC,mEAAiD;AACjD,2DAAyC;AACzC,oEAAkD;AAClD,2DAAyC;AACzC,mEAAiD;AACjD,wFAAsE;AACtE,0FAAwE;AACxE,4EAA0D"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gEAA6C;AAC7C,0DAAwC;AACxC,mEAAiD;AACjD,2DAAyC;AACzC,4DAA0C;AAC1C,oEAAkD;AAClD,2DAAyC;AACzC,mEAAiD;AACjD,wFAAsE;AACtE,0FAAwE;AACxE,4EAA0D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/core-entities",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "Entity subclasses for the metadata layer of MemberJunction defined in the MJ_CORE schema (usually 'admin'), distributed as part of each release of MemberJunction",
|
|
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/core": "2.
|
|
23
|
-
"@memberjunction/global": "2.
|
|
22
|
+
"@memberjunction/core": "2.44.0",
|
|
23
|
+
"@memberjunction/global": "2.44.0",
|
|
24
24
|
"zod": "^3.23.8"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/readme.md
CHANGED
|
@@ -1,3 +1,270 @@
|
|
|
1
1
|
# @memberjunction/core-entities
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A comprehensive library of strongly-typed entity classes for MemberJunction's core metadata schema. This package provides type-safe access to all MemberJunction system entities with built-in validation, custom business logic, and seamless integration with the MemberJunction framework.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The `@memberjunction/core-entities` package contains:
|
|
8
|
+
- **178+ Generated Entity Classes**: Strongly-typed TypeScript classes for all core MemberJunction entities
|
|
9
|
+
- **Extended Entity Classes**: Custom subclasses with specialized business logic
|
|
10
|
+
- **Resource Permission Engine**: Comprehensive permission management system
|
|
11
|
+
- **Zod Schema Validation**: Built-in runtime validation for all entity types
|
|
12
|
+
- **Type Definitions**: Full TypeScript type definitions for enhanced IDE support
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @memberjunction/core-entities
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Key Features
|
|
21
|
+
|
|
22
|
+
### 1. Strongly-Typed Entity Classes
|
|
23
|
+
Every MemberJunction core entity has a corresponding TypeScript class with:
|
|
24
|
+
- Full type safety for all properties
|
|
25
|
+
- Automatic validation using Zod schemas
|
|
26
|
+
- Relationship navigation properties
|
|
27
|
+
- Built-in CRUD operations
|
|
28
|
+
|
|
29
|
+
### 2. Extended Entity Classes
|
|
30
|
+
Several entities have custom extended classes that provide additional functionality:
|
|
31
|
+
|
|
32
|
+
- **UserViewEntityExtended**: Enhanced view management with filter and column parsing
|
|
33
|
+
- **DashboardEntityExtended**: Dashboard configuration management
|
|
34
|
+
- **AIModelEntityExtended**: AI model utilities and helpers
|
|
35
|
+
- **AIPromptEntityExtended**: Prompt management functionality
|
|
36
|
+
- **ListDetailEntityExtended**: List view enhancements
|
|
37
|
+
- **ScheduledActionExtended**: Scheduled task management
|
|
38
|
+
- **ResourcePermissionEntity**: Resource access control
|
|
39
|
+
|
|
40
|
+
### 3. Resource Permission Engine
|
|
41
|
+
A sophisticated permission system for managing access to various resources:
|
|
42
|
+
- Role-based permissions
|
|
43
|
+
- Resource type definitions
|
|
44
|
+
- Permission inheritance
|
|
45
|
+
- Cached permission lookups
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Basic Entity Usage
|
|
50
|
+
|
|
51
|
+
```typescript
|
|
52
|
+
import { Metadata } from '@memberjunction/core';
|
|
53
|
+
import { UserEntity, ApplicationEntity } from '@memberjunction/core-entities';
|
|
54
|
+
|
|
55
|
+
// Always use Metadata to create entity instances
|
|
56
|
+
const md = new Metadata();
|
|
57
|
+
|
|
58
|
+
// Load a user by ID
|
|
59
|
+
const user = await md.GetEntityObject<UserEntity>('Users');
|
|
60
|
+
await user.Load('user-id-here');
|
|
61
|
+
|
|
62
|
+
// Access strongly-typed properties
|
|
63
|
+
console.log(user.Email);
|
|
64
|
+
console.log(user.FirstName);
|
|
65
|
+
|
|
66
|
+
// Create a new application
|
|
67
|
+
const app = await md.GetEntityObject<ApplicationEntity>('Applications');
|
|
68
|
+
app.NewRecord();
|
|
69
|
+
app.Name = 'My New Application';
|
|
70
|
+
app.Description = 'A test application';
|
|
71
|
+
await app.Save();
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Working with User Views
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { UserViewEntityExtended } from '@memberjunction/core-entities';
|
|
78
|
+
import { Metadata, RunView } from '@memberjunction/core';
|
|
79
|
+
|
|
80
|
+
const md = new Metadata();
|
|
81
|
+
|
|
82
|
+
// Load user views for an entity
|
|
83
|
+
const rv = new RunView();
|
|
84
|
+
const views = await rv.RunView<UserViewEntityExtended>({
|
|
85
|
+
EntityName: 'User Views',
|
|
86
|
+
ExtraFilter: `EntityID='${entityId}' AND UserID='${userId}'`,
|
|
87
|
+
ResultType: 'entity_object'
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Access parsed view configuration
|
|
91
|
+
const view = views.Results[0];
|
|
92
|
+
const columns = view.Columns; // Parsed column configuration
|
|
93
|
+
const filters = view.Filter; // Parsed filter configuration
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Resource Permissions
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
import { ResourcePermissionEngine } from '@memberjunction/core-entities';
|
|
100
|
+
|
|
101
|
+
// Get the singleton instance
|
|
102
|
+
const permEngine = ResourcePermissionEngine.Instance;
|
|
103
|
+
|
|
104
|
+
// Initialize the engine
|
|
105
|
+
await permEngine.Config();
|
|
106
|
+
|
|
107
|
+
// Check permissions for a resource
|
|
108
|
+
const permissions = permEngine.GetPermissionsForResource(
|
|
109
|
+
resourceTypeId,
|
|
110
|
+
resourceRecordId
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Get user's permission level
|
|
114
|
+
const userPermission = await permEngine.GetUserPermissionForResource(
|
|
115
|
+
userId,
|
|
116
|
+
resourceTypeId,
|
|
117
|
+
resourceRecordId
|
|
118
|
+
);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Dashboard Management
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { DashboardEntityExtended } from '@memberjunction/core-entities';
|
|
125
|
+
import { Metadata } from '@memberjunction/core';
|
|
126
|
+
|
|
127
|
+
const md = new Metadata();
|
|
128
|
+
|
|
129
|
+
// Create a new dashboard
|
|
130
|
+
const dashboard = await md.GetEntityObject<DashboardEntityExtended>('Dashboards');
|
|
131
|
+
dashboard.NewRecord(); // Automatically sets default configuration
|
|
132
|
+
|
|
133
|
+
dashboard.Name = 'Sales Dashboard';
|
|
134
|
+
dashboard.Description = 'Monthly sales metrics';
|
|
135
|
+
await dashboard.Save();
|
|
136
|
+
|
|
137
|
+
// The UIConfigDetails is automatically initialized with default grid configuration
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### AI Model Access
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { AIModelEntityExtended } from '@memberjunction/core-entities';
|
|
144
|
+
import { RunView } from '@memberjunction/core';
|
|
145
|
+
|
|
146
|
+
const rv = new RunView();
|
|
147
|
+
|
|
148
|
+
// Load all active AI models
|
|
149
|
+
const models = await rv.RunView<AIModelEntityExtended>({
|
|
150
|
+
EntityName: 'AI Models',
|
|
151
|
+
ExtraFilter: "IsActive=1",
|
|
152
|
+
OrderBy: 'Name',
|
|
153
|
+
ResultType: 'entity_object'
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// Use the extended functionality
|
|
157
|
+
models.Results.forEach(model => {
|
|
158
|
+
console.log(model.APINameOrName); // Uses APIName if available, otherwise Name
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Entity Validation
|
|
163
|
+
|
|
164
|
+
All entities include Zod schema validation:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
import { UserSchema, UserEntityType } from '@memberjunction/core-entities';
|
|
168
|
+
|
|
169
|
+
// Validate data before creating entity
|
|
170
|
+
const userData: unknown = { /* user data */ };
|
|
171
|
+
|
|
172
|
+
try {
|
|
173
|
+
const validatedData = UserSchema.parse(userData);
|
|
174
|
+
// Data is now typed as UserEntityType
|
|
175
|
+
} catch (error) {
|
|
176
|
+
// Handle validation errors
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Type Definitions
|
|
181
|
+
|
|
182
|
+
Every entity exports both the class and its TypeScript type:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import {
|
|
186
|
+
ApplicationEntity, // The entity class
|
|
187
|
+
ApplicationEntityType, // The TypeScript type
|
|
188
|
+
ApplicationSchema // The Zod schema
|
|
189
|
+
} from '@memberjunction/core-entities';
|
|
190
|
+
|
|
191
|
+
// Use types for function parameters
|
|
192
|
+
function processApplication(app: ApplicationEntityType) {
|
|
193
|
+
// Type-safe access to all properties
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Custom Entity Extensions
|
|
198
|
+
|
|
199
|
+
To create your own entity extensions:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
203
|
+
import { BaseEntity } from '@memberjunction/core';
|
|
204
|
+
import { YourEntity } from '@memberjunction/core-entities';
|
|
205
|
+
|
|
206
|
+
@RegisterClass(BaseEntity, 'Your Entity Name')
|
|
207
|
+
export class YourEntityExtended extends YourEntity {
|
|
208
|
+
// Add custom methods and properties
|
|
209
|
+
public customMethod(): void {
|
|
210
|
+
// Your business logic
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Available Entities
|
|
216
|
+
|
|
217
|
+
This package includes classes for all core MemberJunction entities including:
|
|
218
|
+
|
|
219
|
+
- **System Entities**: Users, Applications, Entities, Entity Fields, etc.
|
|
220
|
+
- **Security**: Roles, Authorizations, User Roles, Resource Permissions
|
|
221
|
+
- **Communication**: Conversations, Templates, Communication Providers
|
|
222
|
+
- **Workflow**: Actions, Action Categories, Scheduled Actions
|
|
223
|
+
- **AI/ML**: AI Models, AI Prompts, Vector Databases
|
|
224
|
+
- **Reporting**: Reports, Dashboards, Query Fields
|
|
225
|
+
- **Integration**: Company Integrations, API Configurations
|
|
226
|
+
- **And 170+ more...**
|
|
227
|
+
|
|
228
|
+
## Dependencies
|
|
229
|
+
|
|
230
|
+
- `@memberjunction/core`: Core MemberJunction functionality
|
|
231
|
+
- `@memberjunction/global`: Global utilities and decorators
|
|
232
|
+
- `zod`: Runtime type validation
|
|
233
|
+
|
|
234
|
+
## Version Compatibility
|
|
235
|
+
|
|
236
|
+
This package is released in sync with MemberJunction core releases. Always use matching versions:
|
|
237
|
+
|
|
238
|
+
```json
|
|
239
|
+
{
|
|
240
|
+
"dependencies": {
|
|
241
|
+
"@memberjunction/core": "2.43.0",
|
|
242
|
+
"@memberjunction/core-entities": "2.43.0",
|
|
243
|
+
"@memberjunction/global": "2.43.0"
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Best Practices
|
|
249
|
+
|
|
250
|
+
1. **Always use Metadata for entity creation**: Never instantiate entity classes directly
|
|
251
|
+
2. **Use RunView for bulk operations**: More efficient than loading entities individually
|
|
252
|
+
3. **Leverage TypeScript types**: Use the exported types for function parameters and return types
|
|
253
|
+
4. **Handle validation errors**: Always wrap entity operations in try-catch blocks
|
|
254
|
+
5. **Use extended classes**: When available, use the extended versions for additional functionality
|
|
255
|
+
|
|
256
|
+
## Contributing
|
|
257
|
+
|
|
258
|
+
This package is generated from MemberJunction metadata. To modify:
|
|
259
|
+
|
|
260
|
+
1. Update the source metadata in MemberJunction
|
|
261
|
+
2. Run the code generation process
|
|
262
|
+
3. Custom extensions can be added to the `/src/custom` directory
|
|
263
|
+
|
|
264
|
+
## License
|
|
265
|
+
|
|
266
|
+
ISC - See LICENSE file for details
|
|
267
|
+
|
|
268
|
+
## Support
|
|
269
|
+
|
|
270
|
+
For issues, questions, or contributions, please visit the [MemberJunction GitHub repository](https://github.com/MemberJunction/MJ).
|