@lightsparkdev/core 1.0.11 → 1.0.12

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,11 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.0.12
4
+
5
+ ### Patch Changes
6
+
7
+ - 35513da: Upgrade dependencies
8
+
3
9
  ## 1.0.11
4
10
 
5
11
  ### Patch Changes
@@ -728,6 +728,14 @@ var isErrorMsg = (e, msg) => {
728
728
  }
729
729
  return false;
730
730
  };
731
+ function errorToJSON(err) {
732
+ if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
733
+ return err.toJSON();
734
+ }
735
+ return JSON.parse(
736
+ JSON.stringify(err, Object.getOwnPropertyNames(err))
737
+ );
738
+ }
731
739
 
732
740
  // ../../node_modules/lodash-es/_freeGlobal.js
733
741
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -889,6 +897,7 @@ export {
889
897
  isErrorWithMessage,
890
898
  getErrorMsg,
891
899
  isErrorMsg,
900
+ errorToJSON,
892
901
  sleep,
893
902
  pollUntil,
894
903
  isType
package/dist/index.cjs CHANGED
@@ -57,9 +57,11 @@ __export(src_exports, {
57
57
  countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
58
58
  createSha256Hash: () => createSha256Hash,
59
59
  defaultCurrencyCode: () => defaultCurrencyCode,
60
+ errorToJSON: () => errorToJSON,
60
61
  formatCurrencyStr: () => formatCurrencyStr,
61
62
  getCurrentLocale: () => getCurrentLocale,
62
63
  getErrorMsg: () => getErrorMsg,
64
+ getLocalStorageBoolean: () => getLocalStorageBoolean,
63
65
  getLocalStorageConfigItem: () => getLocalStorageConfigItem,
64
66
  hexToBytes: () => hexToBytes,
65
67
  isBrowser: () => isBrowser,
@@ -180,6 +182,9 @@ var ConfigKeys = {
180
182
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
181
183
  };
182
184
  var getLocalStorageConfigItem = (key) => {
185
+ return getLocalStorageBoolean(key);
186
+ };
187
+ var getLocalStorageBoolean = (key) => {
183
188
  try {
184
189
  return localStorage.getItem(key) === "1";
185
190
  } catch (e) {
@@ -1125,6 +1130,14 @@ var isErrorMsg = (e, msg) => {
1125
1130
  }
1126
1131
  return false;
1127
1132
  };
1133
+ function errorToJSON(err) {
1134
+ if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
1135
+ return err.toJSON();
1136
+ }
1137
+ return JSON.parse(
1138
+ JSON.stringify(err, Object.getOwnPropertyNames(err))
1139
+ );
1140
+ }
1128
1141
 
1129
1142
  // ../../node_modules/lodash-es/_freeGlobal.js
1130
1143
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -1571,9 +1584,11 @@ var Requester_default = Requester;
1571
1584
  countryCodesToCurrencyCodes,
1572
1585
  createSha256Hash,
1573
1586
  defaultCurrencyCode,
1587
+ errorToJSON,
1574
1588
  formatCurrencyStr,
1575
1589
  getCurrentLocale,
1576
1590
  getErrorMsg,
1591
+ getLocalStorageBoolean,
1577
1592
  getLocalStorageConfigItem,
1578
1593
  hexToBytes,
1579
1594
  isBrowser,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Observable } from 'zen-observable-ts';
2
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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';
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;
@@ -47,6 +47,7 @@ declare const ConfigKeys: {
47
47
  };
48
48
  type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
49
49
  declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
50
+ declare const getLocalStorageBoolean: (key: string) => boolean;
50
51
 
51
52
  type OnlyKey = {
52
53
  key: string;
@@ -165,4 +166,4 @@ declare class Requester {
165
166
  private addSigningDataIfNeeded;
166
167
  }
167
168
 
168
- export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
169
+ export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageBoolean, getLocalStorageConfigItem };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Observable } from 'zen-observable-ts';
2
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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';
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;
@@ -47,6 +47,7 @@ declare const ConfigKeys: {
47
47
  };
48
48
  type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
49
49
  declare const getLocalStorageConfigItem: (key: ConfigKeys) => boolean;
50
+ declare const getLocalStorageBoolean: (key: string) => boolean;
50
51
 
51
52
  type OnlyKey = {
52
53
  key: string;
@@ -165,4 +166,4 @@ declare class Requester {
165
166
  private addSigningDataIfNeeded;
166
167
  }
167
168
 
168
- export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageConfigItem };
169
+ export { AuthProvider, ConfigKeys, CryptoInterface, DefaultCrypto, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Logger, NodeKeyCache, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, getLocalStorageBoolean, getLocalStorageConfigItem };
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  countryCodesToCurrencyCodes,
12
12
  createSha256Hash,
13
13
  defaultCurrencyCode,
14
+ errorToJSON,
14
15
  formatCurrencyStr,
15
16
  getCurrentLocale,
16
17
  getErrorMsg,
@@ -35,7 +36,7 @@ import {
35
36
  separateCurrencyStrParts,
36
37
  sleep,
37
38
  urlsafe_b64decode
38
- } from "./chunk-F3XHLUGC.js";
39
+ } from "./chunk-BYCLLNFL.js";
39
40
 
40
41
  // src/Logger.ts
41
42
  var Logger = class {
@@ -113,6 +114,9 @@ var ConfigKeys = {
113
114
  ConsoleToolsEnabled: "lightspark-console-tools-enabled"
114
115
  };
115
116
  var getLocalStorageConfigItem = (key) => {
117
+ return getLocalStorageBoolean(key);
118
+ };
119
+ var getLocalStorageBoolean = (key) => {
116
120
  try {
117
121
  return localStorage.getItem(key) === "1";
118
122
  } catch (e) {
@@ -663,9 +667,11 @@ export {
663
667
  countryCodesToCurrencyCodes,
664
668
  createSha256Hash,
665
669
  defaultCurrencyCode,
670
+ errorToJSON,
666
671
  formatCurrencyStr,
667
672
  getCurrentLocale,
668
673
  getErrorMsg,
674
+ getLocalStorageBoolean,
669
675
  getLocalStorageConfigItem,
670
676
  hexToBytes,
671
677
  isBrowser,
@@ -41,6 +41,7 @@ __export(utils_exports, {
41
41
  countryCodesToCurrencyCodes: () => countryCodesToCurrencyCodes,
42
42
  createSha256Hash: () => createSha256Hash,
43
43
  defaultCurrencyCode: () => defaultCurrencyCode,
44
+ errorToJSON: () => errorToJSON,
44
45
  formatCurrencyStr: () => formatCurrencyStr,
45
46
  getCurrentLocale: () => getCurrentLocale,
46
47
  getErrorMsg: () => getErrorMsg,
@@ -798,6 +799,14 @@ var isErrorMsg = (e, msg) => {
798
799
  }
799
800
  return false;
800
801
  };
802
+ function errorToJSON(err) {
803
+ if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
804
+ return err.toJSON();
805
+ }
806
+ return JSON.parse(
807
+ JSON.stringify(err, Object.getOwnPropertyNames(err))
808
+ );
809
+ }
801
810
 
802
811
  // ../../node_modules/lodash-es/_freeGlobal.js
803
812
  var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
@@ -937,6 +946,7 @@ var isType = (typename) => (node) => {
937
946
  countryCodesToCurrencyCodes,
938
947
  createSha256Hash,
939
948
  defaultCurrencyCode,
949
+ errorToJSON,
940
950
  formatCurrencyStr,
941
951
  getCurrentLocale,
942
952
  getErrorMsg,
@@ -132,6 +132,30 @@ declare const isBrowser: boolean;
132
132
  declare const isNode: boolean;
133
133
  declare const isTest: boolean;
134
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
+
135
159
  declare const isError: (e: unknown) => e is Error;
136
160
  type ErrorWithMessage = {
137
161
  message: string;
@@ -139,6 +163,7 @@ type ErrorWithMessage = {
139
163
  declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
140
164
  declare const getErrorMsg: (e: unknown) => string;
141
165
  declare const isErrorMsg: (e: unknown, msg: string) => boolean;
166
+ declare function errorToJSON(err: unknown): JSONType;
142
167
 
143
168
  declare const bytesToHex: (bytes: Uint8Array) => string;
144
169
  declare const hexToBytes: (hex: string) => Uint8Array;
@@ -232,21 +257,4 @@ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getV
232
257
 
233
258
  declare function sleep(ms: number): Promise<unknown>;
234
259
 
235
- type Maybe<T> = T | null | undefined;
236
- type ExpandRecursively<T> = T extends object ? T extends infer O ? {
237
- [K in keyof O]: ExpandRecursively<O[K]>;
238
- } : never : T;
239
- type ById<T> = {
240
- [id: string]: T;
241
- };
242
- type OmitTypename<T> = Omit<T, "__typename">;
243
- declare const isType: <T extends string>(typename: T) => <N extends {
244
- __typename: string;
245
- }>(node: N | null | undefined) => node is Extract<N, {
246
- __typename: T;
247
- }>;
248
- type DeepPartial<T> = T extends object ? {
249
- [P in keyof T]?: DeepPartial<T[P]>;
250
- } : T;
251
-
252
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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 };
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 };
@@ -132,6 +132,30 @@ declare const isBrowser: boolean;
132
132
  declare const isNode: boolean;
133
133
  declare const isTest: boolean;
134
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
+
135
159
  declare const isError: (e: unknown) => e is Error;
136
160
  type ErrorWithMessage = {
137
161
  message: string;
@@ -139,6 +163,7 @@ type ErrorWithMessage = {
139
163
  declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
140
164
  declare const getErrorMsg: (e: unknown) => string;
141
165
  declare const isErrorMsg: (e: unknown, msg: string) => boolean;
166
+ declare function errorToJSON(err: unknown): JSONType;
142
167
 
143
168
  declare const bytesToHex: (bytes: Uint8Array) => string;
144
169
  declare const hexToBytes: (hex: string) => Uint8Array;
@@ -232,21 +257,4 @@ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getV
232
257
 
233
258
  declare function sleep(ms: number): Promise<unknown>;
234
259
 
235
- type Maybe<T> = T | null | undefined;
236
- type ExpandRecursively<T> = T extends object ? T extends infer O ? {
237
- [K in keyof O]: ExpandRecursively<O[K]>;
238
- } : never : T;
239
- type ById<T> = {
240
- [id: string]: T;
241
- };
242
- type OmitTypename<T> = Omit<T, "__typename">;
243
- declare const isType: <T extends string>(typename: T) => <N extends {
244
- __typename: string;
245
- }>(node: N | null | undefined) => node is Extract<N, {
246
- __typename: T;
247
- }>;
248
- type DeepPartial<T> = T extends object ? {
249
- [P in keyof T]?: DeepPartial<T[P]>;
250
- } : T;
251
-
252
- export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, DeepPartial, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, 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 };
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 };
@@ -10,6 +10,7 @@ import {
10
10
  countryCodesToCurrencyCodes,
11
11
  createSha256Hash,
12
12
  defaultCurrencyCode,
13
+ errorToJSON,
13
14
  formatCurrencyStr,
14
15
  getCurrentLocale,
15
16
  getErrorMsg,
@@ -34,7 +35,7 @@ import {
34
35
  separateCurrencyStrParts,
35
36
  sleep,
36
37
  urlsafe_b64decode
37
- } from "../chunk-F3XHLUGC.js";
38
+ } from "../chunk-BYCLLNFL.js";
38
39
  export {
39
40
  CurrencyUnit,
40
41
  abbrCurrencyUnit,
@@ -47,6 +48,7 @@ export {
47
48
  countryCodesToCurrencyCodes,
48
49
  createSha256Hash,
49
50
  defaultCurrencyCode,
51
+ errorToJSON,
50
52
  formatCurrencyStr,
51
53
  getCurrentLocale,
52
54
  getErrorMsg,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -5,6 +5,11 @@ export const ConfigKeys = {
5
5
  export type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
6
6
 
7
7
  export const getLocalStorageConfigItem = (key: ConfigKeys) => {
8
+ return getLocalStorageBoolean(key);
9
+ };
10
+
11
+ export const getLocalStorageBoolean = (key: string) => {
12
+ /* localStorage is not available in all contexts, use try/catch: */
8
13
  try {
9
14
  return localStorage.getItem(key) === "1";
10
15
  } catch (e) {
@@ -1,3 +1,5 @@
1
+ import { type JSONType } from "./types.js";
2
+
1
3
  export const isError = (e: unknown): e is Error => {
2
4
  return Boolean(
3
5
  typeof e === "object" &&
@@ -34,3 +36,17 @@ export const isErrorMsg = (e: unknown, msg: string) => {
34
36
  }
35
37
  return false;
36
38
  };
39
+
40
+ export function errorToJSON(err: unknown) {
41
+ if (
42
+ typeof err === "object" &&
43
+ err !== null &&
44
+ "toJSON" in err &&
45
+ typeof err.toJSON === "function"
46
+ ) {
47
+ return err.toJSON() as JSONType;
48
+ }
49
+ return JSON.parse(
50
+ JSON.stringify(err, Object.getOwnPropertyNames(err)),
51
+ ) as JSONType;
52
+ }
@@ -27,3 +27,7 @@ export type DeepPartial<T> = T extends object
27
27
  [P in keyof T]?: DeepPartial<T[P]>;
28
28
  }
29
29
  : T;
30
+
31
+ export type JSONLiteral = string | number | boolean | null;
32
+ export type JSONType = JSONLiteral | JSONType[] | { [key: string]: JSONType };
33
+ export type JSONObject = { [key: string]: JSONType };