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
17 changes: 14 additions & 3 deletions packages/node-sdk/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ export class BucketClient {
*/
public readonly logger: Logger;

private initializationFinished = false;
private _initialize = once(async () => {
if (!this._config.offline) {
await this.featuresCache.refresh();
}
this.logger.info("Bucket initialized");
this.logger.info(
"Bucket initialized" + (this._config.offline ? " (offline mode)" : ""),
);
this.initializationFinished = true;
});

/**
Expand Down Expand Up @@ -219,7 +223,10 @@ export class BucketClient {

const offline = config.offline ?? process.env.NODE_ENV === "test";
if (!offline) {
ok(typeof config.secretKey === "string", "secretKey must be a string");
ok(
typeof config.secretKey === "string",
"secretKey must be a string, or set offline=true",
);
ok(config.secretKey.length > 22, "invalid secretKey specified");
}

Expand Down Expand Up @@ -957,6 +964,10 @@ export class BucketClient {
): Record<string, RawFeature> {
checkContextWithTracking(options);

if (!this.initializationFinished) {
this.logger.error("getFeature(s): BucketClient is not initialized yet.");
}

void this.syncContext(options);
let featureDefinitions: FeaturesAPIResponse["features"];

Expand All @@ -966,7 +977,7 @@ export class BucketClient {
const fetchedFeatures = this.featuresCache.get();
if (!fetchedFeatures) {
this.logger.warn(
"failed to use feature definitions, there are none cached yet. Using fallback features.",
"no feature definitions available, using fallback features.",
);
return this._config.fallbackFeatures || {};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node-sdk/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ describe("BucketClient", () => {

expect(logger.warn).toHaveBeenCalledWith(
expect.stringMatching(
"failed to use feature definitions, there are none cached yet. Using fallback features.",
"no feature definitions available, using fallback features",
),
);

Expand Down