@memberjunction/templates 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 +296 -1
- package/dist/TemplateEngine.d.ts +2 -1
- package/dist/TemplateEngine.d.ts.map +1 -1
- package/dist/TemplateEngine.js +5 -0
- package/dist/TemplateEngine.js.map +1 -1
- package/dist/extensions/AIPrompt.extension.d.ts +26 -1
- package/dist/extensions/AIPrompt.extension.d.ts.map +1 -1
- package/dist/extensions/AIPrompt.extension.js +64 -15
- package/dist/extensions/AIPrompt.extension.js.map +1 -1
- package/dist/extensions/TemplateEmbed.extension.d.ts +86 -0
- package/dist/extensions/TemplateEmbed.extension.d.ts.map +1 -0
- package/dist/extensions/TemplateEmbed.extension.js +248 -0
- package/dist/extensions/TemplateEmbed.extension.js.map +1 -0
- package/dist/extensions/TemplateExtensionBase.d.ts +16 -1
- package/dist/extensions/TemplateExtensionBase.d.ts.map +1 -1
- package/dist/extensions/TemplateExtensionBase.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -1,3 +1,298 @@
|
|
|
1
1
|
# @memberjunction/templates
|
|
2
2
|
|
|
3
|
-
The `@memberjunction/templates` library provides
|
|
3
|
+
The `@memberjunction/templates` library provides a powerful templating engine built on Nunjucks with MemberJunction-specific extensions for dynamic content generation, AI-powered prompts, and recursive template embedding.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package serves as the core templating engine for MemberJunction applications, offering:
|
|
8
|
+
|
|
9
|
+
- **Nunjucks-based templating** with full syntax support
|
|
10
|
+
- **Template management** with metadata integration
|
|
11
|
+
- **Custom extensions** for AI prompts and template embedding
|
|
12
|
+
- **Type-safe interfaces** for template rendering
|
|
13
|
+
- **Caching and performance optimization**
|
|
14
|
+
- **Async rendering support**
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @memberjunction/templates
|
|
20
|
+
```
|
|
21
|
+
|
|
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
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
### Basic Template Rendering
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { TemplateEngineServer } from '@memberjunction/templates';
|
|
51
|
+
import { UserInfo } from '@memberjunction/core';
|
|
52
|
+
|
|
53
|
+
// Get the template engine instance
|
|
54
|
+
const templateEngine = TemplateEngineServer.Instance;
|
|
55
|
+
|
|
56
|
+
// Configure the engine (usually done once at startup)
|
|
57
|
+
await templateEngine.Config(false, contextUser);
|
|
58
|
+
|
|
59
|
+
// Simple rendering without metadata
|
|
60
|
+
const result = await templateEngine.RenderTemplateSimple(
|
|
61
|
+
'Hello {{ name }}! Welcome to {{ company }}.',
|
|
62
|
+
{ name: 'John', company: 'Acme Corp' }
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
if (result.Success) {
|
|
66
|
+
console.log(result.Output); // "Hello John! Welcome to Acme Corp."
|
|
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);
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Using the AI Prompt Extension
|
|
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.
|
|
170
|
+
|
|
171
|
+
### TemplateRenderResult
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
interface TemplateRenderResult {
|
|
175
|
+
Success: boolean; // Whether rendering succeeded
|
|
176
|
+
Output: string; // The rendered output (null if failed)
|
|
177
|
+
Message?: string; // Error message (only when Success=false)
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Extension Configuration
|
|
182
|
+
|
|
183
|
+
#### AIPrompt Extension Parameters
|
|
184
|
+
|
|
185
|
+
- `AIModel` (optional): Specific AI model to use (e.g., "gpt-4", "claude-3")
|
|
186
|
+
- `AllowFormatting` (optional): Whether to allow formatted output (HTML, Markdown, etc.)
|
|
187
|
+
|
|
188
|
+
#### Template Embed Extension Parameters
|
|
189
|
+
|
|
190
|
+
- First parameter: Template name (required)
|
|
191
|
+
- `type` (optional): Specific content type to use
|
|
192
|
+
- `data` (optional): Additional data to pass to the embedded template
|
|
193
|
+
|
|
194
|
+
## Template Extension Development
|
|
195
|
+
|
|
196
|
+
To create custom template extensions:
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { TemplateExtensionBase, RegisterClass } from '@memberjunction/templates';
|
|
200
|
+
|
|
201
|
+
@RegisterClass(TemplateExtensionBase, 'MyExtension')
|
|
202
|
+
export class MyExtension extends TemplateExtensionBase {
|
|
203
|
+
constructor(contextUser: UserInfo) {
|
|
204
|
+
super(contextUser);
|
|
205
|
+
this.tags = ['myTag'];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public parse(parser: Parser, nodes: Nodes, lexer: Lexer) {
|
|
209
|
+
const tok = parser.nextToken();
|
|
210
|
+
const params = parser.parseSignature(null, true);
|
|
211
|
+
parser.advanceAfterBlockEnd(tok.value);
|
|
212
|
+
|
|
213
|
+
const body = parser.parseUntilBlocks('endMyTag');
|
|
214
|
+
parser.advanceAfterBlockEnd();
|
|
215
|
+
|
|
216
|
+
return new nodes.CallExtensionAsync(this, 'run', params, [body]);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
public run(context: Context, params: any, body: any, callBack: NunjucksCallback) {
|
|
220
|
+
// Your extension logic here
|
|
221
|
+
try {
|
|
222
|
+
const content = body();
|
|
223
|
+
// Process content...
|
|
224
|
+
callBack(null, processedContent);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
callBack(error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Dependencies
|
|
233
|
+
|
|
234
|
+
- `@memberjunction/core`: Core MemberJunction functionality
|
|
235
|
+
- `@memberjunction/templates-base-types`: Base types and interfaces
|
|
236
|
+
- `@memberjunction/ai`: AI integration interfaces
|
|
237
|
+
- `@memberjunction/aiengine`: AI engine implementation
|
|
238
|
+
- `@memberjunction/ai-groq`: Groq AI provider
|
|
239
|
+
- `@memberjunction/core-entities`: Entity definitions
|
|
240
|
+
- `@memberjunction/global`: Global utilities
|
|
241
|
+
- `nunjucks`: Template engine
|
|
242
|
+
|
|
243
|
+
## Integration with MemberJunction
|
|
244
|
+
|
|
245
|
+
This package integrates seamlessly with other MemberJunction packages:
|
|
246
|
+
|
|
247
|
+
- **Entity System**: Templates are stored as entities with full metadata support
|
|
248
|
+
- **AI Engine**: Direct integration for AI-powered content generation
|
|
249
|
+
- **User Context**: Templates respect user permissions and context
|
|
250
|
+
- **Metadata Provider**: Flexible metadata loading strategies
|
|
251
|
+
|
|
252
|
+
## Configuration
|
|
253
|
+
|
|
254
|
+
The template engine uses the MemberJunction configuration system. Key configuration options:
|
|
255
|
+
|
|
256
|
+
- Template caching strategies
|
|
257
|
+
- Default AI models for prompts
|
|
258
|
+
- Extension registration
|
|
259
|
+
- Nunjucks environment settings
|
|
260
|
+
|
|
261
|
+
## Performance Considerations
|
|
262
|
+
|
|
263
|
+
- Templates are cached after first compilation
|
|
264
|
+
- Use `ClearTemplateCache()` when templates are updated
|
|
265
|
+
- AI prompts are processed asynchronously
|
|
266
|
+
- Template embedding includes cycle detection
|
|
267
|
+
|
|
268
|
+
## Error Handling
|
|
269
|
+
|
|
270
|
+
All rendering methods return a `TemplateRenderResult` object:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
const result = await templateEngine.RenderTemplateSimple(template, data);
|
|
274
|
+
|
|
275
|
+
if (!result.Success) {
|
|
276
|
+
console.error('Rendering failed:', result.Message);
|
|
277
|
+
// Handle error appropriately
|
|
278
|
+
} else {
|
|
279
|
+
// Use result.Output
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Best Practices
|
|
284
|
+
|
|
285
|
+
1. **Always check rendering results** for success before using output
|
|
286
|
+
2. **Configure the engine once** at application startup
|
|
287
|
+
3. **Use template validation** for user-provided data
|
|
288
|
+
4. **Clear cache** when templates are modified
|
|
289
|
+
5. **Handle AI failures gracefully** with fallback content
|
|
290
|
+
6. **Avoid deep template nesting** to prevent performance issues
|
|
291
|
+
|
|
292
|
+
## License
|
|
293
|
+
|
|
294
|
+
ISC - See LICENSE file for details.
|
|
295
|
+
|
|
296
|
+
## Support
|
|
297
|
+
|
|
298
|
+
For issues, questions, or contributions, please visit [MemberJunction.com](https://memberjunction.com) or contact the development team.
|
package/dist/TemplateEngine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UserInfo } from "@memberjunction/core";
|
|
1
|
+
import { IMetadataProvider, UserInfo } from "@memberjunction/core";
|
|
2
2
|
import { TemplateContentEntity } from "@memberjunction/core-entities";
|
|
3
3
|
import * as nunjucks from 'nunjucks';
|
|
4
4
|
import { TemplateEntityExtended, TemplateRenderResult, TemplateEngineBase } from '@memberjunction/templates-base-types';
|
|
@@ -27,6 +27,7 @@ export declare class TemplateEntityLoader extends nunjucks.Loader {
|
|
|
27
27
|
export declare class TemplateEngineServer extends TemplateEngineBase {
|
|
28
28
|
static get Instance(): TemplateEngineServer;
|
|
29
29
|
private _oneTimeLoadingComplete;
|
|
30
|
+
Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
|
|
30
31
|
protected AdditionalLoading(contextUser?: UserInfo): Promise<void>;
|
|
31
32
|
SetupNunjucks(): void;
|
|
32
33
|
private _nunjucksEnv;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.d.ts","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,QAAQ,EAAuB,MAAM,sBAAsB,CAAC;
|
|
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,MAAM,+BAA+B,CAAC;AACtE,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAC;AAGrC,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAA;AAEvH;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ,CAAC,MAAM;IAC9C,KAAK,EAAE,IAAI,CAAC;IAEnB,OAAO,CAAC,SAAS,CAAwD;IAEzE;;;;OAIG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB;IAIvE;;;;OAIG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;CAW/C;AAED;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,kBAAkB;IACxD,WAAkB,QAAQ,IAAI,oBAAoB,CAEjD;IAED,OAAO,CAAC,uBAAuB,CAAkB;IACxC,MAAM,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;cAK5F,iBAAiB,CAAC,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAyBjE,aAAa,IAAI,IAAI;IAK5B,OAAO,CAAC,YAAY,CAAuB;IAC3C,OAAO,CAAC,eAAe,CAAuB;IAE9C;;OAEG;IACH,OAAO,CAAC,cAAc,CAA4C;IAE3D,WAAW,CAAC,cAAc,EAAE,sBAAsB;IAKzD;;;;;OAKG;IACU,cAAc,CAAC,cAAc,EAAE,sBAAsB,EAAE,eAAe,EAAE,qBAAqB,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAgD/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;CAW/F"}
|
package/dist/TemplateEngine.js
CHANGED
|
@@ -78,6 +78,11 @@ class TemplateEngineServer extends templates_base_types_1.TemplateEngineBase {
|
|
|
78
78
|
static get Instance() {
|
|
79
79
|
return super.getInstance();
|
|
80
80
|
}
|
|
81
|
+
Config(forceRefresh, contextUser, provider) {
|
|
82
|
+
// call the base class to ensure we get the config loaded
|
|
83
|
+
this.ClearTemplateCache(); // clear the template cache before we load the config
|
|
84
|
+
return super.Config(forceRefresh, contextUser, provider);
|
|
85
|
+
}
|
|
81
86
|
async AdditionalLoading(contextUser) {
|
|
82
87
|
// pass along the call to our base class so it can do whatever it wants
|
|
83
88
|
await super.AdditionalLoading(contextUser);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateEngine.js","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"TemplateEngine.js","sourceRoot":"","sources":["../src/TemplateEngine.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAkG;AAElG,mDAAqC;AACrC,mDAAkD;AAClD,8EAA2E;AAC3E,+EAAuH;AAEvH;;GAEG;AACH,MAAa,oBAAqB,SAAQ,QAAQ,CAAC,MAAM;IAAzD;;QAGY,cAAS,GAAqD,EAAE,CAAC;IA2B7E,CAAC;IAzBG;;;;OAIG;IACI,WAAW,CAAC,UAAkB,EAAE,QAAgC;QACnE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,IAAY,EAAE,QAAa;QACxC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAC5C,IAAI,QAAQ,EAAE,CAAC;YACX,QAAQ,CAAC;gBACL,GAAG,EAAE,QAAQ,CAAC,GAAG;gBACjB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,IAAI;aAChB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ;AA9BD,oDA8BC;AAED;;GAEG;AACH,MAAa,oBAAqB,SAAQ,yCAAkB;IAA5D;;QAKY,4BAAuB,GAAY,KAAK,CAAC;QAuCjD;;WAEG;QACK,mBAAc,GAAqB,IAAI,GAAG,EAAe,CAAC;IA6ItE,CAAC;IA3LU,MAAM,KAAK,QAAQ;QACtB,OAAO,KAAK,CAAC,WAAW,EAAwB,C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AAC,CAAC;gBACrD,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;YACzD,CAAC;YACD,OAAO,QAAQ,CAAC;QACpB,CAAC;aACI,CAAC;YACF,iGAAiG;YACjG,gFAAgF;YAChF,OAAO,IAAI,CAAC,sBAAsB,CAAC,YAAY,CAAC,CAAC;QACrD,CAAC;IACL,CAAC;IAED;;;;OAIG;IACO,sBAAsB,CAAC,YAAoB;QACjD,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAClE,CAAC;IAEM,kBAAkB;QACrB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,mBAAmB,CAAC,QAA2B,EAAE,IAAS;QACtE,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACnC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;gBAClC,IAAI,GAAG,EAAE,CAAC;oBACN,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,MAAM,CAAC,CAAC;gBACpB,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AA5LD,oDA4LC"}
|
|
@@ -12,7 +12,31 @@ export declare class AIPromptExtension extends TemplateExtensionBase {
|
|
|
12
12
|
AllowFormattingText: string;
|
|
13
13
|
constructor(contextUser: UserInfo);
|
|
14
14
|
parse(parser: Parser, nodes: Nodes, lexer: Lexer): any;
|
|
15
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Executes AI prompt processing using the configured language model.
|
|
17
|
+
*
|
|
18
|
+
* **Parameter Mapping from CallExtensionAsync:**
|
|
19
|
+
* - In parse(): `new nodes.CallExtensionAsync(this, 'run', params, [body])`
|
|
20
|
+
* - Results in: `run(context, params, body, callBack)`
|
|
21
|
+
*
|
|
22
|
+
* The key difference from TemplateEmbed is that we pass `[body]` as the 4th parameter
|
|
23
|
+
* to CallExtensionAsync, which shifts the parameter order to include both params and body
|
|
24
|
+
* as separate arguments. The body contains the prompt text between the opening and closing tags.
|
|
25
|
+
*
|
|
26
|
+
* @param context - Nunjucks template rendering context containing variables and data
|
|
27
|
+
* @param params - Parsed parameters from the opening tag (AIModel, AllowFormatting, etc.)
|
|
28
|
+
* @param body - Function that returns the rendered prompt content between {% AIPrompt %} and {% endAIPrompt %}
|
|
29
|
+
* @param callBack - Async callback function to return the AI-generated response or errors
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```nunjucks
|
|
33
|
+
* {% AIPrompt AIModel="gpt-4", AllowFormatting=true %}
|
|
34
|
+
* Generate a personalized greeting for {{ user.name }} who works as {{ user.jobTitle }}.
|
|
35
|
+
* Make it professional but warm.
|
|
36
|
+
* {% endAIPrompt %}
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
run(context: Context, params: any, body: any, callBack: NunjucksCallback): void;
|
|
16
40
|
/**
|
|
17
41
|
* Default implementation simply returns 'OpenAI' - override this in your subclass if you are using a different AI vendor.
|
|
18
42
|
* @returns
|
|
@@ -35,5 +59,6 @@ export type AIPromptConfig = {
|
|
|
35
59
|
*/
|
|
36
60
|
AllowFormatting?: boolean;
|
|
37
61
|
};
|
|
62
|
+
export declare function LoadAIPromptExtension(): void;
|
|
38
63
|
export {};
|
|
39
64
|
//# 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,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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;AAqGF,wBAAgB,qBAAqB,SAEpC"}
|
|
@@ -9,7 +9,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AIPromptExtension = void 0;
|
|
12
|
+
exports.LoadAIPromptExtension = exports.AIPromptExtension = void 0;
|
|
13
13
|
const core_1 = require("@memberjunction/core");
|
|
14
14
|
const global_1 = require("@memberjunction/global");
|
|
15
15
|
const TemplateExtensionBase_1 = require("./TemplateExtensionBase");
|
|
@@ -47,21 +47,58 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
47
47
|
// parser.advanceAfterBlockEnd();
|
|
48
48
|
// const errorBody = '';
|
|
49
49
|
// See above for notes about CallExtension
|
|
50
|
-
return new nodes.CallExtensionAsync(this, 'run', params, [body
|
|
50
|
+
return new nodes.CallExtensionAsync(this, 'run', params, [body]);
|
|
51
51
|
}
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Executes AI prompt processing using the configured language model.
|
|
54
|
+
*
|
|
55
|
+
* **Parameter Mapping from CallExtensionAsync:**
|
|
56
|
+
* - In parse(): `new nodes.CallExtensionAsync(this, 'run', params, [body])`
|
|
57
|
+
* - Results in: `run(context, params, body, callBack)`
|
|
58
|
+
*
|
|
59
|
+
* The key difference from TemplateEmbed is that we pass `[body]` as the 4th parameter
|
|
60
|
+
* to CallExtensionAsync, which shifts the parameter order to include both params and body
|
|
61
|
+
* as separate arguments. The body contains the prompt text between the opening and closing tags.
|
|
62
|
+
*
|
|
63
|
+
* @param context - Nunjucks template rendering context containing variables and data
|
|
64
|
+
* @param params - Parsed parameters from the opening tag (AIModel, AllowFormatting, etc.)
|
|
65
|
+
* @param body - Function that returns the rendered prompt content between {% AIPrompt %} and {% endAIPrompt %}
|
|
66
|
+
* @param callBack - Async callback function to return the AI-generated response or errors
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```nunjucks
|
|
70
|
+
* {% AIPrompt AIModel="gpt-4", AllowFormatting=true %}
|
|
71
|
+
* Generate a personalized greeting for {{ user.name }} who works as {{ user.jobTitle }}.
|
|
72
|
+
* Make it professional but warm.
|
|
73
|
+
* {% endAIPrompt %}
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
run(context, params, body, callBack) {
|
|
53
77
|
const prompt = body();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
78
|
+
const config = {};
|
|
79
|
+
// now map each value from params to the config object, and be case INsensitive
|
|
80
|
+
for (const key in params) {
|
|
81
|
+
if (params.hasOwnProperty(key)) {
|
|
82
|
+
const value = params[key];
|
|
83
|
+
// convert the key to lower case and remove any spaces
|
|
84
|
+
const lowerKey = key.toLowerCase().replace(/\s+/g, '');
|
|
85
|
+
// now set the value in the config object
|
|
86
|
+
if (lowerKey === 'aimodel') {
|
|
87
|
+
config.AIModel = value;
|
|
88
|
+
}
|
|
89
|
+
else if (lowerKey === 'allowformatting') {
|
|
90
|
+
// convert the value to a boolean
|
|
91
|
+
if (typeof value === 'string') {
|
|
92
|
+
config.AllowFormatting = value.toLowerCase() === 'true' || value.toLowerCase() === 'yes';
|
|
93
|
+
}
|
|
94
|
+
else if (typeof value === 'boolean') {
|
|
95
|
+
config.AllowFormatting = value;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// if the value is not a string or boolean, we will just set it to false
|
|
99
|
+
config.AllowFormatting = false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
65
102
|
}
|
|
66
103
|
}
|
|
67
104
|
// we now have the LLM prompt in the prompt variable
|
|
@@ -73,10 +110,17 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
73
110
|
try {
|
|
74
111
|
let model = null;
|
|
75
112
|
if (config.AIModel) {
|
|
76
|
-
model = aiengine_1.AIEngine.Instance.Models.find(m => m.Name.toLowerCase()
|
|
113
|
+
model = aiengine_1.AIEngine.Instance.Models.find(m => m.Name.toLowerCase() === config.AIModel.toLowerCase() ||
|
|
114
|
+
m.APIName?.toLowerCase() === config.AIModel.toLowerCase());
|
|
115
|
+
if (!model) {
|
|
116
|
+
throw new Error(`AI model '${config.AIModel}' not found.`);
|
|
117
|
+
}
|
|
77
118
|
}
|
|
78
119
|
else {
|
|
79
120
|
model = await aiengine_1.AIEngine.Instance.GetHighestPowerModel('Groq', 'llm', this.ContextUser);
|
|
121
|
+
if (!model) {
|
|
122
|
+
throw new Error(`No AI model found for the vendor 'Groq' and type 'llm'.`);
|
|
123
|
+
}
|
|
80
124
|
}
|
|
81
125
|
const llm = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(ai_1.BaseLLM, model.DriverClass, (0, ai_1.GetAIAPIKey)(model.DriverClass));
|
|
82
126
|
const llmResult = await llm.ChatCompletion({
|
|
@@ -102,6 +146,7 @@ let AIPromptExtension = class AIPromptExtension extends TemplateExtensionBase_1.
|
|
|
102
146
|
}
|
|
103
147
|
catch (e) {
|
|
104
148
|
(0, core_1.LogError)(e);
|
|
149
|
+
callBack(null, e);
|
|
105
150
|
}
|
|
106
151
|
});
|
|
107
152
|
}
|
|
@@ -213,4 +258,8 @@ exports.AIPromptExtension = AIPromptExtension = __decorate([
|
|
|
213
258
|
// models.sort((a, b) => b.PowerRank - a.PowerRank); // highest power rank first
|
|
214
259
|
// return models[0];
|
|
215
260
|
// }
|
|
261
|
+
function LoadAIPromptExtension() {
|
|
262
|
+
// does nothing just to ensure the extension class isn't tree-shaken
|
|
263
|
+
}
|
|
264
|
+
exports.LoadAIPromptExtension = LoadAIPromptExtension;
|
|
216
265
|
//# sourceMappingURL=AIPrompt.extension.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIPrompt.extension.js","sourceRoot":"","sources":["../../src/extensions/AIPrompt.extension.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0D;AAC1D,
|
|
1
|
+
{"version":3,"file":"AIPrompt.extension.js","sourceRoot":"","sources":["../../src/extensions/AIPrompt.extension.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0D;AAC1D,mDAAgF;AAChF,mEAAkF;AAClF,uDAAoD;AACpD,2CAA0D;AAQ1D;;GAEG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,6CAAqB;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,EAAE,aAAa,CAAC,CAAC;QAC3D,IAAI,SAAS,GAAG,IAAI,CAAC;QAErB,IAAG,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E;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;AAGJ,SAAgB,qBAAqB;IACjC,oEAAoE;AACxE,CAAC;AAFD,sDAEC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { NunjucksCallback, TemplateExtensionBase } from "./TemplateExtensionBase";
|
|
3
|
+
type Parser = any;
|
|
4
|
+
type Nodes = any;
|
|
5
|
+
type Lexer = any;
|
|
6
|
+
type Context = any;
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for template embedding
|
|
9
|
+
*/
|
|
10
|
+
export type TemplateEmbedConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* Specific content type to use for the embedded template.
|
|
13
|
+
* If not provided, inherits from current template's content type.
|
|
14
|
+
*/
|
|
15
|
+
type?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Additional data to merge with or override the current template's data context.
|
|
18
|
+
* This data will be available to the embedded template.
|
|
19
|
+
*/
|
|
20
|
+
data?: any;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Extension that enables recursive template embedding using {% template "TemplateName" %} syntax.
|
|
24
|
+
*
|
|
25
|
+
* Features:
|
|
26
|
+
* - Recursive template inclusion with cycle detection
|
|
27
|
+
* - Content type inheritance with intelligent fallbacks
|
|
28
|
+
* - Data context passing and merging
|
|
29
|
+
* - Error handling for missing templates
|
|
30
|
+
*
|
|
31
|
+
* Usage:
|
|
32
|
+
* {% template "TemplateName" %}
|
|
33
|
+
* {% template "TemplateName", type="HTML" %}
|
|
34
|
+
* {% template "TemplateName", data={extra: "value"} %}
|
|
35
|
+
* {% template "TemplateName", type="PlainText", data={key: "value"} %}
|
|
36
|
+
*/
|
|
37
|
+
export declare class TemplateEmbedExtension extends TemplateExtensionBase {
|
|
38
|
+
constructor(contextUser: UserInfo);
|
|
39
|
+
parse(parser: Parser, nodes: Nodes, lexer: Lexer): any;
|
|
40
|
+
/**
|
|
41
|
+
* Executes the template embedding logic with recursive template inclusion.
|
|
42
|
+
*
|
|
43
|
+
* **Parameter Mapping from CallExtensionAsync:**
|
|
44
|
+
* - In parse(): `new nodes.CallExtensionAsync(this, 'run', params)`
|
|
45
|
+
* - Results in: `run(context, body, callBack)`
|
|
46
|
+
*
|
|
47
|
+
* The `body` parameter will be undefined since TemplateEmbed is a self-closing tag
|
|
48
|
+
* that doesn't parse body content. The template name and configuration come from
|
|
49
|
+
* the parsed parameters instead.
|
|
50
|
+
*
|
|
51
|
+
* @param context - Nunjucks template rendering context containing variables and data
|
|
52
|
+
* @param body - Will be undefined for self-closing template tags (not used)
|
|
53
|
+
* @param callBack - Async callback function to return results or errors
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```nunjucks
|
|
57
|
+
* {% template "HeaderTemplate" %}
|
|
58
|
+
* {% template "UserCard", type="HTML" %}
|
|
59
|
+
* {% template "Footer", data={year: 2024} %}
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
run(context: Context, body: any, callBack: NunjucksCallback): void;
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the content type to use for the embedded template.
|
|
65
|
+
* Priority order:
|
|
66
|
+
* 1. Explicit type parameter
|
|
67
|
+
* 2. Current template's content type
|
|
68
|
+
* 3. Highest priority content available in target template
|
|
69
|
+
*/
|
|
70
|
+
private resolveContentType;
|
|
71
|
+
/**
|
|
72
|
+
* Gets the template content for the specified type with fallback logic.
|
|
73
|
+
*/
|
|
74
|
+
private getTemplateContent;
|
|
75
|
+
/**
|
|
76
|
+
* Prepares the data context for the embedded template by merging current context with additional data.
|
|
77
|
+
*/
|
|
78
|
+
private prepareDataContext;
|
|
79
|
+
/**
|
|
80
|
+
* Renders the embedded template content with the provided data context.
|
|
81
|
+
*/
|
|
82
|
+
private renderEmbeddedTemplate;
|
|
83
|
+
}
|
|
84
|
+
export declare function LoadTemplateEmbedExtension(): void;
|
|
85
|
+
export {};
|
|
86
|
+
//# sourceMappingURL=TemplateEmbed.extension.d.ts.map
|
|
@@ -0,0 +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;AAMlF,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;AAED,wBAAgB,0BAA0B,SAEzC"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LoadTemplateEmbedExtension = exports.TemplateEmbedExtension = void 0;
|
|
13
|
+
const core_1 = require("@memberjunction/core");
|
|
14
|
+
const global_1 = require("@memberjunction/global");
|
|
15
|
+
const TemplateExtensionBase_1 = require("./TemplateExtensionBase");
|
|
16
|
+
const TemplateEngine_1 = require("../TemplateEngine");
|
|
17
|
+
/**
|
|
18
|
+
* Extension that enables recursive template embedding using {% template "TemplateName" %} syntax.
|
|
19
|
+
*
|
|
20
|
+
* Features:
|
|
21
|
+
* - Recursive template inclusion with cycle detection
|
|
22
|
+
* - Content type inheritance with intelligent fallbacks
|
|
23
|
+
* - Data context passing and merging
|
|
24
|
+
* - Error handling for missing templates
|
|
25
|
+
*
|
|
26
|
+
* Usage:
|
|
27
|
+
* {% template "TemplateName" %}
|
|
28
|
+
* {% template "TemplateName", type="HTML" %}
|
|
29
|
+
* {% template "TemplateName", data={extra: "value"} %}
|
|
30
|
+
* {% template "TemplateName", type="PlainText", data={key: "value"} %}
|
|
31
|
+
*/
|
|
32
|
+
let TemplateEmbedExtension = class TemplateEmbedExtension extends TemplateExtensionBase_1.TemplateExtensionBase {
|
|
33
|
+
constructor(contextUser) {
|
|
34
|
+
super(contextUser);
|
|
35
|
+
this.tags = ['template'];
|
|
36
|
+
}
|
|
37
|
+
parse(parser, nodes, lexer) {
|
|
38
|
+
// Get the tag token
|
|
39
|
+
const tok = parser.nextToken();
|
|
40
|
+
// Parse the arguments - template name and optional parameters
|
|
41
|
+
const params = parser.parseSignature(null, true);
|
|
42
|
+
parser.advanceAfterBlockEnd(tok.value);
|
|
43
|
+
// Template embedding is a self-closing tag, no body content to parse
|
|
44
|
+
// Return a CallExtensionAsync node with the parsed parameters
|
|
45
|
+
return new nodes.CallExtensionAsync(this, 'run', params);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Executes the template embedding logic with recursive template inclusion.
|
|
49
|
+
*
|
|
50
|
+
* **Parameter Mapping from CallExtensionAsync:**
|
|
51
|
+
* - In parse(): `new nodes.CallExtensionAsync(this, 'run', params)`
|
|
52
|
+
* - Results in: `run(context, body, callBack)`
|
|
53
|
+
*
|
|
54
|
+
* The `body` parameter will be undefined since TemplateEmbed is a self-closing tag
|
|
55
|
+
* that doesn't parse body content. The template name and configuration come from
|
|
56
|
+
* the parsed parameters instead.
|
|
57
|
+
*
|
|
58
|
+
* @param context - Nunjucks template rendering context containing variables and data
|
|
59
|
+
* @param body - Will be undefined for self-closing template tags (not used)
|
|
60
|
+
* @param callBack - Async callback function to return results or errors
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```nunjucks
|
|
64
|
+
* {% template "HeaderTemplate" %}
|
|
65
|
+
* {% template "UserCard", type="HTML" %}
|
|
66
|
+
* {% template "Footer", data={year: 2024} %}
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
run(context, body, callBack) {
|
|
70
|
+
try {
|
|
71
|
+
// Extract template name (first parameter)
|
|
72
|
+
const bodyString = body ? body : '';
|
|
73
|
+
const params = bodyString.split(',');
|
|
74
|
+
/*
|
|
75
|
+
Possible Formats for the body of the template tag:
|
|
76
|
+
|
|
77
|
+
Basic Usage:
|
|
78
|
+
|
|
79
|
+
{% template "TemplateName" %}
|
|
80
|
+
|
|
81
|
+
With Optional Parameters:
|
|
82
|
+
|
|
83
|
+
{% template "TemplateName", type="HTML" %}
|
|
84
|
+
{% template "TemplateName", data={key: "value"} %}
|
|
85
|
+
{% template "TemplateName", type="PlainText", data={extra: "data"} %}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
So we need to take the params array we have above and each item is either just a string
|
|
89
|
+
' e.g. the TemplateName, or a key-value pair like 'type="HTML"' or 'data={key: "value"}'
|
|
90
|
+
We will parse these into a structured object for easier handling.
|
|
91
|
+
*/
|
|
92
|
+
const parsedParams = params.map(param => {
|
|
93
|
+
// Split by the first '=' to separate property name and value
|
|
94
|
+
const [propertyName, ...valueParts] = param.split('=');
|
|
95
|
+
const value = valueParts.join('=').trim().replace(/^"|"$/g, ''); // Remove surrounding quotes if any
|
|
96
|
+
if (value.trim() === '') {
|
|
97
|
+
return { propertyName: 'template', value: propertyName.trim() }; // Default to 'template' if no value provided
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return { propertyName: propertyName.trim(), value: value };
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
if (!parsedParams || parsedParams.length === 0) {
|
|
104
|
+
throw new Error('Template name is required for template embedding');
|
|
105
|
+
}
|
|
106
|
+
const templateName = parsedParams.find(param => param.propertyName === 'template')?.value || parsedParams[0].value;
|
|
107
|
+
if (!templateName || typeof templateName !== 'string') {
|
|
108
|
+
throw new Error('Template name must be a non-empty string');
|
|
109
|
+
}
|
|
110
|
+
// Parse optional configuration parameters
|
|
111
|
+
let config = {};
|
|
112
|
+
if (params.length > 1) {
|
|
113
|
+
// Additional parameters should be key-value pairs
|
|
114
|
+
for (let i = 1; i < params.length; i += 2) {
|
|
115
|
+
if (i + 1 < params.length) {
|
|
116
|
+
const key = params[i];
|
|
117
|
+
const value = params[i + 1];
|
|
118
|
+
config[key] = value;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Get the template engine instance
|
|
123
|
+
const templateEngine = TemplateEngine_1.TemplateEngineServer.Instance;
|
|
124
|
+
// Initialize render context for cycle detection
|
|
125
|
+
let renderContext = context.ctx._mjRenderContext;
|
|
126
|
+
if (!renderContext) {
|
|
127
|
+
renderContext = {
|
|
128
|
+
templateStack: [],
|
|
129
|
+
currentContentType: undefined
|
|
130
|
+
};
|
|
131
|
+
context.ctx._mjRenderContext = renderContext;
|
|
132
|
+
}
|
|
133
|
+
// Check for cycles before proceeding
|
|
134
|
+
if (renderContext.templateStack.includes(templateName)) {
|
|
135
|
+
const cyclePath = [...renderContext.templateStack, templateName].join(' → ');
|
|
136
|
+
throw new Error(`Cycle detected in template embedding: ${cyclePath}`);
|
|
137
|
+
}
|
|
138
|
+
// Find the target template
|
|
139
|
+
const targetTemplate = templateEngine.FindTemplate(templateName);
|
|
140
|
+
if (!targetTemplate) {
|
|
141
|
+
throw new Error(`Template "${templateName}" not found`);
|
|
142
|
+
}
|
|
143
|
+
// Determine the content type to use
|
|
144
|
+
const contentType = this.resolveContentType(config.type, renderContext.currentContentType, targetTemplate);
|
|
145
|
+
const templateContent = this.getTemplateContent(targetTemplate, contentType);
|
|
146
|
+
if (!templateContent) {
|
|
147
|
+
throw new Error(`No suitable content found for template "${templateName}" with type "${contentType}"`);
|
|
148
|
+
}
|
|
149
|
+
// Prepare data context for the embedded template
|
|
150
|
+
const embeddedData = this.prepareDataContext(context.ctx, config.data);
|
|
151
|
+
// Add current template to the stack to prevent cycles
|
|
152
|
+
renderContext.templateStack.push(templateName);
|
|
153
|
+
const originalContentType = renderContext.currentContentType;
|
|
154
|
+
renderContext.currentContentType = templateContent.Type;
|
|
155
|
+
// Render the embedded template asynchronously
|
|
156
|
+
this.renderEmbeddedTemplate(templateEngine, templateContent, embeddedData)
|
|
157
|
+
.then((result) => {
|
|
158
|
+
// Remove template from stack after successful rendering
|
|
159
|
+
renderContext.templateStack.pop();
|
|
160
|
+
renderContext.currentContentType = originalContentType;
|
|
161
|
+
callBack(null, result);
|
|
162
|
+
})
|
|
163
|
+
.catch((error) => {
|
|
164
|
+
// Remove template from stack on error as well
|
|
165
|
+
renderContext.templateStack.pop();
|
|
166
|
+
renderContext.currentContentType = originalContentType;
|
|
167
|
+
(0, core_1.LogError)(error);
|
|
168
|
+
callBack(error);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
catch (error) {
|
|
172
|
+
(0, core_1.LogError)(error);
|
|
173
|
+
callBack(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Resolves the content type to use for the embedded template.
|
|
178
|
+
* Priority order:
|
|
179
|
+
* 1. Explicit type parameter
|
|
180
|
+
* 2. Current template's content type
|
|
181
|
+
* 3. Highest priority content available in target template
|
|
182
|
+
*/
|
|
183
|
+
resolveContentType(explicitType, currentType, targetTemplate) {
|
|
184
|
+
// 1. Use explicit type if provided
|
|
185
|
+
if (explicitType) {
|
|
186
|
+
return explicitType;
|
|
187
|
+
}
|
|
188
|
+
// 2. Use current content type if available
|
|
189
|
+
if (currentType) {
|
|
190
|
+
const matchingContent = targetTemplate.GetContentByType(currentType);
|
|
191
|
+
if (matchingContent && matchingContent.length > 0) {
|
|
192
|
+
return currentType;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// 3. Fall back to highest priority content
|
|
196
|
+
const highestPriorityContent = targetTemplate.GetHighestPriorityContent();
|
|
197
|
+
if (highestPriorityContent) {
|
|
198
|
+
return highestPriorityContent.Type;
|
|
199
|
+
}
|
|
200
|
+
// This should not happen if template has any content, but provide a fallback
|
|
201
|
+
throw new Error(`No content available for template "${targetTemplate.Name}"`);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Gets the template content for the specified type with fallback logic.
|
|
205
|
+
*/
|
|
206
|
+
getTemplateContent(template, contentType) {
|
|
207
|
+
// Try to get content of the specified type
|
|
208
|
+
const contentByType = template.GetContentByType(contentType);
|
|
209
|
+
if (contentByType && contentByType.length > 0) {
|
|
210
|
+
// Return highest priority content of this type
|
|
211
|
+
return contentByType.sort((a, b) => b.Priority - a.Priority)[0];
|
|
212
|
+
}
|
|
213
|
+
// Fall back to highest priority content of any type
|
|
214
|
+
return template.GetHighestPriorityContent();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Prepares the data context for the embedded template by merging current context with additional data.
|
|
218
|
+
*/
|
|
219
|
+
prepareDataContext(currentContext, additionalData) {
|
|
220
|
+
if (!additionalData) {
|
|
221
|
+
return currentContext;
|
|
222
|
+
}
|
|
223
|
+
// Create a new context object that merges current context with additional data
|
|
224
|
+
// Additional data takes precedence over current context
|
|
225
|
+
return { ...currentContext, ...additionalData };
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Renders the embedded template content with the provided data context.
|
|
229
|
+
*/
|
|
230
|
+
async renderEmbeddedTemplate(templateEngine, templateContent, data) {
|
|
231
|
+
// Use the template engine's simple rendering method which handles Nunjucks environment setup
|
|
232
|
+
const result = await templateEngine.RenderTemplateSimple(templateContent.TemplateText, data);
|
|
233
|
+
if (!result.Success) {
|
|
234
|
+
throw new Error(`Failed to render embedded template: ${result.Message}`);
|
|
235
|
+
}
|
|
236
|
+
return result.Output;
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
exports.TemplateEmbedExtension = TemplateEmbedExtension;
|
|
240
|
+
exports.TemplateEmbedExtension = TemplateEmbedExtension = __decorate([
|
|
241
|
+
(0, global_1.RegisterClass)(TemplateExtensionBase_1.TemplateExtensionBase, 'TemplateEmbed'),
|
|
242
|
+
__metadata("design:paramtypes", [core_1.UserInfo])
|
|
243
|
+
], TemplateEmbedExtension);
|
|
244
|
+
function LoadTemplateEmbedExtension() {
|
|
245
|
+
// This function ensures the extension class isn't tree-shaken
|
|
246
|
+
}
|
|
247
|
+
exports.LoadTemplateEmbedExtension = LoadTemplateEmbedExtension;
|
|
248
|
+
//# sourceMappingURL=TemplateEmbed.extension.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateEmbed.extension.js","sourceRoot":"","sources":["../../src/extensions/TemplateEmbed.extension.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+CAA0D;AAC1D,mDAAuD;AACvD,mEAAkF;AAGlF,sDAAyD;AAuCzD;;;;;;;;;;;;;;GAcG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,6CAAqB;IAE7D,YAAY,WAAqB;QAC7B,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,MAAc,EAAE,KAAY,EAAE,KAAY;QACnD,oBAAoB;QACpB,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;QAE/B,8DAA8D;QAC9D,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACjD,MAAM,CAAC,oBAAoB,CAAC,GA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24
|
abstract parse(parser: Parser, nodes: Nodes, lexer: Lexer): any;
|
|
25
25
|
/**
|
|
26
26
|
* Required, must implement this method to run the extension.
|
|
27
|
+
*
|
|
28
|
+
* **IMPORTANT**: The actual signature of this method depends on what you pass to
|
|
29
|
+
* `nodes.CallExtensionAsync()` in your `parse()` method. The parameters listed here
|
|
30
|
+
* are just placeholders - your actual implementation will have different parameters.
|
|
31
|
+
*
|
|
32
|
+
* **Common Patterns:**
|
|
33
|
+
* - `CallExtensionAsync(this, 'run', params)` → `run(context, body, callBack)`
|
|
34
|
+
* - `CallExtensionAsync(this, 'run', params, [body])` → `run(context, params, body, callBack)`
|
|
35
|
+
* - `CallExtensionAsync(this, 'run', params, [body, error])` → `run(context, params, body, error, callBack)`
|
|
36
|
+
*
|
|
37
|
+
* @param context - Always the first parameter: Nunjucks rendering context
|
|
38
|
+
* @param callBack - Always the last parameter: Async callback for results/errors
|
|
39
|
+
* @param ...rest - Middle parameters determined by CallExtensionAsync array argument
|
|
40
|
+
*
|
|
41
|
+
* @see README.md in this directory for detailed documentation on parameter mapping
|
|
27
42
|
*/
|
|
28
|
-
abstract run(context: Context,
|
|
43
|
+
abstract run(context: Context, ...args: any[]): any;
|
|
29
44
|
}
|
|
30
45
|
export {};
|
|
31
46
|
//# sourceMappingURL=TemplateExtensionBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateExtensionBase.d.ts","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,KAAK,MAAM,GAAG,GAAG,CAAC;AAClB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,OAAO,GAAG,GAAG,CAAC;AAInB,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;AAEzE;;GAEG;AACH,8BAAsB,qBAAqB;IACvC;;OAEG;IACI,IAAI,EAAE,MAAM,EAAE,CAAM;IAE3B,IAAW,WAAW,IAAI,QAAQ,CAEjC;IACD,OAAO,CAAC,YAAY,CAAW;gBAEnB,WAAW,EAAE,QAAQ;IAIjC;;;;;OAKG;aACa,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;IACtE
|
|
1
|
+
{"version":3,"file":"TemplateExtensionBase.d.ts","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,KAAK,MAAM,GAAG,GAAG,CAAC;AAClB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,KAAK,GAAG,GAAG,CAAC;AACjB,KAAK,OAAO,GAAG,GAAG,CAAC;AAInB,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;AAEzE;;GAEG;AACH,8BAAsB,qBAAqB;IACvC;;OAEG;IACI,IAAI,EAAE,MAAM,EAAE,CAAM;IAE3B,IAAW,WAAW,IAAI,QAAQ,CAEjC;IACD,OAAO,CAAC,YAAY,CAAW;gBAEnB,WAAW,EAAE,QAAQ;IAIjC;;;;;OAKG;aACa,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,GAAG;IACtE;;;;;;;;;;;;;;;;;OAiBG;aACa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE;CACvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateExtensionBase.js","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACH,MAAsB,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;
|
|
1
|
+
{"version":3,"file":"TemplateExtensionBase.js","sourceRoot":"","sources":["../../src/extensions/TemplateExtensionBase.ts"],"names":[],"mappings":";;;AAWA;;GAEG;AACH,MAAsB,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;AAzCD,sDAyCC"}
|
package/dist/index.d.ts
CHANGED
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":"AAQA,cAAc,kBAAkB,CAAC;AACjC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
const ai_groq_1 = require("@memberjunction/ai-groq");
|
|
18
18
|
(0, ai_groq_1.LoadGroqLLM)(); // make sure it doesnt get tree shaken out, we need Groq
|
|
19
|
+
const TemplateEmbed_extension_1 = require("./extensions/TemplateEmbed.extension");
|
|
20
|
+
const AIPrompt_extension_1 = require("./extensions/AIPrompt.extension");
|
|
21
|
+
(0, TemplateEmbed_extension_1.LoadTemplateEmbedExtension)(); // make sure it doesnt get tree shaken out, we need template embedding
|
|
22
|
+
(0, AIPrompt_extension_1.LoadAIPromptExtension)(); // make sure it doesnt get tree shaken out, we need AI prompts
|
|
19
23
|
__exportStar(require("./TemplateEngine"), exports);
|
|
20
24
|
__exportStar(require("./extensions/AIPrompt.extension"), exports);
|
|
25
|
+
__exportStar(require("./extensions/TemplateEmbed.extension"), exports);
|
|
21
26
|
__exportStar(require("./extensions/TemplateExtensionBase"), exports);
|
|
22
27
|
//# 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":";;;;;;;;;;;;;;;;AAAA,qDAAsD;AACtD,IAAA,qBAAW,GAAE,CAAC,CAAC,wDAAwD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAsD;AACtD,IAAA,qBAAW,GAAE,CAAC,CAAC,wDAAwD;AAEvE,kFAAkF;AAClF,wEAAwE;AACxE,IAAA,oDAA0B,GAAE,CAAC,CAAC,sEAAsE;AACpG,IAAA,0CAAqB,GAAE,CAAC,CAAC,8DAA8D;AAEvF,mDAAiC;AACjC,kEAAgD;AAChD,uEAAqD;AACrD,qEAAmD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/templates",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"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
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
"typescript": "^5.4.5"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@memberjunction/core": "2.
|
|
22
|
-
"@memberjunction/templates-base-types": "2.
|
|
23
|
-
"@memberjunction/ai": "2.
|
|
24
|
-
"@memberjunction/aiengine": "2.
|
|
25
|
-
"@memberjunction/ai-groq": "2.
|
|
26
|
-
"@memberjunction/core-entities": "2.
|
|
27
|
-
"@memberjunction/global": "2.
|
|
21
|
+
"@memberjunction/core": "2.44.0",
|
|
22
|
+
"@memberjunction/templates-base-types": "2.44.0",
|
|
23
|
+
"@memberjunction/ai": "2.44.0",
|
|
24
|
+
"@memberjunction/aiengine": "2.44.0",
|
|
25
|
+
"@memberjunction/ai-groq": "2.44.0",
|
|
26
|
+
"@memberjunction/core-entities": "2.44.0",
|
|
27
|
+
"@memberjunction/global": "2.44.0",
|
|
28
28
|
"nunjucks": "3.2.4"
|
|
29
29
|
}
|
|
30
30
|
}
|