@happyvertical/smrt-subscriptions 0.51.19 → 0.51.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,22 @@
1
1
  import { SmrtCollection, SmrtObject } from '@happyvertical/smrt-core';
2
2
  export type PricingStrategy = 'fixed_unit' | 'cost_plus' | 'multiplier' | 'tiered' | 'included_overage' | 'flat' | 'custom';
3
3
  export type SpendingPolicyBehavior = 'observe' | 'warn' | 'block' | 'approval_required';
4
- export type SpendingPeriod = 'day' | 'week' | 'month' | 'year' | 'rolling';
4
+ /**
5
+ * `balance` is a prepaid credit balance: the policy's limit is the sum of its
6
+ * {@link CreditGrant}s and spend accumulates from `balanceFrom` onward.
7
+ */
8
+ export type SpendingPeriod = 'day' | 'week' | 'month' | 'year' | 'rolling' | 'balance';
9
+ /**
10
+ * Which charges a spending policy counts (#3059).
11
+ *
12
+ * - `billed`: provider charges payable by the policy tenant (`ClientCharge`
13
+ * rows whose `tenantId` is the tenant) — the pre-#3059 behavior.
14
+ * - `retail`: what the tenant owes its reseller (`RetailCharge` rows).
15
+ * - `wholesale`: what the policy's parent (`setByTenantId`) pays the provider
16
+ * for this tenant's usage (`ClientCharge` rows billed to the parent with
17
+ * `usageTenantId` = the tenant). Requires a delegated policy.
18
+ */
19
+ export type SpendingBasis = 'billed' | 'retail' | 'wholesale';
5
20
  export declare class PricingRule extends SmrtObject {
6
21
  tenantId?: string;
7
22
  ruleKey: string;
@@ -14,12 +29,21 @@ export declare class PricingRule extends SmrtObject {
14
29
  priority: number;
15
30
  terms: string;
16
31
  active: boolean;
32
+ /**
33
+ * The price book this rule belongs to (#3059), or empty for a tenant's
34
+ * direct pricing. Book rules are priced only through
35
+ * `CommercialUsageService.rateUsage()`; `price()` ignores them.
36
+ */
37
+ priceBookId: string;
17
38
  getTerms(): Record<string, unknown>;
18
39
  setTerms(value: Record<string, unknown>): void;
19
40
  }
20
41
  export declare class ClientCharge extends SmrtObject {
42
+ /** The payer: the usage tenant, or its billing owner when parent-billed. */
21
43
  tenantId?: string;
22
44
  usageEventId: string;
45
+ /** The tenant whose usage was charged; differs from `tenantId` for wholesale. */
46
+ usageTenantId: string;
23
47
  subscriberKind: string;
24
48
  subscriberExternalId: string;
25
49
  projectId: string;
@@ -44,6 +68,8 @@ export declare class ClientCharge extends SmrtObject {
44
68
  amount: number;
45
69
  currency: string;
46
70
  pricingRuleId: string;
71
+ /** Wholesale book that priced this charge, or empty for direct pricing. */
72
+ priceBookId: string;
47
73
  pricingSnapshot: string;
48
74
  status: 'draft' | 'approved' | 'adjusted';
49
75
  approvedAt: Date | null;
@@ -81,13 +107,47 @@ export declare class SpendingPolicy extends SmrtObject {
81
107
  * Spending cap in **integer minor units** of {@link currency}. Compared
82
108
  * directly against the sum of `ClientCharge.amount` + `BillingAdjustment`s
83
109
  * plus the caller's estimate, so it must carry the same unit (#2401).
110
+ * Must be zero for a `balance` policy, whose limit is its credit grants.
84
111
  */
85
112
  limitAmount: number;
86
113
  currency: string;
87
114
  behavior: SpendingPolicyBehavior;
88
115
  priority: number;
89
116
  active: boolean;
117
+ /** Which charges count toward the policy; see {@link SpendingBasis}. */
118
+ basis: SpendingBasis;
119
+ /**
120
+ * The parent tenant that set this policy on its child (#3059), or empty for
121
+ * a tenant's own policy. A delegated policy can be changed or deleted only
122
+ * by that parent, a system context, or a super-admin bypass.
123
+ */
124
+ setByTenantId: string;
125
+ /** Start of the spend window for a `balance` policy; defaults to creation. */
126
+ balanceFrom: Date | null;
90
127
  protected validateBeforeSave(): Promise<void>;
128
+ /**
129
+ * A balance policy's credit grants are scoped to its currency and period;
130
+ * changing either would silently detach the ledger, so create a new
131
+ * balance instead.
132
+ */
133
+ protected assertBalanceLedgerStable(rows: Array<Record<string, unknown> | null>): Promise<void>;
134
+ /**
135
+ * The rows this save can overwrite: by id and, because a new object may
136
+ * already carry a generated id, by conflict key (an upsert target).
137
+ */
138
+ protected persistedTargets(): Promise<Array<Record<string, unknown> | null>>;
139
+ /**
140
+ * A delegated policy belongs to the parent that set it: the constrained
141
+ * child cannot create one in a parent's name, loosen it, or delete it.
142
+ * The parent's-own-context allowance applies only where no tenancy
143
+ * interceptor is registered; with one, the interceptor refuses a parent
144
+ * writing the child's row, so parents change delegated policies through
145
+ * `ResellerBillingService.setDelegatedSpendingPolicy()` (set
146
+ * `active: false` to retire one).
147
+ * Checks both the persisted row (by id, or by conflict key for an upsert)
148
+ * and the incoming value.
149
+ */
150
+ protected assertDelegationAuthority(targets?: Array<Record<string, unknown> | null>): Promise<void>;
91
151
  }
92
152
  export declare class PricingRuleCollection extends SmrtCollection<PricingRule> {
93
153
  static readonly _itemClass: typeof PricingRule;
@@ -1 +1 @@
1
- {"version":3,"file":"commercial.d.ts","sourceRoot":"","sources":["../../src/models/commercial.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAGlC,MAAM,MAAM,eAAe,GACvB,YAAY,GACZ,WAAW,GACX,YAAY,GACZ,QAAQ,GACR,kBAAkB,GAClB,MAAM,GACN,QAAQ,CAAC;AACb,MAAM,MAAM,sBAAsB,GAC9B,SAAS,GACT,MAAM,GACN,OAAO,GACP,mBAAmB,CAAC;AACxB,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAE3E,qBAOa,WAAY,SAAQ,UAAU;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAM;IACrB,SAAS,EAAE,MAAM,CAAM;IACvB,UAAU,EAAE,MAAM,CAAM;IACxB,QAAQ,EAAE,eAAe,CAAgB;IACzC,QAAQ,EAAE,MAAM,CAAS;IACzB,aAAa,EAAE,IAAI,CAAc;IACjC,WAAW,EAAE,IAAI,GAAG,IAAI,CAAQ;IAChC,QAAQ,EAAE,MAAM,CAAK;IACrB,KAAK,EAAE,MAAM,CAAQ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ior, } from './commercial.js';
1
+ export type { PricingStrategy, SpendingBasis, SpendingPeriod, SpendingPolicyBehavior, } from './commercial.js';
2
2
  export { BillingAdjustment, BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, PricingRule, PricingRuleCollection, SpendingPolicy, SpendingPolicyCollection, } from './commercial.js';
3
+ export type { PriceBookKind } from './reseller.js';
4
+ export { CreditGrant, CreditGrantCollection, isCurrencyCode, isPriceBookKind, PriceBook, PriceBookAssignment, PriceBookCollection, RetailCharge, RetailChargeCollection, } from './reseller.js';
3
5
  export { SubscriptionPlan } from './SubscriptionPlan.js';
4
6
  export { TenantSubscription } from './TenantSubscription.js';
5
7
  export { TenantUsageMetric } from './TenantUsageMetric.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,YAAY,EACZ,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,eAAe,EACf,aAAa,EACb,cAAc,EACd,sBAAsB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EACjB,2BAA2B,EAC3B,YAAY,EACZ,sBAAsB,EACtB,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,SAAS,EACT,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,EACZ,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,107 @@
1
+ import { SmrtCollection, SmrtObject } from '@happyvertical/smrt-core';
2
+ /**
3
+ * `wholesale` books price what a service provider charges a reseller for its
4
+ * children's usage; `retail` books price what a reseller charges its children.
5
+ */
6
+ export type PriceBookKind = 'wholesale' | 'retail';
7
+ export declare function isPriceBookKind(value: unknown): value is PriceBookKind;
8
+ /** ISO 4217-shaped (three upper-case letters) currency code check. */
9
+ export declare function isCurrencyCode(value: unknown): value is string;
10
+ /**
11
+ * A named set of prices published by one seller tenant. Its prices are
12
+ * ordinary {@link PricingRule} rows that carry this book's id and the same
13
+ * tenant; one rule per currency gives a price in several currencies.
14
+ */
15
+ export declare class PriceBook extends SmrtObject {
16
+ /** The seller that publishes and owns the book. */
17
+ tenantId?: string;
18
+ bookKey: string;
19
+ name: string;
20
+ kind: PriceBookKind;
21
+ active: boolean;
22
+ protected validateBeforeSave(): Promise<void>;
23
+ }
24
+ /**
25
+ * Which price books rate one child tenant's usage, keyed like the tenancy
26
+ * billing relationship it belongs to (one row per child). The reseller is
27
+ * recorded so an assignment made under one relationship never prices usage
28
+ * after the child moves to a different reseller.
29
+ *
30
+ * A system table managed through `ResellerBillingService`, like
31
+ * `_smrt_billing_relationships`; it has no generated API surface.
32
+ */
33
+ export declare class PriceBookAssignment extends SmrtObject {
34
+ childTenantId: string;
35
+ resellerTenantId: string;
36
+ wholesalePriceBookId: string;
37
+ wholesaleCurrency: string;
38
+ retailPriceBookId: string;
39
+ retailCurrency: string;
40
+ }
41
+ /**
42
+ * What a reseller charges one child for one usage event, priced from the
43
+ * reseller's retail book. The provider's charge for the same event is the
44
+ * {@link ClientCharge} in `clientChargeId`, payable by the billing owner.
45
+ *
46
+ * `tenantId` is always the payer (the child), so tenant-scoped reads and the
47
+ * child's `retail`-basis spending policies see exactly what it owes.
48
+ */
49
+ export declare class RetailCharge extends SmrtObject {
50
+ tenantId?: string;
51
+ resellerTenantId: string;
52
+ usageEventId: string;
53
+ clientChargeId: string;
54
+ subscriberKind: string;
55
+ subscriberExternalId: string;
56
+ projectId: string;
57
+ workRefType: string;
58
+ workRefId: string;
59
+ provider: string;
60
+ serviceKey: string;
61
+ metricKey: string;
62
+ /** Metered quantity; fractional, like `ClientCharge.quantity`. */
63
+ quantity: number;
64
+ /** Charge in integer minor units of {@link currency}. */
65
+ amount: number;
66
+ currency: string;
67
+ priceBookId: string;
68
+ pricingRuleId: string;
69
+ pricingSnapshot: string;
70
+ status: 'draft' | 'approved';
71
+ approvedAt: Date | null;
72
+ getPricingSnapshot(): Record<string, unknown>;
73
+ protected validateBeforeSave(): Promise<void>;
74
+ }
75
+ /**
76
+ * An append-only credit on a prepaid (`period: 'balance'`) spending policy.
77
+ * Positive amounts add credit; a negative amount reverses an earlier grant.
78
+ */
79
+ export declare class CreditGrant extends SmrtObject {
80
+ /** The tenant whose balance is credited (the policy's tenant). */
81
+ tenantId?: string;
82
+ spendingPolicyId: string;
83
+ /** Signed credit in integer minor units of {@link currency}. */
84
+ amount: number;
85
+ currency: string;
86
+ reason: string;
87
+ source: string;
88
+ sourceId: string;
89
+ /** A parent tenant that granted the credit, or empty when self-granted. */
90
+ grantedByTenantId: string;
91
+ /** Append-only: history is corrected by a reversing grant, never removed. */
92
+ protected refuseDelete(): void;
93
+ protected validateBeforeSave(): Promise<void>;
94
+ }
95
+ export declare class PriceBookCollection extends SmrtCollection<PriceBook> {
96
+ static readonly _itemClass: typeof PriceBook;
97
+ }
98
+ export declare class PriceBookAssignmentCollection extends SmrtCollection<PriceBookAssignment> {
99
+ static readonly _itemClass: typeof PriceBookAssignment;
100
+ }
101
+ export declare class RetailChargeCollection extends SmrtCollection<RetailCharge> {
102
+ static readonly _itemClass: typeof RetailCharge;
103
+ }
104
+ export declare class CreditGrantCollection extends SmrtCollection<CreditGrant> {
105
+ static readonly _itemClass: typeof CreditGrant;
106
+ }
107
+ //# sourceMappingURL=reseller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reseller.d.ts","sourceRoot":"","sources":["../../src/models/reseller.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIL,cAAc,EACd,UAAU,EAEX,MAAM,0BAA0B,CAAC;AAWlC;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG,QAAQ,CAAC;AAKnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,sEAAsE;AACtE,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;;GAIG;AACH,qBAQa,SAAU,SAAQ,UAAU;IACvC,mDAAmD;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAM;IACrB,IAAI,EAAE,MAAM,CAAM;IAClB,IAAI,EAAE,aAAa,CAAY;IAC/B,MAAM,EAAE,OAAO,CAAQ;cAEP,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC;CASpD;AAED;;;;;;;;GAQG;AACH,qBAOa,mBAAoB,SAAQ,UAAU;IAGjD,aAAa,EAAE,MAAM,CAAM;IAG3B,gBAAgB,EAAE,MAAM,CAAM;IAE9B,oBAAoB,EAAE,MAAM,CAAM;IAClC,iBAAiB,EAAE,MAAM,CAAM;IAE/B,iBAAiB,EAAE,MAAM,CAAM;IAC/B,cAAc,EAAE,MAAM,CAAM;CAC7B;AAED;;;;;;;GAOG;AACH,qBAQa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AAI,OAAO,CAAC,IAAI,CAAC;CA+CpD;AAED,qBAAa,mBAAoB,SAAQ,cAAc,CAAC,SAAS,CAAC;IAChE,MAAM,CAAC,QAAQ,CAAC,UAAU,mBAAa;CACxC;AACD,qBAAa,6BAA8B,SAAQ,cAAc,CAAC,mBAAmB,CAAC;IACpF,MAAM,CAAC,QAAQ,CAAC,UAAU,6BAAuB;CAClD;AACD,qBAAa,sBAAuB,SAAQ,cAAc,CAAC,YAAY,CAAC;IACtE,MAAM,CAAC,QAAQ,CAAC,UAAU,sBAAgB;CAC3C;AACD,qBAAa,qBAAsB,SAAQ,cAAc,CAAC,WAAW,CAAC;IACpE,MAAM,CAAC,QAAQ,CAAC,UAAU,qBAAe;CAC1C"}
@@ -1,13 +1,39 @@
1
1
  import { SmrtClassOptions } from '@happyvertical/smrt-core';
2
+ import { BillingRelationshipService } from '@happyvertical/smrt-tenancy';
2
3
  import { SqlAdapterType } from '@happyvertical/sql';
3
4
  import { TenantUsageMetricCollection } from '../collections/TenantUsageMetricCollection.js';
4
- import { BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, PricingRule, PricingRuleCollection, SpendingPolicyCollection } from '../models/commercial.js';
5
+ import { BillingAdjustmentCollection, ClientCharge, ClientChargeCollection, PricingRule, PricingRuleCollection, SpendingBasis, SpendingPolicyCollection } from '../models/commercial.js';
6
+ import { CreditGrant, CreditGrantCollection, PriceBook, RetailCharge, RetailChargeCollection } from '../models/reseller.js';
7
+ import { TenantUsageMetric } from '../models/TenantUsageMetric.js';
5
8
  import { RecordUsageOptions, SubscriberKind } from '../types.js';
6
9
  export interface PriceUsageOptions {
7
10
  usageEventId: string;
8
11
  approved?: boolean;
9
12
  at?: Date;
10
13
  }
14
+ /** The released smrt-tenancy billing-owner read this package depends on. */
15
+ export type BillingRelationshipReader = Pick<BillingRelationshipService, 'getRelationship'>;
16
+ export interface RateUsageOptions extends PriceUsageOptions {
17
+ /** Resolves the usage tenant's reseller relationship and billing owner. */
18
+ billingRelationships: BillingRelationshipReader;
19
+ }
20
+ /**
21
+ * The outcome of rating one usage event (#3059). A usage event is rated
22
+ * exactly once: the first rating fixes the payer and price books, and later
23
+ * calls return the same records even if the billing owner has since changed.
24
+ */
25
+ export interface UsageRating {
26
+ /** The tenant that produced the usage. */
27
+ usageTenantId: string;
28
+ /** Who pays the provider: the usage tenant, or its reseller. */
29
+ billingOwnerTenantId: string;
30
+ /** `direct` for self-billed usage, `wholesale` for reseller-billed usage. */
31
+ mode: 'direct' | 'wholesale';
32
+ /** The provider's charge, payable by {@link billingOwnerTenantId}. */
33
+ charge: ClientCharge;
34
+ /** The reseller's retail charge to the child, when a retail book applies. */
35
+ retailCharge: RetailCharge | null;
36
+ }
11
37
  export interface CustomPricingContext {
12
38
  usage: {
13
39
  quantity: number;
@@ -44,11 +70,36 @@ export declare class CommercialUsageService {
44
70
  private readonly adjustments;
45
71
  private readonly billingStorage;
46
72
  private readonly customStrategies;
73
+ private resellerCollections?;
47
74
  constructor(usage: TenantUsageMetricCollection, rules: PricingRuleCollection, charges: ClientChargeCollection, adjustments: BillingAdjustmentCollection, billingStorage: CommercialBillingStorage);
48
75
  static create(options?: CommercialUsageServiceOptions): Promise<CommercialUsageService>;
49
76
  registerCustomStrategy(key: string, strategy: CustomPricingStrategy): void;
50
- record(options: RecordUsageOptions): Promise<import('../index.js').TenantUsageMetric>;
77
+ record(options: RecordUsageOptions): Promise<TenantUsageMetric>;
51
78
  price(options: PriceUsageOptions): Promise<ClientCharge>;
79
+ /**
80
+ * Rate one usage event under its billing owner's price books (#3059).
81
+ *
82
+ * - No reseller relationship, or a `self`-billed one: the usage tenant pays
83
+ * the provider directly, priced exactly as {@link price} prices it.
84
+ * - `reseller`-billed: the reseller pays the provider from the child's
85
+ * assigned wholesale book (a {@link ClientCharge} with `tenantId` = the
86
+ * reseller and `usageTenantId` = the child) and, when the child has a
87
+ * retail book assigned, the child owes the reseller a
88
+ * {@link RetailCharge}. Both records commit in one transaction.
89
+ *
90
+ * Rating is idempotent per usage event and frozen at first rating: a later
91
+ * billing-owner change never re-prices or double-charges an event that
92
+ * already has a provider charge, because `ClientCharge` holds exactly one
93
+ * row per usage event.
94
+ *
95
+ * Rating reads the seller's books across tenants; run it where the host's
96
+ * tenancy rules allow that (typically a system context).
97
+ */
98
+ rateUsage(options: RateUsageOptions): Promise<UsageRating>;
99
+ private rateResellerBilled;
100
+ private selectBookRule;
101
+ private frozenRating;
102
+ private getResellerCollections;
52
103
  private approveCharge;
53
104
  /**
54
105
  * Append a signed correction to an approved charge.
@@ -85,8 +136,13 @@ export interface SpendingDecision {
85
136
  */
86
137
  projectedAmount: number;
87
138
  matchedPolicyId: string | null;
139
+ /**
140
+ * For a prepaid `balance` policy: credit remaining before this estimate
141
+ * (grants minus spend), in integer minor units. Absent for other periods.
142
+ */
143
+ balanceAmount?: number;
88
144
  }
89
- interface SpendingEvaluationInput {
145
+ export interface SpendingEvaluationInput {
90
146
  tenantId: string;
91
147
  subscriberKind?: SubscriberKind;
92
148
  subscriberExternalId?: string;
@@ -95,17 +151,102 @@ interface SpendingEvaluationInput {
95
151
  metricKey: string;
96
152
  /** Estimated cost of the pending call, in integer minor units (#2401). */
97
153
  estimatedAmount: number;
154
+ /**
155
+ * Per-basis estimates, in integer minor units, for policies whose basis
156
+ * prices the call differently (a retail estimate for `retail` policies, a
157
+ * wholesale estimate for `wholesale` ones). Falls back to
158
+ * {@link estimatedAmount}.
159
+ */
160
+ estimatedAmounts?: Partial<Record<SpendingBasis, number>>;
98
161
  currency: string;
99
162
  at?: Date;
100
163
  }
164
+ /** Context handed to an {@link AutoTopUpHook} when a balance would run out. */
165
+ export interface AutoTopUpRequest {
166
+ policyId: string;
167
+ tenantId: string;
168
+ /** The parent that set the policy, or empty for the tenant's own policy. */
169
+ setByTenantId: string;
170
+ currency: string;
171
+ /** Credit remaining before the estimate, in integer minor units. */
172
+ balanceAmount: number;
173
+ estimatedAmount: number;
174
+ /** How far the estimate overshoots the balance, in integer minor units. */
175
+ shortfall: number;
176
+ }
177
+ /**
178
+ * A top-up the hook has secured. `sourceId` makes it idempotent: the same
179
+ * `source`/`sourceId` pair is credited once however often it is returned.
180
+ */
181
+ export interface AutoTopUpGrant {
182
+ amount: number;
183
+ sourceId: string;
184
+ source?: string;
185
+ reason?: string;
186
+ }
187
+ /**
188
+ * Host hook for prepaid balances. Called when a pending charge would exhaust a
189
+ * `balance` policy; return a grant to credit it (after the host has secured
190
+ * the funds) or nothing to let the policy's behavior apply. The evaluator
191
+ * never calls a payment provider itself.
192
+ */
193
+ export type AutoTopUpHook = (request: AutoTopUpRequest) => AutoTopUpGrant | null | undefined | Promise<AutoTopUpGrant | null | undefined>;
194
+ export interface SpendingPolicyEvaluatorOptions extends SmrtClassOptions {
195
+ autoTopUp?: AutoTopUpHook;
196
+ /**
197
+ * The smrt-tenancy relationship reader. When supplied, a delegated policy
198
+ * applies only while its `setByTenantId` is the tenant's current reseller;
199
+ * without it every delegated policy applies (fail closed).
200
+ */
201
+ billingRelationships?: BillingRelationshipReader;
202
+ }
203
+ export interface GrantCreditInput {
204
+ spendingPolicyId: string;
205
+ /** Signed, nonzero credit in integer minor units of the policy currency. */
206
+ amount: number;
207
+ reason?: string;
208
+ /** With `sourceId`, makes the grant idempotent (a payment or order id). */
209
+ source?: string;
210
+ sourceId?: string;
211
+ /** The parent granting credit on its child's delegated policy. */
212
+ grantedByTenantId?: string;
213
+ }
214
+ export interface SpendingPolicyEvaluatorExtensions {
215
+ retailCharges?: RetailChargeCollection;
216
+ credits?: CreditGrantCollection;
217
+ autoTopUp?: AutoTopUpHook;
218
+ billingRelationships?: BillingRelationshipReader;
219
+ }
101
220
  export declare class SpendingPolicyEvaluator {
102
221
  private readonly policies;
103
222
  private readonly charges;
104
223
  private readonly adjustments;
105
- constructor(policies: SpendingPolicyCollection, charges: ClientChargeCollection, adjustments: BillingAdjustmentCollection);
106
- static create(options?: SmrtClassOptions): Promise<SpendingPolicyEvaluator>;
224
+ private readonly extensions;
225
+ private ledgers?;
226
+ constructor(policies: SpendingPolicyCollection, charges: ClientChargeCollection, adjustments: BillingAdjustmentCollection, extensions?: SpendingPolicyEvaluatorExtensions);
227
+ static create(options?: SpendingPolicyEvaluatorOptions): Promise<SpendingPolicyEvaluator>;
107
228
  evaluate(input: SpendingEvaluationInput): Promise<SpendingDecision>;
229
+ /**
230
+ * Drop delegated policies whose parent is no longer the tenant's reseller,
231
+ * when a relationship reader is configured.
232
+ */
233
+ private withoutStaleDelegations;
234
+ /**
235
+ * Credit a prepaid `balance` policy. A delegated policy accepts grants only
236
+ * from the parent that set it (or a system context / super-admin bypass).
237
+ */
238
+ grantCredit(input: GrantCreditInput): Promise<CreditGrant>;
239
+ private recordGrant;
108
240
  private evaluatePolicy;
241
+ /** Approved spend in the policy's window, currency, scope, and basis. */
242
+ private spentFor;
243
+ private sumProviderCharges;
244
+ private creditFor;
245
+ private getLedgers;
109
246
  }
110
- export {};
247
+ /**
248
+ * The provider leg must be priced by someone other than the payer: a reseller
249
+ * (or its child) never publishes the wholesale book it is charged from.
250
+ */
251
+ export declare function assertWholesalePublisher(book: PriceBook, resellerTenantId: string, childTenantId: string): void;
111
252
  //# sourceMappingURL=commercial.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"commercial.d.ts","sourceRoot":"","sources":["../../src/services/commercial.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,2BAA2B,EAAE,MAAM,+CAA+C,CAAC;AAC5F,OAAO,EACL,2BAA2B,EAC3B,KAAK,YAAY,EACjB,sBAAsB,EACtB,KAAK,WAAW,EAChB,qBAAqB,EAGrB,wBAAwB,EACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAOtE,MAAM,WAAW,iBAAiB;I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AAwB,EAClC,OAAO,EAAE,sBAAsB,EAC/B,WAAW,EAAE,2BAA2B,EACxC,UAAU,GAAE,iCAAsC;WAExD,MAAM,CAAC,OAAO,GAAE,8BAAmC;IAiB1D,QAAQ,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA2CzE;;;OAGG;YACW,uBAAuB;IAerC;;;OAGG;IACG,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,WAAW,CAAC;YAkClD,WAAW;YAqDX,cAAc;IAgD5B,yEAAyE;YAC3D,QAAQ;YAmDR,kBAAkB;YA2ClB,SAAS;IAsBvB,OAAO,CAAC,UAAU;CAoBnB;AAsDD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,SAAS,EACf,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,GACpB,IAAI,CAQN"}
@@ -1,6 +1,8 @@
1
1
  export type { EntitlementResolutionContext } from '../types.js';
2
- export type { CommercialBillingStorage, CommercialUsageServiceOptions, CustomPricingContext, CustomPricingStrategy, PriceUsageOptions, SpendingDecision, } from './commercial.js';
2
+ export type { AutoTopUpGrant, AutoTopUpHook, AutoTopUpRequest, BillingRelationshipReader, CommercialBillingStorage, CommercialUsageServiceOptions, CustomPricingContext, CustomPricingStrategy, GrantCreditInput, PriceUsageOptions, RateUsageOptions, SpendingDecision, SpendingEvaluationInput, SpendingPolicyEvaluatorExtensions, SpendingPolicyEvaluatorOptions, UsageRating, } from './commercial.js';
3
3
  export { assertCommercialBillingStorageSupported, CommercialBillingStorageConfigurationError, CommercialUsageService, SpendingPolicyEvaluator, UnsupportedCommercialBillingStorageError, } from './commercial.js';
4
+ export { type AssignPriceBooksInput, type DefinePriceBookPriceInput, type DelegatedSpendingPolicyInput, type GrantChildCreditInput, type PriceBookAssignmentView, type PriceBookLeg, type ResellerBillingAction, ResellerBillingService, type ResellerBillingServiceOptions, } from './reseller.js';
5
+ export { ResellerBillingError, type ResellerBillingErrorCode, } from './reseller-errors.js';
4
6
  export { type SubscriptionPlanReader, SubscriptionResolver, type SubscriptionResolverReaders, type TenantSubscriptionReader, type UsageSummaryReader, } from './subscription-resolver.js';
5
7
  export { evaluateThreshold, evaluateThresholds, } from './threshold-evaluator.js';
6
8
  export { TenantUsageMeter } from './usage-meter.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EACV,wBAAwB,EACxB,6BAA6B,EAC7B,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,uCAAuC,EACvC,0CAA0C,EAC1C,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,GACzC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,sBAAsB,EAC3B,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAChE,YAAY,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,6BAA6B,EAC7B,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,uBAAuB,EACvB,iCAAiC,EACjC,8BAA8B,EAC9B,WAAW,GACZ,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,uCAAuC,EACvC,0CAA0C,EAC1C,sBAAsB,EACtB,uBAAuB,EACvB,wCAAwC,GACzC,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,uBAAuB,EAC5B,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,sBAAsB,EACtB,KAAK,6BAA6B,GACnC,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,KAAK,sBAAsB,EAC3B,oBAAoB,EACpB,KAAK,2BAA2B,EAChC,KAAK,wBAAwB,EAC7B,KAAK,kBAAkB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type ResellerBillingErrorCode = 'INVALID_TENANT' | 'INVALID_CURRENCY' | 'INVALID_AMOUNT' | 'PRICE_BOOK_NOT_FOUND' | 'PRICE_BOOK_INACTIVE' | 'PRICE_BOOK_KIND_MISMATCH' | 'PRICE_BOOK_OWNER_MISMATCH' | 'PRICE_BOOK_NOT_ASSIGNED' | 'NO_EFFECTIVE_PRICE' | 'RELATIONSHIP_REQUIRED' | 'POLICY_NOT_FOUND' | 'POLICY_NOT_BALANCE' | 'POLICY_CONFLICT' | 'ASSIGNMENT_CONFLICT';
2
+ /** A reseller price book, rating, or delegated-spending rule was violated. */
3
+ export declare class ResellerBillingError extends Error {
4
+ readonly code: ResellerBillingErrorCode;
5
+ constructor(message: string, code: ResellerBillingErrorCode);
6
+ }
7
+ //# sourceMappingURL=reseller-errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reseller-errors.d.ts","sourceRoot":"","sources":["../../src/services/reseller-errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,wBAAwB,GAChC,gBAAgB,GAChB,kBAAkB,GAClB,gBAAgB,GAChB,sBAAsB,GACtB,qBAAqB,GACrB,0BAA0B,GAC1B,2BAA2B,GAC3B,yBAAyB,GACzB,oBAAoB,GACpB,uBAAuB,GACvB,kBAAkB,GAClB,oBAAoB,GACpB,iBAAiB,GACjB,qBAAqB,CAAC;AAE1B,8EAA8E;AAC9E,qBAAa,oBAAqB,SAAQ,KAAK;aAG3B,IAAI,EAAE,wBAAwB;gBAD9C,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,wBAAwB;CAKjD"}