Skip to content

feat: file upload via Order Entry Service (OES) - #3334

Merged
ArthurTriis1 merged 43 commits into
devfrom
feature/file-upload-order-entry-service
Jun 10, 2026
Merged

ArthurTriis1 merged 43 commits into
devfrom
feature/file-upload-order-entry-service

Conversation

@ArthurTriis1

@ArthurTriis1 ArthurTriis1 commented May 19, 2026 •

Copy link
Copy Markdown
Collaborator

Context

Previously, the quick order feature required merchants to upload files in a strict CSV format — with a fixed column layout — for the system to parse and add products to the cart. This was brittle, error-prone, and limited to a single file type.

This PR integrates FastStore with the VTEX Order Entry Service (OES), a backend service that handles file parsing and order composition server-side, with AI-assisted extraction. This means:

  • More file types are supported — not just CSV. The OES can understand various formats without requiring the user to follow a rigid template.
  • Smarter parsing — the OES uses AI to extract product and quantity information from uploaded files, making the feature more resilient to different file structures.
  • Transparent to the end user — the quick order UI looks and feels the same. The user selects a file, waits for processing, and gets the items loaded into the drawer. The underlying engine is now far more capable.

What changed

  • API layer (@faststore/api): adds GraphQL mutations and queries (uploadFileToOrderEntry, startOrderEntryOperation, orderEntryOperation, orderFormItems) and the corresponding VTEX commerce client methods to drive the OES flow.
  • SDK hooks (@faststore/core): introduces useOrderEntryUpload, useOrderEntryOperation, useOrderFormItems, and the orchestration hook useOrderEntry that ties upload → processing → cart merge together.
  • UI (@faststore/components): adds a Processing state to FileUploadStatus to represent the OES processing phase (distinct from the upload phase), with a configurable processingStatusText label.
  • SearchInput refactor: replaces the old useCSVParser + bulk-product lookup approach with the OES-backed flow end-to-end.
  • Cleanup: removes useCSVParser hook and useBulkProductsQuery — no longer needed.

Test Plan

  • Select a CSV file in the quick order search input and confirm the upload → processing → drawer flow works end-to-end
  • Verify the uploading spinner transitions to a processing state before the drawer opens
  • Verify the QuickOrderDrawer is populated with the correct items after a successful OES operation
  • Verify error state is shown when the upload or OES operation fails
  • Run the test suite: pnpm turbo run test --filter=@faststore/api --filter=@faststore/core

🤖 Generated with Claude Code

@ArthurTriis1
ArthurTriis1 requested a review from a team as a code owner May 19, 2026 15:31
@ArthurTriis1
ArthurTriis1 requested review from eduardoformiga and hellofanny and removed request for a team May 19, 2026 15:31
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds VTEX Order Entry integration: backend client namespace and GraphQL types/resolvers for file upload and operation polling; frontend SDK hooks (upload, operation, order-form items), Processing UI state for file uploads, SearchInput refactor from CSV to OES flow, and cleanup of CSV parser/bulk-product hooks/exports.

Changes

Order Entry Integration & Quick-Order Refactor

Layer / File(s) Summary
VTEX client & GraphQL types
packages/api/src/platforms/vtex/clients/commerce/index.ts, packages/api/src/platforms/vtex/typeDefs/orderEntry.graphql, packages/api/src/platforms/vtex/typeDefs/mutation.graphql, packages/api/src/platforms/vtex/typeDefs/query.graphql
Adds orderEntry namespace (uploadFile, startOperation, getOperation, createOrderForm, getOrderFormItems) and GraphQL types/inputs/results for upload, operation, status, missing items, and OrderFormCartItem.
GraphQL resolvers & tests
packages/api/src/platforms/vtex/resolvers/*.ts, packages/api/test/integration/schema.test.ts, packages/core/test/server/index.test.ts
Resolvers for uploadFileToOrderEntry, startOrderEntryOperation, orderEntryOperation, and orderFormItems validate inputs, decode/forward file buffers, orchestrate order form creation and operation start, delegate to commerce client, and update schema test expectations.
React SDK hooks: upload, operation, items
packages/core/src/sdk/orderEntry/*
useOrderEntryUpload reads file → Base64 → mutation; useOrderEntryOperation starts operation and polls until terminal status; useOrderFormItems fetches order-form items by id; types and reset/loading/error APIs provided.
Orchestration hook & Processing UI
packages/core/src/sdk/orderEntry/useOrderEntry.ts, packages/components/src/molecules/FileUploadStatus/*, packages/components/src/molecules/FileUploadCard/*, packages/ui/src/components/molecules/FileUploadStatus/styles.scss
useOrderEntry composes upload and startOperation with cart id; adds Processing FileUploadState, isProcessing prop and processingStatusText prop; shared spinner styling applied and components wired to show processing state.
SearchInput: migrate CSV → OES quick-order
packages/core/src/components/search/SearchInput/SearchInput.tsx
Replaces CSV parsing + bulk-products query with OES hooks (useOrderEntry, useOrderFormItems), adds mapping helper for order-form items → products, refactors file selection/search/add-to-cart and drawer lifecycle to use OES state.
Configuration: CMS schema & Navbar props
packages/core/cms/faststore/sections.json, packages/core/src/components/sections/Navbar/Navbar.tsx
Adds processingStatusText field (default "Importing...") to fileUploadCard schema and optional processingStatusText prop in Navbar config types.
Cleanup: remove CSV parser & exports
packages/components/src/hooks/index.ts, packages/components/src/hooks/useCSVParser.ts, packages/core/src/sdk/product/useBulkProductsQuery.ts
Removes CSV parser hook module and barrel exports; deletes bulk-products query hook previously used for CSV quick-order flow.
Unit & integration tests
packages/api/test/unit/platforms/vtex/resolvers/orderEntry.test.ts, packages/components/test/molecules/*, packages/api/test/integration/schema.test.ts
Adds unit tests for order-entry resolvers and component tests for FileUploadCard/FileUploadStatus; updates schema tests to include new Query/Mutation fields.

Sequence Diagram

sequenceDiagram
  participant User
  participant Frontend
  participant GraphQL
  participant VtexCommerceClient
  participant OrderEntryAPI
  User->>Frontend: select file & submit
  Frontend->>GraphQL: uploadFileToOrderEntry(file base64,..)
  GraphQL->>VtexCommerceClient: orderEntry.uploadFile(buffer,..)
  VtexCommerceClient->>OrderEntryAPI: multipart POST /upload
  OrderEntryAPI-->>VtexCommerceClient: objectKey
  GraphQL-->>Frontend: objectKey
  Frontend->>GraphQL: startOrderEntryOperation(objectKey,orderFormId)
  GraphQL->>VtexCommerceClient: orderEntry.startOperation(...)
  VtexCommerceClient->>OrderEntryAPI: POST create operation
  OrderEntryAPI-->>VtexCommerceClient: operationId
  Frontend->>GraphQL: poll orderEntryOperation(operationId)
  GraphQL->>VtexCommerceClient: orderEntry.getOperation(operationId)
  VtexCommerceClient-->>GraphQL: status/details
  Frontend->>GraphQL: orderFormItems(orderFormId)
  GraphQL->>VtexCommerceClient: orderEntry.getOrderFormItems(orderFormId)
  VtexCommerceClient-->>GraphQL: items
  GraphQL-->>Frontend: items -> map -> add to cart
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • vtex/faststore#3117: Removes useCSVParser, overlapping with this PR's CSV removal.
  • vtex/faststore#3197: Both modify quick-order file flow; this PR migrates that flow to VTEX OES.
  • vtex/faststore#3109: Adds FileUploadCard/FileUploadStatus behavior that this PR extends with Processing state.

Suggested labels

enhancement

Suggested reviewers

  • hellofanny
  • eduardoformiga
  • lemagnetic

Poem

🎵 A CSV settled, its parse put to rest,
OES arrives to handle the bulk request.
Uploads, polls, and items align,
Quick-order flows — cart adds just fine.
Merge the change — let the new path do its best.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding file upload functionality via the Order Entry Service (OES), which aligns with the substantial changes across GraphQL schema, resolvers, SDK hooks, and UI components.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/file-upload-order-entry-service

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codesandbox-ci

codesandbox-ci Bot commented May 19, 2026 •

Copy link
Copy Markdown

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 10

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/api/src/platforms/vtex/clients/commerce/index.ts`:
- Around line 870-874: The checkout request headers are only copying
VtexIdclientAutCookie from autHeaders, dropping other auth headers; update the
headers object used in the commerce checkout calls to spread the entire
autHeaders (e.g., headers: { 'Content-Type': 'application/json',
'X-FORWARDED-HOST': forwardedHost, ...autHeaders }) so all auth-related keys are
forwarded, and apply the same change to the second occurrence that currently
builds headers at the other checkout call (the block using autHeaders around
lines 891-895).
- Around line 769-775: The multipart header assembly in headerPart currently
interpolates the user-controlled fileName directly; sanitize fileName before use
in the Content-Disposition line by stripping or replacing CRLF (\r, \n), double
quotes, and other control characters and optionally limiting length or falling
back to a safe default; update the code that constructs headerPart (referencing
headerPart, fileName, boundary, mimeType, CRLF) to use the sanitized filename
variable so injected CR/LF or quotes cannot break multipart boundaries or
headers.

In `@packages/api/src/platforms/vtex/resolvers/startOrderEntryOperation.ts`:
- Around line 14-19: The resolver currently always calls
commerce.orderEntry.createOrderForm() and ignores any orderFormId provided by
the mutation input; change it to prefer the input by setting a local orderFormId
= data.orderFormId ?? (await commerce.orderEntry.createOrderForm()).orderFormId
(or equivalent) and then pass that orderFormId into
commerce.orderEntry.startOperation along with data.objectKey and
data.sessionToken; update references to the existing orderFormId variable (and
remove the unconditional createOrderForm call) so the input value is used when
present.

In `@packages/api/src/platforms/vtex/resolvers/uploadFileToOrderEntry.ts`:
- Around line 12-19: The input validation currently only checks presence before
calling Buffer.from(fileContent, 'base64') in uploadFileToOrderEntry; update
this to first validate that fileContent is valid Base64 (e.g., match against a
Base64 regex or try a safe decode check) and enforce a maximum upload size by
computing the decoded byte size from the Base64 length (or set a
MAX_UPLOAD_BYTES constant) and throwing BadRequestError if it exceeds the limit;
also add simple checks on fileName/mimeType length/format to reject suspicious
values before decoding or making platform calls so malformed or very large
payloads never reach Buffer.from or downstream APIs.

In `@packages/api/src/typeDefs/orderEntry.graphql`:
- Around line 24-65: The GraphQL output types must be renamed to use the
Store{Entity} prefix: rename OrderEntryUploadResult ->
StoreOrderEntryUploadResult, OrderEntryOperationResult ->
StoreOrderEntryOperationResult, OrderEntryMissingItem ->
StoreOrderEntryMissingItem, OrderEntryOperationStatus ->
StoreOrderEntryOperationStatus, and OrderFormCartItem -> StoreOrderFormCartItem;
update every schema reference and any resolver/type-mapping code that uses those
symbols (queries, mutations, fragments, imports) to the new names so the schema
and implementation remain consistent.

In `@packages/api/src/typeDefs/query.graphql`:
- Around line 467-471: The schema exposes two queries without authentication:
add the `@auth` directive to the GraphQL query fields orderEntryOperation and
orderFormItems in the query type so these endpoints require authentication;
update the definitions for orderEntryOperation(operationId: String!):
OrderEntryOperationStatus and orderFormItems(orderFormId: String!):
[OrderFormCartItem!]! to include `@auth`, ensuring the schema-level protection is
applied for those operations.

In `@packages/core/src/components/search/SearchInput/SearchInput.tsx`:
- Around line 154-162: The effect using useEffect reads oesStatus and calls
fetchOrderFormItems but does not list fetchOrderFormItems in the dependency
array, which can cause stale closures; fix by either adding fetchOrderFormItems
to the dependency array of the useEffect where oesStatus is checked or ensure
fetchOrderFormItems is stable (wrap it in useCallback) and then include that
stable reference in the dependency array (update the useEffect that references
oesStatus, fetchOrderFormItems to depend on oesStatus?.status,
oesStatus?.entityId, and fetchOrderFormItems).

In `@packages/core/src/sdk/orderEntry/useOrderEntry.ts`:
- Around line 12-19: The composite reset in useOrderEntry only calls reset from
useOrderEntryOperation and leaves upload state/error sticky; update
useOrderEntryUpload to expose a reset/clear function (e.g., resetUpload or
clearUploadState) if it doesn't already, then change the composite reset in
useOrderEntry.ts to call both reset (from useOrderEntryOperation) and the new
reset/clear function from useOrderEntryUpload so uploadError and isUploading are
cleared between attempts.

In `@packages/core/src/sdk/orderEntry/useOrderEntryOperation.ts`:
- Around line 100-113: The returned status can be stale after calling reset
since reset only clears operationId but the code still returns statusData;
update the return shape so status is only provided when the current operationId
is active (e.g., return null for status when operationId is falsy) — locate the
return block in useOrderEntryOperation (referencing reset, operationId,
statusData, isPolling/isPending) and change status:
statusData?.orderEntryOperation ?? null to be gated by operationId (only return
the orderEntryOperation when operationId is truthy and matches the active
operation), and ensure any derived flags (isLoading/isPending) consistently
consider operationId so cleared operations don’t leave stale UI state.

In `@packages/core/src/sdk/orderEntry/useOrderFormItems.ts`:
- Around line 47-53: reset currently only clears the orderFormId which leaves
previous items in `data?.orderFormItems`; update the `reset` callback to also
clear the items cache/state so the returned `items` becomes null (e.g. in the
`reset` implementation call the local setter that holds items like
`setOrderFormItems(null)` or, if using a fetch cache/SWR, call
`mutate(null)`/clear the cached `data`) so that `items: data?.orderFormItems ??
null` doesn't leak prior items after reset.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3d3db84b-f68a-4fea-a5de-11df930ce7c4

📥 Commits

Reviewing files that changed from the base of the PR and between a803535 and 5bec4c2.

⛔ Files ignored due to path filters (4)
  • packages/api/src/__generated__/schema.ts is excluded by !**/__generated__/** and included by packages/**
  • packages/core/@generated/gql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
  • packages/core/@generated/graphql.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
  • packages/core/@generated/index.ts is excluded by !**/@generated/**, !**/@generated/** and included by packages/**
📒 Files selected for processing (25)
  • packages/api/src/platforms/vtex/clients/commerce/index.ts
  • packages/api/src/platforms/vtex/resolvers/getOrderEntryOperation.ts
  • packages/api/src/platforms/vtex/resolvers/getOrderFormItems.ts
  • packages/api/src/platforms/vtex/resolvers/mutation.ts
  • packages/api/src/platforms/vtex/resolvers/query.ts
  • packages/api/src/platforms/vtex/resolvers/startOrderEntryOperation.ts
  • packages/api/src/platforms/vtex/resolvers/uploadFileToOrderEntry.ts
  • packages/api/src/typeDefs/mutation.graphql
  • packages/api/src/typeDefs/orderEntry.graphql
  • packages/api/src/typeDefs/query.graphql
  • packages/api/test/integration/schema.test.ts
  • packages/components/src/hooks/index.ts
  • packages/components/src/hooks/useCSVParser.ts
  • packages/components/src/molecules/FileUploadCard/FileUploadCard.tsx
  • packages/components/src/molecules/FileUploadStatus/FileUploadStatus.tsx
  • packages/core/cms/faststore/sections.json
  • packages/core/src/components/search/SearchInput/SearchInput.tsx
  • packages/core/src/components/sections/Navbar/Navbar.tsx
  • packages/core/src/sdk/orderEntry/useOrderEntry.ts
  • packages/core/src/sdk/orderEntry/useOrderEntryOperation.ts
  • packages/core/src/sdk/orderEntry/useOrderEntryUpload.ts
  • packages/core/src/sdk/orderEntry/useOrderFormItems.ts
  • packages/core/src/sdk/product/useBulkProductsQuery.ts
  • packages/core/test/server/index.test.ts
  • packages/ui/src/components/molecules/FileUploadStatus/styles.scss
💤 Files with no reviewable changes (3)
  • packages/core/src/sdk/product/useBulkProductsQuery.ts
  • packages/components/src/hooks/useCSVParser.ts
  • packages/components/src/hooks/index.ts

Comment thread packages/api/src/typeDefs/query.graphql Outdated
Comment on lines +467 to +471
orderEntryOperation(operationId: String!): OrderEntryOperationStatus
"""
Returns the items in an orderForm by its ID.
"""
orderFormItems(orderFormId: String!): [OrderFormCartItem!]!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add @auth to OES queries to avoid unauthenticated access paths.

orderEntryOperation and orderFormItems expose operation/cart data but currently have no auth directive. Protect them at schema level.

Suggested fix
-  orderEntryOperation(operationId: String!): OrderEntryOperationStatus
+  orderEntryOperation(operationId: String!): OrderEntryOperationStatus
+    `@auth`
+    `@cacheControl`(scope: "private", sMaxAge: 0, staleWhileRevalidate: 0)
@@
-  orderFormItems(orderFormId: String!): [OrderFormCartItem!]!
+  orderFormItems(orderFormId: String!): [OrderFormCartItem!]!
+    `@auth`
+    `@cacheControl`(scope: "private", sMaxAge: 0, staleWhileRevalidate: 0)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/api/src/typeDefs/query.graphql` around lines 467 - 471, The schema
exposes two queries without authentication: add the `@auth` directive to the
GraphQL query fields orderEntryOperation and orderFormItems in the query type so
these endpoints require authentication; update the definitions for
orderEntryOperation(operationId: String!): OrderEntryOperationStatus and
orderFormItems(orderFormId: String!): [OrderFormCartItem!]! to include `@auth`,
ensuring the schema-level protection is applied for those operations.

@ArthurTriis1
ArthurTriis1 marked this pull request as draft May 19, 2026 15:48
@pkg-pr-new

pkg-pr-new Bot commented May 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@faststore/api

npm i https://pkg.pr.new/vtex/faststore/@faststore/api@fd37d86

@faststore/cli

npm i https://pkg.pr.new/vtex/faststore/@faststore/cli@fd37d86

@faststore/components

npm i https://pkg.pr.new/vtex/faststore/@faststore/components@fd37d86

@faststore/core

npm i https://pkg.pr.new/vtex/faststore/@faststore/core@fd37d86

@faststore/diagnostics

npm i https://pkg.pr.new/vtex/faststore/@faststore/diagnostics@fd37d86

@faststore/lighthouse

npm i https://pkg.pr.new/vtex/faststore/@faststore/lighthouse@fd37d86

@faststore/sdk

npm i https://pkg.pr.new/vtex/faststore/@faststore/sdk@fd37d86

@faststore/ui

npm i https://pkg.pr.new/vtex/faststore/@faststore/ui@fd37d86

commit: fd37d86

ArthurTriis1 and others added 14 commits May 19, 2026 15:57
…d createOrderForm

Separate oesBase (vtexcommercebeta.com.br) from the main API base to correctly
target the Order Entry Service. Also adds createOrderForm to provision a new
orderForm before starting a bulk import operation.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ions

Registers uploadFileToOrderEntry and startOrderEntryOperation mutations
alongside the orderEntryOperation polling query. Each resolver delegates
to the commerce client's orderEntry namespace.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ned flow

Introduces useOrderEntryUpload (Base64 file upload), useOrderEntryOperation
(polling with 2s interval until terminal status), and useOrderEntry as the
high-level composite hook for the full CSV import flow.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
CSV parsing logic was replaced by the Order Entry Service flow, which
handles file processing server-side. The hook and its public exports
are no longer needed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Replaces the CSV-parse-then-bulk-search approach (useCSVParser +
useBulkProductsQuery) with useOrderEntry, which uploads the file
directly to the Order Entry Service and redirects to checkout on
success. Removes useBulkProductsQuery as it is no longer used.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…port phase

Adds FileUploadState.Processing with a processingStatusText prop so the
upload card can display a distinct label while the Order Entry Service
operation is polling. The spinning icon animation is shared between the
Uploading and Processing states via a selector group.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Exposes isUploading and isProcessing separately from useOrderEntry.
isProcessing covers both the startOperation mutation and the polling
period, eliminating the Completed flash between phases. SearchInput
passes each flag independently to FileUploadCard and wires the new
processingStatusText CMS field (default: "Importing...").

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds getOrderFormItems commerce client method (GET /api/checkout/pub/orderForm/{id}),
OrderFormCartItem GraphQL type, orderFormItems query, and its resolver.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…rt merge

After OES operation completes (SUCCESS/PARTIAL_SUCCESS), fetches the items
from the created orderForm via the new orderFormItems query, maps them to
Product[] and opens the QuickOrderDrawer for review. Clicking "Add to Cart"
merges each item into the current session cart via cartStore instead of
redirecting directly to checkout.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ArthurTriis1
ArthurTriis1 force-pushed the feature/file-upload-order-entry-service branch from 2f86367 to 5d3e7c0 Compare May 19, 2026 19:06
@ArthurTriis1
ArthurTriis1 force-pushed the feature/file-upload-order-entry-service branch from 5d3e7c0 to fdc5413 Compare May 20, 2026 14:45
ArthurTriis1 and others added 4 commits May 20, 2026 12:05
- Convert TERMINAL_STATUSES from Array to Set and use .has() for O(1) lookups
- Remove unnecessary ArrayBuffer type assertion on body.buffer

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ArthurTriis1 and others added 5 commits May 20, 2026 16:32
…cases

Covers uploadFile (multipart body, MIME fallback, file content),
startOperation (sessionToken include/omit), getOperation, createOrderForm,
and getOrderFormItems to improve coverage on commerce/index.ts new code.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
… unit tests

- FileUploadCard: add drag/drop, dragenter/leave, Escape key, hasError
  prop, and onDownloadTemplate callback tests to cover uncovered branches
- Export and unit-test mapOrderFormItemsToProducts from SearchInput to
  cover the pure mapping function for OES items

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Covers fetchOrderFormItems trigger on SUCCESS/PARTIAL_SUCCESS, suppression
on FAILED, unauthenticated attachment button, and orderFormItems effect.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…actor

Re-adds submitButtonAriaLabel, loadingLabel, searchHistoryTitle and
searchTopTitle to SearchInputProps so starters can pass them without
a TypeScript error.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ArthurTriis1
ArthurTriis1 marked this pull request as draft May 22, 2026 01:53
@ArthurTriis1
ArthurTriis1 marked this pull request as ready for review May 22, 2026 17:41

@renatomaurovtex renatomaurovtex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code review — OES file upload

Reviewed the full diff (41 files). Architecture is sound — API/SDK/UI boundaries are respected (resolvers are framework-agnostic, hooks live in core, the new Processing state is in components), and the new hooks/resolvers/commerce-client have good test coverage. A few items should be addressed before merge, mostly around failure/edge paths.

🟠 Blocking

1. Header injection via fileName — packages/api/.../clients/commerce/index.ts. mimeType is sanitized with SAFE_MIME_PATTERN, but fileName is interpolated raw into the Content-Disposition header. A filename containing " or CRLF can break out of the multipart part and inject headers/parts; fileName is end-user controlled.

-          `Content-Disposition: form-data; name="file"; filename="${fileName}"`,
+          `Content-Disposition: form-data; name="file"; filename="${fileName.replace(/[\r\n"]/g, '')}"`,

2. OrderEntryOperationStatus.entityId should be nullable — packages/api/.../typeDefs/orderEntry.graphql. It's declared entityId: String!, but a FAILED operation has no entity (the new SearchInputComponent.test.tsx itself mocks entityId: null for FAILED, and the getOperation client types it optional). On FAILED with a null entityId, the non-null coercion errors the whole orderEntryOperation query → (a) the real FAILED status never reaches the client (the UI's oesStatus?.status === 'FAILED' branch becomes dead), and (b) useOrderEntryOperation's refreshInterval never sees a terminal status, so it polls forever.

 type OrderEntryOperationStatus {
   status: String!
-  entityId: String!
+  entityId: String
   message: String
   missingItems: [OrderEntryMissingItem!]
 }

3. No polling timeout / max attempts — packages/core/src/sdk/orderEntry/useOrderEntryOperation.ts. refreshInterval returns 2000 for any non-terminal/absent status with no ceiling. A stuck/slow OES op or a persistently erroring status query leaves the user on a spinner indefinitely. The CSV flow this replaces had a 30s timeout — please add a deadline/max-attempts that surfaces an error and stops polling.

4. SearchInput.tsx regressions:

  • handleDownloadTemplate is now an empty no-op, but downloadTemplateButtonLabel is still passed to FileUploadCard, so the button likely still renders and does nothing. Remove the button or restore behavior (with OES accepting arbitrary formats the template concept may no longer apply).
  • Public SearchInputProps removals: onFileSearch, submitButtonAriaLabel, loadingLabel, searchHistoryTitle, searchTopTitle, plus the faststore:file-search CustomEvent. These are breaking — they need a deprecation note + migration guidance. The searchHistoryTitle/searchTopTitle/loadingLabel removals (no longer forwarded to SearchDropdown) look unrelated to OES — intentional, or scope creep?
  • a11y: the submit IconButton now uses aria-label={a11yLabels?.searchButtonAriaLabel} with no fallback (the submitButtonAriaLabel fallback was removed). If a11yLabels is unset, the button ends up with no accessible name.
  • PARTIAL_SUCCESS opens the drawer but status.message / missingItems are never surfaced — the user is silently not told which items were dropped.

🟡 Minor

5. New required prop — FileUploadCard.tsx / FileUploadStatus.tsx. processingStatusText was added as required on both prop types, breaking existing @faststore/components consumers who don't pass it. Consider making it optional with a default (the core caller already falls back to 'Importing...').

6. data.orderFormId is unused — startOrderEntryOperation.ts. The input requires orderFormId: String! (the SDK passes cart.id), but the resolver ignores it and always calls createOrderForm(). If a throwaway order form is intentional, why require orderFormId in the contract? Use it or drop it.

💬 Nits / questions

7. Global CSS growth — packages/core/src/styles/global/index.scss. Badge/Button/Icon/Price/Alert/QuantitySelector/Table/Tooltip styles now load globally (the portal-rendered drawer is outside .section scope). Reasonable given the portal, but it ships on every page regardless of QuickOrder usage — please confirm pnpm size doesn't regress.

8. Base64 upload payload — useOrderEntryUpload.ts sends the file as a base64 GraphQL variable (~33% inflation). Fine for small CSVs; worth a size limit/note now that larger formats are accepted, to avoid request-body limits.

9. @generated/__generated__ changes look like a clean codegen regeneration matching the new schema (ClientProductQuery is reordered, not dropped) — just confirm they came from pnpm codegen.


Verdict: Changes requested. Blocking: #1 (filename header injection), #2 (nullable entityId / infinite poll on FAILED), #3 (polling timeout), #4 (SearchInput regressions). The rest are minor/nits.

Suggested checks before merge: pnpm lint · build · pnpm turbo run test --filter=@faststore/api --filter=@faststore/core --filter=@faststore/components · pnpm size.

ArthurTriis1 and others added 3 commits June 3, 2026 14:46
- Sanitize fileName against CR/LF/quotes before multipart Content-Disposition header
- Spread full autHeaders in createOrderForm and getOrderFormItems checkout calls
- Fix SAFE_MIME_PATTERN formatting to satisfy Biome
- Use data.orderFormId when provided in startOrderEntryOperation; create new only when empty
- Validate Base64 format and enforce 5 MB size limit in uploadFileToOrderEntry
- Rename GraphQL output types to Store* prefix (StoreOrderEntryUploadResult,
  StoreOrderEntryOperationResult, StoreOrderEntryMissingItem,
  StoreOrderEntryOperationStatus, StoreOrderFormCartItem) in schema source
  and generated files
- Fix isAutenticated typo → isAuthenticated in useAuth, ProfileChallenge,
  SearchInput and test mocks
- Add fetchOrderFormItems to useEffect dependency array in SearchInput
- Fix composite reset() in useOrderEntry to also clear upload error via clearError
- Gate status return in useOrderEntryOperation by active operationId to avoid stale state
- Gate items return in useOrderFormItems by orderFormId to avoid stale items after reset
- Remove transient Completed flash in FileUploadCard handlers; set Uploading immediately
- Update discovery.config.default.js with B2B store values while preserving original fields

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Make entityId nullable in StoreOrderEntryOperationStatus schema and
  generated types — FAILED operations have no entity; non-null coercion
  was erroring the query and causing infinite polling on failure
- Make orderFormId optional in IOrderEntryOperation input — resolver uses
  the provided value when non-empty, otherwise creates a new orderForm
- Add 60s polling timeout to useOrderEntryOperation: pollStartRef tracks
  start time, refreshInterval stops and surfaces a timeoutError when
  the deadline is exceeded; reset() also clears the timeout state
- Remove no-op handleDownloadTemplate from FileUploadCard call — OES
  accepts arbitrary formats so the template button no longer applies
- Add aria-label fallback 'Search' to hidden submit IconButton so the
  button always has an accessible name when a11yLabels is unset
- Surface PARTIAL_SUCCESS message via alertMessages.notFound in the
  QuickOrderDrawer so users see which items were not imported
- Make processingStatusText optional with default 'Importing...' in
  both FileUploadStatus and FileUploadCard to avoid breaking existing
  consumers who do not pass the prop

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Comment thread packages/components/src/hooks/index.ts Resolved
ArthurTriis1 and others added 3 commits June 8, 2026 11:32
- Restore discovery.config.default.js to starter defaults (removed accidental B2B tenant values)
- Fix startOrderEntryOperation tests: align with resolver behavior (createOrderForm only called when orderFormId is empty); add separate test for reuse path
- Add CHANGELOG breaking change entry for removed useCSVParser export

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ArthurTriis1
ArthurTriis1 force-pushed the feature/file-upload-order-entry-service branch from a3d80fb to 088fabe Compare June 9, 2026 12:55
ArthurTriis1 and others added 3 commits June 9, 2026 10:28
…ileUploadCard branches

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…tatus and FileUploadCard

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@sonar-workflows

Copy link
Copy Markdown

@ArthurTriis1
ArthurTriis1 merged commit 03edc11 into dev Jun 10, 2026
9 checks passed
@ArthurTriis1
ArthurTriis1 deleted the feature/file-upload-order-entry-service branch June 10, 2026 14:26
lemagnetic added a commit that referenced this pull request Jun 16, 2026
## What's the purpose of this pull request?

fix(api): use account-scoped cookie in orderEntry headers

The orderEntry methods (file upload via OES, #3334) still referenced the
withAutCookie helper that #3381 removed, since that PR was not rebased
on
the latest dev and did not see the newly merged orderEntry block. This
left an undefined withAutCookie reference, breaking the build and tests
on dev.

Replace the 5 withAutCookie(forwardedHost, account) calls with the
withCookie({ 'content-type', 'X-FORWARDED-HOST' }) pattern adopted by
#3381 

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved authentication/header handling for order entry endpoints to
ensure requests consistently include the correct `Content-Type` and
forwarded host information.
* Ensures file upload continues to use `multipart/form-data` with the
proper boundary while retaining the updated base header behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@eduardoformiga eduardoformiga mentioned this pull request Jun 17, 2026
2 tasks
eduardoformiga added a commit that referenced this pull request Jun 17, 2026
## Summary

Graduate the `4.3.0-dev.8` prerelease cycle to the stable `4.3.0`
release on `latest`.

Merging this PR triggers CD on `main`, which runs `lerna version
--conventional-graduate` and publishes all `@faststore/*` packages to
the `latest` dist-tag.

### Features
- Password Protection (v4) (#3276)
- File upload via Order Entry Service (OES) (#3334)
- Add sitemap to CMS Landing Page content-type (#3386)

### Bug Fixes
- **core:** use authenticator route for setpassword (#3380)
- migrate partytown `@builder.io` → `@[email protected]` (#3394)
- **api:** use account-scoped cookie in orderEntry headers (#3395)
- forward auth token only via account-scoped cookie (#3381)
- **core:** propagate upstream error status instead of always 500
(#3379)

## Pre-flight (faststore-release skill)
- Working tree clean; `release.yml` has `fetch-depth: 0`
- All 8 packages have `repository.url`
- No breaking changes since `v4.2.0`
- `dev → main` merges cleanly (no CHANGELOG/codegen conflicts)
- No unmerged hotfixes on `main` (accidental `4.2.1` was fully reverted
in #3375)

## Test plan
- [ ] CI green on this PR
- [ ] After merge, confirm CD publishes all 8 packages at `4.3.0` under
`latest`

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Matheus P. Silva <[email protected]>
Co-authored-by: vtexgithubbot <[email protected]>
Co-authored-by: Lucas Feijó <[email protected]>
Co-authored-by: Luiz Falcão <[email protected]>
Co-authored-by: Artur Santiago <[email protected]>
Co-authored-by: Larícia Mota <[email protected]>
Co-authored-by: Sahan Jayawardana <[email protected]>
Co-authored-by: Mateus Pontes <[email protected]>
Co-authored-by: Matheus Martins <[email protected]>
Co-authored-by: renatomaurovtex <[email protected]>
Co-authored-by: Leandro Rodrigues <[email protected]>
Co-authored-by: Fanny Chien <[email protected]>
Co-authored-by: Arthur Andrade <[email protected]>
Co-authored-by: Leandro Rodrigues <[email protected]>
Co-authored-by: Cursor <[email protected]>
Co-authored-by: Thiago Pereira <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: Giuliana Rigaud <[email protected]>
Co-authored-by: renato <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: BrunaCubos <[email protected]>
Co-authored-by: Ícaro Oliveira <[email protected]>
Co-authored-by: Bruna Santos <[email protected]>
Co-authored-by: Everton Ataide <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Otavio Moreira Meirelles <[email protected]>
Co-authored-by: Marco Cardoso <[email protected]>
Co-authored-by: Gabriel Paladino <[email protected]>
Co-authored-by: CodeRabbit <[email protected]>
Co-authored-by: dk-portal[bot] <134092483+dk-portal[bot]@users.noreply.github.com>
Co-authored-by: Rodrigo Tavares <[email protected]>
Co-authored-by: vitorflg <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: Válber Laux <[email protected]>
lariciamota added a commit that referenced this pull request Nov 19, 2026
## What's the purpose of this pull request?

The search dropdown can't be translated. "Top Search" and "History"
ignore the titles set in the CMS (Navbar > searchInput), and "Suggested
Products" and "Clear History" have no CMS field at all, so stores in
non-English locales always show these four labels in English.

The first part is a regression: since #3334 (released in v4.4.0),
`SearchInput` no longer destructures
`searchTopTitle`/`searchHistoryTitle`. They fall into `...otherProps`,
end up on the `<input>` as HTML attributes (`searchtoptitle="..."`), and
`<SearchDropdown>` renders without them.

## How it works?

- `SearchInput` destructures the dropdown labels again
(`searchTopTitle`, `searchHistoryTitle` and `loadingLabel`, which was
dropped in the same refactor and left the loading text empty) and
forwards them to `SearchDropdown`, so they no longer leak to the
`<input>`.
- New optional CMS fields on the Navbar `searchInput` (in
`sections.json`, `schema.json` and `cms_component__navbar.jsonc`):
- `searchProductsTitle` (default "Suggested Products"), passed as
`title` to `SearchProducts`
- `searchHistoryClearLabel` (default "Clear History"), passed as
`clearLabel` to `SearchHistory`
- The `searchTopTitle` CMS default now matches the component ("Top
Search" instead of "Top search").
- `NavbarProps['searchInput']` and `SearchInputProps` get the two new
optional props. This is additive only: nothing changes for stores that
don't set them, since `@faststore/components` keeps its English
defaults.

## How to test it?

- Set the four labels in the CMS (Navbar > Search Input), open the
search dropdown and check that the titles and the clear button use the
CMS values.
- Inspect the search `<input>`: it should no longer carry
`searchtoptitle`/`searchhistorytitle` attributes.
- Unit tests: `cd packages/core && pnpm vitest run
test/components/search`. The new label tests in
`SearchInputComponent.test.tsx` and `SearchDropdown.test.tsx` fail on
`dev` and pass here.

### Starters Deploy Preview

Use the CodeSandbox build from this PR.

## References

- Regression introduced in #3334.
- #3240 (from a partner) tackles the same problem. This PR is a rebased
take on it against the current `dev` and also covers the "Clear History"
label. Thanks to the authors of #3240 for the original fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

3 participants