import { EventBus, EventName } from "../events/event-bus"; export declare class AjaxApiPublisher { private readonly eventBus; private readonly eventMap; private previousCart; private pendingCartMutations; constructor(eventBus: EventBus); /** * Registers a cart mutation as in flight from the moment it is dispatched * until its response has been processed, and returns the function that * clears it. Requests that are not cart mutations are ignored. * * This is what stops a plain `/cart.js` read that resolves mid-mutation from * replacing the snapshot the mutation will be diffed against — see * `snapshotCart` and SWI-2836. */ beginRequest(request: Request): (() => void) | void; processFetchResponse(response: Response, request: Request): Promise; getEventName(url: string): EventName | null; /** * A cart read that resolves while a mutation is in flight can already reflect * that mutation, and adopting it would leave the mutation diffing against a * cart the removal has happened in — nothing looks removed. The mutation's * own response is the next snapshot; reads wait their turn. * * `/cart/change.js` no longer depends on this, since `diffRemovedItems` reads * Shopify's `items_removed` first. `/cart/update.js` has no such field, so * the snapshot is all it has. */ private snapshotCart; /** * `/cart/change.js` reports its own removals in `items_removed`, so that is * the authoritative answer and it is read first. * * Leading with the snapshot diff instead loses the removal whenever another * script's `/cart.js` read lands between the removal request and its response * (an abandoned-cart app polling the cart is enough): `snapshotCart` has * already replaced `previousCart` with the post-removal cart, so the diff * finds nothing gone and the shopper is never offered the save — SWI-2836. * * `/cart/update.js` omits the field entirely, so an *absent* `items_removed` * is what selects the snapshot diff. An empty array is Shopify telling us * nothing was removed, and is not second-guessed. * * Both branches match on the cart line, never on `variant_id`. Shopify lists * a quantity *decrease* in `items_removed` too, naming the line that survived * it; a line the shopper deleted names a line the cart no longer has. Keying * off `variant_id` instead drops a deleted line whenever another line still * holds that variant — two lines of one variant separated by line item * properties (gift wrap, engraving, a selling plan) — and the shopper is * offered nothing for a deletion they just made. * * Verified against the live Ajax API (2026-09-16): an `items_removed` entry * carries the line key as `view_key` and has no `key` of its own, and a * 2 → 1 quantity change reports the surviving line's key there. * `/cart/update.js` returns no `items_removed`, and its `items_changelog` * carries `added` only — the snapshot really is all that path has. */ private diffRemovedItems; private toCartChangeItem; }