@adobe/magento-storefront-events-sdk

中文文档
1.18.0发布于 2026/08/11MITTypeScriptESM + CJS近 30 天下载 24.8万

SDK for working with events on an Adobe Commerce storefront

原始使用文档
文档目录10 节
  1. Overview
  2. Installation
  3. Quick start
  4. Schemas and supported events
  5. API reference
  6. Context
  7. Publish
  8. Subscribe
  9. Unsubscribe
  10. Support

Adobe Commerce Events SDK

version downloads size build typescript contributing

Overview

This package serves as the foundation for eventing on an Adobe Commerce storefront. It provides access to the Adobe data layer, and an event publishing service.

You can handle the events in a custom implementation, or use the Adobe Commerce Events Collectors package that listens for events and sends them to Adobe Commerce edges for processing.

Note: When an event is published through the SDK, all subscribers to that event get notified. Defining a custom listener shouldn't preclude you from also running the Adobe Commerce Events Collectors.

Our context schemas are designed to simplify forwarding to two edges:

  • Adobe Commerce Data Services (maintained by Adobe Engineering and used to power merchant performance dashboards)
  • Adobe Experience Platform (requires a subscription and additional merchant setup; data can be used by merchants inside the Adobe Experience Platform for detailed analytics, targeted merchandising, real time customer data profiles, and more)

Installation

This SDK can be used as a hosted script, or bundled in a JavaScript application. The script version is hosted on jsdelivr, and the bundled version is hosted on npm.

To load the SDK as a script, use the following snippet.

<script src="https://cdn.jsdelivr.net/npm/@adobe/commerce-events-sdk/dist/index.js"></script>

To install the script as a dependency, run this command.

npm install @adobe/commerce-events-sdk

Quick start

Once imported, you have access to the four main functions of the Events SDK.

  • Context - set context data
  • Publish - publish events
  • Subscribe - subscribe to events
  • Unsubscribe - unsubscribe from events

Below is a code example of how to get started.

IMPORTANT Relevant context data must be populated before publishing events that require it.

import mse from "@adobe/commerce-events-sdk";
// handler - can go in a different module
function addToCartHandler(event) {
    // do something with the event
}
// subscribe to events
mse.subscribe.addToCart(addToCartHandler);

// set context data
const shoppingCartContext = {
    id: "1",
    items: [
        {
            id: "shoppingCart",
            product: {
                productId: 111111,
                sku: "ts001",
                pricing: {
                    regularPrice: 20.0,
                    currencyCode: "USD",
                },
            },
            quantity: 1,
        },
    ],
};
mse.context.setShoppingCart(shoppingCartContext);

// publish events
mse.publish.addToCart();

// unsubscribe from events
mse.unsubscribe.addToCart(addToCartHandler);

Schemas and supported events

The below methods allow you to set specific contexts based on the SDK schema and to publish a set of events supported by this API.

Addiontally, you can publish custom events or add a custom context to a supported event.

API reference

The SDK is broken down into four major parts: Context, Publish, Subscribe, Unsubscribe.

Context

Pre-defined contexts are listed in the ContextManager.

Examples of setting context under examples/events/example-contexts.

Required contexts per event under examples/events/.

Publish

Pre-defined publishable events are listed in the PublishManager. Any event that is not part of the PublishManager should be handled as a custom event.

A list of examples on publishing events is available under examples.

Subscribe

Supported subscibe events are defined in the SubscribeManager. Any event that is not part of the SubscribeManager should be handled as a custom event.

Note that a large number of custom events with different schemas is an anti-pattern (most events you need should be supported by SubscribeManager). If there are standard events you believe should be supported by SubscribeManager, please submit an issue.

Note that it is rare for an application utilizing the SDK to have to subscribe to events. In most cases subscribes and unsubscribes are handled by the Storefront Events Collector.

Unsubscribe

Supported unsubscibe events are defined in the UnubscribeManager.

As noted above, it is rare for an SDK and Collector user to have to call these functions directly.

Support

If you have any questions or encounter any issues, please reach out on GitHub.

版本与发布记录

@adobe/magento-storefront-events-sdk 共发布 263 个版本,首次发布于 2021/03/18;过去 12 个月发布了 9 个版本。

版本发布日期距今
1.18.0latest2026/08/112 个月前
0.0.0-84da724408a456d7ef1cd15b1cb6c1c6da4f83e3qa2026/08/112 个月前
0.0.0-7387e97ff463b8c6f589cb378485c553591016bc2026/07/303 个月前
1.17.02026/05/046 个月前
0.0.0-073607462513e30948d67e0f5de3f6770bc194e02026/05/046 个月前
0.0.0-278062401f574c64949b443e2e19a7d80b93b7d32026/05/016 个月前

关于 @adobe/magento-storefront-events-sdk 的常见问题

@adobe/magento-storefront-events-sdk 是什么?

SDK for working with events on an Adobe Commerce storefront

如何安装 @adobe/magento-storefront-events-sdk?

在项目目录运行 npm install @adobe/magento-storefront-events-sdk,或使用 pnpm add / yarn add / bun add。

@adobe/magento-storefront-events-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/magento-storefront-events-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@adobe/magento-storefront-events-sdk 可以商用吗?

@adobe/magento-storefront-events-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@adobe/magento-storefront-events-sdk 的下载量有多少?

根据 npm 官方下载统计,@adobe/magento-storefront-events-sdk 在 2026/10/05 – 2026/11/03 这 30 天内被下载 247,650 次,日均约 8,255 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/magento-storefront-events-sdk 还在维护吗?

最新版本 1.18.0 发布于 2026/08/11(2 个月前);至今共发布 263 个版本,其中过去 12 个月发布了 9 个;首次发布于 2021/03/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。