@foxy.io/sdk

中文文档
1.19.1发布于 2026/11/05MITTypeScriptESM + CJS近 30 天下载 1.2万

Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.

原始使用文档
文档目录8 节
  1. Foxy SDK 🦊🧱
  2. Setup
  3. Getting started
  4. 1. Find a node
  5. 2. Get some data
  6. 3. Making complex queries
  7. Bonus: followable responses
  8. Development

Foxy SDK 🦊🧱

Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.

Setup

Install the package:

npm i @foxy.io/sdk

Then import using CommonJS (Node 10-12):

const FoxySDK = require('@foxy.io/sdk');

or ES Modules (Node 13+, TypeScript, browsers):

import * as FoxySDK from '@foxy.io/sdk';

Getting started

Our SDK consists of 3 main parts available via the main file:

  1. Backend is for building Node.JS apps that connect to hAPI directly from a safe server-side environment. Apart from the API client, you'll also find a number of useful utilities for HMAC signing, removing sensitive info from responses and webhook verification under this export alias.
  2. Customer is for building universal apps and websites that interact with a subset of hAPI available to customers of a particular store. This export is also available as a pre-built library on our CDN.
  3. Core: is for building custom API clients that interact with Hypermedia API endpoints. This is the most advanced part of the SDK that every other built-in API client depends on. You can run it server and client-side.

Backend and Customer export API client classes for working with the respective endpoints. If you're using TypeScript, you'll also see the type exports for API-specific hypermedia relations and graphs named Rels and Graph. Let's connect to hAPI using FoxySDK.Backend.API class:

const api = new FoxySDK.Backend.API({
  refreshToken: 'your refresh token',
  clientSecret: 'your client secret',
  clientId: 'your client id',
});

This will create a hAPI version 1 client connecting to https://api.foxy.io/ with the given credentials, using in-memory storage for access token and URL resolution, logging errors, warnings and informational messages to console. You can customize each one of these defaults in constructor params and you'll see similar options for Customer API as well.

Regardless of the API type you're working with, you'll see the same methods on each node: .follow(), .get(), .put(), .post(), .patch() and .delete(). Here's how you can use them in 3 steps:

1. Find a node

To access a hAPI endpoint, you don't type in a URL – instead you traverse the API graph via links until you reach your target. For example, to see your transactions, you need to load the bookmark URL (https://api.foxy.io/), load your store at bookmark._links['fx:store'].href and only then get to the transactions at store._links['fx:transactions'].href. With our SDK this lengthy process becomes a one-liner:

const transactionsNode = api.follow('fx:store').follow('fx:transactions');

String bits that start with fx: are called Compact URIs (or curies for short), and if you're using an editor that supports code autocompletion based on TypeScript definitions, we'll provide suggestions for available curies where possible.

Now that we have our node, let's get some data from it:

2. Get some data

Each node has a class method corresponding to a supported HTTP method. For example, to make a GET request, we can call .get():

const transactionsResponse = await transactionsNode.get();

The method we've just called returns a Promise (hence the use of the await keyword) that resolves with an enhanced version of a native Response object, giving you an ability to access response status, headers and more. But for now we just want our JSON:

const transactions = await transactionsResponse.json();

Done! Now you have the API response with the same schema as in the docs at your disposal. And yes, we have type definitions for it too, meaning that you'll get type checking with TypeScript and rich autosuggestions with inline docs in every editor that supports them. But what if we could go even further?

3. Making complex queries

Quite often you'll need to fetch a specific set of items, maybe apply some filters, skip a few entries, speed things up by requesting a partial resource – and you can do that with hAPI using query parameters from our cheatsheet. Our SDK provides convenient shortcuts for these parameters in the .get() method (all optional):

const transactionsResponse = await transactionsNode.get({
  zoom: { customer: ['default_billing_address'] },
  filters: ['total_order:greaterthan=50', 'attributes:name[color]=red'],
  fields: ['id', 'total_order', 'currency_code'],
  offset: 25,
  limit: 10,
});

The response type will also match your query as close as possible, giving you the ability to eliminate possible errors before hitting the API. For example, for the above request each transaction will have only those 3 fields and only those 2 nested embeds (+ attributes where supported as they're included by default).

Bonus: followable responses

Each link in the _links object received from our SDK includes the same methods as a regular node, so you can do something like this:

const nextTransactionsPage = await transactions._links.next.get();

It also works with embedded resources and following, and you'll get autocompletion and type checking all the way through:

const recentSubscriptions = await transactions._embedded['fx:customer']._links['fx:subscriptions'].follow('last').get();

Development

To get started, clone this repo locally and install the dependencies:

git clone https://github.com/foxy/foxy-sdk.git && cd foxy-sdk && npm i

You can also build this package and test it locally in another project by running the following in the project folder:

npm pack

Use the following commands to run tests:

npm test # run all tests
npm run test:watch # watch files for changes and re-run relevant tests

All the latest features are published from the beta branch to the beta distribution channel. If you submit a PR, please target beta as well. Releases are published from main.

版本与发布记录

@foxy.io/sdk 共发布 78 个版本,首次发布于 2020/11/07;过去 12 个月发布了 10 个版本。

版本发布日期距今
1.19.1latest2026/11/0511 天前
1.19.02026/10/091 个月前
1.18.02026/09/251 个月前
1.17.12026/09/161 个月前
1.17.02026/08/292 个月前
1.16.22026/01/309 个月前

其他发布通道:beta → 1.16.1-beta.1。

关于 @foxy.io/sdk 的常见问题

@foxy.io/sdk 是什么?

Universal SDK for a full server-side and a limited in-browser access to Foxy hAPI.

如何安装 @foxy.io/sdk?

在项目目录运行 npm install @foxy.io/sdk,或使用 pnpm add / yarn add / bun add。

@foxy.io/sdk 支持 TypeScript 吗?

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

@foxy.io/sdk 支持 ESM 还是 CommonJS?

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

@foxy.io/sdk 需要什么版本的 Node.js?

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

@foxy.io/sdk 可以商用吗?

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

@foxy.io/sdk 的下载量有多少?

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

@foxy.io/sdk 还在维护吗?

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