@spotify-confidence/sdk
Advanced tools
Comparing version 0.0.5 to 0.0.7
# 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 @@ |
{ | ||
"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()); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
88
2
Yes
258329
4
6
2612
3
- Removed@spotify-confidence/client-http@0.1.6(transitive)