@atlaskit/link-datasource 6.13.3 → 6.13.5

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 (24) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/services/getAvailableSites.js +5 -3
  3. package/dist/cjs/services/isLinkDatasourceInUnitsRollout.js +25 -0
  4. package/dist/cjs/ui/table-footer/sync-info/index.js +18 -0
  5. package/dist/es2019/services/getAvailableSites.js +6 -2
  6. package/dist/es2019/services/isLinkDatasourceInUnitsRollout.js +20 -0
  7. package/dist/es2019/ui/table-footer/sync-info/index.js +16 -0
  8. package/dist/esm/services/getAvailableSites.js +5 -3
  9. package/dist/esm/services/isLinkDatasourceInUnitsRollout.js +20 -0
  10. package/dist/esm/ui/table-footer/sync-info/index.js +18 -0
  11. package/dist/types/services/isLinkDatasourceInUnitsRollout.d.ts +14 -0
  12. package/package.json +9 -6
  13. package/dist/cjs/services/__clearUnitsRolloutSettingsCacheForTests.js +0 -13
  14. package/dist/cjs/services/getUnitsRolloutSettings.js +0 -199
  15. package/dist/cjs/services/isUnitsIsolationEnabled.js +0 -63
  16. package/dist/es2019/services/__clearUnitsRolloutSettingsCacheForTests.js +0 -8
  17. package/dist/es2019/services/getUnitsRolloutSettings.js +0 -112
  18. package/dist/es2019/services/isUnitsIsolationEnabled.js +0 -34
  19. package/dist/esm/services/__clearUnitsRolloutSettingsCacheForTests.js +0 -8
  20. package/dist/esm/services/getUnitsRolloutSettings.js +0 -192
  21. package/dist/esm/services/isUnitsIsolationEnabled.js +0 -57
  22. package/dist/types/services/__clearUnitsRolloutSettingsCacheForTests.d.ts +0 -4
  23. package/dist/types/services/getUnitsRolloutSettings.d.ts +0 -29
  24. package/dist/types/services/isUnitsIsolationEnabled.d.ts +0 -15
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @atlaskit/link-datasource
2
2
 
3
+ ## 6.13.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`d096b1c221885`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/d096b1c221885) -
8
+ Reduce datasource sync timestamp updates by scheduling the next minute, hour, or day boundary
9
+ behind a feature gate.
10
+ - Updated dependencies
11
+
12
+ ## 6.13.4
13
+
14
+ ### Patch Changes
15
+
16
+ - [`2474922a7a598`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/2474922a7a598) -
17
+ Internal change only. The units rollout check now uses the shared
18
+ `@atlaskit/linking-common/units-rollout` helper instead of a local copy. Behaviour is unchanged.
19
+ - Updated dependencies
20
+
3
21
  ## 6.13.3
4
22
 
5
23
  ### Patch Changes
@@ -8,7 +8,8 @@ exports.getAccessibleProducts = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _hooks = require("@atlaskit/linking-common/hooks");
11
- var _isUnitsIsolationEnabled = require("./isUnitsIsolationEnabled");
11
+ var _unitsRollout = require("@atlaskit/linking-common/units-rollout");
12
+ var _isLinkDatasourceInUnitsRollout = require("./isLinkDatasourceInUnitsRollout");
12
13
  var getAccessibleProducts = exports.getAccessibleProducts = /*#__PURE__*/function () {
13
14
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(product) {
14
15
  var requestConfig, endpoint, response, res, _t, _t2, _t3, _t4;
@@ -26,9 +27,10 @@ var getAccessibleProducts = exports.getAccessibleProducts = /*#__PURE__*/functio
26
27
  body: JSON.stringify({
27
28
  productIds: product === 'confluence' ? ['confluence.ondemand'] : ['jira-software.ondemand', 'jira-core.ondemand', 'jira-incident-manager.ondemand', 'jira-product-discovery', 'jira-servicedesk.ondemand']
28
29
  })
29
- };
30
+ }; // Organisations with units isolation in effect must be served the unit compliant endpoint,
31
+ // which filters the products down to the unit the user belongs to.
30
32
  _context.next = 1;
31
- return (0, _isUnitsIsolationEnabled.isUnitsIsolationEnabled)();
33
+ return (0, _unitsRollout.shouldUseUnitCompliantApi)(_isLinkDatasourceInUnitsRollout.isLinkDatasourceInUnitsRollout);
32
34
  case 1:
33
35
  if (!_context.sent) {
34
36
  _context.next = 2;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isLinkDatasourceInUnitsRollout = void 0;
7
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
8
+ /**
9
+ * Whether link datasource is in the units isolation rollout.
10
+ *
11
+ * Two gates drive the same rollout so it can be turned on for either an organisation or a single
12
+ * site: `..._unit_compliant` targets org id, `..._unit_compliant_cloud_id` targets cloud id.
13
+ * Either one being on opts link datasource in, and both are always evaluated so that exposure is
14
+ * recorded for the two of them.
15
+ *
16
+ * Being in the rollout is not on its own enough to change behaviour - the organisation also has to
17
+ * have launched units with boundary enforcement on. Pass this to `shouldUseUnitCompliantApi` from
18
+ * `@atlaskit/linking-common/units-rollout`, which owns that decision, rather than calling it
19
+ * directly.
20
+ */
21
+ var isLinkDatasourceInUnitsRollout = exports.isLinkDatasourceInUnitsRollout = function isLinkDatasourceInUnitsRollout() {
22
+ var isOrgInRollout = (0, _fg.fg)('linking_platform_link_datasource_unit_compliant');
23
+ var isSiteInRollout = (0, _fg.fg)('linking_platform_link_datasource_unit_compliant_cloud_id');
24
+ return isOrgInRollout || isSiteInRollout;
25
+ };
@@ -10,6 +10,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var _react = _interopRequireWildcard(require("react"));
12
12
  var _reactIntl = require("react-intl");
13
+ var _fg = require("@atlaskit/platform-feature-flags/fg");
13
14
  var _messages = require("./messages");
14
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
15
16
  var SECONDS_IN_MIN = 60;
@@ -36,6 +37,23 @@ var SyncInfo = exports.SyncInfo = function SyncInfo(_ref) {
36
37
  var totalHours = Math.floor(secondsSinceUpdate / SECONDS_IN_HR);
37
38
  var totalMinutes = Math.floor(secondsSinceUpdate / SECONDS_IN_MIN);
38
39
  (0, _react.useEffect)(function () {
40
+ if ((0, _fg.fg)('platform_datasource_sync_info_boundary_updates')) {
41
+ var timeout;
42
+ var _update = function update() {
43
+ var elapsedMs = Date.now() - lastSyncTime.getTime();
44
+ setSecondsSinceUpdate(Math.floor(elapsedMs / 1000));
45
+ // At eight days the label becomes a fixed date, so no further updates are needed.
46
+ if (elapsedMs >= 8 * SECONDS_IN_DAY * 1000) {
47
+ return;
48
+ }
49
+ var unitMs = (elapsedMs < SECONDS_IN_HR * 1000 ? SECONDS_IN_MIN : elapsedMs < SECONDS_IN_DAY * 1000 ? SECONDS_IN_HR : SECONDS_IN_DAY) * 1000;
50
+ timeout = setTimeout(_update, unitMs - elapsedMs % unitMs);
51
+ };
52
+ _update();
53
+ return function () {
54
+ return clearTimeout(timeout);
55
+ };
56
+ }
39
57
  setSecondsSinceUpdate(calculateTimeDiff());
40
58
  var interval = setInterval(function () {
41
59
  return setSecondsSinceUpdate(calculateTimeDiff());
@@ -1,5 +1,6 @@
1
1
  import { mapAccessibleProductsToAvailableSites } from '@atlaskit/linking-common/hooks';
2
- import { isUnitsIsolationEnabled } from './isUnitsIsolationEnabled';
2
+ import { shouldUseUnitCompliantApi } from '@atlaskit/linking-common/units-rollout';
3
+ import { isLinkDatasourceInUnitsRollout } from './isLinkDatasourceInUnitsRollout';
3
4
  export const getAccessibleProducts = async product => {
4
5
  const requestConfig = {
5
6
  method: 'POST',
@@ -13,7 +14,10 @@ export const getAccessibleProducts = async product => {
13
14
  productIds: product === 'confluence' ? ['confluence.ondemand'] : ['jira-software.ondemand', 'jira-core.ondemand', 'jira-incident-manager.ondemand', 'jira-product-discovery', 'jira-servicedesk.ondemand']
14
15
  })
15
16
  };
16
- const endpoint = (await isUnitsIsolationEnabled()) ? '/gateway/api/experimental/v2/accessible-products' : '/gateway/api/v2/accessible-products';
17
+
18
+ // Organisations with units isolation in effect must be served the unit compliant endpoint,
19
+ // which filters the products down to the unit the user belongs to.
20
+ const endpoint = (await shouldUseUnitCompliantApi(isLinkDatasourceInUnitsRollout)) ? '/gateway/api/experimental/v2/accessible-products' : '/gateway/api/v2/accessible-products';
17
21
  const response = await fetch(endpoint, requestConfig);
18
22
  if (response.ok) {
19
23
  const res = await response.json();
@@ -0,0 +1,20 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
2
+
3
+ /**
4
+ * Whether link datasource is in the units isolation rollout.
5
+ *
6
+ * Two gates drive the same rollout so it can be turned on for either an organisation or a single
7
+ * site: `..._unit_compliant` targets org id, `..._unit_compliant_cloud_id` targets cloud id.
8
+ * Either one being on opts link datasource in, and both are always evaluated so that exposure is
9
+ * recorded for the two of them.
10
+ *
11
+ * Being in the rollout is not on its own enough to change behaviour - the organisation also has to
12
+ * have launched units with boundary enforcement on. Pass this to `shouldUseUnitCompliantApi` from
13
+ * `@atlaskit/linking-common/units-rollout`, which owns that decision, rather than calling it
14
+ * directly.
15
+ */
16
+ export const isLinkDatasourceInUnitsRollout = () => {
17
+ const isOrgInRollout = fg('linking_platform_link_datasource_unit_compliant');
18
+ const isSiteInRollout = fg('linking_platform_link_datasource_unit_compliant_cloud_id');
19
+ return isOrgInRollout || isSiteInRollout;
20
+ };
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useCallback, useEffect, useState } from 'react';
3
3
  import { FormattedDate, FormattedMessage, FormattedRelativeTime } from 'react-intl';
4
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
4
5
  import { messages } from './messages';
5
6
  const SECONDS_IN_MIN = 60;
6
7
  const SECONDS_IN_HR = SECONDS_IN_MIN * 60;
@@ -22,6 +23,21 @@ export const SyncInfo = ({
22
23
  const totalHours = Math.floor(secondsSinceUpdate / SECONDS_IN_HR);
23
24
  const totalMinutes = Math.floor(secondsSinceUpdate / SECONDS_IN_MIN);
24
25
  useEffect(() => {
26
+ if (fg('platform_datasource_sync_info_boundary_updates')) {
27
+ let timeout;
28
+ const update = () => {
29
+ const elapsedMs = Date.now() - lastSyncTime.getTime();
30
+ setSecondsSinceUpdate(Math.floor(elapsedMs / 1000));
31
+ // At eight days the label becomes a fixed date, so no further updates are needed.
32
+ if (elapsedMs >= 8 * SECONDS_IN_DAY * 1000) {
33
+ return;
34
+ }
35
+ const unitMs = (elapsedMs < SECONDS_IN_HR * 1000 ? SECONDS_IN_MIN : elapsedMs < SECONDS_IN_DAY * 1000 ? SECONDS_IN_HR : SECONDS_IN_DAY) * 1000;
36
+ timeout = setTimeout(update, unitMs - elapsedMs % unitMs);
37
+ };
38
+ update();
39
+ return () => clearTimeout(timeout);
40
+ }
25
41
  setSecondsSinceUpdate(calculateTimeDiff());
26
42
  const interval = setInterval(() => setSecondsSinceUpdate(calculateTimeDiff()), 1000);
27
43
  return () => clearInterval(interval);
@@ -1,7 +1,8 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  import { mapAccessibleProductsToAvailableSites } from '@atlaskit/linking-common/hooks';
4
- import { isUnitsIsolationEnabled } from './isUnitsIsolationEnabled';
4
+ import { shouldUseUnitCompliantApi } from '@atlaskit/linking-common/units-rollout';
5
+ import { isLinkDatasourceInUnitsRollout } from './isLinkDatasourceInUnitsRollout';
5
6
  export var getAccessibleProducts = /*#__PURE__*/function () {
6
7
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(product) {
7
8
  var requestConfig, endpoint, response, res, _t, _t2, _t3, _t4;
@@ -19,9 +20,10 @@ export var getAccessibleProducts = /*#__PURE__*/function () {
19
20
  body: JSON.stringify({
20
21
  productIds: product === 'confluence' ? ['confluence.ondemand'] : ['jira-software.ondemand', 'jira-core.ondemand', 'jira-incident-manager.ondemand', 'jira-product-discovery', 'jira-servicedesk.ondemand']
21
22
  })
22
- };
23
+ }; // Organisations with units isolation in effect must be served the unit compliant endpoint,
24
+ // which filters the products down to the unit the user belongs to.
23
25
  _context.next = 1;
24
- return isUnitsIsolationEnabled();
26
+ return shouldUseUnitCompliantApi(isLinkDatasourceInUnitsRollout);
25
27
  case 1:
26
28
  if (!_context.sent) {
27
29
  _context.next = 2;
@@ -0,0 +1,20 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
2
+
3
+ /**
4
+ * Whether link datasource is in the units isolation rollout.
5
+ *
6
+ * Two gates drive the same rollout so it can be turned on for either an organisation or a single
7
+ * site: `..._unit_compliant` targets org id, `..._unit_compliant_cloud_id` targets cloud id.
8
+ * Either one being on opts link datasource in, and both are always evaluated so that exposure is
9
+ * recorded for the two of them.
10
+ *
11
+ * Being in the rollout is not on its own enough to change behaviour - the organisation also has to
12
+ * have launched units with boundary enforcement on. Pass this to `shouldUseUnitCompliantApi` from
13
+ * `@atlaskit/linking-common/units-rollout`, which owns that decision, rather than calling it
14
+ * directly.
15
+ */
16
+ export var isLinkDatasourceInUnitsRollout = function isLinkDatasourceInUnitsRollout() {
17
+ var isOrgInRollout = fg('linking_platform_link_datasource_unit_compliant');
18
+ var isSiteInRollout = fg('linking_platform_link_datasource_unit_compliant_cloud_id');
19
+ return isOrgInRollout || isSiteInRollout;
20
+ };
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import React, { useCallback, useEffect, useState } from 'react';
4
4
  import { FormattedDate, FormattedMessage, FormattedRelativeTime } from 'react-intl';
5
+ import { fg } from '@atlaskit/platform-feature-flags/fg';
5
6
  import { messages } from './messages';
6
7
  var SECONDS_IN_MIN = 60;
7
8
  var SECONDS_IN_HR = SECONDS_IN_MIN * 60;
@@ -27,6 +28,23 @@ export var SyncInfo = function SyncInfo(_ref) {
27
28
  var totalHours = Math.floor(secondsSinceUpdate / SECONDS_IN_HR);
28
29
  var totalMinutes = Math.floor(secondsSinceUpdate / SECONDS_IN_MIN);
29
30
  useEffect(function () {
31
+ if (fg('platform_datasource_sync_info_boundary_updates')) {
32
+ var timeout;
33
+ var _update = function update() {
34
+ var elapsedMs = Date.now() - lastSyncTime.getTime();
35
+ setSecondsSinceUpdate(Math.floor(elapsedMs / 1000));
36
+ // At eight days the label becomes a fixed date, so no further updates are needed.
37
+ if (elapsedMs >= 8 * SECONDS_IN_DAY * 1000) {
38
+ return;
39
+ }
40
+ var unitMs = (elapsedMs < SECONDS_IN_HR * 1000 ? SECONDS_IN_MIN : elapsedMs < SECONDS_IN_DAY * 1000 ? SECONDS_IN_HR : SECONDS_IN_DAY) * 1000;
41
+ timeout = setTimeout(_update, unitMs - elapsedMs % unitMs);
42
+ };
43
+ _update();
44
+ return function () {
45
+ return clearTimeout(timeout);
46
+ };
47
+ }
30
48
  setSecondsSinceUpdate(calculateTimeDiff());
31
49
  var interval = setInterval(function () {
32
50
  return setSecondsSinceUpdate(calculateTimeDiff());
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether link datasource is in the units isolation rollout.
3
+ *
4
+ * Two gates drive the same rollout so it can be turned on for either an organisation or a single
5
+ * site: `..._unit_compliant` targets org id, `..._unit_compliant_cloud_id` targets cloud id.
6
+ * Either one being on opts link datasource in, and both are always evaluated so that exposure is
7
+ * recorded for the two of them.
8
+ *
9
+ * Being in the rollout is not on its own enough to change behaviour - the organisation also has to
10
+ * have launched units with boundary enforcement on. Pass this to `shouldUseUnitCompliantApi` from
11
+ * `@atlaskit/linking-common/units-rollout`, which owns that decision, rather than calling it
12
+ * directly.
13
+ */
14
+ export declare const isLinkDatasourceInUnitsRollout: () => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/link-datasource",
3
- "version": "6.13.3",
3
+ "version": "6.13.5",
4
4
  "description": "UI Components to support linking platform dataset feature",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,13 +39,13 @@
39
39
  "@atlaskit/afm-i18n-platform-linking-platform-link-datasource": "2.242.0",
40
40
  "@atlaskit/analytics-cross-product": "^2.2.0",
41
41
  "@atlaskit/analytics-next": "^12.5.0",
42
- "@atlaskit/atlassian-context": "^1.1.0",
42
+ "@atlaskit/atlassian-context": "^1.2.0",
43
43
  "@atlaskit/avatar": "^28.0.0",
44
44
  "@atlaskit/avatar-group": "^14.3.0",
45
45
  "@atlaskit/badge": "^21.2.0",
46
46
  "@atlaskit/button": "^25.3.0",
47
47
  "@atlaskit/css": "^1.1.0",
48
- "@atlaskit/datetime-picker": "^18.6.0",
48
+ "@atlaskit/datetime-picker": "^18.7.0",
49
49
  "@atlaskit/dropdown-menu": "^18.3.0",
50
50
  "@atlaskit/editor-prosemirror": "^8.0.0",
51
51
  "@atlaskit/empty-state": "^12.2.0",
@@ -53,7 +53,7 @@
53
53
  "@atlaskit/flag": "^18.5.0",
54
54
  "@atlaskit/form": "^17.2.0",
55
55
  "@atlaskit/heading": "^7.2.0",
56
- "@atlaskit/icon": "^37.6.0",
56
+ "@atlaskit/icon": "^37.7.0",
57
57
  "@atlaskit/image": "^5.2.0",
58
58
  "@atlaskit/inline-edit": "^16.4.0",
59
59
  "@atlaskit/intl-messages-provider": "^4.3.0",
@@ -64,7 +64,7 @@
64
64
  "@atlaskit/link": "^5.1.0",
65
65
  "@atlaskit/link-client-extension": "^7.3.0",
66
66
  "@atlaskit/link-provider": "^5.6.0",
67
- "@atlaskit/linking-common": "^12.1.0",
67
+ "@atlaskit/linking-common": "^12.2.0",
68
68
  "@atlaskit/linking-types": "^15.3.0",
69
69
  "@atlaskit/logo": "^23.0.0",
70
70
  "@atlaskit/lozenge": "^15.4.0",
@@ -83,7 +83,7 @@
83
83
  "@atlaskit/react-compiler-gating": "^0.2.0",
84
84
  "@atlaskit/react-select": "^4.9.0",
85
85
  "@atlaskit/select": "^22.11.0",
86
- "@atlaskit/smart-card": "^45.22.0",
86
+ "@atlaskit/smart-card": "^45.23.0",
87
87
  "@atlaskit/smart-user-picker": "^11.8.0",
88
88
  "@atlaskit/spinner": "^20.4.0",
89
89
  "@atlaskit/tag": "^15.8.0",
@@ -143,6 +143,9 @@
143
143
  "wait-for-expect": "^1.2.0"
144
144
  },
145
145
  "platform-feature-flags": {
146
+ "platform_datasource_sync_info_boundary_updates": {
147
+ "type": "boolean"
148
+ },
146
149
  "platform_navx_3298_message_wrapper": {
147
150
  "type": "boolean"
148
151
  },
@@ -1,13 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.__clearUnitsRolloutSettingsCacheForTests = void 0;
7
- var _getUnitsRolloutSettings = require("./getUnitsRolloutSettings");
8
- /**
9
- * Test-only: clear the cached units rollout settings so each test starts with a clean slate.
10
- */
11
- var __clearUnitsRolloutSettingsCacheForTests = exports.__clearUnitsRolloutSettingsCacheForTests = function __clearUnitsRolloutSettingsCacheForTests() {
12
- _getUnitsRolloutSettings.cache.promise = undefined;
13
- };
@@ -1,199 +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.unitsRolloutSettingsQuery = exports.tenantContextQuery = exports.getUnitsRolloutSettings = exports.cache = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _linkingCommon = require("@atlaskit/linking-common");
11
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
12
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
13
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
14
- var AGG_URL = '/gateway/api/graphql';
15
- var TENANT_CONTEXT_OPERATION_NAME = 'link_datasource_tenantContext';
16
- var UNITS_ROLLOUT_SETTINGS_OPERATION_NAME = 'link_datasource_unitSettings';
17
-
18
- /**
19
- * `Query.admin_unitSettings` is keyed by org id, which the browser does not know, so the org id
20
- * is resolved from the host the product is currently served from.
21
- */
22
- var tenantContextQuery = exports.tenantContextQuery = "\n\tquery ".concat(TENANT_CONTEXT_OPERATION_NAME, "($hostNames: [String!]) {\n\t\ttenantContexts(hostNames: $hostNames) {\n\t\t\torgId\n\t\t}\n\t}\n");
23
-
24
- /**
25
- * `admin_unitSettings` exposes both flags of the rollout and is callable with the session of the
26
- * end user, so no opt-in directive or admin OAuth scope is needed from the browser.
27
- */
28
- var unitsRolloutSettingsQuery = exports.unitsRolloutSettingsQuery = "\n\tquery ".concat(UNITS_ROLLOUT_SETTINGS_OPERATION_NAME, "($orgId: ID!) {\n\t\tadmin_unitSettings(orgId: $orgId) {\n\t\t\tboundaryEnforced\n\t\t\tendUsersLaunched\n\t\t}\n\t}\n");
29
- /**
30
- * When the rollout settings cannot be resolved we keep the pre-isolation behaviour, which is
31
- * what every org gets today while the unit settings are unset. The settings are only
32
- * written when an org is activated - they are not backfilled - so `null` is expected for orgs
33
- * that have not been activated yet and must be read as `false`.
34
- */
35
- var DEFAULT_SETTINGS = {
36
- boundaryEnforced: false,
37
- endUsersLaunched: false
38
- };
39
-
40
- /**
41
- * Holds the in-flight/resolved request so that the settings are only fetched once per page load.
42
- */
43
- var cache = exports.cache = {};
44
-
45
- /**
46
- * AGG answers with a 200 and an `errors` array for query level failures, so those have to be
47
- * turned into a rejection explicitly rather than being read as an empty response.
48
- */
49
- var requestGraphQL = /*#__PURE__*/function () {
50
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(operationName, query, variables) {
51
- var _response$errors, _response$data;
52
- var response, messages;
53
- return _regenerator.default.wrap(function (_context) {
54
- while (1) switch (_context.prev = _context.next) {
55
- case 0:
56
- _context.next = 1;
57
- return (0, _linkingCommon.request)('post', AGG_URL, {
58
- operationName: operationName,
59
- query: query,
60
- variables: variables
61
- });
62
- case 1:
63
- response = _context.sent;
64
- if (!(response !== null && response !== void 0 && (_response$errors = response.errors) !== null && _response$errors !== void 0 && _response$errors.length)) {
65
- _context.next = 2;
66
- break;
67
- }
68
- messages = response.errors.map(function (error) {
69
- return error === null || error === void 0 ? void 0 : error.message;
70
- }).filter(Boolean).join(', ');
71
- throw new Error("".concat(operationName, " failed: ").concat(messages || 'unknown error'));
72
- case 2:
73
- return _context.abrupt("return", (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : undefined);
74
- case 3:
75
- case "end":
76
- return _context.stop();
77
- }
78
- }, _callee);
79
- }));
80
- return function requestGraphQL(_x, _x2, _x3) {
81
- return _ref.apply(this, arguments);
82
- };
83
- }();
84
- var fetchOrgId = /*#__PURE__*/function () {
85
- var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
86
- var _window$location, _data$tenantContexts;
87
- var hostName, data, _iterator, _step, tenantContext, _t;
88
- return _regenerator.default.wrap(function (_context2) {
89
- while (1) switch (_context2.prev = _context2.next) {
90
- case 0:
91
- hostName = typeof window !== 'undefined' ? (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname : undefined;
92
- if (hostName) {
93
- _context2.next = 1;
94
- break;
95
- }
96
- return _context2.abrupt("return", undefined);
97
- case 1:
98
- _context2.next = 2;
99
- return requestGraphQL(TENANT_CONTEXT_OPERATION_NAME, tenantContextQuery, {
100
- hostNames: [hostName]
101
- });
102
- case 2:
103
- data = _context2.sent;
104
- _iterator = _createForOfIteratorHelper((_data$tenantContexts = data === null || data === void 0 ? void 0 : data.tenantContexts) !== null && _data$tenantContexts !== void 0 ? _data$tenantContexts : []);
105
- _context2.prev = 3;
106
- _iterator.s();
107
- case 4:
108
- if ((_step = _iterator.n()).done) {
109
- _context2.next = 6;
110
- break;
111
- }
112
- tenantContext = _step.value;
113
- if (!(tenantContext !== null && tenantContext !== void 0 && tenantContext.orgId)) {
114
- _context2.next = 5;
115
- break;
116
- }
117
- return _context2.abrupt("return", tenantContext.orgId);
118
- case 5:
119
- _context2.next = 4;
120
- break;
121
- case 6:
122
- _context2.next = 8;
123
- break;
124
- case 7:
125
- _context2.prev = 7;
126
- _t = _context2["catch"](3);
127
- _iterator.e(_t);
128
- case 8:
129
- _context2.prev = 8;
130
- _iterator.f();
131
- return _context2.finish(8);
132
- case 9:
133
- return _context2.abrupt("return", undefined);
134
- case 10:
135
- case "end":
136
- return _context2.stop();
137
- }
138
- }, _callee2, null, [[3, 7, 8, 9]]);
139
- }));
140
- return function fetchOrgId() {
141
- return _ref2.apply(this, arguments);
142
- };
143
- }();
144
- var fetchUnitsRolloutSettings = /*#__PURE__*/function () {
145
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
146
- var _settings$boundaryEnf, _settings$endUsersLau;
147
- var orgId, data, settings;
148
- return _regenerator.default.wrap(function (_context3) {
149
- while (1) switch (_context3.prev = _context3.next) {
150
- case 0:
151
- _context3.next = 1;
152
- return fetchOrgId();
153
- case 1:
154
- orgId = _context3.sent;
155
- if (orgId) {
156
- _context3.next = 2;
157
- break;
158
- }
159
- return _context3.abrupt("return", DEFAULT_SETTINGS);
160
- case 2:
161
- _context3.next = 3;
162
- return requestGraphQL(UNITS_ROLLOUT_SETTINGS_OPERATION_NAME, unitsRolloutSettingsQuery, {
163
- orgId: orgId
164
- });
165
- case 3:
166
- data = _context3.sent;
167
- settings = data === null || data === void 0 ? void 0 : data.admin_unitSettings;
168
- return _context3.abrupt("return", {
169
- boundaryEnforced: (_settings$boundaryEnf = settings === null || settings === void 0 ? void 0 : settings.boundaryEnforced) !== null && _settings$boundaryEnf !== void 0 ? _settings$boundaryEnf : false,
170
- endUsersLaunched: (_settings$endUsersLau = settings === null || settings === void 0 ? void 0 : settings.endUsersLaunched) !== null && _settings$endUsersLau !== void 0 ? _settings$endUsersLau : false
171
- });
172
- case 4:
173
- case "end":
174
- return _context3.stop();
175
- }
176
- }, _callee3);
177
- }));
178
- return function fetchUnitsRolloutSettings() {
179
- return _ref3.apply(this, arguments);
180
- };
181
- }();
182
-
183
- /**
184
- * Reads the org's units rollout settings (`boundaryEnforced` and `endUsersLaunched`) from the
185
- * TCS key exposed by AGG's `Query.admin_unitSettings`.
186
- *
187
- * The result is cached for the lifetime of the page because the settings only change when an
188
- * admin activates or launches units, which requires a reload to be picked up anyway. A failed
189
- * request is not cached so that a later call can retry.
190
- */
191
- var getUnitsRolloutSettings = exports.getUnitsRolloutSettings = function getUnitsRolloutSettings() {
192
- if (!cache.promise) {
193
- cache.promise = fetchUnitsRolloutSettings().catch(function () {
194
- cache.promise = undefined;
195
- return DEFAULT_SETTINGS;
196
- });
197
- }
198
- return cache.promise;
199
- };
@@ -1,63 +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.isUnitsIsolationEnabled = void 0;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
- var _fg = require("@atlaskit/platform-feature-flags/fg");
11
- var _getUnitsRolloutSettings = require("./getUnitsRolloutSettings");
12
- /**
13
- * Whether unit isolation behaviour should be applied for the current org.
14
- *
15
- * An org is isolated when units GA is on, the org has been opted in to the rollout - either by
16
- * org id or by cloud id - *and* the org has actually launched units with boundary enforcement
17
- * turned on:
18
- *
19
- * `cc-units-ga on -> (orgId gate on || cloudId gate on) -> endUsersLaunched && boundaryEnforced -> isolate`
20
- *
21
- * `cc-units-ga` is the units GA master gate and acts as the killswitch: while it is off nothing
22
- * else is evaluated and the current, non-isolated behaviour is kept. The AGG call is only made
23
- * when one of the rollout gates passes, so orgs outside of the rollout do not pay for an extra
24
- * request.
25
- */
26
- var isUnitsIsolationEnabled = exports.isUnitsIsolationEnabled = /*#__PURE__*/function () {
27
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
28
- var isOrgInRollout, isCloudInRollout, _yield$getUnitsRollou, boundaryEnforced, endUsersLaunched;
29
- return _regenerator.default.wrap(function (_context) {
30
- while (1) switch (_context.prev = _context.next) {
31
- case 0:
32
- if ((0, _fg.fg)('cc-units-ga')) {
33
- _context.next = 1;
34
- break;
35
- }
36
- return _context.abrupt("return", false);
37
- case 1:
38
- // Both rollout gates are always evaluated so that exposure is recorded consistently.
39
- isOrgInRollout = (0, _fg.fg)('linking_platform_link_datasource_unit_compliant');
40
- isCloudInRollout = (0, _fg.fg)('linking_platform_link_datasource_unit_compliant_cloud_id');
41
- if (!(!isOrgInRollout && !isCloudInRollout)) {
42
- _context.next = 2;
43
- break;
44
- }
45
- return _context.abrupt("return", false);
46
- case 2:
47
- _context.next = 3;
48
- return (0, _getUnitsRolloutSettings.getUnitsRolloutSettings)();
49
- case 3:
50
- _yield$getUnitsRollou = _context.sent;
51
- boundaryEnforced = _yield$getUnitsRollou.boundaryEnforced;
52
- endUsersLaunched = _yield$getUnitsRollou.endUsersLaunched;
53
- return _context.abrupt("return", boundaryEnforced && endUsersLaunched);
54
- case 4:
55
- case "end":
56
- return _context.stop();
57
- }
58
- }, _callee);
59
- }));
60
- return function isUnitsIsolationEnabled() {
61
- return _ref.apply(this, arguments);
62
- };
63
- }();
@@ -1,8 +0,0 @@
1
- import { cache } from './getUnitsRolloutSettings';
2
-
3
- /**
4
- * Test-only: clear the cached units rollout settings so each test starts with a clean slate.
5
- */
6
- export const __clearUnitsRolloutSettingsCacheForTests = () => {
7
- cache.promise = undefined;
8
- };
@@ -1,112 +0,0 @@
1
- import { request } from '@atlaskit/linking-common';
2
- const AGG_URL = '/gateway/api/graphql';
3
- const TENANT_CONTEXT_OPERATION_NAME = 'link_datasource_tenantContext';
4
- const UNITS_ROLLOUT_SETTINGS_OPERATION_NAME = 'link_datasource_unitSettings';
5
-
6
- /**
7
- * `Query.admin_unitSettings` is keyed by org id, which the browser does not know, so the org id
8
- * is resolved from the host the product is currently served from.
9
- */
10
- export const tenantContextQuery = `
11
- query ${TENANT_CONTEXT_OPERATION_NAME}($hostNames: [String!]) {
12
- tenantContexts(hostNames: $hostNames) {
13
- orgId
14
- }
15
- }
16
- `;
17
-
18
- /**
19
- * `admin_unitSettings` exposes both flags of the rollout and is callable with the session of the
20
- * end user, so no opt-in directive or admin OAuth scope is needed from the browser.
21
- */
22
- export const unitsRolloutSettingsQuery = `
23
- query ${UNITS_ROLLOUT_SETTINGS_OPERATION_NAME}($orgId: ID!) {
24
- admin_unitSettings(orgId: $orgId) {
25
- boundaryEnforced
26
- endUsersLaunched
27
- }
28
- }
29
- `;
30
- /**
31
- * When the rollout settings cannot be resolved we keep the pre-isolation behaviour, which is
32
- * what every org gets today while the unit settings are unset. The settings are only
33
- * written when an org is activated - they are not backfilled - so `null` is expected for orgs
34
- * that have not been activated yet and must be read as `false`.
35
- */
36
- const DEFAULT_SETTINGS = {
37
- boundaryEnforced: false,
38
- endUsersLaunched: false
39
- };
40
-
41
- /**
42
- * Holds the in-flight/resolved request so that the settings are only fetched once per page load.
43
- */
44
- export const cache = {};
45
-
46
- /**
47
- * AGG answers with a 200 and an `errors` array for query level failures, so those have to be
48
- * turned into a rejection explicitly rather than being read as an empty response.
49
- */
50
- const requestGraphQL = async (operationName, query, variables) => {
51
- var _response$errors, _response$data;
52
- const response = await request('post', AGG_URL, {
53
- operationName,
54
- query,
55
- variables
56
- });
57
- if (response !== null && response !== void 0 && (_response$errors = response.errors) !== null && _response$errors !== void 0 && _response$errors.length) {
58
- const messages = response.errors.map(error => error === null || error === void 0 ? void 0 : error.message).filter(Boolean).join(', ');
59
- throw new Error(`${operationName} failed: ${messages || 'unknown error'}`);
60
- }
61
- return (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : undefined;
62
- };
63
- const fetchOrgId = async () => {
64
- var _window$location;
65
- const hostName = typeof window !== 'undefined' ? (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname : undefined;
66
- if (!hostName) {
67
- return undefined;
68
- }
69
- const data = await requestGraphQL(TENANT_CONTEXT_OPERATION_NAME, tenantContextQuery, {
70
- hostNames: [hostName]
71
- });
72
- for (const tenantContext of (_data$tenantContexts = data === null || data === void 0 ? void 0 : data.tenantContexts) !== null && _data$tenantContexts !== void 0 ? _data$tenantContexts : []) {
73
- var _data$tenantContexts;
74
- if (tenantContext !== null && tenantContext !== void 0 && tenantContext.orgId) {
75
- return tenantContext.orgId;
76
- }
77
- }
78
- return undefined;
79
- };
80
- const fetchUnitsRolloutSettings = async () => {
81
- var _settings$boundaryEnf, _settings$endUsersLau;
82
- const orgId = await fetchOrgId();
83
- if (!orgId) {
84
- return DEFAULT_SETTINGS;
85
- }
86
- const data = await requestGraphQL(UNITS_ROLLOUT_SETTINGS_OPERATION_NAME, unitsRolloutSettingsQuery, {
87
- orgId
88
- });
89
- const settings = data === null || data === void 0 ? void 0 : data.admin_unitSettings;
90
- return {
91
- boundaryEnforced: (_settings$boundaryEnf = settings === null || settings === void 0 ? void 0 : settings.boundaryEnforced) !== null && _settings$boundaryEnf !== void 0 ? _settings$boundaryEnf : false,
92
- endUsersLaunched: (_settings$endUsersLau = settings === null || settings === void 0 ? void 0 : settings.endUsersLaunched) !== null && _settings$endUsersLau !== void 0 ? _settings$endUsersLau : false
93
- };
94
- };
95
-
96
- /**
97
- * Reads the org's units rollout settings (`boundaryEnforced` and `endUsersLaunched`) from the
98
- * TCS key exposed by AGG's `Query.admin_unitSettings`.
99
- *
100
- * The result is cached for the lifetime of the page because the settings only change when an
101
- * admin activates or launches units, which requires a reload to be picked up anyway. A failed
102
- * request is not cached so that a later call can retry.
103
- */
104
- export const getUnitsRolloutSettings = () => {
105
- if (!cache.promise) {
106
- cache.promise = fetchUnitsRolloutSettings().catch(() => {
107
- cache.promise = undefined;
108
- return DEFAULT_SETTINGS;
109
- });
110
- }
111
- return cache.promise;
112
- };
@@ -1,34 +0,0 @@
1
- import { fg } from '@atlaskit/platform-feature-flags/fg';
2
- import { getUnitsRolloutSettings } from './getUnitsRolloutSettings';
3
-
4
- /**
5
- * Whether unit isolation behaviour should be applied for the current org.
6
- *
7
- * An org is isolated when units GA is on, the org has been opted in to the rollout - either by
8
- * org id or by cloud id - *and* the org has actually launched units with boundary enforcement
9
- * turned on:
10
- *
11
- * `cc-units-ga on -> (orgId gate on || cloudId gate on) -> endUsersLaunched && boundaryEnforced -> isolate`
12
- *
13
- * `cc-units-ga` is the units GA master gate and acts as the killswitch: while it is off nothing
14
- * else is evaluated and the current, non-isolated behaviour is kept. The AGG call is only made
15
- * when one of the rollout gates passes, so orgs outside of the rollout do not pay for an extra
16
- * request.
17
- */
18
- export const isUnitsIsolationEnabled = async () => {
19
- if (!fg('cc-units-ga')) {
20
- return false;
21
- }
22
-
23
- // Both rollout gates are always evaluated so that exposure is recorded consistently.
24
- const isOrgInRollout = fg('linking_platform_link_datasource_unit_compliant');
25
- const isCloudInRollout = fg('linking_platform_link_datasource_unit_compliant_cloud_id');
26
- if (!isOrgInRollout && !isCloudInRollout) {
27
- return false;
28
- }
29
- const {
30
- boundaryEnforced,
31
- endUsersLaunched
32
- } = await getUnitsRolloutSettings();
33
- return boundaryEnforced && endUsersLaunched;
34
- };
@@ -1,8 +0,0 @@
1
- import { cache } from './getUnitsRolloutSettings';
2
-
3
- /**
4
- * Test-only: clear the cached units rollout settings so each test starts with a clean slate.
5
- */
6
- export var __clearUnitsRolloutSettingsCacheForTests = function __clearUnitsRolloutSettingsCacheForTests() {
7
- cache.promise = undefined;
8
- };
@@ -1,192 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- import _regeneratorRuntime from "@babel/runtime/regenerator";
6
- import { request } from '@atlaskit/linking-common';
7
- var AGG_URL = '/gateway/api/graphql';
8
- var TENANT_CONTEXT_OPERATION_NAME = 'link_datasource_tenantContext';
9
- var UNITS_ROLLOUT_SETTINGS_OPERATION_NAME = 'link_datasource_unitSettings';
10
-
11
- /**
12
- * `Query.admin_unitSettings` is keyed by org id, which the browser does not know, so the org id
13
- * is resolved from the host the product is currently served from.
14
- */
15
- export var tenantContextQuery = "\n\tquery ".concat(TENANT_CONTEXT_OPERATION_NAME, "($hostNames: [String!]) {\n\t\ttenantContexts(hostNames: $hostNames) {\n\t\t\torgId\n\t\t}\n\t}\n");
16
-
17
- /**
18
- * `admin_unitSettings` exposes both flags of the rollout and is callable with the session of the
19
- * end user, so no opt-in directive or admin OAuth scope is needed from the browser.
20
- */
21
- export var unitsRolloutSettingsQuery = "\n\tquery ".concat(UNITS_ROLLOUT_SETTINGS_OPERATION_NAME, "($orgId: ID!) {\n\t\tadmin_unitSettings(orgId: $orgId) {\n\t\t\tboundaryEnforced\n\t\t\tendUsersLaunched\n\t\t}\n\t}\n");
22
- /**
23
- * When the rollout settings cannot be resolved we keep the pre-isolation behaviour, which is
24
- * what every org gets today while the unit settings are unset. The settings are only
25
- * written when an org is activated - they are not backfilled - so `null` is expected for orgs
26
- * that have not been activated yet and must be read as `false`.
27
- */
28
- var DEFAULT_SETTINGS = {
29
- boundaryEnforced: false,
30
- endUsersLaunched: false
31
- };
32
-
33
- /**
34
- * Holds the in-flight/resolved request so that the settings are only fetched once per page load.
35
- */
36
- export var cache = {};
37
-
38
- /**
39
- * AGG answers with a 200 and an `errors` array for query level failures, so those have to be
40
- * turned into a rejection explicitly rather than being read as an empty response.
41
- */
42
- var requestGraphQL = /*#__PURE__*/function () {
43
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(operationName, query, variables) {
44
- var _response$errors, _response$data;
45
- var response, messages;
46
- return _regeneratorRuntime.wrap(function (_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- _context.next = 1;
50
- return request('post', AGG_URL, {
51
- operationName: operationName,
52
- query: query,
53
- variables: variables
54
- });
55
- case 1:
56
- response = _context.sent;
57
- if (!(response !== null && response !== void 0 && (_response$errors = response.errors) !== null && _response$errors !== void 0 && _response$errors.length)) {
58
- _context.next = 2;
59
- break;
60
- }
61
- messages = response.errors.map(function (error) {
62
- return error === null || error === void 0 ? void 0 : error.message;
63
- }).filter(Boolean).join(', ');
64
- throw new Error("".concat(operationName, " failed: ").concat(messages || 'unknown error'));
65
- case 2:
66
- return _context.abrupt("return", (_response$data = response === null || response === void 0 ? void 0 : response.data) !== null && _response$data !== void 0 ? _response$data : undefined);
67
- case 3:
68
- case "end":
69
- return _context.stop();
70
- }
71
- }, _callee);
72
- }));
73
- return function requestGraphQL(_x, _x2, _x3) {
74
- return _ref.apply(this, arguments);
75
- };
76
- }();
77
- var fetchOrgId = /*#__PURE__*/function () {
78
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
79
- var _window$location, _data$tenantContexts;
80
- var hostName, data, _iterator, _step, tenantContext, _t;
81
- return _regeneratorRuntime.wrap(function (_context2) {
82
- while (1) switch (_context2.prev = _context2.next) {
83
- case 0:
84
- hostName = typeof window !== 'undefined' ? (_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname : undefined;
85
- if (hostName) {
86
- _context2.next = 1;
87
- break;
88
- }
89
- return _context2.abrupt("return", undefined);
90
- case 1:
91
- _context2.next = 2;
92
- return requestGraphQL(TENANT_CONTEXT_OPERATION_NAME, tenantContextQuery, {
93
- hostNames: [hostName]
94
- });
95
- case 2:
96
- data = _context2.sent;
97
- _iterator = _createForOfIteratorHelper((_data$tenantContexts = data === null || data === void 0 ? void 0 : data.tenantContexts) !== null && _data$tenantContexts !== void 0 ? _data$tenantContexts : []);
98
- _context2.prev = 3;
99
- _iterator.s();
100
- case 4:
101
- if ((_step = _iterator.n()).done) {
102
- _context2.next = 6;
103
- break;
104
- }
105
- tenantContext = _step.value;
106
- if (!(tenantContext !== null && tenantContext !== void 0 && tenantContext.orgId)) {
107
- _context2.next = 5;
108
- break;
109
- }
110
- return _context2.abrupt("return", tenantContext.orgId);
111
- case 5:
112
- _context2.next = 4;
113
- break;
114
- case 6:
115
- _context2.next = 8;
116
- break;
117
- case 7:
118
- _context2.prev = 7;
119
- _t = _context2["catch"](3);
120
- _iterator.e(_t);
121
- case 8:
122
- _context2.prev = 8;
123
- _iterator.f();
124
- return _context2.finish(8);
125
- case 9:
126
- return _context2.abrupt("return", undefined);
127
- case 10:
128
- case "end":
129
- return _context2.stop();
130
- }
131
- }, _callee2, null, [[3, 7, 8, 9]]);
132
- }));
133
- return function fetchOrgId() {
134
- return _ref2.apply(this, arguments);
135
- };
136
- }();
137
- var fetchUnitsRolloutSettings = /*#__PURE__*/function () {
138
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
139
- var _settings$boundaryEnf, _settings$endUsersLau;
140
- var orgId, data, settings;
141
- return _regeneratorRuntime.wrap(function (_context3) {
142
- while (1) switch (_context3.prev = _context3.next) {
143
- case 0:
144
- _context3.next = 1;
145
- return fetchOrgId();
146
- case 1:
147
- orgId = _context3.sent;
148
- if (orgId) {
149
- _context3.next = 2;
150
- break;
151
- }
152
- return _context3.abrupt("return", DEFAULT_SETTINGS);
153
- case 2:
154
- _context3.next = 3;
155
- return requestGraphQL(UNITS_ROLLOUT_SETTINGS_OPERATION_NAME, unitsRolloutSettingsQuery, {
156
- orgId: orgId
157
- });
158
- case 3:
159
- data = _context3.sent;
160
- settings = data === null || data === void 0 ? void 0 : data.admin_unitSettings;
161
- return _context3.abrupt("return", {
162
- boundaryEnforced: (_settings$boundaryEnf = settings === null || settings === void 0 ? void 0 : settings.boundaryEnforced) !== null && _settings$boundaryEnf !== void 0 ? _settings$boundaryEnf : false,
163
- endUsersLaunched: (_settings$endUsersLau = settings === null || settings === void 0 ? void 0 : settings.endUsersLaunched) !== null && _settings$endUsersLau !== void 0 ? _settings$endUsersLau : false
164
- });
165
- case 4:
166
- case "end":
167
- return _context3.stop();
168
- }
169
- }, _callee3);
170
- }));
171
- return function fetchUnitsRolloutSettings() {
172
- return _ref3.apply(this, arguments);
173
- };
174
- }();
175
-
176
- /**
177
- * Reads the org's units rollout settings (`boundaryEnforced` and `endUsersLaunched`) from the
178
- * TCS key exposed by AGG's `Query.admin_unitSettings`.
179
- *
180
- * The result is cached for the lifetime of the page because the settings only change when an
181
- * admin activates or launches units, which requires a reload to be picked up anyway. A failed
182
- * request is not cached so that a later call can retry.
183
- */
184
- export var getUnitsRolloutSettings = function getUnitsRolloutSettings() {
185
- if (!cache.promise) {
186
- cache.promise = fetchUnitsRolloutSettings().catch(function () {
187
- cache.promise = undefined;
188
- return DEFAULT_SETTINGS;
189
- });
190
- }
191
- return cache.promise;
192
- };
@@ -1,57 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _regeneratorRuntime from "@babel/runtime/regenerator";
3
- import { fg } from '@atlaskit/platform-feature-flags/fg';
4
- import { getUnitsRolloutSettings } from './getUnitsRolloutSettings';
5
-
6
- /**
7
- * Whether unit isolation behaviour should be applied for the current org.
8
- *
9
- * An org is isolated when units GA is on, the org has been opted in to the rollout - either by
10
- * org id or by cloud id - *and* the org has actually launched units with boundary enforcement
11
- * turned on:
12
- *
13
- * `cc-units-ga on -> (orgId gate on || cloudId gate on) -> endUsersLaunched && boundaryEnforced -> isolate`
14
- *
15
- * `cc-units-ga` is the units GA master gate and acts as the killswitch: while it is off nothing
16
- * else is evaluated and the current, non-isolated behaviour is kept. The AGG call is only made
17
- * when one of the rollout gates passes, so orgs outside of the rollout do not pay for an extra
18
- * request.
19
- */
20
- export var isUnitsIsolationEnabled = /*#__PURE__*/function () {
21
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
22
- var isOrgInRollout, isCloudInRollout, _yield$getUnitsRollou, boundaryEnforced, endUsersLaunched;
23
- return _regeneratorRuntime.wrap(function (_context) {
24
- while (1) switch (_context.prev = _context.next) {
25
- case 0:
26
- if (fg('cc-units-ga')) {
27
- _context.next = 1;
28
- break;
29
- }
30
- return _context.abrupt("return", false);
31
- case 1:
32
- // Both rollout gates are always evaluated so that exposure is recorded consistently.
33
- isOrgInRollout = fg('linking_platform_link_datasource_unit_compliant');
34
- isCloudInRollout = fg('linking_platform_link_datasource_unit_compliant_cloud_id');
35
- if (!(!isOrgInRollout && !isCloudInRollout)) {
36
- _context.next = 2;
37
- break;
38
- }
39
- return _context.abrupt("return", false);
40
- case 2:
41
- _context.next = 3;
42
- return getUnitsRolloutSettings();
43
- case 3:
44
- _yield$getUnitsRollou = _context.sent;
45
- boundaryEnforced = _yield$getUnitsRollou.boundaryEnforced;
46
- endUsersLaunched = _yield$getUnitsRollou.endUsersLaunched;
47
- return _context.abrupt("return", boundaryEnforced && endUsersLaunched);
48
- case 4:
49
- case "end":
50
- return _context.stop();
51
- }
52
- }, _callee);
53
- }));
54
- return function isUnitsIsolationEnabled() {
55
- return _ref.apply(this, arguments);
56
- };
57
- }();
@@ -1,4 +0,0 @@
1
- /**
2
- * Test-only: clear the cached units rollout settings so each test starts with a clean slate.
3
- */
4
- export declare const __clearUnitsRolloutSettingsCacheForTests: () => void;
@@ -1,29 +0,0 @@
1
- /**
2
- * `Query.admin_unitSettings` is keyed by org id, which the browser does not know, so the org id
3
- * is resolved from the host the product is currently served from.
4
- */
5
- export declare const tenantContextQuery: string;
6
- /**
7
- * `admin_unitSettings` exposes both flags of the rollout and is callable with the session of the
8
- * end user, so no opt-in directive or admin OAuth scope is needed from the browser.
9
- */
10
- export declare const unitsRolloutSettingsQuery: string;
11
- export interface UnitsRolloutSettings {
12
- boundaryEnforced: boolean;
13
- endUsersLaunched: boolean;
14
- }
15
- /**
16
- * Holds the in-flight/resolved request so that the settings are only fetched once per page load.
17
- */
18
- export declare const cache: {
19
- promise?: Promise<UnitsRolloutSettings>;
20
- };
21
- /**
22
- * Reads the org's units rollout settings (`boundaryEnforced` and `endUsersLaunched`) from the
23
- * TCS key exposed by AGG's `Query.admin_unitSettings`.
24
- *
25
- * The result is cached for the lifetime of the page because the settings only change when an
26
- * admin activates or launches units, which requires a reload to be picked up anyway. A failed
27
- * request is not cached so that a later call can retry.
28
- */
29
- export declare const getUnitsRolloutSettings: () => Promise<UnitsRolloutSettings>;
@@ -1,15 +0,0 @@
1
- /**
2
- * Whether unit isolation behaviour should be applied for the current org.
3
- *
4
- * An org is isolated when units GA is on, the org has been opted in to the rollout - either by
5
- * org id or by cloud id - *and* the org has actually launched units with boundary enforcement
6
- * turned on:
7
- *
8
- * `cc-units-ga on -> (orgId gate on || cloudId gate on) -> endUsersLaunched && boundaryEnforced -> isolate`
9
- *
10
- * `cc-units-ga` is the units GA master gate and acts as the killswitch: while it is off nothing
11
- * else is evaluated and the current, non-isolated behaviour is kept. The AGG call is only made
12
- * when one of the rollout gates passes, so orgs outside of the rollout do not pay for an extra
13
- * request.
14
- */
15
- export declare const isUnitsIsolationEnabled: () => Promise<boolean>;