Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@spotify-confidence/sdk

Package Overview
Dependencies
Maintainers
4
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@spotify-confidence/sdk - npm Package Compare versions

Comparing version 0.0.5 to 0.0.7

dist/index.d.ts

25

CHANGELOG.md
# Changelog
## [0.0.7](https://github.com/spotify/confidence-sdk-js/compare/sdk-v0.0.6...sdk-v0.0.7) (2024-05-28)
### 🐛 Bug Fixes
* npm deployment ([#146](https://github.com/spotify/confidence-sdk-js/issues/146)) ([0c93173](https://github.com/spotify/confidence-sdk-js/commit/0c931732a8c8df4b73d5e7a5b3bcda21684cb441))
## [0.0.6](https://github.com/spotify/confidence-sdk-js/compare/sdk-v0.0.5...sdk-v0.0.6) (2024-05-27)
### 🐛 Bug Fixes
* widen flag return types ([#142](https://github.com/spotify/confidence-sdk-js/issues/142)) ([6554e8c](https://github.com/spotify/confidence-sdk-js/commit/6554e8c83c6c49103f11fbdcf3f53c5576870788))
### ✨ New Features
* confidence flag api ([#141](https://github.com/spotify/confidence-sdk-js/issues/141)) ([3583415](https://github.com/spotify/confidence-sdk-js/commit/3583415957915a4d181316b66e5549071836799f))
* send context as a struct ([#144](https://github.com/spotify/confidence-sdk-js/issues/144)) ([2f73b3b](https://github.com/spotify/confidence-sdk-js/commit/2f73b3b519082fa58a64de3d3be957571dc72a00))
### 📚 Documentation
* update main README.md ([#134](https://github.com/spotify/confidence-sdk-js/issues/134)) ([730fceb](https://github.com/spotify/confidence-sdk-js/commit/730fcebbc87fdab7b39817ab61e1ef23951e3466))
## [0.0.5](https://github.com/spotify/confidence-openfeature-provider-js/compare/sdk-v0.0.4...sdk-v0.0.5) (2024-05-03)

@@ -4,0 +29,0 @@

33

package.json
{
"name": "@spotify-confidence/sdk",
"license": "Apache-2.0",
"version": "0.0.5",
"module": "build/esm/index.js",
"main": "build/cjs/index.js",
"types": "build/types/index.d.ts",
"version": "0.0.7",
"types": "dist/index.d.ts",
"engineStrict": true,

@@ -13,15 +11,26 @@ "engines": {

"scripts": {
"build:esm": "tsc -p tsconfig.esm.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:types": "tsc -p tsconfig.types.json",
"clean": "rm -rf build"
"gen:proto": "protoc --plugin=$(yarn bin protoc-gen-ts_proto) --ts_proto_out=src/generated -I proto proto/confidence/flags/resolver/v1/api.proto --ts_proto_opt=outputEncodeMethods=false --ts_proto_opt=outputPartialMethods=false && prettier --config ../../prettier.config.js -w src/generated",
"build": "tsc",
"bundle": "rollup -c && api-extractor run"
},
"publishConfig": {
"access": "public"
"registry": "https://registry.npmjs.org/",
"access": "public",
"types": "dist/index.d.ts",
"main": "dist/index.js"
},
"dependencies": {
"@spotify-confidence/client-http": "0.1.6",
"web-vitals": "^3.5.2"
},
"gitHead": "9cc79a28acd7b00a5e7e341229081e854d0b5292"
}
"files": [
"dist/index.*"
],
"devDependencies": {
"@microsoft/api-extractor": "*",
"prettier": "*",
"rollup": "*",
"ts-proto": "^1.171.0"
},
"type": "module",
"main": "dist/index.js"
}
# Confidence SDK
![](https://img.shields.io/badge/lifecycle-beta-a0c3d2.svg)
JavaScript implementation of the Confidence SDK, enables event tracking and feature flagging capabilities in conjunction wth the OpenFeature Web SDK.
# Usage
## Adding the dependencies
To add the packages to your dependencies run:
```sh
yarn add @spotify-confidence/sdk
```
## Initializing the SDK
Run the `Confidence.create` function to obtain a root instance of `Confidence`.
```ts
import { Confidence } from '@spotify-confidence/sdk';
const confidence = Confidence.create({
clientSecret: 'mysecret',
region: 'eu',
environment: 'client',
timeout: 1000,
});
```
### Region
The region option is used to set the region for the network request to the Confidence backend. When the region is not set, the default (global) region will be used.
The current regions are: `eu` and `us`, the region can be set as follows:
```ts
const provider = createConfidenceWebProvider({
region: 'eu', // or 'us'
// ... other options
});
```
### Timeout
The timeout option is used to set the timeout for the feature flag resolve network request to the Confidence backend. When the timeout is reached, default values will be returned.
## Setting the context
You can set the context manually by using `setContext({})`:
```ts
confidence.setContext({ 'pants-color': 'yellow' });
```
or obtain a "child instance" of Confidence with a modified context by using `withContext({})`
```ts
const childInstance = confidence.withContext({ 'pants-color': 'blue', 'pants-fit': 'slim' });
```
At this point, the context of `childInstance` is `'pants-color': 'blue', 'pants-fit': 'slim'` while the context of `confidence` remains `{'pants-color': 'yellow'}`.
## Event tracking
Use `confidence.track()` from any Confidence instance to track an event in Confidence. Any context data set on the instance will be appended to the tracking event.
```ts
confidence.track('event_name', { 'message-detail1': 'something interesting' });
```
### Auto track
Confidence supports automatically tracking certain things out of the box and supports API's for you to extend that functionality.
To automatically track `page views`, use the following:
```ts
import { Confidence, pageViews } from '@spotify-confidence/sdk';
confidence.track(pageViews());
```
and to automatically track events containing web vitals data, use:
```ts
import { Confidence, webVitals } from '@spotify-confidence/sdk';
confidence.track(webVitals());
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc