Repository navigation
feat: add Supabase integration with product catalog seeding and manag… - #15
Merged
Merged
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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-repositorylayer to read/write catalog entities (including product images via Supabase Storage). - Introduced initial Supabase schema + RLS policies and a
supabase:seedscript 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 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 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) |
| 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.", |
| 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)); |
| ensureQueryResult(deleteProductResponse, "Falha ao excluir produto"); | ||
|
|
||
| if (imageRows.length > 0) { | ||
| await client.storage.from(getSupabaseProductsBucket()).remove(imageRows.map((row) => row.storage_path)); |
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 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ement
lib/supabase-server.jsfor public and service role access.scripts/supabase-seed.cjsto populate categories, subcategories, products, attendants, and contact channels in the database.20260319_000001_catalog_phase1.sql.AdminServiceManagercomponent to ensure attendants are loaded and editable.