@vio-live/web-sdk 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +19 -4
- package/dist/{chunk-C5Q6W4B2.js → chunk-T5B74YBQ.js} +46 -8
- package/dist/chunk-T5B74YBQ.js.map +1 -0
- package/dist/{chunk-IR4XYTZL.js → chunk-ZORYG4W3.js} +668 -98
- package/dist/chunk-ZORYG4W3.js.map +1 -0
- package/dist/core/index.d.ts +759 -568
- package/dist/core/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +3 -3
- package/dist/{tokens-D1DCVzOf.d.ts → tokens-B7GVA_qB.d.ts} +14 -0
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +3 -3
- package/package.json +1 -1
- package/dist/chunk-C5Q6W4B2.js.map +0 -1
- package/dist/chunk-IR4XYTZL.js.map +0 -1
package/dist/core/index.d.ts
CHANGED
|
@@ -627,6 +627,15 @@ interface SponsorCartState {
|
|
|
627
627
|
currency: string;
|
|
628
628
|
/** Backend (Vio Commerce) cart id, once created. */
|
|
629
629
|
cartId?: string;
|
|
630
|
+
/**
|
|
631
|
+
* The commerce channel the backend cart was created on (the sponsor's
|
|
632
|
+
* block for the campaign the first line came from). Every later cart and
|
|
633
|
+
* checkout call for this cart uses THAT channel's key; when the bootstrap
|
|
634
|
+
* no longer lists it, the cart is created again on the current channel with
|
|
635
|
+
* its lines. Absent on carts created before 0.33 (they keep the sponsor's
|
|
636
|
+
* first block, as then, and learn it on the next call).
|
|
637
|
+
*/
|
|
638
|
+
channelId?: string;
|
|
630
639
|
shippingCountry?: string;
|
|
631
640
|
subtotal?: number;
|
|
632
641
|
shipping?: number;
|
|
@@ -634,393 +643,88 @@ interface SponsorCartState {
|
|
|
634
643
|
}
|
|
635
644
|
|
|
636
645
|
/**
|
|
637
|
-
*
|
|
646
|
+
* What the commerce gateway may not know yet.
|
|
638
647
|
*
|
|
639
|
-
*
|
|
640
|
-
*
|
|
641
|
-
*
|
|
642
|
-
*
|
|
648
|
+
* The SDK ships ahead of the gateway more than once a quarter: a selection
|
|
649
|
+
* (`buyer_ref`, 2026-10-19), an argument (`origin` on the cart lines,
|
|
650
|
+
* `attribution` on the checkout — ADR-0035 phase B). A gateway that does not
|
|
651
|
+
* have the field refuses the WHOLE operation at validation — before anything
|
|
652
|
+
* runs, with no `data` — so each such operation is sent again without the
|
|
653
|
+
* field, once, and the answer remembered for the page load. An operation that
|
|
654
|
+
* DID run and failed is never repeated: for a mutation that would be a second
|
|
655
|
+
* charge, a second line in the cart.
|
|
643
656
|
*
|
|
644
|
-
*
|
|
645
|
-
*
|
|
646
|
-
|
|
647
|
-
|
|
657
|
+
* One mechanism for all of them, so the next field costs a token here and a
|
|
658
|
+
* call to `withGatewayFeature`, not a new copy of the retry.
|
|
659
|
+
*/
|
|
660
|
+
type GatewayFeature = 'buyer_ref' | 'line_origin' | 'checkout_attribution';
|
|
661
|
+
/** Whether this page load still expects the gateway to know `feature` (false once it refused it). */
|
|
662
|
+
declare function gatewayHas(feature: GatewayFeature): boolean;
|
|
663
|
+
/** Forget what this page load learned (tests). One feature, or all of them. */
|
|
664
|
+
declare function resetGatewayFeatures(feature?: GatewayFeature): void;
|
|
665
|
+
/**
|
|
666
|
+
* True when `err` is the gateway refusing something it does not know, named
|
|
667
|
+
* `token` (`Cannot query field "buyer_ref" on type …`, `Unknown argument
|
|
668
|
+
* "origin" on field …`, `Unknown type "CartLineOriginInput"`, `Field "origin" is
|
|
669
|
+
* not defined by type "LineItemInput"`): a validation error, with no `data`
|
|
670
|
+
* and no `path` because nothing ran — safe to send again without it, a
|
|
671
|
+
* mutation included. Anything that ran (data present, or an error with a
|
|
672
|
+
* path) or any other message is not.
|
|
673
|
+
*/
|
|
674
|
+
declare function isUnknownTokenError(err: unknown, token: string): boolean;
|
|
675
|
+
/** `isUnknownTokenError` for any of the names a feature goes by. */
|
|
676
|
+
declare function isUnknownFeatureError(err: unknown, feature: GatewayFeature): boolean;
|
|
677
|
+
/**
|
|
678
|
+
* Runs `request(true)` (the operation with the feature); when the gateway
|
|
679
|
+
* does not know it, `request(false)` (without it) — and from then on, for
|
|
680
|
+
* this page load, straight to the latter. Said once in the console: a
|
|
681
|
+
* gateway behind the SDK is worth knowing about, and so is a renamed type.
|
|
648
682
|
*/
|
|
683
|
+
declare function withGatewayFeature<T>(feature: GatewayFeature, request: (supported: boolean) => Promise<T>): Promise<T>;
|
|
649
684
|
|
|
650
|
-
interface CartChangeDetail {
|
|
651
|
-
cartsBySponsor: Map<number, SponsorCartState>;
|
|
652
|
-
itemCount: number;
|
|
653
|
-
}
|
|
654
685
|
/**
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
*
|
|
658
|
-
* (`
|
|
659
|
-
*
|
|
686
|
+
* A line origin as Commerce receives it (ADR-0035 phase B): `origin` on each
|
|
687
|
+
* line of `AddItem` and, when the quantity goes UP, on `UpdateItem` — the
|
|
688
|
+
* origin of the units that update adds. shopcart keeps every origin of a
|
|
689
|
+
* line with its units (`cart_item.origins`) and writes the order from them:
|
|
690
|
+
* `order_item.campaign_id` / `location_id` / `component_kind`, and the
|
|
691
|
+
* order's page when the checkout does not name one.
|
|
692
|
+
*
|
|
693
|
+
* snake_case on the wire, the caps of shopcart's `LineOriginDto` enforced
|
|
694
|
+
* here, once. Pure: `lineOriginWire()` takes the origin and the page.
|
|
660
695
|
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
product: Product;
|
|
672
|
-
sponsorId: number;
|
|
673
|
-
sponsorName?: string;
|
|
674
|
-
quantity?: number;
|
|
675
|
-
variantId?: number;
|
|
676
|
-
/** Where these units come from (`Vio.attribution(slot)`); see `CartOrigin`. */
|
|
677
|
-
origin?: CartOrigin;
|
|
696
|
+
|
|
697
|
+
/** The largest `Int` GraphQL coerces; a bigger id would fail the whole mutation. */
|
|
698
|
+
declare const GRAPHQL_INT_MAX = 2147483647;
|
|
699
|
+
/** `LineOriginDto` (shopcart `cart/dtos/send/line-origin.dto.ts`). */
|
|
700
|
+
interface LineOriginWire {
|
|
701
|
+
campaign_id?: number;
|
|
702
|
+
location_id?: string;
|
|
703
|
+
component_kind?: string;
|
|
704
|
+
content_url?: string;
|
|
705
|
+
content_title?: string;
|
|
678
706
|
}
|
|
679
|
-
/**
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
variantId?: number;
|
|
691
|
-
/** Where these units come from (`Vio.attribution(slot)`); see `CartOrigin`. */
|
|
692
|
-
origin?: CartOrigin;
|
|
707
|
+
/** The caps of `LineOriginDto` — a longer value is refused whole by the API, so it is cut here. */
|
|
708
|
+
declare const LINE_ORIGIN_CAPS: Readonly<{
|
|
709
|
+
locationId: 100;
|
|
710
|
+
componentKind: 32;
|
|
711
|
+
contentUrl: 2048;
|
|
712
|
+
contentTitle: 255;
|
|
713
|
+
}>;
|
|
714
|
+
/** The page the units are added from, for an origin that does not carry its own. */
|
|
715
|
+
interface OriginPage {
|
|
716
|
+
contentUrl?: string;
|
|
717
|
+
contentTitle?: string;
|
|
693
718
|
}
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
* cart (two CreateCarts split the items and one silently disappears). */
|
|
698
|
-
private cartIdPromises;
|
|
699
|
-
/** Monotonic mutation counter per sponsor + last applied response, so a
|
|
700
|
-
* slow response can't overwrite the state of a newer one. */
|
|
701
|
-
private mutationSeq;
|
|
702
|
-
private appliedSeq;
|
|
703
|
-
/** In-flight AddItem/UpdateItem/DeleteItem per sponsor. Callers that need
|
|
704
|
-
* the backend cart to reflect a just-made change (e.g. fetching shippings
|
|
705
|
-
* right after an add) should `await waitForCartMutations(sponsorId)` first
|
|
706
|
-
* — otherwise they can race the mutation and see the cart from before it
|
|
707
|
-
* landed (Alan, 2026-08-18: shippings queried before AddItem settled,
|
|
708
|
-
* came back empty). */
|
|
709
|
-
private inFlightMutations;
|
|
710
|
-
/** Per-line quantity sync with the backend: at most ONE UpdateItem /
|
|
711
|
-
* DeleteItem in flight per line. Targets that arrive while one is in flight
|
|
712
|
-
* are coalesced into `pending` (only the latest survives) and sent when the
|
|
713
|
-
* current request settles. Keyed by `${sponsorId}:${cartItemId}`.
|
|
714
|
-
* (Alan, 2026-10-15: a burst of +/− clicks fired one UpdateItem per click
|
|
715
|
-
* in parallel; each response re-applied the whole backend cart, so an
|
|
716
|
-
* older one landing after a newer optimistic change rolled the line back.) */
|
|
717
|
-
private qtySyncs;
|
|
718
|
-
constructor();
|
|
719
|
-
private nextSeq;
|
|
720
|
-
/** Resolves once every in-flight AddItem/UpdateItem/DeleteItem for this
|
|
721
|
-
* sponsor has settled (success or failure), including ones started while
|
|
722
|
-
* waiting (a quantity intent replayed by an AddItem reconcile). No-op if
|
|
723
|
-
* nothing is pending. */
|
|
724
|
-
waitForCartMutations(sponsorId: number): Promise<void>;
|
|
725
|
-
/**
|
|
726
|
-
* True while an AddItem/UpdateItem/DeleteItem of this sponsor OTHER than
|
|
727
|
-
* `except` has not settled. A mutation applying its own answer passes
|
|
728
|
-
* itself: its response is current for what IT sent — only the others make
|
|
729
|
-
* it stale.
|
|
730
|
-
*/
|
|
731
|
-
private hasMutationsInFlight;
|
|
732
|
-
/** Register a backend mutation so `waitForCartMutations` can await it. */
|
|
733
|
-
private trackMutation;
|
|
734
|
-
private qtySyncKey;
|
|
735
|
-
/** The quantity a line is heading to (pending beats in flight), or
|
|
736
|
-
* undefined when no quantity sync is active for it. */
|
|
737
|
-
private intendedQuantity;
|
|
738
|
-
/** Apply a backend response only if no newer response was applied already.
|
|
739
|
-
* Returns false when it was discarded as stale. */
|
|
740
|
-
private applyBackendCart;
|
|
741
|
-
/** The final answer of a line's sync lost the per-sponsor seq race (another
|
|
742
|
-
* line answered later): the cart as a whole is stale, but for THIS line it
|
|
743
|
-
* is the latest word. Copy its quantity (and price) so a server-side clamp
|
|
744
|
-
* — stock — doesn't leave the optimistic value behind for good, with the
|
|
745
|
-
* checkout / Apple Pay total built on it. */
|
|
746
|
-
private reconcileLineFromResponse;
|
|
747
|
-
/** Surface a cart sync problem to hosts/UI (and the console). */
|
|
748
|
-
private emitError;
|
|
749
|
-
/** Ensure the sponsor cart exists server-side; returns its backend cart id. */
|
|
750
|
-
ensureCartId(sponsorId: number, currency?: string, shippingCountry?: string): Promise<string | undefined>;
|
|
719
|
+
interface LineOriginWireOptions {
|
|
720
|
+
/** The current page, for an origin that does not carry its own. */
|
|
721
|
+
page?: OriginPage;
|
|
751
722
|
/**
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
* empty, and the local lines go — not an add still on its way.
|
|
758
|
-
*/
|
|
759
|
-
updateFromBackendCart(sponsorId: number, backendCart: {
|
|
760
|
-
cart_id?: string;
|
|
761
|
-
currency?: string;
|
|
762
|
-
shipping_country?: string;
|
|
763
|
-
subtotal?: number;
|
|
764
|
-
shipping?: number;
|
|
765
|
-
available_shipping_countries?: string[];
|
|
766
|
-
line_items?: Array<{
|
|
767
|
-
id: string;
|
|
768
|
-
product_id: number;
|
|
769
|
-
variant_id?: number | string | null;
|
|
770
|
-
variant_title?: string | null;
|
|
771
|
-
brand?: string | null;
|
|
772
|
-
title?: string | null;
|
|
773
|
-
quantity: number;
|
|
774
|
-
image?: string | {
|
|
775
|
-
url?: string;
|
|
776
|
-
} | null;
|
|
777
|
-
imageUrl?: string | null;
|
|
778
|
-
image_url?: string | null;
|
|
779
|
-
price?: {
|
|
780
|
-
amount?: number;
|
|
781
|
-
amount_incl_taxes?: number | null;
|
|
782
|
-
currency_code?: string;
|
|
783
|
-
} | null;
|
|
784
|
-
shipping?: unknown;
|
|
785
|
-
available_shippings?: unknown[];
|
|
786
|
-
}>;
|
|
787
|
-
}, opts?: {
|
|
788
|
-
settling?: Promise<unknown>;
|
|
789
|
-
authoritative?: boolean;
|
|
790
|
-
}): void;
|
|
791
|
-
/** Add a Product DTO to a sponsor's cart. Bumps quantity if already present.
|
|
792
|
-
* When a variantId is given, the line uses the VARIANT's price / image / title
|
|
793
|
-
* (not the product base), so different combinations are priced correctly. */
|
|
794
|
-
addProduct(opts: AddProductOptions): CartLineItem;
|
|
795
|
-
/** Add a manually-specified line item (no Product DTO). */
|
|
796
|
-
addManual(opts: AddManualOptions): CartLineItem;
|
|
797
|
-
/** Quantity intents for lines whose backend id hasn't arrived yet — replayed
|
|
798
|
-
* when the AddItem response reconciles (keyed by product::variant). */
|
|
799
|
-
private pendingQtyIntents;
|
|
800
|
-
private intentKey;
|
|
801
|
-
private findLine;
|
|
802
|
-
/** Change a line's quantity by `delta`, computed on the manager's CURRENT
|
|
803
|
-
* quantity — not on whatever a UI rendered a moment ago. A burst of +/−
|
|
804
|
-
* clicks before a re-render therefore asks for 2, 3, 4… and not for the
|
|
805
|
-
* same target several times. Reaching 0 removes the line. */
|
|
806
|
-
adjustQuantity(lineItemId: string, sponsorId: number, delta: number, opts?: {
|
|
807
|
-
origin?: CartOrigin;
|
|
808
|
-
}): void;
|
|
809
|
-
/** Set a line's quantity (0 or less removes it). Optimistic: the local
|
|
810
|
-
* state and `change` update at once; the backend is synced through
|
|
811
|
-
* `syncQuantity`, one request in flight per line, latest target wins. */
|
|
812
|
-
updateQuantity(lineItemId: string, sponsorId: number, quantity: number, opts?: {
|
|
813
|
-
origin?: CartOrigin;
|
|
814
|
-
}): void;
|
|
815
|
-
/** Send a line's target quantity to the backend — ONE request in flight per
|
|
816
|
-
* line. Targets that arrive while one is in flight queue behind it as
|
|
817
|
-
* steps (`queueStep`): reduced like the line's origins, sent in order once
|
|
818
|
-
* the current request settles — one request per queued increase from a
|
|
819
|
-
* different origin, one for a net decrease — so the server ends on the
|
|
820
|
-
* last intent, credits every increase to its own origin, and never sees two
|
|
821
|
-
* updates racing each other. While the sync is active the line keeps its
|
|
822
|
-
* optimistic quantity through any backend response (see
|
|
823
|
-
* `updateFromBackendCart`); a rejection drops what was queued and
|
|
824
|
-
* reconciles the cart from the server. */
|
|
825
|
-
private syncQuantity;
|
|
826
|
-
removeItem(lineItemId: string, sponsorId: number): void;
|
|
827
|
-
clearSponsorCart(sponsorId: number): void;
|
|
828
|
-
clearAllCarts(): void;
|
|
829
|
-
/** Refresh the local cart from the backend (source of truth). */
|
|
830
|
-
fetchCartFromBackend(sponsorId: number): Promise<unknown>;
|
|
831
|
-
/**
|
|
832
|
-
* The cart as the server has it, for the moment a checkout is about to be
|
|
833
|
-
* built on it: what the shopper is about to pay must be what the page shows.
|
|
834
|
-
* Waits for this tab's own mutations (their answers are the server's too),
|
|
835
|
-
* then applies GetCart as it is — a line another tab added, one it removed,
|
|
836
|
-
* an empty cart — and tells the page: `change` for the drawer, and
|
|
837
|
-
* `vio:cart-updated` on `document` (`source: 'server'`) for a host that
|
|
838
|
-
* draws its own. A mutation that starts while the server is answering makes
|
|
839
|
-
* that answer old: it is asked once more. Nothing to ask without a backend
|
|
840
|
-
* cart. A GetCart that fails leaves the local state as it was and does not
|
|
841
|
-
* throw — the checkout then goes on with the lines the last mutation
|
|
842
|
-
* answered, as it always did. Resolves with the sponsor's cart.
|
|
843
|
-
*/
|
|
844
|
-
refreshFromServer(sponsorId: number): Promise<SponsorCartState | undefined>;
|
|
845
|
-
/** `vio:cart-updated` on `document` — see `CartUpdatedDetail`. */
|
|
846
|
-
private emitCartUpdated;
|
|
847
|
-
/**
|
|
848
|
-
* Another tab of the site wrote the carts: adopt what it wrote, sponsor by
|
|
849
|
-
* sponsor — its lines and its backend cart id, or nothing when it cleared
|
|
850
|
-
* the cart (a payment) — except for a sponsor this tab is mid-write for:
|
|
851
|
-
* its own answer lands in a moment and is persisted then, over whatever
|
|
852
|
-
* the other tab had. `key` is null when the other tab cleared the whole
|
|
853
|
-
* storage. Says `change` (the drawer) and `vio:cart-updated` per sponsor
|
|
854
|
-
* that changed (`source: 'storage'`); nothing when nothing did.
|
|
855
|
-
*/
|
|
856
|
-
private onStorage;
|
|
857
|
-
/** Line items grouped by supplier (shipping is per-supplier server-side). */
|
|
858
|
-
fetchLineItemsBySupplier(sponsorId: number): Promise<unknown>;
|
|
859
|
-
/** Set the chosen shipping option per supplier on the backend cart. */
|
|
860
|
-
updateShippingsBySupplier(sponsorId: number, data: Array<{
|
|
861
|
-
shipping_id: string;
|
|
862
|
-
supplier_id: number;
|
|
863
|
-
}>): Promise<unknown>;
|
|
864
|
-
getAllCarts(): Map<number, SponsorCartState>;
|
|
865
|
-
getCart(sponsorId: number): SponsorCartState | undefined;
|
|
866
|
-
get itemCount(): number;
|
|
867
|
-
subtotalForSponsor(sponsorId: number): number;
|
|
868
|
-
get totalAcrossSponsors(): number;
|
|
869
|
-
get primaryCurrency(): string;
|
|
870
|
-
formatTotal(): string;
|
|
871
|
-
/**
|
|
872
|
-
* Keep the carts for the next page and the other tabs. Where storage
|
|
873
|
-
* refuses (in-app browsers, private modes) nothing throws (safe-storage.ts):
|
|
874
|
-
* the carts stay in this manager's own map, the add to cart and the
|
|
875
|
-
* checkout go on, and the cart just does not survive a reload there.
|
|
876
|
-
*/
|
|
877
|
-
private persist;
|
|
878
|
-
private loadFromStorage;
|
|
879
|
-
private emit;
|
|
880
|
-
}
|
|
881
|
-
/**
|
|
882
|
-
* Only the attribution fields, trimmed; `{}` when nothing is known. The kind
|
|
883
|
-
* of element is kept as Commerce and the collector name it (`card`,
|
|
884
|
-
* `carousel`, `detail` — `componentKindOf`), from `componentKind` or from
|
|
885
|
-
* the `componentTemplateId` an element's attribution carries (`product-card`);
|
|
886
|
-
* the page as origin + path (`contentUrl`) and its title, within Commerce's caps.
|
|
887
|
-
*/
|
|
888
|
-
declare function normalizeOrigin(origin: CartOrigin | null | undefined): CartOrigin;
|
|
889
|
-
/** Two origins are the same place when campaign, slot, content and kind of element all match (the page's URL and title are attributes of the place, not its identity). */
|
|
890
|
-
declare function sameOrigin(a: CartOrigin, b: CartOrigin): boolean;
|
|
891
|
-
/**
|
|
892
|
-
* The origins of a line for reporting: what it carries, plus an empty origin
|
|
893
|
-
* for any units it does not account for (a cart persisted before origins
|
|
894
|
-
* existed, a server-side bump). Their quantities add up to the line's.
|
|
895
|
-
*/
|
|
896
|
-
declare function lineOrigins(line: Pick<CartLineItem, 'origins' | 'quantity'>): CartLineOrigin[];
|
|
897
|
-
|
|
898
|
-
/**
|
|
899
|
-
* Who sells — the sponsor's (brand's) display identity: its name and logo.
|
|
900
|
-
*
|
|
901
|
-
* ONE rule for every place that names a sponsor (the product detail, the
|
|
902
|
-
* carousel's retailer line, the cart, the checkout header, the confirmation,
|
|
903
|
-
* the payment event and `getOrderReference`): the bootstrap's sponsor block —
|
|
904
|
-
* the config's primary and secondaries, then every `campaigns[]` primary and
|
|
905
|
-
* secondaries, first match — and, when the bootstrap does not know the id,
|
|
906
|
-
* what this tab remembered of the checkout, then the cart's `sponsorName`.
|
|
907
|
-
*
|
|
908
|
-
* In a checkout and on its confirmation the sponsor is the CHECKOUT's (the
|
|
909
|
-
* cart's sponsor, the one the order is with), never the page's attribution:
|
|
910
|
-
* an article of brand A may sell a product of brand B.
|
|
911
|
-
*
|
|
912
|
-
* Pure helpers and a tiny per-checkout memory in `sessionStorage`; no DOM.
|
|
913
|
-
*/
|
|
914
|
-
|
|
915
|
-
/** What a sponsor looks like to a shopper. `name` is the brand's display name. */
|
|
916
|
-
interface SponsorIdentity {
|
|
917
|
-
id: number;
|
|
918
|
-
name: string;
|
|
919
|
-
/** The brand's logo, as the bootstrap gives it (never rewritten); `null` when it has none. */
|
|
920
|
-
logoUrl: string | null;
|
|
921
|
-
avatarUrl: string | null;
|
|
922
|
-
/** The brand's purchase terms page — https only; `null` when it has none. */
|
|
923
|
-
termsUrl?: string | null;
|
|
924
|
-
/** The brand's returns / refund policy page — https only; `null` when it has none. */
|
|
925
|
-
refundPolicyUrl?: string | null;
|
|
926
|
-
/** The brand's promises (at most three, each with a title); absent when it has none. */
|
|
927
|
-
highlights?: SponsorHighlight[];
|
|
928
|
-
}
|
|
929
|
-
/** The sponsor of a checkout / an order as events and `getOrderReference` carry it. */
|
|
930
|
-
type CheckoutSponsor = Pick<SponsorIdentity, 'id' | 'name' | 'logoUrl'>;
|
|
931
|
-
/** `sessionStorage` key of the per-checkout memory. */
|
|
932
|
-
declare const CHECKOUT_SPONSOR_STORAGE_KEY = "vio.checkoutSponsor.v1";
|
|
933
|
-
/**
|
|
934
|
-
* The identity of a sponsor from a bootstrap (`findSponsorIn`): its trimmed
|
|
935
|
-
* name and its logo / avatar URLs as given (an empty string is `null`).
|
|
936
|
-
* `null` when the bootstrap does not know the id, or the block says neither
|
|
937
|
-
* a name nor a logo. Pure, never throws.
|
|
938
|
-
*/
|
|
939
|
-
declare function sponsorIdentityFrom(boot: BootstrapResponse | null | undefined, sponsorId: number | string | null | undefined): SponsorIdentity | null;
|
|
940
|
-
|
|
941
|
-
/**
|
|
942
|
-
* What the commerce gateway may not know yet.
|
|
943
|
-
*
|
|
944
|
-
* The SDK ships ahead of the gateway more than once a quarter: a selection
|
|
945
|
-
* (`buyer_ref`, 2026-10-19), an argument (`origin` on the cart lines,
|
|
946
|
-
* `attribution` on the checkout — ADR-0035 phase B). A gateway that does not
|
|
947
|
-
* have the field refuses the WHOLE operation at validation — before anything
|
|
948
|
-
* runs, with no `data` — so each such operation is sent again without the
|
|
949
|
-
* field, once, and the answer remembered for the page load. An operation that
|
|
950
|
-
* DID run and failed is never repeated: for a mutation that would be a second
|
|
951
|
-
* charge, a second line in the cart.
|
|
952
|
-
*
|
|
953
|
-
* One mechanism for all of them, so the next field costs a token here and a
|
|
954
|
-
* call to `withGatewayFeature`, not a new copy of the retry.
|
|
955
|
-
*/
|
|
956
|
-
type GatewayFeature = 'buyer_ref' | 'line_origin' | 'checkout_attribution';
|
|
957
|
-
/** Whether this page load still expects the gateway to know `feature` (false once it refused it). */
|
|
958
|
-
declare function gatewayHas(feature: GatewayFeature): boolean;
|
|
959
|
-
/** Forget what this page load learned (tests). One feature, or all of them. */
|
|
960
|
-
declare function resetGatewayFeatures(feature?: GatewayFeature): void;
|
|
961
|
-
/**
|
|
962
|
-
* True when `err` is the gateway refusing something it does not know, named
|
|
963
|
-
* `token` (`Cannot query field "buyer_ref" on type …`, `Unknown argument
|
|
964
|
-
* "origin" on field …`, `Unknown type "CartLineOriginInput"`, `Field "origin" is
|
|
965
|
-
* not defined by type "LineItemInput"`): a validation error, with no `data`
|
|
966
|
-
* and no `path` because nothing ran — safe to send again without it, a
|
|
967
|
-
* mutation included. Anything that ran (data present, or an error with a
|
|
968
|
-
* path) or any other message is not.
|
|
969
|
-
*/
|
|
970
|
-
declare function isUnknownTokenError(err: unknown, token: string): boolean;
|
|
971
|
-
/** `isUnknownTokenError` for any of the names a feature goes by. */
|
|
972
|
-
declare function isUnknownFeatureError(err: unknown, feature: GatewayFeature): boolean;
|
|
973
|
-
/**
|
|
974
|
-
* Runs `request(true)` (the operation with the feature); when the gateway
|
|
975
|
-
* does not know it, `request(false)` (without it) — and from then on, for
|
|
976
|
-
* this page load, straight to the latter. Said once in the console: a
|
|
977
|
-
* gateway behind the SDK is worth knowing about, and so is a renamed type.
|
|
978
|
-
*/
|
|
979
|
-
declare function withGatewayFeature<T>(feature: GatewayFeature, request: (supported: boolean) => Promise<T>): Promise<T>;
|
|
980
|
-
|
|
981
|
-
/**
|
|
982
|
-
* A line origin as Commerce receives it (ADR-0035 phase B): `origin` on each
|
|
983
|
-
* line of `AddItem` and, when the quantity goes UP, on `UpdateItem` — the
|
|
984
|
-
* origin of the units that update adds. shopcart keeps every origin of a
|
|
985
|
-
* line with its units (`cart_item.origins`) and writes the order from them:
|
|
986
|
-
* `order_item.campaign_id` / `location_id` / `component_kind`, and the
|
|
987
|
-
* order's page when the checkout does not name one.
|
|
988
|
-
*
|
|
989
|
-
* snake_case on the wire, the caps of shopcart's `LineOriginDto` enforced
|
|
990
|
-
* here, once. Pure: `lineOriginWire()` takes the origin and the page.
|
|
991
|
-
*/
|
|
992
|
-
|
|
993
|
-
/** The largest `Int` GraphQL coerces; a bigger id would fail the whole mutation. */
|
|
994
|
-
declare const GRAPHQL_INT_MAX = 2147483647;
|
|
995
|
-
/** `LineOriginDto` (shopcart `cart/dtos/send/line-origin.dto.ts`). */
|
|
996
|
-
interface LineOriginWire {
|
|
997
|
-
campaign_id?: number;
|
|
998
|
-
location_id?: string;
|
|
999
|
-
component_kind?: string;
|
|
1000
|
-
content_url?: string;
|
|
1001
|
-
content_title?: string;
|
|
1002
|
-
}
|
|
1003
|
-
/** The caps of `LineOriginDto` — a longer value is refused whole by the API, so it is cut here. */
|
|
1004
|
-
declare const LINE_ORIGIN_CAPS: Readonly<{
|
|
1005
|
-
locationId: 100;
|
|
1006
|
-
componentKind: 32;
|
|
1007
|
-
contentUrl: 2048;
|
|
1008
|
-
contentTitle: 255;
|
|
1009
|
-
}>;
|
|
1010
|
-
/** The page the units are added from, for an origin that does not carry its own. */
|
|
1011
|
-
interface OriginPage {
|
|
1012
|
-
contentUrl?: string;
|
|
1013
|
-
contentTitle?: string;
|
|
1014
|
-
}
|
|
1015
|
-
interface LineOriginWireOptions {
|
|
1016
|
-
/** The current page, for an origin that does not carry its own. */
|
|
1017
|
-
page?: OriginPage;
|
|
1018
|
-
/**
|
|
1019
|
-
* The surface's privacy mode. Only on a `standard` surface do the slot
|
|
1020
|
-
* (`location_id`) and the page (`content_url`, `content_title`) travel —
|
|
1021
|
-
* which screen a unit was sold from is what `minimal` keeps private, the
|
|
1022
|
-
* same promise the collector keeps for the events. `campaign_id` and
|
|
1023
|
-
* `component_kind` always do. Default `unknown`: fail closed.
|
|
723
|
+
* The surface's privacy mode. Only on a `standard` surface do the slot
|
|
724
|
+
* (`location_id`) and the page (`content_url`, `content_title`) travel —
|
|
725
|
+
* which screen a unit was sold from is what `minimal` keeps private, the
|
|
726
|
+
* same promise the collector keeps for the events. `campaign_id` and
|
|
727
|
+
* `component_kind` always do. Default `unknown`: fail closed.
|
|
1024
728
|
*/
|
|
1025
729
|
privacyMode?: SurfacePrivacyMode | 'unknown';
|
|
1026
730
|
}
|
|
@@ -1245,6 +949,63 @@ declare function autoSlotDisplayName(kind: SlotKind, ordinal: number, scopeName?
|
|
|
1245
949
|
/** A scope value fit for an id: trimmed, inner whitespace → `-`. */
|
|
1246
950
|
declare function normalizeScope(scope: string | null | undefined): string;
|
|
1247
951
|
|
|
952
|
+
/**
|
|
953
|
+
* Who sells — the sponsor's (brand's) display identity: its name and logo.
|
|
954
|
+
*
|
|
955
|
+
* ONE rule for every place that names a sponsor (the product detail, the
|
|
956
|
+
* carousel's retailer line, the cart, the checkout header, the confirmation,
|
|
957
|
+
* the payment event and `getOrderReference`): the bootstrap's sponsor block —
|
|
958
|
+
* the config's primary and secondaries, then every `campaigns[]` primary and
|
|
959
|
+
* secondaries, first match — and, when the bootstrap does not know the id,
|
|
960
|
+
* what this tab remembered of the checkout, then the cart's `sponsorName`.
|
|
961
|
+
*
|
|
962
|
+
* In a checkout and on its confirmation the sponsor is the CHECKOUT's (the
|
|
963
|
+
* cart's sponsor, the one the order is with), never the page's attribution:
|
|
964
|
+
* an article of brand A may sell a product of brand B.
|
|
965
|
+
*
|
|
966
|
+
* Pure helpers and a tiny per-checkout memory in `sessionStorage`; no DOM.
|
|
967
|
+
*/
|
|
968
|
+
|
|
969
|
+
/** What a sponsor looks like to a shopper. `name` is the brand's display name. */
|
|
970
|
+
interface SponsorIdentity {
|
|
971
|
+
id: number;
|
|
972
|
+
name: string;
|
|
973
|
+
/** The brand's logo, as the bootstrap gives it (never rewritten); `null` when it has none. */
|
|
974
|
+
logoUrl: string | null;
|
|
975
|
+
avatarUrl: string | null;
|
|
976
|
+
/** The brand's purchase terms page — https only; `null` when it has none. */
|
|
977
|
+
termsUrl?: string | null;
|
|
978
|
+
/** The brand's returns / refund policy page — https only; `null` when it has none. */
|
|
979
|
+
refundPolicyUrl?: string | null;
|
|
980
|
+
/** The brand's promises (at most three, each with a title); absent when it has none. */
|
|
981
|
+
highlights?: SponsorHighlight[];
|
|
982
|
+
}
|
|
983
|
+
/** The sponsor of a checkout / an order as events and `getOrderReference` carry it. */
|
|
984
|
+
type CheckoutSponsor = Pick<SponsorIdentity, 'id' | 'name' | 'logoUrl'>;
|
|
985
|
+
/** `sessionStorage` key of the per-checkout memory. */
|
|
986
|
+
declare const CHECKOUT_SPONSOR_STORAGE_KEY = "vio.checkoutSponsor.v1";
|
|
987
|
+
/**
|
|
988
|
+
* Where a sponsor sells right now: the campaign in context (`campaignId` —
|
|
989
|
+
* the element's `vio-campaign`, an ancestor's `data-vio-campaign`, the
|
|
990
|
+
* click's `campaignId`, `Vio.init`'s, in that order of precedence) or the
|
|
991
|
+
* channel a cart was created on (`channelId`).
|
|
992
|
+
*/
|
|
993
|
+
interface SponsorCommerceContext {
|
|
994
|
+
campaignId?: CampaignHint;
|
|
995
|
+
channelId?: string | number | null;
|
|
996
|
+
}
|
|
997
|
+
/** A sponsor block that can sell: it carries a commerce block with an API key. */
|
|
998
|
+
type SellingSponsor = Sponsor & {
|
|
999
|
+
commerce: SponsorCommerceBlock;
|
|
1000
|
+
};
|
|
1001
|
+
/**
|
|
1002
|
+
* The identity of a sponsor from a bootstrap (`findSponsorIn`): its trimmed
|
|
1003
|
+
* name and its logo / avatar URLs as given (an empty string is `null`).
|
|
1004
|
+
* `null` when the bootstrap does not know the id, or the block says neither
|
|
1005
|
+
* a name nor a logo. Pure, never throws.
|
|
1006
|
+
*/
|
|
1007
|
+
declare function sponsorIdentityFrom(boot: BootstrapResponse | null | undefined, sponsorId: number | string | null | undefined): SponsorIdentity | null;
|
|
1008
|
+
|
|
1248
1009
|
/**
|
|
1249
1010
|
* Vio.analytics — the web SDK's half of the Vio Analytics pipeline.
|
|
1250
1011
|
*
|
|
@@ -1806,195 +1567,531 @@ interface CheckoutAttributionInput {
|
|
|
1806
1567
|
/** Where the session came in (`resolveLanding()`): referrer, utm, landing page. */
|
|
1807
1568
|
landing?: Landing | null;
|
|
1808
1569
|
/**
|
|
1809
|
-
* The surface's privacy mode. Only on a `standard` surface do the page
|
|
1810
|
-
* (`content_url`, `content_title`) and the entry context travel: which
|
|
1811
|
-
* screen the sale was made on and why the shopper was there is what
|
|
1812
|
-
* `minimal` keeps private — the same promise the collector keeps for the
|
|
1813
|
-
* events. `unknown` (it could not be learnt) counts as `minimal`: what can
|
|
1814
|
-
* reveal it is only sent when the surface is known to allow it. The surface
|
|
1815
|
-
* and the campaign always travel.
|
|
1570
|
+
* The surface's privacy mode. Only on a `standard` surface do the page
|
|
1571
|
+
* (`content_url`, `content_title`) and the entry context travel: which
|
|
1572
|
+
* screen the sale was made on and why the shopper was there is what
|
|
1573
|
+
* `minimal` keeps private — the same promise the collector keeps for the
|
|
1574
|
+
* events. `unknown` (it could not be learnt) counts as `minimal`: what can
|
|
1575
|
+
* reveal it is only sent when the surface is known to allow it. The surface
|
|
1576
|
+
* and the campaign always travel.
|
|
1577
|
+
*/
|
|
1578
|
+
privacyMode?: SurfacePrivacyMode | 'unknown';
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* The attribution for the wire, or `undefined` when there is nothing to say.
|
|
1582
|
+
* The campaign is the page's; without one, the campaign that explains most
|
|
1583
|
+
* units of the cart under the same rule `purchase` is split by (ties: the
|
|
1584
|
+
* higher value, then the first). The page (origin + path) and the entry go
|
|
1585
|
+
* only on a `standard` surface.
|
|
1586
|
+
*/
|
|
1587
|
+
declare function checkoutAttributionOf(input: CheckoutAttributionInput): CheckoutAttributionWire | undefined;
|
|
1588
|
+
/** The landing as `entry`, capped; `undefined` when it says nothing. */
|
|
1589
|
+
declare function entryContextOf(landing: Landing | null | undefined): EntryContextWire | undefined;
|
|
1590
|
+
/**
|
|
1591
|
+
* The campaign that explains most units of the cart — over the slices
|
|
1592
|
+
* `purchase` is split by, so the order names the campaign the biggest
|
|
1593
|
+
* purchase event names. Ties go to the higher value, then to the first
|
|
1594
|
+
* slice. Units nobody attributes (a slice without campaign) never win.
|
|
1595
|
+
*/
|
|
1596
|
+
declare function dominantCampaignOf(slices: ReadonlyArray<CartSlice> | null | undefined): number | undefined;
|
|
1597
|
+
|
|
1598
|
+
/**
|
|
1599
|
+
* Vipps MobilePay Payment Adapter — GraphQL Integration & Types.
|
|
1600
|
+
*
|
|
1601
|
+
* Vipps payment integration uses 2 GraphQL operations:
|
|
1602
|
+
*
|
|
1603
|
+
* 1. `CreatePaymentVipps` mutation:
|
|
1604
|
+
* Initiates a Vipps payment session for a checkout and returns `payment_url`.
|
|
1605
|
+
*
|
|
1606
|
+
* 2. `GetVippsStatus` query:
|
|
1607
|
+
* Queries Vipps payment state directly for a checkout (`state`).
|
|
1608
|
+
*/
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* GraphQL mutation to create a Vipps payment session.
|
|
1612
|
+
*/
|
|
1613
|
+
declare const CREATE_PAYMENT_VIPPS_MUTATION = "\nmutation CreatePaymentVipps($checkoutId: String!, $email: String, $returnUrl: String!, $express: Boolean) {\n Payment {\n CreatePaymentVipps(checkout_id: $checkoutId, email: $email, return_url: $returnUrl, express: $express) {\n payment_url\n reference\n express\n reason\n }\n }\n}\n";
|
|
1614
|
+
/**
|
|
1615
|
+
* GraphQL query to fetch current Vipps payment status.
|
|
1616
|
+
*/
|
|
1617
|
+
declare const GET_VIPPS_STATUS_QUERY = "\nquery GetVippsStatus($checkoutId: String!) {\n Payment {\n GetVippsStatus(checkout_id: $checkoutId) {\n state\n duplicate_of\n }\n }\n}\n";
|
|
1618
|
+
interface CreatePaymentVippsVariables extends Record<string, unknown> {
|
|
1619
|
+
checkoutId: string;
|
|
1620
|
+
/** Optional since Express: Vipps hands the email back with the payment. */
|
|
1621
|
+
email?: string;
|
|
1622
|
+
returnUrl: string;
|
|
1623
|
+
/**
|
|
1624
|
+
* `true` asks for Express — address and delivery chosen inside the Vipps
|
|
1625
|
+
* app. When the cart cannot have it, no payment is created and the answer
|
|
1626
|
+
* says `express: false` with the reason; the caller then opens the
|
|
1627
|
+
* ordinary checkout.
|
|
1628
|
+
*/
|
|
1629
|
+
express?: boolean;
|
|
1630
|
+
}
|
|
1631
|
+
interface CreatePaymentVippsResponse {
|
|
1632
|
+
/** Absent when Express was asked for and refused. */
|
|
1633
|
+
payment_url?: string;
|
|
1634
|
+
/** The reference the seller reads in its Vipps portal. */
|
|
1635
|
+
reference?: string;
|
|
1636
|
+
express?: boolean;
|
|
1637
|
+
reason?: string;
|
|
1638
|
+
}
|
|
1639
|
+
interface GetVippsStatusVariables extends Record<string, unknown> {
|
|
1640
|
+
checkoutId: string;
|
|
1641
|
+
}
|
|
1642
|
+
interface VippsStatusResult {
|
|
1643
|
+
state: string;
|
|
1644
|
+
/** Set when this checkout was closed as a duplicate: the checkout that paid the cart. */
|
|
1645
|
+
duplicate_of?: string | null;
|
|
1646
|
+
}
|
|
1647
|
+
type VippsPaymentState = 'CREATED' | 'INITIATED' | 'AUTHORIZED' | 'TERMINATED' | 'EXPIRED' | string;
|
|
1648
|
+
/**
|
|
1649
|
+
* Executes the `CreatePaymentVipps` GraphQL mutation.
|
|
1650
|
+
*/
|
|
1651
|
+
declare function createPaymentVipps(variables: CreatePaymentVippsVariables | Record<string, unknown>, options?: CartQueryOptions): Promise<CreatePaymentVippsResponse | null>;
|
|
1652
|
+
/**
|
|
1653
|
+
* Executes the `GetVippsStatus` GraphQL query.
|
|
1654
|
+
*/
|
|
1655
|
+
declare function getVippsStatus(variables: GetVippsStatusVariables | Record<string, unknown>, options?: CartQueryOptions): Promise<VippsStatusResult | null>;
|
|
1656
|
+
|
|
1657
|
+
declare const CREATE_CART_MUTATION = "\nmutation CreateCart($customerSessionId: String!, $currency: String!, $shippingCountry: String) {\n Cart {\n CreateCart(customer_session_id: $customerSessionId, currency: $currency, shipping_country: $shippingCountry) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1658
|
+
declare const ADD_ITEM_MUTATION = "\nmutation AddItem($cartId: String!, $lineItems: [LineItemInput!]!) {\n Cart {\n AddItem(cart_id: $cartId, line_items: $lineItems) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1659
|
+
declare const DELETE_ITEM_MUTATION = "\nmutation DeleteItem($cartId: String!, $cartItemId: String!) {\n Cart {\n DeleteItem(cart_id: $cartId, cart_item_id: $cartItemId) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1660
|
+
declare const UPDATE_ITEM_MUTATION: string;
|
|
1661
|
+
/** `UpdateItem` with the `origin` of the added units (`CartLineOriginInput`, snake_case fields — see `lineOriginWire`). */
|
|
1662
|
+
declare const UPDATE_ITEM_WITH_ORIGIN_MUTATION: string;
|
|
1663
|
+
declare const GET_CART_QUERY = "\nquery GetCart($cartId: String!) {\n Cart {\n GetCart(cart_id: $cartId) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1664
|
+
declare const GET_LINE_ITEMS_BY_SUPPLIER_QUERY = "\nquery GetLineItemsBySupplier($cartId: String!) {\n Cart {\n GetLineItemsBySupplier(cart_id: $cartId) {\n supplier {\n id\n name\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n }\n }\n}\n";
|
|
1665
|
+
declare const UPDATE_SHIPPINGS_BY_SUPPLIER_MUTATION = "\nmutation UpdateShippingsBySupplier($cartId: String!, $data: [DataUpdateShippingsBySupplier!]!) {\n Cart {\n UpdateShippingsBySupplier(cart_id: $cartId, data: $data) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1666
|
+
declare const CREATE_CHECKOUT_MUTATION: string;
|
|
1667
|
+
/** `CreateCheckout` with the checkout's `attribution` (`CheckoutAttributionInput`, snake_case fields — see `checkoutAttributionOf`). */
|
|
1668
|
+
declare const CREATE_CHECKOUT_WITH_ATTRIBUTION_MUTATION: string;
|
|
1669
|
+
declare const UPDATE_CHECKOUT_MUTATION: string;
|
|
1670
|
+
/** `UpdateCheckout` with the checkout's `attribution` (`CheckoutAttributionInput`). */
|
|
1671
|
+
declare const UPDATE_CHECKOUT_WITH_ATTRIBUTION_MUTATION: string;
|
|
1672
|
+
declare const GET_CHECKOUT_QUERY = "\nquery GetCheckout($checkoutId: String!) {\n Checkout {\n GetCheckout(checkout_id: $checkoutId) {\n buyer_accepts_purchase_conditions\n buyer_accepts_terms_conditions\n created_at\n updated_at\n id\n deleted_at\n success_url\n cancel_url\n payment_method\n email\n status\n checkout_url\n origin_payment_id\n duplicate_of\n billing_address {\n id\n first_name\n last_name\n phone_code\n phone\n company\n address1\n address2\n city\n province\n province_code\n country\n country_code\n zip\n }\n shipping_address {\n id\n first_name\n last_name\n phone_code\n phone\n company\n address1\n address2\n city\n province\n province_code\n country\n country_code\n zip\n }\n available_payment_methods {\n name\n }\n discount_code\n cart {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n totals {\n currency_code\n subtotal\n shipping\n total\n taxes\n tax_rate\n discounts\n }\n }\n }\n}\n";
|
|
1673
|
+
declare const GET_AVAILABLE_PAYMENT_METHODS_QUERY = "\nquery Config {\n Payment {\n GetAvailablePaymentMethods {\n config {\n name\n type\n value\n }\n name\n }\n }\n}\n";
|
|
1674
|
+
|
|
1675
|
+
/** Transport options for a cart/checkout GraphQL call. */
|
|
1676
|
+
interface CartQueryOptions {
|
|
1677
|
+
endpoint?: string;
|
|
1678
|
+
apiKey?: string;
|
|
1679
|
+
/** Sponsor commerce key — goes in the Authorization header. */
|
|
1680
|
+
commerceKey?: string;
|
|
1681
|
+
/** True when the commerce key came from a resolved sponsor (bootstrap).
|
|
1682
|
+
* False = we fell back to the host apiKey — writes like CreateCart should
|
|
1683
|
+
* NOT proceed with the wrong key (the cart would be orphaned). */
|
|
1684
|
+
sponsorResolved?: boolean;
|
|
1685
|
+
/** The commerce channel of the key (`commerce.channelId` of the block it came from), when known. */
|
|
1686
|
+
channelId?: string;
|
|
1687
|
+
/**
|
|
1688
|
+
* True when a channel was asked for (`ctx.channelId`) and the bootstrap no
|
|
1689
|
+
* longer lists it for the sponsor: the call must not go out with another
|
|
1690
|
+
* channel's key — a cart on that channel is rebuilt on the current one.
|
|
1691
|
+
*/
|
|
1692
|
+
channelMissing?: boolean;
|
|
1693
|
+
}
|
|
1694
|
+
/** Which channel's key a cart / checkout call takes (see `getCartGraphQLOptions`). */
|
|
1695
|
+
interface CartKeyContext {
|
|
1696
|
+
/** The channel the cart (or checkout) lives on: only that channel's key. */
|
|
1697
|
+
channelId?: string | number | null;
|
|
1698
|
+
/** The campaign in context (candidates in precedence order); `null` = none at all, not even `Vio.init`'s. */
|
|
1699
|
+
campaignId?: number | string | null | ReadonlyArray<number | string | null | undefined>;
|
|
1700
|
+
/** A channel the bootstrap no longer lists still answers with the key this page saw for it (an open checkout). */
|
|
1701
|
+
retired?: boolean;
|
|
1702
|
+
}
|
|
1703
|
+
/**
|
|
1704
|
+
* Resolve endpoint + keys for cart GraphQL calls. Awaits Vio.bootstrap() once
|
|
1705
|
+
* if it hasn't run yet (the sponsor commerce keys come from bootstrap), then
|
|
1706
|
+
* uses the sponsor's commerce apiKey (via the Vio facade on globalThis,
|
|
1707
|
+
* avoiding an import cycle); falls back to the host apiKey.
|
|
1708
|
+
*/
|
|
1709
|
+
declare function getCartGraphQLOptions(sponsorId?: number, ctx?: CartKeyContext): Promise<CartQueryOptions>;
|
|
1710
|
+
/**
|
|
1711
|
+
* Stable per-browser customer session id (backend CreateCart requires one).
|
|
1712
|
+
* Never throws: where storage is refused (in-app browsers) the id lives in
|
|
1713
|
+
* this page's memory — still one per shopper, never the shared
|
|
1714
|
+
* `cs_session_default` every storage-less browser used to send.
|
|
1715
|
+
*/
|
|
1716
|
+
declare function getCustomerSessionId(): string;
|
|
1717
|
+
interface GraphQLEnvelope {
|
|
1718
|
+
data?: Record<string, Record<string, unknown>> | null;
|
|
1719
|
+
errors?: Array<{
|
|
1720
|
+
message?: string;
|
|
1721
|
+
path?: unknown;
|
|
1722
|
+
}>;
|
|
1723
|
+
}
|
|
1724
|
+
/** Execute a GraphQL query/mutation against the configured commerce endpoint.
|
|
1725
|
+
* Callers that skip `getCartGraphQLOptions()` (or pass a bare sponsorId) get
|
|
1726
|
+
* it resolved here instead of silently sending an unauthenticated request.
|
|
1727
|
+
* Rejects after `CART_GRAPHQL_TIMEOUT_MS` (and aborts the fetch). */
|
|
1728
|
+
declare function executeCartGraphQL(query: string, variables: Record<string, unknown>, options?: CartQueryOptions | number | undefined): Promise<GraphQLEnvelope>;
|
|
1729
|
+
declare function createCart(customerSessionId: string, currency: string, shippingCountry?: string | null, options?: CartQueryOptions): Promise<any>;
|
|
1730
|
+
/**
|
|
1731
|
+
* `AddItem`. A line may carry `origin` (`LineOriginWire`: where its units
|
|
1732
|
+
* come from — ADR-0035 phase B). A gateway that predates the field refuses
|
|
1733
|
+
* the whole mutation at validation (`LineItemInput` has no `origin`), so the
|
|
1734
|
+
* lines are sent again without it, once per page load — see gateway-features.
|
|
1735
|
+
*/
|
|
1736
|
+
declare function addItem(cartId: string, lineItems: unknown[], options?: CartQueryOptions): Promise<any>;
|
|
1737
|
+
declare function deleteItem(cartId: string, cartItemId: string, options?: CartQueryOptions): Promise<any>;
|
|
1738
|
+
/**
|
|
1739
|
+
* `UpdateItem`. `extra.origin` is where the units a quantity INCREASE adds
|
|
1740
|
+
* come from (ADR-0035 phase B); the server credits the new units to it. Sent
|
|
1741
|
+
* only with it; a gateway that predates the argument gets the legacy
|
|
1742
|
+
* mutation instead, once per page load — see gateway-features.
|
|
1743
|
+
*/
|
|
1744
|
+
declare function updateItem(cartId: string, cartItemId: string, shippingId?: string | null, qty?: number | null, options?: CartQueryOptions, extra?: {
|
|
1745
|
+
origin?: LineOriginWire;
|
|
1746
|
+
}): Promise<any>;
|
|
1747
|
+
declare function getCart(cartId: string, options?: CartQueryOptions): Promise<any>;
|
|
1748
|
+
declare function getLineItemsBySupplier(cartId: string, options?: CartQueryOptions): Promise<any>;
|
|
1749
|
+
declare function updateShippingsBySupplier(cartId: string, data: unknown[], options?: CartQueryOptions): Promise<any>;
|
|
1750
|
+
/**
|
|
1751
|
+
* `CreateCheckout`. With `extra.attribution` (`CheckoutAttributionWire`:
|
|
1752
|
+
* the surface, the page's campaign, the page and the entry — ADR-0035 phase
|
|
1753
|
+
* B) the checkout is born attributed; a gateway that predates the argument
|
|
1754
|
+
* gets the legacy mutation, once per page load — see gateway-features.
|
|
1755
|
+
*/
|
|
1756
|
+
declare function createCheckout(cartId: string, options?: CartQueryOptions, extra?: {
|
|
1757
|
+
attribution?: CheckoutAttributionWire;
|
|
1758
|
+
}): Promise<any>;
|
|
1759
|
+
/**
|
|
1760
|
+
* `UpdateCheckout`. `variables.attribution` (`CheckoutAttributionWire`) is
|
|
1761
|
+
* merged key by key over what the checkout has; a gateway that predates the
|
|
1762
|
+
* argument gets the legacy mutation without it, once per page load.
|
|
1763
|
+
*/
|
|
1764
|
+
declare function updateCheckout(variables: Record<string, unknown>, options?: CartQueryOptions): Promise<any>;
|
|
1765
|
+
declare function getCheckout(checkoutId: string, options?: CartQueryOptions): Promise<any>;
|
|
1766
|
+
/** What a checkout says of itself after paying: its Vio order number, once the order exists, and its buyer reference. */
|
|
1767
|
+
interface CheckoutReference {
|
|
1768
|
+
orderNumber: number | null;
|
|
1769
|
+
buyerRef: string | null;
|
|
1770
|
+
}
|
|
1771
|
+
/** The order number (null while the order does not exist yet) and the buyer reference (null when the API does not say it). */
|
|
1772
|
+
declare function getCheckoutReference(checkoutId: string, options?: CartQueryOptions): Promise<CheckoutReference>;
|
|
1773
|
+
declare function getAvailablePaymentMethods(options?: CartQueryOptions): Promise<any>;
|
|
1774
|
+
declare const CREATE_PAYMENT_STRIPE_MUTATION = "\nmutation CreatePaymentStripe($checkoutId: String!, $successUrl: String!, $paymentMethod: String!, $email: String!) {\n Payment {\n CreatePaymentStripe(checkout_id: $checkoutId, success_url: $successUrl, payment_method: $paymentMethod, email: $email) {\n order_id\n checkout_url\n }\n }\n}\n";
|
|
1775
|
+
declare function createPaymentStripe(variables: Record<string, unknown>, options?: CartQueryOptions): Promise<any>;
|
|
1776
|
+
|
|
1777
|
+
/**
|
|
1778
|
+
* CartManager — multi-sponsor cart state.
|
|
1779
|
+
*
|
|
1780
|
+
* Mirrors iOS's `CartManager` + `cartsBySponsor`. Holds local state in
|
|
1781
|
+
* memory and persists to localStorage. Reactive: dispatches a `change`
|
|
1782
|
+
* CustomEvent that UI components subscribe to (Web Components react via
|
|
1783
|
+
* `requestUpdate()`).
|
|
1784
|
+
*
|
|
1785
|
+
* The backend cart (Vio Commerce GraphQL CreateCart / AddItem / UpdateItem /
|
|
1786
|
+
* DeleteItem) is kept in sync optimistically from here; since 0.26 every add
|
|
1787
|
+
* and every increase tells it where the units come from (`origin`, ADR-0035
|
|
1788
|
+
* phase B) so the order is born attributed — see `origin-wire.ts`.
|
|
1789
|
+
*/
|
|
1790
|
+
|
|
1791
|
+
interface CartChangeDetail {
|
|
1792
|
+
cartsBySponsor: Map<number, SponsorCartState>;
|
|
1793
|
+
itemCount: number;
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* Detail of `vio:cart-updated` (on `document`): a sponsor's cart as it stands
|
|
1797
|
+
* after this tab learned of it from somewhere other than its own taps —
|
|
1798
|
+
* `source: 'server'`: GetCart, applied right before a checkout is built on it
|
|
1799
|
+
* (`refreshFromServer`); `source: 'storage'`: another tab of the same site
|
|
1800
|
+
* wrote it (an add there, a payment that cleared it). The lines are copies.
|
|
1801
|
+
*/
|
|
1802
|
+
interface CartUpdatedDetail {
|
|
1803
|
+
sponsorId: number;
|
|
1804
|
+
cartId?: string;
|
|
1805
|
+
items: CartLineItem[];
|
|
1806
|
+
itemCount: number;
|
|
1807
|
+
subtotal: number;
|
|
1808
|
+
currency: string;
|
|
1809
|
+
source: 'server' | 'storage';
|
|
1810
|
+
}
|
|
1811
|
+
interface AddProductOptions {
|
|
1812
|
+
product: Product;
|
|
1813
|
+
sponsorId: number;
|
|
1814
|
+
sponsorName?: string;
|
|
1815
|
+
quantity?: number;
|
|
1816
|
+
variantId?: number;
|
|
1817
|
+
/** Where these units come from (`Vio.attribution(slot)`); see `CartOrigin`. */
|
|
1818
|
+
origin?: CartOrigin;
|
|
1819
|
+
}
|
|
1820
|
+
/** Minimal product shape — for callers who only have e.g. mock data, not a full Product. */
|
|
1821
|
+
interface AddManualOptions {
|
|
1822
|
+
productId: number;
|
|
1823
|
+
sponsorId: number;
|
|
1824
|
+
sponsorName?: string;
|
|
1825
|
+
brand: string;
|
|
1826
|
+
name: string;
|
|
1827
|
+
unitPrice: number;
|
|
1828
|
+
currency: string;
|
|
1829
|
+
imageUrl: string;
|
|
1830
|
+
quantity?: number;
|
|
1831
|
+
variantId?: number;
|
|
1832
|
+
/** Where these units come from (`Vio.attribution(slot)`); see `CartOrigin`. */
|
|
1833
|
+
origin?: CartOrigin;
|
|
1834
|
+
}
|
|
1835
|
+
declare class CartManager extends EventTarget {
|
|
1836
|
+
private cartsBySponsor;
|
|
1837
|
+
/** In-flight CreateCart per sponsor — two quick adds must share ONE backend
|
|
1838
|
+
* cart (two CreateCarts split the items and one silently disappears). */
|
|
1839
|
+
private cartIdPromises;
|
|
1840
|
+
/** Monotonic mutation counter per sponsor + last applied response, so a
|
|
1841
|
+
* slow response can't overwrite the state of a newer one. */
|
|
1842
|
+
private mutationSeq;
|
|
1843
|
+
private appliedSeq;
|
|
1844
|
+
/** In-flight AddItem/UpdateItem/DeleteItem per sponsor. Callers that need
|
|
1845
|
+
* the backend cart to reflect a just-made change (e.g. fetching shippings
|
|
1846
|
+
* right after an add) should `await waitForCartMutations(sponsorId)` first
|
|
1847
|
+
* — otherwise they can race the mutation and see the cart from before it
|
|
1848
|
+
* landed (Alan, 2026-08-18: shippings queried before AddItem settled,
|
|
1849
|
+
* came back empty). */
|
|
1850
|
+
private inFlightMutations;
|
|
1851
|
+
/** Per-line quantity sync with the backend: at most ONE UpdateItem /
|
|
1852
|
+
* DeleteItem in flight per line. Targets that arrive while one is in flight
|
|
1853
|
+
* are coalesced into `pending` (only the latest survives) and sent when the
|
|
1854
|
+
* current request settles. Keyed by `${sponsorId}:${cartItemId}`.
|
|
1855
|
+
* (Alan, 2026-10-15: a burst of +/− clicks fired one UpdateItem per click
|
|
1856
|
+
* in parallel; each response re-applied the whole backend cart, so an
|
|
1857
|
+
* older one landing after a newer optimistic change rolled the line back.) */
|
|
1858
|
+
private qtySyncs;
|
|
1859
|
+
/**
|
|
1860
|
+
* Bumped per sponsor each time its backend cart is dropped because its
|
|
1861
|
+
* channel went away: the lines as they stood then (`carryOver`) go to the
|
|
1862
|
+
* new backend cart, so an add whose local units were already counted in
|
|
1863
|
+
* them must not send its own AddItem as well (see `addManual`).
|
|
1864
|
+
*/
|
|
1865
|
+
private rebuildEpoch;
|
|
1866
|
+
/** The lines to give the next backend cart of a sponsor, after its channel went away. */
|
|
1867
|
+
private carryOver;
|
|
1868
|
+
/** The storage key of this connection's carts. */
|
|
1869
|
+
private readonly storageKey;
|
|
1870
|
+
/**
|
|
1871
|
+
* Whether this is the page's connection now. A manager left behind by a
|
|
1872
|
+
* re-init (another key) still finishes its requests and keeps its own
|
|
1873
|
+
* carts, but says nothing to the page: no `vio:cart-*` events.
|
|
1874
|
+
*/
|
|
1875
|
+
private active;
|
|
1876
|
+
constructor(scope?: string);
|
|
1877
|
+
/** The page's connection is (or is no longer) this one; see `active`. */
|
|
1878
|
+
setActive(active: boolean): void;
|
|
1879
|
+
/** Tell the listeners what this connection's carts hold now (after the page switched to it). */
|
|
1880
|
+
announce(): void;
|
|
1881
|
+
private nextSeq;
|
|
1882
|
+
/** Resolves once every in-flight AddItem/UpdateItem/DeleteItem for this
|
|
1883
|
+
* sponsor has settled (success or failure), including ones started while
|
|
1884
|
+
* waiting (a quantity intent replayed by an AddItem reconcile). No-op if
|
|
1885
|
+
* nothing is pending. */
|
|
1886
|
+
waitForCartMutations(sponsorId: number): Promise<void>;
|
|
1887
|
+
/**
|
|
1888
|
+
* True while an AddItem/UpdateItem/DeleteItem of this sponsor OTHER than
|
|
1889
|
+
* `except` has not settled. A mutation applying its own answer passes
|
|
1890
|
+
* itself: its response is current for what IT sent — only the others make
|
|
1891
|
+
* it stale.
|
|
1892
|
+
*/
|
|
1893
|
+
private hasMutationsInFlight;
|
|
1894
|
+
/** Register a backend mutation so `waitForCartMutations` can await it. */
|
|
1895
|
+
private trackMutation;
|
|
1896
|
+
private qtySyncKey;
|
|
1897
|
+
/** The quantity a line is heading to (pending beats in flight), or
|
|
1898
|
+
* undefined when no quantity sync is active for it. */
|
|
1899
|
+
private intendedQuantity;
|
|
1900
|
+
/** Apply a backend response only if no newer response was applied already.
|
|
1901
|
+
* Returns false when it was discarded as stale. */
|
|
1902
|
+
private applyBackendCart;
|
|
1903
|
+
/** The final answer of a line's sync lost the per-sponsor seq race (another
|
|
1904
|
+
* line answered later): the cart as a whole is stale, but for THIS line it
|
|
1905
|
+
* is the latest word. Copy its quantity (and price) so a server-side clamp
|
|
1906
|
+
* — stock — doesn't leave the optimistic value behind for good, with the
|
|
1907
|
+
* checkout / Apple Pay total built on it. */
|
|
1908
|
+
private reconcileLineFromResponse;
|
|
1909
|
+
/** Surface a cart sync problem to hosts/UI (and the console). */
|
|
1910
|
+
private emitError;
|
|
1911
|
+
/**
|
|
1912
|
+
* The options of a sponsor's backend cart: the key of the channel it was
|
|
1913
|
+
* created on (`channelMissing` when the bootstrap no longer lists it). A
|
|
1914
|
+
* cart from before channels were remembered keeps the sponsor's first
|
|
1915
|
+
* block, as when it was created, and remembers that channel from now on.
|
|
1916
|
+
*/
|
|
1917
|
+
private cartOptions;
|
|
1918
|
+
/**
|
|
1919
|
+
* The backend cart to call for a sponsor, with the key of its channel. When
|
|
1920
|
+
* the bootstrap no longer lists that channel the stale cart is dropped and a
|
|
1921
|
+
* new one is created on the sponsor's current channel with the same lines
|
|
1922
|
+
* (`dropStaleBackendCart` + `ensureCartId`) — never a call with a key of
|
|
1923
|
+
* another channel. `undefined` when there is no backend cart (or none could
|
|
1924
|
+
* be made).
|
|
1925
|
+
*/
|
|
1926
|
+
liveCart(sponsorId: number): Promise<{
|
|
1927
|
+
cartId: string;
|
|
1928
|
+
opts: CartQueryOptions;
|
|
1929
|
+
} | undefined>;
|
|
1930
|
+
/**
|
|
1931
|
+
* The channel of a sponsor's cart is gone from the bootstrap (the campaign
|
|
1932
|
+
* moved, a refresh after hours): forget the backend cart and its line ids,
|
|
1933
|
+
* keep the lines, and remember them as they stand now for the next backend
|
|
1934
|
+
* cart (`carryOver`). Queued quantity syncs of the old cart are dropped —
|
|
1935
|
+
* their quantities are in the lines carried.
|
|
1936
|
+
*/
|
|
1937
|
+
private dropStaleBackendCart;
|
|
1938
|
+
/** Give a new backend cart the lines of the one whose channel went away — each unit with its own origin. */
|
|
1939
|
+
private replayCarriedLines;
|
|
1940
|
+
/**
|
|
1941
|
+
* Ensure the sponsor cart exists server-side; returns its backend cart id.
|
|
1942
|
+
* A new backend cart is created on the channel of the campaign in context —
|
|
1943
|
+
* `ctx.campaignId` (the add's origin), else the campaign the cart's lines
|
|
1944
|
+
* came from, else `Vio.init`'s — and remembers it (`channelId`). An existing
|
|
1945
|
+
* one whose channel the bootstrap no longer lists is created again on the
|
|
1946
|
+
* current channel, with its lines (`liveCart`).
|
|
1947
|
+
*/
|
|
1948
|
+
ensureCartId(sponsorId: number, currency?: string, shippingCountry?: string, ctx?: Pick<CartKeyContext, 'campaignId'>): Promise<string | undefined>;
|
|
1949
|
+
/**
|
|
1950
|
+
* Overwrite local cart state with the backend cart response (source of
|
|
1951
|
+
* truth). `opts.settling` is the mutation whose answer this is: it does not
|
|
1952
|
+
* count as "in flight" for the origins (see `hasMutationsInFlight`).
|
|
1953
|
+
* `opts.authoritative` is a GetCart taken with nothing of this tab's in
|
|
1954
|
+
* flight (`refreshFromServer`): an empty answer then means the cart IS
|
|
1955
|
+
* empty, and the local lines go — not an add still on its way.
|
|
1956
|
+
*/
|
|
1957
|
+
updateFromBackendCart(sponsorId: number, backendCart: {
|
|
1958
|
+
cart_id?: string;
|
|
1959
|
+
currency?: string;
|
|
1960
|
+
shipping_country?: string;
|
|
1961
|
+
subtotal?: number;
|
|
1962
|
+
shipping?: number;
|
|
1963
|
+
available_shipping_countries?: string[];
|
|
1964
|
+
line_items?: Array<{
|
|
1965
|
+
id: string;
|
|
1966
|
+
product_id: number;
|
|
1967
|
+
variant_id?: number | string | null;
|
|
1968
|
+
variant_title?: string | null;
|
|
1969
|
+
brand?: string | null;
|
|
1970
|
+
title?: string | null;
|
|
1971
|
+
quantity: number;
|
|
1972
|
+
image?: string | {
|
|
1973
|
+
url?: string;
|
|
1974
|
+
} | null;
|
|
1975
|
+
imageUrl?: string | null;
|
|
1976
|
+
image_url?: string | null;
|
|
1977
|
+
price?: {
|
|
1978
|
+
amount?: number;
|
|
1979
|
+
amount_incl_taxes?: number | null;
|
|
1980
|
+
currency_code?: string;
|
|
1981
|
+
} | null;
|
|
1982
|
+
shipping?: unknown;
|
|
1983
|
+
available_shippings?: unknown[];
|
|
1984
|
+
}>;
|
|
1985
|
+
}, opts?: {
|
|
1986
|
+
settling?: Promise<unknown>;
|
|
1987
|
+
authoritative?: boolean;
|
|
1988
|
+
}): void;
|
|
1989
|
+
/** Add a Product DTO to a sponsor's cart. Bumps quantity if already present.
|
|
1990
|
+
* When a variantId is given, the line uses the VARIANT's price / image / title
|
|
1991
|
+
* (not the product base), so different combinations are priced correctly. */
|
|
1992
|
+
addProduct(opts: AddProductOptions): CartLineItem;
|
|
1993
|
+
/** Add a manually-specified line item (no Product DTO). */
|
|
1994
|
+
addManual(opts: AddManualOptions): CartLineItem;
|
|
1995
|
+
/** Quantity intents for lines whose backend id hasn't arrived yet — replayed
|
|
1996
|
+
* when the AddItem response reconciles (keyed by product::variant). */
|
|
1997
|
+
private pendingQtyIntents;
|
|
1998
|
+
private intentKey;
|
|
1999
|
+
private findLine;
|
|
2000
|
+
/** Change a line's quantity by `delta`, computed on the manager's CURRENT
|
|
2001
|
+
* quantity — not on whatever a UI rendered a moment ago. A burst of +/−
|
|
2002
|
+
* clicks before a re-render therefore asks for 2, 3, 4… and not for the
|
|
2003
|
+
* same target several times. Reaching 0 removes the line. */
|
|
2004
|
+
adjustQuantity(lineItemId: string, sponsorId: number, delta: number, opts?: {
|
|
2005
|
+
origin?: CartOrigin;
|
|
2006
|
+
}): void;
|
|
2007
|
+
/** Set a line's quantity (0 or less removes it). Optimistic: the local
|
|
2008
|
+
* state and `change` update at once; the backend is synced through
|
|
2009
|
+
* `syncQuantity`, one request in flight per line, latest target wins. */
|
|
2010
|
+
updateQuantity(lineItemId: string, sponsorId: number, quantity: number, opts?: {
|
|
2011
|
+
origin?: CartOrigin;
|
|
2012
|
+
}): void;
|
|
2013
|
+
/** Send a line's target quantity to the backend — ONE request in flight per
|
|
2014
|
+
* line. Targets that arrive while one is in flight queue behind it as
|
|
2015
|
+
* steps (`queueStep`): reduced like the line's origins, sent in order once
|
|
2016
|
+
* the current request settles — one request per queued increase from a
|
|
2017
|
+
* different origin, one for a net decrease — so the server ends on the
|
|
2018
|
+
* last intent, credits every increase to its own origin, and never sees two
|
|
2019
|
+
* updates racing each other. While the sync is active the line keeps its
|
|
2020
|
+
* optimistic quantity through any backend response (see
|
|
2021
|
+
* `updateFromBackendCart`); a rejection drops what was queued and
|
|
2022
|
+
* reconciles the cart from the server. */
|
|
2023
|
+
private syncQuantity;
|
|
2024
|
+
removeItem(lineItemId: string, sponsorId: number): void;
|
|
2025
|
+
clearSponsorCart(sponsorId: number): void;
|
|
2026
|
+
clearAllCarts(): void;
|
|
2027
|
+
/** Refresh the local cart from the backend (source of truth). */
|
|
2028
|
+
fetchCartFromBackend(sponsorId: number): Promise<unknown>;
|
|
2029
|
+
/**
|
|
2030
|
+
* The cart as the server has it, for the moment a checkout is about to be
|
|
2031
|
+
* built on it: what the shopper is about to pay must be what the page shows.
|
|
2032
|
+
* Waits for this tab's own mutations (their answers are the server's too),
|
|
2033
|
+
* then applies GetCart as it is — a line another tab added, one it removed,
|
|
2034
|
+
* an empty cart — and tells the page: `change` for the drawer, and
|
|
2035
|
+
* `vio:cart-updated` on `document` (`source: 'server'`) for a host that
|
|
2036
|
+
* draws its own. A mutation that starts while the server is answering makes
|
|
2037
|
+
* that answer old: it is asked once more. Nothing to ask without a backend
|
|
2038
|
+
* cart. A GetCart that fails leaves the local state as it was and does not
|
|
2039
|
+
* throw — the checkout then goes on with the lines the last mutation
|
|
2040
|
+
* answered, as it always did. Resolves with the sponsor's cart.
|
|
1816
2041
|
*/
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
* The attribution for the wire, or `undefined` when there is nothing to say.
|
|
1821
|
-
* The campaign is the page's; without one, the campaign that explains most
|
|
1822
|
-
* units of the cart under the same rule `purchase` is split by (ties: the
|
|
1823
|
-
* higher value, then the first). The page (origin + path) and the entry go
|
|
1824
|
-
* only on a `standard` surface.
|
|
1825
|
-
*/
|
|
1826
|
-
declare function checkoutAttributionOf(input: CheckoutAttributionInput): CheckoutAttributionWire | undefined;
|
|
1827
|
-
/** The landing as `entry`, capped; `undefined` when it says nothing. */
|
|
1828
|
-
declare function entryContextOf(landing: Landing | null | undefined): EntryContextWire | undefined;
|
|
1829
|
-
/**
|
|
1830
|
-
* The campaign that explains most units of the cart — over the slices
|
|
1831
|
-
* `purchase` is split by, so the order names the campaign the biggest
|
|
1832
|
-
* purchase event names. Ties go to the higher value, then to the first
|
|
1833
|
-
* slice. Units nobody attributes (a slice without campaign) never win.
|
|
1834
|
-
*/
|
|
1835
|
-
declare function dominantCampaignOf(slices: ReadonlyArray<CartSlice> | null | undefined): number | undefined;
|
|
1836
|
-
|
|
1837
|
-
/**
|
|
1838
|
-
* Vipps MobilePay Payment Adapter — GraphQL Integration & Types.
|
|
1839
|
-
*
|
|
1840
|
-
* Vipps payment integration uses 2 GraphQL operations:
|
|
1841
|
-
*
|
|
1842
|
-
* 1. `CreatePaymentVipps` mutation:
|
|
1843
|
-
* Initiates a Vipps payment session for a checkout and returns `payment_url`.
|
|
1844
|
-
*
|
|
1845
|
-
* 2. `GetVippsStatus` query:
|
|
1846
|
-
* Queries Vipps payment state directly for a checkout (`state`).
|
|
1847
|
-
*/
|
|
1848
|
-
|
|
1849
|
-
/**
|
|
1850
|
-
* GraphQL mutation to create a Vipps payment session.
|
|
1851
|
-
*/
|
|
1852
|
-
declare const CREATE_PAYMENT_VIPPS_MUTATION = "\nmutation CreatePaymentVipps($checkoutId: String!, $email: String, $returnUrl: String!, $express: Boolean) {\n Payment {\n CreatePaymentVipps(checkout_id: $checkoutId, email: $email, return_url: $returnUrl, express: $express) {\n payment_url\n reference\n express\n reason\n }\n }\n}\n";
|
|
1853
|
-
/**
|
|
1854
|
-
* GraphQL query to fetch current Vipps payment status.
|
|
1855
|
-
*/
|
|
1856
|
-
declare const GET_VIPPS_STATUS_QUERY = "\nquery GetVippsStatus($checkoutId: String!) {\n Payment {\n GetVippsStatus(checkout_id: $checkoutId) {\n state\n duplicate_of\n }\n }\n}\n";
|
|
1857
|
-
interface CreatePaymentVippsVariables extends Record<string, unknown> {
|
|
1858
|
-
checkoutId: string;
|
|
1859
|
-
/** Optional since Express: Vipps hands the email back with the payment. */
|
|
1860
|
-
email?: string;
|
|
1861
|
-
returnUrl: string;
|
|
2042
|
+
refreshFromServer(sponsorId: number): Promise<SponsorCartState | undefined>;
|
|
2043
|
+
/** `vio:cart-updated` on `document` — see `CartUpdatedDetail`. */
|
|
2044
|
+
private emitCartUpdated;
|
|
1862
2045
|
/**
|
|
1863
|
-
*
|
|
1864
|
-
*
|
|
1865
|
-
*
|
|
1866
|
-
*
|
|
2046
|
+
* Another tab of the site wrote the carts: adopt what it wrote, sponsor by
|
|
2047
|
+
* sponsor — its lines and its backend cart id, or nothing when it cleared
|
|
2048
|
+
* the cart (a payment) — except for a sponsor this tab is mid-write for:
|
|
2049
|
+
* its own answer lands in a moment and is persisted then, over whatever
|
|
2050
|
+
* the other tab had. `key` is null when the other tab cleared the whole
|
|
2051
|
+
* storage. Says `change` (the drawer) and `vio:cart-updated` per sponsor
|
|
2052
|
+
* that changed (`source: 'storage'`); nothing when nothing did.
|
|
1867
2053
|
*/
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
/**
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
/**
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
* Executes the `GetVippsStatus` GraphQL query.
|
|
1893
|
-
*/
|
|
1894
|
-
declare function getVippsStatus(variables: GetVippsStatusVariables | Record<string, unknown>, options?: CartQueryOptions): Promise<VippsStatusResult | null>;
|
|
1895
|
-
|
|
1896
|
-
declare const CREATE_CART_MUTATION = "\nmutation CreateCart($customerSessionId: String!, $currency: String!, $shippingCountry: String) {\n Cart {\n CreateCart(customer_session_id: $customerSessionId, currency: $currency, shipping_country: $shippingCountry) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1897
|
-
declare const ADD_ITEM_MUTATION = "\nmutation AddItem($cartId: String!, $lineItems: [LineItemInput!]!) {\n Cart {\n AddItem(cart_id: $cartId, line_items: $lineItems) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1898
|
-
declare const DELETE_ITEM_MUTATION = "\nmutation DeleteItem($cartId: String!, $cartItemId: String!) {\n Cart {\n DeleteItem(cart_id: $cartId, cart_item_id: $cartItemId) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1899
|
-
declare const UPDATE_ITEM_MUTATION: string;
|
|
1900
|
-
/** `UpdateItem` with the `origin` of the added units (`CartLineOriginInput`, snake_case fields — see `lineOriginWire`). */
|
|
1901
|
-
declare const UPDATE_ITEM_WITH_ORIGIN_MUTATION: string;
|
|
1902
|
-
declare const GET_CART_QUERY = "\nquery GetCart($cartId: String!) {\n Cart {\n GetCart(cart_id: $cartId) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1903
|
-
declare const GET_LINE_ITEMS_BY_SUPPLIER_QUERY = "\nquery GetLineItemsBySupplier($cartId: String!) {\n Cart {\n GetLineItemsBySupplier(cart_id: $cartId) {\n supplier {\n id\n name\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n }\n }\n}\n";
|
|
1904
|
-
declare const UPDATE_SHIPPINGS_BY_SUPPLIER_MUTATION = "\nmutation UpdateShippingsBySupplier($cartId: String!, $data: [DataUpdateShippingsBySupplier!]!) {\n Cart {\n UpdateShippingsBySupplier(cart_id: $cartId, data: $data) {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n }\n}\n";
|
|
1905
|
-
declare const CREATE_CHECKOUT_MUTATION: string;
|
|
1906
|
-
/** `CreateCheckout` with the checkout's `attribution` (`CheckoutAttributionInput`, snake_case fields — see `checkoutAttributionOf`). */
|
|
1907
|
-
declare const CREATE_CHECKOUT_WITH_ATTRIBUTION_MUTATION: string;
|
|
1908
|
-
declare const UPDATE_CHECKOUT_MUTATION: string;
|
|
1909
|
-
/** `UpdateCheckout` with the checkout's `attribution` (`CheckoutAttributionInput`). */
|
|
1910
|
-
declare const UPDATE_CHECKOUT_WITH_ATTRIBUTION_MUTATION: string;
|
|
1911
|
-
declare const GET_CHECKOUT_QUERY = "\nquery GetCheckout($checkoutId: String!) {\n Checkout {\n GetCheckout(checkout_id: $checkoutId) {\n buyer_accepts_purchase_conditions\n buyer_accepts_terms_conditions\n created_at\n updated_at\n id\n deleted_at\n success_url\n cancel_url\n payment_method\n email\n status\n checkout_url\n origin_payment_id\n duplicate_of\n billing_address {\n id\n first_name\n last_name\n phone_code\n phone\n company\n address1\n address2\n city\n province\n province_code\n country\n country_code\n zip\n }\n shipping_address {\n id\n first_name\n last_name\n phone_code\n phone\n company\n address1\n address2\n city\n province\n province_code\n country\n country_code\n zip\n }\n available_payment_methods {\n name\n }\n discount_code\n cart {\n cart_id\n customer_session_id\n shipping_country\n line_items {\n id\n supplier\n image {\n id\n url\n width\n height\n }\n sku\n barcode\n brand\n product_id\n title\n variant_id\n variant_title\n variant {\n option\n value\n }\n quantity\n price {\n amount\n currency_code\n discount\n compare_at\n compare_at_incl_taxes\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n shipping {\n id\n name\n description\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n available_shippings {\n id\n name\n description\n country_code\n price {\n amount\n currency_code\n amount_incl_taxes\n tax_amount\n tax_rate\n }\n }\n }\n subtotal\n shipping\n currency\n available_shipping_countries\n }\n totals {\n currency_code\n subtotal\n shipping\n total\n taxes\n tax_rate\n discounts\n }\n }\n }\n}\n";
|
|
1912
|
-
declare const GET_AVAILABLE_PAYMENT_METHODS_QUERY = "\nquery Config {\n Payment {\n GetAvailablePaymentMethods {\n config {\n name\n type\n value\n }\n name\n }\n }\n}\n";
|
|
1913
|
-
|
|
1914
|
-
/** Transport options for a cart/checkout GraphQL call. */
|
|
1915
|
-
interface CartQueryOptions {
|
|
1916
|
-
endpoint?: string;
|
|
1917
|
-
apiKey?: string;
|
|
1918
|
-
/** Sponsor commerce key — goes in the Authorization header. */
|
|
1919
|
-
commerceKey?: string;
|
|
1920
|
-
/** True when the commerce key came from a resolved sponsor (bootstrap).
|
|
1921
|
-
* False = we fell back to the host apiKey — writes like CreateCart should
|
|
1922
|
-
* NOT proceed with the wrong key (the cart would be orphaned). */
|
|
1923
|
-
sponsorResolved?: boolean;
|
|
1924
|
-
}
|
|
1925
|
-
/**
|
|
1926
|
-
* Resolve endpoint + keys for cart GraphQL calls. Awaits Vio.bootstrap() once
|
|
1927
|
-
* if it hasn't run yet (the sponsor commerce keys come from bootstrap), then
|
|
1928
|
-
* uses the sponsor's commerce apiKey (via the Vio facade on globalThis,
|
|
1929
|
-
* avoiding an import cycle); falls back to the host apiKey.
|
|
1930
|
-
*/
|
|
1931
|
-
declare function getCartGraphQLOptions(sponsorId?: number): Promise<CartQueryOptions>;
|
|
1932
|
-
/**
|
|
1933
|
-
* Stable per-browser customer session id (backend CreateCart requires one).
|
|
1934
|
-
* Never throws: where storage is refused (in-app browsers) the id lives in
|
|
1935
|
-
* this page's memory — still one per shopper, never the shared
|
|
1936
|
-
* `cs_session_default` every storage-less browser used to send.
|
|
1937
|
-
*/
|
|
1938
|
-
declare function getCustomerSessionId(): string;
|
|
1939
|
-
interface GraphQLEnvelope {
|
|
1940
|
-
data?: Record<string, Record<string, unknown>> | null;
|
|
1941
|
-
errors?: Array<{
|
|
1942
|
-
message?: string;
|
|
1943
|
-
path?: unknown;
|
|
1944
|
-
}>;
|
|
2054
|
+
private onStorage;
|
|
2055
|
+
/** Line items grouped by supplier (shipping is per-supplier server-side). */
|
|
2056
|
+
fetchLineItemsBySupplier(sponsorId: number): Promise<unknown>;
|
|
2057
|
+
/** Set the chosen shipping option per supplier on the backend cart. */
|
|
2058
|
+
updateShippingsBySupplier(sponsorId: number, data: Array<{
|
|
2059
|
+
shipping_id: string;
|
|
2060
|
+
supplier_id: number;
|
|
2061
|
+
}>): Promise<unknown>;
|
|
2062
|
+
getAllCarts(): Map<number, SponsorCartState>;
|
|
2063
|
+
getCart(sponsorId: number): SponsorCartState | undefined;
|
|
2064
|
+
get itemCount(): number;
|
|
2065
|
+
subtotalForSponsor(sponsorId: number): number;
|
|
2066
|
+
get totalAcrossSponsors(): number;
|
|
2067
|
+
get primaryCurrency(): string;
|
|
2068
|
+
formatTotal(): string;
|
|
2069
|
+
/**
|
|
2070
|
+
* Keep the carts for the next page and the other tabs. Where storage
|
|
2071
|
+
* refuses (in-app browsers, private modes) nothing throws (safe-storage.ts):
|
|
2072
|
+
* the carts stay in this manager's own map, the add to cart and the
|
|
2073
|
+
* checkout go on, and the cart just does not survive a reload there.
|
|
2074
|
+
*/
|
|
2075
|
+
private persist;
|
|
2076
|
+
private loadFromStorage;
|
|
2077
|
+
private emit;
|
|
1945
2078
|
}
|
|
1946
|
-
/** Execute a GraphQL query/mutation against the configured commerce endpoint.
|
|
1947
|
-
* Callers that skip `getCartGraphQLOptions()` (or pass a bare sponsorId) get
|
|
1948
|
-
* it resolved here instead of silently sending an unauthenticated request.
|
|
1949
|
-
* Rejects after `CART_GRAPHQL_TIMEOUT_MS` (and aborts the fetch). */
|
|
1950
|
-
declare function executeCartGraphQL(query: string, variables: Record<string, unknown>, options?: CartQueryOptions | number | undefined): Promise<GraphQLEnvelope>;
|
|
1951
|
-
declare function createCart(customerSessionId: string, currency: string, shippingCountry?: string | null, options?: CartQueryOptions): Promise<any>;
|
|
1952
|
-
/**
|
|
1953
|
-
* `AddItem`. A line may carry `origin` (`LineOriginWire`: where its units
|
|
1954
|
-
* come from — ADR-0035 phase B). A gateway that predates the field refuses
|
|
1955
|
-
* the whole mutation at validation (`LineItemInput` has no `origin`), so the
|
|
1956
|
-
* lines are sent again without it, once per page load — see gateway-features.
|
|
1957
|
-
*/
|
|
1958
|
-
declare function addItem(cartId: string, lineItems: unknown[], options?: CartQueryOptions): Promise<any>;
|
|
1959
|
-
declare function deleteItem(cartId: string, cartItemId: string, options?: CartQueryOptions): Promise<any>;
|
|
1960
|
-
/**
|
|
1961
|
-
* `UpdateItem`. `extra.origin` is where the units a quantity INCREASE adds
|
|
1962
|
-
* come from (ADR-0035 phase B); the server credits the new units to it. Sent
|
|
1963
|
-
* only with it; a gateway that predates the argument gets the legacy
|
|
1964
|
-
* mutation instead, once per page load — see gateway-features.
|
|
1965
|
-
*/
|
|
1966
|
-
declare function updateItem(cartId: string, cartItemId: string, shippingId?: string | null, qty?: number | null, options?: CartQueryOptions, extra?: {
|
|
1967
|
-
origin?: LineOriginWire;
|
|
1968
|
-
}): Promise<any>;
|
|
1969
|
-
declare function getCart(cartId: string, options?: CartQueryOptions): Promise<any>;
|
|
1970
|
-
declare function getLineItemsBySupplier(cartId: string, options?: CartQueryOptions): Promise<any>;
|
|
1971
|
-
declare function updateShippingsBySupplier(cartId: string, data: unknown[], options?: CartQueryOptions): Promise<any>;
|
|
1972
2079
|
/**
|
|
1973
|
-
*
|
|
1974
|
-
*
|
|
1975
|
-
*
|
|
1976
|
-
*
|
|
2080
|
+
* Only the attribution fields, trimmed; `{}` when nothing is known. The kind
|
|
2081
|
+
* of element is kept as Commerce and the collector name it (`card`,
|
|
2082
|
+
* `carousel`, `detail` — `componentKindOf`), from `componentKind` or from
|
|
2083
|
+
* the `componentTemplateId` an element's attribution carries (`product-card`);
|
|
2084
|
+
* the page as origin + path (`contentUrl`) and its title, within Commerce's caps.
|
|
1977
2085
|
*/
|
|
1978
|
-
declare function
|
|
1979
|
-
|
|
1980
|
-
|
|
2086
|
+
declare function normalizeOrigin(origin: CartOrigin | null | undefined): CartOrigin;
|
|
2087
|
+
/** Two origins are the same place when campaign, slot, content and kind of element all match (the page's URL and title are attributes of the place, not its identity). */
|
|
2088
|
+
declare function sameOrigin(a: CartOrigin, b: CartOrigin): boolean;
|
|
1981
2089
|
/**
|
|
1982
|
-
*
|
|
1983
|
-
*
|
|
1984
|
-
*
|
|
2090
|
+
* The origins of a line for reporting: what it carries, plus an empty origin
|
|
2091
|
+
* for any units it does not account for (a cart persisted before origins
|
|
2092
|
+
* existed, a server-side bump). Their quantities add up to the line's.
|
|
1985
2093
|
*/
|
|
1986
|
-
declare function
|
|
1987
|
-
declare function getCheckout(checkoutId: string, options?: CartQueryOptions): Promise<any>;
|
|
1988
|
-
/** What a checkout says of itself after paying: its Vio order number, once the order exists, and its buyer reference. */
|
|
1989
|
-
interface CheckoutReference {
|
|
1990
|
-
orderNumber: number | null;
|
|
1991
|
-
buyerRef: string | null;
|
|
1992
|
-
}
|
|
1993
|
-
/** The order number (null while the order does not exist yet) and the buyer reference (null when the API does not say it). */
|
|
1994
|
-
declare function getCheckoutReference(checkoutId: string, options?: CartQueryOptions): Promise<CheckoutReference>;
|
|
1995
|
-
declare function getAvailablePaymentMethods(options?: CartQueryOptions): Promise<any>;
|
|
1996
|
-
declare const CREATE_PAYMENT_STRIPE_MUTATION = "\nmutation CreatePaymentStripe($checkoutId: String!, $successUrl: String!, $paymentMethod: String!, $email: String!) {\n Payment {\n CreatePaymentStripe(checkout_id: $checkoutId, success_url: $successUrl, payment_method: $paymentMethod, email: $email) {\n order_id\n checkout_url\n }\n }\n}\n";
|
|
1997
|
-
declare function createPaymentStripe(variables: Record<string, unknown>, options?: CartQueryOptions): Promise<any>;
|
|
2094
|
+
declare function lineOrigins(line: Pick<CartLineItem, 'origins' | 'quantity'>): CartLineOrigin[];
|
|
1998
2095
|
|
|
1999
2096
|
/**
|
|
2000
2097
|
* Stripe on our own page — the Payment Element, no redirect.
|
|
@@ -2601,6 +2698,8 @@ interface CheckoutState {
|
|
|
2601
2698
|
currency: string;
|
|
2602
2699
|
/** Backend checkout id (Vio Commerce CreateCheckout). */
|
|
2603
2700
|
checkoutId?: string;
|
|
2701
|
+
/** The commerce channel the checkout lives on (its cart's): every call for it uses that channel's key. */
|
|
2702
|
+
channelId?: string;
|
|
2604
2703
|
/** Full backend checkout payload (untyped upstream). */
|
|
2605
2704
|
checkout?: unknown;
|
|
2606
2705
|
/** Klarna Payments session id (native GraphQL flow). */
|
|
@@ -2729,6 +2828,17 @@ declare class CheckoutManager extends EventTarget {
|
|
|
2729
2828
|
*/
|
|
2730
2829
|
private get state();
|
|
2731
2830
|
private set state(value);
|
|
2831
|
+
/**
|
|
2832
|
+
* The options of a call for a sponsor's cart or checkout: the key of the
|
|
2833
|
+
* channel the checkout lives on — what this tab remembered for the
|
|
2834
|
+
* checkout (a return from a redirect, after the cart was cleared), the open
|
|
2835
|
+
* checkout's, else the cart's — even if a bootstrap refresh no longer lists
|
|
2836
|
+
* it (an open checkout keeps paying with its own key). Without any, the
|
|
2837
|
+
* sponsor's block as `getCartGraphQLOptions` resolves it.
|
|
2838
|
+
*/
|
|
2839
|
+
private gqlOptions;
|
|
2840
|
+
/** See `gqlOptions`. */
|
|
2841
|
+
private channelOf;
|
|
2732
2842
|
/** The last checkout + identity written to the memory — the state is set on every keystroke of the form. */
|
|
2733
2843
|
private lastRememberedSponsor;
|
|
2734
2844
|
/** Backend checkouts this page load announced with `vio:checkout-created`: one event each. */
|
|
@@ -3283,9 +3393,23 @@ declare function resolveContent(init?: ContentInit | null, doc?: Document | null
|
|
|
3283
3393
|
type PrivacyAnswer = SurfacePrivacyMode | 'unknown';
|
|
3284
3394
|
declare class VioFacade {
|
|
3285
3395
|
private apiInstance;
|
|
3396
|
+
/** Commerce clients by sponsor AND key: one sponsor may sell on several channels (one per campaign). */
|
|
3286
3397
|
private commerceClients;
|
|
3287
3398
|
private bootstrapPromise;
|
|
3288
3399
|
private cachedBootstrap;
|
|
3400
|
+
/** When the cached bootstrap arrived (ms epoch). */
|
|
3401
|
+
private bootstrapAt;
|
|
3402
|
+
/** A refresh of the bootstrap in flight (`refreshStaleBootstrap`). */
|
|
3403
|
+
private bootstrapRefresh;
|
|
3404
|
+
private bootstrapRefreshFailedAt;
|
|
3405
|
+
/** The `visibilitychange` listener is installed once per page. */
|
|
3406
|
+
private visibilityHooked;
|
|
3407
|
+
/**
|
|
3408
|
+
* Every selling block this page has seen, by `sponsorId:channelId` — so a
|
|
3409
|
+
* checkout opened on a channel keeps its key after a bootstrap refresh no
|
|
3410
|
+
* longer lists that channel (`sponsorCommerce(…, { retired: true })`).
|
|
3411
|
+
*/
|
|
3412
|
+
private seenChannels;
|
|
3289
3413
|
/** Last bootstrap failure — short backoff so cart mutations don't hammer a
|
|
3290
3414
|
* dead endpoint on every call. */
|
|
3291
3415
|
private bootstrapFailedAt;
|
|
@@ -3307,7 +3431,17 @@ declare class VioFacade {
|
|
|
3307
3431
|
/** Each cap warns once per page load. */
|
|
3308
3432
|
private warnedLocationCap;
|
|
3309
3433
|
private warnedDeclarationCap;
|
|
3310
|
-
|
|
3434
|
+
/**
|
|
3435
|
+
* One cart manager per connection (environment + key), each with its own
|
|
3436
|
+
* storage entry; `Vio.cart` is a stable front for the current one, so a
|
|
3437
|
+
* re-init with another key switches carts without the page re-subscribing.
|
|
3438
|
+
* A manager left behind keeps its carts (they come back if the page switches
|
|
3439
|
+
* back) and finishes its requests into ITS carts, never the new one's.
|
|
3440
|
+
*/
|
|
3441
|
+
private cartManagers;
|
|
3442
|
+
private cartScope;
|
|
3443
|
+
private cartFront;
|
|
3444
|
+
private readonly cartEvents;
|
|
3311
3445
|
private checkoutManager;
|
|
3312
3446
|
private analyticsManager;
|
|
3313
3447
|
/** What the surface answered of its privacy mode (`GET /v2/mobile/surface`) and when; `unknown` expires after a minute. */
|
|
@@ -3329,6 +3463,15 @@ declare class VioFacade {
|
|
|
3329
3463
|
get config(): ResolvedConfig;
|
|
3330
3464
|
/** Multi-sponsor cart manager. Reactive — listen via addEventListener('change', ...). */
|
|
3331
3465
|
get cart(): CartManager;
|
|
3466
|
+
/** The cart manager of the page's connection now (created on first use). */
|
|
3467
|
+
private currentCartManager;
|
|
3468
|
+
/**
|
|
3469
|
+
* `Vio.cart`: every property and method is the current connection's
|
|
3470
|
+
* manager's; the listeners live on the front, so they survive a switch.
|
|
3471
|
+
*/
|
|
3472
|
+
private makeCartFront;
|
|
3473
|
+
/** After `init`: the carts are the new connection's. Says `change` when that switched them. */
|
|
3474
|
+
private switchCartScope;
|
|
3332
3475
|
/** Checkout flow manager. Subscribes to cart state via the CartManager; asks here for the order's attribution. */
|
|
3333
3476
|
get checkout(): CheckoutManager;
|
|
3334
3477
|
/**
|
|
@@ -3349,6 +3492,20 @@ declare class VioFacade {
|
|
|
3349
3492
|
*/
|
|
3350
3493
|
bootstrap(): Promise<BootstrapResponse>;
|
|
3351
3494
|
get bootstrapCache(): BootstrapResponse | null;
|
|
3495
|
+
/** A bootstrap becomes the page's: when it arrived, the channels it lists, and the tab-visible refresh. */
|
|
3496
|
+
private adoptBootstrap;
|
|
3497
|
+
/**
|
|
3498
|
+
* The bootstrap is cached for the page's life, but a tab can stay open for
|
|
3499
|
+
* days: when it becomes visible again and the cached one is older than
|
|
3500
|
+
* five minutes, it is fetched again (new campaigns, channels). The old one
|
|
3501
|
+
* stays until the new one arrives — and stays if the refresh fails. Carts
|
|
3502
|
+
* keep their lines; a cart whose channel the new bootstrap no longer lists
|
|
3503
|
+
* is moved to the current channel the next time it is used (CartManager),
|
|
3504
|
+
* and an open checkout keeps paying with the key of its own channel.
|
|
3505
|
+
*/
|
|
3506
|
+
private hookVisibility;
|
|
3507
|
+
/** Fetch the bootstrap again when the cached one is older than `maxAgeMs`; never throws, never clears the cache. */
|
|
3508
|
+
private refreshStaleBootstrap;
|
|
3352
3509
|
/**
|
|
3353
3510
|
* Who a sponsor is to a shopper — `{ id, name, logoUrl, avatarUrl }` — by
|
|
3354
3511
|
* the ONE rule every element uses (`sponsorIdentityFrom`): the live
|
|
@@ -3366,10 +3523,32 @@ declare class VioFacade {
|
|
|
3366
3523
|
checkoutId?: string | null;
|
|
3367
3524
|
}): SponsorIdentity | null;
|
|
3368
3525
|
/**
|
|
3369
|
-
*
|
|
3370
|
-
*
|
|
3371
|
-
|
|
3372
|
-
|
|
3526
|
+
* The block a sponsor sells with — its `commerce.apiKey` and `channelId` —
|
|
3527
|
+
* by the rule one article = one campaign = one channel = one sponsor (see
|
|
3528
|
+
* `sponsorCommerceIn`): `ctx.channelId` → that channel's block only (a cart
|
|
3529
|
+
* created on a channel is only called with its key); else the campaign in
|
|
3530
|
+
* context — `ctx.campaignId` candidates (the click's, the element's
|
|
3531
|
+
* `vio-campaign`, an ancestor's `data-vio-campaign`), then
|
|
3532
|
+
* `Vio.init({ campaignId })` — when the sponsor takes part in it; else the
|
|
3533
|
+
* sponsor's first block that sells (the behaviour before). `campaignId:
|
|
3534
|
+
* null` means no campaign at all, not even `Vio.init`'s. `retired: true`
|
|
3535
|
+
* also answers a channel the current bootstrap no longer lists with the
|
|
3536
|
+
* block this page saw for it (an open checkout after a bootstrap refresh).
|
|
3537
|
+
* Blocks with `commerce: null` are skipped. `null` when none; never throws.
|
|
3538
|
+
*/
|
|
3539
|
+
sponsorCommerce(sponsorId: number | string | null | undefined, ctx?: SponsorCommerceContext & {
|
|
3540
|
+
retired?: boolean;
|
|
3541
|
+
}): SellingSponsor | null;
|
|
3542
|
+
/**
|
|
3543
|
+
* Get a CommerceClient scoped to a sponsor (via bootstrap) — on the
|
|
3544
|
+
* channel of the campaign in context (`ctx.campaignId`, the element's
|
|
3545
|
+
* candidates first; see `sponsorCommerce`) or of `ctx.channelId`. Without
|
|
3546
|
+
* `ctx`, the page's campaign (`Vio.init`) when the sponsor takes part in
|
|
3547
|
+
* it, else the sponsor's first selling block, as before. Clients are kept
|
|
3548
|
+
* per sponsor and key. Throws if bootstrap hasn't been called or nothing of
|
|
3549
|
+
* the sponsor sells there.
|
|
3550
|
+
*/
|
|
3551
|
+
commerceFor(sponsorId: number, ctx?: SponsorCommerceContext): CommerceClient;
|
|
3373
3552
|
/** Get a CommerceClient using an explicit commerce apiKey (skip bootstrap). */
|
|
3374
3553
|
commerceWithKey(commerceApiKey: string): CommerceClient;
|
|
3375
3554
|
/**
|
|
@@ -3479,9 +3658,10 @@ declare class VioFacade {
|
|
|
3479
3658
|
* The attribution of the order a sponsor's cart is about to become
|
|
3480
3659
|
* (ADR-0035 phase B) — what `CreateCheckout` / `UpdateCheckout` send as
|
|
3481
3660
|
* `attribution` and shopcart writes on the order: the surface (its SDK
|
|
3482
|
-
* key), the
|
|
3483
|
-
*
|
|
3484
|
-
*
|
|
3661
|
+
* key), the campaign of the order — always one the cart's sponsor takes part
|
|
3662
|
+
* in (`orderCampaign`: the cart lines' own campaign, else the page's;
|
|
3663
|
+
* without one, the campaign that explains most units of the cart under the
|
|
3664
|
+
* same rule `purchase` is split by — `cartSlices`) and, on a surface KNOWN to be `standard`
|
|
3485
3665
|
* (`privacyModeNow`), the page (`content()`'s url as origin + path, and
|
|
3486
3666
|
* title) and where the session came in: the landing the session REMEMBERS
|
|
3487
3667
|
* (`storedLanding`, else the one analytics resolved on this page) — never
|
|
@@ -3490,6 +3670,17 @@ declare class VioFacade {
|
|
|
3490
3670
|
* limits. `undefined` when there is nothing to say; never throws.
|
|
3491
3671
|
*/
|
|
3492
3672
|
orderAttribution(sponsorId?: number): CheckoutAttributionWire | undefined;
|
|
3673
|
+
/**
|
|
3674
|
+
* The campaign an order of `sponsorId` is credited to — one article = one
|
|
3675
|
+
* campaign = one sponsor, so it is always one the sponsor takes part in:
|
|
3676
|
+
* the campaign the cart's own lines were added from (their origins; the one
|
|
3677
|
+
* that explains most units), else the page's — the elements' campaigns on
|
|
3678
|
+
* the page (`vio-campaign` / `data-vio-campaign`, in document order), then
|
|
3679
|
+
* `Vio.init({ campaignId })` — the first one active with that sponsor.
|
|
3680
|
+
* `undefined` when neither says one (the slices then decide). Without a
|
|
3681
|
+
* sponsor, the page's campaign as before.
|
|
3682
|
+
*/
|
|
3683
|
+
private orderCampaign;
|
|
3493
3684
|
/** The landing the session remembers: what the first page stored, else what analytics resolved on this page load (consent pending); null otherwise. */
|
|
3494
3685
|
private rememberedLanding;
|
|
3495
3686
|
/**
|
|
@@ -3586,7 +3777,7 @@ declare function writeInternal(internal: boolean, storage?: StorageLike | null |
|
|
|
3586
3777
|
*
|
|
3587
3778
|
* RELEASE CHECKLIST: bump together with package.json (see CONTRIBUTING).
|
|
3588
3779
|
*/
|
|
3589
|
-
declare const SDK_VERSION = "0.
|
|
3780
|
+
declare const SDK_VERSION = "0.33.0";
|
|
3590
3781
|
|
|
3591
3782
|
/**
|
|
3592
3783
|
* Vipps MobilePay's own button, the way the design guidelines ask for it.
|