Skip to content

feat: added new smarthint product listing loader#1571

Open
aline-pereira wants to merge 1 commit intomainfrom
feat/smarthint-loader
Open

feat: added new smarthint product listing loader#1571
aline-pereira wants to merge 1 commit intomainfrom
feat/smarthint-loader

Conversation

@aline-pereira
Copy link
Copy Markdown
Contributor

@aline-pereira aline-pereira commented Apr 9, 2026

What is this Contribution About?

Please provide a brief description of the changes or enhancements you are proposing in this pull request.

Issue Link

Please link to the relevant issue that this pull request addresses:

Loom Video

Record a quick screencast describing your changes to help the team understand and review your contribution. This will greatly assist in the review process.

Demonstration Link

Provide a link to a branch or environment where this pull request can be tested and seen in action.


Summary by cubic

Adds a SmartHint product list loader that builds a Product[] from recommendations by page and position. This enables ProductShelf to show SmartHint-driven products with filters, categories, and session awareness.

  • New Features

    • Added smarthint/loaders/productList.ts calling /recommendationByPage/withProducts, flattening products from Products, Promotional, and Combination combos, and returning Product[] | null. Registered in smarthint/manifest.gen.ts.
  • Refactors

    • Exported getProductParam from smarthint/loaders/recommendations.ts for reuse.

Written for commit 4d64c76. Summary will update on new commits.

Summary by CodeRabbit

  • New Features
    • Added a new product list loader that enables fetching product recommendations configured per page. The loader supports filtering by position, categories, and product parameters, aggregating results from multiple recommendation sources.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 2026

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.144.3 update
  • 🎉 for Minor 0.145.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new SmartHint product list loader (productList.ts) that fetches recommendations from the SmartHint API and aggregates products from multiple response categories. Additionally, it exports the getProductParam helper function from the recommendations module and registers the new loader in the manifest.

Changes

Cohort / File(s) Summary
New Product List Loader
smarthint/loaders/productList.ts
New loader module that accepts position, pagetype, categories, filters, and products as inputs. Calls SmartHint recommendations API, parses response, locates matching position entry, and aggregates products from RecommendationsProducts, RecommendationsPromotional, and RecommendationsCombination entries, converting each via toProduct helper.
Utility and Manifest Updates
smarthint/loaders/recommendations.ts, smarthint/manifest.gen.ts
Exports the getProductParam helper function for reuse, and registers the new productList loader in the manifest's loaders mapping.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • fix smarthing productListingPage #1547: Modifies smarthint/utils/transform.ts (specifically the toProduct function) which is directly used by the new product list loader for product conversion.

Suggested reviewers

  • aka-sacci-ccr
  • nicacioliveira

Poem

🐰 A loader hops with SmartHint cheer,
Gathering products far and near,
Positions matched, and combos too,
Manifest's blessed with something new!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description includes the template structure but lacks critical required information: no issue link, Loom video, or demonstration link are provided by the author. Complete the description template by providing an issue link, recording a Loom video demonstration, and including a demonstration link for testing.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a new SmartHint product listing loader module.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/smarthint-loader

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@smarthint/loaders/productList.ts`:
- Around line 70-84: The code calls recs["GET
/recommendationByPage/withProducts"] and immediately parses and uses the
response as an array (variable data) then runs .find to create positionItem; to
harden this, first capture the raw response, check response.ok and handle non-OK
(log/throw or return an empty result), then attempt to parse JSON inside a
try/catch to handle invalid JSON, and after parsing validate Array.isArray(data)
before calling .find (if not an array, set data = [] or handle accordingly).
Update the call site around recs["GET /recommendationByPage/withProducts"], the
parsing step that assigns data, and the subsequent creation of positionItem to
follow these guards.

In `@smarthint/loaders/recommendations.ts`:
- Around line 38-41: Reformat the declaration of getProductParam to match deno
fmt: run deno fmt and update the function signature/spacing so it matches the
formatter's output (ensure parameter spacing and placement of the opening brace
follow deno fmt conventions for export function getProductParam(pagetype:
ComplexPageType, productsParam: string[])). After running deno fmt, commit the
updated signature so CI passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 832ffeda-0a19-41a9-88e2-37fd67c02465

📥 Commits

Reviewing files that changed from the base of the PR and between a07ef6c and 4d64c76.

📒 Files selected for processing (3)
  • smarthint/loaders/productList.ts
  • smarthint/loaders/recommendations.ts
  • smarthint/manifest.gen.ts

Comment on lines +70 to +84
const data = await recs["GET /recommendationByPage/withProducts"]({
shcode,
anonymous,
categories,
channel,
filter: filters,
pageIdentifier,
pagetype: pagetype.type,
position,
products: productsString,
}).then((r) => r.json());

const positionItem = data.find((item) =>
Number(item.SmartHintPosition) == Number(position)
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Guard external response before parsing and .find().

This path assumes a successful JSON array response. A non-OK status, invalid JSON, or non-array payload will throw and break the loader.

🛡️ Suggested hardening
-  const data = await recs["GET /recommendationByPage/withProducts"]({
+  const response = await recs["GET /recommendationByPage/withProducts"]({
     shcode,
     anonymous,
     categories,
     channel,
     filter: filters,
     pageIdentifier,
     pagetype: pagetype.type,
     position,
     products: productsString,
-  }).then((r) => r.json());
+  });
+
+  if (!response.ok) return null;
+
+  let data: unknown;
+  try {
+    data = await response.json();
+  } catch {
+    return null;
+  }
+  if (!Array.isArray(data)) return null;
 
   const positionItem = data.find((item) =>
     Number(item.SmartHintPosition) == Number(position)
   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const data = await recs["GET /recommendationByPage/withProducts"]({
shcode,
anonymous,
categories,
channel,
filter: filters,
pageIdentifier,
pagetype: pagetype.type,
position,
products: productsString,
}).then((r) => r.json());
const positionItem = data.find((item) =>
Number(item.SmartHintPosition) == Number(position)
);
const response = await recs["GET /recommendationByPage/withProducts"]({
shcode,
anonymous,
categories,
channel,
filter: filters,
pageIdentifier,
pagetype: pagetype.type,
position,
products: productsString,
});
if (!response.ok) return null;
let data: unknown;
try {
data = await response.json();
} catch {
return null;
}
if (!Array.isArray(data)) return null;
const positionItem = data.find((item) =>
Number(item.SmartHintPosition) == Number(position)
);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@smarthint/loaders/productList.ts` around lines 70 - 84, The code calls
recs["GET /recommendationByPage/withProducts"] and immediately parses and uses
the response as an array (variable data) then runs .find to create positionItem;
to harden this, first capture the raw response, check response.ok and handle
non-OK (log/throw or return an empty result), then attempt to parse JSON inside
a try/catch to handle invalid JSON, and after parsing validate
Array.isArray(data) before calling .find (if not an array, set data = [] or
handle accordingly). Update the call site around recs["GET
/recommendationByPage/withProducts"], the parsing step that assigns data, and
the subsequent creation of positionItem to follow these guards.

Comment on lines +38 to 41
export function getProductParam(pagetype: ComplexPageType, productsParam: string[]) {
if (productsParam.length) {
return productsParam.map((productId) => `productid:${productId}`).join("&");
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix formatting for getProductParam declaration to unblock CI.

deno fmt --check is failing on this declaration; reformat this signature exactly as deno fmt expects.

💡 Suggested patch
-export function getProductParam(pagetype: ComplexPageType, productsParam: string[]) {
+export function getProductParam(
+  pagetype: ComplexPageType,
+  productsParam: string[],
+) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export function getProductParam(pagetype: ComplexPageType, productsParam: string[]) {
if (productsParam.length) {
return productsParam.map((productId) => `productid:${productId}`).join("&");
}
export function getProductParam(
pagetype: ComplexPageType,
productsParam: string[],
) {
if (productsParam.length) {
return productsParam.map((productId) => `productid:${productId}`).join("&");
}
🧰 Tools
🪛 GitHub Actions: ci

[error] 38-41: deno fmt --check failed. Found 1 not formatted file in 2112 files. Formatting diff indicates function declaration 'getProductParam' needs reformatting (parameter list spanning multiple lines).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@smarthint/loaders/recommendations.ts` around lines 38 - 41, Reformat the
declaration of getProductParam to match deno fmt: run deno fmt and update the
function signature/spacing so it matches the formatter's output (ensure
parameter spacing and placement of the opening brace follow deno fmt conventions
for export function getProductParam(pagetype: ComplexPageType, productsParam:
string[])). After running deno fmt, commit the updated signature so CI passes.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant