@hipnation-truth/sdk 0.26.1 → 0.26.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/dist/index.mjs CHANGED
@@ -1917,6 +1917,7 @@ var TruthClient = class {
1917
1917
  config.getAuthToken
1918
1918
  );
1919
1919
  this.userSettings = new UserSettingsResource(this.convex);
1920
+ this._getAuthToken = config.getAuthToken;
1920
1921
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
1921
1922
  if (typeof window !== "undefined" && isWebPushSupported() && config.autoInitServiceWorker !== false) {
1922
1923
  this._webPushReady = this.initWebPush();
@@ -1928,9 +1929,33 @@ var TruthClient = class {
1928
1929
  get webPushReady() {
1929
1930
  return this._webPushReady;
1930
1931
  }
1932
+ /**
1933
+ * When a Clerk token fetcher is configured (publishable-key clients),
1934
+ * the VAPID endpoint is auth-gated — calling it before the session has
1935
+ * hydrated 401s and strands web-push in the "no key" path. Wait
1936
+ * (briefly, bounded) for a token to become available first. No fetcher
1937
+ * → resolve immediately (secret-key path is unaffected).
1938
+ */
1939
+ waitForAuthToken() {
1940
+ return __async(this, null, function* () {
1941
+ if (!this._getAuthToken) {
1942
+ return;
1943
+ }
1944
+ for (let attempt = 0; attempt < 20; attempt++) {
1945
+ try {
1946
+ if (yield this._getAuthToken()) {
1947
+ return;
1948
+ }
1949
+ } catch (e) {
1950
+ }
1951
+ yield new Promise((resolve) => setTimeout(resolve, 500));
1952
+ }
1953
+ });
1954
+ }
1931
1955
  initWebPush() {
1932
1956
  return __async(this, null, function* () {
1933
1957
  try {
1958
+ yield this.waitForAuthToken();
1934
1959
  const key = yield this.notifications.getVapidKey();
1935
1960
  if (!key) {
1936
1961
  return;