Refresh HiveGrid Cloud reference snapshot

This commit is contained in:
david committed 2026-08-03 15:31:14 +02:00
1 parent 5e99e14772
commit 7f88026f79
5955 files changed
+1177325 -188362

No files matched your search

@@ -1,14 +1,15 @@
import { adminGetAllLegacyTenantSummaries } from "@hivegrid/db/accounts.server";
import {
adminDeleteLegacyApiKeyLogsByIds,
countLegacyApiKeyLogs,
deleteTenantLegacyApiKeyLogsByIds,
findLegacyApiKeyLogTenantScopesByIds,
getLegacyApiKeyLogAdminDetails,
groupLegacyApiKeyLogs,
tenantLegacyApiKeyLogScope,
type LegacyApiKeyLogOrderByInput,
type LegacyApiKeyLogWhereInput,
} from "@hivegrid/db/api-keys.server";
import { getRlsExecutionContext, runWithRlsContext } from "@hivegrid/db/rls-context.server";
import { Prisma } from "@hivegrid/db/prisma-browser";
import { Params } from "react-router";
import { FilterablePropertyDto } from "~/application/dtos/data/FilterablePropertyDto";
@@ -63,7 +64,7 @@ async function getDetails({ request, params }: { request: Request; params: Param
const totalItems = await countLegacyApiKeyLogs(whereFilters);
return {
items: items as ApiKeyLogDto[],
items: items.map(toApiKeyLogDto),
filterableProperties,
pagination: {
page: pagination.page,
@@ -170,12 +171,55 @@ async function getFilters({ request, params }: { request: Request; params: Param
return { filterableProperties, whereFilters, allTenants };
}
async function adminDeleteMany(ids: string[]) {
return await adminDeleteLegacyApiKeyLogsByIds(ids);
async function adminDeleteMany(ids: string[]): Promise<{ deletedCount: number; rejectedTenantlessIds: string[] }> {
const context = getRlsExecutionContext();
if (!context?.userId || context.tenantId) {
throw new Error("Admin API log deletion requires an unscoped authenticated operator context");
}
const normalizedIds = [...new Set(ids.map((id) => id.trim()).filter(Boolean))];
if (normalizedIds.length === 0) return { deletedCount: 0, rejectedTenantlessIds: [] };
if (normalizedIds.length > 500) {
throw new Error("At most 500 API log entries can be deleted at once");
}
const scopes = await findLegacyApiKeyLogTenantScopesByIds(normalizedIds);
const rejectedTenantlessIds = scopes.filter((scope) => !scope.tenantId).map((scope) => scope.id);
if (rejectedTenantlessIds.length > 0) {
return { deletedCount: 0, rejectedTenantlessIds };
}
const byTenant = new Map<string, string[]>();
for (const scope of scopes) {
if (!scope.tenantId) continue;
const tenantIds = byTenant.get(scope.tenantId) ?? [];
tenantIds.push(scope.id);
byTenant.set(scope.tenantId, tenantIds);
}
await Promise.all(
[...byTenant].map(([tenantId, tenantIds]) => runWithRlsContext({ tenantId }, () => deleteTenantLegacyApiKeyLogsByIds({ ids: tenantIds, tenantId })))
);
return { deletedCount: scopes.length, rejectedTenantlessIds: [] };
}
async function deleteManyForTenant(ids: string[], tenantId: string | null) {
return await deleteTenantLegacyApiKeyLogsByIds({ ids, tenantId });
return tenantId
? runWithRlsContext({ tenantId }, () => deleteTenantLegacyApiKeyLogsByIds({ ids, tenantId }))
: deleteTenantLegacyApiKeyLogsByIds({ ids, tenantId });
}
function toApiKeyLogDto(item: Awaited<ReturnType<typeof getLegacyApiKeyLogAdminDetails>>[number]): ApiKeyLogDto {
if (item.apiKey || !item.apiKeyId || !item.alias || !item.tenantId) return item as ApiKeyLogDto;
return {
...item,
apiKey: {
alias: item.alias,
tenant: {
id: item.tenantId,
name: item.tenant?.name ?? item.tenantName ?? item.tenantId,
},
},
} as ApiKeyLogDto;
}
export default {