From 37042d857caf0bea30ed8b511928dbebcbb74b0b Mon Sep 17 00:00:00 2001 From: JOY <5027251+JOY@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:24:28 +0700 Subject: [PATCH 1/4] fix(importer): reject --audit-only with --apply in backfill-specs (#1856) * fix(importer): reject --audit-only with --apply in backfill-specs Fail closed in parseBackfillSpecsArgs, runBackfillSpecsCli, and runQuickSpecSyncAndAudit when --audit-only is combined with --apply, preserving the read-only --audit-only contract and preventing unscoped flagship seed writes. Refs #1854 * fix(importer): make runQuickSpecSyncAndAudit strictly read-only Reject truthy apply, only, expect, expectInserts, and insertMissing unconditionally at the entry of runQuickSpecSyncAndAudit and remove its legacy unscoped master_products update loop so delegating callers such as test-ai-enricher.ts --audit-only --apply also fail closed. Refs #1854 --- .../__tests__/backfill-specs-scope.test.ts | 156 ++++++++++++++++++ .../src/shopee/jobs/backfill-specs.ts | 127 ++++++++------ 2 files changed, 231 insertions(+), 52 deletions(-) diff --git a/apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts b/apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts index f7a8fe3e..b5602a78 100644 --- a/apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts +++ b/apps/importer/src/shopee/__tests__/backfill-specs-scope.test.ts @@ -6,11 +6,14 @@ import { } from '../flagship-seed-data.js'; import { parseBackfillSpecsArgs, + runBackfillSpecsCli, runMasterSpecsBackfill, runMasterSpecsBackfillWith, + runQuickSpecSyncAndAudit, selectOnlyScope, selectOnlySeeds, type BackfillSpecsDeps, + type BackfillSpecsOptions, } from '../jobs/backfill-specs.js'; import type { ProductSpecifications } from '@repo/shared-data'; import type { RateSupabaseClient } from '../types.js'; @@ -859,3 +862,156 @@ test('unscoped master scan paginates past 1000 rows via keyset fetchByKey (#1665 'second page queried via keyset gt(id, last)' ); }); + +test('--audit-only rejects --apply in either order and never executes apply: true (#1854)', async () => { + assert.deepEqual(parseBackfillSpecsArgs([]), { apply: false, auditOnly: false }); + assert.deepEqual(parseBackfillSpecsArgs(['--audit-only']), { apply: false, auditOnly: true }); + assert.deepEqual(parseBackfillSpecsArgs(['--apply']), { apply: true, auditOnly: false }); + assert.deepEqual(parseBackfillSpecsArgs(['--apply', '--only', APPROVED[0]!, '--expect', '1']), { + apply: true, + auditOnly: false, + only: [APPROVED[0]!], + expect: 1, + }); + + for (const argv of [ + ['--audit-only', '--apply'], + ['--apply', '--audit-only'], + ['--audit-only', '--only', APPROVED[0]!, '--apply', '--expect', '1'], + ['--only', APPROVED[0]!, '--apply', '--expect', '1', '--audit-only'], + ]) { + assert.throws( + () => parseBackfillSpecsArgs(argv), + /--apply does not combine with --audit-only/, + argv.join(' ') + ); + } + assert.throws( + () => parseBackfillSpecsArgs(['--audit-only', '--audit-only']), + /--audit-only is repeated/ + ); + + // CLI dispatcher rejects both flag orders before invoking either runner. + for (const argv of [ + ['--audit-only', '--apply'], + ['--apply', '--audit-only'], + ]) { + let called = false; + await assert.rejects( + runBackfillSpecsCli(argv, { + runQuickAudit: async () => { + called = true; + return 0; + }, + runBackfill: async () => { + called = true; + return null; + }, + }), + /--apply does not combine with --audit-only/, + argv.join(' ') + ); + assert.equal(called, false, `${argv.join(' ')} never reaches a runner`); + } + + // Defensive guard inside runBackfillSpecsCli even if parseArgs were bypassed. + let quickAuditCalled = false; + await assert.rejects( + runBackfillSpecsCli(['--audit-only'], { + parseArgs: () => ({ apply: true, auditOnly: true }), + runQuickAudit: async () => { + quickAuditCalled = true; + return 0; + }, + }), + /--apply does not combine with --audit-only/ + ); + assert.equal(quickAuditCalled, false); + + // Valid --audit-only dispatches with apply: false, auditOnly: true. + const quickCalls: Array = []; + const backfillCalls: BackfillSpecsOptions[] = []; + const auditCount = await runBackfillSpecsCli(['--audit-only'], { + runQuickAudit: async opts => { + quickCalls.push(opts); + return 42; + }, + runBackfill: async opts => { + backfillCalls.push(opts); + return null; + }, + }); + assert.equal(auditCount, 42); + assert.deepEqual(quickCalls, [{ apply: false, auditOnly: true }]); + assert.deepEqual(backfillCalls, []); + + // Valid scoped --apply dispatches to runBackfill only. + const scopedQuickCalls: Array = []; + const scopedBackfillCalls: BackfillSpecsOptions[] = []; + await runBackfillSpecsCli(['--apply', '--only', APPROVED[0]!, '--expect', '1'], { + runQuickAudit: async opts => { + scopedQuickCalls.push(opts); + return 0; + }, + runBackfill: async opts => { + scopedBackfillCalls.push(opts); + return null; + }, + }); + assert.deepEqual(scopedQuickCalls, []); + assert.deepEqual(scopedBackfillCalls, [{ apply: true, only: [APPROVED[0]!], expect: 1 }]); + + // Defensive guard at the entry of runQuickSpecSyncAndAudit fails closed before reading env/client. + const envKeys = [ + 'SUPABASE_URL', + 'NEXT_PUBLIC_SUPABASE_URL', + 'SUPABASE_SECRET_KEY', + 'NEXT_PUBLIC_SUPABASE_ANON_KEY', + 'SUPABASE_ANON_KEY', + ]; + const saved = Object.fromEntries(envKeys.map(k => [k, process.env[k]])); + for (const k of envKeys) delete process.env[k]; + try { + for (const badOptions of [ + { auditOnly: true, apply: true }, + { apply: true }, + { apply: true, only: [APPROVED[0]!], expect: 1 }, + { auditOnly: 'true' as unknown as boolean, apply: true }, + { auditOnly: true, apply: 'true' as unknown as boolean }, + { apply: 1 as unknown as boolean }, + ]) { + await assert.rejects( + runQuickSpecSyncAndAudit(badOptions), + /--apply does not combine with --audit-only/, + JSON.stringify(badOptions) + ); + } + for (const badScoped of [ + { auditOnly: true, only: [APPROVED[0]!] }, + { only: [APPROVED[0]!] }, + { auditOnly: true, expect: 1 }, + { expect: 1 }, + { auditOnly: true, expectInserts: 0 }, + { expectInserts: 0 }, + ]) { + await assert.rejects( + runQuickSpecSyncAndAudit(badScoped), + /--only, --expect and --expect-inserts do not combine with --audit-only/, + JSON.stringify(badScoped) + ); + } + for (const badInsertMissing of [ + { auditOnly: true, insertMissing: true }, + { insertMissing: true }, + { insertMissing: 'true' as unknown as boolean }, + ]) { + await assert.rejects( + runQuickSpecSyncAndAudit(badInsertMissing), + /--insert-missing does not combine with --audit-only/, + JSON.stringify(badInsertMissing) + ); + } + } finally { + for (const k of envKeys) if (saved[k] !== undefined) process.env[k] = saved[k]; + } +}); diff --git a/apps/importer/src/shopee/jobs/backfill-specs.ts b/apps/importer/src/shopee/jobs/backfill-specs.ts index 6823defa..96a5f8a4 100644 --- a/apps/importer/src/shopee/jobs/backfill-specs.ts +++ b/apps/importer/src/shopee/jobs/backfill-specs.ts @@ -25,7 +25,8 @@ * between the dry run and the apply cannot pass as an update (DOS/Rate#1739). * A scoped run only updates existing masters: a named key with no master row stops an * --apply before any write (a dry run warns). Any unknown argument, `--flag=value` or a - * repeated flag fails. Neither flag combines with --audit-only. The read-only catalog + * repeated flag fails. None of --apply, --only, --expect, --expect-inserts or + * --insert-missing combines with --audit-only. The read-only catalog * audit still runs at the end, so a scoped --apply can exit 1 after its writes when an * unrelated master fails the audit: read the log, not only the exit code. * @@ -184,7 +185,7 @@ export function specUpdateChanges( /** * The spec columns a seed writes onto its existing master: specs and key specs merged into * the stored ones, minus the seed's retracted paths, and for a replaced seed its variant - * name and value columns. Shared by the full backfill and the quick sync, so neither keeps a retracted value. + * name and value columns. Ensures no seed update keeps a retracted value. */ export function seedMasterSpecUpdate( existing: { specifications?: unknown; key_specs?: unknown } | null | undefined, @@ -578,6 +579,9 @@ export function parseBackfillSpecsArgs(argv: readonly string[]): BackfillSpecsAr } expectInserts = Number(expectInsertsRaw.trim()); } + if (auditOnly && apply) { + throw new Error('--apply does not combine with --audit-only'); + } if (auditOnly && (only !== undefined || expect !== undefined || expectInserts !== undefined)) { throw new Error('--only, --expect and --expect-inserts do not combine with --audit-only'); } @@ -1248,11 +1252,28 @@ export async function runMasterSpecsBackfillWith( }; } +/** + * Read-only quick spec audit (`--audit-only`). Fails closed before loading the Supabase + * client if `apply` or any scoped/write flag is passed, including from delegating callers + * such as `test-ai-enricher.ts --audit-only`. + */ export async function runQuickSpecSyncAndAudit( - options: BackfillSpecsOptions = {} + options: BackfillSpecsOptions & { readonly auditOnly?: boolean } = {} ): Promise { if (!options || typeof options !== 'object' || Array.isArray(options)) options = {}; - const apply = options.apply === true; + if (options.apply) { + throw new Error('--apply does not combine with --audit-only'); + } + if ( + options.only !== undefined || + options.expect !== undefined || + options.expectInserts !== undefined + ) { + throw new Error('--only, --expect and --expect-inserts do not combine with --audit-only'); + } + if (options.insertMissing) { + throw new Error('--insert-missing does not combine with --audit-only'); + } const { createClient } = await import('@supabase/supabase-js'); const rawSupabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL; const supabaseKey = ( @@ -1271,41 +1292,56 @@ export async function runQuickSpecSyncAndAudit( }) ); - if (apply) { - for (const seed of FLAGSHIP_DEVICES_TO_SEED) { - const { data: existingRow, error: lookupErr } = await supabase - .from('master_products') - .select('id, key_specs, specifications') - .eq('model_key', seed.model_key) - .maybeSingle(); - if (lookupErr) { - throw new Error(`Failed to look up master product ${seed.model_key}: ${lookupErr.message}`); - } - const { error: upErr } = await supabase - .from('master_products') - .update({ - ...seedMasterSpecUpdate( - existingRow as { specifications?: unknown; key_specs?: unknown } | null, - seed - ), - updated_at: new Date().toISOString(), - }) - .eq('model_key', seed.model_key); - if (upErr) { - throw new Error(`Failed to sync specs of ${seed.model_key}: ${upErr.message}`); - } - } - } - const total = await auditMasterSpecs(supabase); logger.info( 'backfill.audit_passed', - `SPEC CLOUD AUDIT PASSED [mode=${apply ? 'APPLY' : 'AUDIT-ONLY'}]: ${total}/${total} master products on Supabase Cloud verified with 10/10 Field Groups (main camera, and a second camera unless single-camera).`, - { apply, totalAudited: total } + `SPEC CLOUD AUDIT PASSED [mode=AUDIT-ONLY]: ${total}/${total} master products on Supabase Cloud verified with 10/10 Field Groups (main camera, and a second camera unless single-camera).`, + { apply: false, totalAudited: total } ); return total; } +export interface BackfillSpecsCliRunners { + readonly parseArgs?: (argv: readonly string[]) => BackfillSpecsArgs; + readonly runQuickAudit?: ( + options: BackfillSpecsOptions & { readonly auditOnly?: boolean } + ) => Promise; + readonly runBackfill?: (options: BackfillSpecsOptions) => Promise; +} + +/** + * Parses CLI arguments and dispatches to the read-only quick audit (`--audit-only`) or the + * master spec backfill. Fails closed if `auditOnly` and `apply` ever appear together. + */ +export async function runBackfillSpecsCli( + argv: readonly string[], + runners: BackfillSpecsCliRunners = {} +): Promise { + const parseArgs = runners.parseArgs ?? parseBackfillSpecsArgs; + const args = parseArgs(argv); + if (args.auditOnly) { + if (args.apply) { + throw new Error('--apply does not combine with --audit-only'); + } + if (args.only !== undefined || args.expect !== undefined || args.expectInserts !== undefined) { + throw new Error('--only, --expect and --expect-inserts do not combine with --audit-only'); + } + if (args.insertMissing) { + throw new Error('--insert-missing does not combine with --audit-only'); + } + const runQuickAudit = runners.runQuickAudit ?? runQuickSpecSyncAndAudit; + return runQuickAudit({ apply: false, auditOnly: true }); + } + const runBackfill = runners.runBackfill ?? runMasterSpecsBackfill; + return runBackfill({ + apply: args.apply, + ...(args.only !== undefined ? { only: args.only } : {}), + ...(args.expect !== undefined ? { expect: args.expect } : {}), + ...(args.expectInserts !== undefined ? { expectInserts: args.expectInserts } : {}), + ...(args.insertMissing ? { insertMissing: true } : {}), + }); +} + const isDirectExecution = typeof process !== 'undefined' && Array.isArray(process.argv) && @@ -1315,24 +1351,11 @@ const isDirectExecution = if (isDirectExecution) { dotenv.config({ quiet: true }); dotenv.config({ path: '../../.env', quiet: true }); - Promise.resolve() - .then((): Promise => { - const args = parseBackfillSpecsArgs(process.argv.slice(2)); - return args.auditOnly - ? runQuickSpecSyncAndAudit({ apply: args.apply }) - : runMasterSpecsBackfill({ - apply: args.apply, - ...(args.only !== undefined ? { only: args.only } : {}), - ...(args.expect !== undefined ? { expect: args.expect } : {}), - ...(args.expectInserts !== undefined ? { expectInserts: args.expectInserts } : {}), - ...(args.insertMissing ? { insertMissing: true } : {}), - }); - }) - .catch((err: unknown) => { - logger.error( - 'backfill.fatal', - `Spec backfill/audit execution failed: ${err instanceof Error ? err.message : String(err)}` - ); - process.exit(1); - }); + runBackfillSpecsCli(process.argv.slice(2)).catch((err: unknown) => { + logger.error( + 'backfill.fatal', + `Spec backfill/audit execution failed: ${err instanceof Error ? err.message : String(err)}` + ); + process.exit(1); + }); } From 4aefe8b7ae57f0a25942f42c5912a4ba7eb61fa1 Mon Sep 17 00:00:00 2001 From: JOY <5027251+JOY@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:28:41 +0700 Subject: [PATCH 2/4] fix(importer): harden review jobs against NaN cap and proto keys (#1857) * fix(importer): harden review jobs against NaN cap and proto keys Closes #1853 * fix(importer): close review-gate path, overflow, and weight bounds --- .../shopee/__tests__/review-ai-points.test.ts | 284 +++++++++++++++++- .../shopee/__tests__/review-values.test.ts | 45 +++ .../src/shopee/jobs/review-ai-points.ts | 106 +++++-- .../importer/src/shopee/jobs/review-values.ts | 17 +- apps/importer/src/shopee/logger.ts | 54 ++-- .../src/shopee/product-points-ai-prompt.ts | 4 +- apps/importer/src/shopee/review-ai-prompt.ts | 16 +- 7 files changed, 476 insertions(+), 50 deletions(-) diff --git a/apps/importer/src/shopee/__tests__/review-ai-points.test.ts b/apps/importer/src/shopee/__tests__/review-ai-points.test.ts index 95020586..0f4d6d8e 100644 --- a/apps/importer/src/shopee/__tests__/review-ai-points.test.ts +++ b/apps/importer/src/shopee/__tests__/review-ai-points.test.ts @@ -1,6 +1,13 @@ import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; -import { comparablePoint, storedPoint } from '@repo/shared-data/rules'; +import { + comparablePoint, + storedPoint, + type PointCluster, + type PointLine, +} from '@repo/shared-data/rules'; +import { sanitizeAiGeneratedText } from '../logger.js'; +import { mergeAndSelectAiProductPoints } from '../product-points-ai-prompt.js'; import { batchCostUsd, checkReviewPoints, @@ -20,9 +27,12 @@ import { collectBatch, dosAiReviewAiClient, fromDosAiOutputLine, + monthSpendUsd, parseReviewAiPointsArgs, qualityStop, runReviewAiPointsJob, + storeAiRows, + type AiBatchRow, type AiMarkerRow, type AiReviewRow, type AiStoreRow, @@ -1096,6 +1106,277 @@ function fakeSupabase(seed: Record) { return { client: client as unknown as RateSupabaseClient, tables, stores, writes, rpcs, state }; } +async function testHardening1853() { + const now = new Date('2026-11-20T00:00:00Z'); + const mkBatch = (extra: Partial = {}): AiBatchRow => ({ + id: 'batch_harden01', + model: 'dos', + prompt_version: REVIEW_AI_PROMPT_VERSION, + status: 'stored', + manifest: [], + reserved_usd: 0.01, + cost_usd: 1.25, + submitted_at: '2026-11-02T00:00:00Z', + stored_at: '2026-11-02T01:00:00Z', + ...extra, + }); + + // 1) monthSpendUsd & runReviewAiPointsJob: non-finite values fail closed (Infinity, never NaN), + // negative values cannot subtract from spend, and +00:00 month start is counted. + for (const bad of [ + mkBatch({ cost_usd: 'NaN', reserved_usd: 0.01 }), + mkBatch({ cost_usd: Number.NaN, reserved_usd: 0.01 }), + mkBatch({ cost_usd: null, reserved_usd: 'NaN' }), + mkBatch({ cost_usd: null, reserved_usd: null as unknown as number }), + mkBatch({ cost_usd: null, reserved_usd: -1 }), + mkBatch({ cost_usd: Number.POSITIVE_INFINITY, reserved_usd: 0.01 }), + mkBatch({ cost_usd: 'Infinity', reserved_usd: 0.01 }), + mkBatch({ cost_usd: '-Infinity', reserved_usd: 0.01 }), + mkBatch({ cost_usd: '', reserved_usd: 0.01 }), + ]) { + const spend = monthSpendUsd([bad, mkBatch({ id: 'batch_neg', cost_usd: -50 })], 'dos', now); + assert.equal(Number.isNaN(spend), false, 'monthSpendUsd must never be NaN'); + assert.equal(spend, Number.POSITIVE_INFINITY, 'malformed row fails closed to +Infinity'); + + const db = fakeSupabase({ + reviews: [review(1)], + review_points: [], + review_ai_extractions: [], + review_ai_batches: [bad], + products: listings, + master_products: masters, + categories, + }); + const ai = fakeAi(() => []); + const res = await runReviewAiPointsJob(db.client, { + apply: true, + enabled: true, + ai: ai.client, + now, + }); + assert.equal(res.capped, true, 'malformed batch row must cap the run'); + assert.equal(res.sent, 0); + assert.equal(ai.calls.length, 0, 'capped run makes zero model calls'); + } + + assert.equal( + monthSpendUsd( + [ + mkBatch({ id: 'b1', cost_usd: 4.5 }), + mkBatch({ id: 'b2', cost_usd: -10, reserved_usd: 0 }), + mkBatch({ id: 'b3', cost_usd: -2, reserved_usd: 0.4 }), + ], + 'dos', + now + ), + 4.9, + 'negative cost_usd falls back to positive reserved_usd or 0 and never subtracts' + ); + assert.equal( + monthSpendUsd( + [mkBatch({ model: 'dos ', submitted_at: '2026-11-01T00:00:00+00:00', cost_usd: 2.25 })], + 'dos', + now + ), + 2.25, + 'PostgREST +00:00 timestamp at month start and padded model are included' + ); + + // 2) batchCostUsd rejects Infinity / -Infinity / NaN / negative token counts, prototype model + // keys, and does not overflow to Infinity or $0 on huge finite token counts. + assert.equal( + batchCostUsd('dos', { + input_tokens: Number.POSITIVE_INFINITY, + output_tokens: Number.NaN, + cache_read_input_tokens: Number.NEGATIVE_INFINITY, + cache_creation_input_tokens: -1000, + }), + 0 + ); + assert.equal(batchCostUsd('toString' as never, { input_tokens: 1000 }), 0); + const maxValCost = batchCostUsd('qwen3.8-max', { output_tokens: Number.MAX_VALUE }); + assert.ok(Number.isFinite(maxValCost) && maxValCost > 0); + const hugeCollected = collectBatch( + { + id: 'batch_huge', + model: 'dos', + prompt_version: REVIEW_AI_PROMPT_VERSION, + manifest: [ + { custom_id: 'r1', category: 'smartphones', criteria_version: 1, reviews: [] }, + { custom_id: 'r2', category: 'smartphones', criteria_version: 1, reviews: [] }, + ], + }, + [ + { custom_id: 'r1', ...answer([], 'end_turn', { input_tokens: 1e308, output_tokens: 1e308 }) }, + { custom_id: 'r2', ...answer([], 'end_turn', { input_tokens: 1e308, output_tokens: 1e308 }) }, + ], + new Map() + ); + assert.ok(Number.isFinite(hugeCollected.costUsd) && hugeCollected.costUsd > 0); + assert.equal( + batchCostUsd('dos', { + input_tokens: 1_000_000, + output_tokens: Number.POSITIVE_INFINITY, + }), + batchCostUsd('dos', { input_tokens: 1_000_000, output_tokens: 0 }) + ); + + // 3) Prototype-key guards in storeAiRows and mergeAndSelectAiProductPoints (byCriterion). + const protoRpcPayload = JSON.parse( + '{"__proto__":7,"constructor":9,"toString":11,"valueOf":3,"stored":4,"empty":"Infinity","rejected":-2}' + ) as Record; + const rpcClient = { + rpc: () => Promise.resolve({ data: protoRpcPayload, error: null }), + } as unknown as RateSupabaseClient; + const dummyRow: AiStoreRow = { + id: id(1), + text_hash: 'h1', + prompt_version: REVIEW_AI_PROMPT_VERSION, + criteria_version: 1, + category: 'smartphones', + model: 'dos', + batch_id: 'batch_01', + failed: false, + rejected: 0, + points: [], + }; + const counts = await storeAiRows(rpcClient, [dummyRow]); + assert.equal(Object.getPrototypeOf(counts), Object.prototype); + assert.equal(Object.hasOwn(counts, '__proto__'), false); + assert.equal(Object.hasOwn(counts, 'constructor'), false); + assert.equal(Object.hasOwn(counts, 'toString'), false); + assert.equal(Object.hasOwn(counts, 'valueOf'), false); + assert.equal(counts.toString, Object.prototype.toString); + assert.equal(counts.stored, 4); + assert.equal(counts.empty, 0); + assert.equal(counts.rejected, 0); + + const protoKeys = ['__proto__', 'constructor', 'toString', 'battery'] as const; + const pLines: PointLine[] = []; + const pClusters: PointCluster[] = []; + protoKeys.forEach((critKey, idx) => { + const l1 = `pl-${idx}-1`; + const l2 = `pl-${idx}-2`; + pLines.push( + { + id: l1, + reviewId: 'r1', + writerId: 'w1', + kind: 'pro', + criterionKey: critKey, + body: 'pin dùng bền cả ngày', + weight: 1, + isExpert: false, + writtenAt: now, + method: 'writer', + }, + { + id: l2, + reviewId: 'r2', + writerId: 'w2', + kind: 'pro', + criterionKey: critKey, + body: 'pin dùng bền cả ngày', + weight: 1, + isExpert: false, + writtenAt: now, + method: 'writer', + } + ); + pClusters.push({ + key: `cluster-${idx}`, + criterionKey: critKey, + kind: 'pro', + label: 'Pin dùng bền cả ngày', + support: 2, + reviewerCount: 2, + aiReviewerCount: 0, + hasExpert: false, + firstSeen: now, + lastSeen: now, + lineIds: [l1, l2], + visible: true, + }); + }); + const merged = mergeAndSelectAiProductPoints(pClusters, pLines, [], now); + assert.equal(Object.getPrototypeOf(merged.byCriterion), null); + assert.equal( + (merged.byCriterion as Record).valueOf, + undefined, + 'unpopulated Object.prototype keys stay undefined' + ); + assert.equal(({} as Record).pros, undefined, 'Object.prototype untouched'); + for (const critKey of protoKeys) { + assert.equal(merged.byCriterion[critKey]?.pros.length, 1, `own bucket kept for ${critKey}`); + } + assert.equal(merged.shown.length, 4); + + // 4) UTF-16 surrogate safety in dosAiReviewAiClient and sanitizeAiGeneratedText. + const seenPaths: string[] = []; + const surrogateGateway = (async (url: string | URL | Request) => { + const path = String(url).replace('https://api.dos.me/v1', ''); + seenPaths.push(path); + if (path.startsWith('/batches/') && path.endsWith('/cancel')) { + return new Response(JSON.stringify({ status: 'cancelling' }), { status: 200 }); + } + if (path.startsWith('/batches/')) { + return new Response( + JSON.stringify({ status: 'completed', output_file_id: 'file_\uDC00_out' }), + { status: 200 } + ); + } + if (path.startsWith('/files/') && path.endsWith('/content')) { + return new Response('', { status: 200 }); + } + return new Response('missing', { status: 404 }); + }) as typeof fetch; + const surrogateClient = dosAiReviewAiClient( + 'dos_sk_test', + undefined, + surrogateGateway, + async () => {} + ); + assert.equal(await surrogateClient.batchStatus('batch_\uD800_bad'), 'ended'); + const drained: BatchResult[] = []; + for await (const item of surrogateClient.results('batch_\uD800_bad')) drained.push(item); + assert.equal(drained.length, 0); + await surrogateClient.cancelBatch('batch_\uDFFF_bad'); + assert.deepEqual(seenPaths, [ + '/batches/batch_%EF%BF%BD_bad', + '/batches/batch_%EF%BF%BD_bad', + '/files/file_%EF%BF%BD_out/content', + '/batches/batch_%EF%BF%BD_bad/cancel', + ]); + for (const badId of ['', ' ', '.', '..', 'a/b', 'a?b', 'a#b', 'a\\b', 'a\u0000b']) { + await assert.rejects(surrogateClient.batchStatus(badId), /Invalid dos\.ai resource identifier/); + await assert.rejects(surrogateClient.cancelBatch(badId), /Invalid dos\.ai resource identifier/); + } + + const cutPair = sanitizeAiGeneratedText('abcd😀', 5); + assert.equal(cutPair, 'abcd'); + assert.ok((cutPair as string & { isWellFormed(): boolean }).isWellFormed()); + assert.ok(cutPair.length <= 5); + + const cutEmojiAtOne = sanitizeAiGeneratedText('😀', 1); + assert.equal(cutEmojiAtOne, ''); + assert.ok((cutEmojiAtOne as string & { isWellFormed(): boolean }).isWellFormed()); + + const cutSpacePair = sanitizeAiGeneratedText('abcd 😀', 6); + assert.equal(cutSpacePair, 'abcd'); + assert.ok((cutSpacePair as string & { isWellFormed(): boolean }).isWellFormed()); + + const cutBoundedBoundary = sanitizeAiGeneratedText(`a${' '.repeat(4094)}😀`, 400); + assert.equal(cutBoundedBoundary, 'a'); + assert.ok((cutBoundedBoundary as string & { isWellFormed(): boolean }).isWellFormed()); + assert.equal(cutBoundedBoundary.includes('\uFFFD'), false); + + const loneInInput = sanitizeAiGeneratedText('abcd\uD800ef\uDC00', 5); + assert.ok((loneInInput as string & { isWellFormed(): boolean }).isWellFormed()); + assert.ok(loneInInput.length <= 5); + + console.log(' ✅ #1853 spend-cap NaN/Infinity, prototype keys, and UTF-16 surrogates verified'); +} + async function run() { console.log('Review AI points job'); testPrompt(); @@ -1103,6 +1384,7 @@ async function run() { testCollect(); await testJob(); await testDosAiClient(); + await testHardening1853(); } run().catch(err => { diff --git a/apps/importer/src/shopee/__tests__/review-values.test.ts b/apps/importer/src/shopee/__tests__/review-values.test.ts index 31258220..9f08c827 100644 --- a/apps/importer/src/shopee/__tests__/review-values.test.ts +++ b/apps/importer/src/shopee/__tests__/review-values.test.ts @@ -258,6 +258,51 @@ async function run() { assert.deepEqual(edge.get(M2)!.criteria_scores, { battery: { score: 4.133, weight_sum: 1.5, writers: 3 }, }); + // Hardening (#1853): NaN / Infinity in criteria_ratings, stars, or weights never reach BigInt, + // and prototype keys (__proto__, constructor, prototype) are ignored. + const protoCriteria = JSON.parse( + '{"__proto__":4,"constructor":4,"prototype":4,"battery":4}' + ) as Record; + const malformedRatings = expectedMasterRatings({ + reviews: [ + review(40, 'l2', { + rating_star: 5, + criteria_ratings: { + ...protoCriteria, + display: Number.NaN, + camera: Number.POSITIVE_INFINITY, + sound: Number.NEGATIVE_INFINITY, + }, + }), + review(41, 'l2', { + rating_star: 4, + criteria_ratings: { ...protoCriteria, display: Number.NaN }, + }), + review(42, 'l2', { + rating_star: Number.NaN, + criteria_ratings: { ...protoCriteria, display: Number.POSITIVE_INFINITY }, + }), + review(43, 'l2', { rating_exact: 'NaN', rating_star: 5 }), + review(44, 'l2', { rating_exact: Number.POSITIVE_INFINITY, rating_star: 5 }), + review(45, 'l2', { helpfulness_weight: Number.POSITIVE_INFINITY, rating_star: 5 }), + review(46, 'l2', { helpfulness_weight: 'NaN', rating_star: 5 }), + review(47, 'l2', { helpfulness_weight: Number.MAX_VALUE, rating_star: 5 }), + ], + listings, + values: new Map(), + }); + const m2Malformed = malformedRatings.get(M2)!; + assert.equal(Object.getPrototypeOf(m2Malformed.criteria_scores), Object.prototype); + assert.equal(Object.hasOwn(m2Malformed.criteria_scores, '__proto__'), false); + assert.equal(Object.hasOwn(m2Malformed.criteria_scores, 'constructor'), false); + assert.equal(Object.hasOwn(m2Malformed.criteria_scores, 'prototype'), false); + assert.deepEqual(Object.keys(m2Malformed.criteria_scores), ['battery']); + assert.equal(m2Malformed.criteria_scores.battery!.writers, 3); + assert.equal( + m2Malformed.rating_weight_sum, + 5, + 'only finite 1..5 star reviews count and huge finite weight clamps cleanly to 3' + ); assert.ok( !masterRatingMatches( { diff --git a/apps/importer/src/shopee/jobs/review-ai-points.ts b/apps/importer/src/shopee/jobs/review-ai-points.ts index 8a013180..f8dc2bc5 100644 --- a/apps/importer/src/shopee/jobs/review-ai-points.ts +++ b/apps/importer/src/shopee/jobs/review-ai-points.ts @@ -301,6 +301,21 @@ export function dosAiReviewAiClient( }; const json = async (path: string, init?: RequestInit, retry?: 'all' | 'throttled') => JSON.parse((await call(path, init, retry)).text) as T; + const normalizePathId = (value: unknown): string => { + if (typeof value !== 'string') throw new Error('Invalid dos.ai resource identifier.'); + const wellFormed = (value as string & { toWellFormed(): string }).toWellFormed().trim(); + if ( + !wellFormed || + wellFormed === '.' || + wellFormed === '..' || + wellFormed.length > 256 || + /[\s/?#\\\p{Cc}]/u.test(wellFormed) + ) { + throw new Error('Invalid dos.ai resource identifier.'); + } + return wellFormed; + }; + const encodePathId = (value: unknown): string => encodeURIComponent(normalizePathId(value)); return { async createBatch(requests) { const form = new FormData(); @@ -313,23 +328,24 @@ export function dosAiReviewAiClient( 'review-ai-points.jsonl' ); const file = await json<{ id: string }>('/files', { method: 'POST', body: form }); + const fileId = normalizePathId(file?.id); const batch = await json<{ id: string }>( '/batches', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ - input_file_id: file.id, + input_file_id: fileId, endpoint: '/v1/chat/completions', completion_window: '24h', }), }, 'throttled' ); - return { id: batch.id }; + return { id: normalizePathId(batch?.id) }; }, async batchStatus(id) { - const batch = await json<{ status: string }>(`/batches/${encodeURIComponent(id)}`); + const batch = await json<{ status: string }>(`/batches/${encodePathId(id)}`); if (batch.status === 'cancelling') return 'canceling'; return ['completed', 'failed', 'cancelled', 'expired'].includes(batch.status) ? 'ended' @@ -340,7 +356,7 @@ export function dosAiReviewAiClient( status?: string; output_file_id?: string | null; errmsg?: string | null; - }>(`/batches/${encodeURIComponent(id)}`); + }>(`/batches/${encodePathId(id)}`); if (!batch.output_file_id) { // Failed as a whole, or ended with no line run: nothing to store. throw new BatchGoneError( @@ -350,7 +366,7 @@ export function dosAiReviewAiClient( } let text: string; try { - text = (await call(`/files/${encodeURIComponent(batch.output_file_id)}/content`)).text; + text = (await call(`/files/${encodePathId(batch.output_file_id)}/content`)).text; } catch (err) { if (/ 404 /.test(String(err))) { throw new BatchGoneError(`dos.ai batch ${id}: its output file is gone (404)`, 'expired'); @@ -370,7 +386,7 @@ export function dosAiReviewAiClient( } }, async cancelBatch(id) { - await call(`/batches/${encodeURIComponent(id)}/cancel`, { method: 'POST' }); + await call(`/batches/${encodePathId(id)}/cancel`, { method: 'POST' }); }, }; } @@ -700,7 +716,12 @@ export function collectBatch( const message = result.result.message; for (const key of Object.keys(usage) as (keyof typeof usage)[]) { const n = Number(message.usage?.[key] ?? 0); - usage[key] += Number.isFinite(n) && n > 0 ? n : 0; + if (Number.isFinite(n) && n > 0) { + const next = usage[key] + n; + usage[key] = Number.isFinite(next) + ? Math.min(next, Number.MAX_SAFE_INTEGER) + : Number.MAX_SAFE_INTEGER; + } } if (message.stop_reason === 'end_turn') { const parsed = parseOutput(message) as { reviews?: unknown } | null; @@ -796,8 +817,13 @@ export async function storeAiRows( for (let attempt = 1; ; attempt++) { const { data, error } = await supabase.rpc('store_review_ai_points', { p_rows: part }); if (!error) { - for (const [key, n] of Object.entries((data ?? {}) as Record)) { - if (key in total) total[key as keyof StoreCounts] += Number(n) || 0; + if (data && typeof data === 'object' && !Array.isArray(data)) { + for (const [key, n] of Object.entries(data as Record)) { + if (Object.hasOwn(total, key)) { + const count = Number(n); + total[key as keyof StoreCounts] += Number.isFinite(count) && count > 0 ? count : 0; + } + } } break; } @@ -811,15 +837,54 @@ export async function storeAiRows( return total; } -const monthStart = (now: Date) => - new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)).toISOString(); +const monthStartMs = (now: Date) => Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1); + +function parseBatchUsd(raw: unknown): number | null { + if (raw === null || raw === undefined) return null; + if (typeof raw === 'number') { + return Number.isFinite(raw) ? raw : Number.POSITIVE_INFINITY; + } + if (typeof raw === 'string') { + const trimmed = raw.trim(); + if (!trimmed) return Number.POSITIVE_INFINITY; + const parsed = Number(trimmed); + return Number.isFinite(parsed) ? parsed : Number.POSITIVE_INFINITY; + } + return Number.POSITIVE_INFINITY; +} /** This month's spend of a model: reported cost, or the reserved ceiling while open. */ export function monthSpendUsd(batches: readonly AiBatchRow[], model: string, now: Date): number { - const start = monthStart(now); - return batches - .filter(b => b.model === model && b.submitted_at >= start) - .reduce((s, b) => s + Number(b.cost_usd ?? b.reserved_usd ?? 0), 0); + const startMs = monthStartMs(now); + if (!Number.isFinite(startMs) || typeof model !== 'string') return Number.POSITIVE_INFINITY; + const targetModel = model.trim(); + let total = 0; + for (const b of batches) { + if (!b || typeof b !== 'object') return Number.POSITIVE_INFINITY; + const rowModel = typeof b.model === 'string' ? b.model.trim() : ''; + if (rowModel !== targetModel) continue; + const submittedMs = + typeof b.submitted_at === 'string' ? Date.parse(b.submitted_at) : Number.NaN; + if (!Number.isFinite(submittedMs)) return Number.POSITIVE_INFINITY; + if (submittedMs < startMs) continue; + const cost = parseBatchUsd(b.cost_usd); + const reserved = parseBatchUsd(b.reserved_usd); + if (cost === Number.POSITIVE_INFINITY || reserved === Number.POSITIVE_INFINITY) { + return Number.POSITIVE_INFINITY; + } + if (cost === null) { + if (reserved === null || reserved < 0) return Number.POSITIVE_INFINITY; + total += reserved; + continue; + } + if (cost < 0) { + if (reserved === null || reserved < 0) return Number.POSITIVE_INFINITY; + total += reserved; + continue; + } + total += cost; + } + return total; } const BATCH_COLUMNS = @@ -1121,10 +1186,17 @@ export async function runReviewAiPointsJob( ); result.monthSpendUsd = monthSpendUsd(refreshed, model, now); const cap = REVIEW_AI_MODELS[model].monthlyCapUsd; - result.capped = requests.length > 0 && result.monthSpendUsd + result.reservedUsd > cap; + result.capped = + requests.length > 0 && + (!Number.isFinite(result.monthSpendUsd) || + !Number.isFinite(result.reservedUsd) || + result.monthSpendUsd + result.reservedUsd > cap); + const monthText = Number.isFinite(result.monthSpendUsd) + ? `$${result.monthSpendUsd.toFixed(4)}` + : 'non-finite (fail-closed)'; logger.info( 'review_ai.plan', - `${apply ? 'Sending' : 'Would send'} ${chosen.length} of ${candidates.length} due reviews in ${requests.length} requests; ceiling $${result.reservedUsd.toFixed(4)}, month $${result.monthSpendUsd.toFixed(4)} of $${cap}.`, + `${apply ? 'Sending' : 'Would send'} ${chosen.length} of ${candidates.length} due reviews in ${requests.length} requests; ceiling $${result.reservedUsd.toFixed(4)}, month ${monthText} of $${cap}.`, { apply, model, diff --git a/apps/importer/src/shopee/jobs/review-values.ts b/apps/importer/src/shopee/jobs/review-values.ts index c6e5e3e3..18caff94 100644 --- a/apps/importer/src/shopee/jobs/review-values.ts +++ b/apps/importer/src/shopee/jobs/review-values.ts @@ -346,6 +346,7 @@ export interface MasterRatingExpected { } const CRITERION_KEY = /^[a-z_]{2,32}$/; +const DISALLOWED_CRITERION_KEYS = new Set(['__proto__', 'constructor', 'prototype']); /** * P2's rating with P6's weight, per master (cluster_id scope): user reviews @@ -374,14 +375,15 @@ export function expectedMasterRatings(input: { review.reviewer_type !== 'user' || flag === null || flag.include_in_rating === false || - !(weight > 0) + !Number.isFinite(weight) || + weight <= 0 ) { continue; } const exact = review.rating_exact == null ? null : Number(review.rating_exact); const list = byMaster.get(masterId) ?? []; const factor = completenessWeightFactor(input.values.get(review.id)?.weightCompleteness); - const w = toUnits(weight, 100n) * toUnits(factor, V_UNIT); + const w = toUnits(Math.min(weight, 3), 100n) * toUnits(factor, V_UNIT); list.push({ // LEAST(3, helpfulness_weight x factor), as reviewRatingWeight, in millionths. w: w < 3n * W_UNIT ? w : 3n * W_UNIT, @@ -392,14 +394,21 @@ export function expectedMasterRatings(input: { } const out = new Map(); for (const [masterId, eligible] of byMaster) { - const rated = eligible.filter(e => e.star >= 1 && e.star <= 5); + const rated = eligible.filter(e => Number.isFinite(e.star) && e.star >= 1 && e.star <= 5); const sumW = rated.reduce((s, e) => s + e.w, 0n); const sumWS = rated.reduce((s, e) => s + e.w * toUnits(e.star, V_UNIT), 0n); const perKey = new Map(); for (const e of eligible) { if (!e.criteria || typeof e.criteria !== 'object' || Array.isArray(e.criteria)) continue; for (const [key, value] of Object.entries(e.criteria as Record)) { - if (!CRITERION_KEY.test(key) || typeof value !== 'number' || value < 1 || value > 5) { + if ( + !CRITERION_KEY.test(key) || + DISALLOWED_CRITERION_KEYS.has(key) || + typeof value !== 'number' || + !Number.isFinite(value) || + value < 1 || + value > 5 + ) { continue; } const acc = perKey.get(key) ?? { writers: 0, w: 0n, shown: 0n, ws: 0n }; diff --git a/apps/importer/src/shopee/logger.ts b/apps/importer/src/shopee/logger.ts index 538ab5ca..e3524522 100644 --- a/apps/importer/src/shopee/logger.ts +++ b/apps/importer/src/shopee/logger.ts @@ -129,6 +129,22 @@ export function computeRetryDelayMs( return Math.min(safeMaxDelayMs, half + jitter); } +const toWellFormedUtf16 = (value: string): string => + (value as string & { toWellFormed(): string }).toWellFormed(); + +function sliceUtf16WellFormed(value: string, maxUnits: number): string { + if (value.length <= maxUnits) return toWellFormedUtf16(value); + let end = maxUnits; + if (end > 0) { + const prev = value.charCodeAt(end - 1); + const next = value.charCodeAt(end); + if (prev >= 0xd800 && prev <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) { + end -= 1; + } + } + return toWellFormedUtf16(value.slice(0, end)); +} + /** * Sanitizes untrusted AI-generated output text (`ai_summary`, `pros`, `cons`, `reason`) * by stripping HTML tags, control characters, URLs, and phone/Zalo numbers to prevent @@ -140,26 +156,24 @@ export function sanitizeAiGeneratedText(raw: unknown, maxLen = 400): string { typeof maxLen === 'number' && Number.isFinite(maxLen) && maxLen >= 1 ? Math.min(Math.floor(maxLen), MAX_LOG_STRING_LENGTH) : 400; - const boundedInput = raw.slice(0, Math.max(safeMaxLen * 4, 4096)); - return ( - boundedInput - // `[^<>]` rather than `[^>]`: a run of unclosed '<' would otherwise be - // rescanned to the end of the string from each '<' (quadratic). - .replace(/<[^<>]*>/g, ' ') - // Strip explicit http(s):// and www. URLs - .replace(/\b(?:https?:\/\/|www\.)\S+/gi, '[link-removed]') - // Strip bare domain links with common TLDs/paths (e.g. bit.ly/xyz, shopee.vn/abc, t.me/xyz) - .replace( - /\b[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.(?:vn|com|net|org|io|me|ly|gg|co|shop|store|xyz|info)(?:\/\S*)?\b/gi, - '[link-removed]' - ) - // Strip Vietnamese phone / Zalo numbers (e.g. 0912345678, +84 912 345 678, 098.123.4567) - .replace(/(?:\+?84|0)\s*[1-9](?:[\s.-]*\d){7,9}\b/g, '[phone-removed]') - .replace(/\p{Cc}+/gu, ' ') - .replace(/\s+/g, ' ') - .trim() - .slice(0, safeMaxLen) - ); + const boundedInput = sliceUtf16WellFormed(raw, Math.max(safeMaxLen * 4, 4096)); + const cleaned = boundedInput + // `[^<>]` rather than `[^>]`: a run of unclosed '<' would otherwise be + // rescanned to the end of the string from each '<' (quadratic). + .replace(/<[^<>]*>/g, ' ') + // Strip explicit http(s):// and www. URLs + .replace(/\b(?:https?:\/\/|www\.)\S+/gi, '[link-removed]') + // Strip bare domain links with common TLDs/paths (e.g. bit.ly/xyz, shopee.vn/abc, t.me/xyz) + .replace( + /\b[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.(?:vn|com|net|org|io|me|ly|gg|co|shop|store|xyz|info)(?:\/\S*)?\b/gi, + '[link-removed]' + ) + // Strip Vietnamese phone / Zalo numbers (e.g. 0912345678, +84 912 345 678, 098.123.4567) + .replace(/(?:\+?84|0)\s*[1-9](?:[\s.-]*\d){7,9}\b/g, '[phone-removed]') + .replace(/\p{Cc}+/gu, ' ') + .replace(/\s+/g, ' ') + .trim(); + return sliceUtf16WellFormed(cleaned, safeMaxLen).trimEnd(); } /** diff --git a/apps/importer/src/shopee/product-points-ai-prompt.ts b/apps/importer/src/shopee/product-points-ai-prompt.ts index bd7a8a09..ad67abd1 100644 --- a/apps/importer/src/shopee/product-points-ai-prompt.ts +++ b/apps/importer/src/shopee/product-points-ai-prompt.ts @@ -324,7 +324,9 @@ export function mergeAndSelectAiProductPoints( pros: list.filter(c => c.kind === 'pro').slice(0, max), cons: list.filter(c => c.kind === 'con').slice(0, max), }); - const byCriterion: Record = {}; + const byCriterion: Record = Object.create( + null + ) as Record; for (const key of new Set(rebuilt.map(c => c.criterionKey ?? GENERAL_POINTS))) { byCriterion[key] = pickSides( rebuilt.filter(c => (c.criterionKey ?? GENERAL_POINTS) === key), diff --git a/apps/importer/src/shopee/review-ai-prompt.ts b/apps/importer/src/shopee/review-ai-prompt.ts index 36991a64..84bc0d27 100644 --- a/apps/importer/src/shopee/review-ai-prompt.ts +++ b/apps/importer/src/shopee/review-ai-prompt.ts @@ -366,15 +366,17 @@ export function batchCostUsd( cache_creation_input_tokens?: number | null; } ): number { + if (!isReviewAiModel(model)) return 0; const price = REVIEW_AI_MODELS[model]; - const n = (v: number | null | undefined) => (typeof v === 'number' && v > 0 ? v : 0); + const mTokens = (v: number | null | undefined) => + typeof v === 'number' && Number.isFinite(v) && v > 0 ? v / 1_000_000 : 0; const usd = - (n(usage.input_tokens) * price.input + - n(usage.cache_read_input_tokens) * price.input * CACHE_READ_FACTOR + - n(usage.cache_creation_input_tokens) * price.input * CACHE_WRITE_FACTOR + - n(usage.output_tokens) * price.output) / - 1_000_000; - return usd * BATCH_DISCOUNT; + (mTokens(usage.input_tokens) * price.input + + mTokens(usage.cache_read_input_tokens) * price.input * CACHE_READ_FACTOR + + mTokens(usage.cache_creation_input_tokens) * price.input * CACHE_WRITE_FACTOR + + mTokens(usage.output_tokens) * price.output) * + BATCH_DISCOUNT; + return Number.isFinite(usd) ? usd : Number.POSITIVE_INFINITY; } /** From 7e6a3ac524fd4af4cf26d230b7da3be0c0da8e4e Mon Sep 17 00:00:00 2001 From: JOY <5027251+JOY@users.noreply.github.com> Date: Sun, 22 Nov 2026 17:55:10 +0700 Subject: [PATCH 3/4] fix(importer): remove unsourced seed templates and tighten 1758 test (#1858) * fix(importer): remove unsourced seed templates and tighten 1758 test - Replace unsourced "6.0, A2DP, LE" Bluetooth text on iPhone 18 Pro, iPhone 18 Pro Max, and Galaxy S26 Ultra with sourced versions ("6" and "6.0") in flagship-seed-sourced-2026.ts and product-normalizer.ts (#1803 item 6). - Replace unsourced 5G band labels on iPad Pro M5 and Apple Watch Ultra 3 with official Apple NR band lists and field-level sources. - Drop remaining unsourced Bluetooth profile strings, CE/FCC/QCVN certifications, and cross-category laptop camera and Wi-Fi-only cellular placeholders across flagship-seed-data.ts, recording every removed seed field in retract_spec_fields. - Require field-level sources[path] in seed-template-values-1758.test.ts so group-level sources. cannot mask template or placeholder values (#1855). * fix(importer): address round 1 provenance and retraction review - Replace unsourced certifications on the 3 canonical iPhone entries with sourced Apple Vietnam model identifiers (A3287, A3290, A3090) so canonicalMasterUpdate overwrites stale stored values (#1855). - Replace AirPods Pro 2 USB-C Bluetooth codec string with sourced "5.3" citing Apple Tech Specs, and remove port/mic text from MacBook key camera specs. - Broaden Bluetooth profile, QCVN, 5G band-pair, and mid-string non-cellular regexes in seed-template-values-1758.test.ts, extend checks to watches/earbuds, and verify 10-group + rear-camera audit invariants after retraction. --- .../__tests__/seed-earbuds-gpu-1793.test.ts | 13 +- .../seed-template-values-1758.test.ts | 578 ++++++++++++++++-- .../shopee/__tests__/sourced-seeds.test.ts | 4 +- .../importer/src/shopee/flagship-seed-data.ts | 222 ++++--- .../src/shopee/flagship-seed-sourced-2026.ts | 10 +- .../importer/src/shopee/product-normalizer.ts | 6 +- apps/importer/src/shopee/test-ai-enricher.ts | 16 +- 7 files changed, 693 insertions(+), 156 deletions(-) diff --git a/apps/importer/src/shopee/__tests__/seed-earbuds-gpu-1793.test.ts b/apps/importer/src/shopee/__tests__/seed-earbuds-gpu-1793.test.ts index baf23fb4..23c80caf 100644 --- a/apps/importer/src/shopee/__tests__/seed-earbuds-gpu-1793.test.ts +++ b/apps/importer/src/shopee/__tests__/seed-earbuds-gpu-1793.test.ts @@ -119,6 +119,12 @@ const STORED_TEMPLATE_TEXT = { technology: 'Bluetooth 5.3 + Ultra Wideband (U1)', sim_type: 'Wireless Audio Accessory', }, + connectivity: { + bluetooth: '5.4, A2DP, LE', + }, + regulatory: { + certifications: 'CE, FCC, RoHS, QCVN', + }, battery: { capacity_mah: 1 }, }, key_specs: { @@ -157,6 +163,7 @@ const RETRACTED_EVERYWHERE = [ 'connectivity.nfc', 'cellular.has_5g', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', ]; // The fields only some earlier seeds set. @@ -169,11 +176,12 @@ const RETRACTED_ALSO: Record = { 'cellular.volte', 'cellular.vowifi', ], - 'apple:airpods-pro-3:standard': ['connectivity.location'], + 'apple:airpods-pro-3:standard': ['connectivity.bluetooth', 'connectivity.location'], 'sony:wf-1000xm5:64gb': [ 'display.ppi', 'display.protection', 'camera.video_recording', + 'connectivity.bluetooth', 'connectivity.location', 'cellular.volte', 'cellular.vowifi', @@ -182,11 +190,12 @@ const RETRACTED_ALSO: Record = { 'display.ppi', 'display.protection', 'camera.video_recording', + 'connectivity.bluetooth', 'connectivity.location', 'cellular.volte', 'cellular.vowifi', ], - 'sony:wf-1000xm6:standard': [], + 'sony:wf-1000xm6:standard': ['connectivity.bluetooth'], }; test('the backfill removes the stored earbud template text from masters and Items', async () => { diff --git a/apps/importer/src/shopee/__tests__/seed-template-values-1758.test.ts b/apps/importer/src/shopee/__tests__/seed-template-values-1758.test.ts index 6259324e..cddcf64e 100644 --- a/apps/importer/src/shopee/__tests__/seed-template-values-1758.test.ts +++ b/apps/importer/src/shopee/__tests__/seed-template-values-1758.test.ts @@ -1,28 +1,51 @@ /** - * DOS/Rate#1758: flagship seed and canonical entries carried template values copied from the - * arena spec syncer's old defaults and the normalizer's generic fallbacks, and the backfill - * wrote them to Production. Each one is now a value a cited source states, or gone (with a - * retraction, since the backfill's merge never deletes a stored field). + * DOS/Rate#1758 & DOS/Rate#1855: flagship seed and canonical entries carried template values + * copied from the arena spec syncer's old defaults, the normalizer's generic fallbacks, and + * cross-category placeholders, and the backfill wrote them to Production. Each one is now a + * value an explicit per-field source states, or gone (with a retraction in + * `retract_spec_fields`, since the backfill's merge never deletes a stored field). Group-level + * `sources.` entries never excuse template-shaped or cross-category field values. */ import assert from 'node:assert/strict'; import test from 'node:test'; -import type { ProductSpecifications } from '@repo/shared-data'; +import { + ProductSpecificationsSchema, + type KeySpecs, + type ProductSpecifications, +} from '@repo/shared-data'; import { CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY, FLAGSHIP_DEVICES_TO_SEED, flagshipSeedsByItem, + type FlagshipDeviceSeed, } from '../flagship-seed-data.js'; -import { seedMasterSpecUpdate } from '../jobs/backfill-specs.js'; +import { + canonicalMasterUpdate, + hasSingleRearCamera, + REQUIRED_10_SPEC_GROUPS, + requiredSpecGroups, + seedMasterSpecUpdate, + statesRearCamera, +} from '../jobs/backfill-specs.js'; +import { ProductNormalizer } from '../product-normalizer.js'; +import type { ShopeeProduct } from '../types.js'; interface Entry { key: string; + categorySlug?: FlagshipDeviceSeed['categorySlug']; + has_5g?: boolean; specifications: ProductSpecifications; + key_specs?: KeySpecs; sources?: Readonly>; } const ENTRIES: Entry[] = [ ...FLAGSHIP_DEVICES_TO_SEED.map(s => ({ ...s, key: s.model_key })), - ...Object.entries(CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY).map(([key, e]) => ({ ...e, key })), + ...Object.entries(CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY).map(([key, e]) => ({ + ...e, + key, + categorySlug: 'smartphones' as const, + })), ]; const at = (specs: ProductSpecifications, path: string): unknown => { @@ -30,9 +53,8 @@ const at = (specs: ProductSpecifications, path: string): unknown => { return (specs as Record | undefined>)[group]?.[field]; }; -// The arena syncer's former page-omitted defaults (removed in DOS/Rate#1754, still in -// `arena-spec-syncer.ts` for the cellular ones) and the normalizer's generic fallbacks. -// A seed may hold one only where its `sources` cite that field. +// The arena syncer's former page-omitted defaults (removed in DOS/Rate#1754) and the +// normalizer's generic fallbacks. const TEMPLATE_VALUES: ReadonlyArray = [ ['regulatory.certifications', 'CE, FCC, RoHS, QCVN (BTTTT Vietnam)'], ['multimedia.audio_features', '24-bit/192kHz Hi-Res & Hi-Res Wireless audio'], @@ -45,32 +67,286 @@ const TEMPLATE_VALUES: ReadonlyArray = [ ['connectivity.bluetooth', '5.3, A2DP, LE'], ]; -// A field counts as sourced when `sources` cites it or its whole group. -const cites = (entry: Entry, path: string): boolean => - Boolean(entry.sources?.[path] ?? entry.sources?.[path.split('.')[0]!]); +const BLUETOOTH_PROFILES_RE = + /\b\d+(?:\.\d+)?,\s*(?:A2DP|AVRCP|HFP|HSP|LE\b|AAC|SBC|aptX|LDAC|LHDC)/i; +const CERT_CODES_RE = /\b(?:CE|FCC|NCC|KC|VCCI|SRRC|SDPPI|SIRIM|NBTC|IMDA|NTRA)\b|\bQCVN/; +const TWO_BAND_NUMBERS_RE = /\bn?\d{1,3}\s*[,/]\s*n?\d{1,3}\b/; +const BARE_NEGATIVE_PLACEHOLDER_RE = /^\s*(?:none|no|n\/a)\s*$/i; +const CELLULAR_NON_CELLULAR_RE = + /^\s*(?:no|none|n\/a)\b|\b(?:wi-?fi|bluetooth)\b|\bno\s+(?:cellular|sim)\b/i; +const LAPTOP_KEY_CAMERA_NON_WEBCAM_RE = /\b(?:Thunderbolt|HDMI|SDXC|\d+-Mic\b|Mic\s+Array)\b/i; -test('no seed or canonical entry holds an unsourced template value', () => { - for (const entry of ENTRIES) { - for (const [path, value] of TEMPLATE_VALUES) { - if (at(entry.specifications, path) !== value) continue; - assert.ok(cites(entry, path), `${entry.key}: unsourced template ${path} = ${value}`); +const ALL_CAMERA_PATHS = [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'camera.third_camera', + 'camera.fourth_camera', + 'camera.flash', + 'camera.video_recording', + 'camera.front_camera', +] as const; + +const LAPTOP_REAR_CAMERA_PATHS = [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'camera.third_camera', + 'camera.fourth_camera', + 'camera.flash', +] as const; + +const CELLULAR_DETAIL_PATHS = [ + 'cellular.bands_5g', + 'cellular.bands_4g', + 'cellular.bands_3g', + 'cellular.bands_2g', + 'cellular.technology', + 'cellular.data_speed', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', +] as const; + +// DOS/Rate#1855: template-shaped and cross-category values require an explicit field-level +// `sources[path]` URL. A group-level `sources.` never excuses them. +const citesField = (entry: Entry, path: string): boolean => Boolean(entry.sources?.[path]); + +function findTemplateViolations(entry: Entry): string[] { + const issues: string[] = []; + + for (const [path, value] of TEMPLATE_VALUES) { + if (at(entry.specifications, path) === value && !citesField(entry, path)) { + issues.push(`${entry.key}: unsourced template ${path} = ${JSON.stringify(value)}`); + } + } + + const bluetooth = at(entry.specifications, 'connectivity.bluetooth'); + if ( + typeof bluetooth === 'string' && + BLUETOOTH_PROFILES_RE.test(bluetooth) && + !citesField(entry, 'connectivity.bluetooth') + ) { + issues.push(`${entry.key}: unsourced Bluetooth profile connectivity.bluetooth = ${bluetooth}`); + } + + const certifications = at(entry.specifications, 'regulatory.certifications'); + if ( + typeof certifications === 'string' && + CERT_CODES_RE.test(certifications) && + !citesField(entry, 'regulatory.certifications') + ) { + issues.push( + `${entry.key}: unsourced regulatory codes regulatory.certifications = ${certifications}` + ); + } + + const bands5g = at(entry.specifications, 'cellular.bands_5g'); + if (bands5g !== undefined) { + const text = String(bands5g); + if (/SA\/NSA\/Sub6/i.test(text) && !TWO_BAND_NUMBERS_RE.test(text)) { + issues.push(`${entry.key}: bare SA/NSA/Sub6 cellular.bands_5g = ${text}`); + } else if (!TWO_BAND_NUMBERS_RE.test(text) && !citesField(entry, 'cellular.bands_5g')) { + issues.push(`${entry.key}: unsourced 5G band text cellular.bands_5g = ${text}`); + } + } + + if (entry.categorySlug === 'laptops') { + for (const path of LAPTOP_REAR_CAMERA_PATHS) { + const val = at(entry.specifications, path); + if (val !== undefined && !citesField(entry, path)) { + issues.push(`${entry.key}: unsourced laptop rear-camera field ${path} = ${String(val)}`); + } + } + const keyCam = entry.key_specs?.camera; + if ( + typeof keyCam === 'string' && + LAPTOP_KEY_CAMERA_NON_WEBCAM_RE.test(keyCam) && + !citesField(entry, 'key_specs.camera') + ) { + issues.push(`${entry.key}: non-webcam laptop key_specs.camera = ${keyCam}`); + } + } + + if (entry.categorySlug === 'smartwatches' || entry.categorySlug === 'earbuds') { + for (const path of ALL_CAMERA_PATHS) { + const val = at(entry.specifications, path); + if (val !== undefined && !citesField(entry, path)) { + issues.push( + `${entry.key}: unsourced ${entry.categorySlug} camera field ${path} = ${String(val)}` + ); + } + } + } + + if (entry.categorySlug === 'earbuds') { + for (const path of ['cellular.has_5g', ...CELLULAR_DETAIL_PATHS] as const) { + const val = at(entry.specifications, path); + if (val !== undefined && !citesField(entry, path)) { + issues.push(`${entry.key}: unsourced earbuds cellular field ${path} = ${String(val)}`); + } + } + } + + const isNonCellularWatch = + entry.categorySlug === 'smartwatches' && + entry.has_5g === false && + at(entry.specifications, 'cellular.bands_4g') === undefined; + const isWifiOnlyTabletOrLaptop = + entry.has_5g === false && + (entry.categorySlug === 'tablets' || entry.categorySlug === 'laptops'); + + if (isWifiOnlyTabletOrLaptop || isNonCellularWatch) { + for (const path of CELLULAR_DETAIL_PATHS) { + const val = at(entry.specifications, path); + if (val !== undefined && !citesField(entry, path)) { + issues.push( + `${entry.key}: unsourced non-cellular ${entry.categorySlug} cellular field ${path} = ${String(val)}` + ); + } } - // The normalizer's Bluetooth shape with any version ("5.4, A2DP, LE"). - const bluetooth = at(entry.specifications, 'connectivity.bluetooth'); - if (typeof bluetooth === 'string' && /^\d+(\.\d+)?, A2DP, LE$/.test(bluetooth)) { - assert.ok(cites(entry, 'connectivity.bluetooth'), `${entry.key}: bluetooth ${bluetooth}`); + } + + for (const group of ['camera', 'cellular', 'connectivity'] as const) { + const groupObj = entry.specifications[group]; + if (!groupObj || typeof groupObj !== 'object') continue; + for (const [field, val] of Object.entries(groupObj)) { + if (typeof val !== 'string') continue; + const path = `${group}.${field}`; + if (citesField(entry, path)) continue; + if (BARE_NEGATIVE_PLACEHOLDER_RE.test(val)) { + issues.push(`${entry.key}: unsourced placeholder ${path} = ${JSON.stringify(val)}`); + } else if (group === 'cellular' && CELLULAR_NON_CELLULAR_RE.test(val)) { + issues.push( + `${entry.key}: unsourced non-cellular placeholder ${path} = ${JSON.stringify(val)}` + ); + } } } + + return issues; +} + +test('no seed or canonical entry holds an unsourced template or cross-category value', () => { + for (const entry of ENTRIES) { + assert.deepEqual(findTemplateViolations(entry), [], entry.key); + } +}); + +test('group-level sources never mask template-shaped or cross-category field values (#1855)', () => { + const groupSourcesOnly: Readonly> = { + camera: 'https://www.apple.com/macbook-air/specs/', + cellular: 'https://www.apple.com/ipad-pro/specs/', + connectivity: 'https://www.apple.com/iphone-18-pro/specs/', + multimedia: 'https://www.gsmarena.com/example.php', + regulatory: 'https://www.apple.com/vn/iphone-18-pro/specs/', + }; + + const masked: Entry = { + key: 'test:masked-by-group:256gb', + categorySlug: 'laptops', + has_5g: false, + specifications: { + camera: { + rear_setup: 'None', + second_camera: 'None', + front_camera: '1080p FaceTime HD', + }, + cellular: { + has_5g: false, + bands_5g: '5G Sub-6 (LTE Cat 20)', + technology: 'GPS + Wi-Fi + Bluetooth', + sim_type: 'No cellular', + volte: false, + }, + connectivity: { + bluetooth: '5.3, AAC, Ultra-low latency Lossless', + }, + multimedia: { + audio_features: '24-bit/192kHz Hi-Res & Hi-Res Wireless audio', + }, + regulatory: { + certifications: 'QCVN127B', + }, + }, + key_specs: { + camera: '12MP Center Stage + 3x Thunderbolt 5', + }, + sources: groupSourcesOnly, + }; + + const violations = findTemplateViolations(masked); + assert.ok(violations.some(v => v.includes('connectivity.bluetooth'))); + assert.ok(violations.some(v => v.includes('regulatory.certifications'))); + assert.ok(violations.some(v => v.includes('cellular.bands_5g'))); + assert.ok(violations.some(v => v.includes('cellular.technology'))); + assert.ok(violations.some(v => v.includes('cellular.sim_type'))); + assert.ok(violations.some(v => v.includes('cellular.volte'))); + assert.ok(violations.some(v => v.includes('multimedia.audio_features'))); + assert.ok(violations.some(v => v.includes('camera.rear_setup'))); + assert.ok(violations.some(v => v.includes('camera.second_camera'))); + assert.ok(violations.some(v => v.includes('key_specs.camera'))); + + // Bare SA/NSA/Sub6 without band numbers is always rejected, even if cited. + const bareSaNsa: Entry = { + key: 'test:bare-sa-nsa:256gb', + categorySlug: 'smartphones', + has_5g: true, + specifications: { cellular: { has_5g: true, bands_5g: 'SA/NSA/Sub6' } }, + sources: { 'cellular.bands_5g': 'https://example.com/specs' }, + }; + assert.ok(findTemplateViolations(bareSaNsa).some(v => v.includes('bare SA/NSA/Sub6'))); + + // GPS smartwatch with volte/vowifi is rejected without field-level citation. + const gpsWatch: Entry = { + key: 'test:gps-watch:64gb', + categorySlug: 'smartwatches', + has_5g: false, + specifications: { cellular: { has_5g: false, volte: false, vowifi: true } }, + sources: { cellular: 'https://example.com/watch' }, + }; + assert.ok(findTemplateViolations(gpsWatch).some(v => v.includes('cellular.volte'))); + assert.ok(findTemplateViolations(gpsWatch).some(v => v.includes('cellular.vowifi'))); + + // Explicit field-level sources clear only non-bare-SA/NSA/Sub6 cited paths. + const fieldCited: Entry = { + ...masked, + specifications: { + ...masked.specifications, + cellular: { + ...masked.specifications.cellular, + bands_5g: '5G (Sub-6)', + }, + }, + sources: { + ...groupSourcesOnly, + 'camera.rear_setup': 'https://www.apple.com/macbook-air/specs/', + 'camera.second_camera': 'https://www.apple.com/macbook-air/specs/', + 'cellular.bands_5g': 'https://www.apple.com/ipad-pro/specs/', + 'cellular.technology': 'https://www.apple.com/ipad-pro/specs/', + 'cellular.sim_type': 'https://www.apple.com/ipad-pro/specs/', + 'cellular.volte': 'https://www.apple.com/ipad-pro/specs/', + 'connectivity.bluetooth': 'https://www.apple.com/iphone-18-pro/specs/', + 'multimedia.audio_features': 'https://www.gsmarena.com/example.php', + 'regulatory.certifications': 'https://www.apple.com/vn/iphone-18-pro/specs/', + 'key_specs.camera': 'https://www.apple.com/macbook-pro/specs/', + }, + }; + assert.deepEqual(findTemplateViolations(fieldCited), []); }); -test('a 5G band field always lists bands', () => { +test('a 5G band field lists explicit bands or cites an official field-level source', () => { for (const entry of ENTRIES) { const bands = at(entry.specifications, 'cellular.bands_5g'); if (bands === undefined) continue; - // "SA/NSA/Sub6" with no band number, bare or with a note ("(Snapdragon X75 Modem)"). - if (/SA\/NSA\/Sub6/i.test(String(bands))) { - assert.match(String(bands), /\bn?\d{1,3}\b.*\bn?\d{1,3}\b/, `${entry.key}: ${bands}`); + const text = String(bands); + if (/SA\/NSA\/Sub6/i.test(text)) { + assert.match(text, TWO_BAND_NUMBERS_RE, `${entry.key}: ${text}`); } + assert.ok( + TWO_BAND_NUMBERS_RE.test(text) || citesField(entry, 'cellular.bands_5g'), + `${entry.key}: ${text}` + ); } }); @@ -88,7 +364,7 @@ const byKey = (key: string): Entry => { return found; }; -test('the replaced values are the sourced ones', () => { +test('the replaced values are the sourced ones (seeds, canonical entries, and 2026 normalizer)', () => { const expected: Record> = { 'apple:iphone-16:128gb': { 'cellular.bands_5g': @@ -96,6 +372,7 @@ test('the replaced values are the sourced ones', () => { 'connectivity.bluetooth': '5.3', 'regulatory.sar_head': '1.08 W/kg', 'regulatory.sar_body': '1.17 W/kg', + 'regulatory.certifications': 'Model A3287 (Vietnam and other countries and regions)', }, 'apple:iphone-16-pro-max:256gb': { 'cellular.bands_5g': @@ -104,10 +381,12 @@ test('the replaced values are the sourced ones', () => { 'apple:iphone-16-plus:256gb': { 'cellular.bands_5g': 'FDD-5G NR n1/n2/n3/n5/n7/n8/n12/n20/n25/n26/n28/n30/n66/n70/n75/n76; TDD-5G NR n38/n40/n41/n48/n53/n77/n78/n79', + 'regulatory.certifications': 'Model A3290 (Vietnam and other countries and regions)', }, 'apple:iphone-15:128gb': { 'cellular.bands_5g': '5G NR n1/n2/n3/n5/n7/n8/n12/n20/n25/n26/n28/n30/n38/n40/n41/n48/n53/n66/n70/n75/n76/n77/n78/n79', + 'regulatory.certifications': 'Model A3090 (Vietnam and other countries and regions)', }, 'apple:iphone-16-pro:256gb': { 'cellular.bands_5g': @@ -125,6 +404,9 @@ test('the replaced values are the sourced ones', () => { 'cellular.bands_5g': '5G (Sub-6)', 'connectivity.bluetooth': '5.3', }, + 'apple:airpods-pro-2-usbc:64gb': { + 'connectivity.bluetooth': '5.3', + }, 'xiaomi:14-ultra:512gb': { 'cellular.bands_5g': '5G NR n1/n2/n3/n5/n7/n8/n20/n28/n38/n40/n41/n48/n66/n77/n78/n79 (n66 varies by region)', @@ -135,47 +417,247 @@ test('the replaced values are the sourced ones', () => { }, 'oppo:find-x9-pro:512gb': { 'cellular.sim_type': 'Nano-SIM + Nano-SIM + eSIM' }, 'apple:ipad-pro-m5-11:256gb': { + 'cellular.bands_5g': + '5G NR n1/n2/n3/n5/n7/n8/n12/n14/n20/n25/n26/n28/n29/n30/n38/n40/n41/n48/n66/n70/n71/n75/n77/n78/n79', 'cellular.data_speed': '5G (sub-6 GHz) with 4x4 MIMO, Gigabit LTE with 4x4 MIMO', 'connectivity.bluetooth': '6', }, + 'apple:watch-ultra-3-49mm:64gb': { + 'cellular.bands_5g': + 'FDD-5G NR n1/n2/n3/n5/n7/n8/n12/n14/n20/n25/n26/n28/n66/n71; TDD-5G NR n38/n40/n41/n53', + 'connectivity.bluetooth': '5.3', + }, + 'apple:iphone-18-pro-max:256gb': { 'connectivity.bluetooth': '6' }, + 'apple:iphone-18-pro:256gb': { 'connectivity.bluetooth': '6' }, + 'samsung:galaxy-s26-ultra:256gb': { 'connectivity.bluetooth': '6.0' }, }; for (const [key, fields] of Object.entries(expected)) { const entry = byKey(key); for (const [path, value] of Object.entries(fields)) { assert.equal(at(entry.specifications, path), value, `${key}: ${path}`); - assert.ok(entry.sources?.[path], `${key}: ${path} has no source`); + assert.ok(entry.sources?.[path], `${key}: ${path} has no field-level source`); } } + + // Canonical backfill updates overwrite stale stored CE/FCC/QCVN certifications on all 3 rows. + for (const [key, entry] of Object.entries(CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY)) { + const update = canonicalMasterUpdate( + { + specifications: { + regulatory: { certifications: 'CE, FCC, RoHS, QCVN (Bộ TT&TT Việt Nam)' }, + }, + key_specs: {}, + }, + entry + ) as { specifications: ProductSpecifications }; + assert.equal( + update.specifications.regulatory?.certifications, + entry.specifications.regulatory?.certifications, + key + ); + assert.doesNotMatch(update.specifications.regulatory?.certifications ?? '', CERT_CODES_RE, key); + } + + // DOS/Rate#1803 item 6: the normalizer registry carries the sourced Bluetooth versions too. + const normalizer = new ProductNormalizer(); + const normalize = (title: string) => + normalizer.normalize({ + itemId: '1', + shopId: '2', + title, + priceMin: 30_000_000, + priceMax: 30_000_000, + priceBeforeDiscount: 0, + currency: 'VND', + stock: 1, + historicalSold: 1, + ratingStar: 5, + ratingCount: 1, + images: [], + models: [], + attributes: [], + shop: { shopId: '2' }, + } as unknown as ShopeeProduct); + + for (const [title, bt] of [ + ['Apple iPhone 18 Pro Max 256GB', '6'], + ['Apple iPhone 18 Pro 256GB', '6'], + ['Samsung Galaxy S26 Ultra 256GB', '6.0'], + ] as const) { + const out = normalize(title).specifications; + assert.equal(out.connectivity?.bluetooth, bt, title); + assert.doesNotMatch(out.connectivity?.bluetooth ?? '', BLUETOOTH_PROFILES_RE, title); + } }); -// Fields no checked source states: dropped from the seed and retracted from stored rows. -const RETRACTED: Record = { - 'samsung:galaxy-a55:256gb': ['cellular.bands_5g', 'connectivity.bluetooth'], +// Fields no checked source states (including cross-category laptop/Wi-Fi placeholders): +// dropped from each seed and listed in `retract_spec_fields` so `seedMasterSpecUpdate` +// removes stale stored copies instead of keeping them on merge. +const RETRACTED_SUBSETS: Record = { + 'samsung:galaxy-s24-ultra:256gb': ['regulatory.certifications'], + 'apple:iphone-16-pro-max:256gb': ['regulatory.certifications'], + 'samsung:galaxy-a55:256gb': [ + 'cellular.bands_5g', + 'connectivity.bluetooth', + 'regulatory.certifications', + ], + 'xiaomi:14-ultra:512gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'oppo:find-x8:256gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'apple:ipad-pro-m4-11:256gb': [ + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], + 'apple:macbook-air-m3-13:256gb': [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], + 'apple:iphone-16-pro:256gb': ['regulatory.certifications'], + 'apple:watch-series-10-42mm:64gb': [ + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], + 'apple:airpods-pro-2-usbc:64gb': ['regulatory.certifications'], + 'samsung:galaxy-tab-s10-ultra:256gb': ['regulatory.certifications'], + 'xiaomi:pad-6s-pro:256gb': [ + 'connectivity.bluetooth', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], + 'asus:zenbook-s-14:1024gb': [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + ], + 'lenovo:thinkpad-x1-carbon-gen-12:512gb': [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + ], + 'apple:watch-ultra-2:64gb': ['regulatory.certifications'], + 'samsung:galaxy-watch-ultra:32gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'garmin:forerunner-265:8gb': ['cellular.volte', 'cellular.vowifi', 'regulatory.certifications'], + 'sony:wf-1000xm5:64gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'samsung:galaxy-buds3-pro:64gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'xiaomi:18-pro-max:512gb': ['connectivity.bluetooth', 'regulatory.certifications'], 'xiaomi:17-pro-max:512gb': [ 'cellular.sim_type', + 'connectivity.bluetooth', 'multimedia.audio_features', 'regulatory.certifications', ], - 'xiaomi:pad-7-pro:256gb': ['multimedia.audio_features'], + 'oppo:find-x9-pro:512gb': ['connectivity.bluetooth', 'regulatory.certifications'], + 'apple:ipad-pro-m5-11:256gb': ['regulatory.certifications'], + 'xiaomi:pad-7-pro:256gb': [ + 'cellular.sim_type', + 'cellular.technology', + 'connectivity.bluetooth', + 'multimedia.audio_features', + 'regulatory.certifications', + ], + 'apple:macbook-air-m4-13:256gb': [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.sim_type', + 'cellular.technology', + 'regulatory.certifications', + ], + 'apple:macbook-pro-m4-pro-14:512gb': [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.sim_type', + 'cellular.technology', + 'regulatory.certifications', + ], + 'apple:watch-series-11-46mm:64gb': ['regulatory.certifications'], + 'apple:watch-ultra-3-49mm:64gb': ['regulatory.certifications'], + 'apple:airpods-pro-3:standard': ['connectivity.bluetooth', 'regulatory.certifications'], + 'sony:wf-1000xm6:standard': ['connectivity.bluetooth', 'regulatory.certifications'], }; test('fields no source states are dropped and retracted from stored rows', () => { - for (const [key, paths] of Object.entries(RETRACTED)) { + // Every seed's `retract_spec_fields` is deduplicated and never overlaps a field the seed sets. + for (const seed of FLAGSHIP_DEVICES_TO_SEED) { + const retracted = seed.retract_spec_fields ?? []; + assert.equal(new Set(retracted).size, retracted.length, `${seed.model_key}: duplicate retract`); + for (const path of retracted) { + if (path.startsWith('key_specs.')) { + const keyField = path.slice('key_specs.'.length); + assert.equal( + (seed.key_specs as Record)[keyField], + undefined, + `${seed.model_key} still sets ${path}` + ); + } else { + assert.equal( + at(seed.specifications, path), + undefined, + `${seed.model_key} still sets ${path}` + ); + } + } + } + + const items = flagshipSeedsByItem(); + for (const [key, paths] of Object.entries(RETRACTED_SUBSETS)) { const seed = FLAGSHIP_DEVICES_TO_SEED.find(s => s.model_key === key); assert.ok(seed, key); - assert.deepEqual(seed.retract_spec_fields, paths, key); + const retractedSet = new Set(seed.retract_spec_fields ?? []); for (const path of paths) { + assert.ok(retractedSet.has(path), `${key}: missing retract_spec_fields entry ${path}`); assert.equal(at(seed.specifications, path), undefined, `${key} still sets ${path}`); } - // The Item carries the retraction too. - const item = flagshipSeedsByItem().find(i => key.startsWith(`${i.itemKey}:`)); + + // The Item carries every retraction of its variants too. + const item = items.find(i => key.startsWith(`${i.itemKey}:`)); assert.ok(item, key); - for (const path of paths) assert.ok(item.retract_spec_fields.includes(path), key); + for (const path of paths) { + assert.ok(item.retract_spec_fields.includes(path), `${key}: Item missing ${path}`); + } - // The master update removes the stored template value instead of keeping it. + // `seedMasterSpecUpdate` removes the stale stored template/placeholder values instead of + // keeping them, and the resulting specifications pass `auditMasterSpecs` runtime checks + // (schema, all 10 groups since seed specs omit `category_slug`, and rear-camera completeness). const stored = { specifications: { - cellular: { bands_5g: 'SA/NSA/Sub6', sim_type: 'Dual SIM (Nano-SIM + eSIM)' }, + camera: { + rear_setup: 'None', + main_camera: '1080p Webcam', + second_camera: 'None', + front_camera: '1080p Webcam', + }, + cellular: { + has_5g: false, + bands_5g: 'SA/NSA/Sub6', + technology: 'Wi-Fi Only', + sim_type: 'No cellular', + volte: false, + vowifi: true, + }, connectivity: { bluetooth: '5.3, A2DP, LE' }, multimedia: { audio_features: '24-bit/192kHz Hi-Res & Hi-Res Wireless audio' }, regulatory: { certifications: 'CE, FCC, RoHS, QCVN (BTTTT Vietnam)' }, @@ -188,6 +670,24 @@ test('fields no source states are dropped and retracted from stored rows', () => for (const path of paths) { assert.equal(at(update.specifications, path), undefined, `${key} keeps stored ${path}`); } + const parsed = ProductSpecificationsSchema.safeParse(update.specifications); + assert.equal(parsed.success, true, `${key}: ${parsed.error?.message}`); + assert.deepEqual( + requiredSpecGroups(update.specifications.category_slug), + REQUIRED_10_SPEC_GROUPS, + key + ); + for (const grp of REQUIRED_10_SPEC_GROUPS) { + assert.ok(update.specifications[grp], `${key}: missing group ${grp} after retraction`); + } + if (statesRearCamera(update.specifications.camera)) { + assert.ok(update.specifications.camera?.main_camera?.trim(), `${key}: missing main_camera`); + assert.ok( + hasSingleRearCamera(update.specifications.camera) || + update.specifications.camera?.second_camera?.trim(), + `${key}: missing second_camera` + ); + } } }); diff --git a/apps/importer/src/shopee/__tests__/sourced-seeds.test.ts b/apps/importer/src/shopee/__tests__/sourced-seeds.test.ts index 963146c6..0410f1aa 100644 --- a/apps/importer/src/shopee/__tests__/sourced-seeds.test.ts +++ b/apps/importer/src/shopee/__tests__/sourced-seeds.test.ts @@ -211,9 +211,7 @@ for (const key of [ assert.equal((update as Record).battery_mah, 5000); assert.deepEqual((update as Record).colors, seed.colors); // A seed with nothing to retract keeps its stored label. - const plain = FLAGSHIP_DEVICES_TO_SEED.find( - s => s.model_key === 'samsung:galaxy-s24-ultra:256gb' - )!; + const plain = FLAGSHIP_DEVICES_TO_SEED.find(s => s.model_key === 'apple:iphone-16e:128gb')!; assert.equal('variant_name' in seedMasterSpecUpdate(null, plain), false); } diff --git a/apps/importer/src/shopee/flagship-seed-data.ts b/apps/importer/src/shopee/flagship-seed-data.ts index ffe25aa0..0902b38b 100644 --- a/apps/importer/src/shopee/flagship-seed-data.ts +++ b/apps/importer/src/shopee/flagship-seed-data.ts @@ -150,7 +150,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< fcc_approval: 'FCC ID BCG-E8692A', sar_head: '1.08 W/kg', sar_body: '1.17 W/kg', - certifications: 'CE, FCC, RoHS, QCVN (Bộ TT&TT Việt Nam)', + certifications: 'Model A3287 (Vietnam and other countries and regions)', }, }, key_specs: { @@ -166,6 +166,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< 'connectivity.bluetooth': 'https://support.apple.com/en-us/121029', 'regulatory.sar_head': 'https://www.apple.com/legal/rfexposure/iphone17,3/en/', 'regulatory.sar_body': 'https://www.apple.com/legal/rfexposure/iphone17,3/en/', + 'regulatory.certifications': 'https://support.apple.com/vi-vn/121029', }, }, 'apple:iphone-16-plus:256gb': { @@ -256,7 +257,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< fcc_approval: 'FCC ID BCG-E8693A', sar_head: '1.12 W/kg', sar_body: '1.14 W/kg', - certifications: 'CE, FCC, RoHS, QCVN (Bộ TT&TT Việt Nam)', + certifications: 'Model A3290 (Vietnam and other countries and regions)', }, }, key_specs: { @@ -270,6 +271,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< sources: { 'cellular.bands_5g': 'https://support.apple.com/vi-vn/121030', 'connectivity.bluetooth': 'https://support.apple.com/en-us/121030', + 'regulatory.certifications': 'https://support.apple.com/vi-vn/121030', }, }, 'apple:iphone-15:128gb': { @@ -358,7 +360,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< fcc_approval: 'FCC ID BCG-E8431A', sar_head: '1.12 W/kg', sar_body: '1.14 W/kg', - certifications: 'CE, FCC, RoHS, QCVN', + certifications: 'Model A3090 (Vietnam and other countries and regions)', }, }, key_specs: { @@ -372,6 +374,7 @@ export const CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY: Record< sources: { 'cellular.bands_5g': 'https://support.apple.com/vi-vn/111831', 'connectivity.bluetooth': 'https://support.apple.com/en-us/111831', + 'regulatory.certifications': 'https://support.apple.com/vi-vn/111831', }, }, }; @@ -484,7 +487,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID A3LSMS928U', sar_head: '1.06 W/kg', sar_body: '0.66 W/kg', - certifications: 'CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -500,6 +502,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.bands_5g': 'https://www.samsung.com/vn/smartphones/galaxy-s24-ultra/specs/', 'connectivity.bluetooth': 'https://www.samsung.com/vn/smartphones/galaxy-s24-ultra/specs/', }, + retract_spec_fields: ['regulatory.certifications'], }, // 2. Apple iPhone 16 Pro Max 256GB (Triple Camera + LiDAR Flagship) @@ -606,7 +609,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID BCG-E8695A', sar_head: '1.16 W/kg', sar_body: '1.17 W/kg', - certifications: 'CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -621,6 +623,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.bands_5g': 'https://support.apple.com/vi-vn/121032', 'connectivity.bluetooth': 'https://support.apple.com/en-us/121032', }, + retract_spec_fields: ['regulatory.certifications'], }, // 3. Samsung Galaxy A55 5G 256GB (Mid-range Champion - Triple Camera) @@ -721,7 +724,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID A3LSMA556E', sar_head: '0.68 W/kg', sar_body: '1.04 W/kg', - certifications: 'CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -732,7 +734,11 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ storage: '256GB', ram: '8GB', }, - retract_spec_fields: ['cellular.bands_5g', 'connectivity.bluetooth'], + retract_spec_fields: [ + 'cellular.bands_5g', + 'connectivity.bluetooth', + 'regulatory.certifications', + ], }, // 4. Xiaomi 14 Ultra 5G 16GB/512GB (Quad Camera Leica 1-inch Sensor Flagship) @@ -814,7 +820,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ '8K@24/30fps, 4K@24/30/60/120fps, 1080p@30/60/120/240/480/960/1920fps, gyro-EIS, Dolby Vision HDR 10-bit rec., 4-mic array', }, connectivity: { - bluetooth: '5.4, A2DP, LE, aptX HD, aptX Adaptive, LHDC', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, tri-band, Wi-Fi Direct', usb: 'USB Type-C 3.2 Gen 2 (10Gbps), DisplayPort, OTG', sensors: @@ -843,7 +848,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID 2AFZZPN82G', sar_head: '0.99 W/kg', sar_body: '1.19 W/kg', - certifications: 'CE, FCC, RoHS, TÜV Rheinland Triple Eye Protection, QCVN', }, }, key_specs: { @@ -857,6 +861,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ sources: { 'cellular.bands_5g': 'https://www.mi.com/global/product/xiaomi-14-ultra/specs/', }, + retract_spec_fields: ['connectivity.bluetooth', 'regulatory.certifications'], }, // 5. OPPO Find X8 5G 16GB/256GB (Hasselblad Triple Periscope Flagship) @@ -932,7 +937,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ video_recording: '4K@30/60fps (Dolby Vision 10-bit), 1080p@30/60/240fps, gyro-EIS', }, connectivity: { - bluetooth: '5.4, A2DP, LE, aptX HD, LHDC 5.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6/7, tri-band', usb: 'USB Type-C 3.0, OTG', sensors: @@ -960,7 +964,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'CPH2651', sar_head: '0.98 W/kg', sar_body: '1.12 W/kg', - certifications: 'CE, RoHS, TÜV Rheinland Eye Comfort 4.0, IP69, QCVN', }, }, key_specs: { @@ -975,6 +978,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.bands_5g': 'https://www.oppo.com/vn/smartphones/series-find-x/find-x8/specs/', 'cellular.sim_type': 'https://www.oppo.com/vn/smartphones/series-find-x/find-x8/specs/', }, + retract_spec_fields: ['connectivity.bluetooth', 'regulatory.certifications'], }, // 6. Apple iPad Pro M4 11 inch Wi-Fi 256GB (Tablets Flagship) @@ -1058,10 +1062,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - technology: 'Wi-Fi Only', - sim_type: 'No cellular connectivity (Wi-Fi model)', - volte: false, - vowifi: true, }, multimedia: { loudspeaker: 'Hệ thống 4 loa Four-speaker audio chuẩn phòng thu', @@ -1071,7 +1071,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { fcc_approval: 'FCC ID BCG-A2836', sar_body: '0.95 W/kg', - certifications: 'ENERGY STAR, CE, FCC, QCVN', }, }, key_specs: { @@ -1085,6 +1084,13 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ sources: { 'connectivity.bluetooth': 'https://support.apple.com/en-us/119892', }, + retract_spec_fields: [ + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], }, // 7. Apple MacBook Air 13 inch M3 16GB/256GB (Laptops Flagship) @@ -1149,9 +1155,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ reverse_charging: true, }, camera: { - rear_setup: 'FaceTime HD System', - main_camera: '1080p FaceTime HD camera với bộ xử lý tín hiệu hình ảnh ISP trên chip M3', - second_camera: '3-mic array with directional beamforming (Voice Isolation & Wide Spectrum)', front_camera: '1080p FaceTime HD (f/2.0)', video_recording: '1080p@30fps HD video recording', }, @@ -1166,10 +1169,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - technology: 'Wi-Fi 6E', - sim_type: 'No cellular slot', - volte: false, - vowifi: true, }, multimedia: { loudspeaker: 'Hệ thống 4 loa Four-speaker sound system', @@ -1179,17 +1178,26 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { fcc_approval: 'FCC ID BCGA3113', - certifications: 'ENERGY STAR, EPEAT Gold, CE, FCC, QCVN', }, }, key_specs: { screen: '13.6" Liquid Retina (2560x1664, 500 nits)', chip: 'Apple M3 (8-core CPU / 8-core GPU)', - camera: '1080p FaceTime HD + 3-Mic Studio Array', + camera: '1080p FaceTime HD', battery: '52.6 Wh (Lên tới 18 giờ, MagSafe 3)', storage: '256GB', ram: '16GB', }, + retract_spec_fields: [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], }, // 8. Apple iPhone 16 Pro 256GB (Compact Flagship - Triple Camera 5x) @@ -1294,7 +1302,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID BCG-E8694A', sar_head: '1.09 W/kg', sar_body: '1.19 W/kg', - certifications: 'CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -1311,6 +1318,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'regulatory.sar_head': 'https://www.apple.com/legal/rfexposure/iphone17,1/en/', 'regulatory.sar_body': 'https://www.apple.com/legal/rfexposure/iphone17,1/en/', }, + retract_spec_fields: ['regulatory.certifications'], }, // 9. Apple Watch Series 10 42mm GPS Viền Nhôm (Smartwatches Flagship) @@ -1390,8 +1398,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - volte: false, - vowifi: true, }, multimedia: { loudspeaker: 'Loa tích hợp phát nhạc trực tiếp (Media playback speaker)', @@ -1402,7 +1408,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID BCG-A2997', sar_head: '0.28 W/kg', sar_body: '0.35 W/kg', - certifications: 'CE, FCC, RoHS, WR50, IP6X, QCVN', }, }, key_specs: { @@ -1426,6 +1431,9 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'key_specs.camera', 'cellular.technology', 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', ], }, @@ -1480,7 +1488,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, camera: {}, connectivity: { - bluetooth: '5.3, AAC, Ultra-low latency 20-bit/48kHz Lossless Audio Protocol', + bluetooth: '5.3', usb: 'USB Type-C charging port', sensors: 'Skin-detect sensor, motion-detecting accelerometer, speech-detecting accelerometer, touch control', @@ -1496,13 +1504,15 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { fcc_approval: 'FCC ID BCG-A3047 / A3048', sar_head: '0.09 W/kg', - certifications: 'CE, FCC, RoHS, IP54, QCVN', }, }, key_specs: { chip: 'Apple H2 + Apple U1 Ultra Wideband', battery: '6h tai nghe / 30h hộp sạc (523 mAh)', }, + sources: { + 'connectivity.bluetooth': 'https://support.apple.com/en-us/111836', + }, // Template text an earlier version of this seed wrote: a display, cameras, a cellular // network and phone hardware earbuds do not have (DOS/Rate#1793). retract_spec_fields: [ @@ -1534,6 +1544,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.volte', 'cellular.vowifi', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', 'key_specs.screen', 'key_specs.camera', 'key_specs.storage', @@ -1636,7 +1647,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { fcc_approval: 'FCC ID A3LSMX926B', sar_body: '0.88 W/kg', - certifications: 'CE, FCC, RoHS, IP68, QCVN', }, }, key_specs: { @@ -1653,6 +1663,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'connectivity.bluetooth': 'https://samsungmobilepress.com/media-assets/galaxy-tab-s10-ultra?tab=specs', }, + retract_spec_fields: ['regulatory.certifications'], }, // 12. Xiaomi Pad 6S Pro 12.4 256GB (Tablet High-Value Flagship) @@ -1725,7 +1736,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ video_recording: '4K@30/60fps, 1080p@30/60fps', }, connectivity: { - bluetooth: '5.3, A2DP, LE, LHDC', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6/7, dual-band, Wi-Fi Direct', usb: 'USB Type-C 3.2 Gen 1, DisplayPort, accessory connector', sensors: 'Fingerprint (side-mounted), accelerometer, gyro, proximity, compass', @@ -1735,10 +1745,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - technology: 'Wi-Fi 7 (802.11be) + Bluetooth 5.3', - sim_type: 'Wi-Fi Only', - volte: false, - vowifi: false, }, multimedia: { loudspeaker: '6 loa Stereo (4 woofer + 2 tweeter)', @@ -1748,7 +1754,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { fcc_approval: 'CE / CMIIT ID 2024AP1092', sar_body: '0.72 W/kg', - certifications: 'CE, RoHS, TÜV Rheinland Low Blue Light, QCVN', }, }, key_specs: { @@ -1759,6 +1764,14 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ storage: '256GB UFS 4.0', ram: '8GB LPDDR5X', }, + retract_spec_fields: [ + 'connectivity.bluetooth', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + 'regulatory.certifications', + ], }, // 13. ASUS Zenbook S 14 OLED UX5406 32GB/1TB (Ultrabook Copilot+ PC Flagship) @@ -1821,9 +1834,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ reverse_charging: true, }, camera: { - rear_setup: 'Dual-Sensor AI Webcam & Ambient Color Array', - main_camera: '1080p FHD ASUS AiSense camera with 3DNR', - second_camera: 'Infrared (IR) depth sensor for Windows Hello + Ambient RGB color sensor', front_camera: '1080p FHD IR Webcam supporting Windows Studio Effects', video_recording: '1080p@30fps với AI Noise-Canceling 3D array microphone', }, @@ -1838,10 +1848,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - technology: 'Wi-Fi 7 (802.11be) + Bluetooth 5.4', - sim_type: 'No Cellular Slot (Wi-Fi 7)', - volte: false, - vowifi: false, }, multimedia: { loudspeaker: 'Hệ thống 4 loa Harman Kardon (2 tweeter + 2 woofer) Smart Amp', @@ -1861,6 +1867,15 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ storage: '1TB PCIe 4.0 NVMe SSD', ram: '32GB LPDDR5X-8533', }, + retract_spec_fields: [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + ], }, // 14. Lenovo ThinkPad X1 Carbon Gen 12 32GB/512GB (Enterprise Ultrabook Flagship) @@ -1925,9 +1940,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ reverse_charging: true, }, camera: { - rear_setup: 'Communications Bar Dual-Sensor Array', - main_camera: 'FHD 1080p MIPI Webcam with Privacy Shutter', - second_camera: 'Discrete Infrared (IR) Camera + Ultrasonic Human Presence Detection', front_camera: '1080p FHD + IR Camera with Computer Vision Presence Detection', video_recording: '1080p@30fps với 2 micro 360 độ tầm xa Dolby Voice', }, @@ -1942,10 +1954,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - technology: 'Wi-Fi 6E / Wi-Fi 7 + WWAN Upgradable option', - sim_type: 'Optional Nano-SIM / eSIM on WWAN SKU', - volte: false, - vowifi: false, }, multimedia: { loudspeaker: 'Stereo speakers (2W x2) hidden under keyboard', @@ -1965,6 +1973,15 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ storage: '512GB PCIe 4.0x4 NVMe SSD', ram: '32GB LPDDR5X', }, + retract_spec_fields: [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.technology', + 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', + ], }, // 15. Apple Watch Ultra 2 49mm GPS + Cellular 64GB (Smartwatch Rugged Flagship) @@ -2062,7 +2079,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID BCG-E8411A', sar_head: '0.48 W/kg', sar_body: '0.35 W/kg', - certifications: 'EN13319 Dive Accessory, MIL-STD 810H, IP6X, CE, FCC, QCVN', }, }, key_specs: { @@ -2086,6 +2102,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'camera.video_recording', 'key_specs.camera', 'hardware.storage_expansion', + 'regulatory.certifications', ], }, @@ -2157,7 +2174,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ // (DOS/Rate#1796). camera: {}, connectivity: { - bluetooth: '5.3, A2DP, AVRCP, HFP, HSP', wlan: 'Wi-Fi 802.11 a/b/g/n, dual-band (2.4GHz + 5GHz)', usb: 'Magnetic Wireless Charging Puck', sensors: @@ -2182,7 +2198,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ fcc_approval: 'FCC ID A3LSML705U', sar_head: '0.32 W/kg', sar_body: '0.68 W/kg', - certifications: 'IP68, 10ATM, MIL-STD-810H, CE, FCC, QCVN', }, }, key_specs: { @@ -2203,6 +2218,8 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'hardware.storage_expansion', // Stray CJK text, and no Samsung spec page value for it (DOS/Rate#1798). 'cellular.technology', + 'connectivity.bluetooth', + 'regulatory.certifications', ], }, @@ -2281,8 +2298,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - volte: false, - vowifi: false, }, multimedia: { loudspeaker: 'Beeper cảnh báo Pace / Nhịp tim + Phát nhạc qua tai nghe Bluetooth', @@ -2291,7 +2306,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { fcc_approval: 'FCC ID IPH-04428', - certifications: '5 ATM, CE, FCC, ANT+ Certified, QCVN', }, }, key_specs: { @@ -2312,7 +2326,10 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'key_specs.camera', 'cellular.technology', 'cellular.sim_type', + 'cellular.volte', + 'cellular.vowifi', 'hardware.storage_expansion', + 'regulatory.certifications', ], }, @@ -2366,7 +2383,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, camera: {}, connectivity: { - bluetooth: '5.3, A2DP, AVRCP, HFP, HSP, TMAP, CSIP, MCP, VCP, CCP (SBC, AAC, LDAC, LC3)', usb: 'USB Type-C port', sensors: 'Bone conduction sensor, IR proximity sensor, gyro head-tracking sensor', other: @@ -2381,7 +2397,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { fcc_approval: 'FCC ID AK8YY2963', - certifications: 'Hi-Res Audio Wireless Certified, IPX4, CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -2410,6 +2425,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'camera.second_camera', 'camera.front_camera', 'camera.video_recording', + 'connectivity.bluetooth', 'connectivity.wlan', 'connectivity.location', 'connectivity.nfc', @@ -2419,6 +2435,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.volte', 'cellular.vowifi', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', 'key_specs.screen', 'key_specs.camera', 'key_specs.storage', @@ -2477,8 +2494,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, camera: {}, connectivity: { - bluetooth: - '5.4, A2DP, AVRCP, HFP, PBP, TMAP (SSC HiFi, SSC UHQ 24-bit/96kHz, AAC, SBC, LC3)', usb: 'USB Type-C port', sensors: 'Accelerometer, Gyro Sensor, Hall Sensor, Pressure Sensor, Proximity Sensor, Touch Sensor, VPU', @@ -2493,7 +2508,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { fcc_approval: 'FCC ID A3LSMR630', - certifications: 'IP57, Bluetooth 5.4 SIG, CE, FCC, RoHS, QCVN', }, }, key_specs: { @@ -2522,6 +2536,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'camera.second_camera', 'camera.front_camera', 'camera.video_recording', + 'connectivity.bluetooth', 'connectivity.wlan', 'connectivity.location', 'connectivity.nfc', @@ -2531,6 +2546,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.volte', 'cellular.vowifi', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', 'key_specs.screen', 'key_specs.camera', 'key_specs.storage', @@ -2623,7 +2639,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ technology: 'GSM / HSPA / LTE / 5G', }, connectivity: { - bluetooth: '6.0, A2DP, LE, aptX HD, aptX Adaptive, LHDC 5.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, tri-band, Wi-Fi Direct', usb: 'USB Type-C 3.2 Gen 2, DisplayPort, OTG', nfc: true, @@ -2644,9 +2659,9 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { sar_head: '0.98 W/kg', sar_body: '1.05 W/kg', - certifications: 'CE, FCC, RoHS, TÜV Rheinland Flicker-Free, QCVN (BTTTT Vietnam)', }, }, + retract_spec_fields: ['connectivity.bluetooth', 'regulatory.certifications'], }, { categorySlug: 'smartphones', @@ -2725,7 +2740,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ technology: 'GSM / HSPA / LTE / 5G', }, connectivity: { - bluetooth: '5.4, A2DP, LE, aptX HD, aptX Adaptive, LHDC 5.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, dual-band or tri-band', usb: 'USB Type-C 3.2 Gen 2, DisplayPort, OTG', nfc: true, @@ -2749,6 +2763,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, retract_spec_fields: [ 'cellular.sim_type', + 'connectivity.bluetooth', 'multimedia.audio_features', 'regulatory.certifications', ], @@ -2831,7 +2846,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ technology: 'GSM / HSPA / LTE / 5G', }, connectivity: { - bluetooth: '5.4, A2DP, LE, aptX HD, LHDC 5.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, tri-band', usb: 'USB Type-C 3.2, OTG', nfc: true, @@ -2852,12 +2866,12 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { sar_head: '0.97 W/kg', sar_body: '1.11 W/kg', - certifications: 'CE, RoHS, QCVN (BTTTT Vietnam)', }, }, sources: { 'cellular.sim_type': 'https://www.oppo.com/vn/smartphones/series-find-x/find-x9-pro/specs/', }, + retract_spec_fields: ['connectivity.bluetooth', 'regulatory.certifications'], }, // 29. Apple iPad Pro M5 11 inch 256GB (2025/2026 Flagship Tablet) { @@ -2930,7 +2944,8 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: true, - bands_5g: '5G Sub-6GHz (trên bản Wi-Fi + Cellular)', + bands_5g: + '5G NR n1/n2/n3/n5/n7/n8/n12/n14/n20/n25/n26/n28/n29/n30/n38/n40/n41/n48/n66/n70/n71/n75/n77/n78/n79', bands_4g: 'Gigabit LTE', sim_type: 'eSIM', data_speed: '5G (sub-6 GHz) with 4x4 MIMO, Gigabit LTE with 4x4 MIMO', @@ -2957,13 +2972,14 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { sar_head: '0.98 W/kg', sar_body: '1.12 W/kg', - certifications: 'CE, FCC, Energy Star, QCVN (BTTTT Vietnam)', }, }, sources: { + 'cellular.bands_5g': 'https://www.apple.com/ipad-pro/specs/', 'cellular.data_speed': 'https://www.apple.com/ipad-pro/specs/', 'connectivity.bluetooth': 'https://www.apple.com/ipad-pro/specs/', }, + retract_spec_fields: ['regulatory.certifications'], }, // 30. Xiaomi Pad 7 Pro 256GB (2025/2026 Flagship Android Tablet) { @@ -3036,11 +3052,8 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - sim_type: 'No cellular connectivity (Wi-Fi 7 edition)', - technology: 'Wi-Fi Only', }, connectivity: { - bluetooth: '5.4, A2DP, LE, LHDC 5.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, dual-band, Wi-Fi Direct', usb: 'USB Type-C 3.2 Gen 1, magnetic accessory connector', nfc: true, @@ -3058,14 +3071,19 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { sar_body: '0.89 W/kg', - certifications: 'CE, RoHS, TÜV Low Blue Light, QCVN (BTTTT Vietnam)', }, }, sources: { 'hardware.ram_gb': 'https://www.mi.com/global/product/xiaomi-pad-7-pro/specs/', 'hardware.storage_gb': 'https://www.mi.com/global/product/xiaomi-pad-7-pro/specs/', }, - retract_spec_fields: ['multimedia.audio_features'], + retract_spec_fields: [ + 'cellular.sim_type', + 'cellular.technology', + 'connectivity.bluetooth', + 'multimedia.audio_features', + 'regulatory.certifications', + ], }, // 31. Apple MacBook Air M4 13 inch 256GB (2025/2026 Flagship Ultrabook) { @@ -3117,10 +3135,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ os: 'macOS Sequoia', }, camera: { - rear_setup: 'Dual External 6K Display Engine via Thunderbolt 4', - main_camera: '12MP Center Stage camera with support for Desk View', - second_camera: - 'Desk View Top-Down Workspace Framing + Continuity Camera Wireless iPhone Array', video_recording: '1080p HD video recording with Advanced ISP', front_camera: '12MP Center Stage 1080p FaceTime HD camera', }, @@ -3142,8 +3156,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - sim_type: 'No cellular (Continuity Instant Hotspot via iPhone)', - technology: 'Wi-Fi 6E + Bluetooth 5.3', }, connectivity: { bluetooth: '5.3', @@ -3163,10 +3175,16 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ status: 'Available. Released 2025, March 12', prices_msrp: '26.990.000₫', }, - regulatory: { - certifications: 'ENERGY STAR, EPEAT Gold, CE, FCC, QCVN (BTTTT Vietnam)', - }, + regulatory: {}, }, + retract_spec_fields: [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.sim_type', + 'cellular.technology', + 'regulatory.certifications', + ], }, // 32. Apple MacBook Pro M4 Pro 14 inch 512GB (2025/2026 Flagship Workstation Laptop) { @@ -3191,7 +3209,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ chip: 'Apple M4 Pro (12-core CPU, 16-core GPU)', ram: '24GB', storage: '512GB', - camera: '12MP Center Stage + 3x Thunderbolt 5 (120Gb/s)', + camera: '12MP Center Stage Camera with Desk View', battery: '72.4Wh (22h) 96W MagSafe 3', }, specifications: { @@ -3214,10 +3232,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ os: 'macOS Sequoia', }, camera: { - rear_setup: '3x Thunderbolt 5 (120Gb/s) + HDMI 2.1 (8K@60Hz / 4K@240Hz) + SDXC', - main_camera: '12MP Center Stage camera with Desk View support', - second_camera: - 'Desk View Top-Down Workspace Framing + Studio-Quality 3-Mic Directional Array', video_recording: '1080p HD video recording with computational video ISP', front_camera: '12MP Center Stage 1080p FaceTime HD camera', }, @@ -3239,8 +3253,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: false, - sim_type: 'No cellular', - technology: 'Wi-Fi 6E + Bluetooth 5.3', }, connectivity: { bluetooth: '5.3', @@ -3259,10 +3271,16 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ status: 'Available. Released 2024, November 08', prices_msrp: '49.990.000₫', }, - regulatory: { - certifications: 'ENERGY STAR, EPEAT Gold, CE, FCC, QCVN (BTTTT Vietnam)', - }, + regulatory: {}, }, + retract_spec_fields: [ + 'camera.rear_setup', + 'camera.main_camera', + 'camera.second_camera', + 'cellular.sim_type', + 'cellular.technology', + 'regulatory.certifications', + ], }, // 33. Apple Watch Series 11 46mm GPS 64GB (2025/2026 Flagship Smartwatch) { @@ -3356,7 +3374,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { sar_head: '0.32 W/kg', sar_body: '0.45 W/kg', - certifications: 'FDA Cleared ECG & Sleep Apnea, CE, FCC, QCVN (BTTTT Vietnam)', }, }, sources: { @@ -3373,6 +3390,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'key_specs.camera', 'cellular.technology', 'cellular.sim_type', + 'regulatory.certifications', ], }, // 34. Apple Watch Ultra 3 49mm 64GB (2025/2026 Flagship Adventure Smartwatch) @@ -3442,7 +3460,8 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: { has_5g: true, - bands_5g: '5G RedCap + LTE + Satellite Emergency SOS', + bands_5g: + 'FDD-5G NR n1/n2/n3/n5/n7/n8/n12/n14/n20/n25/n26/n28/n66/n71; TDD-5G NR n38/n40/n41/n53', sim_type: 'eSIM', technology: 'GSM / HSPA / LTE / 5G RedCap / Satellite', }, @@ -3469,10 +3488,10 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ regulatory: { sar_head: '0.38 W/kg', sar_body: '0.52 W/kg', - certifications: 'MIL-STD-810H, EN13319 Dive Certified, CE, FCC, QCVN (BTTTT Vietnam)', }, }, sources: { + 'cellular.bands_5g': 'https://support.apple.com/en-us/125095', 'connectivity.bluetooth': 'https://support.apple.com/en-us/125095', }, // Health sensors as cameras (DOS/Rate#1796). @@ -3483,6 +3502,7 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'camera.front_camera', 'camera.video_recording', 'key_specs.camera', + 'regulatory.certifications', ], }, // 35. Apple AirPods Pro 3 USB-C (2025/2026 Flagship ANC Earbuds) @@ -3533,7 +3553,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: {}, connectivity: { - bluetooth: '5.4, A2DP, LE Audio, AAC-ELD, Apple Lossless Audio Protocol', usb: 'USB Type-C', sensors: 'In-ear heart rate sensor, in-ear temperature sensor, skin-detect sensor, motion-detecting accelerometer, speech-detecting accelerometer', @@ -3550,7 +3569,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { sar_head: '0.09 W/kg', - certifications: 'FDA OTC Hearing Aid Authorized, IP54, CE, FCC, QCVN (BTTTT Vietnam)', }, }, // Template text an earlier version of this seed wrote: a display, cameras, a cellular @@ -3575,10 +3593,12 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.has_5g', 'cellular.sim_type', 'cellular.technology', + 'connectivity.bluetooth', 'connectivity.wlan', 'connectivity.nfc', 'connectivity.location', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', 'key_specs.screen', 'key_specs.ram', 'key_specs.storage', @@ -3640,7 +3660,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, cellular: {}, connectivity: { - bluetooth: '5.4, A2DP, AVRCP, HFP, HSP, TMAP, CSIP, MCP, VCP, CCP (SBC, AAC, LDAC, LC3)', usb: 'USB Type-C + Qi Wireless Charging', sensors: 'Bone conduction sensor, dual proximity sensors, gyro/accelerometer for head gestures', @@ -3657,7 +3676,6 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ }, regulatory: { sar_head: '0.08 W/kg', - certifications: 'Hi-Res Audio Wireless Certified, IPX4, CE, FCC, QCVN (BTTTT Vietnam)', }, }, // Template text an earlier version of this seed wrote: a display, cameras, a cellular @@ -3682,9 +3700,11 @@ export const FLAGSHIP_DEVICES_TO_SEED: FlagshipDeviceSeed[] = [ 'cellular.has_5g', 'cellular.sim_type', 'cellular.technology', + 'connectivity.bluetooth', 'connectivity.wlan', 'connectivity.nfc', 'multimedia.headphone_jack_35mm', + 'regulatory.certifications', 'key_specs.screen', 'key_specs.ram', 'key_specs.storage', diff --git a/apps/importer/src/shopee/flagship-seed-sourced-2026.ts b/apps/importer/src/shopee/flagship-seed-sourced-2026.ts index 025b3738..5759d232 100644 --- a/apps/importer/src/shopee/flagship-seed-sourced-2026.ts +++ b/apps/importer/src/shopee/flagship-seed-sourced-2026.ts @@ -102,7 +102,7 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ sim_type: 'Nano-SIM + eSIM (dual eSIM supported)', }, connectivity: { - bluetooth: '6.0, A2DP, LE', + bluetooth: '6', wlan: 'Wi-Fi 7 (802.11be) 2x2 MIMO, tri-band, hotspot (Apple N1 wireless chip)', usb: 'USB-C, USB 3 (up to 10Gb/s), DisplayPort', nfc: true, @@ -145,6 +145,7 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ 'cellular.sim_type': 'https://www.apple.com/vn/iphone-18-pro/specs/', 'cellular.technology': 'https://www.apple.com/iphone-18-pro/specs/', connectivity: 'https://www.apple.com/iphone-18-pro/specs/', + 'connectivity.bluetooth': 'https://www.apple.com/iphone-18-pro/specs/', multimedia: 'https://www.gsmarena.com/apple_iphone_18_pro_max-14716.php', 'availability.announced': 'https://www.gsmarena.com/apple_iphone_18_pro_max-14716.php', 'availability.vn_sale_date': 'https://cellphones.com.vn/iphone-18-pro.html', @@ -255,7 +256,7 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ sim_type: 'Nano-SIM + eSIM (dual eSIM supported)', }, connectivity: { - bluetooth: '6.0, A2DP, LE', + bluetooth: '6', wlan: 'Wi-Fi 7 (802.11be) 2x2 MIMO, tri-band, hotspot (Apple N1 wireless chip)', usb: 'USB-C, USB 3 (up to 10Gb/s), DisplayPort', nfc: true, @@ -297,6 +298,7 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ 'cellular.sim_type': 'https://www.apple.com/vn/iphone-18-pro/specs/', 'cellular.technology': 'https://www.apple.com/iphone-18-pro/specs/', connectivity: 'https://www.apple.com/iphone-18-pro/specs/', + 'connectivity.bluetooth': 'https://www.apple.com/iphone-18-pro/specs/', multimedia: 'https://www.gsmarena.com/apple_iphone_18_pro_5g-14934.php', 'availability.announced': 'https://www.gsmarena.com/apple_iphone_18_pro_5g-14934.php', 'availability.vn_sale_date': 'https://cellphones.com.vn/iphone-18-pro.html', @@ -415,7 +417,7 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ sim_type: 'Nano-SIM + Nano-SIM + eSIM (max 2 at a time) (International)', }, connectivity: { - bluetooth: '6.0, A2DP, LE', + bluetooth: '6.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, tri-band, Wi-Fi Direct', usb: 'USB Type-C 3.2, DisplayPort 1.2, OTG', sensors: @@ -454,6 +456,8 @@ export const SOURCED_SEEDS_2026: FlagshipDeviceSeed[] = [ 'https://fptshop.com.vn/dien-thoai/samsung-galaxy-s26-ultra', cellular: 'https://www.gsmarena.com/samsung_galaxy_s26_ultra_5g-14320.php', connectivity: 'https://www.gsmarena.com/samsung_galaxy_s26_ultra_5g-14320.php', + 'connectivity.bluetooth': + 'https://www.samsungmobilepress.com/media-assets/galaxy-s26-ultra?tab=specs', multimedia: 'https://www.gsmarena.com/samsung_galaxy_s26_ultra_5g-14320.php', 'availability.announced_status': 'https://www.gsmarena.com/samsung_galaxy_s26_ultra_5g-14320.php', diff --git a/apps/importer/src/shopee/product-normalizer.ts b/apps/importer/src/shopee/product-normalizer.ts index ffcb46cf..45edc65e 100644 --- a/apps/importer/src/shopee/product-normalizer.ts +++ b/apps/importer/src/shopee/product-normalizer.ts @@ -1493,7 +1493,7 @@ const CANONICAL_PHONE_REGISTRY: Record< loudspeaker: 'Yes, stereo speakers', // As the sourced seed states them (DOS/Rate#1761). flash: 'Adaptive True Tone flash', - bluetooth: '6.0, A2DP, LE', + bluetooth: '6', wlan: 'Wi-Fi 7 (802.11be) 2x2 MIMO, tri-band, hotspot (Apple N1 wireless chip)', usb: 'USB-C, USB 3 (up to 10Gb/s), DisplayPort', location: 'Dual-frequency GPS (L1+L5), GLONASS, Galileo, QZSS, BeiDou, NavIC', @@ -1558,7 +1558,7 @@ const CANONICAL_PHONE_REGISTRY: Record< loudspeaker: 'Yes, stereo speakers', // As the sourced seed states them (DOS/Rate#1761). flash: 'Adaptive True Tone flash', - bluetooth: '6.0, A2DP, LE', + bluetooth: '6', wlan: 'Wi-Fi 7 (802.11be) 2x2 MIMO, tri-band, hotspot (Apple N1 wireless chip)', usb: 'USB-C, USB 3 (up to 10Gb/s), DisplayPort', location: 'Dual-frequency GPS (L1+L5), GLONASS, Galileo, QZSS, BeiDou, NavIC', @@ -1625,7 +1625,7 @@ const CANONICAL_PHONE_REGISTRY: Record< // As the sourced seed states them (GSMArena); its sources state no certifications // (DOS/Rate#1761). flash: 'LED flash, laser AF, auto-HDR, panorama', - bluetooth: '6.0, A2DP, LE', + bluetooth: '6.0', wlan: 'Wi-Fi 802.11 a/b/g/n/ac/6e/7, tri-band, Wi-Fi Direct', usb: 'USB Type-C 3.2, DisplayPort 1.2, OTG', location: 'GPS, GLONASS, BDS, GALILEO, QZSS', diff --git a/apps/importer/src/shopee/test-ai-enricher.ts b/apps/importer/src/shopee/test-ai-enricher.ts index feebfd72..691adeb6 100644 --- a/apps/importer/src/shopee/test-ai-enricher.ts +++ b/apps/importer/src/shopee/test-ai-enricher.ts @@ -12,7 +12,6 @@ import http from 'node:http'; import assert from 'node:assert/strict'; import dotenv from 'dotenv'; import { ProductSpecificationsSchema, KeySpecsSchema } from '@repo/shared-data'; -import { getCategorySpecTemplate } from '@repo/shared-data/rules'; import { ProductNormalizer } from './product-normalizer.js'; import { AiSpecEnricher, @@ -25,7 +24,7 @@ import { CANONICAL_BACKFILL_SPECS_BY_MODEL_KEY, FLAGSHIP_DEVICES_TO_SEED, } from './flagship-seed-data.js'; -import { hasSingleRearCamera } from './jobs/backfill-specs.js'; +import { hasSingleRearCamera, statesRearCamera } from './jobs/backfill-specs.js'; import type { ShopeeProduct } from './types.js'; dotenv.config(); @@ -306,9 +305,11 @@ async function runTests() { `Flagship seed ${device.model_key} missing group ${grp}` ); } - // Earbuds and watches have no cameras: their seeds keep the group, empty or not, for - // the spec audit (DOS/Rate#1793). - if (getCategorySpecTemplate(device.categorySlug).groups.includes('camera')) { + // Phones and tablets always state rear cameras; laptops carry only their front webcam, and + // earbuds and watches have no cameras (DOS/Rate#1787, #1793, #1855). + const rearCameraExpected = + device.categorySlug === 'smartphones' || device.categorySlug === 'tablets'; + if (rearCameraExpected || statesRearCamera(device.specifications.camera)) { assert.ok( device.specifications.camera?.main_camera, `Flagship seed ${device.model_key} missing main_camera` @@ -318,6 +319,11 @@ async function runTests() { device.specifications.camera?.second_camera, `Flagship seed ${device.model_key} missing second_camera` ); + } else if (device.categorySlug === 'laptops') { + assert.ok( + device.specifications.camera?.front_camera, + `Flagship seed ${device.model_key} missing front_camera` + ); } console.log( `✅ [Seed Validation] ${device.name} (${device.categorySlug}) -> 10/10 groups, camera=${device.specifications.camera?.rear_setup}` From 56309d8a695ea3ea84e1cd4603bc56c181330e28 Mon Sep 17 00:00:00 2001 From: JOY <5027251+JOY@users.noreply.github.com> Date: Sun, 22 Nov 2026 19:12:49 +0700 Subject: [PATCH 4/4] feat(shared): add 12 Wave 1-3 retail platforms across monorepo (#1859) * feat(shared): add 12 Wave 1-3 retail platforms across monorepo * fix(shared): harden Wave 1-3 URL, SQL, and MV3 parity * fix(shared): address CodeRabbit review threads in web and extension - Scope legacy tgdd- fallback lookups to the parsed retailer platform and prefer canonical tz-/dmx- IDs in inspect, extension lookup, and item-model resolution. - Align non-An Phat URL slug bounds to 120 chars and An Phat externalId bounds to 128 chars across lookup route and OpenAPI spec. - Exclude An Phat smartphone slugs and HACOM sub-series category paths while keeping laptop, tablet, smartwatch, and earbud listings. - Harden DOM active-container price selectors and PicoPix title suffix boundaries, and clarify 22-store lookup vs 10-store observation scope. --- apps/extension/CHROMEWEBSTORE.md | 22 +- apps/extension/RELEASE.md | 25 +- apps/extension/manifest.json | 42 +- apps/extension/src/_locales/cs/messages.json | 14 +- apps/extension/src/_locales/en/messages.json | 14 +- apps/extension/src/_locales/vi/messages.json | 14 +- .../src/background/service-worker.ts | 86 +- .../src/extractors/ecommerce-detector.ts | 666 +++++++++++- apps/extension/src/i18n.ts | 1 + apps/extension/src/security-guards.ts | 24 +- apps/extension/src/sidepanel/sidepanel.ts | 7 +- apps/extension/src/test-extension-pipeline.ts | 997 +++++++++++++++++- apps/extension/src/types.ts | 14 +- .../__tests__/shopee-to-supabase.test.ts | 129 +++ apps/importer/src/shopee/types.ts | 14 +- apps/web/e2e/deals-copy.spec.ts | 6 +- apps/web/locales/cs.json | 60 +- apps/web/locales/en.json | 60 +- apps/web/locales/vi.json | 60 +- apps/web/src/app/api/v1/rate/deals/route.ts | 14 +- .../app/api/v1/rate/extension/ingest/route.ts | 14 +- .../app/api/v1/rate/extension/lookup/route.ts | 4 +- .../components/deals/DealFinderWorkspace.tsx | 2 +- .../components/home/HeroSearchInspector.tsx | 4 +- .../merchants/MerchantDirectoryExplorer.tsx | 12 + .../watchlist/WatchlistWorkspace.tsx | 41 +- apps/web/src/lib/rate-api.ts | 157 ++- apps/web/src/lib/rate-domain-core.ts | 690 +++++++++++- .../__tests__/core-rate-architecture.test.ts | 447 +++++++- apps/web/src/server/rate/api-handler.ts | 14 +- apps/web/src/server/rate/extension.ts | 350 +++++- apps/web/src/server/rate/item-api.ts | 54 +- apps/web/src/server/rate/openapi.ts | 19 +- .../src/__tests__/shared-data.test.ts | 54 +- .../src/rules/extension-observation.ts | 16 +- .../shared-data/src/schemas/specs.schema.ts | 16 + .../test-extension-observations-proposal.mjs | 14 + 37 files changed, 3738 insertions(+), 439 deletions(-) diff --git a/apps/extension/CHROMEWEBSTORE.md b/apps/extension/CHROMEWEBSTORE.md index 22eac929..ce1ebf10 100644 --- a/apps/extension/CHROMEWEBSTORE.md +++ b/apps/extension/CHROMEWEBSTORE.md @@ -1,6 +1,6 @@ # Chrome Web Store Listing & Compliance - Rate.vn Browser Extension (MV3) -- **Last Updated:** 2026-11-19 +- **Last Updated:** 2026-11-22 - **Current Version:** 2.0.0 - **Category:** Shopping @@ -14,11 +14,11 @@ Rate.vn - So Sánh Giá, Lịch Sử Giá & Lọc Đánh Giá Ảo AI ### Short Summary (<= 132 characters) -Xem lịch sử giá 90 ngày, phát hiện giảm giá ảo, tìm nơi bán rẻ hơn, lọc đánh giá ảo bằng AI trên 10 sàn và chuỗi bán lẻ Việt Nam. +Xem lịch sử giá 90 ngày, phát hiện giảm giá ảo, tìm nơi bán rẻ hơn, lọc đánh giá ảo bằng AI trên 22 sàn và chuỗi bán lẻ Việt Nam. ### Detailed Description -Rate.vn giúp người tiêu dùng mua sắm đồ công nghệ minh bạch và tiết kiệm hơn ngay khi đang xem sản phẩm trên Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, FPT Shop, Hoàng Hà Mobile, Di Động Việt và Phong Vũ: +Rate.vn giúp người tiêu dùng mua sắm đồ công nghệ minh bạch và tiết kiệm hơn ngay khi đang xem sản phẩm trên Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà Mobile, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone và An Phát Computer: - Phát hiện Giảm Giá Ảo: Tự động đối chiếu mức giá hiện tại và mức giá gạch ngang với lịch sử giá đã xác minh để nhận diện khuyến mãi thật hay nâng giá gốc rồi giảm ảo. - So Sánh Giá Đa Sàn Tức Thì: Hiển thị ngay các gian hàng chính hãng khác đang bán cùng mẫu điện thoại, máy tính bảng, laptop với mức giá thấp hơn. @@ -32,20 +32,20 @@ Rate.vn giúp người tiêu dùng mua sắm đồ công nghệ minh bạch và This table lists exactly what `manifest.json` requests; `test-extension-pipeline.ts` fails when the two disagree (DOS/Rate#1231). -| Permission / Host Permission | Plain-English Justification | -| :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `storage` | Saves the user's preferred Rate.vn server endpoint, a temporary product lookup cache for the active session, and the user's explicit opt-in preference for contributing product price signals. | -| `sidePanel` | Displays the price history chart, cross-merchant price comparison table and AI review authenticity breakdown beside the shopping page when the user clicks the extension badge or floating pill. | -| `https://shopee.vn/*`, `https://*.lazada.vn/*`, `https://tiki.vn/*`, `https://www.tiktok.com/*`, `https://shop.tiktok.com/*`, `https://cellphones.com.vn/*`, `https://thegioididong.com/*`, `https://*.thegioididong.com/*`, `https://topzone.vn/*`, `https://*.topzone.vn/*`, `https://dienmayxanh.com/*`, `https://*.dienmayxanh.com/*`, `https://fptshop.com.vn/*`, `https://hoanghamobile.com/*`, `https://didongviet.vn/*`, `https://phongvu.vn/*` | Runs the content script on the 10 supported Vietnamese stores (including Thế Giới Di Động's sister storefronts `topzone.vn` and `dienmayxanh.com`). It reads the public product title, selected variant, listed price, original price and rating of a product page to show the floating price-check badge. The script loads on every page of these sites because they navigate in-page, but it reads and sends nothing on pages it does not recognise as a product page. On `www.tiktok.com` it loads only on product page paths (`/view/product/`, `/@shop/product/`, `/shop/.../pdp/`), not on the video feed or video pages (DOS/Rate#1601). A product page reached by in-page navigation from the feed gets the badge after a reload; `shop.tiktok.com` serves only shop pages (DOS/Rate#1232). | -| `https://rate.vn/*`, `https://www.rate.vn/*` | Fetches verified price history, cross-merchant offers and review authenticity scores from the Rate.vn API, and sends the opt-in crowd signal. | +| Permission / Host Permission | Plain-English Justification | +| :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `storage` | Saves the user's preferred Rate.vn server endpoint, a temporary product lookup cache for the active session, and the user's explicit opt-in preference for contributing product price signals. | +| `sidePanel` | Displays the price history chart, cross-merchant price comparison table and AI review authenticity breakdown beside the shopping page when the user clicks the extension badge or floating pill. | +| `https://shopee.vn/*`, `https://*.lazada.vn/*`, `https://tiki.vn/*`, `https://www.tiktok.com/*`, `https://shop.tiktok.com/*`, `https://cellphones.com.vn/*`, `https://thegioididong.com/*`, `https://*.thegioididong.com/*`, `https://topzone.vn/*`, `https://*.topzone.vn/*`, `https://dienmayxanh.com/*`, `https://*.dienmayxanh.com/*`, `https://fptshop.com.vn/*`, `https://hoanghamobile.com/*`, `https://didongviet.vn/*`, `https://phongvu.vn/*`, `https://gearvn.com/*`, `https://*.gearvn.com/*`, `https://nguyenkim.com/*`, `https://*.nguyenkim.com/*`, `https://shopdunk.com/*`, `https://*.shopdunk.com/*`, `https://hacom.vn/*`, `https://*.hacom.vn/*`, `https://clickbuy.com.vn/*`, `https://*.clickbuy.com.vn/*`, `https://viettelstore.vn/*`, `https://*.viettelstore.vn/*`, `https://pico.vn/*`, `https://*.pico.vn/*`, `https://mediamart.vn/*`, `https://*.mediamart.vn/*`, `https://memoryzone.com.vn/*`, `https://*.memoryzone.com.vn/*`, `https://anphatpc.com.vn/*`, `https://*.anphatpc.com.vn/*` | Runs the content script on the 22 supported Vietnamese stores. It reads the public product title, selected variant, listed price, original price and rating of a product page to show the floating price-check badge. The script loads on every page of these sites because they navigate in-page, but it reads and sends nothing on pages it does not recognise as a product page. On `www.tiktok.com` it loads only on product page paths (`/view/product/`, `/@shop/product/`, `/shop/.../pdp/`), not on the video feed or video pages (DOS/Rate#1601). A product page reached by in-page navigation from the feed gets the badge after a reload; `shop.tiktok.com` serves only shop pages (DOS/Rate#1232). | +| `https://rate.vn/*`, `https://www.rate.vn/*` | Fetches verified price history, cross-merchant offers and review authenticity scores from the Rate.vn API, and sends the opt-in crowd signal. | --- ## 3. Privacy & User Data Disclosure -1. **Where it runs:** the content script loads on the 10 supported stores listed above (`shopee.vn`, `lazada.vn`, `tiki.vn`, TikTok Shop product pages on `www.tiktok.com` and `shop.tiktok.com`, `cellphones.com.vn`, `thegioididong.com` and its sister storefronts `topzone.vn` and `dienmayxanh.com`, `fptshop.com.vn`, `hoanghamobile.com`, `didongviet.vn`, `phongvu.vn`). It acts only on pages it recognises as a product page. The extension itself never opens or fetches pages the user did not open, never works around a store's bot checks and never solves captchas. +1. **Where it runs:** the content script loads on the 22 supported stores listed above (`shopee.vn`, `lazada.vn`, `tiki.vn`, TikTok Shop product pages on `www.tiktok.com` and `shop.tiktok.com`, `cellphones.com.vn`, `thegioididong.com`, `topzone.vn`, `dienmayxanh.com`, `fptshop.com.vn`, `hoanghamobile.com`, `didongviet.vn`, `phongvu.vn`, `gearvn.com`, `nguyenkim.com`, `shopdunk.com`, `hacom.vn`, `clickbuy.com.vn`, `viettelstore.vn`, `pico.vn`, `mediamart.vn`, `memoryzone.com.vn`, `anphatpc.com.vn`). It acts only on pages it recognises as a product page. The extension itself never opens or fetches pages the user did not open, never works around a store's bot checks and never solves captchas. 2. **Lookup (on by default, no opt-in):** on a recognised product page the extension sends `GET /api/v1/rate/extension/lookup` with the store, the product URL with query parameters and tracking tokens (`utm_*`, `sp_atk`, `xptdk`, `fbclid`, `gclid`) stripped locally, the product title, the store's item id and shop id, the selected variant, the listed price and the original price. The request is read-only and carries no account, name, email or cookies. -3. **Opt-in observation (off by default):** only when the user chooses "Có" / "Yes" on the consent page opened once at first install, or turns on "Đóng góp phát hiện sản phẩm mới (chỉ khi bạn bật)" (English: "Help find new products (only when you turn it on)") in the Side Panel, the extension sends an ExtensionObservation v1 to `POST /api/v1/rate/extension/observation`: the store, the cleaned URL (no query), the item and shop ids, the variant id (SKU), the selected variant, the price, the original price, the stock status and quantity, the time the user saw the price and the extension version, with how the page was read (DOS/Rate#1606). It carries a random submitter id for the install, obtained once from `POST /api/v1/rate/extension/submitter`. No title, no ratings, no account data. The toggle's label and the consent page list these same fields; a test ties them to the payload. Observations go to a quarantine, stored with the time received and a salted hash of the network range (never the IP) to tell independent senders apart; the hash is deleted after 28 days and observations after 180 days. Rate.vn's servers may re-check the listing on the store. They never change public prices directly. Turning the opt-in off calls `DELETE /api/v1/rate/extension/submitter`, which deletes the id and every observation sent with it; the extension keeps retrying that erasure until the server confirms it. Uninstalling without turning it off leaves the observations to the 180-day purge. An opt-in given to the older crowd signal is not taken as consent to this: after the update it is off and the consent page asks again. Closing the consent page keeps the opt-in off, and updates or reloads do not open it again (DOS/Rate#1603). +3. **Opt-in observation (off by default):** only when the user chooses "Có" / "Yes" on the consent page opened once at first install, or turns on "Đóng góp phát hiện sản phẩm mới (chỉ khi bạn bật)" (English: "Help find new products (only when you turn it on)") in the Side Panel, the extension sends an ExtensionObservation v1 to `POST /api/v1/rate/extension/observation` on the 10 quarantine-enabled stores (`shopee.vn`, `lazada.vn`, `tiki.vn`, `www.tiktok.com` and `shop.tiktok.com`, `cellphones.com.vn`, `thegioididong.com`, `fptshop.com.vn`, `hoanghamobile.com`, `didongviet.vn`, `phongvu.vn`; the remaining 12 retail chains are read-only lookup-only for now): the store, the cleaned URL (no query), the item and shop ids, the variant id (SKU), the selected variant, the price, the original price, the stock status and quantity, the time the user saw the price and the extension version, with how the page was read (DOS/Rate#1606). It carries a random submitter id for the install, obtained once from `POST /api/v1/rate/extension/submitter`. No title, no ratings, no account data. The toggle's label and the consent page list these same fields; a test ties them to the payload. Observations go to a quarantine, stored with the time received and a salted hash of the network range (never the IP) to tell independent senders apart; the hash is deleted after 28 days and observations after 180 days. Rate.vn's servers may re-check the listing on the store. They never change public prices directly. Turning the opt-in off calls `DELETE /api/v1/rate/extension/submitter`, which deletes the id and every observation sent with it; the extension keeps retrying that erasure until the server confirms it. Uninstalling without turning it off leaves the observations to the 180-day purge. An opt-in given to the older crowd signal is not taken as consent to this: after the update it is off and the consent page asks again. Closing the consent page keeps the opt-in off, and updates or reloads do not open it again (DOS/Rate#1603). 4. **Stored in the browser only:** the server address, the opt-in choice and, while the user contributes, the submitter id (`chrome.storage.local`), and a session-only cache of the products viewed in each tab, the latest side panel search, their lookup results and a lookup wait time after a rate limit (`chrome.storage.session`). 5. **IP address:** like any web request, the Rate.vn server receives the user's IP address. The lookup and observation routes use it in memory for a per-minute request limit; the observation routes also derive the salted network-range hash above from it. Rate.vn's code never stores the IP itself; the hosting provider keeps standard access logs for a short time. 6. **Side panel requests:** text the user types into the side panel search is sent to the same lookup endpoint; the side panel also reads public deals and merchant lists from the Rate.vn API. diff --git a/apps/extension/RELEASE.md b/apps/extension/RELEASE.md index 83a56311..dd3f7b90 100644 --- a/apps/extension/RELEASE.md +++ b/apps/extension/RELEASE.md @@ -4,18 +4,18 @@ Release-readiness check of the extension built from `dev` at `fc9b820d` on 2026- ## 1. Readiness check (2026-10-30) -| Check | Result | Evidence | -| :--------------------------------------------- | :------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| Build (`pnpm --filter @repo/extension build`) | Pass | `dist/` holds 11 files, 936 KB. The manifest is MV3, version `2.0.0`. | -| Extension tests, typecheck, lint | Pass | `test-extension-pipeline.ts` passes, including #1302, #1304 and #1326; `eslint --max-warnings 0` is clean. | -| Manifest permissions match `CHROMEWEBSTORE.md` | Pass | `storage` and `sidePanel`; 11 store host patterns (10 stores, TikTok on two hosts) plus `rate.vn` and `www.rate.vn`. The content-script matches cover the same origins; on `www.tiktok.com` they are limited to product page paths (#1601). The pipeline test enforces this (#1231). | -| `review_risk_score: null` shown as no data | Pass | The live lookup returns `null` for a seller with no analysed review, and the side panel shows `reviewRiskNoData` (#1266). | -| `dosafe_risk_score: null` | Fixed in #1465 (PR #1476) | A seller with no DOSafe score answers null from the API and reads "chưa đủ dữ liệu" in the side panel, never "0". | -| Verdict `messageKey` and the locale catalogue | Pass | All 10 server keys (`apps/web/src/server/rate/extension.ts`) map in `VERDICT_MESSAGES`. Every label and explanation exists in vi, en and cs with the right placeholder count. The live lookup returns `genuine_deal` and `fair_market` with their params. | -| Lookup ranking (#1379) | Pass | Live lookup of "Apple iPhone 16 128GB" matches `apple-iphone-16-128gb`, not the 16e. | -| 429 handling | Fixed in #1466 | After a 429 the extension sends no lookup until `Retry-After` (default 60 s, cap 600 s), the panel says how many seconds to wait, and the pill looks the product up again once the wait is over. | -| No locale sent | Pass | The lookup sends platform, URL, title, mode, ids, variant and prices, but no locale. The verdict is rendered from `messageKey` in the extension's language. | -| Version header | Fixed in #1466 | `X-Rate-Extension-Version` reads `chrome.runtime.getManifest().version`. | +| Check | Result | Evidence | +| :--------------------------------------------- | :------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Build (`pnpm --filter @repo/extension build`) | Pass | `dist/` holds 11 files, 936 KB. The manifest is MV3, version `2.0.0`. | +| Extension tests, typecheck, lint | Pass | `test-extension-pipeline.ts` passes, including #1302, #1304 and #1326; `eslint --max-warnings 0` is clean. | +| Manifest permissions match `CHROMEWEBSTORE.md` | Pass | `storage` and `sidePanel`; 36 store host patterns across 22 stores (TikTok on two hosts, 13 retail chains on bare + subdomain patterns) plus `rate.vn` and `www.rate.vn`. The content-script matches cover the same origins; on `www.tiktok.com` they are limited to product page paths (#1601). The pipeline test enforces this (#1231, #1850). | +| `review_risk_score: null` shown as no data | Pass | The live lookup returns `null` for a seller with no analysed review, and the side panel shows `reviewRiskNoData` (#1266). | +| `dosafe_risk_score: null` | Fixed in #1465 (PR #1476) | A seller with no DOSafe score answers null from the API and reads "chưa đủ dữ liệu" in the side panel, never "0". | +| Verdict `messageKey` and the locale catalogue | Pass | All 10 server keys (`apps/web/src/server/rate/extension.ts`) map in `VERDICT_MESSAGES`. Every label and explanation exists in vi, en and cs with the right placeholder count. The live lookup returns `genuine_deal` and `fair_market` with their params. | +| Lookup ranking (#1379) | Pass | Live lookup of "Apple iPhone 16 128GB" matches `apple-iphone-16-128gb`, not the 16e. | +| 429 handling | Fixed in #1466 | After a 429 the extension sends no lookup until `Retry-After` (default 60 s, cap 600 s), the panel says how many seconds to wait, and the pill looks the product up again once the wait is over. | +| No locale sent | Pass | The lookup sends platform, URL, title, mode, ids, variant and prices, but no locale. The verdict is rendered from `messageKey` in the extension's language. | +| Version header | Fixed in #1466 | `X-Rate-Extension-Version` reads `chrome.runtime.getManifest().version`. | ## 2. Release checklist (JOY publishes) @@ -28,6 +28,7 @@ Release-readiness check of the extension built from `dev` at `fc9b820d` on 2026- - **Opt-in:** the crowd opt-in is off by default, and its label names the fields it sends (#1230, #1241). - **Contribution erasure:** with the observation routes on, opt in, open a product page, then turn the opt-in off: the server holds no observation for the install's id afterwards, and with the network off the erasure is retried at the next start (#1606). - **Consent page:** a fresh install opens the consent page once, with "No" focused. Closing it leaves the opt-in off; "Yes" turns on the side panel toggle; reloading or updating the extension does not open it again (#1603). + - **Host-permission upgrade & re-enable:** install the previous packaged release first, then update in place without uninstalling. Confirm Chrome shows the new host-permission prompt when additional store patterns are introduced; in the release notes and support copy, tell existing users whose install Chrome pauses for new permissions to click the puzzle-piece Extensions menu (or open `chrome://extensions`), select Rate.vn, and click "Accept permissions" / re-enable the toggle so store lookup resumes. 5. Update the store listing: - Description and screenshots match the panel as it is now (the price list and the states from #1319). - The changelog below. diff --git a/apps/extension/manifest.json b/apps/extension/manifest.json index 788ff6ab..1ea7e241 100644 --- a/apps/extension/manifest.json +++ b/apps/extension/manifest.json @@ -43,6 +43,26 @@ "https://hoanghamobile.com/*", "https://didongviet.vn/*", "https://phongvu.vn/*", + "https://gearvn.com/*", + "https://*.gearvn.com/*", + "https://nguyenkim.com/*", + "https://*.nguyenkim.com/*", + "https://shopdunk.com/*", + "https://*.shopdunk.com/*", + "https://hacom.vn/*", + "https://*.hacom.vn/*", + "https://clickbuy.com.vn/*", + "https://*.clickbuy.com.vn/*", + "https://viettelstore.vn/*", + "https://*.viettelstore.vn/*", + "https://pico.vn/*", + "https://*.pico.vn/*", + "https://mediamart.vn/*", + "https://*.mediamart.vn/*", + "https://memoryzone.com.vn/*", + "https://*.memoryzone.com.vn/*", + "https://anphatpc.com.vn/*", + "https://*.anphatpc.com.vn/*", "https://rate.vn/*", "https://www.rate.vn/*" ], @@ -66,7 +86,27 @@ "https://fptshop.com.vn/*", "https://hoanghamobile.com/*", "https://didongviet.vn/*", - "https://phongvu.vn/*" + "https://phongvu.vn/*", + "https://gearvn.com/*", + "https://*.gearvn.com/*", + "https://nguyenkim.com/*", + "https://*.nguyenkim.com/*", + "https://shopdunk.com/*", + "https://*.shopdunk.com/*", + "https://hacom.vn/*", + "https://*.hacom.vn/*", + "https://clickbuy.com.vn/*", + "https://*.clickbuy.com.vn/*", + "https://viettelstore.vn/*", + "https://*.viettelstore.vn/*", + "https://pico.vn/*", + "https://*.pico.vn/*", + "https://mediamart.vn/*", + "https://*.mediamart.vn/*", + "https://memoryzone.com.vn/*", + "https://*.memoryzone.com.vn/*", + "https://anphatpc.com.vn/*", + "https://*.anphatpc.com.vn/*" ], "exclude_matches": ["https://www.tiktok.com/@*/video/*"], "js": ["content/content-script.js"], diff --git a/apps/extension/src/_locales/cs/messages.json b/apps/extension/src/_locales/cs/messages.json index 4500f7ae..d78236e5 100644 --- a/apps/extension/src/_locales/cs/messages.json +++ b/apps/extension/src/_locales/cs/messages.json @@ -3,7 +3,7 @@ "message": "Rate.vn - Porovnání cen, historie cen a AI filtr falešných recenzí" }, "extDescription": { - "message": "Historie cen za 90 dní, odhalení falešných slev, levnější prodejci a AI filtr falešných recenzí v 10 vietnamských obchodech." + "message": "Historie cen za 90 dní, odhalení falešných slev, levnější prodejci a AI filtr falešných recenzí ve 22 vietnamských obchodech." }, "actionTitle": { "message": "Otevřít panel cen a důvěryhodnosti Rate.vn" @@ -276,7 +276,7 @@ "message": "Body historie cen se stále sbírají." }, "radarDealsTitle": { - "message": "Skutečné slevy pod mediánem (10 obchodů)" + "message": "Skutečné slevy pod mediánem (22 obchodů)" }, "radarSavings": { "message": "Ušetříte $AMOUNT$ (-$PCT$ %)", @@ -335,7 +335,7 @@ "message": "nedostatek dat" }, "merchantDirTitle": { - "message": "Důvěryhodnost prodejců v 10 obchodech ($COUNT$)", + "message": "Důvěryhodnost prodejců ve 22 obchodech ($COUNT$)", "placeholders": { "count": { "content": "$1" @@ -398,10 +398,10 @@ } }, "noProductStores": { - "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, FPT Shop, Hoàng Hà Mobile, Di Động Việt" + "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà Mobile, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone" }, "noProductLastStore": { - "message": "Phong Vũ" + "message": "An Phát Computer" }, "variantPickerTitle": { "message": "Zvolte prohlíženou variantu úložiště" @@ -514,7 +514,7 @@ } }, "radarPillSpread": { - "message": "Rozdíl v 10 obchodech $PCT$ %", + "message": "Rozdíl mezi obchody $PCT$ %", "placeholders": { "pct": { "content": "$1" @@ -673,7 +673,7 @@ "message": "Rate.vn je připraveno" }, "onboardingLookup": { - "message": "Na stránkách produktů 10 podporovaných obchodů rozšíření posílá Rate.vn obchod, URL bez parametrů, název, ID produktu a obchodu, variantu, cenu a původní cenu, aby vyhledalo historii cen. Účet není potřeba." + "message": "Na stránkách produktů 22 podporovaných obchodů rozšíření posílá Rate.vn obchod, URL bez parametrů, název, ID produktu a obchodu, variantu, cenu a původní cenu, aby vyhledalo historii cen. Účet není potřeba." }, "onboardingQuestion": { "message": "Chcete přispívat nabídkami, které si prohlížíte?" diff --git a/apps/extension/src/_locales/en/messages.json b/apps/extension/src/_locales/en/messages.json index 6331dae3..515e4a6b 100644 --- a/apps/extension/src/_locales/en/messages.json +++ b/apps/extension/src/_locales/en/messages.json @@ -3,7 +3,7 @@ "message": "Rate.vn - Price Comparison, Price History & AI Fake Review Filter" }, "extDescription": { - "message": "Check 90-day price history, spot fake discounts, find cheaper sellers and filter fake reviews with AI on 10 Vietnamese stores." + "message": "Check 90-day price history, spot fake discounts, find cheaper sellers and filter fake reviews with AI on 22 Vietnamese stores." }, "actionTitle": { "message": "Open the Rate.vn price and trust panel" @@ -276,7 +276,7 @@ "message": "Still collecting price history points." }, "radarDealsTitle": { - "message": "Genuine deals below the median (10 stores)" + "message": "Genuine deals below the median (22 stores)" }, "radarSavings": { "message": "Save $AMOUNT$ (-$PCT$%)", @@ -335,7 +335,7 @@ "message": "not enough data" }, "merchantDirTitle": { - "message": "Seller trust across 10 stores ($COUNT$)", + "message": "Seller trust across 22 stores ($COUNT$)", "placeholders": { "count": { "content": "$1" @@ -398,10 +398,10 @@ } }, "noProductStores": { - "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, FPT Shop, Hoàng Hà Mobile, Di Động Việt" + "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà Mobile, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone" }, "noProductLastStore": { - "message": "Phong Vũ" + "message": "An Phát Computer" }, "variantPickerTitle": { "message": "Choose the Storage Variant You Are Viewing" @@ -514,7 +514,7 @@ } }, "radarPillSpread": { - "message": "10-store gap $PCT$%", + "message": "Cross-store gap $PCT$%", "placeholders": { "pct": { "content": "$1" @@ -673,7 +673,7 @@ "message": "Rate.vn is ready" }, "onboardingLookup": { - "message": "On product pages of the 10 supported stores, the extension sends Rate.vn the store, the URL without parameters, the title, the item and shop ids, the variant, the price and the original price to look up price history. No account needed." + "message": "On product pages of the 22 supported stores, the extension sends Rate.vn the store, the URL without parameters, the title, the item and shop ids, the variant, the price and the original price to look up price history. No account needed." }, "onboardingQuestion": { "message": "Would you like to contribute the listings you view?" diff --git a/apps/extension/src/_locales/vi/messages.json b/apps/extension/src/_locales/vi/messages.json index 423ff326..c1b7d440 100644 --- a/apps/extension/src/_locales/vi/messages.json +++ b/apps/extension/src/_locales/vi/messages.json @@ -3,7 +3,7 @@ "message": "Rate.vn - So Sánh Giá, Lịch Sử Giá & Lọc Đánh Giá Ảo AI" }, "extDescription": { - "message": "Xem lịch sử giá 90 ngày, phát hiện giảm giá ảo, tìm nơi bán rẻ hơn, lọc đánh giá ảo bằng AI trên 10 sàn và chuỗi bán lẻ Việt Nam." + "message": "Xem lịch sử giá 90 ngày, phát hiện giảm giá ảo, tìm nơi bán rẻ hơn, lọc đánh giá ảo bằng AI trên 22 sàn và chuỗi bán lẻ Việt Nam." }, "actionTitle": { "message": "Mở bảng phân tích giá & độ tin cậy Rate.vn" @@ -276,7 +276,7 @@ "message": "Đang tích lũy thêm các mốc thời gian lịch sử giá." }, "radarDealsTitle": { - "message": "Deal thật dưới giá trung vị (10 sàn)" + "message": "Deal thật dưới giá trung vị (22 sàn)" }, "radarSavings": { "message": "Tiết kiệm $AMOUNT$ (-$PCT$%)", @@ -335,7 +335,7 @@ "message": "chưa đủ dữ liệu" }, "merchantDirTitle": { - "message": "Độ tin cậy gian hàng trên 10 sàn ($COUNT$)", + "message": "Độ tin cậy gian hàng trên 22 sàn ($COUNT$)", "placeholders": { "count": { "content": "$1" @@ -398,10 +398,10 @@ } }, "noProductStores": { - "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, FPT Shop, Hoàng Hà Mobile, Di Động Việt" + "message": "Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, Thế Giới Di Động, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà Mobile, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone" }, "noProductLastStore": { - "message": "Phong Vũ" + "message": "An Phát Computer" }, "variantPickerTitle": { "message": "Chọn Phiên Bản Bộ Nhớ Đang Xem" @@ -514,7 +514,7 @@ } }, "radarPillSpread": { - "message": "Lệch 10 sàn $PCT$%", + "message": "Lệch đa sàn $PCT$%", "placeholders": { "pct": { "content": "$1" @@ -673,7 +673,7 @@ "message": "Rate.vn đã sẵn sàng" }, "onboardingLookup": { - "message": "Trên trang sản phẩm của 10 sàn được hỗ trợ, tiện ích gửi cho Rate.vn sàn, URL đã bỏ tham số, tên, mã sản phẩm và mã gian hàng, phiên bản, giá bán và giá gốc để tra lịch sử giá. Không cần tài khoản." + "message": "Trên trang sản phẩm của 22 sàn được hỗ trợ, tiện ích gửi cho Rate.vn sàn, URL đã bỏ tham số, tên, mã sản phẩm và mã gian hàng, phiên bản, giá bán và giá gốc để tra lịch sử giá. Không cần tài khoản." }, "onboardingQuestion": { "message": "Bạn có muốn đóng góp các tin bán bạn xem không?" diff --git a/apps/extension/src/background/service-worker.ts b/apps/extension/src/background/service-worker.ts index 029c94ec..efa22835 100644 --- a/apps/extension/src/background/service-worker.ts +++ b/apps/extension/src/background/service-worker.ts @@ -1,8 +1,5 @@ import { RATE_API_V1_ENDPOINTS } from '@repo/shared-data'; -import { - EXTENSION_MARKETPLACES, - isExtensionMarketplaceHost, -} from '@repo/shared-data/rules'; +import { EXTENSION_MARKETPLACES } from '@repo/shared-data/rules'; import type { ExtensionLookupData, ExtensionSettings, @@ -153,18 +150,12 @@ async function fetchExtensionLookup( ); } -const SUPPORTED_CROWD_PLATFORMS = new Set([ - 'shopee', - 'lazada', - 'tiki', - 'tiktok', - 'cellphones', - 'tgdd', - 'fptshop', - 'hoangha', - 'didongviet', - 'phongvu', -]); +// Opt-in ExtensionObservation v1 quarantine remains restricted to the 10 +// SQL-checked marketplaces (`EXTENSION_MARKETPLACES`) until a coordinated +// `DOS-Me` PostgreSQL migration widens `rate.extension_observations` (#1850). +const SUPPORTED_CROWD_PLATFORMS: ReadonlySet = new Set( + EXTENSION_MARKETPLACES +); const QUICK_QUERY_BARE_MARKETPLACE_DOMAINS = [ 'shopee.vn', @@ -179,6 +170,16 @@ const QUICK_QUERY_BARE_MARKETPLACE_DOMAINS = [ 'hoanghamobile.com', 'didongviet.vn', 'phongvu.vn', + 'gearvn.com', + 'nguyenkim.com', + 'shopdunk.com', + 'hacom.vn', + 'clickbuy.com.vn', + 'viettelstore.vn', + 'pico.vn', + 'mediamart.vn', + 'memoryzone.com.vn', + 'anphatpc.com.vn', ] as const; function normalizeQuickQueryBareMarketplaceUrl( @@ -231,6 +232,53 @@ interface VerifiedMarketplaceUrl { origin: string; } +/** + * Exact store hosts permitted by `manifest.json` `host_permissions` across all + * 22 supported Vietnamese stores. A leading `.` allows valid `[a-z0-9-]+` + * subdomains as well as the bare base domain. + */ +const ALLOWED_EXTENSION_STORE_HOSTS: Readonly< + Record +> = { + shopee: ['shopee.vn'], + lazada: ['lazada.vn', '.lazada.vn'], + tiki: ['tiki.vn'], + tiktok: ['www.tiktok.com', 'shop.tiktok.com'], + cellphones: ['cellphones.com.vn'], + tgdd: ['thegioididong.com', '.thegioididong.com'], + dienmayxanh: ['dienmayxanh.com', '.dienmayxanh.com'], + topzone: ['topzone.vn', '.topzone.vn'], + fptshop: ['fptshop.com.vn'], + hoangha: ['hoanghamobile.com'], + didongviet: ['didongviet.vn'], + phongvu: ['phongvu.vn'], + gearvn: ['gearvn.com', '.gearvn.com'], + nguyenkim: ['nguyenkim.com', '.nguyenkim.com'], + shopdunk: ['shopdunk.com', '.shopdunk.com'], + hacom: ['hacom.vn', '.hacom.vn'], + clickbuy: ['clickbuy.com.vn', '.clickbuy.com.vn'], + viettelstore: ['viettelstore.vn', '.viettelstore.vn'], + pico: ['pico.vn', '.pico.vn'], + mediamart: ['mediamart.vn', '.mediamart.vn'], + memoryzone: ['memoryzone.com.vn', '.memoryzone.com.vn'], + anphatpc: ['anphatpc.com.vn', '.anphatpc.com.vn'], +}; + +function isAllowedExtensionStoreHost( + platform: SupportedEcommercePlatform, + host: string +): boolean { + const h = host.toLowerCase(); + return ALLOWED_EXTENSION_STORE_HOSTS[platform].some((allowed) => { + if (!allowed.startsWith('.')) return h === allowed; + if (h === allowed.slice(1)) return true; + if (!h.endsWith(allowed)) return false; + return /^(?:[a-z0-9-]+\.)+$/.test( + h.slice(0, h.length - allowed.length + 1) + ); + }); +} + function resolvePositiveIntId(value: unknown): number | undefined { return typeof value === 'number' && Number.isInteger(value) && value > 0 ? value @@ -264,8 +312,10 @@ function resolveMarketplaceFromHttpsUrl( ) { return null; } - for (const marketplace of EXTENSION_MARKETPLACES) { - if (isExtensionMarketplaceHost(marketplace, host)) { + for (const marketplace of Object.keys( + ALLOWED_EXTENSION_STORE_HOSTS + ) as SupportedEcommercePlatform[]) { + if (isAllowedExtensionStoreHost(marketplace, host)) { return { marketplace, origin: parsed.origin.toLowerCase() }; } } diff --git a/apps/extension/src/extractors/ecommerce-detector.ts b/apps/extension/src/extractors/ecommerce-detector.ts index fc06bf6c..09bdbbb2 100644 --- a/apps/extension/src/extractors/ecommerce-detector.ts +++ b/apps/extension/src/extractors/ecommerce-detector.ts @@ -77,64 +77,186 @@ export function detectEcommercePlatform( if (isDomainOrSubdomain(host, 'tiki.vn')) return 'tiki'; if (isDomainOrSubdomain(host, 'tiktok.com')) return 'tiktok'; if (isDomainOrSubdomain(host, 'cellphones.com.vn')) return 'cellphones'; - if ( - isDomainOrSubdomain(host, 'thegioididong.com') || - isDomainOrSubdomain(host, 'topzone.vn') || - isDomainOrSubdomain(host, 'dienmayxanh.com') - ) { - return 'tgdd'; - } + if (isDomainOrSubdomain(host, 'thegioididong.com')) return 'tgdd'; + if (isDomainOrSubdomain(host, 'dienmayxanh.com')) return 'dienmayxanh'; + if (isDomainOrSubdomain(host, 'topzone.vn')) return 'topzone'; if (isDomainOrSubdomain(host, 'fptshop.com.vn')) return 'fptshop'; if (isDomainOrSubdomain(host, 'hoanghamobile.com')) return 'hoangha'; if (isDomainOrSubdomain(host, 'didongviet.vn')) return 'didongviet'; if (isDomainOrSubdomain(host, 'phongvu.vn')) return 'phongvu'; + if (isDomainOrSubdomain(host, 'gearvn.com')) return 'gearvn'; + if (isDomainOrSubdomain(host, 'nguyenkim.com')) return 'nguyenkim'; + if (isDomainOrSubdomain(host, 'shopdunk.com')) return 'shopdunk'; + if (isDomainOrSubdomain(host, 'hacom.vn')) return 'hacom'; + if (isDomainOrSubdomain(host, 'clickbuy.com.vn')) return 'clickbuy'; + if (isDomainOrSubdomain(host, 'viettelstore.vn')) return 'viettelstore'; + if (isDomainOrSubdomain(host, 'pico.vn')) return 'pico'; + if (isDomainOrSubdomain(host, 'mediamart.vn')) return 'mediamart'; + if (isDomainOrSubdomain(host, 'memoryzone.com.vn')) return 'memoryzone'; + if (isDomainOrSubdomain(host, 'anphatpc.com.vn')) return 'anphatpc'; return null; } const RETAIL_NON_PRODUCT_FIRST_SEGMENTS = new Set([ 'tin-tuc', + 'tin-khuyen-mai', + 'cong-nghe', 'sforum', 'dchannel', 'hoi-dap', + 'huong-dan', 'khuyen-mai', + 'hot-deal', 'tra-gop', + 'thu-cu-doi-moi', 'bao-hanh', + 'tra-bao-hanh', + 'tra-cuu-bao-hanh', + 'chinh-sach', + 'lien-he', + 'gioi-thieu', + 've-chung-toi', + 'tuyen-dung', + 'so-sanh', + 'so-sanh-san-pham', + 'compare', + 'cua-hang', + 'showroom', + 'sieu-thi', 'he-thong-cua-hang', 'he-thong-sieu-thi', + 'he-thong-showroom', + 'he-thong-trung-tam', + 'trung-tam-bao-hanh', 'catalogsearch', 'tim-kiem', + 'ket-qua-tim-kiem', + 'tim', 'search', + 'filter', 'cart', 'gio-hang', + 'checkout', + 'thanh-toan', 'account', + 'tai-khoan', + 'taikhoan', 'login', + 'dang-nhap', + 'register', + 'dang-ky', + 'logout', + 'dang-xuat', + 'auth', + 'captcha', + 'challenge', 'blog', + 'blogs', 'news', 'event', + 'su-kien', 'landing', 'collection', + 'collections', + 'pages', + 'page', + 'policies', + 'tag', + 'tags', + 'brand', + 'thuong-hieu', + 'buildpc', + 'xay-dung-cau-hinh', + 'sua-chua', + 'dich-vu', + 'may-cu', + 'hang-cu', + 'may-cu-gia-re', + 'likenew', + 'like-new', + 'outlet', + 'xa-kho', + 'ajax', + 'api', + 'media', + 'static', + 'assets', + 'cdn-cgi', 'c', + 'danh-muc', ]); +const RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX = + /^(?:chinh-sach-|quy-che-|huong-dan-|dieu-khoan-|gioi-thieu(?:-|$)|ve-chung-toi(?:-|$)|tin-khuyen-mai(?:-|$)|tin-tuc-|khuyen-mai-|sua-chua(?:-|$)|dich-vu(?:-|$)|tra-bao-hanh(?:-|$)|tra-cuu-bao-hanh(?:-|$)|he-thong-(?:cua-hang|sieu-thi|showroom|trung-tam)(?:-|$)|ket-qua-tim-kiem$|so-sanh(?:-san-pham)?$|buildpc$|xay-dung-cau-hinh$)/i; + +const RETAIL_AUTH_SEGMENT_REGEX = + /^(?:login|register|account|tai-khoan|taikhoan|dang-nhap|dang-ky|logout|dang-xuat|auth|captcha|challenge)$/i; + +const RETAIL_STATIC_ASSET_EXT_REGEX = + /\.(?:js|mjs|cjs|json|css|xml|txt|pdf|zip|rar|7z|png|jpe?g|webp|avif|svg|gif|ico|woff2?|ttf|eot|map|mp[34]|webm|aspx|ashx|axd|php)$/i; + +const ANPHAT_DESK_PHONE_SLUG_REGEX = + /^(?:dien-thoai-(?:huu-tuyen|ip|ban|de-ban|khong-day|keo-dai|hoi-nghi)|tong-dai-ip)(?:-|$)/i; + const RETAIL_CATEGORY_ROOT_SLUGS = new Set([ 'dtdd', + 'mtb', 'dien-thoai', 'dien-thoai-di-dong', + 'dien-thoai-thong-minh', 'mobile', 'smartphones', 'laptop', 'laptops', + 'laptop-gaming', + 'laptop-gaming-do-hoa', + 'laptop-van-phong', + 'laptop-tablet-mobile', 'may-tinh-xach-tay', + 'may-tinh-xach-tay-laptop', 'may-tinh-bang', + 'may-tinh-bang-tablet', 'tablet', 'tablets', + 'dong-ho', 'dong-ho-thong-minh', 'smartwatch', 'smartwatches', 'tai-nghe', + 'tai-nghe-bluetooth', + 'tai-nghe-nhet-tai', + 'tai-nghe-chup-tai', + 'tai-nghe-gaming', + 'am-thanh', + 'thiet-bi-am-thanh', + 'loa', 'earbuds', 'phu-kien', + 'phu-kien-di-dong', + 'linh-kien', + 'linh-kien-may-tinh', + 'man-hinh', + 'man-hinh-may-tinh', + 'pc', + 'pc-gaming', + 'pc-van-phong-do-hoa', + 'may-tinh-de-ban', + 'gaming-gear', + 'tivi', + 'tu-lanh', + 'may-giat', + 'may-lanh', + 'gia-dung', + 'dien-gia-dung', + 'dien-may', + 'sim-so', + 'san-pham', + 'products', + 'product', 'apple', + 'apple-iphone', + 'apple-ipad', + 'apple-watch', 'iphone', 'ipad', 'macbook', @@ -183,6 +305,15 @@ const RETAIL_BRAND_LISTING_SLUGS = new Set([ 'anker', 'baseus', 'ugreen', + 'logitech', + 'razer', + 'corsair', + 'hyperx', + 'steelseries', + 'bose', + 'sennheiser', + 'gigabyte', + 'tcl', 'mac', ]); @@ -193,6 +324,385 @@ const ACCESSORY_SLUG_PREFIX = const isSeriesListingSlug = (slug: string) => /-series$/.test(slug) && !ACCESSORY_SLUG_PREFIX.test(slug); +const MEDIAMART_ALLOWED_CATEGORY_PREFIXES = new Set([ + 'smartphones', + 'dien-thoai', + 'dien-thoai-di-dong', + 'laptop', + 'may-tinh-xach-tay', + 'macbook', + 'may-tinh-bang', + 'tablet', + 'ipad', + 'smartwatch', + 'dong-ho-thong-minh', + 'tai-nghe', + 'san-pham', + 'products', +]); + +const HACOM_CATEGORY_BRAND_SLUG_REGEX = + /^(?:laptop-(?:asus(?:-(?:vivobook|zenbook|tuf|rog|expertbook|proart))?|dell(?:-(?:inspiron|vostro|xps|latitude|alienware|precision))?|acer(?:-(?:aspire|nitro|swift|predator|travelmate))?|lenovo(?:-(?:thinkpad|thinkbook|ideapad|legion|loq|yoga))?|hp(?:-(?:pavilion|victus|omen|envy|probook|elitebook|omnibook))?|msi(?:-(?:modern|katana|cyborg|prestige|stealth|raider|thin|sword))?|apple(?:-(?:macbook|macbook-air|macbook-pro))?|lg(?:-gram)?|gigabyte(?:-(?:aorus|aero|gaming))?)|may-tinh-nguyen-bo-theo-hang|may-tinh-mini-da-dung)$/i; + +const CLICKBUY_NON_PRODUCT_SLUG_REGEX = + /^(?:dien-thoai-(?:iphone|samsung|xiaomi|oppo|vivo|realme|nokia|honor|asus|tcl|google|sony|tecno|infinix|masstel|itel)|(?:iphone|samsung|dien-thoai|ipad|macbook|apple-watch)-cu|thay-pin|ep-kinh|google-pixel|trang)$/i; + +const VIETTELSTORE_PRODUCT_CATEGORY_SEGMENTS = new Set([ + 'dien-thoai', + 'may-tinh-bang', + 'tablet', + 'laptop', + 'may-tinh-xach-tay', + 'dong-ho-thong-minh', + 'dong-ho', + 'apple-watch', + 'smartwatch', + 'tai-nghe', + 'am-thanh', + 'loa', + 'phu-kien', + 'man-hinh', + 'pc', + 'tivi', + 'san-pham', + 'products', +]); + +const VIETTELSTORE_NON_PRODUCT_PREFIXES = new Set([ + 'tra-gop', + 'so-sanh', + 'so-sanh-san-pham', + 'tin-tuc', + 'chuyen-muc-tin', + 'landing', + 'khuyen-mai', + 'site', + 'he-thong-sieu-thi', + 'sieu-thi', + 'ho-tro', + 'tuyen-dung', + 'account', + 'login', + 'dang-nhap', + 'register', + 'dang-ky', + 'auth', + 'captcha', + 'challenge', + 'cart', + 'gio-hang', + 'dtdd', + 'mtb', + 'tim-kiem', + 'ket-qua-tim-kiem', +]); + +const VIETTELSTORE_CATEGORY_SLUG_REGEX = + /^(?:dtdd(?:-|$)|mtb(?:-|$)|laptop-(?:apple|asus|acer|dell|hp|lenovo|msi|lg)$|phu-kien-o-to$|bao-da-op-lung$|tam-dan$)/i; + +const ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS = new Set([ + 'template', + 'templates', + 'includes', + 'user', + 'order', + 'don-hang', + 'rss', + 'sitemap', + 'robots.txt', +]); + +const ANPHAT_INFO_SUFFIX_REGEX = + /(?:^|-)(?:he-thong-showroom|tin-khuyen-mai|tin-tuc|khuyen-mai|bao-hanh|chinh-sach|huong-dan|lien-he|tuyen-dung|gioi-thieu|pc-an-phat)$/i; + +const ANPHAT_ACTIVE_DEVICE_SLUG_CUE_REGEX = + /(?:^|[-/_])(?:laptop|may-tinh-xach-tay|macbook|ipad|may-tinh-bang|tablet|galaxy-tab|redmi-pad|xiaomi-pad|matepad|lenovo-tab|apple-watch|galaxy-watch|dong-ho|smartwatch|garmin|amazfit|tai-nghe|airpods|earbuds|galaxy-buds|redmi-buds|headphone|headset)(?:[-/_]|$)/i; + +const ANPHAT_SMARTPHONE_SLUG_REGEX = + /(?:^(?:dien-thoai|iphone|smartphone)(?:-|_|$)|(?:^|[-/_])(?:iphone-\d+|galaxy-(?:s\d+|z-(?:fold|flip)|a\d+|m\d+)|redmi-(?:note|\d+)|poco-[xfmc]\d+|oppo-(?:reno|find)|vivo-[vxyt]\d+|realme-(?:c\d+|gt|\d+)|xiaomi-\d+|google-pixel-\d+)(?:[-/_]|$))/i; + +function isExcludedAnPhatPhoneSlug(slugLower: string): boolean { + if (ANPHAT_DESK_PHONE_SLUG_REGEX.test(slugLower)) return true; + if (/^(?:dien-thoai|iphone|smartphone)(?:-|_|$)/i.test(slugLower)) { + return true; + } + return ( + ANPHAT_SMARTPHONE_SLUG_REGEX.test(slugLower) && + !ANPHAT_ACTIVE_DEVICE_SLUG_CUE_REGEX.test(slugLower) + ); +} + +function sha1Hex10(input: string): string { + const bytes = new TextEncoder().encode(input); + const bitLen = bytes.length * 8; + const paddedLen = (((bytes.length + 8) >>> 6) + 1) << 6; + const buf = new Uint8Array(paddedLen); + buf.set(bytes); + buf[bytes.length] = 0x80; + const view = new DataView(buf.buffer); + view.setUint32(paddedLen - 8, Math.floor(bitLen / 0x100000000), false); + view.setUint32(paddedLen - 4, bitLen >>> 0, false); + + let h0 = 0x67452301; + let h1 = 0xefcdab89; + let h2 = 0x98badcfe; + let h3 = 0x10325476; + let h4 = 0xc3d2e1f0; + const w = new Uint32Array(80); + + for (let offset = 0; offset < paddedLen; offset += 64) { + for (let i = 0; i < 16; i++) { + w[i] = view.getUint32(offset + i * 4, false); + } + for (let i = 16; i < 80; i++) { + const n = w[i - 3]! ^ w[i - 8]! ^ w[i - 14]! ^ w[i - 16]!; + w[i] = ((n << 1) | (n >>> 31)) >>> 0; + } + + let a = h0; + let b = h1; + let c = h2; + let d = h3; + let e = h4; + + for (let i = 0; i < 80; i++) { + let f: number; + let k: number; + if (i < 20) { + f = (b & c) | (~b & d); + k = 0x5a827999; + } else if (i < 40) { + f = b ^ c ^ d; + k = 0x6ed9eba1; + } else if (i < 60) { + f = (b & c) | (b & d) | (c & d); + k = 0x8f1bbcdc; + } else { + f = b ^ c ^ d; + k = 0xca62c1d6; + } + const temp = + ((((a << 5) | (a >>> 27)) >>> 0) + (f >>> 0) + e + k + w[i]!) >>> 0; + e = d; + d = c; + c = ((b << 30) | (b >>> 2)) >>> 0; + b = a; + a = temp; + } + + h0 = (h0 + a) >>> 0; + h1 = (h1 + b) >>> 0; + h2 = (h2 + c) >>> 0; + h3 = (h3 + d) >>> 0; + h4 = (h4 + e) >>> 0; + } + + return ( + h0.toString(16).padStart(8, '0') + h1.toString(16).padStart(8, '0') + ).slice(0, 10); +} + +export function sanitizeAnPhatItemId(rawKey: string): string { + const cleaned = rawKey.trim().replace(/^\/+|\/+$/g, ''); + if (!cleaned) return ''; + const normalized = cleaned.toLowerCase().replace(/[^a-z0-9-]/g, (ch) => { + const hex = ch.codePointAt(0)?.toString(16).padStart(2, '0') ?? '00'; + return `_${hex}`; + }); + if (!normalized) return ''; + const maxSlugLen = 125; + if (normalized.length <= maxSlugLen) { + return `ap-${normalized}`; + } + const digest = sha1Hex10(normalized); + const keepLen = Math.max(1, maxSlugLen - digest.length - 1); + let trimmed = normalized.slice(0, keepLen).replace(/[-_]+$/g, ''); + if (!trimmed) trimmed = normalized.slice(0, keepLen); + return `ap-${trimmed}-${digest}`; +} + +function extractValidRetailItemSlug( + retailPlatform: SupportedEcommercePlatform, + segments: readonly string[] +): string | null { + if (segments.length === 0) return null; + + for (const seg of segments) { + const strippedSeg = seg + .toLowerCase() + .replace(/\.(?:html|htm|aspx|ashx|axd|php)$/i, ''); + if ( + RETAIL_AUTH_SEGMENT_REGEX.test(strippedSeg) || + RETAIL_AUTH_SEGMENT_REGEX.test(seg) + ) { + return null; + } + } + + const firstRawLower = segments[0]!.toLowerCase(); + const firstSegLower = firstRawLower.replace(/\.html?$/i, ''); + const lastRaw = segments[segments.length - 1]!; + if (RETAIL_STATIC_ASSET_EXT_REGEX.test(lastRaw)) { + return null; + } + if ( + (retailPlatform === 'nguyenkim' || retailPlatform === 'pico') && + /\.(?:c|b)$/i.test(lastRaw) + ) { + return null; + } + + const isCollectionProductPath = + segments.length === 4 && + firstSegLower === 'collections' && + segments[2]!.toLowerCase() === 'products'; + + if (retailPlatform === 'gearvn') { + if ( + !(segments.length === 2 && firstSegLower === 'products') && + !isCollectionProductPath + ) { + return null; + } + } else if (retailPlatform === 'memoryzone') { + if ( + segments.length !== 1 && + !(segments.length === 2 && firstSegLower === 'products') && + !isCollectionProductPath + ) { + return null; + } + } else if (retailPlatform === 'mediamart') { + if ( + segments.length !== 2 || + !MEDIAMART_ALLOWED_CATEGORY_PREFIXES.has(firstSegLower) + ) { + return null; + } + } else if ( + retailPlatform === 'tgdd' || + retailPlatform === 'dienmayxanh' || + retailPlatform === 'topzone' + ) { + if (segments.length < 2) return null; + } else if (retailPlatform === 'cellphones') { + // CellphoneS product pages sit at the root ("/iphone-16-pro-max.html"); + // deeper paths are category listings (DOS/Rate#1246). + if (segments.length > 1) return null; + } else if ( + retailPlatform === 'nguyenkim' || + retailPlatform === 'shopdunk' || + retailPlatform === 'hacom' || + retailPlatform === 'clickbuy' || + retailPlatform === 'pico' + ) { + if ( + segments.length !== 1 && + !( + segments.length === 2 && + (firstSegLower === 'products' || firstSegLower === 'san-pham') + ) + ) { + return null; + } + } else if (retailPlatform === 'viettelstore') { + if (segments.length > 2) return null; + if (segments.length === 2) { + if (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(firstSegLower)) return null; + const leafLower = lastRaw.toLowerCase().replace(/\.html?$/i, ''); + const hasPid = /(?:^|-)pid[1-9]\d{1,14}$/i.test(leafLower); + if ( + !VIETTELSTORE_PRODUCT_CATEGORY_SEGMENTS.has(firstSegLower) && + !hasPid + ) { + return null; + } + } + } else if (retailPlatform === 'anphatpc') { + const hasHtmlExt = /\.html?$/i.test(lastRaw); + const isDirectRoutePrefix = + segments.length === 2 && + (firstSegLower === 'products' || firstSegLower === 'san-pham'); + if (!hasHtmlExt && !isDirectRoutePrefix) return null; + if ( + firstRawLower.startsWith('ajax') || + firstRawLower.endsWith('.php') || + ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS.has(firstRawLower) || + ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) || + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) + ) { + return null; + } + if (segments.some((s) => /_dm\d+$/i.test(s.replace(/\.html?$/i, '')))) { + return null; + } + if (segments.length > 1 && !isDirectRoutePrefix) { + const lastClean = lastRaw.replace(/\.html?$/i, ''); + if (!lastClean) return null; + const rawKey = [...segments.slice(0, -1), lastClean].join('/'); + const rawKeyLower = rawKey.toLowerCase(); + if ( + rawKey.length < 3 || + rawKey.length > 512 || + rawKeyLower.includes('..') || + isExcludedAnPhatPhoneSlug(rawKeyLower) || + RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX.test(rawKeyLower) || + ANPHAT_INFO_SUFFIX_REGEX.test(lastClean.toLowerCase()) + ) { + return null; + } + return sanitizeAnPhatItemId(rawKey) || null; + } + } + + if ( + !isCollectionProductPath && + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) + ) { + return null; + } + + const lastSeg = lastRaw.replace(/\.html?$/i, '') || null; + const lastSegLower = (lastSeg || '').toLowerCase(); + const vtsHasPid = + retailPlatform === 'viettelstore' && + /(?:^|-)pid[1-9]\d{1,14}$/i.test(lastSegLower); + if ( + !lastSeg || + lastSeg.length < 2 || + lastSeg.length > 256 || + !/^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(lastSegLower) || + lastSegLower.includes('..') || + /^(?:0+|null|undefined|nan|infinity|-infinity|true|false|default|index|home|trang-chu|404|page-not-found|error)$/i.test( + lastSegLower + ) || + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(lastSegLower) || + RETAIL_CATEGORY_ROOT_SLUGS.has(lastSegLower) || + RETAIL_BRAND_LISTING_SLUGS.has(lastSegLower) || + RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX.test(lastSegLower) || + isSeriesListingSlug(lastSegLower) || + (retailPlatform === 'hacom' && + HACOM_CATEGORY_BRAND_SLUG_REGEX.test(lastSegLower)) || + (retailPlatform === 'clickbuy' && + CLICKBUY_NON_PRODUCT_SLUG_REGEX.test(lastSegLower)) || + (retailPlatform === 'viettelstore' && + !vtsHasPid && + (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(lastSegLower) || + VIETTELSTORE_CATEGORY_SLUG_REGEX.test(lastSegLower))) || + (retailPlatform === 'anphatpc' && + (isExcludedAnPhatPhoneSlug(lastSegLower) || + ANPHAT_INFO_SUFFIX_REGEX.test(lastSegLower))) + ) { + return null; + } + + if (retailPlatform === 'anphatpc' && lastSeg.length > 120) { + return sanitizeAnPhatItemId(lastSeg) || null; + } + + return lastSeg.length <= 120 ? lastSeg : null; +} + export function extractIdsFromUrl( platform: SupportedEcommercePlatform, canonicalUrl: string @@ -265,7 +775,7 @@ export function extractIdsFromUrl( }; } - // For CellphoneS / TGDD / FPT Shop / Hoàng Hà / Di Động Việt / Phong Vũ, validate pathname segments + // Validate pathname segments across all 18 Vietnamese retail chains let pathname = canonicalUrl; try { pathname = new URL(canonicalUrl).pathname; @@ -276,32 +786,8 @@ export function extractIdsFromUrl( .split('/') .map((s) => s.trim()) .filter(Boolean); - const firstSegLower = (segments[0] || '') - .replace(/\.html?$/i, '') - .toLowerCase(); - const lastSegment = - segments[segments.length - 1]?.replace(/\.html?$/i, '') || null; - const lastSegLower = (lastSegment || '').toLowerCase(); - const isValidItemSlug = - Boolean(lastSegment) && - lastSegment!.length >= 2 && - lastSegment!.length <= 120 && - /^[a-zA-Z0-9_.-]+$/.test(lastSegment!) && - /[a-zA-Z0-9]/.test(lastSegment!) && - !lastSegment!.startsWith('.') && - !lastSegment!.endsWith('.') && - !lastSegment!.includes('..') && - !RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) && - !RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(lastSegLower) && - !(segments.length === 1 && RETAIL_CATEGORY_ROOT_SLUGS.has(firstSegLower)) && - !RETAIL_BRAND_LISTING_SLUGS.has(lastSegLower) && - !isSeriesListingSlug(lastSegLower) && - !(platform === 'tgdd' && segments.length < 2) && - // CellphoneS product pages sit at the root ("/iphone-16-pro-max.html"); - // deeper paths are category listings (DOS/Rate#1246). - !(platform === 'cellphones' && segments.length > 1); return { - externalItemId: isValidItemSlug ? lastSegment : null, + externalItemId: extractValidRetailItemSlug(platform, segments), externalShopId: null, }; } @@ -786,10 +1272,14 @@ export function extractRatingFromJsonLd(aggRaw: unknown): { export function cleanExtractedProductTitle(rawTitle: string): string { if (typeof rawTitle !== 'string') return ''; - const withoutPlatformSuffix = stripLoneSurrogates(rawTitle) - .replace(/\p{Cc}+/gu, ' ') + // Bound code points and collapse whitespace first so suffix matching stays strictly O(N). + const normalizedTitle = sliceCodePoints(stripLoneSurrogates(rawTitle), 2048) + .replace(/[\p{Cc}\s]+/gu, ' ') + .trim(); + if (!normalizedTitle) return ''; + const withoutPlatformSuffix = normalizedTitle .replace( - /\s*(?:\||[-–—])\s*(?:Shopee(?:\s*Việt\s*Nam|\s*VN)?|Lazada(?:\s*Việt\s*Nam|\s*VN)?|Tiki(?:\.vn)?|TikTok\s*Shop|CellphoneS(?:\.com\.vn)?|Thế\s*Giới\s*Di\s*Động|Thegioididong(?:\.com)?|TopZone(?:\.vn)?|Điện\s*Máy\s*Xanh|FPT\s*Shop|Fptshop(?:\.com\.vn)?|Hoàng\s*Hà\s*Mobile|HoangHaMobile(?:\.com)?|Di\s*Động\s*Việt|Didongviet(?:\.vn)?|Phong\s*Vũ|Phongvu(?:\.vn)?).*$/i, + / ?(?:\||[-\u2013\u2014]) ?(?:Shopee(?:\s*Việt\s*Nam|\s*VN)?|Lazada(?:\s*Việt\s*Nam|\s*VN)?|Tiki(?:\.vn)?|TikTok\s*Shop|CellphoneS(?:\.com\.vn)?|Thế\s*Giới\s*Di\s*Động|Thegioididong(?:\.com)?|TopZone(?:\.vn)?|Điện\s*Máy\s*Xanh|Dienmayxanh(?:\.com)?|FPT\s*Shop|Fptshop(?:\.com\.vn)?|Hoàng\s*Hà\s*Mobile|HoangHaMobile(?:\.com)?|Di\s*Động\s*Việt|Didongviet(?:\.vn)?|Phong\s*Vũ|Phongvu(?:\.vn)?|GearVN(?:\.com)?|Nguy\u1ec5n\s*Kim|Nguyenkim(?:\.com)?|ShopDunk(?:\.com)?|HACOM(?:\.vn)?|Hanoicomputer(?:\.vn)?|Clickbuy(?:\.com\.vn)?|Viettel\s*Store|Viettelstore(?:\.vn)?|Si\u00eau\s*th\u1ecb\s*\u0111i\u1ec7n\s*m\u00e1y\s*Pico|Pico(?:\.vn)?|Media\s*Mart|Mediamart(?:\.vn)?|MemoryZone(?:\.com\.vn)?|An\s*Ph\u00e1t(?:\s*Computer|\s*PC)?|Anphatpc(?:\.com\.vn)?)(?: ?(?:\||[-\u2013\u2014(:]).*)?$/i, '' ) .replace(/\s+/g, ' ') @@ -968,6 +1458,71 @@ export function extractSelectedVariantFromDom(doc: Document): string | null { return null; } +const NON_PDP_PRICE_ANCESTOR_SELECTOR = + '[hidden], [aria-hidden="true"], .hidden, .d-none, .related-products, .product-related, .similar-products, .viewed-products, .cross-sell, .upsell, .product-list, .product-grid, .product-item, .product-card, .product-box, .p-item, .item-product, .owl-item, .swiper-slide, header, footer, nav, aside'; + +function isExcludedDomPriceNode(el: Element | null | undefined): boolean { + if (!el) return true; + if (typeof el.hasAttribute === 'function' && el.hasAttribute('hidden')) { + return true; + } + if ((el as unknown as { hidden?: boolean }).hidden === true) { + return true; + } + if ( + typeof el.closest === 'function' && + el.closest(NON_PDP_PRICE_ANCESTOR_SELECTOR) + ) { + return true; + } + let ancestor = ( + el as unknown as { + parentElement?: { + hidden?: boolean; + hasAttribute?: (name: string) => boolean; + parentElement?: unknown; + } | null; + } + ).parentElement; + let depth = 0; + while (ancestor && depth < 16) { + if ( + ancestor.hidden === true || + (typeof ancestor.hasAttribute === 'function' && + ancestor.hasAttribute('hidden')) + ) { + return true; + } + ancestor = ancestor.parentElement as typeof ancestor; + depth++; + } + return false; +} + +function queryFirstActivePdpPriceNode( + doc: Document, + selector: string +): Element | null { + if (typeof doc.querySelectorAll === 'function') { + const nodes = Array.from(doc.querySelectorAll(selector)); + if (nodes.length > 0) { + for (const node of nodes) { + if (!isExcludedDomPriceNode(node)) { + return node; + } + } + return null; + } + } + if (typeof doc.querySelector === 'function') { + const single = doc.querySelector(selector); + if (single && !isExcludedDomPriceNode(single)) { + return single; + } + } + return null; +} + /** * Extract product signal from the current DOM + JSON-LD structured data without blocking the main thread. */ @@ -1065,12 +1620,22 @@ export function extractProductSignalFromDom( '[data-testid="pdp-product-price"]', '.pdp-price_type_normal', '.product-price__current-price', + '.product-detail .product-price .pro-price', + '.product-price .pro-price', + '.product_info_price_value-final', + '.overview .prices .actual-price', + '.pdp-price-online', + '.product-detail-price .price-sale', + '.cb-pbox:not([hidden]) .cb-pbox__now:not([hidden])', + '.cb-pbox__now:not([hidden])', + '.wrap-price .new-price', + '.special-price .price:not(.related-products *):not(.product-item *):not(.product-card *):not(.product-box *):not(header *):not(footer *)', '.tpt---sale-price', '.box-price-present', ]; if (!price) { for (const sel of priceSelectors) { - const el = doc.querySelector(sel); + const el = queryFirstActivePdpPriceNode(doc, sel); const parsed = parseVndPriceText(el?.textContent); if (parsed) { price = parsed; @@ -1084,17 +1649,30 @@ export function extractProductSignalFromDom( '.ZA5sW5', '.pdp-price_type_deleted', '.product-price__original-price', + '.product-detail .product-price .pro-price-del', + '.product-price .pro-price-del', + '.product_info_price_value-real', + '.overview .old-product-price', + '.pdp-price-old', + '.product-detail-price .price-old', + '.cb-pbox:not([hidden]) .cb-pbox__old:not([hidden])', + '.cb-pbox__old:not([hidden])', + '.wrap-price .old-price', + '.product-price-regular:not(.related-products *):not(.product-item *):not(.product-card *):not(.product-box *):not(header *):not(footer *)', + '.old-price .price:not(.related-products *):not(.product-item *):not(.product-card *):not(.product-box *):not(header *):not(footer *)', '.tpt---price-through', '.box-price-old', 'del', ]; - for (const sel of originalPriceSelectors) { - const el = doc.querySelector(sel); - const parsed = parseVndPriceText(el?.textContent); - if (parsed && (!price || parsed > price)) { - originalPrice = parsed; - originalFromDom = true; - break; + if (!originalPrice) { + for (const sel of originalPriceSelectors) { + const el = queryFirstActivePdpPriceNode(doc, sel); + const parsed = parseVndPriceText(el?.textContent); + if (parsed && (!price || parsed > price)) { + originalPrice = parsed; + originalFromDom = true; + break; + } } } diff --git a/apps/extension/src/i18n.ts b/apps/extension/src/i18n.ts index 4bfa61ea..a80b79ac 100644 --- a/apps/extension/src/i18n.ts +++ b/apps/extension/src/i18n.ts @@ -88,6 +88,7 @@ const VIETNAMESE_WORDS = new Set([ 'c\u00f3', 'b\u00e1n', 'n\u00f3ng', + 'ph\u00e1t', 'nhanh', 'nghe', ]); diff --git a/apps/extension/src/security-guards.ts b/apps/extension/src/security-guards.ts index d28bf39e..85b5910a 100644 --- a/apps/extension/src/security-guards.ts +++ b/apps/extension/src/security-guards.ts @@ -31,10 +31,22 @@ const ALLOWED_EXTENSION_PLATFORMS: ReadonlySet = 'tiktok', 'cellphones', 'tgdd', + 'dienmayxanh', + 'topzone', 'fptshop', 'hoangha', 'didongviet', 'phongvu', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]); export const ALLOWED_API_BASE_ORIGINS = [ @@ -257,16 +269,17 @@ export function selectFreshestSessionSignal( return tabSignal ?? latestSignal ?? null; } -const SAFE_EXTERNAL_ID_REGEX = /^[a-zA-Z0-9_.-]{1,120}$/; +const SAFE_EXTERNAL_ID_CHARS_REGEX = /^[a-zA-Z0-9_.-]+$/; const RESERVED_EXTERNAL_ID_REGEX = /^(?:0+|null|undefined|nan|infinity|-infinity|true|false)$/i; -function sanitizeExternalIdentifier(val: unknown): string | null { +function sanitizeExternalIdentifier(val: unknown, maxLen = 120): string | null { if (typeof val !== 'string') return null; const cleaned = val.replace(/\p{Cc}+/gu, '').trim(); if ( !cleaned || - !SAFE_EXTERNAL_ID_REGEX.test(cleaned) || + cleaned.length > maxLen || + !SAFE_EXTERNAL_ID_CHARS_REGEX.test(cleaned) || !/[a-zA-Z0-9]/.test(cleaned) || cleaned.startsWith('.') || cleaned.endsWith('.') || @@ -385,7 +398,10 @@ export function sanitizeExtensionProductSignal( ...safeSignal, platform: validPlatform, canonicalUrl: sanitizeCanonicalSignalUrl(safeSignal.canonicalUrl), - externalItemId: sanitizeExternalIdentifier(safeSignal.externalItemId), + externalItemId: sanitizeExternalIdentifier( + safeSignal.externalItemId, + validPlatform === 'anphatpc' ? 128 : 120 + ), externalShopId: sanitizeExternalIdentifier(safeSignal.externalShopId), title: trimmedTitle, selectedVariant: trimmedVariant, diff --git a/apps/extension/src/sidepanel/sidepanel.ts b/apps/extension/src/sidepanel/sidepanel.ts index 4956e46b..bc6f959d 100644 --- a/apps/extension/src/sidepanel/sidepanel.ts +++ b/apps/extension/src/sidepanel/sidepanel.ts @@ -351,8 +351,11 @@ function renderPanelContent(
${escapeHtml(t('noProductTitle'))}

${tHtml('noProductBody', [ - `${escapeHtml(t('noProductStores'))}`, - `${escapeHtml(t('noProductLastStore'))}`, + `${t('noProductStores') + .split(', ') + .map((s) => contentTextHtml(s)) + .join(', ')}`, + `${contentTextHtml(t('noProductLastStore'))}`, `${escapeHtml(t('quickLookupBoxName'))}`, ])}

diff --git a/apps/extension/src/test-extension-pipeline.ts b/apps/extension/src/test-extension-pipeline.ts index 90a82646..0bdfae89 100644 --- a/apps/extension/src/test-extension-pipeline.ts +++ b/apps/extension/src/test-extension-pipeline.ts @@ -134,7 +134,7 @@ async function runTests() { ); assert.equal( detectEcommercePlatform('https://www.topzone.vn/iphone/iphone-16-pro-max'), - 'tgdd' + 'topzone' ); assert.equal( detectEcommercePlatform('https://www.google.com/search?q=shopee.vn'), @@ -158,7 +158,23 @@ async function runTests() { ); assert.equal( detectPlatformFromInput(null, 'https://www.dienmayxanh.com/dtdd/iphone-16'), - 'tgdd' + 'dienmayxanh' + ); + assert.equal( + detectPlatformFromInput( + 'tgdd', + 'https://www.dienmayxanh.com/dtdd/iphone-16' + ), + 'dienmayxanh', + 'Legacy tgdd platform hint upgrades to dienmayxanh when rawUrl is dienmayxanh.com' + ); + assert.equal( + detectPlatformFromInput( + 'tgdd', + 'https://www.topzone.vn/iphone/iphone-16-pro-max' + ), + 'topzone', + 'Legacy tgdd platform hint upgrades to topzone when rawUrl is topzone.vn' ); assert.deepEqual( parseEcommerceUrlOrQuery( @@ -190,7 +206,7 @@ async function runTests() { ), { isUrl: true, - platform: 'tgdd', + platform: 'topzone', platformShopId: null, platformItemId: 'iphone-16-pro-max-256gb', internalSlug: null, @@ -247,10 +263,10 @@ async function runTests() { null, 'parseEcommerceUrlOrQuery must reject spoofed domains' ); - assert.equal(Object.keys(EXTENSION_CAPABILITY_MATRIX).length, 10); + assert.equal(Object.keys(EXTENSION_CAPABILITY_MATRIX).length, 22); assert.equal(parseVndPriceText('28.990.000₫ - 34.990.000₫'), 28990000); console.log( - ' ✅ [1/6] URL Canonicalization & 10-Platform ID Extraction passed' + ' ✅ [1/6] URL Canonicalization & 22-Platform ID Extraction passed' ); // 2. Gatekeeper Layer 0: Accessory & Spare Part Rejection @@ -440,6 +456,35 @@ async function runTests() { assert.equal(EXTENSION_CAPABILITY_MATRIX.hoangha.crowdVerifyQueue, true); assert.equal(EXTENSION_CAPABILITY_MATRIX.didongviet.crowdVerifyQueue, true); assert.equal(EXTENSION_CAPABILITY_MATRIX.phongvu.crowdVerifyQueue, true); + for (const wavePlatform of [ + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', + ] as const) { + assert.equal(EXTENSION_CAPABILITY_MATRIX[wavePlatform].lookup, true); + assert.equal( + EXTENSION_CAPABILITY_MATRIX[wavePlatform].exactItemMatch, + true + ); + assert.equal( + EXTENSION_CAPABILITY_MATRIX[wavePlatform].crossCatalogMatch, + true + ); + assert.equal( + EXTENSION_CAPABILITY_MATRIX[wavePlatform].crowdVerifyQueue, + false, + `${wavePlatform} crowdVerifyQueue must remain false until DOS-Me SQL migration` + ); + } assert.equal(EXTENSION_CAPABILITY_MATRIX.tiktok.lookup, true); assert.equal(EXTENSION_CAPABILITY_MATRIX.hoangha.lookup, true); assert.equal(DEFAULT_API_BASE_URL, 'https://rate.vn'); @@ -580,19 +625,93 @@ async function runTests() { ); } - for (const url of [ - 'https://thegioididong.com/dtdd/iphone-16-pro-max', - 'https://www.thegioididong.com/dtdd/iphone-16-pro-max', - 'https://topzone.vn/iphone/iphone-16-pro-max', - 'https://www.topzone.vn/iphone/iphone-16-pro-max', - 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', - 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', - ]) { + for (const [url, expectedPlatform, expectedItemId] of [ + [ + 'https://thegioididong.com/dtdd/iphone-16-pro-max', + 'tgdd', + 'iphone-16-pro-max', + ], + [ + 'https://www.thegioididong.com/dtdd/iphone-16-pro-max', + 'tgdd', + 'iphone-16-pro-max', + ], + [ + 'https://topzone.vn/iphone/iphone-16-pro-max', + 'topzone', + 'iphone-16-pro-max', + ], + [ + 'https://www.topzone.vn/iphone/iphone-16-pro-max', + 'topzone', + 'iphone-16-pro-max', + ], + [ + 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', + 'dienmayxanh', + 'iphone-16-pro-max', + ], + [ + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', + 'dienmayxanh', + 'iphone-16-pro-max', + ], + [ + 'https://gearvn.com/products/laptop-gaming-asus-rog-strix', + 'gearvn', + 'laptop-gaming-asus-rog-strix', + ], + [ + 'https://www.nguyenkim.com/dien-thoai-iphone-16-pro-max.html', + 'nguyenkim', + 'dien-thoai-iphone-16-pro-max', + ], + [ + 'https://shopdunk.com/iphone-16-pro-max', + 'shopdunk', + 'iphone-16-pro-max', + ], + [ + 'https://hacom.vn/laptop-apple-macbook-air-m3', + 'hacom', + 'laptop-apple-macbook-air-m3', + ], + [ + 'https://clickbuy.com.vn/apple-iphone-16-pro-max.html', + 'clickbuy', + 'apple-iphone-16-pro-max', + ], + [ + 'https://viettelstore.vn/dien-thoai/iphone-16-pro-max-pid341099.html', + 'viettelstore', + 'iphone-16-pro-max-pid341099', + ], + [ + 'https://pico.vn/39871-dien-thoai-apple-iphone-16-pro-max', + 'pico', + '39871-dien-thoai-apple-iphone-16-pro-max', + ], + [ + 'https://mediamart.vn/smartphones/apple-iphone-16-pro-max', + 'mediamart', + 'apple-iphone-16-pro-max', + ], + [ + 'https://memoryzone.com.vn/products/macbook-pro-14-m4', + 'memoryzone', + 'macbook-pro-14-m4', + ], + [ + 'https://www.anphatpc.com.vn/laptop-apple-macbook-air-m3_id49201.html', + 'anphatpc', + 'laptop-apple-macbook-air-m3_id49201', + ], + ] as const) { assert.ok(injectedOn(url), `content script must run on ${url}`); - assert.equal(detectEcommercePlatform(url), 'tgdd', url); + assert.equal(detectEcommercePlatform(url), expectedPlatform, url); assert.equal( - extractIdsFromUrl('tgdd', url).externalItemId, - 'iphone-16-pro-max', + extractIdsFromUrl(expectedPlatform, url).externalItemId, + expectedItemId, url ); assert.ok( @@ -607,6 +726,26 @@ async function runTests() { 'https://*.topzone.vn/*', 'https://dienmayxanh.com/*', 'https://*.dienmayxanh.com/*', + 'https://gearvn.com/*', + 'https://*.gearvn.com/*', + 'https://nguyenkim.com/*', + 'https://*.nguyenkim.com/*', + 'https://shopdunk.com/*', + 'https://*.shopdunk.com/*', + 'https://hacom.vn/*', + 'https://*.hacom.vn/*', + 'https://clickbuy.com.vn/*', + 'https://*.clickbuy.com.vn/*', + 'https://viettelstore.vn/*', + 'https://*.viettelstore.vn/*', + 'https://pico.vn/*', + 'https://*.pico.vn/*', + 'https://mediamart.vn/*', + 'https://*.mediamart.vn/*', + 'https://memoryzone.com.vn/*', + 'https://*.memoryzone.com.vn/*', + 'https://anphatpc.com.vn/*', + 'https://*.anphatpc.com.vn/*', ]) { assert.ok(matches.includes(pattern), `matches missing ${pattern}`); assert.ok(hosts.includes(pattern), `host_permissions missing ${pattern}`); @@ -615,6 +754,16 @@ async function runTests() { 'https://eviltopzone.vn/iphone/iphone-16-pro-max', 'https://evildienmayxanh.com/dtdd/iphone-16-pro-max', 'https://evilthegioididong.com/dtdd/iphone-16-pro-max', + 'https://evilgearvn.com/products/iphone-16-pro-max', + 'https://evilnguyenkim.com/iphone-16-pro-max.html', + 'https://evilshopdunk.com/iphone-16-pro-max', + 'https://evilhacom.vn/iphone-16-pro-max', + 'https://evilclickbuy.com.vn/iphone-16-pro-max.html', + 'https://evilviettelstore.vn/dien-thoai/iphone-16-pro-max.html', + 'https://evilpico.vn/iphone-16-pro-max', + 'https://evilmediamart.vn/smartphones/iphone-16-pro-max', + 'https://evilmemoryzone.com.vn/products/iphone-16-pro-max', + 'https://evilanphatpc.com.vn/iphone-16-pro-max.html', ]) { assert.ok( !injectedOn(lookalikeUrl), @@ -689,16 +838,14 @@ async function runTests() { '2.1.0' ); assert.ok(sample); - for (const tgddSisterUrl of [ - 'https://topzone.vn/iphone/iphone-16-pro-max', - 'https://www.topzone.vn/iphone/iphone-16-pro-max', - 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', - 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', + for (const tgddUrl of [ + 'https://thegioididong.com/dtdd/iphone-16-pro-max', + 'https://www.thegioididong.com/dtdd/iphone-16-pro-max', ]) { const obs = buildExtensionObservationV1( { platform: 'tgdd', - canonicalUrl: tgddSisterUrl, + canonicalUrl: tgddUrl, externalItemId: 'iphone-16-pro-max', externalShopId: null, title: 'iPhone 16 Pro Max', @@ -711,10 +858,17 @@ async function runTests() { new Date(), '2.1.0' ); - assert.ok(obs, `tgdd observation must accept ${tgddSisterUrl}`); - assert.equal(obs.listing_url, tgddSisterUrl); + assert.ok(obs, `tgdd observation must accept ${tgddUrl}`); + assert.equal(obs.listing_url, tgddUrl); } - for (const lookalikeUrl of [ + // TopZone and Dien May Xanh are standalone Wave 1A platforms (#1850), and + // PostgreSQL `extension_observations_listing_url_check` allows only + // `thegioididong.com` under `marketplace = 'tgdd'`. + for (const disallowedForTgddUrl of [ + 'https://topzone.vn/iphone/iphone-16-pro-max', + 'https://www.topzone.vn/iphone/iphone-16-pro-max', + 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', 'https://eviltopzone.vn/iphone/iphone-16-pro-max', 'https://evildienmayxanh.com/dtdd/iphone-16-pro-max', ]) { @@ -722,7 +876,7 @@ async function runTests() { buildExtensionObservationV1( { platform: 'tgdd', - canonicalUrl: lookalikeUrl, + canonicalUrl: disallowedForTgddUrl, externalItemId: 'iphone-16-pro-max', externalShopId: null, title: 'iPhone 16 Pro Max', @@ -736,7 +890,7 @@ async function runTests() { '2.1.0' ), null, - `tgdd observation must reject lookalike ${lookalikeUrl}` + `tgdd observation must reject ${disallowedForTgddUrl}` ); } assert.deepEqual( @@ -1697,8 +1851,8 @@ async function runTests() { assert.equal( detectEcommercePlatform('https://www.dienmayxanh.com/dtdd/iphone-16e'), - 'tgdd', - 'detectEcommercePlatform must map dienmayxanh.com to tgdd' + 'dienmayxanh', + 'detectEcommercePlatform must map dienmayxanh.com to dienmayxanh' ); assert.deepEqual( extractIdsFromUrl( @@ -8397,17 +8551,17 @@ async function runTests() { ['tiki.vn/sp-p777888.html', 'tiki', '777888'], ['tiktok.com/@apple/product/999111', 'tiktok', '999111'], ['thegioididong.com/dtdd/iphone-16-pro', 'tgdd', 'iphone-16-pro'], - ['topzone.vn/iphone/iphone-16-pro', 'tgdd', 'iphone-16-pro'], + ['topzone.vn/iphone/iphone-16-pro', 'topzone', 'iphone-16-pro'], [ 'www.topzone.vn/iphone/iphone-16-pro?utm_source=fb#specs', - 'tgdd', + 'topzone', 'iphone-16-pro', 'https://www.topzone.vn/iphone/iphone-16-pro', ], - ['dienmayxanh.com/dtdd/iphone-16-pro', 'tgdd', 'iphone-16-pro'], + ['dienmayxanh.com/dtdd/iphone-16-pro', 'dienmayxanh', 'iphone-16-pro'], [ '//www.dienmayxanh.com/dtdd/iphone-16-pro', - 'tgdd', + 'dienmayxanh', 'iphone-16-pro', 'https://www.dienmayxanh.com/dtdd/iphone-16-pro', ], @@ -8428,6 +8582,52 @@ async function runTests() { 'phongvu', 'apple-iphone-16-pro--s2502001', ], + [ + 'gearvn.com/products/laptop-asus-rog-strix', + 'gearvn', + 'laptop-asus-rog-strix', + ], + [ + 'www.nguyenkim.com/dien-thoai-iphone-16-pro.html', + 'nguyenkim', + 'dien-thoai-iphone-16-pro', + ], + ['shopdunk.com/iphone-16-pro', 'shopdunk', 'iphone-16-pro'], + [ + 'hacom.vn/laptop-apple-macbook-air-m3', + 'hacom', + 'laptop-apple-macbook-air-m3', + ], + [ + 'clickbuy.com.vn/apple-iphone-16-pro.html', + 'clickbuy', + 'apple-iphone-16-pro', + ], + [ + 'viettelstore.vn/dien-thoai/iphone-16-pro-pid341098.html', + 'viettelstore', + 'iphone-16-pro-pid341098', + ], + [ + 'pico.vn/39870-dien-thoai-iphone-16-pro', + 'pico', + '39870-dien-thoai-iphone-16-pro', + ], + [ + 'mediamart.vn/smartphones/iphone-16-pro', + 'mediamart', + 'iphone-16-pro', + ], + [ + 'memoryzone.com.vn/products/macbook-pro-14-m4', + 'memoryzone', + 'macbook-pro-14-m4', + ], + [ + 'www.anphatpc.com.vn/laptop-apple-macbook-air-m3_id49201.html', + 'anphatpc', + 'laptop-apple-macbook-air-m3_id49201', + ], ]; for (const [ bareUrl, @@ -11751,6 +11951,737 @@ async function runTests() { } } } + // --- DOS/Rate#1850: 12 Wave 1-3 retail platforms across detector, lookup & SQL boundary --- + { + const { cleanExtractedProductTitle, extractProductSignalFromDom } = + await import('./extractors/ecommerce-detector.js'); + const { buildCandidateExternalItemIds } = + await import('../../web/src/server/rate/extension.js'); + + // 1. Positive PDP detection & ID extraction across all 12 Wave 1-3 platforms + for (const [url, expectedPlatform, expectedId] of [ + [ + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', + 'dienmayxanh', + 'iphone-16-pro-max', + ], + [ + 'https://www.topzone.vn/iphone/iphone-16-pro-max', + 'topzone', + 'iphone-16-pro-max', + ], + [ + 'https://gearvn.com/products/laptop-gaming-asus-rog-strix', + 'gearvn', + 'laptop-gaming-asus-rog-strix', + ], + [ + 'https://gearvn.com/collections/laptop-gaming/products/asus-tuf-a15', + 'gearvn', + 'asus-tuf-a15', + ], + [ + 'https://www.nguyenkim.com/dien-thoai-iphone-16-pro-max.html', + 'nguyenkim', + 'dien-thoai-iphone-16-pro-max', + ], + [ + 'https://shopdunk.com/iphone-16-pro-max', + 'shopdunk', + 'iphone-16-pro-max', + ], + [ + 'https://hacom.vn/laptop-apple-macbook-air-m3', + 'hacom', + 'laptop-apple-macbook-air-m3', + ], + [ + 'https://clickbuy.com.vn/apple-iphone-16-pro-max.html', + 'clickbuy', + 'apple-iphone-16-pro-max', + ], + [ + 'https://viettelstore.vn/dien-thoai/iphone-16-pro-max-pid341099.html', + 'viettelstore', + 'iphone-16-pro-max-pid341099', + ], + [ + 'https://pico.vn/39871-dien-thoai-apple-iphone-16-pro-max', + 'pico', + '39871-dien-thoai-apple-iphone-16-pro-max', + ], + [ + 'https://mediamart.vn/smartphones/apple-iphone-16-pro-max', + 'mediamart', + 'apple-iphone-16-pro-max', + ], + [ + 'https://memoryzone.com.vn/products/macbook-pro-14-m4', + 'memoryzone', + 'macbook-pro-14-m4', + ], + [ + 'https://memoryzone.com.vn/ssd-samsung-990-pro-1tb', + 'memoryzone', + 'ssd-samsung-990-pro-1tb', + ], + [ + 'https://www.anphatpc.com.vn/laptop-apple-macbook-air-m3_id49201.html', + 'anphatpc', + 'laptop-apple-macbook-air-m3_id49201', + ], + ] as const) { + assert.equal(detectEcommercePlatform(url), expectedPlatform, url); + assert.deepEqual( + extractIdsFromUrl(expectedPlatform, url), + { externalItemId: expectedId, externalShopId: null }, + url + ); + } + + // 2. Non-product category, brand, auth, policy, static-asset, and desk-phone rejections + for (const [platform, badUrl] of [ + ['dienmayxanh', 'https://www.dienmayxanh.com/dtdd'], + ['topzone', 'https://www.topzone.vn/iphone'], + ['gearvn', 'https://gearvn.com/collections/laptop-gaming'], + ['gearvn', 'https://gearvn.com/pages/chinh-sach-bao-hanh'], + ['nguyenkim', 'https://www.nguyenkim.com/dien-thoai-di-dong.c'], + ['nguyenkim', 'https://www.nguyenkim.com/apple.b'], + ['shopdunk', 'https://shopdunk.com/iphone'], + ['shopdunk', 'https://shopdunk.com/iphone-16-series'], + ['hacom', 'https://hacom.vn/buildpc'], + ['hacom', 'https://hacom.vn/chinh-sach-bao-hanh'], + ['clickbuy', 'https://clickbuy.com.vn/sua-chua'], + ['viettelstore', 'https://viettelstore.vn/dien-thoai'], + ['viettelstore', 'https://viettelstore.vn/tin-tuc/iphone-16-ra-mat'], + ['pico', 'https://pico.vn/dien-thoai.c'], + ['mediamart', 'https://mediamart.vn/smartphones'], + ['memoryzone', 'https://memoryzone.com.vn/collections/ssd'], + [ + 'anphatpc', + 'https://www.anphatpc.com.vn/may-tinh-xach-tay-laptop_dm1013.html', + ], + [ + 'anphatpc', + 'https://www.anphatpc.com.vn/dien-thoai-ban-panasonic-kx-ts500_id1234.html', + ], + [ + 'anphatpc', + 'https://www.anphatpc.com.vn/iphone-16-pro-max_id49201.html', + ], + [ + 'anphatpc', + 'https://www.anphatpc.com.vn/dien-thoai-apple-iphone-16-pro-max_id49201.html', + ], + ['anphatpc', 'https://www.anphatpc.com.vn/laptop-asus-without-html-ext'], + ] as const) { + assert.equal( + extractIdsFromUrl(platform, badUrl).externalItemId, + null, + `must reject non-product URL ${badUrl}` + ); + } + + // 3. Title suffix cleaning across Wave 1-3 chains + for (const [rawTitle, expectedClean] of [ + ['Laptop ASUS ROG Strix G16 | GearVN.com', 'Laptop ASUS ROG Strix G16'], + ['iPhone 16 Pro Max 256GB - Nguyễn Kim', 'iPhone 16 Pro Max 256GB'], + ['iPhone 16 Pro Max 256GB | ShopDunk.com', 'iPhone 16 Pro Max 256GB'], + ['MacBook Air M3 13 inch | HACOM', 'MacBook Air M3 13 inch'], + [ + 'Samsung Galaxy S25 Ultra - Clickbuy.com.vn', + 'Samsung Galaxy S25 Ultra', + ], + ['iPhone 16 Pro 128GB | Viettel Store', 'iPhone 16 Pro 128GB'], + ['iPhone 16 Pro Max - Siêu thị điện máy Pico', 'iPhone 16 Pro Max'], + ['iPhone 16 Pro Max 256GB | MediaMart', 'iPhone 16 Pro Max 256GB'], + ['MacBook Pro 14 M4 - MemoryZone', 'MacBook Pro 14 M4'], + ['Laptop MacBook Air M3 | An Phát Computer', 'Laptop MacBook Air M3'], + ] as const) { + assert.equal( + cleanExtractedProductTitle(rawTitle), + expectedClean, + rawTitle + ); + } + + // 4. DOM extraction with MediaMart .product-price-regular strikethrough original price + const mediamartDoc = { + title: 'Apple iPhone 16 Pro Max 256GB | MediaMart', + querySelectorAll: (sel: string) => + sel === 'script[type="application/ld+json"]' + ? [ + { + textContent: JSON.stringify({ + '@type': 'Product', + name: 'Apple iPhone 16 Pro Max 256GB | MediaMart', + offers: { + '@type': 'Offer', + price: '29990000', + availability: 'https://schema.org/InStock', + }, + }), + }, + ] + : [], + querySelector: (sel: string) => + sel.startsWith('.product-price-regular') + ? { textContent: '34.990.000₫' } + : null, + } as unknown as Document; + const mediamartSignal = extractProductSignalFromDom( + mediamartDoc, + 'https://mediamart.vn/smartphones/apple-iphone-16-pro-max?utm_source=zalo' + ); + assert.ok(mediamartSignal); + assert.equal(mediamartSignal.platform, 'mediamart'); + assert.equal( + mediamartSignal.canonicalUrl, + 'https://mediamart.vn/smartphones/apple-iphone-16-pro-max' + ); + assert.equal(mediamartSignal.externalItemId, 'apple-iphone-16-pro-max'); + assert.equal(mediamartSignal.price, 29_990_000); + assert.equal(mediamartSignal.originalPrice, 34_990_000); + + // 5. Server lookup candidate item ID prefixes across all 12 Wave 1-3 platforms + const dmxIds = buildCandidateExternalItemIds({ + platform: 'dienmayxanh', + externalId: 'iphone-16-pro-max', + }); + assert.ok( + dmxIds.includes('dmx-iphone-16-pro-max') && + dmxIds.includes('tgdd-iphone-16-pro-max') + ); + const tzIds = buildCandidateExternalItemIds({ + platform: 'topzone', + externalId: 'iphone-16-pro-max', + }); + assert.ok( + tzIds.includes('tz-iphone-16-pro-max') && + tzIds.includes('tgdd-iphone-16-pro-max') + ); + assert.ok( + buildCandidateExternalItemIds({ + platform: 'anphatpc', + externalId: 'laptop_id49201', + }).includes('ap-laptop_5fid49201') + ); + assert.ok( + buildCandidateExternalItemIds({ + platform: 'nguyenkim', + externalId: 'iphone_16', + }).includes('nk-iphone_5f16') + ); + + // 6. Service-worker sender validation & DOS-Me SQL boundary (crowd observation skipped for Wave 1-3) + const g1850 = globalThis as Record; + const savedChrome1850 = Object.getOwnPropertyDescriptor(g1850, 'chrome'); + const savedFetch1850 = Object.getOwnPropertyDescriptor(g1850, 'fetch'); + try { + const local1850 = new Map([ + ['apiBaseUrl', 'https://rate.vn'], + ['crowdContributeOptIn', true], + ['crowdConsentVersion', 2], + ]); + const session1850 = new Map(); + const swFetchCalls1850: string[] = []; + let swHandler1850: + | (( + msg: Record, + sender: Record, + sendResponse: (res: unknown) => void + ) => boolean | void) + | null = null; + + Object.defineProperty(g1850, 'chrome', { + configurable: true, + writable: true, + value: { + runtime: { + id: 'rate-ext-1850', + getManifest: () => ({ version: '2.0.0' }), + getURL: (p: string) => `chrome-extension://rate-ext-1850/${p}`, + onInstalled: { addListener: () => {} }, + onStartup: { addListener: () => {} }, + onMessage: { + addListener: (cb: typeof swHandler1850) => { + swHandler1850 = cb; + }, + }, + }, + storage: { + local: { + get: async (keys?: string | string[]) => { + const list = Array.isArray(keys) + ? keys + : typeof keys === 'string' + ? [keys] + : [...local1850.keys()]; + return Object.fromEntries( + list + .filter((k) => local1850.has(k)) + .map((k) => [k, local1850.get(k)]) + ); + }, + set: async (items: Record) => { + for (const [k, v] of Object.entries(items)) local1850.set(k, v); + }, + remove: async (keys: string | string[]) => { + for (const k of Array.isArray(keys) ? keys : [keys]) { + local1850.delete(k); + } + }, + }, + session: { + get: async (keys?: string | string[]) => { + const list = Array.isArray(keys) + ? keys + : typeof keys === 'string' + ? [keys] + : [...session1850.keys()]; + return Object.fromEntries( + list + .filter((k) => session1850.has(k)) + .map((k) => [k, session1850.get(k)]) + ); + }, + set: async (items: Record) => { + for (const [k, v] of Object.entries(items)) + session1850.set(k, v); + }, + remove: async (keys: string | string[]) => { + for (const k of Array.isArray(keys) ? keys : [keys]) { + session1850.delete(k); + } + }, + }, + }, + sidePanel: { + setPanelBehavior: async () => {}, + open: async () => {}, + }, + action: { + setBadgeText: async () => {}, + setBadgeBackgroundColor: async () => {}, + }, + tabs: { + query: async () => [{ id: 88, active: true }], + create: async () => ({ id: 89 }), + }, + }, + }); + Object.defineProperty(g1850, 'fetch', { + configurable: true, + writable: true, + value: async (input: string | URL) => { + const href = String(input); + swFetchCalls1850.push(href); + if (href.includes('/api/v1/rate/extension/submitter')) { + return new Response( + JSON.stringify({ + ok: true, + submitterId: '11111111-1111-4111-8111-111111111111', + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ); + } + if (href.includes('/api/v1/rate/extension/observation')) { + return new Response(JSON.stringify({ ok: true }), { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }); + } + return new Response( + JSON.stringify({ + ok: true, + data: { + matchStatus: 'exact_listing', + platform: 'gearvn', + canonicalUrl: 'https://gearvn.com/products/asus-rog-strix', + detectedStorageGb: 512, + isAccessoryOrPart: false, + accessoryReason: null, + variantCandidates: [], + priceAssessment: { + verdict: 'genuine_deal', + badgeLabel: 'Giá Tốt Thực Sự', + explanation: 'Giá tốt', + observedPrice: 28_990_000, + observedOriginalPrice: 32_990_000, + claimedDiscountPct: 12, + vsMarketMedianPct: -6, + marketMinPrice: 28_990_000, + marketMedianPrice: 30_990_000, + marketMaxPrice: 32_990_000, + historicalMinPrice: 28_990_000, + historicalMaxPrice: 33_990_000, + cheaperOfferCount: 0, + maxSavingsAmount: 0, + }, + masterProduct: null, + matchedOffer: null, + topCheaperOffers: [], + allOffers: [], + merchantProfile: null, + reviewSummary: null, + priceHistory: null, + compareUrl: null, + productDetailUrl: null, + }, + }), + { status: 200, headers: { 'Content-Type': 'application/json' } } + ); + }, + }); + + await import( + new URL('./background/service-worker.js?case=1850sw', import.meta.url) + .href + ); + const callSw1850 = ( + msg: Record, + sender: Record + ) => + new Promise>((resolve) => { + const asyncReply = swHandler1850!(msg, sender, (r) => + resolve(r as Record) + ); + if (asyncReply === false) { + // sendResponse already called synchronously + } + }); + + for (const [platform, pageUrl, itemId] of [ + [ + 'dienmayxanh', + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', + 'iphone-16-pro-max', + ], + [ + 'topzone', + 'https://www.topzone.vn/iphone/iphone-16-pro-max', + 'iphone-16-pro-max', + ], + [ + 'gearvn', + 'https://gearvn.com/products/asus-rog-strix', + 'asus-rog-strix', + ], + [ + 'nguyenkim', + 'https://www.nguyenkim.com/iphone-16-pro-max.html', + 'iphone-16-pro-max', + ], + [ + 'shopdunk', + 'https://shopdunk.com/iphone-16-pro-max', + 'iphone-16-pro-max', + ], + ['hacom', 'https://hacom.vn/macbook-air-m3', 'macbook-air-m3'], + [ + 'clickbuy', + 'https://clickbuy.com.vn/iphone-16-pro-max.html', + 'iphone-16-pro-max', + ], + [ + 'viettelstore', + 'https://viettelstore.vn/dien-thoai/iphone-16-pro-max.html', + 'iphone-16-pro-max', + ], + [ + 'pico', + 'https://pico.vn/39871-iphone-16-pro-max', + '39871-iphone-16-pro-max', + ], + [ + 'mediamart', + 'https://mediamart.vn/smartphones/iphone-16-pro-max', + 'iphone-16-pro-max', + ], + [ + 'memoryzone', + 'https://memoryzone.com.vn/products/macbook-pro-14-m4', + 'macbook-pro-14-m4', + ], + [ + 'anphatpc', + 'https://www.anphatpc.com.vn/macbook-air-m3_id49201.html', + 'macbook-air-m3_id49201', + ], + ] as const) { + const res = await callSw1850( + { + type: 'RATE_PRODUCT_DETECTED', + signal: { + platform, + canonicalUrl: pageUrl, + externalItemId: itemId, + externalShopId: null, + title: 'iPhone 16 Pro Max 256GB', + selectedVariant: '256GB', + price: 28_990_000, + originalPrice: 32_990_000, + ratingStar: 4.9, + ratingCount: 25, + }, + }, + { + id: 'rate-ext-1850', + tab: { id: 88, windowId: 1, active: true }, + url: pageUrl, + } + ); + assert.equal( + res.ok, + true, + `Wave 1-3 lookup must succeed for ${platform}` + ); + } + await new Promise((r) => setTimeout(r, 30)); + assert.equal( + swFetchCalls1850.some( + (u) => u.includes('/submitter') || u.includes('/observation') + ), + false, + 'Wave 1-3 detections must NOT hit extension observation endpoints before DOS-Me SQL migration' + ); + + // Cross-store sender spoofing on Wave 1-3 origins must be rejected + const spoofRes = await callSw1850( + { + type: 'RATE_PRODUCT_DETECTED', + signal: { + platform: 'gearvn', + canonicalUrl: 'https://gearvn.com/products/asus-rog-strix', + externalItemId: 'asus-rog-strix', + externalShopId: null, + title: 'ASUS ROG Strix', + selectedVariant: null, + price: 28_990_000, + originalPrice: null, + ratingStar: null, + ratingCount: null, + }, + }, + { + id: 'rate-ext-1850', + tab: { id: 88, windowId: 1, active: true }, + url: 'https://shopdunk.com/iphone-16-pro-max', + } + ); + assert.equal(spoofRes.ok, false, 'cross-store sender spoofing must fail'); + } finally { + if (savedChrome1850) + Object.defineProperty(g1850, 'chrome', savedChrome1850); + else delete g1850.chrome; + if (savedFetch1850) Object.defineProperty(g1850, 'fetch', savedFetch1850); + else delete g1850.fetch; + } + + console.log( + ' ✅ [Wave 1-3 12 retail platforms across detector, lookup & SQL boundary (#1850)] Verified' + ); + + // Round 1 review hardening (#1850): An Phat multi-segment Apple URLs + SHA-1 truncation, + // prefix-collision candidates, category/editorial guards, O(N) title cleaning & An Phát lang="vi" + const { createHash } = await import('node:crypto'); + const { sanitizeAnPhatItemId } = + await import('./extractors/ecommerce-detector.js'); + const { isVietnameseText } = await import('./i18n.js'); + + assert.deepEqual( + extractIdsFromUrl( + 'anphatpc', + 'https://www.anphatpc.com.vn/apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za/a.html' + ), + { + externalItemId: + 'ap-apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za_2fa', + externalShopId: null, + } + ); + const longAnPhatPath = + 'laptop-apple-macbook-air-mdhf4sa/a-mba-13.6-m5/10c/10gpu/16g/1t/35w/midnight-vietnam-edition-special-config-2026-ultra-extended-sku'; + const expectedNormalized = longAnPhatPath.replace(/[^a-z0-9-]/g, (ch) => { + const hex = ch.codePointAt(0)?.toString(16).padStart(2, '0') ?? '00'; + return `_${hex}`; + }); + const expectedSha1 = createHash('sha1') + .update(expectedNormalized) + .digest('hex') + .slice(0, 10); + const expectedTrimmed = expectedNormalized + .slice(0, 114) + .replace(/[-_]+$/g, ''); + const expectedLongApId = `ap-${expectedTrimmed}-${expectedSha1}`; + assert.equal(sanitizeAnPhatItemId(longAnPhatPath), expectedLongApId); + assert.equal( + extractIdsFromUrl( + 'anphatpc', + `https://www.anphatpc.com.vn/${longAnPhatPath}.html` + ).externalItemId, + expectedLongApId + ); + assert.ok(expectedLongApId.length <= 128); + + // Prefix-starting slugs & pre-prefixed unencoded IDs, plus non-leaking numeric underscore suffixes + const mzSelfPrefixed = buildCandidateExternalItemIds({ + platform: 'memoryzone', + externalId: 'mz-v9p1t0bw', + }); + assert.ok( + mzSelfPrefixed.includes('mz-mz-v9p1t0bw'), + 'raw slug starting with mz- must still produce mz-mz-...' + ); + const apPrePrefixed = buildCandidateExternalItemIds({ + platform: 'anphatpc', + externalId: 'ap-laptop_id49201', + }); + assert.ok( + apPrePrefixed.includes('ap-laptop_5fid49201') && + apPrePrefixed.includes('ap-ap-laptop_5fid49201') + ); + const nkNumericUnderscore = buildCandidateExternalItemIds({ + platform: 'nguyenkim', + externalId: 'laptop_274819201', + }); + assert.equal( + nkNumericUnderscore.includes('274819201'), + false, + 'retail underscore slugs must not leak bare numeric suffixes across platforms' + ); + + // Editorial / brand-category / used-hub rejections on MediaMart, HACOM, Clickbuy, Viettel Store + for (const [plat, nonPdp] of [ + ['mediamart', 'https://mediamart.vn/tu-van-tieu-dung/top-5-iphone-16'], + ['hacom', 'https://hacom.vn/laptop-asus'], + ['hacom', 'https://hacom.vn/laptop-asus-vivobook'], + ['clickbuy', 'https://clickbuy.com.vn/dien-thoai-iphone'], + ['clickbuy', 'https://clickbuy.com.vn/iphone-cu'], + ['clickbuy', 'https://clickbuy.com.vn/thay-pin'], + ['viettelstore', 'https://viettelstore.vn/chuyen-muc-tin/iphone-16'], + ['viettelstore', 'https://viettelstore.vn/dtdd-apple-iphone'], + ] as const) { + assert.equal( + extractIdsFromUrl(plat, nonPdp).externalItemId, + null, + nonPdp + ); + } + assert.equal( + extractIdsFromUrl( + 'hacom', + 'https://hacom.vn/laptop-asus-vivobook-x1407ca-ly008w-ltau1066' + ).externalItemId, + 'laptop-asus-vivobook-x1407ca-ly008w-ltau1066' + ); + assert.equal( + extractIdsFromUrl( + 'anphatpc', + 'https://www.anphatpc.com.vn/tai-nghe-bluetooth-airpods-4-dung-cho-iphone-16_id49202.html' + ).externalItemId, + 'tai-nghe-bluetooth-airpods-4-dung-cho-iphone-16_id49202' + ); + + // Long-input title cleaning, PicoPix model preservation & An Phát Vietnamese detection + const cleanedAdversarial = cleanExtractedProductTitle( + `iPhone 16 Pro${' '.repeat(20_000)}|NotAStore` + ); + assert.ok(cleanedAdversarial.startsWith('iPhone 16 Pro')); + assert.equal( + cleanExtractedProductTitle('Máy chiếu Philips - PicoPix Max | ShopDunk'), + 'Máy chiếu Philips - PicoPix Max' + ); + assert.equal( + cleanExtractedProductTitle('Kính thực tế ảo - Pico 4 Ultra | CellphoneS'), + 'Kính thực tế ảo - Pico 4 Ultra' + ); + assert.equal(isVietnameseText('An Phát Computer'), true); + + // Clickbuy hidden ancestor price container skipped in favor of visible container + const hiddenClickbuyPriceNode = { + textContent: '19.990.000₫', + parentElement: { + hidden: true, + hasAttribute: (attr: string) => attr === 'hidden', + }, + closest: (sel: string) => (sel.includes('[hidden]') ? {} : null), + }; + const visibleClickbuyPriceNode = { + textContent: '24.990.000₫', + parentElement: { hidden: false, hasAttribute: () => false }, + closest: () => null, + }; + const clickbuyHiddenFixtureDoc = { + title: 'iPhone 16 128GB Chính hãng - Clickbuy.com.vn', + querySelectorAll: (sel: string) => { + if (sel === 'script[type="application/ld+json"]') return []; + if (sel.includes('.cb-pbox__now')) { + return [hiddenClickbuyPriceNode, visibleClickbuyPriceNode]; + } + return []; + }, + querySelector: (sel: string) => { + if (sel === 'h1') { + return { textContent: 'iPhone 16 128GB Chính hãng' }; + } + if (sel.includes('.cb-pbox__now')) return hiddenClickbuyPriceNode; + return null; + }, + } as unknown as Document; + const clickbuyHiddenSig = extractProductSignalFromDom( + clickbuyHiddenFixtureDoc, + 'https://clickbuy.com.vn/apple-iphone-16-128gb.html' + ); + assert.ok(clickbuyHiddenSig); + assert.equal( + clickbuyHiddenSig.price, + 24_990_000, + 'must skip hidden Clickbuy price container and read active visible price' + ); + + // Related-product .pro-price-del must never overwrite structured JSON-LD originalPrice + const relatedDelNode = { + textContent: '24.990.000₫', + closest: (sel: string) => (sel.includes('.related-products') ? {} : null), + }; + const structuredListPriceDoc = { + title: 'iPad Gen 10 64GB | GearVN.com', + querySelectorAll: (sel: string) => { + if (sel === 'script[type="application/ld+json"]') { + return [ + { + textContent: JSON.stringify({ + '@type': 'Product', + name: 'iPad Gen 10 64GB', + offers: { + '@type': 'AggregateOffer', + lowPrice: '12990000', + highPrice: '14990000', + availability: 'https://schema.org/InStock', + }, + }), + }, + ]; + } + if (sel.includes('.pro-price-del')) return [relatedDelNode]; + return []; + }, + querySelector: (sel: string) => + sel.includes('.pro-price-del') ? relatedDelNode : null, + } as unknown as Document; + const structuredListSig = extractProductSignalFromDom( + structuredListPriceDoc, + 'https://gearvn.com/products/ipad-gen-10-64gb' + ); + assert.ok(structuredListSig); + assert.equal(structuredListSig.price, 12_990_000); + assert.equal( + structuredListSig.originalPrice, + 14_990_000, + 'related-product .pro-price-del must not replace JSON-LD originalPrice' + ); + } console.log('🎉 All Rate Browser Extension MV3 v2 tests passed!'); } diff --git a/apps/extension/src/types.ts b/apps/extension/src/types.ts index 6daaa903..5244b2f7 100644 --- a/apps/extension/src/types.ts +++ b/apps/extension/src/types.ts @@ -5,10 +5,22 @@ export type SupportedEcommercePlatform = | 'tiktok' | 'cellphones' | 'tgdd' + | 'dienmayxanh' + | 'topzone' | 'fptshop' | 'hoangha' | 'didongviet' - | 'phongvu'; + | 'phongvu' + | 'gearvn' + | 'nguyenkim' + | 'shopdunk' + | 'hacom' + | 'clickbuy' + | 'viettelstore' + | 'pico' + | 'mediamart' + | 'memoryzone' + | 'anphatpc'; export type ExtensionPriceVerdict = | 'genuine_deal' diff --git a/apps/importer/src/shopee/__tests__/shopee-to-supabase.test.ts b/apps/importer/src/shopee/__tests__/shopee-to-supabase.test.ts index 02e165d1..7ff2b8d7 100644 --- a/apps/importer/src/shopee/__tests__/shopee-to-supabase.test.ts +++ b/apps/importer/src/shopee/__tests__/shopee-to-supabase.test.ts @@ -1092,6 +1092,135 @@ async function runTests() { console.log( ' ✅ [8/8] DOS/Rate#879 platformReviewIdFor, review videos/profileUrl & spec group bounds passed' ); + + // 9. DOS/Rate#1850: All 12 Wave 1-3 retail platforms ingest cleanly with canonical shopId and itemId prefixes + const wave1To3Fixtures = [ + { + platform: 'dienmayxanh' as const, + shopId: 'dmx-mwg-vn', + shopName: 'Điện Máy Xanh', + itemId: 'dmx-iphone-16-pro-max-256gb', + url: 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max-256gb', + title: 'Điện thoại iPhone 16 Pro Max 256GB Chính hãng VN/A', + }, + { + platform: 'topzone' as const, + shopId: 'tz-mwg-vn', + shopName: 'TopZone', + itemId: 'tz-iphone-16-pro-max-256gb', + url: 'https://www.topzone.vn/iphone/iphone-16-pro-max-256gb', + title: 'iPhone 16 Pro Max 256GB Chính hãng VN/A', + }, + { + platform: 'gearvn' as const, + shopId: 'gearvn-retail-vn', + shopName: 'GearVN', + itemId: 'gearvn-laptop-apple-macbook-air-m3-13-inch-256gb', + url: 'https://gearvn.com/products/laptop-apple-macbook-air-m3-13-inch-256gb', + title: 'Laptop Apple MacBook Air M3 13 inch 16GB 256GB Chính hãng', + }, + { + platform: 'nguyenkim' as const, + shopId: 'nguyenkim-vn', + shopName: 'Nguyễn Kim', + itemId: 'nk-dien-thoai-iphone-16-pro-max-256gb', + url: 'https://www.nguyenkim.com/dien-thoai-iphone-16-pro-max-256gb.html', + title: 'Điện thoại iPhone 16 Pro Max 256GB Chính hãng', + }, + { + platform: 'shopdunk' as const, + shopId: 'shopdunk-vn', + shopName: 'ShopDunk', + itemId: 'shopdunk-iphone-16-pro-max-256gb', + url: 'https://shopdunk.com/iphone-16-pro-max-256gb', + title: 'iPhone 16 Pro Max 256GB Chính hãng VN/A', + }, + { + platform: 'hacom' as const, + shopId: 'hacom-vn', + shopName: 'HACOM', + itemId: 'hacom-laptop-apple-macbook-air-m3-256gb', + url: 'https://hacom.vn/laptop-apple-macbook-air-m3-256gb', + title: 'Laptop Apple MacBook Air M3 13 inch 16GB 256GB', + }, + { + platform: 'clickbuy' as const, + shopId: 'cb-retail-vn', + shopName: 'Clickbuy', + itemId: 'cb-iphone-16-pro-max-256gb', + url: 'https://clickbuy.com.vn/iphone-16-pro-max-256gb', + title: 'iPhone 16 Pro Max 256GB Chính hãng VN/A', + }, + { + platform: 'viettelstore' as const, + shopId: 'vts-retail-vn', + shopName: 'Viettel Store', + itemId: 'vts-iphone-16-pro-max-256gb-pid341920', + url: 'https://viettelstore.vn/dien-thoai/iphone-16-pro-max-256gb-pid341920.html', + title: 'iPhone 16 Pro Max 256GB Chính hãng', + }, + { + platform: 'pico' as const, + shopId: 'pico-vn', + shopName: 'Pico', + itemId: 'pico-iphone-16-pro-max-256gb', + url: 'https://pico.vn/iphone-16-pro-max-256gb.html', + title: 'Điện thoại Apple iPhone 16 Pro Max 256GB', + }, + { + platform: 'mediamart' as const, + shopId: 'mediamart-vn', + shopName: 'MediaMart', + itemId: 'mm-dien-thoai-apple-iphone-16-pro-max-256gb', + url: 'https://mediamart.vn/smartphones/dien-thoai-apple-iphone-16-pro-max-256gb', + title: 'Điện thoại Apple iPhone 16 Pro Max 256GB', + }, + { + platform: 'memoryzone' as const, + shopId: 'memoryzone-vn', + shopName: 'MemoryZone', + itemId: 'mz-laptop-apple-macbook-air-m3-256gb', + url: 'https://memoryzone.com.vn/products/laptop-apple-macbook-air-m3-256gb', + title: 'Laptop Apple MacBook Air M3 13 inch 16GB 256GB', + }, + { + platform: 'anphatpc' as const, + shopId: 'anphatpc-vn', + shopName: 'An Phát Computer', + itemId: 'ap-laptop-apple-macbook-air-m3-256gb_5fid49201', + url: 'https://www.anphatpc.com.vn/laptop-apple-macbook-air-m3-256gb_id49201.html', + title: 'Laptop Apple MacBook Air M3 13 inch 16GB 256GB', + }, + ]; + for (const fx of wave1To3Fixtures) { + const { stub: waveStub, events: waveEvents } = createPipelineStubSupabase({ + hintRow: { id: 'master-wave-1850' }, + }); + const wavePipeline = new ShopeeIngestionPipeline({ + supabaseClient: waveStub, + apiKey: '', + }); + const waveRes = await wavePipeline.ingestProduct( + createBaseProduct({ + platform: fx.platform, + itemId: fx.itemId, + shopId: fx.shopId, + url: fx.url, + title: fx.title, + shop: { + shopId: fx.shopId, + name: fx.shopName, + isMall: true, + }, + }), + undefined, + { masterIdHint: 'master-wave-1850' } + ); + assert.equal(waveRes.platform, fx.platform); + assert.equal(waveEvents.productUpserts[0]?.platform, fx.platform); + assert.equal(waveEvents.productUpserts[0]?.platform_item_id, fx.itemId); + } + console.log(' ✅ [9/9] DOS/Rate#1850 Wave 1-3 12 retail platforms ingestion passed'); console.log('\n🎉 ALL SHOPEE INGESTION PIPELINE TESTS PASSED!'); } diff --git a/apps/importer/src/shopee/types.ts b/apps/importer/src/shopee/types.ts index 7fb2a5ad..dacd20ce 100644 --- a/apps/importer/src/shopee/types.ts +++ b/apps/importer/src/shopee/types.ts @@ -39,7 +39,19 @@ export type SupportedEcommercePlatform = | 'fptshop' | 'hoangha' | 'didongviet' - | 'phongvu'; + | 'phongvu' + | 'dienmayxanh' + | 'topzone' + | 'gearvn' + | 'nguyenkim' + | 'shopdunk' + | 'hacom' + | 'clickbuy' + | 'viettelstore' + | 'pico' + | 'mediamart' + | 'memoryzone' + | 'anphatpc'; /** * Reviewer metadata scraped alongside a review. What each platform exposes differs diff --git a/apps/web/e2e/deals-copy.spec.ts b/apps/web/e2e/deals-copy.spec.ts index 20380cdb..3e711cb2 100644 --- a/apps/web/e2e/deals-copy.spec.ts +++ b/apps/web/e2e/deals-copy.spec.ts @@ -3,9 +3,9 @@ import { expect, test } from '@playwright/test'; // /deals reads in plain words in every locale: no "radar", "audit" or // "kèo thơm" labels, and sentence-case headings (DOS/Rate#659). const TITLES = { - vi: 'Deal đáng tiền nhất, đã lọc khuyến mãi ảo trên 10 sàn', - en: 'Best-value deals with fake sales filtered out (10 stores)', - cs: 'Nejvýhodnější nabídky bez falešných slev (10 obchodů)', + vi: 'Deal đáng tiền nhất, đã lọc khuyến mãi ảo trên 22 sàn', + en: 'Best-value deals with fake sales filtered out (22 stores)', + cs: 'Nejvýhodnější nabídky bez falešných slev (22 obchodů)', }; for (const [locale, title] of Object.entries(TITLES)) { diff --git a/apps/web/locales/cs.json b/apps/web/locales/cs.json index 80c2685a..ea5b02d3 100644 --- a/apps/web/locales/cs.json +++ b/apps/web/locales/cs.json @@ -178,7 +178,7 @@ "leadingDeltaNote": "(Náskok +{delta} b. v celkovém hodnocení)", "labScorePending": "Lab: nedostupné", "price60dStable": "Cena stabilní", - "radarRowTitle": "Cenový signál z 10 obchodů (pod mediánem, falešné slevy)", + "radarRowTitle": "Cenový signál z 22 obchodů (pod mediánem, falešné slevy)", "md1v1Heading": "Verdikt souboje 1v1: {nameA} vs {nameB}", "mdLeadingDevice": "Vedoucí zařízení", "mdScoreDelta": "Rozdíl {delta} b.", @@ -321,7 +321,7 @@ "addSameCategoryTitle": "Přidat {unit} ze stejné kategorie", "addCategorySlotTitle": "Přidat {category}", "remainingSlotsSub": "Volné pozice: {remaining}", - "radarRowMatrixTitle": "Cenový signál z 10 obchodů (nabídky pod mediánem a falešné slevy)", + "radarRowMatrixTitle": "Cenový signál z 22 obchodů (nabídky pod mediánem a falešné slevy)", "radarStableMedian": "Stabilní kolem tržního mediánu", "radarGenuineFloor": "Cenové dno napříč obchody (-{pct} % vs medián • {platform})", "radarBelowMedian": "Pod mediánem (-{pct} % • {platform})", @@ -335,7 +335,7 @@ "mdRowBatteryEnergy": "Baterie a energie", "csvColSpecGroup": "Skupina parametrů", "csvColTechCriterion": "Technické kritérium", - "csvRadarGroupTitle": "0. Cenový signál z 10 obchodů", + "csvRadarGroupTitle": "0. Cenový signál z 22 obchodů", "csvRadarVerdictRow": "Verdikt a cenová odchylka", "quickToggleLimitTitle": "Maximálně 4 zařízení v porovnávací tabulce", "quickToggleRemoveTitle": "Odebrat ze seznamu porovnání", @@ -677,12 +677,12 @@ "cloudSavedPartial": "Uloženo pouze {saved}/{total} upozornění do Rate Cloud{errorSuffix}. Ostatní zůstávají v prohlížeči.", "cloudSaveError": "Chyba připojení, upozornění se nepodařilo uložit do Rate Cloud.", "mdHeader": "### 🔔 Hlídané ceny na Rate.vn ({count, plural, one {# model} few {# modely} other {# modelů}})", - "mdTotalMin": "- **Celková hodnota portfolia (nejnižší cena z 10 platforem):** {price} ₫", + "mdTotalMin": "- **Celková hodnota portfolia (nejnižší cena z 22 platforem):** {price} ₫", "mdTotalTarget": "- **Celkový cílový rozpočet:** {price} ₫", "mdTotalSpread": "- **Celková úspora z rozdílů mezi platformami:** {price} ₫", "mdAvgRating": "- **Průměrné skóre JReviews v portfoliu:** ★ {rating}", "mdNoRating": "N/A", - "mdTableHead": "| Zařízení | Značka | Aktuální minimum | Cílová cena | Rozpětí 10 obchodů | Cenový signál | Stav | Nejlepší nabídka |", + "mdTableHead": "| Zařízení | Značka | Aktuální minimum | Cílová cena | Rozpětí 22 obchodů | Cenový signál | Stav | Nejlepší nabídka |", "mdSourcesCount": "{count, plural, one {# zdroj} few {# zdroje} other {# zdrojů}}", "mdStatusReached": "✅ Cíl dosažen", "mdStatusWatching": "⏳ Hlídáno", @@ -698,7 +698,7 @@ "compareSameCatBtn": "Porovnat {count} zařízení stejné kategorie", "kpiTotalMinLabel": "Hodnota portfolia (minimální ceny)", "kpiTotalTargetLabel": "Celkový cílový rozpočet", - "kpiSpreadSavingsLabel": "Úspora napříč 10 platformami", + "kpiSpreadSavingsLabel": "Úspora napříč 22 platformami", "kpiAvgRatingLabel": "Průměrné skóre JReviews", "kpiNoRating": "Zatím bez hodnocení", "cloudExplain": "Upozornění v Rate Cloud jsou propojena s přihlášeným účtem DOS ID a zasílána na e-mail při dosažení cílové ceny.", @@ -721,7 +721,7 @@ "radarGenuineBadge": "Minimum napříč obchody (-{pct} % oproti mediánu na {platform})", "radarBelowMedianBadge": "Pod mediánem (-{pct} % na {platform})", "radarFakeBadge": "{platform} umělé navýšení +{pct} %", - "radarSpreadBadge": "Rozpětí 10 platforem +{pct} % (rozdíl {vnd} ₫ mezi {cheapest} a {priciest})", + "radarSpreadBadge": "Rozpětí 22 platforem +{pct} % (rozdíl {vnd} ₫ mezi {cheapest} a {priciest})", "savedDateLabel": "Uloženo: {date}", "colCurrentLowest": "Aktuální nejnižší cena", "highestPriceSub": "Nejvyšší: {price} ₫", @@ -752,10 +752,10 @@ "sizeRequiredProductLink": "Otevřít stránku produktu" }, "deals": { - "metaTitle": "Výhodné nabídky ověřené v 10 obchodech | Rate.vn", - "metaDescription": "Najděte nejvýhodnější technologická zařízení podle rozpočtu a způsobu využití, ověřená porovnáním cen napříč obchody a filtrem falešných slev na 10 tržištích.", + "metaTitle": "Výhodné nabídky ověřené ve 22 obchodech | Rate.vn", + "metaDescription": "Najděte nejvýhodnější technologická zařízení podle rozpočtu a způsobu využití, ověřená porovnáním cen napříč obchody a filtrem falešných slev na 22 tržištích.", "pageEyebrow": "Ověřené slevy", - "pageTitle": "Nejvýhodnější nabídky bez falešných slev (10 obchodů)", + "pageTitle": "Nejvýhodnější nabídky bez falešných slev (22 obchodů)", "pageSubtitle": "Řadí zařízení podle poměru cena / skóre JReviews a úspor mezi oficiálními obchody. Podporuje export do Markdown, CSV a JSON.", "leaderboardBtn": "Žebříček JReviews", "inspectBtn": "Ověřit odkaz na falešnou slevu", @@ -770,7 +770,7 @@ "personaPhotography": "Fotoaparát a zvuk", "personaGaming": "Výkon a hraní her", "personaEndurance": "Výdrž baterie a nabíjení", - "radarMdHeader": "### 🔥 Ceny pod mediánem a falešné slevy v 10 obchodech - Rate.vn", + "radarMdHeader": "### 🔥 Ceny pod mediánem a falešné slevy ve 22 obchodech - Rate.vn", "radarMdMeta": "- **Kategorie:** {category} | **Analyzované klastry:** {clusters} ({offers, plural, one {# nabídka} few {# nabídky} other {# nabídek}})", "radarMdGenuineTitle": "#### 🟢 Pod mediánem napříč obchody", "radarMdGenuineTableHead": "| Zařízení | Obchod / prodejce | Aktuální cena | Medián nabídek | Skutečná úspora | Skóre JReviews |", @@ -784,7 +784,7 @@ "dealsMdUrlLine": "- **Zobrazit na Rate.vn:** {url}", "dealsMdTableHead": "| Pořadí | Zařízení | Značka | Skóre profilu | Skóre JReviews | Nejnižší cena | Úspora mezi obchody | Cenový signál |", "samePrice": "Stejná cena", - "filterBadge": "Nabídky ověřené v 10 obchodech", + "filterBadge": "Nabídky ověřené ve 22 obchodech", "showingCount": "Zobrazeno {visible} z {count} zařízení v rámci rozpočtu", "copiedMdBtn": "✓ Markdown zkopírován!", "copyMdBtn": "Kopírovat Markdown", @@ -795,7 +795,7 @@ "maxBudgetLabel": "Maximální rozpočet:", "maxBudgetAria": "Maximální rozpočet", "searchPlaceholder": "Rychlé hledání podle názvu modelu nebo značky (Apple, Samsung, Xiaomi, Sony...)", - "radarBannerBadge": "Ceny pod mediánem a upozornění na falešné slevy v 10 obchodech", + "radarBannerBadge": "Ceny pod mediánem a upozornění na falešné slevy ve 22 obchodech", "radarScannedSummary": "{offers, plural, one {Prohledána # nabídka} few {Prohledány # nabídky} other {Prohledáno # nabídek}} napříč {clusters, plural, one {# produktovým klastrem} other {# produktovými klastry}}", "copiedRadarMdBtn": "✓ Cenové signály zkopírovány", "copyRadarMdBtn": "Kopírovat cenové signály (Markdown)", @@ -815,7 +815,7 @@ "labNoScore": "Lab: N/A", "spreadSavingsBadge": "Úspora mezi platformami {amount} ₫", "costPerPointSub": "({cost} ₫ / bod JReviews)", - "audit10PlatformsLink": "Porovnat ceny v 10 obchodech →", + "audit10PlatformsLink": "Porovnat ceny ve 22 obchodech →", "radarBadgeGenuine": "🔥 Minimum napříč obchody (-{pct} %)", "radarBadgeBelowMedian": "✅ Pod mediánem (-{pct} %)", "radarBadgeFakeTrap": "🚨 Upozornění na falešnou slevu (+{pct} %)", @@ -850,12 +850,12 @@ "genuineDiscountBadge": "Uvedená cena odpovídá skutečné historii cen.", "implausiblyLowBadge": "Podezřele nízká cena", "implausiblyLowTitle": "Mnohem levnější než všechny ostatní obchody: může jít o padělek, příslušenství nebo návnadu. Před nákupem obchod pečlivě ověřte.", - "radarSectionBadge": "Cenové signály a rozdíly cen v 10 obchodech", - "openDealRadarLink": "Zobrazit nabídky z 10 obchodů →", + "radarSectionBadge": "Cenové signály a rozdíly cen ve 22 obchodech", + "openDealRadarLink": "Zobrazit nabídky z 22 obchodů →", "radarGenuinePill": "Nejnižší cena v obchodech: -{pct} % na {platform} ({price} ₫)", "radarBelowMedianPill": "Pod mediánem: -{pct} % na {platform} ({price} ₫)", "radarFakePill": "Falešná sleva: +{pct} % na {platform}", - "radarSpreadPill": "Rozdíl cen v 10 obchodech: +{pct} % ({vnd} ₫ mezi {cheapest} a {priciest})", + "radarSpreadPill": "Rozdíl cen ve 22 obchodech: +{pct} % ({vnd} ₫ mezi {cheapest} a {priciest})", "masterProductSection": "Nalezený produkt (10 skupin parametrů)", "userNoScore": "Kupující: bez skóre", "expertNoScore": "bez skóre", @@ -1007,7 +1007,7 @@ "profileRadarGenuineCount": "{count, plural, one {# nabídka} few {# nabídky} other {# nabídek}} pod mediánem", "profileRadarFakeCount": "{count} varování na falešnou slevu", "profileRadarZeroFake": "0 varování na falešnou slevu", - "openRadar10PlatformsBtn": "Slevy z 10 obchodů →", + "openRadar10PlatformsBtn": "Slevy z 22 obchodů →", "low60dAndMedian": "Tržní minimum: {min} ₫ • Medián: {median} ₫", "vsMedianBadge": "-{pct} % oproti mediánu", "inflatedOriginalPrice": "Uměle navýšená cena: {price} ₫", @@ -1141,7 +1141,7 @@ "noOffersYet": "K tomuto modelu zatím nejsou připojeny žádné nabídky e-shopů.", "competitorsBadge": "Produkty ze stejného segmentu ({category})", "competitorsTitle": "Alternativy pro {name}", - "dealHub10PlatformsBtn": "Slevy z 10 obchodů", + "dealHub10PlatformsBtn": "Slevy z 22 obchodů", "compareAllPeersBtn": "{count, plural, =2 {Porovnat oba modely} few {Porovnat všechny # modely} other {Porovnat všech # modelů}} →", "peerNoRating": "není", "cheaperByBadge": "O {amount} ₫ levnější", @@ -1340,7 +1340,7 @@ "compare10GroupsBtn": "Porovnat 10 skupin parametrů", "scoreDeltaLabel": "Rozdíl {delta} bodu", "view1v1ScoreBtn": "Zobrazit souboj 1v1", - "radarHomeBadge": "Cenové signály z 10 obchodů", + "radarHomeBadge": "Cenové signály z 22 obchodů", "radarHomeAnalyzed": "Automatické porovnání {offers, plural, one {# nabídky} other {# nabídek}} od {merchants, plural, one {# prodejce} other {# prodejců}} napříč {clusters, plural, one {# produktovým klastrem} other {# produktovými klastry}}", "radarHomeDealHubBtn": "Centrum slev", "radarHomeInspectBtn": "Ověřit odkaz na akci", @@ -1429,9 +1429,9 @@ "ep5Params": "q nebo url (odkaz Shopee/Lazada/Tiki nebo klíčové slovo)", "ep5Summary": "Analýza odkazu na produkt nebo obchod a automatické spárování s normalizovaným produktem a profilem důvěryhodnosti prodejce. Limit 30 požadavků za minutu na IP adresu (společný s /inspect); po jeho překročení přijde 429 s hlavičkou Retry-After.", "ep6Params": "q nebo url (URL nebo název modelu), price (viděná cena, volitelné), originalPrice (přeškrtnutá cena, volitelné)", - "ep6Summary": "Kontrola ceny a odkazu (/inspect): normalizuje URL na 10 tržištích a u prodejců, vyřazuje příslušenství a díly, porovná s mediánem ceny a vrátí 5stupňový verdikt. Limit 30 požadavků za minutu na IP adresu (společný s /lookup); po jeho překročení přijde 429 s hlavičkou Retry-After.", + "ep6Summary": "Kontrola ceny a odkazu (/inspect): normalizuje URL na 22 tržištích a u prodejců, vyřazuje příslušenství a díly, porovná s mediánem ceny a vrátí 5stupňový verdikt. Limit 30 požadavků za minutu na IP adresu (společný s /lookup); po jeho překročení přijde 429 s hlavičkou Retry-After.", "ep7Params": "url, title, price, originalPrice, skuText", - "ep7Summary": "Rychlý endpoint pro rozšíření prohlížeče Rate na 10 tržištích a u prodejců (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu).", + "ep7Summary": "Rychlý endpoint pro rozšíření prohlížeče Rate na 22 tržištích a u prodejců (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat).", "ep8Params": "Body JSON: { url, title, price, originalPrice?, platform?, selectedVariant?, userConsentOptIn: true }", "ep8Summary": "Přijímá anonymní signály o produktech z rozšíření prohlížeče se souhlasem uživatele: ověří strukturu, odstraní osobní identifikátory (PII) a zařadí je do fronty rate.crawl_jobs.", "ep9Params": "platform, officialOnly, min_trust, q, sort, limit", @@ -1513,7 +1513,7 @@ "pgPreset5Title": "Přímé srovnání (/versus)", "pgPreset5Desc": "Hodnotí dva modely stejné kategorie podle 5 kritérií (displej, výkon, fotoaparát, baterie, hodnota) s nastavitelnými vahami a cenovým rozdílem.", "pgPreset6Title": "Kontrola ceny a odkazu (/inspect)", - "pgPreset6Desc": "Kontrola libovolné URL nebo názvu modelu na 10 tržištích a u prodejců (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu) s 5stupňovým verdiktem ceny.", + "pgPreset6Desc": "Kontrola libovolné URL nebo názvu modelu na 22 tržištích a u prodejců (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat) s 5stupňovým verdiktem ceny.", "pgPreset7Title": "Vyhledávání pro rozšíření prohlížeče", "pgPreset7Desc": "Rychlý endpoint pro rozšíření prohlížeče Rate: normalizuje URL, vyřazuje příslušenství a díly a vrací 5stupňový verdikt ceny.", "pgPreset8Title": "Odeslání signálu o produktu (POST)", @@ -1524,8 +1524,8 @@ "pgPreset10Desc": "Hromadný dotaz na nejnižší aktuální ceny, historické mediány a stav skutečné/falešné slevy pro sledované produkty.", "pgPreset11Title": "Celkové statistiky platformy (/stats)", "pgPreset11Desc": "Vrací počet normalizovaných produktů, záznamů historie cen, podíl autentických recenzí a počty modelů podle kategorií.", - "pgPreset12Title": "Skutečné slevy a falešné výprodeje na 10 tržištích (/deals)", - "pgPreset12Desc": "Prochází ceny na 10 tržištích a hledá skutečně nízké ceny (genuineDeals) a nafouknuté původní ceny (fakeSaleTraps).", + "pgPreset12Title": "Skutečné slevy a falešné výprodeje na 22 tržištích (/deals)", + "pgPreset12Desc": "Prochází ceny na 22 tržištích a hledá skutečně nízké ceny (genuineDeals) a nafouknuté původní ceny (fakeSaleTraps).", "pgPreset13Title": "Specifikace OpenAPI 3.1.0 (/openapi.json)", "pgPreset13Desc": "Vrací specifikaci OpenAPI 3.1.0 ve formátu JSON pro endpointy Rate.vn REST API v1.", "authPublic": "Veřejný přístup (CORS)", @@ -1600,7 +1600,7 @@ "privacyS4Title": "4. Soukromé údaje prodejců", "privacyS4Desc": "Soukromé údaje prodejce (telefonní číslo, bankovní účet) jsou v polích, která veřejnost nemůže číst. Web i API mohou číst jen veřejná pole.", "privacyS5Title": "5. Rozšíření prohlížeče Rate.vn", - "privacyS5Desc": "Na stránkách produktů 10 podporovaných obchodů rozšíření posílá Rate.vn obchod, URL produktu bez parametrů, název produktu, ID položky a obchodu, zvolenou variantu, cenu a původní cenu, aby vyhledalo historii cen; toto vyhledávání je zapnuté ve výchozím stavu, jen čte a nepotřebuje účet. Text, který napíšete do vyhledávacího pole rozšíření, se také odešle k vyhledání. Jen když zvolíte \"Ano\" na stránce zobrazené při instalaci nebo zapnete \"Pomoc s hledáním nových produktů (jen když ji zapnete)\" v bočním panelu (ve výchozím stavu vypnuto), posílá také do fronty ke kontrole záznam o dané nabídce: obchod, URL bez parametrů, ID položky a obchodu, ID varianty (SKU), zvolenou variantu, cenu, původní cenu, stav a počet kusů skladem, čas, kdy jste cenu viděli, a verzi rozšíření, spolu s náhodným ID přispěvatele této instalace. Server jej ukládá s časem přijetí a s osoleným otiskem rozsahu vaší sítě (ne IP adresou), aby rozlišil nezávislé odesílatele; otisk se maže po 28 dnech a záznam po 180 dnech. Servery Rate.vn mohou nabídku v obchodě znovu ověřit a tato data sama veřejné ceny nemění. Vypnutím přispívání se ID přispěvatele i všechny odeslané záznamy smažou; pokud rozšíření odinstalujete bez vypnutí, smažou se po 180 dnech. Rozšíření neposílá účet, jméno, e-mail ani cookies, neotevírá stránky, které jste neotevřeli, a ve vašem prohlížeči ukládá jen adresu serveru, volbu opt-in, ID přispěvatele této instalace, dokud přispíváte, a mezipaměť platnou po dobu relace s produkty, které jste si prohlédli, vaším posledním hledáním, výsledky vyhledávání a dobou čekání na další vyhledání. Jako u každého webového požadavku server obdrží vaši IP adresu: kód Rate.vn ji používá v paměti pro limit požadavků za minutu a při přispívání k odvození výše uvedeného otisku rozsahu sítě; samotná IP adresa se nikdy neukládá a náš poskytovatel hostingu uchovává běžné přístupové záznamy po krátkou dobu.", + "privacyS5Desc": "Na stránkách produktů 22 podporovaných obchodů rozšíření posílá Rate.vn obchod, URL produktu bez parametrů, název produktu, ID položky a obchodu, zvolenou variantu, cenu a původní cenu, aby vyhledalo historii cen; toto vyhledávání je zapnuté ve výchozím stavu, jen čte a nepotřebuje účet. Text, který napíšete do vyhledávacího pole rozšíření, se také odešle k vyhledání. Jen když zvolíte \"Ano\" na stránce zobrazené při instalaci nebo zapnete \"Pomoc s hledáním nových produktů (jen když ji zapnete)\" v bočním panelu (ve výchozím stavu vypnuto), posílá také do fronty ke kontrole záznam o dané nabídce v 10 obchodech se zapnutou kontrolní frontou (12 novějších řetězců je zatím pouze pro čtecí vyhledávání): obchod, URL bez parametrů, ID položky a obchodu, ID varianty (SKU), zvolenou variantu, cenu, původní cenu, stav a počet kusů skladem, čas, kdy jste cenu viděli, a verzi rozšíření, spolu s náhodným ID přispěvatele této instalace. Server jej ukládá s časem přijetí a s osoleným otiskem rozsahu vaší sítě (ne IP adresou), aby rozlišil nezávislé odesílatele; otisk se maže po 28 dnech a záznam po 180 dnech. Servery Rate.vn mohou nabídku v obchodě znovu ověřit a tato data sama veřejné ceny nemění. Vypnutím přispívání se ID přispěvatele i všechny odeslané záznamy smažou; pokud rozšíření odinstalujete bez vypnutí, smažou se po 180 dnech. Rozšíření neposílá účet, jméno, e-mail ani cookies, neotevírá stránky, které jste neotevřeli, a ve vašem prohlížeči ukládá jen adresu serveru, volbu opt-in, ID přispěvatele této instalace, dokud přispíváte, a mezipaměť platnou po dobu relace s produkty, které jste si prohlédli, vaším posledním hledáním, výsledky vyhledávání a dobou čekání na další vyhledání. Jako u každého webového požadavku server obdrží vaši IP adresu: kód Rate.vn ji používá v paměti pro limit požadavků za minutu a při přispívání k odvození výše uvedeného otisku rozsahu sítě; samotná IP adresa se nikdy neukládá a náš poskytovatel hostingu uchovává běžné přístupové záznamy po krátkou dobu.", "privacySide1Title": "Ověřte si otevřený kód", "privacySide1Desc": "Pravidla přístupu k datům a způsob ukládání hlasů jsou veřejné v repozitáři na GitHubu.", "privacySide1Btn": "Technická a API dokumentace", @@ -1634,7 +1634,7 @@ "contactSeoDesc": "Nahlaste falešné slevy nebo falešné recenze, nebo požádejte o přezkoumání důvěryhodnosti prodejce na Rate.vn.", "contactHeroBadge": "Kontakt a zpětná vazba", "contactHeroTitle": "Rychlá inspekce a nahlášení podezřelého obchodu", - "contactHeroDesc": "Vložte níže odkaz na produkt nebo obchod ze Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet nebo Phong Vu a zobrazte historii cen, nebo odkaz pošlete Rate.vn ke kontrole.", + "contactHeroDesc": "Vložte níže odkaz na produkt nebo obchod ze 22 podporovaných obchodů (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat) pro okamžité zobrazení historie cen, nebo odešlete odkaz z 10 obchodů se zapnutou kontrolní frontou ke kontrole Rate.vn.", "contactCard1Title": "1. Nahlášení falešných slev a falešných recenzí", "contactCard1Desc": "Když uvidíte původní cenu navýšenou před výprodejem, vložte odkaz na produkt do kontroly na této stránce. Když uvidíte falešné účty opakující šablonové recenze, přihlaste se a u té recenze na stránce produktu klikněte na \"Nahlásit\".", "contactCard1Btn": "Přejít do katalogu produktů →", @@ -1673,7 +1673,7 @@ "quarantineOutcome": { "accepted": "Odkaz je ve frontě ke kontrole. Zadaná cena se nezveřejní přímo.", "noConsent": "Před odesláním zaškrtněte souhlas se sdílením.", - "invalidUrl": "Nejde o stránku produktu z jednoho z 10 podporovaných obchodů. Otevřete stránku produktu a zkopírujte odkaz znovu.", + "invalidUrl": "Nejde o stránku produktu z jednoho z 22 podporovaných obchodů. Otevřete stránku produktu a zkopírujte odkaz znovu.", "platformPending": "Rate.vn zatím nepřijímá odkazy z tohoto obchodu. Zkuste to prosím později.", "invalidPrice": "Aktuální cena není platná. Zadejte částku v dongech.", "accessory": "Vypadá to na příslušenství nebo díl. Rate.vn sleduje jen ceny zařízení.", @@ -1865,10 +1865,10 @@ "sortByPrefix": "Řazení: {label}", "radarBannerBadge": "Ceny pod mediánem a falešné slevy ({title})", "radarAnalyzedSub": "{count, plural, one {Zkontrolována # nabídka} few {Zkontrolovány # nabídky} other {Zkontrolováno # nabídek}}", - "viewAllRadarBtn": "Zobrazit všechny nabídky z 10 obchodů", + "viewAllRadarBtn": "Zobrazit všechny nabídky z 22 obchodů", "vsMedianBadge": "-{pct} % oproti mediánu", "fakeMarkupBadge": "Nadsazeno +{pct} %", - "spreadHeader": "Největší cenový rozptyl na 10 tržištích ({title}):", + "spreadHeader": "Největší cenový rozptyl na 22 tržištích ({title}):", "spreadSub": "Ušetřete miliony VND výběrem správného tržiště", "spreadDiffBadge": "Rozdíl +{pct} % ({amount} ₫)", "emptySyncingTitle": "Kategorie \"{title}\" čeká na synchronizaci normalizovaných dat", diff --git a/apps/web/locales/en.json b/apps/web/locales/en.json index 5a68f494..4fb58a61 100644 --- a/apps/web/locales/en.json +++ b/apps/web/locales/en.json @@ -178,7 +178,7 @@ "leadingDeltaNote": "(+{delta} pts lead on overall stars)", "labScorePending": "Lab: pending", "price60dStable": "Price stable", - "radarRowTitle": "10-store price signal (below-median deals, fake sales)", + "radarRowTitle": "22-store price signal (below-median deals, fake sales)", "md1v1Heading": "1v1 verdict: {nameA} vs {nameB}", "mdLeadingDevice": "Leading device", "mdScoreDelta": "Delta {delta} pts", @@ -321,7 +321,7 @@ "addSameCategoryTitle": "Add same-category {unit}", "addCategorySlotTitle": "Add {category}", "remainingSlotsSub": "{remaining} same-category slots available", - "radarRowMatrixTitle": "Price signal across 10 stores (below-median deals and fake sales)", + "radarRowMatrixTitle": "Price signal across 22 stores (below-median deals and fake sales)", "radarStableMedian": "Stable near the market median", "radarGenuineFloor": "Cross-platform price floor (-{pct}% vs median • {platform})", "radarBelowMedian": "Below median (-{pct}% • {platform})", @@ -335,7 +335,7 @@ "mdRowBatteryEnergy": "Battery and power", "csvColSpecGroup": "Spec group", "csvColTechCriterion": "Technical criterion", - "csvRadarGroupTitle": "0. Price signal across 10 stores", + "csvRadarGroupTitle": "0. Price signal across 22 stores", "csvRadarVerdictRow": "Verdict and price gap", "quickToggleLimitTitle": "Maximum 4 devices in comparison table", "quickToggleRemoveTitle": "Remove from comparison list", @@ -677,12 +677,12 @@ "cloudSavedPartial": "Saved {saved}/{total} alerts to Rate Cloud{errorSuffix}. Remaining alerts are kept in this browser.", "cloudSaveError": "Network error while syncing alerts to Rate Cloud.", "mdHeader": "### 🔔 Price watchlist on Rate.vn ({count, plural, one {# model} other {# models}})", - "mdTotalMin": "- **Total value (lowest price across 10 stores):** {price} ₫", + "mdTotalMin": "- **Total value (lowest price across 22 stores):** {price} ₫", "mdTotalTarget": "- **Total target budget:** {price} ₫", "mdTotalSpread": "- **Total cross-store savings:** {price} ₫", "mdAvgRating": "- **Average JReviews score:** ★ {rating}", "mdNoRating": "N/A", - "mdTableHead": "| Device | Brand | Current lowest | Target price | 10-store gap | Price signal | Status | Best offer |", + "mdTableHead": "| Device | Brand | Current lowest | Target price | 22-store gap | Price signal | Status | Best offer |", "mdSourcesCount": "{count, plural, one {# source} other {# sources}}", "mdStatusReached": "✅ Target reached", "mdStatusWatching": "⏳ Watching", @@ -698,7 +698,7 @@ "compareSameCatBtn": "Compare {count, plural, one {# same-category device} other {# same-category devices}}", "kpiTotalMinLabel": "Total at lowest prices", "kpiTotalTargetLabel": "Total target budget", - "kpiSpreadSavingsLabel": "Savings across 10 stores", + "kpiSpreadSavingsLabel": "Savings across 22 stores", "kpiAvgRatingLabel": "Average JReviews score", "kpiNoRating": "No score yet", "cloudExplain": "Rate Cloud alerts are linked to your signed-in DOS ID account and emailed when prices hit your target threshold.", @@ -721,7 +721,7 @@ "radarGenuineBadge": "Cross-platform low (-{pct}% vs median on {platform})", "radarBelowMedianBadge": "Below median (-{pct}% on {platform})", "radarFakeBadge": "{platform} fake markup +{pct}%", - "radarSpreadBadge": "Price gap across 10 stores +{pct}% ({vnd} ₫ between {cheapest} and {priciest})", + "radarSpreadBadge": "Price gap across 22 stores +{pct}% ({vnd} ₫ between {cheapest} and {priciest})", "savedDateLabel": "Saved on: {date}", "colCurrentLowest": "Current lowest price", "highestPriceSub": "Highest: {price} ₫", @@ -752,10 +752,10 @@ "sizeRequiredProductLink": "Open the product page" }, "deals": { - "metaTitle": "Best-value tech deals, checked across 10 stores | Rate.vn", - "metaDescription": "Find the best-value tech devices by budget and usage persona, cross-checked against cross-platform prices and fake discount filters across 10 marketplaces.", + "metaTitle": "Best-value tech deals, checked across 22 stores | Rate.vn", + "metaDescription": "Find the best-value tech devices by budget and usage persona, cross-checked against cross-platform prices and fake discount filters across 22 marketplaces.", "pageEyebrow": "Verified deal discovery", - "pageTitle": "Best-value deals with fake sales filtered out (10 stores)", + "pageTitle": "Best-value deals with fake sales filtered out (22 stores)", "pageSubtitle": "Ranks devices by Price-to-JReviews Score efficiency and cross-platform arbitrage savings across official stores. Supports Markdown, CSV, and JSON exports.", "leaderboardBtn": "JReviews Leaderboard", "inspectBtn": "Check a fake-discount link", @@ -770,7 +770,7 @@ "personaPhotography": "Camera and audio", "personaGaming": "Performance and gaming", "personaEndurance": "Battery and fast charging", - "radarMdHeader": "### 🔥 Below-median prices and fake-sale warnings (10 stores) - Rate.vn", + "radarMdHeader": "### 🔥 Below-median prices and fake-sale warnings (22 stores) - Rate.vn", "radarMdMeta": "- **Category:** {category} | **Clusters analyzed:** {clusters} ({offers, plural, one {# listing} other {# listings}})", "radarMdGenuineTitle": "#### 🟢 Below the cross-store median", "radarMdGenuineTableHead": "| Device | Store / seller | Current price | Listing median | Real savings | JReviews score |", @@ -784,7 +784,7 @@ "dealsMdUrlLine": "- **View on Rate.vn:** {url}", "dealsMdTableHead": "| Rank | Device | Brand | Priority score | JReviews score | Lowest price | Cross-store savings | Price signal |", "samePrice": "Uniform price", - "filterBadge": "Deals checked across 10 stores", + "filterBadge": "Deals checked across 22 stores", "showingCount": "Showing {visible} of {count, plural, one {# device} other {# devices}} within your budget", "copiedMdBtn": "✓ Markdown Copied!", "copyMdBtn": "Copy Markdown", @@ -795,7 +795,7 @@ "maxBudgetLabel": "Maximum budget:", "maxBudgetAria": "Maximum budget", "searchPlaceholder": "Quick search by model name or brand (Apple, Samsung, Xiaomi, Sony...)", - "radarBannerBadge": "Below-median prices and fake-sale warnings across 10 stores", + "radarBannerBadge": "Below-median prices and fake-sale warnings across 22 stores", "radarScannedSummary": "Scanned {offers, plural, one {# merchant listing} other {# merchant listings}} across {clusters, plural, one {# product cluster} other {# product clusters}}", "copiedRadarMdBtn": "✓ Price signals copied", "copyRadarMdBtn": "Copy price signals (Markdown)", @@ -815,7 +815,7 @@ "labNoScore": "Lab: N/A", "spreadSavingsBadge": "Cross-platform savings {amount} ₫", "costPerPointSub": "({cost} ₫ / JReviews pt)", - "audit10PlatformsLink": "Compare prices across 10 stores →", + "audit10PlatformsLink": "Compare prices across 22 stores →", "radarBadgeGenuine": "🔥 Cross-platform low (-{pct}%)", "radarBadgeBelowMedian": "✅ Below median (-{pct}%)", "radarBadgeFakeTrap": "🚨 Fake sale warning (+{pct}%)", @@ -850,12 +850,12 @@ "genuineDiscountBadge": "The listed price matches the real price history.", "implausiblyLowBadge": "Suspiciously low price", "implausiblyLowTitle": "Far cheaper than every other store: possibly a counterfeit, an accessory or a bait listing. Check the shop carefully before buying.", - "radarSectionBadge": "Price signals and price gaps across 10 stores", - "openDealRadarLink": "See deals across 10 stores →", + "radarSectionBadge": "Price signals and price gaps across 22 stores", + "openDealRadarLink": "See deals across 22 stores →", "radarGenuinePill": "Lowest across stores: -{pct}% on {platform} ({price} ₫)", "radarBelowMedianPill": "Below median: -{pct}% on {platform} ({price} ₫)", "radarFakePill": "Fake discount: +{pct}% on {platform}", - "radarSpreadPill": "Price gap across 10 stores: +{pct}% ({vnd} ₫ between {cheapest} and {priciest})", + "radarSpreadPill": "Price gap across 22 stores: +{pct}% ({vnd} ₫ between {cheapest} and {priciest})", "masterProductSection": "Matched product (10 spec groups)", "userNoScore": "Buyers: no score", "expertNoScore": "no score", @@ -1007,7 +1007,7 @@ "profileRadarGenuineCount": "{count, plural, one {# below-median listing} other {# below-median listings}}", "profileRadarFakeCount": "{count, plural, one {# fake-sale markup alert} other {# fake-sale markup alerts}}", "profileRadarZeroFake": "0 fake-sale markup alerts", - "openRadar10PlatformsBtn": "Deals across 10 stores →", + "openRadar10PlatformsBtn": "Deals across 22 stores →", "low60dAndMedian": "Market low: {min} ₫ • Median: {median} ₫", "vsMedianBadge": "-{pct}% vs median", "inflatedOriginalPrice": "Inflated list price: {price} ₫", @@ -1141,7 +1141,7 @@ "noOffersYet": "No marketplace listings are currently linked to this model.", "competitorsBadge": "Same-segment products ({category})", "competitorsTitle": "Alternatives to {name}", - "dealHub10PlatformsBtn": "Deals across 10 stores", + "dealHub10PlatformsBtn": "Deals across 22 stores", "compareAllPeersBtn": "{count, plural, =2 {Compare both models} other {Compare all # models}} →", "peerNoRating": "N/A", "cheaperByBadge": "{amount} ₫ cheaper", @@ -1340,7 +1340,7 @@ "compare10GroupsBtn": "Compare 10 spec groups", "scoreDeltaLabel": "{delta} pts apart", "view1v1ScoreBtn": "See the 1v1 breakdown", - "radarHomeBadge": "Price signals across 10 stores", + "radarHomeBadge": "Price signals across 22 stores", "radarHomeAnalyzed": "Automatically cross-checking {offers, plural, one {# listing} other {# listings}} from {merchants, plural, one {# merchant} other {# merchants}} across {clusters, plural, one {# product cluster} other {# product clusters}}", "radarHomeDealHubBtn": "Deal hub", "radarHomeInspectBtn": "Check a sale link", @@ -1429,9 +1429,9 @@ "ep5Params": "q or url (Shopee/Lazada/Tiki link or keyword)", "ep5Summary": "Read a product or shop link and match it to a normalized product and the seller's trust profile. Limited to 30 requests per minute per IP (shared with /inspect); past the limit the answer is a 429 with a Retry-After header.", "ep6Params": "q or url (URL or model name), price (price you see, optional), originalPrice (struck-through price, optional)", - "ep6Summary": "Price and link check (/inspect): normalizes URLs across 10 marketplaces and retailers, filters out accessories and parts, compares against the median price and returns a 5-level price verdict. Limited to 30 requests per minute per IP (shared with /lookup); past the limit the answer is a 429 with a Retry-After header.", + "ep6Summary": "Price and link check (/inspect): normalizes URLs across 22 marketplaces and retailers, filters out accessories and parts, compares against the median price and returns a 5-level price verdict. Limited to 30 requests per minute per IP (shared with /lookup); past the limit the answer is a 429 with a Retry-After header.", "ep7Params": "url, title, price, originalPrice, skuText", - "ep7Summary": "Fast endpoint for the Rate browser extension across 10 marketplaces and retailers (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu).", + "ep7Summary": "Fast endpoint for the Rate browser extension across 22 marketplaces and retailers (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat).", "ep8Params": "Body JSON: { url, title, price, originalPrice?, platform?, selectedVariant?, userConsentOptIn: true }", "ep8Summary": "Accepts anonymous product signals from the browser extension once the user has consented: validates the shape, strips personal identifiers (PII) and queues them in rate.crawl_jobs.", "ep9Params": "platform, officialOnly, min_trust, q, sort, limit", @@ -1513,7 +1513,7 @@ "pgPreset5Title": "Head to head (/versus)", "pgPreset5Desc": "Scores two same-category models on 5 criteria (display, performance, camera, battery, value), with adjustable weights and the price gap.", "pgPreset6Title": "Price and link check (/inspect)", - "pgPreset6Desc": "Check any product URL or model name across 10 marketplaces and retailers (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu) and get a 5-level price verdict.", + "pgPreset6Desc": "Check any product URL or model name across 22 marketplaces and retailers (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat) and get a 5-level price verdict.", "pgPreset7Title": "Browser extension lookup", "pgPreset7Desc": "Fast endpoint for the Rate browser extension: normalizes URLs, filters out accessories and parts, and returns a 5-level price verdict.", "pgPreset8Title": "Send a product signal (POST)", @@ -1524,8 +1524,8 @@ "pgPreset10Desc": "Get current lowest prices, median prices and real-or-fake discount verdicts for watched products in one call.", "pgPreset11Title": "Platform numbers (/stats)", "pgPreset11Desc": "Returns master product counts, price observations, the share of genuine reviews and models per category.", - "pgPreset12Title": "Real deals and fake sales on 10 marketplaces (/deals)", - "pgPreset12Desc": "Scans prices across 10 marketplaces to find genuinely low prices (genuineDeals) and inflated original prices (fakeSaleTraps).", + "pgPreset12Title": "Real deals and fake sales on 22 marketplaces (/deals)", + "pgPreset12Desc": "Scans prices across 22 marketplaces to find genuinely low prices (genuineDeals) and inflated original prices (fakeSaleTraps).", "pgPreset13Title": "OpenAPI 3.1.0 spec (/openapi.json)", "pgPreset13Desc": "Returns the OpenAPI 3.1.0 spec in JSON for the Rate.vn REST API v1 endpoints.", "authPublic": "Public (CORS)", @@ -1600,7 +1600,7 @@ "privacyS4Title": "4. Sellers' private details", "privacyS4Desc": "A seller's private details (phone number, bank account) are kept in fields the public cannot read. The website and the API can only read the public fields.", "privacyS5Title": "5. The Rate.vn browser extension", - "privacyS5Desc": "On product pages of the 10 supported stores, the extension sends Rate.vn the store, the product URL without its parameters, the product title, the item and shop ids, the selected variant, the price and the original price to look up price history; this lookup is on by default, read-only and needs no account. Text you type into the extension's search box is also sent to look it up. Only if you choose \"Yes\" on the page shown at install or turn on \"Help find new products (only when you turn it on)\" in the side panel (off by default) does it also send an observation of that listing to a moderation queue: the store, the URL without its parameters, the item and shop ids, the variant ID (SKU), the selected variant, the price, the original price, the stock status and quantity, the time you saw the price and the extension version, with a random contributor ID for this install. The server stores it with the time it was received and a salted hash of your network range (not your IP) to tell independent senders apart; the hash is deleted after 28 days and the observation after 180 days. Rate.vn's servers may re-check that listing on the store, and this data does not change public prices by itself. Turning contributions off deletes the contributor ID and every observation sent with it; if you uninstall without turning it off, they are deleted after 180 days. The extension sends no account, name, email or cookies, opens no page you did not open, and keeps only the server address, the opt-in choice, the contributor ID while you contribute, and a session-only cache of the products you viewed, your latest search, their lookup results and a lookup wait time in your browser. Like any web request, the server receives your IP address: Rate.vn's code uses it in memory for a per-minute request limit and, when you contribute, to derive the network-range hash above; the IP itself is never stored, and our hosting provider keeps standard access logs for a short time.", + "privacyS5Desc": "On product pages of the 22 supported stores, the extension sends Rate.vn the store, the product URL without its parameters, the product title, the item and shop ids, the selected variant, the price and the original price to look up price history; this lookup is on by default, read-only and needs no account. Text you type into the extension's search box is also sent to look it up. Only if you choose \"Yes\" on the page shown at install or turn on \"Help find new products (only when you turn it on)\" in the side panel (off by default) does it also send an observation of that listing to a moderation queue on the 10 stores with queue support enabled (the 12 newer retail chains are currently read-only lookup-only): the store, the URL without its parameters, the item and shop ids, the variant ID (SKU), the selected variant, the price, the original price, the stock status and quantity, the time you saw the price and the extension version, with a random contributor ID for this install. The server stores it with the time it was received and a salted hash of your network range (not your IP) to tell independent senders apart; the hash is deleted after 28 days and the observation after 180 days. Rate.vn's servers may re-check that listing on the store, and this data does not change public prices by itself. Turning contributions off deletes the contributor ID and every observation sent with it; if you uninstall without turning it off, they are deleted after 180 days. The extension sends no account, name, email or cookies, opens no page you did not open, and keeps only the server address, the opt-in choice, the contributor ID while you contribute, and a session-only cache of the products you viewed, your latest search, their lookup results and a lookup wait time in your browser. Like any web request, the server receives your IP address: Rate.vn's code uses it in memory for a per-minute request limit and, when you contribute, to derive the network-range hash above; the IP itself is never stored, and our hosting provider keeps standard access logs for a short time.", "privacySide1Title": "Check the open code", "privacySide1Desc": "The data access rules and how votes are stored are public in the GitHub repository.", "privacySide1Btn": "Technical and API docs", @@ -1634,7 +1634,7 @@ "contactSeoDesc": "Report fake discounts or fake reviews, or ask for a seller trust review on Rate.vn.", "contactHeroBadge": "Contact & feedback", "contactHeroTitle": "Quick URL inspection & suspicious merchant reporting", - "contactHeroDesc": "Paste a product or shop link from Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, FPT Shop, Hoang Ha, Di Dong Viet or Phong Vu below to see its price history, or send the link for Rate.vn to check.", + "contactHeroDesc": "Paste a product or shop link from 22 supported marketplaces and retailers (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDD, Dien May Xanh, TopZone, FPT Shop, Hoang Ha, Di Dong Viet, Phong Vu, GearVN, Nguyen Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phat) below to see its price history right away, or submit a link from the 10 queue-enabled stores for Rate.vn to check.", "contactCard1Title": "1. Report fake discounts and fake reviews", "contactCard1Desc": "If you see a list price inflated before a sale, paste the product link into the checker on this page. If you see fake accounts repeating template reviews, sign in and click \"Report\" on that review on the product page.", "contactCard1Btn": "Go to product catalog →", @@ -1673,7 +1673,7 @@ "quarantineOutcome": { "accepted": "The link is in the queue for checking. The price you entered is not published directly.", "noConsent": "Please tick the sharing consent box before sending.", - "invalidUrl": "This is not a product page from one of the 10 supported stores. Open the product page and copy its link again.", + "invalidUrl": "This is not a product page from one of the 22 supported stores. Open the product page and copy its link again.", "platformPending": "Rate.vn is not taking links from this store yet. Please try again later.", "invalidPrice": "The current price is not valid. Enter the amount in dong.", "accessory": "This looks like an accessory or a part. Rate.vn only tracks device prices.", @@ -1865,10 +1865,10 @@ "sortByPrefix": "Sort: {label}", "radarBannerBadge": "Below-median prices and fake-sale warnings ({title})", "radarAnalyzedSub": "Checked {count, plural, one {# store listing} other {# store listings}}", - "viewAllRadarBtn": "See all deals across 10 stores", + "viewAllRadarBtn": "See all deals across 22 stores", "vsMedianBadge": "-{pct}% vs median", "fakeMarkupBadge": "Inflated +{pct}%", - "spreadHeader": "Largest price gap across 10 marketplaces ({title}):", + "spreadHeader": "Largest price gap across 22 marketplaces ({title}):", "spreadSub": "Save millions of VND by choosing the right marketplace", "spreadDiffBadge": "Spread +{pct}% ({amount} ₫)", "emptySyncingTitle": "Category \"{title}\" is awaiting normalized product data sync", diff --git a/apps/web/locales/vi.json b/apps/web/locales/vi.json index fc2d20cd..72f4ea0e 100644 --- a/apps/web/locales/vi.json +++ b/apps/web/locales/vi.json @@ -178,7 +178,7 @@ "leadingDeltaNote": "(Chênh lệch +{delta} điểm sao tổng)", "labScorePending": "Lab: chưa có", "price60dStable": "Giá ổn định", - "radarRowTitle": "Tín hiệu giá 10 sàn (deal dưới trung vị, giảm giá ảo)", + "radarRowTitle": "Tín hiệu giá 22 sàn (deal dưới trung vị, giảm giá ảo)", "md1v1Heading": "Kết luận so sánh 1v1: {nameA} vs {nameB}", "mdLeadingDevice": "Thiết bị dẫn trước", "mdScoreDelta": "Chênh lệch {delta} điểm", @@ -321,7 +321,7 @@ "addSameCategoryTitle": "Thêm {unit} cùng danh mục", "addCategorySlotTitle": "Thêm {category}", "remainingSlotsSub": "Còn trống {remaining} vị trí cùng nhóm", - "radarRowMatrixTitle": "Tín hiệu giá trên 10 sàn (deal dưới giá trung vị và giảm giá ảo)", + "radarRowMatrixTitle": "Tín hiệu giá trên 22 sàn (deal dưới giá trung vị và giảm giá ảo)", "radarStableMedian": "Ổn định quanh trung vị thị trường", "radarGenuineFloor": "Đáy giá đa sàn (-{pct}% so với trung vị • {platform})", "radarBelowMedian": "Dưới giá trung vị (-{pct}% • {platform})", @@ -335,7 +335,7 @@ "mdRowBatteryEnergy": "Pin và năng lượng", "csvColSpecGroup": "Nhóm thông số", "csvColTechCriterion": "Tiêu chí kỹ thuật", - "csvRadarGroupTitle": "0. Tín hiệu giá trên 10 sàn", + "csvRadarGroupTitle": "0. Tín hiệu giá trên 22 sàn", "csvRadarVerdictRow": "Kết luận và độ lệch giá", "quickToggleLimitTitle": "Tối đa 4 thiết bị trong bảng so sánh", "quickToggleRemoveTitle": "Bỏ khỏi danh sách so sánh", @@ -677,12 +677,12 @@ "cloudSavedPartial": "Chỉ lưu được {saved}/{total} cảnh báo lên Rate Cloud{errorSuffix}. Các cảnh báo còn lại vẫn nằm trên trình duyệt này.", "cloudSaveError": "Lỗi kết nối, chưa lưu được cảnh báo lên Rate Cloud.", "mdHeader": "### 🔔 Danh sách theo dõi giá trên Rate.vn ({count} mẫu)", - "mdTotalMin": "- **Tổng giá trị (giá thấp nhất trên 10 sàn):** {price} ₫", + "mdTotalMin": "- **Tổng giá trị (giá thấp nhất trên 22 sàn):** {price} ₫", "mdTotalTarget": "- **Tổng ngân sách mục tiêu:** {price} ₫", "mdTotalSpread": "- **Tổng tiết kiệm giữa các sàn:** {price} ₫", "mdAvgRating": "- **Điểm JReviews trung bình danh mục:** ★ {rating}", "mdNoRating": "chưa có", - "mdTableHead": "| Thiết bị | Hãng | Giá thấp nhất hiện tại | Giá mục tiêu | Chênh lệch 10 sàn | Tín hiệu giá | Trạng thái | Deal tốt nhất |", + "mdTableHead": "| Thiết bị | Hãng | Giá thấp nhất hiện tại | Giá mục tiêu | Chênh lệch 22 sàn | Tín hiệu giá | Trạng thái | Deal tốt nhất |", "mdSourcesCount": "{count} nguồn", "mdStatusReached": "✅ Đạt mục tiêu", "mdStatusWatching": "⏳ Đang canh", @@ -698,7 +698,7 @@ "compareSameCatBtn": "So sánh {count} máy cùng danh mục", "kpiTotalMinLabel": "Tổng giá trị danh mục (Giá đáy)", "kpiTotalTargetLabel": "Tổng ngân sách mục tiêu", - "kpiSpreadSavingsLabel": "Tiết kiệm giữa 10 sàn", + "kpiSpreadSavingsLabel": "Tiết kiệm giữa 22 sàn", "kpiAvgRatingLabel": "Điểm JReviews trung bình danh mục", "kpiNoRating": "Chưa có", "cloudExplain": "Cảnh báo trên Rate Cloud gắn với tài khoản DOS ID đã đăng nhập và gửi tới email của tài khoản đó khi giá chạm ngưỡng mục tiêu.", @@ -721,7 +721,7 @@ "radarGenuineBadge": "Đáy giá đa sàn (-{pct}% so trung vị tại {platform})", "radarBelowMedianBadge": "Dưới giá trung vị (-{pct}% tại {platform})", "radarFakeBadge": "Cảnh báo sàn {platform} kê khống +{pct}%", - "radarSpreadBadge": "Độ lệch 10 sàn +{pct}% (Chênh {vnd} ₫ giữa {cheapest} & {priciest})", + "radarSpreadBadge": "Độ lệch 22 sàn +{pct}% (Chênh {vnd} ₫ giữa {cheapest} & {priciest})", "savedDateLabel": "Lưu ngày: {date}", "colCurrentLowest": "Giá hiện tại thấp nhất", "highestPriceSub": "Cao nhất: {price} ₫", @@ -752,10 +752,10 @@ "sizeRequiredProductLink": "Mở trang sản phẩm" }, "deals": { - "metaTitle": "Deal công nghệ đã kiểm tra trên 10 sàn | Rate.vn", - "metaDescription": "Tìm kiếm thiết bị công nghệ đáng tiền nhất theo ngân sách và nhu cầu sử dụng, đã đối chiếu giá giữa các sàn và lọc khuyến mãi ảo trên 10 sàn TMĐT.", + "metaTitle": "Deal công nghệ đã kiểm tra trên 22 sàn | Rate.vn", + "metaDescription": "Tìm kiếm thiết bị công nghệ đáng tiền nhất theo ngân sách và nhu cầu sử dụng, đã đối chiếu giá giữa các sàn và lọc khuyến mãi ảo trên 22 sàn và đại lý.", "pageEyebrow": "Săn deal đã kiểm chứng", - "pageTitle": "Deal đáng tiền nhất, đã lọc khuyến mãi ảo trên 10 sàn", + "pageTitle": "Deal đáng tiền nhất, đã lọc khuyến mãi ảo trên 22 sàn", "pageSubtitle": "Xếp hạng thiết bị theo chỉ số hiệu suất giá / điểm JReviews và biên độ tiết kiệm giữa các sàn chính hãng. Hỗ trợ xuất Markdown, CSV và JSON.", "leaderboardBtn": "Bảng xếp hạng JReviews", "inspectBtn": "Kiểm tra link giảm giá ảo", @@ -770,7 +770,7 @@ "personaPhotography": "Camera và âm thanh", "personaGaming": "Hiệu năng và chơi game", "personaEndurance": "Pin trâu và sạc nhanh", - "radarMdHeader": "### 🔥 Giá dưới trung vị các sàn và cảnh báo giá gốc bị nâng khống (10 sàn) - Rate.vn", + "radarMdHeader": "### 🔥 Giá dưới trung vị các sàn và cảnh báo giá gốc bị nâng khống (22 sàn) - Rate.vn", "radarMdMeta": "- **Ngành hàng:** {category} | **Cụm sản phẩm phân tích:** {clusters} ({offers} tin bán)", "radarMdGenuineTitle": "#### 🟢 Rẻ hơn giá trung vị các sàn", "radarMdGenuineTableHead": "| Thiết bị | Sàn / gian hàng | Giá bán hiện tại | Giá trung vị các tin bán | Tiết kiệm thật | Điểm JReviews |", @@ -784,7 +784,7 @@ "dealsMdUrlLine": "- **Xem trên Rate.vn:** {url}", "dealsMdTableHead": "| Hạng | Thiết bị | Hãng | Điểm theo nhu cầu | Điểm JReviews | Giá thấp nhất | Tiết kiệm giữa các sàn | Tín hiệu giá |", "samePrice": "Đồng giá", - "filterBadge": "Tìm deal đã kiểm tra trên 10 sàn", + "filterBadge": "Tìm deal đã kiểm tra trên 22 sàn", "showingCount": "Hiển thị {visible} trên {count} thiết bị trong ngân sách", "copiedMdBtn": "✓ Đã sao chép Markdown!", "copyMdBtn": "Sao chép Markdown", @@ -795,7 +795,7 @@ "maxBudgetLabel": "Ngân sách tối đa:", "maxBudgetAria": "Ngân sách tối đa", "searchPlaceholder": "Tìm nhanh theo tên máy hoặc thương hiệu (Apple, Samsung, Xiaomi, Sony...)", - "radarBannerBadge": "Deal dưới giá trung vị và cảnh báo giảm giá ảo trên 10 sàn", + "radarBannerBadge": "Deal dưới giá trung vị và cảnh báo giảm giá ảo trên 22 sàn", "radarScannedSummary": "Đã quét {offers} tin bán trên {clusters} cụm sản phẩm", "copiedRadarMdBtn": "✓ Đã chép tín hiệu giá", "copyRadarMdBtn": "Sao chép tín hiệu giá (Markdown)", @@ -815,7 +815,7 @@ "labNoScore": "Lab: chưa có", "spreadSavingsBadge": "Chênh sàn tiết kiệm {amount} ₫", "costPerPointSub": "({cost} ₫ / điểm JReviews)", - "audit10PlatformsLink": "So sánh giá trên 10 sàn →", + "audit10PlatformsLink": "So sánh giá trên 22 sàn →", "radarBadgeGenuine": "🔥 Đáy giá đa sàn (-{pct}%)", "radarBadgeBelowMedian": "✅ Dưới giá trung vị (-{pct}%)", "radarBadgeFakeTrap": "🚨 Cảnh báo giảm giá ảo (+{pct}%)", @@ -850,12 +850,12 @@ "genuineDiscountBadge": "Giá niêm yết khớp với lịch sử giá thật.", "implausiblyLowBadge": "Giá thấp bất thường", "implausiblyLowTitle": "Rẻ hơn nhiều so với mọi nơi bán khác: có thể là hàng giả, phụ kiện hoặc tin câu khách. Hãy kiểm tra kỹ gian hàng trước khi mua.", - "radarSectionBadge": "Tín hiệu giá trên 10 sàn và chênh lệch giá", - "openDealRadarLink": "Xem deal trên 10 sàn →", + "radarSectionBadge": "Tín hiệu giá trên 22 sàn và chênh lệch giá", + "openDealRadarLink": "Xem deal trên 22 sàn →", "radarGenuinePill": "Giá thấp nhất các sàn: -{pct}% tại {platform} ({price} ₫)", "radarBelowMedianPill": "Dưới giá trung vị: -{pct}% tại {platform} ({price} ₫)", "radarFakePill": "Giảm giá ảo: +{pct}% tại {platform}", - "radarSpreadPill": "Chênh lệch giá trên 10 sàn: +{pct}% ({vnd} ₫ giữa {cheapest} và {priciest})", + "radarSpreadPill": "Chênh lệch giá trên 22 sàn: +{pct}% ({vnd} ₫ giữa {cheapest} và {priciest})", "masterProductSection": "Sản phẩm khớp (10 nhóm thông số)", "userNoScore": "Người mua: chưa có điểm", "expertNoScore": "chưa có điểm", @@ -1007,7 +1007,7 @@ "profileRadarGenuineCount": "{count} tin bán dưới giá trung vị", "profileRadarFakeCount": "{count} cảnh báo kê khống giá gốc", "profileRadarZeroFake": "0 cảnh báo nâng khống giá gốc", - "openRadar10PlatformsBtn": "Xem deal trên 10 sàn →", + "openRadar10PlatformsBtn": "Xem deal trên 22 sàn →", "low60dAndMedian": "Thấp nhất thị trường: {min} ₫ • Trung vị: {median} ₫", "vsMedianBadge": "-{pct}% so trung vị", "inflatedOriginalPrice": "Giá gạch ngang kê khống: {price} ₫", @@ -1141,7 +1141,7 @@ "noOffersYet": "Hiện chưa có sàn bán nào liên kết với mẫu máy này.", "competitorsBadge": "Sản phẩm cùng phân khúc ({category})", "competitorsTitle": "Lựa chọn thay thế cho {name}", - "dealHub10PlatformsBtn": "Xem deal trên 10 sàn", + "dealHub10PlatformsBtn": "Xem deal trên 22 sàn", "compareAllPeersBtn": "So sánh cả {count} máy →", "peerNoRating": "chưa có", "cheaperByBadge": "Rẻ hơn {amount} ₫", @@ -1340,7 +1340,7 @@ "compare10GroupsBtn": "So sánh 10 nhóm thông số", "scoreDeltaLabel": "Chênh {delta} điểm", "view1v1ScoreBtn": "Xem chấm điểm 1v1", - "radarHomeBadge": "Tín hiệu giá trên 10 sàn", + "radarHomeBadge": "Tín hiệu giá trên 22 sàn", "radarHomeAnalyzed": "Đối chiếu tự động {offers} tin bán của {merchants} gian hàng trên {clusters} cụm sản phẩm", "radarHomeDealHubBtn": "Trung tâm săn deal", "radarHomeInspectBtn": "Kiểm tra link khuyến mãi", @@ -1429,9 +1429,9 @@ "ep5Params": "q hoặc url (link Shopee/Lazada/Tiki hoặc từ khóa)", "ep5Summary": "Đọc link sản phẩm hoặc gian hàng, ghép với sản phẩm chuẩn hóa và hồ sơ tin cậy của gian hàng. Giới hạn 30 yêu cầu mỗi phút cho mỗi IP (dùng chung với /inspect); vượt giới hạn sẽ nhận mã 429. Retry-After trong header cho biết số giây cần chờ.", "ep6Params": "q hoặc url (URL hoặc tên máy), price (giá đang thấy, không bắt buộc), originalPrice (giá gốc bị gạch, không bắt buộc)", - "ep6Summary": "Kiểm tra giá và link (/inspect): chuẩn hóa URL trên 10 sàn và đại lý, loại phụ kiện và linh kiện, so với giá trung vị rồi trả kết luận giá 5 mức. Giới hạn 30 yêu cầu mỗi phút cho mỗi IP (dùng chung với /lookup); vượt giới hạn sẽ nhận mã 429. Retry-After trong header cho biết số giây cần chờ.", + "ep6Summary": "Kiểm tra giá và link (/inspect): chuẩn hóa URL trên 22 sàn và đại lý, loại phụ kiện và linh kiện, so với giá trung vị rồi trả kết luận giá 5 mức. Giới hạn 30 yêu cầu mỗi phút cho mỗi IP (dùng chung với /lookup); vượt giới hạn sẽ nhận mã 429. Retry-After trong header cho biết số giây cần chờ.", "ep7Params": "url, title, price, originalPrice, skuText", - "ep7Summary": "Endpoint nhanh cho tiện ích trình duyệt Rate trên 10 sàn và đại lý (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ).", + "ep7Summary": "Endpoint nhanh cho tiện ích trình duyệt Rate trên 22 sàn và đại lý (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phát).", "ep8Params": "Body JSON: { url, title, price, originalPrice?, platform?, selectedVariant?, userConsentOptIn: true }", "ep8Summary": "Nhận tín hiệu sản phẩm ẩn danh từ tiện ích trình duyệt khi người dùng đã đồng ý: kiểm tra cấu trúc, xóa tham số định danh cá nhân (PII) rồi đưa vào hàng đợi rate.crawl_jobs.", "ep9Params": "platform, officialOnly, min_trust, q, sort, limit", @@ -1513,7 +1513,7 @@ "pgPreset5Title": "So sánh trực tiếp hai máy (/versus)", "pgPreset5Desc": "Chấm điểm hai mẫu cùng ngành hàng theo 5 tiêu chí (màn hình, hiệu năng, camera, pin, đáng tiền), cho phép đổi trọng số theo nhu cầu và tính chênh lệch giá.", "pgPreset6Title": "Kiểm tra giá và link (/inspect)", - "pgPreset6Desc": "Kiểm tra URL hoặc tên máy trên 10 sàn và đại lý (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ) rồi trả kết luận giá 5 mức.", + "pgPreset6Desc": "Kiểm tra URL hoặc tên máy trên 22 sàn và đại lý (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phát) rồi trả kết luận giá 5 mức.", "pgPreset7Title": "Tra cứu cho tiện ích trình duyệt", "pgPreset7Desc": "Endpoint nhanh cho tiện ích trình duyệt Rate: chuẩn hóa URL, loại phụ kiện và linh kiện, trả kết luận giá 5 mức.", "pgPreset8Title": "Gửi tín hiệu sản phẩm (POST)", @@ -1524,8 +1524,8 @@ "pgPreset10Desc": "Truy vấn hàng loạt giá thấp nhất hiện tại, trung vị lịch sử và trạng thái giảm giá thật/ảo cho danh sách sản phẩm đang theo dõi.", "pgPreset11Title": "Số liệu toàn nền tảng (/stats)", "pgPreset11Desc": "Trả về số lượng sản phẩm chuẩn hóa, bản ghi lịch sử giá, tỷ lệ đánh giá thực chất và số lượng mẫu theo từng ngành hàng.", - "pgPreset12Title": "Deal thật và giảm giá ảo trên 10 sàn (/deals)", - "pgPreset12Desc": "Quét giá trên 10 sàn để tìm giá thấp thật (genuineDeals) và giá gốc bị nâng khống (fakeSaleTraps).", + "pgPreset12Title": "Deal thật và giảm giá ảo trên 22 sàn (/deals)", + "pgPreset12Desc": "Quét giá trên 22 sàn để tìm giá thấp thật (genuineDeals) và giá gốc bị nâng khống (fakeSaleTraps).", "pgPreset13Title": "Spec OpenAPI 3.1.0 (/openapi.json)", "pgPreset13Desc": "Trả về spec OpenAPI 3.1.0 dạng JSON cho các endpoint REST API v1 của Rate.vn.", "authPublic": "Công khai (CORS)", @@ -1600,7 +1600,7 @@ "privacyS4Title": "4. Thông tin riêng của gian hàng", "privacyS4Desc": "Thông tin riêng của gian hàng (số điện thoại, tài khoản ngân hàng) nằm ở các trường mà công chúng không đọc được. Trang web và API chỉ đọc được các trường công khai.", "privacyS5Title": "5. Tiện ích trình duyệt Rate.vn", - "privacyS5Desc": "Trên trang sản phẩm của 10 sàn được hỗ trợ, tiện ích gửi cho Rate.vn sàn, URL sản phẩm đã bỏ tham số, tên sản phẩm, mã sản phẩm và mã gian hàng, phiên bản đang chọn, giá bán và giá gốc để tra lịch sử giá; việc tra cứu này bật sẵn, chỉ đọc và không cần tài khoản. Nội dung bạn gõ vào ô tìm kiếm của tiện ích cũng được gửi để tra cứu. Chỉ khi bạn chọn \"Có\" ở trang hiện ra lúc cài đặt hoặc bật \"Đóng góp phát hiện sản phẩm mới (chỉ khi bạn bật)\" trong bảng bên cạnh (mặc định tắt), tiện ích còn gửi vào hàng đợi kiểm duyệt một quan sát về tin bán đó: sàn, URL đã bỏ tham số, mã sản phẩm, mã gian hàng, mã SKU của phân loại, phiên bản đang chọn, giá bán, giá gốc, tình trạng và số lượng còn hàng, thời điểm bạn thấy giá và phiên bản tiện ích, kèm một mã người đóng góp ngẫu nhiên của lượt cài này. Máy chủ lưu kèm thời điểm nhận và một mã băm có muối của dải mạng (không phải IP) để phân biệt người gửi độc lập; mã băm được xóa sau 28 ngày, quan sát sau 180 ngày. Máy chủ Rate.vn có thể kiểm tra lại tin bán đó trên sàn, và dữ liệu này không tự đổi giá công khai. Tắt đóng góp là xóa mã người đóng góp cùng mọi quan sát đã gửi; nếu gỡ tiện ích mà chưa tắt, chúng tự xóa sau 180 ngày. Tiện ích không gửi tài khoản, tên, email hay cookie, không mở trang bạn không mở, và chỉ lưu trên trình duyệt của bạn địa chỉ máy chủ, lựa chọn có đóng góp hay không, mã người đóng góp khi bạn đóng góp, cùng bộ nhớ tạm theo phiên gồm các sản phẩm bạn vừa xem, lần tìm kiếm gần nhất, kết quả tra cứu và thời gian chờ khi bị giới hạn tra cứu. Như mọi yêu cầu web, máy chủ nhận địa chỉ IP của bạn: mã của Rate.vn dùng nó trong bộ nhớ để giới hạn số yêu cầu mỗi phút và, khi bạn đóng góp, để tính mã băm dải mạng nói trên; bản thân IP không bao giờ được lưu, còn nhà cung cấp hosting giữ nhật ký truy cập thông thường trong thời gian ngắn.", + "privacyS5Desc": "Trên trang sản phẩm của 22 sàn được hỗ trợ, tiện ích gửi cho Rate.vn sàn, URL sản phẩm đã bỏ tham số, tên sản phẩm, mã sản phẩm và mã gian hàng, phiên bản đang chọn, giá bán và giá gốc để tra lịch sử giá; việc tra cứu này bật sẵn, chỉ đọc và không cần tài khoản. Nội dung bạn gõ vào ô tìm kiếm của tiện ích cũng được gửi để tra cứu. Chỉ khi bạn chọn \"Có\" ở trang hiện ra lúc cài đặt hoặc bật \"Đóng góp phát hiện sản phẩm mới (chỉ khi bạn bật)\" trong bảng bên cạnh (mặc định tắt), tiện ích còn gửi vào hàng đợi kiểm duyệt một quan sát về tin bán đó trên 10 sàn đã mở hàng đợi kiểm duyệt (12 chuỗi bán lẻ mới hiện chỉ tra cứu một chiều): sàn, URL đã bỏ tham số, mã sản phẩm, mã gian hàng, mã SKU của phân loại, phiên bản đang chọn, giá bán, giá gốc, tình trạng và số lượng còn hàng, thời điểm bạn thấy giá và phiên bản tiện ích, kèm một mã người đóng góp ngẫu nhiên của lượt cài này. Máy chủ lưu kèm thời điểm nhận và một mã băm có muối của dải mạng (không phải IP) để phân biệt người gửi độc lập; mã băm được xóa sau 28 ngày, quan sát sau 180 ngày. Máy chủ Rate.vn có thể kiểm tra lại tin bán đó trên sàn, và dữ liệu này không tự đổi giá công khai. Tắt đóng góp là xóa mã người đóng góp cùng mọi quan sát đã gửi; nếu gỡ tiện ích mà chưa tắt, chúng tự xóa sau 180 ngày. Tiện ích không gửi tài khoản, tên, email hay cookie, không mở trang bạn không mở, và chỉ lưu trên trình duyệt của bạn địa chỉ máy chủ, lựa chọn có đóng góp hay không, mã người đóng góp khi bạn đóng góp, cùng bộ nhớ tạm theo phiên gồm các sản phẩm bạn vừa xem, lần tìm kiếm gần nhất, kết quả tra cứu và thời gian chờ khi bị giới hạn tra cứu. Như mọi yêu cầu web, máy chủ nhận địa chỉ IP của bạn: mã của Rate.vn dùng nó trong bộ nhớ để giới hạn số yêu cầu mỗi phút và, khi bạn đóng góp, để tính mã băm dải mạng nói trên; bản thân IP không bao giờ được lưu, còn nhà cung cấp hosting giữ nhật ký truy cập thông thường trong thời gian ngắn.", "privacySide1Title": "Kiểm tra mã nguồn công khai", "privacySide1Desc": "Quy tắc phân quyền dữ liệu và cách lưu bình chọn đều công khai trong repository trên GitHub.", "privacySide1Btn": "Xem tài liệu kỹ thuật và API", @@ -1634,7 +1634,7 @@ "contactSeoDesc": "Gửi link sản phẩm hoặc gian hàng Shopee, Lazada, Tiki có dấu hiệu nâng khống giá gốc hoặc đánh giá ảo để Rate.vn kiểm tra.", "contactHeroBadge": "Liên hệ & phản hồi", "contactHeroTitle": "Kiểm tra nhanh và báo cáo gian hàng bất thường", - "contactHeroDesc": "Dán link sản phẩm hoặc gian hàng từ Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, FPT Shop, Hoàng Hà, Di Động Việt hoặc Phong Vũ vào ô bên dưới để xem lịch sử giá, hoặc gửi link để Rate.vn kiểm tra.", + "contactHeroDesc": "Dán link sản phẩm hoặc gian hàng từ 22 sàn và chuỗi bán lẻ (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, TGDĐ, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ, GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, MemoryZone, An Phát) vào ô bên dưới để xem lịch sử giá tức thì, hoặc gửi link từ 10 sàn đã mở hàng đợi kiểm duyệt để Rate.vn kiểm tra.", "contactCard1Title": "1. Báo cáo giảm giá ảo và đánh giá ảo", "contactCard1Desc": "Khi thấy giá gốc bị nâng trước ngày sale, hãy dán link sản phẩm vào ô kiểm tra ở trang này. Khi thấy tài khoản ảo lặp lại bình luận mẫu để đẩy sao, hãy đăng nhập rồi bấm \"Báo cáo\" ngay tại đánh giá đó trên trang sản phẩm.", "contactCard1Btn": "Tới danh mục sản phẩm →", @@ -1673,7 +1673,7 @@ "quarantineOutcome": { "accepted": "Link đã vào hàng chờ kiểm tra. Giá bạn nhập không được đưa thẳng lên trang.", "noConsent": "Hãy đánh dấu ô đồng ý chia sẻ trước khi gửi.", - "invalidUrl": "Link này không phải trang chi tiết sản phẩm của một trong 10 sàn được hỗ trợ. Hãy mở trang sản phẩm và sao chép lại link.", + "invalidUrl": "Link này không phải trang chi tiết sản phẩm của một trong 22 sàn được hỗ trợ. Hãy mở trang sản phẩm và sao chép lại link.", "platformPending": "Rate.vn tạm thời chưa nhận link từ sàn này. Vui lòng thử lại sau.", "invalidPrice": "Giá đang bán không hợp lệ. Hãy nhập số tiền bằng đồng.", "accessory": "Có vẻ đây là phụ kiện hoặc linh kiện. Rate.vn chỉ theo dõi giá của thiết bị.", @@ -1865,10 +1865,10 @@ "sortByPrefix": "Sắp xếp: {label}", "radarBannerBadge": "Deal dưới giá trung vị và cảnh báo giảm giá ảo ({title})", "radarAnalyzedSub": "Đã kiểm tra {count} tin bán", - "viewAllRadarBtn": "Xem tất cả deal trên 10 sàn", + "viewAllRadarBtn": "Xem tất cả deal trên 22 sàn", "vsMedianBadge": "-{pct}% so trung vị", "fakeMarkupBadge": "Kê khống +{pct}%", - "spreadHeader": "Chênh lệch giá lớn nhất giữa 10 sàn ({title}):", + "spreadHeader": "Chênh lệch giá lớn nhất giữa 22 sàn ({title}):", "spreadSub": "Mua đúng sàn tiết kiệm hàng triệu đồng", "spreadDiffBadge": "Lệch +{pct}% ({amount} ₫)", "emptySyncingTitle": "Danh mục \"{title}\" đang chờ đồng bộ dữ liệu sản phẩm mới", diff --git a/apps/web/src/app/api/v1/rate/deals/route.ts b/apps/web/src/app/api/v1/rate/deals/route.ts index 8046d21e..9cb7284e 100644 --- a/apps/web/src/app/api/v1/rate/deals/route.ts +++ b/apps/web/src/app/api/v1/rate/deals/route.ts @@ -3,6 +3,7 @@ import { getCrossPlatformDealRadar } from '../../../../../server/rate/deals'; import type { CanonicalCategorySlug } from '../../../../../lib/rate-api'; import { PUBLIC_API_CORS_HEADERS, + SUPPORTED_PLATFORM_SLUGS, jsonApiError, parseBoundedIntParam, parseBoundedStringParam, @@ -16,18 +17,7 @@ const VALID_CATEGORIES = new Set([ 'earbuds', ]); -const VALID_PLATFORMS = new Set([ - 'shopee', - 'lazada', - 'tiki', - 'tiktok', - 'cellphones', - 'tgdd', - 'fptshop', - 'hoangha', - 'didongviet', - 'phongvu', -]); +const VALID_PLATFORMS = SUPPORTED_PLATFORM_SLUGS; export async function OPTIONS() { return new NextResponse(null, { diff --git a/apps/web/src/app/api/v1/rate/extension/ingest/route.ts b/apps/web/src/app/api/v1/rate/extension/ingest/route.ts index 4e1419dc..e89a9bef 100644 --- a/apps/web/src/app/api/v1/rate/extension/ingest/route.ts +++ b/apps/web/src/app/api/v1/rate/extension/ingest/route.ts @@ -37,9 +37,21 @@ const CrowdIngestSchema = z.object({ 'hoangha', 'didongviet', 'phongvu', + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]) .optional(), - externalItemId: z.string().trim().min(1).max(120).optional(), + externalItemId: z.string().trim().min(1).max(128).optional(), externalShopId: z.string().trim().max(120).nullish(), url: z .string() diff --git a/apps/web/src/app/api/v1/rate/extension/lookup/route.ts b/apps/web/src/app/api/v1/rate/extension/lookup/route.ts index e6cd4394..1946182d 100644 --- a/apps/web/src/app/api/v1/rate/extension/lookup/route.ts +++ b/apps/web/src/app/api/v1/rate/extension/lookup/route.ts @@ -41,7 +41,7 @@ export async function OPTIONS() { * GET /api/v1/rate/extension/lookup * Fast-Path Read-Only Lookup for Rate Browser Extension MV3 (Two-Speed Hybrid Architecture v2). * Query parameters: - * - platform: shopee | lazada | tiki | tiktok | cellphones | tgdd | fptshop | hoangha | didongviet | phongvu + * - platform: shopee | lazada | tiki | tiktok | cellphones | tgdd | fptshop | hoangha | didongviet | phongvu | dienmayxanh | topzone | gearvn | nguyenkim | shopdunk | hacom | clickbuy | viettelstore | pico | mediamart | memoryzone | anphatpc * - externalId: platform item ID or shopId_itemId * - shopId: platform shop ID * - url: product URL (automatically canonicalized, stripping tracking params) @@ -64,7 +64,7 @@ export async function GET(request: NextRequest) { const sp = request.nextUrl.searchParams; const platform = parseBoundedStringParam(sp.get('platform'), 32); - const externalId = parseBoundedStringParam(sp.get('externalId'), 120); + const externalId = parseBoundedStringParam(sp.get('externalId'), 128); const shopId = parseBoundedStringParam(sp.get('shopId'), 120); const url = parseBoundedStringParam(sp.get('url'), 1024); const title = parseBoundedStringParam(sp.get('title'), 320); diff --git a/apps/web/src/components/deals/DealFinderWorkspace.tsx b/apps/web/src/components/deals/DealFinderWorkspace.tsx index a528e098..1f94c4fe 100644 --- a/apps/web/src/components/deals/DealFinderWorkspace.tsx +++ b/apps/web/src/components/deals/DealFinderWorkspace.tsx @@ -719,7 +719,7 @@ export default function DealFinderWorkspace({ if (typeof window === 'undefined' || !dealRadar) return; const payload = { source: - 'Rate.vn cross-store price lows and fake-sale warnings (10 stores)', + 'Rate.vn cross-store price lows and fake-sale warnings (22 stores)', categoryFilter, exportedAt: new Date().toISOString(), totalClustersAnalyzed: dealRadar.totalClustersAnalyzed, diff --git a/apps/web/src/components/home/HeroSearchInspector.tsx b/apps/web/src/components/home/HeroSearchInspector.tsx index 69ff73e6..3a8166d7 100644 --- a/apps/web/src/components/home/HeroSearchInspector.tsx +++ b/apps/web/src/components/home/HeroSearchInspector.tsx @@ -104,7 +104,9 @@ export function isLikelyEcommerceUrl(input: unknown): boolean { const s = input.replace(HERO_INSPECTOR_CONTROL_CHARS_RE, '').trim(); return ( /^https?:\/\//i.test(s) || - /shopee\.vn|lazada\.vn|tiki\.vn|tiktok\.com|i\.\d+\.\d+/i.test(s) + /(?:^|\/\/|\.)(?:shopee\.vn|lazada\.vn|tiki\.vn|tiktok\.com|cellphones\.com\.vn|thegioididong\.com|dienmayxanh\.com|topzone\.vn|fptshop\.com\.vn|hoanghamobile\.com|didongviet\.vn|phongvu\.vn|gearvn\.com|nguyenkim\.com|shopdunk\.com|hacom\.vn|clickbuy\.com\.vn|viettelstore\.vn|pico\.vn|mediamart\.vn|memoryzone\.com\.vn|anphatpc\.com\.vn)\/|i\.\d+\.\d+/i.test( + s + ) ); } diff --git a/apps/web/src/components/merchants/MerchantDirectoryExplorer.tsx b/apps/web/src/components/merchants/MerchantDirectoryExplorer.tsx index 2768a21f..8b48c5d4 100644 --- a/apps/web/src/components/merchants/MerchantDirectoryExplorer.tsx +++ b/apps/web/src/components/merchants/MerchantDirectoryExplorer.tsx @@ -619,6 +619,18 @@ export default function MerchantDirectoryExplorer({ 'hoangha', 'didongviet', 'phongvu', + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]; for (const p of platformCounts.keys()) { if (!base.includes(p)) base.push(p); diff --git a/apps/web/src/components/watchlist/WatchlistWorkspace.tsx b/apps/web/src/components/watchlist/WatchlistWorkspace.tsx index 294d861d..e9af1dd9 100644 --- a/apps/web/src/components/watchlist/WatchlistWorkspace.tsx +++ b/apps/web/src/components/watchlist/WatchlistWorkspace.tsx @@ -107,8 +107,30 @@ const PLATFORM_DISPLAY_LABELS: Record = { hoangha: 'Hoàng Hà Mobile', didongviet: 'Di Động Việt', phongvu: 'Phong Vũ', + dienmayxanh: 'Điện Máy Xanh', + topzone: 'TopZone', + gearvn: 'GearVN', + nguyenkim: 'Nguyễn Kim', + shopdunk: 'ShopDunk', + hacom: 'HACOM', + clickbuy: 'Clickbuy', + viettelstore: 'Viettel Store', + pico: 'Pico', + mediamart: 'MediaMart', + memoryzone: 'MemoryZone', + anphatpc: 'An Phát Computer', }; +const VIETNAMESE_NAMED_PLATFORMS = new Set([ + 'tgdd', + 'hoangha', + 'didongviet', + 'phongvu', + 'dienmayxanh', + 'nguyenkim', + 'anphatpc', +]); + export function sanitizeWatchlistBestOfferUrl(rawUrl: unknown): string | null { if (typeof rawUrl !== 'string') return null; const cleaned = rawUrl.replace(/\p{Cc}+/gu, '').trim(); @@ -1487,8 +1509,23 @@ export default function WatchlistWorkspace({ {t('bestOfferPrefix', { count: platformCount })} {' '} - {PLATFORM_DISPLAY_LABELS[bestOffer.platform] || - bestOffer.platform.toUpperCase()} + +>([ + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', +]); + function lookupOfferDiscountAnalysis( byOffer: Record | null | undefined, rawId: unknown @@ -4560,7 +4587,7 @@ export function selectOfferForUrlInspection( } /** - * Inspect an e-commerce product/shop URL (all 10 platforms) or keyword: + * Inspect an e-commerce product/shop URL (all 22 platforms) or keyword: * - Resolves exact `platform_item_id` or `url` against `rate.products` * - Or resolves `platform_shop_id` / merchant name against `rate.merchants` * - Or resolves product slug / keyword against `rate.master_products` @@ -4602,36 +4629,124 @@ export async function inspectProductOrShopUrl( // 1. Direct lookup by platform_item_id if parsed from URL if (parsedUrl.platformItemId) { - const candidateIds = new Set([parsedUrl.platformItemId]); - if (parsedUrl.platformShopId) { - candidateIds.add( - `${parsedUrl.platformShopId}_${parsedUrl.platformItemId}` - ); - } + const rawItemId = parsedUrl.platformItemId; + const lowerItemId = rawItemId.toLowerCase(); + const candidateIds = new Set([rawItemId, lowerItemId]); const prefix = parsedUrl.platform ? PLATFORM_ITEM_ID_PREFIX[parsedUrl.platform] : undefined; - if (prefix && !parsedUrl.platformItemId.startsWith(prefix)) { - candidateIds.add(`${prefix}${parsedUrl.platformItemId}`); + const isOverlongRetailSlug = (slug: string): boolean => + Boolean(prefix && parsedUrl.platform !== 'anphatpc' && slug.length > 120); + const barePrefixedInput = + prefix && + lowerItemId.startsWith(prefix) && + rawItemId.length > prefix.length + ? rawItemId.slice(prefix.length) + : rawItemId; + if (!isOverlongRetailSlug(barePrefixedInput)) { + candidateIds.add(rawItemId); + candidateIds.add(lowerItemId); + } else { + candidateIds.clear(); } - - const { data: prodRow, error: prodErr } = await supabase - .from('products') - .select('id, cluster_id, merchant_id, platform_item_id') - .in('platform_item_id', Array.from(candidateIds)) - .limit(1) - .maybeSingle(); - - if (prodErr) { - throw new RateDataUnavailableError('URL product listing lookup', prodErr); + if (!prefix && parsedUrl.platformShopId && !rawItemId.includes('_')) { + candidateIds.add(`${parsedUrl.platformShopId}_${rawItemId}`); + } + if (prefix) { + const rawSlugs = [rawItemId]; + if (lowerItemId.startsWith(prefix) && rawItemId.length > prefix.length) { + rawSlugs.push(rawItemId.slice(prefix.length)); + } + for (const slugCandidate of rawSlugs) { + if (isOverlongRetailSlug(slugCandidate)) continue; + const lowerSlug = slugCandidate.toLowerCase(); + if (`${prefix}${slugCandidate}`.length <= 128) { + candidateIds.add(`${prefix}${slugCandidate}`); + } + if (`${prefix}${lowerSlug}`.length <= 128) { + candidateIds.add(`${prefix}${lowerSlug}`); + } + if ( + parsedUrl.platform && + WAVE_UNDERSCORE_ENCODED_PLATFORMS.has(parsedUrl.platform) && + lowerSlug.includes('_') + ) { + const waveEncoded = `${prefix}${lowerSlug.replace(/_/g, '_5f')}`; + if (waveEncoded.length <= 128) candidateIds.add(waveEncoded); + } + if (parsedUrl.platform === 'anphatpc') { + const apEncoded = sanitizeAnPhatItemId(slugCandidate); + if (apEncoded && apEncoded.length <= 128) { + candidateIds.add(apEncoded); + } + } + } + } + if ( + parsedUrl.platform === 'topzone' || + parsedUrl.platform === 'dienmayxanh' + ) { + const bareMwg = rawItemId.replace(/^(?:tz|dmx|tgdd)-/i, ''); + if (bareMwg && bareMwg.length <= 120) { + if (prefix && /^tgdd-/i.test(rawItemId)) { + candidateIds.add(`${prefix}${bareMwg}`); + candidateIds.add(`${prefix}${bareMwg.toLowerCase()}`); + } + candidateIds.add(`tgdd-${bareMwg}`); + candidateIds.add(`tgdd-${bareMwg.toLowerCase()}`); + } } - const matchedProd = prodRow as { + type ListingLookupRow = { id: string; cluster_id: string | null; merchant_id: string; + platform?: string | null; platform_item_id: string; - } | null; + }; + const orderedCandidates = Array.from(candidateIds); + let matchedProd: ListingLookupRow | null = null; + + if (orderedCandidates.length > 0) { + let prodQuery = supabase + .from('products') + .select('id, cluster_id, merchant_id, platform, platform_item_id') + .in('platform_item_id', orderedCandidates); + if (parsedUrl.platform && parsedUrl.platform !== 'rate') { + prodQuery = prodQuery.eq('platform', parsedUrl.platform); + } + const { data: prodData, error: prodErr } = await prodQuery.limit(10); + + if (prodErr) { + throw new RateDataUnavailableError( + 'URL product listing lookup', + prodErr + ); + } + + const rawProdRows: ListingLookupRow[] = Array.isArray(prodData) + ? (prodData as ListingLookupRow[]) + : prodData + ? [prodData as ListingLookupRow] + : []; + const scopedProdRows = rawProdRows + .filter( + (r) => + !parsedUrl.platform || + parsedUrl.platform === 'rate' || + !r.platform || + r.platform === parsedUrl.platform + ) + .sort((a, b) => { + const ai = orderedCandidates.indexOf(a.platform_item_id); + const bi = orderedCandidates.indexOf(b.platform_item_id); + return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi); + }); + matchedProd = + scopedProdRows.find((r) => Boolean(r.cluster_id)) ?? + scopedProdRows[0] ?? + null; + } if (matchedProd?.cluster_id) { // A draft master has no product page (DOS/Rate#769). The listing is diff --git a/apps/web/src/lib/rate-domain-core.ts b/apps/web/src/lib/rate-domain-core.ts index 03d8160b..4437560c 100644 --- a/apps/web/src/lib/rate-domain-core.ts +++ b/apps/web/src/lib/rate-domain-core.ts @@ -1595,6 +1595,18 @@ export interface ParsedEcommerceUrl { | 'hoangha' | 'didongviet' | 'phongvu' + | 'dienmayxanh' + | 'topzone' + | 'gearvn' + | 'nguyenkim' + | 'shopdunk' + | 'hacom' + | 'clickbuy' + | 'viettelstore' + | 'pico' + | 'mediamart' + | 'memoryzone' + | 'anphatpc' | 'rate' | null; platformShopId: string | null; @@ -1606,31 +1618,110 @@ function isDomainOrSubdomain(host: string, domain: string): boolean { return host === domain || host.endsWith(`.${domain}`); } +const KNOWN_ECOMMERCE_DOMAIN_TOKEN_REGEX = + /(?:^|\/\/|\.)(?:shopee\.vn|lazada\.vn|tiki\.vn|tiktok\.com|cellphones\.com\.vn|thegioididong\.com|dienmayxanh\.com|topzone\.vn|fptshop\.com\.vn|hoanghamobile\.com|didongviet\.vn|phongvu\.vn|gearvn\.com|nguyenkim\.com|shopdunk\.com|hacom\.vn|clickbuy\.com\.vn|viettelstore\.vn|pico\.vn|mediamart\.vn|memoryzone\.com\.vn|anphatpc\.com\.vn|rate\.vn)(?:\/|$)/i; + const RETAIL_NON_PRODUCT_FIRST_SEGMENTS = new Set([ 'tin-tuc', + 'tin-khuyen-mai', + 'cong-nghe', 'sforum', 'dchannel', 'hoi-dap', + 'huong-dan', 'khuyen-mai', + 'hot-deal', 'tra-gop', + 'thu-cu-doi-moi', 'bao-hanh', + 'tra-bao-hanh', + 'tra-cuu-bao-hanh', + 'chinh-sach', + 'lien-he', + 'gioi-thieu', + 've-chung-toi', + 'tuyen-dung', + 'so-sanh', + 'so-sanh-san-pham', + 'compare', + 'cua-hang', + 'showroom', + 'sieu-thi', 'he-thong-cua-hang', 'he-thong-sieu-thi', + 'he-thong-showroom', + 'he-thong-trung-tam', + 'trung-tam-bao-hanh', 'catalogsearch', 'tim-kiem', + 'ket-qua-tim-kiem', + 'tim', 'search', + 'filter', 'cart', 'gio-hang', + 'checkout', + 'thanh-toan', 'account', + 'tai-khoan', + 'taikhoan', 'login', + 'dang-nhap', + 'register', + 'dang-ky', + 'logout', + 'dang-xuat', + 'auth', + 'captcha', + 'challenge', 'blog', + 'blogs', 'news', 'event', + 'su-kien', 'landing', 'collection', + 'collections', + 'pages', + 'page', + 'policies', + 'tag', + 'tags', + 'brand', + 'thuong-hieu', + 'buildpc', + 'xay-dung-cau-hinh', + 'sua-chua', + 'dich-vu', + 'may-cu', + 'hang-cu', + 'may-cu-gia-re', + 'likenew', + 'like-new', + 'outlet', + 'xa-kho', + 'ajax', + 'api', + 'media', + 'static', + 'assets', + 'cdn-cgi', 'c', + 'danh-muc', ]); +const RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX = + /^(?:chinh-sach-|quy-che-|huong-dan-|dieu-khoan-|gioi-thieu(?:-|$)|ve-chung-toi(?:-|$)|tin-khuyen-mai(?:-|$)|tin-tuc-|khuyen-mai-|sua-chua(?:-|$)|dich-vu(?:-|$)|tra-bao-hanh(?:-|$)|tra-cuu-bao-hanh(?:-|$)|he-thong-(?:cua-hang|sieu-thi|showroom|trung-tam)(?:-|$)|ket-qua-tim-kiem$|so-sanh(?:-san-pham)?$|buildpc$|xay-dung-cau-hinh$)/i; + +const RETAIL_AUTH_SEGMENT_REGEX = + /^(?:login|register|account|tai-khoan|taikhoan|dang-nhap|dang-ky|logout|dang-xuat|auth|captcha|challenge)$/i; + +const RETAIL_STATIC_ASSET_EXT_REGEX = + /\.(?:js|mjs|cjs|json|css|xml|txt|pdf|zip|rar|7z|png|jpe?g|webp|avif|svg|gif|ico|woff2?|ttf|eot|map|mp[34]|webm|aspx|ashx|axd|php)$/i; + +const ANPHAT_DESK_PHONE_SLUG_REGEX = + /^(?:dien-thoai-(?:huu-tuyen|ip|ban|de-ban|khong-day|keo-dai|hoi-nghi)|tong-dai-ip)(?:-|$)/i; + // A path ending in a bare brand lists that brand's products, as in // cellphones.com.vn/mobile/apple.html or fptshop.com.vn/dien-thoai/samsung; // no product slug is a brand alone (DOS/Rate#1246). Keep these rules in @@ -1672,6 +1763,15 @@ const RETAIL_BRAND_LISTING_SLUGS = new Set([ 'anker', 'baseus', 'ugreen', + 'logitech', + 'razer', + 'corsair', + 'hyperx', + 'steelseries', + 'bose', + 'sennheiser', + 'gigabyte', + 'tcl', 'mac', ]); @@ -1684,23 +1784,63 @@ const isSeriesListingSlug = (slug: string) => const RETAIL_CATEGORY_ROOT_SLUGS = new Set([ 'dtdd', + 'mtb', 'dien-thoai', 'dien-thoai-di-dong', + 'dien-thoai-thong-minh', 'mobile', 'smartphones', 'laptop', 'laptops', + 'laptop-gaming', + 'laptop-gaming-do-hoa', + 'laptop-van-phong', + 'laptop-tablet-mobile', 'may-tinh-xach-tay', + 'may-tinh-xach-tay-laptop', 'may-tinh-bang', + 'may-tinh-bang-tablet', 'tablet', 'tablets', + 'dong-ho', 'dong-ho-thong-minh', 'smartwatch', 'smartwatches', 'tai-nghe', + 'tai-nghe-bluetooth', + 'tai-nghe-nhet-tai', + 'tai-nghe-chup-tai', + 'tai-nghe-gaming', + 'am-thanh', + 'thiet-bi-am-thanh', + 'loa', 'earbuds', 'phu-kien', + 'phu-kien-di-dong', + 'linh-kien', + 'linh-kien-may-tinh', + 'man-hinh', + 'man-hinh-may-tinh', + 'pc', + 'pc-gaming', + 'pc-van-phong-do-hoa', + 'may-tinh-de-ban', + 'gaming-gear', + 'tivi', + 'tu-lanh', + 'may-giat', + 'may-lanh', + 'gia-dung', + 'dien-gia-dung', + 'dien-may', + 'sim-so', + 'san-pham', + 'products', + 'product', 'apple', + 'apple-iphone', + 'apple-ipad', + 'apple-watch', 'iphone', 'ipad', 'macbook', @@ -1708,6 +1848,388 @@ const RETAIL_CATEGORY_ROOT_SLUGS = new Set([ 'airpods', ]); +const MEDIAMART_ALLOWED_CATEGORY_PREFIXES = new Set([ + 'smartphones', + 'dien-thoai', + 'dien-thoai-di-dong', + 'laptop', + 'may-tinh-xach-tay', + 'macbook', + 'may-tinh-bang', + 'tablet', + 'ipad', + 'smartwatch', + 'dong-ho-thong-minh', + 'tai-nghe', + 'san-pham', + 'products', +]); + +const HACOM_CATEGORY_BRAND_SLUG_REGEX = + /^(?:laptop-(?:asus(?:-(?:vivobook|zenbook|tuf|rog|expertbook|proart))?|dell(?:-(?:inspiron|vostro|xps|latitude|alienware|precision))?|acer(?:-(?:aspire|nitro|swift|predator|travelmate))?|lenovo(?:-(?:thinkpad|thinkbook|ideapad|legion|loq|yoga))?|hp(?:-(?:pavilion|victus|omen|envy|probook|elitebook|omnibook))?|msi(?:-(?:modern|katana|cyborg|prestige|stealth|raider|thin|sword))?|apple(?:-(?:macbook|macbook-air|macbook-pro))?|lg(?:-gram)?|gigabyte(?:-(?:aorus|aero|gaming))?)|may-tinh-nguyen-bo-theo-hang|may-tinh-mini-da-dung)$/i; + +const CLICKBUY_NON_PRODUCT_SLUG_REGEX = + /^(?:dien-thoai-(?:iphone|samsung|xiaomi|oppo|vivo|realme|nokia|honor|asus|tcl|google|sony|tecno|infinix|masstel|itel)|(?:iphone|samsung|dien-thoai|ipad|macbook|apple-watch)-cu|thay-pin|ep-kinh|google-pixel|trang)$/i; + +const VIETTELSTORE_PRODUCT_CATEGORY_SEGMENTS = new Set([ + 'dien-thoai', + 'may-tinh-bang', + 'tablet', + 'laptop', + 'may-tinh-xach-tay', + 'dong-ho-thong-minh', + 'dong-ho', + 'apple-watch', + 'smartwatch', + 'tai-nghe', + 'am-thanh', + 'loa', + 'phu-kien', + 'man-hinh', + 'pc', + 'tivi', + 'san-pham', + 'products', +]); + +const VIETTELSTORE_NON_PRODUCT_PREFIXES = new Set([ + 'tra-gop', + 'so-sanh', + 'so-sanh-san-pham', + 'tin-tuc', + 'chuyen-muc-tin', + 'landing', + 'khuyen-mai', + 'site', + 'he-thong-sieu-thi', + 'sieu-thi', + 'ho-tro', + 'tuyen-dung', + 'account', + 'login', + 'dang-nhap', + 'register', + 'dang-ky', + 'auth', + 'captcha', + 'challenge', + 'cart', + 'gio-hang', + 'dtdd', + 'mtb', + 'tim-kiem', + 'ket-qua-tim-kiem', +]); + +const VIETTELSTORE_CATEGORY_SLUG_REGEX = + /^(?:dtdd(?:-|$)|mtb(?:-|$)|laptop-(?:apple|asus|acer|dell|hp|lenovo|msi|lg)$|phu-kien-o-to$|bao-da-op-lung$|tam-dan$)/i; + +const ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS = new Set([ + 'template', + 'templates', + 'includes', + 'user', + 'order', + 'don-hang', + 'rss', + 'sitemap', + 'robots.txt', +]); + +const ANPHAT_INFO_SUFFIX_REGEX = + /(?:^|-)(?:he-thong-showroom|tin-khuyen-mai|tin-tuc|khuyen-mai|bao-hanh|chinh-sach|huong-dan|lien-he|tuyen-dung|gioi-thieu|pc-an-phat)$/i; + +const ANPHAT_ACTIVE_DEVICE_SLUG_CUE_REGEX = + /(?:^|[-/_])(?:laptop|may-tinh-xach-tay|macbook|ipad|may-tinh-bang|tablet|galaxy-tab|redmi-pad|xiaomi-pad|matepad|lenovo-tab|apple-watch|galaxy-watch|dong-ho|smartwatch|garmin|amazfit|tai-nghe|airpods|earbuds|galaxy-buds|redmi-buds|headphone|headset)(?:[-/_]|$)/i; + +const ANPHAT_SMARTPHONE_SLUG_REGEX = + /(?:^(?:dien-thoai|iphone|smartphone)(?:-|_|$)|(?:^|[-/_])(?:iphone-\d+|galaxy-(?:s\d+|z-(?:fold|flip)|a\d+|m\d+)|redmi-(?:note|\d+)|poco-[xfmc]\d+|oppo-(?:reno|find)|vivo-[vxyt]\d+|realme-(?:c\d+|gt|\d+)|xiaomi-\d+|google-pixel-\d+)(?:[-/_]|$))/i; + +function isExcludedAnPhatPhoneSlug(slugLower: string): boolean { + if (ANPHAT_DESK_PHONE_SLUG_REGEX.test(slugLower)) return true; + if (/^(?:dien-thoai|iphone|smartphone)(?:-|_|$)/i.test(slugLower)) { + return true; + } + return ( + ANPHAT_SMARTPHONE_SLUG_REGEX.test(slugLower) && + !ANPHAT_ACTIVE_DEVICE_SLUG_CUE_REGEX.test(slugLower) + ); +} + +function sha1Hex10(input: string): string { + const bytes = new TextEncoder().encode(input); + const bitLen = bytes.length * 8; + const paddedLen = (((bytes.length + 8) >>> 6) + 1) << 6; + const buf = new Uint8Array(paddedLen); + buf.set(bytes); + buf[bytes.length] = 0x80; + const view = new DataView(buf.buffer); + view.setUint32(paddedLen - 8, Math.floor(bitLen / 0x100000000), false); + view.setUint32(paddedLen - 4, bitLen >>> 0, false); + + let h0 = 0x67452301; + let h1 = 0xefcdab89; + let h2 = 0x98badcfe; + let h3 = 0x10325476; + let h4 = 0xc3d2e1f0; + const w = new Uint32Array(80); + + for (let offset = 0; offset < paddedLen; offset += 64) { + for (let i = 0; i < 16; i++) { + w[i] = view.getUint32(offset + i * 4, false); + } + for (let i = 16; i < 80; i++) { + const n = w[i - 3]! ^ w[i - 8]! ^ w[i - 14]! ^ w[i - 16]!; + w[i] = ((n << 1) | (n >>> 31)) >>> 0; + } + + let a = h0; + let b = h1; + let c = h2; + let d = h3; + let e = h4; + + for (let i = 0; i < 80; i++) { + let f: number; + let k: number; + if (i < 20) { + f = (b & c) | (~b & d); + k = 0x5a827999; + } else if (i < 40) { + f = b ^ c ^ d; + k = 0x6ed9eba1; + } else if (i < 60) { + f = (b & c) | (b & d) | (c & d); + k = 0x8f1bbcdc; + } else { + f = b ^ c ^ d; + k = 0xca62c1d6; + } + const temp = + ((((a << 5) | (a >>> 27)) >>> 0) + (f >>> 0) + e + k + w[i]!) >>> 0; + e = d; + d = c; + c = ((b << 30) | (b >>> 2)) >>> 0; + b = a; + a = temp; + } + + h0 = (h0 + a) >>> 0; + h1 = (h1 + b) >>> 0; + h2 = (h2 + c) >>> 0; + h3 = (h3 + d) >>> 0; + h4 = (h4 + e) >>> 0; + } + + return ( + h0.toString(16).padStart(8, '0') + h1.toString(16).padStart(8, '0') + ).slice(0, 10); +} + +/** + * Encodes an An Phat Computer URL slug/path into canonical `ap-` format + * (`<= 128` chars, matching `AnPhatScraper.sanitizeAnPhatItemId` in `DOS/Rate-Services`). + */ +export function sanitizeAnPhatItemId(rawKey: string): string { + const cleaned = rawKey.trim().replace(/^\/+|\/+$/g, ''); + if (!cleaned) return ''; + const normalized = cleaned.toLowerCase().replace(/[^a-z0-9-]/g, (ch) => { + const hex = ch.codePointAt(0)?.toString(16).padStart(2, '0') ?? '00'; + return `_${hex}`; + }); + if (!normalized) return ''; + const maxSlugLen = 125; + if (normalized.length <= maxSlugLen) { + return `ap-${normalized}`; + } + const digest = sha1Hex10(normalized); + const keepLen = Math.max(1, maxSlugLen - digest.length - 1); + let trimmed = normalized.slice(0, keepLen).replace(/[-_]+$/g, ''); + if (!trimmed) trimmed = normalized.slice(0, keepLen); + return `ap-${trimmed}-${digest}`; +} + +function extractValidRetailItemSlug( + retailPlatform: NonNullable, + segments: readonly string[] +): string | null { + if (segments.length === 0) return null; + + for (const seg of segments) { + const strippedSeg = seg + .toLowerCase() + .replace(/\.(?:html|htm|aspx|ashx|axd|php)$/i, ''); + if ( + RETAIL_AUTH_SEGMENT_REGEX.test(strippedSeg) || + RETAIL_AUTH_SEGMENT_REGEX.test(seg) + ) { + return null; + } + } + + const firstRawLower = segments[0]!.toLowerCase(); + const firstSegLower = firstRawLower.replace(/\.html?$/i, ''); + const lastRaw = segments[segments.length - 1]!; + if (RETAIL_STATIC_ASSET_EXT_REGEX.test(lastRaw)) { + return null; + } + if ( + (retailPlatform === 'nguyenkim' || retailPlatform === 'pico') && + /\.(?:c|b)$/i.test(lastRaw) + ) { + return null; + } + + const isCollectionProductPath = + segments.length === 4 && + firstSegLower === 'collections' && + segments[2]!.toLowerCase() === 'products'; + + if (retailPlatform === 'gearvn') { + if ( + !(segments.length === 2 && firstSegLower === 'products') && + !isCollectionProductPath + ) { + return null; + } + } else if (retailPlatform === 'memoryzone') { + if ( + segments.length !== 1 && + !(segments.length === 2 && firstSegLower === 'products') && + !isCollectionProductPath + ) { + return null; + } + } else if (retailPlatform === 'mediamart') { + if ( + segments.length !== 2 || + !MEDIAMART_ALLOWED_CATEGORY_PREFIXES.has(firstSegLower) + ) { + return null; + } + } else if ( + retailPlatform === 'tgdd' || + retailPlatform === 'dienmayxanh' || + retailPlatform === 'topzone' + ) { + if (segments.length < 2) return null; + } else if (retailPlatform === 'cellphones') { + // CellphoneS product pages sit at the root (DOS/Rate#1246). + if (segments.length > 1) return null; + } else if ( + retailPlatform === 'nguyenkim' || + retailPlatform === 'shopdunk' || + retailPlatform === 'hacom' || + retailPlatform === 'clickbuy' || + retailPlatform === 'pico' + ) { + if ( + segments.length !== 1 && + !( + segments.length === 2 && + (firstSegLower === 'products' || firstSegLower === 'san-pham') + ) + ) { + return null; + } + } else if (retailPlatform === 'viettelstore') { + if (segments.length > 2) return null; + if (segments.length === 2) { + if (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(firstSegLower)) return null; + const leafLower = lastRaw.toLowerCase().replace(/\.html?$/i, ''); + const hasPid = /(?:^|-)pid[1-9]\d{1,14}$/i.test(leafLower); + if ( + !VIETTELSTORE_PRODUCT_CATEGORY_SEGMENTS.has(firstSegLower) && + !hasPid + ) { + return null; + } + } + } else if (retailPlatform === 'anphatpc') { + const hasHtmlExt = /\.html?$/i.test(lastRaw); + const isDirectRoutePrefix = + segments.length === 2 && + (firstSegLower === 'products' || firstSegLower === 'san-pham'); + if (!hasHtmlExt && !isDirectRoutePrefix) return null; + if ( + firstRawLower.startsWith('ajax') || + firstRawLower.endsWith('.php') || + ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS.has(firstRawLower) || + ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) || + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) + ) { + return null; + } + if (segments.some((s) => /_dm\d+$/i.test(s.replace(/\.html?$/i, '')))) { + return null; + } + if (segments.length > 1 && !isDirectRoutePrefix) { + const lastClean = lastRaw.replace(/\.html?$/i, ''); + if (!lastClean) return null; + const rawKey = [...segments.slice(0, -1), lastClean].join('/'); + const rawKeyLower = rawKey.toLowerCase(); + if ( + rawKey.length < 3 || + rawKey.length > 512 || + rawKeyLower.includes('..') || + isExcludedAnPhatPhoneSlug(rawKeyLower) || + RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX.test(rawKeyLower) || + ANPHAT_INFO_SUFFIX_REGEX.test(lastClean.toLowerCase()) + ) { + return null; + } + return sanitizeAnPhatItemId(rawKey) || null; + } + } + + if ( + !isCollectionProductPath && + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) + ) { + return null; + } + + const lastSeg = lastRaw.replace(/\.html?$/i, '') || null; + const lastSegLower = (lastSeg || '').toLowerCase(); + const vtsHasPid = + retailPlatform === 'viettelstore' && + /(?:^|-)pid[1-9]\d{1,14}$/i.test(lastSegLower); + if ( + !lastSeg || + lastSeg.length < 2 || + lastSeg.length > 256 || + !/^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(lastSegLower) || + lastSegLower.includes('..') || + /^(?:0+|null|undefined|nan|infinity|-infinity|true|false|default|index|home|trang-chu|404|page-not-found|error)$/i.test( + lastSegLower + ) || + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(lastSegLower) || + RETAIL_CATEGORY_ROOT_SLUGS.has(lastSegLower) || + RETAIL_BRAND_LISTING_SLUGS.has(lastSegLower) || + RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX.test(lastSegLower) || + isSeriesListingSlug(lastSegLower) || + (retailPlatform === 'hacom' && + HACOM_CATEGORY_BRAND_SLUG_REGEX.test(lastSegLower)) || + (retailPlatform === 'clickbuy' && + CLICKBUY_NON_PRODUCT_SLUG_REGEX.test(lastSegLower)) || + (retailPlatform === 'viettelstore' && + !vtsHasPid && + (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(lastSegLower) || + VIETTELSTORE_CATEGORY_SLUG_REGEX.test(lastSegLower))) || + (retailPlatform === 'anphatpc' && + (isExcludedAnPhatPhoneSlug(lastSegLower) || + ANPHAT_INFO_SUFFIX_REGEX.test(lastSegLower))) + ) { + return null; + } + + if (retailPlatform === 'anphatpc' && lastSeg.length > 120) { + return sanitizeAnPhatItemId(lastSeg) || null; + } + + return lastSeg.length <= 120 ? lastSeg : null; +} + export function parseEcommerceUrlOrQuery(raw: string): ParsedEcommerceUrl { const trimmed = typeof raw === 'string' @@ -1717,10 +2239,7 @@ export function parseEcommerceUrlOrQuery(raw: string): ParsedEcommerceUrl { .slice(0, 2048) : ''; const hasHttpProtocol = /^https?:\/\//i.test(trimmed); - const hasKnownDomainToken = - /(?:^|\/\/|\.)(?:shopee\.vn|lazada\.vn|tiki\.vn|tiktok\.com|cellphones\.com\.vn|thegioididong\.com|topzone\.vn|dienmayxanh\.com|fptshop\.com\.vn|hoanghamobile\.com|didongviet\.vn|phongvu\.vn|rate\.vn)(?:\/|$)/i.test( - trimmed - ); + const hasKnownDomainToken = KNOWN_ECOMMERCE_DOMAIN_TOKEN_REGEX.test(trimmed); const isUrl = hasHttpProtocol || hasKnownDomainToken; const toPositiveNumericId = ( @@ -1868,55 +2387,68 @@ export function parseEcommerceUrlOrQuery(raw: string): ParsedEcommerceUrl { 'cellphones.com.vn' ) ? 'cellphones' - : isDomainOrSubdomain(parsedHost, 'thegioididong.com') || - isDomainOrSubdomain(parsedHost, 'topzone.vn') || - isDomainOrSubdomain(parsedHost, 'dienmayxanh.com') + : isDomainOrSubdomain(parsedHost, 'thegioididong.com') ? 'tgdd' - : isDomainOrSubdomain(parsedHost, 'fptshop.com.vn') - ? 'fptshop' - : isDomainOrSubdomain(parsedHost, 'hoanghamobile.com') - ? 'hoangha' - : isDomainOrSubdomain(parsedHost, 'didongviet.vn') - ? 'didongviet' - : isDomainOrSubdomain(parsedHost, 'phongvu.vn') - ? 'phongvu' - : null; + : isDomainOrSubdomain(parsedHost, 'dienmayxanh.com') + ? 'dienmayxanh' + : isDomainOrSubdomain(parsedHost, 'topzone.vn') + ? 'topzone' + : isDomainOrSubdomain(parsedHost, 'fptshop.com.vn') + ? 'fptshop' + : isDomainOrSubdomain(parsedHost, 'hoanghamobile.com') + ? 'hoangha' + : isDomainOrSubdomain(parsedHost, 'didongviet.vn') + ? 'didongviet' + : isDomainOrSubdomain(parsedHost, 'phongvu.vn') + ? 'phongvu' + : isDomainOrSubdomain(parsedHost, 'gearvn.com') + ? 'gearvn' + : isDomainOrSubdomain(parsedHost, 'nguyenkim.com') + ? 'nguyenkim' + : isDomainOrSubdomain(parsedHost, 'shopdunk.com') + ? 'shopdunk' + : isDomainOrSubdomain(parsedHost, 'hacom.vn') + ? 'hacom' + : isDomainOrSubdomain(parsedHost, 'clickbuy.com.vn') + ? 'clickbuy' + : isDomainOrSubdomain( + parsedHost, + 'viettelstore.vn' + ) + ? 'viettelstore' + : isDomainOrSubdomain(parsedHost, 'pico.vn') + ? 'pico' + : isDomainOrSubdomain( + parsedHost, + 'mediamart.vn' + ) + ? 'mediamart' + : isDomainOrSubdomain( + parsedHost, + 'memoryzone.com.vn' + ) + ? 'memoryzone' + : isDomainOrSubdomain( + parsedHost, + 'anphatpc.com.vn' + ) + ? 'anphatpc' + : null; if (retailPlatform) { const segments = parsedPathname .split('/') .map((s) => s.trim()) .filter(Boolean); - const firstSegLower = (segments[0] || '') - .replace(/\.html?$/i, '') - .toLowerCase(); - const lastSeg = - segments[segments.length - 1]?.replace(/\.html?$/i, '') || null; - const lastSegLower = (lastSeg || '').toLowerCase(); - const isValidItemSlug = - Boolean(lastSeg) && - lastSeg!.length >= 2 && - lastSeg!.length <= 256 && - /^[a-z0-9][a-z0-9._-]*[a-z0-9]$/i.test(lastSegLower) && - !lastSegLower.includes('..') && - !/^(?:0+|null|undefined|nan|infinity|-infinity|true|false)$/i.test( - lastSegLower - ) && - !RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) && - !RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(lastSegLower) && - !( - segments.length === 1 && RETAIL_CATEGORY_ROOT_SLUGS.has(firstSegLower) - ) && - !RETAIL_BRAND_LISTING_SLUGS.has(lastSegLower) && - !isSeriesListingSlug(lastSegLower) && - !(retailPlatform === 'tgdd' && segments.length < 2) && - // CellphoneS product pages sit at the root (DOS/Rate#1246). - !(retailPlatform === 'cellphones' && segments.length > 1); + const validItemSlug = extractValidRetailItemSlug( + retailPlatform, + segments + ); return { isUrl: true, platform: retailPlatform, platformShopId: null, - platformItemId: isValidItemSlug ? lastSeg : null, + platformItemId: validItemSlug, internalSlug: null, }; } @@ -2054,18 +2586,17 @@ export function stripEcommerceNoiseTokens(rawText: string): string { /** * Extract a clean, human-readable product search keyword from an e-commerce product URL - * across all 10 supported platforms (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, - * TGDD/TopZone/DMX, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ). + * across all 22 supported platforms (Shopee, Lazada, Tiki, TikTok Shop, CellphoneS, + * TGDD, Điện Máy Xanh, TopZone, FPT Shop, Hoàng Hà, Di Động Việt, Phong Vũ, + * GearVN, Nguyễn Kim, ShopDunk, HACOM, Clickbuy, Viettel Store, Pico, MediaMart, + * MemoryZone, An Phát Computer). */ export function extractProductKeywordFromUrl(rawUrl?: string | null): string { if (!rawUrl || typeof rawUrl !== 'string') return ''; const trimmed = rawUrl.replace(/\p{Cc}+/gu, '').trim(); if (!trimmed || trimmed.length > 2048) return ''; const hasHttpProtocol = /^https?:\/\//i.test(trimmed); - const hasKnownDomainToken = - /(?:^|\/\/|\.)(?:shopee\.vn|lazada\.vn|tiki\.vn|tiktok\.com|cellphones\.com\.vn|thegioididong\.com|topzone\.vn|dienmayxanh\.com|fptshop\.com\.vn|hoanghamobile\.com|didongviet\.vn|phongvu\.vn|rate\.vn)(?:\/|$)/i.test( - trimmed - ); + const hasKnownDomainToken = KNOWN_ECOMMERCE_DOMAIN_TOKEN_REGEX.test(trimmed); if (!hasHttpProtocol && !hasKnownDomainToken) return ''; try { @@ -2082,6 +2613,7 @@ export function extractProductKeywordFromUrl(rawUrl?: string | null): string { decodedPathname = parsed.pathname; } + const parsedHostLower = parsed.hostname.toLowerCase(); const rawSegments = decodedPathname .split('/') .map((s) => s.trim()) @@ -2089,36 +2621,90 @@ export function extractProductKeywordFromUrl(rawUrl?: string | null): string { const firstSegLower = (rawSegments[0] || '') .replace(/\.html?$/i, '') .toLowerCase(); + const isCollectionProductPath = + rawSegments.length === 4 && + firstSegLower === 'collections' && + rawSegments[2]?.toLowerCase() === 'products'; + const rawLeaf = rawSegments[rawSegments.length - 1] || ''; + const vtsLeafLower = rawLeaf.toLowerCase().replace(/\.html?$/i, ''); + const vtsLeafHasPid = /(?:^|-)pid[1-9]\d{1,14}$/i.test(vtsLeafLower); if ( - RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) || + (!isCollectionProductPath && + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower)) || firstSegLower === 'shop' || firstSegLower === 'opaanlp' || - firstSegLower === 'video' + firstSegLower === 'video' || + (isDomainOrSubdomain(parsedHostLower, 'mediamart.vn') && + (rawSegments.length !== 2 || + !MEDIAMART_ALLOWED_CATEGORY_PREFIXES.has(firstSegLower))) || + (isDomainOrSubdomain(parsedHostLower, 'viettelstore.vn') && + (rawSegments.length > 2 || + (rawSegments.length === 2 && + (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(firstSegLower) || + (!VIETTELSTORE_PRODUCT_CATEGORY_SEGMENTS.has(firstSegLower) && + !vtsLeafHasPid))) || + (!vtsLeafHasPid && + (VIETTELSTORE_NON_PRODUCT_PREFIXES.has(vtsLeafLower) || + VIETTELSTORE_CATEGORY_SLUG_REGEX.test(vtsLeafLower))))) || + (isDomainOrSubdomain(parsedHostLower, 'anphatpc.com.vn') && + (ANPHAT_EXTRA_NON_PRODUCT_FIRST_SEGMENTS.has(firstSegLower) || + rawSegments.some((s) => /_dm\d+(?:\.html?)?$/i.test(s)))) + ) { + return ''; + } + if ( + RETAIL_STATIC_ASSET_EXT_REGEX.test(rawLeaf) || + /\.(?:c|b)$/i.test(rawLeaf) || + /_dm\d+(?:\.html?)?$/i.test(rawLeaf) ) { return ''; } - const cleanedPath = decodedPathname + // Multi-segment An Phat Computer URLs embed `/` inside Apple part numbers + // (e.g. `/apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za/a.html`); + // flatten the full path before extracting keywords so the trailing `/a` + // is never treated as a 1-character product slug. + const effectivePath = + isDomainOrSubdomain(parsedHostLower, 'anphatpc.com.vn') && + rawSegments.length > 1 && + firstSegLower !== 'products' && + firstSegLower !== 'san-pham' && + /\.html?$/i.test(rawLeaf) + ? `/${rawSegments.join('-').replace(/\.html?$/i, '')}` + : decodedPathname; + + const cleanedPath = effectivePath .replace(/(?:\/a-i|-i|\/i)\.\d+\.\d+\/?$/i, '') .replace(/\/(?:product|opaanlp)\/\d+\/\d+\/?$/i, '') .replace(/\/(?:view\/)?product\/\d+\/?$/i, '') .replace(/(?:\/|-)i\d+(?:-s\d+)?\.html?$/i, '') .replace(/(?:\/|-)p\d+\.html?$/i, '') .replace(/--s\d+(?:\.html?)?$/i, '') + .replace(/(?:_id|-pid)\d+(?:\.html?)?$/i, '') .replace(/\.html?$/i, '') + .replace(/^\/collections\/[^/]+\/products\//i, '/') .replace( /^\/(?:products?|san-pham|dien-thoai|dien-thoai-di-dong|dtdd|may-tinh-bang|may-tinh-xach-tay|laptop|dong-ho-thong-minh|tai-nghe|smartphones|tablets|laptops|smartwatches|earbuds|apple|iphone|ipad|macbook|watch|airpods)\//i, '/' ); const segments = cleanedPath.split('/').filter(Boolean); - const lastSeg = segments[segments.length - 1] || ''; + const rawLastSeg = segments[segments.length - 1] || ''; + const lastSeg = rawLastSeg.replace(/^\d{3,8}-(?=.*[a-z])/i, ''); const lastSegLower = lastSeg.toLowerCase(); if ( !lastSeg || + lastSeg.length < 2 || /^\d+$/.test(lastSeg) || /^(?:a-)?i\.\d+\.\d+$/i.test(lastSeg) || lastSeg.startsWith('@') || RETAIL_CATEGORY_ROOT_SLUGS.has(lastSegLower) || + RETAIL_NON_PRODUCT_FIRST_SEGMENTS.has(lastSegLower) || + RETAIL_AUTH_OR_NON_PRODUCT_SLUG_REGEX.test(lastSegLower) || + HACOM_CATEGORY_BRAND_SLUG_REGEX.test(lastSegLower) || + CLICKBUY_NON_PRODUCT_SLUG_REGEX.test(lastSegLower) || + ANPHAT_DESK_PHONE_SLUG_REGEX.test(lastSegLower) || + (isDomainOrSubdomain(parsedHostLower, 'anphatpc.com.vn') && + isExcludedAnPhatPhoneSlug(lastSegLower)) || /^(?:search|tim-kiem|result|product|products|view)$/.test(lastSegLower) ) { return ''; diff --git a/apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts b/apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts index a0665258..66e7ecbe 100644 --- a/apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts +++ b/apps/web/src/server/rate/__tests__/core-rate-architecture.test.ts @@ -350,7 +350,7 @@ async function runCoreArchitectureSuite() { enum: string[]; } ).enum.length, - 10 + 22 ); console.log( ' ✅ [7/8] OpenAPI 3.1.0 Specification (/api/v1/rate/openapi.json) passed' @@ -623,12 +623,25 @@ async function runCoreArchitectureSuite() { 'shopee', 'lazada', 'tiki', + 'tiktok', 'cellphones', 'tgdd', 'fptshop', 'hoangha', 'didongviet', 'phongvu', + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]) { assert.ok( merchantExplorerSrc.includes(`'${plat}'`), @@ -7943,7 +7956,7 @@ async function runCoreArchitectureSuite() { // keep their capitals; two or more other capitalised words in a row mean // Title Case. const names = - /Rate\.vn|Rate Lab|Rate Cloud|DOS ID|DOSafe|JReviews|Markdown|OpenAPI|Next\.js|PostgreSQL|Supabase|Authorization: Bearer|TikTok Shop|Official Mall|Apple Watch|Galaxy Watch|Galaxy Buds|Galaxy Tab|Xiaomi Watch|Xiaomi Pad|Huawei Watch|AirPods Pro|Hoang Ha Mobile|Hoang Ha|Di Dong Viet|The Gioi Di Dong|Phong Vu|Natural Titanium|Alex Nguyen|Wikimedia Commons|Vietnam|Shopee|Lazada|Tiki|Apple|iPhone|Pro|Max|Samsung|Galaxy|Xiaomi|Google|Pixel|Huawei|Garmin|Sony|Bose|Sennheiser|MacBook|iPad|Rate\b|Bayesian \w+|Helpful|Report|[A-Z]{2,}\w*|\w+-[A-Z]\w*/g; + /Rate\.vn|Rate Lab|Rate Cloud|DOS ID|DOSafe|JReviews|Markdown|OpenAPI|Next\.js|PostgreSQL|Supabase|Authorization: Bearer|TikTok Shop|Official Mall|Apple Watch|Galaxy Watch|Galaxy Buds|Galaxy Tab|Xiaomi Watch|Xiaomi Pad|Huawei Watch|AirPods Pro|Hoang Ha Mobile|Hoang Ha|Di Dong Viet|The Gioi Di Dong|Dien May Xanh|TopZone|GearVN|Nguyen Kim|ShopDunk|HACOM|Clickbuy|Viettel Store|Pico|MediaMart|MemoryZone|An Phat Computer|An Phat|Phong Vu|Natural Titanium|Alex Nguyen|Wikimedia Commons|Vietnam|Shopee|Lazada|Tiki|Apple|iPhone|Pro|Max|Samsung|Galaxy|Xiaomi|Google|Pixel|Huawei|Garmin|Sony|Bose|Sennheiser|MacBook|iPad|Rate\b|Bayesian \w+|Helpful|Report|[A-Z]{2,}\w*|\w+-[A-Z]\w*/g; const strip = (s: string) => s.replace(/\{[^}]+\}/g, '').replace(names, ''); const titleCase = /\b[A-Z][a-z]+\b(\s+(&|and|of|to|for|in|the|a|on|with|by|or|from|vs|at)?\s*\b[A-Z][a-z]+\b)+/; @@ -7981,7 +7994,7 @@ async function runCoreArchitectureSuite() { // Names keep their capitals: brands, products, retailers, programs, // places and people used in examples. const names = - /Rate\.vn|Rate Lab|Rate Cloud|DOS ID|DOSafe|JReviews|Markdown|TikTok Shop|Official Mall|Apple Watch|Galaxy Watch|Galaxy Buds|Galaxy Tab|Xiaomi Watch|Xiaomi Pad|Huawei Watch|AirPods Pro|OpenAPI|Next\.js|PostgreSQL|Supabase|Authorization: Bearer|Hoàng Hà|Di Động Việt|Thế Giới Di Động|Phong Vũ|Việt Nam|Wikimedia Commons|Bộ TT&TT|Minh Quân|Hà Nội|Nguyễn Văn A|Pro Max|Pro|Titan Tự Nhiên|AI Review Analyzer|Rate Trust Score|Bayesian|GSMArena|PhoneArena|GitHub|Wi-Fi|Bluetooth|Hi-Res|Qi|MagSafe|Hz|Bayes|Rate Lab|API Playground|Kiểm tra link|Liên hệ|Hữu ích|Báo cáo|Shopee|Lazada|Tiki|Apple|iPhone|Samsung|Galaxy|Xiaomi|Google|Pixel|Sony|Bose|Sennheiser|MacBook|iPad|Rate\b|[A-ZĐ]{2,}\w*/g; + /Rate\.vn|Rate Lab|Rate Cloud|DOS ID|DOSafe|JReviews|Markdown|TikTok Shop|Official Mall|Apple Watch|Galaxy Watch|Galaxy Buds|Galaxy Tab|Xiaomi Watch|Xiaomi Pad|Huawei Watch|AirPods Pro|OpenAPI|Next\.js|PostgreSQL|Supabase|Authorization: Bearer|Hoàng Hà|Di Động Việt|Thế Giới Di Động|Điện Máy Xanh|TopZone|GearVN|Nguyễn Kim|ShopDunk|HACOM|Clickbuy|Viettel Store|Pico|MediaMart|MemoryZone|An Phát Computer|An Phát|Phong Vũ|Việt Nam|Wikimedia Commons|Bộ TT&TT|Minh Quân|Hà Nội|Nguyễn Văn A|Pro Max|Pro|Titan Tự Nhiên|AI Review Analyzer|Rate Trust Score|Bayesian|GSMArena|PhoneArena|GitHub|Wi-Fi|Bluetooth|Hi-Res|Qi|MagSafe|Hz|Bayes|Rate Lab|API Playground|Kiểm tra link|Liên hệ|Hữu ích|Báo cáo|Shopee|Lazada|Tiki|Apple|iPhone|Samsung|Galaxy|Xiaomi|Google|Pixel|Sony|Bose|Sennheiser|MacBook|iPad|Rate\b|[A-ZĐ]{2,}\w*/g; const strip = (s: string) => s .normalize('NFC') @@ -14989,6 +15002,434 @@ async function runCoreArchitectureSuite() { await runProductPointsDisplaySuite(); } + // DOS/Rate#1850: All 12 Wave 1-3 retail platforms across web URL parser, lookup candidate IDs, OpenAPI, and SQL-safe crowd ingest boundary + { + const { + EXTENSION_CAPABILITY_MATRIX, + buildCandidateExternalItemIds, + detectPlatformFromInput, + ingestExtensionCrowdSignal, + } = await import('../extension'); + const { SUPPORTED_PLATFORM_SLUGS } = await import('../api-handler'); + const { extractProductKeywordFromUrl, parseEcommerceUrlOrQuery } = + await import('../../../lib/rate-domain-core'); + + const wave1To3Cases = [ + { + platform: 'dienmayxanh' as const, + pdpUrl: 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max-256gb', + nonPdpUrl: 'https://www.dienmayxanh.com/dtdd', + expectedSlug: 'iphone-16-pro-max-256gb', + expectedPrefixedId: 'dmx-iphone-16-pro-max-256gb', + }, + { + platform: 'topzone' as const, + pdpUrl: 'https://www.topzone.vn/iphone/iphone-16-pro-max-256gb', + nonPdpUrl: 'https://www.topzone.vn/iphone', + expectedSlug: 'iphone-16-pro-max-256gb', + expectedPrefixedId: 'tz-iphone-16-pro-max-256gb', + }, + { + platform: 'gearvn' as const, + pdpUrl: 'https://gearvn.com/products/laptop-asus-rog-strix-g16', + nonPdpUrl: 'https://gearvn.com/collections/laptop-gaming', + expectedSlug: 'laptop-asus-rog-strix-g16', + expectedPrefixedId: 'gearvn-laptop-asus-rog-strix-g16', + }, + { + platform: 'nguyenkim' as const, + pdpUrl: 'https://www.nguyenkim.com/dien-thoai-iphone-16-pro-max.html', + nonPdpUrl: 'https://www.nguyenkim.com/dien-thoai.c', + expectedSlug: 'dien-thoai-iphone-16-pro-max', + expectedPrefixedId: 'nk-dien-thoai-iphone-16-pro-max', + }, + { + platform: 'shopdunk' as const, + pdpUrl: 'https://shopdunk.com/iphone-16-pro-max-256gb', + nonPdpUrl: 'https://shopdunk.com/iphone', + expectedSlug: 'iphone-16-pro-max-256gb', + expectedPrefixedId: 'shopdunk-iphone-16-pro-max-256gb', + }, + { + platform: 'hacom' as const, + pdpUrl: 'https://hacom.vn/laptop-apple-macbook-air-m3-256gb', + nonPdpUrl: 'https://hacom.vn/laptop-gaming-do-hoa', + expectedSlug: 'laptop-apple-macbook-air-m3-256gb', + expectedPrefixedId: 'hacom-laptop-apple-macbook-air-m3-256gb', + }, + { + platform: 'clickbuy' as const, + pdpUrl: 'https://clickbuy.com.vn/iphone-16-pro-max-256gb', + nonPdpUrl: 'https://clickbuy.com.vn/sua-chua', + expectedSlug: 'iphone-16-pro-max-256gb', + expectedPrefixedId: 'cb-iphone-16-pro-max-256gb', + }, + { + platform: 'viettelstore' as const, + pdpUrl: + 'https://viettelstore.vn/dien-thoai/iphone-16-pro-max-pid341920.html', + nonPdpUrl: 'https://viettelstore.vn/ket-qua-tim-kiem.html', + expectedSlug: 'iphone-16-pro-max-pid341920', + expectedPrefixedId: 'vts-iphone-16-pro-max-pid341920', + }, + { + platform: 'pico' as const, + pdpUrl: 'https://pico.vn/45678-dien-thoai-iphone-16-pro-max.html', + nonPdpUrl: 'https://pico.vn/dien-thoai', + expectedSlug: '45678-dien-thoai-iphone-16-pro-max', + expectedPrefixedId: 'pico-45678-dien-thoai-iphone-16-pro-max', + }, + { + platform: 'mediamart' as const, + pdpUrl: 'https://mediamart.vn/smartphones/iphone-16-pro-max-256gb', + nonPdpUrl: 'https://mediamart.vn/smartphones', + expectedSlug: 'iphone-16-pro-max-256gb', + expectedPrefixedId: 'mm-iphone-16-pro-max-256gb', + }, + { + platform: 'memoryzone' as const, + pdpUrl: + 'https://memoryzone.com.vn/products/laptop-apple-macbook-air-m3', + nonPdpUrl: 'https://memoryzone.com.vn/collections/laptop', + expectedSlug: 'laptop-apple-macbook-air-m3', + expectedPrefixedId: 'mz-laptop-apple-macbook-air-m3', + }, + { + platform: 'anphatpc' as const, + pdpUrl: + 'https://www.anphatpc.com.vn/laptop-apple-macbook-air-13.6-inch-m3_id49201.html', + nonPdpUrl: + 'https://www.anphatpc.com.vn/may-tinh-xach-tay-laptop_dm1005.html', + expectedSlug: 'laptop-apple-macbook-air-13.6-inch-m3_id49201', + expectedPrefixedId: + 'ap-laptop-apple-macbook-air-13_2e6-inch-m3_5fid49201', + }, + ]; + + assert.equal(SUPPORTED_PLATFORM_SLUGS.size, 22); + + let rpcInvoked = false; + const fakeRateClient = { + rpc: async () => { + rpcInvoked = true; + return { data: null, error: null }; + }, + }; + + for (const tc of wave1To3Cases) { + assert.ok(SUPPORTED_PLATFORM_SLUGS.has(tc.platform), tc.platform); + const cap = EXTENSION_CAPABILITY_MATRIX[tc.platform]; + assert.ok(cap, tc.platform); + assert.equal(cap.lookup, true, tc.platform); + assert.equal(cap.exactItemMatch, true, tc.platform); + assert.equal(cap.crossCatalogMatch, true, tc.platform); + assert.equal(cap.crowdVerifyQueue, false, tc.platform); + + assert.equal(detectPlatformFromInput(null, tc.pdpUrl), tc.platform); + assert.equal(detectPlatformFromInput(tc.platform, null), tc.platform); + + const parsedPdp = parseEcommerceUrlOrQuery(tc.pdpUrl); + assert.equal(parsedPdp.isUrl, true, tc.pdpUrl); + assert.equal(parsedPdp.platform, tc.platform, tc.pdpUrl); + assert.equal(parsedPdp.platformItemId, tc.expectedSlug, tc.pdpUrl); + + const parsedNonPdp = parseEcommerceUrlOrQuery(tc.nonPdpUrl); + assert.equal(parsedNonPdp.isUrl, true, tc.nonPdpUrl); + assert.equal(parsedNonPdp.platform, tc.platform, tc.nonPdpUrl); + assert.equal(parsedNonPdp.platformItemId, null, tc.nonPdpUrl); + + const kw = extractProductKeywordFromUrl(tc.pdpUrl); + assert.ok(kw.length >= 4, `${tc.platform} keyword: "${kw}"`); + + const candidateIds = buildCandidateExternalItemIds({ + externalId: tc.expectedSlug, + platform: tc.platform, + }); + assert.ok( + candidateIds.includes(tc.expectedPrefixedId), + `${tc.platform} candidates ${JSON.stringify(candidateIds)} missing ${tc.expectedPrefixedId}` + ); + + // Crowd ingest must stop cleanly at capability gate without calling PostgreSQL RPC + const ingestRes = await ingestExtensionCrowdSignal({ + platform: tc.platform, + externalItemId: tc.expectedSlug, + url: tc.pdpUrl, + title: 'Apple iPhone 16 Pro Max 256GB', + price: 29_990_000, + userConsentOptIn: true, + rateClient: fakeRateClient, + }); + assert.equal(ingestRes.accepted, false, tc.platform); + assert.equal( + ingestRes.jobState, + 'platform_worker_pending_phase_5_1', + tc.platform + ); + } + assert.equal( + rpcInvoked, + false, + 'Wave 1-3 crowd ingest must never call enqueue_crowd_verify_signal before DOS-Me migration' + ); + + // Legacy compatibility: older extension clients sending platform=tgdd on topzone.vn / dienmayxanh.com upgrade cleanly + assert.equal( + detectPlatformFromInput( + 'tgdd', + 'https://www.topzone.vn/iphone/iphone-16-pro-max' + ), + 'topzone' + ); + assert.equal( + detectPlatformFromInput( + 'tgdd', + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max' + ), + 'dienmayxanh' + ); + assert.ok( + buildCandidateExternalItemIds({ + externalId: 'iphone-16-pro-max', + platform: 'topzone', + }).includes('tgdd-iphone-16-pro-max') + ); + assert.ok( + buildCandidateExternalItemIds({ + externalId: 'iphone-16-pro-max', + platform: 'dienmayxanh', + }).includes('tgdd-iphone-16-pro-max') + ); + assert.equal( + parseEcommerceUrlOrQuery( + 'https://www.anphatpc.com.vn/apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za/a.html' + ).platformItemId, + 'ap-apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za_2fa' + ); + assert.ok( + extractProductKeywordFromUrl( + 'https://www.anphatpc.com.vn/apple-ipad-11-inch-ipad-wi-fi-128gb-blue-md4a4za/a.html' + ).includes('ipad') + ); + assert.equal( + parseEcommerceUrlOrQuery( + 'https://mediamart.vn/tu-van-tieu-dung/top-5-iphone-16' + ).platformItemId, + null + ); + assert.equal( + parseEcommerceUrlOrQuery('https://hacom.vn/laptop-asus').platformItemId, + null + ); + assert.equal( + parseEcommerceUrlOrQuery('https://clickbuy.com.vn/dien-thoai-iphone') + .platformItemId, + null + ); + assert.equal( + parseEcommerceUrlOrQuery( + 'https://viettelstore.vn/chuyen-muc-tin/iphone-16' + ).platformItemId, + null + ); + assert.equal( + extractProductKeywordFromUrl( + 'https://viettelstore.vn/dtdd/apple/iphone-16' + ), + '' + ); + assert.ok( + extractProductKeywordFromUrl( + 'https://viettelstore.vn/dien-thoai/iphone-16-256gb-pid339615.html' + ).includes('iphone 16') + ); + assert.equal( + parseEcommerceUrlOrQuery('https://hacom.vn/laptop-asus-vivobook') + .platformItemId, + null + ); + assert.equal( + parseEcommerceUrlOrQuery( + 'https://hacom.vn/laptop-asus-vivobook-x1407ca-ly008w-ltau1066' + ).platformItemId, + 'laptop-asus-vivobook-x1407ca-ly008w-ltau1066' + ); + assert.equal( + parseEcommerceUrlOrQuery( + 'https://www.anphatpc.com.vn/iphone-16-pro-max_id49201.html' + ).platformItemId, + null + ); + assert.equal( + parseEcommerceUrlOrQuery(`https://hacom.vn/${'a'.repeat(121)}`) + .platformItemId, + null, + 'web HACOM slug bound must match extension 120-char bound' + ); + + // Legacy tgdd- input on topzone/dienmayxanh generates canonical tz-/dmx- first + const tzFromLegacy = buildCandidateExternalItemIds({ + externalId: 'tgdd-iphone-16-pro-max', + platform: 'topzone', + }); + assert.ok( + tzFromLegacy.includes('tz-iphone-16-pro-max') && + tzFromLegacy.indexOf('tz-iphone-16-pro-max') < + tzFromLegacy.indexOf('tgdd-iphone-16-pro-max'), + 'canonical tz- candidate must precede legacy tgdd- fallback' + ); + + // Cross-platform guard: a TGDD row (`platform = tgdd`, `tgdd-iphone-16-pro-max`) + // must NEVER match a TopZone URL, and canonical `tz-` beats same-platform `tgdd-` + const { inspectProductOrShopUrl, lookupExtensionProduct: lookupExt1850 } = + await import('../index'); + const origFetch1850 = globalThis.fetch; + try { + const tzMaster = { + id: 'master-tz-1850', + slug: 'apple-iphone-16-pro-max-256gb-tz', + brand: 'Apple', + name: 'Apple iPhone 16 Pro Max 256GB', + model: 'iPhone 16 Pro Max', + status: 'published', + min_price: 29_990_000, + max_price: 30_990_000, + merchant_count: 1, + criteria_scores: {}, + key_specs: {}, + specifications: {}, + spec_provenance: {}, + }; + const tgddWrongMaster = { + ...tzMaster, + id: 'master-tgdd-wrong-1850', + slug: 'wrong-tgdd-cluster-1850', + name: 'Wrong TGDD Cluster', + }; + let scenario: 'cross_platform_only' | 'both_same_platform' = + 'cross_platform_only'; + globalThis.fetch = (async (input: RequestInfo | URL) => { + const reqUrl = decodeURIComponent( + typeof input === 'string' + ? input + : input instanceof URL + ? input.toString() + : input.url + ); + const json1850 = (body: unknown) => + new Response(JSON.stringify(body), { + status: 200, + headers: { 'content-type': 'application/json' }, + }); + if ( + reqUrl.includes('/rest/v1/products') && + reqUrl.includes('platform_item_id=in.') + ) { + const allRows = + scenario === 'cross_platform_only' + ? [ + { + id: 'prod-tgdd-only', + cluster_id: tgddWrongMaster.id, + merchant_id: 'merch-tgdd', + platform: 'tgdd', + platform_item_id: 'tgdd-iphone-16-pro-max', + }, + ] + : [ + { + id: 'prod-tz-legacy', + cluster_id: tgddWrongMaster.id, + merchant_id: 'merch-tz', + platform: 'topzone', + platform_item_id: 'tgdd-iphone-16-pro-max', + }, + { + id: 'prod-tz-canonical', + cluster_id: tzMaster.id, + merchant_id: 'merch-tz', + platform: 'topzone', + platform_item_id: 'tz-iphone-16-pro-max', + }, + ]; + const filtered = reqUrl.includes('platform=eq.topzone') + ? allRows.filter((r) => r.platform === 'topzone') + : allRows; + return json1850(filtered); + } + if (reqUrl.includes(`/rest/v1/master_products`)) { + if (reqUrl.includes(`id=eq.${tzMaster.id}`)) + return json1850(tzMaster); + if (reqUrl.includes(`id=eq.${tgddWrongMaster.id}`)) { + return json1850(tgddWrongMaster); + } + return json1850([]); + } + if (reqUrl.includes('/rest/v1/merchants')) { + return json1850([ + { + id: 'merch-tz', + platform: 'topzone', + platform_shop_id: 'tz-mwg-vn', + name: 'TopZone', + slug: 'topzone', + is_official: true, + metadata: {}, + }, + ]); + } + return json1850([]); + }) as typeof fetch; + + const crossInspected = await inspectProductOrShopUrl( + 'https://www.topzone.vn/iphone/iphone-16-pro-max' + ); + assert.notEqual( + crossInspected.masterProduct?.id, + tgddWrongMaster.id, + 'TopZone URL inspection must never match a TGDD listing row' + ); + const crossExt = await lookupExt1850({ + platform: 'topzone', + url: 'https://www.topzone.vn/iphone/iphone-16-pro-max', + title: 'Unknown Nonmatching Title', + mode: 'pill', + }); + assert.notEqual( + crossExt.masterProduct?.id, + tgddWrongMaster.id, + 'TopZone extension lookup must never match a TGDD listing row' + ); + + scenario = 'both_same_platform'; + const sameInspected = await inspectProductOrShopUrl( + 'https://www.topzone.vn/iphone/iphone-16-pro-max' + ); + assert.equal( + sameInspected.masterProduct?.id, + tzMaster.id, + 'Canonical tz- listing must take precedence over legacy tgdd- fallback on TopZone' + ); + const sameExt = await lookupExt1850({ + platform: 'topzone', + url: 'https://www.topzone.vn/iphone/iphone-16-pro-max', + title: 'Unknown Nonmatching Title', + mode: 'pill', + }); + assert.equal( + sameExt.masterProduct?.id, + tzMaster.id, + 'Extension lookup must prefer canonical tz- listing over legacy tgdd- fallback' + ); + } finally { + globalThis.fetch = origFetch1850; + } + + console.log( + ' ✅ DOS/Rate#1850 Wave 1-3 12 retail platforms web & API parity passed' + ); + } + console.log('🎉 All Rate.vn Core Architecture tests passed!'); } diff --git a/apps/web/src/server/rate/api-handler.ts b/apps/web/src/server/rate/api-handler.ts index be12ef50..e13d49c4 100644 --- a/apps/web/src/server/rate/api-handler.ts +++ b/apps/web/src/server/rate/api-handler.ts @@ -870,7 +870,7 @@ export function extractClientRateLimitKey( return 'anon'; } -/** The 10 marketplaces and retailers Rate tracks (DOS/Rate#1308). */ +/** The 22 marketplaces and retailers Rate tracks (DOS/Rate#1308, #1850). */ export const SUPPORTED_PLATFORM_SLUGS: ReadonlySet = new Set([ 'shopee', 'lazada', @@ -882,6 +882,18 @@ export const SUPPORTED_PLATFORM_SLUGS: ReadonlySet = new Set([ 'hoangha', 'didongviet', 'phongvu', + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]); /** diff --git a/apps/web/src/server/rate/extension.ts b/apps/web/src/server/rate/extension.ts index 7d450faf..3b677ea3 100644 --- a/apps/web/src/server/rate/extension.ts +++ b/apps/web/src/server/rate/extension.ts @@ -26,6 +26,7 @@ import { normalizeMasterProductRow, parseEcommerceUrlOrQuery, RateDataUnavailableError, + sanitizeAnPhatItemId, stripEcommerceNoiseTokens, type CanonicalCategorySlug, type MasterProduct, @@ -68,7 +69,19 @@ export type SupportedEcommercePlatform = | 'fptshop' | 'hoangha' | 'didongviet' - | 'phongvu'; + | 'phongvu' + | 'dienmayxanh' + | 'topzone' + | 'gearvn' + | 'nguyenkim' + | 'shopdunk' + | 'hacom' + | 'clickbuy' + | 'viettelstore' + | 'pico' + | 'mediamart' + | 'memoryzone' + | 'anphatpc'; export interface PlatformCapability { platform: SupportedEcommercePlatform; @@ -163,6 +176,106 @@ export const EXTENSION_CAPABILITY_MATRIX: Record< crossCatalogMatch: true, crowdVerifyQueue: true, }, + // Wave 1-3 retail chains (DOS/Rate#1850): full lookup, exact item match, and + // cross-catalog comparison are enabled; `crowdVerifyQueue` stays false until + // a DOS-Me migration widens `rate.enqueue_crowd_verify_signal` and M2 SQL + // CHECK constraints (`DOS/Rate#1762`). + dienmayxanh: { + platform: 'dienmayxanh', + displayName: 'Điện Máy Xanh', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + topzone: { + platform: 'topzone', + displayName: 'TopZone', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + gearvn: { + platform: 'gearvn', + displayName: 'GearVN', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + nguyenkim: { + platform: 'nguyenkim', + displayName: 'Nguyễn Kim', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + shopdunk: { + platform: 'shopdunk', + displayName: 'ShopDunk', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + hacom: { + platform: 'hacom', + displayName: 'HACOM', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + clickbuy: { + platform: 'clickbuy', + displayName: 'Clickbuy', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + viettelstore: { + platform: 'viettelstore', + displayName: 'Viettel Store', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + pico: { + platform: 'pico', + displayName: 'Pico', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + mediamart: { + platform: 'mediamart', + displayName: 'MediaMart', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + memoryzone: { + platform: 'memoryzone', + displayName: 'MemoryZone', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, + anphatpc: { + platform: 'anphatpc', + displayName: 'An Phát Computer', + lookup: true, + exactItemMatch: true, + crossCatalogMatch: true, + crowdVerifyQueue: false, + }, }; /** @@ -412,31 +525,9 @@ export function extractKeywordFromProductUrl(rawUrl?: string | null): string { return extractProductKeywordFromUrl(rawUrl); } -export function detectPlatformFromInput( - rawPlatform?: string | null, +function detectPlatformFromUrlHost( rawUrl?: string | null ): SupportedEcommercePlatform | null { - const norm = - typeof rawPlatform === 'string' - ? rawPlatform - .replace(/\p{Cc}+/gu, '') - .trim() - .toLowerCase() - : ''; - if ( - norm === 'shopee' || - norm === 'lazada' || - norm === 'tiki' || - norm === 'tiktok' || - norm === 'cellphones' || - norm === 'tgdd' || - norm === 'fptshop' || - norm === 'hoangha' || - norm === 'didongviet' || - norm === 'phongvu' - ) { - return norm; - } if (!rawUrl || typeof rawUrl !== 'string') return null; if (/\p{Cc}/u.test(rawUrl)) return null; const trimmedUrl = rawUrl.trim(); @@ -477,20 +568,53 @@ export function detectPlatformFromInput( if (isDomainOrSubdomain(host, 'tiki.vn')) return 'tiki'; if (isDomainOrSubdomain(host, 'tiktok.com')) return 'tiktok'; if (isDomainOrSubdomain(host, 'cellphones.com.vn')) return 'cellphones'; - if ( - isDomainOrSubdomain(host, 'thegioididong.com') || - isDomainOrSubdomain(host, 'topzone.vn') || - isDomainOrSubdomain(host, 'dienmayxanh.com') - ) { - return 'tgdd'; - } + if (isDomainOrSubdomain(host, 'thegioididong.com')) return 'tgdd'; + if (isDomainOrSubdomain(host, 'dienmayxanh.com')) return 'dienmayxanh'; + if (isDomainOrSubdomain(host, 'topzone.vn')) return 'topzone'; if (isDomainOrSubdomain(host, 'fptshop.com.vn')) return 'fptshop'; if (isDomainOrSubdomain(host, 'hoanghamobile.com')) return 'hoangha'; if (isDomainOrSubdomain(host, 'didongviet.vn')) return 'didongviet'; if (isDomainOrSubdomain(host, 'phongvu.vn')) return 'phongvu'; + if (isDomainOrSubdomain(host, 'gearvn.com')) return 'gearvn'; + if (isDomainOrSubdomain(host, 'nguyenkim.com')) return 'nguyenkim'; + if (isDomainOrSubdomain(host, 'shopdunk.com')) return 'shopdunk'; + if (isDomainOrSubdomain(host, 'hacom.vn')) return 'hacom'; + if (isDomainOrSubdomain(host, 'clickbuy.com.vn')) return 'clickbuy'; + if (isDomainOrSubdomain(host, 'viettelstore.vn')) return 'viettelstore'; + if (isDomainOrSubdomain(host, 'pico.vn')) return 'pico'; + if (isDomainOrSubdomain(host, 'mediamart.vn')) return 'mediamart'; + if (isDomainOrSubdomain(host, 'memoryzone.com.vn')) return 'memoryzone'; + if (isDomainOrSubdomain(host, 'anphatpc.com.vn')) return 'anphatpc'; return null; } +export function detectPlatformFromInput( + rawPlatform?: string | null, + rawUrl?: string | null +): SupportedEcommercePlatform | null { + const norm = + typeof rawPlatform === 'string' + ? rawPlatform + .replace(/\p{Cc}+/gu, '') + .trim() + .toLowerCase() + : ''; + const urlPlatform = detectPlatformFromUrlHost(rawUrl); + if (Object.hasOwn(EXTENSION_CAPABILITY_MATRIX, norm)) { + // Older extension builds sent `platform=tgdd` for MWG sister domains + // `topzone.vn` and `dienmayxanh.com` before DOS/Rate#1850 promoted them to + // first-class platforms; upgrade seamlessly when `rawUrl` names one. + if ( + norm === 'tgdd' && + (urlPlatform === 'topzone' || urlPlatform === 'dienmayxanh') + ) { + return urlPlatform; + } + return norm as SupportedEcommercePlatform; + } + return urlPlatform; +} + /** * Gatekeeper Layer 0: Distinguish accessories/spare parts from actual phones/tablets/laptops/earbuds. */ @@ -1129,30 +1253,134 @@ export function buildCandidateExternalItemIds(params: { return []; } - candidateItemIds.add(cleanExternalId); - if (cleanExternalId.includes('_')) { - const parts = cleanExternalId.split('_'); - if (parts[1] && isValidExternalEntityId(parts[1])) { - candidateItemIds.add(parts[1]); - } - } - if (cleanShopId && !cleanExternalId.includes('_')) { - candidateItemIds.add(`${cleanShopId}_${cleanExternalId}`); - } const prefixMap: Partial> = { tiktok: 'tts-', cellphones: 'cps-', tgdd: 'tgdd-', + dienmayxanh: 'dmx-', + topzone: 'tz-', fptshop: 'fpt-', hoangha: 'hhm-', didongviet: 'ddv-', phongvu: 'pv-', + gearvn: 'gearvn-', + nguyenkim: 'nk-', + shopdunk: 'shopdunk-', + hacom: 'hacom-', + clickbuy: 'cb-', + viettelstore: 'vts-', + pico: 'pico-', + mediamart: 'mm-', + memoryzone: 'mz-', + anphatpc: 'ap-', }; + const waveUnderscorePlatforms = new Set([ + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + ]); const prefix = params.platform ? prefixMap[params.platform] : undefined; - if (prefix && !cleanExternalId.startsWith(prefix)) { - const prefixed = `${prefix}${cleanExternalId}`; - if (isValidExternalEntityId(prefixed)) { - candidateItemIds.add(prefixed); + const lowerCleanExternalId = cleanExternalId.toLowerCase(); + const isOverlongRetailSlug = (slug: string): boolean => + Boolean(prefix && params.platform !== 'anphatpc' && slug.length > 120); + const barePrefixedExternal = + prefix && + lowerCleanExternalId.startsWith(prefix) && + cleanExternalId.length > prefix.length + ? cleanExternalId.slice(prefix.length) + : cleanExternalId; + if (isOverlongRetailSlug(barePrefixedExternal)) { + return []; + } + + // When a legacy `tgdd-` externalId is queried on `topzone` or `dienmayxanh`, + // enqueue the canonical `tz-` / `dmx-` IDs first so canonical listings win. + if ( + prefix && + (params.platform === 'topzone' || params.platform === 'dienmayxanh') && + /^tgdd-/i.test(cleanExternalId) + ) { + const bareMwg = cleanExternalId.replace(/^tgdd-/i, ''); + if (bareMwg && bareMwg.length <= 120) { + for (const canonicalCandidate of [ + `${prefix}${bareMwg}`, + `${prefix}${bareMwg.toLowerCase()}`, + ]) { + if (isValidExternalEntityId(canonicalCandidate)) { + candidateItemIds.add(canonicalCandidate); + } + } + } + } + + candidateItemIds.add(cleanExternalId); + if (isValidExternalEntityId(lowerCleanExternalId)) { + candidateItemIds.add(lowerCleanExternalId); + } + // `shopId_itemId` underscore splitting applies only to non-prefixed marketplaces + // (`shopee`, `lazada`, `tiki`); retail slugs with `_` must not split into numeric suffixes. + if (!prefix && cleanExternalId.includes('_')) { + const parts = cleanExternalId.split('_'); + if (parts[1] && isValidExternalEntityId(parts[1])) { + candidateItemIds.add(parts[1]); + } + } + if (!prefix && cleanShopId && !cleanExternalId.includes('_')) { + candidateItemIds.add(`${cleanShopId}_${cleanExternalId}`); + } + if (prefix) { + const rawSlugs = [cleanExternalId]; + if ( + lowerCleanExternalId.startsWith(prefix) && + cleanExternalId.length > prefix.length + ) { + rawSlugs.push(cleanExternalId.slice(prefix.length)); + } + for (const slugCandidate of rawSlugs) { + if (isOverlongRetailSlug(slugCandidate)) continue; + const lowerSlug = slugCandidate.toLowerCase(); + const prefixed = `${prefix}${slugCandidate}`; + if (isValidExternalEntityId(prefixed)) { + candidateItemIds.add(prefixed); + } + const lowerPrefixed = `${prefix}${lowerSlug}`; + if (isValidExternalEntityId(lowerPrefixed)) { + candidateItemIds.add(lowerPrefixed); + } + if ( + params.platform && + waveUnderscorePlatforms.has(params.platform) && + lowerSlug.includes('_') + ) { + const waveEncoded = `${prefix}${lowerSlug.replace(/_/g, '_5f')}`; + if (isValidExternalEntityId(waveEncoded)) { + candidateItemIds.add(waveEncoded); + } + } + if (params.platform === 'anphatpc') { + const apCandidate = sanitizeAnPhatItemId(slugCandidate); + if (apCandidate && isValidExternalEntityId(apCandidate)) { + candidateItemIds.add(apCandidate); + } + } + } + } + if (params.platform === 'topzone' || params.platform === 'dienmayxanh') { + const bareMwg = cleanExternalId.replace(/^(?:tz|dmx|tgdd)-/i, ''); + if (bareMwg && bareMwg.length <= 120) { + for (const mwgCandidate of [ + `tgdd-${bareMwg}`, + `tgdd-${bareMwg.toLowerCase()}`, + ]) { + if (isValidExternalEntityId(mwgCandidate)) { + candidateItemIds.add(mwgCandidate); + } + } } } return Array.from(candidateItemIds); @@ -1337,15 +1565,19 @@ export async function lookupExtensionProduct( if (!matchedMaster && candidateItemIds.size > 0) { const client = getRateClient(); if (client) { - const { data: prodRows, error: prodErr } = await client + const orderedCandidates = Array.from(candidateItemIds); + let prodQuery = client .from('products') - .select('cluster_id, platform_item_id') - .in('platform_item_id', Array.from(candidateItemIds)) - .not('cluster_id', 'is', null) - .limit(5); + .select('cluster_id, platform, platform_item_id') + .in('platform_item_id', orderedCandidates) + .not('cluster_id', 'is', null); + if (platform) { + prodQuery = prodQuery.eq('platform', platform); + } + const { data: prodRows, error: prodErr } = await prodQuery.limit(10); if (prodErr) { log.error('extension_lookup_products_failed', { - candidateItemIds: Array.from(candidateItemIds), + candidateItemIds: orderedCandidates, message: prodErr.message, code: prodErr.code, }); @@ -1354,9 +1586,20 @@ export async function lookupExtensionProduct( const matchedProd = ( (prodRows || []) as Array<{ cluster_id: string | null; + platform?: string | null; platform_item_id: string; }> - ).find((r) => Boolean(r.cluster_id)); + ) + .filter( + (r) => + Boolean(r.cluster_id) && + (!platform || !r.platform || r.platform === platform) + ) + .sort((a, b) => { + const ai = orderedCandidates.indexOf(a.platform_item_id); + const bi = orderedCandidates.indexOf(b.platform_item_id); + return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi); + })[0]; if (matchedProd?.cluster_id) { // A draft master has no product page (DOS/Rate#769). The listing is // then known to be that model, so no catalogue guess either. @@ -1397,7 +1640,8 @@ export async function lookupExtensionProduct( candidateItemIds.size > 0 ) { const listingItem = await resolveListingItemContext( - Array.from(candidateItemIds) + Array.from(candidateItemIds), + platform ); if (listingItem === 'no_variant') { // The listing's Item is known but has no page yet: no catalogue guess. diff --git a/apps/web/src/server/rate/item-api.ts b/apps/web/src/server/rate/item-api.ts index 1427d156..de1db894 100644 --- a/apps/web/src/server/rate/item-api.ts +++ b/apps/web/src/server/rate/item-api.ts @@ -248,13 +248,25 @@ export function chooseItemVariant( * such listing exists. */ export async function resolveListingItemContext( - platformItemIds: readonly string[] + platformItemIds: readonly string[], + platform?: string | null ): Promise { if (!isItemModelOn() || platformItemIds.length === 0) return null; const client = getRateClient(); if (!client) return null; // `item_id` is not in the generated types until #1150 lands. - const { data, error } = await ( + type ListingItemQuery = { + eq: (col: string, val: string) => ListingItemQuery; + limit: (n: number) => PromiseLike<{ + data: Array<{ + item_id: string | null; + platform?: string | null; + platform_item_id?: string; + }> | null; + error: { message: string; code?: string } | null; + }>; + }; + let query = ( client.from('products') as unknown as { select: (cols: string) => { in: ( @@ -265,26 +277,20 @@ export async function resolveListingItemContext( col: string, value: null ) => { - not: ( - col: string, - op: string, - value: null - ) => { - limit: (n: number) => PromiseLike<{ - data: Array<{ item_id: string | null }> | null; - error: { message: string; code?: string } | null; - }>; - }; + not: (col: string, op: string, value: null) => ListingItemQuery; }; }; }; } ) - .select('item_id, platform_item_id') + .select('item_id, platform, platform_item_id') .in('platform_item_id', platformItemIds) .is('cluster_id', null) - .not('item_id', 'is', null) - .limit(5); + .not('item_id', 'is', null); + if (platform) { + query = query.eq('platform', platform); + } + const { data, error } = await query.limit(10); if (error) { if (error.code && MISSING_SCHEMA_CODES.has(error.code)) { log.warn('item model on but products.item_id is missing', { @@ -295,9 +301,21 @@ export async function resolveListingItemContext( log.error('listing item lookup failed', { message: error.message }); throw new RateDataUnavailableError('products', error); } - const itemId = (data ?? []).find( - (r) => typeof r.item_id === 'string' - )?.item_id; + const itemId = (data ?? []) + .filter( + (r) => + typeof r.item_id === 'string' && + (!platform || !r.platform || r.platform === platform) + ) + .sort((a, b) => { + const ai = a.platform_item_id + ? platformItemIds.indexOf(a.platform_item_id) + : -1; + const bi = b.platform_item_id + ? platformItemIds.indexOf(b.platform_item_id) + : -1; + return (ai === -1 ? 999 : ai) - (bi === -1 ? 999 : bi); + })[0]?.item_id; if (!itemId) return null; return orUnavailable('listing item', async () => { const item = await getItemById(itemId); diff --git a/apps/web/src/server/rate/openapi.ts b/apps/web/src/server/rate/openapi.ts index b06001f1..033975f4 100644 --- a/apps/web/src/server/rate/openapi.ts +++ b/apps/web/src/server/rate/openapi.ts @@ -15,6 +15,7 @@ export interface OpenApiParameter { format?: string; enum?: string[]; default?: string | number | boolean; + maxLength?: number; }; } @@ -303,7 +304,7 @@ function buildBaseRateOpenApiSpec( summary: 'Standardized 10-Group Tech Specs, Price History, Product Deal Radar & AI Review Auditing API', description: - 'OpenAPI 3.1 specification for the Rate.vn REST API v1. The website, the Rate browser extension (10 Vietnamese marketplaces and retailers) and open e-commerce research all use these endpoints.', + 'OpenAPI 3.1 specification for the Rate.vn REST API v1. The website, the Rate browser extension (22 Vietnamese marketplaces and retailers) and open e-commerce research all use these endpoints.', license: { name: 'MIT Open-Core License', url: 'https://github.com/DOS/Rate', @@ -333,7 +334,7 @@ function buildBaseRateOpenApiSpec( { name: 'URL Inspector & Extension MV3', description: - 'Real-time URL/SKU canonicalization, 10-platform hybrid lookup, evidence-based price verdict, and zero-trust quarantine ingestion.', + 'Real-time URL/SKU canonicalization, 22-platform hybrid lookup, evidence-based price verdict, and zero-trust quarantine ingestion.', }, { name: 'Merchants & Dual Risk Score', @@ -1070,7 +1071,7 @@ function buildBaseRateOpenApiSpec( summary: 'Full Web Product & URL Inspector with price verdict and price history chart', description: - 'Runs the complete hybrid lookup pipeline for the `/inspect` web portal: canonicalizes 10 supported e-commerce/retailer platforms, blocks non-hardware accessories, resolves SKU variant capacity, computes the price verdict (`PriceVerdictLevel`), and returns full product detail with the Deal Radar signal (`data.radarSignal`, null when no product matched). One of `q` or `url` is required. Limited to 30 requests per minute per client IP (shared with `/lookup`, counted on each server instance); past it the answer is 429 with `Retry-After`.', + 'Runs the complete hybrid lookup pipeline for the `/inspect` web portal: canonicalizes 22 supported e-commerce/retailer platforms, blocks non-hardware accessories, resolves SKU variant capacity, computes the price verdict (`PriceVerdictLevel`), and returns full product detail with the Deal Radar signal (`data.radarSignal`, null when no product matched). One of `q` or `url` is required. Limited to 30 requests per minute per client IP (shared with `/lookup`, counted on each server instance); past it the answer is 429 with `Retry-After`.', tags: ['URL Inspector & Extension MV3'], parameters: [ { @@ -1156,7 +1157,7 @@ function buildBaseRateOpenApiSpec( summary: 'Low-latency Hybrid Lookup for Rate Browser Extension Manifest V3', description: - 'Dedicated read-only lookup endpoint for the Rate Browser Extension MV3 across 10 platforms (`shopee`, `lazada`, `tiki`, `tiktok`, `cellphones`, `tgdd`, `fptshop`, `hoangha`, `didongviet`, `phongvu`). Performs deterministic `platform_item_id` lookup, canonical model fallback, accessory gatekeeping, price verdict calculation (`PriceVerdictLevel`), and returns the Deal Radar signal as `data.radarSignal`.', + 'Dedicated read-only lookup endpoint for the Rate Browser Extension MV3 across 22 platforms (`shopee`, `lazada`, `tiki`, `tiktok`, `cellphones`, `tgdd`, `fptshop`, `hoangha`, `didongviet`, `phongvu`, `dienmayxanh`, `topzone`, `gearvn`, `nguyenkim`, `shopdunk`, `hacom`, `clickbuy`, `viettelstore`, `pico`, `mediamart`, `memoryzone`, `anphatpc`). Performs deterministic `platform_item_id` lookup, canonical model fallback, accessory gatekeeping, price verdict calculation (`PriceVerdictLevel`), and returns the Deal Radar signal as `data.radarSignal`.', tags: ['URL Inspector & Extension MV3'], parameters: [ { @@ -1172,7 +1173,7 @@ function buildBaseRateOpenApiSpec( name: 'externalId', in: 'query', description: 'Platform item ID or shopId_itemId', - schema: { type: 'string' }, + schema: { type: 'string', maxLength: 128 }, }, { name: 'shopId', @@ -1948,7 +1949,7 @@ function buildBaseRateOpenApiSpec( get: { operationId: 'getCrossPlatformDealRadar', summary: - 'Cross-Platform Deal Radar & Fake-Sale Trap Feed across 10 platforms', + 'Cross-Platform Deal Radar & Fake-Sale Trap Feed across 22 platforms', description: 'Returns real-time genuine cross-platform deals (`genuineDeals`, current offers below the cross-retailer median) and inflated fake-sale traps (`fakeSaleTraps`) audited against cross-retailer median prices. A genuine deal has `verdict` `genuine_all_time_low` (the multi-platform price floor) only when the product has 3 or more offers and the deal is the cheapest offer at least 2% below the median; otherwise it is `best_market_deal`, since the median of 2 offers is just their midpoint.', tags: ['Products & Specs'], @@ -1987,7 +1988,7 @@ function buildBaseRateOpenApiSpec( responses: { '200': { description: - 'Genuine deal radar and fake-sale trap list across 10 retailers.', + 'Genuine deal radar and fake-sale trap list across 22 retailers.', }, }, }, @@ -2120,7 +2121,7 @@ function buildBaseRateOpenApiSpec( type: 'string', enum: supportedPlatforms, description: - '10 supported Vietnamese e-commerce marketplaces and authorized electronics retailers.', + '22 supported Vietnamese e-commerce marketplaces and authorized electronics retailers.', }, CanonicalRateCategorySlug: { type: 'string', @@ -2146,7 +2147,7 @@ function buildBaseRateOpenApiSpec( externalItemId: { type: 'string', minLength: 1, - maxLength: 120, + maxLength: 128, example: '29512841920', description: 'Optional; derived from `url` when omitted.', }, diff --git a/packages/shared-data/src/__tests__/shared-data.test.ts b/packages/shared-data/src/__tests__/shared-data.test.ts index 5d6660de..d16d7139 100644 --- a/packages/shared-data/src/__tests__/shared-data.test.ts +++ b/packages/shared-data/src/__tests__/shared-data.test.ts @@ -312,7 +312,7 @@ function testMasterProductAndScrapedProductSchemas(): void { assert.deepEqual(master.images, []); assert.deepEqual(master.metadata, {}); - for (const platform of [ + const all22Platforms = [ 'shopee', 'lazada', 'tiki', @@ -323,16 +323,32 @@ function testMasterProductAndScrapedProductSchemas(): void { 'hoangha', 'didongviet', 'phongvu', - ]) { + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', + ]; + assert.deepEqual(SupportedEcommercePlatformSchema.options, all22Platforms); + for (const platform of all22Platforms) { assert.equal( SupportedEcommercePlatformSchema.safeParse(platform).success, true ); } - assert.equal( - SupportedEcommercePlatformSchema.safeParse('amazon').success, - false - ); + for (const unsupported of ['amazon', 'ebay', 'GEARVN', 'anphat', '']) { + assert.equal( + SupportedEcommercePlatformSchema.safeParse(unsupported).success, + false + ); + } const scraped = ScrapedProductSchema.parse({ platform: 'shopee', @@ -2926,10 +2942,6 @@ function testExtensionObservation(): void { for (const tgddUrl of [ 'https://thegioididong.com/dtdd/iphone-16-pro-max', 'https://www.thegioididong.com/dtdd/iphone-16-pro-max', - 'https://topzone.vn/iphone/iphone-16-pro-max', - 'https://www.topzone.vn/iphone/iphone-16-pro-max', - 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', - 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', ]) { assert.ok( parse({ @@ -2940,14 +2952,28 @@ function testExtensionObservation(): void { tgddUrl ); } + for (const separatedSisterUrl of [ + 'https://topzone.vn/iphone/iphone-16-pro-max', + 'https://www.topzone.vn/iphone/iphone-16-pro-max', + 'https://dienmayxanh.com/dtdd/iphone-16-pro-max', + 'https://www.dienmayxanh.com/dtdd/iphone-16-pro-max', + ]) { + const res = parse({ + ...valid, + marketplace: 'tgdd', + listing_url: separatedSisterUrl, + }); + assert.equal(res.ok, false, separatedSisterUrl); + if (!res.ok) assert.equal(res.field, 'listing_url'); + } // Every marketplace accepts its own hosts and refuses another's. assert.ok(rules.isExtensionMarketplaceHost('lazada', 'www.lazada.vn')); assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'thegioididong.com')); assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'www.thegioididong.com')); - assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'topzone.vn')); - assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'www.topzone.vn')); - assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'dienmayxanh.com')); - assert.ok(rules.isExtensionMarketplaceHost('tgdd', 'www.dienmayxanh.com')); + assert.ok(!rules.isExtensionMarketplaceHost('tgdd', 'topzone.vn')); + assert.ok(!rules.isExtensionMarketplaceHost('tgdd', 'www.topzone.vn')); + assert.ok(!rules.isExtensionMarketplaceHost('tgdd', 'dienmayxanh.com')); + assert.ok(!rules.isExtensionMarketplaceHost('tgdd', 'www.dienmayxanh.com')); assert.ok(rules.isExtensionMarketplaceHost('tiktok', 'shop.tiktok.com')); assert.ok(!rules.isExtensionMarketplaceHost('tiktok', 'm.tiktok.com')); assert.ok(!rules.isExtensionMarketplaceHost('lazada', 'notlazada.vn')); diff --git a/packages/shared-data/src/rules/extension-observation.ts b/packages/shared-data/src/rules/extension-observation.ts index 1a31b039..70acf874 100644 --- a/packages/shared-data/src/rules/extension-observation.ts +++ b/packages/shared-data/src/rules/extension-observation.ts @@ -12,6 +12,13 @@ export const EXTENSION_OBSERVATION_VERSION = 1; +/** + * Marketplaces accepted by `rate.extension_observations` and + * `rate.submit_extension_observation` in PostgreSQL (`20261106160000` in + * `DOS-Me`). Kept at the 10 SQL-checked marketplaces until a coordinated + * `DOS-Me` migration widens the table `CHECK` and RPC allowlist (see + * `DOS/Rate#1762` and `DOS/Rate#1850`). + */ const EXTENSION_MARKETPLACES = [ 'shopee', 'lazada', @@ -47,14 +54,7 @@ const EXTENSION_MARKETPLACE_HOSTS: Readonly< tiki: ['tiki.vn'], tiktok: ['www.tiktok.com', 'shop.tiktok.com'], cellphones: ['cellphones.com.vn'], - tgdd: [ - 'thegioididong.com', - '.thegioididong.com', - 'topzone.vn', - '.topzone.vn', - 'dienmayxanh.com', - '.dienmayxanh.com', - ], + tgdd: ['thegioididong.com', '.thegioididong.com'], fptshop: ['fptshop.com.vn'], hoangha: ['hoanghamobile.com'], didongviet: ['didongviet.vn'], diff --git a/packages/shared-data/src/schemas/specs.schema.ts b/packages/shared-data/src/schemas/specs.schema.ts index 8d4eedc7..d7ed5f45 100644 --- a/packages/shared-data/src/schemas/specs.schema.ts +++ b/packages/shared-data/src/schemas/specs.schema.ts @@ -188,8 +188,24 @@ export const SupportedEcommercePlatformSchema = z.enum([ 'hoangha', 'didongviet', 'phongvu', + 'dienmayxanh', + 'topzone', + 'gearvn', + 'nguyenkim', + 'shopdunk', + 'hacom', + 'clickbuy', + 'viettelstore', + 'pico', + 'mediamart', + 'memoryzone', + 'anphatpc', ]); +export type SupportedEcommercePlatform = z.infer< + typeof SupportedEcommercePlatformSchema +>; + export const ScrapedReviewerSchema = z.object({ key: z.string().max(128).optional(), isAnonymous: z.boolean().optional(), diff --git a/scripts/test-extension-observations-proposal.mjs b/scripts/test-extension-observations-proposal.mjs index 387129fe..bbe3ac65 100644 --- a/scripts/test-extension-observations-proposal.mjs +++ b/scripts/test-extension-observations-proposal.mjs @@ -463,6 +463,20 @@ try { 'listing_url', good({ marketplace: 'tiktok', listing_url: 'https://m.tiktok.com/x' }), ], + [ + 'listing_url', + good({ + marketplace: 'tgdd', + listing_url: 'https://www.topzone.vn/iphone/x', + }), + ], + [ + 'listing_url', + good({ + marketplace: 'tgdd', + listing_url: 'https://www.dienmayxanh.com/dtdd/x', + }), + ], [ 'listing_url', good({ listing_url: `https://shopee.vn/${'a'.repeat(2031)}` }),