@kenji71089/evaluation 0.0.1 → 0.0.8
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/CHANGELOG.md +45 -0
- package/README.md +36 -6
- package/lib/bucketeer.d.ts +6 -0
- package/lib/bucketeer.js +65 -0
- package/lib/bucketeer.mjs +38 -0
- package/lib/clauseEvaluator.js +49 -7
- package/lib/clauseEvaluator.mjs +41 -7
- package/lib/evaluation.d.ts +10 -1
- package/lib/evaluation.js +184 -27
- package/lib/evaluation.mjs +141 -10
- package/lib/index.d.ts +12 -10
- package/lib/index.js +61 -40
- package/lib/index.mjs +16 -10
- package/lib/modelFactory.d.ts +1 -0
- package/lib/modelFactory.js +2 -0
- package/lib/modelFactory.mjs +2 -0
- package/lib/proto/event/client/event_pb.d.ts +19 -9
- package/lib/proto/event/client/event_pb.js +22 -12
- package/lib/proto/event/client/event_pb.mjs +100 -90
- package/lib/proto/feature/clause_pb.d.ts +2 -1
- package/lib/proto/feature/clause_pb.js +3 -2
- package/lib/proto/feature/clause_pb.mjs +7 -6
- package/lib/proto/feature/evaluation_pb.d.ts +3 -3
- package/lib/proto/feature/evaluation_pb.js +1 -1
- package/lib/proto/feature/evaluation_pb.mjs +15 -15
- package/lib/proto/feature/feature_last_used_info_pb.d.ts +10 -1
- package/lib/proto/feature/feature_last_used_info_pb.js +12 -1
- package/lib/proto/feature/feature_last_used_info_pb.mjs +18 -7
- package/lib/proto/feature/feature_pb.d.ts +72 -7
- package/lib/proto/feature/feature_pb.js +446 -4
- package/lib/proto/feature/feature_pb.mjs +535 -29
- package/lib/proto/feature/prerequisite_pb.d.ts +1 -1
- package/lib/proto/feature/prerequisite_pb.js +1 -1
- package/lib/proto/feature/prerequisite_pb.mjs +3 -3
- package/lib/proto/feature/reason_pb.d.ts +8 -1
- package/lib/proto/feature/reason_pb.js +9 -2
- package/lib/proto/feature/reason_pb.mjs +11 -4
- package/lib/proto/feature/rule_pb.d.ts +3 -3
- package/lib/proto/feature/rule_pb.js +1 -1
- package/lib/proto/feature/rule_pb.mjs +4 -4
- package/lib/proto/feature/segment_pb.d.ts +3 -3
- package/lib/proto/feature/segment_pb.js +1 -1
- package/lib/proto/feature/segment_pb.mjs +22 -22
- package/lib/proto/feature/strategy_pb.d.ts +31 -1
- package/lib/proto/feature/strategy_pb.js +206 -2
- package/lib/proto/feature/strategy_pb.mjs +242 -9
- package/lib/proto/feature/target_pb.d.ts +1 -1
- package/lib/proto/feature/target_pb.js +1 -1
- package/lib/proto/feature/target_pb.mjs +3 -3
- package/lib/proto/feature/variation_pb.d.ts +1 -1
- package/lib/proto/feature/variation_pb.js +1 -1
- package/lib/proto/feature/variation_pb.mjs +5 -5
- package/lib/proto/user/user_pb.d.ts +53 -1
- package/lib/proto/user/user_pb.js +374 -1
- package/lib/proto/user/user_pb.mjs +427 -7
- package/lib/strategyEvaluator.d.ts +0 -2
- package/lib/strategyEvaluator.js +23 -57
- package/lib/strategyEvaluator.mjs +23 -46
- package/lib/userEvaluation.js +13 -3
- package/lib/userEvaluation.mjs +13 -3
- package/package.json +15 -8
- package/lib/google/api/annotations_pb.d.ts +0 -8
- package/lib/google/api/annotations_pb.js +0 -40
- package/lib/google/api/annotations_pb.mjs +0 -54
- package/lib/google/api/annotations_pb_service.d.ts +0 -3
- package/lib/google/api/annotations_pb_service.js +0 -3
- package/lib/google/api/annotations_pb_service.mjs +0 -3
- package/lib/google/api/http_pb.d.ts +0 -132
- package/lib/google/api/http_pb.js +0 -860
- package/lib/google/api/http_pb.mjs +0 -982
- package/lib/google/api/http_pb_service.d.ts +0 -3
- package/lib/google/api/http_pb_service.js +0 -3
- package/lib/google/api/http_pb_service.mjs +0 -3
- package/lib/google/rpc/code_pb.d.ts +0 -26
- package/lib/google/rpc/code_pb.js +0 -44
- package/lib/google/rpc/code_pb.mjs +0 -48
- package/lib/google/rpc/code_pb_service.d.ts +0 -3
- package/lib/google/rpc/code_pb_service.js +0 -3
- package/lib/google/rpc/code_pb_service.mjs +0 -3
- package/lib/google/rpc/error_details_pb.d.ts +0 -322
- package/lib/google/rpc/error_details_pb.js +0 -2220
- package/lib/google/rpc/error_details_pb.mjs +0 -2499
- package/lib/google/rpc/error_details_pb_service.d.ts +0 -3
- package/lib/google/rpc/error_details_pb_service.js +0 -3
- package/lib/google/rpc/error_details_pb_service.mjs +0 -3
- package/lib/google/rpc/status_pb.d.ts +0 -36
- package/lib/google/rpc/status_pb.js +0 -235
- package/lib/google/rpc/status_pb.mjs +0 -268
- package/lib/google/rpc/status_pb_service.d.ts +0 -3
- package/lib/google/rpc/status_pb_service.js +0 -3
- package/lib/google/rpc/status_pb_service.mjs +0 -3
- package/lib/proto/event/client/event_pb_service.d.ts +0 -3
- package/lib/proto/event/client/event_pb_service.js +0 -3
- package/lib/proto/event/client/event_pb_service.mjs +0 -3
- package/lib/proto/event/domain/event_pb.d.ts +0 -4518
- package/lib/proto/event/domain/event_pb.js +0 -10834
- package/lib/proto/event/domain/event_pb.mjs +0 -33315
- package/lib/proto/event/domain/event_pb_service.d.ts +0 -3
- package/lib/proto/event/domain/event_pb_service.js +0 -3
- package/lib/proto/event/domain/event_pb_service.mjs +0 -3
- package/lib/proto/event/domain/localized_message_pb.d.ts +0 -29
- package/lib/proto/event/domain/localized_message_pb.js +0 -183
- package/lib/proto/event/domain/localized_message_pb.mjs +0 -206
- package/lib/proto/event/domain/localized_message_pb_service.d.ts +0 -3
- package/lib/proto/event/domain/localized_message_pb_service.js +0 -3
- package/lib/proto/event/domain/localized_message_pb_service.mjs +0 -3
- package/lib/proto/event/service/feature_pb.d.ts +0 -44
- package/lib/proto/event/service/feature_pb.js +0 -277
- package/lib/proto/event/service/feature_pb.mjs +0 -319
- package/lib/proto/event/service/feature_pb_service.d.ts +0 -3
- package/lib/proto/event/service/feature_pb_service.js +0 -3
- package/lib/proto/event/service/feature_pb_service.mjs +0 -3
- package/lib/proto/event/service/segment_pb.d.ts +0 -51
- package/lib/proto/event/service/segment_pb.js +0 -324
- package/lib/proto/event/service/segment_pb.mjs +0 -375
- package/lib/proto/event/service/segment_pb_service.d.ts +0 -3
- package/lib/proto/event/service/segment_pb_service.js +0 -3
- package/lib/proto/event/service/segment_pb_service.mjs +0 -3
- package/lib/proto/event/service/user_pb.d.ts +0 -49
- package/lib/proto/event/service/user_pb.js +0 -315
- package/lib/proto/event/service/user_pb.mjs +0 -362
- package/lib/proto/event/service/user_pb_service.d.ts +0 -3
- package/lib/proto/event/service/user_pb_service.js +0 -3
- package/lib/proto/event/service/user_pb_service.mjs +0 -3
- package/lib/proto/feature/clause_pb_service.d.ts +0 -3
- package/lib/proto/feature/clause_pb_service.js +0 -3
- package/lib/proto/feature/clause_pb_service.mjs +0 -3
- package/lib/proto/feature/command_pb.d.ts +0 -1213
- package/lib/proto/feature/command_pb.js +0 -8260
- package/lib/proto/feature/command_pb.mjs +0 -9275
- package/lib/proto/feature/command_pb_service.d.ts +0 -3
- package/lib/proto/feature/command_pb_service.js +0 -3
- package/lib/proto/feature/command_pb_service.mjs +0 -3
- package/lib/proto/feature/evaluation_pb_service.d.ts +0 -3
- package/lib/proto/feature/evaluation_pb_service.js +0 -3
- package/lib/proto/feature/evaluation_pb_service.mjs +0 -3
- package/lib/proto/feature/feature_last_used_info_pb_service.d.ts +0 -3
- package/lib/proto/feature/feature_last_used_info_pb_service.js +0 -3
- package/lib/proto/feature/feature_last_used_info_pb_service.mjs +0 -3
- package/lib/proto/feature/feature_pb_service.d.ts +0 -3
- package/lib/proto/feature/feature_pb_service.js +0 -3
- package/lib/proto/feature/feature_pb_service.mjs +0 -3
- package/lib/proto/feature/flag_trigger_pb.d.ts +0 -84
- package/lib/proto/feature/flag_trigger_pb.js +0 -452
- package/lib/proto/feature/flag_trigger_pb.mjs +0 -525
- package/lib/proto/feature/flag_trigger_pb_service.d.ts +0 -3
- package/lib/proto/feature/flag_trigger_pb_service.js +0 -3
- package/lib/proto/feature/flag_trigger_pb_service.mjs +0 -3
- package/lib/proto/feature/prerequisite_pb_service.d.ts +0 -3
- package/lib/proto/feature/prerequisite_pb_service.js +0 -3
- package/lib/proto/feature/prerequisite_pb_service.mjs +0 -3
- package/lib/proto/feature/reason_pb_service.d.ts +0 -3
- package/lib/proto/feature/reason_pb_service.js +0 -3
- package/lib/proto/feature/reason_pb_service.mjs +0 -3
- package/lib/proto/feature/rule_pb_service.d.ts +0 -3
- package/lib/proto/feature/rule_pb_service.js +0 -3
- package/lib/proto/feature/rule_pb_service.mjs +0 -3
- package/lib/proto/feature/segment_pb_service.d.ts +0 -3
- package/lib/proto/feature/segment_pb_service.js +0 -3
- package/lib/proto/feature/segment_pb_service.mjs +0 -3
- package/lib/proto/feature/service_pb.d.ts +0 -2158
- package/lib/proto/feature/service_pb.js +0 -5363
- package/lib/proto/feature/service_pb.mjs +0 -16348
- package/lib/proto/feature/service_pb_service.d.ts +0 -747
- package/lib/proto/feature/service_pb_service.js +0 -1424
- package/lib/proto/feature/service_pb_service.mjs +0 -1501
- package/lib/proto/feature/strategy_pb_service.d.ts +0 -3
- package/lib/proto/feature/strategy_pb_service.js +0 -3
- package/lib/proto/feature/strategy_pb_service.mjs +0 -3
- package/lib/proto/feature/target_pb_service.d.ts +0 -3
- package/lib/proto/feature/target_pb_service.js +0 -3
- package/lib/proto/feature/target_pb_service.mjs +0 -3
- package/lib/proto/feature/variation_pb_service.d.ts +0 -3
- package/lib/proto/feature/variation_pb_service.js +0 -3
- package/lib/proto/feature/variation_pb_service.mjs +0 -3
- package/lib/proto/gateway/service_pb.d.ts +0 -772
- package/lib/proto/gateway/service_pb.js +0 -5249
- package/lib/proto/gateway/service_pb.mjs +0 -6001
- package/lib/proto/gateway/service_pb_service.d.ts +0 -253
- package/lib/proto/gateway/service_pb_service.js +0 -436
- package/lib/proto/gateway/service_pb_service.mjs +0 -461
- package/lib/proto/user/user_pb_service.d.ts +0 -3
- package/lib/proto/user/user_pb_service.js +0 -3
- package/lib/proto/user/user_pb_service.mjs +0 -3
- package/lib/protoc-gen-openapiv2/options/annotations_pb.d.ts +0 -16
- package/lib/protoc-gen-openapiv2/options/annotations_pb.js +0 -100
- package/lib/protoc-gen-openapiv2/options/annotations_pb.mjs +0 -158
- package/lib/protoc-gen-openapiv2/options/annotations_pb_service.d.ts +0 -3
- package/lib/protoc-gen-openapiv2/options/annotations_pb_service.js +0 -3
- package/lib/protoc-gen-openapiv2/options/annotations_pb_service.mjs +0 -3
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb.d.ts +0 -834
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb.js +0 -5456
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb.mjs +0 -6256
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.d.ts +0 -3
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.js +0 -3
- package/lib/protoc-gen-openapiv2/options/openapiv2_pb_service.mjs +0 -3
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @public
|
|
9
9
|
*/
|
|
10
10
|
// GENERATED CODE -- DO NOT EDIT!
|
|
11
|
-
|
|
11
|
+
/* eslint-disable */
|
|
12
12
|
// @ts-nocheck
|
|
13
13
|
|
|
14
14
|
var jspb = require('google-protobuf');
|
|
@@ -23,6 +23,8 @@ var global =
|
|
|
23
23
|
|
|
24
24
|
goog.exportSymbol('proto.bucketeer.user.User', null, global);
|
|
25
25
|
goog.exportSymbol('proto.bucketeer.user.User.Data', null, global);
|
|
26
|
+
goog.exportSymbol('proto.bucketeer.user.UserAttribute', null, global);
|
|
27
|
+
goog.exportSymbol('proto.bucketeer.user.UserAttributes', null, global);
|
|
26
28
|
/**
|
|
27
29
|
* Generated by JsPbCodeGenerator.
|
|
28
30
|
* @param {Array=} opt_data Optional initial data array, typically from a
|
|
@@ -65,6 +67,48 @@ if (goog.DEBUG && !COMPILED) {
|
|
|
65
67
|
*/
|
|
66
68
|
proto.bucketeer.user.User.Data.displayName = 'proto.bucketeer.user.User.Data';
|
|
67
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Generated by JsPbCodeGenerator.
|
|
72
|
+
* @param {Array=} opt_data Optional initial data array, typically from a
|
|
73
|
+
* server response, or constructed directly in Javascript. The array is used
|
|
74
|
+
* in place and becomes part of the constructed object. It is not cloned.
|
|
75
|
+
* If no data is provided, the constructed object will be empty, but still
|
|
76
|
+
* valid.
|
|
77
|
+
* @extends {jspb.Message}
|
|
78
|
+
* @constructor
|
|
79
|
+
*/
|
|
80
|
+
proto.bucketeer.user.UserAttributes = function(opt_data) {
|
|
81
|
+
jspb.Message.initialize(this, opt_data, 0, -1, proto.bucketeer.user.UserAttributes.repeatedFields_, null);
|
|
82
|
+
};
|
|
83
|
+
goog.inherits(proto.bucketeer.user.UserAttributes, jspb.Message);
|
|
84
|
+
if (goog.DEBUG && !COMPILED) {
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
* @override
|
|
88
|
+
*/
|
|
89
|
+
proto.bucketeer.user.UserAttributes.displayName = 'proto.bucketeer.user.UserAttributes';
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generated by JsPbCodeGenerator.
|
|
93
|
+
* @param {Array=} opt_data Optional initial data array, typically from a
|
|
94
|
+
* server response, or constructed directly in Javascript. The array is used
|
|
95
|
+
* in place and becomes part of the constructed object. It is not cloned.
|
|
96
|
+
* If no data is provided, the constructed object will be empty, but still
|
|
97
|
+
* valid.
|
|
98
|
+
* @extends {jspb.Message}
|
|
99
|
+
* @constructor
|
|
100
|
+
*/
|
|
101
|
+
proto.bucketeer.user.UserAttribute = function(opt_data) {
|
|
102
|
+
jspb.Message.initialize(this, opt_data, 0, -1, proto.bucketeer.user.UserAttribute.repeatedFields_, null);
|
|
103
|
+
};
|
|
104
|
+
goog.inherits(proto.bucketeer.user.UserAttribute, jspb.Message);
|
|
105
|
+
if (goog.DEBUG && !COMPILED) {
|
|
106
|
+
/**
|
|
107
|
+
* @public
|
|
108
|
+
* @override
|
|
109
|
+
*/
|
|
110
|
+
proto.bucketeer.user.UserAttribute.displayName = 'proto.bucketeer.user.UserAttribute';
|
|
111
|
+
}
|
|
68
112
|
|
|
69
113
|
|
|
70
114
|
|
|
@@ -97,11 +141,11 @@ proto.bucketeer.user.User.prototype.toObject = function(opt_includeInstance) {
|
|
|
97
141
|
*/
|
|
98
142
|
proto.bucketeer.user.User.toObject = function(includeInstance, msg) {
|
|
99
143
|
var f, obj = {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
144
|
+
id: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
|
145
|
+
dataMap: (f = msg.getDataMap()) ? f.toObject(includeInstance, undefined) : [],
|
|
146
|
+
taggedDataMap: (f = msg.getTaggedDataMap()) ? f.toObject(includeInstance, proto.bucketeer.user.User.Data.toObject) : [],
|
|
147
|
+
lastSeen: jspb.Message.getFieldWithDefault(msg, 4, 0),
|
|
148
|
+
createdAt: jspb.Message.getFieldWithDefault(msg, 5, 0)
|
|
105
149
|
};
|
|
106
150
|
|
|
107
151
|
if (includeInstance) {
|
|
@@ -255,7 +299,7 @@ proto.bucketeer.user.User.Data.prototype.toObject = function(opt_includeInstance
|
|
|
255
299
|
*/
|
|
256
300
|
proto.bucketeer.user.User.Data.toObject = function(includeInstance, msg) {
|
|
257
301
|
var f, obj = {
|
|
258
|
-
|
|
302
|
+
valueMap: (f = msg.getValueMap()) ? f.toObject(includeInstance, undefined) : []
|
|
259
303
|
};
|
|
260
304
|
|
|
261
305
|
if (includeInstance) {
|
|
@@ -457,4 +501,380 @@ proto.bucketeer.user.User.prototype.setCreatedAt = function(value) {
|
|
|
457
501
|
};
|
|
458
502
|
|
|
459
503
|
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* List of repeated fields within this message type.
|
|
507
|
+
* @private {!Array<number>}
|
|
508
|
+
* @const
|
|
509
|
+
*/
|
|
510
|
+
proto.bucketeer.user.UserAttributes.repeatedFields_ = [2];
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
if (jspb.Message.GENERATE_TO_OBJECT) {
|
|
515
|
+
/**
|
|
516
|
+
* Creates an object representation of this proto.
|
|
517
|
+
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
|
518
|
+
* Optional fields that are not set will be set to undefined.
|
|
519
|
+
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
|
520
|
+
* For the list of reserved names please see:
|
|
521
|
+
* net/proto2/compiler/js/internal/generator.cc#kKeyword.
|
|
522
|
+
* @param {boolean=} opt_includeInstance Deprecated. whether to include the
|
|
523
|
+
* JSPB instance for transitional soy proto support:
|
|
524
|
+
* http://goto/soy-param-migration
|
|
525
|
+
* @return {!Object}
|
|
526
|
+
*/
|
|
527
|
+
proto.bucketeer.user.UserAttributes.prototype.toObject = function(opt_includeInstance) {
|
|
528
|
+
return proto.bucketeer.user.UserAttributes.toObject(opt_includeInstance, this);
|
|
529
|
+
};
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* Static version of the {@see toObject} method.
|
|
534
|
+
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
|
|
535
|
+
* the JSPB instance for transitional soy proto support:
|
|
536
|
+
* http://goto/soy-param-migration
|
|
537
|
+
* @param {!proto.bucketeer.user.UserAttributes} msg The msg instance to transform.
|
|
538
|
+
* @return {!Object}
|
|
539
|
+
* @suppress {unusedLocalVariables} f is only used for nested messages
|
|
540
|
+
*/
|
|
541
|
+
proto.bucketeer.user.UserAttributes.toObject = function(includeInstance, msg) {
|
|
542
|
+
var f, obj = {
|
|
543
|
+
environmentId: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
|
544
|
+
userAttributesList: jspb.Message.toObjectList(msg.getUserAttributesList(),
|
|
545
|
+
proto.bucketeer.user.UserAttribute.toObject, includeInstance)
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
if (includeInstance) {
|
|
549
|
+
obj.$jspbMessageInstance = msg;
|
|
550
|
+
}
|
|
551
|
+
return obj;
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Deserializes binary data (in protobuf wire format).
|
|
558
|
+
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
|
559
|
+
* @return {!proto.bucketeer.user.UserAttributes}
|
|
560
|
+
*/
|
|
561
|
+
proto.bucketeer.user.UserAttributes.deserializeBinary = function(bytes) {
|
|
562
|
+
var reader = new jspb.BinaryReader(bytes);
|
|
563
|
+
var msg = new proto.bucketeer.user.UserAttributes;
|
|
564
|
+
return proto.bucketeer.user.UserAttributes.deserializeBinaryFromReader(msg, reader);
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Deserializes binary data (in protobuf wire format) from the
|
|
570
|
+
* given reader into the given message object.
|
|
571
|
+
* @param {!proto.bucketeer.user.UserAttributes} msg The message object to deserialize into.
|
|
572
|
+
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
|
573
|
+
* @return {!proto.bucketeer.user.UserAttributes}
|
|
574
|
+
*/
|
|
575
|
+
proto.bucketeer.user.UserAttributes.deserializeBinaryFromReader = function(msg, reader) {
|
|
576
|
+
while (reader.nextField()) {
|
|
577
|
+
if (reader.isEndGroup()) {
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
var field = reader.getFieldNumber();
|
|
581
|
+
switch (field) {
|
|
582
|
+
case 1:
|
|
583
|
+
var value = /** @type {string} */ (reader.readString());
|
|
584
|
+
msg.setEnvironmentId(value);
|
|
585
|
+
break;
|
|
586
|
+
case 2:
|
|
587
|
+
var value = new proto.bucketeer.user.UserAttribute;
|
|
588
|
+
reader.readMessage(value,proto.bucketeer.user.UserAttribute.deserializeBinaryFromReader);
|
|
589
|
+
msg.addUserAttributes(value);
|
|
590
|
+
break;
|
|
591
|
+
default:
|
|
592
|
+
reader.skipField();
|
|
593
|
+
break;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return msg;
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
/**
|
|
601
|
+
* Serializes the message to binary data (in protobuf wire format).
|
|
602
|
+
* @return {!Uint8Array}
|
|
603
|
+
*/
|
|
604
|
+
proto.bucketeer.user.UserAttributes.prototype.serializeBinary = function() {
|
|
605
|
+
var writer = new jspb.BinaryWriter();
|
|
606
|
+
proto.bucketeer.user.UserAttributes.serializeBinaryToWriter(this, writer);
|
|
607
|
+
return writer.getResultBuffer();
|
|
608
|
+
};
|
|
609
|
+
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
* Serializes the given message to binary data (in protobuf wire
|
|
613
|
+
* format), writing to the given BinaryWriter.
|
|
614
|
+
* @param {!proto.bucketeer.user.UserAttributes} message
|
|
615
|
+
* @param {!jspb.BinaryWriter} writer
|
|
616
|
+
* @suppress {unusedLocalVariables} f is only used for nested messages
|
|
617
|
+
*/
|
|
618
|
+
proto.bucketeer.user.UserAttributes.serializeBinaryToWriter = function(message, writer) {
|
|
619
|
+
var f = undefined;
|
|
620
|
+
f = message.getEnvironmentId();
|
|
621
|
+
if (f.length > 0) {
|
|
622
|
+
writer.writeString(
|
|
623
|
+
1,
|
|
624
|
+
f
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
f = message.getUserAttributesList();
|
|
628
|
+
if (f.length > 0) {
|
|
629
|
+
writer.writeRepeatedMessage(
|
|
630
|
+
2,
|
|
631
|
+
f,
|
|
632
|
+
proto.bucketeer.user.UserAttribute.serializeBinaryToWriter
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* optional string environment_id = 1;
|
|
640
|
+
* @return {string}
|
|
641
|
+
*/
|
|
642
|
+
proto.bucketeer.user.UserAttributes.prototype.getEnvironmentId = function() {
|
|
643
|
+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
/**
|
|
648
|
+
* @param {string} value
|
|
649
|
+
* @return {!proto.bucketeer.user.UserAttributes} returns this
|
|
650
|
+
*/
|
|
651
|
+
proto.bucketeer.user.UserAttributes.prototype.setEnvironmentId = function(value) {
|
|
652
|
+
return jspb.Message.setProto3StringField(this, 1, value);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
/**
|
|
657
|
+
* repeated UserAttribute user_attributes = 2;
|
|
658
|
+
* @return {!Array<!proto.bucketeer.user.UserAttribute>}
|
|
659
|
+
*/
|
|
660
|
+
proto.bucketeer.user.UserAttributes.prototype.getUserAttributesList = function() {
|
|
661
|
+
return /** @type{!Array<!proto.bucketeer.user.UserAttribute>} */ (
|
|
662
|
+
jspb.Message.getRepeatedWrapperField(this, proto.bucketeer.user.UserAttribute, 2));
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
* @param {!Array<!proto.bucketeer.user.UserAttribute>} value
|
|
668
|
+
* @return {!proto.bucketeer.user.UserAttributes} returns this
|
|
669
|
+
*/
|
|
670
|
+
proto.bucketeer.user.UserAttributes.prototype.setUserAttributesList = function(value) {
|
|
671
|
+
return jspb.Message.setRepeatedWrapperField(this, 2, value);
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
/**
|
|
676
|
+
* @param {!proto.bucketeer.user.UserAttribute=} opt_value
|
|
677
|
+
* @param {number=} opt_index
|
|
678
|
+
* @return {!proto.bucketeer.user.UserAttribute}
|
|
679
|
+
*/
|
|
680
|
+
proto.bucketeer.user.UserAttributes.prototype.addUserAttributes = function(opt_value, opt_index) {
|
|
681
|
+
return jspb.Message.addToRepeatedWrapperField(this, 2, opt_value, proto.bucketeer.user.UserAttribute, opt_index);
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Clears the list making it empty but non-null.
|
|
687
|
+
* @return {!proto.bucketeer.user.UserAttributes} returns this
|
|
688
|
+
*/
|
|
689
|
+
proto.bucketeer.user.UserAttributes.prototype.clearUserAttributesList = function() {
|
|
690
|
+
return this.setUserAttributesList([]);
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* List of repeated fields within this message type.
|
|
697
|
+
* @private {!Array<number>}
|
|
698
|
+
* @const
|
|
699
|
+
*/
|
|
700
|
+
proto.bucketeer.user.UserAttribute.repeatedFields_ = [2];
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
if (jspb.Message.GENERATE_TO_OBJECT) {
|
|
705
|
+
/**
|
|
706
|
+
* Creates an object representation of this proto.
|
|
707
|
+
* Field names that are reserved in JavaScript and will be renamed to pb_name.
|
|
708
|
+
* Optional fields that are not set will be set to undefined.
|
|
709
|
+
* To access a reserved field use, foo.pb_<name>, eg, foo.pb_default.
|
|
710
|
+
* For the list of reserved names please see:
|
|
711
|
+
* net/proto2/compiler/js/internal/generator.cc#kKeyword.
|
|
712
|
+
* @param {boolean=} opt_includeInstance Deprecated. whether to include the
|
|
713
|
+
* JSPB instance for transitional soy proto support:
|
|
714
|
+
* http://goto/soy-param-migration
|
|
715
|
+
* @return {!Object}
|
|
716
|
+
*/
|
|
717
|
+
proto.bucketeer.user.UserAttribute.prototype.toObject = function(opt_includeInstance) {
|
|
718
|
+
return proto.bucketeer.user.UserAttribute.toObject(opt_includeInstance, this);
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Static version of the {@see toObject} method.
|
|
724
|
+
* @param {boolean|undefined} includeInstance Deprecated. Whether to include
|
|
725
|
+
* the JSPB instance for transitional soy proto support:
|
|
726
|
+
* http://goto/soy-param-migration
|
|
727
|
+
* @param {!proto.bucketeer.user.UserAttribute} msg The msg instance to transform.
|
|
728
|
+
* @return {!Object}
|
|
729
|
+
* @suppress {unusedLocalVariables} f is only used for nested messages
|
|
730
|
+
*/
|
|
731
|
+
proto.bucketeer.user.UserAttribute.toObject = function(includeInstance, msg) {
|
|
732
|
+
var f, obj = {
|
|
733
|
+
key: jspb.Message.getFieldWithDefault(msg, 1, ""),
|
|
734
|
+
valuesList: (f = jspb.Message.getRepeatedField(msg, 2)) == null ? undefined : f
|
|
735
|
+
};
|
|
736
|
+
|
|
737
|
+
if (includeInstance) {
|
|
738
|
+
obj.$jspbMessageInstance = msg;
|
|
739
|
+
}
|
|
740
|
+
return obj;
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Deserializes binary data (in protobuf wire format).
|
|
747
|
+
* @param {jspb.ByteSource} bytes The bytes to deserialize.
|
|
748
|
+
* @return {!proto.bucketeer.user.UserAttribute}
|
|
749
|
+
*/
|
|
750
|
+
proto.bucketeer.user.UserAttribute.deserializeBinary = function(bytes) {
|
|
751
|
+
var reader = new jspb.BinaryReader(bytes);
|
|
752
|
+
var msg = new proto.bucketeer.user.UserAttribute;
|
|
753
|
+
return proto.bucketeer.user.UserAttribute.deserializeBinaryFromReader(msg, reader);
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Deserializes binary data (in protobuf wire format) from the
|
|
759
|
+
* given reader into the given message object.
|
|
760
|
+
* @param {!proto.bucketeer.user.UserAttribute} msg The message object to deserialize into.
|
|
761
|
+
* @param {!jspb.BinaryReader} reader The BinaryReader to use.
|
|
762
|
+
* @return {!proto.bucketeer.user.UserAttribute}
|
|
763
|
+
*/
|
|
764
|
+
proto.bucketeer.user.UserAttribute.deserializeBinaryFromReader = function(msg, reader) {
|
|
765
|
+
while (reader.nextField()) {
|
|
766
|
+
if (reader.isEndGroup()) {
|
|
767
|
+
break;
|
|
768
|
+
}
|
|
769
|
+
var field = reader.getFieldNumber();
|
|
770
|
+
switch (field) {
|
|
771
|
+
case 1:
|
|
772
|
+
var value = /** @type {string} */ (reader.readString());
|
|
773
|
+
msg.setKey(value);
|
|
774
|
+
break;
|
|
775
|
+
case 2:
|
|
776
|
+
var value = /** @type {string} */ (reader.readString());
|
|
777
|
+
msg.addValues(value);
|
|
778
|
+
break;
|
|
779
|
+
default:
|
|
780
|
+
reader.skipField();
|
|
781
|
+
break;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return msg;
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
/**
|
|
789
|
+
* Serializes the message to binary data (in protobuf wire format).
|
|
790
|
+
* @return {!Uint8Array}
|
|
791
|
+
*/
|
|
792
|
+
proto.bucketeer.user.UserAttribute.prototype.serializeBinary = function() {
|
|
793
|
+
var writer = new jspb.BinaryWriter();
|
|
794
|
+
proto.bucketeer.user.UserAttribute.serializeBinaryToWriter(this, writer);
|
|
795
|
+
return writer.getResultBuffer();
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Serializes the given message to binary data (in protobuf wire
|
|
801
|
+
* format), writing to the given BinaryWriter.
|
|
802
|
+
* @param {!proto.bucketeer.user.UserAttribute} message
|
|
803
|
+
* @param {!jspb.BinaryWriter} writer
|
|
804
|
+
* @suppress {unusedLocalVariables} f is only used for nested messages
|
|
805
|
+
*/
|
|
806
|
+
proto.bucketeer.user.UserAttribute.serializeBinaryToWriter = function(message, writer) {
|
|
807
|
+
var f = undefined;
|
|
808
|
+
f = message.getKey();
|
|
809
|
+
if (f.length > 0) {
|
|
810
|
+
writer.writeString(
|
|
811
|
+
1,
|
|
812
|
+
f
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
f = message.getValuesList();
|
|
816
|
+
if (f.length > 0) {
|
|
817
|
+
writer.writeRepeatedString(
|
|
818
|
+
2,
|
|
819
|
+
f
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* optional string key = 1;
|
|
827
|
+
* @return {string}
|
|
828
|
+
*/
|
|
829
|
+
proto.bucketeer.user.UserAttribute.prototype.getKey = function() {
|
|
830
|
+
return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, ""));
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* @param {string} value
|
|
836
|
+
* @return {!proto.bucketeer.user.UserAttribute} returns this
|
|
837
|
+
*/
|
|
838
|
+
proto.bucketeer.user.UserAttribute.prototype.setKey = function(value) {
|
|
839
|
+
return jspb.Message.setProto3StringField(this, 1, value);
|
|
840
|
+
};
|
|
841
|
+
|
|
842
|
+
|
|
843
|
+
/**
|
|
844
|
+
* repeated string values = 2;
|
|
845
|
+
* @return {!Array<string>}
|
|
846
|
+
*/
|
|
847
|
+
proto.bucketeer.user.UserAttribute.prototype.getValuesList = function() {
|
|
848
|
+
return /** @type {!Array<string>} */ (jspb.Message.getRepeatedField(this, 2));
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @param {!Array<string>} value
|
|
854
|
+
* @return {!proto.bucketeer.user.UserAttribute} returns this
|
|
855
|
+
*/
|
|
856
|
+
proto.bucketeer.user.UserAttribute.prototype.setValuesList = function(value) {
|
|
857
|
+
return jspb.Message.setField(this, 2, value || []);
|
|
858
|
+
};
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* @param {string} value
|
|
863
|
+
* @param {number=} opt_index
|
|
864
|
+
* @return {!proto.bucketeer.user.UserAttribute} returns this
|
|
865
|
+
*/
|
|
866
|
+
proto.bucketeer.user.UserAttribute.prototype.addValues = function(value, opt_index) {
|
|
867
|
+
return jspb.Message.addToRepeatedField(this, 2, value, opt_index);
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Clears the list making it empty but non-null.
|
|
873
|
+
* @return {!proto.bucketeer.user.UserAttribute} returns this
|
|
874
|
+
*/
|
|
875
|
+
proto.bucketeer.user.UserAttribute.prototype.clearValuesList = function() {
|
|
876
|
+
return this.setValuesList([]);
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
|
|
460
880
|
goog.object.extend(exports, proto.bucketeer.user);
|
|
@@ -3,8 +3,6 @@ import { Variation } from './proto/feature/variation_pb';
|
|
|
3
3
|
declare class StrategyEvaluator {
|
|
4
4
|
evaluate(strategy: Strategy, userID: string, variations: Variation[], featureID: string, samplingSeed: string): Variation;
|
|
5
5
|
private rollout;
|
|
6
|
-
private bucket;
|
|
7
|
-
private hash;
|
|
8
6
|
private findVariation;
|
|
9
7
|
}
|
|
10
8
|
export { StrategyEvaluator };
|
package/lib/strategyEvaluator.js
CHANGED
|
@@ -9,45 +9,12 @@ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o =
|
|
|
9
9
|
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
10
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
11
11
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
|
-
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
15
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
16
|
-
desc = {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function get() {
|
|
19
|
-
return m[k];
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
Object.defineProperty(o, k2, desc);
|
|
24
|
-
} : function (o, m, k, k2) {
|
|
25
|
-
if (k2 === undefined) k2 = k;
|
|
26
|
-
o[k2] = m[k];
|
|
27
|
-
});
|
|
28
|
-
var __setModuleDefault = void 0 && (void 0).__setModuleDefault || (Object.create ? function (o, v) {
|
|
29
|
-
Object.defineProperty(o, "default", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
value: v
|
|
32
|
-
});
|
|
33
|
-
} : function (o, v) {
|
|
34
|
-
o["default"] = v;
|
|
35
|
-
});
|
|
36
|
-
var __importStar = void 0 && (void 0).__importStar || function (mod) {
|
|
37
|
-
if (mod && mod.__esModule) return mod;
|
|
38
|
-
var result = {};
|
|
39
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
40
|
-
__setModuleDefault(result, mod);
|
|
41
|
-
return result;
|
|
42
|
-
};
|
|
43
12
|
Object.defineProperty(exports, "__esModule", {
|
|
44
13
|
value: true
|
|
45
14
|
});
|
|
46
15
|
exports.StrategyEvaluator = void 0;
|
|
47
|
-
var
|
|
16
|
+
var bucketeer_1 = require("./bucketeer");
|
|
48
17
|
var strategy_pb_1 = require("./proto/feature/strategy_pb");
|
|
49
|
-
//
|
|
50
|
-
var MAX = 0xffffffffffffffffn;
|
|
51
18
|
var StrategyEvaluator = /*#__PURE__*/function () {
|
|
52
19
|
function StrategyEvaluator() {
|
|
53
20
|
_classCallCheck(this, StrategyEvaluator);
|
|
@@ -73,15 +40,33 @@ var StrategyEvaluator = /*#__PURE__*/function () {
|
|
|
73
40
|
}, {
|
|
74
41
|
key: "rollout",
|
|
75
42
|
value: function rollout(strategy, userID, featureID, samplingSeed) {
|
|
76
|
-
var
|
|
77
|
-
var
|
|
43
|
+
var bucketeer = new bucketeer_1.Bucketeer();
|
|
44
|
+
var audience = strategy.getAudience();
|
|
45
|
+
if (audience !== undefined) {
|
|
46
|
+
if (audience.getPercentage() > 0 && audience.getPercentage() < 100) {
|
|
47
|
+
// Use different hash input for audience control to ensure independence from A/B split
|
|
48
|
+
var trafficInput = "traffic-".concat(featureID, "-").concat(userID, "-").concat(samplingSeed);
|
|
49
|
+
var trafficBucket = bucketeer.bucket(trafficInput);
|
|
50
|
+
var trafficThreshold = audience.getPercentage() / 100.0;
|
|
51
|
+
// If user is not in experiment traffic, return default variation
|
|
52
|
+
if (trafficBucket >= trafficThreshold) {
|
|
53
|
+
if (audience.getDefaultVariation() === '') {
|
|
54
|
+
throw new Error('Variation not found');
|
|
55
|
+
}
|
|
56
|
+
return audience.getDefaultVariation();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
var input = "".concat(featureID, "-").concat(userID, "-").concat(samplingSeed);
|
|
61
|
+
var bucket = bucketeer.bucket(input);
|
|
62
|
+
var rangeEnd = 0.0;
|
|
78
63
|
var _iterator = _createForOfIteratorHelper(strategy.getVariationsList()),
|
|
79
64
|
_step;
|
|
80
65
|
try {
|
|
81
66
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
82
67
|
var variation = _step.value;
|
|
83
|
-
|
|
84
|
-
if (bucket <
|
|
68
|
+
rangeEnd += variation.getWeight() / 100000.0;
|
|
69
|
+
if (bucket < rangeEnd) {
|
|
85
70
|
return variation.getVariation();
|
|
86
71
|
}
|
|
87
72
|
}
|
|
@@ -92,25 +77,6 @@ var StrategyEvaluator = /*#__PURE__*/function () {
|
|
|
92
77
|
}
|
|
93
78
|
throw new Error('Variation not found');
|
|
94
79
|
}
|
|
95
|
-
}, {
|
|
96
|
-
key: "bucket",
|
|
97
|
-
value: function bucket(userID, featureID, samplingSeed) {
|
|
98
|
-
try {
|
|
99
|
-
var hash = this.hash(userID, featureID, samplingSeed);
|
|
100
|
-
var intVal = BigInt('0x' + hash.slice(0, 16)); // Convert the first 16 hex characters to BigInt
|
|
101
|
-
// Divide the BigInt value by `max` and convert it to a number. Use Number() since we need a float.
|
|
102
|
-
return Number(intVal) / Number(MAX);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error('Failed to calculate bucket value:', error);
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}, {
|
|
109
|
-
key: "hash",
|
|
110
|
-
value: function hash(userID, featureID, samplingSeed) {
|
|
111
|
-
var concat = "".concat(featureID, "-").concat(userID).concat(samplingSeed);
|
|
112
|
-
return crypto.createHash('md5').update(concat).digest('hex');
|
|
113
|
-
}
|
|
114
80
|
}, {
|
|
115
81
|
key: "findVariation",
|
|
116
82
|
value: function findVariation(variationID, variations) {
|
|
@@ -1,33 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.StrategyEvaluator = void 0;
|
|
27
|
-
const
|
|
4
|
+
const bucketeer_1 = require("./bucketeer");
|
|
28
5
|
const strategy_pb_1 = require("./proto/feature/strategy_pb");
|
|
29
|
-
//
|
|
30
|
-
const MAX = 0xffffffffffffffffn;
|
|
31
6
|
class StrategyEvaluator {
|
|
32
7
|
evaluate(strategy, userID, variations, featureID, samplingSeed) {
|
|
33
8
|
switch (strategy.getType()) {
|
|
@@ -45,32 +20,34 @@ class StrategyEvaluator {
|
|
|
45
20
|
}
|
|
46
21
|
}
|
|
47
22
|
rollout(strategy, userID, featureID, samplingSeed) {
|
|
48
|
-
const
|
|
49
|
-
|
|
23
|
+
const bucketeer = new bucketeer_1.Bucketeer();
|
|
24
|
+
const audience = strategy.getAudience();
|
|
25
|
+
if (audience !== undefined) {
|
|
26
|
+
if (audience.getPercentage() > 0 && audience.getPercentage() < 100) {
|
|
27
|
+
// Use different hash input for audience control to ensure independence from A/B split
|
|
28
|
+
const trafficInput = `traffic-${featureID}-${userID}-${samplingSeed}`;
|
|
29
|
+
const trafficBucket = bucketeer.bucket(trafficInput);
|
|
30
|
+
const trafficThreshold = audience.getPercentage() / 100.0;
|
|
31
|
+
// If user is not in experiment traffic, return default variation
|
|
32
|
+
if (trafficBucket >= trafficThreshold) {
|
|
33
|
+
if (audience.getDefaultVariation() === '') {
|
|
34
|
+
throw new Error('Variation not found');
|
|
35
|
+
}
|
|
36
|
+
return audience.getDefaultVariation();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const input = `${featureID}-${userID}-${samplingSeed}`;
|
|
41
|
+
const bucket = bucketeer.bucket(input);
|
|
42
|
+
let rangeEnd = 0.0;
|
|
50
43
|
for (const variation of strategy.getVariationsList()) {
|
|
51
|
-
|
|
52
|
-
if (bucket <
|
|
44
|
+
rangeEnd += variation.getWeight() / 100000.0;
|
|
45
|
+
if (bucket < rangeEnd) {
|
|
53
46
|
return variation.getVariation();
|
|
54
47
|
}
|
|
55
48
|
}
|
|
56
49
|
throw new Error('Variation not found');
|
|
57
50
|
}
|
|
58
|
-
bucket(userID, featureID, samplingSeed) {
|
|
59
|
-
try {
|
|
60
|
-
const hash = this.hash(userID, featureID, samplingSeed);
|
|
61
|
-
const intVal = BigInt('0x' + hash.slice(0, 16)); // Convert the first 16 hex characters to BigInt
|
|
62
|
-
// Divide the BigInt value by `max` and convert it to a number. Use Number() since we need a float.
|
|
63
|
-
return Number(intVal) / Number(MAX);
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
console.error('Failed to calculate bucket value:', error);
|
|
67
|
-
throw error;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
hash(userID, featureID, samplingSeed) {
|
|
71
|
-
const concat = `${featureID}-${userID}${samplingSeed}`;
|
|
72
|
-
return crypto.createHash('md5').update(concat).digest('hex');
|
|
73
|
-
}
|
|
74
51
|
findVariation(variationID, variations) {
|
|
75
52
|
for (const variation of variations) {
|
|
76
53
|
if (variation.getId() === variationID) {
|