Nano Store - Ecommerce Docs
Developer ResourcesPOS

POS Deploy Notes

Migrations 0070-0073, deploy order, env and nginx delta, the cashier role, POS client rollout, rollback and post-deploy checks for the counter till.

POS — Deploy Notes

These notes cover the POS release: migrations 0070_order_refund_method_counter, 0071_pos_counter_returns and 0072_pos_counter_walk_in_customer and 0073_order_item_serial_release, the permission changes, and the desktop client (nano-store-pos). Base setup lives in docs/vps-deployment-runbook.md; this page lists only what differs. That runbook is not committed to the repo.


1. Pre-deploy

Migrations

MigrationWhat it does
0070_order_refund_method_counterAppends card_reversal and qr_reversal to the order_refund_method enum (IF NOT EXISTS)
0071_pos_counter_returnsCreates the pos_counter_returns table
0072_pos_counter_walk_in_customerInserts the shared Counter Walk-in customer, fixed id 01a2076e-fe59-73dc-9d64-ee3ce2edb086
0073_order_item_serial_releaseAdds release columns to order_item_serial and swaps its full unique index for a partial one over unreleased rows

Replay all four against a production dump first. The replay is manual and uses the same rules as b2b-second-inventory/deploy.mdx section 1: a database name that does not look like production, and never a live app against it.

After migrating, check the walk-in row:

SELECT id, name, email, phone, status, banned
FROM customers
WHERE id = '01a2076e-fe59-73dc-9d64-ee3ce2edb086';

Expect one row: Counter Walk-in, email and phone NULL, status = 'active', banned = false.

A missing or edited row makes every POS sale answer 503 POS_COUNTER_CUSTOMER_MISSING. The application accepts the row only while it is not soft-deleted, active, not banned, and has no email and no phone. Do not rename it, give it a contact or ban it.

Deploy order

  1. Back up the database and prove the dump is readable (pg_restore --list).

  2. Migrate, then verify lineage:

    pnpm db:migrate
    echo $?
    pnpm --filter @nano-store/db db:verify-lineage
  3. Build:

    pnpm install --frozen-lockfile
    pnpm build
    pnpm build:docs
  4. Sync permissions. This release changes the permission catalogue. Run it after the build: the script reads the catalogue from the built @nano-store/db dist, so a run before the build sees the previous release's catalogue, prints Permissions are already up to date and inserts nothing.

    pnpm --filter @nano-store/api permissions:sync

    Expect Added N missing permissions on a release that adds a permission module. Permissions are read from the database, so this step needs no restart.

  5. Restart:

    pm2 restart ns-api
    pm2 restart ns-docs
  6. Create the cashier role (section 3).

  7. Roll out the POS installers (section 4).

Turbo and DATABASE_URL. pnpm db:migrate runs turbo -F @nano-store/db db:migrate, and turbo.json declares no env passthrough. A DATABASE_URL or DIRECT_DATABASE_URL exported in your shell may therefore not reach drizzle-kit, which then reads apps/api/.env instead. This matters when you point a replay at another database. Bypass turbo with the filtered command:

DIRECT_DATABASE_URL=postgresql://<user>@<host>:5432/<replay-db> pnpm --filter @nano-store/db db:migrate

drizzle.config.ts prefers DIRECT_DATABASE_URL over DATABASE_URL.


2. Env and nginx delta

No new env vars are required, no new process, no nginx change. Compare against docs/vps-deployment-runbook.md sections 9.1 and 13.1.

Env

KeyNeededNotes
POS_STORE_DISTRICT_IDOptionalDefaults to 1
POS_STORE_MUNICIPALITY_NAMEOptionalDefaults to Kathmandu
POS_STORE_WARDOptionalDefaults to 1 (max 40)
POS_STORE_STREETOptionalDefaults to Store Counter
POS_STORE_RECIPIENT_NAMEOptionalDefaults to Nano Store
POS_STORE_RECIPIENT_PHONEOptionalE.164, defaults to +9779800000000

Set real store values before real sales; the defaults are placeholders. Leave a key out rather than filling it with a placeholder (<district id> fails validation and the API refuses to boot).

KeyRequirement
RESEND_API_KEY, RESEND_DEFAULT_FROMReceipt email needs both. Sales succeed without them; receipts are silently not sent
API_RUNTIME_PROFILEKeep full. fast disables the scheduler: the outbox tick and the hourly draft sweep
API_BIND_HOST, INTERNAL_CLIENT_IP_TOKENConfirm both are present. The API refuses to boot in production without them (env.validation.ts:823-850)
PORTSet it explicitly. The defaults disagree: schema 3003, main.ts 5000, VPS 5002. Keep nginx proxy_pass equal to it

Nginx

The existing section 13.1 ns-api block already meets every POS requirement. Do not "improve" these away:

  • Forward Host, X-Real-IP, X-Forwarded-For and X-Forwarded-Proto.
  • Keep blanking X-Internal-Client-Ip and X-Internal-Client-Ip-Token.
  • Serve /health/live and /health/ready unprefixed, with no auth, rate limit or redirect. The POS pings /health/live every 15 s.
  • No redirects on the API host. POS requests use redirect: "error". The port-80 to 443 redirect is fine.
  • No websocket support is needed for POS.
  • POS body limits are 256 KB per request and 5 MB per response, with a 15 s timeout (nano-store-pos/src/shared/constants.ts: MAX_REQUEST_BODY_BYTES, MAX_RESPONSE_BODY_BYTES, API_TIMEOUT_MS). The existing client_max_body_size 25M and proxy_read_timeout 300s are well above them.

3. Roles

permissions:sync grants the POS modules only to superadmin and admin. Create a cashier role in the admin and grant it:

PermissionCovers
Pos_READConfig, customer and product lookup, sale list, detail and timeline, returnable lines
Pos_CREATECreate a sale, create a customer on a sale, complete a sale
Pos_UPDATEChange customer, lines, fulfilment and payment method on a draft; send the receipt email; load the customer's addresses
Pos_DELETECancel a sale
PosReturns_CREATERecord a counter return. Grant it only to staff who process returns

A counter return (POST /api/admin/pos/sales/:publicId/returns) needs Pos_UPDATE and PosReturns_CREATE.

Create one staff account per cashier so the audit trail names the person.


4. POS client rollout

  • Server. The packaged app defaults to https://api.nanostore.com.np (PRODUCTION_API_URL, nano-store-pos/src/shared/constants.ts:6). For another domain, change the constant and rebuild, or launch with --api-url=https://…, which logs the user out because the stored session belongs to the old server.

  • CORS and CSP. HTTP calls come from the Electron main process. No CORS applies and no CORS_ORIGINS entry is needed. Do not add the API to the CSP.

  • Unsigned installers. There is no auto-update; reinstall each till for a new version.

    • Windows: SmartScreen, "More info", then "Run anyway".

    • macOS: System Settings, Privacy & Security, "Open Anyway", or:

      xattr -dr com.apple.quarantine "/Applications/Nano Store POS.app"
  • Build commands (run in nano-store-pos):

    OSCommandWhere it runs
    Linuxpnpm package:linuxLinux
    Windowspnpm package:winWindows, or Linux with Wine
    macOSpnpm package:macA Mac only

    Build from a short path. NSIS makensis crashed from a path of about 190 characters.


Serial numbers: migration 0073

The POS serial-numbers feature adds 0073_order_item_serial_release. Deploy order: the migration, then the backend, then the POS app. The migration takes ACCESS EXCLUSIVE locks on order_item_serial with lock_timeout = 5s; run it in a quiet window and re-run it if it times out (it is all-or-nothing). Its down file refuses once any serial has been released. Details: /docs/developer/pos/serials.


5. Rollback

migrate-down.ts refuses production-looking URLs, so a production reversal is by hand with a backup taken first. The down files are in packages/db/src/migrations/down/.

Down fileBehaviour
0072_pos_counter_walk_in_customer.down.sqlRefuses while any pos_sale or order references the walk-in customer; otherwise deletes the row
0071_pos_counter_returns.down.sqlRefuses while pos_counter_returns holds any row; otherwise drops the table
0070_order_refund_method_counter.down.sqlA no-op (SELECT 1;). PostgreSQL has no DROP VALUE, so card_reversal and qr_reversal stay on the enum
0073_order_item_serial_release.down.sqlRefuses once any serial has been released or a serial has duplicate history

After the first POS sale or counter return the guards in 0071 and 0072 fire, and 0073 refuses once any serial is released or duplicate history exists, so the schema is forward-fix only after first use.

Code-only rollback after first use: leave the schema in place. pos_counter_returns stays, and returns already recorded lose their UI.


6. Verification after deploy

  1. Readiness:

    curl -s -o /dev/null -w '%{http_code}\n' https://api.nanostore.com.np/health/ready

    Expect 200.

  2. In the POS: log in as a cashier, ring up a sale, check the receipt email arrives, and find the sale in the sales list.

  3. Check that POS logins do not trigger the internal-peer warning. It should not appear:

    pm2 logs ns-api --lines 200 --nostream | grep -F 'login from internal peer without trusted client IP'
  4. Check the outbox does not accumulate stuck rows. Rows should leave pending within a scheduler tick.

This page was written without running these commands against a live server. Run them on staging first.