1 | 'use strict';
|
2 |
|
3 | const { ROLLOUT_KEY, IS_ON_PREM } = require('./config');
|
4 | const logger = require('./logger').getLogger('FeatureFlagsService');
|
5 | const Promise = require('bluebird');
|
6 | const Rox = require('rox-node');
|
7 |
|
8 |
|
9 | const USE_FEATURE_FLAGS = !IS_ON_PREM && !process.env.IS_UNIT_TEST;
|
10 |
|
11 | const FORCE_FETCH_TIMEOUT_MS = 20000;
|
12 | const SEC_IN_DAY = 60 * 60 * 24;
|
13 |
|
14 | class FeatureFlagsService {
|
15 | constructor() {
|
16 | this.flags = {
|
17 | useNewWebdriverApi: new Rox.Flag(),
|
18 | useNewWSCLI: new Rox.Flag(),
|
19 | disableEdgeVisibilityChecks: new Rox.Flag(),
|
20 | useSafariWebdriverVisibilityChecks: new Rox.Flag(),
|
21 | useClickimVisibilityChecks: new Rox.Flag(),
|
22 | useIEWebdriverVisibilityChecks: new Rox.Flag(),
|
23 | enableTDKRun: new Rox.Flag(true),
|
24 | runGetElementCodeInAut: new Rox.Flag(),
|
25 | enableNpmPackageInstallUsingNpmCli: new Rox.Flag(),
|
26 | enableFrameSwitchOptimization: new Rox.Flag(),
|
27 | maximumJsResultSize: new Rox.Configuration(2000 * 1024),
|
28 | skipFileInputClicks: new Rox.Flag(),
|
29 | enableMockNetwork: new Rox.Flag(),
|
30 | errorMessageOnBadNetwork: new Rox.Flag(true),
|
31 | warnOnBadNetwork: new Rox.Flag(false),
|
32 | };
|
33 | Rox.register('default', this.flags);
|
34 | }
|
35 |
|
36 | setProjectId(projectId) {
|
37 | Rox.setCustomStringProperty('projectId', projectId);
|
38 | }
|
39 |
|
40 | setCompanyId(companyId) {
|
41 | Rox.setCustomStringProperty('companyId', companyId);
|
42 | }
|
43 |
|
44 | setRunnerMode(mode) {
|
45 | Rox.setCustomStringProperty('runnerMode', mode);
|
46 | }
|
47 |
|
48 | fetch() {
|
49 | if (!USE_FEATURE_FLAGS) {
|
50 | return Promise.resolve();
|
51 | }
|
52 | const opts = {
|
53 | fetchIntervalInSec: SEC_IN_DAY,
|
54 | disableNetworkFetch: false,
|
55 | };
|
56 |
|
57 |
|
58 | if (global.ProxyAgent) {
|
59 | const agent = new global.ProxyAgent(global.proxyUri);
|
60 | opts.httpsAgent = agent;
|
61 | opts.httpAgent = agent;
|
62 | }
|
63 |
|
64 | return Promise.resolve(Rox.setup(ROLLOUT_KEY, opts))
|
65 | .timeout(FORCE_FETCH_TIMEOUT_MS).catch(err => logger.error('failed to get feature flag status', err));
|
66 | }
|
67 | }
|
68 |
|
69 | module.exports = new FeatureFlagsService();
|