@memberjunction/templates 3.4.0 → 4.1.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 +116 -319
- package/dist/TemplateEngine.d.ts +1 -1
- package/dist/TemplateEngine.d.ts.map +1 -1
- package/dist/TemplateEngine.js +15 -40
- package/dist/TemplateEngine.js.map +1 -1
- package/dist/extensions/AIPrompt.extension.d.ts +1 -2
- package/dist/extensions/AIPrompt.extension.d.ts.map +1 -1
- package/dist/extensions/AIPrompt.extension.js +17 -24
- package/dist/extensions/AIPrompt.extension.js.map +1 -1
- package/dist/extensions/TemplateEmbed.extension.d.ts +1 -2
- package/dist/extensions/TemplateEmbed.extension.d.ts.map +1 -1
- package/dist/extensions/TemplateEmbed.extension.js +12 -19
- package/dist/extensions/TemplateEmbed.extension.js.map +1 -1
- package/dist/extensions/TemplateExtensionBase.js +1 -5
- package/dist/extensions/TemplateExtensionBase.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -26
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -1,17 +1,57 @@
|
|
|
1
1
|
# @memberjunction/templates
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Server-side template rendering engine for MemberJunction, built on Nunjucks. Extends `TemplateEngineBase` with rendering capabilities, custom filters, and MJ-specific extensions for AI prompt integration and recursive template embedding.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```mermaid
|
|
8
|
+
graph TD
|
|
9
|
+
subgraph "@memberjunction/templates"
|
|
10
|
+
A[TemplateEngineServer] --> B[Nunjucks Environment]
|
|
11
|
+
A --> C[Template Cache]
|
|
12
|
+
A --> D[TemplateEntityLoader]
|
|
13
|
+
B --> E[Custom Filters]
|
|
14
|
+
B --> F[Extensions]
|
|
15
|
+
F --> G[AIPrompt Extension]
|
|
16
|
+
F --> H[TemplateEmbed Extension]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
subgraph "Base Layer"
|
|
20
|
+
I["TemplateEngineBase<br/>(from base-types)"]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
A -->|extends| I
|
|
24
|
+
|
|
25
|
+
subgraph "Rendering"
|
|
26
|
+
J[Template Entity] --> K[Validation]
|
|
27
|
+
K --> L[Merge Defaults]
|
|
28
|
+
L --> M[Nunjucks Render]
|
|
29
|
+
M --> N[TemplateRenderResult]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
33
|
+
style B fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
34
|
+
style C fill:#7c5295,stroke:#563a6b,color:#fff
|
|
35
|
+
style G fill:#b8762f,stroke:#8a5722,color:#fff
|
|
36
|
+
style H fill:#b8762f,stroke:#8a5722,color:#fff
|
|
37
|
+
style I fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
38
|
+
style N fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
39
|
+
```
|
|
4
40
|
|
|
5
41
|
## Overview
|
|
6
42
|
|
|
7
|
-
This package
|
|
43
|
+
This package is the **server-side rendering engine** for MemberJunction templates. It is NOT used within Angular applications despite using Angular Universal internally for compilation.
|
|
44
|
+
|
|
45
|
+
**Key capabilities:**
|
|
8
46
|
|
|
9
|
-
- **Nunjucks
|
|
10
|
-
- **
|
|
11
|
-
- **
|
|
12
|
-
- **
|
|
13
|
-
- **
|
|
14
|
-
- **
|
|
47
|
+
- **Nunjucks Rendering**: Full Nunjucks template syntax with async support
|
|
48
|
+
- **Parameter Validation**: Validates input data against template parameter definitions before rendering
|
|
49
|
+
- **Default Value Merging**: Automatically applies parameter defaults with content-specific overrides
|
|
50
|
+
- **Template Caching**: Compiled Nunjucks templates are cached for performance
|
|
51
|
+
- **Custom Filters**: `json`, `jsoninline`, and `jsonparse` filters for JSON manipulation
|
|
52
|
+
- **Extensible**: Plugin system via `TemplateExtensionBase` for custom Nunjucks tags
|
|
53
|
+
- **AI Prompt Extension**: Execute AI prompts inline within templates
|
|
54
|
+
- **Template Embedding**: Recursively embed templates within other templates
|
|
15
55
|
|
|
16
56
|
## Installation
|
|
17
57
|
|
|
@@ -19,355 +59,112 @@ This package serves as the core templating engine for MemberJunction application
|
|
|
19
59
|
npm install @memberjunction/templates
|
|
20
60
|
```
|
|
21
61
|
|
|
22
|
-
## Key Features
|
|
23
|
-
|
|
24
|
-
### 1. Template Engine
|
|
25
|
-
|
|
26
|
-
- Manages template metadata and caching
|
|
27
|
-
- Provides both metadata-based and simple rendering APIs
|
|
28
|
-
- Integrates with MemberJunction's entity system
|
|
29
|
-
- Supports template validation and parameter checking
|
|
30
|
-
|
|
31
|
-
### 2. AI Prompt Extension
|
|
32
|
-
|
|
33
|
-
- Embeds AI-generated content directly in templates
|
|
34
|
-
- Supports multiple AI models (OpenAI, Groq, etc.)
|
|
35
|
-
- Configurable formatting options
|
|
36
|
-
- Seamless integration with MemberJunction's AI Engine
|
|
37
|
-
|
|
38
|
-
### 3. Template Embed Extension
|
|
39
|
-
|
|
40
|
-
- Recursive template inclusion with cycle detection
|
|
41
|
-
- Content type inheritance and fallbacks
|
|
42
|
-
- Data context passing and merging
|
|
43
|
-
- Error handling for missing templates
|
|
44
|
-
|
|
45
62
|
## Usage
|
|
46
63
|
|
|
47
|
-
###
|
|
64
|
+
### Rendering Templates
|
|
48
65
|
|
|
49
66
|
```typescript
|
|
50
67
|
import { TemplateEngineServer } from '@memberjunction/templates';
|
|
51
|
-
import { UserInfo } from '@memberjunction/core';
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
const engine = TemplateEngineServer.Instance;
|
|
70
|
+
await engine.Config(false, contextUser);
|
|
55
71
|
|
|
56
|
-
//
|
|
57
|
-
|
|
72
|
+
// Find and render a template
|
|
73
|
+
const template = engine.FindTemplate('Welcome Email');
|
|
74
|
+
const content = template.Content[0]; // First content variant
|
|
58
75
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'
|
|
62
|
-
|
|
63
|
-
);
|
|
76
|
+
const result = await engine.RenderTemplate(template, content, {
|
|
77
|
+
userName: 'John Doe',
|
|
78
|
+
companyName: 'Acme Corp'
|
|
79
|
+
});
|
|
64
80
|
|
|
65
81
|
if (result.Success) {
|
|
66
|
-
console.log(result.Output); //
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
### Rendering with Template Metadata
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { TemplateEngineServer } from '@memberjunction/templates';
|
|
74
|
-
import { TemplateContentEntity } from '@memberjunction/core-entities';
|
|
75
|
-
|
|
76
|
-
// Assume you have loaded a template entity and its content
|
|
77
|
-
const templateEntity = await templateEngine.GetTemplateByName('WelcomeEmail');
|
|
78
|
-
const templateContent = templateEntity.GetHighestPriorityContent();
|
|
79
|
-
|
|
80
|
-
// Render with validation
|
|
81
|
-
const result = await templateEngine.RenderTemplate(
|
|
82
|
-
templateEntity,
|
|
83
|
-
templateContent,
|
|
84
|
-
{
|
|
85
|
-
userName: 'John Doe',
|
|
86
|
-
accountType: 'Premium',
|
|
87
|
-
signupDate: new Date()
|
|
88
|
-
},
|
|
89
|
-
false // SkipValidation = false
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
if (!result.Success) {
|
|
93
|
-
console.error('Template rendering failed:', result.Message);
|
|
82
|
+
console.log(result.Output); // Rendered HTML/text
|
|
83
|
+
} else {
|
|
84
|
+
console.error(result.Message); // Validation or rendering error
|
|
94
85
|
}
|
|
95
86
|
```
|
|
96
87
|
|
|
97
|
-
###
|
|
98
|
-
|
|
99
|
-
```typescript
|
|
100
|
-
// In your template:
|
|
101
|
-
const templateText = `
|
|
102
|
-
Dear {{ userName }},
|
|
103
|
-
|
|
104
|
-
{% AIPrompt AIModel="gpt-4", AllowFormatting=false %}
|
|
105
|
-
Generate a personalized welcome message for a new {{ accountType }} customer
|
|
106
|
-
named {{ userName }} who just signed up for our service. Make it warm and
|
|
107
|
-
professional, highlighting the benefits of their account type.
|
|
108
|
-
{% endAIPrompt %}
|
|
109
|
-
|
|
110
|
-
Best regards,
|
|
111
|
-
The Team
|
|
112
|
-
`;
|
|
113
|
-
|
|
114
|
-
const result = await templateEngine.RenderTemplateSimple(templateText, {
|
|
115
|
-
userName: 'Sarah',
|
|
116
|
-
accountType: 'Enterprise'
|
|
117
|
-
});
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### Using the Template Embed Extension
|
|
121
|
-
|
|
122
|
-
```typescript
|
|
123
|
-
// Main template
|
|
124
|
-
const mainTemplate = `
|
|
125
|
-
{% template "Header", type="HTML" %}
|
|
126
|
-
|
|
127
|
-
<div class="content">
|
|
128
|
-
<h1>Welcome {{ user.name }}</h1>
|
|
129
|
-
{% template "UserProfile", data={showDetails: true} %}
|
|
130
|
-
</div>
|
|
131
|
-
|
|
132
|
-
{% template "Footer" %}
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
// The embedded templates will be loaded from the template metadata
|
|
136
|
-
// and rendered with the appropriate content type and data context
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
## API Reference
|
|
140
|
-
|
|
141
|
-
### TemplateEngineServer
|
|
142
|
-
|
|
143
|
-
The main template engine class that handles all template operations.
|
|
144
|
-
|
|
145
|
-
#### Methods
|
|
146
|
-
|
|
147
|
-
##### `Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>`
|
|
148
|
-
|
|
149
|
-
Configures the template engine and loads template metadata.
|
|
150
|
-
|
|
151
|
-
##### `RenderTemplate(templateEntity: TemplateEntityExtended, templateContent: TemplateContentEntity, data: any, SkipValidation?: boolean): Promise<TemplateRenderResult>`
|
|
152
|
-
|
|
153
|
-
Renders a template using metadata entities with optional validation.
|
|
154
|
-
|
|
155
|
-
##### `RenderTemplateSimple(templateText: string, data: any): Promise<TemplateRenderResult>`
|
|
156
|
-
|
|
157
|
-
Renders a template string without metadata integration.
|
|
158
|
-
|
|
159
|
-
##### `GetTemplateByName(templateName: string): TemplateEntityExtended | null`
|
|
160
|
-
|
|
161
|
-
Retrieves a template entity by its name.
|
|
162
|
-
|
|
163
|
-
##### `GetTemplateByID(templateID: string): TemplateEntityExtended | null`
|
|
164
|
-
|
|
165
|
-
Retrieves a template entity by its ID.
|
|
166
|
-
|
|
167
|
-
##### `ClearTemplateCache(): void`
|
|
168
|
-
|
|
169
|
-
Clears the internal template cache.
|
|
88
|
+
### Simple Template Rendering
|
|
170
89
|
|
|
171
|
-
|
|
90
|
+
For ad-hoc templates not stored in the database:
|
|
172
91
|
|
|
173
92
|
```typescript
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Built-in Filters
|
|
182
|
-
|
|
183
|
-
The template engine provides several filters for handling complex objects and JSON data:
|
|
184
|
-
|
|
185
|
-
#### `dump` (Nunjucks built-in)
|
|
186
|
-
Converts any JavaScript object to a formatted JSON string.
|
|
187
|
-
|
|
188
|
-
```nunjucks
|
|
189
|
-
{{ myObject | dump }} <!-- Pretty-printed with 2 spaces -->
|
|
190
|
-
{{ myObject | dump(4) }} <!-- Pretty-printed with 4 spaces -->
|
|
191
|
-
{{ myObject | dump(0) }} <!-- Compact single-line format -->
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
#### `json` (Custom filter)
|
|
195
|
-
Similar to `dump` but with better error handling. Converts objects to JSON strings.
|
|
196
|
-
|
|
197
|
-
```nunjucks
|
|
198
|
-
{{ userData | json }} <!-- Pretty-printed with 2 spaces (default) -->
|
|
199
|
-
{{ userData | json(4) }} <!-- Pretty-printed with 4 spaces -->
|
|
200
|
-
{{ userData | json(0) }} <!-- Compact format -->
|
|
93
|
+
const result = await engine.RenderTemplateSimple(
|
|
94
|
+
'Hello {{ name }}, welcome to {{ company }}!',
|
|
95
|
+
{ name: 'Jane', company: 'MemberJunction' }
|
|
96
|
+
);
|
|
97
|
+
// result.Output: "Hello Jane, welcome to MemberJunction!"
|
|
201
98
|
```
|
|
202
99
|
|
|
203
|
-
|
|
100
|
+
### Custom Nunjucks Filters
|
|
204
101
|
|
|
205
|
-
|
|
206
|
-
Converts objects to compact JSON strings (no formatting).
|
|
102
|
+
The engine provides built-in filters for JSON operations:
|
|
207
103
|
|
|
208
104
|
```nunjucks
|
|
209
|
-
{
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
#### `jsonparse` (Custom filter)
|
|
213
|
-
Parses JSON strings into JavaScript objects. Useful for processing JSON data stored as strings.
|
|
214
|
-
|
|
215
|
-
```nunjucks
|
|
216
|
-
{{ '{"name":"John","age":30}' | jsonparse | json }}
|
|
217
|
-
<!-- First parses the string to object, then formats it -->
|
|
218
|
-
|
|
219
|
-
<!-- Access parsed object properties -->
|
|
220
|
-
{{ '{"name":"John","age":30}' | jsonparse | attr("name") }}
|
|
221
|
-
<!-- Output: John -->
|
|
222
|
-
```
|
|
105
|
+
{# Convert object to formatted JSON #}
|
|
106
|
+
{{ userData | json }}
|
|
223
107
|
|
|
224
|
-
|
|
108
|
+
{# Compact JSON output #}
|
|
109
|
+
{{ userData | jsoninline }}
|
|
225
110
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
```nunjucks
|
|
229
|
-
<!-- Problem: Shows [object Object] -->
|
|
230
|
-
<div>User Data: {{ userData }}</div>
|
|
231
|
-
|
|
232
|
-
<!-- Solutions: Use filters to display JSON -->
|
|
233
|
-
<div>User Data: {{ userData | dump }}</div>
|
|
234
|
-
<div>User Data: {{ userData | json }}</div>
|
|
235
|
-
<pre>{{ userData | json(2) }}</pre>
|
|
236
|
-
|
|
237
|
-
<!-- For debugging: Compact format -->
|
|
238
|
-
<script>
|
|
239
|
-
const data = {{ userData | jsoninline | safe }};
|
|
240
|
-
</script>
|
|
111
|
+
{# Parse a JSON string back to object #}
|
|
112
|
+
{% set parsed = jsonString | jsonparse %}
|
|
241
113
|
```
|
|
242
114
|
|
|
243
|
-
|
|
115
|
+
### Template Extensions
|
|
244
116
|
|
|
245
|
-
|
|
246
|
-
<!-- Parse a JSON string, then format it nicely -->
|
|
247
|
-
{{ jsonString | jsonparse | json(4) }}
|
|
117
|
+
Extensions are registered via the MJ class factory:
|
|
248
118
|
|
|
249
|
-
|
|
250
|
-
|
|
119
|
+
```mermaid
|
|
120
|
+
graph LR
|
|
121
|
+
A[TemplateExtensionBase] --> B[AIPrompt Extension]
|
|
122
|
+
A --> C[TemplateEmbed Extension]
|
|
123
|
+
A --> D[Custom Extensions]
|
|
251
124
|
|
|
252
|
-
|
|
253
|
-
|
|
125
|
+
style A fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
126
|
+
style B fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
127
|
+
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
128
|
+
style D fill:#7c5295,stroke:#563a6b,color:#fff
|
|
254
129
|
```
|
|
255
130
|
|
|
256
|
-
|
|
131
|
+
- **AIPrompt Extension**: Executes AI prompts inline within templates using `{% aiprompt %}` tags
|
|
132
|
+
- **TemplateEmbed Extension**: Embeds other templates within a template using `{% templateembed %}` tags
|
|
257
133
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
- `AIModel` (optional): Specific AI model to use (e.g., "gpt-4", "claude-3")
|
|
261
|
-
- `AllowFormatting` (optional): Whether to allow formatted output (HTML, Markdown, etc.)
|
|
262
|
-
|
|
263
|
-
#### Template Embed Extension Parameters
|
|
134
|
+
## API Reference
|
|
264
135
|
|
|
265
|
-
|
|
266
|
-
- `type` (optional): Specific content type to use
|
|
267
|
-
- `data` (optional): Additional data to pass to the embedded template
|
|
136
|
+
### TemplateEngineServer
|
|
268
137
|
|
|
269
|
-
|
|
138
|
+
| Member | Type | Description |
|
|
139
|
+
|--------|------|-------------|
|
|
140
|
+
| `Instance` | static getter | Singleton instance |
|
|
141
|
+
| `Config()` | method | Load metadata and initialize Nunjucks environment |
|
|
142
|
+
| `RenderTemplate()` | method | Render a stored template with validation |
|
|
143
|
+
| `RenderTemplateSimple()` | method | Render an ad-hoc template string |
|
|
144
|
+
| `AddTemplate()` | method | Add a template to the Nunjucks loader |
|
|
145
|
+
| `SetupNunjucks()` | method | Re-initialize the Nunjucks environment |
|
|
146
|
+
| `ClearTemplateCache()` | method | Clear cached compiled templates |
|
|
270
147
|
|
|
271
|
-
|
|
148
|
+
### Rendering Process
|
|
272
149
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
constructor(contextUser: UserInfo) {
|
|
279
|
-
super(contextUser);
|
|
280
|
-
this.tags = ['myTag'];
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
public parse(parser: Parser, nodes: Nodes, lexer: Lexer) {
|
|
284
|
-
const tok = parser.nextToken();
|
|
285
|
-
const params = parser.parseSignature(null, true);
|
|
286
|
-
parser.advanceAfterBlockEnd(tok.value);
|
|
287
|
-
|
|
288
|
-
const body = parser.parseUntilBlocks('endMyTag');
|
|
289
|
-
parser.advanceAfterBlockEnd();
|
|
290
|
-
|
|
291
|
-
return new nodes.CallExtensionAsync(this, 'run', params, [body]);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
public run(context: Context, params: any, body: any, callBack: NunjucksCallback) {
|
|
295
|
-
// Your extension logic here
|
|
296
|
-
try {
|
|
297
|
-
const content = body();
|
|
298
|
-
// Process content...
|
|
299
|
-
callBack(null, processedContent);
|
|
300
|
-
} catch (error) {
|
|
301
|
-
callBack(error);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
```
|
|
150
|
+
1. **Validation**: Input data is validated against template parameter definitions
|
|
151
|
+
2. **Default Merging**: Missing parameters receive default values (content-specific defaults override global defaults)
|
|
152
|
+
3. **Compilation**: Template text is compiled by Nunjucks (cached after first compile)
|
|
153
|
+
4. **Rendering**: Nunjucks processes the template with merged data
|
|
154
|
+
5. **Result**: Returns `TemplateRenderResult` with `Success`, `Output`, and optional `Message`
|
|
306
155
|
|
|
307
156
|
## Dependencies
|
|
308
157
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
-
|
|
317
|
-
|
|
318
|
-
## Integration with MemberJunction
|
|
319
|
-
|
|
320
|
-
This package integrates seamlessly with other MemberJunction packages:
|
|
321
|
-
|
|
322
|
-
- **Entity System**: Templates are stored as entities with full metadata support
|
|
323
|
-
- **AI Engine**: Direct integration for AI-powered content generation
|
|
324
|
-
- **User Context**: Templates respect user permissions and context
|
|
325
|
-
- **Metadata Provider**: Flexible metadata loading strategies
|
|
326
|
-
|
|
327
|
-
## Configuration
|
|
328
|
-
|
|
329
|
-
The template engine uses the MemberJunction configuration system. Key configuration options:
|
|
330
|
-
|
|
331
|
-
- Template caching strategies
|
|
332
|
-
- Default AI models for prompts
|
|
333
|
-
- Extension registration
|
|
334
|
-
- Nunjucks environment settings
|
|
335
|
-
|
|
336
|
-
## Performance Considerations
|
|
337
|
-
|
|
338
|
-
- Templates are cached after first compilation
|
|
339
|
-
- Use `ClearTemplateCache()` when templates are updated
|
|
340
|
-
- AI prompts are processed asynchronously
|
|
341
|
-
- Template embedding includes cycle detection
|
|
342
|
-
|
|
343
|
-
## Error Handling
|
|
344
|
-
|
|
345
|
-
All rendering methods return a `TemplateRenderResult` object:
|
|
346
|
-
|
|
347
|
-
```typescript
|
|
348
|
-
const result = await templateEngine.RenderTemplateSimple(template, data);
|
|
349
|
-
|
|
350
|
-
if (!result.Success) {
|
|
351
|
-
console.error('Rendering failed:', result.Message);
|
|
352
|
-
// Handle error appropriately
|
|
353
|
-
} else {
|
|
354
|
-
// Use result.Output
|
|
355
|
-
}
|
|
356
|
-
```
|
|
357
|
-
|
|
358
|
-
## Best Practices
|
|
359
|
-
|
|
360
|
-
1. **Always check rendering results** for success before using output
|
|
361
|
-
2. **Configure the engine once** at application startup
|
|
362
|
-
3. **Use template validation** for user-provided data
|
|
363
|
-
4. **Clear cache** when templates are modified
|
|
364
|
-
5. **Handle AI failures gracefully** with fallback content
|
|
365
|
-
6. **Avoid deep template nesting** to prevent performance issues
|
|
158
|
+
| Package | Purpose |
|
|
159
|
+
|---------|---------|
|
|
160
|
+
| `@memberjunction/templates-base-types` | Base engine and result types |
|
|
161
|
+
| `@memberjunction/core` | UserInfo, logging utilities |
|
|
162
|
+
| `@memberjunction/core-entities` | Template entity types |
|
|
163
|
+
| `@memberjunction/global` | Class factory for extensions |
|
|
164
|
+
| `@memberjunction/ai` | AI integration for prompts |
|
|
165
|
+
| `@memberjunction/ai-core-plus` | AI core utilities |
|
|
166
|
+
| `nunjucks` | Template rendering engine |
|
|
366
167
|
|
|
367
168
|
## License
|
|
368
169
|
|
|
369
|
-
ISC
|
|
370
|
-
|
|
371
|
-
## Support
|
|
372
|
-
|
|
373
|
-
For issues, questions, or contributions, please visit [MemberJunction.com](https://memberjunction.com) or contact the development team.
|
|
170
|
+
ISC
|
package/dist/TemplateEngine.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IMetadataProvider, UserInfo } from "@memberjunction/core";
|
|
2
2
|
import { TemplateContentEntity, TemplateEntityExtended } from "@memberjunction/core-entities";
|
|
3
|
-
import
|
|
3
|
+
import nunjucks from 'nunjucks';
|
|
4
4
|
import { TemplateRenderResult, TemplateEngineBase } from '@memberjunction/templates-base-types';
|
|
5
5
|
/**
|
|
6
6
|
* This class extends the nunjucks loader to allow adding templates directly to the loader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAY,QAAQ,EAAuB,MAAM,sBAAsB,CAAC;AAClG,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAuB,MAAM,+BAA+B,CAAC;AACnH,OAAO,
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,eAAe,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoD/K;;;;;;;OAOG;IACU,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAoBjG;;;;;;OAMG;IACH,SAAS,CAAC,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,GAAG;IAgB3G;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,GAAG;IAIpD,kBAAkB;IAIzB;;;;OAIG;cACa,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAY5F;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,kBAAkB,CAAC,cAAc,EAAE,sBAAsB,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,GAAG;CAuD1G"}
|
package/dist/TemplateEngine.js
CHANGED
|
@@ -1,38 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TemplateEngineServer = exports.TemplateEntityLoader = void 0;
|
|
27
|
-
const core_1 = require("@memberjunction/core");
|
|
28
|
-
const nunjucks = __importStar(require("nunjucks"));
|
|
29
|
-
const global_1 = require("@memberjunction/global");
|
|
30
|
-
const TemplateExtensionBase_1 = require("./extensions/TemplateExtensionBase");
|
|
31
|
-
const templates_base_types_1 = require("@memberjunction/templates-base-types");
|
|
1
|
+
import { LogError } from "@memberjunction/core";
|
|
2
|
+
import nunjucks from 'nunjucks';
|
|
3
|
+
import { MJGlobal } from "@memberjunction/global";
|
|
4
|
+
import { TemplateExtensionBase } from "./extensions/TemplateExtensionBase.js";
|
|
5
|
+
import { TemplateEngineBase } from '@memberjunction/templates-base-types';
|
|
32
6
|
/**
|
|
33
7
|
* This class extends the nunjucks loader to allow adding templates directly to the loader
|
|
34
8
|
*/
|
|
35
|
-
class TemplateEntityLoader extends nunjucks.Loader {
|
|
9
|
+
export class TemplateEntityLoader extends nunjucks.Loader {
|
|
36
10
|
constructor() {
|
|
37
11
|
super(...arguments);
|
|
38
12
|
this.templates = {};
|
|
@@ -62,11 +36,10 @@ class TemplateEntityLoader extends nunjucks.Loader {
|
|
|
62
36
|
}
|
|
63
37
|
}
|
|
64
38
|
}
|
|
65
|
-
exports.TemplateEntityLoader = TemplateEntityLoader;
|
|
66
39
|
/**
|
|
67
40
|
* TemplateEngine is used for accessing template metadata/caching it, and rendering templates
|
|
68
41
|
*/
|
|
69
|
-
class TemplateEngineServer extends
|
|
42
|
+
export class TemplateEngineServer extends TemplateEngineBase {
|
|
70
43
|
constructor() {
|
|
71
44
|
super(...arguments);
|
|
72
45
|
this._oneTimeLoadingComplete = false;
|
|
@@ -97,11 +70,14 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
97
70
|
// Add custom filters
|
|
98
71
|
this.addCustomFilters();
|
|
99
72
|
// get all of the extensions that are registered and register them with nunjucks
|
|
100
|
-
const extensions =
|
|
73
|
+
const extensions = MJGlobal.Instance.ClassFactory.GetAllRegistrations(TemplateExtensionBase);
|
|
101
74
|
if (extensions && extensions.length > 0) {
|
|
102
75
|
for (const ext of extensions) {
|
|
103
|
-
const
|
|
104
|
-
|
|
76
|
+
const SubClassConstructor = ext.SubClass;
|
|
77
|
+
const instance = new SubClassConstructor(contextUser);
|
|
78
|
+
if (ext.Key) {
|
|
79
|
+
this._nunjucksEnv.addExtension(ext.Key, instance);
|
|
80
|
+
}
|
|
105
81
|
}
|
|
106
82
|
}
|
|
107
83
|
}
|
|
@@ -220,7 +196,7 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
220
196
|
};
|
|
221
197
|
}
|
|
222
198
|
catch (e) {
|
|
223
|
-
|
|
199
|
+
LogError(e);
|
|
224
200
|
return {
|
|
225
201
|
Success: false,
|
|
226
202
|
Output: null,
|
|
@@ -336,12 +312,11 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
336
312
|
}
|
|
337
313
|
catch (error) {
|
|
338
314
|
// Log warning but continue - don't fail the entire render
|
|
339
|
-
|
|
315
|
+
LogError(`Failed to apply default value for parameter '${name}': ${error.message}`);
|
|
340
316
|
}
|
|
341
317
|
}
|
|
342
318
|
});
|
|
343
319
|
return mergedData;
|
|
344
320
|
}
|
|
345
321
|
}
|
|
346
|
-
exports.TemplateEngineServer = TemplateEngineServer;
|
|
347
322
|
//# sourceMappingURL=TemplateEngine.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.js","sourceRoot":"","sources":["../src/Template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I,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC;4BACtC,MAAM;oBACd,CAAC;gBACL,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,0DAA0D;oBAC1D,QAAQ,CAAC,gDAAgD,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBACxF,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserInfo } from "@memberjunction/core";
|
|
2
|
-
import { NunjucksCallback, TemplateExtensionBase } from "./TemplateExtensionBase";
|
|
2
|
+
import { NunjucksCallback, TemplateExtensionBase } from "./TemplateExtensionBase.js";
|
|
3
3
|
import { AIModelEntityExtended } from "@memberjunction/ai-core-plus";
|
|
4
4
|
type Parser = any;
|
|
5
5
|
type Nodes = any;
|
|
@@ -59,6 +59,5 @@ export type AIPromptConfig = {
|
|
|
59
59
|
*/
|
|
60
60
|
AllowFormatting?: boolean;
|
|
61
61
|
};
|
|
62
|
-
export declare function LoadAIPromptExtension(): void;
|
|
63
62
|
export {};
|
|
64
63
|
//# sourceMappingURL=AIPrompt.extension.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIPrompt.extension.d.ts","sourceRoot":"","sources":["../../src/extensions/AIPrompt.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGlF,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,KAAK,MAAM,GAAG,GAAG,CAAC;AAClB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,OAAO,GAAG,GAAG,CAAC;AAEnB;;GAEG;AACH,qBACa,iBAAk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EAAE,KAAK;IAkCvD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACI,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB;IAiF/E;;;OAGG;IACH,SAAS,KAAK,mBAAmB,IAAI,MAAM,CAE1C;IAED;;;OAGG;cACa,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAQxG;AAED,MAAM,MAAM,cAAc,GAAG;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,17 +7,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const aiengine_1 = require("@memberjunction/aiengine");
|
|
17
|
-
const ai_1 = require("@memberjunction/ai");
|
|
10
|
+
import { LogError, UserInfo } from "@memberjunction/core";
|
|
11
|
+
import { MJGlobal, RegisterClass } from "@memberjunction/global";
|
|
12
|
+
import { TemplateExtensionBase } from "./TemplateExtensionBase.js";
|
|
13
|
+
import { AIEngine } from "@memberjunction/aiengine";
|
|
14
|
+
import { BaseLLM, GetAIAPIKey } from "@memberjunction/ai";
|
|
18
15
|
/**
|
|
19
16
|
* This class is an extension for the Nunjucks template engine that allows for the use of an AI prompt in a template.
|
|
20
17
|
*/
|
|
21
|
-
let AIPromptExtension = class AIPromptExtension extends
|
|
18
|
+
let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase {
|
|
22
19
|
constructor(contextUser) {
|
|
23
20
|
super(contextUser);
|
|
24
21
|
this.AllowFormattingText = "Do not use markdown, HTML, or any other special formatting.";
|
|
@@ -106,23 +103,23 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
106
103
|
// so instead we will use the callback pattern
|
|
107
104
|
// we will get the highest power model from the AI Engine
|
|
108
105
|
// then we will create an instance of the LLM class
|
|
109
|
-
|
|
106
|
+
AIEngine.Instance.Config(false, this.ContextUser).then(async () => {
|
|
110
107
|
try {
|
|
111
108
|
let model = null;
|
|
112
109
|
if (config.AIModel) {
|
|
113
|
-
model =
|
|
110
|
+
model = AIEngine.Instance.Models.find(m => m.Name.toLowerCase() === config.AIModel.toLowerCase() ||
|
|
114
111
|
m.APIName?.toLowerCase() === config.AIModel.toLowerCase());
|
|
115
112
|
if (!model) {
|
|
116
113
|
throw new Error(`AI model '${config.AIModel}' not found.`);
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
else {
|
|
120
|
-
model = await
|
|
117
|
+
model = await AIEngine.Instance.GetHighestPowerModel('Groq', 'llm', this.ContextUser);
|
|
121
118
|
if (!model) {
|
|
122
119
|
throw new Error(`No AI model found for the vendor 'Groq' and type 'llm'.`);
|
|
123
120
|
}
|
|
124
121
|
}
|
|
125
|
-
const llm =
|
|
122
|
+
const llm = MJGlobal.Instance.ClassFactory.CreateInstance(BaseLLM, model.DriverClass, GetAIAPIKey(model.DriverClass));
|
|
126
123
|
const llmResult = await llm.ChatCompletion({
|
|
127
124
|
messages: [
|
|
128
125
|
{
|
|
@@ -145,7 +142,7 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
145
142
|
}
|
|
146
143
|
}
|
|
147
144
|
catch (e) {
|
|
148
|
-
|
|
145
|
+
LogError(e);
|
|
149
146
|
callBack(null, e);
|
|
150
147
|
}
|
|
151
148
|
});
|
|
@@ -162,19 +159,19 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
162
159
|
* @returns
|
|
163
160
|
*/
|
|
164
161
|
async GetAIModel(vendorName, contextUser) {
|
|
165
|
-
await
|
|
166
|
-
const models =
|
|
162
|
+
await AIEngine.Instance.Config(false, contextUser); // most of the time this is already loaded, but just in case it isn't we will load it here
|
|
163
|
+
const models = AIEngine.Instance.Models.filter(m => m.AIModelType.trim().toLowerCase() === 'llm' &&
|
|
167
164
|
m.Vendor.trim().toLowerCase() === vendorName.trim().toLowerCase());
|
|
168
165
|
// next, sort the models by the PowerRank field so that the highest power rank model is the first array element
|
|
169
166
|
models.sort((a, b) => b.PowerRank - a.PowerRank); // highest power rank first
|
|
170
167
|
return models[0];
|
|
171
168
|
}
|
|
172
169
|
};
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
(
|
|
176
|
-
__metadata("design:paramtypes", [core_1.UserInfo])
|
|
170
|
+
AIPromptExtension = __decorate([
|
|
171
|
+
RegisterClass(TemplateExtensionBase, 'AIPrompt'),
|
|
172
|
+
__metadata("design:paramtypes", [UserInfo])
|
|
177
173
|
], AIPromptExtension);
|
|
174
|
+
export { AIPromptExtension };
|
|
178
175
|
// function AIPromptExtension() {
|
|
179
176
|
// this.tags = ['AIPrompt'];
|
|
180
177
|
// this.parse = function(parser, nodes, lexer) {
|
|
@@ -258,8 +255,4 @@ exports.AIPromptExtension = AIPromptExtension = __decorate([
|
|
|
258
255
|
// models.sort((a, b) => b.PowerRank - a.PowerRank); // highest power rank first
|
|
259
256
|
// return models[0];
|
|
260
257
|
// }
|
|
261
|
-
function LoadAIPromptExtension() {
|
|
262
|
-
// does nothing just to ensure the extension class isn't tree-shaken
|
|
263
|
-
}
|
|
264
|
-
exports.LoadAIPromptExtension = LoadAIPromptExtension;
|
|
265
258
|
//# sourceMappingURL=AIPrompt.extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIPrompt.extension.js","sourceRoot":"","sources":["../../src/extensions/AIPrompt.extension.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AIPrompt.extension.js","sourceRoot":"","sources":["../../src/extensions/AIPrompt.extension.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAiB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAoB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAQ1D;;GAEG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,qBAAqB;IAIxD,YAAY,WAAqB;QAC7B,KAAK,CAAC,WAAW,CAAC,CAAC;QAHvB,wBAAmB,GAAW,6DAA6D,CAAA;QAIvF,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,MAAc,EAAE,KAAY,EAAE,KAAY;QACnD,oBAAoB;QACpB,IAAI,GAAG,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAE7B,4DAA4D;QAC5D,4DAA4D;QAC5D,IAAI,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/C,MAAM,CAAC,oBAAoB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEvC,iEAAiE;QACjE,IAAI,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,OAAO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AkF;AAClF,yDAAyD;AACzD,oEAAoE;AACpE,8DAA8D;AAC9D,iFAAiF;AACjF,oBAAoB;AACpB,+GAA+G;AAC/G,iJAAiJ;AACjJ,+DAA+D;AAC/D,kCAAkC;AAClC,4BAA4B;AAC5B,8CAA8C;AAC9C,4KAA4K;AAC5K,sKAAsK;AACtK,8KAA8K;AAC9K,0JAA0J;AAC1J,6BAA6B;AAC7B,4BAA4B;AAC5B,4CAA4C;AAC5C,oDAAoD;AACpD,4BAA4B;AAC5B,yBAAyB;AACzB,iDAAiD;AACjD,qBAAqB;AACrB,wDAAwD;AACxD,iFAAiF;AACjF,oBAAoB;AACpB,gBAAgB;AAChB,0BAA0B;AAC1B,+BAA+B;AAC/B,gBAAgB;AAChB,cAAc;AACd,SAAS;AACT,IAAI;AAIJ,MAAM;AACN,6HAA6H;AAC7H,eAAe;AACf,MAAM;AACN,oCAAoC;AACpC,uBAAuB;AACvB,IAAI;AAEJ,MAAM;AACN,2FAA2F;AAC3F,eAAe;AACf,MAAM;AACN,yGAAyG;AACzG,6IAA6I;AAC7I,kGAAkG;AAClG,uHAAuH;AACvH,sHAAsH;AACtH,oFAAoF;AACpF,wBAAwB;AACxB,IAAI"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UserInfo } from "@memberjunction/core";
|
|
2
|
-
import { NunjucksCallback, TemplateExtensionBase } from "./TemplateExtensionBase";
|
|
2
|
+
import { NunjucksCallback, TemplateExtensionBase } from "./TemplateExtensionBase.js";
|
|
3
3
|
type Parser = any;
|
|
4
4
|
type Nodes = any;
|
|
5
5
|
type Lexer = any;
|
|
@@ -81,6 +81,5 @@ export declare class TemplateEmbedExtension extends TemplateExtensionBase {
|
|
|
81
81
|
*/
|
|
82
82
|
private renderEmbeddedTemplate;
|
|
83
83
|
}
|
|
84
|
-
export declare function LoadTemplateEmbedExtension(): void;
|
|
85
84
|
export {};
|
|
86
85
|
//# sourceMappingURL=TemplateEmbed.extension.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEmbed.extension.d.ts","sourceRoot":"","sources":["../../src/extensions/TemplateEmbed.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKlF,KAAK,MAAM,GAAG,GAAG,CAAC;AAClB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,OAAO,GAAG,GAAG,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;CACd,CAAC;AAiBF;;;;;;;;;;;;;;GAcG;AACH,qBACa,sBAAuB,SAAQ,qBAAqB;gBAEjD,WAAW,EAAE,QAAQ;IAK1B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAavD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB;IAyHlE;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAwB1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;YACW,sBAAsB;CAUvC
|
|
1
|
+
{"version":3,"file":"TemplateEmbed.extension.d.ts","sourceRoot":"","sources":["../../src/extensions/TemplateEmbed.extension.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAKlF,KAAK,MAAM,GAAG,GAAG,CAAC;AAClB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,OAAO,GAAG,GAAG,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,IAAI,CAAC,EAAE,GAAG,CAAC;CACd,CAAC;AAiBF;;;;;;;;;;;;;;GAcG;AACH,qBACa,sBAAuB,SAAQ,qBAAqB;gBAEjD,WAAW,EAAE,QAAQ;IAK1B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK;IAavD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACI,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,gBAAgB;IAyHlE;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAwB1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;YACW,sBAAsB;CAUvC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -8,12 +7,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const TemplateExtensionBase_1 = require("./TemplateExtensionBase");
|
|
16
|
-
const TemplateEngine_1 = require("../TemplateEngine");
|
|
10
|
+
import { LogError, UserInfo } from "@memberjunction/core";
|
|
11
|
+
import { RegisterClass } from "@memberjunction/global";
|
|
12
|
+
import { TemplateExtensionBase } from "./TemplateExtensionBase.js";
|
|
13
|
+
import { TemplateEngineServer } from '../TemplateEngine.js';
|
|
17
14
|
/**
|
|
18
15
|
* Extension that enables recursive template embedding using {% template "TemplateName" %} syntax.
|
|
19
16
|
*
|
|
@@ -29,7 +26,7 @@ const TemplateEngine_1 = require("../TemplateEngine");
|
|
|
29
26
|
* {% template "TemplateName", data={extra: "value"} %}
|
|
30
27
|
* {% template "TemplateName", type="PlainText", data={key: "value"} %}
|
|
31
28
|
*/
|
|
32
|
-
let TemplateEmbedExtension = class TemplateEmbedExtension extends
|
|
29
|
+
let TemplateEmbedExtension = class TemplateEmbedExtension extends TemplateExtensionBase {
|
|
33
30
|
constructor(contextUser) {
|
|
34
31
|
super(contextUser);
|
|
35
32
|
this.tags = ['template'];
|
|
@@ -120,7 +117,7 @@ let TemplateEmbedExtension = class TemplateEmbedExtension extends TemplateExtens
|
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
// Get the template engine instance
|
|
123
|
-
const templateEngine =
|
|
120
|
+
const templateEngine = TemplateEngineServer.Instance;
|
|
124
121
|
// Initialize render context for cycle detection
|
|
125
122
|
let renderContext = context.ctx._mjRenderContext;
|
|
126
123
|
if (!renderContext) {
|
|
@@ -164,12 +161,12 @@ let TemplateEmbedExtension = class TemplateEmbedExtension extends TemplateExtens
|
|
|
164
161
|
// Remove template from stack on error as well
|
|
165
162
|
renderContext.templateStack.pop();
|
|
166
163
|
renderContext.currentContentType = originalContentType;
|
|
167
|
-
|
|
164
|
+
LogError(error);
|
|
168
165
|
callBack(error);
|
|
169
166
|
});
|
|
170
167
|
}
|
|
171
168
|
catch (error) {
|
|
172
|
-
|
|
169
|
+
LogError(error);
|
|
173
170
|
callBack(error);
|
|
174
171
|
}
|
|
175
172
|
}
|
|
@@ -236,13 +233,9 @@ let TemplateEmbedExtension = class TemplateEmbedExtension extends TemplateExtens
|
|
|
236
233
|
return result.Output;
|
|
237
234
|
}
|
|
238
235
|
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
(
|
|
242
|
-
__metadata("design:paramtypes", [core_1.UserInfo])
|
|
236
|
+
TemplateEmbedExtension = __decorate([
|
|
237
|
+
RegisterClass(TemplateExtensionBase, 'TemplateEmbed'),
|
|
238
|
+
__metadata("design:paramtypes", [UserInfo])
|
|
243
239
|
], TemplateEmbedExtension);
|
|
244
|
-
|
|
245
|
-
// This function ensures the extension class isn't tree-shaken
|
|
246
|
-
}
|
|
247
|
-
exports.LoadTemplateEmbedExtension = LoadTemplateEmbedExtension;
|
|
240
|
+
export { TemplateEmbedExtension };
|
|
248
241
|
//# sourceMappingURL=TemplateEmbed.extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEmbed.extension.js","sourceRoot":"","sources":["../../src/extensions/TemplateEmbed.extension.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TemplateEmbed.extension.js","sourceRoot":"","sources":["../../src/extensions/TemplateEmbed.extension.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAoB,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAElF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAuCzD;;;;;;;;;;;;;;GAcG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,qBAAqB;IAE7D,YAAY,WAAqB;QAC7B,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,CAAC,UAA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,CAAC;CACJ,CAAA;AA3OY,sBAAsB;IADlC,aAAa,CAAC,qBAAqB,EAAE,eAAe,CAAC;qCAGzB,QAAQ;GAFxB,sBAAsB,CA2OlC"}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TemplateExtensionBase = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Used for extending the functionality of the template engine (Nunjucks). Sub-class this class to create a new template extension.
|
|
6
3
|
*/
|
|
7
|
-
class TemplateExtensionBase {
|
|
4
|
+
export class TemplateExtensionBase {
|
|
8
5
|
get ContextUser() {
|
|
9
6
|
return this._contextUser;
|
|
10
7
|
}
|
|
@@ -16,5 +13,4 @@ class TemplateExtensionBase {
|
|
|
16
13
|
this._contextUser = contextUser;
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
|
-
exports.TemplateExtensionBase = TemplateExtensionBase;
|
|
20
16
|
//# sourceMappingURL=TemplateExtensionBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateExtensionBase.js","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TemplateExtensionBase.js","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,MAAM,OAAgB,qBAAqB;IAMvC,IAAW,WAAW;QAClB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAGD,YAAY,WAAqB;QAVjC;;WAEG;QACI,SAAI,GAAa,EAAE,CAAC;QAQvB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IACpC,CAAC;CA4BJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './TemplateEngine';
|
|
2
|
-
export * from './extensions/AIPrompt.extension';
|
|
3
|
-
export * from './extensions/TemplateEmbed.extension';
|
|
4
|
-
export * from './extensions/TemplateExtensionBase';
|
|
1
|
+
export * from './TemplateEngine.js';
|
|
2
|
+
export * from './extensions/AIPrompt.extension.js';
|
|
3
|
+
export * from './extensions/TemplateEmbed.extension.js';
|
|
4
|
+
export * from './extensions/TemplateExtensionBase.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const TemplateEmbed_extension_1 = require("./extensions/TemplateEmbed.extension");
|
|
18
|
-
const AIPrompt_extension_1 = require("./extensions/AIPrompt.extension");
|
|
19
|
-
const ai_provider_bundle_1 = require("@memberjunction/ai-provider-bundle");
|
|
20
|
-
(0, TemplateEmbed_extension_1.LoadTemplateEmbedExtension)(); // make sure it doesnt get tree shaken out, we need template embedding
|
|
21
|
-
(0, AIPrompt_extension_1.LoadAIPromptExtension)(); // make sure it doesnt get tree shaken out, we need AI prompts
|
|
22
|
-
(0, ai_provider_bundle_1.LoadAIProviders)(); // Ensure all AI providers are loaded
|
|
23
|
-
__exportStar(require("./TemplateEngine"), exports);
|
|
24
|
-
__exportStar(require("./extensions/AIPrompt.extension"), exports);
|
|
25
|
-
__exportStar(require("./extensions/TemplateEmbed.extension"), exports);
|
|
26
|
-
__exportStar(require("./extensions/TemplateExtensionBase"), exports);
|
|
1
|
+
export * from './TemplateEngine.js';
|
|
2
|
+
export * from './extensions/AIPrompt.extension.js';
|
|
3
|
+
export * from './extensions/TemplateEmbed.extension.js';
|
|
4
|
+
export * from './extensions/TemplateExtensionBase.js';
|
|
27
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/templates",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.1.0",
|
|
4
5
|
"description": "MemberJunction Templating Engine and Utilities - Used for any application that requires templating utility functionality. NOTE: this package does use Angular Universal for compilation but is not marked with the usual ng prefix because it is a server-side library and not used within Angular apps.",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,23 +10,23 @@
|
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"start": "ts-node-dev src/index.ts",
|
|
12
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && tsc-alias -f",
|
|
13
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
15
|
},
|
|
15
16
|
"author": "MemberJunction.com",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"devDependencies": {
|
|
18
|
-
"typescript": "^5.
|
|
19
|
+
"typescript": "^5.9.3"
|
|
19
20
|
},
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"@memberjunction/core": "
|
|
22
|
-
"@memberjunction/templates-base-types": "
|
|
23
|
-
"@memberjunction/ai": "
|
|
24
|
-
"@memberjunction/ai-core-plus": "
|
|
25
|
-
"@memberjunction/aiengine": "
|
|
26
|
-
"@memberjunction/ai-provider-bundle": "
|
|
27
|
-
"@memberjunction/core-entities": "
|
|
28
|
-
"@memberjunction/global": "
|
|
22
|
+
"@memberjunction/core": "4.1.0",
|
|
23
|
+
"@memberjunction/templates-base-types": "4.1.0",
|
|
24
|
+
"@memberjunction/ai": "4.1.0",
|
|
25
|
+
"@memberjunction/ai-core-plus": "4.1.0",
|
|
26
|
+
"@memberjunction/aiengine": "4.1.0",
|
|
27
|
+
"@memberjunction/ai-provider-bundle": "4.1.0",
|
|
28
|
+
"@memberjunction/core-entities": "4.1.0",
|
|
29
|
+
"@memberjunction/global": "4.1.0",
|
|
29
30
|
"nunjucks": "3.2.4"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|