@beamimpact/web-sdk
Version:
The Beam SDK enables brands to connect with their customers over shared values, not transactional discounts, to build stronger loyalty. Our integration achieves this by allowing customers to (a) choose a nonprofit where the brand will donate part of their
113 lines (109 loc) • 4.72 kB
TypeScript
import * as lodash from 'lodash';
import { B as BeamCartAPIConfig, a as BeamCartValues } from './update-cart-CauFT0AF.esm.js';
import { T as TCart } from './cart-contents-CLT7p7Gd.esm.js';
import '../components/post-purchase.js';
import { b as postTransaction } from './routes-DahRzf8t.esm.js';
import { T as TUrl, L as LANGUAGES } from './types-DfRc36jU.esm.js';
type BeamShopifyCartIntegrationConfig = BeamCartAPIConfig & {
storeId: number;
chainId?: number;
};
/**
* @main registerCartIntegration - set up event listeners to integrate Beam with Shopify cart
* @return {boolean} returns true if NEW listeners were created, false if setup was already done
*/
declare function registerCartIntegration(config: BeamShopifyCartIntegrationConfig, autoUpdateShopifyCartAttributes?: boolean): Promise<boolean>;
declare function appendToShopifyCartBeamAttribute(config: BeamShopifyCartIntegrationConfig): Promise<void>;
/**
* Gathers the base Beam data needed for updating a Shopify cart's metadata
*/
declare function getBeamAttributesForCart(config: BeamShopifyCartIntegrationConfig): Promise<{
showBeam: boolean | undefined;
remoteSessionId: any;
beamCartId: string | undefined;
cartId: string | undefined;
chainId: number | undefined;
storeId: number;
}>;
/**
* Adds Statsig data to a Shopify cart
*/
declare const appendStatsigToShopifyCartAttributes: typeof appendToShopifyCartBeamAttribute;
/**
* Detects change in cart since last page load,
* by calling GET /cart.js, and returns cart values.
* Used for:
* - Form-based carts where the page refreshes to modify cart instead of using AJAX calls
* - Hydrogen/GraphQL based carts (needs to be integrated manually)
*/
declare function getCurrentCart(config: BeamShopifyCartIntegrationConfig): Promise<{
changed: boolean;
cart: {
cartId: string;
subtotal: number;
itemCount: number;
currencyCode: string;
} & TCart;
}>;
/**
* trackCart - Backwards-compatible alias for updateCart
*/
declare const trackCart: lodash.DebouncedFuncLeading<(config: BeamCartAPIConfig, cartValues: BeamCartValues, isFirstCartUpdateOnPageLoad?: any) => Promise<void>>;
/**
* Helper function to get the Shopify cart attributes
*/
declare const getShopifyCart: () => Promise<any>;
/**
* Sends Beam data to Shopify to integrate with order as custom attributes.
* Memoized so that calls with the same data as the previous don't create additional API calls to Shopify.
* This will do an append, not a full overwrite of the attributes in the beam property
*/
declare const appendBeamAttributesToCart: (args_0: {
selectedNonprofitId?: number | null | undefined;
selectionId?: string | undefined;
beamCartId?: string | undefined;
cartId?: string | undefined;
chainId?: number | undefined;
storeId?: number | undefined;
showBeam?: boolean | undefined;
remoteSessionId?: string | undefined;
}) => Promise<void>;
/**
* Sends Beam data to Shopify to integrate with order as custom attributes.
* Memoized so that calls with the same data as the previous don't create additional API calls to Shopify.
* This method force-updates the "beam" attribute with the values passed in
*/
declare const addBeamAttributesToCart: (args_0: {
selectedNonprofitId?: number | null | undefined;
selectionId?: string | undefined;
beamCartId?: string | undefined;
cartId?: string | undefined;
chainId?: number | undefined;
storeId?: number | undefined;
}) => Promise<void>;
declare global {
interface Window {
statsig?: any;
}
}
type TBeamOrderPageParams = Parameters<typeof postTransaction>[0]["requestBody"] & {
storeId?: number;
postalCode?: string;
countryCode?: string;
orderId: string;
email: string;
cartTotal: number;
cart: TCart;
discountCodes: string[];
promoCodes: string[];
htmlPromoCodes: string;
currencyCode: string;
parentSelector: string;
apiKey: string;
baseUrl: TUrl;
domain?: string;
lang: LANGUAGES;
debug: boolean;
};
declare function showBeamOrderPageWidgets({ parentSelector, apiKey, baseUrl, storeId, postalCode, discountCodes, countryCode, orderId, email, cartTotal, cart, promoCodes, htmlPromoCodes, currencyCode, domain, lang, debug, }: TBeamOrderPageParams): Promise<void>;
export { type BeamShopifyCartIntegrationConfig as B, type TBeamOrderPageParams as T, addBeamAttributesToCart as a, appendBeamAttributesToCart as b, appendStatsigToShopifyCartAttributes as c, appendToShopifyCartBeamAttribute as d, getCurrentCart as e, getShopifyCart as f, getBeamAttributesForCart as g, registerCartIntegration as r, showBeamOrderPageWidgets as s, trackCart as t };