@netcom/search-sdk
v0.1.20260901-ci.3
Published
Headless SDK for the NetCom Search API — typed clients for parts search, catalog, pricing, cart and orders.
Maintainers
Readme
netcom.search.sdk.js
Framework-agnostic JS/TS SDK for NetCom's search/catalog/pricing API (@netcom/search-sdk). Call a
method, get a typed object back — no React, no UI dependency.
Install
Published publicly on npm — no registry config or credentials needed to install.
npm install @netcom/search-sdkQuick start
import { createSearchSdk } from "@netcom/search-sdk";
const sdk = createSearchSdk({
baseUrl: "https://your-tenant.netcomcanada.com", // no trailing slash
});
const makes = await sdk.makes.getFilteredMakes(undefined, 2015);
const info = await sdk.parts.getProductInfo("Akebono", "Disc Brake Pad Set", "ACT1878");That's it for anonymous/public browsing — omit getAccessToken entirely and the SDK sends no
Authorization header. Whether the API actually allows anonymous access is a per-tenant backend setting
(AllowAnonymous, unrelated to this SDK) — some tenants will 401 until you authenticate.
Authentication
The SDK is agnostic of the identity provider — it never imports Keycloak or any IdP client itself. You supply how to get a token:
const sdk = createSearchSdk({
baseUrl: "https://your-tenant.netcomcanada.com",
getAccessToken: async () => keycloak.token, // your own IdP client, called lazily as needed
});getAccessToken is a fallback — it's only called when no token has been explicitly injected. Two
more escape hatches sit on top of it:
// Push a freshly refreshed token yourself (e.g. after your own IdP's refresh flow) — overrides the
// fallback for every subsequent REST call *and* the live SignalR pricing connection, until cleared.
sdk.setAccessToken(newToken);
// Get told when a token stops working (401 on REST, or the pricing hub's handshake rejected for
// auth reasons) — the SDK never retries on its own, it just signals so you can react (refresh + retry,
// redirect to login, etc). Returns an unsubscribe function.
const unsubscribe = sdk.onAuthError(({ source, status }) => {
console.warn(`auth failed on ${source}`, status);
});Data APIs
Each group mirrors a domain of the backend API, same requests/responses as netcom.search.client used
directly (no behavior change from the port):
| Group | Examples |
|---|---|
| sdk.parts | searchPartsByKeywords, searchPartsByApplication, searchPartsByPartNumber, getProductInfo, getBuyerGuide, getAutocompleteSuggestions |
| sdk.cart | addCartItem, getCartItems, makeOrder |
| sdk.orders | getOrders, getOrder |
| sdk.categories | getAllCategories, getCategoriesByMakeModelYear |
| sdk.makes / sdk.models / sdk.years | getFiltered*, search* |
| sdk.searchScope | getSearchScope — informational: what this caller's token restricts them to |
| sdk.tenantSettings | getMySettings, getMyBranding, putMySettings |
| sdk.ai | .client (a configured axios instance for the separate AI API) + .isAiEnabled() |
All fully typed — import any DTO you need directly from the package root, e.g.
import type { PartDto, CartLineDto } from "@netcom/search-sdk".
Pricing (live updates over SignalR)
Pricing isn't request/response — the backend can push results asynchronously, sometimes more than once
per search as different connectors respond. sdk.pricing is a PricingClient for this:
await sdk.pricing.connect(); // once, e.g. at app startup
const { priceRequestId, parts } = await sdk.parts.searchPartsByKeywords("brake pad");
// Option A: event-style — get every batch as it arrives
const unsubscribe = sdk.pricing.subscribe(priceRequestId, (results) => {
// results: PriceAndAvailabilityResultDto[]
});
// Option B: just want one object, no events
const results = await sdk.pricing.waitForFirst(priceRequestId, { timeoutMs: 5000 });sdk.pricing.onConnectionStateChange((state) => ...) reports { isConnected, isReady } if you want to
show connection status or gate UI on it. isReady becomes true once the handshake resolves or a
3-second fallback elapses — searches are never blocked waiting on a slow/unreachable hub; pricing then
falls back to whatever the backend resolves synchronously per-request.
sdk.setAccessToken/sdk.onAuthError cover the pricing connection too — one call updates both REST and
SignalR auth.
What this SDK does not do
- No retry logic hidden anywhere (auth failures, pricing timeouts) — you decide the strategy.
- No UI, no React, no framework assumptions.
netcom.search.clientconsumes this SDK the same way any other caller would. - No bundler needed to consume it — plain
tscoutput, works directly under Node or any bundler.
