Compare commits
4 Commits
feature/cl
...
hotfix/dom
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d914f5973 | |||
| fbeb089b9e | |||
| 269c9e47c9 | |||
| 78d3f104de |
@@ -50,7 +50,7 @@ export default async function DashboardPage() {
|
|||||||
supabase
|
supabase
|
||||||
.from("plesk_domains")
|
.from("plesk_domains")
|
||||||
.select(
|
.select(
|
||||||
"id, plesk_instance_id, subscription_id, status, domain_name, hosting_type, source_created_at, aliases_count, updated_at, subscription:plesk_subscriptions(status)",
|
"id, plesk_instance_id, subscription_id, status, domain_name, hosting_type, source_created_at, aliases_count, updated_at",
|
||||||
)
|
)
|
||||||
.eq("agency_id", context.agencyId)
|
.eq("agency_id", context.agencyId)
|
||||||
.order("updated_at", { ascending: false })
|
.order("updated_at", { ascending: false })
|
||||||
@@ -107,15 +107,36 @@ export default async function DashboardPage() {
|
|||||||
source_created_at: string | null;
|
source_created_at: string | null;
|
||||||
aliases_count: number | null;
|
aliases_count: number | null;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
subscription: {
|
|
||||||
status: string | null;
|
|
||||||
} | null;
|
|
||||||
}> | null;
|
}> | null;
|
||||||
},
|
},
|
||||||
{ data: BillingSummary | null },
|
{ data: BillingSummary | null },
|
||||||
{ data: ActionLogSummary[] | null },
|
{ data: ActionLogSummary[] | null },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const domainSubscriptionIds = Array.from(
|
||||||
|
new Set(
|
||||||
|
(domains ?? [])
|
||||||
|
.map((domain) => domain.subscription_id)
|
||||||
|
.filter((id): id is string => Boolean(id)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
const { data: domainSubscriptions } =
|
||||||
|
domainSubscriptionIds.length > 0
|
||||||
|
? await supabase
|
||||||
|
.from("plesk_subscriptions")
|
||||||
|
.select("id, status")
|
||||||
|
.eq("agency_id", context.agencyId)
|
||||||
|
.in("id", domainSubscriptionIds)
|
||||||
|
: { data: [] };
|
||||||
|
|
||||||
|
const subscriptionStatusById = new Map<string, string | null>(
|
||||||
|
(domainSubscriptions ?? []).map((subscription: any) => [
|
||||||
|
String(subscription.id),
|
||||||
|
subscription?.status ? String(subscription.status) : null,
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
|
||||||
const autoSyncByInstance = new Map<
|
const autoSyncByInstance = new Map<
|
||||||
string,
|
string,
|
||||||
{ status: string; created_at: string; error_message: string | null }
|
{ status: string; created_at: string; error_message: string | null }
|
||||||
@@ -171,9 +192,9 @@ export default async function DashboardPage() {
|
|||||||
instances={instances ?? []}
|
instances={instances ?? []}
|
||||||
subscriptions={subscriptions ?? []}
|
subscriptions={subscriptions ?? []}
|
||||||
domains={(domains ?? []).map((domain) => {
|
domains={(domains ?? []).map((domain) => {
|
||||||
const joinedStatus = Array.isArray(domain.subscription)
|
const joinedStatus = domain.subscription_id
|
||||||
? domain.subscription[0]?.status
|
? subscriptionStatusById.get(domain.subscription_id)
|
||||||
: domain.subscription?.status;
|
: null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...domain,
|
...domain,
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ type InstanceRow = Pick<
|
|||||||
| "last_connected_at"
|
| "last_connected_at"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
type LocalSubscriptionLookupRow = {
|
||||||
|
id: string;
|
||||||
|
plesk_subscription_id: string;
|
||||||
|
name: string | null;
|
||||||
|
status: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
const MIN_INTERVAL_MS = 3 * 60 * 1000;
|
const MIN_INTERVAL_MS = 3 * 60 * 1000;
|
||||||
|
|
||||||
export async function syncPleskInstance(
|
export async function syncPleskInstance(
|
||||||
@@ -156,7 +163,7 @@ export async function syncPleskInstance(
|
|||||||
const { data: localSubscriptions, error: localSubscriptionsError } =
|
const { data: localSubscriptions, error: localSubscriptionsError } =
|
||||||
await supabase
|
await supabase
|
||||||
.from("plesk_subscriptions")
|
.from("plesk_subscriptions")
|
||||||
.select("id, plesk_subscription_id, status")
|
.select("id, plesk_subscription_id, name, status")
|
||||||
.eq("agency_id", instance.agency_id)
|
.eq("agency_id", instance.agency_id)
|
||||||
.eq("plesk_instance_id", instance.id);
|
.eq("plesk_instance_id", instance.id);
|
||||||
|
|
||||||
@@ -164,19 +171,49 @@ export async function syncPleskInstance(
|
|||||||
throw new Error(localSubscriptionsError.message);
|
throw new Error(localSubscriptionsError.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const subscriptionsIndexed = ((localSubscriptions ?? []) as Array<any>)
|
||||||
|
.filter((row): row is LocalSubscriptionLookupRow =>
|
||||||
|
Boolean(row?.plesk_subscription_id && row?.id),
|
||||||
|
)
|
||||||
|
.map((row) => ({
|
||||||
|
id: String(row.id),
|
||||||
|
pleskSubscriptionId: String(row.plesk_subscription_id),
|
||||||
|
status: row?.status ? String(row.status) : null,
|
||||||
|
name: row?.name ? String(row.name) : null,
|
||||||
|
}));
|
||||||
|
|
||||||
const subscriptionByExternalId = new Map<
|
const subscriptionByExternalId = new Map<
|
||||||
string,
|
string,
|
||||||
{ id: string; status: string | null }
|
|
||||||
>(
|
|
||||||
(localSubscriptions ?? [])
|
|
||||||
.filter((row: any) => row?.plesk_subscription_id && row?.id)
|
|
||||||
.map((row: any) => [
|
|
||||||
String(row.plesk_subscription_id),
|
|
||||||
{
|
{
|
||||||
id: String(row.id),
|
id: string;
|
||||||
status: row?.status ? String(row.status) : null,
|
pleskSubscriptionId: string;
|
||||||
},
|
status: string | null;
|
||||||
]),
|
name: string | null;
|
||||||
|
}
|
||||||
|
>(subscriptionsIndexed.map((row) => [row.pleskSubscriptionId, row]));
|
||||||
|
|
||||||
|
const subscriptionByLocalId = new Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
pleskSubscriptionId: string;
|
||||||
|
status: string | null;
|
||||||
|
name: string | null;
|
||||||
|
}
|
||||||
|
>(subscriptionsIndexed.map((row) => [row.id, row]));
|
||||||
|
|
||||||
|
const subscriptionByName = new Map<
|
||||||
|
string,
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
pleskSubscriptionId: string;
|
||||||
|
status: string | null;
|
||||||
|
name: string | null;
|
||||||
|
}
|
||||||
|
>(
|
||||||
|
subscriptionsIndexed
|
||||||
|
.filter((row) => row.name)
|
||||||
|
.map((row) => [String(row.name).trim().toLowerCase(), row]),
|
||||||
);
|
);
|
||||||
|
|
||||||
const domainsForUpsert = domainsRaw
|
const domainsForUpsert = domainsRaw
|
||||||
@@ -185,12 +222,37 @@ export async function syncPleskInstance(
|
|||||||
const domainName = item?.name ?? item?.domain_name ?? item?.domain;
|
const domainName = item?.name ?? item?.domain_name ?? item?.domain;
|
||||||
const subExternalId =
|
const subExternalId =
|
||||||
item?.subscription?.id ?? item?.subscription_id ?? item?.webspace_id;
|
item?.subscription?.id ?? item?.subscription_id ?? item?.webspace_id;
|
||||||
const externalSubscriptionId = subExternalId
|
const rawExternalSubscriptionId = subExternalId
|
||||||
? String(subExternalId)
|
? String(subExternalId)
|
||||||
: null;
|
: null;
|
||||||
const localSubscription = externalSubscriptionId
|
const subscriptionNameHint =
|
||||||
? subscriptionByExternalId.get(externalSubscriptionId)
|
item?.subscription?.name ??
|
||||||
|
item?.subscription_name ??
|
||||||
|
item?.webspace_name ??
|
||||||
|
item?.webspace ??
|
||||||
|
null;
|
||||||
|
|
||||||
|
const localSubscriptionByExternal = rawExternalSubscriptionId
|
||||||
|
? subscriptionByExternalId.get(rawExternalSubscriptionId)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
const localSubscriptionByLocalId = rawExternalSubscriptionId
|
||||||
|
? subscriptionByLocalId.get(rawExternalSubscriptionId)
|
||||||
|
: undefined;
|
||||||
|
const localSubscriptionByName = subscriptionNameHint
|
||||||
|
? subscriptionByName.get(
|
||||||
|
String(subscriptionNameHint).trim().toLowerCase(),
|
||||||
|
)
|
||||||
|
: undefined;
|
||||||
|
const localSubscription =
|
||||||
|
localSubscriptionByExternal ??
|
||||||
|
localSubscriptionByLocalId ??
|
||||||
|
localSubscriptionByName;
|
||||||
|
|
||||||
|
const externalSubscriptionId = localSubscription
|
||||||
|
? localSubscription.pleskSubscriptionId
|
||||||
|
: subscriptionNameHint
|
||||||
|
? String(subscriptionNameHint)
|
||||||
|
: rawExternalSubscriptionId;
|
||||||
const rawCreated = item?.created_at ?? item?.created;
|
const rawCreated = item?.created_at ?? item?.created;
|
||||||
const sourceCreatedAt = rawCreated
|
const sourceCreatedAt = rawCreated
|
||||||
? new Date(String(rawCreated)).toISOString()
|
? new Date(String(rawCreated)).toISOString()
|
||||||
|
|||||||
Reference in New Issue
Block a user