feat(phone-sms): support 5sim provider

(cherry picked from commit 7d10cab9765ed662b5088f791c8635fd8cc63e44)
This commit is contained in:
朴圣佑
2026-04-30 15:12:58 +08:00
committed by QLHazyCoder
parent 48e3df0831
commit 2eb913e00b
17 changed files with 3569 additions and 2140 deletions
@@ -52,7 +52,7 @@ function extractFunction(name) {
return sidepanelSource.slice(start, end);
}
test('sidepanel html exposes phone verification toggle and dedicated HeroSMS rows', () => {
test('sidepanel html exposes phone verification toggle and multi-provider SMS rows', () => {
const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
assert.match(html, /id="row-phone-verification-enabled"/);
@@ -67,6 +67,12 @@ test('sidepanel html exposes phone verification toggle and dedicated HeroSMS row
assert.match(html, /id="row-phone-sms-provider-order-actions"/);
assert.match(html, /id="btn-phone-sms-provider-order-reset"/);
assert.match(html, /id="row-hero-sms-platform"/);
assert.match(html, /id="select-phone-sms-provider"/);
assert.match(html, /\.\.\/phone-sms\/providers\/hero-sms\.js/);
assert.match(html, /\.\.\/phone-sms\/providers\/five-sim\.js/);
assert.match(html, /\.\.\/phone-sms\/providers\/registry\.js/);
assert.match(html, /<option value="hero-sms">HeroSMS<\/option>/);
assert.match(html, /<option value="5sim">5sim<\/option>/);
assert.match(html, /id="row-hero-sms-country"/);
assert.match(html, /id="row-hero-sms-country-fallback"/);
assert.match(html, /id="row-hero-sms-acquire-priority"/);
@@ -75,6 +81,10 @@ test('sidepanel html exposes phone verification toggle and dedicated HeroSMS row
assert.doesNotMatch(html, /id="select-hero-sms-country-fallback"/);
assert.match(html, /id="row-hero-sms-api-key"/);
assert.match(html, /id="row-hero-sms-max-price"/);
assert.match(html, /id="btn-phone-sms-balance"/);
assert.match(html, /id="display-phone-sms-balance"/);
assert.match(html, /id="row-five-sim-operator"/);
assert.match(html, /id="input-five-sim-operator"/);
assert.match(html, /id="row-hero-sms-current-number"/);
assert.match(html, /id="row-hero-sms-current-countdown"/);
assert.match(html, /id="row-hero-sms-price-tiers"/);
@@ -107,7 +117,7 @@ test('sidepanel html exposes phone verification toggle and dedicated HeroSMS row
assert.doesNotMatch(html, /id="input-account-run-history-text-enabled"/);
});
test('updatePhoneVerificationSettingsUI toggles HeroSMS rows from the sms switch', () => {
test('updatePhoneVerificationSettingsUI toggles SMS rows from the sms switch and provider selection', () => {
const api = new Function(`
const phoneVerificationSectionExpanded = true;
let latestState = {};
@@ -159,6 +169,7 @@ const rowHeroSmsCountryFallback = { style: { display: 'none' } };
const rowHeroSmsAcquirePriority = { style: { display: 'none' } };
const rowHeroSmsApiKey = { style: { display: 'none' } };
const rowHeroSmsMaxPrice = { style: { display: 'none' } };
const rowFiveSimOperator = { style: { display: 'none' } };
const rowHeroSmsCurrentNumber = { style: { display: 'none' } };
const rowHeroSmsCurrentCountdown = { style: { display: 'none' } };
const rowHeroSmsPriceTiers = { style: { display: 'none' } };
@@ -170,15 +181,12 @@ const rowPhoneCodeWaitSeconds = { style: { display: 'none' } };
const rowPhoneCodeTimeoutWindows = { style: { display: 'none' } };
const rowPhoneCodePollIntervalSeconds = { style: { display: 'none' } };
const rowPhoneCodePollMaxRounds = { style: { display: 'none' } };
const rowFiveSimApiKey = { style: { display: 'none' } };
const rowFiveSimCountry = { style: { display: 'none' } };
const rowFiveSimCountryFallback = { style: { display: 'none' } };
const rowFiveSimOperator = { style: { display: 'none' } };
const rowFiveSimProduct = { style: { display: 'none' } };
const rowNexSmsApiKey = { style: { display: 'none' } };
const rowNexSmsCountry = { style: { display: 'none' } };
const rowNexSmsCountryFallback = { style: { display: 'none' } };
const rowNexSmsServiceCode = { style: { display: 'none' } };
const PHONE_SMS_PROVIDER_HERO_SMS = 'hero-sms';
const PHONE_SMS_PROVIDER_FIVE_SIM = '5sim';
let selectedPhoneSmsProvider = PHONE_SMS_PROVIDER_HERO_SMS;
function getSelectedPhoneSmsProvider() { return selectedPhoneSmsProvider; }
function isFiveSimProviderSelected() { return getSelectedPhoneSmsProvider() === PHONE_SMS_PROVIDER_FIVE_SIM; }
function updateHeroSmsPlatformDisplay() {}
${extractFunction('updatePhoneVerificationSettingsUI')}
@@ -198,6 +206,7 @@ return {
rowHeroSmsAcquirePriority,
rowHeroSmsApiKey,
rowHeroSmsMaxPrice,
rowFiveSimOperator,
rowHeroSmsCurrentNumber,
rowHeroSmsCurrentCountdown,
rowHeroSmsPriceTiers,
@@ -209,15 +218,7 @@ return {
rowPhoneCodeTimeoutWindows,
rowPhoneCodePollIntervalSeconds,
rowPhoneCodePollMaxRounds,
rowFiveSimApiKey,
rowFiveSimCountry,
rowFiveSimCountryFallback,
rowFiveSimOperator,
rowFiveSimProduct,
rowNexSmsApiKey,
rowNexSmsCountry,
rowNexSmsCountryFallback,
rowNexSmsServiceCode,
setSelectedPhoneSmsProvider(value) { selectedPhoneSmsProvider = value; },
updatePhoneVerificationSettingsUI,
};
`)();
@@ -230,12 +231,13 @@ return {
assert.equal(api.rowPhoneSmsProviderOrderActions.style.display, 'none');
assert.equal(api.btnTogglePhoneVerificationSection.disabled, true);
assert.equal(api.btnTogglePhoneVerificationSection.textContent, '展开设置');
assert.equal(api.rowHeroSmsPlatform.style.display, 'none');
assert.equal(api.rowHeroSmsPlatform.style.display, '');
assert.equal(api.rowHeroSmsCountry.style.display, 'none');
assert.equal(api.rowHeroSmsCountryFallback.style.display, 'none');
assert.equal(api.rowHeroSmsAcquirePriority.style.display, 'none');
assert.equal(api.rowHeroSmsApiKey.style.display, 'none');
assert.equal(api.rowHeroSmsMaxPrice.style.display, 'none');
assert.equal(api.rowFiveSimOperator.style.display, 'none');
assert.equal(api.rowHeroSmsCurrentNumber.style.display, 'none');
assert.equal(api.rowHeroSmsCurrentCountdown.style.display, 'none');
assert.equal(api.rowHeroSmsPriceTiers.style.display, 'none');
@@ -271,6 +273,7 @@ return {
assert.equal(api.rowHeroSmsAcquirePriority.style.display, '');
assert.equal(api.rowHeroSmsApiKey.style.display, '');
assert.equal(api.rowHeroSmsMaxPrice.style.display, '');
assert.equal(api.rowFiveSimOperator.style.display, 'none');
assert.equal(api.rowHeroSmsCurrentNumber.style.display, '');
assert.equal(api.rowHeroSmsCurrentCountdown.style.display, '');
assert.equal(api.rowHeroSmsPriceTiers.style.display, 'none');
@@ -282,41 +285,10 @@ return {
assert.equal(api.rowPhoneCodeTimeoutWindows.style.display, '');
assert.equal(api.rowPhoneCodePollIntervalSeconds.style.display, '');
assert.equal(api.rowPhoneCodePollMaxRounds.style.display, '');
assert.equal(api.rowFiveSimApiKey.style.display, 'none');
assert.equal(api.rowFiveSimCountry.style.display, 'none');
assert.equal(api.rowFiveSimCountryFallback.style.display, 'none');
assert.equal(api.rowFiveSimOperator.style.display, 'none');
assert.equal(api.rowFiveSimProduct.style.display, 'none');
assert.equal(api.rowNexSmsApiKey.style.display, 'none');
assert.equal(api.rowNexSmsCountry.style.display, 'none');
assert.equal(api.rowNexSmsCountryFallback.style.display, 'none');
assert.equal(api.rowNexSmsServiceCode.style.display, 'none');
api.selectPhoneSmsProvider.value = '5sim';
api.setLatestState({ phoneSmsProviderOrder: ['5sim'] });
api.setSelectedPhoneSmsProvider('5sim');
api.updatePhoneVerificationSettingsUI();
assert.equal(api.rowHeroSmsCountry.style.display, 'none');
assert.equal(api.rowHeroSmsApiKey.style.display, 'none');
assert.equal(api.rowFiveSimApiKey.style.display, '');
assert.equal(api.rowFiveSimCountry.style.display, '');
assert.equal(api.rowFiveSimCountryFallback.style.display, '');
assert.equal(api.rowFiveSimOperator.style.display, '');
assert.equal(api.rowFiveSimProduct.style.display, '');
assert.equal(api.rowNexSmsApiKey.style.display, 'none');
assert.equal(api.rowNexSmsCountry.style.display, 'none');
assert.equal(api.rowNexSmsCountryFallback.style.display, 'none');
assert.equal(api.rowNexSmsServiceCode.style.display, 'none');
api.selectPhoneSmsProvider.value = 'nexsms';
api.setLatestState({ phoneSmsProviderOrder: ['nexsms'] });
api.updatePhoneVerificationSettingsUI();
assert.equal(api.rowHeroSmsCountry.style.display, 'none');
assert.equal(api.rowFiveSimApiKey.style.display, 'none');
assert.equal(api.rowFiveSimCountry.style.display, 'none');
assert.equal(api.rowNexSmsApiKey.style.display, '');
assert.equal(api.rowNexSmsCountry.style.display, '');
assert.equal(api.rowNexSmsCountryFallback.style.display, '');
assert.equal(api.rowNexSmsServiceCode.style.display, '');
});
test('collectSettingsPayload keeps local helper sync enabled while persisting sms toggle state', () => {
@@ -386,6 +358,7 @@ function getSelectedPhonePreferredActivation() {
};
}
const inputHeroSmsMaxPrice = { value: '0.12' };
const inputFiveSimOperator = { value: 'any' };
const inputPhoneReplacementLimit = { value: '5' };
const inputPhoneCodeWaitSeconds = { value: '75' };
const inputPhoneCodeTimeoutWindows = { value: '3' };
@@ -414,6 +387,12 @@ const PHONE_REPLACEMENT_LIMIT_MIN = 1;
const PHONE_REPLACEMENT_LIMIT_MAX = 20;
const DEFAULT_HERO_SMS_COUNTRY_ID = 52;
const DEFAULT_HERO_SMS_COUNTRY_LABEL = 'Thailand';
const PHONE_SMS_PROVIDER_HERO_SMS = 'hero-sms';
const PHONE_SMS_PROVIDER_FIVE_SIM = '5sim';
const DEFAULT_PHONE_SMS_PROVIDER = PHONE_SMS_PROVIDER_HERO_SMS;
const DEFAULT_FIVE_SIM_COUNTRY_ID = 'england';
const DEFAULT_FIVE_SIM_COUNTRY_LABEL = '英国 (England)';
const DEFAULT_FIVE_SIM_OPERATOR = 'any';
const selectHeroSmsCountry = {
value: '52',
selectedIndex: 0,
@@ -436,6 +415,14 @@ function normalizeAutoRunThreadIntervalMinutes(value) { return Number(value) ||
function normalizeAutoDelayMinutes(value) { return Number(value) || 30; }
function normalizeAutoStepDelaySeconds(value) { return value === '' ? null : Number(value); }
function normalizeVerificationResendCount(value, fallback) { return Number(value) || fallback; }
${extractFunction('normalizePhoneSmsProvider')}
function getSelectedPhoneSmsProvider() { return normalizePhoneSmsProvider(selectPhoneSmsProvider?.value || latestState?.phoneSmsProvider); }
${extractFunction('normalizeFiveSimCountryId')}
${extractFunction('normalizeFiveSimCountryLabel')}
${extractFunction('normalizeFiveSimOperator')}
${extractFunction('normalizeFiveSimMaxPriceValue')}
${extractFunction('normalizeFiveSimCountryFallbackList')}
${extractFunction('normalizePhoneSmsMaxPriceValue')}
${extractFunction('normalizeHeroSmsMaxPriceValue')}
${extractFunction('normalizePhoneVerificationReplacementLimit')}
${extractFunction('normalizePhoneCodeWaitSecondsValue')}
@@ -485,6 +472,193 @@ return { collectSettingsPayload };
assert.equal(payload.heroSmsCountryId, 52);
assert.equal(payload.heroSmsCountryLabel, 'Thailand');
assert.deepStrictEqual(payload.heroSmsCountryFallback, [{ id: 16, label: 'United Kingdom' }]);
assert.equal(payload.fiveSimApiKey, '');
assert.equal(payload.fiveSimCountryId, 'england');
});
test('switchPhoneSmsProvider saves API keys independently when the select value has already changed', async () => {
const api = new Function(`
let latestState = {
phoneSmsProvider: 'hero-sms',
heroSmsApiKey: 'hero-old',
fiveSimApiKey: 'five-old',
heroSmsMaxPrice: '0.11',
fiveSimMaxPrice: '12',
heroSmsCountryId: 52,
heroSmsCountryLabel: 'Thailand',
heroSmsCountryFallback: [],
fiveSimCountryId: 'england',
fiveSimCountryLabel: '英国 (England)',
fiveSimCountryFallback: [],
fiveSimOperator: 'any',
};
const PHONE_SMS_PROVIDER_HERO_SMS = 'hero-sms';
const PHONE_SMS_PROVIDER_FIVE_SIM = '5sim';
const DEFAULT_FIVE_SIM_COUNTRY_ID = 'england';
const DEFAULT_FIVE_SIM_COUNTRY_LABEL = '英国 (England)';
const DEFAULT_FIVE_SIM_OPERATOR = 'any';
const DEFAULT_HERO_SMS_COUNTRY_ID = 52;
const DEFAULT_HERO_SMS_COUNTRY_LABEL = 'Thailand';
const selectPhoneSmsProvider = { value: 'hero-sms', dataset: { activeProvider: 'hero-sms' } };
const inputHeroSmsApiKey = { value: 'hero-live' };
const inputHeroSmsMaxPrice = { value: '0.22' };
const inputFiveSimOperator = { value: 'any' };
const displayHeroSmsPriceTiers = { textContent: '' };
const displayPhoneSmsBalance = { textContent: '' };
const rowHeroSmsPriceTiers = { style: { display: '' } };
let heroSmsCountrySelectionOrder = [];
let savedPayload = null;
${extractFunction('normalizePhoneSmsProvider')}
${extractFunction('setPhoneSmsProviderSelectValue')}
${extractFunction('getLastAppliedPhoneSmsProvider')}
function getSelectedPhoneSmsProvider() { return normalizePhoneSmsProvider(selectPhoneSmsProvider?.value || latestState?.phoneSmsProvider); }
${extractFunction('normalizeFiveSimCountryId')}
${extractFunction('normalizeFiveSimCountryLabel')}
${extractFunction('normalizeFiveSimOperator')}
${extractFunction('normalizeFiveSimMaxPriceValue')}
${extractFunction('normalizeHeroSmsMaxPriceValue')}
${extractFunction('normalizePhoneSmsMaxPriceValue')}
${extractFunction('normalizeHeroSmsCountryId')}
${extractFunction('normalizeHeroSmsCountryLabel')}
${extractFunction('normalizeHeroSmsCountryFallbackList')}
${extractFunction('normalizeFiveSimCountryFallbackList')}
function getSelectedHeroSmsCountryOption() {
return getSelectedPhoneSmsProvider() === PHONE_SMS_PROVIDER_FIVE_SIM
? { id: latestState.fiveSimCountryId || DEFAULT_FIVE_SIM_COUNTRY_ID, label: latestState.fiveSimCountryLabel || DEFAULT_FIVE_SIM_COUNTRY_LABEL }
: { id: latestState.heroSmsCountryId || DEFAULT_HERO_SMS_COUNTRY_ID, label: latestState.heroSmsCountryLabel || DEFAULT_HERO_SMS_COUNTRY_LABEL };
}
function syncHeroSmsFallbackSelectionOrderFromSelect() {
return getSelectedPhoneSmsProvider() === PHONE_SMS_PROVIDER_FIVE_SIM
? [{ id: 'england', label: '英国 (England)' }]
: [{ id: 52, label: 'Thailand' }];
}
function syncLatestState(patch) { latestState = { ...latestState, ...patch }; }
function loadHeroSmsCountries() { return Promise.resolve(); }
function applyHeroSmsFallbackSelection() {}
function updatePhoneVerificationSettingsUI() {}
function markSettingsDirty() {}
function saveSettings() { savedPayload = { ...latestState }; return Promise.resolve(); }
${extractFunction('switchPhoneSmsProvider')}
return {
selectPhoneSmsProvider,
inputHeroSmsApiKey,
get latestState() { return latestState; },
get savedPayload() { return savedPayload; },
switchPhoneSmsProvider,
};
`)();
// Browser change events update <select>.value before the listener runs.
api.selectPhoneSmsProvider.value = '5sim';
await api.switchPhoneSmsProvider(api.selectPhoneSmsProvider.value);
assert.equal(api.latestState.phoneSmsProvider, '5sim');
assert.equal(api.latestState.heroSmsApiKey, 'hero-live');
assert.equal(api.latestState.fiveSimApiKey, 'five-old');
assert.equal(api.inputHeroSmsApiKey.value, 'five-old');
assert.equal(api.selectPhoneSmsProvider.dataset.activeProvider, '5sim');
api.inputHeroSmsApiKey.value = 'five-live';
api.selectPhoneSmsProvider.value = 'hero-sms';
await api.switchPhoneSmsProvider(api.selectPhoneSmsProvider.value);
assert.equal(api.latestState.phoneSmsProvider, 'hero-sms');
assert.equal(api.latestState.heroSmsApiKey, 'hero-live');
assert.equal(api.latestState.fiveSimApiKey, 'five-live');
assert.equal(api.inputHeroSmsApiKey.value, 'hero-live');
assert.equal(api.selectPhoneSmsProvider.dataset.activeProvider, 'hero-sms');
assert.equal(api.savedPayload.heroSmsApiKey, 'hero-live');
assert.equal(api.savedPayload.fiveSimApiKey, 'five-live');
});
test('previewHeroSmsPriceTiers prefers 5sim products price for buy-compatible any operator', async () => {
const api = new Function(`
let latestState = { phoneSmsProvider: '5sim', fiveSimOperator: 'any' };
const PHONE_SMS_PROVIDER_HERO_SMS = 'hero-sms';
const PHONE_SMS_PROVIDER_FIVE_SIM = '5sim';
const DEFAULT_FIVE_SIM_COUNTRY_ID = 'england';
const DEFAULT_FIVE_SIM_COUNTRY_LABEL = '英国 (England)';
const DEFAULT_FIVE_SIM_OPERATOR = 'any';
const inputHeroSmsMaxPrice = { value: '' };
const inputHeroSmsApiKey = { value: '' };
const inputFiveSimOperator = { value: 'any' };
const displayHeroSmsPriceTiers = { textContent: '' };
const rowHeroSmsPriceTiers = { style: { display: 'none' } };
const fetchCalls = [];
${extractFunction('normalizePhoneSmsProvider')}
function getSelectedPhoneSmsProvider() { return '5sim'; }
${extractFunction('normalizeFiveSimCountryId')}
${extractFunction('normalizeFiveSimCountryLabel')}
${extractFunction('normalizeFiveSimOperator')}
${extractFunction('normalizePhoneSmsMaxPriceValue')}
${extractFunction('normalizeFiveSimMaxPriceValue')}
${extractFunction('normalizeHeroSmsMaxPriceValue')}
${extractFunction('normalizeHeroSmsPriceForPreview')}
${extractFunction('formatHeroSmsPriceForPreview')}
${extractFunction('isHeroSmsPreviewEmptyPayload')}
${extractFunction('collectHeroSmsPriceEntriesForPreview')}
${extractFunction('formatPhoneSmsPriceEntriesSummary')}
${extractFunction('describeHeroSmsPreviewPayload')}
${extractFunction('summarizeHeroSmsPreviewError')}
function normalizeHeroSmsFetchErrorMessage(error) { return error?.message || String(error); }
function syncHeroSmsFallbackSelectionOrderFromSelect() {
return [{ id: 'vietnam', label: '越南 (Vietnam)' }];
}
function getSelectedHeroSmsCountryOption() {
return { id: 'vietnam', label: '越南 (Vietnam)' };
}
function normalizePhoneSmsCountryId(value) { return normalizeFiveSimCountryId(value); }
function normalizePhoneSmsCountryLabel(value) { return normalizeFiveSimCountryLabel(value); }
function getHeroSmsCountryLabelById() { return '越南 (Vietnam)'; }
async function fetch(url, options = {}) {
const parsed = new URL(url);
fetchCalls.push({ url: parsed, options });
if (parsed.pathname === '/v1/guest/products/vietnam/any') {
return {
ok: true,
status: 200,
text: async () => JSON.stringify({ openai: { Category: 'activation', Qty: 4609, Price: 0.08 } }),
};
}
if (parsed.pathname === '/v1/guest/prices') {
return {
ok: true,
status: 200,
text: async () => JSON.stringify({
vietnam: {
openai: {
virtual21: { cost: 0.0769, count: 0 },
virtual47: { cost: 0.1282, count: 4608 },
},
},
}),
};
}
throw new Error('unexpected ' + parsed.pathname);
}
${extractFunction('previewHeroSmsPriceTiers')}
return {
displayHeroSmsPriceTiers,
rowHeroSmsPriceTiers,
fetchCalls,
previewHeroSmsPriceTiers,
};
`)();
await api.previewHeroSmsPriceTiers();
assert.equal(api.displayHeroSmsPriceTiers.textContent, '越南 (Vietnam): 最低 0.08');
assert.equal(api.rowHeroSmsPriceTiers.style.display, '');
assert.deepStrictEqual(
api.fetchCalls.map((entry) => entry.url.pathname),
['/v1/guest/products/vietnam/any', '/v1/guest/prices']
);
});
test('hero sms max price input does not auto-save partial typing states', () => {