@spotify-confidence/sdk
Advanced tools
Comparing version 0.1.4 to 0.1.6
# Changelog | ||
## [0.1.6](https://github.com/spotify/confidence-sdk-js/compare/sdk-v0.1.5...sdk-v0.1.6) (2024-08-20) | ||
### 🐛 Bug Fixes | ||
* use main&module instead of exports ([5cc01b6](https://github.com/spotify/confidence-sdk-js/commit/5cc01b6c4f7cc9d0857e35ddfcca5cad3ae4d85b)) | ||
### 🧹 Chore | ||
* update package json to expose both es and cjs ([5cc01b6](https://github.com/spotify/confidence-sdk-js/commit/5cc01b6c4f7cc9d0857e35ddfcca5cad3ae4d85b)) | ||
### 📚 Documentation | ||
* add documentation to the SDK to resolve MD warnings ([#177](https://github.com/spotify/confidence-sdk-js/issues/177)) ([956594b](https://github.com/spotify/confidence-sdk-js/commit/956594b3f666de3eb9567f7b4855d69a6057d2d0)) | ||
## [0.1.5](https://github.com/spotify/confidence-sdk-js/compare/sdk-v0.1.4...sdk-v0.1.5) (2024-07-08) | ||
### 🐛 Bug Fixes | ||
* infinite in memory flag cache ([#170](https://github.com/spotify/confidence-sdk-js/issues/170)) ([9156dd7](https://github.com/spotify/confidence-sdk-js/commit/9156dd70942f295c4f45125137c022526b15ffdb)) | ||
* shared requests aborted ([#169](https://github.com/spotify/confidence-sdk-js/issues/169)) ([9dc6314](https://github.com/spotify/confidence-sdk-js/commit/9dc6314fab1028af940a672adc5811ec35c570ea)) | ||
## [0.1.4](https://github.com/spotify/confidence-sdk-js/compare/sdk-v0.1.3...sdk-v0.1.4) (2024-06-05) | ||
@@ -4,0 +29,0 @@ |
@@ -19,9 +19,23 @@ declare class AccessiblePromise<T> { | ||
/** | ||
* Utility functions to manage Closer types | ||
* @public | ||
*/ | ||
export declare namespace Closer { | ||
/** Combine multiple closers */ | ||
export function combine(...closers: Closer[]): Closer; | ||
} | ||
/** | ||
* Utility functions to manage Closer types | ||
* @public | ||
*/ | ||
export declare type Closer = () => void; | ||
/** | ||
* Class containing main Confidence APIs | ||
* @public | ||
*/ | ||
export declare class Confidence implements EventSender, Trackable, FlagResolver { | ||
/** Internal Confidence configurations */ | ||
readonly config: Configuration; | ||
@@ -36,33 +50,86 @@ private readonly parent?; | ||
constructor(config: Configuration, parent?: Confidence); | ||
/** Returns currently used environment */ | ||
get environment(): string; | ||
private sendEvent; | ||
private contextEntries; | ||
/** Returns context of the current Confidence instance */ | ||
getContext(): Context; | ||
/** Set Confidence context */ | ||
setContext(context: Context): boolean; | ||
/** Clears context of current Confidence instance */ | ||
clearContext(): void; | ||
/** | ||
* Creates a new Confidence instance with context | ||
* @param context - Confidence context | ||
* @returns Confidence instance | ||
*/ | ||
withContext(context: Context): Confidence; | ||
/** | ||
* Tracks an event | ||
* @param name - event name | ||
* @param data - data to track */ | ||
track(name: string, data?: EventData): void; | ||
/** | ||
* Sets up a Trackable.Manager to manage event tracking or context changes. | ||
* @param manager - event manager | ||
*/ | ||
track(manager: Trackable.Manager): Closer; | ||
/** Resolves all flags in cache */ | ||
protected resolveFlags(): AccessiblePromise<void>; | ||
/** | ||
* Shows flag state | ||
* @returns flag state - READY, NOT_READY, STALE or ERROR | ||
*/ | ||
get flagState(): State; | ||
/** Subscribe to flag changes in Confidence */ | ||
subscribe(onStateChange?: StateObserver): () => void; | ||
private evaluateFlagAsync; | ||
/** Evaluates a flag */ | ||
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>; | ||
/** Returns flag value for a given flag */ | ||
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>; | ||
/** | ||
* Creates a Confidence instance | ||
* @param clientSecret - clientSecret found on the Confidence console | ||
* @param region - region in which Confidence will operate | ||
* @param timeout - timeout for flag resolves | ||
* @param environment - can be either "client" or "backend" | ||
* @param fetchImplementation - fetch implementation | ||
* @param logger - debug logger | ||
* @returns | ||
*/ | ||
static create({ clientSecret, region, timeout, environment, fetchImplementation, logger, }: ConfidenceOptions): Confidence; | ||
} | ||
/** | ||
* Confidence options, to be used for easier initialization of Confidence | ||
* @public | ||
* */ | ||
export declare interface ConfidenceOptions { | ||
/** Client secret, to be found in Confidence console*/ | ||
clientSecret: string; | ||
/** Region in which Confidence will operate */ | ||
region?: 'eu' | 'us'; | ||
/** Resolve URL */ | ||
resolveUrl?: string; | ||
/** Environment: can be either client of backend */ | ||
environment: 'client' | 'backend'; | ||
/** Fetch implementation */ | ||
fetchImplementation?: SimpleFetch; | ||
/** Resolve timeout */ | ||
timeout: number; | ||
/** Debug logger */ | ||
logger?: Logger; | ||
} | ||
/** | ||
* Confidence configuration | ||
* @public | ||
*/ | ||
export declare interface Configuration { | ||
/** Environment: can be either client of backend */ | ||
readonly environment: 'client' | 'backend'; | ||
/** Debug logger */ | ||
readonly logger: Logger; | ||
/** Resolve timeout */ | ||
readonly timeout: number; | ||
@@ -73,5 +140,12 @@ /* Excluded from this release type: eventSenderEngine */ | ||
/** | ||
* Confidence context | ||
* @public | ||
*/ | ||
export declare interface Context extends Value.Struct { | ||
/** Visitor id */ | ||
visitor_id?: string; | ||
/** Targeting key */ | ||
targeting_key?: string; | ||
/** Page metadata */ | ||
page?: { | ||
@@ -86,6 +160,18 @@ path: string; | ||
/** | ||
* Interface that describes a Contextual | ||
* @public | ||
*/ | ||
export declare interface Contextual<Self extends Contextual<Self>> { | ||
/** Returns context of the current Confidence instance */ | ||
getContext(): Context; | ||
/** Set Confidence context */ | ||
setContext(context: Context): void; | ||
/** | ||
* Creates a new Confidence instance with context | ||
* @param context - Confidence context | ||
* @returns Confidence instance | ||
*/ | ||
withContext(context: Context): Self; | ||
/** Clears context of current Confidence instance */ | ||
clearContext(): void; | ||
@@ -106,2 +192,6 @@ } | ||
/** | ||
* Event data | ||
* @public | ||
*/ | ||
export declare type EventData = Value.Struct & { | ||
@@ -111,3 +201,11 @@ context?: never; | ||
/** | ||
* EventSender interface | ||
* @public | ||
*/ | ||
export declare interface EventSender extends Contextual<EventSender> { | ||
/** | ||
* Tracks an event | ||
* @param name - event name | ||
* @param data - data to track */ | ||
track(name: string, data?: EventData): void; | ||
@@ -143,23 +241,43 @@ } | ||
/** | ||
* Flag evaluation identifiers | ||
* @public | ||
*/ | ||
export declare namespace FlagEvaluation { | ||
/** Error code thrown in case flag couldn't be correctly evaluated */ | ||
export type ErrorCode = 'FLAG_NOT_FOUND' | 'TYPE_MISMATCH' | 'NOT_READY' | 'TIMEOUT' | 'GENERAL'; | ||
/** Flag evaluation case of Matched */ | ||
export interface Matched<T> { | ||
/** Matched reason */ | ||
readonly reason: 'MATCH'; | ||
/** Flag value */ | ||
readonly value: T; | ||
/** Flag variant */ | ||
readonly variant: string; | ||
} | ||
/** Flag evaluation case of Unmatched */ | ||
export interface Unmatched<T> { | ||
/** Unmatched reason */ | ||
readonly reason: 'UNSPECIFIED' | 'NO_SEGMENT_MATCH' | 'NO_TREATMENT_MATCH' | 'FLAG_ARCHIVED' | 'TARGETING_KEY_ERROR'; | ||
/** Flag value */ | ||
readonly value: T; | ||
} | ||
/** Flag evaluation case of Failed */ | ||
export interface Failed<T> { | ||
/** Failed reason */ | ||
readonly reason: 'ERROR'; | ||
/** Flag value */ | ||
readonly value: T; | ||
/** Error code */ | ||
readonly errorCode: ErrorCode; | ||
/** Error message */ | ||
readonly errorMessage: string; | ||
} | ||
/** Flag evaluation case of Resolved */ | ||
export type Resolved<T> = Matched<T> | Unmatched<T> | Failed<T>; | ||
/** Flag evaluation case of Stale */ | ||
export type Stale<T> = Resolved<T> & PromiseLike<Resolved<T>>; | ||
} | ||
/** Flag evaluation */ | ||
export declare type FlagEvaluation<T> = FlagEvaluation.Resolved<T> | FlagEvaluation.Stale<T>; | ||
@@ -178,5 +296,12 @@ | ||
/** | ||
* Flag Resolver interface | ||
* @public | ||
*/ | ||
export declare interface FlagResolver extends Contextual<FlagResolver> { | ||
/** Subscribe to flag changes in Confidence */ | ||
subscribe(onStateChange?: StateObserver): () => void; | ||
/** Evaluates a flag */ | ||
evaluateFlag<T extends Value>(path: string, defaultValue: T): FlagEvaluation<Value.Widen<T>>; | ||
/** Returns flag value for a given flag */ | ||
getFlag<T extends Value>(path: string, defaultValue: T): Promise<Value.Widen<T>>; | ||
@@ -314,2 +439,6 @@ } | ||
/** | ||
* Tracks page views | ||
* @public | ||
*/ | ||
export declare function pageViews(): Trackable.Manager; | ||
@@ -412,4 +541,11 @@ | ||
/** | ||
* Flags states | ||
* @public | ||
*/ | ||
export declare type State = 'NOT_READY' | 'READY' | 'STALE' | 'ERROR'; | ||
/** | ||
* Flag state observer | ||
* @public */ | ||
export declare type StateObserver = (state: State) => void; | ||
@@ -419,41 +555,83 @@ | ||
/** | ||
* Namespace describing something to track | ||
* @public | ||
*/ | ||
export declare namespace Trackable { | ||
/** Trackable Controller */ | ||
export type Controller = Pick<Confidence, 'setContext' | 'track' | 'config'>; | ||
/** Trackable Cleanup */ | ||
export type Cleanup = void | Closer; | ||
/** Trackable Manager */ | ||
export type Manager = (controller: Controller) => Cleanup; | ||
/** Setup of Trackable */ | ||
export function setup(controller: Controller, manager: Manager): Closer; | ||
} | ||
/** | ||
* Namespace describing something to track | ||
* @public | ||
*/ | ||
export declare interface Trackable { | ||
/** Tracks an event given a Trackable Manager */ | ||
track(manager: Trackable.Manager): Closer; | ||
} | ||
/** | ||
* Namespace that describes Values used in Confidence | ||
* @public | ||
*/ | ||
export declare namespace Value { | ||
/** TypeName enum */ | ||
export type TypeName = 'number' | 'string' | 'boolean' | 'Struct' | 'List' | 'undefined'; | ||
/** Primitive types */ | ||
export type Primitive = number | string | boolean; | ||
/** Struct in Confidence */ | ||
export type Struct = { | ||
readonly [key: string]: Value; | ||
}; | ||
/** Readonly List */ | ||
export type List = ReadonlyArray<number> | ReadonlyArray<string> | ReadonlyArray<boolean>; | ||
/** Sets Confidence used Values to be implementations of primitive types */ | ||
export type Widen<T extends Value> = T extends number ? number : T extends string ? string : T extends boolean ? boolean : T; | ||
/** Asserts a Value */ | ||
export function assertValue(value: unknown): asserts value is Value; | ||
/** Clones a Value */ | ||
export function clone<T extends Value>(value: T): T; | ||
/** Asserts if two Values are equal */ | ||
export function equal(value1: Value, value2: Value): boolean; | ||
/** Returns typename of given Value */ | ||
export function getType(value: Value): TypeName; | ||
/** Asserts that Value is a Struct */ | ||
export function isStruct(value: Value): value is Struct; | ||
/** Asserts that Value is a List */ | ||
export function isList(value: Value): value is List; | ||
/** Asserts that type of value is undefined */ | ||
export function assertType(expected: 'undefined', found: Value): asserts found is undefined; | ||
/** Asserts that type of value is string */ | ||
export function assertType(expected: 'string', found: Value): asserts found is string; | ||
/** Asserts that type of value is number */ | ||
export function assertType(expected: 'number', found: Value): asserts found is number; | ||
/** Asserts that type of value is boolean */ | ||
export function assertType(expected: 'boolean', found: Value): asserts found is boolean; | ||
/** Asserts that type of value is List */ | ||
export function assertType(expected: 'List', found: Value): asserts found is List; | ||
/** Asserts that type of value is Struct */ | ||
export function assertType(expected: 'Struct', found: Value): asserts found is Struct; | ||
/** Returns a Value given a Struct */ | ||
export function get(struct: Struct | undefined, path: string): Value; | ||
/** Returns a Value given a Struct */ | ||
export function get(struct: Struct | undefined, ...steps: string[]): Value; | ||
/** Serializes value */ | ||
export function serialize(value: Value): string; | ||
/** Deserializes value */ | ||
export function deserialize(data: string): Value; | ||
} | ||
/** Confidence used Values */ | ||
export declare type Value = Value.Primitive | Value.Struct | Value.List | undefined; | ||
/** | ||
* Visitor Identity which can be used in Cookies | ||
* @public */ | ||
export declare const visitorIdentity: () => Trackable.Manager; | ||
@@ -465,3 +643,3 @@ | ||
* @param options - specifying which metrics to emit | ||
* @returns a {@link Topic} to be used with {@link Confidence.track } | ||
* @returns a Topic to be used with Confidence.track | ||
* @public | ||
@@ -468,0 +646,0 @@ */ |
{ | ||
"name": "@spotify-confidence/sdk", | ||
"license": "Apache-2.0", | ||
"version": "0.1.4", | ||
"version": "0.1.6", | ||
"types": "dist/index.d.ts", | ||
@@ -20,3 +20,4 @@ "engineStrict": true, | ||
"types": "dist/index.d.ts", | ||
"main": "dist/index.js" | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js" | ||
}, | ||
@@ -30,9 +31,9 @@ "dependencies": { | ||
"devDependencies": { | ||
"@microsoft/api-extractor": "*", | ||
"@microsoft/api-extractor": "7.43.1", | ||
"prettier": "*", | ||
"rollup": "*", | ||
"rollup": "4.14.2", | ||
"ts-proto": "^1.171.0" | ||
}, | ||
"type": "module", | ||
"main": "dist/index.js" | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.esm.js" | ||
} |
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
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
599746
8
5760
3
3
No