azirid-react 0.7.0 → 0.9.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.d.cts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, CSSProperties, FormEvent } from 'react';
2
+ import { CSSProperties, ReactNode, FormEvent } from 'react';
3
3
  import * as _tanstack_react_query from '@tanstack/react-query';
4
4
  import { UseMutationResult, UseQueryResult } from '@tanstack/react-query';
5
5
  import { z } from 'zod';
6
+ import { TenantRole, Environment } from '@azirid/shared';
6
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
8
  import { ClassValue } from 'clsx';
8
9
 
@@ -15,9 +16,9 @@ interface AuthUser {
15
16
  mfaEnabled?: boolean;
16
17
  appId?: string;
17
18
  tenantId: string;
18
- tenantRole: string;
19
+ tenantRole: TenantRole | string;
19
20
  workspaceId?: string;
20
- environment?: 'development' | 'production';
21
+ environment?: Environment;
21
22
  mustChangePassword?: boolean;
22
23
  publicMetadata?: Record<string, unknown> | null;
23
24
  unsafeMetadata?: Record<string, unknown> | null;
@@ -126,6 +127,14 @@ interface AccessMessages {
126
127
  cancel: string;
127
128
  processing: string;
128
129
  };
130
+ navigation: {
131
+ noAccountText: string;
132
+ signUpLink: string;
133
+ hasAccountText: string;
134
+ signInLink: string;
135
+ forgotPassword: string;
136
+ backToLogin: string;
137
+ };
129
138
  validation: {
130
139
  emailRequired: string;
131
140
  emailInvalid: string;
@@ -359,6 +368,101 @@ interface SignupFormProps {
359
368
  confirmPasswordPlaceholder?: string;
360
369
  };
361
370
  }
371
+ type AuthView = 'login' | 'signup' | 'forgot-password' | 'reset-password';
372
+ interface ForgotPasswordFormProps {
373
+ /** Override the default onSubmit */
374
+ onSubmit?: (data: {
375
+ email: string;
376
+ }) => void | Promise<void>;
377
+ /** Custom Zod schema for validation */
378
+ schema?: z.ZodType;
379
+ /** Show a loading spinner / disable the form */
380
+ isLoading?: boolean;
381
+ /** Error message to display */
382
+ error?: string | null;
383
+ /** Custom class name for the root element */
384
+ className?: string;
385
+ /** Inline styles for the root element */
386
+ style?: CSSProperties;
387
+ /** Title displayed above the form */
388
+ title?: string;
389
+ /** Subtitle / description below the title */
390
+ description?: string;
391
+ /** Logo or branding element rendered above the card */
392
+ logo?: ReactNode;
393
+ /** Text for the submit button */
394
+ submitText?: string;
395
+ /** Render a footer below the form */
396
+ footer?: ReactNode;
397
+ /** Pre-fill the form fields */
398
+ defaultValues?: {
399
+ email?: string;
400
+ };
401
+ }
402
+ interface ResetPasswordFormProps {
403
+ /** Token from the reset URL */
404
+ token: string;
405
+ /** Override the default onSubmit */
406
+ onSubmit?: (data: {
407
+ token: string;
408
+ newPassword: string;
409
+ }) => void | Promise<void>;
410
+ /** Custom Zod schema for validation */
411
+ schema?: z.ZodType;
412
+ /** Show a loading spinner / disable the form */
413
+ isLoading?: boolean;
414
+ /** Error message to display */
415
+ error?: string | null;
416
+ /** Custom class name for the root element */
417
+ className?: string;
418
+ /** Inline styles for the root element */
419
+ style?: CSSProperties;
420
+ /** Title displayed above the form */
421
+ title?: string;
422
+ /** Subtitle / description below the title */
423
+ description?: string;
424
+ /** Logo or branding element rendered above the card */
425
+ logo?: ReactNode;
426
+ /** Text for the submit button */
427
+ submitText?: string;
428
+ /** Render a footer below the form */
429
+ footer?: ReactNode;
430
+ /** Callback on successful password reset */
431
+ onSuccess?: () => void;
432
+ }
433
+ interface AuthFormProps {
434
+ /** Controlled view (parent manages state) */
435
+ view?: AuthView;
436
+ /** Callback when navigation links are clicked (controlled mode) */
437
+ onViewChange?: (view: AuthView) => void;
438
+ /** Initial view for uncontrolled mode (default: 'login') */
439
+ defaultView?: AuthView;
440
+ /** Custom class name for the root element */
441
+ className?: string;
442
+ /** Inline styles for the root element */
443
+ style?: CSSProperties;
444
+ /** Logo or branding element rendered above the card */
445
+ logo?: ReactNode;
446
+ /** Show SSO buttons on login/signup (default: true) */
447
+ showSocialButtons?: boolean;
448
+ /** Hide navigation links between views */
449
+ hideNavigation?: boolean;
450
+ /** Token for reset-password view */
451
+ resetToken?: string;
452
+ /** Default form values passed to child forms */
453
+ defaultValues?: {
454
+ email?: string;
455
+ password?: string;
456
+ };
457
+ /** Props forwarded to LoginForm */
458
+ loginProps?: Omit<LoginFormProps, 'className' | 'style' | 'logo' | 'showSocialButtons' | 'footer' | 'forgotPassword'>;
459
+ /** Props forwarded to SignupForm */
460
+ signupProps?: Omit<SignupFormProps, 'className' | 'style' | 'logo' | 'showSocialButtons' | 'footer'>;
461
+ /** Props forwarded to ForgotPasswordForm */
462
+ forgotPasswordProps?: Omit<ForgotPasswordFormProps, 'className' | 'style' | 'logo' | 'footer'>;
463
+ /** Props forwarded to ResetPasswordForm */
464
+ resetPasswordProps?: Omit<ResetPasswordFormProps, 'className' | 'style' | 'logo' | 'footer' | 'token'>;
465
+ }
362
466
  interface FieldError {
363
467
  field: string;
364
468
  message: string;
@@ -510,12 +614,12 @@ interface TenantWithRole {
510
614
  slug: string;
511
615
  description?: string | null;
512
616
  enabled: boolean;
513
- role: 'OWNER' | 'MEMBER';
617
+ role: TenantRole;
514
618
  joinedAt: string;
515
619
  }
516
620
  interface TenantMemberInfo {
517
621
  id: string;
518
- role: 'OWNER' | 'MEMBER';
622
+ role: TenantRole;
519
623
  joinedAt: string;
520
624
  user: {
521
625
  id: string;
@@ -534,6 +638,15 @@ declare const LoginForm: react.ForwardRefExoticComponent<LoginFormProps & react.
534
638
 
535
639
  declare const SignupForm: react.ForwardRefExoticComponent<SignupFormProps & react.RefAttributes<HTMLFormElement>>;
536
640
 
641
+ declare const ForgotPasswordForm: react.ForwardRefExoticComponent<ForgotPasswordFormProps & react.RefAttributes<HTMLFormElement>>;
642
+
643
+ declare const ResetPasswordForm: react.ForwardRefExoticComponent<ResetPasswordFormProps & react.RefAttributes<HTMLFormElement>>;
644
+
645
+ declare function AuthForm({ view: controlledView, onViewChange, defaultView, className, style, logo, showSocialButtons, hideNavigation, resetToken, defaultValues, loginProps, signupProps, forgotPasswordProps, resetPasswordProps, }: AuthFormProps): react_jsx_runtime.JSX.Element;
646
+ declare namespace AuthForm {
647
+ var displayName: string;
648
+ }
649
+
537
650
  interface ReferralCardProps {
538
651
  className?: string;
539
652
  style?: CSSProperties;
@@ -656,6 +769,8 @@ declare const SUFFIXES: {
656
769
  readonly submitTransferProof: "billing/transfer-proof";
657
770
  readonly transferProofs: "billing/transfer-proofs";
658
771
  readonly payphoneConfirm: "billing/payphone/confirm";
772
+ readonly passwordResetRequest: "password/reset/request";
773
+ readonly passwordResetConfirm: "password/reset/confirm";
659
774
  readonly referralMe: "referrals/me";
660
775
  readonly referralStats: "referrals/stats";
661
776
  readonly userTenants: "tenants";
@@ -1442,6 +1557,92 @@ declare function useSwitchTenant(): {
1442
1557
  switchTenant: (tenantId: string) => Promise<void>;
1443
1558
  };
1444
1559
 
1560
+ interface PasswordResetRequestData {
1561
+ email: string;
1562
+ }
1563
+ interface PasswordResetConfirmData {
1564
+ token: string;
1565
+ newPassword: string;
1566
+ }
1567
+ interface UsePasswordResetOptions {
1568
+ /** Callback after reset email sent */
1569
+ onRequestSuccess?: () => void;
1570
+ /** Callback after password successfully reset */
1571
+ onConfirmSuccess?: () => void;
1572
+ /** Callback on error */
1573
+ onError?: (error: Error) => void;
1574
+ }
1575
+ interface UsePasswordResetReturn {
1576
+ /** Request a password reset email */
1577
+ request: UseMutationResult<unknown, Error, PasswordResetRequestData>;
1578
+ /** Confirm the password reset with token + new password */
1579
+ confirm: UseMutationResult<unknown, Error, PasswordResetConfirmData>;
1580
+ }
1581
+ /**
1582
+ * Standalone hook for password reset flow. Requires `<AziridProvider>`.
1583
+ *
1584
+ * @example
1585
+ * ```tsx
1586
+ * const passwordReset = usePasswordReset({
1587
+ * onRequestSuccess: () => toast.success("Check your email"),
1588
+ * onConfirmSuccess: () => router.push("/login"),
1589
+ * });
1590
+ *
1591
+ * // Step 1: request reset
1592
+ * passwordReset.request.mutate({ email: "user@test.com" });
1593
+ *
1594
+ * // Step 2: confirm with token from URL
1595
+ * passwordReset.confirm.mutate({ token: "abc", newPassword: "newPass123!" });
1596
+ * ```
1597
+ */
1598
+ declare function usePasswordReset(options?: UsePasswordResetOptions): UsePasswordResetReturn;
1599
+
1600
+ /**
1601
+ * Options common to all simple mutation hooks created via `createMutationHook`.
1602
+ */
1603
+ interface SimpleMutationOptions<TData> {
1604
+ onSuccess?: (data: TData) => void;
1605
+ onError?: (error: Error) => void;
1606
+ }
1607
+ /**
1608
+ * Configuration for `createMutationHook`.
1609
+ *
1610
+ * @template TData The response type from the API
1611
+ * @template TInput The input/variables type for the mutation
1612
+ */
1613
+ interface MutationHookConfig<TData, TInput> {
1614
+ /** Static mutation key for deduplication / devtools */
1615
+ mutationKey: string[];
1616
+ /**
1617
+ * Derive the mutation function from the AccessClient and input.
1618
+ * Most hooks simply call `client.post<TData>(client.paths.someEndpoint, data)`.
1619
+ */
1620
+ mutationFn: (client: AccessClient, input: TInput) => Promise<TData>;
1621
+ }
1622
+ /**
1623
+ * Factory that creates a simple `useMutation`-based hook.
1624
+ *
1625
+ * Eliminates the boilerplate of:
1626
+ * 1. Calling `useAccessClient()`
1627
+ * 2. Creating a `useMutation` with `mutationKey`, `mutationFn`, `onSuccess`, `onError`
1628
+ *
1629
+ * The resulting hook has the same return type as `useMutation` (`UseMutationResult`),
1630
+ * preserving full compatibility with TanStack Query.
1631
+ *
1632
+ * @example
1633
+ * ```ts
1634
+ * export const useChangePassword = createMutationHook<
1635
+ * { updated: boolean },
1636
+ * ChangePasswordData
1637
+ * >({
1638
+ * mutationKey: ['azirid-access', 'change-password'],
1639
+ * mutationFn: (client, data) =>
1640
+ * client.post<{ updated: boolean }>(client.paths.changePassword, data),
1641
+ * })
1642
+ * ```
1643
+ */
1644
+ declare function createMutationHook<TData, TInput = void>(config: MutationHookConfig<TData, TInput>): (options?: SimpleMutationOptions<TData>) => UseMutationResult<TData, Error, TInput>;
1645
+
1445
1646
  declare function useFormState<T extends Record<string, unknown>>(initialValues: T, schema: z.ZodType<unknown, z.ZodTypeDef, unknown>, onSubmit: (values: T) => void | Promise<void>): UseFormReturn<T>;
1446
1647
 
1447
1648
  declare function usePasswordToggle(): {
@@ -1566,6 +1767,64 @@ declare const socialLoginSchema: z.ZodObject<{
1566
1767
  turnstileToken?: string | undefined;
1567
1768
  }>;
1568
1769
  type SocialLoginInput = z.infer<typeof socialLoginSchema>;
1770
+ declare function createForgotPasswordSchema(v: AccessMessages['validation']): z.ZodObject<{
1771
+ email: z.ZodString;
1772
+ }, "strip", z.ZodTypeAny, {
1773
+ email: string;
1774
+ }, {
1775
+ email: string;
1776
+ }>;
1777
+ declare const forgotPasswordSchema: z.ZodObject<{
1778
+ email: z.ZodString;
1779
+ }, "strip", z.ZodTypeAny, {
1780
+ email: string;
1781
+ }, {
1782
+ email: string;
1783
+ }>;
1784
+ type ForgotPasswordInput = z.infer<typeof forgotPasswordSchema>;
1785
+ declare function createResetPasswordConfirmSchema(v: AccessMessages['validation']): z.ZodEffects<z.ZodObject<{
1786
+ token: z.ZodString;
1787
+ newPassword: z.ZodString;
1788
+ confirmPassword: z.ZodString;
1789
+ }, "strip", z.ZodTypeAny, {
1790
+ token: string;
1791
+ newPassword: string;
1792
+ confirmPassword: string;
1793
+ }, {
1794
+ token: string;
1795
+ newPassword: string;
1796
+ confirmPassword: string;
1797
+ }>, {
1798
+ token: string;
1799
+ newPassword: string;
1800
+ confirmPassword: string;
1801
+ }, {
1802
+ token: string;
1803
+ newPassword: string;
1804
+ confirmPassword: string;
1805
+ }>;
1806
+ declare const resetPasswordConfirmSchema: z.ZodEffects<z.ZodObject<{
1807
+ token: z.ZodString;
1808
+ newPassword: z.ZodString;
1809
+ confirmPassword: z.ZodString;
1810
+ }, "strip", z.ZodTypeAny, {
1811
+ token: string;
1812
+ newPassword: string;
1813
+ confirmPassword: string;
1814
+ }, {
1815
+ token: string;
1816
+ newPassword: string;
1817
+ confirmPassword: string;
1818
+ }>, {
1819
+ token: string;
1820
+ newPassword: string;
1821
+ confirmPassword: string;
1822
+ }, {
1823
+ token: string;
1824
+ newPassword: string;
1825
+ confirmPassword: string;
1826
+ }>;
1827
+ type ResetPasswordConfirmInput = z.infer<typeof resetPasswordConfirmSchema>;
1569
1828
  declare const passkeyRegisterStartSchema: z.ZodObject<{
1570
1829
  deviceName: z.ZodOptional<z.ZodString>;
1571
1830
  }, "strip", z.ZodTypeAny, {
@@ -1580,6 +1839,30 @@ declare function cn(...inputs: ClassValue[]): string;
1580
1839
  /** Remove injected styles from the DOM (useful when embedding in host apps). */
1581
1840
  declare function removeStyles(): void;
1582
1841
 
1842
+ interface PricingCardProps {
1843
+ plan: BillingPlan;
1844
+ isCurrentPlan: boolean;
1845
+ isCheckoutPending: boolean;
1846
+ onSelect: (plan: BillingPlan) => void;
1847
+ }
1848
+
1849
+ interface PricingFeatureListProps {
1850
+ features: string[];
1851
+ }
1852
+
1853
+ interface ProviderModalProps {
1854
+ providers: AvailableProvider[];
1855
+ isPending: boolean;
1856
+ onSelect: (provider: PaymentProviderType) => void;
1857
+ onClose: () => void;
1858
+ labels?: Record<string, string>;
1859
+ }
1860
+ interface TransferModalProps {
1861
+ data: CheckoutResponse;
1862
+ onClose: () => void;
1863
+ labels?: Record<string, string>;
1864
+ }
1865
+
1583
1866
  declare global {
1584
1867
  interface Window {
1585
1868
  PPaymentButtonBox: new (config: Record<string, unknown>) => {
@@ -1604,4 +1887,4 @@ interface SessionSyncOptions {
1604
1887
 
1605
1888
  declare const SDK_VERSION: string;
1606
1889
 
1607
- export { type AccessClient, type AccessClientConfig, type AccessMessages, type ApiError, type AppBranding, type AuthPaths, type AuthState, type AuthSuccessResponse, type AuthUser, type AvailableProvider, type AziridContextValue, AziridProvider, type AziridProviderProps, BASE_PATHS, type BillingInvoice, type BillingPlan, type BootstrapResponse, type ChangePasswordData, type ChangePasswordInput, CheckoutButton, type CheckoutButtonProps, type CheckoutParams, type CheckoutResponse, type CreateTenantData, type FieldError, InvoiceList, type InvoiceListProps, type LoginData, LoginForm, type LoginFormProps, type LoginInput, type MagicLinkRequestData, type MagicLinkRequestInput, type MagicLinkVerifyData, type MagicLinkVerifyInput, PATHS, type PasskeyItem, type PasskeyLoginData, type PasskeyLoginStartData, type PasskeyLoginStartResponse, type PasskeyLoginVerifyData, type PasskeyRegisterStartData, type PasskeyRegisterStartInput, type PasskeyRegisterStartResponse, type PasskeyRegisterVerifyData, PayButton, type PayButtonProps, type PaymentIntent, type PaymentProviderType, PayphoneCallback, type PayphoneCallbackProps, type PayphoneConfirmParams, type PayphoneConfirmResult, type PayphoneModalProps, type PayphoneWidgetConfig, PricingTable, type PricingTableProps, ReferralCard, type ReferralCardProps, type ReferralInfo, type ReferralItem, ReferralStats, type ReferralStatsData, type ReferralStatsProps, type RegisterPasskeyData, SDK_VERSION, type SessionSyncOptions, type SignupData, SignupForm, type SignupFormProps, type SignupInput, type SocialLoginData, type SocialLoginInput, type SubmitTransferProofData, SubscriptionBadge, type SubscriptionBadgeProps, type SupportedLocale, type TenantMemberInfo, type TenantWithRole, type TransferProof, type UseBootstrapOptions, type UseBootstrapReturn, type UseChangePasswordOptions, type UseChangePasswordReturn, type UseCheckoutOptions, type UseFormReturn, type UseLoginOptions, type UseLoginReturn, type UseLogoutOptions, type UseLogoutReturn, type UseMagicLinkOptions, type UseMagicLinkReturn, type UsePasskeysOptions, type UsePasskeysReturn, type UsePayphoneConfirmOptions, type UseRefreshOptions, type UseRefreshReturn, type UseSessionOptions, type UseSessionReturn, type UseSignupOptions, type UseSignupReturn, type UseSocialLoginOptions, type UseSocialLoginReturn, type UserSubscription, buildPaths, changePasswordSchema, cn, createAccessClient, createLoginSchema, createSignupSchema, en, es, isAuthError, loginSchema, magicLinkRequestSchema, magicLinkVerifySchema, passkeyRegisterStartSchema, removeStyles, resolveMessages, signupSchema, socialLoginSchema, useAccessClient, useAzirid, useBootstrap, useBranding, useChangePassword, useCheckout, useFormState, useInvoices, useLogin, useLogout, useMagicLink, useMessages, usePasskeys, usePasswordToggle, usePaymentProviders, usePayphoneConfirm, usePlans, useReferral, useReferralStats, useRefresh, useSession, useSignup, useSocialLogin, useSubmitTransferProof, useSubscription, useSwitchTenant, useTenantMembers, useTenants, useTransferProofs };
1890
+ export { type AccessClient, type AccessClientConfig, type AccessMessages, type ApiError, type AppBranding, AuthForm, type AuthFormProps, type AuthPaths, type AuthState, type AuthSuccessResponse, type AuthUser, type AuthView, type AvailableProvider, type AziridContextValue, AziridProvider, type AziridProviderProps, BASE_PATHS, type BillingInvoice, type BillingPlan, type BootstrapResponse, type ChangePasswordData, type ChangePasswordInput, CheckoutButton, type CheckoutButtonProps, type CheckoutParams, type CheckoutResponse, type CreateTenantData, type FieldError, ForgotPasswordForm, type ForgotPasswordFormProps, type ForgotPasswordInput, InvoiceList, type InvoiceListProps, type LoginData, LoginForm, type LoginFormProps, type LoginInput, type MagicLinkRequestData, type MagicLinkRequestInput, type MagicLinkVerifyData, type MagicLinkVerifyInput, type MutationHookConfig, PATHS, type PasskeyItem, type PasskeyLoginData, type PasskeyLoginStartData, type PasskeyLoginStartResponse, type PasskeyLoginVerifyData, type PasskeyRegisterStartData, type PasskeyRegisterStartInput, type PasskeyRegisterStartResponse, type PasskeyRegisterVerifyData, type PasswordResetConfirmData, type PasswordResetRequestData, PayButton, type PayButtonProps, type PaymentIntent, type PaymentProviderType, PayphoneCallback, type PayphoneCallbackProps, type PayphoneConfirmParams, type PayphoneConfirmResult, type PayphoneModalProps, type PayphoneWidgetConfig, type PricingCardProps, type PricingFeatureListProps, PricingTable, type PricingTableProps, type ProviderModalProps, ReferralCard, type ReferralCardProps, type ReferralInfo, type ReferralItem, ReferralStats, type ReferralStatsData, type ReferralStatsProps, type RegisterPasskeyData, type ResetPasswordConfirmInput, ResetPasswordForm, type ResetPasswordFormProps, SDK_VERSION, type SessionSyncOptions, type SignupData, SignupForm, type SignupFormProps, type SignupInput, type SimpleMutationOptions, type SocialLoginData, type SocialLoginInput, type SubmitTransferProofData, SubscriptionBadge, type SubscriptionBadgeProps, type SupportedLocale, type TenantMemberInfo, type TenantWithRole, type TransferModalProps, type TransferProof, type UseBootstrapOptions, type UseBootstrapReturn, type UseChangePasswordOptions, type UseChangePasswordReturn, type UseCheckoutOptions, type UseFormReturn, type UseLoginOptions, type UseLoginReturn, type UseLogoutOptions, type UseLogoutReturn, type UseMagicLinkOptions, type UseMagicLinkReturn, type UsePasskeysOptions, type UsePasskeysReturn, type UsePasswordResetOptions, type UsePasswordResetReturn, type UsePayphoneConfirmOptions, type UseRefreshOptions, type UseRefreshReturn, type UseSessionOptions, type UseSessionReturn, type UseSignupOptions, type UseSignupReturn, type UseSocialLoginOptions, type UseSocialLoginReturn, type UserSubscription, buildPaths, changePasswordSchema, cn, createAccessClient, createForgotPasswordSchema, createLoginSchema, createMutationHook, createResetPasswordConfirmSchema, createSignupSchema, en, es, forgotPasswordSchema, isAuthError, loginSchema, magicLinkRequestSchema, magicLinkVerifySchema, passkeyRegisterStartSchema, removeStyles, resetPasswordConfirmSchema, resolveMessages, signupSchema, socialLoginSchema, useAccessClient, useAzirid, useBootstrap, useBranding, useChangePassword, useCheckout, useFormState, useInvoices, useLogin, useLogout, useMagicLink, useMessages, usePasskeys, usePasswordReset, usePasswordToggle, usePaymentProviders, usePayphoneConfirm, usePlans, useReferral, useReferralStats, useRefresh, useSession, useSignup, useSocialLogin, useSubmitTransferProof, useSubscription, useSwitchTenant, useTenantMembers, useTenants, useTransferProofs };