@percy/client 1.30.6 → 1.30.7-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -9,7 +9,7 @@ import { pool, request, formatBytes, sha256hash, base64encode, getPackageJSON, w
9
9
  const {
10
10
  PERCY_CLIENT_API_URL = 'https://percy.io/api/v1'
11
11
  } = process.env;
12
- const pkg = getPackageJSON(import.meta.url);
12
+ let pkg = getPackageJSON(import.meta.url);
13
13
  // minimum polling interval milliseconds
14
14
  const MIN_POLLING_INTERVAL = 1_000;
15
15
  const INVALID_TOKEN_ERROR_MESSAGE = 'Unable to retrieve snapshot details with write access token. Kindly use a full access token for retrieving snapshot details with Synchronous CLI.';
@@ -77,6 +77,9 @@ export class PercyClient {
77
77
 
78
78
  // Stringifies client and environment info.
79
79
  userAgent() {
80
+ // forcedPkgValue has been added since when percy package is bundled inside Electron app (LCNC)
81
+ // we can't read Percy's package json for package name and version, so we are passing it via env variables
82
+ if (this.env.forcedPkgValue) pkg = this.env.forcedPkgValue;
80
83
  let client = new Set([`Percy/${/\w+$/.exec(this.apiUrl)}`].concat(`${pkg.name}/${pkg.version}`, ...this.clientInfo).filter(Boolean));
81
84
  let environment = new Set([...this.environmentInfo].concat(`node/${process.version}`, this.env.info).filter(Boolean));
82
85
  return `${[...client].join(' ')} (${[...environment].join('; ')})`;
package/dist/proxy.js CHANGED
@@ -4,9 +4,26 @@ import http from 'http';
4
4
  import https from 'https';
5
5
  import logger from '@percy/logger';
6
6
  import { stripQuotesAndSpaces } from '@percy/env/utils';
7
+ import { PacProxyAgent } from 'pac-proxy-agent';
7
8
  const CRLF = '\r\n';
8
9
  const STATUS_REG = /^HTTP\/1.[01] (\d*)/;
9
10
 
11
+ // function to create PAC proxy agent
12
+ export function createPacAgent(pacUrl, options = {}) {
13
+ pacUrl = stripQuotesAndSpaces(pacUrl);
14
+ try {
15
+ const agent = new PacProxyAgent(pacUrl, {
16
+ keepAlive: true,
17
+ ...options
18
+ });
19
+ logger('client:proxy').info(`Successfully loaded PAC file from: ${pacUrl}`);
20
+ return agent;
21
+ } catch (error) {
22
+ logger('client:proxy').error(`Failed to load PAC file, error message: ${error.message}, stack: ${error.stack}`);
23
+ throw new Error(`Failed to initialize PAC proxy: ${error.message}`);
24
+ }
25
+ }
26
+
10
27
  // Returns true if the URL hostname matches any patterns
11
28
  export function hostnameMatches(patterns, url) {
12
29
  let subject = new URL(url);
@@ -196,8 +213,29 @@ export function proxyAgentFor(url, options) {
196
213
  hostname
197
214
  } = new URL(url);
198
215
  let cachekey = `${protocol}//${hostname}`;
199
- if (!cache.has(cachekey)) {
200
- cache.set(cachekey, protocol === 'https:' ? new ProxyHttpsAgent(options) : new ProxyHttpAgent(options));
216
+
217
+ // If we already have a cached agent, return it
218
+ if (cache.has(cachekey)) {
219
+ return cache.get(cachekey);
220
+ }
221
+ try {
222
+ let agent;
223
+ const pacUrl = process.env.PERCY_PAC_FILE_URL;
224
+
225
+ // If PAC URL is provided, use PAC proxy
226
+ if (pacUrl) {
227
+ logger('client:proxy').info(`Using PAC file from: ${pacUrl}`);
228
+ agent = createPacAgent(pacUrl, options);
229
+ } else {
230
+ // Fall back to other proxy configuration
231
+ agent = protocol === 'https:' ? new ProxyHttpsAgent(options) : new ProxyHttpAgent(options);
232
+ }
233
+
234
+ // Cache the created agent
235
+ cache.set(cachekey, agent);
236
+ return agent;
237
+ } catch (error) {
238
+ logger('client:proxy').error(`Failed to create proxy agent: ${error.message}`);
239
+ throw error;
201
240
  }
202
- return cache.get(cachekey);
203
241
  }
package/dist/utils.js CHANGED
@@ -141,9 +141,11 @@ export async function request(url, options = {}, callback) {
141
141
  } = new URL(url);
142
142
 
143
143
  // reference the default export so tests can mock it
144
+ // bundling cli inside electron or another package fails if we import it
145
+ // like this: await import(protocol === 'https:' ? 'https' : 'http');
144
146
  let {
145
147
  default: http
146
- } = await import(protocol === 'https:' ? 'https' : 'http');
148
+ } = protocol === 'https:' ? await import('https') : await import('http');
147
149
  let {
148
150
  proxyAgentFor
149
151
  } = await import('./proxy.js');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/client",
3
- "version": "1.30.6",
3
+ "version": "1.30.7-beta.1",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -33,9 +33,10 @@
33
33
  "test:coverage": "yarn test --coverage"
34
34
  },
35
35
  "dependencies": {
36
- "@percy/env": "1.30.6",
37
- "@percy/logger": "1.30.6",
36
+ "@percy/env": "1.30.7-beta.1",
37
+ "@percy/logger": "1.30.7-beta.1",
38
+ "pac-proxy-agent": "^7.0.2",
38
39
  "pako": "^2.1.0"
39
40
  },
40
- "gitHead": "4f08c2841c452d1d445077a8e465641100b712de"
41
+ "gitHead": "b9a15ba7853ff350b7d7b7c3364700e70ca66643"
41
42
  }