@epcc-sdk/sdks-cart-checkout-order

中文文档
0.8.3发布于 2026/11/03TypeScriptESM + CJS近 30 天下载 2129

A TypeScript client for the Elastic Path carts, checkout and orders API. The functions, types and Zod schemas are generated from the OpenAPI spec of the API.

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start
  3. Base URL
  4. Credentials
  5. Make the client yourself
  6. Zod schemas
  7. MCP tools

@epcc-sdk/sdks-cart-checkout-order

A TypeScript client for the Elastic Path carts, checkout and orders API. The functions, types and Zod schemas are generated from the OpenAPI spec of the API.

Installation

npm install @epcc-sdk/sdks-cart-checkout-order

Quick start

import {
  createCartCheckoutOrderClient,
  getCarts,
} from "@epcc-sdk/sdks-cart-checkout-order"

const client = createCartCheckoutOrderClient({
  baseUrl: "https://euwest.api.elasticpath.com",
  clientId: process.env.EPCC_CLIENT_ID!,
  clientSecret: process.env.EPCC_CLIENT_SECRET!,
})

const { data, error } = await getCarts({ client })

The client gets an access token and adds it to each request. It gets a new token before the token expires. After a 401 response, it gets a new token and sends the request one more time. After a 408 or 429 response, or after some server and network errors, it waits and sends the request again.

Pass the client to each operation. The package also exports a client that has no credentials. If you call an operation without { client }, it uses that client and the API returns a 401 response.

A failed request does not throw. The operation returns the error in error. To make operations throw, add config: { throwOnError: true } to the factory options.

Base URL

Set baseUrl to the API host of your region, with no path. Each operation adds its own path.

Credentials

OptionGrant type
clientId and clientSecretClient credentials. Use it only on a server, because it contains a secret.
clientIdImplicit. You can use it in a browser.
tokenA token that you got yourself. The client cannot replace it, so a 401 response is final.
providerYour own TokenProvider function.
sourceA TokenSource that you keep, for example to clear the token when a user signs out.

These options change the default behavior:

OptionWhat it does
storageWhere the client keeps the token. The default is memoryStorage. localStorageAdapter keeps the token across page loads and browser tabs.
leewaySecondsHow many seconds before expiry the client gets a new token.
retryThe options of createRetryFetch. Set it to false to stop the retries.
fetchThe fetch function that the client uses for all requests, including token requests.
configClient configuration, for example headers. It overrides the values that the factory sets.

Make the client yourself

The package exports the parts that the factory uses. Use them when you need your own token source or your own fetch.

import {
  clientCredentialsProvider,
  createAuthCallback,
  createAuthenticatedFetch,
  createClient,
  createConfig,
  createRetryFetch,
  createTokenSource,
} from "@epcc-sdk/sdks-cart-checkout-order"

const source = createTokenSource(
  clientCredentialsProvider({
    baseUrl: "https://euwest.api.elasticpath.com",
    clientId: process.env.EPCC_CLIENT_ID!,
    clientSecret: process.env.EPCC_CLIENT_SECRET!,
  }),
)

const client = createClient(
  createConfig({
    baseUrl: "https://euwest.api.elasticpath.com",
    auth: createAuthCallback(source),
    fetch: createRetryFetch({ fetch: createAuthenticatedFetch(source) }),
  }),
)
  1. Make both wrappers from the same source. createAuthenticatedFetch replaces only a token that came from its own source.
  2. Put createAuthenticatedFetch inside createRetryFetch. In the other order, each retry sends the expired token again.

Do not add the token with a request interceptor. An interceptor cannot see the response, so it cannot get a new token after a 401 response.

Zod schemas

The ./zod export has a Zod schema for each request and response. zod 4 is an optional peer dependency, so the main export does not import it.

import { zGetCartsResponse } from "@epcc-sdk/sdks-cart-checkout-order/zod"

const result = zGetCartsResponse.safeParse(data)

A field that the spec gives as int64 is a number in the types and in the schemas.

MCP tools

The ./mcp export has one Model Context Protocol (MCP) tool for each operation, for MCP SDK v2. You need zod 4 and @modelcontextprotocol/server 2 only for this export.

import { McpServer } from "@modelcontextprotocol/server"
import { tools } from "@epcc-sdk/sdks-cart-checkout-order/mcp"

const server = new McpServer({ name: "cart-checkout-order", version: "1.0.0" })

for (const tool of tools({ client })) {
  server.registerTool(tool.name, tool.config, tool.handler)
}
  • Each tool sends its requests with the client that you give it. To send a header with each request, such as EP-Store-Id, set it in config.headers of the client.
  • For one tool, use its factory. The name of the factory is the operation name with Tool added, for example getCartsTool.
  • The name of a tool is cart_checkout_order_ and the operation name in snake case, for example cart_checkout_order_get_carts.
  • The arguments of a tool are in path, query, headers and body. The Authorization header comes from the client.
  • tool.config._meta["com.elasticpath/operation"].risk is read, create, update or delete. The tool annotations come from it. To register only the read tools, keep the tools where risk is read.
  • A tool returns an API error as an isError result. It does not throw.

These operations have a risk that is different from the default for their HTTP method:

  • anonymizeOrders is update, because it replaces customer data in orders and cannot be undone.

版本与发布记录

@epcc-sdk/sdks-cart-checkout-order 共发布 22 个版本,首次发布于 2025/03/14;过去 12 个月发布了 15 个版本。

版本发布日期距今
0.8.3latest2026/11/0310 天前
0.8.22026/10/3015 天前
0.8.12026/10/2816 天前
0.8.02026/10/2718 天前
0.7.02026/10/2123 天前
0.6.02026/10/2024 天前

关于 @epcc-sdk/sdks-cart-checkout-order 的常见问题

@epcc-sdk/sdks-cart-checkout-order 是什么?

A TypeScript client for the Elastic Path carts, checkout and orders API. The functions, types and Zod schemas are generated from the OpenAPI spec of the API.

如何安装 @epcc-sdk/sdks-cart-checkout-order?

在项目目录运行 npm install @epcc-sdk/sdks-cart-checkout-order,或使用 pnpm add / yarn add / bun add。

@epcc-sdk/sdks-cart-checkout-order 支持 TypeScript 吗?

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

@epcc-sdk/sdks-cart-checkout-order 支持 ESM 还是 CommonJS?

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

@epcc-sdk/sdks-cart-checkout-order 可以商用吗?

@epcc-sdk/sdks-cart-checkout-order 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@epcc-sdk/sdks-cart-checkout-order 的下载量有多少?

根据 npm 官方下载统计,@epcc-sdk/sdks-cart-checkout-order 在 2026/10/14 – 2026/11/12 这 30 天内被下载 2,129 次,日均约 71 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@epcc-sdk/sdks-cart-checkout-order 还在维护吗?

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