@intuned/runtime 1.0.5 → 1.1.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 (50) hide show
  1. package/InterfaceTemplate/utils.ts +53 -31
  2. package/LICENSE +43 -0
  3. package/bin/check-auth-session +3 -0
  4. package/bin/cli-build +3 -0
  5. package/bin/create-auth-session +3 -0
  6. package/bin/deploy +3 -0
  7. package/bin/init +3 -0
  8. package/bin/run-api +3 -0
  9. package/dist/commands/cli-auth-sessions/check.d.ts +2 -0
  10. package/dist/commands/cli-auth-sessions/check.js +40 -0
  11. package/dist/commands/cli-auth-sessions/create.d.ts +2 -0
  12. package/dist/commands/cli-auth-sessions/create.js +53 -0
  13. package/dist/commands/cli-auth-sessions/utils.d.ts +28 -0
  14. package/dist/commands/cli-auth-sessions/utils.js +285 -0
  15. package/dist/commands/cli-build/cli-build.d.ts +2 -0
  16. package/dist/commands/cli-build/cli-build.js +20 -0
  17. package/dist/commands/common/projectExclusions.d.ts +2 -0
  18. package/dist/commands/common/projectExclusions.js +8 -0
  19. package/dist/commands/common/tsNodeImport.d.ts +2 -1
  20. package/dist/commands/common/tsNodeImport.js +19 -5
  21. package/dist/commands/deploy/deploy.d.ts +2 -0
  22. package/dist/commands/deploy/deploy.js +47 -0
  23. package/dist/commands/deploy/utils.d.ts +16 -0
  24. package/dist/commands/deploy/utils.js +408 -0
  25. package/dist/commands/init/init.d.ts +2 -0
  26. package/dist/commands/init/init.js +22 -0
  27. package/dist/commands/init/utils.d.ts +11 -0
  28. package/dist/commands/init/utils.js +181 -0
  29. package/dist/commands/interface/run.js +30 -3
  30. package/dist/commands/run-api-cli/run-api.d.ts +2 -0
  31. package/dist/commands/run-api-cli/run-api.js +57 -0
  32. package/dist/commands/run-api-cli/utils.d.ts +9 -0
  33. package/dist/commands/run-api-cli/utils.js +144 -0
  34. package/dist/common/asyncLocalStorage/index.d.ts +1 -1
  35. package/dist/common/asyncLocalStorage/index.js +2 -2
  36. package/dist/common/cli/cliReadme.d.ts +1 -0
  37. package/dist/common/cli/cliReadme.js +92 -0
  38. package/dist/common/cli/constants.d.ts +33 -0
  39. package/dist/common/cli/constants.js +39 -0
  40. package/dist/common/cli/types.d.ts +74 -0
  41. package/dist/common/cli/types.js +13 -0
  42. package/dist/common/cli/utils.d.ts +6 -0
  43. package/dist/common/cli/utils.js +35 -0
  44. package/dist/common/constants.d.ts +1 -0
  45. package/dist/common/constants.js +3 -2
  46. package/dist/common/contextStorageStateHelpers.d.ts +1 -1
  47. package/dist/common/runApi/index.d.ts +1 -0
  48. package/dist/common/runApi/index.js +9 -2
  49. package/dist/common/runApi/types.d.ts +7 -1
  50. package/package.json +41 -41
@@ -0,0 +1,74 @@
1
+ export declare const templateIds: string[];
2
+ export type TemplateId = (typeof templateIds)[number];
3
+ /**
4
+ * A simple, tree-like structure to describe the contents of a folder to be mounted.
5
+ *
6
+ * @example
7
+ * ```
8
+ * const tree = {
9
+ * myproject: {
10
+ * directory: {
11
+ * 'foo.js': {
12
+ * file: {
13
+ * contents: 'const x = 1;',
14
+ * },
15
+ * },
16
+ * .envrc: {
17
+ * file: {
18
+ * contents: 'ENVIRONMENT=staging'
19
+ * }
20
+ * },
21
+ * },
22
+ * },
23
+ * emptyFolder: {
24
+ * directory: {}
25
+ * },
26
+ * };
27
+ * ```
28
+ */
29
+ export interface FileSystemTree {
30
+ [name: string]: DirectoryNode | FileNode;
31
+ }
32
+ /**
33
+ * Represents a directory, see {@link FileSystemTree}.
34
+ */
35
+ export interface DirectoryNode {
36
+ directory: FileSystemTree;
37
+ }
38
+ /**
39
+ * Represents a file, see {@link FileSystemTree}.
40
+ */
41
+ export interface FileNode {
42
+ file: {
43
+ /**
44
+ * The contents of the file, either as a UTF-8 string or as raw binary.
45
+ */
46
+ contents: string | Uint8Array;
47
+ };
48
+ }
49
+ export interface AuthCredentials {
50
+ workspaceId: string;
51
+ apiKey: string;
52
+ }
53
+ export declare enum ApiAuthSessionBehavior {
54
+ PERFORM_CHECK_AND_REFRESH = "PERFORM_CHECK_AND_REFRESH",
55
+ SKIP_CHECK_AND_REFRESH = "SKIP_CHECK_AND_REFRESH"
56
+ }
57
+ export declare const CHECK_FAILED_ERROR_MESSAGE = "Auth session check failed";
58
+ export type AuthSessionType = "API" | "MANUAL";
59
+ export type AuthSessionMetadata = {
60
+ createdAt: string;
61
+ updatedAt: string;
62
+ authSessionId: string;
63
+ authSessionType: AuthSessionType;
64
+ authSessionInput?: Record<string, any>;
65
+ recorderStartUrl?: string;
66
+ recorderEndUrl?: string;
67
+ };
68
+ export interface SessionStorageState {
69
+ origin: string;
70
+ sessionStorage: {
71
+ name: string;
72
+ value: string;
73
+ }[];
74
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.templateIds = exports.CHECK_FAILED_ERROR_MESSAGE = exports.ApiAuthSessionBehavior = void 0;
7
+ const templateIds = exports.templateIds = ["default", "empty", "linkedin-recorder", "api-auth-sessions", "nested-scheduling", "ai-extractors", "npm-auth-sessions"];
8
+ let ApiAuthSessionBehavior = exports.ApiAuthSessionBehavior = function (ApiAuthSessionBehavior) {
9
+ ApiAuthSessionBehavior["PERFORM_CHECK_AND_REFRESH"] = "PERFORM_CHECK_AND_REFRESH";
10
+ ApiAuthSessionBehavior["SKIP_CHECK_AND_REFRESH"] = "SKIP_CHECK_AND_REFRESH";
11
+ return ApiAuthSessionBehavior;
12
+ }({});
13
+ const CHECK_FAILED_ERROR_MESSAGE = exports.CHECK_FAILED_ERROR_MESSAGE = "Auth session check failed";
@@ -0,0 +1,6 @@
1
+ export declare function getAuthCredentials(options: any): Promise<{
2
+ workspaceId: any;
3
+ apiKey: any;
4
+ }>;
5
+ export declare function getBaseUrl(): string;
6
+ export declare function getSettingIntunedJSON(key: string): Promise<any>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAuthCredentials = getAuthCredentials;
7
+ exports.getBaseUrl = getBaseUrl;
8
+ exports.getSettingIntunedJSON = getSettingIntunedJSON;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var fs = _interopRequireWildcard(require("fs-extra"));
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
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ async function getAuthCredentials(options) {
15
+ const workspaceId = options.workspaceId || (await getSettingIntunedJSON("workspaceId"));
16
+ const apiKey = options.apiKey || process.env.INTUNED_API_KEY;
17
+ if (!workspaceId || !apiKey) {
18
+ throw new Error("Authentication details are required. Please provide them via command line options(api key, workspace id), intuned.json(workspace id) or environment variables(api key).");
19
+ }
20
+ return {
21
+ workspaceId,
22
+ apiKey
23
+ };
24
+ }
25
+ function getBaseUrl() {
26
+ return process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`;
27
+ }
28
+ async function getSettingIntunedJSON(key) {
29
+ const intunedJsonPath = _path.default.join(process.cwd(), "Intuned.json");
30
+ const intunedJson = await fs.readJSON(intunedJsonPath);
31
+ if (intunedJson && intunedJson[key]) {
32
+ return intunedJson[key];
33
+ }
34
+ return null;
35
+ }
@@ -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";
@@ -1,4 +1,4 @@
1
- import * as playwright from "playwright-core";
1
+ import * as playwright from "playwright";
2
2
  interface StorageEntry {
3
3
  name: string;
4
4
  value: string;
@@ -10,3 +10,4 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
10
10
  export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
11
11
  export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
12
12
  export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
13
+ export type ImportFunction = ExtendedRunApiParameters["importFunction"];
@@ -242,7 +242,14 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
242
242
  }
243
243
  async function importUsingImportFunction(path, importFunction) {
244
244
  try {
245
- const imported = importFunction ? await importFunction(path) : await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
245
+ const importedResult = await importFunction(path);
246
+ if (importedResult.isErr()) {
247
+ if (importedResult.error.type === "not_found") {
248
+ return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
249
+ }
250
+ return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
251
+ }
252
+ const imported = importedResult.value;
246
253
  if (!imported || !imported.default || !imported.default.constructor) {
247
254
  return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
248
255
  }
@@ -260,6 +267,6 @@ async function importUsingImportFunction(path, importFunction) {
260
267
  }
261
268
  return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
262
269
  } catch (error) {
263
- return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
270
+ return (0, _neverthrow.err)(new _errors.AutomationError(error));
264
271
  }
265
272
  }
@@ -688,9 +688,15 @@ export declare const runApiParametersSchema: z.ZodObject<{
688
688
  }>;
689
689
  export type RunApiSession = z.infer<typeof runApiSessionSchema>;
690
690
  export type RunApiParameters = z.input<typeof runApiParametersSchema>;
691
+ export type ImportFunctionError = {
692
+ type: "not_found";
693
+ } | {
694
+ type: "other";
695
+ error: any;
696
+ };
691
697
  export type ExtendedRunApiParameters = RunApiParameters & {
692
698
  abortSignal?: AbortSignal;
693
- importFunction?: (name: string) => Promise<any> | undefined;
699
+ importFunction: (name: string) => Promise<Result<any, ImportFunctionError>>;
694
700
  };
695
701
  export type RunApiResultOk<R = any> = {
696
702
  result: R;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
@@ -13,11 +13,12 @@
13
13
  "./dist/common/asyncLocalStorage": "./dist/common/asyncLocalStorage/index.js",
14
14
  "./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
15
15
  "./dist/common/constants": "./dist/common/constants.js",
16
- "./dist/commands/interface/run": "./dist/commands/interface/run.js"
16
+ "./dist/commands/interface/run": "./dist/commands/interface/run.js",
17
+ "./dist/commands/intuned-run/intuned-run": "./dist/commands/intuned-run/intuned-run.js"
17
18
  },
18
19
  "types": "./dist/index.d.ts",
19
20
  "author": "Intuned Team",
20
- "license": "MIT",
21
+ "license": "Elastic-2.0",
21
22
  "scripts": {
22
23
  "intuned-api-run": "vite-node ./src/commands/api/run.ts",
23
24
  "intuned-browser-save-state": "vite-node ./src/commands/browser/save-state.ts",
@@ -48,54 +49,53 @@
48
49
  "intuned-build": "./bin/intuned-build",
49
50
  "intuned-browser-start": "./bin/intuned-browser-start",
50
51
  "intuned-browser-save-state": "./bin/intuned-browser-save-state",
51
- "intuned-ts-check": "./bin/intuned-ts-check"
52
+ "intuned-ts-check": "./bin/intuned-ts-check",
53
+ "init": "./bin/init",
54
+ "run-api": "./bin/run-api",
55
+ "deploy": "./bin/deploy",
56
+ "cli-build": "./bin/cli-build",
57
+ "create-auth-session": "./bin/create-auth-session",
58
+ "check-auth-session": "./bin/check-auth-session"
52
59
  },
53
60
  "dependencies": {
54
- "@babel/plugin-syntax-dynamic-import": "^7.8.3",
55
- "@rollup/plugin-commonjs": "^25.0.2",
56
- "@rollup/plugin-dynamic-import-vars": "^2.0.4",
57
- "@rollup/plugin-json": "^6.0.0",
58
- "@rollup/plugin-node-resolve": "^15.1.0",
59
- "@rollup/plugin-typescript": "^11.1.2",
60
- "@tinyhttp/app": "^2.1.0",
61
- "@types/async-retry": "^1.4.8",
62
- "@types/fs-extra": "^11.0.1",
63
- "@types/lodash": "^4.14.200",
64
- "@types/node": "^20.4.1",
65
- "applicationinsights": "^2.9.2",
66
- "async-retry": "^1.3.3",
67
- "babel-plugin-dynamic-import-node": "^2.3.3",
61
+ "@babel/plugin-syntax-dynamic-import": "7.8.3",
62
+ "@rollup/plugin-commonjs": "25.0.2",
63
+ "@rollup/plugin-dynamic-import-vars": "2.0.4",
64
+ "@rollup/plugin-json": "6.0.0",
65
+ "@rollup/plugin-node-resolve": "15.1.0",
66
+ "@rollup/plugin-typescript": "11.1.2",
67
+ "@types/fs-extra": "11.0.1",
68
+ "@types/lodash": "4.14.200",
69
+ "@types/node": "20.4.1",
70
+ "applicationinsights": "2.9.2",
71
+ "babel-plugin-dynamic-import-node": "2.3.3",
72
+ "boxen": "8.0.1",
68
73
  "chalk": "^4.1.2",
69
74
  "commander": "^11.0.0",
70
75
  "cross-fetch": "^4.0.0",
71
76
  "dotenv": "^16.3.1",
72
- "express": "4.20.0",
73
- "fastify": "^4.19.2",
74
- "file-type": "16.5.4",
75
77
  "fs-extra": "^11.3.0",
76
- "https-proxy-agent": "^7.0.5",
77
78
  "image-size": "^1.1.1",
78
- "jsonwebtoken": "^9.0.2",
79
- "lodash": "^4.17.21",
80
- "milliparsec": "^2.3.0",
81
- "ms": "^2.1.3",
79
+ "inquirer": "12.6.0",
80
+ "jsonwebtoken": "9.0.2",
81
+ "lodash": "4.17.21",
82
+ "milliparsec": "2.3.0",
83
+ "minimatch": "10.0.1",
82
84
  "nanoid": "3",
83
- "neverthrow": "^6.1.0",
85
+ "neverthrow": "6.1.0",
84
86
  "playwright": "1.44.1",
85
- "playwright-extra": "^4.3.6",
86
- "prettier": "^2.8.0",
87
- "promptly": "^3.2.0",
88
- "read-chunk": "^3.2.0",
89
- "rollup": "^3.26.2",
90
- "source-map": "^0.7.4",
91
- "stack-utils": "^2.0.6",
92
- "ts-morph": "^21.0.1",
93
- "ts-node": "^10.9.1",
94
- "tslib": "^2.6.0",
95
- "typescript": "^5.1.6",
96
- "wait-on": "^7.2.0",
97
- "zod": "^3.21.4",
98
- "zod-validation-error": "^3.0.3"
87
+ "playwright-extra": "4.3.6",
88
+ "prettier": "2.8.0",
89
+ "promptly": "3.2.0",
90
+ "rollup": "3.26.2",
91
+ "source-map": "0.7.4",
92
+ "ts-morph": "21.0.1",
93
+ "ts-node": "10.9.1",
94
+ "tslib": "2.6.0",
95
+ "typescript": "5.1.6",
96
+ "uuid": "11.1.0",
97
+ "wait-on": "7.2.0",
98
+ "zod": "^3.21.4"
99
99
  },
100
100
  "devDependencies": {
101
101
  "@babel/cli": "^7.23.4",