Skip to content

add: Passar o segmento via props#1516

Open
devdaniloWicomm wants to merge 18 commits intodeco-cx:mainfrom
devdaniloWicomm:main
Open

add: Passar o segmento via props#1516
devdaniloWicomm wants to merge 18 commits intodeco-cx:mainfrom
devdaniloWicomm:main

Conversation

@devdaniloWicomm
Copy link

@devdaniloWicomm devdaniloWicomm commented Jan 19, 2026

Ajuste em passar o segmento via props, por conta que quando loga puxa do seguemento 1, sendo que está configurado o 7 no admin. Tendo a opção de passar via props, resolver esse problema.

image

Summary by CodeRabbit

  • New Features

    • Cart actions now accept an optional channel override (sc) across simulation, add/remove/update items, coupons, attachments, installments, profile and user updates.
    • New config flag allowMixedSegments to control segment-based channel selection.
  • Bug Fixes

    • Cart endpoints now consistently return parsed JSON responses.
    • Channel selection fallback behavior standardized when no override is provided.

@github-actions
Copy link
Contributor

Tagging Options

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

  • 👍 for Patch 0.133.26 update
  • 🎉 for Minor 0.134.0 update
  • 🚀 for Major 1.0.0 update

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds optional sc?: string to many cart action Props, threads conditional sc resolution using ctx.allowMixedSegments and segment?.payload.channel with fallback to ctx.salesChannel, adjusts some API call argument shapes, adds typed Props/function signatures and returns response.json(), and adds allowMixedSegments?: boolean to vtex/mod.ts.

Changes

Cohort / File(s) Summary
Cart actions — sc prop added & conditional resolution
vtex/actions/cart/simulation.ts, vtex/actions/cart/addItems.ts, vtex/actions/cart/getInstallment.ts, vtex/actions/cart/removeItemAttachment.ts, vtex/actions/cart/removeItems.ts, vtex/actions/cart/updateAttachment.ts, vtex/actions/cart/updateCoupons.ts, vtex/actions/cart/updateItemAttachment.ts, vtex/actions/cart/updateItemPrice.ts, vtex/actions/cart/updateItems.ts, vtex/actions/cart/updateProfile.ts, vtex/actions/cart/updateUser.ts
Added sc?: string to Props and updated each action to compute sc as sc ?? (ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel) (or equivalent conditional).
Function signatures, exports & JSON returns
vtex/actions/cart/removeItems.ts, vtex/actions/cart/updateUser.ts, vtex/actions/cart/getInstallment.ts, vtex/actions/cart/removeItemAttachment.ts, ...
Several actions changed from _props: unknown to props: Props, now destructure sc, some files add export default action, and many now return response.json().
API call / request payload shape adjustments
vtex/actions/cart/addItems.ts, vtex/actions/cart/updateItemAttachment.ts, vtex/actions/cart/updateItems.ts, vtex/actions/cart/updateCoupons.ts, vtex/actions/cart/updateItemPrice.ts
Reordered/adjusted vcsDeprecated/vcs call argument grouping to include computed sc in the request object; body/headers and cookie proxy handling preserved but restructured in places.
Module config update
vtex/mod.ts
Added allowMixedSegments?: boolean to exported Props and minor formatting/type annotation edits.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant Action as Cart Action
  participant Context as AppContext (ctx)
  participant Segment as Segment
  participant API as VTEX API

  Client->>Action: invoke action(props including optional sc)
  Action->>Context: read ctx.allowMixedSegments, ctx.salesChannel
  Action->>Segment: read segment?.payload.channel
  alt sc provided
    Action->>API: call API with sc (props.sc)
  else sc not provided and ctx.allowMixedSegments true
    Action->>API: call API with sc = segment?.payload.channel
  else
    Action->>API: call API with sc = ctx.salesChannel
  end
  API-->>Action: response
  Action-->>Client: return response.json()
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • guitavano

Poem

🐰 I found a tiny sc in the hay,
I threaded it gentle through routes today.
If you pass it, I follow your cue,
If not, segments or salesChannel guide through.
Hop—cookies and headers—off they hop hooray!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description lacks required sections from the template: no 'What is this Contribution About' structured section, no 'Issue Link', no 'Loom Video', and no 'Demonstration Link' - only a brief explanation and an image. Add all required template sections: structured 'What is this Contribution About', link to relevant issue #, Loom video recording, and demonstration/testing environment link.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title in Portuguese 'Passar o segmento via props' accurately describes the main change: adding functionality to pass the segment via props to multiple cart actions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
vtex/actions/cart/updateProfile.ts (1)

33-37: sc resolution logic is correct but duplicated across all cart actions.

The previous operator-precedence bug is fixed. The sc ? sc : fallback pattern correctly prioritizes an explicit sc prop. However, this exact expression is copy-pasted verbatim in at least 7 files. Consider extracting it into a shared helper to reduce duplication and make future changes (e.g., adding logging or validation) a single-point edit.

♻️ Suggested helper (e.g., in vtex/utils/segment.ts)
export const resolveSalesChannel = (
  sc: string | undefined,
  ctx: AppContext,
  segment: WrappedSegment | undefined,
): string | undefined =>
  sc
    ? sc
    : ctx.allowMixedSegments
      ? segment?.payload.channel
      : ctx.salesChannel;

Then each action becomes:

-      sc:
-        sc ? sc :
-        (ctx.allowMixedSegments
-          ? segment?.payload.channel
-          : ctx.salesChannel),
+      sc: resolveSalesChannel(sc, ctx, segment),
vtex/actions/cart/updateAttachment.ts (1)

47-51: Minor: Inconsistent indentation in the ternary.

The ? and : of the inner ternary are not aligned, unlike the other cart action files. Not a functional issue, but hurts readability when scanning across the batch of changes.

🔧 Suggested formatting alignment
      sc:
        sc ? sc :
        (ctx.allowMixedSegments
-        ? segment?.payload.channel
-          : ctx.salesChannel),
+          ? segment?.payload.channel
+          : ctx.salesChannel),

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.

devdaniloWicomm and others added 2 commits January 22, 2026 15:54
Co-authored-by: Gabriel Matos Boubee <108771428+gabrielMatosBoubee@users.noreply.github.com>
Copy link

@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.

1 issue found across 2 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="vtex/actions/cart/simulation.ts">

<violation number="1" location="vtex/actions/cart/simulation.ts:39">
P0: Operator precedence bug: the nullish coalescing operator (`??`) has higher precedence than the ternary operator (`?:`), so this expression is evaluated as `(sc ?? ctx.allowMixedSegments) ? ... : ...` instead of `sc ?? (... ? ... : ...)`. When `sc` is provided, it will be used as the ternary condition rather than as the actual `sc` value, which defeats the entire purpose of this PR. Add parentheses to fix the precedence.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
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

🤖 Fix all issues with AI agents
In `@vtex/actions/cart/addItems.ts`:
- Around line 33-46: The call to vcsDeprecated POST uses sc fallback that misses
ctx.salesChannel, so update the sc argument in addItems (where props.sc is read)
to use sc ?? segment?.payload.channel ?? ctx.salesChannel (matching
simulation.ts) to ensure a sales channel is always sent; also update the
Props.sc typing or coerce it to a number before passing to vcsDeprecated to
align with the VTEX OpenAPI expectation.
- Around line 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.

Comment on lines 16 to 20
export interface Props {
orderItems: Item[];
allowedOutdatedData?: Array<"paymentData">;
sc?: string;
}
Copy link
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.

Copy link
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: 8

🤖 Fix all issues with AI agents
In `@vtex/actions/cart/addItems.ts`:
- Around line 45-48: The ternary currently uses (sc ?? ctx.allowMixedSegments)
as the condition which ignores an explicit sc value; change the expression so sc
is used when defined by applying the nullish coalescing first and only falling
back to the conditional on ctx.allowMixedSegments, e.g. replace the existing
ternary with sc ?? (ctx.allowMixedSegments ? segment?.payload.channel :
ctx.salesChannel) so that explicit sc values are returned and only when sc is
null/undefined the allowMixedSegments branch selects segment?.payload.channel or
ctx.salesChannel.

In `@vtex/actions/cart/getInstallment.ts`:
- Around line 34-37: The current assignment for sc incorrectly uses the ternary
with the nullish coalescing, causing an explicitly provided sc to be ignored;
change the expression so sc is used when defined and only fall back to choosing
between segment?.payload.channel and ctx.salesChannel based on
ctx.allowMixedSegments (i.e. use sc ?? (ctx.allowMixedSegments ?
segment?.payload.channel : ctx.salesChannel)), updating the sc assignment in
getInstallment.ts where sc, ctx.allowMixedSegments, segment?.payload.channel and
ctx.salesChannel are referenced.

In `@vtex/actions/cart/removeItemAttachment.ts`:
- Around line 65-68: The ternary uses (sc ?? ctx.allowMixedSegments) as the
condition so a provided sc never becomes the returned value; change the
expression to prefer sc first and only if sc is null/undefined evaluate the
existing branch — e.g. replace the current expression with one that returns sc
when defined, otherwise returns ctx.allowMixedSegments ?
segment?.payload.channel : ctx.salesChannel; update the assignment for sc in the
same scope where sc, ctx.allowMixedSegments, segment?.payload.channel and
ctx.salesChannel are referenced.

In `@vtex/actions/cart/updateAttachment.ts`:
- Around line 47-50: The current expression uses the ternary before the nullish
coalescing so a provided sc is effectively ignored; change the logic so sc is
used when defined, otherwise evaluate the ternary based on
ctx.allowMixedSegments to pick between segment?.payload.channel and
ctx.salesChannel (i.e., make the ternary the RHS fallback of the sc nullish
coalescing). Update the expression in updateAttachment.ts where sc,
ctx.allowMixedSegments, segment?.payload.channel and ctx.salesChannel are
referenced to ensure sc wins when present and the ternary only applies as the
fallback.

In `@vtex/actions/cart/updateCoupons.ts`:
- Around line 33-36: The sc assignment uses (sc ?? ctx.allowMixedSegments) ? ...
: ... which causes an operator-precedence bug that ignores an explicitly
provided sc; update the expression in updateCoupons.ts so the nullish-coalescing
applies to the entire ternary result, e.g. replace the current line with: sc ??
(ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel) to ensure
explicit sc is honored (referencing the sc variable, ctx.allowMixedSegments,
segment?.payload.channel and ctx.salesChannel).

In `@vtex/actions/cart/updateItemAttachment.ts`:
- Around line 58-69: The request currently ignores an explicit sc value because
the ternary tests sc for truthiness but always returns segment?.payload.channel;
update the sc parameter in the POST call to use the explicit sc first (if
provided), otherwise fall back to the existing behavior: if
ctx.allowMixedSegments is true use segment?.payload.channel, else use
ctx.salesChannel; adjust the sc expression in the vcsDeprecated["POST
/api/checkout/..."] call accordingly so passing sc="7" will be honored.

In `@vtex/actions/cart/updateItemPrice.ts`:
- Around line 35-38: The ternary is being parsed with the ?? operator
incorrectly so the explicit property sc is ignored; fix the expression in
updateItemPrice.ts by wrapping the nullish-coalescing check in an extra set of
parentheses before the ? operator (i.e. ensure the right-hand side of the sc:
property is ((sc ?? ctx.allowMixedSegments) ? segment?.payload.channel :
ctx.salesChannel)), so the decision uses (sc ?? ctx.allowMixedSegments) as
intended; update the expression that references sc, ctx.allowMixedSegments,
segment?.payload.channel and ctx.salesChannel accordingly.

In `@vtex/actions/cart/updateProfile.ts`:
- Around line 33-36: The ternary is affected by operator-precedence with ?? so
an explicit sc value gets ignored; replace the current left-hand expression with
an explicit presence check—use (typeof sc !== 'undefined' ? sc :
ctx.allowMixedSegments) as the condition in the ternary that sets sc, i.e.
update the expression that currently uses (sc ?? ctx.allowMixedSegments) ?
segment?.payload.channel : ctx.salesChannel to use the typeof check so sc is
honored correctly.
🧹 Nitpick comments (2)
vtex/actions/cart/simulation.ts (1)

11-17: Align sc type with other cart actions.

Other actions (and segment payloads) treat sc as a string; using number here forces casts and drifts the API. Consider using string (or string | number) for consistency.

♻️ Suggested type alignment
-  sc?: number;
+  sc?: string;
vtex/actions/cart/updateUser.ts (1)

16-23: Guard against undefined props for backward compatibility.

This action previously required no props. If it’s invoked without props, destructuring will throw. Consider defaulting to {}.

🛡️ Suggested guard
-  const { sc } = props;
+  const { sc } = props ?? {};

Copy link
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

🤖 Fix all issues with AI agents
In `@vtex/actions/cart/removeItems.ts`:
- Around line 32-35: The current ternary in removeItems treats a provided sc as
a boolean and returns segment?.payload.channel instead of the sc value; change
the expression so when sc is supplied it is used directly, otherwise fall back
to ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel (e.g.
use sc ?? (ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel)
or an equivalent conditional) to ensure the provided sc overrides the other
branches.

In `@vtex/actions/cart/updateUser.ts`:
- Around line 32-35: The ternary currently only checks sc for truthiness but
never returns it; change the expression to return sc when present (e.g., use the
nullish-coalescing pattern) so sc is passed through: replace the current block
that computes sc with something like sc ?? (ctx.allowMixedSegments ?
segment?.payload.channel : ctx.salesChannel), ensuring sc is used directly when
defined and falling back to segment?.payload.channel or ctx.salesChannel
otherwise.

devdaniloWicomm and others added 10 commits February 3, 2026 09:04
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
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: 1

🤖 Fix all issues with AI agents
In `@vtex/actions/cart/removeItemAttachment.ts`:
- Line 15: The sc query param is typed incorrectly as number; change its
declaration from sc?: number to sc?: string in the cart remove-item attachment
action (look for the sc field in the request/params interface in
removeItemAttachment.ts) so it matches other cart actions (updateProfile.ts,
updateUser.ts, updateItemPrice.ts) and the VTEX API; after changing the type,
run typechecks to ensure callers passing string values like "7" compile without
errors and update any tests or mock objects that declared sc as a number.

devdaniloWicomm and others added 2 commits February 4, 2026 16:12
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

@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.

1 issue found across 12 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="vtex/actions/cart/getInstallment.ts">

<violation number="1" location="vtex/actions/cart/getInstallment.ts:35">
P2: Using a truthy check for `sc` changes behavior vs the previous nullish fallback. If callers pass an explicit but falsy value (e.g., empty string), it will now be ignored and replaced by the fallback channel. Preserve nullish-coalescing semantics to avoid unintended channel overrides.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

orderFormId,
paymentSystem,
sc:
sc ? sc :
Copy link

@cubic-dev-ai cubic-dev-ai bot Feb 9, 2026

Choose a reason for hiding this comment

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

P2: Using a truthy check for sc changes behavior vs the previous nullish fallback. If callers pass an explicit but falsy value (e.g., empty string), it will now be ignored and replaced by the fallback channel. Preserve nullish-coalescing semantics to avoid unintended channel overrides.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At vtex/actions/cart/getInstallment.ts, line 35:

<comment>Using a truthy check for `sc` changes behavior vs the previous nullish fallback. If callers pass an explicit but falsy value (e.g., empty string), it will now be ignored and replaced by the fallback channel. Preserve nullish-coalescing semantics to avoid unintended channel overrides.</comment>

<file context>
@@ -32,8 +32,10 @@ const action = async (
       sc:
-        sc ??
-        (ctx.allowMixedSegments ? segment?.payload.channel : ctx.salesChannel),
+        sc ? sc :
+        (ctx.allowMixedSegments
+          ? segment?.payload.channel
</file context>
Suggested change
sc ? sc :
sc ??
(ctx.allowMixedSegments
? segment?.payload.channel
: ctx.salesChannel)
Fix with Cubic

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.

3 participants