@hook-sdk/template 0.5.0 → 0.7.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 +96 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -7
- package/dist/index.d.ts +117 -7
- package/dist/index.js +90 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,11 +32,16 @@ __export(index_exports, {
|
|
|
32
32
|
InstallSplash: () => InstallSplash,
|
|
33
33
|
LoadingState: () => LoadingState,
|
|
34
34
|
PushPrompt: () => PushPrompt2,
|
|
35
|
+
computeAnchorCents: () => computeAnchorCents,
|
|
36
|
+
dailyFromYearly: () => dailyFromYearly,
|
|
35
37
|
detectAndroidBrowser: () => detectAndroidBrowser,
|
|
36
38
|
detectIOSBrowser: () => detectIOSBrowser,
|
|
37
39
|
detectInAppApp: () => detectInAppApp,
|
|
38
40
|
detectPlatform: () => detectPlatform,
|
|
39
41
|
detectStandalone: () => detectStandalone,
|
|
42
|
+
discountPercent: () => discountPercent,
|
|
43
|
+
formatBRL: () => formatBRL,
|
|
44
|
+
monthlyFromYearly: () => monthlyFromYearly,
|
|
40
45
|
shouldBlockInstall: () => shouldBlockInstall,
|
|
41
46
|
shouldShowPermanentOption: () => shouldShowPermanentOption,
|
|
42
47
|
useAuth: () => useAuth,
|
|
@@ -45,6 +50,7 @@ __export(index_exports, {
|
|
|
45
50
|
useInstallPrompt: () => useInstallPrompt,
|
|
46
51
|
useLoginForm: () => useLoginForm,
|
|
47
52
|
usePaywallState: () => usePaywallState,
|
|
53
|
+
usePlan: () => usePlan,
|
|
48
54
|
usePush: () => usePush,
|
|
49
55
|
useReminders: () => useReminders,
|
|
50
56
|
useResetForm: () => useResetForm,
|
|
@@ -154,6 +160,7 @@ function usePaywallState() {
|
|
|
154
160
|
const { subscription } = (0, import_sdk2.useHook)();
|
|
155
161
|
const [opening, setOpening] = (0, import_react3.useState)(false);
|
|
156
162
|
const [error, setError] = (0, import_react3.useState)(null);
|
|
163
|
+
const [pixPending, setPixPending] = (0, import_react3.useState)(null);
|
|
157
164
|
const status = subscription.status();
|
|
158
165
|
const daysLeftInTrial = subscription.daysLeftInTrial();
|
|
159
166
|
const initialLoadComplete = subscription.initialLoadComplete;
|
|
@@ -161,12 +168,37 @@ function usePaywallState() {
|
|
|
161
168
|
async (args) => {
|
|
162
169
|
setOpening(true);
|
|
163
170
|
setError(null);
|
|
171
|
+
setPixPending(null);
|
|
172
|
+
const method = args.method ?? "card";
|
|
173
|
+
const cycle = args.cycle ?? "MONTHLY";
|
|
164
174
|
try {
|
|
165
|
-
|
|
166
|
-
cpf: args.cpf,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
175
|
+
if (method === "card") {
|
|
176
|
+
const result = await subscription.checkoutCard({ cpf: args.cpf, cycle });
|
|
177
|
+
window.location.href = result.invoiceUrl;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (method === "pix-auto") {
|
|
181
|
+
const result = await subscription.checkoutPixAuto({ cpf: args.cpf, cycle });
|
|
182
|
+
setPixPending({
|
|
183
|
+
method: "pix-auto",
|
|
184
|
+
qrCodePayload: result.qrCodePayload,
|
|
185
|
+
qrCodeBase64: result.qrCodeBase64,
|
|
186
|
+
expiresAt: null
|
|
187
|
+
});
|
|
188
|
+
setOpening(false);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (method === "pix-once") {
|
|
192
|
+
const result = await subscription.checkoutPixOnce({ cpf: args.cpf, cycle });
|
|
193
|
+
setPixPending({
|
|
194
|
+
method: "pix-once",
|
|
195
|
+
qrCodePayload: result.qrCodePayload,
|
|
196
|
+
qrCodeBase64: result.qrCodeBase64,
|
|
197
|
+
expiresAt: result.expiresAt
|
|
198
|
+
});
|
|
199
|
+
setOpening(false);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
170
202
|
} catch (err) {
|
|
171
203
|
setError(err);
|
|
172
204
|
setOpening(false);
|
|
@@ -182,7 +214,18 @@ function usePaywallState() {
|
|
|
182
214
|
setError(err);
|
|
183
215
|
}
|
|
184
216
|
}, [subscription]);
|
|
185
|
-
|
|
217
|
+
const dismissPix = (0, import_react3.useCallback)(() => setPixPending(null), []);
|
|
218
|
+
return {
|
|
219
|
+
status,
|
|
220
|
+
daysLeftInTrial,
|
|
221
|
+
initialLoadComplete,
|
|
222
|
+
checkout,
|
|
223
|
+
cancel,
|
|
224
|
+
opening,
|
|
225
|
+
error,
|
|
226
|
+
pixPending,
|
|
227
|
+
dismissPix
|
|
228
|
+
};
|
|
186
229
|
}
|
|
187
230
|
|
|
188
231
|
// src/internal/SubscriptionGate.tsx
|
|
@@ -2383,12 +2426,47 @@ function EmptyState({ title, description, action }) {
|
|
|
2383
2426
|
] });
|
|
2384
2427
|
}
|
|
2385
2428
|
|
|
2429
|
+
// src/hooks/usePlan.ts
|
|
2430
|
+
var import_sdk11 = require("@hook-sdk/sdk");
|
|
2431
|
+
function usePlan() {
|
|
2432
|
+
const { plan } = (0, import_sdk11.useHook)();
|
|
2433
|
+
return plan;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
// src/utils/price.ts
|
|
2437
|
+
function formatBRL(cents) {
|
|
2438
|
+
if (cents === null || cents === void 0) return "";
|
|
2439
|
+
const reais = cents / 100;
|
|
2440
|
+
return new Intl.NumberFormat("pt-BR", {
|
|
2441
|
+
style: "currency",
|
|
2442
|
+
currency: "BRL"
|
|
2443
|
+
}).format(reais);
|
|
2444
|
+
}
|
|
2445
|
+
function monthlyFromYearly(yearlyCents) {
|
|
2446
|
+
if (yearlyCents === null || yearlyCents === void 0) return 0;
|
|
2447
|
+
return Math.round(yearlyCents / 12);
|
|
2448
|
+
}
|
|
2449
|
+
function dailyFromYearly(yearlyCents) {
|
|
2450
|
+
if (yearlyCents === null || yearlyCents === void 0) return 0;
|
|
2451
|
+
return Math.round(yearlyCents / 365);
|
|
2452
|
+
}
|
|
2453
|
+
function computeAnchorCents(baseCents, multiplier) {
|
|
2454
|
+
if (multiplier === null || multiplier === void 0) return null;
|
|
2455
|
+
if (!Number.isFinite(multiplier)) return null;
|
|
2456
|
+
if (multiplier <= 1) return null;
|
|
2457
|
+
return Math.round(baseCents * multiplier);
|
|
2458
|
+
}
|
|
2459
|
+
function discountPercent(anchorCents, realCents) {
|
|
2460
|
+
if (anchorCents <= realCents) return 0;
|
|
2461
|
+
return Math.floor((anchorCents - realCents) / anchorCents * 100);
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2386
2464
|
// src/hooks/useAuthPrimitives.ts
|
|
2387
2465
|
var import_react17 = require("react");
|
|
2388
|
-
var
|
|
2466
|
+
var import_sdk12 = require("@hook-sdk/sdk");
|
|
2389
2467
|
var warned = false;
|
|
2390
2468
|
function useAuthPrimitives() {
|
|
2391
|
-
const { auth } = (0,
|
|
2469
|
+
const { auth } = (0, import_sdk12.useHook)();
|
|
2392
2470
|
(0, import_react17.useEffect)(() => {
|
|
2393
2471
|
if (!warned && process.env.NODE_ENV !== "production") {
|
|
2394
2472
|
warned = true;
|
|
@@ -2411,9 +2489,9 @@ function useAuthPrimitives() {
|
|
|
2411
2489
|
}
|
|
2412
2490
|
|
|
2413
2491
|
// src/hooks/useSubscription.ts
|
|
2414
|
-
var
|
|
2492
|
+
var import_sdk13 = require("@hook-sdk/sdk");
|
|
2415
2493
|
function useSubscription() {
|
|
2416
|
-
const { subscription } = (0,
|
|
2494
|
+
const { subscription } = (0, import_sdk13.useHook)();
|
|
2417
2495
|
return {
|
|
2418
2496
|
status: subscription.status()
|
|
2419
2497
|
};
|
|
@@ -2421,9 +2499,9 @@ function useSubscription() {
|
|
|
2421
2499
|
|
|
2422
2500
|
// src/hooks/useReminders.ts
|
|
2423
2501
|
var import_react18 = require("react");
|
|
2424
|
-
var
|
|
2502
|
+
var import_sdk14 = require("@hook-sdk/sdk");
|
|
2425
2503
|
function useReminders() {
|
|
2426
|
-
const { push } = (0,
|
|
2504
|
+
const { push } = (0, import_sdk14.useHook)();
|
|
2427
2505
|
const r = push.reminders;
|
|
2428
2506
|
const [reminders, setReminders] = (0, import_react18.useState)([]);
|
|
2429
2507
|
const [loading, setLoading] = (0, import_react18.useState)(true);
|
|
@@ -2486,11 +2564,16 @@ function useToast() {
|
|
|
2486
2564
|
InstallSplash,
|
|
2487
2565
|
LoadingState,
|
|
2488
2566
|
PushPrompt,
|
|
2567
|
+
computeAnchorCents,
|
|
2568
|
+
dailyFromYearly,
|
|
2489
2569
|
detectAndroidBrowser,
|
|
2490
2570
|
detectIOSBrowser,
|
|
2491
2571
|
detectInAppApp,
|
|
2492
2572
|
detectPlatform,
|
|
2493
2573
|
detectStandalone,
|
|
2574
|
+
discountPercent,
|
|
2575
|
+
formatBRL,
|
|
2576
|
+
monthlyFromYearly,
|
|
2494
2577
|
shouldBlockInstall,
|
|
2495
2578
|
shouldShowPermanentOption,
|
|
2496
2579
|
useAuth,
|
|
@@ -2499,6 +2582,7 @@ function useToast() {
|
|
|
2499
2582
|
useInstallPrompt,
|
|
2500
2583
|
useLoginForm,
|
|
2501
2584
|
usePaywallState,
|
|
2585
|
+
usePlan,
|
|
2502
2586
|
usePush,
|
|
2503
2587
|
useReminders,
|
|
2504
2588
|
useResetForm,
|