@piprail/sdk 2.14.0 → 2.14.2

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.
@@ -71,6 +71,9 @@ var SettlementError = class extends PipRailError {
71
71
  var InvalidEnvelopeError = class extends PipRailError {
72
72
  code = "INVALID_ENVELOPE";
73
73
  };
74
+ var InvalidConfigError = class extends PipRailError {
75
+ code = "INVALID_CONFIG";
76
+ };
74
77
  var NoCompatibleAcceptError = class extends PipRailError {
75
78
  code = "NO_COMPATIBLE_ACCEPT";
76
79
  };
@@ -123,6 +126,11 @@ var FAMILY_TOKEN = {
123
126
  };
124
127
  function rejectForeignToken(token, family, network) {
125
128
  const own = FAMILY_TOKEN[family];
129
+ if (typeof token !== "object" || token === null) {
130
+ throw new InvalidConfigError(
131
+ `token must be the string 'native', a built-in symbol, or an object (${own.shape} \u2014 pass ${own.hint}); got ${token === null ? "null" : typeof token}.`
132
+ );
133
+ }
126
134
  for (const fam of Object.keys(FAMILY_TOKEN)) {
127
135
  if (fam === family) continue;
128
136
  if (FAMILY_TOKEN[fam].key === own.key) continue;
@@ -159,9 +167,15 @@ function expandScientific(value) {
159
167
  }
160
168
  function parseUnits(value, decimals) {
161
169
  assertValidDecimals(decimals, "parseUnits");
162
- value = expandScientific(value);
170
+ if (typeof value !== "string") {
171
+ throw new InvalidConfigError(
172
+ `parseUnits: amount must be a decimal STRING, got ${typeof value}. Pass '0.05', not 0.05.`
173
+ );
174
+ }
163
175
  if (!/^\d+(\.\d+)?$/.test(value)) {
164
- throw new Error(`parseUnits: "${value}" is not a non-negative decimal amount.`);
176
+ throw new InvalidConfigError(
177
+ `parseUnits: "${value}" is not a plain non-negative decimal amount (scientific notation like '1e3' is rejected \u2014 write the number out, e.g. '1000').`
178
+ );
165
179
  }
166
180
  const [whole, frac = ""] = value.split(".");
167
181
  if (frac.length > decimals) {
@@ -227,6 +241,7 @@ export {
227
241
  ConfirmationTimeoutError,
228
242
  SettlementError,
229
243
  InvalidEnvelopeError,
244
+ InvalidConfigError,
230
245
  NoCompatibleAcceptError,
231
246
  UnsupportedSchemeError,
232
247
  NonReplayableBodyError,