Skip to content

Commit 327d934

Browse files
Kanishkavijay39Kanishkacursoragent
authored
fix(data-access): support both snake_case and camelCase in BROKEN_BAC… (#1336)
…KLINKS schema - Add support for both url_from/urlFrom and url_to/urlTo - Use Joi .or() validation to require at least one naming convention - Update minimal projection to include all field name variants - Ensures compatibility with both Ahrefs API (snake_case) and internal data (camelCase) Please ensure your pull request adheres to the following guidelines: - [ ] make sure to link the related issues in this description - [ ] when merging / squashing, make sure the fixed issue references are visible in the commits, for easy compilation of release notes ## Related Issues Thanks for contributing! --------- Co-authored-by: Kanishka <kanishka@adobe.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2ea2c52 commit 327d934

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

packages/spacecat-shared-data-access/src/models/suggestion/suggestion.data-schemas.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,35 +350,46 @@ export const DATA_SCHEMAS = {
350350
},
351351
[OPPORTUNITY_TYPES.BROKEN_BACKLINKS]: {
352352
schema: Joi.object({
353-
url_from: Joi.string().uri().required(),
354-
url_to: Joi.string().uri().required(),
353+
url_from: Joi.string().uri().optional(),
354+
urlFrom: Joi.string().uri().optional(),
355+
url_to: Joi.string().uri().optional(),
356+
urlTo: Joi.string().uri().optional(),
355357
title: Joi.string().optional(),
356358
traffic_domain: Joi.number().optional(),
357359
aiRationale: Joi.string().optional(),
358360
urlsSuggested: Joi.array().items(Joi.string().uri()).optional(),
359361
aggregationKey: Joi.string().allow(null).optional(),
360-
}).unknown(true),
362+
})
363+
.or('url_from', 'urlFrom') // At least one of these must be present
364+
.or('url_to', 'urlTo') // At least one of these must be present
365+
.unknown(true),
361366
projections: {
362367
minimal: {
363-
fields: ['url_from', 'url_to'],
368+
fields: ['url_from', 'url_to', 'urlFrom', 'urlTo'],
364369
transformers: {},
365370
},
366371
},
367372
},
368373
[OPPORTUNITY_TYPES.BROKEN_INTERNAL_LINKS]: {
369374
schema: Joi.object({
370-
urlFrom: Joi.string().uri().required(),
371-
urlTo: Joi.string().uri().required(),
375+
// Support both naming conventions (snake_case and camelCase)
376+
url_from: Joi.string().uri().optional(),
377+
urlFrom: Joi.string().uri().optional(),
378+
url_to: Joi.string().uri().optional(),
379+
urlTo: Joi.string().uri().optional(),
372380
title: Joi.string().optional(),
373381
urlsSuggested: Joi.array().items(Joi.string().uri()).optional(),
374382
aiRationale: Joi.string().optional(),
375383
trafficDomain: Joi.number().optional(),
376384
priority: Joi.string().optional(),
377385
aggregationKey: Joi.string().allow(null).optional(),
378-
}).unknown(true),
386+
})
387+
.or('url_from', 'urlFrom') // At least one of these must be present
388+
.or('url_to', 'urlTo') // At least one of these must be present
389+
.unknown(true),
379390
projections: {
380391
minimal: {
381-
fields: ['urlFrom', 'urlTo'],
392+
fields: ['url_from', 'url_to', 'urlFrom', 'urlTo'],
382393
transformers: {},
383394
},
384395
},

packages/spacecat-shared-data-access/src/models/suggestion/suggestion.projection-utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export const FALLBACK_PROJECTION = {
104104
'path',
105105
'sourceUrl',
106106
'destinationUrl',
107+
'trendData', // Web Performance Trends: [{ date, good, needsImprovement, poor }] for header cards
107108
],
108109
transformers: {},
109110
},

packages/spacecat-shared-data-access/test/unit/models/suggestion/suggestion.projection-utils.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,9 @@ describe('Suggestion Projection Utils', () => {
157157
expect(fields).to.not.include('issues');
158158
});
159159

160-
it('has exactly 14 URL-related fields', () => {
161-
expect(FALLBACK_PROJECTION.minimal.fields).to.have.lengthOf(14);
160+
it('has expected URL-related and trend fields', () => {
161+
expect(FALLBACK_PROJECTION.minimal.fields).to.have.lengthOf(15);
162+
expect(FALLBACK_PROJECTION.minimal.fields).to.include('trendData');
162163
});
163164
});
164165
});

0 commit comments

Comments
 (0)