@ram_28/kf-ai-sdk 1.0.0 → 1.0.2

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.
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import type { AuthContextValue, AuthProviderProps } from "./types";
3
+ export declare function AuthProvider({ children, config: configOverride, onAuthChange, onError, loadingComponent, unauthenticatedComponent, skipInitialCheck, }: AuthProviderProps): React.ReactElement;
4
+ export declare function useAuthContext(): AuthContextValue;
5
+ //# sourceMappingURL=AuthProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthProvider.d.ts","sourceRoot":"","sources":["../../sdk/auth/AuthProvider.tsx"],"names":[],"mappings":"AAKA,OAAO,KAQN,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EAOlB,MAAM,SAAS,CAAC;AAsBjB,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,MAAM,EAAE,cAAc,EACtB,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,wBAAwB,EACxB,gBAAwB,GACzB,EAAE,iBAAiB,GAAG,KAAK,CAAC,YAAY,CA2MxC;AAMD,wBAAgB,cAAc,IAAI,gBAAgB,CAMjD"}
@@ -0,0 +1,26 @@
1
+ import type { SessionResponse, AuthProviderName, LoginOptions, LogoutOptions } from "./types";
2
+ /**
3
+ * Custom error class for authentication errors
4
+ */
5
+ export declare class AuthenticationError extends Error {
6
+ readonly statusCode: number;
7
+ constructor(message: string, statusCode: number);
8
+ }
9
+ /**
10
+ * Fetch current session from the server
11
+ * Calls the session endpoint (default: /api/id)
12
+ *
13
+ * @throws AuthenticationError if session check fails or user is not authenticated
14
+ */
15
+ export declare function fetchSession(): Promise<SessionResponse>;
16
+ /**
17
+ * Initiate login flow by redirecting to the auth provider
18
+ * The server handles the OAuth flow and sets cookies
19
+ */
20
+ export declare function initiateLogin(provider?: AuthProviderName, options?: LoginOptions): void;
21
+ /**
22
+ * Logout the current user
23
+ * Optionally calls the logout endpoint before clearing client state
24
+ */
25
+ export declare function performLogout(options?: LogoutOptions): Promise<void>;
26
+ //# sourceMappingURL=authClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authClient.d.ts","sourceRoot":"","sources":["../../sdk/auth/authClient.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACd,MAAM,SAAS,CAAC;AAQjB;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAEvB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAKhD;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,IAAI,OAAO,CAAC,eAAe,CAAC,CAuB7D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,CAAC,EAAE,gBAAgB,EAC3B,OAAO,CAAC,EAAE,YAAY,GACrB,IAAI,CA0BN;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAyB1E"}
@@ -0,0 +1,38 @@
1
+ import type { AuthConfig, AuthProviderName, AuthEndpointConfig } from "./types";
2
+ /**
3
+ * Configure authentication settings globally
4
+ * @example
5
+ * ```ts
6
+ * configureAuth({
7
+ * defaultProvider: "google",
8
+ * autoRedirect: true,
9
+ * providers: {
10
+ * google: { loginPath: "/api/auth/google/login" },
11
+ * microsoft: { loginPath: "/api/auth/microsoft/login" },
12
+ * },
13
+ * });
14
+ * ```
15
+ */
16
+ export declare function configureAuth(config: Partial<AuthConfig>): void;
17
+ /**
18
+ * Add or update an auth provider configuration
19
+ */
20
+ export declare function setAuthProvider(provider: AuthProviderName, config: AuthEndpointConfig): void;
21
+ /**
22
+ * Get current auth configuration
23
+ */
24
+ export declare function getAuthConfig(): Readonly<AuthConfig>;
25
+ /**
26
+ * Get the base URL for auth endpoints
27
+ * Falls back to API base URL if not explicitly set
28
+ */
29
+ export declare function getAuthBaseUrl(): string;
30
+ /**
31
+ * Get endpoint configuration for a specific provider
32
+ */
33
+ export declare function getProviderConfig(provider: AuthProviderName): AuthEndpointConfig | undefined;
34
+ /**
35
+ * Reset auth configuration to defaults
36
+ */
37
+ export declare function resetAuthConfig(): void;
38
+ //# sourceMappingURL=authConfig.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authConfig.d.ts","sourceRoot":"","sources":["../../sdk/auth/authConfig.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AA6BhF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAa/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,kBAAkB,GACzB,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,QAAQ,CAAC,UAAU,CAAC,CAEpD;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,gBAAgB,GACzB,kBAAkB,GAAG,SAAS,CAEhC;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,IAAI,CAEtC"}
@@ -0,0 +1,6 @@
1
+ export { AuthProvider } from "./AuthProvider";
2
+ export { useAuth } from "./useAuth";
3
+ export { configureAuth, setAuthProvider, getAuthConfig, getAuthBaseUrl, resetAuthConfig, } from "./authConfig";
4
+ export { fetchSession, initiateLogin, performLogout, AuthenticationError, } from "./authClient";
5
+ export type { UserDetails, SessionResponse, AuthStatus, AuthConfig, AuthProviderName, AuthEndpointConfig, AuthProviderProps, UseAuthReturn, LoginOptions, LogoutOptions, } from "./types";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../sdk/auth/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EACL,aAAa,EACb,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,aAAa,GACd,MAAM,SAAS,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * User details returned from the session endpoint
3
+ */
4
+ export interface UserDetails {
5
+ _id: string;
6
+ _name: string;
7
+ Role: string;
8
+ [key: string]: unknown;
9
+ }
10
+ /**
11
+ * Session response from /api/id endpoint
12
+ */
13
+ export interface SessionResponse {
14
+ userDetails: UserDetails;
15
+ staticBaseUrl: string;
16
+ buildId: string;
17
+ }
18
+ /**
19
+ * Authentication status
20
+ */
21
+ export type AuthStatus = "loading" | "authenticated" | "unauthenticated";
22
+ /**
23
+ * Authentication provider type (extensible for multiple OAuth providers)
24
+ */
25
+ export type AuthProviderName = "google" | "microsoft" | "github" | "custom";
26
+ /**
27
+ * Auth endpoint configuration for a specific provider
28
+ */
29
+ export interface AuthEndpointConfig {
30
+ /** Login endpoint path (e.g., "/api/auth/google/login") */
31
+ loginPath: string;
32
+ /** Optional logout endpoint path */
33
+ logoutPath?: string;
34
+ /** Optional callback endpoint path */
35
+ callbackPath?: string;
36
+ }
37
+ /**
38
+ * Global authentication configuration
39
+ */
40
+ export interface AuthConfig {
41
+ /** Base URL for auth endpoints (defaults to apiBaseUrl) */
42
+ baseUrl?: string;
43
+ /** Session check endpoint (default: "/api/id") */
44
+ sessionEndpoint: string;
45
+ /** Auth provider configurations */
46
+ providers: Partial<Record<AuthProviderName, AuthEndpointConfig>>;
47
+ /** Default provider to use for login */
48
+ defaultProvider: AuthProviderName;
49
+ /** Auto-redirect to login when unauthenticated */
50
+ autoRedirect: boolean;
51
+ /** Custom redirect URL (if not using provider's login path) */
52
+ loginRedirectUrl?: string;
53
+ /** URL to redirect after successful login */
54
+ callbackUrl?: string;
55
+ /** Session check interval in milliseconds (0 to disable) */
56
+ sessionCheckInterval: number;
57
+ /** Retry configuration for session check */
58
+ retry: {
59
+ count: number;
60
+ delay: number;
61
+ };
62
+ /** React Query stale time for session data */
63
+ staleTime: number;
64
+ }
65
+ /**
66
+ * AuthProvider component props
67
+ */
68
+ export interface AuthProviderProps {
69
+ children: React.ReactNode;
70
+ /** Override global config for this provider instance */
71
+ config?: Partial<AuthConfig>;
72
+ /** Callback when authentication status changes */
73
+ onAuthChange?: (status: AuthStatus, user: UserDetails | null) => void;
74
+ /** Callback on authentication error */
75
+ onError?: (error: Error) => void;
76
+ /** Custom loading component */
77
+ loadingComponent?: React.ReactNode;
78
+ /** Custom unauthenticated component (shown when autoRedirect is false) */
79
+ unauthenticatedComponent?: React.ReactNode;
80
+ /** Disable automatic session check on mount */
81
+ skipInitialCheck?: boolean;
82
+ }
83
+ /**
84
+ * Options for login operation
85
+ */
86
+ export interface LoginOptions {
87
+ /** URL to redirect after successful login */
88
+ callbackUrl?: string;
89
+ /** Additional query parameters for login URL */
90
+ params?: Record<string, string>;
91
+ }
92
+ /**
93
+ * Options for logout operation
94
+ */
95
+ export interface LogoutOptions {
96
+ /** URL to redirect after logout */
97
+ redirectUrl?: string;
98
+ /** Whether to call logout endpoint (default: true) */
99
+ callLogoutEndpoint?: boolean;
100
+ }
101
+ /**
102
+ * Return type for useAuth hook
103
+ */
104
+ export interface UseAuthReturn {
105
+ /** Current authenticated user (null if not authenticated) */
106
+ user: UserDetails | null;
107
+ /** Static base URL from session */
108
+ staticBaseUrl: string | null;
109
+ /** Build ID from session */
110
+ buildId: string | null;
111
+ /** Current authentication status */
112
+ status: AuthStatus;
113
+ /** Convenience boolean for authenticated state */
114
+ isAuthenticated: boolean;
115
+ /** Convenience boolean for loading state */
116
+ isLoading: boolean;
117
+ /**
118
+ * Initiate login flow
119
+ * @param provider - Auth provider to use (defaults to configured default)
120
+ * @param options - Additional options for login
121
+ */
122
+ login: (provider?: AuthProviderName, options?: LoginOptions) => void;
123
+ /**
124
+ * Logout the current user
125
+ * @param options - Additional options for logout
126
+ */
127
+ logout: (options?: LogoutOptions) => Promise<void>;
128
+ /**
129
+ * Manually refresh the session
130
+ */
131
+ refreshSession: () => Promise<SessionResponse | null>;
132
+ /**
133
+ * Check if user has a specific role
134
+ */
135
+ hasRole: (role: string) => boolean;
136
+ /**
137
+ * Check if user has any of the specified roles
138
+ */
139
+ hasAnyRole: (roles: string[]) => boolean;
140
+ /** Last authentication error */
141
+ error: Error | null;
142
+ /** Clear the current error */
143
+ clearError: () => void;
144
+ }
145
+ /**
146
+ * Auth context value (internal)
147
+ */
148
+ export interface AuthContextValue extends UseAuthReturn {
149
+ /** Internal: force re-check session */
150
+ _forceCheck: () => void;
151
+ }
152
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../sdk/auth/types.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,WAAW,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,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,cAAc,EAAE,MAAM,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC;IAEtD;;OAEG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnC;;OAEG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC;IAMzC,gCAAgC;IAChC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,8BAA8B;IAC9B,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACrD,uCAAuC;IACvC,WAAW,EAAE,MAAM,IAAI,CAAC;CACzB"}
@@ -0,0 +1,27 @@
1
+ import type { UseAuthReturn } from "./types";
2
+ /**
3
+ * Hook to access authentication state and operations
4
+ *
5
+ * Must be used within an AuthProvider component.
6
+ *
7
+ * @example
8
+ * ```tsx
9
+ * function UserProfile() {
10
+ * const { user, isAuthenticated, logout } = useAuth();
11
+ *
12
+ * if (!isAuthenticated) {
13
+ * return <div>Please log in</div>;
14
+ * }
15
+ *
16
+ * return (
17
+ * <div>
18
+ * <h1>Welcome, {user._name}</h1>
19
+ * <p>Role: {user.Role}</p>
20
+ * <button onClick={() => logout()}>Logout</button>
21
+ * </div>
22
+ * );
23
+ * }
24
+ * ```
25
+ */
26
+ export declare function useAuth(): UseAuthReturn;
27
+ //# sourceMappingURL=useAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../sdk/auth/useAuth.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,OAAO,IAAI,aAAa,CAkCvC"}