@atlaskit/profilecard 19.18.1 → 19.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/agent/package.json +14 -0
  3. package/dist/cjs/client/ProfileCardClient.js +2 -2
  4. package/dist/cjs/client/RovoAgentCardClient.js +11 -8
  5. package/dist/cjs/client/getAgentInfo.js +4 -7
  6. package/dist/cjs/client/getTeamFromAGG.js +1 -1
  7. package/dist/cjs/components/Agent/AgentProfileCard.js +34 -6
  8. package/dist/cjs/components/Agent/AgentProfileCardResourced.js +36 -12
  9. package/dist/cjs/components/Agent/AgentProfileCardTrigger.js +41 -16
  10. package/dist/cjs/components/Agent/index.js +8 -0
  11. package/dist/cjs/components/Agent/useSetFavouriteAgent.js +22 -16
  12. package/dist/cjs/components/common/ProfileCardTrigger.js +13 -5
  13. package/dist/cjs/mocks/simple-mock-clients.js +1 -1
  14. package/dist/cjs/util/analytics.js +16 -4
  15. package/dist/cjs/util/rovoAgentUtils.js +3 -3
  16. package/dist/cjs/util/useProfileInfo.js +11 -6
  17. package/dist/es2019/client/ProfileCardClient.js +2 -2
  18. package/dist/es2019/client/RovoAgentCardClient.js +12 -9
  19. package/dist/es2019/client/getAgentInfo.js +5 -3
  20. package/dist/es2019/client/getTeamFromAGG.js +1 -1
  21. package/dist/es2019/components/Agent/AgentProfileCard.js +32 -6
  22. package/dist/es2019/components/Agent/AgentProfileCardResourced.js +31 -10
  23. package/dist/es2019/components/Agent/AgentProfileCardTrigger.js +39 -17
  24. package/dist/es2019/components/Agent/index.js +2 -0
  25. package/dist/es2019/components/Agent/useSetFavouriteAgent.js +5 -2
  26. package/dist/es2019/components/common/ProfileCardTrigger.js +10 -3
  27. package/dist/es2019/mocks/simple-mock-clients.js +1 -1
  28. package/dist/es2019/util/analytics.js +20 -6
  29. package/dist/es2019/util/rovoAgentUtils.js +2 -2
  30. package/dist/es2019/util/useProfileInfo.js +3 -1
  31. package/dist/esm/client/ProfileCardClient.js +2 -2
  32. package/dist/esm/client/RovoAgentCardClient.js +12 -9
  33. package/dist/esm/client/getAgentInfo.js +4 -7
  34. package/dist/esm/client/getTeamFromAGG.js +1 -1
  35. package/dist/esm/components/Agent/AgentProfileCard.js +31 -6
  36. package/dist/esm/components/Agent/AgentProfileCardResourced.js +36 -12
  37. package/dist/esm/components/Agent/AgentProfileCardTrigger.js +42 -17
  38. package/dist/esm/components/Agent/index.js +2 -0
  39. package/dist/esm/components/Agent/useSetFavouriteAgent.js +22 -16
  40. package/dist/esm/components/common/ProfileCardTrigger.js +13 -5
  41. package/dist/esm/mocks/simple-mock-clients.js +1 -1
  42. package/dist/esm/util/analytics.js +16 -4
  43. package/dist/esm/util/rovoAgentUtils.js +2 -2
  44. package/dist/esm/util/useProfileInfo.js +11 -6
  45. package/dist/types/client/ProfileCardClient.d.ts +2 -2
  46. package/dist/types/client/RovoAgentCardClient.d.ts +3 -3
  47. package/dist/types/components/Agent/AgentProfileCard.d.ts +4 -3
  48. package/dist/types/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  49. package/dist/types/components/Agent/index.d.ts +2 -0
  50. package/dist/types/components/Agent/lazyAgentProfileCard.d.ts +3 -2
  51. package/dist/types/components/Agent/useSetFavouriteAgent.d.ts +2 -2
  52. package/dist/types/components/common/ProfileCardTrigger.d.ts +1 -1
  53. package/dist/types/components/common/types.d.ts +6 -1
  54. package/dist/types/mocks/simple-mock-clients.d.ts +2 -2
  55. package/dist/types/types.d.ts +6 -1
  56. package/dist/types/util/analytics.d.ts +1 -1
  57. package/dist/types/util/rovoAgentUtils.d.ts +1 -0
  58. package/dist/types/util/useProfileInfo.d.ts +1 -0
  59. package/dist/types-ts4.5/client/ProfileCardClient.d.ts +2 -2
  60. package/dist/types-ts4.5/client/RovoAgentCardClient.d.ts +3 -3
  61. package/dist/types-ts4.5/components/Agent/AgentProfileCard.d.ts +4 -3
  62. package/dist/types-ts4.5/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  63. package/dist/types-ts4.5/components/Agent/index.d.ts +2 -0
  64. package/dist/types-ts4.5/components/Agent/lazyAgentProfileCard.d.ts +3 -2
  65. package/dist/types-ts4.5/components/Agent/useSetFavouriteAgent.d.ts +2 -2
  66. package/dist/types-ts4.5/components/common/ProfileCardTrigger.d.ts +1 -1
  67. package/dist/types-ts4.5/components/common/types.d.ts +6 -1
  68. package/dist/types-ts4.5/mocks/simple-mock-clients.d.ts +2 -2
  69. package/dist/types-ts4.5/types.d.ts +6 -1
  70. package/dist/types-ts4.5/util/analytics.d.ts +1 -1
  71. package/dist/types-ts4.5/util/rovoAgentUtils.d.ts +1 -0
  72. package/dist/types-ts4.5/util/useProfileInfo.d.ts +1 -0
  73. package/package.json +3 -2
@@ -4,10 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.getAAIDFromARI = exports.createHeaders = void 0;
7
+ exports.getAAIDFromARI = exports.createHeaders = exports.USER_ARI_PREFIX = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  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; }
10
10
  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; }
11
+ var USER_ARI_PREFIX = exports.USER_ARI_PREFIX = 'ari:cloud:identity::user/';
11
12
  var createHeaders = exports.createHeaders = function createHeaders(product, cloudId) {
12
13
  var config = {
13
14
  headers: {
@@ -19,6 +20,5 @@ var createHeaders = exports.createHeaders = function createHeaders(product, clou
19
20
  return new Headers(_objectSpread({}, config.headers || {}));
20
21
  };
21
22
  var getAAIDFromARI = exports.getAAIDFromARI = function getAAIDFromARI(ari) {
22
- var matched = ari.match(/\/([a-zA-Z0-9_\|\-\:]{1,128})$/);
23
- return matched ? matched[1] : undefined;
23
+ return ari.replace(USER_ARI_PREFIX, '');
24
24
  };
@@ -15,10 +15,14 @@ var useProfileInfo = exports.useProfileInfo = function useProfileInfo(_ref) {
15
15
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
16
16
  isLoading = _useState2[0],
17
17
  setIsLoading = _useState2[1];
18
- var _useState3 = (0, _react.useState)(),
18
+ var _useState3 = (0, _react.useState)(null),
19
19
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
20
- profileData = _useState4[0],
21
- setProfileData = _useState4[1];
20
+ error = _useState4[0],
21
+ setError = _useState4[1];
22
+ var _useState5 = (0, _react.useState)(),
23
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
24
+ profileData = _useState6[0],
25
+ setProfileData = _useState6[1];
22
26
  var getProfileData = /*#__PURE__*/function () {
23
27
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
24
28
  var _profileData;
@@ -33,13 +37,14 @@ var useProfileInfo = exports.useProfileInfo = function useProfileInfo(_ref) {
33
37
  _profileData = _context.sent;
34
38
  setProfileData(_profileData);
35
39
  setIsLoading(false);
36
- _context.next = 12;
40
+ _context.next = 13;
37
41
  break;
38
42
  case 9:
39
43
  _context.prev = 9;
40
44
  _context.t0 = _context["catch"](1);
45
+ setError(_context.t0);
41
46
  setIsLoading(true);
42
- case 12:
47
+ case 13:
43
48
  case "end":
44
49
  return _context.stop();
45
50
  }
@@ -52,7 +57,7 @@ var useProfileInfo = exports.useProfileInfo = function useProfileInfo(_ref) {
52
57
  return {
53
58
  profileData: profileData,
54
59
  isLoading: isLoading,
55
- // hasError: Boolean(error) || cannotLoadUser,
60
+ error: error,
56
61
  getProfileData: getProfileData
57
62
  };
58
63
  };
@@ -40,9 +40,9 @@ class ProfileCardClient {
40
40
  }
41
41
  return this.tcClient.checkWorkspaceExists();
42
42
  }
43
- getRovoAgentProfile(agentId, analytics) {
43
+ getRovoAgentProfile(id, analytics) {
44
44
  var _this$rovoAgentClient2;
45
- return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(agentId, analytics);
45
+ return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(id, analytics);
46
46
  }
47
47
  }
48
48
  function maybeCreateTeamCentralClient(config, clients) {
@@ -2,26 +2,29 @@ import { agentRequestAnalytics } from '../util/analytics';
2
2
  import { getPageTime } from '../util/performance';
3
3
  import CachingClient from './CachingClient';
4
4
  import { getErrorAttributes } from './errorUtils';
5
- import { getAgentDetailsByAgentId } from './getAgentInfo';
5
+ import { getAgentDetailsByAgentId, getAgentDetailsByUserId } from './getAgentInfo';
6
6
  export default class RovoAgentCardClient extends CachingClient {
7
7
  constructor(options) {
8
8
  super(options);
9
9
  this.options = options;
10
10
  }
11
- makeRequest(agentId, cloudId) {
11
+ makeRequest(id, cloudId) {
12
12
  if (!this.options.productIdentifier) {
13
13
  throw new Error('Trying to fetch agents data with no specified config.productIdentifier');
14
14
  }
15
- return getAgentDetailsByAgentId(agentId, this.options.productIdentifier, cloudId);
15
+ if (id.type === 'identity') {
16
+ return getAgentDetailsByUserId(id.value, this.options.productIdentifier, cloudId);
17
+ }
18
+ return getAgentDetailsByAgentId(id.value, this.options.productIdentifier, cloudId);
16
19
  }
17
- getProfile(agentId, analytics) {
18
- if (!agentId) {
19
- return Promise.reject(new Error('agentId is missing'));
20
+ getProfile(id, analytics) {
21
+ if (!id.value) {
22
+ return Promise.reject(new Error('IF is missing'));
20
23
  }
21
24
  if (!this.options.cloudId) {
22
25
  return Promise.reject(new Error('cloudId is missing'));
23
26
  }
24
- const cache = this.getCachedProfile(agentId);
27
+ const cache = this.getCachedProfile(id.value);
25
28
  if (cache) {
26
29
  return Promise.resolve(cache);
27
30
  }
@@ -30,9 +33,9 @@ export default class RovoAgentCardClient extends CachingClient {
30
33
  if (analytics) {
31
34
  analytics(agentRequestAnalytics('triggered'));
32
35
  }
33
- this.makeRequest(agentId, this.options.cloudId || '').then(data => {
36
+ this.makeRequest(id, this.options.cloudId || '').then(data => {
34
37
  if (this.cache) {
35
- this.setCachedProfile(agentId, data);
38
+ this.setCachedProfile(id.value, data);
36
39
  }
37
40
  if (analytics) {
38
41
  analytics(agentRequestAnalytics('succeeded', {
@@ -1,7 +1,7 @@
1
1
  import { createHeaders } from '../util/rovoAgentUtils';
2
2
  export async function getAgentDetailsByAgentId(agentId, product, cloudId) {
3
3
  const headers = createHeaders(product, cloudId);
4
- return await fetch(new Request(`assist/agents/v1/${agentId}`, {
4
+ return await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}`, {
5
5
  method: 'GET',
6
6
  credentials: 'include',
7
7
  mode: 'cors',
@@ -10,10 +10,12 @@ export async function getAgentDetailsByAgentId(agentId, product, cloudId) {
10
10
  }
11
11
  export async function getAgentDetailsByUserId(userId, product, cloudId) {
12
12
  const headers = createHeaders(product, cloudId);
13
- return await fetch(new Request(`assist/agents/v1/accountid/${userId}`, {
13
+ return fetch(new Request(`/gateway/api/assist/agents/v1/accountid/${userId}`, {
14
14
  method: 'GET',
15
15
  credentials: 'include',
16
16
  mode: 'cors',
17
17
  headers
18
- })).then(response => response.json());
18
+ })).then(response => {
19
+ return response.json();
20
+ });
19
21
  }
@@ -67,7 +67,7 @@ export const addHeaders = headers => {
67
67
  headers.append('X-ExperimentalApi', 'teams-beta');
68
68
  headers.append('X-ExperimentalApi', 'team-members-beta');
69
69
  headers.append('atl-client-name', "@atlaskit/profilecard");
70
- headers.append('atl-client-version', "19.18.1");
70
+ headers.append('atl-client-version', "19.19.0");
71
71
  return headers;
72
72
  };
73
73
  export async function getTeamFromAGG(url, teamId, siteId) {
@@ -1,7 +1,10 @@
1
- import React from 'react';
1
+ import React, { useCallback, useEffect } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
2
3
  import { Box, Stack, xcss } from '@atlaskit/primitives';
3
4
  import { AgentAvatar, AgentBanner, AgentProfileCreator, AgentProfileInfo, AgentStarCount } from '@atlaskit/rovo-agent-components';
5
+ import { fireEvent, profileCardRendered } from '../../util/analytics';
4
6
  import LoadingState from '../common/LoadingState';
7
+ import { ErrorMessage } from '../Error';
5
8
  import { AgentActions } from './Actions';
6
9
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
7
10
  import { ConversationStarters } from './ConversationStarters';
@@ -27,7 +30,9 @@ const AgentProfileCard = ({
27
30
  isCreatedByViewingUser,
28
31
  cloudId,
29
32
  onOpenChat,
30
- product = 'rovo'
33
+ product = 'rovo',
34
+ hasError,
35
+ errorType
31
36
  }) => {
32
37
  var _agent$creatorInfo, _agent$creatorInfo2, _agent$creatorInfo3, _agent$creatorInfo4;
33
38
  const {
@@ -41,14 +46,34 @@ const AgentProfileCard = ({
41
46
  isStarred,
42
47
  setFavourite
43
48
  } = useSetFavouriteAgent({
44
- agentId: agent.id,
45
- cloudId: cloudId || '',
46
- isStarred: agent.favourite,
49
+ agentId: agent === null || agent === void 0 ? void 0 : agent.id,
50
+ cloudId: cloudId,
51
+ isStarred: !!(agent !== null && agent !== void 0 && agent.favourite),
47
52
  product
48
53
  });
54
+ const {
55
+ createAnalyticsEvent
56
+ } = useAnalyticsEvents();
57
+ const fireAnalytics = useCallback(payload => {
58
+ if (createAnalyticsEvent) {
59
+ fireEvent(createAnalyticsEvent, payload);
60
+ }
61
+ }, [createAnalyticsEvent]);
62
+ useEffect(() => {
63
+ if (!isLoading && agent) {
64
+ fireAnalytics(profileCardRendered('agent', 'content'));
65
+ }
66
+ }, [agent, fireAnalytics, isLoading]);
49
67
  if (isLoading) {
50
68
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(LoadingState, {
51
- profileType: "agent"
69
+ profileType: "agent",
70
+ fireAnalytics: fireAnalytics
71
+ }));
72
+ }
73
+ if (hasError || !agent) {
74
+ return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
75
+ errorType: errorType,
76
+ fireAnalytics: fireAnalytics
52
77
  }));
53
78
  }
54
79
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(Box, {
@@ -66,6 +91,7 @@ const AgentProfileCard = ({
66
91
  agentName: agent.name,
67
92
  isStarred: isStarred,
68
93
  onStarToggle: setFavourite,
94
+ isHidden: agent.visibility === 'PRIVATE',
69
95
  creatorRender: ((_agent$creatorInfo = agent.creatorInfo) === null || _agent$creatorInfo === void 0 ? void 0 : _agent$creatorInfo.type) && /*#__PURE__*/React.createElement(AgentProfileCreator, {
70
96
  creator: {
71
97
  type: (_agent$creatorInfo2 = agent.creatorInfo) === null || _agent$creatorInfo2 === void 0 ? void 0 : _agent$creatorInfo2.type,
@@ -1,4 +1,6 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
+ import { fireEvent } from '../../util/analytics';
2
4
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
3
5
  import ErrorMessage from '../Error/ErrorMessage';
4
6
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
@@ -7,6 +9,14 @@ export const AgentProfileCardResourced = props => {
7
9
  const [agentData, setAgentData] = useState();
8
10
  const [isLoading, setIsLoading] = useState(false);
9
11
  const [error, setError] = useState();
12
+ const {
13
+ createAnalyticsEvent
14
+ } = useAnalyticsEvents();
15
+ const fireAnalytics = useCallback(payload => {
16
+ if (createAnalyticsEvent) {
17
+ fireEvent(createAnalyticsEvent, payload);
18
+ }
19
+ }, [createAnalyticsEvent]);
10
20
  const creatorUserId = useMemo(() => (agentData === null || agentData === void 0 ? void 0 : agentData.creator_type) === 'CUSTOMER' && agentData.creator ? getAAIDFromARI(agentData.creator) : '', [agentData === null || agentData === void 0 ? void 0 : agentData.creator_type, agentData === null || agentData === void 0 ? void 0 : agentData.creator]);
11
21
  const getCreator = useCallback(async (creator_type, creator) => {
12
22
  if (!creator) {
@@ -23,19 +33,30 @@ export const AgentProfileCardResourced = props => {
23
33
  name: creator !== null && creator !== void 0 ? creator : ''
24
34
  };
25
35
  case 'CUSTOMER':
26
- const creatorInfo = await props.resourceClient.getProfile(creatorUserId || '', props.cloudId || '');
27
- return {
28
- type: 'CUSTOMER',
29
- name: creatorInfo.fullName,
30
- profileLink: `/people/${creatorUserId}`
31
- };
36
+ try {
37
+ if (!creatorUserId || !props.cloudId) {
38
+ return undefined;
39
+ }
40
+ const creatorInfo = await props.resourceClient.getProfile(creatorUserId, props.cloudId, fireAnalytics);
41
+ return {
42
+ type: 'CUSTOMER',
43
+ name: creatorInfo.fullName,
44
+ profileLink: `/people/${creatorUserId}`,
45
+ id: creatorUserId
46
+ };
47
+ } catch (error) {
48
+ return undefined;
49
+ }
32
50
  default:
33
51
  return undefined;
34
52
  }
35
- }, [creatorUserId, props.cloudId, props.resourceClient]);
53
+ }, [creatorUserId, fireAnalytics, props.cloudId, props.resourceClient]);
36
54
  const getAgentInfo = useCallback(() => {
37
- return props.resourceClient.getRovoAgentProfile(props.agentId);
38
- }, [props.agentId, props.resourceClient]);
55
+ return props.resourceClient.getRovoAgentProfile({
56
+ type: 'identity',
57
+ value: props.accountId
58
+ }, fireAnalytics);
59
+ }, [fireAnalytics, props.accountId, props.resourceClient]);
39
60
  const fetchData = useCallback(async () => {
40
61
  setIsLoading(true);
41
62
  const getAgentData = async () => {
@@ -57,7 +78,7 @@ export const AgentProfileCardResourced = props => {
57
78
  setIsLoading(false);
58
79
  setError(error);
59
80
  }
60
- }, [fetchData, getAgentInfo, getCreator, props.agentId, props.cloudId, props.resourceClient]);
81
+ }, [fetchData, getAgentInfo, getCreator, props.accountId, props.cloudId, props.resourceClient]);
61
82
  if (error || !isLoading && !agentData) {
62
83
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
63
84
  reload: () => {
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React, { Suspense, useCallback } from 'react';
3
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
4
+ import { fireEvent } from '../../util/analytics';
3
5
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
4
6
  import ProfileCardTrigger from '../common/ProfileCardTrigger';
5
7
  import { AgentProfileCardLazy } from './lazyAgentProfileCard';
@@ -14,6 +16,14 @@ export const AgentProfileCardTrigger = ({
14
16
  userId,
15
17
  cloudId
16
18
  } = props;
19
+ const {
20
+ createAnalyticsEvent
21
+ } = useAnalyticsEvents();
22
+ const fireAnalytics = useCallback(payload => {
23
+ if (createAnalyticsEvent) {
24
+ fireEvent(createAnalyticsEvent, payload);
25
+ }
26
+ }, [createAnalyticsEvent]);
17
27
  const getCreator = async (creator_type, creator) => {
18
28
  if (!creator) {
19
29
  return undefined;
@@ -30,19 +40,29 @@ export const AgentProfileCardTrigger = ({
30
40
  };
31
41
  case 'CUSTOMER':
32
42
  const userId = getAAIDFromARI(creator) || '';
33
- const creatorInfo = await props.resourceClient.getProfile(userId, cloudId || '');
34
- return {
35
- type: 'CUSTOMER',
36
- name: creatorInfo.fullName,
37
- profileLink: `/people/${userId}`,
38
- id: userId
39
- };
43
+ try {
44
+ if (!userId || !cloudId) {
45
+ return undefined;
46
+ }
47
+ const creatorInfo = await props.resourceClient.getProfile(cloudId, userId, fireAnalytics);
48
+ return {
49
+ type: 'CUSTOMER',
50
+ name: creatorInfo.fullName,
51
+ profileLink: `/people/${userId}`,
52
+ id: userId
53
+ };
54
+ } catch (error) {
55
+ return undefined;
56
+ }
40
57
  default:
41
58
  return undefined;
42
59
  }
43
60
  };
44
61
  const fetchAgentProfile = async () => {
45
- const agentInfo = await resourceClient.getRovoAgentProfile(userId);
62
+ const agentInfo = await resourceClient.getRovoAgentProfile({
63
+ type: 'agent',
64
+ value: userId
65
+ }, fireAnalytics);
46
66
  const agentCreatorInfo = await getCreator(agentInfo.creator_type, agentInfo.creator || undefined);
47
67
  return {
48
68
  ...agentInfo,
@@ -51,25 +71,27 @@ export const AgentProfileCardTrigger = ({
51
71
  };
52
72
  const renderProfileCard = ({
53
73
  profileData,
54
- isLoading
74
+ isLoading,
75
+ error
55
76
  }) => {
56
77
  var _profileData$creatorI;
57
- if (!profileData) {
58
- return /*#__PURE__*/React.createElement(React.Fragment, null);
59
- }
60
78
  return /*#__PURE__*/React.createElement(Suspense, {
61
79
  fallback: null
62
80
  }, /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
63
81
  agent: profileData,
64
82
  isLoading: isLoading,
65
- isCreatedByViewingUser: ((_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
83
+ hasError: !!error,
84
+ isCreatedByViewingUser: (profileData === null || profileData === void 0 ? void 0 : (_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
66
85
  cloudId: props.cloudId,
67
- product: product
86
+ product: product,
87
+ errorType: error
68
88
  }));
69
89
  };
70
90
  return /*#__PURE__*/React.createElement(ProfileCardTrigger, _extends({}, props, {
91
+ trigger: "hover",
71
92
  renderProfileCard: renderProfileCard,
72
- trigger: trigger,
73
- fetchProfile: fetchAgentProfile
93
+ fetchProfile: fetchAgentProfile,
94
+ fireAnalytics: fireAnalytics,
95
+ profileCardType: "agent"
74
96
  }));
75
97
  };
@@ -0,0 +1,2 @@
1
+ import { AgentProfileCardTrigger } from './AgentProfileCardTrigger';
2
+ export default AgentProfileCardTrigger;
@@ -9,11 +9,14 @@ export const useSetFavouriteAgent = ({
9
9
  const [isLoading, setIsLoading] = useState(false);
10
10
  const [isFavourite, setIsFavourite] = useState(isStarred);
11
11
  const setFavourite = async () => {
12
+ if (!agentId || !cloudId) {
13
+ return;
14
+ }
12
15
  setIsLoading(true);
13
16
  try {
14
17
  const headers = createHeaders(product, cloudId);
15
18
  if (isFavourite) {
16
- await fetch(new Request(`/agents/v1/${agentId}/favourite`, {
19
+ await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}/favourite`, {
17
20
  method: 'POST',
18
21
  credentials: 'include',
19
22
  mode: 'cors',
@@ -22,7 +25,7 @@ export const useSetFavouriteAgent = ({
22
25
  setIsFavourite(true);
23
26
  });
24
27
  } else {
25
- await fetch(new Request(`/agents/v1/${agentId}/favourite`, {
28
+ await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}/favourite`, {
26
29
  method: 'DELETE',
27
30
  credentials: 'include',
28
31
  mode: 'cors',
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import Popup from '@atlaskit/popup';
4
4
  import { layers } from '@atlaskit/theme/constants';
5
+ import { cardTriggered } from '../../util/analytics';
5
6
  import { useProfileInfo } from '../../util/useProfileInfo';
6
7
  import { PopupTrigger } from './PopupTrigger';
7
8
  const DELAY_MS_SHOW = 800;
@@ -13,6 +14,8 @@ function ProfileCardTrigger({
13
14
  renderProfileCard,
14
15
  fetchProfile,
15
16
  disabledAriaAttributes,
17
+ profileCardType,
18
+ fireAnalytics,
16
19
  ...popupProps
17
20
  }) {
18
21
  var _popupProps$autoFocus;
@@ -24,7 +27,7 @@ function ProfileCardTrigger({
24
27
  const {
25
28
  profileData,
26
29
  isLoading,
27
- // hasError: Boolean(error) || cannotLoadUser,
30
+ error,
28
31
  getProfileData
29
32
  } = useProfileInfo({
30
33
  fetchUserProfile: fetchProfile
@@ -49,9 +52,12 @@ function ProfileCardTrigger({
49
52
  if (!visible) {
50
53
  await (getProfileData === null || getProfileData === void 0 ? void 0 : getProfileData());
51
54
  setVisible(true);
55
+ if (fireAnalytics) {
56
+ fireAnalytics(cardTriggered(profileCardType, trigger));
57
+ }
52
58
  }
53
59
  }, showDelay);
54
- }, [showDelay, visible, getProfileData]);
60
+ }, [showDelay, visible, getProfileData, fireAnalytics, profileCardType, trigger]);
55
61
  const onMouseEnter = useCallback(() => {
56
62
  showProfilecard();
57
63
  }, [showProfilecard]);
@@ -83,7 +89,8 @@ function ProfileCardTrigger({
83
89
  onFocus: showProfilecard
84
90
  }, renderProfileCard({
85
91
  profileData,
86
- isLoading
92
+ isLoading,
93
+ error
87
94
  }))
88
95
  }));
89
96
  }
@@ -31,7 +31,7 @@ class SimpleMockUserClient extends UserProfileCardClient {
31
31
  }
32
32
  }
33
33
  class SimpleMockAgentClient extends RovoAgentCardClient {
34
- makeRequest(userId) {
34
+ makeRequest(id, cloudId) {
35
35
  return Promise.resolve(agentData);
36
36
  }
37
37
  }
@@ -24,7 +24,7 @@ export const fireEvent = (createAnalyticsEvent, body) => {
24
24
 
25
25
  const TEAM_SUBJECT = 'teamProfileCard';
26
26
  const USER_SUBJECT = 'profilecard';
27
- const RovoAgent = 'rovoAgenrProfilecard';
27
+ const AGENT_SUBJECT = 'rovoAgenrProfilecard';
28
28
  const createEvent = (eventType, action, actionSubject, actionSubjectId, attributes = {}) => ({
29
29
  eventType,
30
30
  action,
@@ -32,14 +32,28 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
32
32
  actionSubjectId,
33
33
  attributes: {
34
34
  packageName: "@atlaskit/profilecard",
35
- packageVersion: "19.18.1",
35
+ packageVersion: "19.19.0",
36
36
  ...attributes,
37
37
  firedAt: Math.round(getPageTime())
38
38
  }
39
39
  });
40
- export const cardTriggered = (type, method) => createEvent('ui', 'triggered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, undefined, {
41
- method
42
- });
40
+ export const cardTriggered = (type, method) => {
41
+ const getActionSubject = type => {
42
+ switch (type) {
43
+ case 'user':
44
+ return USER_SUBJECT;
45
+ case 'team':
46
+ return TEAM_SUBJECT;
47
+ case 'agent':
48
+ return AGENT_SUBJECT;
49
+ default:
50
+ return 'user';
51
+ }
52
+ };
53
+ return createEvent('ui', 'triggered', getActionSubject(type), undefined, {
54
+ method
55
+ });
56
+ };
43
57
  export const teamRequestAnalytics = (action, attributes) => createEvent('operational', action, TEAM_SUBJECT, 'request', attributes);
44
58
  export const userRequestAnalytics = (action, attributes) => createEvent('operational', action, USER_SUBJECT, 'request', attributes);
45
59
  export const profileCardRendered = (type, actionSubjectId, attributes) => createEvent('ui', 'rendered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, actionSubjectId, attributes);
@@ -49,4 +63,4 @@ export const moreActionsClicked = (type, attributes) => createEvent('ui', 'click
49
63
  export const teamAvatarClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'avatar', attributes);
50
64
  export const moreMembersClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'moreMembers', attributes);
51
65
  export const errorRetryClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'errorRetry', attributes);
52
- export const agentRequestAnalytics = (action, attributes) => createEvent('operational', action, RovoAgent, 'request', attributes);
66
+ export const agentRequestAnalytics = (action, attributes) => createEvent('operational', action, AGENT_SUBJECT, 'request', attributes);
@@ -1,3 +1,4 @@
1
+ export const USER_ARI_PREFIX = 'ari:cloud:identity::user/';
1
2
  export const createHeaders = (product, cloudId) => {
2
3
  const config = {
3
4
  headers: {
@@ -11,6 +12,5 @@ export const createHeaders = (product, cloudId) => {
11
12
  });
12
13
  };
13
14
  export const getAAIDFromARI = ari => {
14
- const matched = ari.match(/\/([a-zA-Z0-9_\|\-\:]{1,128})$/);
15
- return matched ? matched[1] : undefined;
15
+ return ari.replace(USER_ARI_PREFIX, '');
16
16
  };
@@ -3,6 +3,7 @@ export const useProfileInfo = ({
3
3
  fetchUserProfile
4
4
  }) => {
5
5
  const [isLoading, setIsLoading] = useState(false);
6
+ const [error, setError] = useState(null);
6
7
  const [profileData, setProfileData] = useState();
7
8
  const getProfileData = async () => {
8
9
  setIsLoading(true);
@@ -11,13 +12,14 @@ export const useProfileInfo = ({
11
12
  setProfileData(profileData);
12
13
  setIsLoading(false);
13
14
  } catch (error) {
15
+ setError(error);
14
16
  setIsLoading(true);
15
17
  }
16
18
  };
17
19
  return {
18
20
  profileData,
19
21
  isLoading,
20
- // hasError: Boolean(error) || cannotLoadUser,
22
+ error,
21
23
  getProfileData
22
24
  };
23
25
  };
@@ -60,9 +60,9 @@ var ProfileCardClient = /*#__PURE__*/function () {
60
60
  }
61
61
  }, {
62
62
  key: "getRovoAgentProfile",
63
- value: function getRovoAgentProfile(agentId, analytics) {
63
+ value: function getRovoAgentProfile(id, analytics) {
64
64
  var _this$rovoAgentClient2;
65
- return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(agentId, analytics);
65
+ return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(id, analytics);
66
66
  }
67
67
  }]);
68
68
  return ProfileCardClient;
@@ -12,7 +12,7 @@ import { agentRequestAnalytics } from '../util/analytics';
12
12
  import { getPageTime } from '../util/performance';
13
13
  import CachingClient from './CachingClient';
14
14
  import { getErrorAttributes } from './errorUtils';
15
- import { getAgentDetailsByAgentId } from './getAgentInfo';
15
+ import { getAgentDetailsByAgentId, getAgentDetailsByUserId } from './getAgentInfo';
16
16
  var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
17
17
  _inherits(RovoAgentCardClient, _CachingClient);
18
18
  var _super = _createSuper(RovoAgentCardClient);
@@ -25,23 +25,26 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
25
25
  }
26
26
  _createClass(RovoAgentCardClient, [{
27
27
  key: "makeRequest",
28
- value: function makeRequest(agentId, cloudId) {
28
+ value: function makeRequest(id, cloudId) {
29
29
  if (!this.options.productIdentifier) {
30
30
  throw new Error('Trying to fetch agents data with no specified config.productIdentifier');
31
31
  }
32
- return getAgentDetailsByAgentId(agentId, this.options.productIdentifier, cloudId);
32
+ if (id.type === 'identity') {
33
+ return getAgentDetailsByUserId(id.value, this.options.productIdentifier, cloudId);
34
+ }
35
+ return getAgentDetailsByAgentId(id.value, this.options.productIdentifier, cloudId);
33
36
  }
34
37
  }, {
35
38
  key: "getProfile",
36
- value: function getProfile(agentId, analytics) {
39
+ value: function getProfile(id, analytics) {
37
40
  var _this2 = this;
38
- if (!agentId) {
39
- return Promise.reject(new Error('agentId is missing'));
41
+ if (!id.value) {
42
+ return Promise.reject(new Error('IF is missing'));
40
43
  }
41
44
  if (!this.options.cloudId) {
42
45
  return Promise.reject(new Error('cloudId is missing'));
43
46
  }
44
- var cache = this.getCachedProfile(agentId);
47
+ var cache = this.getCachedProfile(id.value);
45
48
  if (cache) {
46
49
  return Promise.resolve(cache);
47
50
  }
@@ -50,9 +53,9 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
50
53
  if (analytics) {
51
54
  analytics(agentRequestAnalytics('triggered'));
52
55
  }
53
- _this2.makeRequest(agentId, _this2.options.cloudId || '').then(function (data) {
56
+ _this2.makeRequest(id, _this2.options.cloudId || '').then(function (data) {
54
57
  if (_this2.cache) {
55
- _this2.setCachedProfile(agentId, data);
58
+ _this2.setCachedProfile(id.value, data);
56
59
  }
57
60
  if (analytics) {
58
61
  analytics(agentRequestAnalytics('succeeded', {