Skip to content

Commit 15eea28

Browse files
authored
Merge pull request #41 from switcherapi/3.0.0
3.0.0
2 parents 1e3b80a + 0879b54 commit 15eea28

File tree

14 files changed

+104
-149
lines changed

14 files changed

+104
-149
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "switcher-client",
33
"version": "2.1.1",
4-
"description": "Module for working with Switcher-API",
4+
"description": "SDK for working with Switcher-API",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",
77
"author": {

src/index.d.ts

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Key from "./lib/key";
2+
13
/**
24
* Quick start with the following 3 steps.
35
*
@@ -7,13 +9,15 @@
79
*/
810
declare class Switcher {
911

12+
constructor();
13+
1014
/**
1115
* Create the necessary configuration to communicate with the API
1216
*
1317
* @param context Necessary arguments
1418
* @param options
1519
*/
16-
static buildContext(context: SwitcherContext, options: SwitcherOptions): void;
20+
static buildContext(context: Switcher.SwitcherContext, options: Switcher.SwitcherOptions): void;
1721

1822
/**
1923
* Creates a new instance of Switcher
@@ -39,7 +43,7 @@ declare class Switcher {
3943
/**
4044
* Strategies available to use as Switcher input
4145
*/
42-
static get StrategiesType(): StrategiesType;
46+
static get StrategiesType(): Switcher.StrategiesType;
4347

4448
/**
4549
* Force a switcher value to return a given value by calling one of both methods - true() false()
@@ -97,32 +101,35 @@ declare class Switcher {
97101

98102
}
99103

100-
declare interface SwitcherContext {
101-
url: string;
102-
apiKey: string;
103-
domain: string;
104-
component: string;
105-
environment: string;
106-
token?: string;
107-
exp?: number;
108-
}
109-
110-
declare interface SwitcherOptions {
111-
offline: boolean;
112-
logger: boolean;
113-
snapshotLocation: string;
114-
snapshotAutoload: string;
115-
silentMode: boolean;
116-
retryAfter: string;
117-
}
118-
119-
declare interface StrategiesType {
120-
NETWORK: string;
121-
VALUE: string;
122-
NUMERIC: string;
123-
TIME: string;
124-
DATE: string;
125-
REGEX: string;
104+
declare namespace Switcher {
105+
106+
interface SwitcherContext {
107+
url: string;
108+
apiKey: string;
109+
domain: string;
110+
component: string;
111+
environment: string;
112+
token?: string;
113+
exp?: number;
114+
}
115+
116+
interface SwitcherOptions {
117+
offline: boolean;
118+
logger: boolean;
119+
snapshotLocation: string;
120+
snapshotAutoload: string;
121+
silentMode: boolean;
122+
retryAfter: string;
123+
}
124+
125+
interface StrategiesType {
126+
NETWORK: string;
127+
VALUE: string;
128+
NUMERIC: string;
129+
TIME: string;
130+
DATE: string;
131+
REGEX: string;
132+
}
126133
}
127134

128135
export = Switcher;

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const Bypasser = require('./lib/bypasser');
4-
const ExecutionLogger = require('./lib/executionLogger');
4+
const ExecutionLogger = require('./lib/utils/executionLogger');
55
const { loadDomain, validateSnapshot, StrategiesType } = require('./lib/snapshot');
66
const services = require('./lib/services');
77
const checkCriteriaOffline = require('./lib/resolver');

src/lib/bypasser.d.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/lib/bypasser.js renamed to src/lib/bypasser/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ var bypassedKeys = new Array();
55

66
class Bypasser {
77

8+
/**
9+
* Force a switcher value to return a given value by calling one of both methods - true() false()
10+
*
11+
* @param key
12+
*/
813
static assume(key) {
914
const existentKey = this.searchBypassed(key, bypassedKeys);
1015
if (existentKey) {
@@ -16,11 +21,21 @@ class Bypasser {
1621
return keyBypassed;
1722
}
1823

24+
/**
25+
* Remove forced value from a switcher
26+
*
27+
* @param key
28+
*/
1929
static forget(key) {
2030
bypassedKeys.splice(
2131
bypassedKeys.indexOf(this.searchBypassed(key, bypassedKeys)), 1);
2232
}
2333

34+
/**
35+
* Search for key registered via 'assume'
36+
*
37+
* @param key
38+
*/
2439
static searchBypassed(key) {
2540
let existentKey;
2641
bypassedKeys.forEach(async bk => {

src/lib/key.js renamed to src/lib/bypasser/key.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,39 @@
11
'use strict';
22

3+
/**
4+
* Type definition for Switcher Keys which are used to mock results
5+
*/
36
class Key {
7+
48
constructor(key) {
59
this.key = key;
610
this.value = undefined;
711
}
812

13+
/**
14+
* Force result to true
15+
*/
916
true() {
1017
this.value = true;
1118
}
1219

20+
/**
21+
* Force result to false
22+
*/
1323
false() {
1424
this.value = false;
1525
}
1626

27+
/**
28+
* Return selected switcher name
29+
*/
1730
getKey() {
1831
return this.key;
1932
}
2033

34+
/**
35+
* Return current value
36+
*/
2137
getValue() {
2238
return this.value;
2339
}

src/lib/datemoment.d.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/lib/executionLogger.d.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/lib/key.d.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

src/lib/services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const axios = require('axios');
2-
const DateMoment = require('./datemoment');
2+
const DateMoment = require('./utils/datemoment');
33

44
const getConnectivityError = (code) => `Connection has been refused - ${code}`;
55

0 commit comments

Comments
 (0)