import { SubscriptionPlan } from '../models/SubscriptionPlan.js'; import { TenantSubscription } from '../models/TenantSubscription.js'; import { EntitlementResolution, EntitlementResolutionContext, PlanThreshold, SmrtClassOptions, Subscriber, SubscriptionResolverOptions, UsageSummary, UsageWindow } from '../types.js'; export interface SubscriptionPlanReader { get(criteria: { id: string; }): Promise; } /** * Reader contract for finding the current subscription for a subscriber. * * The legacy `findCurrentForTenant(tenantId)` signature stays for backward * compatibility with the original tenant-only resolver. New implementations * should provide `findCurrentForSubscriber(subscriber)` — it's preferred when * present and lets the resolver work with both `'tenant'` and `'external'` * subscribers without callers having to pre-narrow the discriminator. */ export interface TenantSubscriptionReader { findCurrentForTenant(tenantId: string, now?: Date): Promise; findCurrentForSubscriber?(subscriber: Subscriber, now?: Date): Promise; } /** * Reader contract for summarizing usage. * * `summarize(options)` already accepts the polymorphic * `subscriberKind`/`subscriberExternalId` fields. When omitted the reader * defaults to `'tenant'`, which is what existing callers got before this * change — no behavior shift for them. The discriminator type is derived * from `Subscriber['kind']` rather than inlined so any future additions to * the union stay consistent across the package. */ export interface UsageSummaryReader { summarize(options: { tenantId: string; subscriberKind?: Subscriber['kind']; subscriberExternalId?: string; metricKey: string; window: UsageWindow; }): Promise; summarizeBatch?(options: { tenantId: string; subscriberKind?: Subscriber['kind']; subscriberExternalId?: string; metricKeys: string[]; window: UsageWindow; }): Promise; } export interface SubscriptionResolverReaders { plans: SubscriptionPlanReader; subscriptions: TenantSubscriptionReader; usage: UsageSummaryReader; } export declare class SubscriptionResolver { private readonly readers; constructor(readers: SubscriptionResolverReaders); /** * Build the default resolver readers once for a request or app lifecycle and * reuse the returned resolver across entitlement checks. */ static create(classOptions?: SmrtClassOptions): Promise; /** * Load the subscription/plan pair used by entitlement resolution. Callers * that need both the entitlement snapshot and the backing records can load * this once, then pass it back via `options.context`. */ loadEntitlementContext(subscriberOrTenantId: Subscriber | string, options?: SubscriptionResolverOptions): Promise; /** * Polymorphic entitlement resolution. Works for both `'tenant'`-kind and * `'external'`-kind subscribers and is the preferred surface — the * `resolveTenantEntitlements(tenantId)` method below is a thin wrapper. */ resolveEntitlements(subscriber: Subscriber, options?: SubscriptionResolverOptions): Promise; /** * Legacy single-tenant wrapper around {@link resolveEntitlements}. Kept so * existing tenant-only callers don't need to update their call sites. */ resolveTenantEntitlements(tenantId: string, options?: SubscriptionResolverOptions): Promise; isFeatureEnabled(subscriberOrTenantId: Subscriber | string, featureKey: string, options?: SubscriptionResolverOptions): Promise; assertWithinThresholds(subscriberOrTenantId: Subscriber | string, options?: SubscriptionResolverOptions): Promise; private resolveSubscription; private resolvePlan; /** * Bridge the legacy and polymorphic reader contracts. * * Prefers `findCurrentForSubscriber` when the reader provides it (the * preferred shape). For `'tenant'` subscribers we fall back to the legacy * `findCurrentForTenant`. For `'external'` subscribers the reader MUST * implement `findCurrentForSubscriber` — otherwise we have no way to scope * the lookup and we throw rather than silently returning the tenant's * primary subscription. */ private findCurrentSubscription; private resolveThresholdEvaluations; } export type { PlanThreshold }; //# sourceMappingURL=subscription-resolver.d.ts.map