Skip to content

Commit f10aab9

Browse files
authored
feat(node-sdk): add refreshFlags() method (#529)
Allow users to trigger an on-demand refresh of cached flag definitions instead of waiting for the next automatic refresh cycle.
1 parent 2a810bd commit f10aab9

4 files changed

Lines changed: 61 additions & 2 deletions

File tree

packages/node-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reflag/node-sdk",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"license": "MIT",
55
"repository": {
66
"type": "git",

packages/node-sdk/src/client.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,21 @@ export class ReflagClient {
598598
await this.flagsCache.waitRefresh();
599599
}
600600

601+
/**
602+
* Refreshes the flag definitions from the server.
603+
*
604+
* @remarks
605+
* This triggers an on-demand refresh of the cached flag definitions.
606+
* Useful when you know flags have changed and don't want to wait for the next automatic refresh cycle.
607+
*
608+
* Note: updated flag rules take a few seconds to propagate to all servers.
609+
*
610+
* Concurrent calls are deduplicated — multiple calls share the same in-flight request.
611+
*/
612+
public async refreshFlags() {
613+
await this.flagsCache.refresh();
614+
}
615+
601616
/**
602617
* Destroys the client and cleans up all resources including timers and background processes.
603618
*
@@ -1491,6 +1506,13 @@ export class BoundReflagClient {
14911506
public async flush() {
14921507
await this._client.flush();
14931508
}
1509+
1510+
/**
1511+
* Refreshes the flag definitions from the server.
1512+
*/
1513+
public async refreshFlags() {
1514+
await this._client.refreshFlags();
1515+
}
14941516
}
14951517

14961518
function checkMeta(

packages/node-sdk/test/client.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,34 @@ describe("ReflagClient", () => {
992992
});
993993
});
994994

995+
describe("refreshFlags", () => {
996+
it("should call flagsCache.refresh()", async () => {
997+
const client = new ReflagClient(validOptions);
998+
999+
const refresh = vi
1000+
.spyOn(client["flagsCache"], "refresh")
1001+
.mockResolvedValue(undefined);
1002+
1003+
await client.refreshFlags();
1004+
1005+
expect(refresh).toHaveBeenCalledTimes(1);
1006+
});
1007+
1008+
it("should call flagsCache.refresh() on each invocation", async () => {
1009+
const client = new ReflagClient(validOptions);
1010+
1011+
const refresh = vi
1012+
.spyOn(client["flagsCache"], "refresh")
1013+
.mockResolvedValue(undefined);
1014+
1015+
await client.refreshFlags();
1016+
await client.refreshFlags();
1017+
await client.refreshFlags();
1018+
1019+
expect(refresh).toHaveBeenCalledTimes(3);
1020+
});
1021+
});
1022+
9951023
describe("getFlag", () => {
9961024
let client: ReflagClient;
9971025

yarn.lock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5140,7 +5140,16 @@ __metadata:
51405140
languageName: unknown
51415141
linkType: soft
51425142

5143-
"@reflag/node-sdk@npm:1.1.0, @reflag/node-sdk@workspace:packages/node-sdk":
5143+
"@reflag/node-sdk@npm:1.1.0":
5144+
version: 1.1.0
5145+
resolution: "@reflag/node-sdk@npm:1.1.0"
5146+
dependencies:
5147+
"@reflag/flag-evaluation": "npm:1.0.0"
5148+
checksum: 10c0/32f1ba05ac40fe7c3b8a772efd04cc577ba6d6c043873ca0253fee3db00c51c1a3489982e8f60849e86bc3c958f5eb43f6995ead02cee90dae4d2c6df44e7a2c
5149+
languageName: node
5150+
linkType: hard
5151+
5152+
"@reflag/node-sdk@workspace:packages/node-sdk":
51445153
version: 0.0.0-use.local
51455154
resolution: "@reflag/node-sdk@workspace:packages/node-sdk"
51465155
dependencies:

0 commit comments

Comments
 (0)