2025-10-26 22:30:58 +03:00
|
|
|
|
/**
|
2026-06-30 07:59:52 +03:00
|
|
|
|
* Пример использования сгенерированного tree-shaking friendly REST-клиента.
|
2025-10-26 22:30:58 +03:00
|
|
|
|
*/
|
2026-06-30 07:59:52 +03:00
|
|
|
|
// @ts-nocheck
|
2025-10-26 22:30:58 +03:00
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
import { createApiClient, HttpClient } from './output';
|
|
|
|
|
|
import { getProfile } from './output/operations/get-profile';
|
|
|
|
|
|
import { login } from './output/operations/login';
|
|
|
|
|
|
import { register } from './output/operations/register';
|
2025-10-26 22:30:58 +03:00
|
|
|
|
|
2026-06-30 23:52:06 +03:00
|
|
|
|
let accessToken: string | null = null;
|
2026-06-30 07:59:52 +03:00
|
|
|
|
|
2026-06-30 23:52:06 +03:00
|
|
|
|
const httpClient = new HttpClient({
|
2026-06-30 07:59:52 +03:00
|
|
|
|
baseUrl: 'https://api.example.com',
|
2026-06-30 23:52:06 +03:00
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
2025-10-26 22:30:58 +03:00
|
|
|
|
},
|
2026-06-30 23:52:06 +03:00
|
|
|
|
onRequest: (params) => {
|
|
|
|
|
|
if (!params.secure || !accessToken) {
|
|
|
|
|
|
return params;
|
2026-06-30 07:59:52 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 00:13:18 +03:00
|
|
|
|
const headers = new Headers(params.headers);
|
|
|
|
|
|
|
|
|
|
|
|
if (!headers.has('Authorization')) {
|
|
|
|
|
|
headers.set('Authorization', `Bearer ${accessToken}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
return {
|
2026-06-30 23:52:06 +03:00
|
|
|
|
...params,
|
2026-07-01 00:13:18 +03:00
|
|
|
|
headers,
|
2026-06-30 07:59:52 +03:00
|
|
|
|
};
|
|
|
|
|
|
},
|
2025-10-26 22:30:58 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
const api = createApiClient(httpClient, {
|
|
|
|
|
|
auth: {
|
|
|
|
|
|
register,
|
|
|
|
|
|
login,
|
|
|
|
|
|
getProfile,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
2025-10-26 22:30:58 +03:00
|
|
|
|
|
|
|
|
|
|
async function registerUser() {
|
2026-06-30 07:59:52 +03:00
|
|
|
|
const result = await api.auth.register({
|
|
|
|
|
|
email: 'user@example.com',
|
|
|
|
|
|
password: 'SecurePassword123',
|
|
|
|
|
|
firstName: 'Иван',
|
|
|
|
|
|
lastName: 'Иванов',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log('Пользователь зарегистрирован:', result);
|
|
|
|
|
|
return result;
|
2025-10-26 22:30:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loginUser() {
|
2026-06-30 07:59:52 +03:00
|
|
|
|
const result = await api.auth.login({
|
|
|
|
|
|
email: 'user@example.com',
|
|
|
|
|
|
password: 'SecurePassword123',
|
|
|
|
|
|
});
|
2025-10-26 22:30:58 +03:00
|
|
|
|
|
2026-06-30 23:52:06 +03:00
|
|
|
|
accessToken = result.access_token;
|
2025-10-26 22:30:58 +03:00
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
return result;
|
2025-10-26 22:30:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
async function getUserProfile() {
|
|
|
|
|
|
const profile = await api.auth.getProfile();
|
|
|
|
|
|
console.log('Профиль пользователя:', profile);
|
|
|
|
|
|
return profile;
|
2025-10-26 22:30:58 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-30 07:59:52 +03:00
|
|
|
|
export { getUserProfile, loginUser, registerUser };
|