@flagship.io/react-sdk 2.2.0-beta.6 → 3.0.2

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.
@@ -17,9 +17,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
17
17
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
18
 
19
19
  // eslint-disable-next-line no-use-before-define
20
- import React, { useState, useEffect, createContext, useRef } from 'react';
21
- import { Flagship, FlagshipStatus } from '@flagship.io/js-sdk';
22
- import { getModificationsFromCampaigns, logError } from './utils';
20
+ import React, { useState, useEffect, createContext, useRef } from "react";
21
+ import { Flagship, FlagshipStatus } from "@flagship.io/js-sdk";
22
+ import { getModificationsFromCampaigns, logError, useNonInitialEffect } from "./utils";
23
23
  var initStat = {
24
24
  status: {
25
25
  isLoading: true,
@@ -53,6 +53,7 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
53
53
  initialBucketing = _ref.initialBucketing,
54
54
  initialCampaigns = _ref.initialCampaigns,
55
55
  initialModifications = _ref.initialModifications,
56
+ initialFlagsData = _ref.initialFlagsData,
56
57
  synchronizeOnBucketingUpdated = _ref.synchronizeOnBucketingUpdated,
57
58
  activateDeduplicationTime = _ref.activateDeduplicationTime,
58
59
  hitDeduplicationTime = _ref.hitDeduplicationTime,
@@ -61,7 +62,11 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
61
62
  disableCache = _ref.disableCache;
62
63
  var modifications = new Map();
63
64
 
64
- if (initialModifications) {
65
+ if (initialFlagsData && initialFlagsData.forEach) {
66
+ initialFlagsData.forEach(function (flag) {
67
+ modifications.set(flag.key, flag);
68
+ });
69
+ } else if (initialModifications && initialModifications.forEach) {
65
70
  initialModifications.forEach(function (modification) {
66
71
  modifications.set(modification.key, modification);
67
72
  });
@@ -83,47 +88,20 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
83
88
 
84
89
  var stateRef = useRef();
85
90
  stateRef.current = state;
86
- useEffect(function () {
91
+ useNonInitialEffect(function () {
87
92
  if (synchronizeOnBucketingUpdated) {
88
93
  var _state$visitor;
89
94
 
90
- (_state$visitor = state.visitor) === null || _state$visitor === void 0 ? void 0 : _state$visitor.synchronizeModifications();
95
+ (_state$visitor = state.visitor) === null || _state$visitor === void 0 ? void 0 : _state$visitor.fetchFlags();
91
96
  }
92
97
  }, [lastModified]);
93
- useEffect(function () {
94
- updateVisitor();
98
+ useNonInitialEffect(function () {
99
+ createVisitor(true);
95
100
  }, [JSON.stringify(visitorData)]);
96
101
  useEffect(function () {
97
102
  initSdk();
98
103
  }, [envId, apiKey, decisionMode]);
99
104
 
100
- var updateVisitor = function updateVisitor() {
101
- if (!state.visitor) {
102
- return;
103
- }
104
-
105
- if (visitorData.context) {
106
- state.visitor.clearContext();
107
- state.visitor.updateContext(visitorData.context);
108
- }
109
-
110
- if (typeof visitorData.hasConsented === 'boolean') {
111
- state.visitor.setConsent(visitorData.hasConsented);
112
- }
113
-
114
- if (state.visitor.anonymousId && !visitorData.isAuthenticated) {
115
- state.visitor.unauthenticate();
116
- } else if (!state.visitor.anonymousId && visitorData.isAuthenticated) {
117
- state.visitor.authenticate(visitorData.id);
118
- }
119
-
120
- if (visitorData.id) {
121
- state.visitor.visitorId = visitorData.id;
122
- }
123
-
124
- state.visitor.synchronizeModifications();
125
- };
126
-
127
105
  function initializeState(param) {
128
106
  var newStatus = {
129
107
  isSdkReady: param.isSdkReady,
@@ -149,7 +127,7 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
149
127
 
150
128
  var onVisitorReady = function onVisitorReady(fsVisitor, error) {
151
129
  if (error) {
152
- logError(Flagship.getConfig(), error.message || error, 'onReady');
130
+ logError(Flagship.getConfig(), error.message || error, "onReady");
153
131
  return;
154
132
  }
155
133
 
@@ -168,6 +146,39 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
168
146
  }
169
147
  };
170
148
 
149
+ var createVisitor = function createVisitor() {
150
+ var fetchFlags = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
151
+
152
+ if (!visitorData) {
153
+ return;
154
+ }
155
+
156
+ var fsVisitor = Flagship.newVisitor({
157
+ visitorId: visitorData.id,
158
+ context: visitorData.context,
159
+ isAuthenticated: visitorData.isAuthenticated,
160
+ hasConsented: visitorData.hasConsented,
161
+ initialCampaigns: initialCampaigns,
162
+ initialModifications: initialModifications,
163
+ initialFlagsData: initialFlagsData
164
+ });
165
+ fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.on("ready", function (error) {
166
+ onVisitorReady(fsVisitor, error);
167
+ });
168
+
169
+ if (!fetchNow && fsVisitor && !fetchFlags) {
170
+ initializeState({
171
+ fsVisitor: fsVisitor,
172
+ isSdkReady: true,
173
+ isLoading: false
174
+ });
175
+ }
176
+
177
+ if (fetchFlags && !fetchNow) {
178
+ fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.fetchFlags();
179
+ }
180
+ };
181
+
171
182
  var statusChanged = function statusChanged(status) {
172
183
  if (statusChangedCallback) {
173
184
  statusChangedCallback(status);
@@ -175,38 +186,15 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
175
186
 
176
187
  if (status === FlagshipStatus.STARTING && onInitStart) {
177
188
  onInitStart();
178
- } else if (status === FlagshipStatus.READY_PANIC_ON || status === FlagshipStatus.READY) {
179
- var _stateRef$current;
189
+ return;
190
+ }
180
191
 
192
+ if (status === FlagshipStatus.READY_PANIC_ON || status === FlagshipStatus.READY) {
181
193
  if (onInitDone) {
182
194
  onInitDone();
183
195
  }
184
196
 
185
- if ((_stateRef$current = stateRef.current) !== null && _stateRef$current !== void 0 && _stateRef$current.visitor) {
186
- var _stateRef$current2;
187
-
188
- (_stateRef$current2 = stateRef.current) === null || _stateRef$current2 === void 0 ? void 0 : _stateRef$current2.visitor.synchronizeModifications();
189
- } else {
190
- var fsVisitor = Flagship.newVisitor({
191
- visitorId: visitorData.id,
192
- context: visitorData.context,
193
- isAuthenticated: visitorData.isAuthenticated,
194
- hasConsented: visitorData.hasConsented,
195
- initialCampaigns: initialCampaigns,
196
- initialModifications: initialModifications
197
- });
198
- fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.on('ready', function (error) {
199
- onVisitorReady(fsVisitor, error);
200
- });
201
-
202
- if (!fetchNow && fsVisitor) {
203
- initializeState({
204
- fsVisitor: fsVisitor,
205
- isSdkReady: true,
206
- isLoading: false
207
- });
208
- }
209
- }
197
+ createVisitor();
210
198
  }
211
199
  };
212
200
 
@@ -237,14 +225,15 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
237
225
  hitDeduplicationTime: hitDeduplicationTime,
238
226
  visitorCacheImplementation: visitorCacheImplementation,
239
227
  hitCacheImplementation: hitCacheImplementation,
240
- disableCache: disableCache
228
+ disableCache: disableCache,
229
+ language: 1
241
230
  });
242
231
  };
243
232
 
244
233
  var handleDisplay = function handleDisplay() {
245
234
  var isFirstInit = !state.visitor;
246
235
 
247
- if (state.status.isLoading && loadingComponent && isFirstInit) {
236
+ if (state.status.isLoading && loadingComponent && isFirstInit && fetchNow) {
248
237
  return /*#__PURE__*/React.createElement(React.Fragment, null, loadingComponent);
249
238
  }
250
239
 
@@ -259,7 +248,6 @@ export var FlagshipProvider = function FlagshipProvider(_ref) {
259
248
  }, handleDisplay());
260
249
  };
261
250
  FlagshipProvider.defaultProps = {
262
- nodeEnv: 'production',
263
251
  activateDeduplicationTime: 10,
264
252
  hitDeduplicationTime: 10
265
253
  };
@@ -1,3 +1,9 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
1
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
8
 
3
9
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -19,6 +25,8 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
19
25
  import { useContext } from 'react';
20
26
  import { FlagshipContext } from './FlagshipContext';
21
27
  import { logError, logWarn } from './utils';
28
+ import { Flag } from './Flag';
29
+ import { noVisitorDefault, noVisitorMessage } from './constants';
22
30
 
23
31
  var checkType = function checkType(value, defaultValue) {
24
32
  return _typeof(value) === 'object' && _typeof(defaultValue) === 'object' && Array.isArray(value) === Array.isArray(defaultValue) || _typeof(value) === _typeof(defaultValue);
@@ -62,6 +70,7 @@ var fsModificationsSync = function fsModificationsSync(args) {
62
70
  };
63
71
  /**
64
72
  * Retrieve a modification value by its key. If no modification match the given key or if the stored value type and default value type do not match, default value will be returned.
73
+ * @deprecated use useFsGetFlag instead
65
74
  */
66
75
 
67
76
 
@@ -83,6 +92,7 @@ export var useFsModifications = function useFsModifications(params, activateAll)
83
92
  };
84
93
  /**
85
94
  * Retrieve a modification value by its key. If no modification match the given key or if the stored value type and default value type do not match, default value will be returned.
95
+ * @deprecated use useFsGetFlag instead
86
96
  */
87
97
 
88
98
  export var useFsModification = function useFsModification(params) {
@@ -131,6 +141,7 @@ var fsModificationInfoSync = function fsModificationInfoSync(args) {
131
141
  /**
132
142
  * Get the campaign modification information value matching the given key.
133
143
  * @param {string} key key which identify the modification.
144
+ * @deprecated use useFsGetFlag instead
134
145
  */
135
146
 
136
147
 
@@ -146,8 +157,8 @@ export var useFsModificationInfo = function useFsModificationInfo(key) {
146
157
  });
147
158
  };
148
159
 
149
- var fsSynchronizeModifications = /*#__PURE__*/function () {
150
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(functionName, visitor, config) {
160
+ var fsActivate = /*#__PURE__*/function () {
161
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(params, functionName, visitor, config) {
151
162
  return regeneratorRuntime.wrap(function _callee$(_context) {
152
163
  while (1) {
153
164
  switch (_context.prev = _context.next) {
@@ -159,12 +170,12 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
159
170
  break;
160
171
  }
161
172
 
162
- reportNoVisitor(config, functionName);
173
+ logWarn(config, noVisitorMessage, functionName);
163
174
  return _context.abrupt("return");
164
175
 
165
176
  case 4:
166
177
  _context.next = 6;
167
- return visitor.synchronizeModifications();
178
+ return visitor.activateModifications(params);
168
179
 
169
180
  case 6:
170
181
  _context.next = 11;
@@ -173,7 +184,7 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
173
184
  case 8:
174
185
  _context.prev = 8;
175
186
  _context.t0 = _context["catch"](0);
176
- logError(config, _context.t0.message || _context.t0, functionName);
187
+ logWarn(config, _context.t0.message || _context.t0, functionName);
177
188
 
178
189
  case 11:
179
190
  case "end":
@@ -183,114 +194,61 @@ var fsSynchronizeModifications = /*#__PURE__*/function () {
183
194
  }, _callee, null, [[0, 8]]);
184
195
  }));
185
196
 
186
- return function fsSynchronizeModifications(_x, _x2, _x3) {
197
+ return function fsActivate(_x, _x2, _x3, _x4) {
187
198
  return _ref.apply(this, arguments);
188
199
  };
189
200
  }();
190
201
  /**
191
- * This function calls the decision api and update all the campaigns modifications from the server according to the visitor context.
192
- */
193
-
194
-
195
- export var useFsSynchronizeModifications = /*#__PURE__*/function () {
196
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
197
- var _useContext4, state, visitor, config, functionName;
198
-
199
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
200
- while (1) {
201
- switch (_context2.prev = _context2.next) {
202
- case 0:
203
- _useContext4 = useContext(FlagshipContext), state = _useContext4.state;
204
- visitor = state.visitor, config = state.config;
205
- functionName = 'useFsSynchronizeModifications';
206
- _context2.next = 5;
207
- return fsSynchronizeModifications(functionName, visitor, config);
208
-
209
- case 5:
210
- case "end":
211
- return _context2.stop();
212
- }
213
- }
214
- }, _callee2);
215
- }));
216
-
217
- return function useFsSynchronizeModifications() {
218
- return _ref2.apply(this, arguments);
219
- };
220
- }();
221
-
222
- var fsActivate = /*#__PURE__*/function () {
223
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params, functionName, visitor, config) {
224
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
225
- while (1) {
226
- switch (_context3.prev = _context3.next) {
227
- case 0:
228
- _context3.prev = 0;
229
-
230
- if (visitor) {
231
- _context3.next = 4;
232
- break;
233
- }
234
-
235
- logWarn(config, noVisitorMessage, functionName);
236
- return _context3.abrupt("return");
202
+ * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
203
+ * @param key
204
+ * @param defaultValue
205
+ * @returns
206
+ */
237
207
 
238
- case 4:
239
- _context3.next = 6;
240
- return visitor.activateModifications(params);
241
208
 
242
- case 6:
243
- _context3.next = 11;
244
- break;
209
+ export var useFsFlag = function useFsFlag(key, defaultValue) {
210
+ var _useContext4 = useContext(FlagshipContext),
211
+ state = _useContext4.state;
245
212
 
246
- case 8:
247
- _context3.prev = 8;
248
- _context3.t0 = _context3["catch"](0);
249
- logWarn(config, _context3.t0.message || _context3.t0, functionName);
213
+ var visitor = state.visitor;
250
214
 
251
- case 11:
252
- case "end":
253
- return _context3.stop();
254
- }
255
- }
256
- }, _callee3, null, [[0, 8]]);
257
- }));
215
+ if (!visitor) {
216
+ return new Flag(defaultValue);
217
+ }
258
218
 
259
- return function fsActivate(_x4, _x5, _x6, _x7) {
260
- return _ref3.apply(this, arguments);
261
- };
262
- }();
219
+ return visitor.getFlag(key, defaultValue);
220
+ };
263
221
  /**
264
222
  * Report this user has seen this modification. Report this user has seen these modifications.
265
223
  * @param params
224
+ * @deprecated use useFsGetFlag instead
266
225
  * @returns
267
226
  */
268
227
 
269
-
270
228
  export var useFsActivate = /*#__PURE__*/function () {
271
- var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(params) {
229
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(params) {
272
230
  var _useContext5, state, visitor, config, functionName;
273
231
 
274
- return regeneratorRuntime.wrap(function _callee4$(_context4) {
232
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
275
233
  while (1) {
276
- switch (_context4.prev = _context4.next) {
234
+ switch (_context2.prev = _context2.next) {
277
235
  case 0:
278
236
  _useContext5 = useContext(FlagshipContext), state = _useContext5.state;
279
237
  visitor = state.visitor, config = state.config;
280
238
  functionName = 'useFsModifications';
281
- _context4.next = 5;
239
+ _context2.next = 5;
282
240
  return fsActivate(params, functionName, visitor, config);
283
241
 
284
242
  case 5:
285
243
  case "end":
286
- return _context4.stop();
244
+ return _context2.stop();
287
245
  }
288
246
  }
289
- }, _callee4);
247
+ }, _callee2);
290
248
  }));
291
249
 
292
- return function useFsActivate(_x8) {
293
- return _ref4.apply(this, arguments);
250
+ return function useFsActivate(_x5) {
251
+ return _ref2.apply(this, arguments);
294
252
  };
295
253
  }();
296
254
  export var useFlagship = function useFlagship() {
@@ -345,8 +303,8 @@ export var useFlagship = function useFlagship() {
345
303
  visitor.unauthenticate();
346
304
  };
347
305
  /**
348
- * Send a Hit to Flagship servers for reporting.
349
- */
306
+ * Send a Hit to Flagship servers for reporting.
307
+ */
350
308
 
351
309
 
352
310
  var fsSendHit = function fsSendHit(hit) {
@@ -360,8 +318,8 @@ export var useFlagship = function useFlagship() {
360
318
  return visitor.sendHit(hit);
361
319
  };
362
320
  /**
363
- * Send a Hit to Flagship servers for reporting.
364
- */
321
+ * Send a Hit to Flagship servers for reporting.
322
+ */
365
323
 
366
324
 
367
325
  var fsSendHits = function fsSendHits(hit) {
@@ -379,60 +337,67 @@ export var useFlagship = function useFlagship() {
379
337
 
380
338
  if (!state.status.isSdkReady && state.modifications) {
381
339
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
382
- modifications = Array.from(state.modifications, function (_ref5) {
383
- var _ref6 = _slicedToArray(_ref5, 2),
384
- _key = _ref6[0],
385
- item = _ref6[1];
340
+ modifications = Array.from(state.modifications, function (_ref3) {
341
+ var _ref4 = _slicedToArray(_ref3, 2),
342
+ _key = _ref4[0],
343
+ item = _ref4[1];
386
344
 
387
345
  return item;
388
346
  });
389
347
  }
390
348
 
391
349
  var activateModification = /*#__PURE__*/function () {
392
- var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(params) {
350
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(params) {
393
351
  var functionName;
394
- return regeneratorRuntime.wrap(function _callee5$(_context5) {
352
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
395
353
  while (1) {
396
- switch (_context5.prev = _context5.next) {
354
+ switch (_context3.prev = _context3.next) {
397
355
  case 0:
398
356
  functionName = 'activateModification';
399
- _context5.next = 3;
357
+ _context3.next = 3;
400
358
  return fsActivate(params, functionName, visitor, config);
401
359
 
402
360
  case 3:
403
361
  case "end":
404
- return _context5.stop();
362
+ return _context3.stop();
405
363
  }
406
364
  }
407
- }, _callee5);
365
+ }, _callee3);
408
366
  }));
409
367
 
410
- return function activateModification(_x9) {
411
- return _ref7.apply(this, arguments);
368
+ return function activateModification(_x6) {
369
+ return _ref5.apply(this, arguments);
412
370
  };
413
371
  }();
414
372
 
415
373
  var synchronizeModifications = /*#__PURE__*/function () {
416
- var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
417
- var functionName;
418
- return regeneratorRuntime.wrap(function _callee6$(_context6) {
374
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
375
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
419
376
  while (1) {
420
- switch (_context6.prev = _context6.next) {
377
+ switch (_context4.prev = _context4.next) {
421
378
  case 0:
422
- functionName = 'synchronizeModifications';
423
- _context6.next = 3;
424
- return fsSynchronizeModifications(functionName, visitor, config);
379
+ if (visitor) {
380
+ _context4.next = 3;
381
+ break;
382
+ }
383
+
384
+ logWarn(config, noVisitorMessage, 'synchronizeModifications');
385
+ return _context4.abrupt("return");
425
386
 
426
387
  case 3:
388
+ _context4.next = 5;
389
+ return visitor.synchronizeModifications();
390
+
391
+ case 5:
427
392
  case "end":
428
- return _context6.stop();
393
+ return _context4.stop();
429
394
  }
430
395
  }
431
- }, _callee6);
396
+ }, _callee4);
432
397
  }));
433
398
 
434
399
  return function synchronizeModifications() {
435
- return _ref8.apply(this, arguments);
400
+ return _ref6.apply(this, arguments);
436
401
  };
437
402
  }();
438
403
 
@@ -456,7 +421,38 @@ export var useFlagship = function useFlagship() {
456
421
  });
457
422
  };
458
423
 
424
+ function getFlag(key, defaultValue) {
425
+ if (!visitor) {
426
+ return new Flag(defaultValue);
427
+ }
428
+
429
+ return visitor.getFlag(key, defaultValue);
430
+ }
431
+
432
+ function fetchFlags() {
433
+ if (!visitor) {
434
+ logWarn(config, noVisitorMessage, 'fetchFlags');
435
+ return Promise.resolve();
436
+ }
437
+
438
+ return visitor.fetchFlags();
439
+ }
440
+
441
+ function setConsent(hasConsented) {
442
+ if (!visitor) {
443
+ logWarn(config, noVisitorMessage, 'setConsent');
444
+ return;
445
+ }
446
+
447
+ visitor.setConsent(hasConsented);
448
+ }
449
+
459
450
  return {
451
+ visitorId: visitor === null || visitor === void 0 ? void 0 : visitor.visitorId,
452
+ anonymousId: visitor === null || visitor === void 0 ? void 0 : visitor.anonymousId,
453
+ context: _objectSpread({}, visitor === null || visitor === void 0 ? void 0 : visitor.context),
454
+ hasConsented: visitor === null || visitor === void 0 ? void 0 : visitor.hasConsented,
455
+ setConsent: setConsent,
460
456
  updateContext: fsUpdateContext,
461
457
  clearContext: fsClearContext,
462
458
  authenticate: fsAuthenticate,
@@ -466,16 +462,13 @@ export var useFlagship = function useFlagship() {
466
462
  synchronizeModifications: synchronizeModifications,
467
463
  getModifications: getModifications,
468
464
  modifications: modifications || [],
465
+ FlagsData: (visitor === null || visitor === void 0 ? void 0 : visitor.getFlagsDataArray()) || [],
469
466
  getModificationInfo: getModificationInfo,
470
467
  hit: {
471
468
  send: fsSendHit,
472
469
  sendMultiple: fsSendHits
473
- }
470
+ },
471
+ getFlag: getFlag,
472
+ fetchFlags: fetchFlags
474
473
  };
475
- };
476
- export var noVisitorMessage = 'sdk not correctly initialized... Make sure fsVisitor is ready.';
477
- export var noVisitorDefault = 'fsVisitor not initialized, returns default value';
478
-
479
- var reportNoVisitor = function reportNoVisitor(config, tag) {
480
- logError(config, noVisitorMessage, tag);
481
474
  };
@@ -0,0 +1,2 @@
1
+ export var noVisitorMessage = 'flagship Visitor not initialized.';
2
+ export var noVisitorDefault = 'fsVisitor not initialized, returns default value';
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { LogLevel } from '@flagship.io/js-sdk';
2
+ import { useEffect, useRef } from 'react';
2
3
  export function logError(config, message, tag) {
3
4
  if (!config || !config.logManager || typeof config.logManager.error !== 'function' || !config.logLevel || config.logLevel < LogLevel.ERROR) {
4
5
  return;
@@ -20,6 +21,16 @@ export function logWarn(config, message, tag) {
20
21
 
21
22
  config.logManager.warning(message, tag);
22
23
  }
24
+ export function log(level, message, tag) {
25
+ var now = new Date(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+
27
+ var getTwoDigit = function getTwoDigit(value) {
28
+ return value.toString().length === 1 ? "0".concat(value) : value;
29
+ };
30
+
31
+ var out = "[".concat(getTwoDigit(now.getFullYear()), "-").concat(getTwoDigit(now.getMonth()), "-").concat(getTwoDigit(now.getDay()), " ").concat(getTwoDigit(now.getHours()), ":").concat(getTwoDigit(now.getMinutes()), "] [Flagship SDK] [").concat(LogLevel[level], "] [").concat(tag, "] : ").concat(message);
32
+ console.log(out);
33
+ }
23
34
  export var getModificationsFromCampaigns = function getModificationsFromCampaigns(campaigns) {
24
35
  var modifications = new Map();
25
36
 
@@ -43,4 +54,24 @@ export var getModificationsFromCampaigns = function getModificationsFromCampaign
43
54
  }
44
55
  });
45
56
  return modifications;
46
- };
57
+ };
58
+ export function uuidV4() {
59
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
60
+ var rand = Math.random() * 16 | 0;
61
+ var value = char === 'x' ? rand : rand & 0x3 | 0x8;
62
+ return value.toString(16);
63
+ });
64
+ }
65
+ export function useNonInitialEffect(effect, deps) {
66
+ var initialRender = useRef(true);
67
+ useEffect(function () {
68
+ if (initialRender.current) {
69
+ initialRender.current = false;
70
+ return;
71
+ }
72
+
73
+ if (typeof effect === 'function') {
74
+ return effect();
75
+ }
76
+ }, deps);
77
+ }