@haatlabs-core/shopify

中文文档
0.18.5发布于 2026/11/14Apache-2.0TypeScriptESM + CJS近 30 天下载 4989

Shopify for Node apps: OAuth, session tokens, the Admin GraphQL client, products, webhooks and billing.

原始使用文档
文档目录5 节
  1. Install
  2. Entry points
  3. The App URL opened outside the admin (0.11)
  4. Time limits and pacing (0.9)
  5. Any Node framework

@haatlabs-core/shopify

Shopify for the projects: OAuth and session tokens, store tokens kept alive, the Admin GraphQL client, products and bulk exports, media, product content and creation, webhooks and billing. It throws SHOPIFY_MEDIA_ERROR besides the core codes; a project spreads SHOPIFY_ERRORS into defineErrors. A project passes its webhook topics to ensureWebhookSubscriptions, its reconnect wording to StoreAccessTokens, and VARIANT_COST_FIELDS as extraVariantFields when it has the inventory scope.

Install

pnpm add @haatlabs-core/shopify

Entry points

  • @haatlabs-core/shopify: everything below, for Node.
  • @haatlabs-core/shopify/contracts (0.12.1): SHOPIFY_ERRORS and ShopifyErrorCode, with nothing of Node: a project's contracts, which its pages load, import them from here.
  • @haatlabs-core/shopify/embedded: for an embedded app's pages in the browser; it imports nothing of Node.
  • @haatlabs-core/shopify/testing: helpers for a project's tests.

The App URL opened outside the admin (0.11)

After an install Shopify may open the App URL as a top-level page, with ?shop= and no host. An embedded app sends that visit to itself inside the shop's admin before it renders:

import { redirectTopLevelVisitToAdmin } from '@haatlabs-core/shopify/embedded';

if (!redirectTopLevelVisitToAdmin(import.meta.env.VITE_SHOPIFY_API_KEY)) render();

It goes to https://<shop>/admin/apps/<api key> only from a top-level page without host, whose shop is a *.myshopify.com address, with an API key; otherwise it returns false and does nothing. topLevelAdminRedirect({ search, isTopLevel, apiKey }) gives that URL, or null, without touching the window.

Time limits and pacing (0.9)

Every Admin GraphQL request has a per-attempt limit, timeoutMs (30 s). A query that runs out of time is retried like a network failure; a mutation is not (it may have been applied): it is thrown as a transient SHOPIFY_API_ERROR, "Shopify did not answer in time", and the job's own retry decides. request(query, variables, { signal, timeoutMs }) takes the caller's signal; its abort is rethrown as the caller's.

When a request to a shop may start is decided by a ShopifyThrottle, told the cost bucket after every answer, and keeping a tenth of the bucket back. Every client shares processShopifyThrottle unless given one; RedisShopifyThrottle (@haatlabs-core/rate-limit) shares it across processes:

new ShopifyAdminClient({ shopDomain, accessToken, apiVersion, throttle });

In the process throttle, the callers who waited on a shop go one at a time. The one whose turn it is reads the shop's start again and, if the answer before it moved the start later, sleeps to it while holding the turn. No request waits more than 60 s in all, asleep and in line; at its cap it goes. resetProcessShopifyThrottle is in @haatlabs-core/shopify/testing.

getBulkOperation(client, id, { signal }) reads a bulk operation once, for a handler that polls with PollAgain (@haatlabs-core/queue), and classifyBulkOperation(op) says 'running', 'completed' or 'failed' (BULK_TERMINAL_STATUSES: FAILED, CANCELED, CANCELING, EXPIRED). startProductsBulkOperation(client, { signal }) starts one. A start that timed out may have begun one anyway, so a retry reads currentBulkOperation(client, { signal }) first: the shop's newest bulk query still created or running (bulkOperations, Admin API 2026-01 and later), to adopt. Since 2026-01 a shop may run up to five bulk queries at once, so a start is not refused for one in progress, and the newest may be another of the app's: an app that runs more than one kind at a time cannot adopt by this alone. readLines gives up, as transient, on a download that sends nothing for a minute.

Any Node framework

Everything here is framework-free: plain functions and classes over fetch, so an app with its own Shopify code (NestJS on Express, Fastify, Koa, a plain server) can adopt one piece at a time.

  • OAuth install: verifyOAuthHmac, buildAuthorizeUrl, exchangeCodeForToken (with expiring offline tokens), exchangeSessionToken and refreshAccessToken.
  • The Admin GraphQL client: ShopifyAdminClient, with the API version, cost-based throttling and Shopify's errors.
  • Webhooks: verifyWebhookHmac(rawBody, header, apiSecret) checks the bytes Shopify sent, so the route must see the raw body. On NestJS: NestFactory.create(AppModule, { rawBody: true }) and req.rawBody (RawBodyRequest<Request>); on Express alone: express.raw() on that route.
  • Session tokens: verifySessionToken(token, { apiKey, apiSecret }) gives the shop and the user behind an App Bridge request.
  • Billing: the plan a store pays for through Shopify.

src/express.int.test.ts runs a webhook and a session token through a NestJS app on Express.

版本与发布记录

@haatlabs-core/shopify 共发布 26 个版本,首次发布于 2026/11/07;过去 12 个月发布了 26 个版本。

版本发布日期距今
0.18.5latest2026/11/143 天前
0.18.42026/11/134 天前
0.18.32026/11/134 天前
0.18.22026/11/134 天前
0.18.12026/11/134 天前
0.18.02026/11/134 天前

关于 @haatlabs-core/shopify 的常见问题

@haatlabs-core/shopify 是什么?

Shopify for Node apps: OAuth, session tokens, the Admin GraphQL client, products, webhooks and billing.

如何安装 @haatlabs-core/shopify?

在项目目录运行 npm install @haatlabs-core/shopify,或使用 pnpm add / yarn add / bun add。

@haatlabs-core/shopify 支持 TypeScript 吗?

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

@haatlabs-core/shopify 支持 ESM 还是 CommonJS?

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

@haatlabs-core/shopify 需要什么版本的 Node.js?

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

@haatlabs-core/shopify 可以商用吗?

@haatlabs-core/shopify 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@haatlabs-core/shopify 的下载量有多少?

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

@haatlabs-core/shopify 还在维护吗?

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