bdy 1.12.8-dev → 1.12.8-dev-pipeline-run

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/distTs/package.json +1 -1
  2. package/package.json +1 -1
  3. package/distTs/bin/cli.js +0 -5
  4. package/distTs/src/agent/agent.js +0 -328
  5. package/distTs/src/agent/linux.js +0 -124
  6. package/distTs/src/agent/manager.js +0 -519
  7. package/distTs/src/agent/osx.js +0 -146
  8. package/distTs/src/agent/socket/client.js +0 -178
  9. package/distTs/src/agent/socket/tunnel.js +0 -237
  10. package/distTs/src/agent/socket.js +0 -242
  11. package/distTs/src/agent/system.js +0 -179
  12. package/distTs/src/agent/wait.js +0 -23
  13. package/distTs/src/agent/windows.js +0 -159
  14. package/distTs/src/agent.js +0 -302
  15. package/distTs/src/api/agent.js +0 -99
  16. package/distTs/src/api/buddy.js +0 -139
  17. package/distTs/src/api/socket.js +0 -159
  18. package/distTs/src/cfg.js +0 -234
  19. package/distTs/src/command/agent/disable.js +0 -27
  20. package/distTs/src/command/agent/enable.js +0 -27
  21. package/distTs/src/command/agent/install.js +0 -117
  22. package/distTs/src/command/agent/restart.js +0 -27
  23. package/distTs/src/command/agent/run.js +0 -19
  24. package/distTs/src/command/agent/start.js +0 -28
  25. package/distTs/src/command/agent/status.js +0 -34
  26. package/distTs/src/command/agent/stop.js +0 -28
  27. package/distTs/src/command/agent/target/disable.js +0 -27
  28. package/distTs/src/command/agent/target/enable.js +0 -27
  29. package/distTs/src/command/agent/target/status.js +0 -32
  30. package/distTs/src/command/agent/target.js +0 -15
  31. package/distTs/src/command/agent/tunnel/http.js +0 -43
  32. package/distTs/src/command/agent/tunnel/list.js +0 -27
  33. package/distTs/src/command/agent/tunnel/remove.js +0 -28
  34. package/distTs/src/command/agent/tunnel/start.js +0 -34
  35. package/distTs/src/command/agent/tunnel/status.js +0 -31
  36. package/distTs/src/command/agent/tunnel/tcp.js +0 -43
  37. package/distTs/src/command/agent/tunnel/tls.js +0 -43
  38. package/distTs/src/command/agent/tunnel.js +0 -23
  39. package/distTs/src/command/agent/uninstall.js +0 -44
  40. package/distTs/src/command/agent/update.js +0 -38
  41. package/distTs/src/command/agent/version.js +0 -21
  42. package/distTs/src/command/agent.js +0 -35
  43. package/distTs/src/command/config/add/http.js +0 -25
  44. package/distTs/src/command/config/add/tcp.js +0 -25
  45. package/distTs/src/command/config/add/tls.js +0 -25
  46. package/distTs/src/command/config/add.js +0 -15
  47. package/distTs/src/command/config/get/region.js +0 -15
  48. package/distTs/src/command/config/get/timeout.js +0 -15
  49. package/distTs/src/command/config/get/token.js +0 -15
  50. package/distTs/src/command/config/get/tunnel.js +0 -19
  51. package/distTs/src/command/config/get/tunnels.js +0 -15
  52. package/distTs/src/command/config/get/whitelist.js +0 -15
  53. package/distTs/src/command/config/get.js +0 -21
  54. package/distTs/src/command/config/remove/tunnel.js +0 -19
  55. package/distTs/src/command/config/remove.js +0 -11
  56. package/distTs/src/command/config/set/region.js +0 -17
  57. package/distTs/src/command/config/set/timeout.js +0 -17
  58. package/distTs/src/command/config/set/token.js +0 -16
  59. package/distTs/src/command/config/set/whitelist.js +0 -17
  60. package/distTs/src/command/config/set.js +0 -17
  61. package/distTs/src/command/config.js +0 -17
  62. package/distTs/src/command/http.js +0 -30
  63. package/distTs/src/command/pre.js +0 -49
  64. package/distTs/src/command/start.js +0 -28
  65. package/distTs/src/command/tcp.js +0 -30
  66. package/distTs/src/command/tls.js +0 -30
  67. package/distTs/src/command/tunnel/config.js +0 -17
  68. package/distTs/src/command/tunnel/http.js +0 -31
  69. package/distTs/src/command/tunnel/start.js +0 -28
  70. package/distTs/src/command/tunnel/tcp.js +0 -30
  71. package/distTs/src/command/tunnel/tls.js +0 -30
  72. package/distTs/src/command/tunnel.js +0 -19
  73. package/distTs/src/command/ut/upload.js +0 -108
  74. package/distTs/src/command/ut.js +0 -12
  75. package/distTs/src/command/version.js +0 -13
  76. package/distTs/src/command/vt/close.js +0 -27
  77. package/distTs/src/command/vt/compare/validation.js +0 -173
  78. package/distTs/src/command/vt/compare.js +0 -97
  79. package/distTs/src/command/vt/exec.js +0 -81
  80. package/distTs/src/command/vt/installBrowser.js +0 -20
  81. package/distTs/src/command/vt/scrap.js +0 -193
  82. package/distTs/src/command/vt/storybook.js +0 -92
  83. package/distTs/src/command/vt.js +0 -22
  84. package/distTs/src/format.js +0 -174
  85. package/distTs/src/index.js +0 -34
  86. package/distTs/src/input.js +0 -270
  87. package/distTs/src/logger.js +0 -95
  88. package/distTs/src/output/interactive/tunnel.js +0 -860
  89. package/distTs/src/output/noninteractive/agent/tunnels.js +0 -43
  90. package/distTs/src/output/noninteractive/config/tunnel.js +0 -65
  91. package/distTs/src/output/noninteractive/config/tunnels.js +0 -18
  92. package/distTs/src/output/noninteractive/tunnel.js +0 -59
  93. package/distTs/src/output.js +0 -143
  94. package/distTs/src/server/cert.js +0 -52
  95. package/distTs/src/server/http1.js +0 -75
  96. package/distTs/src/server/http2.js +0 -78
  97. package/distTs/src/server/sftp.js +0 -497
  98. package/distTs/src/server/ssh.js +0 -446
  99. package/distTs/src/server/tls.js +0 -41
  100. package/distTs/src/ssh/client.js +0 -197
  101. package/distTs/src/texts.js +0 -421
  102. package/distTs/src/tunnel/agent.js +0 -103
  103. package/distTs/src/tunnel/api/agent.js +0 -100
  104. package/distTs/src/tunnel/api/buddy.js +0 -141
  105. package/distTs/src/tunnel/cfg.js +0 -243
  106. package/distTs/src/tunnel/compression.js +0 -44
  107. package/distTs/src/tunnel/dns.js +0 -53
  108. package/distTs/src/tunnel/html/503.html +0 -338
  109. package/distTs/src/tunnel/html.js +0 -33
  110. package/distTs/src/tunnel/http/log.js +0 -218
  111. package/distTs/src/tunnel/http/serve.js +0 -133
  112. package/distTs/src/tunnel/http/stream.js +0 -34
  113. package/distTs/src/tunnel/http.js +0 -508
  114. package/distTs/src/tunnel/identification.js +0 -103
  115. package/distTs/src/tunnel/latency.js +0 -83
  116. package/distTs/src/tunnel/output/interactive/tunnel.js +0 -867
  117. package/distTs/src/tunnel/output/noninteractive/agent/tunnels.js +0 -45
  118. package/distTs/src/tunnel/output/noninteractive/config/tunnel.js +0 -67
  119. package/distTs/src/tunnel/output/noninteractive/config/tunnels.js +0 -20
  120. package/distTs/src/tunnel/output/noninteractive/tunnel.js +0 -61
  121. package/distTs/src/tunnel/server/cert.js +0 -54
  122. package/distTs/src/tunnel/server/http1.js +0 -80
  123. package/distTs/src/tunnel/server/http2.js +0 -84
  124. package/distTs/src/tunnel/server/sftp.js +0 -514
  125. package/distTs/src/tunnel/server/ssh.js +0 -464
  126. package/distTs/src/tunnel/server/tls.js +0 -47
  127. package/distTs/src/tunnel/ssh/client.js +0 -211
  128. package/distTs/src/tunnel/tcp.js +0 -113
  129. package/distTs/src/tunnel/tunnel.js +0 -1010
  130. package/distTs/src/tunnel.js +0 -656
  131. package/distTs/src/types/ciInfo.js +0 -10
  132. package/distTs/src/types/options.js +0 -2
  133. package/distTs/src/types/plugin.js +0 -2
  134. package/distTs/src/types/queue.js +0 -2
  135. package/distTs/src/types/requests.js +0 -2
  136. package/distTs/src/types/resources.js +0 -2
  137. package/distTs/src/types/schemas.js +0 -54
  138. package/distTs/src/types/scrape.js +0 -2
  139. package/distTs/src/types/snapshots.js +0 -2
  140. package/distTs/src/types/storybook.js +0 -2
  141. package/distTs/src/types/tunnel.js +0 -141
  142. package/distTs/src/unitTest/ci.js +0 -108
  143. package/distTs/src/unitTest/requests.js +0 -72
  144. package/distTs/src/utils.js +0 -378
  145. package/distTs/src/visualTest/browser.js +0 -39
  146. package/distTs/src/visualTest/ci.js +0 -241
  147. package/distTs/src/visualTest/context.js +0 -52
  148. package/distTs/src/visualTest/exec.js +0 -51
  149. package/distTs/src/visualTest/linkUtils.js +0 -21
  150. package/distTs/src/visualTest/queue.js +0 -43
  151. package/distTs/src/visualTest/requests.js +0 -365
  152. package/distTs/src/visualTest/resources.js +0 -259
  153. package/distTs/src/visualTest/server.js +0 -109
  154. package/distTs/src/visualTest/snapshots.js +0 -129
  155. package/distTs/src/visualTest/utils/parseDom.js +0 -238
  156. package/distTs/src/visualTest/validation.js +0 -18
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.debug = exports.executionUrl = exports.browserPath = exports.commitDetails = exports.invokerId = exports.executionId = exports.actionId = exports.pipelineName = exports.pipelineId = exports.baseCommit = exports.commit = exports.pullRequestNumber = exports.tag = exports.branch = exports.ci = exports.defaultTimeout = exports.cliId = exports.buildId = exports.token = exports.parallel = exports.skipDiscovery = exports.oneByOne = exports.cliVersion = void 0;
4
- exports.setExecOptions = setExecOptions;
5
- exports.setBrowserPath = setBrowserPath;
6
- exports.setCiAndCommitInfo = setCiAndCommitInfo;
7
- const uuid_1 = require("uuid");
8
- const ciInfo_1 = require("../types/ciInfo");
9
- const utils_1 = require("../utils");
10
- exports.cliVersion = (0, utils_1.getVersion)();
11
- exports.oneByOne = false;
12
- exports.skipDiscovery = false;
13
- exports.parallel = false;
14
- exports.token = process.env.BUDDY_VT_TOKEN || '';
15
- exports.buildId = process.env.SNAPSHOTS_BUILD_ID || (0, uuid_1.v4)();
16
- exports.cliId = (0, uuid_1.v4)();
17
- exports.defaultTimeout = Number(process.env.SNAPSHOTS_DEFAULT_TIMEOUT) || 60_000;
18
- exports.ci = ciInfo_1.CI.NONE;
19
- exports.debug = process.env.DEBUG === '1';
20
- function setExecOptions(options) {
21
- if (options.oneByOne) {
22
- exports.oneByOne = true;
23
- }
24
- if (options.skipDiscovery) {
25
- exports.skipDiscovery = true;
26
- }
27
- if (options.parallel) {
28
- exports.parallel = true;
29
- }
30
- }
31
- function setBrowserPath(path) {
32
- exports.browserPath = path;
33
- }
34
- function setCiAndCommitInfo(ciInfo) {
35
- exports.ci = ciInfo.ci;
36
- exports.branch = ciInfo.branch;
37
- exports.tag = ciInfo.tag;
38
- exports.pullRequestNumber = ciInfo.pullRequestNumber;
39
- exports.commit = ciInfo.commit;
40
- exports.baseCommit = ciInfo.baseCommit;
41
- exports.commitDetails = ciInfo.commitDetails;
42
- if (ciInfo.ci === ciInfo_1.CI.BUDDY) {
43
- exports.pipelineId = ciInfo.pipelineId;
44
- exports.actionId = ciInfo.actionId;
45
- exports.executionId = ciInfo.executionId;
46
- exports.invokerId = ciInfo.invokerId;
47
- exports.pipelineName = ciInfo.pipelineName;
48
- }
49
- if (ciInfo.ci === ciInfo_1.CI.GITHUB_ACTION || ciInfo.ci === ciInfo_1.CI.CIRCLE_CI) {
50
- exports.executionUrl = ciInfo.executionUrl;
51
- }
52
- }
@@ -1,51 +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.testExec = testExec;
7
- exports.gitExec = gitExec;
8
- const cross_spawn_1 = require("cross-spawn");
9
- const output_1 = __importDefault(require("../output"));
10
- const texts_1 = require("../texts");
11
- function testExec(command, arguments_) {
12
- return new Promise((resolve, reject) => {
13
- const process = (0, cross_spawn_1.spawn)(command, arguments_, { stdio: 'inherit' });
14
- let processError;
15
- process.on('error', (error) => {
16
- output_1.default.error(texts_1.ERR_TEST_EXECUTION);
17
- processError = error;
18
- });
19
- process.on('close', (code) => {
20
- if (processError) {
21
- reject(processError);
22
- }
23
- else {
24
- resolve(code || 0);
25
- }
26
- });
27
- });
28
- }
29
- function gitExec(arguments_) {
30
- return new Promise((resolve, reject) => {
31
- const process = (0, cross_spawn_1.spawn)('git', arguments_, {
32
- stdio: ['ignore', 'pipe', 'pipe'],
33
- });
34
- let errorOutput = '';
35
- let output = '';
36
- process.stdout.on('data', (message) => {
37
- output += message;
38
- });
39
- process.stderr.on('data', (message) => {
40
- errorOutput += message;
41
- });
42
- process.on('close', (code) => {
43
- if (code === 0) {
44
- resolve(output);
45
- }
46
- else {
47
- reject(errorOutput);
48
- }
49
- });
50
- });
51
- }
@@ -1,21 +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.addProtocolIfMissing = addProtocolIfMissing;
7
- const output_1 = __importDefault(require("../output"));
8
- function addProtocolIfMissing(url) {
9
- let urlWithProtocol = url;
10
- if (!url.toLowerCase().startsWith('http://') &&
11
- !url.toLowerCase().startsWith('https://')) {
12
- urlWithProtocol = `http://${url}`;
13
- }
14
- try {
15
- new URL(urlWithProtocol);
16
- }
17
- catch {
18
- output_1.default.exitError(`Invalid url: ${urlWithProtocol}`);
19
- }
20
- return urlWithProtocol;
21
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addToQueue = addToQueue;
4
- exports.isQueueEmpty = isQueueEmpty;
5
- const queue = [];
6
- const observers = [];
7
- let processing = false;
8
- function addToQueue(job) {
9
- queue.push(job);
10
- if (!processing) {
11
- processQueue();
12
- }
13
- }
14
- function processQueue() {
15
- const task = queue.shift();
16
- if (task) {
17
- processing = true;
18
- task().then(() => {
19
- if (queue.length > 0) {
20
- processQueue();
21
- }
22
- else {
23
- processing = false;
24
- signalStopProcessing();
25
- }
26
- });
27
- }
28
- }
29
- function subscribeToStopProcessing(function_) {
30
- observers.push(function_);
31
- }
32
- function signalStopProcessing() {
33
- for (const observer of observers) {
34
- observer();
35
- }
36
- }
37
- async function isQueueEmpty() {
38
- return new Promise((resolve) => {
39
- subscribeToStopProcessing(() => {
40
- resolve(true);
41
- });
42
- });
43
- }
@@ -1,365 +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.sendSnapshot = sendSnapshot;
7
- exports.sendSnapshots = sendSnapshots;
8
- exports.closeSession = closeSession;
9
- exports.getDefaultSettings = getDefaultSettings;
10
- exports.sendStorybook = sendStorybook;
11
- exports.sendCompareLinks = sendCompareLinks;
12
- exports.sendScrap = sendScrap;
13
- exports.downloadScrapPackage = downloadScrapPackage;
14
- exports.connectToScrapSession = connectToScrapSession;
15
- const context_1 = require("./context");
16
- const undici_1 = require("undici");
17
- const uuid_1 = require("uuid");
18
- const node_fs_1 = require("node:fs");
19
- const output_1 = __importDefault(require("../output"));
20
- const texts_1 = require("../texts");
21
- const eventsource_1 = require("eventsource");
22
- const customServiceUrl = process.env.BUDDY_VT_SERVICE_URL;
23
- function checkIfIsDevToken(token) {
24
- const tokenParts = token.split('_');
25
- return tokenParts.length === 5;
26
- }
27
- function getServiceUrl() {
28
- if (customServiceUrl) {
29
- return customServiceUrl;
30
- }
31
- const tokenParts = context_1.token.split('_');
32
- const isDevToken = checkIfIsDevToken(context_1.token);
33
- const devServiceUrl = Buffer.from(tokenParts[3], 'base64url').toString('utf-8');
34
- if (isDevToken) {
35
- if (devServiceUrl.includes('local.io')) {
36
- throw new Error('Use BUDDY_VT_SERVICE_URL to set the service URL in this environment');
37
- }
38
- return devServiceUrl;
39
- }
40
- if (context_1.token.startsWith('bud_vt_eu')) {
41
- return 'https://vt.eu.buddy.works';
42
- }
43
- return 'https://vt.buddy.works';
44
- }
45
- function prepareSnapshotInternal(snapshot) {
46
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
- const { resourceDiscoveryTimeout, cookies, ...filteredSnapshot } = snapshot;
48
- return filteredSnapshot;
49
- }
50
- function convertTextToBlob(text, headers) {
51
- if (headers['content-type']?.includes('image')) {
52
- const buffer = Buffer.from(text, 'base64');
53
- return new Blob([buffer]);
54
- }
55
- else {
56
- return new Blob([text]);
57
- }
58
- }
59
- function prepareSnapshot(snapshot, files) {
60
- return {
61
- ...prepareSnapshotInternal(snapshot),
62
- resources: snapshot.resources.map((resource) => {
63
- const { body, headers, ...rest } = resource;
64
- if (body) {
65
- const id = (0, uuid_1.v4)();
66
- const preparedBody = typeof body === 'string' ? convertTextToBlob(body, headers) : body;
67
- files.push({ id, body: preparedBody });
68
- return { ...rest, headers, id };
69
- }
70
- return resource;
71
- }),
72
- };
73
- }
74
- function createFormData(info, files) {
75
- const formData = new undici_1.FormData();
76
- formData.append('info', JSON.stringify(info));
77
- for (const { id, body } of files) {
78
- formData.append(id, body);
79
- }
80
- return formData;
81
- }
82
- async function sendSnapshot(snapshot, firstSnapshot) {
83
- const files = [];
84
- const preparedSnapshot = prepareSnapshot(snapshot, files);
85
- const info = {
86
- snapshot: preparedSnapshot,
87
- buildId: context_1.buildId,
88
- parallel: context_1.parallel,
89
- ci: context_1.ci,
90
- branch: context_1.branch,
91
- tag: context_1.tag,
92
- pullRequestNumber: context_1.pullRequestNumber,
93
- commit: context_1.commit,
94
- baseCommit: context_1.baseCommit,
95
- pipelineId: context_1.pipelineId,
96
- pipelineName: context_1.pipelineName,
97
- actionId: context_1.actionId,
98
- executionId: context_1.executionId,
99
- invokerId: context_1.invokerId,
100
- commitDetails: context_1.commitDetails,
101
- cliId: context_1.cliId,
102
- executionUrl: context_1.executionUrl,
103
- firstSnapshot,
104
- };
105
- const formData = createFormData(info, files);
106
- const [message, response] = await sendRequest({
107
- path: '/snapshot',
108
- payload: formData,
109
- multipart: true,
110
- });
111
- if (message) {
112
- throw new Error(message);
113
- }
114
- if (!response) {
115
- throw new Error(texts_1.ERR_INVALID_SNAPSHOT_RESPONSE);
116
- }
117
- return response;
118
- }
119
- async function sendSnapshots(snapshots) {
120
- const files = [];
121
- const preparedSnapshots = snapshots.map((snapshot) => prepareSnapshot(snapshot, files));
122
- const info = {
123
- snapshots: preparedSnapshots,
124
- buildId: context_1.buildId,
125
- parallel: context_1.parallel,
126
- ci: context_1.ci,
127
- branch: context_1.branch,
128
- tag: context_1.tag,
129
- pullRequestNumber: context_1.pullRequestNumber,
130
- commit: context_1.commit,
131
- baseCommit: context_1.baseCommit,
132
- pipelineId: context_1.pipelineId,
133
- pipelineName: context_1.pipelineName,
134
- actionId: context_1.actionId,
135
- executionId: context_1.executionId,
136
- invokerId: context_1.invokerId,
137
- commitDetails: context_1.commitDetails,
138
- cliId: context_1.cliId,
139
- executionUrl: context_1.executionUrl,
140
- firstSnapshot: true,
141
- };
142
- const formData = createFormData(info, files);
143
- const [message, response] = await sendRequest({
144
- path: '/snapshots',
145
- payload: formData,
146
- multipart: true,
147
- });
148
- if (message) {
149
- throw new Error(message);
150
- }
151
- if (!response) {
152
- throw new Error(texts_1.ERR_INVALID_SNAPSHOTS_RESPONSE);
153
- }
154
- return response;
155
- }
156
- async function closeSession() {
157
- const payload = {
158
- token: context_1.token,
159
- buildId: context_1.buildId,
160
- };
161
- const [message, response] = await sendRequest({
162
- path: '/close',
163
- payload,
164
- });
165
- if (message) {
166
- throw new Error(message);
167
- }
168
- if (!response) {
169
- throw new Error(texts_1.ERR_INVALID_CLOSE_SESSION_RESPONSE);
170
- }
171
- return response;
172
- }
173
- async function getDefaultSettings() {
174
- const [message, response] = await sendRequest({
175
- path: `/defaultSettings`,
176
- });
177
- if (message) {
178
- throw new Error(message);
179
- }
180
- if (!response) {
181
- throw new Error(texts_1.ERR_INVALID_DEFAULT_SETTINGS_RESPONSE);
182
- }
183
- return response;
184
- }
185
- async function sendStorybook(snapshots, filePaths) {
186
- const info = {
187
- snapshots,
188
- buildId: context_1.buildId,
189
- ci: context_1.ci,
190
- branch: context_1.branch,
191
- tag: context_1.tag,
192
- pullRequestNumber: context_1.pullRequestNumber,
193
- commit: context_1.commit,
194
- baseCommit: context_1.baseCommit,
195
- pipelineId: context_1.pipelineId,
196
- pipelineName: context_1.pipelineName,
197
- actionId: context_1.actionId,
198
- executionId: context_1.executionId,
199
- invokerId: context_1.invokerId,
200
- commitDetails: context_1.commitDetails,
201
- cliId: context_1.cliId,
202
- executionUrl: context_1.executionUrl,
203
- };
204
- const files = filePaths.map((file) => ({
205
- id: file,
206
- body: new Blob([new Uint8Array((0, node_fs_1.readFileSync)(file))]),
207
- }));
208
- const formData = createFormData(info, files);
209
- const [message, response] = await sendRequest({
210
- path: '/storybook',
211
- payload: formData,
212
- multipart: true,
213
- });
214
- if (message) {
215
- throw new Error(message);
216
- }
217
- if (!response) {
218
- throw new Error(texts_1.ERR_INVALID_STORYBOOK_RESPONSE);
219
- }
220
- return response;
221
- }
222
- async function sendCompareLinks(urls, validatedOptions, sitemapSource) {
223
- const info = {
224
- urls,
225
- sitemapSource,
226
- ignores: validatedOptions.ignore ?? [],
227
- cookies: validatedOptions.cookie ?? [],
228
- headers: validatedOptions.header ?? [],
229
- delays: validatedOptions.delay ?? [],
230
- waitFors: validatedOptions.waitFor ?? [],
231
- follow: validatedOptions.follow,
232
- respectRobots: validatedOptions.respectRobots,
233
- ignoreUrls: validatedOptions.ignoreUrls ?? [],
234
- buildId: context_1.buildId,
235
- ci: context_1.ci,
236
- branch: context_1.branch,
237
- tag: context_1.tag,
238
- commit: context_1.commit,
239
- baseCommit: context_1.baseCommit,
240
- pipelineId: context_1.pipelineId,
241
- pipelineName: context_1.pipelineName,
242
- actionId: context_1.actionId,
243
- executionId: context_1.executionId,
244
- invokerId: context_1.invokerId,
245
- commitDetails: context_1.commitDetails,
246
- cliId: context_1.cliId,
247
- };
248
- const [message, response] = await sendRequest({
249
- path: '/compareLinks',
250
- payload: info,
251
- });
252
- if (message) {
253
- throw new Error(message);
254
- }
255
- if (!response) {
256
- throw new Error(texts_1.ERR_INVALID_COMPARE_LINKS_RESPONSE);
257
- }
258
- return response;
259
- }
260
- async function sendScrap(url, outputType, follow, quality, fullPage, cssSelector, xpathSelector, browser, viewport, devicePixelRatio, darkMode, delay, waitForElement) {
261
- const payload = {
262
- url,
263
- follow,
264
- outputType,
265
- quality,
266
- fullPage,
267
- cssSelector,
268
- xpathSelector,
269
- browser,
270
- viewport,
271
- devicePixelRatio,
272
- darkMode,
273
- delay,
274
- waitForElement,
275
- };
276
- const [message, response] = await sendRequest({
277
- path: '/scrap',
278
- payload,
279
- });
280
- if (message) {
281
- throw new Error(message);
282
- }
283
- if (!response) {
284
- throw new Error(texts_1.ERR_INVALID_SCRAP_RESPONSE);
285
- }
286
- return response;
287
- }
288
- async function downloadScrapPackage(buildId) {
289
- const [message, response] = await sendRequest({
290
- path: '/download',
291
- payload: { token: context_1.token, buildId },
292
- });
293
- if (message) {
294
- throw new Error(message);
295
- }
296
- if (!response) {
297
- throw new Error(texts_1.ERR_INVALID_DOWNLOAD_RESPONSE);
298
- }
299
- return response;
300
- }
301
- async function sendRequest({ path, payload, multipart, }) {
302
- const fullUrl = new URL(path, getServiceUrl());
303
- output_1.default.debug((0, texts_1.LOG_SENDING_REQUEST)(fullUrl.toString()));
304
- const isDevToken = checkIfIsDevToken(context_1.token);
305
- const init = {
306
- method: 'GET',
307
- redirect: 'follow',
308
- headers: {
309
- 'X-CLI-VERSION': context_1.cliVersion,
310
- 'X-TOKEN': context_1.token,
311
- },
312
- dispatcher: isDevToken
313
- ? new undici_1.Agent({
314
- connect: {
315
- rejectUnauthorized: false,
316
- },
317
- })
318
- : undefined,
319
- };
320
- if (payload && !multipart) {
321
- init.method = 'POST';
322
- init.headers = {
323
- 'Content-Type': 'application/json',
324
- 'X-TOKEN': context_1.token,
325
- 'X-CLI-VERSION': context_1.cliVersion,
326
- };
327
- init.body = JSON.stringify(payload);
328
- }
329
- if (multipart) {
330
- init.method = 'POST';
331
- init.body = payload;
332
- }
333
- const response = await (0, undici_1.fetch)(fullUrl, init);
334
- const contentType = response.headers.get('content-type');
335
- if (contentType && contentType.includes('application/json')) {
336
- try {
337
- const json = (await response.json());
338
- return [undefined, json];
339
- }
340
- catch {
341
- throw new Error(texts_1.ERR_INVALID_JSON);
342
- }
343
- }
344
- if (contentType && contentType.includes('application/octet-stream')) {
345
- const buffer = response.body;
346
- return [undefined, buffer];
347
- }
348
- const text = await response.text();
349
- return [text, undefined];
350
- }
351
- function connectToScrapSession(buildId) {
352
- return new eventsource_1.EventSource(`${getServiceUrl()}/sse`, {
353
- fetch: (url, options) => {
354
- return (0, undici_1.fetch)(url, {
355
- ...options,
356
- headers: {
357
- ...options?.headers,
358
- 'x-token': context_1.token,
359
- 'x-cli-version': context_1.cliVersion,
360
- 'x-build-id': buildId,
361
- },
362
- });
363
- },
364
- });
365
- }