@slicekit/core
v0.5.2
Published
Typed Slice API client and commerce domain functions for building on the Slice protocol
Readme
@slicekit/core
Typed Slice API client and commerce domain functions for building on the Slice protocol. The API client's types are generated from the Slice API itself, so requests, parameters, and responses are checked end to end — no schema duplication, no drift.
Installation
npm install @slicekit/core viemFeatures
- Typed API client:
sliceClient()is a fully typed Hono RPC client for the Slice API, resolving the production or development base URL automatically. - Slicers and products:
getSlicer,getSlicerProducts,getSlicerProduct, product options and category filters, checkout sessions, and product metadata creation — plus variant-selection models (getVariantPickerModel,buildInitialVariantSelections) and price selectors for loaded products. - Pricing: aggregation and totals (
aggregatePricesByCurrency,computeSubtotal,computeTotal) and display formatting (formatPrice,getDisplayedPrice). - Cart: pure cart state and actions (
createCart,addItem,updateQuantity, payments and extra costs) with selectors and cart pricing. - Orders and accounts: order fetching, status updates and CSV export, account orders, shippings, carts, and shop client state.
- Authentication helpers: ERC-8128 request signers for server-side use.
Domain types and canonical value sets come from
@slicekit/commerce; onchain facts from
@slicekit/abi.
Quick Start
import { getSlicerProducts } from "@slicekit/core"
const { data } = await getSlicerProducts({
slicerId: 123,
limit: 24,
include: { prices: true, variants: true },
signer: { fetch }
})Every fetcher narrows its response type from the request's include flags, so
data only carries what was requested.
Authentication
Every fetcher takes a signer that authenticates the request:
{ fetch }sends it unauthenticated — enough for public data.- An ERC-8128
EthHttpSignersigns the request. On a server, build one from a private key:
import { createErc8128PrivateKeySigner, getAccountOrders } from "@slicekit/core"
const signer = createErc8128PrivateKeySigner({
privateKey: process.env.ETH_PRIVATE_KEY as `0x${string}`
})
const orders = await getAccountOrders({ address: signer.address, signer })In the browser, Slice ID provisions the session signer — see @slicekit/id.
Error Handling
Failed API calls throw SliceApiError, which carries the HTTP status, the
operation that failed, and the API's error code when one was returned:
import { SliceApiError } from "@slicekit/core"
try {
// ...
} catch (error) {
if (error instanceof SliceApiError && error.status === 404) {
// handle missing resource
}
}TypeScript
The package is strictly typed end to end: API response types are generated
from the Slice API's route definitions, include flags narrow response
shapes at the type level, and domain values (statuses, roles, currencies)
are unions from @slicekit/commerce rather than plain strings.
