@memberjunction/code-execution 2.115.0 → 2.116.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,166 @@
1
+ const { CodeExecutionService } = require('./dist/index.js');
2
+
3
+ async function testAllLibraries() {
4
+ const service = new CodeExecutionService();
5
+ await service.initialize();
6
+
7
+ const tests = [
8
+ {
9
+ name: 'lodash',
10
+ code: `
11
+ const _ = require('lodash');
12
+ const data = [
13
+ { category: 'A', value: 10 },
14
+ { category: 'B', value: 20 },
15
+ { category: 'A', value: 15 }
16
+ ];
17
+ const grouped = _.groupBy(data, 'category');
18
+ const summed = _.mapValues(grouped, items => _.sumBy(items, 'value'));
19
+ output = { grouped: Object.keys(grouped), sums: summed };
20
+ `,
21
+ inputData: {}
22
+ },
23
+ {
24
+ name: 'date-fns',
25
+ code: `
26
+ const { format, addDays, differenceInDays } = require('date-fns');
27
+ const today = new Date('2024-01-01');
28
+ const future = addDays(today, 30);
29
+ output = {
30
+ today: format(today, 'yyyy-MM-dd'),
31
+ future: format(future, 'yyyy-MM-dd'),
32
+ diff: differenceInDays(future, today)
33
+ };
34
+ `,
35
+ inputData: {}
36
+ },
37
+ {
38
+ name: 'mathjs',
39
+ code: `
40
+ const math = require('mathjs');
41
+ const values = input.values;
42
+ output = {
43
+ mean: math.mean(values),
44
+ median: math.median(values),
45
+ std: math.std(values),
46
+ variance: math.variance(values)
47
+ };
48
+ `,
49
+ inputData: { values: [10, 20, 30, 40, 50] }
50
+ },
51
+ {
52
+ name: 'papaparse',
53
+ code: `
54
+ const Papa = require('papaparse');
55
+ const parsed = Papa.parse(input.csv, {
56
+ header: true,
57
+ dynamicTyping: true
58
+ });
59
+ output = {
60
+ rowCount: parsed.data.length,
61
+ headers: parsed.meta.fields,
62
+ firstRow: parsed.data[0]
63
+ };
64
+ `,
65
+ inputData: { csv: 'name,age,city\\nAlice,30,NYC\\nBob,25,SF' }
66
+ },
67
+ {
68
+ name: 'jstat',
69
+ code: `
70
+ const jStat = require('jstat');
71
+ const data = input.data;
72
+ const mean = jStat.mean(data);
73
+ const stdev = jStat.stdev(data);
74
+ output = {
75
+ mean: mean,
76
+ stdev: stdev,
77
+ normalProb: jStat.normal.cdf(35, mean, stdev)
78
+ };
79
+ `,
80
+ inputData: { data: [20, 25, 30, 35, 40, 45, 50] }
81
+ },
82
+ {
83
+ name: 'uuid',
84
+ code: `
85
+ const uuid = require('uuid');
86
+ const id1 = uuid.v4();
87
+ const id2 = uuid.v4();
88
+ output = {
89
+ uuid1: id1,
90
+ uuid2: id2,
91
+ different: id1 !== id2,
92
+ validFormat: /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id1)
93
+ };
94
+ `,
95
+ inputData: {}
96
+ },
97
+ {
98
+ name: 'validator',
99
+ code: `
100
+ const validator = require('validator');
101
+ output = {
102
+ emailValid: validator.isEmail('test@example.com'),
103
+ emailInvalid: validator.isEmail('not-an-email'),
104
+ urlValid: validator.isURL('https://example.com')
105
+ };
106
+ `,
107
+ inputData: {}
108
+ }
109
+ ];
110
+
111
+ let allPassed = true;
112
+
113
+ for (const test of tests) {
114
+ console.log(`\n========================================`);
115
+ console.log(`Testing: ${test.name}`);
116
+ console.log(`========================================`);
117
+
118
+ try {
119
+ const result = await service.execute({
120
+ code: test.code,
121
+ language: 'javascript',
122
+ inputData: test.inputData,
123
+ timeoutSeconds: 30,
124
+ memoryLimitMB: 128
125
+ });
126
+
127
+ if (result.success) {
128
+ console.log(`✅ ${test.name} test PASSED`);
129
+ console.log('Output:', JSON.stringify(result.output, null, 2));
130
+ console.log('Execution time:', result.executionTimeMs, 'ms');
131
+ if (result.logs && result.logs.length > 0) {
132
+ console.log('Logs:', result.logs);
133
+ }
134
+ } else {
135
+ console.log(`❌ ${test.name} test FAILED`);
136
+ console.log('Error:', result.error);
137
+ console.log('Error type:', result.errorType);
138
+ allPassed = false;
139
+ }
140
+ } catch (error) {
141
+ console.log(`❌ ${test.name} test FAILED with exception`);
142
+ console.log('Error:', error.message);
143
+ console.log('Stack:', error.stack);
144
+ allPassed = false;
145
+ }
146
+ }
147
+
148
+ await service.shutdown();
149
+
150
+ console.log('\n========================================');
151
+ console.log('Test Summary');
152
+ console.log('========================================');
153
+ if (allPassed) {
154
+ console.log('✅ ALL TESTS PASSED!');
155
+ process.exit(0);
156
+ } else {
157
+ console.log('❌ SOME TESTS FAILED');
158
+ process.exit(1);
159
+ }
160
+ }
161
+
162
+ testAllLibraries().catch(error => {
163
+ console.error('Fatal error:', error);
164
+ console.error('Stack:', error.stack);
165
+ process.exit(1);
166
+ });
@@ -0,0 +1,39 @@
1
+ const { CodeExecutionService } = require('./dist/index.js');
2
+
3
+ async function testLodash() {
4
+ const service = new CodeExecutionService();
5
+ await service.initialize();
6
+
7
+ console.log('\n=== Testing JUST simple code (no library) ===');
8
+ const simpleTest = await service.execute({
9
+ code: `
10
+ const numbers = [1, 2, 3, 4, 5];
11
+ const sum = numbers.reduce((a, b) => a + b, 0);
12
+ output = { sum, count: numbers.length };
13
+ `,
14
+ language: 'javascript'
15
+ });
16
+ console.log('Simple test (no require):');
17
+ console.log(' Success:', simpleTest.success);
18
+ console.log(' Output:', JSON.stringify(simpleTest.output, null, 2));
19
+ console.log(' Error:', simpleTest.error);
20
+
21
+ console.log('\n=== Testing lodash with require ===');
22
+ const lodashTest = await service.execute({
23
+ code: `
24
+ const _ = require('lodash');
25
+ const numbers = [1, 2, 3, 4, 5];
26
+ const sum = _.sum(numbers);
27
+ output = { sum, mean: _.mean(numbers) };
28
+ `,
29
+ language: 'javascript'
30
+ });
31
+ console.log('Lodash test:');
32
+ console.log(' Success:', lodashTest.success);
33
+ console.log(' Output:', JSON.stringify(lodashTest.output, null, 2));
34
+ console.log(' Error:', lodashTest.error);
35
+
36
+ await service.shutdown();
37
+ }
38
+
39
+ testLodash().catch(console.error);
package/test-simple.js ADDED
@@ -0,0 +1,29 @@
1
+ const { CodeExecutionService } = require('./dist/index.js');
2
+
3
+ async function test() {
4
+ const service = new CodeExecutionService();
5
+ await service.initialize();
6
+
7
+ // Ultra simple test
8
+ const result1 = await service.execute({
9
+ code: `output = { test: 'simple' };`,
10
+ language: 'javascript',
11
+ inputData: {}
12
+ });
13
+ console.log('Test 1 (simple):', JSON.stringify(result1));
14
+
15
+ // Test with lodash
16
+ const result2 = await service.execute({
17
+ code: `
18
+ const _ = require('lodash');
19
+ output = { sum: _.sum([1,2,3]) };
20
+ `,
21
+ language: 'javascript',
22
+ inputData: {}
23
+ });
24
+ console.log('Test 2 (lodash):', JSON.stringify(result2));
25
+
26
+ await service.shutdown();
27
+ }
28
+
29
+ test();
@@ -0,0 +1,24 @@
1
+ const { CodeExecutionService } = require('./dist/index.js');
2
+
3
+ async function quickTest() {
4
+ const service = new CodeExecutionService();
5
+ await service.initialize();
6
+
7
+ // Test lodash
8
+ const result = await service.execute({
9
+ code: `
10
+ const _ = require('lodash');
11
+ const sum = _.sum([1, 2, 3, 4, 5]);
12
+ console.log('Sum:', sum);
13
+ output = { sum: sum, library: 'lodash' };
14
+ `,
15
+ language: 'javascript',
16
+ inputData: {}
17
+ });
18
+
19
+ console.log('Result:', JSON.stringify(result, null, 2));
20
+
21
+ await service.shutdown();
22
+ }
23
+
24
+ quickTest();