@hook-sdk/template 0.17.0 → 0.18.1
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 +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -400,6 +400,7 @@ interface PaywallPlanDerived {
|
|
|
400
400
|
*/
|
|
401
401
|
declare function usePaywallState(): {
|
|
402
402
|
status: SubscriptionStatus;
|
|
403
|
+
hasAccess: boolean | null;
|
|
403
404
|
daysLeftInTrial: number | null;
|
|
404
405
|
initialLoadComplete: boolean;
|
|
405
406
|
plan: PaywallPlanDerived | null;
|
|
@@ -722,7 +723,21 @@ declare function shouldBlockInstall(state: InstallState, now?: number): boolean;
|
|
|
722
723
|
*/
|
|
723
724
|
declare function shouldShowPermanentOption(state: InstallState): boolean;
|
|
724
725
|
|
|
725
|
-
|
|
726
|
+
/**
|
|
727
|
+
* Map Asaas error → PT-BR user-facing message.
|
|
728
|
+
*
|
|
729
|
+
* Two inputs because backend folds Asaas's specific error code into a
|
|
730
|
+
* compound code (`payments.capture_card.tokenize_failed:invalid_holderInfo`)
|
|
731
|
+
* and only the *description* string ("O CEP informado é inválido.")
|
|
732
|
+
* distinguishes between sub-cases of `invalid_holderInfo` (CEP, phone, name).
|
|
733
|
+
*
|
|
734
|
+
* Asaas keeps a snapshot of Correios CEPs that lags real registrations by
|
|
735
|
+
* months — CEPs of recently-cadastrated streets (ex: bairros novos) get
|
|
736
|
+
* rejected even though they're valid in ViaCEP/BrasilAPI. We don't suggest
|
|
737
|
+
* a fictitious CEP (would mess up nota fiscal/comms); we explain the issue
|
|
738
|
+
* is on the processor's side and ask user to try a nearby street's CEP.
|
|
739
|
+
*/
|
|
740
|
+
declare function asaasErrorMessage(code: string, description?: string): string;
|
|
726
741
|
|
|
727
742
|
type RouteBoundaryProps = {
|
|
728
743
|
children: ReactNode;
|
package/dist/index.d.ts
CHANGED
|
@@ -400,6 +400,7 @@ interface PaywallPlanDerived {
|
|
|
400
400
|
*/
|
|
401
401
|
declare function usePaywallState(): {
|
|
402
402
|
status: SubscriptionStatus;
|
|
403
|
+
hasAccess: boolean | null;
|
|
403
404
|
daysLeftInTrial: number | null;
|
|
404
405
|
initialLoadComplete: boolean;
|
|
405
406
|
plan: PaywallPlanDerived | null;
|
|
@@ -722,7 +723,21 @@ declare function shouldBlockInstall(state: InstallState, now?: number): boolean;
|
|
|
722
723
|
*/
|
|
723
724
|
declare function shouldShowPermanentOption(state: InstallState): boolean;
|
|
724
725
|
|
|
725
|
-
|
|
726
|
+
/**
|
|
727
|
+
* Map Asaas error → PT-BR user-facing message.
|
|
728
|
+
*
|
|
729
|
+
* Two inputs because backend folds Asaas's specific error code into a
|
|
730
|
+
* compound code (`payments.capture_card.tokenize_failed:invalid_holderInfo`)
|
|
731
|
+
* and only the *description* string ("O CEP informado é inválido.")
|
|
732
|
+
* distinguishes between sub-cases of `invalid_holderInfo` (CEP, phone, name).
|
|
733
|
+
*
|
|
734
|
+
* Asaas keeps a snapshot of Correios CEPs that lags real registrations by
|
|
735
|
+
* months — CEPs of recently-cadastrated streets (ex: bairros novos) get
|
|
736
|
+
* rejected even though they're valid in ViaCEP/BrasilAPI. We don't suggest
|
|
737
|
+
* a fictitious CEP (would mess up nota fiscal/comms); we explain the issue
|
|
738
|
+
* is on the processor's side and ask user to try a nearby street's CEP.
|
|
739
|
+
*/
|
|
740
|
+
declare function asaasErrorMessage(code: string, description?: string): string;
|
|
726
741
|
|
|
727
742
|
type RouteBoundaryProps = {
|
|
728
743
|
children: ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -196,7 +196,16 @@ var MAP = {
|
|
|
196
196
|
pix_expired: "QR Code do PIX expirou. Gere um novo.",
|
|
197
197
|
pix_not_paid_yet: "PIX ainda n\xE3o foi pago. Aguardando confirma\xE7\xE3o."
|
|
198
198
|
};
|
|
199
|
-
function asaasErrorMessage(code) {
|
|
199
|
+
function asaasErrorMessage(code, description) {
|
|
200
|
+
if (description) {
|
|
201
|
+
const lower = description.toLowerCase();
|
|
202
|
+
if (lower.includes("cep")) {
|
|
203
|
+
return "Nosso processador de pagamentos n\xE3o reconheceu esse CEP \u2014 a base deles pode estar desatualizada. Tente outro CEP.";
|
|
204
|
+
}
|
|
205
|
+
if (lower.includes("telefone") || lower.includes("contato com ddd")) {
|
|
206
|
+
return "Telefone inv\xE1lido. Confira o n\xFAmero com DDD e tente novamente.";
|
|
207
|
+
}
|
|
208
|
+
}
|
|
200
209
|
return MAP[code] ?? "Ocorreu um erro inesperado. Tente novamente em instantes.";
|
|
201
210
|
}
|
|
202
211
|
|
|
@@ -282,6 +291,7 @@ function usePaywallState() {
|
|
|
282
291
|
const status = subscription.status();
|
|
283
292
|
const daysLeftInTrial = subscription.daysLeftInTrial();
|
|
284
293
|
const initialLoadComplete = subscription.initialLoadComplete;
|
|
294
|
+
const hasAccess = subscription.hasAccess;
|
|
285
295
|
const pixPending = useMemo2(() => {
|
|
286
296
|
const sdkPix = subscription.pixPending;
|
|
287
297
|
if (!sdkPix) return null;
|
|
@@ -324,7 +334,9 @@ function usePaywallState() {
|
|
|
324
334
|
(code, fallbackMessage) => ({
|
|
325
335
|
code,
|
|
326
336
|
message: fallbackMessage,
|
|
327
|
-
|
|
337
|
+
// fallbackMessage carries Asaas's PT-BR description ("O CEP informado é inválido.")
|
|
338
|
+
// that distinguishes invalid_holderInfo sub-cases (CEP vs phone vs name).
|
|
339
|
+
userMessage: useDefaultMessages ? asaasErrorMessage(code, fallbackMessage) : fallbackMessage
|
|
328
340
|
}),
|
|
329
341
|
[useDefaultMessages]
|
|
330
342
|
);
|
|
@@ -485,6 +497,7 @@ function usePaywallState() {
|
|
|
485
497
|
return {
|
|
486
498
|
// Subscription status (reactive, proxied from SDK)
|
|
487
499
|
status,
|
|
500
|
+
hasAccess,
|
|
488
501
|
daysLeftInTrial,
|
|
489
502
|
initialLoadComplete,
|
|
490
503
|
// Plan derivation from config (sync, no fetch)
|
|
@@ -528,9 +541,10 @@ var BLOCKING = /* @__PURE__ */ new Set([
|
|
|
528
541
|
]);
|
|
529
542
|
function SubscriptionGate({ Paywall, children }) {
|
|
530
543
|
const { mode } = useTemplateConfig();
|
|
531
|
-
const { status, initialLoadComplete } = usePaywallState();
|
|
544
|
+
const { status, hasAccess, initialLoadComplete } = usePaywallState();
|
|
532
545
|
if (mode === "free") return /* @__PURE__ */ jsx5(Fragment2, { children });
|
|
533
546
|
if (!initialLoadComplete && status === "none") return null;
|
|
547
|
+
if (hasAccess === true && status !== "none") return /* @__PURE__ */ jsx5(Fragment2, { children });
|
|
534
548
|
if (BLOCKING.has(status)) return /* @__PURE__ */ jsx5(Paywall, {});
|
|
535
549
|
return /* @__PURE__ */ jsx5(Fragment2, { children });
|
|
536
550
|
}
|