Skip to content

Commit 5de74db

Browse files
authored
Merge pull request #1114 from OpenFn/release/next
Release/next
2 parents 5d2ccdf + 3e58a4e commit 5de74db

File tree

14 files changed

+144
-15
lines changed

14 files changed

+144
-15
lines changed

packages/cli/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @openfn/cli
22

3+
## 1.18.2
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [fe06f44]
8+
- @openfn/runtime@1.7.5
9+
310
## 1.18.1
411

512
### Patch Changes

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/cli",
3-
"version": "1.18.1",
3+
"version": "1.18.2",
44
"description": "CLI devtools for the OpenFn toolchain",
55
"engines": {
66
"node": ">=18",

packages/engine-multi/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# engine-multi
22

3+
## 1.8.3
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [fe06f44]
8+
- @openfn/runtime@1.7.5
9+
310
## 1.8.2
411

512
### Patch Changes

packages/engine-multi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/engine-multi",
3-
"version": "1.8.2",
3+
"version": "1.8.3",
44
"description": "Multi-process runtime engine",
55
"main": "dist/index.js",
66
"type": "module",

packages/lightning-mock/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# @openfn/lightning-mock
22

3+
## 2.3.6
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [fe06f44]
8+
- @openfn/runtime@1.7.5
9+
- @openfn/engine-multi@1.8.3
10+
311
## 2.3.5
412

513
### Patch Changes

packages/lightning-mock/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/lightning-mock",
3-
"version": "2.3.5",
3+
"version": "2.3.6",
44
"private": true,
55
"description": "A mock Lightning server",
66
"main": "dist/index.js",

packages/runtime/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @openfn/runtime
22

3+
## 1.7.5
4+
5+
### Patch Changes
6+
7+
- fe06f44: Expose Buffer to runtime context. Quite safe in node 20+
8+
39
## 1.7.4
410

511
### Patch Changes

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openfn/runtime",
3-
"version": "1.7.4",
3+
"version": "1.7.5",
44
"description": "Job processing runtime.",
55
"type": "module",
66
"exports": {

packages/runtime/src/execute/context.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@ export default (
2121
) => {
2222
const logger = options.jobLogger ?? console;
2323
const globals = options.globals || {};
24+
25+
// Workaround for https://github.com/nodejs/node/issues/4660
26+
// The Buffer class we share directly with users will throw if used
27+
// All _internal_ Buffer references use the original nodejs interface
28+
class SafeBuffer extends Buffer {
29+
constructor(x: any) {
30+
throw new Error(
31+
'Do not call Buffer() constructor directly. Use Buffer.from() instead.'
32+
);
33+
super(x); // keeps types happy
34+
}
35+
}
36+
2437
const context = vm.createContext(
2538
freezeAll(
2639
{
@@ -34,6 +47,7 @@ export default (
3447
setInterval,
3548
setTimeout,
3649
state, // TODO will be dropped as a global one day, see https://github.com/OpenFn/kit/issues/17
50+
Buffer: SafeBuffer,
3751
},
3852
{ state: true }
3953
),

packages/runtime/test/context.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,27 @@ test("doesn't allow eval inside a job", async (t) => {
6060
message: /Illegal eval statement detected/,
6161
});
6262
});
63+
64+
test('Buffer.from() works inside a job', async (t) => {
65+
const expression = `
66+
export default [
67+
(s) => { s.data = Buffer.from('6a6f65', 'hex').toString(); return s; }
68+
];`;
69+
const input = {};
70+
71+
const result = await run(expression, input);
72+
t.is(result.data as any, 'joe');
73+
});
74+
75+
test('Buffer constructor throws inside a job', async (t) => {
76+
const expression = `
77+
export default [
78+
(s) => { s.data = new Buffer('6a6f65', 'hex').toString(); return s; }
79+
];`;
80+
const input = {};
81+
82+
const result = await run(expression, input);
83+
const err = result.errors!['job-1'];
84+
t.is(err.name, 'JobError');
85+
t.regex(err.message, /do not call Buffer\(\) constructor/i);
86+
});

0 commit comments

Comments
 (0)