@lightsparkdev/core 1.0.0 → 1.0.1
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 +6 -0
- package/dist/index.cjs +29 -0
- package/dist/index.d.ts +9 -1
- package/dist/index.js +25 -0
- package/package.json +1 -1
- package/src/utils/errors.ts +36 -0
- package/src/utils/index.ts +1 -0
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -49,8 +49,12 @@ __export(src_exports, {
|
|
|
49
49
|
bytesToHex: () => bytesToHex,
|
|
50
50
|
convertCurrencyAmount: () => convertCurrencyAmount,
|
|
51
51
|
createSha256Hash: () => createSha256Hash,
|
|
52
|
+
getErrorMsg: () => getErrorMsg,
|
|
52
53
|
hexToBytes: () => hexToBytes,
|
|
53
54
|
isBrowser: () => isBrowser,
|
|
55
|
+
isError: () => isError,
|
|
56
|
+
isErrorMsg: () => isErrorMsg,
|
|
57
|
+
isErrorWithMessage: () => isErrorWithMessage,
|
|
54
58
|
isNode: () => isNode,
|
|
55
59
|
isType: () => isType,
|
|
56
60
|
urlsafe_b64decode: () => urlsafe_b64decode
|
|
@@ -741,6 +745,27 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
741
745
|
};
|
|
742
746
|
};
|
|
743
747
|
|
|
748
|
+
// src/utils/errors.ts
|
|
749
|
+
var isError = (e) => {
|
|
750
|
+
return Boolean(
|
|
751
|
+
typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
|
|
752
|
+
);
|
|
753
|
+
};
|
|
754
|
+
var isErrorWithMessage = (e) => {
|
|
755
|
+
return Boolean(
|
|
756
|
+
typeof e === "object" && e !== null && "message" in e && typeof e.message === "string"
|
|
757
|
+
);
|
|
758
|
+
};
|
|
759
|
+
var getErrorMsg = (e) => {
|
|
760
|
+
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
761
|
+
};
|
|
762
|
+
var isErrorMsg = (e, msg) => {
|
|
763
|
+
if (isError(e)) {
|
|
764
|
+
return e.message === msg;
|
|
765
|
+
}
|
|
766
|
+
return false;
|
|
767
|
+
};
|
|
768
|
+
|
|
744
769
|
// src/utils/hex.ts
|
|
745
770
|
var bytesToHex = (bytes) => {
|
|
746
771
|
return bytes.reduce((acc, byte) => {
|
|
@@ -780,8 +805,12 @@ var isType = (typename) => (node) => {
|
|
|
780
805
|
bytesToHex,
|
|
781
806
|
convertCurrencyAmount,
|
|
782
807
|
createSha256Hash,
|
|
808
|
+
getErrorMsg,
|
|
783
809
|
hexToBytes,
|
|
784
810
|
isBrowser,
|
|
811
|
+
isError,
|
|
812
|
+
isErrorMsg,
|
|
813
|
+
isErrorWithMessage,
|
|
785
814
|
isNode,
|
|
786
815
|
isType,
|
|
787
816
|
urlsafe_b64decode
|
package/dist/index.d.ts
CHANGED
|
@@ -196,6 +196,14 @@ declare const convertCurrencyAmount: (from: CurrencyAmount, toUnit: CurrencyUnit
|
|
|
196
196
|
declare const isBrowser: boolean;
|
|
197
197
|
declare const isNode: boolean;
|
|
198
198
|
|
|
199
|
+
declare const isError: (e: unknown) => e is Error;
|
|
200
|
+
type ErrorWithMessage = {
|
|
201
|
+
message: string;
|
|
202
|
+
};
|
|
203
|
+
declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
|
|
204
|
+
declare const getErrorMsg: (e: unknown) => string;
|
|
205
|
+
declare const isErrorMsg: (e: unknown, msg: string) => boolean;
|
|
206
|
+
|
|
199
207
|
declare const bytesToHex: (bytes: Uint8Array) => string;
|
|
200
208
|
declare const hexToBytes: (hex: string) => Uint8Array;
|
|
201
209
|
|
|
@@ -213,4 +221,4 @@ declare const isType: <T extends string>(typename: T) => <N extends {
|
|
|
213
221
|
__typename: T;
|
|
214
222
|
}>;
|
|
215
223
|
|
|
216
|
-
export { AuthProvider, ById, CryptoInterface, DefaultCrypto, ExpandRecursively, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Maybe, NodeKeyCache, OmitTypename, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, b64decode, b64encode, bytesToHex, convertCurrencyAmount, createSha256Hash, hexToBytes, isBrowser, isNode, isType, urlsafe_b64decode };
|
|
224
|
+
export { AuthProvider, ById, CryptoInterface, DefaultCrypto, ExpandRecursively, GeneratedKeyPair, KeyOrAlias, KeyOrAliasType, LightsparkAuthException, LightsparkException, LightsparkSigningException, Maybe, NodeKeyCache, OmitTypename, Query, RSASigningKey, Requester, Secp256k1SigningKey, ServerEnvironment, SigningKey, SigningKeyType, StubAuthProvider, apiDomainForEnvironment, b64decode, b64encode, bytesToHex, convertCurrencyAmount, createSha256Hash, getErrorMsg, hexToBytes, isBrowser, isError, isErrorMsg, isErrorWithMessage, isNode, isType, urlsafe_b64decode };
|
package/dist/index.js
CHANGED
|
@@ -682,6 +682,27 @@ var convertCurrencyAmount = (from, toUnit) => {
|
|
|
682
682
|
};
|
|
683
683
|
};
|
|
684
684
|
|
|
685
|
+
// src/utils/errors.ts
|
|
686
|
+
var isError = (e) => {
|
|
687
|
+
return Boolean(
|
|
688
|
+
typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
|
|
689
|
+
);
|
|
690
|
+
};
|
|
691
|
+
var isErrorWithMessage = (e) => {
|
|
692
|
+
return Boolean(
|
|
693
|
+
typeof e === "object" && e !== null && "message" in e && typeof e.message === "string"
|
|
694
|
+
);
|
|
695
|
+
};
|
|
696
|
+
var getErrorMsg = (e) => {
|
|
697
|
+
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
698
|
+
};
|
|
699
|
+
var isErrorMsg = (e, msg) => {
|
|
700
|
+
if (isError(e)) {
|
|
701
|
+
return e.message === msg;
|
|
702
|
+
}
|
|
703
|
+
return false;
|
|
704
|
+
};
|
|
705
|
+
|
|
685
706
|
// src/utils/hex.ts
|
|
686
707
|
var bytesToHex = (bytes) => {
|
|
687
708
|
return bytes.reduce((acc, byte) => {
|
|
@@ -720,8 +741,12 @@ export {
|
|
|
720
741
|
bytesToHex,
|
|
721
742
|
convertCurrencyAmount,
|
|
722
743
|
createSha256Hash,
|
|
744
|
+
getErrorMsg,
|
|
723
745
|
hexToBytes,
|
|
724
746
|
isBrowser,
|
|
747
|
+
isError,
|
|
748
|
+
isErrorMsg,
|
|
749
|
+
isErrorWithMessage,
|
|
725
750
|
isNode,
|
|
726
751
|
isType,
|
|
727
752
|
urlsafe_b64decode
|
package/package.json
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const isError = (e: unknown): e is Error => {
|
|
2
|
+
return Boolean(
|
|
3
|
+
typeof e === "object" &&
|
|
4
|
+
e !== null &&
|
|
5
|
+
"name" in e &&
|
|
6
|
+
typeof e.name === "string" &&
|
|
7
|
+
"message" in e &&
|
|
8
|
+
typeof e.message === "string" &&
|
|
9
|
+
"stack" in e &&
|
|
10
|
+
(!e.stack || typeof e.stack === "string"),
|
|
11
|
+
);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type ErrorWithMessage = {
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const isErrorWithMessage = (e: unknown): e is ErrorWithMessage => {
|
|
19
|
+
return Boolean(
|
|
20
|
+
typeof e === "object" &&
|
|
21
|
+
e !== null &&
|
|
22
|
+
"message" in e &&
|
|
23
|
+
typeof e.message === "string",
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const getErrorMsg = (e: unknown): string => {
|
|
28
|
+
return isErrorWithMessage(e) ? e.message : "Unknown error";
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const isErrorMsg = (e: unknown, msg: string) => {
|
|
32
|
+
if (isError(e)) {
|
|
33
|
+
return e.message === msg;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|