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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -70,15 +70,15 @@ 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
});

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)
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 4 additions & 6 deletions src/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand Down Expand Up @@ -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 = {
/**
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)
});

Expand Down
2 changes: 1 addition & 1 deletion src/lib/constants.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/globals/globalOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class Switcher extends SwitcherRequest {

#tryCachedResult() {
if (this.#hasThrottle()) {
if (!GlobalOptions.static) {
if (!GlobalOptions.freeze) {
this.scheduleBackgroundRefresh();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/switcher-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down