featureflow-node-sdk 0.6.12 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/dist/Client.d.ts +0 -14
- package/dist/Client.js +0 -182
- package/dist/Conditions.d.ts +0 -1
- package/dist/Conditions.js +0 -76
- package/dist/Evaluate.d.ts +0 -11
- package/dist/Evaluate.js +0 -48
- package/dist/EvaluateHelpers.d.ts +0 -5
- package/dist/EvaluateHelpers.js +0 -97
- package/dist/EventsClient.d.ts +0 -19
- package/dist/EventsClient.js +0 -114
- package/dist/ExpressMiddleware.d.ts +0 -1
- package/dist/ExpressMiddleware.js +0 -31
- package/dist/Feature.d.ts +0 -12
- package/dist/Feature.js +0 -51
- package/dist/FeatureStore.d.ts +0 -8
- package/dist/FeatureStore.js +0 -49
- package/dist/PollingClient.d.ts +0 -15
- package/dist/PollingClient.js +0 -90
- package/dist/User.d.ts +0 -20
- package/dist/User.js +0 -75
- package/dist/debug.d.ts +0 -2
- package/dist/debug.js +0 -3
- package/dist/index.d.ts +0 -11
- package/dist/index.js +0 -36
package/package.json
CHANGED
package/dist/Client.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default class Featureflow {
|
|
2
|
-
constructor(config: any, callback?: (_err: any, self: any) => void);
|
|
3
|
-
failoverVariants: {};
|
|
4
|
-
isReady: boolean;
|
|
5
|
-
config: any;
|
|
6
|
-
eventsClient: EventsClient;
|
|
7
|
-
pollingClient: PollingClient;
|
|
8
|
-
ready(callback?: () => void): any;
|
|
9
|
-
evaluateAll(): any;
|
|
10
|
-
evaluate(key: any): any;
|
|
11
|
-
close(): void;
|
|
12
|
-
}
|
|
13
|
-
import EventsClient from "./EventsClient";
|
|
14
|
-
import PollingClient from "./PollingClient";
|
package/dist/Client.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
-
|
|
9
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
10
|
-
|
|
11
|
-
var _PollingClient = require('./PollingClient');
|
|
12
|
-
|
|
13
|
-
var _PollingClient2 = _interopRequireDefault(_PollingClient);
|
|
14
|
-
|
|
15
|
-
var _EventsClient = require('./EventsClient');
|
|
16
|
-
|
|
17
|
-
var _EventsClient2 = _interopRequireDefault(_EventsClient);
|
|
18
|
-
|
|
19
|
-
var _FeatureStore = require('./FeatureStore');
|
|
20
|
-
|
|
21
|
-
var _User = require('./User');
|
|
22
|
-
|
|
23
|
-
var _Evaluate = require('./Evaluate');
|
|
24
|
-
|
|
25
|
-
var _Evaluate2 = _interopRequireDefault(_Evaluate);
|
|
26
|
-
|
|
27
|
-
var _debug = require('./debug');
|
|
28
|
-
|
|
29
|
-
var _debug2 = _interopRequireDefault(_debug);
|
|
30
|
-
|
|
31
|
-
var _EvaluateHelpers = require('./EvaluateHelpers');
|
|
32
|
-
|
|
33
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
-
|
|
35
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
36
|
-
|
|
37
|
-
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
|
38
|
-
|
|
39
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
|
40
|
-
|
|
41
|
-
var EventEmitter = require('events');
|
|
42
|
-
|
|
43
|
-
var Featureflow = function (_EventEmitter) {
|
|
44
|
-
_inherits(Featureflow, _EventEmitter);
|
|
45
|
-
|
|
46
|
-
function Featureflow(config) {
|
|
47
|
-
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_err, self) {};
|
|
48
|
-
|
|
49
|
-
_classCallCheck(this, Featureflow);
|
|
50
|
-
|
|
51
|
-
var _this = _possibleConstructorReturn(this, (Featureflow.__proto__ || Object.getPrototypeOf(Featureflow)).call(this));
|
|
52
|
-
|
|
53
|
-
_this.failoverVariants = {};
|
|
54
|
-
_this.isReady = false;
|
|
55
|
-
|
|
56
|
-
(0, _debug2.default)("initializing client");
|
|
57
|
-
if (!callback && typeof config === "function") {
|
|
58
|
-
callback = config;
|
|
59
|
-
config = undefined;
|
|
60
|
-
}
|
|
61
|
-
_this.config = _extends({
|
|
62
|
-
baseUrl: 'https://app.featureflow.io',
|
|
63
|
-
eventsUrl: 'https://events.featureflow.io'
|
|
64
|
-
}, config);
|
|
65
|
-
|
|
66
|
-
_this.config.apiKey = _this.config.apiKey || process.env.FEATUREFLOW_SERVER_KEY || "";
|
|
67
|
-
if (!_this.config.apiKey.length) {
|
|
68
|
-
callback(new Error("Api Key must be provided"));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
_this.config.featureStore = new _FeatureStore.InMemoryFeatureStore();
|
|
72
|
-
_this.config.disableEvents = _this.config.disableEvents || false;
|
|
73
|
-
|
|
74
|
-
_this.eventsClient = new _EventsClient2.default(_this.config.apiKey, _this.config.eventsUrl, _this.config.disableEvents);
|
|
75
|
-
|
|
76
|
-
if (_this.config.withFeatures) {
|
|
77
|
-
_this.config.withFeatures.forEach(function (feature) {
|
|
78
|
-
(0, _debug2.default)('Registering feature with key ' + feature.key);
|
|
79
|
-
_this.failoverVariants[feature.key] = feature.failoverVariant;
|
|
80
|
-
});
|
|
81
|
-
_this.eventsClient.registerFeaturesEvent(_this.config.withFeatures);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
_this.pollingClient = new _PollingClient2.default(_this.config.baseUrl + '/api/sdk/v1/features', _this.config, function () {
|
|
85
|
-
(0, _debug2.default)("client initialized");
|
|
86
|
-
_this.isReady = true;
|
|
87
|
-
_this.emit('ready');
|
|
88
|
-
callback(null, _this);
|
|
89
|
-
});
|
|
90
|
-
return _this;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
_createClass(Featureflow, [{
|
|
94
|
-
key: 'ready',
|
|
95
|
-
value: function ready() {
|
|
96
|
-
var _this2 = this;
|
|
97
|
-
|
|
98
|
-
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
|
99
|
-
|
|
100
|
-
if (this.isReady) {
|
|
101
|
-
callback(null, this);
|
|
102
|
-
} else {
|
|
103
|
-
return this.once('ready', function () {
|
|
104
|
-
callback(null, _this2);
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: 'evaluateAll',
|
|
110
|
-
value: function (_evaluateAll) {
|
|
111
|
-
function evaluateAll() {
|
|
112
|
-
return _evaluateAll.apply(this, arguments);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
evaluateAll.toString = function () {
|
|
116
|
-
return _evaluateAll.toString();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
return evaluateAll;
|
|
120
|
-
}(function () {
|
|
121
|
-
return evaluateAll('anonymous');
|
|
122
|
-
})
|
|
123
|
-
}, {
|
|
124
|
-
key: 'evaluateAll',
|
|
125
|
-
value: function evaluateAll(user) {
|
|
126
|
-
var evaluatedFeatures = {};
|
|
127
|
-
var features = this.config.featureStore.getAll();
|
|
128
|
-
for (var p in features) {
|
|
129
|
-
if (features.hasOwnProperty(p)) {
|
|
130
|
-
var value = this.evaluate(p, user).value();
|
|
131
|
-
evaluatedFeatures[p] = value;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return evaluatedFeatures;
|
|
135
|
-
}
|
|
136
|
-
}, {
|
|
137
|
-
key: 'evaluate',
|
|
138
|
-
value: function (_evaluate) {
|
|
139
|
-
function evaluate(_x) {
|
|
140
|
-
return _evaluate.apply(this, arguments);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
evaluate.toString = function () {
|
|
144
|
-
return _evaluate.toString();
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
return evaluate;
|
|
148
|
-
}(function (key) {
|
|
149
|
-
return evaluate(key, 'anonymous');
|
|
150
|
-
})
|
|
151
|
-
}, {
|
|
152
|
-
key: 'evaluate',
|
|
153
|
-
value: function evaluate(key, user) {
|
|
154
|
-
var evaluatedVariant = void 0;
|
|
155
|
-
var feature = this.config.featureStore.get(key);
|
|
156
|
-
|
|
157
|
-
if (!feature) {
|
|
158
|
-
var failover = this.failoverVariants[key];
|
|
159
|
-
if (!failover) {
|
|
160
|
-
evaluatedVariant = "off";
|
|
161
|
-
} else {
|
|
162
|
-
evaluatedVariant = failover;
|
|
163
|
-
}
|
|
164
|
-
(0, _debug2.default)('Evaluating undefined feature \'' + key + '\' using the ' + (failover ? 'provided' : 'default') + ' failover \'' + evaluatedVariant + '\'');
|
|
165
|
-
} else {
|
|
166
|
-
evaluatedVariant = (0, _EvaluateHelpers.featureEvaluation)(feature, user);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
return new _Evaluate2.default(key, evaluatedVariant, user, this.eventsClient);
|
|
170
|
-
}
|
|
171
|
-
}, {
|
|
172
|
-
key: 'close',
|
|
173
|
-
value: function close() {
|
|
174
|
-
this.pollingClient.close();
|
|
175
|
-
this.eventsClient.close();
|
|
176
|
-
}
|
|
177
|
-
}]);
|
|
178
|
-
|
|
179
|
-
return Featureflow;
|
|
180
|
-
}(EventEmitter);
|
|
181
|
-
|
|
182
|
-
exports.default = Featureflow;
|
package/dist/Conditions.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function test(op: any, a: any, b: any): any;
|
package/dist/Conditions.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.test = test;
|
|
7
|
-
var operators = {
|
|
8
|
-
equals: function equals(a, b) {
|
|
9
|
-
return a === b;
|
|
10
|
-
},
|
|
11
|
-
contains: function contains(a, b) {
|
|
12
|
-
return typeof a === 'string' && a.indexOf(b) > -1;
|
|
13
|
-
},
|
|
14
|
-
startsWith: function startsWith(a, b) {
|
|
15
|
-
return typeof a === 'string' && a.startsWith(b);
|
|
16
|
-
},
|
|
17
|
-
endsWith: function endsWith(a, b) {
|
|
18
|
-
return typeof a === 'string' && a.endsWith(b);
|
|
19
|
-
},
|
|
20
|
-
matches: function matches(a, b) {
|
|
21
|
-
return typeof a === 'string' && typeof b === 'string' && new RegExp(b).test(a);
|
|
22
|
-
},
|
|
23
|
-
in: function _in(a, b) {
|
|
24
|
-
return typeof a === 'string' && Array.isArray(b) && b.indexOf(a) > -1;
|
|
25
|
-
},
|
|
26
|
-
notIn: function notIn(a, b) {
|
|
27
|
-
return typeof a === 'string' && Array.isArray(b) && b.indexOf(a) < 0;
|
|
28
|
-
},
|
|
29
|
-
before: function before(a, b) {
|
|
30
|
-
a = dateParse(a);
|
|
31
|
-
b = dateParse(b);
|
|
32
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
33
|
-
return a < b;
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
36
|
-
},
|
|
37
|
-
after: function after(a, b) {
|
|
38
|
-
a = dateParse(a);
|
|
39
|
-
b = dateParse(b);
|
|
40
|
-
if (typeof a === 'number' && typeof b === 'number') {
|
|
41
|
-
return a > b;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
},
|
|
45
|
-
greaterThan: function greaterThan(a, b) {
|
|
46
|
-
return a > b;
|
|
47
|
-
},
|
|
48
|
-
greaterThanOrEqual: function greaterThanOrEqual(a, b) {
|
|
49
|
-
return a >= b;
|
|
50
|
-
},
|
|
51
|
-
lessThan: function lessThan(a, b) {
|
|
52
|
-
return a < b;
|
|
53
|
-
},
|
|
54
|
-
lessThanOrEqual: function lessThanOrEqual(a, b) {
|
|
55
|
-
return a <= b;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function dateParse(date) {
|
|
60
|
-
if (typeof date === 'string') {
|
|
61
|
-
return Date.parse(date);
|
|
62
|
-
}
|
|
63
|
-
if (date instanceof Date) {
|
|
64
|
-
return date.getTime();
|
|
65
|
-
}
|
|
66
|
-
return date;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
var notFound = function notFound() {
|
|
70
|
-
return false;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
function test(op, a, b) {
|
|
74
|
-
b = ['in', 'notIn'].indexOf(op) >= 0 ? b : b[0];
|
|
75
|
-
return (operators[op] || notFound)(a, b);
|
|
76
|
-
}
|
package/dist/Evaluate.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export default class Evaluate {
|
|
2
|
-
constructor(featureKey: any, evaluatedVariant: any, user: any, eventsClient: any);
|
|
3
|
-
featureKey: any;
|
|
4
|
-
evaluatedVariant: any;
|
|
5
|
-
user: any;
|
|
6
|
-
eventsClient: any;
|
|
7
|
-
is(value: any): boolean;
|
|
8
|
-
isOn(): boolean;
|
|
9
|
-
isOff(): boolean;
|
|
10
|
-
value(): any;
|
|
11
|
-
}
|
package/dist/Evaluate.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
-
|
|
9
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
|
|
11
|
-
var Evaluate = function () {
|
|
12
|
-
function Evaluate(featureKey, evaluatedVariant, user, eventsClient) {
|
|
13
|
-
_classCallCheck(this, Evaluate);
|
|
14
|
-
|
|
15
|
-
this.featureKey = featureKey;
|
|
16
|
-
this.evaluatedVariant = evaluatedVariant;
|
|
17
|
-
this.user = user;
|
|
18
|
-
this.eventsClient = eventsClient;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_createClass(Evaluate, [{
|
|
22
|
-
key: 'is',
|
|
23
|
-
value: function is(value) {
|
|
24
|
-
this.eventsClient.evaluateEvent(this.featureKey, this.evaluatedVariant, value, this.user);
|
|
25
|
-
return value === this.evaluatedVariant;
|
|
26
|
-
}
|
|
27
|
-
}, {
|
|
28
|
-
key: 'isOn',
|
|
29
|
-
value: function isOn() {
|
|
30
|
-
return this.is('on');
|
|
31
|
-
}
|
|
32
|
-
}, {
|
|
33
|
-
key: 'isOff',
|
|
34
|
-
value: function isOff() {
|
|
35
|
-
return this.is('off');
|
|
36
|
-
}
|
|
37
|
-
}, {
|
|
38
|
-
key: 'value',
|
|
39
|
-
value: function value() {
|
|
40
|
-
this.eventsClient.evaluateEvent(this.featureKey, this.evaluatedVariant, null, this.user);
|
|
41
|
-
return this.evaluatedVariant;
|
|
42
|
-
}
|
|
43
|
-
}]);
|
|
44
|
-
|
|
45
|
-
return Evaluate;
|
|
46
|
-
}();
|
|
47
|
-
|
|
48
|
-
exports.default = Evaluate;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export function featureEvaluation(feature: any, user: any): any;
|
|
2
|
-
export function ruleMatches(rule: any, user: any): boolean;
|
|
3
|
-
export function getVariantSplitKey(variantSplits: any, variantValue: any): any;
|
|
4
|
-
export function calculateHash(salt: any, feature: any, id: any): any;
|
|
5
|
-
export function getVariantValue(hash: any): number;
|
package/dist/EvaluateHelpers.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.featureEvaluation = featureEvaluation;
|
|
7
|
-
exports.ruleMatches = ruleMatches;
|
|
8
|
-
exports.getVariantSplitKey = getVariantSplitKey;
|
|
9
|
-
exports.calculateHash = calculateHash;
|
|
10
|
-
exports.getVariantValue = getVariantValue;
|
|
11
|
-
|
|
12
|
-
var _bigInteger = require('big-integer');
|
|
13
|
-
|
|
14
|
-
var _bigInteger2 = _interopRequireDefault(_bigInteger);
|
|
15
|
-
|
|
16
|
-
var _sha1Hex = require('sha1-hex');
|
|
17
|
-
|
|
18
|
-
var _sha1Hex2 = _interopRequireDefault(_sha1Hex);
|
|
19
|
-
|
|
20
|
-
var _Conditions = require('./Conditions');
|
|
21
|
-
|
|
22
|
-
var _User = require('./User');
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function featureEvaluation(feature, user) {
|
|
27
|
-
if (user === null || typeof user === 'undefined') {
|
|
28
|
-
user = new _User.UserBuilder('anonymous').build();
|
|
29
|
-
} else if (typeof user === "string") {
|
|
30
|
-
user = new _User.UserBuilder(user).build();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (feature.enabled) {
|
|
34
|
-
var now = new Date();
|
|
35
|
-
var hourOfDay = now.getHours();
|
|
36
|
-
var hArray = new Array(1);
|
|
37
|
-
hArray[0] = hourOfDay;
|
|
38
|
-
user.attributes['featureflow.user.id'] = [user.id];
|
|
39
|
-
user.attributes['featureflow.date'] = [new Date().toISOString()];
|
|
40
|
-
user.attributes['featureflow.hourofday'] = hArray;
|
|
41
|
-
|
|
42
|
-
for (var i in feature.rules) {
|
|
43
|
-
var rule = feature.rules[i];
|
|
44
|
-
if (ruleMatches(feature.rules[i], user)) {
|
|
45
|
-
var variantValue = getVariantValue(calculateHash("1", feature.key, user.getId()));
|
|
46
|
-
return getVariantSplitKey(rule.variantSplits, variantValue);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return feature.offVariantKey;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function ruleMatches(rule, user) {
|
|
55
|
-
if (!rule.audience) {
|
|
56
|
-
return true;
|
|
57
|
-
} else {
|
|
58
|
-
for (var cKey in rule.audience.conditions) {
|
|
59
|
-
var condition = rule.audience.conditions[cKey];
|
|
60
|
-
var pass = false;
|
|
61
|
-
var values = user.getAttributesForKey(condition.target);
|
|
62
|
-
for (var vKey in values) {
|
|
63
|
-
var value = values[vKey];
|
|
64
|
-
if ((0, _Conditions.test)(condition.operator, value, condition.values)) {
|
|
65
|
-
pass = true;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (!pass) {
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function getVariantSplitKey(variantSplits, variantValue) {
|
|
78
|
-
var percent = 0.0;
|
|
79
|
-
for (var i in variantSplits) {
|
|
80
|
-
var variantSplit = variantSplits[i];
|
|
81
|
-
percent += variantSplit.split;
|
|
82
|
-
|
|
83
|
-
if (percent >= variantValue) {
|
|
84
|
-
return variantSplit.variantKey;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return "off";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function calculateHash(salt, feature, id) {
|
|
91
|
-
var hashValues = [salt || '1', feature || 'feature', id || 'anonymous'].join(':');
|
|
92
|
-
return (0, _sha1Hex2.default)(hashValues).substr(0, 15);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function getVariantValue(hash) {
|
|
96
|
-
return (0, _bigInteger2.default)(hash, 16).mod(100).toJSNumber() + 1;
|
|
97
|
-
}
|
package/dist/EventsClient.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export default class EventsClient {
|
|
2
|
-
constructor(apiKey: any, eventsUrl?: string, disabled?: boolean);
|
|
3
|
-
SEND_INTERVAL: number;
|
|
4
|
-
QUEUE_SIZE: number;
|
|
5
|
-
clientVersion: string;
|
|
6
|
-
queue: any[];
|
|
7
|
-
overLimit: boolean;
|
|
8
|
-
apiKey: any;
|
|
9
|
-
eventsUrl: string;
|
|
10
|
-
disabled: boolean;
|
|
11
|
-
sendInterval: number;
|
|
12
|
-
interval: number;
|
|
13
|
-
registerFeaturesEvent(features: any): void;
|
|
14
|
-
evaluateEvent(featureKey: any, evaluatedVariant: any, expectedVariant: any, user: any): void;
|
|
15
|
-
queueEvaluateEvent(event: any): void;
|
|
16
|
-
sendQueue(): void;
|
|
17
|
-
sendEvent(eventType: any, method: any, url: any, json: any): void;
|
|
18
|
-
close(): void;
|
|
19
|
-
}
|
package/dist/EventsClient.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
-
|
|
9
|
-
var _request = require('request');
|
|
10
|
-
|
|
11
|
-
var _request2 = _interopRequireDefault(_request);
|
|
12
|
-
|
|
13
|
-
var _debug = require('./debug');
|
|
14
|
-
|
|
15
|
-
var _debug2 = _interopRequireDefault(_debug);
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
|
|
21
|
-
var EventsClient = function () {
|
|
22
|
-
function EventsClient(apiKey) {
|
|
23
|
-
var _this = this;
|
|
24
|
-
|
|
25
|
-
var eventsUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "https://events.featureflow.io";
|
|
26
|
-
var disabled = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
27
|
-
|
|
28
|
-
_classCallCheck(this, EventsClient);
|
|
29
|
-
|
|
30
|
-
this.SEND_INTERVAL = 5;
|
|
31
|
-
this.QUEUE_SIZE = 10000;
|
|
32
|
-
this.clientVersion = 'NodeJsClient/0.6.11';
|
|
33
|
-
this.queue = [];
|
|
34
|
-
this.overLimit = false;
|
|
35
|
-
|
|
36
|
-
this.apiKey = apiKey;
|
|
37
|
-
this.eventsUrl = eventsUrl;
|
|
38
|
-
this.disabled = disabled;
|
|
39
|
-
this.sendInterval = this.SEND_INTERVAL;
|
|
40
|
-
this.interval = setInterval(function () {
|
|
41
|
-
_this.sendQueue();
|
|
42
|
-
}, this.sendInterval * 1000);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
_createClass(EventsClient, [{
|
|
46
|
-
key: 'registerFeaturesEvent',
|
|
47
|
-
value: function registerFeaturesEvent(features) {
|
|
48
|
-
this.sendEvent('Register Features', 'PUT', this.eventsUrl + '/api/sdk/v1/register', features);
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
key: 'evaluateEvent',
|
|
52
|
-
value: function evaluateEvent(featureKey, evaluatedVariant, expectedVariant, user) {
|
|
53
|
-
this.queueEvaluateEvent({
|
|
54
|
-
featureKey: featureKey,
|
|
55
|
-
evaluatedVariant: evaluatedVariant,
|
|
56
|
-
expectedVariant: expectedVariant,
|
|
57
|
-
user: user
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}, {
|
|
61
|
-
key: 'queueEvaluateEvent',
|
|
62
|
-
value: function queueEvaluateEvent(event) {
|
|
63
|
-
if (this.queue.length < this.QUEUE_SIZE) {
|
|
64
|
-
this.queue.push(event);
|
|
65
|
-
this.overLimit = false;
|
|
66
|
-
} else {
|
|
67
|
-
this.overLimit = true;
|
|
68
|
-
(0, _debug2.default)('Event queue limit exceeded. Increase queue size to prevent dropping events.', method, url, "Event Queue Exceeded");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}, {
|
|
72
|
-
key: 'sendQueue',
|
|
73
|
-
value: function sendQueue() {
|
|
74
|
-
if (this.queue.length === 0) return;
|
|
75
|
-
var sendQueue = this.queue;
|
|
76
|
-
this.queue = [];
|
|
77
|
-
|
|
78
|
-
this.sendEvent('evaluate', 'POST', this.eventsUrl + '/api/sdk/v1/events', sendQueue);
|
|
79
|
-
}
|
|
80
|
-
}, {
|
|
81
|
-
key: 'sendEvent',
|
|
82
|
-
value: function sendEvent(eventType, method, url, json) {
|
|
83
|
-
if (this.disabled) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
(0, _request2.default)({
|
|
87
|
-
method: method,
|
|
88
|
-
uri: url,
|
|
89
|
-
json: json,
|
|
90
|
-
headers: {
|
|
91
|
-
'Authorization': 'Bearer ' + this.apiKey,
|
|
92
|
-
'X-Featureflow-Client': this.clientVersion
|
|
93
|
-
}
|
|
94
|
-
}, function (error, response, body) {
|
|
95
|
-
if (error) {
|
|
96
|
-
(0, _debug2.default)('error %s to "%s". message:', method, url, error.message);
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (response.statusCode >= 400) {
|
|
100
|
-
(0, _debug2.default)("unable to send event %s to %s. Failed with response status %d", eventType, url, response.statusCode);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}, {
|
|
105
|
-
key: 'close',
|
|
106
|
-
value: function close() {
|
|
107
|
-
clearInterval(this.interval);
|
|
108
|
-
}
|
|
109
|
-
}]);
|
|
110
|
-
|
|
111
|
-
return EventsClient;
|
|
112
|
-
}();
|
|
113
|
-
|
|
114
|
-
exports.default = EventsClient;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function _default(options: any): (req: any, res: any, next: any) => void;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
exports.default = function (options) {
|
|
8
|
-
var _featureflow = void 0;
|
|
9
|
-
|
|
10
|
-
function respondWithFeatureflow(req, res, next) {
|
|
11
|
-
req.featureflow = _featureflow;
|
|
12
|
-
next();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return function (req, res, next) {
|
|
16
|
-
if (!_featureflow) {
|
|
17
|
-
new _Client2.default(options, function (err, featureflow) {
|
|
18
|
-
_featureflow = featureflow;
|
|
19
|
-
respondWithFeatureflow(req, res, next);
|
|
20
|
-
});
|
|
21
|
-
} else {
|
|
22
|
-
respondWithFeatureflow(req, res, next);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
var _Client = require('./Client');
|
|
28
|
-
|
|
29
|
-
var _Client2 = _interopRequireDefault(_Client);
|
|
30
|
-
|
|
31
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/dist/Feature.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export default class Feature {
|
|
2
|
-
constructor(key: any, failoverVariant?: string);
|
|
3
|
-
variants: any[];
|
|
4
|
-
key: any;
|
|
5
|
-
failoverVariant: string;
|
|
6
|
-
addVariant(key: any, value: any): Feature;
|
|
7
|
-
build(): {
|
|
8
|
-
key: any;
|
|
9
|
-
failoverVariant: string;
|
|
10
|
-
variants: any[];
|
|
11
|
-
};
|
|
12
|
-
}
|
package/dist/Feature.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
-
|
|
9
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10
|
-
|
|
11
|
-
var Feature = function () {
|
|
12
|
-
function Feature(key) {
|
|
13
|
-
var failoverVariant = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'off';
|
|
14
|
-
|
|
15
|
-
_classCallCheck(this, Feature);
|
|
16
|
-
|
|
17
|
-
this.variants = [];
|
|
18
|
-
|
|
19
|
-
this.key = key;
|
|
20
|
-
this.failoverVariant = failoverVariant;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
_createClass(Feature, [{
|
|
24
|
-
key: 'addVariant',
|
|
25
|
-
value: function addVariant(key, value) {
|
|
26
|
-
value = value || key;
|
|
27
|
-
this.variants.push({
|
|
28
|
-
key: key,
|
|
29
|
-
value: value
|
|
30
|
-
});
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
}, {
|
|
34
|
-
key: 'build',
|
|
35
|
-
value: function build() {
|
|
36
|
-
if (this.variants.length < 2) {
|
|
37
|
-
this.variants = [];
|
|
38
|
-
this.addVariant('on').addVariant('off');
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
key: this.key,
|
|
42
|
-
failoverVariant: this.failoverVariant,
|
|
43
|
-
variants: this.variants
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}]);
|
|
47
|
-
|
|
48
|
-
return Feature;
|
|
49
|
-
}();
|
|
50
|
-
|
|
51
|
-
exports.default = Feature;
|
package/dist/FeatureStore.d.ts
DELETED
package/dist/FeatureStore.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
-
|
|
9
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
var InMemoryFeatureStore = exports.InMemoryFeatureStore = function () {
|
|
14
|
-
function InMemoryFeatureStore() {
|
|
15
|
-
var features = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
-
|
|
17
|
-
_classCallCheck(this, InMemoryFeatureStore);
|
|
18
|
-
|
|
19
|
-
this.features = {};
|
|
20
|
-
this.setAll(features);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
_createClass(InMemoryFeatureStore, [{
|
|
24
|
-
key: "get",
|
|
25
|
-
value: function get(key) {
|
|
26
|
-
return this.features[key];
|
|
27
|
-
}
|
|
28
|
-
}, {
|
|
29
|
-
key: "set",
|
|
30
|
-
value: function set(key, feature) {
|
|
31
|
-
this.features[key] = _extends({}, feature);
|
|
32
|
-
}
|
|
33
|
-
}, {
|
|
34
|
-
key: "setAll",
|
|
35
|
-
value: function setAll(features) {
|
|
36
|
-
this.features = {};
|
|
37
|
-
for (var key in features) {
|
|
38
|
-
this.features[key] = _extends({}, features[key]);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: "getAll",
|
|
43
|
-
value: function getAll() {
|
|
44
|
-
return this.features;
|
|
45
|
-
}
|
|
46
|
-
}]);
|
|
47
|
-
|
|
48
|
-
return InMemoryFeatureStore;
|
|
49
|
-
}();
|
package/dist/PollingClient.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export default class PollingClient {
|
|
2
|
-
constructor(url: any, config: any, callback: any);
|
|
3
|
-
DEFAULT_TIMEOUT: number;
|
|
4
|
-
DEFAULT_INTERVAL: number;
|
|
5
|
-
clientVersion: string;
|
|
6
|
-
url: any;
|
|
7
|
-
apiKey: any;
|
|
8
|
-
featureStore: any;
|
|
9
|
-
pollingInterval: number;
|
|
10
|
-
timeout: number;
|
|
11
|
-
etag: string;
|
|
12
|
-
interval: number | undefined;
|
|
13
|
-
getFeatures(callback?: () => void): void;
|
|
14
|
-
close(): void;
|
|
15
|
-
}
|
package/dist/PollingClient.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
8
|
-
|
|
9
|
-
var _request = require('request');
|
|
10
|
-
|
|
11
|
-
var _request2 = _interopRequireDefault(_request);
|
|
12
|
-
|
|
13
|
-
var _debug = require('./debug');
|
|
14
|
-
|
|
15
|
-
var _debug2 = _interopRequireDefault(_debug);
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
20
|
-
|
|
21
|
-
var PollingClient = function () {
|
|
22
|
-
function PollingClient(url, config, callback) {
|
|
23
|
-
_classCallCheck(this, PollingClient);
|
|
24
|
-
|
|
25
|
-
this.DEFAULT_TIMEOUT = 5 * 1000;
|
|
26
|
-
this.DEFAULT_INTERVAL = 10 * 1000;
|
|
27
|
-
this.clientVersion = 'NodeJsClient/0.6.11';
|
|
28
|
-
|
|
29
|
-
this.url = url;
|
|
30
|
-
this.apiKey = config.apiKey;
|
|
31
|
-
this.featureStore = config.featureStore;
|
|
32
|
-
this.pollingInterval = this.DEFAULT_INTERVAL;
|
|
33
|
-
if (config.interval && config.interval > 5 || config.interval == 0) {
|
|
34
|
-
this.pollingInterval = config.interval * 1000;
|
|
35
|
-
}
|
|
36
|
-
this.timeout = this.DEFAULT_TIMEOUT;
|
|
37
|
-
this.etag = "";
|
|
38
|
-
|
|
39
|
-
this.getFeatures(callback);
|
|
40
|
-
if (this.pollingInterval > 0) {
|
|
41
|
-
this.interval = setInterval(this.getFeatures.bind(this), this.pollingInterval);
|
|
42
|
-
} else {
|
|
43
|
-
(0, _debug2.default)("Polling interval set to 0. Featureflow will NOT poll for feature changes.");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
_createClass(PollingClient, [{
|
|
48
|
-
key: 'getFeatures',
|
|
49
|
-
value: function getFeatures() {
|
|
50
|
-
var _this = this;
|
|
51
|
-
|
|
52
|
-
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
|
|
53
|
-
|
|
54
|
-
(0, _request2.default)({
|
|
55
|
-
method: 'get',
|
|
56
|
-
uri: this.url,
|
|
57
|
-
timeout: this.timeout,
|
|
58
|
-
headers: {
|
|
59
|
-
'Authorization': 'Bearer ' + this.apiKey,
|
|
60
|
-
'If-None-Match': this.etag,
|
|
61
|
-
'X-Featureflow-Client': this.clientVersion
|
|
62
|
-
}
|
|
63
|
-
}, function (error, response, body) {
|
|
64
|
-
if (response) {
|
|
65
|
-
if (response.statusCode === 200) {
|
|
66
|
-
_this.etag = response.headers['etag'];
|
|
67
|
-
(0, _debug2.default)("updating features");
|
|
68
|
-
_this.featureStore.setAll(JSON.parse(body));
|
|
69
|
-
} else if (response.statusCode >= 400 || error) {
|
|
70
|
-
(0, _debug2.default)("request for features failed with response status %d", response.statusCode);
|
|
71
|
-
}
|
|
72
|
-
callback();
|
|
73
|
-
} else {
|
|
74
|
-
if (error.code != null) {
|
|
75
|
-
(0, _debug2.default)(error.code);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}, {
|
|
81
|
-
key: 'close',
|
|
82
|
-
value: function close() {
|
|
83
|
-
clearInterval(this.interval);
|
|
84
|
-
}
|
|
85
|
-
}]);
|
|
86
|
-
|
|
87
|
-
return PollingClient;
|
|
88
|
-
}();
|
|
89
|
-
|
|
90
|
-
exports.default = PollingClient;
|
package/dist/User.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class UserBuilder {
|
|
2
|
-
constructor(id: any);
|
|
3
|
-
id: any;
|
|
4
|
-
attributes: {
|
|
5
|
-
'featureflow.user.id': any[];
|
|
6
|
-
'featureflow.date': string[];
|
|
7
|
-
};
|
|
8
|
-
withAttribute(key: any, value: any): UserBuilder;
|
|
9
|
-
withAttributes(key: any, values: any): UserBuilder;
|
|
10
|
-
build(): User;
|
|
11
|
-
}
|
|
12
|
-
declare class User {
|
|
13
|
-
constructor(id: any, attributes: any);
|
|
14
|
-
id: any;
|
|
15
|
-
attributes: any;
|
|
16
|
-
getId(): any;
|
|
17
|
-
getAttributesForKey(key: any): any;
|
|
18
|
-
addAttribute(key: any, value: any): void;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/dist/User.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
|
-
|
|
9
|
-
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
|
10
|
-
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
|
-
|
|
13
|
-
var User = function () {
|
|
14
|
-
function User(id, attributes) {
|
|
15
|
-
_classCallCheck(this, User);
|
|
16
|
-
|
|
17
|
-
this.id = id;
|
|
18
|
-
this.attributes = _extends({}, attributes);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_createClass(User, [{
|
|
22
|
-
key: 'getId',
|
|
23
|
-
value: function getId() {
|
|
24
|
-
return this.id;
|
|
25
|
-
}
|
|
26
|
-
}, {
|
|
27
|
-
key: 'getAttributesForKey',
|
|
28
|
-
value: function getAttributesForKey(key) {
|
|
29
|
-
return this.attributes[key];
|
|
30
|
-
}
|
|
31
|
-
}, {
|
|
32
|
-
key: 'addAttribute',
|
|
33
|
-
value: function addAttribute(key, value) {
|
|
34
|
-
this.attributes[key] = [].concat(value);
|
|
35
|
-
}
|
|
36
|
-
}]);
|
|
37
|
-
|
|
38
|
-
return User;
|
|
39
|
-
}();
|
|
40
|
-
|
|
41
|
-
var UserBuilder = exports.UserBuilder = function () {
|
|
42
|
-
function UserBuilder(id) {
|
|
43
|
-
_classCallCheck(this, UserBuilder);
|
|
44
|
-
|
|
45
|
-
if (!id || !id.length) {
|
|
46
|
-
throw new Error("User must have an id");
|
|
47
|
-
}
|
|
48
|
-
this.id = id;
|
|
49
|
-
this.attributes = {
|
|
50
|
-
'featureflow.user.id': [id],
|
|
51
|
-
'featureflow.date': [new Date().toISOString()]
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
_createClass(UserBuilder, [{
|
|
56
|
-
key: 'withAttribute',
|
|
57
|
-
value: function withAttribute(key, value) {
|
|
58
|
-
this.attributes[key] = [].concat(value);
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: 'withAttributes',
|
|
63
|
-
value: function withAttributes(key, values) {
|
|
64
|
-
this.withAttribute(key, values);
|
|
65
|
-
return this;
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
key: 'build',
|
|
69
|
-
value: function build() {
|
|
70
|
-
return new User(this.id, this.attributes);
|
|
71
|
-
}
|
|
72
|
-
}]);
|
|
73
|
-
|
|
74
|
-
return UserBuilder;
|
|
75
|
-
}();
|
package/dist/debug.d.ts
DELETED
package/dist/debug.js
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
declare namespace _default {
|
|
2
|
-
export { Client };
|
|
3
|
-
export { UserBuilder };
|
|
4
|
-
export { Feature };
|
|
5
|
-
export { ExpressClient };
|
|
6
|
-
}
|
|
7
|
-
export default _default;
|
|
8
|
-
import Client from "./Client";
|
|
9
|
-
import { UserBuilder } from "./User";
|
|
10
|
-
import Feature from "./Feature";
|
|
11
|
-
import ExpressClient from "./ExpressMiddleware";
|
package/dist/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _Client = require('./Client');
|
|
8
|
-
|
|
9
|
-
var _Client2 = _interopRequireDefault(_Client);
|
|
10
|
-
|
|
11
|
-
var _User = require('./User');
|
|
12
|
-
|
|
13
|
-
var _Feature = require('./Feature');
|
|
14
|
-
|
|
15
|
-
var _Feature2 = _interopRequireDefault(_Feature);
|
|
16
|
-
|
|
17
|
-
var _ExpressMiddleware = require('./ExpressMiddleware');
|
|
18
|
-
|
|
19
|
-
var _ExpressMiddleware2 = _interopRequireDefault(_ExpressMiddleware);
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
exports.default = {
|
|
24
|
-
Client: _Client2.default,
|
|
25
|
-
UserBuilder: _User.UserBuilder,
|
|
26
|
-
Feature: _Feature2.default,
|
|
27
|
-
ExpressClient: _ExpressMiddleware2.default
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
Client: _Client2.default,
|
|
33
|
-
UserBuilder: _User.UserBuilder,
|
|
34
|
-
Feature: _Feature2.default,
|
|
35
|
-
ExpressClient: _ExpressMiddleware2.default
|
|
36
|
-
};
|