@intuned/runtime 1.3.0 → 1.3.2

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 +93 -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
@@ -3,147 +3,32 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.convertProjectToCodeTree = convertProjectToCodeTree;
7
6
  exports.projectNameSchema = void 0;
8
7
  exports.runDeployProject = runDeployProject;
9
- exports.validateProjectName = exports.validateIntunedProject = void 0;
10
- var fs = _interopRequireWildcard(require("fs-extra"));
11
- var path = _interopRequireWildcard(require("path"));
12
- var _minimatch = require("minimatch");
13
8
  var _zod = require("zod");
14
- var _projectExclusions = _interopRequireDefault(require("../../common/projectExclusions"));
15
9
  var _constants = require("../constants");
16
10
  var _helpers = require("../helpers");
17
- var _lodash = require("lodash");
18
- var _uuid = require("uuid");
19
11
  var _terminal = require("../helpers/terminal");
20
12
  var _promises = require("timers/promises");
21
13
  var _ms = _interopRequireDefault(require("ms"));
22
- var _build = require("./build");
14
+ var _save = require("./save");
15
+ var _constants2 = require("../../../common/constants");
23
16
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
24
- 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); }
25
- 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; }
26
- function ignoreFilesByPattern(filePath, patterns, projectPath) {
27
- const relativePath = path.relative(projectPath, filePath);
28
- if (relativePath.startsWith("node_modules")) {
29
- return true;
30
- }
31
- for (const pattern of patterns) {
32
- if (!pattern || pattern.startsWith("#")) continue;
33
- if (pattern.startsWith("!")) {
34
- if ((0, _minimatch.minimatch)(relativePath, pattern.substring(1))) {
35
- return false;
36
- }
37
- } else if ((0, _minimatch.minimatch)(relativePath, pattern)) {
38
- return true;
39
- }
40
- }
41
- return false;
42
- }
43
- function listFilesNotIgnored(projectPath, ignorePatterns) {
44
- const results = [];
45
- function traverseDirectory(dirPath) {
46
- try {
47
- const entries = fs.readdirSync(dirPath);
48
- for (const entry of entries) {
49
- const fullPath = path.join(dirPath, entry);
50
- if (ignoreFilesByPattern(fullPath, ignorePatterns, projectPath)) {
51
- continue;
52
- }
53
- try {
54
- const stats = fs.statSync(fullPath);
55
- if (stats.isDirectory()) {
56
- traverseDirectory(fullPath);
57
- } else if (stats.isFile()) {
58
- results.push(path.relative(projectPath, fullPath));
59
- }
60
- } catch (error) {
61
- (0, _terminal.terminal)(`^yWarning: Could not access ${fullPath}^:\n`);
62
- }
63
- }
64
- } catch (error) {
65
- (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
66
- }
67
- }
68
- traverseDirectory(projectPath);
69
- return results;
70
- }
71
- async function convertProjectToCodeTree(projectPath) {
72
- const filesToDeploy = listFilesNotIgnored(projectPath, _projectExclusions.default);
73
- const filesToDeployText = " " + filesToDeploy.join("\n ");
74
- (0, _terminal.terminal)("^CFiles to be deployed:^:\n");
75
- (0, _terminal.terminal)(filesToDeployText + "\n");
76
- function readDirectory(dirPath) {
77
- const tree = {};
78
- try {
79
- const entries = fs.readdirSync(dirPath);
80
- for (const entry of entries) {
81
- const entryPath = path.join(dirPath, entry);
82
- if (ignoreFilesByPattern(entryPath, _projectExclusions.default, projectPath)) {
83
- continue;
84
- }
85
- try {
86
- const stats = fs.statSync(entryPath);
87
- if (stats.isFile()) {
88
- try {
89
- const content = fs.readFileSync(entryPath, "utf-8");
90
- tree[entry] = {
91
- file: {
92
- contents: content
93
- }
94
- };
95
- } catch (error) {
96
- (0, _terminal.terminal)(`^yWarning: Could not read file ${entryPath}^:\n`);
97
- }
98
- } else if (stats.isDirectory()) {
99
- const subTree = readDirectory(entryPath);
100
- if (Object.keys(subTree).length > 0) {
101
- tree[entry] = {
102
- directory: subTree
103
- };
104
- }
105
- }
106
- } catch (error) {
107
- (0, _terminal.terminal)(`^yWarning: Could not access ${entryPath}^:\n`);
108
- }
109
- }
110
- } catch (error) {
111
- (0, _terminal.terminal)(`^YWarning: Could not read directory ${dirPath}^:\n`);
112
- }
113
- return tree;
114
- }
115
- const tree = readDirectory(projectPath);
116
- await mapToIDEParams(tree);
117
- return tree;
118
- }
119
17
  async function runDeployProject(projectName, auth) {
18
+ await (0, _save.runSaveProject)(projectName, auth);
120
19
  const {
121
20
  workspaceId,
122
21
  apiKey
123
22
  } = auth;
124
23
  const baseUrl = (0, _helpers.getBaseUrl)();
125
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create`;
24
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy`;
126
25
  const headers = {
127
- "x-api-key": apiKey,
26
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
128
27
  "Content-Type": "application/json"
129
28
  };
130
- const projectPath = process.cwd();
131
- const codeTree = await convertProjectToCodeTree(projectPath);
132
- codeTree["tsconfig.json"] = {
133
- file: {
134
- contents: JSON.stringify(_constants.tsConfigCli, null, 2)
135
- }
136
- };
137
- const deployProjectPayload = {
138
- name: projectName,
139
- codeTree,
140
- isCli: true,
141
- language: "typescript"
142
- };
143
29
  const response = await fetch(url, {
144
30
  headers,
145
- method: "POST",
146
- body: JSON.stringify(deployProjectPayload)
31
+ method: "POST"
147
32
  });
148
33
  if (!response.ok) {
149
34
  if (response.status === 401) {
@@ -223,117 +108,11 @@ async function runDeployProject(projectName, auth) {
223
108
  const projectNameSchema = exports.projectNameSchema = _zod.z.string().min(1, "Project Name is required").max(50, "Name must be 50 characters or less").regex(/^[a-z0-9]+(?:[-_][a-z0-9]+)*$/, "Name can only contain lowercase letters, numbers, hyphens, and underscores in between").refine(value => !_zod.z.string().uuid().safeParse(value).success, {
224
109
  message: "Name cannot be a UUID"
225
110
  });
226
- const validateProjectName = projectName => {
227
- const validation = projectNameSchema.safeParse(projectName);
228
- if (!validation.success) {
229
- return {
230
- isValid: false,
231
- errorMessage: validation.error.errors[0].message
232
- };
233
- }
234
- return {
235
- isValid: true
236
- };
237
- };
238
- exports.validateProjectName = validateProjectName;
239
- const validateIntunedProject = async () => {
240
- const currentDirectoryToDeploy = process.cwd();
241
- const validationSteps = [{
242
- name: "build",
243
- check: async () => {
244
- try {
245
- const buildResult = await (0, _build.runBuild)();
246
- if (!buildResult) {
247
- return {
248
- isValid: false,
249
- errorMessage: "Build failed"
250
- };
251
- }
252
- return {
253
- isValid: true
254
- };
255
- } catch (error) {
256
- return {
257
- isValid: false,
258
- errorMessage: "Build failed"
259
- };
260
- }
261
- }
262
- }, {
263
- name: "package.json",
264
- check: async () => {
265
- try {
266
- const packageJsonPath = path.join(currentDirectoryToDeploy, "package.json");
267
- await fs.exists(packageJsonPath);
268
- const packageJson = JSON.parse(await fs.readFile(packageJsonPath, {
269
- encoding: "utf-8"
270
- }));
271
- const userCodePlaywrightVersion = packageJson.dependencies?.playwright;
272
- if (userCodePlaywrightVersion !== _constants.CURRENT_PLAYWRIGHT_VERSION) {
273
- return {
274
- isValid: false,
275
- errorMessage: `Playwright version mismatch: expected ${_constants.CURRENT_PLAYWRIGHT_VERSION}, found ${userCodePlaywrightVersion || "none"}`
276
- };
277
- }
278
- return {
279
- isValid: true
280
- };
281
- } catch (error) {
282
- return {
283
- isValid: false,
284
- errorMessage: "Package.json file not found or cannot be read"
285
- };
286
- }
287
- }
288
- }, {
289
- name: "Intuned.json",
290
- check: async () => {
291
- try {
292
- const intunedJsonPath = path.join(currentDirectoryToDeploy, "Intuned.json");
293
- await fs.exists(intunedJsonPath);
294
- return {
295
- isValid: true
296
- };
297
- } catch (error) {
298
- return {
299
- isValid: false,
300
- errorMessage: "Intuned.json file not found"
301
- };
302
- }
303
- }
304
- }, {
305
- name: "api folder",
306
- check: async () => {
307
- try {
308
- const apiFolderPath = path.join(currentDirectoryToDeploy, "api");
309
- await fs.access(apiFolderPath);
310
- return {
311
- isValid: true
312
- };
313
- } catch (error) {
314
- return {
315
- isValid: false,
316
- errorMessage: "API folder not found"
317
- };
318
- }
319
- }
320
- }];
321
- for (const step of validationSteps) {
322
- const result = await step.check();
323
- if (!result.isValid) {
324
- return result;
325
- }
326
- }
327
- return {
328
- isValid: true
329
- };
330
- };
331
- exports.validateIntunedProject = validateIntunedProject;
332
111
  const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey) => {
333
112
  const baseUrl = (0, _helpers.getBaseUrl)();
334
- const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/create/${projectName}/result`;
113
+ const url = `${baseUrl}/api/v1/workspace/${workspaceId}/projects/${projectName}/deploy/result`;
335
114
  const headers = {
336
- "x-api-key": apiKey,
115
+ [_constants2.API_KEY_HEADER_NAME]: apiKey,
337
116
  "Content-Type": "application/json"
338
117
  };
339
118
  const response = await fetch(url, {
@@ -357,58 +136,4 @@ const checkIntunedProjectDeployStatus = async (workspaceId, projectName, apiKey)
357
136
  status: "failed",
358
137
  message: `Deployment failed, please try again: ${data.message}`
359
138
  };
360
- };
361
- async function mapToIDEParams(tree) {
362
- if (!tree) {
363
- return;
364
- }
365
- if (!tree["parameters"] || "file" in tree["parameters"]) {
366
- return;
367
- }
368
- const apiParametersMap = {};
369
- const cliParameters = Object.keys(tree["parameters"].directory);
370
- const ____testParameters = {
371
- directory: {}
372
- };
373
- for (const parameterKey of cliParameters) {
374
- const parameter = tree["parameters"].directory[parameterKey];
375
- if ("directory" in parameter) {
376
- continue;
377
- }
378
- if ((0, _lodash.isEmpty)(parameter.file.contents)) {
379
- continue;
380
- }
381
- const parameterPayload = JSON.parse(parameter.file.contents);
382
- if (!parameterPayload["__api-name"]) {
383
- continue;
384
- }
385
- const api = parameterPayload["__api-name"];
386
- const {
387
- "__api-name": _,
388
- ...parameterValue
389
- } = parameterPayload;
390
- const testParameter = {
391
- name: parameterKey.replace(".json", ""),
392
- lastUsed: false,
393
- id: (0, _uuid.v4)(),
394
- value: JSON.stringify(parameterValue)
395
- };
396
- if (!apiParametersMap[api]) {
397
- apiParametersMap[api] = [];
398
- }
399
- apiParametersMap[api].push(testParameter);
400
- }
401
- for (const api in apiParametersMap) {
402
- if (apiParametersMap[api].length > 0) {
403
- apiParametersMap[api][apiParametersMap[api].length - 1].lastUsed = true;
404
- }
405
- ____testParameters.directory[`${api}.json`] = {
406
- file: {
407
- contents: JSON.stringify(apiParametersMap[api], null, 2)
408
- }
409
- };
410
- }
411
- delete tree["parameters"];
412
- tree["____testParameters"] = ____testParameters;
413
- return;
414
- }
139
+ };
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ import type { AuthCredentials } from "../types";
3
+ export declare function runSaveProject(projectName: string, auth: AuthCredentials): Promise<void>;
4
+ export declare const projectNameSchema: z.ZodEffects<z.ZodString, string, string>;
5
+ export declare const validateProjectName: (projectName: string) => {
6
+ isValid: true;
7
+ } | {
8
+ isValid: false;
9
+ errorMessage: string;
10
+ };
11
+ export declare const validateIntunedProject: () => Promise<{
12
+ isValid: boolean;
13
+ errorMessage?: string;
14
+ }>;