@plasius/economy 0.3.1 → 0.4.0

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.
package/dist/index.d.cts CHANGED
@@ -26,7 +26,12 @@ type EconomyContractVersion = typeof ECONOMY_CONTRACT_VERSION;
26
26
  type AccountId = string;
27
27
  type AllocationId = string;
28
28
  type HouseholdId = string;
29
+ type LearningEntitlementId = string;
30
+ type LearningModuleVersionId = string;
29
31
  type LotId = string;
32
+ type ModuleAllowanceId = string;
33
+ type ModuleSpendHoldId = string;
34
+ type ModuleSpendQuoteId = string;
30
35
  type PostingId = string;
31
36
  type ProviderEventId = string;
32
37
  type TransactionId = string;
@@ -484,6 +489,204 @@ declare function assertJournalChainHead(head: JournalChainHeadV1): void;
484
489
  */
485
490
  declare function advanceJournalChainHead(head: JournalChainHeadV1, transaction: ChainedEconomicJournalTransactionV1): JournalChainHeadV1;
486
491
 
492
+ declare const MODULE_ALLOWANCE_PURPOSE: "junior-coder-module-entitlement";
493
+ type ModuleAllowanceStatusV1 = "active" | "closed";
494
+ /** Guardian-funded value that can only purchase modules for one child. */
495
+ interface ModuleAllowanceV1 {
496
+ readonly schemaVersion: EconomyContractVersion;
497
+ readonly purpose: typeof MODULE_ALLOWANCE_PURPOSE;
498
+ readonly allowanceId: ModuleAllowanceId;
499
+ readonly householdId: HouseholdId;
500
+ readonly hostWalletId: WalletId;
501
+ readonly allowanceWalletId: WalletId;
502
+ readonly childAccountId: AccountId;
503
+ readonly status: ModuleAllowanceStatusV1;
504
+ readonly allocatedAmount: TokenSubunitString;
505
+ readonly availableAmount: TokenSubunitString;
506
+ readonly heldAmount: TokenSubunitString;
507
+ readonly spentAmount: TokenSubunitString;
508
+ readonly reclaimedAmount: TokenSubunitString;
509
+ readonly fundingSlices: readonly SourceLotSliceV1[];
510
+ readonly reclaimedSlices: readonly SourceLotSliceV1[];
511
+ readonly version: number;
512
+ readonly createdAt: IsoTimestamp;
513
+ readonly updatedAt: IsoTimestamp;
514
+ }
515
+ interface CreateModuleAllowanceInputV1 {
516
+ readonly allowanceId: ModuleAllowanceId;
517
+ readonly householdId: HouseholdId;
518
+ readonly hostWalletId: WalletId;
519
+ readonly allowanceWalletId: WalletId;
520
+ readonly childAccountId: AccountId;
521
+ readonly amount: TokenSubunitString;
522
+ readonly fundingSlices: readonly SourceLotSliceV1[];
523
+ readonly occurredAt: IsoTimestamp;
524
+ }
525
+ interface FundModuleAllowanceInputV1 {
526
+ readonly amount: TokenSubunitString;
527
+ readonly fundingSlices: readonly SourceLotSliceV1[];
528
+ readonly expectedVersion: number;
529
+ readonly occurredAt: IsoTimestamp;
530
+ }
531
+ interface ReclaimModuleAllowanceInputV1 {
532
+ readonly amount: TokenSubunitString;
533
+ readonly sourceSlices: readonly SourceLotSliceV1[];
534
+ readonly expectedVersion: number;
535
+ readonly occurredAt: IsoTimestamp;
536
+ }
537
+ interface CloseModuleAllowanceInputV1 {
538
+ readonly expectedVersion: number;
539
+ readonly occurredAt: IsoTimestamp;
540
+ }
541
+ /** Immutable Guardian-approved module price and requirements evidence. */
542
+ interface ModuleSpendQuoteV1 {
543
+ readonly schemaVersion: EconomyContractVersion;
544
+ readonly quoteId: ModuleSpendQuoteId;
545
+ readonly allowanceId: ModuleAllowanceId;
546
+ readonly householdId: HouseholdId;
547
+ readonly guardianAccountId: AccountId;
548
+ readonly childAccountId: AccountId;
549
+ readonly moduleVersionId: LearningModuleVersionId;
550
+ readonly catalogVersion: string;
551
+ readonly amount: TokenSubunitString;
552
+ readonly requirementsManifestVersion: string;
553
+ readonly requirementsManifestHash: string;
554
+ readonly requirementsAcknowledgedAt: IsoTimestamp;
555
+ readonly issuedAt: IsoTimestamp;
556
+ readonly expiresAt: IsoTimestamp;
557
+ }
558
+ type CreateModuleSpendQuoteInputV1 = Omit<ModuleSpendQuoteV1, "schemaVersion">;
559
+ type ModuleSpendHoldStatusV1 = "held" | "settled" | "released";
560
+ /** Versioned projection for one quote-bound allowance hold. */
561
+ interface ModuleSpendHoldV1 {
562
+ readonly schemaVersion: EconomyContractVersion;
563
+ readonly holdId: ModuleSpendHoldId;
564
+ readonly quoteId: ModuleSpendQuoteId;
565
+ readonly allowanceId: ModuleAllowanceId;
566
+ readonly householdId: HouseholdId;
567
+ readonly guardianAccountId: AccountId;
568
+ readonly childAccountId: AccountId;
569
+ readonly moduleVersionId: LearningModuleVersionId;
570
+ readonly amount: TokenSubunitString;
571
+ readonly requirementsManifestVersion: string;
572
+ readonly requirementsManifestHash: string;
573
+ readonly sourceSlices: readonly SourceLotSliceV1[];
574
+ readonly status: ModuleSpendHoldStatusV1;
575
+ readonly holdIdempotencyKey: string;
576
+ readonly settlementIdempotencyKey?: string;
577
+ readonly releaseIdempotencyKey?: string;
578
+ readonly entitlementId?: LearningEntitlementId;
579
+ readonly settlementTransactionId?: TransactionId;
580
+ readonly releaseTransactionId?: TransactionId;
581
+ readonly version: number;
582
+ readonly createdAt: IsoTimestamp;
583
+ readonly expiresAt: IsoTimestamp;
584
+ readonly updatedAt: IsoTimestamp;
585
+ }
586
+ interface CreateModuleSpendHoldInputV1 {
587
+ readonly holdId: ModuleSpendHoldId;
588
+ readonly idempotencyKey: string;
589
+ readonly sourceSlices: readonly SourceLotSliceV1[];
590
+ readonly expectedAllowanceVersion: number;
591
+ readonly occurredAt: IsoTimestamp;
592
+ }
593
+ interface SettleModuleSpendHoldInputV1 {
594
+ readonly entitlementId: LearningEntitlementId;
595
+ readonly settlementTransactionId: TransactionId;
596
+ readonly idempotencyKey: string;
597
+ readonly expectedAllowanceVersion: number;
598
+ readonly expectedHoldVersion: number;
599
+ readonly occurredAt: IsoTimestamp;
600
+ }
601
+ interface ReleaseModuleSpendHoldInputV1 {
602
+ readonly releaseTransactionId: TransactionId;
603
+ readonly idempotencyKey: string;
604
+ readonly expectedAllowanceVersion: number;
605
+ readonly expectedHoldVersion: number;
606
+ readonly occurredAt: IsoTimestamp;
607
+ }
608
+ interface ModuleSpendTransitionResultV1 {
609
+ readonly allowance: ModuleAllowanceV1;
610
+ readonly hold: ModuleSpendHoldV1;
611
+ }
612
+ /** Durable economic receipt for an activated learning entitlement. */
613
+ interface ModulePurchaseReceiptV1 {
614
+ readonly schemaVersion: EconomyContractVersion;
615
+ readonly receiptId: string;
616
+ readonly quoteId: ModuleSpendQuoteId;
617
+ readonly holdId: ModuleSpendHoldId;
618
+ readonly allowanceId: ModuleAllowanceId;
619
+ readonly householdId: HouseholdId;
620
+ readonly guardianAccountId: AccountId;
621
+ readonly childAccountId: AccountId;
622
+ readonly moduleVersionId: LearningModuleVersionId;
623
+ readonly entitlementId: LearningEntitlementId;
624
+ readonly amount: TokenSubunitString;
625
+ readonly requirementsManifestVersion: string;
626
+ readonly requirementsManifestHash: string;
627
+ readonly settlementTransactionId: TransactionId;
628
+ readonly issuedAt: IsoTimestamp;
629
+ }
630
+ interface CreateModulePurchaseReceiptInputV1 {
631
+ readonly receiptId: string;
632
+ readonly issuedAt: IsoTimestamp;
633
+ }
634
+ type ModulePurchaseFinancialStateV1 = "missing" | "held" | "settled" | "released";
635
+ type ModulePurchaseEntitlementStateV1 = "missing" | "pending" | "active" | "cancelled";
636
+ /** Privacy-minimized observation used by an authoritative reconciler. */
637
+ interface ModulePurchaseReconciliationObservationV1 {
638
+ readonly schemaVersion: EconomyContractVersion;
639
+ readonly quoteId: ModuleSpendQuoteId;
640
+ readonly holdId: ModuleSpendHoldId;
641
+ readonly childAccountId: AccountId;
642
+ readonly moduleVersionId: LearningModuleVersionId;
643
+ readonly financialState: ModulePurchaseFinancialStateV1;
644
+ readonly entitlementState: ModulePurchaseEntitlementStateV1;
645
+ readonly receiptPresent: boolean;
646
+ readonly observedAt: IsoTimestamp;
647
+ }
648
+ type ModulePurchaseReconciliationActionV1 = "none" | "resume-settlement" | "release-hold" | "activate-entitlement" | "issue-receipt" | "cancel-pending-entitlement" | "manual-review";
649
+ interface ModulePurchaseReconciliationResultV1 {
650
+ readonly schemaVersion: EconomyContractVersion;
651
+ readonly action: ModulePurchaseReconciliationActionV1;
652
+ readonly blocking: boolean;
653
+ readonly consistent: boolean;
654
+ readonly reasonCode: string;
655
+ }
656
+ /** Validates exact arithmetic and source-lot provenance for an allowance. */
657
+ declare function assertModuleAllowance(allowance: ModuleAllowanceV1): void;
658
+ /** Creates a child-specific Module Allowance from locked source-lot slices. */
659
+ declare function createModuleAllowance(input: CreateModuleAllowanceInputV1): ModuleAllowanceV1;
660
+ /** Adds Guardian-selected source-lot value without replacing prior history. */
661
+ declare function fundModuleAllowance(allowance: ModuleAllowanceV1, input: FundModuleAllowanceInputV1): ModuleAllowanceV1;
662
+ /** Returns unused value to its source lots without changing spent history. */
663
+ declare function reclaimModuleAllowance(allowance: ModuleAllowanceV1, input: ReclaimModuleAllowanceInputV1): ModuleAllowanceV1;
664
+ /** Closes an empty allowance; funding later requires a new allowance. */
665
+ declare function closeModuleAllowance(allowance: ModuleAllowanceV1, input: CloseModuleAllowanceInputV1): ModuleAllowanceV1;
666
+ /** Validates immutable price, Guardian acknowledgement, and manifest evidence. */
667
+ declare function assertModuleSpendQuote(quote: ModuleSpendQuoteV1): void;
668
+ /** Creates immutable quote evidence from server-derived catalog facts. */
669
+ declare function createModuleSpendQuote(input: CreateModuleSpendQuoteInputV1): ModuleSpendQuoteV1;
670
+ /** Validates one quote-bound hold lifecycle projection. */
671
+ declare function assertModuleSpendHold(hold: ModuleSpendHoldV1): void;
672
+ /** Moves quoted value from available to held after all bindings are checked. */
673
+ declare function createModuleSpendHold(allowance: ModuleAllowanceV1, quote: ModuleSpendQuoteV1, input: CreateModuleSpendHoldInputV1): ModuleSpendTransitionResultV1;
674
+ /** Settles a hold only when the pending learning entitlement is identified. */
675
+ declare function settleModuleSpendHold(allowance: ModuleAllowanceV1, hold: ModuleSpendHoldV1, input: SettleModuleSpendHoldInputV1): ModuleSpendTransitionResultV1;
676
+ /** Releases failed or expired held value back to the same allowance. */
677
+ declare function releaseModuleSpendHold(allowance: ModuleAllowanceV1, hold: ModuleSpendHoldV1, input: ReleaseModuleSpendHoldInputV1): ModuleSpendTransitionResultV1;
678
+ /** Validates a durable receipt against settled economic evidence. */
679
+ declare function assertModulePurchaseReceipt(receipt: ModulePurchaseReceiptV1): void;
680
+ /** Creates a receipt only when quote and settled hold evidence match exactly. */
681
+ declare function createModulePurchaseReceipt(quote: ModuleSpendQuoteV1, hold: ModuleSpendHoldV1, input: CreateModulePurchaseReceiptInputV1): ModulePurchaseReceiptV1;
682
+ /** Validates privacy-minimized cross-service reconciliation evidence. */
683
+ declare function assertModulePurchaseReconciliationObservation(observation: ModulePurchaseReconciliationObservationV1): void;
684
+ /**
685
+ * Returns one forward-safe action. Callers must reload and lock authoritative
686
+ * state before carrying it out; `manual-review` never authorizes a mutation.
687
+ */
688
+ declare function reconcileModulePurchase(observation: ModulePurchaseReconciliationObservationV1): ModulePurchaseReconciliationResultV1;
689
+
487
690
  type AdjustmentStatus = "draft" | "pending-approval" | "approved" | "rejected" | "executed" | "expired";
488
691
  /** Dual-control request; the resulting change is always a ledger transaction. */
489
692
  interface AdjustmentRequestV1 {
@@ -503,6 +706,88 @@ interface AdjustmentRequestV1 {
503
706
  /** Proves that production adjustment approval was performed by another actor. */
504
707
  declare function assertDistinctAdjustmentApproval(request: AdjustmentRequestV1): void;
505
708
 
709
+ type PaidLotLifecycleStatusV1 = "clear" | "partially-reversed" | "disputed" | "fully-reversed" | "chargeback-lost";
710
+ type PaidLotLifecycleEventTypeV1 = "refund" | "dispute-hold" | "dispute-won" | "dispute-lost" | "chargeback" | "reversal";
711
+ /** Paid-purchase facts not already carried by the source lot. */
712
+ interface PaidLotPurchaseProvenanceV1 {
713
+ readonly schemaVersion: EconomyContractVersion;
714
+ readonly purchaseId: string;
715
+ readonly catalogVersion: string;
716
+ readonly purchasedAt: IsoTimestamp;
717
+ }
718
+ /** Provider-neutral refund/dispute evidence for a paid source lot. */
719
+ interface PaidLotLifecycleEventV1 {
720
+ readonly schemaVersion: EconomyContractVersion;
721
+ readonly eventId: string;
722
+ readonly lotId: LotId;
723
+ readonly eventType: PaidLotLifecycleEventTypeV1;
724
+ readonly amount: TokenSubunitString;
725
+ readonly occurredAt: IsoTimestamp;
726
+ }
727
+ interface PaidLotLifecycleReceiptV1 {
728
+ readonly schemaVersion: EconomyContractVersion;
729
+ readonly event: PaidLotLifecycleEventV1;
730
+ }
731
+ /**
732
+ * Retained paid-lot projection. Immutable purchase/original facts plus every
733
+ * receipt are sufficient to rebuild all derived amounts in occurrence order.
734
+ */
735
+ interface PaidLotLifecycleV1 {
736
+ readonly schemaVersion: EconomyContractVersion;
737
+ readonly lotId: LotId;
738
+ readonly payerAccountId: AccountId;
739
+ readonly receivingHouseholdId: HouseholdId;
740
+ readonly purchaseId: string;
741
+ readonly catalogVersion: string;
742
+ readonly purchasedAt: IsoTimestamp;
743
+ readonly settledAt: IsoTimestamp;
744
+ readonly creditedAt: IsoTimestamp;
745
+ readonly originalAmount: TokenSubunitString;
746
+ readonly retainedAmount: TokenSubunitString;
747
+ readonly heldAmount: TokenSubunitString;
748
+ readonly reversedAmount: TokenSubunitString;
749
+ readonly refundedAmount: TokenSubunitString;
750
+ readonly chargebackAmount: TokenSubunitString;
751
+ readonly oneTimeReversalAmount: TokenSubunitString;
752
+ readonly status: PaidLotLifecycleStatusV1;
753
+ readonly version: number;
754
+ readonly receipts: readonly PaidLotLifecycleReceiptV1[];
755
+ readonly effectiveEventIds: readonly string[];
756
+ }
757
+ /** Exact signed projection deltas produced when one receipt is appended. */
758
+ interface PaidLotLifecycleArithmeticV1 {
759
+ readonly retainedDelta: TokenSubunitString;
760
+ readonly heldDelta: TokenSubunitString;
761
+ readonly reversedDelta: TokenSubunitString;
762
+ readonly refundedDelta: TokenSubunitString;
763
+ readonly chargebackDelta: TokenSubunitString;
764
+ readonly oneTimeReversalDelta: TokenSubunitString;
765
+ }
766
+ interface PaidLotLifecycleMutationResultV1 {
767
+ readonly lifecycle: PaidLotLifecycleV1;
768
+ /** False only for an exact event-ID replay already recorded. */
769
+ readonly applied: boolean;
770
+ readonly stateChanged: boolean;
771
+ readonly arithmetic: PaidLotLifecycleArithmeticV1;
772
+ }
773
+ /** Validates the paid purchase facts paired with a source lot. */
774
+ declare function assertPaidLotPurchaseProvenance(provenance: PaidLotPurchaseProvenanceV1): void;
775
+ /** Validates one provider-neutral paid-lot lifecycle event. */
776
+ declare function assertPaidLotLifecycleEvent(event: PaidLotLifecycleEventV1): void;
777
+ /** Validates and deterministically rebuilds retained paid-lot arithmetic. */
778
+ declare function assertPaidLotLifecycle(lifecycle: PaidLotLifecycleV1): void;
779
+ /** Creates the retained projection for one newly credited paid source lot. */
780
+ declare function createPaidLotLifecycle(lot: SourceLotV1, provenance: PaidLotPurchaseProvenanceV1): PaidLotLifecycleV1;
781
+ /**
782
+ * Appends one event then rebuilds every receipt in authoritative occurrence
783
+ * order. Exact retries succeed before stale-version validation.
784
+ */
785
+ declare function applyPaidLotLifecycleEvent(lifecycle: PaidLotLifecycleV1, event: PaidLotLifecycleEventV1, expectedVersion: number): PaidLotLifecycleMutationResultV1;
786
+ /** Reduces unordered/retried lifecycle evidence in canonical event order. */
787
+ declare function reducePaidLotLifecycleEvents(initial: PaidLotLifecycleV1, events: readonly PaidLotLifecycleEventV1[]): PaidLotLifecycleV1;
788
+ /** Creates the exact retained-basis input used by early-backer evaluators. */
789
+ declare function createEarlyBackerRetentionFromPaidLot(lifecycle: PaidLotLifecycleV1): PaidLotRetentionV1;
790
+
506
791
  type WalletKind = "household-treasury" | "personal" | "gameplay-allocation" | "hold" | "purchase-clearing" | "provider-clearing" | "system";
507
792
  type WalletStatus = "active" | "restricted" | "closed";
508
793
  type WalletOwnerType = "account" | "household" | "system";
@@ -926,6 +1211,163 @@ interface EconomyQueryPortV1 {
926
1211
  listPortfolioActivity(scope: WalletPortfolioReadScopeV1, request: WalletActivityPageRequestV1): Promise<WalletActivityPageV1>;
927
1212
  }
928
1213
 
1214
+ declare const gbpMinorUnitStringBrand: unique symbol;
1215
+ /** Canonical non-negative GBP minor-unit string used by cap contracts. */
1216
+ type GbpMinorUnitString = string & {
1217
+ readonly [gbpMinorUnitStringBrand]: "GbpMinorUnitString";
1218
+ };
1219
+ /** Parses exact GBP minor units without floating point or coercion. */
1220
+ declare function parseGbpMinorUnits(value: string): bigint;
1221
+ /** Serializes exact GBP minor units using the canonical wire representation. */
1222
+ declare function serializeGbpMinorUnits(amount: bigint): GbpMinorUnitString;
1223
+ type PurchaseCapScopeTypeV1 = "payer" | "household";
1224
+ type PurchaseCapReservationStatusV1 = "reserved" | "settled" | "released" | "expired";
1225
+ type PurchaseCapReservationTransitionTypeV1 = "settle" | "release" | "expire";
1226
+ interface PurchaseCapReservationTransitionV1 {
1227
+ readonly schemaVersion: EconomyContractVersion;
1228
+ readonly transitionId: string;
1229
+ readonly reservationId: string;
1230
+ readonly transitionType: PurchaseCapReservationTransitionTypeV1;
1231
+ readonly occurredAt: IsoTimestamp;
1232
+ }
1233
+ /** Append-only cap evidence; effectiveness is rebuilt from occurrence order. */
1234
+ interface PurchaseCapReservationTransitionReceiptV1 {
1235
+ readonly schemaVersion: EconomyContractVersion;
1236
+ readonly transition: PurchaseCapReservationTransitionV1;
1237
+ }
1238
+ /** One purchase amount mirrored into payer and household cap aggregates. */
1239
+ interface PurchaseCapReservationV1 {
1240
+ readonly schemaVersion: EconomyContractVersion;
1241
+ readonly reservationId: string;
1242
+ readonly payerAccountId: AccountId;
1243
+ readonly householdId: HouseholdId;
1244
+ readonly priceMinorUnits: GbpMinorUnitString;
1245
+ readonly status: PurchaseCapReservationStatusV1;
1246
+ readonly reservedAt: IsoTimestamp;
1247
+ readonly expiresAt: IsoTimestamp;
1248
+ /** Derived winning transition; every delivery remains in `transitionReceipts`. */
1249
+ readonly finalTransitionId?: string;
1250
+ readonly finalizedAt?: IsoTimestamp;
1251
+ readonly transitionReceipts: readonly PurchaseCapReservationTransitionReceiptV1[];
1252
+ }
1253
+ /** Optimistic aggregate for exactly one payer or household rolling ceiling. */
1254
+ interface RollingPurchaseCapStateV1 {
1255
+ readonly schemaVersion: EconomyContractVersion;
1256
+ readonly scopeType: PurchaseCapScopeTypeV1;
1257
+ readonly scopeId: string;
1258
+ readonly version: number;
1259
+ readonly reservations: readonly PurchaseCapReservationV1[];
1260
+ }
1261
+ interface ReservePurchaseCapsCommandV1 {
1262
+ readonly schemaVersion: EconomyContractVersion;
1263
+ readonly reservationId: string;
1264
+ readonly payerAccountId: AccountId;
1265
+ readonly householdId: HouseholdId;
1266
+ readonly priceMinorUnits: GbpMinorUnitString;
1267
+ readonly reservedAt: IsoTimestamp;
1268
+ readonly expiresAt: IsoTimestamp;
1269
+ readonly expectedPayerVersion: number;
1270
+ readonly expectedHouseholdVersion: number;
1271
+ }
1272
+ interface PurchaseCapMutationResultV1 {
1273
+ readonly payerState: RollingPurchaseCapStateV1;
1274
+ readonly householdState: RollingPurchaseCapStateV1;
1275
+ readonly reservation: PurchaseCapReservationV1;
1276
+ /** True when a reservation or transition receipt was newly recorded. */
1277
+ readonly applied: boolean;
1278
+ readonly stateChanged: boolean;
1279
+ readonly payerUsageMinorUnits: GbpMinorUnitString;
1280
+ readonly householdUsageMinorUnits: GbpMinorUnitString;
1281
+ }
1282
+ /** Validates one rolling-cap transition envelope. */
1283
+ declare function assertPurchaseCapReservationTransition(transition: PurchaseCapReservationTransitionV1): void;
1284
+ /** Validates one mirrored rolling-cap reservation and its complete rebuild. */
1285
+ declare function assertPurchaseCapReservation(reservation: PurchaseCapReservationV1): void;
1286
+ /** Validates one payer or household rolling-cap aggregate. */
1287
+ declare function assertRollingPurchaseCapState(state: RollingPurchaseCapStateV1): void;
1288
+ /** Returns the exact cap usage at one point in time. */
1289
+ declare function calculateRollingPurchaseCapUsage(state: RollingPurchaseCapStateV1, checkedAt: IsoTimestamp, policy: PurchaseLimitPolicyV1): GbpMinorUnitString;
1290
+ /** Creates an empty compare-and-swap aggregate for one cap scope. */
1291
+ declare function createRollingPurchaseCapState(scopeType: PurchaseCapScopeTypeV1, scopeId: string): RollingPurchaseCapStateV1;
1292
+ /**
1293
+ * Atomically reserves the same amount in payer and household aggregates.
1294
+ * Adapters must compare-and-swap both returned versions in one transaction.
1295
+ */
1296
+ declare function reserveRollingPurchaseCaps(payerState: RollingPurchaseCapStateV1, householdState: RollingPurchaseCapStateV1, command: ReservePurchaseCapsCommandV1, policy: PurchaseLimitPolicyV1): PurchaseCapMutationResultV1;
1297
+ /**
1298
+ * Appends a settle/release/expiry receipt and rebuilds authoritative order. A
1299
+ * late-delivered pre-expiry settlement corrects a stored expiry while retaining
1300
+ * both receipts. Payer and household versions still advance atomically.
1301
+ */
1302
+ declare function transitionRollingPurchaseCapReservation(payerState: RollingPurchaseCapStateV1, householdState: RollingPurchaseCapStateV1, transition: PurchaseCapReservationTransitionV1, expectedPayerVersion: number, expectedHouseholdVersion: number, policy: PurchaseLimitPolicyV1): PurchaseCapMutationResultV1;
1303
+
1304
+ type PurchaseIntentTransitionTypeV1 = "checkout-bound" | "payment-observed" | "credit-recorded" | "expire" | "cancel" | "dispute-opened" | "dispute-won" | "dispute-lost";
1305
+ type PurchaseIntentDisputeDispositionV1 = "none" | "open" | "won" | "lost";
1306
+ /** Provider-neutral evidence for one requested purchase-intent transition. */
1307
+ interface PurchaseIntentTransitionV1 {
1308
+ readonly schemaVersion: EconomyContractVersion;
1309
+ readonly transitionId: string;
1310
+ readonly intentId: string;
1311
+ readonly transitionType: PurchaseIntentTransitionTypeV1;
1312
+ readonly occurredAt: IsoTimestamp;
1313
+ /** Sanitized binding; raw provider checkout references are adapter concerns. */
1314
+ readonly providerCheckoutReferenceHash?: string;
1315
+ }
1316
+ /** Append-only receipt. Whether it is effective is a rebuildable projection. */
1317
+ interface PurchaseIntentTransitionReceiptV1 {
1318
+ readonly schemaVersion: EconomyContractVersion;
1319
+ readonly transition: PurchaseIntentTransitionV1;
1320
+ }
1321
+ /**
1322
+ * Versioned lifecycle projection. `initialIntent` never changes; every delivery
1323
+ * is rebuilt from its append-only receipts in authoritative occurrence order.
1324
+ */
1325
+ interface PurchaseIntentLifecycleV1 {
1326
+ readonly schemaVersion: EconomyContractVersion;
1327
+ readonly initialIntent: PurchaseIntentV1;
1328
+ readonly intent: PurchaseIntentV1;
1329
+ readonly version: number;
1330
+ readonly creditRecorded: boolean;
1331
+ readonly disputeDisposition: PurchaseIntentDisputeDispositionV1;
1332
+ readonly receipts: readonly PurchaseIntentTransitionReceiptV1[];
1333
+ readonly effectiveTransitionIds: readonly string[];
1334
+ }
1335
+ /** Stable instruction identity for the one permitted purchase credit. */
1336
+ interface PurchaseCreditInstructionV1 {
1337
+ readonly schemaVersion: EconomyContractVersion;
1338
+ readonly intentId: string;
1339
+ readonly transitionId: string;
1340
+ readonly idempotencyKey: string;
1341
+ }
1342
+ interface PurchaseIntentTransitionResultV1 {
1343
+ readonly lifecycle: PurchaseIntentLifecycleV1;
1344
+ /** False only for an exact transition-ID replay already in `receipts`. */
1345
+ readonly recorded: boolean;
1346
+ readonly stateChanged: boolean;
1347
+ readonly creditInstruction?: PurchaseCreditInstructionV1;
1348
+ }
1349
+ interface PurchaseIntentReductionV1 {
1350
+ readonly lifecycle: PurchaseIntentLifecycleV1;
1351
+ readonly creditInstructions: readonly PurchaseCreditInstructionV1[];
1352
+ }
1353
+ /** Validates one provider-neutral purchase-intent transition envelope. */
1354
+ declare function assertPurchaseIntentTransition(transition: PurchaseIntentTransitionV1): void;
1355
+ /** Validates and deterministically rebuilds a lifecycle projection. */
1356
+ declare function assertPurchaseIntentLifecycle(lifecycle: PurchaseIntentLifecycleV1, pack: TokenPackV1): void;
1357
+ /** Creates a lifecycle from immutable, server-created purchase-intent facts. */
1358
+ declare function createPurchaseIntentLifecycle(initialIntent: PurchaseIntentV1, pack: TokenPackV1): PurchaseIntentLifecycleV1;
1359
+ /**
1360
+ * Appends one event and rebuilds all receipts by authoritative occurrence time.
1361
+ * A late pre-expiry payment can therefore correct a stored expiry without
1362
+ * deleting the expiry receipt. Exact retries succeed before version checking.
1363
+ */
1364
+ declare function applyPurchaseIntentTransition(lifecycle: PurchaseIntentLifecycleV1, transition: PurchaseIntentTransitionV1, expectedVersion: number, pack: TokenPackV1): PurchaseIntentTransitionResultV1;
1365
+ /**
1366
+ * Reduces an unordered delivery batch in canonical event-time/type/ID order.
1367
+ * Exact duplicate IDs collapse; conflicting duplicate facts are rejected.
1368
+ */
1369
+ declare function reducePurchaseIntentTransitions(initialIntent: PurchaseIntentV1, transitions: readonly PurchaseIntentTransitionV1[], pack: TokenPackV1): PurchaseIntentReductionV1;
1370
+
929
1371
  type RecurrenceInterval = "daily" | "weekly" | "monthly";
930
1372
  /** Provider-neutral subscription contract. Site policy controls enablement. */
931
1373
  interface TokenSubscriptionPlanV1 {
@@ -965,4 +1407,4 @@ interface SpendRequestV1 {
965
1407
  /** Validates future child requests while creation remains policy-disabled. */
966
1408
  declare function assertSpendRequest(request: SpendRequestV1): void;
967
1409
 
968
- export { type AccountId, type ActivityEntryV1, type ActivityStatus, type ActivityType, type AdjustmentRequestV1, type AdjustmentStatus, type AllocationId, type AllocationStatus, BASELINE_GBP_CATALOG_VERSION, BASELINE_GBP_REFERENCE_RATE, BASELINE_GBP_TOKEN_PACKS, BASELINE_MONTHLY_SUBSCRIPTION_PLAN, BASELINE_PURCHASE_LIMIT_POLICY, type BalanceProjection, type BalanceProjectionSnapshotV1, type BitLabsConversionState, type BoostGameplayAllocationInputV1, type ChainedEconomicJournalTransactionV1, type CreateGameplayAllocationInputV1, EARLY_BACKER_SETTLEMENT_POLICY_V2, ECONOMY_CONTRACT_VERSION, type EarlyBackerEvaluationV1, type EarlyBackerEvaluationV2, type EarlyBackerWindowV1, type EconomicActivityStatusV1, type EconomicJournalStatus, type EconomicJournalTransactionV1, type EconomicWalletActivityEntryV1, type EconomyClockPort, type EconomyCommandEnvelopeV1, type EconomyCommandType, type EconomyCommandWorkflowEventV1, type EconomyCommandWorkflowStateV1, type EconomyContractVersion, EconomyError, type EconomyErrorCode, type EconomyErrorEnvelopeV1, type EconomyIdPort, type EconomyIdempotencyScopeV1, type EconomyOutboxEventV1, type EconomyPersistencePort, type EconomyPersistencePortV2, type EconomyQueryPortV1, type EconomyUnitOfWork, type EconomyUnitOfWorkV2, type FxSnapshotV1, type GameplayAllocationV1, type GameplayLimitsV1, type HouseholdId, type IsoTimestamp, type JournalChainHeadV1, type JournalChainId, type LedgerPostingV1, type LedgerTransactionV1, type LotId, type LotRefundState, type LotTransferPolicy, type LotUseContextV1, type LotUseOperation, PRE_UTILITY_BACKER_COHORT, type PaidLotRetentionV1, type PeriodicLimitWindow, type PersistedIdempotencyResultV1, type PostingId, type ProviderEventId, type PurchaseIntentStatus, type PurchaseIntentV1, type PurchaseLimitPolicyV1, type ReclaimGameplayAllocationInputV1, type RecurrenceInterval, type ReversalInputV1, type RewardActivityTransitionV1, type RewardConversionStatus, type RewardConversionV1, type RewardRateV1, type ScopedPersistedIdempotencyResultV1, type SourceLotMovementType, type SourceLotMovementV1, type SourceLotSliceV1, type SourceLotV1, type SpendRequestPurpose, type SpendRequestStatus, type SpendRequestV1, TOKEN_SUBUNITS_MAX, TOKEN_SUBUNITS_MIN, TOKEN_SUBUNITS_PER_TOKEN, type TokenPackV1, type TokenReferenceRateV1, type TokenSource, type TokenSubscriptionPlanV1, type TokenSubunitString, type TransactionId, type VersionedSourceLotV1, type WalletActivityEntryV1, type WalletActivityFilterV1, type WalletActivityPageRequestV1, type WalletActivityPageV1, type WalletActivityStatusV1, type WalletBalanceDeltaV1, type WalletBalanceProjectionV1, type WalletBalanceSummaryV1, type WalletBalanceTotalsV1, type WalletId, type WalletKind, type WalletLifetimeBucket, type WalletLifetimeDeltaV1, type WalletLifetimeSnapshotV1, type WalletLifetimeTotalsV1, type WalletOwnerReferenceV1, type WalletOwnerType, type WalletPortfolioBalanceComponentV1, type WalletPortfolioComponentRole, type WalletPortfolioComponentScopeV1, type WalletPortfolioLifetimeComponentV1, type WalletPortfolioLifetimeV1, type WalletPortfolioReadScopeV1, type WalletPortfolioSummaryV1, type WalletPostingAccountBindingV1, type WalletProjectionBucket, type WalletStatus, type WalletV1, type WorkflowActivityStatusV1, type WorkflowWalletActivityEntryV1, advanceJournalChainHead, applySourceLotMovement, applyTransactionToProjection, applyWalletBalanceDelta, applyWalletLifetimeDeltas, assertActivityEntry, assertBalancedTransaction, assertDeterministicWalletBalanceSummary, assertDistinctAdjustmentApproval, assertEconomicJournalTransaction, assertEconomyCommandEnvelope, assertEconomyCommandWorkflowEvent, assertEconomyIdempotencyScope, assertEconomyIdentifier, assertFlatTokenCatalog, assertFxSnapshot, assertGameplayAllocation, assertJournalChainHead, assertNonNegativeAccounts, assertOpenPurchaseIntent, assertPurchaseIntentBinding, assertPurchaseLimitPolicy, assertReversalAvailable, assertRewardConversion, assertRewardRate, assertScopedPersistedIdempotencyResult, assertSourceLot, assertSourceLotMovement, assertSpendRequest, assertTokenPack, assertTokenReferenceRate, assertTokenSubscriptionPlan, assertVersionedSourceLot, assertWallet, assertWalletActivityEntry, assertWalletActivityPage, assertWalletActivityPageForPortfolio, assertWalletActivityPageRequest, assertWalletBalanceDelta, assertWalletBalanceDeltaBatch, assertWalletBalanceProjection, assertWalletBalanceSummary, assertWalletLifetimeSnapshot, assertWalletLifetimeTotals, assertWalletOwnerReference, assertWalletPortfolioLifetime, assertWalletPortfolioReadScope, assertWalletPortfolioSummary, availableSourceLotAmount, boostGameplayAllocation, canUseSourceLot, canonicalTransactionPayload, convertRewardPayout, createGameplayAllocation, createInitialSourceLotSnapshot, createProjectionSnapshot, createReversalTransaction, createWalletBalanceSummary, createWalletPortfolioLifetime, createWalletPortfolioSummary, deriveWalletBalanceDeltas, deriveWalletLifetimeDeltas, economyAssert, evaluateEarlyBacker, evaluateEarlyBackerBySettlementV2, isWholeTokenAmount, mapBitLabsConversionState, parseIsoTimestamp, parseTokenSubunits, rebuildBalanceProjection, reclaimGameplayAllocation, selectSourceLots, serializeTokenSubunits, sortStringRecord, subunitsToWholeTokens, sumTokenSubunits, toEconomyErrorEnvelope, wholeTokensToSubunits };
1410
+ export { type AccountId, type ActivityEntryV1, type ActivityStatus, type ActivityType, type AdjustmentRequestV1, type AdjustmentStatus, type AllocationId, type AllocationStatus, BASELINE_GBP_CATALOG_VERSION, BASELINE_GBP_REFERENCE_RATE, BASELINE_GBP_TOKEN_PACKS, BASELINE_MONTHLY_SUBSCRIPTION_PLAN, BASELINE_PURCHASE_LIMIT_POLICY, type BalanceProjection, type BalanceProjectionSnapshotV1, type BitLabsConversionState, type BoostGameplayAllocationInputV1, type ChainedEconomicJournalTransactionV1, type CloseModuleAllowanceInputV1, type CreateGameplayAllocationInputV1, type CreateModuleAllowanceInputV1, type CreateModulePurchaseReceiptInputV1, type CreateModuleSpendHoldInputV1, type CreateModuleSpendQuoteInputV1, EARLY_BACKER_SETTLEMENT_POLICY_V2, ECONOMY_CONTRACT_VERSION, type EarlyBackerEvaluationV1, type EarlyBackerEvaluationV2, type EarlyBackerWindowV1, type EconomicActivityStatusV1, type EconomicJournalStatus, type EconomicJournalTransactionV1, type EconomicWalletActivityEntryV1, type EconomyClockPort, type EconomyCommandEnvelopeV1, type EconomyCommandType, type EconomyCommandWorkflowEventV1, type EconomyCommandWorkflowStateV1, type EconomyContractVersion, EconomyError, type EconomyErrorCode, type EconomyErrorEnvelopeV1, type EconomyIdPort, type EconomyIdempotencyScopeV1, type EconomyOutboxEventV1, type EconomyPersistencePort, type EconomyPersistencePortV2, type EconomyQueryPortV1, type EconomyUnitOfWork, type EconomyUnitOfWorkV2, type FundModuleAllowanceInputV1, type FxSnapshotV1, type GameplayAllocationV1, type GameplayLimitsV1, type GbpMinorUnitString, type HouseholdId, type IsoTimestamp, type JournalChainHeadV1, type JournalChainId, type LearningEntitlementId, type LearningModuleVersionId, type LedgerPostingV1, type LedgerTransactionV1, type LotId, type LotRefundState, type LotTransferPolicy, type LotUseContextV1, type LotUseOperation, MODULE_ALLOWANCE_PURPOSE, type ModuleAllowanceId, type ModuleAllowanceStatusV1, type ModuleAllowanceV1, type ModulePurchaseEntitlementStateV1, type ModulePurchaseFinancialStateV1, type ModulePurchaseReceiptV1, type ModulePurchaseReconciliationActionV1, type ModulePurchaseReconciliationObservationV1, type ModulePurchaseReconciliationResultV1, type ModuleSpendHoldId, type ModuleSpendHoldStatusV1, type ModuleSpendHoldV1, type ModuleSpendQuoteId, type ModuleSpendQuoteV1, type ModuleSpendTransitionResultV1, PRE_UTILITY_BACKER_COHORT, type PaidLotLifecycleArithmeticV1, type PaidLotLifecycleEventTypeV1, type PaidLotLifecycleEventV1, type PaidLotLifecycleMutationResultV1, type PaidLotLifecycleReceiptV1, type PaidLotLifecycleStatusV1, type PaidLotLifecycleV1, type PaidLotPurchaseProvenanceV1, type PaidLotRetentionV1, type PeriodicLimitWindow, type PersistedIdempotencyResultV1, type PostingId, type ProviderEventId, type PurchaseCapMutationResultV1, type PurchaseCapReservationStatusV1, type PurchaseCapReservationTransitionReceiptV1, type PurchaseCapReservationTransitionTypeV1, type PurchaseCapReservationTransitionV1, type PurchaseCapReservationV1, type PurchaseCapScopeTypeV1, type PurchaseCreditInstructionV1, type PurchaseIntentDisputeDispositionV1, type PurchaseIntentLifecycleV1, type PurchaseIntentReductionV1, type PurchaseIntentStatus, type PurchaseIntentTransitionReceiptV1, type PurchaseIntentTransitionResultV1, type PurchaseIntentTransitionTypeV1, type PurchaseIntentTransitionV1, type PurchaseIntentV1, type PurchaseLimitPolicyV1, type ReclaimGameplayAllocationInputV1, type ReclaimModuleAllowanceInputV1, type RecurrenceInterval, type ReleaseModuleSpendHoldInputV1, type ReservePurchaseCapsCommandV1, type ReversalInputV1, type RewardActivityTransitionV1, type RewardConversionStatus, type RewardConversionV1, type RewardRateV1, type RollingPurchaseCapStateV1, type ScopedPersistedIdempotencyResultV1, type SettleModuleSpendHoldInputV1, type SourceLotMovementType, type SourceLotMovementV1, type SourceLotSliceV1, type SourceLotV1, type SpendRequestPurpose, type SpendRequestStatus, type SpendRequestV1, TOKEN_SUBUNITS_MAX, TOKEN_SUBUNITS_MIN, TOKEN_SUBUNITS_PER_TOKEN, type TokenPackV1, type TokenReferenceRateV1, type TokenSource, type TokenSubscriptionPlanV1, type TokenSubunitString, type TransactionId, type VersionedSourceLotV1, type WalletActivityEntryV1, type WalletActivityFilterV1, type WalletActivityPageRequestV1, type WalletActivityPageV1, type WalletActivityStatusV1, type WalletBalanceDeltaV1, type WalletBalanceProjectionV1, type WalletBalanceSummaryV1, type WalletBalanceTotalsV1, type WalletId, type WalletKind, type WalletLifetimeBucket, type WalletLifetimeDeltaV1, type WalletLifetimeSnapshotV1, type WalletLifetimeTotalsV1, type WalletOwnerReferenceV1, type WalletOwnerType, type WalletPortfolioBalanceComponentV1, type WalletPortfolioComponentRole, type WalletPortfolioComponentScopeV1, type WalletPortfolioLifetimeComponentV1, type WalletPortfolioLifetimeV1, type WalletPortfolioReadScopeV1, type WalletPortfolioSummaryV1, type WalletPostingAccountBindingV1, type WalletProjectionBucket, type WalletStatus, type WalletV1, type WorkflowActivityStatusV1, type WorkflowWalletActivityEntryV1, advanceJournalChainHead, applyPaidLotLifecycleEvent, applyPurchaseIntentTransition, applySourceLotMovement, applyTransactionToProjection, applyWalletBalanceDelta, applyWalletLifetimeDeltas, assertActivityEntry, assertBalancedTransaction, assertDeterministicWalletBalanceSummary, assertDistinctAdjustmentApproval, assertEconomicJournalTransaction, assertEconomyCommandEnvelope, assertEconomyCommandWorkflowEvent, assertEconomyIdempotencyScope, assertEconomyIdentifier, assertFlatTokenCatalog, assertFxSnapshot, assertGameplayAllocation, assertJournalChainHead, assertModuleAllowance, assertModulePurchaseReceipt, assertModulePurchaseReconciliationObservation, assertModuleSpendHold, assertModuleSpendQuote, assertNonNegativeAccounts, assertOpenPurchaseIntent, assertPaidLotLifecycle, assertPaidLotLifecycleEvent, assertPaidLotPurchaseProvenance, assertPurchaseCapReservation, assertPurchaseCapReservationTransition, assertPurchaseIntentBinding, assertPurchaseIntentLifecycle, assertPurchaseIntentTransition, assertPurchaseLimitPolicy, assertReversalAvailable, assertRewardConversion, assertRewardRate, assertRollingPurchaseCapState, assertScopedPersistedIdempotencyResult, assertSourceLot, assertSourceLotMovement, assertSpendRequest, assertTokenPack, assertTokenReferenceRate, assertTokenSubscriptionPlan, assertVersionedSourceLot, assertWallet, assertWalletActivityEntry, assertWalletActivityPage, assertWalletActivityPageForPortfolio, assertWalletActivityPageRequest, assertWalletBalanceDelta, assertWalletBalanceDeltaBatch, assertWalletBalanceProjection, assertWalletBalanceSummary, assertWalletLifetimeSnapshot, assertWalletLifetimeTotals, assertWalletOwnerReference, assertWalletPortfolioLifetime, assertWalletPortfolioReadScope, assertWalletPortfolioSummary, availableSourceLotAmount, boostGameplayAllocation, calculateRollingPurchaseCapUsage, canUseSourceLot, canonicalTransactionPayload, closeModuleAllowance, convertRewardPayout, createEarlyBackerRetentionFromPaidLot, createGameplayAllocation, createInitialSourceLotSnapshot, createModuleAllowance, createModulePurchaseReceipt, createModuleSpendHold, createModuleSpendQuote, createPaidLotLifecycle, createProjectionSnapshot, createPurchaseIntentLifecycle, createReversalTransaction, createRollingPurchaseCapState, createWalletBalanceSummary, createWalletPortfolioLifetime, createWalletPortfolioSummary, deriveWalletBalanceDeltas, deriveWalletLifetimeDeltas, economyAssert, evaluateEarlyBacker, evaluateEarlyBackerBySettlementV2, fundModuleAllowance, isWholeTokenAmount, mapBitLabsConversionState, parseGbpMinorUnits, parseIsoTimestamp, parseTokenSubunits, rebuildBalanceProjection, reclaimGameplayAllocation, reclaimModuleAllowance, reconcileModulePurchase, reducePaidLotLifecycleEvents, reducePurchaseIntentTransitions, releaseModuleSpendHold, reserveRollingPurchaseCaps, selectSourceLots, serializeGbpMinorUnits, serializeTokenSubunits, settleModuleSpendHold, sortStringRecord, subunitsToWholeTokens, sumTokenSubunits, toEconomyErrorEnvelope, transitionRollingPurchaseCapReservation, wholeTokensToSubunits };