Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

B2B Second Inventory Catalog Feature Overview

Phase 2 of the bb (B2B second inventory) area — a catalog of categories, brands, series, tags, products, variants and option axes, with bulk actions and import/export jobs, kept apart from the retail catalog.

B2B Second Inventory (bb) — Catalog Feature Overview

1. Purpose

Phase 2 gives bb staff their own product catalog. It is a separate set of tables, routes, permission codes and audit entries from the retail catalog. A bb staff member never sees a retail product, and a retail admin never sees a bb one.

Phase 2 covers:

  • Categories (a tree), brands, brand series and tags
  • Products with variants, option axes and values, a gallery and a sanitized HTML description
  • Bulk delete, bulk restore, reorder and bulk active toggle
  • Import and export jobs (CSV or XLSX in, CSV out) tracked as job rows

Pricing is integer paisa. Stock is phase 3 and is documented in the stock feature page. Orders and customer-facing pricing rules are later phases and are not documented here.

Every route in this page is mounted by BbAdminAggregateModule, and the bb_catalog job worker is registered by BbModule.


2. Surface Matrix

SurfacePathAuth
Categories/api/admin/bb/categoriesJWT + BB_Categories_*
Brands/api/admin/bb/brandsJWT + BB_Brands_*
Brand series/api/admin/bb/brand-seriesJWT + BB_BrandSeries_*
Tags/api/admin/bb/tagsJWT + BB_Tags_*
Products/api/admin/bb/productsJWT + BB_Products_*
Variants/api/admin/bb/products/:productPublicId/variantsJWT + BB_Products_*
Option axes and values/api/admin/bb/products/:productPublicId/optionsJWT + BB_Products_*
Jobs/api/admin/bb/jobs/{categories,brands,brand-series,products}JWT + BB_Catalog_* combined with the entity code

All routes are admin-only and IP-throttled. There is no public or storefront surface. Throttle constants: ADMIN_READ 30 per 60 s, ADMIN_WRITE 10 per 60 s, ADMIN_BULK_WRITE 5 per 60 s, ADMIN_REORDER 30 per 60 s.


3. Who Can Do What

Each module has five codes: CREATE, READ, UPDATE, DELETE, RESTORE.

Phase 2 adds six modules to the bb catalog, and all six are assignable to a bb role: BB_Categories, BB_Brands, BB_BrandSeries, BB_Tags, BB_Products, BB_Catalog.

ActionCode
Read live rowsBB_<Module>_READ
Create, update, move, reorder, set tags, bulk activeBB_<Module>_CREATE or _UPDATE (reorder and bulk active use UPDATE)
Soft-delete, bulk deleteBB_<Module>_DELETE
List deleted rows, restore, bulk restoreBB_<Module>_RESTORE (listing deleted rows needs RESTORE, not READ)
Variants and option axesBB_Products_*, same action mapping as the product
Import jobsBB_Catalog_CREATE and BB_<Entity>_CREATE and BB_<Entity>_UPDATE
Export jobs, list/get jobs, template, resultBB_Catalog_READ and BB_<Entity>_READ
Cancel a jobBB_Catalog_UPDATE and BB_<Entity>_UPDATE
Export deleted rows (includeDeleted: true)the above plus BB_<Entity>_RESTORE

BB_Catalog is always checked together with an entity code. Holding it alone grants nothing.

Superadmin passes every check. BB_Roles and BB_Staff are still not assignable, so only superadmin manages bb roles and staff.

A job is also re-checked when a worker claims it: the requester must still exist, not be banned, still be bb staff, and still hold every code. Otherwise the job fails with BB_JOB_AUTHORIZATION_REVOKED.


4. Catalog Rules

Categories

  • A category tree has at most 7 levels: depth is stored 0 to 6.
  • Sibling names are unique among live rows (BB_CATEGORY_NAME_TAKEN).
  • A move that would put a category under its own descendant is refused (BB_CATEGORY_MOVE_CYCLE).
  • Deleting a category with live children or live products is refused (BB_CATEGORY_HAS_CHILDREN, BB_CATEGORY_HAS_PRODUCTS).
  • Restoring a child whose parent is deleted is refused (BB_CATEGORY_PARENT_DELETED).
  • The tree endpoint returns at most 5,000 rows and sets truncated: true when it cuts.

Brands, series and tags

  • Brand, series and tag names are unique among live rows.
  • A brand with live series or live products cannot be deleted. A series with live products cannot be deleted.
  • A series belongs to one brand. A product may only pick a series of its own brand (BB_BRAND_SERIES_BRAND_MISMATCH).
  • Restoring a series needs its brand to be live (BB_BRAND_DELETED).

Products, variants and options

  • A product is created with its variants in one request: 1 to 20 variants.
  • A product holds at most 100 live variants (BB_VARIANT_LIMIT_EXCEEDED).
  • Exactly one live variant is the default. If none is flagged, the first one is. Two flagged is a 400. A default must be active (BB_VARIANT_DEFAULT_INACTIVE).
  • Deleting the last live variant is refused (BB_VARIANT_LAST_LIVE). Deleting the default needs another active variant to take over (BB_VARIANT_NO_ACTIVE_SUCCESSOR).
  • SKU is optional, matches ^[A-Za-z0-9._/-]{1,64}$, and is unique among live variants (BB_VARIANT_SKU_TAKEN).
  • Prices are integer paisa, 0 to 1,000,000,000,000 (10^12). The selling price may not exceed the MRP (BB_VARIANT_PRICE_INVALID).
  • A product has at most 5 option axes, each with 1 to 50 values. Axis names are up to 64 characters, values up to 128.
  • Two live variants may not share the same option-value combination (BB_VARIANT_DUPLICATE_COMBINATION). Adding or removing an axis that would create duplicates is refused.
  • Deleting an option value still used by a live variant is refused (BB_OPTION_VALUE_HAS_LIVE_VARIANTS).
  • A product holds at most 30 tags.
  • Gallery: at most 20 items, at most 5 videos. Images live under public/thumbnail/, videos under public/product-video/. Only a video has a poster, and only an image has alt text.
  • Description: HTML, sanitized on write. Raw input over 50,000 code points is rejected as VALIDATION_FAILED. Sanitized output over 20,000 code points is BB_PRODUCT_DESCRIPTION_TOO_LONG. A non-blank description with no allowed content left is BB_PRODUCT_DESCRIPTION_EMPTY. A blank description stores null.
  • Allowed tags: p br strong b em i u s h2 h3 h4 ul ol li blockquote code pre hr a img. Links allow http, https, mailto. Images allow http, https.

Concurrent edits

  • A product carries a version. A product update that sends a stale version answers 409 BB_PRODUCT_VERSION_CONFLICT. The version field on update is optional.
  • Every option-axis and option-value write requires productVersion and returns the new one.
  • A variant update or delete with a stale version answers 409 BB_VARIANT_VERSION_CONFLICT.
  • Catalog writes wait at most 5 seconds for a lock, then answer 409 BB_CATALOG_BUSY. A catalog entity write or bulk action that loses a deadlock or a serialization failure answers the same code, so the client retries in every case.

5. Bulk Actions and Reorder

ActionCapResult
Bulk delete, bulk restore100 ids in the request; ids are lower-cased and de-duplicated before they run200 with succeeded[] and failed[]; a refused id does not stop the rest
Bulk active (products only)100 idssame shape
Reorder (categories, brands, series)1,000 ids, not de-duplicatedall-or-nothing; changedCount
  • Sending more than 100 ids answers 400 VALIDATION_FAILED: the DTO caps the raw array at 100 before the service runs. The service-side BB_BULK_TOO_MANY_ITEMS check runs on the de-duplicated list, so it cannot fire for a request that passed the DTO.
  • Each id runs in its own savepoint with its own audit row. A failed id lands in failed[] with its errorCode. A lock timeout, a deadlock or a serialization failure aborts the whole batch with 409 BB_CATALOG_BUSY.
  • Category bulk delete runs deepest first, so a parent and its only child can leave together. Bulk restore runs shallowest first.
  • Reorder must name exactly the live siblings of one parent, in the new order. Anything else is 400 BB_REORDER_INVALID_ITEM with details.reason of duplicate_id, not_found, mixed_parents or incomplete_set.
  • Reorder writes only rows whose position changed, one audit row each (bb.category.reorder, bb.brand.reorder, bb.brand_series.reorder). The position written is the id's 0-based index in the request.

6. Import and Export Jobs

Jobs are asynchronous. Submitting one writes a job row, an outbox row and an audit row in one transaction and returns 201 with a publicId. A worker picks the job up later, one job at a time.

There are four catalog entities: categories, brands, brand series and products. There are no tag jobs. Phase 3 adds a fifth job entity, inventory, for stock: see the stock feature page.

  • A requester may have at most 2 jobs queued or processing at once (BB_JOB_TOO_MANY_ACTIVE).
  • Job lists and job reads are scoped to the route's entity, not to the requester: any staff member with the read codes sees every job of that entity.
  • Cancel needs BB_Catalog_UPDATE plus the entity UPDATE, and answers 200 with the job. The code does not compare the caller with the requester, so any staff member holding those codes can cancel any job of that entity. A job that already finished answers 409 BB_JOB_NOT_CANCELLABLE.
  • Import limits: 5,000 data rows, 25 MiB file, 50 columns, .csv or .xlsx. XLSX adds 100 MiB uncompressed and 1,000 zip entries. Export limit: 50,000 rows.
  • Status values: queued, processing, completed, failed, cancelled.
  • A stuck job shows isStalled: true. A sweep every 5 minutes fails jobs that lost their lease or were never delivered.
  • lastError is never raw error text. A temporary failure that will be retried reads "The last attempt hit a temporary error; the job will be retried." A job that ran out of attempts reads "The job failed after its attempts ran out. Contact support with the job id." A rejected import or export carries its own fixed sentence, for example "Import rejected: 3 row(s) have errors; nothing was written."
  • The import source file is deleted as soon as the job ends: completed, failed, cancelled or swept. Re-upload the file to retry.
  • A finished export keeps its file: there is no expiry. The download answers 410 BB_JOB_RESULT_GONE only when the file is already missing from the API host.

Import files

Download the header row for an entity from GET .../import-template, fill it in and upload it. The header must contain exactly the template columns. Column order does not matter. A missing, unexpected or repeated column fails the job with one row-0 BB_JOB_FILE_INVALID error that lists what is wrong. The one extra column an import accepts is deletedAt, which an export with deleted rows writes. The import ignores it.

EntityColumns, in template order
CategorypublicId, name, parentPublicId, description, displayOrder
BrandpublicId, name, description, displayOrder
Brand seriespublicId, brandPublicId, name, description, displayOrder
Productsku, name, categoryPublicId, brandPublicId, brandSeriesPublicId, mrpPaisa, sellingPricePaisa, description, isActive

What a row does:

  • Categories, brands, series. A blank publicId creates a row. A publicId of a live row updates it. A category whose parentPublicId changed moves. The brand of an existing series cannot change. A publicId that is missing or deleted is a row error.
  • Products. The sku picks the row, compared case-insensitively. An unknown SKU creates a product with one default variant. The SKU of a product's default variant updates the product and that variant. The SKU of a non-default variant, or of a deleted product, is a row error.
  • Every row writes its normal audit entry (bb.category.create, bb.product.update and so on).

Cell rules:

ColumnRule
publicIdBlank, or a UUID in any case (stored lower-case)
nameRequired. Normalized to NFC and trimmed. At most 150 characters for categories, brands and series, 255 for products. Counted in code points
description (category, brand, series)Plain text, trimmed, at most 2,000 characters. Blank becomes null
description (product)HTML, run through the same sanitizer as the API. Too long, or nothing allowed left, is a row error
displayOrderBlank is 0. Otherwise 1 to 9 digits, so 0 to 999,999,999. This is wider than the API, which stops at 100,000
parentPublicId, brandPublicId (product), brandSeriesPublicIdBlank is null, otherwise a UUID. A series needs a brandPublicId
brandPublicId (series), categoryPublicIdRequired UUID
skuRequired. ^[A-Za-z0-9._/-]{1,64}$
mrpPaisa, sellingPricePaisaRequired. Whole paisa: 1 to 15 digits, no sign, decimal point or separator. At most 1,000,000,000,000. The selling price may not exceed the MRP
isActiveRequired. true or false in any case

Reading rules for both formats:

  • The CSV must be UTF-8. A leading byte-order mark is tolerated. XLSX reads the first sheet only.
  • Each cell loses leading and trailing whitespace, then exactly one leading ' is removed. The ' is the formula guard an export adds.
  • Blank lines are skipped. A cell beyond the header width is dropped. A short row reads the missing cells as blank.
  • row in an error is the data-row number, counted from 1. The header is row 0, and row: 0 marks an error about the whole file.

Round trip and carriage returns. Re-importing an export has two limits that come from the shared CSV reader. First, whitespace at the edge of an unguarded cell is trimmed. Second, a carriage return (CR) inside a cell comes back as a line feed (LF): the reader splits lines with Node readline, which treats a bare CR, a CRLF pair and a bare LF alike, then rejoins the pieces of a quoted cell with LF. The ' guard keeps a leading CR from being trimmed away, but the character that survives is an LF. XLSX cells are not affected.

All or nothing. The worker parses every row and every in-file duplicate first. A repeated name (scoped to the parent category or the brand), publicId or sku flags the later row with BB_IMPORT_ROW_DUPLICATE. If any error exists, nothing is written. Otherwise all rows write in one transaction. A write-time error rolls the whole job back, so a job never half-applies. A failed import has status: failed, one errors[] entry per bad cell (at most 500 kept; failedRows holds the true count), and processedRows equal to totalRows.

A row error carries row, column, errorCode and a fixed message that never repeats a cell value:

errorCodeRaised when
BB_IMPORT_ROW_INVALIDA cell fails its rule above, the file is not UTF-8, a category's parent is at the maximum depth, or a series changes brand
BB_IMPORT_ROW_DUPLICATEname, publicId or sku appeared on an earlier row
BB_IMPORT_ROW_CONFLICTA database uniqueness, reference or check rule rejected the row (column holds the constraint name), or the SKU belongs to a product that is deleted or changed during the run
BB_IMPORT_ROW_REFERENT_INVALIDcategoryPublicId, brandPublicId, brandSeriesPublicId, parentPublicId or an update target publicId does not refer to a live row
BB_IMPORT_ROW_MOVE_INVALIDA category move would form a cycle or pass the maximum depth
BB_IMPORT_ROW_SKU_NOT_DEFAULTThe SKU belongs to a variant that is not its product's default

A lock timeout, a deadlock or a serialization failure while writing a row is not a row error. The job is released and retried, up to the queue's attempt limit.

A file-level failure ends the job with one row-0 error: BB_JOB_FILE_INVALID (empty, unreadable, not a workbook, header wrong, unterminated quote, missing file) or BB_JOB_FILE_TOO_LARGE (over 5,000 rows, 50 columns, 25 MiB, or a workbook that expands past 100 MiB).

A 5,000-row product import completed in about 18 seconds wall time on the gate host, in a single transaction.

Export files

An export is a CSV with the import columns of the entity in the same order, plus deletedAt (ISO 8601, or empty) as the last column when includeDeleted is true. Rows come in ascending internal id, read 500 at a time. A product row uses its default live variant for sku, mrpPaisa and sellingPricePaisa (blank when it has none), and description is the stored HTML. Prices are paisa digits.

  • Formula guard. A cell whose first character is =, +, -, @, TAB, CR or ' gets a leading '. Fields containing a quote, comma, CR or LF are quoted with doubled quotes.
  • A matching count over 50,000 rows fails the submit with 400 BB_JOB_EXPORT_TOO_LARGE. If the data grows past it before the worker finishes, the job fails with the same code in errors[].
  • The file is written whole to a temporary part file and renamed into place, so a download never sees half a file. Cancelling the job stops the write at the next check, every 500 rows.

7. Error UX Mapping

SituationCodeSuggested admin behavior
Name already usedBB_CATEGORY_NAME_TAKEN, BB_BRAND_NAME_TAKEN, BB_BRAND_SERIES_NAME_TAKEN, BB_TAG_NAME_TAKENInline error on the name field
SKU already usedBB_VARIANT_SKU_TAKEN (details.sku)Inline error on the SKU field
Stale editBB_PRODUCT_VERSION_CONFLICT, BB_VARIANT_VERSION_CONFLICTReload the product and ask the user to re-apply
Blocked deleteBB_CATEGORY_HAS_CHILDREN, BB_CATEGORY_HAS_PRODUCTS, BB_BRAND_HAS_SERIES, BB_BRAND_HAS_PRODUCTS, BB_BRAND_SERIES_HAS_PRODUCTSSay what still depends on the row
Parent deleted on restoreBB_CATEGORY_PARENT_DELETED, BB_BRAND_DELETEDRestore the parent first
BusyBB_CATALOG_BUSYOffer a retry
Bulk partial failurefailed[].errorCodeShow per-row reasons from failed[].message
Reorder out of dateBB_REORDER_INVALID_ITEM (details.reason)Refetch siblings and retry
Too many active jobsBB_JOB_TOO_MANY_ACTIVETell the user to wait for a job to finish
Import rejectedjob status: failed; row 0 BB_JOB_FILE_INVALID or BB_JOB_FILE_TOO_LARGE; BB_IMPORT_ROW_* per cellList errors[] by row and column, and say nothing was written
Export file missingBB_JOB_RESULT_GONESay the file is gone and offer a new export

Enum values, error codes and permission codes are wire values. Map them to labels in the client. See the API page for the full error table.


8. See Also

  • Catalog API reference: catalog-api
  • Catalog backend architecture: catalog-backend
  • Phase 1 overview: feature