@hyperscale0/hsx 1.0.128 → 1.0.132
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/src/cli.js +1 -1
- package/dist/src/cli.js.map +1 -1
- package/dist/src/compile.d.ts.map +1 -1
- package/dist/src/compile.js +173 -23
- package/dist/src/compile.js.map +1 -1
- package/dist/src/examples-bundle.js +6 -6
- package/dist/src/examples-bundle.js.map +1 -1
- package/dist/src/parse.js +4 -1
- package/dist/src/parse.js.map +1 -1
- package/dist/src/std-bundle.js +10 -10
- package/dist/src/std-bundle.js.map +1 -1
- package/docs/README.md +78 -27
- package/examples/cards.hsx +7 -1
- package/examples/collections.hsx +4 -0
- package/examples/cost-table.json +80 -56
- package/examples/insurance.hsx +2 -1
- package/examples/marketplace.hsx +3 -1
- package/examples/rental-deposit.hsx +2 -0
- package/examples/wallet.hsx +1 -1
- package/package.json +4 -4
- package/src/cli.ts +1 -1
- package/src/compile.ts +246 -23
- package/src/examples-bundle.ts +6 -6
- package/src/parse.ts +4 -1
- package/src/std-bundle.ts +10 -10
- package/std/booking.hsx +1 -1
- package/std/cards.hsx +20 -11
- package/std/escrow.hsx +45 -10
- package/std/financing.hsx +214 -62
- package/std/insurance.hsx +3 -3
- package/std/lending.hsx +16 -8
- package/std/marketplace.hsx +4 -3
- package/std/money.hsx +28 -14
- package/std/savings.hsx +3 -2
- package/std/wallet.hsx +13 -8
package/std/booking.hsx
CHANGED
|
@@ -21,7 +21,7 @@ header booking
|
|
|
21
21
|
// cancellation and completion move the held balance. Run hsx cost for the
|
|
22
22
|
// composed counts.
|
|
23
23
|
|
|
24
|
-
instrument reservation(customer: party = party(person), operator: party = programOperator, early_until: duration = 30d, late_from: duration = 15d, balance_due: duration =
|
|
24
|
+
instrument reservation(customer: party = party(person), operator: party = programOperator, early_until: duration = 30d, late_from: duration = 15d, balance_due: duration = 15d, middle_forfeit: percent = 0%, late_forfeit: percent = 0%) {
|
|
25
25
|
revisioned: true
|
|
26
26
|
summary: "Take a deposit and a balance for a dated booking, with cancellation windows before departure."
|
|
27
27
|
fields {
|
package/std/cards.hsx
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
header cards
|
|
2
2
|
|
|
3
3
|
// Activate holder and card before creating and approving an authorization.
|
|
4
|
+
// Only the Product operator activates, suspends or resumes a cardholder; the
|
|
5
|
+
// cardholder or the Product operator closes it. The card's person, bound to the
|
|
6
|
+
// cardholder's holder, freezes, unfreezes and cancels their own card. The issuer
|
|
7
|
+
// freezes it with issuer_freeze into blocked, which only issuer_unfreeze lifts,
|
|
8
|
+
// and cancels it with issuer_cancel.
|
|
4
9
|
// Expose authorization.create, approve and capture; expose decline and reverse
|
|
5
10
|
// separately if callers need those paths. Issuer declines only from pending;
|
|
6
11
|
// merchant captures or reverses an approved reservation. Expiry voids approved
|
|
@@ -21,21 +26,25 @@ instrument cardholder(holder: party) {
|
|
|
21
26
|
fields { holder: account of holder }
|
|
22
27
|
lifecycle { states: [pending, active, suspended, closed], initial: pending }
|
|
23
28
|
action create {}
|
|
24
|
-
action activate { from: pending, to: active }
|
|
25
|
-
action suspend { from: active, to: suspended }
|
|
26
|
-
action resume { from: suspended, to: active }
|
|
27
|
-
action close { from: [active, suspended], to: closed }
|
|
29
|
+
action activate { from: pending, to: active, actor: { party: programOperator } }
|
|
30
|
+
action suspend { from: active, to: suspended, actor: { party: programOperator } }
|
|
31
|
+
action resume { from: suspended, to: active, actor: { party: programOperator } }
|
|
32
|
+
action close { from: [active, suspended], to: closed, actor: { party: holder } }
|
|
33
|
+
action operator_close { from: [active, suspended], to: closed, actor: { party: programOperator } }
|
|
28
34
|
}
|
|
29
35
|
|
|
30
|
-
instrument card(holder: ref<cards.cardholder>, spend_limit: money) {
|
|
36
|
+
instrument card(holder: ref<cards.cardholder>, spend_limit: money, issuer: party = programOperator, person: party = party(person)) {
|
|
31
37
|
summary: "A card with a per-spend ceiling that can be activated, frozen or cancelled."
|
|
32
|
-
fields { holder: ref<holder>, spendLimit: money = spend_limit }
|
|
33
|
-
lifecycle { states: [issued, active, frozen, cancelled], initial: issued }
|
|
34
|
-
action create { requires self.holder in [active] }
|
|
38
|
+
fields { holder: ref<holder>, person: account of person, spendLimit: money = spend_limit }
|
|
39
|
+
lifecycle { states: [issued, active, frozen, blocked, cancelled], initial: issued }
|
|
40
|
+
action create { requires self.holder in [active]; requires self.holder.holder == self.person }
|
|
35
41
|
action activate { from: issued, to: active, requires self.holder in [active] }
|
|
36
|
-
action freeze { from: active, to: frozen }
|
|
37
|
-
action unfreeze { from: frozen, to: active, requires self.holder in [active] }
|
|
38
|
-
action
|
|
42
|
+
action freeze { from: active, to: frozen, actor: { party: person } }
|
|
43
|
+
action unfreeze { from: frozen, to: active, actor: { party: person }, requires self.holder in [active] }
|
|
44
|
+
action issuer_freeze { from: [active, frozen], to: blocked, actor: { party: issuer } }
|
|
45
|
+
action issuer_unfreeze { from: [frozen, blocked], to: active, actor: { party: issuer }, requires self.holder in [active] }
|
|
46
|
+
action cancel { from: [issued, active, frozen, blocked], to: cancelled, actor: { party: person } }
|
|
47
|
+
action issuer_cancel { from: [issued, active, frozen, blocked], to: cancelled, actor: { party: issuer } }
|
|
39
48
|
}
|
|
40
49
|
|
|
41
50
|
instrument authorization(card: ref<cards.card>, merchant: party, issuer: party = programOperator) {
|
package/std/escrow.hsx
CHANGED
|
@@ -9,13 +9,29 @@ header escrow
|
|
|
9
9
|
// Expose dispute, verify_return and refund separately for the return path.
|
|
10
10
|
// Payer disputes delivered goods; payee verifies return evidence from disputed.
|
|
11
11
|
// Payee refunds the whole held balance before delivery, or from return_verified
|
|
12
|
-
// by default after a dispute. While a
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
12
|
+
// by default after a dispute. While a financing plan funds the hold in any state
|
|
13
|
+
// but cancelled, both refunds refuse, so a written-off plan never hands lender
|
|
14
|
+
// principal to the payer. Only unwind returns the principal to capital and
|
|
15
|
+
// cancels the plan; after that, refund returns the rest. Before delivery the
|
|
16
|
+
// Product operator runs the plan's unwind_undelivered instead, which invokes
|
|
17
|
+
// unwind_financed here to return the rest to the payer and close the hold.
|
|
18
|
+
// For a paid plan, the plan's unwind_paid runs unwind_financed from funded after
|
|
19
|
+
// deliverBy, and return_hold or unwind_paid runs it from return_verified,
|
|
20
|
+
// depending on the plan's returned_goods.
|
|
21
|
+
// Only an installments plan can run confirm and unwind_financed. In a program
|
|
22
|
+
// without financing neither action exists, so every hold reaches funded through
|
|
23
|
+
// fund, which sets fundedAt. The plan's confirm leaves fundedAt unset, so
|
|
24
|
+
// refund_undelivered never comes due on a financed hold and no schedule offers
|
|
25
|
+
// it. Confirm sets deliverBy, deliver_within after confirmation, and the plan's
|
|
26
|
+
// unwind_paid waits for it so the payee keeps the whole delivery window.
|
|
16
27
|
// Expose refund_undelivered to let the payer take the whole held price back once
|
|
17
28
|
// deliver_within has passed since funding without delivery. It is a payer action
|
|
18
29
|
// that becomes available at that time; nothing runs it automatically.
|
|
30
|
+
// The Product operator settles any disputed hold: settle_release pays the payee
|
|
31
|
+
// as acceptance would, and settle_return moves it to return_verified. Without a
|
|
32
|
+
// live plan, settle_return also runs settle_refund to return the whole balance
|
|
33
|
+
// to the payer. A financed return continues on the plan's returned-goods path,
|
|
34
|
+
// and once that plan is cancelled the operator's settle_refund returns the rest.
|
|
19
35
|
// Acceptance expiry enters disputed, never released. Neither verify_return nor
|
|
20
36
|
// refund becomes public merely because dispute is exposed. Clock actions remain
|
|
21
37
|
// internal. Expose cancel for a pending hold, including a checkout-funded hold;
|
|
@@ -31,7 +47,7 @@ instrument hold(payer: party = party(person), payee: party = programOperator, ac
|
|
|
31
47
|
summary: "Hold the subject price through delivery, acceptance and verified return."
|
|
32
48
|
fields {
|
|
33
49
|
payer: account of payer, payee: account of payee
|
|
34
|
-
held: account of self, fundedAt: date?, deliveredAt: date?
|
|
50
|
+
held: account of self, fundedAt: date?, deliverBy: date?, deliveredAt: date?, openPlans: integer?
|
|
35
51
|
price: money = subject.price
|
|
36
52
|
}
|
|
37
53
|
lifecycle { states: [pending, funded, delivered, disputed, return_verified, released, refunded, cancelled], initial: pending }
|
|
@@ -41,14 +57,13 @@ instrument hold(payer: party = party(person), payee: party = programOperator, ac
|
|
|
41
57
|
}
|
|
42
58
|
action fund {
|
|
43
59
|
from: pending, to: funded, actor: { party: payer }
|
|
44
|
-
subject { price: money }
|
|
45
60
|
set: { fundedAt: { field: self.now } }
|
|
46
61
|
moves self.price from payer to self.held economics { purpose: principal, sourceParty: payer }
|
|
47
62
|
}
|
|
48
63
|
action confirm {
|
|
49
|
-
from: pending, to: funded
|
|
64
|
+
from: pending, to: funded, actor: { parent: all(financing.installments) }
|
|
50
65
|
requires self.held.balance == self.price
|
|
51
|
-
|
|
66
|
+
calculate: [{ target: deliverBy, op: shift, date: { field: self.now }, milliseconds: { literal: deliver_within }, direction: after }]
|
|
52
67
|
}
|
|
53
68
|
action deliver {
|
|
54
69
|
from: funded, to: delivered, actor: { party: payee }
|
|
@@ -72,17 +87,37 @@ instrument hold(payer: party = party(person), payee: party = programOperator, ac
|
|
|
72
87
|
from: disputed, to: return_verified, actor: { party: payee }
|
|
73
88
|
input { returnEvidence: text }
|
|
74
89
|
}
|
|
90
|
+
action settle_release { allowZero: true, requires self.price > "0";
|
|
91
|
+
from: disputed, to: released, actor: { party: programOperator }
|
|
92
|
+
input { ruling: text }
|
|
93
|
+
moves self.price from self.held to payee fee fee economics { payee: { recipient: payee, company: { purpose: earning, sourceParty: payer }, participant: { purpose: pass_through, sourceParty: programOperator } }, fee: { purpose: earning, sourceParty: payer }, tax: { purpose: pass_through, sourceParty: programOperator } }
|
|
94
|
+
}
|
|
95
|
+
action settle_return {
|
|
96
|
+
from: disputed, to: return_verified, actor: { party: programOperator }
|
|
97
|
+
input { ruling: text }
|
|
98
|
+
calculate: [{ target: openPlans, op: aggregate, selection: { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [quoted, signed, active, paid, written_off], limit: 1 }, measure: count }]
|
|
99
|
+
invoke: [{ reference: self.id, action: settle_refund, guard: { kind: compare, left: { field: self.openPlans }, operator: "==", right: { literal: 0 } }, input: {} }]
|
|
100
|
+
}
|
|
101
|
+
action settle_refund { allowZero: true,
|
|
102
|
+
from: return_verified, to: refunded, actor: { party: programOperator }
|
|
103
|
+
requires count of { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [quoted, signed, active, paid, written_off], limit: 1 } == 0
|
|
104
|
+
moves self.held.balance from self.held to payer economics { purpose: principal, sourceParty: programOperator }
|
|
105
|
+
}
|
|
75
106
|
action refund {
|
|
76
107
|
from: [funded, dispute.refund_after], to: refunded, actor: { party: payee }
|
|
77
|
-
requires count of { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [signed, active, paid], limit: 1 } == 0
|
|
108
|
+
requires count of { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [quoted, signed, active, paid, written_off], limit: 1 } == 0
|
|
78
109
|
moves self.held.balance from self.held to payer economics { purpose: principal, sourceParty: programOperator }
|
|
79
110
|
}
|
|
80
111
|
action refund_undelivered {
|
|
81
112
|
from: funded, to: refunded, actor: { party: payer }
|
|
82
113
|
due: { at: self.fundedAt, offset: deliver_within }
|
|
83
|
-
requires count of { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [signed, active, paid], limit: 1 } == 0
|
|
114
|
+
requires count of { instrument: all(financing.installments), reference: "funds", anchor: self.id, states: [quoted, signed, active, paid, written_off], limit: 1 } == 0
|
|
84
115
|
moves self.price from self.held to payer economics { purpose: principal, sourceParty: programOperator }
|
|
85
116
|
}
|
|
117
|
+
action unwind_financed { allowZero: true,
|
|
118
|
+
from: [funded, return_verified], to: refunded, actor: { parent: all(financing.installments) }
|
|
119
|
+
moves self.held.balance from self.held to payer economics { purpose: principal, sourceParty: programOperator }
|
|
120
|
+
}
|
|
86
121
|
action cancel { allowZero: true,
|
|
87
122
|
from: pending, to: cancelled, actor: { party: payer }
|
|
88
123
|
moves self.held.balance from self.held to payer economics { purpose: principal, sourceParty: programOperator }
|