@atlaskit/tmp-editor-statsig 1.0.0 → 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 (36) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/dist/cjs/experiments-config.js +56 -0
  3. package/dist/cjs/experiments.js +123 -0
  4. package/dist/cjs/index.js +5 -0
  5. package/dist/cjs/test-runner.js +83 -0
  6. package/dist/es2019/experiments-config.js +50 -0
  7. package/dist/es2019/experiments.js +110 -0
  8. package/dist/es2019/index.js +1 -0
  9. package/dist/es2019/test-runner.js +65 -0
  10. package/dist/esm/experiments-config.js +50 -0
  11. package/dist/esm/experiments.js +115 -0
  12. package/dist/esm/index.js +1 -0
  13. package/dist/esm/test-runner.js +77 -0
  14. package/dist/types/experiments-config.d.ts +43 -0
  15. package/dist/types/experiments.d.ts +66 -0
  16. package/dist/types/index.d.ts +1 -0
  17. package/dist/types/test-runner.d.ts +41 -0
  18. package/dist/types-ts4.5/experiments-config.d.ts +43 -0
  19. package/dist/types-ts4.5/experiments.d.ts +66 -0
  20. package/dist/types-ts4.5/index.d.ts +1 -0
  21. package/dist/types-ts4.5/test-runner.d.ts +41 -0
  22. package/experiments/package.json +14 -0
  23. package/package.json +9 -9
  24. package/test-runner/package.json +14 -0
  25. package/dist/cjs/feature-gate-js-client.js +0 -21
  26. package/dist/cjs/feature-gates-react.js +0 -110
  27. package/dist/es2019/feature-gate-js-client.js +0 -14
  28. package/dist/es2019/feature-gates-react.js +0 -84
  29. package/dist/esm/feature-gate-js-client.js +0 -14
  30. package/dist/esm/feature-gates-react.js +0 -101
  31. package/dist/types/feature-gate-js-client.d.ts +0 -12
  32. package/dist/types/feature-gates-react.d.ts +0 -19
  33. package/dist/types-ts4.5/feature-gate-js-client.d.ts +0 -12
  34. package/dist/types-ts4.5/feature-gates-react.d.ts +0 -19
  35. package/feature-gate-js-client/package.json +0 -14
  36. package/feature-gates-react/package.json +0 -14
@@ -0,0 +1,77 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ // This is loosely based on the `ffTest` util from `@atlassian/feature-flags-test-utils` package.
5
+
6
+ import { setupEditorExperiments } from './experiments';
7
+ import { editorExperimentsConfig } from './experiments-config';
8
+
9
+ /**
10
+ * This is a utility function for testing editor experiments.
11
+ *
12
+ * @example Boolean experiment
13
+ * ```ts
14
+ * eeTest('example-boolean', {
15
+ * true: () => {
16
+ * expect(editorExperiment('example-boolean', true)).toBe(true);
17
+ * expect(editorExperiment('example-boolean', false)).toBe(false);
18
+ * },
19
+ * false: () => {
20
+ * expect(editorExperiment('example-boolean', false)).toBe(true);
21
+ * expect(editorExperiment('example-boolean', true)).toBe(false);
22
+ * },
23
+ * })
24
+ * ```
25
+ *
26
+ * @example Multivariate experiment
27
+ * ```ts
28
+ * eeTest('example-multivariate', {
29
+ * one: () => {
30
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(true);
31
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(false);
32
+ * },
33
+ * two: () => {
34
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(true);
35
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
36
+ * },
37
+ * three: () => {
38
+ * expect(editorExperiment('example-multivariate', 'three')).toBe(true);
39
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
40
+ * },
41
+ * })
42
+ * ```
43
+ */
44
+ export function eeTest(experimentName, cases, otherExperiments) {
45
+ setupEditorExperiments('test', {});
46
+ describe("eeTest: ".concat(experimentName), function () {
47
+ afterEach(function () {
48
+ setupEditorExperiments('test', otherExperiments !== null && otherExperiments !== void 0 ? otherExperiments : {});
49
+ });
50
+ var isBooleanExperiment = typeof editorExperimentsConfig[experimentName].defaultValue === 'boolean';
51
+ if (isBooleanExperiment && Object.keys(cases).length !== 2) {
52
+ throw new Error("Expected exactly 2 cases for boolean experiment ".concat(experimentName, ", got ").concat(Object.keys(cases).length));
53
+ }
54
+ test.each(Object.keys(cases))("".concat(experimentName, ": %s"), /*#__PURE__*/function () {
55
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(value) {
56
+ var testCaseKey, convertedValue, testCase;
57
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
58
+ while (1) switch (_context.prev = _context.next) {
59
+ case 0:
60
+ testCaseKey = value; // For boolean experiments, we need to convert the 'on' and 'off' cases to boolean `true` and `false` values.
61
+ convertedValue = isBooleanExperiment ? testCaseKey === 'true' ? true : false : testCaseKey;
62
+ setupEditorExperiments('test', _defineProperty({}, experimentName, convertedValue));
63
+ testCase = cases[testCaseKey]; // @ts-ignore
64
+ _context.next = 6;
65
+ return Promise.resolve(testCase());
66
+ case 6:
67
+ case "end":
68
+ return _context.stop();
69
+ }
70
+ }, _callee);
71
+ }));
72
+ return function (_x) {
73
+ return _ref.apply(this, arguments);
74
+ };
75
+ }());
76
+ });
77
+ }
@@ -0,0 +1,43 @@
1
+ declare function isBoolean(value: unknown): value is boolean;
2
+ export type EditorExperimentsConfig = typeof editorExperimentsConfig;
3
+ /**
4
+ * When adding a new experiment, you need to add it here.
5
+ * Please follow the pattern established in the examples and any
6
+ * existing experiments.
7
+ */
8
+ export declare const editorExperimentsConfig: {
9
+ 'example-boolean': {
10
+ productKeys: {
11
+ confluence: string;
12
+ };
13
+ param: string;
14
+ typeGuard: typeof isBoolean;
15
+ defaultValue: boolean;
16
+ };
17
+ 'example-multivariate': {
18
+ productKeys: {
19
+ confluence: string;
20
+ };
21
+ param: string;
22
+ typeGuard: typeof isBoolean;
23
+ defaultValue: "one" | "two" | "three";
24
+ };
25
+ 'test-new-experiments-package': {
26
+ productKeys: {
27
+ confluence: string;
28
+ jira: string;
29
+ };
30
+ param: string;
31
+ typeGuard: typeof isBoolean;
32
+ defaultValue: boolean;
33
+ };
34
+ 'basic-text-transformations': {
35
+ productKeys: {
36
+ confluence: string;
37
+ };
38
+ param: string;
39
+ typeGuard: typeof isBoolean;
40
+ defaultValue: boolean;
41
+ };
42
+ };
43
+ export {};
@@ -0,0 +1,66 @@
1
+ import { type EditorExperimentsConfig, editorExperimentsConfig } from './experiments-config';
2
+ export type EditorExperimentOverrides = Partial<{
3
+ [ExperimentName in keyof typeof editorExperimentsConfig]: (typeof editorExperimentsConfig)[ExperimentName]['defaultValue'];
4
+ }>;
5
+ /**
6
+ * This function is used to set up the editor experiments for testing purposes.
7
+ * It should be called before running code that depends on editor experiments.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * setupEditorExperiments('confluence', {
12
+ * 'experiment-name': 'value',
13
+ * });
14
+ * ```
15
+ */
16
+ export declare function setupEditorExperiments(product: 'confluence' | 'jira' | 'test',
17
+ /**
18
+ * Overrides are used to set the value of an experiment for testing purposes.
19
+ * This is useful when you want to test a specific value of an experiment.
20
+ */
21
+ overrides?: EditorExperimentOverrides): void;
22
+ /**
23
+ * Check the value of an editor experiment.
24
+ *
25
+ * Note: By default this will not fire an [exposure event](https://hello.atlassian.net/wiki/spaces/~732385844/pages/3187295823/Exposure+Events+101).
26
+ *
27
+ * You need explicitly call it using the exposure property when you need an exposure event to be fired (all experiments should fire exposure events).
28
+ *
29
+ * @example Boolean experiment
30
+ * ```ts
31
+ * if (editorExperiment('example-boolean', true)) {
32
+ * // Run code for on variant
33
+ * } else {
34
+ * // Run code for off variant
35
+ * }
36
+ * ```
37
+ *
38
+ * @example Multivariate experiment
39
+ * ```ts
40
+ * switch (true) {
41
+ * case editorExperiment('example-multivariate', 'one'):
42
+ * // Run code for variant one
43
+ * break;
44
+ * case editorExperiment('example-multivariate', 'two'):
45
+ * // Run code for variant two
46
+ * break;
47
+ * case editorExperiment('example-multivariate', 'three'):
48
+ * // Run code for variant three
49
+ * break;
50
+ * }
51
+ * }
52
+ *```
53
+
54
+ @example Experiment with exposure event
55
+ * ```ts
56
+ * // Inside feature surface where either the control or variant should be shown
57
+ * if (editorExperiment('example-boolean', true, { exposure: true })) {
58
+ * // Run code for on variant
59
+ * } else {
60
+ * // Run code for off variant
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function editorExperiment<ExperimentName extends keyof EditorExperimentsConfig>(experimentName: ExperimentName, expectedExperimentValue: EditorExperimentsConfig[ExperimentName]['defaultValue'], options?: {
65
+ exposure: boolean;
66
+ }): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { type EditorExperimentOverrides } from './experiments';
2
+ import { type EditorExperimentsConfig } from './experiments-config';
3
+ /**
4
+ * This is a utility function for testing editor experiments.
5
+ *
6
+ * @example Boolean experiment
7
+ * ```ts
8
+ * eeTest('example-boolean', {
9
+ * true: () => {
10
+ * expect(editorExperiment('example-boolean', true)).toBe(true);
11
+ * expect(editorExperiment('example-boolean', false)).toBe(false);
12
+ * },
13
+ * false: () => {
14
+ * expect(editorExperiment('example-boolean', false)).toBe(true);
15
+ * expect(editorExperiment('example-boolean', true)).toBe(false);
16
+ * },
17
+ * })
18
+ * ```
19
+ *
20
+ * @example Multivariate experiment
21
+ * ```ts
22
+ * eeTest('example-multivariate', {
23
+ * one: () => {
24
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(true);
25
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(false);
26
+ * },
27
+ * two: () => {
28
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(true);
29
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
30
+ * },
31
+ * three: () => {
32
+ * expect(editorExperiment('example-multivariate', 'three')).toBe(true);
33
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
34
+ * },
35
+ * })
36
+ * ```
37
+ */
38
+ export declare function eeTest<ExperimentName extends keyof EditorExperimentsConfig>(experimentName: ExperimentName, cases: EditorExperimentsConfig[ExperimentName] extends string ? Record<EditorExperimentsConfig[ExperimentName], () => void | Promise<void>> : {
39
+ true: () => void | Promise<void>;
40
+ false: () => void | Promise<void>;
41
+ }, otherExperiments?: EditorExperimentOverrides): void;
@@ -0,0 +1,43 @@
1
+ declare function isBoolean(value: unknown): value is boolean;
2
+ export type EditorExperimentsConfig = typeof editorExperimentsConfig;
3
+ /**
4
+ * When adding a new experiment, you need to add it here.
5
+ * Please follow the pattern established in the examples and any
6
+ * existing experiments.
7
+ */
8
+ export declare const editorExperimentsConfig: {
9
+ 'example-boolean': {
10
+ productKeys: {
11
+ confluence: string;
12
+ };
13
+ param: string;
14
+ typeGuard: typeof isBoolean;
15
+ defaultValue: boolean;
16
+ };
17
+ 'example-multivariate': {
18
+ productKeys: {
19
+ confluence: string;
20
+ };
21
+ param: string;
22
+ typeGuard: typeof isBoolean;
23
+ defaultValue: "one" | "two" | "three";
24
+ };
25
+ 'test-new-experiments-package': {
26
+ productKeys: {
27
+ confluence: string;
28
+ jira: string;
29
+ };
30
+ param: string;
31
+ typeGuard: typeof isBoolean;
32
+ defaultValue: boolean;
33
+ };
34
+ 'basic-text-transformations': {
35
+ productKeys: {
36
+ confluence: string;
37
+ };
38
+ param: string;
39
+ typeGuard: typeof isBoolean;
40
+ defaultValue: boolean;
41
+ };
42
+ };
43
+ export {};
@@ -0,0 +1,66 @@
1
+ import { type EditorExperimentsConfig, editorExperimentsConfig } from './experiments-config';
2
+ export type EditorExperimentOverrides = Partial<{
3
+ [ExperimentName in keyof typeof editorExperimentsConfig]: (typeof editorExperimentsConfig)[ExperimentName]['defaultValue'];
4
+ }>;
5
+ /**
6
+ * This function is used to set up the editor experiments for testing purposes.
7
+ * It should be called before running code that depends on editor experiments.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * setupEditorExperiments('confluence', {
12
+ * 'experiment-name': 'value',
13
+ * });
14
+ * ```
15
+ */
16
+ export declare function setupEditorExperiments(product: 'confluence' | 'jira' | 'test',
17
+ /**
18
+ * Overrides are used to set the value of an experiment for testing purposes.
19
+ * This is useful when you want to test a specific value of an experiment.
20
+ */
21
+ overrides?: EditorExperimentOverrides): void;
22
+ /**
23
+ * Check the value of an editor experiment.
24
+ *
25
+ * Note: By default this will not fire an [exposure event](https://hello.atlassian.net/wiki/spaces/~732385844/pages/3187295823/Exposure+Events+101).
26
+ *
27
+ * You need explicitly call it using the exposure property when you need an exposure event to be fired (all experiments should fire exposure events).
28
+ *
29
+ * @example Boolean experiment
30
+ * ```ts
31
+ * if (editorExperiment('example-boolean', true)) {
32
+ * // Run code for on variant
33
+ * } else {
34
+ * // Run code for off variant
35
+ * }
36
+ * ```
37
+ *
38
+ * @example Multivariate experiment
39
+ * ```ts
40
+ * switch (true) {
41
+ * case editorExperiment('example-multivariate', 'one'):
42
+ * // Run code for variant one
43
+ * break;
44
+ * case editorExperiment('example-multivariate', 'two'):
45
+ * // Run code for variant two
46
+ * break;
47
+ * case editorExperiment('example-multivariate', 'three'):
48
+ * // Run code for variant three
49
+ * break;
50
+ * }
51
+ * }
52
+ *```
53
+
54
+ @example Experiment with exposure event
55
+ * ```ts
56
+ * // Inside feature surface where either the control or variant should be shown
57
+ * if (editorExperiment('example-boolean', true, { exposure: true })) {
58
+ * // Run code for on variant
59
+ * } else {
60
+ * // Run code for off variant
61
+ * }
62
+ * ```
63
+ */
64
+ export declare function editorExperiment<ExperimentName extends keyof EditorExperimentsConfig>(experimentName: ExperimentName, expectedExperimentValue: EditorExperimentsConfig[ExperimentName]['defaultValue'], options?: {
65
+ exposure: boolean;
66
+ }): boolean;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,41 @@
1
+ import { type EditorExperimentOverrides } from './experiments';
2
+ import { type EditorExperimentsConfig } from './experiments-config';
3
+ /**
4
+ * This is a utility function for testing editor experiments.
5
+ *
6
+ * @example Boolean experiment
7
+ * ```ts
8
+ * eeTest('example-boolean', {
9
+ * true: () => {
10
+ * expect(editorExperiment('example-boolean', true)).toBe(true);
11
+ * expect(editorExperiment('example-boolean', false)).toBe(false);
12
+ * },
13
+ * false: () => {
14
+ * expect(editorExperiment('example-boolean', false)).toBe(true);
15
+ * expect(editorExperiment('example-boolean', true)).toBe(false);
16
+ * },
17
+ * })
18
+ * ```
19
+ *
20
+ * @example Multivariate experiment
21
+ * ```ts
22
+ * eeTest('example-multivariate', {
23
+ * one: () => {
24
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(true);
25
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(false);
26
+ * },
27
+ * two: () => {
28
+ * expect(editorExperiment('example-multivariate', 'two')).toBe(true);
29
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
30
+ * },
31
+ * three: () => {
32
+ * expect(editorExperiment('example-multivariate', 'three')).toBe(true);
33
+ * expect(editorExperiment('example-multivariate', 'one')).toBe(false);
34
+ * },
35
+ * })
36
+ * ```
37
+ */
38
+ export declare function eeTest<ExperimentName extends keyof EditorExperimentsConfig>(experimentName: ExperimentName, cases: EditorExperimentsConfig[ExperimentName] extends string ? Record<EditorExperimentsConfig[ExperimentName], () => void | Promise<void>> : {
39
+ true: () => void | Promise<void>;
40
+ false: () => void | Promise<void>;
41
+ }, otherExperiments?: EditorExperimentOverrides): void;
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@atlaskit/tmp-editor-statsig/experiments",
3
+ "main": "../dist/cjs/experiments.js",
4
+ "module": "../dist/esm/experiments.js",
5
+ "module:es2019": "../dist/es2019/experiments.js",
6
+ "types": "../dist/types/experiments.d.ts",
7
+ "typesVersions": {
8
+ ">=4.5 <5.4": {
9
+ "*": [
10
+ "../dist/types-ts4.5/experiments.d.ts"
11
+ ]
12
+ }
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tmp-editor-statsig",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Temp plugin to ease use of statsig feature flags until platform feature flags are available",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -17,22 +17,22 @@
17
17
  }
18
18
  },
19
19
  "repository": "https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo",
20
- "main": "dist/cjs/feature-gate-js-client.js",
21
- "module": "dist/esm/feature-gate-js-client.js",
22
- "module:es2019": "dist/es2019/feature-gate-js-client.js",
23
- "types": "dist/types/feature-gate-js-client.d.ts",
20
+ "main": "dist/cjs/index.js",
21
+ "module": "dist/esm/index.js",
22
+ "module:es2019": "dist/es2019/index.js",
23
+ "types": "dist/types/index.d.ts",
24
24
  "typesVersions": {
25
25
  ">=4.5 <5.4": {
26
26
  "*": [
27
27
  "dist/types-ts4.5/*",
28
- "dist/types-ts4.5/feature-gate-js-client.d.ts"
28
+ "dist/types-ts4.5/index.d.ts"
29
29
  ]
30
30
  }
31
31
  },
32
- "atlaskit:src": "src/feature-gate-js-client.ts",
32
+ "atlaskit:src": "src/index.ts",
33
33
  "af:exports": {
34
- "./feature-gate-js-client": "./src/feature-gate-js-client.ts",
35
- "./feature-gates-react": "./src/feature-gates-react.tsx"
34
+ "./experiments": "./src/experiments.ts",
35
+ "./test-runner": "./src/test-runner.ts"
36
36
  },
37
37
  "dependencies": {
38
38
  "@atlaskit/feature-gate-js-client": "^4.17.0",
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "@atlaskit/tmp-editor-statsig/test-runner",
3
+ "main": "../dist/cjs/test-runner.js",
4
+ "module": "../dist/esm/test-runner.js",
5
+ "module:es2019": "../dist/es2019/test-runner.js",
6
+ "types": "../dist/types/test-runner.d.ts",
7
+ "typesVersions": {
8
+ ">=4.5 <5.4": {
9
+ "*": [
10
+ "../dist/types-ts4.5/test-runner.d.ts"
11
+ ]
12
+ }
13
+ }
14
+ }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _featureGateJsClient = _interopRequireDefault(require("@atlaskit/feature-gate-js-client"));
9
- var EditorFeatureGates = {
10
- checkGate: function checkGate(key) {
11
- return _featureGateJsClient.default.checkGate(key);
12
- },
13
- /**
14
- *
15
- * Warning -- this is not yet implemented
16
- *
17
- * When implemented -- please update docs/0-intro.tsx
18
- */
19
- getExperimentValue: function () {}
20
- };
21
- var _default = exports.default = EditorFeatureGates;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.EditorFeatureGatesInitialization = void 0;
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
- var _react = _interopRequireWildcard(require("react"));
12
- var _featureGateJsClient = _interopRequireDefault(require("@atlaskit/feature-gate-js-client"));
13
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
14
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
- /**
18
- * This component initializes the @atlassian/feature-flag-js-client by fetching the gate and experiment
19
- * evaluations for the given user, and blocks rendering of the children until the rendering is complete.
20
- *
21
- * This is based on the private dependency @atlassian/feature-gates-react, which is not intended for public use.
22
- *
23
- * https://bitbucket.org/atlassian/feature-gate-clients/src/main/packages/react-sdk/src/FeatureGatesInitialization.tsx
24
- * https://bitbucket.org/atlassian/feature-gate-clients/src/main/packages/react-sdk/src/utils.tsx
25
- */
26
- var EditorFeatureGatesInitialization = exports.EditorFeatureGatesInitialization = function EditorFeatureGatesInitialization(_ref) {
27
- var children = _ref.children,
28
- overrides = _ref.overrides;
29
- // Rather than checking the state of all overrides, we can just assume that if overrides are provided
30
- // then some sort of update will need to be performed, and hold off rendering until the useEffect is run.
31
- var _useState = (0, _react.useState)(!overrides && isClientAlreadyInCorrectState()),
32
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
33
- isInitialized = _useState2[0],
34
- setInitialized = _useState2[1];
35
- (0, _react.useEffect)(function () {
36
- var _overrides = _objectSpread({
37
- configs: {},
38
- layers: {}
39
- }, overrides);
40
- if (isClientAlreadyInCorrectState()) {
41
- applyOverrides(_overrides);
42
- setInitialized(true);
43
- } else {
44
- setInitialized(false);
45
- var initPromise = _featureGateJsClient.default.initialize({}, {}, {});
46
- void initPromise.then(function () {
47
- return applyOverrides(_overrides);
48
- }).catch(function (err) {
49
- return toError(err);
50
- }).then(function (err) {
51
- setInitialized(true);
52
- });
53
- }
54
- return function () {
55
- return clearOverrides(_overrides);
56
- };
57
- }, [overrides]);
58
- if (!isInitialized) {
59
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "loading feature flags");
60
- }
61
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
62
- };
63
- var hasWarnedAboutMissingOverrideSupport = false;
64
- function applyOverrides(overrides) {
65
- // Allow newer versions of the React SDK to be used with older v3.x JS client versions,
66
- // provided the caller does not try to leverage the overrides which were introduced in v4.
67
- if (overrides && (!_featureGateJsClient.default.overrideGate || !_featureGateJsClient.default.overrideConfig)) {
68
- if (!hasWarnedAboutMissingOverrideSupport) {
69
- // eslint-disable-next-line no-console
70
- console.warn('Overrides are only supported in @atlaskit/feature-gate-js-client v4.0.0+');
71
- hasWarnedAboutMissingOverrideSupport = true;
72
- }
73
- return;
74
- }
75
- Object.entries((overrides === null || overrides === void 0 ? void 0 : overrides.gates) || {}).forEach(function (_ref2) {
76
- var _FeatureGates$overrid;
77
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
78
- gateName = _ref3[0],
79
- value = _ref3[1];
80
- (_FeatureGates$overrid = _featureGateJsClient.default.overrideGate) === null || _FeatureGates$overrid === void 0 || _FeatureGates$overrid.call(_featureGateJsClient.default, gateName, value);
81
- });
82
- Object.entries((overrides === null || overrides === void 0 ? void 0 : overrides.configs) || {}).forEach(function (_ref4) {
83
- var _FeatureGates$overrid2;
84
- var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
85
- configName = _ref5[0],
86
- values = _ref5[1];
87
- (_FeatureGates$overrid2 = _featureGateJsClient.default.overrideConfig) === null || _FeatureGates$overrid2 === void 0 || _FeatureGates$overrid2.call(_featureGateJsClient.default, configName, values);
88
- });
89
- }
90
- function isClientAlreadyInCorrectState() {
91
- var _FeatureGates$initial;
92
- // If either of these methods don't exist (ie. if the product is using <v4.2.0), then this method will always return false
93
- return (_FeatureGates$initial = _featureGateJsClient.default.initializeCompleted) === null || _FeatureGates$initial === void 0 ? void 0 : _FeatureGates$initial.call(_featureGateJsClient.default);
94
- }
95
- function toError(err) {
96
- if (err instanceof Error) {
97
- return err;
98
- }
99
- return new Error(err === null || err === void 0 ? void 0 : err.toString());
100
- }
101
- function clearOverrides(overrides) {
102
- Object.keys((overrides === null || overrides === void 0 ? void 0 : overrides.gates) || {}).forEach(function (gateName) {
103
- var _FeatureGates$clearGa;
104
- (_FeatureGates$clearGa = _featureGateJsClient.default.clearGateOverride) === null || _FeatureGates$clearGa === void 0 || _FeatureGates$clearGa.call(_featureGateJsClient.default, gateName);
105
- });
106
- Object.keys((overrides === null || overrides === void 0 ? void 0 : overrides.configs) || {}).forEach(function (configName) {
107
- var _FeatureGates$clearCo;
108
- (_FeatureGates$clearCo = _featureGateJsClient.default.clearConfigOverride) === null || _FeatureGates$clearCo === void 0 || _FeatureGates$clearCo.call(_featureGateJsClient.default, configName);
109
- });
110
- }
@@ -1,14 +0,0 @@
1
- import FeatureGates from '@atlaskit/feature-gate-js-client';
2
- const EditorFeatureGates = {
3
- checkGate: key => {
4
- return FeatureGates.checkGate(key);
5
- },
6
- /**
7
- *
8
- * Warning -- this is not yet implemented
9
- *
10
- * When implemented -- please update docs/0-intro.tsx
11
- */
12
- getExperimentValue: () => {}
13
- };
14
- export default EditorFeatureGates;