This repository has been archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
/
configuration.js
103 lines (91 loc) · 2.91 KB
/
configuration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
var winston = require('winston');
var InMemoryFeatureStore = require('./feature_store');
var messages = require('./messages');
var package_json = require('./package.json');
module.exports = (function() {
var defaults = {
baseUri: 'https://app.launchdarkly.com',
streamUri: 'https://stream.launchdarkly.com',
eventsUri: 'https://events.launchdarkly.com',
stream: true,
sendEvents: true,
timeout: 5,
capacity: 1000,
flushInterval: 5,
pollInterval: 30,
offline: false,
useLdd: false,
allAttributesPrivate: false,
privateAttributeNames: [],
userKeysCapacity: 1000,
userKeysFlushInterval: 300,
featureStore: InMemoryFeatureStore()
};
var deprecatedOptions = {
base_uri: 'baseUri',
stream_uri: 'streamUri',
events_uri: 'eventsUri',
send_events: 'sendEvents',
flush_interval: 'flushInterval',
poll_interval: 'pollInterval',
proxy_host: 'proxyHost',
proxy_port: 'proxyPort',
proxy_auth: 'proxyAuth',
feature_store: 'featureStore',
use_ldd: 'useLdd',
all_attributes_private: 'allAttributesPrivate',
private_attribute_names: 'privateAttributeNames'
};
function checkDeprecatedOptions(config) {
Object.keys(deprecatedOptions).forEach(function(oldName) {
if (config[oldName] !== undefined) {
var newName = deprecatedOptions[oldName];
config.logger.warn(messages.deprecated(oldName, newName));
if (config[newName] === undefined) {
config[newName] = config[oldName];
}
delete config[oldName];
}
});
}
function applyDefaults(config, defaults) {
// This works differently from Object.assign() in that it will *not* override a default value
// if the provided value is explicitly set to null.
var ret = Object.assign({}, config);
Object.keys(defaults).forEach(function(name) {
if (ret[name] === undefined || ret[name] === null) {
ret[name] = defaults[name];
}
});
return ret;
}
function canonicalizeUri(uri) {
return uri.replace(/\/+$/, "");
}
function validate(options) {
var config = Object.assign({}, options || {});
config.userAgent = 'NodeJSClient/' + package_json.version;
config.logger = (config.logger ||
new winston.Logger({
level: 'info',
transports: [
new (winston.transports.Console)(({
formatter: function(options) {
return '[LaunchDarkly] ' + (options.message ? options.message : '');
}
})),
]
})
);
checkDeprecatedOptions(config);
config = applyDefaults(config, defaults);
config.baseUri = canonicalizeUri(config.baseUri);
config.streamUri = canonicalizeUri(config.streamUri);
config.eventsUri = canonicalizeUri(config.eventsUri);
config.pollInterval = config.pollInterval > 30 ? config.pollInterval : 30;
return config;
}
return {
validate: validate
};
})();