Skip to content

Commit acafdaf

Browse files
committed
chore: format
1 parent 700f996 commit acafdaf

File tree

1 file changed

+50
-46
lines changed

1 file changed

+50
-46
lines changed

src/FeatureProbe.ts

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import 'whatwg-fetch';
2-
import { TinyEmitter } from 'tiny-emitter';
3-
import { Base64 } from 'js-base64';
4-
import { FPUser } from './FPUser';
1+
import "whatwg-fetch";
2+
import { TinyEmitter } from "tiny-emitter";
3+
import { Base64 } from "js-base64";
4+
import { FPUser } from "./FPUser";
55

66
const PKG_VERSION = require("../package.json").version;
77
const USER_AGENT = "Js/" + PKG_VERSION;
88

99
const EVENTS = {
10-
READY: 'ready',
11-
ERROR: 'error',
10+
READY: "ready",
11+
ERROR: "error",
1212
};
1313

1414
interface IValue {
@@ -67,26 +67,28 @@ class FeatureProbe extends TinyEmitter {
6767
}: IOption) {
6868
super();
6969
if (!clientSdkKey) {
70-
throw new Error('clientSdkKey is required');
70+
throw new Error("clientSdkKey is required");
7171
}
7272
if (refreshInterval <= 0) {
73-
throw new Error('refreshInterval is invalid');
73+
throw new Error("refreshInterval is invalid");
7474
}
7575

7676
if (!remoteUrl && !togglesUrl) {
77-
throw new Error('remoteUrl or togglesUrl is required');
77+
throw new Error("remoteUrl or togglesUrl is required");
7878
}
7979

8080
if (!remoteUrl && !eventsUrl) {
81-
throw new Error('remoteUrl or eventsUrl is required');
81+
throw new Error("remoteUrl or eventsUrl is required");
8282
}
8383

8484
if (!remoteUrl && !togglesUrl && !eventsUrl) {
85-
throw new Error('remoteUrl is required');
85+
throw new Error("remoteUrl is required");
8686
}
8787

88-
this.togglesUrl = new URL(togglesUrl || (remoteUrl + '/api/client-sdk/toggles'));
89-
this.eventsUrl = new URL(eventsUrl || (remoteUrl + '/api/server/events'));
88+
this.togglesUrl = new URL(
89+
togglesUrl || remoteUrl + "/api/client-sdk/toggles"
90+
);
91+
this.eventsUrl = new URL(eventsUrl || remoteUrl + "/api/server/events");
9092
this.user = user;
9193
this.clientSdkKey = clientSdkKey;
9294
this.refreshInterval = refreshInterval;
@@ -105,35 +107,35 @@ class FeatureProbe extends TinyEmitter {
105107
}
106108

107109
public boolValue(key: string, defaultValue: boolean): boolean {
108-
return this.toggleValue(key, defaultValue, 'boolean') as boolean;
110+
return this.toggleValue(key, defaultValue, "boolean") as boolean;
109111
}
110112

111113
public numberValue(key: string, defaultValue: number): number {
112-
return this.toggleValue(key, defaultValue, 'number') as number;
114+
return this.toggleValue(key, defaultValue, "number") as number;
113115
}
114116

115117
public stringValue(key: string, defaultValue: string): string {
116-
return this.toggleValue(key, defaultValue, 'string') as string;
118+
return this.toggleValue(key, defaultValue, "string") as string;
117119
}
118120

119121
public jsonValue(key: string, defaultValue: object): object {
120-
return this.toggleValue(key, defaultValue, 'object') as object;
122+
return this.toggleValue(key, defaultValue, "object") as object;
121123
}
122124

123125
public boolDetail(key: string, defaultValue: boolean): FPToggleDetail {
124-
return this.toggleDetail(key, defaultValue, 'boolean');
126+
return this.toggleDetail(key, defaultValue, "boolean");
125127
}
126128

127129
public numberDetail(key: string, defaultValue: number): FPToggleDetail {
128-
return this.toggleDetail(key, defaultValue, 'number');
130+
return this.toggleDetail(key, defaultValue, "number");
129131
}
130132

131133
public stringDetail(key: string, defaultValue: string): FPToggleDetail {
132-
return this.toggleDetail(key, defaultValue, 'string');
134+
return this.toggleDetail(key, defaultValue, "string");
133135
}
134136

135137
public jsonDetail(key: string, defaultValue: object): FPToggleDetail {
136-
return this.toggleDetail(key, defaultValue, 'object');
138+
return this.toggleDetail(key, defaultValue, "object");
137139
}
138140

139141
public allToggles(): { [key: string]: FPToggleDetail } | undefined {
@@ -177,7 +179,7 @@ class FeatureProbe extends TinyEmitter {
177179
ruleIndex: null,
178180
variationIndex: null,
179181
version: 0,
180-
reason: 'Not ready',
182+
reason: "Not ready",
181183
};
182184
}
183185

@@ -188,7 +190,7 @@ class FeatureProbe extends TinyEmitter {
188190
ruleIndex: null,
189191
variationIndex: null,
190192
version: null,
191-
reason: 'Toggle: [' + key + '] not found',
193+
reason: "Toggle: [" + key + "] not found",
192194
};
193195
} else if (typeof detail.value === valueType) {
194196
return detail;
@@ -198,7 +200,7 @@ class FeatureProbe extends TinyEmitter {
198200
ruleIndex: null,
199201
variationIndex: null,
200202
version: null,
201-
reason: 'Value type mismatch',
203+
reason: "Value type mismatch",
202204
};
203205
}
204206
}
@@ -207,15 +209,15 @@ class FeatureProbe extends TinyEmitter {
207209
const userStr = JSON.stringify(this.user);
208210
const userParam = Base64.encode(userStr);
209211
const url = this.togglesUrl;
210-
url.searchParams.set('user', userParam);
212+
url.searchParams.set("user", userParam);
211213

212214
await fetch(url.toString(), {
213-
method: 'GET',
214-
cache: 'no-cache',
215+
method: "GET",
216+
cache: "no-cache",
215217
headers: {
216218
Authorization: this.clientSdkKey,
217-
'Content-Type': 'application/json',
218-
'User-Agent': USER_AGENT,
219+
"Content-Type": "application/json",
220+
"User-Agent": USER_AGENT,
219221
},
220222
})
221223
.then((response) => {
@@ -234,28 +236,30 @@ class FeatureProbe extends TinyEmitter {
234236
const timestamp = Date.now();
235237
const payload: IParams[] = [
236238
{
237-
'access': {
238-
'startTime': timestamp,
239-
'endTime': timestamp,
240-
'counters': {
241-
[key]: [{
242-
'count': 1,
243-
'value': this.toggles[key].value,
244-
'index': this.toggles[key].variationIndex,
245-
'version': this.toggles[key].version,
246-
}]
247-
}
248-
}
249-
}
239+
access: {
240+
startTime: timestamp,
241+
endTime: timestamp,
242+
counters: {
243+
[key]: [
244+
{
245+
count: 1,
246+
value: this.toggles[key].value,
247+
index: this.toggles[key].variationIndex,
248+
version: this.toggles[key].version,
249+
},
250+
],
251+
},
252+
},
253+
},
250254
];
251255

252256
await fetch(this.eventsUrl.toString(), {
253-
cache: 'no-cache',
254-
method: 'POST',
257+
cache: "no-cache",
258+
method: "POST",
255259
headers: {
256260
Authorization: this.clientSdkKey,
257-
'Content-Type': 'application/json',
258-
'User-Agent': USER_AGENT,
261+
"Content-Type": "application/json",
262+
"User-Agent": USER_AGENT,
259263
},
260264
body: JSON.stringify(payload),
261265
});

0 commit comments

Comments
 (0)