diff --git a/README.md b/README.md index e32bf65..78f81bb 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ takoSearch({ baseUrl: 'https://tako.com', // optional; override for staging effort: 'fast', // 'fast' (default) | 'instant' | 'deep' sources: { // a source is searched iff its key is present; omit to search both - tako: { count: 5, includeContents: false, deferDataRetrieval: false }, + data: { count: 5, includeContents: false, deferDataRetrieval: false }, // legacy alias: tako web: { count: 5, includeContents: false }, }, countryCode: 'US', // default 'US' diff --git a/src/request.ts b/src/request.ts index b7f712c..c454a74 100644 --- a/src/request.ts +++ b/src/request.ts @@ -16,7 +16,7 @@ export interface SearchRequestBody { country_code: string; locale: string; sources?: { - tako?: { count?: number; include_contents?: boolean; defer_data_retrieval?: boolean }; + data?: { count?: number; include_contents?: boolean; defer_data_retrieval?: boolean }; web?: { count?: number; include_contents?: boolean }; }; timezone?: string; @@ -34,12 +34,14 @@ export function buildSearchRequestBody(config: TakoRetrievalConfig, query: strin if (config.sources) { const sources: NonNullable = {}; - if (config.sources.tako) { - const tako: NonNullable["tako"]> = {}; - if (config.sources.tako.count !== undefined) tako.count = config.sources.tako.count; - if (config.sources.tako.includeContents !== undefined) tako.include_contents = config.sources.tako.includeContents; - if (config.sources.tako.deferDataRetrieval !== undefined) tako.defer_data_retrieval = config.sources.tako.deferDataRetrieval; - sources.tako = tako; + // `data` is the curated Tako source; `tako` is the deprecated legacy alias. + const dataSource = config.sources.data ?? config.sources.tako; + if (dataSource) { + const data: NonNullable["data"]> = {}; + if (dataSource.count !== undefined) data.count = dataSource.count; + if (dataSource.includeContents !== undefined) data.include_contents = dataSource.includeContents; + if (dataSource.deferDataRetrieval !== undefined) data.defer_data_retrieval = dataSource.deferDataRetrieval; + sources.data = data; } if (config.sources.web) { const web: NonNullable["web"]> = {}; diff --git a/src/types.ts b/src/types.ts index 2e08f4d..2f54f81 100644 --- a/src/types.ts +++ b/src/types.ts @@ -31,8 +31,14 @@ export interface TakoCardSourceOptions extends TakoSourceOptions { export interface TakoRetrievalConfig extends TakoBaseConfig { /** "fast" (default) | "instant" | "deep". */ effort?: TakoSearchEffort; - /** Per-source settings. A source is searched iff its key is present. Omit to search tako + web. */ - sources?: { tako?: TakoCardSourceOptions; web?: TakoSourceOptions }; + /** Per-source settings. A source is searched iff its key is present. Omit to search data + web. */ + sources?: { + /** The curated Tako data source. */ + data?: TakoCardSourceOptions; + web?: TakoSourceOptions; + /** @deprecated Use `data`. Legacy alias for the curated Tako source. */ + tako?: TakoCardSourceOptions; + }; /** ISO 3166-1 alpha-2 country code. Default "US". */ countryCode?: string; /** BCP-47 locale tag. Default "en-US". */ diff --git a/tests/search.test.ts b/tests/search.test.ts index 17db523..7fc3329 100644 --- a/tests/search.test.ts +++ b/tests/search.test.ts @@ -28,7 +28,7 @@ describe("takoSearch", () => { const t = takoSearch({ apiKey: "key", effort: "deep", - sources: { tako: { count: 10, deferDataRetrieval: true } }, + sources: { data: { count: 10, deferDataRetrieval: true } }, timezone: "America/New_York", outputSettings: { imageDarkMode: true }, }); @@ -39,12 +39,24 @@ describe("takoSearch", () => { effort: "deep", country_code: "US", locale: "en-US", - sources: { tako: { count: 10, defer_data_retrieval: true } }, + sources: { data: { count: 10, defer_data_retrieval: true } }, timezone: "America/New_York", output_settings: { image_dark_mode: true }, }); }); + it("maps the deprecated `tako` source alias onto the `data` wire key", async () => { + const fetchMock = stubFetch(200, OK); + const t = takoSearch({ + apiKey: "key", + sources: { tako: { count: 10, deferDataRetrieval: true } }, + }); + await runTool(t, { query: "x" }); + const init = fetchMock.mock.calls[0][1] as RequestInit; + const body = JSON.parse(init.body as string); + expect(body.sources).toEqual({ data: { count: 10, defer_data_retrieval: true } }); + }); + it("honors baseUrl override (trailing slash stripped)", async () => { const fetchMock = stubFetch(200, OK); const t = takoSearch({ apiKey: "key", baseUrl: "https://staging.trytako.com/" }); diff --git a/tests/types.test.ts b/tests/types.test.ts index c653c7f..eeb0f80 100644 --- a/tests/types.test.ts +++ b/tests/types.test.ts @@ -71,7 +71,7 @@ describe("types", () => { apiKey: "k", baseUrl: "https://staging.trytako.com", effort: "deep", - sources: { tako: { count: 10, deferDataRetrieval: true }, web: { count: 3, includeContents: true } }, + sources: { data: { count: 10, deferDataRetrieval: true }, web: { count: 3, includeContents: true } }, countryCode: "US", locale: "en-US", timezone: "America/New_York",