{"_id":"@avocet/sdk","_rev":"2-214bfb032f123e31f0a837d3bd27acfd","name":"@avocet/sdk","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@avocet/sdk","version":"1.0.0","keywords":["feature flag","experiment"],"author":{"url":"https://avocet-experimentation.github.io","name":"Avocet Team"},"license":"MIT","_id":"@avocet/sdk@1.0.0","maintainers":[{"name":"nanobot","email":"adnan@ashihabi.me"},{"name":"gautam-panakkal","email":"gautampanakkal@gmail.com"}],"contributors":[{"url":"https://github.com/gpanakkal","name":"Gautam Panakkal","email":"gautampanakkal@gmail.com"},{"url":"https://ashihabi.me","name":"Adnan O. Shihabi","email":"adnan@ashihabi.me"},{"url":"https://www.linkedin.com/in/sean-mentele-58481417a","name":"Sean Mentele","email":"sean.a.mentele@gmail.com"}],"homepage":"https://avocet-experimentation.github.io","bugs":{"url":"https://github.com/avocet-experimentation/packages/issues"},"dist":{"shasum":"3cf30a5d0214e86b21ab50eba037595212d2cc34","tarball":"https://registry.npmjs.org/@avocet/sdk/-/sdk-1.0.0.tgz","fileCount":12,"integrity":"sha512-D9hqbLVXEyMM9zCojdaPr0wHBORNJ4eidoAmV/Gatomd4BfpN1dA47oiHz8hfphev8GqeDe6ddXk9g627X9wsw==","signatures":[{"sig":"MEQCIAomF0r/XTpzI4WshMa0CV1porE7dUrmlk7YXrWZu2NnAiBrXdMEiLHkas+1MGokw/5HS8jD0G/VPFE2+TFI9/xI4A==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":19391},"main":"dist/index.js","type":"module","types":"dist/index.d.ts","gitHead":"bb5149ab15f283ed616f75a185701eaac0927357","scripts":{"test":"vitest run","build":"npm i && rm -rf ./dist && tsc","rebuild":"rm -rf ./dist && tsc"},"_npmUser":{"name":"gautam-panakkal","email":"gautampanakkal@gmail.com"},"repository":{"url":"git+https://github.com/avocet-experimentation/packages.git","type":"git","directory":"mongo-client"},"_npmVersion":"10.8.3","description":"SDK for fetching feature flags from Avocet","directories":{"lib":"dist","test":"__tests__"},"_nodeVersion":"22.9.0","dependencies":{"quick-lru":"^7.0.0","@avocet/core":"^1.0.0"},"_hasShrinkwrap":false,"devDependencies":{},"_npmOperationalInternal":{"tmp":"tmp/sdk_1.0.0_1737756383158_0.5870271974507475","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@avocet/sdk","version":"1.0.1","description":"JavaScript SDK for fetching feature flags from Avocet","keywords":["feature flag","experiment"],"homepage":"https://avocet-experimentation.github.io","author":{"name":"Avocet Team","url":"https://avocet-experimentation.github.io"},"contributors":[{"name":"Gautam Panakkal","email":"gautampanakkal@gmail.com","url":"https://github.com/gpanakkal"},{"name":"Adnan O. Shihabi","email":"adnan@ashihabi.me","url":"https://ashihabi.me"},{"name":"Sean Mentele","email":"sean.a.mentele@gmail.com","url":"https://www.linkedin.com/in/sean-mentele-58481417a"}],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/avocet-experimentation/packages.git","directory":"avocet-sdk"},"main":"dist/index.js","types":"dist/index.d.ts","directories":{"lib":"dist","test":"__tests__"},"scripts":{"build":"npm i && rm -rf ./dist && tsc","rebuild":"rm -rf ./dist && tsc","test":"vitest run"},"type":"module","dependencies":{"@avocet/core":"^1.0.0","quick-lru":"^7.0.0"},"devDependencies":{},"bugs":{"url":"https://github.com/avocet-experimentation/packages/issues"},"_id":"@avocet/sdk@1.0.1","gitHead":"9e022454425bbcbac178eddbed20236cd08c8e90","_nodeVersion":"22.9.0","_npmVersion":"10.8.3","dist":{"integrity":"sha512-S/xYy4Lr3qDUy4jQsnDdS4+8F39DXnHyP6c3BvwOmJVJxEKfOGVlwL7V3XD9ADyAHszjZQ9igKs8pxmNXen+5A==","shasum":"a99de11e999d220a8220f6f081cd408df38ce229","tarball":"https://registry.npmjs.org/@avocet/sdk/-/sdk-1.0.1.tgz","fileCount":12,"unpackedSize":19400,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCICgOJw6NwyX+Zf3OGB3PWax4z7wfrgBpxVuTDMbIS/vkAiA8GFHC5Mgp42qqCH8enr6iztd3+FzCnsFKI9vOz98ANA=="}]},"_npmUser":{"name":"gautam-panakkal","email":"gautampanakkal@gmail.com"},"maintainers":[{"name":"nanobot","email":"adnan@ashihabi.me"},{"name":"gautam-panakkal","email":"gautampanakkal@gmail.com"},{"name":"seanm0124","email":"sean.a.mentele@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_1.0.1_1738020808042_0.29728654036607116"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-24T22:06:23.014Z","modified":"2025-01-27T23:33:28.473Z","1.0.0":"2025-01-24T22:06:23.401Z","1.0.1":"2025-01-27T23:33:28.227Z"},"bugs":{"url":"https://github.com/avocet-experimentation/packages/issues"},"author":{"name":"Avocet Team","url":"https://avocet-experimentation.github.io"},"license":"MIT","homepage":"https://avocet-experimentation.github.io","keywords":["feature flag","experiment"],"repository":{"type":"git","url":"git+https://github.com/avocet-experimentation/packages.git","directory":"avocet-sdk"},"description":"JavaScript SDK for fetching feature flags from Avocet","contributors":[{"name":"Gautam Panakkal","email":"gautampanakkal@gmail.com","url":"https://github.com/gpanakkal"},{"name":"Adnan O. Shihabi","email":"adnan@ashihabi.me","url":"https://ashihabi.me"},{"name":"Sean Mentele","email":"sean.a.mentele@gmail.com","url":"https://www.linkedin.com/in/sean-mentele-58481417a"}],"maintainers":[{"name":"nanobot","email":"adnan@ashihabi.me"},{"name":"gautam-panakkal","email":"gautampanakkal@gmail.com"},{"name":"seanm0124","email":"sean.a.mentele@gmail.com"}],"readme":"# `avocet-sdk`\n\nJavaScript SDK for fetching feature flags from [Avocet](https://avocet-experimentation.github.io), an open-source feature flagging and software experimentation platform.\n\n## Setup\n\n1. From the Avocet dashboard, create an SDK connection to generate an API key, or select an existing one.\n2. Install the package: `npm install @avocet/sdk`.\n3. Initialize the SDK in the application in which you wish to add feature flags:\n\n```ts\nimport { AvocetClient } from '@avocet/sdk';\nimport { Span } from '@opentelemetry/api'; // we use OpenTelemetry as an example, but other providers work\n\nconst avocetClient = AvocetClient.start({\n  apiKey: '', // replace with API key from an SDK connection\n  apiUrl: '', // public endpoint of the flagging API\n  attributeAssignmentCb: (attributes: Record<string, string>, span: Span) => {\n    span.setAttributes(attributes);\n  }, // an optional callback defining how to save flag attributes onto telemetry data\n  autoRefresh: true, // if true, periodically fetches data for all flags in the environment\n  refreshIntervalInSeconds: 300, // defaults to 300 seconds (5 minutes)\n  useStale: true, // defaults to true. If set to true, cached flag data will be retained when refreshing\n  clientProps: {\n    // client properties will be formatted and included in the attributes argument to the assignment callback\n    id: 'my-user-id'\n  }\n});\n\nexport default avocetClient;\n```\n\n## Usage\n\n1. Define flags in the Avocet dashboard.\n2. Use them to guide control flow, either with synchronous checks:\n\n```ts\nimport avocetClient from './feature-flagging.ts';\n\nif (avocetClient.get('my-boolean-flag') === true) {\n  // feature logic\n} else {\n  // fallback logic\n}\n```\n\nor asynchronous checks, fetching the most up-to-date value of the flag:\n\n```ts\nconst flagValue = await avocetClient.getLive('my-number-flag');\nif (flagValue === 2) {\n  // logic for first version of the feature\n} else if (flagValue === 1) {\n  // logic for second version of the feature\n} else {\n  // fallback logic\n}\n```\n\nIf the SDK was initialized with an attribute assignment callback, you have the option to pass telemetry data into `.get`, which triggers the callback:\n\n```ts\nif (avocetClient.get('my-boolean-flag', currentSpan) === true) {\n  // feature logic\n} else {\n  // fallback logic\n}\n```\n\nEnable or disable flag refreshing:\n\n```ts\navocetClient.startPolling();\navocetClient.stopPolling();\n```\n\nInstead of using the attribute assignment callback, you can get attribute data directly:\n\n```ts\nconst { value, attributes } = avocetClient.getWithAttributes('my-string-flag');\n```\n","readmeFilename":"README.md"}