Skip to content

fix(customers): match trunk-zero phone search - #1119

Merged
khaira777 merged 2 commits into
mainfrom
fm/flocafe-issue-1065-r1
Oct 13, 2026
Merged

khaira777 merged 2 commits into
mainfrom
fm/flocafe-issue-1065-r1

Conversation

@khaira777

@khaira777 khaira777 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Verify and implement the surgical fix for FreeOpenSourcePOS/FloCafe issue #1065 ("support local trunk prefix (leading zero) in customer phone search"): in main/routes/customers.ts, GET /api/customers?search=<query> misses customers stored in international E.164 format (e.g., +66899123456 -> phone_digits 66899123456) when searched using the domestic trunk-zero format (0899123456). Use the existing parsePhoneE164 helper with the configured default country to include the normalized E.164 digits candidate in phone search without blindly stripping leading zeros from arbitrary partial searches. Deliver via the no-mistakes pipeline as its own PR with Fixes #1065 in the PR summary.

What Changed

  • Updated GET /api/customers phone-like search in main/routes/customers.ts to parse the search query with parsePhoneE164 using the configured tenant country setting and include any distinct normalized E.164 digit sequence alongside the raw digit substring match.
  • Added integration tests in tests/phone-search-integration.test.ts verifying domestic trunk-zero search matching against E.164 stored numbers while preserving partial digit and non-trunk leading-zero search behavior.

Fixes #1065

Risk Assessment

✅ Low: The change is a small, well-bounded query enhancement in GET /api/customers using the existing parsePhoneE164 helper and store country setting, backed by integration tests covering trunk-zero, partial leading-zero, and non-trunk zero queries.

Testing

Stood up an isolated Express API server and SQLite database to drive GET /api/customers?search= end-to-end across domestic trunk-zero (0899123456 and 089-912-3456), partial leading-zero guard (0899), legitimate zero substring (0000), partial national digit (899123), and full E.164 (+66899123456) queries, and ran the focused phone search and validation test suites (test:phone-search-integration, test:customer-phone-search, test:phone, test:phone-validation) plus backend build; all scenarios and checks passed with API transcript evidence captured. No visual screenshot was captured because this change is strictly a backend SQL query parameter normalization in main/routes/customers.ts with no UI change.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Searching GET /api/customers?search=0899123456 (and formatted 089-912-3456) with default country TH returns the customer stored in E.164 format (+66899123456, phone_digits 66899123456) ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching a partial leading-zero prefix GET /api/customers?search=0899 does not blindly strip the leading zero and returns 0 false-positive matches against +66899123456 ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching legitimate zero substrings GET /api/customers?search=0000 preserves leading zeros and returns the customer whose stored E.164 phone contains 0000 (+541143210000) ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching partial national digits (899123), full E.164 (+66899123456), and digit-bearing names/emails (Alice 2, [email protected]) continues to return only the expected matching customers ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/phone-search-integration-output.txt
Evidence: Live API transcript for domestic trunk-zero customer phone search

{ "configuredCountry": "TH", "storedCustomersInDb": [ { "id": "cust-88289bd5-d678-4311-9da0-c0ccab27cc13", "name": "Carlos AR", "phone": "+541143210000", "phone_digits": "541143210000", "country_code": "+54" }, { "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813", "name": "Somchai TH", "phone": "+66899123456", "phone_digits": "66899123456", "country_code": "+66" } ], "scenarios": [ { "scenario": "Domestic trunk-zero search (0899123456)", "endpoint": "GET /api/customers?search=0899123456&per_page=10", "status": 200, "matchCount": 1 }, { "scenario": "Formatted domestic trunk-zero search (089-912-3456)", "endpoint": "GET /api/customers?search=089-912-3456&per_page=10", "status": 200, "matchCount": 1 }, { "scenario": "Partial leading-zero search guard (0899)", "endpoint": "GET /api/customers?search=0899&per_page=10", "status": 200, "matchCount": 0 }, { "scenario": "Legitimate zero substring search guard (0000)", "endpoint": "GET /api/customers?search=0000&per_page=10", "status": 200, "matchCount": 1 } ] }

{
  "configuredCountry": "TH",
  "storedCustomersInDb": [
    {
      "id": "cust-88289bd5-d678-4311-9da0-c0ccab27cc13",
      "name": "Carlos AR",
      "phone": "+541143210000",
      "phone_digits": "541143210000",
      "country_code": "+54"
    },
    {
      "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813",
      "name": "Somchai TH",
      "phone": "+66899123456",
      "phone_digits": "66899123456",
      "country_code": "+66"
    }
  ],
  "scenarios": [
    {
      "scenario": "Domestic trunk-zero search (0899123456)",
      "endpoint": "GET /api/customers?search=0899123456&per_page=10",
      "status": 200,
      "matchCount": 1,
      "matchedCustomers": [
        {
          "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813",
          "name": "Somchai TH",
          "phone": "+66899123456",
          "phone_digits": "66899123456"
        }
      ]
    },
    {
      "scenario": "Formatted domestic trunk-zero search (089-912-3456)",
      "endpoint": "GET /api/customers?search=089-912-3456&per_page=10",
      "status": 200,
      "matchCount": 1,
      "matchedCustomers": [
        {
          "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813",
          "name": "Somchai TH",
          "phone": "+66899123456",
          "phone_digits": "66899123456"
        }
      ]
    },
    {
      "scenario": "Partial leading-zero search guard (0899)",
      "endpoint": "GET /api/customers?search=0899&per_page=10",
      "status": 200,
      "matchCount": 0,
      "matchedCustomers": []
    },
    {
      "scenario": "Legitimate zero substring search guard (0000)",
      "endpoint": "GET /api/customers?search=0000&per_page=10",
      "status": 200,
      "matchCount": 1,
      "matchedCustomers": [
        {
          "id": "cust-88289bd5-d678-4311-9da0-c0ccab27cc13",
          "name": "Carlos AR",
          "phone": "+541143210000",
          "phone_digits": "541143210000"
        }
      ]
    },
    {
      "scenario": "Partial national digit search (899123)",
      "endpoint": "GET /api/customers?search=899123&per_page=10",
      "status": 200,
      "matchCount": 1,
      "matchedCustomers": [
        {
          "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813",
          "name": "Somchai TH",
          "phone": "+66899123456",
          "phone_digits": "66899123456"
        }
      ]
    },
    {
      "scenario": "International E.164 search (+66899123456)",
      "endpoint": "GET /api/customers?search=+66899123456&per_page=10",
      "status": 200,
      "matchCount": 1,
      "matchedCustomers": [
        {
          "id": "cust-13c64dfa-9e76-4ef9-9b5f-83256f86b813",
          "name": "Somchai TH",
          "phone": "+66899123456",
          "phone_digits": "66899123456"
        }
      ]
    }
  ]
}
Evidence: Phone search integration test suite output (54/54 passed)

> [email protected] test:phone-search-integration
> node tests/run-electron-node-test.cjs tests/phone-search-integration.test.ts

Integration: customer phone search bridges e164 + legacy + pretty
============================================================
[DB] Opening database at: /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-phone-search-int-LBWeDo/flo.db
[DB] Schema: v0 → v112
[DB] Triggering auto-backup before migrating v0 → v112...
[DB] Auto-backup before migrating v0 → v112 created at /var/folders/y_/1ltcxtwj0zd_w1dg9jv4jl580000gn/T/flo-phone-search-int-LBWeDo/backups/flo-backup-2026-10-13T20-59-33-394Z-pre-v0-to-v112.db
[DB] Install defaults loaded; first-run setup pending
[MIGRATION v23] normalized: 0, unparseable: 0
[MIGRATION v23] merged 0 duplicate customer(s)
[MIGRATION v23] verification: 0 customers, 0 still non-E.164
[MIGRATION v24] normalized: 0, unparseable: 0
[MIGRATION v25] backfilled addons for 0 order items (0 unparseable, skipped)
[MIGRATION v30] backfilled 0 order_item(s) still missing a normalized addons snapshot
[MIGRATION v30] Dropped order_items.addons — order_item_addons is now the only place selected addons live.
[MIGRATION v73] normalized 0 merchant template payload(s); 0 already canonical or left untouched
[DB] integrity_check: ok
[DB] foreign_key_check: clean
[Auth] Generated new JWT secret for this install
  ✓ search returns 200 for short digits
  ✓ digits "9876543210" matches e164 (got 1)
  ✓ e164 row returned for short query
  ✓ search returns 200 for intl digits
  ✓ intl digits match e164 (got 1)
  ✓ e164 row returned for intl query
  ✓ digit-equivalent formatted query matches legacy separators
  ✓ digit-equivalent formatted query returns the legacy row
  ✓ formatted phone query matches the existing customer
  ✓ formatted phone query returns the US customer
  ✓ search returns 200 for inactive digits
  ✓ inactive e164 row excluded by is_active = 1
  ✓ AR digits find ci-ar only (got 1)
  ✓ AR row is ci-ar
  ✓ US short digits "5551234567" find ci-us only after stripping parens (got 1)
  ✓ US pretty-format row matched for short query
  ✓ US intl digits "15551234567" find ci-us only (got 1)
  ✓ US pretty-format row matched for intl query
  ✓ name LIKE branch matches anita (got 3)
  ✓ list filter short query matches e164 (got 1)
  ✓ list returns e164
  ✓ list filter intl query excludes local (got 1)
  ✓ list returns e164 for intl query
  ✓ list filter formatted US query matches ci-us only
  ✓ list filter matches US row for formatted international query
  ✓ list filter formatted US local query matches ci-us only
  ✓ list filter matches US row for formatted local query
  ✓ list filter formatted India query matches ci-e164 only
  ✓ list filter matches India row for formatted query
  ✓ list filter matches legacy separators with digit-equivalent query
  ✓ list filter returns the legacy row for formatted query
  ✓ list filter US short query matches ci-us only (got 1)
  ✓ list filter matches US pretty-format row
  ✓ list filter US intl query matches ci-us only (got 1)
  ✓ list filter matches US pretty-format row for intl query
  ✓ list filter continues matching customer names
  ✓ name search returns Alice Smith
  ✓ list filter continues matching customer emails
  ✓ email search returns Alice Smith
  ✓ digit-bearing name search does not overmatch phone digits
  ✓ digit-bearing name search returns the named customer
  ✓ digit-bearing email search does not overmatch phone digits
  ✓ digit-bearing email search returns the emailed customer
  ✓ list filter preserves pagination
  ✓ list filter preserves ascending name sorting
  ✓ list filter preserves is_active = 1 filtering
  ✓ creates TH customer with E.164 phone
  ✓ domestic trunk-zero query "0899123456" matches +66899123456 (got 1)
  ✓ domestic trunk-zero query returns TH E.164 customer
  ✓ partial leading-zero query "0899" does not produce an incorrect match (got 0)
  ✓ partial digit query "899123" still matches +66899123456 (got 1)
  ✓ partial digit query returns TH E.164 customer
  ✓ non-trunk leading zeros "0000" are not stripped and match ci-ar (got 1)
  ✓ non-trunk zero query returns ci-ar (+541143210000)
[DB] Database closed

54/54 passed, 0 failed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Searching GET /api/customers?search=0899123456 (and formatted 089-912-3456) with default country TH returns the customer stored in E.164 format (+66899123456, phone_digits 66899123456) ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching a partial leading-zero prefix GET /api/customers?search=0899 does not blindly strip the leading zero and returns 0 false-positive matches against +66899123456 ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching legitimate zero substrings GET /api/customers?search=0000 preserves leading zeros and returns the customer whose stored E.164 phone contains 0000 (+541143210000) ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/issue-1065-api-transcript.json
Searching partial national digits (899123), full E.164 (+66899123456), and digit-bearing names/emails (Alice 2, [email protected]) continues to return only the expected matching customers ✅ pass live ~/.no-mistakes/evidence/01M4VGQR091T40PZQM3CBBQHB9/phone-search-integration-output.txt
  • npm run test:phone-search-integration
  • npm run test:customer-phone-search
  • npm run test:phone
  • npm run test:phone-validation
  • npm run build
  • Live HTTP verification against Express /api/customers?search= with SQLite store (TH trunk-zero 0899123456, formatted 089-912-3456, partial 0899 guard, 0000 substring guard, 899123 partial digits, +66899123456 E.164)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4af899ff-4f3c-4aae-99a7-30ad43cca2b2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@khaira777

Copy link
Copy Markdown
Contributor Author

@greptile review

@khaira777 khaira777 changed the title fix: match domestic trunk-zero phone numbers in customer search fix(customers): match E.164 phones on trunk-0 query Oct 13, 2026
@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium impact] Expands phone number matching in customer search.

The phone-search change appears sound, but the comment must meet the repository's explicit rule before merging.

Findings

  1. P2 Partial searches lack protection ▶
  2. P2 Heading breaks comment rule ▶

Summary

This PR lets GET /api/customers find international phone numbers when staff enter a complete domestic number with a leading zero.

  • Customer search matches domestic trunk-zero numbers to saved international phones.

Reviews (1) · Last reviewed commit: "fix(customers): match trunk-zero phone s..." · Reviewed by Greptile

Comment thread tests/phone-search-integration.test.ts Resolved
Comment thread tests/phone-search-integration.test.ts Resolved
@khaira777 khaira777 changed the title fix(customers): match E.164 phones on trunk-0 query fix(customers): match trunk-zero phone search Oct 13, 2026
@khaira777

Copy link
Copy Markdown
Contributor Author

The main phone-search fix looks good. Please address the two remaining Greptile findings before merging.

  1. Add a permanent integration test in tests/phone-search-integration.test.ts confirming that a partial leading-zero search such as 0899 does not produce an incorrect match, while the full local number 0899123456 matches the correct customer. This scenario was covered in live validation but is missing from the committed test suite.
  2. Remove Issue #1065 from the new test comment to comply with the AGENTS.md rule against historical issue references in code comments.

Keep existing international and partial phone-search behavior unchanged. Run the relevant tests and confirm they pass.

Please limit the changes to these findings. No unrelated formatting or refactoring.

@khaira777
khaira777 force-pushed the fm/flocafe-issue-1065-r1 branch from 89e013e to 780a73d Compare October 13, 2026 21:02
@khaira777 khaira777 changed the title fix(customers): match trunk-zero phone search fix: support local trunk prefix in customer phone search Oct 13, 2026
@khaira777 khaira777 changed the title fix: support local trunk prefix in customer phone search fix(customers): match trunk-zero phone search Oct 13, 2026
Normalize phone-like search queries via parsePhoneE164 with the configured store country so domestic trunk-zero queries match customers stored in international E.164 format without stripping leading zeros from arbitrary partial searches.

Fixes #1065
Add integration test confirming partial leading-zero queries (0899) do not produce false matches while full trunk-zero queries match, and remove the historical issue reference from the test comment.
@khaira777
khaira777 force-pushed the fm/flocafe-issue-1065-r1 branch from 780a73d to 20e0314 Compare October 13, 2026 22:11
@khaira777
khaira777 enabled auto-merge (squash) October 13, 2026 22:11
@khaira777
khaira777 merged commit 20d4469 into main Oct 13, 2026
23 checks passed
@khaira777
khaira777 deleted the fm/flocafe-issue-1065-r1 branch October 13, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(customers): support local trunk prefix (leading zero) in customer phone search

1 participant