@intuned/runtime-dev 1.0.6-cli-auth.0.0.10-test → 1.0.6-cli-auth.0.0.11-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.
|
@@ -2,25 +2,17 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _commander = require("commander");
|
|
5
|
-
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
6
5
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
7
|
-
var _path = _interopRequireDefault(require("path"));
|
|
8
6
|
var _utils = require("./utils");
|
|
9
7
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
10
8
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
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); }
|
|
12
|
-
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; }
|
|
13
9
|
_dotenv.default.config({
|
|
14
10
|
path: `.env`
|
|
15
11
|
});
|
|
16
|
-
_commander.program.description("Check an auth session, if it is still valid or not").option("-a, --auth-session <session>", "Name of the auth session instance to use").action(async options => {
|
|
12
|
+
_commander.program.description("Check an auth session, if it is still valid or not").option("-a, --auth-session <session>", "Name/id of the auth session instance to use").action(async options => {
|
|
17
13
|
try {
|
|
18
14
|
if (!options.authSession) {
|
|
19
|
-
throw new Error("Auth session
|
|
20
|
-
}
|
|
21
|
-
const authSessionInstancePath = _path.default.resolve(process.cwd(), options.authSession);
|
|
22
|
-
if (!(await fs.exists(authSessionInstancePath))) {
|
|
23
|
-
throw new Error(`Auth session file not found at ${authSessionInstancePath}, please provide a valid path`);
|
|
15
|
+
throw new Error("Auth session instance is required, provide an ID/name for it");
|
|
24
16
|
}
|
|
25
17
|
const _isAuthEnabled = await (0, _utils.isAuthEnabled)();
|
|
26
18
|
if (!_isAuthEnabled) {
|
|
@@ -30,14 +22,17 @@ _commander.program.description("Check an auth session, if it is still valid or n
|
|
|
30
22
|
if (!checkApiExists) {
|
|
31
23
|
throw new Error("Auth check creation API not implemented, please create it in the auth sessions specified directory");
|
|
32
24
|
}
|
|
33
|
-
const
|
|
25
|
+
const {
|
|
26
|
+
authSessionInstanceStoragePath
|
|
27
|
+
} = await (0, _utils.retrieveAuthSessionInstance)(options.authSession, true);
|
|
28
|
+
const checkResult = await (0, _utils.runCheckApi)(authSessionInstanceStoragePath);
|
|
34
29
|
if (checkResult) {
|
|
35
30
|
console.log(_chalk.default.green("✓ Auth session checked successfully"));
|
|
36
31
|
} else {
|
|
37
32
|
console.log(_chalk.default.red("✗ Auth session is not valid, check failed"));
|
|
38
33
|
}
|
|
39
34
|
} catch (error) {
|
|
40
|
-
console.error(_chalk.default.red(`Failed to
|
|
35
|
+
console.error(_chalk.default.red(`Failed to check auth session: ${error.message}`));
|
|
41
36
|
} finally {
|
|
42
37
|
process.exit(0);
|
|
43
38
|
}
|
|
@@ -6,4 +6,14 @@ export declare function runCheckApi(authSessionPath: string): Promise<boolean>;
|
|
|
6
6
|
export declare function runCreateApiViaCLI(authSessionInput: Record<string, any>): Promise<StorageState>;
|
|
7
7
|
export declare function runCheckApiViaCLI(authSessionPath: string): Promise<boolean>;
|
|
8
8
|
export declare function storeAuthSessionInstance(authSessionInstance: StorageState, customName?: string, authSessionInput?: Record<string, any>): Promise<string>;
|
|
9
|
-
export declare function retrieveAuthSessionInstance(): Promise<
|
|
9
|
+
export declare function retrieveAuthSessionInstance(authSessionId: string, pathsOnly?: boolean): Promise<{
|
|
10
|
+
authSessionInstanceStoragePath: string;
|
|
11
|
+
authSessionInstanceMetadataPath: string;
|
|
12
|
+
authSessionInstance?: undefined;
|
|
13
|
+
metadata?: undefined;
|
|
14
|
+
} | {
|
|
15
|
+
authSessionInstance: any;
|
|
16
|
+
metadata: any;
|
|
17
|
+
authSessionInstanceStoragePath?: undefined;
|
|
18
|
+
authSessionInstanceMetadataPath?: undefined;
|
|
19
|
+
}>;
|
|
@@ -174,4 +174,27 @@ async function storeAuthSessionInstance(authSessionInstance, customName, authSes
|
|
|
174
174
|
throw new Error(`Error storing auth session instance: ${error.message}`);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
async function retrieveAuthSessionInstance() {
|
|
177
|
+
async function retrieveAuthSessionInstance(authSessionId, pathsOnly = false) {
|
|
178
|
+
try {
|
|
179
|
+
const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
|
|
180
|
+
const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
|
|
181
|
+
const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
|
|
182
|
+
if (!(await fs.exists(authSessionInstanceStoragePath))) {
|
|
183
|
+
throw new Error(`Auth session instance with ID ${authSessionId} not found`);
|
|
184
|
+
}
|
|
185
|
+
if (pathsOnly) {
|
|
186
|
+
return {
|
|
187
|
+
authSessionInstanceStoragePath,
|
|
188
|
+
authSessionInstanceMetadataPath
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const authSessionInstance = await fs.readJSON(authSessionInstanceStoragePath);
|
|
192
|
+
const metadata = await fs.readJSON(authSessionInstanceMetadataPath);
|
|
193
|
+
return {
|
|
194
|
+
authSessionInstance,
|
|
195
|
+
metadata
|
|
196
|
+
};
|
|
197
|
+
} catch (error) {
|
|
198
|
+
throw new Error(`Error retrieving auth session instance: ${error.message}`);
|
|
199
|
+
}
|
|
200
|
+
}
|