@texakey/frontend-sdk
v0.1.0
Published
Reusable frontend infrastructure for authentication, tenancy, permissions, feature gates, API access, deployment modes, and runtime configuration.
Downloads
109
Readme
@texakey/frontend-sdk
Shared frontend infrastructure for Texakey product apps. This package contains auth, tenant resolution, RBAC, feature gates, API client setup, deployment helpers, and runtime config helpers.
This repo is a library, not a Next.js app. Product repos such as EHR, admin, AI, or portal apps run Next.js and install this SDK.
Package Workflow
Install dependencies:
npm installRun local checks:
npm run typecheck
npm run build
npm run testWatch SDK source while developing:
npm run devPreview the package that npm would publish:
npm run pack:dryUse In A Next.js Repo
For local development, add the SDK as a file dependency in the product repo:
{
"dependencies": {
"@texakey/frontend-sdk": "file:../frontend-sdks"
}
}Then install from the product repo:
npm installAdd the SDK to next.config.ts:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
transpilePackages: ["@texakey/frontend-sdk"],
};
export default nextConfig;Create a client-side provider wrapper in the Next.js app, for example app/providers.tsx:
"use client";
import type { ReactNode } from "react";
import {
AuthProvider,
FeatureProvider,
PermissionProvider,
TenantProvider,
createStorageAuthAdapter,
createTenantFromSubdomain,
loadRuntimeConfig,
} from "@texakey/frontend-sdk";
const runtimeConfig = loadRuntimeConfig({
apiBaseUrl: process.env.NEXT_PUBLIC_API_BASE_URL ?? "http://localhost:3001",
productKey: process.env.NEXT_PUBLIC_PRODUCT_KEY ?? "platform-admin",
environment: process.env.NEXT_PUBLIC_APP_ENV ?? "local",
features: {},
});
const authAdapter = createStorageAuthAdapter();
export function Providers({ children }: { children: ReactNode }) {
return (
<AuthProvider adapter={authAdapter}>
<TenantProvider
resolver={() => createTenantFromSubdomain()}
>
<PermissionProvider roles={[]} permissions={[]}>
<FeatureProvider features={runtimeConfig.features ?? {}}>
{children}
</FeatureProvider>
</PermissionProvider>
</TenantProvider>
</AuthProvider>
);
}Wrap the root layout:
import type { ReactNode } from "react";
import { Providers } from "./providers";
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
<Providers>{children}</Providers>
</body>
</html>
);
}Run the product app:
npm run devBest Pre-Ship Test
Before publishing, test the exact package shape in a product repo:
cd ../frontend-sdks
npm run typecheck
npm run build
npm packThen install the tarball in a Next.js product repo:
cd ../texakey-platform-admin
npm install ../frontend-sdks/texakey-frontend-sdk-0.1.0.tgz
npm run dev
npm run buildIf both next dev and next build pass, the SDK is ready to publish.
Publish
The package is scoped as @texakey/frontend-sdk. Choose the access mode that matches your registry policy.
npm publish --access publicFor a private npm organization package:
npm publish --access restrictedAfter publishing, product repos install it normally:
npm install @texakey/frontend-sdkImport Paths
Use the root export for most app code:
import { AuthProvider, createApiClient } from "@texakey/frontend-sdk";Use subpath exports when a repo only needs one area:
import { AuthProvider } from "@texakey/frontend-sdk/auth";
import { PermissionGate } from "@texakey/frontend-sdk/rbac";
import { FeatureGate } from "@texakey/frontend-sdk/feature-gates";