@hashrytech/quick-components-kit 0.13.4 → 0.13.5
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @hashrytech/quick-components-kit
|
|
2
2
|
|
|
3
|
+
## 0.13.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- refactor: setting placeholder text size to text-base default
|
|
8
|
+
- refactor: set text size for lg TextInput to text-base
|
|
9
|
+
- patch: adding evaluation of redirect rule to apiclient
|
|
10
|
+
|
|
3
11
|
## 0.13.4
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
let sizeStyle: Record<TextInputSize, string> = {
|
|
64
64
|
sm: "h-[2.05rem] text-sm placeholder:text-sm",
|
|
65
65
|
md: "h-[2.375rem] text-sm placeholder:text-sm",
|
|
66
|
-
lg: "h-[2.8rem] text-
|
|
66
|
+
lg: "h-[2.8rem] text-base placeholder:text-base"
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
</script>
|
|
@@ -9,6 +9,12 @@ import { type ProblemDetail } from "./problem-details.js";
|
|
|
9
9
|
* and API routes) to automatically benefit from its enhancements (e.g., cookie forwarding,
|
|
10
10
|
* built-in request/response interception via SvelteKit's `handleFetch` hook).
|
|
11
11
|
*/
|
|
12
|
+
export interface AutoRedirectRule {
|
|
13
|
+
status: number;
|
|
14
|
+
errorKey: string;
|
|
15
|
+
errorValue?: string;
|
|
16
|
+
redirectTo: string;
|
|
17
|
+
}
|
|
12
18
|
export type ApiResponse<T> = {
|
|
13
19
|
ok: boolean;
|
|
14
20
|
status: number;
|
|
@@ -26,6 +32,7 @@ export interface ApiClientConfig {
|
|
|
26
32
|
* handled by `src/hooks.server.ts` via `handleFetch`.
|
|
27
33
|
*/
|
|
28
34
|
getAccessToken?: () => string | undefined;
|
|
35
|
+
autoRedirects?: AutoRedirectRule[];
|
|
29
36
|
}
|
|
30
37
|
export interface RequestOptions extends RequestInit {
|
|
31
38
|
/** If true, the Authorization header will not be added to this request. */
|
|
@@ -82,6 +89,7 @@ export declare class ApiClient {
|
|
|
82
89
|
private clientAuthToken;
|
|
83
90
|
private getAccessTokenFromStore;
|
|
84
91
|
private fetchInstance?;
|
|
92
|
+
private autoRedirects;
|
|
85
93
|
private requestInterceptors;
|
|
86
94
|
private responseInterceptors;
|
|
87
95
|
private errorHandlers;
|
|
@@ -155,6 +163,7 @@ export declare class ApiClient {
|
|
|
155
163
|
* @template T - Expected type of the response data.
|
|
156
164
|
*/
|
|
157
165
|
request<T>(endpoint: string, method: string, body: BodyInit | object | null | undefined, options?: RequestOptions): Promise<ApiResponse<T>>;
|
|
166
|
+
private evaluateRedirect;
|
|
158
167
|
/**
|
|
159
168
|
* Sends a GET request to the specified API endpoint.
|
|
160
169
|
*
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/lib/api/client.ts
|
|
2
|
+
import { redirect } from "@sveltejs/kit";
|
|
2
3
|
import { getProblemDetail } from "./problem-details.js";
|
|
4
|
+
import { browser } from "$app/environment";
|
|
3
5
|
/**
|
|
4
6
|
* Custom error class for API responses.
|
|
5
7
|
* Provides access to the HTTP status code.
|
|
@@ -35,6 +37,7 @@ export class ApiClient {
|
|
|
35
37
|
clientAuthToken;
|
|
36
38
|
getAccessTokenFromStore;
|
|
37
39
|
fetchInstance;
|
|
40
|
+
autoRedirects = [];
|
|
38
41
|
requestInterceptors = [];
|
|
39
42
|
responseInterceptors = [];
|
|
40
43
|
errorHandlers = [];
|
|
@@ -47,6 +50,7 @@ export class ApiClient {
|
|
|
47
50
|
this.baseURL = config.baseURL;
|
|
48
51
|
this.defaultHeaders = config.defaultHeaders || { 'Content-Type': 'application/json' };
|
|
49
52
|
this.getAccessTokenFromStore = config.getAccessToken;
|
|
53
|
+
this.autoRedirects = config.autoRedirects || [];
|
|
50
54
|
}
|
|
51
55
|
/**
|
|
52
56
|
* Sets the Bearer token for client-side requests.
|
|
@@ -247,6 +251,7 @@ export class ApiClient {
|
|
|
247
251
|
const message = error instanceof Error ? error.message : 'Unexpected error occurred';
|
|
248
252
|
const errorObj = isApiError && error.json ? error.json : getProblemDetail({ status, title: "Server fetch error", type: "/exceptions/fetch-error/", detail: message });
|
|
249
253
|
//const errorObj = status != 503 ? message : getProblemDetail({status, title: "Server fetch error", type: "/exceptions/fetch-error/", detail: "Error fetching data from API", server: message });
|
|
254
|
+
this.evaluateRedirect(errorObj, status);
|
|
250
255
|
return {
|
|
251
256
|
ok: false,
|
|
252
257
|
status,
|
|
@@ -254,6 +259,24 @@ export class ApiClient {
|
|
|
254
259
|
};
|
|
255
260
|
}
|
|
256
261
|
}
|
|
262
|
+
evaluateRedirect(errorObj, status) {
|
|
263
|
+
for (const rule of this.autoRedirects) {
|
|
264
|
+
// Checks if the error matches the redirect rule value can be undefined to match if no value is specified.
|
|
265
|
+
if (status === rule.status && rule.errorKey in errorObj && (rule.errorValue === undefined || errorObj[rule.errorKey] === rule.errorValue)) {
|
|
266
|
+
if (browser) {
|
|
267
|
+
// Client-side redirect
|
|
268
|
+
import('$app/navigation').then(({ goto }) => {
|
|
269
|
+
goto(rule.redirectTo, { replaceState: true });
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
// Server-side redirect
|
|
274
|
+
throw redirect(303, rule.redirectTo);
|
|
275
|
+
}
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
257
280
|
// --- HTTP Method Shorthands ---
|
|
258
281
|
/**
|
|
259
282
|
* Sends a GET request to the specified API endpoint.
|