Skip to content

Feature/b2b team 3521 export bulk - #224

Open
wender wants to merge 4 commits into
masterfrom
feature/B2BTEAM-3521_export-bulk
Open

Feature/b2b team 3521 export bulk#224
wender wants to merge 4 commits into
masterfrom
feature/B2BTEAM-3521_export-bulk

Conversation

@wender

@wender wender commented May 29, 2026

Copy link
Copy Markdown
Contributor

What problem is this solving?

The B2B Admin needs to export organizations, cost centers, members, and addresses as CSV, but the export engine lives in b2b-bulk-import (REST + XLSX). The admin frontend should not call that service directly or handle file conversion.

This PR adds a GraphQL layer in b2b-organizations-graphql that:

  • Exposes createExport and exportStatus for all four export types
  • Proxies b2b-bulk-import with admin auth
  • Converts completed XLSX exports to UTF-8 CSV (with BOM) on first download
  • Serves files via GET /_v/private/b2b/export/:exportId
  • Normalizes columns for organizations and cost_centers; passes through members and addresses as returned by bulk-import
  • Caches converted CSV in VBase (5-minute TTL) and throttles status snapshot writes to avoid VBase rate limits during polling

This unblocks the frontend export button work in b2b-organizations.

How to test it?

Workspace: https://wender--b2bstoreqa.myvtex.com (link this branch with vtex link)

Prerequisites: Admin user with buyer_organization_view; b2b-bulk-import available on the account.

  1. Start an export (Admin GraphQL IDE or curl):
mutation CreateExport($exportType: ExportType!) {
  createExport(exportType: $exportType) {
    exportId
  }
}

Variables: { "exportType": "organizations" } (repeat for cost_centers, members, addresses).

  1. Poll until complete:
query ExportStatus($exportId: String!) {
  exportStatus(exportId: $exportId) {
    status
    progressPercentage
    exportedRows
    linkToFile
  }
}
  • Expect IN_PROGRESSCOMPLETED
  • linkToFile should appear only when status === COMPLETED
  • Progress may be computed from exportedRows / totalRows when bulk-import returns 0%
  1. Download CSV: open linkToFile in the browser while logged into Admin, or:
curl -O -J 'https://wender--b2bstoreqa.myvtex.com/_v/private/b2b/export/{exportId}' \
  -H 'cookie: VtexIdclientAutCookie=...'
  • First download may take a few seconds (XLSX fetch + conversion)
  • CSV should have UTF-8 BOM and normalized headers for orgs/cost centers
  • Second download within 5 minutes should be faster (VBase cache)
  1. Auth: unauthenticated download should return 403 Access denied.

  2. Unit tests: yarn test in node/ (includes csvConverter.test.ts).

See docs/README.md for full API details.

Workspace

Screenshots or example usage:

image

@vtex-io-ci-cd

vtex-io-ci-cd Bot commented May 29, 2026

Copy link
Copy Markdown

Hi! I'm VTEX IO CI/CD Bot and I'll be helping you to publish your app! 🤖

Please select which version do you want to release:

  • Patch (backwards-compatible bug fixes)

  • Minor (backwards-compatible functionality)

  • Major (incompatible API changes)

And then you just need to merge your PR when you are ready! There is no need to create a release commit/tag.

  • No thanks, I would rather do it manually 😞

@vtex-io-docs-bot

Copy link
Copy Markdown

Beep boop 🤖

Thank you so much for keeping our documentation up-to-date ❤️

@wender wender changed the title Feature/b2 bteam 3521 export bulk Feature/b2b team 3521 export bulk May 29, 2026

@enzomerca enzomerca 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.

por que não podemos chamar o b2b-bulk-import do front? entendo que podemos, da mesma forma que ele é chamado para a feature de importação.

@wender

wender commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

por que não podemos chamar o b2b-bulk-import do front? entendo que podemos, da mesma forma que ele é chamado para a feature de importação.

@enzomerca
Poderia fazer só no front, mas perderia alguns controles, como cache, conversão de arquivo, normalização etc. Dividir as tarefas em front e backend diminui a complexidade. O backend é mais eficiente pra essas tarefas e ainda devolvemos um download via HTTP real

@wender
wender requested a review from enzomerca June 8, 2026 16:56
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