eco-vue-js 0.10.75 → 0.10.77

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.
Files changed (53) hide show
  1. package/dist/components/Auth/WRouteAuth.vue.d.ts +7 -0
  2. package/dist/components/Auth/WRouteAuth.vue.d.ts.map +1 -0
  3. package/dist/components/Auth/WRouteAuth.vue.js +38 -0
  4. package/dist/components/Auth/WRouteAuth.vue2.js +5 -0
  5. package/dist/components/Auth/WRouteAuthNo.vue.d.ts +7 -0
  6. package/dist/components/Auth/WRouteAuthNo.vue.d.ts.map +1 -0
  7. package/dist/components/Auth/WRouteAuthNo.vue.js +51 -0
  8. package/dist/components/Auth/WRouteAuthNo.vue2.js +5 -0
  9. package/dist/components/Auth/utils/utils.d.ts +7 -0
  10. package/dist/components/Auth/utils/utils.d.ts.map +1 -0
  11. package/dist/components/Auth/utils/utils.js +61 -0
  12. package/dist/components/Button/types.d.ts +2 -5
  13. package/dist/components/Button/types.d.ts.map +1 -1
  14. package/dist/components/DragContainer/use/useDragContainer.js +2 -2
  15. package/dist/components/Input/WInputAsync.vue.d.ts.map +1 -1
  16. package/dist/components/Input/WInputAsync.vue.js +1 -1
  17. package/dist/components/Input/WInputDate.vue.d.ts +1 -1
  18. package/dist/components/Modal/WModalStepper.vue.d.ts +4 -4
  19. package/dist/components/Select/WSelect.vue.d.ts +3 -15
  20. package/dist/components/Select/WSelect.vue.d.ts.map +1 -1
  21. package/dist/components/Select/WSelect.vue.js +10 -4
  22. package/dist/components/Select/WSelectAsync.vue.d.ts +3 -17
  23. package/dist/components/Select/WSelectAsync.vue.d.ts.map +1 -1
  24. package/dist/components/Select/WSelectAsync.vue.js +6 -4
  25. package/dist/components/Select/WSelectAsyncList.vue.d.ts +3 -12
  26. package/dist/components/Select/WSelectAsyncList.vue.d.ts.map +1 -1
  27. package/dist/components/Select/WSelectAsyncList.vue.js +4 -2
  28. package/dist/components/Select/WSelectAsyncSingle.vue.d.ts +11 -11
  29. package/dist/components/Select/WSelectAsyncSingle.vue.d.ts.map +1 -1
  30. package/dist/components/Select/WSelectAsyncSingle.vue.js +3 -8
  31. package/dist/components/Select/WSelectSingle.vue.d.ts +12 -11
  32. package/dist/components/Select/WSelectSingle.vue.d.ts.map +1 -1
  33. package/dist/components/Select/WSelectSingle.vue.js +3 -8
  34. package/dist/components/Select/WSelectStringified.vue.d.ts +3 -13
  35. package/dist/components/Select/WSelectStringified.vue.d.ts.map +1 -1
  36. package/dist/components/Select/WSelectStringified.vue.js +3 -8
  37. package/dist/components/Select/components/SelectAsyncList.vue.d.ts +3 -12
  38. package/dist/components/Select/components/SelectAsyncList.vue.d.ts.map +1 -1
  39. package/dist/components/Select/components/SelectAsyncList.vue.js +8 -4
  40. package/dist/components/Select/types.d.ts +5 -4
  41. package/dist/components/Select/types.d.ts.map +1 -1
  42. package/dist/components/Tabs/WTabs.vue.d.ts +4 -4
  43. package/dist/components/Tabs/components/TabItem.vue.d.ts +2 -2
  44. package/dist/imports/componentsPlugin.d.ts +3 -1
  45. package/dist/imports/componentsPlugin.d.ts.map +1 -1
  46. package/dist/main.d.ts +1 -0
  47. package/dist/main.d.ts.map +1 -1
  48. package/dist/main.js +3 -0
  49. package/dist/types/global.d.ts +9 -1
  50. package/dist/utils/ApiClient.d.ts +89 -0
  51. package/dist/utils/ApiClient.d.ts.map +1 -0
  52. package/dist/utils/ApiClient.js +225 -0
  53. package/package.json +10 -10
@@ -0,0 +1,225 @@
1
+ import { ref } from 'vue';
2
+ import _sfc_main from '../components/Auth/WRouteAuth.vue.js';
3
+ import _sfc_main$1 from '../components/Auth/WRouteAuthNo.vue.js';
4
+ import { removeExpirationDate, getLastRefreshPromise, setRefreshTimestamp, removeRefreshTimestamp, checkExpirationDate, setExpirationDate } from '../components/Auth/utils/utils.js';
5
+ import { encodeQueryParams, ApiError, ApiErrorCancel } from './api.js';
6
+
7
+ const getURLParams = (params) => {
8
+ return new URLSearchParams(encodeQueryParams(params)).toString();
9
+ };
10
+ const HEADERS_JSON = {
11
+ "Content-Type": "application/json",
12
+ "Access-Control-Allow-Origin": "*"
13
+ };
14
+ const HEADERS_FORMDATA = {
15
+ "Access-Control-Allow-Origin": "*"
16
+ };
17
+ class ApiClientInstance {
18
+ constructor(config) {
19
+ this.config = config;
20
+ }
21
+ refreshPromise = null;
22
+ isAuthFailed = ref(false);
23
+ get routeNameAuth() {
24
+ return this.config.routeNameAuth;
25
+ }
26
+ get routeNameAuthNo() {
27
+ return this.config.routeNameAuthNo;
28
+ }
29
+ logout() {
30
+ removeExpirationDate();
31
+ }
32
+ async retry(request) {
33
+ const newRequest = request.clone();
34
+ const response = await fetch(request);
35
+ return {
36
+ data: await response.json(),
37
+ status: response.status,
38
+ request: newRequest
39
+ };
40
+ }
41
+ async refresh() {
42
+ if (!this.refreshPromise) {
43
+ const refreshTimeoutPromise = getLastRefreshPromise();
44
+ if (refreshTimeoutPromise) {
45
+ this.refreshPromise = refreshTimeoutPromise.then(() => {
46
+ this.refreshPromise = null;
47
+ this.isAuthFailed.value = false;
48
+ }).catch(async () => {
49
+ this.refreshPromise = null;
50
+ const check = this.checkAuth();
51
+ if (!check) {
52
+ if (this.refreshPromise) return this.refreshPromise;
53
+ if (check === null) {
54
+ this.isAuthFailed.value = true;
55
+ return Promise.reject();
56
+ }
57
+ return this.refresh();
58
+ }
59
+ });
60
+ } else {
61
+ setRefreshTimestamp();
62
+ this.refreshPromise = this.fetch("GET", this.config.refreshUrl, { updateToken: true }).then(() => {
63
+ this.refreshPromise = null;
64
+ }).catch((error) => {
65
+ this.refreshPromise = null;
66
+ this.isAuthFailed.value = true;
67
+ return Promise.reject(error);
68
+ }).finally(removeRefreshTimestamp);
69
+ }
70
+ }
71
+ return this.refreshPromise;
72
+ }
73
+ checkAuth() {
74
+ let result;
75
+ if (this.config.tokenGetter) result = !!this.config.tokenGetter?.();
76
+ else result = checkExpirationDate();
77
+ if (result) this.isAuthFailed.value = false;
78
+ return result;
79
+ }
80
+ fetch(method, url, config, baseUrl) {
81
+ return new Promise(async (resolve, reject) => {
82
+ const headers = new Headers(config?.data instanceof FormData ? HEADERS_FORMDATA : HEADERS_JSON);
83
+ if (!config?.noAuth && !config?.updateToken) {
84
+ if (this.refreshPromise) await this.refreshPromise;
85
+ const check = this.checkAuth();
86
+ if (!check) {
87
+ if (check === null) {
88
+ this.isAuthFailed.value = true;
89
+ return Promise.reject();
90
+ }
91
+ if (this.config.refreshUrl) await this.refresh();
92
+ } else if (this.config.tokenGetter) {
93
+ const token = this.config.tokenGetter();
94
+ if (token) headers.append("Authorization", "Bearer " + token);
95
+ else return Promise.reject();
96
+ }
97
+ }
98
+ const params = config?.params ? "?" + getURLParams(config.params) : "";
99
+ const request = new Request(
100
+ (baseUrl ?? this.config.baseUrl) + url + params,
101
+ {
102
+ method,
103
+ mode: "cors",
104
+ cache: "no-cache",
105
+ credentials: this.config.credentials ?? "same-origin",
106
+ headers,
107
+ redirect: "follow",
108
+ referrerPolicy: "no-referrer",
109
+ body: config?.data ? config.data instanceof FormData ? config.data : JSON.stringify(config.data) : void 0,
110
+ signal: config?.signal
111
+ }
112
+ );
113
+ fetch(request).then((response) => {
114
+ response.json().catch(() => void 0).then((data) => {
115
+ if (response.ok) {
116
+ resolve({
117
+ data,
118
+ status: response.status,
119
+ config,
120
+ request
121
+ });
122
+ } else {
123
+ if (response.status === 401) {
124
+ if (this.config.refreshUrl) return this.refresh().then(() => this.retry(request));
125
+ this.isAuthFailed.value = true;
126
+ }
127
+ this.config.onFailure?.(response);
128
+ reject(new ApiError({
129
+ data,
130
+ status: response.status,
131
+ config,
132
+ request
133
+ }));
134
+ }
135
+ });
136
+ }).catch((error) => {
137
+ if (error instanceof DOMException && error.name === "AbortError") {
138
+ reject(new ApiErrorCancel({
139
+ data: void 0,
140
+ config,
141
+ request
142
+ }));
143
+ }
144
+ reject(error);
145
+ }).finally(() => {
146
+ if (config?.updateToken) setExpirationDate();
147
+ });
148
+ });
149
+ }
150
+ get baseUrl() {
151
+ return this.config.baseUrl ?? "";
152
+ }
153
+ get(url, config) {
154
+ return this.fetch("GET", url, config);
155
+ }
156
+ post(url, data, config) {
157
+ return this.fetch("POST", url, { data, ...config });
158
+ }
159
+ patch(url, data, config) {
160
+ return this.fetch("PATCH", url, { data, ...config });
161
+ }
162
+ delete(url, config) {
163
+ return this.fetch("DELETE", url, config);
164
+ }
165
+ getRouteAuth() {
166
+ return {
167
+ path: "",
168
+ props: { apiClientInstance: this },
169
+ component: _sfc_main,
170
+ beforeEnter: async (to) => {
171
+ if (to.meta.noAuth) return;
172
+ if (this.refreshPromise) await this.refreshPromise;
173
+ if (!this.checkAuth()) {
174
+ if (this.config.refreshUrl) return this.refresh().catch(() => ({
175
+ name: this.routeNameAuthNo,
176
+ query: to.fullPath !== "/" ? { hash: to.fullPath } : void 0
177
+ }));
178
+ return { name: this.routeNameAuthNo, query: to.fullPath !== "/" ? { hash: to.fullPath } : void 0 };
179
+ }
180
+ },
181
+ meta: {
182
+ noAuth: false
183
+ }
184
+ };
185
+ }
186
+ getRouteAuthNo() {
187
+ return {
188
+ path: "",
189
+ props: { apiClientInstance: this },
190
+ component: _sfc_main$1,
191
+ beforeEnter: (to, from) => {
192
+ if (!this.checkAuth()) {
193
+ if (!to.query.hash && !from.meta.noAuth && from.fullPath !== "/") {
194
+ return { ...to, query: { hash: from.fullPath } };
195
+ }
196
+ return;
197
+ }
198
+ if (typeof to.query.hash === "string") return to.query.hash;
199
+ else return { name: this.routeNameAuth };
200
+ },
201
+ meta: {
202
+ noAuth: true
203
+ }
204
+ };
205
+ }
206
+ addInstance(baseUrl) {
207
+ return {
208
+ baseUrl,
209
+ get: (url, config) => {
210
+ return this.fetch("GET", url, config, baseUrl);
211
+ },
212
+ post: (url, data, config) => {
213
+ return this.fetch("POST", url, { data, ...config }, baseUrl);
214
+ },
215
+ patch: (url, data, config) => {
216
+ return this.fetch("PATCH", url, { data, ...config }, baseUrl);
217
+ },
218
+ delete: (url, config) => {
219
+ return this.fetch("DELETE", url, config, baseUrl);
220
+ }
221
+ };
222
+ }
223
+ }
224
+
225
+ export { ApiClientInstance, getURLParams };
package/package.json CHANGED
@@ -4,16 +4,7 @@
4
4
  "type": "git",
5
5
  "url": "https://github.com/rsmple/eco-vue-js.git"
6
6
  },
7
- "version": "0.10.75",
8
- "scripts": {
9
- "build": "run-p type-check \"build-only {@}\" --",
10
- "dev": "vite build --mode development --watch",
11
- "build-only": "vite build",
12
- "type-check": "vue-tsc --build --force",
13
- "lint": "eslint .",
14
- "lint:fix": "eslint . --fix",
15
- "lint:inspect": "npx eslint --inspect-config"
16
- },
7
+ "version": "0.10.77",
17
8
  "dependencies": {
18
9
  "@stylistic/eslint-plugin": "5.1.0",
19
10
  "@tanstack/eslint-plugin-query": "5.81.2",
@@ -110,6 +101,9 @@
110
101
  "./dist/utils/api": {
111
102
  "import": "./dist/utils/api.js"
112
103
  },
104
+ "./dist/utils/ApiClient": {
105
+ "import": "./dist/utils/ApiClient.js"
106
+ },
113
107
  "./dist/utils/validate": {
114
108
  "import": "./dist/utils/validate.js"
115
109
  },
@@ -119,6 +113,12 @@
119
113
  "./dist/components/ActionsBar/WActionsBarFilter.vue": {
120
114
  "import": "./dist/components/ActionsBar/WActionsBarFilter.vue.js"
121
115
  },
116
+ "./dist/components/Auth/WRouteAuth.vue": {
117
+ "import": "./dist/components/Auth/WRouteAuth.vue.js"
118
+ },
119
+ "./dist/components/Auth/WRouteAuthNo.vue": {
120
+ "import": "./dist/components/Auth/WRouteAuthNo.vue.js"
121
+ },
122
122
  "./dist/components/BottomSheet/WBottomSheet.vue": {
123
123
  "import": "./dist/components/BottomSheet/WBottomSheet.vue.js"
124
124
  },