@lightsparkdev/core 1.2.6 → 1.2.8

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/dist/index.cjs CHANGED
@@ -62,12 +62,14 @@ __export(src_exports, {
62
62
  ensureArray: () => ensureArray,
63
63
  errorToJSON: () => errorToJSON,
64
64
  formatCurrencyStr: () => formatCurrencyStr,
65
+ getCurrencyAmount: () => getCurrencyAmount,
65
66
  getCurrentLocale: () => getCurrentLocale,
66
67
  getErrorMsg: () => getErrorMsg,
67
68
  getLocalStorageBoolean: () => getLocalStorageBoolean,
68
69
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
69
70
  hexToBytes: () => hexToBytes,
70
71
  isBrowser: () => isBrowser,
72
+ isCurrencyAmountInputObj: () => isCurrencyAmountInputObj,
71
73
  isCurrencyAmountObj: () => isCurrencyAmountObj,
72
74
  isCurrencyAmountPreferenceObj: () => isCurrencyAmountPreferenceObj,
73
75
  isCurrencyMap: () => isCurrencyMap,
@@ -794,6 +796,7 @@ var CurrencyUnit = {
794
796
  MILLIBITCOIN: "MILLIBITCOIN",
795
797
  USD: "USD",
796
798
  MXN: "MXN",
799
+ PHP: "PHP",
797
800
  Bitcoin: "BITCOIN",
798
801
  Microbitcoin: "MICROBITCOIN",
799
802
  Millibitcoin: "MILLIBITCOIN",
@@ -801,7 +804,8 @@ var CurrencyUnit = {
801
804
  Nanobitcoin: "NANOBITCOIN",
802
805
  Satoshi: "SATOSHI",
803
806
  Usd: "USD",
804
- Mxn: "MXN"
807
+ Mxn: "MXN",
808
+ Php: "PHP"
805
809
  };
806
810
  var standardUnitConversionObj = {
807
811
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -812,7 +816,8 @@ var standardUnitConversionObj = {
812
816
  [CurrencyUnit.SATOSHI]: (v, unitsPerBtc = 1) => v / unitsPerBtc * 1e8,
813
817
  /* Converting between two different fiat types is not currently supported */
814
818
  [CurrencyUnit.USD]: (v) => v,
815
- [CurrencyUnit.MXN]: (v) => v
819
+ [CurrencyUnit.MXN]: (v) => v,
820
+ [CurrencyUnit.PHP]: (v) => v
816
821
  };
817
822
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
818
823
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -829,7 +834,8 @@ var CONVERSION_MAP = {
829
834
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e9,
830
835
  [CurrencyUnit.SATOSHI]: (v) => v * 1e8,
831
836
  [CurrencyUnit.USD]: toBitcoinConversion,
832
- [CurrencyUnit.MXN]: toBitcoinConversion
837
+ [CurrencyUnit.MXN]: toBitcoinConversion,
838
+ [CurrencyUnit.PHP]: toBitcoinConversion
833
839
  },
834
840
  [CurrencyUnit.MICROBITCOIN]: {
835
841
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -839,7 +845,8 @@ var CONVERSION_MAP = {
839
845
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e3,
840
846
  [CurrencyUnit.SATOSHI]: (v) => v * 100,
841
847
  [CurrencyUnit.USD]: toMicrobitcoinConversion,
842
- [CurrencyUnit.MXN]: toMicrobitcoinConversion
848
+ [CurrencyUnit.MXN]: toMicrobitcoinConversion,
849
+ [CurrencyUnit.PHP]: toMicrobitcoinConversion
843
850
  },
844
851
  [CurrencyUnit.MILLIBITCOIN]: {
845
852
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -849,7 +856,8 @@ var CONVERSION_MAP = {
849
856
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 1e6,
850
857
  [CurrencyUnit.SATOSHI]: (v) => v * 1e5,
851
858
  [CurrencyUnit.USD]: toMillibitcoinConversion,
852
- [CurrencyUnit.MXN]: toMillibitcoinConversion
859
+ [CurrencyUnit.MXN]: toMillibitcoinConversion,
860
+ [CurrencyUnit.PHP]: toMillibitcoinConversion
853
861
  },
854
862
  [CurrencyUnit.MILLISATOSHI]: {
855
863
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -859,7 +867,8 @@ var CONVERSION_MAP = {
859
867
  [CurrencyUnit.NANOBITCOIN]: (v) => v / 100,
860
868
  [CurrencyUnit.SATOSHI]: (v) => v / 1e3,
861
869
  [CurrencyUnit.USD]: toMillisatoshiConversion,
862
- [CurrencyUnit.MXN]: toMillisatoshiConversion
870
+ [CurrencyUnit.MXN]: toMillisatoshiConversion,
871
+ [CurrencyUnit.PHP]: toMillisatoshiConversion
863
872
  },
864
873
  [CurrencyUnit.NANOBITCOIN]: {
865
874
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -869,7 +878,8 @@ var CONVERSION_MAP = {
869
878
  [CurrencyUnit.NANOBITCOIN]: (v) => v,
870
879
  [CurrencyUnit.SATOSHI]: (v) => v / 10,
871
880
  [CurrencyUnit.USD]: toNanobitcoinConversion,
872
- [CurrencyUnit.MXN]: toNanobitcoinConversion
881
+ [CurrencyUnit.MXN]: toNanobitcoinConversion,
882
+ [CurrencyUnit.PHP]: toNanobitcoinConversion
873
883
  },
874
884
  [CurrencyUnit.SATOSHI]: {
875
885
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -879,10 +889,12 @@ var CONVERSION_MAP = {
879
889
  [CurrencyUnit.NANOBITCOIN]: (v) => v * 10,
880
890
  [CurrencyUnit.SATOSHI]: (v) => v,
881
891
  [CurrencyUnit.USD]: toSatoshiConversion,
882
- [CurrencyUnit.MXN]: toSatoshiConversion
892
+ [CurrencyUnit.MXN]: toSatoshiConversion,
893
+ [CurrencyUnit.PHP]: toSatoshiConversion
883
894
  },
884
895
  [CurrencyUnit.USD]: standardUnitConversionObj,
885
- [CurrencyUnit.MXN]: standardUnitConversionObj
896
+ [CurrencyUnit.MXN]: standardUnitConversionObj,
897
+ [CurrencyUnit.PHP]: standardUnitConversionObj
886
898
  };
887
899
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
888
900
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -913,6 +925,9 @@ var convertCurrencyAmount = (from, toUnit) => {
913
925
  preferredCurrencyValueRounded: value
914
926
  };
915
927
  };
928
+ function isCurrencyAmountInputObj(arg) {
929
+ return typeof arg === "object" && arg !== null && "value" in arg && (typeof arg.value === "number" || typeof arg.value === "string" || arg.value === null) && "unit" in arg && typeof arg.unit === "string";
930
+ }
916
931
  function isDeprecatedCurrencyAmountObj(arg) {
917
932
  return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
918
933
  }
@@ -920,7 +935,7 @@ function isCurrencyAmountObj(arg) {
920
935
  return typeof arg === "object" && arg !== null && "original_value" in arg && "original_unit" in arg;
921
936
  }
922
937
  function isCurrencyAmountPreferenceObj(arg) {
923
- return typeof arg === "object" && arg !== null && "preferred_currency_unit" in arg && "preferred_currency_value_rounded" in arg;
938
+ return typeof arg === "object" && arg !== null && "original_unit" in arg && typeof arg.original_unit === "string" && "original_value" in arg && typeof arg.original_value === "number" && "preferred_currency_unit" in arg && typeof arg.preferred_currency_unit === "string" && "preferred_currency_value_approx" in arg && typeof arg.preferred_currency_value_approx === "number";
924
939
  }
925
940
  function isSDKCurrencyAmount(arg) {
926
941
  return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
@@ -938,13 +953,10 @@ function getCurrencyAmount(currencyAmountArg) {
938
953
  if (isSDKCurrencyAmount(currencyAmountArg)) {
939
954
  value = currencyAmountArg.originalValue;
940
955
  unit = currencyAmountArg.originalUnit;
941
- } else if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
942
- value = asNumber(currencyAmountArg.preferred_currency_value_rounded);
943
- unit = currencyAmountArg.preferred_currency_unit;
944
956
  } else if (isCurrencyAmountObj(currencyAmountArg)) {
945
957
  value = asNumber(currencyAmountArg.original_value);
946
958
  unit = currencyAmountArg.original_unit;
947
- } else if (isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
959
+ } else if (isCurrencyAmountInputObj(currencyAmountArg) || isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
948
960
  value = asNumber(currencyAmountArg.value);
949
961
  unit = currencyAmountArg.unit;
950
962
  }
@@ -953,23 +965,61 @@ function getCurrencyAmount(currencyAmountArg) {
953
965
  unit: unit || CurrencyUnit.SATOSHI
954
966
  };
955
967
  }
968
+ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversionOverride) {
969
+ const convert = convertCurrencyAmountValue;
970
+ const namesToUnits = {
971
+ sats: CurrencyUnit.SATOSHI,
972
+ btc: CurrencyUnit.BITCOIN,
973
+ msats: CurrencyUnit.MILLISATOSHI,
974
+ usd: CurrencyUnit.USD,
975
+ mxn: CurrencyUnit.MXN,
976
+ php: CurrencyUnit.PHP,
977
+ mibtc: CurrencyUnit.MICROBITCOIN,
978
+ mlbtc: CurrencyUnit.MILLIBITCOIN,
979
+ nbtc: CurrencyUnit.NANOBITCOIN
980
+ };
981
+ return Object.entries(namesToUnits).reduce(
982
+ (acc, [name, unit]) => {
983
+ if (conversionOverride && unit === conversionOverride.unit) {
984
+ acc[name] = conversionOverride.convertedValue;
985
+ } else {
986
+ acc[name] = convert(
987
+ fromUnit,
988
+ unit,
989
+ amount,
990
+ unitsPerBtc
991
+ );
992
+ }
993
+ return acc;
994
+ },
995
+ {}
996
+ );
997
+ }
998
+ function getPreferredConversionOverride(currencyAmountArg) {
999
+ if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
1000
+ return {
1001
+ unit: currencyAmountArg.preferred_currency_unit,
1002
+ convertedValue: currencyAmountArg.preferred_currency_value_approx
1003
+ };
1004
+ } else if (isSDKCurrencyAmount(currencyAmountArg)) {
1005
+ return {
1006
+ unit: currencyAmountArg.preferredCurrencyUnit,
1007
+ convertedValue: currencyAmountArg.preferredCurrencyValueApprox
1008
+ };
1009
+ }
1010
+ return void 0;
1011
+ }
956
1012
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
957
1013
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
958
- const convert = convertCurrencyAmountValue;
959
- const sats = convert(unit, CurrencyUnit.SATOSHI, value, unitsPerBtc);
960
- const btc = convert(unit, CurrencyUnit.BITCOIN, value, unitsPerBtc);
961
- const msats = convert(unit, CurrencyUnit.MILLISATOSHI, value, unitsPerBtc);
962
- const usd = convert(unit, CurrencyUnit.USD, value, unitsPerBtc);
963
- const mxn = convert(unit, CurrencyUnit.MXN, value, unitsPerBtc);
964
- const mibtc = convert(unit, CurrencyUnit.MICROBITCOIN, value, unitsPerBtc);
965
- const mlbtc = convert(unit, CurrencyUnit.MILLIBITCOIN, value, unitsPerBtc);
966
- const nbtc = convert(unit, CurrencyUnit.NANOBITCOIN, value, unitsPerBtc);
1014
+ const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
1015
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
967
1016
  const mapWithCurrencyUnits = {
968
1017
  [CurrencyUnit.BITCOIN]: btc,
969
1018
  [CurrencyUnit.SATOSHI]: sats,
970
1019
  [CurrencyUnit.MILLISATOSHI]: msats,
971
1020
  [CurrencyUnit.USD]: usd,
972
1021
  [CurrencyUnit.MXN]: mxn,
1022
+ [CurrencyUnit.PHP]: php,
973
1023
  [CurrencyUnit.MICROBITCOIN]: mibtc,
974
1024
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
975
1025
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -1007,6 +1057,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
1007
1057
  value: mxn,
1008
1058
  unit: CurrencyUnit.MXN
1009
1059
  }),
1060
+ [CurrencyUnit.PHP]: formatCurrencyStr({
1061
+ value: php,
1062
+ unit: CurrencyUnit.PHP
1063
+ }),
1010
1064
  [CurrencyUnit.FUTURE_VALUE]: "-"
1011
1065
  }
1012
1066
  };
@@ -1061,8 +1115,16 @@ var abbrCurrencyUnit = (unit) => {
1061
1115
  return "SAT";
1062
1116
  case CurrencyUnit.MILLISATOSHI:
1063
1117
  return "MSAT";
1118
+ case CurrencyUnit.MILLIBITCOIN:
1119
+ return "mBTC";
1120
+ case CurrencyUnit.MICROBITCOIN:
1121
+ return "\u03BCBTC";
1064
1122
  case CurrencyUnit.USD:
1065
1123
  return "USD";
1124
+ case CurrencyUnit.MXN:
1125
+ return "MXN";
1126
+ case CurrencyUnit.PHP:
1127
+ return "PHP";
1066
1128
  }
1067
1129
  return "Unsupported CurrencyUnit";
1068
1130
  };
@@ -1070,7 +1132,8 @@ var defaultOptions = {
1070
1132
  /* undefined indicates to use default precision for unit defined below */
1071
1133
  precision: void 0,
1072
1134
  compact: false,
1073
- showBtcSymbol: false
1135
+ showBtcSymbol: false,
1136
+ append: void 0
1074
1137
  };
1075
1138
  function formatCurrencyStr(amount, options) {
1076
1139
  const { precision, compact, showBtcSymbol } = {
@@ -1080,7 +1143,12 @@ function formatCurrencyStr(amount, options) {
1080
1143
  const currencyAmount = getCurrencyAmount(amount);
1081
1144
  let { value: num } = currencyAmount;
1082
1145
  const { unit } = currencyAmount;
1083
- if (unit === CurrencyUnit.USD) {
1146
+ const centCurrencies = [
1147
+ CurrencyUnit.USD,
1148
+ CurrencyUnit.MXN,
1149
+ CurrencyUnit.PHP
1150
+ ];
1151
+ if (centCurrencies.includes(unit)) {
1084
1152
  num = num / 100;
1085
1153
  }
1086
1154
  function getDefaultMaxFractionDigits(defaultDigits, fullPrecisionDigits) {
@@ -1096,34 +1164,52 @@ function formatCurrencyStr(amount, options) {
1096
1164
  }
1097
1165
  const symbol = !showBtcSymbol ? "" : unit === CurrencyUnit.BITCOIN ? "\uE903" : unit === CurrencyUnit.SATOSHI ? "\uE902" : "";
1098
1166
  const currentLocale = getCurrentLocale();
1167
+ let formattedStr = "";
1099
1168
  switch (unit) {
1169
+ case CurrencyUnit.MXN:
1170
+ case CurrencyUnit.USD:
1171
+ case CurrencyUnit.PHP:
1172
+ formattedStr = num.toLocaleString(currentLocale, {
1173
+ style: "currency",
1174
+ currency: unit,
1175
+ currencyDisplay: "narrowSymbol",
1176
+ notation: compact ? "compact" : void 0,
1177
+ maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
1178
+ });
1179
+ break;
1100
1180
  case CurrencyUnit.BITCOIN:
1101
- return `${symbol}${num.toLocaleString(currentLocale, {
1181
+ formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
1102
1182
  notation: compact ? "compact" : void 0,
1103
1183
  maximumFractionDigits: getDefaultMaxFractionDigits(4, 8)
1104
1184
  })}`;
1185
+ break;
1105
1186
  case CurrencyUnit.SATOSHI:
1106
- return `${symbol}${num.toLocaleString(currentLocale, {
1187
+ formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
1107
1188
  notation: compact ? "compact" : void 0,
1108
1189
  maximumFractionDigits: getDefaultMaxFractionDigits(0, 3)
1109
1190
  })}`;
1191
+ break;
1110
1192
  case CurrencyUnit.MILLISATOSHI:
1111
1193
  case CurrencyUnit.MICROBITCOIN:
1112
1194
  case CurrencyUnit.MILLIBITCOIN:
1113
1195
  case CurrencyUnit.NANOBITCOIN:
1114
1196
  default:
1115
- return `${symbol}${num.toLocaleString(currentLocale, {
1197
+ formattedStr = `${symbol}${num.toLocaleString(currentLocale, {
1116
1198
  notation: compact ? "compact" : void 0,
1117
1199
  maximumFractionDigits: getDefaultMaxFractionDigits(0, 0)
1118
1200
  })}`;
1119
- case CurrencyUnit.USD:
1120
- return num.toLocaleString(currentLocale, {
1121
- style: "currency",
1122
- currency: defaultCurrencyCode,
1123
- notation: compact ? "compact" : void 0,
1124
- maximumFractionDigits: getDefaultMaxFractionDigits(2, 2)
1125
- });
1126
1201
  }
1202
+ if (options?.appendUnits) {
1203
+ const localeCurrencyCode = localeToCurrencyCode(currentLocale);
1204
+ if (unit === localeCurrencyCode && !options.appendUnits.showForCurrentLocaleUnit) {
1205
+ return formattedStr;
1206
+ }
1207
+ const unitStr = abbrCurrencyUnit(unit);
1208
+ const unitSuffix = options.appendUnits.plural && num > 1 ? "s" : "";
1209
+ const unitStrWithSuffix = `${unitStr}${unitSuffix}`;
1210
+ formattedStr += ` ${options.appendUnits.lowercase ? unitStrWithSuffix.toLowerCase() : unitStrWithSuffix}`;
1211
+ }
1212
+ return formattedStr;
1127
1213
  }
1128
1214
  function separateCurrencyStrParts(currencyStr) {
1129
1215
  const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
@@ -1502,13 +1588,15 @@ var import_zen_observable_ts = require("zen-observable-ts");
1502
1588
  var DEFAULT_BASE_URL = "api.lightspark.com";
1503
1589
  import_dayjs.default.extend(import_utc.default);
1504
1590
  var Requester = class {
1505
- constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto) {
1591
+ constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto, signingKey, fetchImpl = fetch) {
1506
1592
  this.nodeKeyCache = nodeKeyCache;
1507
1593
  this.schemaEndpoint = schemaEndpoint;
1508
1594
  this.sdkUserAgent = sdkUserAgent;
1509
1595
  this.authProvider = authProvider;
1510
1596
  this.baseUrl = baseUrl;
1511
1597
  this.cryptoImpl = cryptoImpl;
1598
+ this.signingKey = signingKey;
1599
+ this.fetchImpl = fetchImpl;
1512
1600
  let websocketImpl;
1513
1601
  if (typeof WebSocket === "undefined" && typeof window === "undefined") {
1514
1602
  websocketImpl = import_ws.default;
@@ -1628,7 +1716,7 @@ var Requester = class {
1628
1716
  variables,
1629
1717
  headers
1630
1718
  });
1631
- const response = await fetch(url, {
1719
+ const response = await this.fetchImpl(url, {
1632
1720
  method: "POST",
1633
1721
  headers,
1634
1722
  body: bodyData
@@ -1673,7 +1761,7 @@ var Requester = class {
1673
1761
  nonce,
1674
1762
  expires_at: expiration
1675
1763
  };
1676
- const key = this.nodeKeyCache.getKey(signingNodeId);
1764
+ const key = this.signingKey ?? this.nodeKeyCache.getKey(signingNodeId);
1677
1765
  if (!key) {
1678
1766
  throw new LightsparkSigningException_default(
1679
1767
  "Missing node of encrypted_signing_private_key"
@@ -1753,12 +1841,14 @@ var ServerEnvironment_default = ServerEnvironment;
1753
1841
  ensureArray,
1754
1842
  errorToJSON,
1755
1843
  formatCurrencyStr,
1844
+ getCurrencyAmount,
1756
1845
  getCurrentLocale,
1757
1846
  getErrorMsg,
1758
1847
  getLocalStorageBoolean,
1759
1848
  getLocalStorageConfigItem,
1760
1849
  hexToBytes,
1761
1850
  isBrowser,
1851
+ isCurrencyAmountInputObj,
1762
1852
  isCurrencyAmountObj,
1763
1853
  isCurrencyAmountPreferenceObj,
1764
1854
  isCurrencyMap,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-COxEW2dD.cjs';
1
+ export { A as AppendUnitsOptions, a7 as ById, ah as Complete, C as ConfigKeys, n as CurrencyAmountArg, k as CurrencyAmountInputObj, l as CurrencyAmountObj, m as CurrencyAmountPreferenceObj, R as CurrencyCodes, Q as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, aa as DeepPartial, D as DeprecatedCurrencyAmountObj, a6 as ExpandRecursively, ab as JSONLiteral, ad as JSONObject, ac as JSONType, a5 as Maybe, ae as NN, a8 as OmitTypename, ag as PartialBy, ai as RequiredKeys, S as SDKCurrencyAmountType, x as abbrCurrencyUnit, b as b64decode, a as b64encode, M as bytesToHex, Y as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, P as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, X as deleteLocalStorageItem, e as ensureArray, L as errorToJSON, y as formatCurrencyStr, t as getCurrencyAmount, O as getCurrentLocale, J as getErrorMsg, V as getLocalStorageBoolean, U as getLocalStorageConfigItem, N as hexToBytes, E as isBrowser, o as isCurrencyAmountInputObj, q as isCurrencyAmountObj, r as isCurrencyAmountPreferenceObj, w as isCurrencyMap, p as isDeprecatedCurrencyAmountObj, H as isError, K as isErrorMsg, I as isErrorWithMessage, F as isNode, $ as isNumber, a4 as isObject, s as isSDKCurrencyAmount, G as isTest, a9 as isType, a3 as isUint8Array, Z as linearInterpolate, T as localeToCurrencyCode, B as localeToCurrencySymbol, a2 as lsidToUUID, v as mapCurrencyAmount, af as notNullUndefined, a0 as pollUntil, _ as round, z as separateCurrencyStrParts, W as setLocalStorageBoolean, a1 as sleep, u as urlsafe_b64decode } from './index-r0bUxDu_.cjs';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
@@ -145,8 +145,10 @@ declare class Requester {
145
145
  private readonly authProvider;
146
146
  private readonly baseUrl;
147
147
  private readonly cryptoImpl;
148
+ private readonly signingKey?;
149
+ private readonly fetchImpl;
148
150
  private readonly wsClient;
149
- constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface);
151
+ constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
150
152
  executeQuery<T>(query: Query<T>): Promise<T | null>;
151
153
  subscribe<T>(queryPayload: string, variables?: {
152
154
  [key: string]: unknown;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { a3 as ById, ad as Complete, C as ConfigKeys, m as CurrencyAmountArg, k as CurrencyAmountObj, l as CurrencyAmountPreferenceObj, N as CurrencyCodes, M as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, a6 as DeepPartial, D as DeprecatedCurrencyAmountObj, a2 as ExpandRecursively, a7 as JSONLiteral, a9 as JSONObject, a8 as JSONType, a1 as Maybe, aa as NN, a4 as OmitTypename, ac as PartialBy, ae as RequiredKeys, S as SDKCurrencyAmountType, t as abbrCurrencyUnit, b as b64decode, a as b64encode, I as bytesToHex, U as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, L as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, T as deleteLocalStorageItem, e as ensureArray, H as errorToJSON, v as formatCurrencyStr, K as getCurrentLocale, F as getErrorMsg, Q as getLocalStorageBoolean, P as getLocalStorageConfigItem, J as hexToBytes, y as isBrowser, o as isCurrencyAmountObj, p as isCurrencyAmountPreferenceObj, s as isCurrencyMap, n as isDeprecatedCurrencyAmountObj, B as isError, G as isErrorMsg, E as isErrorWithMessage, z as isNode, X as isNumber, a0 as isObject, q as isSDKCurrencyAmount, A as isTest, a5 as isType, $ as isUint8Array, V as linearInterpolate, O as localeToCurrencyCode, x as localeToCurrencySymbol, _ as lsidToUUID, r as mapCurrencyAmount, ab as notNullUndefined, Y as pollUntil, W as round, w as separateCurrencyStrParts, R as setLocalStorageBoolean, Z as sleep, u as urlsafe_b64decode } from './index-COxEW2dD.js';
1
+ export { A as AppendUnitsOptions, a7 as ById, ah as Complete, C as ConfigKeys, n as CurrencyAmountArg, k as CurrencyAmountInputObj, l as CurrencyAmountObj, m as CurrencyAmountPreferenceObj, R as CurrencyCodes, Q as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, aa as DeepPartial, D as DeprecatedCurrencyAmountObj, a6 as ExpandRecursively, ab as JSONLiteral, ad as JSONObject, ac as JSONType, a5 as Maybe, ae as NN, a8 as OmitTypename, ag as PartialBy, ai as RequiredKeys, S as SDKCurrencyAmountType, x as abbrCurrencyUnit, b as b64decode, a as b64encode, M as bytesToHex, Y as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, P as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, X as deleteLocalStorageItem, e as ensureArray, L as errorToJSON, y as formatCurrencyStr, t as getCurrencyAmount, O as getCurrentLocale, J as getErrorMsg, V as getLocalStorageBoolean, U as getLocalStorageConfigItem, N as hexToBytes, E as isBrowser, o as isCurrencyAmountInputObj, q as isCurrencyAmountObj, r as isCurrencyAmountPreferenceObj, w as isCurrencyMap, p as isDeprecatedCurrencyAmountObj, H as isError, K as isErrorMsg, I as isErrorWithMessage, F as isNode, $ as isNumber, a4 as isObject, s as isSDKCurrencyAmount, G as isTest, a9 as isType, a3 as isUint8Array, Z as linearInterpolate, T as localeToCurrencyCode, B as localeToCurrencySymbol, a2 as lsidToUUID, v as mapCurrencyAmount, af as notNullUndefined, a0 as pollUntil, _ as round, z as separateCurrencyStrParts, W as setLocalStorageBoolean, a1 as sleep, u as urlsafe_b64decode } from './index-r0bUxDu_.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
@@ -145,8 +145,10 @@ declare class Requester {
145
145
  private readonly authProvider;
146
146
  private readonly baseUrl;
147
147
  private readonly cryptoImpl;
148
+ private readonly signingKey?;
149
+ private readonly fetchImpl;
148
150
  private readonly wsClient;
149
- constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface);
151
+ constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
150
152
  executeQuery<T>(query: Query<T>): Promise<T | null>;
151
153
  subscribe<T>(queryPayload: string, variables?: {
152
154
  [key: string]: unknown;
package/dist/index.js CHANGED
@@ -15,12 +15,14 @@ import {
15
15
  ensureArray,
16
16
  errorToJSON,
17
17
  formatCurrencyStr,
18
+ getCurrencyAmount,
18
19
  getCurrentLocale,
19
20
  getErrorMsg,
20
21
  getLocalStorageBoolean,
21
22
  getLocalStorageConfigItem,
22
23
  hexToBytes,
23
24
  isBrowser,
25
+ isCurrencyAmountInputObj,
24
26
  isCurrencyAmountObj,
25
27
  isCurrencyAmountPreferenceObj,
26
28
  isCurrencyMap,
@@ -47,7 +49,7 @@ import {
47
49
  setLocalStorageBoolean,
48
50
  sleep,
49
51
  urlsafe_b64decode
50
- } from "./chunk-CKJUUY2Z.js";
52
+ } from "./chunk-NY4EJZNK.js";
51
53
 
52
54
  // src/auth/LightsparkAuthException.ts
53
55
  var LightsparkAuthException = class extends LightsparkException_default {
@@ -489,13 +491,15 @@ import { Observable } from "zen-observable-ts";
489
491
  var DEFAULT_BASE_URL = "api.lightspark.com";
490
492
  dayjs.extend(utc);
491
493
  var Requester = class {
492
- constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto) {
494
+ constructor(nodeKeyCache, schemaEndpoint, sdkUserAgent, authProvider = new StubAuthProvider(), baseUrl = DEFAULT_BASE_URL, cryptoImpl = DefaultCrypto, signingKey, fetchImpl = fetch) {
493
495
  this.nodeKeyCache = nodeKeyCache;
494
496
  this.schemaEndpoint = schemaEndpoint;
495
497
  this.sdkUserAgent = sdkUserAgent;
496
498
  this.authProvider = authProvider;
497
499
  this.baseUrl = baseUrl;
498
500
  this.cryptoImpl = cryptoImpl;
501
+ this.signingKey = signingKey;
502
+ this.fetchImpl = fetchImpl;
499
503
  let websocketImpl;
500
504
  if (typeof WebSocket === "undefined" && typeof window === "undefined") {
501
505
  websocketImpl = NodeWebSocket;
@@ -615,7 +619,7 @@ var Requester = class {
615
619
  variables,
616
620
  headers
617
621
  });
618
- const response = await fetch(url, {
622
+ const response = await this.fetchImpl(url, {
619
623
  method: "POST",
620
624
  headers,
621
625
  body: bodyData
@@ -660,7 +664,7 @@ var Requester = class {
660
664
  nonce,
661
665
  expires_at: expiration
662
666
  };
663
- const key = this.nodeKeyCache.getKey(signingNodeId);
667
+ const key = this.signingKey ?? this.nodeKeyCache.getKey(signingNodeId);
664
668
  if (!key) {
665
669
  throw new LightsparkSigningException_default(
666
670
  "Missing node of encrypted_signing_private_key"
@@ -739,12 +743,14 @@ export {
739
743
  ensureArray,
740
744
  errorToJSON,
741
745
  formatCurrencyStr,
746
+ getCurrencyAmount,
742
747
  getCurrentLocale,
743
748
  getErrorMsg,
744
749
  getLocalStorageBoolean,
745
750
  getLocalStorageConfigItem,
746
751
  hexToBytes,
747
752
  isBrowser,
753
+ isCurrencyAmountInputObj,
748
754
  isCurrencyAmountObj,
749
755
  isCurrencyAmountPreferenceObj,
750
756
  isCurrencyMap,