@djangocfg/api 2.1.129 → 2.1.131

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/api",
3
- "version": "2.1.129",
3
+ "version": "2.1.131",
4
4
  "description": "Auto-generated TypeScript API client with React hooks, SWR integration, and Zod validation for Django REST Framework backends",
5
5
  "keywords": [
6
6
  "django",
@@ -84,7 +84,7 @@
84
84
  "devDependencies": {
85
85
  "@types/node": "^24.7.2",
86
86
  "@types/react": "^19.0.0",
87
- "@djangocfg/typescript-config": "^2.1.129",
87
+ "@djangocfg/typescript-config": "^2.1.131",
88
88
  "next": "^16.0.0",
89
89
  "react": "^19.0.0",
90
90
  "tsup": "^8.5.0",
@@ -60,7 +60,7 @@ export interface AccountsContextValue {
60
60
  updateProfile: (data: UserProfileUpdateRequest) => Promise<User>;
61
61
  partialUpdateProfile: (data: PatchedUserProfileUpdateRequest) => Promise<User>;
62
62
  uploadAvatar: (avatar: File | Blob) => Promise<User>;
63
- refreshProfile: (callerId?: string) => Promise<User | undefined>;
63
+ refreshProfile: (options?: { callerId?: string; force?: boolean }) => Promise<User | undefined>;
64
64
 
65
65
  // Authentication
66
66
  requestOTP: (data: OTPRequestRequest) => Promise<OTPRequestResponse>;
@@ -114,30 +114,25 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
114
114
  const otpVerifyMutation = useCreateAccountsOtpVerifyCreate();
115
115
  const tokenRefreshMutation = useCreateAccountsTokenRefreshCreate();
116
116
 
117
- // Refresh profile - fetch and cache with stable callback
118
- const refreshProfile = useCallback(async (callerId?: string): Promise<User | undefined> => {
119
- // Use refs to check current state without creating dependency
120
- const currentProfile = profileRef.current;
117
+ // Refresh profile - fetch from API and update cache
118
+ const refreshProfile = useCallback(async (options?: { callerId?: string; force?: boolean }): Promise<User | undefined> => {
119
+ const { callerId, force } = options || {};
121
120
  const currentLoading = isLoadingRef.current;
122
121
 
123
- // Prevent duplicate calls if profile is already loaded and not loading
124
- if (currentProfile && !currentLoading) {
125
- authLogger.debug(`Profile already loaded, returning cached (caller: ${callerId})`);
126
- return currentProfile;
122
+ // Prevent duplicate concurrent calls
123
+ if (currentLoading) {
124
+ authLogger.debug(`Profile loading in progress, skipping (caller: ${callerId})`);
125
+ return profileRef.current;
127
126
  }
128
127
 
129
128
  setIsLoadingProfile(true);
130
129
  isLoadingRef.current = true;
131
130
  setProfileError(null);
132
131
  try {
133
- // Log caller for debugging excessive API calls using consola logger
134
- if (callerId) {
135
- authLogger.debug(`Profile refresh called by: ${callerId}`);
136
- }
132
+ authLogger.debug(`Fetching profile from API (caller: ${callerId}, force: ${force})`);
137
133
  const result = await getAccountsProfileRetrieve(apiAccounts);
138
134
  setProfile(result);
139
135
  profileRef.current = result;
140
- // Save to cache with 1 hour TTL
141
136
  setCachedProfile(result);
142
137
  return result;
143
138
  } catch (error) {
@@ -148,27 +143,27 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
148
143
  setIsLoadingProfile(false);
149
144
  isLoadingRef.current = false;
150
145
  }
151
- }, []); // Empty dependencies - callback is stable
146
+ }, []);
152
147
 
153
- // Update profile (full)
148
+ // Update profile (full) - then reload from API
154
149
  const updateProfile = async (data: UserProfileUpdateRequest): Promise<User> => {
155
- const result = await updateMutation(data, apiAccounts);
156
- await refreshProfile('AccountsContext.updateProfile');
157
- return result as User;
150
+ await updateMutation(data, apiAccounts);
151
+ const user = await refreshProfile({ callerId: 'updateProfile', force: true });
152
+ return user as User;
158
153
  };
159
154
 
160
- // Partial update profile
155
+ // Partial update profile - then reload from API
161
156
  const partialUpdateProfile = async (data: PatchedUserProfileUpdateRequest): Promise<User> => {
162
- const result = await partialUpdateMutation(data, apiAccounts);
163
- await refreshProfile('AccountsContext.partialUpdateProfile');
164
- return result as User;
157
+ await partialUpdateMutation(data, apiAccounts);
158
+ const user = await refreshProfile({ callerId: 'partialUpdateProfile', force: true });
159
+ return user as User;
165
160
  };
166
161
 
167
- // Upload avatar
162
+ // Upload avatar - then reload from API
168
163
  const uploadAvatar = async (avatar: File | Blob): Promise<User> => {
169
- const result = await avatarMutation({ avatar }, apiAccounts);
170
- await refreshProfile('AccountsContext.uploadAvatar');
171
- return result as User;
164
+ await avatarMutation({ avatar }, apiAccounts);
165
+ const user = await refreshProfile({ callerId: 'uploadAvatar', force: true });
166
+ return user as User;
172
167
  };
173
168
 
174
169
  // Request OTP
@@ -192,7 +187,7 @@ export function AccountsProvider({ children }: AccountsProviderProps) {
192
187
  if (result.access && result.refresh) {
193
188
  apiAccounts.setToken(result.access, result.refresh);
194
189
  // Refresh profile to load user data with new token
195
- await refreshProfile('AccountsContext.verifyOTP');
190
+ await refreshProfile({ callerId: 'verifyOTP', force: true });
196
191
  }
197
192
 
198
193
  return result as OTPVerifyResponse;
@@ -163,8 +163,8 @@ const AuthProviderInternal: React.FC<AuthProviderProps> = ({ children, config })
163
163
  return;
164
164
  }
165
165
 
166
- // Refresh profile from AccountsContext (now with memoization)
167
- const refreshedProfile = await accounts.refreshProfile(finalCallerId);
166
+ // Refresh profile from AccountsContext
167
+ const refreshedProfile = await accounts.refreshProfile({ callerId: finalCallerId });
168
168
 
169
169
  if (refreshedProfile) {
170
170
  authLogger.info('Profile loaded successfully:', refreshedProfile.id);