37 lines
1 KiB
TypeScript
37 lines
1 KiB
TypeScript
// scripts/tenant.ts
|
||
export type TenantDto = { name: string }
|
||
export type PagedResultDto<T> = { totalCount: number; items: T[] }
|
||
|
||
if (process.env.NODE_ENV === 'development') {
|
||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||
}
|
||
|
||
export async function fetchTenantNames(apiUrl: string): Promise<string[]> {
|
||
try {
|
||
const url = `${apiUrl.replace(/\/$/, '')}/api/app/platform-tenant?skipCount=0&maxResultCount=1000`
|
||
|
||
const response = await fetch(url, {
|
||
headers: {
|
||
Accept: 'application/json',
|
||
'X-Requested-With': 'XMLHttpRequest',
|
||
},
|
||
})
|
||
|
||
if (!response.ok) {
|
||
console.error('[vite] Tenant API hatası:', response.status, response.statusText)
|
||
return []
|
||
}
|
||
|
||
const data = (await response.json()) as PagedResultDto<TenantDto>
|
||
return (data.items ?? [])
|
||
.map((t) =>
|
||
String(t?.name || '')
|
||
.trim()
|
||
.toLowerCase(),
|
||
)
|
||
.filter(Boolean)
|
||
} catch (e) {
|
||
console.error('[vite] Tenant listesi alınamadı:', e)
|
||
return []
|
||
}
|
||
}
|