@adobe/spacecat-shared-google-client 1.0.1 → 1.0.2
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 +1 -1
- package/src/index.d.ts +10 -9
- package/src/index.js +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-google-client-v1.0.2](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-google-client-v1.0.1...@adobe/spacecat-shared-google-client-v1.0.2) (2024-05-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* getOrganicSearchData interface params ([#236](https://github.com/adobe/spacecat-shared/issues/236)) ([acfd48b](https://github.com/adobe/spacecat-shared/commit/acfd48baaaa7594d0b9d7f00f7c9d52118b137e9))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-google-client-v1.0.1](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-google-client-v1.0.0...@adobe/spacecat-shared-google-client-v1.0.1) (2024-05-21)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -10,18 +10,17 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import { UniversalContext } from '@adobe/helix-universal';
|
|
14
13
|
import { OAuth2Client } from 'google-auth-library';
|
|
15
14
|
|
|
16
15
|
export default class GoogleClient {
|
|
17
16
|
/**
|
|
18
17
|
* Static factory method to create an instance of GoogleClient.
|
|
19
18
|
*
|
|
20
|
-
* @param {
|
|
19
|
+
* @param {object} context - An object containing the AWS Lambda context information
|
|
21
20
|
* @param {string} url - The URL of the site to be audited.
|
|
22
21
|
* @returns An instance of GoogleClient.
|
|
23
22
|
*/
|
|
24
|
-
static createFrom(context:
|
|
23
|
+
static createFrom(context: object, url: string): GoogleClient;
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* Constructor for creating an instance of GoogleClient.
|
|
@@ -33,12 +32,13 @@ export default class GoogleClient {
|
|
|
33
32
|
/**
|
|
34
33
|
* Retrieves the Google Search Console data for the specified date range.
|
|
35
34
|
*
|
|
36
|
-
* @param
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param dimensions - The dimensions to be included in the report.
|
|
35
|
+
* @param {Date} startDate - The start date of the date range.
|
|
36
|
+
* @param {Date} endDate - The end date of the date range.
|
|
37
|
+
* @param {Array} dimensions - The dimensions to be included in the report.
|
|
40
38
|
* this parameter is optional and defaults to ['date'],
|
|
41
39
|
* which means that the report will be grouped by date.
|
|
40
|
+
* @param {Number} rowLimit - The maximum number of rows to return, defaults to 1000.
|
|
41
|
+
* @param {Number} startRow - The row number to start from, defaults to 0.
|
|
42
42
|
* @returns {Promise<JSON>} The Google Search Console data.
|
|
43
43
|
* Format: {
|
|
44
44
|
* "rows": [
|
|
@@ -56,10 +56,11 @@ export default class GoogleClient {
|
|
|
56
56
|
* }
|
|
57
57
|
*/
|
|
58
58
|
getOrganicSearchData(
|
|
59
|
-
baseURL: string,
|
|
60
59
|
startDate: Date,
|
|
61
60
|
endDate: Date,
|
|
62
|
-
dimensions
|
|
61
|
+
dimensions?: string[],
|
|
62
|
+
rowLimit?: number,
|
|
63
|
+
startRow?: number
|
|
63
64
|
): Promise<JSON>;
|
|
64
65
|
|
|
65
66
|
/**
|
package/src/index.js
CHANGED
|
@@ -16,12 +16,16 @@ import { GetSecretValueCommand, SecretsManagerClient } from '@aws-sdk/client-sec
|
|
|
16
16
|
import {
|
|
17
17
|
isArray,
|
|
18
18
|
isInteger,
|
|
19
|
-
isValidDate,
|
|
19
|
+
isValidDate, isValidUrl,
|
|
20
20
|
resolveCustomerSecretsName,
|
|
21
21
|
} from '@adobe/spacecat-shared-utils';
|
|
22
22
|
|
|
23
23
|
export default class GoogleClient {
|
|
24
24
|
static async createFrom(context, baseURL) {
|
|
25
|
+
if (!isValidUrl(baseURL)) {
|
|
26
|
+
throw new Error('Error creating GoogleClient: Invalid base URL');
|
|
27
|
+
}
|
|
28
|
+
|
|
25
29
|
try {
|
|
26
30
|
const customerSecret = resolveCustomerSecretsName(baseURL, context);
|
|
27
31
|
const client = new SecretsManagerClient({});
|
|
@@ -61,6 +65,10 @@ export default class GoogleClient {
|
|
|
61
65
|
throw new Error('Missing refresh token in secret');
|
|
62
66
|
}
|
|
63
67
|
|
|
68
|
+
if (!isValidUrl(config.siteUrl)) {
|
|
69
|
+
throw new Error('Invalid site URL in secret');
|
|
70
|
+
}
|
|
71
|
+
|
|
64
72
|
authClient.setCredentials({
|
|
65
73
|
access_token: config.accessToken,
|
|
66
74
|
refresh_token: config.refreshToken,
|