Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 34 additions & 46 deletions verified-reviews/utils/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
toReview,
} from "./transform.ts";
import { context } from "@deco/deco";

export type ClientVerifiedReviews = ReturnType<typeof createClient>;

export interface PaginationOptions {
count?: number;
offset?: number;
Expand Down Expand Up @@ -43,25 +45,28 @@
fullReview:
"🔴⭐ Error on call Full Review of Verified Review - probably unidentified product",
};

const baseUrl = "https://awsapis3.netreviews.eu/product";
const jsonHeaders = { "content-type": "application/json" };

export const createClient = (params: ConfigVerifiedReviews | undefined) => {
if (!params) {
return;
}
const { idWebsite } = params;

/** @description https://documenter.getpostman.com/view/2336519/SVzw6MK5#338f8f1b-4379-40a2-8893-080fe5234679 */
const rating = async ({ productId }: {
productId: string;
}) => {
const rating = async ({ productId }: { productId: string }) => {
const payload = {
query: "average",
products: [productId],
idWebsite: idWebsite,
idWebsite,
plateforme: "br",
};
try {
const data = await fetchAPI<Ratings>(`${baseUrl}`, {
method: "POST",
headers: jsonHeaders,
body: JSON.stringify(payload),
});
return Object.keys(data).length ? data : undefined;
Expand All @@ -74,19 +79,19 @@
return undefined;
}
};

/** @description https://documenter.getpostman.com/view/2336519/SVzw6MK5#6d8ab05a-28b6-48b3-9e8f-6bbbc046619a */
const ratings = async ({ productsIds }: {
productsIds: string[];
}) => {
const ratings = async ({ productsIds }: { productsIds: string[] }) => {
const payload = {
query: "average",
products: productsIds,
idWebsite: idWebsite,
idWebsite,
plateforme: "br",
};
try {
const data = await fetchAPI<Ratings>(`${baseUrl}`, {
method: "POST",
headers: jsonHeaders,
body: JSON.stringify(payload),
});
return Object.keys(data).length ? data : undefined;
Expand All @@ -100,19 +105,16 @@
return undefined;
}
};

/** @description https://documenter.getpostman.com/view/2336519/SVzw6MK5#daf51360-c79e-451a-b627-33bdd0ef66b8 */
const reviews = (
const reviews = async (

Check failure on line 110 in verified-reviews/utils/client.ts

View workflow job for this annotation

GitHub Actions / Bundle & Check Apps (ubuntu-latest)

Async arrow function has no 'await' expression or 'await using' declaration.

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 | 🟠 Major | ⚡ Quick win

Remove unnecessary async on reviews to clear the failing check

Line 110 declares reviews as async but returns fetchAPI(...) directly with no await, which matches the reported CI/static-analysis failure.

Suggested fix
-  const reviews = async (
+  const reviews = (
📝 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 reviews = async (
const reviews = (
🧰 Tools
🪛 GitHub Actions: ci / 0_Bundle & Check Apps (ubuntu-latest).txt

[error] 110-110: deno lint failed (require-await): Async arrow function has no 'await' expression or 'await using' declaration.

🪛 GitHub Actions: ci / Bundle & Check Apps (ubuntu-latest)

[error] 110-110: deno lint failed (require-await): Async arrow function has no 'await' expression or 'await using' declaration.

🪛 GitHub Check: Bundle & Check Apps (ubuntu-latest)

[failure] 110-110:
�[0m�[1mAsync arrow function has no 'await' expression or 'await using' declaration.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@verified-reviews/utils/client.ts` at line 110, The `reviews` function is
declared as `async` but does not contain any `await` expressions, which causes a
CI/static-analysis failure. Remove the `async` keyword from the `reviews`
function declaration since it directly returns the result of `fetchAPI(...)`
without awaiting any asynchronous operations. This will align the function
signature with its actual behavior and clear the failing check.

Source: Linters/SAST tools

{
productId,
count = 5,
offset = 0,
order: _order = "date_desc",
customizeOrder = false,
}:
& PaginationOptions
& {
productId: string | string[];
},
}: PaginationOptions & { productId: string | string[] },
) => {
const order = customizeOrder
? _order
Expand All @@ -121,15 +123,16 @@
const payload = {
query: "reviews",
product: Array.isArray(productId) ? productId : [productId],
idWebsite: idWebsite,
idWebsite,
plateforme: "br",
offset: offset,
offset,
limit: count,
order: order,
order,
};

return fetchAPI<Reviews[]>(`${baseUrl}`, {
method: "POST",
headers: jsonHeaders,
body: JSON.stringify(payload),
});
};
Expand All @@ -145,51 +148,40 @@
try {
const isMultiProduct = Array.isArray(productId);

const response = await Promise.all([
ratings({
productsIds: isMultiProduct ? productId : [productId],
}),
const [responseRating, responseReviews] = await Promise.all([
ratings({ productsIds: isMultiProduct ? productId : [productId] }),
reviews({ productId, count, offset, order }),
]);
const [responseRating, responseReview] = response.flat() as [
Ratings,
Reviews | null,
];
]) as [Ratings | undefined, Reviews[]];

const responseReview = responseReviews?.[0];

const aggregateRating = isMultiProduct
? getWeightedRatingProduct(responseRating)
: getRatingProduct({ ratings: responseRating, productId });

return {
aggregateRating: aggregateRating
? {
...aggregateRating,
stats: responseReview?.stats,
}
? { ...aggregateRating, stats: responseReview?.stats }
: undefined,
review: responseReview ? responseReview.reviews?.map(toReview) : [],
};
} catch (error) {
if (context.isDeploy) {
console.error(MessageError.ratings, error);
console.error(MessageError.fullReview, error);
} else {
throw new Error(`${MessageError.fullReview} - ${error}`);
}
return {
aggregateRating: undefined,
review: [],
};
return { aggregateRating: undefined, review: [] };
}
};

const storeReview = async (): Promise<Reviews["reviews"] | null> => {
try {
const response = await fetchAPI<Reviews["reviews"]>(
`https://cl.avis-verifies.com/br/cache/8/6/a/${idWebsite}/AWS/WEBSITE_API/reviews.json`,
{
method: "GET",
},
{ method: "GET" },
);
return (response ? response : []);
return response ?? [];
} catch (error) {
if (context.isDeploy) {
console.error(MessageError.ratings, error);
Expand All @@ -199,13 +191,9 @@
return null;
}
};
return {
rating,
ratings,
reviews,
fullReview,
storeReview,
};

return { rating, ratings, reviews, fullReview, storeReview };
};

export const getProductId = (product: Product) =>
product.isVariantOf!.productGroupID;
Loading