@hook-sdk/template 0.4.2 → 0.6.0
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.cjs +43 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +64 -2
- package/dist/index.d.ts +64 -2
- package/dist/index.js +39 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,14 @@ __export(index_exports, {
|
|
|
32
32
|
InstallSplash: () => InstallSplash,
|
|
33
33
|
LoadingState: () => LoadingState,
|
|
34
34
|
PushPrompt: () => PushPrompt2,
|
|
35
|
+
dailyFromYearly: () => dailyFromYearly,
|
|
35
36
|
detectAndroidBrowser: () => detectAndroidBrowser,
|
|
36
37
|
detectIOSBrowser: () => detectIOSBrowser,
|
|
37
38
|
detectInAppApp: () => detectInAppApp,
|
|
38
39
|
detectPlatform: () => detectPlatform,
|
|
39
40
|
detectStandalone: () => detectStandalone,
|
|
41
|
+
formatBRL: () => formatBRL,
|
|
42
|
+
monthlyFromYearly: () => monthlyFromYearly,
|
|
40
43
|
shouldBlockInstall: () => shouldBlockInstall,
|
|
41
44
|
shouldShowPermanentOption: () => shouldShowPermanentOption,
|
|
42
45
|
useAuth: () => useAuth,
|
|
@@ -45,6 +48,7 @@ __export(index_exports, {
|
|
|
45
48
|
useInstallPrompt: () => useInstallPrompt,
|
|
46
49
|
useLoginForm: () => useLoginForm,
|
|
47
50
|
usePaywallState: () => usePaywallState,
|
|
51
|
+
usePlan: () => usePlan,
|
|
48
52
|
usePush: () => usePush,
|
|
49
53
|
useReminders: () => useReminders,
|
|
50
54
|
useResetForm: () => useResetForm,
|
|
@@ -156,6 +160,7 @@ function usePaywallState() {
|
|
|
156
160
|
const [error, setError] = (0, import_react3.useState)(null);
|
|
157
161
|
const status = subscription.status();
|
|
158
162
|
const daysLeftInTrial = subscription.daysLeftInTrial();
|
|
163
|
+
const initialLoadComplete = subscription.initialLoadComplete;
|
|
159
164
|
const checkout = (0, import_react3.useCallback)(
|
|
160
165
|
async (args) => {
|
|
161
166
|
setOpening(true);
|
|
@@ -181,7 +186,7 @@ function usePaywallState() {
|
|
|
181
186
|
setError(err);
|
|
182
187
|
}
|
|
183
188
|
}, [subscription]);
|
|
184
|
-
return { status, daysLeftInTrial, checkout, cancel, opening, error };
|
|
189
|
+
return { status, daysLeftInTrial, initialLoadComplete, checkout, cancel, opening, error };
|
|
185
190
|
}
|
|
186
191
|
|
|
187
192
|
// src/internal/SubscriptionGate.tsx
|
|
@@ -194,8 +199,9 @@ var BLOCKING = /* @__PURE__ */ new Set([
|
|
|
194
199
|
]);
|
|
195
200
|
function SubscriptionGate({ Paywall, children }) {
|
|
196
201
|
const { mode } = useTemplateConfig();
|
|
197
|
-
const { status } = usePaywallState();
|
|
202
|
+
const { status, initialLoadComplete } = usePaywallState();
|
|
198
203
|
if (mode === "free") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children });
|
|
204
|
+
if (!initialLoadComplete && status === "none") return null;
|
|
199
205
|
if (BLOCKING.has(status)) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Paywall, {});
|
|
200
206
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children });
|
|
201
207
|
}
|
|
@@ -2381,12 +2387,37 @@ function EmptyState({ title, description, action }) {
|
|
|
2381
2387
|
] });
|
|
2382
2388
|
}
|
|
2383
2389
|
|
|
2390
|
+
// src/hooks/usePlan.ts
|
|
2391
|
+
var import_sdk11 = require("@hook-sdk/sdk");
|
|
2392
|
+
function usePlan() {
|
|
2393
|
+
const { plan } = (0, import_sdk11.useHook)();
|
|
2394
|
+
return plan;
|
|
2395
|
+
}
|
|
2396
|
+
|
|
2397
|
+
// src/utils/price.ts
|
|
2398
|
+
function formatBRL(cents) {
|
|
2399
|
+
if (cents === null || cents === void 0) return "";
|
|
2400
|
+
const reais = cents / 100;
|
|
2401
|
+
return new Intl.NumberFormat("pt-BR", {
|
|
2402
|
+
style: "currency",
|
|
2403
|
+
currency: "BRL"
|
|
2404
|
+
}).format(reais);
|
|
2405
|
+
}
|
|
2406
|
+
function monthlyFromYearly(yearlyCents) {
|
|
2407
|
+
if (yearlyCents === null || yearlyCents === void 0) return 0;
|
|
2408
|
+
return Math.round(yearlyCents / 12);
|
|
2409
|
+
}
|
|
2410
|
+
function dailyFromYearly(yearlyCents) {
|
|
2411
|
+
if (yearlyCents === null || yearlyCents === void 0) return 0;
|
|
2412
|
+
return Math.round(yearlyCents / 365);
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2384
2415
|
// src/hooks/useAuthPrimitives.ts
|
|
2385
2416
|
var import_react17 = require("react");
|
|
2386
|
-
var
|
|
2417
|
+
var import_sdk12 = require("@hook-sdk/sdk");
|
|
2387
2418
|
var warned = false;
|
|
2388
2419
|
function useAuthPrimitives() {
|
|
2389
|
-
const { auth } = (0,
|
|
2420
|
+
const { auth } = (0, import_sdk12.useHook)();
|
|
2390
2421
|
(0, import_react17.useEffect)(() => {
|
|
2391
2422
|
if (!warned && process.env.NODE_ENV !== "production") {
|
|
2392
2423
|
warned = true;
|
|
@@ -2409,9 +2440,9 @@ function useAuthPrimitives() {
|
|
|
2409
2440
|
}
|
|
2410
2441
|
|
|
2411
2442
|
// src/hooks/useSubscription.ts
|
|
2412
|
-
var
|
|
2443
|
+
var import_sdk13 = require("@hook-sdk/sdk");
|
|
2413
2444
|
function useSubscription() {
|
|
2414
|
-
const { subscription } = (0,
|
|
2445
|
+
const { subscription } = (0, import_sdk13.useHook)();
|
|
2415
2446
|
return {
|
|
2416
2447
|
status: subscription.status()
|
|
2417
2448
|
};
|
|
@@ -2419,9 +2450,9 @@ function useSubscription() {
|
|
|
2419
2450
|
|
|
2420
2451
|
// src/hooks/useReminders.ts
|
|
2421
2452
|
var import_react18 = require("react");
|
|
2422
|
-
var
|
|
2453
|
+
var import_sdk14 = require("@hook-sdk/sdk");
|
|
2423
2454
|
function useReminders() {
|
|
2424
|
-
const { push } = (0,
|
|
2455
|
+
const { push } = (0, import_sdk14.useHook)();
|
|
2425
2456
|
const r = push.reminders;
|
|
2426
2457
|
const [reminders, setReminders] = (0, import_react18.useState)([]);
|
|
2427
2458
|
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
@@ -2484,11 +2515,14 @@ function useToast() {
|
|
|
2484
2515
|
InstallSplash,
|
|
2485
2516
|
LoadingState,
|
|
2486
2517
|
PushPrompt,
|
|
2518
|
+
dailyFromYearly,
|
|
2487
2519
|
detectAndroidBrowser,
|
|
2488
2520
|
detectIOSBrowser,
|
|
2489
2521
|
detectInAppApp,
|
|
2490
2522
|
detectPlatform,
|
|
2491
2523
|
detectStandalone,
|
|
2524
|
+
formatBRL,
|
|
2525
|
+
monthlyFromYearly,
|
|
2492
2526
|
shouldBlockInstall,
|
|
2493
2527
|
shouldShowPermanentOption,
|
|
2494
2528
|
useAuth,
|
|
@@ -2497,6 +2531,7 @@ function useToast() {
|
|
|
2497
2531
|
useInstallPrompt,
|
|
2498
2532
|
useLoginForm,
|
|
2499
2533
|
usePaywallState,
|
|
2534
|
+
usePlan,
|
|
2500
2535
|
usePush,
|
|
2501
2536
|
useReminders,
|
|
2502
2537
|
useResetForm,
|