UNPKG

@beignet/core

Version:

Core framework primitives for Beignet

34 lines 1.05 kB
import { requireTenant } from "../ports/auth.js"; const tenantScopeBrand = Symbol("TenantScope"); /** * Create a tenant scope from a resolved activity tenant. * * This does not load, create, or validate a tenant record. It only brands the * already-resolved tenant for repository and adapter boundaries. */ export function createTenantScope(tenant) { return { id: tenant.id, tenant, [tenantScopeBrand]: true, }; } /** * Return a branded tenant scope from `ctx.tenant` or throw. * * Throws `TenantRequiredError` by default through `requireTenant`. Pass * `options.error` to throw an app-owned error instead. */ export function requireTenantScope(ctx, options) { return createTenantScope(requireTenant(ctx, options)); } /** * Extract the stable tenant ID from a tenant scope. * * Repository adapters should use this helper at the persistence boundary * instead of accepting raw tenant IDs from use cases. */ export function tenantScopeId(scope) { return scope.id; } //# sourceMappingURL=index.js.map