Nano Store - Ecommerce Docs
Developer Resourcesb2b-second-inventory

B2B Second Inventory Feature Overview

Phase 1 of the bb (B2B second inventory) area — a separate staff, role and customer surface with its own permissions and audit trail, kept apart from the retail admin.

B2B Second Inventory (bb) — Feature Overview

1. Purpose

The bb area is a second inventory for B2B selling, run by its own staff and kept invisible to the retail admin. Phase 1 ships the foundation only: bb roles, bb staff, bb permissions, bb customers, and an append-only audit trail of every bb write. Catalog and stock were added in phases 2 and 3 and have their own pages (catalog-*, inventory-*); orders and pricing for bb are later phases and are not documented here.

The admin screens that consume these endpoints are not part of this document.


2. Surface Matrix

SurfacePathAuth
Roles/api/admin/bb/rolesJWT + BB_Roles_*
Permissions catalog/api/admin/bb/permissionsJWT + BB_Roles_READ
Staff/api/admin/bb/staffJWT + BB_Staff_*
Customers/api/admin/bb/customersJWT + BB_Customers_*
Audit/api/admin/bb/auditJWT + BB_Audit_READ

Every route is admin-only and IP-throttled with RATE_LIMITS.ADMIN_READ (reads) or RATE_LIMITS.ADMIN_WRITE (writes). There is no public or storefront surface.


3. Who Can Do What

  • Superadmin manages bb roles and bb staff. BB_Roles and BB_Staff are not assignable to any bb role, so only superadmin (which bypasses the permission check) can reach /roles, /permissions and /staff.
  • bb roles can hold only BB_Audit_* and BB_Customers_* codes in phase 1.
  • A bb staff member with BB_Customers_* manages bb customers. BB_Customers_RESTORE is also required to list deleted customers.
  • A bb staff member with BB_Audit_READ reads the audit trail.

4. Business Rules

Separation from retail

  • bb roles and bb staff never appear in the retail /team, /roles and /permissions endpoints, and the retail endpoints cannot change them.
  • A retail role cannot be granted a BB_* permission.
  • A bb endpoint treats a retail role or a retail admin as if it does not exist.

Roles

  • Role names superadmin, admin and customer are reserved (case-insensitive).
  • A role cannot be deleted while any staff member holds it, banned staff included.
  • A staff member cannot rename, re-permission or delete their own role.

Staff

  • A staff member needs a name, an email, a password and a bb role. Phone is optional and must be E.164.
  • Ban requires a reason. A staff member cannot ban themselves, and superadmin cannot be banned.
  • Banning an already-banned member, or unbanning one who is not banned, returns success without writing an audit row.

Customers

  • A customer needs at least one of name, phone, companyName.
  • Phone is normalised to E.164 (default region NP). Email is lower-cased.
  • Live phone and email are unique. A soft-deleted customer does not hold its phone or email.
  • Delete is a soft delete. Restore can fail if a live customer now holds the phone or email; the caller may pass clearPhone or clearEmail to restore without it.

Audit

  • Every bb write (role, staff, customer) writes one audit row in the same transaction. If the audit insert fails, the write rolls back.
  • Audit rows cannot be updated or deleted.
  • Audit stores values only for a short allowlist of fields. Everything else is recorded as "changed" with no value, so phone numbers, emails, PAN/VAT numbers and notes never enter the trail.

5. Error UX Mapping

Error codeHTTPShow the user
BB_PERMISSION_NOT_ASSIGNABLE400Highlight the offending codes in details.codes
BB_ROLE_NOT_FOUND404 / 400"Role no longer exists" (400 when the role came from a request body)
BB_STAFF_NOT_FOUND404"Staff member not found"
ROLE_NAME_RESERVED403"That role name is reserved"
ROLE_NAME_ALREADY_EXISTS409Inline error on the name field
ROLE_IN_USE409"Reassign staff before deleting this role"
ROLE_SELF_TARGET_FORBIDDEN403"You cannot modify your own role"
TEAM_SELF_BAN_FORBIDDEN403"You cannot ban yourself"
BB_CUSTOMER_PHONE_TAKEN / BB_CUSTOMER_EMAIL_TAKEN409Inline error; offer the existing customer via details.conflictingPublicId
BB_CUSTOMER_IDENTITY_REQUIRED400"Enter a name, phone or company"
BB_CUSTOMER_PHONE_INVALID400Inline error on the phone field
BB_AUDIT_RANGE_INVALID400"Start date must be before end date"

Branch on errorCode, never on message.


See Also