> ## Documentation Index
> Fetch the complete documentation index at: https://docs.napps.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cart operations extension

The Cart Operations extension lets you inspect the current cart and return native cart mutations.

## Exported function

Export `onCartChanged` from the extension module:

```ts theme={null}
export function onCartChanged(
  cart: Cart
): CartOperation[] | Promise<CartOperation[]> {
  return [];
}
```

Use `CartOperations` to create the returned mutations. See [Cart operations](/cart-operations) and [Data models](/models).

## Execution behavior

* Native can invoke the hook repeatedly, up to three passes.
* Each pass receives the latest cart after previously returned operations are applied.
* Conflicting operations are suppressed by the native runner.
* Return an empty array when no change is needed.
* Async work must complete within the extension's three-second execution budget.

```ts theme={null}
import { CartOperations } from "@napps/component-extension";

export async function onCartChanged(cart: Cart) {
  const item = cart.lineItems.find((line) => line.product?.vendor === "Example");

  if (!item) {
    return [];
  }

  return [CartOperations.updateLineItem(item.id, undefined, undefined, 1)];
}
```

Keep the hook idempotent. Repeated passes should converge instead of continuously producing new operations.
