bdy 1.19.1-dev-pipeline → 1.19.2-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 +1 -1
- package/distTs/src/api/client.js +2 -61
- package/distTs/src/command/pipeline/run.js +125 -22
- package/distTs/src/command/project/get.js +18 -0
- package/distTs/src/command/project/link.js +11 -11
- package/distTs/src/command/project/set.js +31 -0
- package/distTs/src/command/sandbox/get/yaml.js +30 -0
- package/distTs/src/command/vt/scrape.js +193 -0
- package/distTs/src/input.js +31 -14
- package/distTs/src/output.js +31 -149
- package/distTs/src/texts.js +33 -55
- package/distTs/src/tunnel/output/interactive/tunnel.js +2 -2
- package/package.json +1 -1
- package/distTs/src/command/crawl/link.js +0 -61
- package/distTs/src/command/crawl/run.js +0 -147
- package/distTs/src/command/crawl/validation.js +0 -154
- package/distTs/src/command/crawl.js +0 -13
- package/distTs/src/command/pipeline/run/apply.js +0 -62
- package/distTs/src/command/pipeline/run/approve.js +0 -62
- package/distTs/src/command/pipeline/run/cancel.js +0 -36
- package/distTs/src/command/pipeline/run/list.js +0 -52
- package/distTs/src/command/pipeline/run/logs.js +0 -37
- package/distTs/src/command/pipeline/run/retry.js +0 -36
- package/distTs/src/command/pipeline/run/start.js +0 -96
- package/distTs/src/command/pipeline/run/status.js +0 -35
- package/distTs/src/command/tests/capture/validation.js +0 -46
- package/distTs/src/command/tests/capture.js +0 -103
- package/distTs/src/command/tests/unit/link.js +0 -61
- package/distTs/src/command/tests/unit/upload.js +0 -91
- package/distTs/src/command/tests/unit.js +0 -13
- package/distTs/src/command/tests/visual/link.js +0 -61
- package/distTs/src/command/tests/visual/session/close.js +0 -32
- package/distTs/src/command/tests/visual/session/create.js +0 -86
- package/distTs/src/command/tests/visual/session.js +0 -13
- package/distTs/src/command/tests/visual/setup.js +0 -20
- package/distTs/src/command/tests/visual/shared/validation.js +0 -145
- package/distTs/src/command/tests/visual/upload.js +0 -141
- package/distTs/src/command/tests/visual.js +0 -17
- package/distTs/src/command/tests.js +0 -15
- package/distTs/src/crawl/requests.js +0 -141
- package/distTs/src/output/pipeline.js +0 -1527
- package/distTs/src/types/crawl.js +0 -2
- package/distTs/src/types/pipeline.js +0 -424
- package/distTs/src/unitTest/context.js +0 -26
|
@@ -1,145 +0,0 @@
|
|
|
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.delaySchema = 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.delaySchema = zod_1.z
|
|
114
|
-
.array(zod_1.z.string().regex(/^(?:([^:]+)::)?(\d+)$/, {
|
|
115
|
-
message: "Delay option must follow pattern '[scope::]milliseconds' (scope is optional)",
|
|
116
|
-
}))
|
|
117
|
-
.optional()
|
|
118
|
-
.transform((value) => value?.map((v) => {
|
|
119
|
-
let scope = exports.DEFAULT_SCOPE;
|
|
120
|
-
let milliseconds;
|
|
121
|
-
if (v.includes('::')) {
|
|
122
|
-
const [scopePart, msPart] = v.split('::');
|
|
123
|
-
scope = scopePart.trim();
|
|
124
|
-
milliseconds = Number(msPart);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
milliseconds = Number(v);
|
|
128
|
-
}
|
|
129
|
-
if (milliseconds < 1 || milliseconds > 60000) {
|
|
130
|
-
throw new zod_1.z.ZodError([
|
|
131
|
-
{
|
|
132
|
-
code: 'custom',
|
|
133
|
-
message: 'Delay must be between 1 and 60000 milliseconds',
|
|
134
|
-
path: [],
|
|
135
|
-
},
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
return { scope, value: milliseconds };
|
|
139
|
-
}));
|
|
140
|
-
exports.waitForSchema = zod_1.z
|
|
141
|
-
.array(zod_1.z.string().regex(/^(?:([^:]+)::)?(?:(CSS|XPATH))=(.+)$/, {
|
|
142
|
-
message: "WaitFor option must follow pattern '[scope::]type=value' where type must be CSS or XPATH (scope is optional)",
|
|
143
|
-
}))
|
|
144
|
-
.optional()
|
|
145
|
-
.transform(parseScopedSelector);
|
|
@@ -1,141 +0,0 @@
|
|
|
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 texts_1 = require("../../../texts");
|
|
8
|
-
const output_1 = __importDefault(require("../../../output"));
|
|
9
|
-
const node_fs_1 = require("node:fs");
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const node_zlib_1 = require("node:zlib");
|
|
12
|
-
const commandVisualUpload = (0, utils_1.newCommand)('upload', texts_1.DESC_COMMAND_VISUAL_UPLOAD);
|
|
13
|
-
commandVisualUpload.action(async () => {
|
|
14
|
-
const { getCiAndGitInfo, formattedCiInfo } = require('@buddy-works/ci-info');
|
|
15
|
-
const { getDefaultSettings, sendStorybook } = require('../../../visualTest/requests');
|
|
16
|
-
const { setDefaultSettings } = require('../../../visualTest/snapshots');
|
|
17
|
-
const { createVtContext, applyToken, applyCiAndCommitInfo } = require('../../../visualTest/context');
|
|
18
|
-
const Input = require('../../../input').default;
|
|
19
|
-
const ctx = createVtContext();
|
|
20
|
-
const token = await Input.vtSuiteToken();
|
|
21
|
-
if (!token) {
|
|
22
|
-
output_1.default.exitError(texts_1.ERR_MISSING_VT_TOKEN);
|
|
23
|
-
}
|
|
24
|
-
applyToken(ctx, token);
|
|
25
|
-
const currentDirectoryFiles = getCurrentDirectoryFiles();
|
|
26
|
-
if (!isStorybookDirectory(currentDirectoryFiles)) {
|
|
27
|
-
output_1.default.exitError(texts_1.ERR_WRONG_STORYBOOK_DIRECTORY);
|
|
28
|
-
}
|
|
29
|
-
const storybookStoriesIndex = getStorybookStoriesIndex(currentDirectoryFiles);
|
|
30
|
-
const storiesList = getStoriesList(storybookStoriesIndex);
|
|
31
|
-
const storybookSnapshots = getStorybookSnapshots(storiesList);
|
|
32
|
-
const defaultSettings = await getDefaultSettings(ctx);
|
|
33
|
-
setDefaultSettings(defaultSettings);
|
|
34
|
-
const ciAndGitInfo = await getCiAndGitInfo({
|
|
35
|
-
baseBranch: defaultSettings.baseBranch,
|
|
36
|
-
logger: output_1.default.warning,
|
|
37
|
-
});
|
|
38
|
-
applyCiAndCommitInfo(ctx, ciAndGitInfo);
|
|
39
|
-
output_1.default.normal(formattedCiInfo(ciAndGitInfo));
|
|
40
|
-
try {
|
|
41
|
-
const compressedStorybookDirectory = await createCompressedStorybookDirectory(currentDirectoryFiles);
|
|
42
|
-
const { message } = await sendStorybook(ctx, storybookSnapshots, compressedStorybookDirectory);
|
|
43
|
-
output_1.default.exitSuccess(message);
|
|
44
|
-
}
|
|
45
|
-
catch (error) {
|
|
46
|
-
output_1.default.exitError(`${error}`);
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
function getCurrentDirectoryFiles() {
|
|
50
|
-
const cwd = process.cwd();
|
|
51
|
-
const filesAndDirectories = (0, node_fs_1.readdirSync)(cwd, {
|
|
52
|
-
encoding: 'utf8',
|
|
53
|
-
recursive: true,
|
|
54
|
-
});
|
|
55
|
-
return filesAndDirectories.filter((file) => {
|
|
56
|
-
const elementPath = node_path_1.default.join(cwd, file);
|
|
57
|
-
const stats = (0, node_fs_1.statSync)(elementPath);
|
|
58
|
-
return stats.isFile();
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async function createCompressedStorybookDirectory(files) {
|
|
62
|
-
const tar = require('tar-stream');
|
|
63
|
-
const cwd = process.cwd();
|
|
64
|
-
const chunks = [];
|
|
65
|
-
return new Promise((resolve, reject) => {
|
|
66
|
-
const compressStream = (0, node_zlib_1.createBrotliCompress)({
|
|
67
|
-
params: {
|
|
68
|
-
[node_zlib_1.constants.BROTLI_PARAM_QUALITY]: 6,
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
compressStream.on('data', (chunk) => {
|
|
72
|
-
chunks.push(chunk);
|
|
73
|
-
});
|
|
74
|
-
compressStream.on('end', () => {
|
|
75
|
-
resolve(Buffer.concat(chunks));
|
|
76
|
-
});
|
|
77
|
-
compressStream.on('error', reject);
|
|
78
|
-
const packStream = tar.pack();
|
|
79
|
-
packStream.pipe(compressStream);
|
|
80
|
-
let filesProcessed = 0;
|
|
81
|
-
for (const file of files) {
|
|
82
|
-
const filePath = node_path_1.default.join(cwd, file);
|
|
83
|
-
const stats = (0, node_fs_1.statSync)(filePath);
|
|
84
|
-
const entry = packStream.entry({
|
|
85
|
-
name: file,
|
|
86
|
-
size: stats.size,
|
|
87
|
-
}, (error) => {
|
|
88
|
-
if (error) {
|
|
89
|
-
reject(error);
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
filesProcessed += 1;
|
|
93
|
-
if (filesProcessed === files.length) {
|
|
94
|
-
packStream.finalize();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
const fileStream = (0, node_fs_1.createReadStream)(filePath);
|
|
99
|
-
fileStream.pipe(entry);
|
|
100
|
-
fileStream.on('error', reject);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
function isStorybookDirectory(files) {
|
|
105
|
-
return (files.length > 0 &&
|
|
106
|
-
files.includes('index.html') &&
|
|
107
|
-
files.includes('iframe.html'));
|
|
108
|
-
}
|
|
109
|
-
function getStorybookStoriesIndex(files) {
|
|
110
|
-
const indexFiles = files.find((file) => file === 'index.json');
|
|
111
|
-
if (indexFiles) {
|
|
112
|
-
return indexFiles;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return output_1.default.exitError(texts_1.ERR_MISSING_STORYBOOK_INDEX_FILE);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
function getStoriesList(storybookStoriesIndex) {
|
|
119
|
-
const storiesListFile = (0, node_fs_1.readFileSync)(storybookStoriesIndex);
|
|
120
|
-
try {
|
|
121
|
-
const json = JSON.parse(storiesListFile.toString());
|
|
122
|
-
if (![4, 5].includes(json.v)) {
|
|
123
|
-
output_1.default.exitError(texts_1.ERR_UNSUPPORTED_STORYBOOK);
|
|
124
|
-
}
|
|
125
|
-
return json;
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
output_1.default.exitError(texts_1.ERR_PARSING_STORIES);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function getStorybookSnapshots(storiesList) {
|
|
132
|
-
const stories = Object.entries(storiesList.entries)
|
|
133
|
-
.filter(([, value]) => value.type === 'story')
|
|
134
|
-
.map(([key, value]) => ({
|
|
135
|
-
id: key,
|
|
136
|
-
name: `${value.title}/${value.name}`,
|
|
137
|
-
}));
|
|
138
|
-
output_1.default.normal((0, texts_1.TXT_STORIES_AMOUNT)(stories.length));
|
|
139
|
-
return stories;
|
|
140
|
-
}
|
|
141
|
-
exports.default = commandVisualUpload;
|
|
@@ -1,17 +0,0 @@
|
|
|
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 texts_1 = require("../../texts");
|
|
8
|
-
const setup_1 = __importDefault(require("./visual/setup"));
|
|
9
|
-
const upload_1 = __importDefault(require("./visual/upload"));
|
|
10
|
-
const session_1 = __importDefault(require("./visual/session"));
|
|
11
|
-
const link_1 = __importDefault(require("./visual/link"));
|
|
12
|
-
const commandVisual = (0, utils_1.newCommand)('visual', texts_1.DESC_COMMAND_VISUAL);
|
|
13
|
-
commandVisual.addCommand(setup_1.default);
|
|
14
|
-
commandVisual.addCommand(upload_1.default);
|
|
15
|
-
commandVisual.addCommand(session_1.default);
|
|
16
|
-
commandVisual.addCommand(link_1.default);
|
|
17
|
-
exports.default = commandVisual;
|
|
@@ -1,15 +0,0 @@
|
|
|
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 texts_1 = require("../texts");
|
|
8
|
-
const unit_1 = __importDefault(require("./tests/unit"));
|
|
9
|
-
const visual_1 = __importDefault(require("./tests/visual"));
|
|
10
|
-
const capture_1 = __importDefault(require("./tests/capture"));
|
|
11
|
-
const commandTests = (0, utils_1.newCommand)('tests', texts_1.DESC_COMMAND_TESTS);
|
|
12
|
-
commandTests.addCommand(unit_1.default);
|
|
13
|
-
commandTests.addCommand(visual_1.default);
|
|
14
|
-
commandTests.addCommand(capture_1.default);
|
|
15
|
-
exports.default = commandTests;
|
|
@@ -1,141 +0,0 @@
|
|
|
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.sendCrawl = sendCrawl;
|
|
7
|
-
exports.downloadCrawlPackage = downloadCrawlPackage;
|
|
8
|
-
exports.connectToCrawlSession = connectToCrawlSession;
|
|
9
|
-
const context_1 = require("../visualTest/context");
|
|
10
|
-
const undici_1 = require("undici");
|
|
11
|
-
const output_1 = __importDefault(require("../output"));
|
|
12
|
-
const texts_1 = require("../texts");
|
|
13
|
-
const eventsource_1 = require("eventsource");
|
|
14
|
-
const customServiceUrl = process.env.BUDDY_CRAWL_SERVICE_URL;
|
|
15
|
-
function checkIfIsDevToken(token) {
|
|
16
|
-
const tokenParts = token.split('_');
|
|
17
|
-
return tokenParts.length === 5;
|
|
18
|
-
}
|
|
19
|
-
function getServiceUrl(token) {
|
|
20
|
-
if (customServiceUrl) {
|
|
21
|
-
return customServiceUrl;
|
|
22
|
-
}
|
|
23
|
-
const tokenParts = token.split('_');
|
|
24
|
-
const isDevToken = checkIfIsDevToken(token);
|
|
25
|
-
const devServiceUrl = Buffer.from(tokenParts[3], 'base64url').toString('utf-8');
|
|
26
|
-
if (isDevToken) {
|
|
27
|
-
if (devServiceUrl.includes('local.io')) {
|
|
28
|
-
throw new Error('Use BUDDY_CRAWL_SERVICE_URL to set the service URL in this environment');
|
|
29
|
-
}
|
|
30
|
-
return devServiceUrl;
|
|
31
|
-
}
|
|
32
|
-
if (token.startsWith('bud_crawl_eu')) {
|
|
33
|
-
return 'https://vt.eu.buddy.works';
|
|
34
|
-
}
|
|
35
|
-
if (token.startsWith('bud_crawl_asia')) {
|
|
36
|
-
return 'https://vt.asia.buddy.works';
|
|
37
|
-
}
|
|
38
|
-
return 'https://vt.buddy.works';
|
|
39
|
-
}
|
|
40
|
-
async function sendCrawl(ctx, url, follow, respectRobots, outputTypes, colorScheme, browsers, devices, cookies, requestHeaders, delays, waitForSelectors, localStorage) {
|
|
41
|
-
const payload = {
|
|
42
|
-
url,
|
|
43
|
-
follow,
|
|
44
|
-
respectRobots,
|
|
45
|
-
outputTypes,
|
|
46
|
-
colorScheme,
|
|
47
|
-
browsers,
|
|
48
|
-
devices,
|
|
49
|
-
cookies,
|
|
50
|
-
requestHeaders,
|
|
51
|
-
delays,
|
|
52
|
-
waitForSelectors,
|
|
53
|
-
localStorage,
|
|
54
|
-
pipelineId: ctx.pipelineId,
|
|
55
|
-
pipelineName: ctx.pipelineName,
|
|
56
|
-
executionId: ctx.executionId,
|
|
57
|
-
actionId: ctx.actionId,
|
|
58
|
-
invokerId: ctx.invokerId,
|
|
59
|
-
ci: ctx.ci,
|
|
60
|
-
executionUrl: ctx.executionUrl,
|
|
61
|
-
};
|
|
62
|
-
const [message, response] = await sendRequest({
|
|
63
|
-
path: '/crawl',
|
|
64
|
-
token: ctx.token,
|
|
65
|
-
payload,
|
|
66
|
-
});
|
|
67
|
-
if (message) {
|
|
68
|
-
throw new Error(message);
|
|
69
|
-
}
|
|
70
|
-
if (!response) {
|
|
71
|
-
throw new Error(texts_1.ERR_INVALID_CRAWL_RESPONSE);
|
|
72
|
-
}
|
|
73
|
-
return response;
|
|
74
|
-
}
|
|
75
|
-
async function downloadCrawlPackage(ctx, buildId) {
|
|
76
|
-
const [message, response] = await sendRequest({
|
|
77
|
-
path: '/download',
|
|
78
|
-
token: ctx.token,
|
|
79
|
-
payload: { token: ctx.token, buildId },
|
|
80
|
-
});
|
|
81
|
-
if (message) {
|
|
82
|
-
throw new Error(message);
|
|
83
|
-
}
|
|
84
|
-
if (!response) {
|
|
85
|
-
throw new Error(texts_1.ERR_INVALID_DOWNLOAD_RESPONSE);
|
|
86
|
-
}
|
|
87
|
-
return response;
|
|
88
|
-
}
|
|
89
|
-
function connectToCrawlSession(ctx, buildId) {
|
|
90
|
-
return new eventsource_1.EventSource(`${getServiceUrl(ctx.token)}/sse`, {
|
|
91
|
-
fetch: (url, options) => {
|
|
92
|
-
return (0, undici_1.fetch)(url, {
|
|
93
|
-
...options,
|
|
94
|
-
headers: {
|
|
95
|
-
...options?.headers,
|
|
96
|
-
'x-token': ctx.token,
|
|
97
|
-
'x-cli-version': context_1.cliVersion,
|
|
98
|
-
'x-build-id': buildId,
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async function sendRequest({ path, token, payload, }) {
|
|
105
|
-
const fullUrl = new URL(path, getServiceUrl(token));
|
|
106
|
-
output_1.default.debug((0, texts_1.LOG_SENDING_REQUEST)(fullUrl.toString()));
|
|
107
|
-
const init = {
|
|
108
|
-
method: 'GET',
|
|
109
|
-
redirect: 'follow',
|
|
110
|
-
headers: {
|
|
111
|
-
'X-CLI-VERSION': context_1.cliVersion,
|
|
112
|
-
'X-TOKEN': token,
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
if (payload) {
|
|
116
|
-
init.method = 'POST';
|
|
117
|
-
init.headers = {
|
|
118
|
-
'Content-Type': 'application/json',
|
|
119
|
-
'X-TOKEN': token,
|
|
120
|
-
'X-CLI-VERSION': context_1.cliVersion,
|
|
121
|
-
};
|
|
122
|
-
init.body = JSON.stringify(payload);
|
|
123
|
-
}
|
|
124
|
-
const response = await (0, undici_1.fetch)(fullUrl, init);
|
|
125
|
-
const contentType = response.headers.get('content-type');
|
|
126
|
-
if (contentType && contentType.includes('application/json')) {
|
|
127
|
-
try {
|
|
128
|
-
const json = (await response.json());
|
|
129
|
-
return [undefined, json];
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
throw new Error(texts_1.ERR_INVALID_JSON);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (contentType && contentType.includes('application/octet-stream')) {
|
|
136
|
-
const buffer = response.body;
|
|
137
|
-
return [undefined, buffer];
|
|
138
|
-
}
|
|
139
|
-
const text = await response.text();
|
|
140
|
-
return [text, undefined];
|
|
141
|
-
}
|