@alfabit/keycloak 0.0.17 → 0.0.19
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/package.json +1 -1
- package/src/api/wallet/client.ts +38 -38
- package/src/api/wallet/endpoints/index.ts +31 -1
- package/src/api/wallet/endpoints/public/public/index.ts +1 -1
- package/src/api/wallet/endpoints/public/public/post.web-login.ts +11 -11
- package/src/api/wallet/swagger-types.ts +12450 -12450
- package/src/api/wallet/types-ext.ts +55 -55
- package/src/composables/use-keycloak.ts +11 -0
package/package.json
CHANGED
package/src/api/wallet/client.ts
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { WALLET_API_HOST } from '@alfabit/constants';
|
|
2
|
-
import { Api } from './swagger-types';
|
|
3
|
-
import { getToken } from '../../composables';
|
|
1
|
+
// import { WALLET_API_HOST } from '@alfabit/constants';
|
|
2
|
+
// import { Api } from './swagger-types';
|
|
3
|
+
// import { getToken } from '../../composables';
|
|
4
4
|
|
|
5
|
-
const client = new Api({
|
|
6
|
-
|
|
7
|
-
});
|
|
5
|
+
// const client = new Api({
|
|
6
|
+
// baseUrl: WALLET_API_HOST,
|
|
7
|
+
// });
|
|
8
8
|
|
|
9
|
-
export const getBearerToken = () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
9
|
+
// export const getBearerToken = () => {
|
|
10
|
+
// const token = getToken();
|
|
11
|
+
// return token ? `Bearer ${token}` : '';
|
|
12
|
+
// };
|
|
13
13
|
|
|
14
|
-
const api = client.public;
|
|
14
|
+
// const api = client.public;
|
|
15
15
|
|
|
16
|
-
type ApiMethod = (...args: any[]) => Promise<any>;
|
|
16
|
+
// type ApiMethod = (...args: any[]) => Promise<any>;
|
|
17
17
|
|
|
18
|
-
// Подмешаем токен в заголовок каждого запроса
|
|
19
|
-
Object.keys(client.public).forEach((methodName) => {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
// // Подмешаем токен в заголовок каждого запроса
|
|
19
|
+
// Object.keys(client.public).forEach((methodName) => {
|
|
20
|
+
// const nativeMethod = client.public[methodName as keyof typeof client.public] as ApiMethod;
|
|
21
|
+
// const argsNumber = nativeMethod.length;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
// api[methodName as keyof typeof api] = function (...args: any[]) {
|
|
24
|
+
// let params: Record<string, unknown> = {};
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
// if (args.length > argsNumber) {
|
|
27
|
+
// params = args.pop();
|
|
28
|
+
// }
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
// if (typeof params !== 'object' || params === null) {
|
|
31
|
+
// params = {};
|
|
32
|
+
// }
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
// if (!('headers' in params)) {
|
|
35
|
+
// params.headers = {};
|
|
36
|
+
// }
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
// const headers = {
|
|
39
|
+
// ...((params.headers as Record<string, string>) ?? {}),
|
|
40
|
+
// Authorization: getBearerToken(),
|
|
41
|
+
// };
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
43
|
+
// return nativeMethod(...args, {
|
|
44
|
+
// ...params,
|
|
45
|
+
// headers,
|
|
46
|
+
// });
|
|
47
|
+
// } as ApiMethod;
|
|
48
|
+
// });
|
|
49
49
|
|
|
50
|
-
export default client;
|
|
50
|
+
// export default client;
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
export * from './public';
|
|
1
|
+
// export * from './public';
|
|
2
|
+
|
|
3
|
+
import { REF_KEY, WALLET_API_HOST } from '@alfabit/constants';
|
|
4
|
+
import { getToken } from '../../../composables';
|
|
5
|
+
|
|
6
|
+
export const postWebLogin = async () => {
|
|
7
|
+
if (typeof window === 'undefined') return;
|
|
8
|
+
|
|
9
|
+
const referral_token = localStorage.getItem(REF_KEY) ?? null;
|
|
10
|
+
const headers: Record<string, string> = {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
};
|
|
13
|
+
const token = getToken();
|
|
14
|
+
if(token) headers['Authorization'] = `Bearer ${token}`;
|
|
15
|
+
|
|
16
|
+
const params: RequestInit = {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers,
|
|
19
|
+
body: JSON.stringify({ referral_token })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const res = await fetch(`${WALLET_API_HOST}/public/web/login/`, params);
|
|
23
|
+
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
throw new Error(`HTTP error: ${res.status}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
if (referral_token) localStorage.removeItem(REF_KEY);
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './post.web-login';
|
|
1
|
+
// export * from './post.web-login';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { REF_KEY } from '@alfabit/constants';
|
|
2
|
-
import api from '../../../client';
|
|
1
|
+
// import { REF_KEY } from '@alfabit/constants';
|
|
2
|
+
// import api from '../../../client';
|
|
3
3
|
|
|
4
|
-
export const postWebLogin = async () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
4
|
+
// export const postWebLogin = async () => {
|
|
5
|
+
// if (typeof window === 'undefined') return;
|
|
6
|
+
// const referral_token = localStorage.getItem(REF_KEY) ?? null;
|
|
7
|
+
// const { data: data_1 } = await api.public.loginPublicWebLoginPost({
|
|
8
|
+
// referral_token,
|
|
9
|
+
// });
|
|
10
|
+
// if (referral_token) localStorage.removeItem(REF_KEY);
|
|
11
|
+
// return data_1;
|
|
12
|
+
// };
|