@hsuite/smart-engines-cli 2.0.0 → 3.0.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 +3 -2
- package/dist/_lib/cluster-convergence.d.ts.map +1 -1
- package/dist/_lib/cluster-convergence.js +1 -1
- package/dist/_lib/cluster-convergence.js.map +1 -1
- package/dist/_lib/deposit-verification.d.ts +91 -0
- package/dist/_lib/deposit-verification.d.ts.map +1 -0
- package/dist/_lib/deposit-verification.js +265 -0
- package/dist/_lib/deposit-verification.js.map +1 -0
- package/dist/_lib/payment-guard.d.ts +2 -2
- package/dist/_lib/payment-guard.d.ts.map +1 -1
- package/dist/_lib/payment-guard.js.map +1 -1
- package/dist/_lib/payment-record.d.ts +6 -0
- package/dist/_lib/payment-record.d.ts.map +1 -1
- package/dist/_lib/payment-record.js +7 -1
- package/dist/_lib/payment-record.js.map +1 -1
- package/dist/_lib/subscription-client.d.ts +181 -7
- package/dist/_lib/subscription-client.d.ts.map +1 -1
- package/dist/_lib/subscription-client.js +63 -4
- package/dist/_lib/subscription-client.js.map +1 -1
- package/dist/_lib/swap-payment.d.ts +54 -0
- package/dist/_lib/swap-payment.d.ts.map +1 -0
- package/dist/_lib/swap-payment.js +203 -0
- package/dist/_lib/swap-payment.js.map +1 -0
- package/dist/_lib/xrp-payment.d.ts +20 -5
- package/dist/_lib/xrp-payment.d.ts.map +1 -1
- package/dist/_lib/xrp-payment.js +26 -8
- package/dist/_lib/xrp-payment.js.map +1 -1
- package/dist/commands/billing.d.ts +5 -3
- package/dist/commands/billing.d.ts.map +1 -1
- package/dist/commands/billing.js +12 -6
- package/dist/commands/billing.js.map +1 -1
- package/dist/commands/customer-scope.d.ts +57 -14
- package/dist/commands/customer-scope.d.ts.map +1 -1
- package/dist/commands/customer-scope.js +126 -25
- package/dist/commands/customer-scope.js.map +1 -1
- package/dist/commands/deploy.d.ts +1 -1
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +15 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +4 -2
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/redeploy.d.ts +4 -3
- package/dist/commands/redeploy.d.ts.map +1 -1
- package/dist/commands/redeploy.js +5 -4
- package/dist/commands/redeploy.js.map +1 -1
- package/dist/commands/renew.d.ts +47 -4
- package/dist/commands/renew.d.ts.map +1 -1
- package/dist/commands/renew.js +338 -9
- package/dist/commands/renew.js.map +1 -1
- package/dist/commands/status.d.ts.map +1 -1
- package/dist/commands/status.js +22 -2
- package/dist/commands/status.js.map +1 -1
- package/dist/commands/subscribe.d.ts +28 -0
- package/dist/commands/subscribe.d.ts.map +1 -1
- package/dist/commands/subscribe.js +225 -10
- package/dist/commands/subscribe.js.map +1 -1
- package/dist/commands/topup.d.ts +14 -0
- package/dist/commands/topup.d.ts.map +1 -1
- package/dist/commands/topup.js +22 -2
- package/dist/commands/topup.js.map +1 -1
- package/dist/commands/upgrade.d.ts +7 -0
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +27 -1
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/usage.d.ts +2 -0
- package/dist/commands/usage.d.ts.map +1 -1
- package/dist/commands/usage.js +6 -1
- package/dist/commands/usage.js.map +1 -1
- package/dist/commands/verify.d.ts +17 -17
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +110 -106
- package/dist/commands/verify.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/dist/__tests__/helpers/fixtures-image-hygiene.d.ts +0 -18
- package/dist/__tests__/helpers/fixtures-image-hygiene.d.ts.map +0 -1
- package/dist/__tests__/helpers/fixtures-image-hygiene.js +0 -42
- package/dist/__tests__/helpers/fixtures-image-hygiene.js.map +0 -1
- package/dist/__tests__/helpers/fixtures.d.ts +0 -48
- package/dist/__tests__/helpers/fixtures.d.ts.map +0 -1
- package/dist/__tests__/helpers/fixtures.js +0 -79
- package/dist/__tests__/helpers/fixtures.js.map +0 -1
- package/dist/__tests__/helpers/xrpl-signing.d.ts +0 -26
- package/dist/__tests__/helpers/xrpl-signing.d.ts.map +0 -1
- package/dist/__tests__/helpers/xrpl-signing.js +0 -39
- package/dist/__tests__/helpers/xrpl-signing.js.map +0 -1
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.swapPaymentOf = swapPaymentOf;
|
|
7
|
+
exports.assertSwapPaymentConsistent = assertSwapPaymentConsistent;
|
|
8
|
+
exports.assertSwapQuoteLive = assertSwapQuoteLive;
|
|
9
|
+
exports.swapPaymentCounted = swapPaymentCounted;
|
|
10
|
+
exports.renderSwapPayment = renderSwapPayment;
|
|
11
|
+
exports.resolveSwapListing = resolveSwapListing;
|
|
12
|
+
exports.swapCreateFields = swapCreateFields;
|
|
13
|
+
exports.swapRequestFields = swapRequestFields;
|
|
14
|
+
/**
|
|
15
|
+
* #3699 PR3 — paying a subscription in another asset (`hsuite subscribe --pay-with btc`).
|
|
16
|
+
*
|
|
17
|
+
* The validator opens a fixed-rate exchange at a swap provider that lands the order's exact XRP due on the
|
|
18
|
+
* subscription's deposit account, and answers `depositInstructions.swap`: what the BUILDER must send, to which
|
|
19
|
+
* provider address, until when, and the refund address the provider returns the funds to. This CLI holds an XRPL
|
|
20
|
+
* key, not a BTC one: it cannot spend those assets and NEVER tries. It checks what it is told, prints it for a
|
|
21
|
+
* human who sends the funds from their own wallet, and stops (the same exit as `--no-autopay`); re-running
|
|
22
|
+
* `hsuite subscribe` once the platform has counted the payment mints the NFT.
|
|
23
|
+
*
|
|
24
|
+
* It shows a human where to send real money, so it refuses an instruction that names another asset than the one
|
|
25
|
+
* asked for, a REFUND address that is not the builder's own (a hostile validator would keep the refund), a
|
|
26
|
+
* payin address or memo that is not a plain token, an amount it cannot read, or a quote past its deadline.
|
|
27
|
+
*/
|
|
28
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
29
|
+
/** The swap instruction of a deposit, or `undefined` when the order is not paid through a swap. */
|
|
30
|
+
function swapPaymentOf(deposit) {
|
|
31
|
+
return deposit.swap;
|
|
32
|
+
}
|
|
33
|
+
const show = (value) => JSON.stringify(String(value).slice(0, 60));
|
|
34
|
+
/** Printable, no whitespace: what an address or a memo is made of. */
|
|
35
|
+
const ADDRESS = /^[\x21-\x7e]{1,256}$/;
|
|
36
|
+
const EXTRA_ID = /^[\x21-\x7e]{1,128}$/;
|
|
37
|
+
const SLUG = /^[A-Za-z0-9]{1,32}$/;
|
|
38
|
+
const PROVIDER = /^[a-z0-9_-]{1,32}$/;
|
|
39
|
+
const POSITIVE_DECIMAL = /^(?=.*[1-9])\d+(\.\d+)?$/;
|
|
40
|
+
/**
|
|
41
|
+
* Check a swap instruction before it is shown. `ask` is what this run asked for (absent on a resume that named
|
|
42
|
+
* no asset: the stored instructions are then the contract, and are only checked for being well-formed).
|
|
43
|
+
*/
|
|
44
|
+
function assertSwapPaymentConsistent(swap, ask) {
|
|
45
|
+
const refuse = (why) => {
|
|
46
|
+
throw new Error(`the swap payment instruction ${why} — nothing was paid`);
|
|
47
|
+
};
|
|
48
|
+
if (typeof swap.payinAddress !== 'string' || !ADDRESS.test(swap.payinAddress)) {
|
|
49
|
+
refuse(`names a payin address that is not a plain address (${show(swap.payinAddress)})`);
|
|
50
|
+
}
|
|
51
|
+
if (swap.payinExtraId !== undefined && (typeof swap.payinExtraId !== 'string' || !EXTRA_ID.test(swap.payinExtraId))) {
|
|
52
|
+
refuse(`names a payin memo that is not a plain token (${show(swap.payinExtraId)})`);
|
|
53
|
+
}
|
|
54
|
+
if (typeof swap.amount !== 'string' || !POSITIVE_DECIMAL.test(swap.amount) || swap.amount.length > 40) {
|
|
55
|
+
refuse(`names an amount that is not a positive plain decimal (${show(swap.amount)})`);
|
|
56
|
+
}
|
|
57
|
+
if (typeof swap.asset !== 'string' || !SLUG.test(swap.asset) || typeof swap.network !== 'string' || !SLUG.test(swap.network)) {
|
|
58
|
+
refuse(`names an asset or network that is not a plain ticker (${show(swap.asset)} on ${show(swap.network)})`);
|
|
59
|
+
}
|
|
60
|
+
if (typeof swap.validUntil !== 'string' || Number.isNaN(new Date(swap.validUntil).getTime())) {
|
|
61
|
+
refuse(`names a deadline that cannot be read (${show(swap.validUntil)})`);
|
|
62
|
+
}
|
|
63
|
+
if (typeof swap.refundAddress !== 'string' || !ADDRESS.test(swap.refundAddress)) {
|
|
64
|
+
refuse(`names a refund address that is not a plain address (${show(swap.refundAddress)})`);
|
|
65
|
+
}
|
|
66
|
+
// Everything below is PRINTED to a terminal: a hostile validator must not smuggle escape sequences in.
|
|
67
|
+
if (swap.refundExtraId !== undefined && (typeof swap.refundExtraId !== 'string' || !EXTRA_ID.test(swap.refundExtraId))) {
|
|
68
|
+
refuse(`names a refund memo that is not a plain token (${show(swap.refundExtraId)})`);
|
|
69
|
+
}
|
|
70
|
+
if (typeof swap.provider !== 'string' || !PROVIDER.test(swap.provider)) {
|
|
71
|
+
refuse(`names a provider that is not a plain name (${show(swap.provider)})`);
|
|
72
|
+
}
|
|
73
|
+
if (typeof swap.toAmountXrp !== 'string' || !POSITIVE_DECIMAL.test(swap.toAmountXrp) || swap.toAmountXrp.length > 40) {
|
|
74
|
+
refuse(`names a payout that is not a positive plain decimal (${show(swap.toAmountXrp)})`);
|
|
75
|
+
}
|
|
76
|
+
if (!ask)
|
|
77
|
+
return;
|
|
78
|
+
if (swap.asset.toLowerCase() !== ask.ticker.toLowerCase()) {
|
|
79
|
+
refuse(`is for ${show(swap.asset)}, not the ${show(ask.ticker.toUpperCase())} that was asked for`);
|
|
80
|
+
}
|
|
81
|
+
if (ask.network !== undefined && swap.network.toLowerCase() !== ask.network.toLowerCase()) {
|
|
82
|
+
refuse(`is for the network ${show(swap.network)}, not the ${show(ask.network)} that was asked for`);
|
|
83
|
+
}
|
|
84
|
+
// The refund goes where the BUILDER said, or the funds of a failed swap are not theirs.
|
|
85
|
+
if (swap.refundAddress !== ask.refundAddress) {
|
|
86
|
+
refuse(`refunds to ${show(swap.refundAddress)}, not the refund address you gave (${show(ask.refundAddress)})`);
|
|
87
|
+
}
|
|
88
|
+
if ((swap.refundExtraId ?? undefined) !== (ask.refundExtraId ?? undefined)) {
|
|
89
|
+
refuse(`refunds with the memo ${show(swap.refundExtraId)}, not the one you gave (${show(ask.refundExtraId)})`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/** A value safe to paste into a shell as one word: plain characters as they are, anything else single-quoted. */
|
|
93
|
+
function shellWord(value) {
|
|
94
|
+
return /^[A-Za-z0-9._:/@-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Never put a lapsed quote's payin address in front of a payer: the provider no longer honours its price. The
|
|
98
|
+
* platform opens a NEW exchange for a lapsed quote when the builder re-runs and names the asset and the SAME
|
|
99
|
+
* refund address again (and only while the provider does not report a payment to the old one as received), so the
|
|
100
|
+
* refusal says exactly that. The command it suggests is built from the validator's answer, so every value in it is
|
|
101
|
+
* quoted.
|
|
102
|
+
*/
|
|
103
|
+
function assertSwapQuoteLive(swap) {
|
|
104
|
+
if (new Date(swap.validUntil).getTime() > Date.now())
|
|
105
|
+
return;
|
|
106
|
+
const command = [
|
|
107
|
+
'hsuite subscribe',
|
|
108
|
+
`--pay-with ${shellWord(swap.asset.toLowerCase())}`,
|
|
109
|
+
`--pay-network ${shellWord(swap.network)}`,
|
|
110
|
+
`--refund-address ${shellWord(swap.refundAddress)}`,
|
|
111
|
+
...(swap.refundExtraId !== undefined ? [`--refund-extra-id ${shellWord(swap.refundExtraId)}`] : []),
|
|
112
|
+
].join(' ');
|
|
113
|
+
throw new Error(`the swap quote for ${swap.asset} expired at ${new Date(swap.validUntil).toLocaleString()}: do NOT send anything to ` +
|
|
114
|
+
`${swap.payinAddress} (the provider no longer honours its price). ` +
|
|
115
|
+
`To be offered a NEW quote, re-run \`${command}\`: the platform opens a new exchange for the same deposit account ` +
|
|
116
|
+
'once this one has lapsed unpaid, and this CLI prints where to send it (it never pays). ' +
|
|
117
|
+
'If you ALREADY sent it in time, do nothing: the provider\'s payout is still honoured for a few hours after the deadline, ' +
|
|
118
|
+
'the platform opens no new quote while the provider reports your payment as received, and re-running `hsuite subscribe` later picks it up.');
|
|
119
|
+
}
|
|
120
|
+
/** Has the platform already counted the builder's swap payment (the order is `paid` or `converting`)? Then nothing is to be sent. */
|
|
121
|
+
function swapPaymentCounted(swap) {
|
|
122
|
+
return swap.status === 'paid' || swap.status === 'converting';
|
|
123
|
+
}
|
|
124
|
+
/** The payment lines of a swap order's instructions. */
|
|
125
|
+
function renderSwapPayment(swap) {
|
|
126
|
+
const minutes = Math.max(0, Math.round((new Date(swap.validUntil).getTime() - Date.now()) / 60_000));
|
|
127
|
+
console.log(chalk_1.default.bold.yellow(`\n Send ${swap.amount} ${swap.asset} (network ${swap.network}) from your OWN wallet:`));
|
|
128
|
+
console.log(chalk_1.default.gray(` amount: ${swap.amount} ${swap.asset}`));
|
|
129
|
+
console.log(chalk_1.default.gray(` network: ${swap.network}`));
|
|
130
|
+
console.log(chalk_1.default.gray(` to: ${swap.payinAddress}`));
|
|
131
|
+
if (swap.payinExtraId !== undefined) {
|
|
132
|
+
console.log(chalk_1.default.gray(` memo: ${swap.payinExtraId} (REQUIRED on the payment — without it the provider cannot match it)`));
|
|
133
|
+
}
|
|
134
|
+
console.log(chalk_1.default.gray(` deadline: ${new Date(swap.validUntil).toLocaleString()} (${minutes} min remaining)`));
|
|
135
|
+
console.log(chalk_1.default.gray(` refund: ${swap.refundAddress}${swap.refundExtraId !== undefined ? ` (memo ${swap.refundExtraId})` : ''} — ` +
|
|
136
|
+
'where the provider returns your funds if the swap cannot complete'));
|
|
137
|
+
console.log(chalk_1.default.gray(` the provider (${swap.provider}) lands ${swap.toAmountXrp} XRP on your deposit account; the platform converts it ` +
|
|
138
|
+
'into your subscription deposit. Send exactly this amount, before the deadline.'));
|
|
139
|
+
console.log(chalk_1.default.cyan(' hsuite does not send this for you: it holds an XRPL key, not a key for this asset.'));
|
|
140
|
+
}
|
|
141
|
+
/** The most alternatives listed in a refusal. */
|
|
142
|
+
const MAX_LISTED = 24;
|
|
143
|
+
/**
|
|
144
|
+
* Find the asset a builder asked to pay in among what `GET /subscription/payment-assets` offers, and refuse,
|
|
145
|
+
* before anything is created, what the validator would refuse: an asset it does not offer (or no swap
|
|
146
|
+
* payments at all), a ticker on several networks with none named, and an asset whose refund address needs a
|
|
147
|
+
* memo that was not given. Returns the listing entry, whose `network` is the one to send.
|
|
148
|
+
*/
|
|
149
|
+
function resolveSwapListing(assets, ask) {
|
|
150
|
+
const swaps = assets.filter((a) => a.kind === 'swap');
|
|
151
|
+
const ticker = ask.ticker.toLowerCase();
|
|
152
|
+
const T = ticker.toUpperCase();
|
|
153
|
+
const listed = swaps.filter((a) => a.symbol.toLowerCase() === ticker);
|
|
154
|
+
if (listed.length === 0) {
|
|
155
|
+
if (swaps.length === 0) {
|
|
156
|
+
throw new Error(`${T} cannot be paid: this network offers no swap payments (they are off, or no swap provider is configured). ` +
|
|
157
|
+
'Pay in hsuite or xrp. Nothing was created.');
|
|
158
|
+
}
|
|
159
|
+
const names = [...new Set(swaps.map((a) => a.symbol))].slice(0, MAX_LISTED).join(', ');
|
|
160
|
+
throw new Error(`${T} is not offered for swap payments on this network. Offered: ${names}. Nothing was created.`);
|
|
161
|
+
}
|
|
162
|
+
let chosen;
|
|
163
|
+
if (ask.network !== undefined) {
|
|
164
|
+
chosen = listed.find((a) => a.network === ask.network.toLowerCase());
|
|
165
|
+
if (!chosen) {
|
|
166
|
+
throw new Error(`${T} is not offered on the network ${show(ask.network)} (offered on: ${listed.map((a) => a.network).join(', ')}). Nothing was created.`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (listed.length === 1) {
|
|
170
|
+
chosen = listed[0];
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
// Never guessed: a payment sent on another chain than the one the builder meant is lost.
|
|
174
|
+
throw new Error(`${T} travels on more than one network (${listed.map((a) => a.network).join(', ')}): say which with --pay-network. Nothing was created.`);
|
|
175
|
+
}
|
|
176
|
+
if (chosen.refundExtraIdRequired === true && ask.refundExtraId === undefined) {
|
|
177
|
+
throw new Error(`${T} refund addresses take a memo / tag: give yours with --refund-extra-id. Nothing was created.`);
|
|
178
|
+
}
|
|
179
|
+
return chosen;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The swap fields of a smart-app create (`POST /api/v3/smart-apps`): the asset as a symbol, the network it
|
|
183
|
+
* travels on (the listing's, else the one asked for), and the builder's refund address and memo.
|
|
184
|
+
*/
|
|
185
|
+
function swapCreateFields(ask, listing) {
|
|
186
|
+
const network = listing?.network ?? ask.network;
|
|
187
|
+
return {
|
|
188
|
+
paymentAsset: ask.ticker.toUpperCase(),
|
|
189
|
+
...(network !== undefined ? { paymentNetwork: network } : {}),
|
|
190
|
+
refundAddress: ask.refundAddress,
|
|
191
|
+
...(ask.refundExtraId !== undefined ? { refundExtraId: ask.refundExtraId } : {}),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** The same fields in the shape of a subscription request (`POST /api/v3/subscription/request`). */
|
|
195
|
+
function swapRequestFields(ask, listing) {
|
|
196
|
+
const network = listing?.network ?? ask.network;
|
|
197
|
+
return {
|
|
198
|
+
paymentAsset: { symbol: ask.ticker.toUpperCase(), ...(network !== undefined ? { network } : {}) },
|
|
199
|
+
refundAddress: ask.refundAddress,
|
|
200
|
+
...(ask.refundExtraId !== undefined ? { refundExtraId: ask.refundExtraId } : {}),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMapping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WAAW,EAAE,EAAE,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QACjG,aAAa,EAAE,GAAG,CAAC,aAAa;QAChC,GAAG,CAAC,GAAG,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACjF,CAAC;AACJ,CAAC"}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import type { DepositInstructions } from './subscription-client';
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* What a subscription is paid in. `hsuite` is the default (HST, on XRPL its ledger code); `xrp` is paid by
|
|
4
|
+
* this CLI; `swap` is any other asset (BTC, ETH, ...), paid through a swap provider by the builder from their
|
|
5
|
+
* own wallet (#3699 PR3): the CLI prints where to send it and never pays it.
|
|
6
|
+
*/
|
|
7
|
+
export type PayWith = 'hsuite' | 'xrp' | 'swap';
|
|
4
8
|
/** The values `--pay-with` accepts, for the option text and the refusal. */
|
|
5
|
-
export declare const PAY_WITH_VALUES: readonly ["hsuite", "xrp"];
|
|
6
|
-
/**
|
|
7
|
-
export
|
|
9
|
+
export declare const PAY_WITH_VALUES: readonly ["hsuite", "xrp", "<swap asset: btc, eth, usdt, ...>"];
|
|
10
|
+
/** What `--pay-with` named: the kind, and for a swap the lower-case ticker. */
|
|
11
|
+
export type PayChoice = {
|
|
12
|
+
kind: PayWith;
|
|
13
|
+
asset?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parse `--pay-with` (case-insensitive; omitted = hsuite). `hsuite` / `hst` and `xrp` are themselves; any other
|
|
17
|
+
* ticker is a SWAP asset (the validator decides whether it is payable: see `GET /subscription/payment-assets`).
|
|
18
|
+
* Throws, before anything is sent, on a value that is not a ticker.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parsePayChoice(raw: string | undefined): PayChoice;
|
|
21
|
+
/** Parse `--pay-network` (a swap asset's network, e.g. `trx` for USDT): letters and digits, lower-cased. */
|
|
22
|
+
export declare function parsePayNetwork(raw: string | undefined): string | undefined;
|
|
8
23
|
/** The XRP instruction of a deposit, or `undefined` when the order is priced in HST. */
|
|
9
24
|
export type XrpPay = NonNullable<DepositInstructions['pay']>;
|
|
10
25
|
export declare function xrpPaymentOf(deposit: Pick<DepositInstructions, 'pay'>): XrpPay | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrp-payment.d.ts","sourceRoot":"","sources":["../../src/_lib/xrp-payment.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE
|
|
1
|
+
{"version":3,"file":"xrp-payment.d.ts","sourceRoot":"","sources":["../../src/_lib/xrp-payment.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC;AAEhD,4EAA4E;AAC5E,eAAO,MAAM,eAAe,iEAAkE,CAAC;AAK/F,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAOjE;AAED,4GAA4G;AAC5G,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAK3E;AAED,wFAAwF;AACxF,MAAM,MAAM,MAAM,GAAG,WAAW,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,CAAC;AAC7D,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,KAAK,CAAC,GAAG,MAAM,GAAG,SAAS,CAE1F;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAWjH;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMhD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQvF;AAED,2FAA2F;AAC3F,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,mBAAmB,EAAE,QAAQ,GAAG,SAAS,GAAG,eAAe,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAUxH"}
|
package/dist/_lib/xrp-payment.js
CHANGED
|
@@ -4,7 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.PAY_WITH_VALUES = void 0;
|
|
7
|
-
exports.
|
|
7
|
+
exports.parsePayChoice = parsePayChoice;
|
|
8
|
+
exports.parsePayNetwork = parsePayNetwork;
|
|
8
9
|
exports.xrpPaymentOf = xrpPaymentOf;
|
|
9
10
|
exports.assertXrpPaymentConsistent = assertXrpPaymentConsistent;
|
|
10
11
|
exports.dropsToXrp = dropsToXrp;
|
|
@@ -23,17 +24,34 @@ exports.renderXrpPayment = renderXrpPayment;
|
|
|
23
24
|
*/
|
|
24
25
|
const chalk_1 = __importDefault(require("chalk"));
|
|
25
26
|
/** The values `--pay-with` accepts, for the option text and the refusal. */
|
|
26
|
-
exports.PAY_WITH_VALUES = ['hsuite', 'xrp'];
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
exports.PAY_WITH_VALUES = ['hsuite', 'xrp', '<swap asset: btc, eth, usdt, ...>'];
|
|
28
|
+
/** A swap asset's ticker or network as the CLI accepts it: letters and digits, the same shape the validator reads. */
|
|
29
|
+
const TICKER = /^[A-Za-z0-9]{1,32}$/;
|
|
30
|
+
/**
|
|
31
|
+
* Parse `--pay-with` (case-insensitive; omitted = hsuite). `hsuite` / `hst` and `xrp` are themselves; any other
|
|
32
|
+
* ticker is a SWAP asset (the validator decides whether it is payable: see `GET /subscription/payment-assets`).
|
|
33
|
+
* Throws, before anything is sent, on a value that is not a ticker.
|
|
34
|
+
*/
|
|
35
|
+
function parsePayChoice(raw) {
|
|
29
36
|
if (raw === undefined)
|
|
30
|
-
return 'hsuite';
|
|
37
|
+
return { kind: 'hsuite' };
|
|
31
38
|
const value = raw.trim().toLowerCase();
|
|
32
39
|
if (value === 'hsuite' || value === 'hst')
|
|
33
|
-
return 'hsuite';
|
|
40
|
+
return { kind: 'hsuite' };
|
|
34
41
|
if (value === 'xrp')
|
|
35
|
-
return 'xrp';
|
|
36
|
-
|
|
42
|
+
return { kind: 'xrp' };
|
|
43
|
+
if (TICKER.test(value))
|
|
44
|
+
return { kind: 'swap', asset: value };
|
|
45
|
+
throw new Error(`unknown --pay-with ${JSON.stringify(raw.slice(0, 40))}. Valid: ${exports.PAY_WITH_VALUES.join(', ')}`);
|
|
46
|
+
}
|
|
47
|
+
/** Parse `--pay-network` (a swap asset's network, e.g. `trx` for USDT): letters and digits, lower-cased. */
|
|
48
|
+
function parsePayNetwork(raw) {
|
|
49
|
+
if (raw === undefined)
|
|
50
|
+
return undefined;
|
|
51
|
+
const value = raw.trim().toLowerCase();
|
|
52
|
+
if (!TICKER.test(value))
|
|
53
|
+
throw new Error(`unknown --pay-network ${JSON.stringify(raw.slice(0, 40))}: a network name is letters and digits only (e.g. btc, eth, trx)`);
|
|
54
|
+
return value;
|
|
37
55
|
}
|
|
38
56
|
function xrpPaymentOf(deposit) {
|
|
39
57
|
return deposit.pay?.asset === 'XRP' ? deposit.pay : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xrp-payment.js","sourceRoot":"","sources":["../../src/_lib/xrp-payment.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"xrp-payment.js","sourceRoot":"","sources":["../../src/_lib/xrp-payment.ts"],"names":[],"mappings":";;;;;;AAkCA,wCAOC;AAGD,0CAKC;AAID,oCAEC;AAOD,gEAWC;AAOD,gCAMC;AAOD,8CAQC;AAGD,0CAMC;AAGD,4CAUC;AA3HD;;;;;;;;;GASG;AACH,kDAA0B;AAU1B,4EAA4E;AAC/D,QAAA,eAAe,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,mCAAmC,CAAU,CAAC;AAE/F,sHAAsH;AACtH,MAAM,MAAM,GAAG,qBAAqB,CAAC;AAKrC;;;;GAIG;AACH,SAAgB,cAAc,CAAC,GAAuB;IACpD,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IACvC,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IACrE,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC5C,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IAC9D,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,uBAAe,CA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AgB,eAAe,CAAC,GAAW;IACzC,OAAO,CACL,uBAAuB,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACxD,WAAW,kBAAkB,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE;QACvD,OAAO,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,EAAE,CACxD,CAAC;AACJ,CAAC;AAED,sFAAsF;AACtF,SAAgB,gBAAgB,CAAC,CAAoE,EAAE,GAAW;IAChH,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC;IAC7F,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,GAAG,CAAC,cAAc,8CAA8C,CAAC,CAAC,CAAC;IAC3G,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,qCAAqC,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,OAAO,gCAAgC;QAC7F,gGAAgG,CACnG,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `hsuite billing` — pretty-print the billing
|
|
2
|
+
* `hsuite billing` — pretty-print the billing history.
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import { SubscriptionClient } from '../_lib/subscription-client';
|
|
5
|
+
import { SubscriptionClient, type BillingLedgerResponse } from '../_lib/subscription-client';
|
|
6
6
|
type BillingOpts = {
|
|
7
7
|
env: string;
|
|
8
8
|
gateway?: string;
|
|
@@ -11,7 +11,9 @@ type BillingOpts = {
|
|
|
11
11
|
offset?: string;
|
|
12
12
|
clientFactory?: (baseUrl: string) => SubscriptionClient;
|
|
13
13
|
};
|
|
14
|
-
export declare function runBilling(opts: BillingOpts): Promise<
|
|
14
|
+
export declare function runBilling(opts: BillingOpts): Promise<BillingLedgerResponse>;
|
|
15
|
+
/** One entry as a table row: what it was for, its status, what arrived, the first transaction, and when. */
|
|
16
|
+
export declare function formatBillingRow(entry: BillingLedgerResponse['entries'][number]): string;
|
|
15
17
|
export declare const billingCommand: Command;
|
|
16
18
|
export {};
|
|
17
19
|
//# sourceMappingURL=billing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/commands/billing.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"billing.d.ts","sourceRoot":"","sources":["../../src/commands/billing.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,kBAAkB,EAAE,KAAK,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAG7F,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,kBAAkB,CAAC;CACzD,CAAC;AAEF,wBAAsB,UAAU,CAAC,IAAI,EAAE,WAAW,kCAUjD;AAED,4GAA4G;AAC5G,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,CAMxF;AAED,eAAO,MAAM,cAAc,SA+BvB,CAAC"}
|
package/dist/commands/billing.js
CHANGED
|
@@ -5,8 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.billingCommand = void 0;
|
|
7
7
|
exports.runBilling = runBilling;
|
|
8
|
+
exports.formatBillingRow = formatBillingRow;
|
|
8
9
|
/**
|
|
9
|
-
* `hsuite billing` — pretty-print the billing
|
|
10
|
+
* `hsuite billing` — pretty-print the billing history.
|
|
10
11
|
*/
|
|
11
12
|
const commander_1 = require("commander");
|
|
12
13
|
const chalk_1 = __importDefault(require("chalk"));
|
|
@@ -26,8 +27,14 @@ async function runBilling(opts) {
|
|
|
26
27
|
const client = (opts.clientFactory ?? ((b) => new subscription_client_1.SubscriptionClient({ baseUrl: b })))(baseUrl);
|
|
27
28
|
return client.billing(appId, limit, offset);
|
|
28
29
|
}
|
|
30
|
+
/** One entry as a table row: what it was for, its status, what arrived, the first transaction, and when. */
|
|
31
|
+
function formatBillingRow(entry) {
|
|
32
|
+
const tx = entry.txHashes[0] ? `${entry.txHashes[0].slice(0, 12)}…` : '-';
|
|
33
|
+
return (` ${(entry.operation ?? '').padEnd(10)} ${(entry.status ?? '').padEnd(11)} ` +
|
|
34
|
+
`${`${entry.amount ?? ''} ${entry.asset ?? ''}`.trim().padEnd(26)} ${tx.padEnd(14)} ${entry.timestamp ?? ''}`);
|
|
35
|
+
}
|
|
29
36
|
exports.billingCommand = new commander_1.Command('billing')
|
|
30
|
-
.description('Print the
|
|
37
|
+
.description('Print the billing history: the deposits, upgrades, top-ups, renewals and credits of the app')
|
|
31
38
|
.option('--env <file>', 'Env file with subscription appId', '.env.local')
|
|
32
39
|
.option('--gateway <url>', 'Validator/gateway URL (defaults to VALIDATOR_URL in env)')
|
|
33
40
|
.option('--app-id <id>', 'Override SUBSCRIPTION_APP_ID from env')
|
|
@@ -43,11 +50,10 @@ exports.billingCommand = new commander_1.Command('billing')
|
|
|
43
50
|
console.log(chalk_1.default.gray(' (no entries)\n'));
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
46
|
-
|
|
47
|
-
console.log(chalk_1.default.
|
|
48
|
-
console.log(chalk_1.default.gray(' ' + '-'.repeat(78)));
|
|
53
|
+
console.log(chalk_1.default.bold.white(` ${'operation'.padEnd(10)} ${'status'.padEnd(11)} ${'amount'.padEnd(26)} ${'tx'.padEnd(14)} timestamp`));
|
|
54
|
+
console.log(chalk_1.default.gray(' ' + '-'.repeat(86)));
|
|
49
55
|
for (const e of res.entries) {
|
|
50
|
-
console.log(chalk_1.default.gray(
|
|
56
|
+
console.log(chalk_1.default.gray(formatBillingRow(e)));
|
|
51
57
|
}
|
|
52
58
|
console.log('');
|
|
53
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/commands/billing.ts"],"names":[],"mappings":";;;;;;AAkBA,gCAUC;
|
|
1
|
+
{"version":3,"file":"billing.js","sourceRoot":"","sources":["../../src/commands/billing.ts"],"names":[],"mappings":";;;;;;AAkBA,gCAUC;AAGD,4CAMC;AArCD;;GAEG;AACH,yCAAoC;AACpC,kDAA0B;AAC1B,qCAAsC;AACtC,qEAA6F;AAC7F,+DAA6E;AAWtE,KAAK,UAAU,UAAU,CAAC,IAAiB;IAChD,MAAM,GAAG,GAAG,IAAA,aAAO,EAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,OAAO,GAAG,IAAA,sCAAmB,EAAC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,IAAA,+BAAY,EAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;IACvD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAA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QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,YAAY,CACzG,CACF,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC/C,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,eAAK,CAAC,GAAG,CAAC,KAAM,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* `hsuite customer-scope
|
|
3
|
-
* BaaS data-plane request from this app that carries no end-user
|
|
2
|
+
* `hsuite customer-scope [strict|permissive]` — show, or set, how the PLATFORM
|
|
3
|
+
* treats a BaaS data-plane request from this app that carries no end-user
|
|
4
|
+
* identity.
|
|
4
5
|
*
|
|
5
6
|
* Smart-host #3228 (Hacken HSUITEPT-6) scopes every db / storage / messaging
|
|
6
7
|
* object to the customer whose session the app forwards
|
|
@@ -12,31 +13,44 @@
|
|
|
12
13
|
* `strict` removes the guesswork — the host refuses (403) any
|
|
13
14
|
* customer-reachable call from this app that carries no customer identity.
|
|
14
15
|
* Tenant-administration routes (collection drop, state transitions, usage
|
|
15
|
-
* stats) stay reachable: they are app-only by construction. `permissive`
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* stats) stay reachable: they are app-only by construction. `permissive` is
|
|
17
|
+
* the explicit opt-out that restores the pre-#3228 behaviour: every customer
|
|
18
|
+
* behind an app that forwards no identity shares one pool. It is never what an
|
|
19
|
+
* app gets by default — a config that never set the field resolves `strict`
|
|
20
|
+
* (HSUITEPT-6), so only a value somebody SET is ever `permissive`.
|
|
18
21
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
+
* With no argument the command prints the app's effective policy and whether the
|
|
23
|
+
* app's config carries it or the platform default applies; `hsuite deploy` runs
|
|
24
|
+
* the same read and warns on
|
|
25
|
+
* `permissive` ({@link warnIfPermissiveCustomerScope}).
|
|
26
|
+
*
|
|
27
|
+
* Wire target: `GET` / `PUT /api/v3/smart-apps/:appId` on the validator,
|
|
28
|
+
* owner-gated on `developerWallet` — hence the developer wallet from
|
|
29
|
+
* `.env.local`. The config merge on `PUT` is partial, so nothing else in the
|
|
30
|
+
* app's config is touched.
|
|
22
31
|
*/
|
|
23
32
|
import { Command } from 'commander';
|
|
24
|
-
import {
|
|
33
|
+
import { type EnvMap } from '../_lib/env';
|
|
34
|
+
import { SubscriptionClient, type AppCustomerScope } from '../_lib/subscription-client';
|
|
25
35
|
/** The two policies the platform accepts (`SmartAppConfigSchema.customerScope`). */
|
|
26
36
|
export declare const CUSTOMER_SCOPE_POLICIES: readonly ["strict", "permissive"];
|
|
27
37
|
export type CustomerScopePolicy = (typeof CUSTOMER_SCOPE_POLICIES)[number];
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
/** What `permissive` costs and the command that ends it — said the same way by `customer-scope` and `deploy`. */
|
|
39
|
+
export declare const PERMISSIVE_WARNING: string;
|
|
40
|
+
type ScopeClientFactory = (baseUrl: string) => SubscriptionClient;
|
|
41
|
+
type ScopeConnectOpts = {
|
|
30
42
|
env: string;
|
|
31
43
|
gateway?: string;
|
|
32
44
|
appId?: string;
|
|
33
|
-
clientFactory?:
|
|
45
|
+
clientFactory?: ScopeClientFactory;
|
|
46
|
+
};
|
|
47
|
+
export type CustomerScopeOpts = ScopeConnectOpts & {
|
|
48
|
+
policy: string;
|
|
34
49
|
};
|
|
35
50
|
/**
|
|
36
51
|
* Validate the policy argument BEFORE any env read, auth or HTTP — a typo is
|
|
37
52
|
* the one failure mode that must never reach the platform, because
|
|
38
|
-
* `SmartAppConfigSchema` would reject it as a 400 after a slow auth round-trip
|
|
39
|
-
* (and an unvalidated value stored on the doc reads back as permissive).
|
|
53
|
+
* `SmartAppConfigSchema` would reject it as a 400 after a slow auth round-trip.
|
|
40
54
|
*/
|
|
41
55
|
export declare function parsePolicy(raw: string): CustomerScopePolicy;
|
|
42
56
|
/** Pure orchestration body — exported for unit tests. */
|
|
@@ -44,5 +58,34 @@ export declare function runCustomerScope(opts: CustomerScopeOpts): Promise<{
|
|
|
44
58
|
appId: string;
|
|
45
59
|
customerScope: CustomerScopePolicy;
|
|
46
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Read the app's effective policy — what the host enforces, and whether the app
|
|
63
|
+
* set it. Both fields are absent when the validator does not say (see
|
|
64
|
+
* `SubscriptionClient.getCustomerScope`). Exported for unit tests.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readCustomerScope(opts: ScopeConnectOpts): Promise<{
|
|
67
|
+
appId: string;
|
|
68
|
+
} & AppCustomerScope>;
|
|
69
|
+
export type CustomerScopeAdvisoryOpts = {
|
|
70
|
+
env: EnvMap;
|
|
71
|
+
/** The validator origin — for `hsuite deploy`, the same gateway the deploy goes to. */
|
|
72
|
+
baseUrl: string;
|
|
73
|
+
appId: string;
|
|
74
|
+
warn: (message: string) => void;
|
|
75
|
+
note: (message: string) => void;
|
|
76
|
+
/** Test seams. */
|
|
77
|
+
clientFactory?: ScopeClientFactory;
|
|
78
|
+
deadlineMs?: number;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* `hsuite deploy`'s customerScope advisory: read the app's effective policy and
|
|
82
|
+
* `warn` when it is `permissive`. It NEVER throws and never blocks — a read that
|
|
83
|
+
* fails, times out or comes back without a policy is a `note`, not an error, and
|
|
84
|
+
* the deploy proceeds either way. With no developer wallet in the env there is
|
|
85
|
+
* nothing to read it with, so it says nothing (the deploy has its own guard for
|
|
86
|
+
* the missing seed).
|
|
87
|
+
*/
|
|
88
|
+
export declare function warnIfPermissiveCustomerScope(opts: CustomerScopeAdvisoryOpts): Promise<void>;
|
|
47
89
|
export declare const customerScopeCommand: Command;
|
|
90
|
+
export {};
|
|
48
91
|
//# sourceMappingURL=customer-scope.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customer-scope.d.ts","sourceRoot":"","sources":["../../src/commands/customer-scope.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"customer-scope.d.ts","sourceRoot":"","sources":["../../src/commands/customer-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,KAAK,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGxF,oFAAoF;AACpF,eAAO,MAAM,uBAAuB,mCAAoC,CAAC;AACzE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E,iHAAiH;AACjH,eAAO,MAAM,kBAAkB,QAE6B,CAAC;AAE7D,KAAK,kBAAkB,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,kBAAkB,CAAC;AAElE,KAAK,gBAAgB,GAAG;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,kBAAkB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,g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