doct-ui-auth-kit 1.0.3 → 1.0.4

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.
Files changed (50) hide show
  1. package/dist/auth-methods/apple.d.ts +1 -1
  2. package/dist/auth-methods/index.d.ts +1 -0
  3. package/dist/components/form/rhf-doct-phone-input.d.ts +1 -1
  4. package/dist/components/form/rhf-input-field.d.ts +1 -1
  5. package/dist/components/form/rhf-otp-input-field.d.ts +1 -1
  6. package/dist/components/layout/image-slider.d.ts +2 -19
  7. package/dist/components/layout/main-layout.d.ts +2 -46
  8. package/dist/core/auth-api-adapter.d.ts +1 -39
  9. package/dist/core/auth-context.d.ts +4 -50
  10. package/dist/core/auth-provider.d.ts +2 -35
  11. package/dist/core/auth-types.d.ts +3 -68
  12. package/dist/core/device-detection.d.ts +2 -6
  13. package/dist/core/sso-session.d.ts +2 -30
  14. package/dist/core/use-auth-flow.d.ts +2 -75
  15. package/dist/hooks/index.d.ts +2 -0
  16. package/dist/hooks/use-login-entry-form.d.ts +4 -28
  17. package/dist/hooks/use-main-auth-page-handlers.d.ts +8 -0
  18. package/dist/hooks/use-otp-verification.d.ts +7 -31
  19. package/dist/hooks/use-repeat-login.d.ts +7 -0
  20. package/dist/hooks/use-signup-form.d.ts +4 -44
  21. package/dist/index.js +2938 -3452
  22. package/dist/pages/index.d.ts +5 -5
  23. package/dist/pages/login-entry.d.ts +40 -21
  24. package/dist/pages/main-login.d.ts +30 -14
  25. package/dist/pages/otp-verification.d.ts +43 -21
  26. package/dist/pages/repeat-login.d.ts +47 -18
  27. package/dist/pages/signup.d.ts +43 -23
  28. package/dist/pages.js +5 -5
  29. package/dist/signup-BpiNvZy4.js +1714 -0
  30. package/dist/types/auth-api-adapter.d.ts +43 -0
  31. package/dist/types/auth-provider.d.ts +37 -0
  32. package/dist/types/auth-types.d.ts +70 -0
  33. package/dist/types/device-detection.d.ts +7 -0
  34. package/dist/types/flow.d.ts +125 -0
  35. package/dist/types/forms.d.ts +2 -0
  36. package/dist/types/index.d.ts +13 -0
  37. package/dist/types/layout.d.ts +57 -0
  38. package/dist/types/login-form.d.ts +39 -0
  39. package/dist/types/main-login.d.ts +29 -0
  40. package/dist/types/otp-verification.d.ts +28 -0
  41. package/dist/types/pages.d.ts +133 -0
  42. package/dist/types/repeat-login.d.ts +28 -0
  43. package/dist/types/signup-form.d.ts +41 -0
  44. package/dist/types/sso-session.d.ts +33 -0
  45. package/dist/utils/index.d.ts +4 -0
  46. package/dist/utils/set-form-errors-from-zod.d.ts +11 -0
  47. package/dist/validations/index.d.ts +6 -0
  48. package/dist/validations/schemas.d.ts +76 -0
  49. package/package.json +105 -104
  50. package/dist/signup-x-Jm7XKn.js +0 -668
@@ -0,0 +1,41 @@
1
+ import type { UseFormReturn } from 'react-hook-form';
2
+ import type { z } from 'zod';
3
+ import type { signupEmailFormSchema, signupForeignFormSchema, signupPhoneFormSchema } from '@/validations';
4
+ /** Signup mode: phone, email as second field, or foreign (full name + email + phone). */
5
+ export type SignupEntryMode = 'phone' | 'email' | 'foreign';
6
+ export type SignupPhoneFormValues = z.infer<typeof signupPhoneFormSchema>;
7
+ export type SignupEmailFormValues = z.infer<typeof signupEmailFormSchema>;
8
+ export type SignupForeignFormValues = z.infer<typeof signupForeignFormSchema>;
9
+ export type SignupFormValues = SignupPhoneFormValues | SignupEmailFormValues | SignupForeignFormValues;
10
+ /** Payload when signup form is valid. */
11
+ export type SignupSubmitData = {
12
+ fullName: string;
13
+ phone?: string;
14
+ email?: string;
15
+ };
16
+ export interface UseSignupFormOptions {
17
+ /** Mode: phone, email as second field, or foreign (name + email + phone) */
18
+ mode: SignupEntryMode;
19
+ /** For foreign mode: pre-fill phone when user already entered it. */
20
+ defaultPhone?: string;
21
+ /** Sync callback with valid data. Use when parent owns API (e.g. AuthFlow). Ignored when submitApi is provided. */
22
+ onSubmit?: ((data: SignupSubmitData) => void) | undefined;
23
+ /** When provided, hook runs: validate → submitApi(data) → onSuccess(). Consumer passes redirect in onSuccess. */
24
+ submitApi?: (data: SignupSubmitData) => Promise<void>;
25
+ /** Called after submitApi succeeds (e.g. router.push('/otp') or next step). */
26
+ onSuccess?: () => void;
27
+ /** Called when submitApi rejects or throws. */
28
+ onError?: (error: unknown) => void;
29
+ }
30
+ export interface UseSignupFormReturn {
31
+ methods: UseFormReturn<SignupFormValues>;
32
+ handleSubmit: (data: SignupFormValues) => void;
33
+ /** True when mode is 'phone', false when mode is 'email'. For 'foreign' same as (mode === 'phone') for layout. */
34
+ isPhone: boolean;
35
+ /** True when mode is 'foreign' (full name + email + phone). */
36
+ isForeign: boolean;
37
+ /** True when current form values pass validation (for disabling Continue – edge cases 9, 16, 19). */
38
+ isFormValid: (data: SignupFormValues) => boolean;
39
+ /** True while submitApi is in flight. */
40
+ isSubmitting: boolean;
41
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * SSO session and token storage types.
3
+ */
4
+ /** How/where the SSO token is stored for cross-app access. */
5
+ export interface TokenStorageStrategy {
6
+ get(): string | null;
7
+ set(token: string, expiresAt: number): void;
8
+ remove(): void;
9
+ }
10
+ /** Minimal request config type for the interceptor (no axios import). */
11
+ export interface AxiosRequestConfig {
12
+ headers?: Record<string, string> | {
13
+ [key: string]: string;
14
+ };
15
+ withCredentials?: boolean;
16
+ }
17
+ /**
18
+ * Axios instance shape needed to attach auth interceptors (avoids hard axios dependency).
19
+ * Use createAxiosAuthInterceptors with your axios instance.
20
+ */
21
+ export interface AxiosAuthInterceptorInstance {
22
+ interceptors: {
23
+ request: {
24
+ use(onFulfilled?: (config: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>, onRejected?: (err: unknown) => unknown): number;
25
+ };
26
+ response: {
27
+ use(onFulfilled?: (res: unknown) => unknown, onRejected?: (err: unknown) => unknown): number;
28
+ };
29
+ };
30
+ defaults: {
31
+ withCredentials?: boolean;
32
+ };
33
+ }
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Reusable utilities used in 2+ places across the auth SDK.
3
+ */
4
+ export { setFormErrorsFromZod } from './set-form-errors-from-zod';
@@ -0,0 +1,11 @@
1
+ import type { ZodError } from 'zod';
2
+ /**
3
+ * Applies Zod validation errors to a React Hook Form setError function.
4
+ * Used by form submit handlers to display field-level errors from schema validation.
5
+ *
6
+ * @param error - The ZodError from schema.safeParse when validation fails
7
+ * @param setError - RHF's setError (e.g. methods.setError)
8
+ */
9
+ export declare function setFormErrorsFromZod(error: ZodError, setError: (path: string, opts: {
10
+ message: string;
11
+ }) => void): void;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Central export for all validation schemas and helpers.
3
+ * Import from here: import { signupSchemas, loginSchemas, otpFormSchema } from '@/validations';
4
+ */
5
+ export type { OtpVerificationMode } from './schemas';
6
+ export { capitalizeWords, emailSchema, fullNameSchema, getResendCooldownSeconds, loginEmailFormSchema, loginPhoneFormSchema, loginSchemas, OTP_LENGTH, otpFormSchema, phoneSchema, RESEND_COOLDOWN_EMAIL_SECONDS, RESEND_COOLDOWN_PHONE_SECONDS, signupEmailFormSchema, signupForeignFormSchema, signupPhoneFormSchema, signupSchemas, } from './schemas';
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Centralized Zod schemas for auth forms (signup, login, OTP).
3
+ * Single source of truth for validation rules per PRODUCT_PROTOCOLS.
4
+ */
5
+ import { z } from 'zod';
6
+ /** Capitalize first letter of each word (PRODUCT_PROTOCOLS #25 – Naming conventions). */
7
+ export declare function capitalizeWords(value: string): string;
8
+ /**
9
+ * Full name: min 3 chars, trim, capitalize each word (Protocol #1, #25; Edge case 9).
10
+ */
11
+ export declare const fullNameSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
12
+ /**
13
+ * Phone: digits only, length between 7 and 15.
14
+ */
15
+ export declare const phoneSchema: z.ZodString;
16
+ /**
17
+ * Email: trim and lowercase before save (Edge case 10).
18
+ */
19
+ export declare const emailSchema: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
20
+ export declare const signupPhoneFormSchema: z.ZodObject<{
21
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
22
+ phone: z.ZodString;
23
+ }, z.core.$strip>;
24
+ export declare const signupEmailFormSchema: z.ZodObject<{
25
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
26
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
27
+ }, z.core.$strip>;
28
+ export declare const signupForeignFormSchema: z.ZodObject<{
29
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
30
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
31
+ phone: z.ZodString;
32
+ }, z.core.$strip>;
33
+ export declare const signupSchemas: {
34
+ readonly phone: z.ZodObject<{
35
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
36
+ phone: z.ZodString;
37
+ }, z.core.$strip>;
38
+ readonly email: z.ZodObject<{
39
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
40
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
41
+ }, z.core.$strip>;
42
+ readonly foreign: z.ZodObject<{
43
+ fullName: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
44
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
45
+ phone: z.ZodString;
46
+ }, z.core.$strip>;
47
+ };
48
+ /**
49
+ * Phone validation per PRODUCT_PROTOCOLS #2, #5 and edge cases 3–5.
50
+ */
51
+ export declare const loginPhoneFormSchema: z.ZodObject<{
52
+ phone: z.ZodString;
53
+ }, z.core.$strip>;
54
+ /**
55
+ * Email validation: trim and lowercase per edge case 10.
56
+ */
57
+ export declare const loginEmailFormSchema: z.ZodObject<{
58
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
59
+ }, z.core.$strip>;
60
+ export declare const loginSchemas: {
61
+ readonly phone: z.ZodObject<{
62
+ phone: z.ZodString;
63
+ }, z.core.$strip>;
64
+ readonly email: z.ZodObject<{
65
+ email: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
66
+ }, z.core.$strip>;
67
+ };
68
+ export declare const OTP_LENGTH = 6;
69
+ /** Resend cooldown: 60s for phone OTP, 2 min for email OTP (per design). */
70
+ export declare const RESEND_COOLDOWN_PHONE_SECONDS = 60;
71
+ export declare const RESEND_COOLDOWN_EMAIL_SECONDS = 120;
72
+ export type OtpVerificationMode = 'phone' | 'email';
73
+ export declare function getResendCooldownSeconds(mode: OtpVerificationMode): number;
74
+ export declare const otpFormSchema: z.ZodObject<{
75
+ otp: z.ZodArray<z.ZodString>;
76
+ }, z.core.$strip>;
package/package.json CHANGED
@@ -1,104 +1,105 @@
1
- {
2
- "name": "doct-ui-auth-kit",
3
- "version": "1.0.3",
4
- "description": "Composable React auth SDK – layouts, login/signup/OTP pages, SSO provider, and auth flow hooks for Docthub",
5
- "type": "module",
6
- "main": "./dist/index.js",
7
- "types": "./dist/index.d.ts",
8
- "files": ["dist", "README.md"],
9
- "keywords": [
10
- "react",
11
- "auth",
12
- "sdk",
13
- "docthub",
14
- "login",
15
- "signup",
16
- "sso",
17
- "otp"
18
- ],
19
- "license": "UNLICENSED",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/docthub/doct-ui-auth-kit"
23
- },
24
- "scripts": {
25
- "dev": "vite",
26
- "build": "tsc -b && vite build && tsc -p tsconfig.build.json",
27
- "prepublishOnly": "npm run build",
28
- "lint": "biome lint .",
29
- "preview": "vite preview",
30
- "format": "biome format --write .",
31
- "lint:biome": "biome lint .",
32
- "check": "biome check .",
33
- "check:fix": "biome check --write .",
34
- "type-check": "tsc --noEmit",
35
- "prepare": "husky",
36
- "storybook": "storybook dev -p 6006",
37
- "build-storybook": "storybook build"
38
- },
39
- "exports": {
40
- ".": {
41
- "types": "./dist/index.d.ts",
42
- "import": "./dist/index.js"
43
- },
44
- "./style.css": "./dist/style.css",
45
- "./pages": {
46
- "types": "./dist/pages/index.d.ts",
47
- "import": "./dist/pages.js"
48
- }
49
- },
50
- "peerDependencies": {
51
- "react": "^19.0.0",
52
- "react-dom": "^19.0.0",
53
- "docthub-core-components": "^2.54.0",
54
- "react-hook-form": "^7.50.0",
55
- "zod": "^4.0.0"
56
- },
57
- "dependencies": {
58
- "clsx": "^2.1.1",
59
- "dayjs": "^1.11.19",
60
- "docthub-core-components": "^2.54.0",
61
- "react": "^19.2.0",
62
- "react-dom": "^19.2.0",
63
- "react-hook-form": "^7.71.1",
64
- "react-icons": "^5.5.0",
65
- "react-phone-number-input": "^3.4.14",
66
- "zod": "^4.3.6"
67
- },
68
- "devDependencies": {
69
- "@biomejs/biome": "^2.3.14",
70
- "@chromatic-com/storybook": "^5.0.0",
71
- "@eslint/js": "^9.39.1",
72
- "@storybook/addon-a11y": "^10.2.6",
73
- "@storybook/addon-docs": "^10.2.6",
74
- "@storybook/addon-onboarding": "^10.2.6",
75
- "@storybook/addon-vitest": "^10.2.6",
76
- "@storybook/react-vite": "^10.2.6",
77
- "@types/node": "^24.10.1",
78
- "@types/react": "^19.2.5",
79
- "@types/react-dom": "^19.2.3",
80
- "@vitejs/plugin-react": "^5.1.1",
81
- "@vitest/browser-playwright": "^4.0.18",
82
- "@vitest/coverage-v8": "^4.0.18",
83
- "autoprefixer": "^10.4.24",
84
- "babel-plugin-react-compiler": "^1.0.0",
85
- "eslint": "^9.39.1",
86
- "eslint-plugin-react-hooks": "^7.0.1",
87
- "eslint-plugin-react-refresh": "^0.4.24",
88
- "glob": "^13.0.1",
89
- "globals": "^16.5.0",
90
- "husky": "^9.1.7",
91
- "lint-staged": "^16.2.7",
92
- "playwright": "^1.58.1",
93
- "postcss": "^8.5.6",
94
- "storybook": "^10.2.6",
95
- "tailwind-merge": "^3.0.1",
96
- "tailwindcss": "^3.4.16",
97
- "tailwindcss-animate": "^1.0.7",
98
- "typescript": "~5.6.2",
99
- "typescript-eslint": "^8.46.4",
100
- "vite": "^7.2.4",
101
- "vitest": "^4.0.18",
102
- "vite-plugin-dts": "^4.5.0"
103
- }
104
- }
1
+ {
2
+ "name": "doct-ui-auth-kit",
3
+ "version": "1.0.4",
4
+ "description": "Composable React auth SDK – layouts, login/signup/OTP pages, SSO provider, and auth flow hooks for Docthub",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "files": ["dist", "README.md"],
9
+ "keywords": [
10
+ "react",
11
+ "auth",
12
+ "sdk",
13
+ "docthub",
14
+ "login",
15
+ "signup",
16
+ "sso",
17
+ "otp"
18
+ ],
19
+ "license": "UNLICENSED",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/docthub/doct-ui-auth-kit"
23
+ },
24
+ "scripts": {
25
+ "dev": "vite",
26
+ "build": "tsc -b && vite build && tsc -p tsconfig.build.json",
27
+ "prepublishOnly": "npm run build",
28
+ "lint": "biome lint .",
29
+ "preview": "vite preview",
30
+ "format": "biome format --write .",
31
+ "lint:biome": "biome lint .",
32
+ "check": "biome check .",
33
+ "check:fix": "biome check --write .",
34
+ "type-check": "tsc --noEmit",
35
+ "prepare": "husky",
36
+ "storybook": "storybook dev -p 6006",
37
+ "build-storybook": "storybook build"
38
+ },
39
+ "exports": {
40
+ ".": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/index.js"
43
+ },
44
+ "./style.css": "./dist/style.css",
45
+ "./pages": {
46
+ "types": "./dist/pages/index.d.ts",
47
+ "import": "./dist/pages.js"
48
+ }
49
+ },
50
+ "peerDependencies": {
51
+ "docthub-core-components": "^2.54.0",
52
+ "react": "^19.0.0",
53
+ "react-dom": "^19.0.0",
54
+ "react-hook-form": "^7.50.0",
55
+ "zod": "^4.0.0"
56
+ },
57
+ "dependencies": {
58
+ "clsx": "^2.1.1",
59
+ "dayjs": "^1.11.19",
60
+ "docthub-core-components": "^2.54.0",
61
+ "react": "^19.0.0",
62
+ "react-dom": "^19.0.0",
63
+ "react-hook-form": "^7.50.0",
64
+ "react-icons": "^5.5.0",
65
+ "react-phone-number-input": "^3.4.14",
66
+ "react-router-dom": "^7.13.0",
67
+ "zod": "^4.0.0"
68
+ },
69
+ "devDependencies": {
70
+ "@biomejs/biome": "^2.3.14",
71
+ "@chromatic-com/storybook": "^5.0.0",
72
+ "@eslint/js": "^9.39.1",
73
+ "@storybook/addon-a11y": "^10.2.6",
74
+ "@storybook/addon-docs": "^10.2.6",
75
+ "@storybook/addon-onboarding": "^10.2.6",
76
+ "@storybook/addon-vitest": "^10.2.6",
77
+ "@storybook/react-vite": "^10.2.6",
78
+ "@types/node": "^24.10.1",
79
+ "@types/react": "^19.2.5",
80
+ "@types/react-dom": "^19.2.3",
81
+ "@vitejs/plugin-react": "^5.1.1",
82
+ "@vitest/browser-playwright": "^4.0.18",
83
+ "@vitest/coverage-v8": "^4.0.18",
84
+ "autoprefixer": "^10.4.24",
85
+ "babel-plugin-react-compiler": "^1.0.0",
86
+ "eslint": "^9.39.1",
87
+ "eslint-plugin-react-hooks": "^7.0.1",
88
+ "eslint-plugin-react-refresh": "^0.4.24",
89
+ "glob": "^13.0.1",
90
+ "globals": "^16.5.0",
91
+ "husky": "^9.1.7",
92
+ "lint-staged": "^16.2.7",
93
+ "playwright": "^1.58.1",
94
+ "postcss": "^8.5.6",
95
+ "storybook": "^10.2.6",
96
+ "tailwind-merge": "^3.0.1",
97
+ "tailwindcss": "^3.4.16",
98
+ "tailwindcss-animate": "^1.0.7",
99
+ "typescript": "~5.6.2",
100
+ "typescript-eslint": "^8.46.4",
101
+ "vite": "^7.2.4",
102
+ "vite-plugin-dts": "^4.5.0",
103
+ "vitest": "^4.0.18"
104
+ }
105
+ }