@intuned/runtime-dev 1.3.1-api-token.6 → 1.3.3-fix.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.
- package/dist/commands/api/run.js +5 -3
- package/dist/commands/auth-sessions/load.js +3 -3
- package/dist/commands/auth-sessions/run-check.js +1 -2
- package/dist/commands/auth-sessions/run-create.js +12 -35
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +14 -40
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +2 -1
- package/dist/commands/intuned-cli/commands/types.d.ts +1 -1
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +1 -2
- package/dist/commands/intuned-cli/controller/api.js +1 -2
- package/dist/commands/intuned-cli/controller/authSession.js +3 -4
- package/dist/commands/intuned-cli/controller/save.js +27 -28
- package/dist/commands/intuned-cli/helpers/errors.d.ts +2 -2
- package/dist/commands/intuned-cli/helpers/errors.js +8 -4
- package/dist/commands/intuned-cli/main.js +2 -2
- package/dist/common/asyncLocalStorage/index.d.ts +1 -0
- package/dist/common/playwrightContext.d.ts +54 -0
- package/dist/common/{getPlaywrightConstructs.js → playwrightContext.js} +148 -79
- package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
- package/dist/common/runApi/importUsingImportFunction.js +46 -0
- package/dist/common/runApi/index.d.ts +2 -7
- package/dist/common/runApi/index.js +92 -177
- package/dist/common/runApi/types.d.ts +3 -7
- package/dist/common/runApi/types.js +1 -2
- package/dist/common/setupContextHook.d.ts +17 -0
- package/dist/common/setupContextHook.js +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +13 -19
- package/dist/runtime/attemptStore.d.ts +2 -0
- package/dist/runtime/attemptStore.js +23 -0
- package/dist/runtime/export.d.ts +51 -41
- package/dist/runtime/index.d.ts +1 -2
- package/dist/runtime/index.js +7 -13
- package/package.json +3 -1
- package/dist/common/getPlaywrightConstructs.d.ts +0 -30
- package/dist/runtime/requestMoreInfo.d.ts +0 -18
- 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
|
|
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
|
|
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,109 @@ async function* runApiGenerator({
|
|
|
78
80
|
resolve(abortSymbol);
|
|
79
81
|
});
|
|
80
82
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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;
|
|
109
|
+
}
|
|
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);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (auth) {
|
|
120
|
+
await (0, _playwrightContext.loadSessionToContext)({
|
|
121
|
+
context,
|
|
122
|
+
session: auth.session
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
const scriptContent = await fs.readFile(_playwrightContext.browserScriptsFile, "utf-8");
|
|
126
|
+
await context.addInitScript({
|
|
127
|
+
content: scriptContent
|
|
155
128
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
129
|
+
for (const page of context.pages()) {
|
|
130
|
+
await page.evaluate(scriptContent);
|
|
131
|
+
}
|
|
132
|
+
if (tracing.enabled) {
|
|
133
|
+
await context.tracing.start({
|
|
134
|
+
screenshots: true,
|
|
135
|
+
snapshots: true,
|
|
136
|
+
sources: true
|
|
137
|
+
});
|
|
138
|
+
traceStarted = true;
|
|
139
|
+
}
|
|
140
|
+
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
141
|
+
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
160
142
|
try {
|
|
161
|
-
|
|
162
|
-
const
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return (0, _neverthrow.err)(new _errors.InvalidCheckError(`Auth session check function failed`, error));
|
|
167
|
-
}
|
|
168
|
-
return authCheckResult;
|
|
169
|
-
}
|
|
170
|
-
if (!authCheckResult.value) {
|
|
171
|
-
return (0, _neverthrow.err)(new _errors.AuthCheckFailedError());
|
|
143
|
+
const automationFunctionResult = await automationFunction(...automationFunctionParameters);
|
|
144
|
+
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
145
|
+
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
146
|
+
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
147
|
+
return (0, _neverthrow.err)(new _errors.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
|
|
172
148
|
}
|
|
149
|
+
return (0, _neverthrow.ok)({
|
|
150
|
+
result: automationFunctionResult,
|
|
151
|
+
extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
|
|
152
|
+
session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
|
|
153
|
+
});
|
|
173
154
|
} catch (error) {
|
|
174
|
-
return (0, _neverthrow.err)(new _errors.
|
|
155
|
+
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
156
|
+
} finally {
|
|
157
|
+
await saveTraceIfNeeded({
|
|
158
|
+
errorMessage: "failed to save trace"
|
|
159
|
+
});
|
|
175
160
|
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
result = generatorResult.value;
|
|
189
|
-
break;
|
|
161
|
+
};
|
|
162
|
+
if (runOptions.environment === "standalone") {
|
|
163
|
+
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
164
|
+
try {
|
|
165
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
166
|
+
headless: runOptions.headless,
|
|
167
|
+
proxy: runOptions.proxy,
|
|
168
|
+
downloadsPath,
|
|
169
|
+
...playwrightContextParameters
|
|
170
|
+
}, runAutomationWithContext);
|
|
171
|
+
} finally {
|
|
172
|
+
await fs.remove(downloadsPath);
|
|
190
173
|
}
|
|
191
174
|
} else {
|
|
192
|
-
|
|
175
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
176
|
+
cdpAddress: runOptions.cdpAddress,
|
|
177
|
+
...playwrightContextParameters
|
|
178
|
+
}, runAutomationWithContext);
|
|
193
179
|
}
|
|
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
180
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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());
|
|
212
|
-
}
|
|
213
|
-
if (!result.done) {
|
|
214
|
-
next = yield result.value;
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
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);
|
|
228
|
-
}
|
|
181
|
+
const result = await Promise.race([await runAutomation(), abortPromise]);
|
|
182
|
+
if (result === abortSymbol) {
|
|
183
|
+
return (0, _neverthrow.err)(new _errors.AbortedError());
|
|
229
184
|
}
|
|
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;
|
|
239
|
-
}
|
|
240
|
-
return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
|
|
185
|
+
return result;
|
|
241
186
|
}
|
|
242
187
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
243
188
|
if (retries === 0) {
|
|
@@ -251,34 +196,4 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
|
|
|
251
196
|
tryNumber++;
|
|
252
197
|
}
|
|
253
198
|
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
199
|
}
|
|
@@ -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,
|
|
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 {
|
|
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
|
|
69
|
+
var _playwrightContext = require("./common/playwrightContext");
|
|
@@ -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
|
+
});
|