@djangocfg/api 2.1.469 → 2.1.471

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/auth.d.cts CHANGED
@@ -1059,10 +1059,19 @@ declare const logger: consola.ConsolaInstance;
1059
1059
  declare const authLogger: consola.ConsolaInstance;
1060
1060
 
1061
1061
  /**
1062
- * Analytics stub for @djangocfg/api/auth
1063
- * Provides minimal analytics interface without external dependencies
1062
+ * Auth analytics a dependency-free SINK, not an implementation.
1064
1063
  *
1065
- * If you need full analytics, install @djangocfg/layouts and use its Analytics module
1064
+ * `@djangocfg/api` cannot depend on `@djangocfg/analytics`: analytics reads auth
1065
+ * state (to attribute events to a signed-in user), so importing it here would
1066
+ * close a dependency cycle. Instead this module owns the *interface* and lets a
1067
+ * real implementation be injected at runtime — `@djangocfg/analytics` calls
1068
+ * `setAnalyticsSink()` when its provider mounts.
1069
+ *
1070
+ * Before this, the object below was a hardcoded stub that console.logged in dev
1071
+ * and did NOTHING in production. Every auth event it "tracked" —
1072
+ * AUTH_LOGIN_SUCCESS, AUTH_OAUTH_FAIL, AUTH_SESSION_EXPIRED — was silently
1073
+ * discarded. The events were fired, the calls looked right, and nothing ever
1074
+ * arrived anywhere.
1066
1075
  */
1067
1076
  declare enum AnalyticsEvent {
1068
1077
  AUTH_OTP_REQUEST = "auth_otp_request",
@@ -1086,19 +1095,23 @@ interface AnalyticsEventParams {
1086
1095
  value?: number;
1087
1096
  [key: string]: any;
1088
1097
  }
1098
+ /** What an analytics implementation must provide to receive auth events. */
1099
+ interface AnalyticsSink {
1100
+ event(name: string, params?: Record<string, any>): void;
1101
+ setUser(userId: string | null): void;
1102
+ }
1089
1103
  /**
1090
- * Minimal analytics implementation
1091
- * Logs to console in development, silent in production
1104
+ * Install the real analytics implementation.
1105
+ *
1106
+ * Called by `@djangocfg/analytics` when its provider mounts. Pass `null` to
1107
+ * uninstall (on unmount), so a torn-down provider does not keep receiving events.
1092
1108
  */
1109
+ declare function setAnalyticsSink(next: AnalyticsSink | null): void;
1093
1110
  declare const Analytics: {
1094
- /**
1095
- * Track an analytics event
1096
- */
1111
+ /** Track an auth event. Delivered to the installed sink, if any. */
1097
1112
  event(eventName: AnalyticsEventType, params?: AnalyticsEventParams): void;
1098
- /**
1099
- * Set user ID for tracking
1100
- */
1101
- setUser(userId: string): void;
1113
+ /** Attach the signed-in user. Pass null on logout. */
1114
+ setUser(userId: string | null): void;
1102
1115
  };
1103
1116
 
1104
- export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1117
+ export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
package/dist/auth.d.ts CHANGED
@@ -1059,10 +1059,19 @@ declare const logger: consola.ConsolaInstance;
1059
1059
  declare const authLogger: consola.ConsolaInstance;
1060
1060
 
1061
1061
  /**
1062
- * Analytics stub for @djangocfg/api/auth
1063
- * Provides minimal analytics interface without external dependencies
1062
+ * Auth analytics a dependency-free SINK, not an implementation.
1064
1063
  *
1065
- * If you need full analytics, install @djangocfg/layouts and use its Analytics module
1064
+ * `@djangocfg/api` cannot depend on `@djangocfg/analytics`: analytics reads auth
1065
+ * state (to attribute events to a signed-in user), so importing it here would
1066
+ * close a dependency cycle. Instead this module owns the *interface* and lets a
1067
+ * real implementation be injected at runtime — `@djangocfg/analytics` calls
1068
+ * `setAnalyticsSink()` when its provider mounts.
1069
+ *
1070
+ * Before this, the object below was a hardcoded stub that console.logged in dev
1071
+ * and did NOTHING in production. Every auth event it "tracked" —
1072
+ * AUTH_LOGIN_SUCCESS, AUTH_OAUTH_FAIL, AUTH_SESSION_EXPIRED — was silently
1073
+ * discarded. The events were fired, the calls looked right, and nothing ever
1074
+ * arrived anywhere.
1066
1075
  */
1067
1076
  declare enum AnalyticsEvent {
1068
1077
  AUTH_OTP_REQUEST = "auth_otp_request",
@@ -1086,19 +1095,23 @@ interface AnalyticsEventParams {
1086
1095
  value?: number;
1087
1096
  [key: string]: any;
1088
1097
  }
1098
+ /** What an analytics implementation must provide to receive auth events. */
1099
+ interface AnalyticsSink {
1100
+ event(name: string, params?: Record<string, any>): void;
1101
+ setUser(userId: string | null): void;
1102
+ }
1089
1103
  /**
1090
- * Minimal analytics implementation
1091
- * Logs to console in development, silent in production
1104
+ * Install the real analytics implementation.
1105
+ *
1106
+ * Called by `@djangocfg/analytics` when its provider mounts. Pass `null` to
1107
+ * uninstall (on unmount), so a torn-down provider does not keep receiving events.
1092
1108
  */
1109
+ declare function setAnalyticsSink(next: AnalyticsSink | null): void;
1093
1110
  declare const Analytics: {
1094
- /**
1095
- * Track an analytics event
1096
- */
1111
+ /** Track an auth event. Delivered to the installed sink, if any. */
1097
1112
  event(eventName: AnalyticsEventType, params?: AnalyticsEventParams): void;
1098
- /**
1099
- * Set user ID for tracking
1100
- */
1101
- setUser(userId: string): void;
1113
+ /** Attach the signed-in user. Pass null on logout. */
1114
+ setUser(userId: string | null): void;
1102
1115
  };
1103
1116
 
1104
- export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
1117
+ export { AUTH_CONSTANTS, type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AnalyticsSink, type AuthConfig, AuthContext, type AuthContextType, type AuthFormAutoSubmit, type AuthFormReturn, type AuthFormState, type AuthFormStateHandlers, type AuthFormSubmitHandlers, type AuthFormValidation, AuthProvider, type AuthProviderProps, type AuthStep, type DeleteAccountResult, type GuardInput, type OTPRequestResult, type PatchedCfgUserUpdateRequest, PatchedCfgUserUpdateRequestSchema, type ProfileCacheOptions, type SessionSnapshot, type SessionStatus, type TwoFactorDevice, type TwoFactorSetupData, type UseAuthFormOptions, type UseAuthFormStateReturn, type UseAutoAuthOptions, type UseDeleteAccountReturn, type UseGithubAuthOptions, type UseGithubAuthReturn, type UseTwoFactorOptions, type UseTwoFactorReturn, type UseTwoFactorSetupOptions, type UseTwoFactorSetupReturn, type UseTwoFactorStatusReturn, type UseTwoFactorVerifyOptions, type UseTwoFactorVerifyReturn, type UserProfile, type WebmailLink, authLogger, clearProfileCache, consumeSavedRedirect, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, isAllowedAuthPath, logger, normalizePath, peekSavedRedirect, resolveGuardIsAuthenticated, resolveGuardIsLoading, setAnalyticsSink, setCachedProfile, shouldRedirectToAuth, useAccountsContext, useAuth, useAuthForm, useAuthFormState, useAuthRedirectManager, useAuthValidation, useAutoAuth, useBase64, useCfgRouter, useDeleteAccount, useGithubAuth, useLocalStorage, useQueryParams, useSession, useSessionStorage, useTwoFactor, useTwoFactorSetup, useTwoFactorStatus, useTwoFactorVerify, validateEmail, validateIdentifier };
package/dist/auth.mjs CHANGED
@@ -2388,21 +2388,30 @@ var AnalyticsCategory = /* @__PURE__ */ ((AnalyticsCategory2) => {
2388
2388
  AnalyticsCategory2["AUTH"] = "auth";
2389
2389
  return AnalyticsCategory2;
2390
2390
  })(AnalyticsCategory || {});
2391
+ var sink = null;
2392
+ function setAnalyticsSink(next) {
2393
+ sink = next;
2394
+ }
2395
+ __name(setAnalyticsSink, "setAnalyticsSink");
2391
2396
  var Analytics = {
2392
- /**
2393
- * Track an analytics event
2394
- */
2397
+ /** Track an auth event. Delivered to the installed sink, if any. */
2395
2398
  event(eventName, params) {
2399
+ if (sink) {
2400
+ sink.event(eventName, params);
2401
+ return;
2402
+ }
2396
2403
  if (isDev) {
2397
- console.log("[Analytics]", eventName, params);
2404
+ console.log("[Analytics:no-sink]", eventName, params);
2398
2405
  }
2399
2406
  },
2400
- /**
2401
- * Set user ID for tracking
2402
- */
2407
+ /** Attach the signed-in user. Pass null on logout. */
2403
2408
  setUser(userId) {
2409
+ if (sink) {
2410
+ sink.setUser(userId);
2411
+ return;
2412
+ }
2404
2413
  if (isDev) {
2405
- console.log("[Analytics] Set user:", userId);
2414
+ console.log("[Analytics:no-sink] Set user:", userId);
2406
2415
  }
2407
2416
  }
2408
2417
  };
@@ -4821,6 +4830,7 @@ export {
4821
4830
  peekSavedRedirect,
4822
4831
  resolveGuardIsAuthenticated,
4823
4832
  resolveGuardIsLoading,
4833
+ setAnalyticsSink,
4824
4834
  setCachedProfile,
4825
4835
  shouldRedirectToAuth,
4826
4836
  useAccountsContext,