@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
@@ -4,13 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- runApiGenerator: true,
8
7
  runApi: true,
9
8
  checkAuthSessionWithRetries: true
10
9
  };
11
10
  exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
12
11
  exports.runApi = runApi;
13
- exports.runApiGenerator = runApiGenerator;
14
12
  var _downloadDirectory = require("../../runtime/downloadDirectory");
15
13
  var _asyncLocalStorage = require("../asyncLocalStorage");
16
14
  var _fsExtra = _interopRequireWildcard(require("fs-extra"));
@@ -30,7 +28,7 @@ Object.keys(_errors).forEach(function (key) {
30
28
  });
31
29
  });
32
30
  var _constants = require("../constants");
33
- var _getPlaywrightConstructs = require("../getPlaywrightConstructs");
31
+ var _playwrightContext = require("../playwrightContext");
34
32
  var _types = require("./types");
35
33
  Object.keys(_types).forEach(function (key) {
36
34
  if (key === "default" || key === "__esModule") return;
@@ -45,6 +43,7 @@ Object.keys(_types).forEach(function (key) {
45
43
  });
46
44
  var _formatZodError = require("../formatZodError");
47
45
  var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
46
+ var _importUsingImportFunction = require("./importUsingImportFunction");
48
47
  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); }
49
48
  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; }
50
49
  function getObjectSizeInBytes(obj) {
@@ -54,10 +53,10 @@ function getObjectSizeInBytes(obj) {
54
53
  return new TextEncoder().encode(String(obj)).length;
55
54
  }
56
55
  }
57
- async function* runApiGenerator({
58
- retrieveSession = false,
56
+ async function runApi({
59
57
  abortSignal,
60
58
  importFunction,
59
+ retrieveSession = false,
61
60
  ...input
62
61
  }) {
63
62
  let traceStarted = false;
@@ -66,7 +65,10 @@ async function* runApiGenerator({
66
65
  return (0, _neverthrow.err)(new _errors.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
67
66
  }
68
67
  const {
69
- automationFunction,
68
+ automationFunction: {
69
+ name,
70
+ params
71
+ },
70
72
  runOptions,
71
73
  tracing,
72
74
  auth
@@ -78,166 +80,108 @@ async function* runApiGenerator({
78
80
  resolve(abortSymbol);
79
81
  });
80
82
  });
81
- let context;
82
- let downloadsPath;
83
- async function saveTraceIfNeeded({
84
- errorMessage
85
- }) {
86
- if (!tracing.enabled || !traceStarted) {
87
- return;
88
- }
89
- try {
90
- await context?.tracing.stop({
91
- path: tracing.filePath
92
- });
93
- } catch (error) {
94
- console.log(errorMessage, error?.message);
95
- await (0, _fsExtra.remove)(tracing.filePath);
96
- }
97
- }
98
- async function* runAutomation() {
99
- let page;
100
- const validatedModuleResult = await importUsingImportFunction(automationFunction.name, importFunction);
83
+ async function runAutomation() {
84
+ const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
85
+ path: name,
86
+ importFunction
87
+ });
101
88
  if (validatedModuleResult.isErr()) {
102
89
  return (0, _neverthrow.err)(validatedModuleResult.error);
103
90
  }
104
- const importedModule = validatedModuleResult.value;
105
- let checkFn;
106
- if (auth?.runCheck) {
107
- if (!auth.session) {
108
- return (0, _neverthrow.err)(new _errors.AuthRequiredError());
109
- }
110
- const checkImportResult = await importUsingImportFunction(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`, importFunction);
111
- if (checkImportResult.isErr()) {
112
- return (0, _neverthrow.err)(checkImportResult.error);
113
- }
114
- if (checkImportResult.value.type !== "async") {
115
- return (0, _neverthrow.err)(new _errors.InvalidCheckError("Check function is not an async function"));
116
- }
117
- checkFn = checkImportResult.value.func;
118
- }
91
+ const automationFunction = validatedModuleResult.value;
119
92
  if (auth && auth.session.type === "state") {
120
93
  const state = auth.session.state;
121
94
  if (state === undefined || state === null) {
122
95
  return (0, _neverthrow.err)(new _errors.AuthRequiredError());
123
96
  }
124
97
  }
125
- if (runOptions.environment === "standalone") {
126
- downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
127
- const {
128
- headless,
129
- proxy
130
- } = runOptions;
131
- ({
132
- page,
133
- context
134
- } = await (0, _getPlaywrightConstructs.getProductionPlaywrightConstructs)({
135
- headless,
136
- proxy,
137
- downloadsPath,
138
- storageState: auth?.session
139
- }));
140
- } else {
141
- const {
142
- mode,
143
- cdpAddress
144
- } = runOptions;
145
- ({
146
- page,
147
- context
148
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth?.session));
149
- }
150
- if (tracing.enabled) {
151
- await context.tracing.start({
152
- screenshots: true,
153
- snapshots: true,
154
- sources: true
155
- });
156
- traceStarted = true;
157
- }
158
- (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
159
- if (checkFn !== undefined) {
160
- try {
161
- console.log("Running auth check");
162
- const authCheckResult = await checkAuthSessionWithRetries(page, context, checkFn, 2);
163
- if (authCheckResult.isErr()) {
164
- const error = authCheckResult.error;
165
- if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
166
- return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed`, error));
167
- }
168
- return authCheckResult;
98
+ const playwrightContextParameters = {
99
+ apiName: name,
100
+ apiParameters: params,
101
+ importFunction
102
+ };
103
+ const runAutomationWithContext = async (context, page) => {
104
+ async function saveTraceIfNeeded({
105
+ errorMessage
106
+ }) {
107
+ if (!tracing.enabled || !traceStarted) {
108
+ return;
169
109
  }
170
- if (!authCheckResult.value) {
171
- return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
110
+ try {
111
+ await context?.tracing.stop({
112
+ path: tracing.filePath
113
+ });
114
+ } catch (error) {
115
+ console.log(errorMessage, error?.message);
116
+ await (0, _fsExtra.remove)(tracing.filePath);
172
117
  }
173
- } catch (error) {
174
- return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
175
118
  }
176
- }
177
- const automationFunctionParameters = [...(automationFunction.params !== undefined ? [automationFunction.params] : []), page, context];
178
- let result;
179
- if (importedModule.type === "async-generator") {
180
- const generator = importedModule.generator(...automationFunctionParameters);
181
- let next = undefined;
182
- while (true) {
183
- const generatorResult = await generator.next(...(next ? [next] : []));
184
- if (!generatorResult.done) {
185
- next = yield generatorResult.value;
186
- continue;
187
- }
188
- result = generatorResult.value;
189
- break;
119
+ if (auth) {
120
+ await (0, _playwrightContext.loadSessionToContext)({
121
+ context,
122
+ session: auth.session
123
+ });
190
124
  }
191
- } else {
192
- result = await importedModule.func(...automationFunctionParameters);
193
- }
194
- const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
195
- const resultSizeInBytes = getObjectSizeInBytes(result);
196
- if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
197
- return (0, _neverthrow.err)(new _errors.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
198
- }
199
- return (0, _neverthrow.ok)({
200
- result,
201
- extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
202
- session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
203
- });
204
- }
205
- try {
206
- const generator = runAutomation();
207
- let next = undefined;
208
- while (true) {
209
- const result = await Promise.race([generator.next(await next), abortPromise]);
210
- if (result === abortSymbol) {
211
- return (0, _neverthrow.err)(new _errors.AbortedError());
125
+ const scriptContent = await fs.readFile(_playwrightContext.browserScriptsFile, "utf-8");
126
+ await context.addInitScript({
127
+ content: scriptContent
128
+ });
129
+ for (const page of context.pages()) {
130
+ await page.evaluate(scriptContent);
212
131
  }
213
- if (!result.done) {
214
- next = yield result.value;
215
- continue;
132
+ if (tracing.enabled) {
133
+ await context.tracing.start({
134
+ screenshots: true,
135
+ snapshots: true,
136
+ sources: true
137
+ });
138
+ traceStarted = true;
216
139
  }
217
- return result.value;
218
- }
219
- } catch (error) {
220
- return (0, _neverthrow.err)(new _errors.AutomationError(error));
221
- } finally {
222
- await saveTraceIfNeeded({
223
- errorMessage: "failed to save trace"
224
- });
225
- await context?.close();
226
- if (downloadsPath !== undefined) {
227
- await fs.remove(downloadsPath);
140
+ (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
141
+ const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
142
+ const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
143
+ const resultSizeInBytes = getObjectSizeInBytes(result);
144
+ if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
145
+ return (0, _neverthrow.err)(new _errors.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
146
+ }
147
+ try {
148
+ return (0, _neverthrow.ok)({
149
+ result: await automationFunction(...automationFunctionParameters),
150
+ extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
151
+ session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
152
+ });
153
+ } catch (error) {
154
+ return (0, _neverthrow.err)(new _errors.AutomationError(error));
155
+ } finally {
156
+ await saveTraceIfNeeded({
157
+ errorMessage: "failed to save trace"
158
+ });
159
+ }
160
+ };
161
+ if (runOptions.environment === "standalone") {
162
+ const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
163
+ try {
164
+ return await (0, _playwrightContext.withPlaywrightContext)({
165
+ headless: runOptions.headless,
166
+ proxy: runOptions.proxy,
167
+ downloadsPath,
168
+ ...playwrightContextParameters
169
+ }, runAutomationWithContext);
170
+ } finally {
171
+ await fs.remove(downloadsPath);
172
+ }
173
+ } else {
174
+ return await (0, _playwrightContext.withPlaywrightContext)({
175
+ cdpAddress: runOptions.cdpAddress,
176
+ ...playwrightContextParameters
177
+ }, runAutomationWithContext);
228
178
  }
229
179
  }
230
- }
231
- async function runApi(params) {
232
- const generator = runApiGenerator(params);
233
- const {
234
- value,
235
- done
236
- } = await generator.next();
237
- if (done) {
238
- return value;
180
+ const result = await Promise.race([await runAutomation(), abortPromise]);
181
+ if (result === abortSymbol) {
182
+ return (0, _neverthrow.err)(new _errors.AbortedError());
239
183
  }
240
- return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
184
+ return result;
241
185
  }
242
186
  async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
243
187
  if (retries === 0) {
@@ -251,34 +195,4 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
251
195
  tryNumber++;
252
196
  }
253
197
  return (0, _neverthrow.ok)(false);
254
- }
255
- async function importUsingImportFunction(path, importFunction) {
256
- try {
257
- const importedResult = await importFunction(path);
258
- if (importedResult.isErr()) {
259
- if (importedResult.error.type === "not_found") {
260
- return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
261
- }
262
- return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
263
- }
264
- const imported = importedResult.value;
265
- if (!imported || !imported.default || !imported.default.constructor) {
266
- return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
267
- }
268
- if (imported.default.constructor.name === "AsyncGeneratorFunction") {
269
- return (0, _neverthrow.ok)({
270
- type: "async-generator",
271
- generator: imported.default
272
- });
273
- }
274
- if (imported.default.constructor.name === "AsyncFunction") {
275
- return (0, _neverthrow.ok)({
276
- type: "async",
277
- func: imported.default
278
- });
279
- }
280
- return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
281
- } catch (error) {
282
- return (0, _neverthrow.err)(new _errors.AutomationError(error));
283
- }
284
198
  }
@@ -580,7 +580,6 @@ export declare const runApiParametersSchema: z.ZodObject<{
580
580
  }[] | undefined;
581
581
  } | null | undefined;
582
582
  }>]>;
583
- runCheck: z.ZodDefault<z.ZodBoolean>;
584
583
  }, "strip", z.ZodTypeAny, {
585
584
  session: {
586
585
  path: string;
@@ -614,7 +613,6 @@ export declare const runApiParametersSchema: z.ZodObject<{
614
613
  }[] | undefined;
615
614
  } | null | undefined;
616
615
  };
617
- runCheck: boolean;
618
616
  }, {
619
617
  session: {
620
618
  path: string;
@@ -648,7 +646,6 @@ export declare const runApiParametersSchema: z.ZodObject<{
648
646
  }[] | undefined;
649
647
  } | null | undefined;
650
648
  };
651
- runCheck?: boolean | undefined;
652
649
  }>>;
653
650
  runOptions: z.ZodDefault<z.ZodDiscriminatedUnion<"environment", [z.ZodObject<{
654
651
  environment: z.ZodLiteral<"standalone">;
@@ -676,12 +673,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
676
673
  } | undefined;
677
674
  }, {
678
675
  environment: "standalone";
679
- headless?: boolean | undefined;
680
676
  proxy?: {
681
677
  server: string;
682
678
  username: string;
683
679
  password: string;
684
680
  } | undefined;
681
+ headless?: boolean | undefined;
685
682
  }>, z.ZodObject<{
686
683
  environment: z.ZodLiteral<"cdp">;
687
684
  cdpAddress: z.ZodString;
@@ -754,7 +751,6 @@ export declare const runApiParametersSchema: z.ZodObject<{
754
751
  }[] | undefined;
755
752
  } | null | undefined;
756
753
  };
757
- runCheck: boolean;
758
754
  } | undefined;
759
755
  }, {
760
756
  automationFunction: {
@@ -800,16 +796,15 @@ export declare const runApiParametersSchema: z.ZodObject<{
800
796
  }[] | undefined;
801
797
  } | null | undefined;
802
798
  };
803
- runCheck?: boolean | undefined;
804
799
  } | undefined;
805
800
  runOptions?: {
806
801
  environment: "standalone";
807
- headless?: boolean | undefined;
808
802
  proxy?: {
809
803
  server: string;
810
804
  username: string;
811
805
  password: string;
812
806
  } | undefined;
807
+ headless?: boolean | undefined;
813
808
  } | {
814
809
  mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
815
810
  environment: "cdp";
@@ -837,3 +832,4 @@ export type RunApiResultWithSessionOk<R = any> = RunApiResultOk<R> & {
837
832
  session: RunApiStorageState;
838
833
  };
839
834
  export type RunApiResult<R = any, FullResult extends RunApiResultOk<R> = RunApiResultOk<R>> = Result<FullResult, RunAutomationError>;
835
+ export type { ImportFunction } from "./importUsingImportFunction";
@@ -53,8 +53,7 @@ const runApiParametersSchema = exports.runApiParametersSchema = _zod.default.obj
53
53
  enabled: false
54
54
  }),
55
55
  auth: _zod.default.object({
56
- session: runApiSessionSchema,
57
- runCheck: _zod.default.boolean().default(false)
56
+ session: runApiSessionSchema
58
57
  }).optional(),
59
58
  runOptions: _zod.default.discriminatedUnion("environment", [_zod.default.object({
60
59
  environment: _zod.default.literal("standalone"),
@@ -0,0 +1,17 @@
1
+ import type * as playwright from "playwright";
2
+ import { type RunAutomationError } from "./runApi/errors";
3
+ import { type Err, type Ok } from "neverthrow";
4
+ import { type ImportFunction } from "./runApi/importUsingImportFunction";
5
+ export type InitializeContextHookOptions = {
6
+ apiName: string;
7
+ apiParameters: any;
8
+ cdpUrl: string;
9
+ };
10
+ export type SetupContextHook = (options: InitializeContextHookOptions) => Promise<{
11
+ page: playwright.Page | null;
12
+ context: playwright.BrowserContext;
13
+ cleanup?: () => Promise<void>;
14
+ } | null>;
15
+ export declare function loadSetupContextHook({ importFunction, }: {
16
+ importFunction: ImportFunction;
17
+ }): Promise<Ok<SetupContextHook | null, any> | Err<any, RunAutomationError>>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadSetupContextHook = loadSetupContextHook;
7
+ var _errors = require("./runApi/errors");
8
+ var _neverthrow = require("neverthrow");
9
+ var _importUsingImportFunction = require("./runApi/importUsingImportFunction");
10
+ const setupContextHookPath = "hooks/setupContext";
11
+ async function loadSetupContextHook({
12
+ importFunction
13
+ }) {
14
+ const importedFunctionResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
15
+ path: setupContextHookPath,
16
+ importFunction
17
+ });
18
+ if (importedFunctionResult.isErr() && importedFunctionResult.error instanceof _errors.ApiNotFoundError) {
19
+ return (0, _neverthrow.ok)(null);
20
+ }
21
+ return importedFunctionResult;
22
+ }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, getAuthSessionParameters, } from "./runtime";
1
+ export { extendPayload, extendTimeout, runInfo, RunError, getAuthSessionParameters, attemptStore, } from "./runtime";
2
2
  export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
3
3
  export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
4
- export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
4
+ export { withPlaywrightContext } from "./common/playwrightContext";
package/dist/index.js CHANGED
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "RunError", {
9
9
  return _runtime.RunError;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "attemptStore", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _runtime.attemptStore;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "extendPayload", {
13
19
  enumerable: true,
14
20
  get: function () {
@@ -39,24 +45,6 @@ Object.defineProperty(exports, "getExecutionContext", {
39
45
  return _asyncLocalStorage.getExecutionContext;
40
46
  }
41
47
  });
42
- Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
43
- enumerable: true,
44
- get: function () {
45
- return _getPlaywrightConstructs.getProductionPlaywrightConstructs;
46
- }
47
- });
48
- Object.defineProperty(exports, "requestMultipleChoice", {
49
- enumerable: true,
50
- get: function () {
51
- return _runtime.requestMultipleChoice;
52
- }
53
- });
54
- Object.defineProperty(exports, "requestOTP", {
55
- enumerable: true,
56
- get: function () {
57
- return _runtime.requestOTP;
58
- }
59
- });
60
48
  Object.defineProperty(exports, "runInfo", {
61
49
  enumerable: true,
62
50
  get: function () {
@@ -69,7 +57,13 @@ Object.defineProperty(exports, "runWithContext", {
69
57
  return _asyncLocalStorage.runWithContext;
70
58
  }
71
59
  });
60
+ Object.defineProperty(exports, "withPlaywrightContext", {
61
+ enumerable: true,
62
+ get: function () {
63
+ return _playwrightContext.withPlaywrightContext;
64
+ }
65
+ });
72
66
  var _runtime = require("./runtime");
73
67
  var _asyncLocalStorage = require("./common/asyncLocalStorage");
74
68
  var _downloadDirectory = require("./runtime/downloadDirectory");
75
- var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs");
69
+ var _playwrightContext = require("./common/playwrightContext");
@@ -0,0 +1,2 @@
1
+ import { Store } from "./export";
2
+ export declare const attemptStore: Store;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.attemptStore = void 0;
7
+ var _asyncLocalStorage = require("../common/asyncLocalStorage");
8
+ const attemptStore = exports.attemptStore = Object.freeze({
9
+ get: key => {
10
+ const context = (0, _asyncLocalStorage.getExecutionContext)();
11
+ return context?.store ? context.store[key] : undefined;
12
+ },
13
+ set: (key, value) => {
14
+ const context = (0, _asyncLocalStorage.getExecutionContext)();
15
+ if (!context) {
16
+ throw new Error("store.set failed due to an internal error.");
17
+ }
18
+ if (!context.store) {
19
+ context.store = {};
20
+ }
21
+ context.store[key] = value;
22
+ }
23
+ });
@@ -126,6 +126,8 @@ export interface RunErrorOptions {
126
126
  }
127
127
 
128
128
  /**
129
+ * @deprecated This error is deprecated. it will be treated like any normal error
130
+ *
129
131
  * Represents an error that occurs during a run.
130
132
  *
131
133
  * @class
@@ -154,65 +156,73 @@ export declare class RunError extends Error {
154
156
  }
155
157
 
156
158
  /**
157
- * 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.
158
- *
159
- * **Note:** This function is currently in beta and may be subject to changes.
159
+ * Retrieves the parameters for the authentication session currently being used.
160
160
  *
161
- * @param {string} message - The message to display to the user.
162
- * @param {string[]} choices - An array of choices to present to the user.
161
+ * @returns {AuthSessionParameters} An object containing the parameters for the current authentication session.
163
162
  *
164
163
  * @example
165
- * ```typescript requestMultipleChoice
166
- * // in auth-sessions/create.ts
167
- *
168
- * import { requestMultipleChoice } from "@intuned/sdk/runtime"
169
- *
170
- * const message = "What is your favorite color?";
171
- * const choices = ["Red", "Blue", "Green", "Yellow"];
172
- *
173
- * const selectedChoice = yield requestMultipleChoice(message, choices);
164
+ * ```typescript getAuthSessionParameters
165
+ * import { getAuthSessionParameters } from "@intuned/sdk/runtime"
174
166
  *
175
- * console.log(selectedChoice);
167
+ * const authSessionParams = getAuthSessionParameters();
168
+ * console.log(authSessionParams);
176
169
  * ```
177
170
  */
178
- export declare function requestMultipleChoice(
179
- message: string,
180
- choices: string[]
181
- ): unknown;
171
+ export declare function getAuthSessionParameters(): Promise<any>;
182
172
 
183
173
  /**
184
- * **Note:** This function is currently in beta and may be subject to changes.
185
- *
186
- * requestOTP help you to ask the user for an otp in the create auth-session flow.
187
- *
188
- * @param {string} message - The message to display to the user.
174
+ * @interface Store
175
+ * @property {function} get - Retrieves a value from the store by key
176
+ * @property {function} set - Sets a value in the store by key
189
177
  *
190
178
  * @example
191
- * ```typescript requestOTP
192
- * // in auth-sessions/create.ts
193
- *
194
- * import { requestOTP } from "@intuned/sdk/runtime"
179
+ * ```typescript Store usage
180
+ * import { store } from "@intuned/sdk/runtime"
195
181
  *
196
- * const message = "please submit and OTP from your authenticator app";
182
+ * // Set a value in the store
183
+ * store.set('userPreference', { theme: 'dark' });
197
184
  *
198
- * const otp = yield requestOTP(message);
199
- *
200
- * console.log(otp);
185
+ * // Get a value from the store
186
+ * const preference = store.get('userPreference');
201
187
  * ```
202
188
  */
203
- export declare function requestOTP(message: string): unknown;
189
+ export interface Store {
190
+ /**
191
+ * Retrieves a value from the store by key.
192
+ *
193
+ * @param {string} key - The key to retrieve the value for
194
+ * @returns {any} The value associated with the key, or undefined if not found
195
+ */
196
+ get(key: string): any;
197
+
198
+ /**
199
+ * Sets a value in the store by key.
200
+ *
201
+ * @param {string} key - The key to set the value for
202
+ * @param {any} value - The value to store
203
+ * @throws {Error} Throws an error if the store operation fails
204
+ */
205
+ set(key: string, value: any): void;
206
+ }
204
207
 
205
208
  /**
206
- * Retrieves the parameters for the authentication session currently being used.
207
- *
208
- * @returns {AuthSessionParameters} An object containing the parameters for the current authentication session.
209
+ * ## Description
210
+ * A persistent key-value store that maintains data within the execution context.
211
+ * This store allows you to share data between different parts of your API execution.
209
212
  *
210
213
  * @example
211
- * ```typescript getAuthSessionParameters
212
- * import { getAuthSessionParameters } from "@intuned/sdk/runtime"
214
+ * ```typescript Store usage
215
+ * import { store } from "@intuned/sdk/runtime"
213
216
  *
214
- * const authSessionParams = getAuthSessionParameters();
215
- * console.log(authSessionParams);
217
+ * // Set a value in the store
218
+ * store.set('sessionData', { userId: '123', token: 'abc' });
219
+ *
220
+ * // Get a value from the store
221
+ * const sessionData = store.get('sessionData');
222
+ * console.log(sessionData.userId); // '123'
223
+ *
224
+ * // Handle missing values
225
+ * const missingData = store.get('nonexistent'); // undefined
216
226
  * ```
217
227
  */
218
- export declare function getAuthSessionParameters(): Promise<any>;
228
+ export declare const attemptStore: Store;