@intuned/runtime-dev 1.2.0-cli.5 → 1.2.0-cli.7
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 +2 -1
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/constants/index.d.ts +1 -4
- package/dist/commands/intuned-cli/constants/index.js +2 -5
- 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 +25 -0
- package/dist/commands/intuned-cli/controller/api.js +24 -27
- package/dist/commands/intuned-cli/controller/authSession.d.ts +176 -10
- package/dist/commands/intuned-cli/controller/authSession.js +121 -132
- package/dist/commands/intuned-cli/controller/deploy.js +18 -8
- package/dist/commands/intuned-cli/helpers/auth.d.ts +35 -11
- package/dist/commands/intuned-cli/helpers/auth.js +38 -14
- package/dist/commands/intuned-cli/helpers/context.js +1 -1
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +4 -0
- package/dist/commands/intuned-cli/helpers/terminal.js +3 -2
- package/dist/commands/intuned-cli/main.js +4 -1
- package/dist/commands/intuned-cli/types.d.ts +1 -0
- package/dist/common/runApi/types.d.ts +140 -9
- package/dist/common/runApi/types.js +28 -27
- package/package.json +2 -1
- package/tsconfig.json +2 -1
- package/dist/common/cli/cliReadme.d.ts +0 -0
- package/dist/common/cli/cliReadme.js +0 -1
- package/dist/common/cli/constants.d.ts +0 -0
- package/dist/common/cli/constants.js +0 -1
- package/dist/common/cli/types.d.ts +0 -0
- package/dist/common/cli/types.js +0 -1
- package/dist/common/cli/utils.d.ts +0 -0
- package/dist/common/cli/utils.js +0 -1
package/dist/commands/api/run.js
CHANGED
|
@@ -18,6 +18,7 @@ var _chalk = _interopRequireDefault(require("chalk"));
|
|
|
18
18
|
var _runApi = require("../../common/runApi");
|
|
19
19
|
var _tsNodeImport = require("../common/tsNodeImport");
|
|
20
20
|
var _isNil = _interopRequireDefault(require("lodash/isNil"));
|
|
21
|
+
var _constants = require("../../common/constants");
|
|
21
22
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
23
|
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); }
|
|
23
24
|
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; }
|
|
@@ -40,7 +41,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
40
41
|
}
|
|
41
42
|
const runApiResult = await (0, _runApi.runApi)({
|
|
42
43
|
automationFunction: {
|
|
43
|
-
name:
|
|
44
|
+
name: `${_constants.API_FOLDER_NAME}/${apiName}`,
|
|
44
45
|
params: inputData
|
|
45
46
|
},
|
|
46
47
|
auth: authSessionPathToUse ? {
|
|
@@ -10,15 +10,12 @@ export declare const userCLIScripts: {
|
|
|
10
10
|
"pre-publish": string;
|
|
11
11
|
start: string;
|
|
12
12
|
"run-api": string;
|
|
13
|
-
"cli-build": string;
|
|
14
|
-
deploy: string;
|
|
15
|
-
"cli-create-auth-session": string;
|
|
16
|
-
"cli-check-auth-session": string;
|
|
17
13
|
"browser-save-state": string;
|
|
18
14
|
"auth-session-check": string;
|
|
19
15
|
"auth-session-create": string;
|
|
20
16
|
"auth-session-refresh": string;
|
|
21
17
|
"auth-session-load": string;
|
|
18
|
+
intuned: string;
|
|
22
19
|
};
|
|
23
20
|
export declare const tsConfigCli: {
|
|
24
21
|
compilerOptions: {
|
|
@@ -38,15 +38,12 @@ const userCLIScripts = exports.userCLIScripts = {
|
|
|
38
38
|
"pre-publish": "intuned-ts-check && intuned-build",
|
|
39
39
|
start: "node ./output/bundle_v2.js",
|
|
40
40
|
"run-api": "run-api",
|
|
41
|
-
"cli-build": "cli-build",
|
|
42
|
-
deploy: "deploy",
|
|
43
|
-
"cli-create-auth-session": "create-auth-session",
|
|
44
|
-
"cli-check-auth-session": "check-auth-session",
|
|
45
41
|
"browser-save-state": "intuned-browser-save-state",
|
|
46
42
|
"auth-session-check": "intuned-auth-session-check",
|
|
47
43
|
"auth-session-create": "intuned-auth-session-create",
|
|
48
44
|
"auth-session-refresh": "intuned-auth-session-refresh",
|
|
49
|
-
"auth-session-load": "intuned-auth-session-load"
|
|
45
|
+
"auth-session-load": "intuned-auth-session-load",
|
|
46
|
+
intuned: "intuned"
|
|
50
47
|
};
|
|
51
48
|
const tsConfigCli = exports.tsConfigCli = {
|
|
52
49
|
compilerOptions: {
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _vitest = require("vitest");
|
|
4
|
+
var _api = require("../api");
|
|
5
|
+
var _authSession = require("../authSession");
|
|
6
|
+
var _helpers = require("../../helpers");
|
|
7
|
+
var _neverthrow = require("neverthrow");
|
|
8
|
+
var _runApi = require("../../../../common/runApi");
|
|
9
|
+
var _fsExtra = require("fs-extra");
|
|
10
|
+
function getTerminal() {
|
|
11
|
+
return new Proxy(() => ({}), {
|
|
12
|
+
get: () => getTerminal(),
|
|
13
|
+
apply: () => ({})
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
_vitest.vi.mock("fs-extra", () => ({
|
|
17
|
+
writeJSON: _vitest.vi.fn()
|
|
18
|
+
}));
|
|
19
|
+
_vitest.vi.mock("../authSession", async importOriginal => {
|
|
20
|
+
const original = await importOriginal();
|
|
21
|
+
return {
|
|
22
|
+
...original,
|
|
23
|
+
executeRunValidateAuthSessionCLI: _vitest.vi.fn()
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
_vitest.vi.mock("../../../../common/runApi", async importOriginal => {
|
|
27
|
+
const original = await importOriginal();
|
|
28
|
+
return {
|
|
29
|
+
...original,
|
|
30
|
+
runApi: _vitest.vi.fn().mockImplementation(() => (0, _neverthrow.ok)({}))
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
_vitest.vi.mock("../../helpers/terminal", () => ({
|
|
34
|
+
terminal: getTerminal()
|
|
35
|
+
}));
|
|
36
|
+
_vitest.vi.mock("../../helpers", async importOriginal => {
|
|
37
|
+
const original = await importOriginal();
|
|
38
|
+
return {
|
|
39
|
+
...original,
|
|
40
|
+
terminal: getTerminal(),
|
|
41
|
+
assertApiFileExists: _vitest.vi.fn(),
|
|
42
|
+
withCLIContext: _vitest.vi.fn(fn => fn()),
|
|
43
|
+
withTimeout: _vitest.vi.fn(fn => fn()),
|
|
44
|
+
parseUrlProxy: _vitest.vi.fn(),
|
|
45
|
+
registerGetAuthSessionParameters: _vitest.vi.fn()
|
|
46
|
+
};
|
|
47
|
+
});
|
|
48
|
+
(0, _vitest.describe)("API controller", () => {
|
|
49
|
+
(0, _vitest.beforeEach)(() => {
|
|
50
|
+
_vitest.vi.clearAllMocks();
|
|
51
|
+
});
|
|
52
|
+
(0, _vitest.describe)("attemptApi", () => {
|
|
53
|
+
(0, _vitest.it)("calls timeout middleware with timeout", async () => {
|
|
54
|
+
await (0, _api._attemptApi)({
|
|
55
|
+
apiName: "testApi",
|
|
56
|
+
inputData: {},
|
|
57
|
+
headless: false,
|
|
58
|
+
timeout: 6000
|
|
59
|
+
});
|
|
60
|
+
(0, _vitest.expect)(_helpers.withTimeout).toHaveBeenCalledWith(_vitest.expect.any(Function), 6000);
|
|
61
|
+
});
|
|
62
|
+
(0, _vitest.it)("calls runApi with correct parameters and parses proxy", async () => {
|
|
63
|
+
_vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
|
|
64
|
+
await (0, _api._attemptApi)({
|
|
65
|
+
apiName: "testApi",
|
|
66
|
+
inputData: "inputData",
|
|
67
|
+
headless: "headless",
|
|
68
|
+
auth: "auth",
|
|
69
|
+
proxy: "proxy",
|
|
70
|
+
timeout: 999999999
|
|
71
|
+
});
|
|
72
|
+
(0, _vitest.expect)(_helpers.parseUrlProxy).toHaveBeenCalledWith("proxy");
|
|
73
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
|
|
74
|
+
automationFunction: {
|
|
75
|
+
name: "api/testApi",
|
|
76
|
+
params: "inputData"
|
|
77
|
+
},
|
|
78
|
+
runOptions: {
|
|
79
|
+
headless: "headless",
|
|
80
|
+
environment: "standalone",
|
|
81
|
+
proxy: "parsed-proxy"
|
|
82
|
+
},
|
|
83
|
+
auth: {
|
|
84
|
+
session: {
|
|
85
|
+
type: "state",
|
|
86
|
+
state: "auth"
|
|
87
|
+
},
|
|
88
|
+
runCheck: false
|
|
89
|
+
},
|
|
90
|
+
importFunction: _vitest.expect.anything()
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
(0, _vitest.it)("returns the result and extended payloads if runApi succeeds", async () => {
|
|
94
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.ok)({
|
|
95
|
+
result: "result",
|
|
96
|
+
extendedPayloads: "extendedPayloads"
|
|
97
|
+
}));
|
|
98
|
+
const result = await (0, _api._attemptApi)({
|
|
99
|
+
apiName: "testApi",
|
|
100
|
+
inputData: "inputData",
|
|
101
|
+
headless: "headless",
|
|
102
|
+
auth: "auth",
|
|
103
|
+
timeout: 999999999
|
|
104
|
+
});
|
|
105
|
+
(0, _vitest.expect)(result).toEqual({
|
|
106
|
+
result: "result",
|
|
107
|
+
payloadToAppend: "extendedPayloads"
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
(0, _vitest.it)("throws the error runApi fails with an error", async () => {
|
|
111
|
+
const error = new Error("runApi failed");
|
|
112
|
+
_vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
|
|
113
|
+
await (0, _vitest.expect)((0, _api._attemptApi)({
|
|
114
|
+
apiName: "testApi",
|
|
115
|
+
inputData: "inputData",
|
|
116
|
+
headless: "headless",
|
|
117
|
+
auth: "auth",
|
|
118
|
+
timeout: 999999999
|
|
119
|
+
})).rejects.toThrow(error);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
(0, _vitest.describe)("executeRunApiCLI", () => {
|
|
123
|
+
(0, _vitest.it)("calls attemptApi once if success", async () => {
|
|
124
|
+
await (0, _api.executeRunApiCLI)({
|
|
125
|
+
apiName: "testApi",
|
|
126
|
+
inputData: {},
|
|
127
|
+
retries: 3
|
|
128
|
+
});
|
|
129
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
130
|
+
});
|
|
131
|
+
(0, _vitest.it)("stops retrying after max retries", async () => {
|
|
132
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
|
|
133
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
134
|
+
apiName: "testApi",
|
|
135
|
+
inputData: {},
|
|
136
|
+
retries: 10
|
|
137
|
+
})).rejects.toThrow(_helpers.CLIError);
|
|
138
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(10);
|
|
139
|
+
});
|
|
140
|
+
(0, _vitest.it)("stops retrying on non-automation errors", async () => {
|
|
141
|
+
_vitest.vi.mocked(_runApi.runApi).mockRejectedValue(new Error("runApi failed"));
|
|
142
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
143
|
+
apiName: "testApi",
|
|
144
|
+
inputData: {},
|
|
145
|
+
retries: 3
|
|
146
|
+
})).rejects.toThrow("runApi failed");
|
|
147
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
148
|
+
});
|
|
149
|
+
(0, _vitest.it)("stops retrying on success", async () => {
|
|
150
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
|
|
151
|
+
result: "success"
|
|
152
|
+
}));
|
|
153
|
+
await (0, _api.executeRunApiCLI)({
|
|
154
|
+
apiName: "testApi",
|
|
155
|
+
inputData: {},
|
|
156
|
+
retries: 10
|
|
157
|
+
});
|
|
158
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
|
|
159
|
+
});
|
|
160
|
+
(0, _vitest.it)("validates auth session before each attempt if provided", async () => {
|
|
161
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
|
|
162
|
+
result: "success"
|
|
163
|
+
}));
|
|
164
|
+
await (0, _api.executeRunApiCLI)({
|
|
165
|
+
apiName: "testApi",
|
|
166
|
+
inputData: {},
|
|
167
|
+
authSession: {
|
|
168
|
+
id: "authSessionId",
|
|
169
|
+
autoRecreate: false,
|
|
170
|
+
checkRetries: 1,
|
|
171
|
+
createRetries: 2
|
|
172
|
+
},
|
|
173
|
+
retries: 10
|
|
174
|
+
});
|
|
175
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toBeCalledTimes(2);
|
|
176
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith({
|
|
177
|
+
id: "authSessionId",
|
|
178
|
+
autoRecreate: false,
|
|
179
|
+
checkRetries: 1,
|
|
180
|
+
createRetries: 2
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
(0, _vitest.it)("doesn't validate auth session if not provided", async () => {
|
|
184
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
185
|
+
result: "success"
|
|
186
|
+
}));
|
|
187
|
+
await (0, _api.executeRunApiCLI)({
|
|
188
|
+
apiName: "testApi",
|
|
189
|
+
inputData: {},
|
|
190
|
+
retries: 1
|
|
191
|
+
});
|
|
192
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
(0, _vitest.it)("fails if auth session is provided but not valid", async () => {
|
|
195
|
+
_vitest.vi.mocked(_authSession.executeRunValidateAuthSessionCLI).mockRejectedValue(new _helpers.CLIError("Auth session validation failed"));
|
|
196
|
+
await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
|
|
197
|
+
apiName: "testApi",
|
|
198
|
+
inputData: {},
|
|
199
|
+
authSession: {
|
|
200
|
+
id: "authSessionId",
|
|
201
|
+
autoRecreate: false,
|
|
202
|
+
checkRetries: 1,
|
|
203
|
+
createRetries: 2
|
|
204
|
+
},
|
|
205
|
+
retries: 10
|
|
206
|
+
})).rejects.toThrow("Auth session validation failed");
|
|
207
|
+
(0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith({
|
|
208
|
+
id: "authSessionId",
|
|
209
|
+
autoRecreate: false,
|
|
210
|
+
checkRetries: 1,
|
|
211
|
+
createRetries: 2
|
|
212
|
+
});
|
|
213
|
+
(0, _vitest.expect)(_runApi.runApi).not.toHaveBeenCalled();
|
|
214
|
+
});
|
|
215
|
+
(0, _vitest.it)("writes result to file if outputFile is provided", async () => {
|
|
216
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
217
|
+
result: "result",
|
|
218
|
+
extendedPayloads: "extendedPayloads"
|
|
219
|
+
}));
|
|
220
|
+
await (0, _api.executeRunApiCLI)({
|
|
221
|
+
apiName: "testApi",
|
|
222
|
+
inputData: {},
|
|
223
|
+
outputFile: "output.json",
|
|
224
|
+
retries: 1
|
|
225
|
+
});
|
|
226
|
+
(0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
|
|
227
|
+
result: "result",
|
|
228
|
+
extendedPayloads: "extendedPayloads"
|
|
229
|
+
}, _vitest.expect.anything());
|
|
230
|
+
});
|
|
231
|
+
(0, _vitest.it)("asserts API file exists", async () => {
|
|
232
|
+
await (0, _api.executeRunApiCLI)({
|
|
233
|
+
apiName: "testApi",
|
|
234
|
+
inputData: {},
|
|
235
|
+
retries: 1
|
|
236
|
+
});
|
|
237
|
+
(0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
(0, _vitest.describe)("executeAttemptApiCLI", () => {
|
|
241
|
+
(0, _vitest.it)("calls attemptApi once", async () => {
|
|
242
|
+
await (0, _api.executeAttemptApiCLI)({
|
|
243
|
+
apiName: "testApi",
|
|
244
|
+
inputData: {},
|
|
245
|
+
retries: 3
|
|
246
|
+
});
|
|
247
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
248
|
+
_vitest.vi.mocked(_runApi.runApi).mockReset();
|
|
249
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
|
|
250
|
+
await (0, _vitest.expect)((0, _api.executeAttemptApiCLI)({
|
|
251
|
+
apiName: "testApi",
|
|
252
|
+
inputData: {}
|
|
253
|
+
})).rejects.toThrow(_runApi.AutomationError);
|
|
254
|
+
(0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
|
|
255
|
+
});
|
|
256
|
+
(0, _vitest.it)("writes result to file if outputFile is provided", async () => {
|
|
257
|
+
_vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
|
|
258
|
+
result: "result",
|
|
259
|
+
extendedPayloads: "extendedPayloads"
|
|
260
|
+
}));
|
|
261
|
+
await (0, _api.executeAttemptApiCLI)({
|
|
262
|
+
apiName: "testApi",
|
|
263
|
+
inputData: {},
|
|
264
|
+
outputFile: "output.json"
|
|
265
|
+
});
|
|
266
|
+
(0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
|
|
267
|
+
result: "result",
|
|
268
|
+
extendedPayloads: "extendedPayloads"
|
|
269
|
+
}, _vitest.expect.anything());
|
|
270
|
+
});
|
|
271
|
+
(0, _vitest.it)("asserts API file exists", async () => {
|
|
272
|
+
await (0, _api.executeRunApiCLI)({
|
|
273
|
+
apiName: "testApi",
|
|
274
|
+
inputData: {},
|
|
275
|
+
retries: 1
|
|
276
|
+
});
|
|
277
|
+
(0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|