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.
The @memberjunction/core-entities package contains:
npm install @memberjunction/core-entities
Every MemberJunction core entity has a corresponding TypeScript class with:
Several entities have custom extended classes that provide additional functionality:
A powerful metadata-driven system for extracting structured attributes from artifact content:
A sophisticated permission system for managing access to various resources:
import { Metadata } from '@memberjunction/core';
import { UserEntity, ApplicationEntity } from '@memberjunction/core-entities';
// Always use Metadata to create entity instances
const md = new Metadata();
// Load a user by ID
const user = await md.GetEntityObject<UserEntity>('Users');
await user.Load('user-id-here');
// Access strongly-typed properties
console.log(user.Email);
console.log(user.FirstName);
// Create a new application
const app = await md.GetEntityObject<ApplicationEntity>('Applications');
app.NewRecord();
app.Name = 'My New Application';
app.Description = 'A test application';
await app.Save();
(continuing in next command due to size...)
The artifact extraction system enables declarative extraction of structured attributes from artifact content with hierarchical inheritance.
Artifacts in MemberJunction can have extract rules defined in their ArtifactType that specify how to extract attributes from the artifact content. These rules:
ArtifactType.ExtractRules columnExtract rules are defined in the ArtifactType.ExtractRules JSON field:
[
{
"name": "subject",
"description": "Email subject line",
"type": "string",
"standardProperty": "name",
"extractor": "const parsed = JSON.parse(content); return parsed.subject || 'Untitled';"
},
{
"name": "recipientCount",
"description": "Number of recipients",
"type": "number",
"extractor": "const parsed = JSON.parse(content); return parsed.recipients?.length || 0;"
}
]
| Property | Type | Description |
|---|---|---|
name |
string | Unique identifier for this rule |
description |
string | Human-readable description |
type |
string | TypeScript type (e.g., 'string', 'Array<{x: number}>') |
standardProperty |
string? | Maps to: 'name', 'description', 'displayMarkdown', 'displayHtml' |
extractor |
string | JavaScript code that receives content and returns value |
import { ArtifactExtractor } from '@memberjunction/core-entities';
// Resolve extract rules with inheritance
const rules = ArtifactExtractor.ResolveExtractRules(artifactTypeChain);
// Extract attributes from content
const result = await ArtifactExtractor.ExtractAttributes({
content: artifactContent,
extractRules: rules,
throwOnError: false,
timeout: 5000
});
// Get standard properties
const name = ArtifactExtractor.GetStandardProperty(result.attributes, 'name');
const description = ArtifactExtractor.GetStandardProperty(result.attributes, 'description');
import { ArtifactVersionExtended } from '@memberjunction/core-entities';
import { Metadata } from '@memberjunction/core';
const md = new Metadata();
const version = await md.GetEntityObject<ArtifactVersionExtended>('MJ: Artifact Versions');
version.NewRecord();
version.Content = JSON.stringify({ subject: "Q4 Campaign", body: "..." });
// Save triggers automatic extraction:
// 1. Calculates SHA-256 hash → ContentHash
// 2. Resolves extract rules from ArtifactType hierarchy
// 3. Extracts attributes → Name and Description
// 4. Creates ArtifactVersionAttribute records
await version.Save();
console.log(version.Name); // "Q4 Campaign" (extracted)
console.log(version.ContentHash); // "a3f7e2..." (SHA-256)
For complete documentation, see the Implementation Summary.
@memberjunction/core: Core MemberJunction functionality@memberjunction/global: Global utilities and decoratorszod: Runtime type validationISC - See LICENSE file for details
For issues, questions, or contributions, visit the MemberJunction GitHub repository.