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 07:59:52 +03:00
|
|
|
|
type SecurityData = {
|
|
|
|
|
|
token: string;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const httpClient = new HttpClient<SecurityData>({
|
|
|
|
|
|
baseUrl: 'https://api.example.com',
|
2025-10-26 22:30:58 +03:00
|
|
|
|
baseApiParams: {
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
2026-06-30 07:59:52 +03:00
|
|
|
|
securityWorker: (securityData) => {
|
|
|
|
|
|
if (!securityData?.token) {
|
|
|
|
|
|
return undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Authorization: `Bearer ${securityData.token}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
},
|
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 07:59:52 +03:00
|
|
|
|
httpClient.setSecurityData({ token: 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 };
|