Skip to content

Commit 988dbc3

Browse files
authored
Prepare v9.0.0 (Catnip) release (#98)
* Improve naming (rename apiKey to sdkKey) * Remove deprecated type (ClientReadyState) * Format code & clean up imports * Bump version * Exclude non-source files so they don't pollute autocompletion/intellisense * Improve word choice in intellisense docs * Sync intellisense docs with SDK reference
1 parent d85b948 commit 988dbc3

14 files changed

+73
-92
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "configcat-common",
3-
"version": "8.2.0",
3+
"version": "9.0.0",
44
"description": "ConfigCat is a configuration as a service that lets you manage your features and configurations without actually deploying new code.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/ConfigCatClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class ConfigCatClientCache {
184184
getOrCreate(options: ConfigCatClientOptions, configCatKernel: IConfigCatKernel): [ConfigCatClient, boolean] {
185185
let instance: ConfigCatClient | undefined;
186186

187-
const cachedInstance = this.instances[options.apiKey];
187+
const cachedInstance = this.instances[options.sdkKey];
188188
if (cachedInstance) {
189189
const [weakRef] = cachedInstance;
190190
instance = weakRef.deref();
@@ -196,7 +196,7 @@ export class ConfigCatClientCache {
196196
const token = {};
197197
instance = new ConfigCatClient(options, configCatKernel, token);
198198
const weakRefCtor = isWeakRefAvailable() ? WeakRef : getWeakRefStub();
199-
this.instances[options.apiKey] = [new weakRefCtor(instance), token];
199+
this.instances[options.sdkKey] = [new weakRefCtor(instance), token];
200200
return [instance, false];
201201
}
202202

@@ -310,7 +310,7 @@ export class ConfigCatClient implements IConfigCatClient {
310310
this.hooks.emit("clientReady", ClientCacheState.HasLocalOverrideFlagDataOnly);
311311
}
312312

313-
this.suppressFinalize = registerForFinalization(this, { sdkKey: options.apiKey, cacheToken, configService: this.configService, logger: options.logger });
313+
this.suppressFinalize = registerForFinalization(this, { sdkKey: options.sdkKey, cacheToken, configService: this.configService, logger: options.logger });
314314
}
315315

316316
private static finalize(data: IFinalizationData) {
@@ -337,7 +337,7 @@ export class ConfigCatClient implements IConfigCatClient {
337337
options.logger.debug("dispose() called");
338338

339339
if (this.cacheToken) {
340-
clientInstanceCache.remove(options.apiKey, this.cacheToken);
340+
clientInstanceCache.remove(options.sdkKey, this.cacheToken);
341341
}
342342

343343
ConfigCatClient.close(this.configService, options.logger, this.hooks);

src/ConfigCatClientOptions.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export abstract class OptionsBase {
134134

135135
logger: LoggerWrapper;
136136

137-
apiKey: string;
137+
sdkKey: string;
138138

139139
clientVersion: string;
140140

@@ -158,15 +158,15 @@ export abstract class OptionsBase {
158158

159159
hooks: SafeHooksWrapper;
160160

161-
constructor(apiKey: string, clientVersion: string, options?: IOptions | null,
161+
constructor(sdkKey: string, clientVersion: string, options?: IOptions | null,
162162
defaultCacheFactory?: ((options: OptionsBase) => IConfigCache) | null,
163163
eventEmitterFactory?: (() => IEventEmitter) | null) {
164164

165-
if (!apiKey) {
166-
throw new Error("Invalid 'apiKey' value");
165+
if (!sdkKey) {
166+
throw new Error("Invalid 'sdkKey' value");
167167
}
168168

169-
this.apiKey = apiKey;
169+
this.sdkKey = sdkKey;
170170
this.clientVersion = clientVersion;
171171
this.dataGovernance = options?.dataGovernance ?? DataGovernance.Global;
172172

@@ -244,11 +244,11 @@ export abstract class OptionsBase {
244244
}
245245

246246
getUrl(): string {
247-
return this.baseUrl + "/configuration-files/" + this.apiKey + "/" + OptionsBase.configFileName + "?sdk=" + this.clientVersion;
247+
return this.baseUrl + "/configuration-files/" + this.sdkKey + "/" + OptionsBase.configFileName + "?sdk=" + this.clientVersion;
248248
}
249249

250250
getCacheKey(): string {
251-
return sha1(`${this.apiKey}_${OptionsBase.configFileName}_${ProjectConfig.serializationFormatVersion}`);
251+
return sha1(`${this.sdkKey}_${OptionsBase.configFileName}_${ProjectConfig.serializationFormatVersion}`);
252252
}
253253
}
254254

@@ -258,11 +258,11 @@ export class AutoPollOptions extends OptionsBase {
258258

259259
maxInitWaitTimeSeconds: number = 5;
260260

261-
constructor(apiKey: string, sdkType: string, sdkVersion: string, options?: IAutoPollOptions | null,
261+
constructor(sdkKey: string, sdkType: string, sdkVersion: string, options?: IAutoPollOptions | null,
262262
defaultCacheFactory?: ((options: OptionsBase) => IConfigCache) | null,
263263
eventEmitterFactory?: (() => IEventEmitter) | null) {
264264

265-
super(apiKey, sdkType + "/a-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
265+
super(sdkKey, sdkType + "/a-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
266266

267267
if (options) {
268268

@@ -290,23 +290,23 @@ export class AutoPollOptions extends OptionsBase {
290290
}
291291

292292
export class ManualPollOptions extends OptionsBase {
293-
constructor(apiKey: string, sdkType: string, sdkVersion: string, options?: IManualPollOptions | null,
293+
constructor(sdkKey: string, sdkType: string, sdkVersion: string, options?: IManualPollOptions | null,
294294
defaultCacheFactory?: ((options: OptionsBase) => IConfigCache) | null,
295295
eventEmitterFactory?: (() => IEventEmitter) | null) {
296296

297-
super(apiKey, sdkType + "/m-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
297+
super(sdkKey, sdkType + "/m-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
298298
}
299299
}
300300

301301
export class LazyLoadOptions extends OptionsBase {
302302

303303
cacheTimeToLiveSeconds: number = 60;
304304

305-
constructor(apiKey: string, sdkType: string, sdkVersion: string, options?: ILazyLoadingOptions | null,
305+
constructor(sdkKey: string, sdkType: string, sdkVersion: string, options?: ILazyLoadingOptions | null,
306306
defaultCacheFactory?: ((options: OptionsBase) => IConfigCache) | null,
307307
eventEmitterFactory?: (() => IEventEmitter) | null) {
308308

309-
super(apiKey, sdkType + "/l-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
309+
super(sdkKey, sdkType + "/l-" + sdkVersion, options, defaultCacheFactory, eventEmitterFactory);
310310

311311
if (options) {
312312
if (options.cacheTimeToLiveSeconds != null) {

src/Hooks.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
import { ClientCacheState } from "./ConfigServiceBase";
1+
import type { ClientCacheState } from "./ConfigServiceBase";
22
import type { IEventEmitter, IEventProvider } from "./EventEmitter";
33
import { NullEventEmitter } from "./EventEmitter";
44
import type { IConfig } from "./ProjectConfig";
55
import type { IEvaluationDetails } from "./RolloutEvaluator";
66

7-
/**
8-
* Contains the initialization state of `ConfigCatClient`.
9-
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
10-
*/
11-
export type ClientReadyState = ClientCacheState;
12-
13-
/**
14-
* @deprecated This type is obsolete and will be removed from the public API in a future major version. Please use `ClientCacheState` instead.
15-
*/
16-
// eslint-disable-next-line @typescript-eslint/naming-convention
17-
export const ClientReadyState = ClientCacheState;
18-
197
/** Hooks (events) that can be emitted by `ConfigCatClient`. */
208
export type HookEvents = {
219
/** Occurs when the client is ready to provide the actual value of feature flags or settings. */

src/RolloutEvaluator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,10 @@ export interface IEvaluationDetails<TValue = SettingValue> {
833833
/** The exception object related to the error in case evaluation failed (if any). */
834834
errorException?: any;
835835

836-
/** The targeting rule which was used to select the evaluated value (if any). */
836+
/** The targeting rule (if any) that matched during the evaluation and was used to return the evaluated value. */
837837
matchedTargetingRule?: ITargetingRule;
838838

839-
/** The percentage option which was used to select the evaluated value (if any). */
839+
/** The percentage option (if any) that was used to select the evaluated value. */
840840
matchedPercentageOption?: IPercentageOption;
841841
}
842842

src/User.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,32 @@ export class User {
1919
/**
2020
* Custom attributes of the user for advanced targeting rule definitions (e.g. user role, subscription type, etc.)
2121
* @remarks
22-
* The set of allowed attribute values depends on the comparison type of the condition which references the User Object attribute.
23-
* `string` values are supported by all comparison types (in some cases they need to be provided in a specific format though).
24-
* Some of the comparison types work with other types of values, as described below.
22+
* All comparators support `string` values as User Object attribute (in some cases they need to be provided in a specific format though, see below),
23+
* but some of them also support other types of values. It depends on the comparator how the values will be handled. The following rules apply:
2524
*
26-
* Text-based comparisons (EQUALS, IS ONE OF, etc.)<br/>
27-
* * accept `string` values,<br/>
28-
* * all other values are automatically converted to string (a warning will be logged but evaluation will continue as normal).
25+
* **Text-based comparators** (EQUALS, IS ONE OF, etc.)
26+
* * accept `string` values,
27+
* * all other values are automatically converted to `string` (a warning will be logged but evaluation will continue as normal).
2928
*
30-
* SemVer-based comparisons (IS ONE OF, &lt;, &gt;=, etc.)<br/>
31-
* * accept `string` values containing a properly formatted, valid semver value,<br/>
29+
* **SemVer-based comparators** (IS ONE OF, &lt;, &gt;=, etc.)
30+
* * accept `string` values containing a properly formatted, valid semver value,
3231
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped).
3332
*
34-
* Number-based comparisons (=, &lt;, &gt;=, etc.)<br/>
35-
* * accept `number` values,<br/>
36-
* * accept `string` values containing a properly formatted, valid `number` value,<br/>
33+
* **Number-based comparators** (=, &lt;, &gt;=, etc.)
34+
* * accept `number` values,
35+
* * accept `string` values containing a properly formatted, valid `number` value,
3736
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped).
3837
*
39-
* Date time-based comparisons (BEFORE / AFTER)<br/>
40-
* * accept `Date` values, which are automatically converted to a second-based Unix timestamp,<br/>
41-
* * accept `number` values representing a second-based Unix timestamp,<br/>
42-
* * accept `string` values containing a properly formatted, valid `number` value,<br/>
38+
* **Date time-based comparators** (BEFORE / AFTER)
39+
* * accept `Date` values, which are automatically converted to a second-based Unix timestamp,
40+
* * accept `number` values representing a second-based Unix timestamp,
41+
* * accept `string` values containing a properly formatted, valid `number` value,
4342
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped).
4443
*
45-
* String array-based comparisons (ARRAY CONTAINS ANY OF / ARRAY NOT CONTAINS ANY OF)<br/>
46-
* * accept arrays of `string`,<br/>
47-
* * accept `string` values containing a valid JSON string which can be deserialized to an array of `string`,<br/>
44+
* **String array-based comparators** (ARRAY CONTAINS ANY OF / ARRAY NOT CONTAINS ANY OF)
45+
* * accept arrays of `string`,
46+
* * accept `string` values containing a valid JSON string which can be deserialized to an array of `string`,
4847
* * all other values are considered invalid (a warning will be logged and the currently evaluated targeting rule will be skipped).
49-
*
50-
* In case a non-string attribute value needs to be converted to `string` during evaluation, it will always be done using the same format
51-
* which is accepted by the comparisons.
5248
**/
5349
public custom: { [key: string]: UserAttributeValue } = {}
5450
) {

src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,3 @@ export { OverrideBehaviour } from "./FlagOverrides";
106106
export { ClientCacheState, RefreshResult } from "./ConfigServiceBase";
107107

108108
export type { IProvidesHooks, HookEvents } from "./Hooks";
109-
110-
export { ClientReadyState } from "./Hooks";

test/ConfigCatClientOptionsTests.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ describe("Options", () => {
2121
assert.instanceOf(options.cache, InMemoryConfigCache);
2222
});
2323

24-
it("ManualPollOptions initialization With 'apiKey' Should create an instance, defaults OK", () => {
24+
it("ManualPollOptions initialization With 'sdkKey' Should create an instance, defaults OK", () => {
2525
const options: ManualPollOptions = new ManualPollOptions("APIKEY", "common", "1.0.0", null, null);
2626
assert.isDefined(options);
2727

28-
assert.equal("APIKEY", options.apiKey);
28+
assert.equal("APIKEY", options.sdkKey);
2929
assert.equal(30000, options.requestTimeoutMs);
3030
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/m-1.0.0", options.getUrl());
3131
});
@@ -44,7 +44,7 @@ describe("Options", () => {
4444

4545
assert.isDefined(options);
4646
assert.equal(fakeLogger, options.logger["logger"]);
47-
assert.equal("APIKEY", options.apiKey);
47+
assert.equal("APIKEY", options.sdkKey);
4848
assert.equal(10, options.requestTimeoutMs);
4949
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/m-1.0.0", options.getUrl());
5050
assert.equal("http://fake-proxy.com:8080", options.proxy);
@@ -65,12 +65,12 @@ describe("Options", () => {
6565
}).to.throw("Invalid 'requestTimeoutMs' value");
6666
});
6767

68-
it("AutoPollOptions initialization With 'apiKey' Should create an instance, defaults OK", () => {
68+
it("AutoPollOptions initialization With 'sdkKey' Should create an instance, defaults OK", () => {
6969
const options: AutoPollOptions = new AutoPollOptions("APIKEY", "common", "1.0.0", null, null);
7070
assert.isDefined(options);
7171
assert.isTrue(options.logger instanceof LoggerWrapper);
7272
assert.isTrue(options.logger["logger"] instanceof ConfigCatConsoleLogger);
73-
assert.equal("APIKEY", options.apiKey);
73+
assert.equal("APIKEY", options.sdkKey);
7474
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/a-1.0.0", options.getUrl());
7575
assert.equal(60, options.pollIntervalSeconds);
7676
assert.equal(30000, options.requestTimeoutMs);
@@ -92,7 +92,7 @@ describe("Options", () => {
9292

9393
assert.isDefined(options);
9494
assert.equal(fakeLogger, options.logger["logger"]);
95-
assert.equal("APIKEY", options.apiKey);
95+
assert.equal("APIKEY", options.sdkKey);
9696
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/a-1.0.0", options.getUrl());
9797
assert.equal(59, options.pollIntervalSeconds);
9898
assert.equal(20, options.requestTimeoutMs);
@@ -208,10 +208,10 @@ describe("Options", () => {
208208
assert.equal(options.maxInitWaitTimeSeconds, 5);
209209
});
210210

211-
it("LazyLoadOptions initialization With 'apiKey' Should create an instance, defaults OK", () => {
211+
it("LazyLoadOptions initialization With 'sdkKey' Should create an instance, defaults OK", () => {
212212
const options: LazyLoadOptions = new LazyLoadOptions("APIKEY", "common", "1.0.0", null, null);
213213
assert.isDefined(options);
214-
assert.equal("APIKEY", options.apiKey);
214+
assert.equal("APIKEY", options.sdkKey);
215215
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/l-1.0.0", options.getUrl());
216216
assert.equal(60, options.cacheTimeToLiveSeconds);
217217
assert.equal(30000, options.requestTimeoutMs);
@@ -231,7 +231,7 @@ describe("Options", () => {
231231

232232
assert.isDefined(options);
233233
assert.equal(fakeLogger, options.logger["logger"]);
234-
assert.equal("APIKEY", options.apiKey);
234+
assert.equal("APIKEY", options.sdkKey);
235235
assert.equal("https://cdn-global.configcat.com/configuration-files/APIKEY/config_v6.json?sdk=common/l-1.0.0", options.getUrl());
236236
assert.equal(59, options.cacheTimeToLiveSeconds);
237237
assert.equal(20, options.requestTimeoutMs);

0 commit comments

Comments
 (0)