@chemmangat/msal-next 3.0.4 → 3.0.5

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
@@ -3,7 +3,6 @@ import { Configuration, LogLevel, IPublicClientApplication, PublicClientApplicat
3
3
  export { AccountInfo } from '@azure/msal-browser';
4
4
  import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'react';
5
5
  import { NextRequest, NextResponse } from 'next/server';
6
- export { ServerSession } from './server.mjs';
7
6
  export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
8
7
 
9
8
  /**
@@ -912,4 +911,24 @@ interface AuthMiddlewareConfig {
912
911
  */
913
912
  declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
914
913
 
915
- export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type RetryConfig, 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 };
914
+ interface ServerSession {
915
+ /**
916
+ * Whether user is authenticated
917
+ */
918
+ isAuthenticated: boolean;
919
+ /**
920
+ * User's account ID from MSAL cache
921
+ */
922
+ accountId?: string;
923
+ /**
924
+ * User's username/email
925
+ */
926
+ username?: string;
927
+ /**
928
+ * Access token (if available in cookie)
929
+ * @deprecated Storing tokens in cookies is not recommended for security reasons
930
+ */
931
+ accessToken?: string;
932
+ }
933
+
934
+ export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, 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 };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,6 @@ import { Configuration, LogLevel, IPublicClientApplication, PublicClientApplicat
3
3
  export { AccountInfo } from '@azure/msal-browser';
4
4
  import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'react';
5
5
  import { NextRequest, NextResponse } from 'next/server';
6
- export { ServerSession } from './server.js';
7
6
  export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
8
7
 
9
8
  /**
@@ -912,4 +911,24 @@ interface AuthMiddlewareConfig {
912
911
  */
913
912
  declare function createAuthMiddleware(config?: AuthMiddlewareConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
914
913
 
915
- export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, type RetryConfig, 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 };
914
+ interface ServerSession {
915
+ /**
916
+ * Whether user is authenticated
917
+ */
918
+ isAuthenticated: boolean;
919
+ /**
920
+ * User's account ID from MSAL cache
921
+ */
922
+ accountId?: string;
923
+ /**
924
+ * User's username/email
925
+ */
926
+ username?: string;
927
+ /**
928
+ * Access token (if available in cookie)
929
+ * @deprecated Storing tokens in cookies is not recommended for security reasons
930
+ */
931
+ accessToken?: string;
932
+ }
933
+
934
+ export { AuthGuard, type AuthGuardProps, type AuthMiddlewareConfig, AuthStatus, type AuthStatusProps, type CustomTokenClaims, type DebugLoggerConfig, ErrorBoundary, type ErrorBoundaryProps, type GraphApiOptions, MSALProvider, MicrosoftSignInButton, type MicrosoftSignInButtonProps, type MsalAuthConfig, MsalAuthProvider, type MsalAuthProviderProps, 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 };
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  "use strict";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
package/dist/index.mjs CHANGED
@@ -1,11 +1,4 @@
1
- import {
2
- isValidAccountData,
3
- isValidRedirectUri,
4
- isValidScope,
5
- safeJsonParse,
6
- sanitizeError,
7
- validateScopes
8
- } from "./chunk-AD43IVG7.mjs";
1
+ "use client";
9
2
 
10
3
  // src/components/MsalAuthProvider.tsx
11
4
  import { MsalProvider } from "@azure/msal-react";
@@ -14,6 +7,51 @@ import { useEffect, useState, useRef } from "react";
14
7
 
15
8
  // src/utils/createMsalConfig.ts
16
9
  import { LogLevel } from "@azure/msal-browser";
10
+
11
+ // src/utils/validation.ts
12
+ function safeJsonParse(jsonString, validator) {
13
+ try {
14
+ const parsed = JSON.parse(jsonString);
15
+ if (validator(parsed)) {
16
+ return parsed;
17
+ }
18
+ console.warn("[Validation] JSON validation failed");
19
+ return null;
20
+ } catch (error) {
21
+ console.error("[Validation] JSON parse error:", error);
22
+ return null;
23
+ }
24
+ }
25
+ function isValidAccountData(data) {
26
+ return typeof data === "object" && data !== null && typeof data.homeAccountId === "string" && data.homeAccountId.length > 0 && typeof data.username === "string" && data.username.length > 0 && (data.name === void 0 || typeof data.name === "string");
27
+ }
28
+ function sanitizeError(error) {
29
+ if (error instanceof Error) {
30
+ const message = error.message;
31
+ const sanitized = message.replace(/[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g, "[TOKEN_REDACTED]").replace(/[a-f0-9]{32,}/gi, "[SECRET_REDACTED]").replace(/Bearer\s+[^\s]+/gi, "Bearer [REDACTED]");
32
+ return sanitized;
33
+ }
34
+ return "An unexpected error occurred";
35
+ }
36
+ function isValidRedirectUri(uri, allowedOrigins) {
37
+ try {
38
+ const url = new URL(uri);
39
+ return allowedOrigins.some((allowed) => {
40
+ const allowedUrl = new URL(allowed);
41
+ return url.origin === allowedUrl.origin;
42
+ });
43
+ } catch {
44
+ return false;
45
+ }
46
+ }
47
+ function isValidScope(scope) {
48
+ return /^[a-zA-Z0-9._-]+$/.test(scope);
49
+ }
50
+ function validateScopes(scopes) {
51
+ return Array.isArray(scopes) && scopes.every(isValidScope);
52
+ }
53
+
54
+ // src/utils/createMsalConfig.ts
17
55
  function createMsalConfig(config) {
18
56
  if (config.msalConfig) {
19
57
  return config.msalConfig;
package/dist/server.mjs CHANGED
@@ -1,10 +1,25 @@
1
- import {
2
- isValidAccountData,
3
- safeJsonParse
4
- } from "./chunk-AD43IVG7.mjs";
5
-
6
1
  // src/utils/getServerSession.ts
7
2
  import { cookies, headers } from "next/headers";
3
+
4
+ // src/utils/validation.ts
5
+ function safeJsonParse(jsonString, validator) {
6
+ try {
7
+ const parsed = JSON.parse(jsonString);
8
+ if (validator(parsed)) {
9
+ return parsed;
10
+ }
11
+ console.warn("[Validation] JSON validation failed");
12
+ return null;
13
+ } catch (error) {
14
+ console.error("[Validation] JSON parse error:", error);
15
+ return null;
16
+ }
17
+ }
18
+ function isValidAccountData(data) {
19
+ return typeof data === "object" && data !== null && typeof data.homeAccountId === "string" && data.homeAccountId.length > 0 && typeof data.username === "string" && data.username.length > 0 && (data.name === void 0 || typeof data.name === "string");
20
+ }
21
+
22
+ // src/utils/getServerSession.ts
8
23
  async function getServerSession() {
9
24
  try {
10
25
  const cookieStore = await cookies();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chemmangat/msal-next",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Production-grade MSAL authentication package for Next.js App Router with minimal boilerplate",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -1,51 +0,0 @@
1
- // src/utils/validation.ts
2
- function safeJsonParse(jsonString, validator) {
3
- try {
4
- const parsed = JSON.parse(jsonString);
5
- if (validator(parsed)) {
6
- return parsed;
7
- }
8
- console.warn("[Validation] JSON validation failed");
9
- return null;
10
- } catch (error) {
11
- console.error("[Validation] JSON parse error:", error);
12
- return null;
13
- }
14
- }
15
- function isValidAccountData(data) {
16
- return typeof data === "object" && data !== null && typeof data.homeAccountId === "string" && data.homeAccountId.length > 0 && typeof data.username === "string" && data.username.length > 0 && (data.name === void 0 || typeof data.name === "string");
17
- }
18
- function sanitizeError(error) {
19
- if (error instanceof Error) {
20
- const message = error.message;
21
- const sanitized = message.replace(/[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}\.[A-Za-z0-9_-]{20,}/g, "[TOKEN_REDACTED]").replace(/[a-f0-9]{32,}/gi, "[SECRET_REDACTED]").replace(/Bearer\s+[^\s]+/gi, "Bearer [REDACTED]");
22
- return sanitized;
23
- }
24
- return "An unexpected error occurred";
25
- }
26
- function isValidRedirectUri(uri, allowedOrigins) {
27
- try {
28
- const url = new URL(uri);
29
- return allowedOrigins.some((allowed) => {
30
- const allowedUrl = new URL(allowed);
31
- return url.origin === allowedUrl.origin;
32
- });
33
- } catch {
34
- return false;
35
- }
36
- }
37
- function isValidScope(scope) {
38
- return /^[a-zA-Z0-9._-]+$/.test(scope);
39
- }
40
- function validateScopes(scopes) {
41
- return Array.isArray(scopes) && scopes.every(isValidScope);
42
- }
43
-
44
- export {
45
- safeJsonParse,
46
- isValidAccountData,
47
- sanitizeError,
48
- isValidRedirectUri,
49
- isValidScope,
50
- validateScopes
51
- };