@chemmangat/msal-next 3.1.7 → 3.1.8

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [3.1.6] - 2026-03-05
5
+ ## [3.1.7] - 2026-03-05
6
6
 
7
7
  ### 🔄 Breaking Change - Redirect-Only Flow
8
8
 
package/README.md CHANGED
@@ -5,7 +5,7 @@ Production-grade MSAL authentication library for Next.js App Router with minimal
5
5
  [![npm version](https://badge.fury.io/js/@chemmangat%2Fmsal-next.svg)](https://www.npmjs.com/package/@chemmangat/msal-next)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
- > **📦 Current Version: 3.1.6** - Redirect-only authentication (popup support removed). [See changelog](./CHANGELOG.md)
8
+ > **📦 Current Version: 3.1.7** - Redirect-only authentication (popup support removed). [See changelog](./CHANGELOG.md)
9
9
 
10
10
  > **⚠️ Important:** If you're on v3.0.6 or v3.0.7, please update immediately - those versions have a critical popup authentication bug.
11
11
 
package/dist/index.d.mts CHANGED
@@ -5,96 +5,276 @@ import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'r
5
5
  import { NextRequest, NextResponse } from 'next/server';
6
6
  export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
7
7
 
8
+ /**
9
+ * Type definitions for @chemmangat/msal-next
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+
8
14
  /**
9
15
  * Custom token claims interface for TypeScript generics
10
- * Extend this interface to add your custom claims
16
+ *
17
+ * @remarks
18
+ * Extend this interface to add type-safe custom claims from your Azure AD tokens.
19
+ * This is useful when you have custom claims configured in your Azure AD app registration.
11
20
  *
12
21
  * @example
13
22
  * ```tsx
23
+ * // Define your custom claims
14
24
  * interface MyCustomClaims extends CustomTokenClaims {
15
25
  * roles: string[];
16
26
  * department: string;
27
+ * employeeId: string;
17
28
  * }
18
29
  *
19
- * const claims = account.idTokenClaims as MyCustomClaims;
30
+ * // Use with type safety
31
+ * const { account } = useMsalAuth();
32
+ * const claims = account?.idTokenClaims as MyCustomClaims;
33
+ *
34
+ * console.log(claims.roles); // Type-safe!
35
+ * console.log(claims.department); // Type-safe!
20
36
  * ```
21
37
  */
22
38
  interface CustomTokenClaims {
23
39
  [key: string]: any;
24
40
  }
41
+ /**
42
+ * Configuration options for MSAL authentication
43
+ *
44
+ * @remarks
45
+ * This interface defines all available configuration options for the MSAL provider.
46
+ * Most options have sensible defaults and only clientId is required.
47
+ */
25
48
  interface MsalAuthConfig {
26
49
  /**
27
50
  * Azure AD Application (client) ID
51
+ *
52
+ * @remarks
53
+ * Required. Get this from your Azure AD app registration.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * clientId: "12345678-1234-1234-1234-123456789012"
58
+ * ```
28
59
  */
29
60
  clientId: string;
30
61
  /**
31
- * Azure AD Directory (tenant) ID (optional for multi-tenant)
62
+ * Azure AD Directory (tenant) ID
63
+ *
64
+ * @remarks
65
+ * Optional. Required for single-tenant apps.
66
+ * Omit for multi-tenant apps (use authorityType: 'common' instead).
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * tenantId: "87654321-4321-4321-4321-210987654321"
71
+ * ```
32
72
  */
33
73
  tenantId?: string;
34
74
  /**
35
- * Authority type: 'common' for multi-tenant, 'organizations', 'consumers', or 'tenant' for single-tenant
36
- * @default 'common'
75
+ * Authority type for authentication
76
+ *
77
+ * @remarks
78
+ * - 'common': Multi-tenant (any Azure AD tenant)
79
+ * - 'organizations': Any organizational Azure AD tenant
80
+ * - 'consumers': Microsoft personal accounts only
81
+ * - 'tenant': Single-tenant (requires tenantId)
82
+ *
83
+ * @defaultValue 'common'
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * // Multi-tenant SaaS app
88
+ * authorityType: 'common'
89
+ *
90
+ * // Single-tenant enterprise app
91
+ * authorityType: 'tenant'
92
+ * tenantId: "your-tenant-id"
93
+ * ```
37
94
  */
38
95
  authorityType?: 'common' | 'organizations' | 'consumers' | 'tenant';
39
96
  /**
40
97
  * Redirect URI after authentication
41
- * @default window.location.origin
98
+ *
99
+ * @remarks
100
+ * Must match a redirect URI configured in your Azure AD app registration.
101
+ *
102
+ * @defaultValue window.location.origin
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * redirectUri: "https://myapp.com/auth/callback"
107
+ * ```
42
108
  */
43
109
  redirectUri?: string;
44
110
  /**
45
111
  * Post logout redirect URI
46
- * @default redirectUri
112
+ *
113
+ * @remarks
114
+ * Where to redirect after logout. Defaults to redirectUri if not specified.
115
+ *
116
+ * @defaultValue redirectUri
117
+ *
118
+ * @example
119
+ * ```tsx
120
+ * postLogoutRedirectUri: "https://myapp.com"
121
+ * ```
47
122
  */
48
123
  postLogoutRedirectUri?: string;
49
124
  /**
50
125
  * Default scopes for authentication
51
- * @default ['User.Read']
126
+ *
127
+ * @remarks
128
+ * Scopes define what permissions your app requests.
129
+ * Common scopes: 'User.Read', 'Mail.Read', 'Calendars.Read'
130
+ *
131
+ * @defaultValue ['User.Read']
132
+ *
133
+ * @example
134
+ * ```tsx
135
+ * scopes: ['User.Read', 'Mail.Read', 'Calendars.Read']
136
+ * ```
52
137
  */
53
138
  scopes?: string[];
54
139
  /**
55
- * Cache location: 'sessionStorage', 'localStorage', or 'memoryStorage'
56
- * @default 'sessionStorage'
140
+ * Cache location for tokens
141
+ *
142
+ * @remarks
143
+ * - 'sessionStorage': Tokens cleared when browser tab closes (more secure)
144
+ * - 'localStorage': Tokens persist across browser sessions
145
+ * - 'memoryStorage': Tokens only in memory (most secure, but lost on refresh)
146
+ *
147
+ * @defaultValue 'sessionStorage'
148
+ *
149
+ * @example
150
+ * ```tsx
151
+ * cacheLocation: 'sessionStorage'
152
+ * ```
57
153
  */
58
154
  cacheLocation?: 'sessionStorage' | 'localStorage' | 'memoryStorage';
59
155
  /**
60
- * Store auth state in cookie (for IE11/Edge legacy)
61
- * @default false
156
+ * Store auth state in cookie
157
+ *
158
+ * @remarks
159
+ * Enable for IE11/Edge legacy support. Not needed for modern browsers.
160
+ *
161
+ * @defaultValue false
62
162
  */
63
163
  storeAuthStateInCookie?: boolean;
64
164
  /**
65
165
  * Navigate to login request URL after authentication
66
- * @default true
166
+ *
167
+ * @remarks
168
+ * If true, redirects to the page that initiated login after successful auth.
169
+ *
170
+ * @defaultValue true
67
171
  */
68
172
  navigateToLoginRequestUrl?: boolean;
69
173
  /**
70
- * Custom MSAL configuration (overrides all other options)
174
+ * Custom MSAL configuration
175
+ *
176
+ * @remarks
177
+ * Advanced: Provide a complete MSAL configuration object.
178
+ * This overrides all other configuration options.
179
+ *
180
+ * @example
181
+ * ```tsx
182
+ * msalConfig: {
183
+ * auth: {
184
+ * clientId: "your-client-id",
185
+ * authority: "https://login.microsoftonline.com/your-tenant-id",
186
+ * },
187
+ * cache: {
188
+ * cacheLocation: "sessionStorage",
189
+ * },
190
+ * }
191
+ * ```
71
192
  */
72
193
  msalConfig?: Configuration;
73
194
  /**
74
195
  * Enable debug logging
75
- * @default false
196
+ *
197
+ * @remarks
198
+ * Logs authentication events to the console. Useful for troubleshooting.
199
+ *
200
+ * @defaultValue false
201
+ *
202
+ * @example
203
+ * ```tsx
204
+ * enableLogging: true
205
+ * ```
76
206
  */
77
207
  enableLogging?: boolean;
78
208
  /**
79
209
  * Custom logger callback
210
+ *
211
+ * @remarks
212
+ * Advanced: Provide a custom function to handle MSAL logs.
213
+ *
214
+ * @example
215
+ * ```tsx
216
+ * loggerCallback: (level, message, containsPii) => {
217
+ * if (level === LogLevel.Error) {
218
+ * console.error('MSAL Error:', message);
219
+ * }
220
+ * }
221
+ * ```
80
222
  */
81
223
  loggerCallback?: (level: LogLevel, message: string, containsPii: boolean) => void;
82
224
  /**
83
- * Allowed redirect URIs for validation (optional but recommended)
84
- * Helps prevent open redirect vulnerabilities
85
- * @example ['https://myapp.com', 'http://localhost:3000']
225
+ * Allowed redirect URIs for validation
226
+ *
227
+ * @remarks
228
+ * Security: Whitelist of allowed redirect URIs to prevent open redirect vulnerabilities.
229
+ * Recommended for production apps.
230
+ *
231
+ * @example
232
+ * ```tsx
233
+ * allowedRedirectUris: [
234
+ * 'https://myapp.com',
235
+ * 'https://staging.myapp.com',
236
+ * 'http://localhost:3000'
237
+ * ]
238
+ * ```
86
239
  */
87
240
  allowedRedirectUris?: string[];
88
241
  /**
89
242
  * Loading component to show while MSAL initializes
243
+ *
244
+ * @remarks
245
+ * Custom React component to display during MSAL initialization.
246
+ *
247
+ * @example
248
+ * ```tsx
249
+ * loadingComponent: <div className="spinner">Loading...</div>
250
+ * ```
90
251
  */
91
252
  loadingComponent?: ReactNode;
92
253
  /**
93
- * Callback invoked after MSAL initialization completes successfully
254
+ * Callback invoked after MSAL initialization completes
255
+ *
256
+ * @remarks
257
+ * Use this to perform actions after MSAL is ready, such as logging or analytics.
258
+ *
259
+ * @example
260
+ * ```tsx
261
+ * onInitialized: (instance) => {
262
+ * console.log('MSAL initialized with', instance.getAllAccounts().length, 'accounts');
263
+ * }
264
+ * ```
94
265
  */
95
266
  onInitialized?: (instance: IPublicClientApplication) => void;
96
267
  }
268
+ /**
269
+ * Props for MsalAuthProvider component
270
+ *
271
+ * @remarks
272
+ * Extends MsalAuthConfig with React children prop
273
+ */
97
274
  interface MsalAuthProviderProps extends MsalAuthConfig {
275
+ /**
276
+ * Child components to wrap with authentication context
277
+ */
98
278
  children: ReactNode;
99
279
  }
100
280
 
package/dist/index.d.ts CHANGED
@@ -5,96 +5,276 @@ import { ReactNode, CSSProperties, Component, ErrorInfo, ComponentType } from 'r
5
5
  import { NextRequest, NextResponse } from 'next/server';
6
6
  export { useAccount, useIsAuthenticated, useMsal } from '@azure/msal-react';
7
7
 
8
+ /**
9
+ * Type definitions for @chemmangat/msal-next
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+
8
14
  /**
9
15
  * Custom token claims interface for TypeScript generics
10
- * Extend this interface to add your custom claims
16
+ *
17
+ * @remarks
18
+ * Extend this interface to add type-safe custom claims from your Azure AD tokens.
19
+ * This is useful when you have custom claims configured in your Azure AD app registration.
11
20
  *
12
21
  * @example
13
22
  * ```tsx
23
+ * // Define your custom claims
14
24
  * interface MyCustomClaims extends CustomTokenClaims {
15
25
  * roles: string[];
16
26
  * department: string;
27
+ * employeeId: string;
17
28
  * }
18
29
  *
19
- * const claims = account.idTokenClaims as MyCustomClaims;
30
+ * // Use with type safety
31
+ * const { account } = useMsalAuth();
32
+ * const claims = account?.idTokenClaims as MyCustomClaims;
33
+ *
34
+ * console.log(claims.roles); // Type-safe!
35
+ * console.log(claims.department); // Type-safe!
20
36
  * ```
21
37
  */
22
38
  interface CustomTokenClaims {
23
39
  [key: string]: any;
24
40
  }
41
+ /**
42
+ * Configuration options for MSAL authentication
43
+ *
44
+ * @remarks
45
+ * This interface defines all available configuration options for the MSAL provider.
46
+ * Most options have sensible defaults and only clientId is required.
47
+ */
25
48
  interface MsalAuthConfig {
26
49
  /**
27
50
  * Azure AD Application (client) ID
51
+ *
52
+ * @remarks
53
+ * Required. Get this from your Azure AD app registration.
54
+ *
55
+ * @example
56
+ * ```tsx
57
+ * clientId: "12345678-1234-1234-1234-123456789012"
58
+ * ```
28
59
  */
29
60
  clientId: string;
30
61
  /**
31
- * Azure AD Directory (tenant) ID (optional for multi-tenant)
62
+ * Azure AD Directory (tenant) ID
63
+ *
64
+ * @remarks
65
+ * Optional. Required for single-tenant apps.
66
+ * Omit for multi-tenant apps (use authorityType: 'common' instead).
67
+ *
68
+ * @example
69
+ * ```tsx
70
+ * tenantId: "87654321-4321-4321-4321-210987654321"
71
+ * ```
32
72
  */
33
73
  tenantId?: string;
34
74
  /**
35
- * Authority type: 'common' for multi-tenant, 'organizations', 'consumers', or 'tenant' for single-tenant
36
- * @default 'common'
75
+ * Authority type for authentication
76
+ *
77
+ * @remarks
78
+ * - 'common': Multi-tenant (any Azure AD tenant)
79
+ * - 'organizations': Any organizational Azure AD tenant
80
+ * - 'consumers': Microsoft personal accounts only
81
+ * - 'tenant': Single-tenant (requires tenantId)
82
+ *
83
+ * @defaultValue 'common'
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * // Multi-tenant SaaS app
88
+ * authorityType: 'common'
89
+ *
90
+ * // Single-tenant enterprise app
91
+ * authorityType: 'tenant'
92
+ * tenantId: "your-tenant-id"
93
+ * ```
37
94
  */
38
95
  authorityType?: 'common' | 'organizations' | 'consumers' | 'tenant';
39
96
  /**
40
97
  * Redirect URI after authentication
41
- * @default window.location.origin
98
+ *
99
+ * @remarks
100
+ * Must match a redirect URI configured in your Azure AD app registration.
101
+ *
102
+ * @defaultValue window.location.origin
103
+ *
104
+ * @example
105
+ * ```tsx
106
+ * redirectUri: "https://myapp.com/auth/callback"
107
+ * ```
42
108
  */
43
109
  redirectUri?: string;
44
110
  /**
45
111
  * Post logout redirect URI
46
- * @default redirectUri
112
+ *
113
+ * @remarks
114
+ * Where to redirect after logout. Defaults to redirectUri if not specified.
115
+ *
116
+ * @defaultValue redirectUri
117
+ *
118
+ * @example
119
+ * ```tsx
120
+ * postLogoutRedirectUri: "https://myapp.com"
121
+ * ```
47
122
  */
48
123
  postLogoutRedirectUri?: string;
49
124
  /**
50
125
  * Default scopes for authentication
51
- * @default ['User.Read']
126
+ *
127
+ * @remarks
128
+ * Scopes define what permissions your app requests.
129
+ * Common scopes: 'User.Read', 'Mail.Read', 'Calendars.Read'
130
+ *
131
+ * @defaultValue ['User.Read']
132
+ *
133
+ * @example
134
+ * ```tsx
135
+ * scopes: ['User.Read', 'Mail.Read', 'Calendars.Read']
136
+ * ```
52
137
  */
53
138
  scopes?: string[];
54
139
  /**
55
- * Cache location: 'sessionStorage', 'localStorage', or 'memoryStorage'
56
- * @default 'sessionStorage'
140
+ * Cache location for tokens
141
+ *
142
+ * @remarks
143
+ * - 'sessionStorage': Tokens cleared when browser tab closes (more secure)
144
+ * - 'localStorage': Tokens persist across browser sessions
145
+ * - 'memoryStorage': Tokens only in memory (most secure, but lost on refresh)
146
+ *
147
+ * @defaultValue 'sessionStorage'
148
+ *
149
+ * @example
150
+ * ```tsx
151
+ * cacheLocation: 'sessionStorage'
152
+ * ```
57
153
  */
58
154
  cacheLocation?: 'sessionStorage' | 'localStorage' | 'memoryStorage';
59
155
  /**
60
- * Store auth state in cookie (for IE11/Edge legacy)
61
- * @default false
156
+ * Store auth state in cookie
157
+ *
158
+ * @remarks
159
+ * Enable for IE11/Edge legacy support. Not needed for modern browsers.
160
+ *
161
+ * @defaultValue false
62
162
  */
63
163
  storeAuthStateInCookie?: boolean;
64
164
  /**
65
165
  * Navigate to login request URL after authentication
66
- * @default true
166
+ *
167
+ * @remarks
168
+ * If true, redirects to the page that initiated login after successful auth.
169
+ *
170
+ * @defaultValue true
67
171
  */
68
172
  navigateToLoginRequestUrl?: boolean;
69
173
  /**
70
- * Custom MSAL configuration (overrides all other options)
174
+ * Custom MSAL configuration
175
+ *
176
+ * @remarks
177
+ * Advanced: Provide a complete MSAL configuration object.
178
+ * This overrides all other configuration options.
179
+ *
180
+ * @example
181
+ * ```tsx
182
+ * msalConfig: {
183
+ * auth: {
184
+ * clientId: "your-client-id",
185
+ * authority: "https://login.microsoftonline.com/your-tenant-id",
186
+ * },
187
+ * cache: {
188
+ * cacheLocation: "sessionStorage",
189
+ * },
190
+ * }
191
+ * ```
71
192
  */
72
193
  msalConfig?: Configuration;
73
194
  /**
74
195
  * Enable debug logging
75
- * @default false
196
+ *
197
+ * @remarks
198
+ * Logs authentication events to the console. Useful for troubleshooting.
199
+ *
200
+ * @defaultValue false
201
+ *
202
+ * @example
203
+ * ```tsx
204
+ * enableLogging: true
205
+ * ```
76
206
  */
77
207
  enableLogging?: boolean;
78
208
  /**
79
209
  * Custom logger callback
210
+ *
211
+ * @remarks
212
+ * Advanced: Provide a custom function to handle MSAL logs.
213
+ *
214
+ * @example
215
+ * ```tsx
216
+ * loggerCallback: (level, message, containsPii) => {
217
+ * if (level === LogLevel.Error) {
218
+ * console.error('MSAL Error:', message);
219
+ * }
220
+ * }
221
+ * ```
80
222
  */
81
223
  loggerCallback?: (level: LogLevel, message: string, containsPii: boolean) => void;
82
224
  /**
83
- * Allowed redirect URIs for validation (optional but recommended)
84
- * Helps prevent open redirect vulnerabilities
85
- * @example ['https://myapp.com', 'http://localhost:3000']
225
+ * Allowed redirect URIs for validation
226
+ *
227
+ * @remarks
228
+ * Security: Whitelist of allowed redirect URIs to prevent open redirect vulnerabilities.
229
+ * Recommended for production apps.
230
+ *
231
+ * @example
232
+ * ```tsx
233
+ * allowedRedirectUris: [
234
+ * 'https://myapp.com',
235
+ * 'https://staging.myapp.com',
236
+ * 'http://localhost:3000'
237
+ * ]
238
+ * ```
86
239
  */
87
240
  allowedRedirectUris?: string[];
88
241
  /**
89
242
  * Loading component to show while MSAL initializes
243
+ *
244
+ * @remarks
245
+ * Custom React component to display during MSAL initialization.
246
+ *
247
+ * @example
248
+ * ```tsx
249
+ * loadingComponent: <div className="spinner">Loading...</div>
250
+ * ```
90
251
  */
91
252
  loadingComponent?: ReactNode;
92
253
  /**
93
- * Callback invoked after MSAL initialization completes successfully
254
+ * Callback invoked after MSAL initialization completes
255
+ *
256
+ * @remarks
257
+ * Use this to perform actions after MSAL is ready, such as logging or analytics.
258
+ *
259
+ * @example
260
+ * ```tsx
261
+ * onInitialized: (instance) => {
262
+ * console.log('MSAL initialized with', instance.getAllAccounts().length, 'accounts');
263
+ * }
264
+ * ```
94
265
  */
95
266
  onInitialized?: (instance: IPublicClientApplication) => void;
96
267
  }
268
+ /**
269
+ * Props for MsalAuthProvider component
270
+ *
271
+ * @remarks
272
+ * Extends MsalAuthConfig with React children prop
273
+ */
97
274
  interface MsalAuthProviderProps extends MsalAuthConfig {
275
+ /**
276
+ * Child components to wrap with authentication context
277
+ */
98
278
  children: ReactNode;
99
279
  }
100
280