@memberjunction/templates 6.2.0-edge.3 → 6.2.0-edge.5

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.
Files changed (42) hide show
  1. package/README.md +85 -1
  2. package/dist/InheritedMemberNames.d.ts +12 -0
  3. package/dist/InheritedMemberNames.d.ts.map +1 -0
  4. package/dist/InheritedMemberNames.js +19 -0
  5. package/dist/InheritedMemberNames.js.map +1 -0
  6. package/dist/NunjucksCompileGuard.d.ts +17 -0
  7. package/dist/NunjucksCompileGuard.d.ts.map +1 -0
  8. package/dist/NunjucksCompileGuard.js +273 -0
  9. package/dist/NunjucksCompileGuard.js.map +1 -0
  10. package/dist/NunjucksSandbox.d.ts +26 -0
  11. package/dist/NunjucksSandbox.d.ts.map +1 -0
  12. package/dist/NunjucksSandbox.js +317 -0
  13. package/dist/NunjucksSandbox.js.map +1 -0
  14. package/dist/TemplateEngine.d.ts +41 -9
  15. package/dist/TemplateEngine.d.ts.map +1 -1
  16. package/dist/TemplateEngine.js +123 -23
  17. package/dist/TemplateEngine.js.map +1 -1
  18. package/dist/TemplateSandboxError.d.ts +9 -0
  19. package/dist/TemplateSandboxError.d.ts.map +1 -0
  20. package/dist/TemplateSandboxError.js +12 -0
  21. package/dist/TemplateSandboxError.js.map +1 -0
  22. package/dist/TemplateVariableAnalysis.d.ts +27 -0
  23. package/dist/TemplateVariableAnalysis.d.ts.map +1 -0
  24. package/dist/TemplateVariableAnalysis.js +140 -0
  25. package/dist/TemplateVariableAnalysis.js.map +1 -0
  26. package/dist/extensions/TemplateEmbed.extension.d.ts +13 -1
  27. package/dist/extensions/TemplateEmbed.extension.d.ts.map +1 -1
  28. package/dist/extensions/TemplateEmbed.extension.js +16 -8
  29. package/dist/extensions/TemplateEmbed.extension.js.map +1 -1
  30. package/dist/index.d.ts +5 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +5 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/operations/TemplateRunAuthorization.d.ts +20 -0
  35. package/dist/operations/TemplateRunAuthorization.d.ts.map +1 -0
  36. package/dist/operations/TemplateRunAuthorization.js +37 -0
  37. package/dist/operations/TemplateRunAuthorization.js.map +1 -0
  38. package/dist/operations/TemplateRunOperation.d.ts +6 -0
  39. package/dist/operations/TemplateRunOperation.d.ts.map +1 -1
  40. package/dist/operations/TemplateRunOperation.js +10 -1
  41. package/dist/operations/TemplateRunOperation.js.map +1 -1
  42. package/package.json +9 -9
@@ -0,0 +1,317 @@
1
+ /**
2
+ * @fileoverview Guards nunjucks so templates cannot run JavaScript or reach server objects.
3
+ *
4
+ * nunjucks has no sandbox mode, and a template can attack it at two points:
5
+ * - **Compile time.** The compiler copies template-controlled names into the code it generates.
6
+ * {@link HardenNunjucksRuntime} wraps the parser that the compiler calls, so every parsed template is
7
+ * checked by `AssertTemplateTreeIsSafe` (`NunjucksCompileGuard.ts`) before it compiles. It also wraps
8
+ * the code generator's `compilePair`, which writes dictionary keys and keyword arguments.
9
+ * - **Render time.** Every compiled template resolves bare names, member access and calls through
10
+ * three functions on nunjucks' shared runtime module: `contextOrFrameLookup`, `memberLookup` and
11
+ * `callWrap`. It builds macros with `makeMacro` and marks keyword arguments with `makeKeywordArgs`, and
12
+ * it finds filters and tests with the environment's `getFilter` and `getTest`, which read plain
13
+ * objects. Unguarded, a template can walk from any value to `Function`, or reach the render context
14
+ * and change the shared environment. {@link HardenNunjucksRuntime} wraps those functions in place.
15
+ *
16
+ * The parser, the code generator, the runtime module and the `Environment` prototype are shared by every
17
+ * nunjucks environment in the process, so the guard covers all of them, including templates loaded
18
+ * through `include` and `import`.
19
+ * @module @memberjunction/templates
20
+ */
21
+ import nunjucks from 'nunjucks';
22
+ import { IsInheritedMemberName } from './InheritedMemberNames.js';
23
+ import { AssertTemplateTreeIsSafe } from './NunjucksCompileGuard.js';
24
+ import { TemplateSandboxError } from './TemplateSandboxError.js';
25
+ const NUNJUCKS = nunjucks;
26
+ /** Member names that lead from a value to its constructor or prototype, and from there to `Function`. */
27
+ const RESTRICTED_MEMBER_NAMES = new Set([
28
+ 'constructor',
29
+ 'prototype',
30
+ '__proto__',
31
+ '__defineGetter__',
32
+ '__defineSetter__',
33
+ '__lookupGetter__',
34
+ '__lookupSetter__',
35
+ ]);
36
+ /** Values a template may never hold: constructors that compile code from strings, and reflection over any object. */
37
+ const RESTRICTED_VALUES = new Set([
38
+ Function,
39
+ (async () => undefined).constructor,
40
+ (function* () { }).constructor,
41
+ (async function* () { }).constructor,
42
+ globalThis.eval,
43
+ Object,
44
+ Reflect,
45
+ globalThis,
46
+ globalThis.process,
47
+ ].filter((value) => value !== undefined && value !== null));
48
+ /** nunjucks' base `Obj` class, which render contexts and templates extend. */
49
+ const NUNJUCKS_OBJ_PROTOTYPE = Object.getPrototypeOf(NUNJUCKS.Template.prototype);
50
+ /** nunjucks' base `EmitterObj` class, which environments and loaders extend. */
51
+ const NUNJUCKS_EMITTER_PROTOTYPE = Object.getPrototypeOf(NUNJUCKS.Environment.prototype);
52
+ /** Prototypes of the objects nunjucks uses to render: contexts and templates, environments and loaders, and frames. */
53
+ const NUNJUCKS_OBJECT_PROTOTYPES = [NUNJUCKS_OBJ_PROTOTYPE, NUNJUCKS_EMITTER_PROTOTYPE, NUNJUCKS.runtime.Frame.prototype];
54
+ /** The nunjucks module and its submodules. */
55
+ const NUNJUCKS_MODULES = new Set([
56
+ nunjucks, NUNJUCKS.runtime, NUNJUCKS.parser, NUNJUCKS.lib, NUNJUCKS.compiler, NUNJUCKS.lexer, NUNJUCKS.nodes,
57
+ ]);
58
+ /** Guards this module installed, so hardening again does not wrap a guard in another guard. */
59
+ const installedGuards = new WeakSet();
60
+ /**
61
+ * Guards the nunjucks parser, code generator and runtime used by every nunjucks environment in this process. After this call:
62
+ * - a template whose names could change the compiled code fails to compile (see `AssertTemplateTreeIsSafe`)
63
+ * - a macro or call-block argument that a call leaves out is filled only from a keyword argument that the
64
+ * call itself passes under that name, never from a member the keyword arguments inherit, so otherwise it
65
+ * reads as empty
66
+ * - keyword arguments written at a call site must be an ordinary object literal: ones that inherit from anything
67
+ * but `Object.prototype`, or that use a name that every object inherits (or `prototype`), throw, and the code
68
+ * generator refuses such a name as a dictionary key or keyword argument too; keyword arguments passed as a
69
+ * value (from render data, for example) are read through a copy of their own keys
70
+ * - a filter, test or global resolves only to a name the environment registered itself, never to a member
71
+ * that every object inherits (such as `hasOwnProperty`); an object, a function or a symbol is refused as the name
72
+ * - a member named `constructor`, `prototype`, `__proto__` or one of the `__define/lookup Getter/Setter__`
73
+ * accessors, written literally or computed while rendering, reads as `undefined`, unless it is an object's
74
+ * own data that is not a function; `__proto__` always reads as `undefined`
75
+ * - a bare name resolves only to a template variable, an own key of the render data, or an own environment
76
+ * global, never to a property that the render data or the globals inherit
77
+ * - a template may not read a member of the render context, an environment, a loader, a frame, a
78
+ * template or a nunjucks module, and a lookup or call that would return one of them throws
79
+ * - a lookup or call that would produce or use `Function` (or its async and generator variants), `eval`,
80
+ * `Object`, `Reflect`, `globalThis` or `process` throws a {@link TemplateSandboxError}
81
+ *
82
+ * Safe to call any number of times: a hook that already carries the guard is left as it is.
83
+ */
84
+ export function HardenNunjucksRuntime() {
85
+ const { parser, compiler, runtime, Environment } = NUNJUCKS;
86
+ installGuard(parser, 'parse', guardParse);
87
+ installGuard(compiler.Compiler.prototype, 'compilePair', guardCompilePair);
88
+ installGuard(runtime, 'memberLookup', guardMemberLookup);
89
+ installGuard(runtime, 'contextOrFrameLookup', guardContextOrFrameLookup);
90
+ installGuard(runtime, 'callWrap', guardCallWrap);
91
+ installGuard(runtime, 'makeMacro', guardMakeMacro);
92
+ installGuard(runtime, 'makeKeywordArgs', guardMakeKeywordArgs);
93
+ installGuard(Environment.prototype, 'getFilter', guardRegistryLookup('filters'));
94
+ installGuard(Environment.prototype, 'getTest', guardRegistryLookup('tests'));
95
+ installGuard(Environment.prototype, 'getGlobal', guardRegistryLookup('globals'));
96
+ }
97
+ /** Replaces one hook with its guarded version, unless the hook is already a guard. */
98
+ function installGuard(target, hook, guard) {
99
+ if (installedGuards.has(target[hook])) {
100
+ return;
101
+ }
102
+ const guarded = guard(target[hook]);
103
+ installedGuards.add(guarded);
104
+ target[hook] = guarded;
105
+ }
106
+ /** Parsing for the compiler: the tree is checked before nunjucks compiles it. */
107
+ function guardParse(original) {
108
+ return (src, extensions, opts) => {
109
+ const tree = original(src, extensions, opts);
110
+ AssertTemplateTreeIsSafe(tree);
111
+ return tree;
112
+ };
113
+ }
114
+ /**
115
+ * The code generator writes a dictionary key or keyword argument as an object-literal key. A key that
116
+ * `IsInheritedMemberName` matches is refused here as well, so one that reaches the code generator without
117
+ * passing the parse-time check still cannot become an object-literal key.
118
+ */
119
+ function guardCompilePair(original) {
120
+ return function guardedCompilePair(node, frame) {
121
+ const key = pairKeyName(node);
122
+ if (key !== undefined && IsInheritedMemberName(key)) {
123
+ throw new TemplateSandboxError(`Templates may not use "${key}" as a dictionary key or keyword argument`);
124
+ }
125
+ original.call(this, node, frame);
126
+ };
127
+ }
128
+ /**
129
+ * `runtime.makeMacro`, which builds every macro and call block. The macro it returns fills an argument that a
130
+ * call leaves out by reading the call's keyword arguments, and stores extra positional values in them. The
131
+ * guard gives nunjucks a copy of the keyword arguments without a prototype, holding only the keys the call
132
+ * passed, so neither step can reach an inherited member.
133
+ */
134
+ function guardMakeMacro(original) {
135
+ return (argNames, kwargNames, func) => {
136
+ const macro = original(argNames, kwargNames, func);
137
+ return function guardedMacro(...macroArgs) {
138
+ return macro.apply(this, withOwnKeywordArguments(macroArgs));
139
+ };
140
+ };
141
+ }
142
+ /**
143
+ * The call's arguments, with its keyword arguments replaced by a copy of their own keys in an object without a
144
+ * prototype. A call without keyword arguments gets an empty copy, because nunjucks would read from a new plain object.
145
+ */
146
+ function withOwnKeywordArguments(macroArgs) {
147
+ const last = macroArgs[macroArgs.length - 1];
148
+ const hasKeywordArguments = isKeywordArguments(last);
149
+ const ownKeywordArguments = Object.create(null);
150
+ if (hasKeywordArguments) {
151
+ for (const key of Object.keys(last)) {
152
+ ownKeywordArguments[key] = readMember(last, key);
153
+ }
154
+ }
155
+ ownKeywordArguments.__keywords = true;
156
+ return [...(hasKeywordArguments ? macroArgs.slice(0, -1) : macroArgs), ownKeywordArguments];
157
+ }
158
+ /** Keyword arguments as nunjucks recognizes them: an object or function that owns `__keywords`. */
159
+ function isKeywordArguments(value) {
160
+ return (typeof value === 'object' || typeof value === 'function') && value !== null && Object.hasOwn(value, '__keywords');
161
+ }
162
+ /**
163
+ * `runtime.makeKeywordArgs`, which marks the object literal that a call site passes as keyword arguments. It must
164
+ * inherit from `Object.prototype`, as an object literal does, and must not own a key that `IsInheritedMemberName` matches.
165
+ */
166
+ function guardMakeKeywordArgs(original) {
167
+ return (obj) => {
168
+ if (Object.getPrototypeOf(obj) !== Object.prototype || Object.getOwnPropertyNames(obj).some((key) => IsInheritedMemberName(key))) {
169
+ throw new TemplateSandboxError('Templates may only pass keyword arguments that are a plain object with ordinary names');
170
+ }
171
+ return original(obj);
172
+ };
173
+ }
174
+ /**
175
+ * `env.getFilter(name)`, `env.getTest(name)` and `env.getGlobal(name)`. nunjucks keeps each registry in a
176
+ * plain object, so a name such as `toString` would find the member every object inherits. Only a name the
177
+ * environment registered itself resolves. A name that is not there at all still fails as nunjucks reports it.
178
+ *
179
+ * The `select` and `reject` filters pass a template value as the name. The name is converted to a key once,
180
+ * and nunjucks receives that same key, so it reads the key the guard checked. An object, a function or a
181
+ * symbol is refused before conversion, because converting it could run template code.
182
+ */
183
+ function guardRegistryLookup(registry) {
184
+ return (original) => function guardedRegistryLookup(name) {
185
+ if ((typeof name === 'object' && name !== null) || typeof name === 'function' || typeof name === 'symbol') {
186
+ throw new TemplateSandboxError('Templates may not use an object, a function or a symbol as the name of a filter, test or global');
187
+ }
188
+ const key = String(name);
189
+ const entries = this[registry];
190
+ if (key in entries && !Object.hasOwn(entries, key)) {
191
+ throw new TemplateSandboxError(`Templates may only use filters, tests and globals that the environment registered ("${key}")`);
192
+ }
193
+ return original.call(this, key);
194
+ };
195
+ }
196
+ /**
197
+ * `obj.key` and `obj[key]`. The key is converted to a string once, so a computed key cannot change
198
+ * between the check and the read. The member is read once (`memberVal`), checked against restricted/nunjucks
199
+ * values, and returned directly (or bound to `obj` when it is a method, matching nunjucks' `memberLookup`
200
+ * without evaluating `obj[key]` a second time).
201
+ */
202
+ function guardMemberLookup(_original) {
203
+ return (obj, val) => {
204
+ if (obj === undefined || obj === null || typeof val === 'symbol') {
205
+ return undefined;
206
+ }
207
+ const key = String(val);
208
+ if (isNunjucksObject(obj)) {
209
+ throw new TemplateSandboxError(`Templates may not read members of the render context or other nunjucks objects (reading "${key}")`);
210
+ }
211
+ if (RESTRICTED_MEMBER_NAMES.has(key) && !isOwnDataValue(obj, key)) {
212
+ return undefined;
213
+ }
214
+ if (RESTRICTED_VALUES.has(obj)) {
215
+ throw new TemplateSandboxError(`Templates may not access members of a restricted value (reading "${key}")`);
216
+ }
217
+ const memberVal = readMember(obj, key);
218
+ if (isRestrictedOrNunjucksValue(memberVal)) {
219
+ throw new TemplateSandboxError(`Templates may not access the member "${key}"`);
220
+ }
221
+ if (typeof memberVal === 'function') {
222
+ return function (...args) {
223
+ return memberVal.apply(obj, args);
224
+ };
225
+ }
226
+ return memberVal;
227
+ };
228
+ }
229
+ /**
230
+ * A bare name such as `{{ user }}`: a template variable, then an own key of the render data, then an own
231
+ * environment global. The guard resolves the name itself, because nunjucks would also return members
232
+ * that the render data or the globals inherit.
233
+ */
234
+ function guardContextOrFrameLookup() {
235
+ return (context, frame, name) => {
236
+ if (name === '__proto__') {
237
+ return undefined;
238
+ }
239
+ const value = ownBinding(context, frame, name);
240
+ if (value === undefined || (RESTRICTED_MEMBER_NAMES.has(name) && typeof value === 'function')) {
241
+ return undefined;
242
+ }
243
+ if (isRestrictedOrNunjucksValue(value, context)) {
244
+ throw new TemplateSandboxError(`Templates may not access the name "${name}"`);
245
+ }
246
+ return value;
247
+ };
248
+ }
249
+ /** A call such as `{{ fn(x) }}`. nunjucks passes the render context as `this`, so a call may not return it. */
250
+ function guardCallWrap(original) {
251
+ return (obj, name, context, args) => {
252
+ if (isRestrictedOrNunjucksValue(obj, context)) {
253
+ throw new TemplateSandboxError(`Templates may not access the function "${name}"`);
254
+ }
255
+ const result = original(obj, name, context, args);
256
+ if (isRestrictedOrNunjucksValue(result, context)) {
257
+ throw new TemplateSandboxError(`Templates may not access the value returned by "${name}"`);
258
+ }
259
+ return result;
260
+ };
261
+ }
262
+ /** The value of a bare name: a template variable, else an own key of the render data, else an own environment global. */
263
+ function ownBinding(context, frame, name) {
264
+ const variable = frame.lookup(name);
265
+ if (variable !== undefined) {
266
+ return variable;
267
+ }
268
+ const data = context.getVariables();
269
+ if (Object.hasOwn(data, name)) {
270
+ return readMember(data, name);
271
+ }
272
+ const globals = context.env.globals;
273
+ return Object.hasOwn(globals, name) ? readMember(globals, name) : undefined;
274
+ }
275
+ /**
276
+ * True when an object (not a function) stores data that is not a function under `key` itself, as
277
+ * `{"constructor": "Acme"}` does. A prototype's own `constructor` is a function, so it never counts,
278
+ * and neither does `__proto__`.
279
+ */
280
+ function isOwnDataValue(obj, key) {
281
+ return key !== '__proto__'
282
+ && typeof obj === 'object' && obj !== null
283
+ && Object.hasOwn(obj, key)
284
+ && typeof readMember(obj, key) !== 'function';
285
+ }
286
+ /** True for the render context, an environment, a loader, a frame, a template or a nunjucks module. */
287
+ function isNunjucksObject(value) {
288
+ if (typeof value !== 'object' || value === null) {
289
+ return false;
290
+ }
291
+ if (NUNJUCKS_MODULES.has(value)) {
292
+ return true;
293
+ }
294
+ const proto = Object.getPrototypeOf(value);
295
+ if (proto === Object.prototype || proto === Array.prototype || proto === null) {
296
+ return false;
297
+ }
298
+ return NUNJUCKS_OBJECT_PROTOTYPES.some((prototype) => prototype.isPrototypeOf(value));
299
+ }
300
+ /** Reads a member the way a template does, including members of primitive strings and numbers. */
301
+ function readMember(obj, key) {
302
+ return obj[key];
303
+ }
304
+ /** The text of a dictionary key or keyword argument (a symbol or a quoted string), or `undefined` for any other key. */
305
+ function pairKeyName(pair) {
306
+ const key = typeof pair === 'object' && pair !== null ? readMember(pair, 'key') : undefined;
307
+ const value = typeof key === 'object' && key !== null ? readMember(key, 'value') : undefined;
308
+ return typeof value === 'string' ? value : undefined;
309
+ }
310
+ /** Returns true when a lookup or call would give a template a restricted value, the render context or another nunjucks object. */
311
+ function isRestrictedOrNunjucksValue(value, context) {
312
+ if (value === null || (typeof value !== 'object' && typeof value !== 'function')) {
313
+ return false;
314
+ }
315
+ return RESTRICTED_VALUES.has(value) || isNunjucksObject(value) || (context !== undefined && value === context);
316
+ }
317
+ //# sourceMappingURL=NunjucksSandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NunjucksSandbox.js","sourceRoot":"","sources":["../src/NunjucksSandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA4D9D,MAAM,QAAQ,GAAG,QAAwC,CAAC;AAK1D,yGAAyG;AACzG,MAAM,uBAAuB,GAAwB,IAAI,GAAG,CAAC;IACzD,aAAa;IACb,WAAW;IACX,WAAW;IACX,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;IAClB,kBAAkB;CACrB,CAAC,CAAC;AAEH,qHAAqH;AACrH,MAAM,iBAAiB,GAAyB,IAAI,GAAG,CAAU;IAC7D,QAAQ;IACR,CAAC,KAAK,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,WAAW;IACnC,CAAC,QAAQ,CAAC,MAAiD,CAAC,CAAC,CAAC,WAAW;IACzE,CAAC,KAAK,SAAS,CAAC,MAAuD,CAAC,CAAC,CAAC,WAAW;IAC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I,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,SAAS,IAAI,KAAK,KAAK,OAAO,CAAC,CAAC;AACnH,CAAC"}
@@ -2,7 +2,8 @@ import { IMetadataProvider, UserInfo } from "@memberjunction/core";
2
2
  import { MJTemplateCategoryEntity, MJTemplateContentEntity, MJTemplateContentTypeEntity, MJTemplateEntityExtended, MJTemplateParamEntity } from "@memberjunction/core-entities";
3
3
  import nunjucks from 'nunjucks';
4
4
  import { BaseSingleton } from "@memberjunction/global";
5
- import { TemplateRenderResult } from '@memberjunction/templates-base-types';
5
+ import { ReferencedVariablesResult } from "./TemplateVariableAnalysis.js";
6
+ import { TemplateRenderOptions, TemplateRenderResult } from '@memberjunction/templates-base-types';
6
7
  /**
7
8
  * This class extends the nunjucks loader to allow adding templates directly to the loader
8
9
  */
@@ -54,8 +55,13 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
54
55
  * not ours, so we drive the render-layer init explicitly here after the cache is loaded.
55
56
  */
56
57
  Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
57
- /** One-time nunjucks environment + registered-extension setup, performed after the base templates load. */
58
+ /** One-time nunjucks environment + registered-extension setup. {@link Config} and {@link GetReferencedVariables} call it. */
58
59
  private ensureNunjucksInitialized;
60
+ /**
61
+ * Registers every {@link TemplateExtensionBase} subclass with the given environment.
62
+ * @returns the extension instances registered on `env`
63
+ */
64
+ private registerExtensions;
59
65
  /** True once the underlying TemplateEngineBase cache has loaded. */
60
66
  get Loaded(): boolean;
61
67
  get ContextUser(): UserInfo;
@@ -66,6 +72,7 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
66
72
  get TemplateContents(): MJTemplateContentEntity[];
67
73
  get TemplateParams(): MJTemplateParamEntity[];
68
74
  FindTemplate(templateName: string): MJTemplateEntityExtended;
75
+ FindTemplateByID(templateId: string): MJTemplateEntityExtended | undefined;
69
76
  SetupNunjucks(): void;
70
77
  private _nunjucksEnv;
71
78
  /**
@@ -76,7 +83,11 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
76
83
  * renders, not the stored-Template extension surface. Reset to `undefined` whenever the loader is rebuilt.
77
84
  */
78
85
  private _nunjucksEnvNoAutoescape?;
86
+ /** Environment with autoescape off and the registered extensions, for {@link RenderTemplate} with `autoescape: false`. Created lazily. */
87
+ private _nunjucksEnvRawTemplates?;
79
88
  private _templateLoader;
89
+ /** The extension instances registered on {@link _nunjucksEnv}. The variable analysis parses their custom tags. */
90
+ private _registeredExtensions;
80
91
  /**
81
92
  * Builds a Nunjucks environment bound to the shared template loader with our custom filters applied.
82
93
  * Single source of truth for env construction so the autoescape and no-autoescape environments never drift.
@@ -89,9 +100,18 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
89
100
  */
90
101
  private addCustomFilters;
91
102
  /**
92
- * Cache for templates that have been created by nunjucks so we don't have to create them over and over
103
+ * Compiled templates per environment, then per template content ID, so a raw compile is never served to an
104
+ * escaping render.
93
105
  */
94
106
  private _templateCache;
107
+ /**
108
+ * Bounded LRU cache for ad-hoc templates rendered via {@link RenderTemplateSimple}.
109
+ * Keyed by `${autoescape ? '1:' : '0:'}${templateText}`.
110
+ */
111
+ private static readonly MAX_SIMPLE_TEMPLATE_CACHE_SIZE;
112
+ private _simpleTemplateCache;
113
+ /** {@link GetReferencedVariables} results by template text. */
114
+ private _referencedVariablesCache;
95
115
  AddTemplate(templateEntity: MJTemplateEntityExtended): void;
96
116
  /**
97
117
  * Renders a template with the given data.
@@ -100,8 +120,10 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
100
120
  * @param data
101
121
  * @param SkipValidation if true, validation is skipped entirely (or reduced to warnings depending on SuppressWarnings)
102
122
  * @param SuppressWarnings if true AND SkipValidation is true, no validation warnings are logged. When SkipValidation is true but SuppressWarnings is false, validation issues are logged as non-fatal warnings. Defaults to false.
123
+ * @param options `autoescape` (default `true`) toggles HTML escaping; pass `false` when the output is plain text for
124
+ * a model, where `Affineur & Owner` must not become `Affineur &amp; Owner`
103
125
  */
104
- RenderTemplate(templateEntity: MJTemplateEntityExtended, templateContent: MJTemplateContentEntity, data: any, SkipValidation?: boolean, SuppressWarnings?: boolean): Promise<TemplateRenderResult>;
126
+ RenderTemplate(templateEntity: MJTemplateEntityExtended, templateContent: MJTemplateContentEntity, data: any, SkipValidation?: boolean, SuppressWarnings?: boolean, options?: TemplateRenderOptions): Promise<TemplateRenderResult>;
105
127
  /**
106
128
  * Simple rendering utilty method. Use this to render any valid Nunjucks Template within the Nunjucks environment created by the Template Engine
107
129
  * without having to use the stored metadata (Templates/Template Contents/Template Params/etc) within the MJ database. This is useful when you have
@@ -112,30 +134,40 @@ export declare class TemplateEngineServer extends BaseSingleton<TemplateEngineSe
112
134
  * `false` for plain-text contexts such as email subject lines, where `Acme & Co` must not become `Acme &amp; Co`.
113
135
  * @returns
114
136
  */
115
- RenderTemplateSimple(templateText: string, data: any, options?: {
116
- autoescape?: boolean;
117
- }): Promise<TemplateRenderResult>;
137
+ RenderTemplateSimple(templateText: string, data: any, options?: TemplateRenderOptions): Promise<TemplateRenderResult>;
138
+ /**
139
+ * Returns the top-level variable names a template's text reads, following stored templates it
140
+ * pulls in by literal name (`{% include %}`, `{% import %}`, `{% from %}`, `{% extends %}`,
141
+ * `{% template %}`). It sets up the Nunjucks environment first, so the registered extensions' tags
142
+ * parse before the first {@link Config} too. The result is frozen and cached per template text until
143
+ * {@link ClearTemplateCache}; a result whose text does not parse is not cached.
144
+ */
145
+ GetReferencedVariables(templateText: string): ReferencedVariablesResult;
118
146
  /**
119
147
  * This method is responsible for creating a new Nunjucks template, caching it, and returning it.
120
148
  * If the templateContentId already had a template created, it will return that template from the cache.
121
149
  * @param templateId - must be provided if you want to cache the template, if not provided the template will not be cached
122
150
  * @param templateText
123
151
  * @param cacheTemplate - if true, the template will be cached, otherwise it will not be cached
152
+ * @param env the environment to compile against; defaults to the shared autoescape environment
124
153
  */
125
- protected getNunjucksTemplate(templateContentId: string, templateText: string, cacheTemplate: boolean): any;
154
+ protected getNunjucksTemplate(templateContentId: string, templateText: string, cacheTemplate: boolean, env?: nunjucks.Environment): nunjucks.Template;
126
155
  /**
127
156
  * Simple utility method to create a new Nunjucks template object and bind it to a Nunjucks environment.
128
157
  * @param templateText
129
158
  * @param env the environment to bind to; defaults to the shared autoescape environment
130
159
  * @returns
131
160
  */
132
- protected createNunjucksTemplate(templateText: string, env?: nunjucks.Environment): any;
161
+ protected createNunjucksTemplate(templateText: string, env?: nunjucks.Environment): nunjucks.Template;
133
162
  /**
134
163
  * Resolves the Nunjucks environment for an ad-hoc {@link RenderTemplateSimple} render. The autoescape:false
135
164
  * variant is created lazily on first use and cached, so callers that never opt out pay nothing.
136
165
  * @param autoescape whether the returned environment HTML-escapes output
137
166
  */
138
167
  private getSimpleRenderEnv;
168
+ /** The environment for {@link RenderTemplate} with `autoescape: false`, built on first use with the registered extensions. */
169
+ private getRawTemplateEnv;
170
+ /** Clears the compiled-template cache and the cached {@link GetReferencedVariables} results. */
139
171
  ClearTemplateCache(): void;
140
172
  /**
141
173
  * Promisifies the Nunjucks template rendering process.
@@ -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,wBAAwB,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAChL,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAE7E,OAAO,EAAE,oBAAoB,EAAsB,MAAM,sCAAsC,CAAA;AAE/F;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ,CAAC,MAAM;IAC9C,KAAK,UAAQ;IAEpB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