@eppo/js-client-sdk-common
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -0,1 +1,2 @@ | ||
import { IAssignmentHooks } from '../assignment-hooks'; | ||
import { IAssignmentLogger } from '../assignment-logger'; | ||
@@ -26,2 +27,3 @@ import { IConfigurationStore } from '../configuration-store'; | ||
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes?: {}): string; | ||
getAssignmentWithHooks(subjectKey: string, experimentKey: string, subjectAttributes: {}, assignmentHooks: IAssignmentHooks): Promise<string>; | ||
setLogger(logger: IAssignmentLogger): void; | ||
@@ -28,0 +30,0 @@ private flushQueuedEvents; |
@@ -41,2 +41,10 @@ "use strict"; | ||
} | ||
async getAssignmentWithHooks(subjectKey, experimentKey, subjectAttributes = {}, assignmentHooks) { | ||
let assignment = await (assignmentHooks === null || assignmentHooks === void 0 ? void 0 : assignmentHooks.onPreAssignment(subjectKey)); | ||
if (assignment == null) { | ||
assignment = this.getAssignment(subjectKey, experimentKey, subjectAttributes); | ||
} | ||
assignmentHooks === null || assignmentHooks === void 0 ? void 0 : assignmentHooks.onPostAssignment(assignment); | ||
return assignment; | ||
} | ||
setLogger(logger) { | ||
@@ -43,0 +51,0 @@ this.assignmentLogger = logger; |
@@ -28,2 +28,3 @@ import { AxiosInstance } from 'axios'; | ||
getAssignment(subjectKey: string, experimentKey: string, subjectAttributes?: {}): string; | ||
getAssignmentWithHooks(subjectKey: string, experimentKey: string, subjectAttributes: {}, assignmentHooks: IAssignmentHooks): Promise<string>; | ||
setLogger(logger: IAssignmentLogger): void; | ||
@@ -86,2 +87,25 @@ private flushQueuedEvents; | ||
/** | ||
* Implement this interface to override an assignment or receive a callback post assignment | ||
* @public | ||
*/ | ||
declare interface IAssignmentHooks { | ||
/** | ||
* Invoked before a subject is assigned to an experiment variation. | ||
* | ||
* @param subject id of subject being assigned | ||
* @returns variation to override for the given subject. If null is returned, | ||
* then the subject will be assigned with the default assignment logic. | ||
* @public | ||
*/ | ||
onPreAssignment(subject: string): Promise<string | null>; | ||
/** | ||
* Invoked after a subject is assigned. Useful for any post assignment logic needed which is specific | ||
* to an experiment/flag. Do not use this for logging assignments - use IAssignmentLogger instead. | ||
* @param variation the assigned variation | ||
* @public | ||
*/ | ||
onPostAssignment(variation: string): Promise<void>; | ||
} | ||
/** | ||
* Implement this interface log variation assignments to your data warehouse. | ||
@@ -88,0 +112,0 @@ * @public |
{ | ||
"name": "@eppo/js-client-sdk-common", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
112046
67
709