@1money/protocol-ts-sdk 1.1.2-alpha.6 → 1.1.2
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/README.md +28 -0
- package/es/api/index.js +15 -15
- package/es/client/index.d.ts +5 -6
- package/es/client/index.js +19 -27
- package/es/index.d.ts +0 -1
- package/es/index.js +21 -29
- package/lib/api/index.js +12 -10
- package/lib/client/index.d.ts +5 -6
- package/lib/client/index.js +16 -18
- package/lib/index.d.ts +0 -1
- package/lib/index.js +18 -20
- package/package.json +1 -1
- package/umd/1money-protocol-ts-sdk.min.js +1 -1
- package/.env.integration +0 -16
- package/umd/1money-ts-sdk.min.js +0 -2
package/README.md
CHANGED
|
@@ -37,6 +37,34 @@ const apiClient = api({
|
|
|
37
37
|
});
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
### Configure Custom HTTP Headers
|
|
41
|
+
|
|
42
|
+
You can set custom HTTP headers that will be included in all API requests:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { setInitConfig } from '@1money/protocol-ts-sdk';
|
|
46
|
+
|
|
47
|
+
// Set custom headers for all requests
|
|
48
|
+
setInitConfig({
|
|
49
|
+
headers: {
|
|
50
|
+
'Authorization': 'Bearer your-token',
|
|
51
|
+
'X-Custom-Header': 'custom-value'
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// You can also combine with other configuration options
|
|
56
|
+
setInitConfig({
|
|
57
|
+
baseURL: 'https://api.custom-domain.com',
|
|
58
|
+
timeout: 10000,
|
|
59
|
+
headers: {
|
|
60
|
+
'Authorization': 'Bearer your-token',
|
|
61
|
+
'X-API-Key': 'your-api-key'
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Note**: Custom headers are automatically merged with axios default headers, ensuring both your custom headers and the library's default security headers are included in all requests.
|
|
67
|
+
|
|
40
68
|
### Fetch the current checkpoint number
|
|
41
69
|
|
|
42
70
|
```typescript
|
package/es/api/index.js
CHANGED
|
@@ -287,42 +287,42 @@ class Request {
|
|
|
287
287
|
});
|
|
288
288
|
return ResPromise.promiseWrapper;
|
|
289
289
|
}
|
|
290
|
-
}const
|
|
290
|
+
}const client = new Request({
|
|
291
291
|
isSuccess: (res, status) => status === 200 && res.code == 0,
|
|
292
292
|
isLogin: (res, status) => status === 401 || res.code == 401,
|
|
293
293
|
timeout: 10000
|
|
294
294
|
});
|
|
295
|
-
let globalHeaders = {};
|
|
296
295
|
function get(url, options) {
|
|
297
|
-
|
|
298
|
-
return request({
|
|
296
|
+
return client.request({
|
|
299
297
|
...options,
|
|
300
298
|
method: 'get',
|
|
301
|
-
url
|
|
302
|
-
headers: {
|
|
303
|
-
...globalHeaders,
|
|
304
|
-
...options?.headers,
|
|
305
|
-
}
|
|
299
|
+
url
|
|
306
300
|
});
|
|
307
301
|
}
|
|
308
302
|
function post(url, data, options) {
|
|
309
|
-
return request({
|
|
303
|
+
return client.request({
|
|
310
304
|
...options,
|
|
311
305
|
method: 'post',
|
|
312
306
|
url,
|
|
313
307
|
data,
|
|
314
308
|
headers: {
|
|
315
309
|
'Content-Type': 'application/json',
|
|
316
|
-
...globalHeaders,
|
|
317
310
|
...options?.headers,
|
|
318
311
|
}
|
|
319
312
|
});
|
|
320
313
|
}
|
|
321
314
|
function setInitConfig(config) {
|
|
322
|
-
const { baseURL, ...rest } = config;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
315
|
+
const { baseURL, headers, ...rest } = config;
|
|
316
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
317
|
+
if (headers) {
|
|
318
|
+
client.axios.defaults.headers.common = {
|
|
319
|
+
...client.axios.defaults.headers.common,
|
|
320
|
+
...headers,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
client.setting(rest);
|
|
324
|
+
}
|
|
325
|
+
client.axios;// Base URLs for the API
|
|
326
326
|
const TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
327
327
|
const MAINNET_API_URL = 'https://api.1money.network';
|
|
328
328
|
const LOCAL_API_URL = 'http://localhost:18555';
|
package/es/client/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawAxiosRequestHeaders } from 'axios';
|
|
2
2
|
import type { InitConfig, Options } from './core';
|
|
3
|
-
declare const axiosStatic: import("axios").AxiosStatic;
|
|
4
3
|
export declare function get<T, U = unknown>(url: string, options?: Omit<Options<T, U>, 'method' | 'url'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
5
4
|
export declare function post<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
6
5
|
export declare function postForm<T, U = unknown>(url: string, data: FormData, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
7
6
|
export declare function put<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
8
7
|
export declare function patch<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
9
8
|
export declare function del<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
10
|
-
export declare function setInitConfig(config: InitConfig
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export declare function setInitConfig(config: InitConfig & {
|
|
10
|
+
headers?: RawAxiosRequestHeaders;
|
|
11
|
+
}): void;
|
|
13
12
|
export type { InitConfig, Options, ParsedError, PromiseWrapper } from './core';
|
|
13
|
+
export declare const axiosStatic: import("axios").AxiosStatic;
|
|
14
14
|
declare const _default: {
|
|
15
15
|
get: typeof get;
|
|
16
16
|
post: typeof post;
|
|
@@ -19,7 +19,6 @@ declare const _default: {
|
|
|
19
19
|
put: typeof put;
|
|
20
20
|
patch: typeof patch;
|
|
21
21
|
setInitConfig: typeof setInitConfig;
|
|
22
|
-
setGlobalHeaders: typeof setGlobalHeaders;
|
|
23
22
|
axiosStatic: import("axios").AxiosStatic;
|
|
24
23
|
};
|
|
25
24
|
export default _default;
|
package/es/client/index.js
CHANGED
|
@@ -287,97 +287,90 @@ class Request {
|
|
|
287
287
|
});
|
|
288
288
|
return ResPromise.promiseWrapper;
|
|
289
289
|
}
|
|
290
|
-
}const
|
|
290
|
+
}const client = new Request({
|
|
291
291
|
isSuccess: (res, status) => status === 200 && res.code == 0,
|
|
292
292
|
isLogin: (res, status) => status === 401 || res.code == 401,
|
|
293
293
|
timeout: 10000
|
|
294
294
|
});
|
|
295
|
-
let globalHeaders = {};
|
|
296
295
|
function get(url, options) {
|
|
297
|
-
|
|
298
|
-
return request({
|
|
296
|
+
return client.request({
|
|
299
297
|
...options,
|
|
300
298
|
method: 'get',
|
|
301
|
-
url
|
|
302
|
-
headers: {
|
|
303
|
-
...globalHeaders,
|
|
304
|
-
...options?.headers,
|
|
305
|
-
}
|
|
299
|
+
url
|
|
306
300
|
});
|
|
307
301
|
}
|
|
308
302
|
function post(url, data, options) {
|
|
309
|
-
return request({
|
|
303
|
+
return client.request({
|
|
310
304
|
...options,
|
|
311
305
|
method: 'post',
|
|
312
306
|
url,
|
|
313
307
|
data,
|
|
314
308
|
headers: {
|
|
315
309
|
'Content-Type': 'application/json',
|
|
316
|
-
...globalHeaders,
|
|
317
310
|
...options?.headers,
|
|
318
311
|
}
|
|
319
312
|
});
|
|
320
313
|
}
|
|
321
314
|
function postForm(url, data, options) {
|
|
322
|
-
return request({
|
|
315
|
+
return client.request({
|
|
323
316
|
...options,
|
|
324
317
|
method: 'post',
|
|
325
318
|
url,
|
|
326
319
|
data,
|
|
327
320
|
headers: {
|
|
328
321
|
'Content-Type': 'multipart/form-data',
|
|
329
|
-
...globalHeaders,
|
|
330
322
|
...options?.headers,
|
|
331
323
|
}
|
|
332
324
|
});
|
|
333
325
|
}
|
|
334
326
|
function put(url, data, options) {
|
|
335
|
-
return request({
|
|
327
|
+
return client.request({
|
|
336
328
|
...options,
|
|
337
329
|
method: 'put',
|
|
338
330
|
url,
|
|
339
331
|
data,
|
|
340
332
|
headers: {
|
|
341
333
|
'Content-Type': 'application/json',
|
|
342
|
-
...globalHeaders,
|
|
343
334
|
...options?.headers,
|
|
344
335
|
}
|
|
345
336
|
});
|
|
346
337
|
}
|
|
347
338
|
function patch(url, data, options) {
|
|
348
|
-
return request({
|
|
339
|
+
return client.request({
|
|
349
340
|
...options,
|
|
350
341
|
method: 'patch',
|
|
351
342
|
url,
|
|
352
343
|
data,
|
|
353
344
|
headers: {
|
|
354
345
|
'Content-Type': 'application/json',
|
|
355
|
-
...globalHeaders,
|
|
356
346
|
...options?.headers,
|
|
357
347
|
}
|
|
358
348
|
});
|
|
359
349
|
}
|
|
360
350
|
function del(url, data, options) {
|
|
361
|
-
return request({
|
|
351
|
+
return client.request({
|
|
362
352
|
...options,
|
|
363
353
|
method: 'delete',
|
|
364
354
|
url,
|
|
365
355
|
data,
|
|
366
356
|
headers: {
|
|
367
357
|
'Content-Type': 'application/json',
|
|
368
|
-
...globalHeaders,
|
|
369
358
|
...options?.headers,
|
|
370
359
|
}
|
|
371
360
|
});
|
|
372
361
|
}
|
|
373
362
|
function setInitConfig(config) {
|
|
374
|
-
const { baseURL, ...rest } = config;
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
363
|
+
const { baseURL, headers, ...rest } = config;
|
|
364
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
365
|
+
if (headers) {
|
|
366
|
+
client.axios.defaults.headers.common = {
|
|
367
|
+
...client.axios.defaults.headers.common,
|
|
368
|
+
...headers,
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
client.setting(rest);
|
|
380
372
|
}
|
|
373
|
+
const axiosStatic = client.axios;
|
|
381
374
|
var index = {
|
|
382
375
|
get,
|
|
383
376
|
post,
|
|
@@ -386,6 +379,5 @@ var index = {
|
|
|
386
379
|
put,
|
|
387
380
|
patch,
|
|
388
381
|
setInitConfig,
|
|
389
|
-
setGlobalHeaders,
|
|
390
382
|
axiosStatic
|
|
391
|
-
};export{axiosStatic,index as default,del,get,patch,post,postForm,put,
|
|
383
|
+
};export{axiosStatic,index as default,del,get,patch,post,postForm,put,setInitConfig};
|
package/es/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ declare const _default: {
|
|
|
14
14
|
put: typeof import("./client/index.js").put;
|
|
15
15
|
patch: typeof import("./client/index.js").patch;
|
|
16
16
|
setInitConfig: typeof import("./client/index.js").setInitConfig;
|
|
17
|
-
setGlobalHeaders: typeof import("./client/index.js").setGlobalHeaders;
|
|
18
17
|
axiosStatic: import("axios").AxiosStatic;
|
|
19
18
|
};
|
|
20
19
|
};
|
package/es/index.js
CHANGED
|
@@ -1131,98 +1131,91 @@ class Request {
|
|
|
1131
1131
|
});
|
|
1132
1132
|
return ResPromise.promiseWrapper;
|
|
1133
1133
|
}
|
|
1134
|
-
}const
|
|
1134
|
+
}const client = new Request({
|
|
1135
1135
|
isSuccess: (res, status) => status === 200 && res.code == 0,
|
|
1136
1136
|
isLogin: (res, status) => status === 401 || res.code == 401,
|
|
1137
1137
|
timeout: 10000
|
|
1138
1138
|
});
|
|
1139
|
-
let globalHeaders = {};
|
|
1140
1139
|
function get(url, options) {
|
|
1141
|
-
|
|
1142
|
-
return request({
|
|
1140
|
+
return client.request({
|
|
1143
1141
|
...options,
|
|
1144
1142
|
method: 'get',
|
|
1145
|
-
url
|
|
1146
|
-
headers: {
|
|
1147
|
-
...globalHeaders,
|
|
1148
|
-
...options?.headers,
|
|
1149
|
-
}
|
|
1143
|
+
url
|
|
1150
1144
|
});
|
|
1151
1145
|
}
|
|
1152
1146
|
function post(url, data, options) {
|
|
1153
|
-
return request({
|
|
1147
|
+
return client.request({
|
|
1154
1148
|
...options,
|
|
1155
1149
|
method: 'post',
|
|
1156
1150
|
url,
|
|
1157
1151
|
data,
|
|
1158
1152
|
headers: {
|
|
1159
1153
|
'Content-Type': 'application/json',
|
|
1160
|
-
...globalHeaders,
|
|
1161
1154
|
...options?.headers,
|
|
1162
1155
|
}
|
|
1163
1156
|
});
|
|
1164
1157
|
}
|
|
1165
1158
|
function postForm(url, data, options) {
|
|
1166
|
-
return request({
|
|
1159
|
+
return client.request({
|
|
1167
1160
|
...options,
|
|
1168
1161
|
method: 'post',
|
|
1169
1162
|
url,
|
|
1170
1163
|
data,
|
|
1171
1164
|
headers: {
|
|
1172
1165
|
'Content-Type': 'multipart/form-data',
|
|
1173
|
-
...globalHeaders,
|
|
1174
1166
|
...options?.headers,
|
|
1175
1167
|
}
|
|
1176
1168
|
});
|
|
1177
1169
|
}
|
|
1178
1170
|
function put(url, data, options) {
|
|
1179
|
-
return request({
|
|
1171
|
+
return client.request({
|
|
1180
1172
|
...options,
|
|
1181
1173
|
method: 'put',
|
|
1182
1174
|
url,
|
|
1183
1175
|
data,
|
|
1184
1176
|
headers: {
|
|
1185
1177
|
'Content-Type': 'application/json',
|
|
1186
|
-
...globalHeaders,
|
|
1187
1178
|
...options?.headers,
|
|
1188
1179
|
}
|
|
1189
1180
|
});
|
|
1190
1181
|
}
|
|
1191
1182
|
function patch(url, data, options) {
|
|
1192
|
-
return request({
|
|
1183
|
+
return client.request({
|
|
1193
1184
|
...options,
|
|
1194
1185
|
method: 'patch',
|
|
1195
1186
|
url,
|
|
1196
1187
|
data,
|
|
1197
1188
|
headers: {
|
|
1198
1189
|
'Content-Type': 'application/json',
|
|
1199
|
-
...globalHeaders,
|
|
1200
1190
|
...options?.headers,
|
|
1201
1191
|
}
|
|
1202
1192
|
});
|
|
1203
1193
|
}
|
|
1204
1194
|
function del(url, data, options) {
|
|
1205
|
-
return request({
|
|
1195
|
+
return client.request({
|
|
1206
1196
|
...options,
|
|
1207
1197
|
method: 'delete',
|
|
1208
1198
|
url,
|
|
1209
1199
|
data,
|
|
1210
1200
|
headers: {
|
|
1211
1201
|
'Content-Type': 'application/json',
|
|
1212
|
-
...globalHeaders,
|
|
1213
1202
|
...options?.headers,
|
|
1214
1203
|
}
|
|
1215
1204
|
});
|
|
1216
1205
|
}
|
|
1217
1206
|
function setInitConfig(config) {
|
|
1218
|
-
const { baseURL, ...rest } = config;
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1207
|
+
const { baseURL, headers, ...rest } = config;
|
|
1208
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
1209
|
+
if (headers) {
|
|
1210
|
+
client.axios.defaults.headers.common = {
|
|
1211
|
+
...client.axios.defaults.headers.common,
|
|
1212
|
+
...headers,
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
client.setting(rest);
|
|
1224
1216
|
}
|
|
1225
|
-
|
|
1217
|
+
const axiosStatic = client.axios;
|
|
1218
|
+
var client$1 = {
|
|
1226
1219
|
get,
|
|
1227
1220
|
post,
|
|
1228
1221
|
postForm,
|
|
@@ -1230,7 +1223,6 @@ var client = {
|
|
|
1230
1223
|
put,
|
|
1231
1224
|
patch,
|
|
1232
1225
|
setInitConfig,
|
|
1233
|
-
setGlobalHeaders,
|
|
1234
1226
|
axiosStatic
|
|
1235
1227
|
};// Base URLs for the API
|
|
1236
1228
|
const TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
@@ -1538,5 +1530,5 @@ function api(options) {
|
|
|
1538
1530
|
};
|
|
1539
1531
|
}var index = {
|
|
1540
1532
|
api,
|
|
1541
|
-
client,
|
|
1542
|
-
};export{_typeof,api,calcTxHash,client,index as default,deriveTokenAddress,encodePayload,safePromiseAll,safePromiseLine,signMessage,toHex};
|
|
1533
|
+
client: client$1,
|
|
1534
|
+
};export{_typeof,api,calcTxHash,client$1 as client,index as default,deriveTokenAddress,encodePayload,safePromiseAll,safePromiseLine,signMessage,toHex};
|
package/lib/api/index.js
CHANGED
|
@@ -393,24 +393,26 @@ var Request = /** @class */ (function () {
|
|
|
393
393
|
return ResPromise.promiseWrapper;
|
|
394
394
|
};
|
|
395
395
|
return Request;
|
|
396
|
-
}());var
|
|
396
|
+
}());var client = new Request({
|
|
397
397
|
isSuccess: function (res, status) { return status === 200 && res.code == 0; },
|
|
398
398
|
isLogin: function (res, status) { return status === 401 || res.code == 401; },
|
|
399
399
|
timeout: 10000
|
|
400
|
-
})
|
|
401
|
-
var globalHeaders = {};
|
|
400
|
+
});
|
|
402
401
|
function get(url, options) {
|
|
403
|
-
|
|
404
|
-
return request(__assign(__assign({}, options), { method: 'get', url: url, headers: __assign(__assign({}, globalHeaders), options === null || options === void 0 ? void 0 : options.headers) }));
|
|
402
|
+
return client.request(__assign(__assign({}, options), { method: 'get', url: url }));
|
|
405
403
|
}
|
|
406
404
|
function post(url, data, options) {
|
|
407
|
-
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign(
|
|
405
|
+
return client.request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
408
406
|
}
|
|
409
407
|
function setInitConfig(config) {
|
|
410
|
-
var baseURL = config.baseURL, rest = __rest(config, ["baseURL"]);
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
408
|
+
var baseURL = config.baseURL, headers = config.headers, rest = __rest(config, ["baseURL", "headers"]);
|
|
409
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
410
|
+
if (headers) {
|
|
411
|
+
client.axios.defaults.headers.common = __assign(__assign({}, client.axios.defaults.headers.common), headers);
|
|
412
|
+
}
|
|
413
|
+
client.setting(rest);
|
|
414
|
+
}
|
|
415
|
+
client.axios;// Base URLs for the API
|
|
414
416
|
var TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
415
417
|
var MAINNET_API_URL = 'https://api.1money.network';
|
|
416
418
|
var LOCAL_API_URL = 'http://localhost:18555';
|
package/lib/client/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RawAxiosRequestHeaders } from 'axios';
|
|
2
2
|
import type { InitConfig, Options } from './core';
|
|
3
|
-
declare const axiosStatic: import("axios").AxiosStatic;
|
|
4
3
|
export declare function get<T, U = unknown>(url: string, options?: Omit<Options<T, U>, 'method' | 'url'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
5
4
|
export declare function post<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
6
5
|
export declare function postForm<T, U = unknown>(url: string, data: FormData, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
7
6
|
export declare function put<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
8
7
|
export declare function patch<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
9
8
|
export declare function del<T, U = unknown>(url: string, data: Record<string, any>, options?: Omit<Options<T, U>, 'method' | 'url' | 'data'>): import("./core").PromiseWrapper<T, U, import("./core").CustomResponseData<T, U, T>, import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<string>, import("./core").ParsedError<string> | import("./core").CustomResponseData<T, U, null | undefined>, import("./core").ParsedError<"timeout">, ""> & Promise<import("./core").CustomResponseData<T, U, import("./core").WithFailureData<T>>>;
|
|
10
|
-
export declare function setInitConfig(config: InitConfig
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
export declare function setInitConfig(config: InitConfig & {
|
|
10
|
+
headers?: RawAxiosRequestHeaders;
|
|
11
|
+
}): void;
|
|
13
12
|
export type { InitConfig, Options, ParsedError, PromiseWrapper } from './core';
|
|
13
|
+
export declare const axiosStatic: import("axios").AxiosStatic;
|
|
14
14
|
declare const _default: {
|
|
15
15
|
get: typeof get;
|
|
16
16
|
post: typeof post;
|
|
@@ -19,7 +19,6 @@ declare const _default: {
|
|
|
19
19
|
put: typeof put;
|
|
20
20
|
patch: typeof patch;
|
|
21
21
|
setInitConfig: typeof setInitConfig;
|
|
22
|
-
setGlobalHeaders: typeof setGlobalHeaders;
|
|
23
22
|
axiosStatic: import("axios").AxiosStatic;
|
|
24
23
|
};
|
|
25
24
|
export default _default;
|
package/lib/client/index.js
CHANGED
|
@@ -393,39 +393,38 @@ var Request = /** @class */ (function () {
|
|
|
393
393
|
return ResPromise.promiseWrapper;
|
|
394
394
|
};
|
|
395
395
|
return Request;
|
|
396
|
-
}());var
|
|
396
|
+
}());var client = new Request({
|
|
397
397
|
isSuccess: function (res, status) { return status === 200 && res.code == 0; },
|
|
398
398
|
isLogin: function (res, status) { return status === 401 || res.code == 401; },
|
|
399
399
|
timeout: 10000
|
|
400
|
-
})
|
|
401
|
-
var globalHeaders = {};
|
|
400
|
+
});
|
|
402
401
|
function get(url, options) {
|
|
403
|
-
|
|
404
|
-
return request(__assign(__assign({}, options), { method: 'get', url: url, headers: __assign(__assign({}, globalHeaders), options === null || options === void 0 ? void 0 : options.headers) }));
|
|
402
|
+
return client.request(__assign(__assign({}, options), { method: 'get', url: url }));
|
|
405
403
|
}
|
|
406
404
|
function post(url, data, options) {
|
|
407
|
-
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign(
|
|
405
|
+
return client.request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
408
406
|
}
|
|
409
407
|
function postForm(url, data, options) {
|
|
410
|
-
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign(
|
|
408
|
+
return client.request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'multipart/form-data' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
411
409
|
}
|
|
412
410
|
function put(url, data, options) {
|
|
413
|
-
return request(__assign(__assign({}, options), { method: 'put', url: url, data: data, headers: __assign(
|
|
411
|
+
return client.request(__assign(__assign({}, options), { method: 'put', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
414
412
|
}
|
|
415
413
|
function patch(url, data, options) {
|
|
416
|
-
return request(__assign(__assign({}, options), { method: 'patch', url: url, data: data, headers: __assign(
|
|
414
|
+
return client.request(__assign(__assign({}, options), { method: 'patch', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
417
415
|
}
|
|
418
416
|
function del(url, data, options) {
|
|
419
|
-
return request(__assign(__assign({}, options), { method: 'delete', url: url, data: data, headers: __assign(
|
|
417
|
+
return client.request(__assign(__assign({}, options), { method: 'delete', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
420
418
|
}
|
|
421
419
|
function setInitConfig(config) {
|
|
422
|
-
var baseURL = config.baseURL, rest = __rest(config, ["baseURL"]);
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
420
|
+
var baseURL = config.baseURL, headers = config.headers, rest = __rest(config, ["baseURL", "headers"]);
|
|
421
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
422
|
+
if (headers) {
|
|
423
|
+
client.axios.defaults.headers.common = __assign(__assign({}, client.axios.defaults.headers.common), headers);
|
|
424
|
+
}
|
|
425
|
+
client.setting(rest);
|
|
428
426
|
}
|
|
427
|
+
var axiosStatic = client.axios;
|
|
429
428
|
var index = {
|
|
430
429
|
get: get,
|
|
431
430
|
post: post,
|
|
@@ -434,6 +433,5 @@ var index = {
|
|
|
434
433
|
put: put,
|
|
435
434
|
patch: patch,
|
|
436
435
|
setInitConfig: setInitConfig,
|
|
437
|
-
setGlobalHeaders: setGlobalHeaders,
|
|
438
436
|
axiosStatic: axiosStatic
|
|
439
|
-
};exports.axiosStatic=axiosStatic;exports.default=index;exports.del=del;exports.get=get;exports.patch=patch;exports.post=post;exports.postForm=postForm;exports.put=put;exports.
|
|
437
|
+
};exports.axiosStatic=axiosStatic;exports.default=index;exports.del=del;exports.get=get;exports.patch=patch;exports.post=post;exports.postForm=postForm;exports.put=put;exports.setInitConfig=setInitConfig;
|
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ declare const _default: {
|
|
|
14
14
|
put: typeof import("./client/index.js").put;
|
|
15
15
|
patch: typeof import("./client/index.js").patch;
|
|
16
16
|
setInitConfig: typeof import("./client/index.js").setInitConfig;
|
|
17
|
-
setGlobalHeaders: typeof import("./client/index.js").setGlobalHeaders;
|
|
18
17
|
axiosStatic: import("axios").AxiosStatic;
|
|
19
18
|
};
|
|
20
19
|
};
|
package/lib/index.js
CHANGED
|
@@ -1275,40 +1275,39 @@ var Request = /** @class */ (function () {
|
|
|
1275
1275
|
return ResPromise.promiseWrapper;
|
|
1276
1276
|
};
|
|
1277
1277
|
return Request;
|
|
1278
|
-
}());var
|
|
1278
|
+
}());var client = new Request({
|
|
1279
1279
|
isSuccess: function (res, status) { return status === 200 && res.code == 0; },
|
|
1280
1280
|
isLogin: function (res, status) { return status === 401 || res.code == 401; },
|
|
1281
1281
|
timeout: 10000
|
|
1282
|
-
})
|
|
1283
|
-
var globalHeaders = {};
|
|
1282
|
+
});
|
|
1284
1283
|
function get(url, options) {
|
|
1285
|
-
|
|
1286
|
-
return request(__assign(__assign({}, options), { method: 'get', url: url, headers: __assign(__assign({}, globalHeaders), options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1284
|
+
return client.request(__assign(__assign({}, options), { method: 'get', url: url }));
|
|
1287
1285
|
}
|
|
1288
1286
|
function post(url, data, options) {
|
|
1289
|
-
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign(
|
|
1287
|
+
return client.request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1290
1288
|
}
|
|
1291
1289
|
function postForm(url, data, options) {
|
|
1292
|
-
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign(
|
|
1290
|
+
return client.request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'multipart/form-data' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1293
1291
|
}
|
|
1294
1292
|
function put(url, data, options) {
|
|
1295
|
-
return request(__assign(__assign({}, options), { method: 'put', url: url, data: data, headers: __assign(
|
|
1293
|
+
return client.request(__assign(__assign({}, options), { method: 'put', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1296
1294
|
}
|
|
1297
1295
|
function patch(url, data, options) {
|
|
1298
|
-
return request(__assign(__assign({}, options), { method: 'patch', url: url, data: data, headers: __assign(
|
|
1296
|
+
return client.request(__assign(__assign({}, options), { method: 'patch', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1299
1297
|
}
|
|
1300
1298
|
function del(url, data, options) {
|
|
1301
|
-
return request(__assign(__assign({}, options), { method: 'delete', url: url, data: data, headers: __assign(
|
|
1299
|
+
return client.request(__assign(__assign({}, options), { method: 'delete', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
1302
1300
|
}
|
|
1303
1301
|
function setInitConfig(config) {
|
|
1304
|
-
var baseURL = config.baseURL, rest = __rest(config, ["baseURL"]);
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1302
|
+
var baseURL = config.baseURL, headers = config.headers, rest = __rest(config, ["baseURL", "headers"]);
|
|
1303
|
+
client.axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
1304
|
+
if (headers) {
|
|
1305
|
+
client.axios.defaults.headers.common = __assign(__assign({}, client.axios.defaults.headers.common), headers);
|
|
1306
|
+
}
|
|
1307
|
+
client.setting(rest);
|
|
1310
1308
|
}
|
|
1311
|
-
var
|
|
1309
|
+
var axiosStatic = client.axios;
|
|
1310
|
+
var client$1 = {
|
|
1312
1311
|
get: get,
|
|
1313
1312
|
post: post,
|
|
1314
1313
|
postForm: postForm,
|
|
@@ -1316,7 +1315,6 @@ var client = {
|
|
|
1316
1315
|
put: put,
|
|
1317
1316
|
patch: patch,
|
|
1318
1317
|
setInitConfig: setInitConfig,
|
|
1319
|
-
setGlobalHeaders: setGlobalHeaders,
|
|
1320
1318
|
axiosStatic: axiosStatic
|
|
1321
1319
|
};// Base URLs for the API
|
|
1322
1320
|
var TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
@@ -1626,5 +1624,5 @@ function api(options) {
|
|
|
1626
1624
|
};
|
|
1627
1625
|
}var index = {
|
|
1628
1626
|
api: api,
|
|
1629
|
-
client: client,
|
|
1630
|
-
};exports._typeof=_typeof;exports.api=api;exports.calcTxHash=calcTxHash;exports.client=client;exports.default=index;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;
|
|
1627
|
+
client: client$1,
|
|
1628
|
+
};exports._typeof=_typeof;exports.api=api;exports.calcTxHash=calcTxHash;exports.client=client$1;exports.default=index;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;
|