fexios-browser 1.0.1 → 1.1.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/dist/index.cjs +46 -9
- package/dist/index.d.cts +23 -10
- package/dist/index.d.ts +23 -10
- package/dist/index.js +46 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -58,24 +58,29 @@ var InterceptorManager = class {
|
|
58
58
|
var InterceptorManager_default = InterceptorManager;
|
59
59
|
|
60
60
|
// src/index.ts
|
61
|
-
var Fexios = class {
|
62
|
-
|
63
|
-
headers;
|
61
|
+
var Fexios = class _Fexios {
|
62
|
+
defaults;
|
64
63
|
interceptors;
|
65
|
-
constructor(
|
66
|
-
this.
|
67
|
-
this.headers = headers;
|
64
|
+
constructor(initConfig) {
|
65
|
+
this.defaults = initConfig;
|
68
66
|
this.interceptors = {
|
69
67
|
request: new InterceptorManager_default(),
|
70
68
|
response: new InterceptorManager_default()
|
71
69
|
};
|
72
70
|
}
|
71
|
+
create(initConfig) {
|
72
|
+
const config = {
|
73
|
+
...this.defaults,
|
74
|
+
...initConfig
|
75
|
+
};
|
76
|
+
return new _Fexios(config);
|
77
|
+
}
|
73
78
|
async request(request) {
|
74
79
|
try {
|
75
80
|
const mergedRequest = {
|
76
81
|
...request,
|
77
|
-
headers: { ...this.headers, ...request.headers },
|
78
|
-
baseURL: request.baseURL || this.baseURL
|
82
|
+
headers: { ...this.defaults.headers, ...request.headers },
|
83
|
+
baseURL: request.baseURL || this.defaults.baseURL
|
79
84
|
};
|
80
85
|
let chain = Promise.resolve(mergedRequest);
|
81
86
|
this.interceptors.request.forEach(({ fulfilled, rejected }) => {
|
@@ -89,7 +94,7 @@ var Fexios = class {
|
|
89
94
|
});
|
90
95
|
const contentType = rowResponse.headers.get("Content-Type") || "";
|
91
96
|
let responseData;
|
92
|
-
if (contentType.includes("json")) {
|
97
|
+
if (contentType.includes("application/json")) {
|
93
98
|
responseData = await rowResponse.json();
|
94
99
|
} else {
|
95
100
|
responseData = rowResponse;
|
@@ -119,5 +124,37 @@ var Fexios = class {
|
|
119
124
|
throw error;
|
120
125
|
}
|
121
126
|
}
|
127
|
+
async get(url, request) {
|
128
|
+
const getRequest = {
|
129
|
+
...request,
|
130
|
+
url,
|
131
|
+
method: "GET"
|
132
|
+
};
|
133
|
+
return this.request(getRequest);
|
134
|
+
}
|
135
|
+
async post(url, request) {
|
136
|
+
const postRequest = {
|
137
|
+
...request,
|
138
|
+
url,
|
139
|
+
method: "POST"
|
140
|
+
};
|
141
|
+
return this.request(postRequest);
|
142
|
+
}
|
143
|
+
async delete(url, request) {
|
144
|
+
const deleteRequest = {
|
145
|
+
...request,
|
146
|
+
url,
|
147
|
+
method: "DELETE"
|
148
|
+
};
|
149
|
+
return this.request(deleteRequest);
|
150
|
+
}
|
151
|
+
async put(url, request) {
|
152
|
+
const putRequest = {
|
153
|
+
...request,
|
154
|
+
url,
|
155
|
+
method: "PUT"
|
156
|
+
};
|
157
|
+
return this.request(putRequest);
|
158
|
+
}
|
122
159
|
};
|
123
160
|
var index_default = Fexios;
|
package/dist/index.d.cts
CHANGED
@@ -1,23 +1,36 @@
|
|
1
|
+
import InterceptorManager from './InterceptorManager.cjs';
|
2
|
+
|
1
3
|
interface FRequest {
|
2
|
-
url: string;
|
4
|
+
url: string | URL;
|
3
5
|
headers?: Record<string, string>;
|
4
|
-
method: "GET" | "POST";
|
5
|
-
baseURL?: string;
|
6
|
-
data?:
|
6
|
+
method: "GET" | "POST" | "DELETE" | "PUT";
|
7
|
+
baseURL?: string | URL;
|
8
|
+
data?: any;
|
7
9
|
}
|
8
10
|
interface FResponse {
|
9
11
|
status: number;
|
10
12
|
statusText: string;
|
11
|
-
data:
|
13
|
+
data: any;
|
12
14
|
headers: Record<string, string>;
|
13
15
|
request: FRequest;
|
14
16
|
}
|
17
|
+
interface InitConfig {
|
18
|
+
baseURL: string | URL;
|
19
|
+
headers: Record<string, string>;
|
20
|
+
}
|
15
21
|
declare class Fexios {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
defaults: InitConfig;
|
23
|
+
interceptors: {
|
24
|
+
request: InterceptorManager;
|
25
|
+
response: InterceptorManager;
|
26
|
+
};
|
27
|
+
constructor(initConfig: InitConfig);
|
28
|
+
create(initConfig: Partial<InitConfig>): Fexios;
|
20
29
|
request(request: FRequest): Promise<FResponse>;
|
30
|
+
get(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
31
|
+
post(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
32
|
+
delete(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
33
|
+
put(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
21
34
|
}
|
22
35
|
|
23
|
-
export { type FRequest, type FResponse, Fexios as default };
|
36
|
+
export { type FRequest, type FResponse, type InitConfig, Fexios as default };
|
package/dist/index.d.ts
CHANGED
@@ -1,23 +1,36 @@
|
|
1
|
+
import InterceptorManager from './InterceptorManager.js';
|
2
|
+
|
1
3
|
interface FRequest {
|
2
|
-
url: string;
|
4
|
+
url: string | URL;
|
3
5
|
headers?: Record<string, string>;
|
4
|
-
method: "GET" | "POST";
|
5
|
-
baseURL?: string;
|
6
|
-
data?:
|
6
|
+
method: "GET" | "POST" | "DELETE" | "PUT";
|
7
|
+
baseURL?: string | URL;
|
8
|
+
data?: any;
|
7
9
|
}
|
8
10
|
interface FResponse {
|
9
11
|
status: number;
|
10
12
|
statusText: string;
|
11
|
-
data:
|
13
|
+
data: any;
|
12
14
|
headers: Record<string, string>;
|
13
15
|
request: FRequest;
|
14
16
|
}
|
17
|
+
interface InitConfig {
|
18
|
+
baseURL: string | URL;
|
19
|
+
headers: Record<string, string>;
|
20
|
+
}
|
15
21
|
declare class Fexios {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
22
|
+
defaults: InitConfig;
|
23
|
+
interceptors: {
|
24
|
+
request: InterceptorManager;
|
25
|
+
response: InterceptorManager;
|
26
|
+
};
|
27
|
+
constructor(initConfig: InitConfig);
|
28
|
+
create(initConfig: Partial<InitConfig>): Fexios;
|
20
29
|
request(request: FRequest): Promise<FResponse>;
|
30
|
+
get(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
31
|
+
post(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
32
|
+
delete(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
33
|
+
put(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
21
34
|
}
|
22
35
|
|
23
|
-
export { type FRequest, type FResponse, Fexios as default };
|
36
|
+
export { type FRequest, type FResponse, type InitConfig, Fexios as default };
|
package/dist/index.js
CHANGED
@@ -3,24 +3,29 @@ import {
|
|
3
3
|
} from "./chunk-UDNTQS3I.js";
|
4
4
|
|
5
5
|
// src/index.ts
|
6
|
-
var Fexios = class {
|
7
|
-
|
8
|
-
headers;
|
6
|
+
var Fexios = class _Fexios {
|
7
|
+
defaults;
|
9
8
|
interceptors;
|
10
|
-
constructor(
|
11
|
-
this.
|
12
|
-
this.headers = headers;
|
9
|
+
constructor(initConfig) {
|
10
|
+
this.defaults = initConfig;
|
13
11
|
this.interceptors = {
|
14
12
|
request: new InterceptorManager_default(),
|
15
13
|
response: new InterceptorManager_default()
|
16
14
|
};
|
17
15
|
}
|
16
|
+
create(initConfig) {
|
17
|
+
const config = {
|
18
|
+
...this.defaults,
|
19
|
+
...initConfig
|
20
|
+
};
|
21
|
+
return new _Fexios(config);
|
22
|
+
}
|
18
23
|
async request(request) {
|
19
24
|
try {
|
20
25
|
const mergedRequest = {
|
21
26
|
...request,
|
22
|
-
headers: { ...this.headers, ...request.headers },
|
23
|
-
baseURL: request.baseURL || this.baseURL
|
27
|
+
headers: { ...this.defaults.headers, ...request.headers },
|
28
|
+
baseURL: request.baseURL || this.defaults.baseURL
|
24
29
|
};
|
25
30
|
let chain = Promise.resolve(mergedRequest);
|
26
31
|
this.interceptors.request.forEach(({ fulfilled, rejected }) => {
|
@@ -34,7 +39,7 @@ var Fexios = class {
|
|
34
39
|
});
|
35
40
|
const contentType = rowResponse.headers.get("Content-Type") || "";
|
36
41
|
let responseData;
|
37
|
-
if (contentType.includes("json")) {
|
42
|
+
if (contentType.includes("application/json")) {
|
38
43
|
responseData = await rowResponse.json();
|
39
44
|
} else {
|
40
45
|
responseData = rowResponse;
|
@@ -64,6 +69,38 @@ var Fexios = class {
|
|
64
69
|
throw error;
|
65
70
|
}
|
66
71
|
}
|
72
|
+
async get(url, request) {
|
73
|
+
const getRequest = {
|
74
|
+
...request,
|
75
|
+
url,
|
76
|
+
method: "GET"
|
77
|
+
};
|
78
|
+
return this.request(getRequest);
|
79
|
+
}
|
80
|
+
async post(url, request) {
|
81
|
+
const postRequest = {
|
82
|
+
...request,
|
83
|
+
url,
|
84
|
+
method: "POST"
|
85
|
+
};
|
86
|
+
return this.request(postRequest);
|
87
|
+
}
|
88
|
+
async delete(url, request) {
|
89
|
+
const deleteRequest = {
|
90
|
+
...request,
|
91
|
+
url,
|
92
|
+
method: "DELETE"
|
93
|
+
};
|
94
|
+
return this.request(deleteRequest);
|
95
|
+
}
|
96
|
+
async put(url, request) {
|
97
|
+
const putRequest = {
|
98
|
+
...request,
|
99
|
+
url,
|
100
|
+
method: "PUT"
|
101
|
+
};
|
102
|
+
return this.request(putRequest);
|
103
|
+
}
|
67
104
|
};
|
68
105
|
var index_default = Fexios;
|
69
106
|
export {
|