mulink 1.2.2 → 1.2.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.
@@ -1767,6 +1767,42 @@ export class BaseApiClient {
1767
1767
  // Handle HTTP errors
1768
1768
  if (!response.ok) {
1769
1769
  const errorData = await this.parseErrorResponse(response)
1770
+
1771
+ // Handle token refresh for 401 errors (token expired)
1772
+ if (response.status === 401 && !skipAuth && ${this.configuration.auth?.enabled ? "true" : "false"} && attempt === 0) {
1773
+ try {
1774
+ // Try to refresh token using auth client
1775
+ const authModule = await import('${authPath}').catch(() => null)
1776
+ if (authModule?.authClient || authModule?.AuthClient) {
1777
+ const authClient = authModule.authClient || authModule.AuthClient.getInstance()
1778
+ const tokens = authClient.getTokens?.()
1779
+
1780
+ if (tokens?.refresh_token) {
1781
+ try {
1782
+ await authClient.refreshToken(tokens.refresh_token)
1783
+ // Token refreshed successfully - retry request with new token
1784
+ console.log('[API Client] Token refreshed, retrying request')
1785
+ // Update auth headers and retry
1786
+ requestConfig.headers = {
1787
+ ...requestConfig.headers,
1788
+ ...(await this.getAuthHeaders())
1789
+ }
1790
+ // Continue to retry the request
1791
+ continue
1792
+ } catch (refreshError: any) {
1793
+ // Token refresh failed - proceed with error handling
1794
+ console.warn('[API Client] Token refresh failed:', refreshError)
1795
+ }
1796
+ }
1797
+ }
1798
+ } catch (refreshAttemptError) {
1799
+ // Auth client not available - proceed with error handling
1800
+ if (process.env.NODE_ENV === 'development') {
1801
+ console.warn('[API Client] Could not attempt token refresh:', refreshAttemptError)
1802
+ }
1803
+ }
1804
+ }
1805
+
1770
1806
  const apiError = new ApiError(
1771
1807
  errorData.message || \`HTTP \${response.status}: \${response.statusText}\`,
1772
1808
  response.status,
@@ -2001,7 +2037,8 @@ async get<TData>(
2001
2037
  const authErrorHandlerPath = errorHandling?.authErrorHandlerPath || "@/lib/auth-error-handler";
2002
2038
  const authErrorMiddlewareCode = enableAuthErrorHandling ? `
2003
2039
  // Authentication error middleware
2004
- // Handles 401/403 errors and redirects to login when needed
2040
+ // Handles 401/403 errors after token refresh has been attempted by the base client
2041
+ // Note: Token refresh is handled automatically by the base client before this middleware runs
2005
2042
  export const authErrorMiddleware: RequestMiddleware = {
2006
2043
  name: 'auth-error',
2007
2044
  onError: async (error) => {
@@ -2022,7 +2059,7 @@ export const authErrorMiddleware: RequestMiddleware = {
2022
2059
  errorCode.toLowerCase() === 'user_account_inactive'
2023
2060
  )
2024
2061
 
2025
- console.warn('[Auth Middleware] Authentication error detected:', {
2062
+ console.warn('[Auth Middleware] Authentication error detected (token refresh already attempted):', {
2026
2063
  status,
2027
2064
  message: errorMessage,
2028
2065
  errorCode,
@@ -2825,13 +2862,10 @@ var SchemaGenerator = class {
2825
2862
  const imports = ['import { z } from "zod"'];
2826
2863
  const schemaExports = [];
2827
2864
  const allSchemaDefinitions = [];
2828
- const orderedSchemas = this.orderSchemasByDependencies(schemas);
2829
- for (const schema of orderedSchemas) {
2865
+ for (const schema of schemas) {
2830
2866
  const { definition, exportName } = this.generateSchemaDefinition(schema);
2831
- const zodDependencies = this.findSchemaDependencies(schema);
2832
- const stringDependencies = this.extractDependenciesFromDefinition(definition, exportName);
2833
- const allDependencies = [.../* @__PURE__ */ new Set([...zodDependencies, ...stringDependencies])];
2834
- allSchemaDefinitions.push({ definition, exportName, dependencies: allDependencies });
2867
+ const dependencies = this.extractDependenciesFromDefinition(definition, exportName);
2868
+ allSchemaDefinitions.push({ definition, exportName, dependencies });
2835
2869
  schemaExports.push(exportName);
2836
2870
  }
2837
2871
  for (const endpoint of endpoints) {
@@ -8714,6 +8748,40 @@ export function isAuthError(error: unknown): boolean {
8714
8748
  return false
8715
8749
  }
8716
8750
 
8751
+ /**
8752
+ * Type guard to check if an error is a preventive unauthorized error
8753
+ * Preventive errors occur when no authentication is provided (before API call)
8754
+ * These should be handled silently without showing notifications
8755
+ *
8756
+ * Optimized for performance: early returns and minimal string operations
8757
+ */
8758
+ export function isPreventiveUnauthorizedError(error: unknown): boolean {
8759
+ if (!isAuthError(error)) return false
8760
+
8761
+ const apiError = error as ApiError
8762
+
8763
+ // Early return if response exists (reactive error, not preventive)
8764
+ if (apiError.response) return false
8765
+
8766
+ // Extract error data once to minimize property access
8767
+ const errorData = apiError.data as any
8768
+ const errorCode = errorData?.error_code || errorData?.code
8769
+
8770
+ // Fast path: check error code first (most reliable indicator)
8771
+ if (errorCode && errorCode.toLowerCase() === 'unauthorized') {
8772
+ return true
8773
+ }
8774
+
8775
+ // Fallback: check error message (only if no error code found)
8776
+ const errorMessage = errorData?.detail || apiError.message
8777
+ if (errorMessage) {
8778
+ const msg = errorMessage.toLowerCase().trim()
8779
+ return msg === 'unauthorized'
8780
+ }
8781
+
8782
+ return false
8783
+ }
8784
+
8717
8785
  /**
8718
8786
  * Type guard to check if an error is an inactive account error
8719
8787
  * Auto-detected account status patterns from schema
@@ -8766,19 +8834,30 @@ export async function handleAuthError(error: unknown, redirectTo?: string): Prom
8766
8834
  }
8767
8835
 
8768
8836
  const apiError = error as ApiError
8837
+
8838
+ // Extract error data once to avoid repeated property access
8839
+ const errorData = apiError.data as any
8840
+ const errorCode = errorData?.error_code || errorData?.code || ''
8841
+ const errorMessage = errorData?.detail || apiError.message || ''
8842
+
8843
+ // Check error types efficiently (single function call, no redundant checks)
8844
+ const isPreventive = isPreventiveUnauthorizedError(error)
8769
8845
  const isInactive = isInactiveAccountError(error)
8770
- const errorMessage = apiError.data?.detail || apiError.message || ''
8771
8846
 
8772
8847
  console.warn('[Auth Error Handler] Authentication error detected:', {
8773
8848
  status: apiError.status,
8774
8849
  message: errorMessage,
8850
+ errorCode,
8775
8851
  isInactive,
8852
+ isPreventive,
8776
8853
  })
8777
8854
 
8778
8855
  const toastInstance = await getToast()
8779
8856
 
8780
8857
  // Show appropriate error message based on error type
8781
- if (toastInstance) {
8858
+ // Skip toast for preventive unauthorized errors (no auth provided - silent handling)
8859
+ // Show toast for reactive auth errors (session expired, account issues, etc.)
8860
+ if (toastInstance && !isPreventive) {
8782
8861
  if (isInactive) {
8783
8862
  toastInstance.error('Your account has been deactivated. Please contact support for assistance.', {
8784
8863
  duration: 5000,
@@ -8843,6 +8922,7 @@ export function createAuthErrorHandler(redirectTo?: string) {
8843
8922
  metadata: {
8844
8923
  exports: [
8845
8924
  "isAuthError",
8925
+ "isPreventiveUnauthorizedError",
8846
8926
  "isInactiveAccountError",
8847
8927
  "handleAuthError",
8848
8928
  "createAuthErrorHandler"
@@ -10060,5 +10140,5 @@ ${errorMessages}`,
10060
10140
  };
10061
10141
 
10062
10142
  export { BridgeCore, BridgeError, BridgeLogger, ConfigurationLoader, FileSystemManager, GenerationError, LogLevel, NextJsCodeGenerator, OpenApiSchemaParser, SchemaParseError, ValidationError, VersionChecker, __name, checkAndNotifyUpdates, createBridgeVersionChecker };
10063
- //# sourceMappingURL=chunk-NXP26AJR.js.map
10064
- //# sourceMappingURL=chunk-NXP26AJR.js.map
10143
+ //# sourceMappingURL=chunk-RXLPPBZQ.js.map
10144
+ //# sourceMappingURL=chunk-RXLPPBZQ.js.map