@splitsoftware/openfeature-js-split-provider 1.0.4 → 1.0.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splitsoftware/openfeature-js-split-provider",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Split OpenFeature Provider",
5
5
  "files": [
6
6
  "README.md",
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "dependencies": {},
28
28
  "peerDependencies": {
29
- "@openfeature/js-sdk": "^0.5.0",
30
- "@splitsoftware/splitio": "^10.21.1"
29
+ "@openfeature/js-sdk": "^1.0.0",
30
+ "@splitsoftware/splitio": "^10.22.1"
31
31
  },
32
32
  "devDependencies": {
33
- "@openfeature/js-sdk": "^0.5.0",
34
- "@splitsoftware/splitio": "^10.21.1",
33
+ "@openfeature/js-sdk": "^1.0.0",
34
+ "@splitsoftware/splitio": "^10.22.1",
35
35
  "copyfiles": "^2.4.1",
36
36
  "cross-env": "^7.0.3",
37
37
  "replace": "^1.2.1",
@@ -64,4 +64,4 @@
64
64
  "karma-webpack"
65
65
  ]
66
66
  }
67
- }
67
+ }
package/es/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './lib/js-split-provider';
@@ -1,163 +0,0 @@
1
- import { __assign, __awaiter, __generator, __rest } from "tslib";
2
- import { ParseError, FlagNotFoundError, StandardResolutionReasons } from '@openfeature/js-sdk';
3
- var OpenFeatureSplitProvider = /** @class */ (function () {
4
- function OpenFeatureSplitProvider(options) {
5
- var _this = this;
6
- this.metadata = {
7
- name: 'split',
8
- };
9
- this.client = options.splitClient;
10
- this.initialized = new Promise(function (resolve) {
11
- _this.client.on(_this.client.Event.SDK_READY, function () {
12
- console.log(_this.metadata.name + " provider initialized");
13
- resolve();
14
- });
15
- });
16
- }
17
- OpenFeatureSplitProvider.prototype.resolveBooleanEvaluation = function (flagKey, defaultValue, context) {
18
- return __awaiter(this, void 0, void 0, function () {
19
- var details, value;
20
- return __generator(this, function (_a) {
21
- switch (_a.label) {
22
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
23
- case 1:
24
- details = _a.sent();
25
- switch (details.value) {
26
- case 'on':
27
- value = true;
28
- break;
29
- case 'off':
30
- value = false;
31
- break;
32
- case 'true':
33
- value = true;
34
- break;
35
- case 'false':
36
- value = false;
37
- break;
38
- case true:
39
- value = true;
40
- break;
41
- case false:
42
- value = false;
43
- break;
44
- case 'control':
45
- value = defaultValue;
46
- details.reason = 'FLAG_NOT_FOUND';
47
- break;
48
- default:
49
- throw new ParseError("Invalid boolean value for " + details.value);
50
- }
51
- return [2 /*return*/, __assign(__assign({}, details), { value: value })];
52
- }
53
- });
54
- });
55
- };
56
- OpenFeatureSplitProvider.prototype.resolveStringEvaluation = function (flagKey, _, context) {
57
- return __awaiter(this, void 0, void 0, function () {
58
- var details;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
62
- case 1:
63
- details = _a.sent();
64
- if (details.value == 'control') {
65
- throw new FlagNotFoundError("Got error for split " + flagKey);
66
- }
67
- return [2 /*return*/, details];
68
- }
69
- });
70
- });
71
- };
72
- OpenFeatureSplitProvider.prototype.resolveNumberEvaluation = function (flagKey, _, context) {
73
- return __awaiter(this, void 0, void 0, function () {
74
- var details;
75
- return __generator(this, function (_a) {
76
- switch (_a.label) {
77
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
78
- case 1:
79
- details = _a.sent();
80
- return [2 /*return*/, __assign(__assign({}, details), { value: this.parseValidNumber(details.value) })];
81
- }
82
- });
83
- });
84
- };
85
- OpenFeatureSplitProvider.prototype.resolveObjectEvaluation = function (flagKey, _, context) {
86
- return __awaiter(this, void 0, void 0, function () {
87
- var details;
88
- return __generator(this, function (_a) {
89
- switch (_a.label) {
90
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
91
- case 1:
92
- details = _a.sent();
93
- return [2 /*return*/, __assign(__assign({}, details), { value: this.parseValidJsonObject(details.value) })];
94
- }
95
- });
96
- });
97
- };
98
- OpenFeatureSplitProvider.prototype.evaluateTreatment = function (flagKey, consumer) {
99
- return __awaiter(this, void 0, void 0, function () {
100
- var details, value, details;
101
- return __generator(this, function (_a) {
102
- switch (_a.label) {
103
- case 0:
104
- if (!!consumer.key) return [3 /*break*/, 1];
105
- details = {
106
- value: 'control',
107
- variant: 'control',
108
- reason: StandardResolutionReasons.ERROR,
109
- errorCode: 'TARGETING_KEY_MISSING'
110
- };
111
- return [2 /*return*/, details];
112
- case 1: return [4 /*yield*/, this.initialized];
113
- case 2:
114
- _a.sent();
115
- value = this.client.getTreatment(consumer.key, flagKey, consumer.attributes);
116
- details = {
117
- value: value,
118
- variant: value,
119
- reason: StandardResolutionReasons.TARGETING_MATCH
120
- };
121
- return [2 /*return*/, details];
122
- }
123
- });
124
- });
125
- };
126
- //Transform the context into an object useful for the Split API, an key string with arbitrary Split "Attributes".
127
- OpenFeatureSplitProvider.prototype.transformContext = function (context) {
128
- var targetingKey = context.targetingKey, attributes = __rest(context, ["targetingKey"]);
129
- return {
130
- key: targetingKey,
131
- // Stringify context objects include date.
132
- attributes: JSON.parse(JSON.stringify(attributes)),
133
- };
134
- };
135
- OpenFeatureSplitProvider.prototype.parseValidNumber = function (stringValue) {
136
- if (stringValue === undefined) {
137
- throw new ParseError("Invalid 'undefined' value.");
138
- }
139
- var result = Number.parseFloat(stringValue);
140
- if (Number.isNaN(result)) {
141
- throw new ParseError("Invalid numeric value " + stringValue);
142
- }
143
- return result;
144
- };
145
- OpenFeatureSplitProvider.prototype.parseValidJsonObject = function (stringValue) {
146
- if (stringValue === undefined) {
147
- throw new ParseError("Invalid 'undefined' JSON value.");
148
- }
149
- // we may want to allow the parsing to be customized.
150
- try {
151
- var value = JSON.parse(stringValue);
152
- if (typeof value !== 'object') {
153
- throw new ParseError("Flag value " + stringValue + " had unexpected type " + typeof value + ", expected \"object\"");
154
- }
155
- return value;
156
- }
157
- catch (err) {
158
- throw new ParseError("Error parsing " + stringValue + " as JSON, " + err);
159
- }
160
- };
161
- return OpenFeatureSplitProvider;
162
- }());
163
- export { OpenFeatureSplitProvider };
package/lib/index.js DELETED
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./lib/js-split-provider"), exports);
@@ -1,166 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.OpenFeatureSplitProvider = void 0;
4
- var tslib_1 = require("tslib");
5
- var js_sdk_1 = require("@openfeature/js-sdk");
6
- var OpenFeatureSplitProvider = /** @class */ (function () {
7
- function OpenFeatureSplitProvider(options) {
8
- var _this = this;
9
- this.metadata = {
10
- name: 'split',
11
- };
12
- this.client = options.splitClient;
13
- this.initialized = new Promise(function (resolve) {
14
- _this.client.on(_this.client.Event.SDK_READY, function () {
15
- console.log(_this.metadata.name + " provider initialized");
16
- resolve();
17
- });
18
- });
19
- }
20
- OpenFeatureSplitProvider.prototype.resolveBooleanEvaluation = function (flagKey, defaultValue, context) {
21
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
22
- var details, value;
23
- return (0, tslib_1.__generator)(this, function (_a) {
24
- switch (_a.label) {
25
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
26
- case 1:
27
- details = _a.sent();
28
- switch (details.value) {
29
- case 'on':
30
- value = true;
31
- break;
32
- case 'off':
33
- value = false;
34
- break;
35
- case 'true':
36
- value = true;
37
- break;
38
- case 'false':
39
- value = false;
40
- break;
41
- case true:
42
- value = true;
43
- break;
44
- case false:
45
- value = false;
46
- break;
47
- case 'control':
48
- value = defaultValue;
49
- details.reason = 'FLAG_NOT_FOUND';
50
- break;
51
- default:
52
- throw new js_sdk_1.ParseError("Invalid boolean value for " + details.value);
53
- }
54
- return [2 /*return*/, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, details), { value: value })];
55
- }
56
- });
57
- });
58
- };
59
- OpenFeatureSplitProvider.prototype.resolveStringEvaluation = function (flagKey, _, context) {
60
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
61
- var details;
62
- return (0, tslib_1.__generator)(this, function (_a) {
63
- switch (_a.label) {
64
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
65
- case 1:
66
- details = _a.sent();
67
- if (details.value == 'control') {
68
- throw new js_sdk_1.FlagNotFoundError("Got error for split " + flagKey);
69
- }
70
- return [2 /*return*/, details];
71
- }
72
- });
73
- });
74
- };
75
- OpenFeatureSplitProvider.prototype.resolveNumberEvaluation = function (flagKey, _, context) {
76
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
77
- var details;
78
- return (0, tslib_1.__generator)(this, function (_a) {
79
- switch (_a.label) {
80
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
81
- case 1:
82
- details = _a.sent();
83
- return [2 /*return*/, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, details), { value: this.parseValidNumber(details.value) })];
84
- }
85
- });
86
- });
87
- };
88
- OpenFeatureSplitProvider.prototype.resolveObjectEvaluation = function (flagKey, _, context) {
89
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
90
- var details;
91
- return (0, tslib_1.__generator)(this, function (_a) {
92
- switch (_a.label) {
93
- case 0: return [4 /*yield*/, this.evaluateTreatment(flagKey, this.transformContext(context))];
94
- case 1:
95
- details = _a.sent();
96
- return [2 /*return*/, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, details), { value: this.parseValidJsonObject(details.value) })];
97
- }
98
- });
99
- });
100
- };
101
- OpenFeatureSplitProvider.prototype.evaluateTreatment = function (flagKey, consumer) {
102
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
103
- var details, value, details;
104
- return (0, tslib_1.__generator)(this, function (_a) {
105
- switch (_a.label) {
106
- case 0:
107
- if (!!consumer.key) return [3 /*break*/, 1];
108
- details = {
109
- value: 'control',
110
- variant: 'control',
111
- reason: js_sdk_1.StandardResolutionReasons.ERROR,
112
- errorCode: 'TARGETING_KEY_MISSING'
113
- };
114
- return [2 /*return*/, details];
115
- case 1: return [4 /*yield*/, this.initialized];
116
- case 2:
117
- _a.sent();
118
- value = this.client.getTreatment(consumer.key, flagKey, consumer.attributes);
119
- details = {
120
- value: value,
121
- variant: value,
122
- reason: js_sdk_1.StandardResolutionReasons.TARGETING_MATCH
123
- };
124
- return [2 /*return*/, details];
125
- }
126
- });
127
- });
128
- };
129
- //Transform the context into an object useful for the Split API, an key string with arbitrary Split "Attributes".
130
- OpenFeatureSplitProvider.prototype.transformContext = function (context) {
131
- var targetingKey = context.targetingKey, attributes = (0, tslib_1.__rest)(context, ["targetingKey"]);
132
- return {
133
- key: targetingKey,
134
- // Stringify context objects include date.
135
- attributes: JSON.parse(JSON.stringify(attributes)),
136
- };
137
- };
138
- OpenFeatureSplitProvider.prototype.parseValidNumber = function (stringValue) {
139
- if (stringValue === undefined) {
140
- throw new js_sdk_1.ParseError("Invalid 'undefined' value.");
141
- }
142
- var result = Number.parseFloat(stringValue);
143
- if (Number.isNaN(result)) {
144
- throw new js_sdk_1.ParseError("Invalid numeric value " + stringValue);
145
- }
146
- return result;
147
- };
148
- OpenFeatureSplitProvider.prototype.parseValidJsonObject = function (stringValue) {
149
- if (stringValue === undefined) {
150
- throw new js_sdk_1.ParseError("Invalid 'undefined' JSON value.");
151
- }
152
- // we may want to allow the parsing to be customized.
153
- try {
154
- var value = JSON.parse(stringValue);
155
- if (typeof value !== 'object') {
156
- throw new js_sdk_1.ParseError("Flag value " + stringValue + " had unexpected type " + typeof value + ", expected \"object\"");
157
- }
158
- return value;
159
- }
160
- catch (err) {
161
- throw new js_sdk_1.ParseError("Error parsing " + stringValue + " as JSON, " + err);
162
- }
163
- };
164
- return OpenFeatureSplitProvider;
165
- }());
166
- exports.OpenFeatureSplitProvider = OpenFeatureSplitProvider;