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
| Surface | Path | Auth |
|---|---|---|
| Roles | /api/admin/bb/roles | JWT + BB_Roles_* |
| Permissions catalog | /api/admin/bb/permissions | JWT + BB_Roles_READ |
| Staff | /api/admin/bb/staff | JWT + BB_Staff_* |
| Customers | /api/admin/bb/customers | JWT + BB_Customers_* |
| Audit | /api/admin/bb/audit | JWT + 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_RolesandBB_Staffare not assignable to any bb role, so only superadmin (which bypasses the permission check) can reach/roles,/permissionsand/staff. - bb roles can hold only
BB_Audit_*andBB_Customers_*codes in phase 1. - A bb staff member with
BB_Customers_*manages bb customers.BB_Customers_RESTOREis also required to list deleted customers. - A bb staff member with
BB_Audit_READreads the audit trail.
4. Business Rules
Separation from retail
- bb roles and bb staff never appear in the retail
/team,/rolesand/permissionsendpoints, 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,adminandcustomerare 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
clearPhoneorclearEmailto 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 code | HTTP | Show the user |
|---|---|---|
BB_PERMISSION_NOT_ASSIGNABLE | 400 | Highlight the offending codes in details.codes |
BB_ROLE_NOT_FOUND | 404 / 400 | "Role no longer exists" (400 when the role came from a request body) |
BB_STAFF_NOT_FOUND | 404 | "Staff member not found" |
ROLE_NAME_RESERVED | 403 | "That role name is reserved" |
ROLE_NAME_ALREADY_EXISTS | 409 | Inline error on the name field |
ROLE_IN_USE | 409 | "Reassign staff before deleting this role" |
ROLE_SELF_TARGET_FORBIDDEN | 403 | "You cannot modify your own role" |
TEAM_SELF_BAN_FORBIDDEN | 403 | "You cannot ban yourself" |
BB_CUSTOMER_PHONE_TAKEN / BB_CUSTOMER_EMAIL_TAKEN | 409 | Inline error; offer the existing customer via details.conflictingPublicId |
BB_CUSTOMER_IDENTITY_REQUIRED | 400 | "Enter a name, phone or company" |
BB_CUSTOMER_PHONE_INVALID | 400 | Inline error on the phone field |
BB_AUDIT_RANGE_INVALID | 400 | "Start date must be before end date" |
Branch on errorCode, never on message.
See Also
Storage Service Setup
Central place to configure uploads for both local disk and object storage (S3-compatible) deployments used by `@nano-store/storage` and the Nest API module.
B2B Second Inventory Backend Architecture
Internal architecture of the bb phase 1 modules — composition, data model, separation invariants, audit, error contract and file map.