flagsmith-nodejs 2.0.0-beta.5 → 2.0.0-beta.6
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/build/flagsmith-engine/environments/integrations/models.js +7 -4
- package/build/flagsmith-engine/environments/models.js +12 -23
- package/build/flagsmith-engine/environments/util.js +9 -7
- package/build/flagsmith-engine/features/models.js +64 -47
- package/build/flagsmith-engine/features/util.js +5 -5
- package/build/flagsmith-engine/identities/models.js +96 -31
- package/build/flagsmith-engine/identities/traits/models.js +4 -5
- package/build/flagsmith-engine/identities/util.js +33 -9
- package/build/flagsmith-engine/index.js +74 -22
- package/build/flagsmith-engine/organisations/models.js +11 -11
- package/build/flagsmith-engine/organisations/util.js +1 -1
- package/build/flagsmith-engine/projects/models.js +5 -8
- package/build/flagsmith-engine/projects/util.js +6 -6
- package/build/flagsmith-engine/segments/evaluators.js +17 -9
- package/build/flagsmith-engine/segments/models.js +67 -58
- package/build/flagsmith-engine/segments/util.js +10 -8
- package/build/flagsmith-engine/utils/collections.js +90 -9
- package/build/flagsmith-engine/utils/errors.js +22 -2
- package/build/flagsmith-engine/utils/hashing/index.js +11 -8
- package/build/flagsmith-engine/utils/index.js +3 -3
- package/build/index.js +1 -1
- package/build/sdk/analytics.js +72 -29
- package/build/sdk/errors.js +29 -4
- package/build/sdk/index.js +263 -140
- package/build/sdk/models.js +95 -47
- package/build/sdk/polling_manager.js +58 -16
- package/build/sdk/utils.js +67 -18
- package/example/package-lock.json +1 -996
- package/example/server/api/index.js +1 -1
- package/package.json +2 -1
- package/tsconfig.json +2 -1
package/build/sdk/errors.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
18
|
exports.FlagsmithAPIError = exports.FlagsmithClientError = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
19
|
+
var FlagsmithClientError = /** @class */ (function (_super) {
|
|
20
|
+
__extends(FlagsmithClientError, _super);
|
|
21
|
+
function FlagsmithClientError() {
|
|
22
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
23
|
+
}
|
|
24
|
+
return FlagsmithClientError;
|
|
25
|
+
}(Error));
|
|
6
26
|
exports.FlagsmithClientError = FlagsmithClientError;
|
|
7
|
-
|
|
8
|
-
|
|
27
|
+
var FlagsmithAPIError = /** @class */ (function (_super) {
|
|
28
|
+
__extends(FlagsmithAPIError, _super);
|
|
29
|
+
function FlagsmithAPIError() {
|
|
30
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
31
|
+
}
|
|
32
|
+
return FlagsmithAPIError;
|
|
33
|
+
}(Error));
|
|
9
34
|
exports.FlagsmithAPIError = FlagsmithAPIError;
|
package/build/sdk/index.js
CHANGED
|
@@ -1,33 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __values = (this && this.__values) || function(o) {
|
|
39
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
40
|
+
if (m) return m.call(o);
|
|
41
|
+
if (o && typeof o.length === "number") return {
|
|
42
|
+
next: function () {
|
|
43
|
+
if (o && i >= o.length) o = void 0;
|
|
44
|
+
return { value: o && o[i++], done: !o };
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
48
|
+
};
|
|
49
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
+
if (!m) return o;
|
|
52
|
+
var i = m.call(o), r, ar = [], e;
|
|
53
|
+
try {
|
|
54
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
+
}
|
|
56
|
+
catch (error) { e = { error: error }; }
|
|
57
|
+
finally {
|
|
58
|
+
try {
|
|
59
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
+
}
|
|
61
|
+
finally { if (e) throw e.error; }
|
|
62
|
+
}
|
|
63
|
+
return ar;
|
|
64
|
+
};
|
|
2
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
66
|
exports.Flagsmith = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
environmentKey;
|
|
17
|
-
apiUrl = DEFAULT_API_URL;
|
|
18
|
-
customHeaders;
|
|
19
|
-
requestTimeoutSeconds;
|
|
20
|
-
enableLocalEvaluation = false;
|
|
21
|
-
environmentRefreshIntervalSeconds = 60;
|
|
22
|
-
retries;
|
|
23
|
-
enableAnalytics = false;
|
|
24
|
-
defaultFlagHandler;
|
|
25
|
-
environmentFlagsUrl;
|
|
26
|
-
identitiesUrl;
|
|
27
|
-
environmentUrl;
|
|
28
|
-
environmentDataPollingManager;
|
|
29
|
-
environment;
|
|
30
|
-
analyticsProcessor;
|
|
67
|
+
var flagsmith_engine_1 = require("../flagsmith-engine");
|
|
68
|
+
var util_1 = require("../flagsmith-engine/environments/util");
|
|
69
|
+
var models_1 = require("../flagsmith-engine/identities/models");
|
|
70
|
+
var models_2 = require("../flagsmith-engine/identities/traits/models");
|
|
71
|
+
var analytics_1 = require("./analytics");
|
|
72
|
+
var errors_1 = require("./errors");
|
|
73
|
+
var models_3 = require("./models");
|
|
74
|
+
var polling_manager_1 = require("./polling_manager");
|
|
75
|
+
var utils_1 = require("./utils");
|
|
76
|
+
var evaluators_1 = require("../flagsmith-engine/segments/evaluators");
|
|
77
|
+
var DEFAULT_API_URL = 'https://api.flagsmith.com/api/v1/';
|
|
78
|
+
var Flagsmith = /** @class */ (function () {
|
|
31
79
|
/**
|
|
32
80
|
* A Flagsmith client.
|
|
33
81
|
*
|
|
@@ -58,7 +106,11 @@ class Flagsmith {
|
|
|
58
106
|
flags cannot be retrieved from the API or a non existent feature is
|
|
59
107
|
requested
|
|
60
108
|
*/
|
|
61
|
-
|
|
109
|
+
function Flagsmith(data) {
|
|
110
|
+
this.apiUrl = DEFAULT_API_URL;
|
|
111
|
+
this.enableLocalEvaluation = false;
|
|
112
|
+
this.environmentRefreshIntervalSeconds = 60;
|
|
113
|
+
this.enableAnalytics = false;
|
|
62
114
|
this.environmentKey = data.environmentKey;
|
|
63
115
|
this.apiUrl = data.apiUrl || this.apiUrl;
|
|
64
116
|
this.customHeaders = data.customHeaders;
|
|
@@ -69,9 +121,9 @@ class Flagsmith {
|
|
|
69
121
|
this.retries = data.retries;
|
|
70
122
|
this.enableAnalytics = data.enableAnalytics || false;
|
|
71
123
|
this.defaultFlagHandler = data.defaultFlagHandler;
|
|
72
|
-
this.environmentFlagsUrl =
|
|
73
|
-
this.identitiesUrl =
|
|
74
|
-
this.environmentUrl =
|
|
124
|
+
this.environmentFlagsUrl = "".concat(this.apiUrl, "flags/");
|
|
125
|
+
this.identitiesUrl = "".concat(this.apiUrl, "identities/");
|
|
126
|
+
this.environmentUrl = "".concat(this.apiUrl, "environment-document/");
|
|
75
127
|
if (this.enableLocalEvaluation) {
|
|
76
128
|
if (!this.environmentKey.startsWith('ser.')) {
|
|
77
129
|
console.error('In order to use local evaluation, please generate a server key in the environment settings page.');
|
|
@@ -93,12 +145,17 @@ class Flagsmith {
|
|
|
93
145
|
*
|
|
94
146
|
* @returns Flags object holding all the flags for the current environment.
|
|
95
147
|
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
148
|
+
Flagsmith.prototype.getEnvironmentFlags = function () {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
+
var _this = this;
|
|
151
|
+
return __generator(this, function (_a) {
|
|
152
|
+
if (this.environment) {
|
|
153
|
+
return [2 /*return*/, new Promise(function (resolve) { return resolve(_this.getEnvironmentFlagsFromDocument()); })];
|
|
154
|
+
}
|
|
155
|
+
return [2 /*return*/, this.getEnvironmentFlagsFromApi()];
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
102
159
|
/**
|
|
103
160
|
* Get all the flags for the current environment for a given identity. Will also
|
|
104
161
|
upsert all traits to the Flagsmith API for future evaluations. Providing a
|
|
@@ -110,15 +167,18 @@ class Flagsmith {
|
|
|
110
167
|
Flagsmith, e.g. {"num_orders": 10}
|
|
111
168
|
* @returns Flags object holding all the flags for the given identity.
|
|
112
169
|
*/
|
|
113
|
-
getIdentityFlags(identifier, traits) {
|
|
170
|
+
Flagsmith.prototype.getIdentityFlags = function (identifier, traits) {
|
|
171
|
+
var _this = this;
|
|
114
172
|
traits = traits || {};
|
|
115
173
|
if (this.enableLocalEvaluation) {
|
|
116
|
-
return new Promise(
|
|
117
|
-
|
|
118
|
-
|
|
174
|
+
return new Promise(function (resolve) {
|
|
175
|
+
return _this.environmentPromise.then(function () {
|
|
176
|
+
resolve(_this.getIdentityFlagsFromDocument(identifier, traits || {}));
|
|
177
|
+
});
|
|
178
|
+
});
|
|
119
179
|
}
|
|
120
180
|
return this.getIdentityFlagsFromApi(identifier, traits);
|
|
121
|
-
}
|
|
181
|
+
};
|
|
122
182
|
/**
|
|
123
183
|
* Get the segments for the current environment for a given identity. Will also
|
|
124
184
|
upsert all traits to the Flagsmith API for future evaluations. Providing a
|
|
@@ -130,134 +190,197 @@ class Flagsmith {
|
|
|
130
190
|
Flagsmith, e.g. {"num_orders": 10}
|
|
131
191
|
* @returns Segments that the given identity belongs to.
|
|
132
192
|
*/
|
|
133
|
-
getIdentitySegments(identifier, traits) {
|
|
193
|
+
Flagsmith.prototype.getIdentitySegments = function (identifier, traits) {
|
|
194
|
+
var _this = this;
|
|
134
195
|
traits = traits || {};
|
|
135
196
|
if (this.enableLocalEvaluation) {
|
|
136
|
-
return this.environmentPromise.then(()
|
|
137
|
-
return new Promise(resolve
|
|
138
|
-
|
|
139
|
-
key,
|
|
140
|
-
value: traits
|
|
141
|
-
})));
|
|
142
|
-
|
|
197
|
+
return this.environmentPromise.then(function () {
|
|
198
|
+
return new Promise(function (resolve) {
|
|
199
|
+
var identityModel = _this.buildIdentityModel(identifier, Object.keys(traits || {}).map(function (key) { return ({
|
|
200
|
+
key: key,
|
|
201
|
+
value: traits === null || traits === void 0 ? void 0 : traits[key]
|
|
202
|
+
}); }));
|
|
203
|
+
var segments = (0, evaluators_1.getIdentitySegments)(_this.environment, identityModel);
|
|
143
204
|
return resolve(segments);
|
|
144
205
|
});
|
|
145
206
|
});
|
|
146
207
|
}
|
|
147
208
|
console.error('This function is only permitted with local evaluation.');
|
|
148
209
|
return Promise.resolve([]);
|
|
149
|
-
}
|
|
210
|
+
};
|
|
150
211
|
/**
|
|
151
212
|
* Updates the environment state for local flag evaluation.
|
|
152
213
|
* Sets a local promise to prevent race conditions in getIdentityFlags / getIdentitySegments.
|
|
153
214
|
* You only need to call this if you wish to bypass environmentRefreshIntervalSeconds.
|
|
154
215
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
216
|
+
Flagsmith.prototype.updateEnvironment = function () {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
218
|
+
var request, _a;
|
|
219
|
+
var _this = this;
|
|
220
|
+
return __generator(this, function (_b) {
|
|
221
|
+
switch (_b.label) {
|
|
222
|
+
case 0:
|
|
223
|
+
request = this.getEnvironmentFromApi();
|
|
224
|
+
if (!!this.environmentPromise) return [3 /*break*/, 2];
|
|
225
|
+
this.environmentPromise = request.then(function (res) {
|
|
226
|
+
_this.environment = res;
|
|
227
|
+
});
|
|
228
|
+
return [4 /*yield*/, this.environmentPromise];
|
|
229
|
+
case 1:
|
|
230
|
+
_b.sent();
|
|
231
|
+
return [3 /*break*/, 4];
|
|
232
|
+
case 2:
|
|
233
|
+
_a = this;
|
|
234
|
+
return [4 /*yield*/, request];
|
|
235
|
+
case 3:
|
|
236
|
+
_a.environment = _b.sent();
|
|
237
|
+
_b.label = 4;
|
|
238
|
+
case 4: return [2 /*return*/];
|
|
239
|
+
}
|
|
160
240
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
Flagsmith.prototype.getJSONResponse = function (url, method, body) {
|
|
244
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
245
|
+
var headers, _a, _b, _c, k, v, data;
|
|
246
|
+
var e_1, _d;
|
|
247
|
+
return __generator(this, function (_e) {
|
|
248
|
+
switch (_e.label) {
|
|
249
|
+
case 0:
|
|
250
|
+
headers = { 'Content-Type': 'application/json' };
|
|
251
|
+
if (this.environmentKey) {
|
|
252
|
+
headers['X-Environment-Key'] = this.environmentKey;
|
|
253
|
+
}
|
|
254
|
+
if (this.customHeaders) {
|
|
255
|
+
try {
|
|
256
|
+
for (_a = __values(Object.entries(this.customHeaders)), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
257
|
+
_c = __read(_b.value, 2), k = _c[0], v = _c[1];
|
|
258
|
+
headers[k] = v;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
262
|
+
finally {
|
|
263
|
+
try {
|
|
264
|
+
if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
|
|
265
|
+
}
|
|
266
|
+
finally { if (e_1) throw e_1.error; }
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return [4 /*yield*/, (0, utils_1.retryFetch)(url, {
|
|
270
|
+
method: method,
|
|
271
|
+
timeout: this.requestTimeoutSeconds || undefined,
|
|
272
|
+
body: JSON.stringify(body),
|
|
273
|
+
headers: headers
|
|
274
|
+
}, this.retries, 1000, (this.requestTimeoutSeconds || 10) * 1000)];
|
|
275
|
+
case 1:
|
|
276
|
+
data = _e.sent();
|
|
277
|
+
if (data.status !== 200) {
|
|
278
|
+
throw new errors_1.FlagsmithAPIError("Invalid request made to Flagsmith API. Response status code: ".concat(data.status));
|
|
279
|
+
}
|
|
280
|
+
return [2 /*return*/, data.json()];
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
Flagsmith.prototype.getEnvironmentFromApi = function () {
|
|
286
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
287
|
+
var environment_data;
|
|
288
|
+
return __generator(this, function (_a) {
|
|
289
|
+
switch (_a.label) {
|
|
290
|
+
case 0: return [4 /*yield*/, this.getJSONResponse(this.environmentUrl, 'GET')];
|
|
291
|
+
case 1:
|
|
292
|
+
environment_data = _a.sent();
|
|
293
|
+
return [2 /*return*/, (0, util_1.buildEnvironmentModel)(environment_data)];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
};
|
|
298
|
+
Flagsmith.prototype.getEnvironmentFlagsFromDocument = function () {
|
|
197
299
|
return models_3.Flags.fromFeatureStateModels({
|
|
198
300
|
featureStates: (0, flagsmith_engine_1.getEnvironmentFeatureStates)(this.environment),
|
|
199
301
|
analyticsProcessor: this.analyticsProcessor,
|
|
200
302
|
defaultFlagHandler: this.defaultFlagHandler
|
|
201
303
|
});
|
|
202
|
-
}
|
|
203
|
-
getIdentityFlagsFromDocument(identifier, traits) {
|
|
204
|
-
|
|
205
|
-
key,
|
|
304
|
+
};
|
|
305
|
+
Flagsmith.prototype.getIdentityFlagsFromDocument = function (identifier, traits) {
|
|
306
|
+
var identityModel = this.buildIdentityModel(identifier, Object.keys(traits).map(function (key) { return ({
|
|
307
|
+
key: key,
|
|
206
308
|
value: traits[key]
|
|
207
|
-
})));
|
|
208
|
-
|
|
309
|
+
}); }));
|
|
310
|
+
var featureStates = (0, flagsmith_engine_1.getIdentityFeatureStates)(this.environment, identityModel);
|
|
209
311
|
return models_3.Flags.fromFeatureStateModels({
|
|
210
312
|
featureStates: featureStates,
|
|
211
313
|
analyticsProcessor: this.analyticsProcessor,
|
|
212
314
|
defaultFlagHandler: this.defaultFlagHandler
|
|
213
315
|
});
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
316
|
+
};
|
|
317
|
+
Flagsmith.prototype.getEnvironmentFlagsFromApi = function () {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
319
|
+
var apiFlags, e_2;
|
|
320
|
+
return __generator(this, function (_a) {
|
|
321
|
+
switch (_a.label) {
|
|
322
|
+
case 0:
|
|
323
|
+
_a.trys.push([0, 2, , 3]);
|
|
324
|
+
return [4 /*yield*/, this.getJSONResponse(this.environmentFlagsUrl, 'GET')];
|
|
325
|
+
case 1:
|
|
326
|
+
apiFlags = _a.sent();
|
|
327
|
+
return [2 /*return*/, models_3.Flags.fromAPIFlags({
|
|
328
|
+
apiFlags: apiFlags,
|
|
329
|
+
analyticsProcessor: this.analyticsProcessor,
|
|
330
|
+
defaultFlagHandler: this.defaultFlagHandler
|
|
331
|
+
})];
|
|
332
|
+
case 2:
|
|
333
|
+
e_2 = _a.sent();
|
|
334
|
+
if (this.defaultFlagHandler) {
|
|
335
|
+
return [2 /*return*/, new models_3.Flags({
|
|
336
|
+
flags: {},
|
|
337
|
+
defaultFlagHandler: this.defaultFlagHandler
|
|
338
|
+
})];
|
|
339
|
+
}
|
|
340
|
+
throw e_2;
|
|
341
|
+
case 3: return [2 /*return*/];
|
|
342
|
+
}
|
|
222
343
|
});
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
Flagsmith.prototype.getIdentityFlagsFromApi = function (identifier, traits) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
+
var data, jsonResponse, e_3;
|
|
349
|
+
return __generator(this, function (_a) {
|
|
350
|
+
switch (_a.label) {
|
|
351
|
+
case 0:
|
|
352
|
+
_a.trys.push([0, 2, , 3]);
|
|
353
|
+
data = (0, utils_1.generateIdentitiesData)(identifier, traits);
|
|
354
|
+
return [4 /*yield*/, this.getJSONResponse(this.identitiesUrl, 'POST', data)];
|
|
355
|
+
case 1:
|
|
356
|
+
jsonResponse = _a.sent();
|
|
357
|
+
return [2 /*return*/, models_3.Flags.fromAPIFlags({
|
|
358
|
+
apiFlags: jsonResponse['flags'],
|
|
359
|
+
analyticsProcessor: this.analyticsProcessor,
|
|
360
|
+
defaultFlagHandler: this.defaultFlagHandler
|
|
361
|
+
})];
|
|
362
|
+
case 2:
|
|
363
|
+
e_3 = _a.sent();
|
|
364
|
+
if (this.defaultFlagHandler) {
|
|
365
|
+
return [2 /*return*/, new models_3.Flags({
|
|
366
|
+
flags: {},
|
|
367
|
+
defaultFlagHandler: this.defaultFlagHandler
|
|
368
|
+
})];
|
|
369
|
+
}
|
|
370
|
+
throw e_3;
|
|
371
|
+
case 3: return [2 /*return*/];
|
|
372
|
+
}
|
|
242
373
|
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return new models_3.Flags({
|
|
247
|
-
flags: {},
|
|
248
|
-
defaultFlagHandler: this.defaultFlagHandler
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
throw e;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
buildIdentityModel(identifier, traits) {
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
Flagsmith.prototype.buildIdentityModel = function (identifier, traits) {
|
|
255
377
|
if (!this.environment) {
|
|
256
378
|
throw new errors_1.FlagsmithClientError('Unable to build identity model when no local environment present.');
|
|
257
379
|
}
|
|
258
|
-
|
|
380
|
+
var traitModels = traits.map(function (trait) { return new models_2.TraitModel(trait.key, trait.value); });
|
|
259
381
|
return new models_1.IdentityModel('0', traitModels, [], this.environment.apiKey, identifier);
|
|
260
|
-
}
|
|
261
|
-
|
|
382
|
+
};
|
|
383
|
+
return Flagsmith;
|
|
384
|
+
}());
|
|
262
385
|
exports.Flagsmith = Flagsmith;
|
|
263
386
|
exports.default = Flagsmith;
|