@intuned/runtime-dev 1.3.1-api-token.5 → 1.3.3-fix.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/commands/run_authsession.command.d.ts +2 -1
- package/dist/commands/intuned-cli/commands/types.d.ts +1 -1
- 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 +28 -29
- 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/jwtTokenManager.d.ts +1 -1
- package/dist/common/jwtTokenManager.js +18 -13
- package/dist/common/playwrightContext.d.ts +54 -0
- package/dist/common/{getPlaywrightConstructs.js → playwrightContext.js} +148 -79
- 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 +3 -7
- package/dist/common/runApi/types.js +1 -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/dist/common/getPlaywrightConstructs.d.ts +0 -30
- 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();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare const baseRunAuthSessionCommandOptionsSchema: import("zod").ZodObject<{
|
|
2
2
|
proxy: import("zod").ZodOptional<import("zod").ZodString>;
|
|
3
|
-
headless: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
4
3
|
timeout: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodDefault<import("zod").ZodString>, import("ms").StringValue, string | undefined>, number, string | undefined>;
|
|
4
|
+
headless: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
5
|
+
} & {
|
|
5
6
|
checkAttempts: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
6
7
|
createAttempts: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
7
8
|
}, "strip", import("zod").ZodTypeAny, {
|
|
@@ -15,7 +15,7 @@ export declare const baseCommandOptionsSchema: z.ZodObject<{
|
|
|
15
15
|
proxy?: string | undefined;
|
|
16
16
|
}, {
|
|
17
17
|
proxy?: string | undefined;
|
|
18
|
-
timeout?: string | undefined;
|
|
19
18
|
headless?: boolean | undefined;
|
|
19
|
+
timeout?: string | undefined;
|
|
20
20
|
}>;
|
|
21
21
|
export type BaseCommandOptions = z.infer<typeof baseCommandOptionsSchema>;
|
|
@@ -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;
|
|
@@ -43,7 +43,7 @@ async function runSaveProject(projectName, auth) {
|
|
|
43
43
|
const baseUrl = (0, _helpers.getBaseUrl)();
|
|
44
44
|
const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}`;
|
|
45
45
|
const headers = {
|
|
46
|
-
|
|
46
|
+
[_constants2.API_KEY_HEADER_NAME]: apiKey,
|
|
47
47
|
"Content-Type": "application/json"
|
|
48
48
|
};
|
|
49
49
|
const projectPath = process.cwd();
|
|
@@ -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;
|
|
@@ -10,7 +10,7 @@ declare class JwtTokenManager {
|
|
|
10
10
|
private scheduleTokenRefresh;
|
|
11
11
|
private refreshToken;
|
|
12
12
|
fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
|
|
13
|
-
get backendFunctionsBaseUrl(): string;
|
|
13
|
+
get backendFunctionsBaseUrl(): string | undefined;
|
|
14
14
|
}
|
|
15
15
|
export declare const backendFunctionsTokenManager: JwtTokenManager;
|
|
16
16
|
export declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
|
|
@@ -9,7 +9,6 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
|
9
9
|
var jwt = _interopRequireWildcard(require("jsonwebtoken"));
|
|
10
10
|
var _neverthrow = require("neverthrow");
|
|
11
11
|
var _constants = require("./constants");
|
|
12
|
-
var _helpers = require("../commands/intuned-cli/helpers");
|
|
13
12
|
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); }
|
|
14
13
|
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 && {}.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; }
|
|
15
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -82,19 +81,25 @@ class JwtTokenManager {
|
|
|
82
81
|
return result;
|
|
83
82
|
}
|
|
84
83
|
get backendFunctionsBaseUrl() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
try {
|
|
85
|
+
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
86
|
+
throw new Error(`Cannot call backend function - FUNCTIONS_DOMAIN not set`);
|
|
87
|
+
}
|
|
88
|
+
const domain = process.env.FUNCTIONS_DOMAIN;
|
|
89
|
+
if (!process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
90
|
+
throw new Error(`Cannot call backend function - ${_constants.WORKSPACE_ID_ENV_VAR_KEY} not set`);
|
|
91
|
+
}
|
|
92
|
+
const workspaceId = process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY];
|
|
93
|
+
if (!process.env[_constants.PROJECT_ID_ENV_VAR_KEY] && !process.env.INTUNED_INTEGRATION_ID) {
|
|
94
|
+
throw new Error(`Cannot call backend function - ${_constants.PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`);
|
|
95
|
+
}
|
|
96
|
+
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY];
|
|
97
|
+
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
|
+
} catch (e) {
|
|
99
|
+
if (process.env[_constants.CLI_ENV_VAR_KEY] === "true") {
|
|
100
|
+
throw new Error(`API credentials not set - make sure to save your project to Intuned to set up the correct API credentials.\nOriginal error: ${e.message}`);
|
|
101
|
+
}
|
|
95
102
|
}
|
|
96
|
-
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY];
|
|
97
|
-
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
103
|
}
|
|
99
104
|
}
|
|
100
105
|
const backendFunctionsTokenManager = exports.backendFunctionsTokenManager = new JwtTokenManager(`refreshBackendFunctionsToken`);
|
|
@@ -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 {};
|