bdy 1.18.1-dev → 1.18.3-dev
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/distTs/package.json
CHANGED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateInputAndOptions = validateInputAndOptions;
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const output_1 = __importDefault(require("../../output"));
|
|
9
|
+
const validation_1 = require("../vt/shared/validation");
|
|
10
|
+
const urlSchema = zod_1.z.string().url().optional();
|
|
11
|
+
const browserSchema = zod_1.z.enum(['chrome', 'firefox', 'safari']);
|
|
12
|
+
const browsersListSchema = zod_1.z
|
|
13
|
+
.string()
|
|
14
|
+
.transform((value) => value
|
|
15
|
+
.split(',')
|
|
16
|
+
.map((browser) => browser.trim().toLowerCase())
|
|
17
|
+
.filter((browser) => browser.length > 0))
|
|
18
|
+
.refine((browsers) => browsers.length > 0, {
|
|
19
|
+
message: 'Invalid browsers list. Supported values: chrome,firefox,safari',
|
|
20
|
+
})
|
|
21
|
+
.pipe(zod_1.z.array(browserSchema))
|
|
22
|
+
.transform((browsers) => Array.from(new Set(browsers.map((browser) => browser === 'chrome'
|
|
23
|
+
? 'CHROMIUM'
|
|
24
|
+
: browser === 'firefox'
|
|
25
|
+
? 'FIREFOX'
|
|
26
|
+
: 'WEBKIT'))));
|
|
27
|
+
const optionsSchema = zod_1.z.object({
|
|
28
|
+
follow: zod_1.z.boolean(),
|
|
29
|
+
respectRobots: zod_1.z.boolean(),
|
|
30
|
+
outputType: zod_1.z.enum(['jpeg', 'png', 'md', 'html']).optional(),
|
|
31
|
+
outputTypes: zod_1.z.string().optional(),
|
|
32
|
+
quality: zod_1.z.coerce.number().min(1).max(100).optional(),
|
|
33
|
+
outputDir: zod_1.z.string().default('.'),
|
|
34
|
+
fullPage: zod_1.z.boolean().optional(),
|
|
35
|
+
cssSelector: zod_1.z.string().optional(),
|
|
36
|
+
xpathSelector: zod_1.z.string().optional(),
|
|
37
|
+
colorScheme: zod_1.z.enum(['LIGHT', 'DARK', 'LIGHT_AND_DARK']).optional(),
|
|
38
|
+
browsers: browsersListSchema.optional(),
|
|
39
|
+
devices: zod_1.z.string().optional(),
|
|
40
|
+
delay: zod_1.z.coerce.number().min(0).max(10000),
|
|
41
|
+
waitFor: validation_1.waitForSchema,
|
|
42
|
+
cookie: validation_1.cookieSchema,
|
|
43
|
+
header: validation_1.headerSchema,
|
|
44
|
+
localStorage: zod_1.z
|
|
45
|
+
.array(zod_1.z.string().regex(/^(?:([^:]+)::)?([^=]+)=(.*)$/, {
|
|
46
|
+
message: "LocalStorage option must follow pattern '[scope::]key=value' (scope is optional)",
|
|
47
|
+
}))
|
|
48
|
+
.optional()
|
|
49
|
+
.transform((value) => value?.map((v) => {
|
|
50
|
+
const { scope, key, value } = (0, validation_1.parseScopedKeyValue)(v);
|
|
51
|
+
return { scope, key, value };
|
|
52
|
+
})),
|
|
53
|
+
});
|
|
54
|
+
function validateInputAndOptions(input, options) {
|
|
55
|
+
try {
|
|
56
|
+
const url = urlSchema.parse(input);
|
|
57
|
+
const { follow, respectRobots, outputType, outputTypes: rawOutputTypes, quality, outputDir, fullPage, cssSelector, xpathSelector, colorScheme, browsers: parsedBrowsers, devices: rawDevices, delay, waitFor, cookie, header, localStorage, } = optionsSchema.parse(options);
|
|
58
|
+
let parsedOutputTypes;
|
|
59
|
+
if (rawOutputTypes) {
|
|
60
|
+
try {
|
|
61
|
+
const outputTypeEntrySchema = zod_1.z.array(zod_1.z
|
|
62
|
+
.object({
|
|
63
|
+
type: zod_1.z.string().transform((v) => v.toUpperCase()),
|
|
64
|
+
selector: zod_1.z
|
|
65
|
+
.object({
|
|
66
|
+
type: zod_1.z.enum(['CSS', 'XPATH']).optional(),
|
|
67
|
+
value: zod_1.z.string().optional(),
|
|
68
|
+
})
|
|
69
|
+
.optional(),
|
|
70
|
+
quality: zod_1.z.number().min(1).max(100).optional(),
|
|
71
|
+
})
|
|
72
|
+
.transform((data) => ({
|
|
73
|
+
...data,
|
|
74
|
+
type: data.type,
|
|
75
|
+
})));
|
|
76
|
+
parsedOutputTypes = outputTypeEntrySchema.parse(JSON.parse(rawOutputTypes));
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
output_1.default.exitError("Invalid --outputTypes value. Use JSON array, e.g. --outputTypes '[{\"type\":\"png\"},{\"type\":\"jpeg\",\"quality\":80}]'");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (outputType) {
|
|
83
|
+
if (typeof quality === 'number' && outputType !== 'jpeg') {
|
|
84
|
+
output_1.default.exitError('Quality is only supported for jpeg output type, use --outputType jpeg');
|
|
85
|
+
}
|
|
86
|
+
if (cssSelector && xpathSelector) {
|
|
87
|
+
output_1.default.exitError('Only one of --cssSelector or --xpathSelector can be used');
|
|
88
|
+
}
|
|
89
|
+
const entry = {
|
|
90
|
+
type: outputType.toUpperCase(),
|
|
91
|
+
};
|
|
92
|
+
if (cssSelector) {
|
|
93
|
+
entry.selector = { type: 'CSS', value: cssSelector };
|
|
94
|
+
}
|
|
95
|
+
else if (xpathSelector) {
|
|
96
|
+
entry.selector = { type: 'XPATH', value: xpathSelector };
|
|
97
|
+
}
|
|
98
|
+
if (typeof quality === 'number') {
|
|
99
|
+
entry.quality = quality;
|
|
100
|
+
}
|
|
101
|
+
parsedOutputTypes = [entry];
|
|
102
|
+
}
|
|
103
|
+
let parsedDevices;
|
|
104
|
+
if (rawDevices) {
|
|
105
|
+
try {
|
|
106
|
+
const viewportSchema = zod_1.z
|
|
107
|
+
.object({
|
|
108
|
+
width: zod_1.z.number().positive(),
|
|
109
|
+
height: zod_1.z.number().positive(),
|
|
110
|
+
})
|
|
111
|
+
.strict();
|
|
112
|
+
const deviceSchema = zod_1.z.array(zod_1.z
|
|
113
|
+
.object({
|
|
114
|
+
viewport: viewportSchema,
|
|
115
|
+
screen: viewportSchema.optional(),
|
|
116
|
+
devicePixelRatio: zod_1.z.number().positive().optional(),
|
|
117
|
+
isMobile: zod_1.z.boolean().optional(),
|
|
118
|
+
})
|
|
119
|
+
.strict()
|
|
120
|
+
.transform((data) => ({
|
|
121
|
+
viewport: data.viewport,
|
|
122
|
+
screen: data.screen ?? data.viewport,
|
|
123
|
+
devicePixelRatio: data.devicePixelRatio ?? 1,
|
|
124
|
+
isMobile: data.isMobile ?? false,
|
|
125
|
+
})));
|
|
126
|
+
parsedDevices = deviceSchema.parse(JSON.parse(rawDevices));
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
output_1.default.exitError('Invalid --devices value. Use JSON array, e.g. --devices \'[{"viewport":{"width":1920,"height":1080}}]\'');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
url,
|
|
134
|
+
follow,
|
|
135
|
+
respectRobots,
|
|
136
|
+
outputTypes: parsedOutputTypes,
|
|
137
|
+
outputDir,
|
|
138
|
+
fullPage,
|
|
139
|
+
colorScheme,
|
|
140
|
+
browsers: parsedBrowsers,
|
|
141
|
+
devices: parsedDevices,
|
|
142
|
+
cookies: cookie,
|
|
143
|
+
requestHeaders: header,
|
|
144
|
+
delay,
|
|
145
|
+
waitForSelectors: waitFor,
|
|
146
|
+
localStorage,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (error instanceof zod_1.ZodError) {
|
|
151
|
+
output_1.default.exitError(error.errors.map((e) => `${e.path}: ${e.message}`).join(', '));
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const commander_1 = require("commander");
|
|
8
|
+
const texts_1 = require("../texts");
|
|
9
|
+
const validation_1 = require("../visualTest/validation");
|
|
10
|
+
const output_1 = __importDefault(require("../output"));
|
|
11
|
+
const requests_1 = require("../visualTest/requests");
|
|
12
|
+
const node_zlib_1 = require("node:zlib");
|
|
13
|
+
const tar_stream_1 = __importDefault(require("tar-stream"));
|
|
14
|
+
const promises_1 = require("node:stream/promises");
|
|
15
|
+
const node_fs_1 = require("node:fs");
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
17
|
+
const promises_2 = require("node:fs/promises");
|
|
18
|
+
const context_1 = require("../visualTest/context");
|
|
19
|
+
const ci_info_1 = require("@buddy-works/ci-info");
|
|
20
|
+
const validation_2 = require("./scrape/validation");
|
|
21
|
+
const commandScrape = (0, utils_1.newCommand)('scrape', texts_1.DESC_COMMAND_VT_SCRAPE);
|
|
22
|
+
commandScrape.argument('[url]', texts_1.OPTION_SCRAPE_URL);
|
|
23
|
+
commandScrape.option('--follow', texts_1.OPTION_SCRAPE_FOLLOW, false);
|
|
24
|
+
commandScrape.option('--respectRobots', texts_1.OPTION_COMPARE_RESPECT_ROBOTS, false);
|
|
25
|
+
commandScrape.addOption(new commander_1.Option('--outputType <type>', texts_1.OPTION_SCRAPE_OUTPUT_TYPE).choices([
|
|
26
|
+
'jpeg',
|
|
27
|
+
'png',
|
|
28
|
+
'md',
|
|
29
|
+
'html',
|
|
30
|
+
]));
|
|
31
|
+
commandScrape.option('--outputTypes <json>', texts_1.OPTION_SCRAPE_OUTPUT_TYPES);
|
|
32
|
+
commandScrape.option('--quality <quality>', texts_1.OPTION_SCRAPE_QUALITY);
|
|
33
|
+
commandScrape.option('--fullPage', texts_1.OPTION_SCRAPE_FULL_PAGE, false);
|
|
34
|
+
commandScrape.option('--cssSelector <selector>', texts_1.OPTION_SCRAPE_CSS_SELECTOR);
|
|
35
|
+
commandScrape.option('--xpathSelector <selector>', texts_1.OPTION_SCRAPE_XPATH_SELECTOR);
|
|
36
|
+
commandScrape.addOption(new commander_1.Option('--colorScheme <scheme>', texts_1.OPTION_SCRAPE_COLOR_SCHEME).choices([
|
|
37
|
+
'LIGHT',
|
|
38
|
+
'DARK',
|
|
39
|
+
'LIGHT_AND_DARK',
|
|
40
|
+
]));
|
|
41
|
+
commandScrape.option('--browsers <browsers>', texts_1.OPTION_SCRAPE_BROWSERS);
|
|
42
|
+
commandScrape.option('--devices <devices>', texts_1.OPTION_SCRAPE_DEVICES);
|
|
43
|
+
commandScrape.option('--waitFor <waitFors...>', texts_1.OPTION_COMPARE_WAIT_FOR);
|
|
44
|
+
commandScrape.option('--cookie <cookies...>', texts_1.OPTION_COMPARE_COOKIE);
|
|
45
|
+
commandScrape.option('--header <headers...>', texts_1.OPTION_COMPARE_HEADER);
|
|
46
|
+
commandScrape.option('--localStorage <items...>', texts_1.OPTION_SCRAPE_LOCAL_STORAGE);
|
|
47
|
+
commandScrape.option('--delay <delay>', texts_1.OPTION_SCRAPE_DELAY, '0');
|
|
48
|
+
commandScrape.option('--outputDir <dir>', texts_1.OPTION_SCRAPE_OUTPUT_DIR, '.');
|
|
49
|
+
commandScrape.action(async (inputUrl, options) => {
|
|
50
|
+
if (!(0, validation_1.checkToken)('scrape')) {
|
|
51
|
+
output_1.default.exitError(texts_1.ERR_MISSING_SCRAPE_TOKEN);
|
|
52
|
+
}
|
|
53
|
+
const { url, follow, respectRobots, outputTypes, outputDir, fullPage, colorScheme, browsers, devices, cookies, requestHeaders, delay, waitForSelectors, localStorage, } = (0, validation_2.validateInputAndOptions)(inputUrl, options);
|
|
54
|
+
try {
|
|
55
|
+
const ciAndGitInfo = await (0, ci_info_1.getCiAndGitInfo)({});
|
|
56
|
+
(0, context_1.setCiAndCommitInfo)(ciAndGitInfo);
|
|
57
|
+
const { buildId } = await (0, requests_1.sendScrap)(url, follow, respectRobots, outputTypes, fullPage, colorScheme, browsers, devices, cookies, requestHeaders, delay, waitForSelectors, localStorage);
|
|
58
|
+
const status = await watchSessionStatus(buildId);
|
|
59
|
+
if (!status.ok) {
|
|
60
|
+
output_1.default.exitError(`Scrape session failed: ${status.error}`);
|
|
61
|
+
}
|
|
62
|
+
output_1.default.normal('Downloading scrape package');
|
|
63
|
+
const scrapPackageStream = await (0, requests_1.downloadScrapPackage)(buildId);
|
|
64
|
+
const brotliDecompressor = (0, node_zlib_1.createBrotliDecompress)();
|
|
65
|
+
const unpack = tar_stream_1.default.extract();
|
|
66
|
+
unpack.on('entry', async (header, stream, next) => {
|
|
67
|
+
const currentDir = process.cwd();
|
|
68
|
+
const preparedOutputDir = outputDir.startsWith('.')
|
|
69
|
+
? node_path_1.default.join(currentDir, outputDir)
|
|
70
|
+
: outputDir;
|
|
71
|
+
const newFilePath = node_path_1.default.join(preparedOutputDir, header.name);
|
|
72
|
+
try {
|
|
73
|
+
if (header.type === 'file') {
|
|
74
|
+
await (0, promises_2.mkdir)(node_path_1.default.dirname(newFilePath), { recursive: true });
|
|
75
|
+
const fileWriteStream = (0, node_fs_1.createWriteStream)(newFilePath);
|
|
76
|
+
await (0, promises_1.pipeline)(stream, fileWriteStream);
|
|
77
|
+
next();
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
stream.resume();
|
|
81
|
+
next();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (entryError) {
|
|
85
|
+
output_1.default.error(`Error processing entry ${header.name}: ${entryError}`);
|
|
86
|
+
next(entryError);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
await (0, promises_1.pipeline)(scrapPackageStream, brotliDecompressor, unpack);
|
|
90
|
+
output_1.default.exitSuccess('Downloading scrape package finished');
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
output_1.default.exitError(`${error}`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
async function watchSessionStatus(buildId) {
|
|
97
|
+
return new Promise((resolve) => {
|
|
98
|
+
const eventSource = (0, requests_1.connectToScrapSession)(buildId);
|
|
99
|
+
eventSource.addEventListener('SESSION_STATUS', (event) => {
|
|
100
|
+
const data = JSON.parse(event.data);
|
|
101
|
+
if (data.status === 'STARTED') {
|
|
102
|
+
output_1.default.normal('Scrape session started');
|
|
103
|
+
}
|
|
104
|
+
else if (data.status === 'GATHER_URLS_COMPLETED') {
|
|
105
|
+
output_1.default.normal(`Gathering URLs completed, found ${data.text} URLs`);
|
|
106
|
+
}
|
|
107
|
+
else if (data.status === 'GATHER_URLS_FAILED') {
|
|
108
|
+
output_1.default.error('Gathering URLs failed');
|
|
109
|
+
}
|
|
110
|
+
else if (data.status === 'SCRAPE_URL_COMPLETED') {
|
|
111
|
+
output_1.default.normal(`Scraping ${data.text} completed`);
|
|
112
|
+
}
|
|
113
|
+
else if (data.status === 'SCRAPE_URL_FAILED') {
|
|
114
|
+
output_1.default.error(`Scraping ${data.text} failed`);
|
|
115
|
+
}
|
|
116
|
+
else if (data.status === 'CREATE_PACKAGE_COMPLETED') {
|
|
117
|
+
output_1.default.normal('Package created');
|
|
118
|
+
}
|
|
119
|
+
else if (data.status === 'CREATE_PACKAGE_FAILED') {
|
|
120
|
+
output_1.default.error('Package creation failed');
|
|
121
|
+
}
|
|
122
|
+
else if (data.status === 'ERROR') {
|
|
123
|
+
eventSource.close();
|
|
124
|
+
resolve({ ok: false, error: data.text });
|
|
125
|
+
}
|
|
126
|
+
else if (data.status === 'FINISHED') {
|
|
127
|
+
eventSource.close();
|
|
128
|
+
output_1.default.normal('Scrape session finished');
|
|
129
|
+
resolve({ ok: true });
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
eventSource.addEventListener('error', (event) => {
|
|
133
|
+
if (event.code) {
|
|
134
|
+
eventSource.close();
|
|
135
|
+
if (event.code === 410) {
|
|
136
|
+
output_1.default.normal('Scrape session finished');
|
|
137
|
+
}
|
|
138
|
+
resolve({ ok: event.code === 410, error: event.code });
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
exports.default = commandScrape;
|
|
@@ -59,6 +59,7 @@ commandVtCompare.action(async (options) => {
|
|
|
59
59
|
output_1.default.normal(`List of urls:\n${filteredUrls.join('\n')}`);
|
|
60
60
|
}
|
|
61
61
|
const ciAndGitInfo = await (0, ci_info_1.getCiAndGitInfo)({});
|
|
62
|
+
output_1.default.normal((0, ci_info_1.formattedCiInfo)(ciAndGitInfo));
|
|
62
63
|
(0, context_1.setCiAndCommitInfo)(ciAndGitInfo);
|
|
63
64
|
try {
|
|
64
65
|
const { message } = await (0, requests_1.sendCompareLinks)(filteredUrls, validatedOptions, sitemapSource);
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.waitForSchema = exports.headerSchema = exports.cookieSchema = exports.DEFAULT_SCOPE = void 0;
|
|
7
|
+
exports.parseScopedSelector = parseScopedSelector;
|
|
8
|
+
exports.parseScopedKeyValue = parseScopedKeyValue;
|
|
9
|
+
const zod_1 = require("zod");
|
|
10
|
+
const output_1 = __importDefault(require("../../../output"));
|
|
11
|
+
exports.DEFAULT_SCOPE = '**';
|
|
12
|
+
function parseScopedSelector(value) {
|
|
13
|
+
return value?.map((v) => {
|
|
14
|
+
let scope, type, selectorValue;
|
|
15
|
+
if (v.includes('::CSS=') || v.includes('::XPATH=')) {
|
|
16
|
+
const [scopePart, ...rest] = v.split('::');
|
|
17
|
+
const [typePart, ...valuePart] = rest.join('::').split('=');
|
|
18
|
+
type = typePart;
|
|
19
|
+
selectorValue = valuePart.join('=');
|
|
20
|
+
scope = scopePart;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const [typePart, ...valuePart] = v.split('=');
|
|
24
|
+
type = typePart;
|
|
25
|
+
selectorValue = valuePart.join('=');
|
|
26
|
+
scope = exports.DEFAULT_SCOPE;
|
|
27
|
+
}
|
|
28
|
+
return { scope, type, value: selectorValue };
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function parseScopedKeyValue(rawValue) {
|
|
32
|
+
let scope = exports.DEFAULT_SCOPE;
|
|
33
|
+
let keyValue = rawValue;
|
|
34
|
+
const scopeSeparatorIndex = rawValue.indexOf('::');
|
|
35
|
+
if (scopeSeparatorIndex >= 0) {
|
|
36
|
+
scope = rawValue.slice(0, scopeSeparatorIndex).trim();
|
|
37
|
+
keyValue = rawValue.slice(scopeSeparatorIndex + 2).trim();
|
|
38
|
+
}
|
|
39
|
+
const equalSignIndex = keyValue.indexOf('=');
|
|
40
|
+
if (equalSignIndex <= 0) {
|
|
41
|
+
output_1.default.exitError("Option value must follow pattern '[scope::]key=value' (scope is optional)");
|
|
42
|
+
}
|
|
43
|
+
const key = keyValue.slice(0, equalSignIndex).trim();
|
|
44
|
+
const value = keyValue.slice(equalSignIndex + 1).trim();
|
|
45
|
+
if (!key) {
|
|
46
|
+
output_1.default.exitError('Option key cannot be empty');
|
|
47
|
+
}
|
|
48
|
+
return { scope, key, value };
|
|
49
|
+
}
|
|
50
|
+
exports.cookieSchema = zod_1.z
|
|
51
|
+
.array(zod_1.z
|
|
52
|
+
.string()
|
|
53
|
+
.max(4096, {
|
|
54
|
+
message: 'Cookie must be less than 4096 characters',
|
|
55
|
+
})
|
|
56
|
+
.regex(/^(?:([^:]+)::)?([^=]+)=(.*)$/, {
|
|
57
|
+
message: "Cookie option must follow pattern '[scope::]key=value[;attribute]' (scope is optional)",
|
|
58
|
+
}))
|
|
59
|
+
.optional()
|
|
60
|
+
.transform((value) => value?.map((v) => {
|
|
61
|
+
let scope = exports.DEFAULT_SCOPE;
|
|
62
|
+
let cookieValue = v;
|
|
63
|
+
if (v.includes('::')) {
|
|
64
|
+
const [scopePart, valuePart] = v.split('::');
|
|
65
|
+
scope = scopePart.trim();
|
|
66
|
+
cookieValue = valuePart.trim();
|
|
67
|
+
}
|
|
68
|
+
const cookieParts = cookieValue.split(';').map((part) => part.trim());
|
|
69
|
+
const mainPart = cookieParts[0];
|
|
70
|
+
const firstEqualSignIndex = mainPart.indexOf('=');
|
|
71
|
+
const key = mainPart.slice(0, firstEqualSignIndex).trim();
|
|
72
|
+
const value = mainPart.slice(firstEqualSignIndex + 1).trim();
|
|
73
|
+
const cookie = {
|
|
74
|
+
scope,
|
|
75
|
+
key,
|
|
76
|
+
value,
|
|
77
|
+
httpOnly: false,
|
|
78
|
+
secure: false,
|
|
79
|
+
};
|
|
80
|
+
for (let i = 1; i < cookieParts.length; i++) {
|
|
81
|
+
const part = cookieParts[i].toLowerCase();
|
|
82
|
+
if (part === 'httponly') {
|
|
83
|
+
cookie.httpOnly = true;
|
|
84
|
+
}
|
|
85
|
+
else if (part === 'secure') {
|
|
86
|
+
cookie.secure = true;
|
|
87
|
+
}
|
|
88
|
+
else if (part.startsWith('domain=')) {
|
|
89
|
+
cookie.domain = part.substring(7);
|
|
90
|
+
}
|
|
91
|
+
else if (part.startsWith('path=')) {
|
|
92
|
+
cookie.path = part.substring(5);
|
|
93
|
+
}
|
|
94
|
+
else if (part.startsWith('samesite=')) {
|
|
95
|
+
const sameSiteValue = part.substring(9);
|
|
96
|
+
if (['strict', 'lax', 'none'].includes(sameSiteValue)) {
|
|
97
|
+
cookie.sameSite = (sameSiteValue.charAt(0).toUpperCase() +
|
|
98
|
+
sameSiteValue.slice(1));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return cookie;
|
|
103
|
+
}));
|
|
104
|
+
exports.headerSchema = zod_1.z
|
|
105
|
+
.array(zod_1.z.string().regex(/^(?:([^:]+)::)?([^=]+)=(.*)$/, {
|
|
106
|
+
message: "Header option must follow pattern '[scope::]key=value' (scope is optional)",
|
|
107
|
+
}))
|
|
108
|
+
.optional()
|
|
109
|
+
.transform((value) => value?.map((v) => {
|
|
110
|
+
const { scope, key, value } = parseScopedKeyValue(v);
|
|
111
|
+
return { scope, key, value };
|
|
112
|
+
}));
|
|
113
|
+
exports.waitForSchema = zod_1.z
|
|
114
|
+
.array(zod_1.z.string().regex(/^(?:([^:]+)::)?(?:(CSS|XPATH))=(.+)$/, {
|
|
115
|
+
message: "WaitFor option must follow pattern '[scope::]type=value' where type must be CSS or XPATH (scope is optional)",
|
|
116
|
+
}))
|
|
117
|
+
.optional()
|
|
118
|
+
.transform(parseScopedSelector);
|