@flagship.io/react-sdk 3.1.0 → 3.1.1-alpha.1

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.
@@ -1,1066 +1,2 @@
1
- /******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ "./src/Flag.ts":
6
- /*!*********************!*\
7
- !*** ./src/Flag.ts ***!
8
- \*********************/
9
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
10
-
11
-
12
-
13
- Object.defineProperty(exports, "__esModule", ({
14
- value: true
15
- }));
16
- exports.Flag = void 0;
17
-
18
- __webpack_require__(/*! core-js/modules/es.promise.js */ "core-js/modules/es.promise.js");
19
-
20
- var _jsSdk = _interopRequireWildcard(__webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk"));
21
-
22
- var _constants = __webpack_require__(/*! ./constants */ "./src/constants.ts");
23
-
24
- var _utils = __webpack_require__(/*! ./utils */ "./src/utils.tsx");
25
-
26
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
27
-
28
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
29
-
30
- 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; }
31
-
32
- class Flag {
33
- constructor(defaultValue, key, flagsData) {
34
- _defineProperty(this, "defaultValue", void 0);
35
-
36
- _defineProperty(this, "flagsData", void 0);
37
-
38
- _defineProperty(this, "key", void 0);
39
-
40
- _defineProperty(this, "flag", void 0);
41
-
42
- if (!flagsData) {
43
- (0, _utils.logWarn)(_jsSdk.default.getConfig(), _constants.noVisitorMessage, 'GetFlag');
44
- }
45
-
46
- this.defaultValue = defaultValue;
47
- this.key = key;
48
- this.flag = flagsData === null || flagsData === void 0 ? void 0 : flagsData.get(key);
49
- }
50
-
51
- NotSameType() {
52
- var _this$flag;
53
-
54
- return this.defaultValue !== null && this.defaultValue !== undefined && !(0, _utils.hasSameType)((_this$flag = this.flag) === null || _this$flag === void 0 ? void 0 : _this$flag.value, this.defaultValue);
55
- }
56
-
57
- getValue() {
58
- if (!this.flag) {
59
- (0, _utils.logWarn)(_jsSdk.default.getConfig(), _constants.noVisitorMessage, 'getValue');
60
- return this.defaultValue;
61
- }
62
-
63
- if (this.NotSameType()) {
64
- (0, _utils.logInfo)(_jsSdk.default.getConfig(), (0, _utils.sprintf)(_constants.GET_FLAG_CAST_ERROR, this.key), 'getValue');
65
- return this.defaultValue;
66
- }
67
-
68
- return this.flag.value;
69
- }
70
-
71
- exists() {
72
- if (!this.flag) {
73
- (0, _utils.logWarn)(_jsSdk.default.getConfig(), _constants.noVisitorMessage, 'exists');
74
- return false;
75
- }
76
-
77
- return !!(this.flag.campaignId && this.flag.variationId && this.flag.variationGroupId);
78
- }
79
-
80
- userExposed() {
81
- if (!this.flag) {
82
- (0, _utils.logWarn)(_jsSdk.default.getConfig(), _constants.noVisitorMessage, 'userExposed');
83
- }
84
-
85
- return Promise.resolve();
86
- }
87
-
88
- get metadata() {
89
- const functionName = 'metadata';
90
-
91
- if (!this.flag) {
92
- (0, _utils.logWarn)(_jsSdk.default.getConfig(), _constants.noVisitorMessage, functionName);
93
- return _jsSdk.FlagMetadata.Empty();
94
- }
95
-
96
- if (this.NotSameType()) {
97
- (0, _utils.logInfo)(_jsSdk.default.getConfig(), (0, _utils.sprintf)(_constants.GET_METADATA_CAST_ERROR, this.key), functionName);
98
- return _jsSdk.FlagMetadata.Empty();
99
- }
100
-
101
- return new _jsSdk.FlagMetadata({
102
- campaignId: this.flag.campaignId,
103
- variationGroupId: this.flag.variationGroupId,
104
- variationId: this.flag.variationId,
105
- isReference: !!this.flag.isReference,
106
- campaignType: this.flag.campaignType,
107
- slug: this.flag.slug
108
- });
109
- }
110
-
111
- }
112
-
113
- exports.Flag = Flag;
114
-
115
- /***/ }),
116
-
117
- /***/ "./src/FlagshipContext.tsx":
118
- /*!*********************************!*\
119
- !*** ./src/FlagshipContext.tsx ***!
120
- \*********************************/
121
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
122
-
123
-
124
-
125
- Object.defineProperty(exports, "__esModule", ({
126
- value: true
127
- }));
128
- exports.FlagshipProvider = exports.FlagshipContext = void 0;
129
-
130
- var _react = _interopRequireWildcard(__webpack_require__(/*! react */ "react"));
131
-
132
- var _jsSdk = __webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk");
133
-
134
- var _utils = __webpack_require__(/*! ./utils */ "./src/utils.tsx");
135
-
136
- var _sdkVersion = __webpack_require__(/*! ./sdkVersion */ "./src/sdkVersion.ts");
137
-
138
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
139
-
140
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
141
-
142
- // eslint-disable-next-line no-use-before-define
143
- const initStat = {
144
- status: {
145
- isLoading: true,
146
- isSdkReady: false
147
- }
148
- };
149
- const FlagshipContext = /*#__PURE__*/(0, _react.createContext)({
150
- state: { ...initStat
151
- }
152
- });
153
- exports.FlagshipContext = FlagshipContext;
154
-
155
- const FlagshipProvider = ({
156
- children,
157
- fetchNow,
158
- envId,
159
- apiKey,
160
- decisionMode,
161
- visitorData,
162
- onInitStart,
163
- onInitDone,
164
- loadingComponent,
165
- statusChangedCallback,
166
- onBucketingUpdated,
167
- onUpdate,
168
- initialCampaigns,
169
- initialModifications,
170
- initialFlagsData,
171
- fetchFlagsOnBucketingUpdated,
172
- ...props
173
- }) => {
174
- let modifications = new Map();
175
-
176
- if (initialFlagsData && initialFlagsData.forEach) {
177
- initialFlagsData.forEach(flag => {
178
- modifications.set(flag.key, flag);
179
- });
180
- } else if (initialModifications && initialModifications.forEach) {
181
- initialModifications.forEach(modification => {
182
- modifications.set(modification.key, modification);
183
- });
184
- } else if (initialCampaigns) {
185
- modifications = (0, _utils.getModificationsFromCampaigns)(initialCampaigns);
186
- }
187
-
188
- const [state, setState] = (0, _react.useState)({ ...initStat,
189
- modifications
190
- });
191
- const [lastModified, setLastModified] = (0, _react.useState)();
192
- const stateRef = (0, _react.useRef)();
193
- stateRef.current = state;
194
- (0, _utils.useNonInitialEffect)(() => {
195
- if (fetchFlagsOnBucketingUpdated) {
196
- var _state$visitor;
197
-
198
- (_state$visitor = state.visitor) === null || _state$visitor === void 0 ? void 0 : _state$visitor.fetchFlags();
199
- }
200
- }, [lastModified]);
201
- (0, _utils.useNonInitialEffect)(() => {
202
- createVisitor(true);
203
- }, [JSON.stringify(visitorData)]);
204
- (0, _react.useEffect)(() => {
205
- initSdk();
206
- }, [envId, apiKey, decisionMode]);
207
-
208
- function initializeState(param) {
209
- const newStatus = {
210
- isSdkReady: param.isSdkReady,
211
- isLoading: param.isLoading,
212
- isVisitorDefined: !!param.fsVisitor,
213
- lastRefresh: new Date().toISOString()
214
- };
215
- setState(currentState => {
216
- if (!currentState.status.firstInitSuccess) {
217
- newStatus.firstInitSuccess = new Date().toISOString();
218
- }
219
-
220
- return { ...currentState,
221
- visitor: param.fsVisitor,
222
- modifications: param.fsVisitor.modifications,
223
- config: _jsSdk.Flagship.getConfig(),
224
- status: { ...currentState.status,
225
- ...newStatus
226
- }
227
- };
228
- });
229
- return newStatus;
230
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
231
-
232
-
233
- const onVisitorReady = (fsVisitor, error) => {
234
- if (error) {
235
- (0, _utils.logError)(_jsSdk.Flagship.getConfig(), error.message || error, 'onReady');
236
- return;
237
- }
238
-
239
- const newStatus = initializeState({
240
- fsVisitor,
241
- isSdkReady: true,
242
- isLoading: false
243
- });
244
-
245
- if (onUpdate) {
246
- onUpdate({
247
- fsModifications: fsVisitor.modifications,
248
- config: _jsSdk.Flagship.getConfig(),
249
- status: newStatus
250
- });
251
- }
252
- };
253
-
254
- const createVisitor = (fetchFlags = false) => {
255
- if (!visitorData) {
256
- return;
257
- }
258
-
259
- const fsVisitor = _jsSdk.Flagship.newVisitor({
260
- visitorId: visitorData.id,
261
- context: visitorData.context,
262
- isAuthenticated: visitorData.isAuthenticated,
263
- hasConsented: visitorData.hasConsented,
264
- initialCampaigns,
265
- initialModifications,
266
- initialFlagsData
267
- });
268
-
269
- fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.on('ready', error => {
270
- onVisitorReady(fsVisitor, error);
271
- });
272
-
273
- if (!fetchNow && fsVisitor && !fetchFlags) {
274
- initializeState({
275
- fsVisitor,
276
- isSdkReady: true,
277
- isLoading: false
278
- });
279
- }
280
-
281
- if (fetchFlags && !fetchNow) {
282
- fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.fetchFlags();
283
- }
284
- };
285
-
286
- const statusChanged = status => {
287
- if (statusChangedCallback) {
288
- statusChangedCallback(status);
289
- }
290
-
291
- switch (status) {
292
- case _jsSdk.FlagshipStatus.STARTING:
293
- if (status === _jsSdk.FlagshipStatus.STARTING && onInitStart) {
294
- onInitStart();
295
- }
296
-
297
- break;
298
-
299
- case _jsSdk.FlagshipStatus.READY_PANIC_ON:
300
- case _jsSdk.FlagshipStatus.READY:
301
- if (onInitDone) {
302
- onInitDone();
303
- }
304
-
305
- createVisitor();
306
- break;
307
-
308
- case _jsSdk.FlagshipStatus.NOT_INITIALIZED:
309
- setState(prev => ({ ...prev,
310
- status: { ...prev.status,
311
- isLoading: false
312
- },
313
- config: _jsSdk.Flagship.getConfig()
314
- }));
315
- break;
316
- }
317
- };
318
-
319
- const onBucketingLastModified = lastUpdate => {
320
- if (onBucketingUpdated) {
321
- onBucketingUpdated(lastUpdate);
322
- }
323
-
324
- setLastModified(lastUpdate);
325
- };
326
-
327
- const initSdk = () => {
328
- _jsSdk.Flagship.start(envId, apiKey, {
329
- decisionMode,
330
- fetchNow,
331
- statusChangedCallback: statusChanged,
332
- onBucketingUpdated: onBucketingLastModified,
333
- ...props
334
- });
335
- };
336
-
337
- const handleDisplay = () => {
338
- const isFirstInit = !state.visitor;
339
-
340
- if (state.status.isLoading && loadingComponent && isFirstInit && fetchNow) {
341
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, loadingComponent);
342
- }
343
-
344
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
345
- };
346
-
347
- return /*#__PURE__*/_react.default.createElement(FlagshipContext.Provider, {
348
- value: {
349
- state,
350
- setState
351
- }
352
- }, handleDisplay());
353
- };
354
-
355
- exports.FlagshipProvider = FlagshipProvider;
356
- FlagshipProvider.defaultProps = {
357
- hitDeduplicationTime: 2,
358
- fetchNow: true,
359
- language: 1,
360
- sdkVersion: _sdkVersion.version
361
- };
362
-
363
- /***/ }),
364
-
365
- /***/ "./src/FlagshipHooks.tsx":
366
- /*!*******************************!*\
367
- !*** ./src/FlagshipHooks.tsx ***!
368
- \*******************************/
369
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
370
-
371
-
372
-
373
- Object.defineProperty(exports, "__esModule", ({
374
- value: true
375
- }));
376
- exports.useFlagship = exports.useFsActivate = exports.useFsFlag = exports.useFsModificationInfo = exports.useFsModification = exports.useFsModifications = void 0;
377
-
378
- __webpack_require__(/*! core-js/modules/es.promise.js */ "core-js/modules/es.promise.js");
379
-
380
- var _react = __webpack_require__(/*! react */ "react");
381
-
382
- var _jsSdk = _interopRequireDefault(__webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk"));
383
-
384
- var _FlagshipContext = __webpack_require__(/*! ./FlagshipContext */ "./src/FlagshipContext.tsx");
385
-
386
- var _utils = __webpack_require__(/*! ./utils */ "./src/utils.tsx");
387
-
388
- var _Flag = __webpack_require__(/*! ./Flag */ "./src/Flag.ts");
389
-
390
- var _constants = __webpack_require__(/*! ./constants */ "./src/constants.ts");
391
-
392
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
393
-
394
- const checkType = (value, defaultValue) => typeof value === 'object' && typeof defaultValue === 'object' && Array.isArray(value) === Array.isArray(defaultValue) || typeof value === typeof defaultValue;
395
-
396
- const fsModificationsSync = args => {
397
- const {
398
- visitor,
399
- params,
400
- activateAll,
401
- state,
402
- functionName,
403
- config
404
- } = args;
405
-
406
- if (visitor) {
407
- return visitor.getModificationsSync(params, activateAll);
408
- }
409
-
410
- const check = !state.status.isSdkReady && !!state.modifications && state.modifications.size > 0;
411
- const flags = {};
412
-
413
- if (check) {
414
- params.forEach(item => {
415
- var _state$modifications;
416
-
417
- const modification = (_state$modifications = state.modifications) === null || _state$modifications === void 0 ? void 0 : _state$modifications.get(item.key);
418
-
419
- if (modification && checkType(modification === null || modification === void 0 ? void 0 : modification.value, item.defaultValue)) {
420
- flags[item.key] = modification.value;
421
- } else {
422
- flags[item.key] = item.defaultValue;
423
- }
424
- });
425
- return flags;
426
- }
427
-
428
- (0, _utils.logWarn)(config, _constants.noVisitorDefault, functionName);
429
- params.forEach(item => {
430
- flags[item.key] = item.defaultValue;
431
- });
432
- return flags;
433
- };
434
- /**
435
- * 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.
436
- * @deprecated use useFsFlag instead
437
- */
438
-
439
-
440
- const useFsModifications = (params, activateAll) => {
441
- const {
442
- state
443
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
444
- const {
445
- visitor,
446
- config
447
- } = state;
448
- const functionName = 'useFsModifications';
449
- return fsModificationsSync({
450
- functionName,
451
- state,
452
- visitor,
453
- config,
454
- params,
455
- activateAll
456
- });
457
- };
458
- /**
459
- * 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.
460
- * @deprecated use useFsFlag instead
461
- */
462
-
463
-
464
- exports.useFsModifications = useFsModifications;
465
-
466
- const useFsModification = params => {
467
- var _state$modifications2;
468
-
469
- const {
470
- state
471
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
472
- const {
473
- visitor,
474
- config
475
- } = state;
476
- const functionName = 'useFsModifications';
477
-
478
- if (visitor) {
479
- return visitor.getModificationSync(params);
480
- }
481
-
482
- const modification = (_state$modifications2 = state.modifications) === null || _state$modifications2 === void 0 ? void 0 : _state$modifications2.get(params.key);
483
-
484
- if (!state.status.isSdkReady && modification && checkType(modification === null || modification === void 0 ? void 0 : modification.value, params.defaultValue)) {
485
- return modification.value;
486
- }
487
-
488
- (0, _utils.logWarn)(config, _constants.noVisitorDefault, functionName);
489
- return params.defaultValue;
490
- };
491
-
492
- exports.useFsModification = useFsModification;
493
-
494
- const fsModificationInfoSync = args => {
495
- var _state$modifications3;
496
-
497
- const {
498
- key,
499
- visitor,
500
- state
501
- } = args;
502
-
503
- if (visitor) {
504
- return visitor.getModificationInfoSync(key);
505
- }
506
-
507
- const modification = (_state$modifications3 = state.modifications) === null || _state$modifications3 === void 0 ? void 0 : _state$modifications3.get(key);
508
-
509
- if (!state.status.isSdkReady && modification) {
510
- return modification;
511
- }
512
-
513
- return null;
514
- };
515
- /**
516
- * Get the campaign modification information value matching the given key.
517
- * @param {string} key key which identify the modification.
518
- * @deprecated use useFsFlag instead
519
- */
520
-
521
-
522
- const useFsModificationInfo = key => {
523
- const {
524
- state
525
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
526
- const {
527
- visitor
528
- } = state;
529
- return fsModificationInfoSync({
530
- key,
531
- state,
532
- visitor
533
- });
534
- };
535
-
536
- exports.useFsModificationInfo = useFsModificationInfo;
537
-
538
- const fsActivate = async (params, functionName, visitor, config) => {
539
- try {
540
- if (!visitor) {
541
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, functionName);
542
- return;
543
- }
544
-
545
- await visitor.activateModifications(params); // eslint-disable-next-line @typescript-eslint/no-explicit-any
546
- } catch (error) {
547
- (0, _utils.logWarn)(config, error.message || error, functionName);
548
- }
549
- };
550
- /**
551
- * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
552
- * @param key
553
- * @param defaultValue
554
- * @returns
555
- */
556
-
557
-
558
- const useFsFlag = (key, defaultValue) => {
559
- const {
560
- state
561
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
562
- const {
563
- visitor
564
- } = state;
565
-
566
- if (!visitor) {
567
- return new _Flag.Flag(defaultValue, key, state.modifications);
568
- }
569
-
570
- return visitor.getFlag(key, defaultValue);
571
- };
572
- /**
573
- * Report this user has seen this modification. Report this user has seen these modifications.
574
- * @param params
575
- * @deprecated use useFsFlag instead
576
- * @returns
577
- */
578
-
579
-
580
- exports.useFsFlag = useFsFlag;
581
-
582
- const useFsActivate = async params => {
583
- const {
584
- state
585
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
586
- const {
587
- visitor,
588
- config
589
- } = state;
590
- const functionName = 'useFsModifications';
591
- await fsActivate(params, functionName, visitor, config);
592
- };
593
-
594
- exports.useFsActivate = useFsActivate;
595
-
596
- const useFlagship = () => {
597
- const {
598
- state
599
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
600
- const {
601
- visitor,
602
- config
603
- } = state;
604
-
605
- const fsUpdateContext = context => {
606
- const functionName = 'updateContext';
607
-
608
- if (!visitor) {
609
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
610
- return;
611
- }
612
-
613
- visitor.clearContext();
614
- visitor.updateContext(context);
615
- };
616
-
617
- const fsClearContext = () => {
618
- const functionName = 'cleanContext';
619
-
620
- if (!visitor) {
621
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
622
- return;
623
- }
624
-
625
- visitor.clearContext();
626
- };
627
-
628
- const fsAuthenticate = visitorId => {
629
- const functionName = 'authenticate';
630
-
631
- if (!visitor) {
632
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
633
- return;
634
- }
635
-
636
- visitor.authenticate(visitorId);
637
- };
638
-
639
- const fsUnauthenticate = () => {
640
- const functionName = 'unauthenticate';
641
-
642
- if (!visitor) {
643
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
644
- return;
645
- }
646
-
647
- visitor.unauthenticate();
648
- };
649
- /**
650
- * Send a Hit to Flagship servers for reporting.
651
- */
652
-
653
-
654
- const fsSendHit = hit => {
655
- const functionName = 'sendHit';
656
-
657
- if (!visitor) {
658
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
659
- return Promise.resolve();
660
- }
661
-
662
- return visitor.sendHit(hit);
663
- };
664
- /**
665
- * Send a Hit to Flagship servers for reporting.
666
- */
667
-
668
-
669
- const fsSendHits = hit => {
670
- const functionName = 'sendHits';
671
-
672
- if (!visitor) {
673
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
674
- return Promise.resolve();
675
- }
676
-
677
- return visitor.sendHits(hit);
678
- };
679
-
680
- let modifications = visitor === null || visitor === void 0 ? void 0 : visitor.getModificationsArray();
681
-
682
- if (!state.status.isSdkReady && state.modifications) {
683
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
684
- modifications = Array.from(state.modifications, ([_key, item]) => item);
685
- }
686
-
687
- const activateModification = async params => {
688
- const functionName = 'activateModification';
689
- await fsActivate(params, functionName, visitor, config);
690
- };
691
-
692
- const synchronizeModifications = async () => {
693
- if (!visitor) {
694
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'synchronizeModifications');
695
- return;
696
- }
697
-
698
- await visitor.synchronizeModifications();
699
- };
700
-
701
- const getModifications = (params, activateAll) => {
702
- const functionName = 'getModifications';
703
- return fsModificationsSync({
704
- functionName,
705
- state,
706
- visitor,
707
- config,
708
- params,
709
- activateAll
710
- });
711
- };
712
-
713
- const getModificationInfo = key => {
714
- return fsModificationInfoSync({
715
- key,
716
- state,
717
- visitor
718
- });
719
- };
720
-
721
- function getFlag(key, defaultValue) {
722
- if (!visitor) {
723
- return new _Flag.Flag(defaultValue, key, state.modifications);
724
- }
725
-
726
- return visitor.getFlag(key, defaultValue);
727
- }
728
-
729
- function fetchFlags() {
730
- if (!visitor) {
731
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'fetchFlags');
732
- return Promise.resolve();
733
- }
734
-
735
- return visitor.fetchFlags();
736
- }
737
-
738
- function setConsent(hasConsented) {
739
- if (!visitor) {
740
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'setConsent');
741
- return;
742
- }
743
-
744
- visitor.setConsent(hasConsented);
745
- }
746
-
747
- async function close() {
748
- await _jsSdk.default.close();
749
- }
750
-
751
- return {
752
- visitorId: visitor === null || visitor === void 0 ? void 0 : visitor.visitorId,
753
- anonymousId: visitor === null || visitor === void 0 ? void 0 : visitor.anonymousId,
754
- context: { ...(visitor === null || visitor === void 0 ? void 0 : visitor.context)
755
- },
756
- hasConsented: visitor === null || visitor === void 0 ? void 0 : visitor.hasConsented,
757
- setConsent,
758
- updateContext: fsUpdateContext,
759
- clearContext: fsClearContext,
760
- authenticate: fsAuthenticate,
761
- unauthenticate: fsUnauthenticate,
762
- status: state.status,
763
- activateModification,
764
- synchronizeModifications,
765
- getModifications,
766
- modifications: modifications || [],
767
- flagsData: (visitor === null || visitor === void 0 ? void 0 : visitor.getFlagsDataArray()) || [],
768
- getModificationInfo,
769
- hit: {
770
- send: fsSendHit,
771
- sendMultiple: fsSendHits
772
- },
773
- getFlag,
774
- fetchFlags,
775
- close
776
- };
777
- };
778
-
779
- exports.useFlagship = useFlagship;
780
-
781
- /***/ }),
782
-
783
- /***/ "./src/constants.ts":
784
- /*!**************************!*\
785
- !*** ./src/constants.ts ***!
786
- \**************************/
787
- /***/ ((__unused_webpack_module, exports) => {
788
-
789
-
790
-
791
- Object.defineProperty(exports, "__esModule", ({
792
- value: true
793
- }));
794
- exports.GET_METADATA_CAST_ERROR = exports.GET_FLAG_CAST_ERROR = exports.noVisitorDefault = exports.noVisitorMessage = void 0;
795
- const noVisitorMessage = 'flagship Visitor not initialized.';
796
- exports.noVisitorMessage = noVisitorMessage;
797
- const noVisitorDefault = 'fsVisitor not initialized, returns default value';
798
- exports.noVisitorDefault = noVisitorDefault;
799
- const GET_FLAG_CAST_ERROR = 'Flag for key {0} has a different type. Default value is returned.';
800
- exports.GET_FLAG_CAST_ERROR = GET_FLAG_CAST_ERROR;
801
- const GET_METADATA_CAST_ERROR = 'Flag for key {0} has a different type with defaultValue, an empty metadata object is returned';
802
- exports.GET_METADATA_CAST_ERROR = GET_METADATA_CAST_ERROR;
803
-
804
- /***/ }),
805
-
806
- /***/ "./src/index.tsx":
807
- /*!***********************!*\
808
- !*** ./src/index.tsx ***!
809
- \***********************/
810
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
811
-
812
-
813
-
814
- Object.defineProperty(exports, "__esModule", ({
815
- value: true
816
- }));
817
-
818
- var _FlagshipContext = __webpack_require__(/*! ./FlagshipContext */ "./src/FlagshipContext.tsx");
819
-
820
- Object.keys(_FlagshipContext).forEach(function (key) {
821
- if (key === "default" || key === "__esModule") return;
822
- if (key in exports && exports[key] === _FlagshipContext[key]) return;
823
- Object.defineProperty(exports, key, {
824
- enumerable: true,
825
- get: function () {
826
- return _FlagshipContext[key];
827
- }
828
- });
829
- });
830
-
831
- var _jsSdk = __webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk");
832
-
833
- Object.keys(_jsSdk).forEach(function (key) {
834
- if (key === "default" || key === "__esModule") return;
835
- if (key in exports && exports[key] === _jsSdk[key]) return;
836
- Object.defineProperty(exports, key, {
837
- enumerable: true,
838
- get: function () {
839
- return _jsSdk[key];
840
- }
841
- });
842
- });
843
-
844
- var _FlagshipHooks = __webpack_require__(/*! ./FlagshipHooks */ "./src/FlagshipHooks.tsx");
845
-
846
- Object.keys(_FlagshipHooks).forEach(function (key) {
847
- if (key === "default" || key === "__esModule") return;
848
- if (key in exports && exports[key] === _FlagshipHooks[key]) return;
849
- Object.defineProperty(exports, key, {
850
- enumerable: true,
851
- get: function () {
852
- return _FlagshipHooks[key];
853
- }
854
- });
855
- });
856
-
857
- /***/ }),
858
-
859
- /***/ "./src/sdkVersion.ts":
860
- /*!***************************!*\
861
- !*** ./src/sdkVersion.ts ***!
862
- \***************************/
863
- /***/ ((__unused_webpack_module, exports) => {
864
-
865
-
866
-
867
- Object.defineProperty(exports, "__esModule", ({
868
- value: true
869
- }));
870
- exports.version = void 0;
871
- // Generated by genversion.
872
- const version = '3.1.0';
873
- exports.version = version;
874
-
875
- /***/ }),
876
-
877
- /***/ "./src/utils.tsx":
878
- /*!***********************!*\
879
- !*** ./src/utils.tsx ***!
880
- \***********************/
881
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
882
-
883
-
884
-
885
- Object.defineProperty(exports, "__esModule", ({
886
- value: true
887
- }));
888
- exports.logError = logError;
889
- exports.logInfo = logInfo;
890
- exports.logWarn = logWarn;
891
- exports.uuidV4 = uuidV4;
892
- exports.useNonInitialEffect = useNonInitialEffect;
893
- exports.hasSameType = hasSameType;
894
- exports.sprintf = sprintf;
895
- exports.getModificationsFromCampaigns = void 0;
896
-
897
- var _jsSdk = __webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk");
898
-
899
- var _react = __webpack_require__(/*! react */ "react");
900
-
901
- function logError(config, message, tag) {
902
- if (!config || !config.logManager || typeof config.logManager.error !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.ERROR) {
903
- return;
904
- }
905
-
906
- config.logManager.error(message, tag);
907
- }
908
-
909
- function logInfo(config, message, tag) {
910
- if (!config || !config.logManager || typeof config.logManager.info !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.INFO) {
911
- return;
912
- }
913
-
914
- config.logManager.info(message, tag);
915
- }
916
-
917
- function logWarn(config, message, tag) {
918
- if (!config || !config.logManager || typeof config.logManager.warning !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.WARNING) {
919
- return;
920
- }
921
-
922
- config.logManager.warning(message, tag);
923
- }
924
-
925
- const getModificationsFromCampaigns = campaigns => {
926
- const modifications = new Map();
927
-
928
- if (!campaigns || !Array.isArray(campaigns)) {
929
- return modifications;
930
- }
931
-
932
- campaigns.forEach(campaign => {
933
- const object = campaign.variation.modifications.value;
934
-
935
- for (const key in object) {
936
- const value = object[key];
937
- modifications.set(key, {
938
- key,
939
- campaignId: campaign.id,
940
- variationGroupId: campaign.variationGroupId,
941
- variationId: campaign.variation.id,
942
- isReference: campaign.variation.reference,
943
- value
944
- });
945
- }
946
- });
947
- return modifications;
948
- };
949
-
950
- exports.getModificationsFromCampaigns = getModificationsFromCampaigns;
951
-
952
- function uuidV4() {
953
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
954
- const rand = Math.random() * 16 | 0;
955
- const value = char === 'x' ? rand : rand & 0x3 | 0x8;
956
- return value.toString(16);
957
- });
958
- }
959
-
960
- function useNonInitialEffect(effect, deps) {
961
- const initialRender = (0, _react.useRef)(true);
962
- (0, _react.useEffect)(() => {
963
- if (initialRender.current) {
964
- initialRender.current = false;
965
- return;
966
- }
967
-
968
- if (typeof effect === 'function') {
969
- return effect();
970
- }
971
- }, deps);
972
- }
973
-
974
- function hasSameType(flagValue, defaultValue) {
975
- if (typeof flagValue !== typeof defaultValue) {
976
- return false;
977
- }
978
-
979
- if (typeof flagValue === 'object' && typeof defaultValue === 'object' && Array.isArray(flagValue) !== Array.isArray(defaultValue)) {
980
- return false;
981
- }
982
-
983
- return true;
984
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
985
-
986
-
987
- function sprintf(format, ...value) {
988
- let formatted = format;
989
-
990
- for (let i = 0; i < value.length; i++) {
991
- const element = value[i];
992
- formatted = formatted.replace(new RegExp(`\\{${i}\\}`, 'g'), element);
993
- }
994
-
995
- return formatted;
996
- }
997
-
998
- /***/ }),
999
-
1000
- /***/ "@flagship.io/js-sdk":
1001
- /*!**************************************!*\
1002
- !*** external "@flagship.io/js-sdk" ***!
1003
- \**************************************/
1004
- /***/ ((module) => {
1005
-
1006
- module.exports = require("@flagship.io/js-sdk");
1007
-
1008
- /***/ }),
1009
-
1010
- /***/ "core-js/modules/es.promise.js":
1011
- /*!************************************************!*\
1012
- !*** external "core-js/modules/es.promise.js" ***!
1013
- \************************************************/
1014
- /***/ ((module) => {
1015
-
1016
- module.exports = require("core-js/modules/es.promise.js");
1017
-
1018
- /***/ }),
1019
-
1020
- /***/ "react":
1021
- /*!************************!*\
1022
- !*** external "react" ***!
1023
- \************************/
1024
- /***/ ((module) => {
1025
-
1026
- module.exports = require("react");
1027
-
1028
- /***/ })
1029
-
1030
- /******/ });
1031
- /************************************************************************/
1032
- /******/ // The module cache
1033
- /******/ var __webpack_module_cache__ = {};
1034
- /******/
1035
- /******/ // The require function
1036
- /******/ function __webpack_require__(moduleId) {
1037
- /******/ // Check if module is in cache
1038
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
1039
- /******/ if (cachedModule !== undefined) {
1040
- /******/ return cachedModule.exports;
1041
- /******/ }
1042
- /******/ // Create a new module (and put it into the cache)
1043
- /******/ var module = __webpack_module_cache__[moduleId] = {
1044
- /******/ // no module.id needed
1045
- /******/ // no module.loaded needed
1046
- /******/ exports: {}
1047
- /******/ };
1048
- /******/
1049
- /******/ // Execute the module function
1050
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1051
- /******/
1052
- /******/ // Return the exports of the module
1053
- /******/ return module.exports;
1054
- /******/ }
1055
- /******/
1056
- /************************************************************************/
1057
- /******/
1058
- /******/ // startup
1059
- /******/ // Load entry module and return exports
1060
- /******/ // This entry module is referenced by other modules so it can't be inlined
1061
- /******/ var __webpack_exports__ = __webpack_require__("./src/index.tsx");
1062
- /******/ module.exports = __webpack_exports__;
1063
- /******/
1064
- /******/ })()
1065
- ;
1
+ (()=>{"use strict";var e={161:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Flag=void 0,i(117);var a=function(e,t){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var i=s(t);if(i&&i.has(e))return i.get(e);var a={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if("default"!==n&&Object.prototype.hasOwnProperty.call(e,n)){var r=o?Object.getOwnPropertyDescriptor(e,n):null;r&&(r.get||r.set)?Object.defineProperty(a,n,r):a[n]=e[n]}return a.default=e,i&&i.set(e,a),a}(i(4)),o=i(147),n=i(370);function s(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,i=new WeakMap;return(s=function(e){return e?i:t})(e)}function r(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}t.Flag=class{constructor(e,t,i){r(this,"defaultValue",void 0),r(this,"flagsData",void 0),r(this,"key",void 0),r(this,"flag",void 0),i||(0,n.logWarn)(a.default.getConfig(),o.noVisitorMessage,"GetFlag"),this.defaultValue=e,this.key=t,this.flag=null==i?void 0:i.get(t)}NotSameType(){var e;return null!==this.defaultValue&&void 0!==this.defaultValue&&!(0,n.hasSameType)(null===(e=this.flag)||void 0===e?void 0:e.value,this.defaultValue)}getValue(){return this.flag?this.NotSameType()?((0,n.logInfo)(a.default.getConfig(),(0,n.sprintf)(o.GET_FLAG_CAST_ERROR,this.key),"getValue"),this.defaultValue):this.flag.value:((0,n.logWarn)(a.default.getConfig(),o.noVisitorMessage,"getValue"),this.defaultValue)}exists(){return this.flag?!!(this.flag.campaignId&&this.flag.variationId&&this.flag.variationGroupId):((0,n.logWarn)(a.default.getConfig(),o.noVisitorMessage,"exists"),!1)}userExposed(){return this.flag||(0,n.logWarn)(a.default.getConfig(),o.noVisitorMessage,"userExposed"),Promise.resolve()}get metadata(){const e="metadata";return this.flag?this.NotSameType()?((0,n.logInfo)(a.default.getConfig(),(0,n.sprintf)(o.GET_METADATA_CAST_ERROR,this.key),e),a.FlagMetadata.Empty()):new a.FlagMetadata({campaignId:this.flag.campaignId,variationGroupId:this.flag.variationGroupId,variationId:this.flag.variationId,isReference:!!this.flag.isReference,campaignType:this.flag.campaignType,slug:this.flag.slug}):((0,n.logWarn)(a.default.getConfig(),o.noVisitorMessage,e),a.FlagMetadata.Empty())}}},821:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.FlagshipProvider=t.FlagshipContext=void 0;var a=function(e,t){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var i=r(t);if(i&&i.has(e))return i.get(e);var a={},o=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if("default"!==n&&Object.prototype.hasOwnProperty.call(e,n)){var s=o?Object.getOwnPropertyDescriptor(e,n):null;s&&(s.get||s.set)?Object.defineProperty(a,n,s):a[n]=e[n]}return a.default=e,i&&i.set(e,a),a}(i(689)),o=i(4),n=i(370),s=i(359);function r(e){if("function"!=typeof WeakMap)return null;var t=new WeakMap,i=new WeakMap;return(r=function(e){return e?i:t})(e)}const l={status:{isLoading:!0,isSdkReady:!1}},u=(0,a.createContext)({state:{...l}});t.FlagshipContext=u;const f=({children:e,fetchNow:t,envId:i,apiKey:s,decisionMode:r,visitorData:f,onInitStart:c,onInitDone:d,loadingComponent:g,statusChangedCallback:p,onBucketingUpdated:v,onUpdate:y,initialCampaigns:h,initialModifications:M,initialFlagsData:x,fetchFlagsOnBucketingUpdated:m,...F})=>{let C=new Map;x&&x.forEach?x.forEach((e=>{C.set(e.key,e)})):M&&M.forEach?M.forEach((e=>{C.set(e.key,e)})):h&&(C=(0,n.getModificationsFromCampaigns)(h));const[E,V]=(0,a.useState)({...l,modifications:C}),[_,A]=(0,a.useState)();function k(e){const t={isSdkReady:e.isSdkReady,isLoading:e.isLoading,isVisitorDefined:!!e.fsVisitor,lastRefresh:(new Date).toISOString()};return V((i=>(i.status.firstInitSuccess||(t.firstInitSuccess=(new Date).toISOString()),{...i,visitor:e.fsVisitor,modifications:e.fsVisitor.modifications,config:o.Flagship.getConfig(),status:{...i.status,...t}}))),t}(0,a.useRef)().current=E,(0,n.useNonInitialEffect)((()=>{var e;m&&(null===(e=E.visitor)||void 0===e||e.fetchFlags())}),[_]),(0,n.useNonInitialEffect)((()=>{I(!0)}),[JSON.stringify(f)]),(0,a.useEffect)((()=>{S()}),[i,s,r]);const I=(e=!1)=>{if(!f)return;const i=o.Flagship.newVisitor({visitorId:f.id,context:f.context,isAuthenticated:f.isAuthenticated,hasConsented:f.hasConsented,initialCampaigns:h,initialModifications:M,initialFlagsData:x});null==i||i.on("ready",(e=>{((e,t)=>{if(t)return void(0,n.logError)(o.Flagship.getConfig(),t.message||t,"onReady");const i=k({fsVisitor:e,isSdkReady:!0,isLoading:!1});y&&y({fsModifications:e.modifications,config:o.Flagship.getConfig(),status:i})})(i,e)})),t||!i||e||k({fsVisitor:i,isSdkReady:!0,isLoading:!1}),e&&!t&&(null==i||i.fetchFlags())},O=e=>{switch(p&&p(e),e){case o.FlagshipStatus.STARTING:e===o.FlagshipStatus.STARTING&&c&&c();break;case o.FlagshipStatus.READY_PANIC_ON:case o.FlagshipStatus.READY:d&&d(),I();break;case o.FlagshipStatus.NOT_INITIALIZED:V((e=>({...e,status:{...e.status,isLoading:!1},config:o.Flagship.getConfig()})))}},R=e=>{v&&v(e),A(e)},S=()=>{o.Flagship.start(i,s,{decisionMode:r,fetchNow:t,statusChangedCallback:O,onBucketingUpdated:R,...F})};return a.default.createElement(u.Provider,{value:{state:E,setState:V}},(()=>{const i=!E.visitor;return E.status.isLoading&&g&&i&&t?a.default.createElement(a.default.Fragment,null,g):a.default.createElement(a.default.Fragment,null,e)})())};t.FlagshipProvider=f,f.defaultProps={hitDeduplicationTime:2,fetchNow:!0,language:1,sdkVersion:s.version}},460:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.useFlagship=t.useFsActivate=t.useFsFlag=t.useFsModificationInfo=t.useFsModification=t.useFsModifications=void 0,i(117);var a,o=i(689),n=(a=i(4))&&a.__esModule?a:{default:a},s=i(821),r=i(370),l=i(161),u=i(147);const f=(e,t)=>"object"==typeof e&&"object"==typeof t&&Array.isArray(e)===Array.isArray(t)||typeof e==typeof t,c=e=>{const{visitor:t,params:i,activateAll:a,state:o,functionName:n,config:s}=e;if(t)return t.getModificationsSync(i,a);const l=!o.status.isSdkReady&&!!o.modifications&&o.modifications.size>0,c={};return l?(i.forEach((e=>{var t;const i=null===(t=o.modifications)||void 0===t?void 0:t.get(e.key);i&&f(null==i?void 0:i.value,e.defaultValue)?c[e.key]=i.value:c[e.key]=e.defaultValue})),c):((0,r.logWarn)(s,u.noVisitorDefault,n),i.forEach((e=>{c[e.key]=e.defaultValue})),c)};t.useFsModifications=(e,t)=>{const{state:i}=(0,o.useContext)(s.FlagshipContext),{visitor:a,config:n}=i;return c({functionName:"useFsModifications",state:i,visitor:a,config:n,params:e,activateAll:t})},t.useFsModification=e=>{var t;const{state:i}=(0,o.useContext)(s.FlagshipContext),{visitor:a,config:n}=i;if(a)return a.getModificationSync(e);const l=null===(t=i.modifications)||void 0===t?void 0:t.get(e.key);return!i.status.isSdkReady&&l&&f(null==l?void 0:l.value,e.defaultValue)?l.value:((0,r.logWarn)(n,u.noVisitorDefault,"useFsModifications"),e.defaultValue)};const d=e=>{var t;const{key:i,visitor:a,state:o}=e;if(a)return a.getModificationInfoSync(i);const n=null===(t=o.modifications)||void 0===t?void 0:t.get(i);return!o.status.isSdkReady&&n?n:null};t.useFsModificationInfo=e=>{const{state:t}=(0,o.useContext)(s.FlagshipContext),{visitor:i}=t;return d({key:e,state:t,visitor:i})};const g=async(e,t,i,a)=>{try{if(!i)return void(0,r.logWarn)(a,u.noVisitorMessage,t);await i.activateModifications(e)}catch(e){(0,r.logWarn)(a,e.message||e,t)}};t.useFsFlag=(e,t)=>{const{state:i}=(0,o.useContext)(s.FlagshipContext),{visitor:a}=i;return a?a.getFlag(e,t):new l.Flag(t,e,i.modifications)},t.useFsActivate=async e=>{const{state:t}=(0,o.useContext)(s.FlagshipContext),{visitor:i,config:a}=t;await g(e,"useFsModifications",i,a)},t.useFlagship=()=>{const{state:e}=(0,o.useContext)(s.FlagshipContext),{visitor:t,config:i}=e;let a=null==t?void 0:t.getModificationsArray();return!e.status.isSdkReady&&e.modifications&&(a=Array.from(e.modifications,(([e,t])=>t))),{visitorId:null==t?void 0:t.visitorId,anonymousId:null==t?void 0:t.anonymousId,context:{...null==t?void 0:t.context},hasConsented:null==t?void 0:t.hasConsented,setConsent:function(e){t?t.setConsent(e):(0,r.logWarn)(i,u.noVisitorMessage,"setConsent")},updateContext:e=>{t?(t.clearContext(),t.updateContext(e)):(0,r.logError)(i,u.noVisitorMessage,"updateContext")},clearContext:()=>{t?t.clearContext():(0,r.logError)(i,u.noVisitorMessage,"cleanContext")},authenticate:e=>{t?t.authenticate(e):(0,r.logError)(i,u.noVisitorMessage,"authenticate")},unauthenticate:()=>{t?t.unauthenticate():(0,r.logError)(i,u.noVisitorMessage,"unauthenticate")},status:e.status,activateModification:async e=>{await g(e,"activateModification",t,i)},synchronizeModifications:async()=>{t?await t.synchronizeModifications():(0,r.logWarn)(i,u.noVisitorMessage,"synchronizeModifications")},getModifications:(a,o)=>c({functionName:"getModifications",state:e,visitor:t,config:i,params:a,activateAll:o}),modifications:a||[],flagsData:(null==t?void 0:t.getFlagsDataArray())||[],getModificationInfo:i=>d({key:i,state:e,visitor:t}),hit:{send:e=>t?t.sendHit(e):((0,r.logError)(i,u.noVisitorMessage,"sendHit"),Promise.resolve()),sendMultiple:e=>t?t.sendHits(e):((0,r.logError)(i,u.noVisitorMessage,"sendHits"),Promise.resolve())},getFlag:function(i,a){return t?t.getFlag(i,a):new l.Flag(a,i,e.modifications)},fetchFlags:function(){return t?t.fetchFlags():((0,r.logWarn)(i,u.noVisitorMessage,"fetchFlags"),Promise.resolve())},close:async function(){await n.default.close()}}}},147:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.GET_METADATA_CAST_ERROR=t.GET_FLAG_CAST_ERROR=t.noVisitorDefault=t.noVisitorMessage=void 0,t.noVisitorMessage="flagship Visitor not initialized.",t.noVisitorDefault="fsVisitor not initialized, returns default value",t.GET_FLAG_CAST_ERROR="Flag for key {0} has a different type. Default value is returned.",t.GET_METADATA_CAST_ERROR="Flag for key {0} has a different type with defaultValue, an empty metadata object is returned"},231:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0});var a=i(821);Object.keys(a).forEach((function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===a[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return a[e]}}))}));var o=i(4);Object.keys(o).forEach((function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===o[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return o[e]}}))}));var n=i(460);Object.keys(n).forEach((function(e){"default"!==e&&"__esModule"!==e&&(e in t&&t[e]===n[e]||Object.defineProperty(t,e,{enumerable:!0,get:function(){return n[e]}}))}))},359:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.version=void 0,t.version="3.1.0-alpha.1"},370:(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.logError=function(e,t,i){e&&e.logManager&&"function"==typeof e.logManager.error&&e.logLevel&&!(e.logLevel<a.LogLevel.ERROR)&&e.logManager.error(t,i)},t.logInfo=function(e,t,i){e&&e.logManager&&"function"==typeof e.logManager.info&&e.logLevel&&!(e.logLevel<a.LogLevel.INFO)&&e.logManager.info(t,i)},t.logWarn=function(e,t,i){e&&e.logManager&&"function"==typeof e.logManager.warning&&e.logLevel&&!(e.logLevel<a.LogLevel.WARNING)&&e.logManager.warning(t,i)},t.uuidV4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)}))},t.useNonInitialEffect=function(e,t){const i=(0,o.useRef)(!0);(0,o.useEffect)((()=>{if(!i.current)return"function"==typeof e?e():void 0;i.current=!1}),t)},t.hasSameType=function(e,t){return typeof e==typeof t&&("object"!=typeof e||"object"!=typeof t||Array.isArray(e)===Array.isArray(t))},t.sprintf=function(e,...t){let i=e;for(let e=0;e<t.length;e++){const a=t[e];i=i.replace(new RegExp(`\\{${e}\\}`,"g"),a)}return i},t.getModificationsFromCampaigns=void 0;var a=i(4),o=i(689);t.getModificationsFromCampaigns=e=>{const t=new Map;return e&&Array.isArray(e)?(e.forEach((e=>{const i=e.variation.modifications.value;for(const a in i){const o=i[a];t.set(a,{key:a,campaignId:e.id,variationGroupId:e.variationGroupId,variationId:e.variation.id,isReference:e.variation.reference,value:o})}})),t):t}},4:e=>{e.exports=require("@flagship.io/js-sdk")},117:e=>{e.exports=require("core-js/modules/es.promise.js")},689:e=>{e.exports=require("react")}},t={},i=function i(a){var o=t[a];if(void 0!==o)return o.exports;var n=t[a]={exports:{}};return e[a](n,n.exports,i),n.exports}(231);module.exports=i})();
1066
2
  //# sourceMappingURL=index.node.js.map