@withpotter/tenant-core — module reference
HTTP routes this module mounts, plus its internal use-cases, entities, and repositories. The exhaustive request/response contract is the engine’s OpenAPI document at /docs; the layered structure below follows the package internal architecture.
HTTP routes
Tenants /tenants
| Method | Path | Auth | Description |
|---|---|---|---|
GET | /tenants/:slug | — | Get a tenant by slug |
GET | /tenants/by-domain/:domain | — | Look up a tenant by custom domain |
GET | /tenants/check-slug | — | Check whether a tenant slug is available |
GET | /tenants/current | Yes | Get the tenant resolved for the current request |
POST | /tenants | Yes | Create a new tenant |
POST | /tenants/current/discard-appearance-draft | Yes | Discard the pending appearance draft |
POST | /tenants/current/publish-appearance | Yes | Promote the appearance draft to live settings |
POST | /tenants/current/settings/colors/suggest | Yes | Extract a color palette from a logo URL |
PATCH | /tenants/current | Yes | Update the current tenant (live or draft) |
DELETE | /tenants/current | Yes | Delete the current tenant |
Internals
Use-cases
Application operations. Each is a single-purpose class with one execute() method.
| Use-case | Signature |
|---|---|
CheckSlugAvailabilityUseCase | execute(slug: string): Promise<boolean> |
CreateTenantUseCase | execute(input: CreateTenantInput) |
DeleteCurrentTenantUseCase | execute(slug: string): Promise<{ deleted: true }> |
DiscardAppearanceDraftUseCase | execute(tenant: Tenant): Promise<Tenant> |
GetCurrentTenantUseCase | execute(tenant: Tenant | null) |
GetTenantByDomainUseCase | execute(domain: string) |
GetTenantByIdUseCase | execute(id: string): Promise<Tenant | null> |
GetTenantBySlugUseCase | execute(slug: string, options?: { includeDrafts?: boolean }) |
LookupTenantByDomainUseCase | execute(domain: string): Promise<{ slug: string; id: string; name: string }> |
PublishAppearanceUseCase | execute(tenant: Tenant): Promise<Tenant> |
SuggestColorsUseCase | execute(logoUrl: string): Promise<SuggestColorsResult> |
UpdateCurrentTenantUseCase | execute(tenant: Tenant | null, dto: UpdateCurrentTenantInput, accountId?: string, target: 'draft' | 'live' = 'live') |
UpdateTenantSettingsUseCase | execute(id: string, settings: Partial<TenantSettings>) |
UpdateTenantTemplateUseCase | execute(id: string, templateId: string) |
Entities
Sequelize models owned by this module.
Account — table accounts
| Field | Type |
|---|---|
id | string |
email | string |
passwordHash | string | null |
name | string | null |
avatarUrl | string | null |
emailVerified | boolean |
lastLoginAt | Date | null |
status | AccountStatus |
passwordResetToken | string | null |
passwordResetExpires | Date | null |
maxWorkspaces | number |
authProvider | AuthProvider |
authProviderId | string | null |
createdAt | Date |
updatedAt | Date |
Organization — table organizations
| Field | Type |
|---|---|
id | string |
name | string |
slug | string |
logoUrl | string | null |
billingEmail | string | null |
status | OrganizationStatus |
subscription | Record<string, unknown> |
settings | Record<string, unknown> |
createdAt | Date |
updatedAt | Date |
id | string |
organizationId | string |
organization | Organization |
accountId | string |
account | Account |
role | OrgMemberRole |
status | OrgMemberStatus |
invitedById | string | null |
invitedAt | Date | null |
joinedAt | Date | null |
createdAt | Date |
updatedAt | Date |
Tenant — table tenants
| Field | Type |
|---|---|
id | string |
organizationId | string | null |
organization | Organization |
slug | string |
customDomain | string |
businessName | string |
email | string |
phone | string |
status | TenantStatus |
templateId | string |
industryKey | string | null |
settings | TenantSettings |
draftSettings | Record<string, unknown> | null |
paymentSettings | PaymentSettings |
subscription | Subscription |
createdAt | Date |
updatedAt | Date |
TenantEmailCredit — table tenant_email_credits
| Field | Type |
|---|---|
id | string |
tenantId | string |
tenant | Tenant |
type | EmailCreditType |
amount | number |
balanceAfter | number |
description | string | null |
referenceType | string | null |
referenceId | string | null |
amountPaid | number | null |
metadata | Record<string, unknown> | null |
createdAt | Date |
updatedAt | Date |
tenantId | string |
tenant | Tenant |
balance | number |
totalPurchased | number |
totalFromPlan | number |
totalEmailsSent | number |
totalSpent | number |
monthlyAllowance | number |
nextResetDate | Date | null |
usedThisPeriod | number |
lowBalanceThreshold | number |
createdAt | Date |
updatedAt | Date |
TenantMessagingCredit — table tenant_messaging_credits
| Field | Type |
|---|---|
id | string |
tenantId | string |
tenant | Tenant |
type | MessagingCreditType |
channel | MessagingChannel | null |
amount | number |
balanceAfter | number |
description | string | null |
referenceType | string | null |
referenceId | string | null |
amountPaid | number | null |
metadata | Record<string, unknown> | null |
createdAt | Date |
updatedAt | Date |
TenantMessagingCreditBalance — table tenant_messaging_credit_balances
| Field | Type |
|---|---|
tenantId | string |
tenant | Tenant |
balance | number |
totalPurchased | number |
totalFromPlan | number |
totalSmsUsed | number |
totalWhatsappUsed | number |
totalSpent | number |
monthlyAllowance | number |
nextResetDate | Date | null |
usedThisPeriod | number |
lowBalanceThreshold | number |
createdAt | Date |
updatedAt | Date |
Repositories
Data-access classes wrapping the entities.
AccountRepository
create · findById · findByEmail · findByAuthProvider · update · updatePassword · updateEmail · updateLastLogin · verifyEmail · existsByEmail · findByResetToken · softDelete · delete
OrganizationRepository
create · findById · findBySlug · update · existsBySlug · generateUniqueSlug · delete · findByOrgAndAccount · findAllByOrg · findAllByAccount · findOrgsForAccount · remove · isOwner · hasAccess · countActiveMembers
TenantEmailCreditRepository
create · findByTenantId · getUsageStats · getOrCreate · addCredits · useCredits · setMonthlyAllowance · resetMonthlyCredits · findAllDueForReset
TenantMessagingCreditRepository
create · findByTenantId · getUsageStats · getMonthlyUsage · getOrCreate · addCredits · useCredits · hasEnoughCredits · setMonthlyAllowance · resetMonthlyCredits · updateLowBalanceThreshold · findAllDueForReset
TenantRepository
findBySlug · findByCustomDomain · existsBySlug · updateSettings · updateTemplate · updateStatus · findByOrganization · findByIdOrFail
Generated from the module’s source. Routes are relative to the engine root
(default http://localhost:3001). For full request/response schemas use the live
OpenAPI document.