@intuned/runtime-dev 0.1.0-test.1 → 0.1.0-test.11
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/.babelrc +3 -1
- package/Intuned.json +1 -1
- package/api/test2.ts +1 -4
- package/dist/commands/api/run.js +27 -35
- package/dist/commands/auth-sessions/load.js +11 -13
- package/dist/commands/auth-sessions/run-check.js +14 -19
- package/dist/commands/auth-sessions/run-create.js +23 -28
- package/dist/commands/browser/save-state.js +7 -10
- package/dist/commands/browser/start-browser.js +7 -10
- package/dist/commands/build.js +25 -30
- package/dist/commands/common/browserUtils.js +15 -28
- package/dist/commands/common/getDefaultExportFromFile.js +2 -10
- package/dist/commands/common/getFirstLineNumber.js +13 -20
- package/dist/commands/common/getFirstLineNumber.test.js +46 -51
- package/dist/commands/common/sendMessageToClient.js +2 -9
- package/dist/commands/common/utils/fileUtils.js +6 -16
- package/dist/commands/common/utils/settings.js +7 -13
- package/dist/commands/common/utils/unixSocket.js +2 -9
- package/dist/commands/common/utils/webTemplate.js +7 -16
- package/dist/commands/interface/run.js +34 -39
- package/dist/commands/ts-check.js +8 -12
- package/dist/common/Logger/Logger/index.js +9 -16
- package/dist/common/Logger/Logger/types.js +1 -5
- package/dist/common/Logger/index.js +9 -16
- package/dist/common/Logger/types.js +1 -5
- package/dist/common/asyncLocalStorage/index.js +4 -12
- package/dist/common/cleanEnvironmentVariables.js +1 -7
- package/dist/common/constants.js +1 -7
- package/dist/common/contextStorageStateHelpers.js +2 -9
- package/dist/common/getPlaywrightConstructs.js +28 -39
- package/dist/common/jwtTokenManager.js +8 -18
- package/dist/common/runApi/errors.js +24 -42
- package/dist/common/runApi/index.js +53 -88
- package/dist/common/runApi/types.js +31 -38
- package/dist/common/settingsSchema.js +2 -10
- package/dist/common/telemetry.js +3 -12
- package/dist/index.js +4 -69
- package/dist/runtime/RunError.js +1 -8
- package/dist/runtime/downloadDirectory.js +5 -11
- package/dist/runtime/enums.d.js +1 -5
- package/dist/runtime/enums.js +2 -8
- package/dist/runtime/executionHelpers.test.js +20 -22
- package/dist/runtime/export.d.js +1 -5
- package/dist/runtime/extendPayload.js +5 -11
- package/dist/runtime/extendTimeout.js +3 -9
- package/dist/runtime/index.js +6 -53
- package/dist/runtime/requestMoreInfo.js +2 -9
- package/dist/runtime/runInfo.js +5 -11
- package/package.json +3 -1
- package/preserve-dynamic-imports.js +16 -0
|
@@ -1,52 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _asyncLocalStorage = require("../asyncLocalStorage");
|
|
16
|
-
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
17
|
-
var fs = _fsExtra;
|
|
18
|
-
var _jwtTokenManager = require("../jwtTokenManager");
|
|
19
|
-
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
20
|
-
var _neverthrow = require("neverthrow");
|
|
21
|
-
var _errors = require("./errors");
|
|
22
|
-
Object.keys(_errors).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
25
|
-
if (key in exports && exports[key] === _errors[key]) return;
|
|
26
|
-
Object.defineProperty(exports, key, {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return _errors[key];
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
var _constants = require("../constants");
|
|
34
|
-
var _getPlaywrightConstructs = require("../getPlaywrightConstructs");
|
|
35
|
-
var _types = require("./types");
|
|
36
|
-
Object.keys(_types).forEach(function (key) {
|
|
37
|
-
if (key === "default" || key === "__esModule") return;
|
|
38
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
39
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
40
|
-
Object.defineProperty(exports, key, {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
get: function () {
|
|
43
|
-
return _types[key];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
48
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
49
|
-
async function* runApiGenerator({
|
|
1
|
+
import { getDownloadDirectoryPath } from "../../runtime/downloadDirectory";
|
|
2
|
+
import { getExecutionContext } from "../asyncLocalStorage";
|
|
3
|
+
import * as fs from "fs-extra";
|
|
4
|
+
import { backendFunctionsTokenManager } from "../jwtTokenManager";
|
|
5
|
+
import { getContextStorageState, setContextStorageState } from "../contextStorageStateHelpers";
|
|
6
|
+
import { remove } from "fs-extra";
|
|
7
|
+
import { ok, err } from "neverthrow";
|
|
8
|
+
import { AbortedError, ApiNotFoundError, AutomationError, InvalidApiError, InvalidCheckError, MaxLevelsExceededError } from "./errors";
|
|
9
|
+
import { AUTH_SESSIONS_FOLDER_NAME } from "../constants";
|
|
10
|
+
import { getPlaywrightConstructsForMode, getProductionPlaywrightConstructs } from "../getPlaywrightConstructs";
|
|
11
|
+
import { runApiParametersSchema } from "./types";
|
|
12
|
+
export * from "./types";
|
|
13
|
+
export * from "./errors";
|
|
14
|
+
export async function* runApiGenerator({
|
|
50
15
|
retrieveSession = false,
|
|
51
16
|
abortSignal,
|
|
52
17
|
...input
|
|
@@ -58,9 +23,9 @@ async function* runApiGenerator({
|
|
|
58
23
|
tracing,
|
|
59
24
|
auth,
|
|
60
25
|
functionsToken
|
|
61
|
-
} =
|
|
62
|
-
|
|
63
|
-
const downloadsPath =
|
|
26
|
+
} = runApiParametersSchema.parse(input);
|
|
27
|
+
backendFunctionsTokenManager.token = functionsToken;
|
|
28
|
+
const downloadsPath = getDownloadDirectoryPath();
|
|
64
29
|
let page;
|
|
65
30
|
let context;
|
|
66
31
|
if (runOptions.environment === "deployed") {
|
|
@@ -71,7 +36,7 @@ async function* runApiGenerator({
|
|
|
71
36
|
({
|
|
72
37
|
page,
|
|
73
38
|
context
|
|
74
|
-
} = await
|
|
39
|
+
} = await getProductionPlaywrightConstructs({
|
|
75
40
|
headless,
|
|
76
41
|
proxy,
|
|
77
42
|
downloadsPath,
|
|
@@ -85,9 +50,9 @@ async function* runApiGenerator({
|
|
|
85
50
|
({
|
|
86
51
|
page,
|
|
87
52
|
context
|
|
88
|
-
} = await
|
|
53
|
+
} = await getPlaywrightConstructsForMode(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
|
|
89
54
|
}
|
|
90
|
-
const executionContext =
|
|
55
|
+
const executionContext = getExecutionContext();
|
|
91
56
|
if (!executionContext) {
|
|
92
57
|
throw "";
|
|
93
58
|
}
|
|
@@ -103,7 +68,7 @@ async function* runApiGenerator({
|
|
|
103
68
|
});
|
|
104
69
|
} catch (error) {
|
|
105
70
|
console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
|
|
106
|
-
await
|
|
71
|
+
await remove(tracing.filePath);
|
|
107
72
|
}
|
|
108
73
|
}
|
|
109
74
|
if (tracing.enabled) {
|
|
@@ -122,13 +87,13 @@ async function* runApiGenerator({
|
|
|
122
87
|
});
|
|
123
88
|
});
|
|
124
89
|
if (auth && auth.session.type === "state") {
|
|
125
|
-
await
|
|
90
|
+
await setContextStorageState(context, auth.session.state);
|
|
126
91
|
}
|
|
127
92
|
async function* runAutomation() {
|
|
128
93
|
var _getExecutionContext;
|
|
129
94
|
if (auth !== null && auth !== void 0 && auth.runCheck) {
|
|
130
95
|
if (!auth.session) {
|
|
131
|
-
return
|
|
96
|
+
return err({
|
|
132
97
|
code: "AuthRequiredError"
|
|
133
98
|
});
|
|
134
99
|
}
|
|
@@ -137,12 +102,12 @@ async function* runApiGenerator({
|
|
|
137
102
|
if (authCheckResult.isErr()) {
|
|
138
103
|
const error = authCheckResult.error;
|
|
139
104
|
if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
|
|
140
|
-
return
|
|
105
|
+
return err(new InvalidCheckError(`Auth session check function failed`, error));
|
|
141
106
|
}
|
|
142
107
|
return authCheckResult;
|
|
143
108
|
}
|
|
144
109
|
if (!authCheckResult.value) {
|
|
145
|
-
return
|
|
110
|
+
return err({
|
|
146
111
|
code: "AuthCheckFailedError"
|
|
147
112
|
});
|
|
148
113
|
}
|
|
@@ -169,10 +134,10 @@ async function* runApiGenerator({
|
|
|
169
134
|
} else {
|
|
170
135
|
result = await importResult.value.func(...args);
|
|
171
136
|
}
|
|
172
|
-
return
|
|
137
|
+
return ok({
|
|
173
138
|
result,
|
|
174
|
-
extendedPayloads: (_getExecutionContext =
|
|
175
|
-
session: retrieveSession ? await
|
|
139
|
+
extendedPayloads: (_getExecutionContext = getExecutionContext()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
|
|
140
|
+
session: retrieveSession ? await getContextStorageState(context) : undefined
|
|
176
141
|
});
|
|
177
142
|
}
|
|
178
143
|
try {
|
|
@@ -181,7 +146,7 @@ async function* runApiGenerator({
|
|
|
181
146
|
while (true) {
|
|
182
147
|
const result = await Promise.race([generator.next(await next), abortPromise]);
|
|
183
148
|
if (result === abortSymbol) {
|
|
184
|
-
return
|
|
149
|
+
return err(new AbortedError());
|
|
185
150
|
}
|
|
186
151
|
if (!result.done) {
|
|
187
152
|
next = yield result.value;
|
|
@@ -191,7 +156,7 @@ async function* runApiGenerator({
|
|
|
191
156
|
}
|
|
192
157
|
} catch (error) {
|
|
193
158
|
console.log("run errored", error);
|
|
194
|
-
return
|
|
159
|
+
return err(new AutomationError(error));
|
|
195
160
|
} finally {
|
|
196
161
|
await saveTraceIfNeeded({
|
|
197
162
|
errorMessage: "failed to save trace"
|
|
@@ -200,7 +165,7 @@ async function* runApiGenerator({
|
|
|
200
165
|
await fs.remove(downloadsPath);
|
|
201
166
|
}
|
|
202
167
|
}
|
|
203
|
-
async function runApi(params) {
|
|
168
|
+
export async function runApi(params) {
|
|
204
169
|
const generator = runApiGenerator(params);
|
|
205
170
|
const {
|
|
206
171
|
value,
|
|
@@ -209,28 +174,28 @@ async function runApi(params) {
|
|
|
209
174
|
if (done) {
|
|
210
175
|
return value;
|
|
211
176
|
}
|
|
212
|
-
return
|
|
177
|
+
return err(new InvalidApiError("Expected API to be async function, got async generator"));
|
|
213
178
|
}
|
|
214
|
-
async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
179
|
+
export async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
215
180
|
if (retries === 0) {
|
|
216
|
-
return
|
|
181
|
+
return ok(false);
|
|
217
182
|
}
|
|
218
183
|
let tryNumber = 0;
|
|
219
|
-
console.log("Checking auth session with retries", `${
|
|
220
|
-
const importResult = await importFunction(`${
|
|
184
|
+
console.log("Checking auth session with retries", `${AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
185
|
+
const importResult = await importFunction(`${AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
221
186
|
if (importResult.isErr()) {
|
|
222
|
-
return
|
|
187
|
+
return err(importResult.error);
|
|
223
188
|
}
|
|
224
189
|
if (importResult.value.type !== "async") {
|
|
225
|
-
return
|
|
190
|
+
return err(new InvalidCheckError("Check function is not an async function"));
|
|
226
191
|
}
|
|
227
192
|
const check = importResult.value.func;
|
|
228
193
|
while (retries > tryNumber) {
|
|
229
194
|
const result = await check(page, context);
|
|
230
|
-
if (result) return
|
|
195
|
+
if (result) return ok(true);
|
|
231
196
|
tryNumber++;
|
|
232
197
|
}
|
|
233
|
-
return
|
|
198
|
+
return ok(false);
|
|
234
199
|
}
|
|
235
200
|
async function importFunction(path) {
|
|
236
201
|
const functionNameParts = path.split("/");
|
|
@@ -239,49 +204,49 @@ async function importFunction(path) {
|
|
|
239
204
|
let imported = undefined;
|
|
240
205
|
switch (functionNameDepth) {
|
|
241
206
|
case 1:
|
|
242
|
-
imported = await (
|
|
207
|
+
imported = await import(`../../../${functionNameParts[0]}.ts`);
|
|
243
208
|
break;
|
|
244
209
|
case 2:
|
|
245
|
-
imported = await (
|
|
210
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}.ts`);
|
|
246
211
|
break;
|
|
247
212
|
case 3:
|
|
248
|
-
imported = await (
|
|
213
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
|
|
249
214
|
break;
|
|
250
215
|
case 4:
|
|
251
|
-
imported = await (
|
|
216
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
|
|
252
217
|
break;
|
|
253
218
|
case 5:
|
|
254
|
-
imported = await (
|
|
219
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
|
|
255
220
|
break;
|
|
256
221
|
case 6:
|
|
257
|
-
imported = await (
|
|
222
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
|
|
258
223
|
break;
|
|
259
224
|
default:
|
|
260
|
-
return
|
|
225
|
+
return err(new MaxLevelsExceededError(5));
|
|
261
226
|
}
|
|
262
227
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
263
|
-
return
|
|
228
|
+
return err(new InvalidApiError("API file path does not have a default export"));
|
|
264
229
|
}
|
|
265
230
|
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
266
|
-
return
|
|
231
|
+
return ok({
|
|
267
232
|
type: "async-generator",
|
|
268
233
|
generator: imported.default
|
|
269
234
|
});
|
|
270
235
|
}
|
|
271
236
|
if (imported.default.constructor.name === "AsyncFunction") {
|
|
272
|
-
return
|
|
237
|
+
return ok({
|
|
273
238
|
type: "async",
|
|
274
239
|
func: imported.default
|
|
275
240
|
});
|
|
276
241
|
}
|
|
277
|
-
return
|
|
242
|
+
return err(new InvalidApiError("API file path does not have a default async function/generator export"));
|
|
278
243
|
} catch (error) {
|
|
279
244
|
if (error.message.includes("Unknown variable dynamic import")) {
|
|
280
|
-
return
|
|
245
|
+
return err(new ApiNotFoundError(path));
|
|
281
246
|
}
|
|
282
247
|
if ((error === null || error === void 0 ? void 0 : error.code) === "ERR_MODULE_NOT_FOUND") {
|
|
283
248
|
console.log("API not found", error);
|
|
284
|
-
return
|
|
249
|
+
return err(new ApiNotFoundError(path));
|
|
285
250
|
}
|
|
286
251
|
throw error;
|
|
287
252
|
}
|
|
@@ -1,50 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
})
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
const runApiSessionSchema = exports.runApiSessionSchema = _zod.default.discriminatedUnion("type", [_zod.default.object({
|
|
10
|
-
type: _zod.default.literal("file"),
|
|
11
|
-
path: _zod.default.string()
|
|
12
|
-
}), _zod.default.object({
|
|
13
|
-
type: _zod.default.literal("state"),
|
|
14
|
-
state: _zod.default.custom(v => v)
|
|
1
|
+
import z from "zod";
|
|
2
|
+
export const runApiSessionSchema = z.discriminatedUnion("type", [z.object({
|
|
3
|
+
type: z.literal("file"),
|
|
4
|
+
path: z.string()
|
|
5
|
+
}), z.object({
|
|
6
|
+
type: z.literal("state"),
|
|
7
|
+
state: z.custom(v => v)
|
|
15
8
|
})]);
|
|
16
|
-
const runApiParametersSchema =
|
|
17
|
-
functionsToken:
|
|
18
|
-
automationFunction:
|
|
19
|
-
name:
|
|
20
|
-
params:
|
|
9
|
+
export const runApiParametersSchema = z.object({
|
|
10
|
+
functionsToken: z.string().optional(),
|
|
11
|
+
automationFunction: z.object({
|
|
12
|
+
name: z.string(),
|
|
13
|
+
params: z.any().optional()
|
|
21
14
|
}),
|
|
22
|
-
tracing:
|
|
23
|
-
enabled:
|
|
24
|
-
}),
|
|
25
|
-
enabled:
|
|
26
|
-
filePath:
|
|
15
|
+
tracing: z.discriminatedUnion("enabled", [z.object({
|
|
16
|
+
enabled: z.literal(false)
|
|
17
|
+
}), z.object({
|
|
18
|
+
enabled: z.literal(true),
|
|
19
|
+
filePath: z.string()
|
|
27
20
|
})]).optional().default({
|
|
28
21
|
enabled: false
|
|
29
22
|
}),
|
|
30
|
-
auth:
|
|
23
|
+
auth: z.object({
|
|
31
24
|
session: runApiSessionSchema,
|
|
32
|
-
runCheck:
|
|
25
|
+
runCheck: z.boolean().default(false)
|
|
33
26
|
}).optional(),
|
|
34
|
-
runOptions:
|
|
35
|
-
environment:
|
|
36
|
-
headless:
|
|
37
|
-
proxy:
|
|
38
|
-
server:
|
|
39
|
-
username:
|
|
40
|
-
password:
|
|
27
|
+
runOptions: z.discriminatedUnion("environment", [z.object({
|
|
28
|
+
environment: z.literal("deployed"),
|
|
29
|
+
headless: z.boolean().default(true),
|
|
30
|
+
proxy: z.object({
|
|
31
|
+
server: z.string(),
|
|
32
|
+
username: z.string(),
|
|
33
|
+
password: z.string()
|
|
41
34
|
}).optional()
|
|
42
|
-
}),
|
|
43
|
-
environment:
|
|
44
|
-
cdpAddress:
|
|
45
|
-
mode:
|
|
35
|
+
}), z.object({
|
|
36
|
+
environment: z.literal("ide"),
|
|
37
|
+
cdpAddress: z.string(),
|
|
38
|
+
mode: z.union([z.literal("vanilla"), z.literal("playwright"), z.literal("playwright-standalone"), z.literal("playwright-headless")])
|
|
46
39
|
})]).default({
|
|
47
40
|
environment: "deployed"
|
|
48
41
|
}),
|
|
49
|
-
retrieveSession:
|
|
42
|
+
retrieveSession: z.boolean().default(false)
|
|
50
43
|
});
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.settingsSchema = void 0;
|
|
7
|
-
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1
|
+
import * as z from "zod";
|
|
10
2
|
const authSessionsSchema = z.object({
|
|
11
3
|
enabled: z.boolean()
|
|
12
4
|
}).optional().default({
|
|
13
5
|
enabled: false
|
|
14
6
|
});
|
|
15
|
-
const settingsSchema =
|
|
7
|
+
export const settingsSchema = z.object({
|
|
16
8
|
authSessions: authSessionsSchema
|
|
17
9
|
});
|
package/dist/common/telemetry.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getTelemetryClient = getTelemetryClient;
|
|
7
|
-
exports.initializeAppInsights = initializeAppInsights;
|
|
8
|
-
var appInsights = _interopRequireWildcard(require("applicationinsights"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
1
|
+
import * as appInsights from "applicationinsights";
|
|
11
2
|
function gracefulShutdown() {
|
|
12
3
|
console.log("Shutting down, so flushing app insights.");
|
|
13
4
|
appInsights.defaultClient.flush();
|
|
14
5
|
process.exit();
|
|
15
6
|
}
|
|
16
|
-
function initializeAppInsights() {
|
|
7
|
+
export function initializeAppInsights() {
|
|
17
8
|
const appInsightsConnectionString = process.env.APPINSIGHTS_CONNECTION_STRING;
|
|
18
9
|
if (appInsightsConnectionString) {
|
|
19
10
|
console.log("Initializing app insights.");
|
|
@@ -27,6 +18,6 @@ function initializeAppInsights() {
|
|
|
27
18
|
appInsights.start();
|
|
28
19
|
}
|
|
29
20
|
}
|
|
30
|
-
function getTelemetryClient() {
|
|
21
|
+
export function getTelemetryClient() {
|
|
31
22
|
return appInsights.defaultClient;
|
|
32
23
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,69 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "RunError", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _runtime.RunError;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "extendPayload", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _runtime.extendPayload;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "extendTimeout", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _runtime.extendTimeout;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _downloadDirectory.getDownloadDirectoryPath;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "getExecutionContext", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _asyncLocalStorage.getExecutionContext;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _getPlaywrightConstructs.getProductionPlaywrightConstructs;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _runtime.requestMultipleChoice;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "requestOTP", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _runtime.requestOTP;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "runInfo", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _runtime.runInfo;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "runWithContext", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _asyncLocalStorage.runWithContext;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
var _runtime = require("./runtime");
|
|
67
|
-
var _asyncLocalStorage = require("./common/asyncLocalStorage");
|
|
68
|
-
var _downloadDirectory = require("./runtime/downloadDirectory");
|
|
69
|
-
var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs");
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP } from "./runtime";
|
|
2
|
+
export { runWithContext, getExecutionContext } from "./common/asyncLocalStorage";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
|
package/dist/runtime/RunError.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RunError = void 0;
|
|
7
|
-
class RunError extends Error {
|
|
1
|
+
export class RunError extends Error {
|
|
8
2
|
constructor(message, options) {
|
|
9
3
|
super(message);
|
|
10
4
|
this.message = message;
|
|
@@ -15,5 +9,4 @@ class RunError extends Error {
|
|
|
15
9
|
Object.setPrototypeOf(this, RunError.prototype);
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
exports.RunError = RunError;
|
|
19
12
|
new RunError("", {});
|
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.getDownloadDirectoryPath = getDownloadDirectoryPath;
|
|
7
|
-
var _ = require("..");
|
|
8
|
-
var _fsExtra = require("fs-extra");
|
|
9
|
-
function getDownloadDirectoryPath() {
|
|
10
|
-
const context = (0, _.getExecutionContext)();
|
|
1
|
+
import { getExecutionContext } from "..";
|
|
2
|
+
import { ensureDirSync } from "fs-extra";
|
|
3
|
+
export function getDownloadDirectoryPath() {
|
|
4
|
+
const context = getExecutionContext();
|
|
11
5
|
if (!context) {
|
|
12
6
|
throw new Error("ExecutionContext not found");
|
|
13
7
|
}
|
|
14
8
|
const path = `/tmp/downloads/${context.runId}`;
|
|
15
|
-
|
|
9
|
+
ensureDirSync(path, {
|
|
16
10
|
mode: 0o2775
|
|
17
11
|
});
|
|
18
12
|
return path;
|
package/dist/runtime/enums.d.js
CHANGED
package/dist/runtime/enums.js
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.RunType = exports.RunEnvironment = void 0;
|
|
7
|
-
let RunEnvironment = exports.RunEnvironment = function (RunEnvironment) {
|
|
1
|
+
export let RunEnvironment = function (RunEnvironment) {
|
|
8
2
|
RunEnvironment["IDE"] = "IDE";
|
|
9
3
|
RunEnvironment["DEPLOYED"] = "DEPLOYED";
|
|
10
4
|
return RunEnvironment;
|
|
11
5
|
}({});
|
|
12
|
-
let RunType =
|
|
6
|
+
export let RunType = function (RunType) {
|
|
13
7
|
RunType["SYNC"] = "SYNC";
|
|
14
8
|
RunType["ASYNC"] = "ASYNC";
|
|
15
9
|
RunType["JOB"] = "JOB";
|
|
@@ -1,53 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
(
|
|
8
|
-
|
|
9
|
-
(0, _asyncLocalStorage.runWithContext)({
|
|
10
|
-
runEnvironment: _enums.RunEnvironment.IDE,
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getExecutionContext, runWithContext } from "../common/asyncLocalStorage";
|
|
3
|
+
import { extendPayload, runInfo } from "./index";
|
|
4
|
+
import { RunEnvironment } from "./enums";
|
|
5
|
+
describe("Execution Helpers", () => {
|
|
6
|
+
it("should be able to get execution info", () => {
|
|
7
|
+
runWithContext({
|
|
8
|
+
runEnvironment: RunEnvironment.IDE,
|
|
11
9
|
runId: "test-run-id",
|
|
12
10
|
extendedPayloads: []
|
|
13
11
|
}, () => {
|
|
14
|
-
|
|
12
|
+
expect(runInfo().runId).toEqual("test-run-id");
|
|
15
13
|
});
|
|
16
14
|
});
|
|
17
|
-
|
|
15
|
+
it("should be able to mutate extendedPayloads and get the accmulated value at the end ", () => {
|
|
18
16
|
const context = {
|
|
19
17
|
extendedPayloads: [],
|
|
20
18
|
runId: "test-run-id"
|
|
21
19
|
};
|
|
22
|
-
|
|
23
|
-
runEnvironment:
|
|
20
|
+
runWithContext({
|
|
21
|
+
runEnvironment: RunEnvironment.IDE,
|
|
24
22
|
runId: "test-run-id",
|
|
25
23
|
extendedPayloads: []
|
|
26
24
|
}, () => {
|
|
27
25
|
var _getExecutionContext, _getExecutionContext2;
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
expect((_getExecutionContext = getExecutionContext()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
|
|
27
|
+
extendPayload({
|
|
30
28
|
api: "test-api",
|
|
31
29
|
parameters: {}
|
|
32
30
|
});
|
|
33
|
-
|
|
31
|
+
expect((_getExecutionContext2 = getExecutionContext()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
|
|
34
32
|
api: "test-api",
|
|
35
33
|
parameters: {}
|
|
36
34
|
}]);
|
|
37
|
-
|
|
35
|
+
extendPayload({
|
|
38
36
|
api: "test-api",
|
|
39
37
|
parameters: {}
|
|
40
38
|
});
|
|
41
|
-
|
|
39
|
+
extendPayload({
|
|
42
40
|
api: "test-api",
|
|
43
41
|
parameters: {}
|
|
44
42
|
});
|
|
45
|
-
|
|
43
|
+
extendPayload({
|
|
46
44
|
api: "test-api",
|
|
47
45
|
parameters: {}
|
|
48
46
|
});
|
|
49
|
-
const context =
|
|
50
|
-
|
|
47
|
+
const context = getExecutionContext();
|
|
48
|
+
expect(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
|
|
51
49
|
});
|
|
52
50
|
});
|
|
53
51
|
});
|
package/dist/runtime/export.d.js
CHANGED