@intuned/runtime-dev 1.1.8-bot-detection → 1.2.0-cli.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/.babelrc +2 -2
- package/CHANGELOG.md +5 -1
- package/WebTemplate.zip +0 -0
- package/bin/intuned +2 -0
- package/dist/commands/api/run.js +8 -2
- package/dist/commands/auth-sessions/run-check.js +18 -4
- package/dist/commands/auth-sessions/run-create.js +2 -1
- package/dist/commands/cli-auth-sessions/create.js +1 -1
- package/dist/commands/cli-auth-sessions/utils.d.ts +1 -1
- package/dist/commands/cli-auth-sessions/utils.js +2 -3
- package/dist/commands/common/browserUtils.d.ts +1 -1
- package/dist/commands/common/browserUtils.js +1 -1
- package/dist/commands/common/getFirstLineNumber.js +2 -4
- package/dist/commands/deploy/utils.js +1 -2
- package/dist/commands/init/utils.js +1 -7
- package/dist/commands/interface/run.js +7 -6
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +40 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +24 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +36 -0
- package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/build.command.js +12 -0
- package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
- package/dist/commands/intuned-cli/commands/command.js +9 -0
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/deploy.command.js +47 -0
- package/dist/commands/intuned-cli/commands/helpers.d.ts +26 -0
- package/dist/commands/intuned-cli/commands/helpers.js +126 -0
- package/dist/commands/intuned-cli/commands/index.d.ts +15 -0
- package/dist/commands/intuned-cli/commands/index.js +170 -0
- package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/init.command.js +14 -0
- package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run.command.js +8 -0
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_api.command.js +54 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +21 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +13 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +39 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +39 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +37 -0
- package/dist/commands/intuned-cli/commands/types.d.ts +21 -0
- package/dist/commands/intuned-cli/commands/types.js +21 -0
- package/dist/commands/intuned-cli/controller/api.d.ts +19 -0
- package/dist/commands/intuned-cli/controller/api.js +179 -0
- package/dist/commands/intuned-cli/controller/authSession.d.ts +32 -0
- package/dist/commands/intuned-cli/controller/authSession.js +295 -0
- package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/build.js +36 -0
- package/dist/commands/intuned-cli/controller/deploy.d.ts +15 -0
- package/dist/commands/intuned-cli/controller/deploy.js +397 -0
- package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/index.js +45 -0
- package/dist/commands/intuned-cli/controller/init.d.ts +5 -0
- package/dist/commands/intuned-cli/controller/init.js +139 -0
- package/dist/commands/intuned-cli/index.d.ts +1 -0
- package/dist/commands/intuned-cli/index.js +16 -0
- package/dist/commands/intuned-cli/main.d.ts +1 -0
- package/dist/commands/intuned-cli/main.js +12 -0
- package/dist/commands/intuned-cli/terminal.d.ts +1 -0
- package/dist/commands/intuned-cli/terminal.js +12 -0
- package/dist/commands/run-api-cli/utils.js +6 -6
- package/dist/common/assets/browser_scripts.js +2509 -2143
- package/dist/common/asyncLocalStorage/index.d.ts +1 -2
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
- package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
- package/dist/common/cli/cliReadme.d.ts +1 -1
- package/dist/common/cli/cliReadme.js +14 -23
- package/dist/common/cli/constants.d.ts +4 -2
- package/dist/common/cli/constants.js +7 -3
- package/dist/common/cli/types.d.ts +2 -2
- package/dist/common/cli/utils.d.ts +5 -2
- package/dist/common/cli/utils.js +6 -2
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +2 -1
- package/dist/common/contextStorageStateHelpers.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +12 -12
- package/dist/common/jwtTokenManager.js +3 -5
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/errors.js +5 -6
- package/dist/common/runApi/index.d.ts +4 -1
- package/dist/common/runApi/index.js +21 -21
- package/dist/index.d.ts +1 -1
- package/dist/index.js +6 -0
- package/dist/runtime/executionHelpers.test.js +3 -4
- package/dist/runtime/export.d.ts +16 -0
- package/dist/runtime/extendPayload.js +1 -1
- package/dist/runtime/extendTimeout.js +0 -7
- package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
- package/dist/runtime/getAuthSessionParameters.js +20 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +7 -0
- package/package.json +10 -7
- package/template.tsconfig.json +4 -7
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.executeAttemptApiCLI = executeAttemptApiCLI;
|
|
7
|
+
exports.executeRunApiCLI = executeRunApiCLI;
|
|
8
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
9
|
+
var _runApi = require("../../../common/runApi");
|
|
10
|
+
var _tsNodeImport = require("../../common/tsNodeImport");
|
|
11
|
+
var _authSession = require("./authSession");
|
|
12
|
+
var _utils = require("../../cli-auth-sessions/utils");
|
|
13
|
+
var _helpers = require("../commands/helpers");
|
|
14
|
+
var _terminal = require("../terminal");
|
|
15
|
+
var _constants = require("../../../common/constants");
|
|
16
|
+
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); }
|
|
17
|
+
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; }
|
|
18
|
+
async function executeRunApiCLI({
|
|
19
|
+
apiName,
|
|
20
|
+
inputData,
|
|
21
|
+
retries,
|
|
22
|
+
authSession,
|
|
23
|
+
outputFile,
|
|
24
|
+
...rest
|
|
25
|
+
}) {
|
|
26
|
+
await (0, _helpers.assertApiFileExists)(_constants.API_FOLDER_NAME, apiName);
|
|
27
|
+
(0, _terminal.terminal)(`^+Running API ^c${apiName}^:\n`);
|
|
28
|
+
const apiResult = await (0, _helpers.withCLIContext)(async () => {
|
|
29
|
+
for (let i = 0; i < retries; i++) {
|
|
30
|
+
(0, _terminal.terminal)(`\n^+Executing ^c${apiName} ^/(Attempt ${i + 1}) ^:...\n`);
|
|
31
|
+
let authSessionPathToUse;
|
|
32
|
+
if (authSession) {
|
|
33
|
+
authSessionPathToUse = await (0, _authSession.executeRunValidateAuthSessionCLI)({
|
|
34
|
+
...authSession,
|
|
35
|
+
useExistingContext: true,
|
|
36
|
+
...rest
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
return await attemptApi({
|
|
41
|
+
apiName,
|
|
42
|
+
inputData,
|
|
43
|
+
auth: authSessionPathToUse ? {
|
|
44
|
+
session: {
|
|
45
|
+
type: "file",
|
|
46
|
+
path: authSessionPathToUse
|
|
47
|
+
},
|
|
48
|
+
runCheck: false
|
|
49
|
+
} : undefined,
|
|
50
|
+
...rest
|
|
51
|
+
});
|
|
52
|
+
} catch (error) {
|
|
53
|
+
(0, _terminal.terminal)(`^r^+Failed to run API ^:^+${apiName}^:: ^R${error.message}^:\n`);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
if (apiResult === undefined) {
|
|
59
|
+
throw new _helpers.CLIError(`^r^+Failed to run API ^:^+${apiName}^:: ^RExceeded maximum retries of ^+${retries}^:\n`, {
|
|
60
|
+
autoColor: false
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return handleApiResult({
|
|
64
|
+
apiResult,
|
|
65
|
+
outputFile
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
async function executeAttemptApiCLI({
|
|
69
|
+
apiName,
|
|
70
|
+
inputData,
|
|
71
|
+
authSessionId,
|
|
72
|
+
outputFile,
|
|
73
|
+
...rest
|
|
74
|
+
}) {
|
|
75
|
+
(0, _terminal.terminal)(`^+Execute API attempt for ^c${apiName}^:\n`);
|
|
76
|
+
await (0, _helpers.assertApiFileExists)(_constants.API_FOLDER_NAME, apiName);
|
|
77
|
+
let authSessionInstance;
|
|
78
|
+
if (authSessionId) {
|
|
79
|
+
({
|
|
80
|
+
authSessionInstance
|
|
81
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(authSessionId));
|
|
82
|
+
}
|
|
83
|
+
return await (0, _helpers.withCLIContext)(async () => {
|
|
84
|
+
const apiResult = await attemptApi({
|
|
85
|
+
apiName,
|
|
86
|
+
inputData,
|
|
87
|
+
auth: authSessionInstance ? {
|
|
88
|
+
session: {
|
|
89
|
+
type: "state",
|
|
90
|
+
state: authSessionInstance
|
|
91
|
+
},
|
|
92
|
+
runCheck: false
|
|
93
|
+
} : undefined,
|
|
94
|
+
...rest
|
|
95
|
+
});
|
|
96
|
+
return await handleApiResult({
|
|
97
|
+
apiResult,
|
|
98
|
+
outputFile
|
|
99
|
+
});
|
|
100
|
+
})();
|
|
101
|
+
}
|
|
102
|
+
async function handleApiResult({
|
|
103
|
+
apiResult,
|
|
104
|
+
outputFile
|
|
105
|
+
}) {
|
|
106
|
+
const {
|
|
107
|
+
result,
|
|
108
|
+
payloadToAppend
|
|
109
|
+
} = apiResult;
|
|
110
|
+
(0, _terminal.terminal)(`^+^gAPI executed successfully^:\n`);
|
|
111
|
+
if (!outputFile) {
|
|
112
|
+
if (!result) {
|
|
113
|
+
(0, _terminal.terminal)(`^+^yNo result returned from the API^:\n`);
|
|
114
|
+
} else {
|
|
115
|
+
(0, _terminal.terminal)(`^+^gResult:^:\n`);
|
|
116
|
+
(0, _terminal.terminal)(`${JSON.stringify(result, null, 2)}\n`);
|
|
117
|
+
}
|
|
118
|
+
if (payloadToAppend && payloadToAppend.length > 0) {
|
|
119
|
+
(0, _terminal.terminal)(`^+^gExtended payloads:^ ^/^G(This will only take effect if this API run was part of a job.)^:\n:\n`);
|
|
120
|
+
(0, _terminal.terminal)(`${JSON.stringify(payloadToAppend, null, 2)}\n`);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
await writeResultToFile(outputFile, result, payloadToAppend);
|
|
125
|
+
}
|
|
126
|
+
async function writeResultToFile(outputFile, result, payloadToAppend) {
|
|
127
|
+
const resultToWrite = {
|
|
128
|
+
result
|
|
129
|
+
};
|
|
130
|
+
if (payloadToAppend && payloadToAppend.length > 0) {
|
|
131
|
+
resultToWrite["extendedPayloads"] = payloadToAppend;
|
|
132
|
+
}
|
|
133
|
+
try {
|
|
134
|
+
await fs.writeJSON(outputFile, resultToWrite, {
|
|
135
|
+
spaces: 2
|
|
136
|
+
});
|
|
137
|
+
(0, _terminal.terminal)(`^+^gResults written to^ ^_${outputFile}^:\n`);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new _helpers.CLIError(`Failed to write result to file: ${error.message}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function attemptApi({
|
|
143
|
+
apiName,
|
|
144
|
+
inputData,
|
|
145
|
+
auth,
|
|
146
|
+
proxy,
|
|
147
|
+
headless,
|
|
148
|
+
timeout
|
|
149
|
+
}) {
|
|
150
|
+
return await (0, _helpers.withTimeout)(async () => {
|
|
151
|
+
const runApiResult = await (0, _runApi.runApi)({
|
|
152
|
+
automationFunction: {
|
|
153
|
+
name: `api/${apiName}`,
|
|
154
|
+
params: inputData
|
|
155
|
+
},
|
|
156
|
+
runOptions: {
|
|
157
|
+
headless,
|
|
158
|
+
environment: "standalone",
|
|
159
|
+
proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
|
|
160
|
+
},
|
|
161
|
+
auth,
|
|
162
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
163
|
+
});
|
|
164
|
+
if (runApiResult.isErr()) {
|
|
165
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
166
|
+
throw runApiResult.error.error;
|
|
167
|
+
}
|
|
168
|
+
throw new _helpers.CLIError(`An error occurred while running the API: ${runApiResult.error.message}`);
|
|
169
|
+
}
|
|
170
|
+
const {
|
|
171
|
+
result,
|
|
172
|
+
extendedPayloads: payloadToAppend
|
|
173
|
+
} = runApiResult.value;
|
|
174
|
+
return {
|
|
175
|
+
result,
|
|
176
|
+
payloadToAppend
|
|
177
|
+
};
|
|
178
|
+
}, timeout)();
|
|
179
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BaseCommandOptions } from "../commands/types";
|
|
2
|
+
import { StorageState } from "../../../common/contextStorageStateHelpers";
|
|
3
|
+
export declare function executeRunValidateAuthSessionCLI({ id, autoRecreate, checkRetries, createRetries, useExistingContext, ...rest }: {
|
|
4
|
+
id: string;
|
|
5
|
+
autoRecreate: boolean;
|
|
6
|
+
checkRetries: number;
|
|
7
|
+
createRetries: number;
|
|
8
|
+
useExistingContext?: boolean;
|
|
9
|
+
} & BaseCommandOptions): Promise<string>;
|
|
10
|
+
export declare function executeRunCreateAuthSessionCLI({ id, input, checkRetries, createRetries, log, ...rest }: {
|
|
11
|
+
id?: string;
|
|
12
|
+
input: any;
|
|
13
|
+
checkRetries: number;
|
|
14
|
+
createRetries: number;
|
|
15
|
+
log?: boolean;
|
|
16
|
+
} & BaseCommandOptions): Promise<string>;
|
|
17
|
+
export declare function executeRunUpdateAuthSessionCLI({ id, input, checkRetries, createRetries, ...rest }: {
|
|
18
|
+
id: string;
|
|
19
|
+
input?: any;
|
|
20
|
+
checkRetries: number;
|
|
21
|
+
createRetries: number;
|
|
22
|
+
} & BaseCommandOptions): Promise<string>;
|
|
23
|
+
export declare function executeAttemptCreateAuthSessionCLI({ id, input, ...rest }: {
|
|
24
|
+
id?: string;
|
|
25
|
+
input: any;
|
|
26
|
+
} & BaseCommandOptions): Promise<string>;
|
|
27
|
+
export declare function executeAttemptCheckAuthSessionCLI({ id, ...rest }: {
|
|
28
|
+
id: string;
|
|
29
|
+
} & BaseCommandOptions): Promise<string>;
|
|
30
|
+
export declare function runCreate({ authSessionInput, proxy, headless, timeout, }: {
|
|
31
|
+
authSessionInput: Record<string, any>;
|
|
32
|
+
} & BaseCommandOptions): Promise<StorageState>;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.executeAttemptCheckAuthSessionCLI = executeAttemptCheckAuthSessionCLI;
|
|
7
|
+
exports.executeAttemptCreateAuthSessionCLI = executeAttemptCreateAuthSessionCLI;
|
|
8
|
+
exports.executeRunCreateAuthSessionCLI = executeRunCreateAuthSessionCLI;
|
|
9
|
+
exports.executeRunUpdateAuthSessionCLI = executeRunUpdateAuthSessionCLI;
|
|
10
|
+
exports.executeRunValidateAuthSessionCLI = executeRunValidateAuthSessionCLI;
|
|
11
|
+
exports.runCreate = runCreate;
|
|
12
|
+
var _utils = require("../../cli-auth-sessions/utils");
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
var _helpers = require("../commands/helpers");
|
|
15
|
+
var _runApi = require("../../../common/runApi");
|
|
16
|
+
var _constants = require("../../../common/constants");
|
|
17
|
+
var _tsNodeImport = require("../../common/tsNodeImport");
|
|
18
|
+
var _terminal = require("../terminal");
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
|
+
async function executeRunValidateAuthSessionCLI({
|
|
21
|
+
id,
|
|
22
|
+
autoRecreate,
|
|
23
|
+
checkRetries,
|
|
24
|
+
createRetries,
|
|
25
|
+
useExistingContext = false,
|
|
26
|
+
...rest
|
|
27
|
+
}) {
|
|
28
|
+
const validate = async () => {
|
|
29
|
+
(0, _terminal.terminal)(`^+Validating auth session with id ^c${id}^:\n`);
|
|
30
|
+
const {
|
|
31
|
+
authSessionInstanceStoragePath
|
|
32
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(id, true);
|
|
33
|
+
const authSessionPathToUse = authSessionInstanceStoragePath;
|
|
34
|
+
await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
|
|
35
|
+
const checkResult = await runCheckWithRetries({
|
|
36
|
+
authSessionPath: authSessionPathToUse,
|
|
37
|
+
retries: checkRetries,
|
|
38
|
+
...rest
|
|
39
|
+
});
|
|
40
|
+
if (!checkResult) {
|
|
41
|
+
if (!autoRecreate) {
|
|
42
|
+
throw new _helpers.CLIError("Auto recreate is disabled, please provide a new auth session or update it manually");
|
|
43
|
+
}
|
|
44
|
+
const {
|
|
45
|
+
metadata
|
|
46
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(id);
|
|
47
|
+
if (metadata?.authSessionType === "MANUAL") {
|
|
48
|
+
throw new _helpers.CLIError("Auth session is recorder-based, please provide a new one or update it manually");
|
|
49
|
+
}
|
|
50
|
+
(0, _terminal.terminal)("^+Auto recreate is enabled - trying to re-create it^:\n");
|
|
51
|
+
await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
|
|
52
|
+
const authSessionInput = metadata?.authSessionInput ?? {};
|
|
53
|
+
await runCreateWithRetries({
|
|
54
|
+
authSessionId: id,
|
|
55
|
+
authSessionInput,
|
|
56
|
+
retries: createRetries,
|
|
57
|
+
...rest
|
|
58
|
+
});
|
|
59
|
+
const checkResult = await runCheckWithRetries({
|
|
60
|
+
authSessionPath: authSessionPathToUse,
|
|
61
|
+
retries: checkRetries,
|
|
62
|
+
...rest
|
|
63
|
+
});
|
|
64
|
+
if (!checkResult) {
|
|
65
|
+
throw new _helpers.CLIError("Failed to re-create auth session");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
(0, _terminal.terminal)(`^+^gAuth session validated successfully^:\n`);
|
|
69
|
+
return authSessionPathToUse;
|
|
70
|
+
};
|
|
71
|
+
if (useExistingContext) {
|
|
72
|
+
return await validate();
|
|
73
|
+
} else {
|
|
74
|
+
return await (0, _helpers.withCLIContext)(validate)();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
async function executeRunCreateAuthSessionCLI({
|
|
78
|
+
id,
|
|
79
|
+
input,
|
|
80
|
+
checkRetries,
|
|
81
|
+
createRetries,
|
|
82
|
+
log = true,
|
|
83
|
+
...rest
|
|
84
|
+
}) {
|
|
85
|
+
return (0, _helpers.withCLIContext)(async () => {
|
|
86
|
+
id = id ?? `auth-session-${Date.now()}`;
|
|
87
|
+
(0, _terminal.terminal)(`^+Creating auth session with id ^c${id}^:\n`);
|
|
88
|
+
await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
|
|
89
|
+
const authSessionPath = await runCreateWithRetries({
|
|
90
|
+
authSessionId: id,
|
|
91
|
+
authSessionInput: input,
|
|
92
|
+
retries: createRetries,
|
|
93
|
+
...rest
|
|
94
|
+
});
|
|
95
|
+
const checkResult = await runCheckWithRetries({
|
|
96
|
+
authSessionPath: _path.default.join(authSessionPath, "auth-session.json"),
|
|
97
|
+
retries: checkRetries,
|
|
98
|
+
...rest
|
|
99
|
+
});
|
|
100
|
+
if (!checkResult) {
|
|
101
|
+
throw new _helpers.CLIError("Failed to create auth session");
|
|
102
|
+
}
|
|
103
|
+
if (log) {
|
|
104
|
+
(0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
|
|
105
|
+
}
|
|
106
|
+
return authSessionPath;
|
|
107
|
+
})();
|
|
108
|
+
}
|
|
109
|
+
async function executeRunUpdateAuthSessionCLI({
|
|
110
|
+
id,
|
|
111
|
+
input,
|
|
112
|
+
checkRetries,
|
|
113
|
+
createRetries,
|
|
114
|
+
...rest
|
|
115
|
+
}) {
|
|
116
|
+
(0, _terminal.terminal)(`^+Updating auth session with id ^c${id}^:\n`);
|
|
117
|
+
return (0, _helpers.withCLIContext)(async () => {
|
|
118
|
+
if (input === undefined) {
|
|
119
|
+
const {
|
|
120
|
+
metadata
|
|
121
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(id);
|
|
122
|
+
if (metadata?.authSessionType === "MANUAL") {
|
|
123
|
+
throw new Error("Auth session is recorder-based, it cannot be updated.");
|
|
124
|
+
}
|
|
125
|
+
input = metadata?.authSessionInput ?? {};
|
|
126
|
+
}
|
|
127
|
+
await Promise.all([await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create"), await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check")]);
|
|
128
|
+
const authSession = await executeRunCreateAuthSessionCLI({
|
|
129
|
+
id,
|
|
130
|
+
input,
|
|
131
|
+
checkRetries,
|
|
132
|
+
createRetries,
|
|
133
|
+
log: false,
|
|
134
|
+
...rest
|
|
135
|
+
});
|
|
136
|
+
(0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
|
|
137
|
+
return authSession;
|
|
138
|
+
})();
|
|
139
|
+
}
|
|
140
|
+
async function executeAttemptCreateAuthSessionCLI({
|
|
141
|
+
id,
|
|
142
|
+
input,
|
|
143
|
+
...rest
|
|
144
|
+
}) {
|
|
145
|
+
id = id ?? `auth-session-attempt-${Date.now()}`;
|
|
146
|
+
(0, _terminal.terminal)(`^+Executing create auth session attempt with id ^c${id}^:\n`);
|
|
147
|
+
await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create");
|
|
148
|
+
return await runCreateWithRetries({
|
|
149
|
+
authSessionId: id,
|
|
150
|
+
authSessionInput: input,
|
|
151
|
+
retries: 1,
|
|
152
|
+
...rest
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
async function executeAttemptCheckAuthSessionCLI({
|
|
156
|
+
id,
|
|
157
|
+
...rest
|
|
158
|
+
}) {
|
|
159
|
+
(0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
|
|
160
|
+
await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
|
|
161
|
+
const {
|
|
162
|
+
authSessionInstanceStoragePath
|
|
163
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(id, true);
|
|
164
|
+
const authSessionPathToUse = authSessionInstanceStoragePath;
|
|
165
|
+
const checkResult = await runCheckWithRetries({
|
|
166
|
+
authSessionPath: authSessionPathToUse,
|
|
167
|
+
retries: 1,
|
|
168
|
+
...rest
|
|
169
|
+
});
|
|
170
|
+
if (!checkResult) {
|
|
171
|
+
throw new Error("Check failed");
|
|
172
|
+
}
|
|
173
|
+
(0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
|
|
174
|
+
return authSessionPathToUse;
|
|
175
|
+
}
|
|
176
|
+
async function runCheck({
|
|
177
|
+
authSessionPath,
|
|
178
|
+
proxy,
|
|
179
|
+
headless,
|
|
180
|
+
timeout
|
|
181
|
+
}) {
|
|
182
|
+
return await (0, _helpers.withTimeout)(async () => {
|
|
183
|
+
const runApiResult = await (0, _runApi.runApi)({
|
|
184
|
+
automationFunction: {
|
|
185
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
186
|
+
},
|
|
187
|
+
runOptions: {
|
|
188
|
+
headless,
|
|
189
|
+
environment: "standalone",
|
|
190
|
+
proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
|
|
191
|
+
},
|
|
192
|
+
auth: {
|
|
193
|
+
session: {
|
|
194
|
+
type: "file",
|
|
195
|
+
path: authSessionPath
|
|
196
|
+
},
|
|
197
|
+
runCheck: false
|
|
198
|
+
},
|
|
199
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
200
|
+
});
|
|
201
|
+
if (runApiResult.isErr()) {
|
|
202
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
203
|
+
throw runApiResult.error.error;
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
const result = runApiResult.value.result;
|
|
208
|
+
if (!result) {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
return result;
|
|
212
|
+
}, timeout)();
|
|
213
|
+
}
|
|
214
|
+
async function runCreate({
|
|
215
|
+
authSessionInput,
|
|
216
|
+
proxy,
|
|
217
|
+
headless,
|
|
218
|
+
timeout
|
|
219
|
+
}) {
|
|
220
|
+
return await (0, _helpers.withTimeout)(async () => {
|
|
221
|
+
const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
|
|
222
|
+
const result = await (0, _runApi.runApi)({
|
|
223
|
+
automationFunction: {
|
|
224
|
+
name: createApiName,
|
|
225
|
+
params: authSessionInput
|
|
226
|
+
},
|
|
227
|
+
runOptions: {
|
|
228
|
+
headless,
|
|
229
|
+
environment: "standalone",
|
|
230
|
+
proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
|
|
231
|
+
},
|
|
232
|
+
retrieveSession: true,
|
|
233
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
234
|
+
});
|
|
235
|
+
if (result.isErr()) {
|
|
236
|
+
if (result.error instanceof _runApi.AutomationError) {
|
|
237
|
+
throw result.error.error;
|
|
238
|
+
}
|
|
239
|
+
console.error(result.error);
|
|
240
|
+
throw new Error("Error while running create");
|
|
241
|
+
}
|
|
242
|
+
return result.value.session;
|
|
243
|
+
}, timeout)();
|
|
244
|
+
}
|
|
245
|
+
async function runCheckWithRetries({
|
|
246
|
+
authSessionPath,
|
|
247
|
+
retries,
|
|
248
|
+
...rest
|
|
249
|
+
}) {
|
|
250
|
+
for (let i = 0; i < retries; i++) {
|
|
251
|
+
(0, _terminal.terminal)(`\n^+Running ^cauth session check${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
|
|
252
|
+
try {
|
|
253
|
+
const checkResult = await runCheck({
|
|
254
|
+
authSessionPath,
|
|
255
|
+
...rest
|
|
256
|
+
});
|
|
257
|
+
if (checkResult) {
|
|
258
|
+
(0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
} catch (error) {
|
|
262
|
+
(0, _terminal.terminal)(`^+^yAuth session check failed with error ^:${error.message}^:\n`);
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
(0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
|
|
266
|
+
}
|
|
267
|
+
(0, _terminal.terminal)(`^+^rAuth session check failed after ${retries} attempts^:\n`);
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
async function runCreateWithRetries({
|
|
271
|
+
authSessionId,
|
|
272
|
+
authSessionInput,
|
|
273
|
+
retries,
|
|
274
|
+
...rest
|
|
275
|
+
}) {
|
|
276
|
+
let newAuthSessionInstance = null;
|
|
277
|
+
for (let i = 0; i < retries; i++) {
|
|
278
|
+
(0, _terminal.terminal)(`\n^+Running ^cauth session create${i === 0 ? "" : ` ^/(Attempt ${i + 1})`}^:...\n`);
|
|
279
|
+
try {
|
|
280
|
+
newAuthSessionInstance = await runCreate({
|
|
281
|
+
authSessionInput,
|
|
282
|
+
...rest
|
|
283
|
+
});
|
|
284
|
+
(0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
|
|
285
|
+
break;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
(0, _terminal.terminal)(`^+^yAuth session create failed with error ^:${error.message}^:\n`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (!newAuthSessionInstance) {
|
|
292
|
+
throw new _helpers.CLIError(`Failed to create auth session after ${retries} retries`);
|
|
293
|
+
}
|
|
294
|
+
return await (0, _utils.storeAuthSessionInstance)(newAuthSessionInstance, authSessionId, authSessionInput);
|
|
295
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const runBuild: () => Promise<boolean>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runBuild = void 0;
|
|
7
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
8
|
+
var path = _interopRequireWildcard(require("path"));
|
|
9
|
+
var _child_process = require("child_process");
|
|
10
|
+
var _util = require("util");
|
|
11
|
+
var _terminal = require("../terminal");
|
|
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); }
|
|
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; }
|
|
14
|
+
const execPromise = (0, _util.promisify)(_child_process.exec);
|
|
15
|
+
const runBuild = async () => {
|
|
16
|
+
const distPath = path.join(process.cwd(), "dist");
|
|
17
|
+
if (await fs.exists(distPath)) {
|
|
18
|
+
await fs.remove(distPath);
|
|
19
|
+
}
|
|
20
|
+
const buildCommand = "tsc";
|
|
21
|
+
try {
|
|
22
|
+
await execPromise(buildCommand);
|
|
23
|
+
(0, _terminal.terminal)(`^g^+✨ Build completed successfully!^:\n`);
|
|
24
|
+
return true;
|
|
25
|
+
} catch (error) {
|
|
26
|
+
(0, _terminal.terminal)(`^r^+An error occurred during the build process:^:\n`);
|
|
27
|
+
if ("stdout" in error) {
|
|
28
|
+
(0, _terminal.terminal)(`${error.stdout}\n`);
|
|
29
|
+
} else {
|
|
30
|
+
(0, _terminal.terminal)(`^${error.message}^:\n`);
|
|
31
|
+
}
|
|
32
|
+
(0, _terminal.terminal)(`^r^+Build failed^:\n`);
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
exports.runBuild = runBuild;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AuthCredentials, FileSystemTree } from "../../../common/cli/types";
|
|
3
|
+
export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
|
|
4
|
+
export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
|
|
5
|
+
export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
|
|
6
|
+
export declare const validateProjectName: (projectName: string) => {
|
|
7
|
+
isValid: true;
|
|
8
|
+
} | {
|
|
9
|
+
isValid: false;
|
|
10
|
+
errorMessage: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const validateIntunedProject: () => Promise<{
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
errorMessage?: string;
|
|
15
|
+
}>;
|