@lacspace/sdk
v2.0.4
Published
High-level TypeScript SDK for Lacspace — api, auth, analytics and e-commerce in one client.
Maintainers
Readme
@lacspace/sdk
One client for the whole Lacspace platform — auth, analytics, e-commerce and raw API, sharing a single connection.
Not sure which package to use? Start here. The SDK bundles
@lacspace/api,@lacspace/authand@lacspace/analyticsbehind one client — so a login token instantly applies to every call — and adds e-commerce helpers on top.
- 🎯 One instance, one token — sign in once, everything's authenticated
- ⚡ Zero dependencies · 🌍 isomorphic · 📦 ESM + CJS · fully typed
Install
npm install @lacspace/sdk # or pnpm add / yarn add / bun addQuick start
import { LacspaceSDK } from "@lacspace/sdk";
const lac = new LacspaceSDK({ baseURL: "https://api.lacspace.com/api" });
// 1 · Authenticate — the token is stored and reused everywhere
const { user } = await lac.auth.login({ email: "[email protected]", password: "••••••••" });
// 2 · E-commerce helpers
const products = await lac.ecommerce.getProducts();
await lac.ecommerce.addToCart({ productId: products[0]!.id, quantity: 1 });
const { orderId } = await lac.ecommerce.checkout("cart_123");
// 3 · Track what happened
await lac.analytics.track("checkout_completed", { orderId });What's on the client
lac.auth // login, register, me, logout, refresh
lac.analytics // track, queueEvent, flush, batch
lac.ecommerce // getProducts, getProduct, addToCart, checkout
lac.api // the raw typed client for any endpointBecause they share one api instance, lac.auth.login() authenticates analytics and ecommerce too — automatically.
Recipes
A tiny React login hook
import { useState } from "react";
import { LacspaceSDK, LacspaceApiError } from "@lacspace/sdk";
const lac = new LacspaceSDK({ baseURL: "https://api.lacspace.com/api" });
export function useLogin() {
const [error, setError] = useState<string>();
async function login(email: string, password: string) {
try {
const { user } = await lac.auth.login({ email, password });
return user;
} catch (e) {
setError(e instanceof LacspaceApiError && e.status === 401 ? "Invalid credentials" : "Something went wrong");
}
}
return { login, error };
}Building in React?
@lacspace/reactgives youuseAuth,useQueryand a provider out of the box.
Anything the helpers don't cover → drop to the raw client
const invoices = await lac.api.get("billing/invoices");
await lac.api.post("support/tickets", { subject: "Help" });Server-side with an API key
const lac = new LacspaceSDK({ baseURL, apiKey: process.env.LACSPACE_API_KEY });One import for everything
Every type and class from api, auth and analytics is re-exported here:
import { LacspaceSDK, LacspaceApi, LacspaceAuth, LacspaceAnalytics, LacspaceApiError } from "@lacspace/sdk";
import type { Product, LacspaceUser, AnalyticsEvent } from "@lacspace/sdk";The Lacspace family
| Package | For |
| --- | --- |
| @lacspace/sdk | Everything in one client (this package) |
| @lacspace/api | The core HTTP client |
| @lacspace/auth | Login, register, tokens |
| @lacspace/analytics | Event tracking |
| @lacspace/react | React hooks |
| @lacspace/nepali-date | Bikram Sambat dates |
| @lacspace/nepali-utils | Nepal helpers |
Licensing
This package is free under the Lacspace Free Licence — MIT-equivalent freedoms. Use it in personal and commercial projects at no cost; just keep the notice.
Not every Lacspace package is free. We also offer Commercial (paid), Client-specific, and Private (proprietary) packages under separate terms. See the full Lacspace Licence Centre.
Part of the Lacspace ecosystem — 35 zero-dependency, isomorphic TypeScript packages.
