@flagship.io/react-sdk 3.0.10-alpha.0 → 3.0.10

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