@lightsparkdev/core 1.4.2 → 1.4.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - e9152bc: - Add INR support to utils/currency
8
+ - Avoid loading graphql-ws in Bare environment due to lack of support there
9
+
3
10
  ## 1.4.2
4
11
 
5
12
  ### Patch Changes
@@ -50,6 +50,7 @@ var b64encode = (data) => {
50
50
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
51
51
  var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
52
52
  var isTest = isNode && process.env.NODE_ENV === "test";
53
+ var isBare = typeof Bare !== "undefined";
53
54
 
54
55
  // src/utils/hex.ts
55
56
  var bytesToHex = (bytes) => {
@@ -410,6 +411,7 @@ var CurrencyUnit = {
410
411
  PHP: "PHP",
411
412
  EUR: "EUR",
412
413
  GBP: "GBP",
414
+ INR: "INR",
413
415
  Bitcoin: "BITCOIN",
414
416
  Microbitcoin: "MICROBITCOIN",
415
417
  Millibitcoin: "MILLIBITCOIN",
@@ -419,7 +421,8 @@ var CurrencyUnit = {
419
421
  Usd: "USD",
420
422
  Mxn: "MXN",
421
423
  Php: "PHP",
422
- Gbp: "GBP"
424
+ Gbp: "GBP",
425
+ Inr: "INR"
423
426
  };
424
427
  var standardUnitConversionObj = {
425
428
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -433,7 +436,8 @@ var standardUnitConversionObj = {
433
436
  [CurrencyUnit.MXN]: (v) => v,
434
437
  [CurrencyUnit.PHP]: (v) => v,
435
438
  [CurrencyUnit.EUR]: (v) => v,
436
- [CurrencyUnit.GBP]: (v) => v
439
+ [CurrencyUnit.GBP]: (v) => v,
440
+ [CurrencyUnit.INR]: (v) => v
437
441
  };
438
442
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
439
443
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -453,7 +457,8 @@ var CONVERSION_MAP = {
453
457
  [CurrencyUnit.MXN]: toBitcoinConversion,
454
458
  [CurrencyUnit.PHP]: toBitcoinConversion,
455
459
  [CurrencyUnit.EUR]: toBitcoinConversion,
456
- [CurrencyUnit.GBP]: toBitcoinConversion
460
+ [CurrencyUnit.GBP]: toBitcoinConversion,
461
+ [CurrencyUnit.INR]: toBitcoinConversion
457
462
  },
458
463
  [CurrencyUnit.MICROBITCOIN]: {
459
464
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -466,7 +471,8 @@ var CONVERSION_MAP = {
466
471
  [CurrencyUnit.MXN]: toMicrobitcoinConversion,
467
472
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
468
473
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
469
- [CurrencyUnit.GBP]: toMicrobitcoinConversion
474
+ [CurrencyUnit.GBP]: toMicrobitcoinConversion,
475
+ [CurrencyUnit.INR]: toMicrobitcoinConversion
470
476
  },
471
477
  [CurrencyUnit.MILLIBITCOIN]: {
472
478
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -479,7 +485,8 @@ var CONVERSION_MAP = {
479
485
  [CurrencyUnit.MXN]: toMillibitcoinConversion,
480
486
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
481
487
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
482
- [CurrencyUnit.GBP]: toMillibitcoinConversion
488
+ [CurrencyUnit.GBP]: toMillibitcoinConversion,
489
+ [CurrencyUnit.INR]: toMillibitcoinConversion
483
490
  },
484
491
  [CurrencyUnit.MILLISATOSHI]: {
485
492
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -492,7 +499,8 @@ var CONVERSION_MAP = {
492
499
  [CurrencyUnit.MXN]: toMillisatoshiConversion,
493
500
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
494
501
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
495
- [CurrencyUnit.GBP]: toMillisatoshiConversion
502
+ [CurrencyUnit.GBP]: toMillisatoshiConversion,
503
+ [CurrencyUnit.INR]: toMillisatoshiConversion
496
504
  },
497
505
  [CurrencyUnit.NANOBITCOIN]: {
498
506
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -505,7 +513,8 @@ var CONVERSION_MAP = {
505
513
  [CurrencyUnit.MXN]: toNanobitcoinConversion,
506
514
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
507
515
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
508
- [CurrencyUnit.GBP]: toNanobitcoinConversion
516
+ [CurrencyUnit.GBP]: toNanobitcoinConversion,
517
+ [CurrencyUnit.INR]: toNanobitcoinConversion
509
518
  },
510
519
  [CurrencyUnit.SATOSHI]: {
511
520
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -518,13 +527,15 @@ var CONVERSION_MAP = {
518
527
  [CurrencyUnit.MXN]: toSatoshiConversion,
519
528
  [CurrencyUnit.PHP]: toSatoshiConversion,
520
529
  [CurrencyUnit.EUR]: toSatoshiConversion,
521
- [CurrencyUnit.GBP]: toSatoshiConversion
530
+ [CurrencyUnit.GBP]: toSatoshiConversion,
531
+ [CurrencyUnit.INR]: toSatoshiConversion
522
532
  },
523
533
  [CurrencyUnit.USD]: standardUnitConversionObj,
524
534
  [CurrencyUnit.MXN]: standardUnitConversionObj,
525
535
  [CurrencyUnit.PHP]: standardUnitConversionObj,
526
536
  [CurrencyUnit.EUR]: standardUnitConversionObj,
527
- [CurrencyUnit.GBP]: standardUnitConversionObj
537
+ [CurrencyUnit.GBP]: standardUnitConversionObj,
538
+ [CurrencyUnit.INR]: standardUnitConversionObj
528
539
  };
529
540
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
530
541
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -609,6 +620,7 @@ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversi
609
620
  php: CurrencyUnit.PHP,
610
621
  eur: CurrencyUnit.EUR,
611
622
  gbp: CurrencyUnit.GBP,
623
+ inr: CurrencyUnit.INR,
612
624
  mibtc: CurrencyUnit.MICROBITCOIN,
613
625
  mlbtc: CurrencyUnit.MILLIBITCOIN,
614
626
  nbtc: CurrencyUnit.NANOBITCOIN
@@ -647,7 +659,7 @@ function getPreferredConversionOverride(currencyAmountArg) {
647
659
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
648
660
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
649
661
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
650
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
662
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
651
663
  const mapWithCurrencyUnits = {
652
664
  [CurrencyUnit.BITCOIN]: btc,
653
665
  [CurrencyUnit.SATOSHI]: sats,
@@ -657,6 +669,7 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
657
669
  [CurrencyUnit.PHP]: php,
658
670
  [CurrencyUnit.EUR]: eur,
659
671
  [CurrencyUnit.GBP]: gbp,
672
+ [CurrencyUnit.INR]: inr,
660
673
  [CurrencyUnit.MICROBITCOIN]: mibtc,
661
674
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
662
675
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -706,6 +719,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
706
719
  value: gbp,
707
720
  unit: CurrencyUnit.GBP
708
721
  }),
722
+ [CurrencyUnit.INR]: formatCurrencyStr({
723
+ value: inr,
724
+ unit: CurrencyUnit.INR
725
+ }),
709
726
  [CurrencyUnit.FUTURE_VALUE]: "-"
710
727
  }
711
728
  };
@@ -774,6 +791,8 @@ var abbrCurrencyUnit = (unit) => {
774
791
  return "EUR";
775
792
  case CurrencyUnit.GBP:
776
793
  return "GBP";
794
+ case CurrencyUnit.INR:
795
+ return "INR";
777
796
  }
778
797
  return "Unsupported CurrencyUnit";
779
798
  };
@@ -906,6 +925,15 @@ function localeToCurrencySymbol(locale) {
906
925
  const { symbol } = separateCurrencyStrParts(formatted);
907
926
  return symbol;
908
927
  }
928
+ function formatInviteAmount(amount, currency) {
929
+ if (!amount || !currency) {
930
+ return "";
931
+ }
932
+ const displayAmount = (amount / Math.pow(10, currency.decimals)).toFixed(
933
+ currency.decimals
934
+ );
935
+ return `${displayAmount} ${currency.code}`;
936
+ }
909
937
 
910
938
  // src/utils/typeGuards.ts
911
939
  function isUint8Array(value) {
@@ -2205,6 +2233,7 @@ export {
2205
2233
  isBrowser,
2206
2234
  isNode,
2207
2235
  isTest,
2236
+ isBare,
2208
2237
  bytesToHex,
2209
2238
  hexToBytes,
2210
2239
  createSha256Hash,
@@ -2232,6 +2261,7 @@ export {
2232
2261
  formatCurrencyStr,
2233
2262
  separateCurrencyStrParts,
2234
2263
  localeToCurrencySymbol,
2264
+ formatInviteAmount,
2235
2265
  isUint8Array,
2236
2266
  isObject,
2237
2267
  isRecord,
@@ -28,6 +28,7 @@ declare const CurrencyUnit: {
28
28
  readonly PHP: "PHP";
29
29
  readonly EUR: "EUR";
30
30
  readonly GBP: "GBP";
31
+ readonly INR: "INR";
31
32
  readonly Bitcoin: "BITCOIN";
32
33
  readonly Microbitcoin: "MICROBITCOIN";
33
34
  readonly Millibitcoin: "MILLIBITCOIN";
@@ -38,6 +39,7 @@ declare const CurrencyUnit: {
38
39
  readonly Mxn: "MXN";
39
40
  readonly Php: "PHP";
40
41
  readonly Gbp: "GBP";
42
+ readonly Inr: "INR";
41
43
  };
42
44
  type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
43
45
  type SDKCurrencyAmountType = {
@@ -64,6 +66,7 @@ type CurrencyMap = {
64
66
  [CurrencyUnit.PHP]: number;
65
67
  [CurrencyUnit.EUR]: number;
66
68
  [CurrencyUnit.GBP]: number;
69
+ [CurrencyUnit.INR]: number;
67
70
  [CurrencyUnit.FUTURE_VALUE]: number;
68
71
  formatted: {
69
72
  sats: string;
@@ -80,6 +83,7 @@ type CurrencyMap = {
80
83
  [CurrencyUnit.PHP]: string;
81
84
  [CurrencyUnit.EUR]: string;
82
85
  [CurrencyUnit.GBP]: string;
86
+ [CurrencyUnit.INR]: string;
83
87
  [CurrencyUnit.FUTURE_VALUE]: string;
84
88
  };
85
89
  isZero: boolean;
@@ -135,7 +139,7 @@ declare function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg): {
135
139
  };
136
140
  declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
137
141
  declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
138
- declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "EUR" | "USD" | "GBP" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
142
+ declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "EUR" | "USD" | "GBP" | "INR" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
139
143
  type AppendUnitsOptions = {
140
144
  plural?: boolean | undefined;
141
145
  lowercase?: boolean | undefined;
@@ -153,10 +157,21 @@ declare function separateCurrencyStrParts(currencyStr: string): {
153
157
  amount: string;
154
158
  };
155
159
  declare function localeToCurrencySymbol(locale: string): string;
160
+ /**
161
+ * Formats an amount from the smallest currency unit to a display string
162
+ * @param amount - The amount in the smallest currency unit (No decimals)
163
+ * @param currency - The currency object with code and decimals
164
+ * @returns Formatted string like "12.50 USD" or empty string if invalid
165
+ */
166
+ declare function formatInviteAmount(amount: number | null | undefined, currency: UmaCurrency | null | undefined): string;
156
167
 
168
+ declare global {
169
+ const Bare: unknown;
170
+ }
157
171
  declare const isBrowser: boolean;
158
172
  declare const isNode: boolean;
159
173
  declare const isTest: boolean;
174
+ declare const isBare: boolean;
160
175
 
161
176
  type Maybe<T> = T | null | undefined;
162
177
  type ExpandRecursively<T> = T extends object ? T extends infer O ? {
@@ -321,4 +336,4 @@ declare const zipcodeToStateCode: Record<string, StateCode>;
321
336
  */
322
337
  declare function zipcodeToState(zipcode: string): StateCode | null;
323
338
 
324
- export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, isRecord as a8, type Maybe as a9, type ExpandRecursively as aa, type ById as ab, type OmitTypename as ac, isType as ad, type ExtractByTypename as ae, type DeepPartial as af, type JSONLiteral as ag, type JSONType as ah, type JSONObject as ai, type NN as aj, notNullUndefined as ak, type PartialBy as al, type Complete as am, type RequiredKeys as an, type StateCode as ao, zipcodeToStateCode as ap, zipcodeToState as aq, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
339
+ export { setLocalStorageBoolean as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, formatInviteAmount as G, isBrowser as H, isNode as I, isTest as J, isBare as K, isError as L, isErrorWithMessage as M, getErrorMsg as N, isErrorMsg as O, errorToJSON as P, bytesToHex as Q, hexToBytes as R, type SDKCurrencyAmountType as S, getCurrentLocale as T, type UmaCurrency as U, countryCodesToCurrencyCodes as V, type CurrencyLocales as W, type CurrencyCodes as X, localeToCurrencyCode as Y, getLocalStorageConfigItem as Z, getLocalStorageBoolean as _, b64encode as a, deleteLocalStorageItem as a0, clamp as a1, linearInterpolate as a2, round as a3, isNumber as a4, pollUntil as a5, sleep as a6, lsidToUUID as a7, isUint8Array as a8, isObject as a9, isRecord as aa, type Maybe as ab, type ExpandRecursively as ac, type ById as ad, type OmitTypename as ae, isType as af, type ExtractByTypename as ag, type DeepPartial as ah, type JSONLiteral as ai, type JSONType as aj, type JSONObject as ak, type NN as al, notNullUndefined as am, type PartialBy as an, type Complete as ao, type RequiredKeys as ap, type StateCode as aq, zipcodeToStateCode as ar, zipcodeToState as as, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
@@ -28,6 +28,7 @@ declare const CurrencyUnit: {
28
28
  readonly PHP: "PHP";
29
29
  readonly EUR: "EUR";
30
30
  readonly GBP: "GBP";
31
+ readonly INR: "INR";
31
32
  readonly Bitcoin: "BITCOIN";
32
33
  readonly Microbitcoin: "MICROBITCOIN";
33
34
  readonly Millibitcoin: "MILLIBITCOIN";
@@ -38,6 +39,7 @@ declare const CurrencyUnit: {
38
39
  readonly Mxn: "MXN";
39
40
  readonly Php: "PHP";
40
41
  readonly Gbp: "GBP";
42
+ readonly Inr: "INR";
41
43
  };
42
44
  type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
43
45
  type SDKCurrencyAmountType = {
@@ -64,6 +66,7 @@ type CurrencyMap = {
64
66
  [CurrencyUnit.PHP]: number;
65
67
  [CurrencyUnit.EUR]: number;
66
68
  [CurrencyUnit.GBP]: number;
69
+ [CurrencyUnit.INR]: number;
67
70
  [CurrencyUnit.FUTURE_VALUE]: number;
68
71
  formatted: {
69
72
  sats: string;
@@ -80,6 +83,7 @@ type CurrencyMap = {
80
83
  [CurrencyUnit.PHP]: string;
81
84
  [CurrencyUnit.EUR]: string;
82
85
  [CurrencyUnit.GBP]: string;
86
+ [CurrencyUnit.INR]: string;
83
87
  [CurrencyUnit.FUTURE_VALUE]: string;
84
88
  };
85
89
  isZero: boolean;
@@ -135,7 +139,7 @@ declare function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg): {
135
139
  };
136
140
  declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, unitsPerBtc?: number): CurrencyMap;
137
141
  declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
138
- declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "EUR" | "USD" | "GBP" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
142
+ declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "EUR" | "USD" | "GBP" | "INR" | "MXN" | "PHP" | "BTC" | "SAT" | "MSAT" | "mBTC" | "μBTC" | "Unsupported CurrencyUnit";
139
143
  type AppendUnitsOptions = {
140
144
  plural?: boolean | undefined;
141
145
  lowercase?: boolean | undefined;
@@ -153,10 +157,21 @@ declare function separateCurrencyStrParts(currencyStr: string): {
153
157
  amount: string;
154
158
  };
155
159
  declare function localeToCurrencySymbol(locale: string): string;
160
+ /**
161
+ * Formats an amount from the smallest currency unit to a display string
162
+ * @param amount - The amount in the smallest currency unit (No decimals)
163
+ * @param currency - The currency object with code and decimals
164
+ * @returns Formatted string like "12.50 USD" or empty string if invalid
165
+ */
166
+ declare function formatInviteAmount(amount: number | null | undefined, currency: UmaCurrency | null | undefined): string;
156
167
 
168
+ declare global {
169
+ const Bare: unknown;
170
+ }
157
171
  declare const isBrowser: boolean;
158
172
  declare const isNode: boolean;
159
173
  declare const isTest: boolean;
174
+ declare const isBare: boolean;
160
175
 
161
176
  type Maybe<T> = T | null | undefined;
162
177
  type ExpandRecursively<T> = T extends object ? T extends infer O ? {
@@ -321,4 +336,4 @@ declare const zipcodeToStateCode: Record<string, StateCode>;
321
336
  */
322
337
  declare function zipcodeToState(zipcode: string): StateCode | null;
323
338
 
324
- export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, isRecord as a8, type Maybe as a9, type ExpandRecursively as aa, type ById as ab, type OmitTypename as ac, isType as ad, type ExtractByTypename as ae, type DeepPartial as af, type JSONLiteral as ag, type JSONType as ah, type JSONObject as ai, type NN as aj, notNullUndefined as ak, type PartialBy as al, type Complete as am, type RequiredKeys as an, type StateCode as ao, zipcodeToStateCode as ap, zipcodeToState as aq, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
339
+ export { setLocalStorageBoolean as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, formatInviteAmount as G, isBrowser as H, isNode as I, isTest as J, isBare as K, isError as L, isErrorWithMessage as M, getErrorMsg as N, isErrorMsg as O, errorToJSON as P, bytesToHex as Q, hexToBytes as R, type SDKCurrencyAmountType as S, getCurrentLocale as T, type UmaCurrency as U, countryCodesToCurrencyCodes as V, type CurrencyLocales as W, type CurrencyCodes as X, localeToCurrencyCode as Y, getLocalStorageConfigItem as Z, getLocalStorageBoolean as _, b64encode as a, deleteLocalStorageItem as a0, clamp as a1, linearInterpolate as a2, round as a3, isNumber as a4, pollUntil as a5, sleep as a6, lsidToUUID as a7, isUint8Array as a8, isObject as a9, isRecord as aa, type Maybe as ab, type ExpandRecursively as ac, type ById as ad, type OmitTypename as ae, isType as af, type ExtractByTypename as ag, type DeepPartial as ah, type JSONLiteral as ai, type JSONType as aj, type JSONObject as ak, type NN as al, notNullUndefined as am, type PartialBy as an, type Complete as ao, type RequiredKeys as ap, type StateCode as aq, zipcodeToStateCode as ar, zipcodeToState as as, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
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
+ formatInviteAmount: () => formatInviteAmount,
65
66
  getCurrencyAmount: () => getCurrencyAmount,
66
67
  getCurrentLocale: () => getCurrentLocale,
67
68
  getErrorMsg: () => getErrorMsg,
68
69
  getLocalStorageBoolean: () => getLocalStorageBoolean,
69
70
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
70
71
  hexToBytes: () => hexToBytes,
72
+ isBare: () => isBare,
71
73
  isBrowser: () => isBrowser,
72
74
  isCurrencyAmountInputObj: () => isCurrencyAmountInputObj,
73
75
  isCurrencyAmountObj: () => isCurrencyAmountObj,
@@ -457,6 +459,7 @@ function ensureArray(value) {
457
459
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
458
460
  var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
459
461
  var isTest = isNode && process.env.NODE_ENV === "test";
462
+ var isBare = typeof Bare !== "undefined";
460
463
 
461
464
  // src/utils/hex.ts
462
465
  var bytesToHex = (bytes) => {
@@ -803,6 +806,7 @@ var CurrencyUnit = {
803
806
  PHP: "PHP",
804
807
  EUR: "EUR",
805
808
  GBP: "GBP",
809
+ INR: "INR",
806
810
  Bitcoin: "BITCOIN",
807
811
  Microbitcoin: "MICROBITCOIN",
808
812
  Millibitcoin: "MILLIBITCOIN",
@@ -812,7 +816,8 @@ var CurrencyUnit = {
812
816
  Usd: "USD",
813
817
  Mxn: "MXN",
814
818
  Php: "PHP",
815
- Gbp: "GBP"
819
+ Gbp: "GBP",
820
+ Inr: "INR"
816
821
  };
817
822
  var standardUnitConversionObj = {
818
823
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -826,7 +831,8 @@ var standardUnitConversionObj = {
826
831
  [CurrencyUnit.MXN]: (v) => v,
827
832
  [CurrencyUnit.PHP]: (v) => v,
828
833
  [CurrencyUnit.EUR]: (v) => v,
829
- [CurrencyUnit.GBP]: (v) => v
834
+ [CurrencyUnit.GBP]: (v) => v,
835
+ [CurrencyUnit.INR]: (v) => v
830
836
  };
831
837
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
832
838
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -846,7 +852,8 @@ var CONVERSION_MAP = {
846
852
  [CurrencyUnit.MXN]: toBitcoinConversion,
847
853
  [CurrencyUnit.PHP]: toBitcoinConversion,
848
854
  [CurrencyUnit.EUR]: toBitcoinConversion,
849
- [CurrencyUnit.GBP]: toBitcoinConversion
855
+ [CurrencyUnit.GBP]: toBitcoinConversion,
856
+ [CurrencyUnit.INR]: toBitcoinConversion
850
857
  },
851
858
  [CurrencyUnit.MICROBITCOIN]: {
852
859
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -859,7 +866,8 @@ var CONVERSION_MAP = {
859
866
  [CurrencyUnit.MXN]: toMicrobitcoinConversion,
860
867
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
861
868
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
862
- [CurrencyUnit.GBP]: toMicrobitcoinConversion
869
+ [CurrencyUnit.GBP]: toMicrobitcoinConversion,
870
+ [CurrencyUnit.INR]: toMicrobitcoinConversion
863
871
  },
864
872
  [CurrencyUnit.MILLIBITCOIN]: {
865
873
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -872,7 +880,8 @@ var CONVERSION_MAP = {
872
880
  [CurrencyUnit.MXN]: toMillibitcoinConversion,
873
881
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
874
882
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
875
- [CurrencyUnit.GBP]: toMillibitcoinConversion
883
+ [CurrencyUnit.GBP]: toMillibitcoinConversion,
884
+ [CurrencyUnit.INR]: toMillibitcoinConversion
876
885
  },
877
886
  [CurrencyUnit.MILLISATOSHI]: {
878
887
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -885,7 +894,8 @@ var CONVERSION_MAP = {
885
894
  [CurrencyUnit.MXN]: toMillisatoshiConversion,
886
895
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
887
896
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
888
- [CurrencyUnit.GBP]: toMillisatoshiConversion
897
+ [CurrencyUnit.GBP]: toMillisatoshiConversion,
898
+ [CurrencyUnit.INR]: toMillisatoshiConversion
889
899
  },
890
900
  [CurrencyUnit.NANOBITCOIN]: {
891
901
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -898,7 +908,8 @@ var CONVERSION_MAP = {
898
908
  [CurrencyUnit.MXN]: toNanobitcoinConversion,
899
909
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
900
910
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
901
- [CurrencyUnit.GBP]: toNanobitcoinConversion
911
+ [CurrencyUnit.GBP]: toNanobitcoinConversion,
912
+ [CurrencyUnit.INR]: toNanobitcoinConversion
902
913
  },
903
914
  [CurrencyUnit.SATOSHI]: {
904
915
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -911,13 +922,15 @@ var CONVERSION_MAP = {
911
922
  [CurrencyUnit.MXN]: toSatoshiConversion,
912
923
  [CurrencyUnit.PHP]: toSatoshiConversion,
913
924
  [CurrencyUnit.EUR]: toSatoshiConversion,
914
- [CurrencyUnit.GBP]: toSatoshiConversion
925
+ [CurrencyUnit.GBP]: toSatoshiConversion,
926
+ [CurrencyUnit.INR]: toSatoshiConversion
915
927
  },
916
928
  [CurrencyUnit.USD]: standardUnitConversionObj,
917
929
  [CurrencyUnit.MXN]: standardUnitConversionObj,
918
930
  [CurrencyUnit.PHP]: standardUnitConversionObj,
919
931
  [CurrencyUnit.EUR]: standardUnitConversionObj,
920
- [CurrencyUnit.GBP]: standardUnitConversionObj
932
+ [CurrencyUnit.GBP]: standardUnitConversionObj,
933
+ [CurrencyUnit.INR]: standardUnitConversionObj
921
934
  };
922
935
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
923
936
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -1002,6 +1015,7 @@ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversi
1002
1015
  php: CurrencyUnit.PHP,
1003
1016
  eur: CurrencyUnit.EUR,
1004
1017
  gbp: CurrencyUnit.GBP,
1018
+ inr: CurrencyUnit.INR,
1005
1019
  mibtc: CurrencyUnit.MICROBITCOIN,
1006
1020
  mlbtc: CurrencyUnit.MILLIBITCOIN,
1007
1021
  nbtc: CurrencyUnit.NANOBITCOIN
@@ -1040,7 +1054,7 @@ function getPreferredConversionOverride(currencyAmountArg) {
1040
1054
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
1041
1055
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
1042
1056
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
1043
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
1057
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
1044
1058
  const mapWithCurrencyUnits = {
1045
1059
  [CurrencyUnit.BITCOIN]: btc,
1046
1060
  [CurrencyUnit.SATOSHI]: sats,
@@ -1050,6 +1064,7 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
1050
1064
  [CurrencyUnit.PHP]: php,
1051
1065
  [CurrencyUnit.EUR]: eur,
1052
1066
  [CurrencyUnit.GBP]: gbp,
1067
+ [CurrencyUnit.INR]: inr,
1053
1068
  [CurrencyUnit.MICROBITCOIN]: mibtc,
1054
1069
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
1055
1070
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -1099,6 +1114,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
1099
1114
  value: gbp,
1100
1115
  unit: CurrencyUnit.GBP
1101
1116
  }),
1117
+ [CurrencyUnit.INR]: formatCurrencyStr({
1118
+ value: inr,
1119
+ unit: CurrencyUnit.INR
1120
+ }),
1102
1121
  [CurrencyUnit.FUTURE_VALUE]: "-"
1103
1122
  }
1104
1123
  };
@@ -1167,6 +1186,8 @@ var abbrCurrencyUnit = (unit) => {
1167
1186
  return "EUR";
1168
1187
  case CurrencyUnit.GBP:
1169
1188
  return "GBP";
1189
+ case CurrencyUnit.INR:
1190
+ return "INR";
1170
1191
  }
1171
1192
  return "Unsupported CurrencyUnit";
1172
1193
  };
@@ -1299,6 +1320,15 @@ function localeToCurrencySymbol(locale) {
1299
1320
  const { symbol } = separateCurrencyStrParts(formatted);
1300
1321
  return symbol;
1301
1322
  }
1323
+ function formatInviteAmount(amount, currency) {
1324
+ if (!amount || !currency) {
1325
+ return "";
1326
+ }
1327
+ const displayAmount = (amount / Math.pow(10, currency.decimals)).toFixed(
1328
+ currency.decimals
1329
+ );
1330
+ return `${displayAmount} ${currency.code}`;
1331
+ }
1302
1332
 
1303
1333
  // src/utils/typeGuards.ts
1304
1334
  function isUint8Array(value) {
@@ -2738,7 +2768,6 @@ var logger = new Logger("@lightsparkdev/core");
2738
2768
  // src/requester/Requester.ts
2739
2769
  var import_dayjs = __toESM(require("dayjs"), 1);
2740
2770
  var import_utc = __toESM(require("dayjs/plugin/utc.js"), 1);
2741
- var import_graphql_ws = require("graphql-ws");
2742
2771
  var import_zen_observable_ts = require("zen-observable-ts");
2743
2772
  var DEFAULT_BASE_URL = "api.lightspark.com";
2744
2773
  import_dayjs.default.extend(import_utc.default);
@@ -2764,6 +2793,9 @@ var Requester = class {
2764
2793
  if (!this.resolveWsClient) {
2765
2794
  return this.wsClient;
2766
2795
  }
2796
+ if (isBare) {
2797
+ return null;
2798
+ }
2767
2799
  let websocketImpl;
2768
2800
  if (isNode && typeof WebSocket === "undefined") {
2769
2801
  const wsModule = await import("ws");
@@ -2773,7 +2805,9 @@ var Requester = class {
2773
2805
  if (baseUrl.startsWith("http://")) {
2774
2806
  websocketProtocol = "ws";
2775
2807
  }
2776
- const wsClient = (0, import_graphql_ws.createClient)({
2808
+ const graphqlWsModule = await import("graphql-ws");
2809
+ const { createClient } = graphqlWsModule;
2810
+ const wsClient = createClient({
2777
2811
  url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
2778
2812
  connectionParams: () => authProvider.addWsConnectionParams({}),
2779
2813
  webSocketImpl: websocketImpl
@@ -2826,6 +2860,12 @@ var Requester = class {
2826
2860
  void (async () => {
2827
2861
  try {
2828
2862
  const wsClient = await this.wsClient;
2863
+ if (!wsClient) {
2864
+ throw new LightsparkException_default(
2865
+ "WebSocketNotInitialized",
2866
+ "WebSocket client is not initialized or is not available in the current environment."
2867
+ );
2868
+ }
2829
2869
  if (!canceled) {
2830
2870
  cleanup = wsClient.subscribe(bodyData, {
2831
2871
  next: (data) => observer.next(data),
@@ -3035,12 +3075,14 @@ var ServerEnvironment_default = ServerEnvironment;
3035
3075
  ensureArray,
3036
3076
  errorToJSON,
3037
3077
  formatCurrencyStr,
3078
+ formatInviteAmount,
3038
3079
  getCurrencyAmount,
3039
3080
  getCurrentLocale,
3040
3081
  getErrorMsg,
3041
3082
  getLocalStorageBoolean,
3042
3083
  getLocalStorageConfigItem,
3043
3084
  hexToBytes,
3085
+ isBare,
3044
3086
  isBrowser,
3045
3087
  isCurrencyAmountInputObj,
3046
3088
  isCurrencyAmountObj,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppendUnitsOptions, ab as ById, am as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, ao as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode, aq as zipcodeToState, ap as zipcodeToStateCode } from './index-BCTAeaWD.cjs';
1
+ export { A as AppendUnitsOptions, ad as ById, ao as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, X as CurrencyCodes, W as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ah as DeepPartial, D as DeprecatedCurrencyAmountObj, ac as ExpandRecursively, ag as ExtractByTypename, ai as JSONLiteral, ak as JSONObject, aj as JSONType, ab as Maybe, al as NN, ae as OmitTypename, an as PartialBy, ap as RequiredKeys, S as SDKCurrencyAmountType, aq as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, Q as bytesToHex, a1 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, V as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a0 as deleteLocalStorageItem, e as ensureArray, P as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, T as getCurrentLocale, N as getErrorMsg, _ as getLocalStorageBoolean, Z as getLocalStorageConfigItem, R as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, L as isError, O as isErrorMsg, M as isErrorWithMessage, I as isNode, a4 as isNumber, a9 as isObject, aa as isRecord, v as isSDKCurrencyAmount, J as isTest, af as isType, a8 as isUint8Array, q as isUmaCurrencyAmount, a2 as linearInterpolate, Y as localeToCurrencyCode, F as localeToCurrencySymbol, a7 as lsidToUUID, x as mapCurrencyAmount, am as notNullUndefined, a5 as pollUntil, a3 as round, E as separateCurrencyStrParts, $ as setLocalStorageBoolean, a6 as sleep, u as urlsafe_b64decode, as as zipcodeToState, ar as zipcodeToStateCode } from './index-gUXiTlhb.cjs';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppendUnitsOptions, ab as ById, am as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, ao as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode, aq as zipcodeToState, ap as zipcodeToStateCode } from './index-BCTAeaWD.js';
1
+ export { A as AppendUnitsOptions, ad as ById, ao as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, X as CurrencyCodes, W as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ah as DeepPartial, D as DeprecatedCurrencyAmountObj, ac as ExpandRecursively, ag as ExtractByTypename, ai as JSONLiteral, ak as JSONObject, aj as JSONType, ab as Maybe, al as NN, ae as OmitTypename, an as PartialBy, ap as RequiredKeys, S as SDKCurrencyAmountType, aq as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, Q as bytesToHex, a1 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, V as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a0 as deleteLocalStorageItem, e as ensureArray, P as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, T as getCurrentLocale, N as getErrorMsg, _ as getLocalStorageBoolean, Z as getLocalStorageConfigItem, R as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, L as isError, O as isErrorMsg, M as isErrorWithMessage, I as isNode, a4 as isNumber, a9 as isObject, aa as isRecord, v as isSDKCurrencyAmount, J as isTest, af as isType, a8 as isUint8Array, q as isUmaCurrencyAmount, a2 as linearInterpolate, Y as localeToCurrencyCode, F as localeToCurrencySymbol, a7 as lsidToUUID, x as mapCurrencyAmount, am as notNullUndefined, a5 as pollUntil, a3 as round, E as separateCurrencyStrParts, $ as setLocalStorageBoolean, a6 as sleep, u as urlsafe_b64decode, as as zipcodeToState, ar as zipcodeToStateCode } from './index-gUXiTlhb.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
package/dist/index.js CHANGED
@@ -15,12 +15,14 @@ import {
15
15
  ensureArray,
16
16
  errorToJSON,
17
17
  formatCurrencyStr,
18
+ formatInviteAmount,
18
19
  getCurrencyAmount,
19
20
  getCurrentLocale,
20
21
  getErrorMsg,
21
22
  getLocalStorageBoolean,
22
23
  getLocalStorageConfigItem,
23
24
  hexToBytes,
25
+ isBare,
24
26
  isBrowser,
25
27
  isCurrencyAmountInputObj,
26
28
  isCurrencyAmountObj,
@@ -53,7 +55,7 @@ import {
53
55
  urlsafe_b64decode,
54
56
  zipcodeToState,
55
57
  zipcodeToStateCode
56
- } from "./chunk-CP4LQTTD.js";
58
+ } from "./chunk-36QHRQJC.js";
57
59
 
58
60
  // src/auth/LightsparkAuthException.ts
59
61
  var LightsparkAuthException = class extends LightsparkException_default {
@@ -489,7 +491,6 @@ var logger = new Logger("@lightsparkdev/core");
489
491
  // src/requester/Requester.ts
490
492
  import dayjs from "dayjs";
491
493
  import utc from "dayjs/plugin/utc.js";
492
- import { createClient } from "graphql-ws";
493
494
  import { Observable } from "zen-observable-ts";
494
495
  var DEFAULT_BASE_URL = "api.lightspark.com";
495
496
  dayjs.extend(utc);
@@ -515,6 +516,9 @@ var Requester = class {
515
516
  if (!this.resolveWsClient) {
516
517
  return this.wsClient;
517
518
  }
519
+ if (isBare) {
520
+ return null;
521
+ }
518
522
  let websocketImpl;
519
523
  if (isNode && typeof WebSocket === "undefined") {
520
524
  const wsModule = await import("ws");
@@ -524,6 +528,8 @@ var Requester = class {
524
528
  if (baseUrl.startsWith("http://")) {
525
529
  websocketProtocol = "ws";
526
530
  }
531
+ const graphqlWsModule = await import("graphql-ws");
532
+ const { createClient } = graphqlWsModule;
527
533
  const wsClient = createClient({
528
534
  url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
529
535
  connectionParams: () => authProvider.addWsConnectionParams({}),
@@ -577,6 +583,12 @@ var Requester = class {
577
583
  void (async () => {
578
584
  try {
579
585
  const wsClient = await this.wsClient;
586
+ if (!wsClient) {
587
+ throw new LightsparkException_default(
588
+ "WebSocketNotInitialized",
589
+ "WebSocket client is not initialized or is not available in the current environment."
590
+ );
591
+ }
580
592
  if (!canceled) {
581
593
  cleanup = wsClient.subscribe(bodyData, {
582
594
  next: (data) => observer.next(data),
@@ -785,12 +797,14 @@ export {
785
797
  ensureArray,
786
798
  errorToJSON,
787
799
  formatCurrencyStr,
800
+ formatInviteAmount,
788
801
  getCurrencyAmount,
789
802
  getCurrentLocale,
790
803
  getErrorMsg,
791
804
  getLocalStorageBoolean,
792
805
  getLocalStorageConfigItem,
793
806
  hexToBytes,
807
+ isBare,
794
808
  isBrowser,
795
809
  isCurrencyAmountInputObj,
796
810
  isCurrencyAmountObj,
@@ -45,12 +45,14 @@ __export(utils_exports, {
45
45
  ensureArray: () => ensureArray,
46
46
  errorToJSON: () => errorToJSON,
47
47
  formatCurrencyStr: () => formatCurrencyStr,
48
+ formatInviteAmount: () => formatInviteAmount,
48
49
  getCurrencyAmount: () => getCurrencyAmount,
49
50
  getCurrentLocale: () => getCurrentLocale,
50
51
  getErrorMsg: () => getErrorMsg,
51
52
  getLocalStorageBoolean: () => getLocalStorageBoolean,
52
53
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
53
54
  hexToBytes: () => hexToBytes,
55
+ isBare: () => isBare,
54
56
  isBrowser: () => isBrowser,
55
57
  isCurrencyAmountInputObj: () => isCurrencyAmountInputObj,
56
58
  isCurrencyAmountObj: () => isCurrencyAmountObj,
@@ -138,6 +140,7 @@ var b64encode = (data) => {
138
140
  var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
139
141
  var isNode = typeof process !== "undefined" && process.versions != null && process.versions.node != null;
140
142
  var isTest = isNode && process.env.NODE_ENV === "test";
143
+ var isBare = typeof Bare !== "undefined";
141
144
 
142
145
  // src/utils/hex.ts
143
146
  var bytesToHex = (bytes) => {
@@ -498,6 +501,7 @@ var CurrencyUnit = {
498
501
  PHP: "PHP",
499
502
  EUR: "EUR",
500
503
  GBP: "GBP",
504
+ INR: "INR",
501
505
  Bitcoin: "BITCOIN",
502
506
  Microbitcoin: "MICROBITCOIN",
503
507
  Millibitcoin: "MILLIBITCOIN",
@@ -507,7 +511,8 @@ var CurrencyUnit = {
507
511
  Usd: "USD",
508
512
  Mxn: "MXN",
509
513
  Php: "PHP",
510
- Gbp: "GBP"
514
+ Gbp: "GBP",
515
+ Inr: "INR"
511
516
  };
512
517
  var standardUnitConversionObj = {
513
518
  [CurrencyUnit.BITCOIN]: (v, unitsPerBtc = 1) => v / unitsPerBtc,
@@ -521,7 +526,8 @@ var standardUnitConversionObj = {
521
526
  [CurrencyUnit.MXN]: (v) => v,
522
527
  [CurrencyUnit.PHP]: (v) => v,
523
528
  [CurrencyUnit.EUR]: (v) => v,
524
- [CurrencyUnit.GBP]: (v) => v
529
+ [CurrencyUnit.GBP]: (v) => v,
530
+ [CurrencyUnit.INR]: (v) => v
525
531
  };
526
532
  var toBitcoinConversion = (v, unitsPerBtc = 1) => round(v * unitsPerBtc);
527
533
  var toMicrobitcoinConversion = (v, unitsPerBtc = 1) => round(v / 1e6 * unitsPerBtc);
@@ -541,7 +547,8 @@ var CONVERSION_MAP = {
541
547
  [CurrencyUnit.MXN]: toBitcoinConversion,
542
548
  [CurrencyUnit.PHP]: toBitcoinConversion,
543
549
  [CurrencyUnit.EUR]: toBitcoinConversion,
544
- [CurrencyUnit.GBP]: toBitcoinConversion
550
+ [CurrencyUnit.GBP]: toBitcoinConversion,
551
+ [CurrencyUnit.INR]: toBitcoinConversion
545
552
  },
546
553
  [CurrencyUnit.MICROBITCOIN]: {
547
554
  [CurrencyUnit.BITCOIN]: (v) => v / 1e6,
@@ -554,7 +561,8 @@ var CONVERSION_MAP = {
554
561
  [CurrencyUnit.MXN]: toMicrobitcoinConversion,
555
562
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
556
563
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
557
- [CurrencyUnit.GBP]: toMicrobitcoinConversion
564
+ [CurrencyUnit.GBP]: toMicrobitcoinConversion,
565
+ [CurrencyUnit.INR]: toMicrobitcoinConversion
558
566
  },
559
567
  [CurrencyUnit.MILLIBITCOIN]: {
560
568
  [CurrencyUnit.BITCOIN]: (v) => v / 1e3,
@@ -567,7 +575,8 @@ var CONVERSION_MAP = {
567
575
  [CurrencyUnit.MXN]: toMillibitcoinConversion,
568
576
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
569
577
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
570
- [CurrencyUnit.GBP]: toMillibitcoinConversion
578
+ [CurrencyUnit.GBP]: toMillibitcoinConversion,
579
+ [CurrencyUnit.INR]: toMillibitcoinConversion
571
580
  },
572
581
  [CurrencyUnit.MILLISATOSHI]: {
573
582
  [CurrencyUnit.BITCOIN]: (v) => v / 1e11,
@@ -580,7 +589,8 @@ var CONVERSION_MAP = {
580
589
  [CurrencyUnit.MXN]: toMillisatoshiConversion,
581
590
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
582
591
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
583
- [CurrencyUnit.GBP]: toMillisatoshiConversion
592
+ [CurrencyUnit.GBP]: toMillisatoshiConversion,
593
+ [CurrencyUnit.INR]: toMillisatoshiConversion
584
594
  },
585
595
  [CurrencyUnit.NANOBITCOIN]: {
586
596
  [CurrencyUnit.BITCOIN]: (v) => v / 1e9,
@@ -593,7 +603,8 @@ var CONVERSION_MAP = {
593
603
  [CurrencyUnit.MXN]: toNanobitcoinConversion,
594
604
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
595
605
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
596
- [CurrencyUnit.GBP]: toNanobitcoinConversion
606
+ [CurrencyUnit.GBP]: toNanobitcoinConversion,
607
+ [CurrencyUnit.INR]: toNanobitcoinConversion
597
608
  },
598
609
  [CurrencyUnit.SATOSHI]: {
599
610
  [CurrencyUnit.BITCOIN]: (v) => v / 1e8,
@@ -606,13 +617,15 @@ var CONVERSION_MAP = {
606
617
  [CurrencyUnit.MXN]: toSatoshiConversion,
607
618
  [CurrencyUnit.PHP]: toSatoshiConversion,
608
619
  [CurrencyUnit.EUR]: toSatoshiConversion,
609
- [CurrencyUnit.GBP]: toSatoshiConversion
620
+ [CurrencyUnit.GBP]: toSatoshiConversion,
621
+ [CurrencyUnit.INR]: toSatoshiConversion
610
622
  },
611
623
  [CurrencyUnit.USD]: standardUnitConversionObj,
612
624
  [CurrencyUnit.MXN]: standardUnitConversionObj,
613
625
  [CurrencyUnit.PHP]: standardUnitConversionObj,
614
626
  [CurrencyUnit.EUR]: standardUnitConversionObj,
615
- [CurrencyUnit.GBP]: standardUnitConversionObj
627
+ [CurrencyUnit.GBP]: standardUnitConversionObj,
628
+ [CurrencyUnit.INR]: standardUnitConversionObj
616
629
  };
617
630
  function convertCurrencyAmountValue(fromUnit, toUnit, amount, unitsPerBtc = 1) {
618
631
  if (fromUnit === CurrencyUnit.FUTURE_VALUE || toUnit === CurrencyUnit.FUTURE_VALUE) {
@@ -697,6 +710,7 @@ function convertCurrencyAmountValues(fromUnit, amount, unitsPerBtc = 1, conversi
697
710
  php: CurrencyUnit.PHP,
698
711
  eur: CurrencyUnit.EUR,
699
712
  gbp: CurrencyUnit.GBP,
713
+ inr: CurrencyUnit.INR,
700
714
  mibtc: CurrencyUnit.MICROBITCOIN,
701
715
  mlbtc: CurrencyUnit.MILLIBITCOIN,
702
716
  nbtc: CurrencyUnit.NANOBITCOIN
@@ -735,7 +749,7 @@ function getPreferredConversionOverride(currencyAmountArg) {
735
749
  function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
736
750
  const { value, unit } = getCurrencyAmount(currencyAmountArg);
737
751
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
738
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
752
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } = convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
739
753
  const mapWithCurrencyUnits = {
740
754
  [CurrencyUnit.BITCOIN]: btc,
741
755
  [CurrencyUnit.SATOSHI]: sats,
@@ -745,6 +759,7 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
745
759
  [CurrencyUnit.PHP]: php,
746
760
  [CurrencyUnit.EUR]: eur,
747
761
  [CurrencyUnit.GBP]: gbp,
762
+ [CurrencyUnit.INR]: inr,
748
763
  [CurrencyUnit.MICROBITCOIN]: mibtc,
749
764
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
750
765
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -794,6 +809,10 @@ function mapCurrencyAmount(currencyAmountArg, unitsPerBtc = 1) {
794
809
  value: gbp,
795
810
  unit: CurrencyUnit.GBP
796
811
  }),
812
+ [CurrencyUnit.INR]: formatCurrencyStr({
813
+ value: inr,
814
+ unit: CurrencyUnit.INR
815
+ }),
797
816
  [CurrencyUnit.FUTURE_VALUE]: "-"
798
817
  }
799
818
  };
@@ -862,6 +881,8 @@ var abbrCurrencyUnit = (unit) => {
862
881
  return "EUR";
863
882
  case CurrencyUnit.GBP:
864
883
  return "GBP";
884
+ case CurrencyUnit.INR:
885
+ return "INR";
865
886
  }
866
887
  return "Unsupported CurrencyUnit";
867
888
  };
@@ -994,6 +1015,15 @@ function localeToCurrencySymbol(locale) {
994
1015
  const { symbol } = separateCurrencyStrParts(formatted);
995
1016
  return symbol;
996
1017
  }
1018
+ function formatInviteAmount(amount, currency) {
1019
+ if (!amount || !currency) {
1020
+ return "";
1021
+ }
1022
+ const displayAmount = (amount / Math.pow(10, currency.decimals)).toFixed(
1023
+ currency.decimals
1024
+ );
1025
+ return `${displayAmount} ${currency.code}`;
1026
+ }
997
1027
 
998
1028
  // src/utils/typeGuards.ts
999
1029
  function isUint8Array(value) {
@@ -2300,12 +2330,14 @@ function zipcodeToState(zipcode) {
2300
2330
  ensureArray,
2301
2331
  errorToJSON,
2302
2332
  formatCurrencyStr,
2333
+ formatInviteAmount,
2303
2334
  getCurrencyAmount,
2304
2335
  getCurrentLocale,
2305
2336
  getErrorMsg,
2306
2337
  getLocalStorageBoolean,
2307
2338
  getLocalStorageConfigItem,
2308
2339
  hexToBytes,
2340
+ isBare,
2309
2341
  isBrowser,
2310
2342
  isCurrencyAmountInputObj,
2311
2343
  isCurrencyAmountObj,
@@ -1 +1 @@
1
- export { A as AppendUnitsOptions, ab as ById, am as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, ao as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode, aq as zipcodeToState, ap as zipcodeToStateCode } from '../index-BCTAeaWD.cjs';
1
+ export { A as AppendUnitsOptions, ad as ById, ao as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, X as CurrencyCodes, W as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ah as DeepPartial, D as DeprecatedCurrencyAmountObj, ac as ExpandRecursively, ag as ExtractByTypename, ai as JSONLiteral, ak as JSONObject, aj as JSONType, ab as Maybe, al as NN, ae as OmitTypename, an as PartialBy, ap as RequiredKeys, S as SDKCurrencyAmountType, aq as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, Q as bytesToHex, a1 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, V as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a0 as deleteLocalStorageItem, e as ensureArray, P as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, T as getCurrentLocale, N as getErrorMsg, _ as getLocalStorageBoolean, Z as getLocalStorageConfigItem, R as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, L as isError, O as isErrorMsg, M as isErrorWithMessage, I as isNode, a4 as isNumber, a9 as isObject, aa as isRecord, v as isSDKCurrencyAmount, J as isTest, af as isType, a8 as isUint8Array, q as isUmaCurrencyAmount, a2 as linearInterpolate, Y as localeToCurrencyCode, F as localeToCurrencySymbol, a7 as lsidToUUID, x as mapCurrencyAmount, am as notNullUndefined, a5 as pollUntil, a3 as round, E as separateCurrencyStrParts, $ as setLocalStorageBoolean, a6 as sleep, u as urlsafe_b64decode, as as zipcodeToState, ar as zipcodeToStateCode } from '../index-gUXiTlhb.cjs';
@@ -1 +1 @@
1
- export { A as AppendUnitsOptions, ab as ById, am as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, ao as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode, aq as zipcodeToState, ap as zipcodeToStateCode } from '../index-BCTAeaWD.js';
1
+ export { A as AppendUnitsOptions, ad as ById, ao as Complete, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, X as CurrencyCodes, W as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ah as DeepPartial, D as DeprecatedCurrencyAmountObj, ac as ExpandRecursively, ag as ExtractByTypename, ai as JSONLiteral, ak as JSONObject, aj as JSONType, ab as Maybe, al as NN, ae as OmitTypename, an as PartialBy, ap as RequiredKeys, S as SDKCurrencyAmountType, aq as StateCode, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, Q as bytesToHex, a1 as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, V as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, a0 as deleteLocalStorageItem, e as ensureArray, P as errorToJSON, B as formatCurrencyStr, G as formatInviteAmount, w as getCurrencyAmount, T as getCurrentLocale, N as getErrorMsg, _ as getLocalStorageBoolean, Z as getLocalStorageConfigItem, R as hexToBytes, K as isBare, H as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, L as isError, O as isErrorMsg, M as isErrorWithMessage, I as isNode, a4 as isNumber, a9 as isObject, aa as isRecord, v as isSDKCurrencyAmount, J as isTest, af as isType, a8 as isUint8Array, q as isUmaCurrencyAmount, a2 as linearInterpolate, Y as localeToCurrencyCode, F as localeToCurrencySymbol, a7 as lsidToUUID, x as mapCurrencyAmount, am as notNullUndefined, a5 as pollUntil, a3 as round, E as separateCurrencyStrParts, $ as setLocalStorageBoolean, a6 as sleep, u as urlsafe_b64decode, as as zipcodeToState, ar as zipcodeToStateCode } from '../index-gUXiTlhb.js';
@@ -14,12 +14,14 @@ import {
14
14
  ensureArray,
15
15
  errorToJSON,
16
16
  formatCurrencyStr,
17
+ formatInviteAmount,
17
18
  getCurrencyAmount,
18
19
  getCurrentLocale,
19
20
  getErrorMsg,
20
21
  getLocalStorageBoolean,
21
22
  getLocalStorageConfigItem,
22
23
  hexToBytes,
24
+ isBare,
23
25
  isBrowser,
24
26
  isCurrencyAmountInputObj,
25
27
  isCurrencyAmountObj,
@@ -52,7 +54,7 @@ import {
52
54
  urlsafe_b64decode,
53
55
  zipcodeToState,
54
56
  zipcodeToStateCode
55
- } from "../chunk-CP4LQTTD.js";
57
+ } from "../chunk-36QHRQJC.js";
56
58
  export {
57
59
  CurrencyUnit,
58
60
  abbrCurrencyUnit,
@@ -69,12 +71,14 @@ export {
69
71
  ensureArray,
70
72
  errorToJSON,
71
73
  formatCurrencyStr,
74
+ formatInviteAmount,
72
75
  getCurrencyAmount,
73
76
  getCurrentLocale,
74
77
  getErrorMsg,
75
78
  getLocalStorageBoolean,
76
79
  getLocalStorageConfigItem,
77
80
  hexToBytes,
81
+ isBare,
78
82
  isBrowser,
79
83
  isCurrencyAmountInputObj,
80
84
  isCurrencyAmountObj,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -4,7 +4,6 @@ import autoBind from "auto-bind";
4
4
  import dayjs from "dayjs";
5
5
  import utc from "dayjs/plugin/utc.js";
6
6
  import type { Client as WsClient } from "graphql-ws";
7
- import { createClient } from "graphql-ws";
8
7
  import { Observable } from "zen-observable-ts";
9
8
 
10
9
  import type Query from "./Query.js";
@@ -18,7 +17,7 @@ import type { SigningKey } from "../crypto/SigningKey.js";
18
17
  import LightsparkException from "../LightsparkException.js";
19
18
  import { logger } from "../Logger.js";
20
19
  import { b64encode } from "../utils/base64.js";
21
- import { isNode } from "../utils/environment.js";
20
+ import { isBare, isNode } from "../utils/environment.js";
22
21
 
23
22
  const DEFAULT_BASE_URL = "api.lightspark.com";
24
23
  dayjs.extend(utc);
@@ -32,8 +31,8 @@ type BodyData = {
32
31
  };
33
32
 
34
33
  class Requester {
35
- private wsClient: Promise<WsClient>;
36
- private resolveWsClient: ((value: WsClient) => void) | null = null;
34
+ private wsClient: Promise<WsClient | null>;
35
+ private resolveWsClient: ((value: WsClient | null) => void) | null = null;
37
36
  constructor(
38
37
  private readonly nodeKeyCache: NodeKeyCache,
39
38
  private readonly schemaEndpoint: string,
@@ -44,7 +43,7 @@ class Requester {
44
43
  private readonly signingKey?: SigningKey,
45
44
  private readonly fetchImpl: typeof fetch = fetch,
46
45
  ) {
47
- this.wsClient = new Promise<WsClient>((resolve) => {
46
+ this.wsClient = new Promise<WsClient | null>((resolve) => {
48
47
  this.resolveWsClient = resolve;
49
48
  });
50
49
  void this.initWsClient(baseUrl, authProvider);
@@ -57,6 +56,11 @@ class Requester {
57
56
  return this.wsClient;
58
57
  }
59
58
 
59
+ if (isBare) {
60
+ /* graphql-ws library is currently not supported in Bare environment, see LIG-7942 */
61
+ return null;
62
+ }
63
+
60
64
  let websocketImpl;
61
65
  if (isNode && typeof WebSocket === "undefined") {
62
66
  const wsModule = await import("ws");
@@ -67,6 +71,9 @@ class Requester {
67
71
  websocketProtocol = "ws";
68
72
  }
69
73
 
74
+ const graphqlWsModule = await import("graphql-ws");
75
+ const { createClient } = graphqlWsModule;
76
+
70
77
  const wsClient = createClient({
71
78
  url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${
72
79
  this.schemaEndpoint
@@ -99,6 +106,7 @@ class Requester {
99
106
  variables: { [key: string]: unknown } = {},
100
107
  ) {
101
108
  logger.trace(`Requester.subscribe variables`, variables);
109
+
102
110
  const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
103
111
  const operationMatch = queryPayload.match(operationNameRegex);
104
112
  if (!operationMatch || operationMatch.length < 3) {
@@ -134,6 +142,15 @@ class Requester {
134
142
  void (async () => {
135
143
  try {
136
144
  const wsClient = await this.wsClient;
145
+
146
+ if (!wsClient) {
147
+ /* graphql-ws library is currently not supported in Bare environment, see LIG-7942 */
148
+ throw new LightsparkException(
149
+ "WebSocketNotInitialized",
150
+ "WebSocket client is not initialized or is not available in the current environment.",
151
+ );
152
+ }
153
+
137
154
  if (!canceled) {
138
155
  cleanup = wsClient.subscribe(bodyData, {
139
156
  next: (data) => observer.next(data as { data: T }),
@@ -23,6 +23,7 @@ export const CurrencyUnit = {
23
23
  PHP: "PHP",
24
24
  EUR: "EUR",
25
25
  GBP: "GBP",
26
+ INR: "INR",
26
27
 
27
28
  Bitcoin: "BITCOIN",
28
29
  Microbitcoin: "MICROBITCOIN",
@@ -34,6 +35,7 @@ export const CurrencyUnit = {
34
35
  Mxn: "MXN",
35
36
  Php: "PHP",
36
37
  Gbp: "GBP",
38
+ Inr: "INR",
37
39
  } as const;
38
40
 
39
41
  export type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
@@ -64,6 +66,7 @@ const standardUnitConversionObj = {
64
66
  [CurrencyUnit.PHP]: (v: number) => v,
65
67
  [CurrencyUnit.EUR]: (v: number) => v,
66
68
  [CurrencyUnit.GBP]: (v: number) => v,
69
+ [CurrencyUnit.INR]: (v: number) => v,
67
70
  };
68
71
 
69
72
  /* Round without decimals since we're returning cents: */
@@ -93,6 +96,7 @@ const CONVERSION_MAP = {
93
96
  [CurrencyUnit.PHP]: toBitcoinConversion,
94
97
  [CurrencyUnit.EUR]: toBitcoinConversion,
95
98
  [CurrencyUnit.GBP]: toBitcoinConversion,
99
+ [CurrencyUnit.INR]: toBitcoinConversion,
96
100
  },
97
101
  [CurrencyUnit.MICROBITCOIN]: {
98
102
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000,
@@ -106,6 +110,7 @@ const CONVERSION_MAP = {
106
110
  [CurrencyUnit.PHP]: toMicrobitcoinConversion,
107
111
  [CurrencyUnit.EUR]: toMicrobitcoinConversion,
108
112
  [CurrencyUnit.GBP]: toMicrobitcoinConversion,
113
+ [CurrencyUnit.INR]: toMicrobitcoinConversion,
109
114
  },
110
115
  [CurrencyUnit.MILLIBITCOIN]: {
111
116
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000,
@@ -119,6 +124,7 @@ const CONVERSION_MAP = {
119
124
  [CurrencyUnit.PHP]: toMillibitcoinConversion,
120
125
  [CurrencyUnit.EUR]: toMillibitcoinConversion,
121
126
  [CurrencyUnit.GBP]: toMillibitcoinConversion,
127
+ [CurrencyUnit.INR]: toMillibitcoinConversion,
122
128
  },
123
129
  [CurrencyUnit.MILLISATOSHI]: {
124
130
  [CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000_000,
@@ -132,6 +138,7 @@ const CONVERSION_MAP = {
132
138
  [CurrencyUnit.PHP]: toMillisatoshiConversion,
133
139
  [CurrencyUnit.EUR]: toMillisatoshiConversion,
134
140
  [CurrencyUnit.GBP]: toMillisatoshiConversion,
141
+ [CurrencyUnit.INR]: toMillisatoshiConversion,
135
142
  },
136
143
  [CurrencyUnit.NANOBITCOIN]: {
137
144
  [CurrencyUnit.BITCOIN]: (v: number) => v / 1_000_000_000,
@@ -145,6 +152,7 @@ const CONVERSION_MAP = {
145
152
  [CurrencyUnit.PHP]: toNanobitcoinConversion,
146
153
  [CurrencyUnit.EUR]: toNanobitcoinConversion,
147
154
  [CurrencyUnit.GBP]: toNanobitcoinConversion,
155
+ [CurrencyUnit.INR]: toNanobitcoinConversion,
148
156
  },
149
157
  [CurrencyUnit.SATOSHI]: {
150
158
  [CurrencyUnit.BITCOIN]: (v: number) => v / 100_000_000,
@@ -158,12 +166,14 @@ const CONVERSION_MAP = {
158
166
  [CurrencyUnit.PHP]: toSatoshiConversion,
159
167
  [CurrencyUnit.EUR]: toSatoshiConversion,
160
168
  [CurrencyUnit.GBP]: toSatoshiConversion,
169
+ [CurrencyUnit.INR]: toSatoshiConversion,
161
170
  },
162
171
  [CurrencyUnit.USD]: standardUnitConversionObj,
163
172
  [CurrencyUnit.MXN]: standardUnitConversionObj,
164
173
  [CurrencyUnit.PHP]: standardUnitConversionObj,
165
174
  [CurrencyUnit.EUR]: standardUnitConversionObj,
166
175
  [CurrencyUnit.GBP]: standardUnitConversionObj,
176
+ [CurrencyUnit.INR]: standardUnitConversionObj,
167
177
  };
168
178
 
169
179
  export function convertCurrencyAmountValue(
@@ -230,6 +240,7 @@ export type CurrencyMap = {
230
240
  [CurrencyUnit.PHP]: number;
231
241
  [CurrencyUnit.EUR]: number;
232
242
  [CurrencyUnit.GBP]: number;
243
+ [CurrencyUnit.INR]: number;
233
244
  [CurrencyUnit.FUTURE_VALUE]: number;
234
245
  formatted: {
235
246
  sats: string;
@@ -246,6 +257,7 @@ export type CurrencyMap = {
246
257
  [CurrencyUnit.PHP]: string;
247
258
  [CurrencyUnit.EUR]: string;
248
259
  [CurrencyUnit.GBP]: string;
260
+ [CurrencyUnit.INR]: string;
249
261
  [CurrencyUnit.FUTURE_VALUE]: string;
250
262
  };
251
263
  isZero: boolean;
@@ -443,6 +455,7 @@ function convertCurrencyAmountValues(
443
455
  php: CurrencyUnit.PHP,
444
456
  eur: CurrencyUnit.EUR,
445
457
  gbp: CurrencyUnit.GBP,
458
+ inr: CurrencyUnit.INR,
446
459
  mibtc: CurrencyUnit.MICROBITCOIN,
447
460
  mlbtc: CurrencyUnit.MILLIBITCOIN,
448
461
  nbtc: CurrencyUnit.NANOBITCOIN,
@@ -492,7 +505,7 @@ export function mapCurrencyAmount(
492
505
  * preferred_currency_unit on CurrencyAmount types: */
493
506
  const conversionOverride = getPreferredConversionOverride(currencyAmountArg);
494
507
 
495
- const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp } =
508
+ const { sats, msats, btc, usd, mxn, php, mibtc, mlbtc, nbtc, eur, gbp, inr } =
496
509
  convertCurrencyAmountValues(unit, value, unitsPerBtc, conversionOverride);
497
510
 
498
511
  const mapWithCurrencyUnits = {
@@ -504,6 +517,7 @@ export function mapCurrencyAmount(
504
517
  [CurrencyUnit.PHP]: php,
505
518
  [CurrencyUnit.EUR]: eur,
506
519
  [CurrencyUnit.GBP]: gbp,
520
+ [CurrencyUnit.INR]: inr,
507
521
  [CurrencyUnit.MICROBITCOIN]: mibtc,
508
522
  [CurrencyUnit.MILLIBITCOIN]: mlbtc,
509
523
  [CurrencyUnit.NANOBITCOIN]: nbtc,
@@ -553,6 +567,10 @@ export function mapCurrencyAmount(
553
567
  value: gbp,
554
568
  unit: CurrencyUnit.GBP,
555
569
  }),
570
+ [CurrencyUnit.INR]: formatCurrencyStr({
571
+ value: inr,
572
+ unit: CurrencyUnit.INR,
573
+ }),
556
574
  [CurrencyUnit.FUTURE_VALUE]: "-",
557
575
  },
558
576
  };
@@ -631,6 +649,8 @@ export const abbrCurrencyUnit = (unit: CurrencyUnitType) => {
631
649
  return "EUR";
632
650
  case CurrencyUnit.GBP:
633
651
  return "GBP";
652
+ case CurrencyUnit.INR:
653
+ return "INR";
634
654
  }
635
655
  return "Unsupported CurrencyUnit";
636
656
  };
@@ -825,3 +845,24 @@ export function localeToCurrencySymbol(locale: string) {
825
845
  const { symbol } = separateCurrencyStrParts(formatted);
826
846
  return symbol;
827
847
  }
848
+
849
+ /**
850
+ * Formats an amount from the smallest currency unit to a display string
851
+ * @param amount - The amount in the smallest currency unit (No decimals)
852
+ * @param currency - The currency object with code and decimals
853
+ * @returns Formatted string like "12.50 USD" or empty string if invalid
854
+ */
855
+ export function formatInviteAmount(
856
+ amount: number | null | undefined,
857
+ currency: UmaCurrency | null | undefined,
858
+ ): string {
859
+ if (!amount || !currency) {
860
+ return "";
861
+ }
862
+
863
+ const displayAmount = (amount / Math.pow(10, currency.decimals)).toFixed(
864
+ currency.decimals,
865
+ );
866
+
867
+ return `${displayAmount} ${currency.code}`;
868
+ }
@@ -1,3 +1,7 @@
1
+ declare global {
2
+ const Bare: unknown;
3
+ }
4
+
1
5
  export const isBrowser =
2
6
  typeof window !== "undefined" && typeof window.document !== "undefined";
3
7
 
@@ -7,3 +11,6 @@ export const isNode =
7
11
  process.versions.node != null;
8
12
 
9
13
  export const isTest = isNode && process.env.NODE_ENV === "test";
14
+
15
+ /* https://github.com/holepunchto/which-runtime/blob/main/index.js */
16
+ export const isBare = typeof Bare !== "undefined";