@hsuite/smart-engines-cli 1.7.0 → 1.9.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.
Files changed (99) hide show
  1. package/README.md +56 -7
  2. package/dist/__tests__/helpers/fixtures-image-hygiene.d.ts +18 -0
  3. package/dist/__tests__/helpers/fixtures-image-hygiene.d.ts.map +1 -0
  4. package/dist/__tests__/helpers/fixtures-image-hygiene.js +42 -0
  5. package/dist/__tests__/helpers/fixtures-image-hygiene.js.map +1 -0
  6. package/dist/_lib/baas.d.ts +12 -17
  7. package/dist/_lib/baas.d.ts.map +1 -1
  8. package/dist/_lib/baas.js +13 -1
  9. package/dist/_lib/baas.js.map +1 -1
  10. package/dist/_lib/cluster-provisioning-report.d.ts +29 -0
  11. package/dist/_lib/cluster-provisioning-report.d.ts.map +1 -0
  12. package/dist/_lib/cluster-provisioning-report.js +35 -0
  13. package/dist/_lib/cluster-provisioning-report.js.map +1 -0
  14. package/dist/_lib/create-outcome.d.ts +43 -0
  15. package/dist/_lib/create-outcome.d.ts.map +1 -0
  16. package/dist/_lib/create-outcome.js +121 -0
  17. package/dist/_lib/create-outcome.js.map +1 -0
  18. package/dist/_lib/decimal-compare.d.ts +23 -0
  19. package/dist/_lib/decimal-compare.d.ts.map +1 -0
  20. package/dist/_lib/decimal-compare.js +69 -0
  21. package/dist/_lib/decimal-compare.js.map +1 -0
  22. package/dist/_lib/env.d.ts +6 -0
  23. package/dist/_lib/env.d.ts.map +1 -1
  24. package/dist/_lib/env.js +68 -1
  25. package/dist/_lib/env.js.map +1 -1
  26. package/dist/_lib/framework.js +2 -2
  27. package/dist/_lib/image-hygiene.d.ts +36 -0
  28. package/dist/_lib/image-hygiene.d.ts.map +1 -0
  29. package/dist/_lib/image-hygiene.js +233 -0
  30. package/dist/_lib/image-hygiene.js.map +1 -0
  31. package/dist/_lib/order-deadline.d.ts +35 -0
  32. package/dist/_lib/order-deadline.d.ts.map +1 -0
  33. package/dist/_lib/order-deadline.js +78 -0
  34. package/dist/_lib/order-deadline.js.map +1 -0
  35. package/dist/_lib/run-fn.d.ts +34 -0
  36. package/dist/_lib/run-fn.d.ts.map +1 -0
  37. package/dist/_lib/run-fn.js +15 -0
  38. package/dist/_lib/run-fn.js.map +1 -0
  39. package/dist/_lib/runtime-env.d.ts.map +1 -1
  40. package/dist/_lib/runtime-env.js +3 -0
  41. package/dist/_lib/runtime-env.js.map +1 -1
  42. package/dist/_lib/subscription-client.d.ts +123 -1
  43. package/dist/_lib/subscription-client.d.ts.map +1 -1
  44. package/dist/_lib/subscription-client.js +51 -41
  45. package/dist/_lib/subscription-client.js.map +1 -1
  46. package/dist/_lib/transport.d.ts +62 -0
  47. package/dist/_lib/transport.d.ts.map +1 -0
  48. package/dist/_lib/transport.js +120 -0
  49. package/dist/_lib/transport.js.map +1 -0
  50. package/dist/_lib/xrpl-login-signer.d.ts +39 -0
  51. package/dist/_lib/xrpl-login-signer.d.ts.map +1 -0
  52. package/dist/_lib/xrpl-login-signer.js +78 -0
  53. package/dist/_lib/xrpl-login-signer.js.map +1 -0
  54. package/dist/commands/app-lifecycle.d.ts.map +1 -1
  55. package/dist/commands/app-lifecycle.js +8 -2
  56. package/dist/commands/app-lifecycle.js.map +1 -1
  57. package/dist/commands/customer-scope.d.ts +48 -0
  58. package/dist/commands/customer-scope.d.ts.map +1 -0
  59. package/dist/commands/customer-scope.js +89 -0
  60. package/dist/commands/customer-scope.js.map +1 -0
  61. package/dist/commands/deploy.d.ts.map +1 -1
  62. package/dist/commands/deploy.js +11 -2
  63. package/dist/commands/deploy.js.map +1 -1
  64. package/dist/commands/personhood.d.ts +2 -2
  65. package/dist/commands/personhood.d.ts.map +1 -1
  66. package/dist/commands/personhood.js +12 -10
  67. package/dist/commands/personhood.js.map +1 -1
  68. package/dist/commands/redeploy.d.ts.map +1 -1
  69. package/dist/commands/redeploy.js +9 -2
  70. package/dist/commands/redeploy.js.map +1 -1
  71. package/dist/commands/subscribe.d.ts +52 -5
  72. package/dist/commands/subscribe.d.ts.map +1 -1
  73. package/dist/commands/subscribe.js +656 -70
  74. package/dist/commands/subscribe.js.map +1 -1
  75. package/dist/commands/topup.d.ts.map +1 -1
  76. package/dist/commands/topup.js +16 -1
  77. package/dist/commands/topup.js.map +1 -1
  78. package/dist/commands/transactions.d.ts +28 -31
  79. package/dist/commands/transactions.d.ts.map +1 -1
  80. package/dist/commands/transactions.js +36 -40
  81. package/dist/commands/transactions.js.map +1 -1
  82. package/dist/commands/upgrade.d.ts.map +1 -1
  83. package/dist/commands/upgrade.js +9 -1
  84. package/dist/commands/upgrade.js.map +1 -1
  85. package/dist/commands/verify.d.ts +23 -3
  86. package/dist/commands/verify.d.ts.map +1 -1
  87. package/dist/commands/verify.js +178 -34
  88. package/dist/commands/verify.js.map +1 -1
  89. package/dist/index.js +7 -4
  90. package/dist/index.js.map +1 -1
  91. package/package.json +2 -2
  92. package/dist/commands/governance.d.ts +0 -42
  93. package/dist/commands/governance.d.ts.map +0 -1
  94. package/dist/commands/governance.js +0 -144
  95. package/dist/commands/governance.js.map +0 -1
  96. package/dist/commands/hist-balance.d.ts +0 -52
  97. package/dist/commands/hist-balance.d.ts.map +0 -1
  98. package/dist/commands/hist-balance.js +0 -134
  99. package/dist/commands/hist-balance.js.map +0 -1
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ /**
3
+ * Exact comparison of two decimal amount strings — for on-ledger balances.
4
+ *
5
+ * XRPL reports an IOU balance as a decimal STRING, with fractions as a matter of course
6
+ * (the 0.25% HST transfer fee alone leaves them) and exponent notation for small values
7
+ * (`"1e-7"`). `Number()` loses precision above 2^53 and `BigInt()` throws on a fraction, so
8
+ * neither is safe to decide "does this account already hold what the quote asks?" with. The
9
+ * validator's `membership/decimal-units.ts` solves the same problem for its deposit check; this
10
+ * is the CLI's own copy, because the CLI deliberately has no runtime dependency on
11
+ * `@hsuite/smart-engines-multi-chain-core`.
12
+ *
13
+ * A ledger answer is untrusted input: both the length of the string and the size of its
14
+ * exponent are bounded, so `"1e999999"` is refused instead of becoming a `10n ** 999999n`.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.compareDecimals = compareDecimals;
18
+ /** `-?digits[.digits][e±digits]` — at least one digit before or after the point. */
19
+ const DECIMAL = /^(-?)(\d*)(?:\.(\d*))?(?:[eE]([+-]?\d+))?$/;
20
+ /** Longest string accepted. An XRPL IOU value has at most 16 significant digits plus an exponent. */
21
+ const MAX_LENGTH = 64;
22
+ /** Largest |exponent| accepted — XRPL IOU values stay within roughly 1e-96 … 1e96. */
23
+ const MAX_EXPONENT = 100;
24
+ function parse(raw) {
25
+ // The strings come off the wire (`depositInstructions.amount`, a ledger `balance`): a number or
26
+ // a null from a misbehaving server must read as "cannot tell", not throw out of `trim()`.
27
+ if (typeof raw !== 'string')
28
+ return undefined;
29
+ const text = raw.trim();
30
+ if (text.length === 0 || text.length > MAX_LENGTH)
31
+ return undefined;
32
+ const match = DECIMAL.exec(text);
33
+ if (!match)
34
+ return undefined;
35
+ const [, sign, whole = '', fraction = '', exponentText] = match;
36
+ if (whole === '' && fraction === '')
37
+ return undefined;
38
+ const exponent = exponentText === undefined ? 0 : Number(exponentText);
39
+ if (!Number.isSafeInteger(exponent) || Math.abs(exponent) > MAX_EXPONENT)
40
+ return undefined;
41
+ return {
42
+ negative: sign === '-',
43
+ digits: BigInt(`${whole}${fraction}`),
44
+ // value = digits × 10^(exponent − fraction digits)
45
+ exponent: exponent - fraction.length,
46
+ };
47
+ }
48
+ /**
49
+ * Compare two decimal amount strings exactly.
50
+ *
51
+ * @returns `-1` / `0` / `1` as `a` is below / equal to / above `b`, or `undefined` when either
52
+ * is not a plain decimal number (empty, garbled, or outside the bounds above) — the caller must
53
+ * treat that as "cannot tell", never as a number.
54
+ */
55
+ function compareDecimals(a, b) {
56
+ const left = parse(a);
57
+ const right = parse(b);
58
+ if (!left || !right)
59
+ return undefined;
60
+ const floor = Math.min(left.exponent, right.exponent);
61
+ const scale = (p) => {
62
+ const magnitude = p.digits * 10n ** BigInt(p.exponent - floor);
63
+ return p.negative ? -magnitude : magnitude;
64
+ };
65
+ const x = scale(left);
66
+ const y = scale(right);
67
+ return x < y ? -1 : x > y ? 1 : 0;
68
+ }
69
+ //# sourceMappingURL=decimal-compare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decimal-compare.js","sourceRoot":"","sources":["../../src/_lib/decimal-compare.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;AAwCH,0CAYC;AAlDD,oFAAoF;AACpF,MAAM,OAAO,GAAG,4CAA4C,CAAC;AAE7D,qGAAqG;AACrG,MAAM,UAAU,GAAG,EAAE,CAAC;AAEtB,sFAAsF;AACtF,MAAM,YAAY,GAAG,GAAG,CAAC;AAIzB,SAAS,KAAK,CAAC,GAAY;IACzB,gGAAgG;IAChG,0FAA0F;IAC1F,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAC9C,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACxB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,UAAU;QAAE,OAAO,SAAS,CAAC;IACpE,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,GAAG,EAAE,EAAE,QAAQ,GAAG,EAAE,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC;IAChE,IAAI,KAAK,KAAK,EAAE,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IACtD,MAAM,QAAQ,GAAG,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACvE,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC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2
2
  export declare function readEnv(path: string): EnvMap;
3
3
  export declare function upsertEnv(path: string, updates: Record<string, string>): void;
4
+ /**
5
+ * Delete every line that sets one of `keys`; everything else — comments, ordering, the final
6
+ * newline — is kept verbatim. A no-op (the file is not rewritten) when the file is missing or
7
+ * none of the keys is set.
8
+ */
9
+ export declare function removeEnvKeys(path: string, keys: readonly string[]): void;
4
10
  export type AuthSigner = {
5
11
  chain: 'xrpl';
6
12
  walletAddress: string;
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":"AAcA,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAuB7E;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAyB1D"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":"AA2BA,MAAM,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEzC,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgB5C;AA4CD,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAuB7E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAYzE;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;CACrC,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAyB1D"}
package/dist/_lib/env.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readEnv = readEnv;
4
4
  exports.upsertEnv = upsertEnv;
5
+ exports.removeEnvKeys = removeEnvKeys;
5
6
  exports.buildSignerFromEnv = buildSignerFromEnv;
6
7
  /**
7
8
  * Tiny .env parser/writer + XRPL signer factory.
@@ -14,6 +15,7 @@ exports.buildSignerFromEnv = buildSignerFromEnv;
14
15
  * still available for downstream consumers that want to authenticate via
15
16
  * other chains, but the CLI's prescriptive boilerplate writes XRPL only.
16
17
  */
18
+ const crypto_1 = require("crypto");
17
19
  const fs_1 = require("fs");
18
20
  const xrpl_1 = require("xrpl");
19
21
  function readEnv(path) {
@@ -36,6 +38,50 @@ function readEnv(path) {
36
38
  }
37
39
  return out;
38
40
  }
41
+ /**
42
+ * Replace the contents of `path` without ever leaving it truncated.
43
+ *
44
+ * The env file holds `XRPL_SEED`, and `writeFileSync` truncates the file BEFORE it writes: a full
45
+ * disk or a kill in that window leaves the developer's wallet seed gone. This writes a temp file
46
+ * in the same directory, fsyncs it, then renames it over the target (an atomic replace), so a
47
+ * reader — and a crash — only ever sees the old file or the new one. A symlinked env file is
48
+ * updated through the link (the link is kept, not replaced by a regular file), and an existing
49
+ * file keeps its permission bits.
50
+ */
51
+ function writeFileAtomic(path, contents) {
52
+ const exists = (0, fs_1.existsSync)(path);
53
+ const target = exists ? (0, fs_1.realpathSync)(path) : path;
54
+ const mode = exists ? (0, fs_1.statSync)(target).mode & 0o777 : undefined;
55
+ const temp = `${target}.${process.pid}.${(0, crypto_1.randomBytes)(4).toString('hex')}.tmp`;
56
+ const fd = (0, fs_1.openSync)(temp, 'wx', 0o666);
57
+ try {
58
+ if (mode !== undefined)
59
+ (0, fs_1.fchmodSync)(fd, mode);
60
+ (0, fs_1.writeSync)(fd, contents);
61
+ (0, fs_1.fsyncSync)(fd);
62
+ }
63
+ catch (err) {
64
+ (0, fs_1.closeSync)(fd);
65
+ discard(temp);
66
+ throw err;
67
+ }
68
+ (0, fs_1.closeSync)(fd);
69
+ try {
70
+ (0, fs_1.renameSync)(temp, target);
71
+ }
72
+ catch (err) {
73
+ discard(temp);
74
+ throw err;
75
+ }
76
+ }
77
+ function discard(path) {
78
+ try {
79
+ (0, fs_1.unlinkSync)(path);
80
+ }
81
+ catch {
82
+ // already gone
83
+ }
84
+ }
39
85
  function upsertEnv(path, updates) {
40
86
  const lines = (0, fs_1.existsSync)(path) ? (0, fs_1.readFileSync)(path, 'utf8').split('\n') : [];
41
87
  const seen = new Set();
@@ -60,7 +106,28 @@ function upsertEnv(path, updates) {
60
106
  let out = next.join('\n');
61
107
  if (!out.endsWith('\n'))
62
108
  out += '\n';
63
- (0, fs_1.writeFileSync)(path, out);
109
+ writeFileAtomic(path, out);
110
+ }
111
+ /**
112
+ * Delete every line that sets one of `keys`; everything else — comments, ordering, the final
113
+ * newline — is kept verbatim. A no-op (the file is not rewritten) when the file is missing or
114
+ * none of the keys is set.
115
+ */
116
+ function removeEnvKeys(path, keys) {
117
+ if (!(0, fs_1.existsSync)(path))
118
+ return;
119
+ const drop = new Set(keys);
120
+ const lines = (0, fs_1.readFileSync)(path, 'utf8').split('\n');
121
+ const kept = lines.filter((raw) => {
122
+ const line = raw.trim();
123
+ const eq = line.indexOf('=');
124
+ if (!line || line.startsWith('#') || eq <= 0)
125
+ return true;
126
+ return !drop.has(line.slice(0, eq).trim());
127
+ });
128
+ if (kept.length === lines.length)
129
+ return;
130
+ writeFileAtomic(path, kept.join('\n'));
64
131
  }
65
132
  function buildSignerFromEnv(env) {
66
133
  const seed = env.get('XRPL_SEED');
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/_lib/env.ts"],"names":[],"mappings":";;AAgBA,0BAgBC;AAED,8BAuBC;AASD,gDAyBC;AA3FD;;;;;;;;;;GAUG;AACH,2BAA6D;AAC7D,+BAA8B;AAI9B,SAAgB,OAAO,CAAC,IAAY;IAClC,IAAI,CAAC,IAAA,eAAU,EAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC;IACtE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,IAAA,iBAAY,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5C,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,GAAG,CAAC;YAAE,SAAS;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACrC,IAAI,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC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C,MAAM;QAAE,OAAO;IACzC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AACzC,CAAC;AASD,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAClC,MAAM,OAAO,GAAG,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACxC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,kFAAkF,CACnF,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,aAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACrC,OAAO;QACL,KAAK,EAAE,MAAM;QACb,aAAa,EAAE,OAAO;QACtB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,MAAM,EAAE,CAAC,OAAe,EAAE,EAAE;YAC1B,uEAAuE;YACvE,yEAAyE;YACzE,8DAA8D;YAC9D,sEAAsE;YACtE,wDAAwD;YACxD,8DAA8D;YAC9D,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAC5C,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;YAC/E,OAAO,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -15,8 +15,8 @@ exports.resolveSdkVersion = resolveSdkVersion;
15
15
  *
16
16
  * Detection is dependency-driven (reads the project's `package.json`), matching
17
17
  * the real showcase apps:
18
- * - backend (`apps/showcase/smart-app`): `@hsuite/smart-engines-sdk` + `@nestjs/core`
19
- * - frontend (`apps/showcase/ionic-dapp`): `@hsuite/native-connect-*` + `@ionic/angular`
18
+ * - backend (`smart-app/` in showcase-smart-app): `@hsuite/smart-engines-sdk` + `@nestjs/core`
19
+ * - frontend (`ionic-dapp/` in showcase-smart-app): `@hsuite/native-connect-*` + `@ionic/angular`
20
20
  *
21
21
  * This module is PURE I/O-at-the-edge: it reads one file and classifies. No
22
22
  * network, no clock.
@@ -0,0 +1,36 @@
1
+ import type { RunFn } from './run-fn';
2
+ /** Compiled-output directories a smart-app image conventionally ships under its `WorkingDir`. */
3
+ export declare const IMAGE_HYGIENE_SCAN_DIRS: readonly ["dist", "build", "lib"];
4
+ /** Entry suffixes that must never ship in a customer image. */
5
+ export declare const IMAGE_HYGIENE_FORBIDDEN_SUFFIXES: readonly [".map", ".d.ts", ".tsbuildinfo"];
6
+ /** Thrown when the built image ships source maps / declarations. `violations` lists every entry. */
7
+ export declare class ImageHygieneError extends Error {
8
+ readonly image: string;
9
+ readonly violations: string[];
10
+ constructor(image: string, violations: string[]);
11
+ }
12
+ /**
13
+ * Entry names of a (ustar / PAX / GNU) tar archive. Contents are skipped by
14
+ * size; only names are returned. Tolerant: stops at the first zero block or a
15
+ * truncated header, so a non-archive buffer yields `[]`.
16
+ */
17
+ export declare function listTarEntries(tar: Buffer): string[];
18
+ /** Entries that must never ship in a customer image. */
19
+ export declare function findImageHygieneViolations(entries: readonly string[]): string[];
20
+ export type AssertImageHygieneOpts = {
21
+ /** Local image ref to scan (the freshly built `hsuite-local/<name>:<tag>`). */
22
+ image: string;
23
+ /** `execFileSync`-shaped seam (see {@link RunFn}). */
24
+ run: RunFn;
25
+ /** Env threaded to every docker leg (carries `DOCKER_HOST`). */
26
+ env: NodeJS.ProcessEnv;
27
+ /** Progress / warning sink. */
28
+ log?: (message: string) => void;
29
+ };
30
+ /**
31
+ * Scan the built image's compiled output and THROW {@link ImageHygieneError}
32
+ * if it ships source maps, declaration files or tsbuildinfo. See the module
33
+ * header for the mechanism and the fail-closed contract.
34
+ */
35
+ export declare function assertImageHygiene(opts: AssertImageHygieneOpts): void;
36
+ //# sourceMappingURL=image-hygiene.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-hygiene.d.ts","sourceRoot":"","sources":["../../src/_lib/image-hygiene.ts"],"names":[],"mappings":"AA8BA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,iGAAiG;AACjG,eAAO,MAAM,uBAAuB,mCAAoC,CAAC;AAEzE,+DAA+D;AAC/D,eAAO,MAAM,gCAAgC,4CAA6C,CAAC;AAqB3F,oGAAoG;AACpG,qBAAa,iBAAkB,SAAQ,KAAK;IAExC,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE;gBADpB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,EAAE;CAWhC;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CA0BpD;AAED,wDAAwD;AACxD,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAE/E;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;IACd,sDAAsD;IACtD,GAAG,EAAE,KAAK,CAAC;IACX,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,+BAA+B;IAC/B,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAyCrE"}
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ImageHygieneError = exports.IMAGE_HYGIENE_FORBIDDEN_SUFFIXES = exports.IMAGE_HYGIENE_SCAN_DIRS = void 0;
4
+ exports.listTarEntries = listTarEntries;
5
+ exports.findImageHygieneViolations = findImageHygieneViolations;
6
+ exports.assertImageHygiene = assertImageHygiene;
7
+ /**
8
+ * `hsuite deploy` image-hygiene gate — HSUITEPT-5 (#3245).
9
+ *
10
+ * The pentest pulled a customer image whose compiled output shipped 98
11
+ * `.js.map`, 49 `.d.ts` and JSDoc-preserved `.js` files: the backend read like
12
+ * source, handing an attacker every guard condition and fallback path before
13
+ * touching the live app. The registry side (tenant Harbor projects served to
14
+ * anonymous pullers) is closed in the provisioner; this closes the image side
15
+ * at the one choke point the platform owns for a customer build — the CLI,
16
+ * right after `docker build` and BEFORE anything is tagged, logged in, or
17
+ * pushed. App-side tsconfig/Dockerfile hygiene is never relied on.
18
+ *
19
+ * Mechanism (no shell inside the image — a distroless runtime has none):
20
+ * docker inspect -f '{{.Config.WorkingDir}}' <image> → where the app lives
21
+ * docker create <image> → throwaway container
22
+ * docker cp <id>:<workdir>/<dir> - → tar of each compiled
23
+ * output dir (dist/…)
24
+ * docker rm -f <id> → always, even on throw
25
+ * The tar is parsed for ENTRY NAMES only; contents are never inspected. Only
26
+ * the conventional compiled-output dirs are scanned, so `node_modules/` (whose
27
+ * published packages legitimately ship `.d.ts` / `.map`) is never a false hit.
28
+ *
29
+ * Fail closed: any offending entry aborts the deploy with the full list and
30
+ * the fix. An absent output dir is "nothing to scan" (a warning when none of
31
+ * the conventional dirs exists at all — the gate could not see the app code).
32
+ * A `docker cp` that fails for any OTHER reason is also fatal — only docker's
33
+ * own not-found signature means "absent"; anything else is a scan that did not
34
+ * happen, and the gate must never report one it did not perform.
35
+ */
36
+ const path_1 = require("path");
37
+ /** Compiled-output directories a smart-app image conventionally ships under its `WorkingDir`. */
38
+ exports.IMAGE_HYGIENE_SCAN_DIRS = ['dist', 'build', 'lib'];
39
+ /** Entry suffixes that must never ship in a customer image. */
40
+ exports.IMAGE_HYGIENE_FORBIDDEN_SUFFIXES = ['.map', '.d.ts', '.tsbuildinfo'];
41
+ /** `docker cp` of a compiled dist/ is a few MB; the default 1 MiB `execFileSync` buffer is not enough. */
42
+ const TAR_MAX_BUFFER_BYTES = 256 * 1024 * 1024;
43
+ /**
44
+ * Docker's "this path is not in the image" signature — the ONE `docker cp`
45
+ * failure that legitimately means "nothing to scan". Matched against the
46
+ * child's stderr, which docker populates for this wording.
47
+ *
48
+ * Deliberately NOT also matching a bare `no such file or directory`: that is
49
+ * the daemon's OS-level errno text, which appears when the READ failed (a
50
+ * pruned or corrupt overlay2 graph) rather than when the path is absent. The
51
+ * two must not collapse — a real not-found read as fatal only aborts a deploy
52
+ * the operator can re-run, while a broken read taken as "absent" silently
53
+ * disables the gate.
54
+ */
55
+ const DOCKER_CP_MISSING_RE = /could not find the file/i;
56
+ const TAR_BLOCK = 512;
57
+ /** Thrown when the built image ships source maps / declarations. `violations` lists every entry. */
58
+ class ImageHygieneError extends Error {
59
+ image;
60
+ violations;
61
+ constructor(image, violations) {
62
+ super(`Image hygiene gate (HSUITEPT-5): ${image} ships ${violations.length} file(s) that expose ` +
63
+ `the app's source and must not be deployed:\n` +
64
+ violations.map((v) => ` - ${v}`).join('\n') +
65
+ `\nBuild the backend with sourceMap/declaration OFF and removeComments ON (a production ` +
66
+ `tsconfig), or exclude them from the image (.dockerignore), then re-run \`hsuite deploy\`.`);
67
+ this.image = image;
68
+ this.violations = violations;
69
+ this.name = 'ImageHygieneError';
70
+ }
71
+ }
72
+ exports.ImageHygieneError = ImageHygieneError;
73
+ /**
74
+ * Entry names of a (ustar / PAX / GNU) tar archive. Contents are skipped by
75
+ * size; only names are returned. Tolerant: stops at the first zero block or a
76
+ * truncated header, so a non-archive buffer yields `[]`.
77
+ */
78
+ function listTarEntries(tar) {
79
+ const names = [];
80
+ let pendingLongName = null;
81
+ for (let off = 0; off + TAR_BLOCK <= tar.length;) {
82
+ const header = tar.subarray(off, off + TAR_BLOCK);
83
+ if (header.every((b) => b === 0))
84
+ break;
85
+ const size = parseInt(cstr(header, 124, 12) || '0', 8) || 0;
86
+ const type = String.fromCharCode(header[156] || 0x30);
87
+ const data = tar.subarray(off + TAR_BLOCK, off + TAR_BLOCK + size);
88
+ off += TAR_BLOCK + Math.ceil(size / TAR_BLOCK) * TAR_BLOCK;
89
+ if (type === 'L') {
90
+ pendingLongName = cstr(data, 0, data.length); // GNU long name
91
+ continue;
92
+ }
93
+ if (type === 'x') {
94
+ pendingLongName = paxPath(data.toString('utf8')) ?? pendingLongName; // PAX extended header
95
+ continue;
96
+ }
97
+ if (type === 'g')
98
+ continue; // PAX global header
99
+ const prefix = cstr(header, 345, 155);
100
+ const name = cstr(header, 0, 100);
101
+ names.push(pendingLongName ?? (prefix ? `${prefix}/${name}` : name));
102
+ pendingLongName = null;
103
+ }
104
+ return names;
105
+ }
106
+ /** Entries that must never ship in a customer image. */
107
+ function findImageHygieneViolations(entries) {
108
+ return entries.filter((e) => exports.IMAGE_HYGIENE_FORBIDDEN_SUFFIXES.some((s) => e.endsWith(s)));
109
+ }
110
+ /**
111
+ * Scan the built image's compiled output and THROW {@link ImageHygieneError}
112
+ * if it ships source maps, declaration files or tsbuildinfo. See the module
113
+ * header for the mechanism and the fail-closed contract.
114
+ */
115
+ function assertImageHygiene(opts) {
116
+ const { image, run, env } = opts;
117
+ const log = opts.log ?? (() => undefined);
118
+ const utf8 = { stdio: ['ignore', 'pipe', 'inherit'], encoding: 'utf8', env };
119
+ const workdir = asText(run('docker', ['inspect', '-f', '{{.Config.WorkingDir}}', image], utf8)) || '/';
120
+ const cid = asText(run('docker', ['create', image], utf8));
121
+ if (!cid)
122
+ throw new Error(`image hygiene gate: \`docker create ${image}\` returned no container id`);
123
+ try {
124
+ const violations = [];
125
+ let scanned = 0;
126
+ for (const dir of exports.IMAGE_HYGIENE_SCAN_DIRS) {
127
+ const entries = copyOut(run, `${cid}:${path_1.posix.join(workdir, dir)}`, env);
128
+ if (entries === null)
129
+ continue;
130
+ scanned++;
131
+ const files = entries.filter((e) => !e.endsWith('/'));
132
+ const bad = findImageHygieneViolations(files);
133
+ violations.push(...bad);
134
+ log(` image hygiene: ${dir}/ — ${files.length} file(s), ${bad.length} offending`);
135
+ }
136
+ if (scanned === 0) {
137
+ log(` ⚠ image hygiene: no compiled output found under ${workdir} (${exports.IMAGE_HYGIENE_SCAN_DIRS.join('/')}) — ` +
138
+ `nothing to scan`);
139
+ }
140
+ if (violations.length > 0)
141
+ throw new ImageHygieneError(image, violations);
142
+ }
143
+ finally {
144
+ // Best-effort reaping. A throw from a `finally` REPLACES the in-flight
145
+ // exception, so an unchecked `docker rm` would mask an `ImageHygieneError`
146
+ // verdict with a docker error — but a leaked container is still worth a
147
+ // line rather than being silent.
148
+ try {
149
+ run('docker', ['rm', '-f', cid], { stdio: 'ignore', env });
150
+ }
151
+ catch (err) {
152
+ log(` ⚠ image hygiene: could not remove scan container ${cid}: ${errorText(err)}`);
153
+ }
154
+ }
155
+ }
156
+ /**
157
+ * `docker cp <src> -` → entry names, or `null` when the path genuinely does not
158
+ * exist in the image.
159
+ *
160
+ * FAIL CLOSED: only docker's own not-found signature maps to `null`. Every
161
+ * other failure — a `maxBuffer` overflow on an unexpectedly huge directory, a
162
+ * dead container, a dropped daemon — is rethrown, because the gate cannot
163
+ * distinguish a broken read from an absent directory and must not report a scan
164
+ * it did not perform. stderr is PIPED rather than discarded so that signature
165
+ * is actually visible; with stderr `ignore`d, `execFileSync`'s error carries no
166
+ * docker text and EVERY failure reads as "not found".
167
+ */
168
+ function copyOut(run, src, env) {
169
+ let out;
170
+ try {
171
+ out = run('docker', ['cp', src, '-'], {
172
+ stdio: ['ignore', 'pipe', 'pipe'],
173
+ env,
174
+ maxBuffer: TAR_MAX_BUFFER_BYTES,
175
+ });
176
+ }
177
+ catch (err) {
178
+ const text = errorText(err);
179
+ if (DOCKER_CP_MISSING_RE.test(text))
180
+ return null;
181
+ throw new Error(`image hygiene gate: \`docker cp ${src} -\` failed, so the built image could not be ` +
182
+ `scanned — refusing to deploy an unscanned image: ${text}`);
183
+ }
184
+ // A non-Buffer means the seam decoded the archive, and a utf8 round-trip
185
+ // corrupts tar bytes into a buffer that parses as empty — a contract
186
+ // violation that would have read as "clean scan". Fail closed on it.
187
+ if (!Buffer.isBuffer(out)) {
188
+ throw new Error(`image hygiene gate: \`docker cp ${src} -\` returned ${typeof out}, not a tar buffer — ` +
189
+ `the run seam must not set \`encoding\` on this leg`);
190
+ }
191
+ return listTarEntries(out);
192
+ }
193
+ /**
194
+ * Message plus captured stderr of a thrown child-process error, for signature
195
+ * matching.
196
+ *
197
+ * TOTAL by construction: this runs inside `catch` blocks — including the
198
+ * `finally` that reaps the scan container — and `String()` throws on a
199
+ * null-prototype object or a hostile `Symbol.toPrimitive`. A throw from here
200
+ * would REPLACE the in-flight `ImageHygieneError`, i.e. the gate's verdict
201
+ * would be masked by a logging failure. Unstringifiable input therefore
202
+ * degrades to a literal rather than propagating.
203
+ */
204
+ function errorText(err) {
205
+ try {
206
+ const stderr = err.stderr;
207
+ const tail = Buffer.isBuffer(stderr) ? stderr.toString('utf8') : String(stderr ?? '');
208
+ const head = err instanceof Error ? err.message : String(err);
209
+ return `${head}\n${tail}`.trim();
210
+ }
211
+ catch {
212
+ return '[unstringifiable error]';
213
+ }
214
+ }
215
+ function asText(out) {
216
+ return typeof out === 'string'
217
+ ? out.trim()
218
+ : Buffer.isBuffer(out)
219
+ ? out.toString('utf8').trim()
220
+ : '';
221
+ }
222
+ /** NUL-terminated ASCII field of a tar header / GNU long-name block. */
223
+ function cstr(buf, start, len) {
224
+ const slice = buf.subarray(start, start + len);
225
+ const nul = slice.indexOf(0);
226
+ return slice.subarray(0, nul === -1 ? slice.length : nul).toString('utf8');
227
+ }
228
+ /** The `path=` record of a PAX extended header (`"<len> path=<value>\n"` lines). */
229
+ function paxPath(pax) {
230
+ const m = /(?:^|\n)\d+ path=([^\n]*)\n/.exec(pax);
231
+ return m ? m[1] : null;
232
+ }
233
+ //# sourceMappingURL=image-hygiene.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-hygiene.js","sourceRoot":"","sources":["../../src/_lib/image-hygiene.ts"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,MAAM,CAAC,GAAG,CAAC,CAAC;QAC9D,OAAO,GAAG,IAAI,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,yBAAyB,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,MAAM,CAAC,GAAY;IAC1B,OAAO,OAAO,GAAG,KAAK,QAAQ;QAC5B,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE;QACZ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;YACpB,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE;YAC7B,CAAC,CAAC,EAAE,CAAC;AACX,CAAC;AAED,wEAAwE;AACxE,SAAS,IAAI,CAAC,GAAW,EAAE,KAAa,EAAE,GAAW;IACnD,MAAM,KAAK,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,CAAC;IAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC7B,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAC7E,CAAC;AAED,oFAAoF;AACpF,SAAS,OAAO,CAAC,GAAW;IAC1B,MAAM,CAAC,GAAG,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACzB,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type { SubscriptionClient } from './subscription-client';
2
+ /** The subset of a quote response {@link renderOrderDeadline} /
3
+ * {@link ensureUnexpiredQuote} actually need — satisfied by both
4
+ * `DepositInstructions` and `SubscriptionClient.topUp`'s response. */
5
+ export type OrderQuoteFields = {
6
+ orderId?: string;
7
+ expiresAt?: string;
8
+ amount?: string;
9
+ destinationTag?: number;
10
+ rate?: {
11
+ hsuiteUsd: string;
12
+ source: string;
13
+ };
14
+ priceUsd?: number;
15
+ hsuiteDue?: string;
16
+ };
17
+ /**
18
+ * Print the quote's deadline (local time + minutes remaining) and the
19
+ * locked rate source alongside the amount. No-op when the server didn't
20
+ * wire a price-locked order (`SubscriptionOrderService` unbound, or an
21
+ * older server) — `expiresAt` is absent in that case, same as today.
22
+ */
23
+ export declare function renderOrderDeadline(quote: Pick<OrderQuoteFields, 'expiresAt' | 'rate'>): void;
24
+ /**
25
+ * Before showing or paying a quote: if its order has already expired, requote
26
+ * it and return a quote for the NEW amount/tag instead — never put an expired
27
+ * order's stale amount in front of a payer (#3699 D8, #3765). A no-op (returns `quote` unchanged) when
28
+ * there is no `orderId`/`expiresAt` to check (older server / order creation
29
+ * unavailable) or the quote is still within its deadline. Preserves every
30
+ * OTHER field on `quote` (e.g. `walletAddress`/`depositAddress`,
31
+ * `success`) — a requote never moves the deposit account, only the
32
+ * economic terms this function overrides.
33
+ */
34
+ export declare function ensureUnexpiredQuote<T extends OrderQuoteFields>(client: Pick<SubscriptionClient, 'requoteOrder'>, quote: T): Promise<T>;
35
+ //# sourceMappingURL=order-deadline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-deadline.d.ts","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;sEAEsE;AACtE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,IAAI,CAAC,gBAAgB,EAAE,WAAW,GAAG,MAAM,CAAC,GAAG,IAAI,CAY7F;AAED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,SAAS,gBAAgB,EACnE,MAAM,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,EAChD,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,CAAC,CAAC,CAgCZ"}
@@ -0,0 +1,78 @@
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.renderOrderDeadline = renderOrderDeadline;
7
+ exports.ensureUnexpiredQuote = ensureUnexpiredQuote;
8
+ /**
9
+ * #3699 PR1b-ii, D8 — deadline display + requote-before-pay guard shared by
10
+ * `hsuite subscribe` / `hsuite topup` (both auto-pay a price-locked-order
11
+ * quote carrying `orderId`/`expiresAt`/`rate`/`destinationTag` — PR1a wired
12
+ * the fields, PR1b-i wired the server-side expiry/requote enforcement; THIS
13
+ * closes the CLI's own half: show the deadline, and never submit a payment
14
+ * against an order the server has already — or is about to have — marked
15
+ * expired).
16
+ *
17
+ * Generic over the two distinct response shapes that carry these fields
18
+ * (`DepositInstructions` for subscribe/upgrade, `SubscriptionClient.topUp`'s
19
+ * inline response for topup) rather than forcing either one into the
20
+ * other's shape.
21
+ *
22
+ * `hsuite upgrade` does not auto-pay today (manual XUMM / `--no-autopay`
23
+ * flow only), so only {@link renderOrderDeadline} applies there — there is
24
+ * no auto-pay call site to guard.
25
+ */
26
+ const chalk_1 = __importDefault(require("chalk"));
27
+ /**
28
+ * Print the quote's deadline (local time + minutes remaining) and the
29
+ * locked rate source alongside the amount. No-op when the server didn't
30
+ * wire a price-locked order (`SubscriptionOrderService` unbound, or an
31
+ * older server) — `expiresAt` is absent in that case, same as today.
32
+ */
33
+ function renderOrderDeadline(quote) {
34
+ if (!quote.expiresAt)
35
+ return;
36
+ const expiresAtMs = new Date(quote.expiresAt).getTime();
37
+ const remainingMin = Math.max(0, Math.round((expiresAtMs - Date.now()) / 60_000));
38
+ console.log(chalk_1.default.gray(` deadline: ${new Date(quote.expiresAt).toLocaleString()} (${remainingMin} min remaining)`));
39
+ if (quote.rate) {
40
+ console.log(chalk_1.default.gray(` rate: ${quote.rate.hsuiteUsd} USD/HST (source: ${quote.rate.source})`));
41
+ }
42
+ }
43
+ /**
44
+ * Before showing or paying a quote: if its order has already expired, requote
45
+ * it and return a quote for the NEW amount/tag instead — never put an expired
46
+ * order's stale amount in front of a payer (#3699 D8, #3765). A no-op (returns `quote` unchanged) when
47
+ * there is no `orderId`/`expiresAt` to check (older server / order creation
48
+ * unavailable) or the quote is still within its deadline. Preserves every
49
+ * OTHER field on `quote` (e.g. `walletAddress`/`depositAddress`,
50
+ * `success`) — a requote never moves the deposit account, only the
51
+ * economic terms this function overrides.
52
+ */
53
+ async function ensureUnexpiredQuote(client, quote) {
54
+ if (!quote.orderId || !quote.expiresAt)
55
+ return quote;
56
+ if (new Date(quote.expiresAt).getTime() > Date.now())
57
+ return quote;
58
+ console.log(chalk_1.default.yellow(`\n quote expired (orderId=${quote.orderId}) — requoting at the current rate...`));
59
+ const requoted = await client.requoteOrder(quote.orderId);
60
+ // A requote asks for the REMAINDER and never carries a reserve surcharge (the one-time charge
61
+ // for the deposit account was already counted in the first quote), so the first deposit's
62
+ // `baseAmount` / `reserveSurcharge` line items must not survive next to the new amount.
63
+ const { baseAmount: _base, reserveSurcharge: _surcharge, ...carried } = quote;
64
+ const next = {
65
+ ...carried,
66
+ amount: requoted.pay.amount,
67
+ destinationTag: requoted.pay.destinationTag,
68
+ orderId: requoted.orderId,
69
+ expiresAt: requoted.expiresAt,
70
+ rate: requoted.rate,
71
+ priceUsd: requoted.priceUsd,
72
+ hsuiteDue: requoted.hsuiteDue,
73
+ };
74
+ console.log(chalk_1.default.yellow(` new amount: ${next.amount} HST (tag ${next.destinationTag}), new deadline: ` +
75
+ `${next.expiresAt ? new Date(next.expiresAt).toLocaleString() : 'n/a'}\n`));
76
+ return next;
77
+ }
78
+ //# sourceMappingURL=order-deadline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-deadline.js","sourceRoot":"","sources":["../../src/_lib/order-deadline.ts"],"names":[],"mappings":";;;;;AAwCA,kDAYC;AAYD,oDAmCC;AAnGD;;;;;;;;;;;;;;;;;GAiBG;AACH,kDAA0B;AAgB1B;;;;;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;AA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