import type { ObjectValues, Prettify } from "./utility"; /** * Custom events with a specific namespace and identifier. */ export type NubeSDKCustomEvent = `custom:${string}:${string}`; /** * List of events that can be sent by the SDK. * * These events are used to trigger various platform interactions, * such as updating UI slots, validating the cart, and modifying configurations. * * @constant * * @property {"cart:validate"} CART_VALIDATE - Triggered to validate the current cart state. * @property {"cart:before_update:result"} CART_BEFORE_UPDATE_RESULT - Used to send the result of the cart before update handling. * @property {"cart:add"} CART_ADD - Used to add a cart item. * @property {"cart:remove"} CART_REMOVE - Used to remove a cart item. * @property {"cart:open"} CART_OPEN - Used to open the cart. * @property {"config:set"} CONFIG_SET - Used to update the SDK configuration. * @property {"ui:slot:set"} UI_SLOT_SET - Used to update a UI slot with new content. * @property {"shipping:update:label"} SHIPPING_UPDATE_LABEL - Used to update custom labels for shipping options. * @property {"order:add:tracking_statuses"} ORDER_ADD_TRACKING_STATUSES - Used to add tracking statuses to an order. * @property {"coupon:add"} COUPON_ADD - Used to add a coupon to the cart. * @property {"coupon:remove"} COUPON_REMOVE - Used to remove a coupon from the cart. * @property {"shipping:select"} SHIPPING_SELECT - Used to select shipping option. * @property {"order:add:extra"} ORDER_ADD_EXTRA - Used to add additional metadata to an order. * @property {"account:register"} ACCOUNT_REGISTER - Used to autocomplete the signup form in the storefront. */ export const SENDABLE_EVENT = { CART_VALIDATE: "cart:validate", CART_BEFORE_UPDATE_RESULT: "cart:before_update:result", CART_ADD: "cart:add", CART_REMOVE: "cart:remove", CART_OPEN: "cart:open", CONFIG_SET: "config:set", UI_SLOT_SET: "ui:slot:set", SHIPPING_UPDATE_LABEL: "shipping:update:label", ORDER_ADD_TRACKING_STATUSES: "order:add:tracking_statuses", ORDER_ADD_EXTRA: "order:add:extra", COUPON_ADD: "coupon:add", COUPON_REMOVE: "coupon:remove", SHIPPING_SELECT: "shipping:select", ACCOUNT_REGISTER: "account:register", } as const; /** * Represents the possible events that can be sent within NubeSDK. * These events trigger specific actions within the SDK. */ export type NubeSDKSendableEvent = Prettify< ObjectValues | NubeSDKCustomEvent >; /** * List of all available events in the SDK. * * This object contains both core and sendable events used for handling * various lifecycle states and user interactions within the checkout process. * * @constant * * @property {"*"} ALL - Wildcard listener for all events. * @property {"page:loaded"} PAGE_LOADED - Fired when the page is loaded and the SDK is ready to be used. * @property {"cart:update"} CART_UPDATE - Fired when the cart state is updated. * @property {"cart:before_update"} CART_BEFORE_UPDATE - Fired before the cart state is updated. * @property {"cart:view"} CART_VIEW - Fired when the user views their shopping cart. * @property {"cart:add:success"} CART_ADD_SUCCESS - Fired when a cart item is added successfully. * @property {"cart:add:fail"} CART_ADD_FAIL - Fired when a cart item is added unsuccessfully. * @property {"cart:remove:success"} CART_REMOVE_SUCCESS - Fired when a cart item is removed successfully. * @property {"cart:remove:fail"} CART_REMOVE_FAIL - Fired when a cart item is removed unsuccessfully. * @property {"checkout:ready"} CHECKOUT_READY - Triggered when checkout is fully initialized. * @property {"checkout:success"} CHECKOUT_SUCCESS - Fired upon successful checkout completion. * @property {"shipping:update"} SHIPPING_UPDATE - Fired when a non-custom shipping data change occurs. * @property {"shipping:select:success"} SHIPPING_SELECT_SUCCESS - Fired when a shipping selected successfully. * @property {"shipping:select:fail"} SHIPPING_SELECT_FAIL - Fired when a shipping selected unsuccessfully. * @property {"customer:update"} CUSTOMER_UPDATE - Fired when the customer data is updated. * @property {"order:update"} ORDER_UPDATE - Fired when the order data is updated. * @property {"payment:update"} PAYMENT_UPDATE - Fired when the payment data is updated. * @property {"coupon:add:success"} COUPON_ADD_SUCCESS - Fired when a coupon is added successfully. * @property {"coupon:add:fail"} COUPON_ADD_FAIL - Fired when a coupon is added unsuccessfully. * @property {"coupon:remove:success"} COUPON_REMOVE_SUCCESS - Fired when a coupon is removed successfully. * @property {"coupon:remove:fail"} COUPON_REMOVE_FAIL - Fired when a coupon is removed unsuccessfully. * @property {"location:updated"} LOCATION_UPDATED - Fired when the location is updated. * @property {"quickbuy:open"} QUICKBUY_OPEN - Fired when the quickbuy modal is opened. * @property {"quickbuy:close"} QUICKBUY_CLOSE - Fired when the quickbuy modal is closed. * @property {"product:variant_selected"} PRODUCT_VARIANT_SELECTED - Fired when a product variant is selected. * @property {"page:scroll"} PAGE_SCROLL - Fired when the page scroll position changes. * @property {"page:exit_intent"} PAGE_EXIT_INTENT - Fired when the cursor leaves through the top edge of the viewport (desktop exit intent). * @property {"page:visibility_change"} PAGE_VISIBILITY_CHANGE - Fired when the store becomes hidden/backgrounded or the user switches tabs (mobile/touch). * @property {...typeof SENDABLE_EVENT} - Includes all sendable events. */ export const EVENT = { ALL: "*", PAGE_LOADED: "page:loaded", CART_UPDATE: "cart:update", CART_BEFORE_UPDATE: "cart:before_update", CART_VIEW: "cart:view", CART_ADD_SUCCESS: "cart:add:success", CART_REMOVE_SUCCESS: "cart:remove:success", CART_ADD_FAIL: "cart:add:fail", CART_REMOVE_FAIL: "cart:remove:fail", CHECKOUT_READY: "checkout:ready", CHECKOUT_SUCCESS: "checkout:success", SHIPPING_UPDATE: "shipping:update", SHIPPING_SELECT_SUCCESS: "shipping:select:success", SHIPPING_SELECT_FAIL: "shipping:select:fail", CUSTOMER_UPDATE: "customer:update", ORDER_UPDATE: "order:update", PAYMENT_UPDATE: "payment:update", COUPON_ADD_SUCCESS: "coupon:add:success", COUPON_REMOVE_SUCCESS: "coupon:remove:success", COUPON_ADD_FAIL: "coupon:add:fail", COUPON_REMOVE_FAIL: "coupon:remove:fail", LOCATION_UPDATED: "location:updated", QUICKBUY_OPEN: "quickbuy:open", QUICKBUY_CLOSE: "quickbuy:close", PRODUCT_VARIANT_SELECTED: "product:variant_selected", PAGE_SCROLL: "page:scroll", PAGE_EXIT_INTENT: "page:exit_intent", PAGE_VISIBILITY_CHANGE: "page:visibility_change", ...SENDABLE_EVENT, } as const; /** * Represents the possible events that can be listened to within NubeSDK that end with :success. */ export type NubeSDKListenableSuccessEvent = Extract< NubeSDKListenableEvent, `${string}:success` >; /** * Represents the possible events that can be listened to within NubeSDK. * These events notify the application about changes in state or actions. */ export type NubeSDKListenableEvent = Prettify< ObjectValues | NubeSDKCustomEvent >;