@flinkk/tenant-form
v1.0.4
Published
Tenant lifecycle data operations (create/read/update/delete, license-aware onboarding) for Flinkk CRM
Readme
@flinkk/tenant-form
Data/service-layer functions for creating, reading, updating, and deleting Tenant rows and their initial seed data — the one place tenant provisioning logic lives, so callers (a signup flow, an admin "add organization" screen, or a CLI script) don't each reimplement it slightly differently.
Exports
All from the package root (import { ... } from "@flinkk/tenant-form"):
| Export | What it does |
| --- | --- |
| createTenant(input: CreateTenantInput) | Creates a Tenant row and seeds its default data in one call: system roles, the creator's Owner membership (if createdById is given), status options, standard fields, lead-conversion mapping, and currency configurations. Runs inside the new tenant's own request context so every seed step is properly scoped under a saas-standalone license. |
| getTenantById(id) / getTenantByDomainOrSlug(domainOrSlug) / listTenants(filter?) | Read helpers. |
| updateTenant(id, input: UpdateTenantInput) | Partial update of tenant settings (name, branding, address, tax config, etc). |
| deleteTenant(id) | Deletes a tenant. |
License-aware tenant ids
Under a "standalone" or "saas-standalone" license, a new tenant's id cannot be arbitrary — extensions/tenant-filter.ts in @flinkk/database forces every query to the license's fixed tenant (standalone) or rejects any tenant not in the license's allowed list (saas-standalone). createTenant calls resolveLicensedTenantId() internally to enforce this: under standalone it ignores input.id and uses the license's one fixed tenant (erroring if that tenant already exists — only one is ever permitted); under saas-standalone it requires input.id to be one of the license's allowed tenant ids and errors if that id is already provisioned. Getting this wrong doesn't fail loudly at the database level — the tenant would be created successfully but be permanently unreachable through every tenant-scoped query in the app, so input.id must match the license exactly for those two license types.
Under "saas" (unrestricted), input.id is used as given, or Prisma auto-generates one if omitted.
Usage
import { createTenant } from "@flinkk/tenant-form";
const tenant = await createTenant({
name: "Acme Inc",
id: "cmo8mley900018gtikrcaokt0", // required under standalone/saas-standalone; must match the license
domain: "acme.example.com",
currency: "USD",
country: "US",
createdById: userId, // omit for unattended/seed creation - no Owner membership is created
});There's also a CLI entry point for provisioning a tenant outside the app itself:
ts-node --transpile-only scripts/create-tenant-cli.ts \
--name "Acme Inc" --id acme --domain acme.example.com \
--currency USD --country US --created-by <userId>Not yet wired here
help-portal defaults, default reports, notification-email config, quote templates, and email templates are currently only reachable as HTTP routes under the consuming app's app/api/setup/* (not as importable functions from this package) — callers that need those still call those routes directly.
License
ISC License - Internal Flinkk library
