fexios-browser 1.0.1 → 1.1.1
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 +38 -8
- package/dist/index.d.cts +22 -10
- package/dist/index.d.ts +22 -10
- package/dist/index.js +38 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -59,12 +59,10 @@ var InterceptorManager_default = InterceptorManager;
|
|
59
59
|
|
60
60
|
// src/index.ts
|
61
61
|
var Fexios = class {
|
62
|
-
|
63
|
-
headers;
|
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()
|
@@ -74,8 +72,8 @@ var Fexios = class {
|
|
74
72
|
try {
|
75
73
|
const mergedRequest = {
|
76
74
|
...request,
|
77
|
-
headers: { ...this.headers, ...request.headers },
|
78
|
-
baseURL: request.baseURL || this.baseURL
|
75
|
+
headers: { ...this.defaults.headers, ...request.headers },
|
76
|
+
baseURL: request.baseURL || this.defaults.baseURL
|
79
77
|
};
|
80
78
|
let chain = Promise.resolve(mergedRequest);
|
81
79
|
this.interceptors.request.forEach(({ fulfilled, rejected }) => {
|
@@ -89,7 +87,7 @@ var Fexios = class {
|
|
89
87
|
});
|
90
88
|
const contentType = rowResponse.headers.get("Content-Type") || "";
|
91
89
|
let responseData;
|
92
|
-
if (contentType.includes("json")) {
|
90
|
+
if (contentType.includes("application/json")) {
|
93
91
|
responseData = await rowResponse.json();
|
94
92
|
} else {
|
95
93
|
responseData = rowResponse;
|
@@ -119,5 +117,37 @@ var Fexios = class {
|
|
119
117
|
throw error;
|
120
118
|
}
|
121
119
|
}
|
120
|
+
async get(url, request) {
|
121
|
+
const getRequest = {
|
122
|
+
...request,
|
123
|
+
url,
|
124
|
+
method: "GET"
|
125
|
+
};
|
126
|
+
return this.request(getRequest);
|
127
|
+
}
|
128
|
+
async post(url, request) {
|
129
|
+
const postRequest = {
|
130
|
+
...request,
|
131
|
+
url,
|
132
|
+
method: "POST"
|
133
|
+
};
|
134
|
+
return this.request(postRequest);
|
135
|
+
}
|
136
|
+
async delete(url, request) {
|
137
|
+
const deleteRequest = {
|
138
|
+
...request,
|
139
|
+
url,
|
140
|
+
method: "DELETE"
|
141
|
+
};
|
142
|
+
return this.request(deleteRequest);
|
143
|
+
}
|
144
|
+
async put(url, request) {
|
145
|
+
const putRequest = {
|
146
|
+
...request,
|
147
|
+
url,
|
148
|
+
method: "PUT"
|
149
|
+
};
|
150
|
+
return this.request(putRequest);
|
151
|
+
}
|
122
152
|
};
|
123
153
|
var index_default = Fexios;
|
package/dist/index.d.cts
CHANGED
@@ -1,23 +1,35 @@
|
|
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);
|
20
28
|
request(request: FRequest): Promise<FResponse>;
|
29
|
+
get(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
30
|
+
post(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
31
|
+
delete(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
32
|
+
put(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
21
33
|
}
|
22
34
|
|
23
|
-
export { type FRequest, type FResponse, Fexios as default };
|
35
|
+
export { type FRequest, type FResponse, type InitConfig, Fexios as default };
|
package/dist/index.d.ts
CHANGED
@@ -1,23 +1,35 @@
|
|
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);
|
20
28
|
request(request: FRequest): Promise<FResponse>;
|
29
|
+
get(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
30
|
+
post(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
31
|
+
delete(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
32
|
+
put(url: string | URL, request: Omit<FRequest, "url" | "method">): Promise<FResponse>;
|
21
33
|
}
|
22
34
|
|
23
|
-
export { type FRequest, type FResponse, Fexios as default };
|
35
|
+
export { type FRequest, type FResponse, type InitConfig, Fexios as default };
|
package/dist/index.js
CHANGED
@@ -4,12 +4,10 @@ import {
|
|
4
4
|
|
5
5
|
// src/index.ts
|
6
6
|
var Fexios = class {
|
7
|
-
|
8
|
-
headers;
|
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()
|
@@ -19,8 +17,8 @@ var Fexios = class {
|
|
19
17
|
try {
|
20
18
|
const mergedRequest = {
|
21
19
|
...request,
|
22
|
-
headers: { ...this.headers, ...request.headers },
|
23
|
-
baseURL: request.baseURL || this.baseURL
|
20
|
+
headers: { ...this.defaults.headers, ...request.headers },
|
21
|
+
baseURL: request.baseURL || this.defaults.baseURL
|
24
22
|
};
|
25
23
|
let chain = Promise.resolve(mergedRequest);
|
26
24
|
this.interceptors.request.forEach(({ fulfilled, rejected }) => {
|
@@ -34,7 +32,7 @@ var Fexios = class {
|
|
34
32
|
});
|
35
33
|
const contentType = rowResponse.headers.get("Content-Type") || "";
|
36
34
|
let responseData;
|
37
|
-
if (contentType.includes("json")) {
|
35
|
+
if (contentType.includes("application/json")) {
|
38
36
|
responseData = await rowResponse.json();
|
39
37
|
} else {
|
40
38
|
responseData = rowResponse;
|
@@ -64,6 +62,38 @@ var Fexios = class {
|
|
64
62
|
throw error;
|
65
63
|
}
|
66
64
|
}
|
65
|
+
async get(url, request) {
|
66
|
+
const getRequest = {
|
67
|
+
...request,
|
68
|
+
url,
|
69
|
+
method: "GET"
|
70
|
+
};
|
71
|
+
return this.request(getRequest);
|
72
|
+
}
|
73
|
+
async post(url, request) {
|
74
|
+
const postRequest = {
|
75
|
+
...request,
|
76
|
+
url,
|
77
|
+
method: "POST"
|
78
|
+
};
|
79
|
+
return this.request(postRequest);
|
80
|
+
}
|
81
|
+
async delete(url, request) {
|
82
|
+
const deleteRequest = {
|
83
|
+
...request,
|
84
|
+
url,
|
85
|
+
method: "DELETE"
|
86
|
+
};
|
87
|
+
return this.request(deleteRequest);
|
88
|
+
}
|
89
|
+
async put(url, request) {
|
90
|
+
const putRequest = {
|
91
|
+
...request,
|
92
|
+
url,
|
93
|
+
method: "PUT"
|
94
|
+
};
|
95
|
+
return this.request(putRequest);
|
96
|
+
}
|
67
97
|
};
|
68
98
|
var index_default = Fexios;
|
69
99
|
export {
|