@djangocfg/api 2.1.27 → 2.1.29

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
@@ -463,6 +463,28 @@ declare function getCacheMetadata(): {
463
463
  expiresIn?: number;
464
464
  } | null;
465
465
 
466
+ /**
467
+ * Encode string to base64
468
+ * @param data - String data to encode
469
+ * @returns Base64 encoded string (or original in dev mode)
470
+ */
471
+ declare function encodeBase64(data: string): string;
472
+ /**
473
+ * Decode base64 to string
474
+ * @param encoded - Base64 encoded string
475
+ * @returns Decoded string (or original in dev mode)
476
+ */
477
+ declare function decodeBase64(encoded: string): string;
478
+ /**
479
+ * Hook for base64 encoding/decoding
480
+ * @returns Object with encode and decode functions
481
+ */
482
+ declare function useBase64(): {
483
+ encode: typeof encodeBase64;
484
+ decode: typeof decodeBase64;
485
+ isDev: boolean;
486
+ };
487
+
466
488
  /**
467
489
  * Email validation utility
468
490
  */
@@ -522,4 +544,4 @@ declare const Analytics: {
522
544
  setUser(userId: string): void;
523
545
  };
524
546
 
525
- export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, type AuthContextType, AuthProvider, type AuthProviderProps, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type UseGithubAuthOptions, type UseGithubAuthReturn, type UserProfile, authLogger, clearProfileCache, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthGuard, useAuthRedirectManager, useAutoAuth, useGithubAuth, useLocalStorage, useSessionStorage, validateEmail };
547
+ export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, type AuthContextType, AuthProvider, type AuthProviderProps, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type UseGithubAuthOptions, type UseGithubAuthReturn, type UserProfile, authLogger, clearProfileCache, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthGuard, useAuthRedirectManager, useAutoAuth, useBase64, useGithubAuth, useLocalStorage, useSessionStorage, validateEmail };
package/dist/auth.d.ts CHANGED
@@ -463,6 +463,28 @@ declare function getCacheMetadata(): {
463
463
  expiresIn?: number;
464
464
  } | null;
465
465
 
466
+ /**
467
+ * Encode string to base64
468
+ * @param data - String data to encode
469
+ * @returns Base64 encoded string (or original in dev mode)
470
+ */
471
+ declare function encodeBase64(data: string): string;
472
+ /**
473
+ * Decode base64 to string
474
+ * @param encoded - Base64 encoded string
475
+ * @returns Decoded string (or original in dev mode)
476
+ */
477
+ declare function decodeBase64(encoded: string): string;
478
+ /**
479
+ * Hook for base64 encoding/decoding
480
+ * @returns Object with encode and decode functions
481
+ */
482
+ declare function useBase64(): {
483
+ encode: typeof encodeBase64;
484
+ decode: typeof decodeBase64;
485
+ isDev: boolean;
486
+ };
487
+
466
488
  /**
467
489
  * Email validation utility
468
490
  */
@@ -522,4 +544,4 @@ declare const Analytics: {
522
544
  setUser(userId: string): void;
523
545
  };
524
546
 
525
- export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, type AuthContextType, AuthProvider, type AuthProviderProps, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type UseGithubAuthOptions, type UseGithubAuthReturn, type UserProfile, authLogger, clearProfileCache, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthGuard, useAuthRedirectManager, useAutoAuth, useGithubAuth, useLocalStorage, useSessionStorage, validateEmail };
547
+ export { type AccountsContextValue, AccountsProvider, Analytics, AnalyticsCategory, type AnalyticsCategoryType, AnalyticsEvent, type AnalyticsEventType, type AuthConfig, type AuthContextType, AuthProvider, type AuthProviderProps, type PatchedUserProfileUpdateRequest, PatchedUserProfileUpdateRequestSchema, type ProfileCacheOptions, type UseGithubAuthOptions, type UseGithubAuthReturn, type UserProfile, authLogger, clearProfileCache, decodeBase64, encodeBase64, formatAuthError, getCacheMetadata, getCachedProfile, hasValidCache, logger, setCachedProfile, useAccountsContext, useAuth, useAuthForm, useAuthGuard, useAuthRedirectManager, useAutoAuth, useBase64, useGithubAuth, useLocalStorage, useSessionStorage, validateEmail };
package/dist/auth.mjs CHANGED
@@ -4486,6 +4486,56 @@ var logger = createConsola2({
4486
4486
  }).withTag("api");
4487
4487
  var authLogger = logger.withTag("auth");
4488
4488
 
4489
+ // src/auth/hooks/useBase64.ts
4490
+ var isDev = process.env.NODE_ENV === "development";
4491
+ function encodeBase64(data) {
4492
+ if (isDev) {
4493
+ return data;
4494
+ }
4495
+ try {
4496
+ if (typeof window !== "undefined") {
4497
+ return btoa(encodeURIComponent(data).replace(/%([0-9A-F]{2})/g, (_, p1) => {
4498
+ return String.fromCharCode(parseInt(p1, 16));
4499
+ }));
4500
+ }
4501
+ return Buffer.from(data, "utf-8").toString("base64");
4502
+ } catch (error) {
4503
+ console.error("Base64 encoding error:", error);
4504
+ return data;
4505
+ }
4506
+ }
4507
+ __name(encodeBase64, "encodeBase64");
4508
+ function decodeBase64(encoded) {
4509
+ if (isDev) {
4510
+ return encoded;
4511
+ }
4512
+ try {
4513
+ if (typeof window !== "undefined") {
4514
+ const binary = atob(encoded);
4515
+ const bytes = new Uint8Array(binary.length);
4516
+ for (let i = 0; i < binary.length; i++) {
4517
+ bytes[i] = binary.charCodeAt(i);
4518
+ }
4519
+ return decodeURIComponent(
4520
+ Array.from(bytes).map((byte) => "%" + ("00" + byte.toString(16)).slice(-2)).join("")
4521
+ );
4522
+ }
4523
+ return Buffer.from(encoded, "base64").toString("utf-8");
4524
+ } catch (error) {
4525
+ console.error("Base64 decoding error:", error);
4526
+ return encoded;
4527
+ }
4528
+ }
4529
+ __name(decodeBase64, "decodeBase64");
4530
+ function useBase64() {
4531
+ return {
4532
+ encode: encodeBase64,
4533
+ decode: decodeBase64,
4534
+ isDev
4535
+ };
4536
+ }
4537
+ __name(useBase64, "useBase64");
4538
+
4489
4539
  // src/auth/hooks/useProfileCache.ts
4490
4540
  var CACHE_KEY = "user_profile_cache";
4491
4541
  var CACHE_VERSION = 1;
@@ -4498,7 +4548,8 @@ function getCachedProfile() {
4498
4548
  authLogger.debug("No cached profile found");
4499
4549
  return null;
4500
4550
  }
4501
- const cachedData = JSON.parse(cached);
4551
+ const decoded = decodeBase64(cached);
4552
+ const cachedData = JSON.parse(decoded);
4502
4553
  if (cachedData.version !== CACHE_VERSION) {
4503
4554
  authLogger.warn("Cache version mismatch, clearing cache");
4504
4555
  clearProfileCache();
@@ -4529,7 +4580,8 @@ function setCachedProfile(profile, options) {
4529
4580
  timestamp: Date.now(),
4530
4581
  ttl: options?.ttl || DEFAULT_TTL
4531
4582
  };
4532
- localStorage.setItem(CACHE_KEY, JSON.stringify(cachedData));
4583
+ const encoded = encodeBase64(JSON.stringify(cachedData));
4584
+ localStorage.setItem(CACHE_KEY, encoded);
4533
4585
  authLogger.debug("Profile cached, TTL:", cachedData.ttl / 1e3, "seconds");
4534
4586
  } catch (error) {
4535
4587
  authLogger.error("Error writing cache:", error);
@@ -4555,7 +4607,8 @@ function getCacheMetadata() {
4555
4607
  if (typeof window === "undefined") return null;
4556
4608
  const cached = localStorage.getItem(CACHE_KEY);
4557
4609
  if (!cached) return { exists: false };
4558
- const cachedData = JSON.parse(cached);
4610
+ const decoded = decodeBase64(cached);
4611
+ const cachedData = JSON.parse(decoded);
4559
4612
  const now = Date.now();
4560
4613
  const age = now - cachedData.timestamp;
4561
4614
  const expiresIn = cachedData.ttl - age;
@@ -6047,6 +6100,8 @@ export {
6047
6100
  PatchedUserProfileUpdateRequestSchema,
6048
6101
  authLogger,
6049
6102
  clearProfileCache,
6103
+ decodeBase64,
6104
+ encodeBase64,
6050
6105
  formatAuthError,
6051
6106
  getCacheMetadata,
6052
6107
  getCachedProfile,
@@ -6059,6 +6114,7 @@ export {
6059
6114
  useAuthGuard,
6060
6115
  useAuthRedirectManager,
6061
6116
  useAutoAuth,
6117
+ useBase64,
6062
6118
  useGithubAuth,
6063
6119
  useLocalStorage2 as useLocalStorage,
6064
6120
  useSessionStorage,