@intuned/runtime 1.3.0 → 1.3.1

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.
Files changed (51) hide show
  1. package/WebTemplate.zip +0 -0
  2. package/dist/commands/api/run.js +5 -3
  3. package/dist/commands/auth-sessions/load.js +3 -3
  4. package/dist/commands/auth-sessions/run-check.js +1 -2
  5. package/dist/commands/auth-sessions/run-create.js +12 -35
  6. package/dist/commands/interface/run.d.ts +1 -1
  7. package/dist/commands/interface/run.js +14 -40
  8. package/dist/commands/intuned-cli/commands/deploy.command.js +6 -9
  9. package/dist/commands/intuned-cli/commands/index.d.ts +1 -0
  10. package/dist/commands/intuned-cli/commands/index.js +11 -0
  11. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +2 -1
  12. package/dist/commands/intuned-cli/commands/save.command.d.ts +12 -0
  13. package/dist/commands/intuned-cli/commands/save.command.js +46 -0
  14. package/dist/commands/intuned-cli/commands/types.d.ts +1 -1
  15. package/dist/commands/intuned-cli/controller/__test__/api.test.js +1 -2
  16. package/dist/commands/intuned-cli/controller/api.js +1 -2
  17. package/dist/commands/intuned-cli/controller/authSession.js +3 -4
  18. package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -12
  19. package/dist/commands/intuned-cli/controller/deploy.js +9 -284
  20. package/dist/commands/intuned-cli/controller/save.d.ts +14 -0
  21. package/dist/commands/intuned-cli/controller/save.js +364 -0
  22. package/dist/commands/intuned-cli/helpers/backend.js +4 -3
  23. package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
  24. package/dist/commands/intuned-cli/helpers/errors.js +8 -4
  25. package/dist/commands/intuned-cli/main.js +7 -0
  26. package/dist/common/asyncLocalStorage/index.d.ts +1 -0
  27. package/dist/common/constants.d.ts +6 -0
  28. package/dist/common/constants.js +8 -2
  29. package/dist/common/jwtTokenManager.d.ts +1 -0
  30. package/dist/common/jwtTokenManager.js +37 -7
  31. package/dist/common/playwrightContext.d.ts +54 -0
  32. package/dist/common/{getPlaywrightConstructs.js → playwrightContext.js} +148 -79
  33. package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
  34. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  35. package/dist/common/runApi/index.d.ts +2 -7
  36. package/dist/common/runApi/index.js +92 -178
  37. package/dist/common/runApi/types.d.ts +3 -7
  38. package/dist/common/runApi/types.js +1 -2
  39. package/dist/common/setupContextHook.d.ts +17 -0
  40. package/dist/common/setupContextHook.js +22 -0
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js +13 -19
  43. package/dist/runtime/attemptStore.d.ts +2 -0
  44. package/dist/runtime/attemptStore.js +23 -0
  45. package/dist/runtime/export.d.ts +51 -41
  46. package/dist/runtime/index.d.ts +1 -2
  47. package/dist/runtime/index.js +7 -13
  48. package/package.json +3 -1
  49. package/dist/common/getPlaywrightConstructs.d.ts +0 -30
  50. package/dist/runtime/requestMoreInfo.d.ts +0 -18
  51. package/dist/runtime/requestMoreInfo.js +0 -25
Binary file
@@ -48,8 +48,7 @@ async function executeCLI(apiName, mode, inputData, options) {
48
48
  session: {
49
49
  type: "file",
50
50
  path: authSessionPathToUse
51
- },
52
- runCheck: false
51
+ }
53
52
  } : undefined,
54
53
  runOptions: {
55
54
  environment: "cdp",
@@ -78,7 +77,10 @@ async function executeCLI(apiName, mode, inputData, options) {
78
77
  _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
79
78
  fs.ensureDirSync(resultsDir);
80
79
  const path = `${resultsDir}/${options.outputFileId}.json`;
81
- await fs.writeJson(path, result, {
80
+ await fs.writeJson(path, {
81
+ input: inputData,
82
+ output: result
83
+ }, {
82
84
  spaces: 2
83
85
  });
84
86
  } else {
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  var _commander = require("commander");
5
- var _getPlaywrightConstructs = require("../../common/getPlaywrightConstructs");
5
+ var _playwrightContext = require("../../common/playwrightContext");
6
6
  var _settings = require("../common/utils/settings");
7
7
  var _dotenv = _interopRequireDefault(require("dotenv"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -19,8 +19,8 @@ _commander.program.description("load auth session to browser").option("--cdpAddr
19
19
  }
20
20
  const {
21
21
  context
22
- } = await (0, _getPlaywrightConstructs.getRemotePlaywrightContext)(cdpAddress);
23
- await (0, _getPlaywrightConstructs.loadSessionToContext)({
22
+ } = await (0, _playwrightContext.getRemotePlaywrightContext)(cdpAddress);
23
+ await (0, _playwrightContext.loadSessionToContext)({
24
24
  context,
25
25
  session: {
26
26
  type: "file",
@@ -54,8 +54,7 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
54
54
  session: {
55
55
  type: "file",
56
56
  path: authSessionPath
57
- },
58
- runCheck: false
57
+ }
59
58
  },
60
59
  importFunction: _tsNodeImport.tsNodeImport
61
60
  }));
@@ -3,7 +3,6 @@
3
3
 
4
4
  var _commander = require("commander");
5
5
  var fs = _interopRequireWildcard(require("fs-extra"));
6
- var _promptly = require("promptly");
7
6
  var _fileUtils = require("../common/utils/fileUtils");
8
7
  var _settings = require("../common/utils/settings");
9
8
  var _dotenv = _interopRequireDefault(require("dotenv"));
@@ -42,7 +41,7 @@ _commander.program.description("run auth session create").option("--cdpAddress <
42
41
  throw new Error("auth session create file not found");
43
42
  }
44
43
  async function runCreate() {
45
- const generator = (0, _runApi.runApiGenerator)({
44
+ const result = await (0, _runApi.runApi)({
46
45
  automationFunction: {
47
46
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
48
47
  params: inputData
@@ -55,40 +54,18 @@ _commander.program.description("run auth session create").option("--cdpAddress <
55
54
  retrieveSession: true,
56
55
  importFunction: _tsNodeImport.tsNodeImport
57
56
  });
58
- let nextGeneratorParam = undefined;
59
- while (true) {
60
- const {
61
- value,
62
- done
63
- } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
64
- if (done) {
65
- if (value.isErr()) {
66
- if (value.error instanceof _runApi.AutomationError) {
67
- throw value.error.error;
68
- }
69
- console.error(value.error);
70
- throw new Error("Error while running create");
71
- }
72
- const fullState = value.value.session;
73
- if (pathToSave) {
74
- const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
75
- fs.ensureFileSync(fullPath);
76
- await fs.writeJSON(fullPath, fullState);
77
- }
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, {});
57
+ if (result.isErr()) {
58
+ if (result.error instanceof _runApi.AutomationError) {
59
+ throw result.error.error;
91
60
  }
61
+ console.error(result.error);
62
+ throw new Error("Error while running create");
63
+ }
64
+ const fullState = result.value.session;
65
+ if (pathToSave) {
66
+ const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
67
+ fs.ensureFileSync(fullPath);
68
+ await fs.writeJSON(fullPath, fullState);
92
69
  }
93
70
  }
94
71
  await (0, _asyncLocalStorage.runWithContext)({
@@ -1 +1 @@
1
- export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
1
+ export declare function runAutomationCLI<ResultType = any>(importFunction?: (path: string) => Promise<any>): void;
@@ -64,15 +64,10 @@ function runAutomationCLI(importFunction) {
64
64
  const throttleTime = 60 * 1000;
65
65
  let timeoutTimestamp = Date.now();
66
66
  const client = net.createConnection(socketPath);
67
- let generator = null;
68
67
  const abortController = new AbortController();
69
- client.on("error", err => {
70
- void generator?.throw(err).catch(() => undefined);
71
- });
72
68
  const interruptSignalHandler = async () => {
73
69
  abortController.abort();
74
70
  await (0, _promises.setTimeout)(60_000);
75
- void generator?.throw(new Error("Interrupted")).catch(() => undefined);
76
71
  client.end();
77
72
  process.exit(1);
78
73
  };
@@ -107,11 +102,6 @@ function runAutomationCLI(importFunction) {
107
102
  return;
108
103
  }
109
104
  if (message.type === "start") {
110
- generator = (0, _runApi.runApiGenerator)({
111
- ...message.parameters,
112
- abortSignal: abortController.signal,
113
- importFunction: importFunction ?? _defaultImport
114
- });
115
105
  context = {
116
106
  extendedPayloads: [],
117
107
  runEnvironment: message.parameters.runOptions.environment === "standalone" ? _enums.RunEnvironment.DEPLOYED : _enums.RunEnvironment.IDE,
@@ -130,38 +120,18 @@ function runAutomationCLI(importFunction) {
130
120
  };
131
121
  _jwtTokenManager.backendFunctionsTokenManager.token = message.parameters.functionsToken;
132
122
  resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
133
- return await generator.next();
123
+ return await (0, _runApi.runApi)({
124
+ ...message.parameters,
125
+ abortSignal: abortController.signal,
126
+ importFunction: importFunction ?? _defaultImport
127
+ });
134
128
  });
135
129
  return;
136
130
  }
137
131
  if (message.type === "next") {
138
- if (!generator) {
139
- throw new Error("generator not started");
140
- }
141
- resultPromise = (0, _asyncLocalStorage.runWithContext)(context, async () => {
142
- return await generator.next(message.parameters.value);
143
- });
144
- return;
132
+ throw new Error("next not supported anymore");
145
133
  }
146
134
  }
147
- async function handleResult(generatorResult) {
148
- if (!generatorResult.done) {
149
- jsonUnixSocket.sendJSON({
150
- type: "yield",
151
- result: generatorResult.value
152
- });
153
- return false;
154
- }
155
- const result = generatorResult.value;
156
- const success = result.isOk();
157
- const resultToSend = success ? result.value : result.error.json;
158
- jsonUnixSocket.sendJSON({
159
- type: "done",
160
- result: resultToSend,
161
- success
162
- });
163
- return true;
164
- }
165
135
  let receiveMessagesPromise = receiveMessages();
166
136
  while (true) {
167
137
  const messageOrResult = await Promise.race([receiveMessagesPromise.then(message => ({
@@ -199,10 +169,14 @@ function runAutomationCLI(importFunction) {
199
169
  const {
200
170
  result
201
171
  } = messageOrResult;
202
- const done = await handleResult(result);
203
- if (done) {
204
- break;
205
- }
172
+ const success = result.isOk();
173
+ const resultToSend = success ? result.value : result.error.json;
174
+ jsonUnixSocket.sendJSON({
175
+ type: "done",
176
+ result: resultToSend,
177
+ success
178
+ });
179
+ break;
206
180
  }
207
181
  if (!client.closed) {
208
182
  client.end();
@@ -6,19 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.deployCommand = void 0;
7
7
  var _command = require("./command");
8
8
  var _dotenv = _interopRequireDefault(require("dotenv"));
9
+ var _save = require("../controller/save");
9
10
  var _deploy = require("../controller/deploy");
10
11
  var _helpers = require("../helpers");
11
- var _zod = require("zod");
12
+ var _save2 = require("./save.command");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  _dotenv.default.config({
14
15
  path: `.env`
15
16
  });
16
- const deployCommandSchema = _zod.z.tuple([_zod.z.union([_zod.z.string(), _zod.z.undefined()]), _zod.z.object({
17
- workspaceId: _zod.z.string().optional(),
18
- apiKey: _zod.z.string().optional()
19
- })]);
20
- const deployCommand = exports.deployCommand = _command.program.command("deploy").description("Deploy an Intuned project to the platform").argument("[project-name]", "Name of the project to deploy").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action((0, _helpers.withErrorLogging)(async (inputProjectName, inputOptions) => {
21
- const parseResult = deployCommandSchema.safeParse([inputProjectName, inputOptions]);
17
+ const deployCommand = exports.deployCommand = _command.program.command("deploy").description("Save and deploy an Intuned project to the platform").argument("[project-name]", "Name of the project to deploy").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action((0, _helpers.withErrorLogging)(async (inputProjectName, inputOptions) => {
18
+ const parseResult = _save2.saveOrDeployCommandSchema.safeParse([inputProjectName, inputOptions]);
22
19
  if (!parseResult.success) {
23
20
  return (0, _helpers.logInvalidInput)(parseResult);
24
21
  }
@@ -26,7 +23,7 @@ const deployCommand = exports.deployCommand = _command.program.command("deploy")
26
23
  const {
27
24
  isValid,
28
25
  errorMessage
29
- } = await (0, _deploy.validateIntunedProject)();
26
+ } = await (0, _save.validateIntunedProject)();
30
27
  if (!isValid) {
31
28
  const message = `^r^+Project to be deployed is not a valid Intuned project:^:^R ${errorMessage}:\n`;
32
29
  throw new _helpers.CLIError(message, {
@@ -37,7 +34,7 @@ const deployCommand = exports.deployCommand = _command.program.command("deploy")
37
34
  if (!_projectName) {
38
35
  throw new _helpers.CLIError("Project name is required");
39
36
  }
40
- const projectNameValidation = (0, _deploy.validateProjectName)(_projectName);
37
+ const projectNameValidation = (0, _save.validateProjectName)(_projectName);
41
38
  if (!projectNameValidation.isValid) {
42
39
  throw new _helpers.CLIError(projectNameValidation.errorMessage);
43
40
  }
@@ -1,6 +1,7 @@
1
1
  export * from "./command";
2
2
  export * from "./build.command";
3
3
  export * from "./deploy.command";
4
+ export * from "./save.command";
4
5
  export * from "./init.command";
5
6
  export * from "./run.command";
6
7
  export * from "./run_api.command";
@@ -36,6 +36,17 @@ Object.keys(_deploy).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
+ var _save = require("./save.command");
40
+ Object.keys(_save).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _save[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _save[key];
47
+ }
48
+ });
49
+ });
39
50
  var _init = require("./init.command");
40
51
  Object.keys(_init).forEach(function (key) {
41
52
  if (key === "default" || key === "__esModule") return;
@@ -1,7 +1,8 @@
1
1
  export declare const baseRunAuthSessionCommandOptionsSchema: import("zod").ZodObject<{
2
2
  proxy: import("zod").ZodOptional<import("zod").ZodString>;
3
- headless: import("zod").ZodDefault<import("zod").ZodBoolean>;
4
3
  timeout: import("zod").ZodEffects<import("zod").ZodEffects<import("zod").ZodDefault<import("zod").ZodString>, import("ms").StringValue, string | undefined>, number, string | undefined>;
4
+ headless: import("zod").ZodDefault<import("zod").ZodBoolean>;
5
+ } & {
5
6
  checkAttempts: import("zod").ZodDefault<import("zod").ZodNumber>;
6
7
  createAttempts: import("zod").ZodDefault<import("zod").ZodNumber>;
7
8
  }, "strip", import("zod").ZodTypeAny, {
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ export declare const saveOrDeployCommandSchema: z.ZodTuple<[z.ZodUnion<[z.ZodString, z.ZodUndefined]>, z.ZodObject<{
3
+ workspaceId: z.ZodOptional<z.ZodString>;
4
+ apiKey: z.ZodOptional<z.ZodString>;
5
+ }, "strip", z.ZodTypeAny, {
6
+ workspaceId?: string | undefined;
7
+ apiKey?: string | undefined;
8
+ }, {
9
+ workspaceId?: string | undefined;
10
+ apiKey?: string | undefined;
11
+ }>], null>;
12
+ export declare const saveCommand: import("commander").Command;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.saveOrDeployCommandSchema = exports.saveCommand = void 0;
7
+ var _command = require("./command");
8
+ var _dotenv = _interopRequireDefault(require("dotenv"));
9
+ var _save = require("../controller/save");
10
+ var _helpers = require("../helpers");
11
+ var _zod = require("zod");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ _dotenv.default.config({
14
+ path: `.env`
15
+ });
16
+ const saveOrDeployCommandSchema = exports.saveOrDeployCommandSchema = _zod.z.tuple([_zod.z.union([_zod.z.string(), _zod.z.undefined()]), _zod.z.object({
17
+ workspaceId: _zod.z.string().optional(),
18
+ apiKey: _zod.z.string().optional()
19
+ })]);
20
+ const saveCommand = exports.saveCommand = _command.program.command("save").description("Save an Intuned project to the platform without deploying it").argument("[project-name]", "Name of the project to save").option("-w, --workspace-id <id>", "Your Intuned workspace ID").option("-k, --api-key <key>", "Your Intuned API key").action((0, _helpers.withErrorLogging)(async (inputProjectName, inputOptions) => {
21
+ const parseResult = saveOrDeployCommandSchema.safeParse([inputProjectName, inputOptions]);
22
+ if (!parseResult.success) {
23
+ return (0, _helpers.logInvalidInput)(parseResult);
24
+ }
25
+ const [projectName, options] = parseResult.data;
26
+ const {
27
+ isValid,
28
+ errorMessage
29
+ } = await (0, _save.validateIntunedProject)();
30
+ if (!isValid) {
31
+ const message = `^r^+Project to be saved is not a valid Intuned project:^:^R ${errorMessage}:\n`;
32
+ throw new _helpers.CLIError(message, {
33
+ autoColor: false
34
+ });
35
+ }
36
+ const _projectName = projectName || (await (0, _helpers.getSettingIntunedJSON)("projectName"));
37
+ if (!_projectName) {
38
+ throw new _helpers.CLIError("Project name is required");
39
+ }
40
+ const projectNameValidation = (0, _save.validateProjectName)(_projectName);
41
+ if (!projectNameValidation.isValid) {
42
+ throw new _helpers.CLIError(projectNameValidation.errorMessage);
43
+ }
44
+ const auth = await (0, _helpers.getAuthCredentials)(options);
45
+ await (0, _save.runSaveProject)(_projectName, auth);
46
+ }));
@@ -15,7 +15,7 @@ export declare const baseCommandOptionsSchema: z.ZodObject<{
15
15
  proxy?: string | undefined;
16
16
  }, {
17
17
  proxy?: string | undefined;
18
- timeout?: string | undefined;
19
18
  headless?: boolean | undefined;
19
+ timeout?: string | undefined;
20
20
  }>;
21
21
  export type BaseCommandOptions = z.infer<typeof baseCommandOptionsSchema>;
@@ -84,8 +84,7 @@ _vitest.vi.mock("../../helpers", async importOriginal => {
84
84
  session: {
85
85
  type: "state",
86
86
  state: "auth"
87
- },
88
- runCheck: false
87
+ }
89
88
  },
90
89
  importFunction: _vitest.expect.anything()
91
90
  }));
@@ -159,8 +159,7 @@ async function attemptApi({
159
159
  session: {
160
160
  type: "state",
161
161
  state: auth
162
- },
163
- runCheck: false
162
+ }
164
163
  } : undefined,
165
164
  importFunction: _tsNodeImport.tsNodeImport,
166
165
  abortSignal
@@ -179,8 +179,7 @@ async function runCheck({
179
179
  session: {
180
180
  type: "state",
181
181
  state: auth
182
- },
183
- runCheck: false
182
+ }
184
183
  },
185
184
  importFunction: _tsNodeImport.tsNodeImport,
186
185
  abortSignal
@@ -241,7 +240,7 @@ async function runCheckWithRetries({
241
240
  return true;
242
241
  }
243
242
  } catch (error) {
244
- if (error instanceof _runApi.AutomationError) {
243
+ if (error instanceof _runApi.RunAutomationError) {
245
244
  (0, _helpers.logAutomationError)(error);
246
245
  } else {
247
246
  throw error;
@@ -270,7 +269,7 @@ async function runCreateWithRetries({
270
269
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
271
270
  break;
272
271
  } catch (error) {
273
- if (error instanceof _runApi.AutomationError) {
272
+ if (error instanceof _runApi.RunAutomationError) {
274
273
  (0, _helpers.logAutomationError)(error);
275
274
  } else {
276
275
  throw error;
@@ -1,15 +1,4 @@
1
1
  import { z } from "zod";
2
- import type { AuthCredentials, FileSystemTree } from "../types";
3
- export declare function convertProjectToCodeTree(projectPath: string): Promise<FileSystemTree>;
2
+ import type { AuthCredentials } from "../types";
4
3
  export declare function runDeployProject(projectName: string, auth: AuthCredentials): Promise<void>;
5
4
  export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
6
- export declare const validateProjectName: (projectName: string) => {
7
- isValid: true;
8
- } | {
9
- isValid: false;
10
- errorMessage: string;
11
- };
12
- export declare const validateIntunedProject: () => Promise<{
13
- isValid: boolean;
14
- errorMessage?: string;
15
- }>;