From 70cebe142e7dbc27e08f3097d7efdc67ab7b183c Mon Sep 17 00:00:00 2001 From: petruki <31597636+petruki@users.noreply.github.com> Date: Tue, 8 Jul 2025 19:53:35 -0700 Subject: [PATCH] Renamed context attribute name to match effect (freeze) --- README.md | 6 +++--- package.json | 8 ++++---- sonar-project.properties | 2 +- src/client.d.ts | 10 ++++------ src/client.js | 4 ++-- src/lib/constants.js | 2 +- src/lib/globals/globalOptions.js | 4 ++-- src/switcher.js | 2 +- tests/switcher-client.test.js | 4 ++-- 9 files changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index bd8a2cc..5f5996d 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ You can also activate features such as local and silent mode: ```js const local = true; -const static = true; +const freeze = true; const logger = true; const snapshotLocation = './snapshot/'; const snapshotAutoUpdateInterval = 3; @@ -70,7 +70,7 @@ const restrictRelay = true; const certPath = './certs/ca.pem'; Client.buildContext({ url, apiKey, domain, component, environment }, { - local, static, logger, snapshotLocation, snapshotAutoUpdateInterval, + local, freeze, logger, snapshotLocation, snapshotAutoUpdateInterval, snapshotWatcher, silentMode, restrictRelay, certPath }); @@ -78,7 +78,7 @@ const switcher = Client.getSwitcher(); ``` - **local**: If activated, the client will only fetch the configuration inside your snapshot file. The default value is 'false' -- **static**: If activated, the client will not perform any API calls and will only use the in-memory snapshot. The default value is 'false' +- **freeze**: If activated, prevents the execution of background cache update when using throttle. The default value is 'false' - **logger**: If activated, it is possible to retrieve the last results from a given Switcher key using Client.getLogger('KEY') - **snapshotLocation**: Location of snapshot files - **snapshotAutoUpdateInterval**: Enable Snapshot Auto Update given an interval in seconds (default: 0 disabled) diff --git a/package.json b/package.json index dbb327d..3baaf19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "switcher-client", - "version": "4.4.0", + "version": "4.4.1", "description": "Client JS SDK for working with Switcher-API", "main": "./switcher-client.js", "type": "module", @@ -32,10 +32,10 @@ ], "devDependencies": { "@babel/eslint-parser": "^7.28.0", - "@typescript-eslint/eslint-plugin": "^8.35.1", - "@typescript-eslint/parser": "^8.35.1", + "@typescript-eslint/eslint-plugin": "^8.36.0", + "@typescript-eslint/parser": "^8.36.0", "c8": "^10.1.3", - "chai": "^5.2.0", + "chai": "^5.2.1", "env-cmd": "^10.1.0", "eslint": "^9.30.1", "mocha": "^11.7.1", diff --git a/sonar-project.properties b/sonar-project.properties index 58bcfeb..99a0c8e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,7 +1,7 @@ sonar.projectKey=switcherapi_switcher-client-master sonar.projectName=switcher-client-js sonar.organization=switcherapi -sonar.projectVersion=4.4.0 +sonar.projectVersion=4.4.1 sonar.links.homepage=https://github.com/switcherapi/switcher-client-js sonar.javascript.lcov.reportPaths=coverage/lcov.info diff --git a/src/client.d.ts b/src/client.d.ts index 5c567a0..6c49699 100644 --- a/src/client.d.ts +++ b/src/client.d.ts @@ -150,7 +150,7 @@ export type LoggerRecord = { } /** - * SwitcherContext is required to build the context to communicate with the API. + * SwitcherContext is required to build the context to communicate with the API */ export type SwitcherContext = { /** @@ -180,7 +180,7 @@ export type SwitcherContext = { } /** - * SwitcherOptions is optional to build the context to communicate with the API. + * SwitcherOptions is optional to build the context to communicate with the API */ export type SwitcherOptions = { /** @@ -191,13 +191,11 @@ export type SwitcherOptions = { local?: boolean; /** - * When enabled it will always use in-memory cached results - * - * This option prevents the scheduling of background updates to improve overall performance + * This option prevents the execution of background cache update when using throttle * * Use Client.clearLogger() to reset the in-memory cache if snapshot are renewed */ - static?: boolean; + freeze?: boolean; /** * When enabled it allows inspecting the result details with Client.getLogger(key) diff --git a/src/client.js b/src/client.js index 8e4bf79..37aead1 100644 --- a/src/client.js +++ b/src/client.js @@ -9,7 +9,7 @@ import { DEFAULT_LOGGER, DEFAULT_REGEX_MAX_BLACKLISTED, DEFAULT_REGEX_MAX_TIME_LIMIT, - DEFAULT_STATIC, + DEFAULT_FREEZE, DEFAULT_TEST_MODE, SWITCHER_OPTIONS } from './lib/constants.js'; @@ -40,7 +40,7 @@ export class Client { snapshotAutoUpdateInterval: 0, snapshotLocation: options?.snapshotLocation, local: util.get(options?.local, DEFAULT_LOCAL), - static: util.get(options?.static, DEFAULT_STATIC), + freeze: util.get(options?.freeze, DEFAULT_FREEZE), logger: util.get(options?.logger, DEFAULT_LOGGER) }); diff --git a/src/lib/constants.js b/src/lib/constants.js index 774ae7f..c1805d7 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -1,6 +1,6 @@ export const DEFAULT_ENVIRONMENT = 'default'; export const DEFAULT_LOCAL = false; -export const DEFAULT_STATIC = false; +export const DEFAULT_FREEZE = false; export const DEFAULT_LOGGER = false; export const DEFAULT_TEST_MODE = false; export const DEFAULT_REGEX_MAX_BLACKLISTED = 50; diff --git a/src/lib/globals/globalOptions.js b/src/lib/globals/globalOptions.js index aba0da3..e35210a 100644 --- a/src/lib/globals/globalOptions.js +++ b/src/lib/globals/globalOptions.js @@ -18,8 +18,8 @@ export class GlobalOptions { return this.#options.local; } - static get static() { - return this.#options.static; + static get freeze() { + return this.#options.freeze; } static get logger() { diff --git a/src/switcher.js b/src/switcher.js index 571ba0e..8520790 100644 --- a/src/switcher.js +++ b/src/switcher.js @@ -168,7 +168,7 @@ export class Switcher extends SwitcherRequest { #tryCachedResult() { if (this.#hasThrottle()) { - if (!GlobalOptions.static) { + if (!GlobalOptions.freeze) { this.scheduleBackgroundRefresh(); } diff --git a/tests/switcher-client.test.js b/tests/switcher-client.test.js index 0a4f796..fe3fa86 100644 --- a/tests/switcher-client.test.js +++ b/tests/switcher-client.test.js @@ -340,12 +340,12 @@ describe('E2E test - Client local from cache:', function () { assert.deepEqual(result.metadata || {}, {}); }); - it('should get response from cache when static mode is enabled', async function () { + it('should get response from cache when freeze mode is enabled', async function () { // given Client.buildContext(contextSettings, { snapshotLocation: options.snapshotLocation, local: true, - static: true + freeze: true }); await Client.loadSnapshot();