@zonastery/bursar 2.0.0 → 2.0.2

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.
Files changed (173) hide show
  1. package/README.md +21 -14
  2. package/dist/billing/auto-recharge-service.d.ts.map +1 -1
  3. package/dist/billing/auto-recharge-service.js +6 -4
  4. package/dist/billing/auto-recharge-service.js.map +1 -1
  5. package/dist/billing/billing-store.d.ts +3 -0
  6. package/dist/billing/billing-store.d.ts.map +1 -1
  7. package/dist/billing/billing-store.js +2 -0
  8. package/dist/billing/billing-store.js.map +1 -1
  9. package/dist/billing/event-handlers.d.ts +2 -3
  10. package/dist/billing/event-handlers.d.ts.map +1 -1
  11. package/dist/billing/event-handlers.js +38 -49
  12. package/dist/billing/event-handlers.js.map +1 -1
  13. package/dist/billing/event-processor.js +4 -4
  14. package/dist/billing/event-processor.js.map +1 -1
  15. package/dist/billing/financial-event-handlers.d.ts +2 -2
  16. package/dist/billing/financial-event-handlers.d.ts.map +1 -1
  17. package/dist/billing/financial-event-handlers.js +7 -7
  18. package/dist/billing/financial-event-handlers.js.map +1 -1
  19. package/dist/billing/postgres/store.d.ts +5 -1
  20. package/dist/billing/postgres/store.d.ts.map +1 -1
  21. package/dist/billing/postgres/store.js +5 -0
  22. package/dist/billing/postgres/store.js.map +1 -1
  23. package/dist/billing/service-types.d.ts +2 -15
  24. package/dist/billing/service-types.d.ts.map +1 -1
  25. package/dist/billing/service-types.js.map +1 -1
  26. package/dist/billing/types/auto-recharge.d.ts.map +1 -1
  27. package/dist/billing/types/auto-recharge.js.map +1 -1
  28. package/dist/billing/types/events.d.ts +3 -2
  29. package/dist/billing/types/events.d.ts.map +1 -1
  30. package/dist/billing/types/events.js +2 -2
  31. package/dist/billing/types/events.js.map +1 -1
  32. package/dist/billing/types/subscriptions.d.ts.map +1 -1
  33. package/dist/billing/types/subscriptions.js.map +1 -1
  34. package/dist/bursar.d.ts +21 -11
  35. package/dist/bursar.d.ts.map +1 -1
  36. package/dist/bursar.js +40 -4
  37. package/dist/bursar.js.map +1 -1
  38. package/dist/catalog.d.ts.map +1 -1
  39. package/dist/catalog.js +1 -1
  40. package/dist/catalog.js.map +1 -1
  41. package/dist/commerce/index.d.ts +0 -1
  42. package/dist/commerce/index.d.ts.map +1 -1
  43. package/dist/commerce/index.js +0 -1
  44. package/dist/commerce/index.js.map +1 -1
  45. package/dist/commerce/service.d.ts.map +1 -1
  46. package/dist/commerce/service.js +99 -59
  47. package/dist/commerce/service.js.map +1 -1
  48. package/dist/commerce/types.d.ts +8 -4
  49. package/dist/commerce/types.d.ts.map +1 -1
  50. package/dist/commerce/types.js.map +1 -1
  51. package/dist/config/parse-credits.d.ts.map +1 -1
  52. package/dist/config/parse-credits.js +0 -6
  53. package/dist/config/parse-credits.js.map +1 -1
  54. package/dist/config/types.d.ts +0 -5
  55. package/dist/config/types.d.ts.map +1 -1
  56. package/dist/config/types.js.map +1 -1
  57. package/dist/config.d.ts.map +1 -1
  58. package/dist/config.js +7 -0
  59. package/dist/config.js.map +1 -1
  60. package/dist/credits/amount.d.ts +8 -0
  61. package/dist/credits/amount.d.ts.map +1 -0
  62. package/dist/credits/amount.js +32 -0
  63. package/dist/credits/amount.js.map +1 -0
  64. package/dist/credits/catalog-runtime.d.ts +4 -6
  65. package/dist/credits/catalog-runtime.d.ts.map +1 -1
  66. package/dist/credits/catalog-runtime.js +3 -12
  67. package/dist/credits/catalog-runtime.js.map +1 -1
  68. package/dist/credits/lease-workflow.d.ts +1 -1
  69. package/dist/credits/lease-workflow.d.ts.map +1 -1
  70. package/dist/credits/lease-workflow.js +23 -20
  71. package/dist/credits/lease-workflow.js.map +1 -1
  72. package/dist/credits/low-balance-monitor.d.ts.map +1 -1
  73. package/dist/credits/low-balance-monitor.js +2 -3
  74. package/dist/credits/low-balance-monitor.js.map +1 -1
  75. package/dist/credits/postgres/repositories/balance.d.ts.map +1 -1
  76. package/dist/credits/postgres/repositories/balance.js.map +1 -1
  77. package/dist/credits/postgres/store.d.ts +15 -11
  78. package/dist/credits/postgres/store.d.ts.map +1 -1
  79. package/dist/credits/postgres/store.js +24 -15
  80. package/dist/credits/postgres/store.js.map +1 -1
  81. package/dist/credits/service-types.d.ts +17 -15
  82. package/dist/credits/service-types.d.ts.map +1 -1
  83. package/dist/credits/service-types.js.map +1 -1
  84. package/dist/credits/service.d.ts +16 -17
  85. package/dist/credits/service.d.ts.map +1 -1
  86. package/dist/credits/service.js +61 -33
  87. package/dist/credits/service.js.map +1 -1
  88. package/dist/credits/store.d.ts +16 -22
  89. package/dist/credits/store.d.ts.map +1 -1
  90. package/dist/credits/store.js +3 -1
  91. package/dist/credits/store.js.map +1 -1
  92. package/dist/credits/types/account.d.ts +1 -1
  93. package/dist/credits/types/account.d.ts.map +1 -1
  94. package/dist/credits/types/account.js.map +1 -1
  95. package/dist/credits/types/grants.d.ts.map +1 -1
  96. package/dist/credits/types/grants.js.map +1 -1
  97. package/dist/expr/ast.d.ts.map +1 -1
  98. package/dist/expr/ast.js.map +1 -1
  99. package/dist/expr/parser.d.ts +1 -0
  100. package/dist/expr/parser.d.ts.map +1 -1
  101. package/dist/expr/parser.js +15 -3
  102. package/dist/expr/parser.js.map +1 -1
  103. package/dist/generated/pricing-config.schema.json +31 -29
  104. package/dist/generated/pricing-config.types.d.ts +6 -18
  105. package/dist/generated/pricing-config.types.d.ts.map +1 -1
  106. package/dist/generated/pricing-config.types.js.map +1 -1
  107. package/dist/index.d.ts +4 -2
  108. package/dist/index.d.ts.map +1 -1
  109. package/dist/index.js +1 -0
  110. package/dist/index.js.map +1 -1
  111. package/dist/load-config-file.d.ts +2 -3
  112. package/dist/load-config-file.d.ts.map +1 -1
  113. package/dist/load-config-file.js +14 -29
  114. package/dist/load-config-file.js.map +1 -1
  115. package/dist/providers/_shared.js +1 -1
  116. package/dist/providers/_shared.js.map +1 -1
  117. package/dist/providers/dodo/client-contract.d.ts +3 -1
  118. package/dist/providers/dodo/client-contract.d.ts.map +1 -1
  119. package/dist/providers/dodo/client-contract.js.map +1 -1
  120. package/dist/providers/dodo/event-mapper.d.ts +1 -1
  121. package/dist/providers/dodo/event-mapper.d.ts.map +1 -1
  122. package/dist/providers/dodo/event-mapper.js +5 -13
  123. package/dist/providers/dodo/event-mapper.js.map +1 -1
  124. package/dist/providers/dodo/provider.d.ts +4 -6
  125. package/dist/providers/dodo/provider.d.ts.map +1 -1
  126. package/dist/providers/dodo/provider.js +22 -71
  127. package/dist/providers/dodo/provider.js.map +1 -1
  128. package/dist/providers/dodo/webhook-bridge.d.ts +1 -2
  129. package/dist/providers/dodo/webhook-bridge.d.ts.map +1 -1
  130. package/dist/providers/dodo/webhook-bridge.js +0 -1
  131. package/dist/providers/dodo/webhook-bridge.js.map +1 -1
  132. package/dist/providers/environment.d.ts +6 -0
  133. package/dist/providers/environment.d.ts.map +1 -0
  134. package/dist/providers/environment.js +10 -0
  135. package/dist/providers/environment.js.map +1 -0
  136. package/dist/providers/index.d.ts +3 -7
  137. package/dist/providers/index.d.ts.map +1 -1
  138. package/dist/providers/index.js +1 -5
  139. package/dist/providers/index.js.map +1 -1
  140. package/dist/providers/mock/provider.d.ts +6 -8
  141. package/dist/providers/mock/provider.d.ts.map +1 -1
  142. package/dist/providers/mock/provider.js +18 -50
  143. package/dist/providers/mock/provider.js.map +1 -1
  144. package/dist/providers/stripe/event-mapper.js +11 -11
  145. package/dist/providers/stripe/event-mapper.js.map +1 -1
  146. package/dist/providers/stripe/provider.d.ts +3 -3
  147. package/dist/providers/stripe/provider.d.ts.map +1 -1
  148. package/dist/providers/stripe/provider.js +37 -24
  149. package/dist/providers/stripe/provider.js.map +1 -1
  150. package/dist/providers/types.d.ts +9 -19
  151. package/dist/providers/types.d.ts.map +1 -1
  152. package/dist/providers/types.js.map +1 -1
  153. package/dist/shared/idempotency.d.ts +9 -0
  154. package/dist/shared/idempotency.d.ts.map +1 -0
  155. package/dist/shared/idempotency.js +34 -0
  156. package/dist/shared/idempotency.js.map +1 -0
  157. package/dist/shared/postgres-client.d.ts +4 -0
  158. package/dist/shared/postgres-client.d.ts.map +1 -1
  159. package/dist/shared/postgres-client.js +6 -2
  160. package/dist/shared/postgres-client.js.map +1 -1
  161. package/dist/shared/postgres-errors.d.ts.map +1 -1
  162. package/dist/shared/postgres-errors.js.map +1 -1
  163. package/dist/storage/outbox-worker.d.ts.map +1 -1
  164. package/dist/storage/outbox-worker.js +22 -21
  165. package/dist/storage/outbox-worker.js.map +1 -1
  166. package/dist/storage/postgres-repository.d.ts.map +1 -1
  167. package/dist/storage/postgres-repository.js +67 -46
  168. package/dist/storage/postgres-repository.js.map +1 -1
  169. package/dist/storage/runtime.d.ts +11 -7
  170. package/dist/storage/runtime.d.ts.map +1 -1
  171. package/dist/storage/runtime.js +52 -8
  172. package/dist/storage/runtime.js.map +1 -1
  173. package/package.json +52 -36
@@ -1,6 +1,8 @@
1
1
  import type { Decimal } from "decimal.js";
2
2
  import type { AddCreditsResult, AddTeamMemberResult, AggregateStats, AllowanceResult, AvailableResult, BalanceResult, BillingMode, BucketBalancesResult, CheckFeatureResult, CreateTeamResult, CreditMetadata, DailySpendRow, DeductionResult, DeductWithAllowanceOptions, ExecuteGrantProgramRequest, GrantProgramAwardResult, GetUserPlanResult, ListQuotaEventsOptions, PlanMigrationBatchResult, PlanMigrationStartResult, QuotaEvent, QuotaState, LeaseResult, LeasePricingContext, ListLedgerEntriesOptions, ListUsageChargesOptions, ListUsageEntriesOptions, LedgerPage, UsageChargePage, UsageRecordResult, CatalogRevisionSummary, CatalogRevision, RefundResult, RevokeCreditsResult, ReleaseResult, SetUserPlanResult, UnsetUserPlanResult, SpendByModelRow, SpendByUserRow, SweepResult, TeamBalanceResult, TeamDeductionResult, TeamMember, TeamRole, TopUserRow, LedgerEntry } from "./types/index.js";
3
- import type { CatalogRollout } from "../config.js";
3
+ import type { BursarConfigData, CatalogRollout } from "../config.js";
4
+ import type { ProviderEnvironment } from "../providers/environment.js";
5
+ import type { AddCreditsOptions, DeductTeamOptions, RefundCreditsOptions } from "./service-types.js";
4
6
  export interface OperationUsageOptions {
5
7
  /** Entitlement feature that must be enabled for the operation. */
6
8
  feature?: string | null;
@@ -15,7 +17,7 @@ export interface CreateLeaseOptions extends OperationUsageOptions {
15
17
  * Replay-safe acquisition key. Supplying the same key with the same request
16
18
  * returns the original lease; conflicting reuse is rejected.
17
19
  */
18
- idempotencyKey?: string | null;
20
+ idempotencyKey: string;
19
21
  billingMode?: BillingMode;
20
22
  floor?: Decimal;
21
23
  maxConcurrent?: number | null;
@@ -25,7 +27,7 @@ export interface CreateLeaseOptions extends OperationUsageOptions {
25
27
  }
26
28
  /** Options for charging the actual cost against a lease. */
27
29
  export interface SettleLeaseOptions extends OperationUsageOptions {
28
- idempotencyKey?: string | null;
30
+ idempotencyKey?: string;
29
31
  metadata?: CreditMetadata | null;
30
32
  }
31
33
  /**
@@ -41,23 +43,17 @@ export interface SettleLeaseOptions extends OperationUsageOptions {
41
43
  * throws {@link CapabilityNotSupportedError} instead of forcing a stub.
42
44
  */
43
45
  export declare abstract class CreditStore {
46
+ /** Optional provider namespace exposed by environment-aware stores. */
47
+ readonly providerEnvironment?: ProviderEnvironment;
44
48
  constructor();
45
49
  abstract getBalance(userId: string): Promise<BalanceResult>;
46
- abstract addCredits(userId: string, amount: Decimal, type?: string, metadata?: CreditMetadata | null, expiresAt?: Date | null,
47
- /** Target credit bucket; omitted/`null` resolves to the config's default bucket. */
48
- bucket?: string | null,
49
- /**
50
- * Replay-safe idempotency key (parity with the `deduct`/`settle`/`refund`
51
- * idempotency idiom). When a prior grant for this `userId` carries the same
52
- * key, the prior result is returned unchanged and no new credits are granted.
53
- */
54
- idempotencyKey?: string | null): Promise<AddCreditsResult>;
50
+ abstract addCredits(userId: string, amount: Decimal, options: AddCreditsOptions): Promise<AddCreditsResult>;
55
51
  /**
56
52
  * Atomically calculate-and-charge in one server-side transaction:
57
53
  * consume free allowance, enforce plan policy and quotas, and debit the net
58
54
  * amount, idempotency-keyed end-to-end.
59
55
  */
60
- abstract deductWithAllowance(userId: string, amount: Decimal, options?: DeductWithAllowanceOptions): Promise<DeductionResult>;
56
+ abstract deductWithAllowance(userId: string, amount: Decimal, options: DeductWithAllowanceOptions): Promise<DeductionResult>;
61
57
  /**
62
58
  * Atomically acquire a lease (hold) — the only authoritative admission control.
63
59
  *
@@ -69,7 +65,7 @@ export declare abstract class CreditStore {
69
65
  * an ``active`` lease expiring after ``ttlSeconds``. Business failures are
70
66
  * returned via ``LeaseResult.error``; the store never raises domain exceptions.
71
67
  */
72
- abstract createLease(userId: string, amount: Decimal, operationType: string, options?: CreateLeaseOptions): Promise<LeaseResult>;
68
+ abstract createLease(userId: string, amount: Decimal, operationType: string, options: CreateLeaseOptions): Promise<LeaseResult>;
73
69
  /**
74
70
  * Charge the actual cost against a lease, then mark it settled.
75
71
  *
@@ -105,11 +101,11 @@ export declare abstract class CreditStore {
105
101
  */
106
102
  abstract getAvailable(userId: string): Promise<AvailableResult>;
107
103
  abstract getActiveCatalog(): Promise<CatalogRevision | null>;
108
- abstract publishAndActivateCatalog(config: Record<string, unknown>, label?: string | null, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<string>;
109
- abstract publishCatalogDraft(config: Record<string, unknown>, label?: string | null): Promise<string>;
104
+ abstract publishAndActivateCatalog(config: BursarConfigData, label?: string | null, rollout?: CatalogRollout | null): Promise<string>;
105
+ abstract publishCatalogDraft(config: BursarConfigData, label?: string | null): Promise<string>;
110
106
  abstract getCatalogHistory(): Promise<CatalogRevisionSummary[]>;
111
107
  abstract getCatalogRevision(version: number): Promise<CatalogRevision | null>;
112
- abstract activateCatalogRevision(version: number, rollout?: CatalogRollout | Record<string, unknown> | null): Promise<string>;
108
+ abstract activateCatalogRevision(version: number, rollout?: CatalogRollout | null): Promise<string>;
113
109
  abstract getUserPlan(userId: string): Promise<GetUserPlanResult>;
114
110
  abstract setUserPlan(userId: string, planKey: string, planAssignedAt?: Date | null): Promise<SetUserPlanResult>;
115
111
  abstract unsetUserPlan(userId: string): Promise<UnsetUserPlanResult>;
@@ -122,9 +118,7 @@ export declare abstract class CreditStore {
122
118
  abstract listQuotaEvents(userId: string, options?: ListQuotaEventsOptions): Promise<QuotaEvent[]>;
123
119
  abstract checkAllowance(userId: string): Promise<AllowanceResult | null>;
124
120
  abstract revokeCreditsByEntryType(userId: string, entryType: string): Promise<RevokeCreditsResult>;
125
- abstract refundCredits(entryId: string, amount?: Decimal, reason?: string, metadata?: CreditMetadata | null,
126
- /** Replay-safe key; pass a unique key for multiple equal partial refunds. */
127
- idempotencyKey?: string | null): Promise<RefundResult>;
121
+ abstract refundCredits(entryId: string, options: RefundCreditsOptions): Promise<RefundResult>;
128
122
  /**
129
123
  * Sweep expired credit grants and debit the aggregate/tier balances.
130
124
  *
@@ -154,7 +148,7 @@ export declare abstract class CreditStore {
154
148
  /** Read metered usage charges, including allowance-covered events. */
155
149
  listUsageCharges(_userId: string, _options?: ListUsageChargesOptions): Promise<UsageChargePage>;
156
150
  /** Append priced usage telemetry without debiting the account again. */
157
- recordUsage(_userId: string, _operation: string, _requested: Decimal, _options?: DeductWithAllowanceOptions): Promise<UsageRecordResult>;
151
+ recordUsage(_userId: string, _operation: string, _requested: Decimal, _options: DeductWithAllowanceOptions): Promise<UsageRecordResult>;
158
152
  /**
159
153
  * Fetch a single transaction by ID. Returns `null` when the transaction
160
154
  * does not exist or belongs to a different user.
@@ -165,6 +159,6 @@ export declare abstract class CreditStore {
165
159
  addTeamMember(_teamId: string, _userId: string, _role?: TeamRole, _spendCap?: Decimal | null): Promise<AddTeamMemberResult>;
166
160
  getTeamMembers(_teamId: string): Promise<TeamMember[]>;
167
161
  removeTeamMember(_teamId: string, _userId: string): Promise<boolean>;
168
- deductTeam(_teamId: string, _userId: string, _amount: Decimal, _metadata?: CreditMetadata | null, _idempotencyKey?: string | null): Promise<TeamDeductionResult>;
162
+ deductTeam(_teamId: string, _userId: string, _amount: Decimal, _options: DeductTeamOptions): Promise<TeamDeductionResult>;
169
163
  }
170
164
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/credits/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,WAAW,qBAAqB;IACpC,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC7C;AAED,gDAAgD;AAChD,MAAM,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ACf,KAAK,CAAC,EAAE,QAAQ,EAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,GACzB,OAAO,CAAC,mBAAmB,CAAC;IAGzB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAGtD,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAGpE,UAAU,CACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,SAAS,CAAC,EAAE,cAAc,GAAG,IAAI,EACjC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,GAC9B,OAAO,CAAC,mBAAmB,CAAC;CAGhC"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/credits/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,eAAe,EACf,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,kBAAkB,EAClB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,eAAe,EACf,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,wBAAwB,EACxB,wBAAwB,EACxB,UAAU,EACV,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,wBAAwB,EACxB,uBAAuB,EACvB,uBAAuB,EACvB,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACZ,MAAM,kBAAkB,CA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tB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAGlE,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,QAAQ,EAChB,SAAS,CAAC,EAAE,OAAO,GAAG,IAAI,GACzB,OAAO,CAAC,mBAAmB,CAAC;IAGzB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAGtD,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAGpE,UAAU,CACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,iBAAiB,GAC1B,OAAO,CAAC,mBAAmB,CAAC;CAGhC"}
@@ -12,6 +12,8 @@ import { CapabilityNotSupportedError } from "../errors.js";
12
12
  * throws {@link CapabilityNotSupportedError} instead of forcing a stub.
13
13
  */
14
14
  export class CreditStore {
15
+ /** Optional provider namespace exposed by environment-aware stores. */
16
+ providerEnvironment;
15
17
  constructor() { }
16
18
  /** Expire a bounded batch of abandoned leases and release their reservations. */
17
19
  async expireLeases(_limit) {
@@ -73,7 +75,7 @@ export class CreditStore {
73
75
  async removeTeamMember(_teamId, _userId) {
74
76
  throw new CapabilityNotSupportedError("removeTeamMember is not supported by this store");
75
77
  }
76
- async deductTeam(_teamId, _userId, _amount, _metadata, _idempotencyKey) {
78
+ async deductTeam(_teamId, _userId, _amount, _options) {
77
79
  throw new CapabilityNotSupportedError("deductTeam is not supported by this store");
78
80
  }
79
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/credits/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAiF3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,WA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C,4CAA4C,CAAC,CAAC;IACtF,CAAC;IAED,wEAAwE;IACxE;;;OAGG;IACH,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,QAAgB;QACpD,MAAM,IAAI,2BAA2B,CAAC,+CAA+C,CAAC,CAAC;IACzF,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,UAAU,CACd,eAAuB,EACvB,KAAa,EACb,eAAyB;QAEzB,MAAM,IAAI,2BAA2B,CAAC,2CAA2C,CAAC,CAAC;IACrF,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,MAAM,IAAI,2BAA2B,CAAC,+CAA+C,CAAC,CAAC;IACzF,CAAC;IACD,KAAK,CAAC,aAAa,CACjB,OAAe,EACf,OAAe,EACf,KAAgB,EAChB,SAA0B;QAE1B,MAAM,IAAI,2BAA2B,CAAC,8CAA8C,CAAC,CAAC;IACxF,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,MAAM,IAAI,2BAA2B,CAAC,+CAA+C,CAAC,CAAC;IACzF,CAAC;IACD,KAAK,CAAC,gBAAgB,CAAC,OAAe,EAAE,OAAe;QACrD,MAAM,IAAI,2BAA2B,CAAC,iDAAiD,CAAC,CAAC;IAC3F,CAAC;IACD,KAAK,CAAC,UAAU,CACd,OAAe,EACf,OAAe,EACf,OAAgB,EAChB,SAAiC,EACjC,eAA+B;QAE/B,MAAM,IAAI,2BAA2B,CAAC,2CAA2C,CAAC,CAAC;IACrF,CAAC;CACF","sourcesContent":["import type { Decimal } from \"decimal.js\";\nimport { CapabilityNotSupportedError } from \"../errors.js\";\nimport type {\n AddCreditsResult,\n AddTeamMemberResult,\n AggregateStats,\n AllowanceResult,\n AvailableResult,\n BalanceResult,\n BillingMode,\n BucketBalancesResult,\n CheckFeatureResult,\n CreateTeamResult,\n CreditMetadata,\n DailySpendRow,\n DeductionResult,\n DeductWithAllowanceOptions,\n ExecuteGrantProgramRequest,\n GrantProgramAwardResult,\n GetUserPlanResult,\n ListQuotaEventsOptions,\n PlanMigrationBatchResult,\n PlanMigrationStartResult,\n QuotaEvent,\n QuotaState,\n LeaseResult,\n LeasePricingContext,\n ListLedgerEntriesOptions,\n ListUsageChargesOptions,\n ListUsageEntriesOptions,\n LedgerPage,\n UsageChargePage,\n UsageRecordResult,\n CatalogRevisionSummary,\n CatalogRevision,\n RefundResult,\n RevokeCreditsResult,\n ReleaseResult,\n SetUserPlanResult,\n UnsetUserPlanResult,\n SpendByModelRow,\n SpendByUserRow,\n SweepResult,\n TeamBalanceResult,\n TeamDeductionResult,\n TeamMember,\n TeamRole,\n TopUserRow,\n LedgerEntry,\n} from \"./types/index.js\";\nimport type { CatalogRollout } from \"../config.js\";\n\nexport interface OperationUsageOptions {\n /** Entitlement feature that must be enabled for the operation. */\n feature?: string | null;\n model?: string | null;\n region?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, unknown> | null;\n}\n\n/** Options for atomically acquiring a lease. */\nexport interface CreateLeaseOptions extends OperationUsageOptions {\n /**\n * Replay-safe acquisition key. Supplying the same key with the same request\n * returns the original lease; conflicting reuse is rejected.\n */\n idempotencyKey?: string | null;\n billingMode?: BillingMode;\n floor?: Decimal;\n maxConcurrent?: number | null;\n overdraftFloor?: Decimal | null;\n ttlSeconds?: number;\n metadata?: CreditMetadata | null;\n}\n\n/** Options for charging the actual cost against a lease. */\nexport interface SettleLeaseOptions extends OperationUsageOptions {\n idempotencyKey?: string | null;\n metadata?: CreditMetadata | null;\n}\n\n/**\n * Abstract base for credit storage backends.\n *\n * Split into two tiers:\n * - **Core** (abstract, must be implemented): balance/credit ops, the atomic\n * lease lifecycle, bursar-config versioning, plan management,\n * refunds, and expiry sweeping. Every backend needs these.\n * - **Optional capabilities** (concrete, default-throwing): usage analytics,\n * ledger listing, and shared team-balance pools. A custom store that\n * doesn't need these can skip them entirely — the default implementation\n * throws {@link CapabilityNotSupportedError} instead of forcing a stub.\n */\nexport abstract class CreditStore {\n constructor() {}\n\n abstract getBalance(userId: string): Promise<BalanceResult>;\n abstract addCredits(\n userId: string,\n amount: Decimal,\n type?: string,\n metadata?: CreditMetadata | null,\n expiresAt?: Date | null,\n /** Target credit bucket; omitted/`null` resolves to the config's default bucket. */\n bucket?: string | null,\n /**\n * Replay-safe idempotency key (parity with the `deduct`/`settle`/`refund`\n * idempotency idiom). When a prior grant for this `userId` carries the same\n * key, the prior result is returned unchanged and no new credits are granted.\n */\n idempotencyKey?: string | null,\n ): Promise<AddCreditsResult>;\n /**\n * Atomically calculate-and-charge in one server-side transaction:\n * consume free allowance, enforce plan policy and quotas, and debit the net\n * amount, idempotency-keyed end-to-end.\n */\n abstract deductWithAllowance(\n userId: string,\n amount: Decimal,\n options?: DeductWithAllowanceOptions,\n ): Promise<DeductionResult>;\n\n // ── Lease lifecycle (atomic admission) ─────────────────────────────\n //\n // The lease is the canonical admission primitive.\n // ``reserve``/``settle``/``release`` on the manager map onto these.\n // Leases reuse the credit_reservations table/records extended with a status\n // (active → settled | released | expired), a billing mode, and an overdraft\n // floor. ``available = balance − Σ(amount WHERE status='active' AND unexpired)``.\n\n /**\n * Atomically acquire a lease (hold) — the only authoritative admission control.\n *\n * Under one critical section the store: (1) ensures the balance row exists;\n * (2) enforces ``maxConcurrent`` by counting active leases for ``(userId,\n * operationType)``; (3) enforces plan entitlements and quotas; (4) computes\n * ``available = balance − Σ active holds`` and rejects with\n * ``error=\"insufficient_credits\"`` if ``available − amount < floor``; (5) inserts\n * an ``active`` lease expiring after ``ttlSeconds``. Business failures are\n * returned via ``LeaseResult.error``; the store never raises domain exceptions.\n */\n abstract createLease(\n userId: string,\n amount: Decimal,\n operationType: string,\n options?: CreateLeaseOptions,\n ): Promise<LeaseResult>;\n\n /**\n * Charge the actual cost against a lease, then mark it settled.\n *\n * De-clamped: charges ``amount`` even if it exceeds the lease hold (overdraft)\n * and never clamps to the reserved ceiling. The balance may go negative in\n * overdraft. ``amount === 0`` releases the lease without charging.\n * Lease-state failures (``lease_not_found``/``lease_expired``) are returned via\n * ``DeductionResult.error``; a replay returns the original result idempotently.\n */\n abstract settleLease(\n userId: string,\n leaseId: string,\n amount: Decimal,\n options?: SettleLeaseOptions,\n ): Promise<DeductionResult>;\n\n /** Read the immutable catalog and rate card captured at lease admission. */\n abstract getLeasePricingContext(\n userId: string,\n leaseId: string,\n ): Promise<LeasePricingContext | null>;\n\n /**\n * Release a lease without charging; safe to repeat after failed or aborted work.\n *\n * Transitions an ``active``/``expired`` lease to ``released`` and reports\n * ``released=true``; otherwise reports ``released=false`` with a ``reason``.\n */\n abstract releaseLease(userId: string, leaseId: string): Promise<ReleaseResult>;\n\n /**\n * Extend an active lease's TTL (long batch/agentic jobs, resolves B4).\n *\n * Returns ``error=\"lease_expired\"`` if the TTL already elapsed and\n * ``error=\"lease_not_found\"`` if missing/other-user/finalized.\n */\n abstract renewLease(userId: string, leaseId: string, ttlSeconds: number): Promise<LeaseResult>;\n\n /** Expire a bounded batch of abandoned leases and release their reservations. */\n async expireLeases(_limit?: number): Promise<number> {\n throw new CapabilityNotSupportedError(\"expireLeases is not supported by this store\");\n }\n\n /**\n * Advisory, non-locking read of ``available = balance − Σ active holds``.\n *\n * For UI only — never an admission gate; may be stale the instant it is read.\n */\n\n abstract getAvailable(userId: string): Promise<AvailableResult>;\n\n abstract getActiveCatalog(): Promise<CatalogRevision | null>;\n abstract publishAndActivateCatalog(\n config: Record<string, unknown>,\n label?: string | null,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<string>;\n abstract publishCatalogDraft(\n config: Record<string, unknown>,\n label?: string | null,\n ): Promise<string>;\n\n // Catalog revision history and activation.\n abstract getCatalogHistory(): Promise<CatalogRevisionSummary[]>;\n abstract getCatalogRevision(version: number): Promise<CatalogRevision | null>;\n abstract activateCatalogRevision(\n version: number,\n rollout?: CatalogRollout | Record<string, unknown> | null,\n ): Promise<string>;\n\n abstract getUserPlan(userId: string): Promise<GetUserPlanResult>;\n abstract setUserPlan(\n userId: string,\n planKey: string,\n planAssignedAt?: Date | null,\n ): Promise<SetUserPlanResult>;\n abstract unsetUserPlan(userId: string): Promise<UnsetUserPlanResult>;\n abstract setPlanRevisionPin(userId: string, pinned: boolean): Promise<boolean>;\n abstract applyDuePlanChanges(limit?: number): Promise<number>;\n abstract startPlanMigration(\n fromPlanId: string | null,\n toPlanId: string,\n ): Promise<PlanMigrationStartResult>;\n abstract migratePlanBatch(\n migrationId: string,\n batchSize?: number,\n ): Promise<PlanMigrationBatchResult>;\n abstract checkFeature(userId: string, feature: string): Promise<CheckFeatureResult>;\n abstract getQuotaState(userId: string, quotaKey?: string | null): Promise<QuotaState[]>;\n abstract listQuotaEvents(userId: string, options?: ListQuotaEventsOptions): Promise<QuotaEvent[]>;\n abstract checkAllowance(userId: string): Promise<AllowanceResult | null>;\n\n abstract revokeCreditsByEntryType(\n userId: string,\n entryType: string,\n ): Promise<RevokeCreditsResult>;\n\n // ── Refunds ────────────────────────────────────────────────────────\n abstract refundCredits(\n entryId: string,\n amount?: Decimal,\n reason?: string,\n metadata?: CreditMetadata | null,\n /** Replay-safe key; pass a unique key for multiple equal partial refunds. */\n idempotencyKey?: string | null,\n ): Promise<RefundResult>;\n\n // ── Credit expiry ────────────────────────────────────────────────────\n /**\n * Sweep expired credit grants and debit the aggregate/tier balances.\n *\n * When `userId` is omitted (default), sweeps globally across every user —\n * unchanged behaviour/output shape from before this parameter existed. When\n * given, restricts the scan/expiry to that user's transactions only (used by\n * bounded expiry sweep operation).\n */\n abstract sweepExpiredCredits(\n dryRun?: boolean,\n userId?: string,\n limit?: number,\n ): Promise<SweepResult>;\n\n // ── Credit buckets ─────────────────────────────────────────────────────\n /**\n * Per-bucket credit balances for a user (credit buckets).\n *\n * Sorted by `priority` ascending. When no buckets are configured, synthesizes\n * a single `\"default\"` entry from the aggregate balance so the shape is\n * uniform either way.\n */\n abstract getBucketBalances(userId: string): Promise<BucketBalancesResult>;\n\n /** Execute one configured grant-program event. */\n async executeGrantProgram(\n _request: ExecuteGrantProgramRequest,\n ): Promise<GrantProgramAwardResult[]> {\n throw new CapabilityNotSupportedError(\"executeGrantProgram is not supported by this store\");\n }\n\n // ── Usage analytics (optional capability) ────────────────────────────\n async spendByUser(_start: Date, _end: Date): Promise<SpendByUserRow[]> {\n throw new CapabilityNotSupportedError(\"spendByUser is not supported by this store\");\n }\n async spendByModel(_start: Date, _end: Date): Promise<SpendByModelRow[]> {\n throw new CapabilityNotSupportedError(\"spendByModel is not supported by this store\");\n }\n async topUsers(_limit: number, _start: Date, _end: Date): Promise<TopUserRow[]> {\n throw new CapabilityNotSupportedError(\"topUsers is not supported by this store\");\n }\n async dailySpend(_start: Date, _end: Date): Promise<DailySpendRow[]> {\n throw new CapabilityNotSupportedError(\"dailySpend is not supported by this store\");\n }\n async aggregateStats(_start: Date, _end: Date): Promise<AggregateStats> {\n throw new CapabilityNotSupportedError(\"aggregateStats is not supported by this store\");\n }\n\n // ── Transaction listing (optional capability) ────────────────────────\n async listLedgerEntries(\n _userId: string,\n _options?: ListLedgerEntriesOptions,\n ): Promise<LedgerPage> {\n throw new CapabilityNotSupportedError(\"listLedgerEntries is not supported by this store\");\n }\n abstract listUsageEntries(userId: string, options?: ListUsageEntriesOptions): Promise<LedgerPage>;\n\n /** Read metered usage charges, including allowance-covered events. */\n async listUsageCharges(\n _userId: string,\n _options?: ListUsageChargesOptions,\n ): Promise<UsageChargePage> {\n throw new CapabilityNotSupportedError(\"listUsageCharges is not supported by this store\");\n }\n\n /** Append priced usage telemetry without debiting the account again. */\n async recordUsage(\n _userId: string,\n _operation: string,\n _requested: Decimal,\n _options?: DeductWithAllowanceOptions,\n ): Promise<UsageRecordResult> {\n throw new CapabilityNotSupportedError(\"recordUsage is not supported by this store\");\n }\n\n // ── Single transaction lookup (optional capability) ──────────────────\n /**\n * Fetch a single transaction by ID. Returns `null` when the transaction\n * does not exist or belongs to a different user.\n */\n async getLedgerEntry(_userId: string, _entryId: string): Promise<LedgerEntry | null> {\n throw new CapabilityNotSupportedError(\"getLedgerEntry is not supported by this store\");\n }\n\n // ── Team/shared balance pools (optional capability) ──────────────────\n async createTeam(\n _ownerSubjectId: string,\n _name: string,\n _initialBalance?: Decimal,\n ): Promise<CreateTeamResult> {\n throw new CapabilityNotSupportedError(\"createTeam is not supported by this store\");\n }\n async getTeamBalance(_teamId: string): Promise<TeamBalanceResult | null> {\n throw new CapabilityNotSupportedError(\"getTeamBalance is not supported by this store\");\n }\n async addTeamMember(\n _teamId: string,\n _userId: string,\n _role?: TeamRole,\n _spendCap?: Decimal | null,\n ): Promise<AddTeamMemberResult> {\n throw new CapabilityNotSupportedError(\"addTeamMember is not supported by this store\");\n }\n async getTeamMembers(_teamId: string): Promise<TeamMember[]> {\n throw new CapabilityNotSupportedError(\"getTeamMembers is not supported by this store\");\n }\n async removeTeamMember(_teamId: string, _userId: string): Promise<boolean> {\n throw new CapabilityNotSupportedError(\"removeTeamMember is not supported by this store\");\n }\n async deductTeam(\n _teamId: string,\n _userId: string,\n _amount: Decimal,\n _metadata?: CreditMetadata | null,\n _idempotencyKey?: string | null,\n ): Promise<TeamDeductionResult> {\n throw new CapabilityNotSupportedError(\"deductTeam is not supported by this store\");\n }\n}\n"]}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/credits/store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAuF3D;;;;;;;;;;;GAWG;AACH,MAAM,OAAgB,WAAW;IAC/B,uEAAuE;IAC9D,mBAAmB,CAAuB;IACnD,gBAAe,CAAC;IAmFhB,iFAAiF;IACjF,KAAK,CAAC,YAAY,CAAC,MAAe;QAChC,MAAM,IAAI,2BAA2B,CAAC,6CAA6C,CAAC,CAAC;IACvF,CAAC;IAiFD,kDAAkD;IAClD,KAAK,CAAC,mBAAmB,CACvB,QAAoC;QAEpC,MAAM,IAAI,2BAA2B,CAAC,oDAAoD,CAAC,CAAC;IAC9F,CAAC;IAED,wEAAwE;IACxE,KAAK,CAAC,WAAW,CAAC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rF,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,MAAM,IAAI,2BAA2B,CAAC,+CAA+C,CAAC,CAAC;IACzF,CAAC;IACD,KAAK,CAAC,aAAa,CACjB,OAAe,EACf,OAAe,EACf,KAAgB,EAChB,SAA0B;QAE1B,MAAM,IAAI,2BAA2B,CAAC,8CAA8C,CAAC,CAAC;IACxF,CAAC;IACD,KAAK,CAAC,cAAc,CAAC,OAAe;QAClC,MAAM,IAAI,2BAA2B,CAAC,+CAA+C,CAAC,CAAC;IACzF,CAAC;IACD,KAAK,CAAC,gBAAgB,CAAC,OAAe,EAAE,OAAe;QACrD,MAAM,IAAI,2BAA2B,CAAC,iDAAiD,CAAC,CAAC;IAC3F,CAAC;IACD,KAAK,CAAC,UAAU,CACd,OAAe,EACf,OAAe,EACf,OAAgB,EAChB,QAA2B;QAE3B,MAAM,IAAI,2BAA2B,CAAC,2CAA2C,CAAC,CAAC;IACrF,CAAC;CACF","sourcesContent":["import type { Decimal } from \"decimal.js\";\nimport { CapabilityNotSupportedError } from \"../errors.js\";\nimport type {\n AddCreditsResult,\n AddTeamMemberResult,\n AggregateStats,\n AllowanceResult,\n AvailableResult,\n BalanceResult,\n BillingMode,\n BucketBalancesResult,\n CheckFeatureResult,\n CreateTeamResult,\n CreditMetadata,\n DailySpendRow,\n DeductionResult,\n DeductWithAllowanceOptions,\n ExecuteGrantProgramRequest,\n GrantProgramAwardResult,\n GetUserPlanResult,\n ListQuotaEventsOptions,\n PlanMigrationBatchResult,\n PlanMigrationStartResult,\n QuotaEvent,\n QuotaState,\n LeaseResult,\n LeasePricingContext,\n ListLedgerEntriesOptions,\n ListUsageChargesOptions,\n ListUsageEntriesOptions,\n LedgerPage,\n UsageChargePage,\n UsageRecordResult,\n CatalogRevisionSummary,\n CatalogRevision,\n RefundResult,\n RevokeCreditsResult,\n ReleaseResult,\n SetUserPlanResult,\n UnsetUserPlanResult,\n SpendByModelRow,\n SpendByUserRow,\n SweepResult,\n TeamBalanceResult,\n TeamDeductionResult,\n TeamMember,\n TeamRole,\n TopUserRow,\n LedgerEntry,\n} from \"./types/index.js\";\nimport type { BursarConfigData, CatalogRollout } from \"../config.js\";\nimport type { ProviderEnvironment } from \"../providers/environment.js\";\nimport type {\n AddCreditsOptions,\n DeductTeamOptions,\n RefundCreditsOptions,\n} from \"./service-types.js\";\n\nexport interface OperationUsageOptions {\n /** Entitlement feature that must be enabled for the operation. */\n feature?: string | null;\n model?: string | null;\n region?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, unknown> | null;\n}\n\n/** Options for atomically acquiring a lease. */\nexport interface CreateLeaseOptions extends OperationUsageOptions {\n /**\n * Replay-safe acquisition key. Supplying the same key with the same request\n * returns the original lease; conflicting reuse is rejected.\n */\n idempotencyKey: string;\n billingMode?: BillingMode;\n floor?: Decimal;\n maxConcurrent?: number | null;\n overdraftFloor?: Decimal | null;\n ttlSeconds?: number;\n metadata?: CreditMetadata | null;\n}\n\n/** Options for charging the actual cost against a lease. */\nexport interface SettleLeaseOptions extends OperationUsageOptions {\n idempotencyKey?: string;\n metadata?: CreditMetadata | null;\n}\n\n/**\n * Abstract base for credit storage backends.\n *\n * Split into two tiers:\n * - **Core** (abstract, must be implemented): balance/credit ops, the atomic\n * lease lifecycle, bursar-config versioning, plan management,\n * refunds, and expiry sweeping. Every backend needs these.\n * - **Optional capabilities** (concrete, default-throwing): usage analytics,\n * ledger listing, and shared team-balance pools. A custom store that\n * doesn't need these can skip them entirely — the default implementation\n * throws {@link CapabilityNotSupportedError} instead of forcing a stub.\n */\nexport abstract class CreditStore {\n /** Optional provider namespace exposed by environment-aware stores. */\n readonly providerEnvironment?: ProviderEnvironment;\n constructor() {}\n\n abstract getBalance(userId: string): Promise<BalanceResult>;\n abstract addCredits(\n userId: string,\n amount: Decimal,\n options: AddCreditsOptions,\n ): Promise<AddCreditsResult>;\n /**\n * Atomically calculate-and-charge in one server-side transaction:\n * consume free allowance, enforce plan policy and quotas, and debit the net\n * amount, idempotency-keyed end-to-end.\n */\n abstract deductWithAllowance(\n userId: string,\n amount: Decimal,\n options: DeductWithAllowanceOptions,\n ): Promise<DeductionResult>;\n\n // ── Lease lifecycle (atomic admission) ─────────────────────────────\n //\n // The lease is the canonical admission primitive.\n // ``reserve``/``settle``/``release`` on the manager map onto these.\n // Leases reuse the credit_reservations table/records extended with a status\n // (active → settled | released | expired), a billing mode, and an overdraft\n // floor. ``available = balance − Σ(amount WHERE status='active' AND unexpired)``.\n\n /**\n * Atomically acquire a lease (hold) — the only authoritative admission control.\n *\n * Under one critical section the store: (1) ensures the balance row exists;\n * (2) enforces ``maxConcurrent`` by counting active leases for ``(userId,\n * operationType)``; (3) enforces plan entitlements and quotas; (4) computes\n * ``available = balance − Σ active holds`` and rejects with\n * ``error=\"insufficient_credits\"`` if ``available − amount < floor``; (5) inserts\n * an ``active`` lease expiring after ``ttlSeconds``. Business failures are\n * returned via ``LeaseResult.error``; the store never raises domain exceptions.\n */\n abstract createLease(\n userId: string,\n amount: Decimal,\n operationType: string,\n options: CreateLeaseOptions,\n ): Promise<LeaseResult>;\n\n /**\n * Charge the actual cost against a lease, then mark it settled.\n *\n * De-clamped: charges ``amount`` even if it exceeds the lease hold (overdraft)\n * and never clamps to the reserved ceiling. The balance may go negative in\n * overdraft. ``amount === 0`` releases the lease without charging.\n * Lease-state failures (``lease_not_found``/``lease_expired``) are returned via\n * ``DeductionResult.error``; a replay returns the original result idempotently.\n */\n abstract settleLease(\n userId: string,\n leaseId: string,\n amount: Decimal,\n options?: SettleLeaseOptions,\n ): Promise<DeductionResult>;\n\n /** Read the immutable catalog and rate card captured at lease admission. */\n abstract getLeasePricingContext(\n userId: string,\n leaseId: string,\n ): Promise<LeasePricingContext | null>;\n\n /**\n * Release a lease without charging; safe to repeat after failed or aborted work.\n *\n * Transitions an ``active``/``expired`` lease to ``released`` and reports\n * ``released=true``; otherwise reports ``released=false`` with a ``reason``.\n */\n abstract releaseLease(userId: string, leaseId: string): Promise<ReleaseResult>;\n\n /**\n * Extend an active lease's TTL (long batch/agentic jobs, resolves B4).\n *\n * Returns ``error=\"lease_expired\"`` if the TTL already elapsed and\n * ``error=\"lease_not_found\"`` if missing/other-user/finalized.\n */\n abstract renewLease(userId: string, leaseId: string, ttlSeconds: number): Promise<LeaseResult>;\n\n /** Expire a bounded batch of abandoned leases and release their reservations. */\n async expireLeases(_limit?: number): Promise<number> {\n throw new CapabilityNotSupportedError(\"expireLeases is not supported by this store\");\n }\n\n /**\n * Advisory, non-locking read of ``available = balance − Σ active holds``.\n *\n * For UI only — never an admission gate; may be stale the instant it is read.\n */\n\n abstract getAvailable(userId: string): Promise<AvailableResult>;\n\n abstract getActiveCatalog(): Promise<CatalogRevision | null>;\n abstract publishAndActivateCatalog(\n config: BursarConfigData,\n label?: string | null,\n rollout?: CatalogRollout | null,\n ): Promise<string>;\n abstract publishCatalogDraft(config: BursarConfigData, label?: string | null): Promise<string>;\n\n // Catalog revision history and activation.\n abstract getCatalogHistory(): Promise<CatalogRevisionSummary[]>;\n abstract getCatalogRevision(version: number): Promise<CatalogRevision | null>;\n abstract activateCatalogRevision(\n version: number,\n rollout?: CatalogRollout | null,\n ): Promise<string>;\n\n abstract getUserPlan(userId: string): Promise<GetUserPlanResult>;\n abstract setUserPlan(\n userId: string,\n planKey: string,\n planAssignedAt?: Date | null,\n ): Promise<SetUserPlanResult>;\n abstract unsetUserPlan(userId: string): Promise<UnsetUserPlanResult>;\n abstract setPlanRevisionPin(userId: string, pinned: boolean): Promise<boolean>;\n abstract applyDuePlanChanges(limit?: number): Promise<number>;\n abstract startPlanMigration(\n fromPlanId: string | null,\n toPlanId: string,\n ): Promise<PlanMigrationStartResult>;\n abstract migratePlanBatch(\n migrationId: string,\n batchSize?: number,\n ): Promise<PlanMigrationBatchResult>;\n abstract checkFeature(userId: string, feature: string): Promise<CheckFeatureResult>;\n abstract getQuotaState(userId: string, quotaKey?: string | null): Promise<QuotaState[]>;\n abstract listQuotaEvents(userId: string, options?: ListQuotaEventsOptions): Promise<QuotaEvent[]>;\n abstract checkAllowance(userId: string): Promise<AllowanceResult | null>;\n\n abstract revokeCreditsByEntryType(\n userId: string,\n entryType: string,\n ): Promise<RevokeCreditsResult>;\n\n // ── Refunds ────────────────────────────────────────────────────────\n abstract refundCredits(entryId: string, options: RefundCreditsOptions): Promise<RefundResult>;\n\n // ── Credit expiry ────────────────────────────────────────────────────\n /**\n * Sweep expired credit grants and debit the aggregate/tier balances.\n *\n * When `userId` is omitted (default), sweeps globally across every user —\n * unchanged behaviour/output shape from before this parameter existed. When\n * given, restricts the scan/expiry to that user's transactions only (used by\n * bounded expiry sweep operation).\n */\n abstract sweepExpiredCredits(\n dryRun?: boolean,\n userId?: string,\n limit?: number,\n ): Promise<SweepResult>;\n\n // ── Credit buckets ─────────────────────────────────────────────────────\n /**\n * Per-bucket credit balances for a user (credit buckets).\n *\n * Sorted by `priority` ascending. When no buckets are configured, synthesizes\n * a single `\"default\"` entry from the aggregate balance so the shape is\n * uniform either way.\n */\n abstract getBucketBalances(userId: string): Promise<BucketBalancesResult>;\n\n /** Execute one configured grant-program event. */\n async executeGrantProgram(\n _request: ExecuteGrantProgramRequest,\n ): Promise<GrantProgramAwardResult[]> {\n throw new CapabilityNotSupportedError(\"executeGrantProgram is not supported by this store\");\n }\n\n // ── Usage analytics (optional capability) ────────────────────────────\n async spendByUser(_start: Date, _end: Date): Promise<SpendByUserRow[]> {\n throw new CapabilityNotSupportedError(\"spendByUser is not supported by this store\");\n }\n async spendByModel(_start: Date, _end: Date): Promise<SpendByModelRow[]> {\n throw new CapabilityNotSupportedError(\"spendByModel is not supported by this store\");\n }\n async topUsers(_limit: number, _start: Date, _end: Date): Promise<TopUserRow[]> {\n throw new CapabilityNotSupportedError(\"topUsers is not supported by this store\");\n }\n async dailySpend(_start: Date, _end: Date): Promise<DailySpendRow[]> {\n throw new CapabilityNotSupportedError(\"dailySpend is not supported by this store\");\n }\n async aggregateStats(_start: Date, _end: Date): Promise<AggregateStats> {\n throw new CapabilityNotSupportedError(\"aggregateStats is not supported by this store\");\n }\n\n // ── Transaction listing (optional capability) ────────────────────────\n async listLedgerEntries(\n _userId: string,\n _options?: ListLedgerEntriesOptions,\n ): Promise<LedgerPage> {\n throw new CapabilityNotSupportedError(\"listLedgerEntries is not supported by this store\");\n }\n abstract listUsageEntries(userId: string, options?: ListUsageEntriesOptions): Promise<LedgerPage>;\n\n /** Read metered usage charges, including allowance-covered events. */\n async listUsageCharges(\n _userId: string,\n _options?: ListUsageChargesOptions,\n ): Promise<UsageChargePage> {\n throw new CapabilityNotSupportedError(\"listUsageCharges is not supported by this store\");\n }\n\n /** Append priced usage telemetry without debiting the account again. */\n async recordUsage(\n _userId: string,\n _operation: string,\n _requested: Decimal,\n _options: DeductWithAllowanceOptions,\n ): Promise<UsageRecordResult> {\n throw new CapabilityNotSupportedError(\"recordUsage is not supported by this store\");\n }\n\n // ── Single transaction lookup (optional capability) ──────────────────\n /**\n * Fetch a single transaction by ID. Returns `null` when the transaction\n * does not exist or belongs to a different user.\n */\n async getLedgerEntry(_userId: string, _entryId: string): Promise<LedgerEntry | null> {\n throw new CapabilityNotSupportedError(\"getLedgerEntry is not supported by this store\");\n }\n\n // ── Team/shared balance pools (optional capability) ──────────────────\n async createTeam(\n _ownerSubjectId: string,\n _name: string,\n _initialBalance?: Decimal,\n ): Promise<CreateTeamResult> {\n throw new CapabilityNotSupportedError(\"createTeam is not supported by this store\");\n }\n async getTeamBalance(_teamId: string): Promise<TeamBalanceResult | null> {\n throw new CapabilityNotSupportedError(\"getTeamBalance is not supported by this store\");\n }\n async addTeamMember(\n _teamId: string,\n _userId: string,\n _role?: TeamRole,\n _spendCap?: Decimal | null,\n ): Promise<AddTeamMemberResult> {\n throw new CapabilityNotSupportedError(\"addTeamMember is not supported by this store\");\n }\n async getTeamMembers(_teamId: string): Promise<TeamMember[]> {\n throw new CapabilityNotSupportedError(\"getTeamMembers is not supported by this store\");\n }\n async removeTeamMember(_teamId: string, _userId: string): Promise<boolean> {\n throw new CapabilityNotSupportedError(\"removeTeamMember is not supported by this store\");\n }\n async deductTeam(\n _teamId: string,\n _userId: string,\n _amount: Decimal,\n _options: DeductTeamOptions,\n ): Promise<TeamDeductionResult> {\n throw new CapabilityNotSupportedError(\"deductTeam is not supported by this store\");\n }\n}\n"]}
@@ -74,7 +74,7 @@ export interface DeductionFailure extends DeductionResultBase {
74
74
  }
75
75
  export type DeductionResult = DeductionSuccess | DeductionFailure;
76
76
  export interface DeductWithAllowanceOptions {
77
- idempotencyKey?: string | null;
77
+ idempotencyKey: string;
78
78
  operation?: string | null;
79
79
  feature?: string | null;
80
80
  model?: string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/credits/types/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEjD,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAC9E,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAA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C;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IAC5C,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC;AAED,UAAU,gBAAgB;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB;AAED,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,KAAK,EAAE,IAAI,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,IAAI,CAAC;IACpB,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;IAC3B,eAAe,EAAE,IAAI,CAAC;CACvB;AAED,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,aAAa,CAAC;AAEzD,+EAA+E;AAC/E,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,WAAW;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,MAAM,EAAE,OAAO,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C"}
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/credits/types/account.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nexport type BillingMode = \"strict\" | \"overdraft\";\n\nexport interface CreditMetadata {\n operation?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, string | number | boolean | Decimal.Value> | null;\n breakdownTotal?: string | null;\n referenceType?: string | null;\n referenceId?: string | null;\n idempotencyKey?: string | null;\n providerRequestId?: string | null;\n traceId?: string | null;\n spanId?: string | null;\n [key: string]: unknown;\n}\n\nexport interface BucketDefinition {\n label: string;\n priority: number;\n expires: boolean;\n ttlDays?: number | null;\n allowOverdraft?: boolean;\n default?: boolean;\n}\n\nexport interface BucketBalance {\n bucketKey: string;\n label: string;\n priority: number;\n expires: boolean;\n balance: Decimal;\n}\n\nexport interface BucketBalancesResult {\n userId: string;\n buckets: BucketBalance[];\n totalBalance: Decimal;\n}\n\nexport interface BalanceResult {\n userId: string;\n balance: Decimal;\n lifetimePurchased: Decimal;\n}\n\nexport interface AddCreditsResult {\n entryId: string;\n userId: string;\n amount: Decimal;\n newBalance: Decimal;\n lifetimePurchased: Decimal;\n /** Destination bucket for grants; `null` when a debit spans one or more lots. */\n bucket: string | null;\n idempotent: boolean;\n}\n\ninterface DeductionResultBase {\n userId: string;\n amount: Decimal;\n allowanceConsumed: Decimal;\n idempotent: boolean;\n}\n\n/** A committed usage charge. Allowance-only charges legitimately have no ledger entry. */\nexport interface DeductionSuccess extends DeductionResultBase {\n error: null;\n entryId: string | null;\n /** Canonical usage receipt, including zero-cost or allowance-only charges. */\n usageChargeId: string | null;\n balanceAfter: Decimal;\n bucketBreakdown: Record<string, Decimal> | null;\n}\n\n/** An expected database rejection. Nullable fields were not committed and are not fabricated. */\nexport interface DeductionFailure extends DeductionResultBase {\n error: string;\n entryId: null;\n usageChargeId: string | null;\n balanceAfter: Decimal | null;\n idempotent: false;\n bucketBreakdown: null;\n}\n\nexport type DeductionResult = DeductionSuccess | DeductionFailure;\n\nexport interface DeductWithAllowanceOptions {\n idempotencyKey?: string | null;\n operation?: string | null;\n feature?: string | null;\n model?: string | null;\n region?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, unknown> | null;\n metadata?: CreditMetadata | null;\n}\n\ninterface RefundResultBase {\n originalEntryId: string;\n userId: string | null;\n}\n\nexport interface RefundSuccess extends RefundResultBase {\n error: null;\n refundEntryId: string;\n userId: string;\n amount: Decimal;\n newBalance: Decimal;\n bucketBreakdown: Record<string, Decimal> | null;\n}\n\nexport interface RefundFailure extends RefundResultBase {\n error: string;\n refundEntryId: null;\n amount: Decimal | null;\n newBalance: Decimal | null;\n bucketBreakdown: null;\n}\n\nexport type RefundResult = RefundSuccess | RefundFailure;\n\n/** Credits removed from all remaining lots created by one ledger operation. */\nexport interface RevokeCreditsResult {\n userId: string;\n entryType: string;\n revoked: Decimal;\n balanceAfter: Decimal;\n}\n\nexport interface SweepResult {\n expiredCount: number;\n expiredAmount: Decimal;\n dryRun: boolean;\n expiredByBucket: Record<string, Decimal>;\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/credits/types/account.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\n\nexport type BillingMode = \"strict\" | \"overdraft\";\n\nexport interface CreditMetadata {\n operation?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, string | number | boolean | Decimal.Value> | null;\n breakdownTotal?: string | null;\n referenceType?: string | null;\n referenceId?: string | null;\n idempotencyKey?: string | null;\n providerRequestId?: string | null;\n traceId?: string | null;\n spanId?: string | null;\n [key: string]: unknown;\n}\n\nexport interface BucketDefinition {\n label: string;\n priority: number;\n expires: boolean;\n ttlDays?: number | null;\n allowOverdraft?: boolean;\n default?: boolean;\n}\n\nexport interface BucketBalance {\n bucketKey: string;\n label: string;\n priority: number;\n expires: boolean;\n balance: Decimal;\n}\n\nexport interface BucketBalancesResult {\n userId: string;\n buckets: BucketBalance[];\n totalBalance: Decimal;\n}\n\nexport interface BalanceResult {\n userId: string;\n balance: Decimal;\n lifetimePurchased: Decimal;\n}\n\nexport interface AddCreditsResult {\n entryId: string;\n userId: string;\n amount: Decimal;\n newBalance: Decimal;\n lifetimePurchased: Decimal;\n /** Destination bucket for grants; `null` when a debit spans one or more lots. */\n bucket: string | null;\n idempotent: boolean;\n}\n\ninterface DeductionResultBase {\n userId: string;\n amount: Decimal;\n allowanceConsumed: Decimal;\n idempotent: boolean;\n}\n\n/** A committed usage charge. Allowance-only charges legitimately have no ledger entry. */\nexport interface DeductionSuccess extends DeductionResultBase {\n error: null;\n entryId: string | null;\n /** Canonical usage receipt, including zero-cost or allowance-only charges. */\n usageChargeId: string | null;\n balanceAfter: Decimal;\n bucketBreakdown: Record<string, Decimal> | null;\n}\n\n/** An expected database rejection. Nullable fields were not committed and are not fabricated. */\nexport interface DeductionFailure extends DeductionResultBase {\n error: string;\n entryId: null;\n usageChargeId: string | null;\n balanceAfter: Decimal | null;\n idempotent: false;\n bucketBreakdown: null;\n}\n\nexport type DeductionResult = DeductionSuccess | DeductionFailure;\n\nexport interface DeductWithAllowanceOptions {\n idempotencyKey: string;\n operation?: string | null;\n feature?: string | null;\n model?: string | null;\n region?: string | null;\n measures?: Record<string, unknown> | null;\n dimensions?: Record<string, unknown> | null;\n metadata?: CreditMetadata | null;\n}\n\ninterface RefundResultBase {\n originalEntryId: string;\n userId: string | null;\n}\n\nexport interface RefundSuccess extends RefundResultBase {\n error: null;\n refundEntryId: string;\n userId: string;\n amount: Decimal;\n newBalance: Decimal;\n bucketBreakdown: Record<string, Decimal> | null;\n}\n\nexport interface RefundFailure extends RefundResultBase {\n error: string;\n refundEntryId: null;\n amount: Decimal | null;\n newBalance: Decimal | null;\n bucketBreakdown: null;\n}\n\nexport type RefundResult = RefundSuccess | RefundFailure;\n\n/** Credits removed from all remaining lots created by one ledger operation. */\nexport interface RevokeCreditsResult {\n userId: string;\n entryType: string;\n revoked: Decimal;\n balanceAfter: Decimal;\n}\n\nexport interface SweepResult {\n expiredCount: number;\n expiredAmount: Decimal;\n dryRun: boolean;\n expiredByBucket: Record<string, Decimal>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../../../src/credits/types/grants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,MAAM,MAAM,mBAAmB,GAC3B,iBAAiB,GACjB,oBAAoB,GACpB,qBAAqB,GACrB,QAAQ,CAAC;AAEb,uEAAuE;AACvE,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,mBAAmB,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,cAAc,GAAG,IAAI,CAAC;CAClC;AAED,UAAU,qBAAqB;IAC7B,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,iEAAiE;AACjE,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB;IACrE,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,IAAI,CAAC;CACb;AAED,mFAAmF;AACnF,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB;IACrE,YAAY,EAAE,IAAI,CAAC;IACnB,YAAY,EAAE,IAAI,CAAC;IACnB,kBAAkB,EAAE,IAAI,CAAC;IACzB,aAAa,EAAE,IAAI,CAAC;IACpB,MAAM,EAAE,IAAI,CAAC;IACb,QAAQ,EAAE,KAAK,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,u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M,uBAAuB,GAAG,wBAAwB,GAAG,wBAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../../src/credits/types/grants.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\nimport type { CreditMetadata } from \"./account.js\";\n\nexport type GrantProgramTrigger =\n | \"account_created\"\n | \"referral_completed\"\n | \"promo_code_redeemed\"\n | \"manual\";\n\n/** One application event that may award one or more catalog grants. */\nexport interface ExecuteGrantProgramRequest {\n trigger: GrantProgramTrigger;\n programKey: string;\n subjectId: string;\n eventKey: string;\n referrerSubjectId?: string | null;\n region?: string | null;\n metadata?: CreditMetadata | null;\n}\n\ninterface GrantProgramAwardBase {\n replayed: boolean;\n}\n\n/** One committed award produced by a grant-program execution. */\nexport interface GrantProgramAwardSuccess extends GrantProgramAwardBase {\n grantEventId: string;\n grantAwardId: string;\n recipientSubjectId: string;\n ledgerEntryId: string;\n amount: Decimal;\n error: null;\n}\n\n/** A rejected grant-program execution. No financial identifiers are fabricated. */\nexport interface GrantProgramAwardFailure extends GrantProgramAwardBase {\n grantEventId: null;\n grantAwardId: null;\n recipientSubjectId: null;\n ledgerEntryId: null;\n amount: null;\n replayed: false;\n error: string;\n}\n\nexport type GrantProgramAwardResult = GrantProgramAwardSuccess | GrantProgramAwardFailure;\n"]}
1
+ {"version":3,"file":"grants.js","sourceRoot":"","sources":["../../../src/credits/types/grants.ts"],"names":[],"mappings":"","sourcesContent":["import type { Decimal } from \"decimal.js\";\nimport type { CreditMetadata } from \"./account.js\";\n\nexport type GrantProgramTrigger =\n \"account_created\" | \"referral_completed\" | \"promo_code_redeemed\" | \"manual\";\n\n/** One application event that may award one or more catalog grants. */\nexport interface ExecuteGrantProgramRequest {\n trigger: GrantProgramTrigger;\n programKey: string;\n subjectId: string;\n eventKey: string;\n referrerSubjectId?: string | null;\n region?: string | null;\n metadata?: CreditMetadata | null;\n}\n\ninterface GrantProgramAwardBase {\n replayed: boolean;\n}\n\n/** One committed award produced by a grant-program execution. */\nexport interface GrantProgramAwardSuccess extends GrantProgramAwardBase {\n grantEventId: string;\n grantAwardId: string;\n recipientSubjectId: string;\n ledgerEntryId: string;\n amount: Decimal;\n error: null;\n}\n\n/** A rejected grant-program execution. No financial identifiers are fabricated. */\nexport interface GrantProgramAwardFailure extends GrantProgramAwardBase {\n grantEventId: null;\n grantAwardId: null;\n recipientSubjectId: null;\n ledgerEntryId: null;\n amount: null;\n replayed: false;\n error: string;\n}\n\nexport type GrantProgramAwardResult = GrantProgramAwardSuccess | GrantProgramAwardFailure;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/expr/ast.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,QAAQ,CAAC;IACf,wFAAwF;IACxF,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,IAAI,CAAC;CACf;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,EAAE,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;CACZ;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,YAAY,CA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ED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC;CACb;AAED,MAAM,MAAM,IAAI,GACd,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAElG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,EAAE,CAgB3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/expr/ast.ts"],"names":[],"mappings":"AA6DA,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,KAAK,OAAO;YACV,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY;YACf,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["export interface NumNode {\n type: \"number\";\n /** Exact literal text, parsed directly by Decimal without a binary-float round trip. */\n value: string;\n}\n\nexport interface IdentNode {\n type: \"identifier\";\n name: string;\n}\n\nexport interface BinOpNode {\n type: \"binary\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport interface UnaryNode {\n type: \"unary\";\n op: string;\n operand: Node;\n}\n\nexport interface CallNode {\n type: \"call\";\n name: string;\n args: Node[];\n}\n\nexport interface TernaryNode {\n type: \"ternary\";\n cond: Node;\n then: Node;\n else: Node;\n}\n\nexport interface CompareNode {\n type: \"comparison\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport interface BoolOpNode {\n type: \"boolean\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport type Node =\n | NumNode\n | IdentNode\n | BinOpNode\n | UnaryNode\n | CallNode\n | TernaryNode\n | CompareNode\n | BoolOpNode;\n\nexport function children(node: Node): Node[] {\n switch (node.type) {\n case \"binary\":\n case \"comparison\":\n case \"boolean\":\n return [node.left, node.right];\n case \"unary\":\n return [node.operand];\n case \"call\":\n return node.args;\n case \"ternary\":\n return [node.cond, node.then, node.else];\n case \"number\":\n case \"identifier\":\n return [];\n }\n}\n"]}
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/expr/ast.ts"],"names":[],"mappings":"AAsDA,MAAM,UAAU,QAAQ,CAAC,IAAU;IACjC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY,CAAC;QAClB,KAAK,SAAS;YACZ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,KAAK,OAAO;YACV,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,KAAK,MAAM;YACT,OAAO,IAAI,CAAC,IAAI,CAAC;QACnB,KAAK,SAAS;YACZ,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3C,KAAK,QAAQ,CAAC;QACd,KAAK,YAAY;YACf,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["export interface NumNode {\n type: \"number\";\n /** Exact literal text, parsed directly by Decimal without a binary-float round trip. */\n value: string;\n}\n\nexport interface IdentNode {\n type: \"identifier\";\n name: string;\n}\n\nexport interface BinOpNode {\n type: \"binary\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport interface UnaryNode {\n type: \"unary\";\n op: string;\n operand: Node;\n}\n\nexport interface CallNode {\n type: \"call\";\n name: string;\n args: Node[];\n}\n\nexport interface TernaryNode {\n type: \"ternary\";\n cond: Node;\n then: Node;\n else: Node;\n}\n\nexport interface CompareNode {\n type: \"comparison\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport interface BoolOpNode {\n type: \"boolean\";\n op: string;\n left: Node;\n right: Node;\n}\n\nexport type Node =\n NumNode | IdentNode | BinOpNode | UnaryNode | CallNode | TernaryNode | CompareNode | BoolOpNode;\n\nexport function children(node: Node): Node[] {\n switch (node.type) {\n case \"binary\":\n case \"comparison\":\n case \"boolean\":\n return [node.left, node.right];\n case \"unary\":\n return [node.operand];\n case \"call\":\n return node.args;\n case \"ternary\":\n return [node.cond, node.then, node.else];\n case \"number\":\n case \"identifier\":\n return [];\n }\n}\n"]}
@@ -16,6 +16,7 @@ export declare class ExpressionParser {
16
16
  private addition;
17
17
  private multiplication;
18
18
  private notExpression;
19
+ private andExpression;
19
20
  private booleanExpression;
20
21
  private unary;
21
22
  private primary;
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/expr/parser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAMV,IAAI,EAIL,MAAM,UAAU,CAAC;AAElB,OAAO,EAAY,KAAK,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AAEtE,qBAAa,gBAAgB;IAGf,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAK;gBAEQ,MAAM,EAAE,KAAK,EAAE;IAE5C,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM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ser {
121
121
  operand: this.notExpression(),
122
122
  };
123
123
  }
124
- booleanExpression() {
124
+ andExpression() {
125
125
  let left = this.notExpression();
126
- while (this.match("and", "or")) {
126
+ while (this.match("and")) {
127
127
  left = {
128
128
  type: "boolean",
129
- op: this.previous().value,
129
+ op: "and",
130
130
  left,
131
131
  right: this.notExpression(),
132
132
  };
133
133
  }
134
134
  return left;
135
135
  }
136
+ booleanExpression() {
137
+ let left = this.andExpression();
138
+ while (this.match("or")) {
139
+ left = {
140
+ type: "boolean",
141
+ op: "or",
142
+ left,
143
+ right: this.andExpression(),
144
+ };
145
+ }
146
+ return left;
147
+ }
136
148
  unary() {
137
149
  if (!this.match("+", "-"))
138
150
  return this.primary();
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/expr/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAY/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAA8B,MAAM,gBAAgB,CAAC;AAEtE,MAAM,OAAO,gBAAgB;IAGE;IAFrB,QAAQ,GAAG,CAAC,CAAC;IAErB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,MAAM,CAAC,UAAU,CAAC,MAAc;QAC9B,OAAO,IAAI,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC7C,CAAC;IAEO,QAAQ;QACd,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,K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IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,EAAc,CAAC;QAC9E,CAAC;QACD,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YAClC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,MAAM,IAAI,eAAe,CAAC,sBAAsB,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC;IAClF,CAAC;IAEO,aAAa;QACnB,MAAM,IAAI,GAAW,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,GAAG,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;YACtC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QAC5B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { ExpressionError } from \"../errors.js\";\nimport type {\n BinOpNode,\n BoolOpNode,\n CallNode,\n CompareNode,\n IdentNode,\n Node,\n NumNode,\n TernaryNode,\n UnaryNode,\n} from \"./ast.js\";\nimport { ALLOWED_FUNCTIONS } from \"./language.js\";\nimport { tokenize, type Token, type TokenType } from \"./tokenizer.js\";\n\nexport class ExpressionParser {\n private position = 0;\n\n constructor(private readonly tokens: Token[]) {}\n\n static fromSource(source: string): ExpressionParser {\n return new ExpressionParser(tokenize(source));\n }\n\n peek(): Token | undefined {\n return this.tokens[this.position];\n }\n\n isAtEnd(): boolean {\n return this.position >= this.tokens.length;\n }\n\n private previous(): Token {\n const token = this.tokens[this.position - 1];\n if (!token) throw new ExpressionError(\"invalid parser state: no previous token\");\n return token;\n }\n\n private check(...types: TokenType[]): boolean {\n const token = this.peek();\n return token !== undefined && types.includes(token.type);\n }\n\n private match(...types: TokenType[]): boolean {\n for (const type of types) {\n if (this.check(type)) {\n this.position++;\n return true;\n }\n }\n return false;\n }\n\n private consume(type: TokenType, message: string): Token {\n const token = this.peek();\n if (token?.type === type) {\n this.position++;\n return token;\n }\n throw new ExpressionError(message);\n }\n\n parse(): Node {\n const expression = this.booleanExpression();\n if (!this.match(\"if\")) return expression;\n\n const condition = this.booleanExpression();\n this.consume(\"else\", \"expected 'else' in ternary expression\");\n return {\n type: \"ternary\",\n cond: condition,\n then: expression,\n else: this.booleanExpression(),\n } as TernaryNode;\n }\n\n private comparison(): Node {\n const left = this.addition();\n let node: Node;\n if (this.check(\"not\")) {\n this.match(\"not\");\n if (!this.match(\"in\")) {\n throw new ExpressionError(\"expected 'in' after 'not'\");\n }\n node = { type: \"comparison\", op: \"not in\", left, right: this.addition() } as CompareNode;\n } else if (this.match(\"==\", \"!=\", \"<\", \"<=\", \">\", \">=\", \"in\")) {\n node = {\n type: \"comparison\",\n op: this.previous().value,\n left,\n right: this.addition(),\n } as CompareNode;\n } else {\n return left;\n }\n // Reject chained comparisons (a < b < c): a left-associative fold would\n // evaluate them as ((a<b)<c) whereas Python uses and-chaining semantics, so\n // forbidding them keeps the two engines identical (parity).\n if (this.check(\"==\", \"!=\", \"<\", \"<=\", \">\", \">=\", \"in\", \"not\")) {\n throw new ExpressionError(\"chained comparisons are not supported\");\n }\n return node;\n }\n\n private addition(): Node {\n let left = this.multiplication();\n while (this.match(\"+\", \"-\")) {\n left = {\n type: \"binary\",\n op: this.previous().value,\n left,\n right: this.multiplication(),\n } as BinOpNode;\n }\n return left;\n }\n\n private multiplication(): Node {\n let left = this.unary();\n while (this.match(\"*\", \"/\", \"//\", \"%\")) {\n left = {\n type: \"binary\",\n op: this.previous().value,\n left,\n right: this.unary(),\n } as BinOpNode;\n }\n if (this.check(\"**\")) {\n throw new ExpressionError(\n \"exponentiation operator '**' is not allowed in pricing expressions\",\n );\n }\n return left;\n }\n\n private notExpression(): Node {\n if (!this.match(\"not\")) return this.comparison();\n return {\n type: \"unary\",\n op: \"not\",\n operand: this.notExpression(),\n } as UnaryNode;\n }\n\n private booleanExpression(): Node {\n let left = this.notExpression();\n while (this.match(\"and\", \"or\")) {\n left = {\n type: \"boolean\",\n op: this.previous().value,\n left,\n right: this.notExpression(),\n } as BoolOpNode;\n }\n return left;\n }\n\n private unary(): Node {\n if (!this.match(\"+\", \"-\")) return this.primary();\n return {\n type: \"unary\",\n op: this.previous().value,\n operand: this.unary(),\n } as UnaryNode;\n }\n\n private primary(): Node {\n if (this.check(\"**\")) {\n throw new ExpressionError(\n \"exponentiation operator '**' is not allowed in pricing expressions\",\n );\n }\n if (this.match(\"number\")) {\n return { type: \"number\", value: this.previous().value } as NumNode;\n }\n if (this.match(\"identifier\")) {\n const name = this.previous().value;\n if (!this.match(\"(\")) return { type: \"identifier\", name } as IdentNode;\n if (!ALLOWED_FUNCTIONS.has(name)) {\n throw new ExpressionError(`disallowed function: ${name}`);\n }\n return { type: \"call\", name, args: this.callArguments() } as CallNode;\n }\n if (this.match(\"if\") && this.match(\"(\")) {\n return { type: \"call\", name: \"if\", args: this.callArguments() } as CallNode;\n }\n if (this.match(\"(\")) {\n const expression = this.parse();\n this.consume(\")\", \"expected ')'\");\n return expression;\n }\n throw new ExpressionError(`unexpected token: '${this.peek()?.value ?? \"EOF\"}'`);\n }\n\n private callArguments(): Node[] {\n const args: Node[] = [];\n if (!this.check(\")\")) {\n do {\n args.push(this.booleanExpression());\n } while (this.match(\",\"));\n }\n this.consume(\")\", \"expected ')'\");\n return args;\n }\n}\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/expr/parser.ts"],"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,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;YAClC,OAAO,UAAU,CAAC;QACpB,CAAC;QACD,MAAM,IAAI,eAAe,CAAC,sBAAsB,IAAI,CAAC,IAAI,EAAE,EAAE,KAAK,IAAI,KAAK,GAAG,CAAC,CAAC;IAClF,CAAC;IAEO,aAAa;QACnB,MAAM,IAAI,GAAW,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,GAAG,CAAC;gBACF,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;YACtC,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QAC5B,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { ExpressionError } from \"../errors.js\";\nimport type {\n BinOpNode,\n BoolOpNode,\n CallNode,\n CompareNode,\n IdentNode,\n Node,\n NumNode,\n TernaryNode,\n UnaryNode,\n} from \"./ast.js\";\nimport { ALLOWED_FUNCTIONS } from \"./language.js\";\nimport { tokenize, type Token, type TokenType } from \"./tokenizer.js\";\n\nexport class ExpressionParser {\n private position = 0;\n\n constructor(private readonly tokens: Token[]) {}\n\n static fromSource(source: string): ExpressionParser {\n return new ExpressionParser(tokenize(source));\n }\n\n peek(): Token | undefined {\n return this.tokens[this.position];\n }\n\n isAtEnd(): boolean {\n return this.position >= this.tokens.length;\n }\n\n private previous(): Token {\n const token = this.tokens[this.position - 1];\n if (!token) throw new ExpressionError(\"invalid parser state: no previous token\");\n return token;\n }\n\n private check(...types: TokenType[]): boolean {\n const token = this.peek();\n return token !== undefined && types.includes(token.type);\n }\n\n private match(...types: TokenType[]): boolean {\n for (const type of types) {\n if (this.check(type)) {\n this.position++;\n return true;\n }\n }\n return false;\n }\n\n private consume(type: TokenType, message: string): Token {\n const token = this.peek();\n if (token?.type === type) {\n this.position++;\n return token;\n }\n throw new ExpressionError(message);\n }\n\n parse(): Node {\n const expression = this.booleanExpression();\n if (!this.match(\"if\")) return expression;\n\n const condition = this.booleanExpression();\n this.consume(\"else\", \"expected 'else' in ternary expression\");\n return {\n type: \"ternary\",\n cond: condition,\n then: expression,\n else: this.booleanExpression(),\n } as TernaryNode;\n }\n\n private comparison(): Node {\n const left = this.addition();\n let node: Node;\n if (this.check(\"not\")) {\n this.match(\"not\");\n if (!this.match(\"in\")) {\n throw new ExpressionError(\"expected 'in' after 'not'\");\n }\n node = { type: \"comparison\", op: \"not in\", left, right: this.addition() } as CompareNode;\n } else if (this.match(\"==\", \"!=\", \"<\", \"<=\", \">\", \">=\", \"in\")) {\n node = {\n type: \"comparison\",\n op: this.previous().value,\n left,\n right: this.addition(),\n } as CompareNode;\n } else {\n return left;\n }\n // Reject chained comparisons (a < b < c): a left-associative fold would\n // evaluate them as ((a<b)<c) whereas Python uses and-chaining semantics, so\n // forbidding them keeps the two engines identical (parity).\n if (this.check(\"==\", \"!=\", \"<\", \"<=\", \">\", \">=\", \"in\", \"not\")) {\n throw new ExpressionError(\"chained comparisons are not supported\");\n }\n return node;\n }\n\n private addition(): Node {\n let left = this.multiplication();\n while (this.match(\"+\", \"-\")) {\n left = {\n type: \"binary\",\n op: this.previous().value,\n left,\n right: this.multiplication(),\n } as BinOpNode;\n }\n return left;\n }\n\n private multiplication(): Node {\n let left = this.unary();\n while (this.match(\"*\", \"/\", \"//\", \"%\")) {\n left = {\n type: \"binary\",\n op: this.previous().value,\n left,\n right: this.unary(),\n } as BinOpNode;\n }\n if (this.check(\"**\")) {\n throw new ExpressionError(\n \"exponentiation operator '**' is not allowed in pricing expressions\",\n );\n }\n return left;\n }\n\n private notExpression(): Node {\n if (!this.match(\"not\")) return this.comparison();\n return {\n type: \"unary\",\n op: \"not\",\n operand: this.notExpression(),\n } as UnaryNode;\n }\n\n private andExpression(): Node {\n let left = this.notExpression();\n while (this.match(\"and\")) {\n left = {\n type: \"boolean\",\n op: \"and\",\n left,\n right: this.notExpression(),\n } as BoolOpNode;\n }\n return left;\n }\n\n private booleanExpression(): Node {\n let left = this.andExpression();\n while (this.match(\"or\")) {\n left = {\n type: \"boolean\",\n op: \"or\",\n left,\n right: this.andExpression(),\n } as BoolOpNode;\n }\n return left;\n }\n\n private unary(): Node {\n if (!this.match(\"+\", \"-\")) return this.primary();\n return {\n type: \"unary\",\n op: this.previous().value,\n operand: this.unary(),\n } as UnaryNode;\n }\n\n private primary(): Node {\n if (this.check(\"**\")) {\n throw new ExpressionError(\n \"exponentiation operator '**' is not allowed in pricing expressions\",\n );\n }\n if (this.match(\"number\")) {\n return { type: \"number\", value: this.previous().value } as NumNode;\n }\n if (this.match(\"identifier\")) {\n const name = this.previous().value;\n if (!this.match(\"(\")) return { type: \"identifier\", name } as IdentNode;\n if (!ALLOWED_FUNCTIONS.has(name)) {\n throw new ExpressionError(`disallowed function: ${name}`);\n }\n return { type: \"call\", name, args: this.callArguments() } as CallNode;\n }\n if (this.match(\"if\") && this.match(\"(\")) {\n return { type: \"call\", name: \"if\", args: this.callArguments() } as CallNode;\n }\n if (this.match(\"(\")) {\n const expression = this.parse();\n this.consume(\")\", \"expected ')'\");\n return expression;\n }\n throw new ExpressionError(`unexpected token: '${this.peek()?.value ?? \"EOF\"}'`);\n }\n\n private callArguments(): Node[] {\n const args: Node[] = [];\n if (!this.check(\")\")) {\n do {\n args.push(this.booleanExpression());\n } while (this.match(\",\"));\n }\n this.consume(\")\", \"expected ')'\");\n return args;\n }\n}\n"]}