Nano Store - Ecommerce Docs
Developer ResourcesPOS

POS Serial Numbers Features and Flows

Optional per-unit serial numbers recorded at the counter, the shared uniqueness rule, release on return, error codes, deploy order and the mistyped-serial runbook.

POS - Serial Numbers Features and Flows

A serial number identifies one physical unit (a phone IMEI, a laptop serial). A cashier can optionally record one per unit when a sale is completed at the counter. The serial is stored against the order the sale creates, so it is traceable for a warranty claim, a theft report or a recall.

1. Documentation Evidence

Source TypeFilesWhat Was Extracted
Utilapps/api/src/modules/order/shared/order-item-serial.util.tsNormalisation, character rule, count and duplicate checks, availability pre-check, insert, release, read.
POS utilapps/api/src/modules/pos/shared/pos-sale-serial.util.tsPer-line resolution on complete, order of checks.
POS release utilapps/api/src/modules/pos/shared/pos-counter-return-serial.util.tsCounter-return picks and refusals.
Servicespos-sale-completion.service.ts, order-counter-handover.service.ts, order-dispatch.service.tsWhere serials are checked and written.
DTOspos/admin/sale/dto/pos-sale-request.dto.ts, pos-sale-response.dto.ts, pos/admin/return/dto/create-pos-counter-return.dto.ts, pos/admin/sale-support/dto/pos-returnable.dto.ts, order/admin/order/dto/dispatch-order-admin.dto.tsRequest and response fields and validators.
Schemapackages/db/src/schema/order/order-item-serial.ts, migration 0073_order_item_serial_release.sqlColumns, indexes, CHECKs.
Error codesapps/api/src/common/types/error-codes.tsThe five serial codes.
POS appnano-store-pos/src/renderer/src/features/sale/serials/, features/returns/return-serial-picker.tsxCashier behaviour.
Plan.omc/plans/pos-serial-numbers/master-plan.md (D5, R4-R6)Release rules and follow-ups.

2. Feature Summary

FieldValue
ModulePOS (shared table and util owned by order)
Primary user valueTrace a specific sold unit after the sale.
ActorsCashier (admin with Pos_CREATE / Pos_UPDATE), dispatching admin, customer (reads own order).
Main entry pointsPOST /api/admin/pos/sales/{publicId}/complete, POST /api/admin/pos/sales/{publicId}/returns, POST /api/orders/{id}/shipments.
Main outputsRows in order_item_serial; serialNumbers / releasedSerialNumbers on the sale lines.

3. What a serial is

  • Optional free text, entered by the cashier at sale time. It is never entered at product creation, and there is no "requires serial" product flag.
  • One entry per unit, at most the line quantity. A line of three phones has up to three serials.
  • Stored one row per unit in order_item_serial, the same table retail dispatch already writes.
  • Normalised by one function for every writer: each entry is trimmed, blank entries are dropped, and each remaining entry must match ^[\x21-\x7E]{1,120}$ (printable ASCII, no internal space, 1 to 120 characters).
  • Case-sensitive: abc and ABC are different serials.

4. Uniqueness rule

A serial is unique per product among active serials, across retail dispatch and POS.

AspectRule
Scope(product_id, serial_number), not global. Two different products may carry the same string.
ActiveA row with released_at IS NULL. Enforced by the partial unique index uq_order_item_serial_product_serial_active.
ReleasedA released row is history and never blocks the same serial being recorded again.
DeletionRows are never deleted.
ChannelsRetail dispatch and POS share the table, so a serial recorded on one channel blocks the other.

Duplicates are refused in three layers: the in-request check, a pre-check SELECT on active rows before stock is reserved or an order number is consumed, and the unique index as the race guard.

5. Actor Matrix

ActorCan DoCannot DoAuth
CashierRecord serials on complete of a counter pickup; pick serials on a counter return.Record serials for a delivery sale; correct a recorded serial.Pos_CREATE (complete), Pos_UPDATE + PosReturns_CREATE (returns).
Dispatching adminRecord serials on POST /api/orders/{id}/shipments.—Orders_UPDATE.
CustomerSee serials on their own order.Write serials.Customer JWT.

No permission was added or changed.

6. Flows

6.1 Record at the counter (pickup)

Serials travel in the complete request. They are never stored on the draft.

Order of checks inside resolvePosLineSerials (this order is the contract):

  1. Normalise every entry and drop entries that normalise to nothing, so an all-blank entry never fails a delivery sale or names a missing line.
  2. Look up each linePublicId on the sale (lower-cased). Unknown line: 409 POS_SERIAL_LINE_NOT_FOUND.
  3. Any serial left on a sale whose goods are not handed over now: 409 POS_SERIALS_NOT_ALLOWED.
  4. At most one serial per unit, and none repeated within a product: 409 ORDER_SERIAL_COUNT_MISMATCH or 409 ORDER_SERIAL_ALREADY_RECORDED.
  5. Pre-check against active serials of the same product: 409 ORDER_SERIAL_ALREADY_RECORDED.

All of this runs before prices are checked, stock is reserved or an order number is taken, and the whole completion is one transaction. A refused serial rolls everything back and the sale stays a live draft.

6.2 Delivery sales

A sale whose goods do not leave with the customer now refuses serials. Record them when the order is dispatched, with POST /api/orders/{id}/shipments.

6.3 Dispatch (retail)

Same util, same rules. The request shape is unchanged: lines[].serialNumbers, at most 99 per line. Serials are checked across every line of the request, and an already-active serial is refused before the shipment exists.

6.4 Read

GET /api/admin/pos/sales/{publicId} and every route returning a sale carry two always-present arrays per line:

FieldMeaning
serialNumbersEvery serial recorded for the line, released or not. This is what was sold.
releasedSerialNumbersThe released subset.

Drafts return [] for both. The same serials appear on the order the sale created (admin order view and the customer's order), released ones included as history.

6.5 Release on return

A released serial can be sold again. Release happens in the same transaction as the return or failure.

TriggerReleasesReason stored
POS counter return that names serials in lines[].serialNumbersExactly the picked serials of that line.counter_return
POS counter return that makes a line fully returnedEvery remaining active serial of that line.order_return
Retail return accepted for the whole line (returnedQuantity + accepted >= deliveredQuantity)Every active serial of that line.order_return
Shipment marked failedEvery active serial of that shipment.shipment_failed
Shipment marked returned to senderEvery active serial of that shipment.shipment_returned_to_sender

Rules:

  • A partial retail return releases nothing. The inspect route takes no serial picks, so the system cannot know which unit came back. The serial stays active until a full-line return or a future admin feature releases it.
  • Counter-return picks are validated first. A pick that is not an active serial of that line is 409 POS_COUNTER_RETURN_NOT_ALLOWED with details.reason = "serial_not_on_line". More picks than units returned, or a repeated pick, is details.reason = "serial_count_exceeds_quantity". The serial itself is never echoed.
  • GET /api/admin/pos/sales/{publicId}/returnable lists each line's active serials in lines[].serialNumbers, always present, so the till can offer them for picking.
  • Releasing is idempotent: only rows with released_at IS NULL match.
  • Each release writes released_at, released_by_admin_id and release_reason.

7. Cashier experience (POS app)

Read from nano-store-pos; no code was changed.

  • Each cart row has a "Serials n/qty" control that opens one dialog. For a delivery sale the dialog cannot be opened (serialStore.openFor returns early) and the complete payload omits serials.
  • In the dialog the cashier scans or types a serial and presses Enter or Tab. The client applies the same rule as the server and refuses with copy such as "That serial number is already entered for this product." or "Every unit already has a serial number."
  • When the quantity of a line is lowered, the list is cut to the new quantity: the earliest entries are kept and the newest extras are dropped.
  • The same serial cannot be entered twice for one product across lines of the same sale.
  • The store holds one active sale at a time. Serials are not visible on another terminal and are lost on restart.
  • On a complete conflict the server names the clashing serials in details, and the dialog flags them "Already recorded".
  • The serials field is omitted from the complete request when nothing was entered or the sale is a delivery.
  • On the returns screen a checkbox picker lists the line's active serials ("Serial numbers coming back (n of qty)"); ticks are capped at the quantity being returned.
  • Serials print under the line's quantity row on the receipt as S/N: a, b, c, wrapped to at most four lines. Before validation the receipt data is clipped to 99 serials of 120 characters each, so a long list never fails the whole receipt. The receipt email does not include them.

8. Request shapes

8.1 POST /api/admin/pos/sales/{publicId}/complete

{
  "paymentReference": "TXN-88213",
  "serials": [
    {
      "linePublicId": "019ff590-0000-7000-8000-000000000131",
      "serialNumbers": ["356938035643809", " 356938035643817 "]
    }
  ]
}
FieldTypeRequiredValidation
serialsarrayNoAt most 100 entries; linePublicId must be unique across entries.
serials[].linePublicIduuid v7Yes@IsUUID("7"), lower-cased before validation.
serials[].serialNumbersstring arrayYesAt most 99 items; each at most 128 raw characters matching ^ *[\x21-\x7E]* *$. The util then trims and enforces 1 to 120.

{} stays a valid body. The second serial above is trimmed and accepted; "3569 3803" (internal space) or a non-ASCII value is refused.

8.2 Response (sale line excerpt)

The project envelope is { message, data, errorCode }. A sale read:

{
  "message": "Sale retrieved successfully",
  "errorCode": null,
  "data": {
    "publicId": "019ff590-0000-7000-8000-000000000101",
    "status": "picked_up",
    "items": [
      {
        "publicId": "019ff590-0000-7000-8000-000000000131",
        "productName": "Galaxy A55",
        "variantName": "8GB/256GB Navy",
        "quantity": 2,
        "serialNumbers": ["356938035643809", "356938035643817"],
        "releasedSerialNumbers": ["356938035643817"]
      }
    ]
  }
}

8.3 Returnable line and counter-return line

{
  "productPublicId": "018f1e2a-0000-7000-8000-000000000012",
  "variantPublicId": "019ff58f-0956-722f-80c9-b5d7fc484b08",
  "sold": 2,
  "returned": 1,
  "pending": 0,
  "returnable": 1,
  "unitNetMinor": 4500000,
  "serialNumbers": ["356938035643809"]
}
{
  "productPublicId": "018f1e2a-0000-7000-8000-000000000012",
  "variantPublicId": "019ff58f-0956-722f-80c9-b5d7fc484b08",
  "quantity": 1,
  "serialNumbers": ["356938035643809"]
}

serialNumbers on a counter-return line is optional, at most 99 items, same per-item validation as above. The serials are part of the idempotency hash, so the same Idempotency-Key with different picks is IDEMPOTENCY_KEY_CONFLICT.

9. Error codes

HTTPCodeWhenClient action
400ORDER_SERIAL_INVALIDAfter trimming, a serial is not 1 to 120 printable ASCII characters without spaces. Backstop to the DTO regex. details.index is the position; the value is never echoed.Validate the same rule client-side; highlight the entry at details.index.
409ORDER_SERIAL_COUNT_MISMATCHMore serials than units on a line.Cap inputs at the line quantity.
409ORDER_SERIAL_ALREADY_RECORDEDThe serial is active for the same product (details.conflicts), or entered twice in one request (details.duplicates). A race lost at the database returns details.conflicts: [].Highlight the named serials. Branch on errorCode, never on message.
409POS_SERIAL_LINE_NOT_FOUNDA linePublicId is not on the sale.Re-fetch the sale and re-sync.
409POS_SERIALS_NOT_ALLOWEDSerials sent on a sale that is not handed over now (delivery).Record them at dispatch.
409POS_COUNTER_RETURN_NOT_ALLOWEDdetails.reason is serial_not_on_line or serial_count_exceeds_quantity.Re-fetch /returnable and re-pick.

Example ORDER_SERIAL_ALREADY_RECORDED body:

{
  "statusCode": 409,
  "errorCode": "ORDER_SERIAL_ALREADY_RECORDED",
  "message": "One or more serial numbers are already recorded against another unit of the same product.",
  "details": {
    "conflicts": [
      {
        "productPublicId": "018f1e2a-0000-7000-8000-000000000012",
        "productName": "Galaxy A55",
        "serialNumber": "356938035643809"
      }
    ]
  }
}

Serials go in details, never in message, and serial exceptions carry no cause. AllExceptionsFilter returns details in the response body and its log lines carry only the message, cause message and stack, so serial values are not written to the server log.

10. Data model

Table order_item_serial (schema packages/db/src/schema/order/order-item-serial.ts).

ColumnNotes
public_iduuid v7, unique.
order_shipment_item_id, order_item_idFKs, ON DELETE CASCADE. order_item_id is denormalised for lookup.
variant_id, product_idFKs, ON DELETE RESTRICT. product_id is denormalised so the unique index can exist.
serial_numbervarchar(120), not blank.
recorded_by_admin_id, recorded_atWho and when.
released_at, released_by_admin_id, release_reasonNULL means active. Added by migration 0073.
Index / ConstraintPurpose
uq_order_item_serial_product_serial_activeUnique (product_id, serial_number) where released_at IS NULL.
idx_order_item_serial_product_serialFull non-unique twin; serves the product FK and the history lookup (warranty, theft).
idx_order_item_serial_released_by_admin_idServes the SET NULL of the releasing admin FK.
chk_order_item_serial_release_pairreleased_at and release_reason are both set or both NULL.
chk_order_item_serial_release_reasonReason is one of counter_return, order_return, shipment_failed, shipment_returned_to_sender.
chk_order_item_serial_released_by_requires_releasedAn admin is recorded only on a released row.
chk_order_item_serial_not_blankExisting.

11. Deploy order

  1. Migration 0073_order_item_serial_release. It runs SET LOCAL lock_timeout = '5s' and takes ACCESS EXCLUSIVE locks on order_item_serial while it adds constraints and builds three indexes. Deploy in a quiet window; a timeout aborts the whole batch and it can be re-run.
  2. The backend. It expects the release columns and the partial unique index that migration 0073 creates, so the migration must already be applied.
  3. The POS app. An old backend answers 400 to the unknown serials field, so the app must not ship first. The app omits the field when empty.

Admin and storefront can ship any time after step 2. Before it, the only effect is the stricter dispatch validation surfacing as 400.

Rollback: down/0073_order_item_serial_release.down.sql refuses once any serial has been released or a serial has duplicate history. A code-only rollback is safe.

12. Behaviour changes on existing routes

  • Dispatch (POST /api/orders/{id}/shipments): a serial with an internal space or a non-ASCII character used to be accepted and is now 400. More than 99 serials on a line is 400. A raw value of 121 to 128 characters is accepted when trimming brings it to 120 or fewer.
  • Dispatch duplicate message text changed; branch on errorCode.
  • Admin order and shipment views have no released flag; they list released serials as history.
  • A customer whose account a POS sale is attached to sees the device serials on their storefront order.

13. Runbook: a mistyped serial

There is no route to correct or delete a recorded serial. A typo blocks the real device's serial until the mistyped row is released.

  1. Find the row by who recorded it and when:

    SELECT id, order_item_id, product_id, serial_number, recorded_by_admin_id, recorded_at
    FROM order_item_serial
    WHERE released_at IS NULL
      AND recorded_by_admin_id = '<admin uuid>'
    ORDER BY recorded_at DESC;
  2. Release it through a return of that unit: a POS counter return that picks the serial, or a full-line return. This is the only supported release path.

  3. Record the correct serial on the next sale or dispatch.

Do not update or delete rows by hand in production.

14. Follow-ups (not built)

ItemNote
Correct or delete a serialNo route yet. Needs an irreversible-class review.
Release on a partial retail returnNeeds a serial picker in the admin inspect UI and a backend extension.
Admin UI to view or mark released serials, and a released flag in admin DTOsAdmin repo, other owner.
Serials on manual or WhatsApp orders and at WhatsApp pickup collectionNot recorded; the parameter exists.
Serials in the POS receipt emailNot included.
Residual 40P01 from unrelated lock orders surfaces as a 500Mapping to SYS_TRANSACTION_CONFLICT is a follow-up.

Consumer contract for the admin and storefront owners: .omc/plans/pos-serial-numbers/consumer-handoff.md.

See Also

  • API doc: /docs/developer/pos/api
  • Backend doc: /docs/developer/pos/backend
  • Features and flows doc: /docs/developer/pos/feature
  • Deploy notes: /docs/developer/pos/deploy
  • TDD: not yet published