@intuned/runtime-dev 1.3.1-api-token.6 → 1.3.4-dev.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/commands/api/run.js +5 -3
- package/dist/commands/auth-sessions/load.js +3 -3
- package/dist/commands/auth-sessions/run-check.js +1 -2
- package/dist/commands/auth-sessions/run-create.js +12 -35
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +14 -40
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +1 -2
- package/dist/commands/intuned-cli/controller/api.js +1 -2
- package/dist/commands/intuned-cli/controller/authSession.js +3 -4
- package/dist/commands/intuned-cli/controller/save.js +27 -28
- package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
- package/dist/commands/intuned-cli/helpers/errors.js +8 -4
- package/dist/commands/intuned-cli/main.js +2 -2
- package/dist/common/asyncLocalStorage/index.d.ts +1 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +2 -1
- package/dist/common/extensionsHelpers.d.ts +15 -0
- package/dist/common/extensionsHelpers.js +81 -0
- package/dist/common/playwrightContext.d.ts +54 -0
- package/dist/common/playwrightContext.js +274 -0
- package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
- package/dist/common/runApi/importUsingImportFunction.js +46 -0
- package/dist/common/runApi/index.d.ts +2 -7
- package/dist/common/runApi/index.js +92 -177
- package/dist/common/runApi/types.d.ts +1 -5
- package/dist/common/runApi/types.js +1 -2
- package/dist/common/settingsSchema.d.ts +513 -0
- package/dist/common/settingsSchema.js +40 -2
- package/dist/common/setupContextHook.d.ts +17 -0
- package/dist/common/setupContextHook.js +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -19
- package/dist/runtime/attemptStore.d.ts +2 -0
- package/dist/runtime/attemptStore.js +23 -0
- package/dist/runtime/export.d.ts +51 -41
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +7 -13
- package/package.json +3 -1
- package/WebTemplate.zip +0 -0
- package/dist/common/getPlaywrightConstructs.d.ts +0 -30
- package/dist/common/getPlaywrightConstructs.js +0 -188
- package/dist/runtime/requestMoreInfo.d.ts +0 -18
- package/dist/runtime/requestMoreInfo.js +0 -25
package/dist/commands/api/run.js
CHANGED
|
@@ -48,8 +48,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
48
48
|
session: {
|
|
49
49
|
type: "file",
|
|
50
50
|
path: authSessionPathToUse
|
|
51
|
-
}
|
|
52
|
-
runCheck: false
|
|
51
|
+
}
|
|
53
52
|
} : undefined,
|
|
54
53
|
runOptions: {
|
|
55
54
|
environment: "cdp",
|
|
@@ -78,7 +77,10 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
78
77
|
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
|
|
79
78
|
fs.ensureDirSync(resultsDir);
|
|
80
79
|
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
81
|
-
await fs.writeJson(path,
|
|
80
|
+
await fs.writeJson(path, {
|
|
81
|
+
input: inputData,
|
|
82
|
+
output: result
|
|
83
|
+
}, {
|
|
82
84
|
spaces: 2
|
|
83
85
|
});
|
|
84
86
|
} else {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
|
-
var
|
|
5
|
+
var _playwrightContext = require("../../common/playwrightContext");
|
|
6
6
|
var _settings = require("../common/utils/settings");
|
|
7
7
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
8
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -19,8 +19,8 @@ _commander.program.description("load auth session to browser").option("--cdpAddr
|
|
|
19
19
|
}
|
|
20
20
|
const {
|
|
21
21
|
context
|
|
22
|
-
} = await (0,
|
|
23
|
-
await (0,
|
|
22
|
+
} = await (0, _playwrightContext.getRemotePlaywrightContext)(cdpAddress);
|
|
23
|
+
await (0, _playwrightContext.loadSessionToContext)({
|
|
24
24
|
context,
|
|
25
25
|
session: {
|
|
26
26
|
type: "file",
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
5
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
6
|
-
var _promptly = require("promptly");
|
|
7
6
|
var _fileUtils = require("../common/utils/fileUtils");
|
|
8
7
|
var _settings = require("../common/utils/settings");
|
|
9
8
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
@@ -42,7 +41,7 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
42
41
|
throw new Error("auth session create file not found");
|
|
43
42
|
}
|
|
44
43
|
async function runCreate() {
|
|
45
|
-
const
|
|
44
|
+
const result = await (0, _runApi.runApi)({
|
|
46
45
|
automationFunction: {
|
|
47
46
|
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
|
|
48
47
|
params: inputData
|
|
@@ -55,40 +54,18 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
55
54
|
retrieveSession: true,
|
|
56
55
|
importFunction: _tsNodeImport.tsNodeImport
|
|
57
56
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
value,
|
|
62
|
-
done
|
|
63
|
-
} = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
|
|
64
|
-
if (done) {
|
|
65
|
-
if (value.isErr()) {
|
|
66
|
-
if (value.error instanceof _runApi.AutomationError) {
|
|
67
|
-
throw value.error.error;
|
|
68
|
-
}
|
|
69
|
-
console.error(value.error);
|
|
70
|
-
throw new Error("Error while running create");
|
|
71
|
-
}
|
|
72
|
-
const fullState = value.value.session;
|
|
73
|
-
if (pathToSave) {
|
|
74
|
-
const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
|
|
75
|
-
fs.ensureFileSync(fullPath);
|
|
76
|
-
await fs.writeJSON(fullPath, fullState);
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
|
|
81
|
-
nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
|
|
82
|
-
validator: input => {
|
|
83
|
-
if (!value.choices.includes(input)) {
|
|
84
|
-
throw new Error("Please type on of the allowed choices");
|
|
85
|
-
}
|
|
86
|
-
return input;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} else if (value.action === "request_more_info" && value.requestType == "otp") {
|
|
90
|
-
nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
|
|
57
|
+
if (result.isErr()) {
|
|
58
|
+
if (result.error instanceof _runApi.AutomationError) {
|
|
59
|
+
throw result.error.error;
|
|
91
60
|
}
|
|
61
|
+
console.error(result.error);
|
|
62
|
+
throw new Error("Error while running create");
|
|
63
|
+
}
|
|
64
|
+
const fullState = result.value.session;
|
|
65
|
+
if (pathToSave) {
|
|
66
|
+
const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
|
|
67
|
+
fs.ensureFileSync(fullPath);
|
|
68
|
+
await fs.writeJSON(fullPath, fullState);
|
|
92
69
|
}
|
|
93
70
|
}
|
|
94
71
|
await (0, _asyncLocalStorage.runWithContext)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
|
|
1
|
+
export declare function runAutomationCLI<ResultType = any>(importFunction?: (path: string) => Promise<any>): void;
|
|
@@ -64,15 +64,10 @@ function runAutomationCLI(importFunction) {
|
|
|
64
64
|
const throttleTime = 60 * 1000;
|
|
65
65
|
let timeoutTimestamp = Date.now();
|
|
66
66
|
const client = net.createConnection(socketPath);
|
|
67
|
-
let generator = null;
|
|
68
67
|
const abortController = new AbortController();
|
|
69
|
-
client.on("error", err => {
|
|
70
|
-
void generator?.throw(err).catch(() => undefined);
|
|
71
|
-
});
|
|
72
68
|
const interruptSignalHandler = async () => {
|
|
73
69
|
abortController.abort();
|
|
74
70
|
await (0, _promises.setTimeout)(60_000);
|
|
75
|
-
void generator?.throw(new Error("Interrupted")).catch(() => undefined);
|
|
76
71
|
client.end();
|
|
77
72
|
process.exit(1);
|
|
78
73
|
};
|
|
@@ -107,11 +102,6 @@ function runAutomationCLI(importFunction) {
|
|
|
107
102
|
return;
|
|
108
103
|
}
|
|
109
104
|
if (message.type === "start") {
|
|
110
|
-
generator = (0, _runApi.runApiGenerator)({
|
|
111
|
-
...message.parameters,
|
|
112
|
-
abortSignal: abortController.signal,
|
|
113
|
-
importFunction: importFunction ?? _defaultImport
|
|
114
|
-
});
|
|
115
105
|
context = {
|
|
116
106
|
extendedPayloads: [],
|
|
117
107
|
runEnvironment: message.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
|
|
@@ -130,38 +120,18 @@ function runAutomationCLI(importFunction) {
|
|
|
130
120
|
};
|
|
131
121
|
_jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
|
|
132
122
|
resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
|
|
133
|
-
return await
|
|
123
|
+
return await (0, _runApi.runApi)({
|
|
124
|
+
...message.parameters,
|
|
125
|
+
abortSignal: abortController.signal,
|
|
126
|
+
importFunction: importFunction ?? _defaultImport
|
|
127
|
+
});
|
|
134
128
|
});
|
|
135
129
|
return;
|
|
136
130
|
}
|
|
137
131
|
if (message.type === "next") {
|
|
138
|
-
|
|
139
|
-
throw new Error("generator not started");
|
|
140
|
-
}
|
|
141
|
-
resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
|
|
142
|
-
return await generator.next(message.parameters.value);
|
|
143
|
-
});
|
|
144
|
-
return;
|
|
132
|
+
throw new Error("next not supported anymore");
|
|
145
133
|
}
|
|
146
134
|
}
|
|
147
|
-
async function handleResult(generatorResult) {
|
|
148
|
-
if (!generatorResult.done) {
|
|
149
|
-
jsonUnixSocket.sendJSON({
|
|
150
|
-
type: "yield",
|
|
151
|
-
result: generatorResult.value
|
|
152
|
-
});
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
const result = generatorResult.value;
|
|
156
|
-
const success = result.isOk();
|
|
157
|
-
const resultToSend = success ? result.value : result.error.json;
|
|
158
|
-
jsonUnixSocket.sendJSON({
|
|
159
|
-
type: "done",
|
|
160
|
-
result: resultToSend,
|
|
161
|
-
success
|
|
162
|
-
});
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
135
|
let receiveMessagesPromise = receiveMessages();
|
|
166
136
|
while (true) {
|
|
167
137
|
const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
|
|
@@ -199,10 +169,14 @@ function runAutomationCLI(importFunction) {
|
|
|
199
169
|
const {
|
|
200
170
|
result
|
|
201
171
|
} = messageOrResult;
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
172
|
+
const success = result.isOk();
|
|
173
|
+
const resultToSend = success ? result.value : result.error.json;
|
|
174
|
+
jsonUnixSocket.sendJSON({
|
|
175
|
+
type: "done",
|
|
176
|
+
result: resultToSend,
|
|
177
|
+
success
|
|
178
|
+
});
|
|
179
|
+
break;
|
|
206
180
|
}
|
|
207
181
|
if (!client.closed) {
|
|
208
182
|
client.end();
|
|
@@ -179,8 +179,7 @@ async function runCheck({
|
|
|
179
179
|
session: {
|
|
180
180
|
type: "state",
|
|
181
181
|
state: auth
|
|
182
|
-
}
|
|
183
|
-
runCheck: false
|
|
182
|
+
}
|
|
184
183
|
},
|
|
185
184
|
importFunction: _tsNodeImport.tsNodeImport,
|
|
186
185
|
abortSignal
|
|
@@ -241,7 +240,7 @@ async function runCheckWithRetries({
|
|
|
241
240
|
return true;
|
|
242
241
|
}
|
|
243
242
|
} catch (error) {
|
|
244
|
-
if (error instanceof _runApi.
|
|
243
|
+
if (error instanceof _runApi.RunAutomationError) {
|
|
245
244
|
(0, _helpers.logAutomationError)(error);
|
|
246
245
|
} else {
|
|
247
246
|
throw error;
|
|
@@ -270,7 +269,7 @@ async function runCreateWithRetries({
|
|
|
270
269
|
(0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
|
|
271
270
|
break;
|
|
272
271
|
} catch (error) {
|
|
273
|
-
if (error instanceof _runApi.
|
|
272
|
+
if (error instanceof _runApi.RunAutomationError) {
|
|
274
273
|
(0, _helpers.logAutomationError)(error);
|
|
275
274
|
} else {
|
|
276
275
|
throw error;
|
|
@@ -53,7 +53,7 @@ async function runSaveProject(projectName, auth) {
|
|
|
53
53
|
contents: JSON.stringify(_constants.tsConfigCli, null, 2)
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
const
|
|
56
|
+
const saveProjectPayload = {
|
|
57
57
|
codeTree,
|
|
58
58
|
platformType: "CLI",
|
|
59
59
|
language: "typescript"
|
|
@@ -61,13 +61,13 @@ async function runSaveProject(projectName, auth) {
|
|
|
61
61
|
const response = await fetch(url, {
|
|
62
62
|
headers,
|
|
63
63
|
method: "PUT",
|
|
64
|
-
body: JSON.stringify(
|
|
64
|
+
body: JSON.stringify(saveProjectPayload)
|
|
65
65
|
});
|
|
66
66
|
if (!response.ok) {
|
|
67
67
|
if (response.status === 401) {
|
|
68
68
|
throw new _helpers.CLIError(`Invalid API key. Please check your API key and try again.`);
|
|
69
69
|
}
|
|
70
|
-
throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project
|
|
70
|
+
throw new _helpers.CLIError(`^r^+Invalid response from server\n^:^R${response.status} ${await response.text()}^:\n^r^+Project save failed^:\n`, {
|
|
71
71
|
autoColor: false
|
|
72
72
|
});
|
|
73
73
|
}
|
|
@@ -83,29 +83,28 @@ async function runSaveProject(projectName, auth) {
|
|
|
83
83
|
id: projectId
|
|
84
84
|
} = parseResult.data;
|
|
85
85
|
const dotEnvPath = path.join(projectPath, ".env");
|
|
86
|
-
if (await fs.exists(dotEnvPath)) {
|
|
87
|
-
const envContent = await fs.readFile(dotEnvPath, "utf-8");
|
|
88
|
-
const dotenvContent = dotenv.parse(envContent);
|
|
89
|
-
let contentToAppend = "";
|
|
90
|
-
if (!dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] || dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] !== projectId) {
|
|
91
|
-
contentToAppend += `\n${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}`;
|
|
92
|
-
}
|
|
93
|
-
if (!dotenvContent[_constants2.WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
94
|
-
contentToAppend += `\n${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}`;
|
|
95
|
-
}
|
|
96
|
-
if (!dotenvContent[_constants2.API_KEY_ENV_VAR_KEY]) {
|
|
97
|
-
contentToAppend += `\n${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`;
|
|
98
|
-
}
|
|
99
|
-
if (contentToAppend) {
|
|
100
|
-
await fs.appendFile(dotEnvPath, contentToAppend + "\n");
|
|
101
|
-
(0, _terminal.terminal)(`^g^+Updated .env file with project credentials.^:\n`);
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
86
|
+
if (!(await fs.exists(dotEnvPath))) {
|
|
104
87
|
await fs.writeFile(dotEnvPath, `${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}
|
|
105
88
|
${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}
|
|
106
89
|
${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`);
|
|
107
90
|
(0, _terminal.terminal)(`^g^+Created .env file with project credentials.^:\n`);
|
|
108
91
|
}
|
|
92
|
+
const envContent = await fs.readFile(dotEnvPath, "utf-8");
|
|
93
|
+
const dotenvContent = dotenv.parse(envContent);
|
|
94
|
+
let contentToAppend = "";
|
|
95
|
+
if (!dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] || dotenvContent[_constants2.PROJECT_ID_ENV_VAR_KEY] !== projectId) {
|
|
96
|
+
contentToAppend += `\n${_constants2.PROJECT_ID_ENV_VAR_KEY}=${projectId}`;
|
|
97
|
+
}
|
|
98
|
+
if (!dotenvContent[_constants2.WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
99
|
+
contentToAppend += `\n${_constants2.WORKSPACE_ID_ENV_VAR_KEY}=${workspaceId}`;
|
|
100
|
+
}
|
|
101
|
+
if (!dotenvContent[_constants2.API_KEY_ENV_VAR_KEY]) {
|
|
102
|
+
contentToAppend += `\n${_constants2.API_KEY_ENV_VAR_KEY}=${apiKey}`;
|
|
103
|
+
}
|
|
104
|
+
if (contentToAppend) {
|
|
105
|
+
await fs.appendFile(dotEnvPath, contentToAppend + "\n");
|
|
106
|
+
(0, _terminal.terminal)(`^g^+Updated .env file with project credentials.^:\n`);
|
|
107
|
+
}
|
|
109
108
|
}
|
|
110
109
|
const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
|
|
111
110
|
message: "Name cannot be a UUID"
|
|
@@ -124,7 +123,7 @@ const validateProjectName = projectName => {
|
|
|
124
123
|
};
|
|
125
124
|
exports.validateProjectName = validateProjectName;
|
|
126
125
|
const validateIntunedProject = async () => {
|
|
127
|
-
const
|
|
126
|
+
const currentDirectoryToSave = process.cwd();
|
|
128
127
|
const validationSteps = [{
|
|
129
128
|
name: "build",
|
|
130
129
|
check: async () => {
|
|
@@ -150,7 +149,7 @@ const validateIntunedProject = async () => {
|
|
|
150
149
|
name: "package.json",
|
|
151
150
|
check: async () => {
|
|
152
151
|
try {
|
|
153
|
-
const packageJsonPath = path.join(
|
|
152
|
+
const packageJsonPath = path.join(currentDirectoryToSave, "package.json");
|
|
154
153
|
await fs.exists(packageJsonPath);
|
|
155
154
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
|
|
156
155
|
encoding: "utf-8"
|
|
@@ -176,7 +175,7 @@ const validateIntunedProject = async () => {
|
|
|
176
175
|
name: "Intuned.json",
|
|
177
176
|
check: async () => {
|
|
178
177
|
try {
|
|
179
|
-
const intunedJsonPath = path.join(
|
|
178
|
+
const intunedJsonPath = path.join(currentDirectoryToSave, "Intuned.json");
|
|
180
179
|
await fs.exists(intunedJsonPath);
|
|
181
180
|
return {
|
|
182
181
|
isValid: true
|
|
@@ -192,7 +191,7 @@ const validateIntunedProject = async () => {
|
|
|
192
191
|
name: "api folder",
|
|
193
192
|
check: async () => {
|
|
194
193
|
try {
|
|
195
|
-
const apiFolderPath = path.join(
|
|
194
|
+
const apiFolderPath = path.join(currentDirectoryToSave, "api");
|
|
196
195
|
await fs.access(apiFolderPath);
|
|
197
196
|
return {
|
|
198
197
|
isValid: true
|
|
@@ -262,10 +261,10 @@ function listFilesNotIgnored(projectPath, ignorePatterns) {
|
|
|
262
261
|
return results;
|
|
263
262
|
}
|
|
264
263
|
async function convertProjectToCodeTree(projectPath) {
|
|
265
|
-
const
|
|
266
|
-
const
|
|
264
|
+
const filesToSave = listFilesNotIgnored(projectPath, _projectExclusions.default);
|
|
265
|
+
const filesToSaveText = " " + filesToSave.join("\n ");
|
|
267
266
|
(0, _terminal.terminal)("^CFiles to be saved:^:\n");
|
|
268
|
-
(0, _terminal.terminal)(
|
|
267
|
+
(0, _terminal.terminal)(filesToSaveText + "\n");
|
|
269
268
|
function readDirectory(dirPath) {
|
|
270
269
|
const tree = {};
|
|
271
270
|
try {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RunAutomationError } from "../../../common/runApi";
|
|
2
2
|
export declare class CLIError extends Error {
|
|
3
3
|
autoColor: boolean;
|
|
4
4
|
constructor(message: string, options?: {
|
|
@@ -10,5 +10,5 @@ export declare class CLIAssertionError extends CLIError {
|
|
|
10
10
|
autoColor?: boolean;
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
export declare function logAutomationError(error:
|
|
13
|
+
export declare function logAutomationError(error: RunAutomationError): void;
|
|
14
14
|
export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
|
|
@@ -25,11 +25,15 @@ class CLIAssertionError extends CLIError {
|
|
|
25
25
|
exports.CLIAssertionError = CLIAssertionError;
|
|
26
26
|
function logAutomationError(error) {
|
|
27
27
|
(0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
|
|
28
|
-
if (error.
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
if (error instanceof _runApi.AutomationError) {
|
|
29
|
+
if (error.error.stack) {
|
|
30
|
+
const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime") && !line.includes("node:"));
|
|
31
|
+
(0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
|
|
32
|
+
} else {
|
|
33
|
+
(0, _terminal.terminal)(`^r${error.error.message}^:\n`);
|
|
34
|
+
}
|
|
31
35
|
} else {
|
|
32
|
-
(0, _terminal.terminal)(`^r${error.
|
|
36
|
+
(0, _terminal.terminal)(`^r${error.message}^:\n`);
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
function withErrorLogging(fn) {
|
|
@@ -10,9 +10,9 @@ _dotenv.default.config({
|
|
|
10
10
|
path: `.env`
|
|
11
11
|
});
|
|
12
12
|
process.env[_constants.CLI_ENV_VAR_KEY] = "true";
|
|
13
|
-
process.env.RUN_ENVIRONMENT = "
|
|
13
|
+
process.env.RUN_ENVIRONMENT = "AUTHORING";
|
|
14
14
|
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
15
|
-
process.env.FUNCTIONS_DOMAIN = (0, _backend.getBaseUrl)();
|
|
15
|
+
process.env.FUNCTIONS_DOMAIN = (0, _backend.getBaseUrl)().replace(/\/$/, "");
|
|
16
16
|
}
|
|
17
17
|
_commands.program.configureHelp({
|
|
18
18
|
sortSubcommands: true
|
|
@@ -9,6 +9,7 @@ interface TimeoutInfo {
|
|
|
9
9
|
export interface InternalRunInfo extends RunInfo {
|
|
10
10
|
extendedPayloads: Payload[];
|
|
11
11
|
timeoutInfo?: TimeoutInfo;
|
|
12
|
+
store?: Record<string, any>;
|
|
12
13
|
getAuthSessionParameters?: () => Promise<any>;
|
|
13
14
|
}
|
|
14
15
|
export declare function getExecutionContext(): InternalRunInfo | undefined;
|
|
@@ -2,6 +2,7 @@ export declare const API_FOLDER_NAME = "api";
|
|
|
2
2
|
export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
3
3
|
export declare const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
|
|
4
4
|
export declare const WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
|
|
5
|
+
export declare const EXTENSION_PATH_ENV_VAR_KEY = "INTUNED_EXTENSION_PATH";
|
|
5
6
|
export declare const PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
|
|
6
7
|
export declare const API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
|
|
7
8
|
export declare const API_KEY_HEADER_NAME = "x-api-key";
|
package/dist/common/constants.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
|
|
6
|
+
exports.WORKSPACE_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = exports.EXTENSION_PATH_ENV_VAR_KEY = exports.CLI_ENV_VAR_KEY = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = exports.API_KEY_HEADER_NAME = exports.API_KEY_ENV_VAR_KEY = exports.API_FOLDER_NAME = exports.API_BASE_URL_ENV_VAR_KEY = void 0;
|
|
7
7
|
const API_FOLDER_NAME = exports.API_FOLDER_NAME = "api";
|
|
8
8
|
const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
9
9
|
const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
|
|
10
10
|
const WORKSPACE_ID_ENV_VAR_KEY = exports.WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
|
|
11
|
+
const EXTENSION_PATH_ENV_VAR_KEY = exports.EXTENSION_PATH_ENV_VAR_KEY = "INTUNED_EXTENSION_PATH";
|
|
11
12
|
const PROJECT_ID_ENV_VAR_KEY = exports.PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
|
|
12
13
|
const API_KEY_ENV_VAR_KEY = exports.API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
|
|
13
14
|
const API_KEY_HEADER_NAME = exports.API_KEY_HEADER_NAME = "x-api-key";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as playwright from "playwright";
|
|
2
|
+
import { CaptchaSolverSettings } from "./settingsSchema";
|
|
3
|
+
type CaptchaSolverSettingsWithRunContext = CaptchaSolverSettings & {
|
|
4
|
+
workspaceId: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
baseUrl: string;
|
|
7
|
+
token?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function buildExtensionsList(): string[];
|
|
10
|
+
export declare function getIntunedExtensionPath(): string;
|
|
11
|
+
export declare function isIntunedExtensionEnabled(): boolean;
|
|
12
|
+
export declare function getIntunedExtensionWorker(context: playwright.BrowserContext): Promise<playwright.Worker | null>;
|
|
13
|
+
export declare function getIntunedExtensionSettings(): Promise<CaptchaSolverSettingsWithRunContext>;
|
|
14
|
+
export declare function setupIntunedExtension(): Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildExtensionsList = buildExtensionsList;
|
|
7
|
+
exports.getIntunedExtensionPath = getIntunedExtensionPath;
|
|
8
|
+
exports.getIntunedExtensionSettings = getIntunedExtensionSettings;
|
|
9
|
+
exports.getIntunedExtensionWorker = getIntunedExtensionWorker;
|
|
10
|
+
exports.isIntunedExtensionEnabled = isIntunedExtensionEnabled;
|
|
11
|
+
exports.setupIntunedExtension = setupIntunedExtension;
|
|
12
|
+
var _settings = require("../commands/common/utils/settings");
|
|
13
|
+
var _settingsSchema = require("./settingsSchema");
|
|
14
|
+
var _constants = require("./constants");
|
|
15
|
+
var _jwtTokenManager = require("./jwtTokenManager");
|
|
16
|
+
var _path = _interopRequireDefault(require("path"));
|
|
17
|
+
var _promises = require("fs/promises");
|
|
18
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
const INTUNED_WORKER = "intunedWorker.js";
|
|
20
|
+
const INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
|
|
21
|
+
function buildExtensionsList() {
|
|
22
|
+
const extensionsList = [];
|
|
23
|
+
if (isIntunedExtensionEnabled()) {
|
|
24
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
25
|
+
extensionsList.push(intunedExtensionPath);
|
|
26
|
+
}
|
|
27
|
+
return extensionsList;
|
|
28
|
+
}
|
|
29
|
+
function getIntunedExtensionPath() {
|
|
30
|
+
return process.env.INTUNED_EXTENSION_PATH;
|
|
31
|
+
}
|
|
32
|
+
function isIntunedExtensionEnabled() {
|
|
33
|
+
return !!getIntunedExtensionPath();
|
|
34
|
+
}
|
|
35
|
+
async function getIntunedExtensionWorker(context) {
|
|
36
|
+
if (!isIntunedExtensionEnabled()) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
let attemptCount = 0;
|
|
40
|
+
while (attemptCount < 4) {
|
|
41
|
+
const intunedServiceWorker = context.serviceWorkers().find(serviceWorker => serviceWorker.url().includes(INTUNED_WORKER));
|
|
42
|
+
if (intunedServiceWorker) {
|
|
43
|
+
return intunedServiceWorker;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await context.waitForEvent("serviceworker", {
|
|
47
|
+
timeout: 3000
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
attemptCount++;
|
|
51
|
+
console.log(`Error accessing service workers (attempt ${attemptCount})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
console.error("Failed to get intuned worker after 5 attmepts");
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
async function getIntunedExtensionSettings() {
|
|
58
|
+
const settings = await (0, _settings.getSettings)();
|
|
59
|
+
const captchaSolverSettings = settings.captchaSolver ?? _settingsSchema.captchaSolverSettingsSchema.parse({});
|
|
60
|
+
const [domain, workspaceId, projectId] = [process.env.FUNCTIONS_DOMAIN, process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY], process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY]];
|
|
61
|
+
if (!domain || !workspaceId || !projectId) {
|
|
62
|
+
const missingEnvVars = [domain && "FUNCTIONS_DOMAIN", workspaceId && _constants.WORKSPACE_ID_ENV_VAR_KEY, projectId && `INTUNED_INTEGRATION_ID OR ${_constants.PROJECT_ID_ENV_VAR_KEY}`];
|
|
63
|
+
throw new Error(`Missing required environment variables: ${missingEnvVars}`);
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...captchaSolverSettings,
|
|
67
|
+
baseUrl: domain,
|
|
68
|
+
token: _jwtTokenManager.backendFunctionsTokenManager.token,
|
|
69
|
+
workspaceId,
|
|
70
|
+
projectId
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
async function setupIntunedExtension() {
|
|
74
|
+
if (!isIntunedExtensionEnabled()) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
78
|
+
const intunedExtensionSettingsPath = _path.default.join(intunedExtensionPath, INTUNED_EXTENSION_SETTINGS_FILE_NAME);
|
|
79
|
+
const settings = await getIntunedExtensionSettings();
|
|
80
|
+
await (0, _promises.writeFile)(intunedExtensionSettingsPath, JSON.stringify(settings));
|
|
81
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as playwright from "playwright";
|
|
2
|
+
import { RunAutomationError } from "./runApi/errors";
|
|
3
|
+
import type { RunApiSession } from "./runApi/types";
|
|
4
|
+
import { Err, Ok } from "neverthrow";
|
|
5
|
+
import { type ImportFunction } from "./runApi/importUsingImportFunction";
|
|
6
|
+
export interface Proxy {
|
|
7
|
+
server: string;
|
|
8
|
+
username: string;
|
|
9
|
+
password: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function launchChromium(options: {
|
|
12
|
+
proxy?: Proxy;
|
|
13
|
+
headless: boolean;
|
|
14
|
+
downloadsPath?: string;
|
|
15
|
+
cdpPort?: number;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
page: playwright.Page;
|
|
18
|
+
context: playwright.BrowserContext;
|
|
19
|
+
}>;
|
|
20
|
+
export declare function launchChromium(options: {
|
|
21
|
+
cdpAddress: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
page: playwright.Page;
|
|
24
|
+
context: playwright.BrowserContext;
|
|
25
|
+
}>;
|
|
26
|
+
export declare const browserScriptsFile: string;
|
|
27
|
+
type WithPlaywrightContextParameters = {
|
|
28
|
+
importFunction: ImportFunction;
|
|
29
|
+
apiName: string;
|
|
30
|
+
apiParameters: any;
|
|
31
|
+
} | {
|
|
32
|
+
importFunction?: undefined;
|
|
33
|
+
apiName?: undefined;
|
|
34
|
+
apiParameters?: undefined;
|
|
35
|
+
};
|
|
36
|
+
type WithPlaywrightContextWrappedFunctionReturn<R> = Ok<R, any> | Err<any, RunAutomationError>;
|
|
37
|
+
export type WithPlaywrightContextWrappedFunction<R> = (context: playwright.BrowserContext, page: playwright.Page) => Promise<WithPlaywrightContextWrappedFunctionReturn<R>>;
|
|
38
|
+
export declare function withPlaywrightContext<R>(options: {
|
|
39
|
+
proxy?: Proxy;
|
|
40
|
+
headless: boolean;
|
|
41
|
+
downloadsPath: string;
|
|
42
|
+
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
43
|
+
export declare function withPlaywrightContext<R>(options: {
|
|
44
|
+
cdpAddress: string;
|
|
45
|
+
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
46
|
+
export declare function loadSessionToContext({ context, session, }: {
|
|
47
|
+
context: playwright.BrowserContext;
|
|
48
|
+
session: RunApiSession;
|
|
49
|
+
}): Promise<void>;
|
|
50
|
+
export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
|
|
51
|
+
browser: playwright.Browser;
|
|
52
|
+
context: playwright.BrowserContext;
|
|
53
|
+
}>;
|
|
54
|
+
export {};
|