@adobe/spacecat-shared-google-client 1.1.18 → 1.2.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 CHANGED
@@ -1,3 +1,17 @@
1
+ # [@adobe/spacecat-shared-google-client-v1.2.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-google-client-v1.1.19...@adobe/spacecat-shared-google-client-v1.2.0) (2024-08-20)
2
+
3
+
4
+ ### Features
5
+
6
+ * introduce url inspect in google client ([#326](https://github.com/adobe/spacecat-shared/issues/326)) ([eb9e8ae](https://github.com/adobe/spacecat-shared/commit/eb9e8ae67f7a95ca5e4abb993f8b625400735312))
7
+
8
+ # [@adobe/spacecat-shared-google-client-v1.1.19](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-google-client-v1.1.18...@adobe/spacecat-shared-google-client-v1.1.19) (2024-08-19)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update external fixes ([#332](https://github.com/adobe/spacecat-shared/issues/332)) ([b2bb2a4](https://github.com/adobe/spacecat-shared/commit/b2bb2a4dd1a0995c36cd2b64510b7c4e0e05436f))
14
+
1
15
  # [@adobe/spacecat-shared-google-client-v1.1.18](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-google-client-v1.1.17...@adobe/spacecat-shared-google-client-v1.1.18) (2024-08-14)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-google-client",
3
- "version": "1.1.18",
3
+ "version": "1.2.0",
4
4
  "description": "Shared modules of the Spacecat Services - Google Client",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -34,16 +34,16 @@
34
34
  "@adobe/helix-universal": "5.0.5",
35
35
  "@adobe/spacecat-shared-http-utils": "1.1.4",
36
36
  "@adobe/spacecat-shared-utils": "1.15.1",
37
- "@aws-sdk/client-secrets-manager": "3.624.0",
37
+ "@aws-sdk/client-secrets-manager": "3.632.0",
38
38
  "google-auth-library": "9.13.0",
39
- "googleapis": "140.0.1"
39
+ "googleapis": "142.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "chai": "4.5.0",
42
+ "chai": "5.1.1",
43
43
  "chai-as-promised": "8.0.0",
44
44
  "nock": "13.5.4",
45
45
  "sinon": "18.0.0",
46
- "sinon-chai": "3.7.0",
46
+ "sinon-chai": "4.0.0",
47
47
  "typescript": "5.5.4"
48
48
  }
49
49
  }
package/src/index.d.ts CHANGED
@@ -63,6 +63,13 @@ export default class GoogleClient {
63
63
  startRow?: number
64
64
  ): Promise<JSON>;
65
65
 
66
+ /**
67
+ * Retrieves the Google Search Console data for the specified url.
68
+ * @param url - The URL of the site to be inspected
69
+ * @returns {Promise<JSON>} The Google Search Console data.
70
+ */
71
+ urlInspect(url: string): Promise<JSON>;
72
+
66
73
  /**
67
74
  * Lists all sites available to the authenticated user in Google Search Console.
68
75
  *
package/src/index.js CHANGED
@@ -17,9 +17,11 @@ import {
17
17
  composeAuditURL,
18
18
  isArray,
19
19
  isInteger,
20
- isValidDate, isValidUrl,
20
+ isValidDate,
21
+ isValidUrl,
21
22
  resolveCustomerSecretsName,
22
23
  } from '@adobe/spacecat-shared-utils';
24
+ import { fetch as httpFetch } from './utils.js';
23
25
 
24
26
  export default class GoogleClient {
25
27
  static async createFrom(context, baseURL) {
@@ -148,6 +150,38 @@ export default class GoogleClient {
148
150
  }
149
151
  }
150
152
 
153
+ async urlInspect(url) {
154
+ if (!isValidUrl(url)) {
155
+ throw new Error(`Error inspecting URL: Invalid URL format (${url})`);
156
+ }
157
+
158
+ await this.#refreshTokenIfExpired();
159
+
160
+ const apiEndpoint = 'https://searchconsole.googleapis.com/v1/urlInspection/index:inspect';
161
+
162
+ const response = await httpFetch(apiEndpoint, {
163
+ method: 'POST',
164
+ headers: {
165
+ 'Content-Type': 'application/json',
166
+ Authorization: `Bearer ${this.authClient.credentials.access_token}`,
167
+ },
168
+ body: JSON.stringify({
169
+ inspectionUrl: url,
170
+ siteUrl: this.siteUrl,
171
+ }),
172
+ });
173
+
174
+ if (!response.ok) {
175
+ throw new Error(`Error inspecting URL ${url}. Returned status ${response.status}`);
176
+ }
177
+
178
+ try {
179
+ return await response.json();
180
+ } catch (e) {
181
+ throw new Error(`Error parsing result of inspecting URL ${url}: ${e.message}`);
182
+ }
183
+ }
184
+
151
185
  async listSites() {
152
186
  await this.#refreshTokenIfExpired();
153
187
 
package/src/utils.js ADDED
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2024 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import { context as h2, h1 } from '@adobe/fetch';
14
+
15
+ /* c8 ignore next 3 */
16
+ export const { fetch } = process.env.HELIX_FETCH_FORCE_HTTP1
17
+ ? h1()
18
+ : h2();