@teleporthq/teleport-plugin-next-workflows 0.43.47 → 0.43.48
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/__tests__/runtime-stringified-boolean-truthiness.test.ts +76 -0
- package/dist/cjs/executor-generator.d.ts.map +1 -1
- package/dist/cjs/executor-generator.js +12 -2
- package/dist/cjs/executor-generator.js.map +1 -1
- package/dist/cjs/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/executor-generator.d.ts.map +1 -1
- package/dist/esm/executor-generator.js +12 -2
- package/dist/esm/executor-generator.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/executor-generator.ts +12 -2
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { generateSharedRuntimeUtilsCode } from '../src'
|
|
2
|
+
|
|
3
|
+
// Producers that cannot type their output emit booleans as the strings
|
|
4
|
+
// "true"/"false" — the evaluate-auth custom-js most notably (see
|
|
5
|
+
// is-logged-in-gate.ts), plus any inspector text input. `is-true`/`is-false`
|
|
6
|
+
// and coerceForComparison already read those as booleans, but `is-truthy` was
|
|
7
|
+
// plain `!!left`, and the string "false" is truthy in JS: an is-truthy gate on
|
|
8
|
+
// isLoggedIn admitted EVERY visitor, and an is-falsy check never fired.
|
|
9
|
+
|
|
10
|
+
type SharedUtils = {
|
|
11
|
+
evaluateSingleComparison: (cfg: unknown, ctx: Record<string, unknown>) => boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function loadSharedRuntime(): SharedUtils {
|
|
15
|
+
const src = generateSharedRuntimeUtilsCode()
|
|
16
|
+
const wrapper: { exports: Record<string, unknown> } = { exports: {} }
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
18
|
+
new Function('module', 'exports', src)(wrapper, wrapper.exports)
|
|
19
|
+
return wrapper.exports as unknown as SharedUtils
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('workflow runtime truthiness of stringified booleans', () => {
|
|
23
|
+
const utils = loadSharedRuntime()
|
|
24
|
+
|
|
25
|
+
const isTruthy = (leftValue: unknown) =>
|
|
26
|
+
utils.evaluateSingleComparison({ leftValue, operator: 'is-truthy' }, {})
|
|
27
|
+
const isFalsy = (leftValue: unknown) =>
|
|
28
|
+
utils.evaluateSingleComparison({ leftValue, operator: 'is-falsy' }, {})
|
|
29
|
+
|
|
30
|
+
it('treats the string "false" as false, matching is-false and coerceForComparison', () => {
|
|
31
|
+
expect(isTruthy('false')).toBe(false)
|
|
32
|
+
expect(isFalsy('false')).toBe(true)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('keeps the string "true" true', () => {
|
|
36
|
+
expect(isTruthy('true')).toBe(true)
|
|
37
|
+
expect(isFalsy('true')).toBe(false)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('agrees with is-true/is-false on the same value', () => {
|
|
41
|
+
for (const value of ['true', 'false', true, false]) {
|
|
42
|
+
expect(isTruthy(value)).toBe(
|
|
43
|
+
utils.evaluateSingleComparison({ leftValue: value, operator: 'is-true' }, {})
|
|
44
|
+
)
|
|
45
|
+
expect(isFalsy(value)).toBe(
|
|
46
|
+
utils.evaluateSingleComparison({ leftValue: value, operator: 'is-false' }, {})
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('leaves ordinary JS truthiness untouched', () => {
|
|
52
|
+
expect(isTruthy(true)).toBe(true)
|
|
53
|
+
expect(isTruthy(false)).toBe(false)
|
|
54
|
+
expect(isTruthy('anything')).toBe(true)
|
|
55
|
+
expect(isTruthy('')).toBe(false)
|
|
56
|
+
expect(isTruthy(0)).toBe(false)
|
|
57
|
+
expect(isTruthy(1)).toBe(true)
|
|
58
|
+
expect(isTruthy(null)).toBe(false)
|
|
59
|
+
expect(isTruthy(undefined)).toBe(false)
|
|
60
|
+
expect(isFalsy('')).toBe(true)
|
|
61
|
+
expect(isFalsy(0)).toBe(true)
|
|
62
|
+
expect(isFalsy('anything')).toBe(false)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('normalizes the snake_case and camelCase spellings the same way', () => {
|
|
66
|
+
expect(utils.evaluateSingleComparison({ leftValue: 'false', operator: 'is_truthy' }, {})).toBe(
|
|
67
|
+
false
|
|
68
|
+
)
|
|
69
|
+
expect(utils.evaluateSingleComparison({ leftValue: 'false', operator: 'isTruthy' }, {})).toBe(
|
|
70
|
+
false
|
|
71
|
+
)
|
|
72
|
+
expect(utils.evaluateSingleComparison({ leftValue: 'false', operator: 'is_falsy' }, {})).toBe(
|
|
73
|
+
true
|
|
74
|
+
)
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-generator.d.ts","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,QAAO,
|
|
1
|
+
{"version":3,"file":"executor-generator.d.ts","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,QAAO,MAiuCjD,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAO,MA0f5C,CAAA;AAED,eAAO,MAAM,yBAAyB,QAAO,MAK5C,CAAA"}
|
|
@@ -543,6 +543,16 @@ function coerceForComparison(a, b) {
|
|
|
543
543
|
return [a, b];
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
// Several producers cannot type their output and emit booleans as the strings
|
|
547
|
+
// "true"/"false": the evaluate-auth custom-js, text inputs in the inspector,
|
|
548
|
+
// form fields. coerceForComparison and is-true/is-false already read those as
|
|
549
|
+
// booleans, so truthiness must agree — under a plain double-negation the
|
|
550
|
+
// string "false" is TRUTHY, which let an is-truthy gate on isLoggedIn admit
|
|
551
|
+
// every visitor (see is-logged-in-gate.ts).
|
|
552
|
+
function isStringifiedBoolean(value) {
|
|
553
|
+
return value === 'true' || value === 'false';
|
|
554
|
+
}
|
|
555
|
+
|
|
546
556
|
// The operator vocabulary is written by THREE producers that never agreed on
|
|
547
557
|
// a spelling: the worker canonicalizes to snake_case (is_not_empty,
|
|
548
558
|
// greater_than), the GUI editor emits camelCase named forms (startsWith,
|
|
@@ -587,8 +597,8 @@ function evaluateSingleComparison(config, context) {
|
|
|
587
597
|
case 'is-not-null': return left !== null && left !== undefined;
|
|
588
598
|
case 'is-true': return left === true || left === 'true';
|
|
589
599
|
case 'is-false': return left === false || left === 'false';
|
|
590
|
-
case 'is-truthy': return !!left;
|
|
591
|
-
case 'is-falsy': return !left;
|
|
600
|
+
case 'is-truthy': return isStringifiedBoolean(left) ? left === 'true' : !!left;
|
|
601
|
+
case 'is-falsy': return isStringifiedBoolean(left) ? left === 'false' : !left;
|
|
592
602
|
case 'matches-regex': try { return new RegExp(String(right)).test(String(left)); } catch(e) { return false; }
|
|
593
603
|
default:
|
|
594
604
|
console.warn('[workflow] Unknown comparison operator "' + config.operator + '" — falling back to loose equality');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor-generator.js","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":";;;AAAO,MAAM,8BAA8B,GAAG,GAAW,EAAE;IACzD,OAAO
|
|
1
|
+
{"version":3,"file":"executor-generator.js","sourceRoot":"","sources":["../../src/executor-generator.ts"],"names":[],"mappings":";;;AAAO,MAAM,8BAA8B,GAAG,GAAW,EAAE;IACzD,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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