@amboras-dev/storefront-core

中文文档
2026.11.9发布于 2026/11/13UNLICENSEDTypeScriptES Module近 30 天下载 7694

The platform half of every Amboras storefront: cart, checkout, payments, auth, orders, subscriptions, catalogue data, analytics, consent, plugin slots, edge proxy and the Next config. Stores keep only design; they import this. ESM, React 19, Next 16.

原始使用文档
文档目录11 节
  1. How a store uses it
  2. 1. Configure once: lib/amboras.ts
  3. 2. Shims keep every import path
  4. 3. The registry and payment UI are injected
  5. Overriding a hook
  6. 4. Next config and Tailwind
  7. 5. The proxy matcher
  8. 6. Feature switches: unknown is not off
  9. 7. Build gates
  10. Entry points
  11. Versions

@amboras-dev/storefront-core

The platform half of every Amboras storefront: cart, checkout logic, payments, auth, orders, subscriptions, catalogue data, analytics, consent, plugin slots, the edge proxy and the Next config. A store keeps only its design. Everything here used to be copied into each of the ~73k store repos at fork time, and drifted from there.

One versioned package means a fix ships as a version bump, rolled out in stages, instead of a file rewrite on every deploy.

This release (2026.11.0) moves logic only. Core's own UI (/ui, the Shopify-style checkout) comes in phase 3. Until then the store passes its own payment surfaces in (see paymentUi).

How a store uses it

1. Configure once: lib/amboras.ts

Next inlines process.env.NEXT_PUBLIC_* only in app source, so the store reads them and hands them to core:

import { configureCore } from '@amboras-dev/storefront-core/config'

configureCore({
  medusaUrl: process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL,
  publishableKey: process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
  storeId: process.env.NEXT_PUBLIC_STORE_ID,
  analyticsEndpoint: process.env.NEXT_PUBLIC_ANALYTICS_ENDPOINT,
  analyticsIngestUrl: process.env.NEXT_PUBLIC_ANALYTICS_INGEST_URL,
  analyticsKey: process.env.NEXT_PUBLIC_ANALYTICS_KEY,
  googleMapsApiKey: process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY,
})

Core reads the config lazily, at call time, so module order does not matter.

In production, a missing Medusa URL throws MissingMedusaUrlError on the first config read. Only development and tests fall back to http://localhost:9000.

2. Shims keep every import path

Each file core owns stays in the store as a one-line re-export, so existing design files (AI-restyled ones included) keep compiling unchanged:

// hooks/use-cart.ts
export * from '@amboras-dev/storefront-core/client/use-cart'

core-manifest.json lists every shim path and its target. The orchestrator builds the AI lock list from it and its version-floor check makes sure each shim exists.

Store pathCore import
hooks/<name>.ts@amboras-dev/storefront-core/client/<name>
lib/<path>.ts@amboras-dev/storefront-core/lib/<path>
types/index.ts@amboras-dev/storefront-core/types
components/ClientPluginSlot.tsx@amboras-dev/storefront-core/shell/client-plugin-slot
components/PluginSlot.tsxcreatePluginSlot from @amboras-dev/storefront-core/server/plugin-slot
proxy.tsproxy from @amboras-dev/storefront-core/edge

3. The registry and payment UI are injected

Core never imports the store's generated app/_generated/plugin-registry or its checkout components.

// components/PluginSlot.tsx (server)
import { PLUGIN_REGISTRY } from '@/app/_generated/plugin-registry'
import { createPluginSlot } from '@amboras-dev/storefront-core/server/plugin-slot'
export const PluginSlot = createPluginSlot(PLUGIN_REGISTRY)
export default PluginSlot
// app/providers.tsx (client)
import { CoreProvider } from '@amboras-dev/storefront-core/client'
import { PLUGIN_REGISTRY } from '@/app/_generated/plugin-registry'
import { StripePaymentForm } from '@/components/checkout/stripe-payment-form'
// … SavedMethodSelector, SaveMethodConsent, PayPalSmartButtons
;<CoreProvider
  registry={PLUGIN_REGISTRY}
  pluginConfigs={pluginConfigs}
  paymentUi={{ StripePaymentForm, SavedMethodSelector, SaveMethodConsent, PayPalSmartButtons }}
>
  {children}
</CoreProvider>

Payment plugins add an adapter with registerPaymentProvider(config) from @amboras-dev/storefront-core/lib/payment-providers/registry.

Overriding a hook

A local export next to a shim's export * only changes the store's own imports. Core's hooks import each other directly, so to change a hook core itself calls, pass it to CoreProvider:

// app/providers.tsx. Module scope: overrides are read once.
const overrides: CoreHookOverrides = {
  useCart: (base) => {
    const cart = base()
    return { ...cart /* … */ }
  },
}

;<CoreProvider registry={PLUGIN_REGISTRY} overrides={overrides}>
  {children}
</CoreProvider>

Overridable: useCart, useRegion, useAuth, useListingParams, usePaymentProviders, usePaymentMethodsConfig, useStripeErrorCopy, useExpressCheckout. Every other hook is called only by store code, so its shim is already the override. /lib functions are not overridable. An override is a hook: call base on every render or on none. overrides is read once, on the first render: keep it stable (module scope), since adding or removing one later would change hook order.

4. Next config and Tailwind

// next.config.mjs
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
import { resolveAmborasImageHosts, withAmborasCore } from '@amboras-dev/storefront-core/next-config'

const __dirname = dirname(fileURLToPath(import.meta.url))
const imageHosts = await resolveAmborasImageHosts()

/** @type {import('next').NextConfig} */
const nextConfig = {
  /* store options */
}

export default withAmborasCore(nextConfig, { root: __dirname, imageHosts })

Keep that shape. The orchestrator (e2b previews, check_build) and the Shopify cloner patch next.config.mjs by regex, and all of them anchor on the literal const nextConfig = {. That is where allowedDevOrigins (previews) and distDir: process.env.NEXT_DIST_DIR (check_build's isolated build) are injected. Keep the store's options in that literal object and apply core only on the export line. const nextConfig = withAmborasCore({...}) matches none of the patterns, so previews and check_build silently lose their patches. withAmborasCore spreads the object, so the injected keys survive. test/core/next-config-patchers.test.ts runs the orchestrator's and the cloner's real patterns against this snippet. Resolve the hosts with a top-level await; never export an async function.

withAmborasCore adds core to transpilePackages, pins turbopack.root, and builds images.remotePatterns from exact hosts only. The hosts are platform data, not code. resolveAmborasImageHosts() reads them once, at config load, from the first source that answers:

  1. the platform: GET <platform>/api/v1/public/storefront/image-hosts?store=<NEXT_PUBLIC_STORE_ID>, with a 2s timeout. <platform> is AMBORAS_PLATFORM_API_URL, else derived from the Medusa host (api[-env].amboras.com becomes core[-env].amboras.com), else https://core.amboras.com;
  2. AMBORAS_IMAGE_HOSTS: a JSON array or a comma list of exact host names;
  3. the baked fallback AMBORAS_FALLBACK_IMAGE_HOSTS (the template's 13 hosts).

The exact host of NEXT_PUBLIC_MEDUSA_BACKEND_URL is always added, and the local-dev hosts are added when not on Vercel. It is the same algorithm as the template's amboras:image-hosts-reader block. Without imageHosts, withAmborasCore uses AMBORAS_IMAGE_HOSTS or the fallback list (it does not call the network). Any hostname containing * throws, whether it is ** or *.cloudfront.net, because a wildcard makes /_next/image an open proxy.

Release order: the orchestrator's image-hosts endpoint must be live in production before any production store adopts 2026.11.2. Without it a production build uses the fallback list. In a 1% production sample of product images, about 4% were on merchant hosts that the list does not include, so they would fail in /_next/image.

Add @source "../node_modules/@amboras-dev/storefront-core"; to app/globals.css (see presets/tailwind.md).

5. The proxy matcher

Next reads config from proxy.ts statically, so it cannot come from a package. The store keeps a literal copy of proxyConfig from @amboras-dev/storefront-core/edge:

export { proxy } from '@amboras-dev/storefront-core/edge'
export const config = {
  matcher: [
    /* copy of proxyConfig.matcher */
  ],
}

amboras-check proxy-matcher fails when the copy differs from the installed core's matcher.

6. Feature switches: unknown is not off

useStoreConfig() (client) and getStoreConfig() (server) read Medusa's GET /store/config. Each feature flag is true, false or null, and null means unknown. Everything is unknown while loading, on an older Medusa, on a 503 and on a network error, and a flag whose reader failed in Medusa is null too. Gate UI with isFeatureOff(feature), which is true only when Medusa said false. Never read features.x as a boolean, because null is falsy and would hide a feature nobody turned off. checkout_settings and brand are null when unknown. useCheckoutSettings then falls back to /store/checkout-settings.

7. Build gates

npx amboras-check            # plugin slots, store quirks, redirect boundaries, consent scroll, proxy matcher
npx amboras-check slots      # one gate

Entry points

EntryWhat"use client"
/clientCoreProvider (registry, payment UI, hook overrides), ClientPluginSlot, configyes
/client/<hook>one hook file, same exports as the template'sper file
/servercreatePluginSlot, PluginSlot, getPluginConfigs, medusaFetch, getStoreConfig, configno
/lib/<path>logic modules (checkout, cart, payment providers, analytics, consent…)per file
/edgeproxy, proxyConfigno
/next-configwithAmborasCore, resolveAmborasImageHostsno
/configconfigureCore, getCoreConfigno
/types, /types/pluginsshared types, slot typesno

dist/ is tsc output, file for file: every "use client" stays on the file that had it.

Versions

CalVer YYYY.M.N (npm run version:next). Plugins declare peerDependencies['@amboras-dev/storefront-core']: '>=2026.11.0'. Deprecated names stay exported for at least two minors. api/*.api.md is the public surface of /client, /server and /next-config; CI fails when it changes without the report being updated. api/shim-exports.json lists the export names behind /client/* and /lib/*; CI fails when one is removed or renamed.

See CONTRIBUTING.md for development and release.

版本与发布记录

@amboras-dev/storefront-core 共发布 19 个版本,首次发布于 2026/11/02;过去 12 个月发布了 19 个版本。

版本发布日期距今
2026.11.9latest2026/11/13今天
2026.11.9-rc.1next2026/11/13今天
2026.11.9-rc.02026/11/112 天前
2026.11.82026/11/112 天前
2026.11.8-rc.42026/11/103 天前
2026.11.8-rc.32026/11/103 天前

关于 @amboras-dev/storefront-core 的常见问题

@amboras-dev/storefront-core 是什么?

The platform half of every Amboras storefront: cart, checkout, payments, auth, orders, subscriptions, catalogue data, analytics, consent, plugin slots, edge proxy and the Next config. Stores keep only design; they import this. ESM, React 19, Next 16.

如何安装 @amboras-dev/storefront-core?

在项目目录运行 npm install @amboras-dev/storefront-core,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=16.3.0)、react(>=19.0.0)、sonner(>=2.0.7)、react-dom(>=19.0.0)、posthog-js(>=1.200.0)、lucide-react(>=1.0.1)、react-hook-form(>=7.72.0)、@medusajs/js-sdk(>=2.13.4)、@stripe/stripe-js(>=8.11.0)、@tanstack/react-query(>=5.17.19)、@stripe/react-stripe-js(>=5.6.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 amboras-check,可以用 npx amboras-check 直接运行。

@amboras-dev/storefront-core 支持 TypeScript 吗?

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

@amboras-dev/storefront-core 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@amboras-dev/storefront-core 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.10.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@amboras-dev/storefront-core 可以商用吗?

@amboras-dev/storefront-core 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@amboras-dev/storefront-core 的下载量有多少?

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

@amboras-dev/storefront-core 还在维护吗?

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