@tall-staik/commons
v0.0.8
Published
Shared types, schemas, and utilities for TallStaik applications
Downloads
31
Maintainers
Readme
@tall-staik/commons
Shared types, schemas, utilities, and constants for TallStaik applications.
Installation
npm install @tall-staik/commons
# or
pnpm add @tall-staik/commons
# or
yarn add @tall-staik/commonsUsage
Types
import type {
User,
Organization,
AuthTokens,
TenantContext,
ApiResponse,
UserRole,
} from "@tall-staik/commons";
// Or import from specific module
import type { User, Organization } from "@tall-staik/commons/types";Schemas (Zod)
import {
loginSchema,
registerSchema,
createOrganizationSchema,
type LoginInput,
type RegisterInput,
} from "@tall-staik/commons";
// Or import from specific module
import { loginSchema } from "@tall-staik/commons/schemas";
// Validate input
const result = loginSchema.safeParse(formData);
if (result.success) {
const data: LoginInput = result.data;
}Utilities
import {
hasPermission,
slugify,
formatBytes,
getRelativeTime,
isValidEmail,
} from "@tall-staik/commons";
// Or import from specific module
import { hasPermission, slugify } from "@tall-staik/commons/utils";
// Check permissions
if (hasPermission(user.role, "members:invite")) {
// Allow action
}
// Generate slug
const slug = slugify("My Organization Name"); // "my-organization-name"Constants
import {
ErrorCodes,
HttpStatus,
AuthConstants,
PlanLimits,
} from "@tall-staik/commons";
// Or import from specific module
import { ErrorCodes, HttpStatus } from "@tall-staik/commons/constants";
// Use constants
if (response.status === HttpStatus.UNAUTHORIZED) {
// Handle unauthorized
}Multi-Tenant Model
This package is designed for multi-tenant applications:
- User: Global user account that can belong to multiple organizations
- Organization: A tenant with isolated data and settings
- Membership: Links users to organizations with specific roles
- TenantContext: Current user + organization context for requests
Example Flow
import type { TenantContext, User, Organization, OrganizationMembership } from "@tall-staik/commons";
// After authentication, you have a tenant context
const context: TenantContext = {
user: { id: "user-123", email: "[email protected]", ... },
organization: { id: "org-456", slug: "acme-corp", ... },
membership: { role: "admin", ... },
};
// Use throughout the application
function createResource(ctx: TenantContext, data: ResourceData) {
// All data is scoped to ctx.organization.id
}Development
# Install dependencies
npm install
# Build
npm run build
# Watch mode
npm run dev
# Type check
npm run type-checkVersioning
We use semantic versioning. To release a new version:
# Patch release (bug fixes)
npm run release:patch
# Minor release (new features)
npm run release:minor
# Major release (breaking changes)
npm run release:majorLicense
MIT
