@plasius/economy 0.1.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 +73 -6
- package/dist/index.cjs +1431 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +476 -66
- package/dist/index.d.ts +476 -66
- package/dist/index.js +1398 -161
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,7 +45,20 @@ const restored = parseTokenSubunits(wireAmount); // 50000n
|
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
Non-canonical values such as `"01"`, decimals, exponent notation, and values
|
|
48
|
-
outside signed PostgreSQL `bigint` range are rejected.
|
|
48
|
+
outside signed PostgreSQL `bigint` range are rejected. Runtime validators also
|
|
49
|
+
reject non-string JSON values rather than coercing numbers into wire amounts.
|
|
50
|
+
|
|
51
|
+
`ActivityEntryV1` contains both a stable `source` (`shopify`, `ayet`, `bitlabs`,
|
|
52
|
+
`subscription`, `event`, `competition`, or `adjustment`) and a bounded
|
|
53
|
+
display-oriented `sourceLabel`. Filters and reconciliation must use `source`;
|
|
54
|
+
localized UI must use `sourceLabel`.
|
|
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.
|
|
49
62
|
|
|
50
63
|
## Baseline GBP catalog
|
|
51
64
|
|
|
@@ -122,12 +135,27 @@ the source rows, revalidate them, append the balanced transaction, update the
|
|
|
122
135
|
projection, save idempotency evidence, and append the outbox event within one
|
|
123
136
|
serializable database transaction.
|
|
124
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
|
+
|
|
125
145
|
## Early backers
|
|
126
146
|
|
|
127
147
|
`evaluateEarlyBacker()` calculates provisional `pre_utility_backer_v1` status
|
|
128
148
|
from net retained paid lots. It uses an inclusive public launch and exclusive
|
|
129
149
|
first-public-spend cutoff. It does not express or promise a reward entitlement.
|
|
130
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
|
+
|
|
131
159
|
## Acquisition and future contracts
|
|
132
160
|
|
|
133
161
|
Purchase intents bind payer, receiving household/wallet, pack, catalog,
|
|
@@ -144,15 +172,54 @@ to household-allocatable is rejected.
|
|
|
144
172
|
monthly/100 Token shape with `enabled: false`. Spend-request contracts likewise
|
|
145
173
|
exist for future use but this package does not enable their creation.
|
|
146
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
|
+
|
|
147
205
|
## Persistence ports
|
|
148
206
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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:
|
|
152
212
|
|
|
153
213
|
- serializable row locking and optimistic versions;
|
|
154
|
-
-
|
|
155
|
-
|
|
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;
|
|
156
223
|
- transactional outbox append;
|
|
157
224
|
- managed identity and least-privilege database access; and
|
|
158
225
|
- immutable audit/integrity evidence outside this package.
|