@intuned/runtime-dev 1.0.6-cli-auth.0.0.4-test → 1.0.6-cli-auth.0.0.6-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.
- package/dist/commands/cli-auth-sessions/create.js +11 -4
- package/dist/commands/cli-auth-sessions/utils.d.ts +2 -0
- package/dist/commands/cli-auth-sessions/utils.js +15 -0
- package/dist/commands/run-api-cli/run-api.js +4 -2
- package/dist/commands/run-api-cli/utils.d.ts +3 -1
- package/dist/commands/run-api-cli/utils.js +23 -1
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +3 -2
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
13
13
|
_dotenv.default.config({
|
|
14
14
|
path: `.env`
|
|
15
15
|
});
|
|
16
|
-
_commander.program.description("Create an auth session").option("-i, --input <input>", "Auth session input parameters file").action(async options => {
|
|
16
|
+
_commander.program.description("Create an auth session").option("-i, --input <input>", "Auth session input parameters file").option("-n, --auth-session-name <output>", "Custom name for the auth session instance stored").action(async options => {
|
|
17
17
|
let authSessionInput = {};
|
|
18
18
|
if (options.input) {
|
|
19
19
|
const authSessionInputFile = options.input;
|
|
@@ -21,8 +21,15 @@ _commander.program.description("Create an auth session").option("-i, --input <in
|
|
|
21
21
|
authSessionInput = await fs.readJSON(authSessionInputPath);
|
|
22
22
|
}
|
|
23
23
|
const session = await (0, _utils.runCreateApi)(authSessionInput);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
if (!session) {
|
|
25
|
+
console.error(_chalk.default.red("Failed to create auth session."));
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
const authSessionInstancePath = await (0, _utils.storeAuthSessionInstace)(session, options.authSessionName);
|
|
29
|
+
console.log(_chalk.default.green("✓ Auth session created successfully!"));
|
|
30
|
+
if (authSessionInstancePath) {
|
|
31
|
+
console.log(_chalk.default.underline.green.white(`🔒 Auth session instance stored at ${authSessionInstancePath}`));
|
|
32
|
+
}
|
|
33
|
+
process.exit(0);
|
|
27
34
|
});
|
|
28
35
|
_commander.program.parse(process.argv);
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { StorageState } from "../../common/contextStorageStateHelpers";
|
|
1
2
|
export declare function isAuthEnabled(): Promise<boolean>;
|
|
2
3
|
export declare function ensureCreateApi(): Promise<boolean>;
|
|
3
4
|
export declare function runCreateApi(authSessionInput: Record<string, any>): Promise<any>;
|
|
5
|
+
export declare function storeAuthSessionInstace(authSessionInstance: StorageState, customName?: string): Promise<string>;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.ensureCreateApi = ensureCreateApi;
|
|
7
7
|
exports.isAuthEnabled = isAuthEnabled;
|
|
8
8
|
exports.runCreateApi = runCreateApi;
|
|
9
|
+
exports.storeAuthSessionInstace = storeAuthSessionInstace;
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
var _constants = require("../../common/constants");
|
|
11
12
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
@@ -91,4 +92,18 @@ async function runCreateApiViaCLI(authSessionInput) {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
return session;
|
|
95
|
+
}
|
|
96
|
+
async function storeAuthSessionInstace(authSessionInstance, customName) {
|
|
97
|
+
try {
|
|
98
|
+
const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
|
|
99
|
+
await fs.ensureDir(authSessionsDirectoryPath);
|
|
100
|
+
const authSessionInstanceFileName = customName ?? `auth-session-${Date.now()}`;
|
|
101
|
+
const authSessionInstanceFilePath = _path.default.join(authSessionsDirectoryPath, `${authSessionInstanceFileName}.json`);
|
|
102
|
+
await fs.writeJSON(authSessionInstanceFilePath, authSessionInstance, {
|
|
103
|
+
spaces: 2
|
|
104
|
+
});
|
|
105
|
+
return authSessionInstanceFilePath;
|
|
106
|
+
} catch (error) {
|
|
107
|
+
throw new Error(`Error storing auth session instance: ${error.message}`);
|
|
108
|
+
}
|
|
94
109
|
}
|
|
@@ -12,7 +12,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
12
12
|
_dotenv.default.config({
|
|
13
13
|
path: `.env`
|
|
14
14
|
});
|
|
15
|
-
_commander.program.name("intuned-run").description("Run an Intuned API with parameters").argument("<api-name>", "Name of the API to run").option("-i, --parameters-file <file>", "JSON file containing API parameters").option("-s, --store-results", "Store the results of the running API in a dedicated folder").action(async (apiName, options) => {
|
|
15
|
+
_commander.program.name("intuned-run").description("Run an Intuned API with parameters").argument("<api-name>", "Name of the API to run").option("-i, --parameters-file <file>", "JSON file containing API parameters").option("-a, --auth-session <session>", "Auth session path").option("-s, --store-results", "Store the results of the running API in a dedicated folder").action(async (apiName, options) => {
|
|
16
16
|
try {
|
|
17
17
|
if (!apiName) {
|
|
18
18
|
throw new Error("API name is required, please provide it");
|
|
@@ -26,7 +26,9 @@ _commander.program.name("intuned-run").description("Run an Intuned API with para
|
|
|
26
26
|
runEnvironment: _enums.RunEnvironment.IDE,
|
|
27
27
|
extendedPayloads: [],
|
|
28
28
|
runId
|
|
29
|
-
}, () => (0, _utils.runApiViaCLI)(apiName, inputData
|
|
29
|
+
}, () => (0, _utils.runApiViaCLI)(apiName, inputData, {
|
|
30
|
+
authSessionPath: options.authSession
|
|
31
|
+
}));
|
|
30
32
|
if (!result) {
|
|
31
33
|
console.log(_chalk.default.yellow("No result returned from the API"));
|
|
32
34
|
return;
|
|
@@ -1,7 +1,9 @@
|
|
|
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
|
|
4
|
+
export declare function runApiViaCLI(apiName: string, inputData: object | null | undefined, options?: {
|
|
5
|
+
authSessionPath?: string;
|
|
6
|
+
}): Promise<{
|
|
5
7
|
result: any;
|
|
6
8
|
payloadToAppend: Payload[] | undefined;
|
|
7
9
|
}>;
|
|
@@ -12,6 +12,7 @@ var _Logger = require("../../common/Logger");
|
|
|
12
12
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
13
13
|
var _runApi = require("../../common/runApi");
|
|
14
14
|
var _tsNodeImport = require("../common/tsNodeImport");
|
|
15
|
+
var _utils = require("../../common/cli/utils");
|
|
15
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); }
|
|
16
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; }
|
|
17
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -59,7 +60,21 @@ async function writeResultToFile(runId, result, payloadToAppend) {
|
|
|
59
60
|
_Logger.logger.error(`Failed to write result to file: ${error.message}`);
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
|
-
async function runApiViaCLI(apiName, inputData) {
|
|
63
|
+
async function runApiViaCLI(apiName, inputData, options) {
|
|
64
|
+
let authSessionPathToUse = null;
|
|
65
|
+
if (options !== null && options !== void 0 && options.authSessionPath) {
|
|
66
|
+
const authSessions = await (0, _utils.getSettingIntunedJSON)("authSessions");
|
|
67
|
+
if (authSessions.enabled) {
|
|
68
|
+
if (!options.authSessionPath) {
|
|
69
|
+
throw new Error("Auth session is enabled but no auth session provided");
|
|
70
|
+
}
|
|
71
|
+
authSessionPathToUse = options.authSessionPath;
|
|
72
|
+
} else {
|
|
73
|
+
if (options.authSessionPath) {
|
|
74
|
+
throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
63
78
|
const runApiResult = await (0, _runApi.runApi)({
|
|
64
79
|
automationFunction: {
|
|
65
80
|
name: `api/${apiName}`,
|
|
@@ -69,6 +84,13 @@ async function runApiViaCLI(apiName, inputData) {
|
|
|
69
84
|
headless: false,
|
|
70
85
|
environment: "standalone"
|
|
71
86
|
},
|
|
87
|
+
auth: authSessionPathToUse ? {
|
|
88
|
+
session: {
|
|
89
|
+
type: "file",
|
|
90
|
+
path: authSessionPathToUse
|
|
91
|
+
},
|
|
92
|
+
runCheck: true
|
|
93
|
+
} : undefined,
|
|
72
94
|
importFunction: _tsNodeImport.tsNodeImport
|
|
73
95
|
});
|
|
74
96
|
if (runApiResult.isErr()) {
|
package/dist/common/constants.js
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.AUTH_SESSIONS_FOLDER_NAME = void 0;
|
|
7
|
-
const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
6
|
+
exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = void 0;
|
|
7
|
+
const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
8
|
+
const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = exports.AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
|