@storehugs/integration
v0.3.0
Published
TypeScript client for the Store Hugs Integration API: the Storefront API and the Admin API.
Maintainers
Readme
@storehugs/integration
A TypeScript client for the Store Hugs Integration API. It has no dependencies and runs on Node 22+, browsers, Deno and Bun.
- Storefront API: the catalog, carts and checkout links, and signed-in shoppers on the shop's host. Use a publishable key in browsers on the sites it lists, or a secret key on your server.
- Admin API: the merchant's own systems and connected apps. Use an Admin key (
sa_live_…) on your server only.
Field names are camelCase in queries, request bodies, answers and webhook payloads (perPage, cartToken, updatedAt). The OAuth token answers are the exception: they keep the standard access_token, refresh_token, expires_in and, for apps, api_key.
The full reference is at https://developers.storehugs.com (/openapi.yaml). Report issues and send changes at https://github.com/innoverse-solutions/storehugs-ts-integration-sdk.
Storefront
import { StorefrontClient } from '@storehugs/integration';
const storefront = new StorefrontClient({
host: 'acme.storehugs.com',
key: 'pk_live_…',
});
const { data: products } = await storefront.products.list({
search: 'mug',
perPage: 12,
});
const cart = await storefront.createCart();
await storefront.cart(cart.cartToken).addItem(products[0].id, 2);
const { checkoutUrl } = await storefront
.cart(cart.cartToken)
.checkout({ returnPath: '/thanks' });
// Open checkoutUrl in the shopper's browser.Shopper sign-in uses OAuth with PKCE on the shop's own page:
- Call
createPkcePair()andcreateState(). - Send the shopper to
storefront.signIn.authorizeUrl(…). - Exchange the code with
storefront.signIn.exchangeCode(…). - Call
storefront.withAccessToken(tokens.access_token)to act as the shopper.
Admin
import { AdminClient } from '@storehugs/integration';
const admin = new AdminClient({ apiKey: process.env.STOREHUGS_ADMIN_KEY! });
for await (const order of admin.orders.all({
updatedSince: '2026-11-01T00:00:00Z',
})) {
// Every page is fetched as you read.
}
await admin.setInventory([{ sku: 'MUG-01', stockQuantity: 40 }]);
const product = await admin.products.get(12);
await admin.products.update(
12,
{ price: 19.5 },
{ unmodifiedSince: product.updatedAt ?? undefined },
); // 409 edit_conflict if it changedCatalog setup: besides products, the client reaches what products are built from.
admin.units: the units products are sold in (a product'sunitId).admin.taxonomies: the shop's taxonomies, andterms(taxonomyId)for one taxonomy's terms (a product'staxonomyTermIds).admin.variantOptions: the options variable products are sold in, such as Size, and their values. Reuse these names so the shop keeps one of each.admin.variableProducts: products sold in those options, created with their variants or given more.admin.specTemplates: the specification templates a product can use, with the properties itsspecsfill.
Apps get an Admin key, not an OAuth token:
- Send the merchant to
AdminClient.authorizeAppUrl({ clientId, redirectUri, scopes, state, codeChallenge }). - On your server, call
AdminClient.exchangeAppCode(…)within 10 minutes. It returns{ api_key, scopes, shop }, and the key is shown only that once.
Behaviour
- Writes are safe to retry. Every POST, PUT, PATCH and DELETE gets an
Idempotency-Key. PassidempotencyKeyto keep one across processes, orfalseto send none. - Retries: answers 429 and 503, and network errors, are retried up to
maxRetriestimes (default 2), followingRetry-After, with the same key. If a retry reaches the server while the first attempt is still running (409idempotency_in_progress), the client waits for it under the same key for up toinProgressTimeoutMs(default 30 seconds) and returns its answer. - Errors: a refusal throws
IntegrationApiError, withstatus, the API'scode(insufficient_scope,edit_conflict, …) and, on a 422,errorsper field. - Webhooks:
verifyWebhookSignature(rawBody, request.headers.get('Storehugs-Signature'), secret)checks the HMAC and that the delivery is recent. Skip anyStorehugs-Event-Idyou have already handled.
Install
npm install @storehugs/integrationDevelopment
npm ci
npm run types:check
npm test
npm run buildsrc/schemas.ts is generated from the Integration API's OpenAPI file. Don't edit it by hand: run npm run generate, which reads the published spec at https://developers.storehugs.com/openapi.yaml. To read another copy, pass a URL or a file path in SPEC, for example SPEC=../matajer/documentation/openapi/integration-api.yaml npm run generate.
A weekly workflow regenerates the types from the published spec and fails when they change, which signals that the client needs a release.
Releasing
Update
versioninpackage.jsonandCHANGELOG.md, and commit tomaster.Tag the commit and push the tag:
git tag v0.1.0 && git push origin v0.1.0The Publish workflow then tests and builds on Node 22, 24 and 26 and publishes to npm with provenance. It refuses a tag that doesn't match
package.json. It publishes through npm trusted publishing, so no npm token is stored in the repository.
CI on pushes and pull requests checks formatting, types and tests only. It doesn't build or publish.
Contributing and security
See CONTRIBUTING.md. Report vulnerabilities privately, as SECURITY.md describes.
License
MIT
