@classic-homes/auth 0.1.32 → 0.1.34

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.
@@ -1,3 +1,3 @@
1
- export { authActions, authStore, currentUser, isAuthenticated } from './chunk-FSUP2LAZ.js';
2
- import './chunk-LYTYYOPU.js';
1
+ export { authActions, authStore, currentUser, isAuthenticated } from './chunk-7M4DUK45.js';
2
+ import './chunk-BDIQSTES.js';
3
3
  import './chunk-DCGC6CNV.js';
@@ -1,4 +1,4 @@
1
- import { authApi } from './chunk-LYTYYOPU.js';
1
+ import { authApi } from './chunk-BDIQSTES.js';
2
2
  import { decodeJWT, isInitialized, getConfig, getStorage, getDefaultStorage } from './chunk-DCGC6CNV.js';
3
3
 
4
4
  // src/svelte/stores/auth.svelte.ts
@@ -53,7 +53,7 @@ function updateStoredTokens(accessToken, refreshToken) {
53
53
  parsed.accessToken = accessToken;
54
54
  parsed.refreshToken = refreshToken;
55
55
  storage.setItem(storageKey, JSON.stringify(parsed));
56
- import('./auth.svelte-CIDAK774.js').then(({ authStore }) => {
56
+ import('./auth.svelte-LJJ7MGDE.js').then(({ authStore }) => {
57
57
  authStore.updateTokens(accessToken, refreshToken);
58
58
  }).catch(() => {
59
59
  });
@@ -81,8 +81,22 @@ async function refreshAccessToken() {
81
81
  body: JSON.stringify({ refreshToken })
82
82
  });
83
83
  if (response.ok) {
84
- const apiResponse = await response.json();
85
- const data = apiResponse.data;
84
+ let apiResponse;
85
+ const contentType = response.headers.get("content-type");
86
+ if (contentType?.includes("application/json")) {
87
+ try {
88
+ apiResponse = await response.json();
89
+ } catch {
90
+ return false;
91
+ }
92
+ } else {
93
+ try {
94
+ apiResponse = await response.json();
95
+ } catch {
96
+ return false;
97
+ }
98
+ }
99
+ const data = apiResponse?.data;
86
100
  const tokens = data && typeof data === "object" && "data" in data ? data.data : data;
87
101
  if (tokens?.accessToken) {
88
102
  const newRefreshToken = tokens.refreshToken ?? refreshToken;
@@ -153,10 +167,43 @@ async function apiRequest(endpoint, options = {}) {
153
167
  });
154
168
  }
155
169
  }
156
- const data = await response.json();
170
+ let data;
171
+ const contentType = response.headers.get("content-type");
172
+ if (contentType?.includes("application/json")) {
173
+ try {
174
+ data = await response.json();
175
+ } catch (parseError) {
176
+ if (!response.ok) {
177
+ throw new Error(`Server error (${response.status}): Invalid JSON response`);
178
+ }
179
+ throw parseError;
180
+ }
181
+ } else {
182
+ const responseText = await response.text().catch(() => "");
183
+ if (responseText) {
184
+ try {
185
+ data = JSON.parse(responseText);
186
+ } catch {
187
+ if (!response.ok) {
188
+ const truncatedText = responseText.length > 100 ? responseText.substring(0, 100) + "..." : responseText;
189
+ throw new Error(
190
+ `Server error (${response.status}): ${truncatedText || response.statusText || "Unknown error"}`
191
+ );
192
+ }
193
+ data = {};
194
+ }
195
+ } else {
196
+ if (!response.ok) {
197
+ throw new Error(
198
+ `Server error (${response.status}): ${response.statusText || "Empty response"}`
199
+ );
200
+ }
201
+ data = {};
202
+ }
203
+ }
157
204
  if (!response.ok) {
158
205
  const dataObj = data;
159
- const errorMessage = data.error?.message || (typeof dataObj.message === "string" ? dataObj.message : void 0) || data.meta?.message || (typeof dataObj.detail === "string" ? dataObj.detail : void 0) || "Request failed";
206
+ const errorMessage = data.error?.message || (typeof dataObj.message === "string" ? dataObj.message : void 0) || data.meta?.message || (typeof dataObj.detail === "string" ? dataObj.detail : void 0) || `Request failed (${response.status})`;
160
207
  const error = new Error(errorMessage);
161
208
  config.onAuthError?.(error);
162
209
  throw error;
@@ -1,4 +1,4 @@
1
- import { authApi } from './chunk-LYTYYOPU.js';
1
+ import { authApi } from './chunk-BDIQSTES.js';
2
2
 
3
3
  // src/core/guards.ts
4
4
  function isMfaChallengeResponse(response) {
@@ -29,7 +29,7 @@ var AuthService = class {
29
29
  const response = await authApi.login(credentials);
30
30
  if (options?.autoSetAuth !== false && !isMfaChallengeResponse(response)) {
31
31
  try {
32
- const { authStore } = await import('./auth.svelte-CIDAK774.js');
32
+ const { authStore } = await import('./auth.svelte-LJJ7MGDE.js');
33
33
  authStore.setAuth(
34
34
  response.accessToken,
35
35
  response.refreshToken,
@@ -204,7 +204,7 @@ var AuthService = class {
204
204
  const response = await authApi.verifyMFAChallenge(data);
205
205
  if (options?.autoSetAuth !== false) {
206
206
  try {
207
- const { authStore } = await import('./auth.svelte-CIDAK774.js');
207
+ const { authStore } = await import('./auth.svelte-LJJ7MGDE.js');
208
208
  authStore.setAuth(
209
209
  response.accessToken,
210
210
  response.refreshToken,
@@ -1,4 +1,4 @@
1
- import { authStore } from './chunk-FSUP2LAZ.js';
1
+ import { authStore } from './chunk-7M4DUK45.js';
2
2
 
3
3
  // src/svelte/guards/auth-guard.ts
4
4
  function checkAuth(options = {}) {
@@ -1,3 +1,3 @@
1
- export { AuthService, authService, getAvailableMethods, getMfaToken, isLoginSuccessResponse, isMfaChallengeResponse } from '../chunk-N5DUPSOL.js';
2
- export { api, apiRequest, authApi, clearStoredAuth, extractData, getAccessToken, getRefreshToken, getSessionToken, updateStoredTokens } from '../chunk-LYTYYOPU.js';
1
+ export { AuthService, authService, getAvailableMethods, getMfaToken, isLoginSuccessResponse, isMfaChallengeResponse } from '../chunk-EVKXT3NR.js';
2
+ export { api, apiRequest, authApi, clearStoredAuth, extractData, getAccessToken, getRefreshToken, getSessionToken, updateStoredTokens } from '../chunk-BDIQSTES.js';
3
3
  export { decodeJWT, extractClaims, getConfig, getDefaultStorage, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, initAuth, isInitialized, isTokenExpired, resetConfig } from '../chunk-DCGC6CNV.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { AuthService, authService, getAvailableMethods, getMfaToken, isLoginSuccessResponse, isMfaChallengeResponse } from './chunk-N5DUPSOL.js';
2
- export { checkAuth, createAuthGuard, protectedLoad, requireAuth, requirePermission, requireRole } from './chunk-3LY565CA.js';
3
- export { authActions, authStore, currentUser, isAuthenticated } from './chunk-FSUP2LAZ.js';
4
- export { api, apiRequest, authApi, clearStoredAuth, extractData, getAccessToken, getRefreshToken, getSessionToken, updateStoredTokens } from './chunk-LYTYYOPU.js';
1
+ export { AuthService, authService, getAvailableMethods, getMfaToken, isLoginSuccessResponse, isMfaChallengeResponse } from './chunk-EVKXT3NR.js';
2
+ export { checkAuth, createAuthGuard, protectedLoad, requireAuth, requirePermission, requireRole } from './chunk-IAPPE4US.js';
3
+ export { authActions, authStore, currentUser, isAuthenticated } from './chunk-7M4DUK45.js';
4
+ export { api, apiRequest, authApi, clearStoredAuth, extractData, getAccessToken, getRefreshToken, getSessionToken, updateStoredTokens } from './chunk-BDIQSTES.js';
5
5
  export { decodeJWT, extractClaims, getConfig, getDefaultStorage, getFetch, getStorage, getTokenExpiration, getTokenRemainingTime, initAuth, isInitialized, isTokenExpired, resetConfig } from './chunk-DCGC6CNV.js';
@@ -1,4 +1,4 @@
1
- export { checkAuth, createAuthGuard, protectedLoad, requireAuth, requirePermission, requireRole } from '../chunk-3LY565CA.js';
2
- export { authActions, authStore, currentUser, isAuthenticated } from '../chunk-FSUP2LAZ.js';
3
- import '../chunk-LYTYYOPU.js';
1
+ export { checkAuth, createAuthGuard, protectedLoad, requireAuth, requirePermission, requireRole } from '../chunk-IAPPE4US.js';
2
+ export { authActions, authStore, currentUser, isAuthenticated } from '../chunk-7M4DUK45.js';
3
+ import '../chunk-BDIQSTES.js';
4
4
  import '../chunk-DCGC6CNV.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/auth",
3
- "version": "0.1.32",
3
+ "version": "0.1.34",
4
4
  "description": "Authentication services and Svelte bindings for Classic Theme apps",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",