@stablyai/playwright-test 2.1.2 → 2.1.3-rc.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/README.md +19 -0
- package/dist/{index-FxXA-kJ_.mjs → index-B3E10pom.mjs} +1048 -1039
- package/dist/index-B3E10pom.mjs.map +1 -0
- package/dist/{index-NMVIqC6_.cjs → index-Cjfxwz2m.cjs} +1047 -1038
- package/dist/index-Cjfxwz2m.cjs.map +1 -0
- package/dist/index.cjs +950 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d-BjGuH5NO.d.cts.map +1 -1
- package/dist/index.d-BjGuH5NO.d.mts.map +1 -1
- package/dist/index.d-BjGuH5NO.d.ts.map +1 -1
- package/dist/index.d.cts +92 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +92 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.d.ts +92 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +948 -4
- package/dist/index.mjs.map +1 -1
- package/dist/reporter.cjs +1 -1
- package/dist/reporter.mjs +1 -1
- package/package.json +5 -4
- package/dist/index-FxXA-kJ_.mjs.map +0 -1
- package/dist/index-NMVIqC6_.cjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var qe = require('path');
|
|
4
4
|
var require$$7 = require('url');
|
|
5
5
|
var test$1 = require('@playwright/test');
|
|
6
6
|
var playwrightBase = require('@stablyai/playwright-base');
|
|
7
|
-
var index = require('./index-
|
|
7
|
+
var index = require('./index-Cjfxwz2m.cjs');
|
|
8
8
|
require('node:buffer');
|
|
9
9
|
require('node:path');
|
|
10
10
|
require('node:child_process');
|
|
@@ -30,8 +30,948 @@ require('zlib');
|
|
|
30
30
|
require('buffer');
|
|
31
31
|
require('os');
|
|
32
32
|
|
|
33
|
+
var jsonBodySerializer = {
|
|
34
|
+
bodySerializer: (body) => JSON.stringify(
|
|
35
|
+
body,
|
|
36
|
+
(_key, value) => typeof value === "bigint" ? value.toString() : value
|
|
37
|
+
)
|
|
38
|
+
};
|
|
39
|
+
var createSseClient = ({
|
|
40
|
+
onRequest,
|
|
41
|
+
onSseError,
|
|
42
|
+
onSseEvent,
|
|
43
|
+
responseTransformer,
|
|
44
|
+
responseValidator,
|
|
45
|
+
sseDefaultRetryDelay,
|
|
46
|
+
sseMaxRetryAttempts,
|
|
47
|
+
sseMaxRetryDelay,
|
|
48
|
+
sseSleepFn,
|
|
49
|
+
url,
|
|
50
|
+
...options
|
|
51
|
+
}) => {
|
|
52
|
+
let lastEventId;
|
|
53
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
54
|
+
const createStream = async function* () {
|
|
55
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
56
|
+
let attempt = 0;
|
|
57
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
58
|
+
while (true) {
|
|
59
|
+
if (signal.aborted) break;
|
|
60
|
+
attempt++;
|
|
61
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
62
|
+
if (lastEventId !== void 0) {
|
|
63
|
+
headers.set("Last-Event-ID", lastEventId);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const requestInit = {
|
|
67
|
+
redirect: "follow",
|
|
68
|
+
...options,
|
|
69
|
+
body: options.serializedBody,
|
|
70
|
+
headers,
|
|
71
|
+
signal
|
|
72
|
+
};
|
|
73
|
+
let request = new Request(url, requestInit);
|
|
74
|
+
if (onRequest) {
|
|
75
|
+
request = await onRequest(url, requestInit);
|
|
76
|
+
}
|
|
77
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
78
|
+
const response = await _fetch(request);
|
|
79
|
+
if (!response.ok)
|
|
80
|
+
throw new Error(
|
|
81
|
+
`SSE failed: ${response.status} ${response.statusText}`
|
|
82
|
+
);
|
|
83
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
84
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
85
|
+
let buffer = "";
|
|
86
|
+
const abortHandler = () => {
|
|
87
|
+
try {
|
|
88
|
+
reader.cancel();
|
|
89
|
+
} catch {
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
signal.addEventListener("abort", abortHandler);
|
|
93
|
+
try {
|
|
94
|
+
while (true) {
|
|
95
|
+
const { done, value } = await reader.read();
|
|
96
|
+
if (done) break;
|
|
97
|
+
buffer += value;
|
|
98
|
+
const chunks = buffer.split("\n\n");
|
|
99
|
+
buffer = chunks.pop() ?? "";
|
|
100
|
+
for (const chunk of chunks) {
|
|
101
|
+
const lines = chunk.split("\n");
|
|
102
|
+
const dataLines = [];
|
|
103
|
+
let eventName;
|
|
104
|
+
for (const line of lines) {
|
|
105
|
+
if (line.startsWith("data:")) {
|
|
106
|
+
dataLines.push(line.replace(/^data:\s*/, ""));
|
|
107
|
+
} else if (line.startsWith("event:")) {
|
|
108
|
+
eventName = line.replace(/^event:\s*/, "");
|
|
109
|
+
} else if (line.startsWith("id:")) {
|
|
110
|
+
lastEventId = line.replace(/^id:\s*/, "");
|
|
111
|
+
} else if (line.startsWith("retry:")) {
|
|
112
|
+
const parsed = Number.parseInt(
|
|
113
|
+
line.replace(/^retry:\s*/, ""),
|
|
114
|
+
10
|
|
115
|
+
);
|
|
116
|
+
if (!Number.isNaN(parsed)) {
|
|
117
|
+
retryDelay = parsed;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
let data;
|
|
122
|
+
let parsedJson = false;
|
|
123
|
+
if (dataLines.length) {
|
|
124
|
+
const rawData = dataLines.join("\n");
|
|
125
|
+
try {
|
|
126
|
+
data = JSON.parse(rawData);
|
|
127
|
+
parsedJson = true;
|
|
128
|
+
} catch {
|
|
129
|
+
data = rawData;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (parsedJson) {
|
|
133
|
+
if (responseValidator) {
|
|
134
|
+
await responseValidator(data);
|
|
135
|
+
}
|
|
136
|
+
if (responseTransformer) {
|
|
137
|
+
data = await responseTransformer(data);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
onSseEvent?.({
|
|
141
|
+
data,
|
|
142
|
+
event: eventName,
|
|
143
|
+
id: lastEventId,
|
|
144
|
+
retry: retryDelay
|
|
145
|
+
});
|
|
146
|
+
if (dataLines.length) {
|
|
147
|
+
yield data;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} finally {
|
|
152
|
+
signal.removeEventListener("abort", abortHandler);
|
|
153
|
+
reader.releaseLock();
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
} catch (error) {
|
|
157
|
+
onSseError?.(error);
|
|
158
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) {
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
const backoff = Math.min(
|
|
162
|
+
retryDelay * 2 ** (attempt - 1),
|
|
163
|
+
sseMaxRetryDelay ?? 3e4
|
|
164
|
+
);
|
|
165
|
+
await sleep(backoff);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const stream = createStream();
|
|
170
|
+
return { stream };
|
|
171
|
+
};
|
|
172
|
+
var separatorArrayExplode = (style) => {
|
|
173
|
+
switch (style) {
|
|
174
|
+
case "label":
|
|
175
|
+
return ".";
|
|
176
|
+
case "matrix":
|
|
177
|
+
return ";";
|
|
178
|
+
case "simple":
|
|
179
|
+
return ",";
|
|
180
|
+
default:
|
|
181
|
+
return "&";
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
var separatorArrayNoExplode = (style) => {
|
|
185
|
+
switch (style) {
|
|
186
|
+
case "form":
|
|
187
|
+
return ",";
|
|
188
|
+
case "pipeDelimited":
|
|
189
|
+
return "|";
|
|
190
|
+
case "spaceDelimited":
|
|
191
|
+
return "%20";
|
|
192
|
+
default:
|
|
193
|
+
return ",";
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var separatorObjectExplode = (style) => {
|
|
197
|
+
switch (style) {
|
|
198
|
+
case "label":
|
|
199
|
+
return ".";
|
|
200
|
+
case "matrix":
|
|
201
|
+
return ";";
|
|
202
|
+
case "simple":
|
|
203
|
+
return ",";
|
|
204
|
+
default:
|
|
205
|
+
return "&";
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var serializeArrayParam = ({
|
|
209
|
+
allowReserved,
|
|
210
|
+
explode,
|
|
211
|
+
name,
|
|
212
|
+
style,
|
|
213
|
+
value
|
|
214
|
+
}) => {
|
|
215
|
+
if (!explode) {
|
|
216
|
+
const joinedValues2 = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
217
|
+
switch (style) {
|
|
218
|
+
case "label":
|
|
219
|
+
return `.${joinedValues2}`;
|
|
220
|
+
case "matrix":
|
|
221
|
+
return `;${name}=${joinedValues2}`;
|
|
222
|
+
case "simple":
|
|
223
|
+
return joinedValues2;
|
|
224
|
+
default:
|
|
225
|
+
return `${name}=${joinedValues2}`;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const separator = separatorArrayExplode(style);
|
|
229
|
+
const joinedValues = value.map((v) => {
|
|
230
|
+
if (style === "label" || style === "simple") {
|
|
231
|
+
return allowReserved ? v : encodeURIComponent(v);
|
|
232
|
+
}
|
|
233
|
+
return serializePrimitiveParam({
|
|
234
|
+
allowReserved,
|
|
235
|
+
name,
|
|
236
|
+
value: v
|
|
237
|
+
});
|
|
238
|
+
}).join(separator);
|
|
239
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
240
|
+
};
|
|
241
|
+
var serializePrimitiveParam = ({
|
|
242
|
+
allowReserved,
|
|
243
|
+
name,
|
|
244
|
+
value
|
|
245
|
+
}) => {
|
|
246
|
+
if (value === void 0 || value === null) {
|
|
247
|
+
return "";
|
|
248
|
+
}
|
|
249
|
+
if (typeof value === "object") {
|
|
250
|
+
throw new Error(
|
|
251
|
+
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
255
|
+
};
|
|
256
|
+
var serializeObjectParam = ({
|
|
257
|
+
allowReserved,
|
|
258
|
+
explode,
|
|
259
|
+
name,
|
|
260
|
+
style,
|
|
261
|
+
value,
|
|
262
|
+
valueOnly
|
|
263
|
+
}) => {
|
|
264
|
+
if (value instanceof Date) {
|
|
265
|
+
return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
266
|
+
}
|
|
267
|
+
if (style !== "deepObject" && !explode) {
|
|
268
|
+
let values = [];
|
|
269
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
270
|
+
values = [
|
|
271
|
+
...values,
|
|
272
|
+
key,
|
|
273
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
274
|
+
];
|
|
275
|
+
});
|
|
276
|
+
const joinedValues2 = values.join(",");
|
|
277
|
+
switch (style) {
|
|
278
|
+
case "form":
|
|
279
|
+
return `${name}=${joinedValues2}`;
|
|
280
|
+
case "label":
|
|
281
|
+
return `.${joinedValues2}`;
|
|
282
|
+
case "matrix":
|
|
283
|
+
return `;${name}=${joinedValues2}`;
|
|
284
|
+
default:
|
|
285
|
+
return joinedValues2;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const separator = separatorObjectExplode(style);
|
|
289
|
+
const joinedValues = Object.entries(value).map(
|
|
290
|
+
([key, v]) => serializePrimitiveParam({
|
|
291
|
+
allowReserved,
|
|
292
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
293
|
+
value: v
|
|
294
|
+
})
|
|
295
|
+
).join(separator);
|
|
296
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
297
|
+
};
|
|
298
|
+
var PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
299
|
+
var defaultPathSerializer = ({ path, url: _url }) => {
|
|
300
|
+
let url = _url;
|
|
301
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
302
|
+
if (matches) {
|
|
303
|
+
for (const match of matches) {
|
|
304
|
+
let explode = false;
|
|
305
|
+
let name = match.substring(1, match.length - 1);
|
|
306
|
+
let style = "simple";
|
|
307
|
+
if (name.endsWith("*")) {
|
|
308
|
+
explode = true;
|
|
309
|
+
name = name.substring(0, name.length - 1);
|
|
310
|
+
}
|
|
311
|
+
if (name.startsWith(".")) {
|
|
312
|
+
name = name.substring(1);
|
|
313
|
+
style = "label";
|
|
314
|
+
} else if (name.startsWith(";")) {
|
|
315
|
+
name = name.substring(1);
|
|
316
|
+
style = "matrix";
|
|
317
|
+
}
|
|
318
|
+
const value = path[name];
|
|
319
|
+
if (value === void 0 || value === null) {
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
if (Array.isArray(value)) {
|
|
323
|
+
url = url.replace(
|
|
324
|
+
match,
|
|
325
|
+
serializeArrayParam({ explode, name, style, value })
|
|
326
|
+
);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
if (typeof value === "object") {
|
|
330
|
+
url = url.replace(
|
|
331
|
+
match,
|
|
332
|
+
serializeObjectParam({
|
|
333
|
+
explode,
|
|
334
|
+
name,
|
|
335
|
+
style,
|
|
336
|
+
value,
|
|
337
|
+
valueOnly: true
|
|
338
|
+
})
|
|
339
|
+
);
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if (style === "matrix") {
|
|
343
|
+
url = url.replace(
|
|
344
|
+
match,
|
|
345
|
+
`;${serializePrimitiveParam({
|
|
346
|
+
name,
|
|
347
|
+
value
|
|
348
|
+
})}`
|
|
349
|
+
);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const replaceValue = encodeURIComponent(
|
|
353
|
+
style === "label" ? `.${value}` : value
|
|
354
|
+
);
|
|
355
|
+
url = url.replace(match, replaceValue);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return url;
|
|
359
|
+
};
|
|
360
|
+
var getUrl = ({
|
|
361
|
+
baseUrl,
|
|
362
|
+
path,
|
|
363
|
+
query,
|
|
364
|
+
querySerializer,
|
|
365
|
+
url: _url
|
|
366
|
+
}) => {
|
|
367
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
368
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
369
|
+
if (path) {
|
|
370
|
+
url = defaultPathSerializer({ path, url });
|
|
371
|
+
}
|
|
372
|
+
let search = query ? querySerializer(query) : "";
|
|
373
|
+
if (search.startsWith("?")) {
|
|
374
|
+
search = search.substring(1);
|
|
375
|
+
}
|
|
376
|
+
if (search) {
|
|
377
|
+
url += `?${search}`;
|
|
378
|
+
}
|
|
379
|
+
return url;
|
|
380
|
+
};
|
|
381
|
+
function getValidRequestBody(options) {
|
|
382
|
+
const hasBody = options.body !== void 0;
|
|
383
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
384
|
+
if (isSerializedBody) {
|
|
385
|
+
if ("serializedBody" in options) {
|
|
386
|
+
const hasSerializedBody = options.serializedBody !== void 0 && options.serializedBody !== "";
|
|
387
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
388
|
+
}
|
|
389
|
+
return options.body !== "" ? options.body : null;
|
|
390
|
+
}
|
|
391
|
+
if (hasBody) {
|
|
392
|
+
return options.body;
|
|
393
|
+
}
|
|
394
|
+
return void 0;
|
|
395
|
+
}
|
|
396
|
+
var getAuthToken = async (auth, callback) => {
|
|
397
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
398
|
+
if (!token) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
if (auth.scheme === "bearer") {
|
|
402
|
+
return `Bearer ${token}`;
|
|
403
|
+
}
|
|
404
|
+
if (auth.scheme === "basic") {
|
|
405
|
+
return `Basic ${btoa(token)}`;
|
|
406
|
+
}
|
|
407
|
+
return token;
|
|
408
|
+
};
|
|
409
|
+
var createQuerySerializer = ({
|
|
410
|
+
parameters = {},
|
|
411
|
+
...args
|
|
412
|
+
} = {}) => {
|
|
413
|
+
const querySerializer = (queryParams) => {
|
|
414
|
+
const search = [];
|
|
415
|
+
if (queryParams && typeof queryParams === "object") {
|
|
416
|
+
for (const name in queryParams) {
|
|
417
|
+
const value = queryParams[name];
|
|
418
|
+
if (value === void 0 || value === null) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
const options = parameters[name] || args;
|
|
422
|
+
if (Array.isArray(value)) {
|
|
423
|
+
const serializedArray = serializeArrayParam({
|
|
424
|
+
allowReserved: options.allowReserved,
|
|
425
|
+
explode: true,
|
|
426
|
+
name,
|
|
427
|
+
style: "form",
|
|
428
|
+
value,
|
|
429
|
+
...options.array
|
|
430
|
+
});
|
|
431
|
+
if (serializedArray) search.push(serializedArray);
|
|
432
|
+
} else if (typeof value === "object") {
|
|
433
|
+
const serializedObject = serializeObjectParam({
|
|
434
|
+
allowReserved: options.allowReserved,
|
|
435
|
+
explode: true,
|
|
436
|
+
name,
|
|
437
|
+
style: "deepObject",
|
|
438
|
+
value,
|
|
439
|
+
...options.object
|
|
440
|
+
});
|
|
441
|
+
if (serializedObject) search.push(serializedObject);
|
|
442
|
+
} else {
|
|
443
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
444
|
+
allowReserved: options.allowReserved,
|
|
445
|
+
name,
|
|
446
|
+
value
|
|
447
|
+
});
|
|
448
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return search.join("&");
|
|
453
|
+
};
|
|
454
|
+
return querySerializer;
|
|
455
|
+
};
|
|
456
|
+
var getParseAs = (contentType) => {
|
|
457
|
+
if (!contentType) {
|
|
458
|
+
return "stream";
|
|
459
|
+
}
|
|
460
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
461
|
+
if (!cleanContent) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
|
|
465
|
+
return "json";
|
|
466
|
+
}
|
|
467
|
+
if (cleanContent === "multipart/form-data") {
|
|
468
|
+
return "formData";
|
|
469
|
+
}
|
|
470
|
+
if (["application/", "audio/", "image/", "video/"].some(
|
|
471
|
+
(type) => cleanContent.startsWith(type)
|
|
472
|
+
)) {
|
|
473
|
+
return "blob";
|
|
474
|
+
}
|
|
475
|
+
if (cleanContent.startsWith("text/")) {
|
|
476
|
+
return "text";
|
|
477
|
+
}
|
|
478
|
+
return;
|
|
479
|
+
};
|
|
480
|
+
var checkForExistence = (options, name) => {
|
|
481
|
+
if (!name) {
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
|
|
485
|
+
return true;
|
|
486
|
+
}
|
|
487
|
+
return false;
|
|
488
|
+
};
|
|
489
|
+
var setAuthParams = async ({
|
|
490
|
+
security,
|
|
491
|
+
...options
|
|
492
|
+
}) => {
|
|
493
|
+
for (const auth of security) {
|
|
494
|
+
if (checkForExistence(options, auth.name)) {
|
|
495
|
+
continue;
|
|
496
|
+
}
|
|
497
|
+
const token = await getAuthToken(auth, options.auth);
|
|
498
|
+
if (!token) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const name = auth.name ?? "Authorization";
|
|
502
|
+
switch (auth.in) {
|
|
503
|
+
case "query":
|
|
504
|
+
if (!options.query) {
|
|
505
|
+
options.query = {};
|
|
506
|
+
}
|
|
507
|
+
options.query[name] = token;
|
|
508
|
+
break;
|
|
509
|
+
case "cookie":
|
|
510
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
511
|
+
break;
|
|
512
|
+
case "header":
|
|
513
|
+
default:
|
|
514
|
+
options.headers.set(name, token);
|
|
515
|
+
break;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
var buildUrl = (options) => getUrl({
|
|
520
|
+
baseUrl: options.baseUrl,
|
|
521
|
+
path: options.path,
|
|
522
|
+
query: options.query,
|
|
523
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
524
|
+
url: options.url
|
|
525
|
+
});
|
|
526
|
+
var mergeConfigs = (a, b) => {
|
|
527
|
+
const config = { ...a, ...b };
|
|
528
|
+
if (config.baseUrl?.endsWith("/")) {
|
|
529
|
+
config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
530
|
+
}
|
|
531
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
532
|
+
return config;
|
|
533
|
+
};
|
|
534
|
+
var headersEntries = (headers) => {
|
|
535
|
+
const entries = [];
|
|
536
|
+
headers.forEach((value, key) => {
|
|
537
|
+
entries.push([key, value]);
|
|
538
|
+
});
|
|
539
|
+
return entries;
|
|
540
|
+
};
|
|
541
|
+
var mergeHeaders = (...headers) => {
|
|
542
|
+
const mergedHeaders = new Headers();
|
|
543
|
+
for (const header of headers) {
|
|
544
|
+
if (!header) {
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
547
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
548
|
+
for (const [key, value] of iterator) {
|
|
549
|
+
if (value === null) {
|
|
550
|
+
mergedHeaders.delete(key);
|
|
551
|
+
} else if (Array.isArray(value)) {
|
|
552
|
+
for (const v of value) {
|
|
553
|
+
mergedHeaders.append(key, v);
|
|
554
|
+
}
|
|
555
|
+
} else if (value !== void 0) {
|
|
556
|
+
mergedHeaders.set(
|
|
557
|
+
key,
|
|
558
|
+
typeof value === "object" ? JSON.stringify(value) : value
|
|
559
|
+
);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
return mergedHeaders;
|
|
564
|
+
};
|
|
565
|
+
var Interceptors = class {
|
|
566
|
+
fns = [];
|
|
567
|
+
clear() {
|
|
568
|
+
this.fns = [];
|
|
569
|
+
}
|
|
570
|
+
eject(id) {
|
|
571
|
+
const index = this.getInterceptorIndex(id);
|
|
572
|
+
if (this.fns[index]) {
|
|
573
|
+
this.fns[index] = null;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
exists(id) {
|
|
577
|
+
const index = this.getInterceptorIndex(id);
|
|
578
|
+
return Boolean(this.fns[index]);
|
|
579
|
+
}
|
|
580
|
+
getInterceptorIndex(id) {
|
|
581
|
+
if (typeof id === "number") {
|
|
582
|
+
return this.fns[id] ? id : -1;
|
|
583
|
+
}
|
|
584
|
+
return this.fns.indexOf(id);
|
|
585
|
+
}
|
|
586
|
+
update(id, fn) {
|
|
587
|
+
const index = this.getInterceptorIndex(id);
|
|
588
|
+
if (this.fns[index]) {
|
|
589
|
+
this.fns[index] = fn;
|
|
590
|
+
return id;
|
|
591
|
+
}
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
use(fn) {
|
|
595
|
+
this.fns.push(fn);
|
|
596
|
+
return this.fns.length - 1;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
var createInterceptors = () => ({
|
|
600
|
+
error: new Interceptors(),
|
|
601
|
+
request: new Interceptors(),
|
|
602
|
+
response: new Interceptors()
|
|
603
|
+
});
|
|
604
|
+
var defaultQuerySerializer = createQuerySerializer({
|
|
605
|
+
allowReserved: false,
|
|
606
|
+
array: {
|
|
607
|
+
explode: true,
|
|
608
|
+
style: "form"
|
|
609
|
+
},
|
|
610
|
+
object: {
|
|
611
|
+
explode: true,
|
|
612
|
+
style: "deepObject"
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
var defaultHeaders = {
|
|
616
|
+
"Content-Type": "application/json"
|
|
617
|
+
};
|
|
618
|
+
var createConfig = (override = {}) => ({
|
|
619
|
+
...jsonBodySerializer,
|
|
620
|
+
headers: defaultHeaders,
|
|
621
|
+
parseAs: "auto",
|
|
622
|
+
querySerializer: defaultQuerySerializer,
|
|
623
|
+
...override
|
|
624
|
+
});
|
|
625
|
+
var createClient = (config = {}) => {
|
|
626
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
627
|
+
const getConfig = () => ({ ..._config });
|
|
628
|
+
const setConfig = (config2) => {
|
|
629
|
+
_config = mergeConfigs(_config, config2);
|
|
630
|
+
return getConfig();
|
|
631
|
+
};
|
|
632
|
+
const interceptors = createInterceptors();
|
|
633
|
+
const beforeRequest = async (options) => {
|
|
634
|
+
const opts = {
|
|
635
|
+
..._config,
|
|
636
|
+
...options,
|
|
637
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
638
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
639
|
+
serializedBody: void 0
|
|
640
|
+
};
|
|
641
|
+
if (opts.security) {
|
|
642
|
+
await setAuthParams({
|
|
643
|
+
...opts,
|
|
644
|
+
security: opts.security
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
if (opts.requestValidator) {
|
|
648
|
+
await opts.requestValidator(opts);
|
|
649
|
+
}
|
|
650
|
+
if (opts.body !== void 0 && opts.bodySerializer) {
|
|
651
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
652
|
+
}
|
|
653
|
+
if (opts.body === void 0 || opts.serializedBody === "") {
|
|
654
|
+
opts.headers.delete("Content-Type");
|
|
655
|
+
}
|
|
656
|
+
const url = buildUrl(opts);
|
|
657
|
+
return { opts, url };
|
|
658
|
+
};
|
|
659
|
+
const request = async (options) => {
|
|
660
|
+
const { opts, url } = await beforeRequest(options);
|
|
661
|
+
const requestInit = {
|
|
662
|
+
redirect: "follow",
|
|
663
|
+
...opts,
|
|
664
|
+
body: getValidRequestBody(opts)
|
|
665
|
+
};
|
|
666
|
+
let request2 = new Request(url, requestInit);
|
|
667
|
+
for (const fn of interceptors.request.fns) {
|
|
668
|
+
if (fn) {
|
|
669
|
+
request2 = await fn(request2, opts);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const _fetch = opts.fetch;
|
|
673
|
+
let response;
|
|
674
|
+
try {
|
|
675
|
+
response = await _fetch(request2);
|
|
676
|
+
} catch (error2) {
|
|
677
|
+
let finalError2 = error2;
|
|
678
|
+
for (const fn of interceptors.error.fns) {
|
|
679
|
+
if (fn) {
|
|
680
|
+
finalError2 = await fn(
|
|
681
|
+
error2,
|
|
682
|
+
void 0,
|
|
683
|
+
request2,
|
|
684
|
+
opts
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
finalError2 = finalError2 || {};
|
|
689
|
+
if (opts.throwOnError) {
|
|
690
|
+
throw finalError2;
|
|
691
|
+
}
|
|
692
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
693
|
+
error: finalError2,
|
|
694
|
+
request: request2,
|
|
695
|
+
response: void 0
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
for (const fn of interceptors.response.fns) {
|
|
699
|
+
if (fn) {
|
|
700
|
+
response = await fn(response, request2, opts);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
const result = {
|
|
704
|
+
request: request2,
|
|
705
|
+
response
|
|
706
|
+
};
|
|
707
|
+
if (response.ok) {
|
|
708
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
709
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
710
|
+
let emptyData;
|
|
711
|
+
switch (parseAs) {
|
|
712
|
+
case "arrayBuffer":
|
|
713
|
+
case "blob":
|
|
714
|
+
case "text":
|
|
715
|
+
emptyData = await response[parseAs]();
|
|
716
|
+
break;
|
|
717
|
+
case "formData":
|
|
718
|
+
emptyData = new FormData();
|
|
719
|
+
break;
|
|
720
|
+
case "stream":
|
|
721
|
+
emptyData = response.body;
|
|
722
|
+
break;
|
|
723
|
+
case "json":
|
|
724
|
+
default:
|
|
725
|
+
emptyData = {};
|
|
726
|
+
break;
|
|
727
|
+
}
|
|
728
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
729
|
+
data: emptyData,
|
|
730
|
+
...result
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
let data;
|
|
734
|
+
switch (parseAs) {
|
|
735
|
+
case "arrayBuffer":
|
|
736
|
+
case "blob":
|
|
737
|
+
case "formData":
|
|
738
|
+
case "json":
|
|
739
|
+
case "text":
|
|
740
|
+
data = await response[parseAs]();
|
|
741
|
+
break;
|
|
742
|
+
case "stream":
|
|
743
|
+
return opts.responseStyle === "data" ? response.body : {
|
|
744
|
+
data: response.body,
|
|
745
|
+
...result
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
if (parseAs === "json") {
|
|
749
|
+
if (opts.responseValidator) {
|
|
750
|
+
await opts.responseValidator(data);
|
|
751
|
+
}
|
|
752
|
+
if (opts.responseTransformer) {
|
|
753
|
+
data = await opts.responseTransformer(data);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return opts.responseStyle === "data" ? data : {
|
|
757
|
+
data,
|
|
758
|
+
...result
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
const textError = await response.text();
|
|
762
|
+
let jsonError;
|
|
763
|
+
try {
|
|
764
|
+
jsonError = JSON.parse(textError);
|
|
765
|
+
} catch {
|
|
766
|
+
}
|
|
767
|
+
const error = jsonError ?? textError;
|
|
768
|
+
let finalError = error;
|
|
769
|
+
for (const fn of interceptors.error.fns) {
|
|
770
|
+
if (fn) {
|
|
771
|
+
finalError = await fn(error, response, request2, opts);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
finalError = finalError || {};
|
|
775
|
+
if (opts.throwOnError) {
|
|
776
|
+
throw finalError;
|
|
777
|
+
}
|
|
778
|
+
return opts.responseStyle === "data" ? void 0 : {
|
|
779
|
+
error: finalError,
|
|
780
|
+
...result
|
|
781
|
+
};
|
|
782
|
+
};
|
|
783
|
+
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
784
|
+
const makeSseFn = (method) => async (options) => {
|
|
785
|
+
const { opts, url } = await beforeRequest(options);
|
|
786
|
+
return createSseClient({
|
|
787
|
+
...opts,
|
|
788
|
+
body: opts.body,
|
|
789
|
+
headers: opts.headers,
|
|
790
|
+
method,
|
|
791
|
+
onRequest: async (url2, init) => {
|
|
792
|
+
let request2 = new Request(url2, init);
|
|
793
|
+
for (const fn of interceptors.request.fns) {
|
|
794
|
+
if (fn) {
|
|
795
|
+
request2 = await fn(request2, opts);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return request2;
|
|
799
|
+
},
|
|
800
|
+
url
|
|
801
|
+
});
|
|
802
|
+
};
|
|
803
|
+
return {
|
|
804
|
+
buildUrl,
|
|
805
|
+
connect: makeMethodFn("CONNECT"),
|
|
806
|
+
delete: makeMethodFn("DELETE"),
|
|
807
|
+
get: makeMethodFn("GET"),
|
|
808
|
+
getConfig,
|
|
809
|
+
head: makeMethodFn("HEAD"),
|
|
810
|
+
interceptors,
|
|
811
|
+
options: makeMethodFn("OPTIONS"),
|
|
812
|
+
patch: makeMethodFn("PATCH"),
|
|
813
|
+
post: makeMethodFn("POST"),
|
|
814
|
+
put: makeMethodFn("PUT"),
|
|
815
|
+
request,
|
|
816
|
+
setConfig,
|
|
817
|
+
sse: {
|
|
818
|
+
connect: makeSseFn("CONNECT"),
|
|
819
|
+
delete: makeSseFn("DELETE"),
|
|
820
|
+
get: makeSseFn("GET"),
|
|
821
|
+
head: makeSseFn("HEAD"),
|
|
822
|
+
options: makeSseFn("OPTIONS"),
|
|
823
|
+
patch: makeSseFn("PATCH"),
|
|
824
|
+
post: makeSseFn("POST"),
|
|
825
|
+
put: makeSseFn("PUT"),
|
|
826
|
+
trace: makeSseFn("TRACE")
|
|
827
|
+
},
|
|
828
|
+
trace: makeMethodFn("TRACE")
|
|
829
|
+
};
|
|
830
|
+
};
|
|
831
|
+
var client = createClient(createConfig({
|
|
832
|
+
baseUrl: "https://api.stably.ai"
|
|
833
|
+
}));
|
|
834
|
+
var postInternalV1TestAccountGoogleAuthState = (options) => {
|
|
835
|
+
return (options.client ?? client).post({
|
|
836
|
+
security: [
|
|
837
|
+
{
|
|
838
|
+
scheme: "bearer",
|
|
839
|
+
type: "http"
|
|
840
|
+
}
|
|
841
|
+
],
|
|
842
|
+
url: "/internal/v1/test-account/google-auth-state",
|
|
843
|
+
...options,
|
|
844
|
+
headers: {
|
|
845
|
+
"Content-Type": "application/json",
|
|
846
|
+
...options.headers
|
|
847
|
+
}
|
|
848
|
+
});
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
const getApiUrl = () => process.env.STABLY_API_URL ?? "https://api.stably.ai";
|
|
852
|
+
const sdkVersion = "2.1.3-rc.0" ;
|
|
853
|
+
const assertNonEmptyString = (value, fieldName) => {
|
|
854
|
+
if (!value.trim()) {
|
|
855
|
+
throw new Error(`Missing required field: ${fieldName}`);
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
859
|
+
const parseCookie = (value) => {
|
|
860
|
+
if (!isRecord(value)) {
|
|
861
|
+
throw new Error("Invalid Google storage state: cookie must be an object");
|
|
862
|
+
}
|
|
863
|
+
const { domain } = value;
|
|
864
|
+
const { name } = value;
|
|
865
|
+
const { path } = value;
|
|
866
|
+
const { sameSite } = value;
|
|
867
|
+
const valueText = value.value;
|
|
868
|
+
if (typeof domain !== "string" || typeof name !== "string" || typeof path !== "string" || typeof valueText !== "string") {
|
|
869
|
+
throw new Error(
|
|
870
|
+
"Invalid Google storage state: cookie is missing required fields"
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
return {
|
|
874
|
+
...typeof value.expires === "number" ? { expires: value.expires } : {},
|
|
875
|
+
...typeof value.httpOnly === "boolean" ? { httpOnly: value.httpOnly } : {},
|
|
876
|
+
...typeof value.partitionKey === "string" ? { partitionKey: value.partitionKey } : {},
|
|
877
|
+
...typeof value.secure === "boolean" ? { secure: value.secure } : {},
|
|
878
|
+
...sameSite === "Lax" || sameSite === "None" || sameSite === "Strict" ? { sameSite } : {},
|
|
879
|
+
domain,
|
|
880
|
+
name,
|
|
881
|
+
path,
|
|
882
|
+
value: valueText
|
|
883
|
+
};
|
|
884
|
+
};
|
|
885
|
+
const parseLocalStorageEntry = (value) => {
|
|
886
|
+
if (!isRecord(value)) {
|
|
887
|
+
throw new Error(
|
|
888
|
+
"Invalid Google storage state: localStorage entry must be an object"
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
const { name } = value;
|
|
892
|
+
const storedValue = value.value;
|
|
893
|
+
if (typeof name !== "string" || typeof storedValue !== "string") {
|
|
894
|
+
throw new Error(
|
|
895
|
+
"Invalid Google storage state: localStorage entry must contain string name and value"
|
|
896
|
+
);
|
|
897
|
+
}
|
|
898
|
+
return { name, value: storedValue };
|
|
899
|
+
};
|
|
900
|
+
const parseOrigin = (value) => {
|
|
901
|
+
if (!isRecord(value)) {
|
|
902
|
+
throw new Error("Invalid Google storage state: origin must be an object");
|
|
903
|
+
}
|
|
904
|
+
const { origin } = value;
|
|
905
|
+
const rawLocalStorage = value.localStorage;
|
|
906
|
+
if (typeof origin !== "string") {
|
|
907
|
+
throw new Error("Invalid Google storage state: origin must be a string");
|
|
908
|
+
}
|
|
909
|
+
if (!Array.isArray(rawLocalStorage)) {
|
|
910
|
+
return { localStorage: [], origin };
|
|
911
|
+
}
|
|
912
|
+
return {
|
|
913
|
+
localStorage: rawLocalStorage.map(parseLocalStorageEntry),
|
|
914
|
+
origin
|
|
915
|
+
};
|
|
916
|
+
};
|
|
917
|
+
const parseStorageState = (value) => ({
|
|
918
|
+
cookies: Array.isArray(value.cookies) ? value.cookies.map(parseCookie) : [],
|
|
919
|
+
origins: Array.isArray(value.origins) ? value.origins.map(parseOrigin) : []
|
|
920
|
+
});
|
|
921
|
+
const applyStorageStateToContext = async (context, storageState) => {
|
|
922
|
+
if (storageState.cookies.length > 0) {
|
|
923
|
+
await context.addCookies(storageState.cookies);
|
|
924
|
+
}
|
|
925
|
+
for (const originState of storageState.origins) {
|
|
926
|
+
if (originState.localStorage.length === 0) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
const page = await context.newPage();
|
|
930
|
+
try {
|
|
931
|
+
await page.goto(originState.origin, { waitUntil: "domcontentloaded" });
|
|
932
|
+
await page.evaluate((entries) => {
|
|
933
|
+
for (const entry of entries) {
|
|
934
|
+
window.localStorage.setItem(entry.name, entry.value);
|
|
935
|
+
}
|
|
936
|
+
}, originState.localStorage);
|
|
937
|
+
} finally {
|
|
938
|
+
await page.close();
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
async function authWithGoogle(options) {
|
|
943
|
+
const apiKey = options.apiKey ?? playwrightBase.requireApiKey();
|
|
944
|
+
assertNonEmptyString(options.email, "email");
|
|
945
|
+
assertNonEmptyString(options.password, "password");
|
|
946
|
+
assertNonEmptyString(options.otpSecret, "otpSecret");
|
|
947
|
+
const client = createClient({
|
|
948
|
+
baseUrl: getApiUrl(),
|
|
949
|
+
headers: {
|
|
950
|
+
Authorization: `Bearer ${apiKey}`,
|
|
951
|
+
"X-Client-Name": "stably-playwright-test",
|
|
952
|
+
"X-Client-Version": sdkVersion,
|
|
953
|
+
"X-Stably-SDK-Version": sdkVersion
|
|
954
|
+
}
|
|
955
|
+
});
|
|
956
|
+
const response = await postInternalV1TestAccountGoogleAuthState({
|
|
957
|
+
body: {
|
|
958
|
+
email: options.email,
|
|
959
|
+
forceRefresh: options.forceRefresh,
|
|
960
|
+
otpSecret: options.otpSecret,
|
|
961
|
+
password: options.password
|
|
962
|
+
},
|
|
963
|
+
client
|
|
964
|
+
});
|
|
965
|
+
if (response.error) {
|
|
966
|
+
const errorMessage = "error" in response.error ? response.error.error : "Unknown error";
|
|
967
|
+
throw new Error(`Failed to authenticate with Google: ${errorMessage}`);
|
|
968
|
+
}
|
|
969
|
+
const storageState = parseStorageState(response.data.storageState);
|
|
970
|
+
await applyStorageStateToContext(options.context, storageState);
|
|
971
|
+
}
|
|
972
|
+
|
|
33
973
|
function getDirname(importMetaUrl) {
|
|
34
|
-
return
|
|
974
|
+
return qe.dirname(require$$7.fileURLToPath(importMetaUrl));
|
|
35
975
|
}
|
|
36
976
|
function getFilename(importMetaUrl) {
|
|
37
977
|
return require$$7.fileURLToPath(importMetaUrl);
|
|
@@ -45,7 +985,11 @@ const test = test$1.test.extend({
|
|
|
45
985
|
await use(playwrightBase.augmentBrowser(browser));
|
|
46
986
|
},
|
|
47
987
|
context: async ({ context }, use) => {
|
|
48
|
-
|
|
988
|
+
const augmentedContext = playwrightBase.augmentBrowserContext(context);
|
|
989
|
+
if (!("authWithGoogle" in augmentedContext)) {
|
|
990
|
+
augmentedContext.authWithGoogle = (options) => authWithGoogle({ context: augmentedContext, ...options });
|
|
991
|
+
}
|
|
992
|
+
await use(augmentedContext);
|
|
49
993
|
},
|
|
50
994
|
page: async ({ page }, use) => {
|
|
51
995
|
await use(playwrightBase.augmentPage(page));
|
|
@@ -62,7 +1006,8 @@ Object.defineProperty(exports, "setApiKey", {
|
|
|
62
1006
|
enumerable: true,
|
|
63
1007
|
get: function () { return playwrightBase.setApiKey; }
|
|
64
1008
|
});
|
|
65
|
-
exports.stablyReporter = index.
|
|
1009
|
+
exports.stablyReporter = index.Ta;
|
|
1010
|
+
exports.authWithGoogle = authWithGoogle;
|
|
66
1011
|
exports.defineConfig = defineConfig;
|
|
67
1012
|
exports.expect = expect;
|
|
68
1013
|
exports.getDirname = getDirname;
|