Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
20 changes: 11 additions & 9 deletions vtex/actions/cart/addItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Item {
export interface Props {
orderItems: Item[];
allowedOutdatedData?: Array<"paymentData">;
sc?: string;
}
Comment on lines 16 to 20
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

🧩 Analysis chain

🏁 Script executed:

cat -n vtex/actions/cart/addItems.ts

Repository: deco-cx/apps

Length of output: 2284


🏁 Script executed:

fd . vtex/actions/cart -type f -name "*.ts" | head -20

Repository: deco-cx/apps

Length of output: 226


🏁 Script executed:

fd . vtex/actions/cart -type f -name "*.ts"

Repository: deco-cx/apps

Length of output: 226


🏁 Script executed:

git ls-files vtex/actions/cart/*.ts

Repository: deco-cx/apps

Length of output: 627


🏁 Script executed:

cat -n vtex/actions/cart/simulation.ts

Repository: deco-cx/apps

Length of output: 1796


🏁 Script executed:

rg -n "sc\?" vtex/actions/cart -A1 -B1

Repository: deco-cx/apps

Length of output: 365


🏁 Script executed:

rg -n "sc:" vtex/actions/cart -B2 -A2

Repository: deco-cx/apps

Length of output: 4285


🏁 Script executed:

cat -n vtex/utils/segment.ts | head -50

Repository: deco-cx/apps

Length of output: 1586


🏁 Script executed:

rg -n "interface Segment" vtex/utils/types.ts -A20

Repository: deco-cx/apps

Length of output: 778


🏁 Script executed:

rg -n "salesChannel" vtex/mod.ts -B5 -A5

Repository: deco-cx/apps

Length of output: 1017


🏁 Script executed:

rg -n "export interface Props" vtex/actions/cart -A10 | grep -E "(interface Props|sc\?)"

Repository: deco-cx/apps

Length of output: 994


Align sc type across cart actions to avoid type inconsistencies.

sc is typed as string in addItems.ts but simulation.ts accepts sc?: number. Both fallback to segment?.payload.channel (which is string). Standardizing to string | number with explicit String(...) coercion on send would prevent callers from hitting type errors when using similar actions with numeric values.

♻️ Suggested normalization
 export interface Props {
   orderItems: Item[];
   allowedOutdatedData?: Array<"paymentData">;
-  sc?: string;
+  sc?: string | number;
 }
@@
-        sc: sc ?? segment?.payload.channel,
+        sc: sc != null ? String(sc) : segment?.payload.channel,
🤖 Prompt for AI Agents
In `@vtex/actions/cart/addItems.ts` around lines 16 - 20, The Props interface's sc
field is currently typed inconsistently (sc?: string in the Props interface in
addItems.ts vs sc?: number in simulation.ts); change sc's type in the Props
interface to sc?: string | number to match across cart actions, and ensure any
place that sends sc (e.g., where the request payload is built / send call)
coerces it with String(sc) before transmission so callers can pass numeric or
string values without type errors; update any related usages of Props/sc to
accept the union type.


/**
Expand All @@ -29,28 +30,29 @@ const action = async (
ctx: AppContext,
): Promise<OrderForm> => {
const { vcsDeprecated } = ctx;
const {
orderItems,
allowedOutdatedData = ["paymentData"],
} = props;
const { orderItems, allowedOutdatedData = ["paymentData"], sc } = props;
const { orderFormId } = parseCookie(req.headers);
const cookie = req.headers.get("cookie") ?? "";
const segment = getSegmentFromBag(ctx);

try {
const response = await vcsDeprecated
["POST /api/checkout/pub/orderForm/:orderFormId/items"]({
const response = await vcsDeprecated[
"POST /api/checkout/pub/orderForm/:orderFormId/items"
](
{
orderFormId,
allowedOutdatedData,
sc: segment?.payload.channel,
}, {
sc: sc ?? segment?.payload.channel,
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
{
body: { orderItems },
headers: {
"content-type": "application/json",
accept: "application/json",
cookie,
},
});
},
);

proxySetCookie(response.headers, ctx.response.headers, req.url);

Expand Down
5 changes: 3 additions & 2 deletions vtex/actions/cart/simulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface Props {
postalCode: string;
country: string;
RnbBehavior?: 0 | 1;
sc?: number;
}

/**
Expand All @@ -27,15 +28,15 @@ const action = async (
): Promise<SimulationOrderForm> => {
const cookie = req.headers.get("cookie") ?? "";
const { vcsDeprecated } = ctx;
const { items, postalCode, country, RnbBehavior = 1 } = props;
const { items, postalCode, country, RnbBehavior = 1, sc } = props;
const segment = getSegmentFromBag(ctx);

const response = await vcsDeprecated[
"POST /api/checkout/pub/orderForms/simulation"
](
{
RnbBehavior,
sc: segment?.payload.channel,
sc: sc ?? ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
},
{
body: { items, country, postalCode },
Expand Down