@n8n/expression-runtime 0.2.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.
@@ -0,0 +1,197 @@
1
+ import type { RuntimeBridge } from './bridge';
2
+ export interface TournamentHooks {
3
+ before?: Array<(ast: unknown) => unknown>;
4
+ after?: Array<(ast: unknown) => unknown>;
5
+ }
6
+ /**
7
+ * Configuration for ExpressionEvaluator.
8
+ *
9
+ * Note: Slice 1 keeps this minimal. Tournament integration and code caching
10
+ * will be added in later slices.
11
+ */
12
+ export interface EvaluatorConfig {
13
+ /**
14
+ * Runtime bridge implementation.
15
+ */
16
+ bridge: RuntimeBridge;
17
+ /**
18
+ * Observability provider for metrics, traces, and logs.
19
+ */
20
+ observability?: ObservabilityProvider;
21
+ /**
22
+ * AST security hooks for tournament expression transformation.
23
+ * Provided by the caller (e.g., workflow package's expression-sandboxing.ts).
24
+ * If omitted, expressions are transformed with no security hooks (dev/testing use).
25
+ */
26
+ hooks?: TournamentHooks;
27
+ }
28
+ /**
29
+ * Expression evaluator - main public API.
30
+ *
31
+ * This is the primary interface used by the workflow package.
32
+ */
33
+ export interface IExpressionEvaluator {
34
+ /**
35
+ * Initialize the evaluator and bridge.
36
+ * Must be called before evaluate().
37
+ */
38
+ initialize(): Promise<void>;
39
+ /**
40
+ * Evaluate an expression string against workflow data.
41
+ *
42
+ * @param expression - Expression string (e.g., "{{ $json.email }}")
43
+ * @param data - Workflow data context
44
+ * @param options - Evaluation options
45
+ * @returns Result of the expression
46
+ *
47
+ * Note: Synchronous for Slice 1 (Node.js vm module).
48
+ * Will be async for Slice 2 (isolated-vm).
49
+ */
50
+ evaluate(expression: string, data: WorkflowData, options?: EvaluateOptions): unknown;
51
+ /**
52
+ * Dispose of the evaluator and free resources.
53
+ */
54
+ dispose(): Promise<void>;
55
+ /**
56
+ * Check if the evaluator has been disposed.
57
+ */
58
+ isDisposed(): boolean;
59
+ }
60
+ /**
61
+ * Workflow data proxy from WorkflowDataProxy.getDataProxy().
62
+ *
63
+ * For Slice 1: We pass this directly via VM context (simple pass-through).
64
+ * Later: Will implement deep lazy proxy for field-level data fetching.
65
+ */
66
+ export type WorkflowData = Record<string, unknown>;
67
+ /**
68
+ * Options for evaluate().
69
+ */
70
+ /**
71
+ * Options for evaluate().
72
+ *
73
+ * Note: Slice 1 is minimal. Tournament options will be added later.
74
+ */
75
+ export interface EvaluateOptions {
76
+ /**
77
+ * Custom timeout for this evaluation (in milliseconds).
78
+ * Overrides the bridge's default timeout.
79
+ */
80
+ timeout?: number;
81
+ }
82
+ /**
83
+ * Observability provider interface.
84
+ *
85
+ * Implementations: NoOpProvider, OpenTelemetryProvider, PostHogProvider
86
+ */
87
+ export interface ObservabilityProvider {
88
+ /**
89
+ * Metrics API.
90
+ */
91
+ metrics: MetricsAPI;
92
+ /**
93
+ * Traces API.
94
+ */
95
+ traces: TracesAPI;
96
+ /**
97
+ * Logs API.
98
+ */
99
+ logs: LogsAPI;
100
+ }
101
+ /**
102
+ * Metrics API.
103
+ */
104
+ export interface MetricsAPI {
105
+ /**
106
+ * Increment a counter.
107
+ */
108
+ counter(name: string, value: number, tags?: Record<string, string>): void;
109
+ /**
110
+ * Set a gauge value.
111
+ */
112
+ gauge(name: string, value: number, tags?: Record<string, string>): void;
113
+ /**
114
+ * Record a histogram value.
115
+ */
116
+ histogram(name: string, value: number, tags?: Record<string, string>): void;
117
+ }
118
+ /**
119
+ * Traces API.
120
+ */
121
+ export interface TracesAPI {
122
+ /**
123
+ * Start a new span.
124
+ */
125
+ startSpan(name: string, attributes?: Record<string, unknown>): Span;
126
+ }
127
+ /**
128
+ * Span interface.
129
+ */
130
+ export interface Span {
131
+ /**
132
+ * Set span status.
133
+ */
134
+ setStatus(status: 'ok' | 'error'): void;
135
+ /**
136
+ * Set span attribute.
137
+ */
138
+ setAttribute(key: string, value: unknown): void;
139
+ /**
140
+ * Record an exception.
141
+ */
142
+ recordException(error: Error): void;
143
+ /**
144
+ * End the span.
145
+ */
146
+ end(): void;
147
+ }
148
+ /**
149
+ * Logs API.
150
+ */
151
+ export interface LogsAPI {
152
+ /**
153
+ * Log an error.
154
+ */
155
+ error(message: string, error?: Error, context?: Record<string, unknown>): void;
156
+ /**
157
+ * Log a warning.
158
+ */
159
+ warn(message: string, context?: Record<string, unknown>): void;
160
+ /**
161
+ * Log info.
162
+ */
163
+ info(message: string, context?: Record<string, unknown>): void;
164
+ /**
165
+ * Log debug.
166
+ */
167
+ debug(message: string, context?: Record<string, unknown>): void;
168
+ }
169
+ /**
170
+ * Expression evaluation error.
171
+ */
172
+ export declare class ExpressionError extends Error {
173
+ context: {
174
+ expression?: string;
175
+ workflowId?: string;
176
+ nodeId?: string;
177
+ [key: string]: unknown;
178
+ };
179
+ constructor(message: string, context: {
180
+ expression?: string;
181
+ workflowId?: string;
182
+ nodeId?: string;
183
+ [key: string]: unknown;
184
+ });
185
+ }
186
+ /**
187
+ * Specific error types.
188
+ */
189
+ export declare class MemoryLimitError extends ExpressionError {
190
+ }
191
+ export declare class TimeoutError extends ExpressionError {
192
+ }
193
+ export declare class SecurityViolationError extends ExpressionError {
194
+ }
195
+ export declare class SyntaxError extends ExpressionError {
196
+ }
197
+ //# sourceMappingURL=evaluator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluator.d.ts","sourceRoot":"","sources":["../../src/types/evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAU9C,MAAM,WAAW,eAAe;IAC/B,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;IAC1C,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;CACzC;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,MAAM,EAAE,aAAa,CAAC;IAEtB;;OAEG;IACH,aAAa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UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB;gBAND,OAAO,EAAE,MAAM,EACR,OAAO,EAAE;QACf,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACvB;CAKF;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,eAAe;CAAG;AACxD,qBAAa,YAAa,SAAQ,eAAe;CAAG;AACpD,qBAAa,sBAAuB,SAAQ,eAAe;CAAG;AAC9D,qBAAa,WAAY,SAAQ,eAAe;CAAG"}
@@ -0,0 +1,29 @@
1
+ // ============================================================================
2
+ // Phase 1.4: Error Handling (IMPLEMENT WITH EVALUATOR)
3
+ //
4
+ // These error types provide structured error information.
5
+ // Start with basic Error, add these types in Phase 1.4.
6
+ // ============================================================================
7
+ /**
8
+ * Expression evaluation error.
9
+ */
10
+ export class ExpressionError extends Error {
11
+ context;
12
+ constructor(message, context) {
13
+ super(message);
14
+ this.context = context;
15
+ this.name = 'ExpressionError';
16
+ }
17
+ }
18
+ /**
19
+ * Specific error types.
20
+ */
21
+ export class MemoryLimitError extends ExpressionError {
22
+ }
23
+ export class TimeoutError extends ExpressionError {
24
+ }
25
+ export class SecurityViolationError extends ExpressionError {
26
+ }
27
+ export class SyntaxError extends ExpressionError {
28
+ }
29
+ //# sourceMappingURL=evaluator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../src/types/evaluator.ts"],"names":[],"mappings":"AAoNA,+EAA+E;AAC/E,uDAAuD;AACvD,EAAE;AACF,0DAA0D;AAC1D,wDAAwD;AACxD,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,eAAgB,SAAQ,KAAK;IAGjC;IAFR,YACC,OAAe,EACR,OAKN;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QAPR,YAAO,GAAP,OAAO,CAKb;QAGD,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAC/B,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;CAAG;AACxD,MAAM,OAAO,YAAa,SAAQ,eAAe;CAAG;AACpD,MAAM,OAAO,sBAAuB,SAAQ,eAAe;CAAG;AAC9D,MAAM,OAAO,WAAY,SAAQ,eAAe;CAAG"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Expression Runtime Types
3
+ *
4
+ * This module exports all TypeScript interfaces and types for the expression runtime.
5
+ */
6
+ export type { RuntimeBridge, BridgeConfig } from './bridge';
7
+ export type { RuntimeHostInterface, RuntimeGlobals, RuntimeConfig, LazyProxyConfig, } from './runtime';
8
+ export { RuntimeError } from './runtime';
9
+ export type { EvaluatorConfig, IExpressionEvaluator, WorkflowData, EvaluateOptions, ObservabilityProvider, MetricsAPI, TracesAPI, Span, LogsAPI, TournamentHooks, } from './evaluator';
10
+ export { ExpressionError, MemoryLimitError, TimeoutError, SecurityViolationError, SyntaxError, } from './evaluator';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG5D,YAAY,EACX,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,eAAe,GACf,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC,YAAY,EACX,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,IAAI,EACJ,OAAO,EACP,eAAe,GACf,MAAM,aAAa,CAAC;AAErB,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,WAAW,GACX,MAAM,aAAa,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Expression Runtime Types
3
+ *
4
+ * This module exports all TypeScript interfaces and types for the expression runtime.
5
+ */
6
+ export { RuntimeError } from './runtime';
7
+ export { ExpressionError, MemoryLimitError, TimeoutError, SecurityViolationError, SyntaxError, } from './evaluator';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAgBzC,OAAO,EACN,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,sBAAsB,EACtB,WAAW,GACX,MAAM,aAAa,CAAC"}
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Runtime interface exposed to isolated context.
3
+ *
4
+ * This interface defines what the runtime code (running inside the isolated context)
5
+ * can call. The bridge implements these functions on the host side.
6
+ */
7
+ export interface RuntimeHostInterface {
8
+ /**
9
+ * Get data from host by path (synchronous).
10
+ * Used by lazy loading proxies to fetch data on-demand.
11
+ *
12
+ * IMPORTANT: This is SYNCHRONOUS because JavaScript Proxy traps cannot be async.
13
+ * - IsolatedVmBridge: Uses ivm.Reference for true sync callbacks
14
+ * - WebWorkerBridge: Not supported - must pre-fetch all data
15
+ *
16
+ * @param path - Property path to fetch (e.g., "user.email", "items[0].json")
17
+ * @returns Value at the path, or undefined if not found
18
+ */
19
+ getDataSync(path: string): unknown;
20
+ }
21
+ /**
22
+ * Lazy-loading proxy for workflow data.
23
+ *
24
+ * At runtime, these appear as plain objects but are actually Proxy objects
25
+ * that fetch data on-demand from the host using getDataSync().
26
+ */
27
+ type LazyDataProxy = Record<string, unknown>;
28
+ /**
29
+ * Runtime globals available in isolated context.
30
+ *
31
+ * These are injected by the bridge when initializing the context.
32
+ */
33
+ export interface RuntimeGlobals {
34
+ /**
35
+ * Host interface for calling back to host process.
36
+ */
37
+ __host: RuntimeHostInterface;
38
+ /**
39
+ * Workflow data proxy ($json, $item, etc.).
40
+ * Set by bridge before each execute() call.
41
+ */
42
+ /** Current item data (lazy-loaded proxy) */
43
+ $json: LazyDataProxy;
44
+ /** Alias for $json (lazy-loaded proxy) */
45
+ $: LazyDataProxy;
46
+ /** Get item by index (lazy-loaded) */
47
+ $item: (index: number, runIndex?: number) => LazyDataProxy;
48
+ /** Access to all items */
49
+ $input: {
50
+ all: () => Array<{
51
+ json: LazyDataProxy;
52
+ }>;
53
+ first: () => {
54
+ json: LazyDataProxy;
55
+ } | undefined;
56
+ last: () => {
57
+ json: LazyDataProxy;
58
+ } | undefined;
59
+ item: {
60
+ json: LazyDataProxy;
61
+ };
62
+ };
63
+ /**
64
+ * Standard libraries available in runtime.
65
+ */
66
+ _: typeof import('lodash');
67
+ DateTime: typeof import('luxon').DateTime;
68
+ }
69
+ /**
70
+ * Configuration for runtime initialization.
71
+ */
72
+ export interface RuntimeConfig {
73
+ /**
74
+ * Enable debug logging in runtime.
75
+ * Default: false
76
+ */
77
+ debug?: boolean;
78
+ /**
79
+ * Custom timeout for data fetches.
80
+ * Default: 1000ms
81
+ */
82
+ dataFetchTimeout?: number;
83
+ }
84
+ /**
85
+ * Runtime error thrown inside isolated context.
86
+ *
87
+ * These errors are thrown by the runtime code when something goes wrong during
88
+ * expression evaluation. The bridge must catch these and translate them to the
89
+ * appropriate ExpressionError subclass (see evaluator.ts).
90
+ *
91
+ * Translation mapping:
92
+ * - code: 'MEMORY_LIMIT' → MemoryLimitError
93
+ * - code: 'TIMEOUT' → TimeoutError
94
+ * - code: 'SECURITY_VIOLATION' → SecurityViolationError
95
+ * - code: 'SYNTAX_ERROR' → SyntaxError
96
+ * - other → ExpressionError
97
+ */
98
+ export declare class RuntimeError extends Error {
99
+ code: string;
100
+ details?: Record<string, unknown> | undefined;
101
+ constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
102
+ }
103
+ /**
104
+ * Lazy proxy configuration.
105
+ */
106
+ export interface LazyProxyConfig {
107
+ /**
108
+ * Host interface for fetching data.
109
+ */
110
+ host: RuntimeHostInterface;
111
+ /**
112
+ * Property path prefix (for nested proxies).
113
+ * Example: If this proxy represents $json.user, pathPrefix would be "user"
114
+ */
115
+ pathPrefix?: string;
116
+ /**
117
+ * Cache for fetched values to avoid repeated host calls.
118
+ */
119
+ cache?: Map<string, unknown>;
120
+ }
121
+ export {};
122
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,MAAM,WAAW,oBAAoB;IACpC;;;;;;;;;;OAUG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CACnC;AAED;;;;;GAKG;AACH,KAAK,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE7C;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC9B;;OAEG;IACH,MAAM,EAAE,oBAAoB,CAAC;IAE7B;;;OAGG;IAEH,4CAA4C;IAC5C,KAAK,EAAE,aAAa,CAAC;IAErB,0CAA0C;IAC1C,CAAC,EAAE,aAAa,CAAC;IAEjB,sCAAsC;IACtC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,aAAa,CAAC;IAE3D,0BAA0B;IAC1B,MAAM,EAAE;QACP,GAAG,EAAE,MAAM,KAAK,CAAC;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC,CAAC;QAC1C,KAAK,EAAE,MAAM;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,GAAG,SAAS,CAAC;QACjD,IAAI,EAAE,MAAM;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,GAAG,SAAS,CAAC;QAChD,IAAI,EAAE;YAAE,IAAI,EAAE,aAAa,CAAA;SAAE,CAAC;KAC9B,CAAC;IAEF;;OAEG;IACH,CAAC,EAAE,cAAc,QAAQ,CAAC,CAAC;IAC3B,QAAQ,EAAE,cAAc,OAAO,EAAE,QAAQ,CAAC;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,YAAa,SAAQ,KAAK;IAG9B,IAAI,EAAE,MAAM;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFxC,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAKzC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,IAAI,EAAE,oBAAoB,CAAC;IAE3B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC7B"}
@@ -0,0 +1,31 @@
1
+ // ============================================================================
2
+ // Phase 1.1: Runtime Interfaces (IMPLEMENT WITH BRIDGE)
3
+ //
4
+ // These interfaces define how the runtime (inside isolation) communicates
5
+ // with the host. Implement these when building the runtime code.
6
+ // ============================================================================
7
+ /**
8
+ * Runtime error thrown inside isolated context.
9
+ *
10
+ * These errors are thrown by the runtime code when something goes wrong during
11
+ * expression evaluation. The bridge must catch these and translate them to the
12
+ * appropriate ExpressionError subclass (see evaluator.ts).
13
+ *
14
+ * Translation mapping:
15
+ * - code: 'MEMORY_LIMIT' → MemoryLimitError
16
+ * - code: 'TIMEOUT' → TimeoutError
17
+ * - code: 'SECURITY_VIOLATION' → SecurityViolationError
18
+ * - code: 'SYNTAX_ERROR' → SyntaxError
19
+ * - other → ExpressionError
20
+ */
21
+ export class RuntimeError extends Error {
22
+ code;
23
+ details;
24
+ constructor(message, code, details) {
25
+ super(message);
26
+ this.code = code;
27
+ this.details = details;
28
+ this.name = 'RuntimeError';
29
+ }
30
+ }
31
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/types/runtime.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wDAAwD;AACxD,EAAE;AACF,0EAA0E;AAC1E,iEAAiE;AACjE,+EAA+E;AAwF/E;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAG9B;IACA;IAHR,YACC,OAAe,EACR,IAAY,EACZ,OAAiC;QAExC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAA0B;QAGxC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC5B,CAAC;CACD"}
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@n8n/expression-runtime",
3
+ "version": "0.2.0",
4
+ "description": "Secure, isolated expression evaluation runtime for n8n",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "keywords": [
8
+ "n8n",
9
+ "expression",
10
+ "evaluation",
11
+ "isolated-vm",
12
+ "web-worker",
13
+ "security"
14
+ ],
15
+ "license": "SEE LICENSE IN LICENSE.md",
16
+ "dependencies": {
17
+ "js-base64": "3.7.2",
18
+ "jssha": "3.3.1",
19
+ "lodash": "4.17.23",
20
+ "luxon": "3.7.2",
21
+ "md5": "2.3.0",
22
+ "title-case": "3.0.3",
23
+ "transliteration": "2.3.5"
24
+ },
25
+ "devDependencies": {
26
+ "@types/lodash": "4.17.17",
27
+ "@types/luxon": "3.2.0",
28
+ "@types/md5": "^2.3.5",
29
+ "typescript": "5.9.2",
30
+ "vitest": "^3.1.3"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "ARCHITECTURE.md",
35
+ "LICENSE.md"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "test": "vitest run",
40
+ "test:dev": "vitest --watch --silent false",
41
+ "typecheck": "tsc --noEmit"
42
+ }
43
+ }