@atlaskit/smart-card 44.5.0 → 44.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/extractors/flexible/actions/extract-rovo-chat-action.js +3 -4
- package/dist/cjs/state/hooks/use-current-site-cloud-id/index.js +71 -0
- package/dist/cjs/state/hooks/use-social-proof/index.js +60 -0
- package/dist/cjs/state/services/current-site-cloud-id/index.js +182 -0
- package/dist/cjs/state/services/personalization/index.js +267 -0
- package/dist/cjs/state/services/personalization/types.js +1 -0
- package/dist/cjs/utils/analytics/analytics.js +1 -1
- package/dist/cjs/view/LinkUrl/index.js +1 -1
- package/dist/es2019/extractors/flexible/actions/extract-rovo-chat-action.js +3 -4
- package/dist/es2019/state/hooks/use-current-site-cloud-id/index.js +28 -0
- package/dist/es2019/state/hooks/use-social-proof/index.js +45 -0
- package/dist/es2019/state/services/current-site-cloud-id/index.js +118 -0
- package/dist/es2019/state/services/personalization/index.js +164 -0
- package/dist/es2019/state/services/personalization/types.js +0 -0
- package/dist/es2019/utils/analytics/analytics.js +1 -1
- package/dist/es2019/view/LinkUrl/index.js +1 -1
- package/dist/esm/extractors/flexible/actions/extract-rovo-chat-action.js +3 -4
- package/dist/esm/state/hooks/use-current-site-cloud-id/index.js +35 -0
- package/dist/esm/state/hooks/use-social-proof/index.js +53 -0
- package/dist/esm/state/services/current-site-cloud-id/index.js +174 -0
- package/dist/esm/state/services/personalization/index.js +258 -0
- package/dist/esm/state/services/personalization/types.js +0 -0
- package/dist/esm/utils/analytics/analytics.js +1 -1
- package/dist/esm/view/LinkUrl/index.js +1 -1
- package/dist/types/common/ui/icons/blog-icon.d.ts +1 -1
- package/dist/types/common/ui/icons/live-document-icon.d.ts +1 -1
- package/dist/types/state/hooks/use-current-site-cloud-id/index.d.ts +6 -0
- package/dist/types/state/hooks/use-social-proof/index.d.ts +13 -0
- package/dist/types/state/services/current-site-cloud-id/index.d.ts +46 -0
- package/dist/types/state/services/personalization/index.d.ts +41 -0
- package/dist/types/state/services/personalization/types.d.ts +10 -0
- package/dist/types/view/FlexibleCard/assets/ai-chapter-icon.d.ts +3 -2
- package/dist/types/view/FlexibleCard/assets/ai-edit-icon.d.ts +3 -2
- package/dist/types/view/FlexibleCard/assets/ai-search-icon.d.ts +3 -2
- package/dist/types/view/FlexibleCard/assets/rovo-hex-logo.d.ts +4 -3
- package/dist/types-ts4.5/common/ui/icons/blog-icon.d.ts +1 -1
- package/dist/types-ts4.5/common/ui/icons/live-document-icon.d.ts +1 -1
- package/dist/types-ts4.5/state/hooks/use-current-site-cloud-id/index.d.ts +6 -0
- package/dist/types-ts4.5/state/hooks/use-social-proof/index.d.ts +13 -0
- package/dist/types-ts4.5/state/services/current-site-cloud-id/index.d.ts +46 -0
- package/dist/types-ts4.5/state/services/personalization/index.d.ts +41 -0
- package/dist/types-ts4.5/state/services/personalization/types.d.ts +10 -0
- package/dist/types-ts4.5/view/FlexibleCard/assets/ai-chapter-icon.d.ts +3 -2
- package/dist/types-ts4.5/view/FlexibleCard/assets/ai-edit-icon.d.ts +3 -2
- package/dist/types-ts4.5/view/FlexibleCard/assets/ai-search-icon.d.ts +3 -2
- package/dist/types-ts4.5/view/FlexibleCard/assets/rovo-hex-logo.d.ts +4 -3
- package/package.json +2 -2
- package/smart-card.docs.tsx +35 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 44.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4403ed7990e4b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/4403ed7990e4b) -
|
|
8
|
+
Add smart-card internal state services and hooks for social proof and current site cloud id
|
|
9
|
+
retrieval.
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 44.5.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`9bf56e51dae31`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/9bf56e51dae31) -
|
|
17
|
+
Scope block card Rovo Chat action to eligible providers (Google, OneDrive, Slack, Teams, GitHub,
|
|
18
|
+
GitLab, Salesforce) using an allowlist instead of relying on the supportsRovoActions backend flag.
|
|
19
|
+
- Updated dependencies
|
|
20
|
+
|
|
3
21
|
## 44.5.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -12,10 +12,10 @@ var _helpers = require("../../../state/helpers");
|
|
|
12
12
|
var _canShowAction = require("../../../utils/actions/can-show-action");
|
|
13
13
|
var _rovo = require("../../../utils/rovo");
|
|
14
14
|
var _types = require("../../../view/Card/types");
|
|
15
|
-
// For rovogrowth-640 post auth inline experiment
|
|
15
|
+
// For rovogrowth-640 post auth inline experiment and block card experiment (NAVX-4814)
|
|
16
16
|
var ELIGIBLE_EXTENSION_KEYS = new Set(['slack-object-provider', 'google-object-provider', 'onedrive-object-provider', 'github-object-provider', 'ms-teams-object-provider', 'gitlab-object-provider', 'salesforce-object-provider']);
|
|
17
17
|
var extractRovoChatAction = function extractRovoChatAction(_ref) {
|
|
18
|
-
var
|
|
18
|
+
var _actionOptions$rovoCh;
|
|
19
19
|
var actionOptions = _ref.actionOptions,
|
|
20
20
|
appearance = _ref.appearance,
|
|
21
21
|
id = _ref.id,
|
|
@@ -29,12 +29,11 @@ var extractRovoChatAction = function extractRovoChatAction(_ref) {
|
|
|
29
29
|
if (!isRovoChatEnabled) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
var supportsRovoActions = response === null || response === void 0 || (_response$meta = response.meta) === null || _response$meta === void 0 || (_response$meta = _response$meta.supportedFeature) === null || _response$meta === void 0 ? void 0 : _response$meta.includes('RovoActions');
|
|
33
32
|
var extensionKey = (0, _helpers.getExtensionKey)(response);
|
|
34
33
|
var isGoogleProvider = extensionKey === 'google-object-provider';
|
|
35
34
|
var is3PAuthRovoActionEnabled = isGoogleProvider && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_action_kill_switch');
|
|
36
35
|
var is3PInlinePostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && (0, _platformFeatureFlags.fg)('rovogrowth-640-inline-action-nudge-fg') && (0, _expValEqualsNoExposure.expValEqualsNoExposure)('rovogrowth-640-inline-action-nudge-exp', 'isEnabled', true);
|
|
37
|
-
var is3PBlockPostAuthActionsEnabled =
|
|
36
|
+
var is3PBlockPostAuthActionsEnabled = extensionKey !== undefined && ELIGIBLE_EXTENSION_KEYS.has(extensionKey) && (0, _platformFeatureFlags.fg)('platform_sl_3p_auth_rovo_block_card_kill_switch');
|
|
38
37
|
var isSupportedFeature = is3PInlinePostAuthActionsEnabled || is3PAuthRovoActionEnabled || is3PBlockPostAuthActionsEnabled;
|
|
39
38
|
var isOptIn = (actionOptions === null || actionOptions === void 0 || (_actionOptions$rovoCh = actionOptions.rovoChatAction) === null || _actionOptions$rovoCh === void 0 ? void 0 : _actionOptions$rovoCh.optIn) === true;
|
|
40
39
|
var url = (0, _linkExtractors.extractSmartLinkUrl)(response);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _currentSiteCloudId.CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _currentSiteCloudId.CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "currentSiteCloudIdService", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _currentSiteCloudId.currentSiteCloudIdService;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
exports.default = void 0;
|
|
26
|
+
Object.defineProperty(exports, "getCachedCurrentSiteCloudIdAndRefresh", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _currentSiteCloudId.getCachedCurrentSiteCloudIdAndRefresh;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
Object.defineProperty(exports, "getCurrentSiteCloudId", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _currentSiteCloudId.getCurrentSiteCloudId;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
39
|
+
var _react = require("react");
|
|
40
|
+
var _currentSiteCloudId = require("../../services/current-site-cloud-id");
|
|
41
|
+
var useCurrentSiteCloudId = function useCurrentSiteCloudId() {
|
|
42
|
+
var _useState = (0, _react.useState)(undefined),
|
|
43
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
44
|
+
cloudId = _useState2[0],
|
|
45
|
+
setCloudId = _useState2[1];
|
|
46
|
+
var _useState3 = (0, _react.useState)(true),
|
|
47
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
48
|
+
isLoading = _useState4[0],
|
|
49
|
+
setIsLoading = _useState4[1];
|
|
50
|
+
(0, _react.useEffect)(function () {
|
|
51
|
+
var cancelled = false;
|
|
52
|
+
setIsLoading(true);
|
|
53
|
+
void (0, _currentSiteCloudId.getCurrentSiteCloudId)().then(function (id) {
|
|
54
|
+
if (!cancelled) {
|
|
55
|
+
setCloudId(id);
|
|
56
|
+
}
|
|
57
|
+
}).finally(function () {
|
|
58
|
+
if (!cancelled) {
|
|
59
|
+
setIsLoading(false);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return function () {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
return {
|
|
67
|
+
cloudId: cloudId,
|
|
68
|
+
isLoading: isLoading
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
var _default = exports.default = useCurrentSiteCloudId;
|
|
@@ -0,0 +1,60 @@
|
|
|
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 _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _personalization = require("../../services/personalization");
|
|
11
|
+
var NOT_ENABLED_RESULT = {
|
|
12
|
+
connectedPct: undefined,
|
|
13
|
+
isEnabled: false,
|
|
14
|
+
isLoading: false
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Fetches provider usage percentage from the TAP Delivery personalization service when the
|
|
19
|
+
* killswitch allows it. Callers decide separately (e.g. via Statsig experiment) whether to
|
|
20
|
+
* surface that data in the UI.
|
|
21
|
+
*/
|
|
22
|
+
var useSocialProof = function useSocialProof(traitName, extensionKey) {
|
|
23
|
+
var isKillswitchOn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
24
|
+
var isEnabled = isKillswitchOn;
|
|
25
|
+
var _useState = (0, _react.useState)(undefined),
|
|
26
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
27
|
+
providerPctMap = _useState2[0],
|
|
28
|
+
setProviderPctMap = _useState2[1];
|
|
29
|
+
var _useState3 = (0, _react.useState)(false),
|
|
30
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
31
|
+
isPersonalizationLoading = _useState4[0],
|
|
32
|
+
setIsPersonalizationLoading = _useState4[1];
|
|
33
|
+
(0, _react.useEffect)(function () {
|
|
34
|
+
if (!isEnabled) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var cancelled = false;
|
|
38
|
+
setIsPersonalizationLoading(true);
|
|
39
|
+
(0, _personalization.getProviderPctMap)(traitName).then(function (pctMap) {
|
|
40
|
+
if (!cancelled) {
|
|
41
|
+
setProviderPctMap(pctMap);
|
|
42
|
+
setIsPersonalizationLoading(false);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return function () {
|
|
46
|
+
cancelled = true;
|
|
47
|
+
};
|
|
48
|
+
}, [isEnabled, traitName]);
|
|
49
|
+
return (0, _react.useMemo)(function () {
|
|
50
|
+
if (!isEnabled) {
|
|
51
|
+
return NOT_ENABLED_RESULT;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
connectedPct: extensionKey && providerPctMap ? providerPctMap[extensionKey] : undefined,
|
|
55
|
+
isEnabled: isEnabled,
|
|
56
|
+
isLoading: isPersonalizationLoading
|
|
57
|
+
};
|
|
58
|
+
}, [extensionKey, isEnabled, isPersonalizationLoading, providerPctMap]);
|
|
59
|
+
};
|
|
60
|
+
var _default = exports.default = useSocialProof;
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.currentSiteCloudIdService = exports.CurrentSiteCloudIdService = exports.CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY = exports.CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY = void 0;
|
|
8
|
+
exports.getCachedCurrentSiteCloudIdAndRefresh = getCachedCurrentSiteCloudIdAndRefresh;
|
|
9
|
+
exports.getCurrentSiteCloudId = void 0;
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
var _storageClient = require("@atlaskit/frontend-utilities/storage-client");
|
|
16
|
+
var _linkingCommon = require("@atlaskit/linking-common");
|
|
17
|
+
/**
|
|
18
|
+
* Logical key shape matches smart-card storage conventions (see personalization-service). {@link StorageClient}
|
|
19
|
+
* stores rows as `<clientKey>_<itemKey>` with `clientKey === '@atlaskit/smart-card'` and
|
|
20
|
+
* `itemKey === 'site-cloud-id:v1'` (no further scope segments; unlike `pct-map:v1:`, this is a single fixed row).
|
|
21
|
+
*/
|
|
22
|
+
var SMART_CARD_STORAGE_SCOPE = '@atlaskit/smart-card';
|
|
23
|
+
var CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY = exports.CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY = 'site-cloud-id:v1';
|
|
24
|
+
var smartCardStorage = new _storageClient.StorageClient(SMART_CARD_STORAGE_SCOPE);
|
|
25
|
+
|
|
26
|
+
/** Keys written by this service in localStorage when using {@link smartCardStorage}. */
|
|
27
|
+
var CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY = exports.CURRENT_SITE_CLOUD_ID_LOCAL_STORAGE_KEY = "".concat(SMART_CARD_STORAGE_SCOPE, "_").concat(CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY);
|
|
28
|
+
var CurrentSiteCloudIdService = exports.CurrentSiteCloudIdService = /*#__PURE__*/function () {
|
|
29
|
+
function CurrentSiteCloudIdService() {
|
|
30
|
+
(0, _classCallCheck2.default)(this, CurrentSiteCloudIdService);
|
|
31
|
+
/**
|
|
32
|
+
* Holds the shared tenant_info work: one in-flight fetch, then (on success) a settled promise for the session cloud
|
|
33
|
+
* id so later callers never trigger another `tenant_info` in the same page lifetime (until {@link clearCache}).
|
|
34
|
+
*/
|
|
35
|
+
(0, _defineProperty2.default)(this, "tenantInfoInflightPromise", null);
|
|
36
|
+
}
|
|
37
|
+
return (0, _createClass2.default)(CurrentSiteCloudIdService, [{
|
|
38
|
+
key: "readStoredCloudId",
|
|
39
|
+
value: function readStoredCloudId() {
|
|
40
|
+
try {
|
|
41
|
+
var cloudId = smartCardStorage.getItem(CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY);
|
|
42
|
+
if (typeof cloudId !== 'string' || !cloudId || cloudId === 'undefined') {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return cloudId;
|
|
46
|
+
} catch (_unused) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "writeStoredCloudId",
|
|
52
|
+
value: function writeStoredCloudId(cloudId) {
|
|
53
|
+
if (!cloudId) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
smartCardStorage.setItemWithExpiry(CURRENT_SITE_CLOUD_ID_STORAGE_ITEM_KEY, cloudId);
|
|
58
|
+
} catch (_unused2) {
|
|
59
|
+
// Quota, private-mode, SSR, etc. — same intent as personalization-service.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "ensureTenantInfoInflightStarted",
|
|
64
|
+
value: function ensureTenantInfoInflightStarted(baseUriWithNoTrailingSlash) {
|
|
65
|
+
var _this = this;
|
|
66
|
+
if (this.tenantInfoInflightPromise !== null) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.tenantInfoInflightPromise = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
70
|
+
var response, cloudId;
|
|
71
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
72
|
+
while (1) switch (_context.prev = _context.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
_context.prev = 0;
|
|
75
|
+
_context.next = 3;
|
|
76
|
+
return (0, _linkingCommon.request)('get', baseUriWithNoTrailingSlash + '/_edge/tenant_info');
|
|
77
|
+
case 3:
|
|
78
|
+
response = _context.sent;
|
|
79
|
+
cloudId = response === null || response === void 0 ? void 0 : response.cloudId;
|
|
80
|
+
if (cloudId) {
|
|
81
|
+
_this.writeStoredCloudId(cloudId);
|
|
82
|
+
}
|
|
83
|
+
return _context.abrupt("return", cloudId ? cloudId : _this.readStoredCloudId());
|
|
84
|
+
case 9:
|
|
85
|
+
_context.prev = 9;
|
|
86
|
+
_context.t0 = _context["catch"](0);
|
|
87
|
+
_this.tenantInfoInflightPromise = null;
|
|
88
|
+
return _context.abrupt("return", _this.readStoredCloudId());
|
|
89
|
+
case 13:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}, _callee, null, [[0, 9]]);
|
|
94
|
+
}))();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Returns the currently cached cloud id synchronously and starts a background refresh.
|
|
99
|
+
* The refresh result is persisted for future calls but is not awaited by this call.
|
|
100
|
+
*/
|
|
101
|
+
}, {
|
|
102
|
+
key: "getCachedCloudIdAndRefresh",
|
|
103
|
+
value: function getCachedCloudIdAndRefresh() {
|
|
104
|
+
this.ensureTenantInfoInflightStarted('');
|
|
105
|
+
return this.readStoredCloudId();
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Writes tenant cloud id for tests or callers that intentionally warm storage before edge resolves. */
|
|
109
|
+
}, {
|
|
110
|
+
key: "persistStoredCloudId",
|
|
111
|
+
value: function persistStoredCloudId(cloudId) {
|
|
112
|
+
this.writeStoredCloudId(cloudId);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* When local storage already has a tenant cloud id, it is returned immediately; a background tenant_info refresh
|
|
117
|
+
* is still kicked off unless one is already in flight.
|
|
118
|
+
*
|
|
119
|
+
* Without storage, this awaits the deduped in-flight tenant_info (first concurrent caller chooses the URL;
|
|
120
|
+
* all share one promise regardless of subsequent `baseUriWithNoTrailingSlash`).
|
|
121
|
+
*
|
|
122
|
+
* On network success with no cloud id, or on failure: falls back via {@link readStoredCloudId}.
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "get",
|
|
126
|
+
value: (function () {
|
|
127
|
+
var _get = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
128
|
+
var baseUriWithNoTrailingSlash,
|
|
129
|
+
fromStorage,
|
|
130
|
+
_args2 = arguments;
|
|
131
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
132
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
133
|
+
case 0:
|
|
134
|
+
baseUriWithNoTrailingSlash = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
|
|
135
|
+
fromStorage = this.readStoredCloudId();
|
|
136
|
+
this.ensureTenantInfoInflightStarted(baseUriWithNoTrailingSlash);
|
|
137
|
+
if (!fromStorage) {
|
|
138
|
+
_context2.next = 5;
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
return _context2.abrupt("return", fromStorage);
|
|
142
|
+
case 5:
|
|
143
|
+
return _context2.abrupt("return", this.tenantInfoInflightPromise);
|
|
144
|
+
case 6:
|
|
145
|
+
case "end":
|
|
146
|
+
return _context2.stop();
|
|
147
|
+
}
|
|
148
|
+
}, _callee2, this);
|
|
149
|
+
}));
|
|
150
|
+
function get() {
|
|
151
|
+
return _get.apply(this, arguments);
|
|
152
|
+
}
|
|
153
|
+
return get;
|
|
154
|
+
}() /** Clears the session pin so the next {@link get} may run `tenant_info` again (e.g. tests). */)
|
|
155
|
+
}, {
|
|
156
|
+
key: "clearCache",
|
|
157
|
+
value: function clearCache() {
|
|
158
|
+
this.tenantInfoInflightPromise = null;
|
|
159
|
+
}
|
|
160
|
+
}]);
|
|
161
|
+
}();
|
|
162
|
+
var currentSiteCloudIdService = exports.currentSiteCloudIdService = new CurrentSiteCloudIdService();
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Resolves the current site cloud id through the module-level {@link currentSiteCloudIdService}.
|
|
166
|
+
* Returns a stored cloud id immediately when one exists; otherwise waits for the shared
|
|
167
|
+
* `tenant_info` request and persists the result for subsequent cached reads.
|
|
168
|
+
*/
|
|
169
|
+
var getCurrentSiteCloudId = exports.getCurrentSiteCloudId = function getCurrentSiteCloudId() {
|
|
170
|
+
var baseUriWithNoTrailingSlash = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
171
|
+
return currentSiteCloudIdService.get(baseUriWithNoTrailingSlash);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Reads the current site cloud id from browser storage (the `site-cloud-id:v1` row) via the
|
|
176
|
+
* module-level {@link currentSiteCloudIdService} singleton, without awaiting network work.
|
|
177
|
+
* Calling this also starts the shared `tenant_info` refresh in the background when one is not
|
|
178
|
+
* already running, so a later call can observe a refreshed value when available.
|
|
179
|
+
*/
|
|
180
|
+
function getCachedCurrentSiteCloudIdAndRefresh() {
|
|
181
|
+
return currentSiteCloudIdService.getCachedCloudIdAndRefresh();
|
|
182
|
+
}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PersonalizationService = exports.PERSONALIZATION_STORAGE_SCOPE = exports.PERSONALIZATION_STORAGE_ITEM_KEY_PREFIX = void 0;
|
|
8
|
+
exports.getCachedProviderPctMapAndRefresh = getCachedProviderPctMapAndRefresh;
|
|
9
|
+
exports.personalizationService = exports.getProviderPctMap = void 0;
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
12
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
13
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
16
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
17
|
+
var _storageClient = require("@atlaskit/frontend-utilities/storage-client");
|
|
18
|
+
var _currentSiteCloudId = require("../current-site-cloud-id");
|
|
19
|
+
var BASE_URL = '/gateway/api/tap-delivery/api/v3/personalization';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Logical key shape: `@atlaskit/smart-card:<feature>:<schema-version>:<scope>` (see smart-card
|
|
23
|
+
* storage conventions). {@link StorageClient} narrows the localStorage key to
|
|
24
|
+
* `<clientKey>_<itemKey>` with `clientKey === '@atlaskit/smart-card'` and
|
|
25
|
+
* `itemKey === 'pct-map:v1:<cloudId>:<traitName>'` (scope segments URI-encoded).
|
|
26
|
+
*/
|
|
27
|
+
var PERSONALIZATION_STORAGE_SCOPE = exports.PERSONALIZATION_STORAGE_SCOPE = '@atlaskit/smart-card';
|
|
28
|
+
var PERSONALIZATION_STORAGE_ITEM_KEY_PREFIX = exports.PERSONALIZATION_STORAGE_ITEM_KEY_PREFIX = 'pct-map:v1:';
|
|
29
|
+
var smartCardStorage = new _storageClient.StorageClient(PERSONALIZATION_STORAGE_SCOPE);
|
|
30
|
+
|
|
31
|
+
/** Keys written by this service in localStorage when using {@link smartCardStorage}. */
|
|
32
|
+
var LOCAL_STORAGE_ROW_KEY_PREFIX = "".concat(PERSONALIZATION_STORAGE_SCOPE, "_").concat(PERSONALIZATION_STORAGE_ITEM_KEY_PREFIX);
|
|
33
|
+
function pctMapStorageItemKey(cloudId, traitName) {
|
|
34
|
+
return "".concat(PERSONALIZATION_STORAGE_ITEM_KEY_PREFIX).concat(encodeURIComponent(cloudId), ":").concat(encodeURIComponent(traitName));
|
|
35
|
+
}
|
|
36
|
+
function fetchSiteTraits(_x) {
|
|
37
|
+
return _fetchSiteTraits.apply(this, arguments);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Service for fetching site-level traits from the TAP Delivery personalization API.
|
|
41
|
+
*/
|
|
42
|
+
function _fetchSiteTraits() {
|
|
43
|
+
_fetchSiteTraits = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(cloudId) {
|
|
44
|
+
var _data$attributes;
|
|
45
|
+
var response, data;
|
|
46
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
47
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
48
|
+
case 0:
|
|
49
|
+
_context3.next = 2;
|
|
50
|
+
return fetch("".concat(BASE_URL, "/site/").concat(cloudId), {
|
|
51
|
+
method: 'GET',
|
|
52
|
+
credentials: 'include',
|
|
53
|
+
headers: {
|
|
54
|
+
'Content-Type': 'application/json'
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
case 2:
|
|
58
|
+
response = _context3.sent;
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
_context3.next = 5;
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
return _context3.abrupt("return", []);
|
|
64
|
+
case 5:
|
|
65
|
+
_context3.next = 7;
|
|
66
|
+
return response.json();
|
|
67
|
+
case 7:
|
|
68
|
+
data = _context3.sent;
|
|
69
|
+
return _context3.abrupt("return", (_data$attributes = data === null || data === void 0 ? void 0 : data.attributes) !== null && _data$attributes !== void 0 ? _data$attributes : []);
|
|
70
|
+
case 9:
|
|
71
|
+
case "end":
|
|
72
|
+
return _context3.stop();
|
|
73
|
+
}
|
|
74
|
+
}, _callee3);
|
|
75
|
+
}));
|
|
76
|
+
return _fetchSiteTraits.apply(this, arguments);
|
|
77
|
+
}
|
|
78
|
+
var PersonalizationService = exports.PersonalizationService = /*#__PURE__*/function () {
|
|
79
|
+
function PersonalizationService() {
|
|
80
|
+
(0, _classCallCheck2.default)(this, PersonalizationService);
|
|
81
|
+
(0, _defineProperty2.default)(this, "cache", new Map());
|
|
82
|
+
}
|
|
83
|
+
return (0, _createClass2.default)(PersonalizationService, [{
|
|
84
|
+
key: "getCachedProviderPctMapAndRefresh",
|
|
85
|
+
value:
|
|
86
|
+
/**
|
|
87
|
+
* Returns the currently cached provider percentage map synchronously and starts a background refresh.
|
|
88
|
+
* The refresh result is persisted for future calls but is not awaited by this call.
|
|
89
|
+
*/
|
|
90
|
+
function getCachedProviderPctMapAndRefresh(traitName) {
|
|
91
|
+
var cloudId = (0, _currentSiteCloudId.getCachedCurrentSiteCloudIdAndRefresh)();
|
|
92
|
+
var fromStorage = cloudId && this.readStoredProviderPctMap(cloudId, traitName) || null;
|
|
93
|
+
void this.getProviderPctMap(traitName);
|
|
94
|
+
return fromStorage;
|
|
95
|
+
}
|
|
96
|
+
}, {
|
|
97
|
+
key: "getProviderPctMap",
|
|
98
|
+
value: function () {
|
|
99
|
+
var _getProviderPctMap = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(traitName) {
|
|
100
|
+
var _this = this;
|
|
101
|
+
var cachedPromise, promise;
|
|
102
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
103
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
104
|
+
case 0:
|
|
105
|
+
cachedPromise = this.cache.get(traitName);
|
|
106
|
+
if (!cachedPromise) {
|
|
107
|
+
_context2.next = 3;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return _context2.abrupt("return", cachedPromise);
|
|
111
|
+
case 3:
|
|
112
|
+
promise = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
113
|
+
var cloudId, traits, trait, mapped;
|
|
114
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
115
|
+
while (1) switch (_context.prev = _context.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
_context.prev = 0;
|
|
118
|
+
_context.next = 3;
|
|
119
|
+
return (0, _currentSiteCloudId.getCurrentSiteCloudId)();
|
|
120
|
+
case 3:
|
|
121
|
+
cloudId = _context.sent;
|
|
122
|
+
if (cloudId) {
|
|
123
|
+
_context.next = 6;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
return _context.abrupt("return", undefined);
|
|
127
|
+
case 6:
|
|
128
|
+
_context.next = 8;
|
|
129
|
+
return fetchSiteTraits(cloudId);
|
|
130
|
+
case 8:
|
|
131
|
+
traits = _context.sent;
|
|
132
|
+
trait = traits.find(function (t) {
|
|
133
|
+
return t.name === traitName;
|
|
134
|
+
});
|
|
135
|
+
mapped = _this.parseTraitValue(trait === null || trait === void 0 ? void 0 : trait.value);
|
|
136
|
+
if (mapped !== undefined) {
|
|
137
|
+
_this.writeStoredProviderPctMap(cloudId, traitName, mapped);
|
|
138
|
+
}
|
|
139
|
+
return _context.abrupt("return", mapped);
|
|
140
|
+
case 15:
|
|
141
|
+
_context.prev = 15;
|
|
142
|
+
_context.t0 = _context["catch"](0);
|
|
143
|
+
return _context.abrupt("return", undefined);
|
|
144
|
+
case 18:
|
|
145
|
+
case "end":
|
|
146
|
+
return _context.stop();
|
|
147
|
+
}
|
|
148
|
+
}, _callee, null, [[0, 15]]);
|
|
149
|
+
}))();
|
|
150
|
+
this.cache.set(traitName, promise);
|
|
151
|
+
return _context2.abrupt("return", promise);
|
|
152
|
+
case 6:
|
|
153
|
+
case "end":
|
|
154
|
+
return _context2.stop();
|
|
155
|
+
}
|
|
156
|
+
}, _callee2, this);
|
|
157
|
+
}));
|
|
158
|
+
function getProviderPctMap(_x2) {
|
|
159
|
+
return _getProviderPctMap.apply(this, arguments);
|
|
160
|
+
}
|
|
161
|
+
return getProviderPctMap;
|
|
162
|
+
}()
|
|
163
|
+
}, {
|
|
164
|
+
key: "readStoredProviderPctMap",
|
|
165
|
+
value: function readStoredProviderPctMap(cloudId, traitName) {
|
|
166
|
+
try {
|
|
167
|
+
var stored = smartCardStorage.getItem(pctMapStorageItemKey(cloudId, traitName));
|
|
168
|
+
if (stored === undefined || stored === null) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
return this.normalizeProviderPctMap(stored);
|
|
172
|
+
} catch (_unused2) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, {
|
|
177
|
+
key: "writeStoredProviderPctMap",
|
|
178
|
+
value: function writeStoredProviderPctMap(cloudId, traitName, map) {
|
|
179
|
+
try {
|
|
180
|
+
smartCardStorage.setItemWithExpiry(pctMapStorageItemKey(cloudId, traitName), map);
|
|
181
|
+
} catch (_unused3) {
|
|
182
|
+
// Quota, private-mode, etc.
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}, {
|
|
186
|
+
key: "normalizeProviderPctMap",
|
|
187
|
+
value: function normalizeProviderPctMap(value) {
|
|
188
|
+
if ((0, _typeof2.default)(value) !== 'object' || value === null || Array.isArray(value)) {
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
var map = {};
|
|
192
|
+
var entries = Object.entries(value);
|
|
193
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
|
194
|
+
var _entries$_i = (0, _slicedToArray2.default)(_entries[_i], 2),
|
|
195
|
+
providerKey = _entries$_i[0],
|
|
196
|
+
percentageRaw = _entries$_i[1];
|
|
197
|
+
if (typeof percentageRaw !== 'number' || !Number.isFinite(percentageRaw)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
map[providerKey] = percentageRaw;
|
|
201
|
+
}
|
|
202
|
+
return map;
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "parseTraitValue",
|
|
206
|
+
value: function parseTraitValue(raw) {
|
|
207
|
+
if (typeof raw !== 'string') {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
try {
|
|
211
|
+
var parsed = JSON.parse(raw);
|
|
212
|
+
var normalized = this.normalizeProviderPctMap(parsed);
|
|
213
|
+
return normalized === null ? undefined : normalized;
|
|
214
|
+
} catch (_unused4) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
key: "clearCache",
|
|
220
|
+
value: function clearCache() {
|
|
221
|
+
this.cache.clear();
|
|
222
|
+
this.clearStoredProviderPctMaps();
|
|
223
|
+
}
|
|
224
|
+
}, {
|
|
225
|
+
key: "clearStoredProviderPctMaps",
|
|
226
|
+
value: function clearStoredProviderPctMaps() {
|
|
227
|
+
if (typeof globalThis.localStorage === 'undefined' || globalThis.localStorage === null) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
var keysToRemove = [];
|
|
231
|
+
for (var index = 0; index < globalThis.localStorage.length; index += 1) {
|
|
232
|
+
var key = globalThis.localStorage.key(index);
|
|
233
|
+
if (key !== null && key.startsWith(LOCAL_STORAGE_ROW_KEY_PREFIX)) {
|
|
234
|
+
keysToRemove.push(key);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
for (var _i2 = 0, _keysToRemove = keysToRemove; _i2 < _keysToRemove.length; _i2++) {
|
|
238
|
+
var _key = _keysToRemove[_i2];
|
|
239
|
+
try {
|
|
240
|
+
globalThis.localStorage.removeItem(_key);
|
|
241
|
+
} catch (_unused5) {
|
|
242
|
+
/* ignore */
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}]);
|
|
247
|
+
}();
|
|
248
|
+
var personalizationService = exports.personalizationService = new PersonalizationService();
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Resolves the provider percentage map for a TAP Delivery trait through the module-level
|
|
252
|
+
* {@link personalizationService}. Work is deduped per trait name for the page lifetime, and a
|
|
253
|
+
* successful response is persisted by cloud id and trait name for later cached reads.
|
|
254
|
+
*/
|
|
255
|
+
var getProviderPctMap = exports.getProviderPctMap = function getProviderPctMap(traitName) {
|
|
256
|
+
return personalizationService.getProviderPctMap(traitName);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Reads the provider percentage map for a trait from browser storage via the module-level
|
|
261
|
+
* {@link personalizationService} singleton, without awaiting network work.
|
|
262
|
+
* Calling this also starts the trait-scoped shared refresh in the background, so a later call can
|
|
263
|
+
* use a refreshed value when it becomes available.
|
|
264
|
+
*/
|
|
265
|
+
function getCachedProviderPctMapAndRefresh(traitName) {
|
|
266
|
+
return personalizationService.getCachedProviderPctMapAndRefresh(traitName);
|
|
267
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -11,7 +11,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
|
|
|
11
11
|
var context = exports.context = {
|
|
12
12
|
componentName: 'smart-cards',
|
|
13
13
|
packageName: "@atlaskit/smart-card" || '',
|
|
14
|
-
packageVersion: "44.
|
|
14
|
+
packageVersion: "44.5.1" || ''
|
|
15
15
|
};
|
|
16
16
|
var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
|
|
17
17
|
TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
|
|
@@ -22,7 +22,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLink
|
|
|
22
22
|
_excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
|
|
23
23
|
var PACKAGE_DATA = {
|
|
24
24
|
packageName: "@atlaskit/smart-card",
|
|
25
|
-
packageVersion: "44.
|
|
25
|
+
packageVersion: "44.5.1",
|
|
26
26
|
componentName: 'linkUrl'
|
|
27
27
|
};
|
|
28
28
|
var Anchor = (0, _click.withLinkClickedEvent)('a');
|