{"name":"@percy/sdk-utils","version":"1.21.0","license":"MIT","_id":"@percy/sdk-utils@1.21.0","homepage":"https://github.com/percy/cli#readme","bugs":{"url":"https://github.com/percy/cli/issues"},"dist":{"shasum":"57b2ce73e7ea9a86e9f69d40e89f56f8dd294476","tarball":"http://registry-npm.ywwl.com/@percy/sdk-utils/download/@percy/sdk-utils-1.21.0.tgz","fileCount":16,"integrity":"sha512-ZI6QbIhMZvE3P73ar7aeXcjSk8/czlS7h55QBynoJNorwimq5xed1CGPHu00uQsCO6dXeEKTfxQcqbCypRE6Hw==","signatures":[{"sig":"MEUCIQDk1dk3uv2ID7mqctmZ5RjuDgWPDdNADOoxY8rGaIIGHgIgQ2ZEh5oXlLX8f0TeZKIidMUcm9/Swdq32+BwlH5meik=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":35974,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkEaHxACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp0Cw/8D7vddwA6wTD56kZvnJuHgYKKma98jqu8vnuQoemWK8Hly1vD\r\nVJuhbjJywI/ucg27eH1ZRj4S5nisa+MPu6/uff0L8DT8NwlIpmLhnQrL31kC\r\nw9Iq4eZ72EhM6bHjEfH7jTBcR+dj9rDNa+fvS8IY5bIx9TB+4BWqqWDScoOS\r\nuHucpRirabq3GPNDNiZjFay1aQkLR8v+hm5/5S89uZ5QbfzV82b5FH3fgfZN\r\nUGXv81PnB9cqy+X3/DyOZFmDL4oqLq3WnPLPEY5VugvnDvAeGozPBtPmE78j\r\nPeQQHE05L3wzHWDllzKzaZcFWMyVF2v83GCq/CFclJqeSUqgTiYv1AW5tvFH\r\nOQ/WTvvVbvcUERQOaDU3CgpJRKXu6BUPcfF4Tz9Ya1Xnz6JZa5gt3CB1zMBK\r\ni/AdLxz2W1WwOgmBW6HOE3cX2F3QdgNDlk4vTigqilXd8h5Q2VDSbAezSS5K\r\nbXc8qvZfH1ROFJf6GL6b443LrrBrhEtblWG+uF0HnU1DrzPYmOVD7wi//Dj8\r\nogtKLf499mU0/ntKqCTdlANBtZmm0tLvIvaV3mffCzRTQzEadN/2RE0wA/1h\r\n8dlGQM2H6VC+exBb5Ml0UsW9kU+U2Qx7Zh1isiPKOGhUI5aVzAg06mgS3no0\r\n6momXMNNp39N5VP1D21cLZtSb3vatqOd49c=\r\n=EbrH\r\n-----END PGP SIGNATURE-----\r\n","size":8837,"noattachment":false,"key":"/@percy/sdk-utils/-/@percy/sdk-utils-1.21.0.tgz"},"main":"./dist/index.js","rollup":{"test":{"external":["test/server(.js)?"]},"output":{"name":"PercySDKUtils"},"external":["ws"]},"browser":"./dist/bundle.js","engines":{"node":">=14"},"exports":{".":{"node":"./dist/index.js","default":"./dist/bundle.js"},"./test/helpers":{"node":"./test/helpers.js","default":"./test/client.js"}},"gitHead":"44c63a3214f1fbfb0b1adcb6fcfe284a9f54d0cb","scripts":{"lint":"eslint --ignore-path ../../.gitignore .","test":"percy exec --testing -- node ../../scripts/test","build":"node ../../scripts/build","test:coverage":"yarn test --coverage"},"_npmUser":{"name":"percy-admin","email":"apps+npm@percy.io"},"repository":{"url":"git+https://github.com/percy/cli.git","type":"git","directory":"packages/sdk-utils"},"_npmVersion":"lerna/6.0.1/node@v14.21.3+x64 (linux)","description":"Common JavaScript SDK utils","directories":{},"_nodeVersion":"14.21.3","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sdk-utils_1.21.0_1678877169661_0.970477102102091","host":"s3://npm-registry-packages"},"readme":"# @percy/sdk-utils\n\nCommon JavaScript SDK utils\n\n- [Usage](#usage)\n  - [`logger()`](#loggerdebug)\n  - [`percy`](#percy)\n  - [`isPercyEnabled()`](#ispercyenabled)\n  - [`postSnapshot()`](#postsnapshot)\n  - [`request`](#requesturl-options)\n\n## Usage\n\n### `logger([debug])`\n\nThis function is a direct export of [`@percy/logger`](./packages/logger).\n\n### `percy`\n\nThis object contains information about the local Percy environment and is updated when\n[`isPercyEnabled`](#ispercyenabled) is called for the first time.\n\n``` js\nimport { percy } from '@percy/sdk-utils'\n\n// reflects/updates process.env.PERCY_SERVER_ADDRESS\npercy.address === 'http://localhost:5338'\n\n// updated after isPercyEnabled() is called\npercy.enabled === true|false\npercy.version.major === 1\npercy.version.minor === 2\npercy.version.patch === 3\npercy.version.toString() === '1.2.3'\npercy.config === {} // .percy.yml config\n\n// updated after fetchPercyDOM() is called\npercy.domScript === fs.readFile(require.resolve('@percy/dom'))\n```\n\n### `isPercyEnabled()`\n\nReturns `true` or `false` if the Percy CLI API server is running. Calls the server's `/healthcheck`\nendpoint and populates information for the [`percy`](#percy) property. The result of this function\nis cached and subsequent calls will return the first cached result. If the healthcheck fails, will\nlog a message unless the CLI loglevel is `quiet` or `silent`.\n\n``` js\nimport { isPercyEnabled } from '@percy/sdk-utils'\n\n// CLI API not running\nawait isPercyEnabled() === false\n// [percy] Percy is not running, disabling snapshots\n\n// CLI API is running\nawait isPercyEnabled() === true\n```\n\n### `fetchPercyDOM()`\n\nFetches and returns the `@percy/dom` serialization script hosted by the local Percy API server. The\nresulting string can be evaluated within a browser context to add the `PercyDOM.serialize` function\nto the global scope. Subsequent calls return the first cached result.\n\n``` js\nimport { fetchPercyDOM } from '@percy/sdk-utils'\n\nlet script = await fetchPercyDOM()\n\n// selenium-webdriver\ndriver.executeScript(script)\n// webdriverio\nbrowser.execute(script)\n// puppeteer\npage.evaluate(script)\n// protractor\nbrowser.executeScript(script)\n// etc...\n```\n\n### `postSnapshot(options)`\n\nPosts snapshot options to the local Percy API server.\n\n``` js\nimport { postSnapshot } from '@percy/sdk-utils'\n\nawait postSnapshot({\n  // required\n  name: 'Snapshot Name',\n  url: 'http://localhost:8000/',\n  domSnapshot: 'result from PercyDOM.serialize()'\n  // optional\n  environmentInfo: ['<lib>/<version>', '<lang>/<version>'],\n  clientInfo: '<sdk>/<version>',\n  widths: [475, 1280],\n  minHeight: 1024,\n  enableJavaScript: false,\n  requestHeaders: {}\n})\n```\n\n### `request(url[, options])`\n\nSends a request to the local Percy API server. Used internally by the other SDK utils.\n\n``` js\nimport { request } from '@percy/sdk-utils'\n\nawait request('/percy/idle')\nawait request('/percy/stop')\n```\n\n#### `request.fetch(url, options)`\n\nThe underlying implementation of the `request()` util. For Node environments, `http.request` is\nused; for browser environments, `window.fetch` is used. Can be overridden by the SDK's framework to\nwork around CORS/CSP issues.\n\nThe returned object must contain the following normalized properties from the request response:\n`status`, `statusText`, `headers`, `body`\n\n``` js\nimport { request } from '@percy/sdk-utils'\n\n// Cypress SDK example\nrequest.fetch = async function fetch(url, options) {\n  options = { url, retryOnNetworkFailure: false, ...options }\n  return Cypress.backend('http:request', options)\n}\n```\n","publish_time":1678877169885,"maintainers":[{"name":"percy-admin","email":"apps+npm@percy.io"}],"_cnpm_publish_time":1678877169885,"dist-tags":{"alpha":"1.31.15-alpha.0","beta":"1.33.2-beta.0","latest":"1.33.1"}}