@intuned/runtime-dev 1.0.6-cli-auth.0.0.3-test → 1.0.6-cli-auth.0.0.4-test
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.
|
@@ -9,10 +9,12 @@ exports.runCreateApi = runCreateApi;
|
|
|
9
9
|
var _path = _interopRequireDefault(require("path"));
|
|
10
10
|
var _constants = require("../../common/constants");
|
|
11
11
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var _utils = require("../run-api-cli/utils");
|
|
13
12
|
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
14
13
|
var _enums = require("../../runtime/enums");
|
|
15
14
|
var _nanoid = require("nanoid");
|
|
15
|
+
var _runApi = require("../../common/runApi");
|
|
16
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
17
|
+
var _promptly = require("promptly");
|
|
16
18
|
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
19
|
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
20
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -32,17 +34,61 @@ async function ensureCreateApi() {
|
|
|
32
34
|
}
|
|
33
35
|
async function runCreateApi(authSessionInput) {
|
|
34
36
|
try {
|
|
35
|
-
const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
|
|
36
37
|
const createApiRunId = (0, _nanoid.nanoid)();
|
|
37
|
-
const
|
|
38
|
+
const authSessionInstance = await (0, _asyncLocalStorage.runWithContext)({
|
|
38
39
|
runEnvironment: _enums.RunEnvironment.IDE,
|
|
39
40
|
extendedPayloads: [],
|
|
40
41
|
runId: createApiRunId
|
|
41
|
-
}, () => (
|
|
42
|
-
|
|
43
|
-
}));
|
|
44
|
-
return runCreateResult;
|
|
42
|
+
}, () => runCreateApiViaCLI(authSessionInput));
|
|
43
|
+
return authSessionInstance;
|
|
45
44
|
} catch (error) {
|
|
46
45
|
throw new Error(`Error running the create API: ${error.message}`);
|
|
47
46
|
}
|
|
47
|
+
}
|
|
48
|
+
async function runCreateApiViaCLI(authSessionInput) {
|
|
49
|
+
const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
|
|
50
|
+
const generator = (0, _runApi.runApiGenerator)({
|
|
51
|
+
automationFunction: {
|
|
52
|
+
name: createApiName,
|
|
53
|
+
params: authSessionInput
|
|
54
|
+
},
|
|
55
|
+
runOptions: {
|
|
56
|
+
headless: false,
|
|
57
|
+
environment: "standalone"
|
|
58
|
+
},
|
|
59
|
+
retrieveSession: true,
|
|
60
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
61
|
+
});
|
|
62
|
+
let session;
|
|
63
|
+
let nextGeneratorParam = undefined;
|
|
64
|
+
while (true) {
|
|
65
|
+
const {
|
|
66
|
+
value,
|
|
67
|
+
done
|
|
68
|
+
} = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
|
|
69
|
+
if (done) {
|
|
70
|
+
if (value.isErr()) {
|
|
71
|
+
if (value.error instanceof _runApi.AutomationError) {
|
|
72
|
+
throw value.error.error;
|
|
73
|
+
}
|
|
74
|
+
console.error(value.error);
|
|
75
|
+
throw new Error("Error while running create");
|
|
76
|
+
}
|
|
77
|
+
session = value.value.session;
|
|
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, {});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return session;
|
|
48
94
|
}
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Payload } from "../../runtime/export";
|
|
2
2
|
export declare function loadParameters(parametersFile: string): Promise<object | null>;
|
|
3
3
|
export declare function writeResultToFile(runId: string, result: any, payloadToAppend?: Payload[]): Promise<void>;
|
|
4
|
-
export declare function runApiViaCLI(apiName: string, inputData: object | null | undefined
|
|
5
|
-
retrieveSession?: boolean;
|
|
6
|
-
}): Promise<{
|
|
4
|
+
export declare function runApiViaCLI(apiName: string, inputData: object | null | undefined): Promise<{
|
|
7
5
|
result: any;
|
|
8
6
|
payloadToAppend: Payload[] | undefined;
|
|
9
|
-
session: import("../../common/contextStorageStateHelpers").StorageState | undefined;
|
|
10
7
|
}>;
|
|
@@ -59,7 +59,7 @@ async function writeResultToFile(runId, result, payloadToAppend) {
|
|
|
59
59
|
_Logger.logger.error(`Failed to write result to file: ${error.message}`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
async function runApiViaCLI(apiName, inputData
|
|
62
|
+
async function runApiViaCLI(apiName, inputData) {
|
|
63
63
|
const runApiResult = await (0, _runApi.runApi)({
|
|
64
64
|
automationFunction: {
|
|
65
65
|
name: `api/${apiName}`,
|
|
@@ -69,7 +69,6 @@ async function runApiViaCLI(apiName, inputData, options) {
|
|
|
69
69
|
headless: false,
|
|
70
70
|
environment: "standalone"
|
|
71
71
|
},
|
|
72
|
-
retrieveSession: (options === null || options === void 0 ? void 0 : options.retrieveSession) ?? false,
|
|
73
72
|
importFunction: _tsNodeImport.tsNodeImport
|
|
74
73
|
});
|
|
75
74
|
if (runApiResult.isErr()) {
|
|
@@ -81,10 +80,8 @@ async function runApiViaCLI(apiName, inputData, options) {
|
|
|
81
80
|
}
|
|
82
81
|
const {
|
|
83
82
|
result,
|
|
84
|
-
extendedPayloads: payloadToAppend
|
|
85
|
-
...rest
|
|
83
|
+
extendedPayloads: payloadToAppend
|
|
86
84
|
} = runApiResult.value;
|
|
87
|
-
const session = "session" in rest ? rest.session : undefined;
|
|
88
85
|
const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
|
|
89
86
|
if (hasPayloadToAppend) {
|
|
90
87
|
_Logger.logger.info("payload to append:", payloadToAppend);
|
|
@@ -92,7 +89,6 @@ async function runApiViaCLI(apiName, inputData, options) {
|
|
|
92
89
|
}
|
|
93
90
|
return {
|
|
94
91
|
result,
|
|
95
|
-
payloadToAppend
|
|
96
|
-
session
|
|
92
|
+
payloadToAppend
|
|
97
93
|
};
|
|
98
94
|
}
|