@intuned/runtime-dev 0.1.0-test.1 → 0.1.0-test.11

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/.babelrc +3 -1
  2. package/Intuned.json +1 -1
  3. package/api/test2.ts +1 -4
  4. package/dist/commands/api/run.js +27 -35
  5. package/dist/commands/auth-sessions/load.js +11 -13
  6. package/dist/commands/auth-sessions/run-check.js +14 -19
  7. package/dist/commands/auth-sessions/run-create.js +23 -28
  8. package/dist/commands/browser/save-state.js +7 -10
  9. package/dist/commands/browser/start-browser.js +7 -10
  10. package/dist/commands/build.js +25 -30
  11. package/dist/commands/common/browserUtils.js +15 -28
  12. package/dist/commands/common/getDefaultExportFromFile.js +2 -10
  13. package/dist/commands/common/getFirstLineNumber.js +13 -20
  14. package/dist/commands/common/getFirstLineNumber.test.js +46 -51
  15. package/dist/commands/common/sendMessageToClient.js +2 -9
  16. package/dist/commands/common/utils/fileUtils.js +6 -16
  17. package/dist/commands/common/utils/settings.js +7 -13
  18. package/dist/commands/common/utils/unixSocket.js +2 -9
  19. package/dist/commands/common/utils/webTemplate.js +7 -16
  20. package/dist/commands/interface/run.js +34 -39
  21. package/dist/commands/ts-check.js +8 -12
  22. package/dist/common/Logger/Logger/index.js +9 -16
  23. package/dist/common/Logger/Logger/types.js +1 -5
  24. package/dist/common/Logger/index.js +9 -16
  25. package/dist/common/Logger/types.js +1 -5
  26. package/dist/common/asyncLocalStorage/index.js +4 -12
  27. package/dist/common/cleanEnvironmentVariables.js +1 -7
  28. package/dist/common/constants.js +1 -7
  29. package/dist/common/contextStorageStateHelpers.js +2 -9
  30. package/dist/common/getPlaywrightConstructs.js +28 -39
  31. package/dist/common/jwtTokenManager.js +8 -18
  32. package/dist/common/runApi/errors.js +24 -42
  33. package/dist/common/runApi/index.js +53 -88
  34. package/dist/common/runApi/types.js +31 -38
  35. package/dist/common/settingsSchema.js +2 -10
  36. package/dist/common/telemetry.js +3 -12
  37. package/dist/index.js +4 -69
  38. package/dist/runtime/RunError.js +1 -8
  39. package/dist/runtime/downloadDirectory.js +5 -11
  40. package/dist/runtime/enums.d.js +1 -5
  41. package/dist/runtime/enums.js +2 -8
  42. package/dist/runtime/executionHelpers.test.js +20 -22
  43. package/dist/runtime/export.d.js +1 -5
  44. package/dist/runtime/extendPayload.js +5 -11
  45. package/dist/runtime/extendTimeout.js +3 -9
  46. package/dist/runtime/index.js +6 -53
  47. package/dist/runtime/requestMoreInfo.js +2 -9
  48. package/dist/runtime/runInfo.js +5 -11
  49. package/package.json +3 -1
  50. package/preserve-dynamic-imports.js +16 -0
@@ -1,52 +1,17 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- runApiGenerator: true,
8
- runApi: true,
9
- checkAuthSessionWithRetries: true
10
- };
11
- exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
12
- exports.runApi = runApi;
13
- exports.runApiGenerator = runApiGenerator;
14
- var _downloadDirectory = require("../../runtime/downloadDirectory");
15
- var _asyncLocalStorage = require("../asyncLocalStorage");
16
- var _fsExtra = _interopRequireWildcard(require("fs-extra"));
17
- var fs = _fsExtra;
18
- var _jwtTokenManager = require("../jwtTokenManager");
19
- var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
20
- var _neverthrow = require("neverthrow");
21
- var _errors = require("./errors");
22
- Object.keys(_errors).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
25
- if (key in exports && exports[key] === _errors[key]) return;
26
- Object.defineProperty(exports, key, {
27
- enumerable: true,
28
- get: function () {
29
- return _errors[key];
30
- }
31
- });
32
- });
33
- var _constants = require("../constants");
34
- var _getPlaywrightConstructs = require("../getPlaywrightConstructs");
35
- var _types = require("./types");
36
- Object.keys(_types).forEach(function (key) {
37
- if (key === "default" || key === "__esModule") return;
38
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
39
- if (key in exports && exports[key] === _types[key]) return;
40
- Object.defineProperty(exports, key, {
41
- enumerable: true,
42
- get: function () {
43
- return _types[key];
44
- }
45
- });
46
- });
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); }
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 && Object.prototype.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; }
49
- async function* runApiGenerator({
1
+ import { getDownloadDirectoryPath } from "../../runtime/downloadDirectory";
2
+ import { getExecutionContext } from "../asyncLocalStorage";
3
+ import * as fs from "fs-extra";
4
+ import { backendFunctionsTokenManager } from "../jwtTokenManager";
5
+ import { getContextStorageState, setContextStorageState } from "../contextStorageStateHelpers";
6
+ import { remove } from "fs-extra";
7
+ import { ok, err } from "neverthrow";
8
+ import { AbortedError, ApiNotFoundError, AutomationError, InvalidApiError, InvalidCheckError, MaxLevelsExceededError } from "./errors";
9
+ import { AUTH_SESSIONS_FOLDER_NAME } from "../constants";
10
+ import { getPlaywrightConstructsForMode, getProductionPlaywrightConstructs } from "../getPlaywrightConstructs";
11
+ import { runApiParametersSchema } from "./types";
12
+ export * from "./types";
13
+ export * from "./errors";
14
+ export async function* runApiGenerator({
50
15
  retrieveSession = false,
51
16
  abortSignal,
52
17
  ...input
@@ -58,9 +23,9 @@ async function* runApiGenerator({
58
23
  tracing,
59
24
  auth,
60
25
  functionsToken
61
- } = _types.runApiParametersSchema.parse(input);
62
- _jwtTokenManager.backendFunctionsTokenManager.token = functionsToken;
63
- const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
26
+ } = runApiParametersSchema.parse(input);
27
+ backendFunctionsTokenManager.token = functionsToken;
28
+ const downloadsPath = getDownloadDirectoryPath();
64
29
  let page;
65
30
  let context;
66
31
  if (runOptions.environment === "deployed") {
@@ -71,7 +36,7 @@ async function* runApiGenerator({
71
36
  ({
72
37
  page,
73
38
  context
74
- } = await (0, _getPlaywrightConstructs.getProductionPlaywrightConstructs)({
39
+ } = await getProductionPlaywrightConstructs({
75
40
  headless,
76
41
  proxy,
77
42
  downloadsPath,
@@ -85,9 +50,9 @@ async function* runApiGenerator({
85
50
  ({
86
51
  page,
87
52
  context
88
- } = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
53
+ } = await getPlaywrightConstructsForMode(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
89
54
  }
90
- const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
55
+ const executionContext = getExecutionContext();
91
56
  if (!executionContext) {
92
57
  throw "";
93
58
  }
@@ -103,7 +68,7 @@ async function* runApiGenerator({
103
68
  });
104
69
  } catch (error) {
105
70
  console.log(errorMessage, error === null || error === void 0 ? void 0 : error.message);
106
- await (0, _fsExtra.remove)(tracing.filePath);
71
+ await remove(tracing.filePath);
107
72
  }
108
73
  }
109
74
  if (tracing.enabled) {
@@ -122,13 +87,13 @@ async function* runApiGenerator({
122
87
  });
123
88
  });
124
89
  if (auth && auth.session.type === "state") {
125
- await (0, _contextStorageStateHelpers.setContextStorageState)(context, auth.session.state);
90
+ await setContextStorageState(context, auth.session.state);
126
91
  }
127
92
  async function* runAutomation() {
128
93
  var _getExecutionContext;
129
94
  if (auth !== null && auth !== void 0 && auth.runCheck) {
130
95
  if (!auth.session) {
131
- return (0, _neverthrow.err)({
96
+ return err({
132
97
  code: "AuthRequiredError"
133
98
  });
134
99
  }
@@ -137,12 +102,12 @@ async function* runApiGenerator({
137
102
  if (authCheckResult.isErr()) {
138
103
  const error = authCheckResult.error;
139
104
  if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
140
- return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed`, error));
105
+ return err(new InvalidCheckError(`Auth session check function failed`, error));
141
106
  }
142
107
  return authCheckResult;
143
108
  }
144
109
  if (!authCheckResult.value) {
145
- return (0, _neverthrow.err)({
110
+ return err({
146
111
  code: "AuthCheckFailedError"
147
112
  });
148
113
  }
@@ -169,10 +134,10 @@ async function* runApiGenerator({
169
134
  } else {
170
135
  result = await importResult.value.func(...args);
171
136
  }
172
- return (0, _neverthrow.ok)({
137
+ return ok({
173
138
  result,
174
- extendedPayloads: (_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
175
- session: retrieveSession ? await (0, _contextStorageStateHelpers.getContextStorageState)(context) : undefined
139
+ extendedPayloads: (_getExecutionContext = getExecutionContext()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads,
140
+ session: retrieveSession ? await getContextStorageState(context) : undefined
176
141
  });
177
142
  }
178
143
  try {
@@ -181,7 +146,7 @@ async function* runApiGenerator({
181
146
  while (true) {
182
147
  const result = await Promise.race([generator.next(await next), abortPromise]);
183
148
  if (result === abortSymbol) {
184
- return (0, _neverthrow.err)(new _errors.AbortedError());
149
+ return err(new AbortedError());
185
150
  }
186
151
  if (!result.done) {
187
152
  next = yield result.value;
@@ -191,7 +156,7 @@ async function* runApiGenerator({
191
156
  }
192
157
  } catch (error) {
193
158
  console.log("run errored", error);
194
- return (0, _neverthrow.err)(new _errors.AutomationError(error));
159
+ return err(new AutomationError(error));
195
160
  } finally {
196
161
  await saveTraceIfNeeded({
197
162
  errorMessage: "failed to save trace"
@@ -200,7 +165,7 @@ async function* runApiGenerator({
200
165
  await fs.remove(downloadsPath);
201
166
  }
202
167
  }
203
- async function runApi(params) {
168
+ export async function runApi(params) {
204
169
  const generator = runApiGenerator(params);
205
170
  const {
206
171
  value,
@@ -209,28 +174,28 @@ async function runApi(params) {
209
174
  if (done) {
210
175
  return value;
211
176
  }
212
- return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
177
+ return err(new InvalidApiError("Expected API to be async function, got async generator"));
213
178
  }
214
- async function checkAuthSessionWithRetries(page, context, retries = 3) {
179
+ export async function checkAuthSessionWithRetries(page, context, retries = 3) {
215
180
  if (retries === 0) {
216
- return (0, _neverthrow.ok)(false);
181
+ return ok(false);
217
182
  }
218
183
  let tryNumber = 0;
219
- console.log("Checking auth session with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
220
- const importResult = await importFunction(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
184
+ console.log("Checking auth session with retries", `${AUTH_SESSIONS_FOLDER_NAME}/check`);
185
+ const importResult = await importFunction(`${AUTH_SESSIONS_FOLDER_NAME}/check`);
221
186
  if (importResult.isErr()) {
222
- return (0, _neverthrow.err)(importResult.error);
187
+ return err(importResult.error);
223
188
  }
224
189
  if (importResult.value.type !== "async") {
225
- return (0, _neverthrow.err)(new _errors.InvalidCheckError("Check function is not an async function"));
190
+ return err(new InvalidCheckError("Check function is not an async function"));
226
191
  }
227
192
  const check = importResult.value.func;
228
193
  while (retries > tryNumber) {
229
194
  const result = await check(page, context);
230
- if (result) return (0, _neverthrow.ok)(true);
195
+ if (result) return ok(true);
231
196
  tryNumber++;
232
197
  }
233
- return (0, _neverthrow.ok)(false);
198
+ return ok(false);
234
199
  }
235
200
  async function importFunction(path) {
236
201
  const functionNameParts = path.split("/");
@@ -239,49 +204,49 @@ async function importFunction(path) {
239
204
  let imported = undefined;
240
205
  switch (functionNameDepth) {
241
206
  case 1:
242
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}.ts`);
207
+ imported = await import(`../../../${functionNameParts[0]}.ts`);
243
208
  break;
244
209
  case 2:
245
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}.ts`);
210
+ imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}.ts`);
246
211
  break;
247
212
  case 3:
248
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
213
+ imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
249
214
  break;
250
215
  case 4:
251
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
216
+ imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
252
217
  break;
253
218
  case 5:
254
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
219
+ imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
255
220
  break;
256
221
  case 6:
257
- imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
222
+ imported = await import(`../../../${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
258
223
  break;
259
224
  default:
260
- return (0, _neverthrow.err)(new _errors.MaxLevelsExceededError(5));
225
+ return err(new MaxLevelsExceededError(5));
261
226
  }
262
227
  if (!imported || !imported.default || !imported.default.constructor) {
263
- return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
228
+ return err(new InvalidApiError("API file path does not have a default export"));
264
229
  }
265
230
  if (imported.default.constructor.name === "AsyncGeneratorFunction") {
266
- return (0, _neverthrow.ok)({
231
+ return ok({
267
232
  type: "async-generator",
268
233
  generator: imported.default
269
234
  });
270
235
  }
271
236
  if (imported.default.constructor.name === "AsyncFunction") {
272
- return (0, _neverthrow.ok)({
237
+ return ok({
273
238
  type: "async",
274
239
  func: imported.default
275
240
  });
276
241
  }
277
- return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
242
+ return err(new InvalidApiError("API file path does not have a default async function/generator export"));
278
243
  } catch (error) {
279
244
  if (error.message.includes("Unknown variable dynamic import")) {
280
- return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
245
+ return err(new ApiNotFoundError(path));
281
246
  }
282
247
  if ((error === null || error === void 0 ? void 0 : error.code) === "ERR_MODULE_NOT_FOUND") {
283
248
  console.log("API not found", error);
284
- return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
249
+ return err(new ApiNotFoundError(path));
285
250
  }
286
251
  throw error;
287
252
  }
@@ -1,50 +1,43 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.runApiSessionSchema = exports.runApiParametersSchema = void 0;
7
- var _zod = _interopRequireDefault(require("zod"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- const runApiSessionSchema = exports.runApiSessionSchema = _zod.default.discriminatedUnion("type", [_zod.default.object({
10
- type: _zod.default.literal("file"),
11
- path: _zod.default.string()
12
- }), _zod.default.object({
13
- type: _zod.default.literal("state"),
14
- state: _zod.default.custom(v => v)
1
+ import z from "zod";
2
+ export const runApiSessionSchema = z.discriminatedUnion("type", [z.object({
3
+ type: z.literal("file"),
4
+ path: z.string()
5
+ }), z.object({
6
+ type: z.literal("state"),
7
+ state: z.custom(v => v)
15
8
  })]);
16
- const runApiParametersSchema = exports.runApiParametersSchema = _zod.default.object({
17
- functionsToken: _zod.default.string().optional(),
18
- automationFunction: _zod.default.object({
19
- name: _zod.default.string(),
20
- params: _zod.default.any().optional()
9
+ export const runApiParametersSchema = z.object({
10
+ functionsToken: z.string().optional(),
11
+ automationFunction: z.object({
12
+ name: z.string(),
13
+ params: z.any().optional()
21
14
  }),
22
- tracing: _zod.default.discriminatedUnion("enabled", [_zod.default.object({
23
- enabled: _zod.default.literal(false)
24
- }), _zod.default.object({
25
- enabled: _zod.default.literal(true),
26
- filePath: _zod.default.string()
15
+ tracing: z.discriminatedUnion("enabled", [z.object({
16
+ enabled: z.literal(false)
17
+ }), z.object({
18
+ enabled: z.literal(true),
19
+ filePath: z.string()
27
20
  })]).optional().default({
28
21
  enabled: false
29
22
  }),
30
- auth: _zod.default.object({
23
+ auth: z.object({
31
24
  session: runApiSessionSchema,
32
- runCheck: _zod.default.boolean().default(false)
25
+ runCheck: z.boolean().default(false)
33
26
  }).optional(),
34
- runOptions: _zod.default.discriminatedUnion("environment", [_zod.default.object({
35
- environment: _zod.default.literal("deployed"),
36
- headless: _zod.default.boolean().default(true),
37
- proxy: _zod.default.object({
38
- server: _zod.default.string(),
39
- username: _zod.default.string(),
40
- password: _zod.default.string()
27
+ runOptions: z.discriminatedUnion("environment", [z.object({
28
+ environment: z.literal("deployed"),
29
+ headless: z.boolean().default(true),
30
+ proxy: z.object({
31
+ server: z.string(),
32
+ username: z.string(),
33
+ password: z.string()
41
34
  }).optional()
42
- }), _zod.default.object({
43
- environment: _zod.default.literal("ide"),
44
- cdpAddress: _zod.default.string(),
45
- mode: _zod.default.union([_zod.default.literal("vanilla"), _zod.default.literal("playwright"), _zod.default.literal("playwright-standalone"), _zod.default.literal("playwright-headless")])
35
+ }), z.object({
36
+ environment: z.literal("ide"),
37
+ cdpAddress: z.string(),
38
+ mode: z.union([z.literal("vanilla"), z.literal("playwright"), z.literal("playwright-standalone"), z.literal("playwright-headless")])
46
39
  })]).default({
47
40
  environment: "deployed"
48
41
  }),
49
- retrieveSession: _zod.default.boolean().default(false)
42
+ retrieveSession: z.boolean().default(false)
50
43
  });
@@ -1,17 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.settingsSchema = void 0;
7
- var z = _interopRequireWildcard(require("zod"));
8
- 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); }
9
- 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 && Object.prototype.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; }
1
+ import * as z from "zod";
10
2
  const authSessionsSchema = z.object({
11
3
  enabled: z.boolean()
12
4
  }).optional().default({
13
5
  enabled: false
14
6
  });
15
- const settingsSchema = exports.settingsSchema = z.object({
7
+ export const settingsSchema = z.object({
16
8
  authSessions: authSessionsSchema
17
9
  });
@@ -1,19 +1,10 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getTelemetryClient = getTelemetryClient;
7
- exports.initializeAppInsights = initializeAppInsights;
8
- var appInsights = _interopRequireWildcard(require("applicationinsights"));
9
- 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); }
10
- 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 && Object.prototype.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; }
1
+ import * as appInsights from "applicationinsights";
11
2
  function gracefulShutdown() {
12
3
  console.log("Shutting down, so flushing app insights.");
13
4
  appInsights.defaultClient.flush();
14
5
  process.exit();
15
6
  }
16
- function initializeAppInsights() {
7
+ export function initializeAppInsights() {
17
8
  const appInsightsConnectionString = process.env.APPINSIGHTS_CONNECTION_STRING;
18
9
  if (appInsightsConnectionString) {
19
10
  console.log("Initializing app insights.");
@@ -27,6 +18,6 @@ function initializeAppInsights() {
27
18
  appInsights.start();
28
19
  }
29
20
  }
30
- function getTelemetryClient() {
21
+ export function getTelemetryClient() {
31
22
  return appInsights.defaultClient;
32
23
  }
package/dist/index.js CHANGED
@@ -1,69 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "RunError", {
7
- enumerable: true,
8
- get: function () {
9
- return _runtime.RunError;
10
- }
11
- });
12
- Object.defineProperty(exports, "extendPayload", {
13
- enumerable: true,
14
- get: function () {
15
- return _runtime.extendPayload;
16
- }
17
- });
18
- Object.defineProperty(exports, "extendTimeout", {
19
- enumerable: true,
20
- get: function () {
21
- return _runtime.extendTimeout;
22
- }
23
- });
24
- Object.defineProperty(exports, "getDownloadDirectoryPath", {
25
- enumerable: true,
26
- get: function () {
27
- return _downloadDirectory.getDownloadDirectoryPath;
28
- }
29
- });
30
- Object.defineProperty(exports, "getExecutionContext", {
31
- enumerable: true,
32
- get: function () {
33
- return _asyncLocalStorage.getExecutionContext;
34
- }
35
- });
36
- Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
37
- enumerable: true,
38
- get: function () {
39
- return _getPlaywrightConstructs.getProductionPlaywrightConstructs;
40
- }
41
- });
42
- Object.defineProperty(exports, "requestMultipleChoice", {
43
- enumerable: true,
44
- get: function () {
45
- return _runtime.requestMultipleChoice;
46
- }
47
- });
48
- Object.defineProperty(exports, "requestOTP", {
49
- enumerable: true,
50
- get: function () {
51
- return _runtime.requestOTP;
52
- }
53
- });
54
- Object.defineProperty(exports, "runInfo", {
55
- enumerable: true,
56
- get: function () {
57
- return _runtime.runInfo;
58
- }
59
- });
60
- Object.defineProperty(exports, "runWithContext", {
61
- enumerable: true,
62
- get: function () {
63
- return _asyncLocalStorage.runWithContext;
64
- }
65
- });
66
- var _runtime = require("./runtime");
67
- var _asyncLocalStorage = require("./common/asyncLocalStorage");
68
- var _downloadDirectory = require("./runtime/downloadDirectory");
69
- var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs");
1
+ export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP } from "./runtime";
2
+ export { runWithContext, getExecutionContext } from "./common/asyncLocalStorage";
3
+ export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
4
+ export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.RunError = void 0;
7
- class RunError extends Error {
1
+ export class RunError extends Error {
8
2
  constructor(message, options) {
9
3
  super(message);
10
4
  this.message = message;
@@ -15,5 +9,4 @@ class RunError extends Error {
15
9
  Object.setPrototypeOf(this, RunError.prototype);
16
10
  }
17
11
  }
18
- exports.RunError = RunError;
19
12
  new RunError("", {});
@@ -1,18 +1,12 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getDownloadDirectoryPath = getDownloadDirectoryPath;
7
- var _ = require("..");
8
- var _fsExtra = require("fs-extra");
9
- function getDownloadDirectoryPath() {
10
- const context = (0, _.getExecutionContext)();
1
+ import { getExecutionContext } from "..";
2
+ import { ensureDirSync } from "fs-extra";
3
+ export function getDownloadDirectoryPath() {
4
+ const context = getExecutionContext();
11
5
  if (!context) {
12
6
  throw new Error("ExecutionContext not found");
13
7
  }
14
8
  const path = `/tmp/downloads/${context.runId}`;
15
- (0, _fsExtra.ensureDirSync)(path, {
9
+ ensureDirSync(path, {
16
10
  mode: 0o2775
17
11
  });
18
12
  return path;
@@ -1,5 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};
@@ -1,15 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.RunType = exports.RunEnvironment = void 0;
7
- let RunEnvironment = exports.RunEnvironment = function (RunEnvironment) {
1
+ export let RunEnvironment = function (RunEnvironment) {
8
2
  RunEnvironment["IDE"] = "IDE";
9
3
  RunEnvironment["DEPLOYED"] = "DEPLOYED";
10
4
  return RunEnvironment;
11
5
  }({});
12
- let RunType = exports.RunType = function (RunType) {
6
+ export let RunType = function (RunType) {
13
7
  RunType["SYNC"] = "SYNC";
14
8
  RunType["ASYNC"] = "ASYNC";
15
9
  RunType["JOB"] = "JOB";
@@ -1,53 +1,51 @@
1
- "use strict";
2
-
3
- var _vitest = require("vitest");
4
- var _asyncLocalStorage = require("../common/asyncLocalStorage");
5
- var _index = require("./index");
6
- var _enums = require("./enums");
7
- (0, _vitest.describe)("Execution Helpers", () => {
8
- (0, _vitest.it)("should be able to get execution info", () => {
9
- (0, _asyncLocalStorage.runWithContext)({
10
- runEnvironment: _enums.RunEnvironment.IDE,
1
+ import { describe, expect, it } from "vitest";
2
+ import { getExecutionContext, runWithContext } from "../common/asyncLocalStorage";
3
+ import { extendPayload, runInfo } from "./index";
4
+ import { RunEnvironment } from "./enums";
5
+ describe("Execution Helpers", () => {
6
+ it("should be able to get execution info", () => {
7
+ runWithContext({
8
+ runEnvironment: RunEnvironment.IDE,
11
9
  runId: "test-run-id",
12
10
  extendedPayloads: []
13
11
  }, () => {
14
- (0, _vitest.expect)((0, _index.runInfo)().runId).toEqual("test-run-id");
12
+ expect(runInfo().runId).toEqual("test-run-id");
15
13
  });
16
14
  });
17
- (0, _vitest.it)("should be able to mutate extendedPayloads and get the accmulated value at the end ", () => {
15
+ it("should be able to mutate extendedPayloads and get the accmulated value at the end ", () => {
18
16
  const context = {
19
17
  extendedPayloads: [],
20
18
  runId: "test-run-id"
21
19
  };
22
- (0, _asyncLocalStorage.runWithContext)({
23
- runEnvironment: _enums.RunEnvironment.IDE,
20
+ runWithContext({
21
+ runEnvironment: RunEnvironment.IDE,
24
22
  runId: "test-run-id",
25
23
  extendedPayloads: []
26
24
  }, () => {
27
25
  var _getExecutionContext, _getExecutionContext2;
28
- (0, _vitest.expect)((_getExecutionContext = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
29
- (0, _index.extendPayload)({
26
+ expect((_getExecutionContext = getExecutionContext()) === null || _getExecutionContext === void 0 ? void 0 : _getExecutionContext.extendedPayloads).toEqual([]);
27
+ extendPayload({
30
28
  api: "test-api",
31
29
  parameters: {}
32
30
  });
33
- (0, _vitest.expect)((_getExecutionContext2 = (0, _asyncLocalStorage.getExecutionContext)()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
31
+ expect((_getExecutionContext2 = getExecutionContext()) === null || _getExecutionContext2 === void 0 ? void 0 : _getExecutionContext2.extendedPayloads).toEqual([{
34
32
  api: "test-api",
35
33
  parameters: {}
36
34
  }]);
37
- (0, _index.extendPayload)({
35
+ extendPayload({
38
36
  api: "test-api",
39
37
  parameters: {}
40
38
  });
41
- (0, _index.extendPayload)({
39
+ extendPayload({
42
40
  api: "test-api",
43
41
  parameters: {}
44
42
  });
45
- (0, _index.extendPayload)({
43
+ extendPayload({
46
44
  api: "test-api",
47
45
  parameters: {}
48
46
  });
49
- const context = (0, _asyncLocalStorage.getExecutionContext)();
50
- (0, _vitest.expect)(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
47
+ const context = getExecutionContext();
48
+ expect(context === null || context === void 0 ? void 0 : context.extendedPayloads).toHaveLength(4);
51
49
  });
52
50
  });
53
51
  });
@@ -1,5 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
1
+ export {};