UNPKG

salsify-experiences-sdk

Version:

SDK to be used by commerce websites to implement product experiences.

60 lines 1.78 kB
"use strict"; /** * @module events */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const navigation_1 = __importDefault(require("./navigation")); const add_to_cart_1 = __importDefault(require("./add-to-cart")); /** * This class is responsible for handling events. * * It is responsible for exposing the public methods for triggering each different type of event. */ class EventsApi { #logger; #options; #ecApi; /** @internal */ constructor(logger, options, ecApi) { this.#logger = logger; this.#options = options; this.#ecApi = ecApi; } /** * Triggers the `navigation` event. * * @example * ```typescript * salsify.events.navigation({ * productIdType: "SKU", * productId: "123", * }); * ``` * * @param options The options to pass to the event handler. */ navigation(options) { this.#options?.beforeNavigation?.(options); new navigation_1.default(this.#logger).handle(options); this.#options?.onNavigation?.(options); } /** * Triggers the `addToCart` event. * * @example * ```javascript * const salsify = window.salsifyExperiencesSdk; * const options = { quantity: 1, productIdType, productId }; * salsify.events.addToCart(options); * ``` * @param options The options to pass to the event handler. */ addToCart(options) { new add_to_cart_1.default(this.#logger).handle(options, { lastEcRenderConfig: this.#ecApi?.lastRenderConfig }); } } exports.default = EventsApi; //# sourceMappingURL=index.js.map