ar-design 0.3.49 → 0.3.51
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/assets/css/components/data-display/diagram/styles.css +1 -1
- package/dist/assets/css/components/feedback/drawer/content.css +1 -0
- package/dist/libs/core/service/Api.d.ts +0 -5
- package/dist/libs/core/service/Api.js +31 -56
- package/dist/libs/core/service/Config.d.ts +10 -0
- package/dist/libs/core/service/Config.js +12 -0
- package/dist/libs/core/service/index.d.ts +2 -1
- package/dist/libs/core/service/index.js +3 -1
- package/package.json +1 -1
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
declare class Api {
|
|
2
2
|
private _host?;
|
|
3
3
|
private _core?;
|
|
4
|
-
private _init?;
|
|
5
|
-
private _token?;
|
|
6
4
|
private _url;
|
|
7
5
|
constructor(values: {
|
|
8
6
|
host?: string;
|
|
9
7
|
core?: string;
|
|
10
8
|
init?: RequestInit;
|
|
11
|
-
token?: string;
|
|
12
9
|
});
|
|
13
10
|
Get(values: {
|
|
14
11
|
input?: RequestInfo | undefined;
|
|
@@ -39,8 +36,6 @@ declare class Api {
|
|
|
39
36
|
input?: RequestInfo;
|
|
40
37
|
init?: RequestInit;
|
|
41
38
|
}): Promise<Response>;
|
|
42
|
-
private HeaderProperties;
|
|
43
|
-
private Cookies;
|
|
44
39
|
/**
|
|
45
40
|
* Burada bir fetch işlemi gerçekleştirilmekte fakat farklı olarak burayı `interceptor` olarak kullanmaktayız.
|
|
46
41
|
* @param input
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
import { getApiConfig } from "./Config";
|
|
1
2
|
class Api {
|
|
2
3
|
_host;
|
|
3
4
|
_core;
|
|
4
|
-
_init;
|
|
5
|
-
_token;
|
|
6
5
|
_url;
|
|
7
6
|
constructor(values) {
|
|
8
7
|
this._host = values.host || (typeof window !== "undefined" ? window.location.origin : "");
|
|
9
8
|
this._core = values.core || "";
|
|
10
|
-
this._init = values.init;
|
|
11
|
-
this._token = values.token;
|
|
12
9
|
// Url
|
|
13
10
|
this._url = `${this._host}/${this._core ? this._core + "/" : ""}`;
|
|
14
11
|
}
|
|
@@ -19,10 +16,6 @@ class Api {
|
|
|
19
16
|
const p_response = this.CustomFetch(`${this._url}${values.input}`, {
|
|
20
17
|
method: "GET",
|
|
21
18
|
...values.init,
|
|
22
|
-
headers: {
|
|
23
|
-
...this.HeaderProperties(),
|
|
24
|
-
...values.init?.headers,
|
|
25
|
-
},
|
|
26
19
|
});
|
|
27
20
|
const clone = (await p_response).clone();
|
|
28
21
|
const response = await clone;
|
|
@@ -36,10 +29,6 @@ class Api {
|
|
|
36
29
|
method: "POST",
|
|
37
30
|
body: JSON.stringify(values.data),
|
|
38
31
|
...values.init,
|
|
39
|
-
headers: {
|
|
40
|
-
...this.HeaderProperties(),
|
|
41
|
-
...values.init?.headers,
|
|
42
|
-
},
|
|
43
32
|
});
|
|
44
33
|
const clone = (await p_response).clone();
|
|
45
34
|
const response = await clone;
|
|
@@ -53,10 +42,6 @@ class Api {
|
|
|
53
42
|
method: "POST",
|
|
54
43
|
body: values.data,
|
|
55
44
|
...values.init,
|
|
56
|
-
headers: {
|
|
57
|
-
...this.HeaderProperties(),
|
|
58
|
-
...values.init?.headers,
|
|
59
|
-
},
|
|
60
45
|
});
|
|
61
46
|
return response;
|
|
62
47
|
}
|
|
@@ -68,10 +53,6 @@ class Api {
|
|
|
68
53
|
method: "PUT",
|
|
69
54
|
body: JSON.stringify(values.data),
|
|
70
55
|
...values.init,
|
|
71
|
-
headers: {
|
|
72
|
-
...this.HeaderProperties(),
|
|
73
|
-
...values.init?.headers,
|
|
74
|
-
},
|
|
75
56
|
});
|
|
76
57
|
return response;
|
|
77
58
|
}
|
|
@@ -82,63 +63,57 @@ class Api {
|
|
|
82
63
|
const response = await this.CustomFetch(`${this._url}${values.input}`, {
|
|
83
64
|
method: "DELETE",
|
|
84
65
|
...values.init,
|
|
85
|
-
headers: {
|
|
86
|
-
...this.HeaderProperties(),
|
|
87
|
-
...values.init?.headers,
|
|
88
|
-
},
|
|
89
66
|
});
|
|
90
67
|
return response;
|
|
91
68
|
}
|
|
92
|
-
HeaderProperties = () => {
|
|
93
|
-
return {
|
|
94
|
-
Accept: "application/json",
|
|
95
|
-
"Content-Type": "application/json",
|
|
96
|
-
...(this._token && { Authorization: `Bearer ${this.Cookies(this._token)}` }),
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
Cookies = (name) => {
|
|
100
|
-
if (typeof window === "undefined")
|
|
101
|
-
return undefined;
|
|
102
|
-
const cookies = document.cookie.split("; ");
|
|
103
|
-
const cookieObject = [];
|
|
104
|
-
cookies.forEach((cookie) => {
|
|
105
|
-
const [key, value] = cookie.split("=");
|
|
106
|
-
cookieObject.push({ key: key, value: value });
|
|
107
|
-
});
|
|
108
|
-
return decodeURIComponent(cookieObject.find((x) => x.key === name)?.value ?? "");
|
|
109
|
-
};
|
|
110
69
|
/**
|
|
111
70
|
* Burada bir fetch işlemi gerçekleştirilmekte fakat farklı olarak burayı `interceptor` olarak kullanmaktayız.
|
|
112
71
|
* @param input
|
|
113
72
|
* @param init
|
|
114
73
|
* @returns
|
|
115
74
|
*/
|
|
116
|
-
async CustomFetch(input, init) {
|
|
75
|
+
async CustomFetch(input, init = {}) {
|
|
117
76
|
try {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
77
|
+
const config = getApiConfig();
|
|
78
|
+
// Request merge: init + headers + global config
|
|
79
|
+
let requestInit = {
|
|
80
|
+
...init,
|
|
81
|
+
headers: {
|
|
82
|
+
...config.headers,
|
|
83
|
+
...init.headers,
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
// Request interceptor (runtime'da eklenmiş olabilir.)
|
|
87
|
+
if (config.requestInterceptor)
|
|
88
|
+
[input, requestInit] = await config.requestInterceptor(input, requestInit);
|
|
89
|
+
// Fetch çağrısı.
|
|
90
|
+
const response = await fetch(input, requestInit);
|
|
91
|
+
// Response interceptor.
|
|
92
|
+
if (config.responseInterceptor)
|
|
93
|
+
return await config.responseInterceptor(response);
|
|
94
|
+
// Error handling
|
|
95
|
+
if (!response.ok) {
|
|
96
|
+
let message = `HTTP Error ${response.status}: ${response.statusText}`;
|
|
97
|
+
switch (response.status) {
|
|
124
98
|
case 400:
|
|
125
|
-
console.error("400");
|
|
99
|
+
console.error("400 Bad Request");
|
|
126
100
|
break;
|
|
127
101
|
case 401:
|
|
128
|
-
console.error("401");
|
|
102
|
+
console.error("401 Unauthorized");
|
|
129
103
|
break;
|
|
130
104
|
case 404:
|
|
131
|
-
console.error("404");
|
|
105
|
+
console.error("404 Not Found");
|
|
132
106
|
break;
|
|
133
107
|
default:
|
|
134
|
-
console.error(
|
|
108
|
+
console.error(message);
|
|
135
109
|
}
|
|
110
|
+
throw new Error(message);
|
|
136
111
|
}
|
|
137
|
-
|
|
138
|
-
return request;
|
|
112
|
+
return response;
|
|
139
113
|
}
|
|
140
114
|
catch (error) {
|
|
141
|
-
|
|
115
|
+
// Network hatası veya fetch exception
|
|
116
|
+
throw new Error(error instanceof Error ? error.message : "Network Error");
|
|
142
117
|
}
|
|
143
118
|
}
|
|
144
119
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type RequestInterceptor = (input: RequestInfo, init: RequestInit) => Promise<[RequestInfo, RequestInit]>;
|
|
2
|
+
type ResponseInterceptor = (res: Response) => Promise<Response>;
|
|
3
|
+
export interface ApiConfig {
|
|
4
|
+
headers?: HeadersInit;
|
|
5
|
+
requestInterceptor?: RequestInterceptor;
|
|
6
|
+
responseInterceptor?: ResponseInterceptor;
|
|
7
|
+
}
|
|
8
|
+
export declare const getApiConfig: () => ApiConfig;
|
|
9
|
+
export declare const setApiConfig: (newConfig: Partial<ApiConfig>) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Başlangıç default config
|
|
2
|
+
let config = {
|
|
3
|
+
headers: {
|
|
4
|
+
Accept: "application/json",
|
|
5
|
+
"Content-Type": "application/json",
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
// Runtime (getter / setter)
|
|
9
|
+
export const getApiConfig = () => config;
|
|
10
|
+
export const setApiConfig = (newConfig) => {
|
|
11
|
+
config = { ...config, ...newConfig };
|
|
12
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { setApiConfig } from "./Config";
|
|
1
2
|
export type Result<TResponse> = {
|
|
2
3
|
response: TResponse;
|
|
3
4
|
__response__: Promise<Response> | null;
|
|
@@ -13,7 +14,6 @@ declare class Service {
|
|
|
13
14
|
core?: string;
|
|
14
15
|
endPoint?: string;
|
|
15
16
|
init?: RequestInit;
|
|
16
|
-
token?: string;
|
|
17
17
|
});
|
|
18
18
|
Get<TResponse>(values?: {
|
|
19
19
|
input?: string;
|
|
@@ -40,4 +40,5 @@ declare class Service {
|
|
|
40
40
|
}): Promise<Result<TResponse>>;
|
|
41
41
|
private Response;
|
|
42
42
|
}
|
|
43
|
+
export { setApiConfig };
|
|
43
44
|
export default Service;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Api from "./Api";
|
|
2
|
+
import { setApiConfig } from "./Config";
|
|
2
3
|
class Service {
|
|
3
4
|
_api;
|
|
4
5
|
_endPoint;
|
|
5
6
|
constructor(values) {
|
|
6
|
-
this._api = new Api({ host: values.host, core: values.core, init: values.init
|
|
7
|
+
this._api = new Api({ host: values.host, core: values.core, init: values.init });
|
|
7
8
|
this._endPoint = values.endPoint;
|
|
8
9
|
}
|
|
9
10
|
async Get(values) {
|
|
@@ -102,4 +103,5 @@ class Service {
|
|
|
102
103
|
};
|
|
103
104
|
};
|
|
104
105
|
}
|
|
106
|
+
export { setApiConfig };
|
|
105
107
|
export default Service;
|