@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/CHANGELOG.md +12 -0
- package/dist/{chunk-BYCLLNFL.js → chunk-ZLX5HJ4C.js} +31 -0
- package/dist/index-d0c72658.d.ts +271 -0
- package/dist/index.cjs +50 -18
- package/dist/index.d.cts +9 -10
- package/dist/index.d.ts +9 -10
- package/dist/index.js +26 -19
- package/dist/utils/index.cjs +35 -0
- package/dist/utils/index.d.cts +1 -260
- package/dist/utils/index.d.ts +1 -260
- package/dist/utils/index.js +9 -1
- package/package.json +1 -1
- package/src/Logger.ts +17 -1
- package/src/constants/index.ts +5 -1
- package/src/crypto/SigningKey.ts +1 -1
- package/src/requester/Requester.ts +7 -5
- package/src/utils/errors.ts +3 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/localStorage.ts +32 -0
- package/src/constants/localStorage.ts +0 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b9dd0c2: Return null if !error in errorToJSON
|
|
8
|
+
|
|
9
|
+
## 1.0.13
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- da1e0b2: - export secp256k1 signatures to DER format
|
|
14
|
+
|
|
3
15
|
## 1.0.12
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -729,6 +729,9 @@ var isErrorMsg = (e, msg) => {
|
|
|
729
729
|
return false;
|
|
730
730
|
};
|
|
731
731
|
function errorToJSON(err) {
|
|
732
|
+
if (!err) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
732
735
|
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
733
736
|
return err.toJSON();
|
|
734
737
|
}
|
|
@@ -737,6 +740,30 @@ function errorToJSON(err) {
|
|
|
737
740
|
);
|
|
738
741
|
}
|
|
739
742
|
|
|
743
|
+
// src/utils/localStorage.ts
|
|
744
|
+
function getLocalStorageConfigItem(key) {
|
|
745
|
+
return getLocalStorageBoolean(key);
|
|
746
|
+
}
|
|
747
|
+
function getLocalStorageBoolean(key) {
|
|
748
|
+
try {
|
|
749
|
+
return localStorage.getItem(key) === "1";
|
|
750
|
+
} catch (e) {
|
|
751
|
+
return false;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function setLocalStorageBoolean(key, value) {
|
|
755
|
+
try {
|
|
756
|
+
localStorage.setItem(key, value ? "1" : "0");
|
|
757
|
+
} catch (e) {
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
var deleteLocalStorageItem = (key) => {
|
|
761
|
+
try {
|
|
762
|
+
localStorage.removeItem(key);
|
|
763
|
+
} catch (e) {
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
|
|
740
767
|
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
741
768
|
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
742
769
|
var freeGlobal_default = freeGlobal;
|
|
@@ -898,6 +925,10 @@ export {
|
|
|
898
925
|
getErrorMsg,
|
|
899
926
|
isErrorMsg,
|
|
900
927
|
errorToJSON,
|
|
928
|
+
getLocalStorageConfigItem,
|
|
929
|
+
getLocalStorageBoolean,
|
|
930
|
+
setLocalStorageBoolean,
|
|
931
|
+
deleteLocalStorageItem,
|
|
901
932
|
sleep,
|
|
902
933
|
pollUntil,
|
|
903
934
|
isType
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
declare const ConfigKeys: {
|
|
2
|
+
readonly LoggingEnabled: "lightspark-logging-enabled";
|
|
3
|
+
readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
|
|
4
|
+
};
|
|
5
|
+
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
6
|
+
|
|
7
|
+
declare const b64decode: (encoded: string) => Uint8Array;
|
|
8
|
+
declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
|
|
9
|
+
declare const b64encode: (data: ArrayBuffer) => string;
|
|
10
|
+
|
|
11
|
+
type SourceData = Uint8Array | string;
|
|
12
|
+
declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
|
|
13
|
+
declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
|
|
14
|
+
|
|
15
|
+
declare const defaultCurrencyCode = "USD";
|
|
16
|
+
/**
|
|
17
|
+
* This enum identifies the unit of currency associated with a CurrencyAmount.
|
|
18
|
+
* *
|
|
19
|
+
*/
|
|
20
|
+
declare enum CurrencyUnit {
|
|
21
|
+
/**
|
|
22
|
+
* This is an enum value that represents values that could be added in the
|
|
23
|
+
* future. Clients should support unknown values as more of them could be
|
|
24
|
+
* added without notice.
|
|
25
|
+
*/
|
|
26
|
+
FUTURE_VALUE = "FUTURE_VALUE",
|
|
27
|
+
/**
|
|
28
|
+
* Bitcoin is the cryptocurrency native to the Bitcoin network.
|
|
29
|
+
* It is used as the native medium for value transfer for the Lightning
|
|
30
|
+
* Network. *
|
|
31
|
+
*/
|
|
32
|
+
BITCOIN = "BITCOIN",
|
|
33
|
+
/**
|
|
34
|
+
* 0.00000001 (10e-8) Bitcoin or one hundred millionth of a Bitcoin.
|
|
35
|
+
* This is the unit most commonly used in Lightning transactions.
|
|
36
|
+
* *
|
|
37
|
+
*/
|
|
38
|
+
SATOSHI = "SATOSHI",
|
|
39
|
+
/**
|
|
40
|
+
* 0.001 Satoshi, or 10e-11 Bitcoin. We recommend using the Satoshi unit
|
|
41
|
+
* instead when possible. *
|
|
42
|
+
*/
|
|
43
|
+
MILLISATOSHI = "MILLISATOSHI",
|
|
44
|
+
/** United States Dollar. **/
|
|
45
|
+
USD = "USD",
|
|
46
|
+
/**
|
|
47
|
+
* 0.000000001 (10e-9) Bitcoin or a billionth of a Bitcoin.
|
|
48
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
49
|
+
* *
|
|
50
|
+
*/
|
|
51
|
+
NANOBITCOIN = "NANOBITCOIN",
|
|
52
|
+
/**
|
|
53
|
+
* 0.000001 (10e-6) Bitcoin or a millionth of a Bitcoin.
|
|
54
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
55
|
+
* *
|
|
56
|
+
*/
|
|
57
|
+
MICROBITCOIN = "MICROBITCOIN",
|
|
58
|
+
/**
|
|
59
|
+
* 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin.
|
|
60
|
+
* We recommend using the Satoshi unit instead when possible.
|
|
61
|
+
* *
|
|
62
|
+
*/
|
|
63
|
+
MILLIBITCOIN = "MILLIBITCOIN"
|
|
64
|
+
}
|
|
65
|
+
/** This object represents the value and unit for an amount of currency. **/
|
|
66
|
+
type CurrencyAmountType = {
|
|
67
|
+
/** The original numeric value for this CurrencyAmount. **/
|
|
68
|
+
originalValue: number;
|
|
69
|
+
/** The original unit of currency for this CurrencyAmount. **/
|
|
70
|
+
originalUnit: CurrencyUnit;
|
|
71
|
+
/** The unit of user's preferred currency. **/
|
|
72
|
+
preferredCurrencyUnit: CurrencyUnit;
|
|
73
|
+
/**
|
|
74
|
+
* The rounded numeric 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
|
+
preferredCurrencyValueRounded: number;
|
|
79
|
+
/**
|
|
80
|
+
* The approximate float value for this CurrencyAmount in the very base level
|
|
81
|
+
* of user's preferred currency. For example, for USD, the value will be in
|
|
82
|
+
* cents.
|
|
83
|
+
**/
|
|
84
|
+
preferredCurrencyValueApprox: number;
|
|
85
|
+
};
|
|
86
|
+
declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
|
|
87
|
+
declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
|
|
88
|
+
type CurrencyMap = {
|
|
89
|
+
sats: number;
|
|
90
|
+
msats: number;
|
|
91
|
+
btc: number;
|
|
92
|
+
[CurrencyUnit.BITCOIN]: number;
|
|
93
|
+
[CurrencyUnit.SATOSHI]: number;
|
|
94
|
+
[CurrencyUnit.MILLISATOSHI]: number;
|
|
95
|
+
[CurrencyUnit.MICROBITCOIN]: number;
|
|
96
|
+
[CurrencyUnit.MILLIBITCOIN]: number;
|
|
97
|
+
[CurrencyUnit.NANOBITCOIN]: number;
|
|
98
|
+
[CurrencyUnit.USD]: number;
|
|
99
|
+
[CurrencyUnit.FUTURE_VALUE]: number;
|
|
100
|
+
formatted: {
|
|
101
|
+
sats: string;
|
|
102
|
+
msats: string;
|
|
103
|
+
btc: string;
|
|
104
|
+
[CurrencyUnit.BITCOIN]: string;
|
|
105
|
+
[CurrencyUnit.SATOSHI]: string;
|
|
106
|
+
[CurrencyUnit.MILLISATOSHI]: string;
|
|
107
|
+
[CurrencyUnit.MILLIBITCOIN]: string;
|
|
108
|
+
[CurrencyUnit.MICROBITCOIN]: string;
|
|
109
|
+
[CurrencyUnit.NANOBITCOIN]: string;
|
|
110
|
+
[CurrencyUnit.USD]: string;
|
|
111
|
+
[CurrencyUnit.FUTURE_VALUE]: string;
|
|
112
|
+
};
|
|
113
|
+
isZero: boolean;
|
|
114
|
+
isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
|
|
115
|
+
isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
|
|
116
|
+
isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
|
|
117
|
+
type: "CurrencyMap";
|
|
118
|
+
};
|
|
119
|
+
type CurrencyAmountObj = {
|
|
120
|
+
value?: number | string | null;
|
|
121
|
+
unit?: CurrencyUnit;
|
|
122
|
+
__typename?: "CurrencyAmount";
|
|
123
|
+
};
|
|
124
|
+
type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
|
|
125
|
+
declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
|
|
126
|
+
declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
|
|
127
|
+
declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
|
|
128
|
+
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
129
|
+
declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
130
|
+
declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
|
|
131
|
+
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
132
|
+
symbol: string;
|
|
133
|
+
amount: string;
|
|
134
|
+
};
|
|
135
|
+
declare function localeToCurrencySymbol(locale: string): string;
|
|
136
|
+
|
|
137
|
+
declare const isBrowser: boolean;
|
|
138
|
+
declare const isNode: boolean;
|
|
139
|
+
declare const isTest: boolean;
|
|
140
|
+
|
|
141
|
+
type Maybe<T> = T | null | undefined;
|
|
142
|
+
type ExpandRecursively<T> = T extends object ? T extends infer O ? {
|
|
143
|
+
[K in keyof O]: ExpandRecursively<O[K]>;
|
|
144
|
+
} : never : T;
|
|
145
|
+
type ById<T> = {
|
|
146
|
+
[id: string]: T;
|
|
147
|
+
};
|
|
148
|
+
type OmitTypename<T> = Omit<T, "__typename">;
|
|
149
|
+
declare const isType: <T extends string>(typename: T) => <N extends {
|
|
150
|
+
__typename: string;
|
|
151
|
+
}>(node: N | null | undefined) => node is Extract<N, {
|
|
152
|
+
__typename: T;
|
|
153
|
+
}>;
|
|
154
|
+
type DeepPartial<T> = T extends object ? {
|
|
155
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
156
|
+
} : T;
|
|
157
|
+
type JSONLiteral = string | number | boolean | null;
|
|
158
|
+
type JSONType = JSONLiteral | JSONType[] | {
|
|
159
|
+
[key: string]: JSONType;
|
|
160
|
+
};
|
|
161
|
+
type JSONObject = {
|
|
162
|
+
[key: string]: JSONType;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
declare const isError: (e: unknown) => e is Error;
|
|
166
|
+
type ErrorWithMessage = {
|
|
167
|
+
message: string;
|
|
168
|
+
};
|
|
169
|
+
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
170
|
+
declare const getErrorMsg: (e: unknown) => string;
|
|
171
|
+
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
172
|
+
declare function errorToJSON(err: unknown): JSONType;
|
|
173
|
+
|
|
174
|
+
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
175
|
+
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
176
|
+
|
|
177
|
+
declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
|
|
178
|
+
declare function getLocalStorageBoolean(key: string): boolean;
|
|
179
|
+
declare function setLocalStorageBoolean(key: string, value: boolean): void;
|
|
180
|
+
declare const deleteLocalStorageItem: (key: string) => void;
|
|
181
|
+
|
|
182
|
+
declare function getCurrentLocale(): string;
|
|
183
|
+
|
|
184
|
+
declare const countryCodesToCurrencyCodes: {
|
|
185
|
+
readonly AD: "EUR";
|
|
186
|
+
readonly AR: "ARS";
|
|
187
|
+
readonly AS: "USD";
|
|
188
|
+
readonly AT: "EUR";
|
|
189
|
+
readonly AU: "AUD";
|
|
190
|
+
readonly AX: "EUR";
|
|
191
|
+
readonly BE: "EUR";
|
|
192
|
+
readonly BL: "EUR";
|
|
193
|
+
readonly BQ: "USD";
|
|
194
|
+
readonly BR: "BRL";
|
|
195
|
+
readonly CA: "CAD";
|
|
196
|
+
readonly CO: "COP";
|
|
197
|
+
readonly CY: "EUR";
|
|
198
|
+
readonly DE: "EUR";
|
|
199
|
+
readonly EC: "USD";
|
|
200
|
+
readonly EE: "EUR";
|
|
201
|
+
readonly ES: "EUR";
|
|
202
|
+
readonly FI: "EUR";
|
|
203
|
+
readonly FM: "USD";
|
|
204
|
+
readonly FR: "EUR";
|
|
205
|
+
readonly GB: "GBP";
|
|
206
|
+
readonly GF: "EUR";
|
|
207
|
+
readonly GG: "GBP";
|
|
208
|
+
readonly GP: "EUR";
|
|
209
|
+
readonly GR: "EUR";
|
|
210
|
+
readonly GS: "GBP";
|
|
211
|
+
readonly GU: "USD";
|
|
212
|
+
readonly IE: "EUR";
|
|
213
|
+
readonly IM: "GBP";
|
|
214
|
+
readonly IN: "INR";
|
|
215
|
+
readonly IO: "USD";
|
|
216
|
+
readonly IT: "EUR";
|
|
217
|
+
readonly JE: "GBP";
|
|
218
|
+
readonly LT: "EUR";
|
|
219
|
+
readonly LU: "EUR";
|
|
220
|
+
readonly LV: "EUR";
|
|
221
|
+
readonly MC: "EUR";
|
|
222
|
+
readonly ME: "EUR";
|
|
223
|
+
readonly MF: "EUR";
|
|
224
|
+
readonly MH: "USD";
|
|
225
|
+
readonly MP: "USD";
|
|
226
|
+
readonly MQ: "EUR";
|
|
227
|
+
readonly MT: "EUR";
|
|
228
|
+
readonly MX: "MXN";
|
|
229
|
+
readonly NF: "AUD";
|
|
230
|
+
readonly NL: "EUR";
|
|
231
|
+
readonly NR: "AUD";
|
|
232
|
+
readonly PM: "EUR";
|
|
233
|
+
readonly PR: "USD";
|
|
234
|
+
readonly PT: "EUR";
|
|
235
|
+
readonly PW: "USD";
|
|
236
|
+
readonly RE: "EUR";
|
|
237
|
+
readonly SI: "EUR";
|
|
238
|
+
readonly SK: "EUR";
|
|
239
|
+
readonly SM: "EUR";
|
|
240
|
+
readonly TC: "USD";
|
|
241
|
+
readonly TF: "EUR";
|
|
242
|
+
readonly TL: "USD";
|
|
243
|
+
readonly TV: "AUD";
|
|
244
|
+
readonly UM: "USD";
|
|
245
|
+
readonly US: "USD";
|
|
246
|
+
readonly VA: "EUR";
|
|
247
|
+
readonly VG: "USD";
|
|
248
|
+
readonly VI: "USD";
|
|
249
|
+
readonly YT: "EUR";
|
|
250
|
+
};
|
|
251
|
+
type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
|
|
252
|
+
type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
|
|
253
|
+
declare function localeToCurrencyCode(locale: string): CurrencyCodes;
|
|
254
|
+
|
|
255
|
+
declare function clamp(val: number, min: number, max: number): number;
|
|
256
|
+
declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
|
|
257
|
+
declare function round(num: number, decimalPlaces?: number): number;
|
|
258
|
+
declare function isNumber(value: unknown): value is number;
|
|
259
|
+
|
|
260
|
+
type GetValueResult<T> = {
|
|
261
|
+
stopPolling: boolean;
|
|
262
|
+
value: null | T;
|
|
263
|
+
};
|
|
264
|
+
declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
|
|
265
|
+
stopPolling: boolean;
|
|
266
|
+
value: null | T;
|
|
267
|
+
}) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
|
|
268
|
+
|
|
269
|
+
declare function sleep(ms: number): Promise<unknown>;
|
|
270
|
+
|
|
271
|
+
export { JSONType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, pollUntil as S, sleep as T, Maybe as U, ExpandRecursively as V, ById as W, OmitTypename as X, isType as Y, DeepPartial as Z, JSONLiteral as _, b64encode as a, JSONObject as a0, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyAmountType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
|
package/dist/index.cjs
CHANGED
|
@@ -57,6 +57,7 @@ __export(src_exports, {
|
|
|
57
57
|
countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
|
|
58
58
|
createSha256Hash: () => createSha256Hash,
|
|
59
59
|
defaultCurrencyCode: () => defaultCurrencyCode,
|
|
60
|
+
deleteLocalStorageItem: () => deleteLocalStorageItem,
|
|
60
61
|
errorToJSON: () => errorToJSON,
|
|
61
62
|
formatCurrencyStr: () => formatCurrencyStr,
|
|
62
63
|
getCurrentLocale: () => getCurrentLocale,
|
|
@@ -82,6 +83,7 @@ __export(src_exports, {
|
|
|
82
83
|
pollUntil: () => pollUntil,
|
|
83
84
|
round: () => round,
|
|
84
85
|
separateCurrencyStrParts: () => separateCurrencyStrParts,
|
|
86
|
+
setLocalStorageBoolean: () => setLocalStorageBoolean,
|
|
85
87
|
sleep: () => sleep,
|
|
86
88
|
urlsafe_b64decode: () => urlsafe_b64decode
|
|
87
89
|
});
|
|
@@ -110,10 +112,14 @@ var isTest = isNode && process.env.NODE_ENV === "test";
|
|
|
110
112
|
var Logger = class {
|
|
111
113
|
context;
|
|
112
114
|
loggingEnabled = false;
|
|
115
|
+
loggingLevel = 1 /* Info */;
|
|
113
116
|
constructor(loggerContext, getLoggingEnabled) {
|
|
114
117
|
this.context = loggerContext;
|
|
115
118
|
void this.updateLoggingEnabled(getLoggingEnabled);
|
|
116
119
|
}
|
|
120
|
+
setLevel(level) {
|
|
121
|
+
this.loggingLevel = level;
|
|
122
|
+
}
|
|
117
123
|
async updateLoggingEnabled(getLoggingEnabled) {
|
|
118
124
|
if (getLoggingEnabled) {
|
|
119
125
|
this.loggingEnabled = await getLoggingEnabled();
|
|
@@ -131,8 +137,13 @@ var Logger = class {
|
|
|
131
137
|
console.log(`[${this.context}] Logging enabled`);
|
|
132
138
|
}
|
|
133
139
|
}
|
|
140
|
+
trace(message, ...rest) {
|
|
141
|
+
if (this.loggingEnabled && this.loggingLevel === 0 /* Trace */) {
|
|
142
|
+
console.log(`[${this.context}] ${message}`, ...rest);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
134
145
|
info(message, ...rest) {
|
|
135
|
-
if (this.loggingEnabled) {
|
|
146
|
+
if (this.loggingEnabled && this.loggingLevel <= 1 /* Info */) {
|
|
136
147
|
console.log(`[${this.context}] ${message}`, ...rest);
|
|
137
148
|
}
|
|
138
149
|
}
|
|
@@ -176,21 +187,11 @@ var StubAuthProvider = class {
|
|
|
176
187
|
}
|
|
177
188
|
};
|
|
178
189
|
|
|
179
|
-
// src/constants/
|
|
190
|
+
// src/constants/index.ts
|
|
180
191
|
var ConfigKeys = {
|
|
181
192
|
LoggingEnabled: "lightspark-logging-enabled",
|
|
182
193
|
ConsoleToolsEnabled: "lightspark-console-tools-enabled"
|
|
183
194
|
};
|
|
184
|
-
var getLocalStorageConfigItem = (key) => {
|
|
185
|
-
return getLocalStorageBoolean(key);
|
|
186
|
-
};
|
|
187
|
-
var getLocalStorageBoolean = (key) => {
|
|
188
|
-
try {
|
|
189
|
-
return localStorage.getItem(key) === "1";
|
|
190
|
-
} catch (e) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
195
|
|
|
195
196
|
// src/crypto/KeyOrAlias.ts
|
|
196
197
|
var KeyOrAlias = {
|
|
@@ -1131,6 +1132,9 @@ var isErrorMsg = (e, msg) => {
|
|
|
1131
1132
|
return false;
|
|
1132
1133
|
};
|
|
1133
1134
|
function errorToJSON(err) {
|
|
1135
|
+
if (!err) {
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1134
1138
|
if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
|
|
1135
1139
|
return err.toJSON();
|
|
1136
1140
|
}
|
|
@@ -1139,6 +1143,30 @@ function errorToJSON(err) {
|
|
|
1139
1143
|
);
|
|
1140
1144
|
}
|
|
1141
1145
|
|
|
1146
|
+
// src/utils/localStorage.ts
|
|
1147
|
+
function getLocalStorageConfigItem(key) {
|
|
1148
|
+
return getLocalStorageBoolean(key);
|
|
1149
|
+
}
|
|
1150
|
+
function getLocalStorageBoolean(key) {
|
|
1151
|
+
try {
|
|
1152
|
+
return localStorage.getItem(key) === "1";
|
|
1153
|
+
} catch (e) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
function setLocalStorageBoolean(key, value) {
|
|
1158
|
+
try {
|
|
1159
|
+
localStorage.setItem(key, value ? "1" : "0");
|
|
1160
|
+
} catch (e) {
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
var deleteLocalStorageItem = (key) => {
|
|
1164
|
+
try {
|
|
1165
|
+
localStorage.removeItem(key);
|
|
1166
|
+
} catch (e) {
|
|
1167
|
+
}
|
|
1168
|
+
};
|
|
1169
|
+
|
|
1142
1170
|
// ../../node_modules/lodash-es/_freeGlobal.js
|
|
1143
1171
|
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
|
|
1144
1172
|
var freeGlobal_default = freeGlobal;
|
|
@@ -1295,7 +1323,7 @@ var Secp256k1SigningKey = class extends SigningKey {
|
|
|
1295
1323
|
const keyBytes = new Uint8Array(hexToBytes(this.privateKey));
|
|
1296
1324
|
const hash = await createSha256Hash(data);
|
|
1297
1325
|
const signResult = import_secp256k1.default.ecdsaSign(hash, keyBytes);
|
|
1298
|
-
return signResult.signature;
|
|
1326
|
+
return import_secp256k1.default.signatureExport(signResult.signature);
|
|
1299
1327
|
}
|
|
1300
1328
|
};
|
|
1301
1329
|
|
|
@@ -1405,14 +1433,14 @@ var Requester = class {
|
|
|
1405
1433
|
return query.constructObject(data);
|
|
1406
1434
|
}
|
|
1407
1435
|
subscribe(queryPayload, variables = {}) {
|
|
1408
|
-
logger.
|
|
1436
|
+
logger.trace(`Requester.subscribe variables`, variables);
|
|
1409
1437
|
const operationNameRegex = /^\s*(query|mutation|subscription)\s+(\w+)/i;
|
|
1410
1438
|
const operationMatch = queryPayload.match(operationNameRegex);
|
|
1411
1439
|
if (!operationMatch || operationMatch.length < 3) {
|
|
1412
1440
|
throw new LightsparkException_default("InvalidQuery", "Invalid query payload");
|
|
1413
1441
|
}
|
|
1414
1442
|
const operationType = operationMatch[1];
|
|
1415
|
-
logger.
|
|
1443
|
+
logger.trace(`Requester.subscribe operationType`, operationType);
|
|
1416
1444
|
if (operationType == "mutation") {
|
|
1417
1445
|
throw new LightsparkException_default(
|
|
1418
1446
|
"InvalidQuery",
|
|
@@ -1431,7 +1459,7 @@ var Requester = class {
|
|
|
1431
1459
|
operationName: operation
|
|
1432
1460
|
};
|
|
1433
1461
|
return new import_zen_observable_ts.Observable((observer) => {
|
|
1434
|
-
logger.
|
|
1462
|
+
logger.trace(`Requester.subscribe observer`, observer);
|
|
1435
1463
|
return this.wsClient.subscribe(bodyData, {
|
|
1436
1464
|
next: (data) => observer.next(data),
|
|
1437
1465
|
error: (err) => observer.error(err),
|
|
@@ -1482,7 +1510,7 @@ var Requester = class {
|
|
|
1482
1510
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
1483
1511
|
}
|
|
1484
1512
|
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
1485
|
-
logger.
|
|
1513
|
+
logger.trace(`Requester.makeRawRequest`, {
|
|
1486
1514
|
url,
|
|
1487
1515
|
operationName: operation,
|
|
1488
1516
|
variables
|
|
@@ -1538,9 +1566,11 @@ var Requester = class {
|
|
|
1538
1566
|
"Missing node of encrypted_signing_private_key"
|
|
1539
1567
|
);
|
|
1540
1568
|
}
|
|
1541
|
-
let TextEncoderImpl
|
|
1569
|
+
let TextEncoderImpl;
|
|
1542
1570
|
if (typeof TextEncoder === "undefined") {
|
|
1543
1571
|
TextEncoderImpl = (await import("text-encoding")).TextEncoder;
|
|
1572
|
+
} else {
|
|
1573
|
+
TextEncoderImpl = TextEncoder;
|
|
1544
1574
|
}
|
|
1545
1575
|
const encodedPayload = new TextEncoderImpl().encode(
|
|
1546
1576
|
JSON.stringify(payload)
|
|
@@ -1584,6 +1614,7 @@ var Requester_default = Requester;
|
|
|
1584
1614
|
countryCodesToCurrencyCodes,
|
|
1585
1615
|
createSha256Hash,
|
|
1586
1616
|
defaultCurrencyCode,
|
|
1617
|
+
deleteLocalStorageItem,
|
|
1587
1618
|
errorToJSON,
|
|
1588
1619
|
formatCurrencyStr,
|
|
1589
1620
|
getCurrentLocale,
|
|
@@ -1609,6 +1640,7 @@ var Requester_default = Requester;
|
|
|
1609
1640
|
pollUntil,
|
|
1610
1641
|
round,
|
|
1611
1642
|
separateCurrencyStrParts,
|
|
1643
|
+
setLocalStorageBoolean,
|
|
1612
1644
|
sleep,
|
|
1613
1645
|
urlsafe_b64decode
|
|
1614
1646
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export { W as ById, C as ConfigKeys, 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';
|
|
1
2
|
import { Observable } from 'zen-observable-ts';
|
|
2
|
-
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 } from './utils/index.cjs';
|
|
3
3
|
|
|
4
4
|
declare class LightsparkException extends Error {
|
|
5
5
|
code: string;
|
|
@@ -9,11 +9,18 @@ declare class LightsparkException extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare enum LoggingLevel {
|
|
13
|
+
Trace = 0,
|
|
14
|
+
Info = 1
|
|
15
|
+
}
|
|
12
16
|
declare class Logger {
|
|
13
17
|
context: string;
|
|
14
18
|
loggingEnabled: boolean;
|
|
19
|
+
loggingLevel: LoggingLevel;
|
|
15
20
|
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
21
|
+
setLevel(level: LoggingLevel): void;
|
|
16
22
|
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
23
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
17
24
|
info(message: string, ...rest: unknown[]): void;
|
|
18
25
|
}
|
|
19
26
|
|
|
@@ -41,14 +48,6 @@ declare class StubAuthProvider implements AuthProvider {
|
|
|
41
48
|
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
declare const ConfigKeys: {
|
|
45
|
-
readonly LoggingEnabled: "lightspark-logging-enabled";
|
|
46
|
-
readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
|
|
47
|
-
};
|
|
48
|
-
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
49
|
-
declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
|
|
50
|
-
declare const getLocalStorageBoolean: (key: string) => boolean;
|
|
51
|
-
|
|
52
51
|
type OnlyKey = {
|
|
53
52
|
key: string;
|
|
54
53
|
alias?: never;
|
|
@@ -166,4 +165,4 @@ declare class Requester {
|
|
|
166
165
|
private addSigningDataIfNeeded;
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
export { AuthProvider,
|
|
168
|
+
export { AuthProvider, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
export { W as ById, C as ConfigKeys, 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';
|
|
1
2
|
import { Observable } from 'zen-observable-ts';
|
|
2
|
-
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 } from './utils/index.js';
|
|
3
3
|
|
|
4
4
|
declare class LightsparkException extends Error {
|
|
5
5
|
code: string;
|
|
@@ -9,11 +9,18 @@ declare class LightsparkException extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
type GetLoggingEnabled = (() => Promise<boolean> | boolean) | undefined;
|
|
12
|
+
declare enum LoggingLevel {
|
|
13
|
+
Trace = 0,
|
|
14
|
+
Info = 1
|
|
15
|
+
}
|
|
12
16
|
declare class Logger {
|
|
13
17
|
context: string;
|
|
14
18
|
loggingEnabled: boolean;
|
|
19
|
+
loggingLevel: LoggingLevel;
|
|
15
20
|
constructor(loggerContext: string, getLoggingEnabled?: GetLoggingEnabled);
|
|
21
|
+
setLevel(level: LoggingLevel): void;
|
|
16
22
|
updateLoggingEnabled(getLoggingEnabled: GetLoggingEnabled): Promise<void>;
|
|
23
|
+
trace(message: string, ...rest: unknown[]): void;
|
|
17
24
|
info(message: string, ...rest: unknown[]): void;
|
|
18
25
|
}
|
|
19
26
|
|
|
@@ -41,14 +48,6 @@ declare class StubAuthProvider implements AuthProvider {
|
|
|
41
48
|
addWsConnectionParams(params: WsConnectionParams): Promise<WsConnectionParams>;
|
|
42
49
|
}
|
|
43
50
|
|
|
44
|
-
declare const ConfigKeys: {
|
|
45
|
-
readonly LoggingEnabled: "lightspark-logging-enabled";
|
|
46
|
-
readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
|
|
47
|
-
};
|
|
48
|
-
type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
|
|
49
|
-
declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
|
|
50
|
-
declare const getLocalStorageBoolean: (key: string) => boolean;
|
|
51
|
-
|
|
52
51
|
type OnlyKey = {
|
|
53
52
|
key: string;
|
|
54
53
|
alias?: never;
|
|
@@ -166,4 +165,4 @@ declare class Requester {
|
|
|
166
165
|
private addSigningDataIfNeeded;
|
|
167
166
|
}
|
|
168
167
|
|
|
169
|
-
export { AuthProvider,
|
|
168
|
+
export { AuthProvider, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment };
|