@flagship.io/react-sdk 3.0.1 → 3.0.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FlagshipContext.d.ts +99 -0
- package/dist/FlagshipContext.js +312 -0
- package/dist/FlagshipContext.js.map +1 -0
- package/dist/FlagshipErrorBoundary.d.ts +34 -0
- package/dist/FlagshipErrorBoundary.js +95 -0
- package/dist/FlagshipErrorBoundary.js.map +1 -0
- package/dist/FlagshipHooks.d.ts +33 -0
- package/dist/FlagshipHooks.js +198 -0
- package/dist/FlagshipHooks.js.map +1 -0
- package/dist/components/ReactErrorBoundaryContainer/index.d.ts +10 -0
- package/dist/components/ReactErrorBoundaryContainer/index.js +65 -0
- package/dist/components/ReactErrorBoundaryContainer/index.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +0 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/loggerHelper.d.ts +5 -0
- package/dist/lib/loggerHelper.js +14 -0
- package/dist/lib/loggerHelper.js.map +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.js +7 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/setupTests.d.ts +1 -0
- package/dist/setupTests.js +9 -0
- package/dist/setupTests.js.map +1 -0
- package/dist/tests/mock/apiAnswers/oneModifInMoreThanOneCampaign.d.ts +3 -0
- package/dist/tests/mock/apiAnswers/oneModifInMoreThanOneCampaign.js +51 -0
- package/dist/tests/mock/apiAnswers/oneModifInMoreThanOneCampaign.js.map +1 -0
- package/dist/tests/mock/env.d.ts +5 -0
- package/dist/tests/mock/env.js +8 -0
- package/dist/tests/mock/env.js.map +1 -0
- package/dist/tests/mock/index.d.ts +74 -0
- package/dist/tests/mock/index.js +90 -0
- package/dist/tests/mock/index.js.map +1 -0
- package/package.json +2 -2
- package/dist/es/Flag.js +0 -36
- package/dist/es/FlagshipContext.js +0 -229
- package/dist/es/FlagshipHooks.js +0 -372
- package/dist/es/constants.js +0 -2
- package/dist/es/index.js +0 -3
- package/dist/es/utils.js +0 -77
- package/dist/esm/Flag.js +0 -55
- package/dist/esm/FlagshipContext.js +0 -253
- package/dist/esm/FlagshipHooks.js +0 -474
- package/dist/esm/constants.js +0 -2
- package/dist/esm/index.js +0 -3
- package/dist/esm/utils.js +0 -77
- package/dist/index.browser.js +0 -2
- package/dist/index.browser.js.map +0 -1
- package/dist/types/Flag.d.ts +0 -9
- package/dist/types/FlagshipContext.d.ts +0 -97
- package/dist/types/FlagshipHooks.d.ts +0 -130
- package/dist/types/constants.d.ts +0 -2
- package/dist/types/utils.d.ts +0 -9
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { FlagshipSdkConfig } from '@flagship.io/js-sdk';
|
|
3
|
+
import { FsState } from '../../FlagshipContext';
|
|
4
|
+
export declare const apiAnswers: {
|
|
5
|
+
oneModifInMoreThanOneCampaign: import("@flagship.io/js-sdk").DecisionApiResponseData;
|
|
6
|
+
};
|
|
7
|
+
export declare const defaultConfig: FlagshipSdkConfig;
|
|
8
|
+
export declare const DefaultLoadingComponent: React.SFC;
|
|
9
|
+
export declare const defaultContext: {
|
|
10
|
+
hasError: boolean;
|
|
11
|
+
state: FsState;
|
|
12
|
+
};
|
|
13
|
+
export declare const anonymousIdForTest = "anonymousTest";
|
|
14
|
+
export declare const providerProps: {
|
|
15
|
+
visitorData: {
|
|
16
|
+
id: string;
|
|
17
|
+
context: {
|
|
18
|
+
isAuth: boolean;
|
|
19
|
+
isVip: boolean;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
config: {
|
|
23
|
+
fetchNow: boolean;
|
|
24
|
+
enableConsoleLogs: boolean;
|
|
25
|
+
enableSafeMode: boolean;
|
|
26
|
+
enableErrorLayout: boolean;
|
|
27
|
+
nodeEnv: string;
|
|
28
|
+
apiKey: string;
|
|
29
|
+
};
|
|
30
|
+
envId: string;
|
|
31
|
+
};
|
|
32
|
+
export declare const fetchedModifications: ({
|
|
33
|
+
id: string;
|
|
34
|
+
slug: null;
|
|
35
|
+
type: string;
|
|
36
|
+
variation: {
|
|
37
|
+
id: string;
|
|
38
|
+
modifications: {
|
|
39
|
+
type: string;
|
|
40
|
+
value: {
|
|
41
|
+
array: number[];
|
|
42
|
+
complex: {
|
|
43
|
+
carray: {
|
|
44
|
+
cobject: number;
|
|
45
|
+
}[];
|
|
46
|
+
};
|
|
47
|
+
object: {
|
|
48
|
+
value: number;
|
|
49
|
+
};
|
|
50
|
+
discount?: undefined;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
reference: boolean;
|
|
54
|
+
};
|
|
55
|
+
variationGroupId: string;
|
|
56
|
+
} | {
|
|
57
|
+
id: string;
|
|
58
|
+
slug: null;
|
|
59
|
+
type: string;
|
|
60
|
+
variation: {
|
|
61
|
+
id: string;
|
|
62
|
+
modifications: {
|
|
63
|
+
type: string;
|
|
64
|
+
value: {
|
|
65
|
+
discount: string;
|
|
66
|
+
array?: undefined;
|
|
67
|
+
complex?: undefined;
|
|
68
|
+
object?: undefined;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
reference: boolean;
|
|
72
|
+
};
|
|
73
|
+
variationGroupId: string;
|
|
74
|
+
})[];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fetchedModifications = exports.providerProps = exports.anonymousIdForTest = exports.defaultContext = exports.DefaultLoadingComponent = exports.defaultConfig = exports.apiAnswers = void 0;
|
|
7
|
+
var react_1 = __importDefault(require("react"));
|
|
8
|
+
var oneModifInMoreThanOneCampaign_1 = __importDefault(require("./apiAnswers/oneModifInMoreThanOneCampaign"));
|
|
9
|
+
var env_1 = require("./env");
|
|
10
|
+
exports.apiAnswers = {
|
|
11
|
+
oneModifInMoreThanOneCampaign: oneModifInMoreThanOneCampaign_1.default
|
|
12
|
+
};
|
|
13
|
+
exports.defaultConfig = {};
|
|
14
|
+
exports.DefaultLoadingComponent = function () { return react_1.default.createElement("div", null, "Loading Flagship React SDK"); };
|
|
15
|
+
exports.defaultContext = {
|
|
16
|
+
hasError: false,
|
|
17
|
+
state: {
|
|
18
|
+
fsSdk: null,
|
|
19
|
+
fsVisitor: null,
|
|
20
|
+
log: null,
|
|
21
|
+
fsModifications: null,
|
|
22
|
+
status: {
|
|
23
|
+
isSdkReady: false,
|
|
24
|
+
isLoading: true,
|
|
25
|
+
isVisitorDefined: false,
|
|
26
|
+
lastRefresh: null,
|
|
27
|
+
firstInitSuccess: null,
|
|
28
|
+
hasError: false
|
|
29
|
+
},
|
|
30
|
+
private: {
|
|
31
|
+
previousFetchedModifications: undefined
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.anonymousIdForTest = 'anonymousTest';
|
|
36
|
+
exports.providerProps = {
|
|
37
|
+
visitorData: {
|
|
38
|
+
id: env_1.vId,
|
|
39
|
+
context: { isAuth: true, isVip: false }
|
|
40
|
+
},
|
|
41
|
+
config: {
|
|
42
|
+
fetchNow: true,
|
|
43
|
+
enableConsoleLogs: true,
|
|
44
|
+
enableSafeMode: true,
|
|
45
|
+
enableErrorLayout: true,
|
|
46
|
+
nodeEnv: 'production',
|
|
47
|
+
apiKey: 'M2FYdfXsJ12tjJQuadw7y9DZojqNGBvecpjGXY93'
|
|
48
|
+
},
|
|
49
|
+
envId: 'bn1ab7m56qolupi5sa0g'
|
|
50
|
+
};
|
|
51
|
+
exports.fetchedModifications = [
|
|
52
|
+
{
|
|
53
|
+
id: 'bsq046crms2g1jsvtb20',
|
|
54
|
+
slug: null,
|
|
55
|
+
type: 'ab',
|
|
56
|
+
variation: {
|
|
57
|
+
id: 'bsq046crms2g1jsvtb40',
|
|
58
|
+
modifications: {
|
|
59
|
+
type: 'JSON',
|
|
60
|
+
value: {
|
|
61
|
+
array: [1, 2, 3],
|
|
62
|
+
complex: {
|
|
63
|
+
carray: [
|
|
64
|
+
{
|
|
65
|
+
cobject: 0
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
object: {
|
|
70
|
+
value: 123456
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
reference: false
|
|
75
|
+
},
|
|
76
|
+
variationGroupId: 'bsq046crms2g1jsvtb30'
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'bqjfstuirtfg01mctmn0',
|
|
80
|
+
slug: null,
|
|
81
|
+
type: 'perso',
|
|
82
|
+
variation: {
|
|
83
|
+
id: 'bqjfstuirtfg01mctmp0',
|
|
84
|
+
modifications: { type: 'JSON', value: { discount: '10%' } },
|
|
85
|
+
reference: false
|
|
86
|
+
},
|
|
87
|
+
variationGroupId: 'bqjfstuirtfg01mctmo0'
|
|
88
|
+
}
|
|
89
|
+
];
|
|
90
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tests/mock/index.tsx"],"names":[],"mappings":";;;;;;AAAA,gDAAwD;AAIxD,6GAAuF;AACvF,6BAA4B;AAEf,QAAA,UAAU,GAAG;IAEtB,6BAA6B,yCAAA;CAChC,CAAC;AAEW,QAAA,aAAa,GAAsB,EAE/C,CAAC;AAEW,QAAA,uBAAuB,GAAc,cAAM,OAAA,wEAAqC,EAArC,CAAqC,CAAC;AAEjF,QAAA,cAAc,GAGvB;IACA,QAAQ,EAAE,KAAK;IACf,KAAK,EAAE;QACH,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI;QACf,GAAG,EAAE,IAAI;QACT,eAAe,EAAE,IAAI;QACrB,MAAM,EAAE;YACJ,UAAU,EAAE,KAAK;YACjB,SAAS,EAAE,IAAI;YACf,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,IAAI;YACjB,gBAAgB,EAAE,IAAI;YACtB,QAAQ,EAAE,KAAK;SAClB;QACD,OAAO,EAAE;YACL,4BAA4B,EAAE,SAAS;SAC1C;KACJ;CACJ,CAAC;AAEW,QAAA,kBAAkB,GAAG,eAAe,CAAC;AAErC,QAAA,aAAa,GAAG;IACzB,WAAW,EAAE;QACT,EAAE,EAAE,SAAG;QACP,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;KAC1C;IACD,MAAM,EAAE;QACJ,QAAQ,EAAE,IAAI;QACd,iBAAiB,EAAE,IAAI;QACvB,cAAc,EAAE,IAAI;QACpB,iBAAiB,EAAE,IAAI;QACvB,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,0CAA0C;KACrD;IACD,KAAK,EAAE,sBAAsB;CAChC,CAAC;AAEW,QAAA,oBAAoB,GAAG;IAChC;QACI,EAAE,EAAE,sBAAsB;QAC1B,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,IAAI;QACV,SAAS,EAAE;YACP,EAAE,EAAE,sBAAsB;YAC1B,aAAa,EAAE;gBACX,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE;oBACH,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;oBAChB,OAAO,EAAE;wBACL,MAAM,EAAE;4BACJ;gCACI,OAAO,EAAE,CAAC;6BACb;yBACJ;qBACJ;oBACD,MAAM,EAAE;wBACJ,KAAK,EAAE,MAAM;qBAChB;iBACJ;aACJ;YACD,SAAS,EAAE,KAAK;SACnB;QACD,gBAAgB,EAAE,sBAAsB;KAC3C;IACD;QACI,EAAE,EAAE,sBAAsB;QAC1B,IAAI,EAAE,IAAI;QACV,IAAI,EAAE,OAAO;QACb,SAAS,EAAE;YACP,EAAE,EAAE,sBAAsB;YAC1B,aAAa,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE;YAC3D,SAAS,EAAE,KAAK;SACnB;QACD,gBAAgB,EAAE,sBAAsB;KAC3C;CACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flagship.io/react-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3-alpha.0",
|
|
4
4
|
"description": "Flagship REACT SDK",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"README.md"
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@flagship.io/js-sdk": "^3.0.
|
|
14
|
+
"@flagship.io/js-sdk": "^3.0.5-alpha.0",
|
|
15
15
|
"encoding": "^0.1.13"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
package/dist/es/Flag.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { FlagMetadata, LogLevel } from '@flagship.io/js-sdk';
|
|
2
|
-
import { noVisitorMessage } from './constants';
|
|
3
|
-
import { log } from './utils';
|
|
4
|
-
export class Flag {
|
|
5
|
-
constructor(defaultValue) {
|
|
6
|
-
log(LogLevel.WARNING, noVisitorMessage, 'GetFlag');
|
|
7
|
-
this._defaultValue = defaultValue;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
getValue() {
|
|
11
|
-
log(LogLevel.WARNING, noVisitorMessage, 'getValue');
|
|
12
|
-
return this._defaultValue;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
exists() {
|
|
16
|
-
log(LogLevel.WARNING, noVisitorMessage, 'exists');
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
userExposed() {
|
|
21
|
-
log(LogLevel.WARNING, noVisitorMessage, 'userExposed');
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get metadata() {
|
|
26
|
-
log(LogLevel.WARNING, noVisitorMessage, 'metadata');
|
|
27
|
-
return new FlagMetadata({
|
|
28
|
-
campaignId: '',
|
|
29
|
-
campaignType: '',
|
|
30
|
-
isReference: false,
|
|
31
|
-
variationGroupId: '',
|
|
32
|
-
variationId: ''
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}
|
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-use-before-define
|
|
2
|
-
import React, { useState, useEffect, createContext, useRef } from "react";
|
|
3
|
-
import { Flagship, FlagshipStatus } from "@flagship.io/js-sdk";
|
|
4
|
-
import { getModificationsFromCampaigns, logError, useNonInitialEffect } from "./utils";
|
|
5
|
-
const initStat = {
|
|
6
|
-
status: {
|
|
7
|
-
isLoading: true,
|
|
8
|
-
isSdkReady: false
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
export const FlagshipContext = /*#__PURE__*/createContext({
|
|
12
|
-
state: { ...initStat
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
export const FlagshipProvider = ({
|
|
16
|
-
children,
|
|
17
|
-
fetchNow,
|
|
18
|
-
envId,
|
|
19
|
-
apiKey,
|
|
20
|
-
decisionMode,
|
|
21
|
-
decisionApiUrl,
|
|
22
|
-
timeout,
|
|
23
|
-
logLevel,
|
|
24
|
-
statusChangedCallback,
|
|
25
|
-
logManager,
|
|
26
|
-
pollingInterval,
|
|
27
|
-
visitorData,
|
|
28
|
-
onInitStart,
|
|
29
|
-
onInitDone,
|
|
30
|
-
onBucketingSuccess,
|
|
31
|
-
onBucketingFail,
|
|
32
|
-
loadingComponent,
|
|
33
|
-
onBucketingUpdated,
|
|
34
|
-
onUpdate,
|
|
35
|
-
enableClientCache,
|
|
36
|
-
initialBucketing,
|
|
37
|
-
initialCampaigns,
|
|
38
|
-
initialModifications,
|
|
39
|
-
initialFlagsData,
|
|
40
|
-
synchronizeOnBucketingUpdated,
|
|
41
|
-
activateDeduplicationTime,
|
|
42
|
-
hitDeduplicationTime,
|
|
43
|
-
visitorCacheImplementation,
|
|
44
|
-
hitCacheImplementation,
|
|
45
|
-
disableCache
|
|
46
|
-
}) => {
|
|
47
|
-
let modifications = new Map();
|
|
48
|
-
|
|
49
|
-
if (initialFlagsData && initialFlagsData.forEach) {
|
|
50
|
-
initialFlagsData.forEach(flag => {
|
|
51
|
-
modifications.set(flag.key, flag);
|
|
52
|
-
});
|
|
53
|
-
} else if (initialModifications && initialModifications.forEach) {
|
|
54
|
-
initialModifications.forEach(modification => {
|
|
55
|
-
modifications.set(modification.key, modification);
|
|
56
|
-
});
|
|
57
|
-
} else if (initialCampaigns) {
|
|
58
|
-
modifications = getModificationsFromCampaigns(initialCampaigns);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const [state, setState] = useState({ ...initStat,
|
|
62
|
-
modifications
|
|
63
|
-
});
|
|
64
|
-
const [lastModified, setLastModified] = useState();
|
|
65
|
-
const stateRef = useRef();
|
|
66
|
-
stateRef.current = state;
|
|
67
|
-
useNonInitialEffect(() => {
|
|
68
|
-
if (synchronizeOnBucketingUpdated) {
|
|
69
|
-
var _state$visitor;
|
|
70
|
-
|
|
71
|
-
(_state$visitor = state.visitor) === null || _state$visitor === void 0 ? void 0 : _state$visitor.fetchFlags();
|
|
72
|
-
}
|
|
73
|
-
}, [lastModified]);
|
|
74
|
-
useNonInitialEffect(() => {
|
|
75
|
-
createVisitor(true);
|
|
76
|
-
}, [JSON.stringify(visitorData)]);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
initSdk();
|
|
79
|
-
}, [envId, apiKey, decisionMode]);
|
|
80
|
-
|
|
81
|
-
function initializeState(param) {
|
|
82
|
-
const newStatus = {
|
|
83
|
-
isSdkReady: param.isSdkReady,
|
|
84
|
-
isLoading: param.isLoading,
|
|
85
|
-
isVisitorDefined: !!param.fsVisitor,
|
|
86
|
-
lastRefresh: new Date().toISOString()
|
|
87
|
-
};
|
|
88
|
-
setState(currentState => {
|
|
89
|
-
if (!currentState.status.firstInitSuccess) {
|
|
90
|
-
newStatus.firstInitSuccess = new Date().toISOString();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return { ...currentState,
|
|
94
|
-
visitor: param.fsVisitor,
|
|
95
|
-
modifications: param.fsVisitor.modifications,
|
|
96
|
-
config: Flagship.getConfig(),
|
|
97
|
-
status: { ...currentState.status,
|
|
98
|
-
...newStatus
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
return newStatus;
|
|
103
|
-
} // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const onVisitorReady = (fsVisitor, error) => {
|
|
107
|
-
if (error) {
|
|
108
|
-
logError(Flagship.getConfig(), error.message || error, "onReady");
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const newStatus = initializeState({
|
|
113
|
-
fsVisitor,
|
|
114
|
-
isSdkReady: true,
|
|
115
|
-
isLoading: false
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
if (onUpdate) {
|
|
119
|
-
onUpdate({
|
|
120
|
-
fsModifications: fsVisitor.modifications,
|
|
121
|
-
config: Flagship.getConfig(),
|
|
122
|
-
status: newStatus
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
const createVisitor = (fetchFlags = false) => {
|
|
128
|
-
if (!visitorData) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const fsVisitor = Flagship.newVisitor({
|
|
133
|
-
visitorId: visitorData.id,
|
|
134
|
-
context: visitorData.context,
|
|
135
|
-
isAuthenticated: visitorData.isAuthenticated,
|
|
136
|
-
hasConsented: visitorData.hasConsented,
|
|
137
|
-
initialCampaigns,
|
|
138
|
-
initialModifications,
|
|
139
|
-
initialFlagsData
|
|
140
|
-
});
|
|
141
|
-
fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.on("ready", error => {
|
|
142
|
-
onVisitorReady(fsVisitor, error);
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
if (!fetchNow && fsVisitor && !fetchFlags) {
|
|
146
|
-
initializeState({
|
|
147
|
-
fsVisitor,
|
|
148
|
-
isSdkReady: true,
|
|
149
|
-
isLoading: false
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (fetchFlags && !fetchNow) {
|
|
154
|
-
fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.fetchFlags();
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const statusChanged = status => {
|
|
159
|
-
if (statusChangedCallback) {
|
|
160
|
-
statusChangedCallback(status);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
if (status === FlagshipStatus.STARTING && onInitStart) {
|
|
164
|
-
onInitStart();
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (status === FlagshipStatus.READY_PANIC_ON || status === FlagshipStatus.READY) {
|
|
169
|
-
if (onInitDone) {
|
|
170
|
-
onInitDone();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
createVisitor();
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
const onBucketingLastModified = lastUpdate => {
|
|
178
|
-
if (onBucketingUpdated) {
|
|
179
|
-
onBucketingUpdated(lastUpdate);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
setLastModified(lastUpdate);
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const initSdk = () => {
|
|
186
|
-
Flagship.start(envId, apiKey, {
|
|
187
|
-
decisionMode,
|
|
188
|
-
fetchNow,
|
|
189
|
-
timeout,
|
|
190
|
-
logLevel,
|
|
191
|
-
statusChangedCallback: statusChanged,
|
|
192
|
-
logManager,
|
|
193
|
-
pollingInterval,
|
|
194
|
-
onBucketingFail,
|
|
195
|
-
onBucketingSuccess,
|
|
196
|
-
enableClientCache,
|
|
197
|
-
decisionApiUrl,
|
|
198
|
-
onBucketingUpdated: onBucketingLastModified,
|
|
199
|
-
initialBucketing,
|
|
200
|
-
activateDeduplicationTime,
|
|
201
|
-
hitDeduplicationTime,
|
|
202
|
-
visitorCacheImplementation,
|
|
203
|
-
hitCacheImplementation,
|
|
204
|
-
disableCache,
|
|
205
|
-
language: 1
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const handleDisplay = () => {
|
|
210
|
-
const isFirstInit = !state.visitor;
|
|
211
|
-
|
|
212
|
-
if (state.status.isLoading && loadingComponent && isFirstInit && fetchNow) {
|
|
213
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, loadingComponent);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
return /*#__PURE__*/React.createElement(FlagshipContext.Provider, {
|
|
220
|
-
value: {
|
|
221
|
-
state,
|
|
222
|
-
setState
|
|
223
|
-
}
|
|
224
|
-
}, handleDisplay());
|
|
225
|
-
};
|
|
226
|
-
FlagshipProvider.defaultProps = {
|
|
227
|
-
activateDeduplicationTime: 10,
|
|
228
|
-
hitDeduplicationTime: 10
|
|
229
|
-
};
|