@flagship.io/react-sdk 4.0.0-alpha.0 → 4.0.0-alpha.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,188 +1,8 @@
1
1
  'use client';
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- // eslint-disable-next-line no-use-before-define
14
- import React, { useState, useEffect, createContext, useRef } from 'react';
15
- import { DecisionMode, Flagship, FlagshipStatus } from '@flagship.io/js-sdk';
16
- import { getModificationsFromCampaigns, logError, useNonInitialEffect } from './utils';
17
- import { version as SDK_VERSION } from './sdkVersion';
18
- import { INTERNAL_EVENTS } from './internalType';
19
- const initStat = {
20
- status: { isLoading: true, isSdkReady: false }
2
+ import { createContext } from 'react';
3
+ export const initStat = {
4
+ isInitializing: true
21
5
  };
22
6
  export const FlagshipContext = createContext({
23
- state: Object.assign({}, initStat)
7
+ state: { ...initStat }
24
8
  });
25
- export const FlagshipProvider = (_a) => {
26
- var _b;
27
- var { children, envId, apiKey, decisionMode = DecisionMode.DECISION_API, visitorData, onInitStart, onInitDone, loadingComponent, statusChangedCallback, onBucketingUpdated, onUpdate, initialCampaigns, initialModifications, initialFlagsData, fetchFlagsOnBucketingUpdated, hitDeduplicationTime = 2, fetchNow = true, language = 1, sdkVersion = SDK_VERSION } = _a, props = __rest(_a, ["children", "envId", "apiKey", "decisionMode", "visitorData", "onInitStart", "onInitDone", "loadingComponent", "statusChangedCallback", "onBucketingUpdated", "onUpdate", "initialCampaigns", "initialModifications", "initialFlagsData", "fetchFlagsOnBucketingUpdated", "hitDeduplicationTime", "fetchNow", "language", "sdkVersion"]);
28
- let modifications = new Map();
29
- if (initialFlagsData && initialFlagsData.forEach) {
30
- initialFlagsData.forEach((flag) => {
31
- modifications.set(flag.key, flag);
32
- });
33
- }
34
- else if (initialModifications && initialModifications.forEach) {
35
- initialModifications.forEach((modification) => {
36
- modifications.set(modification.key, modification);
37
- });
38
- }
39
- else if (initialCampaigns) {
40
- modifications = getModificationsFromCampaigns(initialCampaigns);
41
- }
42
- const [state, setState] = useState(Object.assign(Object.assign({}, initStat), { modifications }));
43
- const [lastModified, setLastModified] = useState();
44
- const stateRef = useRef();
45
- stateRef.current = state;
46
- useNonInitialEffect(() => {
47
- var _a;
48
- if (fetchFlagsOnBucketingUpdated) {
49
- (_a = state.visitor) === null || _a === void 0 ? void 0 : _a.fetchFlags();
50
- }
51
- }, [lastModified]);
52
- useNonInitialEffect(() => {
53
- updateVisitor();
54
- }, [JSON.stringify(visitorData)]);
55
- useEffect(() => {
56
- initSdk();
57
- }, [envId, apiKey, decisionMode]);
58
- useEffect(() => {
59
- window.addEventListener(INTERNAL_EVENTS.FsTriggerRendering, onVariationsForced);
60
- return () => window.removeEventListener(INTERNAL_EVENTS.FsTriggerRendering, onVariationsForced);
61
- }, [(_b = state.config) === null || _b === void 0 ? void 0 : _b.isQAModeEnabled]);
62
- const onVariationsForced = () => {
63
- setState(state => (Object.assign(Object.assign({}, state), { toggleForcedVariations: !state.toggleForcedVariations })));
64
- };
65
- function initializeState(param) {
66
- const newStatus = {
67
- isSdkReady: param.isSdkReady,
68
- isLoading: param.isLoading,
69
- isVisitorDefined: !!param.fsVisitor,
70
- lastRefresh: new Date().toISOString()
71
- };
72
- setState((currentState) => {
73
- if (!currentState.status.firstInitSuccess) {
74
- newStatus.firstInitSuccess = new Date().toISOString();
75
- }
76
- return Object.assign(Object.assign({}, currentState), { visitor: param.fsVisitor, modifications: param.fsVisitor.modifications, config: Flagship.getConfig(), status: Object.assign(Object.assign({}, currentState.status), newStatus) });
77
- });
78
- return newStatus;
79
- }
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- const onVisitorReady = (fsVisitor, error) => {
82
- if (error) {
83
- logError(Flagship.getConfig(), error.message || error, 'onReady');
84
- return;
85
- }
86
- const newStatus = initializeState({
87
- fsVisitor,
88
- isSdkReady: true,
89
- isLoading: false
90
- });
91
- if (onUpdate) {
92
- onUpdate({
93
- fsModifications: fsVisitor.modifications,
94
- config: Flagship.getConfig(),
95
- status: newStatus
96
- });
97
- }
98
- };
99
- function updateVisitor() {
100
- var _a;
101
- if (!visitorData) {
102
- return;
103
- }
104
- if (!state.visitor || (state.visitor.visitorId !== visitorData.id && (!visitorData.isAuthenticated || (visitorData.isAuthenticated && state.visitor.anonymousId)))) {
105
- createVisitor();
106
- return;
107
- }
108
- if (visitorData.hasConsented !== state.visitor.hasConsented) {
109
- state.visitor.setConsent((_a = visitorData.hasConsented) !== null && _a !== void 0 ? _a : true);
110
- }
111
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
112
- state.visitor.updateContext(visitorData.context);
113
- if (!state.visitor.anonymousId && visitorData.isAuthenticated) {
114
- state.visitor.authenticate(visitorData.id);
115
- }
116
- if (state.visitor.anonymousId && !visitorData.isAuthenticated) {
117
- state.visitor.unauthenticate();
118
- }
119
- state.visitor.fetchFlags();
120
- }
121
- const createVisitor = () => {
122
- if (!visitorData) {
123
- return;
124
- }
125
- const fsVisitor = Flagship.newVisitor({
126
- visitorId: visitorData.id,
127
- context: visitorData.context,
128
- isAuthenticated: visitorData.isAuthenticated,
129
- hasConsented: visitorData.hasConsented,
130
- initialCampaigns,
131
- initialModifications,
132
- initialFlagsData
133
- });
134
- fsVisitor === null || fsVisitor === void 0 ? void 0 : fsVisitor.on('ready', (error) => {
135
- onVisitorReady(fsVisitor, error);
136
- });
137
- if (!fetchNow) {
138
- initializeState({
139
- fsVisitor,
140
- isSdkReady: true,
141
- isLoading: false
142
- });
143
- }
144
- };
145
- const statusChanged = (status) => {
146
- if (statusChangedCallback) {
147
- statusChangedCallback(status);
148
- }
149
- switch (status) {
150
- case FlagshipStatus.STARTING:
151
- if (status === FlagshipStatus.STARTING && onInitStart) {
152
- onInitStart();
153
- }
154
- break;
155
- case FlagshipStatus.READY_PANIC_ON:
156
- case FlagshipStatus.READY:
157
- if (onInitDone) {
158
- onInitDone();
159
- }
160
- createVisitor();
161
- break;
162
- case FlagshipStatus.NOT_INITIALIZED:
163
- setState((prev) => (Object.assign(Object.assign({}, prev), { status: Object.assign(Object.assign({}, prev.status), { isLoading: false }), config: Flagship.getConfig() })));
164
- break;
165
- }
166
- };
167
- const onBucketingLastModified = (lastUpdate) => {
168
- if (onBucketingUpdated) {
169
- onBucketingUpdated(lastUpdate);
170
- }
171
- setLastModified(lastUpdate);
172
- };
173
- const initSdk = () => {
174
- Flagship.start(envId, apiKey, Object.assign({
175
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
176
- decisionMode: decisionMode, fetchNow, statusChangedCallback: statusChanged, onBucketingUpdated: onBucketingLastModified, hitDeduplicationTime,
177
- language,
178
- sdkVersion }, props));
179
- };
180
- const handleDisplay = () => {
181
- const isFirstInit = !state.visitor;
182
- if (state.status.isLoading && loadingComponent && isFirstInit && fetchNow) {
183
- return React.createElement(React.Fragment, null, loadingComponent);
184
- }
185
- return React.createElement(React.Fragment, null, children);
186
- };
187
- return (React.createElement(FlagshipContext.Provider, { value: { state, setState } }, handleDisplay()));
188
- };
@@ -1,139 +1,10 @@
1
- import { FlagDTO, HitAbstract, HitShape, IFlag, IHit, Modification, modificationsRequested, primitive } from '@flagship.io/js-sdk';
2
- import { FsStatus } from './FlagshipContext';
3
- /**
4
- * 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.
5
- * @deprecated use useFsFlag instead
6
- */
7
- export declare const useFsModifications: <T extends unknown>(params: modificationsRequested<T>[], activateAll?: boolean) => Record<string, T>;
8
- /**
9
- * 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.
10
- * @deprecated use useFsFlag instead
11
- */
12
- export declare const useFsModification: {
13
- <T>(params: modificationsRequested<T>): T;
14
- };
15
- /**
16
- * Get the campaign modification information value matching the given key.
17
- * @param {string} key key which identify the modification.
18
- * @deprecated use useFsFlag instead
19
- */
20
- export declare const useFsModificationInfo: {
21
- (key: string): Modification | null;
22
- };
1
+ import { IFSFlag } from '@flagship.io/js-sdk';
2
+ import { UseFlagshipOutput } from './type';
23
3
  /**
24
4
  * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
25
5
  * @param key
26
6
  * @param defaultValue
27
7
  * @returns
28
8
  */
29
- export declare const useFsFlag: <T extends unknown>(key: string, defaultValue: T) => IFlag<T>;
30
- /**
31
- * Report this user has seen this modification. Report this user has seen these modifications.
32
- * @param params
33
- * @deprecated use useFsFlag instead
34
- * @returns
35
- */
36
- export declare const useFsActivate: {
37
- (keys: {
38
- key: string;
39
- }[]): Promise<void>;
40
- (keys: string[]): Promise<void>;
41
- };
42
- export type UseFlagshipParams<T> = {
43
- modifications: {
44
- requested: modificationsRequested<T>[];
45
- activateAll?: boolean;
46
- };
47
- };
48
- export type UseFlagshipOutput = {
49
- visitorId?: string;
50
- anonymousId?: string | null;
51
- context?: Record<string, primitive>;
52
- hasConsented?: boolean;
53
- /**
54
- * Set if visitor has consented for protected data usage.
55
- * @param hasConsented True if the visitor has consented false otherwise.
56
- */
57
- setConsent: (hasConsented: boolean) => void;
58
- modifications: Modification[];
59
- flagsData: FlagDTO[];
60
- status: FsStatus;
61
- /**
62
- *
63
- * @param params
64
- * @param activateAll
65
- * @deprecated use getFlag instead
66
- */
67
- getModifications<T>(params: modificationsRequested<T>[], activateAll?: boolean): Record<string, T>;
68
- /**
69
- *
70
- * @param key
71
- * @deprecated use getFlag instead
72
- */
73
- getModificationInfo(key: string): Modification | null;
74
- /**
75
- * @deprecated use fetchFlags instead
76
- */
77
- synchronizeModifications(): Promise<void>;
78
- /**
79
- * @deprecated use getFlag instead
80
- */
81
- activateModification: {
82
- (keys: {
83
- key: string;
84
- }[]): Promise<void>;
85
- (keys: string[]): Promise<void>;
86
- };
87
- /**
88
- * Update the visitor context values, matching the given keys, used for targeting.
89
- * A new context value associated with this key will be created if there is no previous matching value.
90
- * Context keys must be String, and values types must be one of the following : Number, Boolean, String.
91
- * @param context collection of keys, values.
92
- */
93
- updateContext(context: Record<string, primitive>): void;
94
- /**
95
- * clear the actual visitor context
96
- */
97
- clearContext(): void;
98
- /**
99
- * Authenticate anonymous visitor
100
- * @param visitorId
101
- */
102
- authenticate(visitorId: string): void;
103
- /**
104
- * This function change authenticated Visitor to anonymous visitor
105
- * @param visitorId
106
- */
107
- unauthenticate(): void;
108
- hit: {
109
- send: {
110
- (hit: HitAbstract): Promise<void>;
111
- (hit: IHit): Promise<void>;
112
- (hit: HitShape): Promise<void>;
113
- (hit: HitAbstract | IHit | HitShape): Promise<void>;
114
- };
115
- sendMultiple: {
116
- (hit: HitAbstract[]): Promise<void>;
117
- (hit: IHit[]): Promise<void>;
118
- (hit: HitShape[]): Promise<void>;
119
- (hit: HitAbstract[] | IHit[] | HitShape[]): Promise<void>;
120
- };
121
- };
122
- /**
123
- * Retrieve a Flag object by its key. If no flag match the given key an empty flag will be returned.
124
- * @param key flag key
125
- * @param defaultValue
126
- */
127
- getFlag<T>(key: string, defaultValue: T): IFlag<T>;
128
- /**
129
- * In DecisionApi Mode this function calls the Flagship Decision API to run campaign assignments according to the current user context and retrieve applicable flags.
130
- *
131
- * In bucketing Mode, it checks bucketing file, validates campaigns targeting the visitor, assigns a variation and retrieve applicable flags.
132
- */
133
- fetchFlags: () => Promise<void>;
134
- /**
135
- * When called, it will batch and send all hits that are in the pool before the application is closed
136
- */
137
- close(): Promise<void>;
138
- };
9
+ export declare const useFsFlag: (key: string) => IFSFlag;
139
10
  export declare const useFlagship: () => UseFlagshipOutput;
@@ -1,149 +1,24 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
1
+ 'use client';
10
2
  import { useContext } from 'react';
11
- import Flagship from '@flagship.io/js-sdk';
3
+ import { Flagship, FSFlagCollection } from '@flagship.io/js-sdk';
4
+ import { noVisitorMessage } from './constants';
12
5
  import { FlagshipContext } from './FlagshipContext';
6
+ import { FSFlag } from './FSFlag';
13
7
  import { logError, logWarn } from './utils';
14
- import { Flag } from './Flag';
15
- import { noVisitorDefault, noVisitorMessage } from './constants';
16
- const checkType = (value, defaultValue) => (typeof value === 'object' &&
17
- typeof defaultValue === 'object' &&
18
- Array.isArray(value) === Array.isArray(defaultValue)) ||
19
- typeof value === typeof defaultValue;
20
- const fsModificationsSync = (args) => {
21
- const { visitor, params, activateAll, state, functionName, config } = args;
22
- if (visitor) {
23
- return visitor.getModificationsSync(params, activateAll);
24
- }
25
- const check = !state.status.isSdkReady &&
26
- !!state.modifications &&
27
- state.modifications.size > 0;
28
- const flags = {};
29
- if (check) {
30
- params.forEach((item) => {
31
- var _a;
32
- const modification = (_a = state.modifications) === null || _a === void 0 ? void 0 : _a.get(item.key);
33
- if (modification && checkType(modification === null || modification === void 0 ? void 0 : modification.value, item.defaultValue)) {
34
- flags[item.key] = modification.value;
35
- }
36
- else {
37
- flags[item.key] = item.defaultValue;
38
- }
39
- });
40
- return flags;
41
- }
42
- logWarn(config, noVisitorDefault, functionName);
43
- params.forEach((item) => {
44
- flags[item.key] = item.defaultValue;
45
- });
46
- return flags;
47
- };
48
- /**
49
- * 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.
50
- * @deprecated use useFsFlag instead
51
- */
52
- export const useFsModifications = (params, activateAll) => {
53
- const { state } = useContext(FlagshipContext);
54
- const { visitor, config } = state;
55
- const functionName = 'useFsModifications';
56
- return fsModificationsSync({
57
- functionName,
58
- state,
59
- visitor,
60
- config,
61
- params,
62
- activateAll
63
- });
64
- };
65
- /**
66
- * 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.
67
- * @deprecated use useFsFlag instead
68
- */
69
- export const useFsModification = (params) => {
70
- var _a;
71
- const { state } = useContext(FlagshipContext);
72
- const { visitor, config } = state;
73
- const functionName = 'useFsModifications';
74
- if (visitor) {
75
- return visitor.getModificationSync(params);
76
- }
77
- const modification = (_a = state.modifications) === null || _a === void 0 ? void 0 : _a.get(params.key);
78
- if (!state.status.isSdkReady &&
79
- modification &&
80
- checkType(modification === null || modification === void 0 ? void 0 : modification.value, params.defaultValue)) {
81
- return modification.value;
82
- }
83
- logWarn(config, noVisitorDefault, functionName);
84
- return params.defaultValue;
85
- };
86
- const fsModificationInfoSync = (args) => {
87
- var _a;
88
- const { key, visitor, state } = args;
89
- if (visitor) {
90
- return visitor.getModificationInfoSync(key);
91
- }
92
- const modification = (_a = state.modifications) === null || _a === void 0 ? void 0 : _a.get(key);
93
- if (!state.status.isSdkReady && modification) {
94
- return modification;
95
- }
96
- return null;
97
- };
98
- /**
99
- * Get the campaign modification information value matching the given key.
100
- * @param {string} key key which identify the modification.
101
- * @deprecated use useFsFlag instead
102
- */
103
- export const useFsModificationInfo = (key) => {
104
- const { state } = useContext(FlagshipContext);
105
- const { visitor } = state;
106
- return fsModificationInfoSync({ key, state, visitor });
107
- };
108
- const fsActivate = (params, functionName, visitor, config) => __awaiter(void 0, void 0, void 0, function* () {
109
- try {
110
- if (!visitor) {
111
- logWarn(config, noVisitorMessage, functionName);
112
- return;
113
- }
114
- yield visitor.activateModifications(params);
115
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
116
- }
117
- catch (error) {
118
- logWarn(config, error.message || error, functionName);
119
- }
120
- });
121
8
  /**
122
9
  * This hook returns a flag object by its key. If no flag match the given key an empty flag will be returned.
123
10
  * @param key
124
11
  * @param defaultValue
125
12
  * @returns
126
13
  */
127
- export const useFsFlag = (key, defaultValue) => {
14
+ export const useFsFlag = (key) => {
128
15
  const { state } = useContext(FlagshipContext);
129
16
  const { visitor } = state;
130
17
  if (!visitor) {
131
- return new Flag(defaultValue, key, state.modifications);
18
+ return new FSFlag(key, state);
132
19
  }
133
- return visitor.getFlag(key, defaultValue);
20
+ return visitor.getFlag(key);
134
21
  };
135
- /**
136
- * Report this user has seen this modification. Report this user has seen these modifications.
137
- * @param params
138
- * @deprecated use useFsFlag instead
139
- * @returns
140
- */
141
- export const useFsActivate = (params) => __awaiter(void 0, void 0, void 0, function* () {
142
- const { state } = useContext(FlagshipContext);
143
- const { visitor, config } = state;
144
- const functionName = 'useFsModifications';
145
- yield fsActivate(params, functionName, visitor, config);
146
- });
147
22
  export const useFlagship = () => {
148
23
  const { state } = useContext(FlagshipContext);
149
24
  const { visitor, config } = state;
@@ -153,8 +28,8 @@ export const useFlagship = () => {
153
28
  logError(config, noVisitorMessage, functionName);
154
29
  return;
155
30
  }
156
- visitor.clearContext();
157
31
  visitor.updateContext(context);
32
+ visitor.fetchFlags();
158
33
  };
159
34
  const fsClearContext = () => {
160
35
  const functionName = 'cleanContext';
@@ -163,6 +38,7 @@ export const useFlagship = () => {
163
38
  return;
164
39
  }
165
40
  visitor.clearContext();
41
+ visitor.fetchFlags();
166
42
  };
167
43
  const fsAuthenticate = (visitorId) => {
168
44
  const functionName = 'authenticate';
@@ -171,6 +47,7 @@ export const useFlagship = () => {
171
47
  return;
172
48
  }
173
49
  visitor.authenticate(visitorId);
50
+ visitor.fetchFlags();
174
51
  };
175
52
  const fsUnauthenticate = () => {
176
53
  const functionName = 'unauthenticate';
@@ -179,6 +56,7 @@ export const useFlagship = () => {
179
56
  return;
180
57
  }
181
58
  visitor.unauthenticate();
59
+ visitor.fetchFlags();
182
60
  };
183
61
  /**
184
62
  * Send a Hit to Flagship servers for reporting.
@@ -189,54 +67,16 @@ export const useFlagship = () => {
189
67
  logError(config, noVisitorMessage, functionName);
190
68
  return Promise.resolve();
191
69
  }
192
- return visitor.sendHit(hit);
193
- };
194
- /**
195
- * Send a Hit to Flagship servers for reporting.
196
- */
197
- const fsSendHits = (hit) => {
198
- const functionName = 'sendHits';
199
- if (!visitor) {
200
- logError(config, noVisitorMessage, functionName);
201
- return Promise.resolve();
202
- }
203
- return visitor.sendHits(hit);
204
- };
205
- let modifications = visitor === null || visitor === void 0 ? void 0 : visitor.getModificationsArray();
206
- if (!state.status.isSdkReady && state.modifications) {
207
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
208
- modifications = Array.from(state.modifications, ([_key, item]) => item);
209
- }
210
- const activateModification = (params) => __awaiter(void 0, void 0, void 0, function* () {
211
- const functionName = 'activateModification';
212
- yield fsActivate(params, functionName, visitor, config);
213
- });
214
- const synchronizeModifications = () => __awaiter(void 0, void 0, void 0, function* () {
215
- if (!visitor) {
216
- logWarn(config, noVisitorMessage, 'synchronizeModifications');
217
- return;
70
+ if (Array.isArray(hit)) {
71
+ return visitor.sendHits(hit);
218
72
  }
219
- yield visitor.synchronizeModifications();
220
- });
221
- const getModifications = (params, activateAll) => {
222
- const functionName = 'getModifications';
223
- return fsModificationsSync({
224
- functionName,
225
- state,
226
- visitor,
227
- config,
228
- params,
229
- activateAll
230
- });
231
- };
232
- const getModificationInfo = (key) => {
233
- return fsModificationInfoSync({ key, state, visitor });
73
+ return visitor.sendHit(hit);
234
74
  };
235
- function getFlag(key, defaultValue) {
75
+ function getFlag(key) {
236
76
  if (!visitor) {
237
- return new Flag(defaultValue, key, state.modifications);
77
+ return new FSFlag(key, state);
238
78
  }
239
- return visitor.getFlag(key, defaultValue);
79
+ return visitor.getFlag(key);
240
80
  }
241
81
  function fetchFlags() {
242
82
  if (!visitor) {
@@ -252,34 +92,35 @@ export const useFlagship = () => {
252
92
  }
253
93
  visitor.setConsent(hasConsented);
254
94
  }
255
- function close() {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- yield Flagship.close();
258
- });
95
+ async function close() {
96
+ await Flagship.close();
97
+ }
98
+ function getFlags() {
99
+ if (!visitor) {
100
+ const flags = new Map();
101
+ state.flags?.forEach((flag, key) => {
102
+ flags.set(key, new FSFlag(key, state));
103
+ });
104
+ return new FSFlagCollection({ flags });
105
+ }
106
+ return visitor.getFlags();
259
107
  }
260
108
  return {
261
- visitorId: visitor === null || visitor === void 0 ? void 0 : visitor.visitorId,
262
- anonymousId: visitor === null || visitor === void 0 ? void 0 : visitor.anonymousId,
263
- context: Object.assign({}, visitor === null || visitor === void 0 ? void 0 : visitor.context),
264
- hasConsented: visitor === null || visitor === void 0 ? void 0 : visitor.hasConsented,
109
+ visitorId: visitor?.visitorId,
110
+ anonymousId: visitor?.anonymousId,
111
+ context: { ...visitor?.context },
112
+ hasConsented: visitor?.hasConsented,
113
+ sdkStatus: Flagship.getStatus(),
114
+ fetchStatus: visitor?.fetchStatus,
265
115
  setConsent,
266
116
  updateContext: fsUpdateContext,
267
117
  clearContext: fsClearContext,
268
118
  authenticate: fsAuthenticate,
269
119
  unauthenticate: fsUnauthenticate,
270
- status: state.status,
271
- activateModification,
272
- synchronizeModifications,
273
- getModifications,
274
- modifications: modifications || [],
275
- flagsData: (visitor === null || visitor === void 0 ? void 0 : visitor.getFlagsDataArray()) || [],
276
- getModificationInfo,
277
- hit: {
278
- send: fsSendHit,
279
- sendMultiple: fsSendHits
280
- },
120
+ sendHits: fsSendHit,
281
121
  getFlag,
282
122
  fetchFlags,
283
- close
123
+ close,
124
+ getFlags
284
125
  };
285
126
  };
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import { FlagshipProviderProps } from './type';
3
+ export declare function FlagshipProvider({ children, envId, apiKey, decisionMode, visitorData, loadingComponent, onSdkStatusChanged, onBucketingUpdated, initialCampaigns, initialFlagsData, fetchFlagsOnBucketingUpdated, hitDeduplicationTime, fetchNow, language, sdkVersion, onFetchFlagsStatusChanged, shouldSaveInstance, ...props }: FlagshipProviderProps): React.JSX.Element;