@hackler/react-sdk 11.1.0 → 11.2.1

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/lib/Context.d.ts CHANGED
@@ -4,6 +4,7 @@ import { HackleReactSDKClient } from "./client";
4
4
  interface HackleContext {
5
5
  hackle: HackleReactSDKClient | undefined;
6
6
  user?: User;
7
+ initialized: boolean;
7
8
  }
8
9
  export declare const HackleContext: import("react").Context<HackleContext>;
9
10
  export declare const HackleContextConsumer: import("react").Consumer<HackleContext>;
@@ -1 +1 @@
1
- {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../src/Context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ;AAED,eAAO,MAAM,aAAa,wCAGxB,CAAA;AAEF,eAAO,MAAM,qBAAqB,yCAAyB,CAAA;AAC3D,eAAO,MAAM,qBAAqB,yCAAyB,CAAA"}
1
+ {"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../src/Context.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACxC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,eAAO,MAAM,aAAa,wCAIxB,CAAA;AAEF,eAAO,MAAM,qBAAqB,yCAAyB,CAAA;AAC3D,eAAO,MAAM,qBAAqB,yCAAyB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Experiment.d.ts","sourceRoot":"","sources":["../src/Experiment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,iBAAS,UAAU,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,eAAe,OAqB/D;AAED,eAAO,MAAM,gBAAgB,mBAAa,CAAA"}
1
+ {"version":3,"file":"Experiment.d.ts","sourceRoot":"","sources":["../src/Experiment.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,MAAM,WAAW,eAAe;IAC9B,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B;AACD,iBAAS,UAAU,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,eAAe,OAyB/D;AAED,eAAO,MAAM,gBAAgB,mBAAa,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,oBAAY,gBAAgB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAA;AAEjE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,CAAA;CAC3B;AAQD,eAAO,MAAM,aAAa,uCAAU,CAAA"}
1
+ {"version":3,"file":"Feature.d.ts","sourceRoot":"","sources":["../src/Feature.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,oBAAY,gBAAgB,GAAG,CAAC,IAAI,EAAE,OAAO,KAAK,KAAK,CAAC,SAAS,CAAA;AAEjE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,gBAAgB,CAAA;CAC3B;AAYD,eAAO,MAAM,aAAa,uCAAU,CAAA"}
package/lib/Provider.d.ts CHANGED
@@ -5,8 +5,9 @@ interface ProviderProps {
5
5
  hackleClient: HackleReactSDKClient;
6
6
  user?: User;
7
7
  timeout?: number;
8
+ supportSSR?: boolean;
8
9
  children?: ReactNode;
9
10
  }
10
- export declare function HackleProvider({ hackleClient, user, timeout, children }: ProviderProps): JSX.Element | null;
11
+ export declare function HackleProvider({ hackleClient, user, timeout, supportSSR, children }: ProviderProps): JSX.Element | null;
11
12
  export {};
12
13
  //# sourceMappingURL=Provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,YAAY,EAAE,oBAAoB,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,wBAAgB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,OAAc,EAAE,QAAQ,EAAE,EAAE,aAAa,sBA4B7F"}
1
+ {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../src/Provider.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAA;AAE9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE/C,UAAU,aAAa;IACrB,YAAY,EAAE,oBAAoB,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED,wBAAgB,cAAc,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,OAAc,EAAE,UAAkB,EAAE,QAAQ,EAAE,EAAE,aAAa,sBAiDjH"}
package/lib/config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare const SDK_NAME_HEADER = "react-sdk";
2
- export declare const SDK_VERSION_HEADER = "11.1.0";
2
+ export declare const SDK_VERSION_HEADER = "11.2.1";
3
3
  //# sourceMappingURL=config.d.ts.map
package/lib/hooks.d.ts CHANGED
@@ -1,15 +1,30 @@
1
- import { Decision, FeatureFlagDecision, HackleEvent, PageView } from "@hackler/javascript-sdk";
1
+ import { Decision, FeatureFlagDecision, HackleEvent } from "@hackler/javascript-sdk";
2
+ interface Loadable {
3
+ isLoading: boolean;
4
+ }
5
+ export interface VariationResult extends Loadable {
6
+ variation: string;
7
+ }
8
+ export interface VariationDetailResult extends Loadable {
9
+ decision: Decision;
10
+ }
11
+ export interface FeatureFlagResult extends Loadable {
12
+ isOn: boolean;
13
+ }
14
+ export interface FeatureFlagDetailResult extends Loadable {
15
+ decision: FeatureFlagDecision;
16
+ }
2
17
  export declare function useVariation(experimentKey: number, defaultVariation?: string): string;
3
18
  export declare function useVariationDetail(experimentKey: number, defaultVariation?: string): Decision;
19
+ export declare function useLoadableVariation(experimentKey: number, defaultVariation?: string): VariationResult;
20
+ export declare function useLoadableVariationDetail(experimentKey: number, defaultVariation?: string): VariationDetailResult;
4
21
  export declare function useFeature(featureKey: number): boolean;
5
22
  export declare function useFeatureFlagDetail(featureKey: number): FeatureFlagDecision;
23
+ export declare function useLoadableFeature(featureKey: number): FeatureFlagResult;
24
+ export declare function useLoadableFeatureDetail(featureKey: number): FeatureFlagDetailResult;
6
25
  interface Track {
7
26
  (event: HackleEvent): void;
8
27
  }
9
28
  export declare function useTrack(): Track;
10
- interface TrackPageView {
11
- (option?: PageView): void;
12
- }
13
- export declare function usePageView(): TrackPageView;
14
29
  export {};
15
30
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAER,mBAAmB,EACnB,WAAW,EAEX,QAAQ,EAET,MAAM,yBAAyB,CAAA;AAOhC,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,MAAM,CA6BlF;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,QAAQ,CA6B1F;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CA6BtD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CA6B5E;AAED,UAAU,KAAK;IACb,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAA;CAC3B;AACD,wBAAgB,QAAQ,IAAI,KAAK,CAWhC;AAED,UAAU,aAAa;IACrB,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC1B;AACD,wBAAgB,WAAW,IAAI,aAAa,CAoB3C"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,mBAAmB,EAAE,WAAW,EAAgB,MAAM,yBAAyB,CAAA;AAOlH,UAAU,QAAQ;IAChB,SAAS,EAAE,OAAO,CAAA;CACnB;AAED,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,qBAAsB,SAAQ,QAAQ;IACrD,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED,MAAM,WAAW,iBAAkB,SAAQ,QAAQ;IACjD,IAAI,EAAE,OAAO,CAAA;CACd;AAED,MAAM,WAAW,uBAAwB,SAAQ,QAAQ;IACvD,QAAQ,EAAE,mBAAmB,CAAA;CAC9B;AAED,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,MAAM,CA+BlF;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,QAAQ,CA8B1F;AAED,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,eAAe,CAOnG;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,qBAAqB,CAmC/G;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CA8BtD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CA8B5E;AAED,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,CAOxE;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,GAAG,uBAAuB,CAkCpF;AAED,UAAU,KAAK;IACb,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAA;CAC3B;AACD,wBAAgB,QAAQ,IAAI,KAAK,CAShC"}
package/lib/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from "@hackler/javascript-sdk";
2
2
  export { createInstance } from "./client";
3
3
  export { HackleProvider } from "./Provider";
4
4
  export { HackleContext, HackleContextProvider, HackleContextConsumer } from "./Context";
5
- export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail } from "./hooks";
5
+ export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail, useLoadableVariation, useLoadableVariationDetail, useLoadableFeature, useLoadableFeatureDetail, VariationResult, VariationDetailResult, FeatureFlagResult, FeatureFlagDetailResult } from "./hooks";
6
6
  export { HackleExperiment } from "./Experiment";
7
7
  export { HackleVariation } from "./Variation";
8
8
  export { HackleFeature } from "./Feature";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACvF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,QAAQ,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AACtG,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAA;AAEvC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAA;AACvF,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA"}
package/lib/index.es.js CHANGED
@@ -48,7 +48,7 @@ function __read(o, n) {
48
48
  }
49
49
 
50
50
  var SDK_NAME_HEADER = "react-sdk";
51
- var SDK_VERSION_HEADER = "11.1.0";
51
+ var SDK_VERSION_HEADER = "11.2.1";
52
52
 
53
53
  var HackleReactSDKClient = /** @class */ (function () {
54
54
  function HackleReactSDKClient(sdkKey, config) {
@@ -87,17 +87,18 @@ function createInstance(sdkKey, config) {
87
87
  var HackleContext = createContext({
88
88
  hackle: undefined,
89
89
  user: undefined,
90
+ initialized: false,
90
91
  });
91
92
  var HackleContextConsumer = HackleContext.Consumer;
92
93
  var HackleContextProvider = HackleContext.Provider;
93
94
 
94
95
  function HackleProvider(_a) {
95
- var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, children = _a.children;
96
+ var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, _c = _a.supportSSR, supportSSR = _c === void 0 ? false : _c, children = _a.children;
96
97
  var state = {
97
98
  hackle: hackleClient,
98
99
  user: user,
100
+ initialized: false
99
101
  };
100
- var _c = __read(useState(false), 2), ready = _c[0], setReady = _c[1];
101
102
  var _d = __read(useState(state), 2), value = _d[0], setValue = _d[1];
102
103
  useEffect(function () {
103
104
  setValue(function (prevState) {
@@ -107,21 +108,32 @@ function HackleProvider(_a) {
107
108
  useEffect(function () {
108
109
  hackleClient.onInitialized({ timeout: timeout })
109
110
  .then(function () {
110
- setReady(true);
111
+ setValue(function (prevState) {
112
+ return __assign(__assign({}, prevState), { initialized: true });
113
+ });
111
114
  }, function () {
112
- setReady(true);
115
+ setValue(function (prevState) {
116
+ return __assign(__assign({}, prevState), { initialized: true });
117
+ });
118
+ }).catch(function () {
119
+ setValue(function (prevState) {
120
+ return __assign(__assign({}, prevState), { initialized: true });
121
+ });
113
122
  });
114
123
  }, [hackleClient]);
115
- return ready ? React__default.createElement(HackleContextProvider, { value: value }, children) : null;
124
+ if (supportSSR) {
125
+ return React__default.createElement(HackleContextProvider, { value: value }, children);
126
+ }
127
+ return value.initialized ? React__default.createElement(HackleContextProvider, { value: value }, children) : null;
116
128
  }
117
129
 
118
130
  var log = Logger.log;
119
131
  function useVariation(experimentKey, defaultVariation) {
120
132
  if (defaultVariation === void 0) { defaultVariation = "A"; }
121
- var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
133
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
122
134
  var getVariation = useCallback(function () {
123
- return (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
124
- }, [defaultVariation, experimentKey, user, hackle]);
135
+ return initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
136
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
125
137
  var _b = __read(useState(function () {
126
138
  if (notExistClient(hackle)) {
127
139
  if ((typeof window) !== "undefined") {
@@ -133,7 +145,8 @@ function useVariation(experimentKey, defaultVariation) {
133
145
  }), 2), variation = _b[0], setVariation = _b[1];
134
146
  var currentInput = {
135
147
  key: experimentKey,
136
- user: user
148
+ user: user,
149
+ initialized: initialized
137
150
  };
138
151
  var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
139
152
  if (!isInputEqual(prevInput, currentInput)) {
@@ -144,10 +157,10 @@ function useVariation(experimentKey, defaultVariation) {
144
157
  }
145
158
  function useVariationDetail(experimentKey, defaultVariation) {
146
159
  if (defaultVariation === void 0) { defaultVariation = "A"; }
147
- var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
160
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
148
161
  var getVariationDetail = useCallback(function () {
149
162
  return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Decision.of(defaultVariation, DecisionReason.EXCEPTION);
150
- }, [defaultVariation, experimentKey, user, hackle]);
163
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
151
164
  var _b = __read(useState(function () {
152
165
  if (notExistClient(hackle)) {
153
166
  if ((typeof window) !== "undefined") {
@@ -159,7 +172,8 @@ function useVariationDetail(experimentKey, defaultVariation) {
159
172
  }), 2), variationDetail = _b[0], setVariationDetail = _b[1];
160
173
  var currentInput = {
161
174
  key: experimentKey,
162
- user: user
175
+ user: user,
176
+ initialized: initialized
163
177
  };
164
178
  var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
165
179
  if (!isInputEqual(prevInput, currentInput)) {
@@ -168,11 +182,50 @@ function useVariationDetail(experimentKey, defaultVariation) {
168
182
  }
169
183
  return variationDetail;
170
184
  }
185
+ function useLoadableVariation(experimentKey, defaultVariation) {
186
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
187
+ var _a = useLoadableVariationDetail(experimentKey, defaultVariation), isLoading = _a.isLoading, decision = _a.decision;
188
+ return {
189
+ isLoading: isLoading,
190
+ variation: decision.variation
191
+ };
192
+ }
193
+ function useLoadableVariationDetail(experimentKey, defaultVariation) {
194
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
195
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
196
+ var getVariationDetail = useCallback(function () {
197
+ if (!initialized) {
198
+ return Decision.of(defaultVariation, DecisionReason.SDK_NOT_READY);
199
+ }
200
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Decision.of(defaultVariation, DecisionReason.EXCEPTION);
201
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
202
+ var _b = __read(useState(function () {
203
+ if (notExistClient(hackle)) {
204
+ log.error("HackleClient is not existed");
205
+ return Decision.of(defaultVariation, DecisionReason.EXCEPTION);
206
+ }
207
+ return getVariationDetail();
208
+ }), 2), variationDetail = _b[0], setVariationDetail = _b[1];
209
+ var currentInput = {
210
+ key: experimentKey,
211
+ user: user,
212
+ initialized: initialized
213
+ };
214
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
215
+ if (!isInputEqual(prevInput, currentInput)) {
216
+ setPrevInput(currentInput);
217
+ setVariationDetail(getVariationDetail());
218
+ }
219
+ return {
220
+ isLoading: !initialized,
221
+ decision: variationDetail
222
+ };
223
+ }
171
224
  function useFeature(featureKey) {
172
- var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
225
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
173
226
  var getIsOn = useCallback(function () {
174
227
  return (hackle === null || hackle === void 0 ? void 0 : hackle.isFeatureOn(featureKey, user)) || false;
175
- }, [featureKey, user, hackle]);
228
+ }, [featureKey, user, hackle, initialized]);
176
229
  var _b = __read(useState(function () {
177
230
  if (notExistClient(hackle)) {
178
231
  if ((typeof window) !== "undefined") {
@@ -185,6 +238,7 @@ function useFeature(featureKey) {
185
238
  var currentInput = {
186
239
  key: featureKey,
187
240
  user: user,
241
+ initialized: initialized
188
242
  };
189
243
  var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
190
244
  if (!isInputEqual(prevInput, currentInput)) {
@@ -194,10 +248,10 @@ function useFeature(featureKey) {
194
248
  return isOn;
195
249
  }
196
250
  function useFeatureFlagDetail(featureKey) {
197
- var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
251
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
198
252
  var getFeatureDetail = useCallback(function () {
199
253
  return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || FeatureFlagDecision.off(DecisionReason.EXCEPTION);
200
- }, [featureKey, user, hackle]);
254
+ }, [featureKey, user, hackle, initialized]);
201
255
  var _b = __read(useState(function () {
202
256
  if (notExistClient(hackle)) {
203
257
  if ((typeof window) !== "undefined") {
@@ -210,6 +264,7 @@ function useFeatureFlagDetail(featureKey) {
210
264
  var currentInput = {
211
265
  key: featureKey,
212
266
  user: user,
267
+ initialized: initialized
213
268
  };
214
269
  var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
215
270
  if (!isInputEqual(prevInput, currentInput)) {
@@ -218,12 +273,47 @@ function useFeatureFlagDetail(featureKey) {
218
273
  }
219
274
  return featureDetail;
220
275
  }
276
+ function useLoadableFeature(featureKey) {
277
+ var _a = useLoadableFeatureDetail(featureKey), isLoading = _a.isLoading, decision = _a.decision;
278
+ return {
279
+ isLoading: isLoading,
280
+ isOn: decision.isOn
281
+ };
282
+ }
283
+ function useLoadableFeatureDetail(featureKey) {
284
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
285
+ var getFeatureDetail = useCallback(function () {
286
+ if (!initialized) {
287
+ return FeatureFlagDecision.off(DecisionReason.SDK_NOT_READY);
288
+ }
289
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || FeatureFlagDecision.off(DecisionReason.EXCEPTION);
290
+ }, [featureKey, user, hackle, initialized]);
291
+ var _b = __read(useState(function () {
292
+ if (notExistClient(hackle)) {
293
+ log.error("HackleClient is not existed");
294
+ return FeatureFlagDecision.off(DecisionReason.EXCEPTION);
295
+ }
296
+ return getFeatureDetail();
297
+ }), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
298
+ var currentInput = {
299
+ key: featureKey,
300
+ user: user,
301
+ initialized: initialized
302
+ };
303
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
304
+ if (!isInputEqual(prevInput, currentInput)) {
305
+ setPrevInput(currentInput);
306
+ setFeatureDetail(getFeatureDetail());
307
+ }
308
+ return {
309
+ isLoading: !initialized,
310
+ decision: featureDetail
311
+ };
312
+ }
221
313
  function useTrack() {
222
314
  var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
223
315
  if (notExistClient(hackle)) {
224
- if ((typeof window) !== "undefined") {
225
- log.error("HackleClient is not existed");
226
- }
316
+ log.error("HackleClient is not existed");
227
317
  return function () { };
228
318
  }
229
319
  return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event, user); };
@@ -233,7 +323,8 @@ function notExistClient(hackle) {
233
323
  }
234
324
  function isInputEqual(prev, current) {
235
325
  var _a, _b, _c, _d;
236
- return (prev.key === current.key &&
326
+ return (prev.initialized === current.initialized &&
327
+ prev.key === current.key &&
237
328
  ((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
238
329
  arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
239
330
  }
@@ -258,7 +349,10 @@ function coerceUnknownToProperties(props) {
258
349
 
259
350
  function Experiment(_a) {
260
351
  var experimentKey = _a.experimentKey, children = _a.children;
261
- var variation = useVariation(experimentKey);
352
+ var _b = useLoadableVariation(experimentKey), isLoading = _b.isLoading, variation = _b.variation;
353
+ if (isLoading) {
354
+ return null;
355
+ }
262
356
  if (!!children && typeof children === "function") {
263
357
  return children(variation);
264
358
  }
@@ -287,9 +381,12 @@ function Variation(_a) {
287
381
  var HackleVariation = Variation;
288
382
 
289
383
  var Feature = function (props) {
290
- var featureOn = useFeature(props.featureKey);
384
+ var _a = useLoadableFeature(props.featureKey), isLoading = _a.isLoading, featureOn = _a.isOn;
385
+ if (isLoading) {
386
+ return null;
387
+ }
291
388
  return React__default.createElement(React__default.Fragment, null, props.children(featureOn));
292
389
  };
293
390
  var HackleFeature = Feature;
294
391
 
295
- export { HackleContext, HackleContextConsumer, HackleContextProvider, HackleExperiment, HackleFeature, HackleProvider, HackleVariation, createInstance, useFeature, useFeatureFlagDetail, useTrack, useVariation, useVariationDetail };
392
+ export { HackleContext, HackleContextConsumer, HackleContextProvider, HackleExperiment, HackleFeature, HackleProvider, HackleVariation, createInstance, useFeature, useFeatureFlagDetail, useLoadableFeature, useLoadableFeatureDetail, useLoadableVariation, useLoadableVariationDetail, useTrack, useVariation, useVariationDetail };
package/lib/index.js CHANGED
@@ -73,7 +73,7 @@ function __read(o, n) {
73
73
  }
74
74
 
75
75
  var SDK_NAME_HEADER = "react-sdk";
76
- var SDK_VERSION_HEADER = "11.1.0";
76
+ var SDK_VERSION_HEADER = "11.2.1";
77
77
 
78
78
  var HackleReactSDKClient = /** @class */ (function () {
79
79
  function HackleReactSDKClient(sdkKey, config) {
@@ -112,17 +112,18 @@ function createInstance(sdkKey, config) {
112
112
  var HackleContext = React.createContext({
113
113
  hackle: undefined,
114
114
  user: undefined,
115
+ initialized: false,
115
116
  });
116
117
  var HackleContextConsumer = HackleContext.Consumer;
117
118
  var HackleContextProvider = HackleContext.Provider;
118
119
 
119
120
  function HackleProvider(_a) {
120
- var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, children = _a.children;
121
+ var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, _c = _a.supportSSR, supportSSR = _c === void 0 ? false : _c, children = _a.children;
121
122
  var state = {
122
123
  hackle: hackleClient,
123
124
  user: user,
125
+ initialized: false
124
126
  };
125
- var _c = __read(React.useState(false), 2), ready = _c[0], setReady = _c[1];
126
127
  var _d = __read(React.useState(state), 2), value = _d[0], setValue = _d[1];
127
128
  React.useEffect(function () {
128
129
  setValue(function (prevState) {
@@ -132,21 +133,32 @@ function HackleProvider(_a) {
132
133
  React.useEffect(function () {
133
134
  hackleClient.onInitialized({ timeout: timeout })
134
135
  .then(function () {
135
- setReady(true);
136
+ setValue(function (prevState) {
137
+ return __assign(__assign({}, prevState), { initialized: true });
138
+ });
136
139
  }, function () {
137
- setReady(true);
140
+ setValue(function (prevState) {
141
+ return __assign(__assign({}, prevState), { initialized: true });
142
+ });
143
+ }).catch(function () {
144
+ setValue(function (prevState) {
145
+ return __assign(__assign({}, prevState), { initialized: true });
146
+ });
138
147
  });
139
148
  }, [hackleClient]);
140
- return ready ? React__default["default"].createElement(HackleContextProvider, { value: value }, children) : null;
149
+ if (supportSSR) {
150
+ return React__default["default"].createElement(HackleContextProvider, { value: value }, children);
151
+ }
152
+ return value.initialized ? React__default["default"].createElement(HackleContextProvider, { value: value }, children) : null;
141
153
  }
142
154
 
143
155
  var log = Hackle.Logger.log;
144
156
  function useVariation(experimentKey, defaultVariation) {
145
157
  if (defaultVariation === void 0) { defaultVariation = "A"; }
146
- var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
158
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
147
159
  var getVariation = React.useCallback(function () {
148
- return (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
149
- }, [defaultVariation, experimentKey, user, hackle]);
160
+ return initialized && (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
161
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
150
162
  var _b = __read(React.useState(function () {
151
163
  if (notExistClient(hackle)) {
152
164
  if ((typeof window) !== "undefined") {
@@ -158,7 +170,8 @@ function useVariation(experimentKey, defaultVariation) {
158
170
  }), 2), variation = _b[0], setVariation = _b[1];
159
171
  var currentInput = {
160
172
  key: experimentKey,
161
- user: user
173
+ user: user,
174
+ initialized: initialized
162
175
  };
163
176
  var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
164
177
  if (!isInputEqual(prevInput, currentInput)) {
@@ -169,10 +182,10 @@ function useVariation(experimentKey, defaultVariation) {
169
182
  }
170
183
  function useVariationDetail(experimentKey, defaultVariation) {
171
184
  if (defaultVariation === void 0) { defaultVariation = "A"; }
172
- var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
185
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
173
186
  var getVariationDetail = React.useCallback(function () {
174
187
  return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
175
- }, [defaultVariation, experimentKey, user, hackle]);
188
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
176
189
  var _b = __read(React.useState(function () {
177
190
  if (notExistClient(hackle)) {
178
191
  if ((typeof window) !== "undefined") {
@@ -184,7 +197,8 @@ function useVariationDetail(experimentKey, defaultVariation) {
184
197
  }), 2), variationDetail = _b[0], setVariationDetail = _b[1];
185
198
  var currentInput = {
186
199
  key: experimentKey,
187
- user: user
200
+ user: user,
201
+ initialized: initialized
188
202
  };
189
203
  var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
190
204
  if (!isInputEqual(prevInput, currentInput)) {
@@ -193,11 +207,50 @@ function useVariationDetail(experimentKey, defaultVariation) {
193
207
  }
194
208
  return variationDetail;
195
209
  }
210
+ function useLoadableVariation(experimentKey, defaultVariation) {
211
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
212
+ var _a = useLoadableVariationDetail(experimentKey, defaultVariation), isLoading = _a.isLoading, decision = _a.decision;
213
+ return {
214
+ isLoading: isLoading,
215
+ variation: decision.variation
216
+ };
217
+ }
218
+ function useLoadableVariationDetail(experimentKey, defaultVariation) {
219
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
220
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
221
+ var getVariationDetail = React.useCallback(function () {
222
+ if (!initialized) {
223
+ return Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.SDK_NOT_READY);
224
+ }
225
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
226
+ }, [defaultVariation, experimentKey, user, hackle, initialized]);
227
+ var _b = __read(React.useState(function () {
228
+ if (notExistClient(hackle)) {
229
+ log.error("HackleClient is not existed");
230
+ return Hackle.Decision.of(defaultVariation, Hackle.DecisionReason.EXCEPTION);
231
+ }
232
+ return getVariationDetail();
233
+ }), 2), variationDetail = _b[0], setVariationDetail = _b[1];
234
+ var currentInput = {
235
+ key: experimentKey,
236
+ user: user,
237
+ initialized: initialized
238
+ };
239
+ var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
240
+ if (!isInputEqual(prevInput, currentInput)) {
241
+ setPrevInput(currentInput);
242
+ setVariationDetail(getVariationDetail());
243
+ }
244
+ return {
245
+ isLoading: !initialized,
246
+ decision: variationDetail
247
+ };
248
+ }
196
249
  function useFeature(featureKey) {
197
- var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
250
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
198
251
  var getIsOn = React.useCallback(function () {
199
252
  return (hackle === null || hackle === void 0 ? void 0 : hackle.isFeatureOn(featureKey, user)) || false;
200
- }, [featureKey, user, hackle]);
253
+ }, [featureKey, user, hackle, initialized]);
201
254
  var _b = __read(React.useState(function () {
202
255
  if (notExistClient(hackle)) {
203
256
  if ((typeof window) !== "undefined") {
@@ -210,6 +263,7 @@ function useFeature(featureKey) {
210
263
  var currentInput = {
211
264
  key: featureKey,
212
265
  user: user,
266
+ initialized: initialized
213
267
  };
214
268
  var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
215
269
  if (!isInputEqual(prevInput, currentInput)) {
@@ -219,10 +273,10 @@ function useFeature(featureKey) {
219
273
  return isOn;
220
274
  }
221
275
  function useFeatureFlagDetail(featureKey) {
222
- var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
276
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
223
277
  var getFeatureDetail = React.useCallback(function () {
224
278
  return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
225
- }, [featureKey, user, hackle]);
279
+ }, [featureKey, user, hackle, initialized]);
226
280
  var _b = __read(React.useState(function () {
227
281
  if (notExistClient(hackle)) {
228
282
  if ((typeof window) !== "undefined") {
@@ -235,6 +289,7 @@ function useFeatureFlagDetail(featureKey) {
235
289
  var currentInput = {
236
290
  key: featureKey,
237
291
  user: user,
292
+ initialized: initialized
238
293
  };
239
294
  var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
240
295
  if (!isInputEqual(prevInput, currentInput)) {
@@ -243,12 +298,47 @@ function useFeatureFlagDetail(featureKey) {
243
298
  }
244
299
  return featureDetail;
245
300
  }
301
+ function useLoadableFeature(featureKey) {
302
+ var _a = useLoadableFeatureDetail(featureKey), isLoading = _a.isLoading, decision = _a.decision;
303
+ return {
304
+ isLoading: isLoading,
305
+ isOn: decision.isOn
306
+ };
307
+ }
308
+ function useLoadableFeatureDetail(featureKey) {
309
+ var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user, initialized = _a.initialized;
310
+ var getFeatureDetail = React.useCallback(function () {
311
+ if (!initialized) {
312
+ return Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.SDK_NOT_READY);
313
+ }
314
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
315
+ }, [featureKey, user, hackle, initialized]);
316
+ var _b = __read(React.useState(function () {
317
+ if (notExistClient(hackle)) {
318
+ log.error("HackleClient is not existed");
319
+ return Hackle.FeatureFlagDecision.off(Hackle.DecisionReason.EXCEPTION);
320
+ }
321
+ return getFeatureDetail();
322
+ }), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
323
+ var currentInput = {
324
+ key: featureKey,
325
+ user: user,
326
+ initialized: initialized
327
+ };
328
+ var _c = __read(React.useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
329
+ if (!isInputEqual(prevInput, currentInput)) {
330
+ setPrevInput(currentInput);
331
+ setFeatureDetail(getFeatureDetail());
332
+ }
333
+ return {
334
+ isLoading: !initialized,
335
+ decision: featureDetail
336
+ };
337
+ }
246
338
  function useTrack() {
247
339
  var _a = React.useContext(HackleContext), hackle = _a.hackle, user = _a.user;
248
340
  if (notExistClient(hackle)) {
249
- if ((typeof window) !== "undefined") {
250
- log.error("HackleClient is not existed");
251
- }
341
+ log.error("HackleClient is not existed");
252
342
  return function () { };
253
343
  }
254
344
  return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event, user); };
@@ -258,7 +348,8 @@ function notExistClient(hackle) {
258
348
  }
259
349
  function isInputEqual(prev, current) {
260
350
  var _a, _b, _c, _d;
261
- return (prev.key === current.key &&
351
+ return (prev.initialized === current.initialized &&
352
+ prev.key === current.key &&
262
353
  ((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
263
354
  arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
264
355
  }
@@ -283,7 +374,10 @@ function coerceUnknownToProperties(props) {
283
374
 
284
375
  function Experiment(_a) {
285
376
  var experimentKey = _a.experimentKey, children = _a.children;
286
- var variation = useVariation(experimentKey);
377
+ var _b = useLoadableVariation(experimentKey), isLoading = _b.isLoading, variation = _b.variation;
378
+ if (isLoading) {
379
+ return null;
380
+ }
287
381
  if (!!children && typeof children === "function") {
288
382
  return children(variation);
289
383
  }
@@ -312,7 +406,10 @@ function Variation(_a) {
312
406
  var HackleVariation = Variation;
313
407
 
314
408
  var Feature = function (props) {
315
- var featureOn = useFeature(props.featureKey);
409
+ var _a = useLoadableFeature(props.featureKey), isLoading = _a.isLoading, featureOn = _a.isOn;
410
+ if (isLoading) {
411
+ return null;
412
+ }
316
413
  return React__default["default"].createElement(React__default["default"].Fragment, null, props.children(featureOn));
317
414
  };
318
415
  var HackleFeature = Feature;
@@ -327,6 +424,10 @@ exports.HackleVariation = HackleVariation;
327
424
  exports.createInstance = createInstance;
328
425
  exports.useFeature = useFeature;
329
426
  exports.useFeatureFlagDetail = useFeatureFlagDetail;
427
+ exports.useLoadableFeature = useLoadableFeature;
428
+ exports.useLoadableFeatureDetail = useLoadableFeatureDetail;
429
+ exports.useLoadableVariation = useLoadableVariation;
430
+ exports.useLoadableVariationDetail = useLoadableVariationDetail;
330
431
  exports.useTrack = useTrack;
331
432
  exports.useVariation = useVariation;
332
433
  exports.useVariationDetail = useVariationDetail;