@requesto/cli 1.8.1 → 1.10.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.
- package/dist/index.mjs +9293 -8524
- package/dist/sandbox-worker.js +193 -4
- package/package.json +7 -7
package/dist/sandbox-worker.js
CHANGED
|
@@ -1,7 +1,193 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
try {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
throw mod = 0, e;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
|
|
31
|
+
// ../backend/dist/utils/variable-substitution.js
|
|
32
|
+
var require_variable_substitution = __commonJS({
|
|
33
|
+
"../backend/dist/utils/variable-substitution.js"(exports) {
|
|
34
|
+
"use strict";
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.substituteVariables = substituteVariables;
|
|
37
|
+
exports.substituteJsonVariables = substituteJsonVariables;
|
|
38
|
+
exports.isNumericLiteral = isNumericLiteral;
|
|
39
|
+
exports.inferType = inferType2;
|
|
40
|
+
exports.substituteInRequest = substituteInRequest;
|
|
41
|
+
exports.substituteInAuth = substituteInAuth;
|
|
42
|
+
function substituteVariables(text, environment) {
|
|
43
|
+
if (!environment)
|
|
44
|
+
return text;
|
|
45
|
+
const values = getResolvedValues(environment);
|
|
46
|
+
let result = text;
|
|
47
|
+
for (const [key, entry] of values) {
|
|
48
|
+
const pattern = new RegExp(`{{\\s*${escapeRegex(key)}\\s*}}`, "g");
|
|
49
|
+
result = result.replace(pattern, entry.value);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function substituteJsonVariables(text, environment) {
|
|
54
|
+
if (!environment)
|
|
55
|
+
return text;
|
|
56
|
+
const values = getResolvedValues(environment);
|
|
57
|
+
let result = text;
|
|
58
|
+
for (const [key, entry] of values) {
|
|
59
|
+
const keyPattern = escapeRegex(key);
|
|
60
|
+
const quoted = new RegExp(`"{{\\s*${keyPattern}\\s*}}"`, "g");
|
|
61
|
+
const literal = typedJsonLiteral(entry.value, entry.type);
|
|
62
|
+
result = result.replace(quoted, literal ?? JSON.stringify(entry.value));
|
|
63
|
+
const plain = new RegExp(`{{\\s*${keyPattern}\\s*}}`, "g");
|
|
64
|
+
result = result.replace(plain, entry.value);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
function typedJsonLiteral(value, type) {
|
|
69
|
+
if (type === "boolean") {
|
|
70
|
+
return value === "true" || value === "false" ? value : null;
|
|
71
|
+
}
|
|
72
|
+
if (type === "number") {
|
|
73
|
+
return isNumericLiteral(value) ? value : null;
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
function getResolvedValues(environment) {
|
|
78
|
+
const raw = /* @__PURE__ */ new Map();
|
|
79
|
+
for (const variable of environment.variables) {
|
|
80
|
+
if (variable.enabled) {
|
|
81
|
+
raw.set(variable.key, {
|
|
82
|
+
value: variable.currentValue ?? variable.value,
|
|
83
|
+
type: variable.type
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
88
|
+
const visiting = /* @__PURE__ */ new Set();
|
|
89
|
+
const resolve = (key) => {
|
|
90
|
+
const memo = resolved.get(key);
|
|
91
|
+
if (memo !== void 0)
|
|
92
|
+
return memo;
|
|
93
|
+
if (visiting.has(key)) {
|
|
94
|
+
const entry2 = raw.get(key);
|
|
95
|
+
return { value: entry2?.value ?? "", type: entry2?.type };
|
|
96
|
+
}
|
|
97
|
+
visiting.add(key);
|
|
98
|
+
const entry = raw.get(key) ?? { value: "", type: void 0 };
|
|
99
|
+
const value = entry.value.replace(/\{\{\s*([^{}]+?)\s*\}\}/g, (match, name) => {
|
|
100
|
+
const referenced = name.trim();
|
|
101
|
+
return raw.has(referenced) ? resolve(referenced).value : match;
|
|
102
|
+
});
|
|
103
|
+
visiting.delete(key);
|
|
104
|
+
const result = { value, type: entry.type };
|
|
105
|
+
resolved.set(key, result);
|
|
106
|
+
return result;
|
|
107
|
+
};
|
|
108
|
+
for (const key of raw.keys())
|
|
109
|
+
resolve(key);
|
|
110
|
+
return resolved;
|
|
111
|
+
}
|
|
112
|
+
function isNumericLiteral(value) {
|
|
113
|
+
return /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/.test(value.trim());
|
|
114
|
+
}
|
|
115
|
+
function inferType2(value) {
|
|
116
|
+
if (typeof value === "number") {
|
|
117
|
+
return Number.isFinite(value) ? "number" : "string";
|
|
118
|
+
}
|
|
119
|
+
if (typeof value === "boolean")
|
|
120
|
+
return "boolean";
|
|
121
|
+
if (typeof value === "string") {
|
|
122
|
+
if (value === "true" || value === "false")
|
|
123
|
+
return "boolean";
|
|
124
|
+
if (isNumericLiteral(value))
|
|
125
|
+
return "number";
|
|
126
|
+
}
|
|
127
|
+
return "string";
|
|
128
|
+
}
|
|
129
|
+
function escapeRegex(str) {
|
|
130
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
131
|
+
}
|
|
132
|
+
function substituteInRequest(request, environment) {
|
|
133
|
+
const jsonMode = request.bodyType === "json" || !request.bodyType && !!request.body;
|
|
134
|
+
const bodySub = jsonMode ? substituteJsonVariables : substituteVariables;
|
|
135
|
+
return {
|
|
136
|
+
url: substituteUrlVariables(request.url, environment),
|
|
137
|
+
headers: request.headers ? Object.fromEntries(Object.entries(request.headers).map(([key, value]) => [
|
|
138
|
+
key,
|
|
139
|
+
substituteVariables(value, environment)
|
|
140
|
+
])) : void 0,
|
|
141
|
+
body: request.body ? bodySub(request.body, environment) : void 0,
|
|
142
|
+
formDataEntries: request.formDataEntries ? request.formDataEntries.map((entry) => ({
|
|
143
|
+
...entry,
|
|
144
|
+
key: substituteVariables(entry.key, environment),
|
|
145
|
+
value: entry.type === "text" ? substituteVariables(entry.value, environment) : entry.value
|
|
146
|
+
})) : void 0
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function substituteUrlVariables(url, environment) {
|
|
150
|
+
const substituted = substituteVariables(url, environment);
|
|
151
|
+
if (!environment || !substituted.includes("="))
|
|
152
|
+
return substituted;
|
|
153
|
+
try {
|
|
154
|
+
const parsed = new URL(substituted);
|
|
155
|
+
const variables = parsed.searchParams.get("variables");
|
|
156
|
+
if (variables && variables.includes("{{")) {
|
|
157
|
+
parsed.searchParams.set("variables", substituteJsonVariables(variables, environment));
|
|
158
|
+
return parsed.toString();
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
}
|
|
162
|
+
return substituted;
|
|
163
|
+
}
|
|
164
|
+
function substituteInAuth(auth, environment) {
|
|
165
|
+
if (!auth)
|
|
166
|
+
return auth;
|
|
167
|
+
const sub = (v) => substituteVariables(v, environment);
|
|
168
|
+
switch (auth.type) {
|
|
169
|
+
case "basic":
|
|
170
|
+
return auth.basic ? { ...auth, basic: { username: sub(auth.basic.username), password: sub(auth.basic.password) } } : auth;
|
|
171
|
+
case "bearer":
|
|
172
|
+
return auth.bearer ? { ...auth, bearer: { token: sub(auth.bearer.token) } } : auth;
|
|
173
|
+
case "api-key":
|
|
174
|
+
return auth.apiKey ? { ...auth, apiKey: { ...auth.apiKey, key: sub(auth.apiKey.key), value: sub(auth.apiKey.value) } } : auth;
|
|
175
|
+
case "digest":
|
|
176
|
+
return auth.digest ? { ...auth, digest: { username: sub(auth.digest.username), password: sub(auth.digest.password) } } : auth;
|
|
177
|
+
case "oauth":
|
|
178
|
+
case "none":
|
|
179
|
+
default:
|
|
180
|
+
return auth;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
1
186
|
// ../../packages/engine/dist/scripts/sandbox-worker.js
|
|
2
187
|
import { parentPort } from "node:worker_threads";
|
|
3
188
|
|
|
4
189
|
// ../../packages/engine/dist/scripts/sandbox-core.js
|
|
190
|
+
var import_variable_substitution = __toESM(require_variable_substitution(), 1);
|
|
5
191
|
var SHADOWED_GLOBALS = `
|
|
6
192
|
"use strict";
|
|
7
193
|
const self = undefined;
|
|
@@ -58,28 +244,31 @@ function createExpect(actual, inverted = false) {
|
|
|
58
244
|
}
|
|
59
245
|
function createEnvironment(env) {
|
|
60
246
|
const envStore = { ...env };
|
|
247
|
+
const typeStore = {};
|
|
61
248
|
return {
|
|
62
249
|
store: envStore,
|
|
250
|
+
types: typeStore,
|
|
63
251
|
api: {
|
|
64
252
|
get: (key) => envStore[key] ?? "",
|
|
65
253
|
set: (key, value) => {
|
|
66
254
|
envStore[key] = String(value);
|
|
255
|
+
typeStore[key] = (0, import_variable_substitution.inferType)(value);
|
|
67
256
|
}
|
|
68
257
|
}
|
|
69
258
|
};
|
|
70
259
|
}
|
|
71
260
|
function executePreRequestScript(script, context) {
|
|
72
|
-
const { store, api } = createEnvironment(context.env);
|
|
261
|
+
const { store, types, api } = createEnvironment(context.env);
|
|
73
262
|
const request = { ...context.request };
|
|
74
263
|
const fn = new Function("environment", "request", `${SHADOWED_GLOBALS}
|
|
75
264
|
${script}`);
|
|
76
265
|
fn(api, request);
|
|
77
|
-
return { envOverrides: store };
|
|
266
|
+
return { envOverrides: store, envTypes: types };
|
|
78
267
|
}
|
|
79
268
|
function executeTestScript(script, context) {
|
|
80
269
|
const results = [];
|
|
81
270
|
const { response: responseCtx, request } = context;
|
|
82
|
-
const { store, api } = createEnvironment(context.env);
|
|
271
|
+
const { store, types, api } = createEnvironment(context.env);
|
|
83
272
|
const response = {
|
|
84
273
|
status: responseCtx.status,
|
|
85
274
|
statusText: responseCtx.statusText,
|
|
@@ -104,7 +293,7 @@ function executeTestScript(script, context) {
|
|
|
104
293
|
const fn = new Function("test", "expect", "response", "request", "environment", `${SHADOWED_GLOBALS}
|
|
105
294
|
${script}`);
|
|
106
295
|
fn(test, expect, response, request, api);
|
|
107
|
-
return { testResults: results, envOverrides: store };
|
|
296
|
+
return { testResults: results, envOverrides: store, envTypes: types };
|
|
108
297
|
}
|
|
109
298
|
|
|
110
299
|
// ../../packages/engine/dist/scripts/sandbox-worker.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@requesto/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Run your Requesto collections from the terminal and CI pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"commander": "^15.0.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/node": "^26.4.
|
|
28
|
-
"esbuild": "^0.28.
|
|
29
|
-
"requesto-backend": "1.
|
|
30
|
-
"requesto-engine": "1.
|
|
31
|
-
"tsx": "^4.23.
|
|
27
|
+
"@types/node": "^26.4.1",
|
|
28
|
+
"esbuild": "^0.28.2",
|
|
29
|
+
"requesto-backend": "1.10.0",
|
|
30
|
+
"requesto-engine": "1.10.0",
|
|
31
|
+
"tsx": "^4.23.13",
|
|
32
32
|
"typescript": "^7.0.2",
|
|
33
|
-
"vitest": "^
|
|
33
|
+
"vitest": "^5.0.0"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|