@backstage/core-app-api 1.2.1-next.2 → 1.2.1-next.3

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,17 @@
1
1
  # @backstage/core-app-api
2
2
 
3
+ ## 1.2.1-next.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 6870b43dd1: Fix for the automatic rewriting of base URLs.
8
+ - 653d7912ac: Made `WebStorage` notify its subscribers when `localStorage` values change in other tabs/windows
9
+ - Updated dependencies
10
+ - @backstage/config@1.0.5-next.1
11
+ - @backstage/core-plugin-api@1.2.0-next.2
12
+ - @backstage/types@1.0.2-next.1
13
+ - @backstage/version-bridge@1.0.3-next.0
14
+
3
15
  ## 1.2.1-next.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -535,16 +535,19 @@ declare class WebStorage implements StorageApi {
535
535
  private readonly namespace;
536
536
  private readonly errorApi;
537
537
  constructor(namespace: string, errorApi: ErrorApi);
538
+ private static hasSubscribed;
538
539
  static create(options: {
539
540
  errorApi: ErrorApi;
540
541
  namespace?: string;
541
542
  }): WebStorage;
543
+ private static addStorageEventListener;
542
544
  get<T>(key: string): T | undefined;
543
545
  snapshot<T extends JsonValue>(key: string): StorageValueSnapshot<T>;
544
546
  forBucket(name: string): WebStorage;
545
547
  set<T>(key: string, data: T): Promise<void>;
546
548
  remove(key: string): Promise<void>;
547
549
  observe$<T extends JsonValue>(key: string): Observable<StorageValueSnapshot<T>>;
550
+ private handleStorageChange;
548
551
  private getKeyName;
549
552
  private notifyChanges;
550
553
  private subscribers;
package/dist/index.esm.js CHANGED
@@ -1613,7 +1613,7 @@ class OAuthRequestManager {
1613
1613
  }
1614
1614
 
1615
1615
  const buckets = /* @__PURE__ */ new Map();
1616
- class WebStorage {
1616
+ const _WebStorage = class {
1617
1617
  constructor(namespace, errorApi) {
1618
1618
  this.namespace = namespace;
1619
1619
  this.errorApi = errorApi;
@@ -1627,7 +1627,17 @@ class WebStorage {
1627
1627
  }
1628
1628
  static create(options) {
1629
1629
  var _a;
1630
- return new WebStorage((_a = options.namespace) != null ? _a : "", options.errorApi);
1630
+ return new _WebStorage((_a = options.namespace) != null ? _a : "", options.errorApi);
1631
+ }
1632
+ static addStorageEventListener() {
1633
+ window.addEventListener("storage", (event) => {
1634
+ var _a;
1635
+ for (const [bucketPath, webStorage] of buckets.entries()) {
1636
+ if ((_a = event.key) == null ? void 0 : _a.startsWith(bucketPath)) {
1637
+ webStorage.handleStorageChange(event.key);
1638
+ }
1639
+ }
1640
+ });
1631
1641
  }
1632
1642
  get(key) {
1633
1643
  return this.snapshot(key).value;
@@ -1656,7 +1666,7 @@ class WebStorage {
1656
1666
  forBucket(name) {
1657
1667
  const bucketPath = `${this.namespace}/${name}`;
1658
1668
  if (!buckets.has(bucketPath)) {
1659
- buckets.set(bucketPath, new WebStorage(bucketPath, this.errorApi));
1669
+ buckets.set(bucketPath, new _WebStorage(bucketPath, this.errorApi));
1660
1670
  }
1661
1671
  return buckets.get(bucketPath);
1662
1672
  }
@@ -1669,8 +1679,21 @@ class WebStorage {
1669
1679
  this.notifyChanges(key);
1670
1680
  }
1671
1681
  observe$(key) {
1682
+ if (!_WebStorage.hasSubscribed) {
1683
+ _WebStorage.addStorageEventListener();
1684
+ _WebStorage.hasSubscribed = true;
1685
+ }
1672
1686
  return this.observable.filter(({ key: messageKey }) => messageKey === key);
1673
1687
  }
1688
+ handleStorageChange(eventKey) {
1689
+ if (!(eventKey == null ? void 0 : eventKey.startsWith(this.namespace))) {
1690
+ return;
1691
+ }
1692
+ const trimmedKey = eventKey == null ? void 0 : eventKey.slice(`${this.namespace}/`.length);
1693
+ if (!trimmedKey.includes("/")) {
1694
+ this.notifyChanges(decodeURIComponent(trimmedKey));
1695
+ }
1696
+ }
1674
1697
  getKeyName(key) {
1675
1698
  return `${this.namespace}/${encodeURIComponent(key)}`;
1676
1699
  }
@@ -1680,7 +1703,9 @@ class WebStorage {
1680
1703
  subscription.next(snapshot);
1681
1704
  }
1682
1705
  }
1683
- }
1706
+ };
1707
+ let WebStorage = _WebStorage;
1708
+ WebStorage.hasSubscribed = false;
1684
1709
 
1685
1710
  function traverseElementTree(options) {
1686
1711
  const collectors = {};
@@ -2540,7 +2565,7 @@ function useConfigLoader(configLoader, components, appThemeApi) {
2540
2565
  return new URL(
2541
2566
  fullUrl.replace(getOrigin(fullUrl), ""),
2542
2567
  document.location.origin
2543
- ).href;
2568
+ ).href.replace(/\/$/, "");
2544
2569
  };
2545
2570
  const appBaseUrl = urlConfigReader.getOptionalString("app.baseUrl");
2546
2571
  const backendBaseUrl = urlConfigReader.getOptionalString("backend.baseUrl");
@@ -2553,15 +2578,17 @@ function useConfigLoader(configLoader, components, appThemeApi) {
2553
2578
  const appOrigin = getOrigin(appBaseUrl);
2554
2579
  const backendOrigin = getOrigin(backendBaseUrl);
2555
2580
  if (appOrigin === backendOrigin) {
2556
- relativeResolverConfig.data.backend = {
2557
- baseUrl: overrideOrigin(backendBaseUrl)
2558
- };
2581
+ const newBackendBaseUrl = overrideOrigin(backendBaseUrl);
2582
+ if (backendBaseUrl !== newBackendBaseUrl) {
2583
+ relativeResolverConfig.data.backend = { baseUrl: newBackendBaseUrl };
2584
+ }
2559
2585
  }
2560
2586
  }
2561
2587
  if (appBaseUrl) {
2562
- relativeResolverConfig.data.app = {
2563
- baseUrl: overrideOrigin(appBaseUrl)
2564
- };
2588
+ const newAppBaseUrl = overrideOrigin(appBaseUrl);
2589
+ if (appBaseUrl !== newAppBaseUrl) {
2590
+ relativeResolverConfig.data.app = { baseUrl: newAppBaseUrl };
2591
+ }
2565
2592
  }
2566
2593
  if (Object.keys(relativeResolverConfig.data).length) {
2567
2594
  configs = configs.concat([relativeResolverConfig]);