@plasius/economy 0.2.0 → 0.3.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/README.md +66 -5
- package/dist/index.cjs +1411 -155
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +428 -20
- package/dist/index.d.ts +428 -20
- package/dist/index.js +1378 -155
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -53,6 +53,13 @@ reject non-string JSON values rather than coercing numbers into wire amounts.
|
|
|
53
53
|
display-oriented `sourceLabel`. Filters and reconciliation must use `source`;
|
|
54
54
|
localized UI must use `sourceLabel`.
|
|
55
55
|
|
|
56
|
+
New read adapters should return the discriminated `WalletActivityEntryV1`.
|
|
57
|
+
`economic` rows may be `held`, `settled`, or read-model-derived `reversed`;
|
|
58
|
+
`workflow` rows alone may be `pending` or `failed`. The additive
|
|
59
|
+
`EconomicJournalTransactionV1` narrows immutable journal writes to `held` or
|
|
60
|
+
`settled`. A reversed display state is derived from a compensating transaction;
|
|
61
|
+
the original journal row is never rewritten.
|
|
62
|
+
|
|
56
63
|
## Baseline GBP catalog
|
|
57
64
|
|
|
58
65
|
`BASELINE_GBP_REFERENCE_RATE` is versioned product-copy metadata with
|
|
@@ -128,12 +135,27 @@ the source rows, revalidate them, append the balanced transaction, update the
|
|
|
128
135
|
projection, save idempotency evidence, and append the outbox event within one
|
|
129
136
|
serializable database transaction.
|
|
130
137
|
|
|
138
|
+
`VersionedSourceLotV1` and `SourceLotMovementV1` make allocation, boost,
|
|
139
|
+
reclaim, spend, hold, release, refund, chargeback, and reversal changes explicit.
|
|
140
|
+
`applySourceLotMovement()` proves the signed amount deltas, refund-state
|
|
141
|
+
transition, and exact optimistic-version increment. A V2 persistence adapter
|
|
142
|
+
must append the movement evidence and compare-and-swap the projection as one
|
|
143
|
+
operation.
|
|
144
|
+
|
|
131
145
|
## Early backers
|
|
132
146
|
|
|
133
147
|
`evaluateEarlyBacker()` calculates provisional `pre_utility_backer_v1` status
|
|
134
148
|
from net retained paid lots. It uses an inclusive public launch and exclusive
|
|
135
149
|
first-public-spend cutoff. It does not express or promise a reward entitlement.
|
|
136
150
|
|
|
151
|
+
Existing `evaluateEarlyBacker()` behavior is preserved for V1 consumers. The
|
|
152
|
+
approved additive `evaluateEarlyBackerBySettlementV2()` policy treats
|
|
153
|
+
`settledAt` as the sole inclusive-launch/exclusive-cutoff qualification event;
|
|
154
|
+
purchase and credit timestamps remain ordering/provenance facts. It ignores
|
|
155
|
+
settlements after `evaluatedAt`. The caller must derive both window timestamps
|
|
156
|
+
from the entire public cohort and exclude non-production/test lots: staff,
|
|
157
|
+
closed-beta, and test availability must never open or close the public window.
|
|
158
|
+
|
|
137
159
|
## Acquisition and future contracts
|
|
138
160
|
|
|
139
161
|
Purchase intents bind payer, receiving household/wallet, pack, catalog,
|
|
@@ -150,15 +172,54 @@ to household-allocatable is rejected.
|
|
|
150
172
|
monthly/100 Token shape with `enabled: false`. Spend-request contracts likewise
|
|
151
173
|
exist for future use but this package does not enable their creation.
|
|
152
174
|
|
|
175
|
+
## Balance, lifetime, and portfolio reads
|
|
176
|
+
|
|
177
|
+
`WalletBalanceProjectionV1` stores exclusive `spendable`, `reserved`, and
|
|
178
|
+
`held` buckets. `createWalletBalanceSummary()` splits each wallet's spendable
|
|
179
|
+
amount into independently usable whole-Token `available` value and a
|
|
180
|
+
sub-Token `rewardProgress` remainder. `WalletBalanceDeltaV1` is an atomic add,
|
|
181
|
+
never an absolute balance replacement.
|
|
182
|
+
|
|
183
|
+
Lifetime counters are monotonic gross flows. Settled purchase/subscription
|
|
184
|
+
credits add to `bought`; rewarded-ad, offerwall, event, and competition credits
|
|
185
|
+
add to `earned`; source-wallet allocation/boost debits add to `allocated`;
|
|
186
|
+
returns add to `reclaimed`; spend debits add to `spent`; and refund,
|
|
187
|
+
chargeback, or reversal debits add to `reversed`. A reversal does not subtract
|
|
188
|
+
from the earlier bought/earned counter.
|
|
189
|
+
|
|
190
|
+
`EconomyQueryPortV1` keeps single-wallet reads and introduces an explicit
|
|
191
|
+
`WalletPortfolioReadScopeV1`. A host portfolio may contain both a household
|
|
192
|
+
treasury and a same-user-only personal reward wallet, and every component keeps
|
|
193
|
+
its wallet ID, role, beneficiary, summary, and lifetime snapshot. Portfolio
|
|
194
|
+
totals are display-only column sums: progress is deliberately not promoted
|
|
195
|
+
across wallets, even if the sum reaches 1,000 TokenSubunits, because source and
|
|
196
|
+
transfer restrictions may differ. Authorization must happen before the server
|
|
197
|
+
constructs a portfolio scope.
|
|
198
|
+
|
|
199
|
+
Activity reads use bounded opaque cursor pagination in stable descending
|
|
200
|
+
`(occurredAt, activityId)` order. Each row retains the component `walletId`
|
|
201
|
+
whose signed display amount it represents. Cursor contents and signatures are
|
|
202
|
+
adapter concerns; `assertWalletActivityPageForPortfolio()` proves that a result
|
|
203
|
+
never expands the authorized portfolio scope.
|
|
204
|
+
|
|
153
205
|
## Persistence ports
|
|
154
206
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
207
|
+
`EconomyPersistencePort` remains exported unchanged for existing consumers.
|
|
208
|
+
New authoritative services should implement `EconomyPersistencePortV2`, whose
|
|
209
|
+
unit of work deliberately omits V1's whole-projection overwrite. Runtime roles
|
|
210
|
+
should execute approved posting procedures but must not update or delete
|
|
211
|
+
journal rows directly. The V2 adapter is responsible for:
|
|
158
212
|
|
|
159
213
|
- serializable row locking and optimistic versions;
|
|
160
|
-
-
|
|
161
|
-
|
|
214
|
+
- exact owner-constrained wallet access and household/child-constrained
|
|
215
|
+
allocation compare-and-swap;
|
|
216
|
+
- immutable accepted-command and workflow-event append;
|
|
217
|
+
- actor/subject/command-scoped idempotency plus unique transaction and
|
|
218
|
+
provider-event constraints;
|
|
219
|
+
- active regional writer-fence validation and locked canonical chain-head
|
|
220
|
+
extension;
|
|
221
|
+
- atomic wallet balance and monotonic lifetime deltas;
|
|
222
|
+
- atomic source-lot movement append, refund-state update, and version advance;
|
|
162
223
|
- transactional outbox append;
|
|
163
224
|
- managed identity and least-privilege database access; and
|
|
164
225
|
- immutable audit/integrity evidence outside this package.
|