Files
wehub-resource-sync 9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

46 lines
1.8 KiB
JavaScript

/**
* 携程酒店 hotel-context suggest — public city/business-area/hotel lookup.
*
* Distinct from `ctrip/search` (destination): the same backing endpoint is
* called with `searchType=H`, surfacing Hotel and BusinessArea rows that the
* destination flavour does not return.
*/
import { ArgumentError, EmptyResultError } from '@jackwener/opencli/errors';
import { cli, Strategy } from '@jackwener/opencli/registry';
import { fetchSuggest, mapSuggestRow, parseLimit } from './utils.js';
cli({
site: 'ctrip',
name: 'hotel-suggest',
access: 'read',
description: '搜索携程酒店上下文联想:城市、商圈、单酒店匹配',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'query', required: true, positional: true, help: 'Search keyword (city, business area, or hotel name)' },
{ name: 'limit', type: 'int', default: 15, help: 'Number of results (1-50)' },
],
columns: [
'rank', 'id', 'type', 'displayType', 'name', 'eName',
'cityId', 'cityName', 'provinceName', 'countryName',
'lat', 'lon', 'score', 'url',
],
func: async (kwargs) => {
const query = String(kwargs.query || '').trim();
if (!query) {
throw new ArgumentError('Search keyword cannot be empty');
}
const limit = parseLimit(kwargs.limit);
const raw = await fetchSuggest(query, 'H');
const rows = raw
.filter((item) => !!item && typeof item === 'object')
.slice(0, limit)
.map(mapSuggestRow)
.filter((row) => row.name);
if (!rows.length) {
throw new EmptyResultError('ctrip hotel-suggest', 'Try a city, business area, or hotel keyword such as "陆家嘴" or "汉庭酒店"');
}
return rows;
},
});