The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Direct partner ID search
Rafiee2e336628b6
diff --git a/apps/web/lib/api/partners/program-enrollment-query.ts b/apps/web/lib/api/partners/program-enrollment-query.tsindex 99a44f5ddc..86b38e0a27 100644--- a/apps/web/lib/api/partners/program-enrollment-query.ts+++ b/apps/web/lib/api/partners/program-enrollment-query.ts@@ -15,6 +15,15 @@ export function isExactEmailQuery(query: string): boolean {return /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/u.test(query);}+/**+ * A pasted partner ID, not a prefix of one. IDs are 24 or 25 characters after+ * `pn_` — verified against all 626,348 production documents — so a shorter+ * suffix is someone typing, and matching it exactly would return nothing.+ */+export function isExactPartnerIdQuery(query: string): boolean {+ return /^pn_[a-z0-9]{24,}$/iu.test(query);+}+/*** Email / search filters on `Partner` (exact email, exact partner ID, or full-text on email/name/company).*/@@ -32,7 +41,7 @@ export function buildPartnerEmailSearchWhere({if (isExactEmailQuery(search)) {return { email: search };}- if (search.startsWith("pn_")) {+ if (isExactPartnerIdQuery(search)) {return { id: search };}const q = sanitizeFullTextSearch(search);diff --git a/apps/web/lib/api/partners/search/build-search-query.ts b/apps/web/lib/api/partners/search/build-search-query.tsindex f945ab4795..f0951fbeb0 100644--- a/apps/web/lib/api/partners/search/build-search-query.ts+++ b/apps/web/lib/api/partners/search/build-search-query.ts@@ -1,3 +1,4 @@+import { isExactPartnerIdQuery } from "@/lib/api/partners/program-enrollment-query";import { getPartnersQuerySchemaExtended } from "@/lib/zod/schemas/partners";import * as z from "zod/v4";import {@@ -29,7 +30,11 @@ export function buildPartnerSearchCandidateQuery({// Exact email and tenant lookups remain database-only. The search provider// is responsible only for finding relevance-ranked free-text candidates.- if (!query || email || tenantId) {+ //+ // A pasted partner ID joins them, and unlike a complete email it needs no+ // fallback: the provider indexes the ID as a plain token, so a miss there is+ // the same miss the primary key already gave, without the round trip.+ if (!query || email || tenantId || isExactPartnerIdQuery(query)) {return null;}diff --git a/apps/web/tests/partners/partner-search-query.test.ts b/apps/web/tests/partners/partner-search-query.test.tsindex 6516ca8522..2d7c94b5f1 100644--- a/apps/web/tests/partners/partner-search-query.test.ts+++ b/apps/web/tests/partners/partner-search-query.test.ts@@ -27,4 +27,29 @@ describe("buildPartnerSearchCandidateQuery", () => {])("keeps %s on the database path", (_name, input) => {expect(buildPartnerSearchCandidateQuery(input)).toBeNull();});++ describe("pasted partner IDs", () => {+ it.each([+ ["24-char suffix, the production minimum", "pn_dlszeepb38rvcnrfbd0srkzb"],+ ["25-char suffix, the common case", "pn_1K0NM7HCN944PEMZ3CQPH43H8"],+ ])(+ "keeps %s on the database, which has it as a primary key",+ (_label, search) => {+ expect(+ buildPartnerSearchCandidateQuery({ programId: "prog_1", search }),+ ).toBeNull();+ },+ );++ it.each([+ ["a bare prefix", "pn_"],+ ["a partial ID", "pn_dls"],+ ["one character short of the minimum", "pn_dlszeepb38rvcnrfbd0srkz"],+ ["an ID with a space", "pn_dlszeepb38rvcnrfbd0srkzb other"],+ ])("sends %s to the provider", (_label, search) => {+ expect(+ buildPartnerSearchCandidateQuery({ programId: "prog_1", search }),+ ).toMatchObject({ query: search });+ });+ });});