@bucketco/node-sdk
Advanced tools
Comparing version 1.4.3 to 1.4.4
{ | ||
"name": "@bucketco/node-sdk", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"license": "MIT", | ||
@@ -47,4 +47,4 @@ "repository": { | ||
"dependencies": { | ||
"@bucketco/flag-evaluation": "~0.0.7" | ||
"@bucketco/flag-evaluation": "~0.1.0" | ||
} | ||
} |
@@ -115,2 +115,226 @@ "use strict"; | ||
/** | ||
* Gets the logger associated with the client. | ||
* | ||
* @returns The logger or `undefined` if it is not set. | ||
**/ | ||
get logger() { | ||
return this._config.logger; | ||
} | ||
set featureOverrides(overrides) { | ||
this._config.featureOverrides = overrides; | ||
} | ||
/** | ||
* Returns a new BoundBucketClient with the user/company/otherContext | ||
* set to be used in subsequent calls. | ||
* For example, for evaluating feature targeting or tracking events. | ||
* | ||
* @param enableTracking | ||
* @param context - The user/company/otherContext to bind to the client. | ||
* | ||
* @returns A new client bound with the arguments given. | ||
* @throws An error if the user/company is given but their ID is not a string. | ||
* @remarks | ||
* The `updateUser` / `updateCompany` methods will automatically be called when | ||
* the user/company is set respectively. | ||
**/ | ||
bindClient(_a) { | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
return new BoundBucketClient(this, Object.assign({ enableTracking }, context)); | ||
} | ||
/** | ||
* Updates the associated user in Bucket. | ||
* | ||
* @param opts.attributes - The additional attributes of the company (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* | ||
* @throws An error if the company is not set or the options are invalid. | ||
* @remarks | ||
* The company must be set using `withCompany` before calling this method. | ||
* If the user is set, the company will be associated with the user. | ||
**/ | ||
updateUser(userId, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(userId, "userId"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if (this._config.offline) { | ||
return; | ||
} | ||
if (this._config.rateLimiter.isAllowed((0, utils_1.hashObject)(Object.assign(Object.assign({}, opts), { userId })))) { | ||
yield this._config.batchBuffer.add({ | ||
type: "user", | ||
userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Updates the associated company in Bucket. | ||
* | ||
* @param opts.attributes - The additional attributes of the company (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* | ||
* @throws An error if the company is not set or the options are invalid. | ||
* @remarks | ||
* The company must be set using `withCompany` before calling this method. | ||
* If the user is set, the company will be associated with the user. | ||
**/ | ||
updateCompany(companyId, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(companyId, "companyId"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if (typeof (opts === null || opts === void 0 ? void 0 : opts.userId) !== "undefined") { | ||
(0, utils_1.idOk)(opts === null || opts === void 0 ? void 0 : opts.userId, "userId"); | ||
} | ||
if (this._config.offline) { | ||
return; | ||
} | ||
if (this._config.rateLimiter.isAllowed((0, utils_1.hashObject)(Object.assign(Object.assign({}, opts), { companyId })))) { | ||
yield this._config.batchBuffer.add({ | ||
type: "company", | ||
companyId, | ||
userId: opts === null || opts === void 0 ? void 0 : opts.userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Tracks an event in Bucket. | ||
* @param event - The event to track. | ||
* @param userId - The userId of the user who performed the event | ||
* @param opts | ||
* @param opts.attributes - The attributes of the event (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* @param opts.companyId - Optional company ID for the event (optional). | ||
* | ||
* @throws An error if the user is not set or the event is invalid or the options are invalid. | ||
* @remarks | ||
* If the company is set, the event will be associated with the company. | ||
**/ | ||
track(userId, event, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(userId, "userId"); | ||
(0, utils_1.ok)(typeof event === "string" && event.length > 0, "event must be a string"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if ((opts === null || opts === void 0 ? void 0 : opts.companyId) !== undefined) { | ||
(0, utils_1.idOk)(opts === null || opts === void 0 ? void 0 : opts.companyId, "companyId"); | ||
} | ||
if (this._config.offline) { | ||
return; | ||
} | ||
yield this._config.batchBuffer.add({ | ||
type: "event", | ||
event, | ||
companyId: opts === null || opts === void 0 ? void 0 : opts.companyId, | ||
userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
}); | ||
} | ||
/** | ||
* Initializes the client by caching the features definitions. | ||
* | ||
* @returns void | ||
* | ||
* @remarks | ||
* Call this method before calling `getFeatures` to ensure the feature definitions are cached. | ||
* The client will ignore subsequent calls to this method. | ||
**/ | ||
initialize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this._initialize(); | ||
return; | ||
}); | ||
} | ||
/** | ||
* Flushes the batch buffer. | ||
* | ||
* @remarks | ||
* It is recommended to call this method when the application is shutting down to ensure all events are sent | ||
* before the process exits. | ||
*/ | ||
flush() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this._config.batchBuffer.flush(); | ||
}); | ||
} | ||
/** | ||
* Gets the evaluated feature for the current context which includes the user, company, and custom context. | ||
* | ||
* @param context - The context to evaluate the features for. | ||
* @returns The evaluated features. | ||
* @remarks | ||
* Call `initialize` before calling this method to ensure the feature definitions are cached, no features will be returned otherwise. | ||
**/ | ||
getFeatures(_a) { | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
const options = Object.assign({ enableTracking }, context); | ||
const features = this._getFeatures(options); | ||
return Object.fromEntries(Object.entries(features).map(([k, v]) => [ | ||
k, | ||
this._wrapRawFeature(options, v), | ||
])); | ||
} | ||
/** | ||
* Gets the evaluated feature for the current context which includes the user, company, and custom context. | ||
* Using the `isEnabled` property sends a `check` event to Bucket. | ||
* | ||
* @returns The evaluated features. | ||
* @remarks | ||
* Call `initialize` before calling this method to ensure the feature definitions are cached, no features will be returned otherwise. | ||
**/ | ||
getFeature(_a, key) { | ||
var _b; | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
const options = Object.assign({ enableTracking }, context); | ||
const features = this._getFeatures(options); | ||
const feature = features[key]; | ||
return this._wrapRawFeature(options, { | ||
key, | ||
isEnabled: (_b = feature === null || feature === void 0 ? void 0 : feature.isEnabled) !== null && _b !== void 0 ? _b : false, | ||
targetingVersion: feature === null || feature === void 0 ? void 0 : feature.targetingVersion, | ||
}); | ||
} | ||
/** | ||
* Gets evaluated features with the usage of remote context. | ||
* This method triggers a network request every time it's called. | ||
* | ||
* @param userId | ||
* @param companyId | ||
* @param additionalContext | ||
* @returns evaluated features | ||
*/ | ||
getFeaturesRemote(userId, companyId, additionalContext) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this._getFeaturesRemote("", userId, companyId, additionalContext); | ||
}); | ||
} | ||
/** | ||
* Gets evaluated feature with the usage of remote context. | ||
* This method triggers a network request every time it's called. | ||
* | ||
* @param key | ||
* @param userId | ||
* @param companyId | ||
* @param additionalContext | ||
* @returns evaluated feature | ||
*/ | ||
getFeatureRemote(key, userId, companyId, additionalContext) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const features = yield this._getFeaturesRemote(key, userId, companyId, additionalContext); | ||
return features[key]; | ||
}); | ||
} | ||
/** | ||
* Sends a POST request to the specified path. | ||
@@ -159,3 +383,3 @@ * | ||
(_a = this._config.logger) === null || _a === void 0 ? void 0 : _a.debug(`get request to "${url}"`, response); | ||
if (!(0, utils_1.isObject)(response.body) || response.body.success !== true) { | ||
if (!(0, utils_1.isObject)(response.body) || !response.body.success) { | ||
(_b = this._config.logger) === null || _b === void 0 ? void 0 : _b.warn(`invalid response received from server for "${url}"`, response); | ||
@@ -245,3 +469,3 @@ return undefined; | ||
* | ||
* @param context - The context to update. | ||
* @param options | ||
*/ | ||
@@ -292,154 +516,2 @@ syncContext(options) { | ||
} | ||
/** | ||
* Gets the logger associated with the client. | ||
* | ||
* @returns The logger or `undefined` if it is not set. | ||
**/ | ||
get logger() { | ||
return this._config.logger; | ||
} | ||
/** | ||
* Returns a new BoundBucketClient with the user/company/otherContext | ||
* set to be used in subsequent calls. | ||
* For example, for evaluating feature targeting or tracking events. | ||
* | ||
* @param context - The user/company/otherContext to bind to the client. | ||
* | ||
* @returns A new client bound with the arguments given. | ||
* @throws An error if the user/company is given but their ID is not a string. | ||
* @remarks | ||
* The `updateUser` / `updateCompany` methods will automatically be called when | ||
* the user/company is set respectively. | ||
**/ | ||
bindClient(_a) { | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
return new BoundBucketClient(this, Object.assign({ enableTracking }, context)); | ||
} | ||
/** | ||
* Updates the associated user in Bucket. | ||
* | ||
* @param opts.attributes - The additional attributes of the company (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* | ||
* @throws An error if the company is not set or the options are invalid. | ||
* @remarks | ||
* The company must be set using `withCompany` before calling this method. | ||
* If the user is set, the company will be associated with the user. | ||
**/ | ||
updateUser(userId, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(userId, "userId"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if (this._config.offline) { | ||
return; | ||
} | ||
if (this._config.rateLimiter.isAllowed((0, utils_1.hashObject)(Object.assign(Object.assign({}, opts), { userId })))) { | ||
yield this._config.batchBuffer.add({ | ||
type: "user", | ||
userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Updates the associated company in Bucket. | ||
* | ||
* @param opts.attributes - The additional attributes of the company (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* | ||
* @throws An error if the company is not set or the options are invalid. | ||
* @remarks | ||
* The company must be set using `withCompany` before calling this method. | ||
* If the user is set, the company will be associated with the user. | ||
**/ | ||
updateCompany(companyId, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(companyId, "companyId"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if (typeof (opts === null || opts === void 0 ? void 0 : opts.userId) !== "undefined") { | ||
(0, utils_1.idOk)(opts === null || opts === void 0 ? void 0 : opts.userId, "userId"); | ||
} | ||
if (this._config.offline) { | ||
return; | ||
} | ||
if (this._config.rateLimiter.isAllowed((0, utils_1.hashObject)(Object.assign(Object.assign({}, opts), { companyId })))) { | ||
yield this._config.batchBuffer.add({ | ||
type: "company", | ||
companyId, | ||
userId: opts === null || opts === void 0 ? void 0 : opts.userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
} | ||
}); | ||
} | ||
/** | ||
* Tracks an event in Bucket. | ||
* @param event - The event to track. | ||
* @param userId - The userId of the user who performed the event | ||
* @param opts.attributes - The attributes of the event (optional). | ||
* @param opts.meta - The meta context associated with tracking (optional). | ||
* @param opts.companyId - Optional company ID for the event (optional). | ||
* | ||
* @throws An error if the user is not set or the event is invalid or the options are invalid. | ||
* @remarks | ||
* If the company is set, the event will be associated with the company. | ||
**/ | ||
track(userId, event, opts) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
(0, utils_1.idOk)(userId, "userId"); | ||
(0, utils_1.ok)(typeof event === "string" && event.length > 0, "event must be a string"); | ||
(0, utils_1.ok)(opts === undefined || (0, utils_1.isObject)(opts), "opts must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.attributes) === undefined || (0, utils_1.isObject)(opts.attributes), "attributes must be an object"); | ||
(0, utils_1.ok)((opts === null || opts === void 0 ? void 0 : opts.meta) === undefined || (0, utils_1.isObject)(opts.meta), "meta must be an object"); | ||
if ((opts === null || opts === void 0 ? void 0 : opts.companyId) !== undefined) { | ||
(0, utils_1.idOk)(opts === null || opts === void 0 ? void 0 : opts.companyId, "companyId"); | ||
} | ||
if (this._config.offline) { | ||
return; | ||
} | ||
yield this._config.batchBuffer.add({ | ||
type: "event", | ||
event, | ||
companyId: opts === null || opts === void 0 ? void 0 : opts.companyId, | ||
userId, | ||
attributes: opts === null || opts === void 0 ? void 0 : opts.attributes, | ||
context: opts === null || opts === void 0 ? void 0 : opts.meta, | ||
}); | ||
}); | ||
} | ||
/** | ||
* Initializes the client by caching the features definitions. | ||
* | ||
* @returns void | ||
* | ||
* @remarks | ||
* Call this method before calling `getFeatures` to ensure the feature definitions are cached. | ||
* The client will ignore subsequent calls to this method. | ||
**/ | ||
initialize() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this._initialize(); | ||
return; | ||
}); | ||
} | ||
/** | ||
* Flushes the batch buffer. | ||
* | ||
* @remarks | ||
* It is recommended to call this method when the application is shutting down to ensure all events are sent | ||
* before the process exits. | ||
*/ | ||
flush() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this._config.batchBuffer.flush(); | ||
}); | ||
} | ||
_getFeatures(options) { | ||
@@ -463,15 +535,16 @@ var _a, _b; | ||
const { enableTracking = true } = options, context = __rest(options, ["enableTracking"]); | ||
const evaluated = featureDefinitions.map((feature) => (0, flag_evaluation_1.evaluateTargeting)({ | ||
const evaluated = featureDefinitions.map((feature) => (0, flag_evaluation_1.evaluateFeatureRules)({ | ||
featureKey: feature.key, | ||
rules: feature.targeting.rules.map((r) => (Object.assign(Object.assign({}, r), { value: true }))), | ||
context, | ||
feature, | ||
})); | ||
if (enableTracking) { | ||
evaluated.forEach((res) => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
var _a, _b; | ||
try { | ||
yield this.sendFeatureEvent({ | ||
action: "evaluate", | ||
key: res.feature.key, | ||
targetingVersion: keyToVersionMap.get(res.feature.key), | ||
evalResult: res.value, | ||
key: res.featureKey, | ||
targetingVersion: keyToVersionMap.get(res.featureKey), | ||
evalResult: (_a = res.value) !== null && _a !== void 0 ? _a : false, | ||
evalContext: res.context, | ||
@@ -483,3 +556,3 @@ evalRuleResults: res.ruleEvaluationResults, | ||
catch (err) { | ||
(_a = this._config.logger) === null || _a === void 0 ? void 0 : _a.error(`failed to send evaluate event for "${res.feature.key}"`, err); | ||
(_b = this._config.logger) === null || _b === void 0 ? void 0 : _b.error(`failed to send evaluate event for "${res.featureKey}"`, err); | ||
} | ||
@@ -489,6 +562,7 @@ })); | ||
let evaluatedFeatures = evaluated.reduce((acc, res) => { | ||
acc[res.feature.key] = { | ||
key: res.feature.key, | ||
isEnabled: res.value, | ||
targetingVersion: keyToVersionMap.get(res.feature.key), | ||
var _a; | ||
acc[res.featureKey] = { | ||
key: res.featureKey, | ||
isEnabled: (_a = res.value) !== null && _a !== void 0 ? _a : false, | ||
targetingVersion: keyToVersionMap.get(res.featureKey), | ||
}; | ||
@@ -544,42 +618,2 @@ return acc; | ||
} | ||
/** | ||
* Gets the evaluated feature for the current context which includes the user, company, and custom context. | ||
* | ||
* @param context - The context to evaluate the features for. | ||
* @returns The evaluated features. | ||
* @remarks | ||
* Call `initialize` before calling this method to ensure the feature definitions are cached, no features will be returned otherwise. | ||
**/ | ||
getFeatures(_a) { | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
const options = Object.assign({ enableTracking }, context); | ||
const features = this._getFeatures(options); | ||
return Object.fromEntries(Object.entries(features).map(([k, v]) => [ | ||
k, | ||
this._wrapRawFeature(options, v), | ||
])); | ||
} | ||
/** | ||
* Gets the evaluated feature for the current context which includes the user, company, and custom context. | ||
* Using the `isEnabled` property sends a `check` event to Bucket. | ||
* | ||
* @returns The evaluated features. | ||
* @remarks | ||
* Call `initialize` before calling this method to ensure the feature definitions are cached, no features will be returned otherwise. | ||
**/ | ||
getFeature(_a, key) { | ||
var _b; | ||
var { enableTracking = true } = _a, context = __rest(_a, ["enableTracking"]); | ||
const options = Object.assign({ enableTracking }, context); | ||
const features = this._getFeatures(options); | ||
const feature = features[key]; | ||
return this._wrapRawFeature(options, { | ||
key, | ||
isEnabled: (_b = feature === null || feature === void 0 ? void 0 : feature.isEnabled) !== null && _b !== void 0 ? _b : false, | ||
targetingVersion: feature === null || feature === void 0 ? void 0 : feature.targetingVersion, | ||
}); | ||
} | ||
set featureOverrides(overrides) { | ||
this._config.featureOverrides = overrides; | ||
} | ||
_getFeaturesRemote(key, userId, companyId, additionalContext) { | ||
@@ -616,30 +650,2 @@ return __awaiter(this, void 0, void 0, function* () { | ||
} | ||
/** | ||
* Gets evaluated features with the usage of remote context. | ||
* This method triggers a network request every time it's called. | ||
* | ||
* @param additionalContext | ||
* @returns evaluated features | ||
*/ | ||
getFeaturesRemote(userId, companyId, additionalContext) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return yield this._getFeaturesRemote("", userId, companyId, additionalContext); | ||
}); | ||
} | ||
/** | ||
* Gets evaluated feature with the usage of remote context. | ||
* This method triggers a network request every time it's called. | ||
* | ||
* @param key | ||
* @param userId | ||
* @param companyId | ||
* @param additionalContext | ||
* @returns evaluated feature | ||
*/ | ||
getFeatureRemote(key, userId, companyId, additionalContext) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const features = yield this._getFeaturesRemote(key, userId, companyId, additionalContext); | ||
return features[key]; | ||
}); | ||
} | ||
} | ||
@@ -727,2 +733,3 @@ exports.BucketClient = BucketClient; | ||
* @param event - The event to track. | ||
* @param opts | ||
* @param opts.attributes - The attributes of the event (optional). | ||
@@ -729,0 +736,0 @@ * @param opts.meta - The meta context associated with tracking (optional). |
@@ -19,2 +19,3 @@ import type { FeatureOverridesFn, IdType } from "./types"; | ||
private _config; | ||
private _initialize; | ||
/** | ||
@@ -29,54 +30,2 @@ * Creates a new SDK client. | ||
/** | ||
* Sends a POST request to the specified path. | ||
* | ||
* @param path - The path to send the request to. | ||
* @param body - The body of the request. | ||
* @returns A boolean indicating if the request was successful. | ||
* @throws An error if the path or body is invalid. | ||
**/ | ||
private post; | ||
/** | ||
* Sends a GET request to the specified path. | ||
* | ||
* @param path - The path to send the request to. | ||
* @returns The response from the server. | ||
* @throws An error if the path is invalid. | ||
**/ | ||
private get; | ||
/** | ||
* Sends a batch of events to the Bucket API. | ||
* @param events - The events to send. | ||
* @throws An error if the the send fails. | ||
**/ | ||
private sendBulkEvents; | ||
/** | ||
* Sends a feature event to the Bucket API. | ||
* | ||
* Feature events are used to track the evaluation of feature targeting rules. | ||
* "check" events are sent when a feature's `isEnabled` property is checked. | ||
* "evaluate" events are sent when a feature's targeting rules are matched against | ||
* the current context. | ||
* | ||
* @param event - The event to send. | ||
* | ||
* @throws An error if the event is invalid. | ||
* | ||
* @remarks | ||
* This method is rate-limited to prevent too many events from being sent. | ||
**/ | ||
private sendFeatureEvent; | ||
/** | ||
* Updates the context in Bucket (if needed). | ||
* This method should be used before requesting feature flags or binding a client. | ||
* | ||
* @param context - The context to update. | ||
*/ | ||
private syncContext; | ||
/** | ||
* Gets the features cache. | ||
* | ||
* @returns The features cache. | ||
**/ | ||
private getFeaturesCache; | ||
/** | ||
* Gets the logger associated with the client. | ||
@@ -87,2 +36,3 @@ * | ||
get logger(): Logger | undefined; | ||
set featureOverrides(overrides: FeatureOverridesFn); | ||
/** | ||
@@ -93,2 +43,3 @@ * Returns a new BoundBucketClient with the user/company/otherContext | ||
* | ||
* @param enableTracking | ||
* @param context - The user/company/otherContext to bind to the client. | ||
@@ -131,5 +82,6 @@ * | ||
* Tracks an event in Bucket. | ||
* @param event - The event to track. | ||
* @param userId - The userId of the user who performed the event | ||
* @param opts | ||
* @param opts.attributes - The attributes of the event (optional). | ||
@@ -146,3 +98,2 @@ * @param opts.meta - The meta context associated with tracking (optional). | ||
}): Promise<void>; | ||
private _initialize; | ||
/** | ||
@@ -166,4 +117,2 @@ * Initializes the client by caching the features definitions. | ||
flush(): Promise<void>; | ||
private _getFeatures; | ||
private _wrapRawFeature; | ||
/** | ||
@@ -187,4 +136,2 @@ * Gets the evaluated feature for the current context which includes the user, company, and custom context. | ||
getFeature({ enableTracking, ...context }: ContextWithTracking, key: keyof TypedFeatures): Feature; | ||
set featureOverrides(overrides: FeatureOverridesFn); | ||
private _getFeaturesRemote; | ||
/** | ||
@@ -194,2 +141,4 @@ * Gets evaluated features with the usage of remote context. | ||
* | ||
* @param userId | ||
* @param companyId | ||
* @param additionalContext | ||
@@ -210,2 +159,57 @@ * @returns evaluated features | ||
getFeatureRemote(key: string, userId?: IdType, companyId?: IdType, additionalContext?: Context): Promise<Feature>; | ||
/** | ||
* Sends a POST request to the specified path. | ||
* | ||
* @param path - The path to send the request to. | ||
* @param body - The body of the request. | ||
* @returns A boolean indicating if the request was successful. | ||
* @throws An error if the path or body is invalid. | ||
**/ | ||
private post; | ||
/** | ||
* Sends a GET request to the specified path. | ||
* | ||
* @param path - The path to send the request to. | ||
* @returns The response from the server. | ||
* @throws An error if the path is invalid. | ||
**/ | ||
private get; | ||
/** | ||
* Sends a batch of events to the Bucket API. | ||
* @param events - The events to send. | ||
* @throws An error if the the send fails. | ||
**/ | ||
private sendBulkEvents; | ||
/** | ||
* Sends a feature event to the Bucket API. | ||
* | ||
* Feature events are used to track the evaluation of feature targeting rules. | ||
* "check" events are sent when a feature's `isEnabled` property is checked. | ||
* "evaluate" events are sent when a feature's targeting rules are matched against | ||
* the current context. | ||
* | ||
* @param event - The event to send. | ||
* | ||
* @throws An error if the event is invalid. | ||
* | ||
* @remarks | ||
* This method is rate-limited to prevent too many events from being sent. | ||
**/ | ||
private sendFeatureEvent; | ||
/** | ||
* Updates the context in Bucket (if needed). | ||
* This method should be used before requesting feature flags or binding a client. | ||
* | ||
* @param options | ||
*/ | ||
private syncContext; | ||
/** | ||
* Gets the features cache. | ||
* | ||
* @returns The features cache. | ||
**/ | ||
private getFeaturesCache; | ||
private _getFeatures; | ||
private _wrapRawFeature; | ||
private _getFeaturesRemote; | ||
} | ||
@@ -277,2 +281,3 @@ /** | ||
* @param event - The event to track. | ||
* @param opts | ||
* @param opts.attributes - The attributes of the event (optional). | ||
@@ -279,0 +284,0 @@ * @param opts.meta - The meta context associated with tracking (optional). |
@@ -1,2 +0,2 @@ | ||
import { FeatureData } from "@bucketco/flag-evaluation"; | ||
import { RuleFilter } from "@bucketco/flag-evaluation"; | ||
/** | ||
@@ -105,2 +105,14 @@ * Describes the meta context associated with tracking. | ||
/** | ||
* Describes a specific feature in the API response | ||
*/ | ||
type FeatureAPIResponse = { | ||
key: string; | ||
targeting: { | ||
version: number; | ||
rules: { | ||
filter: RuleFilter; | ||
}[]; | ||
}; | ||
}; | ||
/** | ||
* Describes the response of the features endpoint | ||
@@ -110,7 +122,3 @@ */ | ||
/** The feature definitions */ | ||
features: (FeatureData & { | ||
targeting: { | ||
version: number; | ||
}; | ||
})[]; | ||
features: FeatureAPIResponse[]; | ||
}; | ||
@@ -341,1 +349,2 @@ export type EvaluatedFeaturesAPIResponse = { | ||
export type IdType = string | number; | ||
export {}; |
{ | ||
"name": "@bucketco/node-sdk", | ||
"version": "1.4.3", | ||
"version": "1.4.4", | ||
"license": "MIT", | ||
@@ -47,5 +47,5 @@ "repository": { | ||
"dependencies": { | ||
"@bucketco/flag-evaluation": "~0.0.7" | ||
"@bucketco/flag-evaluation": "~0.1.0" | ||
}, | ||
"gitHead": "5411ac337abbcdf254584286599ae94b934c0ca7" | ||
"gitHead": "4d51b5dbce8f6f1bb9b6b2b3e12a586512409ed8" | ||
} |
@@ -130,10 +130,10 @@ # Bucket Node.js SDK | ||
{ | ||
secretKey: "...", | ||
logLevel: "warn", | ||
offline: true, | ||
host: "https://proxy.slick-demo.com" | ||
featureOverrides: { | ||
huddles: true, | ||
voiceChat: false | ||
}, | ||
"secretKey": "...", | ||
"logLevel": "warn", | ||
"offline": true, | ||
"host": "https://proxy.slick-demo.com", | ||
"featureOverrides": { | ||
"huddles": true, | ||
"voiceChat": false | ||
} | ||
} | ||
@@ -140,0 +140,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
139205
2081
+ Added@bucketco/flag-evaluation@0.1.0(transitive)
- Removed@bucketco/flag-evaluation@0.0.7(transitive)