@intuned/runtime-dev 1.0.6-cli-auth.0.0.3-test → 1.0.6-cli-auth.0.0.5-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.
@@ -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,14 @@ _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
- console.log(_chalk.default.green("Auth session created successfully!"));
25
- console.log(_chalk.default.blue("Session details:"));
26
- console.log(_chalk.default.blue(JSON.stringify(session, null, 2)));
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
+ }
27
33
  });
28
34
  _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,13 +6,16 @@ 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"));
12
- var _utils = require("../run-api-cli/utils");
13
13
  var _asyncLocalStorage = require("../../common/asyncLocalStorage");
14
14
  var _enums = require("../../runtime/enums");
15
15
  var _nanoid = require("nanoid");
16
+ var _runApi = require("../../common/runApi");
17
+ var _tsNodeImport = require("../common/tsNodeImport");
18
+ var _promptly = require("promptly");
16
19
  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
20
  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
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -32,17 +35,75 @@ async function ensureCreateApi() {
32
35
  }
33
36
  async function runCreateApi(authSessionInput) {
34
37
  try {
35
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
36
38
  const createApiRunId = (0, _nanoid.nanoid)();
37
- const runCreateResult = await (0, _asyncLocalStorage.runWithContext)({
39
+ const authSessionInstance = await (0, _asyncLocalStorage.runWithContext)({
38
40
  runEnvironment: _enums.RunEnvironment.IDE,
39
41
  extendedPayloads: [],
40
42
  runId: createApiRunId
41
- }, () => (0, _utils.runApiViaCLI)(createApiName, authSessionInput, {
42
- retrieveSession: true
43
- }));
44
- return runCreateResult;
43
+ }, () => runCreateApiViaCLI(authSessionInput));
44
+ return authSessionInstance;
45
45
  } catch (error) {
46
46
  throw new Error(`Error running the create API: ${error.message}`);
47
47
  }
48
+ }
49
+ async function runCreateApiViaCLI(authSessionInput) {
50
+ const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
51
+ const generator = (0, _runApi.runApiGenerator)({
52
+ automationFunction: {
53
+ name: createApiName,
54
+ params: authSessionInput
55
+ },
56
+ runOptions: {
57
+ headless: false,
58
+ environment: "standalone"
59
+ },
60
+ retrieveSession: true,
61
+ importFunction: _tsNodeImport.tsNodeImport
62
+ });
63
+ let session;
64
+ let nextGeneratorParam = undefined;
65
+ while (true) {
66
+ const {
67
+ value,
68
+ done
69
+ } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
70
+ if (done) {
71
+ if (value.isErr()) {
72
+ if (value.error instanceof _runApi.AutomationError) {
73
+ throw value.error.error;
74
+ }
75
+ console.error(value.error);
76
+ throw new Error("Error while running create");
77
+ }
78
+ session = value.value.session;
79
+ break;
80
+ }
81
+ if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
82
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
83
+ validator: input => {
84
+ if (!value.choices.includes(input)) {
85
+ throw new Error("Please type on of the allowed choices");
86
+ }
87
+ return input;
88
+ }
89
+ });
90
+ } else if (value.action === "request_more_info" && value.requestType == "otp") {
91
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
92
+ }
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
+ }
48
109
  }
@@ -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, options?: {
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, options) {
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
  }
@@ -1 +1,2 @@
1
1
  export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
2
+ export declare const AUTH_SESSIONS_INSTANCES_FOLDER_NAME = "auth-sessions-instances";
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.0.6-cli-auth.0.0.3-test",
3
+ "version": "1.0.6-cli-auth.0.0.5-test",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",