{"name":"@percy/sdk-utils","version":"1.0.0-beta.23","license":"MIT","_id":"@percy/sdk-utils@1.0.0-beta.23","dist":{"shasum":"440109b7b41c5a1444814a5b360381fca0f3545f","tarball":"http://registry-npm.ywwl.com/@percy/sdk-utils/download/@percy/sdk-utils-1.0.0-beta.23.tgz","fileCount":5,"integrity":"sha512-PPOB2/0aRfKnRLMtKKtvKII4wrqZusHQr6cUjza9barDQdsrC5WQV+r86D4ECUFJVrD1OQp45kx1D9WQw430kg==","signatures":[{"sig":"MEYCIQDIUnM8BqNBqYG4cBcN3rhOnXw16TlUXbJmBiBN0KmWpgIhANaN5/Ap/JpSRKOikEAx+nkupnM4hvcnx+c1vbSpltyw","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10547,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJftAgRCRA9TVsSAnZWagAAOEQP/iUbOvld+9uA9k/CQhNB\nshaR0uB7j60ZiD7QKU+JyGH6kB3cP8JQ5tlKiK9M7kiCez1XFfkrrU8y5EOh\nayAX7D4WplMfbOWbUbnqxOmPzyz6Ih5oR9WO1uxfD7VFvOe0FdUja/pwYPVo\nhyqiA53PEJrrKF+fu5iN7srizG6LF2E97eY+Q8eqhaTCNy8Fe3JSmfhZeXSE\nwT5ywRhFSv2SyZ8i5IPP6WBqeQfieOAvCZFlWD/7XYr7gxVOkx3suyYQBS/b\nMMFpSimnrO39q3oSPWGbpW9fYydPpdBKs1vDbH2i2JpPv0HdKzX3xtTtyitH\n71YQdzgfB6rT7ORgso2SLPVWtvsI65kP+SwL2sR/P6bxHC9IufhagRxNRoU+\n6XzLM0ytywXZ96ah+wmMkmKHF2h9XxnYODAsuHM1OwU8tqJ7Kp+2FpBg5j1y\n4XPRv3KMesQ8NOKwHTKvZ86UkksCBTKfe4eZij82XzYeoW+QjdlQ+MHaz6MD\n8Y/OdpMumC+pLPe9Kv40UlYh03N0eVL4u34TjUVmcLlrQ1EPkiPvFTmagTDS\nyJV5Jvbzh4Y23gtTBbMF4Waw1N4dcJm6yUeH4WGKjurNE2iKHtGGaXO91UxF\nhoJYiVvnvRkc1y9e7bEI/H1W/DqyAlDrz8J/wTXr23lFusA2+8QzIBFhINrH\nX+zd\r\n=P3Of\r\n-----END PGP SIGNATURE-----\r\n","size":4429,"noattachment":false,"key":"/@percy/sdk-utils/-/@percy/sdk-utils-1.0.0-beta.23.tgz"},"main":"index.js","mocha":{"require":"../../scripts/babel-register"},"gitHead":"a80cdeb7b97f0806983cc1d0b02ce7d99fdfaed5","scripts":{"lint":"eslint --ignore-path ../../.gitignore .","test":"cross-env NODE_ENV=test mocha","test:coverage":"nyc yarn test"},"_npmUser":{"name":"percy-admin","email":"apps+npm@percy.io"},"_npmVersion":"lerna/3.22.1/node@v12.19.0+x64 (linux)","description":"Common Node SDK utils","directories":{},"_nodeVersion":"12.19.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sdk-utils_1.0.0-beta.23_1605634065202_0.739202366069732","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":1605634065414,"maintainers":[{"name":"percy-admin","email":"apps+npm@percy.io"}],"_cnpm_publish_time":1605634065414,"dist-tags":{"alpha":"1.31.15-alpha.0","beta":"1.33.2-beta.0","latest":"1.33.1"}}