@intuned/runtime-dev 1.2.0-cli.0 → 1.2.0-cli.10
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/attempt_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/build.command.js +1 -1
- package/dist/commands/intuned-cli/commands/deploy.command.js +3 -4
- package/dist/commands/intuned-cli/commands/init.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +1 -1
- package/dist/{common/cli/constants.d.ts → commands/intuned-cli/constants/index.d.ts} +2 -4
- package/dist/{common/cli/constants.js → commands/intuned-cli/constants/index.js} +22 -5
- package/dist/commands/intuned-cli/constants/readme.d.ts +1 -0
- package/dist/{common/cli/cliReadme.js → commands/intuned-cli/constants/readme.js} +13 -15
- 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 +40 -38
- package/dist/commands/intuned-cli/controller/authSession.d.ts +176 -10
- package/dist/commands/intuned-cli/controller/authSession.js +125 -125
- package/dist/commands/intuned-cli/controller/build.js +1 -1
- package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -1
- package/dist/commands/intuned-cli/controller/deploy.js +47 -32
- package/dist/commands/intuned-cli/controller/index.js +5 -4
- package/dist/commands/intuned-cli/controller/init.d.ts +1 -1
- package/dist/commands/intuned-cli/controller/init.js +12 -15
- 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/{common/cli/utils.d.ts → commands/intuned-cli/helpers/backend.d.ts} +0 -1
- 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 -20
- 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/{terminal.js → helpers/terminal.js} +3 -2
- 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/main.js +4 -1
- package/dist/{common/cli → commands/intuned-cli}/types.d.ts +1 -32
- package/dist/common/runApi/types.d.ts +140 -9
- package/dist/common/runApi/types.js +28 -27
- package/package.json +2 -7
- 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 -284
- 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/deploy/utils.js +0 -407
- 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 -175
- package/dist/commands/intuned-cli/commands/helpers.d.ts +0 -26
- package/dist/commands/intuned-cli/commands/helpers.js +0 -126
- package/dist/commands/intuned-cli/terminal.d.ts +0 -1
- 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 → commands/intuned-cli}/types.js +0 -0
|
@@ -8,14 +8,11 @@ exports.mountFiles = mountFiles;
|
|
|
8
8
|
exports.scaffoldProject = scaffoldProject;
|
|
9
9
|
exports.selectTemplate = selectTemplate;
|
|
10
10
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
11
|
-
var _types = require("
|
|
11
|
+
var _types = require("../types");
|
|
12
12
|
var _path = _interopRequireDefault(require("path"));
|
|
13
13
|
var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
|
|
14
|
-
var _constants = require("
|
|
15
|
-
var
|
|
16
|
-
var _utils = require("../../../common/cli/utils");
|
|
17
|
-
var _helpers = require("../commands/helpers");
|
|
18
|
-
var _terminal = require("../terminal");
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
var _helpers = require("../helpers");
|
|
19
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
20
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); }
|
|
21
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; }
|
|
@@ -61,10 +58,10 @@ async function selectTemplate(templateName) {
|
|
|
61
58
|
}
|
|
62
59
|
return templateName;
|
|
63
60
|
}
|
|
64
|
-
(0,
|
|
61
|
+
(0, _helpers.terminal)("^+Select a template (ESC to cancel):^:\n");
|
|
65
62
|
const {
|
|
66
63
|
promise: selectedCommandPromise
|
|
67
|
-
} =
|
|
64
|
+
} = _helpers.terminal.singleColumnMenu(_types.templateIds, {
|
|
68
65
|
cancelable: true
|
|
69
66
|
});
|
|
70
67
|
const selectedTemplateIndex = (await selectedCommandPromise).selectedIndex;
|
|
@@ -77,10 +74,10 @@ async function selectTemplate(templateName) {
|
|
|
77
74
|
}
|
|
78
75
|
async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
|
|
79
76
|
if (!isTargetDirectoryEmpty) {
|
|
80
|
-
(0,
|
|
77
|
+
(0, _helpers.terminal)("^+The current directory is not empty. Do you want to proceed and override files?^: (y/N)");
|
|
81
78
|
const {
|
|
82
79
|
promise
|
|
83
|
-
} =
|
|
80
|
+
} = _helpers.terminal.yesOrNo({
|
|
84
81
|
no: ["n", "ENTER", "ESCAPE"],
|
|
85
82
|
yes: ["y"],
|
|
86
83
|
echoNo: " no\n",
|
|
@@ -94,16 +91,16 @@ async function scaffoldProject(templateId, isTargetDirectoryEmpty) {
|
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
93
|
const cwd = process.cwd();
|
|
97
|
-
(0,
|
|
94
|
+
(0, _helpers.terminal)(`^c🚀 Initializing ^:^+${templateId}^:^c project...\n`);
|
|
98
95
|
const template = await fetchProjectTemplate(templateId);
|
|
99
|
-
(0,
|
|
96
|
+
(0, _helpers.terminal)(`^c🔨 Creating project files...^:\n`);
|
|
100
97
|
const codeTree = template;
|
|
101
98
|
await prepareCLITemplate(codeTree);
|
|
102
99
|
await mountFiles(cwd, codeTree);
|
|
103
|
-
(0,
|
|
100
|
+
(0, _helpers.terminal)(`^g^+🎉 Project initialized successfully!^ ^GRun ^:^+yarn^:^G to install dependencies and start coding!\n`);
|
|
104
101
|
}
|
|
105
102
|
async function fetchProjectTemplate(templateId) {
|
|
106
|
-
const baseUrl = (0,
|
|
103
|
+
const baseUrl = (0, _helpers.getBaseUrl)();
|
|
107
104
|
const url = `${baseUrl}/api/templates/${templateId}`;
|
|
108
105
|
const response = await fetch(url);
|
|
109
106
|
if (!response.ok) {
|
|
@@ -133,7 +130,7 @@ async function prepareCLITemplate(codeTree) {
|
|
|
133
130
|
}
|
|
134
131
|
codeTree["README.md"] = {
|
|
135
132
|
file: {
|
|
136
|
-
contents:
|
|
133
|
+
contents: _constants.readme
|
|
137
134
|
}
|
|
138
135
|
};
|
|
139
136
|
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
|
|
2
|
+
export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
|
|
3
|
+
export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assertApiFileExists = assertApiFileExists;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _fsExtra = require("fs-extra");
|
|
9
|
+
var _errors = require("./errors");
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
async function assertApiFileExists(dirname, api) {
|
|
12
|
+
const file = `${dirname}/${api}.ts`;
|
|
13
|
+
const filePath = _path.default.join(process.cwd(), file);
|
|
14
|
+
if (!(await (0, _fsExtra.exists)(filePath))) {
|
|
15
|
+
throw new _errors.CLIAssertionError(`^+^r API^ ^+${dirname}/${api}^ ^r^+is not implemented.^:`, {
|
|
16
|
+
autoColor: false
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AuthSessionMetadata } from "../types";
|
|
2
|
+
import { RunApiStorageState as StorageState } from "../../../common/runApi";
|
|
3
|
+
export declare function isAuthEnabled(): Promise<boolean>;
|
|
4
|
+
export declare function assertAuthEnabled(): Promise<void>;
|
|
5
|
+
export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
|
|
6
|
+
export declare function loadAuthSessionInstance(authSessionId: string): Promise<{
|
|
7
|
+
storageState: {
|
|
8
|
+
cookies: {
|
|
9
|
+
value: string;
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
domain: string;
|
|
13
|
+
expires: number;
|
|
14
|
+
httpOnly: boolean;
|
|
15
|
+
secure: boolean;
|
|
16
|
+
sameSite: "Strict" | "Lax" | "None";
|
|
17
|
+
}[];
|
|
18
|
+
origins: {
|
|
19
|
+
origin: string;
|
|
20
|
+
localStorage: {
|
|
21
|
+
value: string;
|
|
22
|
+
name: string;
|
|
23
|
+
}[];
|
|
24
|
+
}[];
|
|
25
|
+
sessionStorage?: {
|
|
26
|
+
sessionStorage: {
|
|
27
|
+
value: string;
|
|
28
|
+
name: string;
|
|
29
|
+
}[];
|
|
30
|
+
origin: string;
|
|
31
|
+
}[] | undefined;
|
|
32
|
+
};
|
|
33
|
+
metadata: AuthSessionMetadata;
|
|
34
|
+
}>;
|
|
35
|
+
export declare function storeAuthSessionInstance({ state, id, input, proxy, }: {
|
|
36
|
+
state: StorageState;
|
|
37
|
+
id?: string;
|
|
38
|
+
input?: Record<string, any>;
|
|
39
|
+
proxy?: string;
|
|
40
|
+
}): Promise<string>;
|
|
41
|
+
export declare function registerGetAuthSessionParameters(authSessionId?: string): void;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.assertAuthConsistent = assertAuthConsistent;
|
|
7
|
+
exports.assertAuthEnabled = assertAuthEnabled;
|
|
8
|
+
exports.isAuthEnabled = isAuthEnabled;
|
|
9
|
+
exports.loadAuthSessionInstance = loadAuthSessionInstance;
|
|
10
|
+
exports.registerGetAuthSessionParameters = registerGetAuthSessionParameters;
|
|
11
|
+
exports.storeAuthSessionInstance = storeAuthSessionInstance;
|
|
12
|
+
var _constants = require("../../../common/constants");
|
|
13
|
+
var _path = _interopRequireDefault(require("path"));
|
|
14
|
+
var _fsExtra = require("fs-extra");
|
|
15
|
+
var _intunedJson = require("./intunedJson");
|
|
16
|
+
var _errors = require("./errors");
|
|
17
|
+
var _runApi = require("../../../common/runApi");
|
|
18
|
+
var _formatZodError = require("../../../common/formatZodError");
|
|
19
|
+
var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
|
|
20
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
+
async function isAuthEnabled() {
|
|
22
|
+
try {
|
|
23
|
+
const intunedJson = await (0, _fsExtra.readJSON)(_path.default.join(process.cwd(), "Intuned.json"));
|
|
24
|
+
return Boolean(intunedJson?.authSessions?.enabled);
|
|
25
|
+
} catch (error) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function assertAuthEnabled() {
|
|
30
|
+
if (!(await isAuthEnabled())) {
|
|
31
|
+
throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function assertAuthConsistent(authSession) {
|
|
35
|
+
const _isAuthEnabled = await isAuthEnabled();
|
|
36
|
+
if (_isAuthEnabled && !authSession) {
|
|
37
|
+
throw new _errors.CLIAssertionError("Auth session is enabled, but no auth session is provided. Please provide an auth session ID.");
|
|
38
|
+
}
|
|
39
|
+
if (!_isAuthEnabled && authSession) {
|
|
40
|
+
throw new _errors.CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async function loadAuthSessionInstance(authSessionId) {
|
|
44
|
+
try {
|
|
45
|
+
const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
|
|
46
|
+
const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
|
|
47
|
+
const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
|
|
48
|
+
if (!(await (0, _fsExtra.exists)(authSessionInstanceStoragePath))) {
|
|
49
|
+
throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} not found`);
|
|
50
|
+
}
|
|
51
|
+
const authSessionInstanceJson = await (0, _fsExtra.readJSON)(authSessionInstanceStoragePath);
|
|
52
|
+
const authSessionInstanceParseResult = _runApi.runApiStorageStateSchema.safeParse(authSessionInstanceJson);
|
|
53
|
+
if (!authSessionInstanceParseResult.success) {
|
|
54
|
+
throw new _errors.CLIError(`Auth session instance with ID ${authSessionId} is not valid: ${(0, _formatZodError.formatZodError)(authSessionInstanceParseResult.error)}`);
|
|
55
|
+
}
|
|
56
|
+
const metadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
|
|
57
|
+
return {
|
|
58
|
+
storageState: authSessionInstanceParseResult.data,
|
|
59
|
+
metadata
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
throw new _errors.CLIError(`Error retrieving auth session instance: ${error.message}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function storeAuthSessionInstance({
|
|
66
|
+
state,
|
|
67
|
+
id,
|
|
68
|
+
input,
|
|
69
|
+
proxy
|
|
70
|
+
}) {
|
|
71
|
+
try {
|
|
72
|
+
const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
|
|
73
|
+
await (0, _fsExtra.ensureDir)(authSessionsDirectoryPath);
|
|
74
|
+
const authSessionInstanceId = id ?? `auth-session-${Date.now()}`;
|
|
75
|
+
const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, authSessionInstanceId);
|
|
76
|
+
const authSessionExists = await (0, _fsExtra.pathExists)(authSessionInstancePath);
|
|
77
|
+
await (0, _fsExtra.ensureDir)(authSessionInstancePath);
|
|
78
|
+
const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
|
|
79
|
+
await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, state, {
|
|
80
|
+
spaces: 2
|
|
81
|
+
});
|
|
82
|
+
const projectAuthConfig = await (0, _intunedJson.getSettingIntunedJSON)("authSessions");
|
|
83
|
+
let existingMetadata = {};
|
|
84
|
+
const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
|
|
85
|
+
if (authSessionExists) {
|
|
86
|
+
try {
|
|
87
|
+
existingMetadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
|
|
88
|
+
} catch (readError) {
|
|
89
|
+
existingMetadata = {};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const authSessionMetadata = {
|
|
93
|
+
createdAt: existingMetadata.createdAt || new Date().toISOString(),
|
|
94
|
+
updatedAt: new Date().toISOString(),
|
|
95
|
+
...(projectAuthConfig.type === "API" && {
|
|
96
|
+
authSessionInput: input || existingMetadata.authSessionInput || {}
|
|
97
|
+
}),
|
|
98
|
+
authSessionId: authSessionInstanceId,
|
|
99
|
+
authSessionType: projectAuthConfig.type ?? existingMetadata.authSessionType ?? "API",
|
|
100
|
+
...(projectAuthConfig.type === "MANUAL" && {
|
|
101
|
+
recorderStartUrl: projectAuthConfig.startUrl,
|
|
102
|
+
recorderEndUrl: projectAuthConfig.endUrl
|
|
103
|
+
}),
|
|
104
|
+
authSessionInput: input || existingMetadata.authSessionInput || {},
|
|
105
|
+
authSessionProxy: proxy || existingMetadata.authSessionProxy
|
|
106
|
+
};
|
|
107
|
+
await (0, _fsExtra.writeJSON)(authSessionInstanceMetadataPath, authSessionMetadata, {
|
|
108
|
+
spaces: 2
|
|
109
|
+
});
|
|
110
|
+
return authSessionInstancePath;
|
|
111
|
+
} catch (error) {
|
|
112
|
+
throw new _errors.CLIError(`Error storing auth session instance: ${error.message}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function registerGetAuthSessionParameters(authSessionId) {
|
|
116
|
+
async function getAuthSessionParameters() {
|
|
117
|
+
if (!authSessionId) {
|
|
118
|
+
throw new Error("getAuthSessionParameters cannot be called without using an auth session");
|
|
119
|
+
}
|
|
120
|
+
const {
|
|
121
|
+
metadata
|
|
122
|
+
} = await loadAuthSessionInstance(authSessionId);
|
|
123
|
+
if (metadata?.authSessionType === "MANUAL") {
|
|
124
|
+
throw new Error("Auth session is recorder-based, it does not have parameters.");
|
|
125
|
+
}
|
|
126
|
+
return metadata?.authSessionInput ?? {};
|
|
127
|
+
}
|
|
128
|
+
(0, _asyncLocalStorage.getExecutionContext)().getAuthSessionParameters = getAuthSessionParameters;
|
|
129
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getAuthCredentials = getAuthCredentials;
|
|
7
|
+
exports.getBaseUrl = getBaseUrl;
|
|
8
|
+
var _errors = require("./errors");
|
|
9
|
+
var _intunedJson = require("./intunedJson");
|
|
10
|
+
async function getAuthCredentials(options) {
|
|
11
|
+
const workspaceId = options.workspaceId || (await (0, _intunedJson.getSettingIntunedJSON)("workspaceId"));
|
|
12
|
+
const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
|
|
13
|
+
if (!workspaceId) {
|
|
14
|
+
throw new _errors.CLIError("Workspace ID is required. Please provide it via command line options or Intuned.json");
|
|
15
|
+
}
|
|
16
|
+
if (!apiKey) {
|
|
17
|
+
throw new _errors.CLIError("API key is required. Please provide it via command line options or INTUNED_API_KEY environment variable.");
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
workspaceId,
|
|
21
|
+
apiKey
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getBaseUrl() {
|
|
25
|
+
return process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`;
|
|
26
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withCLIContext = withCLIContext;
|
|
7
|
+
var _nanoid = require("nanoid");
|
|
8
|
+
var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
|
|
9
|
+
var _enums = require("../../../runtime/enums");
|
|
10
|
+
var _auth = require("./auth");
|
|
11
|
+
async function withCLIContext(fn, options) {
|
|
12
|
+
const runId = (0, _nanoid.nanoid)();
|
|
13
|
+
async function getAuthSessionParameters() {
|
|
14
|
+
const id = options?.authSessionId;
|
|
15
|
+
if (!id) {
|
|
16
|
+
throw new Error("getAuthSessionParameters cannot be called without using an auth session");
|
|
17
|
+
}
|
|
18
|
+
const {
|
|
19
|
+
metadata
|
|
20
|
+
} = await (0, _auth.loadAuthSessionInstance)(id);
|
|
21
|
+
if (metadata?.authSessionType === "MANUAL") {
|
|
22
|
+
throw new Error("Auth session is recorder-based, it does not have parameters.");
|
|
23
|
+
}
|
|
24
|
+
return metadata?.authSessionInput ?? {};
|
|
25
|
+
}
|
|
26
|
+
return await (0, _asyncLocalStorage.runWithContext)({
|
|
27
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
28
|
+
runId,
|
|
29
|
+
extendedPayloads: [],
|
|
30
|
+
timeoutInfo: {},
|
|
31
|
+
getAuthSessionParameters
|
|
32
|
+
}, fn);
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AutomationError } from "../../../common/runApi";
|
|
2
|
+
export declare class CLIError extends Error {
|
|
3
|
+
autoColor: boolean;
|
|
4
|
+
constructor(message: string, options?: {
|
|
5
|
+
autoColor?: boolean;
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
export declare class CLIAssertionError extends CLIError {
|
|
9
|
+
constructor(message: string, options?: {
|
|
10
|
+
autoColor?: boolean;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
export declare function logAutomationError(error: AutomationError): void;
|
|
14
|
+
export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CLIError = exports.CLIAssertionError = void 0;
|
|
7
|
+
exports.logAutomationError = logAutomationError;
|
|
8
|
+
exports.withErrorLogging = withErrorLogging;
|
|
9
|
+
var _runApi = require("../../../common/runApi");
|
|
10
|
+
var _terminal = require("./terminal");
|
|
11
|
+
class CLIError extends Error {
|
|
12
|
+
constructor(message, options) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "CLIError";
|
|
15
|
+
this.autoColor = options?.autoColor ?? true;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CLIError = CLIError;
|
|
19
|
+
class CLIAssertionError extends CLIError {
|
|
20
|
+
constructor(message, options) {
|
|
21
|
+
super(message, options);
|
|
22
|
+
this.name = "CLIAssertionError";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CLIAssertionError = CLIAssertionError;
|
|
26
|
+
function logAutomationError(error) {
|
|
27
|
+
(0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
|
|
28
|
+
if (error.error.stack) {
|
|
29
|
+
const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime") && !line.includes("node:"));
|
|
30
|
+
(0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
|
|
31
|
+
} else {
|
|
32
|
+
(0, _terminal.terminal)(`^r${error.error.message}^:\n`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function withErrorLogging(fn) {
|
|
36
|
+
return async (...args) => {
|
|
37
|
+
try {
|
|
38
|
+
await fn(...args);
|
|
39
|
+
process.exit(0);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
if (error instanceof CLIError) {
|
|
42
|
+
if (error.autoColor) {
|
|
43
|
+
(0, _terminal.terminal)(`^r^+${error.message}^:\n`);
|
|
44
|
+
} else {
|
|
45
|
+
(0, _terminal.terminal)(`${error.message}\n`);
|
|
46
|
+
}
|
|
47
|
+
} else if (error instanceof _runApi.AutomationError) {
|
|
48
|
+
logAutomationError(error);
|
|
49
|
+
} else {
|
|
50
|
+
(0, _terminal.terminal)(`^r^+An error occurred:^: ^R${error.message}^:\n^r^+Please report this issue to the Intuned team.^:\n`);
|
|
51
|
+
}
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./api";
|
|
2
|
+
export * from "./auth";
|
|
3
|
+
export * from "./context";
|
|
4
|
+
export * from "./errors";
|
|
5
|
+
export * from "./proxy";
|
|
6
|
+
export * from "./terminal";
|
|
7
|
+
export * from "./timeout";
|
|
8
|
+
export * from "./validation";
|
|
9
|
+
export * from "./intunedJson";
|
|
10
|
+
export * from "./backend";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _api = require("./api");
|
|
7
|
+
Object.keys(_api).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _api[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _api[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _auth = require("./auth");
|
|
18
|
+
Object.keys(_auth).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _auth[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _auth[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _context = require("./context");
|
|
29
|
+
Object.keys(_context).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _context[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function () {
|
|
35
|
+
return _context[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
var _errors = require("./errors");
|
|
40
|
+
Object.keys(_errors).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _errors[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _errors[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _proxy = require("./proxy");
|
|
51
|
+
Object.keys(_proxy).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _proxy[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _proxy[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _terminal = require("./terminal");
|
|
62
|
+
Object.keys(_terminal).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _terminal[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _terminal[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _timeout = require("./timeout");
|
|
73
|
+
Object.keys(_timeout).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _timeout[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _timeout[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _validation = require("./validation");
|
|
84
|
+
Object.keys(_validation).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _validation[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function () {
|
|
90
|
+
return _validation[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _intunedJson = require("./intunedJson");
|
|
95
|
+
Object.keys(_intunedJson).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _intunedJson[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function () {
|
|
101
|
+
return _intunedJson[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
var _backend = require("./backend");
|
|
106
|
+
Object.keys(_backend).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _backend[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _backend[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getSettingIntunedJSON(key: string): Promise<any>;
|
|
@@ -3,32 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getAuthCredentials = getAuthCredentials;
|
|
7
|
-
exports.getBaseUrl = getBaseUrl;
|
|
8
6
|
exports.getSettingIntunedJSON = getSettingIntunedJSON;
|
|
9
7
|
var _path = _interopRequireDefault(require("path"));
|
|
10
8
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
11
|
-
var _helpers = require("../../commands/intuned-cli/commands/helpers");
|
|
12
9
|
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); }
|
|
13
10
|
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; }
|
|
14
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
async function getAuthCredentials(options) {
|
|
16
|
-
const workspaceId = options.workspaceId || (await getSettingIntunedJSON("workspaceId"));
|
|
17
|
-
const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
|
|
18
|
-
if (!workspaceId) {
|
|
19
|
-
throw new _helpers.CLIError("Workspace ID is required. Please provide it via command line options or Intuned.json");
|
|
20
|
-
}
|
|
21
|
-
if (!apiKey) {
|
|
22
|
-
throw new _helpers.CLIError("API key is required. Please provide it via command line options or INTUNED_API_KEY environment variable.");
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
workspaceId,
|
|
26
|
-
apiKey
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function getBaseUrl() {
|
|
30
|
-
return process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`;
|
|
31
|
-
}
|
|
32
12
|
async function getSettingIntunedJSON(key) {
|
|
33
13
|
const intunedJsonPath = _path.default.join(process.cwd(), "Intuned.json");
|
|
34
14
|
const intunedJson = await fs.readJSON(intunedJsonPath);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseUrlProxy = parseUrlProxy;
|
|
7
|
+
function parseUrlProxy(proxyUrl) {
|
|
8
|
+
try {
|
|
9
|
+
const url = new URL(proxyUrl);
|
|
10
|
+
const username = url.username;
|
|
11
|
+
const password = url.password;
|
|
12
|
+
const proxy = url.hostname;
|
|
13
|
+
const port = url.port ? `:${url.port}` : "";
|
|
14
|
+
const domain = `${url.protocol}//${proxy}${port}`;
|
|
15
|
+
return {
|
|
16
|
+
password,
|
|
17
|
+
username,
|
|
18
|
+
server: domain
|
|
19
|
+
};
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.terminal = void 0;
|
|
6
|
+
exports.terminalStdout = exports.terminal = void 0;
|
|
7
7
|
var _terminalKit = require("terminal-kit");
|
|
8
|
+
const terminalStdout = exports.terminalStdout = process.stderr;
|
|
8
9
|
const terminal = exports.terminal = (0, _terminalKit.createTerminal)({
|
|
9
10
|
appId: "Intuned CLI",
|
|
10
11
|
appName: "Intuned CLI",
|
|
11
|
-
stdout:
|
|
12
|
+
stdout: terminalStdout
|
|
12
13
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withTimeout<R>(fn: (abortSignal: AbortSignal) => Promise<R>, timeout: number): Promise<Awaited<R>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withTimeout = withTimeout;
|
|
7
|
+
var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
|
|
8
|
+
var _runApi = require("../../../common/runApi");
|
|
9
|
+
function withTimeout(fn, timeout) {
|
|
10
|
+
let reject;
|
|
11
|
+
const abortController = new AbortController();
|
|
12
|
+
const timeoutPromise = new Promise((_, _reject) => {
|
|
13
|
+
reject = _reject;
|
|
14
|
+
});
|
|
15
|
+
const timeoutId = setTimeout(() => {
|
|
16
|
+
abortController.abort();
|
|
17
|
+
reject(new _runApi.AutomationError(new Error("Timed out")));
|
|
18
|
+
}, timeout);
|
|
19
|
+
(0, _asyncLocalStorage.getExecutionContext)().timeoutInfo.extendTimeoutCallback = async () => {
|
|
20
|
+
timeoutId.refresh();
|
|
21
|
+
};
|
|
22
|
+
return Promise.race([fn(abortController.signal), timeoutPromise]);
|
|
23
|
+
}
|