@lightsparkdev/core 1.3.1 → 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 +20 -0
- package/dist/{chunk-23SS5EX2.js → chunk-NV53XYAS.js} +64 -24
- package/dist/{index-C7dqDM91.d.cts → index-DZbfPQqd.d.cts} +5 -5
- package/dist/{index-C7dqDM91.d.ts → index-DZbfPQqd.d.ts} +5 -5
- package/dist/index.cjs +104 -32
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +44 -12
- package/dist/utils/index.cjs +61 -21
- package/dist/utils/index.d.cts +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +3 -2
- package/src/requester/Requester.ts +52 -11
- package/src/requester/tests/Requester.test.ts +347 -0
- package/src/utils/errors.ts +49 -7
- package/src/utils/localStorage.ts +19 -3
- package/src/utils/typeGuards.ts +10 -1
- package/src/utils/types.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
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
|
+
|
|
3
23
|
## 1.3.1
|
|
4
24
|
|
|
5
25
|
### Patch 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
|
|
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 (
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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: () =>
|
|
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
|
|
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 (
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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 (
|
|
1654
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
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) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as AppendUnitsOptions,
|
|
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
|
|
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,
|
|
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
|
|
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.js
CHANGED
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
setLocalStorageBoolean,
|
|
52
52
|
sleep,
|
|
53
53
|
urlsafe_b64decode
|
|
54
|
-
} from "./chunk-
|
|
54
|
+
} from "./chunk-NV53XYAS.js";
|
|
55
55
|
|
|
56
56
|
// src/auth/LightsparkAuthException.ts
|
|
57
57
|
var LightsparkAuthException = class extends LightsparkException_default {
|
|
@@ -488,7 +488,6 @@ var logger = new Logger("@lightsparkdev/core");
|
|
|
488
488
|
import dayjs from "dayjs";
|
|
489
489
|
import utc from "dayjs/plugin/utc.js";
|
|
490
490
|
import { createClient } from "graphql-ws";
|
|
491
|
-
import NodeWebSocket from "ws";
|
|
492
491
|
import { Observable } from "zen-observable-ts";
|
|
493
492
|
var DEFAULT_BASE_URL = "api.lightspark.com";
|
|
494
493
|
dayjs.extend(utc);
|
|
@@ -502,22 +501,38 @@ var Requester = class {
|
|
|
502
501
|
this.cryptoImpl = cryptoImpl;
|
|
503
502
|
this.signingKey = signingKey;
|
|
504
503
|
this.fetchImpl = fetchImpl;
|
|
504
|
+
this.wsClient = new Promise((resolve) => {
|
|
505
|
+
this.resolveWsClient = resolve;
|
|
506
|
+
});
|
|
507
|
+
void this.initWsClient(baseUrl, authProvider);
|
|
508
|
+
autoBind(this);
|
|
509
|
+
}
|
|
510
|
+
wsClient;
|
|
511
|
+
resolveWsClient = null;
|
|
512
|
+
async initWsClient(baseUrl, authProvider) {
|
|
513
|
+
if (!this.resolveWsClient) {
|
|
514
|
+
return this.wsClient;
|
|
515
|
+
}
|
|
505
516
|
let websocketImpl;
|
|
506
|
-
if (
|
|
507
|
-
|
|
517
|
+
if (isNode && typeof WebSocket === "undefined") {
|
|
518
|
+
const wsModule = await import("ws");
|
|
519
|
+
websocketImpl = wsModule.default;
|
|
508
520
|
}
|
|
509
521
|
let websocketProtocol = "wss";
|
|
510
522
|
if (baseUrl.startsWith("http://")) {
|
|
511
523
|
websocketProtocol = "ws";
|
|
512
524
|
}
|
|
513
|
-
|
|
525
|
+
const wsClient = createClient({
|
|
514
526
|
url: `${websocketProtocol}://${this.stripProtocol(this.baseUrl)}/${this.schemaEndpoint}`,
|
|
515
527
|
connectionParams: () => authProvider.addWsConnectionParams({}),
|
|
516
528
|
webSocketImpl: websocketImpl
|
|
517
529
|
});
|
|
518
|
-
|
|
530
|
+
if (this.resolveWsClient) {
|
|
531
|
+
this.resolveWsClient(wsClient);
|
|
532
|
+
this.resolveWsClient = null;
|
|
533
|
+
}
|
|
534
|
+
return wsClient;
|
|
519
535
|
}
|
|
520
|
-
wsClient;
|
|
521
536
|
async executeQuery(query) {
|
|
522
537
|
const data = await this.makeRawRequest(
|
|
523
538
|
query.queryPayload,
|
|
@@ -555,11 +570,28 @@ var Requester = class {
|
|
|
555
570
|
};
|
|
556
571
|
return new Observable((observer) => {
|
|
557
572
|
logger.trace(`Requester.subscribe observer`, observer);
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
573
|
+
let cleanup = null;
|
|
574
|
+
let canceled = false;
|
|
575
|
+
void (async () => {
|
|
576
|
+
try {
|
|
577
|
+
const wsClient = await this.wsClient;
|
|
578
|
+
if (!canceled) {
|
|
579
|
+
cleanup = wsClient.subscribe(bodyData, {
|
|
580
|
+
next: (data) => observer.next(data),
|
|
581
|
+
error: (err) => observer.error(err),
|
|
582
|
+
complete: () => observer.complete()
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
} catch (err) {
|
|
586
|
+
observer.error(err);
|
|
587
|
+
}
|
|
588
|
+
})();
|
|
589
|
+
return () => {
|
|
590
|
+
canceled = true;
|
|
591
|
+
if (cleanup) {
|
|
592
|
+
cleanup();
|
|
593
|
+
}
|
|
594
|
+
};
|
|
563
595
|
});
|
|
564
596
|
}
|
|
565
597
|
async makeRawRequest(queryPayload, variables = {}, signingNodeId = void 0, skipAuth = false) {
|