@atlaskit/profilecard 26.5.4 → 26.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @atlaskit/profilecard
2
2
 
3
+ ## 26.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`7fe653c5ef53b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7fe653c5ef53b) -
8
+ Fix agent profile card favourite status not updating until page refresh.
9
+
10
+ ## 26.5.5
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
3
16
  ## 26.5.4
4
17
 
5
18
  ### Patch Changes
@@ -8,6 +8,7 @@ exports.default = exports.AgentForbiddenError = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
11
12
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
13
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
14
  var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
@@ -22,8 +23,10 @@ var _rovoAgentUtils = require("../util/rovoAgentUtils");
22
23
  var _CachingClient2 = _interopRequireDefault(require("./CachingClient"));
23
24
  var _errorUtils = require("./errorUtils");
24
25
  var _graphqlUtils = require("./graphqlUtils");
26
+ var _sharedAgentProfileCache = require("./sharedAgentProfileCache");
25
27
  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; }
26
28
  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; }
29
+ function _superPropGet(t, o, e, r) { var p = (0, _get2.default)((0, _getPrototypeOf2.default)(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
27
30
  function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
28
31
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
29
32
  var AgentForbiddenError = exports.AgentForbiddenError = /*#__PURE__*/function (_Error) {
@@ -98,6 +101,41 @@ var RovoAgentCardClient = exports.default = /*#__PURE__*/function (_CachingClien
98
101
  value: function basePath() {
99
102
  return '/gateway/api/assist/rovo/v1/agents';
100
103
  }
104
+ }, {
105
+ key: "sharedCacheKey",
106
+ value: function sharedCacheKey(idValue) {
107
+ var _this$options$cloudId;
108
+ return "".concat((_this$options$cloudId = this.options.cloudId) !== null && _this$options$cloudId !== void 0 ? _this$options$cloudId : '', ":").concat(idValue);
109
+ }
110
+ }, {
111
+ key: "getCachedProfile",
112
+ value: function getCachedProfile(idValue) {
113
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_agent_profile_card_favourite_sync')) {
114
+ return _superPropGet(RovoAgentCardClient, "getCachedProfile", this, 3)([idValue]);
115
+ }
116
+ var key = this.sharedCacheKey(idValue);
117
+ var cached = _sharedAgentProfileCache.sharedAgentProfileCache.get(key);
118
+ if (!cached) {
119
+ return null;
120
+ }
121
+ if (cached.expire < Date.now()) {
122
+ _sharedAgentProfileCache.sharedAgentProfileCache.delete(key);
123
+ return null;
124
+ }
125
+ return cached.profile;
126
+ }
127
+ }, {
128
+ key: "setCachedProfile",
129
+ value: function setCachedProfile(idValue, profile) {
130
+ if (!(0, _platformFeatureFlags.fg)('platform_editor_agent_profile_card_favourite_sync')) {
131
+ _superPropGet(RovoAgentCardClient, "setCachedProfile", this, 3)([idValue, profile]);
132
+ return;
133
+ }
134
+ _sharedAgentProfileCache.sharedAgentProfileCache.set(this.sharedCacheKey(idValue), {
135
+ expire: Date.now() + (this.config.cacheMaxAge || _sharedAgentProfileCache.SHARED_CACHE_MAX_AGE),
136
+ profile: profile
137
+ });
138
+ }
101
139
  }, {
102
140
  key: "getActivationId",
103
141
  value: function () {
@@ -282,7 +320,7 @@ var RovoAgentCardClient = exports.default = /*#__PURE__*/function (_CachingClien
282
320
  }, _analytics.PACKAGE_META_DATA));
283
321
  }
284
322
  _this4.makeRequest(id, analytics).then(function (data) {
285
- if (_this4.cache) {
323
+ if (_this4.cache || (0, _platformFeatureFlags.fg)('platform_editor_agent_profile_card_favourite_sync')) {
286
324
  _this4.setCachedProfile(id.value, data);
287
325
  }
288
326
  if (analytics) {
@@ -386,6 +424,9 @@ var RovoAgentCardClient = exports.default = /*#__PURE__*/function (_CachingClien
386
424
  firedAt: Math.round((0, _performance.getPageTime)())
387
425
  }, _analytics.PACKAGE_META_DATA));
388
426
  }
427
+ if ((0, _platformFeatureFlags.fg)('platform_editor_agent_profile_card_favourite_sync')) {
428
+ _this6.syncFavouriteToCache(agentId, isFavourite);
429
+ }
389
430
  resolve();
390
431
  }).catch(function (error) {
391
432
  if (analytics) {
@@ -409,6 +450,42 @@ var RovoAgentCardClient = exports.default = /*#__PURE__*/function (_CachingClien
409
450
  };
410
451
  }());
411
452
  }
453
+
454
+ /**
455
+ * Keeps the shared agent profile cache in sync with the favourite state
456
+ */
457
+ }, {
458
+ key: "syncFavouriteToCache",
459
+ value: function syncFavouriteToCache(agentId, isFavourite) {
460
+ var _this$options$cloudId2;
461
+ var prefix = "".concat((_this$options$cloudId2 = this.options.cloudId) !== null && _this$options$cloudId2 !== void 0 ? _this$options$cloudId2 : '', ":");
462
+ var keysToUpdate = [];
463
+ _sharedAgentProfileCache.sharedAgentProfileCache.forEach(function (cached, key) {
464
+ var _cached$profile;
465
+ if (key.startsWith(prefix) && ((_cached$profile = cached.profile) === null || _cached$profile === void 0 || (_cached$profile = _cached$profile.restData) === null || _cached$profile === void 0 ? void 0 : _cached$profile.id) === agentId) {
466
+ keysToUpdate.push(key);
467
+ }
468
+ });
469
+ keysToUpdate.forEach(function (key) {
470
+ var _restData$favourite_c;
471
+ var cached = _sharedAgentProfileCache.sharedAgentProfileCache.get(key);
472
+ if (!cached) {
473
+ return;
474
+ }
475
+ var restData = cached.profile.restData;
476
+ var wasFavourite = restData.favourite;
477
+ var currentCount = (_restData$favourite_c = restData.favourite_count) !== null && _restData$favourite_c !== void 0 ? _restData$favourite_c : 0;
478
+ var favouriteCount = isFavourite ? currentCount + (wasFavourite ? 0 : 1) : Math.max(0, currentCount - (wasFavourite ? 1 : 0));
479
+ _sharedAgentProfileCache.sharedAgentProfileCache.set(key, _objectSpread(_objectSpread({}, cached), {}, {
480
+ profile: _objectSpread(_objectSpread({}, cached.profile), {}, {
481
+ restData: _objectSpread(_objectSpread({}, restData), {}, {
482
+ favourite: isFavourite,
483
+ favourite_count: favouriteCount
484
+ })
485
+ })
486
+ }));
487
+ });
488
+ }
412
489
  }, {
413
490
  key: "getPermissions",
414
491
  value: function getPermissions(id, fireAnalytics) {
@@ -11,7 +11,7 @@ var _graphqlUtils = require("./graphqlUtils");
11
11
  var ORG_ID_FROM_CLOUD_ID_QUERY = "query OrgIdFromCloudId($cloudId: ID!) {\n\ttenantContexts(cloudIds: [$cloudId]) {\n\t\torgId\n\t}\n}";
12
12
  var addHeaders = function addHeaders(headers) {
13
13
  headers.append('atl-client-name', "@atlaskit/profilecard");
14
- headers.append('atl-client-version', "26.5.3");
14
+ headers.append('atl-client-version', "26.5.5");
15
15
  return headers;
16
16
  };
17
17
  function getOrgIdForCloudIdFromAGG(_x, _x2) {
@@ -66,7 +66,7 @@ var addHeaders = exports.addHeaders = function addHeaders(headers) {
66
66
  headers.append('X-ExperimentalApi', 'teams-beta');
67
67
  headers.append('X-ExperimentalApi', 'team-members-beta');
68
68
  headers.append('atl-client-name', "@atlaskit/profilecard");
69
- headers.append('atl-client-version', "26.5.3");
69
+ headers.append('atl-client-version', "26.5.5");
70
70
  return headers;
71
71
  };
72
72
  function getTeamFromAGG(_x, _x2, _x3) {
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sharedAgentProfileCache = exports.SHARED_CACHE_MAX_AGE = void 0;
7
+ var _lru_map = require("lru_map");
8
+ /**
9
+ * Module-level agent profile cache shared across every `RovoAgentCardClient`
10
+ * instance
11
+ */
12
+
13
+ var SHARED_CACHE_SIZE = 50;
14
+ var SHARED_CACHE_MAX_AGE = exports.SHARED_CACHE_MAX_AGE = 5 * 60 * 1000; // 5 minutes
15
+
16
+ var sharedAgentProfileCache = exports.sharedAgentProfileCache = new _lru_map.LRUMap(SHARED_CACHE_SIZE);
@@ -12,7 +12,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
12
12
  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; }
13
13
  var PACKAGE_META_DATA = exports.PACKAGE_META_DATA = {
14
14
  packageName: (_process$env$_PACKAGE = "@atlaskit/profilecard") !== null && _process$env$_PACKAGE !== void 0 ? _process$env$_PACKAGE : '',
15
- packageVersion: (_process$env$_PACKAGE2 = "26.5.3") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
15
+ packageVersion: (_process$env$_PACKAGE2 = "26.5.5") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
16
16
  };
17
17
  var TEAM_SUBJECT = 'teamProfileCard';
18
18
  var USER_SUBJECT = 'profilecard';
@@ -31,7 +31,7 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
31
31
  actionSubjectId: actionSubjectId,
32
32
  attributes: _objectSpread(_objectSpread({
33
33
  packageName: "@atlaskit/profilecard",
34
- packageVersion: "26.5.3"
34
+ packageVersion: "26.5.5"
35
35
  }, attributes), {}, {
36
36
  firedAt: Math.round((0, _performance.getPageTime)())
37
37
  })
@@ -6,6 +6,7 @@ import { USER_ARI_PREFIX } from '../util/rovoAgentUtils';
6
6
  import CachingClient from './CachingClient';
7
7
  import { getErrorAttributes } from './errorUtils';
8
8
  import { AGGQuery } from './graphqlUtils';
9
+ import { SHARED_CACHE_MAX_AGE, sharedAgentProfileCache } from './sharedAgentProfileCache';
9
10
  export class AgentForbiddenError extends Error {
10
11
  constructor() {
11
12
  super('Agent access forbidden');
@@ -111,6 +112,35 @@ export default class RovoAgentCardClient extends CachingClient {
111
112
  basePath() {
112
113
  return '/gateway/api/assist/rovo/v1/agents';
113
114
  }
115
+ sharedCacheKey(idValue) {
116
+ var _this$options$cloudId;
117
+ return `${(_this$options$cloudId = this.options.cloudId) !== null && _this$options$cloudId !== void 0 ? _this$options$cloudId : ''}:${idValue}`;
118
+ }
119
+ getCachedProfile(idValue) {
120
+ if (!fg('platform_editor_agent_profile_card_favourite_sync')) {
121
+ return super.getCachedProfile(idValue);
122
+ }
123
+ const key = this.sharedCacheKey(idValue);
124
+ const cached = sharedAgentProfileCache.get(key);
125
+ if (!cached) {
126
+ return null;
127
+ }
128
+ if (cached.expire < Date.now()) {
129
+ sharedAgentProfileCache.delete(key);
130
+ return null;
131
+ }
132
+ return cached.profile;
133
+ }
134
+ setCachedProfile(idValue, profile) {
135
+ if (!fg('platform_editor_agent_profile_card_favourite_sync')) {
136
+ super.setCachedProfile(idValue, profile);
137
+ return;
138
+ }
139
+ sharedAgentProfileCache.set(this.sharedCacheKey(idValue), {
140
+ expire: Date.now() + (this.config.cacheMaxAge || SHARED_CACHE_MAX_AGE),
141
+ profile
142
+ });
143
+ }
114
144
  async getActivationId(cloudId, product) {
115
145
  var _response$tenantConte, _response$tenantConte2, _response$tenantConte3, _response$tenantConte4;
116
146
  const response = await AGGQuery('/gateway/api/graphql', buildActivationIdQuery(cloudId, product));
@@ -221,7 +251,7 @@ export default class RovoAgentCardClient extends CachingClient {
221
251
  });
222
252
  }
223
253
  this.makeRequest(id, analytics).then(data => {
224
- if (this.cache) {
254
+ if (this.cache || fg('platform_editor_agent_profile_card_favourite_sync')) {
225
255
  this.setCachedProfile(id.value, data);
226
256
  }
227
257
  if (analytics) {
@@ -320,6 +350,9 @@ export default class RovoAgentCardClient extends CachingClient {
320
350
  ...PACKAGE_META_DATA
321
351
  });
322
352
  }
353
+ if (fg('platform_editor_agent_profile_card_favourite_sync')) {
354
+ this.syncFavouriteToCache(agentId, isFavourite);
355
+ }
323
356
  resolve();
324
357
  }).catch(error => {
325
358
  if (analytics) {
@@ -335,6 +368,45 @@ export default class RovoAgentCardClient extends CachingClient {
335
368
  });
336
369
  });
337
370
  }
371
+
372
+ /**
373
+ * Keeps the shared agent profile cache in sync with the favourite state
374
+ */
375
+ syncFavouriteToCache(agentId, isFavourite) {
376
+ var _this$options$cloudId2;
377
+ const prefix = `${(_this$options$cloudId2 = this.options.cloudId) !== null && _this$options$cloudId2 !== void 0 ? _this$options$cloudId2 : ''}:`;
378
+ const keysToUpdate = [];
379
+ sharedAgentProfileCache.forEach((cached, key) => {
380
+ var _cached$profile, _cached$profile$restD;
381
+ if (key.startsWith(prefix) && ((_cached$profile = cached.profile) === null || _cached$profile === void 0 ? void 0 : (_cached$profile$restD = _cached$profile.restData) === null || _cached$profile$restD === void 0 ? void 0 : _cached$profile$restD.id) === agentId) {
382
+ keysToUpdate.push(key);
383
+ }
384
+ });
385
+ keysToUpdate.forEach(key => {
386
+ var _restData$favourite_c;
387
+ const cached = sharedAgentProfileCache.get(key);
388
+ if (!cached) {
389
+ return;
390
+ }
391
+ const {
392
+ restData
393
+ } = cached.profile;
394
+ const wasFavourite = restData.favourite;
395
+ const currentCount = (_restData$favourite_c = restData.favourite_count) !== null && _restData$favourite_c !== void 0 ? _restData$favourite_c : 0;
396
+ const favouriteCount = isFavourite ? currentCount + (wasFavourite ? 0 : 1) : Math.max(0, currentCount - (wasFavourite ? 1 : 0));
397
+ sharedAgentProfileCache.set(key, {
398
+ ...cached,
399
+ profile: {
400
+ ...cached.profile,
401
+ restData: {
402
+ ...restData,
403
+ favourite: isFavourite,
404
+ favourite_count: favouriteCount
405
+ }
406
+ }
407
+ });
408
+ });
409
+ }
338
410
  getPermissions(id, fireAnalytics) {
339
411
  if (!this.options.cloudId) {
340
412
  return Promise.reject(new Error('cloudId is missing'));
@@ -6,7 +6,7 @@ const ORG_ID_FROM_CLOUD_ID_QUERY = `query OrgIdFromCloudId($cloudId: ID!) {
6
6
  }`;
7
7
  const addHeaders = headers => {
8
8
  headers.append('atl-client-name', "@atlaskit/profilecard");
9
- headers.append('atl-client-version', "26.5.3");
9
+ headers.append('atl-client-version', "26.5.5");
10
10
  return headers;
11
11
  };
12
12
  export async function getOrgIdForCloudIdFromAGG(url, cloudId) {
@@ -78,7 +78,7 @@ export const addHeaders = headers => {
78
78
  headers.append('X-ExperimentalApi', 'teams-beta');
79
79
  headers.append('X-ExperimentalApi', 'team-members-beta');
80
80
  headers.append('atl-client-name', "@atlaskit/profilecard");
81
- headers.append('atl-client-version', "26.5.3");
81
+ headers.append('atl-client-version', "26.5.5");
82
82
  return headers;
83
83
  };
84
84
  export async function getTeamFromAGG(url, teamId, siteId) {
@@ -0,0 +1,11 @@
1
+ import { LRUMap } from 'lru_map';
2
+
3
+ /**
4
+ * Module-level agent profile cache shared across every `RovoAgentCardClient`
5
+ * instance
6
+ */
7
+
8
+ const SHARED_CACHE_SIZE = 50;
9
+ export const SHARED_CACHE_MAX_AGE = 5 * 60 * 1000; // 5 minutes
10
+
11
+ export const sharedAgentProfileCache = new LRUMap(SHARED_CACHE_SIZE);
@@ -2,7 +2,7 @@ var _process$env$_PACKAGE, _process$env$_PACKAGE2;
2
2
  import { getPageTime } from './performance';
3
3
  export const PACKAGE_META_DATA = {
4
4
  packageName: (_process$env$_PACKAGE = "@atlaskit/profilecard") !== null && _process$env$_PACKAGE !== void 0 ? _process$env$_PACKAGE : '',
5
- packageVersion: (_process$env$_PACKAGE2 = "26.5.3") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
5
+ packageVersion: (_process$env$_PACKAGE2 = "26.5.5") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
6
6
  };
7
7
  const TEAM_SUBJECT = 'teamProfileCard';
8
8
  const USER_SUBJECT = 'profilecard';
@@ -19,7 +19,7 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
19
19
  actionSubjectId,
20
20
  attributes: {
21
21
  packageName: "@atlaskit/profilecard",
22
- packageVersion: "26.5.3",
22
+ packageVersion: "26.5.5",
23
23
  ...attributes,
24
24
  firedAt: Math.round(getPageTime())
25
25
  }
@@ -1,5 +1,6 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _get from "@babel/runtime/helpers/get";
3
4
  import _createClass from "@babel/runtime/helpers/createClass";
4
5
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
@@ -10,6 +11,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
11
  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; }
11
12
  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; }
12
13
  import _regeneratorRuntime from "@babel/runtime/regenerator";
14
+ function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
13
15
  function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
14
16
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
15
17
  import { fg } from '@atlaskit/platform-feature-flags';
@@ -19,6 +21,7 @@ import { USER_ARI_PREFIX } from '../util/rovoAgentUtils';
19
21
  import CachingClient from './CachingClient';
20
22
  import { getErrorAttributes } from './errorUtils';
21
23
  import { AGGQuery } from './graphqlUtils';
24
+ import { SHARED_CACHE_MAX_AGE, sharedAgentProfileCache } from './sharedAgentProfileCache';
22
25
  export var AgentForbiddenError = /*#__PURE__*/function (_Error) {
23
26
  function AgentForbiddenError() {
24
27
  var _this;
@@ -91,6 +94,41 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
91
94
  value: function basePath() {
92
95
  return '/gateway/api/assist/rovo/v1/agents';
93
96
  }
97
+ }, {
98
+ key: "sharedCacheKey",
99
+ value: function sharedCacheKey(idValue) {
100
+ var _this$options$cloudId;
101
+ return "".concat((_this$options$cloudId = this.options.cloudId) !== null && _this$options$cloudId !== void 0 ? _this$options$cloudId : '', ":").concat(idValue);
102
+ }
103
+ }, {
104
+ key: "getCachedProfile",
105
+ value: function getCachedProfile(idValue) {
106
+ if (!fg('platform_editor_agent_profile_card_favourite_sync')) {
107
+ return _superPropGet(RovoAgentCardClient, "getCachedProfile", this, 3)([idValue]);
108
+ }
109
+ var key = this.sharedCacheKey(idValue);
110
+ var cached = sharedAgentProfileCache.get(key);
111
+ if (!cached) {
112
+ return null;
113
+ }
114
+ if (cached.expire < Date.now()) {
115
+ sharedAgentProfileCache.delete(key);
116
+ return null;
117
+ }
118
+ return cached.profile;
119
+ }
120
+ }, {
121
+ key: "setCachedProfile",
122
+ value: function setCachedProfile(idValue, profile) {
123
+ if (!fg('platform_editor_agent_profile_card_favourite_sync')) {
124
+ _superPropGet(RovoAgentCardClient, "setCachedProfile", this, 3)([idValue, profile]);
125
+ return;
126
+ }
127
+ sharedAgentProfileCache.set(this.sharedCacheKey(idValue), {
128
+ expire: Date.now() + (this.config.cacheMaxAge || SHARED_CACHE_MAX_AGE),
129
+ profile: profile
130
+ });
131
+ }
94
132
  }, {
95
133
  key: "getActivationId",
96
134
  value: function () {
@@ -275,7 +313,7 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
275
313
  }, PACKAGE_META_DATA));
276
314
  }
277
315
  _this4.makeRequest(id, analytics).then(function (data) {
278
- if (_this4.cache) {
316
+ if (_this4.cache || fg('platform_editor_agent_profile_card_favourite_sync')) {
279
317
  _this4.setCachedProfile(id.value, data);
280
318
  }
281
319
  if (analytics) {
@@ -379,6 +417,9 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
379
417
  firedAt: Math.round(getPageTime())
380
418
  }, PACKAGE_META_DATA));
381
419
  }
420
+ if (fg('platform_editor_agent_profile_card_favourite_sync')) {
421
+ _this6.syncFavouriteToCache(agentId, isFavourite);
422
+ }
382
423
  resolve();
383
424
  }).catch(function (error) {
384
425
  if (analytics) {
@@ -402,6 +443,42 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
402
443
  };
403
444
  }());
404
445
  }
446
+
447
+ /**
448
+ * Keeps the shared agent profile cache in sync with the favourite state
449
+ */
450
+ }, {
451
+ key: "syncFavouriteToCache",
452
+ value: function syncFavouriteToCache(agentId, isFavourite) {
453
+ var _this$options$cloudId2;
454
+ var prefix = "".concat((_this$options$cloudId2 = this.options.cloudId) !== null && _this$options$cloudId2 !== void 0 ? _this$options$cloudId2 : '', ":");
455
+ var keysToUpdate = [];
456
+ sharedAgentProfileCache.forEach(function (cached, key) {
457
+ var _cached$profile;
458
+ if (key.startsWith(prefix) && ((_cached$profile = cached.profile) === null || _cached$profile === void 0 || (_cached$profile = _cached$profile.restData) === null || _cached$profile === void 0 ? void 0 : _cached$profile.id) === agentId) {
459
+ keysToUpdate.push(key);
460
+ }
461
+ });
462
+ keysToUpdate.forEach(function (key) {
463
+ var _restData$favourite_c;
464
+ var cached = sharedAgentProfileCache.get(key);
465
+ if (!cached) {
466
+ return;
467
+ }
468
+ var restData = cached.profile.restData;
469
+ var wasFavourite = restData.favourite;
470
+ var currentCount = (_restData$favourite_c = restData.favourite_count) !== null && _restData$favourite_c !== void 0 ? _restData$favourite_c : 0;
471
+ var favouriteCount = isFavourite ? currentCount + (wasFavourite ? 0 : 1) : Math.max(0, currentCount - (wasFavourite ? 1 : 0));
472
+ sharedAgentProfileCache.set(key, _objectSpread(_objectSpread({}, cached), {}, {
473
+ profile: _objectSpread(_objectSpread({}, cached.profile), {}, {
474
+ restData: _objectSpread(_objectSpread({}, restData), {}, {
475
+ favourite: isFavourite,
476
+ favourite_count: favouriteCount
477
+ })
478
+ })
479
+ }));
480
+ });
481
+ }
405
482
  }, {
406
483
  key: "getPermissions",
407
484
  value: function getPermissions(id, fireAnalytics) {
@@ -4,7 +4,7 @@ import { AGGQuery } from './graphqlUtils';
4
4
  var ORG_ID_FROM_CLOUD_ID_QUERY = "query OrgIdFromCloudId($cloudId: ID!) {\n\ttenantContexts(cloudIds: [$cloudId]) {\n\t\torgId\n\t}\n}";
5
5
  var addHeaders = function addHeaders(headers) {
6
6
  headers.append('atl-client-name', "@atlaskit/profilecard");
7
- headers.append('atl-client-version', "26.5.3");
7
+ headers.append('atl-client-version', "26.5.5");
8
8
  return headers;
9
9
  };
10
10
  export function getOrgIdForCloudIdFromAGG(_x, _x2) {
@@ -59,7 +59,7 @@ export var addHeaders = function addHeaders(headers) {
59
59
  headers.append('X-ExperimentalApi', 'teams-beta');
60
60
  headers.append('X-ExperimentalApi', 'team-members-beta');
61
61
  headers.append('atl-client-name', "@atlaskit/profilecard");
62
- headers.append('atl-client-version', "26.5.3");
62
+ headers.append('atl-client-version', "26.5.5");
63
63
  return headers;
64
64
  };
65
65
  export function getTeamFromAGG(_x, _x2, _x3) {
@@ -0,0 +1,11 @@
1
+ import { LRUMap } from 'lru_map';
2
+
3
+ /**
4
+ * Module-level agent profile cache shared across every `RovoAgentCardClient`
5
+ * instance
6
+ */
7
+
8
+ var SHARED_CACHE_SIZE = 50;
9
+ export var SHARED_CACHE_MAX_AGE = 5 * 60 * 1000; // 5 minutes
10
+
11
+ export var sharedAgentProfileCache = new LRUMap(SHARED_CACHE_SIZE);
@@ -5,7 +5,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
5
5
  import { getPageTime } from './performance';
6
6
  export var PACKAGE_META_DATA = {
7
7
  packageName: (_process$env$_PACKAGE = "@atlaskit/profilecard") !== null && _process$env$_PACKAGE !== void 0 ? _process$env$_PACKAGE : '',
8
- packageVersion: (_process$env$_PACKAGE2 = "26.5.3") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
8
+ packageVersion: (_process$env$_PACKAGE2 = "26.5.5") !== null && _process$env$_PACKAGE2 !== void 0 ? _process$env$_PACKAGE2 : ''
9
9
  };
10
10
  var TEAM_SUBJECT = 'teamProfileCard';
11
11
  var USER_SUBJECT = 'profilecard';
@@ -24,7 +24,7 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
24
24
  actionSubjectId: actionSubjectId,
25
25
  attributes: _objectSpread(_objectSpread({
26
26
  packageName: "@atlaskit/profilecard",
27
- packageVersion: "26.5.3"
27
+ packageVersion: "26.5.5"
28
28
  }, attributes), {}, {
29
29
  firedAt: Math.round(getPageTime())
30
30
  })
@@ -9,6 +9,9 @@ export default class RovoAgentCardClient extends CachingClient<RovoAgentCardClie
9
9
  options: ProfileClientOptions;
10
10
  constructor(options: ProfileClientOptions);
11
11
  private basePath;
12
+ private sharedCacheKey;
13
+ getCachedProfile(idValue: string): RovoAgentCardClientResult | null;
14
+ setCachedProfile(idValue: string, profile: RovoAgentCardClientResult): void;
12
15
  private getActivationId;
13
16
  private getAgentByARIAgg;
14
17
  private getAgentByAccountIdAgg;
@@ -23,5 +26,9 @@ export default class RovoAgentCardClient extends CachingClient<RovoAgentCardClie
23
26
  getProfile(id: AgentIdType, analytics?: FireEventType): Promise<RovoAgentCardClientResult>;
24
27
  deleteAgent(agentId: string, analytics?: FireEventType): Promise<void>;
25
28
  setFavouriteAgent(agentId: string, isFavourite: boolean, analytics?: FireEventType): Promise<void>;
29
+ /**
30
+ * Keeps the shared agent profile cache in sync with the favourite state
31
+ */
32
+ private syncFavouriteToCache;
26
33
  getPermissions(id: string, fireAnalytics?: FireEventType): Promise<AgentPermissions>;
27
34
  }
@@ -0,0 +1,13 @@
1
+ import { LRUMap } from 'lru_map';
2
+ import type { RovoAgentCardClientResult } from '../types';
3
+ /**
4
+ * Module-level agent profile cache shared across every `RovoAgentCardClient`
5
+ * instance
6
+ */
7
+ type CachedAgentProfile = {
8
+ expire: number;
9
+ profile: RovoAgentCardClientResult;
10
+ };
11
+ export declare const SHARED_CACHE_MAX_AGE: number;
12
+ export declare const sharedAgentProfileCache: LRUMap<string, CachedAgentProfile>;
13
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/profilecard",
3
- "version": "26.5.4",
3
+ "version": "26.6.0",
4
4
  "description": "A React component to display a card with user information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -47,7 +47,7 @@
47
47
  "@atlaskit/dropdown-menu": "^17.1.0",
48
48
  "@atlaskit/empty-state": "^11.1.0",
49
49
  "@atlaskit/feature-gate-js-client": "^6.0.0",
50
- "@atlaskit/give-kudos": "^6.2.0",
50
+ "@atlaskit/give-kudos": "^6.3.0",
51
51
  "@atlaskit/heading": "^6.1.0",
52
52
  "@atlaskit/icon": "^36.1.0",
53
53
  "@atlaskit/link": "4.1.0",
@@ -60,7 +60,7 @@
60
60
  "@atlaskit/primitives": "^20.3.0",
61
61
  "@atlaskit/react-compiler-gating": "^0.2.0",
62
62
  "@atlaskit/rovo-agent-components": "^7.3.0",
63
- "@atlaskit/rovo-triggers": "^9.6.0",
63
+ "@atlaskit/rovo-triggers": "^9.7.0",
64
64
  "@atlaskit/spinner": "^20.1.0",
65
65
  "@atlaskit/teams-app-config": "^2.1.0",
66
66
  "@atlaskit/teams-app-internal-analytics": "^2.2.0",
@@ -68,7 +68,7 @@
68
68
  "@atlaskit/teams-avatar": "^3.1.0",
69
69
  "@atlaskit/teams-public": "^2.3.0",
70
70
  "@atlaskit/theme": "^26.1.0",
71
- "@atlaskit/tmp-editor-statsig": "^119.0.0",
71
+ "@atlaskit/tmp-editor-statsig": "^120.0.0",
72
72
  "@atlaskit/tokens": "^15.3.0",
73
73
  "@atlaskit/tooltip": "^23.1.0",
74
74
  "@atlassian/studio-entry-link": "^1.1.0",
@@ -181,6 +181,9 @@
181
181
  "fix_aria_attribute_violation_on_agent_card_trigger": {
182
182
  "type": "boolean"
183
183
  },
184
+ "platform_editor_agent_profile_card_favourite_sync": {
185
+ "type": "boolean"
186
+ },
184
187
  "platform_editor_reduced_agent_profile_card": {
185
188
  "type": "boolean"
186
189
  }