@intuned/runtime-dev 1.0.6-test-ping.0 → 1.1.2-auth-helper.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/LICENSE +43 -0
- package/bin/check-auth-session +3 -0
- package/bin/cli-build +3 -0
- package/bin/create-auth-session +3 -0
- package/bin/deploy +3 -0
- package/bin/init +3 -0
- package/bin/run-api +3 -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/check.d.ts +2 -0
- package/dist/commands/cli-auth-sessions/check.js +40 -0
- package/dist/commands/cli-auth-sessions/create.d.ts +2 -0
- package/dist/commands/cli-auth-sessions/create.js +53 -0
- package/dist/commands/cli-auth-sessions/utils.d.ts +28 -0
- package/dist/commands/cli-auth-sessions/utils.js +285 -0
- package/dist/commands/cli-build/cli-build.d.ts +2 -0
- package/dist/commands/cli-build/cli-build.js +20 -0
- package/dist/commands/common/projectExclusions.d.ts +2 -0
- package/dist/commands/common/projectExclusions.js +8 -0
- package/dist/commands/deploy/deploy.d.ts +2 -0
- package/dist/commands/deploy/deploy.js +47 -0
- package/dist/commands/deploy/utils.d.ts +16 -0
- package/dist/commands/deploy/utils.js +408 -0
- package/dist/commands/init/init.d.ts +2 -0
- package/dist/commands/init/init.js +22 -0
- package/dist/commands/init/utils.d.ts +11 -0
- package/dist/commands/init/utils.js +181 -0
- package/dist/commands/interface/run.js +2 -0
- package/dist/commands/run-api-cli/run-api.d.ts +2 -0
- package/dist/commands/run-api-cli/run-api.js +57 -0
- package/dist/commands/run-api-cli/utils.d.ts +9 -0
- package/dist/commands/run-api-cli/utils.js +144 -0
- package/dist/common/asyncLocalStorage/index.d.ts +2 -3
- package/dist/common/asyncLocalStorage/index.js +2 -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 -0
- package/dist/common/cli/cliReadme.js +92 -0
- package/dist/common/cli/constants.d.ts +33 -0
- package/dist/common/cli/constants.js +39 -0
- package/dist/common/cli/types.d.ts +74 -0
- package/dist/common/cli/types.js +13 -0
- package/dist/common/cli/utils.d.ts +6 -0
- package/dist/common/cli/utils.js +35 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +3 -2
- package/dist/common/contextStorageStateHelpers.d.ts +1 -1
- package/dist/runtime/export.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +0 -7
- package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
- package/dist/runtime/getAuthSessionParameters.js +20 -0
- package/package.json +41 -41
package/LICENSE
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
Acceptance
|
|
2
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
3
|
+
|
|
4
|
+
Copyright License
|
|
5
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
|
|
6
|
+
|
|
7
|
+
Limitations
|
|
8
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
9
|
+
|
|
10
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
11
|
+
|
|
12
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
13
|
+
|
|
14
|
+
Patents
|
|
15
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
16
|
+
|
|
17
|
+
Notices
|
|
18
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
19
|
+
|
|
20
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
21
|
+
|
|
22
|
+
No Other Rights
|
|
23
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
24
|
+
|
|
25
|
+
Termination
|
|
26
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
27
|
+
|
|
28
|
+
No Liability
|
|
29
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
30
|
+
|
|
31
|
+
Definitions
|
|
32
|
+
The licensor is the entity offering these terms, and the software is the software the licensor makes available under these terms, including any portion of it.
|
|
33
|
+
|
|
34
|
+
you refers to the individual or entity agreeing to these terms.
|
|
35
|
+
|
|
36
|
+
your company is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
37
|
+
|
|
38
|
+
your licenses are all the licenses granted to you for the software under these terms.
|
|
39
|
+
|
|
40
|
+
use means anything you do with the software requiring one of your licenses.
|
|
41
|
+
|
|
42
|
+
trademark means trademarks, service marks, and similar rights.
|
|
43
|
+
|
package/bin/cli-build
ADDED
package/bin/deploy
ADDED
package/bin/init
ADDED
package/bin/run-api
ADDED
package/dist/commands/api/run.js
CHANGED
|
@@ -17,6 +17,7 @@ var _nanoid = require("nanoid");
|
|
|
17
17
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
18
|
var _runApi = require("../../common/runApi");
|
|
19
19
|
var _tsNodeImport = require("../common/tsNodeImport");
|
|
20
|
+
var _isNil = _interopRequireDefault(require("lodash/isNil"));
|
|
20
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
22
|
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); }
|
|
22
23
|
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; }
|
|
@@ -95,7 +96,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
95
96
|
_Logger.logger.info("This will only take an effect if this API run was part of a job.");
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
_commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
|
|
99
|
+
_commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").option("--authSessionPath <authSessionParameters>", "parameters used to create the used auth session").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
|
|
99
100
|
let inputData = null;
|
|
100
101
|
if (options.input) {
|
|
101
102
|
inputData = await fs.readJSON(options.input);
|
|
@@ -104,11 +105,16 @@ _commander.program.description("run the user function in the cli for testing pur
|
|
|
104
105
|
} else {
|
|
105
106
|
inputData = {};
|
|
106
107
|
}
|
|
108
|
+
let authSessionParametersJson = undefined;
|
|
109
|
+
if (!(0, _isNil.default)(options === null || options === void 0 ? void 0 : options.authSessionParameters)) {
|
|
110
|
+
authSessionParametersJson = JSON.parse(options.authSessionParameters);
|
|
111
|
+
}
|
|
107
112
|
await (0, _asyncLocalStorage.runWithContext)({
|
|
108
113
|
runEnvironment: _enums.RunEnvironment.IDE,
|
|
109
114
|
extendedPayloads: [],
|
|
110
115
|
runId: (0, _nanoid.nanoid)(),
|
|
111
|
-
proxy: options.proxy
|
|
116
|
+
proxy: options.proxy,
|
|
117
|
+
getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
|
|
112
118
|
}, () => executeCLI(apiName, mode, inputData, options));
|
|
113
119
|
process.exit(0);
|
|
114
120
|
});
|
|
@@ -9,15 +9,20 @@ var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
|
9
9
|
var _constants = require("../../common/constants");
|
|
10
10
|
var _runApi = require("../../common/runApi");
|
|
11
11
|
var _tsNodeImport = require("../common/tsNodeImport");
|
|
12
|
+
var _enums = require("../../runtime/enums");
|
|
13
|
+
var _nanoid = require("nanoid");
|
|
14
|
+
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
15
|
+
var _isNil = _interopRequireDefault(require("lodash/isNil"));
|
|
12
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
17
|
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); }
|
|
14
18
|
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; }
|
|
15
19
|
_dotenv.default.config({
|
|
16
20
|
path: `.env`
|
|
17
21
|
});
|
|
18
|
-
_commander.program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
|
|
22
|
+
_commander.program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").option("--authSessionPath <authSessionParameters>", "parameters used to create the used auth session").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
|
|
19
23
|
cdpAddress,
|
|
20
|
-
authSessionPath
|
|
24
|
+
authSessionPath,
|
|
25
|
+
authSessionParameters
|
|
21
26
|
}) => {
|
|
22
27
|
const setting = await (0, _settings.getSettings)();
|
|
23
28
|
if (!setting.authSessions.enabled) {
|
|
@@ -27,7 +32,16 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
27
32
|
if (!fs.exists(checkFilePath)) {
|
|
28
33
|
throw new Error("auth session check file not found");
|
|
29
34
|
}
|
|
30
|
-
|
|
35
|
+
let authSessionParametersJson = undefined;
|
|
36
|
+
if (!(0, _isNil.default)(authSessionParameters)) {
|
|
37
|
+
authSessionParametersJson = JSON.parse(authSessionParameters);
|
|
38
|
+
}
|
|
39
|
+
const runApiResult = await (0, _asyncLocalStorage.runWithContext)({
|
|
40
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
41
|
+
extendedPayloads: [],
|
|
42
|
+
runId: (0, _nanoid.nanoid)(),
|
|
43
|
+
getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
|
|
44
|
+
}, async () => await (0, _runApi.runApi)({
|
|
31
45
|
automationFunction: {
|
|
32
46
|
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
33
47
|
},
|
|
@@ -44,7 +58,7 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
44
58
|
runCheck: false
|
|
45
59
|
},
|
|
46
60
|
importFunction: _tsNodeImport.tsNodeImport
|
|
47
|
-
});
|
|
61
|
+
}));
|
|
48
62
|
if (runApiResult.isErr()) {
|
|
49
63
|
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
50
64
|
throw runApiResult.error.error;
|
|
@@ -94,7 +94,8 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
94
94
|
await (0, _asyncLocalStorage.runWithContext)({
|
|
95
95
|
runEnvironment: _enums.RunEnvironment.IDE,
|
|
96
96
|
extendedPayloads: [],
|
|
97
|
-
runId: (0, _nanoid.nanoid)()
|
|
97
|
+
runId: (0, _nanoid.nanoid)(),
|
|
98
|
+
getAuthSessionParameters: async () => inputData
|
|
98
99
|
}, runCreate);
|
|
99
100
|
process.exit(0);
|
|
100
101
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
6
|
+
var _utils = require("./utils");
|
|
7
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
_dotenv.default.config({
|
|
10
|
+
path: `.env`
|
|
11
|
+
});
|
|
12
|
+
_commander.program.description("Check an auth session, if it is still valid or not").argument("<auth-session>", "Name/id of the auth session instance to use").action(async authSession => {
|
|
13
|
+
try {
|
|
14
|
+
if (!authSession) {
|
|
15
|
+
throw new Error("Auth session instance is required, provide an ID/name for it");
|
|
16
|
+
}
|
|
17
|
+
const _isAuthEnabled = await (0, _utils.isAuthEnabled)();
|
|
18
|
+
if (!_isAuthEnabled) {
|
|
19
|
+
throw new Error("Auth session is not enabled, enable it in Intuned.json to be able to use it");
|
|
20
|
+
}
|
|
21
|
+
const checkApiExists = await (0, _utils.ensureAuthApi)("check");
|
|
22
|
+
if (!checkApiExists) {
|
|
23
|
+
throw new Error("Auth check API not implemented, please create it in the auth sessions specified directory");
|
|
24
|
+
}
|
|
25
|
+
const {
|
|
26
|
+
authSessionInstanceStoragePath
|
|
27
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(authSession, true);
|
|
28
|
+
const checkResult = await (0, _utils.runCheckApi)(authSessionInstanceStoragePath);
|
|
29
|
+
if (checkResult) {
|
|
30
|
+
console.log(_chalk.default.green("✓ Auth session checked successfully"));
|
|
31
|
+
} else {
|
|
32
|
+
console.log(_chalk.default.red("✗ Auth session is not valid, check failed"));
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(_chalk.default.red(`Failed to check auth session: ${error.message}`));
|
|
36
|
+
} finally {
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
6
|
+
var _utils = require("./utils");
|
|
7
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
8
|
+
var _utils2 = require("../run-api-cli/utils");
|
|
9
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
+
_dotenv.default.config({
|
|
11
|
+
path: `.env`
|
|
12
|
+
});
|
|
13
|
+
_commander.program.description("Create an auth session").argument("[auth-session-name]", "Name/id of the auth session instance to use (optional)").option("-i, --input <input>", "Auth session input parameters file").action(async (authSessionName, options) => {
|
|
14
|
+
try {
|
|
15
|
+
const _isAuthEnabled = await (0, _utils.isAuthEnabled)();
|
|
16
|
+
if (!_isAuthEnabled) {
|
|
17
|
+
throw new Error("Auth session is not enabled, enable it in Intuned.json to be able to use it");
|
|
18
|
+
}
|
|
19
|
+
const authType = await (0, _utils.getAuthType)();
|
|
20
|
+
let authSessionInstancePath;
|
|
21
|
+
if (authType === "MANUAL") {
|
|
22
|
+
const recorderConfig = await (0, _utils.ensureRecorderURLs)();
|
|
23
|
+
const {
|
|
24
|
+
startUrl,
|
|
25
|
+
endUrl
|
|
26
|
+
} = recorderConfig;
|
|
27
|
+
console.log(_chalk.default.blue("Starting auth session recorder..."));
|
|
28
|
+
const session = await (0, _utils.recordAuthSession)(startUrl, endUrl);
|
|
29
|
+
authSessionInstancePath = await (0, _utils.storeAuthSessionInstance)(session, authSessionName, {});
|
|
30
|
+
} else {
|
|
31
|
+
const createApiExists = await (0, _utils.ensureAuthApi)("create");
|
|
32
|
+
if (!createApiExists) {
|
|
33
|
+
throw new Error("Auth session create API not implemented, please create it in the auth sessions specified directory");
|
|
34
|
+
}
|
|
35
|
+
const authSessionInput = (await (0, _utils2.loadParameters)(options === null || options === void 0 ? void 0 : options.input)) ?? {};
|
|
36
|
+
const session = await (0, _utils.runCreateApi)(authSessionInput);
|
|
37
|
+
if (!session) {
|
|
38
|
+
console.error(_chalk.default.red("Failed to create auth session."));
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
authSessionInstancePath = await (0, _utils.storeAuthSessionInstance)(session, authSessionName, authSessionInput);
|
|
42
|
+
}
|
|
43
|
+
console.log(_chalk.default.green("✓ Auth session created successfully!"));
|
|
44
|
+
if (authSessionInstancePath) {
|
|
45
|
+
console.log(_chalk.default.underline.green.white(`🔒 Auth session instance and metadata stored at ${authSessionInstancePath}`));
|
|
46
|
+
}
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error(_chalk.default.red(`Failed to create auth session: ${error.message}`));
|
|
49
|
+
} finally {
|
|
50
|
+
process.exit(0);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { StorageState } from "../../common/contextStorageStateHelpers";
|
|
2
|
+
import { AuthSessionMetadata, AuthSessionType } from "../../common/cli/types";
|
|
3
|
+
import * as playwright from "playwright-core";
|
|
4
|
+
export declare function isAuthEnabled(): Promise<boolean>;
|
|
5
|
+
export declare function getAuthType(): Promise<AuthSessionType>;
|
|
6
|
+
export declare function ensureRecorderURLs(): Promise<{
|
|
7
|
+
startUrl: string;
|
|
8
|
+
endUrl: string;
|
|
9
|
+
}>;
|
|
10
|
+
export declare function ensureAuthApi(operation: "create" | "check"): Promise<boolean>;
|
|
11
|
+
export declare function runCreateApi(authSessionInput: Record<string, any>): Promise<StorageState>;
|
|
12
|
+
export declare function runCheckApi(authSessionPath: string): Promise<boolean>;
|
|
13
|
+
export declare function runCreateApiViaCLI(authSessionInput: Record<string, any>): Promise<StorageState>;
|
|
14
|
+
export declare function runCheckApiViaCLI(authSessionPath: string): Promise<boolean>;
|
|
15
|
+
export declare function storeAuthSessionInstance(authSessionInstance: StorageState, customName?: string, authSessionInput?: Record<string, any>): Promise<string>;
|
|
16
|
+
export declare function retrieveAuthSessionInstance(authSessionId: string, pathsOnly?: boolean): Promise<{
|
|
17
|
+
authSessionInstanceStoragePath: string;
|
|
18
|
+
authSessionInstanceMetadataPath: string;
|
|
19
|
+
authSessionInstance?: undefined;
|
|
20
|
+
metadata?: undefined;
|
|
21
|
+
} | {
|
|
22
|
+
authSessionInstance: StorageState;
|
|
23
|
+
metadata: AuthSessionMetadata;
|
|
24
|
+
authSessionInstanceStoragePath?: undefined;
|
|
25
|
+
authSessionInstanceMetadataPath?: undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare function getStorageState(context: playwright.BrowserContext): Promise<StorageState>;
|
|
28
|
+
export declare function recordAuthSession(startUrl: string, endUrl: string): Promise<StorageState>;
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ensureAuthApi = ensureAuthApi;
|
|
7
|
+
exports.ensureRecorderURLs = ensureRecorderURLs;
|
|
8
|
+
exports.getAuthType = getAuthType;
|
|
9
|
+
exports.getStorageState = getStorageState;
|
|
10
|
+
exports.isAuthEnabled = isAuthEnabled;
|
|
11
|
+
exports.recordAuthSession = recordAuthSession;
|
|
12
|
+
exports.retrieveAuthSessionInstance = retrieveAuthSessionInstance;
|
|
13
|
+
exports.runCheckApi = runCheckApi;
|
|
14
|
+
exports.runCheckApiViaCLI = runCheckApiViaCLI;
|
|
15
|
+
exports.runCreateApi = runCreateApi;
|
|
16
|
+
exports.runCreateApiViaCLI = runCreateApiViaCLI;
|
|
17
|
+
exports.storeAuthSessionInstance = storeAuthSessionInstance;
|
|
18
|
+
var _path = _interopRequireDefault(require("path"));
|
|
19
|
+
var _constants = require("../../common/constants");
|
|
20
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
21
|
+
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
22
|
+
var _enums = require("../../runtime/enums");
|
|
23
|
+
var _nanoid = require("nanoid");
|
|
24
|
+
var _runApi = require("../../common/runApi");
|
|
25
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
26
|
+
var _promptly = require("promptly");
|
|
27
|
+
var _utils = require("../../common/cli/utils");
|
|
28
|
+
var _types = require("../../common/cli/types");
|
|
29
|
+
var playwright = _interopRequireWildcard(require("playwright-core"));
|
|
30
|
+
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); }
|
|
31
|
+
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; }
|
|
32
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
33
|
+
async function isAuthEnabled() {
|
|
34
|
+
try {
|
|
35
|
+
var _intunedJson$authSess;
|
|
36
|
+
const intunedJson = await fs.readJSON(_path.default.join(process.cwd(), "Intuned.json"));
|
|
37
|
+
return Boolean(intunedJson === null || intunedJson === void 0 || (_intunedJson$authSess = intunedJson.authSessions) === null || _intunedJson$authSess === void 0 ? void 0 : _intunedJson$authSess.enabled);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function getAuthType() {
|
|
43
|
+
const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
|
|
44
|
+
return projectAuthConfig.type ?? "API";
|
|
45
|
+
}
|
|
46
|
+
async function ensureRecorderURLs() {
|
|
47
|
+
const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
|
|
48
|
+
if (projectAuthConfig.type === "MANUAL" && projectAuthConfig.startUrl && projectAuthConfig.endUrl) {
|
|
49
|
+
return {
|
|
50
|
+
startUrl: projectAuthConfig.startUrl,
|
|
51
|
+
endUrl: projectAuthConfig.endUrl
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
throw new Error("Auth session recorder URLs are not configured, please configure them in Intuned.json");
|
|
55
|
+
}
|
|
56
|
+
async function ensureAuthApi(operation) {
|
|
57
|
+
const authApiFile = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/${operation}.ts`;
|
|
58
|
+
const authApiFilePath = _path.default.join(process.cwd(), authApiFile);
|
|
59
|
+
return await fs.exists(authApiFilePath);
|
|
60
|
+
}
|
|
61
|
+
async function runCreateApi(authSessionInput) {
|
|
62
|
+
try {
|
|
63
|
+
const createApiOperationId = (0, _nanoid.nanoid)();
|
|
64
|
+
const authSessionInstance = await (0, _asyncLocalStorage.runWithContext)({
|
|
65
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
66
|
+
extendedPayloads: [],
|
|
67
|
+
runId: createApiOperationId
|
|
68
|
+
}, () => runCreateApiViaCLI(authSessionInput));
|
|
69
|
+
return authSessionInstance;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw new Error(`Error running the create API: ${error.message}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function runCheckApi(authSessionPath) {
|
|
75
|
+
try {
|
|
76
|
+
const checkApiOperationId = (0, _nanoid.nanoid)();
|
|
77
|
+
const checkResult = await (0, _asyncLocalStorage.runWithContext)({
|
|
78
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
79
|
+
extendedPayloads: [],
|
|
80
|
+
runId: checkApiOperationId
|
|
81
|
+
}, () => runCheckApiViaCLI(authSessionPath));
|
|
82
|
+
return checkResult;
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (error.message === _types.CHECK_FAILED_ERROR_MESSAGE) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
throw new Error(`Error running the check API: ${error.message}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function runCreateApiViaCLI(authSessionInput) {
|
|
91
|
+
const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
|
|
92
|
+
const generator = (0, _runApi.runApiGenerator)({
|
|
93
|
+
automationFunction: {
|
|
94
|
+
name: createApiName,
|
|
95
|
+
params: authSessionInput
|
|
96
|
+
},
|
|
97
|
+
runOptions: {
|
|
98
|
+
headless: false,
|
|
99
|
+
environment: "standalone"
|
|
100
|
+
},
|
|
101
|
+
retrieveSession: true,
|
|
102
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
103
|
+
});
|
|
104
|
+
let nextGeneratorParam = undefined;
|
|
105
|
+
while (true) {
|
|
106
|
+
const {
|
|
107
|
+
value,
|
|
108
|
+
done
|
|
109
|
+
} = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
|
|
110
|
+
if (done) {
|
|
111
|
+
if (value.isErr()) {
|
|
112
|
+
if (value.error instanceof _runApi.AutomationError) {
|
|
113
|
+
throw value.error.error;
|
|
114
|
+
}
|
|
115
|
+
console.error(value.error);
|
|
116
|
+
throw new Error("Error while running create");
|
|
117
|
+
}
|
|
118
|
+
return value.value.session;
|
|
119
|
+
}
|
|
120
|
+
if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
|
|
121
|
+
nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
|
|
122
|
+
validator: input => {
|
|
123
|
+
if (!value.choices.includes(input)) {
|
|
124
|
+
throw new Error("Please type on of the allowed choices");
|
|
125
|
+
}
|
|
126
|
+
return input;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
} else if (value.action === "request_more_info" && value.requestType == "otp") {
|
|
130
|
+
nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
async function runCheckApiViaCLI(authSessionPath) {
|
|
135
|
+
const runApiResult = await (0, _runApi.runApi)({
|
|
136
|
+
automationFunction: {
|
|
137
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
138
|
+
},
|
|
139
|
+
runOptions: {
|
|
140
|
+
headless: false,
|
|
141
|
+
environment: "standalone"
|
|
142
|
+
},
|
|
143
|
+
auth: {
|
|
144
|
+
session: {
|
|
145
|
+
type: "file",
|
|
146
|
+
path: authSessionPath
|
|
147
|
+
},
|
|
148
|
+
runCheck: false
|
|
149
|
+
},
|
|
150
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
151
|
+
});
|
|
152
|
+
if (runApiResult.isErr()) {
|
|
153
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
154
|
+
throw runApiResult.error.error;
|
|
155
|
+
}
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
const result = runApiResult.value.result;
|
|
159
|
+
if (!result) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
async function storeAuthSessionInstance(authSessionInstance, customName, authSessionInput) {
|
|
165
|
+
try {
|
|
166
|
+
const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
|
|
167
|
+
await fs.ensureDir(authSessionsDirectoryPath);
|
|
168
|
+
const authSessionInstanceId = customName ?? `auth-session-${Date.now()}`;
|
|
169
|
+
const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
|
|
170
|
+
const authSessionExists = await fs.pathExists(authSessionInstancePath);
|
|
171
|
+
await fs.ensureDir(authSessionInstancePath);
|
|
172
|
+
const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
|
|
173
|
+
await fs.writeJSON(authSessionInstanceStoragePath, authSessionInstance, {
|
|
174
|
+
spaces: 2
|
|
175
|
+
});
|
|
176
|
+
const projectAuthConfig = await (0, _utils.getSettingIntunedJSON)("authSessions");
|
|
177
|
+
let existingMetadata = {};
|
|
178
|
+
const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
|
|
179
|
+
if (authSessionExists) {
|
|
180
|
+
try {
|
|
181
|
+
existingMetadata = await fs.readJSON(authSessionInstanceMetadataPath);
|
|
182
|
+
} catch (readError) {
|
|
183
|
+
existingMetadata = {};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const authSessionMetadata = {
|
|
187
|
+
createdAt: existingMetadata.createdAt || new Date().toISOString(),
|
|
188
|
+
updatedAt: new Date().toISOString(),
|
|
189
|
+
...(projectAuthConfig.type === "API" && {
|
|
190
|
+
authSessionInput: authSessionInput || existingMetadata.authSessionInput || {}
|
|
191
|
+
}),
|
|
192
|
+
authSessionId: authSessionInstanceId,
|
|
193
|
+
authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
|
|
194
|
+
...(projectAuthConfig.type === "MANUAL" && {
|
|
195
|
+
recorderStartUrl: projectAuthConfig.startUrl,
|
|
196
|
+
recorderEndUrl: projectAuthConfig.endUrl
|
|
197
|
+
})
|
|
198
|
+
};
|
|
199
|
+
await fs.writeJSON(authSessionInstanceMetadataPath, authSessionMetadata, {
|
|
200
|
+
spaces: 2
|
|
201
|
+
});
|
|
202
|
+
return authSessionInstancePath;
|
|
203
|
+
} catch (error) {
|
|
204
|
+
throw new Error(`Error storing auth session instance: ${error.message}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
async function retrieveAuthSessionInstance(authSessionId, pathsOnly = false) {
|
|
208
|
+
try {
|
|
209
|
+
const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
|
|
210
|
+
const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
|
|
211
|
+
const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
|
|
212
|
+
if (!(await fs.exists(authSessionInstanceStoragePath))) {
|
|
213
|
+
throw new Error(`Auth session instance with ID ${authSessionId} not found`);
|
|
214
|
+
}
|
|
215
|
+
if (pathsOnly) {
|
|
216
|
+
return {
|
|
217
|
+
authSessionInstanceStoragePath,
|
|
218
|
+
authSessionInstanceMetadataPath
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
const authSessionInstance = await fs.readJSON(authSessionInstanceStoragePath);
|
|
222
|
+
const metadata = await fs.readJSON(authSessionInstanceMetadataPath);
|
|
223
|
+
return {
|
|
224
|
+
authSessionInstance,
|
|
225
|
+
metadata
|
|
226
|
+
};
|
|
227
|
+
} catch (error) {
|
|
228
|
+
throw new Error(`Error retrieving auth session instance: ${error.message}`);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
async function getStorageState(context) {
|
|
232
|
+
const result = {};
|
|
233
|
+
const storageState = await context.storageState();
|
|
234
|
+
result.cookies = storageState.cookies;
|
|
235
|
+
result.origins = storageState.origins;
|
|
236
|
+
const sessionDataList = [];
|
|
237
|
+
const pages = context.pages();
|
|
238
|
+
for (const page of pages) {
|
|
239
|
+
if (page.isClosed()) continue;
|
|
240
|
+
try {
|
|
241
|
+
const sessionData = await page.evaluate(() => {
|
|
242
|
+
const items = {
|
|
243
|
+
...window.sessionStorage
|
|
244
|
+
};
|
|
245
|
+
return {
|
|
246
|
+
origin: window.location.origin,
|
|
247
|
+
sessionStorage: Object.entries(items).map(([name, value]) => ({
|
|
248
|
+
name,
|
|
249
|
+
value
|
|
250
|
+
}))
|
|
251
|
+
};
|
|
252
|
+
});
|
|
253
|
+
sessionDataList.push(sessionData);
|
|
254
|
+
} catch (error) {
|
|
255
|
+
console.error("Error getting sessionStorage:", error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
result.sessionStorage = sessionDataList;
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
async function recordAuthSession(startUrl, endUrl) {
|
|
262
|
+
let browser;
|
|
263
|
+
try {
|
|
264
|
+
browser = await playwright.chromium.launch({
|
|
265
|
+
headless: false,
|
|
266
|
+
args: ["--start-maximized", "--no-sandbox"]
|
|
267
|
+
});
|
|
268
|
+
const context = await browser.newContext({
|
|
269
|
+
viewport: null
|
|
270
|
+
});
|
|
271
|
+
const page = await context.newPage();
|
|
272
|
+
await page.goto(startUrl);
|
|
273
|
+
await page.waitForURL(url => url.toString().startsWith(endUrl), {
|
|
274
|
+
timeout: 300000
|
|
275
|
+
});
|
|
276
|
+
const storageState = await getStorageState(context);
|
|
277
|
+
return storageState;
|
|
278
|
+
} catch (error) {
|
|
279
|
+
throw new Error(`Authentication recording failed: ${error.message}`);
|
|
280
|
+
} finally {
|
|
281
|
+
if (browser) {
|
|
282
|
+
await browser.close();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
var _commander = require("commander");
|
|
5
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
6
|
+
var _utils = require("../deploy/utils");
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
_dotenv.default.config({
|
|
9
|
+
path: `.env`
|
|
10
|
+
});
|
|
11
|
+
_commander.program.name("intuned-build-project").description("Build your current Intuned project").action(async () => {
|
|
12
|
+
try {
|
|
13
|
+
await (0, _utils.runBuild)();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
process.exit(1);
|
|
16
|
+
} finally {
|
|
17
|
+
process.exit(0);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
_commander.program.parse(process.argv);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const exclusions = ["node_modules/**", ".git/**", "dist/**", "build/**", "coverage/**", ".next/**", ".cache/**", "out/**", "tmp/**", ".DS_Store", "npm-debug.log*", "yarn-debug.log*", "yarn-error.log*", ".env", ".env.*", "**/*.map", "**/*.tsbuildinfo", "tsconfig.json", "output/**", "auth-sessions-instances/**", "README.md"];
|
|
8
|
+
var _default = exports.default = exclusions;
|