@adobe/spacecat-shared-scrape-client 2.1.6 → 2.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-scrape-client-v2.2.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-scrape-client-v2.1.7...@adobe/spacecat-shared-scrape-client-v2.2.0) (2025-10-29)
2
+
3
+
4
+ ### Features
5
+
6
+ * scrape url access pattern ([#1059](https://github.com/adobe/spacecat-shared/issues/1059)) ([26facf6](https://github.com/adobe/spacecat-shared/commit/26facf63dfae4908ed88221f16266910205e2473))
7
+
8
+ # [@adobe/spacecat-shared-scrape-client-v2.1.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-scrape-client-v2.1.6...@adobe/spacecat-shared-scrape-client-v2.1.7) (2025-10-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * remove cyclic deps in shared ([#1053](https://github.com/adobe/spacecat-shared/issues/1053)) ([acbbc93](https://github.com/adobe/spacecat-shared/commit/acbbc93f8c961fdef55edb5e7947958456538586))
14
+
1
15
  # [@adobe/spacecat-shared-scrape-client-v2.1.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-scrape-client-v2.1.5...@adobe/spacecat-shared-scrape-client-v2.1.6) (2025-10-28)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/spacecat-shared-scrape-client",
3
- "version": "2.1.6",
3
+ "version": "2.2.0",
4
4
  "description": "Shared modules of the Spacecat Services - Scrape Client",
5
5
  "type": "module",
6
6
  "engines": {
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@adobe/helix-universal": "5.2.3",
39
39
  "@adobe/spacecat-shared-data-access": "2.45.0",
40
- "@adobe/spacecat-shared-utils": "1.31.0"
40
+ "@adobe/spacecat-shared-utils": "1.66.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "chai": "6.2.0",
@@ -16,6 +16,7 @@ import {
16
16
  import { ScrapeJob as ScrapeJobModel } from '@adobe/spacecat-shared-data-access';
17
17
  import { ScrapeJobDto } from './scrapeJobDto.js';
18
18
  import ScrapeJobSupervisor from './scrape-job-supervisor.js';
19
+ import { ScrapeUrlDto } from './scrapeUrlDto.js';
19
20
 
20
21
  export default class ScrapeClient {
21
22
  config = null;
@@ -343,4 +344,30 @@ export default class ScrapeClient {
343
344
  throw new Error(msgError);
344
345
  }
345
346
  }
347
+
348
+ async getScrapeUrlsByProcessingType(url, processingType, maxScrapeAge = 168) {
349
+ let decodedUrl;
350
+ try {
351
+ decodedUrl = decodeURIComponent(url);
352
+ if (!isValidUrl(decodedUrl)) {
353
+ throw new Error(`Invalid request: ${decodedUrl} must be a valid URL`);
354
+ }
355
+
356
+ const scrapeUrls = await this.scrapeSupervisor.getScrapeUrlsByProcessingType(
357
+ decodedUrl,
358
+ processingType,
359
+ maxScrapeAge,
360
+ );
361
+
362
+ if (!isNonEmptyArray(scrapeUrls)) {
363
+ return null;
364
+ }
365
+
366
+ return scrapeUrls.map((scrapeUrl) => ScrapeUrlDto.toJSON(scrapeUrl));
367
+ } catch (error) {
368
+ const msgError = `Failed to fetch scrape URL by URL: ${decodedUrl} and processing type: ${processingType}, ${error.message}`;
369
+ this.config.log.error(msgError);
370
+ throw new Error(msgError);
371
+ }
372
+ }
346
373
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import { ScrapeJob as ScrapeJobModel } from '@adobe/spacecat-shared-data-access';
14
- import { isValidUUID } from '@adobe/spacecat-shared-utils';
14
+ import { isValidUrl, isValidUUID } from '@adobe/spacecat-shared-utils';
15
15
 
16
16
  /**
17
17
  * Scrape Supervisor provides functionality to start and manage scrape jobs.
@@ -30,7 +30,7 @@ function ScrapeJobSupervisor(services, config) {
30
30
  dataAccess, sqs, log,
31
31
  } = services;
32
32
 
33
- const { ScrapeJob } = dataAccess;
33
+ const { ScrapeJob, ScrapeUrl } = dataAccess;
34
34
 
35
35
  const {
36
36
  scrapeWorkerQueue, // URL of the scrape worker queue
@@ -227,12 +227,27 @@ function ScrapeJobSupervisor(services, config) {
227
227
  }
228
228
  }
229
229
 
230
+ async function getScrapeUrlsByProcessingType(url, processingType, maxScrapeAge) {
231
+ if (!isValidUrl(url)) {
232
+ throw new Error(`${url} must be a valid URL`);
233
+ }
234
+ try {
235
+ return ScrapeUrl.allRecentByUrlAndProcessingType(url, processingType, maxScrapeAge);
236
+ } catch (error) {
237
+ if (error.message.includes('Not found')) {
238
+ return null;
239
+ }
240
+ throw error;
241
+ }
242
+ }
243
+
230
244
  return {
231
245
  startNewJob,
232
246
  getScrapeJob,
233
247
  getScrapeJobsByDateRange,
234
248
  getScrapeJobsByBaseURL,
235
249
  getScrapeJobsByBaseURLAndProcessingType,
250
+ getScrapeUrlsByProcessingType,
236
251
  };
237
252
  }
238
253
 
@@ -0,0 +1,30 @@
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
+ /**
14
+ * Data transfer object for Import Job.
15
+ */
16
+ export const ScrapeUrlDto = {
17
+ /**
18
+ * Converts an Import Job object into a JSON object.
19
+ */
20
+ toJSON: (scrapeUrl) => ({
21
+ id: scrapeUrl.getId(),
22
+ URL: scrapeUrl.getUrl(),
23
+ processingType: scrapeUrl.getProcessingType(),
24
+ options: scrapeUrl.getOptions(),
25
+ status: scrapeUrl.getStatus(),
26
+ path: scrapeUrl.getPath(),
27
+ scrapeJobId: scrapeUrl.getScrapeJobId(),
28
+ createdAt: scrapeUrl.getCreatedAt(),
29
+ }),
30
+ };