@lightsparkdev/core 1.2.1 → 1.2.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/dist/index.js CHANGED
@@ -12,6 +12,7 @@ import {
12
12
  createSha256Hash,
13
13
  defaultCurrencyCode,
14
14
  deleteLocalStorageItem,
15
+ ensureArray,
15
16
  errorToJSON,
16
17
  formatCurrencyStr,
17
18
  getCurrentLocale,
@@ -21,7 +22,9 @@ import {
21
22
  hexToBytes,
22
23
  isBrowser,
23
24
  isCurrencyAmountObj,
25
+ isCurrencyAmountPreferenceObj,
24
26
  isCurrencyMap,
27
+ isDeprecatedCurrencyAmountObj,
25
28
  isError,
26
29
  isErrorMsg,
27
30
  isErrorWithMessage,
@@ -44,70 +47,7 @@ import {
44
47
  setLocalStorageBoolean,
45
48
  sleep,
46
49
  urlsafe_b64decode
47
- } from "./chunk-YRWJVCZI.js";
48
-
49
- // src/Logger.ts
50
- var LoggingLevel = /* @__PURE__ */ ((LoggingLevel2) => {
51
- LoggingLevel2[LoggingLevel2["Trace"] = 0] = "Trace";
52
- LoggingLevel2[LoggingLevel2["Info"] = 1] = "Info";
53
- return LoggingLevel2;
54
- })(LoggingLevel || {});
55
- var Logger = class {
56
- context;
57
- loggingEnabled = false;
58
- loggingLevel = 1 /* Info */;
59
- constructor(loggerContext, getLoggingEnabled) {
60
- this.context = loggerContext;
61
- void this.updateLoggingEnabled(getLoggingEnabled);
62
- }
63
- setLevel(level) {
64
- this.loggingLevel = level;
65
- }
66
- async updateLoggingEnabled(getLoggingEnabled) {
67
- if (getLoggingEnabled) {
68
- this.loggingEnabled = await getLoggingEnabled();
69
- } else if (isTest) {
70
- this.loggingEnabled = true;
71
- } else if (isBrowser) {
72
- try {
73
- this.loggingEnabled = getLocalStorageConfigItem(
74
- ConfigKeys.LoggingEnabled
75
- );
76
- } catch (e) {
77
- }
78
- }
79
- if (this.loggingEnabled) {
80
- console.log(`[${this.context}] Logging enabled`);
81
- }
82
- }
83
- trace(message, ...rest) {
84
- if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
85
- console.log(`[${this.context}] ${message}`, ...rest);
86
- }
87
- }
88
- info(message, ...rest) {
89
- if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
90
- console.log(`[${this.context}] ${message}`, ...rest);
91
- }
92
- }
93
- };
94
- var logger = new Logger("@lightsparkdev/core");
95
-
96
- // src/ServerEnvironment.ts
97
- var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
98
- ServerEnvironment2["PRODUCTION"] = "production";
99
- ServerEnvironment2["DEV"] = "dev";
100
- return ServerEnvironment2;
101
- })(ServerEnvironment || {});
102
- var apiDomainForEnvironment = (environment) => {
103
- switch (environment) {
104
- case "dev" /* DEV */:
105
- return "api.dev.dev.sparkinfra.net";
106
- case "production" /* PRODUCTION */:
107
- return "api.lightspark.com";
108
- }
109
- };
110
- var ServerEnvironment_default = ServerEnvironment;
50
+ } from "./chunk-ZU7NVHMW.js";
111
51
 
112
52
  // src/auth/LightsparkAuthException.ts
113
53
  var LightsparkAuthException = class extends LightsparkException_default {
@@ -136,12 +76,6 @@ var ConfigKeys = {
136
76
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
137
77
  };
138
78
 
139
- // src/crypto/KeyOrAlias.ts
140
- var KeyOrAlias = {
141
- key: (key) => ({ key }),
142
- alias: (alias) => ({ alias })
143
- };
144
-
145
79
  // src/crypto/LightsparkSigningException.ts
146
80
  var LightsparkSigningException = class extends LightsparkException_default {
147
81
  constructor(message, extraInfo) {
@@ -150,39 +84,6 @@ var LightsparkSigningException = class extends LightsparkException_default {
150
84
  };
151
85
  var LightsparkSigningException_default = LightsparkSigningException;
152
86
 
153
- // ../../node_modules/auto-bind/index.js
154
- var getAllProperties = (object) => {
155
- const properties = /* @__PURE__ */ new Set();
156
- do {
157
- for (const key of Reflect.ownKeys(object)) {
158
- properties.add([object, key]);
159
- }
160
- } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
161
- return properties;
162
- };
163
- function autoBind(self, { include, exclude } = {}) {
164
- const filter = (key) => {
165
- const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
166
- if (include) {
167
- return include.some(match);
168
- }
169
- if (exclude) {
170
- return !exclude.some(match);
171
- }
172
- return true;
173
- };
174
- for (const [object, key] of getAllProperties(self.constructor.prototype)) {
175
- if (key === "constructor" || !filter(key)) {
176
- continue;
177
- }
178
- const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
179
- if (descriptor && typeof descriptor.value === "function") {
180
- self[key] = self[key].bind(self);
181
- }
182
- }
183
- return self;
184
- }
185
-
186
87
  // src/crypto/crypto.ts
187
88
  var getCrypto = () => {
188
89
  let cryptoImplPromise;
@@ -203,7 +104,8 @@ var getCrypto = () => {
203
104
  return array;
204
105
  }
205
106
  const buffer = Buffer.from(array.buffer);
206
- nodeCrypto.randomFillSync(buffer);
107
+ const view = new Uint8Array(buffer);
108
+ nodeCrypto.randomFillSync(view);
207
109
  return array;
208
110
  }
209
111
  });
@@ -392,6 +294,45 @@ var DefaultCrypto = {
392
294
  importPrivateSigningKey
393
295
  };
394
296
 
297
+ // src/crypto/KeyOrAlias.ts
298
+ var KeyOrAlias = {
299
+ key: (key) => ({ key }),
300
+ alias: (alias) => ({ alias })
301
+ };
302
+
303
+ // ../../node_modules/auto-bind/index.js
304
+ var getAllProperties = (object) => {
305
+ const properties = /* @__PURE__ */ new Set();
306
+ do {
307
+ for (const key of Reflect.ownKeys(object)) {
308
+ properties.add([object, key]);
309
+ }
310
+ } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype);
311
+ return properties;
312
+ };
313
+ function autoBind(self, { include, exclude } = {}) {
314
+ const filter = (key) => {
315
+ const match = (pattern) => typeof pattern === "string" ? key === pattern : pattern.test(key);
316
+ if (include) {
317
+ return include.some(match);
318
+ }
319
+ if (exclude) {
320
+ return !exclude.some(match);
321
+ }
322
+ return true;
323
+ };
324
+ for (const [object, key] of getAllProperties(self.constructor.prototype)) {
325
+ if (key === "constructor" || !filter(key)) {
326
+ continue;
327
+ }
328
+ const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
329
+ if (descriptor && typeof descriptor.value === "function") {
330
+ self[key] = self[key].bind(self);
331
+ }
332
+ }
333
+ return self;
334
+ }
335
+
395
336
  // src/crypto/SigningKey.ts
396
337
  import secp256k1 from "secp256k1";
397
338
  function isAlias(key) {
@@ -488,6 +429,57 @@ var NodeKeyCache = class {
488
429
  };
489
430
  var NodeKeyCache_default = NodeKeyCache;
490
431
 
432
+ // src/Logger.ts
433
+ var LoggingLevel = /* @__PURE__ */ ((LoggingLevel2) => {
434
+ LoggingLevel2[LoggingLevel2["Trace"] = 0] = "Trace";
435
+ LoggingLevel2[LoggingLevel2["Info"] = 1] = "Info";
436
+ return LoggingLevel2;
437
+ })(LoggingLevel || {});
438
+ var Logger = class {
439
+ context;
440
+ loggingEnabled = false;
441
+ loggingLevel = 1 /* Info */;
442
+ constructor(loggerContext, getLoggingEnabled) {
443
+ this.context = loggerContext;
444
+ void this.updateLoggingEnabled(getLoggingEnabled);
445
+ }
446
+ setLevel(level) {
447
+ this.loggingLevel = level;
448
+ }
449
+ setEnabled(enabled, level = 1 /* Info */) {
450
+ this.loggingEnabled = enabled;
451
+ this.loggingLevel = level;
452
+ }
453
+ async updateLoggingEnabled(getLoggingEnabled) {
454
+ if (getLoggingEnabled) {
455
+ this.loggingEnabled = await getLoggingEnabled();
456
+ } else if (isTest) {
457
+ this.loggingEnabled = true;
458
+ } else if (isBrowser) {
459
+ try {
460
+ this.loggingEnabled = getLocalStorageConfigItem(
461
+ ConfigKeys.LoggingEnabled
462
+ );
463
+ } catch (e) {
464
+ }
465
+ }
466
+ if (this.loggingEnabled) {
467
+ console.log(`[${this.context}] Logging enabled`);
468
+ }
469
+ }
470
+ trace(message, ...rest) {
471
+ if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
472
+ console.log(`[${this.context}] ${message}`, ...rest);
473
+ }
474
+ }
475
+ info(message, ...rest) {
476
+ if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
477
+ console.log(`[${this.context}] ${message}`, ...rest);
478
+ }
479
+ }
480
+ };
481
+ var logger = new Logger("@lightsparkdev/core");
482
+
491
483
  // src/requester/Requester.ts
492
484
  import dayjs from "dayjs";
493
485
  import utc from "dayjs/plugin/utc.js";
@@ -565,6 +557,12 @@ var Requester = class {
565
557
  });
566
558
  }
567
559
  async makeRawRequest(queryPayload, variables = {}, signingNodeId = void 0, skipAuth = false) {
560
+ logger.trace(`Requester.makeRawRequest args`, {
561
+ queryPayload,
562
+ variables,
563
+ signingNodeId,
564
+ skipAuth
565
+ });
568
566
  const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
569
567
  const operationMatch = queryPayload.match(operationNameRegex);
570
568
  if (!operationMatch || operationMatch.length < 3) {
@@ -614,7 +612,8 @@ var Requester = class {
614
612
  logger.trace(`Requester.makeRawRequest`, {
615
613
  url,
616
614
  operationName: operation,
617
- variables
615
+ variables,
616
+ headers
618
617
  });
619
618
  const response = await fetch(url, {
620
619
  method: "POST",
@@ -699,6 +698,22 @@ async function compress(data) {
699
698
  return new Uint8Array(await blob.arrayBuffer());
700
699
  }
701
700
  var Requester_default = Requester;
701
+
702
+ // src/ServerEnvironment.ts
703
+ var ServerEnvironment = /* @__PURE__ */ ((ServerEnvironment2) => {
704
+ ServerEnvironment2["PRODUCTION"] = "production";
705
+ ServerEnvironment2["DEV"] = "dev";
706
+ return ServerEnvironment2;
707
+ })(ServerEnvironment || {});
708
+ var apiDomainForEnvironment = (environment) => {
709
+ switch (environment) {
710
+ case "dev" /* DEV */:
711
+ return "api.dev.dev.sparkinfra.net";
712
+ case "production" /* PRODUCTION */:
713
+ return "api.lightspark.com";
714
+ }
715
+ };
716
+ var ServerEnvironment_default = ServerEnvironment;
702
717
  export {
703
718
  ConfigKeys,
704
719
  CurrencyUnit,
@@ -729,6 +744,7 @@ export {
729
744
  createSha256Hash,
730
745
  defaultCurrencyCode,
731
746
  deleteLocalStorageItem,
747
+ ensureArray,
732
748
  errorToJSON,
733
749
  formatCurrencyStr,
734
750
  getCurrentLocale,
@@ -738,7 +754,9 @@ export {
738
754
  hexToBytes,
739
755
  isBrowser,
740
756
  isCurrencyAmountObj,
757
+ isCurrencyAmountPreferenceObj,
741
758
  isCurrencyMap,
759
+ isDeprecatedCurrencyAmountObj,
742
760
  isError,
743
761
  isErrorMsg,
744
762
  isErrorWithMessage,
@@ -752,6 +770,7 @@ export {
752
770
  linearInterpolate,
753
771
  localeToCurrencyCode,
754
772
  localeToCurrencySymbol,
773
+ logger,
755
774
  lsidToUUID,
756
775
  mapCurrencyAmount,
757
776
  notNullUndefined,
@@ -42,6 +42,7 @@ __export(utils_exports, {
42
42
  createSha256Hash: () => createSha256Hash,
43
43
  defaultCurrencyCode: () => defaultCurrencyCode,
44
44
  deleteLocalStorageItem: () => deleteLocalStorageItem,
45
+ ensureArray: () => ensureArray,
45
46
  errorToJSON: () => errorToJSON,
46
47
  formatCurrencyStr: () => formatCurrencyStr,
47
48
  getCurrentLocale: () => getCurrentLocale,
@@ -51,7 +52,9 @@ __export(utils_exports, {
51
52
  hexToBytes: () => hexToBytes,
52
53
  isBrowser: () => isBrowser,
53
54
  isCurrencyAmountObj: () => isCurrencyAmountObj,
55
+ isCurrencyAmountPreferenceObj: () => isCurrencyAmountPreferenceObj,
54
56
  isCurrencyMap: () => isCurrencyMap,
57
+ isDeprecatedCurrencyAmountObj: () => isDeprecatedCurrencyAmountObj,
55
58
  isError: () => isError,
56
59
  isErrorMsg: () => isErrorMsg,
57
60
  isErrorWithMessage: () => isErrorWithMessage,
@@ -77,6 +80,11 @@ __export(utils_exports, {
77
80
  });
78
81
  module.exports = __toCommonJS(utils_exports);
79
82
 
83
+ // src/utils/arrays.ts
84
+ function ensureArray(value) {
85
+ return Array.isArray(value) ? value : [value];
86
+ }
87
+
80
88
  // src/utils/base64.ts
81
89
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
82
90
  var Base64 = {
@@ -600,9 +608,15 @@ var convertCurrencyAmount = (from, toUnit) => {
600
608
  preferredCurrencyValueRounded: value
601
609
  };
602
610
  };
603
- function isCurrencyAmountObj(arg) {
611
+ function isDeprecatedCurrencyAmountObj(arg) {
604
612
  return typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg;
605
613
  }
614
+ function isCurrencyAmountObj(arg) {
615
+ return typeof arg === "object" && arg !== null && "original_value" in arg && "original_unit" in arg;
616
+ }
617
+ function isCurrencyAmountPreferenceObj(arg) {
618
+ return typeof arg === "object" && arg !== null && "preferred_currency_unit" in arg && "preferred_currency_value_rounded" in arg;
619
+ }
606
620
  function isSDKCurrencyAmount(arg) {
607
621
  return typeof arg === "object" && arg !== null && /* We can expect all SDK CurrencyAmount types to always have these exact properties: */
608
622
  "originalValue" in arg && "originalUnit" in arg && "preferredCurrencyUnit" in arg && "preferredCurrencyValueRounded" in arg && "preferredCurrencyValueApprox" in arg;
@@ -619,7 +633,13 @@ function getCurrencyAmount(currencyAmountArg) {
619
633
  if (isSDKCurrencyAmount(currencyAmountArg)) {
620
634
  value = currencyAmountArg.originalValue;
621
635
  unit = currencyAmountArg.originalUnit;
636
+ } else if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
637
+ value = asNumber(currencyAmountArg.preferred_currency_value_rounded);
638
+ unit = currencyAmountArg.preferred_currency_unit;
622
639
  } else if (isCurrencyAmountObj(currencyAmountArg)) {
640
+ value = asNumber(currencyAmountArg.original_value);
641
+ unit = currencyAmountArg.original_unit;
642
+ } else if (isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
623
643
  value = asNumber(currencyAmountArg.value);
624
644
  unit = currencyAmountArg.unit;
625
645
  }
@@ -816,7 +836,7 @@ function localeToCurrencySymbol(locale) {
816
836
  // src/utils/errors.ts
817
837
  var isError = (e) => {
818
838
  return Boolean(
819
- typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
839
+ typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string"
820
840
  );
821
841
  };
822
842
  var isErrorWithMessage = (e) => {
@@ -1029,6 +1049,7 @@ function notNullUndefined(value) {
1029
1049
  createSha256Hash,
1030
1050
  defaultCurrencyCode,
1031
1051
  deleteLocalStorageItem,
1052
+ ensureArray,
1032
1053
  errorToJSON,
1033
1054
  formatCurrencyStr,
1034
1055
  getCurrentLocale,
@@ -1038,7 +1059,9 @@ function notNullUndefined(value) {
1038
1059
  hexToBytes,
1039
1060
  isBrowser,
1040
1061
  isCurrencyAmountObj,
1062
+ isCurrencyAmountPreferenceObj,
1041
1063
  isCurrencyMap,
1064
+ isDeprecatedCurrencyAmountObj,
1042
1065
  isError,
1043
1066
  isErrorMsg,
1044
1067
  isErrorWithMessage,
@@ -1 +1 @@
1
- export { _ as ById, a8 as Complete, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a1 as DeepPartial, Z as ExpandRecursively, a2 as JSONLiteral, a4 as JSONObject, a3 as JSONType, Y as Maybe, a5 as NN, $ as OmitTypename, a7 as PartialBy, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, X as isObject, m as isSDKCurrencyAmount, w as isTest, a0 as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a6 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-b1e5d968.js';
1
+ export { a3 as ById, ad as Complete, 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, 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-DWJjMhfr.cjs';
@@ -1 +1 @@
1
- export { _ as ById, a8 as Complete, k as CurrencyAmountArg, j as CurrencyAmountObj, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, f as CurrencyUnitType, a1 as DeepPartial, Z as ExpandRecursively, a2 as JSONLiteral, a4 as JSONObject, a3 as JSONType, Y as Maybe, a5 as NN, $ as OmitTypename, a7 as PartialBy, S as SDKCurrencyAmountType, p as abbrCurrencyUnit, b as b64decode, a as b64encode, D as bytesToHex, O as clamp, h as convertCurrencyAmount, g as convertCurrencyAmountValue, K as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, I as deleteLocalStorageItem, B as errorToJSON, q as formatCurrencyStr, J as getCurrentLocale, z as getErrorMsg, G as getLocalStorageBoolean, F as getLocalStorageConfigItem, E as hexToBytes, t as isBrowser, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, X as isObject, m as isSDKCurrencyAmount, w as isTest, a0 as isType, W as isUint8Array, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, V as lsidToUUID, n as mapCurrencyAmount, a6 as notNullUndefined, T as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, U as sleep, u as urlsafe_b64decode } from '../index-b1e5d968.js';
1
+ export { a3 as ById, ad as Complete, 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, 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-DWJjMhfr.js';
@@ -11,6 +11,7 @@ import {
11
11
  createSha256Hash,
12
12
  defaultCurrencyCode,
13
13
  deleteLocalStorageItem,
14
+ ensureArray,
14
15
  errorToJSON,
15
16
  formatCurrencyStr,
16
17
  getCurrentLocale,
@@ -20,7 +21,9 @@ import {
20
21
  hexToBytes,
21
22
  isBrowser,
22
23
  isCurrencyAmountObj,
24
+ isCurrencyAmountPreferenceObj,
23
25
  isCurrencyMap,
26
+ isDeprecatedCurrencyAmountObj,
24
27
  isError,
25
28
  isErrorMsg,
26
29
  isErrorWithMessage,
@@ -43,7 +46,7 @@ import {
43
46
  setLocalStorageBoolean,
44
47
  sleep,
45
48
  urlsafe_b64decode
46
- } from "../chunk-YRWJVCZI.js";
49
+ } from "../chunk-ZU7NVHMW.js";
47
50
  export {
48
51
  CurrencyUnit,
49
52
  abbrCurrencyUnit,
@@ -57,6 +60,7 @@ export {
57
60
  createSha256Hash,
58
61
  defaultCurrencyCode,
59
62
  deleteLocalStorageItem,
63
+ ensureArray,
60
64
  errorToJSON,
61
65
  formatCurrencyStr,
62
66
  getCurrentLocale,
@@ -66,7 +70,9 @@ export {
66
70
  hexToBytes,
67
71
  isBrowser,
68
72
  isCurrencyAmountObj,
73
+ isCurrencyAmountPreferenceObj,
69
74
  isCurrencyMap,
75
+ isDeprecatedCurrencyAmountObj,
70
76
  isError,
71
77
  isErrorMsg,
72
78
  isErrorWithMessage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -44,8 +44,7 @@
44
44
  "require": {
45
45
  "types": "./dist/utils/index.d.ts",
46
46
  "default": "./dist/utils/index.cjs"
47
- },
48
- "default": "./dist/utils/index.cjs"
47
+ }
49
48
  }
50
49
  },
51
50
  "browser": {
@@ -59,7 +58,7 @@
59
58
  "scripts": {
60
59
  "build": "yarn tsc && tsup",
61
60
  "build:watch": "yarn build --watch --clean=false",
62
- "clean": "rm -rf .turbo && rm -rf dist",
61
+ "clean": "rm -rf dist",
63
62
  "dev": "yarn build -- --watch",
64
63
  "format:fix": "prettier src --write",
65
64
  "format": "prettier src --check",
@@ -100,8 +99,8 @@
100
99
  "prettier-plugin-organize-imports": "^3.2.4",
101
100
  "ts-jest": "^29.1.1",
102
101
  "tsc-absolute": "^1.0.1",
103
- "tsup": "^7.2.0",
104
- "typescript": "^5.0.0"
102
+ "tsup": "^8.2.4",
103
+ "typescript": "^5.6.2"
105
104
  },
106
105
  "engines": {
107
106
  "node": ">=18"
package/src/Logger.ts CHANGED
@@ -22,6 +22,11 @@ export class Logger {
22
22
  this.loggingLevel = level;
23
23
  }
24
24
 
25
+ public setEnabled(enabled: boolean, level: LoggingLevel = LoggingLevel.Info) {
26
+ this.loggingEnabled = enabled;
27
+ this.loggingLevel = level;
28
+ }
29
+
25
30
  async updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled) {
26
31
  if (getLoggingEnabled) {
27
32
  this.loggingEnabled = await getLoggingEnabled();
@@ -54,7 +54,8 @@ const getCrypto = () => {
54
54
  }
55
55
 
56
56
  const buffer = Buffer.from(array.buffer);
57
- nodeCrypto.randomFillSync(buffer);
57
+ const view = new Uint8Array(buffer);
58
+ nodeCrypto.randomFillSync(view);
58
59
  return array;
59
60
  },
60
61
  }) as typeof crypto;
@@ -1,8 +1,8 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
+ export * from "./crypto.js";
3
4
  export * from "./KeyOrAlias.js";
4
5
  export { default as LightsparkSigningException } from "./LightsparkSigningException.js";
5
6
  export { default as NodeKeyCache } from "./NodeKeyCache.js";
6
7
  export * from "./SigningKey.js";
7
- export * from "./crypto.js";
8
8
  export * from "./types.js";
package/src/index.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  // Copyright ©, 2023-present, Lightspark Group, Inc. - All Rights Reserved
2
2
 
3
+ export * from "./auth/index.js";
4
+ export * from "./constants/index.js";
5
+ export * from "./crypto/index.js";
3
6
  export { default as LightsparkException } from "./LightsparkException.js";
4
- export { Logger, LoggingLevel } from "./Logger.js";
7
+ export { Logger, LoggingLevel, logger } from "./Logger.js";
8
+ export * from "./requester/index.js";
5
9
  export {
6
10
  default as ServerEnvironment,
7
11
  apiDomainForEnvironment,
8
12
  } from "./ServerEnvironment.js";
9
- export * from "./auth/index.js";
10
- export * from "./constants/index.js";
11
- export * from "./crypto/index.js";
12
- export * from "./requester/index.js";
13
13
  export * from "./utils/index.js";
@@ -118,6 +118,13 @@ class Requester {
118
118
  skipAuth: boolean = false,
119
119
  /* eslint-disable-next-line @typescript-eslint/no-explicit-any -- LIG-3400 */
120
120
  ): Promise<any> {
121
+ logger.trace(`Requester.makeRawRequest args`, {
122
+ queryPayload,
123
+ variables,
124
+ signingNodeId,
125
+ skipAuth,
126
+ });
127
+
121
128
  const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
122
129
  const operationMatch = queryPayload.match(operationNameRegex);
123
130
  if (!operationMatch || operationMatch.length < 3) {
@@ -179,10 +186,11 @@ class Requester {
179
186
  url,
180
187
  operationName: operation,
181
188
  variables,
189
+ headers,
182
190
  });
183
191
  const response = await fetch(url, {
184
192
  method: "POST",
185
- headers: headers,
193
+ headers,
186
194
  body: bodyData,
187
195
  });
188
196
  if (!response.ok) {
@@ -0,0 +1,3 @@
1
+ export function ensureArray<T>(value: T | T[]): T[] {
2
+ return Array.isArray(value) ? value : [value];
3
+ }
@@ -199,7 +199,7 @@ export type CurrencyMap = {
199
199
  type: "CurrencyMap";
200
200
  };
201
201
 
202
- export type CurrencyAmountObj = {
202
+ export type DeprecatedCurrencyAmountObj = {
203
203
  /* Technically the generated graphql schema has value as `any` but it's always a number.
204
204
  * We are intentionally widening the type here to allow for more forgiving input: */
205
205
  value?: number | string | null;
@@ -208,18 +208,60 @@ export type CurrencyAmountObj = {
208
208
  __typename?: "CurrencyAmount" | undefined;
209
209
  };
210
210
 
211
+ export type CurrencyAmountObj = {
212
+ /* Technically the generated graphql schema has value as `any` but it's always a number.
213
+ * We are intentionally widening the type here to allow for more forgiving input: */
214
+ original_value?: number | string | null;
215
+ /* assume satoshi if not provided */
216
+ original_unit?: CurrencyUnitType;
217
+ __typename?: "CurrencyAmount" | undefined;
218
+ };
219
+
220
+ export type CurrencyAmountPreferenceObj = {
221
+ /* Technically the generated graphql schema has value as `any` but it's always a number.
222
+ * We are intentionally widening the type here to allow for more forgiving input: */
223
+ preferred_currency_unit?: CurrencyUnitType;
224
+ /* assume satoshi if not provided */
225
+ preferred_currency_value_rounded?: number | string | null;
226
+ __typename?: "CurrencyAmount" | undefined;
227
+ };
228
+
211
229
  export type CurrencyAmountArg =
230
+ | DeprecatedCurrencyAmountObj
212
231
  | CurrencyAmountObj
232
+ | CurrencyAmountPreferenceObj
213
233
  | SDKCurrencyAmountType
214
234
  | undefined
215
235
  | null;
216
236
 
217
- export function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj {
237
+ export function isDeprecatedCurrencyAmountObj(
238
+ arg: unknown,
239
+ ): arg is DeprecatedCurrencyAmountObj {
218
240
  return (
219
241
  typeof arg === "object" && arg !== null && "value" in arg && "unit" in arg
220
242
  );
221
243
  }
222
244
 
245
+ export function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj {
246
+ return (
247
+ typeof arg === "object" &&
248
+ arg !== null &&
249
+ "original_value" in arg &&
250
+ "original_unit" in arg
251
+ );
252
+ }
253
+
254
+ export function isCurrencyAmountPreferenceObj(
255
+ arg: unknown,
256
+ ): arg is CurrencyAmountPreferenceObj {
257
+ return (
258
+ typeof arg === "object" &&
259
+ arg !== null &&
260
+ "preferred_currency_unit" in arg &&
261
+ "preferred_currency_value_rounded" in arg
262
+ );
263
+ }
264
+
223
265
  export function isSDKCurrencyAmount(
224
266
  arg: unknown,
225
267
  ): arg is SDKCurrencyAmountType {
@@ -248,7 +290,13 @@ function getCurrencyAmount(currencyAmountArg: CurrencyAmountArg) {
248
290
  if (isSDKCurrencyAmount(currencyAmountArg)) {
249
291
  value = currencyAmountArg.originalValue;
250
292
  unit = currencyAmountArg.originalUnit;
293
+ } else if (isCurrencyAmountPreferenceObj(currencyAmountArg)) {
294
+ value = asNumber(currencyAmountArg.preferred_currency_value_rounded);
295
+ unit = currencyAmountArg.preferred_currency_unit;
251
296
  } else if (isCurrencyAmountObj(currencyAmountArg)) {
297
+ value = asNumber(currencyAmountArg.original_value);
298
+ unit = currencyAmountArg.original_unit;
299
+ } else if (isDeprecatedCurrencyAmountObj(currencyAmountArg)) {
252
300
  value = asNumber(currencyAmountArg.value);
253
301
  unit = currencyAmountArg.unit;
254
302
  }