@atlaskit/smart-card 45.26.0 → 45.27.1

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 CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 45.27.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`27b51e491d701`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/27b51e491d701) -
8
+ Add internal eligibility and suppression utilities for One Click Chat Spotlight V2; production
9
+ integration under platform_sl_one_click_chat_spotlight_v2_fg follows separately.
10
+
11
+ ## 45.27.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [`69cbbe9ee0f63`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/69cbbe9ee0f63) -
16
+ Update i18n NPM package versions for linking-platform,smart-experiences (Group 15)
17
+
3
18
  ## 45.26.0
4
19
 
5
20
  ### Minor Changes
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SEVEN_DAYS_MS = void 0;
7
+ exports.evaluateExperiment = evaluateExperiment;
8
+ exports.evaluateOpportunity = evaluateOpportunity;
9
+ /** No link, content, or account identifiers belong in eligibility diagnostics. */
10
+
11
+ var SEVEN_DAYS_MS = exports.SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000;
12
+ var result = function result(reason) {
13
+ return {
14
+ isEligible: reason === 'eligible',
15
+ reason: reason
16
+ };
17
+ };
18
+
19
+ /** Calendar days use the browser's local timezone; seven-day windows use elapsed time. */
20
+ function evaluateOpportunity(input) {
21
+ if (!input.gateEnabled) {
22
+ return result('gate_off');
23
+ }
24
+ if (input.appearance !== 'inline' || input.status !== 'resolved') {
25
+ return result('not_resolved_inline');
26
+ }
27
+ if (input.provider !== 'google-object-provider' && input.provider !== 'github-object-provider') {
28
+ return result('unsupported_provider');
29
+ }
30
+ if (!input.authorized) {
31
+ return result('provider_unauthorized');
32
+ }
33
+ if (!input.hasAccess) {
34
+ return result('object_inaccessible');
35
+ }
36
+ if (!input.rovoAvailable) {
37
+ return result('rovo_unavailable');
38
+ }
39
+ if (!input.consumerOptedIn) {
40
+ return result('consumer_not_opted_in');
41
+ }
42
+ if (input.product !== 'jira_web' && input.product !== 'confluence_web') {
43
+ return result('unsupported_product');
44
+ }
45
+ if (!input.history) {
46
+ return result('suppression_unavailable');
47
+ }
48
+ if (input.spotlightActive) {
49
+ return result('spotlight_active');
50
+ }
51
+ var _input$history = input.history,
52
+ dismissedAt = _input$history.dismissedAt,
53
+ impressions = _input$history.impressions;
54
+ var cutoff = input.now - SEVEN_DAYS_MS;
55
+ if (dismissedAt !== undefined && dismissedAt > cutoff) {
56
+ return result('dismissal_cooldown');
57
+ }
58
+ var startOfDay = new Date(input.now);
59
+ startOfDay.setHours(0, 0, 0, 0);
60
+ if (impressions.some(function (timestamp) {
61
+ return timestamp >= startOfDay.getTime();
62
+ })) {
63
+ return result('shown_today');
64
+ }
65
+ if (impressions.filter(function (timestamp) {
66
+ return timestamp > cutoff;
67
+ }).length >= 3) {
68
+ return result('weekly_limit');
69
+ }
70
+ return result('eligible');
71
+ }
72
+
73
+ /** Pure cohort evaluation, kept separate so suppressed opportunities never expose the experiment. */
74
+ function evaluateExperiment(value) {
75
+ return result(value === true ? 'eligible' : value === false ? 'control' : 'experiment_unavailable');
76
+ }
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.claimSpotlight = claimSpotlight;
8
+ exports.createSuppressionStore = createSuppressionStore;
9
+ exports.getSuppressionStore = getSuppressionStore;
10
+ exports.isSpotlightActive = isSpotlightActive;
11
+ exports.releaseSpotlight = releaseSpotlight;
12
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
13
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
14
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
15
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
17
+ var _StorageClient = require("@atlaskit/frontend-utilities/StorageClient");
18
+ var _evaluate = require("./evaluate");
19
+ 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; }
20
+ 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; }
21
+ /** Shared across inline cards. Account identifiers are held in memory only. */
22
+ var stores = new Map();
23
+ var activeSpotlight;
24
+ var isHistory = function isHistory(value) {
25
+ if ((0, _typeof2.default)(value) !== 'object' || value === null || !('impressions' in value)) {
26
+ return false;
27
+ }
28
+ return Array.isArray(value.impressions) && value.impressions.every(function (timestamp) {
29
+ return typeof timestamp === 'number' && Number.isFinite(timestamp);
30
+ }) && (!('dismissedAt' in value) || value.dismissedAt === undefined || typeof value.dismissedAt === 'number' && Number.isFinite(value.dismissedAt));
31
+ };
32
+
33
+ /** Reuses Smart Card's StorageClient, with timestamp-only values and a one-way user namespace. */
34
+ function createSuppressionStore(storage) {
35
+ var isAvailable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
36
+ return true;
37
+ };
38
+ var blocked = false;
39
+ var read = function read() {
40
+ try {
41
+ var value = storage.getItem('history');
42
+ if (blocked || !isAvailable()) {
43
+ return undefined;
44
+ }
45
+ return value === undefined ? {
46
+ impressions: []
47
+ } : isHistory(value) ? value : undefined;
48
+ } catch (_unused) {
49
+ return undefined;
50
+ }
51
+ };
52
+ var write = function write(history) {
53
+ try {
54
+ storage.setItemWithExpiry('history', history, _evaluate.SEVEN_DAYS_MS);
55
+ // StorageClient can swallow write failures. Verify persistence before counting delivery.
56
+ var persisted = isAvailable() && JSON.stringify(storage.getItem('history')) === JSON.stringify(history);
57
+ blocked = !persisted;
58
+ return persisted;
59
+ } catch (_unused2) {
60
+ blocked = true;
61
+ return false;
62
+ }
63
+ };
64
+ return {
65
+ read: read,
66
+ impress: function impress(now) {
67
+ var history = read();
68
+ return !!history && write(_objectSpread(_objectSpread({}, history), {}, {
69
+ impressions: [].concat((0, _toConsumableArray2.default)(history.impressions.filter(function (timestamp) {
70
+ return timestamp > now - _evaluate.SEVEN_DAYS_MS;
71
+ })), [now])
72
+ }));
73
+ },
74
+ dismiss: function dismiss(now) {
75
+ var history = read();
76
+ return !!history && write(_objectSpread(_objectSpread({}, history), {}, {
77
+ dismissedAt: now
78
+ }));
79
+ }
80
+ };
81
+ }
82
+ function getSuppressionStore(accountId) {
83
+ var cached = stores.get(accountId);
84
+ if (cached) {
85
+ return cached;
86
+ }
87
+ var pending = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
88
+ var _window$crypto, digest, namespace, available, storage, _t;
89
+ return _regenerator.default.wrap(function (_context) {
90
+ while (1) switch (_context.prev = _context.next) {
91
+ case 0:
92
+ _context.prev = 0;
93
+ if (!(typeof window === 'undefined' || !((_window$crypto = window.crypto) !== null && _window$crypto !== void 0 && _window$crypto.subtle))) {
94
+ _context.next = 1;
95
+ break;
96
+ }
97
+ return _context.abrupt("return", undefined);
98
+ case 1:
99
+ _context.next = 2;
100
+ return window.crypto.subtle.digest('SHA-256', new TextEncoder().encode("one-click-chat-spotlight-v2:".concat(accountId)));
101
+ case 2:
102
+ digest = _context.sent;
103
+ namespace = Array.from(new Uint8Array(digest), function (byte) {
104
+ return byte.toString(16).padStart(2, '0');
105
+ }).join('');
106
+ available = true;
107
+ storage = new _StorageClient.StorageClient("one-click-chat-spotlight-v2:".concat(namespace), {
108
+ handlers: {
109
+ captureException: function captureException() {
110
+ available = false;
111
+ }
112
+ }
113
+ });
114
+ return _context.abrupt("return", createSuppressionStore(storage, function () {
115
+ return available;
116
+ }));
117
+ case 3:
118
+ _context.prev = 3;
119
+ _t = _context["catch"](0);
120
+ return _context.abrupt("return", undefined);
121
+ case 4:
122
+ case "end":
123
+ return _context.stop();
124
+ }
125
+ }, _callee, null, [[0, 3]]);
126
+ }))();
127
+ stores.set(accountId, pending);
128
+ return pending;
129
+ }
130
+ function claimSpotlight(owner) {
131
+ if (activeSpotlight && activeSpotlight !== owner) {
132
+ return false;
133
+ }
134
+ activeSpotlight = owner;
135
+ return true;
136
+ }
137
+ function releaseSpotlight(owner) {
138
+ if (activeSpotlight === owner) {
139
+ activeSpotlight = undefined;
140
+ }
141
+ }
142
+ function isSpotlightActive(owner) {
143
+ return activeSpotlight !== undefined && activeSpotlight !== owner;
144
+ }
@@ -25,7 +25,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
25
25
  var context = exports.context = {
26
26
  componentName: 'smart-cards',
27
27
  packageName: "@atlaskit/smart-card" || '',
28
- packageVersion: "45.25.1" || ''
28
+ packageVersion: "45.27.0" || ''
29
29
  };
30
30
  var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
31
31
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -19,7 +19,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLink
19
19
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
20
20
  var PACKAGE_DATA = {
21
21
  packageName: "@atlaskit/smart-card",
22
- packageVersion: "45.25.1",
22
+ packageVersion: "45.27.0",
23
23
  componentName: 'linkUrl'
24
24
  };
25
25
  var LinkUrl = function LinkUrl(_ref) {
@@ -0,0 +1,63 @@
1
+ /** No link, content, or account identifiers belong in eligibility diagnostics. */
2
+
3
+ export const SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000;
4
+ const result = reason => ({
5
+ isEligible: reason === 'eligible',
6
+ reason
7
+ });
8
+
9
+ /** Calendar days use the browser's local timezone; seven-day windows use elapsed time. */
10
+ export function evaluateOpportunity(input) {
11
+ if (!input.gateEnabled) {
12
+ return result('gate_off');
13
+ }
14
+ if (input.appearance !== 'inline' || input.status !== 'resolved') {
15
+ return result('not_resolved_inline');
16
+ }
17
+ if (input.provider !== 'google-object-provider' && input.provider !== 'github-object-provider') {
18
+ return result('unsupported_provider');
19
+ }
20
+ if (!input.authorized) {
21
+ return result('provider_unauthorized');
22
+ }
23
+ if (!input.hasAccess) {
24
+ return result('object_inaccessible');
25
+ }
26
+ if (!input.rovoAvailable) {
27
+ return result('rovo_unavailable');
28
+ }
29
+ if (!input.consumerOptedIn) {
30
+ return result('consumer_not_opted_in');
31
+ }
32
+ if (input.product !== 'jira_web' && input.product !== 'confluence_web') {
33
+ return result('unsupported_product');
34
+ }
35
+ if (!input.history) {
36
+ return result('suppression_unavailable');
37
+ }
38
+ if (input.spotlightActive) {
39
+ return result('spotlight_active');
40
+ }
41
+ const {
42
+ dismissedAt,
43
+ impressions
44
+ } = input.history;
45
+ const cutoff = input.now - SEVEN_DAYS_MS;
46
+ if (dismissedAt !== undefined && dismissedAt > cutoff) {
47
+ return result('dismissal_cooldown');
48
+ }
49
+ const startOfDay = new Date(input.now);
50
+ startOfDay.setHours(0, 0, 0, 0);
51
+ if (impressions.some(timestamp => timestamp >= startOfDay.getTime())) {
52
+ return result('shown_today');
53
+ }
54
+ if (impressions.filter(timestamp => timestamp > cutoff).length >= 3) {
55
+ return result('weekly_limit');
56
+ }
57
+ return result('eligible');
58
+ }
59
+
60
+ /** Pure cohort evaluation, kept separate so suppressed opportunities never expose the experiment. */
61
+ export function evaluateExperiment(value) {
62
+ return result(value === true ? 'eligible' : value === false ? 'control' : 'experiment_unavailable');
63
+ }
@@ -0,0 +1,103 @@
1
+ import { StorageClient } from '@atlaskit/frontend-utilities/StorageClient';
2
+ import { SEVEN_DAYS_MS } from './evaluate';
3
+
4
+ /** Shared across inline cards. Account identifiers are held in memory only. */
5
+ const stores = new Map();
6
+ let activeSpotlight;
7
+ const isHistory = value => {
8
+ if (typeof value !== 'object' || value === null || !('impressions' in value)) {
9
+ return false;
10
+ }
11
+ return Array.isArray(value.impressions) && value.impressions.every(timestamp => typeof timestamp === 'number' && Number.isFinite(timestamp)) && (!('dismissedAt' in value) || value.dismissedAt === undefined || typeof value.dismissedAt === 'number' && Number.isFinite(value.dismissedAt));
12
+ };
13
+
14
+ /** Reuses Smart Card's StorageClient, with timestamp-only values and a one-way user namespace. */
15
+ export function createSuppressionStore(storage, isAvailable = () => true) {
16
+ let blocked = false;
17
+ const read = () => {
18
+ try {
19
+ const value = storage.getItem('history');
20
+ if (blocked || !isAvailable()) {
21
+ return undefined;
22
+ }
23
+ return value === undefined ? {
24
+ impressions: []
25
+ } : isHistory(value) ? value : undefined;
26
+ } catch {
27
+ return undefined;
28
+ }
29
+ };
30
+ const write = history => {
31
+ try {
32
+ storage.setItemWithExpiry('history', history, SEVEN_DAYS_MS);
33
+ // StorageClient can swallow write failures. Verify persistence before counting delivery.
34
+ const persisted = isAvailable() && JSON.stringify(storage.getItem('history')) === JSON.stringify(history);
35
+ blocked = !persisted;
36
+ return persisted;
37
+ } catch {
38
+ blocked = true;
39
+ return false;
40
+ }
41
+ };
42
+ return {
43
+ read,
44
+ impress: now => {
45
+ const history = read();
46
+ return !!history && write({
47
+ ...history,
48
+ impressions: [...history.impressions.filter(timestamp => timestamp > now - SEVEN_DAYS_MS), now]
49
+ });
50
+ },
51
+ dismiss: now => {
52
+ const history = read();
53
+ return !!history && write({
54
+ ...history,
55
+ dismissedAt: now
56
+ });
57
+ }
58
+ };
59
+ }
60
+ export function getSuppressionStore(accountId) {
61
+ const cached = stores.get(accountId);
62
+ if (cached) {
63
+ return cached;
64
+ }
65
+ const pending = (async () => {
66
+ try {
67
+ var _window$crypto;
68
+ if (typeof window === 'undefined' || !((_window$crypto = window.crypto) !== null && _window$crypto !== void 0 && _window$crypto.subtle)) {
69
+ return undefined;
70
+ }
71
+ const digest = await window.crypto.subtle.digest('SHA-256', new TextEncoder().encode(`one-click-chat-spotlight-v2:${accountId}`));
72
+ const namespace = Array.from(new Uint8Array(digest), byte => byte.toString(16).padStart(2, '0')).join('');
73
+ let available = true;
74
+ const storage = new StorageClient(`one-click-chat-spotlight-v2:${namespace}`, {
75
+ handlers: {
76
+ captureException: () => {
77
+ available = false;
78
+ }
79
+ }
80
+ });
81
+ return createSuppressionStore(storage, () => available);
82
+ } catch {
83
+ return undefined;
84
+ }
85
+ })();
86
+ stores.set(accountId, pending);
87
+ return pending;
88
+ }
89
+ export function claimSpotlight(owner) {
90
+ if (activeSpotlight && activeSpotlight !== owner) {
91
+ return false;
92
+ }
93
+ activeSpotlight = owner;
94
+ return true;
95
+ }
96
+ export function releaseSpotlight(owner) {
97
+ if (activeSpotlight === owner) {
98
+ activeSpotlight = undefined;
99
+ }
100
+ }
101
+ export function isSpotlightActive(owner) {
102
+ return activeSpotlight !== undefined && activeSpotlight !== owner;
103
+ }
@@ -4,7 +4,7 @@ export const ANALYTICS_CHANNEL = 'media';
4
4
  export const context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "45.25.1" || ''
7
+ packageVersion: "45.27.0" || ''
8
8
  };
9
9
  export let TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -9,7 +9,7 @@ import LinkWarningModal from './LinkWarningModal';
9
9
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
10
10
  const PACKAGE_DATA = {
11
11
  packageName: "@atlaskit/smart-card",
12
- packageVersion: "45.25.1",
12
+ packageVersion: "45.27.0",
13
13
  componentName: 'linkUrl'
14
14
  };
15
15
  const LinkUrl = ({
@@ -0,0 +1,68 @@
1
+ /** No link, content, or account identifiers belong in eligibility diagnostics. */
2
+
3
+ export var SEVEN_DAYS_MS = 7 * 24 * 60 * 60 * 1000;
4
+ var result = function result(reason) {
5
+ return {
6
+ isEligible: reason === 'eligible',
7
+ reason: reason
8
+ };
9
+ };
10
+
11
+ /** Calendar days use the browser's local timezone; seven-day windows use elapsed time. */
12
+ export function evaluateOpportunity(input) {
13
+ if (!input.gateEnabled) {
14
+ return result('gate_off');
15
+ }
16
+ if (input.appearance !== 'inline' || input.status !== 'resolved') {
17
+ return result('not_resolved_inline');
18
+ }
19
+ if (input.provider !== 'google-object-provider' && input.provider !== 'github-object-provider') {
20
+ return result('unsupported_provider');
21
+ }
22
+ if (!input.authorized) {
23
+ return result('provider_unauthorized');
24
+ }
25
+ if (!input.hasAccess) {
26
+ return result('object_inaccessible');
27
+ }
28
+ if (!input.rovoAvailable) {
29
+ return result('rovo_unavailable');
30
+ }
31
+ if (!input.consumerOptedIn) {
32
+ return result('consumer_not_opted_in');
33
+ }
34
+ if (input.product !== 'jira_web' && input.product !== 'confluence_web') {
35
+ return result('unsupported_product');
36
+ }
37
+ if (!input.history) {
38
+ return result('suppression_unavailable');
39
+ }
40
+ if (input.spotlightActive) {
41
+ return result('spotlight_active');
42
+ }
43
+ var _input$history = input.history,
44
+ dismissedAt = _input$history.dismissedAt,
45
+ impressions = _input$history.impressions;
46
+ var cutoff = input.now - SEVEN_DAYS_MS;
47
+ if (dismissedAt !== undefined && dismissedAt > cutoff) {
48
+ return result('dismissal_cooldown');
49
+ }
50
+ var startOfDay = new Date(input.now);
51
+ startOfDay.setHours(0, 0, 0, 0);
52
+ if (impressions.some(function (timestamp) {
53
+ return timestamp >= startOfDay.getTime();
54
+ })) {
55
+ return result('shown_today');
56
+ }
57
+ if (impressions.filter(function (timestamp) {
58
+ return timestamp > cutoff;
59
+ }).length >= 3) {
60
+ return result('weekly_limit');
61
+ }
62
+ return result('eligible');
63
+ }
64
+
65
+ /** Pure cohort evaluation, kept separate so suppressed opportunities never expose the experiment. */
66
+ export function evaluateExperiment(value) {
67
+ return result(value === true ? 'eligible' : value === false ? 'control' : 'experiment_unavailable');
68
+ }
@@ -0,0 +1,134 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ import _typeof from "@babel/runtime/helpers/typeof";
5
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
6
+ 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; }
7
+ 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) { _defineProperty(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; }
8
+ import { StorageClient } from '@atlaskit/frontend-utilities/StorageClient';
9
+ import { SEVEN_DAYS_MS } from './evaluate';
10
+
11
+ /** Shared across inline cards. Account identifiers are held in memory only. */
12
+ var stores = new Map();
13
+ var activeSpotlight;
14
+ var isHistory = function isHistory(value) {
15
+ if (_typeof(value) !== 'object' || value === null || !('impressions' in value)) {
16
+ return false;
17
+ }
18
+ return Array.isArray(value.impressions) && value.impressions.every(function (timestamp) {
19
+ return typeof timestamp === 'number' && Number.isFinite(timestamp);
20
+ }) && (!('dismissedAt' in value) || value.dismissedAt === undefined || typeof value.dismissedAt === 'number' && Number.isFinite(value.dismissedAt));
21
+ };
22
+
23
+ /** Reuses Smart Card's StorageClient, with timestamp-only values and a one-way user namespace. */
24
+ export function createSuppressionStore(storage) {
25
+ var isAvailable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {
26
+ return true;
27
+ };
28
+ var blocked = false;
29
+ var read = function read() {
30
+ try {
31
+ var value = storage.getItem('history');
32
+ if (blocked || !isAvailable()) {
33
+ return undefined;
34
+ }
35
+ return value === undefined ? {
36
+ impressions: []
37
+ } : isHistory(value) ? value : undefined;
38
+ } catch (_unused) {
39
+ return undefined;
40
+ }
41
+ };
42
+ var write = function write(history) {
43
+ try {
44
+ storage.setItemWithExpiry('history', history, SEVEN_DAYS_MS);
45
+ // StorageClient can swallow write failures. Verify persistence before counting delivery.
46
+ var persisted = isAvailable() && JSON.stringify(storage.getItem('history')) === JSON.stringify(history);
47
+ blocked = !persisted;
48
+ return persisted;
49
+ } catch (_unused2) {
50
+ blocked = true;
51
+ return false;
52
+ }
53
+ };
54
+ return {
55
+ read: read,
56
+ impress: function impress(now) {
57
+ var history = read();
58
+ return !!history && write(_objectSpread(_objectSpread({}, history), {}, {
59
+ impressions: [].concat(_toConsumableArray(history.impressions.filter(function (timestamp) {
60
+ return timestamp > now - SEVEN_DAYS_MS;
61
+ })), [now])
62
+ }));
63
+ },
64
+ dismiss: function dismiss(now) {
65
+ var history = read();
66
+ return !!history && write(_objectSpread(_objectSpread({}, history), {}, {
67
+ dismissedAt: now
68
+ }));
69
+ }
70
+ };
71
+ }
72
+ export function getSuppressionStore(accountId) {
73
+ var cached = stores.get(accountId);
74
+ if (cached) {
75
+ return cached;
76
+ }
77
+ var pending = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
78
+ var _window$crypto, digest, namespace, available, storage, _t;
79
+ return _regeneratorRuntime.wrap(function (_context) {
80
+ while (1) switch (_context.prev = _context.next) {
81
+ case 0:
82
+ _context.prev = 0;
83
+ if (!(typeof window === 'undefined' || !((_window$crypto = window.crypto) !== null && _window$crypto !== void 0 && _window$crypto.subtle))) {
84
+ _context.next = 1;
85
+ break;
86
+ }
87
+ return _context.abrupt("return", undefined);
88
+ case 1:
89
+ _context.next = 2;
90
+ return window.crypto.subtle.digest('SHA-256', new TextEncoder().encode("one-click-chat-spotlight-v2:".concat(accountId)));
91
+ case 2:
92
+ digest = _context.sent;
93
+ namespace = Array.from(new Uint8Array(digest), function (byte) {
94
+ return byte.toString(16).padStart(2, '0');
95
+ }).join('');
96
+ available = true;
97
+ storage = new StorageClient("one-click-chat-spotlight-v2:".concat(namespace), {
98
+ handlers: {
99
+ captureException: function captureException() {
100
+ available = false;
101
+ }
102
+ }
103
+ });
104
+ return _context.abrupt("return", createSuppressionStore(storage, function () {
105
+ return available;
106
+ }));
107
+ case 3:
108
+ _context.prev = 3;
109
+ _t = _context["catch"](0);
110
+ return _context.abrupt("return", undefined);
111
+ case 4:
112
+ case "end":
113
+ return _context.stop();
114
+ }
115
+ }, _callee, null, [[0, 3]]);
116
+ }))();
117
+ stores.set(accountId, pending);
118
+ return pending;
119
+ }
120
+ export function claimSpotlight(owner) {
121
+ if (activeSpotlight && activeSpotlight !== owner) {
122
+ return false;
123
+ }
124
+ activeSpotlight = owner;
125
+ return true;
126
+ }
127
+ export function releaseSpotlight(owner) {
128
+ if (activeSpotlight === owner) {
129
+ activeSpotlight = undefined;
130
+ }
131
+ }
132
+ export function isSpotlightActive(owner) {
133
+ return activeSpotlight !== undefined && activeSpotlight !== owner;
134
+ }
@@ -4,7 +4,7 @@ export var ANALYTICS_CHANNEL = 'media';
4
4
  export var context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "45.25.1" || ''
7
+ packageVersion: "45.27.0" || ''
8
8
  };
9
9
  export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -12,7 +12,7 @@ import LinkWarningModal from './LinkWarningModal';
12
12
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
13
13
  var PACKAGE_DATA = {
14
14
  packageName: "@atlaskit/smart-card",
15
- packageVersion: "45.25.1",
15
+ packageVersion: "45.27.0",
16
16
  componentName: 'linkUrl'
17
17
  };
18
18
  var LinkUrl = function LinkUrl(_ref) {
@@ -0,0 +1,29 @@
1
+ /** No link, content, or account identifiers belong in eligibility diagnostics. */
2
+ export type EligibilityReason = 'gate_off' | 'not_resolved_inline' | 'unsupported_provider' | 'provider_unauthorized' | 'object_inaccessible' | 'rovo_unavailable' | 'consumer_not_opted_in' | 'unsupported_product' | 'suppression_unavailable' | 'spotlight_active' | 'dismissal_cooldown' | 'shown_today' | 'weekly_limit' | 'experiment_unavailable' | 'control' | 'eligible';
3
+ export interface SpotlightHistory {
4
+ dismissedAt?: number;
5
+ impressions: readonly number[];
6
+ }
7
+ export interface EligibilityInput {
8
+ appearance: string;
9
+ authorized: boolean;
10
+ consumerOptedIn: boolean;
11
+ gateEnabled: boolean;
12
+ hasAccess: boolean;
13
+ history?: SpotlightHistory;
14
+ now: number;
15
+ product?: string;
16
+ provider?: string;
17
+ rovoAvailable: boolean;
18
+ spotlightActive: boolean;
19
+ status: string;
20
+ }
21
+ export interface EligibilityResult {
22
+ isEligible: boolean;
23
+ reason: EligibilityReason;
24
+ }
25
+ export declare const SEVEN_DAYS_MS: number;
26
+ /** Calendar days use the browser's local timezone; seven-day windows use elapsed time. */
27
+ export declare function evaluateOpportunity(input: EligibilityInput): EligibilityResult;
28
+ /** Pure cohort evaluation, kept separate so suppressed opportunities never expose the experiment. */
29
+ export declare function evaluateExperiment(value: unknown): EligibilityResult;
@@ -0,0 +1,13 @@
1
+ import { StorageClient } from '@atlaskit/frontend-utilities/StorageClient';
2
+ import { type SpotlightHistory } from './evaluate';
3
+ export interface SpotlightSuppression {
4
+ dismiss: (now: number) => boolean;
5
+ impress: (now: number) => boolean;
6
+ read: () => SpotlightHistory | undefined;
7
+ }
8
+ /** Reuses Smart Card's StorageClient, with timestamp-only values and a one-way user namespace. */
9
+ export declare function createSuppressionStore(storage: StorageClient, isAvailable?: () => boolean): SpotlightSuppression;
10
+ export declare function getSuppressionStore(accountId: string): Promise<SpotlightSuppression | undefined>;
11
+ export declare function claimSpotlight(owner: symbol): boolean;
12
+ export declare function releaseSpotlight(owner: symbol): void;
13
+ export declare function isSpotlightActive(owner: symbol): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "45.26.0",
3
+ "version": "45.27.1",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@atlaskit/adf-utils": "^20.9.0",
42
- "@atlaskit/afm-i18n-platform-linking-platform-smart-card": "2.242.0",
42
+ "@atlaskit/afm-i18n-platform-linking-platform-smart-card": "2.258.0",
43
43
  "@atlaskit/analytics-cross-product": "^2.2.0",
44
44
  "@atlaskit/analytics-gas-types": "^6.2.0",
45
45
  "@atlaskit/analytics-next": "^12.5.0",
@@ -94,7 +94,7 @@
94
94
  "@atlaskit/theme": "^28.2.0",
95
95
  "@atlaskit/tile": "^4.1.0",
96
96
  "@atlaskit/tmp-editor-statsig": "^202.0.0",
97
- "@atlaskit/tokens": "^18.2.0",
97
+ "@atlaskit/tokens": "^18.3.0",
98
98
  "@atlaskit/tooltip": "^24.3.0",
99
99
  "@atlaskit/ufo": "^1.2.0",
100
100
  "@atlaskit/width-detector": "^7.2.0",