@intuned/runtime-dev 0.0.1-split.0

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 (87) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/.vite/deps_temp_01af7156/package.json +3 -0
  5. package/.vscode/extensions.json +3 -0
  6. package/.vscode/launch.json +102 -0
  7. package/.vscode/settings.json +12 -0
  8. package/WebTemplate/accessKeyHelpers.ts +28 -0
  9. package/WebTemplate/api.ts +139 -0
  10. package/WebTemplate/app.ts +18 -0
  11. package/WebTemplate/controllers/async.ts +138 -0
  12. package/WebTemplate/controllers/authSessions/check.ts +68 -0
  13. package/WebTemplate/controllers/authSessions/create.ts +128 -0
  14. package/WebTemplate/controllers/authSessions/index.ts +41 -0
  15. package/WebTemplate/controllers/authSessions/killOperation.ts +35 -0
  16. package/WebTemplate/controllers/authSessions/resumeOperation.ts +80 -0
  17. package/WebTemplate/controllers/authSessions/store.ts +14 -0
  18. package/WebTemplate/controllers/controllers.ts +73 -0
  19. package/WebTemplate/controllers/runApi/helpers.ts +220 -0
  20. package/WebTemplate/controllers/runApi/index.ts +68 -0
  21. package/WebTemplate/controllers/runApi/types.ts +13 -0
  22. package/WebTemplate/controllers/traces.ts +151 -0
  23. package/WebTemplate/features.ts +8 -0
  24. package/WebTemplate/headers.ts +6 -0
  25. package/WebTemplate/index.playwright.ts +47 -0
  26. package/WebTemplate/index.vanilla.ts +44 -0
  27. package/WebTemplate/jobs.ts +356 -0
  28. package/WebTemplate/shutdown.ts +64 -0
  29. package/WebTemplate/utils.ts +294 -0
  30. package/bin/intuned-api-run +2 -0
  31. package/bin/intuned-auth-session-check +2 -0
  32. package/bin/intuned-auth-session-create +2 -0
  33. package/bin/intuned-auth-session-load +2 -0
  34. package/bin/intuned-auth-session-refresh +2 -0
  35. package/bin/intuned-browser-save-state +2 -0
  36. package/bin/intuned-browser-start +2 -0
  37. package/bin/intuned-build +2 -0
  38. package/bin/intuned-ts-check +2 -0
  39. package/package.json +133 -0
  40. package/playwright.config.ts +48 -0
  41. package/src/commands/api/run.ts +225 -0
  42. package/src/commands/auth-sessions/load.ts +42 -0
  43. package/src/commands/auth-sessions/run-check.ts +70 -0
  44. package/src/commands/auth-sessions/run-create.ts +124 -0
  45. package/src/commands/browser/save-state.ts +22 -0
  46. package/src/commands/browser/start-browser.ts +17 -0
  47. package/src/commands/build.ts +125 -0
  48. package/src/commands/common/browserUtils.ts +80 -0
  49. package/src/commands/common/getDefaultExportFromFile.ts +13 -0
  50. package/src/commands/common/getFirstLineNumber.test.ts +274 -0
  51. package/src/commands/common/getFirstLineNumber.ts +146 -0
  52. package/src/commands/common/sendMessageToClient.ts +8 -0
  53. package/src/commands/common/utils/fileUtils.ts +25 -0
  54. package/src/commands/common/utils/settings.ts +23 -0
  55. package/src/commands/common/utils/webTemplate.ts +46 -0
  56. package/src/commands/testing/saveVisibleHtml.ts +29 -0
  57. package/src/commands/ts-check.ts +88 -0
  58. package/src/common/Logger/Logger/index.ts +64 -0
  59. package/src/common/Logger/Logger/types.ts +9 -0
  60. package/src/common/Logger/index.ts +64 -0
  61. package/src/common/Logger/types.ts +9 -0
  62. package/src/common/assets/browser_scripts.js +2214 -0
  63. package/src/common/asyncLocalStorage/index.ts +29 -0
  64. package/src/common/cleanEnvironmentVariables.ts +13 -0
  65. package/src/common/constants.ts +1 -0
  66. package/src/common/contextStorageStateHelpers.ts +71 -0
  67. package/src/common/getPlaywrightConstructs.ts +283 -0
  68. package/src/common/jwtTokenManager.ts +111 -0
  69. package/src/common/settingsSchema.ts +16 -0
  70. package/src/common/telemetry.ts +49 -0
  71. package/src/index.ts +14 -0
  72. package/src/runtime/RunError.ts +16 -0
  73. package/src/runtime/downloadDirectory.ts +14 -0
  74. package/src/runtime/enums.d.ts +11 -0
  75. package/src/runtime/enums.ts +11 -0
  76. package/src/runtime/executionHelpers.test.ts +70 -0
  77. package/src/runtime/export.d.ts +202 -0
  78. package/src/runtime/extendPayload.ts +22 -0
  79. package/src/runtime/extendTimeout.ts +32 -0
  80. package/src/runtime/index.ts +8 -0
  81. package/src/runtime/requestMoreInfo.ts +40 -0
  82. package/src/runtime/runInfo.ts +19 -0
  83. package/template.tsconfig.json +14 -0
  84. package/tsconfig.eslint.json +5 -0
  85. package/tsconfig.json +24 -0
  86. package/typedoc.json +49 -0
  87. package/vite.config.ts +17 -0
@@ -0,0 +1,70 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ getExecutionContext,
4
+ runWithContext,
5
+ } from "../common/asyncLocalStorage";
6
+ import { RunError, extendPayload, runInfo } from "./index";
7
+ import { RunEnvironment, RunType } from "./enums";
8
+
9
+ describe("Execution Helpers", () => {
10
+ it("should be able to get execution info", () => {
11
+ runWithContext(
12
+ {
13
+ runEnvironment: RunEnvironment.IDE,
14
+ // runType: RunType.SYNC,
15
+ runId: "test-run-id",
16
+ extendedPayloads: [],
17
+ },
18
+ () => {
19
+ expect(runInfo().runId).toEqual("test-run-id");
20
+ }
21
+ );
22
+ });
23
+
24
+ it("should be able to mutate extendedPayloads and get the accmulated value at the end ", () => {
25
+ const context = {
26
+ extendedPayloads: [],
27
+ runId: "test-run-id",
28
+ };
29
+
30
+ runWithContext(
31
+ {
32
+ runEnvironment: RunEnvironment.IDE,
33
+ // runType: RunType.SYNC,
34
+ runId: "test-run-id",
35
+ extendedPayloads: [],
36
+ },
37
+ () => {
38
+ expect(getExecutionContext()?.extendedPayloads).toEqual([]);
39
+ extendPayload({
40
+ api: "test-api",
41
+ parameters: {},
42
+ });
43
+
44
+ expect(getExecutionContext()?.extendedPayloads).toEqual([
45
+ {
46
+ api: "test-api",
47
+ parameters: {},
48
+ },
49
+ ]);
50
+
51
+ extendPayload({
52
+ api: "test-api",
53
+ parameters: {},
54
+ });
55
+ extendPayload({
56
+ api: "test-api",
57
+ parameters: {},
58
+ });
59
+ extendPayload({
60
+ api: "test-api",
61
+ parameters: {},
62
+ });
63
+
64
+ const context = getExecutionContext();
65
+
66
+ expect(context?.extendedPayloads).toHaveLength(4);
67
+ }
68
+ );
69
+ });
70
+ });
@@ -0,0 +1,202 @@
1
+ import { RunEnvironment } from "./enums";
2
+
3
+ /**
4
+ * ## Description
5
+ * In the context of a job, extendTimeout will increase the timeout of the currently executing payload.
6
+ * This is useful when the payload is expected to take a long time. For example, when running pagination code.
7
+ *
8
+ * @example
9
+ * ```typescript Example
10
+ * import { extendTimeout } from "@intuned/sdk/runtime"
11
+ *
12
+ * extendTimeout();
13
+ * ```
14
+ *
15
+ */
16
+ export declare function extendTimeout(): void;
17
+
18
+ /**
19
+ * ## Description
20
+ * In the context of a job or queue execution, extendPayload appends new payloads to the end of the queue of job.
21
+ * Calling extendPayload will also call extendTimeout.
22
+ *
23
+ * @param {Payload | Payload[]} payload - The payload or array of payloads to extend. you can specify the api name and what parameters you want to pass it, the new added apis will use the same proxy and auth-session settings as the api that extended them
24
+ *
25
+ * @example
26
+ * ```typescript Single payload
27
+ * import { extendPayload } from "@intuned/sdk/runtime"
28
+ *
29
+ * // this function will append the exampleApi to the end of the queue or job it's executing in.
30
+ * extendPayload({ api: 'exampleApi', parameters: { key: 'value' } });
31
+ * ```
32
+ *
33
+ * @example
34
+ * ```typescript Array of payloads
35
+ * import { extendPayload } from "@intuned/sdk/runtime"
36
+ *
37
+ * const payloadArray: Payload[] = [
38
+ * { api: 'exampleApi1', parameters: { key1: 'value1' } },
39
+ * { api: 'exampleApi2', parameters: { key2: 'value2' } }
40
+ * ];
41
+ *
42
+ * // this function will append 2 apis to the end of the queue or job it's executing in.
43
+ * extendPayload(payloadArray);
44
+ * ```
45
+ */
46
+ export declare function extendPayload(payload: Payload | Payload[]): void;
47
+
48
+ /**
49
+ * @interface Payload
50
+ * @property {string} api - The API path you want to extend.
51
+ * @property {Record<string, any>} parameters - A record of key-value pairs representing the parameters to be sent to the API
52
+ *
53
+ * @example
54
+ *
55
+ * ```typescript payload
56
+ * import { Payload } from "@intuned/sdk/runtime"
57
+ *
58
+ * const payload: Payload = {
59
+ * api: 'exampleApi',
60
+ * parameters: {
61
+ * key1: 'value1',
62
+ * key2: 'value2'
63
+ * }
64
+ * };
65
+ * ```
66
+ */
67
+ export interface Payload {
68
+ api: string;
69
+ parameters: Record<string, any>;
70
+ }
71
+
72
+ /**
73
+ * Retrieves information about the current run environment.
74
+ *
75
+ * @returns {RunInfo} An object containing details about the run environment and the run ID.
76
+ *
77
+ * @example
78
+ * ```typescript runInfo
79
+ * import { runInfo } from "@intuned/sdk/runtime"
80
+ *
81
+ * const info = runInfo();
82
+ * console.log(info.runEnvironment); // Outputs the run environment, IDE or DEPLOYED
83
+ * console.log(info.runId); // Outputs the run ID, if available, in IDE run id will be undefined
84
+ * ```
85
+ */
86
+ export declare function runInfo(): RunInfo;
87
+
88
+ /**
89
+ * Represents information about the current run.
90
+ *
91
+ * @interface RunInfo
92
+ * @property {RunEnvironment} runEnvironment - the run environment `IDE` or `DEPLOYED`
93
+ * @property {string} [runId] - Optional. The ID of the current run, in IDE environment, run id will be undefined
94
+ */
95
+ export interface RunInfo {
96
+ runEnvironment: RunEnvironment;
97
+ runId?: string;
98
+ jobId?: string;
99
+ jobRunId?: string;
100
+ queueId?: string;
101
+ proxy?: string;
102
+ }
103
+
104
+ /**
105
+ * @interface RunErrorOptions
106
+ * @property {boolean} [retryable] - Optional. Indicates whether the error is retryable.
107
+ * @property {number} [status_code] - Optional. The HTTP status code associated with the error.
108
+ * @property {string} [error_code] - Optional. A specific error code to identify the type of error.
109
+ *
110
+ * @example
111
+ * ```typescript RunErrorOptions
112
+ * import { RunErrorOptions } from "@intuned/sdk/runtime"
113
+ *
114
+ * const options: RunErrorOptions = {
115
+ * retryable: true,
116
+ * status_code: 500,
117
+ * error_code: 'SERVER_ERROR'
118
+ * };
119
+ * ```
120
+ */
121
+ export interface RunErrorOptions {
122
+ retryable?: boolean;
123
+ status_code?: number;
124
+ error_code?: string;
125
+ }
126
+
127
+ /**
128
+ * Represents an error that occurs during a run.
129
+ *
130
+ * @class
131
+ * @extends Error
132
+ *
133
+ * @param {string} message - The error message.
134
+ * @param {RunErrorOptions} [options] - Optional. Additional options for the error.
135
+ *
136
+ * @property {RunErrorOptions} options - The options associated with the error.
137
+ *
138
+ * @example
139
+ * ```typescript RunError
140
+ * import { RunError } from "@intuned/sdk/runtime"
141
+ *
142
+ * throw new RunError('An error occurred', {
143
+ * retryable: true,
144
+ * status_code: 500,
145
+ * error_code: 'SERVER_ERROR'
146
+ * });
147
+ *
148
+ * ```
149
+ */
150
+ export declare class RunError extends Error {
151
+ constructor(message: string, options?: RunErrorOptions);
152
+ options: RunErrorOptions;
153
+ }
154
+
155
+ /**
156
+ * in the create auth session flow, you might to need a multiple choice answer from the user, requestMultipleChoice prompts the user with the question and possible options and returns their selection.
157
+ *
158
+ * **Note:** This function is currently in beta and may be subject to changes.
159
+ *
160
+ * @param {string} message - The message to display to the user.
161
+ * @param {string[]} choices - An array of choices to present to the user.
162
+ *
163
+ * @example
164
+ * ```typescript requestMultipleChoice
165
+ * // in auth-sessions/create.ts
166
+ *
167
+ * import { requestMultipleChoice } from "@intuned/sdk/runtime"
168
+ *
169
+ * const message = "What is your favorite color?";
170
+ * const choices = ["Red", "Blue", "Green", "Yellow"];
171
+ *
172
+ * const selectedChoice = yield requestMultipleChoice(message, choices);
173
+ *
174
+ * console.log(selectedChoice);
175
+ * ```
176
+ */
177
+ export declare function requestMultipleChoice(
178
+ message: string,
179
+ choices: string[]
180
+ ): unknown;
181
+
182
+ /**
183
+ * **Note:** This function is currently in beta and may be subject to changes.
184
+ *
185
+ * requestOTP help you to ask the user for an otp in the create auth-session flow.
186
+ *
187
+ * @param {string} message - The message to display to the user.
188
+ *
189
+ * @example
190
+ * ```typescript requestOTP
191
+ * // in auth-sessions/create.ts
192
+ *
193
+ * import { requestOTP } from "@intuned/sdk/runtime"
194
+ *
195
+ * const message = "please submit and OTP from your authenticator app";
196
+ *
197
+ * const otp = yield requestOTP(message);
198
+ *
199
+ * console.log(otp);
200
+ * ```
201
+ */
202
+ export declare function requestOTP(message: string): unknown;
@@ -0,0 +1,22 @@
1
+ import { getExecutionContext } from "../common/asyncLocalStorage";
2
+ import { Payload } from "./export";
3
+ import { extendTimeout } from "./extendTimeout";
4
+
5
+ export function extendPayload(payload: Payload | Payload[]) {
6
+ const context = getExecutionContext();
7
+
8
+ if (!context) {
9
+ throw new Error("extendPayload failed due to an internal error.");
10
+ }
11
+
12
+ const items = Array.isArray(payload) ? payload : [payload];
13
+
14
+ if (!context.extendedPayloads) {
15
+ context.extendedPayloads = [...items];
16
+ return;
17
+ }
18
+
19
+ context?.extendedPayloads.push(...items);
20
+
21
+ extendTimeout();
22
+ }
@@ -0,0 +1,32 @@
1
+ import { getExecutionContext } from "../common/asyncLocalStorage";
2
+
3
+ const _DEBOUNCE_TIME = 60_000;
4
+
5
+ export function extendTimeout() {
6
+ const context = getExecutionContext();
7
+
8
+ if (!context) {
9
+ throw new Error("extendTimeout failed due to an internal error.");
10
+ }
11
+
12
+ const { timeoutInfo } = context;
13
+
14
+ if (
15
+ !timeoutInfo ||
16
+ timeoutInfo.timeoutTimestamp === undefined ||
17
+ timeoutInfo.timeoutDuration === undefined ||
18
+ timeoutInfo.extendTimeoutCallback === undefined
19
+ ) {
20
+ return;
21
+ }
22
+
23
+ const newTimeoutStamp = Date.now() + timeoutInfo.timeoutDuration;
24
+
25
+ if (newTimeoutStamp - timeoutInfo.timeoutTimestamp < _DEBOUNCE_TIME) {
26
+ return;
27
+ }
28
+
29
+ timeoutInfo.timeoutTimestamp = newTimeoutStamp;
30
+
31
+ void timeoutInfo.extendTimeoutCallback().catch(() => undefined);
32
+ }
@@ -0,0 +1,8 @@
1
+ export { extendPayload } from "./extendPayload";
2
+ export { extendTimeout } from "./extendTimeout";
3
+ export { runInfo } from "./runInfo";
4
+ export { RunError } from "./RunError";
5
+
6
+ export { requestMultipleChoice, requestOTP } from "./requestMoreInfo";
7
+
8
+ export {getDownloadDirectoryPath} from "./downloadDirectory";
@@ -0,0 +1,40 @@
1
+ interface RequestMoreInfoReturnTypeBase {
2
+ [REQUEST_MORE_INFO_KEY]: true;
3
+ action: "request_more_info";
4
+ }
5
+
6
+ interface RequestMultipleChoiceReturnType
7
+ extends RequestMoreInfoReturnTypeBase {
8
+ messageToUser: string;
9
+ choices: string[];
10
+ requestType: "multiple_choice";
11
+ }
12
+
13
+ interface RequestOtpReturnType extends RequestMoreInfoReturnTypeBase {
14
+ messageToUser: string;
15
+ requestType: "otp";
16
+ }
17
+
18
+ const REQUEST_MORE_INFO_KEY: unique symbol = Symbol("REQUEST_MORE_INFO");
19
+
20
+ export function requestOTP(messageToUser: string): RequestOtpReturnType {
21
+ return {
22
+ [REQUEST_MORE_INFO_KEY]: true,
23
+ action: "request_more_info",
24
+ messageToUser,
25
+ requestType: "otp",
26
+ };
27
+ }
28
+
29
+ export function requestMultipleChoice(
30
+ messageToUser: string,
31
+ choices: string[]
32
+ ): RequestMultipleChoiceReturnType {
33
+ return {
34
+ [REQUEST_MORE_INFO_KEY]: true,
35
+ action: "request_more_info",
36
+ messageToUser,
37
+ requestType: "multiple_choice",
38
+ choices,
39
+ };
40
+ }
@@ -0,0 +1,19 @@
1
+ import { getExecutionContext } from "../common/asyncLocalStorage";
2
+ import { RunInfo } from "./export";
3
+ import { RunType, RunEnvironment } from "./enums";
4
+
5
+ export function runInfo(): RunInfo {
6
+ const context = getExecutionContext();
7
+
8
+ if (!context) {
9
+ return {
10
+ runEnvironment: RunEnvironment.IDE,
11
+ // runType: RunType.SYNC,
12
+ };
13
+ }
14
+
15
+ //remove extendedPayloads from the user exposed data
16
+ const { extendedPayloads: _extendedPayloads, ...rest } = context;
17
+
18
+ return rest;
19
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "ESNext",
4
+ "target": "ES2021",
5
+ "lib": [
6
+ "dom",
7
+ "es2021"
8
+ ],
9
+ "resolveJsonModule": true,
10
+ "esModuleInterop": true,
11
+ "moduleResolution": "node",
12
+ "skipLibCheck": true
13
+ }
14
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "include": ["**/*.ts", "**/*.d.ts"],
4
+ "exclude": ["node_modules"]
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2021",
4
+ "module": "esnext",
5
+ "esModuleInterop": true,
6
+ "moduleResolution": "bundler",
7
+ "resolveJsonModule": true,
8
+ "outDir": "./dist",
9
+ "strict": false,
10
+ "strictNullChecks": true,
11
+ "rootDir": "./src",
12
+ "sourceMap": false,
13
+ "declaration": true,
14
+ "emitDeclarationOnly": false,
15
+ "skipLibCheck": true
16
+ },
17
+ "include": [
18
+ "src/**/*.ts",
19
+ "src/**/*.d.ts",
20
+ "types-package/noEmpty.ts",
21
+ "src/assets/**/*"
22
+ ],
23
+ "exclude": ["node_modules", "**/*.test.ts", "**/__tests__/*"]
24
+ }
package/typedoc.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ // base config
3
+ "out": "docs/content",
4
+ "tsconfig": "./types-package/tsconfig.json",
5
+ "entryPoints": ["./types-package/ai-extractors/index.d.ts"],
6
+
7
+ // specific inclusions and exclusions
8
+ // "excludeProtected": true,
9
+ // "excludeNotDocumented": true,
10
+
11
+ "exclude": [
12
+ "./src.ts/_admin/**/*",
13
+ "./src.ts/_tests/**/*",
14
+ "./src.ts/testcases/**/*"
15
+ ],
16
+
17
+ // plugins
18
+ "plugin": [
19
+ // "./plugins/reorderSections.mjs",
20
+ "typedoc-plugin-remove-references", // remove additional references that clutter documentation
21
+ "typedoc-plugin-markdown", // generate markdown files
22
+ "typedoc-plugin-frontmatter", // add frontmatter to markdown files, prereq for the below custom plugin
23
+ "./docs/plugins/typedoc-plugin-mintlify-frontmatter.mjs", // formats frontmatter to match mintlify
24
+ "./docs/plugins/typedoc-plugin-navigation-output.mjs" // formats navigation to match mintlify
25
+ ],
26
+
27
+ // formatting + mintlify compatibility
28
+ "fileExtension": ".mdx", // use mdx files for mintlfiy compatibility
29
+ "entryFileName": "index.mdx", // rename entry from "README.md" to "index.mdx"
30
+ "hidePageHeader": true, // hide page header, conflicts with mintlify
31
+ "hidePageTitle": true, // hide page title, conflicts with mintlify
32
+ "hideBreadcrumbs": true, // hide breadcrumbs, conflicts with mintlify
33
+ "useCodeBlocks": true, // makes API definitions more readable
34
+
35
+ "expandObjects": false,
36
+ // "parametersFormat": "table", // readability
37
+ // "propertiesFormat": "table", // readability
38
+ "navigation": {
39
+ "includeCategories": true,
40
+ "includeGroups": false
41
+ },
42
+ "disableSources": true,
43
+ "hideParameterTypesInTitle": false,
44
+ // "membersWithOwnFile": ["Class", "Enum", "Interface", "Function"],
45
+ // "hideParameterTypesInTitle": true,
46
+ "readme": "none",
47
+ "githubPages": false,
48
+ "excludeExternals": true
49
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from "vite";
2
+ import macros from "vite-plugin-babel-macros"
3
+ require('dotenv').config();
4
+
5
+ export default defineConfig({
6
+ test: {
7
+ reporters: ['verbose', "html"],
8
+ outputFile: { html: './reports/html/index.html' },
9
+ testTimeout: 30000,
10
+ env: {
11
+ RUN_ENVIRONMENT: "AUTHORING",
12
+ }
13
+ },
14
+ plugins: [
15
+ macros(),
16
+ ],
17
+ });