@intuned/runtime-dev 1.0.6-cli-auth.0.0.2 → 1.0.6-cli-auth.0.0.4-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.
@@ -1,4 +1,3 @@
1
- import { StorageState } from "../../common/contextStorageStateHelpers";
2
1
  export declare function isAuthEnabled(): Promise<boolean>;
3
2
  export declare function ensureCreateApi(): Promise<boolean>;
4
- export declare function runCreateApi(authSessionInput: Record<string, any>): Promise<StorageState | null>;
3
+ export declare function runCreateApi(authSessionInput: Record<string, any>): Promise<any>;
@@ -9,11 +9,12 @@ exports.runCreateApi = runCreateApi;
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _constants = require("../../common/constants");
11
11
  var fs = _interopRequireWildcard(require("fs-extra"));
12
- var _utils = require("../run-api-cli/utils");
13
12
  var _asyncLocalStorage = require("../../common/asyncLocalStorage");
14
13
  var _enums = require("../../runtime/enums");
15
14
  var _nanoid = require("nanoid");
16
15
  var _runApi = require("../../common/runApi");
16
+ var _tsNodeImport = require("../common/tsNodeImport");
17
+ var _promptly = require("promptly");
17
18
  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); }
18
19
  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; }
19
20
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -33,23 +34,61 @@ async function ensureCreateApi() {
33
34
  }
34
35
  async function runCreateApi(authSessionInput) {
35
36
  try {
36
- const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
37
37
  const createApiRunId = (0, _nanoid.nanoid)();
38
- const runCreateResult = await (0, _asyncLocalStorage.runWithContext)({
38
+ const authSessionInstance = await (0, _asyncLocalStorage.runWithContext)({
39
39
  runEnvironment: _enums.RunEnvironment.IDE,
40
40
  extendedPayloads: [],
41
41
  runId: createApiRunId
42
- }, () => (0, _utils.runApiViaCLI)(createApiName, authSessionInput, {
43
- retrieveSession: true
44
- }));
45
- if (runCreateResult.result.isErr()) {
46
- throw new _runApi.AutomationError(runCreateResult.result.error);
47
- }
48
- if (!runCreateResult.session) {
49
- throw new Error(`Auth session not retrieved in the result. Please check the create API.`);
50
- }
51
- return runCreateResult.session;
42
+ }, () => runCreateApiViaCLI(authSessionInput));
43
+ return authSessionInstance;
52
44
  } catch (error) {
53
45
  throw new Error(`Error running the create API: ${error.message}`);
54
46
  }
47
+ }
48
+ async function runCreateApiViaCLI(authSessionInput) {
49
+ const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
50
+ const generator = (0, _runApi.runApiGenerator)({
51
+ automationFunction: {
52
+ name: createApiName,
53
+ params: authSessionInput
54
+ },
55
+ runOptions: {
56
+ headless: false,
57
+ environment: "standalone"
58
+ },
59
+ retrieveSession: true,
60
+ importFunction: _tsNodeImport.tsNodeImport
61
+ });
62
+ let session;
63
+ let nextGeneratorParam = undefined;
64
+ while (true) {
65
+ const {
66
+ value,
67
+ done
68
+ } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
69
+ if (done) {
70
+ if (value.isErr()) {
71
+ if (value.error instanceof _runApi.AutomationError) {
72
+ throw value.error.error;
73
+ }
74
+ console.error(value.error);
75
+ throw new Error("Error while running create");
76
+ }
77
+ session = value.value.session;
78
+ break;
79
+ }
80
+ if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
81
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
82
+ validator: input => {
83
+ if (!value.choices.includes(input)) {
84
+ throw new Error("Please type on of the allowed choices");
85
+ }
86
+ return input;
87
+ }
88
+ });
89
+ } else if (value.action === "request_more_info" && value.requestType == "otp") {
90
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
91
+ }
92
+ }
93
+ return session;
55
94
  }
@@ -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
  }
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.2",
3
+ "version": "1.0.6-cli-auth.0.0.4-test",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",