@lightsparkdev/core 1.3.0 → 1.4.0

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,33 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5cfff96: - **Test script**
8
+ - Renamed `test` to `test-cmd` and made `test` an alias that accepts arbitrary Jest patterns.
9
+ - **Requester**
10
+ - Switched `wsClient` to a lazily initialized `Promise` resolved in a new `initWsClient` method.
11
+ - Moved `autoBind` into constructor and improved cleanup/cancellation logic in `subscribe()`.
12
+ - **New tests**
13
+ - Added `Requester.test.ts` covering query execution, error handling, subscriptions, and signing logic.
14
+ - **Errors utility**
15
+ - Enhanced `errorToJSON` to enumerate non-enumerable props and optionally stringify nested objects.
16
+ - **LocalStorage utility**
17
+ - Made `getLocalStorageBoolean` return `true`/`false`/`null`; `getLocalStorageConfigItem` now defaults missing keys to `false`.
18
+ - **Type guards**
19
+ - Tightened `isObject` signature, added `isRecord`, and removed a duplicate in `types.ts`.
20
+ - **Static assets**
21
+ - Replaced the monolithic SVG logo with an optimized, higher-resolution `lightspark-logo.svg`.
22
+
23
+ ## 1.3.1
24
+
25
+ ### Patch Changes
26
+
27
+ - b21b85e: \* Surface error name when the requester hits a graphQL error.
28
+ - Update Turbo
29
+ - Several small UI package improvements.
30
+
3
31
  ## 1.3.0
4
32
 
5
33
  ### Minor Changes
@@ -888,6 +888,18 @@ function localeToCurrencySymbol(locale) {
888
888
  return symbol;
889
889
  }
890
890
 
891
+ // src/utils/typeGuards.ts
892
+ function isUint8Array(value) {
893
+ return value instanceof Uint8Array;
894
+ }
895
+ function isObject(value) {
896
+ const type = typeof value;
897
+ return value != null && (type == "object" || type == "function");
898
+ }
899
+ function isRecord(value) {
900
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
901
+ }
902
+
891
903
  // src/utils/errors.ts
892
904
  var isError = (e) => {
893
905
  return Boolean(
@@ -908,31 +920,71 @@ var isErrorMsg = (e, msg) => {
908
920
  }
909
921
  return false;
910
922
  };
911
- function errorToJSON(err) {
923
+ function normalizeObject(obj) {
924
+ const normalized = {};
925
+ if (isObject(obj)) {
926
+ const props = Object.getOwnPropertyNames(obj);
927
+ for (const prop of props) {
928
+ const objRecord = obj;
929
+ normalized[prop] = objRecord[prop];
930
+ }
931
+ }
932
+ return normalized;
933
+ }
934
+ function errorToJSON(err, stringifyObjects = false) {
912
935
  if (!err) {
913
936
  return null;
914
937
  }
915
- if (typeof err === "object" && "toJSON" in err && typeof err.toJSON === "function") {
938
+ if (isObject(err) && "toJSON" in err && typeof err.toJSON === "function") {
939
+ if (stringifyObjects === true) {
940
+ return objectToJSON(err.toJSON());
941
+ }
916
942
  return err.toJSON();
917
943
  }
918
944
  if (typeof err === "object" && /* This happens for certain errors like DOMException: */
919
945
  Object.getOwnPropertyNames(err).length === 0 && "message" in err && typeof err.message === "string") {
920
946
  return { message: err.message };
921
947
  }
948
+ return objectToJSON(err);
949
+ }
950
+ function objectToJSON(obj) {
951
+ const normalizedObj = normalizeObject(obj);
922
952
  return JSON.parse(
923
- JSON.stringify(err, Object.getOwnPropertyNames(err))
953
+ JSON.stringify(normalizedObj, (key, value) => {
954
+ if (key === "") {
955
+ return value;
956
+ }
957
+ const objProps = Object.getOwnPropertyNames(normalizedObj);
958
+ if (!objProps.includes(key)) {
959
+ return void 0;
960
+ }
961
+ if (isObject(value)) {
962
+ return JSON.stringify(value);
963
+ }
964
+ return value;
965
+ })
924
966
  );
925
967
  }
926
968
 
927
969
  // src/utils/localStorage.ts
928
970
  function getLocalStorageConfigItem(key) {
929
- return getLocalStorageBoolean(key);
971
+ const localStorageBoolean = getLocalStorageBoolean(key);
972
+ if (localStorageBoolean == null) {
973
+ return false;
974
+ }
975
+ return localStorageBoolean;
930
976
  }
931
977
  function getLocalStorageBoolean(key) {
932
978
  try {
933
- return localStorage.getItem(key) === "1";
979
+ if (localStorage.getItem(key) === "1") {
980
+ return true;
981
+ } else if (localStorage.getItem(key) == null) {
982
+ return null;
983
+ } else {
984
+ return false;
985
+ }
934
986
  } catch (e) {
935
- return false;
987
+ return null;
936
988
  }
937
989
  }
938
990
  function setLocalStorageBoolean(key, value) {
@@ -1006,11 +1058,11 @@ function baseGetTag(value) {
1006
1058
  var baseGetTag_default = baseGetTag;
1007
1059
 
1008
1060
  // ../../node_modules/lodash-es/isObject.js
1009
- function isObject(value) {
1061
+ function isObject2(value) {
1010
1062
  var type = typeof value;
1011
1063
  return value != null && (type == "object" || type == "function");
1012
1064
  }
1013
- var isObject_default = isObject;
1065
+ var isObject_default = isObject2;
1014
1066
 
1015
1067
  // ../../node_modules/lodash-es/isFunction.js
1016
1068
  var asyncTag = "[object AsyncFunction]";
@@ -1074,15 +1126,6 @@ function lsidToUUID(lsid) {
1074
1126
  return lsid.replace(/^[^:]+:(.*)$/, "$1");
1075
1127
  }
1076
1128
 
1077
- // src/utils/typeGuards.ts
1078
- function isUint8Array(value) {
1079
- return value instanceof Uint8Array;
1080
- }
1081
- function isObject2(value) {
1082
- const type = typeof value;
1083
- return value != null && (type == "object" || type == "function");
1084
- }
1085
-
1086
1129
  // src/utils/types.ts
1087
1130
  var isType = (typename) => (node) => {
1088
1131
  return node?.__typename === typename;
@@ -1090,9 +1133,6 @@ var isType = (typename) => (node) => {
1090
1133
  function notNullUndefined(value) {
1091
1134
  return value !== null && value !== void 0;
1092
1135
  }
1093
- function isRecord(value) {
1094
- return typeof value === "object" && value !== null && !Array.isArray(value);
1095
- }
1096
1136
 
1097
1137
  export {
1098
1138
  LightsparkException_default,
@@ -1130,6 +1170,9 @@ export {
1130
1170
  formatCurrencyStr,
1131
1171
  separateCurrencyStrParts,
1132
1172
  localeToCurrencySymbol,
1173
+ isUint8Array,
1174
+ isObject,
1175
+ isRecord,
1133
1176
  isError,
1134
1177
  isErrorWithMessage,
1135
1178
  getErrorMsg,
@@ -1142,11 +1185,8 @@ export {
1142
1185
  sleep,
1143
1186
  pollUntil,
1144
1187
  lsidToUUID,
1145
- isUint8Array,
1146
- isObject2 as isObject,
1147
1188
  isType,
1148
- notNullUndefined,
1149
- isRecord
1189
+ notNullUndefined
1150
1190
  };
1151
1191
  /*! Bundled license information:
1152
1192
 
@@ -195,7 +195,6 @@ type Complete<T> = {
195
195
  type RequiredKeys<T> = {
196
196
  [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
197
197
  }[keyof T];
198
- declare function isRecord(value: unknown): value is Record<string, unknown>;
199
198
 
200
199
  declare const isError: (e: unknown) => e is Error;
201
200
  type ErrorWithMessage = {
@@ -204,7 +203,7 @@ type ErrorWithMessage = {
204
203
  declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
205
204
  declare const getErrorMsg: (e: unknown) => string;
206
205
  declare const isErrorMsg: (e: unknown, msg: string) => boolean;
207
- declare function errorToJSON(err: unknown): JSONType;
206
+ declare function errorToJSON(err: unknown, stringifyObjects?: boolean): JSONType;
208
207
 
209
208
  declare const bytesToHex: (bytes: Uint8Array) => string;
210
209
  declare const hexToBytes: (hex: string) => Uint8Array;
@@ -283,7 +282,7 @@ type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
283
282
  declare function localeToCurrencyCode(locale: string): CurrencyCodes;
284
283
 
285
284
  declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
286
- declare function getLocalStorageBoolean(key: string): boolean;
285
+ declare function getLocalStorageBoolean(key: string): boolean | null;
287
286
  declare function setLocalStorageBoolean(key: string, value: boolean): void;
288
287
  declare const deleteLocalStorageItem: (key: string) => void;
289
288
 
@@ -306,6 +305,7 @@ declare function sleep(ms: number): Promise<unknown>;
306
305
  declare function lsidToUUID(lsid: string): string;
307
306
 
308
307
  declare function isUint8Array(value: unknown): value is Uint8Array;
309
- declare function isObject(value: unknown): value is Record<string, unknown>;
308
+ declare function isObject(value: unknown): value is object;
309
+ declare function isRecord(value: unknown): value is Record<string, unknown>;
310
310
 
311
- export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, type Maybe as a8, type ExpandRecursively as a9, type ById as aa, type OmitTypename as ab, isType as ac, type ExtractByTypename as ad, type DeepPartial as ae, type JSONLiteral as af, type JSONType as ag, type JSONObject as ah, type NN as ai, notNullUndefined as aj, type PartialBy as ak, type Complete as al, type RequiredKeys as am, isRecord as an, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
311
+ export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, isRecord as a8, type Maybe as a9, type ExpandRecursively as aa, type ById as ab, type OmitTypename as ac, isType as ad, type ExtractByTypename as ae, type DeepPartial as af, type JSONLiteral as ag, type JSONType as ah, type JSONObject as ai, type NN as aj, notNullUndefined as ak, type PartialBy as al, type Complete as am, type RequiredKeys as an, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
@@ -195,7 +195,6 @@ type Complete<T> = {
195
195
  type RequiredKeys<T> = {
196
196
  [K in keyof T]-?: Record<string, never> extends Pick<T, K> ? never : K;
197
197
  }[keyof T];
198
- declare function isRecord(value: unknown): value is Record<string, unknown>;
199
198
 
200
199
  declare const isError: (e: unknown) => e is Error;
201
200
  type ErrorWithMessage = {
@@ -204,7 +203,7 @@ type ErrorWithMessage = {
204
203
  declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
205
204
  declare const getErrorMsg: (e: unknown) => string;
206
205
  declare const isErrorMsg: (e: unknown, msg: string) => boolean;
207
- declare function errorToJSON(err: unknown): JSONType;
206
+ declare function errorToJSON(err: unknown, stringifyObjects?: boolean): JSONType;
208
207
 
209
208
  declare const bytesToHex: (bytes: Uint8Array) => string;
210
209
  declare const hexToBytes: (hex: string) => Uint8Array;
@@ -283,7 +282,7 @@ type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
283
282
  declare function localeToCurrencyCode(locale: string): CurrencyCodes;
284
283
 
285
284
  declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
286
- declare function getLocalStorageBoolean(key: string): boolean;
285
+ declare function getLocalStorageBoolean(key: string): boolean | null;
287
286
  declare function setLocalStorageBoolean(key: string, value: boolean): void;
288
287
  declare const deleteLocalStorageItem: (key: string) => void;
289
288
 
@@ -306,6 +305,7 @@ declare function sleep(ms: number): Promise<unknown>;
306
305
  declare function lsidToUUID(lsid: string): string;
307
306
 
308
307
  declare function isUint8Array(value: unknown): value is Uint8Array;
309
- declare function isObject(value: unknown): value is Record<string, unknown>;
308
+ declare function isObject(value: unknown): value is object;
309
+ declare function isRecord(value: unknown): value is Record<string, unknown>;
310
310
 
311
- export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, type Maybe as a8, type ExpandRecursively as a9, type ById as aa, type OmitTypename as ab, isType as ac, type ExtractByTypename as ad, type DeepPartial as ae, type JSONLiteral as af, type JSONType as ag, type JSONObject as ah, type NN as ai, notNullUndefined as aj, type PartialBy as ak, type Complete as al, type RequiredKeys as am, isRecord as an, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
311
+ export { clamp as $, type AppendUnitsOptions as A, formatCurrencyStr as B, ConfigKeys as C, type DeprecatedCurrencyAmountObj as D, separateCurrencyStrParts as E, localeToCurrencySymbol as F, isBrowser as G, isNode as H, isTest as I, isError as J, isErrorWithMessage as K, getErrorMsg as L, isErrorMsg as M, errorToJSON as N, bytesToHex as O, hexToBytes as P, getCurrentLocale as Q, countryCodesToCurrencyCodes as R, type SDKCurrencyAmountType as S, type CurrencyLocales as T, type UmaCurrency as U, type CurrencyCodes as V, localeToCurrencyCode as W, getLocalStorageConfigItem as X, getLocalStorageBoolean as Y, setLocalStorageBoolean as Z, deleteLocalStorageItem as _, b64encode as a, linearInterpolate as a0, round as a1, isNumber as a2, pollUntil as a3, sleep as a4, lsidToUUID as a5, isUint8Array as a6, isObject as a7, isRecord as a8, type Maybe as a9, type ExpandRecursively as aa, type ById as ab, type OmitTypename as ac, isType as ad, type ExtractByTypename as ae, type DeepPartial as af, type JSONLiteral as ag, type JSONType as ah, type JSONObject as ai, type NN as aj, notNullUndefined as ak, type PartialBy as al, type Complete as am, type RequiredKeys as an, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountInputObj as k, type UmaCurrencyAmount as l, type CurrencyAmountObj as m, type CurrencyAmountPreferenceObj as n, type CurrencyAmountArg as o, isCurrencyAmountInputObj as p, isUmaCurrencyAmount as q, isDeprecatedCurrencyAmountObj as r, isCurrencyAmountObj as s, isCurrencyAmountPreferenceObj as t, urlsafe_b64decode as u, isSDKCurrencyAmount as v, getCurrencyAmount as w, mapCurrencyAmount as x, isCurrencyMap as y, abbrCurrencyUnit as z };
package/dist/index.cjs CHANGED
@@ -79,7 +79,7 @@ __export(src_exports, {
79
79
  isErrorWithMessage: () => isErrorWithMessage,
80
80
  isNode: () => isNode,
81
81
  isNumber: () => isNumber,
82
- isObject: () => isObject2,
82
+ isObject: () => isObject,
83
83
  isRecord: () => isRecord,
84
84
  isSDKCurrencyAmount: () => isSDKCurrencyAmount,
85
85
  isTest: () => isTest,
@@ -1279,6 +1279,18 @@ function localeToCurrencySymbol(locale) {
1279
1279
  return symbol;
1280
1280
  }
1281
1281
 
1282
+ // src/utils/typeGuards.ts
1283
+ function isUint8Array(value) {
1284
+ return value instanceof Uint8Array;
1285
+ }
1286
+ function isObject(value) {
1287
+ const type = typeof value;
1288
+ return value != null && (type == "object" || type == "function");
1289
+ }
1290
+ function isRecord(value) {
1291
+ return typeof value === "object" && value !== null && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
1292
+ }
1293
+
1282
1294
  // src/utils/errors.ts
1283
1295
  var isError = (e) => {
1284
1296
  return Boolean(
@@ -1299,31 +1311,71 @@ var isErrorMsg = (e, msg) => {
1299
1311
  }
1300
1312
  return false;
1301
1313
  };
1302
- function errorToJSON(err) {
1314
+ function normalizeObject(obj) {
1315
+ const normalized = {};
1316
+ if (isObject(obj)) {
1317
+ const props = Object.getOwnPropertyNames(obj);
1318
+ for (const prop of props) {
1319
+ const objRecord = obj;
1320
+ normalized[prop] = objRecord[prop];
1321
+ }
1322
+ }
1323
+ return normalized;
1324
+ }
1325
+ function errorToJSON(err, stringifyObjects = false) {
1303
1326
  if (!err) {
1304
1327
  return null;
1305
1328
  }
1306
- if (typeof err === "object" && "toJSON" in err && typeof err.toJSON === "function") {
1329
+ if (isObject(err) && "toJSON" in err && typeof err.toJSON === "function") {
1330
+ if (stringifyObjects === true) {
1331
+ return objectToJSON(err.toJSON());
1332
+ }
1307
1333
  return err.toJSON();
1308
1334
  }
1309
1335
  if (typeof err === "object" && /* This happens for certain errors like DOMException: */
1310
1336
  Object.getOwnPropertyNames(err).length === 0 && "message" in err && typeof err.message === "string") {
1311
1337
  return { message: err.message };
1312
1338
  }
1339
+ return objectToJSON(err);
1340
+ }
1341
+ function objectToJSON(obj) {
1342
+ const normalizedObj = normalizeObject(obj);
1313
1343
  return JSON.parse(
1314
- JSON.stringify(err, Object.getOwnPropertyNames(err))
1344
+ JSON.stringify(normalizedObj, (key, value) => {
1345
+ if (key === "") {
1346
+ return value;
1347
+ }
1348
+ const objProps = Object.getOwnPropertyNames(normalizedObj);
1349
+ if (!objProps.includes(key)) {
1350
+ return void 0;
1351
+ }
1352
+ if (isObject(value)) {
1353
+ return JSON.stringify(value);
1354
+ }
1355
+ return value;
1356
+ })
1315
1357
  );
1316
1358
  }
1317
1359
 
1318
1360
  // src/utils/localStorage.ts
1319
1361
  function getLocalStorageConfigItem(key) {
1320
- return getLocalStorageBoolean(key);
1362
+ const localStorageBoolean = getLocalStorageBoolean(key);
1363
+ if (localStorageBoolean == null) {
1364
+ return false;
1365
+ }
1366
+ return localStorageBoolean;
1321
1367
  }
1322
1368
  function getLocalStorageBoolean(key) {
1323
1369
  try {
1324
- return localStorage.getItem(key) === "1";
1370
+ if (localStorage.getItem(key) === "1") {
1371
+ return true;
1372
+ } else if (localStorage.getItem(key) == null) {
1373
+ return null;
1374
+ } else {
1375
+ return false;
1376
+ }
1325
1377
  } catch (e) {
1326
- return false;
1378
+ return null;
1327
1379
  }
1328
1380
  }
1329
1381
  function setLocalStorageBoolean(key, value) {
@@ -1397,11 +1449,11 @@ function baseGetTag(value) {
1397
1449
  var baseGetTag_default = baseGetTag;
1398
1450
 
1399
1451
  // ../../node_modules/lodash-es/isObject.js
1400
- function isObject(value) {
1452
+ function isObject2(value) {
1401
1453
  var type = typeof value;
1402
1454
  return value != null && (type == "object" || type == "function");
1403
1455
  }
1404
- var isObject_default = isObject;
1456
+ var isObject_default = isObject2;
1405
1457
 
1406
1458
  // ../../node_modules/lodash-es/isFunction.js
1407
1459
  var asyncTag = "[object AsyncFunction]";
@@ -1465,15 +1517,6 @@ function lsidToUUID(lsid) {
1465
1517
  return lsid.replace(/^[^:]+:(.*)$/, "$1");
1466
1518
  }
1467
1519
 
1468
- // src/utils/typeGuards.ts
1469
- function isUint8Array(value) {
1470
- return value instanceof Uint8Array;
1471
- }
1472
- function isObject2(value) {
1473
- const type = typeof value;
1474
- return value != null && (type == "object" || type == "function");
1475
- }
1476
-
1477
1520
  // src/utils/types.ts
1478
1521
  var isType = (typename) => (node) => {
1479
1522
  return node?.__typename === typename;
@@ -1481,9 +1524,6 @@ var isType = (typename) => (node) => {
1481
1524
  function notNullUndefined(value) {
1482
1525
  return value !== null && value !== void 0;
1483
1526
  }
1484
- function isRecord(value) {
1485
- return typeof value === "object" && value !== null && !Array.isArray(value);
1486
- }
1487
1527
 
1488
1528
  // src/crypto/SigningKey.ts
1489
1529
  function isAlias(key) {
@@ -1635,7 +1675,6 @@ var logger = new Logger("@lightsparkdev/core");
1635
1675
  var import_dayjs = __toESM(require("dayjs"), 1);
1636
1676
  var import_utc = __toESM(require("dayjs/plugin/utc.js"), 1);
1637
1677
  var import_graphql_ws = require("graphql-ws");
1638
- var import_ws = __toESM(require("ws"), 1);
1639
1678
  var import_zen_observable_ts = require("zen-observable-ts");
1640
1679
  var DEFAULT_BASE_URL = "api.lightspark.com";
1641
1680
  import_dayjs.default.extend(import_utc.default);
@@ -1649,22 +1688,38 @@ var Requester = class {
1649
1688
  this.cryptoImpl = cryptoImpl;
1650
1689
  this.signingKey = signingKey;
1651
1690
  this.fetchImpl = fetchImpl;
1691
+ this.wsClient = new Promise((resolve) => {
1692
+ this.resolveWsClient = resolve;
1693
+ });
1694
+ void this.initWsClient(baseUrl, authProvider);
1695
+ autoBind(this);
1696
+ }
1697
+ wsClient;
1698
+ resolveWsClient = null;
1699
+ async initWsClient(baseUrl, authProvider) {
1700
+ if (!this.resolveWsClient) {
1701
+ return this.wsClient;
1702
+ }
1652
1703
  let websocketImpl;
1653
- if (typeof WebSocket === "undefined" && typeof window === "undefined") {
1654
- websocketImpl = import_ws.default;
1704
+ if (isNode && typeof WebSocket === "undefined") {
1705
+ const wsModule = await import("ws");
1706
+ websocketImpl = wsModule.default;
1655
1707
  }
1656
1708
  let websocketProtocol = "wss";
1657
1709
  if (baseUrl.startsWith("http://")) {
1658
1710
  websocketProtocol = "ws";
1659
1711
  }
1660
- this.wsClient = (0, import_graphql_ws.createClient)({
1712
+ const wsClient = (0, import_graphql_ws.createClient)({
1661
1713
  url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
1662
1714
  connectionParams: () => authProvider.addWsConnectionParams({}),
1663
1715
  webSocketImpl: websocketImpl
1664
1716
  });
1665
- autoBind(this);
1717
+ if (this.resolveWsClient) {
1718
+ this.resolveWsClient(wsClient);
1719
+ this.resolveWsClient = null;
1720
+ }
1721
+ return wsClient;
1666
1722
  }
1667
- wsClient;
1668
1723
  async executeQuery(query) {
1669
1724
  const data = await this.makeRawRequest(
1670
1725
  query.queryPayload,
@@ -1702,11 +1757,28 @@ var Requester = class {
1702
1757
  };
1703
1758
  return new import_zen_observable_ts.Observable((observer) => {
1704
1759
  logger.trace(`Requester.subscribe observer`, observer);
1705
- return this.wsClient.subscribe(bodyData, {
1706
- next: (data) => observer.next(data),
1707
- error: (err) => observer.error(err),
1708
- complete: () => observer.complete()
1709
- });
1760
+ let cleanup = null;
1761
+ let canceled = false;
1762
+ void (async () => {
1763
+ try {
1764
+ const wsClient = await this.wsClient;
1765
+ if (!canceled) {
1766
+ cleanup = wsClient.subscribe(bodyData, {
1767
+ next: (data) => observer.next(data),
1768
+ error: (err) => observer.error(err),
1769
+ complete: () => observer.complete()
1770
+ });
1771
+ }
1772
+ } catch (err) {
1773
+ observer.error(err);
1774
+ }
1775
+ })();
1776
+ return () => {
1777
+ canceled = true;
1778
+ if (cleanup) {
1779
+ cleanup();
1780
+ }
1781
+ };
1710
1782
  });
1711
1783
  }
1712
1784
  async makeRawRequest(queryPayload, variables = {}, signingNodeId = void 0, skipAuth = false) {
@@ -1782,9 +1854,15 @@ var Requester = class {
1782
1854
  const responseJson = await response.json();
1783
1855
  const data = responseJson.data;
1784
1856
  if (!data) {
1857
+ let firstErrorName = void 0;
1858
+ if (Array.isArray(responseJson.errors) && responseJson.errors.length > 0) {
1859
+ const firstError = responseJson.errors[0];
1860
+ firstErrorName = firstError["extensions"]?.["error_name"];
1861
+ }
1785
1862
  throw new LightsparkException_default(
1786
1863
  "RequestFailed",
1787
- `Request ${operation} failed. ${JSON.stringify(responseJson.errors)}`
1864
+ `Request ${operation} failed. ${JSON.stringify(responseJson.errors)}`,
1865
+ { errorName: firstErrorName }
1788
1866
  );
1789
1867
  }
1790
1868
  return data;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppendUnitsOptions, aa as ById, al as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ae as DeepPartial, D as DeprecatedCurrencyAmountObj, a9 as ExpandRecursively, ad as ExtractByTypename, af as JSONLiteral, ah as JSONObject, ag as JSONType, a8 as Maybe, ai as NN, ab as OmitTypename, ak as PartialBy, am as RequiredKeys, S as SDKCurrencyAmountType, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, an as isRecord, v as isSDKCurrencyAmount, I as isTest, ac as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, aj as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode } from './index-C7dqDM91.cjs';
1
+ export { A as AppendUnitsOptions, ab as ById, am as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode } from './index-DZbfPQqd.cjs';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
@@ -147,8 +147,10 @@ declare class Requester {
147
147
  private readonly cryptoImpl;
148
148
  private readonly signingKey?;
149
149
  private readonly fetchImpl;
150
- private readonly wsClient;
150
+ private wsClient;
151
+ private resolveWsClient;
151
152
  constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
153
+ private initWsClient;
152
154
  executeQuery<T>(query: Query<T>): Promise<T | null>;
153
155
  subscribe<T>(queryPayload: string, variables?: {
154
156
  [key: string]: unknown;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AppendUnitsOptions, aa as ById, al as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, ae as DeepPartial, D as DeprecatedCurrencyAmountObj, a9 as ExpandRecursively, ad as ExtractByTypename, af as JSONLiteral, ah as JSONObject, ag as JSONType, a8 as Maybe, ai as NN, ab as OmitTypename, ak as PartialBy, am as RequiredKeys, S as SDKCurrencyAmountType, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, an as isRecord, v as isSDKCurrencyAmount, I as isTest, ac as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, aj as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode } from './index-C7dqDM91.js';
1
+ export { A as AppendUnitsOptions, ab as ById, am as Complete, C as ConfigKeys, o as CurrencyAmountArg, k as CurrencyAmountInputObj, m as CurrencyAmountObj, n as CurrencyAmountPreferenceObj, V as CurrencyCodes, T as CurrencyLocales, j as CurrencyMap, f as CurrencyUnit, g as CurrencyUnitType, af as DeepPartial, D as DeprecatedCurrencyAmountObj, aa as ExpandRecursively, ae as ExtractByTypename, ag as JSONLiteral, ai as JSONObject, ah as JSONType, a9 as Maybe, aj as NN, ac as OmitTypename, al as PartialBy, an as RequiredKeys, S as SDKCurrencyAmountType, U as UmaCurrency, l as UmaCurrencyAmount, z as abbrCurrencyUnit, b as b64decode, a as b64encode, O as bytesToHex, $ as clamp, i as convertCurrencyAmount, h as convertCurrencyAmountValue, R as countryCodesToCurrencyCodes, c as createSha256Hash, d as defaultCurrencyCode, _ as deleteLocalStorageItem, e as ensureArray, N as errorToJSON, B as formatCurrencyStr, w as getCurrencyAmount, Q as getCurrentLocale, L as getErrorMsg, Y as getLocalStorageBoolean, X as getLocalStorageConfigItem, P as hexToBytes, G as isBrowser, p as isCurrencyAmountInputObj, s as isCurrencyAmountObj, t as isCurrencyAmountPreferenceObj, y as isCurrencyMap, r as isDeprecatedCurrencyAmountObj, J as isError, M as isErrorMsg, K as isErrorWithMessage, H as isNode, a2 as isNumber, a7 as isObject, a8 as isRecord, v as isSDKCurrencyAmount, I as isTest, ad as isType, a6 as isUint8Array, q as isUmaCurrencyAmount, a0 as linearInterpolate, W as localeToCurrencyCode, F as localeToCurrencySymbol, a5 as lsidToUUID, x as mapCurrencyAmount, ak as notNullUndefined, a3 as pollUntil, a1 as round, E as separateCurrencyStrParts, Z as setLocalStorageBoolean, a4 as sleep, u as urlsafe_b64decode } from './index-DZbfPQqd.js';
2
2
  import { Observable } from 'zen-observable-ts';
3
3
 
4
4
  type Headers = Record<string, string>;
@@ -147,8 +147,10 @@ declare class Requester {
147
147
  private readonly cryptoImpl;
148
148
  private readonly signingKey?;
149
149
  private readonly fetchImpl;
150
- private readonly wsClient;
150
+ private wsClient;
151
+ private resolveWsClient;
151
152
  constructor(nodeKeyCache: NodeKeyCache, schemaEndpoint: string, sdkUserAgent: string, authProvider?: AuthProvider, baseUrl?: string, cryptoImpl?: CryptoInterface, signingKey?: SigningKey | undefined, fetchImpl?: typeof fetch);
153
+ private initWsClient;
152
154
  executeQuery<T>(query: Query<T>): Promise<T | null>;
153
155
  subscribe<T>(queryPayload: string, variables?: {
154
156
  [key: string]: unknown;