@tradalab/nekit
v7.13.0
Published
Tradalab internal Next.js foundation kit — shared UI, auth, data, and app primitives for company web projects.
Readme
@tradalab/nekit
Internal Next.js foundation kit for Tradalab — shared UI, auth, data, and app primitives so new web projects bootstrap with zero setup.
Status: Stable. See
CHANGELOG.mdfor history,docs/architecture.mdfor design rationale, anddocs/adr/for the decisions behind the current shape.
Table of contents
- Install
- Usage
- Subpaths
- Server vs. client subpaths
- Compatibility
- Versioning policy
- Development
- Adding a UI primitive
- Releasing
- Troubleshooting
- Contributing
Install
@tradalab/nekit is published to the public npm registry (like @tradalab/lyra) — no registry config or auth token required:
pnpm add @tradalab/nekitUsage
Import from a subpath, never from the root:
import { cn, formatPrice, formatPercent } from "@tradalab/nekit/utils"
import { NekitProvider } from "@tradalab/nekit/bootstrap"UI primitives, blocks and the app shell are not here: they moved to @tradalab/lyra in nekit 3.0 (ADR-0008).
A typical app layout.tsx:
import { NekitProvider } from "@tradalab/nekit/bootstrap"
import "@tradalab/nekit/styles.css"
import "./globals.css"
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<body>
<NekitProvider>{children}</NekitProvider>
</body>
</html>
)
}
<NekitProvider>already mounts<SessionProvider>internally — no need to wrap it.suppressHydrationWarningon<html>is required bynext-themes, which<NekitProvider>mounts.
For RBAC, observability, intl, feature flags, or any other provider that needs to sit between nekit's built-ins and your app, use the wrap prop:
<NekitProvider
wrap={(c) => (
<PolicyProvider policy={appPolicy} user={user}>
{c}
</PolicyProvider>
)}
>
{children}
</NekitProvider>Subpaths
| Subpath | Purpose | Boundary |
|---|---|---|
| @tradalab/nekit/utils | cn, locale-aware number/currency/percent formatters, invariant | server-safe |
| @tradalab/nekit/env | defineEnv — Zod-based env validation, server/client split | server-safe |
| @tradalab/nekit/hooks | useMobile, usePersistedState, useDebouncedValue, useEventCallback | client |
| @tradalab/nekit/auth | Types, zitadelProvider, session-augmentation side-effects | server-safe |
| @tradalab/nekit/auth/server | createAuth + createProxy + createSignInRoute + createSignInResetRoute (provider-agnostic via NekitAuthProvider) | server-safe |
| @tradalab/nekit/auth/client | useCurrentUser, useAccessToken, useIdToken, useHasAuthError, SessionProvider, SignInRedirect, SignInError | client |
| @tradalab/nekit/theme | ThemeProvider, useTheme, ThemeToggle, design token handles | client |
| @tradalab/nekit/styles.css | Tailwind v4 + tw-animate-css + tokens + dark variant | CSS |
| @tradalab/nekit/data | Types + HttpError + createQueryKeys + default query options | server-safe |
| @tradalab/nekit/data/client | createApiClient — bearer-token injection, retry, error hooks | server-safe |
| @tradalab/nekit/app-client | createAppApiClient - an app's bff client: session bearer, guarded sign-out, one toast per failure, space | server-safe |
| @tradalab/nekit/data/query | <QueryProvider> (TanStack Query v5) with Tradalab defaults | client |
| @tradalab/nekit/forms | react-hook-form + zod, useZodForm, FormInput/FormTextarea/FormCheckbox | client |
| @tradalab/nekit/rbac | definePolicy, <PolicyProvider>, <Can>, usePermission | client |
| @tradalab/nekit/bootstrap | <NekitProvider> — consolidates theme/query/tooltip/policy/toaster | client |
| @tradalab/nekit/eslint | tradalabEslint - flat-config entries every app spreads into its eslint.config (no double error toasts) | node |
| @tradalab/nekit/pwa | <InstallScript> (goes in <head>), <InstallSteps>, <PwaRuntime> - an installable app; NekitProvider's pwa prop mounts the runtime | client |
Server vs. client subpaths
nekit's "use client" directive lives on subpath entry artefacts only — never on per-file sources. The mechanism (scripts/inject-use-client.mjs + scripts/sync-ui.mjs) is documented in ADR-0005.
What this means for consumers:
Server-safe subpaths (table above) may be imported directly from server components or
proxy.ts/ route handlers. No"use client"is forced into your tree.Client subpaths carry the directive at their entry. Importing from them inside a server component will fail at build time (Next.js will emit the standard
Component cannot be imported from a Server Componenterror). Wrap the consumer in a"use client"file, or compose via children.@tradalab/nekit/authis the side-effect entry that registersid_token/access_token/expires_at/erroronSessionandJWTglobally. Use it once in your app:// next-auth.d.ts at the project root import "@tradalab/nekit/auth"Importing from
/auth/serveror/auth/clientalso applies the augmentation transitively.
Compatibility
| Floor | Version | Why |
|---|---|---|
| Next.js | 16+ | proxy.ts convention, async cookies/headers/params |
| React | 19.x | concurrent + actions APIs assumed |
| Node | 20.9+ to consume · 22.13+ to develop | engines field is the consumer floor; pnpm 11 itself requires 22.13+ |
| Tailwind | v4 | @import "tailwindcss" + v4 token shape |
| TypeScript | 5.1+ | verbatimModuleSyntax, noUncheckedIndexedAccess |
| pnpm | 11.22.0 | packageManager field pins this exactly |
| Auth (optional) | NextAuth v5-beta.30+, @auth/core 0.41+ | Zitadel provider integration |
Peer-dep ranges are tight on purpose. If you need to consume nekit on a non-supported floor, open an issue — do not force-install. Hidden incompatibilities are worse than blocked installs.
Versioning policy
Strict SemVer from 1.0.0 onward (see ADR-0001, ADR-0004):
- patch — bug fix, no API change.
- minor — additive only, backwards-compatible.
- major — breaking change. Requires an ADR.
Deprecated APIs stay marked @deprecated (with replacement guidance) for at least one minor cycle before removal. The 0.x history is preserved in git but is not referenced from CHANGELOG.md.
Development
pnpm install
make verify # typecheck + lint + test with the coverage floor CI enforces
make build # tsup + inject-use-clientSee CONTRIBUTING.md for the full contributor workflow (branching, changesets, layer rules, ADRs).
Adding a UI primitive
Not in this repo: primitives live in @tradalab/lyra since nekit 3.0 (ADR-0008). Add them there with its make ui-add.
Releasing
Published to the public npm registry (@tradalab/nekit). Version bumps and changelog entries need human judgment, so they stay manual; the upload itself runs in CI when a release tag is pushed. Maintainer flow:
# 1. On your branch, describe the change. `commit: true` auto-commits the changeset.
pnpm changeset
# 2. Merge to main.
# 3. On main, cut the release:
pnpm changeset:version # bumps package.json + CHANGELOG, deletes consumed changesets
git add -A && git commit -m "release: vX.Y.Z"
git push origin main
git tag -a vX.Y.Z -m "vX.Y.Z"
git push origin vX.Y.Z # 4. the tag pipeline publishesThe tag pipeline runs typecheck, lint, test (with the coverage floor) and build, then the publish job pushes that dist to npm. It refuses a tag that differs from package.json, and skips a version already on npm. It needs NPM_TOKEN (an npm automation token) as a protected, masked CI variable and v* as a protected tag. pnpm release (npm login + build + publish) remains the manual fallback.
Troubleshooting
pnpm install warns EPEERINVALID for react / next. Your app is on a pre-19 React or pre-16 Next.js. nekit 1.x does not support those floors. See Compatibility.
Component cannot be imported from a Server Component when importing from /forms, /rbac, /bootstrap, /auth/client, /data/query, /theme, /pwa, or /hooks. Those subpaths carry "use client" at their entry. Either wrap your file with "use client" or pass the component down through children from a client wrapper.
@tradalab/[email protected] is not in the npm registry. That version was never published — check pnpm view @tradalab/nekit versions. nekit resolves from the public npm registry, so no .npmrc or auth token is needed.
useSession() returns null even though the user is logged in. Check that <NekitProvider> is in the tree (it mounts <SessionProvider> internally). If it is, check (a) the API route handler app/api/auth/[...nextauth]/route.ts exists and exports { GET, POST } from your auth.ts, (b) AUTH_SECRET is set, (c) the session cookie isn't being stripped by an over-eager CSP.
Hydration warning on <html>. Required by next-themes (mounted inside <NekitProvider>). The suppressHydrationWarning on <html> is intentional and only affects that element — it does not silence hydration warnings elsewhere.
pnpm release fails with "version already exists". This version is already on npm. Bump the version with a new changeset (changeset publish skips already-published versions, so this only surfaces on a manual re-publish of the same version).
Contributing
See CONTRIBUTING.md. Internal Slack: #frontend-platform.
License
UNLICENSED — internal Tradalab use only.
