{"name":"@percy/sdk-utils","version":"1.0.0","license":"MIT","_id":"@percy/sdk-utils@1.0.0","homepage":"https://github.com/percy/cli#readme","bugs":{"url":"https://github.com/percy/cli/issues"},"dist":{"shasum":"8ce7b06619c93081ef5a73c1df4c01ffad79e99a","tarball":"http://registry-npm.ywwl.com/@percy/sdk-utils/download/@percy/sdk-utils-1.0.0.tgz","fileCount":3,"integrity":"sha512-2gA64hhLwR7Wc0WuTmzsrvMGXtaxkOmvEydnDEUXAxweIIRZJNUzDpPPxKpM6bM5xqpIleQHC7QV7lpmGoP4Hg==","signatures":[{"sig":"MEYCIQCLtdT36uU6O0+/RzZDbgXw1yOseaUkq3b0sODWQC28SAIhAMdZMw4bnnIe8jmPLVwrBAezyt8qx2IpTGIWzUttt8+L","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":6082,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiR10OACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqk1A/+NawqV4mbspz/nsH/lrSbc2/Ij0HFaWwnopZIHgxVTg5Gm+/I\r\n/iSXzN3eLkHpJ06tMhj6/MUwsePWZxi6sF7O5jYBMocYtCQdZ4CzMFhuBuuh\r\nkZkxp6BkMJ+FXyf9NYTPv6TyCFxjwdgVfs80jgqTpuPa94p+g9sYi+LeLOT0\r\nwyZNU+n6+iPFfH3Oiw8s1vPU3MFXsLQcFl+Jmo9DiyJatLKt62LbOBqB7cRm\r\nUBBAzNK7A2/CJlREENku9gd0tWX+K/SZo7jaSNAc+TpaqRAwcAX99NrjPBm9\r\nvX8w4Dbye1Ywe1TsPfSFBtkGHXGcnBNw92IIbVfCUbHvi5gW7jeVk5aY3slf\r\nMv48eqn/FMJktkF52nxUdYMFFd1AOtVkMzi0Ucumnm3cf40N9ZSBOooccE55\r\nkIJDHUjjj6waDKWSozKQK4itUY17ktbeeMJeL0g6Bdy5FvU5RJ+jmn0zCE6D\r\nPfDXz4gp+Z90lDjQfXOGjU9qDoN61t3KEjZMdJ0xeWqzSVrbJcYUed3rAOOz\r\nAtAXcW2e0dmvkzInZhw+KT/0Fp0fQOM5R6C0wm/1LhaFtyg9SeTiNz7amcXT\r\nKxocXtHU+r6JR+bYME3AFFd4H9Zm8tEPXzFNVR15+Ay7V45y8IO9cbfhpXVO\r\nz5CI9l9ZlPNx6vO/xu7iBx3hTnuVbeypI9U=\r\n=wsvX\r\n-----END PGP SIGNATURE-----\r\n","size":2828,"noattachment":false,"key":"/@percy/sdk-utils/-/@percy/sdk-utils-1.0.0.tgz"},"main":"./dist/index.js","type":"module","karma":{"run_start":"node test/server start","run_complete":"node test/server stop"},"rollup":{"test":{"output":{"globals":{"@percy/logger":"PercySDKUtils.logger"}},"external":["@percy/logger","test/server(.js)?"]},"output":{"name":"PercySDKUtils"},"external":["ws"]},"browser":"./dist/bundle.js","engines":{"node":">=14"},"exports":{".":"./dist/index.js","./test/client":"./test/client.js","./test/server":"./test/server.js","./test/helpers":"./test/helpers.js"},"gitHead":"6df509421a60144e4f9f5d59dc57a5675372a0b2","scripts":{"lint":"eslint --ignore-path ../../.gitignore .","test":"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/4.0.0/node@v14.19.1+x64 (linux)","description":"Common JavaScript SDK utils","directories":{},"_nodeVersion":"14.19.1","dependencies":{"@percy/logger":"1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/sdk-utils_1.0.0_1648844046440_0.299133636865786","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":1648844046588,"maintainers":[{"name":"percy-admin","email":"apps+npm@percy.io"}],"_cnpm_publish_time":1648844046588,"dist-tags":{"alpha":"1.31.15-alpha.0","beta":"1.33.2-beta.0","latest":"1.33.1"}}