npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tiendanube/nube-sdk-helper

v0.2.0

Published

Utility functions, type guards, and SDK instance management for NubeSDK apps

Readme

@tiendanube/nube-sdk-helper

Utility functions, type guards, and SDK instance management for building NubeSDK apps.

About

@tiendanube/nube-sdk-helper centralizes the repetitive patterns that NubeSDK apps need: registering and accessing the SDK instance, reading state with selectors, runtime type guards, page/checkout handling, rendering, and event subscriptions. The goal is less boilerplate and stronger type safety.

Apps in NubeSDK run inside isolated web workers, without direct access to the DOM. All helpers are designed for that environment and interact with the platform exclusively through the SDK instance.

Installation

npm install @tiendanube/nube-sdk-helper @tiendanube/nube-sdk-types

Note: @tiendanube/nube-sdk-types is a peer dependency and must be installed alongside this package.

Instance management

The NubeSDK runtime passes the SDK instance only as the argument of your app entry point (App(nube)). Register it once with setNubeInstance and every other helper (getCurrentState, ui, browser, selectors, onPage, ...) can access it without you having to thread nube through every function and component.

import {
  setNubeInstance,
  getCurrentState,
  getNubeInstance,
  ui,
} from "@tiendanube/nube-sdk-helper";
import type { NubeSDK } from "@tiendanube/nube-sdk-types";

export function App(nube: NubeSDK) {
  setNubeInstance(nube); // call this first

  const state = getCurrentState();
  ui.showToast(`You are on the ${state.location.page.type} page`);
}
  • setNubeInstance(nube) — registers the instance (call once at the top of App).
  • getNubeInstance() — returns the registered instance; throws a descriptive error if you forgot to register it.
  • clearNubeInstance() — clears the registered instance (useful in tests).

State access

import {
  getCurrentState,
  getCart,
  getCartItems,
  getPageType,
  getCustomer,
  getAppData,
  getScriptParam,
} from "@tiendanube/nube-sdk-helper";

// Selectors read the current state by default; pass a state to keep them pure.
const items = getCartItems();
const pageType = getPageType();
const customer = getCustomer();

// App data injected by the runtime
const { id } = getAppData();
const variant = getScriptParam("variant"); // ?variant=... on the app script URL

Pages and checkout

import { pageMatch, onPage, onCheckoutStep } from "@tiendanube/nube-sdk-helper";

// One-off dispatch on the current page:
pageMatch(getCurrentState(), {
  product: (state, product) => console.log(product.name),
  checkout: (state, checkout) => console.log(checkout.step),
});

// Subscribe to navigation. Both return an unsubscribe function:
const stop = onPage({
  product: (state, product) => trackProductView(product.id),
});
// stop(); // when you no longer need it

onCheckoutStep({
  success: () => trackPurchase(),
});

Events

import { onEvent, toastOn } from "@tiendanube/nube-sdk-helper";

// Thin wrapper around nube.on that returns an unsubscribe:
const off = onEvent("cart:update", (state) => {
  console.log("items:", state.cart.items.length);
});

// Show a toast whenever an event fires:
toastOn("cart:add:success", "Added to cart", "success");
toastOn("cart:update", (state) => `Cart: ${state.cart.items.length} items`);

Rendering

import { ui, forEachProduct } from "@tiendanube/nube-sdk-helper";

// Render the same component into many slots at once:
ui.renderAll(["corner_top_left", "corner_top_right"], { type: "txt", children: "Hi" });

// Render one component per product on the current page (keys are added automatically):
getNubeInstance().render(
  "product_grid_item_image_bottom_right",
  forEachProduct((product) => ({ type: "txt", children: product.name })),
);

ui.showToast("Done!", "success");
ui.clear("corner_top_right");

Browser APIs

import { browser, navigate } from "@tiendanube/nube-sdk-helper";

await browser.asyncLocalStorage.setItem("key", "value");
navigate("/products/123");

Type guards

Runtime checks that also narrow types for TypeScript:

  • Pages: isProductPage, isCategoryPage, isCheckoutPage, isHomePage, isAllProductsPage, isSearchPage
  • Cart: isCart, isCartItem, isCartValidationSuccess / Pending / Fail
  • Domain: isStore, isCustomer, isPayment, isShipping, isShippingOption, isAddress, isShippingAddress, isBillingAddress
  • Components / page data: isNubeComponent, hasProductList, hasSections, hasSingleProduct, isSectionWithProducts
import { isProductPage } from "@tiendanube/nube-sdk-helper";

const { page } = getCurrentState().location;
if (isProductPage(page)) {
  console.log(page.data.product.name);
}

General utilities

import { deepClone, debounce, throttle } from "@tiendanube/nube-sdk-helper";

const copy = deepClone(state); // uses structuredClone when available
const debounced = debounce((q: string) => search(q), 300);
const throttled = throttle(() => onScroll(), 100);

License

MIT