|
|
import { createHash } from "node:crypto";
|
|
|
import type {
|
|
|
AddressLookupInput,
|
|
|
MothershipAddressCandidate,
|
|
|
} from "@/modules/address/types";
|
|
|
|
|
|
function optionId(label: string): string {
|
|
|
return `ms_${createHash("sha256").update(label).digest("hex").slice(0, 16)}`;
|
|
|
}
|
|
|
|
|
|
function candidate(
|
|
|
displayLabel: string,
|
|
|
street: string,
|
|
|
city: string,
|
|
|
state: string,
|
|
|
zip: string,
|
|
|
): MothershipAddressCandidate {
|
|
|
return {
|
|
|
option_id: optionId(displayLabel),
|
|
|
display_label: displayLabel,
|
|
|
formatted_address: `${street}, ${city}, ${state}, USA`,
|
|
|
street,
|
|
|
city,
|
|
|
state,
|
|
|
zip,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/** 演示/联调:MotherShip 同邮编多精确坐标(禁止 RPA 自动择一) */
|
|
|
export function listMockMothershipCandidates(
|
|
|
input: AddressLookupInput,
|
|
|
): MothershipAddressCandidate[] {
|
|
|
const zip = input.zip.trim();
|
|
|
const street = input.street.trim().toLowerCase();
|
|
|
|
|
|
if (zip === "90001" || street.includes("warehouse")) {
|
|
|
return [
|
|
|
candidate(
|
|
|
"1234 Warehouse Street, Los Angeles, CA",
|
|
|
"1234 Warehouse Street",
|
|
|
"Los Angeles",
|
|
|
"CA",
|
|
|
"90001",
|
|
|
),
|
|
|
candidate(
|
|
|
"1234 Warehouse Blvd, Los Angeles, CA",
|
|
|
"1234 Warehouse Blvd",
|
|
|
"Los Angeles",
|
|
|
"CA",
|
|
|
"90001",
|
|
|
),
|
|
|
candidate(
|
|
|
"1234 S Warehouse St, Los Angeles, CA",
|
|
|
"1234 S Warehouse St",
|
|
|
"Los Angeles",
|
|
|
"CA",
|
|
|
"90001",
|
|
|
),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
if (zip === "75201" || street.includes("distribution")) {
|
|
|
return [
|
|
|
candidate(
|
|
|
"5678 Distribution Dr, Dallas, TX",
|
|
|
"5678 Distribution Dr",
|
|
|
"Dallas",
|
|
|
"TX",
|
|
|
"75201",
|
|
|
),
|
|
|
candidate(
|
|
|
"5678 Distribution Dr, Eagle Pass, TX",
|
|
|
"5678 Distribution Dr",
|
|
|
"Eagle Pass",
|
|
|
"TX",
|
|
|
"75201",
|
|
|
),
|
|
|
candidate(
|
|
|
"5678 Distribution Drive, Dallas, TX",
|
|
|
"5678 Distribution Drive",
|
|
|
"Dallas",
|
|
|
"TX",
|
|
|
"75201",
|
|
|
),
|
|
|
candidate(
|
|
|
"5678 Distribution Dr Ste 100, Dallas, TX",
|
|
|
"5678 Distribution Dr Ste 100",
|
|
|
"Dallas",
|
|
|
"TX",
|
|
|
"75201",
|
|
|
),
|
|
|
];
|
|
|
}
|
|
|
|
|
|
const display = `${input.street}, ${input.city}, ${input.state}`;
|
|
|
return [
|
|
|
candidate(display, input.street, input.city, input.state, input.zip),
|
|
|
];
|
|
|
}
|