semrush-api-client 1.0.3 → 1.0.6

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.
@@ -4,6 +4,7 @@ import { getBacklinksOverview, getBacklinks, getAnchors, getIndexedPages, getRef
4
4
  import { getRankDifference, getSemrushRank } from "../overview";
5
5
  import { getTrafficSummary } from "../trend";
6
6
  import { getUrlOverview, getUrlOrganicSearchKeywords, getUrlPaidSearchKeywords } from "../url";
7
+ import { countApiUnits } from "../user";
7
8
  export declare class SemrushAPIClient {
8
9
  private client;
9
10
  private api_key;
@@ -35,4 +36,5 @@ export declare class SemrushAPIClient {
35
36
  getUrlOverview: typeof getUrlOverview;
36
37
  getUrlOrganicSearchKeywords: typeof getUrlOrganicSearchKeywords;
37
38
  getUrlPaidSearchKeywords: typeof getUrlPaidSearchKeywords;
39
+ countApiUnits: typeof countApiUnits;
38
40
  }
@@ -11,6 +11,7 @@ const backlinks_1 = require("../backlinks");
11
11
  const overview_1 = require("../overview");
12
12
  const trend_1 = require("../trend");
13
13
  const url_1 = require("../url");
14
+ const user_1 = require("../user");
14
15
  class SemrushAPIClient {
15
16
  client;
16
17
  api_key;
@@ -83,5 +84,7 @@ class SemrushAPIClient {
83
84
  getUrlOverview = url_1.getUrlOverview;
84
85
  getUrlOrganicSearchKeywords = url_1.getUrlOrganicSearchKeywords;
85
86
  getUrlPaidSearchKeywords = url_1.getUrlPaidSearchKeywords;
87
+ // User methods
88
+ countApiUnits = user_1.countApiUnits;
86
89
  }
87
90
  exports.SemrushAPIClient = SemrushAPIClient;
@@ -17,7 +17,7 @@ async function getDomainOrganicSearchKeywords({ domain, exportColumns = [
17
17
  "Td",
18
18
  ], database = "us", displayPosition, displayPositionsType, displayLimit = 10, displayOffset, displaySort, displayFilter, displayDate, exportEscape, exportDecode, outputObj = true, }) {
19
19
  if (displayDate && !(0, displayDateValidator_1.displayDateValidator)(displayDate)) {
20
- throw new Error("Invalid displayDate format. Format: YYYYMM15");
20
+ throw new Error("Invalid displayDate format. Format: YYYYMM15 or YYYYMMDD");
21
21
  }
22
22
  const params = {
23
23
  type: "domain_organic",
@@ -2,9 +2,10 @@ import { SemrushAPIClient } from "../client";
2
2
  import { Database } from "../type/general/database";
3
3
  type KeywordExportColumns = "Po" | "Pt" | "Dn" | "Ur" | "Fk" | "Fp" | "Fl";
4
4
  export type KeywordOrganicDisplaySort = "po_asc" | "po_desc" | "tr_asc" | "tr_desc";
5
- export declare function getKeywordOrganic(this: SemrushAPIClient, { phrase, exportColumns, database, displayLimit, displayOffset, displaySort, displayFilter, exportEscape, exportDecode, outputObj, }: {
5
+ export declare function getKeywordOrganic(this: SemrushAPIClient, { phrase, exportColumns, database, displayLimit, displayOffset, displayDate, displaySort, displayFilter, exportEscape, exportDecode, outputObj, }: {
6
6
  phrase: string;
7
7
  exportColumns?: KeywordExportColumns[];
8
+ displayDate?: string;
8
9
  database?: Database;
9
10
  displayLimit?: number;
10
11
  displayOffset?: number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getKeywordOrganic = getKeywordOrganic;
4
- async function getKeywordOrganic({ phrase, exportColumns = ["Po", "Pt", "Dn", "Ur", "Fk", "Fp", "Fl"], database = "us", displayLimit = 10, displayOffset, displaySort, displayFilter, exportEscape, exportDecode, outputObj = true, }) {
4
+ async function getKeywordOrganic({ phrase, exportColumns = ["Po", "Pt", "Dn", "Ur", "Fk", "Fp", "Fl"], database = "us", displayLimit = 10, displayOffset, displayDate, displaySort, displayFilter, exportEscape, exportDecode, outputObj = true, }) {
5
5
  const params = {
6
6
  type: "phrase_organic",
7
7
  export_columns: exportColumns.join(","),
@@ -9,6 +9,7 @@ async function getKeywordOrganic({ phrase, exportColumns = ["Po", "Pt", "Dn", "U
9
9
  database,
10
10
  display_limit: displayLimit,
11
11
  display_offset: displayOffset,
12
+ display_date: displayDate,
12
13
  display_sort: displaySort,
13
14
  display_filter: displayFilter,
14
15
  export_escape: exportEscape,
@@ -1,7 +1,8 @@
1
1
  import { SemrushAPIClient } from "../client";
2
2
  import { Database } from "../type/general/database";
3
- type KeywordExportColumns = "Dt" | "Db" | "Ph" | "Nq" | "Cp" | "Co" | "Nr" | "In" | "Kd";
4
- export declare function getKeywordOverview(this: SemrushAPIClient, { phrase, exportColumns, database, displayDate, exportEscape, exportDecode, outputObj, }: {
3
+ type KeywordExportColumns = "Dt" | "Db" | "Ph" | "Nq" | "Cp" | "Co" | "Nr" | "Td" | "In" | "Kd";
4
+ export declare function getKeywordOverview(this: SemrushAPIClient, { type, phrase, exportColumns, database, displayDate, exportEscape, exportDecode, outputObj, }: {
5
+ type?: "phrase_all" | "phrase_this";
5
6
  phrase: string;
6
7
  exportColumns?: KeywordExportColumns[];
7
8
  database?: Database;
@@ -2,15 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getKeywordOverview = getKeywordOverview;
4
4
  const displayDateValidator_1 = require("../utils/displayDateValidator");
5
- async function getKeywordOverview({ phrase, exportColumns = ["Dt", "Db", "Ph", "Nq", "Cp", "Co", "Nr", "In", "Kd"], database = "us", displayDate, exportEscape, exportDecode, outputObj = true, }) {
5
+ async function getKeywordOverview({ type = "phrase_this", phrase, exportColumns, database = type === "phrase_this" ? "us" : undefined, displayDate, exportEscape, exportDecode, outputObj = true, }) {
6
6
  if (displayDate && !(0, displayDateValidator_1.displayDateValidator)(displayDate)) {
7
7
  throw new Error("Invalid displayDate format. Format: YYYYMM15");
8
8
  }
9
+ // Set default export columns dynamically based on the requested report type
10
+ // Default columns per API documentation
11
+ const finalExportColumns = exportColumns
12
+ ? exportColumns
13
+ : type === "phrase_all"
14
+ ? ["Dt", "Db", "Ph", "Nq", "Cp", "Co", "Nr", "In", "Kd"]
15
+ : ["Ph", "Nq", "Cp", "Co", "Nr", "Td", "In", "Kd"];
9
16
  const params = {
10
- type: "phrase_all",
11
- export_columns: exportColumns.join(","),
17
+ type,
18
+ export_columns: finalExportColumns.join(","),
12
19
  phrase,
13
- database,
20
+ ...(type === "phrase_this" && database ? { database } : {}),
21
+ ...(type === "phrase_all" && database ? { database } : {}), // Optional filter for phrase_all
14
22
  display_date: displayDate,
15
23
  export_escape: exportEscape,
16
24
  export_decode: exportDecode,
@@ -0,0 +1,2 @@
1
+ import { SemrushAPIClient } from "../client";
2
+ export declare function countApiUnits(this: SemrushAPIClient): Promise<string>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countApiUnits = countApiUnits;
4
+ async function countApiUnits() {
5
+ const url = "http://www.semrush.com/users/countapiunits.html";
6
+ return this.get(url, undefined, false);
7
+ }
@@ -0,0 +1 @@
1
+ export { countApiUnits } from "./countApiUnits";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.countApiUnits = void 0;
4
+ var countApiUnits_1 = require("./countApiUnits");
5
+ Object.defineProperty(exports, "countApiUnits", { enumerable: true, get: function () { return countApiUnits_1.countApiUnits; } });
@@ -4,6 +4,6 @@ exports.displayDateValidator = displayDateValidator;
4
4
  function displayDateValidator(displayDate) {
5
5
  if (!displayDate)
6
6
  return true;
7
- const regex = /^\d{4}(0[1-9]|1[0-2])15$/;
7
+ const regex = /^\d{4}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])$/;
8
8
  return regex.test(displayDate);
9
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "semrush-api-client",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",