@flagship.io/react-sdk 3.1.1-alpha.2 → 3.1.2

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