@intuned/runtime-dev 0.1.0-test.11 → 0.1.0-test.13
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 +0 -1
- package/dist/commands/api/run.js +156 -83
- package/dist/commands/api/run.ts +105 -0
- package/dist/commands/auth-sessions/load.js +20 -20
- package/dist/commands/auth-sessions/load.ts +30 -0
- package/dist/commands/auth-sessions/run-check.js +45 -39
- package/dist/commands/auth-sessions/run-check.ts +51 -0
- package/dist/commands/auth-sessions/run-create.js +84 -74
- package/dist/commands/auth-sessions/run-create.ts +91 -0
- package/dist/commands/browser/save-state.js +12 -7
- package/dist/commands/browser/save-state.ts +14 -0
- package/dist/commands/browser/start-browser.js +7 -4
- package/dist/commands/browser/start-browser.ts +11 -0
- package/dist/commands/build.js +97 -61
- package/dist/commands/build.ts +78 -0
- package/dist/commands/common/browserUtils.js +42 -31
- package/dist/commands/common/browserUtils.ts +45 -0
- package/dist/commands/common/getDefaultExportFromFile.js +11 -10
- package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
- package/dist/commands/common/getFirstLineNumber.js +90 -83
- package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +2 -2
- package/dist/commands/common/getFirstLineNumber.ts +96 -0
- package/dist/commands/common/sendMessageToClient.js +4 -2
- package/dist/commands/common/sendMessageToClient.ts +3 -0
- package/dist/commands/common/utils/fileUtils.js +16 -16
- package/dist/commands/common/utils/fileUtils.ts +23 -0
- package/dist/commands/common/utils/settings.js +17 -19
- package/dist/commands/common/utils/settings.ts +22 -0
- package/dist/commands/common/utils/unixSocket.js +43 -36
- package/dist/commands/common/utils/unixSocket.ts +38 -0
- package/dist/commands/common/utils/webTemplate.js +25 -18
- package/dist/commands/common/utils/webTemplate.ts +22 -0
- package/dist/commands/interface/run.js +139 -133
- package/dist/commands/interface/run.ts +156 -0
- package/dist/commands/ts-check.js +45 -41
- package/dist/commands/ts-check.ts +50 -0
- package/dist/common/Logger/Logger/index.d.ts +1 -1
- package/dist/common/Logger/Logger/index.js +40 -46
- package/dist/common/Logger/Logger/index.ts +53 -0
- package/dist/common/Logger/Logger/types.js +1 -1
- package/dist/common/Logger/index.d.ts +1 -1
- package/dist/common/Logger/index.js +40 -46
- package/dist/common/Logger/index.ts +53 -0
- package/dist/common/Logger/types.js +1 -1
- package/dist/common/asyncLocalStorage/index.js +4 -4
- package/dist/common/asyncLocalStorage/index.ts +9 -0
- package/dist/common/cleanEnvironmentVariables.js +11 -9
- package/dist/common/cleanEnvironmentVariables.ts +10 -0
- package/dist/common/constants.js +1 -1
- package/dist/common/constants.ts +1 -0
- package/dist/common/contextStorageStateHelpers.js +36 -38
- package/dist/common/contextStorageStateHelpers.ts +43 -0
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +187 -157
- package/dist/common/getPlaywrightConstructs.ts +181 -0
- package/dist/common/jwtTokenManager.js +74 -61
- package/dist/common/jwtTokenManager.ts +71 -0
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/errors.js +130 -121
- package/dist/common/runApi/errors.ts +154 -0
- package/dist/common/runApi/index.d.ts +4 -4
- package/dist/common/runApi/index.js +219 -233
- package/dist/common/runApi/index.ts +253 -0
- package/dist/common/runApi/types.d.ts +1 -1
- package/dist/common/runApi/types.js +55 -41
- package/dist/common/runApi/types.ts +43 -0
- package/dist/common/settingsSchema.js +9 -6
- package/dist/common/settingsSchema.ts +9 -0
- package/dist/common/telemetry.js +27 -16
- package/dist/common/telemetry.ts +23 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/index.ts +4 -0
- package/dist/runtime/RunError.d.ts +1 -1
- package/dist/runtime/RunError.js +10 -10
- package/dist/runtime/RunError.ts +12 -0
- package/dist/runtime/downloadDirectory.js +10 -10
- package/dist/runtime/downloadDirectory.ts +13 -0
- package/dist/runtime/enums.d.ts +1 -11
- package/dist/runtime/enums.js +12 -12
- package/dist/runtime/enums.ts +12 -0
- package/dist/runtime/{executionHelpers.test.js → executionHelpers.test.ts} +2 -2
- package/dist/runtime/export.d.ts +1 -202
- package/dist/runtime/extendPayload.d.ts +1 -1
- package/dist/runtime/extendPayload.js +13 -13
- package/dist/runtime/extendPayload.ts +15 -0
- package/dist/runtime/extendTimeout.js +19 -20
- package/dist/runtime/extendTimeout.ts +24 -0
- package/dist/runtime/index.d.ts +7 -7
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/index.ts +6 -0
- package/dist/runtime/requestMoreInfo.js +14 -14
- package/dist/runtime/requestMoreInfo.ts +18 -0
- package/dist/runtime/runInfo.d.ts +1 -1
- package/dist/runtime/runInfo.js +12 -13
- package/dist/runtime/runInfo.ts +15 -0
- package/package.json +3 -2
- package/tsconfig.json +1 -1
- /package/dist/{runtime/enums.d.js → common/Logger/Logger/types.ts} +0 -0
- /package/dist/{runtime/export.d.js → common/Logger/types.ts} +0 -0
|
@@ -0,0 +1,253 @@
|
|
|
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.js";
|
|
9
|
+
import { AUTH_SESSIONS_FOLDER_NAME } from "../constants";
|
|
10
|
+
import { getPlaywrightConstructsForMode, getProductionPlaywrightConstructs } from "../getPlaywrightConstructs";
|
|
11
|
+
import { runApiParametersSchema } from "./types.js";
|
|
12
|
+
export * from "./types.js";
|
|
13
|
+
export * from "./errors.js";
|
|
14
|
+
export async function* runApiGenerator({
|
|
15
|
+
retrieveSession = false,
|
|
16
|
+
abortSignal,
|
|
17
|
+
...input
|
|
18
|
+
}) {
|
|
19
|
+
let traceStarted = false;
|
|
20
|
+
const {
|
|
21
|
+
automationFunction,
|
|
22
|
+
runOptions,
|
|
23
|
+
tracing,
|
|
24
|
+
auth,
|
|
25
|
+
functionsToken
|
|
26
|
+
} = runApiParametersSchema.parse(input);
|
|
27
|
+
backendFunctionsTokenManager.token = functionsToken;
|
|
28
|
+
const downloadsPath = getDownloadDirectoryPath();
|
|
29
|
+
let page;
|
|
30
|
+
let context;
|
|
31
|
+
if (runOptions.environment === "deployed") {
|
|
32
|
+
const {
|
|
33
|
+
headless,
|
|
34
|
+
proxy
|
|
35
|
+
} = runOptions;
|
|
36
|
+
({
|
|
37
|
+
page,
|
|
38
|
+
context
|
|
39
|
+
} = await getProductionPlaywrightConstructs({
|
|
40
|
+
headless,
|
|
41
|
+
proxy,
|
|
42
|
+
downloadsPath,
|
|
43
|
+
storageState: auth === null || auth === void 0 ? void 0 : auth.session
|
|
44
|
+
}));
|
|
45
|
+
} else {
|
|
46
|
+
const {
|
|
47
|
+
mode,
|
|
48
|
+
cdpAddress
|
|
49
|
+
} = runOptions;
|
|
50
|
+
({
|
|
51
|
+
page,
|
|
52
|
+
context
|
|
53
|
+
} = await getPlaywrightConstructsForMode(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
|
|
54
|
+
}
|
|
55
|
+
const executionContext = getExecutionContext();
|
|
56
|
+
if (!executionContext) {
|
|
57
|
+
throw "";
|
|
58
|
+
}
|
|
59
|
+
async function saveTraceIfNeeded({
|
|
60
|
+
errorMessage
|
|
61
|
+
}) {
|
|
62
|
+
if (!tracing.enabled || !traceStarted) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await context.tracing.stop({
|
|
67
|
+
path: tracing.filePath
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
|
|
71
|
+
await remove(tracing.filePath);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (tracing.enabled) {
|
|
75
|
+
await context.tracing.start({
|
|
76
|
+
screenshots: true,
|
|
77
|
+
snapshots: true,
|
|
78
|
+
sources: true
|
|
79
|
+
});
|
|
80
|
+
traceStarted = true;
|
|
81
|
+
}
|
|
82
|
+
const abortSymbol = Symbol("abort");
|
|
83
|
+
const abortPromise = new Promise(resolve => {
|
|
84
|
+
if (!abortSignal) return;
|
|
85
|
+
abortSignal.addEventListener("abort", () => {
|
|
86
|
+
resolve(abortSymbol);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
if (auth && auth.session.type === "state") {
|
|
90
|
+
await setContextStorageState(context, auth.session.state);
|
|
91
|
+
}
|
|
92
|
+
async function* runAutomation() {
|
|
93
|
+
var _getExecutionContext;
|
|
94
|
+
if (auth !== null && auth !== void 0 && auth.runCheck) {
|
|
95
|
+
if (!auth.session) {
|
|
96
|
+
return err({
|
|
97
|
+
code: "AuthRequiredError"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
console.log("Running auth check");
|
|
101
|
+
const authCheckResult = await checkAuthSessionWithRetries(page, context, 2);
|
|
102
|
+
if (authCheckResult.isErr()) {
|
|
103
|
+
const error = authCheckResult.error;
|
|
104
|
+
if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
|
|
105
|
+
return err(new InvalidCheckError(`Auth session check function failed`, error));
|
|
106
|
+
}
|
|
107
|
+
return authCheckResult;
|
|
108
|
+
}
|
|
109
|
+
if (!authCheckResult.value) {
|
|
110
|
+
return err({
|
|
111
|
+
code: "AuthCheckFailedError"
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
console.log("Running function", automationFunction.name);
|
|
116
|
+
const args = [...(automationFunction.params ? [automationFunction.params] : []), page, context];
|
|
117
|
+
const importResult = await importFunction(automationFunction.name);
|
|
118
|
+
if (importResult.isErr()) {
|
|
119
|
+
return importResult;
|
|
120
|
+
}
|
|
121
|
+
let result;
|
|
122
|
+
if (importResult.value.type === "async-generator") {
|
|
123
|
+
const generator = importResult.value.generator(...args);
|
|
124
|
+
let next = undefined;
|
|
125
|
+
while (true) {
|
|
126
|
+
const generatorResult = await generator.next(...(next ? [next] : []));
|
|
127
|
+
if (!generatorResult.done) {
|
|
128
|
+
next = yield generatorResult.value;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
result = generatorResult.value;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
result = await importResult.value.func(...args);
|
|
136
|
+
}
|
|
137
|
+
return ok({
|
|
138
|
+
result,
|
|
139
|
+
extendedPayloads: (_getExecutionContext = getExecutionContext()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
|
|
140
|
+
session: retrieveSession ? await getContextStorageState(context) : undefined
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const generator = runAutomation();
|
|
145
|
+
let next = undefined;
|
|
146
|
+
while (true) {
|
|
147
|
+
const result = await Promise.race([generator.next(await next), abortPromise]);
|
|
148
|
+
if (result === abortSymbol) {
|
|
149
|
+
return err(new AbortedError());
|
|
150
|
+
}
|
|
151
|
+
if (!result.done) {
|
|
152
|
+
next = yield result.value;
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
return result.value;
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.log("run errored", error);
|
|
159
|
+
return err(new AutomationError(error));
|
|
160
|
+
} finally {
|
|
161
|
+
await saveTraceIfNeeded({
|
|
162
|
+
errorMessage: "failed to save trace"
|
|
163
|
+
});
|
|
164
|
+
await context.close();
|
|
165
|
+
await fs.remove(downloadsPath);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
export async function runApi(params) {
|
|
169
|
+
const generator = runApiGenerator(params);
|
|
170
|
+
const {
|
|
171
|
+
value,
|
|
172
|
+
done
|
|
173
|
+
} = await generator.next();
|
|
174
|
+
if (done) {
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
return err(new InvalidApiError("Expected API to be async function, got async generator"));
|
|
178
|
+
}
|
|
179
|
+
export async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
180
|
+
if (retries === 0) {
|
|
181
|
+
return ok(false);
|
|
182
|
+
}
|
|
183
|
+
let tryNumber = 0;
|
|
184
|
+
console.log("Checking auth session with retries", `${AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
185
|
+
const importResult = await importFunction(`${AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
186
|
+
if (importResult.isErr()) {
|
|
187
|
+
return err(importResult.error);
|
|
188
|
+
}
|
|
189
|
+
if (importResult.value.type !== "async") {
|
|
190
|
+
return err(new InvalidCheckError("Check function is not an async function"));
|
|
191
|
+
}
|
|
192
|
+
const check = importResult.value.func;
|
|
193
|
+
while (retries > tryNumber) {
|
|
194
|
+
const result = await check(page, context);
|
|
195
|
+
if (result) return ok(true);
|
|
196
|
+
tryNumber++;
|
|
197
|
+
}
|
|
198
|
+
return ok(false);
|
|
199
|
+
}
|
|
200
|
+
async function importFunction(path) {
|
|
201
|
+
const functionNameParts = path.split("/");
|
|
202
|
+
const functionNameDepth = functionNameParts.length;
|
|
203
|
+
try {
|
|
204
|
+
let imported = undefined;
|
|
205
|
+
switch (functionNameDepth) {
|
|
206
|
+
case 1:
|
|
207
|
+
imported = await import(`../../../${functionNameParts[0]}.ts`);
|
|
208
|
+
break;
|
|
209
|
+
case 2:
|
|
210
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}.ts`);
|
|
211
|
+
break;
|
|
212
|
+
case 3:
|
|
213
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
|
|
214
|
+
break;
|
|
215
|
+
case 4:
|
|
216
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
|
|
217
|
+
break;
|
|
218
|
+
case 5:
|
|
219
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
|
|
220
|
+
break;
|
|
221
|
+
case 6:
|
|
222
|
+
imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
|
|
223
|
+
break;
|
|
224
|
+
default:
|
|
225
|
+
return err(new MaxLevelsExceededError(5));
|
|
226
|
+
}
|
|
227
|
+
if (!imported || !imported.default || !imported.default.constructor) {
|
|
228
|
+
return err(new InvalidApiError("API file path does not have a default export"));
|
|
229
|
+
}
|
|
230
|
+
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
231
|
+
return ok({
|
|
232
|
+
type: "async-generator",
|
|
233
|
+
generator: imported.default
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
if (imported.default.constructor.name === "AsyncFunction") {
|
|
237
|
+
return ok({
|
|
238
|
+
type: "async",
|
|
239
|
+
func: imported.default
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return err(new InvalidApiError("API file path does not have a default async function/generator export"));
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (error.message.includes("Unknown variable dynamic import")) {
|
|
245
|
+
return err(new ApiNotFoundError(path));
|
|
246
|
+
}
|
|
247
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === "ERR_MODULE_NOT_FOUND") {
|
|
248
|
+
console.log("API not found", error);
|
|
249
|
+
return err(new ApiNotFoundError(path));
|
|
250
|
+
}
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IntunedStorageState } from "../contextStorageStateHelpers";
|
|
2
2
|
import type { Payload } from "../../runtime/export";
|
|
3
3
|
import type { Result } from "neverthrow";
|
|
4
|
-
import type { RunAutomationError } from "./errors";
|
|
4
|
+
import type { RunAutomationError } from "./errors.js";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
export interface PayloadToAppend {
|
|
7
7
|
apiName: string;
|
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
import z from "zod";
|
|
2
|
-
export const runApiSessionSchema = z.discriminatedUnion("type", [
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
export const runApiSessionSchema = z.discriminatedUnion("type", [
|
|
3
|
+
z.object({
|
|
4
|
+
type: z.literal("file"),
|
|
5
|
+
path: z.string(),
|
|
6
|
+
}),
|
|
7
|
+
z.object({
|
|
8
|
+
type: z.literal("state"),
|
|
9
|
+
state: z.custom((v) => v),
|
|
10
|
+
}),
|
|
11
|
+
]);
|
|
9
12
|
export const runApiParametersSchema = z.object({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
13
|
+
functionsToken: z.string().optional(),
|
|
14
|
+
automationFunction: z.object({
|
|
15
|
+
name: z.string(),
|
|
16
|
+
params: z.any().optional(),
|
|
17
|
+
}),
|
|
18
|
+
tracing: z
|
|
19
|
+
.discriminatedUnion("enabled", [
|
|
20
|
+
z.object({ enabled: z.literal(false) }),
|
|
21
|
+
z.object({ enabled: z.literal(true), filePath: z.string() }),
|
|
22
|
+
])
|
|
23
|
+
.optional()
|
|
24
|
+
.default({ enabled: false }),
|
|
25
|
+
auth: z
|
|
26
|
+
.object({
|
|
27
|
+
session: runApiSessionSchema,
|
|
28
|
+
runCheck: z.boolean().default(false),
|
|
29
|
+
})
|
|
30
|
+
.optional(),
|
|
31
|
+
runOptions: z
|
|
32
|
+
.discriminatedUnion("environment", [
|
|
33
|
+
z.object({
|
|
34
|
+
environment: z.literal("deployed"),
|
|
35
|
+
headless: z.boolean().default(true),
|
|
36
|
+
proxy: z
|
|
37
|
+
.object({
|
|
38
|
+
server: z.string(),
|
|
39
|
+
username: z.string(),
|
|
40
|
+
password: z.string(),
|
|
41
|
+
})
|
|
42
|
+
.optional(),
|
|
43
|
+
}),
|
|
44
|
+
z.object({
|
|
45
|
+
environment: z.literal("ide"),
|
|
46
|
+
cdpAddress: z.string(),
|
|
47
|
+
mode: z.union([
|
|
48
|
+
z.literal("vanilla"),
|
|
49
|
+
z.literal("playwright"),
|
|
50
|
+
z.literal("playwright-standalone"),
|
|
51
|
+
z.literal("playwright-headless"),
|
|
52
|
+
]),
|
|
53
|
+
}),
|
|
54
|
+
])
|
|
55
|
+
.default({ environment: "deployed" }),
|
|
56
|
+
retrieveSession: z.boolean().default(false),
|
|
57
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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)
|
|
8
|
+
})]);
|
|
9
|
+
export const runApiParametersSchema = z.object({
|
|
10
|
+
functionsToken: z.string().optional(),
|
|
11
|
+
automationFunction: z.object({
|
|
12
|
+
name: z.string(),
|
|
13
|
+
params: z.any().optional()
|
|
14
|
+
}),
|
|
15
|
+
tracing: z.discriminatedUnion("enabled", [z.object({
|
|
16
|
+
enabled: z.literal(false)
|
|
17
|
+
}), z.object({
|
|
18
|
+
enabled: z.literal(true),
|
|
19
|
+
filePath: z.string()
|
|
20
|
+
})]).optional().default({
|
|
21
|
+
enabled: false
|
|
22
|
+
}),
|
|
23
|
+
auth: z.object({
|
|
24
|
+
session: runApiSessionSchema,
|
|
25
|
+
runCheck: z.boolean().default(false)
|
|
26
|
+
}).optional(),
|
|
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()
|
|
34
|
+
}).optional()
|
|
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")])
|
|
39
|
+
})]).default({
|
|
40
|
+
environment: "deployed"
|
|
41
|
+
}),
|
|
42
|
+
retrieveSession: z.boolean().default(false)
|
|
43
|
+
});
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
const authSessionsSchema = z
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
const authSessionsSchema = z
|
|
3
|
+
.object({
|
|
4
|
+
enabled: z.boolean(),
|
|
5
|
+
})
|
|
6
|
+
.optional()
|
|
7
|
+
.default({
|
|
8
|
+
enabled: false,
|
|
6
9
|
});
|
|
7
10
|
export const settingsSchema = z.object({
|
|
8
|
-
|
|
9
|
-
});
|
|
11
|
+
authSessions: authSessionsSchema,
|
|
12
|
+
});
|
package/dist/common/telemetry.js
CHANGED
|
@@ -1,23 +1,34 @@
|
|
|
1
1
|
import * as appInsights from "applicationinsights";
|
|
2
2
|
function gracefulShutdown() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
console.log("Shutting down, so flushing app insights.");
|
|
4
|
+
appInsights.defaultClient.flush();
|
|
5
|
+
process.exit();
|
|
6
6
|
}
|
|
7
7
|
export function initializeAppInsights() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
const appInsightsConnectionString = process.env.APPINSIGHTS_CONNECTION_STRING;
|
|
9
|
+
if (appInsightsConnectionString) {
|
|
10
|
+
console.log("Initializing app insights.");
|
|
11
|
+
appInsights
|
|
12
|
+
.setup(appInsightsConnectionString)
|
|
13
|
+
.setAutoCollectConsole(true, true)
|
|
14
|
+
.setAutoCollectDependencies(true)
|
|
15
|
+
.setAutoCollectExceptions(true)
|
|
16
|
+
.setAutoCollectHeartbeat(true)
|
|
17
|
+
.setAutoCollectPerformance(true, true)
|
|
18
|
+
.setAutoCollectRequests(true)
|
|
19
|
+
.setAutoDependencyCorrelation(true)
|
|
20
|
+
.setDistributedTracingMode(appInsights.DistributedTracingModes.AI_AND_W3C)
|
|
21
|
+
.setSendLiveMetrics(true)
|
|
22
|
+
.setUseDiskRetryCaching(true);
|
|
23
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "@intuned/sdk";
|
|
24
|
+
if (process.env.FLY_APP_NAME) {
|
|
25
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRoleInstance] = process.env.FLY_APP_NAME;
|
|
26
|
+
}
|
|
27
|
+
process.on("SIGTERM", gracefulShutdown);
|
|
28
|
+
process.on("SIGINT", gracefulShutdown);
|
|
29
|
+
appInsights.start();
|
|
15
30
|
}
|
|
16
|
-
process.on("SIGTERM", gracefulShutdown);
|
|
17
|
-
process.on("SIGINT", gracefulShutdown);
|
|
18
|
-
appInsights.start();
|
|
19
|
-
}
|
|
20
31
|
}
|
|
21
32
|
export function getTelemetryClient() {
|
|
22
|
-
|
|
23
|
-
}
|
|
33
|
+
return appInsights.defaultClient;
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as appInsights from "applicationinsights";
|
|
2
|
+
function gracefulShutdown() {
|
|
3
|
+
console.log("Shutting down, so flushing app insights.");
|
|
4
|
+
appInsights.defaultClient.flush();
|
|
5
|
+
process.exit();
|
|
6
|
+
}
|
|
7
|
+
export function initializeAppInsights() {
|
|
8
|
+
const appInsightsConnectionString = process.env.APPINSIGHTS_CONNECTION_STRING;
|
|
9
|
+
if (appInsightsConnectionString) {
|
|
10
|
+
console.log("Initializing app insights.");
|
|
11
|
+
appInsights.setup(appInsightsConnectionString).setAutoCollectConsole(true, true).setAutoCollectDependencies(true).setAutoCollectExceptions(true).setAutoCollectHeartbeat(true).setAutoCollectPerformance(true, true).setAutoCollectRequests(true).setAutoDependencyCorrelation(true).setDistributedTracingMode(appInsights.DistributedTracingModes.AI_AND_W3C).setSendLiveMetrics(true).setUseDiskRetryCaching(true);
|
|
12
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRole] = "@intuned/sdk";
|
|
13
|
+
if (process.env.FLY_APP_NAME) {
|
|
14
|
+
appInsights.defaultClient.context.tags[appInsights.defaultClient.context.keys.cloudRoleInstance] = process.env.FLY_APP_NAME;
|
|
15
|
+
}
|
|
16
|
+
process.on("SIGTERM", gracefulShutdown);
|
|
17
|
+
process.on("SIGINT", gracefulShutdown);
|
|
18
|
+
appInsights.start();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function getTelemetryClient() {
|
|
22
|
+
return appInsights.defaultClient;
|
|
23
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime/index.js";
|
|
2
|
+
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage/index.js";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory.js";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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";
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime/index.js";
|
|
2
|
+
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage/index.js";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory.js";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs.js";
|
package/dist/index.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP } from "./runtime/index.js";
|
|
2
|
+
export { runWithContext, getExecutionContext } from "./common/asyncLocalStorage/index.js";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory.js";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs.js";
|
package/dist/runtime/RunError.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export class RunError extends Error {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.message = message;
|
|
5
|
+
this.name = "USER_GENERATED_ERROR";
|
|
6
|
+
this.options = options ?? {
|
|
7
|
+
retryable: false,
|
|
8
|
+
};
|
|
9
|
+
Object.setPrototypeOf(this, RunError.prototype);
|
|
10
|
+
}
|
|
11
11
|
}
|
|
12
|
-
new RunError("", {});
|
|
12
|
+
new RunError("", {});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class RunError extends Error {
|
|
2
|
+
constructor(message, options) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.message = message;
|
|
5
|
+
this.name = "USER_GENERATED_ERROR";
|
|
6
|
+
this.options = options ?? {
|
|
7
|
+
retryable: false
|
|
8
|
+
};
|
|
9
|
+
Object.setPrototypeOf(this, RunError.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
new RunError("", {});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { getExecutionContext } from "..";
|
|
2
2
|
import { ensureDirSync } from "fs-extra";
|
|
3
3
|
export function getDownloadDirectoryPath() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
4
|
+
const context = getExecutionContext();
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("ExecutionContext not found");
|
|
7
|
+
}
|
|
8
|
+
const path = `/tmp/downloads/${context.runId}`;
|
|
9
|
+
ensureDirSync(path, {
|
|
10
|
+
mode: 0o2775,
|
|
11
|
+
});
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getExecutionContext } from "..";
|
|
2
|
+
import { ensureDirSync } from "fs-extra";
|
|
3
|
+
export function getDownloadDirectoryPath() {
|
|
4
|
+
const context = getExecutionContext();
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error("ExecutionContext not found");
|
|
7
|
+
}
|
|
8
|
+
const path = `/tmp/downloads/${context.runId}`;
|
|
9
|
+
ensureDirSync(path, {
|
|
10
|
+
mode: 0o2775
|
|
11
|
+
});
|
|
12
|
+
return path;
|
|
13
|
+
}
|
package/dist/runtime/enums.d.ts
CHANGED
package/dist/runtime/enums.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}({});
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}({});
|
|
1
|
+
export var RunEnvironment;
|
|
2
|
+
(function (RunEnvironment) {
|
|
3
|
+
RunEnvironment["IDE"] = "IDE";
|
|
4
|
+
RunEnvironment["DEPLOYED"] = "DEPLOYED";
|
|
5
|
+
})(RunEnvironment || (RunEnvironment = {}));
|
|
6
|
+
export var RunType;
|
|
7
|
+
(function (RunType) {
|
|
8
|
+
RunType["SYNC"] = "SYNC";
|
|
9
|
+
RunType["ASYNC"] = "ASYNC";
|
|
10
|
+
RunType["JOB"] = "JOB";
|
|
11
|
+
RunType["QUEUE"] = "QUEUE";
|
|
12
|
+
})(RunType || (RunType = {}));
|