@adobe/spacecat-shared-ahrefs-client 1.2.6 → 1.3.0
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/CHANGELOG.md +7 -0
- package/package.json +3 -3
- package/src/index.d.ts +6 -0
- package/src/index.js +43 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-ahrefs-client-v1.3.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-ahrefs-client-v1.2.6...@adobe/spacecat-shared-ahrefs-client-v1.3.0) (2024-06-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* introduce organic keywords for ahrefs client and top keyword in top pages ([#257](https://github.com/adobe/spacecat-shared/issues/257)) ([371f1c4](https://github.com/adobe/spacecat-shared/commit/371f1c475870fd2aac833f925236237a8b25c026))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-ahrefs-client-v1.2.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-ahrefs-client-v1.2.5...@adobe/spacecat-shared-ahrefs-client-v1.2.6) (2024-06-11)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-ahrefs-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Ahrefs Client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"chai": "4.4.1",
|
|
39
|
-
"chai-as-promised": "
|
|
39
|
+
"chai-as-promised": "8.0.0",
|
|
40
40
|
"nock": "13.5.4",
|
|
41
|
-
"sinon": "
|
|
41
|
+
"sinon": "18.0.0",
|
|
42
42
|
"sinon-chai": "3.7.0",
|
|
43
43
|
"typescript": "5.4.5"
|
|
44
44
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -70,4 +70,10 @@ export default class AhrefsAPIClient {
|
|
|
70
70
|
*/
|
|
71
71
|
getBacklinks(url: string, limit?: number):
|
|
72
72
|
Promise<{ result: object, fullAuditRef: string }>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Asynchronous method to get organic keywords.
|
|
76
|
+
*/
|
|
77
|
+
getOrganicKeywords(url: string, country?: string, keywordFilter?: string[], limit?: number):
|
|
78
|
+
Promise<{ result: object, fullAuditRef: string }>;
|
|
73
79
|
}
|
package/src/index.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { isValidUrl } from '@adobe/spacecat-shared-utils';
|
|
13
|
+
import { hasText, isValidUrl, isArray } from '@adobe/spacecat-shared-utils';
|
|
14
14
|
import { context as h2, h1 } from '@adobe/fetch';
|
|
15
15
|
|
|
16
16
|
/* c8 ignore next 3 */
|
|
@@ -120,6 +120,7 @@ export default class AhrefsAPIClient {
|
|
|
120
120
|
select: [
|
|
121
121
|
'url',
|
|
122
122
|
'sum_traffic',
|
|
123
|
+
'top_keyword',
|
|
123
124
|
].join(','),
|
|
124
125
|
order_by: 'sum_traffic',
|
|
125
126
|
date: new Date().toISOString().split('T')[0],
|
|
@@ -174,4 +175,45 @@ export default class AhrefsAPIClient {
|
|
|
174
175
|
|
|
175
176
|
return this.sendRequest('/site-explorer/metrics-history', queryParams);
|
|
176
177
|
}
|
|
178
|
+
|
|
179
|
+
async getOrganicKeywords(url, country = 'us', keywordFilter = [], limit = 200) {
|
|
180
|
+
if (!hasText(url)) {
|
|
181
|
+
throw new Error(`Invalid URL: ${url}`);
|
|
182
|
+
}
|
|
183
|
+
if (!hasText(country)) {
|
|
184
|
+
throw new Error(`Invalid country: ${country}`);
|
|
185
|
+
}
|
|
186
|
+
if (!isArray(keywordFilter)) {
|
|
187
|
+
throw new Error(`Invalid keyword filter: ${keywordFilter}`);
|
|
188
|
+
}
|
|
189
|
+
if (!Number.isInteger(limit) || limit < 1) {
|
|
190
|
+
throw new Error(`Invalid limit: ${limit}`);
|
|
191
|
+
}
|
|
192
|
+
const queryParams = {
|
|
193
|
+
country,
|
|
194
|
+
date: new Date().toISOString().split('T')[0],
|
|
195
|
+
select: [
|
|
196
|
+
'keyword',
|
|
197
|
+
'sum_traffic',
|
|
198
|
+
'best_position_url',
|
|
199
|
+
].join(','),
|
|
200
|
+
order_by: 'sum_traffic:desc',
|
|
201
|
+
target: url,
|
|
202
|
+
limit: getLimit(limit, 2000),
|
|
203
|
+
mode: 'prefix',
|
|
204
|
+
output: 'json',
|
|
205
|
+
};
|
|
206
|
+
if (keywordFilter.length > 0) {
|
|
207
|
+
try {
|
|
208
|
+
queryParams.where = JSON.stringify({
|
|
209
|
+
or: keywordFilter.map((keyword) => ({ field: 'keyword', is: ['iphrase_match', keyword] })),
|
|
210
|
+
});
|
|
211
|
+
} catch (e) {
|
|
212
|
+
this.log.error(`Error parsing keyword filter: ${e.message}`);
|
|
213
|
+
throw new Error(`Error parsing keyword filter: ${e.message}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return this.sendRequest('/site-explorer/organic-keywords', queryParams);
|
|
218
|
+
}
|
|
177
219
|
}
|