Claims API
Claim-type discovery (claimTypeEligibility({ orderNumber, email, orderLineNumber, language? })) returns the merchant-configured claim types with their offered resolutions, the per-line descriptionMode and pictureMode intake settings, and the feedback label tree annotated per value with product eligibility (true, false or 'unknown'). Labels are additive category:value feedback tokens submitted per claim line; a nested value's token requires its parent value's token (submit both). Labels never determine policy. Submitting a claimType validates membership; an omitted type means an uncategorized claim with no offered resolutions.
withdrawalAvailability(orderNumber, email, signal?) checks the server's current withdrawal window and returns remaining claimable line quantities. createWithdrawal({ orderNumber, email, returnShippingOptionKey? }, signal?) asks the server to recheck and create a withdrawal for all remaining quantities. The response is a ClaimCreateResponse; requesting a refund does not imply approval.
lookupClaims(orderNumber) returns each claim's lines with two independent status facets. status is the decision facet (needsDecision, decided, rejected); returnStatus is the goods facet (notExpected, awaitingAuthorization, awaitingGoods, inTransit, received). A line can be decided and still awaitingGoods, or have its goods received before it is decided. Show both; neither implies the other. authorizedQuantity and receivedQuantity give the quantities behind the goods facet.
The goods side is live: a claim completes (and is settled) as soon as every line is decided, and parcels can still arrive afterwards, so returnStatus, authorizedQuantity and receivedQuantity are computed from the current authorizations and confirmed receipts on every lookup. Once the claim is no longer open each line also carries settlement ({ returnStatus, receivedQuantity }), the goods facts frozen at completion, so you can show "2 of 3 received now, 1 at settlement". settlement is null while the claim is open and its values are null when the goods were not yet tracked at completion. (Versions before 0.14.0 returned a physicalReturn policy value, now replaced by returnStatus, and a single status that mixed both facets.)
Import createClaimsClient from @hantera/storefront-sdk/claims. Install the Claims and Storefront apps; the host backend must authenticate the customer and supply Storefront customer tokens.
import { createClaimsClient } from '@hantera/storefront-sdk/claims'
const claimsClient = createClaimsClient({
baseUrl: 'https://core.example.com',
getCustomerToken: () => getTokenFromYourBackend(),
})
const { claims } = await claimsClient.lookupClaims('ORDER-123')
const stop = claimsClient.subscribeCustomerClaims(update => {
// One stream per customer session; route updates by order number.
if (update.orderNumber === 'ORDER-123') void claimsClient.lookupClaims('ORDER-123').then(updateClaims)
}, showConnectionError)
// Call stop when the customer signs out or the customer context changes.Lookup and streamCustomerClaims(signal, onUpdate) obtain a token per call. subscribeCustomerClaims maintains one stream per customer session, reconnects with a fresh callback token after disconnects, renews the connection before the token's 30-minute lifetime, and returns an unsubscribe function. Updates carry { orderNumber, claimNumber }; route them to the affected order's view. Stream events are invalidations, not complete claim snapshots. Delivery is best-effort; applications should also refresh periodically. ClaimsError carries code and HTTP status; SSE errors use status zero. Cancellation is signaled by the provided AbortSignal.
lookupClaimMessages(orderNumber, claimNumber, after?, signal?) returns a page with messages and nextCursor; follow the cursor until null, or use getAllClaimMessages(orderNumber, claimNumber, signal?). Public messages expose their ID, time, text and customer/operator author kind, not an operator identity. sendClaimMessage({orderNumber, claimNumber, messageId, body}, signal?) posts as the authenticated customer. Generate a UUID for each message and reuse it for retries. A retry can return MESSAGE_NOT_CONFIRMED after an ambiguous successful write; re-read the conversation and match the ID before deciding what happened. Subscribe to claim invalidations and re-fetch messages; also refresh periodically when streaming is unavailable. This messaging integration is awaiting live verification.
claimTypeEligibility({ orderNumber, email, orderLineNumber }) and createClaim(request) wrap the existing Claims public registration APIs. They use order-number-plus-email ownership checks, not customer tokens; claim submission is controlled by the Claims publicCreateClaimEnabled setting. There is currently no order-wide eligible-lines endpoint.
Each discovered claim type carries pictureMode and descriptionMode (disabled | optional | required), both enforced per line: required pictures demand at least one picture on every submitted line, and a required description demands nonblank text on every line. Supply selected browser File objects in the corresponding createClaim line's pictures array when required. The client always sends multipart to /claims/storefront/claims, including when there are no pictures; direct HTTP clients must send one JSON request part and optional pictures parts. A nonblank claim-level comment is trimmed and becomes the first customer message; the maximum is 4000 characters. The JSON part is limited to 128 KiB. The server rechecks the policy, validates image signatures and limits uploads to five JPEG, PNG or WebP files, 5 MiB each and 10 MiB total request. Picture upload requires a Core server with multipart token support and a Claims app with safe orphan cleanup; the current integration is not yet production-ready.
searchExchangeProducts({ orderNumber, email, orderLineNumber, claimType, phrase?, locale }, signal?) searches products for an exchange-eligible line. Omit the phrase to load initial choices. The response contains up to 100 products and hasMore: true when another eligible product was observed, or null when the provider's completeness is unknown. A null or empty result does not prove that there are no other matches. Search is best effort and does not reserve stock. Pass the chosen exchangeProductNumber on the relevant createClaim line. Submission re-evaluates the first matching exchange policy and checks target labels through product lookup when matching categories are configured. returnShippingOptions(orderNumber, email, signal?, language?) returns customer-selectable shipping options with the fee and any return instructions, localized for language. Each claimTypes entry also carries its duplicate limit and a per-type claimableQuantity: a type that is once-only can already be used up on a line while other types remain claimable. These registration operations use order-number-plus-email checks, not customer tokens.
The current Storefront token implementation and demo issuer are proofs of concept, not a production security boundary. Follow Storefront's hardening guidance before using real customer data.