@hsuite/smart-engines-cli 1.9.0 → 2.1.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 +4 -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/env.d.ts.map +1 -1
- package/dist/_lib/env.js +9 -7
- package/dist/_lib/env.js.map +1 -1
- package/dist/_lib/error-message.d.ts +7 -0
- package/dist/_lib/error-message.d.ts.map +1 -0
- package/dist/_lib/error-message.js +21 -0
- package/dist/_lib/error-message.js.map +1 -0
- package/dist/_lib/order-deadline.d.ts +23 -0
- package/dist/_lib/order-deadline.d.ts.map +1 -1
- package/dist/_lib/order-deadline.js +40 -6
- package/dist/_lib/order-deadline.js.map +1 -1
- package/dist/_lib/payment-guard.d.ts +59 -0
- package/dist/_lib/payment-guard.d.ts.map +1 -0
- package/dist/_lib/payment-guard.js +188 -0
- package/dist/_lib/payment-guard.js.map +1 -0
- package/dist/_lib/payment-lock.d.ts +27 -0
- package/dist/_lib/payment-lock.d.ts.map +1 -0
- package/dist/_lib/payment-lock.js +199 -0
- package/dist/_lib/payment-lock.js.map +1 -0
- package/dist/_lib/payment-record.d.ts +76 -0
- package/dist/_lib/payment-record.d.ts.map +1 -0
- package/dist/_lib/payment-record.js +84 -0
- package/dist/_lib/payment-record.js.map +1 -0
- package/dist/_lib/runtime-env.d.ts.map +1 -1
- package/dist/_lib/runtime-env.js +5 -0
- package/dist/_lib/runtime-env.js.map +1 -1
- package/dist/_lib/subscription-client.d.ts +192 -15
- package/dist/_lib/subscription-client.d.ts.map +1 -1
- package/dist/_lib/subscription-client.js +44 -2
- 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 +48 -0
- package/dist/_lib/xrp-payment.d.ts.map +1 -0
- package/dist/_lib/xrp-payment.js +117 -0
- package/dist/_lib/xrp-payment.js.map +1 -0
- package/dist/_lib/xrpl-login-signer.d.ts +16 -1
- package/dist/_lib/xrpl-login-signer.d.ts.map +1 -1
- package/dist/_lib/xrpl-login-signer.js +25 -1
- package/dist/_lib/xrpl-login-signer.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/deploy.d.ts +1 -1
- package/dist/commands/deploy.js +2 -2
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/faucet.d.ts +1 -1
- package/dist/commands/faucet.d.ts.map +1 -1
- package/dist/commands/faucet.js +2 -7
- package/dist/commands/faucet.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 +39 -3
- package/dist/commands/subscribe.d.ts.map +1 -1
- package/dist/commands/subscribe.js +424 -110
- package/dist/commands/subscribe.js.map +1 -1
- package/dist/commands/topup.d.ts +33 -7
- package/dist/commands/topup.d.ts.map +1 -1
- package/dist/commands/topup.js +148 -16
- 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 +35 -5
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/commands/verify.d.ts.map +1 -1
- package/dist/commands/verify.js +8 -2
- 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
|
@@ -4,6 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.renderOrderDeadline = renderOrderDeadline;
|
|
7
|
+
exports.renderDestinationTag = renderDestinationTag;
|
|
8
|
+
exports.xummSendDeeplink = xummSendDeeplink;
|
|
7
9
|
exports.ensureUnexpiredQuote = ensureUnexpiredQuote;
|
|
8
10
|
/**
|
|
9
11
|
* #3699 PR1b-ii, D8 — deadline display + requote-before-pay guard shared by
|
|
@@ -19,11 +21,13 @@ exports.ensureUnexpiredQuote = ensureUnexpiredQuote;
|
|
|
19
21
|
* inline response for topup) rather than forcing either one into the
|
|
20
22
|
* other's shape.
|
|
21
23
|
*
|
|
22
|
-
* `hsuite upgrade` does not auto-pay today (manual XUMM
|
|
23
|
-
*
|
|
24
|
-
*
|
|
24
|
+
* `hsuite upgrade` does not auto-pay today (manual XUMM flow only), so there is
|
|
25
|
+
* no auto-pay call site to guard — but a manual payer is shown the quote, so it
|
|
26
|
+
* gets the same {@link ensureUnexpiredQuote}, {@link renderDestinationTag} and
|
|
27
|
+
* {@link xummSendDeeplink} (#3917 item 2).
|
|
25
28
|
*/
|
|
26
29
|
const chalk_1 = __importDefault(require("chalk"));
|
|
30
|
+
const xrp_payment_1 = require("./xrp-payment");
|
|
27
31
|
/**
|
|
28
32
|
* Print the quote's deadline (local time + minutes remaining) and the
|
|
29
33
|
* locked rate source alongside the amount. No-op when the server didn't
|
|
@@ -40,6 +44,25 @@ function renderOrderDeadline(quote) {
|
|
|
40
44
|
console.log(chalk_1.default.gray(` rate: ${quote.rate.hsuiteUsd} USD/HST (source: ${quote.rate.source})`));
|
|
41
45
|
}
|
|
42
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* The Destination Tag line of a quote's payment instructions. The order is matched by the tag, so a
|
|
49
|
+
* payment that omits it (typed by hand, from a wallet whose "destination tag" field was left empty)
|
|
50
|
+
* is not attributed to the order. `!== undefined`, not truthiness: `0` is a valid tag (#3765, #3917).
|
|
51
|
+
*/
|
|
52
|
+
function renderDestinationTag(quote) {
|
|
53
|
+
if (quote.destinationTag === undefined)
|
|
54
|
+
return;
|
|
55
|
+
console.log(chalk_1.default.gray(` tag: ${quote.destinationTag} (Destination Tag — REQUIRED on the payment)`));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The XUMM deeplink of an XRPL payment instruction. Carries `dt=` whenever the quote has a
|
|
59
|
+
* destination tag (`0` included): a deeplink without it pays an untagged payment, which the
|
|
60
|
+
* platform attributes only to the sole OPEN order on the address (#3917 item 2).
|
|
61
|
+
*/
|
|
62
|
+
function xummSendDeeplink(d) {
|
|
63
|
+
const tag = d.destinationTag !== undefined ? `&dt=${encodeURIComponent(String(d.destinationTag))}` : '';
|
|
64
|
+
return `xumm://xrpl/send?to=${encodeURIComponent(d.walletAddress)}&amount=${encodeURIComponent(d.amount)}&token=${encodeURIComponent(d.tokenId)}${tag}`;
|
|
65
|
+
}
|
|
43
66
|
/**
|
|
44
67
|
* Before showing or paying a quote: if its order has already expired, requote
|
|
45
68
|
* it and return a quote for the NEW amount/tag instead — never put an expired
|
|
@@ -61,9 +84,18 @@ async function ensureUnexpiredQuote(client, quote) {
|
|
|
61
84
|
// for the deposit account was already counted in the first quote), so the first deposit's
|
|
62
85
|
// `baseAmount` / `reserveSurcharge` line items must not survive next to the new amount.
|
|
63
86
|
const { baseAmount: _base, reserveSurcharge: _surcharge, ...carried } = quote;
|
|
87
|
+
// #3699 PR2 — an XRP order's requote asks the remainder in XRP DROPS (`pay`); `amount` stays the HST the
|
|
88
|
+
// deposit account ends up holding (the requote's re-priced HST target, when it names one).
|
|
89
|
+
const xrp = requoted.pay.asset === 'XRP';
|
|
64
90
|
const next = {
|
|
65
91
|
...carried,
|
|
66
|
-
|
|
92
|
+
...(xrp
|
|
93
|
+
? {
|
|
94
|
+
pay: requoted.pay,
|
|
95
|
+
// Read structurally: this CLI may be built against an SDK that predates `SubscriptionOrder.xrp`.
|
|
96
|
+
amount: requoted.xrp?.hstTarget ?? carried.amount,
|
|
97
|
+
}
|
|
98
|
+
: { amount: requoted.pay.amount }),
|
|
67
99
|
destinationTag: requoted.pay.destinationTag,
|
|
68
100
|
orderId: requoted.orderId,
|
|
69
101
|
expiresAt: requoted.expiresAt,
|
|
@@ -71,8 +103,10 @@ async function ensureUnexpiredQuote(client, quote) {
|
|
|
71
103
|
priceUsd: requoted.priceUsd,
|
|
72
104
|
hsuiteDue: requoted.hsuiteDue,
|
|
73
105
|
};
|
|
74
|
-
|
|
75
|
-
|
|
106
|
+
const deadline = next.expiresAt ? new Date(next.expiresAt).toLocaleString() : 'n/a';
|
|
107
|
+
console.log(chalk_1.default.yellow(xrp
|
|
108
|
+
? ` new amount: ${(0, xrp_payment_1.dropsToXrp)(requoted.pay.amount)} XRP (${requoted.pay.amount} drops, tag ${next.destinationTag}), new deadline: ${deadline}\n`
|
|
109
|
+
: ` new amount: ${next.amount} HST (tag ${next.destinationTag}), new deadline: ${deadline}\n`));
|
|
76
110
|
return next;
|
|
77
111
|
}
|
|
78
112
|
//# sourceMappingURL=order-deadline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"order-deadline.js","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"order-deadline.js","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":";;;;;AA4CA,kDAYC;AAOD,oDAGC;AAOD,4CAKC;AAYD,oDA8CC;AAxID;;;;;;;;;;;;;;;;;;GAkBG;AACH,kDAA0B;AAE1B,+CAA2C;AAiB3C;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAmD;IACrF,IAAI,CAAC,KAAK,CAAC,SAAS;QAAE,OAAO;IAC7B,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC;IACxD,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;IAClF,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,IAAI,CACR,iBAAiB,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,cAAc,EAAE,KAAK,YAAY,iBAAiB,CAC9F,CACF,CAAC;IACF,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,iBAAiB,KAAK,CAAC,IAAI,CAAC,SAAS,qBAAqB,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1G,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,KAA+C;IAClF,IAAI,KAAK,CAAC,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Y, type PendingPayment } from './payment-record';
|
|
2
|
+
/**
|
|
3
|
+
* The env key a flow keeps its record under. One slot per flow: a `topup` must not read a deposit
|
|
4
|
+
* payment `subscribe` could not clear (and the other way round), or an old, credited payment would
|
|
5
|
+
* refuse a new one.
|
|
6
|
+
*/
|
|
7
|
+
export type PaymentRecordKey = typeof PENDING_PAYMENT_KEY | typeof PENDING_TOPUP_PAYMENT_KEY | typeof PENDING_RENEW_PAYMENT_KEY;
|
|
8
|
+
/** The one ledger call the lookup needs; the `xrpl` client and every test fake satisfy it. */
|
|
9
|
+
export type LedgerQueryClient = {
|
|
10
|
+
request(req: Record<string, unknown>): Promise<{
|
|
11
|
+
result: any;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The payment left this process but no verdict came back (a timeout, a dropped websocket …), or an
|
|
16
|
+
* earlier run's payment may still validate: it may land. A plain "fix the cause and re-run" would
|
|
17
|
+
* invite a second payment, so it gets its own message at each command.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PaymentOutcomeUnknownError extends Error {
|
|
20
|
+
constructor(cause: unknown);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The payment an earlier run sent is on the ledger (validated `tesSUCCESS`), but the platform has
|
|
24
|
+
* not credited it. Thrown INSTEAD of paying — whatever the new quote asks.
|
|
25
|
+
*/
|
|
26
|
+
export declare class RecordedPaymentLandedError extends Error {
|
|
27
|
+
readonly txHash: string;
|
|
28
|
+
constructor(txHash: string);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The payment record in the env file, whoever's it is, or `undefined` when there is none. An
|
|
32
|
+
* unreadable value is an ERROR, not "none": it could be hiding a payment that landed.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readRecordedPayment(envPath: string, key: PaymentRecordKey): PendingPayment | undefined;
|
|
35
|
+
/** The payment an earlier run recorded for `appId`: none when there is no record, or it is another entity's. */
|
|
36
|
+
export declare function readPendingPayment(envPath: string, appId: string, key: PaymentRecordKey): PendingPayment | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Settle the payment an earlier run recorded BEFORE paying again: ask the ledger what became of THAT
|
|
39
|
+
* transaction. `delivered` refuses ({@link RecordedPaymentLandedError}); `pending` refuses as unknown
|
|
40
|
+
* ({@link PaymentOutcomeUnknownError}); `failed` and `never-landed` mean it delivered nothing and can
|
|
41
|
+
* never deliver, so the run goes on (and its own record replaces this one). FAILS CLOSED: a lookup
|
|
42
|
+
* that errors is an error, never "carry on and pay".
|
|
43
|
+
*/
|
|
44
|
+
export declare function refuseIfRecordedPaymentMayLand(client: LedgerQueryClient, envPath: string, appId: string, key: PaymentRecordKey): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Record the payment about to be submitted. Fails loud — with NOTHING submitted — when the file
|
|
47
|
+
* cannot be written (as the pending create is recorded, #3766): a payment this CLI cannot keep track
|
|
48
|
+
* of is exactly the one a requote or a resumed run would make it pay a second time. The record is
|
|
49
|
+
* single-slot per flow, so writing this one forgets another entity's unfinished record; that is said,
|
|
50
|
+
* not silent.
|
|
51
|
+
*/
|
|
52
|
+
export declare function recordPendingPayment(envPath: string, payment: PendingPayment, key: PaymentRecordKey): void;
|
|
53
|
+
/**
|
|
54
|
+
* Forget `appId`'s recorded payment once the platform has CREDITED it. Only that entity's: another
|
|
55
|
+
* entity's record is its own guard. Best effort: a record that survives only makes a later run ask
|
|
56
|
+
* the ledger about a payment that is credited anyway.
|
|
57
|
+
*/
|
|
58
|
+
export declare function clearPendingPayment(envPath: string, appId: string, key: PaymentRecordKey): void;
|
|
59
|
+
//# sourceMappingURL=payment-guard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-guard.d.ts","sourceRoot":"","sources":["../../src/_lib/payment-guard.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EAIzB,KAAK,cAAc,EAEpB,MAAM,kBAAkB,CAAC;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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.RecordedPaymentLandedError = exports.PaymentOutcomeUnknownError = void 0;
|
|
7
|
+
exports.readRecordedPayment = readRecordedPayment;
|
|
8
|
+
exports.readPendingPayment = readPendingPayment;
|
|
9
|
+
exports.refuseIfRecordedPaymentMayLand = refuseIfRecordedPaymentMayLand;
|
|
10
|
+
exports.recordPendingPayment = recordPendingPayment;
|
|
11
|
+
exports.clearPendingPayment = clearPendingPayment;
|
|
12
|
+
/**
|
|
13
|
+
* The I/O half of the recorded-payment guard (#3917 items 3 and 5): the env file that remembers
|
|
14
|
+
* the payment a run SENT, and the ledger lookup that says what became of it. The format and the
|
|
15
|
+
* verdicts are `payment-record.ts`; this module is shared by every command that pays from the
|
|
16
|
+
* developer wallet (`subscribe`, `topup`) so that a resumed run never pays twice.
|
|
17
|
+
*
|
|
18
|
+
* The record is written BEFORE the signed blob leaves the process and kept until the platform has
|
|
19
|
+
* credited the payment. On the next run the ledger is asked about THAT transaction — never about the
|
|
20
|
+
* deposit account's balance, which cannot say whose HST it holds.
|
|
21
|
+
*/
|
|
22
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
23
|
+
const env_1 = require("./env");
|
|
24
|
+
const error_message_1 = require("./error-message");
|
|
25
|
+
const payment_record_1 = require("./payment-record");
|
|
26
|
+
/**
|
|
27
|
+
* The payment left this process but no verdict came back (a timeout, a dropped websocket …), or an
|
|
28
|
+
* earlier run's payment may still validate: it may land. A plain "fix the cause and re-run" would
|
|
29
|
+
* invite a second payment, so it gets its own message at each command.
|
|
30
|
+
*/
|
|
31
|
+
class PaymentOutcomeUnknownError extends Error {
|
|
32
|
+
constructor(cause) {
|
|
33
|
+
super((0, error_message_1.errorMessage)(cause), { cause });
|
|
34
|
+
this.name = 'PaymentOutcomeUnknownError';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.PaymentOutcomeUnknownError = PaymentOutcomeUnknownError;
|
|
38
|
+
/**
|
|
39
|
+
* The payment an earlier run sent is on the ledger (validated `tesSUCCESS`), but the platform has
|
|
40
|
+
* not credited it. Thrown INSTEAD of paying — whatever the new quote asks.
|
|
41
|
+
*/
|
|
42
|
+
class RecordedPaymentLandedError extends Error {
|
|
43
|
+
txHash;
|
|
44
|
+
constructor(txHash) {
|
|
45
|
+
super(`payment ${txHash}, sent by an earlier run, is on the ledger`);
|
|
46
|
+
this.txHash = txHash;
|
|
47
|
+
this.name = 'RecordedPaymentLandedError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.RecordedPaymentLandedError = RecordedPaymentLandedError;
|
|
51
|
+
/**
|
|
52
|
+
* The `txnNotFound` answer of a `tx` lookup, in either shape xrpl.js raises it, with the server's
|
|
53
|
+
* `searched_all` (true only when it held every ledger in the range asked for). `undefined` for
|
|
54
|
+
* any other failure.
|
|
55
|
+
*/
|
|
56
|
+
function txnNotFoundOf(err) {
|
|
57
|
+
const data = err?.data;
|
|
58
|
+
if (data?.error === 'txnNotFound')
|
|
59
|
+
return { searchedAll: data.searched_all === true };
|
|
60
|
+
if (/txnNotFound/.test(err instanceof Error ? err.message : ''))
|
|
61
|
+
return { searchedAll: false };
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Ask the ledger for a transaction by hash, over `[LastLedgerSequence - 256, LastLedgerSequence]`
|
|
66
|
+
* when the record carries one (the only range the payment can be in). `found: false` is its
|
|
67
|
+
* `txnNotFound`; any other failure throws.
|
|
68
|
+
*/
|
|
69
|
+
async function lookupTx(client, payment) {
|
|
70
|
+
const lls = payment.lastLedgerSequence;
|
|
71
|
+
let res;
|
|
72
|
+
try {
|
|
73
|
+
res = await client.request({
|
|
74
|
+
command: 'tx',
|
|
75
|
+
transaction: payment.txHash,
|
|
76
|
+
...(lls !== undefined ? { min_ledger: Math.max(1, lls - payment_record_1.LLS_HISTORY_WINDOW), max_ledger: lls } : {}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const notFound = txnNotFoundOf(err);
|
|
81
|
+
if (notFound)
|
|
82
|
+
return { found: false, ...notFound };
|
|
83
|
+
throw err;
|
|
84
|
+
}
|
|
85
|
+
const result = res.result ?? {};
|
|
86
|
+
if (result.error === 'txnNotFound')
|
|
87
|
+
return { found: false, searchedAll: result.searched_all === true };
|
|
88
|
+
if (result.error !== undefined)
|
|
89
|
+
throw new Error(String(result.error));
|
|
90
|
+
return {
|
|
91
|
+
found: true,
|
|
92
|
+
validated: result.validated === true,
|
|
93
|
+
...(typeof result.meta?.TransactionResult === 'string' ? { result: result.meta.TransactionResult } : {}),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** The validated ledger's index, or `undefined` when the ledger does not give a usable one. */
|
|
97
|
+
async function validatedLedgerIndex(client) {
|
|
98
|
+
const res = await client.request({ command: 'ledger', ledger_index: 'validated' });
|
|
99
|
+
const index = Number(res.result?.ledger_index ?? res.result?.ledger?.ledger_index);
|
|
100
|
+
return Number.isFinite(index) ? index : undefined;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The payment record in the env file, whoever's it is, or `undefined` when there is none. An
|
|
104
|
+
* unreadable value is an ERROR, not "none": it could be hiding a payment that landed.
|
|
105
|
+
*/
|
|
106
|
+
function readRecordedPayment(envPath, key) {
|
|
107
|
+
const raw = (0, env_1.readEnv)(envPath).get(key);
|
|
108
|
+
if (raw === undefined || raw === '')
|
|
109
|
+
return undefined;
|
|
110
|
+
const parsed = (0, payment_record_1.parsePendingPayment)(raw);
|
|
111
|
+
if (!parsed) {
|
|
112
|
+
throw new Error(`${key} in ${envPath} is not a payment record this CLI wrote (${JSON.stringify(raw)}) — ` +
|
|
113
|
+
'refusing to pay: it could be hiding a deposit payment that already landed. Check whether ' +
|
|
114
|
+
'the developer wallet already sent HST to the deposit account; if it did not, delete that ' +
|
|
115
|
+
`${key} line from the file and re-run.`);
|
|
116
|
+
}
|
|
117
|
+
return parsed;
|
|
118
|
+
}
|
|
119
|
+
/** The payment an earlier run recorded for `appId`: none when there is no record, or it is another entity's. */
|
|
120
|
+
function readPendingPayment(envPath, appId, key) {
|
|
121
|
+
const recorded = readRecordedPayment(envPath, key);
|
|
122
|
+
return recorded?.appId === appId ? recorded : undefined;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Settle the payment an earlier run recorded BEFORE paying again: ask the ledger what became of THAT
|
|
126
|
+
* transaction. `delivered` refuses ({@link RecordedPaymentLandedError}); `pending` refuses as unknown
|
|
127
|
+
* ({@link PaymentOutcomeUnknownError}); `failed` and `never-landed` mean it delivered nothing and can
|
|
128
|
+
* never deliver, so the run goes on (and its own record replaces this one). FAILS CLOSED: a lookup
|
|
129
|
+
* that errors is an error, never "carry on and pay".
|
|
130
|
+
*/
|
|
131
|
+
async function refuseIfRecordedPaymentMayLand(client, envPath, appId, key) {
|
|
132
|
+
const recorded = readPendingPayment(envPath, appId, key);
|
|
133
|
+
if (!recorded)
|
|
134
|
+
return;
|
|
135
|
+
let verdict;
|
|
136
|
+
try {
|
|
137
|
+
// The validated ledger FIRST: a payment absent from a complete search whose LastLedgerSequence
|
|
138
|
+
// is behind an index read BEFORE the search cannot have validated in between.
|
|
139
|
+
const validated = await validatedLedgerIndex(client);
|
|
140
|
+
verdict = (0, payment_record_1.classifyRecordedPayment)(await lookupTx(client, recorded), recorded, validated);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
throw new Error(`could not look up payment ${recorded.txHash}, which an earlier run recorded (${(0, error_message_1.errorMessage)(err)}) — ` +
|
|
144
|
+
'refusing to pay without knowing it did not land', { cause: err });
|
|
145
|
+
}
|
|
146
|
+
if (verdict === 'delivered')
|
|
147
|
+
throw new RecordedPaymentLandedError(recorded.txHash);
|
|
148
|
+
if (verdict === 'pending') {
|
|
149
|
+
throw new PaymentOutcomeUnknownError(new Error(`payment ${recorded.txHash}, sent by an earlier run, has not settled on the ledger yet`));
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Record the payment about to be submitted. Fails loud — with NOTHING submitted — when the file
|
|
154
|
+
* cannot be written (as the pending create is recorded, #3766): a payment this CLI cannot keep track
|
|
155
|
+
* of is exactly the one a requote or a resumed run would make it pay a second time. The record is
|
|
156
|
+
* single-slot per flow, so writing this one forgets another entity's unfinished record; that is said,
|
|
157
|
+
* not silent.
|
|
158
|
+
*/
|
|
159
|
+
function recordPendingPayment(envPath, payment, key) {
|
|
160
|
+
try {
|
|
161
|
+
const existing = readRecordedPayment(envPath, key);
|
|
162
|
+
if (existing && existing.appId !== payment.appId) {
|
|
163
|
+
console.log(chalk_1.default.yellow(` warning: replacing the unfinished payment record of smart-app entity ${existing.appId} ` +
|
|
164
|
+
`(tx ${existing.txHash}) — resuming that entity can no longer ask the ledger about it.`));
|
|
165
|
+
}
|
|
166
|
+
(0, env_1.upsertEnv)(envPath, { [key]: (0, payment_record_1.formatPendingPayment)(payment) });
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
throw new Error(`cannot record deposit payment ${payment.txHash} in ${envPath} (${(0, error_message_1.errorMessage)(err)}) — refusing ` +
|
|
170
|
+
'to pay: a payment this CLI cannot keep track of could be paid again after a requote or by a resumed run. ' +
|
|
171
|
+
'Nothing was submitted and nothing has been paid.', { cause: err });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Forget `appId`'s recorded payment once the platform has CREDITED it. Only that entity's: another
|
|
176
|
+
* entity's record is its own guard. Best effort: a record that survives only makes a later run ask
|
|
177
|
+
* the ledger about a payment that is credited anyway.
|
|
178
|
+
*/
|
|
179
|
+
function clearPendingPayment(envPath, appId, key) {
|
|
180
|
+
try {
|
|
181
|
+
if (readPendingPayment(envPath, appId, key))
|
|
182
|
+
(0, env_1.removeEnvKeys)(envPath, [key]);
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// see above
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=payment-guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-guard.js","sourceRoot":"","sources":["../../src/_lib/payment-guard.ts"],"names":[],"mappings":";;;;;;AAmHA,kDAaC;AAGD,gDAOC;AASD,wEA2BC;AASD,oDAoBC;AAOD,kDAMC;AAxND;;;;;;;;;GASG;AACH,kDAA0B;AAC1B,+BAA0D;AAC1D,mDAA+C;AAC/C,qDAU0B;AAiB1B;;;;GAIG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IACnD,YAAY,KAAc;QACxB,KAAK,CAAC,IAAA,4BAAY,EAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AALD,gEAKC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAC9B;IAArB,YAAqB,MAAc;QACjC,KAAK,CAAC,WAAW,MAAM,4CAA4C,CAAC,CAAC;QADlD,WAAM,GAAN,MAAM,CAAQ;QAEjC,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AALD,gEAKC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,GAAY;IACjC,MAAM,IAAI,GAAI,GAAiF,EAAE,IAAI,CAAC;IACtG,IAAI,IAAI,EAAE,KAAK,KAAK,aAAa;QAAE,OAAO,EAAE,WAAW,EAAE,IAAI,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;IACtF,IAAI,aAAa,CAAC,IAAI,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QAAE,OAAO,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D,IAAI,QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC;YACjD,OAAO,CAAC,GAAG,CACT,eAAK,CAAC,MAAM,CACV,0EAA0E,QAAQ,CAAC,KAAK,GAAG;gBACzF,OAAO,QAAQ,CAAC,MAAM,iEAAiE,CAC1F,CACF,CAAC;QACJ,CAAC;QACD,IAAA,eAAS,EAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,IAAA,qCAAoB,EAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,iCAAiC,OAAO,CAAC,MAAM,OAAO,OAAO,KAAK,IAAA,4BAAY,EAAC,GAAG,CAAC,eAAe;YAChG,2GAA2G;YAC3G,kDAAkD,EACpD,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,SAAgB,mBAAmB,CAAC,OAAe,EAAE,KAAa,EAAE,GAAqB;IACvF,IAAI,CAAC;QACH,IAAI,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC;YAAE,IAAA,mBAAa,EAAC,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC7E,CAAC;IAAC,MAAM,CAAC;QACP,YAAY;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The lock file is the env file's path plus this. */
|
|
2
|
+
export declare const PAYMENT_LOCK_SUFFIX = ".payment-lock";
|
|
3
|
+
/** Who holds a lock: what the lock file says. */
|
|
4
|
+
export type PaymentLockOwner = {
|
|
5
|
+
pid: number;
|
|
6
|
+
host: string;
|
|
7
|
+
/** The command that took it (`hsuite topup`). */
|
|
8
|
+
command: string;
|
|
9
|
+
/** ISO time it was taken. */
|
|
10
|
+
since: string;
|
|
11
|
+
/** Random per acquisition: lets a holder tell its own lock from one that replaced it. */
|
|
12
|
+
token: string;
|
|
13
|
+
};
|
|
14
|
+
/** Another run holds the payment lock for this env file (or the lock file cannot be read). */
|
|
15
|
+
export declare class PaymentLockHeldError extends Error {
|
|
16
|
+
readonly lockPath: string;
|
|
17
|
+
readonly owner: PaymentLockOwner | undefined;
|
|
18
|
+
constructor(lockPath: string, owner: PaymentLockOwner | undefined, message: string);
|
|
19
|
+
}
|
|
20
|
+
/** The lock path for an env file. Resolved through symlinks, so every spelling of one file shares one lock. */
|
|
21
|
+
export declare function paymentLockPath(envPath: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Run `fn` holding the payment lock of `envPath`. A second caller on the same env file is refused
|
|
24
|
+
* with {@link PaymentLockHeldError} while `fn` runs — before it reads, asks or pays anything.
|
|
25
|
+
*/
|
|
26
|
+
export declare function withPaymentLock<T>(envPath: string, command: string, fn: () => Promise<T>): Promise<T>;
|
|
27
|
+
//# sourceMappingURL=payment-lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-lock.d.ts","sourceRoot":"","sources":["../../src/_lib/payment-lock.ts"],"names":[],"mappings":"AAiCA,sDAAsD;AACtD,eAAO,MAAM,mBAAmB,kBAAkB,CAAC;AAEnD,iDAAiD;AACjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,yFAAyF;IACzF,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,8FAA8F;AAC9F,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS;gBADnC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,gBAAgB,GAAG,SAAS,EAC5C,OAAO,EAAE,MAAM;CAKlB;AAED,+GAA+G;AAC/G,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvD;AAkID;;;GAGG;AACH,wBAAsB,eAAe,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAiB3G"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentLockHeldError = exports.PAYMENT_LOCK_SUFFIX = void 0;
|
|
4
|
+
exports.paymentLockPath = paymentLockPath;
|
|
5
|
+
exports.withPaymentLock = withPaymentLock;
|
|
6
|
+
/**
|
|
7
|
+
* An exclusive lock on the env file for a run that PAYS (#3917 item 3).
|
|
8
|
+
*
|
|
9
|
+
* `hsuite subscribe` and `hsuite topup` keep a record of the payment they send in the env file and,
|
|
10
|
+
* before paying, read that record and ask the ledger what became of it (`payment-guard.ts`). That
|
|
11
|
+
* guard is a read followed, much later, by a write: two runs on one env file (two terminals, a CI
|
|
12
|
+
* job and a laptop, a retry loop) can both read "nothing recorded", both pass, and both pay. The
|
|
13
|
+
* lock makes the whole guarded section — read the record, ask the ledger, record the new payment,
|
|
14
|
+
* submit it — one run at a time per env file.
|
|
15
|
+
*
|
|
16
|
+
* It is a lock FILE next to the env file (`<env>.payment-lock`), created with `O_EXCL` so that
|
|
17
|
+
* exactly one creator wins, naming its owner so the run that loses can say who holds it. It is
|
|
18
|
+
* released in a `finally`, on process exit and on SIGINT / SIGTERM / SIGHUP. A run killed outright
|
|
19
|
+
* (SIGKILL, power loss) leaves it behind, and it is NEVER taken over automatically: the run that
|
|
20
|
+
* finds it is refused with the owner and the path to delete (and, for an owner on this host that is
|
|
21
|
+
* no longer running, says so). A takeover cannot be made atomic with a file lock, two runs finding
|
|
22
|
+
* the same stale lock can each take the other's live one, and the cost of getting that wrong is a
|
|
23
|
+
* second payment, against the cost of deleting one file after a crash.
|
|
24
|
+
*/
|
|
25
|
+
const crypto_1 = require("crypto");
|
|
26
|
+
const fs_1 = require("fs");
|
|
27
|
+
const os_1 = require("os");
|
|
28
|
+
const error_message_1 = require("./error-message");
|
|
29
|
+
/** The lock file is the env file's path plus this. */
|
|
30
|
+
exports.PAYMENT_LOCK_SUFFIX = '.payment-lock';
|
|
31
|
+
/** Another run holds the payment lock for this env file (or the lock file cannot be read). */
|
|
32
|
+
class PaymentLockHeldError extends Error {
|
|
33
|
+
lockPath;
|
|
34
|
+
owner;
|
|
35
|
+
constructor(lockPath, owner, message) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.lockPath = lockPath;
|
|
38
|
+
this.owner = owner;
|
|
39
|
+
this.name = 'PaymentLockHeldError';
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.PaymentLockHeldError = PaymentLockHeldError;
|
|
43
|
+
/** The lock path for an env file. Resolved through symlinks, so every spelling of one file shares one lock. */
|
|
44
|
+
function paymentLockPath(envPath) {
|
|
45
|
+
return `${(0, fs_1.realpathSync)(envPath)}${exports.PAYMENT_LOCK_SUFFIX}`;
|
|
46
|
+
}
|
|
47
|
+
function parseOwner(raw) {
|
|
48
|
+
try {
|
|
49
|
+
const value = JSON.parse(raw);
|
|
50
|
+
if (value &&
|
|
51
|
+
Number.isSafeInteger(value.pid) &&
|
|
52
|
+
value.pid > 0 &&
|
|
53
|
+
typeof value.host === 'string' &&
|
|
54
|
+
typeof value.command === 'string' &&
|
|
55
|
+
typeof value.since === 'string' &&
|
|
56
|
+
typeof value.token === 'string') {
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// not ours
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
function readOwner(lockPath) {
|
|
66
|
+
let raw;
|
|
67
|
+
try {
|
|
68
|
+
raw = (0, fs_1.readFileSync)(lockPath, 'utf8');
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (err.code === 'ENOENT')
|
|
72
|
+
return undefined;
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
return { raw, owner: parseOwner(raw) };
|
|
76
|
+
}
|
|
77
|
+
/** Is `pid` a live process? `EPERM` means it exists and is somebody else's. */
|
|
78
|
+
function processAlive(pid) {
|
|
79
|
+
try {
|
|
80
|
+
process.kill(pid, 0);
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
return err.code !== 'ESRCH';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Create the lock file with `O_EXCL`. `false` when it already exists. */
|
|
88
|
+
function createExclusive(lockPath, owner) {
|
|
89
|
+
let fd;
|
|
90
|
+
try {
|
|
91
|
+
fd = (0, fs_1.openSync)(lockPath, 'wx', 0o600);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (err.code === 'EEXIST')
|
|
95
|
+
return false;
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
(0, fs_1.writeSync)(fd, `${JSON.stringify(owner)}\n`);
|
|
100
|
+
(0, fs_1.fsyncSync)(fd);
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
(0, fs_1.closeSync)(fd);
|
|
104
|
+
}
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
function describeOwner(owner) {
|
|
108
|
+
return `pid ${owner.pid} on ${owner.host}, \`${owner.command}\`, since ${owner.since}`;
|
|
109
|
+
}
|
|
110
|
+
function heldError(envPath, lockPath, owner) {
|
|
111
|
+
const who = owner ? describeOwner(owner) : 'an owner this CLI cannot read from the lock file';
|
|
112
|
+
const gone = owner && owner.host === (0, os_1.hostname)() && !processAlive(owner.pid);
|
|
113
|
+
return new PaymentLockHeldError(lockPath, owner, `another hsuite run is already paying from ${envPath} (${who}). Two runs on one env file can both pass ` +
|
|
114
|
+
'the paid-twice guard and pay twice, so this one is refused until the other finishes — nothing was ' +
|
|
115
|
+
'requested and nothing was paid. ' +
|
|
116
|
+
(gone
|
|
117
|
+
? `That process is no longer running (a run killed outright leaves its lock behind): check what it paid ` +
|
|
118
|
+
`(\`hsuite status\`, the wallet's history), then delete ${lockPath} and re-run.`
|
|
119
|
+
: `If no hsuite run is active (a run killed outright leaves its lock behind), delete ${lockPath} and re-run.`));
|
|
120
|
+
}
|
|
121
|
+
/** Take the lock, or throw {@link PaymentLockHeldError}. Returns the release function. */
|
|
122
|
+
function acquire(envPath, command) {
|
|
123
|
+
if (!(0, fs_1.existsSync)(envPath))
|
|
124
|
+
throw new Error(`env file not found: ${envPath}`);
|
|
125
|
+
const lockPath = paymentLockPath(envPath);
|
|
126
|
+
const owner = {
|
|
127
|
+
pid: process.pid,
|
|
128
|
+
host: (0, os_1.hostname)(),
|
|
129
|
+
command,
|
|
130
|
+
since: new Date().toISOString(),
|
|
131
|
+
token: (0, crypto_1.randomBytes)(8).toString('hex'),
|
|
132
|
+
};
|
|
133
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
134
|
+
if (createExclusive(lockPath, owner))
|
|
135
|
+
return releaser(lockPath, owner.token);
|
|
136
|
+
const held = readOwner(lockPath);
|
|
137
|
+
// Released between our create and our read: try once more. Anything else is someone's lock.
|
|
138
|
+
if (held)
|
|
139
|
+
throw heldError(envPath, lockPath, held.owner);
|
|
140
|
+
}
|
|
141
|
+
throw heldError(envPath, lockPath, readOwner(lockPath)?.owner);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Release only a lock that is still ours: a lock another run took over (it saw this process dead) is
|
|
145
|
+
* theirs to release. Idempotent; never throws.
|
|
146
|
+
*/
|
|
147
|
+
function releaser(lockPath, token) {
|
|
148
|
+
let released = false;
|
|
149
|
+
const onSignal = (signal) => {
|
|
150
|
+
release();
|
|
151
|
+
// The default action the handler replaced: end the process as the signal would have.
|
|
152
|
+
process.kill(process.pid, signal);
|
|
153
|
+
};
|
|
154
|
+
const signals = ['SIGINT', 'SIGTERM', 'SIGHUP'];
|
|
155
|
+
const release = () => {
|
|
156
|
+
if (released)
|
|
157
|
+
return;
|
|
158
|
+
released = true;
|
|
159
|
+
process.removeListener('exit', release);
|
|
160
|
+
for (const signal of signals)
|
|
161
|
+
process.removeListener(signal, onSignal);
|
|
162
|
+
try {
|
|
163
|
+
if (readOwner(lockPath)?.owner?.token === token)
|
|
164
|
+
(0, fs_1.unlinkSync)(lockPath);
|
|
165
|
+
}
|
|
166
|
+
catch {
|
|
167
|
+
// best effort: a lock that survives only makes the next run say who held it
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
process.once('exit', release);
|
|
171
|
+
for (const signal of signals)
|
|
172
|
+
process.once(signal, onSignal);
|
|
173
|
+
return release;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Run `fn` holding the payment lock of `envPath`. A second caller on the same env file is refused
|
|
177
|
+
* with {@link PaymentLockHeldError} while `fn` runs — before it reads, asks or pays anything.
|
|
178
|
+
*/
|
|
179
|
+
async function withPaymentLock(envPath, command, fn) {
|
|
180
|
+
let release;
|
|
181
|
+
try {
|
|
182
|
+
release = acquire(envPath, command);
|
|
183
|
+
}
|
|
184
|
+
catch (err) {
|
|
185
|
+
if (err instanceof PaymentLockHeldError || (err instanceof Error && /^env file not found/.test(err.message))) {
|
|
186
|
+
throw err;
|
|
187
|
+
}
|
|
188
|
+
throw new Error(`cannot take the payment lock for ${envPath} (${(0, error_message_1.errorMessage)(err)}) — refusing to pay`, {
|
|
189
|
+
cause: err,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
return await fn();
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
release();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=payment-lock.js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