Skip to content

feat: add Supabase integration with product catalog seeding and manag… - #15

Merged
ArielAio merged 1 commit into
mainfrom
feature/supabase
Mar 19, 2026
Merged

ArielAio merged 1 commit into
mainfrom
feature/supabase

Conversation

@ArielAio

Copy link
Copy Markdown
Owner

…ement

  • Implement Supabase client setup in lib/supabase-server.js for public and service role access.
  • Create a seeding script in scripts/supabase-seed.cjs to populate categories, subcategories, products, attendants, and contact channels in the database.
  • Define database schema for categories, subcategories, products, product images, attendants, contact channels, and site settings in a new migration file 20260319_000001_catalog_phase1.sql.
  • Add row-level security policies for data access control in Supabase.
  • Introduce integration tests for the AdminServiceManager component to ensure attendants are loaded and editable.

…ement

- Implement Supabase client setup in `lib/supabase-server.js` for public and service role access.
- Create a seeding script in `scripts/supabase-seed.cjs` to populate categories, subcategories, products, attendants, and contact channels in the database.
- Define database schema for categories, subcategories, products, product images, attendants, contact channels, and site settings in a new migration file `20260319_000001_catalog_phase1.sql`.
- Add row-level security policies for data access control in Supabase.
- Introduce integration tests for the `AdminServiceManager` component to ensure attendants are loaded and editable.
@ArielAio ArielAio self-assigned this Mar 19, 2026
Copilot AI review requested due to automatic review settings March 19, 2026 13:19
@vercel

vercel Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
li-rilko Ready Ready Preview, Comment Mar 19, 2026 1:19pm

@ArielAio
ArielAio merged commit 221ccbe into main Mar 19, 2026
5 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the app’s catalog/admin persistence layer from GitHub-backed JSON + localStorage to Supabase (Postgres + Storage), including schema/migrations, a seed script, server-side catalog snapshots, and updated admin APIs/UI + tests.

Changes:

  • Added Supabase server client helpers plus a new catalog-repository layer to read/write catalog entities (including product images via Supabase Storage).
  • Introduced initial Supabase schema + RLS policies and a supabase:seed script to bootstrap catalog data into Supabase.
  • Refactored CatalogProvider + admin managers/routes/tests to use the new Supabase-backed API contract and server-provided initial snapshot.

Reviewed changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/unit/lib/attendants-store.test.js Updates unit tests to cover local file attendants reading + fallback behavior.
tests/unit/api/admin-attendants-route.test.js Updates API route unit tests for new Supabase-backed attendants persistence/contract.
tests/setup/jsdom.setup.js Adds next/navigation mocks and clears new runtime test globals between tests.
tests/known-issues/admin-contracts.test.jsx Adjusts “known issues” contract probe to new async mutators + new provider contract.
tests/integration/providers/catalog-provider.integration.test.jsx Updates provider integration tests for server snapshot + API-driven mutations.
tests/integration/providers/catalog-provider-admin-contract.integration.test.jsx Updates admin mutator contract integration tests for new async API contract (incl. attendants).
tests/integration/components/admin-service-manager.integration.test.jsx Adds integration test ensuring attendants are loaded and editable in AdminServiceManager.
tests/fixtures/catalog.fixture.js Refactors catalog fixture creation/persistence to new app-catalog and runtime globals (no localStorage).
tests/e2e/smoke/runtime-mocks.js Updates Playwright runtime mocks to inject catalog via test globals rather than localStorage.
supabase/migrations/20260319_000001_catalog_phase1.sql Adds initial Supabase schema for catalog entities + RLS policies + storage bucket/policy.
scripts/supabase-seed.cjs Adds seed script to upsert catalog entities and upload product images to Supabase Storage.
package.json Adds @supabase/supabase-js dependency and supabase:seed script.
package-lock.json Locks new Supabase dependency tree.
lib/supabase-server.js Adds server-only Supabase client creation + env/config helpers.
lib/catalog-repository.js Implements Supabase-backed catalog repository (bootstrap snapshots, CRUD, image upload/delete).
lib/attendants-store.js Simplifies attendants store to local file read + sanitize/fallback (removes GitHub sync).
lib/app-catalog-data.js Introduces “app catalog” default creator that merges catalog defaults + attendants defaults.
lib/admin-route.js Adds shared admin route helpers (auth gate + no-store JSON responses).
data/catalog-seed.json Adds initial catalog seed dataset (categories/products/contact/site settings).
components/whatsapp-float-widget.js Reads attendants from CatalogProvider and passes them into attendant flow resolution.
components/providers/catalog-provider.js Major refactor: provider now initializes from server snapshot and uses admin API for mutations (incl. images/attendants).
components/providers/app-providers.js Wires initialCatalog into CatalogProvider.
components/admin/managers/admin-service-manager.js Refactors attendants/contact/site settings management to use provider mutators + refresh; removes GitHub PR metadata UI.
components/admin/managers/admin-products-manager.js Refactors product form to categoryId/subcategoryId, adds image upload/delete UI backed by API.
components/admin/managers/admin-categories-manager.js Refactors categories editor to ID-based admin categories + structured subcategory editing.
app/layout.js Makes RootLayout async and injects initialCatalog from getPublicCatalogSnapshot().
app/contato/page.js Uses provider attendants for WhatsApp attendant flow resolution.
app/carrinho/page.js Uses provider attendants for WhatsApp attendant flow resolution.
app/api/admin/site-settings/route.js Adds admin API route to persist site settings via catalog repository.
app/api/admin/products/route.js Adds admin API route to create products via catalog repository.
app/api/admin/products/[id]/route.js Adds admin API routes to update/delete products via catalog repository.
app/api/admin/products/[id]/images/route.js Adds admin API route to upload staged product images via Supabase Storage.
app/api/admin/products/[id]/images/[imageId]/route.js Adds admin API route to delete staged or persisted product images.
app/api/admin/contact-channels/route.js Adds admin API route to persist contact channels via catalog repository.
app/api/admin/categories/route.js Adds admin API route to persist categories/subcategories via catalog repository.
app/api/admin/bootstrap/route.js Adds admin bootstrap endpoint used by provider to refresh admin catalog state.
app/api/admin/attendants/route.js Refactors attendants admin API to use catalog repository (read bootstrap + save attendants).
TESTING.md Documents Supabase seed command and updates notes about GitHub persistence removal.
.env.example Updates example env vars from GitHub sync to Supabase configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/catalog-repository.js
Comment on lines +661 to +665
const deleteAllResponse = await client.from("product_images").delete().eq("product_id", productId);
ensureQueryResult(deleteAllResponse, "Falha ao sincronizar imagens do produto");

if (upserts.length > 0) {
const insertResponse = await client.from("product_images").insert(upserts);
Comment thread TESTING.md
Comment on lines +18 to +19
- Migration inicial: [supabase/migrations/20260319_000001_catalog_phase1.sql](/Users/arielaio/Desktop/Arquivos/Projetos/Projetos%20com%20Siconeli/Li%20Rilko/supabase/migrations/20260319_000001_catalog_phase1.sql)
- Seed local: [scripts/supabase-seed.cjs](/Users/arielaio/Desktop/Arquivos/Projetos/Projetos%20com%20Siconeli/Li%20Rilko/scripts/supabase-seed.cjs)
Comment thread lib/catalog-repository.js
function ensureSupabaseServiceClient() {
if (!isSupabaseServiceConfigured()) {
throw new CatalogRepositoryConfigError(
"Supabase não configurado para escrita. Defina NEXT_PUBLIC_SUPABASE_URL, NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY, SUPABASE_SERVICE_ROLE_KEY e SUPABASE_STORAGE_BUCKET_PRODUCTS.",
Comment thread lib/catalog-repository.js
const removedRows = existingRows.filter((row) => !keptIds.has(row.id));

if (removedRows.length > 0) {
await client.storage.from(getSupabaseProductsBucket()).remove(removedRows.map((row) => row.storage_path));
Comment thread lib/catalog-repository.js
ensureQueryResult(deleteProductResponse, "Falha ao excluir produto");

if (imageRows.length > 0) {
await client.storage.from(getSupabaseProductsBucket()).remove(imageRows.map((row) => row.storage_path));
Comment thread lib/catalog-repository.js
Comment on lines +969 to +974
if (isStagedImageId(imageId)) {
const storagePath = decodeStagedImageId(imageId);
if (storagePath) {
await client.storage.from(getSupabaseProductsBucket()).remove([storagePath]);
}
return { ok: true };
Comment thread lib/catalog-repository.js
Comment on lines +987 to +989
await client.storage.from(getSupabaseProductsBucket()).remove([imageResponse.data.storage_path]);
const deleteResponse = await client.from("product_images").delete().eq("id", imageId);
ensureQueryResult(deleteResponse, "Falha ao excluir imagem do produto");
Comment on lines +71 to 86
it("retorna 200 no PUT autenticado", async () => {
isAdminSessionValidMock.mockReturnValue(true);
updateAttendantsInRepositoryMock.mockResolvedValue({
attendants: [{ name: "Ari", phone: "5517999991111" }],
commitSha: "abc123",
pullRequestUrl: "https://github.com/ArielAio/Li-Rilko/pull/42",
pullRequestNumber: 42,
workBranch: "bot/attendants-admin",
unchanged: false,
autoMergeRequested: true,
autoMergeStatusMessage: "Auto-merge solicitado com método squash.",
saveAttendantsInCatalogMock.mockResolvedValue({
catalog: {
attendants: [{ id: "att-1", name: "Ari", phone: "5517999991111" }],
},
});

const response = await PUT(
makeRequest(
"PUT",
JSON.stringify({
attendants: [{ name: "Ari", phone: "5517999991111" }],
attendants: [{ id: "att-1", name: "Ari", phone: "5517999991111" }],
}),
),
);

This branch was successfully deployed

1 active deployment
Preview — f6ab2bd2 Deployed Mar 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants