@derekurban2001/ca-supermarket-api
v1.0.0
Published
A TypeScript client exposing: - `listStores()` — list all Real Canadian Superstore locations - `searchProducts(query, storeId, page, pageSize)` — search products scoped to a store with user-specified pagination - `getProductDetails(productId, storeId)` —
Readme
CanadianSupermarketApi (Superstore v1)
A TypeScript client exposing:
listStores()— list all Real Canadian Superstore locationssearchProducts(query, storeId, page, pageSize)— search products scoped to a store with user-specified paginationgetProductDetails(productId, storeId)— fetch product details for a store
Results use a typed Result<T> union: { ok: true, value } | { ok: false, error }.
Install & Scripts
npm install
npm test
npm run lint
npm run formatEnvironment
Set SUPERSTORE_API_KEY before running the library or its tests. The contract and integration suites call the live Real Canadian Superstore API—no fake datasources or offline fallbacks exist. missing.r invalid credentials return an unauthorized error via the Result type; tests require the key and will fail fast if it is missing.
Optional overrides:
SUPERSTORE_BASE_URLSUPERSTORE_BANNER(defaults tosuperstore)SUPERSTORE_TIMEOUT_MS(ms, defaults to10000)
You can also load a typed config via loadEnvConfig() from src/config/env.ts.
Usage
import { createClient, listStores, searchProducts, getProductDetails } from './src/index';
import { loadEnvConfig } from './src/config/env';
// Option A: Functional API (uses env when not overridden)
const stores = await listStores();
const search = await searchProducts('milk', '1234', 1, 10);
const details = await getProductDetails('21053436_EA', '1234');
// Option B: Explicit client with programmatic config
const { superstore } = loadEnvConfig();
const client = createClient({ superstore: { ...superstore, apiKey: process.env.SUPERSTORE_API_KEY } });
await client.listStores();createRepository remains exported if you prefer to work directly with the repository port.
Notes
- Prices are in CAD and exclude tax. All pricing fields provided upstream should be returned.
- No retry/backoff in v1. Errors carry types and messages. Handle 401/403/429 appropriately in your app.
- Credentials must be supplied by callers once the datasource is wired.
- Contract and integration tests hit the live API; set
SUPERSTORE_API_KEYand be mindful of upstream rate limits when running the suite.
Superstore Search Requirements (confirmed)
Headers (required)
x-apikey: your API key (provided via env/config)x-application-type: Web(literal)x-loblaw-tenant-id: ONLINE_GROCERIES(literal)accept-language: en(literal;fralso works;en-CAfails)
Headers (optional)
origin,referer, allsec-*,user-agent,x-channel,x-preview
Payload (required)
banner: "superstore"(literal)cart.cartId: random UUID per requestfulfillmentInfo.storeId: provided store idfulfillmentInfo.offerType: "OG"(literal)searchRelatedInfo.term: search term string
Payload (optional)
fulfillmentInfo.date(DDMMYYYY),pickupType,timeSlotlistingInfo(filters/sort/includeFiltersInResponse/pagination). If sent,pagination.from >= 1userData,device,searchRelatedInfo.options
Constraints
pagination.frommust be >= 1 (server enforces combined bounds)offerTypemust beOGaccept-languagemust be a simple language code (en/fr)
