Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/node-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bucketco/node-sdk",
"version": "1.9.1",
"version": "1.9.2",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions packages/node-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export class BucketClient {
fallbackFeatures?: Record<keyof TypedFeatures, RawFeature>;
featureOverrides: FeatureOverridesFn;
offline: boolean;
emitEvaluationEvents: boolean;
configFile?: string;
featuresFetchRetries: number;
fetchTimeoutMs: number;
Expand Down Expand Up @@ -302,6 +303,7 @@ export class BucketClient {

this._config = {
offline,
emitEvaluationEvents: config.emitEvaluationEvents ?? true,
apiBaseUrl: (config.apiBaseUrl ?? config.host) || API_BASE_URL,
headers: {
"Content-Type": "application/json",
Expand Down Expand Up @@ -908,6 +910,13 @@ export class BucketClient {
return;
}

if (
!this._config.emitEvaluationEvents &&
(event.action === "evaluate" || event.action === "evaluate-config")
) {
return;
}

if (
!this.rateLimiter.isAllowed(
hashObject({
Expand Down
5 changes: 5 additions & 0 deletions packages/node-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,11 @@ export type ClientOptions = {
*/
offline?: boolean;

/**
* If set to `false`, no evaluation events will be emitted.
*/
emitEvaluationEvents?: boolean;

/**
* The path to the config file. If supplied, the config file will be loaded.
* Defaults to `bucket.json` when NODE_ENV is not production. Can also be
Expand Down
64 changes: 64 additions & 0 deletions packages/node-sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,70 @@ describe("BucketClient", () => {
);
});

it("`track` does not send evaluation events when `emitEvaluationEvents` is `false`", async () => {
client = new BucketClient({
...validOptions,
emitEvaluationEvents: false,
});

const context = {
company,
user,
other: otherContext,
};

// test that the feature is returned
await client.initialize();
const feature = client.getFeature(
{
...context,
meta: {
active: true,
},
enableTracking: true,
},
"feature1",
);

await feature.track();
await client.flush();

expect(httpClient.post).toHaveBeenCalledWith(
BULK_ENDPOINT,
expectedHeaders,
[
{
attributes: {
employees: 100,
name: "Acme Inc.",
},
companyId: "company123",
context: {
active: true,
},
type: "company",
},
{
attributes: {
age: 1,
name: "John",
},
context: {
active: true,
},
type: "user",
userId: "user123",
},
{
type: "event",
event: "feature1",
userId: user.id,
companyId: company.id,
},
],
);
});

it("`isEnabled` sends `check` event", async () => {
const context = {
company,
Expand Down
4 changes: 2 additions & 2 deletions packages/openfeature-node-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bucketco/openfeature-node-provider",
"version": "0.4.0",
"version": "0.4.1",
"license": "MIT",
"repository": {
"type": "git",
Expand Down Expand Up @@ -50,7 +50,7 @@
"vitest": "~1.6.0"
},
"dependencies": {
"@bucketco/node-sdk": "1.9.1"
"@bucketco/node-sdk": "1.9.2"
},
"peerDependencies": {
"@openfeature/server-sdk": ">=1.16.1"
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ __metadata:
languageName: unknown
linkType: soft

"@bucketco/node-sdk@npm:1.9.1, @bucketco/node-sdk@workspace:packages/node-sdk":
"@bucketco/node-sdk@npm:1.9.2, @bucketco/node-sdk@workspace:packages/node-sdk":
version: 0.0.0-use.local
resolution: "@bucketco/node-sdk@workspace:packages/node-sdk"
dependencies:
Expand Down Expand Up @@ -836,7 +836,7 @@ __metadata:
dependencies:
"@babel/core": "npm:~7.24.7"
"@bucketco/eslint-config": "npm:~0.0.2"
"@bucketco/node-sdk": "npm:1.9.1"
"@bucketco/node-sdk": "npm:1.9.2"
"@bucketco/tsconfig": "npm:~0.0.2"
"@openfeature/core": "npm:^1.5.0"
"@openfeature/server-sdk": "npm:>=1.16.1"
Expand Down