@flagship.io/react-sdk 3.0.13 → 3.1.0-beta.0

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,1058 +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
- activateDeduplicationTime: 2,
358
- hitDeduplicationTime: 2,
359
- fetchNow: true,
360
- language: 1,
361
- sdkVersion: _sdkVersion.version
362
- };
363
-
364
- /***/ }),
365
-
366
- /***/ "./src/FlagshipHooks.tsx":
367
- /*!*******************************!*\
368
- !*** ./src/FlagshipHooks.tsx ***!
369
- \*******************************/
370
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
371
-
372
-
373
-
374
- Object.defineProperty(exports, "__esModule", ({
375
- value: true
376
- }));
377
- exports.useFlagship = exports.useFsActivate = exports.useFsFlag = exports.useFsModificationInfo = exports.useFsModification = exports.useFsModifications = void 0;
378
-
379
- __webpack_require__(/*! core-js/modules/es.promise.js */ "core-js/modules/es.promise.js");
380
-
381
- var _react = __webpack_require__(/*! react */ "react");
382
-
383
- var _FlagshipContext = __webpack_require__(/*! ./FlagshipContext */ "./src/FlagshipContext.tsx");
384
-
385
- var _utils = __webpack_require__(/*! ./utils */ "./src/utils.tsx");
386
-
387
- var _Flag = __webpack_require__(/*! ./Flag */ "./src/Flag.ts");
388
-
389
- var _constants = __webpack_require__(/*! ./constants */ "./src/constants.ts");
390
-
391
- const checkType = (value, defaultValue) => typeof value === 'object' && typeof defaultValue === 'object' && Array.isArray(value) === Array.isArray(defaultValue) || typeof value === typeof defaultValue;
392
-
393
- const fsModificationsSync = args => {
394
- const {
395
- visitor,
396
- params,
397
- activateAll,
398
- state,
399
- functionName,
400
- config
401
- } = args;
402
-
403
- if (visitor) {
404
- return visitor.getModificationsSync(params, activateAll);
405
- }
406
-
407
- const check = !state.status.isSdkReady && !!state.modifications && state.modifications.size > 0;
408
- const flags = {};
409
-
410
- if (check) {
411
- params.forEach(item => {
412
- var _state$modifications;
413
-
414
- const modification = (_state$modifications = state.modifications) === null || _state$modifications === void 0 ? void 0 : _state$modifications.get(item.key);
415
-
416
- if (modification && checkType(modification === null || modification === void 0 ? void 0 : modification.value, item.defaultValue)) {
417
- flags[item.key] = modification.value;
418
- } else {
419
- flags[item.key] = item.defaultValue;
420
- }
421
- });
422
- return flags;
423
- }
424
-
425
- (0, _utils.logWarn)(config, _constants.noVisitorDefault, functionName);
426
- params.forEach(item => {
427
- flags[item.key] = item.defaultValue;
428
- });
429
- return flags;
430
- };
431
- /**
432
- * 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.
433
- * @deprecated use useFsFlag instead
434
- */
435
-
436
-
437
- const useFsModifications = (params, activateAll) => {
438
- const {
439
- state
440
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
441
- const {
442
- visitor,
443
- config
444
- } = state;
445
- const functionName = 'useFsModifications';
446
- return fsModificationsSync({
447
- functionName,
448
- state,
449
- visitor,
450
- config,
451
- params,
452
- activateAll
453
- });
454
- };
455
- /**
456
- * 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.
457
- * @deprecated use useFsFlag instead
458
- */
459
-
460
-
461
- exports.useFsModifications = useFsModifications;
462
-
463
- const useFsModification = params => {
464
- var _state$modifications2;
465
-
466
- const {
467
- state
468
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
469
- const {
470
- visitor,
471
- config
472
- } = state;
473
- const functionName = 'useFsModifications';
474
-
475
- if (visitor) {
476
- return visitor.getModificationSync(params);
477
- }
478
-
479
- const modification = (_state$modifications2 = state.modifications) === null || _state$modifications2 === void 0 ? void 0 : _state$modifications2.get(params.key);
480
-
481
- if (!state.status.isSdkReady && modification && checkType(modification === null || modification === void 0 ? void 0 : modification.value, params.defaultValue)) {
482
- return modification.value;
483
- }
484
-
485
- (0, _utils.logWarn)(config, _constants.noVisitorDefault, functionName);
486
- return params.defaultValue;
487
- };
488
-
489
- exports.useFsModification = useFsModification;
490
-
491
- const fsModificationInfoSync = args => {
492
- var _state$modifications3;
493
-
494
- const {
495
- key,
496
- visitor,
497
- state
498
- } = args;
499
-
500
- if (visitor) {
501
- return visitor.getModificationInfoSync(key);
502
- }
503
-
504
- const modification = (_state$modifications3 = state.modifications) === null || _state$modifications3 === void 0 ? void 0 : _state$modifications3.get(key);
505
-
506
- if (!state.status.isSdkReady && modification) {
507
- return modification;
508
- }
509
-
510
- return null;
511
- };
512
- /**
513
- * Get the campaign modification information value matching the given key.
514
- * @param {string} key key which identify the modification.
515
- * @deprecated use useFsFlag instead
516
- */
517
-
518
-
519
- const useFsModificationInfo = key => {
520
- const {
521
- state
522
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
523
- const {
524
- visitor
525
- } = state;
526
- return fsModificationInfoSync({
527
- key,
528
- state,
529
- visitor
530
- });
531
- };
532
-
533
- exports.useFsModificationInfo = useFsModificationInfo;
534
-
535
- const fsActivate = async (params, functionName, visitor, config) => {
536
- try {
537
- if (!visitor) {
538
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, functionName);
539
- return;
540
- }
541
-
542
- await visitor.activateModifications(params); // eslint-disable-next-line @typescript-eslint/no-explicit-any
543
- } catch (error) {
544
- (0, _utils.logWarn)(config, error.message || error, functionName);
545
- }
546
- };
547
- /**
548
- * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
549
- * @param key
550
- * @param defaultValue
551
- * @returns
552
- */
553
-
554
-
555
- const useFsFlag = (key, defaultValue) => {
556
- const {
557
- state
558
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
559
- const {
560
- visitor
561
- } = state;
562
-
563
- if (!visitor) {
564
- return new _Flag.Flag(defaultValue, key, state.modifications);
565
- }
566
-
567
- return visitor.getFlag(key, defaultValue);
568
- };
569
- /**
570
- * Report this user has seen this modification. Report this user has seen these modifications.
571
- * @param params
572
- * @deprecated use useFsFlag instead
573
- * @returns
574
- */
575
-
576
-
577
- exports.useFsFlag = useFsFlag;
578
-
579
- const useFsActivate = async params => {
580
- const {
581
- state
582
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
583
- const {
584
- visitor,
585
- config
586
- } = state;
587
- const functionName = 'useFsModifications';
588
- await fsActivate(params, functionName, visitor, config);
589
- };
590
-
591
- exports.useFsActivate = useFsActivate;
592
-
593
- const useFlagship = () => {
594
- const {
595
- state
596
- } = (0, _react.useContext)(_FlagshipContext.FlagshipContext);
597
- const {
598
- visitor,
599
- config
600
- } = state;
601
-
602
- const fsUpdateContext = context => {
603
- const functionName = 'updateContext';
604
-
605
- if (!visitor) {
606
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
607
- return;
608
- }
609
-
610
- visitor.clearContext();
611
- visitor.updateContext(context);
612
- };
613
-
614
- const fsClearContext = () => {
615
- const functionName = 'cleanContext';
616
-
617
- if (!visitor) {
618
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
619
- return;
620
- }
621
-
622
- visitor.clearContext();
623
- };
624
-
625
- const fsAuthenticate = visitorId => {
626
- const functionName = 'authenticate';
627
-
628
- if (!visitor) {
629
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
630
- return;
631
- }
632
-
633
- visitor.authenticate(visitorId);
634
- };
635
-
636
- const fsUnauthenticate = () => {
637
- const functionName = 'unauthenticate';
638
-
639
- if (!visitor) {
640
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
641
- return;
642
- }
643
-
644
- visitor.unauthenticate();
645
- };
646
- /**
647
- * Send a Hit to Flagship servers for reporting.
648
- */
649
-
650
-
651
- const fsSendHit = hit => {
652
- const functionName = 'sendHit';
653
-
654
- if (!visitor) {
655
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
656
- return Promise.resolve();
657
- }
658
-
659
- return visitor.sendHit(hit);
660
- };
661
- /**
662
- * Send a Hit to Flagship servers for reporting.
663
- */
664
-
665
-
666
- const fsSendHits = hit => {
667
- const functionName = 'sendHits';
668
-
669
- if (!visitor) {
670
- (0, _utils.logError)(config, _constants.noVisitorMessage, functionName);
671
- return Promise.resolve();
672
- }
673
-
674
- return visitor.sendHits(hit);
675
- };
676
-
677
- let modifications = visitor === null || visitor === void 0 ? void 0 : visitor.getModificationsArray();
678
-
679
- if (!state.status.isSdkReady && state.modifications) {
680
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
681
- modifications = Array.from(state.modifications, ([_key, item]) => item);
682
- }
683
-
684
- const activateModification = async params => {
685
- const functionName = 'activateModification';
686
- await fsActivate(params, functionName, visitor, config);
687
- };
688
-
689
- const synchronizeModifications = async () => {
690
- if (!visitor) {
691
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'synchronizeModifications');
692
- return;
693
- }
694
-
695
- await visitor.synchronizeModifications();
696
- };
697
-
698
- const getModifications = (params, activateAll) => {
699
- const functionName = 'getModifications';
700
- return fsModificationsSync({
701
- functionName,
702
- state,
703
- visitor,
704
- config,
705
- params,
706
- activateAll
707
- });
708
- };
709
-
710
- const getModificationInfo = key => {
711
- return fsModificationInfoSync({
712
- key,
713
- state,
714
- visitor
715
- });
716
- };
717
-
718
- function getFlag(key, defaultValue) {
719
- if (!visitor) {
720
- return new _Flag.Flag(defaultValue, key, state.modifications);
721
- }
722
-
723
- return visitor.getFlag(key, defaultValue);
724
- }
725
-
726
- function fetchFlags() {
727
- if (!visitor) {
728
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'fetchFlags');
729
- return Promise.resolve();
730
- }
731
-
732
- return visitor.fetchFlags();
733
- }
734
-
735
- function setConsent(hasConsented) {
736
- if (!visitor) {
737
- (0, _utils.logWarn)(config, _constants.noVisitorMessage, 'setConsent');
738
- return;
739
- }
740
-
741
- visitor.setConsent(hasConsented);
742
- }
743
-
744
- return {
745
- visitorId: visitor === null || visitor === void 0 ? void 0 : visitor.visitorId,
746
- anonymousId: visitor === null || visitor === void 0 ? void 0 : visitor.anonymousId,
747
- context: { ...(visitor === null || visitor === void 0 ? void 0 : visitor.context)
748
- },
749
- hasConsented: visitor === null || visitor === void 0 ? void 0 : visitor.hasConsented,
750
- setConsent,
751
- updateContext: fsUpdateContext,
752
- clearContext: fsClearContext,
753
- authenticate: fsAuthenticate,
754
- unauthenticate: fsUnauthenticate,
755
- status: state.status,
756
- activateModification,
757
- synchronizeModifications,
758
- getModifications,
759
- modifications: modifications || [],
760
- flagsData: (visitor === null || visitor === void 0 ? void 0 : visitor.getFlagsDataArray()) || [],
761
- getModificationInfo,
762
- hit: {
763
- send: fsSendHit,
764
- sendMultiple: fsSendHits
765
- },
766
- getFlag,
767
- fetchFlags
768
- };
769
- };
770
-
771
- exports.useFlagship = useFlagship;
772
-
773
- /***/ }),
774
-
775
- /***/ "./src/constants.ts":
776
- /*!**************************!*\
777
- !*** ./src/constants.ts ***!
778
- \**************************/
779
- /***/ ((__unused_webpack_module, exports) => {
780
-
781
-
782
-
783
- Object.defineProperty(exports, "__esModule", ({
784
- value: true
785
- }));
786
- exports.GET_METADATA_CAST_ERROR = exports.GET_FLAG_CAST_ERROR = exports.noVisitorDefault = exports.noVisitorMessage = void 0;
787
- const noVisitorMessage = 'flagship Visitor not initialized.';
788
- exports.noVisitorMessage = noVisitorMessage;
789
- const noVisitorDefault = 'fsVisitor not initialized, returns default value';
790
- exports.noVisitorDefault = noVisitorDefault;
791
- const GET_FLAG_CAST_ERROR = 'Flag for key {0} has a different type. Default value is returned.';
792
- exports.GET_FLAG_CAST_ERROR = GET_FLAG_CAST_ERROR;
793
- const GET_METADATA_CAST_ERROR = 'Flag for key {0} has a different type with defaultValue, an empty metadata object is returned';
794
- exports.GET_METADATA_CAST_ERROR = GET_METADATA_CAST_ERROR;
795
-
796
- /***/ }),
797
-
798
- /***/ "./src/index.tsx":
799
- /*!***********************!*\
800
- !*** ./src/index.tsx ***!
801
- \***********************/
802
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
803
-
804
-
805
-
806
- Object.defineProperty(exports, "__esModule", ({
807
- value: true
808
- }));
809
-
810
- var _FlagshipContext = __webpack_require__(/*! ./FlagshipContext */ "./src/FlagshipContext.tsx");
811
-
812
- Object.keys(_FlagshipContext).forEach(function (key) {
813
- if (key === "default" || key === "__esModule") return;
814
- if (key in exports && exports[key] === _FlagshipContext[key]) return;
815
- Object.defineProperty(exports, key, {
816
- enumerable: true,
817
- get: function () {
818
- return _FlagshipContext[key];
819
- }
820
- });
821
- });
822
-
823
- var _jsSdk = __webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk");
824
-
825
- Object.keys(_jsSdk).forEach(function (key) {
826
- if (key === "default" || key === "__esModule") return;
827
- if (key in exports && exports[key] === _jsSdk[key]) return;
828
- Object.defineProperty(exports, key, {
829
- enumerable: true,
830
- get: function () {
831
- return _jsSdk[key];
832
- }
833
- });
834
- });
835
-
836
- var _FlagshipHooks = __webpack_require__(/*! ./FlagshipHooks */ "./src/FlagshipHooks.tsx");
837
-
838
- Object.keys(_FlagshipHooks).forEach(function (key) {
839
- if (key === "default" || key === "__esModule") return;
840
- if (key in exports && exports[key] === _FlagshipHooks[key]) return;
841
- Object.defineProperty(exports, key, {
842
- enumerable: true,
843
- get: function () {
844
- return _FlagshipHooks[key];
845
- }
846
- });
847
- });
848
-
849
- /***/ }),
850
-
851
- /***/ "./src/sdkVersion.ts":
852
- /*!***************************!*\
853
- !*** ./src/sdkVersion.ts ***!
854
- \***************************/
855
- /***/ ((__unused_webpack_module, exports) => {
856
-
857
-
858
-
859
- Object.defineProperty(exports, "__esModule", ({
860
- value: true
861
- }));
862
- exports.version = void 0;
863
- // Generated by genversion.
864
- const version = '3.0.13';
865
- exports.version = version;
866
-
867
- /***/ }),
868
-
869
- /***/ "./src/utils.tsx":
870
- /*!***********************!*\
871
- !*** ./src/utils.tsx ***!
872
- \***********************/
873
- /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
874
-
875
-
876
-
877
- Object.defineProperty(exports, "__esModule", ({
878
- value: true
879
- }));
880
- exports.logError = logError;
881
- exports.logInfo = logInfo;
882
- exports.logWarn = logWarn;
883
- exports.uuidV4 = uuidV4;
884
- exports.useNonInitialEffect = useNonInitialEffect;
885
- exports.hasSameType = hasSameType;
886
- exports.sprintf = sprintf;
887
- exports.getModificationsFromCampaigns = void 0;
888
-
889
- var _jsSdk = __webpack_require__(/*! @flagship.io/js-sdk */ "@flagship.io/js-sdk");
890
-
891
- var _react = __webpack_require__(/*! react */ "react");
892
-
893
- function logError(config, message, tag) {
894
- if (!config || !config.logManager || typeof config.logManager.error !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.ERROR) {
895
- return;
896
- }
897
-
898
- config.logManager.error(message, tag);
899
- }
900
-
901
- function logInfo(config, message, tag) {
902
- if (!config || !config.logManager || typeof config.logManager.info !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.INFO) {
903
- return;
904
- }
905
-
906
- config.logManager.info(message, tag);
907
- }
908
-
909
- function logWarn(config, message, tag) {
910
- if (!config || !config.logManager || typeof config.logManager.warning !== 'function' || !config.logLevel || config.logLevel < _jsSdk.LogLevel.WARNING) {
911
- return;
912
- }
913
-
914
- config.logManager.warning(message, tag);
915
- }
916
-
917
- const getModificationsFromCampaigns = campaigns => {
918
- const modifications = new Map();
919
-
920
- if (!campaigns || !Array.isArray(campaigns)) {
921
- return modifications;
922
- }
923
-
924
- campaigns.forEach(campaign => {
925
- const object = campaign.variation.modifications.value;
926
-
927
- for (const key in object) {
928
- const value = object[key];
929
- modifications.set(key, {
930
- key,
931
- campaignId: campaign.id,
932
- variationGroupId: campaign.variationGroupId,
933
- variationId: campaign.variation.id,
934
- isReference: campaign.variation.reference,
935
- value
936
- });
937
- }
938
- });
939
- return modifications;
940
- };
941
-
942
- exports.getModificationsFromCampaigns = getModificationsFromCampaigns;
943
-
944
- function uuidV4() {
945
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (char) {
946
- const rand = Math.random() * 16 | 0;
947
- const value = char === 'x' ? rand : rand & 0x3 | 0x8;
948
- return value.toString(16);
949
- });
950
- }
951
-
952
- function useNonInitialEffect(effect, deps) {
953
- const initialRender = (0, _react.useRef)(true);
954
- (0, _react.useEffect)(() => {
955
- if (initialRender.current) {
956
- initialRender.current = false;
957
- return;
958
- }
959
-
960
- if (typeof effect === 'function') {
961
- return effect();
962
- }
963
- }, deps);
964
- }
965
-
966
- function hasSameType(flagValue, defaultValue) {
967
- if (typeof flagValue !== typeof defaultValue) {
968
- return false;
969
- }
970
-
971
- if (typeof flagValue === 'object' && typeof defaultValue === 'object' && Array.isArray(flagValue) !== Array.isArray(defaultValue)) {
972
- return false;
973
- }
974
-
975
- return true;
976
- } // eslint-disable-next-line @typescript-eslint/no-explicit-any
977
-
978
-
979
- function sprintf(format, ...value) {
980
- let formatted = format;
981
-
982
- for (let i = 0; i < value.length; i++) {
983
- const element = value[i];
984
- formatted = formatted.replace(new RegExp(`\\{${i}\\}`, 'g'), element);
985
- }
986
-
987
- return formatted;
988
- }
989
-
990
- /***/ }),
991
-
992
- /***/ "@flagship.io/js-sdk":
993
- /*!**************************************!*\
994
- !*** external "@flagship.io/js-sdk" ***!
995
- \**************************************/
996
- /***/ ((module) => {
997
-
998
- module.exports = require("@flagship.io/js-sdk");
999
-
1000
- /***/ }),
1001
-
1002
- /***/ "core-js/modules/es.promise.js":
1003
- /*!************************************************!*\
1004
- !*** external "core-js/modules/es.promise.js" ***!
1005
- \************************************************/
1006
- /***/ ((module) => {
1007
-
1008
- module.exports = require("core-js/modules/es.promise.js");
1009
-
1010
- /***/ }),
1011
-
1012
- /***/ "react":
1013
- /*!************************!*\
1014
- !*** external "react" ***!
1015
- \************************/
1016
- /***/ ((module) => {
1017
-
1018
- module.exports = require("react");
1019
-
1020
- /***/ })
1021
-
1022
- /******/ });
1023
- /************************************************************************/
1024
- /******/ // The module cache
1025
- /******/ var __webpack_module_cache__ = {};
1026
- /******/
1027
- /******/ // The require function
1028
- /******/ function __webpack_require__(moduleId) {
1029
- /******/ // Check if module is in cache
1030
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
1031
- /******/ if (cachedModule !== undefined) {
1032
- /******/ return cachedModule.exports;
1033
- /******/ }
1034
- /******/ // Create a new module (and put it into the cache)
1035
- /******/ var module = __webpack_module_cache__[moduleId] = {
1036
- /******/ // no module.id needed
1037
- /******/ // no module.loaded needed
1038
- /******/ exports: {}
1039
- /******/ };
1040
- /******/
1041
- /******/ // Execute the module function
1042
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
1043
- /******/
1044
- /******/ // Return the exports of the module
1045
- /******/ return module.exports;
1046
- /******/ }
1047
- /******/
1048
- /************************************************************************/
1049
- /******/
1050
- /******/ // startup
1051
- /******/ // Load entry module and return exports
1052
- /******/ // This entry module is referenced by other modules so it can't be inlined
1053
- /******/ var __webpack_exports__ = __webpack_require__("./src/index.tsx");
1054
- /******/ module.exports = __webpack_exports__;
1055
- /******/
1056
- /******/ })()
1057
- ;
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)((()=>{b()}),[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)},b=()=>{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-beta.0"},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})();
1058
2
  //# sourceMappingURL=index.node.js.map