@salesforcedevs/dx-components 1.2.7-avatar-button-3 → 1.2.7-avatar-button-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "1.2.7-avatar-button-3",
3
+ "version": "1.2.7-avatar-button-5",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -97,7 +97,7 @@
97
97
  <span class="login-section-title">Products</span>
98
98
  <ul>
99
99
  <li class="login-list-item">
100
- <a href="#" class="login-link" target="_blank">
100
+ <a href="https://www.salesforce.com" class="login-link" target="_blank">
101
101
  <span class="login-link-label">
102
102
  Salesforce
103
103
  </span>
@@ -114,7 +114,7 @@
114
114
  </a>
115
115
  </li>
116
116
  <li class="login-list-item">
117
- <a href="#" class="login-link" target="_blank">
117
+ <a href={marketingCloudUrl} class="login-link" target="_blank">
118
118
  <span class="login-link-label">
119
119
  Marketing Cloud
120
120
  </span>
@@ -145,7 +145,7 @@
145
145
  </div>
146
146
  </li>
147
147
  <li class="login-list-item">
148
- <a href="#" class="login-link" target="_blank">
148
+ <a href="https://developer.salesforce.com/forums" class="login-link" target="_blank">
149
149
  <span class="login-link-label">
150
150
  Developer Forums
151
151
  </span>
@@ -20,6 +20,8 @@ const TBID_API_LOGIN_URL = `${TBID_API_BASE_URL}/dologin`;
20
20
  const TBID_API_TOKEN_URL = `${TBID_API_BASE_URL}/token`;
21
21
  const TBID_API_PLATFORM_EVENTS_URL = `${TBID_API_BASE_URL}/platform-events`;
22
22
 
23
+ const DSC_BASE_URL = process.env.BASE_URL || "https://developer.salesforce.com";
24
+
23
25
  declare global {
24
26
  interface Window {
25
27
  SFIDWidget?: {
@@ -73,9 +75,12 @@ export default class AvatarButton extends LightningElement {
73
75
  private settingsUrl = TBID_SETTINGS_URL;
74
76
  private profileUrl = TBID_PROFILE_URL;
75
77
  private eventSource?: EventSource;
76
- private _hasRendered = false;
77
78
  private _didReceiveUserInfo = false;
78
79
 
80
+ private get marketingCloudUrl() {
81
+ return `${DSC_BASE_URL}/developer-centers/marketing-cloud`;
82
+ }
83
+
79
84
  private get loginUrl() {
80
85
  return `${TBID_API_LOGIN_URL}?startUrl=${encodeURIComponent(
81
86
  window.location.href
@@ -108,9 +113,12 @@ export default class AvatarButton extends LightningElement {
108
113
  // user info immediately. The check prevents duplicate requests.
109
114
  if (
110
115
  this.isLoading &&
111
- (!window.SFIDWidget || (!isWidgetDisabled && !isWidgetLoggedIn)) &&
116
+ !isWidgetDisabled &&
117
+ !isWidgetLoggedIn &&
112
118
  document.querySelector('script[src*="authProviderEmbeddedLogin"]')
113
119
  ) {
120
+ // Try to give SFIDWidget time to update any tokens it may have access to before
121
+ // completing initiation. It has 1 second maximum.
114
122
  setTimeout(() => {
115
123
  if (!window.SFIDWidget?.openid_response) {
116
124
  // SFIDWidget not responding in time; handle login ourselves.
@@ -119,6 +127,7 @@ export default class AvatarButton extends LightningElement {
119
127
  }
120
128
  }, 1000);
121
129
  } else {
130
+ // No SFIDWidget, proceed to normal initiation.
122
131
  if (this.isLoading) {
123
132
  // This is a successful login; track it.
124
133
  this.trackLoginSuccess();
@@ -227,41 +236,37 @@ export default class AvatarButton extends LightningElement {
227
236
  private handleSsoLogin = async (event: Event) => {
228
237
  const { userInfo } = (event as CustomEvent).detail;
229
238
  const token = userInfo?.access_token;
230
- const isAlreadyLoading = this.isLoading;
231
239
 
232
240
  // `token` should always be defined if an SSO login occurs, but we check for extra safety
233
- if (token) {
234
- this.isLoading = true;
235
-
236
- // If an SSO login occurred and we have an SSO access token, we want to start using
237
- // it rather than some other non-linked access token, for the "seamless SSO"
238
- // experience
239
- try {
240
- const tokenResponse = await fetch(TBID_API_TOKEN_URL, {
241
- method: "POST",
242
- headers: {
243
- "Content-Type": "application/json"
244
- },
245
- body: JSON.stringify({
246
- token
247
- })
248
- });
249
- if (tokenResponse.ok) {
250
- this.platformEventsSubscribe();
251
- this.trackLoginSuccess();
252
- }
253
- } catch (ex) {
254
- console.error(`Attempt to update token failed: ${ex}`);
255
- }
241
+ if (!token) {
242
+ return;
256
243
  }
257
244
 
258
- if (userInfo && !isAlreadyLoading) {
259
- // TODO: This sucks and we will have to raise an issue with the TBID team, but for some reason the
260
- // SSO login userInfo payload is missing photos for the user, so we have to re-request it on login.
261
- this.requestUserInfo();
262
- }
245
+ // If an SSO login occurred and we have an SSO access token, we want to start using
246
+ // it rather than some other non-linked access token, for the "seamless SSO"
247
+ // experience
248
+ try {
249
+ const tokenResponse = await fetch(TBID_API_TOKEN_URL, {
250
+ method: "POST",
251
+ headers: {
252
+ "Content-Type": "application/json"
253
+ },
254
+ body: JSON.stringify({
255
+ token
256
+ })
257
+ });
263
258
 
264
- this.isLoading = false;
259
+ if (tokenResponse.ok) {
260
+ this.platformEventsSubscribe();
261
+ this.trackLoginSuccess();
262
+ // TODO: This sucks and we will have to raise an issue with the TBID team, but for some reason the
263
+ // SSO login userInfo payload is missing photos for the user, so we have to re-request it on login.
264
+ // We only want to do this if we aren't already requesting it, of course.
265
+ this.requestUserInfo();
266
+ }
267
+ } catch (ex) {
268
+ console.error(`Attempt to update token failed: ${ex}`);
269
+ }
265
270
  };
266
271
 
267
272
  private handleComponentLogin = (event: MouseEvent) => {