@intuned/runtime-dev 1.3.17-source.0 → 1.3.18-interface.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 (224) hide show
  1. package/InterfaceTemplate/index.playwright.ts +1 -1
  2. package/api/sample.ts +4 -0
  3. package/bin/intuned +0 -0
  4. package/bin/intuned-interface +7 -0
  5. package/package.json +10 -8
  6. package/dist/commands/api/run.d.ts +0 -6
  7. package/dist/commands/api/run.js +0 -119
  8. package/dist/commands/auth-sessions/load.d.ts +0 -2
  9. package/dist/commands/auth-sessions/load.js +0 -35
  10. package/dist/commands/auth-sessions/run-check.d.ts +0 -2
  11. package/dist/commands/auth-sessions/run-check.js +0 -74
  12. package/dist/commands/auth-sessions/run-create.d.ts +0 -2
  13. package/dist/commands/auth-sessions/run-create.js +0 -78
  14. package/dist/commands/browser/save-state.d.ts +0 -2
  15. package/dist/commands/browser/save-state.js +0 -17
  16. package/dist/commands/browser/start-browser.d.ts +0 -2
  17. package/dist/commands/browser/start-browser.js +0 -14
  18. package/dist/commands/build.d.ts +0 -1
  19. package/dist/commands/build.js +0 -85
  20. package/dist/commands/common/browserUtils.d.ts +0 -14
  21. package/dist/commands/common/browserUtils.js +0 -58
  22. package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
  23. package/dist/commands/common/getFirstLineNumber.js +0 -101
  24. package/dist/commands/common/getFirstLineNumber.test.js +0 -228
  25. package/dist/commands/common/projectExclusions.d.ts +0 -2
  26. package/dist/commands/common/projectExclusions.js +0 -8
  27. package/dist/commands/common/sendMessageToClient.d.ts +0 -1
  28. package/dist/commands/common/sendMessageToClient.js +0 -10
  29. package/dist/commands/common/tsNodeImport.d.ts +0 -2
  30. package/dist/commands/common/tsNodeImport.js +0 -43
  31. package/dist/commands/common/utils/fileUtils.d.ts +0 -6
  32. package/dist/commands/common/utils/fileUtils.js +0 -33
  33. package/dist/commands/common/utils/settings.d.ts +0 -2
  34. package/dist/commands/common/utils/settings.js +0 -31
  35. package/dist/commands/common/utils/template.d.ts +0 -2
  36. package/dist/commands/common/utils/template.js +0 -31
  37. package/dist/commands/common/utils/unixSocket.d.ts +0 -23
  38. package/dist/commands/common/utils/unixSocket.js +0 -87
  39. package/dist/commands/get-headless-user-agent.d.ts +0 -1
  40. package/dist/commands/get-headless-user-agent.js +0 -18
  41. package/dist/commands/interface/run.d.ts +0 -1
  42. package/dist/commands/interface/run.js +0 -215
  43. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
  44. package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
  45. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
  46. package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
  47. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
  48. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
  49. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
  50. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
  51. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
  52. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
  53. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
  54. package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
  55. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
  56. package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -32
  57. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +0 -1
  58. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +0 -16
  59. package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
  60. package/dist/commands/intuned-cli/commands/build.command.js +0 -12
  61. package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
  62. package/dist/commands/intuned-cli/commands/command.js +0 -9
  63. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
  64. package/dist/commands/intuned-cli/commands/deploy.command.js +0 -42
  65. package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
  66. package/dist/commands/intuned-cli/commands/index.js +0 -203
  67. package/dist/commands/intuned-cli/commands/provision.command.d.ts +0 -13
  68. package/dist/commands/intuned-cli/commands/provision.command.js +0 -50
  69. package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
  70. package/dist/commands/intuned-cli/commands/run.command.js +0 -8
  71. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
  72. package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
  73. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -31
  74. package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
  75. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
  76. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
  77. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
  78. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
  79. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
  80. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
  81. package/dist/commands/intuned-cli/commands/types.d.ts +0 -35
  82. package/dist/commands/intuned-cli/commands/types.js +0 -31
  83. package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
  84. package/dist/commands/intuned-cli/constants/index.js +0 -25
  85. package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -398
  86. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1060
  87. package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
  88. package/dist/commands/intuned-cli/controller/api.js +0 -194
  89. package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
  90. package/dist/commands/intuned-cli/controller/authSession.js +0 -424
  91. package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
  92. package/dist/commands/intuned-cli/controller/build.js +0 -36
  93. package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -5
  94. package/dist/commands/intuned-cli/controller/deploy.js +0 -318
  95. package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
  96. package/dist/commands/intuned-cli/controller/index.js +0 -46
  97. package/dist/commands/intuned-cli/controller/provision.d.ts +0 -21
  98. package/dist/commands/intuned-cli/controller/provision.js +0 -300
  99. package/dist/commands/intuned-cli/controller/scaffold.d.ts +0 -1
  100. package/dist/commands/intuned-cli/controller/scaffold.js +0 -77
  101. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -115
  102. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -41
  103. package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
  104. package/dist/commands/intuned-cli/helpers/api.js +0 -16
  105. package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
  106. package/dist/commands/intuned-cli/helpers/auth.js +0 -147
  107. package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
  108. package/dist/commands/intuned-cli/helpers/backend.js +0 -35
  109. package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -15
  110. package/dist/commands/intuned-cli/helpers/browser.js +0 -64
  111. package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
  112. package/dist/commands/intuned-cli/helpers/context.js +0 -33
  113. package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -16
  114. package/dist/commands/intuned-cli/helpers/errors.js +0 -44
  115. package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
  116. package/dist/commands/intuned-cli/helpers/index.js +0 -137
  117. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -39
  118. package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -20
  119. package/dist/commands/intuned-cli/helpers/prompts.d.ts +0 -3
  120. package/dist/commands/intuned-cli/helpers/prompts.js +0 -71
  121. package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
  122. package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
  123. package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
  124. package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
  125. package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
  126. package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
  127. package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
  128. package/dist/commands/intuned-cli/helpers/traces.js +0 -32
  129. package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
  130. package/dist/commands/intuned-cli/helpers/validation.js +0 -14
  131. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
  132. package/dist/commands/intuned-cli/helpers/wrapper.js +0 -76
  133. package/dist/commands/intuned-cli/index.d.ts +0 -1
  134. package/dist/commands/intuned-cli/index.js +0 -16
  135. package/dist/commands/intuned-cli/main.d.ts +0 -1
  136. package/dist/commands/intuned-cli/main.js +0 -36
  137. package/dist/commands/intuned-cli/types.d.ts +0 -70
  138. package/dist/commands/intuned-cli/types.js +0 -22
  139. package/dist/commands/ts-check.d.ts +0 -2
  140. package/dist/commands/ts-check.js +0 -56
  141. package/dist/common/Logger/Logger/index.d.ts +0 -12
  142. package/dist/common/Logger/Logger/index.js +0 -60
  143. package/dist/common/Logger/Logger/types.d.ts +0 -8
  144. package/dist/common/Logger/Logger/types.js +0 -5
  145. package/dist/common/Logger/index.d.ts +0 -12
  146. package/dist/common/Logger/index.js +0 -60
  147. package/dist/common/Logger/types.d.ts +0 -8
  148. package/dist/common/Logger/types.js +0 -5
  149. package/dist/common/assets/browser_scripts.js +0 -2580
  150. package/dist/common/asyncLocalStorage/index.d.ts +0 -16
  151. package/dist/common/asyncLocalStorage/index.js +0 -17
  152. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
  153. package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
  154. package/dist/common/binStartupScript.d.ts +0 -1
  155. package/dist/common/binStartupScript.js +0 -37
  156. package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
  157. package/dist/common/cleanEnvironmentVariables.js +0 -16
  158. package/dist/common/constants.d.ts +0 -10
  159. package/dist/common/constants.js +0 -16
  160. package/dist/common/contextStorageStateHelpers.d.ts +0 -21
  161. package/dist/common/contextStorageStateHelpers.js +0 -81
  162. package/dist/common/extension/extensionsHelpers.d.ts +0 -11
  163. package/dist/common/extension/extensionsHelpers.js +0 -147
  164. package/dist/common/extension/intunedExtensionServer.d.ts +0 -24
  165. package/dist/common/extension/intunedExtensionServer.js +0 -178
  166. package/dist/common/extension/types.d.ts +0 -212
  167. package/dist/common/extension/types.js +0 -51
  168. package/dist/common/formatZodError.d.ts +0 -2
  169. package/dist/common/formatZodError.js +0 -18
  170. package/dist/common/intunedJson.d.ts +0 -229
  171. package/dist/common/intunedJson.js +0 -133
  172. package/dist/common/jwtTokenManager.d.ts +0 -17
  173. package/dist/common/jwtTokenManager.js +0 -109
  174. package/dist/common/launchBrowser.d.ts +0 -33
  175. package/dist/common/launchBrowser.js +0 -235
  176. package/dist/common/playwrightContext.d.ts +0 -31
  177. package/dist/common/playwrightContext.js +0 -150
  178. package/dist/common/runApi/errors.d.ts +0 -72
  179. package/dist/common/runApi/errors.js +0 -169
  180. package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
  181. package/dist/common/runApi/importUsingImportFunction.js +0 -46
  182. package/dist/common/runApi/index.d.ts +0 -11
  183. package/dist/common/runApi/index.js +0 -203
  184. package/dist/common/runApi/types.d.ts +0 -830
  185. package/dist/common/runApi/types.js +0 -73
  186. package/dist/common/settingsSchema.d.ts +0 -533
  187. package/dist/common/settingsSchema.js +0 -58
  188. package/dist/common/setupContextHook.d.ts +0 -17
  189. package/dist/common/setupContextHook.js +0 -22
  190. package/dist/common/telemetry.d.ts +0 -3
  191. package/dist/common/telemetry.js +0 -32
  192. package/dist/index.d.ts +0 -5
  193. package/dist/index.js +0 -124
  194. package/dist/runtime/RunError.d.ts +0 -5
  195. package/dist/runtime/RunError.js +0 -19
  196. package/dist/runtime/attemptStore.d.ts +0 -2
  197. package/dist/runtime/attemptStore.js +0 -23
  198. package/dist/runtime/captcha.d.ts +0 -15
  199. package/dist/runtime/captcha.js +0 -191
  200. package/dist/runtime/captcha.test.js +0 -821
  201. package/dist/runtime/downloadDirectory.d.ts +0 -1
  202. package/dist/runtime/downloadDirectory.js +0 -19
  203. package/dist/runtime/enums.d.js +0 -5
  204. package/dist/runtime/enums.d.ts +0 -11
  205. package/dist/runtime/enums.js +0 -18
  206. package/dist/runtime/executionHelpers.test.js +0 -52
  207. package/dist/runtime/export.d.js +0 -5
  208. package/dist/runtime/export.d.ts +0 -284
  209. package/dist/runtime/extendPayload.d.ts +0 -2
  210. package/dist/runtime/extendPayload.js +0 -21
  211. package/dist/runtime/extendTimeout.d.ts +0 -1
  212. package/dist/runtime/extendTimeout.js +0 -23
  213. package/dist/runtime/getAiGatewayConfig.d.ts +0 -10
  214. package/dist/runtime/getAiGatewayConfig.js +0 -16
  215. package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
  216. package/dist/runtime/getAuthSessionParameters.js +0 -20
  217. package/dist/runtime/index.d.ts +0 -10
  218. package/dist/runtime/index.js +0 -111
  219. package/dist/runtime/persistentStore.d.ts +0 -2
  220. package/dist/runtime/persistentStore.js +0 -37
  221. package/dist/runtime/persistentStore.test.js +0 -101
  222. package/dist/runtime/runInfo.d.ts +0 -2
  223. package/dist/runtime/runInfo.js +0 -21
  224. /package/InterfaceTemplate/{utils.ts → __utils.ts} +0 -0
@@ -1,169 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.runAutomationErrorCodes = exports.resultTooBigErrorCode = exports.maxLevelsExceededErrorCode = exports.invalidCheckErrorCode = exports.invalidApiErrorCode = exports.internalInvalidInputErrorCode = exports.automationError = exports.authRequiredErrorCode = exports.authCheckNotFoundErrorCode = exports.authCheckFailedErrorCode = exports.apiNotFoundErrorCode = exports.abortedErrorCode = exports.RunAutomationError = exports.ResultTooBigError = exports.MaxLevelsExceededError = exports.InvalidCheckError = exports.InvalidApiError = exports.InternalInvalidInputError = exports.AutomationError = exports.AuthRequiredError = exports.AuthCheckNotFoundError = exports.AuthCheckFailedError = exports.ApiNotFoundError = exports.AbortedError = void 0;
7
- var _runtime = require("../../runtime");
8
- var playwright = _interopRequireWildcard(require("playwright-core"));
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 && {}.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; }
11
- const apiNotFoundErrorCode = exports.apiNotFoundErrorCode = "APINotFoundError";
12
- const invalidApiErrorCode = exports.invalidApiErrorCode = "InvalidAPIError";
13
- const invalidCheckErrorCode = exports.invalidCheckErrorCode = "InvalidCheckError";
14
- const abortedErrorCode = exports.abortedErrorCode = "AbortedError";
15
- const authRequiredErrorCode = exports.authRequiredErrorCode = "AuthRequiredError";
16
- const authCheckNotFoundErrorCode = exports.authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
17
- const authCheckFailedErrorCode = exports.authCheckFailedErrorCode = "AuthCheckFailedError";
18
- const maxLevelsExceededErrorCode = exports.maxLevelsExceededErrorCode = "MaxLevelsExceededError";
19
- const automationError = exports.automationError = "AutomationError";
20
- const internalInvalidInputErrorCode = exports.internalInvalidInputErrorCode = "InternalInvalidInputError";
21
- const resultTooBigErrorCode = exports.resultTooBigErrorCode = "ResultTooBigError";
22
- const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundErrorCode, invalidApiErrorCode, invalidCheckErrorCode, abortedErrorCode, authRequiredErrorCode, authCheckNotFoundErrorCode, authCheckFailedErrorCode, maxLevelsExceededErrorCode, automationError, internalInvalidInputErrorCode, resultTooBigErrorCode];
23
- class RunAutomationError {
24
- wrapped = false;
25
- get json() {
26
- return {
27
- code: this.code,
28
- details: this.details,
29
- cause: this.cause?.json
30
- };
31
- }
32
- }
33
- exports.RunAutomationError = RunAutomationError;
34
- class ApiNotFoundError extends RunAutomationError {
35
- constructor(apiName) {
36
- super();
37
- this.code = apiNotFoundErrorCode;
38
- this.statusCode = 404;
39
- this.message = `API ${apiName} not found`;
40
- }
41
- }
42
- exports.ApiNotFoundError = ApiNotFoundError;
43
- class InvalidApiError extends RunAutomationError {
44
- constructor(message) {
45
- super();
46
- this.code = invalidApiErrorCode;
47
- this.statusCode = 400;
48
- this.message = `API is invalid: ${message}`;
49
- }
50
- }
51
- exports.InvalidApiError = InvalidApiError;
52
- class InvalidCheckError extends RunAutomationError {
53
- constructor(message, cause) {
54
- super();
55
- this.code = invalidCheckErrorCode;
56
- this.statusCode = 400;
57
- this.message = message;
58
- this.cause = cause;
59
- }
60
- }
61
- exports.InvalidCheckError = InvalidCheckError;
62
- class AbortedError extends RunAutomationError {
63
- constructor() {
64
- super();
65
- this.code = abortedErrorCode;
66
- this.statusCode = 200;
67
- this.message = "Operation was aborted";
68
- }
69
- }
70
- exports.AbortedError = AbortedError;
71
- class AuthRequiredError extends RunAutomationError {
72
- constructor() {
73
- super();
74
- this.code = authRequiredErrorCode;
75
- this.statusCode = 401;
76
- this.message = "Authentication is required";
77
- this.wrapped = true;
78
- }
79
- }
80
- exports.AuthRequiredError = AuthRequiredError;
81
- class AuthCheckNotFoundError extends RunAutomationError {
82
- constructor() {
83
- super();
84
- this.code = authCheckNotFoundErrorCode;
85
- this.statusCode = 404;
86
- this.message = "Auth check not found";
87
- }
88
- }
89
- exports.AuthCheckNotFoundError = AuthCheckNotFoundError;
90
- class AuthCheckFailedError extends RunAutomationError {
91
- constructor() {
92
- super();
93
- this.code = authCheckFailedErrorCode;
94
- this.statusCode = 401;
95
- this.message = "AuthSession check failed";
96
- this.wrapped = true;
97
- }
98
- }
99
- exports.AuthCheckFailedError = AuthCheckFailedError;
100
- class MaxLevelsExceededError extends RunAutomationError {
101
- constructor(levels) {
102
- super();
103
- this.code = maxLevelsExceededErrorCode;
104
- this.statusCode = 400;
105
- this.message = `Max levels exceeded. Only ${levels} levels are supported`;
106
- this.details = {
107
- levels
108
- };
109
- }
110
- }
111
- exports.MaxLevelsExceededError = MaxLevelsExceededError;
112
- class AutomationError extends RunAutomationError {
113
- constructor(error) {
114
- super();
115
- this.error = error;
116
- this.code = automationError;
117
- if (error instanceof playwright.errors.TimeoutError) {
118
- this.statusCode = 500;
119
- this.message = `[${error.name}] ${error.message}`;
120
- this.details = {
121
- name: error.name,
122
- message: error.message
123
- };
124
- return;
125
- }
126
- if (error instanceof _runtime.RunError) {
127
- this.wrapped = true;
128
- this.statusCode = error.options.status_code ?? 500;
129
- this.message = `[${error.options.error_code ?? error.name}] ${error.message}`;
130
- this.details = {
131
- name: error.name,
132
- statusCode: error.options.status_code,
133
- errorCode: error.options.error_code,
134
- message: error.message,
135
- options: error.options
136
- };
137
- }
138
- this.statusCode = 500;
139
- this.message = `[${error?.name ?? error}] ${error?.message}`;
140
- this.details = {
141
- name: error?.name,
142
- message: error?.message
143
- };
144
- }
145
- }
146
- exports.AutomationError = AutomationError;
147
- class InternalInvalidInputError extends RunAutomationError {
148
- constructor(message, details) {
149
- super();
150
- this.code = internalInvalidInputErrorCode;
151
- this.statusCode = 500;
152
- this.message = message;
153
- this.details = details;
154
- }
155
- }
156
- exports.InternalInvalidInputError = InternalInvalidInputError;
157
- class ResultTooBigError extends RunAutomationError {
158
- constructor(sizeInBytes, maxSizeInBytes) {
159
- super();
160
- this.code = resultTooBigErrorCode;
161
- this.statusCode = 413;
162
- this.message = `Automation result is too big. Size: ${Math.round(sizeInBytes / 1024 / 1024 * 100) / 100}MB, Max allowed: ${Math.round(maxSizeInBytes / 1024 / 1024 * 100) / 100}MB`;
163
- this.details = {
164
- sizeInBytes,
165
- maxSizeInBytes
166
- };
167
- }
168
- }
169
- exports.ResultTooBigError = ResultTooBigError;
@@ -1,9 +0,0 @@
1
- import { Result } from "neverthrow";
2
- import { RunAutomationError } from "./errors";
3
- import { ExtendedRunApiParameters } from "./types";
4
- export type ImportFunction = ExtendedRunApiParameters["importFunction"];
5
- export declare function importUsingImportFunction<_ReturnType = any>({ path, allowGenerators, importFunction, }: {
6
- path: string;
7
- importFunction: ImportFunction;
8
- allowGenerators?: boolean;
9
- }): Promise<Result<(..._: any) => Promise<_ReturnType>, RunAutomationError>>;
@@ -1,46 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.importUsingImportFunction = importUsingImportFunction;
7
- var _neverthrow = require("neverthrow");
8
- var _errors = require("./errors");
9
- async function importUsingImportFunction({
10
- path,
11
- allowGenerators = true,
12
- importFunction
13
- }) {
14
- try {
15
- const importedResult = await importFunction(path);
16
- if (importedResult.isErr()) {
17
- if (importedResult.error.type === "not_found") {
18
- return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
19
- }
20
- return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
21
- }
22
- const imported = importedResult.value;
23
- if (!imported || !imported.default || !imported.default.constructor) {
24
- return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} does not have a default export`));
25
- }
26
- if (imported.default.constructor.name === "AsyncGeneratorFunction") {
27
- if (!allowGenerators) {
28
- return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} default export must be an async function`));
29
- }
30
- return (0, _neverthrow.ok)(async (...args) => {
31
- const generator = imported.default(...args);
32
- const result = await generator.next();
33
- if (!result.done) {
34
- throw new Error("Yield is not supported");
35
- }
36
- return result.value;
37
- });
38
- }
39
- if (imported.default.constructor.name === "AsyncFunction") {
40
- return (0, _neverthrow.ok)(imported.default);
41
- }
42
- return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} default export must be an async function`));
43
- } catch (error) {
44
- return (0, _neverthrow.err)(new _errors.AutomationError(error));
45
- }
46
- }
@@ -1,11 +0,0 @@
1
- import { Result } from "neverthrow";
2
- import { RunAutomationError } from "./errors";
3
- import { Page, BrowserContext } from "playwright";
4
- import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
5
- export * from "./types";
6
- export * from "./errors";
7
- export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
8
- retrieveSession: true;
9
- }): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk>>;
10
- export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
11
- export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
@@ -1,203 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _exportNames = {
7
- runApi: true,
8
- checkAuthSessionWithRetries: true
9
- };
10
- exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
11
- exports.runApi = runApi;
12
- var _downloadDirectory = require("../../runtime/downloadDirectory");
13
- var _asyncLocalStorage = require("../asyncLocalStorage");
14
- var _fsExtra = _interopRequireWildcard(require("fs-extra"));
15
- var fs = _fsExtra;
16
- var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
17
- var _neverthrow = require("neverthrow");
18
- var _errors = require("./errors");
19
- Object.keys(_errors).forEach(function (key) {
20
- if (key === "default" || key === "__esModule") return;
21
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
22
- if (key in exports && exports[key] === _errors[key]) return;
23
- Object.defineProperty(exports, key, {
24
- enumerable: true,
25
- get: function () {
26
- return _errors[key];
27
- }
28
- });
29
- });
30
- var _constants = require("../constants");
31
- var _playwrightContext = require("../playwrightContext");
32
- var _types = require("./types");
33
- Object.keys(_types).forEach(function (key) {
34
- if (key === "default" || key === "__esModule") return;
35
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
36
- if (key in exports && exports[key] === _types[key]) return;
37
- Object.defineProperty(exports, key, {
38
- enumerable: true,
39
- get: function () {
40
- return _types[key];
41
- }
42
- });
43
- });
44
- var _formatZodError = require("../formatZodError");
45
- var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
46
- var _importUsingImportFunction = require("./importUsingImportFunction");
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 && {}.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
- function getObjectSizeInBytes(obj) {
50
- try {
51
- return new TextEncoder().encode(JSON.stringify(obj)).length;
52
- } catch (error) {
53
- return new TextEncoder().encode(String(obj)).length;
54
- }
55
- }
56
- async function runApi({
57
- abortSignal,
58
- importFunction,
59
- retrieveSession = false,
60
- ...input
61
- }) {
62
- let traceStarted = false;
63
- const inputParseResult = _types.runApiParametersSchema.safeParse(input);
64
- if (!inputParseResult.success) {
65
- return (0, _neverthrow.err)(new _errors.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
66
- }
67
- const {
68
- automationFunction: {
69
- name,
70
- params
71
- },
72
- runOptions,
73
- tracing,
74
- auth
75
- } = inputParseResult.data;
76
- const abortSymbol = Symbol("abort");
77
- const abortPromise = new Promise(resolve => {
78
- if (!abortSignal) return;
79
- abortSignal.addEventListener("abort", () => {
80
- resolve(abortSymbol);
81
- });
82
- });
83
- async function runAutomation() {
84
- const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
85
- path: name,
86
- importFunction
87
- });
88
- if (validatedModuleResult.isErr()) {
89
- return (0, _neverthrow.err)(validatedModuleResult.error);
90
- }
91
- const automationFunction = validatedModuleResult.value;
92
- if (auth && auth.session.type === "state") {
93
- const state = auth.session.state;
94
- if (state === undefined || state === null) {
95
- return (0, _neverthrow.err)(new _errors.AuthRequiredError());
96
- }
97
- }
98
- const playwrightContextParameters = {
99
- apiName: name,
100
- apiParameters: params,
101
- importFunction
102
- };
103
- const intunedContext = (0, _asyncLocalStorage.getExecutionContext)();
104
- const runAutomationWithContext = async (context, page) => {
105
- async function saveTraceIfNeeded({
106
- errorMessage
107
- }) {
108
- if (!tracing.enabled || !traceStarted) {
109
- return;
110
- }
111
- try {
112
- await context?.tracing.stop({
113
- path: tracing.filePath
114
- });
115
- } catch (error) {
116
- console.log(errorMessage, error?.message);
117
- await (0, _fsExtra.remove)(tracing.filePath);
118
- }
119
- }
120
- if (auth) {
121
- await (0, _playwrightContext.loadSessionToContext)({
122
- context,
123
- session: auth.session
124
- });
125
- }
126
- const scriptContent = await fs.readFile(_playwrightContext.browserScriptsFile, "utf-8");
127
- await context.addInitScript({
128
- content: scriptContent
129
- });
130
- for (const page of context.pages()) {
131
- await page.evaluate(scriptContent);
132
- }
133
- if (tracing.enabled) {
134
- await context.tracing.start({
135
- screenshots: true,
136
- snapshots: true,
137
- sources: true
138
- });
139
- traceStarted = true;
140
- }
141
- (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
142
- const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
143
- try {
144
- const automationFunctionResult = await automationFunction(...automationFunctionParameters);
145
- const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
146
- const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
147
- if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
148
- return (0, _neverthrow.err)(new _errors.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
149
- }
150
- return (0, _neverthrow.ok)({
151
- result: automationFunctionResult,
152
- extendedPayloads: intunedContext?.extendedPayloads,
153
- session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
154
- });
155
- } catch (error) {
156
- return (0, _neverthrow.err)(new _errors.AutomationError(error));
157
- } finally {
158
- await saveTraceIfNeeded({
159
- errorMessage: "failed to save trace"
160
- });
161
- }
162
- };
163
- if (intunedContext?.store) {
164
- intunedContext.store = {};
165
- }
166
- if (runOptions.environment === "standalone") {
167
- const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
168
- try {
169
- return await (0, _playwrightContext.withPlaywrightContext)({
170
- headless: runOptions.headless,
171
- proxy: runOptions.proxy,
172
- downloadsPath,
173
- ...playwrightContextParameters
174
- }, runAutomationWithContext);
175
- } finally {
176
- await fs.remove(downloadsPath);
177
- }
178
- } else {
179
- return await (0, _playwrightContext.withPlaywrightContext)({
180
- cdpAddress: runOptions.cdpAddress,
181
- ...playwrightContextParameters
182
- }, runAutomationWithContext);
183
- }
184
- }
185
- const result = await Promise.race([await runAutomation(), abortPromise]);
186
- if (result === abortSymbol) {
187
- return (0, _neverthrow.err)(new _errors.AbortedError());
188
- }
189
- return result;
190
- }
191
- async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
192
- if (retries === 0) {
193
- return (0, _neverthrow.ok)(false);
194
- }
195
- let tryNumber = 0;
196
- console.log("Checking AuthSession with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
197
- while (retries > tryNumber) {
198
- const result = await checkFn(page, context);
199
- if (result) return (0, _neverthrow.ok)(true);
200
- tryNumber++;
201
- }
202
- return (0, _neverthrow.ok)(false);
203
- }