@hook-sdk/template 0.7.0 → 0.7.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/index.d.cts CHANGED
@@ -603,4 +603,4 @@ declare function shouldBlockInstall(state: InstallState, now?: number): boolean;
603
603
  */
604
604
  declare function shouldShowPermanentOption(state: InstallState): boolean;
605
605
 
606
- export { type AndroidBrowser, AppRoot, type AppRootProps, type AuthFormError, type AuthFormErrorCode, type AuthScreen, type AuthScreenProps, DefaultForgotScreen, DefaultLoginScreen, DefaultPaywall, DefaultResetScreen, DefaultSignupScreen, EmptyState, ErrorBoundary, type IOSBrowser, type InAppApp, type InstallActions, InstallGate, InstallSplash, type InstallState, type InstallVariant, LoadingState, type Platform, PushPrompt, type PushPromptProps, type PushPromptTexts, type PushUiState, type SubscriptionStatus, type ToastItem, type UseLoginFormResult, type UseResetFormResult, computeAnchorCents, dailyFromYearly, detectAndroidBrowser, detectIOSBrowser, detectInAppApp, detectPlatform, detectStandalone, discountPercent, formatBRL, monthlyFromYearly, shouldBlockInstall, shouldShowPermanentOption, useAuth, useAuthPrimitives, useForgotForm, useInstallPrompt, useLoginForm, usePaywallState, usePlan, usePush, useReminders, useResetForm, useSignupForm, useSubscription, useToast };
606
+ export { type AndroidBrowser, AppRoot, type AppRootProps, type AuthFormError, type AuthFormErrorCode, type AuthScreen, type AuthScreenProps, DefaultForgotScreen, DefaultLoginScreen, DefaultPaywall, DefaultResetScreen, DefaultSignupScreen, EmptyState, ErrorBoundary, type IOSBrowser, type InAppApp, type InstallActions, InstallGate, InstallSplash, type InstallState, type InstallVariant, LoadingState, type PaymentMethod, type PixPending, type Platform, PushPrompt, type PushPromptProps, type PushPromptTexts, type PushUiState, type SubscriptionStatus, type ToastItem, type UseLoginFormResult, type UseResetFormResult, computeAnchorCents, dailyFromYearly, detectAndroidBrowser, detectIOSBrowser, detectInAppApp, detectPlatform, detectStandalone, discountPercent, formatBRL, monthlyFromYearly, shouldBlockInstall, shouldShowPermanentOption, useAuth, useAuthPrimitives, useForgotForm, useInstallPrompt, useLoginForm, usePaywallState, usePlan, usePush, useReminders, useResetForm, useSignupForm, useSubscription, useToast };
package/dist/index.d.ts CHANGED
@@ -603,4 +603,4 @@ declare function shouldBlockInstall(state: InstallState, now?: number): boolean;
603
603
  */
604
604
  declare function shouldShowPermanentOption(state: InstallState): boolean;
605
605
 
606
- export { type AndroidBrowser, AppRoot, type AppRootProps, type AuthFormError, type AuthFormErrorCode, type AuthScreen, type AuthScreenProps, DefaultForgotScreen, DefaultLoginScreen, DefaultPaywall, DefaultResetScreen, DefaultSignupScreen, EmptyState, ErrorBoundary, type IOSBrowser, type InAppApp, type InstallActions, InstallGate, InstallSplash, type InstallState, type InstallVariant, LoadingState, type Platform, PushPrompt, type PushPromptProps, type PushPromptTexts, type PushUiState, type SubscriptionStatus, type ToastItem, type UseLoginFormResult, type UseResetFormResult, computeAnchorCents, dailyFromYearly, detectAndroidBrowser, detectIOSBrowser, detectInAppApp, detectPlatform, detectStandalone, discountPercent, formatBRL, monthlyFromYearly, shouldBlockInstall, shouldShowPermanentOption, useAuth, useAuthPrimitives, useForgotForm, useInstallPrompt, useLoginForm, usePaywallState, usePlan, usePush, useReminders, useResetForm, useSignupForm, useSubscription, useToast };
606
+ export { type AndroidBrowser, AppRoot, type AppRootProps, type AuthFormError, type AuthFormErrorCode, type AuthScreen, type AuthScreenProps, DefaultForgotScreen, DefaultLoginScreen, DefaultPaywall, DefaultResetScreen, DefaultSignupScreen, EmptyState, ErrorBoundary, type IOSBrowser, type InAppApp, type InstallActions, InstallGate, InstallSplash, type InstallState, type InstallVariant, LoadingState, type PaymentMethod, type PixPending, type Platform, PushPrompt, type PushPromptProps, type PushPromptTexts, type PushUiState, type SubscriptionStatus, type ToastItem, type UseLoginFormResult, type UseResetFormResult, computeAnchorCents, dailyFromYearly, detectAndroidBrowser, detectIOSBrowser, detectInAppApp, detectPlatform, detectStandalone, discountPercent, formatBRL, monthlyFromYearly, shouldBlockInstall, shouldShowPermanentOption, useAuth, useAuthPrimitives, useForgotForm, useInstallPrompt, useLoginForm, usePaywallState, usePlan, usePush, useReminders, useResetForm, useSignupForm, useSubscription, useToast };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/AppRoot.tsx
2
- import { useCallback as useCallback7, useEffect as useEffect7, useRef as useRef2, useState as useState11 } from "react";
2
+ import { useCallback as useCallback7, useEffect as useEffect8, useRef as useRef3, useState as useState11 } from "react";
3
3
  import { useHook as useHook8 } from "@hook-sdk/sdk";
4
4
 
5
5
  // src/internal/TemplateConfigContext.tsx
@@ -92,7 +92,7 @@ function AuthGate({ Login, Signup, Forgot, Reset, children }) {
92
92
  }
93
93
 
94
94
  // src/hooks/usePaywallState.ts
95
- import { useCallback, useState as useState2 } from "react";
95
+ import { useCallback, useEffect as useEffect2, useRef, useState as useState2 } from "react";
96
96
  import { useHook as useHook2 } from "@hook-sdk/sdk";
97
97
  function usePaywallState() {
98
98
  const { subscription } = useHook2();
@@ -153,6 +153,33 @@ function usePaywallState() {
153
153
  }
154
154
  }, [subscription]);
155
155
  const dismissPix = useCallback(() => setPixPending(null), []);
156
+ const subRef = useRef(subscription);
157
+ subRef.current = subscription;
158
+ useEffect2(() => {
159
+ if (!pixPending) return;
160
+ let attempts = 0;
161
+ const MAX_ATTEMPTS = 60;
162
+ let cancelled = false;
163
+ const tick = async () => {
164
+ if (cancelled || attempts >= MAX_ATTEMPTS) return;
165
+ attempts++;
166
+ try {
167
+ await subRef.current.refresh();
168
+ if (cancelled) return;
169
+ const s = subRef.current.status();
170
+ if (s === "active" || s === "trialing") {
171
+ setPixPending(null);
172
+ return;
173
+ }
174
+ } catch {
175
+ }
176
+ if (!cancelled) setTimeout(tick, 3e3);
177
+ };
178
+ setTimeout(tick, 3e3);
179
+ return () => {
180
+ cancelled = true;
181
+ };
182
+ }, [pixPending]);
156
183
  return {
157
184
  status,
158
185
  daysLeftInTrial,
@@ -184,13 +211,13 @@ function SubscriptionGate({ Paywall, children }) {
184
211
  }
185
212
 
186
213
  // src/internal/PersistedKeysPrefetch.tsx
187
- import { useEffect as useEffect2 } from "react";
214
+ import { useEffect as useEffect3 } from "react";
188
215
  import { useHook as useHook3 } from "@hook-sdk/sdk";
189
216
  import { Fragment as Fragment3, jsx as jsx6 } from "react/jsx-runtime";
190
217
  function PersistedKeysPrefetch({ children }) {
191
218
  const { appData } = useHook3();
192
219
  const config = useTemplateConfig();
193
- useEffect2(() => {
220
+ useEffect3(() => {
194
221
  const keys = config.persistedKeys;
195
222
  if (!keys || keys.length === 0) return;
196
223
  appData.cache.startPrefetch(keys, (ks) => appData.bulkRead(ks));
@@ -204,10 +231,10 @@ function PushPrompt() {
204
231
  }
205
232
 
206
233
  // src/components/InstallGate/InstallGate.tsx
207
- import { useEffect as useEffect4, useRef } from "react";
234
+ import { useEffect as useEffect5, useRef as useRef2 } from "react";
208
235
 
209
236
  // src/hooks/useInstallPrompt.ts
210
- import { useCallback as useCallback2, useEffect as useEffect3, useState as useState3 } from "react";
237
+ import { useCallback as useCallback2, useEffect as useEffect4, useState as useState3 } from "react";
211
238
  var IOS_RE = /iPad|iPhone|iPod/;
212
239
  var IOS_NON_SAFARI_RE = /CriOS|FxiOS|EdgiOS/;
213
240
  var ANDROID_RE = /Android/;
@@ -351,7 +378,7 @@ function useInstallPrompt(slug) {
351
378
  const [isDismissedSession, setIsDismissedSession] = useState3(() => readSessionSkip(slug));
352
379
  const [isDismissedPermanent, setIsDismissedPermanent] = useState3(() => readPermanentDismiss(slug).dismissed);
353
380
  const [skipCount, setSkipCount] = useState3(() => readSkipCount(slug));
354
- useEffect3(() => {
381
+ useEffect4(() => {
355
382
  if (typeof window === "undefined") return;
356
383
  if (window.__pwaInstallPrompt) {
357
384
  setIsInstallable(true);
@@ -375,7 +402,7 @@ function useInstallPrompt(slug) {
375
402
  window.removeEventListener("appinstalled", onInstalled);
376
403
  };
377
404
  }, [slug]);
378
- useEffect3(() => {
405
+ useEffect4(() => {
379
406
  if (typeof window === "undefined") return;
380
407
  const mq = window.matchMedia?.("(display-mode: standalone)");
381
408
  if (!mq) return;
@@ -1420,8 +1447,8 @@ function InstallGate({ children }) {
1420
1447
  const enabled = features_enabled.includes("install_prompt");
1421
1448
  const installState = useInstallPrompt(slug);
1422
1449
  const shouldBlock = enabled && shouldBlockInstall(installState);
1423
- const trackedRef = useRef(null);
1424
- useEffect4(() => {
1450
+ const trackedRef = useRef2(null);
1451
+ useEffect5(() => {
1425
1452
  if (!shouldBlock) return;
1426
1453
  if (typeof window === "undefined") return;
1427
1454
  const variantKey = `${slug}:${installState.variant}`;
@@ -1635,7 +1662,7 @@ function GoogleGlyph() {
1635
1662
  }
1636
1663
 
1637
1664
  // src/internal/OAuthErrorBanner.tsx
1638
- import { useEffect as useEffect5, useState as useState6 } from "react";
1665
+ import { useEffect as useEffect6, useState as useState6 } from "react";
1639
1666
  import { jsx as jsx19, jsxs as jsxs13 } from "react/jsx-runtime";
1640
1667
  var ERROR_MESSAGES = {
1641
1668
  invalid_state: "Sess\xE3o expirou, tente de novo.",
@@ -1657,7 +1684,7 @@ function stripErrorFromUrl() {
1657
1684
  }
1658
1685
  function OAuthErrorBanner() {
1659
1686
  const [code, setCode] = useState6(() => readErrorCode());
1660
- useEffect5(() => {
1687
+ useEffect6(() => {
1661
1688
  if (code !== null) stripErrorFromUrl();
1662
1689
  }, [code]);
1663
1690
  if (!code) return null;
@@ -1979,7 +2006,7 @@ function DefaultForgotScreen({ onNavigate }) {
1979
2006
  }
1980
2007
 
1981
2008
  // src/hooks/useResetForm.ts
1982
- import { useCallback as useCallback6, useEffect as useEffect6, useMemo as useMemo5, useState as useState9 } from "react";
2009
+ import { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo5, useState as useState9 } from "react";
1983
2010
  import { useHook as useHook7 } from "@hook-sdk/sdk";
1984
2011
  var MIN_PASSWORD3 = 12;
1985
2012
  function useResetForm() {
@@ -1990,7 +2017,7 @@ function useResetForm() {
1990
2017
  const [submitting, setSubmitting] = useState9(false);
1991
2018
  const [done, setDone] = useState9(false);
1992
2019
  const [error, setError] = useState9(null);
1993
- useEffect6(() => {
2020
+ useEffect7(() => {
1994
2021
  if (typeof window === "undefined") return;
1995
2022
  const params = new URLSearchParams(window.location.search);
1996
2023
  const t = params.get("token");
@@ -2148,9 +2175,9 @@ import { Fragment as Fragment6, jsx as jsx25, jsxs as jsxs19 } from "react/jsx-r
2148
2175
  var BACKOFF_MS = [2e3, 5e3, 1e4, 2e4, 4e4];
2149
2176
  function PaymentReturnHandler({ children }) {
2150
2177
  const { subscription } = useHook8();
2151
- const subRef = useRef2(subscription);
2178
+ const subRef = useRef3(subscription);
2152
2179
  subRef.current = subscription;
2153
- const runIdRef = useRef2(0);
2180
+ const runIdRef = useRef3(0);
2154
2181
  const [state, setState] = useState11("idle");
2155
2182
  const runPoll = useCallback7(() => {
2156
2183
  const runId = ++runIdRef.current;
@@ -2181,7 +2208,7 @@ function PaymentReturnHandler({ children }) {
2181
2208
  };
2182
2209
  void tick();
2183
2210
  }, []);
2184
- useEffect7(() => {
2211
+ useEffect8(() => {
2185
2212
  if (typeof window === "undefined") return;
2186
2213
  const url = new URL(window.location.href);
2187
2214
  if (url.searchParams.get("paymentReturn") !== "1") return;
@@ -2255,7 +2282,7 @@ function AppRoot({
2255
2282
  }
2256
2283
 
2257
2284
  // src/hooks/usePush.ts
2258
- import { useCallback as useCallback8, useEffect as useEffect8, useState as useState12 } from "react";
2285
+ import { useCallback as useCallback8, useEffect as useEffect9, useState as useState12 } from "react";
2259
2286
  import { useHook as useHook9 } from "@hook-sdk/sdk";
2260
2287
  function detectIosNeedsInstall() {
2261
2288
  if (typeof navigator === "undefined" || typeof window === "undefined") return false;
@@ -2284,7 +2311,7 @@ function deriveState(push) {
2284
2311
  function usePush() {
2285
2312
  const { push } = useHook9();
2286
2313
  const [state, setState] = useState12(() => deriveState(push));
2287
- useEffect8(() => {
2314
+ useEffect9(() => {
2288
2315
  setState(deriveState(push));
2289
2316
  }, [push]);
2290
2317
  const subscribe = useCallback8(async () => {
@@ -2400,12 +2427,12 @@ function discountPercent(anchorCents, realCents) {
2400
2427
  }
2401
2428
 
2402
2429
  // src/hooks/useAuthPrimitives.ts
2403
- import { useEffect as useEffect9 } from "react";
2430
+ import { useEffect as useEffect10 } from "react";
2404
2431
  import { useHook as useHook11 } from "@hook-sdk/sdk";
2405
2432
  var warned = false;
2406
2433
  function useAuthPrimitives() {
2407
2434
  const { auth } = useHook11();
2408
- useEffect9(() => {
2435
+ useEffect10(() => {
2409
2436
  if (!warned && process.env.NODE_ENV !== "production") {
2410
2437
  warned = true;
2411
2438
  console.warn(
@@ -2436,7 +2463,7 @@ function useSubscription() {
2436
2463
  }
2437
2464
 
2438
2465
  // src/hooks/useReminders.ts
2439
- import { useCallback as useCallback9, useEffect as useEffect10, useState as useState13 } from "react";
2466
+ import { useCallback as useCallback9, useEffect as useEffect11, useState as useState13 } from "react";
2440
2467
  import { useHook as useHook13 } from "@hook-sdk/sdk";
2441
2468
  function useReminders() {
2442
2469
  const { push } = useHook13();
@@ -2452,7 +2479,7 @@ function useReminders() {
2452
2479
  setLoading(false);
2453
2480
  }
2454
2481
  }, [r]);
2455
- useEffect10(() => {
2482
+ useEffect11(() => {
2456
2483
  void reload();
2457
2484
  }, [reload]);
2458
2485
  const setReminder = useCallback9(async (input) => {