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