From f5a44a91aea83840ce15b9dd023dc94127462533 Mon Sep 17 00:00:00 2001 From: Sweets Sweetman Date: Wed, 1 Jul 2026 11:05:55 -0500 Subject: [PATCH] fix(socials): drop the dead account_socials.id from /socials (keep social_id) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit /api/artists/{id}/socials returned both `id` (account_socials link-row id) and `social_id` (the socials PK). POST /api/socials/{id}/scrape and every sub-resource key on social_id — using the `id` field 404s ("Social profile not found") for every platform. The `id` was functionally dead (only React keys + a docs entry used it; scrape + updateArtistSocials use social_id). Drop `id` from AccountSocialResponse + flattenAccountSocials; keep social_id as the single identity. Chat React keys switch to social_id in a companion chat PR. Part of recoupable/chat#1833 (same id-consistency pattern as api#734). Co-Authored-By: Claude Opus 4.8 (1M context) --- .../__tests__/flattenAccountSocials.test.ts | 30 +++++++++++++++++++ lib/account/flattenAccountSocials.ts | 3 +- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 lib/account/__tests__/flattenAccountSocials.test.ts diff --git a/lib/account/__tests__/flattenAccountSocials.test.ts b/lib/account/__tests__/flattenAccountSocials.test.ts new file mode 100644 index 000000000..c300dcca0 --- /dev/null +++ b/lib/account/__tests__/flattenAccountSocials.test.ts @@ -0,0 +1,30 @@ +import { describe, it, expect } from "vitest"; +import { flattenAccountSocials } from "@/lib/account/flattenAccountSocials"; + +const rows = [ + { + id: "account-social-1", + account_id: "acct-1", + social_id: "soc-1", + social: { + id: "soc-1", + username: "apache_207", + profile_url: "tiktok.com/@apache_207", + avatar: "a", + bio: "", + region: "", + followerCount: 10, + followingCount: 1, + updated_at: "t", + }, + }, +] as never; + +describe("flattenAccountSocials", () => { + it("returns social_id (what scrape/sub-resources need) and drops the link-row id", () => { + const [s] = flattenAccountSocials(rows) as Array>; + expect(s.social_id).toBe("soc-1"); + expect(s.username).toBe("apache_207"); + expect(s.id).toBeUndefined(); // account_socials.id used to leak here → scrape 404s on it + }); +}); diff --git a/lib/account/flattenAccountSocials.ts b/lib/account/flattenAccountSocials.ts index d4bdbf814..d233a3183 100644 --- a/lib/account/flattenAccountSocials.ts +++ b/lib/account/flattenAccountSocials.ts @@ -4,7 +4,7 @@ import type { AccountSocialWithSocial } from "@/lib/supabase/account_socials/sel type AccountSocialRow = Tables<"account_socials">; type SocialRow = Tables<"socials">; -export type AccountSocialResponse = Pick & +export type AccountSocialResponse = Pick & Pick & { follower_count: SocialRow["followerCount"]; following_count: SocialRow["followingCount"]; @@ -27,7 +27,6 @@ export function flattenAccountSocials( throw new Error(`No social data found for account_social id: ${accountSocial.id}`); } return { - id: accountSocial.id, social_id: accountSocial.social_id, username: socialData.username, profile_url: socialData.profile_url,