@kameleoon/react-sdk 1.2.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.
Files changed (138) hide show
  1. package/LICENSE.md +165 -0
  2. package/README.md +1172 -0
  3. package/dist/Feature.d.ts +11 -0
  4. package/dist/Feature.js +26 -0
  5. package/dist/Feature.js.map +1 -0
  6. package/dist/KameleoonContext.d.ts +3 -0
  7. package/dist/KameleoonContext.js +6 -0
  8. package/dist/KameleoonContext.js.map +1 -0
  9. package/dist/KameleoonProvider.d.ts +14 -0
  10. package/dist/KameleoonProvider.js +25 -0
  11. package/dist/KameleoonProvider.js.map +1 -0
  12. package/dist/ProviderError.d.ts +3 -0
  13. package/dist/ProviderError.js +29 -0
  14. package/dist/ProviderError.js.map +1 -0
  15. package/dist/compose.d.ts +8 -0
  16. package/dist/compose.js +33 -0
  17. package/dist/compose.js.map +1 -0
  18. package/dist/constants.d.ts +13 -0
  19. package/dist/constants.js +19 -0
  20. package/dist/constants.js.map +1 -0
  21. package/dist/index.d.ts +37 -0
  22. package/dist/index.js +85 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/kameleoonClient.d.ts +16 -0
  25. package/dist/kameleoonClient.js +17 -0
  26. package/dist/kameleoonClient.js.map +1 -0
  27. package/dist/stories/Form.d.ts +22 -0
  28. package/dist/stories/Form.js +97 -0
  29. package/dist/stories/Form.js.map +1 -0
  30. package/dist/stories/FormHOC.d.ts +2 -0
  31. package/dist/stories/FormHOC.js +36 -0
  32. package/dist/stories/FormHOC.js.map +1 -0
  33. package/dist/stories/FormHook.d.ts +2 -0
  34. package/dist/stories/FormHook.js +61 -0
  35. package/dist/stories/FormHook.js.map +1 -0
  36. package/dist/stories/FormRenderProps.d.ts +3 -0
  37. package/dist/stories/FormRenderProps.js +24 -0
  38. package/dist/stories/FormRenderProps.js.map +1 -0
  39. package/dist/stories/Radio.d.ts +8 -0
  40. package/dist/stories/Radio.js +9 -0
  41. package/dist/stories/Radio.js.map +1 -0
  42. package/dist/stories/constants.d.ts +13 -0
  43. package/dist/stories/constants.js +18 -0
  44. package/dist/stories/constants.js.map +1 -0
  45. package/dist/types.d.ts +20 -0
  46. package/dist/types.js +4 -0
  47. package/dist/types.js.map +1 -0
  48. package/dist/useActivateFeature.d.ts +12 -0
  49. package/dist/useActivateFeature.js +23 -0
  50. package/dist/useActivateFeature.js.map +1 -0
  51. package/dist/useAddData.d.ts +14 -0
  52. package/dist/useAddData.js +33 -0
  53. package/dist/useAddData.js.map +1 -0
  54. package/dist/useBrowser.d.ts +13 -0
  55. package/dist/useBrowser.js +22 -0
  56. package/dist/useBrowser.js.map +1 -0
  57. package/dist/useConversion.d.ts +14 -0
  58. package/dist/useConversion.js +18 -0
  59. package/dist/useConversion.js.map +1 -0
  60. package/dist/useCustomData.d.ts +13 -0
  61. package/dist/useCustomData.js +18 -0
  62. package/dist/useCustomData.js.map +1 -0
  63. package/dist/useFeature.d.ts +5 -0
  64. package/dist/useFeature.js +75 -0
  65. package/dist/useFeature.js.map +1 -0
  66. package/dist/useFeatureVariable.d.ts +13 -0
  67. package/dist/useFeatureVariable.js +36 -0
  68. package/dist/useFeatureVariable.js.map +1 -0
  69. package/dist/useFlush.d.ts +11 -0
  70. package/dist/useFlush.js +19 -0
  71. package/dist/useFlush.js.map +1 -0
  72. package/dist/useInterest.d.ts +12 -0
  73. package/dist/useInterest.js +16 -0
  74. package/dist/useInterest.js.map +1 -0
  75. package/dist/useKameleoon.d.ts +10 -0
  76. package/dist/useKameleoon.js +20 -0
  77. package/dist/useKameleoon.js.map +1 -0
  78. package/dist/usePageView.d.ts +14 -0
  79. package/dist/usePageView.js +18 -0
  80. package/dist/usePageView.js.map +1 -0
  81. package/dist/useTrackingConversion.d.ts +13 -0
  82. package/dist/useTrackingConversion.js +19 -0
  83. package/dist/useTrackingConversion.js.map +1 -0
  84. package/dist/useTriggerExperiment.d.ts +15 -0
  85. package/dist/useTriggerExperiment.js +22 -0
  86. package/dist/useTriggerExperiment.js.map +1 -0
  87. package/dist/useVariationAssociatedData.d.ts +14 -0
  88. package/dist/useVariationAssociatedData.js +21 -0
  89. package/dist/useVariationAssociatedData.js.map +1 -0
  90. package/dist/useVisitorCode.d.ts +12 -0
  91. package/dist/useVisitorCode.js +19 -0
  92. package/dist/useVisitorCode.js.map +1 -0
  93. package/dist/withActivateFeature.d.ts +15 -0
  94. package/dist/withActivateFeature.js +37 -0
  95. package/dist/withActivateFeature.js.map +1 -0
  96. package/dist/withAddData.d.ts +16 -0
  97. package/dist/withAddData.js +49 -0
  98. package/dist/withAddData.js.map +1 -0
  99. package/dist/withBrowser.d.ts +16 -0
  100. package/dist/withBrowser.js +36 -0
  101. package/dist/withBrowser.js.map +1 -0
  102. package/dist/withConversion.d.ts +17 -0
  103. package/dist/withConversion.js +32 -0
  104. package/dist/withConversion.js.map +1 -0
  105. package/dist/withCustomData.d.ts +16 -0
  106. package/dist/withCustomData.js +32 -0
  107. package/dist/withCustomData.js.map +1 -0
  108. package/dist/withFeature.d.ts +6 -0
  109. package/dist/withFeature.js +31 -0
  110. package/dist/withFeature.js.map +1 -0
  111. package/dist/withFeatureVariable.d.ts +15 -0
  112. package/dist/withFeatureVariable.js +28 -0
  113. package/dist/withFeatureVariable.js.map +1 -0
  114. package/dist/withFlush.d.ts +14 -0
  115. package/dist/withFlush.js +36 -0
  116. package/dist/withFlush.js.map +1 -0
  117. package/dist/withInterest.d.ts +15 -0
  118. package/dist/withInterest.js +31 -0
  119. package/dist/withInterest.js.map +1 -0
  120. package/dist/withKameleoon.d.ts +13 -0
  121. package/dist/withKameleoon.js +34 -0
  122. package/dist/withKameleoon.js.map +1 -0
  123. package/dist/withPageView.d.ts +17 -0
  124. package/dist/withPageView.js +31 -0
  125. package/dist/withPageView.js.map +1 -0
  126. package/dist/withTrackingConversion.d.ts +16 -0
  127. package/dist/withTrackingConversion.js +36 -0
  128. package/dist/withTrackingConversion.js.map +1 -0
  129. package/dist/withTriggerExperiment.d.ts +17 -0
  130. package/dist/withTriggerExperiment.js +38 -0
  131. package/dist/withTriggerExperiment.js.map +1 -0
  132. package/dist/withVariationAssociatedData.d.ts +17 -0
  133. package/dist/withVariationAssociatedData.js +39 -0
  134. package/dist/withVariationAssociatedData.js.map +1 -0
  135. package/dist/withVisitorCode.d.ts +15 -0
  136. package/dist/withVisitorCode.js +36 -0
  137. package/dist/withVisitorCode.js.map +1 -0
  138. package/package.json +47 -0
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withFlush = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var ProviderError_1 = require("./ProviderError");
18
+ var KameleoonContext_1 = require("./KameleoonContext");
19
+ /**
20
+ * A React HOC that gives a wrapped component access to callback function
21
+ * which allows to flush data to servers
22
+ */
23
+ function withFlush(Component) {
24
+ return function WrappedComponent(props) {
25
+ var client = (0, react_1.useContext)(KameleoonContext_1.KameleoonContext);
26
+ var flush = (0, react_1.useCallback)(function (visitorCode) {
27
+ if (!client) {
28
+ throw new ProviderError_1.ProviderError('withFlush');
29
+ }
30
+ client.flush(visitorCode);
31
+ }, [client]);
32
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ flush: flush }, props), void 0);
33
+ };
34
+ }
35
+ exports.withFlush = withFlush;
36
+ //# sourceMappingURL=withFlush.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withFlush.js","sourceRoot":"","sources":["../src/withFlush.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuD;AACvD,iDAAgD;AAEhD,uDAAsD;AAStD;;;GAGG;AACH,SAAgB,SAAS,CACvB,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mCAAgB,CAAC,CAAC;QAE5C,IAAM,KAAK,GAAG,IAAA,mBAAW,EACvB,UAAC,WAAmB;YAClB,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,6BAAa,CAAC,WAAW,CAAC,CAAC;aACtC;YACD,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;QAEF,OAAO,uBAAC,SAAS,aAAC,KAAK,EAAE,KAAK,IAAO,KAAe,UAAI,CAAC;IAC3D,CAAC,CAAC;AACJ,CAAC;AAlBD,8BAkBC"}
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { Interest } from 'kameleoon-client-javascript/dist/data';
3
+ import { UnknownPropsType, Without } from './types';
4
+ interface IWithInterest {
5
+ /**
6
+ * @param index - index of interest
7
+ */
8
+ addInterest: (index: number) => Interest;
9
+ }
10
+ /**
11
+ * A React HOC that gives a wrapped component access to callback function
12
+ * which adds interest
13
+ */
14
+ export declare function withInterest<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithInterest>>;
15
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withInterest = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var kameleoon_client_javascript_1 = require("kameleoon-client-javascript");
18
+ /**
19
+ * A React HOC that gives a wrapped component access to callback function
20
+ * which adds interest
21
+ */
22
+ function withInterest(Component) {
23
+ return function WrappedComponent(props) {
24
+ var addInterest = (0, react_1.useCallback)(function (index) {
25
+ return new kameleoon_client_javascript_1.KameleoonData.Interest(index);
26
+ }, []);
27
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ addInterest: addInterest }, props), void 0);
28
+ };
29
+ }
30
+ exports.withInterest = withInterest;
31
+ //# sourceMappingURL=withInterest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withInterest.js","sourceRoot":"","sources":["../src/withInterest.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA2C;AAE3C,2EAA4D;AAU5D;;;GAGG;AACH,SAAgB,YAAY,CAC1B,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,WAAW,GAAG,IAAA,mBAAW,EAAC,UAAC,KAAa;YAC5C,OAAO,IAAI,2CAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,uBAAC,SAAS,aAAC,WAAW,EAAE,WAAW,IAAO,KAAe,UAAI,CAAC;IACvE,CAAC,CAAC;AACJ,CAAC;AAVD,oCAUC"}
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { KameleoonClient } from 'kameleoon-client-javascript';
3
+ import { UnknownPropsType, Without } from './types';
4
+ interface IWithKameleoonProps {
5
+ /** An instance of KameleoonClient */
6
+ client: KameleoonClient;
7
+ }
8
+ /**
9
+ * A React HOC that gives a wrapped component direct access
10
+ * to Kameleoon client via props
11
+ */
12
+ export declare function withKameleoon<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithKameleoonProps>>;
13
+ export {};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withKameleoon = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var KameleoonContext_1 = require("./KameleoonContext");
18
+ var ProviderError_1 = require("./ProviderError");
19
+ ;
20
+ /**
21
+ * A React HOC that gives a wrapped component direct access
22
+ * to Kameleoon client via props
23
+ */
24
+ function withKameleoon(Component) {
25
+ return function WrappedComponent(props) {
26
+ var client = (0, react_1.useContext)(KameleoonContext_1.KameleoonContext);
27
+ if (!client) {
28
+ throw new ProviderError_1.ProviderError('withKameleoon');
29
+ }
30
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ client: client }, props), void 0);
31
+ };
32
+ }
33
+ exports.withKameleoon = withKameleoon;
34
+ //# sourceMappingURL=withKameleoon.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withKameleoon.js","sourceRoot":"","sources":["../src/withKameleoon.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA0C;AAE1C,uDAAsD;AACtD,iDAAgD;AAM/C,CAAC;AAEF;;;GAGG;AACH,SAAgB,aAAa,CAC3B,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mCAAgB,CAAC,CAAC;QAE5C,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,IAAI,6BAAa,CAAC,eAAe,CAAC,CAAC;SAC1C;QAED,OAAO,uBAAC,SAAS,aAAC,MAAM,EAAE,MAAM,IAAO,KAAe,UAAI,CAAC;IAC7D,CAAC,CAAC;AACJ,CAAC;AAZD,sCAYC"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { PageView } from 'kameleoon-client-javascript/dist/data';
3
+ import { UnknownPropsType, Without } from './types';
4
+ interface IWithPageView {
5
+ /**
6
+ * @param url - URL of the page viewed
7
+ * @param title - title of the page viewed
8
+ * @param referrer - referrer of the page viewed
9
+ */
10
+ addPageView: (url: string, title: string, referrer?: number) => PageView;
11
+ }
12
+ /**
13
+ * A React HOC that gives a wrapped component access to callback function
14
+ * which adds page view
15
+ */
16
+ export declare function withPageView<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithPageView>>;
17
+ export {};
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withPageView = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var kameleoon_client_javascript_1 = require("kameleoon-client-javascript");
18
+ /**
19
+ * A React HOC that gives a wrapped component access to callback function
20
+ * which adds page view
21
+ */
22
+ function withPageView(Component) {
23
+ return function WrappedComponent(props) {
24
+ var addPageView = (0, react_1.useCallback)(function (url, title, referrer) {
25
+ return new kameleoon_client_javascript_1.KameleoonData.PageView(url, title, referrer);
26
+ }, []);
27
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ addPageView: addPageView }, props), void 0);
28
+ };
29
+ }
30
+ exports.withPageView = withPageView;
31
+ //# sourceMappingURL=withPageView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withPageView.js","sourceRoot":"","sources":["../src/withPageView.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAA2C;AAE3C,2EAA4D;AAY5D;;;GAGG;AACH,SAAgB,YAAY,CAC1B,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,WAAW,GAAG,IAAA,mBAAW,EAAC,UAAC,GAAW,EAAE,KAAa,EAAE,QAAiB;YAC5E,OAAO,IAAI,2CAAa,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC1D,CAAC,EAAE,EAAE,CAAC,CAAC;QAEP,OAAO,uBAAC,SAAS,aAAC,WAAW,EAAE,WAAW,IAAO,KAAe,UAAI,CAAC;IACvE,CAAC,CAAC;AACJ,CAAC;AAVD,oCAUC"}
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { UnknownPropsType, Without } from './types';
3
+ interface IWithTrackingConversion {
4
+ /**
5
+ * @param visitorCode - unique identifier of the user
6
+ * @param goalId - unique identifier of the goal
7
+ * @param revenue - revenue of the conversion
8
+ */
9
+ trackConversion: (visitorCode: string, goalId: number, revenue?: number) => void;
10
+ }
11
+ /**
12
+ * A React HOC that gives a wrapped component access access to callback function
13
+ * which tracks conversion
14
+ */
15
+ export declare function withTrackingConversion<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithTrackingConversion>>;
16
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withTrackingConversion = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var ProviderError_1 = require("./ProviderError");
18
+ var _1 = require("./");
19
+ /**
20
+ * A React HOC that gives a wrapped component access access to callback function
21
+ * which tracks conversion
22
+ */
23
+ function withTrackingConversion(Component) {
24
+ return function WrappedComponent(props) {
25
+ var client = (0, react_1.useContext)(_1.KameleoonContext);
26
+ var trackConversion = (0, react_1.useCallback)(function (visitorCode, goalId, revenue) {
27
+ if (!client) {
28
+ throw new ProviderError_1.ProviderError('withTrackingConversion');
29
+ }
30
+ return client.trackConversion(visitorCode, goalId, revenue);
31
+ }, [client]);
32
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ trackConversion: trackConversion }, props), void 0);
33
+ };
34
+ }
35
+ exports.withTrackingConversion = withTrackingConversion;
36
+ //# sourceMappingURL=withTrackingConversion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withTrackingConversion.js","sourceRoot":"","sources":["../src/withTrackingConversion.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuD;AAEvD,iDAAgD;AAChD,uBAAsC;AAWtC;;;GAGG;AACH,SAAgB,sBAAsB,CACpC,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mBAAgB,CAAC,CAAC;QAE5C,IAAM,eAAe,GAAG,IAAA,mBAAW,EAAC,UAAC,WAAmB,EAAE,MAAc,EAAE,OAAgB;YACxF,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,6BAAa,CAAC,wBAAwB,CAAC,CAAC;aACnD;YAED,OAAO,MAAM,CAAC,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC9D,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAEb,OAAO,uBAAC,SAAS,aAAC,eAAe,EAAE,eAAe,IAAO,KAAe,UAAI,CAAC;IAC/E,CAAC,CAAC;AACJ,CAAC;AAhBD,wDAgBC"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { UnknownPropsType, Without } from './types';
3
+ interface IWithTriggerExperiment {
4
+ /**
5
+ * @param visitorCode - unique identifier of the user
6
+ * @param experimentId - unique identifier of the experiment you want to expose to a user
7
+ */
8
+ getVariationId: (visitorCode: string, experimentId: number) => number;
9
+ }
10
+ /**
11
+ * A React HOC that gives a wrapped component access access to callback function which triggers experiment
12
+ * If such a user has never been associated with any variation, the SDK returns a randomly selected variation.
13
+ * If a user with a given visitorCode is already registered with a variation,
14
+ * it will detect the previously registered variation and return the variationID
15
+ */
16
+ export declare function withTriggerExperiment<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithTriggerExperiment>>;
17
+ export {};
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withTriggerExperiment = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var KameleoonContext_1 = require("./KameleoonContext");
18
+ var ProviderError_1 = require("./ProviderError");
19
+ /**
20
+ * A React HOC that gives a wrapped component access access to callback function which triggers experiment
21
+ * If such a user has never been associated with any variation, the SDK returns a randomly selected variation.
22
+ * If a user with a given visitorCode is already registered with a variation,
23
+ * it will detect the previously registered variation and return the variationID
24
+ */
25
+ function withTriggerExperiment(Component) {
26
+ return function WrappedComponent(props) {
27
+ var client = (0, react_1.useContext)(KameleoonContext_1.KameleoonContext);
28
+ var getVariationId = (0, react_1.useCallback)(function (visitorCode, experimentId) {
29
+ if (!client) {
30
+ throw new ProviderError_1.ProviderError('withTriggerExperiment');
31
+ }
32
+ return client.triggerExperiment(visitorCode, experimentId);
33
+ }, [client]);
34
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ getVariationId: getVariationId }, props), void 0);
35
+ };
36
+ }
37
+ exports.withTriggerExperiment = withTriggerExperiment;
38
+ //# sourceMappingURL=withTriggerExperiment.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withTriggerExperiment.js","sourceRoot":"","sources":["../src/withTriggerExperiment.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuD;AAEvD,uDAAsD;AACtD,iDAAgD;AAUhD;;;;;GAKG;AACH,SAAgB,qBAAqB,CACnC,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mCAAgB,CAAC,CAAC;QAE5C,IAAM,cAAc,GAAG,IAAA,mBAAW,EAAC,UAAC,WAAmB,EAAE,YAAoB;YAC3E,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,6BAAa,CAAC,uBAAuB,CAAC,CAAC;aAClD;YAED,OAAO,MAAM,CAAC,iBAAiB,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;QAC7D,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAEb,OAAO,uBAAC,SAAS,aAAC,cAAc,EAAE,cAAc,IAAO,KAAe,UAAI,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC;AAhBD,sDAgBC"}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { UnknownPropsType, Without } from './types';
3
+ import { AnyType } from './types';
4
+ interface IWithVariationAssociatedData {
5
+ /**
6
+ * @param variationId - unique identifier of the variation you want to obtain associated data for
7
+ */
8
+ getVariationAssociatedData: (variationId: number) => AnyType;
9
+ }
10
+ /**
11
+ * A React HOC that gives a wrapped component access to callback function which
12
+ * retrieves JSON data associated with a variation.
13
+ * The JSON data usually represents some metadata of the variation,
14
+ * and can be configured on our web application interface or via our Automation API.
15
+ */
16
+ export declare function withVariationAssociatedData<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithVariationAssociatedData>>;
17
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withVariationAssociatedData = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var KameleoonContext_1 = require("./KameleoonContext");
18
+ var ProviderError_1 = require("./ProviderError");
19
+ ;
20
+ /**
21
+ * A React HOC that gives a wrapped component access to callback function which
22
+ * retrieves JSON data associated with a variation.
23
+ * The JSON data usually represents some metadata of the variation,
24
+ * and can be configured on our web application interface or via our Automation API.
25
+ */
26
+ function withVariationAssociatedData(Component) {
27
+ return function WrappedComponent(props) {
28
+ var client = (0, react_1.useContext)(KameleoonContext_1.KameleoonContext);
29
+ var getVariationAssociatedData = (0, react_1.useCallback)(function (variationId) {
30
+ if (!client) {
31
+ throw new ProviderError_1.ProviderError('withVariationAssociatedData');
32
+ }
33
+ return client.obtainVariationAssociatedData(variationId);
34
+ }, [client]);
35
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ getVariationAssociatedData: getVariationAssociatedData }, props), void 0);
36
+ };
37
+ }
38
+ exports.withVariationAssociatedData = withVariationAssociatedData;
39
+ //# sourceMappingURL=withVariationAssociatedData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withVariationAssociatedData.js","sourceRoot":"","sources":["../src/withVariationAssociatedData.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuD;AAEvD,uDAAsD;AACtD,iDAAgD;AAQ/C,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CACzC,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mCAAgB,CAAC,CAAC;QAE5C,IAAM,0BAA0B,GAAG,IAAA,mBAAW,EAAC,UAAC,WAAmB;YACjE,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,6BAAa,CAAC,6BAA6B,CAAC,CAAC;aACxD;YACD,OAAO,MAAM,CAAC,6BAA6B,CAAC,WAAW,CAAC,CAAC;QAC3D,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QAEb,OAAO,uBAAC,SAAS,aAAC,0BAA0B,EAAE,0BAA0B,IAAO,KAAe,UAAI,CAAC;IACrG,CAAC,CAAC;AACJ,CAAC;AAfD,kEAeC"}
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { UnknownPropsType, Without } from './types';
3
+ interface IWithVisitorCode {
4
+ /**
5
+ * @param topLevelDomain - current top level domain for the concerned site
6
+ * @param defaultVisitorCode - this parameter will be used as the visitorCode
7
+ */
8
+ getVisitorCode: (topLevelDomain: string, defaultVisitorCode?: string) => string;
9
+ }
10
+ /**
11
+ * A React HOC that gives a wrapped component access to callback function
12
+ * which obtains the Kameleoon visitorCode for the current visitor
13
+ */
14
+ export declare function withVisitorCode<Props extends UnknownPropsType>(Component: React.ComponentType<Props>): React.ComponentType<Props & Without<Props, IWithVisitorCode>>;
15
+ export {};
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.withVisitorCode = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_1 = require("react");
17
+ var KameleoonContext_1 = require("./KameleoonContext");
18
+ var ProviderError_1 = require("./ProviderError");
19
+ /**
20
+ * A React HOC that gives a wrapped component access to callback function
21
+ * which obtains the Kameleoon visitorCode for the current visitor
22
+ */
23
+ function withVisitorCode(Component) {
24
+ return function WrappedComponent(props) {
25
+ var client = (0, react_1.useContext)(KameleoonContext_1.KameleoonContext);
26
+ var getVisitorCode = (0, react_1.useCallback)(function (topLevelDomain, defaultVisitorCode) {
27
+ if (!client) {
28
+ throw new ProviderError_1.ProviderError('withVisitorCode');
29
+ }
30
+ return client.obtainVisitorCode(topLevelDomain, defaultVisitorCode);
31
+ }, [client]);
32
+ return (0, jsx_runtime_1.jsx)(Component, __assign({ getVisitorCode: getVisitorCode }, props), void 0);
33
+ };
34
+ }
35
+ exports.withVisitorCode = withVisitorCode;
36
+ //# sourceMappingURL=withVisitorCode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withVisitorCode.js","sourceRoot":"","sources":["../src/withVisitorCode.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+BAAuD;AAEvD,uDAAsD;AACtD,iDAAgD;AAahD;;;GAGG;AACH,SAAgB,eAAe,CAC7B,SAAqC;IAErC,OAAO,SAAS,gBAAgB,CAAC,KAAY;QAC3C,IAAM,MAAM,GAAG,IAAA,kBAAU,EAAC,mCAAgB,CAAC,CAAC;QAE5C,IAAM,cAAc,GAAG,IAAA,mBAAW,EAChC,UAAC,cAAsB,EAAE,kBAA2B;YAClD,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,6BAAa,CAAC,iBAAiB,CAAC,CAAC;aAC5C;YAED,OAAO,MAAM,CAAC,iBAAiB,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAAC;QACtE,CAAC,EACD,CAAC,MAAM,CAAC,CACT,CAAC;QAEF,OAAO,uBAAC,SAAS,aAAC,cAAc,EAAE,cAAc,IAAO,KAAe,UAAI,CAAC;IAC7E,CAAC,CAAC;AACJ,CAAC;AAnBD,0CAmBC"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@kameleoon/react-sdk",
3
+ "version": "1.2.0",
4
+ "description": "Kameleoon React SDK",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "dist/index.js",
9
+ "scripts": {
10
+ "clear": "rimraf dist",
11
+ "start": "npm run clear && tsc -w",
12
+ "build": "npm run clear && tsc",
13
+ "test": "jest",
14
+ "test:watch": "jest --watch",
15
+ "test:coverage": "jest --coverage",
16
+ "test:update": "jest --updateSnapshot"
17
+ },
18
+ "homepage": "https://developers.kameleoon.com/react-js-sdk.html",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "keywords": [
23
+ "kameleoon",
24
+ "react",
25
+ "sdk",
26
+ "react sdk"
27
+ ],
28
+ "license": "ISC",
29
+ "peerDependencies": {
30
+ "react": ">=16.8.0"
31
+ },
32
+ "dependencies": {
33
+ "@types/validator": "^13.6.3",
34
+ "kameleoon-client-javascript": "^1.0.5",
35
+ "validator": "^13.6.0"
36
+ },
37
+ "devDependencies": {
38
+ "@types/react": "^17.0.24",
39
+ "react": "^17.0.2",
40
+ "rimraf": "^3.0.2",
41
+ "typescript": "^4.4.4"
42
+ },
43
+ "commitlint": {
44
+ "extends": "@commitlint/config-conventional"
45
+ },
46
+ "gitHead": "4dbaa5faa990facdac3d2c75aedf712e9b06ccbe"
47
+ }