@hashrytech/quick-components-kit 0.13.5 → 0.14.0

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,11 @@
1
1
  # @hashrytech/quick-components-kit
2
2
 
3
+ ## 0.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - refactor: Changing the setAuthToken method to setAccessToken and removing the getAccessToken method
8
+
3
9
  ## 0.13.5
4
10
 
5
11
  ### Patch Changes
@@ -26,12 +26,7 @@ export interface ApiClientConfig {
26
26
  baseURL: string;
27
27
  /** Default headers to be sent with every request. */
28
28
  defaultHeaders?: HeadersInit;
29
- /** A function that returns the current access token. This is useful for client-side
30
- * operations where you might store the token in a Svelte store or similar.
31
- * For server-side operations using SvelteKit's `fetch`, the token is typically
32
- * handled by `src/hooks.server.ts` via `handleFetch`.
33
- */
34
- getAccessToken?: () => string | undefined;
29
+ /** Specified redirects if the response matches the specified rules. */
35
30
  autoRedirects?: AutoRedirectRule[];
36
31
  }
37
32
  export interface RequestOptions extends RequestInit {
@@ -86,8 +81,7 @@ export interface ApiClientEvents {
86
81
  export declare class ApiClient {
87
82
  private baseURL;
88
83
  private defaultHeaders;
89
- private clientAuthToken;
90
- private getAccessTokenFromStore;
84
+ private accessToken;
91
85
  private fetchInstance?;
92
86
  private autoRedirects;
93
87
  private requestInterceptors;
@@ -103,10 +97,9 @@ export declare class ApiClient {
103
97
  });
104
98
  /**
105
99
  * Sets the Bearer token for client-side requests.
106
- * This will override `getAccessToken` for subsequent requests using this client instance.
107
100
  * @param token - The access token string, or undefined to clear it.
108
101
  */
109
- setAuthToken(token: string | undefined): void;
102
+ setAccessToken(token: string | undefined): void;
110
103
  /**
111
104
  * Sets a custom fetch implementation globally for all requests made by this client.
112
105
  * Useful for passing enhanced `fetch` from SvelteKit's load functions.
@@ -32,10 +32,7 @@ export class ApiError extends Error {
32
32
  export class ApiClient {
33
33
  baseURL;
34
34
  defaultHeaders;
35
- // This token is primarily for explicit client-side setting if needed,
36
- // otherwise relies on getAccessTokenFromStore or SvelteKit's `handleFetch`.
37
- clientAuthToken;
38
- getAccessTokenFromStore;
35
+ accessToken;
39
36
  fetchInstance;
40
37
  autoRedirects = [];
41
38
  requestInterceptors = [];
@@ -49,16 +46,14 @@ export class ApiClient {
49
46
  constructor(config) {
50
47
  this.baseURL = config.baseURL;
51
48
  this.defaultHeaders = config.defaultHeaders || { 'Content-Type': 'application/json' };
52
- this.getAccessTokenFromStore = config.getAccessToken;
53
49
  this.autoRedirects = config.autoRedirects || [];
54
50
  }
55
51
  /**
56
52
  * Sets the Bearer token for client-side requests.
57
- * This will override `getAccessToken` for subsequent requests using this client instance.
58
53
  * @param token - The access token string, or undefined to clear it.
59
54
  */
60
- setAuthToken(token) {
61
- this.clientAuthToken = token;
55
+ setAccessToken(token) {
56
+ this.accessToken = token;
62
57
  }
63
58
  /**
64
59
  * Sets a custom fetch implementation globally for all requests made by this client.
@@ -113,12 +108,8 @@ export class ApiClient {
113
108
  }
114
109
  }
115
110
  // Add auth token unless skipped
116
- if (!options.skipAuth) {
117
- // Priority: Explicit clientAuthToken > getAccessTokenFromStore
118
- const token = this.clientAuthToken || (this.getAccessTokenFromStore ? this.getAccessTokenFromStore() : undefined);
119
- if (token) {
120
- requestHeaders.set('Authorization', `Bearer ${token}`);
121
- }
111
+ if (!options.skipAuth && this.accessToken) {
112
+ requestHeaders.set('Authorization', `Bearer ${this.accessToken}`);
122
113
  }
123
114
  let processedBody = undefined;
124
115
  if (body instanceof FormData) {
@@ -400,7 +391,7 @@ export class ApiClient {
400
391
  const url = new URL(endpoint, this.baseURL).toString();
401
392
  const formData = new FormData();
402
393
  formData.append(fieldName, file);
403
- const token = this.clientAuthToken || this.getAccessTokenFromStore?.();
394
+ const token = this.accessToken;
404
395
  const headers = new Headers(this.defaultHeaders);
405
396
  // Merge user-supplied headers
406
397
  if (options.headers) {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/hashrytech/quick-components-kit.git"
7
7
  },
8
- "version": "0.13.5",
8
+ "version": "0.14.0",
9
9
  "license": "MIT",
10
10
  "author": "Hashry Tech",
11
11
  "files": [