supaapps-api-kit-client 0.6.0 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { AxiosInstance, AxiosResponse } from 'axios';
1
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import { PaginatedResponse } from './types';
3
3
  type UnAuthorizedCallback = () => void;
4
4
  type AuthTokenCallback = () => Promise<string>;
@@ -21,17 +21,17 @@ export declare class ApiKitClient {
21
21
  get<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<T>>;
22
22
  getOne<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<T>>;
23
23
  getPaginated<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<PaginatedResponse<T>>>;
24
- post<T>(endpoint: string, data?: T): Promise<AxiosResponse<T>>;
25
- put<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>>;
26
- patch<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>>;
24
+ post<T>(endpoint: string, data?: T, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
25
+ put<T>(endpoint: string, data: Partial<T>, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
26
+ patch<T>(endpoint: string, data: Partial<T>, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
27
27
  delete<T>(endpoint: string): Promise<AxiosResponse<T>>;
28
28
  static initialize(baseURL: string, authTokenCallback?: AuthTokenCallback, unauthorizedCallback?: UnAuthorizedCallback, useAuth?: boolean): void;
29
29
  static get<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<T>>;
30
30
  static getOne<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<T>>;
31
31
  static getPaginated<T>(endpoint: string, params?: URLSearchParams): Promise<AxiosResponse<PaginatedResponse<T>>>;
32
- static post<T>(endpoint: string, data?: T): Promise<AxiosResponse<T>>;
33
- static put<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>>;
34
- static patch<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>>;
32
+ static post<T>(endpoint: string, data?: T, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
33
+ static put<T>(endpoint: string, data: Partial<T>, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
34
+ static patch<T>(endpoint: string, data: Partial<T>, options?: Omit<AxiosRequestConfig, 'url' | 'method'>): Promise<AxiosResponse<T>>;
35
35
  static delete<T>(endpoint: string): Promise<AxiosResponse<T>>;
36
36
  }
37
37
  export {};
@@ -79,25 +79,28 @@ class ApiKitClient {
79
79
  return axiosInstance.get(endpoint, { params });
80
80
  });
81
81
  }
82
- post(endpoint, data) {
82
+ post(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
83
+ ) {
83
84
  return __awaiter(this, void 0, void 0, function* () {
84
85
  this.checkInitialization();
85
86
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
86
- return axiosInstance.post(endpoint, data);
87
+ return axiosInstance.post(endpoint, data, options);
87
88
  });
88
89
  }
89
- put(endpoint, data) {
90
+ put(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
91
+ ) {
90
92
  return __awaiter(this, void 0, void 0, function* () {
91
93
  this.checkInitialization();
92
94
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
93
- return axiosInstance.put(endpoint, data);
95
+ return axiosInstance.put(endpoint, data, options);
94
96
  });
95
97
  }
96
- patch(endpoint, data) {
98
+ patch(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
99
+ ) {
97
100
  return __awaiter(this, void 0, void 0, function* () {
98
101
  this.checkInitialization();
99
102
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
100
- return axiosInstance.patch(endpoint, data);
103
+ return axiosInstance.patch(endpoint, data, options);
101
104
  });
102
105
  }
103
106
  delete(endpoint) {
@@ -126,19 +129,22 @@ class ApiKitClient {
126
129
  return (new ApiKitClient('default')).getPaginated(endpoint, params);
127
130
  });
128
131
  }
129
- static post(endpoint, data) {
132
+ static post(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
133
+ ) {
130
134
  return __awaiter(this, void 0, void 0, function* () {
131
- return (new ApiKitClient('default')).post(endpoint, data);
135
+ return (new ApiKitClient('default')).post(endpoint, data, options);
132
136
  });
133
137
  }
134
- static put(endpoint, data) {
138
+ static put(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
139
+ ) {
135
140
  return __awaiter(this, void 0, void 0, function* () {
136
- return (new ApiKitClient('default')).put(endpoint, data);
141
+ return (new ApiKitClient('default')).put(endpoint, data, options);
137
142
  });
138
143
  }
139
- static patch(endpoint, data) {
144
+ static patch(endpoint, data, options // Exclude 'url' and 'method' since they are handled separately
145
+ ) {
140
146
  return __awaiter(this, void 0, void 0, function* () {
141
- return (new ApiKitClient('default')).patch(endpoint, data);
147
+ return (new ApiKitClient('default')).patch(endpoint, data, options);
142
148
  });
143
149
  }
144
150
  static delete(endpoint) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supaapps-api-kit-client",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "A versatile, type-safe API kit client designed for TypeScript applications.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import axios, { AxiosInstance, AxiosResponse, AxiosError } from 'axios';
1
+ import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
2
2
  import { PaginatedResponse } from './types';
3
3
 
4
4
  type UnAuthorizedCallback = () => void;
@@ -92,22 +92,34 @@ export class ApiKitClient {
92
92
  return axiosInstance!.get<PaginatedResponse<T>>(endpoint, { params });
93
93
  }
94
94
 
95
- public async post<T>(endpoint: string, data?: T): Promise<AxiosResponse<T>> {
95
+ public async post<T>(
96
+ endpoint: string,
97
+ data?: T,
98
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
99
+ ): Promise<AxiosResponse<T>> {
96
100
  this.checkInitialization();
97
101
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
98
- return axiosInstance!.post<T>(endpoint, data);
102
+ return axiosInstance!.post<T>(endpoint, data, options);
99
103
  }
100
104
 
101
- public async put<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>> {
105
+ public async put<T>(
106
+ endpoint: string,
107
+ data: Partial<T>,
108
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
109
+ ): Promise<AxiosResponse<T>> {
102
110
  this.checkInitialization();
103
111
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
104
- return axiosInstance!.put<T>(endpoint, data);
112
+ return axiosInstance!.put<T>(endpoint, data, options);
105
113
  }
106
114
 
107
- public async patch<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>> {
115
+ public async patch<T>(
116
+ endpoint: string,
117
+ data: Partial<T>,
118
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
119
+ ): Promise<AxiosResponse<T>> {
108
120
  this.checkInitialization();
109
121
  const axiosInstance = ApiKitClient.apiClients[this.apiClientKey].axiosInstance;
110
- return axiosInstance!.patch<T>(endpoint, data);
122
+ return axiosInstance!.patch<T>(endpoint, data, options);
111
123
  }
112
124
 
113
125
  public async delete<T>(endpoint: string): Promise<AxiosResponse<T>> {
@@ -135,16 +147,28 @@ export class ApiKitClient {
135
147
  return (new ApiKitClient('default')).getPaginated<T>(endpoint, params);
136
148
  }
137
149
 
138
- public static async post<T>(endpoint: string, data?: T): Promise<AxiosResponse<T>> {
139
- return (new ApiKitClient('default')).post<T>(endpoint, data);
150
+ public static async post<T>(
151
+ endpoint: string,
152
+ data?: T,
153
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
154
+ ): Promise<AxiosResponse<T>> {
155
+ return (new ApiKitClient('default')).post<T>(endpoint, data, options);
140
156
  }
141
157
 
142
- public static async put<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>> {
143
- return (new ApiKitClient('default')).put<T>(endpoint, data);
158
+ public static async put<T>(
159
+ endpoint: string,
160
+ data: Partial<T>,
161
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
162
+ ): Promise<AxiosResponse<T>> {
163
+ return (new ApiKitClient('default')).put<T>(endpoint, data, options);
144
164
  }
145
165
 
146
- public static async patch<T>(endpoint: string, data: Partial<T>): Promise<AxiosResponse<T>> {
147
- return (new ApiKitClient('default')).patch<T>(endpoint, data);
166
+ public static async patch<T>(
167
+ endpoint: string,
168
+ data: Partial<T>,
169
+ options?: Omit<AxiosRequestConfig, 'url' | 'method'> // Exclude 'url' and 'method' since they are handled separately
170
+ ): Promise<AxiosResponse<T>> {
171
+ return (new ApiKitClient('default')).patch<T>(endpoint, data, options);
148
172
  }
149
173
 
150
174
  public static async delete<T>(endpoint: string): Promise<AxiosResponse<T>> {