@hook-sdk/template 0.1.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 +790 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +288 -0
- package/dist/index.d.ts +288 -0
- package/dist/index.js +745 -0
- package/dist/index.js.map +1 -0
- package/package.json +61 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode, ComponentType, Component } from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import * as _hook_sdk_sdk from '@hook-sdk/sdk';
|
|
5
|
+
|
|
6
|
+
declare const AppConfigSchema: z.ZodObject<{
|
|
7
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
8
|
+
slug: z.ZodString;
|
|
9
|
+
name: z.ZodString;
|
|
10
|
+
display_name: z.ZodOptional<z.ZodString>;
|
|
11
|
+
email_alias: z.ZodString;
|
|
12
|
+
theme: z.ZodObject<{
|
|
13
|
+
primary_color: z.ZodString;
|
|
14
|
+
background_color: z.ZodOptional<z.ZodString>;
|
|
15
|
+
logo_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
16
|
+
icon_url: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
}, z.core.$strict>;
|
|
18
|
+
features_enabled: z.ZodArray<z.ZodEnum<{
|
|
19
|
+
db: "db";
|
|
20
|
+
storage: "storage";
|
|
21
|
+
upload: "upload";
|
|
22
|
+
leaderboard: "leaderboard";
|
|
23
|
+
push: "push";
|
|
24
|
+
subscription: "subscription";
|
|
25
|
+
}>>;
|
|
26
|
+
dependencies_allowlist: z.ZodArray<z.ZodString>;
|
|
27
|
+
subscription: z.ZodObject<{
|
|
28
|
+
price_cents: z.ZodNumber;
|
|
29
|
+
currency: z.ZodLiteral<"brl">;
|
|
30
|
+
trial_days: z.ZodNumber;
|
|
31
|
+
paywall_config: z.ZodObject<{
|
|
32
|
+
title: z.ZodString;
|
|
33
|
+
subtitle: z.ZodOptional<z.ZodString>;
|
|
34
|
+
benefits: z.ZodArray<z.ZodString>;
|
|
35
|
+
cta: z.ZodString;
|
|
36
|
+
priceHint: z.ZodOptional<z.ZodString>;
|
|
37
|
+
footerNote: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
sdk_version_required: z.ZodString;
|
|
41
|
+
max_bundle_size_kb: z.ZodNumber;
|
|
42
|
+
}, z.core.$strict>;
|
|
43
|
+
type AppConfig = z.infer<typeof AppConfigSchema>;
|
|
44
|
+
|
|
45
|
+
type AuthScreen = 'login' | 'signup' | 'forgot' | 'reset';
|
|
46
|
+
interface AuthScreenProps {
|
|
47
|
+
onNavigate: (to: AuthScreen) => void;
|
|
48
|
+
}
|
|
49
|
+
declare function DefaultLoginScreen({ onNavigate }: AuthScreenProps): react_jsx_runtime.JSX.Element;
|
|
50
|
+
|
|
51
|
+
interface AppRootProps {
|
|
52
|
+
config: AppConfig;
|
|
53
|
+
children: ReactNode;
|
|
54
|
+
Login?: ComponentType<AuthScreenProps>;
|
|
55
|
+
Signup?: ComponentType<AuthScreenProps>;
|
|
56
|
+
Forgot?: ComponentType<AuthScreenProps>;
|
|
57
|
+
/**
|
|
58
|
+
* Tela de reset de senha (form com nova senha via link do email).
|
|
59
|
+
* Renderizada pelo AuthGate quando URL tem `?token=` + user não logado.
|
|
60
|
+
* Default: DefaultResetScreen.
|
|
61
|
+
*/
|
|
62
|
+
Reset?: ComponentType<AuthScreenProps>;
|
|
63
|
+
Paywall?: ComponentType;
|
|
64
|
+
}
|
|
65
|
+
declare function AppRoot({ config, children, Login, Signup, Forgot, Reset, Paywall, }: AppRootProps): react_jsx_runtime.JSX.Element;
|
|
66
|
+
|
|
67
|
+
declare function DefaultSignupScreen({ onNavigate }: AuthScreenProps): react_jsx_runtime.JSX.Element;
|
|
68
|
+
|
|
69
|
+
declare function DefaultForgotScreen({ onNavigate }: AuthScreenProps): react_jsx_runtime.JSX.Element;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Tela default de reset de senha. Renderizada pelo AuthGate quando
|
|
73
|
+
* `?token=` está presente na URL (link vindo do email de password_reset).
|
|
74
|
+
*
|
|
75
|
+
* AuthScreenProps.onNavigate é usado pra voltar pro login após reset
|
|
76
|
+
* bem-sucedido (usuário precisa re-autenticar — backend revoga todos
|
|
77
|
+
* os refresh tokens na chamada de `auth.reset`).
|
|
78
|
+
*/
|
|
79
|
+
declare function DefaultResetScreen({ onNavigate }: AuthScreenProps): react_jsx_runtime.JSX.Element;
|
|
80
|
+
|
|
81
|
+
declare function DefaultPaywall(): react_jsx_runtime.JSX.Element;
|
|
82
|
+
|
|
83
|
+
declare function LoadingState({ message }: {
|
|
84
|
+
message?: string;
|
|
85
|
+
}): react_jsx_runtime.JSX.Element;
|
|
86
|
+
|
|
87
|
+
declare function EmptyState({ title, description, action }: {
|
|
88
|
+
title: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
action?: ReactNode;
|
|
91
|
+
}): react_jsx_runtime.JSX.Element;
|
|
92
|
+
|
|
93
|
+
interface Props {
|
|
94
|
+
children: ReactNode;
|
|
95
|
+
fallback?: ReactNode;
|
|
96
|
+
}
|
|
97
|
+
interface State {
|
|
98
|
+
error: Error | null;
|
|
99
|
+
}
|
|
100
|
+
declare class ErrorBoundary extends Component<Props, State> {
|
|
101
|
+
state: State;
|
|
102
|
+
static getDerivedStateFromError(error: Error): State;
|
|
103
|
+
componentDidCatch(error: Error): void;
|
|
104
|
+
render(): string | number | boolean | Iterable<ReactNode> | react_jsx_runtime.JSX.Element;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type AuthFormErrorCode = 'invalid_credentials' | 'rate_limited' | 'email_unverified' | 'account_locked' | 'network' | 'server';
|
|
108
|
+
interface AuthFormError {
|
|
109
|
+
code: AuthFormErrorCode;
|
|
110
|
+
message: string;
|
|
111
|
+
retryAfter?: number;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
interface UseLoginFormResult {
|
|
115
|
+
email: string;
|
|
116
|
+
setEmail: (v: string) => void;
|
|
117
|
+
emailError: string | null;
|
|
118
|
+
password: string;
|
|
119
|
+
setPassword: (v: string) => void;
|
|
120
|
+
passwordError: string | null;
|
|
121
|
+
submit: () => Promise<void>;
|
|
122
|
+
submitting: boolean;
|
|
123
|
+
canSubmit: boolean;
|
|
124
|
+
error: AuthFormError | null;
|
|
125
|
+
}
|
|
126
|
+
declare function useLoginForm(): UseLoginFormResult;
|
|
127
|
+
|
|
128
|
+
interface UseSignupFormResult {
|
|
129
|
+
name: string;
|
|
130
|
+
setName: (v: string) => void;
|
|
131
|
+
nameError: string | null;
|
|
132
|
+
email: string;
|
|
133
|
+
setEmail: (v: string) => void;
|
|
134
|
+
emailError: string | null;
|
|
135
|
+
password: string;
|
|
136
|
+
setPassword: (v: string) => void;
|
|
137
|
+
passwordError: string | null;
|
|
138
|
+
submit: () => Promise<void>;
|
|
139
|
+
submitting: boolean;
|
|
140
|
+
canSubmit: boolean;
|
|
141
|
+
error: AuthFormError | null;
|
|
142
|
+
}
|
|
143
|
+
declare function useSignupForm(): UseSignupFormResult;
|
|
144
|
+
|
|
145
|
+
interface UseForgotFormResult {
|
|
146
|
+
email: string;
|
|
147
|
+
setEmail: (v: string) => void;
|
|
148
|
+
emailError: string | null;
|
|
149
|
+
submit: () => Promise<void>;
|
|
150
|
+
submitting: boolean;
|
|
151
|
+
canSubmit: boolean;
|
|
152
|
+
sent: boolean;
|
|
153
|
+
error: AuthFormError | null;
|
|
154
|
+
}
|
|
155
|
+
declare function useForgotForm(): UseForgotFormResult;
|
|
156
|
+
|
|
157
|
+
interface UseResetFormResult {
|
|
158
|
+
/** Token JWT lido de `?token=` da URL. null se ausente. */
|
|
159
|
+
token: string | null;
|
|
160
|
+
password: string;
|
|
161
|
+
setPassword: (v: string) => void;
|
|
162
|
+
passwordError: string | null;
|
|
163
|
+
confirm: string;
|
|
164
|
+
setConfirm: (v: string) => void;
|
|
165
|
+
confirmError: string | null;
|
|
166
|
+
submit: () => Promise<void>;
|
|
167
|
+
submitting: boolean;
|
|
168
|
+
canSubmit: boolean;
|
|
169
|
+
/** true após submit 200. UI deve mostrar "senha alterada, volte pro login". */
|
|
170
|
+
done: boolean;
|
|
171
|
+
error: AuthFormError | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Hook headless pro fluxo de reset de senha via link do email.
|
|
175
|
+
*
|
|
176
|
+
* Lê `?token=` da URL atual automaticamente (readonly snapshot no mount).
|
|
177
|
+
* Se token ausente, `canSubmit` fica false + `token: null` pra UI mostrar
|
|
178
|
+
* mensagem "link inválido".
|
|
179
|
+
*
|
|
180
|
+
* Após submit 200, todos os refresh tokens do user são revogados pelo
|
|
181
|
+
* backend (forçar re-login). UI deve direcionar pra LoginScreen.
|
|
182
|
+
*/
|
|
183
|
+
declare function useResetForm(): UseResetFormResult;
|
|
184
|
+
|
|
185
|
+
type SubscriptionStatus = 'active' | 'trialing' | 'expired' | 'canceled' | 'past_due' | 'none';
|
|
186
|
+
/**
|
|
187
|
+
* Hook headless pro Paywall. Expõe status atual da subscription + ação
|
|
188
|
+
* `checkout(cpf)` que chama `POST /payments/checkout/card` e redireciona
|
|
189
|
+
* o browser pro `invoiceUrl` hosted do Asaas. Após o checkout, Asaas
|
|
190
|
+
* redireciona de volta com query string indicativa; subscription real
|
|
191
|
+
* é atualizada via webhook (`PAYMENT_RECEIVED` / `SUBSCRIPTION_ACTIVATED`).
|
|
192
|
+
*
|
|
193
|
+
* MVP: checkout só cartão. Pix vem depois (gatilho documentado em P10.7).
|
|
194
|
+
*/
|
|
195
|
+
declare function usePaywallState(): {
|
|
196
|
+
status: SubscriptionStatus;
|
|
197
|
+
daysLeftInTrial: number | null;
|
|
198
|
+
checkout: (args: {
|
|
199
|
+
cpf: string;
|
|
200
|
+
cycle?: "MONTHLY" | "YEARLY";
|
|
201
|
+
}) => Promise<void>;
|
|
202
|
+
cancel: () => Promise<void>;
|
|
203
|
+
opening: boolean;
|
|
204
|
+
error: Error | null;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Escape hatch pra screens FORA do fluxo de auth (ex: settings/trocar-senha).
|
|
209
|
+
* Pra LoginScreen/SignupScreen/ForgotScreen custom, use useLoginForm/useSignupForm/useForgotForm.
|
|
210
|
+
*/
|
|
211
|
+
declare function useAuthPrimitives(): {
|
|
212
|
+
login: (args: {
|
|
213
|
+
email: string;
|
|
214
|
+
password: string;
|
|
215
|
+
}) => Promise<void>;
|
|
216
|
+
signup: (args: {
|
|
217
|
+
email: string;
|
|
218
|
+
password: string;
|
|
219
|
+
name?: string;
|
|
220
|
+
}) => Promise<void>;
|
|
221
|
+
logout: () => Promise<void>;
|
|
222
|
+
logoutAll: () => Promise<void>;
|
|
223
|
+
forgot: (args: {
|
|
224
|
+
email: string;
|
|
225
|
+
}) => Promise<void>;
|
|
226
|
+
resendVerify: () => Promise<void>;
|
|
227
|
+
changePassword: (args: {
|
|
228
|
+
oldPassword: string;
|
|
229
|
+
newPassword: string;
|
|
230
|
+
}) => Promise<void>;
|
|
231
|
+
changeEmail: (args: {
|
|
232
|
+
newEmail: string;
|
|
233
|
+
}) => Promise<void>;
|
|
234
|
+
refresh: () => Promise<void>;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Wrapper fino sobre useHook(). Expõe apenas `user`, `authStatus` e `refresh`
|
|
239
|
+
* pros consumidores que não precisam das methods completas do auth.
|
|
240
|
+
*/
|
|
241
|
+
declare function useAuth(): {
|
|
242
|
+
user: {
|
|
243
|
+
id: string;
|
|
244
|
+
email: string;
|
|
245
|
+
emailVerified: boolean;
|
|
246
|
+
createdAt: string;
|
|
247
|
+
} | null;
|
|
248
|
+
authStatus: _hook_sdk_sdk.AuthStatus;
|
|
249
|
+
refresh: () => Promise<void>;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Wrapper fino sobre `subscription` do SDK. MVP: apenas status (stub retorna 'none').
|
|
254
|
+
*/
|
|
255
|
+
declare function useSubscription(): {
|
|
256
|
+
status: _hook_sdk_sdk.SdkSubscriptionStatus;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Wrapper fino sobre `push` do SDK. MVP: stub retorna 'unsupported' no status
|
|
261
|
+
* e subscribe/unsubscribe lançam SdkError. A shape segue o SDK real.
|
|
262
|
+
*/
|
|
263
|
+
declare function usePush(): {
|
|
264
|
+
status: _hook_sdk_sdk.PushStatus;
|
|
265
|
+
subscribe: () => Promise<{
|
|
266
|
+
subscribed: true;
|
|
267
|
+
}>;
|
|
268
|
+
unsubscribe: () => Promise<{
|
|
269
|
+
subscribed: false;
|
|
270
|
+
}>;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
interface ToastItem {
|
|
274
|
+
id: string;
|
|
275
|
+
message: string;
|
|
276
|
+
kind: 'info' | 'error' | 'success';
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Toast mínimo in-memory. MVP: IA renderiza a lista onde quiser (ex: no final do <Home>).
|
|
280
|
+
* Não opina sobre UI; retorna items + actions.
|
|
281
|
+
*/
|
|
282
|
+
declare function useToast(): {
|
|
283
|
+
items: ToastItem[];
|
|
284
|
+
show: (message: string, kind?: ToastItem["kind"]) => void;
|
|
285
|
+
dismiss: (id: string) => void;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
export { AppRoot, type AppRootProps, type AuthFormError, type AuthFormErrorCode, type AuthScreen, type AuthScreenProps, DefaultForgotScreen, DefaultLoginScreen, DefaultPaywall, DefaultResetScreen, DefaultSignupScreen, EmptyState, ErrorBoundary, LoadingState, type SubscriptionStatus, type ToastItem, type UseLoginFormResult, type UseResetFormResult, useAuth, useAuthPrimitives, useForgotForm, useLoginForm, usePaywallState, usePush, useResetForm, useSignupForm, useSubscription, useToast };
|