Skip to content

Add Recebimento/Conferência MVP: frontend, Supabase schema and TeraBox backend - #4

Open
hhhthiti wants to merge 6 commits into
mainfrom
codex/integrate-supabase-user-authentication-system-ozbp8r
Open

Add Recebimento/Conferência MVP: frontend, Supabase schema and TeraBox backend#4
hhhthiti wants to merge 6 commits into
mainfrom
codex/integrate-supabase-user-authentication-system-ozbp8r

Conversation

@hhhthiti

@hhhthiti hhhthiti commented Apr 4, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Provide a minimal MVP web app for NF-e recebimento and conferência with ADM and Operação profiles and tooling to produce NQ/Excel lines and PDFs.
  • Support both Supabase-hosted DB and a local fallback mode when the Supabase schema is missing to allow offline/demo usage.
  • Enable exporting logs to TeraBox via a small backend service that handles OAuth and the TeraBox precreate/upload/create flow.
  • Supply documentation and environment examples so the backend can be run locally or deployed (Render/Netlify flows described).

Description

  • Added a full frontend: index.html, styles.css and main.js implementing authentication (matrícula/senha), ADM/Operação UIs, XML parsing, PDF generation, barcode, NQ/recebimento export lines, chat and logs.
  • Implemented Supabase integration with automatic switch to a local mode using localStorage when schema/tables are missing, via helper DB functions dbSelect, dbInsert, dbUpdate, and dbDeleteAll.
  • Added TeraBox backend service server.js plus package.json and .env.example to perform OAuth (/auth/terabox), receive callback and export TXT files to TeraBox (/exportar-txt-terabox) using preupload/upload/create calls.
  • Included an idempotent supabase-schema.sql to create required tables (usuarios, notas, conferencias, logs, chats, nq_reports) and kept README with setup and run instructions.

Testing

  • No automated tests were added or executed as part of this change.

Codex Task

@vercel

vercel Bot commented Apr 4, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
recebimento Ready Ready Preview, Comment Apr 9, 2026 7:39pm

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f2e4a6086

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server.js
Comment on lines +138 to +142
app.post('/exportar-txt-terabox', async (req, res) => {
try {
ensureConfig();
ensureToken();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Protect TeraBox export route with user authentication

The /exportar-txt-terabox handler only checks that a process-wide teraboxToken exists, so once any admin completes OAuth, any caller can POST arbitrary content to this endpoint and write files into the same TeraBox account. Because CORS is globally enabled and there is no per-request identity check, this becomes an unauthorized write path when the backend is publicly deployed.

Useful? React with 👍 / 👎.

Comment thread main.js
try {
await dbUpdate('usuarios', { matricula }, { senha: novaSenha });
if (state.mode === 'supabase') {
const { error } = await supabase.functions.invoke('send-email', { body: { to: 'leseliv487@fengnu.com', subject: 'Nova senha', text: `Nova senha: ${novaSenha}` } });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Send reset email to the user being recovered

The email recovery flow always sends the new password to a fixed mailbox instead of the target user's registered email, so resetting any matrícula leaks credentials to an unrelated address and the intended user never receives the recovery message. This breaks account recovery and exposes sensitive credentials.

Useful? React with 👍 / 👎.

Comment thread main.js
Comment on lines +827 to +830
await dbUpdate('usuarios', { matricula, telefone }, { senha: novaSenha });
if (state.mode === 'supabase') {
const { error } = await supabase.functions.invoke('send-sms', { body: { to: telefone, message: `Nova senha: ${novaSenha}` } });
if (error) throw error;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update password only after SMS delivery succeeds

The SMS recovery path writes the new password before attempting to send the SMS. If the edge function is missing/misconfigured or SMS delivery fails, the catch path reports failure but the password has already changed, leaving the user locked out without receiving the new credential.

Useful? React with 👍 / 👎.

Comment thread main.js
(nota.itens_json || []).forEach((item) => {
const code = normalizeProductCode(item.codigo);
const fardosPorPalete = getFardosPorPalete(code);
conferenciaForm.insertAdjacentHTML('beforeend', `<div class="item"><p><strong>${code}</strong> - ${item.descricao}</p><p class="hint">${fardosPorPalete} fardos por palete</p><label>Quantidade conferida<input type="number" step="0.01" min="0" required name="${code}" /></label><label class="fracao-fardo hidden" data-fracao="${code}">Fardos fracionados (quando conferir em paletes)<input type="number" step="0.01" min="0" name="${code}__fracao" value="0" /></label></div>`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Disambiguate repeated SKU rows in conferência input

Each item input is keyed only by normalized SKU code, so when an XML has multiple det rows with the same product code, the form ends up with duplicated field names and FormData.get(code) later reads only the first value. That causes incorrect per-line conferência totals, false divergences, and corrupted NQ output for those invoices.

Useful? React with 👍 / 👎.

Removed the Recebimento Excel tab and its content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant