@hipnation-truth/sdk 0.26.1 → 0.26.2

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/react.d.ts CHANGED
@@ -2680,12 +2680,21 @@ declare class TruthClient {
2680
2680
  readonly userSettings: UserSettingsResource;
2681
2681
  private readonly convex;
2682
2682
  private readonly tracker;
2683
+ private readonly _getAuthToken?;
2683
2684
  private _vapidPublicKey;
2684
2685
  private _webPushReady;
2685
2686
  private readonly _serviceWorkerPath;
2686
2687
  constructor(config: TruthClientConfig);
2687
2688
  get vapidPublicKey(): string | null;
2688
2689
  get webPushReady(): Promise<void> | null;
2690
+ /**
2691
+ * When a Clerk token fetcher is configured (publishable-key clients),
2692
+ * the VAPID endpoint is auth-gated — calling it before the session has
2693
+ * hydrated 401s and strands web-push in the "no key" path. Wait
2694
+ * (briefly, bounded) for a token to become available first. No fetcher
2695
+ * → resolve immediately (secret-key path is unaffected).
2696
+ */
2697
+ private waitForAuthToken;
2689
2698
  private initWebPush;
2690
2699
  /**
2691
2700
  * The resolved Truth API base URL for this environment.
package/dist/react.js CHANGED
@@ -2240,6 +2240,7 @@ var TruthClient = class {
2240
2240
  config.getAuthToken
2241
2241
  );
2242
2242
  this.userSettings = new UserSettingsResource(this.convex);
2243
+ this._getAuthToken = config.getAuthToken;
2243
2244
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
2244
2245
  if (typeof window !== "undefined" && isWebPushSupported() && config.autoInitServiceWorker !== false) {
2245
2246
  this._webPushReady = this.initWebPush();
@@ -2251,9 +2252,33 @@ var TruthClient = class {
2251
2252
  get webPushReady() {
2252
2253
  return this._webPushReady;
2253
2254
  }
2255
+ /**
2256
+ * When a Clerk token fetcher is configured (publishable-key clients),
2257
+ * the VAPID endpoint is auth-gated — calling it before the session has
2258
+ * hydrated 401s and strands web-push in the "no key" path. Wait
2259
+ * (briefly, bounded) for a token to become available first. No fetcher
2260
+ * → resolve immediately (secret-key path is unaffected).
2261
+ */
2262
+ waitForAuthToken() {
2263
+ return __async(this, null, function* () {
2264
+ if (!this._getAuthToken) {
2265
+ return;
2266
+ }
2267
+ for (let attempt = 0; attempt < 20; attempt++) {
2268
+ try {
2269
+ if (yield this._getAuthToken()) {
2270
+ return;
2271
+ }
2272
+ } catch (e) {
2273
+ }
2274
+ yield new Promise((resolve) => setTimeout(resolve, 500));
2275
+ }
2276
+ });
2277
+ }
2254
2278
  initWebPush() {
2255
2279
  return __async(this, null, function* () {
2256
2280
  try {
2281
+ yield this.waitForAuthToken();
2257
2282
  const key = yield this.notifications.getVapidKey();
2258
2283
  if (!key) {
2259
2284
  return;