npm.io
0.1.0 • Published yesterday

@curless/shopify-adapter

Licence
MIT
Version
0.1.0
Deps
0
Size
33 kB
Vulns
0
Weekly
0

@curless/shopify-adapter

Use a Shopify store as your agentbank catalog, and record agent-settled sales back as paid Shopify orders. Drop it into a merchant backend so an AI agent can buy your Shopify products through any agentbank payment protocol — the money settles through agentbank, and the sale shows up in your Shopify admin.

Zero runtime dependencies — it uses the platform fetch and the Shopify Admin GraphQL API. Pairs with @curless/agentbank-merchant-sdk, which prices and opens the checkout.

npm install @curless/shopify-adapter

The two halves

import {
  shopifyConfigFromEnv,
  fetchShopifyCatalog,
  writebackShopifyOrder,
} from '@curless/shopify-adapter';

const shopify = shopifyConfigFromEnv(); // null unless SHOPIFY_* env is set

1. Catalog — map the store's products into generic CatalogItems you price from:

const items = shopify ? await fetchShopifyCatalog(shopify) : [];
// items: { sku, name, priceMinor, currency, description, imageUrl?, variantId?, productType? }[]
// …price a merchant-quoted checkout from `items` with the merchant SDK…

2. Writeback — after the agent pays through agentbank, record the paid order:

await writebackShopifyOrder(shopify, {
  variantId,                 // CatalogItem.variantId
  quantity,
  protocol: 'acp',           // which agentbank protocol settled it
  agentbankOrderId: orderId, // idempotency tag
  unitPriceMinor: 268000,    // the amount actually collected (see below)
  currency: 'EUR',
});

No money moves in Shopify — the order is marked paid via an external transaction and tagged agentbank + protocol:… + the agentbank order id, so it's traceable and never mistaken for a Shopify Payments sale.

Notes

  • Auth is Shopify's 2026 client-credentials grant: a Dev Dashboard app no longer shows a token in the UI, so you exchange SHOPIFY_CLIENT_ID + SHOPIFY_CLIENT_SECRET for a short-lived Admin token programmatically. Set SHOPIFY_SHOP_DOMAIN too. The app needs read_products (catalog) and write_orders (writeback) — required scopes go in shopify.app.toml, then deploy + reinstall. Secrets come from the environment; never hardcode them.
  • Amounts are currency-aware. Prices convert to integer minor units using the currency's own exponent — cents for USD/EUR, none for JPY, mills for KWD — so a non-2-decimal store isn't silently mis-scaled.
  • Record the real amount. Pass unitPriceMinor + currency to the writeback so the Shopify order reflects what the agent actually paid. Omit them to fall back to the variant's current price (which drifts if the price changed after payment).
  • Idempotency. The writeback searches for an order already tagged with the agentbank order id. Shopify's tag search lags creation by the search-index refresh, so two writebacks fired within a second can both miss and duplicate — add your own in-process guard on the order id if you fire them rapidly; the tag search is the cross-restart backstop.
  • Pagination. Products paginate to completion. A single product with more than 250 variants has its tail dropped with a warning (not silently).

MIT

Keywords