seo 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { i as __toESM, n as load, r as __commonJSMin, t as version } from "./package-CmplBMg7.js";
2
+ import { i as __toESM, n as load, r as __commonJSMin, t as version } from "./package-BaQwwfSG.js";
3
3
  import { createHash, randomUUID, sign } from "node:crypto";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import { arch, homedir, platform, totalmem } from "node:os";
@@ -38586,10 +38586,32 @@ async function research(provider, headers, input) {
38586
38586
  function countryName(code) {
38587
38587
  return new Intl.DisplayNames("en", { type: "region" }).of(code.toUpperCase()) ?? "United States";
38588
38588
  }
38589
+ function mainLanguage(country) {
38590
+ try {
38591
+ return new Intl.Locale(`und-${country.toUpperCase()}`).maximize().language;
38592
+ } catch {
38593
+ return "en";
38594
+ }
38595
+ }
38596
+ const LABS_LANGUAGES = new Map(`
38597
+ ae:ar al:sq am:hy ao:pt ar:es at:de au:en az:az ba:bs bd:bn be:nl bf:fr
38598
+ bg:bg bh:ar bo:es br:pt ca:en ch:de ci:fr cl:es cm:fr co:es cr:es cy:el
38599
+ cz:cs de:de dk:da dz:ar ec:es ee:et eg:ar es:es fi:fi fr:fr gb:en gh:en
38600
+ gr:el gt:es hk:en hr:hr hu:hu id:id ie:en il:he in:en it:it jo:ar jp:ja
38601
+ ke:en kh:en kr:ko kz:ru lk:en lt:lt lv:lv ma:ar mc:fr md:ro mk:mk mm:en
38602
+ mt:en mx:es my:en ng:en ni:es nl:nl no:nb nz:en pa:es pe:es ph:en pk:en
38603
+ pl:pl pt:pt py:es ro:ro rs:sr sa:ar se:sv sg:en si:sl sk:sk sn:fr sv:es
38604
+ th:th tn:ar tr:tr tw:zh-TW ua:uk us:en uy:es ve:es vn:vi za:en
38605
+ `.trim().split(/\s+/).map((pair) => pair.split(":")));
38606
+ function dataForSeoLanguage(country) {
38607
+ return LABS_LANGUAGES.get(country.toLowerCase()) ?? null;
38608
+ }
38589
38609
  async function dataForSeo([login, password], input) {
38610
+ const language = dataForSeoLanguage(input.country);
38611
+ if (!language && input.action !== "serp" && input.action !== "backlinks") throw new CommandError("INVALID_INPUT", `DataForSEO has no ${input.action} data for country "${input.country}".`);
38590
38612
  const market = {
38591
38613
  location_name: countryName(input.country),
38592
- language_code: input.language
38614
+ language_code: language ?? mainLanguage(input.country)
38593
38615
  };
38594
38616
  const post = async (path, task) => {
38595
38617
  const result = (await (await call("dataforseo", new Request(`https://api.dataforseo.com/${path}`, {
@@ -38798,12 +38820,12 @@ async function runResearch(input, keys, options) {
38798
38820
  const country = input.country ?? "us";
38799
38821
  const target = input.target ?? "";
38800
38822
  const offset = input.offset ?? 0;
38823
+ const language = input.provider === "dataforseo" ? dataForSeoLanguage(country) : null;
38801
38824
  const found = await research(input.provider, keys, {
38802
38825
  action: input.action,
38803
38826
  keywords: input.keywords ?? [],
38804
38827
  target,
38805
38828
  country,
38806
- language: "en",
38807
38829
  limit: Math.min(1e3, Math.max(100, offset + 50))
38808
38830
  });
38809
38831
  const { rows, note } = input.action === "competitors" ? realCompetitors(found, target) : {
@@ -38816,7 +38838,7 @@ async function runResearch(input, keys, options) {
38816
38838
  const hasTargetDr = targetDr !== void 0 && targetDr !== null;
38817
38839
  return {
38818
38840
  text: rowsText({
38819
- title: `${input.provider} ${input.action}${target ? ` for ${target}` : ""}, ${country}.`,
38841
+ title: `${input.provider} ${input.action}${target ? ` for ${target}` : ""}, ${country}${language ? `, language ${language}` : ""}.`,
38820
38842
  rows: rated.rows,
38821
38843
  offset,
38822
38844
  limit: 50,
@@ -38834,6 +38856,7 @@ async function runResearch(input, keys, options) {
38834
38856
  action: input.action,
38835
38857
  target: target || null,
38836
38858
  country,
38859
+ language,
38837
38860
  targetDomainRating: hasTargetDr ? targetDr : null,
38838
38861
  attribution: rated.added || hasTargetDr ? DR_ATTRIBUTION : null,
38839
38862
  leftOut: note,