@visa/cli 4.1.0-rc.145 → 4.1.0-rc.146

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.
@@ -33,6 +33,21 @@ export function isTransientDrawFailure(err) {
33
33
  const msgs = [];
34
34
  let e = err;
35
35
  for (let i = 0; i < 5 && e; i++) {
36
+ // A refusal that declared itself TERMINAL wins outright, before any message
37
+ // matching. Message text is not a safe carrier for this decision: the mint
38
+ // client interpolates provider-supplied `upstream_codes` into its message
39
+ // for diagnosability, and an identifier like `request_timeout` would match
40
+ // the unanchored `tim(e|ed)-out` alternative below and silently reclassify
41
+ // a permanent 422 as transient — skipping markUnhonored and stranding the
42
+ // mandate in the retry-forever loop this classifier exists to prevent.
43
+ // Duck-typed rather than instanceof so it survives bundling and any
44
+ // re-wrapping across package boundaries. Optional chaining rather than an
45
+ // explicit null guard: the loop condition already proved `e` truthy, so a
46
+ // `e !== null` test is dead code, and `?.` stays safe on a primitive or a
47
+ // nullish link if that guard ever changes.
48
+ if (e?.terminal === true) {
49
+ return false;
50
+ }
36
51
  if (e instanceof Error && typeof e.message === 'string')
37
52
  msgs.push(e.message);
38
53
  e = e.cause;
@@ -17,6 +17,25 @@ export type ServerMintDeps = {
17
17
  * — the mint must never throw here.
18
18
  */
19
19
  export declare function merchantOrigin(url: string): string;
20
+ /**
21
+ * A definitive refusal from the cryptogram mint route — the request will not
22
+ * succeed if retried unchanged.
23
+ *
24
+ * `terminal` is the load-bearing field. Draw terminality used to be decided by
25
+ * regex over the error MESSAGE, which made it hostage to text nobody controls:
26
+ * this client now interpolates the provider's own `upstream_codes` into the
27
+ * message for diagnosability, and a provider identifier such as
28
+ * `request_timeout` would match the transient matcher's unanchored
29
+ * `tim(e|ed)-out` alternative — flipping a permanent 422 back to "transient",
30
+ * skipping markUnhonored, and stranding the mandate in the exact retry-forever
31
+ * loop this whole change exists to kill. Terminality is therefore carried
32
+ * structurally, and consumers must consult it BEFORE any message matching.
33
+ */
34
+ export declare class ServerCryptogramRefusedError extends Error {
35
+ readonly status: number;
36
+ readonly terminal: true;
37
+ constructor(status: number, detail: string);
38
+ }
20
39
  /**
21
40
  * Optional mandate override for serverCreateIntent. Absent → the historical
22
41
  * 1:1 fresh-tap shape is preserved byte-for-byte (cap = ceil(amount)+10 min 25,
@@ -40,6 +40,29 @@ export function merchantOrigin(url) {
40
40
  return url;
41
41
  }
42
42
  }
43
+ /**
44
+ * A definitive refusal from the cryptogram mint route — the request will not
45
+ * succeed if retried unchanged.
46
+ *
47
+ * `terminal` is the load-bearing field. Draw terminality used to be decided by
48
+ * regex over the error MESSAGE, which made it hostage to text nobody controls:
49
+ * this client now interpolates the provider's own `upstream_codes` into the
50
+ * message for diagnosability, and a provider identifier such as
51
+ * `request_timeout` would match the transient matcher's unanchored
52
+ * `tim(e|ed)-out` alternative — flipping a permanent 422 back to "transient",
53
+ * skipping markUnhonored, and stranding the mandate in the exact retry-forever
54
+ * loop this whole change exists to kill. Terminality is therefore carried
55
+ * structurally, and consumers must consult it BEFORE any message matching.
56
+ */
57
+ export class ServerCryptogramRefusedError extends Error {
58
+ status;
59
+ terminal = true;
60
+ constructor(status, detail) {
61
+ super(`server cryptogram refused (${status}): ${detail}`);
62
+ this.name = 'ServerCryptogramRefusedError';
63
+ this.status = status;
64
+ }
65
+ }
43
66
  /** Read a stable, non-secret error message from a route's JSON body. */
44
67
  async function routeError(res) {
45
68
  const doc = (await res.json().catch(() => null));
@@ -165,7 +188,7 @@ export async function serverFetchCryptogram(base, mintToken, input, deps = {}) {
165
188
  // healthy mandate. The route maps upstream rate limits to 503 today, so this
166
189
  // is a guard against a future emitter, not a live path.
167
190
  if (res.status >= 400 && res.status < 500 && res.status !== 429) {
168
- throw new Error(`server cryptogram refused (${res.status}): ${await routeError(res)}`);
191
+ throw new ServerCryptogramRefusedError(res.status, await routeError(res));
169
192
  }
170
193
  lastError = `${res.status}: ${await routeError(res)}`;
171
194
  if (attempt < attempts)