squarefi-bff-api-module 1.32.36 → 1.32.37
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/dist/api/wallets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { apiClientV1Native, apiClientV2 } from '../utils/apiClientFactory';
|
|
2
2
|
import { defaultPaginationParams } from '../constants';
|
|
3
3
|
export const wallets = {
|
|
4
4
|
create: (data) => apiClientV2.postRequest('/wallets', { data }),
|
|
@@ -28,6 +28,6 @@ export const wallets = {
|
|
|
28
28
|
},
|
|
29
29
|
},
|
|
30
30
|
statementPdf: {
|
|
31
|
-
getByWalletUuid: ({ wallet_uuid, ...params }) =>
|
|
31
|
+
getByWalletUuid: ({ wallet_uuid, ...params }) => apiClientV1Native.getRequest(`/wallets/transactions/${wallet_uuid}/statement-pdf`, { params, responseType: 'blob' }),
|
|
32
32
|
},
|
|
33
33
|
};
|
|
@@ -10,12 +10,35 @@ export declare const createApiClient: ({ baseURL, isBearerToken, tenantId }: Cre
|
|
|
10
10
|
deleteRequest: (url: string, config?: AxiosRequestConfig) => Promise<any>;
|
|
11
11
|
getRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
12
12
|
};
|
|
13
|
+
type FetchRequestConfig = {
|
|
14
|
+
params?: Record<string, string | number | boolean>;
|
|
15
|
+
data?: Record<string, unknown> | unknown;
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
responseType?: 'json' | 'blob' | 'text' | 'arrayBuffer';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Native fetch-based API client.
|
|
21
|
+
* Used for endpoints that require native fetch behavior (e.g., blob responses for PDFs).
|
|
22
|
+
* Unlike axios-based client, this uses browser's native fetch API.
|
|
23
|
+
*/
|
|
24
|
+
export declare const createFetchApiClient: ({ baseURL, isBearerToken, tenantId }: CreateApiClientOptions) => {
|
|
25
|
+
getRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
26
|
+
postRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
27
|
+
patchRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
28
|
+
deleteRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
29
|
+
};
|
|
13
30
|
export declare const apiClientV1: {
|
|
14
31
|
patchRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
15
32
|
postRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
16
33
|
deleteRequest: (url: string, config?: AxiosRequestConfig) => Promise<any>;
|
|
17
34
|
getRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
18
35
|
};
|
|
36
|
+
export declare const apiClientV1Native: {
|
|
37
|
+
getRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
38
|
+
postRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
39
|
+
patchRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
40
|
+
deleteRequest: <T>(url: string, config?: FetchRequestConfig) => Promise<T>;
|
|
41
|
+
};
|
|
19
42
|
export declare const apiClientV2: {
|
|
20
43
|
patchRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
21
44
|
postRequest: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
|
|
@@ -122,10 +122,106 @@ export const createApiClient = ({ baseURL, isBearerToken, tenantId }) => {
|
|
|
122
122
|
};
|
|
123
123
|
return { patchRequest, postRequest, deleteRequest, getRequest };
|
|
124
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* Native fetch-based API client.
|
|
127
|
+
* Used for endpoints that require native fetch behavior (e.g., blob responses for PDFs).
|
|
128
|
+
* Unlike axios-based client, this uses browser's native fetch API.
|
|
129
|
+
*/
|
|
130
|
+
export const createFetchApiClient = ({ baseURL, isBearerToken, tenantId }) => {
|
|
131
|
+
const buildUrl = (url, params) => {
|
|
132
|
+
const fullUrl = `${baseURL}${url}`;
|
|
133
|
+
if (!params || Object.keys(params).length === 0) {
|
|
134
|
+
return fullUrl;
|
|
135
|
+
}
|
|
136
|
+
const searchParams = new URLSearchParams();
|
|
137
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
138
|
+
searchParams.append(key, String(value));
|
|
139
|
+
});
|
|
140
|
+
return `${fullUrl}?${searchParams.toString()}`;
|
|
141
|
+
};
|
|
142
|
+
const getHeaders = (additionalHeaders) => {
|
|
143
|
+
const { access_token } = getTokens();
|
|
144
|
+
const headers = {
|
|
145
|
+
'Content-Type': 'application/json',
|
|
146
|
+
'x-tenant-id': tenantId,
|
|
147
|
+
...additionalHeaders,
|
|
148
|
+
};
|
|
149
|
+
if (access_token) {
|
|
150
|
+
const authHeader = isBearerToken ? `Bearer ${access_token}` : access_token;
|
|
151
|
+
headers.Authorization = authHeader;
|
|
152
|
+
}
|
|
153
|
+
return headers;
|
|
154
|
+
};
|
|
155
|
+
const handleResponse = async (response, responseType) => {
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
let errorMessage = `HTTP error! status: ${response.status}`;
|
|
158
|
+
try {
|
|
159
|
+
const errorData = await response.json();
|
|
160
|
+
errorMessage = errorData.message || errorData.error || errorMessage;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
// If response is not JSON, use default error message
|
|
164
|
+
}
|
|
165
|
+
throw new Error(errorMessage);
|
|
166
|
+
}
|
|
167
|
+
// Handle different response types
|
|
168
|
+
switch (responseType) {
|
|
169
|
+
case 'blob':
|
|
170
|
+
return response.blob();
|
|
171
|
+
case 'text':
|
|
172
|
+
return response.text();
|
|
173
|
+
case 'arrayBuffer':
|
|
174
|
+
return response.arrayBuffer();
|
|
175
|
+
case 'json':
|
|
176
|
+
default:
|
|
177
|
+
return response.json();
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
const getRequest = async (url, config) => {
|
|
181
|
+
const fullUrl = buildUrl(url, config?.params);
|
|
182
|
+
const response = await fetch(fullUrl, {
|
|
183
|
+
method: 'GET',
|
|
184
|
+
headers: getHeaders(config?.headers),
|
|
185
|
+
});
|
|
186
|
+
return handleResponse(response, config?.responseType);
|
|
187
|
+
};
|
|
188
|
+
const postRequest = async (url, config) => {
|
|
189
|
+
const fullUrl = buildUrl(url);
|
|
190
|
+
const response = await fetch(fullUrl, {
|
|
191
|
+
method: 'POST',
|
|
192
|
+
headers: getHeaders(config?.headers),
|
|
193
|
+
body: config?.data ? JSON.stringify(config.data) : undefined,
|
|
194
|
+
});
|
|
195
|
+
return handleResponse(response, config?.responseType);
|
|
196
|
+
};
|
|
197
|
+
const patchRequest = async (url, config) => {
|
|
198
|
+
const fullUrl = buildUrl(url);
|
|
199
|
+
const response = await fetch(fullUrl, {
|
|
200
|
+
method: 'PATCH',
|
|
201
|
+
headers: getHeaders(config?.headers),
|
|
202
|
+
body: config?.data ? JSON.stringify(config.data) : undefined,
|
|
203
|
+
});
|
|
204
|
+
return handleResponse(response, config?.responseType);
|
|
205
|
+
};
|
|
206
|
+
const deleteRequest = async (url, config) => {
|
|
207
|
+
const fullUrl = buildUrl(url);
|
|
208
|
+
const response = await fetch(fullUrl, {
|
|
209
|
+
method: 'DELETE',
|
|
210
|
+
headers: getHeaders(config?.headers),
|
|
211
|
+
body: config?.data ? JSON.stringify(config.data) : undefined,
|
|
212
|
+
});
|
|
213
|
+
return handleResponse(response, config?.responseType);
|
|
214
|
+
};
|
|
215
|
+
return { getRequest, postRequest, patchRequest, deleteRequest };
|
|
216
|
+
};
|
|
125
217
|
export const apiClientV1 = createApiClient({
|
|
126
218
|
baseURL: apiV1BaseURL,
|
|
127
219
|
tenantId: envTenantId,
|
|
128
220
|
});
|
|
221
|
+
export const apiClientV1Native = createFetchApiClient({
|
|
222
|
+
baseURL: apiV1BaseURL,
|
|
223
|
+
tenantId: envTenantId,
|
|
224
|
+
});
|
|
129
225
|
export const apiClientV2 = createApiClient({
|
|
130
226
|
baseURL: apiV2BaseURL,
|
|
131
227
|
isBearerToken: true,
|