@hyperscale0/hsx 1.0.125 → 1.0.130

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 (43) hide show
  1. package/README.md +2 -2
  2. package/dist/src/cli.js +1 -1
  3. package/dist/src/cli.js.map +1 -1
  4. package/dist/src/compile.d.ts.map +1 -1
  5. package/dist/src/compile.js +155 -21
  6. package/dist/src/compile.js.map +1 -1
  7. package/dist/src/examples-bundle.js +9 -9
  8. package/dist/src/examples-bundle.js.map +1 -1
  9. package/dist/src/headers.d.ts +1 -1
  10. package/dist/src/headers.d.ts.map +1 -1
  11. package/dist/src/headers.js +1 -0
  12. package/dist/src/headers.js.map +1 -1
  13. package/dist/src/parse.js +4 -1
  14. package/dist/src/parse.js.map +1 -1
  15. package/dist/src/std-bundle.d.ts.map +1 -1
  16. package/dist/src/std-bundle.js +8 -7
  17. package/dist/src/std-bundle.js.map +1 -1
  18. package/docs/README.md +102 -50
  19. package/examples/cards.hsx +4 -0
  20. package/examples/collections.hsx +5 -1
  21. package/examples/cost-table.json +80 -56
  22. package/examples/financing.hsx +1 -1
  23. package/examples/insurance.hsx +5 -4
  24. package/examples/lending.hsx +1 -1
  25. package/examples/library.hsx +1 -1
  26. package/examples/rental-deposit.hsx +1 -1
  27. package/examples/reporting.hsx +1 -1
  28. package/examples/serviced.hsx +1 -1
  29. package/package.json +4 -4
  30. package/src/cli.ts +1 -1
  31. package/src/compile.ts +223 -27
  32. package/src/examples-bundle.ts +9 -9
  33. package/src/headers.ts +1 -0
  34. package/src/parse.ts +4 -1
  35. package/src/std-bundle.ts +8 -7
  36. package/std/booking.hsx +75 -0
  37. package/std/cards.hsx +5 -3
  38. package/std/escrow.hsx +35 -9
  39. package/std/financing.hsx +158 -36
  40. package/std/insurance.hsx +9 -5
  41. package/std/marketplace.hsx +3 -3
  42. package/std/money.hsx +3 -3
  43. package/std/wallet.hsx +20 -9
package/std/insurance.hsx CHANGED
@@ -4,7 +4,11 @@ header insurance
4
4
  // Outside broker commissions are pass-through. Adapter-owned premium and claim
5
5
  // accounts lack an authored source party, so their moves remain unclassified.
6
6
 
7
- // Expose cover.create, activate and cancel separately. Activation binds adapter;
7
+ // Expose cover.create, activate and cancel separately. The adapter names a
8
+ // registered boundary adapter (conformance_boundary in sandbox). covers is an
9
+ // optional link to a sibling attachment; the attached object is already the
10
+ // insured thing. claim_limit is the sum insured: approved and paid claims on one
11
+ // cover never total more. Activation binds adapter;
8
12
  // each slice needs a separately created unique period and an active cover to collect.
9
13
  // Collection debits holder for insurerPremium to the insurer and commission to
10
14
  // broker as two moves. Broker defaults to programOperator; bind a declared business
@@ -23,9 +27,9 @@ header insurance
23
27
  // reserves once; pay posts once and expiry voids once. Cover cancellation adds
24
28
  // bounded slice invocations. Run hsx cost for composed counts, not provider prices.
25
29
 
26
- instrument cover(holder: party, adapter: text, commission: percent = 0%, broker: party = programOperator, covers: ref, premium: money = runtime) {
30
+ instrument cover(holder: party, adapter: text, commission: percent = 0%, broker: party = programOperator, covers: ref?, premium: money = runtime, claim_limit: money = runtime) {
27
31
  summary: "Recurring cover bound to an outside insurer across an ADL boundary."
28
- fields { covers: ref<covers>, holder: account of holder, insurer: account(adapter(adapter), cash, "premium"), expiresAt: date }
32
+ fields { covers: ref<covers>?, holder: account of holder, insurer: account(adapter(adapter), cash, "premium"), expiresAt: date, claimLimit: money = claim_limit }
29
33
  lifecycle { states: [pending, active, cancelled, expired], initial: pending }
30
34
  action create {}
31
35
  action activate {
@@ -41,13 +45,12 @@ instrument cover(holder: party, adapter: text, commission: percent = 0%, broker:
41
45
  slice: {
42
46
  summary: "A whole premium period, collected once and refundable only before it starts."
43
47
  fields {
44
- cover: ref<parent>, covers: ref<covers>, premium: money = premium, startsAt: date, endsAt: date
48
+ cover: ref<parent>, premium: money = premium, startsAt: date, endsAt: date
45
49
  commission: money = rate(self.premium, commission)
46
50
  insurerPremium: money = subtract(self.premium, self.commission), commissionReceipt: text?
47
51
  }
48
52
  lifecycle { states: [pending, paid, active, expired, refunded], initial: pending }
49
53
  action create {
50
- requires self.covers == self.cover.covers
51
54
  requires self.startsAt < self.endsAt
52
55
  requires unique "premium_period" on [self.cover, self.startsAt, self.endsAt]
53
56
  }
@@ -76,6 +79,7 @@ instrument claim(cover: ref<insurance.cover>, inspector: party) {
76
79
  summary: "A claim decision reserves one claim payment before settlement."
77
80
  fields { cover: ref<cover>, amount: money, expiresAt: date, evidence: text, reservation: text? }
78
81
  lifecycle { states: [submitted, approved, paid, denied, expired], initial: submitted }
82
+ invariants sum "amount" of { instrument: current(), reference: "cover", anchor: self.cover, states: [approved, paid], limit: 366 } <= self.cover.claimLimit
79
83
  action create { requires self.cover in [active] }
80
84
  action approve {
81
85
  from: submitted, to: approved
@@ -1,7 +1,7 @@
1
1
  header marketplace
2
2
 
3
3
  // Economics: Deposit funding, escrow credit and returns are principal. Retention is
4
- // earning for the company or a payout to a bound outside recipient.
4
+ // earning for the company or passes the buyer's cash through to a bound outside recipient.
5
5
 
6
6
  // Listing, order and reservation are separate agreements. Expose their create
7
7
  // and decision actions individually. Order fulfillment does not move escrow cash.
@@ -100,7 +100,7 @@ instrument reservation(listing: ref<marketplace.listing>, funds: ref<escrow.hold
100
100
  from: active, to: cancelled, actor: { party: buyer }, input { reason: text }
101
101
  calculate: [{ target: refund, op: rate, base: { field: self.held.balance }, bps: { literal: cancellation_refund }, rounding: floor }, { target: retained, op: subtract, base: { field: self.held.balance }, subtract: [{ field: self.refund }] }]
102
102
  set: { reason: { field: input.reason }, dispositionAt: { field: self.now } }
103
- moves self.refund from self.held to self.buyer economics { purpose: principal, sourceParty: programOperator }; moves self.retained from self.held to retained_to economics { recipient: retained_to, company: { purpose: earning, sourceParty: buyer }, participant: { purpose: participant_payout, sourceParty: programOperator } }
103
+ moves self.refund from self.held to self.buyer economics { purpose: principal, sourceParty: programOperator }; moves self.retained from self.held to retained_to economics { recipient: retained_to, company: { purpose: earning, sourceParty: buyer }, participant: { purpose: pass_through, sourceParty: programOperator } }
104
104
  }
105
105
  action seller_cancel {
106
106
  from: active, to: cancelled, actor: { party: seller }, input { reason: text }
@@ -117,7 +117,7 @@ instrument reservation(listing: ref<marketplace.listing>, funds: ref<escrow.hold
117
117
  from: active, to: expired, actor: clock, due: { at: self.expiresAt }
118
118
  calculate: [{ target: refund, op: rate, base: { field: self.held.balance }, bps: { literal: expiry_refund }, rounding: floor }, { target: retained, op: subtract, base: { field: self.held.balance }, subtract: [{ field: self.refund }] }]
119
119
  set: { dispositionAt: { field: self.now } }
120
- moves self.refund from self.held to self.buyer economics { purpose: principal, sourceParty: programOperator }; moves self.retained from self.held to retained_to economics { recipient: retained_to, company: { purpose: earning, sourceParty: buyer }, participant: { purpose: participant_payout, sourceParty: programOperator } }
120
+ moves self.refund from self.held to self.buyer economics { purpose: principal, sourceParty: programOperator }; moves self.retained from self.held to retained_to economics { recipient: retained_to, company: { purpose: earning, sourceParty: buyer }, participant: { purpose: pass_through, sourceParty: programOperator } }
121
121
  }
122
122
  action expire_proposal { from: proposed, to: expired, actor: clock, due: { at: self.proposalExpiresAt } }
123
123
  }
package/std/money.hsx CHANGED
@@ -1,7 +1,7 @@
1
1
  header money
2
2
 
3
3
  // Economics: Held funding and returns are principal. Release to the company realizes
4
- // earnings; release to another participant is a payout. Generic transfers, splits,
4
+ // earnings; release to another participant passes the payer's cash through. Generic transfers, splits,
5
5
  // schedules, swaps, boundary payouts and metered fees retain no assumed purpose.
6
6
 
7
7
  // Expose each attachment's create and caller actions explicitly. A transfer or
@@ -48,7 +48,7 @@ instrument hold(payer: party, payee: party, amount: money = runtime) {
48
48
  }
49
49
  action release {
50
50
  from: funded, to: released, actor: { party: payer }
51
- moves self.amount from self.held to payee economics { recipient: payee, company: { purpose: earning, sourceParty: payer }, participant: { purpose: participant_payout, sourceParty: programOperator } }
51
+ moves self.amount from self.held to payee economics { recipient: payee, company: { purpose: earning, sourceParty: payer }, participant: { purpose: pass_through, sourceParty: programOperator } }
52
52
  }
53
53
  action refund {
54
54
  from: funded, to: refunded, actor: { party: payee }
@@ -107,7 +107,7 @@ instrument pool(payer: party, payee: party, target: money, closes: date) {
107
107
  action pay {
108
108
  from: open, to: paid, actor: { party: payee }
109
109
  requires self.held.balance == self.target
110
- moves self.target from self.held to payee economics { recipient: payee, company: { purpose: earning, sourceParty: payer }, participant: { purpose: participant_payout, sourceParty: programOperator } }
110
+ moves self.target from self.held to payee economics { recipient: payee, company: { purpose: earning, sourceParty: payer }, participant: { purpose: pass_through, sourceParty: programOperator } }
111
111
  }
112
112
  action fail {
113
113
  from: open, to: failed, actor: clock, due: { at: self.closesAt }
package/std/wallet.hsx CHANGED
@@ -1,39 +1,50 @@
1
1
  header wallet
2
2
 
3
- // Economics: Topups and withdrawals are excluded prepaid credit. Spending remains
3
+ // Economics: Topups and withdrawals are excluded prepaid credit; a top-up fee is
4
+ // Company earning. Spending remains
4
5
  // unclassified because the bound payee alone does not state the purchase purpose.
5
6
 
6
7
  // Expose balance.create, activate, topup and withdraw as needed. Holder moves
7
8
  // cash only while active. Freeze blocks new topups, withdrawals and spend reserves;
8
- // close requires no held cash. Freeze/unfreeze use caller operation authority.
9
+ // close requires no held cash. Only the Product operator freezes or unfreezes.
9
10
  // A separate spend record checks its amount against spendLimit at creation.
10
11
  // Expose reserve, pay and cancel for the bound payee. Reserve requires an active
11
12
  // wallet before expiresAt; pay posts the whole reservation, cancel/expiry void it.
12
13
  // Existing reservations may still post after the wallet freezes. There is no
13
14
  // daily aggregate limit, partial spend or card-network settlement in this header.
14
15
 
15
- // Cost: balance.create declares one owned account; topup and withdraw each
16
- // declare one transfer. Spend reserve, pay and cancel each declare one transfer
16
+ // Top-up fee: topup_fee takes a floored percentage of each top-up for the Company;
17
+ // the wallet receives the rest. At 1%, a 100.00 top-up credits 99.00 and earns 1.00.
18
+ // The default 0% moves nothing to the Company.
19
+
20
+ // Cost: balance.create declares one owned account; topup declares two transfers
21
+ // and withdraw one. Spend reserve, pay and cancel each declare one transfer
17
22
  // instruction. These are counts, not the executor tariff.
18
23
 
19
- instrument balance(holder: party, spend_limit: money = 100000 SAR) {
24
+ instrument balance(holder: party, spend_limit: money = 100000 SAR, topup_fee: percent = 0%) {
20
25
  summary: "A holder's reusable balance with an immutable per-spend ceiling."
21
- fields { holder: account of holder, held: account of self, spendLimit: money = spend_limit }
26
+ fields { holder: account of holder, held: account of self, spendLimit: money = spend_limit, topupFee: money?, topupCredit: money? }
22
27
  lifecycle { states: [pending, active, frozen, closed], initial: pending }
23
28
  action create { }
24
29
  action activate { from: pending, to: active, actor: { party: holder } }
25
30
  action topup {
31
+ allowZero: true, requires input.amount > "0"
26
32
  from: active, to: active, actor: { party: holder }
27
33
  input { amount: money }
28
- moves input.amount from holder to self.held economics { purpose: prepaid_credit, sourceParty: holder }
34
+ calculate: [
35
+ { target: topupFee, op: rate, base: { field: input.amount }, bps: { literal: topup_fee }, rounding: floor }
36
+ { target: topupCredit, op: subtract, base: { field: input.amount }, subtract: [{ field: self.topupFee }] }
37
+ ]
38
+ moves self.topupCredit from holder to self.held economics { purpose: prepaid_credit, sourceParty: holder }
39
+ moves self.topupFee from holder to programOperator economics { purpose: earning, sourceParty: holder }
29
40
  }
30
41
  action withdraw {
31
42
  from: active, to: active, actor: { party: holder }
32
43
  input { amount: money }
33
44
  moves input.amount from self.held to holder economics { purpose: prepaid_credit, sourceParty: programOperator }
34
45
  }
35
- action freeze { from: active, to: frozen, }
36
- action unfreeze { from: frozen, to: active, }
46
+ action freeze { from: active, to: frozen, actor: { party: programOperator } }
47
+ action unfreeze { from: frozen, to: active, actor: { party: programOperator } }
37
48
  action close { from: [pending, active], to: closed, requires self.held.balance == "0" }
38
49
  }
39
50