@lightsparkdev/core 1.0.12 → 1.0.14

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
@@ -11,10 +11,13 @@ import {
11
11
  countryCodesToCurrencyCodes,
12
12
  createSha256Hash,
13
13
  defaultCurrencyCode,
14
+ deleteLocalStorageItem,
14
15
  errorToJSON,
15
16
  formatCurrencyStr,
16
17
  getCurrentLocale,
17
18
  getErrorMsg,
19
+ getLocalStorageBoolean,
20
+ getLocalStorageConfigItem,
18
21
  hexToBytes,
19
22
  isBrowser,
20
23
  isCurrencyAmount,
@@ -34,18 +37,23 @@ import {
34
37
  pollUntil,
35
38
  round,
36
39
  separateCurrencyStrParts,
40
+ setLocalStorageBoolean,
37
41
  sleep,
38
42
  urlsafe_b64decode
39
- } from "./chunk-BYCLLNFL.js";
43
+ } from "./chunk-ZLX5HJ4C.js";
40
44
 
41
45
  // src/Logger.ts
42
46
  var Logger = class {
43
47
  context;
44
48
  loggingEnabled = false;
49
+ loggingLevel = 1 /* Info */;
45
50
  constructor(loggerContext, getLoggingEnabled) {
46
51
  this.context = loggerContext;
47
52
  void this.updateLoggingEnabled(getLoggingEnabled);
48
53
  }
54
+ setLevel(level) {
55
+ this.loggingLevel = level;
56
+ }
49
57
  async updateLoggingEnabled(getLoggingEnabled) {
50
58
  if (getLoggingEnabled) {
51
59
  this.loggingEnabled = await getLoggingEnabled();
@@ -63,8 +71,13 @@ var Logger = class {
63
71
  console.log(`[${this.context}] Logging enabled`);
64
72
  }
65
73
  }
74
+ trace(message, ...rest) {
75
+ if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
76
+ console.log(`[${this.context}] ${message}`, ...rest);
77
+ }
78
+ }
66
79
  info(message, ...rest) {
67
- if (this.loggingEnabled) {
80
+ if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
68
81
  console.log(`[${this.context}] ${message}`, ...rest);
69
82
  }
70
83
  }
@@ -108,21 +121,11 @@ var StubAuthProvider = class {
108
121
  }
109
122
  };
110
123
 
111
- // src/constants/localStorage.ts
124
+ // src/constants/index.ts
112
125
  var ConfigKeys = {
113
126
  LoggingEnabled: "lightspark-logging-enabled",
114
127
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
115
128
  };
116
- var getLocalStorageConfigItem = (key) => {
117
- return getLocalStorageBoolean(key);
118
- };
119
- var getLocalStorageBoolean = (key) => {
120
- try {
121
- return localStorage.getItem(key) === "1";
122
- } catch (e) {
123
- return false;
124
- }
125
- };
126
129
 
127
130
  // src/crypto/KeyOrAlias.ts
128
131
  var KeyOrAlias = {
@@ -379,7 +382,7 @@ var Secp256k1SigningKey = class extends SigningKey {
379
382
  const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
380
383
  const hash = await createSha256Hash(data);
381
384
  const signResult = secp256k1.ecdsaSign(hash, keyBytes);
382
- return signResult.signature;
385
+ return secp256k1.signatureExport(signResult.signature);
383
386
  }
384
387
  };
385
388
 
@@ -489,14 +492,14 @@ var Requester = class {
489
492
  return query.constructObject(data);
490
493
  }
491
494
  subscribe(queryPayload, variables = {}) {
492
- logger.info(`Requester.subscribe variables`, variables);
495
+ logger.trace(`Requester.subscribe variables`, variables);
493
496
  const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
494
497
  const operationMatch = queryPayload.match(operationNameRegex);
495
498
  if (!operationMatch || operationMatch.length < 3) {
496
499
  throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
497
500
  }
498
501
  const operationType = operationMatch[1];
499
- logger.info(`Requester.subscribe operationType`, operationType);
502
+ logger.trace(`Requester.subscribe operationType`, operationType);
500
503
  if (operationType == "mutation") {
501
504
  throw new LightsparkException_default(
502
505
  "InvalidQuery",
@@ -515,7 +518,7 @@ var Requester = class {
515
518
  operationName: operation
516
519
  };
517
520
  return new Observable((observer) => {
518
- logger.info(`Requester.subscribe observer`, observer);
521
+ logger.trace(`Requester.subscribe observer`, observer);
519
522
  return this.wsClient.subscribe(bodyData, {
520
523
  next: (data) => observer.next(data),
521
524
  error: (err) => observer.error(err),
@@ -566,7 +569,7 @@ var Requester = class {
566
569
  urlWithProtocol = `https://${urlWithProtocol}`;
567
570
  }
568
571
  const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
569
- logger.info(`Requester.makeRawRequest`, {
572
+ logger.trace(`Requester.makeRawRequest`, {
570
573
  url,
571
574
  operationName: operation,
572
575
  variables
@@ -622,9 +625,11 @@ var Requester = class {
622
625
  "Missing node of encrypted_signing_private_key"
623
626
  );
624
627
  }
625
- let TextEncoderImpl = TextEncoder;
628
+ let TextEncoderImpl;
626
629
  if (typeof TextEncoder === "undefined") {
627
630
  TextEncoderImpl = (await import("text-encoding")).TextEncoder;
631
+ } else {
632
+ TextEncoderImpl = TextEncoder;
628
633
  }
629
634
  const encodedPayload = new TextEncoderImpl().encode(
630
635
  JSON.stringify(payload)
@@ -667,6 +672,7 @@ export {
667
672
  countryCodesToCurrencyCodes,
668
673
  createSha256Hash,
669
674
  defaultCurrencyCode,
675
+ deleteLocalStorageItem,
670
676
  errorToJSON,
671
677
  formatCurrencyStr,
672
678
  getCurrentLocale,
@@ -692,6 +698,7 @@ export {
692
698
  pollUntil,
693
699
  round,
694
700
  separateCurrencyStrParts,
701
+ setLocalStorageBoolean,
695
702
  sleep,
696
703
  urlsafe_b64decode
697
704
  };
@@ -41,10 +41,13 @@ __export(utils_exports, {
41
41
  countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
42
42
  createSha256Hash: () => createSha256Hash,
43
43
  defaultCurrencyCode: () => defaultCurrencyCode,
44
+ deleteLocalStorageItem: () => deleteLocalStorageItem,
44
45
  errorToJSON: () => errorToJSON,
45
46
  formatCurrencyStr: () => formatCurrencyStr,
46
47
  getCurrentLocale: () => getCurrentLocale,
47
48
  getErrorMsg: () => getErrorMsg,
49
+ getLocalStorageBoolean: () => getLocalStorageBoolean,
50
+ getLocalStorageConfigItem: () => getLocalStorageConfigItem,
48
51
  hexToBytes: () => hexToBytes,
49
52
  isBrowser: () => isBrowser,
50
53
  isCurrencyAmount: () => isCurrencyAmount,
@@ -64,6 +67,7 @@ __export(utils_exports, {
64
67
  pollUntil: () => pollUntil,
65
68
  round: () => round,
66
69
  separateCurrencyStrParts: () => separateCurrencyStrParts,
70
+ setLocalStorageBoolean: () => setLocalStorageBoolean,
67
71
  sleep: () => sleep,
68
72
  urlsafe_b64decode: () => urlsafe_b64decode
69
73
  });
@@ -800,6 +804,9 @@ var isErrorMsg = (e, msg) => {
800
804
  return false;
801
805
  };
802
806
  function errorToJSON(err) {
807
+ if (!err) {
808
+ return null;
809
+ }
803
810
  if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
804
811
  return err.toJSON();
805
812
  }
@@ -808,6 +815,30 @@ function errorToJSON(err) {
808
815
  );
809
816
  }
810
817
 
818
+ // src/utils/localStorage.ts
819
+ function getLocalStorageConfigItem(key) {
820
+ return getLocalStorageBoolean(key);
821
+ }
822
+ function getLocalStorageBoolean(key) {
823
+ try {
824
+ return localStorage.getItem(key) === "1";
825
+ } catch (e) {
826
+ return false;
827
+ }
828
+ }
829
+ function setLocalStorageBoolean(key, value) {
830
+ try {
831
+ localStorage.setItem(key, value ? "1" : "0");
832
+ } catch (e) {
833
+ }
834
+ }
835
+ var deleteLocalStorageItem = (key) => {
836
+ try {
837
+ localStorage.removeItem(key);
838
+ } catch (e) {
839
+ }
840
+ };
841
+
811
842
  // ../../node_modules/lodash-es/_freeGlobal.js
812
843
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
813
844
  var freeGlobal_default = freeGlobal;
@@ -946,10 +977,13 @@ var isType = (typename) => (node) => {
946
977
  countryCodesToCurrencyCodes,
947
978
  createSha256Hash,
948
979
  defaultCurrencyCode,
980
+ deleteLocalStorageItem,
949
981
  errorToJSON,
950
982
  formatCurrencyStr,
951
983
  getCurrentLocale,
952
984
  getErrorMsg,
985
+ getLocalStorageBoolean,
986
+ getLocalStorageConfigItem,
953
987
  hexToBytes,
954
988
  isBrowser,
955
989
  isCurrencyAmount,
@@ -969,6 +1003,7 @@ var isType = (typename) => (node) => {
969
1003
  pollUntil,
970
1004
  round,
971
1005
  separateCurrencyStrParts,
1006
+ setLocalStorageBoolean,
972
1007
  sleep,
973
1008
  urlsafe_b64decode
974
1009
  });
@@ -1,260 +1 @@
1
- declare const b64decode: (encoded: string) => Uint8Array;
2
- declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
3
- declare const b64encode: (data: ArrayBuffer) => string;
4
-
5
- type SourceData = Uint8Array | string;
6
- declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
7
- declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
8
-
9
- declare const defaultCurrencyCode = "USD";
10
- /**
11
- * This enum identifies the unit of currency associated with a CurrencyAmount.
12
- * *
13
- */
14
- declare enum CurrencyUnit {
15
- /**
16
- * This is an enum value that represents values that could be added in the
17
- * future. Clients should support unknown values as more of them could be
18
- * added without notice.
19
- */
20
- FUTURE_VALUE = "FUTURE_VALUE",
21
- /**
22
- * Bitcoin is the cryptocurrency native to the Bitcoin network.
23
- * It is used as the native medium for value transfer for the Lightning
24
- * Network. *
25
- */
26
- BITCOIN = "BITCOIN",
27
- /**
28
- * 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
29
- * This is the unit most commonly used in Lightning transactions.
30
- * *
31
- */
32
- SATOSHI = "SATOSHI",
33
- /**
34
- * 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
35
- * instead when possible. *
36
- */
37
- MILLISATOSHI = "MILLISATOSHI",
38
- /** United States Dollar. **/
39
- USD = "USD",
40
- /**
41
- * 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
42
- * We recommend using the Satoshi unit instead when possible.
43
- * *
44
- */
45
- NANOBITCOIN = "NANOBITCOIN",
46
- /**
47
- * 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
48
- * We recommend using the Satoshi unit instead when possible.
49
- * *
50
- */
51
- MICROBITCOIN = "MICROBITCOIN",
52
- /**
53
- * 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
54
- * We recommend using the Satoshi unit instead when possible.
55
- * *
56
- */
57
- MILLIBITCOIN = "MILLIBITCOIN"
58
- }
59
- /** This object represents the value and unit for an amount of currency. **/
60
- type CurrencyAmountType = {
61
- /** The original numeric value for this CurrencyAmount. **/
62
- originalValue: number;
63
- /** The original unit of currency for this CurrencyAmount. **/
64
- originalUnit: CurrencyUnit;
65
- /** The unit of user's preferred currency. **/
66
- preferredCurrencyUnit: CurrencyUnit;
67
- /**
68
- * The rounded numeric value for this CurrencyAmount in the very base level
69
- * of user's preferred currency. For example, for USD, the value will be in
70
- * cents.
71
- **/
72
- preferredCurrencyValueRounded: number;
73
- /**
74
- * The approximate float value for this CurrencyAmount in the very base level
75
- * of user's preferred currency. For example, for USD, the value will be in
76
- * cents.
77
- **/
78
- preferredCurrencyValueApprox: number;
79
- };
80
- declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
81
- declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
82
- type CurrencyMap = {
83
- sats: number;
84
- msats: number;
85
- btc: number;
86
- [CurrencyUnit.BITCOIN]: number;
87
- [CurrencyUnit.SATOSHI]: number;
88
- [CurrencyUnit.MILLISATOSHI]: number;
89
- [CurrencyUnit.MICROBITCOIN]: number;
90
- [CurrencyUnit.MILLIBITCOIN]: number;
91
- [CurrencyUnit.NANOBITCOIN]: number;
92
- [CurrencyUnit.USD]: number;
93
- [CurrencyUnit.FUTURE_VALUE]: number;
94
- formatted: {
95
- sats: string;
96
- msats: string;
97
- btc: string;
98
- [CurrencyUnit.BITCOIN]: string;
99
- [CurrencyUnit.SATOSHI]: string;
100
- [CurrencyUnit.MILLISATOSHI]: string;
101
- [CurrencyUnit.MILLIBITCOIN]: string;
102
- [CurrencyUnit.MICROBITCOIN]: string;
103
- [CurrencyUnit.NANOBITCOIN]: string;
104
- [CurrencyUnit.USD]: string;
105
- [CurrencyUnit.FUTURE_VALUE]: string;
106
- };
107
- isZero: boolean;
108
- isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
109
- isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
110
- isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
111
- type: "CurrencyMap";
112
- };
113
- type CurrencyAmountObj = {
114
- value?: number | string | null;
115
- unit?: CurrencyUnit;
116
- __typename?: "CurrencyAmount";
117
- };
118
- type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
119
- declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
120
- declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
121
- declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
122
- declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
123
- declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
124
- declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
125
- declare function separateCurrencyStrParts(currencyStr: string): {
126
- symbol: string;
127
- amount: string;
128
- };
129
- declare function localeToCurrencySymbol(locale: string): string;
130
-
131
- declare const isBrowser: boolean;
132
- declare const isNode: boolean;
133
- declare const isTest: boolean;
134
-
135
- type Maybe<T> = T | null | undefined;
136
- type ExpandRecursively<T> = T extends object ? T extends infer O ? {
137
- [K in keyof O]: ExpandRecursively<O[K]>;
138
- } : never : T;
139
- type ById<T> = {
140
- [id: string]: T;
141
- };
142
- type OmitTypename<T> = Omit<T, "__typename">;
143
- declare const isType: <T extends string>(typename: T) => <N extends {
144
- __typename: string;
145
- }>(node: N | null | undefined) => node is Extract<N, {
146
- __typename: T;
147
- }>;
148
- type DeepPartial<T> = T extends object ? {
149
- [P in keyof T]?: DeepPartial<T[P]>;
150
- } : T;
151
- type JSONLiteral = string | number | boolean | null;
152
- type JSONType = JSONLiteral | JSONType[] | {
153
- [key: string]: JSONType;
154
- };
155
- type JSONObject = {
156
- [key: string]: JSONType;
157
- };
158
-
159
- declare const isError: (e: unknown) => e is Error;
160
- type ErrorWithMessage = {
161
- message: string;
162
- };
163
- declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
164
- declare const getErrorMsg: (e: unknown) => string;
165
- declare const isErrorMsg: (e: unknown, msg: string) => boolean;
166
- declare function errorToJSON(err: unknown): JSONType;
167
-
168
- declare const bytesToHex: (bytes: Uint8Array) => string;
169
- declare const hexToBytes: (hex: string) => Uint8Array;
170
-
171
- declare function getCurrentLocale(): string;
172
-
173
- declare const countryCodesToCurrencyCodes: {
174
- readonly AD: "EUR";
175
- readonly AR: "ARS";
176
- readonly AS: "USD";
177
- readonly AT: "EUR";
178
- readonly AU: "AUD";
179
- readonly AX: "EUR";
180
- readonly BE: "EUR";
181
- readonly BL: "EUR";
182
- readonly BQ: "USD";
183
- readonly BR: "BRL";
184
- readonly CA: "CAD";
185
- readonly CO: "COP";
186
- readonly CY: "EUR";
187
- readonly DE: "EUR";
188
- readonly EC: "USD";
189
- readonly EE: "EUR";
190
- readonly ES: "EUR";
191
- readonly FI: "EUR";
192
- readonly FM: "USD";
193
- readonly FR: "EUR";
194
- readonly GB: "GBP";
195
- readonly GF: "EUR";
196
- readonly GG: "GBP";
197
- readonly GP: "EUR";
198
- readonly GR: "EUR";
199
- readonly GS: "GBP";
200
- readonly GU: "USD";
201
- readonly IE: "EUR";
202
- readonly IM: "GBP";
203
- readonly IN: "INR";
204
- readonly IO: "USD";
205
- readonly IT: "EUR";
206
- readonly JE: "GBP";
207
- readonly LT: "EUR";
208
- readonly LU: "EUR";
209
- readonly LV: "EUR";
210
- readonly MC: "EUR";
211
- readonly ME: "EUR";
212
- readonly MF: "EUR";
213
- readonly MH: "USD";
214
- readonly MP: "USD";
215
- readonly MQ: "EUR";
216
- readonly MT: "EUR";
217
- readonly MX: "MXN";
218
- readonly NF: "AUD";
219
- readonly NL: "EUR";
220
- readonly NR: "AUD";
221
- readonly PM: "EUR";
222
- readonly PR: "USD";
223
- readonly PT: "EUR";
224
- readonly PW: "USD";
225
- readonly RE: "EUR";
226
- readonly SI: "EUR";
227
- readonly SK: "EUR";
228
- readonly SM: "EUR";
229
- readonly TC: "USD";
230
- readonly TF: "EUR";
231
- readonly TL: "USD";
232
- readonly TV: "AUD";
233
- readonly UM: "USD";
234
- readonly US: "USD";
235
- readonly VA: "EUR";
236
- readonly VG: "USD";
237
- readonly VI: "USD";
238
- readonly YT: "EUR";
239
- };
240
- type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
241
- type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
242
- declare function localeToCurrencyCode(locale: string): CurrencyCodes;
243
-
244
- declare function clamp(val: number, min: number, max: number): number;
245
- declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
246
- declare function round(num: number, decimalPlaces?: number): number;
247
- declare function isNumber(value: unknown): value is number;
248
-
249
- type GetValueResult<T> = {
250
- stopPolling: boolean;
251
- value: null | T;
252
- };
253
- declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
254
- stopPolling: boolean;
255
- value: null | T;
256
- }) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
257
-
258
- declare function sleep(ms: number): Promise<unknown>;
259
-
260
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, JSONLiteral, JSONObject, JSONType, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, errorToJSON, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
1
+ export { W as ById, k as CurrencyAmountArg, j as CurrencyAmountObj, f as CurrencyAmountType, M as CurrencyCodes, L as CurrencyLocales, i as CurrencyMap, e as CurrencyUnit, Z as DeepPartial, V as ExpandRecursively, _ as JSONLiteral, a0 as JSONObject, $ as JSONType, U as Maybe, X as OmitTypename, 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, m as isCurrencyAmount, l as isCurrencyAmountObj, o as isCurrencyMap, x as isError, A as isErrorMsg, y as isErrorWithMessage, v as isNode, R as isNumber, w as isTest, Y as isType, P as linearInterpolate, N as localeToCurrencyCode, r as localeToCurrencySymbol, n as mapCurrencyAmount, S as pollUntil, Q as round, s as separateCurrencyStrParts, H as setLocalStorageBoolean, T as sleep, u as urlsafe_b64decode } from '../index-d0c72658.js';