@hackler/react-sdk 2.2.4 → 3.1.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/lib/Context.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- /// <reference types="react" />
2
- import { User } from "@hackler/js-client-sdk";
3
- import { HackleReactSDKClient } from "./client";
4
- interface HackleContext {
5
- hackle: HackleReactSDKClient | undefined;
6
- user?: User;
7
- }
8
- export declare const HackleContext: import("react").Context<HackleContext>;
9
- export declare const HackleContextConsumer: import("react").Consumer<HackleContext>;
10
- export declare const HackleContextProvider: import("react").Provider<HackleContext>;
11
- export {};
1
+ /// <reference types="react" />
2
+ import { User } from "@hackler/js-client-sdk";
3
+ import { HackleReactSDKClient } from "./client";
4
+ interface HackleContext {
5
+ hackle: HackleReactSDKClient | undefined;
6
+ user?: User;
7
+ }
8
+ export declare const HackleContext: import("react").Context<HackleContext>;
9
+ export declare const HackleContextConsumer: import("react").Consumer<HackleContext>;
10
+ export declare const HackleContextProvider: import("react").Provider<HackleContext>;
11
+ export {};
12
12
  //# sourceMappingURL=Context.d.ts.map
@@ -1,9 +1,9 @@
1
- import * as React from "react";
2
- export interface ExperimentProps {
3
- experimentKey: number;
4
- children?: React.ReactNode;
5
- }
6
- declare function Experiment({ experimentKey, children }: ExperimentProps): any;
7
- export declare const HackleExperiment: typeof Experiment;
8
- export {};
1
+ import * as React from "react";
2
+ export interface ExperimentProps {
3
+ experimentKey: number;
4
+ children?: React.ReactNode;
5
+ }
6
+ declare function Experiment({ experimentKey, children }: ExperimentProps): any;
7
+ export declare const HackleExperiment: typeof Experiment;
8
+ export {};
9
9
  //# sourceMappingURL=Experiment.d.ts.map
package/lib/Feature.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import React from "react";
2
- import { User } from "@hackler/sdk-core";
3
- export declare type ChildrenFunction = (isOn: boolean) => React.ReactNode;
4
- export interface FeatureProps {
5
- featureKey: number;
6
- user?: User;
7
- children: ChildrenFunction;
8
- }
9
- export declare const HackleFeature: React.FunctionComponent<FeatureProps>;
1
+ import React from "react";
2
+ import { User } from "@hackler/sdk-core";
3
+ export declare type ChildrenFunction = (isOn: boolean) => React.ReactNode;
4
+ export interface FeatureProps {
5
+ featureKey: number;
6
+ user?: User;
7
+ children: ChildrenFunction;
8
+ }
9
+ export declare const HackleFeature: React.FunctionComponent<FeatureProps>;
10
10
  //# sourceMappingURL=Feature.d.ts.map
package/lib/Provider.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { ReactNode } from "react";
2
- import { User } from "@hackler/js-client-sdk";
3
- import { HackleReactSDKClient } from "./client";
4
- interface ProviderProps {
5
- hackleClient: HackleReactSDKClient;
6
- user?: User;
7
- timeout?: number;
8
- children?: ReactNode;
9
- }
10
- export declare function HackleProvider({ hackleClient, user, timeout, children }: ProviderProps): JSX.Element | null;
11
- export {};
1
+ import { ReactNode } from "react";
2
+ import { User } from "@hackler/js-client-sdk";
3
+ import { HackleReactSDKClient } from "./client";
4
+ interface ProviderProps {
5
+ hackleClient: HackleReactSDKClient;
6
+ user?: User;
7
+ timeout?: number;
8
+ children?: ReactNode;
9
+ }
10
+ export declare function HackleProvider({ hackleClient, user, timeout, children }: ProviderProps): JSX.Element | null;
11
+ export {};
12
12
  //# sourceMappingURL=Provider.d.ts.map
@@ -1,10 +1,10 @@
1
- import { ReactNode } from "react";
2
- export interface VariationProps {
3
- variation: string;
4
- default?: any;
5
- children?: ReactNode;
6
- }
7
- declare function Variation({ variation, children }: VariationProps): JSX.Element;
8
- export declare const HackleVariation: typeof Variation;
9
- export {};
1
+ import { ReactNode } from "react";
2
+ export interface VariationProps {
3
+ variation: string;
4
+ default?: any;
5
+ children?: ReactNode;
6
+ }
7
+ declare function Variation({ variation, children }: VariationProps): JSX.Element;
8
+ export declare const HackleVariation: typeof Variation;
9
+ export {};
10
10
  //# sourceMappingURL=Variation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Variation.d.ts","sourceRoot":"","sources":["../src/Variation.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AACD,iBAAS,SAAS,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAE,cAAc,eAEvD;AAED,eAAO,MAAM,eAAe,kBAAY,CAAA"}
1
+ {"version":3,"file":"Variation.d.ts","sourceRoot":"","sources":["../src/Variation.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEjC,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,GAAG,CAAA;IACb,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AACD,iBAAS,SAAS,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAC,EAAE,cAAc,eAEvD;AAED,eAAO,MAAM,eAAe,kBAAY,CAAA"}
package/lib/client.d.ts CHANGED
@@ -1,21 +1,20 @@
1
- import { Event, User } from "@hackler/js-client-sdk";
2
- import { Decision, FeatureFlagDecision } from "@hackler/sdk-core/lib/internal/model/model";
3
- import { PageView } from "@hackler/js-client-sdk/lib/HackleClient";
4
- interface Config {
5
- debug?: boolean;
6
- auto_track_page_view?: boolean;
7
- }
8
- export declare class HackleReactSDKClient {
9
- private client;
10
- constructor(sdkKey: string, config?: Config);
11
- variation(experimentKey: number, user?: User, defaultVariation?: string): string;
12
- variationDetail(experimentKey: number, user?: User, defaultVariation?: string): Decision;
13
- isFeatureOn(featureKey: number, user?: User): boolean;
14
- featureFlagDetail(featureKey: number, user?: User): FeatureFlagDecision;
15
- track(event: string | Event, user?: User): void;
16
- trackPageView(option?: PageView): void;
17
- onReady(cb: any, timeout?: number): void;
18
- }
19
- export declare function createInstance(sdkKey: string, config?: Config): HackleReactSDKClient;
20
- export {};
1
+ import { PageView, User, HackleEvent } from "@hackler/js-client-sdk";
2
+ import { Decision, FeatureFlagDecision } from "@hackler/sdk-core";
3
+ interface Config {
4
+ debug?: boolean;
5
+ auto_track_page_view?: boolean;
6
+ }
7
+ export declare class HackleReactSDKClient {
8
+ private client;
9
+ constructor(sdkKey: string, config?: Config);
10
+ variation(experimentKey: number, user?: User, defaultVariation?: string): string;
11
+ variationDetail(experimentKey: number, user?: User, defaultVariation?: string): Decision;
12
+ isFeatureOn(featureKey: number, user?: User): boolean;
13
+ featureFlagDetail(featureKey: number, user?: User): FeatureFlagDecision;
14
+ track(event: string | HackleEvent, user?: User): void;
15
+ trackPageView(option?: PageView): void;
16
+ onReady(cb: any, timeout?: number): void;
17
+ }
18
+ export declare function createInstance(sdkKey: string, config?: Config): HackleReactSDKClient;
19
+ export {};
21
20
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAgB,IAAI,EAAE,MAAM,wBAAwB,CAAA;AAElE,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAA;AAElE,UAAU,MAAM;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3C,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhF,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,QAAQ;IAIxF,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO;IAIrD,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,mBAAmB;IAIvE,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI;IAI/C,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI;IAItC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM;CAGlC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAEpF"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAGjE,UAAU,MAAM;IACd,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,oBAAoB,CAAC,EAAE,OAAO,CAAA;CAC/B;AAED,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAQ3C,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM;IAIhF,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,EAAE,MAAM,GAAG,QAAQ;IAIxF,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO;IAIrD,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,mBAAmB;IAIvE,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI;IAIrD,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI;IAItC,OAAO,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM;CAGlC;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,oBAAoB,CAEpF"}
package/lib/config.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare const SDK_NAME_HEADER = "react-sdk";
2
- export declare const SDK_VERSION_HEADER = "2.2.4";
1
+ export declare const SDK_NAME_HEADER = "react-sdk";
2
+ export declare const SDK_VERSION_HEADER = "3.1.0";
3
3
  //# sourceMappingURL=config.d.ts.map
package/lib/hooks.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { Event } from "@hackler/js-client-sdk";
2
- import { PageView } from "@hackler/js-client-sdk/lib/HackleClient";
3
- import { Decision, FeatureFlagDecision } from "@hackler/sdk-core/lib/internal/model/model";
4
- export declare function useVariation(experimentKey: number, defaultVariation?: string): string;
5
- export declare function useVariationDetail(experimentKey: number, defaultVariation?: string): Decision;
6
- export declare function useFeature(featureKey: number): boolean;
7
- export declare function useFeatureFlagDetail(featureKey: number): FeatureFlagDecision;
8
- interface Track {
9
- (event: Event): void;
10
- }
11
- export declare function useTrack(): Track;
12
- interface TrackPageView {
13
- (option?: PageView): void;
14
- }
15
- export declare function usePageView(): TrackPageView;
16
- export {};
1
+ import { HackleEvent, PageView } from "@hackler/js-client-sdk";
2
+ import { Decision, FeatureFlagDecision } from "@hackler/sdk-core";
3
+ export declare function useVariation(experimentKey: number, defaultVariation?: string): string;
4
+ export declare function useVariationDetail(experimentKey: number, defaultVariation?: string): Decision;
5
+ export declare function useFeature(featureKey: number): boolean;
6
+ export declare function useFeatureFlagDetail(featureKey: number): FeatureFlagDecision;
7
+ interface Track {
8
+ (event: HackleEvent): void;
9
+ }
10
+ export declare function useTrack(): Track;
11
+ interface TrackPageView {
12
+ (option?: PageView): void;
13
+ }
14
+ export declare function usePageView(): TrackPageView;
15
+ export {};
17
16
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAQ,MAAM,wBAAwB,CAAA;AAGpD,OAAO,EAAE,QAAQ,EAAE,MAAM,yCAAyC,CAAA;AAElE,OAAO,EAAE,QAAQ,EAAkB,mBAAmB,EAAE,MAAM,4CAA4C,CAAA;AAK1G,wBAAgB,YAAY,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,MAAM,CA2BlF;AAED,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,SAAM,GAAG,QAAQ,CA2B1F;AAED,wBAAgB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CA2BtD;AAED,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,mBAAmB,CA2B5E;AAED,UAAU,KAAK;IACb,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CACrB;AACD,wBAAgB,QAAQ,IAAI,KAAK,CAShC;AAED,UAAU,aAAa;IACrB,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAA;CAC1B;AACD,wBAAgB,WAAW,IAAI,aAAa,CAkB3C"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAQ,WAAW,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAIrE,OAAO,EAAE,QAAQ,EAAkB,mBAAmB,EAAU,MAAM,mBAAmB,CAAA;AAIzF,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.d.ts","sourceRoot":"","sources":["../src/index.cjs.ts"],"names":[],"mappings":""}
package/lib/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- export { createInstance } from "./client";
2
- export { HackleProvider } from "./Provider";
3
- export { HackleContext, HackleContextProvider, HackleContextConsumer } from "./Context";
4
- export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail } from "./hooks";
5
- export { HackleExperiment } from "./Experiment";
6
- export { HackleVariation } from "./Variation";
7
- export { getUserId } from "@hackler/js-client-sdk";
1
+ export { createInstance } from "./client";
2
+ export { HackleProvider } from "./Provider";
3
+ export { HackleContext, HackleContextProvider, HackleContextConsumer } from "./Context";
4
+ export { useVariation, useVariationDetail, useTrack, useFeature, useFeatureFlagDetail } from "./hooks";
5
+ export { HackleExperiment } from "./Experiment";
6
+ export { HackleVariation } from "./Variation";
7
+ export * from "@hackler/js-client-sdk";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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,SAAS,EAAE,MAAM,wBAAwB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,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;AAE7C,cAAc,wBAAwB,CAAA"}
@@ -0,0 +1,279 @@
1
+ import * as Hackle from '@hackler/js-client-sdk';
2
+ export * from '@hackler/js-client-sdk';
3
+ import * as React from 'react';
4
+ import React__default, { createContext, useState, useEffect, useContext, useCallback } from 'react';
5
+ import { Logger, Decision, DecisionReason, FeatureFlagDecision } from '@hackler/sdk-core';
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+
22
+ var __assign = function() {
23
+ __assign = Object.assign || function __assign(t) {
24
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
25
+ s = arguments[i];
26
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
+ }
28
+ return t;
29
+ };
30
+ return __assign.apply(this, arguments);
31
+ };
32
+
33
+ function __read(o, n) {
34
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
35
+ if (!m) return o;
36
+ var i = m.call(o), r, ar = [], e;
37
+ try {
38
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
39
+ }
40
+ catch (error) { e = { error: error }; }
41
+ finally {
42
+ try {
43
+ if (r && !r.done && (m = i["return"])) m.call(i);
44
+ }
45
+ finally { if (e) throw e.error; }
46
+ }
47
+ return ar;
48
+ }
49
+
50
+ var SDK_NAME_HEADER = "react-sdk";
51
+ var SDK_VERSION_HEADER = "3.1.0";
52
+
53
+ var HackleReactSDKClient = /** @class */ (function () {
54
+ function HackleReactSDKClient(sdkKey, config) {
55
+ this.client = Hackle.createInstance(sdkKey, __assign(__assign({}, config), { SDK_NAME_HEADER: SDK_NAME_HEADER, SDK_VERSION_HEADER: SDK_VERSION_HEADER }));
56
+ }
57
+ HackleReactSDKClient.prototype.variation = function (experimentKey, user, defaultVariation) {
58
+ return this.client.variation(experimentKey, user, defaultVariation);
59
+ };
60
+ HackleReactSDKClient.prototype.variationDetail = function (experimentKey, user, defaultVariation) {
61
+ return this.client.variationDetail(experimentKey, user, defaultVariation);
62
+ };
63
+ HackleReactSDKClient.prototype.isFeatureOn = function (featureKey, user) {
64
+ return this.client.isFeatureOn(featureKey, user);
65
+ };
66
+ HackleReactSDKClient.prototype.featureFlagDetail = function (featureKey, user) {
67
+ return this.client.featureFlagDetail(featureKey, user);
68
+ };
69
+ HackleReactSDKClient.prototype.track = function (event, user) {
70
+ this.client.track(event, user);
71
+ };
72
+ HackleReactSDKClient.prototype.trackPageView = function (option) {
73
+ this.client.trackPageView(option);
74
+ };
75
+ HackleReactSDKClient.prototype.onReady = function (cb, timeout) {
76
+ this.client.onReady(cb, timeout);
77
+ };
78
+ return HackleReactSDKClient;
79
+ }());
80
+ function createInstance(sdkKey, config) {
81
+ return new HackleReactSDKClient(sdkKey, config);
82
+ }
83
+
84
+ var HackleContext = createContext({
85
+ hackle: undefined,
86
+ user: undefined,
87
+ });
88
+ var HackleContextConsumer = HackleContext.Consumer;
89
+ var HackleContextProvider = HackleContext.Provider;
90
+
91
+ function HackleProvider(_a) {
92
+ var hackleClient = _a.hackleClient, user = _a.user, _b = _a.timeout, timeout = _b === void 0 ? 3000 : _b, children = _a.children;
93
+ var state = {
94
+ hackle: hackleClient,
95
+ user: user,
96
+ };
97
+ var _c = __read(useState(false), 2), ready = _c[0], setReady = _c[1];
98
+ var _d = __read(useState(state), 2), value = _d[0], setValue = _d[1];
99
+ useEffect(function () {
100
+ setValue(function (prevState) {
101
+ return __assign(__assign({}, prevState), { user: user });
102
+ });
103
+ }, [user]);
104
+ hackleClient.onReady(function () { return setReady(true); }, timeout);
105
+ return ready ? React__default.createElement(HackleContextProvider, { value: value }, children) : null;
106
+ }
107
+
108
+ var log = Logger.log;
109
+ function useVariation(experimentKey, defaultVariation) {
110
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
111
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
112
+ var getVariation = useCallback(function () {
113
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.variation(experimentKey, user)) || defaultVariation;
114
+ }, [defaultVariation, experimentKey, user, hackle]);
115
+ var _b = __read(useState(function () {
116
+ if (notExistClient(hackle)) {
117
+ if ((typeof window) !== "undefined") {
118
+ log.error("HackleClient is not existed");
119
+ }
120
+ return defaultVariation;
121
+ }
122
+ return getVariation();
123
+ }), 2), variation = _b[0], setVariation = _b[1];
124
+ var currentInput = {
125
+ key: experimentKey,
126
+ user: user
127
+ };
128
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
129
+ if (!isInputEqual(prevInput, currentInput)) {
130
+ setPrevInput(currentInput);
131
+ setVariation(getVariation());
132
+ }
133
+ return variation;
134
+ }
135
+ function useVariationDetail(experimentKey, defaultVariation) {
136
+ if (defaultVariation === void 0) { defaultVariation = "A"; }
137
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
138
+ var getVariationDetail = useCallback(function () {
139
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.variationDetail(experimentKey, user)) || Decision.of(defaultVariation, DecisionReason.EXCEPTION);
140
+ }, [defaultVariation, experimentKey, user, hackle]);
141
+ var _b = __read(useState(function () {
142
+ if (notExistClient(hackle)) {
143
+ if ((typeof window) !== "undefined") {
144
+ log.error("HackleClient is not existed");
145
+ }
146
+ return Decision.of(defaultVariation, DecisionReason.EXCEPTION);
147
+ }
148
+ return getVariationDetail();
149
+ }), 2), variationDetail = _b[0], setVariationDetail = _b[1];
150
+ var currentInput = {
151
+ key: experimentKey,
152
+ user: user
153
+ };
154
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
155
+ if (!isInputEqual(prevInput, currentInput)) {
156
+ setPrevInput(currentInput);
157
+ setVariationDetail(getVariationDetail());
158
+ }
159
+ return variationDetail;
160
+ }
161
+ function useFeature(featureKey) {
162
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
163
+ var getIsOn = useCallback(function () {
164
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.isFeatureOn(featureKey, user)) || false;
165
+ }, [featureKey, user, hackle]);
166
+ var _b = __read(useState(function () {
167
+ if (notExistClient(hackle)) {
168
+ if ((typeof window) !== "undefined") {
169
+ log.error("HackleClient is not existed");
170
+ }
171
+ return false;
172
+ }
173
+ return getIsOn();
174
+ }), 2), isOn = _b[0], setIsOn = _b[1];
175
+ var currentInput = {
176
+ key: featureKey,
177
+ user: user,
178
+ };
179
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
180
+ if (!isInputEqual(prevInput, currentInput)) {
181
+ setPrevInput(currentInput);
182
+ setIsOn(getIsOn());
183
+ }
184
+ return isOn;
185
+ }
186
+ function useFeatureFlagDetail(featureKey) {
187
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
188
+ var getFeatureDetail = useCallback(function () {
189
+ return (hackle === null || hackle === void 0 ? void 0 : hackle.featureFlagDetail(featureKey, user)) || FeatureFlagDecision.off(DecisionReason.EXCEPTION);
190
+ }, [featureKey, user, hackle]);
191
+ var _b = __read(useState(function () {
192
+ if (notExistClient(hackle)) {
193
+ if ((typeof window) !== "undefined") {
194
+ log.error("HackleClient is not existed");
195
+ }
196
+ return FeatureFlagDecision.off(DecisionReason.EXCEPTION);
197
+ }
198
+ return getFeatureDetail();
199
+ }), 2), featureDetail = _b[0], setFeatureDetail = _b[1];
200
+ var currentInput = {
201
+ key: featureKey,
202
+ user: user,
203
+ };
204
+ var _c = __read(useState(currentInput), 2), prevInput = _c[0], setPrevInput = _c[1];
205
+ if (!isInputEqual(prevInput, currentInput)) {
206
+ setPrevInput(currentInput);
207
+ setFeatureDetail(getFeatureDetail());
208
+ }
209
+ return featureDetail;
210
+ }
211
+ function useTrack() {
212
+ var _a = useContext(HackleContext), hackle = _a.hackle, user = _a.user;
213
+ if (notExistClient(hackle)) {
214
+ if ((typeof window) !== "undefined") {
215
+ log.error("HackleClient is not existed");
216
+ }
217
+ return function () { };
218
+ }
219
+ return function (event) { return hackle === null || hackle === void 0 ? void 0 : hackle.track(event, user); };
220
+ }
221
+ function notExistClient(hackle) {
222
+ return !hackle;
223
+ }
224
+ function isInputEqual(prev, current) {
225
+ var _a, _b, _c, _d;
226
+ return (prev.key === current.key &&
227
+ ((_a = prev.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = current.user) === null || _b === void 0 ? void 0 : _b.id) &&
228
+ arePropertiesEqual((_c = prev.user) === null || _c === void 0 ? void 0 : _c.properties, (_d = current.user) === null || _d === void 0 ? void 0 : _d.properties));
229
+ }
230
+ function arePropertiesEqual(prevProps, currentProps) {
231
+ var prev = coerceUnknownToProperties(prevProps);
232
+ var current = coerceUnknownToProperties(currentProps);
233
+ var prevKeys = Object.keys(prev);
234
+ var currentKeys = Object.keys(current);
235
+ if (prevKeys.length !== currentKeys.length) {
236
+ return false;
237
+ }
238
+ return prevKeys.every(function (it) {
239
+ return it in current && prev[it] === current[it];
240
+ });
241
+ }
242
+ function coerceUnknownToProperties(props) {
243
+ if (typeof props === "object" && props !== null) {
244
+ return props;
245
+ }
246
+ return {};
247
+ }
248
+
249
+ function Experiment(_a) {
250
+ var experimentKey = _a.experimentKey, children = _a.children;
251
+ var variation = useVariation(experimentKey);
252
+ if (!!children && typeof children === "function") {
253
+ return children(variation);
254
+ }
255
+ var match;
256
+ React.Children.forEach(children, (function (it) {
257
+ if (!React.isValidElement(it)) {
258
+ return;
259
+ }
260
+ if (it.props.variation) {
261
+ if (variation === it.props.variation) {
262
+ match = it;
263
+ }
264
+ }
265
+ else if (it.props.default) {
266
+ match = it;
267
+ }
268
+ }));
269
+ return match ? React.cloneElement(match, { variation: variation }) : null;
270
+ }
271
+ var HackleExperiment = Experiment;
272
+
273
+ function Variation(_a) {
274
+ _a.variation; var children = _a.children;
275
+ return React.createElement(React.Fragment, null, children);
276
+ }
277
+ var HackleVariation = Variation;
278
+
279
+ export { HackleContext, HackleContextConsumer, HackleContextProvider, HackleExperiment, HackleProvider, HackleVariation, createInstance, useFeature, useFeatureFlagDetail, useTrack, useVariation, useVariationDetail };