@chemmangat/msal-next 4.0.0 → 4.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.
package/dist/index.d.mts CHANGED
@@ -748,24 +748,116 @@ interface UseGraphApiReturn {
748
748
  */
749
749
  declare function useGraphApi(): UseGraphApiReturn;
750
750
 
751
+ /**
752
+ * Complete Microsoft Graph User Profile Types
753
+ * Based on Microsoft Graph /me endpoint
754
+ *
755
+ * @see https://learn.microsoft.com/en-us/graph/api/user-get
756
+ */
757
+ /**
758
+ * Complete user profile from Microsoft Graph /me endpoint
759
+ *
760
+ * @remarks
761
+ * This interface includes all common fields returned by the Microsoft Graph /me endpoint.
762
+ * You can extend this interface with custom fields specific to your organization.
763
+ *
764
+ * @example
765
+ * ```tsx
766
+ * // Basic usage
767
+ * const { profile } = useUserProfile();
768
+ * console.log(profile?.department); // Now type-safe!
769
+ *
770
+ * // With custom fields
771
+ * interface MyUserProfile extends UserProfile {
772
+ * customField: string;
773
+ * }
774
+ *
775
+ * const { profile } = useUserProfile<MyUserProfile>();
776
+ * console.log(profile?.customField);
777
+ * ```
778
+ */
751
779
  interface UserProfile {
780
+ /** Unique identifier for the user */
752
781
  id: string;
782
+ /** User's display name */
753
783
  displayName: string;
784
+ /** User's first name */
754
785
  givenName: string;
786
+ /** User's last name */
755
787
  surname: string;
788
+ /** User principal name (UPN) - typically the email used for login */
756
789
  userPrincipalName: string;
790
+ /** Primary email address */
757
791
  mail: string;
792
+ /** Job title */
758
793
  jobTitle?: string;
794
+ /** Department name */
795
+ department?: string;
796
+ /** Company name */
797
+ companyName?: string;
798
+ /** Office location */
759
799
  officeLocation?: string;
800
+ /** Mobile phone number */
760
801
  mobilePhone?: string;
802
+ /** Business phone numbers */
761
803
  businessPhones?: string[];
804
+ /** Preferred language (e.g., "en-US") */
805
+ preferredLanguage?: string;
806
+ /** Employee ID */
807
+ employeeId?: string;
808
+ /** Employee hire date */
809
+ employeeHireDate?: string;
810
+ /** Employee type (e.g., "Employee", "Contractor") */
811
+ employeeType?: string;
812
+ /** Country/region */
813
+ country?: string;
814
+ /** City */
815
+ city?: string;
816
+ /** State or province */
817
+ state?: string;
818
+ /** Street address */
819
+ streetAddress?: string;
820
+ /** Postal code */
821
+ postalCode?: string;
822
+ /** Usage location (ISO 3166 country code) */
823
+ usageLocation?: string;
824
+ /** Manager's user ID */
825
+ manager?: string;
826
+ /** About me / bio */
827
+ aboutMe?: string;
828
+ /** Birthday */
829
+ birthday?: string;
830
+ /** Interests */
831
+ interests?: string[];
832
+ /** Skills */
833
+ skills?: string[];
834
+ /** Schools attended */
835
+ schools?: string[];
836
+ /** Past projects */
837
+ pastProjects?: string[];
838
+ /** Responsibilities */
839
+ responsibilities?: string[];
840
+ /** My site URL */
841
+ mySite?: string;
842
+ /** Fax number */
843
+ faxNumber?: string;
844
+ /** Account enabled status */
845
+ accountEnabled?: boolean;
846
+ /** Age group (e.g., "Adult", "Minor") */
847
+ ageGroup?: string;
848
+ /** User type (e.g., "Member", "Guest") */
849
+ userType?: string;
850
+ /** Profile photo URL (blob URL created by the library) */
762
851
  photo?: string;
763
852
  }
764
- interface UseUserProfileReturn {
853
+ /**
854
+ * Return type for useUserProfile hook
855
+ */
856
+ interface UseUserProfileReturn<T extends UserProfile = UserProfile> {
765
857
  /**
766
858
  * User profile data
767
859
  */
768
- profile: UserProfile | null;
860
+ profile: T | null;
769
861
  /**
770
862
  * Whether profile is loading
771
863
  */
@@ -783,15 +875,27 @@ interface UseUserProfileReturn {
783
875
  */
784
876
  clearCache: () => void;
785
877
  }
878
+
786
879
  /**
787
880
  * Hook for fetching and caching user profile from MS Graph
788
881
  *
882
+ * @remarks
883
+ * Supports generic type parameter for custom profile fields.
884
+ *
789
885
  * @example
790
886
  * ```tsx
887
+ * // Basic usage
791
888
  * const { profile, loading } = useUserProfile();
889
+ * console.log(profile?.department); // Now available!
890
+ *
891
+ * // With custom fields
892
+ * interface MyProfile extends UserProfile {
893
+ * customField: string;
894
+ * }
895
+ * const { profile } = useUserProfile<MyProfile>();
792
896
  * ```
793
897
  */
794
- declare function useUserProfile(): UseUserProfileReturn;
898
+ declare function useUserProfile<T extends UserProfile = UserProfile>(): UseUserProfileReturn<T>;
795
899
 
796
900
  interface UseRolesReturn {
797
901
  /**
@@ -1114,6 +1218,107 @@ declare function isValidScope(scope: string): boolean;
1114
1218
  */
1115
1219
  declare function validateScopes(scopes: string[]): boolean;
1116
1220
 
1221
+ /**
1222
+ * Development-mode configuration validator
1223
+ * Helps developers catch common configuration mistakes early
1224
+ */
1225
+
1226
+ interface ValidationResult {
1227
+ valid: boolean;
1228
+ warnings: ValidationWarning[];
1229
+ errors: ValidationError[];
1230
+ }
1231
+ interface ValidationWarning {
1232
+ field: string;
1233
+ message: string;
1234
+ fix: string;
1235
+ }
1236
+ interface ValidationError {
1237
+ field: string;
1238
+ message: string;
1239
+ fix: string;
1240
+ }
1241
+ /**
1242
+ * Validate MSAL configuration in development mode
1243
+ *
1244
+ * @remarks
1245
+ * This function only runs in development mode and caches results.
1246
+ * It checks for common configuration mistakes and provides helpful warnings.
1247
+ *
1248
+ * @example
1249
+ * ```tsx
1250
+ * const result = validateConfig({
1251
+ * clientId: process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!,
1252
+ * tenantId: process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID,
1253
+ * });
1254
+ *
1255
+ * if (!result.valid) {
1256
+ * console.warn('Configuration issues detected');
1257
+ * }
1258
+ * ```
1259
+ */
1260
+ declare function validateConfig(config: MsalAuthConfig): ValidationResult;
1261
+ /**
1262
+ * Display validation results in console with colors and emojis
1263
+ */
1264
+ declare function displayValidationResults(result: ValidationResult): void;
1265
+
1266
+ /**
1267
+ * Enhanced MSAL error class with actionable messages
1268
+ */
1269
+ declare class MsalError extends Error {
1270
+ /** Original error code from MSAL */
1271
+ readonly code?: string;
1272
+ /** Actionable fix instructions */
1273
+ readonly fix?: string;
1274
+ /** Documentation link */
1275
+ readonly docs?: string;
1276
+ /** Original error object */
1277
+ readonly originalError?: unknown;
1278
+ constructor(error: unknown);
1279
+ /**
1280
+ * Parse error and extract actionable information
1281
+ */
1282
+ private static parseError;
1283
+ /**
1284
+ * Format error for console logging with colors (development only)
1285
+ */
1286
+ toConsoleString(): string;
1287
+ /**
1288
+ * Check if error is a user cancellation (not a real error)
1289
+ */
1290
+ isUserCancellation(): boolean;
1291
+ /**
1292
+ * Check if error requires user interaction
1293
+ */
1294
+ requiresInteraction(): boolean;
1295
+ }
1296
+ /**
1297
+ * Wrap MSAL errors with enhanced error information
1298
+ *
1299
+ * @example
1300
+ * ```tsx
1301
+ * try {
1302
+ * await loginRedirect();
1303
+ * } catch (error) {
1304
+ * const msalError = wrapMsalError(error);
1305
+ *
1306
+ * if (msalError.isUserCancellation()) {
1307
+ * // User cancelled, ignore
1308
+ * return;
1309
+ * }
1310
+ *
1311
+ * console.error(msalError.toConsoleString());
1312
+ * throw msalError;
1313
+ * }
1314
+ * ```
1315
+ */
1316
+ declare function wrapMsalError(error: unknown): MsalError;
1317
+ /**
1318
+ * Create error for missing environment variable
1319
+ */
1320
+ declare function createMissingEnvVarError(varName: string): MsalError;
1321
+
1117
1322
  interface ProtectedPageProps {
1118
1323
  children: ReactNode;
1119
1324
  config: PageAuthConfig;
@@ -1224,4 +1429,4 @@ interface ServerSession {
1224
1429
  accessToken?: string;
1225
1430
  }
1226
1431
 
1227
- export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, type AuthProtectionConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type PageAuthConfig, ProtectedPage, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth, withPageAuth };
1432
+ export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, type AuthProtectionConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, MsalError, type PageAuthConfig, ProtectedPage, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type ValidationError, type ValidationResult, type ValidationWarning, type WithAuthOptions, createAuthMiddleware, createMissingEnvVarError, createMsalConfig, createRetryWrapper, createScopedLogger, displayValidationResults, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateConfig, validateScopes, withAuth, withPageAuth, wrapMsalError };
package/dist/index.d.ts CHANGED
@@ -748,24 +748,116 @@ interface UseGraphApiReturn {
748
748
  */
749
749
  declare function useGraphApi(): UseGraphApiReturn;
750
750
 
751
+ /**
752
+ * Complete Microsoft Graph User Profile Types
753
+ * Based on Microsoft Graph /me endpoint
754
+ *
755
+ * @see https://learn.microsoft.com/en-us/graph/api/user-get
756
+ */
757
+ /**
758
+ * Complete user profile from Microsoft Graph /me endpoint
759
+ *
760
+ * @remarks
761
+ * This interface includes all common fields returned by the Microsoft Graph /me endpoint.
762
+ * You can extend this interface with custom fields specific to your organization.
763
+ *
764
+ * @example
765
+ * ```tsx
766
+ * // Basic usage
767
+ * const { profile } = useUserProfile();
768
+ * console.log(profile?.department); // Now type-safe!
769
+ *
770
+ * // With custom fields
771
+ * interface MyUserProfile extends UserProfile {
772
+ * customField: string;
773
+ * }
774
+ *
775
+ * const { profile } = useUserProfile<MyUserProfile>();
776
+ * console.log(profile?.customField);
777
+ * ```
778
+ */
751
779
  interface UserProfile {
780
+ /** Unique identifier for the user */
752
781
  id: string;
782
+ /** User's display name */
753
783
  displayName: string;
784
+ /** User's first name */
754
785
  givenName: string;
786
+ /** User's last name */
755
787
  surname: string;
788
+ /** User principal name (UPN) - typically the email used for login */
756
789
  userPrincipalName: string;
790
+ /** Primary email address */
757
791
  mail: string;
792
+ /** Job title */
758
793
  jobTitle?: string;
794
+ /** Department name */
795
+ department?: string;
796
+ /** Company name */
797
+ companyName?: string;
798
+ /** Office location */
759
799
  officeLocation?: string;
800
+ /** Mobile phone number */
760
801
  mobilePhone?: string;
802
+ /** Business phone numbers */
761
803
  businessPhones?: string[];
804
+ /** Preferred language (e.g., "en-US") */
805
+ preferredLanguage?: string;
806
+ /** Employee ID */
807
+ employeeId?: string;
808
+ /** Employee hire date */
809
+ employeeHireDate?: string;
810
+ /** Employee type (e.g., "Employee", "Contractor") */
811
+ employeeType?: string;
812
+ /** Country/region */
813
+ country?: string;
814
+ /** City */
815
+ city?: string;
816
+ /** State or province */
817
+ state?: string;
818
+ /** Street address */
819
+ streetAddress?: string;
820
+ /** Postal code */
821
+ postalCode?: string;
822
+ /** Usage location (ISO 3166 country code) */
823
+ usageLocation?: string;
824
+ /** Manager's user ID */
825
+ manager?: string;
826
+ /** About me / bio */
827
+ aboutMe?: string;
828
+ /** Birthday */
829
+ birthday?: string;
830
+ /** Interests */
831
+ interests?: string[];
832
+ /** Skills */
833
+ skills?: string[];
834
+ /** Schools attended */
835
+ schools?: string[];
836
+ /** Past projects */
837
+ pastProjects?: string[];
838
+ /** Responsibilities */
839
+ responsibilities?: string[];
840
+ /** My site URL */
841
+ mySite?: string;
842
+ /** Fax number */
843
+ faxNumber?: string;
844
+ /** Account enabled status */
845
+ accountEnabled?: boolean;
846
+ /** Age group (e.g., "Adult", "Minor") */
847
+ ageGroup?: string;
848
+ /** User type (e.g., "Member", "Guest") */
849
+ userType?: string;
850
+ /** Profile photo URL (blob URL created by the library) */
762
851
  photo?: string;
763
852
  }
764
- interface UseUserProfileReturn {
853
+ /**
854
+ * Return type for useUserProfile hook
855
+ */
856
+ interface UseUserProfileReturn<T extends UserProfile = UserProfile> {
765
857
  /**
766
858
  * User profile data
767
859
  */
768
- profile: UserProfile | null;
860
+ profile: T | null;
769
861
  /**
770
862
  * Whether profile is loading
771
863
  */
@@ -783,15 +875,27 @@ interface UseUserProfileReturn {
783
875
  */
784
876
  clearCache: () => void;
785
877
  }
878
+
786
879
  /**
787
880
  * Hook for fetching and caching user profile from MS Graph
788
881
  *
882
+ * @remarks
883
+ * Supports generic type parameter for custom profile fields.
884
+ *
789
885
  * @example
790
886
  * ```tsx
887
+ * // Basic usage
791
888
  * const { profile, loading } = useUserProfile();
889
+ * console.log(profile?.department); // Now available!
890
+ *
891
+ * // With custom fields
892
+ * interface MyProfile extends UserProfile {
893
+ * customField: string;
894
+ * }
895
+ * const { profile } = useUserProfile<MyProfile>();
792
896
  * ```
793
897
  */
794
- declare function useUserProfile(): UseUserProfileReturn;
898
+ declare function useUserProfile<T extends UserProfile = UserProfile>(): UseUserProfileReturn<T>;
795
899
 
796
900
  interface UseRolesReturn {
797
901
  /**
@@ -1114,6 +1218,107 @@ declare function isValidScope(scope: string): boolean;
1114
1218
  */
1115
1219
  declare function validateScopes(scopes: string[]): boolean;
1116
1220
 
1221
+ /**
1222
+ * Development-mode configuration validator
1223
+ * Helps developers catch common configuration mistakes early
1224
+ */
1225
+
1226
+ interface ValidationResult {
1227
+ valid: boolean;
1228
+ warnings: ValidationWarning[];
1229
+ errors: ValidationError[];
1230
+ }
1231
+ interface ValidationWarning {
1232
+ field: string;
1233
+ message: string;
1234
+ fix: string;
1235
+ }
1236
+ interface ValidationError {
1237
+ field: string;
1238
+ message: string;
1239
+ fix: string;
1240
+ }
1241
+ /**
1242
+ * Validate MSAL configuration in development mode
1243
+ *
1244
+ * @remarks
1245
+ * This function only runs in development mode and caches results.
1246
+ * It checks for common configuration mistakes and provides helpful warnings.
1247
+ *
1248
+ * @example
1249
+ * ```tsx
1250
+ * const result = validateConfig({
1251
+ * clientId: process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID!,
1252
+ * tenantId: process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID,
1253
+ * });
1254
+ *
1255
+ * if (!result.valid) {
1256
+ * console.warn('Configuration issues detected');
1257
+ * }
1258
+ * ```
1259
+ */
1260
+ declare function validateConfig(config: MsalAuthConfig): ValidationResult;
1261
+ /**
1262
+ * Display validation results in console with colors and emojis
1263
+ */
1264
+ declare function displayValidationResults(result: ValidationResult): void;
1265
+
1266
+ /**
1267
+ * Enhanced MSAL error class with actionable messages
1268
+ */
1269
+ declare class MsalError extends Error {
1270
+ /** Original error code from MSAL */
1271
+ readonly code?: string;
1272
+ /** Actionable fix instructions */
1273
+ readonly fix?: string;
1274
+ /** Documentation link */
1275
+ readonly docs?: string;
1276
+ /** Original error object */
1277
+ readonly originalError?: unknown;
1278
+ constructor(error: unknown);
1279
+ /**
1280
+ * Parse error and extract actionable information
1281
+ */
1282
+ private static parseError;
1283
+ /**
1284
+ * Format error for console logging with colors (development only)
1285
+ */
1286
+ toConsoleString(): string;
1287
+ /**
1288
+ * Check if error is a user cancellation (not a real error)
1289
+ */
1290
+ isUserCancellation(): boolean;
1291
+ /**
1292
+ * Check if error requires user interaction
1293
+ */
1294
+ requiresInteraction(): boolean;
1295
+ }
1296
+ /**
1297
+ * Wrap MSAL errors with enhanced error information
1298
+ *
1299
+ * @example
1300
+ * ```tsx
1301
+ * try {
1302
+ * await loginRedirect();
1303
+ * } catch (error) {
1304
+ * const msalError = wrapMsalError(error);
1305
+ *
1306
+ * if (msalError.isUserCancellation()) {
1307
+ * // User cancelled, ignore
1308
+ * return;
1309
+ * }
1310
+ *
1311
+ * console.error(msalError.toConsoleString());
1312
+ * throw msalError;
1313
+ * }
1314
+ * ```
1315
+ */
1316
+ declare function wrapMsalError(error: unknown): MsalError;
1317
+ /**
1318
+ * Create error for missing environment variable
1319
+ */
1320
+ declare function createMissingEnvVarError(varName: string): MsalError;
1321
+
1117
1322
  interface ProtectedPageProps {
1118
1323
  children: ReactNode;
1119
1324
  config: PageAuthConfig;
@@ -1224,4 +1429,4 @@ interface ServerSession {
1224
1429
  accessToken?: string;
1225
1430
  }
1226
1431
 
1227
- export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, type AuthProtectionConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type PageAuthConfig, ProtectedPage, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type WithAuthOptions, createAuthMiddleware, createMsalConfig, createRetryWrapper, createScopedLogger, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateScopes, withAuth, withPageAuth };
1432
+ export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, type AuthProtectionConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, MsalError, type PageAuthConfig, ProtectedPage, type RetryConfig, type ServerSession, SignOutButton, type SignOutButtonProps, type UseGraphApiReturn, type UseMsalAuthReturn, type UseRolesReturn, type UseUserProfileReturn, UserAvatar, type UserAvatarProps, type UserProfile, type ValidatedAccountData, type ValidationError, type ValidationResult, type ValidationWarning, type WithAuthOptions, createAuthMiddleware, createMissingEnvVarError, createMsalConfig, createRetryWrapper, createScopedLogger, displayValidationResults, getDebugLogger, getMsalInstance, isValidAccountData, isValidRedirectUri, isValidScope, retryWithBackoff, safeJsonParse, sanitizeError, useGraphApi, useMsalAuth, useRoles, useUserProfile, validateConfig, validateScopes, withAuth, withPageAuth, wrapMsalError };